From aa43d61b584c377b0209bf1e07a6191f01cde6ef Mon Sep 17 00:00:00 2001 From: Daniel Naab Date: Tue, 13 Feb 2024 09:46:31 -0600 Subject: [PATCH] Support customizable content types (#44) * Add a FormConfig type to define injectable form field definitions. This is an overly large commit, but includes most of the refactoring necessary for this purpose. In the design package, we could use a better type and/or constructor for configuring the UI side of the form field configuration. * Fix some typings * Add @vitest/coverage-c8 back in. It's deprecated, but used by the Github Action that is currently posting coverage data as PR comments. * Add an initial mapping for form element -> ui component * Linting --- .gitignore | 1 + .../src/components/AppFormManager.tsx | 14 +- .../src/components/AppFormRouter.tsx | 2 +- apps/spotlight/src/components/Footer.astro | 17 +-- apps/spotlight/src/context.ts | 5 + package.json | 1 + packages/design/.eslintrc.cjs | 62 ++++----- packages/design/src/Form/Form.stories.tsx | 3 +- packages/design/src/Form/index.tsx | 5 +- .../FormManager/DocumentImporter/index.tsx | 9 +- .../FormManager/FormEdit/FormEdit.stories.tsx | 3 +- .../FormEdit/FormElementEdit/RenderField.tsx | 76 ----------- .../FormElementEdit/SequenceElementEdit.tsx | 111 --------------- .../design/src/FormManager/FormEdit/index.tsx | 41 ++---- .../FormPreview/FormPreview.stories.tsx | 3 +- .../src/FormManager/FormPreview/index.tsx | 5 + .../src/FormManager/import-document.tsx | 5 + packages/design/src/FormManager/index.tsx | 20 ++- packages/design/src/FormRouter/index.tsx | 4 + .../design/src/config/InputElementEdit.tsx | 61 +++++++++ .../design/src/config/SequenceElementEdit.tsx | 127 ++++++++++++++++++ packages/design/src/config/index.ts | 25 ++++ packages/design/src/index.ts | 1 + packages/design/src/test-form.ts | 39 ++++-- packages/design/src/test-helper.ts | 6 +- packages/documents/src/document.ts | 38 ++++-- .../form-service/src/operations/get-form.ts | 2 +- packages/forms/src/config/config.ts | 13 ++ packages/forms/src/config/elements/input.ts | 35 +++++ .../forms/src/config/elements/sequence.ts | 27 ++++ packages/forms/src/config/index.ts | 26 ++-- packages/forms/src/elements.ts | 24 ++++ packages/forms/src/elements/index.ts | 20 --- packages/forms/src/elements/input.ts | 9 -- packages/forms/src/elements/sequence.ts | 7 - packages/forms/src/index.ts | 80 ++++------- .../src/{prompts/index.ts => prompts.ts} | 47 +++---- packages/forms/tests/two-field-form.test.ts | 25 ++-- pnpm-lock.yaml | 63 ++++++--- 39 files changed, 610 insertions(+), 452 deletions(-) delete mode 100644 packages/design/src/FormManager/FormEdit/FormElementEdit/RenderField.tsx delete mode 100644 packages/design/src/FormManager/FormEdit/FormElementEdit/SequenceElementEdit.tsx create mode 100644 packages/design/src/config/InputElementEdit.tsx create mode 100644 packages/design/src/config/SequenceElementEdit.tsx create mode 100644 packages/design/src/config/index.ts create mode 100644 packages/forms/src/config/config.ts create mode 100644 packages/forms/src/config/elements/input.ts create mode 100644 packages/forms/src/config/elements/sequence.ts create mode 100644 packages/forms/src/elements.ts delete mode 100644 packages/forms/src/elements/index.ts delete mode 100644 packages/forms/src/elements/input.ts delete mode 100644 packages/forms/src/elements/sequence.ts rename packages/forms/src/{prompts/index.ts => prompts.ts} (55%) diff --git a/.gitignore b/.gitignore index b168fc06..7f174c0f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ coverage/ html/ node_modules/ NOTES.md +tsconfig.tsbuildinfo diff --git a/apps/spotlight/src/components/AppFormManager.tsx b/apps/spotlight/src/components/AppFormManager.tsx index 020464bc..ad669db0 100644 --- a/apps/spotlight/src/components/AppFormManager.tsx +++ b/apps/spotlight/src/components/AppFormManager.tsx @@ -1,9 +1,19 @@ import React from 'react'; -import { FormManager } from '@atj/design'; +import { FormManager, defaultFormElementComponent } from '@atj/design'; + import { getAppContext } from '../context'; export default function () { const ctx = getAppContext(); - return ; + return ( + + ); } diff --git a/apps/spotlight/src/components/AppFormRouter.tsx b/apps/spotlight/src/components/AppFormRouter.tsx index 09cbc11d..9cff368f 100644 --- a/apps/spotlight/src/components/AppFormRouter.tsx +++ b/apps/spotlight/src/components/AppFormRouter.tsx @@ -5,5 +5,5 @@ import { getAppContext } from '../context'; export default function AppFormRouter() { const ctx = getAppContext(); - return ; + return ; } diff --git a/apps/spotlight/src/components/Footer.astro b/apps/spotlight/src/components/Footer.astro index 02a2d1c7..f11a3421 100644 --- a/apps/spotlight/src/components/Footer.astro +++ b/apps/spotlight/src/components/Footer.astro @@ -18,25 +18,14 @@ const { github } = Astro.props;