@getodk/xforms-engine 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/BaseNode.d.ts +4 -4
- package/dist/client/BaseValueNode.d.ts +7 -3
- package/dist/client/RootNode.d.ts +20 -16
- package/dist/client/UploadNode.d.ts +53 -0
- package/dist/client/attachments/InstanceAttachmentMeta.d.ts +8 -0
- package/dist/client/attachments/InstanceAttachmentsConfig.d.ts +8 -0
- package/dist/client/constants.d.ts +11 -12
- package/dist/client/form/CreateFormInstance.d.ts +14 -0
- package/dist/client/form/EditFormInstance.d.ts +62 -0
- package/dist/client/form/FormInstance.d.ts +104 -0
- package/dist/client/form/FormInstanceConfig.d.ts +19 -0
- package/dist/client/form/FormResource.d.ts +1 -0
- package/dist/client/form/LoadForm.d.ts +79 -0
- package/dist/client/form/LoadFormResult.d.ts +67 -0
- package/dist/client/form/RestoreFormInstance.d.ts +8 -0
- package/dist/client/hierarchy.d.ts +4 -5
- package/dist/client/index.d.ts +40 -11
- package/dist/client/node-types.d.ts +2 -3
- package/dist/client/repeat/BaseRepeatRangeNode.d.ts +3 -4
- package/dist/client/repeat/RepeatInstanceNode.d.ts +4 -5
- package/dist/client/repeat/RepeatRangeControlledNode.d.ts +2 -2
- package/dist/client/repeat/RepeatRangeUncontrolledNode.d.ts +2 -2
- package/dist/client/resources.d.ts +1 -1
- package/dist/client/serialization/InstanceData.d.ts +14 -0
- package/dist/client/serialization/InstanceFile.d.ts +6 -0
- package/dist/client/serialization/InstancePayload.d.ts +93 -0
- package/dist/client/serialization/InstancePayloadOptions.d.ts +24 -0
- package/dist/client/serialization/InstanceState.d.ts +12 -0
- package/dist/client/submission/{SubmissionDefinition.d.ts → SubmissionMeta.d.ts} +1 -1
- package/dist/entrypoints/FormInstance.d.ts +20 -0
- package/dist/entrypoints/FormResult/BaseFormResult.d.ts +22 -0
- package/dist/entrypoints/FormResult/BaseInstantiableFormResult.d.ts +25 -0
- package/dist/entrypoints/FormResult/FormFailureResult.d.ts +17 -0
- package/dist/entrypoints/FormResult/FormSuccessResult.d.ts +15 -0
- package/dist/entrypoints/FormResult/FormWarningResult.d.ts +15 -0
- package/dist/entrypoints/createInstance.d.ts +9 -0
- package/dist/entrypoints/editInstance.d.ts +9 -0
- package/dist/entrypoints/index.d.ts +4 -0
- package/dist/entrypoints/loadForm.d.ts +4 -0
- package/dist/entrypoints/restoreInstance.d.ts +9 -0
- package/dist/error/LoadFormFailureError.d.ts +9 -0
- package/dist/error/MalformedInstanceDataError.d.ts +3 -0
- package/dist/error/TemplatedNodeAttributeSerializationError.d.ts +22 -0
- package/dist/error/UploadValueTypeError.d.ts +8 -0
- package/dist/index.d.ts +2 -33
- package/dist/index.js +8280 -6779
- package/dist/index.js.map +1 -1
- package/dist/instance/Group.d.ts +6 -5
- package/dist/instance/InputControl.d.ts +5 -4
- package/dist/instance/ModelValue.d.ts +5 -4
- package/dist/instance/Note.d.ts +4 -3
- package/dist/instance/PrimaryInstance.d.ts +34 -8
- package/dist/instance/RangeControl.d.ts +5 -4
- package/dist/instance/RankControl.d.ts +6 -5
- package/dist/instance/Root.d.ts +7 -9
- package/dist/instance/SelectControl.d.ts +4 -3
- package/dist/instance/Subtree.d.ts +6 -5
- package/dist/instance/TriggerControl.d.ts +4 -3
- package/dist/instance/UploadControl.d.ts +58 -0
- package/dist/instance/abstract/DescendantNode.d.ts +10 -1
- package/dist/instance/abstract/InstanceNode.d.ts +7 -4
- package/dist/instance/abstract/ValueNode.d.ts +7 -5
- package/dist/instance/attachments/InstanceAttachment.d.ts +42 -0
- package/dist/instance/attachments/InstanceAttachmentsState.d.ts +9 -0
- package/dist/instance/children/DescendantNodeInitOptions.d.ts +32 -0
- package/dist/instance/{children.d.ts → children/buildChildren.d.ts} +1 -1
- package/dist/instance/children/childrenInitOptions.d.ts +9 -0
- package/dist/instance/children/normalizeChildInitOptions.d.ts +2 -0
- package/dist/instance/hierarchy.d.ts +6 -7
- package/dist/instance/input/InitialInstanceState.d.ts +13 -0
- package/dist/instance/input/InstanceAttachmentMap.d.ts +19 -0
- package/dist/instance/internal-api/InstanceAttachmentContext.d.ts +19 -0
- package/dist/instance/internal-api/InstanceConfig.d.ts +4 -9
- package/dist/instance/internal-api/InstanceValueContext.d.ts +8 -1
- package/dist/instance/internal-api/serialization/ClientReactiveSerializableInstance.d.ts +16 -0
- package/dist/instance/internal-api/serialization/ClientReactiveSerializableLeafNode.d.ts +32 -0
- package/dist/instance/internal-api/serialization/ClientReactiveSerializableParentNode.d.ts +18 -0
- package/dist/instance/internal-api/serialization/ClientReactiveSerializableTemplatedNode.d.ts +13 -0
- package/dist/instance/internal-api/serialization/ClientReactiveSerializableValueNode.d.ts +21 -0
- package/dist/instance/repeat/BaseRepeatRange.d.ts +10 -8
- package/dist/instance/repeat/RepeatInstance.d.ts +10 -7
- package/dist/instance/repeat/RepeatRangeControlled.d.ts +27 -3
- package/dist/instance/repeat/RepeatRangeUncontrolled.d.ts +4 -3
- package/dist/instance/resource.d.ts +5 -1
- package/dist/integration/xpath/EngineXPathEvaluator.d.ts +2 -2
- package/dist/integration/xpath/adapter/kind.d.ts +4 -10
- package/dist/integration/xpath/static-dom/StaticAttribute.d.ts +4 -5
- package/dist/integration/xpath/static-dom/StaticDocument.d.ts +13 -10
- package/dist/integration/xpath/static-dom/StaticElement.d.ts +21 -22
- package/dist/integration/xpath/static-dom/StaticNode.d.ts +1 -1
- package/dist/integration/xpath/static-dom/StaticParentNode.d.ts +13 -0
- package/dist/integration/xpath/static-dom/staticNodeName.d.ts +3 -0
- package/dist/lib/client-reactivity/instance-state/createNodeRangeInstanceState.d.ts +4 -0
- package/dist/lib/client-reactivity/instance-state/createParentNodeInstanceState.d.ts +4 -0
- package/dist/lib/client-reactivity/instance-state/createPrimaryInstanceState.d.ts +3 -0
- package/dist/lib/client-reactivity/instance-state/createRootInstanceState.d.ts +3 -0
- package/dist/lib/client-reactivity/instance-state/createTemplatedNodeInstanceState.d.ts +6 -0
- package/dist/lib/client-reactivity/instance-state/createValueNodeInstanceState.d.ts +3 -0
- package/dist/lib/client-reactivity/instance-state/prepareInstancePayload.d.ts +8 -0
- package/dist/lib/names/UnprefixedXFormsName.d.ts +4 -0
- package/dist/lib/reactivity/createInstanceAttachment.d.ts +8 -0
- package/dist/lib/reactivity/createInstanceValueState.d.ts +2 -27
- package/dist/lib/resource-helpers.d.ts +2 -0
- package/dist/parse/XFormDOM.d.ts +1 -1
- package/dist/parse/body/BodyDefinition.d.ts +2 -1
- package/dist/parse/body/control/UploadControlDefinition.d.ts +2 -0
- package/dist/parse/model/BindDefinition.d.ts +1 -1
- package/dist/parse/model/BindTypeDefinition.d.ts +2 -7
- package/dist/parse/model/ItextTranslationsDefinition.d.ts +18 -0
- package/dist/parse/model/LeafNodeDefinition.d.ts +4 -5
- package/dist/parse/model/ModelBindMap.d.ts +1 -1
- package/dist/parse/model/ModelDefinition.d.ts +9 -2
- package/dist/parse/model/NodeDefinition.d.ts +18 -30
- package/dist/parse/model/NoteNodeDefinition.d.ts +3 -2
- package/dist/parse/model/RangeNodeDefinition.d.ts +2 -1
- package/dist/parse/model/RepeatDefinition.d.ts +62 -0
- package/dist/parse/model/RootAttributeDefinition.d.ts +1 -4
- package/dist/parse/model/RootAttributeMap.d.ts +2 -1
- package/dist/parse/model/RootDefinition.d.ts +7 -8
- package/dist/parse/model/SecondaryInstance/SecondaryInstancesDefinition.d.ts +15 -2
- package/dist/parse/model/SecondaryInstance/assertSecondaryInstanceDefinition.d.ts +5 -0
- package/dist/parse/model/SecondaryInstance/defineSecondaryInstance.d.ts +5 -0
- package/dist/parse/model/SecondaryInstance/sources/BlankSecondaryInstanceSource.d.ts +1 -7
- package/dist/parse/model/SecondaryInstance/sources/CSVExternalSecondaryInstance.d.ts +1 -1
- package/dist/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.d.ts +1 -1
- package/dist/parse/model/SecondaryInstance/sources/InternalSecondaryInstanceSource.d.ts +1 -1
- package/dist/parse/model/SecondaryInstance/sources/SecondaryInstanceSource.d.ts +1 -1
- package/dist/parse/model/SecondaryInstance/sources/XMLExternalSecondaryInstanceSource.d.ts +1 -1
- package/dist/parse/model/{FormSubmissionDefinition.d.ts → SubmissionDefinition.d.ts} +2 -2
- package/dist/parse/model/SubtreeDefinition.d.ts +4 -5
- package/dist/parse/model/nodeDefinitionMap.d.ts +5 -0
- package/dist/parse/shared/parseInstanceXML.d.ts +21 -0
- package/dist/parse/shared/parseStaticDocumentFromDOMSubtree.d.ts +4 -21
- package/dist/solid.js +8251 -6751
- package/dist/solid.js.map +1 -1
- package/package.json +15 -14
- package/src/client/BaseNode.ts +4 -4
- package/src/client/BaseValueNode.ts +7 -3
- package/src/client/RootNode.ts +32 -19
- package/src/client/UploadNode.ts +78 -0
- package/src/client/attachments/InstanceAttachmentMeta.ts +10 -0
- package/src/client/attachments/InstanceAttachmentsConfig.ts +13 -0
- package/src/client/constants.ts +12 -14
- package/src/client/form/CreateFormInstance.ts +19 -0
- package/src/client/form/EditFormInstance.ts +93 -0
- package/src/client/form/FormInstance.ts +114 -0
- package/src/client/form/FormInstanceConfig.ts +21 -0
- package/src/client/form/FormResource.ts +1 -0
- package/src/client/form/LoadForm.ts +92 -0
- package/src/client/form/LoadFormResult.ts +103 -0
- package/src/client/form/RestoreFormInstance.ts +14 -0
- package/src/client/hierarchy.ts +5 -8
- package/src/client/index.ts +49 -29
- package/src/client/node-types.ts +3 -8
- package/src/client/repeat/BaseRepeatRangeNode.ts +3 -4
- package/src/client/repeat/RepeatInstanceNode.ts +4 -8
- package/src/client/repeat/RepeatRangeControlledNode.ts +2 -2
- package/src/client/repeat/RepeatRangeUncontrolledNode.ts +2 -2
- package/src/client/resources.ts +2 -2
- package/src/client/serialization/InstanceData.ts +24 -0
- package/src/client/serialization/InstanceFile.ts +9 -0
- package/src/client/serialization/InstancePayload.ts +126 -0
- package/src/client/serialization/InstancePayloadOptions.ts +29 -0
- package/src/client/serialization/InstanceState.ts +14 -0
- package/src/client/submission/{SubmissionDefinition.ts → SubmissionMeta.ts} +1 -1
- package/src/entrypoints/FormInstance.ts +56 -0
- package/src/entrypoints/FormResult/BaseFormResult.ts +40 -0
- package/src/entrypoints/FormResult/BaseInstantiableFormResult.ts +109 -0
- package/src/entrypoints/FormResult/FormFailureResult.ts +44 -0
- package/src/entrypoints/FormResult/FormSuccessResult.ts +25 -0
- package/src/entrypoints/FormResult/FormWarningResult.ts +25 -0
- package/src/entrypoints/createInstance.ts +23 -0
- package/src/entrypoints/editInstance.ts +24 -0
- package/src/entrypoints/index.ts +4 -0
- package/src/entrypoints/loadForm.ts +154 -0
- package/src/entrypoints/restoreInstance.ts +27 -0
- package/src/error/LoadFormFailureError.ts +114 -0
- package/src/error/MalformedInstanceDataError.ts +3 -0
- package/src/error/TemplatedNodeAttributeSerializationError.ts +24 -0
- package/src/error/UploadValueTypeError.ts +13 -0
- package/src/index.ts +2 -46
- package/src/instance/Group.ts +16 -15
- package/src/instance/InputControl.ts +17 -11
- package/src/instance/ModelValue.ts +17 -11
- package/src/instance/Note.ts +10 -9
- package/src/instance/PrimaryInstance.ts +68 -31
- package/src/instance/RangeControl.ts +17 -11
- package/src/instance/RankControl.ts +28 -19
- package/src/instance/Root.ts +20 -31
- package/src/instance/SelectControl.ts +21 -12
- package/src/instance/Subtree.ts +16 -15
- package/src/instance/TriggerControl.ts +21 -12
- package/src/instance/UploadControl.ts +184 -0
- package/src/instance/abstract/DescendantNode.ts +12 -2
- package/src/instance/abstract/InstanceNode.ts +9 -5
- package/src/instance/abstract/ValueNode.ts +11 -13
- package/src/instance/attachments/InstanceAttachment.ts +69 -0
- package/src/instance/attachments/InstanceAttachmentsState.ts +18 -0
- package/src/instance/children/DescendantNodeInitOptions.ts +35 -0
- package/src/instance/{children.ts → children/buildChildren.ts} +57 -53
- package/src/instance/children/childrenInitOptions.ts +117 -0
- package/src/instance/children/normalizeChildInitOptions.ts +332 -0
- package/src/instance/hierarchy.ts +6 -9
- package/src/instance/input/InitialInstanceState.ts +108 -0
- package/src/instance/input/InstanceAttachmentMap.ts +154 -0
- package/src/instance/internal-api/InstanceAttachmentContext.ts +20 -0
- package/src/instance/internal-api/InstanceConfig.ts +6 -10
- package/src/instance/internal-api/InstanceValueContext.ts +9 -1
- package/src/instance/internal-api/serialization/ClientReactiveSerializableInstance.ts +22 -0
- package/src/instance/internal-api/serialization/ClientReactiveSerializableLeafNode.ts +43 -0
- package/src/instance/internal-api/serialization/ClientReactiveSerializableParentNode.ts +26 -0
- package/src/instance/internal-api/serialization/ClientReactiveSerializableTemplatedNode.ts +24 -0
- package/src/instance/internal-api/serialization/ClientReactiveSerializableValueNode.ts +28 -0
- package/src/instance/repeat/BaseRepeatRange.ts +19 -24
- package/src/instance/repeat/RepeatInstance.ts +26 -19
- package/src/instance/repeat/RepeatRangeControlled.ts +90 -17
- package/src/instance/repeat/RepeatRangeUncontrolled.ts +10 -9
- package/src/instance/resource.ts +14 -1
- package/src/integration/xpath/EngineXPathEvaluator.ts +2 -2
- package/src/integration/xpath/adapter/kind.ts +1 -28
- package/src/integration/xpath/adapter/traversal.ts +2 -2
- package/src/integration/xpath/static-dom/StaticAttribute.ts +6 -5
- package/src/integration/xpath/static-dom/StaticDocument.ts +17 -16
- package/src/integration/xpath/static-dom/StaticElement.ts +196 -50
- package/src/integration/xpath/static-dom/StaticNode.ts +1 -1
- package/src/integration/xpath/static-dom/StaticParentNode.ts +22 -0
- package/src/integration/xpath/static-dom/staticNodeName.ts +20 -0
- package/src/lib/client-reactivity/instance-state/createNodeRangeInstanceState.ts +17 -0
- package/src/lib/client-reactivity/instance-state/createParentNodeInstanceState.ts +22 -0
- package/src/lib/client-reactivity/instance-state/createPrimaryInstanceState.ts +12 -0
- package/src/lib/client-reactivity/{submission/createRootSubmissionState.ts → instance-state/createRootInstanceState.ts} +4 -4
- package/src/lib/client-reactivity/instance-state/createTemplatedNodeInstanceState.ts +31 -0
- package/src/lib/client-reactivity/instance-state/createValueNodeInstanceState.ts +21 -0
- package/src/lib/client-reactivity/instance-state/prepareInstancePayload.ts +237 -0
- package/src/lib/names/UnprefixedXFormsName.ts +12 -0
- package/src/lib/reactivity/createInstanceAttachment.ts +212 -0
- package/src/lib/reactivity/createInstanceValueState.ts +27 -51
- package/src/lib/resource-helpers.ts +33 -0
- package/src/parse/XFormDOM.ts +1 -3
- package/src/parse/body/BodyDefinition.ts +4 -0
- package/src/parse/body/control/UploadControlDefinition.ts +42 -0
- package/src/parse/model/BindDefinition.ts +1 -1
- package/src/parse/model/BindTypeDefinition.ts +68 -26
- package/src/parse/model/ItextTranslationsDefinition.ts +79 -0
- package/src/parse/model/LeafNodeDefinition.ts +3 -5
- package/src/parse/model/ModelBindMap.ts +0 -5
- package/src/parse/model/ModelDefinition.ts +36 -3
- package/src/parse/model/NodeDefinition.ts +19 -45
- package/src/parse/model/NoteNodeDefinition.ts +4 -3
- package/src/parse/model/RangeNodeDefinition.ts +3 -2
- package/src/parse/model/RepeatDefinition.ts +382 -0
- package/src/parse/model/RootAttributeDefinition.ts +6 -7
- package/src/parse/model/RootAttributeMap.ts +15 -10
- package/src/parse/model/RootDefinition.ts +17 -19
- package/src/parse/model/SecondaryInstance/SecondaryInstancesDefinition.ts +23 -2
- package/src/parse/model/SecondaryInstance/assertSecondaryInstanceDefinition.ts +14 -0
- package/src/parse/model/SecondaryInstance/defineSecondaryInstance.ts +32 -0
- package/src/parse/model/SecondaryInstance/sources/BlankSecondaryInstanceSource.ts +3 -24
- package/src/parse/model/SecondaryInstance/sources/CSVExternalSecondaryInstance.ts +33 -86
- package/src/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceResource.ts +1 -30
- package/src/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.ts +64 -137
- package/src/parse/model/SecondaryInstance/sources/InternalSecondaryInstanceSource.ts +9 -7
- package/src/parse/model/SecondaryInstance/sources/SecondaryInstanceSource.ts +1 -1
- package/src/parse/model/SecondaryInstance/sources/XMLExternalSecondaryInstanceSource.ts +7 -7
- package/src/parse/model/{FormSubmissionDefinition.ts → SubmissionDefinition.ts} +2 -2
- package/src/parse/model/SubtreeDefinition.ts +4 -5
- package/src/parse/model/nodeDefinitionMap.ts +34 -0
- package/src/parse/shared/parseInstanceXML.ts +79 -0
- package/src/parse/shared/parseStaticDocumentFromDOMSubtree.ts +45 -130
- package/dist/client/EngineConfig.d.ts +0 -79
- package/dist/client/submission/SubmissionData.d.ts +0 -7
- package/dist/client/submission/SubmissionInstanceFile.d.ts +0 -6
- package/dist/client/submission/SubmissionOptions.d.ts +0 -23
- package/dist/client/submission/SubmissionResult.d.ts +0 -91
- package/dist/client/submission/SubmissionState.d.ts +0 -12
- package/dist/client/unsupported/UnsupportedControlNode.d.ts +0 -30
- package/dist/client/unsupported/UploadNode.d.ts +0 -9
- package/dist/instance/abstract/UnsupportedControl.d.ts +0 -54
- package/dist/instance/index.d.ts +0 -8
- package/dist/instance/internal-api/ValueContext.d.ts +0 -23
- package/dist/instance/internal-api/submission/ClientReactiveSubmittableInstance.d.ts +0 -14
- package/dist/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.d.ts +0 -32
- package/dist/instance/internal-api/submission/ClientReactiveSubmittableParentNode.d.ts +0 -19
- package/dist/instance/internal-api/submission/ClientReactiveSubmittableValueNode.d.ts +0 -18
- package/dist/instance/unsupported/UploadControl.d.ts +0 -6
- package/dist/lib/client-reactivity/submission/createInstanceSubmissionState.d.ts +0 -3
- package/dist/lib/client-reactivity/submission/createLeafNodeSubmissionState.d.ts +0 -3
- package/dist/lib/client-reactivity/submission/createNodeRangeSubmissionState.d.ts +0 -4
- package/dist/lib/client-reactivity/submission/createParentNodeSubmissionState.d.ts +0 -4
- package/dist/lib/client-reactivity/submission/createRootSubmissionState.d.ts +0 -3
- package/dist/lib/client-reactivity/submission/createValueNodeSubmissionState.d.ts +0 -3
- package/dist/lib/client-reactivity/submission/prepareSubmission.d.ts +0 -8
- package/dist/lib/reactivity/createValueState.d.ts +0 -40
- package/dist/parse/model/ItextTranslation/ItextTranslationDefinition.d.ts +0 -4
- package/dist/parse/model/ItextTranslation/ItextTranslationRootDefinition.d.ts +0 -9
- package/dist/parse/model/ItextTranslation/ItextTranslationsDefinition.d.ts +0 -8
- package/dist/parse/model/RepeatInstanceDefinition.d.ts +0 -17
- package/dist/parse/model/RepeatRangeDefinition.d.ts +0 -32
- package/dist/parse/model/RepeatTemplateDefinition.d.ts +0 -31
- package/dist/parse/model/SecondaryInstance/SecondaryInstanceDefinition.d.ts +0 -4
- package/dist/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.d.ts +0 -7
- package/src/client/EngineConfig.ts +0 -84
- package/src/client/submission/SubmissionData.ts +0 -12
- package/src/client/submission/SubmissionInstanceFile.ts +0 -9
- package/src/client/submission/SubmissionOptions.ts +0 -28
- package/src/client/submission/SubmissionResult.ts +0 -124
- package/src/client/submission/SubmissionState.ts +0 -14
- package/src/client/unsupported/UnsupportedControlNode.ts +0 -36
- package/src/client/unsupported/UploadNode.ts +0 -14
- package/src/instance/abstract/UnsupportedControl.ts +0 -175
- package/src/instance/index.ts +0 -55
- package/src/instance/internal-api/ValueContext.ts +0 -28
- package/src/instance/internal-api/submission/ClientReactiveSubmittableInstance.ts +0 -20
- package/src/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.ts +0 -43
- package/src/instance/internal-api/submission/ClientReactiveSubmittableParentNode.ts +0 -26
- package/src/instance/internal-api/submission/ClientReactiveSubmittableValueNode.ts +0 -24
- package/src/instance/unsupported/UploadControl.ts +0 -9
- package/src/lib/client-reactivity/submission/createInstanceSubmissionState.ts +0 -12
- package/src/lib/client-reactivity/submission/createLeafNodeSubmissionState.ts +0 -20
- package/src/lib/client-reactivity/submission/createNodeRangeSubmissionState.ts +0 -17
- package/src/lib/client-reactivity/submission/createParentNodeSubmissionState.ts +0 -22
- package/src/lib/client-reactivity/submission/createValueNodeSubmissionState.ts +0 -21
- package/src/lib/client-reactivity/submission/prepareSubmission.ts +0 -172
- package/src/lib/reactivity/createValueState.ts +0 -200
- package/src/parse/model/ItextTranslation/ItextTranslationDefinition.ts +0 -4
- package/src/parse/model/ItextTranslation/ItextTranslationRootDefinition.ts +0 -42
- package/src/parse/model/ItextTranslation/ItextTranslationsDefinition.ts +0 -31
- package/src/parse/model/RepeatInstanceDefinition.ts +0 -38
- package/src/parse/model/RepeatRangeDefinition.ts +0 -98
- package/src/parse/model/RepeatTemplateDefinition.ts +0 -149
- package/src/parse/model/SecondaryInstance/SecondaryInstanceDefinition.ts +0 -4
- package/src/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.ts +0 -12
|
@@ -11,9 +11,11 @@ import type {
|
|
|
11
11
|
} from '../../integration/xpath/adapter/XFormsXPathNode.ts';
|
|
12
12
|
import { XFORMS_XPATH_NODE_RANGE_KIND } from '../../integration/xpath/adapter/XFormsXPathNode.ts';
|
|
13
13
|
import type { EngineXPathEvaluator } from '../../integration/xpath/EngineXPathEvaluator.ts';
|
|
14
|
+
import type { StaticElement } from '../../integration/xpath/static-dom/StaticElement.ts';
|
|
14
15
|
import { createComputedExpression } from '../../lib/reactivity/createComputedExpression.ts';
|
|
15
16
|
import type { ReactiveScope } from '../../lib/reactivity/scope.ts';
|
|
16
17
|
import type { AnyNodeDefinition } from '../../parse/model/NodeDefinition.ts';
|
|
18
|
+
import type { DescendantNodeInitOptions } from '../children/DescendantNodeInitOptions.ts';
|
|
17
19
|
import type { AnyChildNode, AnyParentNode, RepeatRange } from '../hierarchy.ts';
|
|
18
20
|
import type { EvaluationContext } from '../internal-api/EvaluationContext.ts';
|
|
19
21
|
import type { RepeatInstance } from '../repeat/RepeatInstance.ts';
|
|
@@ -50,6 +52,13 @@ interface DescendantNodeOptions {
|
|
|
50
52
|
readonly computeReference?: Accessor<string>;
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
/**
|
|
56
|
+
* @todo Unify constructor signatures of {@link DescendantNode} and its
|
|
57
|
+
* subclasses, which will simplify the branchy logic of child node construction
|
|
58
|
+
* and minimize internal churn as common themes evolve. A good starting point is
|
|
59
|
+
* beginning to form in {@link DescendantNodeInitOptions} (not to be confused
|
|
60
|
+
* with the current module-local {@link DescendantNodeOptions}).
|
|
61
|
+
*/
|
|
53
62
|
export abstract class DescendantNode<
|
|
54
63
|
Definition extends DescendantNodeDefinition,
|
|
55
64
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -128,10 +137,11 @@ export abstract class DescendantNode<
|
|
|
128
137
|
|
|
129
138
|
constructor(
|
|
130
139
|
override readonly parent: Parent,
|
|
140
|
+
override readonly instanceNode: StaticElement | null,
|
|
131
141
|
override readonly definition: Definition,
|
|
132
142
|
options?: DescendantNodeOptions
|
|
133
143
|
) {
|
|
134
|
-
super(parent.
|
|
144
|
+
super(parent.instanceConfig, parent, instanceNode, definition, options);
|
|
135
145
|
|
|
136
146
|
if (this.isRoot()) {
|
|
137
147
|
this.root = this;
|
|
@@ -142,7 +152,7 @@ export abstract class DescendantNode<
|
|
|
142
152
|
const { evaluator } = parent;
|
|
143
153
|
|
|
144
154
|
// See notes on property declaration
|
|
145
|
-
if (definition.type === 'repeat
|
|
155
|
+
if (definition.type === 'repeat') {
|
|
146
156
|
this[XPathNodeKindKey] = XFORMS_XPATH_NODE_RANGE_KIND;
|
|
147
157
|
} else {
|
|
148
158
|
this[XPathNodeKindKey] = 'element';
|
|
@@ -4,7 +4,7 @@ import type { BaseNode } from '../../client/BaseNode.ts';
|
|
|
4
4
|
import type { NodeAppearances } from '../../client/NodeAppearances.ts';
|
|
5
5
|
import type { FormNodeID } from '../../client/identity.ts';
|
|
6
6
|
import type { InstanceNodeType as ClientInstanceNodeType } from '../../client/node-types.ts';
|
|
7
|
-
import type {
|
|
7
|
+
import type { InstanceState } from '../../client/serialization/InstanceState.ts';
|
|
8
8
|
import type { NodeValidationState } from '../../client/validation.ts';
|
|
9
9
|
import type { ActiveLanguage, TextRange } from '../../index.ts';
|
|
10
10
|
import type { EngineXPathEvaluator } from '../../integration/xpath/EngineXPathEvaluator.ts';
|
|
@@ -13,6 +13,8 @@ import type {
|
|
|
13
13
|
XFormsXPathPrimaryInstanceNodeKind,
|
|
14
14
|
} from '../../integration/xpath/adapter/XFormsXPathNode.ts';
|
|
15
15
|
import type { PrimaryInstanceXPathNode } from '../../integration/xpath/adapter/kind.ts';
|
|
16
|
+
import type { StaticDocument } from '../../integration/xpath/static-dom/StaticDocument.ts';
|
|
17
|
+
import type { StaticElement } from '../../integration/xpath/static-dom/StaticElement.ts';
|
|
16
18
|
import type { MaterializedChildren } from '../../lib/reactivity/materializeCurrentStateChildren.ts';
|
|
17
19
|
import type { CurrentState } from '../../lib/reactivity/node-state/createCurrentState.ts';
|
|
18
20
|
import type { EngineState } from '../../lib/reactivity/node-state/createEngineState.ts';
|
|
@@ -20,6 +22,7 @@ import type { SharedNodeState } from '../../lib/reactivity/node-state/createShar
|
|
|
20
22
|
import type { ReactiveScope } from '../../lib/reactivity/scope.ts';
|
|
21
23
|
import { createReactiveScope } from '../../lib/reactivity/scope.ts';
|
|
22
24
|
import type { SimpleAtomicState } from '../../lib/reactivity/types.ts';
|
|
25
|
+
import { createUniqueId } from '../../lib/unique-id.ts';
|
|
23
26
|
import type { AnyNodeDefinition } from '../../parse/model/NodeDefinition.ts';
|
|
24
27
|
import type { PrimaryInstance } from '../PrimaryInstance.ts';
|
|
25
28
|
import type { Root } from '../Root.ts';
|
|
@@ -148,7 +151,7 @@ export abstract class InstanceNode<
|
|
|
148
151
|
|
|
149
152
|
abstract readonly validationState: NodeValidationState;
|
|
150
153
|
|
|
151
|
-
abstract readonly
|
|
154
|
+
abstract readonly instanceState: InstanceState;
|
|
152
155
|
|
|
153
156
|
// EvaluationContext: instance-global/shared
|
|
154
157
|
abstract readonly evaluator: EngineXPathEvaluator;
|
|
@@ -186,8 +189,9 @@ export abstract class InstanceNode<
|
|
|
186
189
|
this as AnyInstanceNode as PrimaryInstanceXPathNode;
|
|
187
190
|
|
|
188
191
|
constructor(
|
|
189
|
-
readonly
|
|
192
|
+
readonly instanceConfig: InstanceConfig,
|
|
190
193
|
readonly parent: Parent,
|
|
194
|
+
readonly instanceNode: StaticDocument | StaticElement | null,
|
|
191
195
|
readonly definition: Definition,
|
|
192
196
|
options?: InstanceNodeOptions
|
|
193
197
|
) {
|
|
@@ -208,8 +212,8 @@ export abstract class InstanceNode<
|
|
|
208
212
|
this.computeReference = options?.computeReference ?? this.computeChildStepReference;
|
|
209
213
|
|
|
210
214
|
this.scope = options?.scope ?? createReactiveScope();
|
|
211
|
-
this.
|
|
212
|
-
this.nodeId = nodeID(
|
|
215
|
+
this.instanceConfig = instanceConfig;
|
|
216
|
+
this.nodeId = nodeID(createUniqueId());
|
|
213
217
|
this.definition = definition;
|
|
214
218
|
}
|
|
215
219
|
|
|
@@ -2,11 +2,12 @@ import { XPathNodeKindKey } from '@getodk/xpath';
|
|
|
2
2
|
import type { Accessor } from 'solid-js';
|
|
3
3
|
import type { BaseValueNode } from '../../client/BaseValueNode.ts';
|
|
4
4
|
import type { LeafNodeType as ValueNodeType } from '../../client/node-types.ts';
|
|
5
|
-
import type {
|
|
5
|
+
import type { InstanceState } from '../../client/serialization/InstanceState.ts';
|
|
6
6
|
import type { AnyViolation, LeafNodeValidationState } from '../../client/validation.ts';
|
|
7
7
|
import type { ValueType } from '../../client/ValueType.ts';
|
|
8
8
|
import type { XFormsXPathElement } from '../../integration/xpath/adapter/XFormsXPathNode.ts';
|
|
9
|
-
import {
|
|
9
|
+
import type { StaticLeafElement } from '../../integration/xpath/static-dom/StaticElement.ts';
|
|
10
|
+
import { createValueNodeInstanceState } from '../../lib/client-reactivity/instance-state/createValueNodeInstanceState.ts';
|
|
10
11
|
import type {
|
|
11
12
|
RuntimeValueSetter,
|
|
12
13
|
RuntimeValueState,
|
|
@@ -26,7 +27,7 @@ import type {
|
|
|
26
27
|
DecodeInstanceValue,
|
|
27
28
|
InstanceValueContext,
|
|
28
29
|
} from '../internal-api/InstanceValueContext.ts';
|
|
29
|
-
import type {
|
|
30
|
+
import type { ClientReactiveSerializableValueNode } from '../internal-api/serialization/ClientReactiveSerializableValueNode.ts';
|
|
30
31
|
import type { ValidationContext } from '../internal-api/ValidationContext.ts';
|
|
31
32
|
import type { DescendantNodeStateSpec } from './DescendantNode.ts';
|
|
32
33
|
import { DescendantNode } from './DescendantNode.ts';
|
|
@@ -52,7 +53,7 @@ export abstract class ValueNode<
|
|
|
52
53
|
EvaluationContext,
|
|
53
54
|
InstanceValueContext,
|
|
54
55
|
ValidationContext,
|
|
55
|
-
|
|
56
|
+
ClientReactiveSerializableValueNode
|
|
56
57
|
{
|
|
57
58
|
protected readonly validation: SharedValidationState;
|
|
58
59
|
protected readonly getInstanceValue: Accessor<string>;
|
|
@@ -80,21 +81,20 @@ export abstract class ValueNode<
|
|
|
80
81
|
return this.validation.currentState;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
readonly
|
|
84
|
+
readonly instanceState: InstanceState;
|
|
84
85
|
|
|
85
86
|
constructor(
|
|
86
87
|
parent: GeneralParentNode,
|
|
88
|
+
override readonly instanceNode: StaticLeafElement | null,
|
|
87
89
|
definition: Definition,
|
|
88
90
|
codec: ValueCodec<V, RuntimeValue, RuntimeInputValue>
|
|
89
91
|
) {
|
|
90
|
-
super(parent, definition);
|
|
92
|
+
super(parent, instanceNode, definition);
|
|
91
93
|
|
|
92
94
|
this.valueType = definition.valueType;
|
|
93
95
|
this.decodeInstanceValue = codec.decodeInstanceValue;
|
|
94
96
|
|
|
95
|
-
const instanceValueState = createInstanceValueState(this
|
|
96
|
-
initialValueSource: 'FORM_DEFAULT',
|
|
97
|
-
});
|
|
97
|
+
const instanceValueState = createInstanceValueState(this);
|
|
98
98
|
const valueState = codec.createRuntimeValueState(instanceValueState);
|
|
99
99
|
|
|
100
100
|
const [getInstanceValue] = instanceValueState;
|
|
@@ -106,10 +106,8 @@ export abstract class ValueNode<
|
|
|
106
106
|
return this.getInstanceValue();
|
|
107
107
|
};
|
|
108
108
|
this.valueState = valueState;
|
|
109
|
-
this.validation = createValidationState(this,
|
|
110
|
-
|
|
111
|
-
});
|
|
112
|
-
this.submissionState = createValueNodeSubmissionState(this);
|
|
109
|
+
this.validation = createValidationState(this, this.instanceConfig);
|
|
110
|
+
this.instanceState = createValueNodeInstanceState(this);
|
|
113
111
|
}
|
|
114
112
|
|
|
115
113
|
// ValidationContext
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Accessor } from 'solid-js';
|
|
2
|
+
import type { InstancePayload } from '../../client/index.ts';
|
|
3
|
+
import type { SimpleAtomicState, SimpleAtomicStateSetter } from '../../lib/reactivity/types.ts';
|
|
4
|
+
import type { InstanceAttachmentContext } from '../internal-api/InstanceAttachmentContext.ts';
|
|
5
|
+
import type { DecodeInstanceValue } from '../internal-api/InstanceValueContext.ts';
|
|
6
|
+
import type { InstanceAttachmentsState } from './InstanceAttachmentsState.ts';
|
|
7
|
+
|
|
8
|
+
export type InstanceAttachmentFileName = string;
|
|
9
|
+
export type InstanceAttachmentRuntimeValue = File | null;
|
|
10
|
+
|
|
11
|
+
export interface InstanceAttachmentOptions {
|
|
12
|
+
readonly getFileName: Accessor<InstanceAttachmentFileName | null>;
|
|
13
|
+
readonly getInstanceValue: Accessor<InstanceAttachmentFileName>;
|
|
14
|
+
readonly decodeInstanceValue: DecodeInstanceValue;
|
|
15
|
+
|
|
16
|
+
readonly getValue: Accessor<InstanceAttachmentRuntimeValue>;
|
|
17
|
+
readonly setValue: SimpleAtomicStateSetter<InstanceAttachmentRuntimeValue>;
|
|
18
|
+
readonly valueState: SimpleAtomicState<InstanceAttachmentRuntimeValue>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class InstanceAttachment {
|
|
22
|
+
/**
|
|
23
|
+
* 1. Creates {@link InstanceAttachment | attachment state} from
|
|
24
|
+
* {@link InstanceAttachmentOptions}
|
|
25
|
+
* 2. Registers that attachment state in an instance-global
|
|
26
|
+
* {@link InstanceAttachmentsState} entry
|
|
27
|
+
*
|
|
28
|
+
* This allows an instance to:
|
|
29
|
+
*
|
|
30
|
+
* - Produce distinct file names for each attachment
|
|
31
|
+
* - Track all attachments so they can be serialized in an
|
|
32
|
+
* {@link InstancePayload}
|
|
33
|
+
*/
|
|
34
|
+
static init(
|
|
35
|
+
context: InstanceAttachmentContext,
|
|
36
|
+
options: InstanceAttachmentOptions
|
|
37
|
+
): InstanceAttachment {
|
|
38
|
+
const attachment = new this(options);
|
|
39
|
+
const { attachments } = context.rootDocument;
|
|
40
|
+
|
|
41
|
+
attachments.set(context, attachment);
|
|
42
|
+
|
|
43
|
+
return attachment;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* This property isn't used at runtime. It causes TypeScript to treat
|
|
48
|
+
* {@link InstanceAttachment} as a nominal type, ensuring
|
|
49
|
+
* {@link InstanceAttachment.init} is called to instantiate it.
|
|
50
|
+
*/
|
|
51
|
+
protected readonly _ = null;
|
|
52
|
+
|
|
53
|
+
readonly getFileName: Accessor<InstanceAttachmentFileName | null>;
|
|
54
|
+
readonly getInstanceValue: Accessor<InstanceAttachmentFileName>;
|
|
55
|
+
readonly decodeInstanceValue: DecodeInstanceValue;
|
|
56
|
+
|
|
57
|
+
readonly getValue: Accessor<InstanceAttachmentRuntimeValue>;
|
|
58
|
+
readonly setValue: SimpleAtomicStateSetter<InstanceAttachmentRuntimeValue>;
|
|
59
|
+
readonly valueState: SimpleAtomicState<InstanceAttachmentRuntimeValue>;
|
|
60
|
+
|
|
61
|
+
private constructor(options: InstanceAttachmentOptions) {
|
|
62
|
+
this.getFileName = options.getFileName;
|
|
63
|
+
this.getInstanceValue = options.getInstanceValue;
|
|
64
|
+
this.decodeInstanceValue = options.decodeInstanceValue;
|
|
65
|
+
this.getValue = options.getValue;
|
|
66
|
+
this.setValue = options.setValue;
|
|
67
|
+
this.valueState = options.valueState;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { StaticLeafElement } from '../../integration/xpath/static-dom/StaticElement.ts';
|
|
2
|
+
import type { InstanceAttachmentMap } from '../input/InstanceAttachmentMap.ts';
|
|
3
|
+
import type { InstanceAttachmentContext } from '../internal-api/InstanceAttachmentContext.ts';
|
|
4
|
+
import type { InstanceAttachment, InstanceAttachmentRuntimeValue } from './InstanceAttachment.ts';
|
|
5
|
+
|
|
6
|
+
export class InstanceAttachmentsState extends Map<InstanceAttachmentContext, InstanceAttachment> {
|
|
7
|
+
constructor(private readonly sourceAttachments: InstanceAttachmentMap | null = null) {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
getInitialFileValue(instanceNode: StaticLeafElement | null): InstanceAttachmentRuntimeValue {
|
|
12
|
+
if (instanceNode == null) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return this.sourceAttachments?.get(instanceNode.value) ?? null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { StaticElement } from '../../integration/xpath/static-dom/StaticElement.ts';
|
|
2
|
+
import type { ChildNodeDefinition } from '../../parse/model/NodeDefinition.ts';
|
|
3
|
+
import type { DescendantNode } from '../abstract/DescendantNode.ts';
|
|
4
|
+
import type { childrenInitOptions } from './childrenInitOptions.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @todo We could pretty significantly simplify downstream child node
|
|
8
|
+
* construction logic, if we break this down into a tagged union (essentially
|
|
9
|
+
* moving the branchy type refinement aspects up the stack, probably trimming
|
|
10
|
+
* the construction logic itself down to a switch statement). At which point,
|
|
11
|
+
* it'd also probably be easier to reason about each of those constructors
|
|
12
|
+
* accepting input exactly as it's represented as a member of this hypothetical
|
|
13
|
+
* tagged union. Something like this:
|
|
14
|
+
*
|
|
15
|
+
* - Revise each concrete {@link DescendantNode} class to accept an options-like
|
|
16
|
+
* object suitable for its construction, each respectively defined by an
|
|
17
|
+
* interface whose name is consistent with that node
|
|
18
|
+
* - Update this type to be a union of those interfaces
|
|
19
|
+
* - Implement that in {@link childrenInitOptions}
|
|
20
|
+
* - Update downstream construction to switch over whatever narrows the union
|
|
21
|
+
* - Bonus points: revise each concrete {@link DescendantNode} to use a common
|
|
22
|
+
* constructor API (i.e. a static `from` method, since several such classes
|
|
23
|
+
* already have private constructors). Then downstream isn't even a switch
|
|
24
|
+
* statement, it's just a lookup table.
|
|
25
|
+
*
|
|
26
|
+
* @todo As of this commit, and as now mentioned on {@link DescendantNode}, and
|
|
27
|
+
* as discussed in
|
|
28
|
+
* {@link https://github.com/getodk/web-forms/pull/352#discussion_r2008237762}:
|
|
29
|
+
* this interface is intended as an intermediate step toward these goals.
|
|
30
|
+
*/
|
|
31
|
+
export interface DescendantNodeInitOptions {
|
|
32
|
+
readonly childNodeset: string;
|
|
33
|
+
readonly definition: ChildNodeDefinition;
|
|
34
|
+
readonly instanceNodes: readonly StaticElement[];
|
|
35
|
+
}
|
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
import { UnreachableError } from '@getodk/common/lib/error/UnreachableError.ts';
|
|
2
|
-
import type { GroupDefinition } from '
|
|
3
|
-
import type { InputDefinition } from '
|
|
4
|
-
import type { ModelValueDefinition } from '
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
10
|
-
import { ErrorProductionDesignPendingError } from '
|
|
11
|
-
import type { LeafNodeDefinition } from '
|
|
12
|
-
import { NoteNodeDefinition } from '
|
|
2
|
+
import type { GroupDefinition } from '../../client/GroupNode.ts';
|
|
3
|
+
import type { InputDefinition } from '../../client/InputNode.ts';
|
|
4
|
+
import type { ModelValueDefinition } from '../../client/ModelValueNode.ts';
|
|
5
|
+
import type { RankDefinition } from '../../client/RankNode.ts';
|
|
6
|
+
import type { SelectDefinition } from '../../client/SelectNode.ts';
|
|
7
|
+
import type { SubtreeDefinition } from '../../client/SubtreeNode.ts';
|
|
8
|
+
import type { TriggerNodeDefinition } from '../../client/TriggerNode.ts';
|
|
9
|
+
import type { UploadDefinition } from '../../client/UploadNode.ts';
|
|
10
|
+
import { ErrorProductionDesignPendingError } from '../../error/ErrorProductionDesignPendingError.ts';
|
|
11
|
+
import type { LeafNodeDefinition } from '../../parse/model/LeafNodeDefinition.ts';
|
|
12
|
+
import { NoteNodeDefinition } from '../../parse/model/NoteNodeDefinition.ts';
|
|
13
13
|
import type {
|
|
14
14
|
AnyRangeNodeDefinition,
|
|
15
15
|
RangeLeafNodeDefinition,
|
|
16
|
-
} from '
|
|
17
|
-
import { RangeNodeDefinition } from '
|
|
18
|
-
import type { SubtreeDefinition as ModelSubtreeDefinition } from '
|
|
19
|
-
import { Group } from '
|
|
20
|
-
import type { GeneralChildNode, GeneralParentNode } from '
|
|
21
|
-
import { InputControl } from '
|
|
22
|
-
import { ModelValue } from '
|
|
23
|
-
import { Note } from '
|
|
24
|
-
import { RangeControl } from '
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import { UploadControl } from '
|
|
16
|
+
} from '../../parse/model/RangeNodeDefinition.ts';
|
|
17
|
+
import { RangeNodeDefinition } from '../../parse/model/RangeNodeDefinition.ts';
|
|
18
|
+
import type { SubtreeDefinition as ModelSubtreeDefinition } from '../../parse/model/SubtreeDefinition.ts';
|
|
19
|
+
import { Group } from '../Group.ts';
|
|
20
|
+
import type { GeneralChildNode, GeneralParentNode } from '../hierarchy.ts';
|
|
21
|
+
import { InputControl } from '../InputControl.ts';
|
|
22
|
+
import { ModelValue } from '../ModelValue.ts';
|
|
23
|
+
import { Note } from '../Note.ts';
|
|
24
|
+
import { RangeControl } from '../RangeControl.ts';
|
|
25
|
+
import { RankControl } from '../RankControl.ts';
|
|
26
|
+
import { RepeatRangeControlled } from '../repeat/RepeatRangeControlled.ts';
|
|
27
|
+
import { RepeatRangeUncontrolled } from '../repeat/RepeatRangeUncontrolled.ts';
|
|
28
|
+
import { SelectControl } from '../SelectControl.ts';
|
|
29
|
+
import { Subtree } from '../Subtree.ts';
|
|
30
|
+
import { TriggerControl } from '../TriggerControl.ts';
|
|
31
|
+
import { UploadControl } from '../UploadControl.ts';
|
|
32
|
+
import { childrenInitOptions } from './childrenInitOptions.ts';
|
|
32
33
|
|
|
33
34
|
const isSubtreeDefinition = (
|
|
34
35
|
definition: ModelSubtreeDefinition
|
|
@@ -36,9 +37,6 @@ const isSubtreeDefinition = (
|
|
|
36
37
|
return definition.bodyElement == null;
|
|
37
38
|
};
|
|
38
39
|
|
|
39
|
-
// prettier-ignore
|
|
40
|
-
type AnyUnsupportedControlDefinition = UploadNodeDefinition;
|
|
41
|
-
|
|
42
40
|
// prettier-ignore
|
|
43
41
|
type ControlNodeDefinition =
|
|
44
42
|
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
@@ -47,7 +45,7 @@ type ControlNodeDefinition =
|
|
|
47
45
|
| SelectDefinition
|
|
48
46
|
| RankDefinition
|
|
49
47
|
| TriggerNodeDefinition
|
|
50
|
-
|
|
|
48
|
+
| UploadDefinition;
|
|
51
49
|
|
|
52
50
|
type AnyLeafNodeDefinition = ControlNodeDefinition | ModelValueDefinition;
|
|
53
51
|
|
|
@@ -122,77 +120,83 @@ const isTriggerNodeDefinition = (
|
|
|
122
120
|
|
|
123
121
|
const isUploadNodeDefinition = (
|
|
124
122
|
definition: ControlNodeDefinition
|
|
125
|
-
): definition is
|
|
123
|
+
): definition is UploadDefinition => {
|
|
126
124
|
return definition.bodyElement.type === 'upload';
|
|
127
125
|
};
|
|
128
126
|
|
|
129
127
|
export const buildChildren = (parent: GeneralParentNode): GeneralChildNode[] => {
|
|
130
|
-
const { children } = parent
|
|
128
|
+
const { children } = childrenInitOptions(parent);
|
|
129
|
+
|
|
130
|
+
return children.map(({ instanceNodes, definition }): GeneralChildNode => {
|
|
131
|
+
const [instanceNode = null] = instanceNodes;
|
|
131
132
|
|
|
132
|
-
|
|
133
|
-
switch (child.type) {
|
|
133
|
+
switch (definition.type) {
|
|
134
134
|
case 'subtree': {
|
|
135
|
-
if (isSubtreeDefinition(
|
|
136
|
-
return new Subtree(parent,
|
|
135
|
+
if (isSubtreeDefinition(definition)) {
|
|
136
|
+
return new Subtree(parent, instanceNode, definition);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
// TODO: it'd be good to be able to do without this type assertion. The
|
|
140
140
|
// only distinction between the types is whether `bodyElement` is
|
|
141
141
|
// `null`, but for some reason that's insufficient to narrow the union.
|
|
142
|
-
return new Group(parent,
|
|
142
|
+
return new Group(parent, instanceNode, definition as GroupDefinition);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
case 'repeat
|
|
146
|
-
if (
|
|
147
|
-
return new RepeatRangeControlled(parent,
|
|
145
|
+
case 'repeat': {
|
|
146
|
+
if (definition.isControlled()) {
|
|
147
|
+
return new RepeatRangeControlled(parent, instanceNodes, definition);
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
return new RepeatRangeUncontrolled(parent,
|
|
150
|
+
return new RepeatRangeUncontrolled(parent, instanceNodes, definition);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
case 'leaf-node': {
|
|
154
|
-
if (
|
|
155
|
-
|
|
154
|
+
if (instanceNode != null && !instanceNode.isLeafElement()) {
|
|
155
|
+
throw new ErrorProductionDesignPendingError();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (definition instanceof NoteNodeDefinition) {
|
|
159
|
+
return new Note(parent, instanceNode, definition);
|
|
156
160
|
}
|
|
157
161
|
|
|
158
162
|
// More specific type helps with narrowing below
|
|
159
|
-
const leafChild: AnyLeafNodeDefinition =
|
|
163
|
+
const leafChild: AnyLeafNodeDefinition = definition;
|
|
160
164
|
|
|
161
165
|
if (isModelValueDefinition(leafChild)) {
|
|
162
|
-
return ModelValue.from(parent, leafChild);
|
|
166
|
+
return ModelValue.from(parent, instanceNode, leafChild);
|
|
163
167
|
}
|
|
164
168
|
|
|
165
169
|
if (isInputDefinition(leafChild)) {
|
|
166
|
-
return InputControl.from(parent, leafChild);
|
|
170
|
+
return InputControl.from(parent, instanceNode, leafChild);
|
|
167
171
|
}
|
|
168
172
|
|
|
169
173
|
if (isSelectDefinition(leafChild)) {
|
|
170
|
-
return SelectControl.from(parent, leafChild);
|
|
174
|
+
return SelectControl.from(parent, instanceNode, leafChild);
|
|
171
175
|
}
|
|
172
176
|
|
|
173
177
|
if (isRankDefinition(leafChild)) {
|
|
174
|
-
return RankControl.from(parent, leafChild);
|
|
178
|
+
return RankControl.from(parent, instanceNode, leafChild);
|
|
175
179
|
}
|
|
176
180
|
|
|
177
181
|
if (isTriggerNodeDefinition(leafChild)) {
|
|
178
|
-
return TriggerControl.from(parent, leafChild);
|
|
182
|
+
return TriggerControl.from(parent, instanceNode, leafChild);
|
|
179
183
|
}
|
|
180
184
|
|
|
181
185
|
if (isRangeLeafNodeDefinition(leafChild)) {
|
|
182
186
|
assertRangeNodeDefinition(leafChild);
|
|
183
187
|
|
|
184
|
-
return RangeControl.from(parent, leafChild);
|
|
188
|
+
return RangeControl.from(parent, instanceNode, leafChild);
|
|
185
189
|
}
|
|
186
190
|
|
|
187
191
|
if (isUploadNodeDefinition(leafChild)) {
|
|
188
|
-
return
|
|
192
|
+
return UploadControl.from(parent, instanceNode, leafChild);
|
|
189
193
|
}
|
|
190
194
|
|
|
191
195
|
throw new UnreachableError(leafChild);
|
|
192
196
|
}
|
|
193
197
|
|
|
194
198
|
default: {
|
|
195
|
-
throw new UnreachableError(
|
|
199
|
+
throw new UnreachableError(definition);
|
|
196
200
|
}
|
|
197
201
|
}
|
|
198
202
|
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { StaticDocument } from '../../integration/xpath/static-dom/StaticDocument.ts';
|
|
2
|
+
import type { StaticElement } from '../../integration/xpath/static-dom/StaticElement.ts';
|
|
3
|
+
import type { ModelDefinition } from '../../parse/model/ModelDefinition.ts';
|
|
4
|
+
import type {
|
|
5
|
+
AnyNodeDefinition,
|
|
6
|
+
ChildNodeDefinition,
|
|
7
|
+
NodeDefinition,
|
|
8
|
+
} from '../../parse/model/NodeDefinition.ts';
|
|
9
|
+
import type { InstanceNode } from '../abstract/InstanceNode.ts';
|
|
10
|
+
import type { GeneralParentNode } from '../hierarchy.ts';
|
|
11
|
+
import type { DescendantNodeInitOptions } from './DescendantNodeInitOptions.ts';
|
|
12
|
+
import { normalizeChildInitOptions } from './normalizeChildInitOptions.ts';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Child nodesets are collected from the {@link parent}'s
|
|
16
|
+
* {@link NodeDefinition.template}, ensuring that we produce
|
|
17
|
+
* {@link InstanceNode}s for every **model-defined** node, even if a
|
|
18
|
+
* corresponding node was not serialized in a {@link parent.instanceNode}.
|
|
19
|
+
*
|
|
20
|
+
* In other words, by referencing the model-defined template, we are able to
|
|
21
|
+
* reproduce nodes which were omitted as non-relevant in a prior serialization
|
|
22
|
+
* and/or submission.
|
|
23
|
+
*
|
|
24
|
+
* @todo Since we're building an instance node's children from the nodesets of
|
|
25
|
+
* the model-defined node's children, we are _implicitly dropping_ any excess
|
|
26
|
+
* nodes from non-model instance data. That's probably the right behavior, but
|
|
27
|
+
* we may want to warn for such nodes if/when we do drop them.
|
|
28
|
+
*/
|
|
29
|
+
const collectModelChildNodesets = (parentTemplate: StaticElement): readonly string[] => {
|
|
30
|
+
const nodesets = parentTemplate.childElements.map(({ nodeset }) => {
|
|
31
|
+
return nodeset;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return Array.from(new Set(nodesets));
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type InstanceNodesByNodeset = ReadonlyMap<string, readonly [StaticElement, ...StaticElement[]]>;
|
|
38
|
+
|
|
39
|
+
const groupChildElementsByNodeset = (
|
|
40
|
+
parent: StaticDocument | StaticElement
|
|
41
|
+
): InstanceNodesByNodeset => {
|
|
42
|
+
const result = new Map<string, [StaticElement, ...StaticElement[]]>();
|
|
43
|
+
|
|
44
|
+
for (const child of parent.childElements) {
|
|
45
|
+
const { nodeset } = child;
|
|
46
|
+
const group = result.get(nodeset);
|
|
47
|
+
|
|
48
|
+
if (group == null) {
|
|
49
|
+
result.set(nodeset, [child]);
|
|
50
|
+
} else {
|
|
51
|
+
group.push(child);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type AssertChildNodeDefinition = (
|
|
59
|
+
definition: AnyNodeDefinition,
|
|
60
|
+
childNodeset: string
|
|
61
|
+
) => asserts definition is ChildNodeDefinition;
|
|
62
|
+
|
|
63
|
+
const assertChildNodeDefinition: AssertChildNodeDefinition = (definition, childNodeset) => {
|
|
64
|
+
if (definition.type === 'root') {
|
|
65
|
+
throw new Error(`Unexpected root definition for child nodeset: ${childNodeset}`);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export interface ChildrenInitOptions {
|
|
70
|
+
readonly parent: GeneralParentNode;
|
|
71
|
+
readonly model: ModelDefinition;
|
|
72
|
+
readonly children: readonly DescendantNodeInitOptions[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const childrenInitOptions = (parent: GeneralParentNode): ChildrenInitOptions => {
|
|
76
|
+
const { model } = parent.rootDocument;
|
|
77
|
+
const childNodesets = collectModelChildNodesets(parent.definition.template);
|
|
78
|
+
|
|
79
|
+
let instanceChildren: InstanceNodesByNodeset | null;
|
|
80
|
+
|
|
81
|
+
if (parent.instanceNode == null) {
|
|
82
|
+
instanceChildren = null;
|
|
83
|
+
} else {
|
|
84
|
+
instanceChildren = groupChildElementsByNodeset(parent.instanceNode);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const children = childNodesets.map((childNodeset) => {
|
|
88
|
+
const definition = model.getNodeDefinition(childNodeset);
|
|
89
|
+
|
|
90
|
+
assertChildNodeDefinition(definition, childNodeset);
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get children of the target nodeset from {@link parent.instanceNode}, if
|
|
94
|
+
* that node exists, and if children with that nodeset exist.
|
|
95
|
+
*
|
|
96
|
+
* If either does not exist (e.g. it was omitted as non-relevant in a prior
|
|
97
|
+
* serialization), we continue to reference model-defined templates as we
|
|
98
|
+
* recurse down the {@link InstanceNode} subtree.
|
|
99
|
+
*
|
|
100
|
+
* @see {@link childNodesets}
|
|
101
|
+
*/
|
|
102
|
+
const instanceNodes = instanceChildren?.get(childNodeset) ?? [];
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
childNodeset,
|
|
106
|
+
definition,
|
|
107
|
+
instanceNodes,
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
const baseResult: ChildrenInitOptions = {
|
|
111
|
+
parent,
|
|
112
|
+
model,
|
|
113
|
+
children,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return normalizeChildInitOptions(baseResult);
|
|
117
|
+
};
|