@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
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { createComputed, createMemo, createSignal, untrack, type Signal } from 'solid-js';
|
|
2
|
-
import { ErrorProductionDesignPendingError } from '../../error/ErrorProductionDesignPendingError.ts';
|
|
3
|
-
import type { ValueContext } from '../../instance/internal-api/ValueContext.ts';
|
|
4
|
-
import type { BindComputationExpression } from '../../parse/expression/BindComputationExpression.ts';
|
|
5
|
-
import { createComputedExpression } from './createComputedExpression.ts';
|
|
6
|
-
import type { SimpleAtomicState, SimpleAtomicStateSetter } from './types.ts';
|
|
7
|
-
|
|
8
|
-
type InitialValueSource = 'FORM_DEFAULT' | 'PRIMARY_INSTANCE';
|
|
9
|
-
|
|
10
|
-
export interface ValueStateOptions {
|
|
11
|
-
/**
|
|
12
|
-
* Specifies the source of a {@link createValueState} signal's initial
|
|
13
|
-
* value state, where:
|
|
14
|
-
*
|
|
15
|
-
* - 'FORM_DEFAULT': Derives the initial state from the form's
|
|
16
|
-
* definition of the node itself. This is the default option, appropriate
|
|
17
|
-
* when initializing a form without additional primary instance data. In
|
|
18
|
-
* other words, this value should not be used for edits.
|
|
19
|
-
*
|
|
20
|
-
* - 'PRIMARY_INSTANCE': Derives the initial state from the current text
|
|
21
|
-
* content of the {@link ValueNode.contextNode}. This option
|
|
22
|
-
* should be specified when initializing a form with existing primary
|
|
23
|
-
* instance data, such as when editing a previous submission.
|
|
24
|
-
*
|
|
25
|
-
* @default 'FORM_DEFAULT'
|
|
26
|
-
*
|
|
27
|
-
* Specifies whether a {@link createV} signal's initial state
|
|
28
|
-
* should be derived from the current text content of the
|
|
29
|
-
* {@link ValueNode.contextNode | primary instance DOM state}.
|
|
30
|
-
*/
|
|
31
|
-
readonly initialValueSource?: InitialValueSource;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const getInitialValue = <RuntimeValue>(
|
|
35
|
-
context: ValueContext<RuntimeValue>,
|
|
36
|
-
options: ValueStateOptions
|
|
37
|
-
): string => {
|
|
38
|
-
const { initialValueSource = 'FORM_DEFAULT' } = options;
|
|
39
|
-
|
|
40
|
-
if (initialValueSource === 'FORM_DEFAULT') {
|
|
41
|
-
return context.definition.defaultValue;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
throw new ErrorProductionDesignPendingError('Edit implementation pending');
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
type BaseValueState = Signal<string>;
|
|
48
|
-
|
|
49
|
-
type RelevantValueState = SimpleAtomicState<string>;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Wraps {@link baseValueState} in a signal-like interface which:
|
|
53
|
-
*
|
|
54
|
-
* - produces a blank value for nodes ({@link context}) in a non-relevant state
|
|
55
|
-
* - persists, and restores, the most recent non-blank value state when a
|
|
56
|
-
* node/context's relevance is restored
|
|
57
|
-
*/
|
|
58
|
-
const createRelevantValueState = <RuntimeValue>(
|
|
59
|
-
context: ValueContext<RuntimeValue>,
|
|
60
|
-
baseValueState: BaseValueState
|
|
61
|
-
): RelevantValueState => {
|
|
62
|
-
return context.scope.runTask(() => {
|
|
63
|
-
const [getRelevantValue, setValue] = baseValueState;
|
|
64
|
-
|
|
65
|
-
const getValue = createMemo(() => {
|
|
66
|
-
if (context.isRelevant()) {
|
|
67
|
-
return getRelevantValue();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return '';
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
return [getValue, setValue];
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
type RuntimeValueState<RuntimeValue> = SimpleAtomicState<RuntimeValue>;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Wraps {@link relevantValueState} in a signal-like interface which
|
|
81
|
-
* automatically encodes and decodes a node's runtime value representation:
|
|
82
|
-
*
|
|
83
|
-
* - Values read by a node will be read from the current state as persisted in
|
|
84
|
-
* the primary instance, then {@link ValueContext.decodeValue | decoded} (as
|
|
85
|
-
* implemented by that node) into a format suitable for the rest of the
|
|
86
|
-
* functionality provided by that node.
|
|
87
|
-
*
|
|
88
|
-
* - Values written by a node will be {@link ValueContext.encodeValue | encoded}
|
|
89
|
-
* (also as implemented by that node) into a string value appropriate for
|
|
90
|
-
* serialization in an instance submission.
|
|
91
|
-
*/
|
|
92
|
-
const createRuntimeValueState = <RuntimeValue>(
|
|
93
|
-
context: ValueContext<RuntimeValue>,
|
|
94
|
-
relevantValueState: RelevantValueState
|
|
95
|
-
): RuntimeValueState<RuntimeValue> => {
|
|
96
|
-
const { decodeValue, encodeValue } = context;
|
|
97
|
-
|
|
98
|
-
return context.scope.runTask(() => {
|
|
99
|
-
const [primaryInstanceValue, setPrimaryInstanceValue] = relevantValueState;
|
|
100
|
-
const getRuntimeValue = createMemo(() => {
|
|
101
|
-
return decodeValue(primaryInstanceValue());
|
|
102
|
-
});
|
|
103
|
-
const setRuntimeValue: SimpleAtomicStateSetter<RuntimeValue> = (value) => {
|
|
104
|
-
const encodedValue = encodeValue(value);
|
|
105
|
-
|
|
106
|
-
return decodeValue(setPrimaryInstanceValue(encodedValue));
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
return [getRuntimeValue, setRuntimeValue];
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* For fields with a `readonly` bind expression, prevent downstream
|
|
115
|
-
* (client/user) writes when the field is in a `readonly` state.
|
|
116
|
-
*/
|
|
117
|
-
const guardDownstreamReadonlyWrites = <RuntimeValue>(
|
|
118
|
-
context: ValueContext<RuntimeValue>,
|
|
119
|
-
baseState: SimpleAtomicState<RuntimeValue>
|
|
120
|
-
): SimpleAtomicState<RuntimeValue> => {
|
|
121
|
-
const { readonly } = context.definition.bind;
|
|
122
|
-
|
|
123
|
-
if (readonly.isDefaultExpression) {
|
|
124
|
-
return baseState;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const [getValue, baseSetValue] = baseState;
|
|
128
|
-
|
|
129
|
-
const setValue: SimpleAtomicStateSetter<RuntimeValue> = (value) => {
|
|
130
|
-
if (context.isReadonly()) {
|
|
131
|
-
const reference = untrack(() => context.contextReference());
|
|
132
|
-
|
|
133
|
-
throw new Error(`Cannot write to readonly field: ${reference}`);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return baseSetValue(value);
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
return [getValue, setValue];
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Defines a reactive effect which writes the result of `calculate` bind
|
|
144
|
-
* computations to the provided value setter, on initialization and any
|
|
145
|
-
* subsequent reactive update.
|
|
146
|
-
*/
|
|
147
|
-
const createCalculation = <RuntimeValue>(
|
|
148
|
-
context: ValueContext<RuntimeValue>,
|
|
149
|
-
setValue: SimpleAtomicStateSetter<RuntimeValue>,
|
|
150
|
-
calculateDefinition: BindComputationExpression<'calculate'>
|
|
151
|
-
): void => {
|
|
152
|
-
context.scope.runTask(() => {
|
|
153
|
-
const calculate = createComputedExpression(context, calculateDefinition, {
|
|
154
|
-
defaultValue: '',
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
createComputed(() => {
|
|
158
|
-
if (context.isAttached() && context.isRelevant()) {
|
|
159
|
-
const calculated = calculate();
|
|
160
|
-
const value = context.decodeValue(calculated);
|
|
161
|
-
|
|
162
|
-
setValue(value);
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
type ValueState<RuntimeValue> = SimpleAtomicState<RuntimeValue>;
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Provides a consistent interface for value nodes of any type which:
|
|
172
|
-
*
|
|
173
|
-
* - derives initial state from either an existing instance (e.g. for edits) or
|
|
174
|
-
* the node's definition (e.g. initializing a new submission)
|
|
175
|
-
* - decodes current primary instance state into the value node's runtime type
|
|
176
|
-
* - encodes updated runtime values to store updated instance state
|
|
177
|
-
* - initializes reactive computation of `calculate` bind expressions for those
|
|
178
|
-
* nodes defined with one
|
|
179
|
-
* - prevents downstream writes to nodes in a readonly state
|
|
180
|
-
*/
|
|
181
|
-
export const createValueState = <RuntimeValue>(
|
|
182
|
-
context: ValueContext<RuntimeValue>,
|
|
183
|
-
options: ValueStateOptions = {}
|
|
184
|
-
): ValueState<RuntimeValue> => {
|
|
185
|
-
return context.scope.runTask(() => {
|
|
186
|
-
const initialValue = getInitialValue(context, options);
|
|
187
|
-
const baseValueState = createSignal(initialValue);
|
|
188
|
-
const valueState = createRelevantValueState(context, baseValueState);
|
|
189
|
-
const runtimeState = createRuntimeValueState(context, valueState);
|
|
190
|
-
const { calculate } = context.definition.bind;
|
|
191
|
-
|
|
192
|
-
if (calculate != null) {
|
|
193
|
-
const [, setValue] = runtimeState;
|
|
194
|
-
|
|
195
|
-
createCalculation(context, setValue, calculate);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return guardDownstreamReadonlyWrites(context, runtimeState);
|
|
199
|
-
});
|
|
200
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { StaticDocument } from '../../../integration/xpath/static-dom/StaticDocument.ts';
|
|
2
|
-
import { ItextTranslationRootDefinition } from './ItextTranslationRootDefinition.ts';
|
|
3
|
-
|
|
4
|
-
export class ItextTranslationDefinition extends StaticDocument<ItextTranslationRootDefinition> {}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { XFormsItextTranslationElement } from '@getodk/xpath';
|
|
2
|
-
import { XFORMS_KNOWN_ATTRIBUTE, XFORMS_LOCAL_NAME } from '@getodk/xpath';
|
|
3
|
-
import { StaticElement } from '../../../integration/xpath/static-dom/StaticElement.ts';
|
|
4
|
-
import type { ItextTranslationDefinition } from './ItextTranslationDefinition.ts';
|
|
5
|
-
|
|
6
|
-
// prettier-ignore
|
|
7
|
-
type ItextTranslationRootKnownAttributeValue<LocalName extends string> =
|
|
8
|
-
LocalName extends 'lang'
|
|
9
|
-
? string
|
|
10
|
-
: string | null;
|
|
11
|
-
|
|
12
|
-
type AssertItextTranslationRootKnownAttributeValue = <LocalName extends string>(
|
|
13
|
-
localName: LocalName,
|
|
14
|
-
value: string | null
|
|
15
|
-
) => asserts value is ItextTranslationRootKnownAttributeValue<LocalName>;
|
|
16
|
-
|
|
17
|
-
const assertItextTranslationRootKnownAttributeValue: AssertItextTranslationRootKnownAttributeValue =
|
|
18
|
-
(localName, value) => {
|
|
19
|
-
if (localName === 'lang' && value == null) {
|
|
20
|
-
throw new Error('Invalid itext <translation> element: missing `lang` attribute');
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export class ItextTranslationRootDefinition
|
|
25
|
-
extends StaticElement<ItextTranslationDefinition>
|
|
26
|
-
implements XFormsItextTranslationElement<ItextTranslationRootDefinition>
|
|
27
|
-
{
|
|
28
|
-
override readonly [XFORMS_LOCAL_NAME] = 'translation';
|
|
29
|
-
override readonly [XFORMS_KNOWN_ATTRIBUTE] = 'lang';
|
|
30
|
-
|
|
31
|
-
override getAttributeValue(localName: 'lang'): string;
|
|
32
|
-
override getAttributeValue(localName: string): string | null;
|
|
33
|
-
override getAttributeValue<LocalName extends string>(
|
|
34
|
-
localName: LocalName
|
|
35
|
-
): ItextTranslationRootKnownAttributeValue<LocalName> {
|
|
36
|
-
const value = super.getAttributeValue(localName);
|
|
37
|
-
|
|
38
|
-
assertItextTranslationRootKnownAttributeValue(localName, value);
|
|
39
|
-
|
|
40
|
-
return value;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { XFormsItextTranslationMap } from '@getodk/xpath';
|
|
2
|
-
import type { EngineXPathNode } from '../../../integration/xpath/adapter/kind.ts';
|
|
3
|
-
import { parseStaticDocumentFromDOMSubtree } from '../../shared/parseStaticDocumentFromDOMSubtree.ts';
|
|
4
|
-
import type { XFormDOM } from '../../XFormDOM.ts';
|
|
5
|
-
import { ItextTranslationDefinition } from './ItextTranslationDefinition.ts';
|
|
6
|
-
import { ItextTranslationRootDefinition } from './ItextTranslationRootDefinition.ts';
|
|
7
|
-
|
|
8
|
-
export class ItextTranslationsDefinition
|
|
9
|
-
extends Map<string, ItextTranslationRootDefinition>
|
|
10
|
-
implements XFormsItextTranslationMap<EngineXPathNode>
|
|
11
|
-
{
|
|
12
|
-
static from(xformDOM: XFormDOM): ItextTranslationsDefinition {
|
|
13
|
-
const translationDefinitions = xformDOM.itextTranslationElements.map((element) => {
|
|
14
|
-
return parseStaticDocumentFromDOMSubtree(
|
|
15
|
-
ItextTranslationDefinition,
|
|
16
|
-
ItextTranslationRootDefinition,
|
|
17
|
-
element
|
|
18
|
-
);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
return new this(translationDefinitions);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
private constructor(translations: readonly ItextTranslationDefinition[]) {
|
|
25
|
-
super(
|
|
26
|
-
translations.map(({ root }) => {
|
|
27
|
-
return [root.getAttributeValue('lang'), root];
|
|
28
|
-
})
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { NamespaceDeclarationMap } from '../../lib/names/NamespaceDeclarationMap.ts';
|
|
2
|
-
import { QualifiedName } from '../../lib/names/QualifiedName.ts';
|
|
3
|
-
import { RepeatElementDefinition } from '../body/RepeatElementDefinition.ts';
|
|
4
|
-
import { DescendentNodeDefinition } from './DescendentNodeDefinition.ts';
|
|
5
|
-
import type { ChildNodeDefinition } from './NodeDefinition.ts';
|
|
6
|
-
import type { AnyRepeatRangeDefinition } from './RepeatRangeDefinition.ts';
|
|
7
|
-
|
|
8
|
-
export class RepeatInstanceDefinition extends DescendentNodeDefinition<
|
|
9
|
-
'repeat-instance',
|
|
10
|
-
RepeatElementDefinition
|
|
11
|
-
> {
|
|
12
|
-
readonly type = 'repeat-instance';
|
|
13
|
-
|
|
14
|
-
readonly namespaceDeclarations: NamespaceDeclarationMap;
|
|
15
|
-
readonly qualifiedName: QualifiedName;
|
|
16
|
-
readonly children: readonly ChildNodeDefinition[];
|
|
17
|
-
readonly instances = null;
|
|
18
|
-
readonly defaultValue = null;
|
|
19
|
-
|
|
20
|
-
constructor(
|
|
21
|
-
range: AnyRepeatRangeDefinition,
|
|
22
|
-
readonly node: Element
|
|
23
|
-
) {
|
|
24
|
-
const { bind, bodyElement, parent, root } = range;
|
|
25
|
-
|
|
26
|
-
super(parent, bind, bodyElement);
|
|
27
|
-
|
|
28
|
-
this.qualifiedName = new QualifiedName(node);
|
|
29
|
-
this.namespaceDeclarations = new NamespaceDeclarationMap(this);
|
|
30
|
-
this.children = root.buildSubtree(this);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
toJSON() {
|
|
34
|
-
const { bind, bodyElement, parent, root, ...rest } = this;
|
|
35
|
-
|
|
36
|
-
return rest;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { NamespaceDeclarationMap } from '../../lib/names/NamespaceDeclarationMap.ts';
|
|
2
|
-
import { QualifiedName } from '../../lib/names/QualifiedName.ts';
|
|
3
|
-
import type { RepeatElementDefinition } from '../body/RepeatElementDefinition.ts';
|
|
4
|
-
import { RepeatCountControlExpression } from '../expression/RepeatCountControlExpression.ts';
|
|
5
|
-
import type { BindDefinition } from './BindDefinition.ts';
|
|
6
|
-
import { DescendentNodeDefinition } from './DescendentNodeDefinition.ts';
|
|
7
|
-
import type { ParentNodeDefinition } from './NodeDefinition.ts';
|
|
8
|
-
import { RepeatInstanceDefinition } from './RepeatInstanceDefinition.ts';
|
|
9
|
-
import { RepeatTemplateDefinition } from './RepeatTemplateDefinition.ts';
|
|
10
|
-
|
|
11
|
-
export interface ControlledRepeatRangeDefinition extends RepeatRangeDefinition {
|
|
12
|
-
readonly count: RepeatCountControlExpression;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface UncontrolledRepeatRangeDefinition extends RepeatRangeDefinition {
|
|
16
|
-
readonly count: null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// prettier-ignore
|
|
20
|
-
export type AnyRepeatRangeDefinition =
|
|
21
|
-
| ControlledRepeatRangeDefinition
|
|
22
|
-
| UncontrolledRepeatRangeDefinition;
|
|
23
|
-
|
|
24
|
-
type AssertRepeatRangeDefinitionUnion = (
|
|
25
|
-
definition: RepeatRangeDefinition
|
|
26
|
-
) => asserts definition is AnyRepeatRangeDefinition;
|
|
27
|
-
|
|
28
|
-
const assertRepeatRangeDefinitionUnion: AssertRepeatRangeDefinitionUnion = (_definition) => {
|
|
29
|
-
// Intentional no-op, used to guide the type checker. Implementation would
|
|
30
|
-
// check _definition.count == null || _definition.count != null, which is
|
|
31
|
-
// tautologically true!
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export class RepeatRangeDefinition extends DescendentNodeDefinition<
|
|
35
|
-
'repeat-range',
|
|
36
|
-
RepeatElementDefinition
|
|
37
|
-
> {
|
|
38
|
-
static from(
|
|
39
|
-
parent: ParentNodeDefinition,
|
|
40
|
-
bind: BindDefinition,
|
|
41
|
-
bodyElement: RepeatElementDefinition,
|
|
42
|
-
modelNodes: readonly [Element, ...Element[]]
|
|
43
|
-
): AnyRepeatRangeDefinition {
|
|
44
|
-
const definition = new this(parent, bind, bodyElement, modelNodes);
|
|
45
|
-
|
|
46
|
-
assertRepeatRangeDefinitionUnion(definition);
|
|
47
|
-
|
|
48
|
-
return definition;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
readonly type = 'repeat-range';
|
|
52
|
-
|
|
53
|
-
readonly template: RepeatTemplateDefinition;
|
|
54
|
-
readonly children = null;
|
|
55
|
-
readonly instances: RepeatInstanceDefinition[];
|
|
56
|
-
readonly count: RepeatCountControlExpression | null;
|
|
57
|
-
|
|
58
|
-
readonly node = null;
|
|
59
|
-
readonly namespaceDeclarations: NamespaceDeclarationMap;
|
|
60
|
-
readonly qualifiedName: QualifiedName;
|
|
61
|
-
readonly defaultValue = null;
|
|
62
|
-
|
|
63
|
-
private constructor(
|
|
64
|
-
parent: ParentNodeDefinition,
|
|
65
|
-
bind: BindDefinition,
|
|
66
|
-
bodyElement: RepeatElementDefinition,
|
|
67
|
-
modelNodes: readonly [Element, ...Element[]]
|
|
68
|
-
) {
|
|
69
|
-
super(parent, bind, bodyElement);
|
|
70
|
-
|
|
71
|
-
const { template, instanceNodes } = RepeatTemplateDefinition.parseModelNodes(this, modelNodes);
|
|
72
|
-
|
|
73
|
-
this.template = template;
|
|
74
|
-
this.qualifiedName = template.qualifiedName;
|
|
75
|
-
this.namespaceDeclarations = new NamespaceDeclarationMap(this);
|
|
76
|
-
this.count = RepeatCountControlExpression.from(bodyElement, instanceNodes.length);
|
|
77
|
-
|
|
78
|
-
assertRepeatRangeDefinitionUnion(this);
|
|
79
|
-
|
|
80
|
-
this.instances = instanceNodes.map((element) => {
|
|
81
|
-
return new RepeatInstanceDefinition(this, element);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
isControlled(): this is ControlledRepeatRangeDefinition {
|
|
86
|
-
return this.count != null;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
isUncontrolled(): this is UncontrolledRepeatRangeDefinition {
|
|
90
|
-
return this.count == null;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
toJSON() {
|
|
94
|
-
const { bind, bodyElement: groupDefinition, parent, root, ...rest } = this;
|
|
95
|
-
|
|
96
|
-
return rest;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { JAVAROSA_NAMESPACE_URI } from '@getodk/common/constants/xmlns.ts';
|
|
2
|
-
import { NamespaceDeclarationMap } from '../../lib/names/NamespaceDeclarationMap.ts';
|
|
3
|
-
import { QualifiedName } from '../../lib/names/QualifiedName.ts';
|
|
4
|
-
import type { RepeatElementDefinition } from '../body/RepeatElementDefinition.ts';
|
|
5
|
-
import { BindDefinition } from './BindDefinition.ts';
|
|
6
|
-
import { DescendentNodeDefinition } from './DescendentNodeDefinition.ts';
|
|
7
|
-
import type { ChildNodeDefinition } from './NodeDefinition.ts';
|
|
8
|
-
import type { RepeatRangeDefinition } from './RepeatRangeDefinition.ts';
|
|
9
|
-
|
|
10
|
-
const repeatTemplates = new WeakMap<BindDefinition, RepeatTemplateDefinition>();
|
|
11
|
-
|
|
12
|
-
interface ExplicitRepeatTemplateElement extends Element {
|
|
13
|
-
getAttributeNS(namespaceURI: typeof JAVAROSA_NAMESPACE_URI, name: 'template'): string;
|
|
14
|
-
getAttributeNS(namespaceURI: string | null, name: string): string | null;
|
|
15
|
-
|
|
16
|
-
hasAttributeNS(namespaceURI: typeof JAVAROSA_NAMESPACE_URI, name: 'template'): true;
|
|
17
|
-
(namespaceURI: string | null, name: string): boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const isExplicitRepeatTemplateElement = (
|
|
21
|
-
element: Element
|
|
22
|
-
): element is ExplicitRepeatTemplateElement => {
|
|
23
|
-
return element.hasAttributeNS(JAVAROSA_NAMESPACE_URI, 'template');
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
type InstanceNodes = readonly [template: ExplicitRepeatTemplateElement, ...rest: Element[]];
|
|
27
|
-
|
|
28
|
-
interface LeafNode extends Element {
|
|
29
|
-
readonly childElementCount: 0;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const isLeafNode = (element: Element): element is LeafNode => {
|
|
33
|
-
return element.childElementCount === 0;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const clearLeafNodes = <T extends Element>(element: T): T => {
|
|
37
|
-
if (isLeafNode(element)) {
|
|
38
|
-
element.textContent = '';
|
|
39
|
-
} else {
|
|
40
|
-
for (const child of element.children) {
|
|
41
|
-
clearLeafNodes(child);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return element;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const getOrCreateTemplateElement = (element: Element): ExplicitRepeatTemplateElement => {
|
|
49
|
-
if (isExplicitRepeatTemplateElement(element)) {
|
|
50
|
-
return element;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const clone = element.cloneNode(true) as Element;
|
|
54
|
-
clone.setAttributeNS(JAVAROSA_NAMESPACE_URI, 'template', '');
|
|
55
|
-
|
|
56
|
-
return clearLeafNodes(clone as ExplicitRepeatTemplateElement);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// TODO: under what circumstances should a default instance be created, and is
|
|
60
|
-
// this the appropriate place for that?
|
|
61
|
-
const splitInstanceNodes = (modelNodes: readonly [Element, ...Element[]]): InstanceNodes => {
|
|
62
|
-
const [first, ...rest] = modelNodes;
|
|
63
|
-
const template = getOrCreateTemplateElement(first);
|
|
64
|
-
|
|
65
|
-
if (template === first) {
|
|
66
|
-
return [template, ...rest];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return [template, ...modelNodes];
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
interface ParsedRepeatNodes {
|
|
73
|
-
readonly template: RepeatTemplateDefinition;
|
|
74
|
-
readonly instanceNodes: readonly Element[];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export class RepeatTemplateDefinition extends DescendentNodeDefinition<
|
|
78
|
-
'repeat-template',
|
|
79
|
-
RepeatElementDefinition
|
|
80
|
-
> {
|
|
81
|
-
static parseModelNodes(
|
|
82
|
-
range: RepeatRangeDefinition,
|
|
83
|
-
modelNodes: readonly [Element, ...Element[]]
|
|
84
|
-
): ParsedRepeatNodes {
|
|
85
|
-
const { bind } = range;
|
|
86
|
-
|
|
87
|
-
let template = repeatTemplates.get(bind);
|
|
88
|
-
let instanceNodes: readonly Element[];
|
|
89
|
-
|
|
90
|
-
if (template == null) {
|
|
91
|
-
const [templateNode, ...rest] = splitInstanceNodes(modelNodes);
|
|
92
|
-
|
|
93
|
-
instanceNodes = rest;
|
|
94
|
-
template = new this(range, templateNode);
|
|
95
|
-
} else {
|
|
96
|
-
// TODO: this is under the assumption that for any depth > 1, if a
|
|
97
|
-
// template has already been defined for the given form definition, any
|
|
98
|
-
// subsequent nodes matching the repeat's nodeset are implicitly default
|
|
99
|
-
// instances. Is this right?
|
|
100
|
-
const duplicateTemplate = modelNodes.find((node) =>
|
|
101
|
-
node.hasAttributeNS(JAVAROSA_NAMESPACE_URI, 'template')
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
if (duplicateTemplate != null) {
|
|
105
|
-
throw new Error(`Multiple explicit templates defined for ${bind.nodeset}`);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
instanceNodes = modelNodes;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
template,
|
|
113
|
-
instanceNodes,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
readonly type = 'repeat-template';
|
|
118
|
-
|
|
119
|
-
readonly node: Element;
|
|
120
|
-
readonly namespaceDeclarations: NamespaceDeclarationMap;
|
|
121
|
-
readonly qualifiedName: QualifiedName;
|
|
122
|
-
readonly children: readonly ChildNodeDefinition[];
|
|
123
|
-
readonly instances = null;
|
|
124
|
-
readonly defaultValue = null;
|
|
125
|
-
|
|
126
|
-
protected constructor(
|
|
127
|
-
range: RepeatRangeDefinition,
|
|
128
|
-
protected readonly templateNode: ExplicitRepeatTemplateElement
|
|
129
|
-
) {
|
|
130
|
-
const { bind, bodyElement, parent, root } = range;
|
|
131
|
-
|
|
132
|
-
super(parent, bind, bodyElement);
|
|
133
|
-
|
|
134
|
-
const node = templateNode.cloneNode(true) as Element;
|
|
135
|
-
|
|
136
|
-
node.removeAttributeNS(JAVAROSA_NAMESPACE_URI, 'template');
|
|
137
|
-
|
|
138
|
-
this.node = node;
|
|
139
|
-
this.qualifiedName = new QualifiedName(node);
|
|
140
|
-
this.namespaceDeclarations = new NamespaceDeclarationMap(this);
|
|
141
|
-
this.children = root.buildSubtree(this);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
toJSON() {
|
|
145
|
-
const { bind, bodyElement, parent, root, ...rest } = this;
|
|
146
|
-
|
|
147
|
-
return rest;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { StaticDocument } from '../../../integration/xpath/static-dom/StaticDocument.ts';
|
|
2
|
-
import { SecondaryInstanceRootDefinition } from './SecondaryInstanceRootDefinition.ts';
|
|
3
|
-
|
|
4
|
-
export class SecondaryInstanceDefinition extends StaticDocument<SecondaryInstanceRootDefinition> {}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { XFormsSecondaryInstanceElement } from '@getodk/xpath';
|
|
2
|
-
import { XFORMS_KNOWN_ATTRIBUTE, XFORMS_LOCAL_NAME } from '@getodk/xpath';
|
|
3
|
-
import { StaticElement } from '../../../integration/xpath/static-dom/StaticElement.ts';
|
|
4
|
-
import type { SecondaryInstanceDefinition } from './SecondaryInstanceDefinition.ts';
|
|
5
|
-
|
|
6
|
-
export class SecondaryInstanceRootDefinition
|
|
7
|
-
extends StaticElement<SecondaryInstanceDefinition>
|
|
8
|
-
implements XFormsSecondaryInstanceElement<StaticElement>
|
|
9
|
-
{
|
|
10
|
-
override readonly [XFORMS_LOCAL_NAME] = 'instance';
|
|
11
|
-
override readonly [XFORMS_KNOWN_ATTRIBUTE] = 'id';
|
|
12
|
-
}
|