@getodk/xforms-engine 0.2.0 → 0.4.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 +69 -4
- package/dist/client/EngineConfig.d.ts +0 -1
- package/dist/client/GroupNode.d.ts +4 -3
- package/dist/client/ModelValueNode.d.ts +36 -0
- package/dist/client/NodeAppearances.d.ts +1 -2
- package/dist/client/NoteNode.d.ts +52 -0
- package/dist/client/RootNode.d.ts +4 -3
- package/dist/client/SelectNode.d.ts +6 -5
- package/dist/client/StringNode.d.ts +6 -5
- package/dist/client/SubtreeNode.d.ts +3 -2
- package/dist/client/TextRange.d.ts +85 -3
- package/dist/client/TriggerNode.d.ts +25 -0
- package/dist/client/constants.d.ts +8 -0
- package/dist/client/hierarchy.d.ts +19 -10
- package/dist/client/index.d.ts +0 -1
- package/dist/client/node-types.d.ts +3 -1
- package/dist/client/{RepeatRangeNode.d.ts → repeat/BaseRepeatRangeNode.d.ts} +18 -18
- package/dist/client/{RepeatInstanceNode.d.ts → repeat/RepeatInstanceNode.d.ts} +9 -9
- package/dist/client/repeat/RepeatRangeControlledNode.d.ts +18 -0
- package/dist/client/repeat/RepeatRangeUncontrolledNode.d.ts +19 -0
- package/dist/client/unsupported/RangeNode.d.ts +9 -0
- package/dist/client/unsupported/RankNode.d.ts +9 -0
- package/dist/client/unsupported/UnsupportedControlNode.d.ts +32 -0
- package/dist/client/unsupported/UploadNode.d.ts +9 -0
- package/dist/client/validation.d.ts +162 -0
- package/dist/index.d.ts +14 -6
- package/dist/index.js +39696 -36151
- package/dist/index.js.map +1 -1
- package/dist/instance/Group.d.ts +3 -2
- package/dist/instance/ModelValue.d.ts +39 -0
- package/dist/instance/Note.d.ts +41 -0
- package/dist/instance/Root.d.ts +5 -4
- package/dist/instance/SelectField.d.ts +11 -6
- package/dist/instance/StringField.d.ts +12 -7
- package/dist/instance/Subtree.d.ts +2 -1
- package/dist/instance/TriggerControl.d.ts +40 -0
- package/dist/instance/abstract/DescendantNode.d.ts +8 -10
- package/dist/instance/abstract/InstanceNode.d.ts +3 -2
- package/dist/instance/abstract/UnsupportedControl.d.ts +46 -0
- package/dist/instance/children.d.ts +0 -1
- package/dist/instance/hierarchy.d.ts +15 -6
- package/dist/instance/index.d.ts +0 -1
- package/dist/instance/internal-api/EvaluationContext.d.ts +0 -1
- package/dist/instance/internal-api/InstanceConfig.d.ts +0 -1
- package/dist/instance/internal-api/SubscribableDependency.d.ts +0 -1
- package/dist/instance/internal-api/TranslationContext.d.ts +0 -1
- package/dist/instance/internal-api/ValidationContext.d.ts +28 -0
- package/dist/instance/internal-api/ValueContext.d.ts +3 -4
- package/dist/instance/{RepeatRange.d.ts → repeat/BaseRepeatRange.d.ts} +46 -46
- package/dist/instance/{RepeatInstance.d.ts → repeat/RepeatInstance.d.ts} +13 -13
- package/dist/instance/repeat/RepeatRangeControlled.d.ts +15 -0
- package/dist/instance/repeat/RepeatRangeUncontrolled.d.ts +34 -0
- package/dist/instance/resource.d.ts +0 -1
- package/dist/instance/text/TextChunk.d.ts +0 -1
- package/dist/instance/text/TextRange.d.ts +4 -5
- package/dist/instance/unsupported/RangeControl.d.ts +4 -0
- package/dist/instance/unsupported/RankControl.d.ts +4 -0
- package/dist/instance/unsupported/UploadControl.d.ts +4 -0
- package/dist/lib/TokenListParser.d.ts +3 -3
- package/dist/lib/dom/query.d.ts +1 -2
- package/dist/lib/reactivity/createChildrenState.d.ts +0 -1
- package/dist/lib/reactivity/createComputedExpression.d.ts +7 -3
- package/dist/lib/reactivity/createNoteReadonlyThunk.d.ts +4 -0
- package/dist/lib/reactivity/createSelectItems.d.ts +0 -1
- package/dist/lib/reactivity/createValueState.d.ts +0 -1
- package/dist/lib/reactivity/materializeCurrentStateChildren.d.ts +0 -1
- package/dist/lib/reactivity/node-state/createClientState.d.ts +0 -1
- package/dist/lib/reactivity/node-state/createCurrentState.d.ts +0 -1
- package/dist/lib/reactivity/node-state/createEngineState.d.ts +0 -1
- package/dist/lib/reactivity/node-state/createSharedNodeState.d.ts +1 -2
- package/dist/lib/reactivity/node-state/createSpecifiedPropertyDescriptor.d.ts +0 -1
- package/dist/lib/reactivity/node-state/createSpecifiedState.d.ts +1 -2
- package/dist/lib/reactivity/node-state/representations.d.ts +0 -1
- package/dist/lib/reactivity/scope.d.ts +0 -1
- package/dist/lib/reactivity/text/createFieldHint.d.ts +3 -4
- package/dist/lib/reactivity/text/createNodeLabel.d.ts +3 -4
- package/dist/lib/reactivity/text/createNoteText.d.ts +24 -0
- package/dist/lib/reactivity/text/createTextRange.d.ts +5 -8
- package/dist/lib/reactivity/types.d.ts +0 -1
- package/dist/lib/reactivity/validation/createAggregatedViolations.d.ts +8 -0
- package/dist/lib/reactivity/validation/createValidation.d.ts +17 -0
- package/dist/{XFormDOM.d.ts → parse/XFormDOM.d.ts} +1 -2
- package/dist/{XFormDataType.d.ts → parse/XFormDataType.d.ts} +2 -4
- package/dist/{XFormDefinition.d.ts → parse/XFormDefinition.d.ts} +2 -3
- package/dist/{body → parse/body}/BodyDefinition.d.ts +15 -10
- package/dist/{body → parse/body}/BodyElementDefinition.d.ts +8 -7
- package/dist/{body → parse/body}/RepeatElementDefinition.d.ts +4 -5
- package/dist/{body → parse/body}/UnsupportedBodyElementDefinition.d.ts +0 -1
- package/dist/{body → parse/body}/appearance/inputAppearanceParser.d.ts +1 -2
- package/dist/{body → parse/body}/appearance/selectAppearanceParser.d.ts +1 -2
- package/dist/{body → parse/body}/appearance/structureElementAppearanceParser.d.ts +1 -2
- package/dist/parse/body/appearance/unknownAppearanceParser.d.ts +3 -0
- package/dist/{body → parse/body}/control/ControlDefinition.d.ts +3 -4
- package/dist/{body → parse/body}/control/InputDefinition.d.ts +1 -2
- package/dist/parse/body/control/RangeControlDefinition.d.ts +11 -0
- package/dist/parse/body/control/RankControlDefinition.d.ts +11 -0
- package/dist/parse/body/control/TriggerControlDefinition.d.ts +11 -0
- package/dist/parse/body/control/UploadControlDefinition.d.ts +11 -0
- package/dist/{body → parse/body}/control/select/ItemDefinition.d.ts +3 -4
- package/dist/{body → parse/body}/control/select/ItemsetDefinition.d.ts +7 -7
- package/dist/{body → parse/body}/control/select/ItemsetNodesetContext.d.ts +2 -3
- package/dist/{body → parse/body}/control/select/SelectDefinition.d.ts +3 -12
- package/dist/{body → parse/body}/group/BaseGroupDefinition.d.ts +3 -5
- package/dist/{body → parse/body}/group/LogicalGroupDefinition.d.ts +0 -1
- package/dist/{body → parse/body}/group/PresentationGroupDefinition.d.ts +1 -2
- package/dist/{body → parse/body}/group/StructuralGroupDefinition.d.ts +0 -1
- package/dist/{model/BindComputation.d.ts → parse/expression/BindComputationExpression.d.ts} +5 -6
- package/dist/{body/control/select → parse/expression}/ItemsetNodesetExpression.d.ts +2 -3
- package/dist/{body/control/select → parse/expression}/ItemsetValueExpression.d.ts +2 -3
- package/dist/parse/expression/RepeatCountControlExpression.d.ts +18 -0
- package/dist/parse/expression/TextLiteralExpression.d.ts +9 -0
- package/dist/parse/expression/TextOutputExpression.d.ts +7 -0
- package/dist/parse/expression/TextReferenceExpression.d.ts +7 -0
- package/dist/parse/expression/TextTranslationExpression.d.ts +8 -0
- package/dist/{expression → parse/expression/abstract}/DependencyContext.d.ts +0 -1
- package/dist/{expression → parse/expression/abstract}/DependentExpression.d.ts +13 -10
- package/dist/parse/expression/abstract/TextChunkExpression.d.ts +17 -0
- package/dist/parse/model/BindDefinition.d.ts +39 -0
- package/dist/{model → parse/model}/BindElement.d.ts +1 -0
- package/dist/{model → parse/model}/DescendentNodeDefinition.d.ts +0 -1
- package/dist/{model/ValueNodeDefinition.d.ts → parse/model/LeafNodeDefinition.d.ts} +3 -4
- package/dist/{model → parse/model}/ModelBindMap.d.ts +0 -1
- package/dist/{model → parse/model}/ModelDefinition.d.ts +1 -2
- package/dist/{model → parse/model}/NodeDefinition.d.ts +8 -9
- package/dist/parse/model/NoteNodeDefinition.d.ts +30 -0
- package/dist/{model → parse/model}/RepeatInstanceDefinition.d.ts +3 -4
- package/dist/{model → parse/model}/RepeatRangeDefinition.d.ts +14 -5
- package/dist/{model → parse/model}/RepeatTemplateDefinition.d.ts +2 -3
- package/dist/{model → parse/model}/RootDefinition.d.ts +2 -3
- package/dist/{model → parse/model}/SubtreeDefinition.d.ts +1 -2
- package/dist/parse/text/HintDefinition.d.ts +8 -0
- package/dist/parse/text/ItemLabelDefinition.d.ts +8 -0
- package/dist/parse/text/ItemsetLabelDefinition.d.ts +12 -0
- package/dist/parse/text/LabelDefinition.d.ts +14 -0
- package/dist/parse/text/MessageDefinition.d.ts +14 -0
- package/dist/parse/text/abstract/TextElementDefinition.d.ts +22 -0
- package/dist/parse/text/abstract/TextRangeDefinition.d.ts +34 -0
- package/dist/parse/xpath/dependency-analysis.d.ts +40 -0
- package/dist/parse/xpath/path-resolution.d.ts +69 -0
- package/dist/parse/xpath/predicate-analysis.d.ts +29 -0
- package/dist/parse/xpath/reference-parsing.d.ts +17 -0
- package/dist/parse/xpath/semantic-analysis.d.ts +97 -0
- package/dist/parse/xpath/syntax-traversal.d.ts +68 -0
- package/dist/solid.js +8745 -5186
- package/dist/solid.js.map +1 -1
- package/package.json +15 -16
- package/src/client/BaseNode.ts +74 -8
- package/src/client/GroupNode.ts +4 -2
- package/src/client/ModelValueNode.ts +40 -0
- package/src/client/NodeAppearances.ts +1 -1
- package/src/client/NoteNode.ts +74 -0
- package/src/client/README.md +1 -0
- package/src/client/RootNode.ts +4 -2
- package/src/client/SelectNode.ts +6 -4
- package/src/client/StringNode.ts +6 -4
- package/src/client/SubtreeNode.ts +3 -1
- package/src/client/TextRange.ts +98 -2
- package/src/client/TriggerNode.ts +29 -0
- package/src/client/constants.ts +10 -0
- package/src/client/hierarchy.ts +43 -15
- package/src/client/node-types.ts +17 -2
- package/src/client/{RepeatRangeNode.ts → repeat/BaseRepeatRangeNode.ts} +18 -19
- package/src/client/{RepeatInstanceNode.ts → repeat/RepeatInstanceNode.ts} +10 -8
- package/src/client/repeat/RepeatRangeControlledNode.ts +20 -0
- package/src/client/repeat/RepeatRangeUncontrolledNode.ts +21 -0
- package/src/client/unsupported/RangeNode.ts +14 -0
- package/src/client/unsupported/RankNode.ts +14 -0
- package/src/client/unsupported/UnsupportedControlNode.ts +40 -0
- package/src/client/unsupported/UploadNode.ts +14 -0
- package/src/client/validation.ts +199 -0
- package/src/index.ts +21 -9
- package/src/instance/Group.ts +10 -4
- package/src/instance/ModelValue.ts +104 -0
- package/src/instance/Note.ts +142 -0
- package/src/instance/Root.ts +16 -6
- package/src/instance/SelectField.ts +29 -7
- package/src/instance/StringField.ts +36 -10
- package/src/instance/Subtree.ts +9 -3
- package/src/instance/TriggerControl.ts +134 -0
- package/src/instance/abstract/DescendantNode.ts +9 -10
- package/src/instance/abstract/InstanceNode.ts +29 -7
- package/src/instance/abstract/UnsupportedControl.ts +151 -0
- package/src/instance/children.ts +113 -16
- package/src/instance/hierarchy.ts +42 -5
- package/src/instance/index.ts +1 -1
- package/src/instance/internal-api/EvaluationContext.ts +1 -1
- package/src/instance/internal-api/ValidationContext.ts +32 -0
- package/src/instance/internal-api/ValueContext.ts +3 -3
- package/src/instance/{RepeatRange.ts → repeat/BaseRepeatRange.ts} +114 -99
- package/src/instance/{RepeatInstance.ts → repeat/RepeatInstance.ts} +27 -22
- package/src/instance/repeat/RepeatRangeControlled.ts +82 -0
- package/src/instance/repeat/RepeatRangeUncontrolled.ts +67 -0
- package/src/instance/text/TextRange.ts +10 -4
- package/src/instance/unsupported/RangeControl.ts +5 -0
- package/src/instance/unsupported/RankControl.ts +5 -0
- package/src/instance/unsupported/UploadControl.ts +5 -0
- package/src/lib/TokenListParser.ts +11 -7
- package/src/lib/dom/query.ts +1 -1
- package/src/lib/reactivity/createComputedExpression.ts +25 -27
- package/src/lib/reactivity/createNoteReadonlyThunk.ts +33 -0
- package/src/lib/reactivity/createSelectItems.ts +23 -16
- package/src/lib/reactivity/createValueState.ts +3 -3
- package/src/lib/reactivity/node-state/createSharedNodeState.ts +1 -1
- package/src/lib/reactivity/node-state/createSpecifiedState.ts +1 -1
- package/src/lib/reactivity/text/createFieldHint.ts +9 -7
- package/src/lib/reactivity/text/createNodeLabel.ts +8 -6
- package/src/lib/reactivity/text/createNoteText.ts +72 -0
- package/src/lib/reactivity/text/createTextRange.ts +17 -90
- package/src/lib/reactivity/validation/createAggregatedViolations.ts +75 -0
- package/src/lib/reactivity/validation/createValidation.ts +196 -0
- package/src/{XFormDataType.ts → parse/XFormDataType.ts} +1 -3
- package/src/{XFormDefinition.ts → parse/XFormDefinition.ts} +2 -2
- package/src/{body → parse/body}/BodyDefinition.ts +44 -27
- package/src/{body → parse/body}/BodyElementDefinition.ts +13 -6
- package/src/{body → parse/body}/RepeatElementDefinition.ts +10 -20
- package/src/{body → parse/body}/appearance/inputAppearanceParser.ts +1 -1
- package/src/{body → parse/body}/appearance/selectAppearanceParser.ts +1 -1
- package/src/{body → parse/body}/appearance/structureElementAppearanceParser.ts +1 -1
- package/src/parse/body/appearance/unknownAppearanceParser.ts +5 -0
- package/src/{body → parse/body}/control/ControlDefinition.ts +5 -4
- package/src/parse/body/control/RangeControlDefinition.ts +26 -0
- package/src/parse/body/control/RankControlDefinition.ts +27 -0
- package/src/parse/body/control/TriggerControlDefinition.ts +26 -0
- package/src/parse/body/control/UploadControlDefinition.ts +26 -0
- package/src/{body → parse/body}/control/select/ItemDefinition.ts +4 -4
- package/src/parse/body/control/select/ItemsetDefinition.ts +53 -0
- package/src/{body → parse/body}/control/select/ItemsetNodesetContext.ts +2 -2
- package/src/{body → parse/body}/control/select/SelectDefinition.ts +3 -11
- package/src/{body → parse/body}/group/BaseGroupDefinition.ts +11 -21
- package/src/{body → parse/body}/group/PresentationGroupDefinition.ts +1 -1
- package/src/{model/BindComputation.ts → parse/expression/BindComputationExpression.ts} +8 -12
- package/src/parse/expression/ItemsetNodesetExpression.ts +8 -0
- package/src/{body/control/select → parse/expression}/ItemsetValueExpression.ts +2 -2
- package/src/parse/expression/RepeatCountControlExpression.ts +44 -0
- package/src/parse/expression/TextLiteralExpression.ts +19 -0
- package/src/parse/expression/TextOutputExpression.ts +25 -0
- package/src/parse/expression/TextReferenceExpression.ts +14 -0
- package/src/parse/expression/TextTranslationExpression.ts +38 -0
- package/src/{expression → parse/expression/abstract}/DependentExpression.ts +46 -28
- package/src/parse/expression/abstract/TextChunkExpression.ts +38 -0
- package/src/{model → parse/model}/BindDefinition.ts +30 -27
- package/src/{model → parse/model}/BindElement.ts +1 -0
- package/src/{model/ValueNodeDefinition.ts → parse/model/LeafNodeDefinition.ts} +4 -4
- package/src/{model → parse/model}/ModelBindMap.ts +4 -0
- package/src/{model → parse/model}/NodeDefinition.ts +12 -12
- package/src/parse/model/NoteNodeDefinition.ts +70 -0
- package/src/{model → parse/model}/RepeatInstanceDefinition.ts +2 -2
- package/src/parse/model/RepeatRangeDefinition.ts +94 -0
- package/src/{model → parse/model}/RootDefinition.ts +8 -4
- package/src/parse/text/HintDefinition.ts +25 -0
- package/src/parse/text/ItemLabelDefinition.ts +25 -0
- package/src/parse/text/ItemsetLabelDefinition.ts +44 -0
- package/src/parse/text/LabelDefinition.ts +61 -0
- package/src/parse/text/MessageDefinition.ts +49 -0
- package/src/parse/text/abstract/TextElementDefinition.ts +71 -0
- package/src/parse/text/abstract/TextRangeDefinition.ts +70 -0
- package/src/parse/xpath/dependency-analysis.ts +105 -0
- package/src/parse/xpath/path-resolution.ts +475 -0
- package/src/parse/xpath/predicate-analysis.ts +61 -0
- package/src/parse/xpath/reference-parsing.ts +90 -0
- package/src/parse/xpath/semantic-analysis.ts +466 -0
- package/src/parse/xpath/syntax-traversal.ts +129 -0
- package/dist/body/text/HintDefinition.d.ts +0 -11
- package/dist/body/text/LabelDefinition.d.ts +0 -22
- package/dist/body/text/TextElementDefinition.d.ts +0 -33
- package/dist/body/text/TextElementOutputPart.d.ts +0 -13
- package/dist/body/text/TextElementPart.d.ts +0 -13
- package/dist/body/text/TextElementReferencePart.d.ts +0 -7
- package/dist/body/text/TextElementStaticPart.d.ts +0 -7
- package/dist/lib/xpath/analysis.d.ts +0 -23
- package/dist/model/BindDefinition.d.ts +0 -32
- package/src/body/control/select/ItemsetDefinition.ts +0 -36
- package/src/body/control/select/ItemsetNodesetExpression.ts +0 -8
- package/src/body/text/HintDefinition.ts +0 -26
- package/src/body/text/LabelDefinition.ts +0 -68
- package/src/body/text/TextElementDefinition.ts +0 -97
- package/src/body/text/TextElementOutputPart.ts +0 -27
- package/src/body/text/TextElementPart.ts +0 -31
- package/src/body/text/TextElementReferencePart.ts +0 -21
- package/src/body/text/TextElementStaticPart.ts +0 -26
- package/src/lib/xpath/analysis.ts +0 -241
- package/src/model/RepeatRangeDefinition.ts +0 -53
- package/src/{XFormDOM.ts → parse/XFormDOM.ts} +0 -0
- package/src/{body → parse/body}/UnsupportedBodyElementDefinition.ts +0 -0
- package/src/{body → parse/body}/control/InputDefinition.ts +1 -1
- /package/src/{body → parse/body}/group/LogicalGroupDefinition.ts +0 -0
- /package/src/{body → parse/body}/group/StructuralGroupDefinition.ts +0 -0
- /package/src/{expression → parse/expression/abstract}/DependencyContext.ts +0 -0
- /package/src/{model → parse/model}/DescendentNodeDefinition.ts +0 -0
- /package/src/{model → parse/model}/ModelDefinition.ts +0 -0
- /package/src/{model → parse/model}/RepeatTemplateDefinition.ts +0 -0
- /package/src/{model → parse/model}/SubtreeDefinition.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getodk/xforms-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "XForms engine for ODK Web Forms",
|
|
6
6
|
"type": "module",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"README.md"
|
|
30
30
|
],
|
|
31
31
|
"engines": {
|
|
32
|
-
"node": "^18.20.
|
|
33
|
-
"yarn": "1.22.
|
|
32
|
+
"node": "^18.20.4 || ^20.17.0 || ^22.8.0",
|
|
33
|
+
"yarn": "1.22.22"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "npm-run-all -nl build:*",
|
|
@@ -54,26 +54,25 @@
|
|
|
54
54
|
"test:types": "tsc --project ./tsconfig.json --emitDeclarationOnly false --noEmit"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"solid-js": "^1.8.
|
|
57
|
+
"solid-js": "^1.8.22"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@babel/core": "^7.
|
|
61
|
-
"@getodk/tree-sitter-xpath": "0.1.
|
|
62
|
-
"@getodk/xpath": "0.
|
|
63
|
-
"@playwright/test": "^1.
|
|
64
|
-
"@vitest/browser": "^
|
|
60
|
+
"@babel/core": "^7.25.2",
|
|
61
|
+
"@getodk/tree-sitter-xpath": "0.1.2",
|
|
62
|
+
"@getodk/xpath": "0.2.0",
|
|
63
|
+
"@playwright/test": "^1.46.1",
|
|
64
|
+
"@vitest/browser": "^2.0.5",
|
|
65
65
|
"babel-plugin-transform-jsbi-to-bigint": "^1.4.0",
|
|
66
66
|
"http-server": "^14.1.1",
|
|
67
|
-
"jsdom": "^
|
|
68
|
-
"typedoc": "^0.
|
|
69
|
-
"
|
|
70
|
-
"vite": "^
|
|
71
|
-
"vite-plugin-dts": "^3.9.1",
|
|
67
|
+
"jsdom": "^25.0.0",
|
|
68
|
+
"typedoc": "^0.26.6",
|
|
69
|
+
"vite": "^5.4.3",
|
|
70
|
+
"vite-plugin-dts": "^4.1.0",
|
|
72
71
|
"vite-plugin-no-bundle": "^4.0.0",
|
|
73
|
-
"vitest": "^
|
|
72
|
+
"vitest": "^2.0.5"
|
|
74
73
|
},
|
|
75
74
|
"peerDependencies": {
|
|
76
|
-
"solid-js": "^1.8.
|
|
75
|
+
"solid-js": "^1.8.18"
|
|
77
76
|
},
|
|
78
77
|
"peerDependenciesMeta": {
|
|
79
78
|
"solid-js": {
|
package/src/client/BaseNode.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { TokenListParser } from '../lib/TokenListParser.ts';
|
|
2
|
-
import type { AnyNodeDefinition } from '../model/NodeDefinition.ts';
|
|
2
|
+
import type { AnyNodeDefinition } from '../parse/model/NodeDefinition.ts';
|
|
3
3
|
import type { NodeAppearances } from './NodeAppearances.ts';
|
|
4
4
|
import type { OpaqueReactiveObjectFactory } from './OpaqueReactiveObjectFactory.ts';
|
|
5
5
|
import type { TextRange } from './TextRange.ts';
|
|
6
6
|
import type { InstanceNodeType } from './node-types.ts';
|
|
7
|
+
import type {
|
|
8
|
+
AncestorNodeValidationState,
|
|
9
|
+
LeafNodeValidationState,
|
|
10
|
+
NodeValidationState,
|
|
11
|
+
} from './validation.ts';
|
|
7
12
|
|
|
8
13
|
export interface BaseNodeState {
|
|
9
14
|
/**
|
|
@@ -43,11 +48,17 @@ export interface BaseNodeState {
|
|
|
43
48
|
*/
|
|
44
49
|
get relevant(): boolean;
|
|
45
50
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Specifies whether the node must have a non-blank value to be valid (see
|
|
53
|
+
* {@link value} for details).
|
|
54
|
+
*
|
|
55
|
+
* @see {@link https://getodk.github.io/xforms-spec/#bind-attributes}
|
|
56
|
+
*
|
|
57
|
+
* @default false
|
|
58
|
+
*
|
|
59
|
+
* @todo What is the expected behavior of `required` expressions defined for
|
|
60
|
+
* non-leaf/value nodes?
|
|
61
|
+
*/
|
|
51
62
|
get required(): boolean;
|
|
52
63
|
|
|
53
64
|
/**
|
|
@@ -106,6 +117,14 @@ export interface BaseNodeState {
|
|
|
106
117
|
*
|
|
107
118
|
* Parent nodes, i.e. nodes which can contain {@link children}, do not store a
|
|
108
119
|
* value state. For those nodes, their value state should always be `null`.
|
|
120
|
+
*
|
|
121
|
+
* A node's value is considered "blank" when its primary instance state is an
|
|
122
|
+
* empty string, and it is considered "non-blank" otherwise. The engine may
|
|
123
|
+
* represent node values according to aspects of the node's definition (such
|
|
124
|
+
* as its defined data type, its associated control type if any). The node's
|
|
125
|
+
* value being blank or non-blank may contribute to satisfying conditions of
|
|
126
|
+
* the node's validity ({@link constraint}, {@link required}). Otherwise, it
|
|
127
|
+
* is an internal engine consideration.
|
|
109
128
|
*/
|
|
110
129
|
get value(): unknown;
|
|
111
130
|
}
|
|
@@ -181,8 +200,55 @@ export interface BaseNode {
|
|
|
181
200
|
readonly parent: BaseNode | null;
|
|
182
201
|
|
|
183
202
|
/**
|
|
184
|
-
* Each node provides a discrete object representing the stateful aspects of
|
|
185
|
-
* that node which will change over time. When a client provides a
|
|
203
|
+
* Each node provides a discrete object representing the stateful aspects\* of
|
|
204
|
+
* that node which will change over time. When a client provides a
|
|
205
|
+
* {@link OpaqueReactiveObjectFactory}, the engine will update the properties
|
|
206
|
+
* of this object as their respective states change, so a client can implement
|
|
207
|
+
* reactive updates that respond to changes as they occur.
|
|
208
|
+
*
|
|
209
|
+
* \* This includes state which is either client-/user-mutable, or state which
|
|
210
|
+
* is computed based on the core XForms computation model. Each node also
|
|
211
|
+
* exposes {@link validationState}, which reflects the validity of the
|
|
212
|
+
* node, or its descendants.
|
|
186
213
|
*/
|
|
187
214
|
readonly currentState: BaseNodeState;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Represents the validation state of a the node itself, or its descendants.
|
|
218
|
+
*
|
|
219
|
+
* @see {@link AncestorNodeValidationState} and
|
|
220
|
+
* {@link LeafNodeValidationState} for additional details.
|
|
221
|
+
*
|
|
222
|
+
* While filling a form (i.e. prior to submission), validation state can be
|
|
223
|
+
* viewed as computed metadata about the form state. The validation conditions
|
|
224
|
+
* and their violation messages produced by a node _may be computed on
|
|
225
|
+
* demand_. Clients should assume:
|
|
226
|
+
*
|
|
227
|
+
* 1. Validation state **will be current** when directly read by the client.
|
|
228
|
+
* Accessing validation state _may_ invoke engine computation of that state
|
|
229
|
+
* _at that time_.
|
|
230
|
+
*
|
|
231
|
+
* It **may** also be pre-computed by the engine so that direct reads are
|
|
232
|
+
* less computationally expensive, but such optimizations cannot be
|
|
233
|
+
* guaranteed by the engine at this time.
|
|
234
|
+
*
|
|
235
|
+
* 2. For clients providing an {@link OpaqueReactiveObjectFactory}, accessing
|
|
236
|
+
* validation state within a reactive context **will produce updates** to
|
|
237
|
+
* the validation state, as long as the client retains a subscription to
|
|
238
|
+
* that state.
|
|
239
|
+
*
|
|
240
|
+
* If it is possible to detect interruption of such client- reactive
|
|
241
|
+
* subscriptions, the engine _may defer computations_ until subsequent
|
|
242
|
+
* client read/re-subscription, in order to reduce unnecessary
|
|
243
|
+
* computational overhead. Again, such optimizations cannot be guaranteed
|
|
244
|
+
* by the engine at this time.
|
|
245
|
+
*
|
|
246
|
+
* @todo it's easier to conceive a reliable, general solution to optimizing
|
|
247
|
+
* the direct read case, than it is for the client-reactive case (largely
|
|
248
|
+
* because our solution for client reactivity is intentionally opaque). If it
|
|
249
|
+
* turns out that such optimizations are crucial for overall usability, the
|
|
250
|
+
* client-reactive case may best be served by additional APIs for reactive
|
|
251
|
+
* clients to explicitly pause and resume recomputation.
|
|
252
|
+
*/
|
|
253
|
+
readonly validationState: NodeValidationState;
|
|
188
254
|
}
|
package/src/client/GroupNode.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { AnyGroupElementDefinition } from '../body/BodyDefinition.ts';
|
|
2
|
-
import type { SubtreeDefinition } from '../model/SubtreeDefinition.ts';
|
|
1
|
+
import type { AnyGroupElementDefinition } from '../parse/body/BodyDefinition.ts';
|
|
2
|
+
import type { SubtreeDefinition } from '../parse/model/SubtreeDefinition.ts';
|
|
3
3
|
import type { BaseNode, BaseNodeState } from './BaseNode.ts';
|
|
4
4
|
import type { NodeAppearances } from './NodeAppearances.ts';
|
|
5
5
|
import type { RootNode } from './RootNode.ts';
|
|
6
6
|
import type { GeneralChildNode, GeneralParentNode } from './hierarchy.ts';
|
|
7
|
+
import type { AncestorNodeValidationState } from './validation.ts';
|
|
7
8
|
|
|
8
9
|
export interface GroupNodeState extends BaseNodeState {
|
|
9
10
|
get hint(): null;
|
|
@@ -34,4 +35,5 @@ export interface GroupNode extends BaseNode {
|
|
|
34
35
|
readonly root: RootNode;
|
|
35
36
|
readonly parent: GeneralParentNode;
|
|
36
37
|
readonly currentState: GroupNodeState;
|
|
38
|
+
readonly validationState: AncestorNodeValidationState;
|
|
37
39
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { LeafNodeDefinition } from '../parse/model/LeafNodeDefinition.ts';
|
|
2
|
+
import type { BaseNode, BaseNodeState } from './BaseNode.ts';
|
|
3
|
+
import type { GeneralParentNode } from './hierarchy.ts';
|
|
4
|
+
import type { RootNode } from './RootNode.ts';
|
|
5
|
+
import type { LeafNodeValidationState } from './validation.ts';
|
|
6
|
+
|
|
7
|
+
export interface ModelValueNodeState extends BaseNodeState {
|
|
8
|
+
get label(): null;
|
|
9
|
+
get hint(): null;
|
|
10
|
+
get children(): null;
|
|
11
|
+
get valueOptions(): null;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Reflects the current value of a {@link ModelValueNode}. This value may be
|
|
15
|
+
* populated when a form is loaded, and it may be updated by certain
|
|
16
|
+
* computations defined by the form.
|
|
17
|
+
*/
|
|
18
|
+
get value(): string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ModelValueDefinition extends LeafNodeDefinition {
|
|
22
|
+
readonly bodyElement: null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A node which is:
|
|
27
|
+
*
|
|
28
|
+
* - model-only (i.e. it has no corresponding body element)
|
|
29
|
+
* - a leaf/value node (i.e. it has no element children; it may be defined in
|
|
30
|
+
* the form's `<model>` as either an {@link Element} or {@link Attr})
|
|
31
|
+
*/
|
|
32
|
+
export interface ModelValueNode extends BaseNode {
|
|
33
|
+
readonly nodeType: 'model-value';
|
|
34
|
+
readonly appearances: null;
|
|
35
|
+
readonly definition: ModelValueDefinition;
|
|
36
|
+
readonly root: RootNode;
|
|
37
|
+
readonly parent: GeneralParentNode;
|
|
38
|
+
readonly currentState: ModelValueNodeState;
|
|
39
|
+
readonly validationState: LeafNodeValidationState;
|
|
40
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ParsedTokenList } from '../lib/TokenListParser.ts';
|
|
2
|
-
import type { NodeDefinition } from '../model/NodeDefinition.ts';
|
|
2
|
+
import type { NodeDefinition } from '../parse/model/NodeDefinition.ts';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* - Provides a means to distinguish between internal and client-facing names
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { InputDefinition } from '../parse/body/control/InputDefinition.ts';
|
|
2
|
+
import type { LeafNodeDefinition } from '../parse/model/LeafNodeDefinition.ts';
|
|
3
|
+
import type { BaseNode, BaseNodeState } from './BaseNode.ts';
|
|
4
|
+
import type { GeneralParentNode } from './hierarchy.ts';
|
|
5
|
+
import type { NodeAppearances } from './NodeAppearances.ts';
|
|
6
|
+
import type { RootNode } from './RootNode.ts';
|
|
7
|
+
import type { TextRange } from './TextRange.ts';
|
|
8
|
+
import type { LeafNodeValidationState } from './validation.ts';
|
|
9
|
+
|
|
10
|
+
export interface NoteNodeState extends BaseNodeState {
|
|
11
|
+
/**
|
|
12
|
+
* Note-specific specialization: a note will always have a non-null value in
|
|
13
|
+
* at least one of:
|
|
14
|
+
*
|
|
15
|
+
* - {@link label}
|
|
16
|
+
* - {@link hint}
|
|
17
|
+
*
|
|
18
|
+
* This is an alias to whichever is present, with precedent to {@link label}
|
|
19
|
+
* if both are present.
|
|
20
|
+
*/
|
|
21
|
+
// ^ @todo While it's possible to convey this at the type level, the resulting
|
|
22
|
+
// types would be far more complex than this, which is not ideal especially at
|
|
23
|
+
// the package (client) boundary. This alias is a concession that the simpler
|
|
24
|
+
// type is preferred, but that it is still important to convey to clients
|
|
25
|
+
// that at least one form-defined text value will always be available. Note:
|
|
26
|
+
// at least for a first pass, we won't guarantee that the resulting text is
|
|
27
|
+
// non-empty. (We'd probably need to accept an engine fallback to make that
|
|
28
|
+
// guarantee; otherwise we'd need to error on invalid state, potentially at
|
|
29
|
+
// arbitrary points in time.)
|
|
30
|
+
//
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
32
|
+
get noteText(): NonNullable<this['label'] | this['hint']>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A note will **always** be `readonly`.
|
|
36
|
+
*/
|
|
37
|
+
readonly readonly: true;
|
|
38
|
+
|
|
39
|
+
get label(): TextRange<'label', 'form'> | null;
|
|
40
|
+
get hint(): TextRange<'hint', 'form'> | null;
|
|
41
|
+
get children(): null;
|
|
42
|
+
get valueOptions(): null;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Reflects the readonly value of a {@link NoteNode}, or `null` if blank.
|
|
46
|
+
*/
|
|
47
|
+
// Note that being nullable is an intentional deviation from most other value
|
|
48
|
+
// node types, specifically to make a clear distinction between blank and
|
|
49
|
+
// non-blank values (as that has been a primary driver for prioritizing note
|
|
50
|
+
// functionality).
|
|
51
|
+
get value(): string | null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface NoteDefinition extends LeafNodeDefinition {
|
|
55
|
+
readonly bodyElement: InputDefinition;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type NoteNodeAppearances = NodeAppearances<NoteDefinition>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A node which is:
|
|
62
|
+
*
|
|
63
|
+
* - associated with an input, with at least one text element (label or hint)
|
|
64
|
+
* - guaranteed to be {@link NoteNodeState.readonly | readonly}
|
|
65
|
+
*/
|
|
66
|
+
export interface NoteNode extends BaseNode {
|
|
67
|
+
readonly nodeType: 'note';
|
|
68
|
+
readonly appearances: NoteNodeAppearances;
|
|
69
|
+
readonly definition: NoteDefinition;
|
|
70
|
+
readonly root: RootNode;
|
|
71
|
+
readonly parent: GeneralParentNode;
|
|
72
|
+
readonly currentState: NoteNodeState;
|
|
73
|
+
readonly validationState: LeafNodeValidationState;
|
|
74
|
+
}
|
package/src/client/README.md
CHANGED
|
@@ -20,6 +20,7 @@ The interface is designed to:
|
|
|
20
20
|
- Facilitate loading any of a form's externally referenced resources, by means of a client-provided generic resource accessor[^2]
|
|
21
21
|
|
|
22
22
|
[^1]: This factory **may be** reactive, and for many clients that is the anticipated usage. But no assumptions are made by the engine about reactivity or any other implementation details beyond the factory's type definition.
|
|
23
|
+
|
|
23
24
|
[^2]: This accessor **may** access networked resources, and for many clients that is the anticipated usage. But no assumptions are made by the engine about the provenance of any resources it requests beyond the accessor's type definition.
|
|
24
25
|
|
|
25
26
|
### Non-goals
|
package/src/client/RootNode.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { BodyClassList } from '../body/BodyDefinition.ts';
|
|
2
|
-
import type { RootDefinition } from '../model/RootDefinition.ts';
|
|
1
|
+
import type { BodyClassList } from '../parse/body/BodyDefinition.ts';
|
|
2
|
+
import type { RootDefinition } from '../parse/model/RootDefinition.ts';
|
|
3
3
|
import type { BaseNode, BaseNodeState } from './BaseNode.ts';
|
|
4
4
|
import type { ActiveLanguage, FormLanguage, FormLanguages } from './FormLanguage.ts';
|
|
5
5
|
import type { GeneralChildNode } from './hierarchy.ts';
|
|
6
|
+
import type { AncestorNodeValidationState } from './validation.ts';
|
|
6
7
|
|
|
7
8
|
export interface RootNodeState extends BaseNodeState {
|
|
8
9
|
/**
|
|
@@ -47,6 +48,7 @@ export interface RootNode extends BaseNode {
|
|
|
47
48
|
readonly root: RootNode;
|
|
48
49
|
readonly parent: null;
|
|
49
50
|
readonly currentState: RootNodeState;
|
|
51
|
+
readonly validationState: AncestorNodeValidationState;
|
|
50
52
|
|
|
51
53
|
/**
|
|
52
54
|
* @todo as with {@link RootNodeState.activeLanguage}, this is the most
|
package/src/client/SelectNode.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import type { AnySelectDefinition } from '../body/control/select/SelectDefinition.ts';
|
|
2
|
-
import type {
|
|
1
|
+
import type { AnySelectDefinition } from '../parse/body/control/select/SelectDefinition.ts';
|
|
2
|
+
import type { LeafNodeDefinition } from '../parse/model/LeafNodeDefinition.ts';
|
|
3
3
|
import type { BaseNode, BaseNodeState } from './BaseNode.ts';
|
|
4
4
|
import type { NodeAppearances } from './NodeAppearances.ts';
|
|
5
5
|
import type { RootNode } from './RootNode.ts';
|
|
6
6
|
import type { StringNode } from './StringNode.ts';
|
|
7
7
|
import type { TextRange } from './TextRange.ts';
|
|
8
8
|
import type { GeneralParentNode } from './hierarchy.ts';
|
|
9
|
+
import type { LeafNodeValidationState } from './validation.ts';
|
|
9
10
|
|
|
10
11
|
export interface SelectItem {
|
|
11
12
|
get value(): string;
|
|
12
|
-
get label(): TextRange<'label'> | null;
|
|
13
|
+
get label(): TextRange<'item-label'> | null;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export interface SelectNodeState extends BaseNodeState {
|
|
@@ -35,7 +36,7 @@ export interface SelectNodeState extends BaseNodeState {
|
|
|
35
36
|
get value(): readonly SelectItem[];
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
export interface SelectDefinition extends
|
|
39
|
+
export interface SelectDefinition extends LeafNodeDefinition {
|
|
39
40
|
readonly bodyElement: AnySelectDefinition;
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -48,6 +49,7 @@ export interface SelectNode extends BaseNode {
|
|
|
48
49
|
readonly root: RootNode;
|
|
49
50
|
readonly parent: GeneralParentNode;
|
|
50
51
|
readonly currentState: SelectNodeState;
|
|
52
|
+
readonly validationState: LeafNodeValidationState;
|
|
51
53
|
|
|
52
54
|
/**
|
|
53
55
|
* For use by a client to update the selection of a select node where:
|
package/src/client/StringNode.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { InputDefinition } from '../body/control/InputDefinition.ts';
|
|
2
|
-
import type {
|
|
1
|
+
import type { InputDefinition } from '../parse/body/control/InputDefinition.ts';
|
|
2
|
+
import type { LeafNodeDefinition } from '../parse/model/LeafNodeDefinition.ts';
|
|
3
3
|
import type { BaseNode, BaseNodeState } from './BaseNode.ts';
|
|
4
4
|
import type { NodeAppearances } from './NodeAppearances.ts';
|
|
5
5
|
import type { RootNode } from './RootNode.ts';
|
|
6
6
|
import type { GeneralParentNode } from './hierarchy.ts';
|
|
7
|
+
import type { LeafNodeValidationState } from './validation.ts';
|
|
7
8
|
|
|
8
9
|
export interface StringNodeState extends BaseNodeState {
|
|
9
10
|
get children(): null;
|
|
@@ -18,8 +19,8 @@ export interface StringNodeState extends BaseNodeState {
|
|
|
18
19
|
get value(): string;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export interface StringDefinition extends
|
|
22
|
-
readonly bodyElement: InputDefinition
|
|
22
|
+
export interface StringDefinition extends LeafNodeDefinition {
|
|
23
|
+
readonly bodyElement: InputDefinition;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export type StringNodeAppearances = NodeAppearances<StringDefinition>;
|
|
@@ -38,6 +39,7 @@ export interface StringNode extends BaseNode {
|
|
|
38
39
|
readonly root: RootNode;
|
|
39
40
|
readonly parent: GeneralParentNode;
|
|
40
41
|
readonly currentState: StringNodeState;
|
|
42
|
+
readonly validationState: LeafNodeValidationState;
|
|
41
43
|
|
|
42
44
|
/**
|
|
43
45
|
* For use by a client to update the value of a string node.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { SubtreeDefinition as BaseSubtreeDefinition } from '../model/SubtreeDefinition.ts';
|
|
1
|
+
import type { SubtreeDefinition as BaseSubtreeDefinition } from '../parse/model/SubtreeDefinition.ts';
|
|
2
2
|
import type { BaseNode, BaseNodeState } from './BaseNode.ts';
|
|
3
3
|
import type { RootNode } from './RootNode.ts';
|
|
4
4
|
import type { GeneralChildNode, GeneralParentNode } from './hierarchy.ts';
|
|
5
|
+
import type { AncestorNodeValidationState } from './validation.ts';
|
|
5
6
|
|
|
6
7
|
export interface SubtreeNodeState extends BaseNodeState {
|
|
7
8
|
get label(): null;
|
|
@@ -55,4 +56,5 @@ export interface SubtreeNode extends BaseNode {
|
|
|
55
56
|
readonly root: RootNode;
|
|
56
57
|
readonly parent: GeneralParentNode;
|
|
57
58
|
readonly currentState: SubtreeNodeState;
|
|
59
|
+
readonly validationState: AncestorNodeValidationState;
|
|
58
60
|
}
|
package/src/client/TextRange.ts
CHANGED
|
@@ -1,7 +1,69 @@
|
|
|
1
1
|
import type { ActiveLanguage } from './FormLanguage.ts';
|
|
2
2
|
import type { RootNodeState } from './RootNode.ts';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* **COMMENTARY**
|
|
6
|
+
*
|
|
7
|
+
* The spec makes naming and mapping these cases a bit more complex than would
|
|
8
|
+
* be ideal. The intent is to clearly identify distinct text definitions (and
|
|
9
|
+
* sub-structural parts) from a source form, in a way that semantically lines up
|
|
10
|
+
* with the ways they will need to be handled at runtime and conveyed to
|
|
11
|
+
* clients. This is the mapping:
|
|
12
|
+
*
|
|
13
|
+
* - 'output': All output values, i.e.:
|
|
14
|
+
* - `output/@value`
|
|
15
|
+
*
|
|
16
|
+
* - 'translation':
|
|
17
|
+
*
|
|
18
|
+
* - Valid XPath translation expressions, in a context accepting mixed
|
|
19
|
+
* translation/static syntax, i.e.:
|
|
20
|
+
*
|
|
21
|
+
* - `h:head//bind/@jr:constraintMsg[is-translation-expr()]`
|
|
22
|
+
* - `h:head//bind/@jr:requiredMsg[is-translation-expr()]`
|
|
23
|
+
*
|
|
24
|
+
* Here, `is-translation-expr()` is a fictional shorthand for checking
|
|
25
|
+
* that the attribute's value is a valid `jr:itext(...)` FunctionCall
|
|
26
|
+
* expression. Note that, per spec, these attributes **do not accept
|
|
27
|
+
* arbitrary XPath expressions**! The non-translation case is treated as
|
|
28
|
+
* static text, not parsed for e.g. an XPath [string] Literal expression.
|
|
29
|
+
* This is why we have introduced this 'translation' case, distinct from
|
|
30
|
+
* 'reference', which previously handled translated labels and hints.
|
|
31
|
+
*
|
|
32
|
+
* - Valid XPath translation expressions, in a context accepting arbitrary
|
|
33
|
+
* XPath expressions, i.e.:
|
|
34
|
+
*
|
|
35
|
+
* - `h:body//label/@ref[is-translation-expr()]`
|
|
36
|
+
*
|
|
37
|
+
* - 'literal':
|
|
38
|
+
* - `h:head//bind/@jr:constraintMsg[not(is-translation-expr())]`
|
|
39
|
+
* - `h:head//bind/@jr:requiredMsg[not(is-translation-expr())]`
|
|
40
|
+
* - `h:body//label/text()`
|
|
41
|
+
* - `h:body//hint/text()`
|
|
42
|
+
*
|
|
43
|
+
* (See notes above for clarification of `is-translation-expr()`.)
|
|
44
|
+
*
|
|
45
|
+
* - 'reference': Any XPath **non-translation** expression defined as a label's
|
|
46
|
+
* (or hint's) `ref` attribute, i.e.
|
|
47
|
+
* - `h:body//label/@ref[not(is-translation-expr())]`
|
|
48
|
+
* - `h:body//hint/@ref[not(is-translation-expr())]`
|
|
49
|
+
*
|
|
50
|
+
* (See notes above for clarification of `is-translation-expr()`.)
|
|
51
|
+
*
|
|
52
|
+
* @todo It's unclear whether this will all become simpler or more compelex when
|
|
53
|
+
* we add support for outputs in translations. In theory, the actual translation
|
|
54
|
+
* `<text>` nodes map quite well to the `TextRange` concept (i.e. they are a
|
|
55
|
+
* range of static and output chunks, just like labels and hints). The potential
|
|
56
|
+
* for complications arise from XPath implementation details being largely
|
|
57
|
+
* opaque (as in, the `jr:itext` implementation is encapsulated in the `xpath`
|
|
58
|
+
* package, and the engine doesn't really deal with itext translations at the
|
|
59
|
+
* node level at all).
|
|
60
|
+
*/
|
|
61
|
+
// prettier-ignore
|
|
62
|
+
export type TextChunkSource =
|
|
63
|
+
| 'literal'
|
|
64
|
+
| 'output'
|
|
65
|
+
| 'reference'
|
|
66
|
+
| 'translation';
|
|
5
67
|
|
|
6
68
|
/**
|
|
7
69
|
* @todo This (and everything else to do with {@link TextRange}s is for
|
|
@@ -23,6 +85,39 @@ export interface TextChunk {
|
|
|
23
85
|
get formatted(): unknown;
|
|
24
86
|
}
|
|
25
87
|
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
89
|
+
export type ElementTextRole = 'hint' | 'label' | 'item-label';
|
|
90
|
+
export type ValidationTextRole = 'constraintMsg' | 'requiredMsg';
|
|
91
|
+
export type TextRole = ElementTextRole | ValidationTextRole;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Specifies the origin of a {@link TextRange}.
|
|
95
|
+
*
|
|
96
|
+
* - 'form': text is computed from the form definition, as specified for the
|
|
97
|
+
* {@link TextRole}. User-facing clients should present text with this origin
|
|
98
|
+
* where appropriate.
|
|
99
|
+
*
|
|
100
|
+
* - 'form-derived': the form definition lacks a text definition for the
|
|
101
|
+
* {@link TextRole}, but an appropriate one has been derived from a related
|
|
102
|
+
* (and semantically appropriate) aspect of the form (example: a select item
|
|
103
|
+
* without a label may derive that label from the item's value). User-facing
|
|
104
|
+
* clients should generally present text with this origin where provided; this
|
|
105
|
+
* origin clarifies the source of such text.
|
|
106
|
+
*
|
|
107
|
+
* - 'engine': the form definition lacks a definition for the {@link TextRole},
|
|
108
|
+
* but provides a constant default in its absence. User facing clients may
|
|
109
|
+
* disregard these constant text values, or may use them where a sensible
|
|
110
|
+
* default is desired. Clients may also use these constants as keys for
|
|
111
|
+
* translation purposes, as appropriate. Non-user facing clients may reference
|
|
112
|
+
* these constants for e.g. testing purposes.
|
|
113
|
+
*/
|
|
114
|
+
// prettier-ignore
|
|
115
|
+
export type TextOrigin =
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
117
|
+
| 'form'
|
|
118
|
+
| 'form-derived'
|
|
119
|
+
| 'engine';
|
|
120
|
+
|
|
26
121
|
/**
|
|
27
122
|
* Represents aspects of a form which produce text, which _might_ be:
|
|
28
123
|
*
|
|
@@ -53,7 +148,8 @@ export interface TextChunk {
|
|
|
53
148
|
* a text range's role may correspond to the "short" or "guidance" `form` of a
|
|
54
149
|
* {@link https://getodk.github.io/xforms-spec/#languages | translation}).
|
|
55
150
|
*/
|
|
56
|
-
export interface TextRange<Role extends
|
|
151
|
+
export interface TextRange<Role extends TextRole, Origin extends TextOrigin = TextOrigin> {
|
|
152
|
+
readonly origin: Origin;
|
|
57
153
|
readonly role: Role;
|
|
58
154
|
|
|
59
155
|
[Symbol.iterator](): Iterable<TextChunk>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { UnknownAppearanceDefinition } from '../parse/body/appearance/unknownAppearanceParser.ts';
|
|
2
|
+
import type { TriggerControlDefinition } from '../parse/body/control/TriggerControlDefinition.ts';
|
|
3
|
+
import type { LeafNodeDefinition } from '../parse/model/LeafNodeDefinition.ts';
|
|
4
|
+
import type { BaseNode, BaseNodeState } from './BaseNode.ts';
|
|
5
|
+
import type { GeneralParentNode } from './hierarchy.ts';
|
|
6
|
+
import type { RootNode } from './RootNode.ts';
|
|
7
|
+
import type { LeafNodeValidationState } from './validation.ts';
|
|
8
|
+
|
|
9
|
+
export interface TriggerNodeState extends BaseNodeState {
|
|
10
|
+
get children(): null;
|
|
11
|
+
get valueOptions(): null;
|
|
12
|
+
get value(): boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface TriggerNodeDefinition extends LeafNodeDefinition {
|
|
16
|
+
readonly bodyElement: TriggerControlDefinition;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface TriggerNode extends BaseNode {
|
|
20
|
+
readonly nodeType: 'trigger';
|
|
21
|
+
readonly definition: TriggerNodeDefinition;
|
|
22
|
+
readonly appearances: UnknownAppearanceDefinition;
|
|
23
|
+
readonly root: RootNode;
|
|
24
|
+
readonly parent: GeneralParentNode;
|
|
25
|
+
readonly currentState: TriggerNodeState;
|
|
26
|
+
readonly validationState: LeafNodeValidationState;
|
|
27
|
+
|
|
28
|
+
setValue(value: boolean): RootNode;
|
|
29
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ValidationTextRole } from './TextRange.ts';
|
|
2
|
+
|
|
3
|
+
export const VALIDATION_TEXT = {
|
|
4
|
+
constraintMsg: 'Condition not satisfied: constraint',
|
|
5
|
+
requiredMsg: 'Condition not satisfied: required',
|
|
6
|
+
} as const satisfies Record<ValidationTextRole, string>;
|
|
7
|
+
|
|
8
|
+
type ValidationTextDefaults = typeof VALIDATION_TEXT;
|
|
9
|
+
|
|
10
|
+
export type ValidationTextDefault<Role extends ValidationTextRole> = ValidationTextDefaults[Role];
|