@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
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { identity } from '@getodk/common/lib/identity.ts';
|
|
2
|
+
import type { ModelValueNode } from '../client/ModelValueNode.ts';
|
|
3
|
+
import type { AnyViolation, LeafNodeValidationState } from '../client/validation.ts';
|
|
4
|
+
import { createValueState } from '../lib/reactivity/createValueState.ts';
|
|
5
|
+
import type { CurrentState } from '../lib/reactivity/node-state/createCurrentState.ts';
|
|
6
|
+
import type { EngineState } from '../lib/reactivity/node-state/createEngineState.ts';
|
|
7
|
+
import type { SharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
|
|
8
|
+
import { createSharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
|
|
9
|
+
import type { SimpleAtomicState } from '../lib/reactivity/types.ts';
|
|
10
|
+
import type { SharedValidationState } from '../lib/reactivity/validation/createValidation.ts';
|
|
11
|
+
import { createValidationState } from '../lib/reactivity/validation/createValidation.ts';
|
|
12
|
+
import type { LeafNodeDefinition } from '../parse/model/LeafNodeDefinition.ts';
|
|
13
|
+
import type { DescendantNodeStateSpec } from './abstract/DescendantNode.ts';
|
|
14
|
+
import { DescendantNode } from './abstract/DescendantNode.ts';
|
|
15
|
+
import type { GeneralParentNode } from './hierarchy.ts';
|
|
16
|
+
import type { EvaluationContext } from './internal-api/EvaluationContext.ts';
|
|
17
|
+
import type { SubscribableDependency } from './internal-api/SubscribableDependency.ts';
|
|
18
|
+
import type { ValidationContext } from './internal-api/ValidationContext.ts';
|
|
19
|
+
import type { ValueContext } from './internal-api/ValueContext.ts';
|
|
20
|
+
|
|
21
|
+
export interface ModelValueDefinition extends LeafNodeDefinition {
|
|
22
|
+
readonly bodyElement: null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface ModelValueStateSpec extends DescendantNodeStateSpec<string> {
|
|
26
|
+
readonly label: null;
|
|
27
|
+
readonly hint: null;
|
|
28
|
+
readonly children: null;
|
|
29
|
+
readonly value: SimpleAtomicState<string>;
|
|
30
|
+
readonly valueOptions: null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class ModelValue
|
|
34
|
+
extends DescendantNode<ModelValueDefinition, ModelValueStateSpec, null>
|
|
35
|
+
implements
|
|
36
|
+
ModelValueNode,
|
|
37
|
+
EvaluationContext,
|
|
38
|
+
SubscribableDependency,
|
|
39
|
+
ValidationContext,
|
|
40
|
+
ValueContext<string>
|
|
41
|
+
{
|
|
42
|
+
private readonly validation: SharedValidationState;
|
|
43
|
+
protected readonly state: SharedNodeState<ModelValueStateSpec>;
|
|
44
|
+
|
|
45
|
+
// InstanceNode
|
|
46
|
+
protected engineState: EngineState<ModelValueStateSpec>;
|
|
47
|
+
|
|
48
|
+
// ModelValueNode
|
|
49
|
+
readonly nodeType = 'model-value';
|
|
50
|
+
readonly appearances = null;
|
|
51
|
+
readonly currentState: CurrentState<ModelValueStateSpec>;
|
|
52
|
+
|
|
53
|
+
get validationState(): LeafNodeValidationState {
|
|
54
|
+
return this.validation.currentState;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ValueContext
|
|
58
|
+
readonly encodeValue = identity<string>;
|
|
59
|
+
readonly decodeValue = identity<string>;
|
|
60
|
+
|
|
61
|
+
constructor(parent: GeneralParentNode, definition: ModelValueDefinition) {
|
|
62
|
+
super(parent, definition);
|
|
63
|
+
|
|
64
|
+
const sharedStateOptions = {
|
|
65
|
+
clientStateFactory: this.engineConfig.stateFactory,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const state = createSharedNodeState(
|
|
69
|
+
this.scope,
|
|
70
|
+
{
|
|
71
|
+
reference: this.contextReference,
|
|
72
|
+
readonly: this.isReadonly,
|
|
73
|
+
relevant: this.isRelevant,
|
|
74
|
+
required: this.isRequired,
|
|
75
|
+
|
|
76
|
+
label: null,
|
|
77
|
+
hint: null,
|
|
78
|
+
children: null,
|
|
79
|
+
valueOptions: null,
|
|
80
|
+
value: createValueState(this),
|
|
81
|
+
},
|
|
82
|
+
sharedStateOptions
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
this.state = state;
|
|
86
|
+
this.engineState = state.engineState;
|
|
87
|
+
this.currentState = state.currentState;
|
|
88
|
+
this.validation = createValidationState(this, sharedStateOptions);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ValidationContext
|
|
92
|
+
getViolation(): AnyViolation | null {
|
|
93
|
+
return this.validation.engineState.violation;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
isBlank(): boolean {
|
|
97
|
+
return this.engineState.value === '';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// InstanceNode
|
|
101
|
+
getChildren(): readonly [] {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { UnreachableError } from '@getodk/common/lib/error/UnreachableError.ts';
|
|
2
|
+
import { identity } from '@getodk/common/lib/identity.ts';
|
|
3
|
+
import type { Accessor } from 'solid-js';
|
|
4
|
+
import type { NoteNode, NoteNodeAppearances } from '../client/NoteNode.ts';
|
|
5
|
+
import type { TextRange } from '../client/TextRange.ts';
|
|
6
|
+
import type { AnyViolation, LeafNodeValidationState } from '../client/validation.ts';
|
|
7
|
+
import { createNoteReadonlyThunk } from '../lib/reactivity/createNoteReadonlyThunk.ts';
|
|
8
|
+
import { createValueState } from '../lib/reactivity/createValueState.ts';
|
|
9
|
+
import type { CurrentState } from '../lib/reactivity/node-state/createCurrentState.ts';
|
|
10
|
+
import type { EngineState } from '../lib/reactivity/node-state/createEngineState.ts';
|
|
11
|
+
import type { SharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
|
|
12
|
+
import { createSharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
|
|
13
|
+
import { createFieldHint } from '../lib/reactivity/text/createFieldHint.ts';
|
|
14
|
+
import { createNodeLabel } from '../lib/reactivity/text/createNodeLabel.ts';
|
|
15
|
+
import { createNoteText, type ComputedNoteText } from '../lib/reactivity/text/createNoteText.ts';
|
|
16
|
+
import type { SimpleAtomicState } from '../lib/reactivity/types.ts';
|
|
17
|
+
import type { SharedValidationState } from '../lib/reactivity/validation/createValidation.ts';
|
|
18
|
+
import { createValidationState } from '../lib/reactivity/validation/createValidation.ts';
|
|
19
|
+
import type { NoteNodeDefinition } from '../parse/model/NoteNodeDefinition.ts';
|
|
20
|
+
import type { DescendantNodeStateSpec } from './abstract/DescendantNode.ts';
|
|
21
|
+
import { DescendantNode } from './abstract/DescendantNode.ts';
|
|
22
|
+
import type { GeneralParentNode } from './hierarchy.ts';
|
|
23
|
+
import type { EvaluationContext } from './internal-api/EvaluationContext.ts';
|
|
24
|
+
import type { SubscribableDependency } from './internal-api/SubscribableDependency.ts';
|
|
25
|
+
import type { ValidationContext } from './internal-api/ValidationContext.ts';
|
|
26
|
+
import type { ValueContext } from './internal-api/ValueContext.ts';
|
|
27
|
+
|
|
28
|
+
interface NoteStateSpec extends DescendantNodeStateSpec<string> {
|
|
29
|
+
readonly readonly: Accessor<true>;
|
|
30
|
+
readonly noteText: ComputedNoteText;
|
|
31
|
+
readonly label: Accessor<TextRange<'label', 'form'> | null>;
|
|
32
|
+
readonly hint: Accessor<TextRange<'hint', 'form'> | null>;
|
|
33
|
+
readonly children: null;
|
|
34
|
+
readonly value: SimpleAtomicState<string>;
|
|
35
|
+
readonly valueOptions: null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class Note
|
|
39
|
+
extends DescendantNode<NoteNodeDefinition, NoteStateSpec, null>
|
|
40
|
+
implements
|
|
41
|
+
NoteNode,
|
|
42
|
+
EvaluationContext,
|
|
43
|
+
SubscribableDependency,
|
|
44
|
+
ValidationContext,
|
|
45
|
+
ValueContext<string>
|
|
46
|
+
{
|
|
47
|
+
private readonly validation: SharedValidationState;
|
|
48
|
+
protected readonly state: SharedNodeState<NoteStateSpec>;
|
|
49
|
+
|
|
50
|
+
// InstanceNode
|
|
51
|
+
protected engineState: EngineState<NoteStateSpec>;
|
|
52
|
+
|
|
53
|
+
// NoteNode
|
|
54
|
+
readonly nodeType = 'note';
|
|
55
|
+
readonly appearances: NoteNodeAppearances;
|
|
56
|
+
readonly currentState: CurrentState<NoteStateSpec>;
|
|
57
|
+
|
|
58
|
+
get validationState(): LeafNodeValidationState {
|
|
59
|
+
return this.validation.currentState;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ValueContext
|
|
63
|
+
readonly encodeValue = identity<string>;
|
|
64
|
+
|
|
65
|
+
readonly decodeValue = identity<string>;
|
|
66
|
+
|
|
67
|
+
constructor(parent: GeneralParentNode, definition: NoteNodeDefinition) {
|
|
68
|
+
super(parent, definition);
|
|
69
|
+
|
|
70
|
+
this.appearances = definition.bodyElement.appearances;
|
|
71
|
+
|
|
72
|
+
const sharedStateOptions = {
|
|
73
|
+
clientStateFactory: this.engineConfig.stateFactory,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const isReadonly = createNoteReadonlyThunk(this, definition.bind.readonly);
|
|
77
|
+
const noteTextComputation = createNoteText(this, definition.noteTextDefinition);
|
|
78
|
+
|
|
79
|
+
let noteText: ComputedNoteText;
|
|
80
|
+
let label: Accessor<TextRange<'label', 'form'> | null>;
|
|
81
|
+
let hint: Accessor<TextRange<'hint', 'form'> | null>;
|
|
82
|
+
|
|
83
|
+
switch (noteTextComputation.role) {
|
|
84
|
+
case 'label': {
|
|
85
|
+
noteText = noteTextComputation.label;
|
|
86
|
+
label = noteTextComputation.label;
|
|
87
|
+
hint = createFieldHint(this, definition);
|
|
88
|
+
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
case 'hint': {
|
|
93
|
+
noteText = noteTextComputation.hint;
|
|
94
|
+
label = createNodeLabel(this, definition);
|
|
95
|
+
hint = noteTextComputation.hint;
|
|
96
|
+
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
default:
|
|
101
|
+
throw new UnreachableError(noteTextComputation);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const state = createSharedNodeState(
|
|
105
|
+
this.scope,
|
|
106
|
+
{
|
|
107
|
+
reference: this.contextReference,
|
|
108
|
+
readonly: isReadonly,
|
|
109
|
+
relevant: this.isRelevant,
|
|
110
|
+
required: this.isRequired,
|
|
111
|
+
|
|
112
|
+
label,
|
|
113
|
+
hint,
|
|
114
|
+
noteText,
|
|
115
|
+
|
|
116
|
+
children: null,
|
|
117
|
+
valueOptions: null,
|
|
118
|
+
value: createValueState(this),
|
|
119
|
+
},
|
|
120
|
+
sharedStateOptions
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
this.state = state;
|
|
124
|
+
this.engineState = state.engineState;
|
|
125
|
+
this.currentState = state.currentState;
|
|
126
|
+
this.validation = createValidationState(this, sharedStateOptions);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ValidationContext
|
|
130
|
+
getViolation(): AnyViolation | null {
|
|
131
|
+
return this.validation.engineState.violation;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
isBlank(): boolean {
|
|
135
|
+
return this.engineState.value === '';
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// InstanceNode
|
|
139
|
+
getChildren(): readonly [] {
|
|
140
|
+
return [];
|
|
141
|
+
}
|
|
142
|
+
}
|
package/src/instance/Root.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { XFormsXPathEvaluator } from '@getodk/xpath';
|
|
2
2
|
import type { Accessor, Signal } from 'solid-js';
|
|
3
3
|
import { createSignal } from 'solid-js';
|
|
4
|
-
import type { XFormDOM } from '../XFormDOM.ts';
|
|
5
|
-
import type { BodyClassList } from '../body/BodyDefinition.ts';
|
|
6
4
|
import type { ActiveLanguage, FormLanguage, FormLanguages } from '../client/FormLanguage.ts';
|
|
7
5
|
import type { RootNode } from '../client/RootNode.ts';
|
|
6
|
+
import type { AncestorNodeValidationState } from '../client/validation.ts';
|
|
8
7
|
import type { ChildrenState } from '../lib/reactivity/createChildrenState.ts';
|
|
9
8
|
import { createChildrenState } from '../lib/reactivity/createChildrenState.ts';
|
|
10
9
|
import type { MaterializedChildren } from '../lib/reactivity/materializeCurrentStateChildren.ts';
|
|
@@ -13,7 +12,10 @@ import type { CurrentState } from '../lib/reactivity/node-state/createCurrentSta
|
|
|
13
12
|
import type { EngineState } from '../lib/reactivity/node-state/createEngineState.ts';
|
|
14
13
|
import type { SharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
|
|
15
14
|
import { createSharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
|
|
16
|
-
import
|
|
15
|
+
import { createAggregatedViolations } from '../lib/reactivity/validation/createAggregatedViolations.ts';
|
|
16
|
+
import type { BodyClassList } from '../parse/body/BodyDefinition.ts';
|
|
17
|
+
import type { RootDefinition } from '../parse/model/RootDefinition.ts';
|
|
18
|
+
import type { XFormDOM } from '../parse/XFormDOM.ts';
|
|
17
19
|
import { InstanceNode } from './abstract/InstanceNode.ts';
|
|
18
20
|
import { buildChildren } from './children.ts';
|
|
19
21
|
import type { GeneralChildNode } from './hierarchy.ts';
|
|
@@ -114,6 +116,7 @@ export class Root
|
|
|
114
116
|
readonly appearances = null;
|
|
115
117
|
readonly classes: BodyClassList;
|
|
116
118
|
readonly currentState: MaterializedChildren<CurrentState<RootStateSpec>, GeneralChildNode>;
|
|
119
|
+
readonly validationState: AncestorNodeValidationState;
|
|
117
120
|
|
|
118
121
|
protected readonly instanceDOM: XFormDOM;
|
|
119
122
|
|
|
@@ -152,6 +155,10 @@ export class Root
|
|
|
152
155
|
const evaluator = instanceDOM.primaryInstanceEvaluator;
|
|
153
156
|
const { translations } = evaluator;
|
|
154
157
|
const { defaultLanguage, languages } = getInitialLanguageState(translations);
|
|
158
|
+
const sharedStateOptions = {
|
|
159
|
+
clientStateFactory: this.engineConfig.stateFactory,
|
|
160
|
+
};
|
|
161
|
+
|
|
155
162
|
const state = createSharedNodeState(
|
|
156
163
|
this.scope,
|
|
157
164
|
{
|
|
@@ -166,9 +173,7 @@ export class Root
|
|
|
166
173
|
value: null,
|
|
167
174
|
children: childrenState.childIds,
|
|
168
175
|
},
|
|
169
|
-
|
|
170
|
-
clientStateFactory: engineConfig.stateFactory,
|
|
171
|
-
}
|
|
176
|
+
sharedStateOptions
|
|
172
177
|
);
|
|
173
178
|
|
|
174
179
|
this.state = state;
|
|
@@ -189,6 +194,7 @@ export class Root
|
|
|
189
194
|
this.languages = languages;
|
|
190
195
|
|
|
191
196
|
childrenState.setChildren(buildChildren(this));
|
|
197
|
+
this.validationState = createAggregatedViolations(this, sharedStateOptions);
|
|
192
198
|
}
|
|
193
199
|
|
|
194
200
|
getChildren(): readonly GeneralChildNode[] {
|
|
@@ -215,6 +221,10 @@ export class Root
|
|
|
215
221
|
override subscribe(): void {
|
|
216
222
|
super.subscribe();
|
|
217
223
|
|
|
224
|
+
// TODO: typescript-eslint is right to object to this! We should _at least_
|
|
225
|
+
// make internal reactive reads obvious, i.e. function calls.
|
|
226
|
+
//
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- read == subscribe
|
|
218
228
|
this.engineState.activeLanguage;
|
|
219
229
|
}
|
|
220
230
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { xmlXPathWhitespaceSeparatedList } from '@getodk/common/lib/string/whitespace.ts';
|
|
2
2
|
import type { Accessor } from 'solid-js';
|
|
3
3
|
import { untrack } from 'solid-js';
|
|
4
|
-
import type { AnySelectDefinition } from '../body/control/select/SelectDefinition.ts';
|
|
5
4
|
import type { SelectItem, SelectNode, SelectNodeAppearances } from '../client/SelectNode.ts';
|
|
6
|
-
import type { TextRange } from '../
|
|
5
|
+
import type { TextRange } from '../client/TextRange.ts';
|
|
6
|
+
import type { AnyViolation, LeafNodeValidationState } from '../client/validation.ts';
|
|
7
7
|
import { createSelectItems } from '../lib/reactivity/createSelectItems.ts';
|
|
8
8
|
import { createValueState } from '../lib/reactivity/createValueState.ts';
|
|
9
9
|
import type { CurrentState } from '../lib/reactivity/node-state/createCurrentState.ts';
|
|
@@ -13,16 +13,20 @@ import { createSharedNodeState } from '../lib/reactivity/node-state/createShared
|
|
|
13
13
|
import { createFieldHint } from '../lib/reactivity/text/createFieldHint.ts';
|
|
14
14
|
import { createNodeLabel } from '../lib/reactivity/text/createNodeLabel.ts';
|
|
15
15
|
import type { SimpleAtomicState } from '../lib/reactivity/types.ts';
|
|
16
|
-
import type {
|
|
16
|
+
import type { SharedValidationState } from '../lib/reactivity/validation/createValidation.ts';
|
|
17
|
+
import { createValidationState } from '../lib/reactivity/validation/createValidation.ts';
|
|
18
|
+
import type { AnySelectDefinition } from '../parse/body/control/select/SelectDefinition.ts';
|
|
19
|
+
import type { LeafNodeDefinition } from '../parse/model/LeafNodeDefinition.ts';
|
|
17
20
|
import type { Root } from './Root.ts';
|
|
18
21
|
import type { DescendantNodeStateSpec } from './abstract/DescendantNode.ts';
|
|
19
22
|
import { DescendantNode } from './abstract/DescendantNode.ts';
|
|
20
23
|
import type { GeneralParentNode } from './hierarchy.ts';
|
|
21
24
|
import type { EvaluationContext } from './internal-api/EvaluationContext.ts';
|
|
22
25
|
import type { SubscribableDependency } from './internal-api/SubscribableDependency.ts';
|
|
26
|
+
import type { ValidationContext } from './internal-api/ValidationContext.ts';
|
|
23
27
|
import type { ValueContext } from './internal-api/ValueContext.ts';
|
|
24
28
|
|
|
25
|
-
export interface SelectFieldDefinition extends
|
|
29
|
+
export interface SelectFieldDefinition extends LeafNodeDefinition {
|
|
26
30
|
readonly bodyElement: AnySelectDefinition;
|
|
27
31
|
}
|
|
28
32
|
|
|
@@ -40,9 +44,11 @@ export class SelectField
|
|
|
40
44
|
SelectNode,
|
|
41
45
|
EvaluationContext,
|
|
42
46
|
SubscribableDependency,
|
|
47
|
+
ValidationContext,
|
|
43
48
|
ValueContext<readonly SelectItem[]>
|
|
44
49
|
{
|
|
45
50
|
private readonly selectExclusive: boolean;
|
|
51
|
+
private readonly validation: SharedValidationState;
|
|
46
52
|
|
|
47
53
|
// InstanceNode
|
|
48
54
|
protected readonly state: SharedNodeState<SelectFieldStateSpec>;
|
|
@@ -53,6 +59,10 @@ export class SelectField
|
|
|
53
59
|
readonly appearances: SelectNodeAppearances;
|
|
54
60
|
readonly currentState: CurrentState<SelectFieldStateSpec>;
|
|
55
61
|
|
|
62
|
+
get validationState(): LeafNodeValidationState {
|
|
63
|
+
return this.validation.currentState;
|
|
64
|
+
}
|
|
65
|
+
|
|
56
66
|
// ValueContext
|
|
57
67
|
readonly encodeValue = (runtimeValue: readonly SelectItem[]): string => {
|
|
58
68
|
const itemValues = new Set(runtimeValue.map(({ value }) => value));
|
|
@@ -90,6 +100,10 @@ export class SelectField
|
|
|
90
100
|
|
|
91
101
|
this.getValueOptions = valueOptions;
|
|
92
102
|
|
|
103
|
+
const sharedStateOptions = {
|
|
104
|
+
clientStateFactory: this.engineConfig.stateFactory,
|
|
105
|
+
};
|
|
106
|
+
|
|
93
107
|
const state = createSharedNodeState(
|
|
94
108
|
this.scope,
|
|
95
109
|
{
|
|
@@ -104,14 +118,13 @@ export class SelectField
|
|
|
104
118
|
value: createValueState(this),
|
|
105
119
|
valueOptions,
|
|
106
120
|
},
|
|
107
|
-
|
|
108
|
-
clientStateFactory: this.engineConfig.stateFactory,
|
|
109
|
-
}
|
|
121
|
+
sharedStateOptions
|
|
110
122
|
);
|
|
111
123
|
|
|
112
124
|
this.state = state;
|
|
113
125
|
this.engineState = state.engineState;
|
|
114
126
|
this.currentState = state.currentState;
|
|
127
|
+
this.validation = createValidationState(this, sharedStateOptions);
|
|
115
128
|
}
|
|
116
129
|
|
|
117
130
|
protected getSelectItemsByValue(
|
|
@@ -201,4 +214,13 @@ export class SelectField
|
|
|
201
214
|
getChildren(): readonly [] {
|
|
202
215
|
return [];
|
|
203
216
|
}
|
|
217
|
+
|
|
218
|
+
// ValidationContext
|
|
219
|
+
getViolation(): AnyViolation | null {
|
|
220
|
+
return this.validation.engineState.violation;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
isBlank(): boolean {
|
|
224
|
+
return this.engineState.value.length === 0;
|
|
225
|
+
}
|
|
204
226
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { identity } from '@getodk/common/lib/identity.ts';
|
|
2
2
|
import type { Accessor } from 'solid-js';
|
|
3
|
-
import type { InputDefinition } from '../body/control/InputDefinition.ts';
|
|
4
3
|
import type { StringNode, StringNodeAppearances } from '../client/StringNode.ts';
|
|
5
|
-
import type { TextRange } from '../
|
|
4
|
+
import type { TextRange } from '../client/TextRange.ts';
|
|
5
|
+
import type { AnyViolation, LeafNodeValidationState } from '../client/validation.ts';
|
|
6
6
|
import { createValueState } from '../lib/reactivity/createValueState.ts';
|
|
7
7
|
import type { CurrentState } from '../lib/reactivity/node-state/createCurrentState.ts';
|
|
8
8
|
import type { EngineState } from '../lib/reactivity/node-state/createEngineState.ts';
|
|
@@ -11,17 +11,21 @@ import { createSharedNodeState } from '../lib/reactivity/node-state/createShared
|
|
|
11
11
|
import { createFieldHint } from '../lib/reactivity/text/createFieldHint.ts';
|
|
12
12
|
import { createNodeLabel } from '../lib/reactivity/text/createNodeLabel.ts';
|
|
13
13
|
import type { SimpleAtomicState } from '../lib/reactivity/types.ts';
|
|
14
|
-
import type {
|
|
14
|
+
import type { SharedValidationState } from '../lib/reactivity/validation/createValidation.ts';
|
|
15
|
+
import { createValidationState } from '../lib/reactivity/validation/createValidation.ts';
|
|
16
|
+
import type { InputDefinition } from '../parse/body/control/InputDefinition.ts';
|
|
17
|
+
import type { LeafNodeDefinition } from '../parse/model/LeafNodeDefinition.ts';
|
|
15
18
|
import type { Root } from './Root.ts';
|
|
16
19
|
import type { DescendantNodeStateSpec } from './abstract/DescendantNode.ts';
|
|
17
20
|
import { DescendantNode } from './abstract/DescendantNode.ts';
|
|
18
21
|
import type { GeneralParentNode } from './hierarchy.ts';
|
|
19
22
|
import type { EvaluationContext } from './internal-api/EvaluationContext.ts';
|
|
20
23
|
import type { SubscribableDependency } from './internal-api/SubscribableDependency.ts';
|
|
24
|
+
import type { ValidationContext } from './internal-api/ValidationContext.ts';
|
|
21
25
|
import type { ValueContext } from './internal-api/ValueContext.ts';
|
|
22
26
|
|
|
23
|
-
export interface StringFieldDefinition extends
|
|
24
|
-
readonly bodyElement: InputDefinition
|
|
27
|
+
export interface StringFieldDefinition extends LeafNodeDefinition {
|
|
28
|
+
readonly bodyElement: InputDefinition;
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
interface StringFieldStateSpec extends DescendantNodeStateSpec<string> {
|
|
@@ -34,8 +38,14 @@ interface StringFieldStateSpec extends DescendantNodeStateSpec<string> {
|
|
|
34
38
|
|
|
35
39
|
export class StringField
|
|
36
40
|
extends DescendantNode<StringFieldDefinition, StringFieldStateSpec, null>
|
|
37
|
-
implements
|
|
41
|
+
implements
|
|
42
|
+
StringNode,
|
|
43
|
+
EvaluationContext,
|
|
44
|
+
SubscribableDependency,
|
|
45
|
+
ValidationContext,
|
|
46
|
+
ValueContext<string>
|
|
38
47
|
{
|
|
48
|
+
private readonly validation: SharedValidationState;
|
|
39
49
|
protected readonly state: SharedNodeState<StringFieldStateSpec>;
|
|
40
50
|
|
|
41
51
|
// InstanceNode
|
|
@@ -46,6 +56,10 @@ export class StringField
|
|
|
46
56
|
readonly appearances: StringNodeAppearances;
|
|
47
57
|
readonly currentState: CurrentState<StringFieldStateSpec>;
|
|
48
58
|
|
|
59
|
+
get validationState(): LeafNodeValidationState {
|
|
60
|
+
return this.validation.currentState;
|
|
61
|
+
}
|
|
62
|
+
|
|
49
63
|
// ValueContext
|
|
50
64
|
readonly encodeValue = identity<string>;
|
|
51
65
|
|
|
@@ -54,7 +68,11 @@ export class StringField
|
|
|
54
68
|
constructor(parent: GeneralParentNode, definition: StringFieldDefinition) {
|
|
55
69
|
super(parent, definition);
|
|
56
70
|
|
|
57
|
-
this.appearances =
|
|
71
|
+
this.appearances = definition.bodyElement.appearances;
|
|
72
|
+
|
|
73
|
+
const sharedStateOptions = {
|
|
74
|
+
clientStateFactory: this.engineConfig.stateFactory,
|
|
75
|
+
};
|
|
58
76
|
|
|
59
77
|
const state = createSharedNodeState(
|
|
60
78
|
this.scope,
|
|
@@ -70,14 +88,22 @@ export class StringField
|
|
|
70
88
|
valueOptions: null,
|
|
71
89
|
value: createValueState(this),
|
|
72
90
|
},
|
|
73
|
-
|
|
74
|
-
clientStateFactory: this.engineConfig.stateFactory,
|
|
75
|
-
}
|
|
91
|
+
sharedStateOptions
|
|
76
92
|
);
|
|
77
93
|
|
|
78
94
|
this.state = state;
|
|
79
95
|
this.engineState = state.engineState;
|
|
80
96
|
this.currentState = state.currentState;
|
|
97
|
+
this.validation = createValidationState(this, sharedStateOptions);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ValidationContext
|
|
101
|
+
getViolation(): AnyViolation | null {
|
|
102
|
+
return this.validation.engineState.violation;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
isBlank(): boolean {
|
|
106
|
+
return this.engineState.value === '';
|
|
81
107
|
}
|
|
82
108
|
|
|
83
109
|
// InstanceNode
|
package/src/instance/Subtree.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Accessor } from 'solid-js';
|
|
2
2
|
import type { SubtreeDefinition, SubtreeNode } from '../client/SubtreeNode.ts';
|
|
3
|
+
import type { AncestorNodeValidationState } from '../client/validation.ts';
|
|
3
4
|
import type { ChildrenState } from '../lib/reactivity/createChildrenState.ts';
|
|
4
5
|
import { createChildrenState } from '../lib/reactivity/createChildrenState.ts';
|
|
5
6
|
import type { MaterializedChildren } from '../lib/reactivity/materializeCurrentStateChildren.ts';
|
|
@@ -8,6 +9,7 @@ import type { CurrentState } from '../lib/reactivity/node-state/createCurrentSta
|
|
|
8
9
|
import type { EngineState } from '../lib/reactivity/node-state/createEngineState.ts';
|
|
9
10
|
import type { SharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
|
|
10
11
|
import { createSharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
|
|
12
|
+
import { createAggregatedViolations } from '../lib/reactivity/validation/createAggregatedViolations.ts';
|
|
11
13
|
import type { DescendantNodeSharedStateSpec } from './abstract/DescendantNode.ts';
|
|
12
14
|
import { DescendantNode } from './abstract/DescendantNode.ts';
|
|
13
15
|
import { buildChildren } from './children.ts';
|
|
@@ -38,6 +40,7 @@ export class Subtree
|
|
|
38
40
|
readonly nodeType = 'subtree';
|
|
39
41
|
readonly appearances = null;
|
|
40
42
|
readonly currentState: MaterializedChildren<CurrentState<SubtreeStateSpec>, GeneralChildNode>;
|
|
43
|
+
readonly validationState: AncestorNodeValidationState;
|
|
41
44
|
|
|
42
45
|
constructor(parent: GeneralParentNode, definition: SubtreeDefinition) {
|
|
43
46
|
super(parent, definition);
|
|
@@ -46,6 +49,10 @@ export class Subtree
|
|
|
46
49
|
|
|
47
50
|
this.childrenState = childrenState;
|
|
48
51
|
|
|
52
|
+
const sharedStateOptions = {
|
|
53
|
+
clientStateFactory: this.engineConfig.stateFactory,
|
|
54
|
+
};
|
|
55
|
+
|
|
49
56
|
const state = createSharedNodeState(
|
|
50
57
|
this.scope,
|
|
51
58
|
{
|
|
@@ -60,9 +67,7 @@ export class Subtree
|
|
|
60
67
|
valueOptions: null,
|
|
61
68
|
value: null,
|
|
62
69
|
},
|
|
63
|
-
|
|
64
|
-
clientStateFactory: this.engineConfig.stateFactory,
|
|
65
|
-
}
|
|
70
|
+
sharedStateOptions
|
|
66
71
|
);
|
|
67
72
|
|
|
68
73
|
this.state = state;
|
|
@@ -74,6 +79,7 @@ export class Subtree
|
|
|
74
79
|
);
|
|
75
80
|
|
|
76
81
|
childrenState.setChildren(buildChildren(this));
|
|
82
|
+
this.validationState = createAggregatedViolations(this, sharedStateOptions);
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
getChildren(): readonly GeneralChildNode[] {
|