@getodk/xforms-engine 0.1.1 → 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.
Files changed (228) hide show
  1. package/dist/body/BodyDefinition.d.ts +24 -7
  2. package/dist/body/BodyElementDefinition.d.ts +4 -3
  3. package/dist/body/RepeatElementDefinition.d.ts +19 -0
  4. package/dist/body/appearance/inputAppearanceParser.d.ts +4 -0
  5. package/dist/body/appearance/selectAppearanceParser.d.ts +4 -0
  6. package/dist/body/appearance/structureElementAppearanceParser.d.ts +4 -0
  7. package/dist/body/control/ControlDefinition.d.ts +4 -2
  8. package/dist/body/control/InputDefinition.d.ts +5 -0
  9. package/dist/body/control/select/ItemDefinition.d.ts +2 -2
  10. package/dist/body/control/select/ItemsetDefinition.d.ts +5 -4
  11. package/dist/body/control/select/SelectDefinition.d.ts +11 -1
  12. package/dist/body/group/BaseGroupDefinition.d.ts +4 -9
  13. package/dist/body/group/PresentationGroupDefinition.d.ts +1 -1
  14. package/dist/client/BaseNode.d.ts +74 -3
  15. package/dist/client/GroupNode.d.ts +7 -2
  16. package/dist/client/ModelValueNode.d.ts +37 -0
  17. package/dist/client/NodeAppearances.d.ts +15 -0
  18. package/dist/client/NoteNode.d.ts +53 -0
  19. package/dist/client/RootNode.d.ts +21 -0
  20. package/dist/client/SelectNode.d.ts +8 -3
  21. package/dist/client/StringNode.d.ts +8 -3
  22. package/dist/client/SubtreeNode.d.ts +3 -0
  23. package/dist/client/TextRange.d.ts +85 -2
  24. package/dist/client/constants.d.ts +9 -0
  25. package/dist/client/hierarchy.d.ts +14 -9
  26. package/dist/client/node-types.d.ts +2 -1
  27. package/dist/client/{RepeatRangeNode.d.ts → repeat/BaseRepeatRangeNode.d.ts} +19 -15
  28. package/dist/client/{RepeatInstanceNode.d.ts → repeat/RepeatInstanceNode.d.ts} +11 -7
  29. package/dist/client/repeat/RepeatRangeControlledNode.d.ts +19 -0
  30. package/dist/client/repeat/RepeatRangeUncontrolledNode.d.ts +20 -0
  31. package/dist/client/validation.d.ts +163 -0
  32. package/dist/expression/DependentExpression.d.ts +12 -8
  33. package/dist/index.d.ts +9 -4
  34. package/dist/index.js +3173 -960
  35. package/dist/index.js.map +1 -1
  36. package/dist/instance/Group.d.ts +6 -4
  37. package/dist/instance/ModelValue.d.ts +40 -0
  38. package/dist/instance/Note.d.ts +42 -0
  39. package/dist/instance/Root.d.ts +10 -23
  40. package/dist/instance/SelectField.d.ts +12 -6
  41. package/dist/instance/StringField.d.ts +13 -7
  42. package/dist/instance/Subtree.d.ts +3 -1
  43. package/dist/instance/abstract/DescendantNode.d.ts +16 -9
  44. package/dist/instance/abstract/InstanceNode.d.ts +28 -29
  45. package/dist/instance/hierarchy.d.ts +10 -5
  46. package/dist/instance/internal-api/EvaluationContext.d.ts +5 -4
  47. package/dist/instance/internal-api/ValidationContext.d.ts +21 -0
  48. package/dist/instance/internal-api/ValueContext.d.ts +2 -2
  49. package/dist/instance/repeat/BaseRepeatRange.d.ts +160 -0
  50. package/dist/instance/{RepeatInstance.d.ts → repeat/RepeatInstance.d.ts} +38 -13
  51. package/dist/instance/repeat/RepeatRangeControlled.d.ts +16 -0
  52. package/dist/instance/repeat/RepeatRangeUncontrolled.d.ts +35 -0
  53. package/dist/instance/text/TextRange.d.ts +4 -4
  54. package/dist/lib/TokenListParser.d.ts +84 -0
  55. package/dist/lib/dom/query.d.ts +5 -0
  56. package/dist/lib/reactivity/createComputedExpression.d.ts +6 -1
  57. package/dist/lib/reactivity/createNoteReadonlyThunk.d.ts +5 -0
  58. package/dist/lib/reactivity/materializeCurrentStateChildren.d.ts +2 -1
  59. package/dist/lib/reactivity/node-state/createSharedNodeState.d.ts +1 -1
  60. package/dist/lib/reactivity/node-state/createSpecifiedState.d.ts +1 -1
  61. package/dist/lib/reactivity/text/createFieldHint.d.ts +3 -3
  62. package/dist/lib/reactivity/text/createNodeLabel.d.ts +2 -2
  63. package/dist/lib/reactivity/text/createNoteText.d.ts +25 -0
  64. package/dist/lib/reactivity/text/createTextRange.d.ts +5 -7
  65. package/dist/lib/reactivity/validation/createAggregatedViolations.d.ts +9 -0
  66. package/dist/lib/reactivity/validation/createValidation.d.ts +18 -0
  67. package/dist/model/BindDefinition.d.ts +4 -2
  68. package/dist/model/BindElement.d.ts +1 -0
  69. package/dist/model/DescendentNodeDefinition.d.ts +1 -2
  70. package/dist/model/{ValueNodeDefinition.d.ts → LeafNodeDefinition.d.ts} +3 -4
  71. package/dist/model/NodeDefinition.d.ts +16 -16
  72. package/dist/model/RepeatInstanceDefinition.d.ts +5 -6
  73. package/dist/model/RepeatRangeDefinition.d.ts +30 -0
  74. package/dist/model/RepeatTemplateDefinition.d.ts +6 -7
  75. package/dist/model/RootDefinition.d.ts +3 -1
  76. package/dist/model/SubtreeDefinition.d.ts +2 -2
  77. package/dist/parse/NoteNodeDefinition.d.ts +31 -0
  78. package/dist/parse/expression/RepeatCountControlExpression.d.ts +19 -0
  79. package/dist/parse/text/HintDefinition.d.ts +9 -0
  80. package/dist/parse/text/ItemLabelDefinition.d.ts +9 -0
  81. package/dist/parse/text/ItemsetLabelDefinition.d.ts +13 -0
  82. package/dist/parse/text/LabelDefinition.d.ts +15 -0
  83. package/dist/parse/text/MessageDefinition.d.ts +15 -0
  84. package/dist/parse/text/OutputChunkDefinition.d.ts +8 -0
  85. package/dist/parse/text/ReferenceChunkDefinition.d.ts +8 -0
  86. package/dist/parse/text/StaticTextChunkDefinition.d.ts +10 -0
  87. package/dist/parse/text/TranslationChunkDefinition.d.ts +9 -0
  88. package/dist/parse/text/abstract/TextChunkDefinition.d.ts +18 -0
  89. package/dist/parse/text/abstract/TextElementDefinition.d.ts +23 -0
  90. package/dist/parse/text/abstract/TextRangeDefinition.d.ts +35 -0
  91. package/dist/parse/xpath/dependency-analysis.d.ts +40 -0
  92. package/dist/parse/xpath/path-resolution.d.ts +70 -0
  93. package/dist/parse/xpath/predicate-analysis.d.ts +30 -0
  94. package/dist/parse/xpath/reference-parsing.d.ts +18 -0
  95. package/dist/parse/xpath/semantic-analysis.d.ts +98 -0
  96. package/dist/parse/xpath/syntax-traversal.d.ts +69 -0
  97. package/dist/solid.js +3174 -961
  98. package/dist/solid.js.map +1 -1
  99. package/package.json +14 -15
  100. package/src/XFormDOM.ts +81 -8
  101. package/src/body/BodyDefinition.ts +38 -23
  102. package/src/body/BodyElementDefinition.ts +4 -3
  103. package/src/body/RepeatElementDefinition.ts +58 -0
  104. package/src/body/appearance/inputAppearanceParser.ts +39 -0
  105. package/src/body/appearance/selectAppearanceParser.ts +38 -0
  106. package/src/body/appearance/structureElementAppearanceParser.ts +7 -0
  107. package/src/body/control/ControlDefinition.ts +8 -3
  108. package/src/body/control/InputDefinition.ts +13 -0
  109. package/src/body/control/select/ItemDefinition.ts +3 -3
  110. package/src/body/control/select/ItemsetDefinition.ts +29 -12
  111. package/src/body/control/select/ItemsetNodesetExpression.ts +1 -1
  112. package/src/body/control/select/SelectDefinition.ts +14 -5
  113. package/src/body/group/BaseGroupDefinition.ts +14 -51
  114. package/src/body/group/PresentationGroupDefinition.ts +1 -1
  115. package/src/client/BaseNode.ts +82 -8
  116. package/src/client/GroupNode.ts +8 -2
  117. package/src/client/ModelValueNode.ts +40 -0
  118. package/src/client/NodeAppearances.ts +22 -0
  119. package/src/client/NoteNode.ts +74 -0
  120. package/src/client/README.md +1 -0
  121. package/src/client/RootNode.ts +24 -0
  122. package/src/client/SelectNode.ts +9 -3
  123. package/src/client/StringNode.ts +9 -3
  124. package/src/client/SubtreeNode.ts +3 -0
  125. package/src/client/TextRange.ts +99 -2
  126. package/src/client/constants.ts +10 -0
  127. package/src/client/hierarchy.ts +30 -14
  128. package/src/client/node-types.ts +8 -1
  129. package/src/client/{RepeatRangeNode.ts → repeat/BaseRepeatRangeNode.ts} +20 -17
  130. package/src/client/{RepeatInstanceNode.ts → repeat/RepeatInstanceNode.ts} +13 -7
  131. package/src/client/repeat/RepeatRangeControlledNode.ts +20 -0
  132. package/src/client/repeat/RepeatRangeUncontrolledNode.ts +21 -0
  133. package/src/client/validation.ts +199 -0
  134. package/src/expression/DependentExpression.ts +45 -27
  135. package/src/index.ts +15 -8
  136. package/src/instance/Group.ts +24 -13
  137. package/src/instance/ModelValue.ts +104 -0
  138. package/src/instance/Note.ts +142 -0
  139. package/src/instance/Root.ts +29 -67
  140. package/src/instance/SelectField.ts +35 -13
  141. package/src/instance/StringField.ts +40 -13
  142. package/src/instance/Subtree.ts +19 -10
  143. package/src/instance/abstract/DescendantNode.ts +50 -49
  144. package/src/instance/abstract/InstanceNode.ts +89 -92
  145. package/src/instance/children.ts +47 -10
  146. package/src/instance/hierarchy.ts +21 -2
  147. package/src/instance/index.ts +1 -1
  148. package/src/instance/internal-api/EvaluationContext.ts +5 -6
  149. package/src/instance/internal-api/ValidationContext.ts +23 -0
  150. package/src/instance/internal-api/ValueContext.ts +2 -2
  151. package/src/instance/repeat/BaseRepeatRange.ts +347 -0
  152. package/src/instance/{RepeatInstance.ts → repeat/RepeatInstance.ts} +85 -36
  153. package/src/instance/repeat/RepeatRangeControlled.ts +82 -0
  154. package/src/instance/repeat/RepeatRangeUncontrolled.ts +67 -0
  155. package/src/instance/text/TextRange.ts +10 -4
  156. package/src/lib/TokenListParser.ts +156 -0
  157. package/src/lib/dom/query.ts +13 -0
  158. package/src/lib/reactivity/createChildrenState.ts +51 -6
  159. package/src/lib/reactivity/createComputedExpression.ts +23 -25
  160. package/src/lib/reactivity/createNoteReadonlyThunk.ts +33 -0
  161. package/src/lib/reactivity/createSelectItems.ts +25 -20
  162. package/src/lib/reactivity/createValueState.ts +6 -6
  163. package/src/lib/reactivity/materializeCurrentStateChildren.ts +3 -1
  164. package/src/lib/reactivity/node-state/createSharedNodeState.ts +1 -1
  165. package/src/lib/reactivity/text/createFieldHint.ts +9 -7
  166. package/src/lib/reactivity/text/createNodeLabel.ts +7 -5
  167. package/src/lib/reactivity/text/createNoteText.ts +72 -0
  168. package/src/lib/reactivity/text/createTextRange.ts +17 -90
  169. package/src/lib/reactivity/validation/createAggregatedViolations.ts +70 -0
  170. package/src/lib/reactivity/validation/createValidation.ts +196 -0
  171. package/src/model/BindComputation.ts +0 -4
  172. package/src/model/BindDefinition.ts +8 -6
  173. package/src/model/BindElement.ts +1 -0
  174. package/src/model/DescendentNodeDefinition.ts +1 -2
  175. package/src/model/{ValueNodeDefinition.ts → LeafNodeDefinition.ts} +5 -6
  176. package/src/model/ModelBindMap.ts +4 -0
  177. package/src/model/ModelDefinition.ts +1 -1
  178. package/src/model/NodeDefinition.ts +21 -21
  179. package/src/model/RepeatInstanceDefinition.ts +8 -13
  180. package/src/model/RepeatRangeDefinition.ts +94 -0
  181. package/src/model/RepeatTemplateDefinition.ts +10 -15
  182. package/src/model/RootDefinition.ts +12 -14
  183. package/src/model/SubtreeDefinition.ts +3 -3
  184. package/src/parse/NoteNodeDefinition.ts +70 -0
  185. package/src/parse/TODO.md +3 -0
  186. package/src/parse/expression/RepeatCountControlExpression.ts +44 -0
  187. package/src/parse/text/HintDefinition.ts +25 -0
  188. package/src/parse/text/ItemLabelDefinition.ts +25 -0
  189. package/src/parse/text/ItemsetLabelDefinition.ts +44 -0
  190. package/src/parse/text/LabelDefinition.ts +61 -0
  191. package/src/parse/text/MessageDefinition.ts +49 -0
  192. package/src/parse/text/OutputChunkDefinition.ts +25 -0
  193. package/src/parse/text/ReferenceChunkDefinition.ts +14 -0
  194. package/src/parse/text/StaticTextChunkDefinition.ts +19 -0
  195. package/src/parse/text/TranslationChunkDefinition.ts +38 -0
  196. package/src/parse/text/abstract/TextChunkDefinition.ts +38 -0
  197. package/src/parse/text/abstract/TextElementDefinition.ts +71 -0
  198. package/src/parse/text/abstract/TextRangeDefinition.ts +70 -0
  199. package/src/parse/xpath/dependency-analysis.ts +105 -0
  200. package/src/parse/xpath/path-resolution.ts +475 -0
  201. package/src/parse/xpath/predicate-analysis.ts +61 -0
  202. package/src/parse/xpath/reference-parsing.ts +90 -0
  203. package/src/parse/xpath/semantic-analysis.ts +466 -0
  204. package/src/parse/xpath/syntax-traversal.ts +129 -0
  205. package/dist/body/RepeatDefinition.d.ts +0 -16
  206. package/dist/body/group/RepeatGroupDefinition.d.ts +0 -13
  207. package/dist/body/text/HintDefinition.d.ts +0 -11
  208. package/dist/body/text/LabelDefinition.d.ts +0 -20
  209. package/dist/body/text/TextElementDefinition.d.ts +0 -33
  210. package/dist/body/text/TextElementOutputPart.d.ts +0 -13
  211. package/dist/body/text/TextElementPart.d.ts +0 -13
  212. package/dist/body/text/TextElementReferencePart.d.ts +0 -7
  213. package/dist/body/text/TextElementStaticPart.d.ts +0 -7
  214. package/dist/instance/RepeatRange.d.ts +0 -80
  215. package/dist/lib/xpath/analysis.d.ts +0 -23
  216. package/dist/model/RepeatSequenceDefinition.d.ts +0 -20
  217. package/src/body/RepeatDefinition.ts +0 -54
  218. package/src/body/group/RepeatGroupDefinition.ts +0 -91
  219. package/src/body/text/HintDefinition.ts +0 -26
  220. package/src/body/text/LabelDefinition.ts +0 -54
  221. package/src/body/text/TextElementDefinition.ts +0 -97
  222. package/src/body/text/TextElementOutputPart.ts +0 -27
  223. package/src/body/text/TextElementPart.ts +0 -31
  224. package/src/body/text/TextElementReferencePart.ts +0 -21
  225. package/src/body/text/TextElementStaticPart.ts +0 -26
  226. package/src/instance/RepeatRange.ts +0 -214
  227. package/src/lib/xpath/analysis.ts +0 -241
  228. package/src/model/RepeatSequenceDefinition.ts +0 -53
@@ -1,14 +1,16 @@
1
1
  import { UpsertableMap } from '@getodk/common/lib/collections/UpsertableMap.ts';
2
- import type { XFormDOM } from '../../XFormDOM.ts';
3
2
  import type { XFormDefinition } from '../../XFormDefinition.ts';
4
- import { getLabelElement, getRepeatElement } from '../../lib/dom/query.ts';
3
+ import { getLabelElement } from '../../lib/dom/query.ts';
4
+ import { LabelDefinition } from '../../parse/text/LabelDefinition.ts';
5
+ import { parseNodesetReference } from '../../parse/xpath/reference-parsing.ts';
5
6
  import {
6
7
  BodyDefinition,
7
8
  type BodyElementDefinitionArray,
8
9
  type BodyElementParentContext,
9
10
  } from '../BodyDefinition.ts';
10
11
  import { BodyElementDefinition } from '../BodyElementDefinition.ts';
11
- import { LabelDefinition } from '../text/LabelDefinition.ts';
12
+ import type { StructureElementAppearanceDefinition } from '../appearance/structureElementAppearanceParser.ts';
13
+ import { structureElementAppearanceParser } from '../appearance/structureElementAppearanceParser.ts';
12
14
 
13
15
  /**
14
16
  * These type names are derived from **and expand upon** the language used in
@@ -23,10 +25,6 @@ import { LabelDefinition } from '../text/LabelDefinition.ts';
23
25
  * - `presentation-group` is a group with a `<label>` child; its usage here
24
26
  * differs from the spec language in that `presentation-group` does **not**
25
27
  * have a `ref`
26
- * - `repeat-group` is not mentioned by the spec; it is an extension of
27
- * `logical-group`, wherein its `ref` is the same as its immediate `<repeat>`
28
- * child's `nodeset` (usage of each attribute is normalized during
29
- * initialization, in {@link XFormDOM})
30
28
  * - `structural-group` is any `<group>` element which does not satisfy any of
31
29
  * the other usage scenarios; this isn't exactly the terminology used, but is
32
30
  * the most closely fitting name for the concept where the other sceanarios
@@ -34,20 +32,17 @@ import { LabelDefinition } from '../text/LabelDefinition.ts';
34
32
  *
35
33
  * A more succinct decision tree:
36
34
  *
37
- * - `<group ref="$ref"><repeat nodeset="$ref">` -> `repeat-group`, else
38
35
  * - `<group ref="$ref">` -> `logical-group`, else
39
36
  * - `<group><label>` -> `presentation-group`, else
40
37
  * - `<group>` -> `structural-group`
41
38
  */
42
- export type GroupType =
43
- | 'logical-group'
44
- | 'presentation-group'
45
- | 'repeat-group'
46
- | 'structural-group';
39
+ export type GroupType = 'logical-group' | 'presentation-group' | 'structural-group';
47
40
 
48
41
  export abstract class BaseGroupDefinition<
49
42
  Type extends GroupType,
50
43
  > extends BodyElementDefinition<Type> {
44
+ // TODO: does this really accomplish anything? It seems highly unlikely it
45
+ // has enough performance benefit to outweigh its memory and lookup costs.
51
46
  private static groupTypes = new UpsertableMap<Element, GroupType | null>();
52
47
 
53
48
  protected static getGroupType(localName: string, element: Element): GroupType | null {
@@ -56,20 +51,8 @@ export abstract class BaseGroupDefinition<
56
51
  return null;
57
52
  }
58
53
 
59
- const ref = element.getAttribute('ref');
60
-
61
- if (ref != null) {
62
- const repeat = getRepeatElement(element);
63
-
64
- if (repeat == null) {
65
- return 'logical-group';
66
- }
67
-
68
- if (repeat.getAttribute('nodeset') === ref) {
69
- return 'repeat-group';
70
- }
71
-
72
- throw new Error('Unexpected <repeat> child of unrelated <group>');
54
+ if (element.hasAttribute('ref')) {
55
+ return 'logical-group';
73
56
  }
74
57
 
75
58
  const label = getLabelElement(element);
@@ -87,6 +70,7 @@ export abstract class BaseGroupDefinition<
87
70
  readonly children: BodyElementDefinitionArray;
88
71
 
89
72
  override readonly reference: string | null;
73
+ readonly appearances: StructureElementAppearanceDefinition;
90
74
  override readonly label: LabelDefinition | null;
91
75
 
92
76
  constructor(
@@ -98,7 +82,8 @@ export abstract class BaseGroupDefinition<
98
82
  super(form, parent, element);
99
83
 
100
84
  this.children = children ?? this.getChildren(element);
101
- this.reference = element.getAttribute('ref');
85
+ this.reference = parseNodesetReference(parent, element, 'ref');
86
+ this.appearances = structureElementAppearanceParser.parseFrom(element, 'appearance');
102
87
  this.label = LabelDefinition.forGroup(form, this);
103
88
  }
104
89
 
@@ -107,31 +92,9 @@ export abstract class BaseGroupDefinition<
107
92
  const children = Array.from(element.children).filter((child) => {
108
93
  const childName = child.localName;
109
94
 
110
- return childName !== 'label' && childName !== 'repeat';
95
+ return childName !== 'label';
111
96
  });
112
97
 
113
98
  return BodyDefinition.getChildElementDefinitions(form, this, element, children);
114
99
  }
115
100
  }
116
-
117
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
- export const repeatGroup = <T extends BaseGroupDefinition<any>>(
119
- groupDefinition: T
120
- ): Extract<T, BaseGroupDefinition<'repeat-group'>> | null => {
121
- if (groupDefinition.type === 'repeat-group') {
122
- return groupDefinition as Extract<T, BaseGroupDefinition<'repeat-group'>>;
123
- }
124
-
125
- return null;
126
- };
127
-
128
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
129
- export const nonRepeatGroup = <T extends BaseGroupDefinition<any>>(
130
- groupDefinition: T
131
- ): Exclude<T, BaseGroupDefinition<'repeat-group'>> | null => {
132
- if (groupDefinition.type === 'repeat-group') {
133
- return null;
134
- }
135
-
136
- return groupDefinition as Exclude<T, BaseGroupDefinition<'repeat-group'>>;
137
- };
@@ -1,6 +1,6 @@
1
1
  import type { XFormDefinition } from '../../XFormDefinition.ts';
2
+ import { LabelDefinition } from '../../parse/text/LabelDefinition.ts';
2
3
  import type { BodyElementParentContext } from '../BodyDefinition.ts';
3
- import { LabelDefinition } from '../text/LabelDefinition.ts';
4
4
  import { BaseGroupDefinition } from './BaseGroupDefinition.ts';
5
5
 
6
6
  export class PresentationGroupDefinition extends BaseGroupDefinition<'presentation-group'> {
@@ -1,7 +1,14 @@
1
+ import type { TokenListParser } from '../lib/TokenListParser.ts';
1
2
  import type { AnyNodeDefinition } from '../model/NodeDefinition.ts';
2
- import type { InstanceNodeType } from './node-types.js';
3
+ import type { NodeAppearances } from './NodeAppearances.ts';
3
4
  import type { OpaqueReactiveObjectFactory } from './OpaqueReactiveObjectFactory.ts';
4
5
  import type { TextRange } from './TextRange.ts';
6
+ import type { InstanceNodeType } from './node-types.ts';
7
+ import type {
8
+ AncestorNodeValidationState,
9
+ LeafNodeValidationState,
10
+ NodeValidationState,
11
+ } from './validation.ts';
5
12
 
6
13
  export interface BaseNodeState {
7
14
  /**
@@ -41,11 +48,17 @@ export interface BaseNodeState {
41
48
  */
42
49
  get relevant(): boolean;
43
50
 
44
- // Note: according to spec, `required` is NOT inherited from ancestor nodes.
45
- // What this means for a `required` state on subtree nodes is an open
46
- // question. It was also raised on the first engine-internals iteration, and I
47
- // could have sworn it was discussed in that PR, but finding any record of
48
- // this discussion has proven elusive.
51
+ /**
52
+ * Specifies whether the node must have a non-blank value to be valid (see
53
+ * {@link value} for details).
54
+ *
55
+ * @see {@link https://getodk.github.io/xforms-spec/#bind-attributes}
56
+ *
57
+ * @default false
58
+ *
59
+ * @todo What is the expected behavior of `required` expressions defined for
60
+ * non-leaf/value nodes?
61
+ */
49
62
  get required(): boolean;
50
63
 
51
64
  /**
@@ -104,6 +117,14 @@ export interface BaseNodeState {
104
117
  *
105
118
  * Parent nodes, i.e. nodes which can contain {@link children}, do not store a
106
119
  * value state. For those nodes, their value state should always be `null`.
120
+ *
121
+ * A node's value is considered "blank" when its primary instance state is an
122
+ * empty string, and it is considered "non-blank" otherwise. The engine may
123
+ * represent node values according to aspects of the node's definition (such
124
+ * as its defined data type, its associated control type if any). The node's
125
+ * value being blank or non-blank may contribute to satisfying conditions of
126
+ * the node's validity ({@link constraint}, {@link required}). Otherwise, it
127
+ * is an internal engine consideration.
107
128
  */
108
129
  get value(): unknown;
109
130
  }
@@ -126,6 +147,12 @@ export interface BaseNode {
126
147
  */
127
148
  readonly nodeId: FormNodeID;
128
149
 
150
+ /**
151
+ * @see {@link TokenListParser} for details.
152
+ */
153
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
154
+ readonly appearances: NodeAppearances<any> | null;
155
+
129
156
  /**
130
157
  * Each node has a definition which specifies aspects of the node defined in
131
158
  * the form. These aspects include (but are not limited to) the node's data
@@ -173,8 +200,55 @@ export interface BaseNode {
173
200
  readonly parent: BaseNode | null;
174
201
 
175
202
  /**
176
- * Each node provides a discrete object representing the stateful aspects of
177
- * that node which will change over time. When a client provides a {@link OpaqueReactiveObjectFactory}
203
+ * Each node provides a discrete object representing the stateful aspects\* of
204
+ * that node which will change over time. When a client provides a
205
+ * {@link OpaqueReactiveObjectFactory}, the engine will update the properties
206
+ * of this object as their respective states change, so a client can implement
207
+ * reactive updates that respond to changes as they occur.
208
+ *
209
+ * \* This includes state which is either client-/user-mutable, or state which
210
+ * is computed based on the core XForms computation model. Each node also
211
+ * exposes {@link validationState}, which reflects the validity of the
212
+ * node, or its descendants.
178
213
  */
179
214
  readonly currentState: BaseNodeState;
215
+
216
+ /**
217
+ * Represents the validation state of a the node itself, or its descendants.
218
+ *
219
+ * @see {@link AncestorNodeValidationState} and
220
+ * {@link LeafNodeValidationState} for additional details.
221
+ *
222
+ * While filling a form (i.e. prior to submission), validation state can be
223
+ * viewed as computed metadata about the form state. The validation conditions
224
+ * and their violation messages produced by a node _may be computed on
225
+ * demand_. Clients should assume:
226
+ *
227
+ * 1. Validation state **will be current** when directly read by the client.
228
+ * Accessing validation state _may_ invoke engine computation of that state
229
+ * _at that time_.
230
+ *
231
+ * It **may** also be pre-computed by the engine so that direct reads are
232
+ * less computationally expensive, but such optimizations cannot be
233
+ * guaranteed by the engine at this time.
234
+ *
235
+ * 2. For clients providing an {@link OpaqueReactiveObjectFactory}, accessing
236
+ * validation state within a reactive context **will produce updates** to
237
+ * the validation state, as long as the client retains a subscription to
238
+ * that state.
239
+ *
240
+ * If it is possible to detect interruption of such client- reactive
241
+ * subscriptions, the engine _may defer computations_ until subsequent
242
+ * client read/re-subscription, in order to reduce unnecessary
243
+ * computational overhead. Again, such optimizations cannot be guaranteed
244
+ * by the engine at this time.
245
+ *
246
+ * @todo it's easier to conceive a reliable, general solution to optimizing
247
+ * the direct read case, than it is for the client-reactive case (largely
248
+ * because our solution for client reactivity is intentionally opaque). If it
249
+ * turns out that such optimizations are crucial for overall usability, the
250
+ * client-reactive case may best be served by additional APIs for reactive
251
+ * clients to explicitly pause and resume recomputation.
252
+ */
253
+ readonly validationState: NodeValidationState;
180
254
  }
@@ -1,8 +1,10 @@
1
- import type { NonRepeatGroupElementDefinition } from '../body/BodyDefinition.ts';
1
+ import type { AnyGroupElementDefinition } from '../body/BodyDefinition.ts';
2
2
  import type { SubtreeDefinition } from '../model/SubtreeDefinition.ts';
3
3
  import type { BaseNode, BaseNodeState } from './BaseNode.ts';
4
+ import type { NodeAppearances } from './NodeAppearances.ts';
4
5
  import type { RootNode } from './RootNode.ts';
5
6
  import type { GeneralChildNode, GeneralParentNode } from './hierarchy.ts';
7
+ import type { AncestorNodeValidationState } from './validation.ts';
6
8
 
7
9
  export interface GroupNodeState extends BaseNodeState {
8
10
  get hint(): null;
@@ -14,9 +16,11 @@ export interface GroupNodeState extends BaseNodeState {
14
16
  // TODO: as with `SubtreeNode`'s `SubtreeDefinition`, there is a naming
15
17
  // inconsistency emerging here.
16
18
  export interface GroupDefinition extends SubtreeDefinition {
17
- readonly bodyElement: NonRepeatGroupElementDefinition;
19
+ readonly bodyElement: AnyGroupElementDefinition;
18
20
  }
19
21
 
22
+ export type GroupNodeAppearances = NodeAppearances<GroupDefinition>;
23
+
20
24
  /**
21
25
  * A node corresponding to an XForms `<group>`.
22
26
  */
@@ -26,8 +30,10 @@ export interface GroupDefinition extends SubtreeDefinition {
26
30
  // for context.
27
31
  export interface GroupNode extends BaseNode {
28
32
  readonly nodeType: 'group';
33
+ readonly appearances: GroupNodeAppearances;
29
34
  readonly definition: GroupDefinition;
30
35
  readonly root: RootNode;
31
36
  readonly parent: GeneralParentNode;
32
37
  readonly currentState: GroupNodeState;
38
+ readonly validationState: AncestorNodeValidationState;
33
39
  }
@@ -0,0 +1,40 @@
1
+ import type { LeafNodeDefinition } from '../model/LeafNodeDefinition.ts';
2
+ import type { BaseNode, BaseNodeState } from './BaseNode.ts';
3
+ import type { GeneralParentNode } from './hierarchy.ts';
4
+ import type { RootNode } from './RootNode.ts';
5
+ import type { LeafNodeValidationState } from './validation.ts';
6
+
7
+ export interface ModelValueNodeState extends BaseNodeState {
8
+ get label(): null;
9
+ get hint(): null;
10
+ get children(): null;
11
+ get valueOptions(): null;
12
+
13
+ /**
14
+ * Reflects the current value of a {@link ModelValueNode}. This value may be
15
+ * populated when a form is loaded, and it may be updated by certain
16
+ * computations defined by the form.
17
+ */
18
+ get value(): string;
19
+ }
20
+
21
+ export interface ModelValueDefinition extends LeafNodeDefinition {
22
+ readonly bodyElement: null;
23
+ }
24
+
25
+ /**
26
+ * A node which is:
27
+ *
28
+ * - model-only (i.e. it has no corresponding body element)
29
+ * - a leaf/value node (i.e. it has no element children; it may be defined in
30
+ * the form's `<model>` as either an {@link Element} or {@link Attr})
31
+ */
32
+ export interface ModelValueNode extends BaseNode {
33
+ readonly nodeType: 'model-value';
34
+ readonly appearances: null;
35
+ readonly definition: ModelValueDefinition;
36
+ readonly root: RootNode;
37
+ readonly parent: GeneralParentNode;
38
+ readonly currentState: ModelValueNodeState;
39
+ readonly validationState: LeafNodeValidationState;
40
+ }
@@ -0,0 +1,22 @@
1
+ import type { ParsedTokenList } from '../lib/TokenListParser.ts';
2
+ import type { NodeDefinition } from '../model/NodeDefinition.ts';
3
+
4
+ /**
5
+ * - Provides a means to distinguish between internal and client-facing names
6
+ * for the same {@link ParsedTokenList} types.
7
+ *
8
+ * - Anticipates some iteration on both parsed ("definition") types and
9
+ * client-facing node types, which may not happen in tandem.
10
+ */
11
+ // prettier-ignore
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ export type NodeAppearances<Definition extends NodeDefinition<any>> =
14
+ Definition extends {
15
+ readonly bodyElement: {
16
+ readonly appearances:
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ infer Appearances extends ParsedTokenList<any>
19
+ };
20
+ }
21
+ ? Appearances
22
+ : null;
@@ -0,0 +1,74 @@
1
+ import type { InputDefinition } from '../body/control/InputDefinition.ts';
2
+ import type { LeafNodeDefinition } from '../model/LeafNodeDefinition.ts';
3
+ import type { BaseNode, BaseNodeState } from './BaseNode.ts';
4
+ import type { GeneralParentNode } from './hierarchy.ts';
5
+ import type { NodeAppearances } from './NodeAppearances.ts';
6
+ import type { RootNode } from './RootNode.ts';
7
+ import type { TextRange } from './TextRange.ts';
8
+ import type { LeafNodeValidationState } from './validation.ts';
9
+
10
+ export interface NoteNodeState extends BaseNodeState {
11
+ /**
12
+ * Note-specific specialization: a note will always have a non-null value in
13
+ * at least one of:
14
+ *
15
+ * - {@link label}
16
+ * - {@link hint}
17
+ *
18
+ * This is an alias to whichever is present, with precedent to {@link label}
19
+ * if both are present.
20
+ */
21
+ // ^ @todo While it's possible to convey this at the type level, the resulting
22
+ // types would be far more complex than this, which is not ideal especially at
23
+ // the package (client) boundary. This alias is a concession that the simpler
24
+ // type is preferred, but that it is still important to convey to clients
25
+ // that at least one form-defined text value will always be available. Note:
26
+ // at least for a first pass, we won't guarantee that the resulting text is
27
+ // non-empty. (We'd probably need to accept an engine fallback to make that
28
+ // guarantee; otherwise we'd need to error on invalid state, potentially at
29
+ // arbitrary points in time.)
30
+ //
31
+ // eslint-disable-next-line @typescript-eslint/sort-type-constituents
32
+ get noteText(): NonNullable<this['label'] | this['hint']>;
33
+
34
+ /**
35
+ * A note will **always** be `readonly`.
36
+ */
37
+ readonly readonly: true;
38
+
39
+ get label(): TextRange<'label', 'form'> | null;
40
+ get hint(): TextRange<'hint', 'form'> | null;
41
+ get children(): null;
42
+ get valueOptions(): null;
43
+
44
+ /**
45
+ * Reflects the readonly value of a {@link NoteNode}, or `null` if blank.
46
+ */
47
+ // Note that being nullable is an intentional deviation from most other value
48
+ // node types, specifically to make a clear distinction between blank and
49
+ // non-blank values (as that has been a primary driver for prioritizing note
50
+ // functionality).
51
+ get value(): string | null;
52
+ }
53
+
54
+ export interface NoteDefinition extends LeafNodeDefinition {
55
+ readonly bodyElement: InputDefinition;
56
+ }
57
+
58
+ export type NoteNodeAppearances = NodeAppearances<NoteDefinition>;
59
+
60
+ /**
61
+ * A node which is:
62
+ *
63
+ * - associated with an input, with at least one text element (label or hint)
64
+ * - guaranteed to be {@link NoteNodeState.readonly | readonly}
65
+ */
66
+ export interface NoteNode extends BaseNode {
67
+ readonly nodeType: 'note';
68
+ readonly appearances: NoteNodeAppearances;
69
+ readonly definition: NoteDefinition;
70
+ readonly root: RootNode;
71
+ readonly parent: GeneralParentNode;
72
+ readonly currentState: NoteNodeState;
73
+ readonly validationState: LeafNodeValidationState;
74
+ }
@@ -20,6 +20,7 @@ The interface is designed to:
20
20
  - Facilitate loading any of a form's externally referenced resources, by means of a client-provided generic resource accessor[^2]
21
21
 
22
22
  [^1]: This factory **may be** reactive, and for many clients that is the anticipated usage. But no assumptions are made by the engine about reactivity or any other implementation details beyond the factory's type definition.
23
+
23
24
  [^2]: This accessor **may** access networked resources, and for many clients that is the anticipated usage. But no assumptions are made by the engine about the provenance of any resources it requests beyond the accessor's type definition.
24
25
 
25
26
  ### Non-goals
@@ -1,7 +1,9 @@
1
+ import type { BodyClassList } from '../body/BodyDefinition.ts';
1
2
  import type { RootDefinition } from '../model/RootDefinition.ts';
2
3
  import type { BaseNode, BaseNodeState } from './BaseNode.ts';
3
4
  import type { ActiveLanguage, FormLanguage, FormLanguages } from './FormLanguage.ts';
4
5
  import type { GeneralChildNode } from './hierarchy.ts';
6
+ import type { AncestorNodeValidationState } from './validation.ts';
5
7
 
6
8
  export interface RootNodeState extends BaseNodeState {
7
9
  /**
@@ -21,10 +23,32 @@ export interface RootNodeState extends BaseNodeState {
21
23
 
22
24
  export interface RootNode extends BaseNode {
23
25
  readonly nodeType: 'root';
26
+
27
+ /**
28
+ * @todo this along with {@link classes} is... awkward.
29
+ */
30
+ readonly appearances: null;
31
+
32
+ /**
33
+ * @todo This is another odd deviation in {@link RootNode}. Unlike
34
+ * {@link languages}, it doesn't feel particularly **essential**. While it
35
+ * would deviate from XForms spec terminology, it seems like it _might be
36
+ * reasonable_ to instead convey `<h:body class="...">` as
37
+ * {@link RootNode.appearances} in the client interface. They do have slightly
38
+ * different spec semantics (i.e. a body class can be anything, to trigger
39
+ * styling in a form UI). But the **most likely anticipated** use case in Web
40
+ * Forms would be the "pages" class, and perhaps "theme-grid". The former is
41
+ * definitely conceptually similar to a XForms `appearance` (albeit
42
+ * form-global, which is not a spec concept). The latter does as well, and we
43
+ * already anticipate applying that concept in non-form-global ways.
44
+ */
45
+ readonly classes: BodyClassList;
46
+
24
47
  readonly definition: RootDefinition;
25
48
  readonly root: RootNode;
26
49
  readonly parent: null;
27
50
  readonly currentState: RootNodeState;
51
+ readonly validationState: AncestorNodeValidationState;
28
52
 
29
53
  /**
30
54
  * @todo as with {@link RootNodeState.activeLanguage}, this is the most
@@ -1,14 +1,16 @@
1
1
  import type { AnySelectDefinition } from '../body/control/select/SelectDefinition.ts';
2
- import type { ValueNodeDefinition } from '../model/ValueNodeDefinition.ts';
2
+ import type { LeafNodeDefinition } from '../model/LeafNodeDefinition.ts';
3
3
  import type { BaseNode, BaseNodeState } from './BaseNode.ts';
4
+ import type { NodeAppearances } from './NodeAppearances.ts';
4
5
  import type { RootNode } from './RootNode.ts';
5
6
  import type { StringNode } from './StringNode.ts';
6
7
  import type { TextRange } from './TextRange.ts';
7
8
  import type { GeneralParentNode } from './hierarchy.ts';
9
+ import type { LeafNodeValidationState } from './validation.ts';
8
10
 
9
11
  export interface SelectItem {
10
12
  get value(): string;
11
- get label(): TextRange<'label'> | null;
13
+ get label(): TextRange<'item-label'> | null;
12
14
  }
13
15
 
14
16
  export interface SelectNodeState extends BaseNodeState {
@@ -34,16 +36,20 @@ export interface SelectNodeState extends BaseNodeState {
34
36
  get value(): readonly SelectItem[];
35
37
  }
36
38
 
37
- export interface SelectDefinition extends ValueNodeDefinition {
39
+ export interface SelectDefinition extends LeafNodeDefinition {
38
40
  readonly bodyElement: AnySelectDefinition;
39
41
  }
40
42
 
43
+ export type SelectNodeAppearances = NodeAppearances<SelectDefinition>;
44
+
41
45
  export interface SelectNode extends BaseNode {
42
46
  readonly nodeType: 'select';
47
+ readonly appearances: SelectNodeAppearances;
43
48
  readonly definition: SelectDefinition;
44
49
  readonly root: RootNode;
45
50
  readonly parent: GeneralParentNode;
46
51
  readonly currentState: SelectNodeState;
52
+ readonly validationState: LeafNodeValidationState;
47
53
 
48
54
  /**
49
55
  * For use by a client to update the selection of a select node where:
@@ -1,8 +1,10 @@
1
1
  import type { InputDefinition } from '../body/control/InputDefinition.ts';
2
- import type { ValueNodeDefinition } from '../model/ValueNodeDefinition.ts';
2
+ import type { LeafNodeDefinition } from '../model/LeafNodeDefinition.ts';
3
3
  import type { BaseNode, BaseNodeState } from './BaseNode.ts';
4
+ import type { NodeAppearances } from './NodeAppearances.ts';
4
5
  import type { RootNode } from './RootNode.ts';
5
6
  import type { GeneralParentNode } from './hierarchy.ts';
7
+ import type { LeafNodeValidationState } from './validation.ts';
6
8
 
7
9
  export interface StringNodeState extends BaseNodeState {
8
10
  get children(): null;
@@ -17,10 +19,12 @@ export interface StringNodeState extends BaseNodeState {
17
19
  get value(): string;
18
20
  }
19
21
 
20
- export interface StringDefinition extends ValueNodeDefinition {
21
- readonly bodyElement: InputDefinition | null;
22
+ export interface StringDefinition extends LeafNodeDefinition {
23
+ readonly bodyElement: InputDefinition;
22
24
  }
23
25
 
26
+ export type StringNodeAppearances = NodeAppearances<StringDefinition>;
27
+
24
28
  /**
25
29
  * A node which can be assigned a string/text value. A string node **MAY**
26
30
  * correspond to form field defined as an XForms `<input>`, which a user-facing
@@ -30,10 +34,12 @@ export interface StringDefinition extends ValueNodeDefinition {
30
34
  */
31
35
  export interface StringNode extends BaseNode {
32
36
  readonly nodeType: 'string';
37
+ readonly appearances: StringNodeAppearances;
33
38
  readonly definition: StringDefinition;
34
39
  readonly root: RootNode;
35
40
  readonly parent: GeneralParentNode;
36
41
  readonly currentState: StringNodeState;
42
+ readonly validationState: LeafNodeValidationState;
37
43
 
38
44
  /**
39
45
  * For use by a client to update the value of a string node.
@@ -2,6 +2,7 @@ import type { SubtreeDefinition as BaseSubtreeDefinition } from '../model/Subtre
2
2
  import type { BaseNode, BaseNodeState } from './BaseNode.ts';
3
3
  import type { RootNode } from './RootNode.ts';
4
4
  import type { GeneralChildNode, GeneralParentNode } from './hierarchy.ts';
5
+ import type { AncestorNodeValidationState } from './validation.ts';
5
6
 
6
7
  export interface SubtreeNodeState extends BaseNodeState {
7
8
  get label(): null;
@@ -50,8 +51,10 @@ export interface SubtreeDefinition extends BaseSubtreeDefinition {
50
51
  // TODO: directly test presentation of non-group subtree children/descendants
51
52
  export interface SubtreeNode extends BaseNode {
52
53
  readonly nodeType: 'subtree';
54
+ readonly appearances: null;
53
55
  readonly definition: SubtreeDefinition;
54
56
  readonly root: RootNode;
55
57
  readonly parent: GeneralParentNode;
56
58
  readonly currentState: SubtreeNodeState;
59
+ readonly validationState: AncestorNodeValidationState;
57
60
  }