@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
|
@@ -110,7 +110,7 @@ export type StaticPropertySpec<T> = Exclude<T, NonStaticValue>;
|
|
|
110
110
|
export type StatePropertySpec<T = any> = MutablePropertySpec<T> | ComputedPropertySpec<T> | StaticPropertySpec<T>;
|
|
111
111
|
export declare const isMutablePropertySpec: <T>(propertySpec: StatePropertySpec<T>) => propertySpec is MutablePropertySpec<T>;
|
|
112
112
|
export declare const isComputedPropertySpec: <T>(propertySpec: StatePropertySpec<T>) => propertySpec is ComputedPropertySpec<T>;
|
|
113
|
-
export declare const isStaticPropertySpec: <T>(propertySpec: StatePropertySpec<T>) => propertySpec is
|
|
113
|
+
export declare const isStaticPropertySpec: <T>(propertySpec: StatePropertySpec<T>) => propertySpec is StaticPropertySpec<T>;
|
|
114
114
|
export type StateSpec = Record<string, StatePropertySpec>;
|
|
115
115
|
type SpecifiedStatePropertyValue<PropertySpec extends StatePropertySpec> = PropertySpec extends StatePropertySpec<infer T> ? T : never;
|
|
116
116
|
type DerivedMutableKeys<Spec extends StateSpec> = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Accessor } from 'solid-js';
|
|
2
|
+
import { TextRange } from '../../../client/TextRange.ts';
|
|
2
3
|
import { EvaluationContext } from '../../../instance/internal-api/EvaluationContext.ts';
|
|
3
|
-
import {
|
|
4
|
-
import { ValueNodeDefinition } from '../../../model/ValueNodeDefinition.ts';
|
|
4
|
+
import { LeafNodeDefinition } from '../../../model/LeafNodeDefinition.ts';
|
|
5
5
|
|
|
6
|
-
export declare const createFieldHint: (context: EvaluationContext, definition:
|
|
6
|
+
export declare const createFieldHint: (context: EvaluationContext, definition: LeafNodeDefinition) => Accessor<TextRange<"hint", "form"> | null>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Accessor } from 'solid-js';
|
|
2
|
+
import { TextRange } from '../../../client/TextRange.ts';
|
|
2
3
|
import { EvaluationContext } from '../../../instance/internal-api/EvaluationContext.ts';
|
|
3
|
-
import { TextRange } from '../../../instance/text/TextRange.ts';
|
|
4
4
|
import { AnyNodeDefinition } from '../../../model/NodeDefinition.ts';
|
|
5
5
|
|
|
6
|
-
export declare const createNodeLabel: (context: EvaluationContext, definition: AnyNodeDefinition) => Accessor<TextRange<
|
|
6
|
+
export declare const createNodeLabel: (context: EvaluationContext, definition: AnyNodeDefinition) => Accessor<TextRange<"label", "form"> | null>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Accessor } from 'solid-js';
|
|
2
|
+
import { TextRange } from '../../../client/TextRange.ts';
|
|
3
|
+
import { EvaluationContext } from '../../../instance/internal-api/EvaluationContext.ts';
|
|
4
|
+
import { NoteTextDefinition } from '../../../parse/NoteNodeDefinition.ts';
|
|
5
|
+
|
|
6
|
+
export type NoteTextRole = 'label' | 'hint';
|
|
7
|
+
export type ComputedNoteText<Role extends NoteTextRole = NoteTextRole> = Accessor<TextRange<Role, 'form'>>;
|
|
8
|
+
interface BaseNoteText {
|
|
9
|
+
readonly role: NoteTextRole;
|
|
10
|
+
readonly label: ComputedNoteText<'label'> | null;
|
|
11
|
+
readonly hint: ComputedNoteText<'hint'> | null;
|
|
12
|
+
}
|
|
13
|
+
interface LabelNoteText extends BaseNoteText {
|
|
14
|
+
readonly role: 'label';
|
|
15
|
+
readonly label: ComputedNoteText<'label'>;
|
|
16
|
+
readonly hint: null;
|
|
17
|
+
}
|
|
18
|
+
interface HintNoteText extends BaseNoteText {
|
|
19
|
+
readonly role: 'hint';
|
|
20
|
+
readonly label: null;
|
|
21
|
+
readonly hint: ComputedNoteText<'hint'>;
|
|
22
|
+
}
|
|
23
|
+
export type NoteTextComputation = LabelNoteText | HintNoteText;
|
|
24
|
+
export declare const createNoteText: (context: EvaluationContext, noteTextDefinition: NoteTextDefinition) => NoteTextComputation;
|
|
25
|
+
export {};
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Accessor } from 'solid-js';
|
|
2
|
-
import {
|
|
2
|
+
import { TextRole } from '../../../client/TextRange.ts';
|
|
3
3
|
import { EvaluationContext } from '../../../instance/internal-api/EvaluationContext.ts';
|
|
4
|
-
import { TextRange
|
|
4
|
+
import { TextRange } from '../../../instance/text/TextRange.ts';
|
|
5
|
+
import { TextRangeDefinition } from '../../../parse/text/abstract/TextRangeDefinition.ts';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
readonly fallbackValue?: FallbackValue;
|
|
8
|
-
}
|
|
9
|
-
type ComputedTextRange<Role extends TextRole, Definition extends TextElementDefinition<Role> | null, FallbackValue extends string | null> = Accessor<Definition extends null ? FallbackValue extends null ? TextRange<Role> | null : TextRange<Role> : TextRange<Role>>;
|
|
7
|
+
type ComputedFormTextRange<Role extends TextRole> = Accessor<TextRange<Role, 'form'>>;
|
|
10
8
|
/**
|
|
11
9
|
* Creates a text range (e.g. label or hint) from the provided definition,
|
|
12
10
|
* reactive to:
|
|
@@ -16,5 +14,5 @@ type ComputedTextRange<Role extends TextRole, Definition extends TextElementDefi
|
|
|
16
14
|
*
|
|
17
15
|
* @todo This does not yet handle itext translations **with** outputs!
|
|
18
16
|
*/
|
|
19
|
-
export declare const createTextRange: <Role extends TextRole
|
|
17
|
+
export declare const createTextRange: <Role extends TextRole>(context: EvaluationContext, role: Role, definition: TextRangeDefinition<Role>) => ComputedFormTextRange<Role>;
|
|
20
18
|
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OpaqueReactiveObjectFactory } from '../../../client/OpaqueReactiveObjectFactory.ts';
|
|
2
|
+
import { AncestorNodeValidationState } from '../../../client/validation.ts';
|
|
3
|
+
import { AnyParentNode } from '../../../instance/hierarchy.ts';
|
|
4
|
+
|
|
5
|
+
interface AggregatedViolationsOptions {
|
|
6
|
+
readonly clientStateFactory: OpaqueReactiveObjectFactory<AncestorNodeValidationState>;
|
|
7
|
+
}
|
|
8
|
+
export declare const createAggregatedViolations: (context: AnyParentNode, options: AggregatedViolationsOptions) => AncestorNodeValidationState;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Accessor } from 'solid-js';
|
|
2
|
+
import { OpaqueReactiveObjectFactory } from '../../../client/OpaqueReactiveObjectFactory.ts';
|
|
3
|
+
import { AnyViolation, ConditionValidation, ValidationCondition } from '../../../client/validation.ts';
|
|
4
|
+
import { ValidationContext } from '../../../instance/internal-api/ValidationContext.ts';
|
|
5
|
+
import { SharedNodeState, SharedNodeStateOptions } from '../node-state/createSharedNodeState.ts';
|
|
6
|
+
|
|
7
|
+
type ComputedConditionValidation<Condition extends ValidationCondition> = Accessor<ConditionValidation<Condition>>;
|
|
8
|
+
type ComputedViolation = Accessor<AnyViolation | null>;
|
|
9
|
+
interface ValidationStateSpec {
|
|
10
|
+
readonly constraint: ComputedConditionValidation<'constraint'>;
|
|
11
|
+
readonly required: ComputedConditionValidation<'required'>;
|
|
12
|
+
readonly violation: ComputedViolation;
|
|
13
|
+
}
|
|
14
|
+
export type SharedValidationState = SharedNodeState<ValidationStateSpec>;
|
|
15
|
+
interface ValidationStateOptions<Factory extends OpaqueReactiveObjectFactory> extends SharedNodeStateOptions<Factory, ValidationStateSpec> {
|
|
16
|
+
}
|
|
17
|
+
export declare const createValidationState: <Factory extends OpaqueReactiveObjectFactory>(context: ValidationContext, options: ValidationStateOptions<Factory>) => SharedValidationState;
|
|
18
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { XFormDataType } from '../XFormDataType.ts';
|
|
2
2
|
import { XFormDefinition } from '../XFormDefinition.ts';
|
|
3
3
|
import { DependencyContext } from '../expression/DependencyContext.ts';
|
|
4
|
-
import {
|
|
4
|
+
import { MessageDefinition } from '../parse/text/MessageDefinition.ts';
|
|
5
5
|
import { BindComputation } from './BindComputation.ts';
|
|
6
6
|
import { BindElement } from './BindElement.ts';
|
|
7
7
|
import { ModelDefinition } from './ModelDefinition.ts';
|
|
@@ -21,7 +21,9 @@ export declare class BindDefinition extends DependencyContext {
|
|
|
21
21
|
/**
|
|
22
22
|
* 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).
|
|
23
23
|
*/
|
|
24
|
-
readonly constraint: BindComputation<'constraint'
|
|
24
|
+
readonly constraint: BindComputation<'constraint'>;
|
|
25
|
+
readonly constraintMsg: MessageDefinition<'constraintMsg'> | null;
|
|
26
|
+
readonly requiredMsg: MessageDefinition<'requiredMsg'> | null;
|
|
25
27
|
readonly saveIncomplete: BindComputation<'saveIncomplete'>;
|
|
26
28
|
protected _parentBind: BindDefinition | null | undefined;
|
|
27
29
|
get parentBind(): BindDefinition | null;
|
|
@@ -3,9 +3,9 @@ import { BindDefinition } from './BindDefinition.ts';
|
|
|
3
3
|
import { DescendentNodeDefinition } from './DescendentNodeDefinition.ts';
|
|
4
4
|
import { NodeDefinition, ParentNodeDefinition } from './NodeDefinition.ts';
|
|
5
5
|
|
|
6
|
-
export declare class
|
|
6
|
+
export declare class LeafNodeDefinition extends DescendentNodeDefinition<'leaf-node', ControlElementDefinition | null> implements NodeDefinition<'leaf-node'> {
|
|
7
7
|
readonly node: Element;
|
|
8
|
-
readonly type = "
|
|
8
|
+
readonly type = "leaf-node";
|
|
9
9
|
readonly nodeName: string;
|
|
10
10
|
readonly children: null;
|
|
11
11
|
readonly instances: null;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { AnyBodyElementDefinition } from '../body/BodyDefinition.ts';
|
|
2
2
|
import { RepeatElementDefinition } from '../body/RepeatElementDefinition.ts';
|
|
3
3
|
import { BindDefinition } from './BindDefinition.ts';
|
|
4
|
+
import { LeafNodeDefinition } from './LeafNodeDefinition.ts';
|
|
4
5
|
import { RepeatInstanceDefinition } from './RepeatInstanceDefinition.ts';
|
|
5
|
-
import {
|
|
6
|
+
import { AnyRepeatRangeDefinition } from './RepeatRangeDefinition.ts';
|
|
6
7
|
import { RepeatTemplateDefinition } from './RepeatTemplateDefinition.ts';
|
|
7
8
|
import { RootDefinition } from './RootDefinition.ts';
|
|
8
9
|
import { SubtreeDefinition } from './SubtreeDefinition.ts';
|
|
9
|
-
import { ValueNodeDefinition } from './ValueNodeDefinition.ts';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Corresponds to the model/entry DOM root node, i.e.:
|
|
@@ -44,16 +44,16 @@ export type SubtreeNodeType = 'subtree';
|
|
|
44
44
|
* - An element with no child elements
|
|
45
45
|
* - Any attribute corresponding to a bind's `nodeset` expression
|
|
46
46
|
*/
|
|
47
|
-
export type
|
|
48
|
-
export type NodeDefinitionType = RootNodeType | RepeatRangeType | RepeatTemplateType | RepeatInstanceType | SubtreeNodeType |
|
|
47
|
+
export type LeafNodeType = 'leaf-node';
|
|
48
|
+
export type NodeDefinitionType = RootNodeType | RepeatRangeType | RepeatTemplateType | RepeatInstanceType | SubtreeNodeType | LeafNodeType;
|
|
49
49
|
export type ParentNodeDefinition = RootDefinition | RepeatTemplateDefinition | RepeatInstanceDefinition | SubtreeDefinition;
|
|
50
|
-
export type ChildNodeDefinition =
|
|
51
|
-
export type ChildNodeInstanceDefinition = RepeatTemplateDefinition | RepeatInstanceDefinition | SubtreeDefinition |
|
|
50
|
+
export type ChildNodeDefinition = AnyRepeatRangeDefinition | LeafNodeDefinition | SubtreeDefinition;
|
|
51
|
+
export type ChildNodeInstanceDefinition = RepeatTemplateDefinition | RepeatInstanceDefinition | SubtreeDefinition | LeafNodeDefinition;
|
|
52
52
|
export type NodeChildren<Type extends NodeDefinitionType> = Type extends ParentNodeDefinition['type'] ? readonly ChildNodeDefinition[] : null;
|
|
53
53
|
export type NodeInstances<Type extends NodeDefinitionType> = Type extends 'repeat-range' ? readonly RepeatInstanceDefinition[] : null;
|
|
54
54
|
export type NodeParent<Type extends NodeDefinitionType> = Type extends ChildNodeDefinition['type'] | ChildNodeInstanceDefinition['type'] ? ParentNodeDefinition : null;
|
|
55
55
|
export type ModelNode<Type extends NodeDefinitionType> = Type extends 'repeat-range' ? null : Element;
|
|
56
|
-
export type NodeDefaultValue<Type extends NodeDefinitionType> = Type extends '
|
|
56
|
+
export type NodeDefaultValue<Type extends NodeDefinitionType> = Type extends 'leaf-node' ? string : null;
|
|
57
57
|
export interface NodeDefinition<Type extends NodeDefinitionType> {
|
|
58
58
|
readonly type: Type;
|
|
59
59
|
readonly bind: BindDefinition;
|
|
@@ -69,7 +69,7 @@ export interface NodeDefinition<Type extends NodeDefinitionType> {
|
|
|
69
69
|
readonly node: ModelNode<Type>;
|
|
70
70
|
readonly defaultValue: NodeDefaultValue<Type>;
|
|
71
71
|
}
|
|
72
|
-
export type AnyNodeDefinition = RootDefinition |
|
|
72
|
+
export type AnyNodeDefinition = RootDefinition | AnyRepeatRangeDefinition | RepeatTemplateDefinition | RepeatInstanceDefinition | SubtreeDefinition | LeafNodeDefinition;
|
|
73
73
|
export type TypedNodeDefinition<Type> = Extract<AnyNodeDefinition, {
|
|
74
74
|
readonly type: Type;
|
|
75
75
|
}>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RepeatElementDefinition } from '../body/RepeatElementDefinition.ts';
|
|
2
2
|
import { DescendentNodeDefinition } from './DescendentNodeDefinition.ts';
|
|
3
3
|
import { ChildNodeDefinition, NodeDefinition } from './NodeDefinition.ts';
|
|
4
|
-
import {
|
|
4
|
+
import { AnyRepeatRangeDefinition } from './RepeatRangeDefinition.ts';
|
|
5
5
|
|
|
6
6
|
export declare class RepeatInstanceDefinition extends DescendentNodeDefinition<'repeat-instance', RepeatElementDefinition> implements NodeDefinition<'repeat-instance'> {
|
|
7
7
|
readonly node: Element;
|
|
@@ -10,6 +10,6 @@ export declare class RepeatInstanceDefinition extends DescendentNodeDefinition<'
|
|
|
10
10
|
readonly children: readonly ChildNodeDefinition[];
|
|
11
11
|
readonly instances: null;
|
|
12
12
|
readonly defaultValue: null;
|
|
13
|
-
constructor(range:
|
|
13
|
+
constructor(range: AnyRepeatRangeDefinition, node: Element);
|
|
14
14
|
toJSON(): Omit<this, "toJSON" | "parent" | "bind" | "root" | "bodyElement">;
|
|
15
15
|
}
|
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
import { RepeatElementDefinition } from '../body/RepeatElementDefinition.ts';
|
|
2
|
+
import { RepeatCountControlExpression } from '../parse/expression/RepeatCountControlExpression.ts';
|
|
2
3
|
import { BindDefinition } from './BindDefinition.ts';
|
|
3
4
|
import { DescendentNodeDefinition } from './DescendentNodeDefinition.ts';
|
|
4
5
|
import { 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
|
+
export interface UncontrolledRepeatRangeDefinition extends RepeatRangeDefinition {
|
|
13
|
+
readonly count: null;
|
|
14
|
+
}
|
|
15
|
+
export type AnyRepeatRangeDefinition = ControlledRepeatRangeDefinition | UncontrolledRepeatRangeDefinition;
|
|
8
16
|
export declare class RepeatRangeDefinition extends DescendentNodeDefinition<'repeat-range', RepeatElementDefinition> implements NodeDefinition<'repeat-range'> {
|
|
9
|
-
static
|
|
10
|
-
static createInstanceElement(templateElement: Element): Element;
|
|
17
|
+
static from(parent: ParentNodeDefinition, bind: BindDefinition, bodyElement: RepeatElementDefinition, modelNodes: readonly [Element, ...Element[]]): AnyRepeatRangeDefinition;
|
|
11
18
|
readonly type = "repeat-range";
|
|
12
19
|
readonly template: RepeatTemplateDefinition;
|
|
13
20
|
readonly children: null;
|
|
14
21
|
readonly instances: RepeatInstanceDefinition[];
|
|
22
|
+
readonly count: RepeatCountControlExpression | null;
|
|
15
23
|
readonly node: null;
|
|
16
24
|
readonly nodeName: string;
|
|
17
25
|
readonly defaultValue: null;
|
|
18
|
-
constructor(
|
|
19
|
-
|
|
26
|
+
private constructor();
|
|
27
|
+
isControlled(): this is ControlledRepeatRangeDefinition;
|
|
28
|
+
isUncontrolled(): this is UncontrolledRepeatRangeDefinition;
|
|
29
|
+
toJSON(): Omit<this, "toJSON" | "parent" | "bind" | "root" | "bodyElement" | "isControlled" | "isUncontrolled">;
|
|
20
30
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AnyBodyElementDefinition } from '../body/BodyDefinition.ts';
|
|
2
|
+
import { InputDefinition } from '../body/control/InputDefinition.ts';
|
|
3
|
+
import { ConstantTruthyDependentExpression } from '../expression/DependentExpression.ts';
|
|
4
|
+
import { BindComputation } from '../model/BindComputation.ts';
|
|
5
|
+
import { BindDefinition } from '../model/BindDefinition.ts';
|
|
6
|
+
import { LeafNodeDefinition } from '../model/LeafNodeDefinition.ts';
|
|
7
|
+
import { ParentNodeDefinition } from '../model/NodeDefinition.ts';
|
|
8
|
+
import { HintDefinition } from './text/HintDefinition.ts';
|
|
9
|
+
import { LabelDefinition } from './text/LabelDefinition.ts';
|
|
10
|
+
|
|
11
|
+
export type NoteReadonlyDefinition = BindComputation<'readonly'> & ConstantTruthyDependentExpression;
|
|
12
|
+
export interface NoteBindDefinition extends BindDefinition {
|
|
13
|
+
readonly readonly: NoteReadonlyDefinition;
|
|
14
|
+
}
|
|
15
|
+
export type NoteTextDefinition = LabelDefinition | HintDefinition;
|
|
16
|
+
/**
|
|
17
|
+
* @package This class is used internally, both in static types and at runtime,
|
|
18
|
+
* to guard and guide the distinction between instance state nodes for 'note'
|
|
19
|
+
* and 'string' node types. It is intentionally package-private! The less
|
|
20
|
+
* specific {@link NoteNode.definition} type, if it has any client value at all,
|
|
21
|
+
* should be more than sufficient. Clients are otherwise expected to use other
|
|
22
|
+
* aspects of the node's interface (such as its {@link NoteNode.nodeType} and
|
|
23
|
+
* distinct {@link NoteNode.currentState} types) to handle note-specific logic.
|
|
24
|
+
*/
|
|
25
|
+
export declare class NoteNodeDefinition extends LeafNodeDefinition {
|
|
26
|
+
readonly bind: NoteBindDefinition;
|
|
27
|
+
readonly bodyElement: InputDefinition;
|
|
28
|
+
readonly noteTextDefinition: NoteTextDefinition;
|
|
29
|
+
static from(parent: ParentNodeDefinition, bind: BindDefinition, bodyElement: AnyBodyElementDefinition | null, node: Element): NoteNodeDefinition | null;
|
|
30
|
+
constructor(parent: ParentNodeDefinition, bind: NoteBindDefinition, bodyElement: InputDefinition, noteTextDefinition: NoteTextDefinition, node: Element);
|
|
31
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RepeatElementDefinition } from '../../body/RepeatElementDefinition.ts';
|
|
2
|
+
import { DependentExpression } from '../../expression/DependentExpression.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents either of these
|
|
6
|
+
* {@link https://getodk.github.io/xforms-spec/#body-attributes | body attributes}:
|
|
7
|
+
*
|
|
8
|
+
* - `jr:count`
|
|
9
|
+
* - `jr:noAddRemove`
|
|
10
|
+
*
|
|
11
|
+
* In both cases, the downstream effect is that the engine is responsible for
|
|
12
|
+
* controlling the count of a repeat range's instances. Representing both cases
|
|
13
|
+
* should simplify client usage, as well as implementation of the internal
|
|
14
|
+
* representation of {@link RepeatRangeControlledNode}.
|
|
15
|
+
*/
|
|
16
|
+
export declare class RepeatCountControlExpression extends DependentExpression<'number'> {
|
|
17
|
+
static from(bodyElement: RepeatElementDefinition, initialCount: number): RepeatCountControlExpression | null;
|
|
18
|
+
private constructor();
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { XFormDefinition } from '../../XFormDefinition.ts';
|
|
2
|
+
import { AnyControlDefinition } from '../../body/control/ControlDefinition.ts';
|
|
3
|
+
import { TextElementDefinition } from './abstract/TextElementDefinition.ts';
|
|
4
|
+
|
|
5
|
+
export declare class HintDefinition extends TextElementDefinition<'hint'> {
|
|
6
|
+
static forElement(form: XFormDefinition, owner: AnyControlDefinition): HintDefinition | null;
|
|
7
|
+
readonly role = "hint";
|
|
8
|
+
private constructor();
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { XFormDefinition } from '../../XFormDefinition.ts';
|
|
2
|
+
import { ItemDefinition } from '../../body/control/select/ItemDefinition.ts';
|
|
3
|
+
import { TextElementDefinition } from './abstract/TextElementDefinition.ts';
|
|
4
|
+
|
|
5
|
+
export declare class ItemLabelDefinition extends TextElementDefinition<'item-label'> {
|
|
6
|
+
static from(form: XFormDefinition, owner: ItemDefinition): ItemLabelDefinition | null;
|
|
7
|
+
readonly role = "item-label";
|
|
8
|
+
private constructor();
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { XFormDefinition } from '../../XFormDefinition.ts';
|
|
2
|
+
import { ItemDefinition } from '../../body/control/select/ItemDefinition.ts';
|
|
3
|
+
import { ItemsetDefinition } from '../../body/control/select/ItemsetDefinition.ts';
|
|
4
|
+
import { RefAttributeChunk } from './abstract/TextElementDefinition.ts';
|
|
5
|
+
import { TextRangeDefinition } from './abstract/TextRangeDefinition.ts';
|
|
6
|
+
|
|
7
|
+
export type ItemLabelOwner = ItemDefinition | ItemsetDefinition;
|
|
8
|
+
export declare class ItemsetLabelDefinition extends TextRangeDefinition<'item-label'> {
|
|
9
|
+
static from(form: XFormDefinition, owner: ItemsetDefinition): ItemsetLabelDefinition | null;
|
|
10
|
+
readonly role = "item-label";
|
|
11
|
+
readonly chunks: readonly [RefAttributeChunk];
|
|
12
|
+
private constructor();
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { XFormDefinition } from '../../XFormDefinition.ts';
|
|
2
|
+
import { AnyGroupElementDefinition } from '../../body/BodyDefinition.ts';
|
|
3
|
+
import { RepeatElementDefinition } from '../../body/RepeatElementDefinition.ts';
|
|
4
|
+
import { AnyControlDefinition } from '../../body/control/ControlDefinition.ts';
|
|
5
|
+
import { BaseGroupDefinition } from '../../body/group/BaseGroupDefinition.ts';
|
|
6
|
+
import { TextElementDefinition } from './abstract/TextElementDefinition.ts';
|
|
7
|
+
|
|
8
|
+
export type LabelOwner = AnyControlDefinition | AnyGroupElementDefinition | RepeatElementDefinition;
|
|
9
|
+
export declare class LabelDefinition extends TextElementDefinition<'label'> {
|
|
10
|
+
static forControl(form: XFormDefinition, control: AnyControlDefinition): LabelDefinition | null;
|
|
11
|
+
static forRepeatGroup(form: XFormDefinition, repeat: RepeatElementDefinition): LabelDefinition | null;
|
|
12
|
+
static forGroup(form: XFormDefinition, group: BaseGroupDefinition<any>): LabelDefinition | null;
|
|
13
|
+
readonly role = "label";
|
|
14
|
+
private constructor();
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BindDefinition } from '../../model/BindDefinition.ts';
|
|
2
|
+
import { StaticTextChunkDefinition } from './StaticTextChunkDefinition.ts';
|
|
3
|
+
import { TranslationChunkDefinition } from './TranslationChunkDefinition.ts';
|
|
4
|
+
import { TextBindAttributeLocalName, TextSourceNode, TextRangeDefinition } from './abstract/TextRangeDefinition.ts';
|
|
5
|
+
|
|
6
|
+
export type MessageSourceNode = TextSourceNode<TextBindAttributeLocalName>;
|
|
7
|
+
type MessageChunk = StaticTextChunkDefinition | TranslationChunkDefinition;
|
|
8
|
+
export declare class MessageDefinition<Type extends TextBindAttributeLocalName> extends TextRangeDefinition<Type> {
|
|
9
|
+
readonly role: Type;
|
|
10
|
+
static from<Type extends TextBindAttributeLocalName>(bind: BindDefinition, type: Type): MessageDefinition<Type> | null;
|
|
11
|
+
readonly chunks: readonly [MessageChunk];
|
|
12
|
+
private constructor();
|
|
13
|
+
}
|
|
14
|
+
export type AnyMessageDefinition = MessageDefinition<TextBindAttributeLocalName>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TextChunkDefinition } from './abstract/TextChunkDefinition.ts';
|
|
2
|
+
import { AnyTextRangeDefinition } from './abstract/TextRangeDefinition.ts';
|
|
3
|
+
|
|
4
|
+
export declare class OutputChunkDefinition extends TextChunkDefinition<'output'> {
|
|
5
|
+
static from(context: AnyTextRangeDefinition, element: Element): OutputChunkDefinition | null;
|
|
6
|
+
readonly source = "output";
|
|
7
|
+
private constructor();
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TextChunkDefinition } from './abstract/TextChunkDefinition.ts';
|
|
2
|
+
import { AnyTextRangeDefinition } from './abstract/TextRangeDefinition.ts';
|
|
3
|
+
|
|
4
|
+
export declare class ReferenceChunkDefinition extends TextChunkDefinition<'reference'> {
|
|
5
|
+
static from(context: AnyTextRangeDefinition, refExpression: string): ReferenceChunkDefinition;
|
|
6
|
+
readonly source = "reference";
|
|
7
|
+
private constructor();
|
|
8
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TextChunkDefinition } from './abstract/TextChunkDefinition.ts';
|
|
2
|
+
import { AnyTextRangeDefinition } from './abstract/TextRangeDefinition.ts';
|
|
3
|
+
|
|
4
|
+
export type StaticTextChunkSourceNode = Attr | Text;
|
|
5
|
+
export declare class StaticTextChunkDefinition extends TextChunkDefinition<'static'> {
|
|
6
|
+
readonly stringValue: string;
|
|
7
|
+
static from(context: AnyTextRangeDefinition, stringValue: string): StaticTextChunkDefinition;
|
|
8
|
+
readonly source = "static";
|
|
9
|
+
private constructor();
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TextChunkDefinition } from './abstract/TextChunkDefinition.ts';
|
|
2
|
+
import { AnyTextRangeDefinition } from './abstract/TextRangeDefinition.ts';
|
|
3
|
+
|
|
4
|
+
export declare class TranslationChunkDefinition extends TextChunkDefinition<'translation'> {
|
|
5
|
+
static fromMessage(context: AnyTextRangeDefinition, maybeExpression: string): TranslationChunkDefinition | null;
|
|
6
|
+
static from(context: AnyTextRangeDefinition, maybeExpression: string): TranslationChunkDefinition | null;
|
|
7
|
+
readonly source = "translation";
|
|
8
|
+
private constructor();
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TextChunkSource } from '../../../client/TextRange.ts';
|
|
2
|
+
import { DependentExpression } from '../../../expression/DependentExpression.ts';
|
|
3
|
+
import { OutputChunkDefinition } from '../OutputChunkDefinition.ts';
|
|
4
|
+
import { ReferenceChunkDefinition } from '../ReferenceChunkDefinition.ts';
|
|
5
|
+
import { StaticTextChunkDefinition } from '../StaticTextChunkDefinition.ts';
|
|
6
|
+
import { TranslationChunkDefinition } from '../TranslationChunkDefinition.ts';
|
|
7
|
+
import { AnyTextRangeDefinition } from './TextRangeDefinition.ts';
|
|
8
|
+
|
|
9
|
+
interface TextChunkDefinitionOptions {
|
|
10
|
+
readonly isTranslated?: true;
|
|
11
|
+
}
|
|
12
|
+
export declare abstract class TextChunkDefinition<Source extends TextChunkSource> extends DependentExpression<'string'> {
|
|
13
|
+
abstract readonly source: Source;
|
|
14
|
+
readonly stringValue?: string;
|
|
15
|
+
constructor(context: AnyTextRangeDefinition, expression: string, options?: TextChunkDefinitionOptions);
|
|
16
|
+
}
|
|
17
|
+
export type AnyTextChunkDefinition = OutputChunkDefinition | ReferenceChunkDefinition | StaticTextChunkDefinition | TranslationChunkDefinition;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { XFormDefinition } from '../../../XFormDefinition.ts';
|
|
2
|
+
import { ItemDefinition } from '../../../body/control/select/ItemDefinition.ts';
|
|
3
|
+
import { ElementTextRole } from '../../../client/TextRange.ts';
|
|
4
|
+
import { HintDefinition } from '../HintDefinition.ts';
|
|
5
|
+
import { ItemLabelDefinition } from '../ItemLabelDefinition.ts';
|
|
6
|
+
import { ItemsetLabelDefinition } from '../ItemsetLabelDefinition.ts';
|
|
7
|
+
import { LabelDefinition, LabelOwner } from '../LabelDefinition.ts';
|
|
8
|
+
import { OutputChunkDefinition } from '../OutputChunkDefinition.ts';
|
|
9
|
+
import { ReferenceChunkDefinition } from '../ReferenceChunkDefinition.ts';
|
|
10
|
+
import { StaticTextChunkDefinition } from '../StaticTextChunkDefinition.ts';
|
|
11
|
+
import { TranslationChunkDefinition } from '../TranslationChunkDefinition.ts';
|
|
12
|
+
import { TextSourceNode, TextRangeDefinition } from './TextRangeDefinition.ts';
|
|
13
|
+
|
|
14
|
+
export type RefAttributeChunk = ReferenceChunkDefinition | TranslationChunkDefinition;
|
|
15
|
+
type TextElementChildChunk = OutputChunkDefinition | StaticTextChunkDefinition;
|
|
16
|
+
type TextElementChunks = readonly [RefAttributeChunk] | readonly TextElementChildChunk[];
|
|
17
|
+
type TextElementOwner = ItemDefinition | LabelOwner;
|
|
18
|
+
export declare abstract class TextElementDefinition<Role extends ElementTextRole> extends TextRangeDefinition<Role> {
|
|
19
|
+
readonly chunks: TextElementChunks;
|
|
20
|
+
constructor(form: XFormDefinition, owner: TextElementOwner, sourceNode: TextSourceNode<Role>);
|
|
21
|
+
}
|
|
22
|
+
export type AnyTextElementDefinition = HintDefinition | ItemLabelDefinition | ItemsetLabelDefinition | LabelDefinition;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { LocalNamedElement } from '../../../../../common/types/dom.ts';
|
|
2
|
+
import { XFormDefinition } from '../../../XFormDefinition.ts';
|
|
3
|
+
import { TextRole } from '../../../client/TextRange.ts';
|
|
4
|
+
import { DependencyContext } from '../../../expression/DependencyContext.ts';
|
|
5
|
+
import { AnyDependentExpression } from '../../../expression/DependentExpression.ts';
|
|
6
|
+
import { AnyMessageDefinition } from '../MessageDefinition.ts';
|
|
7
|
+
import { AnyTextChunkDefinition } from './TextChunkDefinition.ts';
|
|
8
|
+
import { AnyTextElementDefinition } from './TextElementDefinition.ts';
|
|
9
|
+
|
|
10
|
+
export type TextBindAttributeLocalName = 'constraintMsg' | 'requiredMsg';
|
|
11
|
+
export type TextBodyElementLocalName = 'hint' | 'label';
|
|
12
|
+
interface TextSourceNodes {
|
|
13
|
+
readonly constraintMsg: null;
|
|
14
|
+
readonly hint: LocalNamedElement<'hint'>;
|
|
15
|
+
readonly label: LocalNamedElement<'label'>;
|
|
16
|
+
readonly 'item-label': LocalNamedElement<'label'>;
|
|
17
|
+
readonly requiredMsg: null;
|
|
18
|
+
}
|
|
19
|
+
export type TextSourceNode<Type extends TextRole> = TextSourceNodes[Type];
|
|
20
|
+
export declare abstract class TextRangeDefinition<Role extends TextRole> extends DependencyContext {
|
|
21
|
+
readonly form: XFormDefinition;
|
|
22
|
+
readonly ownerContext: DependencyContext;
|
|
23
|
+
readonly sourceNode: TextSourceNode<Role>;
|
|
24
|
+
abstract readonly role: Role;
|
|
25
|
+
readonly parentReference: string | null;
|
|
26
|
+
readonly reference: string | null;
|
|
27
|
+
abstract readonly chunks: readonly AnyTextChunkDefinition[];
|
|
28
|
+
get isTranslated(): boolean;
|
|
29
|
+
set isTranslated(value: true);
|
|
30
|
+
protected constructor(form: XFormDefinition, ownerContext: DependencyContext, sourceNode: TextSourceNode<Role>);
|
|
31
|
+
registerDependentExpression(expression: AnyDependentExpression): void;
|
|
32
|
+
toJSON(): object;
|
|
33
|
+
}
|
|
34
|
+
export type AnyTextRangeDefinition = AnyMessageDefinition | AnyTextElementDefinition;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface PathResolutionOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Excludes direct references to the nodeset specified as a context. This flag
|
|
4
|
+
* has earlier precedent as `ignoreContextReference` in similar internal APIs.
|
|
5
|
+
* The intent, in part, is to allow for certain in-spec exceptions to cycle
|
|
6
|
+
* analysis (which we previously did explicitly, and foresee reintroducing in
|
|
7
|
+
* some form relatively soon). As such, the default for this flag should be
|
|
8
|
+
* overridden when a computation is (A) not among the core `<bind>`
|
|
9
|
+
* computations or (B) is a computation which is explicitly expected to have
|
|
10
|
+
* self-references (such as `constraint`).
|
|
11
|
+
*
|
|
12
|
+
* @default false
|
|
13
|
+
*
|
|
14
|
+
* @todo It is highly likely we will eliminate this in the future. We
|
|
15
|
+
* considered removing its precursor (and existing code now referencing this)
|
|
16
|
+
* in {@link https://github.com/getodk/web-forms/pull/67}, but ran into issues
|
|
17
|
+
* with some of the reactive logic introduced there. It's likely that
|
|
18
|
+
* subsequent improvements have addressed those issues, but it's also likely
|
|
19
|
+
* that we will want similar special casing when we reintroduce explicit graph
|
|
20
|
+
* cycle analysis.
|
|
21
|
+
*/
|
|
22
|
+
readonly ignoreReferenceToContextPath?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolves XPath paths referenced by an arbitrary expression to XForms
|
|
26
|
+
* `nodeset` references:
|
|
27
|
+
*
|
|
28
|
+
* 1. The provided {@link expression} is analyzed to find path sub-expressions
|
|
29
|
+
* (LocationPaths, sub-expressions with a node-set producing FilterExpr).
|
|
30
|
+
*
|
|
31
|
+
* 2. When a {@link contextNodeset} is available, each sub-expression is
|
|
32
|
+
* resolved to that context. See {@link resolvePath} for additional
|
|
33
|
+
* detail.
|
|
34
|
+
*
|
|
35
|
+
* 3. Once resolved, each dependency path is further analyzed to identify
|
|
36
|
+
* sub-expressions in any of its predicates, resolving each to their
|
|
37
|
+
* respective predicates' Steps. See {@link resolvePredicateReference} for
|
|
38
|
+
* additional detail.
|
|
39
|
+
*/
|
|
40
|
+
export declare const resolveDependencyNodesets: (contextNodeset: string | null, expression: string, options?: PathResolutionOptions) => readonly string[];
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { AbsoluteRootLocationPathNode, FilterExprNode, RelativeStepSyntaxLiteralNode, StepNode } from '@getodk/xpath/static/grammar/SyntaxNode.js';
|
|
2
|
+
import { PathExpressionNode } from './semantic-analysis.ts';
|
|
3
|
+
|
|
4
|
+
type AbsolutePathHead =
|
|
5
|
+
/** / - as first character in LocationPath */
|
|
6
|
+
AbsoluteRootLocationPathNode
|
|
7
|
+
/** // - as first characters in LocationPath */
|
|
8
|
+
| RelativeStepSyntaxLiteralNode;
|
|
9
|
+
/**
|
|
10
|
+
* fn(...args) - as first (and potentially only) part of a path expression,
|
|
11
|
+
* where the function is either known to produce a node-set result, or where
|
|
12
|
+
* other aspects of the exression's syntax are inherently node-set producing.
|
|
13
|
+
*/
|
|
14
|
+
type FilterPathExprHead = FilterExprNode;
|
|
15
|
+
type StepLikeNode =
|
|
16
|
+
/** // - shorthand for `/descendant-or-self::node()/` */
|
|
17
|
+
RelativeStepSyntaxLiteralNode
|
|
18
|
+
/** Any _actual_ Step in a LocationPath */
|
|
19
|
+
| StepNode;
|
|
20
|
+
type PathNodeListHead = AbsolutePathHead | FilterPathExprHead | StepLikeNode;
|
|
21
|
+
/**
|
|
22
|
+
* A path node list is a semi-flattened representation of...
|
|
23
|
+
*
|
|
24
|
+
* - Any XPath LocationPath expression:
|
|
25
|
+
* - AbsoluteLocationPath
|
|
26
|
+
* - RelativeLocationPath
|
|
27
|
+
*
|
|
28
|
+
* - Any expression beginning with a FilterExpr which is known to produce a
|
|
29
|
+
* node-set result
|
|
30
|
+
*
|
|
31
|
+
* The flattening of these syntax representations is used to perform various
|
|
32
|
+
* aspects of path resolution logic, accounting for complexities of XPath syntax
|
|
33
|
+
* and semantics in a roughly linear/list processing manner.
|
|
34
|
+
*/
|
|
35
|
+
export type PathNodeList<Head extends PathNodeListHead = PathNodeListHead> = readonly [
|
|
36
|
+
head: Head,
|
|
37
|
+
...tail: StepLikeNode[]
|
|
38
|
+
];
|
|
39
|
+
export declare const resolvePath: (contextNode: PathExpressionNode | null, pathNode: PathExpressionNode) => PathNodeList;
|
|
40
|
+
/**
|
|
41
|
+
* Resolves the parsed path {@link predicatePathNode}, in the context of:
|
|
42
|
+
*
|
|
43
|
+
* - The {@link contextNode} context, representing the original expression's
|
|
44
|
+
* context (if one was available)
|
|
45
|
+
*
|
|
46
|
+
* - The {@link stepContextNodes} context, representing the cumulative portion
|
|
47
|
+
* of the source path where {@link predicatePathNode} was parsed from a
|
|
48
|
+
* Predicate sub-expression
|
|
49
|
+
*
|
|
50
|
+
* Both contexts are necessary for resolution to ensure that:
|
|
51
|
+
*
|
|
52
|
+
* - A `current()` call within the predicate's sub-expression is contextualized
|
|
53
|
+
* to the current `nodeset` reference associated with the original expression
|
|
54
|
+
*
|
|
55
|
+
* - A `.` self-reference within the predicate's sub-expression is
|
|
56
|
+
* contextualized to the Step in which it occurred
|
|
57
|
+
*/
|
|
58
|
+
export declare const resolvePredicateReference: (contextNode: PathExpressionNode | null, stepContextNodes: PathNodeList, predicatePathNode: PathExpressionNode) => PathNodeList;
|
|
59
|
+
interface PathSerializationOptions {
|
|
60
|
+
/**
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
readonly stripPredicates: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Serializes a resolved {@link PathNodeList} to its XPath expression
|
|
67
|
+
* representation, optionally stripping predicates.
|
|
68
|
+
*/
|
|
69
|
+
export declare const serializeNodesetReference: (nodes: PathNodeList, options: PathSerializationOptions) => string;
|
|
70
|
+
export {};
|