@getodk/xforms-engine 0.5.0 → 0.6.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 (232) hide show
  1. package/README.md +1 -1
  2. package/dist/client/BaseNode.d.ts +4 -0
  3. package/dist/client/BaseValueNode.d.ts +1 -1
  4. package/dist/client/GroupNode.d.ts +1 -0
  5. package/dist/client/InputNode.d.ts +32 -3
  6. package/dist/client/ModelValueNode.d.ts +1 -0
  7. package/dist/client/NoteNode.d.ts +24 -7
  8. package/dist/client/RangeNode.d.ts +36 -0
  9. package/dist/client/RankNode.d.ts +46 -0
  10. package/dist/client/RootNode.d.ts +6 -3
  11. package/dist/client/SelectNode.d.ts +47 -25
  12. package/dist/client/SubtreeNode.d.ts +1 -0
  13. package/dist/client/TriggerNode.d.ts +10 -6
  14. package/dist/client/hierarchy.d.ts +5 -5
  15. package/dist/client/node-types.d.ts +2 -2
  16. package/dist/client/unsupported/UnsupportedControlNode.d.ts +1 -3
  17. package/dist/error/RankMissingValueError.d.ts +3 -0
  18. package/dist/error/RankValueTypeError.d.ts +6 -0
  19. package/dist/error/SelectValueTypeError.d.ts +15 -0
  20. package/dist/error/XFormsSpecViolationError.d.ts +2 -0
  21. package/dist/index.d.ts +2 -3
  22. package/dist/index.js +5604 -4666
  23. package/dist/index.js.map +1 -1
  24. package/dist/instance/Group.d.ts +1 -0
  25. package/dist/instance/InputControl.d.ts +5 -3
  26. package/dist/instance/ModelValue.d.ts +2 -0
  27. package/dist/instance/Note.d.ts +13 -25
  28. package/dist/instance/PrimaryInstance.d.ts +1 -0
  29. package/dist/instance/RangeControl.d.ts +34 -0
  30. package/dist/instance/RankControl.d.ts +40 -0
  31. package/dist/instance/Root.d.ts +1 -0
  32. package/dist/instance/SelectControl.d.ts +66 -0
  33. package/dist/instance/Subtree.d.ts +1 -0
  34. package/dist/instance/TriggerControl.d.ts +9 -22
  35. package/dist/instance/abstract/DescendantNode.d.ts +1 -2
  36. package/dist/instance/abstract/InstanceNode.d.ts +3 -1
  37. package/dist/instance/abstract/UnsupportedControl.d.ts +1 -0
  38. package/dist/instance/abstract/ValueNode.d.ts +0 -1
  39. package/dist/instance/hierarchy.d.ts +9 -9
  40. package/dist/instance/internal-api/InstanceValueContext.d.ts +2 -0
  41. package/dist/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.d.ts +2 -1
  42. package/dist/instance/internal-api/submission/ClientReactiveSubmittableParentNode.d.ts +2 -1
  43. package/dist/instance/internal-api/submission/ClientReactiveSubmittableValueNode.d.ts +2 -1
  44. package/dist/instance/repeat/BaseRepeatRange.d.ts +1 -0
  45. package/dist/instance/repeat/RepeatInstance.d.ts +1 -0
  46. package/dist/integration/xpath/adapter/names.d.ts +1 -11
  47. package/dist/integration/xpath/adapter/traversal.d.ts +10 -9
  48. package/dist/integration/xpath/static-dom/StaticAttribute.d.ts +10 -3
  49. package/dist/integration/xpath/static-dom/StaticDocument.d.ts +0 -1
  50. package/dist/integration/xpath/static-dom/StaticElement.d.ts +12 -4
  51. package/dist/lib/client-reactivity/submission/createRootSubmissionState.d.ts +3 -0
  52. package/dist/lib/codecs/Geopoint/Geopoint.d.ts +48 -0
  53. package/dist/lib/codecs/Geopoint/GeopointValueCodec.d.ts +5 -0
  54. package/dist/lib/codecs/NoteCodec.d.ts +8 -0
  55. package/dist/lib/codecs/RangeCodec.d.ts +8 -0
  56. package/dist/lib/codecs/TriggerCodec.d.ts +7 -0
  57. package/dist/lib/codecs/ValueArrayCodec.d.ts +11 -0
  58. package/dist/lib/codecs/ValueCodec.d.ts +2 -2
  59. package/dist/lib/codecs/getNoteCodec.d.ts +3 -0
  60. package/dist/lib/codecs/getSelectCodec.d.ts +5 -0
  61. package/dist/lib/codecs/getSharedValueCodec.d.ts +3 -2
  62. package/dist/lib/codecs/items/BaseItemCodec.d.ts +9 -0
  63. package/dist/lib/codecs/items/MultipleValueItemCodec.d.ts +14 -0
  64. package/dist/lib/codecs/items/SingleValueItemCodec.d.ts +24 -0
  65. package/dist/lib/dom/query.d.ts +1 -2
  66. package/dist/lib/names/NamespaceDeclaration.d.ts +45 -0
  67. package/dist/lib/names/NamespaceDeclarationMap.d.ts +137 -0
  68. package/dist/lib/names/NamespaceURL.d.ts +30 -0
  69. package/dist/lib/names/QualifiedName.d.ts +113 -0
  70. package/dist/lib/number-parsers.d.ts +2 -0
  71. package/dist/lib/reactivity/createItemCollection.d.ts +21 -0
  72. package/dist/lib/xml-serialization.d.ts +11 -2
  73. package/dist/parse/XFormDOM.d.ts +1 -1
  74. package/dist/parse/body/BodyDefinition.d.ts +2 -2
  75. package/dist/parse/body/appearance/rangeAppearanceParser.d.ts +3 -0
  76. package/dist/parse/body/control/InputControlDefinition.d.ts +3 -0
  77. package/dist/parse/body/control/ItemDefinition.d.ts +14 -0
  78. package/dist/parse/body/control/ItemsetDefinition.d.ts +18 -0
  79. package/dist/parse/body/control/RangeControlDefinition.d.ts +31 -2
  80. package/dist/parse/body/control/RankControlDefinition.d.ts +7 -3
  81. package/dist/parse/body/control/{select/SelectDefinition.d.ts → SelectControlDefinition.d.ts} +9 -9
  82. package/dist/parse/expression/ItemsetNodesetExpression.d.ts +1 -1
  83. package/dist/parse/expression/ItemsetValueExpression.d.ts +1 -1
  84. package/dist/parse/model/BindDefinition.d.ts +3 -1
  85. package/dist/parse/model/BindPreloadDefinition.d.ts +42 -0
  86. package/dist/parse/model/DescendentNodeDefinition.d.ts +4 -13
  87. package/dist/parse/model/ItextTranslation/ItextTranslationRootDefinition.d.ts +2 -1
  88. package/dist/parse/model/LeafNodeDefinition.d.ts +7 -4
  89. package/dist/parse/model/ModelBindMap.d.ts +1 -1
  90. package/dist/parse/model/NodeDefinition.d.ts +16 -19
  91. package/dist/parse/model/NoteNodeDefinition.d.ts +6 -5
  92. package/dist/parse/model/RangeNodeDefinition.d.ts +41 -0
  93. package/dist/parse/model/RepeatInstanceDefinition.d.ts +7 -4
  94. package/dist/parse/model/RepeatRangeDefinition.d.ts +7 -4
  95. package/dist/parse/model/RepeatTemplateDefinition.d.ts +7 -4
  96. package/dist/parse/model/RootAttributeDefinition.d.ts +24 -0
  97. package/dist/parse/model/RootAttributeMap.d.ts +23 -0
  98. package/dist/parse/model/RootDefinition.d.ts +9 -7
  99. package/dist/parse/model/SubtreeDefinition.d.ts +7 -4
  100. package/dist/parse/shared/parseStaticDocumentFromDOMSubtree.d.ts +2 -3
  101. package/dist/parse/text/ItemLabelDefinition.d.ts +1 -1
  102. package/dist/parse/text/ItemsetLabelDefinition.d.ts +2 -2
  103. package/dist/parse/text/abstract/TextElementDefinition.d.ts +1 -1
  104. package/dist/parse/xpath/semantic-analysis.d.ts +1 -3
  105. package/dist/solid.js +5603 -4665
  106. package/dist/solid.js.map +1 -1
  107. package/package.json +15 -12
  108. package/src/client/BaseNode.ts +5 -0
  109. package/src/client/BaseValueNode.ts +1 -1
  110. package/src/client/GroupNode.ts +1 -0
  111. package/src/client/InputNode.ts +38 -2
  112. package/src/client/ModelValueNode.ts +1 -0
  113. package/src/client/NoteNode.ts +43 -7
  114. package/src/client/RangeNode.ts +51 -0
  115. package/src/client/RankNode.ts +54 -0
  116. package/src/client/RootNode.ts +11 -5
  117. package/src/client/SelectNode.ts +53 -26
  118. package/src/client/SubtreeNode.ts +1 -0
  119. package/src/client/TriggerNode.ts +12 -6
  120. package/src/client/hierarchy.ts +7 -8
  121. package/src/client/node-types.ts +1 -1
  122. package/src/client/unsupported/UnsupportedControlNode.ts +2 -6
  123. package/src/error/RankMissingValueError.ts +5 -0
  124. package/src/error/RankValueTypeError.ts +13 -0
  125. package/src/error/SelectValueTypeError.ts +22 -0
  126. package/src/error/XFormsSpecViolationError.ts +1 -0
  127. package/src/index.ts +2 -12
  128. package/src/instance/Group.ts +1 -0
  129. package/src/instance/InputControl.ts +42 -2
  130. package/src/instance/ModelValue.ts +2 -0
  131. package/src/instance/Note.ts +34 -59
  132. package/src/instance/PrimaryInstance.ts +1 -0
  133. package/src/instance/RangeControl.ts +113 -0
  134. package/src/instance/RankControl.ts +199 -0
  135. package/src/instance/Root.ts +3 -2
  136. package/src/instance/SelectControl.ts +219 -0
  137. package/src/instance/Subtree.ts +1 -0
  138. package/src/instance/TriggerControl.ts +36 -75
  139. package/src/instance/abstract/DescendantNode.ts +1 -6
  140. package/src/instance/abstract/InstanceNode.ts +10 -2
  141. package/src/instance/abstract/UnsupportedControl.ts +1 -0
  142. package/src/instance/abstract/ValueNode.ts +3 -2
  143. package/src/instance/children.ts +71 -30
  144. package/src/instance/hierarchy.ts +21 -16
  145. package/src/instance/internal-api/InstanceValueContext.ts +2 -0
  146. package/src/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.ts +2 -1
  147. package/src/instance/internal-api/submission/ClientReactiveSubmittableParentNode.ts +2 -1
  148. package/src/instance/internal-api/submission/ClientReactiveSubmittableValueNode.ts +2 -1
  149. package/src/instance/repeat/BaseRepeatRange.ts +2 -0
  150. package/src/instance/repeat/RepeatInstance.ts +1 -0
  151. package/src/instance/resource.ts +4 -1
  152. package/src/integration/xpath/adapter/names.ts +66 -17
  153. package/src/integration/xpath/adapter/traversal.ts +10 -9
  154. package/src/integration/xpath/static-dom/StaticAttribute.ts +15 -7
  155. package/src/integration/xpath/static-dom/StaticDocument.ts +0 -2
  156. package/src/integration/xpath/static-dom/StaticElement.ts +21 -8
  157. package/src/lib/client-reactivity/submission/createLeafNodeSubmissionState.ts +1 -1
  158. package/src/lib/client-reactivity/submission/createParentNodeSubmissionState.ts +1 -1
  159. package/src/lib/client-reactivity/submission/createRootSubmissionState.ts +19 -0
  160. package/src/lib/client-reactivity/submission/createValueNodeSubmissionState.ts +2 -2
  161. package/src/lib/codecs/Geopoint/Geopoint.ts +150 -0
  162. package/src/lib/codecs/Geopoint/GeopointValueCodec.ts +20 -0
  163. package/src/lib/codecs/NoteCodec.ts +32 -0
  164. package/src/lib/codecs/RangeCodec.ts +65 -0
  165. package/src/lib/codecs/TriggerCodec.ts +64 -0
  166. package/src/lib/codecs/ValueArrayCodec.ts +42 -0
  167. package/src/lib/codecs/ValueCodec.ts +2 -2
  168. package/src/lib/codecs/getNoteCodec.ts +27 -0
  169. package/src/lib/codecs/getSelectCodec.ts +27 -0
  170. package/src/lib/codecs/getSharedValueCodec.ts +5 -3
  171. package/src/lib/codecs/items/BaseItemCodec.ts +20 -0
  172. package/src/lib/codecs/items/MultipleValueItemCodec.ts +28 -0
  173. package/src/lib/codecs/items/SingleValueItemCodec.ts +67 -0
  174. package/src/lib/dom/query.ts +1 -2
  175. package/src/lib/names/NamespaceDeclaration.ts +106 -0
  176. package/src/lib/names/NamespaceDeclarationMap.ts +228 -0
  177. package/src/lib/names/NamespaceURL.ts +44 -0
  178. package/src/lib/names/QualifiedName.ts +170 -0
  179. package/src/lib/number-parsers.ts +25 -0
  180. package/src/lib/reactivity/createInstanceValueState.ts +50 -0
  181. package/src/lib/reactivity/{createSelectItems.ts → createItemCollection.ts} +41 -36
  182. package/src/lib/xml-serialization.ts +76 -9
  183. package/src/parse/XFormDOM.ts +141 -21
  184. package/src/parse/XFormDefinition.ts +1 -4
  185. package/src/parse/body/BodyDefinition.ts +4 -4
  186. package/src/parse/body/appearance/rangeAppearanceParser.ts +11 -0
  187. package/src/parse/body/control/InputControlDefinition.ts +9 -0
  188. package/src/parse/body/control/{select/ItemDefinition.ts → ItemDefinition.ts} +8 -6
  189. package/src/parse/body/control/{select/ItemsetDefinition.ts → ItemsetDefinition.ts} +11 -9
  190. package/src/parse/body/control/RangeControlDefinition.ts +91 -6
  191. package/src/parse/body/control/RankControlDefinition.ts +25 -7
  192. package/src/parse/body/control/{select/SelectDefinition.ts → SelectControlDefinition.ts} +9 -9
  193. package/src/parse/expression/ItemsetNodesetExpression.ts +1 -1
  194. package/src/parse/expression/ItemsetValueExpression.ts +1 -1
  195. package/src/parse/model/BindDefinition.ts +4 -0
  196. package/src/parse/model/BindPreloadDefinition.ts +100 -0
  197. package/src/parse/model/DescendentNodeDefinition.ts +7 -25
  198. package/src/parse/model/ItextTranslation/ItextTranslationRootDefinition.ts +2 -1
  199. package/src/parse/model/LeafNodeDefinition.ts +11 -4
  200. package/src/parse/model/NodeDefinition.ts +24 -45
  201. package/src/parse/model/NoteNodeDefinition.ts +8 -7
  202. package/src/parse/model/RangeNodeDefinition.ts +118 -0
  203. package/src/parse/model/RepeatInstanceDefinition.ts +11 -7
  204. package/src/parse/model/RepeatRangeDefinition.ts +11 -7
  205. package/src/parse/model/RepeatTemplateDefinition.ts +11 -7
  206. package/src/parse/model/RootAttributeDefinition.ts +45 -0
  207. package/src/parse/model/RootAttributeMap.ts +44 -0
  208. package/src/parse/model/RootDefinition.ts +29 -28
  209. package/src/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.ts +1 -0
  210. package/src/parse/model/SubtreeDefinition.ts +12 -12
  211. package/src/parse/shared/parseStaticDocumentFromDOMSubtree.ts +3 -3
  212. package/src/parse/text/ItemLabelDefinition.ts +1 -1
  213. package/src/parse/text/ItemsetLabelDefinition.ts +2 -2
  214. package/src/parse/text/abstract/TextElementDefinition.ts +1 -1
  215. package/src/parse/xpath/semantic-analysis.ts +4 -3
  216. package/dist/client/unsupported/RangeNode.d.ts +0 -9
  217. package/dist/client/unsupported/RankNode.d.ts +0 -9
  218. package/dist/instance/SelectField.d.ts +0 -58
  219. package/dist/instance/unsupported/RangeControl.d.ts +0 -6
  220. package/dist/instance/unsupported/RankControl.d.ts +0 -6
  221. package/dist/integration/xpath/static-dom/StaticNamedNode.d.ts +0 -17
  222. package/dist/lib/reactivity/createSelectItems.d.ts +0 -16
  223. package/dist/parse/body/control/select/ItemDefinition.d.ts +0 -13
  224. package/dist/parse/body/control/select/ItemsetDefinition.d.ts +0 -17
  225. package/dist/parse/body/control/select/ItemsetNodesetContext.d.ts +0 -9
  226. package/src/client/unsupported/RangeNode.ts +0 -14
  227. package/src/client/unsupported/RankNode.ts +0 -14
  228. package/src/instance/SelectField.ts +0 -263
  229. package/src/instance/unsupported/RangeControl.ts +0 -9
  230. package/src/instance/unsupported/RankControl.ts +0 -9
  231. package/src/integration/xpath/static-dom/StaticNamedNode.ts +0 -45
  232. package/src/parse/body/control/select/ItemsetNodesetContext.ts +0 -21
@@ -1,26 +1,23 @@
1
1
  import type { Group } from './Group.ts';
2
2
  import type { AnyInputControl } from './InputControl.ts';
3
3
  import type { AnyModelValue } from './ModelValue.ts';
4
- import type { Note } from './Note.ts';
4
+ import type { AnyNote } from './Note.ts';
5
5
  import type { PrimaryInstance } from './PrimaryInstance.ts';
6
+ import type { AnyRangeControl } from './RangeControl.ts';
6
7
  import type { RepeatInstance } from './repeat/RepeatInstance.ts';
7
8
  import type { RepeatRangeControlled } from './repeat/RepeatRangeControlled.ts';
8
9
  import type { RepeatRangeUncontrolled } from './repeat/RepeatRangeUncontrolled.ts';
9
10
  import type { Root } from './Root.ts';
10
- import type { SelectField } from './SelectField.ts';
11
+ import type { SelectControl } from './SelectControl.ts';
11
12
  import type { Subtree } from './Subtree.ts';
12
13
  import type { TriggerControl } from './TriggerControl.ts';
13
- import type { RangeControl } from './unsupported/RangeControl.ts';
14
- import type { RankControl } from './unsupported/RankControl.ts';
14
+ import type { RankControl } from './RankControl.ts';
15
15
  import type { UploadControl } from './unsupported/UploadControl.ts';
16
16
 
17
17
  export type RepeatRange = RepeatRangeControlled | RepeatRangeUncontrolled;
18
18
 
19
19
  // prettier-ignore
20
- export type AnyUnsupportedControl =
21
- | RangeControl
22
- | RankControl
23
- | UploadControl;
20
+ export type AnyUnsupportedControl = UploadControl;
24
21
 
25
22
  // prettier-ignore
26
23
  export type AnyNode =
@@ -31,10 +28,12 @@ export type AnyNode =
31
28
  | Subtree
32
29
  | RepeatRange
33
30
  | RepeatInstance
34
- | Note
31
+ | AnyNote
35
32
  | AnyModelValue
36
33
  | AnyInputControl
37
- | SelectField
34
+ | AnyRangeControl
35
+ | RankControl
36
+ | SelectControl
38
37
  | TriggerControl
39
38
  | AnyUnsupportedControl;
40
39
 
@@ -65,9 +64,11 @@ export type AnyChildNode =
65
64
  | RepeatRange
66
65
  | RepeatInstance
67
66
  | AnyModelValue
68
- | Note
67
+ | AnyNote
69
68
  | AnyInputControl
70
- | SelectField
69
+ | AnyRangeControl
70
+ | RankControl
71
+ | SelectControl
71
72
  | TriggerControl
72
73
  | AnyUnsupportedControl;
73
74
 
@@ -78,9 +79,11 @@ export type GeneralChildNode =
78
79
  | Subtree
79
80
  | RepeatRange
80
81
  | AnyModelValue
81
- | Note
82
+ | AnyNote
82
83
  | AnyInputControl
83
- | SelectField
84
+ | AnyRangeControl
85
+ | RankControl
86
+ | SelectControl
84
87
  | TriggerControl
85
88
  | AnyUnsupportedControl;
86
89
 
@@ -88,8 +91,10 @@ export type GeneralChildNode =
88
91
  export type AnyValueNode =
89
92
  // eslint-disable-next-line @typescript-eslint/sort-type-constituents
90
93
  | AnyModelValue
91
- | Note
94
+ | AnyNote
92
95
  | AnyInputControl
93
- | SelectField
96
+ | AnyRangeControl
97
+ | RankControl
98
+ | SelectControl
94
99
  | TriggerControl
95
100
  | AnyUnsupportedControl;
@@ -1,10 +1,12 @@
1
1
  import type { ReactiveScope } from '../../lib/reactivity/scope.ts';
2
2
  import type { BindComputationExpression } from '../../parse/expression/BindComputationExpression.ts';
3
+ import type { AnyBindPreloadDefinition } from '../../parse/model/BindPreloadDefinition.ts';
3
4
  import type { EvaluationContext } from './EvaluationContext.ts';
4
5
 
5
6
  export type DecodeInstanceValue = (value: string) => string;
6
7
 
7
8
  interface InstanceValueContextDefinitionBind {
9
+ readonly preload: AnyBindPreloadDefinition | null;
8
10
  readonly calculate: BindComputationExpression<'calculate'> | null;
9
11
  readonly readonly: BindComputationExpression<'readonly'>;
10
12
  }
@@ -1,4 +1,5 @@
1
1
  import type { SubmissionState } from '../../../client/submission/SubmissionState.ts';
2
+ import type { QualifiedName } from '../../../lib/names/QualifiedName.ts';
2
3
  import type { EscapedXMLText } from '../../../lib/xml-serialization.ts';
3
4
  import type {
4
5
  ClientReactiveSubmittableChildNode,
@@ -13,7 +14,7 @@ interface ClientReactiveSubmittableLeafNodeCurrentState<RuntimeValue> {
13
14
  export type SerializedSubmissionValue = string;
14
15
 
15
16
  interface ClientReactiveSubmittableLeafNodeDefinition {
16
- readonly nodeName: string;
17
+ readonly qualifiedName: QualifiedName;
17
18
  }
18
19
 
19
20
  export interface ClientReactiveSubmittableLeafNode<RuntimeValue> {
@@ -1,4 +1,5 @@
1
1
  import type { SubmissionState } from '../../../client/submission/SubmissionState.ts';
2
+ import type { QualifiedName } from '../../../lib/names/QualifiedName.ts';
2
3
 
3
4
  export interface ClientReactiveSubmittableChildNode {
4
5
  readonly submissionState: SubmissionState;
@@ -12,7 +13,7 @@ interface ClientReactiveSubmittableParentNodeCurrentState<
12
13
  }
13
14
 
14
15
  export interface ClientReactiveSubmittableParentNodeDefinition {
15
- readonly nodeName: string;
16
+ readonly qualifiedName: QualifiedName;
16
17
  }
17
18
 
18
19
  export interface ClientReactiveSubmittableParentNode<
@@ -1,4 +1,5 @@
1
1
  import type { SubmissionState } from '../../../client/submission/SubmissionState.ts';
2
+ import type { QualifiedName } from '../../../lib/names/QualifiedName.ts';
2
3
  import type {
3
4
  ClientReactiveSubmittableChildNode,
4
5
  ClientReactiveSubmittableParentNode,
@@ -12,7 +13,7 @@ interface ClientReactiveSubmittableValueNodeCurrentState {
12
13
  export type SerializedSubmissionValue = string;
13
14
 
14
15
  interface ClientReactiveSubmittableValueNodeDefinition {
15
- readonly nodeName: string;
16
+ readonly qualifiedName: QualifiedName;
16
17
  }
17
18
 
18
19
  export interface ClientReactiveSubmittableValueNode {
@@ -143,6 +143,8 @@ export abstract class BaseRepeatRange<Definition extends AnyRepeatRangeDefinitio
143
143
  */
144
144
  abstract override readonly appearances: NodeAppearances<Definition>;
145
145
 
146
+ readonly nodeOptions = null;
147
+
146
148
  readonly currentState: MaterializedChildren<CurrentState<RepeatRangeStateSpec>, RepeatInstance>;
147
149
 
148
150
  abstract override readonly validationState: AncestorNodeValidationState;
@@ -92,6 +92,7 @@ export class RepeatInstance
92
92
  * @see {@link RepeatRange.appearances}
93
93
  */
94
94
  readonly appearances: RepeatInstanceNodeAppearances;
95
+ readonly nodeOptions = null;
95
96
 
96
97
  readonly currentState: MaterializedChildren<
97
98
  CurrentState<RepeatInstanceStateSpec>,
@@ -10,7 +10,10 @@ export interface ResourceOptions {
10
10
  }
11
11
 
12
12
  const fetchTextFromURL = async (resource: URL, options: ResourceOptions): Promise<string> => {
13
- const response = await options.fetchResource(resource);
13
+ // destructuring prevents "Failed to execute 'fetch' on 'Window': Illegal invocation"
14
+ const { fetchResource } = options;
15
+
16
+ const response = await fetchResource(resource);
14
17
 
15
18
  return response.text();
16
19
  };
@@ -15,49 +15,54 @@ import {
15
15
  XHTML_NAMESPACE_URI,
16
16
  } from '@getodk/common/constants/xmlns.ts';
17
17
  import { XPathFunctionalityNotSupportedError } from '../../../error/XPathFunctionalityNotSupportedError.ts';
18
- import type { InstanceNode } from '../../../instance/abstract/InstanceNode.ts';
19
- import type { StaticNode } from '../static-dom/StaticNode.ts';
18
+ import type { AnyStaticNode } from '../static-dom/StaticNode.ts';
20
19
  import type { EngineXPathNode } from './kind.ts';
21
- import type { getNamespaceDeclarations } from './traversal.ts';
22
20
 
23
21
  export const getEngineXPathNodeNamespaceURI = (node: EngineXPathNode): string | null => {
24
22
  switch (node.nodeType) {
25
23
  case 'primary-instance':
24
+ case 'static-document':
26
25
  case 'static-text':
26
+ case 'repeat-range:controlled':
27
+ case 'repeat-range:uncontrolled':
27
28
  return null;
28
29
 
29
30
  case 'static-attribute':
30
31
  case 'static-element':
31
- return node.namespaceURI;
32
+ return node.qualifiedName.namespaceURI?.href ?? null;
32
33
 
33
34
  default:
34
- return XFORMS_NAMESPACE_URI;
35
+ return node.definition.qualifiedName.namespaceURI?.href ?? null;
35
36
  }
36
37
  };
37
38
 
38
- /**
39
- * @todo currently, neither {@link InstanceNode} nor {@link StaticNode} account
40
- * for prefixes in qualified names. This was already a general enough gap that
41
- * it makes sense to defer to a broader solution as it becomes a priority
42
- * (likely prompted by a bug report about unexpected behavior of the XPath
43
- * `name` function).
44
- */
45
39
  export const getEngineXPathNodeQualifiedName = (node: EngineXPathNode): string => {
46
- return getEngineXPathNodeLocalName(node);
40
+ switch (node.nodeType) {
41
+ case 'static-attribute':
42
+ case 'static-element':
43
+ return node.qualifiedName.getPrefixedName();
44
+
45
+ case 'static-document':
46
+ case 'static-text':
47
+ return '';
48
+
49
+ default:
50
+ return node.definition.qualifiedName.getPrefixedName();
51
+ }
47
52
  };
48
53
 
49
54
  export const getEngineXPathNodeLocalName = (node: EngineXPathNode): string => {
50
55
  switch (node.nodeType) {
51
56
  case 'static-attribute':
52
57
  case 'static-element':
53
- return node.localName;
58
+ return node.qualifiedName.localName;
54
59
 
55
60
  case 'static-document':
56
61
  case 'static-text':
57
62
  return '';
58
63
 
59
64
  default:
60
- return node.definition.nodeName;
65
+ return node.definition.qualifiedName.localName;
61
66
  }
62
67
  };
63
68
 
@@ -65,9 +70,23 @@ export const getEngineProcessingInstructionName =
65
70
  XPathFunctionalityNotSupportedError.createStubImplementation('processing-instruction');
66
71
 
67
72
  /**
68
- * @todo @see {@link getNamespaceDeclarations}
73
+ * @todo in most cases we should not have **custom** namespace resolution from a
74
+ * static node (e.g. external secondary instance, itext translation) context.
75
+ * The main exception to that would be _XML external secondary instances_, which
76
+ * of course can declare arbitrary namespaces on any arbitrary subtree, just
77
+ * like a form definition's XML. In all other cases, we'd want to resolve a
78
+ * prefix here from the _primary instance_ context. However, we don't (yet) have
79
+ * access to the primary instance context from a static node. So we currently
80
+ * fall back to the previous (incomplete/potentially wrong) default mapping.
81
+ *
82
+ * Note that this is relatively safe for the general case, and only potentially
83
+ * wrong for:
84
+ *
85
+ * 1. Forms authored as XML, with arbitrary/non-default namespace declarations
86
+ * 2. XML external secondary instances, also with arbitrary/non-default
87
+ * namespace declarations
69
88
  */
70
- export const resolveEngineXPathNodeNamespaceURI = (_: EngineXPathNode, prefix: string | null) => {
89
+ const resolveNamespaceURIFromStaticNodeContext = (_: AnyStaticNode, prefix: string | null) => {
71
90
  switch (prefix) {
72
91
  case null:
73
92
  return XFORMS_NAMESPACE_URI;
@@ -97,3 +116,33 @@ export const resolveEngineXPathNodeNamespaceURI = (_: EngineXPathNode, prefix: s
97
116
  return null;
98
117
  }
99
118
  };
119
+
120
+ export const resolveEngineXPathNodeNamespaceURI = (
121
+ node: EngineXPathNode,
122
+ prefix: string | null
123
+ ): string | null => {
124
+ switch (node.nodeType) {
125
+ case 'static-attribute':
126
+ case 'static-document':
127
+ case 'static-element':
128
+ case 'static-text':
129
+ return resolveNamespaceURIFromStaticNodeContext(node, prefix);
130
+
131
+ case 'group':
132
+ case 'input':
133
+ case 'model-value':
134
+ case 'note':
135
+ case 'primary-instance':
136
+ case 'range':
137
+ case 'rank':
138
+ case 'repeat-instance':
139
+ case 'repeat-range:controlled':
140
+ case 'repeat-range:uncontrolled':
141
+ case 'root':
142
+ case 'select':
143
+ case 'subtree':
144
+ case 'trigger':
145
+ case 'upload':
146
+ return node.definition.namespaceDeclarations.get(prefix)?.declaredURI?.href ?? null;
147
+ }
148
+ };
@@ -27,16 +27,17 @@ export const getEngineXPathAttributes = (node: EngineXPathNode): Iterable<Engine
27
27
  };
28
28
 
29
29
  /**
30
- * @todo XML XForms may actually define explicit namespace declarations on
31
- * non-root elements (i.e. elements other than the form definition's `h:html`,
32
- * itext `translation`, secondary `instance`). Expressions defined in such forms
33
- * may also expect to use those namespace declarations. It would even seem
34
- * likely! Why declare namespaces on a subtree if you don't intend to use them?
35
- * We don't currently capture namespace declarations below `h:html` in the parse
36
- * stage (which, if we intend to support the use case, is where we should
37
- * start).
30
+ * @todo We've now laid most of the groundwork necessary to implement this
31
+ * properly. At time of writing it has still been deferred because:
38
32
  *
39
- * @todo At the very least, we should probably produce a set of default namespace declarations. At least for `h:html`, maybe for other "root" nodes.
33
+ * 1. The scope of changes enabling it is already a fairly large yak shave.
34
+ * 2. It is only used to support XPath LocationPath Steps whose AxisName is
35
+ * `namespace`. If we _ever_ support this, it would probably be for extremely
36
+ * niche use cases!
37
+ *
38
+ * @todo Since we've consciously deferred implementing this (twice now!), should
39
+ * it throw? It might be nice to be alerted if the assumptions in point 2 above
40
+ * are somehow wrong (or become wrong).
40
41
  */
41
42
  export const getNamespaceDeclarations = (): Iterable<never> => [];
42
43
 
@@ -1,28 +1,36 @@
1
1
  import { XPathNodeKindKey } from '@getodk/xpath';
2
+ import { QualifiedName } from '../../../lib/names/QualifiedName.ts';
2
3
  import type { XFormsXPathAttribute } from '../adapter/XFormsXPathNode.ts';
4
+ import type { StaticDocument } from './StaticDocument.ts';
3
5
  import type { StaticElement } from './StaticElement.ts';
4
- import type { StaticNamedNodeOptions } from './StaticNamedNode.ts';
5
- import { StaticNamedNode } from './StaticNamedNode.ts';
6
+ import { StaticNode } from './StaticNode.ts';
6
7
 
7
- interface StaticAttributeOptions extends StaticNamedNodeOptions {
8
+ interface StaticAttributeOptions {
9
+ readonly namespaceURI: string | null;
10
+ readonly prefix?: string | null;
11
+ readonly localName: string;
8
12
  readonly value: string;
9
13
  }
10
14
 
11
- export class StaticAttribute extends StaticNamedNode<'attribute'> implements XFormsXPathAttribute {
15
+ export class StaticAttribute extends StaticNode<'attribute'> implements XFormsXPathAttribute {
12
16
  readonly [XPathNodeKindKey] = 'attribute';
13
17
  readonly nodeType = 'static-attribute';
18
+ readonly rootDocument: StaticDocument;
14
19
  readonly root: StaticElement;
20
+ readonly qualifiedName: QualifiedName;
15
21
  readonly attributes = [] as const;
16
22
  readonly children = null;
17
- override readonly value: string;
23
+ readonly value: string;
18
24
 
19
25
  constructor(
20
- override readonly parent: StaticElement,
26
+ readonly parent: StaticElement,
21
27
  options: StaticAttributeOptions
22
28
  ) {
23
- super(parent, options);
29
+ super();
24
30
 
31
+ this.rootDocument = parent.rootDocument;
25
32
  this.root = parent.root;
33
+ this.qualifiedName = new QualifiedName(options);
26
34
  this.value = options.value;
27
35
  }
28
36
 
@@ -15,7 +15,6 @@ export abstract class StaticDocument<DocumentRoot extends StaticElement = Static
15
15
  readonly nodeType = 'static-document';
16
16
  readonly rootDocument: StaticDocument;
17
17
  readonly root: DocumentRoot;
18
- readonly isXFormsNamespace: boolean;
19
18
  readonly parent = null;
20
19
  readonly children: readonly [root: DocumentRoot];
21
20
 
@@ -27,7 +26,6 @@ export abstract class StaticDocument<DocumentRoot extends StaticElement = Static
27
26
  const root = rootFactory(this);
28
27
 
29
28
  this.root = root;
30
- this.isXFormsNamespace = root.isXFormsNamespace;
31
29
  this.children = [root];
32
30
  }
33
31
 
@@ -1,16 +1,21 @@
1
1
  import { XFORMS_KNOWN_ATTRIBUTE, XFORMS_LOCAL_NAME, XPathNodeKindKey } from '@getodk/xpath';
2
+ import { QualifiedName } from '../../../lib/names/QualifiedName.ts';
2
3
  import type { EngineDOMAdapter } from '../adapter/engineDOMAdapter.ts';
3
4
  import type { XFormsXPathElement } from '../adapter/XFormsXPathNode.ts';
4
5
  import { StaticAttribute } from './StaticAttribute.ts';
5
- import type { StaticNamedNodeOptions } from './StaticNamedNode.ts';
6
- import { StaticNamedNode } from './StaticNamedNode.ts';
6
+ import type { StaticDocument } from './StaticDocument.ts';
7
7
  import type { StaticChildNode, StaticParentNode } from './StaticNode.ts';
8
+ import { StaticNode } from './StaticNode.ts';
8
9
 
9
10
  export type StaticElementAttributesFactory = (element: StaticElement) => readonly StaticAttribute[];
10
11
 
11
12
  export type StaticElementChildNodesFactory = (element: StaticElement) => readonly StaticChildNode[];
12
13
 
13
- export interface StaticElementOptions extends StaticNamedNodeOptions {}
14
+ export interface StaticElementOptions {
15
+ readonly namespaceURI: string | null;
16
+ readonly prefix?: string | null;
17
+ readonly localName: string;
18
+ }
14
19
 
15
20
  type StaticElementKnownAttributeValue<
16
21
  T extends StaticElement,
@@ -34,7 +39,7 @@ const assertStaticElementKnownAttributeValue: AssertStaticElementKnownAttributeV
34
39
  };
35
40
 
36
41
  export class StaticElement<Parent extends StaticParentNode = StaticParentNode>
37
- extends StaticNamedNode<'element'>
42
+ extends StaticNode<'element'>
38
43
  implements XFormsXPathElement
39
44
  {
40
45
  readonly [XFORMS_LOCAL_NAME]?: string;
@@ -42,25 +47,33 @@ export class StaticElement<Parent extends StaticParentNode = StaticParentNode>
42
47
 
43
48
  readonly [XPathNodeKindKey] = 'element';
44
49
  readonly nodeType = 'static-element';
50
+ readonly rootDocument: StaticDocument;
45
51
  readonly root: StaticElement;
52
+ readonly qualifiedName: QualifiedName;
46
53
  readonly attributes: readonly StaticAttribute[];
47
54
  readonly children: readonly StaticChildNode[];
55
+ readonly value = null;
48
56
 
49
57
  constructor(
50
- parent: Parent,
58
+ readonly parent: Parent,
51
59
  attributesFactory: StaticElementAttributesFactory,
52
60
  childNodesFactory: StaticElementChildNodesFactory,
53
61
  options: StaticElementOptions
54
62
  ) {
55
- super(parent, options);
63
+ super();
64
+
65
+ const { rootDocument } = parent;
66
+
67
+ this.rootDocument = rootDocument;
56
68
 
57
69
  // Account for the fact that we may be constructing the document root!
58
- if (parent === this.rootDocument) {
70
+ if (parent === rootDocument) {
59
71
  this.root = this;
60
72
  } else {
61
73
  this.root = parent.root;
62
74
  }
63
75
 
76
+ this.qualifiedName = new QualifiedName(options);
64
77
  this.attributes = attributesFactory(this);
65
78
  this.children = childNodesFactory(this);
66
79
  }
@@ -73,7 +86,7 @@ export class StaticElement<Parent extends StaticParentNode = StaticParentNode>
73
86
  protected getAttributeNode(localName: string): StaticAttribute | null {
74
87
  return (
75
88
  this.attributes.find((attribute) => {
76
- return attribute.localName === localName;
89
+ return attribute.qualifiedName.localName === localName;
77
90
  }) ?? null
78
91
  );
79
92
  }
@@ -14,7 +14,7 @@ export const createLeafNodeSubmissionState = <Value>(
14
14
  const value = node.encodeValue(node.currentState.value);
15
15
  const xmlValue = escapeXMLText(value);
16
16
 
17
- return serializeLeafElementXML(node.definition.nodeName, xmlValue);
17
+ return serializeLeafElementXML(node.definition.qualifiedName, xmlValue);
18
18
  },
19
19
  };
20
20
  };
@@ -16,7 +16,7 @@ export const createParentNodeSubmissionState = (
16
16
  return child.submissionState.submissionXML;
17
17
  });
18
18
 
19
- return serializeParentElementXML(node.definition.nodeName, serializedChildren);
19
+ return serializeParentElementXML(node.definition.qualifiedName, serializedChildren);
20
20
  },
21
21
  };
22
22
  };
@@ -0,0 +1,19 @@
1
+ import type { SubmissionState } from '../../../client/submission/SubmissionState.ts';
2
+ import type { Root } from '../../../instance/Root.ts';
3
+ import { serializeParentElementXML } from '../../xml-serialization.ts';
4
+
5
+ export const createRootSubmissionState = (node: Root): SubmissionState => {
6
+ return {
7
+ get submissionXML() {
8
+ const { namespaceDeclarations, attributes } = node.definition;
9
+ const serializedChildren = node.currentState.children.map((child) => {
10
+ return child.submissionState.submissionXML;
11
+ });
12
+
13
+ return serializeParentElementXML(node.definition.qualifiedName, serializedChildren, {
14
+ namespaceDeclarations,
15
+ attributes: Array.from(attributes.values()),
16
+ });
17
+ },
18
+ };
19
+ };
@@ -5,7 +5,7 @@ import { escapeXMLText, serializeLeafElementXML } from '../../xml-serialization.
5
5
  export const createValueNodeSubmissionState = (
6
6
  node: ClientReactiveSubmittableValueNode
7
7
  ): SubmissionState => {
8
- const { nodeName } = node.definition;
8
+ const { qualifiedName } = node.definition;
9
9
 
10
10
  return {
11
11
  get submissionXML() {
@@ -15,7 +15,7 @@ export const createValueNodeSubmissionState = (
15
15
 
16
16
  const xmlValue = escapeXMLText(node.currentState.instanceValue);
17
17
 
18
- return serializeLeafElementXML(nodeName, xmlValue);
18
+ return serializeLeafElementXML(qualifiedName, xmlValue);
19
19
  },
20
20
  };
21
21
  };