From cac14e73ac1604c278df5b9984e2908532d04c07 Mon Sep 17 00:00:00 2001 From: Valentin Serra Date: Sun, 17 Sep 2023 18:38:53 +0200 Subject: [PATCH 01/54] chore: rename expression-language folder --- .../ConditionChecker.js | 0 .../FeelExpressionLanguage.js | 0 .../FeelersTemplating.js | 0 .../{expression-language => expressionLanguage}/index.js | 0 .../variableExtractionHelpers.js | 0 packages/form-js-viewer/src/features/index.js | 2 +- packages/form-js-viewer/src/util/index.js | 4 ++-- 7 files changed, 3 insertions(+), 3 deletions(-) rename packages/form-js-viewer/src/features/{expression-language => expressionLanguage}/ConditionChecker.js (100%) rename packages/form-js-viewer/src/features/{expression-language => expressionLanguage}/FeelExpressionLanguage.js (100%) rename packages/form-js-viewer/src/features/{expression-language => expressionLanguage}/FeelersTemplating.js (100%) rename packages/form-js-viewer/src/features/{expression-language => expressionLanguage}/index.js (100%) rename packages/form-js-viewer/src/features/{expression-language => expressionLanguage}/variableExtractionHelpers.js (100%) diff --git a/packages/form-js-viewer/src/features/expression-language/ConditionChecker.js b/packages/form-js-viewer/src/features/expressionLanguage/ConditionChecker.js similarity index 100% rename from packages/form-js-viewer/src/features/expression-language/ConditionChecker.js rename to packages/form-js-viewer/src/features/expressionLanguage/ConditionChecker.js diff --git a/packages/form-js-viewer/src/features/expression-language/FeelExpressionLanguage.js b/packages/form-js-viewer/src/features/expressionLanguage/FeelExpressionLanguage.js similarity index 100% rename from packages/form-js-viewer/src/features/expression-language/FeelExpressionLanguage.js rename to packages/form-js-viewer/src/features/expressionLanguage/FeelExpressionLanguage.js diff --git a/packages/form-js-viewer/src/features/expression-language/FeelersTemplating.js b/packages/form-js-viewer/src/features/expressionLanguage/FeelersTemplating.js similarity index 100% rename from packages/form-js-viewer/src/features/expression-language/FeelersTemplating.js rename to packages/form-js-viewer/src/features/expressionLanguage/FeelersTemplating.js diff --git a/packages/form-js-viewer/src/features/expression-language/index.js b/packages/form-js-viewer/src/features/expressionLanguage/index.js similarity index 100% rename from packages/form-js-viewer/src/features/expression-language/index.js rename to packages/form-js-viewer/src/features/expressionLanguage/index.js diff --git a/packages/form-js-viewer/src/features/expression-language/variableExtractionHelpers.js b/packages/form-js-viewer/src/features/expressionLanguage/variableExtractionHelpers.js similarity index 100% rename from packages/form-js-viewer/src/features/expression-language/variableExtractionHelpers.js rename to packages/form-js-viewer/src/features/expressionLanguage/variableExtractionHelpers.js diff --git a/packages/form-js-viewer/src/features/index.js b/packages/form-js-viewer/src/features/index.js index daf35a86d..15033049c 100644 --- a/packages/form-js-viewer/src/features/index.js +++ b/packages/form-js-viewer/src/features/index.js @@ -2,6 +2,6 @@ export { default as ExpressionLanguageModule } from './expression-language'; export { default as MarkdownModule } from './markdown'; export { default as ViewerCommandsModule } from './viewerCommands'; -export * from './expression-language'; +export * from './expressionLanguage'; export * from './markdown'; export * from './viewerCommands'; \ No newline at end of file diff --git a/packages/form-js-viewer/src/util/index.js b/packages/form-js-viewer/src/util/index.js index 7a425ab61..72640a552 100644 --- a/packages/form-js-viewer/src/util/index.js +++ b/packages/form-js-viewer/src/util/index.js @@ -1,5 +1,5 @@ -import FeelExpressionLanguage from '../features/expression-language/FeelExpressionLanguage.js'; -import FeelersTemplating from '../features/expression-language/FeelersTemplating.js'; +import FeelExpressionLanguage from '../features/expressionLanguage/FeelExpressionLanguage.js'; +import FeelersTemplating from '../features/expressionLanguage/FeelersTemplating.js'; import FormFields from '../render/FormFields.js'; import { get } from 'min-dash'; From 12282cb66f99862f4a303b859a734ac9ead6fb96 Mon Sep 17 00:00:00 2001 From: Valentin Serra Date: Sun, 17 Sep 2023 18:40:17 +0200 Subject: [PATCH 02/54] wip: implemented protoype repeatRenderManager --- packages/form-js-viewer/src/Form.js | 6 ++- packages/form-js-viewer/src/features/index.js | 6 ++- .../repeatRender/RepeatRenderManager.js | 47 +++++++++++++++++++ .../src/features/repeatRender/index.js | 8 ++++ 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js create mode 100644 packages/form-js-viewer/src/features/repeatRender/index.js diff --git a/packages/form-js-viewer/src/Form.js b/packages/form-js-viewer/src/Form.js index 7af68f833..aa01f4e29 100644 --- a/packages/form-js-viewer/src/Form.js +++ b/packages/form-js-viewer/src/Form.js @@ -4,7 +4,8 @@ import { get, isString, isUndefined, set } from 'min-dash'; import { ExpressionLanguageModule, MarkdownModule, - ViewerCommandsModule + ViewerCommandsModule, + RepeatRenderModule } from './features'; import core from './core'; @@ -388,7 +389,8 @@ export default class Form { return [ ExpressionLanguageModule, MarkdownModule, - ViewerCommandsModule + ViewerCommandsModule, + RepeatRenderModule ]; } diff --git a/packages/form-js-viewer/src/features/index.js b/packages/form-js-viewer/src/features/index.js index 15033049c..ed35d55ba 100644 --- a/packages/form-js-viewer/src/features/index.js +++ b/packages/form-js-viewer/src/features/index.js @@ -1,7 +1,9 @@ -export { default as ExpressionLanguageModule } from './expression-language'; +export { default as ExpressionLanguageModule } from './expressionLanguage'; export { default as MarkdownModule } from './markdown'; export { default as ViewerCommandsModule } from './viewerCommands'; +export { default as RepeatRenderModule } from './repeatRender'; export * from './expressionLanguage'; export * from './markdown'; -export * from './viewerCommands'; \ No newline at end of file +export * from './viewerCommands'; +export * from './repeatRender'; \ No newline at end of file diff --git a/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js b/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js new file mode 100644 index 000000000..088c5b2db --- /dev/null +++ b/packages/form-js-viewer/src/features/repeatRender/RepeatRenderManager.js @@ -0,0 +1,47 @@ +export default class RepeatRenderManager { + + /** TODO: do we need to maintain keys list for preact rendering ? 9*/ + + constructor(formFieldRegistry, formFields) { + this._formFieldRegistry = formFieldRegistry; + this._formFields = formFields; + } + + /** + * Checks whether a field should be repeatable. + * + * @param {string} id - The id of the field to check + * @returns {boolean} - True if repeatable, false otherwise + */ + isFieldRepeating(id) { + + if (!id) { + return false; + } + + const formField = this._formFieldRegistry.get(id); + const formFieldDefinition = this._formFields.get(formField.type); + return formFieldDefinition.config.repeatable && formField.isRepeating; + } + + Repeater(props) { + const { ElementRenderer } = props; + const parentId = props.field.id; + const renderElements = [ 1, 2, 3, 4, 5 ]; + + return ( + <> + {renderElements.map((renderElement, index) => { + const elementProps = { + ...props, + indexes: { ...props.indexes, [parentId]: index }, + }; + + return ; + })} + + ); + } +} + +RepeatRenderManager.$inject = [ 'formFieldRegistry', 'formFields' ]; \ No newline at end of file diff --git a/packages/form-js-viewer/src/features/repeatRender/index.js b/packages/form-js-viewer/src/features/repeatRender/index.js new file mode 100644 index 000000000..cb6c41759 --- /dev/null +++ b/packages/form-js-viewer/src/features/repeatRender/index.js @@ -0,0 +1,8 @@ +import RepeatRenderManager from './RepeatRenderManager'; + +export default { + __init__: [ 'repeatRenderManager' ], + repeatRenderManager: [ 'type', RepeatRenderManager ], +}; + +export { RepeatRenderManager }; \ No newline at end of file From a0ae23a95d491ae5b4853faea19752c7600554e1 Mon Sep 17 00:00:00 2001 From: Valentin Serra Date: Sun, 17 Sep 2023 20:02:06 +0200 Subject: [PATCH 03/54] feat: `subform` component --- .../form-js-viewer/src/core/FormLayouter.js | 2 +- .../render/components/form-fields/Subform.js | 41 +++++++++++++++++++ .../src/render/components/icons/index.js | 2 + .../src/render/components/index.js | 3 ++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 packages/form-js-viewer/src/render/components/form-fields/Subform.js diff --git a/packages/form-js-viewer/src/core/FormLayouter.js b/packages/form-js-viewer/src/core/FormLayouter.js index aec88638b..a90521f4d 100644 --- a/packages/form-js-viewer/src/core/FormLayouter.js +++ b/packages/form-js-viewer/src/core/FormLayouter.js @@ -102,7 +102,7 @@ export default class FormLayouter { components } = formField; - if (type !== 'default' && type !== 'group' || !components) { + if (![ 'default', 'group', 'subform' ].includes(type) || !components) { return; } diff --git a/packages/form-js-viewer/src/render/components/form-fields/Subform.js b/packages/form-js-viewer/src/render/components/form-fields/Subform.js new file mode 100644 index 000000000..ae78f67c1 --- /dev/null +++ b/packages/form-js-viewer/src/render/components/form-fields/Subform.js @@ -0,0 +1,41 @@ +import { useContext } from 'preact/hooks'; +import ChildrenRenderer from './parts/ChildrenRenderer'; +import { FormContext, FormRenderContext } from '../../context'; +import { formFieldClasses, prefixId } from '../Util'; +import Label from '../Label'; +import classNames from 'classnames'; + +export default function Subform(props) { + + const { field } = props; + const { label, id, type, showOutline } = field; + const { formId } = useContext(FormContext); + + const { + Empty, + } = useContext(FormRenderContext); + + const fullProps = { ...props, Empty }; + + return ( +
+
+ ); +} + +Subform.config = { + type: 'subform', + pathed: true, + label: 'Subform', + group: 'presentation', + create: (options = {}) => ({ + components: [], + showOutline: true, + isRepeating: true, + ...options + }) +}; diff --git a/packages/form-js-viewer/src/render/components/icons/index.js b/packages/form-js-viewer/src/render/components/icons/index.js index 77189489a..2bc3bf654 100644 --- a/packages/form-js-viewer/src/render/components/icons/index.js +++ b/packages/form-js-viewer/src/render/components/icons/index.js @@ -10,6 +10,7 @@ import RadioIcon from './Radio.svg'; import SelectIcon from './Select.svg'; import SeparatorIcon from './Separator.svg'; import SpacerIcon from './Spacer.svg'; +import SubformIcon from './Group.svg'; import TextIcon from './Text.svg'; import TextfieldIcon from './Textfield.svg'; import TextareaIcon from './Textarea.svg'; @@ -33,6 +34,7 @@ export const iconsByType = (type) => { select: SelectIcon, separator: SeparatorIcon, spacer: SpacerIcon, + subform: SubformIcon, taglist: TaglistIcon, text: TextIcon, textfield: TextfieldIcon, diff --git a/packages/form-js-viewer/src/render/components/index.js b/packages/form-js-viewer/src/render/components/index.js index 7a42e077f..65e98860f 100644 --- a/packages/form-js-viewer/src/render/components/index.js +++ b/packages/form-js-viewer/src/render/components/index.js @@ -13,6 +13,7 @@ import Radio from './form-fields/Radio'; import Select from './form-fields/Select'; import Separator from './form-fields/Separator'; import Spacer from './form-fields/Spacer'; +import Subform from './form-fields/Subform'; import Taglist from './form-fields/Taglist'; import Text from './form-fields/Text'; import Textfield from './form-fields/Textfield'; @@ -45,6 +46,7 @@ export { Select, Separator, Spacer, + Subform, Taglist, Text, Textfield, @@ -66,6 +68,7 @@ export const formFields = [ Select, Spacer, Separator, + Subform, Taglist, Text, Textfield, From d505a981e891d864aef8ce1e68d2ab9702800e27 Mon Sep 17 00:00:00 2001 From: Valentin Serra Date: Sun, 17 Sep 2023 20:02:49 +0200 Subject: [PATCH 04/54] feat: integrated prototype repeatRenderModule --- .../render/components/form-fields/Default.js | 4 +- .../render/components/form-fields/Group.js | 9 +-- .../form-fields/parts/ChildrenRenderer.js | 79 +++++++++++++++++++ .../components/form-fields/parts/Grid.js | 63 --------------- 4 files changed, 84 insertions(+), 71 deletions(-) create mode 100644 packages/form-js-viewer/src/render/components/form-fields/parts/ChildrenRenderer.js delete mode 100644 packages/form-js-viewer/src/render/components/form-fields/parts/Grid.js diff --git a/packages/form-js-viewer/src/render/components/form-fields/Default.js b/packages/form-js-viewer/src/render/components/form-fields/Default.js index 24ed62e56..39d942d9e 100644 --- a/packages/form-js-viewer/src/render/components/form-fields/Default.js +++ b/packages/form-js-viewer/src/render/components/form-fields/Default.js @@ -1,6 +1,6 @@ import { useContext } from 'preact/hooks'; import { FormRenderContext } from '../../context'; -import Grid from './parts/Grid'; +import ChildrenRenderer from './parts/ChildrenRenderer'; export default function FormComponent(props) { @@ -10,7 +10,7 @@ export default function FormComponent(props) { const fullProps = { ...props, Empty: EmptyRoot }; - return ; + return ; } FormComponent.config = { diff --git a/packages/form-js-viewer/src/render/components/form-fields/Group.js b/packages/form-js-viewer/src/render/components/form-fields/Group.js index a7a2a8155..443ea6b7b 100644 --- a/packages/form-js-viewer/src/render/components/form-fields/Group.js +++ b/packages/form-js-viewer/src/render/components/form-fields/Group.js @@ -1,19 +1,16 @@ import { useContext } from 'preact/hooks'; -import Grid from './parts/Grid'; import { FormContext, FormRenderContext } from '../../context'; import { formFieldClasses, prefixId } from '../Util'; import Label from '../Label'; import classNames from 'classnames'; +import ChildrenRenderer from './parts/ChildrenRenderer'; export default function Group(props) { const { field } = props; const { label, id, type, showOutline } = field; const { formId } = useContext(FormContext); - - const { - Empty, - } = useContext(FormRenderContext); + const { Empty } = useContext(FormRenderContext); const fullProps = { ...props, Empty }; @@ -22,7 +19,7 @@ export default function Group(props) {