@getodk/xforms-engine 0.2.0 → 0.3.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/body/BodyElementDefinition.d.ts +4 -3
- package/dist/body/RepeatElementDefinition.d.ts +2 -2
- package/dist/body/control/ControlDefinition.d.ts +2 -2
- package/dist/body/control/select/ItemDefinition.d.ts +2 -2
- package/dist/body/control/select/ItemsetDefinition.d.ts +5 -4
- package/dist/body/group/BaseGroupDefinition.d.ts +1 -1
- package/dist/body/group/PresentationGroupDefinition.d.ts +1 -1
- package/dist/client/BaseNode.d.ts +68 -2
- package/dist/client/GroupNode.d.ts +2 -0
- package/dist/client/ModelValueNode.d.ts +37 -0
- package/dist/client/NoteNode.d.ts +53 -0
- package/dist/client/RootNode.d.ts +2 -0
- package/dist/client/SelectNode.d.ts +5 -3
- package/dist/client/StringNode.d.ts +5 -3
- package/dist/client/SubtreeNode.d.ts +2 -0
- package/dist/client/TextRange.d.ts +85 -2
- package/dist/client/constants.d.ts +9 -0
- package/dist/client/hierarchy.d.ts +14 -9
- package/dist/client/node-types.d.ts +2 -1
- package/dist/client/{RepeatRangeNode.d.ts → repeat/BaseRepeatRangeNode.d.ts} +18 -17
- package/dist/client/{RepeatInstanceNode.d.ts → repeat/RepeatInstanceNode.d.ts} +9 -8
- package/dist/client/repeat/RepeatRangeControlledNode.d.ts +19 -0
- package/dist/client/repeat/RepeatRangeUncontrolledNode.d.ts +20 -0
- package/dist/client/validation.d.ts +163 -0
- package/dist/expression/DependentExpression.d.ts +12 -8
- package/dist/index.d.ts +9 -4
- package/dist/index.js +2635 -678
- package/dist/index.js.map +1 -1
- package/dist/instance/Group.d.ts +3 -1
- package/dist/instance/ModelValue.d.ts +40 -0
- package/dist/instance/Note.d.ts +42 -0
- package/dist/instance/Root.d.ts +2 -0
- package/dist/instance/SelectField.d.ts +10 -4
- package/dist/instance/StringField.d.ts +11 -5
- package/dist/instance/Subtree.d.ts +2 -0
- package/dist/instance/abstract/DescendantNode.d.ts +5 -6
- package/dist/instance/abstract/InstanceNode.d.ts +2 -0
- package/dist/instance/hierarchy.d.ts +10 -5
- package/dist/instance/internal-api/ValidationContext.d.ts +21 -0
- package/dist/instance/{RepeatRange.d.ts → repeat/BaseRepeatRange.d.ts} +46 -45
- package/dist/instance/{RepeatInstance.d.ts → repeat/RepeatInstance.d.ts} +13 -12
- package/dist/instance/repeat/RepeatRangeControlled.d.ts +16 -0
- package/dist/instance/repeat/RepeatRangeUncontrolled.d.ts +35 -0
- package/dist/instance/text/TextRange.d.ts +4 -4
- package/dist/lib/reactivity/createComputedExpression.d.ts +6 -1
- package/dist/lib/reactivity/createNoteReadonlyThunk.d.ts +5 -0
- package/dist/lib/reactivity/node-state/createSharedNodeState.d.ts +1 -1
- package/dist/lib/reactivity/node-state/createSpecifiedState.d.ts +1 -1
- package/dist/lib/reactivity/text/createFieldHint.d.ts +3 -3
- package/dist/lib/reactivity/text/createNodeLabel.d.ts +2 -2
- package/dist/lib/reactivity/text/createNoteText.d.ts +25 -0
- package/dist/lib/reactivity/text/createTextRange.d.ts +5 -7
- package/dist/lib/reactivity/validation/createAggregatedViolations.d.ts +9 -0
- package/dist/lib/reactivity/validation/createValidation.d.ts +18 -0
- package/dist/model/BindDefinition.d.ts +4 -2
- package/dist/model/BindElement.d.ts +1 -0
- package/dist/model/{ValueNodeDefinition.d.ts → LeafNodeDefinition.d.ts} +2 -2
- package/dist/model/NodeDefinition.d.ts +8 -8
- package/dist/model/RepeatInstanceDefinition.d.ts +2 -2
- package/dist/model/RepeatRangeDefinition.d.ts +14 -4
- package/dist/parse/NoteNodeDefinition.d.ts +31 -0
- package/dist/parse/expression/RepeatCountControlExpression.d.ts +19 -0
- package/dist/parse/text/HintDefinition.d.ts +9 -0
- package/dist/parse/text/ItemLabelDefinition.d.ts +9 -0
- package/dist/parse/text/ItemsetLabelDefinition.d.ts +13 -0
- package/dist/parse/text/LabelDefinition.d.ts +15 -0
- package/dist/parse/text/MessageDefinition.d.ts +15 -0
- package/dist/parse/text/OutputChunkDefinition.d.ts +8 -0
- package/dist/parse/text/ReferenceChunkDefinition.d.ts +8 -0
- package/dist/parse/text/StaticTextChunkDefinition.d.ts +10 -0
- package/dist/parse/text/TranslationChunkDefinition.d.ts +9 -0
- package/dist/parse/text/abstract/TextChunkDefinition.d.ts +18 -0
- package/dist/parse/text/abstract/TextElementDefinition.d.ts +23 -0
- package/dist/parse/text/abstract/TextRangeDefinition.d.ts +35 -0
- package/dist/parse/xpath/dependency-analysis.d.ts +40 -0
- package/dist/parse/xpath/path-resolution.d.ts +70 -0
- package/dist/parse/xpath/predicate-analysis.d.ts +30 -0
- package/dist/parse/xpath/reference-parsing.d.ts +18 -0
- package/dist/parse/xpath/semantic-analysis.d.ts +98 -0
- package/dist/parse/xpath/syntax-traversal.d.ts +69 -0
- package/dist/solid.js +2636 -679
- package/dist/solid.js.map +1 -1
- package/package.json +14 -15
- package/src/body/BodyElementDefinition.ts +4 -3
- package/src/body/RepeatElementDefinition.ts +5 -17
- package/src/body/control/ControlDefinition.ts +4 -3
- package/src/body/control/select/ItemDefinition.ts +3 -3
- package/src/body/control/select/ItemsetDefinition.ts +29 -12
- package/src/body/control/select/ItemsetNodesetExpression.ts +1 -1
- package/src/body/group/BaseGroupDefinition.ts +3 -2
- package/src/body/group/PresentationGroupDefinition.ts +1 -1
- package/src/client/BaseNode.ts +73 -7
- package/src/client/GroupNode.ts +2 -0
- package/src/client/ModelValueNode.ts +40 -0
- package/src/client/NoteNode.ts +74 -0
- package/src/client/README.md +1 -0
- package/src/client/RootNode.ts +2 -0
- package/src/client/SelectNode.ts +5 -3
- package/src/client/StringNode.ts +5 -3
- package/src/client/SubtreeNode.ts +2 -0
- package/src/client/TextRange.ts +99 -2
- package/src/client/constants.ts +10 -0
- package/src/client/hierarchy.ts +30 -14
- package/src/client/node-types.ts +8 -1
- 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/validation.ts +199 -0
- package/src/expression/DependentExpression.ts +45 -27
- package/src/index.ts +15 -8
- 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 +9 -3
- package/src/instance/SelectField.ts +28 -6
- package/src/instance/StringField.ts +35 -9
- package/src/instance/Subtree.ts +9 -3
- package/src/instance/abstract/DescendantNode.ts +6 -7
- package/src/instance/abstract/InstanceNode.ts +20 -6
- package/src/instance/children.ts +42 -15
- package/src/instance/hierarchy.ts +21 -2
- package/src/instance/internal-api/ValidationContext.ts +23 -0
- 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/lib/reactivity/createComputedExpression.ts +22 -24
- package/src/lib/reactivity/createNoteReadonlyThunk.ts +33 -0
- package/src/lib/reactivity/createSelectItems.ts +21 -14
- package/src/lib/reactivity/node-state/createSharedNodeState.ts +1 -1
- package/src/lib/reactivity/text/createFieldHint.ts +9 -7
- package/src/lib/reactivity/text/createNodeLabel.ts +7 -5
- 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 +70 -0
- package/src/lib/reactivity/validation/createValidation.ts +196 -0
- package/src/model/BindComputation.ts +0 -4
- package/src/model/BindDefinition.ts +8 -6
- package/src/model/BindElement.ts +1 -0
- package/src/model/{ValueNodeDefinition.ts → LeafNodeDefinition.ts} +4 -4
- package/src/model/ModelBindMap.ts +4 -0
- package/src/model/NodeDefinition.ts +12 -12
- package/src/model/RepeatInstanceDefinition.ts +2 -2
- package/src/model/RepeatRangeDefinition.ts +49 -8
- package/src/model/RootDefinition.ts +7 -3
- package/src/parse/NoteNodeDefinition.ts +70 -0
- package/src/parse/TODO.md +3 -0
- package/src/parse/expression/RepeatCountControlExpression.ts +44 -0
- 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/OutputChunkDefinition.ts +25 -0
- package/src/parse/text/ReferenceChunkDefinition.ts +14 -0
- package/src/parse/text/StaticTextChunkDefinition.ts +19 -0
- package/src/parse/text/TranslationChunkDefinition.ts +38 -0
- package/src/parse/text/abstract/TextChunkDefinition.ts +38 -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/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
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import type { Accessor } from 'solid-js';
|
|
2
|
+
import { createMemo } from 'solid-js';
|
|
3
|
+
import type { OpaqueReactiveObjectFactory } from '../../../client/OpaqueReactiveObjectFactory.ts';
|
|
4
|
+
import type {
|
|
5
|
+
TextRange as ClientTextRange,
|
|
6
|
+
ValidationTextRole,
|
|
7
|
+
} from '../../../client/TextRange.ts';
|
|
8
|
+
import { VALIDATION_TEXT } from '../../../client/constants.ts';
|
|
9
|
+
import type {
|
|
10
|
+
AnyViolation,
|
|
11
|
+
ConditionSatisfied,
|
|
12
|
+
ConditionValidation,
|
|
13
|
+
ConditionViolation,
|
|
14
|
+
ValidationCondition,
|
|
15
|
+
} from '../../../client/validation.ts';
|
|
16
|
+
import type { ValidationContext } from '../../../instance/internal-api/ValidationContext.ts';
|
|
17
|
+
import { TextChunk } from '../../../instance/text/TextChunk.ts';
|
|
18
|
+
import { TextRange } from '../../../instance/text/TextRange.ts';
|
|
19
|
+
import type { MessageDefinition } from '../../../parse/text/MessageDefinition.ts';
|
|
20
|
+
import { createComputedExpression } from '../createComputedExpression.ts';
|
|
21
|
+
import type {
|
|
22
|
+
SharedNodeState,
|
|
23
|
+
SharedNodeStateOptions,
|
|
24
|
+
} from '../node-state/createSharedNodeState.ts';
|
|
25
|
+
import { createSharedNodeState } from '../node-state/createSharedNodeState.ts';
|
|
26
|
+
import type { ReactiveScope } from '../scope.ts';
|
|
27
|
+
import { createTextRange } from '../text/createTextRange.ts';
|
|
28
|
+
|
|
29
|
+
type EngineViolationMessage<Role extends ValidationTextRole> = ClientTextRange<Role, 'engine'>;
|
|
30
|
+
|
|
31
|
+
const engineViolationMessage = <Role extends ValidationTextRole>(
|
|
32
|
+
context: ValidationContext,
|
|
33
|
+
role: Role
|
|
34
|
+
): Accessor<EngineViolationMessage<Role>> => {
|
|
35
|
+
const messageText = VALIDATION_TEXT[role];
|
|
36
|
+
const chunk = new TextChunk(context.root, 'static', messageText);
|
|
37
|
+
const message = new TextRange('engine', role, [chunk]);
|
|
38
|
+
|
|
39
|
+
return () => message;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const createViolationMessage = <Role extends ValidationTextRole>(
|
|
43
|
+
context: ValidationContext,
|
|
44
|
+
role: Role,
|
|
45
|
+
definition: MessageDefinition<Role> | null
|
|
46
|
+
) => {
|
|
47
|
+
if (definition == null) {
|
|
48
|
+
return engineViolationMessage(context, role);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return createTextRange(context, role, definition);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// prettier-ignore
|
|
55
|
+
type ComputedConditionValidation<
|
|
56
|
+
Condition extends ValidationCondition
|
|
57
|
+
> = Accessor<ConditionValidation<Condition>>;
|
|
58
|
+
|
|
59
|
+
const constraintValid = (): ConditionSatisfied<'constraint'> => {
|
|
60
|
+
return {
|
|
61
|
+
condition: 'constraint',
|
|
62
|
+
valid: true,
|
|
63
|
+
message: null,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const createConstraintValidation = (
|
|
68
|
+
context: ValidationContext
|
|
69
|
+
): ComputedConditionValidation<'constraint'> => {
|
|
70
|
+
return context.scope.runTask(() => {
|
|
71
|
+
const { constraint, constraintMsg } = context.definition.bind;
|
|
72
|
+
|
|
73
|
+
if (constraint == null) {
|
|
74
|
+
return constraintValid;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const isValid = createComputedExpression(context, constraint, {
|
|
78
|
+
arbitraryDependencies: [context],
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const message = createViolationMessage(context, 'constraintMsg', constraintMsg);
|
|
82
|
+
|
|
83
|
+
return createMemo(() => {
|
|
84
|
+
if (!context.isRelevant() || context.isBlank() || isValid()) {
|
|
85
|
+
return constraintValid();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
condition: 'constraint',
|
|
90
|
+
valid: false,
|
|
91
|
+
message: message(),
|
|
92
|
+
} as const;
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const requiredValid = (): ConditionSatisfied<'required'> => {
|
|
98
|
+
return {
|
|
99
|
+
condition: 'required',
|
|
100
|
+
valid: true,
|
|
101
|
+
message: null,
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const createRequiredValidation = (
|
|
106
|
+
context: ValidationContext
|
|
107
|
+
): ComputedConditionValidation<'required'> => {
|
|
108
|
+
return context.scope.runTask(() => {
|
|
109
|
+
const { required, requiredMsg } = context.definition.bind;
|
|
110
|
+
|
|
111
|
+
if (required.isDefaultExpression) {
|
|
112
|
+
return requiredValid;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const isValid = () => {
|
|
116
|
+
if (context.isRequired()) {
|
|
117
|
+
return !context.isBlank();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return true;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const message = createViolationMessage(context, 'requiredMsg', requiredMsg);
|
|
124
|
+
|
|
125
|
+
return createMemo(() => {
|
|
126
|
+
if (!context.isRelevant() || isValid()) {
|
|
127
|
+
return requiredValid();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
condition: 'required',
|
|
132
|
+
valid: false,
|
|
133
|
+
message: message(),
|
|
134
|
+
} as const;
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
type OptionalViolation<Condition extends ValidationCondition> =
|
|
140
|
+
Accessor<ConditionViolation<Condition> | null>;
|
|
141
|
+
|
|
142
|
+
const createComputedViolation = <Condition extends ValidationCondition>(
|
|
143
|
+
scope: ReactiveScope,
|
|
144
|
+
validateCondition: ComputedConditionValidation<Condition>
|
|
145
|
+
): OptionalViolation<Condition> => {
|
|
146
|
+
return scope.runTask(() => {
|
|
147
|
+
return createMemo(() => {
|
|
148
|
+
const validation = validateCondition();
|
|
149
|
+
|
|
150
|
+
if (validation.valid) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return validation;
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
type ComputedViolation = Accessor<AnyViolation | null>;
|
|
160
|
+
|
|
161
|
+
interface ValidationStateSpec {
|
|
162
|
+
readonly constraint: ComputedConditionValidation<'constraint'>;
|
|
163
|
+
readonly required: ComputedConditionValidation<'required'>;
|
|
164
|
+
readonly violation: ComputedViolation;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export type SharedValidationState = SharedNodeState<ValidationStateSpec>;
|
|
168
|
+
|
|
169
|
+
interface ValidationStateOptions<Factory extends OpaqueReactiveObjectFactory>
|
|
170
|
+
extends SharedNodeStateOptions<Factory, ValidationStateSpec> {}
|
|
171
|
+
|
|
172
|
+
export const createValidationState = <Factory extends OpaqueReactiveObjectFactory>(
|
|
173
|
+
context: ValidationContext,
|
|
174
|
+
options: ValidationStateOptions<Factory>
|
|
175
|
+
): SharedValidationState => {
|
|
176
|
+
const { scope } = context;
|
|
177
|
+
|
|
178
|
+
return scope.runTask(() => {
|
|
179
|
+
const constraint = createConstraintValidation(context);
|
|
180
|
+
const constraintViolation = createComputedViolation(scope, constraint);
|
|
181
|
+
const required = createRequiredValidation(context);
|
|
182
|
+
const requiredViolation = createComputedViolation(scope, required);
|
|
183
|
+
|
|
184
|
+
const violation = createMemo(() => {
|
|
185
|
+
return constraintViolation() ?? requiredViolation();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
const spec: ValidationStateSpec = {
|
|
189
|
+
constraint,
|
|
190
|
+
required,
|
|
191
|
+
violation,
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
return createSharedNodeState(scope, spec, options);
|
|
195
|
+
});
|
|
196
|
+
};
|
|
@@ -57,7 +57,6 @@ export class BindComputation<Computation extends BindComputationType> extends De
|
|
|
57
57
|
readonly computation: Computation,
|
|
58
58
|
expression: string | null
|
|
59
59
|
) {
|
|
60
|
-
const isInherited = computation === 'readonly' || computation === 'relevant';
|
|
61
60
|
const ignoreContextReference = computation === 'constraint';
|
|
62
61
|
|
|
63
62
|
let isDefaultExpression: boolean;
|
|
@@ -78,9 +77,6 @@ export class BindComputation<Computation extends BindComputationType> extends De
|
|
|
78
77
|
|
|
79
78
|
super(bind, bindComputationResultTypes[computation], resolvedExpression, {
|
|
80
79
|
ignoreContextReference,
|
|
81
|
-
semanticDependencies: {
|
|
82
|
-
parentContext: isInherited,
|
|
83
|
-
},
|
|
84
80
|
});
|
|
85
81
|
|
|
86
82
|
this.isDefaultExpression = isDefaultExpression;
|
|
@@ -3,6 +3,7 @@ import { bindDataType } from '../XFormDataType.ts';
|
|
|
3
3
|
import type { XFormDefinition } from '../XFormDefinition.ts';
|
|
4
4
|
import { DependencyContext } from '../expression/DependencyContext.ts';
|
|
5
5
|
import type { DependentExpression } from '../expression/DependentExpression.ts';
|
|
6
|
+
import { MessageDefinition } from '../parse/text/MessageDefinition.ts';
|
|
6
7
|
import { BindComputation } from './BindComputation.ts';
|
|
7
8
|
import type { BindElement } from './BindElement.ts';
|
|
8
9
|
import type { ModelDefinition } from './ModelDefinition.ts';
|
|
@@ -25,15 +26,16 @@ export class BindDefinition extends DependencyContext {
|
|
|
25
26
|
/**
|
|
26
27
|
* Diverges from {@link https://github.com/getodk/javarosa/blob/059321160e6f8dbb3e81d9add61d68dd35b13cc8/dag.md | JavaRosa's}, which excludes `constraint` expressions. We compute `constraint` dependencies like the other <bind> computation expressions, but explicitly ignore self-references (this is currently handled by {@link BindComputation}, via its {@link DependentExpression} parent class).
|
|
27
28
|
*/
|
|
28
|
-
readonly constraint: BindComputation<'constraint'
|
|
29
|
+
readonly constraint: BindComputation<'constraint'>;
|
|
30
|
+
|
|
31
|
+
readonly constraintMsg: MessageDefinition<'constraintMsg'> | null;
|
|
32
|
+
readonly requiredMsg: MessageDefinition<'requiredMsg'> | null;
|
|
29
33
|
|
|
30
34
|
// TODO: it is unclear whether this will need to be supported.
|
|
31
35
|
// https://github.com/getodk/collect/issues/3758 mentions deprecation.
|
|
32
36
|
readonly saveIncomplete: BindComputation<'saveIncomplete'>;
|
|
33
37
|
|
|
34
|
-
// TODO: these are deferred
|
|
35
|
-
// readonly requiredMsg: string | null;
|
|
36
|
-
// readonly constraintMsg: string | null;
|
|
38
|
+
// TODO: these are deferred until prioritized
|
|
37
39
|
// readonly preload: string | null;
|
|
38
40
|
// readonly preloadParams: string | null;
|
|
39
41
|
// readonly 'max-pixels': string | null;
|
|
@@ -88,9 +90,9 @@ export class BindDefinition extends DependencyContext {
|
|
|
88
90
|
this.required = BindComputation.forExpression(this, 'required');
|
|
89
91
|
this.constraint = BindComputation.forExpression(this, 'constraint');
|
|
90
92
|
this.saveIncomplete = BindComputation.forExpression(this, 'saveIncomplete');
|
|
93
|
+
this.constraintMsg = MessageDefinition.from(this, 'constraintMsg');
|
|
94
|
+
this.requiredMsg = MessageDefinition.from(this, 'requiredMsg');
|
|
91
95
|
|
|
92
|
-
// this.requiredMsg = BindComputation.forExpression(this, 'requiredMsg');
|
|
93
|
-
// this.constraintMsg = BindComputation.forExpression(this, 'constraintMsg');
|
|
94
96
|
// this.preload = BindComputation.forExpression(this, 'preload');
|
|
95
97
|
// this.preloadParams = BindComputation.forExpression(this, 'preloadParams');
|
|
96
98
|
// this['max-pixels'] = BindComputation.forExpression(this, 'max-pixels');
|
package/src/model/BindElement.ts
CHANGED
|
@@ -3,11 +3,11 @@ import type { BindDefinition } from './BindDefinition.ts';
|
|
|
3
3
|
import { DescendentNodeDefinition } from './DescendentNodeDefinition.ts';
|
|
4
4
|
import type { NodeDefinition, ParentNodeDefinition } from './NodeDefinition.ts';
|
|
5
5
|
|
|
6
|
-
export class
|
|
7
|
-
extends DescendentNodeDefinition<'
|
|
8
|
-
implements NodeDefinition<'
|
|
6
|
+
export class LeafNodeDefinition
|
|
7
|
+
extends DescendentNodeDefinition<'leaf-node', ControlElementDefinition | null>
|
|
8
|
+
implements NodeDefinition<'leaf-node'>
|
|
9
9
|
{
|
|
10
|
-
readonly type = '
|
|
10
|
+
readonly type = 'leaf-node';
|
|
11
11
|
|
|
12
12
|
readonly nodeName: string;
|
|
13
13
|
readonly children = null;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { AnyBodyElementDefinition } from '../body/BodyDefinition.ts';
|
|
2
2
|
import type { RepeatElementDefinition } from '../body/RepeatElementDefinition.ts';
|
|
3
3
|
import type { BindDefinition } from './BindDefinition.ts';
|
|
4
|
+
import type { LeafNodeDefinition } from './LeafNodeDefinition.ts';
|
|
4
5
|
import type { RepeatInstanceDefinition } from './RepeatInstanceDefinition.ts';
|
|
5
|
-
import type {
|
|
6
|
+
import type { AnyRepeatRangeDefinition } from './RepeatRangeDefinition.ts';
|
|
6
7
|
import type { RepeatTemplateDefinition } from './RepeatTemplateDefinition.ts';
|
|
7
8
|
import type { RootDefinition } from './RootDefinition.ts';
|
|
8
9
|
import type { SubtreeDefinition } from './SubtreeDefinition.ts';
|
|
9
|
-
import type { ValueNodeDefinition } from './ValueNodeDefinition.ts';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Corresponds to the model/entry DOM root node, i.e.:
|
|
@@ -49,7 +49,7 @@ export type SubtreeNodeType = 'subtree';
|
|
|
49
49
|
* - An element with no child elements
|
|
50
50
|
* - Any attribute corresponding to a bind's `nodeset` expression
|
|
51
51
|
*/
|
|
52
|
-
export type
|
|
52
|
+
export type LeafNodeType = 'leaf-node';
|
|
53
53
|
|
|
54
54
|
// prettier-ignore
|
|
55
55
|
export type NodeDefinitionType =
|
|
@@ -59,7 +59,7 @@ export type NodeDefinitionType =
|
|
|
59
59
|
| RepeatTemplateType
|
|
60
60
|
| RepeatInstanceType
|
|
61
61
|
| SubtreeNodeType
|
|
62
|
-
|
|
|
62
|
+
| LeafNodeType;
|
|
63
63
|
|
|
64
64
|
// prettier-ignore
|
|
65
65
|
export type ParentNodeDefinition =
|
|
@@ -71,9 +71,9 @@ export type ParentNodeDefinition =
|
|
|
71
71
|
|
|
72
72
|
// prettier-ignore
|
|
73
73
|
export type ChildNodeDefinition =
|
|
74
|
-
|
|
|
75
|
-
|
|
|
76
|
-
|
|
|
74
|
+
| AnyRepeatRangeDefinition
|
|
75
|
+
| LeafNodeDefinition
|
|
76
|
+
| SubtreeDefinition;
|
|
77
77
|
|
|
78
78
|
// prettier-ignore
|
|
79
79
|
export type ChildNodeInstanceDefinition =
|
|
@@ -81,7 +81,7 @@ export type ChildNodeInstanceDefinition =
|
|
|
81
81
|
| RepeatTemplateDefinition
|
|
82
82
|
| RepeatInstanceDefinition
|
|
83
83
|
| SubtreeDefinition
|
|
84
|
-
|
|
|
84
|
+
| LeafNodeDefinition;
|
|
85
85
|
|
|
86
86
|
// prettier-ignore
|
|
87
87
|
export type NodeChildren<Type extends NodeDefinitionType> =
|
|
@@ -101,7 +101,7 @@ export type NodeParent<Type extends NodeDefinitionType> =
|
|
|
101
101
|
? ParentNodeDefinition
|
|
102
102
|
: null;
|
|
103
103
|
|
|
104
|
-
// TODO:
|
|
104
|
+
// TODO: leaf-node may be Attr
|
|
105
105
|
// prettier-ignore
|
|
106
106
|
export type ModelNode<Type extends NodeDefinitionType> =
|
|
107
107
|
Type extends 'repeat-range'
|
|
@@ -110,7 +110,7 @@ export type ModelNode<Type extends NodeDefinitionType> =
|
|
|
110
110
|
|
|
111
111
|
// prettier-ignore
|
|
112
112
|
export type NodeDefaultValue<Type extends NodeDefinitionType> =
|
|
113
|
-
Type extends '
|
|
113
|
+
Type extends 'leaf-node'
|
|
114
114
|
? string
|
|
115
115
|
: null;
|
|
116
116
|
|
|
@@ -137,10 +137,10 @@ export interface NodeDefinition<Type extends NodeDefinitionType> {
|
|
|
137
137
|
export type AnyNodeDefinition =
|
|
138
138
|
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
139
139
|
| RootDefinition
|
|
140
|
-
|
|
|
140
|
+
| AnyRepeatRangeDefinition
|
|
141
141
|
| RepeatTemplateDefinition
|
|
142
142
|
| RepeatInstanceDefinition
|
|
143
143
|
| SubtreeDefinition
|
|
144
|
-
|
|
|
144
|
+
| LeafNodeDefinition;
|
|
145
145
|
|
|
146
146
|
export type TypedNodeDefinition<Type> = Extract<AnyNodeDefinition, { readonly type: Type }>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RepeatElementDefinition } from '../body/RepeatElementDefinition.ts';
|
|
2
2
|
import { DescendentNodeDefinition } from './DescendentNodeDefinition.ts';
|
|
3
3
|
import type { ChildNodeDefinition, NodeDefinition } from './NodeDefinition.ts';
|
|
4
|
-
import type {
|
|
4
|
+
import type { AnyRepeatRangeDefinition } from './RepeatRangeDefinition.ts';
|
|
5
5
|
|
|
6
6
|
export class RepeatInstanceDefinition
|
|
7
7
|
extends DescendentNodeDefinition<'repeat-instance', RepeatElementDefinition>
|
|
@@ -15,7 +15,7 @@ export class RepeatInstanceDefinition
|
|
|
15
15
|
readonly defaultValue = null;
|
|
16
16
|
|
|
17
17
|
constructor(
|
|
18
|
-
range:
|
|
18
|
+
range: AnyRepeatRangeDefinition,
|
|
19
19
|
readonly node: Element
|
|
20
20
|
) {
|
|
21
21
|
const { bind, bodyElement, parent, root } = range;
|
|
@@ -1,22 +1,49 @@
|
|
|
1
1
|
import type { RepeatElementDefinition } from '../body/RepeatElementDefinition.ts';
|
|
2
|
+
import { RepeatCountControlExpression } from '../parse/expression/RepeatCountControlExpression.ts';
|
|
2
3
|
import type { BindDefinition } from './BindDefinition.ts';
|
|
3
4
|
import { DescendentNodeDefinition } from './DescendentNodeDefinition.ts';
|
|
4
5
|
import type { NodeDefinition, ParentNodeDefinition } from './NodeDefinition.ts';
|
|
5
6
|
import { RepeatInstanceDefinition } from './RepeatInstanceDefinition.ts';
|
|
6
7
|
import { RepeatTemplateDefinition } from './RepeatTemplateDefinition.ts';
|
|
7
8
|
|
|
9
|
+
export interface ControlledRepeatRangeDefinition extends RepeatRangeDefinition {
|
|
10
|
+
readonly count: RepeatCountControlExpression;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface UncontrolledRepeatRangeDefinition extends RepeatRangeDefinition {
|
|
14
|
+
readonly count: null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// prettier-ignore
|
|
18
|
+
export type AnyRepeatRangeDefinition =
|
|
19
|
+
| ControlledRepeatRangeDefinition
|
|
20
|
+
| UncontrolledRepeatRangeDefinition;
|
|
21
|
+
|
|
22
|
+
type AssertRepeatRangeDefinitionUnion = (
|
|
23
|
+
definition: RepeatRangeDefinition
|
|
24
|
+
) => asserts definition is AnyRepeatRangeDefinition;
|
|
25
|
+
|
|
26
|
+
const assertRepeatRangeDefinitionUnion: AssertRepeatRangeDefinitionUnion = (_definition) => {
|
|
27
|
+
// Intentional no-op, used to guide the type checker. Implementation would
|
|
28
|
+
// check _definition.count == null || _definition.count != null, which is
|
|
29
|
+
// tautologically true!
|
|
30
|
+
};
|
|
31
|
+
|
|
8
32
|
export class RepeatRangeDefinition
|
|
9
33
|
extends DescendentNodeDefinition<'repeat-range', RepeatElementDefinition>
|
|
10
34
|
implements NodeDefinition<'repeat-range'>
|
|
11
35
|
{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
36
|
+
static from(
|
|
37
|
+
parent: ParentNodeDefinition,
|
|
38
|
+
bind: BindDefinition,
|
|
39
|
+
bodyElement: RepeatElementDefinition,
|
|
40
|
+
modelNodes: readonly [Element, ...Element[]]
|
|
41
|
+
): AnyRepeatRangeDefinition {
|
|
42
|
+
const definition = new this(parent, bind, bodyElement, modelNodes);
|
|
43
|
+
|
|
44
|
+
assertRepeatRangeDefinitionUnion(definition);
|
|
17
45
|
|
|
18
|
-
|
|
19
|
-
return templateElement.cloneNode(true) as Element;
|
|
46
|
+
return definition;
|
|
20
47
|
}
|
|
21
48
|
|
|
22
49
|
readonly type = 'repeat-range';
|
|
@@ -24,27 +51,41 @@ export class RepeatRangeDefinition
|
|
|
24
51
|
readonly template: RepeatTemplateDefinition;
|
|
25
52
|
readonly children = null;
|
|
26
53
|
readonly instances: RepeatInstanceDefinition[];
|
|
54
|
+
readonly count: RepeatCountControlExpression | null;
|
|
27
55
|
|
|
28
56
|
readonly node = null;
|
|
29
57
|
readonly nodeName: string;
|
|
30
58
|
readonly defaultValue = null;
|
|
31
59
|
|
|
32
|
-
constructor(
|
|
60
|
+
private constructor(
|
|
33
61
|
parent: ParentNodeDefinition,
|
|
34
62
|
bind: BindDefinition,
|
|
35
63
|
bodyElement: RepeatElementDefinition,
|
|
36
64
|
modelNodes: readonly [Element, ...Element[]]
|
|
37
65
|
) {
|
|
38
66
|
super(parent, bind, bodyElement);
|
|
67
|
+
|
|
39
68
|
const { template, instanceNodes } = RepeatTemplateDefinition.parseModelNodes(this, modelNodes);
|
|
40
69
|
|
|
41
70
|
this.template = template;
|
|
42
71
|
this.nodeName = template.nodeName;
|
|
72
|
+
this.count = RepeatCountControlExpression.from(bodyElement, instanceNodes.length);
|
|
73
|
+
|
|
74
|
+
assertRepeatRangeDefinitionUnion(this);
|
|
75
|
+
|
|
43
76
|
this.instances = instanceNodes.map((element) => {
|
|
44
77
|
return new RepeatInstanceDefinition(this, element);
|
|
45
78
|
});
|
|
46
79
|
}
|
|
47
80
|
|
|
81
|
+
isControlled(): this is ControlledRepeatRangeDefinition {
|
|
82
|
+
return this.count != null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
isUncontrolled(): this is UncontrolledRepeatRangeDefinition {
|
|
86
|
+
return this.count == null;
|
|
87
|
+
}
|
|
88
|
+
|
|
48
89
|
toJSON() {
|
|
49
90
|
const { bind, bodyElement: groupDefinition, parent, root, ...rest } = this;
|
|
50
91
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { XFormDefinition } from '../XFormDefinition.ts';
|
|
2
2
|
import type { BodyClassList } from '../body/BodyDefinition.ts';
|
|
3
|
+
import { NoteNodeDefinition } from '../parse/NoteNodeDefinition.ts';
|
|
3
4
|
import type { BindDefinition } from './BindDefinition.ts';
|
|
5
|
+
import { LeafNodeDefinition } from './LeafNodeDefinition.ts';
|
|
4
6
|
import type { ModelDefinition } from './ModelDefinition.ts';
|
|
5
7
|
import type {
|
|
6
8
|
ChildNodeDefinition,
|
|
@@ -9,7 +11,6 @@ import type {
|
|
|
9
11
|
} from './NodeDefinition.ts';
|
|
10
12
|
import { RepeatRangeDefinition } from './RepeatRangeDefinition.ts';
|
|
11
13
|
import { SubtreeDefinition } from './SubtreeDefinition.ts';
|
|
12
|
-
import { ValueNodeDefinition } from './ValueNodeDefinition.ts';
|
|
13
14
|
|
|
14
15
|
export class RootDefinition implements NodeDefinition<'root'> {
|
|
15
16
|
readonly type = 'root';
|
|
@@ -89,7 +90,7 @@ export class RootDefinition implements NodeDefinition<'root'> {
|
|
|
89
90
|
const [firstChild, ...restChildren] = children;
|
|
90
91
|
|
|
91
92
|
if (bodyElement?.type === 'repeat') {
|
|
92
|
-
return
|
|
93
|
+
return RepeatRangeDefinition.from(parent, bind, bodyElement, children);
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
if (restChildren.length) {
|
|
@@ -100,7 +101,10 @@ export class RootDefinition implements NodeDefinition<'root'> {
|
|
|
100
101
|
const isLeafNode = element.childElementCount === 0;
|
|
101
102
|
|
|
102
103
|
if (isLeafNode) {
|
|
103
|
-
return
|
|
104
|
+
return (
|
|
105
|
+
NoteNodeDefinition.from(parent, bind, bodyElement, element) ??
|
|
106
|
+
new LeafNodeDefinition(parent, bind, bodyElement, element)
|
|
107
|
+
);
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
return new SubtreeDefinition(parent, bind, bodyElement, element);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { AnyBodyElementDefinition } from '../body/BodyDefinition.ts';
|
|
2
|
+
import type { InputDefinition } from '../body/control/InputDefinition.ts';
|
|
3
|
+
import type { NoteNode } from '../client/NoteNode.ts';
|
|
4
|
+
import type { ConstantTruthyDependentExpression } from '../expression/DependentExpression.ts';
|
|
5
|
+
import { BindComputation } from '../model/BindComputation.ts';
|
|
6
|
+
import type { BindDefinition } from '../model/BindDefinition.ts';
|
|
7
|
+
import { LeafNodeDefinition } from '../model/LeafNodeDefinition.ts';
|
|
8
|
+
import type { ParentNodeDefinition } from '../model/NodeDefinition.ts';
|
|
9
|
+
import type { HintDefinition } from './text/HintDefinition.ts';
|
|
10
|
+
import type { LabelDefinition } from './text/LabelDefinition.ts';
|
|
11
|
+
|
|
12
|
+
// prettier-ignore
|
|
13
|
+
export type NoteReadonlyDefinition =
|
|
14
|
+
& BindComputation<'readonly'>
|
|
15
|
+
& ConstantTruthyDependentExpression;
|
|
16
|
+
|
|
17
|
+
export interface NoteBindDefinition extends BindDefinition {
|
|
18
|
+
readonly readonly: NoteReadonlyDefinition;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const isNoteBindDefinition = (bind: BindDefinition): bind is NoteBindDefinition => {
|
|
22
|
+
return bind.readonly.isConstantTruthyExpression();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// prettier-ignore
|
|
26
|
+
export type NoteTextDefinition =
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
28
|
+
| LabelDefinition
|
|
29
|
+
| HintDefinition;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @package This class is used internally, both in static types and at runtime,
|
|
33
|
+
* to guard and guide the distinction between instance state nodes for 'note'
|
|
34
|
+
* and 'string' node types. It is intentionally package-private! The less
|
|
35
|
+
* specific {@link NoteNode.definition} type, if it has any client value at all,
|
|
36
|
+
* should be more than sufficient. Clients are otherwise expected to use other
|
|
37
|
+
* aspects of the node's interface (such as its {@link NoteNode.nodeType} and
|
|
38
|
+
* distinct {@link NoteNode.currentState} types) to handle note-specific logic.
|
|
39
|
+
*/
|
|
40
|
+
export class NoteNodeDefinition extends LeafNodeDefinition {
|
|
41
|
+
static from(
|
|
42
|
+
parent: ParentNodeDefinition,
|
|
43
|
+
bind: BindDefinition,
|
|
44
|
+
bodyElement: AnyBodyElementDefinition | null,
|
|
45
|
+
node: Element
|
|
46
|
+
): NoteNodeDefinition | null {
|
|
47
|
+
if (!isNoteBindDefinition(bind) || bodyElement?.type !== 'input') {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const { label, hint } = bodyElement;
|
|
52
|
+
const noteTextDefinition = label ?? hint;
|
|
53
|
+
|
|
54
|
+
if (noteTextDefinition == null) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return new this(parent, bind, bodyElement, noteTextDefinition, node);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
constructor(
|
|
62
|
+
parent: ParentNodeDefinition,
|
|
63
|
+
override readonly bind: NoteBindDefinition,
|
|
64
|
+
override readonly bodyElement: InputDefinition,
|
|
65
|
+
readonly noteTextDefinition: NoteTextDefinition,
|
|
66
|
+
node: Element
|
|
67
|
+
) {
|
|
68
|
+
super(parent, bind, bodyElement, node);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# @getodk/xforms-engine: parse
|
|
2
|
+
|
|
3
|
+
Presence of this file is intended to be temporary! It is here to signal the intent to make a clearer distinction between the parsing and runtime aspects of the engine implementation. For entirely pragmatic purposes, newly introduced will be added here to start. We can decide in review if we want to move the rest into this directory right away. (For existing/untouched code, this would just mean moving the files and updating imports to reflect that. Small effort, lots of potential diff noise.)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { RepeatElementDefinition } from '../../body/RepeatElementDefinition.ts';
|
|
2
|
+
import type { RepeatRangeControlledNode } from '../../client/repeat/RepeatRangeControlledNode.ts';
|
|
3
|
+
import { DependentExpression } from '../../expression/DependentExpression.ts';
|
|
4
|
+
import { isConstantTruthyExpression } from '../xpath/semantic-analysis.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents either of these
|
|
8
|
+
* {@link https://getodk.github.io/xforms-spec/#body-attributes | body attributes}:
|
|
9
|
+
*
|
|
10
|
+
* - `jr:count`
|
|
11
|
+
* - `jr:noAddRemove`
|
|
12
|
+
*
|
|
13
|
+
* In both cases, the downstream effect is that the engine is responsible for
|
|
14
|
+
* controlling the count of a repeat range's instances. Representing both cases
|
|
15
|
+
* should simplify client usage, as well as implementation of the internal
|
|
16
|
+
* representation of {@link RepeatRangeControlledNode}.
|
|
17
|
+
*/
|
|
18
|
+
export class RepeatCountControlExpression extends DependentExpression<'number'> {
|
|
19
|
+
static from(
|
|
20
|
+
bodyElement: RepeatElementDefinition,
|
|
21
|
+
initialCount: number
|
|
22
|
+
): RepeatCountControlExpression | null {
|
|
23
|
+
const { countExpression, noAddRemoveExpression } = bodyElement;
|
|
24
|
+
|
|
25
|
+
if (countExpression != null) {
|
|
26
|
+
return new this(bodyElement, countExpression);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (noAddRemoveExpression != null && isConstantTruthyExpression(noAddRemoveExpression)) {
|
|
30
|
+
// Assumption: `noAddRemove` with no form-defined repeat instances has no
|
|
31
|
+
// purpose. Infer intent as a single repeat instance, as defined by the
|
|
32
|
+
// repeat's template.
|
|
33
|
+
const fixedCountExpression = String(Math.max(initialCount, 1));
|
|
34
|
+
|
|
35
|
+
return new this(bodyElement, fixedCountExpression);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private constructor(context: RepeatElementDefinition, expression: string) {
|
|
42
|
+
super(context, 'number', expression);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LocalNamedElement } from '@getodk/common/types/dom.ts';
|
|
2
|
+
import type { XFormDefinition } from '../../XFormDefinition.ts';
|
|
3
|
+
import type { AnyControlDefinition } from '../../body/control/ControlDefinition.ts';
|
|
4
|
+
import { getHintElement } from '../../lib/dom/query.ts';
|
|
5
|
+
import { TextElementDefinition } from './abstract/TextElementDefinition.ts';
|
|
6
|
+
|
|
7
|
+
interface HintElement extends LocalNamedElement<'hint'> {}
|
|
8
|
+
|
|
9
|
+
export class HintDefinition extends TextElementDefinition<'hint'> {
|
|
10
|
+
static forElement(form: XFormDefinition, owner: AnyControlDefinition): HintDefinition | null {
|
|
11
|
+
const hintElement = getHintElement(owner.element);
|
|
12
|
+
|
|
13
|
+
if (hintElement == null) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return new this(form, owner, hintElement);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
readonly role = 'hint';
|
|
21
|
+
|
|
22
|
+
private constructor(form: XFormDefinition, owner: AnyControlDefinition, element: HintElement) {
|
|
23
|
+
super(form, owner, element);
|
|
24
|
+
}
|
|
25
|
+
}
|