@getodk/xforms-engine 0.6.0 → 0.7.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 (296) hide show
  1. package/dist/client/BaseNode.d.ts +4 -4
  2. package/dist/client/BaseValueNode.d.ts +7 -3
  3. package/dist/client/RootNode.d.ts +20 -16
  4. package/dist/client/constants.d.ts +11 -12
  5. package/dist/client/form/CreateFormInstance.d.ts +14 -0
  6. package/dist/client/form/EditFormInstance.d.ts +62 -0
  7. package/dist/client/form/FormInstance.d.ts +104 -0
  8. package/dist/client/form/FormInstanceConfig.d.ts +17 -0
  9. package/dist/client/form/FormResource.d.ts +1 -0
  10. package/dist/client/form/LoadForm.d.ts +79 -0
  11. package/dist/client/form/LoadFormResult.d.ts +67 -0
  12. package/dist/client/form/RestoreFormInstance.d.ts +8 -0
  13. package/dist/client/index.d.ts +37 -11
  14. package/dist/client/node-types.d.ts +2 -2
  15. package/dist/client/repeat/BaseRepeatRangeNode.d.ts +3 -4
  16. package/dist/client/repeat/RepeatInstanceNode.d.ts +4 -5
  17. package/dist/client/repeat/RepeatRangeControlledNode.d.ts +2 -2
  18. package/dist/client/repeat/RepeatRangeUncontrolledNode.d.ts +2 -2
  19. package/dist/client/resources.d.ts +1 -1
  20. package/dist/client/serialization/InstanceData.d.ts +12 -0
  21. package/dist/client/serialization/InstanceFile.d.ts +6 -0
  22. package/dist/client/serialization/InstancePayload.d.ts +93 -0
  23. package/dist/client/serialization/InstancePayloadOptions.d.ts +23 -0
  24. package/dist/client/serialization/InstanceState.d.ts +12 -0
  25. package/dist/client/submission/{SubmissionDefinition.d.ts → SubmissionMeta.d.ts} +1 -1
  26. package/dist/entrypoints/FormInstance.d.ts +20 -0
  27. package/dist/entrypoints/FormResult/BaseFormResult.d.ts +22 -0
  28. package/dist/entrypoints/FormResult/BaseInstantiableFormResult.d.ts +25 -0
  29. package/dist/entrypoints/FormResult/FormFailureResult.d.ts +17 -0
  30. package/dist/entrypoints/FormResult/FormSuccessResult.d.ts +15 -0
  31. package/dist/entrypoints/FormResult/FormWarningResult.d.ts +15 -0
  32. package/dist/entrypoints/createInstance.d.ts +9 -0
  33. package/dist/entrypoints/editInstance.d.ts +9 -0
  34. package/dist/entrypoints/index.d.ts +4 -0
  35. package/dist/entrypoints/loadForm.d.ts +4 -0
  36. package/dist/entrypoints/restoreInstance.d.ts +9 -0
  37. package/dist/error/LoadFormFailureError.d.ts +9 -0
  38. package/dist/error/MalformedInstanceDataError.d.ts +3 -0
  39. package/dist/error/TemplatedNodeAttributeSerializationError.d.ts +22 -0
  40. package/dist/index.d.ts +2 -33
  41. package/dist/index.js +1915 -1419
  42. package/dist/index.js.map +1 -1
  43. package/dist/instance/Group.d.ts +6 -5
  44. package/dist/instance/InputControl.d.ts +5 -4
  45. package/dist/instance/ModelValue.d.ts +5 -4
  46. package/dist/instance/Note.d.ts +4 -3
  47. package/dist/instance/PrimaryInstance.d.ts +35 -8
  48. package/dist/instance/RangeControl.d.ts +5 -4
  49. package/dist/instance/RankControl.d.ts +6 -5
  50. package/dist/instance/Root.d.ts +7 -9
  51. package/dist/instance/SelectControl.d.ts +4 -3
  52. package/dist/instance/Subtree.d.ts +6 -5
  53. package/dist/instance/TriggerControl.d.ts +4 -3
  54. package/dist/instance/abstract/DescendantNode.d.ts +10 -1
  55. package/dist/instance/abstract/InstanceNode.d.ts +7 -4
  56. package/dist/instance/abstract/ValueNode.d.ts +7 -5
  57. package/dist/instance/children/DescendantNodeInitOptions.d.ts +32 -0
  58. package/dist/instance/{children.d.ts → children/buildChildren.d.ts} +1 -1
  59. package/dist/instance/children/childrenInitOptions.d.ts +9 -0
  60. package/dist/instance/children/normalizeChildInitOptions.d.ts +2 -0
  61. package/dist/instance/input/InitialInstanceState.d.ts +13 -0
  62. package/dist/instance/input/InstanceAttachmentMap.d.ts +19 -0
  63. package/dist/instance/internal-api/InstanceConfig.d.ts +2 -9
  64. package/dist/instance/internal-api/InstanceValueContext.d.ts +8 -1
  65. package/dist/instance/internal-api/serialization/ClientReactiveSerializableInstance.d.ts +14 -0
  66. package/dist/instance/internal-api/serialization/ClientReactiveSerializableLeafNode.d.ts +32 -0
  67. package/dist/instance/internal-api/serialization/ClientReactiveSerializableParentNode.d.ts +18 -0
  68. package/dist/instance/internal-api/serialization/ClientReactiveSerializableTemplatedNode.d.ts +13 -0
  69. package/dist/instance/internal-api/serialization/ClientReactiveSerializableValueNode.d.ts +21 -0
  70. package/dist/instance/repeat/BaseRepeatRange.d.ts +10 -8
  71. package/dist/instance/repeat/RepeatInstance.d.ts +10 -7
  72. package/dist/instance/repeat/RepeatRangeControlled.d.ts +27 -3
  73. package/dist/instance/repeat/RepeatRangeUncontrolled.d.ts +4 -3
  74. package/dist/instance/resource.d.ts +5 -1
  75. package/dist/instance/unsupported/UploadControl.d.ts +32 -4
  76. package/dist/integration/xpath/EngineXPathEvaluator.d.ts +2 -2
  77. package/dist/integration/xpath/adapter/kind.d.ts +4 -10
  78. package/dist/integration/xpath/static-dom/StaticAttribute.d.ts +4 -5
  79. package/dist/integration/xpath/static-dom/StaticDocument.d.ts +13 -10
  80. package/dist/integration/xpath/static-dom/StaticElement.d.ts +21 -22
  81. package/dist/integration/xpath/static-dom/StaticNode.d.ts +1 -1
  82. package/dist/integration/xpath/static-dom/StaticParentNode.d.ts +13 -0
  83. package/dist/integration/xpath/static-dom/staticNodeName.d.ts +3 -0
  84. package/dist/lib/client-reactivity/instance-state/createNodeRangeInstanceState.d.ts +4 -0
  85. package/dist/lib/client-reactivity/instance-state/createParentNodeInstanceState.d.ts +4 -0
  86. package/dist/lib/client-reactivity/instance-state/createPrimaryInstanceState.d.ts +3 -0
  87. package/dist/lib/client-reactivity/instance-state/createRootInstanceState.d.ts +3 -0
  88. package/dist/lib/client-reactivity/instance-state/createTemplatedNodeInstanceState.d.ts +6 -0
  89. package/dist/lib/client-reactivity/instance-state/createValueNodeInstanceState.d.ts +3 -0
  90. package/dist/lib/client-reactivity/instance-state/prepareInstancePayload.d.ts +8 -0
  91. package/dist/lib/codecs/TempUnsupportedControlCodec.d.ts +7 -0
  92. package/dist/lib/names/UnprefixedXFormsName.d.ts +4 -0
  93. package/dist/lib/reactivity/createInstanceValueState.d.ts +2 -27
  94. package/dist/parse/XFormDOM.d.ts +1 -1
  95. package/dist/parse/model/BindDefinition.d.ts +1 -1
  96. package/dist/parse/model/ItextTranslationsDefinition.d.ts +18 -0
  97. package/dist/parse/model/LeafNodeDefinition.d.ts +4 -5
  98. package/dist/parse/model/ModelBindMap.d.ts +1 -1
  99. package/dist/parse/model/ModelDefinition.d.ts +9 -2
  100. package/dist/parse/model/NodeDefinition.d.ts +18 -30
  101. package/dist/parse/model/NoteNodeDefinition.d.ts +3 -2
  102. package/dist/parse/model/RangeNodeDefinition.d.ts +2 -1
  103. package/dist/parse/model/RepeatDefinition.d.ts +62 -0
  104. package/dist/parse/model/RootAttributeDefinition.d.ts +1 -4
  105. package/dist/parse/model/RootAttributeMap.d.ts +2 -1
  106. package/dist/parse/model/RootDefinition.d.ts +7 -8
  107. package/dist/parse/model/SecondaryInstance/SecondaryInstancesDefinition.d.ts +15 -2
  108. package/dist/parse/model/SecondaryInstance/assertSecondaryInstanceDefinition.d.ts +5 -0
  109. package/dist/parse/model/SecondaryInstance/defineSecondaryInstance.d.ts +5 -0
  110. package/dist/parse/model/SecondaryInstance/sources/BlankSecondaryInstanceSource.d.ts +1 -7
  111. package/dist/parse/model/SecondaryInstance/sources/CSVExternalSecondaryInstance.d.ts +1 -1
  112. package/dist/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.d.ts +1 -1
  113. package/dist/parse/model/SecondaryInstance/sources/InternalSecondaryInstanceSource.d.ts +1 -1
  114. package/dist/parse/model/SecondaryInstance/sources/SecondaryInstanceSource.d.ts +1 -1
  115. package/dist/parse/model/SecondaryInstance/sources/XMLExternalSecondaryInstanceSource.d.ts +1 -1
  116. package/dist/parse/model/{FormSubmissionDefinition.d.ts → SubmissionDefinition.d.ts} +2 -2
  117. package/dist/parse/model/SubtreeDefinition.d.ts +4 -5
  118. package/dist/parse/model/nodeDefinitionMap.d.ts +5 -0
  119. package/dist/parse/shared/parseInstanceXML.d.ts +21 -0
  120. package/dist/parse/shared/parseStaticDocumentFromDOMSubtree.d.ts +4 -21
  121. package/dist/solid.js +1709 -1213
  122. package/dist/solid.js.map +1 -1
  123. package/package.json +1 -1
  124. package/src/client/BaseNode.ts +4 -4
  125. package/src/client/BaseValueNode.ts +7 -3
  126. package/src/client/RootNode.ts +27 -19
  127. package/src/client/constants.ts +12 -14
  128. package/src/client/form/CreateFormInstance.ts +19 -0
  129. package/src/client/form/EditFormInstance.ts +93 -0
  130. package/src/client/form/FormInstance.ts +114 -0
  131. package/src/client/form/FormInstanceConfig.ts +18 -0
  132. package/src/client/form/FormResource.ts +1 -0
  133. package/src/client/form/LoadForm.ts +92 -0
  134. package/src/client/form/LoadFormResult.ts +103 -0
  135. package/src/client/form/RestoreFormInstance.ts +14 -0
  136. package/src/client/index.ts +47 -29
  137. package/src/client/node-types.ts +2 -4
  138. package/src/client/repeat/BaseRepeatRangeNode.ts +3 -4
  139. package/src/client/repeat/RepeatInstanceNode.ts +4 -8
  140. package/src/client/repeat/RepeatRangeControlledNode.ts +2 -2
  141. package/src/client/repeat/RepeatRangeUncontrolledNode.ts +2 -2
  142. package/src/client/resources.ts +2 -2
  143. package/src/client/serialization/InstanceData.ts +16 -0
  144. package/src/client/serialization/InstanceFile.ts +9 -0
  145. package/src/client/serialization/InstancePayload.ts +126 -0
  146. package/src/client/serialization/InstancePayloadOptions.ts +28 -0
  147. package/src/client/serialization/InstanceState.ts +14 -0
  148. package/src/client/submission/{SubmissionDefinition.ts → SubmissionMeta.ts} +1 -1
  149. package/src/entrypoints/FormInstance.ts +55 -0
  150. package/src/entrypoints/FormResult/BaseFormResult.ts +40 -0
  151. package/src/entrypoints/FormResult/BaseInstantiableFormResult.ts +109 -0
  152. package/src/entrypoints/FormResult/FormFailureResult.ts +44 -0
  153. package/src/entrypoints/FormResult/FormSuccessResult.ts +25 -0
  154. package/src/entrypoints/FormResult/FormWarningResult.ts +25 -0
  155. package/src/entrypoints/createInstance.ts +23 -0
  156. package/src/entrypoints/editInstance.ts +24 -0
  157. package/src/entrypoints/index.ts +4 -0
  158. package/src/entrypoints/loadForm.ts +154 -0
  159. package/src/entrypoints/restoreInstance.ts +27 -0
  160. package/src/error/LoadFormFailureError.ts +114 -0
  161. package/src/error/MalformedInstanceDataError.ts +3 -0
  162. package/src/error/TemplatedNodeAttributeSerializationError.ts +24 -0
  163. package/src/index.ts +2 -46
  164. package/src/instance/Group.ts +16 -15
  165. package/src/instance/InputControl.ts +17 -11
  166. package/src/instance/ModelValue.ts +17 -11
  167. package/src/instance/Note.ts +10 -9
  168. package/src/instance/PrimaryInstance.ts +69 -31
  169. package/src/instance/RangeControl.ts +17 -11
  170. package/src/instance/RankControl.ts +28 -19
  171. package/src/instance/Root.ts +20 -31
  172. package/src/instance/SelectControl.ts +21 -12
  173. package/src/instance/Subtree.ts +16 -15
  174. package/src/instance/TriggerControl.ts +21 -12
  175. package/src/instance/abstract/DescendantNode.ts +12 -2
  176. package/src/instance/abstract/InstanceNode.ts +9 -5
  177. package/src/instance/abstract/ValueNode.ts +11 -13
  178. package/src/instance/children/DescendantNodeInitOptions.ts +35 -0
  179. package/src/instance/{children.ts → children/buildChildren.ts} +55 -48
  180. package/src/instance/children/childrenInitOptions.ts +117 -0
  181. package/src/instance/children/normalizeChildInitOptions.ts +332 -0
  182. package/src/instance/input/InitialInstanceState.ts +108 -0
  183. package/src/instance/input/InstanceAttachmentMap.ts +142 -0
  184. package/src/instance/internal-api/InstanceConfig.ts +3 -10
  185. package/src/instance/internal-api/InstanceValueContext.ts +9 -1
  186. package/src/instance/internal-api/serialization/ClientReactiveSerializableInstance.ts +20 -0
  187. package/src/instance/internal-api/serialization/ClientReactiveSerializableLeafNode.ts +43 -0
  188. package/src/instance/internal-api/serialization/ClientReactiveSerializableParentNode.ts +26 -0
  189. package/src/instance/internal-api/serialization/ClientReactiveSerializableTemplatedNode.ts +24 -0
  190. package/src/instance/internal-api/serialization/ClientReactiveSerializableValueNode.ts +28 -0
  191. package/src/instance/repeat/BaseRepeatRange.ts +19 -24
  192. package/src/instance/repeat/RepeatInstance.ts +26 -19
  193. package/src/instance/repeat/RepeatRangeControlled.ts +90 -17
  194. package/src/instance/repeat/RepeatRangeUncontrolled.ts +10 -9
  195. package/src/instance/resource.ts +14 -1
  196. package/src/instance/unsupported/UploadControl.ts +116 -5
  197. package/src/integration/xpath/EngineXPathEvaluator.ts +2 -2
  198. package/src/integration/xpath/adapter/kind.ts +1 -28
  199. package/src/integration/xpath/adapter/traversal.ts +2 -2
  200. package/src/integration/xpath/static-dom/StaticAttribute.ts +6 -5
  201. package/src/integration/xpath/static-dom/StaticDocument.ts +17 -16
  202. package/src/integration/xpath/static-dom/StaticElement.ts +196 -50
  203. package/src/integration/xpath/static-dom/StaticNode.ts +1 -1
  204. package/src/integration/xpath/static-dom/StaticParentNode.ts +22 -0
  205. package/src/integration/xpath/static-dom/staticNodeName.ts +20 -0
  206. package/src/lib/client-reactivity/instance-state/createNodeRangeInstanceState.ts +17 -0
  207. package/src/lib/client-reactivity/instance-state/createParentNodeInstanceState.ts +22 -0
  208. package/src/lib/client-reactivity/instance-state/createPrimaryInstanceState.ts +12 -0
  209. package/src/lib/client-reactivity/{submission/createRootSubmissionState.ts → instance-state/createRootInstanceState.ts} +4 -4
  210. package/src/lib/client-reactivity/instance-state/createTemplatedNodeInstanceState.ts +31 -0
  211. package/src/lib/client-reactivity/instance-state/createValueNodeInstanceState.ts +21 -0
  212. package/src/lib/client-reactivity/instance-state/prepareInstancePayload.ts +173 -0
  213. package/src/lib/codecs/TempUnsupportedControlCodec.ts +32 -0
  214. package/src/lib/names/UnprefixedXFormsName.ts +12 -0
  215. package/src/lib/reactivity/createInstanceValueState.ts +27 -51
  216. package/src/parse/model/ItextTranslationsDefinition.ts +79 -0
  217. package/src/parse/model/LeafNodeDefinition.ts +3 -5
  218. package/src/parse/model/ModelDefinition.ts +36 -3
  219. package/src/parse/model/NodeDefinition.ts +19 -45
  220. package/src/parse/model/NoteNodeDefinition.ts +4 -3
  221. package/src/parse/model/RangeNodeDefinition.ts +3 -2
  222. package/src/parse/model/RepeatDefinition.ts +382 -0
  223. package/src/parse/model/RootAttributeDefinition.ts +6 -7
  224. package/src/parse/model/RootAttributeMap.ts +15 -10
  225. package/src/parse/model/RootDefinition.ts +17 -19
  226. package/src/parse/model/SecondaryInstance/SecondaryInstancesDefinition.ts +23 -2
  227. package/src/parse/model/SecondaryInstance/assertSecondaryInstanceDefinition.ts +14 -0
  228. package/src/parse/model/SecondaryInstance/defineSecondaryInstance.ts +32 -0
  229. package/src/parse/model/SecondaryInstance/sources/BlankSecondaryInstanceSource.ts +3 -24
  230. package/src/parse/model/SecondaryInstance/sources/CSVExternalSecondaryInstance.ts +33 -86
  231. package/src/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.ts +64 -137
  232. package/src/parse/model/SecondaryInstance/sources/InternalSecondaryInstanceSource.ts +9 -7
  233. package/src/parse/model/SecondaryInstance/sources/SecondaryInstanceSource.ts +1 -1
  234. package/src/parse/model/SecondaryInstance/sources/XMLExternalSecondaryInstanceSource.ts +7 -7
  235. package/src/parse/model/{FormSubmissionDefinition.ts → SubmissionDefinition.ts} +2 -2
  236. package/src/parse/model/SubtreeDefinition.ts +4 -5
  237. package/src/parse/model/nodeDefinitionMap.ts +34 -0
  238. package/src/parse/shared/parseInstanceXML.ts +79 -0
  239. package/src/parse/shared/parseStaticDocumentFromDOMSubtree.ts +45 -130
  240. package/dist/client/EngineConfig.d.ts +0 -79
  241. package/dist/client/submission/SubmissionData.d.ts +0 -7
  242. package/dist/client/submission/SubmissionInstanceFile.d.ts +0 -6
  243. package/dist/client/submission/SubmissionOptions.d.ts +0 -23
  244. package/dist/client/submission/SubmissionResult.d.ts +0 -91
  245. package/dist/client/submission/SubmissionState.d.ts +0 -12
  246. package/dist/instance/abstract/UnsupportedControl.d.ts +0 -54
  247. package/dist/instance/index.d.ts +0 -8
  248. package/dist/instance/internal-api/ValueContext.d.ts +0 -23
  249. package/dist/instance/internal-api/submission/ClientReactiveSubmittableInstance.d.ts +0 -14
  250. package/dist/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.d.ts +0 -32
  251. package/dist/instance/internal-api/submission/ClientReactiveSubmittableParentNode.d.ts +0 -19
  252. package/dist/instance/internal-api/submission/ClientReactiveSubmittableValueNode.d.ts +0 -18
  253. package/dist/lib/client-reactivity/submission/createInstanceSubmissionState.d.ts +0 -3
  254. package/dist/lib/client-reactivity/submission/createLeafNodeSubmissionState.d.ts +0 -3
  255. package/dist/lib/client-reactivity/submission/createNodeRangeSubmissionState.d.ts +0 -4
  256. package/dist/lib/client-reactivity/submission/createParentNodeSubmissionState.d.ts +0 -4
  257. package/dist/lib/client-reactivity/submission/createRootSubmissionState.d.ts +0 -3
  258. package/dist/lib/client-reactivity/submission/createValueNodeSubmissionState.d.ts +0 -3
  259. package/dist/lib/client-reactivity/submission/prepareSubmission.d.ts +0 -8
  260. package/dist/lib/reactivity/createValueState.d.ts +0 -40
  261. package/dist/parse/model/ItextTranslation/ItextTranslationDefinition.d.ts +0 -4
  262. package/dist/parse/model/ItextTranslation/ItextTranslationRootDefinition.d.ts +0 -9
  263. package/dist/parse/model/ItextTranslation/ItextTranslationsDefinition.d.ts +0 -8
  264. package/dist/parse/model/RepeatInstanceDefinition.d.ts +0 -17
  265. package/dist/parse/model/RepeatRangeDefinition.d.ts +0 -32
  266. package/dist/parse/model/RepeatTemplateDefinition.d.ts +0 -31
  267. package/dist/parse/model/SecondaryInstance/SecondaryInstanceDefinition.d.ts +0 -4
  268. package/dist/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.d.ts +0 -7
  269. package/src/client/EngineConfig.ts +0 -84
  270. package/src/client/submission/SubmissionData.ts +0 -12
  271. package/src/client/submission/SubmissionInstanceFile.ts +0 -9
  272. package/src/client/submission/SubmissionOptions.ts +0 -28
  273. package/src/client/submission/SubmissionResult.ts +0 -124
  274. package/src/client/submission/SubmissionState.ts +0 -14
  275. package/src/instance/abstract/UnsupportedControl.ts +0 -175
  276. package/src/instance/index.ts +0 -55
  277. package/src/instance/internal-api/ValueContext.ts +0 -28
  278. package/src/instance/internal-api/submission/ClientReactiveSubmittableInstance.ts +0 -20
  279. package/src/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.ts +0 -43
  280. package/src/instance/internal-api/submission/ClientReactiveSubmittableParentNode.ts +0 -26
  281. package/src/instance/internal-api/submission/ClientReactiveSubmittableValueNode.ts +0 -24
  282. package/src/lib/client-reactivity/submission/createInstanceSubmissionState.ts +0 -12
  283. package/src/lib/client-reactivity/submission/createLeafNodeSubmissionState.ts +0 -20
  284. package/src/lib/client-reactivity/submission/createNodeRangeSubmissionState.ts +0 -17
  285. package/src/lib/client-reactivity/submission/createParentNodeSubmissionState.ts +0 -22
  286. package/src/lib/client-reactivity/submission/createValueNodeSubmissionState.ts +0 -21
  287. package/src/lib/client-reactivity/submission/prepareSubmission.ts +0 -172
  288. package/src/lib/reactivity/createValueState.ts +0 -200
  289. package/src/parse/model/ItextTranslation/ItextTranslationDefinition.ts +0 -4
  290. package/src/parse/model/ItextTranslation/ItextTranslationRootDefinition.ts +0 -42
  291. package/src/parse/model/ItextTranslation/ItextTranslationsDefinition.ts +0 -31
  292. package/src/parse/model/RepeatInstanceDefinition.ts +0 -38
  293. package/src/parse/model/RepeatRangeDefinition.ts +0 -98
  294. package/src/parse/model/RepeatTemplateDefinition.ts +0 -149
  295. package/src/parse/model/SecondaryInstance/SecondaryInstanceDefinition.ts +0 -4
  296. package/src/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.ts +0 -12
package/dist/solid.js CHANGED
@@ -1,20 +1,17 @@
1
- import { createRoot, getOwner, runWithOwner, createUniqueId as createUniqueId$1, createSignal, createComputed, untrack, createMemo, on } from 'solid-js';
2
-
3
- const identity$1 = (value) => value;
1
+ import { createRoot, getOwner, runWithOwner, createSignal, createComputed, untrack, createUniqueId as createUniqueId$1, createMemo, on } from 'solid-js';
4
2
 
5
3
  const MISSING_RESOURCE_BEHAVIOR = {
6
4
  /**
7
- * When this behavior is configured, {@link InitializeForm | initializing} a
8
- * {@link PrimaryInstance} for a form which references any **missing**
9
- * resources will fail, producing an error to the calling client.
5
+ * When this behavior is configured, {@link LoadForm | loading a form} which
6
+ * references any **missing** resources will fail, producing an error to the
7
+ * calling client.
10
8
  *
11
9
  * @see {@link MissingResourceBehavior}
12
10
  */
13
11
  ERROR: "ERROR",
14
12
  /**
15
- * When this behavior is configured, {@link InitializeForm | initializing} a
16
- * {@link PrimaryInstance} for a form which references any **missing**
17
- * resources will succeed (producing a warning).
13
+ * When this behavior is configured, {@link LoadForm | loading a form} which
14
+ * references any **missing** resources will succeed (producing a warning).
18
15
  *
19
16
  * Such missing resources will be parsed as if they are blank, as appropriate
20
17
  * for the resource's XForm semantic usage and/or format.
@@ -33,17 +30,77 @@ const VALIDATION_TEXT = {
33
30
  constraintMsg: "Condition not satisfied: constraint",
34
31
  requiredMsg: "Condition not satisfied: required"
35
32
  };
36
- const SUBMISSION_INSTANCE_FILE_NAME = "xml_submission_file";
37
- const SUBMISSION_INSTANCE_FILE_TYPE = "text/xml";
33
+ const INSTANCE_FILE_NAME = "xml_submission_file";
34
+ const INSTANCE_FILE_TYPE = "text/xml";
38
35
 
39
36
  const constants = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
40
37
  __proto__: null,
38
+ INSTANCE_FILE_NAME,
39
+ INSTANCE_FILE_TYPE,
41
40
  MISSING_RESOURCE_BEHAVIOR,
42
- SUBMISSION_INSTANCE_FILE_NAME,
43
- SUBMISSION_INSTANCE_FILE_TYPE,
44
41
  VALIDATION_TEXT
45
42
  }, Symbol.toStringTag, { value: 'Module' }));
46
43
 
44
+ const blobDescription = (resource) => {
45
+ const { name } = resource;
46
+ if (typeof name === "string") {
47
+ return name;
48
+ }
49
+ let commonConstructorName;
50
+ if (resource instanceof File) {
51
+ commonConstructorName = "File";
52
+ } else {
53
+ commonConstructorName = "Blob";
54
+ }
55
+ return `Unknown ${commonConstructorName} data`;
56
+ };
57
+ const formResourceMetadata = (resource) => {
58
+ if (resource instanceof Blob) {
59
+ return {
60
+ description: blobDescription(resource),
61
+ rawData: null
62
+ };
63
+ }
64
+ if (resource instanceof URL) {
65
+ return {
66
+ description: resource.href,
67
+ rawData: null
68
+ };
69
+ }
70
+ return {
71
+ description: "Raw string data",
72
+ rawData: resource
73
+ };
74
+ };
75
+ class LoadFormFailureError extends AggregateError {
76
+ constructor(resource, errors) {
77
+ const { description, rawData } = formResourceMetadata(resource);
78
+ const messageLines = [
79
+ `Failed to load form resource: ${description}`,
80
+ "\n",
81
+ ...errors.map((error) => {
82
+ const aggregatedMessage = error.message;
83
+ if (aggregatedMessage == null) {
84
+ return "- Unknown error";
85
+ }
86
+ return `- ${aggregatedMessage}`;
87
+ })
88
+ ];
89
+ if (rawData != null) {
90
+ messageLines.push("\n- - -\n", "Raw resource data:", rawData);
91
+ }
92
+ const message = messageLines.join("\n");
93
+ super(errors, message);
94
+ const [head, ...tail] = errors;
95
+ if (head != null && tail.length === 0) {
96
+ const { stack } = head;
97
+ if (typeof stack === "string") {
98
+ this.stack = stack;
99
+ }
100
+ }
101
+ }
102
+ }
103
+
47
104
  let UnreachableError$1 = class UnreachableError extends Error {
48
105
  constructor(unrechable, additionalDetail) {
49
106
  let message = `Unreachable value: ${JSON.stringify(unrechable)}`;
@@ -141,6 +198,11 @@ const retrieveSourceXMLResource = async (resource, options) => {
141
198
  assertResourceTextIsXML(text);
142
199
  return text;
143
200
  };
201
+ const retrieveFormDefinition = async (resource, options) => {
202
+ return retrieveSourceXMLResource(resource, {
203
+ fetchResource: options.fetchFormDefinition
204
+ });
205
+ };
144
206
 
145
207
  const validateReactiveScopeAPI = (api) => {
146
208
  if (api.owner == null) {
@@ -182,11 +244,6 @@ const createReactiveScope = (options = {}) => {
182
244
  }, options.owner ?? getOwner());
183
245
  };
184
246
 
185
- const createUniqueId = (() => {
186
- const { crypto } = globalThis;
187
- return crypto?.randomUUID?.bind(crypto) ?? createUniqueId$1;
188
- })();
189
-
190
247
  const XHTML_NAMESPACE_URI$1 = "http://www.w3.org/1999/xhtml";
191
248
  const XMLNS_NAMESPACE_URI$1 = "http://www.w3.org/2000/xmlns/";
192
249
  const XSD_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema";
@@ -25104,7 +25161,7 @@ class UnreachableError extends Error {
25104
25161
  }
25105
25162
  }
25106
25163
 
25107
- const identity = (value) => value;
25164
+ const identity$1 = (value) => value;
25108
25165
 
25109
25166
  class Reiterable {
25110
25167
  constructor(source) {
@@ -25384,7 +25441,7 @@ const getNodeTypeFilter = (domProvider, step) => {
25384
25441
  case "comment":
25385
25442
  return domProvider.filterComments;
25386
25443
  case "node":
25387
- return identity;
25444
+ return identity$1;
25388
25445
  case "text":
25389
25446
  return domProvider.filterTextNodes;
25390
25447
  default:
@@ -28865,9 +28922,6 @@ class DefaultEvaluator extends Evaluator {
28865
28922
  }
28866
28923
  }
28867
28924
 
28868
- const XFORMS_LOCAL_NAME = Symbol("XFORMS_LOCAL_NAME");
28869
- const XFORMS_KNOWN_ATTRIBUTE = Symbol("XFORMS_KNOWN_ATTRIBUTE");
28870
-
28871
28925
  const DAY_MILLISECONDS = 1e3 * 60 * 60 * 24;
28872
28926
  const MILLISECOND_NANOSECONDS = BigInt(1e6);
28873
28927
  const ISO_DATE_LIKE_SUBPATTERN = "\\d{4}-\\d{2}-\\d{2}";
@@ -38658,38 +38712,6 @@ class BodyDefinition extends DependencyContext {
38658
38712
  }
38659
38713
  }
38660
38714
 
38661
- class FormSubmissionDefinition {
38662
- submissionAction;
38663
- submissionMethod = "post";
38664
- encryptionKey;
38665
- constructor(xformDOM) {
38666
- const submissionElement = getSubmissionElement(xformDOM.model);
38667
- let submissionAction = null;
38668
- let submissionMethod;
38669
- let encryptionKey = null;
38670
- if (submissionElement == null) {
38671
- submissionAction = null;
38672
- submissionMethod = "post";
38673
- encryptionKey = null;
38674
- } else {
38675
- const method = submissionElement.getAttribute("method")?.trim();
38676
- if (method == null || method === "post" || method === "form-data-post") {
38677
- submissionMethod = "post";
38678
- } else {
38679
- throw new Error(`Unexpected <submission method>: ${method}`);
38680
- }
38681
- const action = submissionElement.getAttribute("action");
38682
- if (action != null) {
38683
- submissionAction = new URL(action.trim());
38684
- }
38685
- encryptionKey = submissionElement.getAttribute("base64RsaPublicKey");
38686
- }
38687
- this.submissionAction = submissionAction;
38688
- this.submissionMethod = submissionMethod;
38689
- this.encryptionKey = encryptionKey;
38690
- }
38691
- }
38692
-
38693
38715
  class NamespaceURL extends URL {
38694
38716
  static from(namespaceURI) {
38695
38717
  if (namespaceURI == null || namespaceURI === "") {
@@ -38763,13 +38785,34 @@ class StaticNode {
38763
38785
  }
38764
38786
  }
38765
38787
 
38788
+ class UnprefixedXFormsName extends QualifiedName {
38789
+ constructor(localName) {
38790
+ super({
38791
+ namespaceURI: XFORMS_NAMESPACE_URI$1,
38792
+ prefix: null,
38793
+ localName
38794
+ });
38795
+ }
38796
+ }
38797
+
38798
+ const staticNodeName = (source) => {
38799
+ if (source instanceof QualifiedName) {
38800
+ return source;
38801
+ }
38802
+ if (typeof source === "string") {
38803
+ return new UnprefixedXFormsName(source);
38804
+ }
38805
+ return new QualifiedName(source);
38806
+ };
38807
+
38766
38808
  class StaticAttribute extends StaticNode {
38767
38809
  constructor(parent, options) {
38768
38810
  super();
38769
38811
  this.parent = parent;
38770
38812
  this.rootDocument = parent.rootDocument;
38771
38813
  this.root = parent.root;
38772
- this.qualifiedName = new QualifiedName(options);
38814
+ this.qualifiedName = staticNodeName(options.name);
38815
+ this.nodeset = `${parent.nodeset}/@${this.qualifiedName.getPrefixedName()}`;
38773
38816
  this.value = options.value;
38774
38817
  }
38775
38818
  [XPathNodeKindKey] = "attribute";
@@ -38777,6 +38820,7 @@ class StaticAttribute extends StaticNode {
38777
38820
  rootDocument;
38778
38821
  root;
38779
38822
  qualifiedName;
38823
+ nodeset;
38780
38824
  attributes = [];
38781
38825
  children = null;
38782
38826
  value;
@@ -38786,36 +38830,140 @@ class StaticAttribute extends StaticNode {
38786
38830
  }
38787
38831
  }
38788
38832
 
38789
- const assertStaticElementKnownAttributeValue = (element, localName, value) => {
38790
- if (localName === element[XFORMS_KNOWN_ATTRIBUTE] && value == null) {
38791
- throw new Error(`Expected attribute: ${element[XFORMS_KNOWN_ATTRIBUTE]}`);
38833
+ class StaticParentNode extends StaticNode {
38834
+ [XPathNodeKindKey];
38835
+ nodeType;
38836
+ constructor(kind) {
38837
+ super();
38838
+ this[XPathNodeKindKey] = kind;
38839
+ this.nodeType = `static-${kind}`;
38792
38840
  }
38793
- };
38794
- class StaticElement extends StaticNode {
38795
- constructor(parent, attributesFactory, childNodesFactory, options) {
38841
+ }
38842
+
38843
+ class StaticText extends StaticNode {
38844
+ constructor(parent, value) {
38796
38845
  super();
38797
38846
  this.parent = parent;
38847
+ this.value = value;
38848
+ this.rootDocument = parent.rootDocument;
38849
+ this.root = parent.root;
38850
+ }
38851
+ [XPathNodeKindKey] = "text";
38852
+ nodeType = "static-text";
38853
+ rootDocument;
38854
+ root;
38855
+ children = null;
38856
+ // XFormsXPathText
38857
+ getXPathValue() {
38858
+ return this.value;
38859
+ }
38860
+ }
38861
+
38862
+ const leafElementChildrenResult = (parent, leafValue) => {
38863
+ const child = new StaticText(parent, leafValue);
38864
+ return {
38865
+ children: [child],
38866
+ childElements: [],
38867
+ leafValue
38868
+ };
38869
+ };
38870
+ const blankLeafElementChildrenResult = (parent) => {
38871
+ return leafElementChildrenResult(parent, "");
38872
+ };
38873
+ const buildStaticElementChildren = (parent, options) => {
38874
+ const children = Array();
38875
+ const childElements = Array();
38876
+ const childOptions = options.children ?? [""];
38877
+ if (childOptions.length === 0) {
38878
+ return {
38879
+ children,
38880
+ childElements,
38881
+ leafValue: ""
38882
+ };
38883
+ }
38884
+ const [head, ...tail] = childOptions;
38885
+ if (tail.length === 0) {
38886
+ if (head == null) {
38887
+ return blankLeafElementChildrenResult(parent);
38888
+ }
38889
+ if (typeof head === "string") {
38890
+ return leafElementChildrenResult(parent, head);
38891
+ }
38892
+ }
38893
+ if (typeof head === "string" && tail.length === 0) {
38894
+ const child = new StaticText(parent, head);
38895
+ children.push(child);
38896
+ return {
38897
+ children,
38898
+ childElements,
38899
+ leafValue: child.value
38900
+ };
38901
+ }
38902
+ for (const item of childOptions) {
38903
+ switch (typeof item) {
38904
+ case "string":
38905
+ children.push(new StaticText(parent, item));
38906
+ break;
38907
+ case "object": {
38908
+ const childElement = new StaticElement(parent, item);
38909
+ children.push(childElement);
38910
+ childElements.push(childElement);
38911
+ break;
38912
+ }
38913
+ default:
38914
+ throw new UnreachableError$1(item);
38915
+ }
38916
+ }
38917
+ return {
38918
+ children,
38919
+ childElements,
38920
+ leafValue: null
38921
+ };
38922
+ };
38923
+ class StaticElement extends StaticParentNode {
38924
+ constructor(parent, options) {
38925
+ super("element");
38926
+ this.parent = parent;
38798
38927
  const { rootDocument } = parent;
38928
+ let nodesetPrefix = parent.nodeset;
38799
38929
  this.rootDocument = rootDocument;
38800
38930
  if (parent === rootDocument) {
38801
38931
  this.root = this;
38932
+ if (nodesetPrefix === "/") {
38933
+ nodesetPrefix = "";
38934
+ }
38802
38935
  } else {
38803
38936
  this.root = parent.root;
38804
38937
  }
38805
- this.qualifiedName = new QualifiedName(options);
38806
- this.attributes = attributesFactory(this);
38807
- this.children = childNodesFactory(this);
38938
+ const { name, attributes = [] } = options;
38939
+ this.qualifiedName = staticNodeName(name);
38940
+ this.nodeset = `${nodesetPrefix}/${this.qualifiedName.getPrefixedName()}`;
38941
+ this.attributes = attributes.map((attrOptions) => {
38942
+ return new StaticAttribute(this, attrOptions);
38943
+ });
38944
+ const { children, childElements, leafValue } = buildStaticElementChildren(this, options);
38945
+ this.children = children;
38946
+ this.childElements = childElements;
38947
+ this.computedValue = leafValue;
38948
+ this.value = leafValue;
38808
38949
  }
38809
- [XFORMS_LOCAL_NAME];
38810
- [XFORMS_KNOWN_ATTRIBUTE];
38811
- [XPathNodeKindKey] = "element";
38812
- nodeType = "static-element";
38950
+ computedValue;
38813
38951
  rootDocument;
38814
38952
  root;
38815
38953
  qualifiedName;
38954
+ nodeset;
38816
38955
  attributes;
38817
38956
  children;
38818
- value = null;
38957
+ childElements;
38958
+ value;
38959
+ isLeafElement() {
38960
+ return this.value != null;
38961
+ }
38962
+ assertLeafElement() {
38963
+ if (!this.isLeafElement()) {
38964
+ throw new ErrorProductionDesignPendingError();
38965
+ }
38966
+ }
38819
38967
  /**
38820
38968
  * @todo Generalize this, incorporate into {@link EngineDOMAdapter}
38821
38969
  * @todo Namespaced lookup
@@ -38838,109 +38986,36 @@ class StaticElement extends StaticNode {
38838
38986
  getAttributeValue(localName) {
38839
38987
  const attribute = this.getAttributeNode(localName);
38840
38988
  const value = attribute?.value ?? null;
38841
- assertStaticElementKnownAttributeValue(this, localName, value);
38842
38989
  return value;
38843
38990
  }
38844
38991
  // XFormsXPathElement
38845
38992
  getXPathValue() {
38846
- return this.children.map((child) => child.getXPathValue()).join("");
38847
- }
38848
- }
38849
-
38850
- class StaticText extends StaticNode {
38851
- constructor(parent, value) {
38852
- super();
38853
- this.parent = parent;
38854
- this.value = value;
38855
- this.rootDocument = parent.rootDocument;
38856
- this.root = parent.root;
38857
- }
38858
- [XPathNodeKindKey] = "text";
38859
- nodeType = "static-text";
38860
- rootDocument;
38861
- root;
38862
- children = null;
38863
- // XFormsXPathText
38864
- getXPathValue() {
38865
- return this.value;
38993
+ const { computedValue } = this;
38994
+ if (computedValue != null) {
38995
+ return computedValue;
38996
+ }
38997
+ const result = this.children.map((child) => child.getXPathValue()).join("");
38998
+ this.computedValue = result;
38999
+ return result;
38866
39000
  }
38867
39001
  }
38868
39002
 
38869
- const domElementAttributesFactory = (domElement) => {
38870
- const attributes = Array.from(domElement.attributes);
38871
- return (element) => {
38872
- return attributes.map((attr) => {
38873
- return new StaticAttribute(element, attr);
38874
- });
38875
- };
38876
- };
38877
- const { ELEMENT_NODE, CDATA_SECTION_NODE, TEXT_NODE } = Node;
38878
- const toStaticChildNodeSource = (childNode) => {
38879
- const domType = childNode.nodeType;
38880
- switch (domType) {
38881
- case ELEMENT_NODE:
38882
- return {
38883
- domType,
38884
- domNode: childNode
38885
- };
38886
- case TEXT_NODE:
38887
- return {
38888
- domType,
38889
- domNode: childNode
38890
- };
38891
- case CDATA_SECTION_NODE:
38892
- return {
38893
- domType,
38894
- domNode: childNode
38895
- };
38896
- default:
38897
- return null;
38898
- }
38899
- };
38900
- const toStaticChildNodeSources = (childNode) => {
38901
- return toStaticChildNodeSource(childNode) ?? [];
38902
- };
38903
- const domElementChildNodesFactory = (domElement) => {
38904
- const childNodeSources = Array.from(domElement.childNodes).flatMap(toStaticChildNodeSources);
38905
- return (parent) => {
38906
- return childNodeSources.map((domSource) => {
38907
- switch (domSource.domType) {
38908
- case ELEMENT_NODE:
38909
- return parseStaticElementFromDOMElement(parent, StaticElement, domSource.domNode);
38910
- case TEXT_NODE:
38911
- case CDATA_SECTION_NODE:
38912
- return new StaticText(parent, domSource.domNode.data);
38913
- default:
38914
- throw new UnreachableError$1(domSource);
38915
- }
38916
- });
38917
- };
38918
- };
38919
- const parseStaticElementFromDOMElement = (parent, ElementConstructor, domElement) => {
38920
- const attributesFactory = domElementAttributesFactory(domElement);
38921
- const childNodesFactory = domElementChildNodesFactory(domElement);
38922
- return new ElementConstructor(parent, attributesFactory, childNodesFactory, domElement);
38923
- };
38924
- const parseStaticDocumentFromDOMSubtree = (DocumentConstructor, DocumentRootConstructor, subtreeRootElement) => {
38925
- const rootFactory = (parent) => {
38926
- return parseStaticElementFromDOMElement(parent, DocumentRootConstructor, subtreeRootElement);
38927
- };
38928
- return new DocumentConstructor(rootFactory);
38929
- };
38930
-
38931
- class StaticDocument extends StaticNode {
38932
- [XPathNodeKindKey] = "document";
38933
- nodeType = "static-document";
39003
+ class StaticDocument extends StaticParentNode {
38934
39004
  rootDocument;
38935
39005
  root;
38936
39006
  parent = null;
39007
+ nodeset;
38937
39008
  children;
38938
- constructor(rootFactory) {
38939
- super();
39009
+ childElements;
39010
+ constructor(options) {
39011
+ super("document");
39012
+ this.nodeset = options.nodesetPrefix ?? "/";
38940
39013
  this.rootDocument = this;
38941
- const root = rootFactory(this);
39014
+ const { documentRoot } = options;
39015
+ const root = new StaticElement(this, documentRoot);
38942
39016
  this.root = root;
38943
39017
  this.children = [root];
39018
+ this.childElements = this.children;
38944
39019
  }
38945
39020
  // XFormsXPathDocument
38946
39021
  getXPathValue() {
@@ -38948,41 +39023,74 @@ class StaticDocument extends StaticNode {
38948
39023
  }
38949
39024
  }
38950
39025
 
38951
- const assertItextTranslationRootKnownAttributeValue = (localName, value) => {
38952
- if (localName === "lang" && value == null) {
38953
- throw new Error("Invalid itext <translation> element: missing `lang` attribute");
38954
- }
39026
+ const parseNodeName = (domNode) => {
39027
+ return {
39028
+ namespaceURI: domNode.namespaceURI,
39029
+ prefix: domNode.prefix,
39030
+ localName: domNode.localName
39031
+ };
39032
+ };
39033
+ const parseStaticElementAttributes = (domElement) => {
39034
+ return Array.from(domElement.attributes).map((attr) => ({
39035
+ name: attr,
39036
+ value: attr.value
39037
+ }));
39038
+ };
39039
+ const { ELEMENT_NODE, CDATA_SECTION_NODE, TEXT_NODE } = Node;
39040
+ const parseStaticElementChildren = (domElement) => {
39041
+ return Array.from(domElement.childNodes).flatMap((child) => {
39042
+ switch (child.nodeType) {
39043
+ case ELEMENT_NODE:
39044
+ return parseStaticElementOptions(child);
39045
+ case TEXT_NODE:
39046
+ case CDATA_SECTION_NODE:
39047
+ return child.data;
39048
+ default:
39049
+ return [];
39050
+ }
39051
+ });
39052
+ };
39053
+ const parseStaticElementOptions = (domElement) => {
39054
+ return {
39055
+ name: parseNodeName(domElement),
39056
+ attributes: parseStaticElementAttributes(domElement),
39057
+ children: parseStaticElementChildren(domElement)
39058
+ };
39059
+ };
39060
+ const parseStaticDocumentFromDOMSubtree = (subtreeRootElement, options = {}) => {
39061
+ const documentRoot = parseStaticElementOptions(subtreeRootElement);
39062
+ return new StaticDocument({
39063
+ ...options,
39064
+ documentRoot
39065
+ });
38955
39066
  };
38956
- class ItextTranslationRootDefinition extends StaticElement {
38957
- [XFORMS_LOCAL_NAME] = "translation";
38958
- [XFORMS_KNOWN_ATTRIBUTE] = "lang";
38959
- getAttributeValue(localName) {
38960
- const value = super.getAttributeValue(localName);
38961
- assertItextTranslationRootKnownAttributeValue(localName, value);
38962
- return value;
38963
- }
38964
- }
38965
-
38966
- class ItextTranslationDefinition extends StaticDocument {
38967
- }
38968
39067
 
39068
+ const assertItextTranslationsDefinitionEntry = ([
39069
+ key,
39070
+ root
39071
+ ]) => {
39072
+ if (key == null || root.qualifiedName.localName !== "translation") {
39073
+ throw new Error();
39074
+ }
39075
+ };
39076
+ const itextTranslationNodesetPrefix = (lang) => {
39077
+ return `wf:translation('${lang}')`;
39078
+ };
38969
39079
  class ItextTranslationsDefinition extends Map {
38970
39080
  static from(xformDOM) {
38971
- const translationDefinitions = xformDOM.itextTranslationElements.map((element) => {
38972
- return parseStaticDocumentFromDOMSubtree(
38973
- ItextTranslationDefinition,
38974
- ItextTranslationRootDefinition,
38975
- element
38976
- );
39081
+ const entries = xformDOM.itextTranslationElements.map((element) => {
39082
+ const lang = element.getAttribute("lang");
39083
+ const { root } = parseStaticDocumentFromDOMSubtree(element, {
39084
+ nodesetPrefix: itextTranslationNodesetPrefix(lang)
39085
+ });
39086
+ const entry = [lang, root];
39087
+ assertItextTranslationsDefinitionEntry(entry);
39088
+ return entry;
38977
39089
  });
38978
- return new this(translationDefinitions);
39090
+ return new this(entries);
38979
39091
  }
38980
- constructor(translations) {
38981
- super(
38982
- translations.map(({ root }) => {
38983
- return [root.getAttributeValue("lang"), root];
38984
- })
38985
- );
39092
+ constructor(entries) {
39093
+ super(entries);
38986
39094
  }
38987
39095
  }
38988
39096
 
@@ -39288,6 +39396,24 @@ class ModelBindMap extends Map {
39288
39396
  }
39289
39397
  }
39290
39398
 
39399
+ const collectDefinitions = (result, definition) => {
39400
+ const { nodeset } = definition;
39401
+ if (result.has(nodeset)) {
39402
+ throw new ErrorProductionDesignPendingError();
39403
+ }
39404
+ result.set(nodeset, definition);
39405
+ if (definition.type === "leaf-node") {
39406
+ return result;
39407
+ }
39408
+ for (const child of definition.children) {
39409
+ collectDefinitions(result, child);
39410
+ }
39411
+ return result;
39412
+ };
39413
+ const nodeDefinitionMap = (root) => {
39414
+ return collectDefinitions(/* @__PURE__ */ new Map(), root);
39415
+ };
39416
+
39291
39417
  const ATTR_REGEX = /[&<>"]/;
39292
39418
  const CONTENT_REGEX = /[&<>]/;
39293
39419
  const escapeXMLText = (text, attr) => {
@@ -39597,24 +39723,21 @@ class DescendentNodeDefinition extends NodeDefinition {
39597
39723
  }
39598
39724
 
39599
39725
  class LeafNodeDefinition extends DescendentNodeDefinition {
39600
- constructor(parent, bind, bodyElement, node) {
39726
+ constructor(parent, bind, bodyElement, template) {
39601
39727
  if (bodyElement != null && bodyElement.category !== "control") {
39602
39728
  throw new Error(`Unexpected body element for nodeset ${bind.nodeset}`);
39603
39729
  }
39604
39730
  super(parent, bind, bodyElement);
39605
- this.node = node;
39731
+ this.template = template;
39606
39732
  this.valueType = bind.type.resolved;
39607
- this.qualifiedName = new QualifiedName(node);
39733
+ this.qualifiedName = template.qualifiedName;
39608
39734
  this.namespaceDeclarations = new NamespaceDeclarationMap(this);
39609
- this.defaultValue = node.textContent ?? "";
39610
39735
  }
39611
39736
  type = "leaf-node";
39612
39737
  valueType;
39613
39738
  namespaceDeclarations;
39614
39739
  qualifiedName;
39615
39740
  children = null;
39616
- instances = null;
39617
- defaultValue;
39618
39741
  toJSON() {
39619
39742
  const { bind, bodyElement, parent, root, ...rest } = this;
39620
39743
  return rest;
@@ -39625,8 +39748,8 @@ const isNoteBindDefinition = (bind) => {
39625
39748
  return bind.readonly.isConstantTruthyExpression();
39626
39749
  };
39627
39750
  class NoteNodeDefinition extends LeafNodeDefinition {
39628
- constructor(parent, bind, bodyElement, noteTextDefinition, node) {
39629
- super(parent, bind, bodyElement, node);
39751
+ constructor(parent, bind, bodyElement, noteTextDefinition, template) {
39752
+ super(parent, bind, bodyElement, template);
39630
39753
  this.bind = bind;
39631
39754
  this.bodyElement = bodyElement;
39632
39755
  this.noteTextDefinition = noteTextDefinition;
@@ -39867,20 +39990,22 @@ class IntValueCodec extends ValueCodec {
39867
39990
  }
39868
39991
  }
39869
39992
 
39993
+ const identity = (value) => value;
39994
+
39870
39995
  class StringValueCodec extends ValueCodec {
39871
39996
  constructor() {
39872
- super("string", identity$1, identity$1, {
39873
- decodeInstanceValueFactory: () => identity$1,
39874
- runtimeValueStateFactory: () => identity$1
39997
+ super("string", identity, identity, {
39998
+ decodeInstanceValueFactory: () => identity,
39999
+ runtimeValueStateFactory: () => identity
39875
40000
  });
39876
40001
  }
39877
40002
  }
39878
40003
 
39879
40004
  class ValueTypePlaceholderCodec extends ValueCodec {
39880
40005
  constructor(valueType) {
39881
- super(valueType, identity$1, identity$1, {
39882
- decodeInstanceValueFactory: () => identity$1,
39883
- runtimeValueStateFactory: () => identity$1
40006
+ super(valueType, identity, identity, {
40007
+ decodeInstanceValueFactory: () => identity,
40008
+ runtimeValueStateFactory: () => identity
39884
40009
  });
39885
40010
  }
39886
40011
  }
@@ -39967,131 +40092,70 @@ class RepeatCountControlExpression extends DependentExpression {
39967
40092
  }
39968
40093
  }
39969
40094
 
39970
- class RepeatInstanceDefinition extends DescendentNodeDefinition {
39971
- constructor(range, node) {
39972
- const { bind, bodyElement, parent, root } = range;
39973
- super(parent, bind, bodyElement);
39974
- this.node = node;
39975
- this.qualifiedName = new QualifiedName(node);
39976
- this.namespaceDeclarations = new NamespaceDeclarationMap(this);
39977
- this.children = root.buildSubtree(this);
39978
- }
39979
- type = "repeat-instance";
39980
- namespaceDeclarations;
39981
- qualifiedName;
39982
- children;
39983
- instances = null;
39984
- defaultValue = null;
39985
- toJSON() {
39986
- const { bind, bodyElement, parent, root, ...rest } = this;
39987
- return rest;
40095
+ const isJRTemplateAttributeName = (name) => {
40096
+ if (name.localName !== "template") {
40097
+ return false;
39988
40098
  }
39989
- }
39990
-
39991
- const repeatTemplates = /* @__PURE__ */ new WeakMap();
39992
- const isExplicitRepeatTemplateElement = (element) => {
39993
- return element.hasAttributeNS(JAVAROSA_NAMESPACE_URI$1, "template");
40099
+ const namespaceURI = name.namespaceURI?.href ?? name.namespaceURI;
40100
+ return namespaceURI === JAVAROSA_NAMESPACE_URI$1;
39994
40101
  };
39995
- const isLeafNode = (element) => {
39996
- return element.childElementCount === 0;
40102
+ const isJRTemplateAttribute = (attribute) => {
40103
+ return isJRTemplateAttributeName(attribute.qualifiedName);
39997
40104
  };
39998
- const clearLeafNodes = (element) => {
39999
- if (isLeafNode(element)) {
40000
- element.textContent = "";
40001
- } else {
40002
- for (const child of element.children) {
40003
- clearLeafNodes(child);
40004
- }
40005
- }
40006
- return element;
40105
+ const isExplicitRepeatTemplateElement = (sourceElement) => {
40106
+ return sourceElement.attributes.some(isJRTemplateAttribute);
40007
40107
  };
40008
- const getOrCreateTemplateElement = (element) => {
40009
- if (isExplicitRepeatTemplateElement(element)) {
40010
- return element;
40011
- }
40012
- const clone = element.cloneNode(true);
40013
- clone.setAttributeNS(JAVAROSA_NAMESPACE_URI$1, "template", "");
40014
- return clearLeafNodes(clone);
40108
+ const cloneStaticAttributeOptions = (attribute) => {
40109
+ return {
40110
+ name: attribute.qualifiedName,
40111
+ value: attribute.value
40112
+ };
40113
+ };
40114
+ const cloneStaticSubtreeStructure = (sourceElement) => {
40115
+ const name = sourceElement.qualifiedName;
40116
+ const attributes = sourceElement.attributes.map(cloneStaticAttributeOptions);
40117
+ const children = sourceElement.childElements.map(cloneStaticSubtreeStructure);
40118
+ return {
40119
+ name,
40120
+ attributes,
40121
+ children
40122
+ };
40015
40123
  };
40016
- const splitInstanceNodes = (modelNodes) => {
40017
- const [first, ...rest] = modelNodes;
40018
- const template = getOrCreateTemplateElement(first);
40019
- if (template === first) {
40020
- return [template, ...rest];
40124
+ const cloneStaticElementStructure = (sourceElement) => {
40125
+ const { root: clone } = new StaticDocument({
40126
+ documentRoot: cloneStaticSubtreeStructure(sourceElement),
40127
+ nodesetPrefix: sourceElement.parent.nodeset
40128
+ });
40129
+ return clone;
40130
+ };
40131
+ const parseRepeatTemplateElement = (firstRepeatInstanceNode) => {
40132
+ if (isExplicitRepeatTemplateElement(firstRepeatInstanceNode)) {
40133
+ return firstRepeatInstanceNode;
40021
40134
  }
40022
- return [template, ...modelNodes];
40135
+ return cloneStaticElementStructure(firstRepeatInstanceNode);
40023
40136
  };
40024
- class RepeatTemplateDefinition extends DescendentNodeDefinition {
40025
- constructor(range, templateNode) {
40026
- const { bind, bodyElement, parent, root } = range;
40027
- super(parent, bind, bodyElement);
40028
- this.templateNode = templateNode;
40029
- const node = templateNode.cloneNode(true);
40030
- node.removeAttributeNS(JAVAROSA_NAMESPACE_URI$1, "template");
40031
- this.node = node;
40032
- this.qualifiedName = new QualifiedName(node);
40033
- this.namespaceDeclarations = new NamespaceDeclarationMap(this);
40034
- this.children = root.buildSubtree(this);
40035
- }
40036
- static parseModelNodes(range, modelNodes) {
40037
- const { bind } = range;
40038
- let template = repeatTemplates.get(bind);
40039
- let instanceNodes;
40040
- if (template == null) {
40041
- const [templateNode, ...rest] = splitInstanceNodes(modelNodes);
40042
- instanceNodes = rest;
40043
- template = new this(range, templateNode);
40044
- } else {
40045
- const duplicateTemplate = modelNodes.find(
40046
- (node) => node.hasAttributeNS(JAVAROSA_NAMESPACE_URI$1, "template")
40047
- );
40048
- if (duplicateTemplate != null) {
40049
- throw new Error(`Multiple explicit templates defined for ${bind.nodeset}`);
40050
- }
40051
- instanceNodes = modelNodes;
40052
- }
40053
- return {
40054
- template,
40055
- instanceNodes
40056
- };
40137
+ class RepeatDefinition extends DescendentNodeDefinition {
40138
+ static from(parent, bind, bodyElement, instanceNodes) {
40139
+ return new this(parent, bind, bodyElement, instanceNodes);
40057
40140
  }
40058
- type = "repeat-template";
40059
- node;
40060
- namespaceDeclarations;
40061
- qualifiedName;
40141
+ type = "repeat";
40062
40142
  children;
40063
- instances = null;
40064
- defaultValue = null;
40065
- toJSON() {
40066
- const { bind, bodyElement, parent, root, ...rest } = this;
40067
- return rest;
40068
- }
40069
- }
40070
-
40071
- class RepeatRangeDefinition extends DescendentNodeDefinition {
40072
- static from(parent, bind, bodyElement, modelNodes) {
40073
- const definition = new this(parent, bind, bodyElement, modelNodes);
40074
- return definition;
40075
- }
40076
- type = "repeat-range";
40077
- template;
40078
- children = null;
40079
- instances;
40080
40143
  count;
40081
- node = null;
40144
+ template;
40082
40145
  namespaceDeclarations;
40083
40146
  qualifiedName;
40084
- defaultValue = null;
40085
- constructor(parent, bind, bodyElement, modelNodes) {
40147
+ constructor(parent, bind, bodyElement, instanceNodes) {
40086
40148
  super(parent, bind, bodyElement);
40087
- const { template, instanceNodes } = RepeatTemplateDefinition.parseModelNodes(this, modelNodes);
40149
+ const { root } = parent;
40150
+ const [instanceNode] = instanceNodes;
40151
+ const template = parseRepeatTemplateElement(instanceNode);
40152
+ const self = this;
40088
40153
  this.template = template;
40089
40154
  this.qualifiedName = template.qualifiedName;
40090
40155
  this.namespaceDeclarations = new NamespaceDeclarationMap(this);
40091
- this.count = RepeatCountControlExpression.from(bodyElement, instanceNodes.length);
40092
- this.instances = instanceNodes.map((element) => {
40093
- return new RepeatInstanceDefinition(this, element);
40094
- });
40156
+ this.children = root.buildSubtree(self, template);
40157
+ const initialCount = this.omitTemplate(instanceNodes).length;
40158
+ this.count = RepeatCountControlExpression.from(bodyElement, initialCount);
40095
40159
  }
40096
40160
  isControlled() {
40097
40161
  return this.count != null;
@@ -40099,9 +40163,13 @@ class RepeatRangeDefinition extends DescendentNodeDefinition {
40099
40163
  isUncontrolled() {
40100
40164
  return this.count == null;
40101
40165
  }
40166
+ omitTemplate(instanceNodes) {
40167
+ return instanceNodes.filter((instanceNode) => {
40168
+ return instanceNode !== this.template;
40169
+ });
40170
+ }
40102
40171
  toJSON() {
40103
- const { bind, bodyElement: groupDefinition, parent, root, ...rest } = this;
40104
- return rest;
40172
+ return {};
40105
40173
  }
40106
40174
  }
40107
40175
 
@@ -40111,13 +40179,14 @@ class RootAttributeDefinition {
40111
40179
  qualifiedName;
40112
40180
  value;
40113
40181
  constructor(root, source) {
40114
- const { namespaceURI, nodeName, value } = source;
40182
+ const { qualifiedName, value } = source;
40115
40183
  this.parent = root;
40116
- this.qualifiedName = new QualifiedName(source);
40184
+ this.qualifiedName = qualifiedName;
40117
40185
  this.value = value;
40118
- if (namespaceURI === XMLNS_NAMESPACE_URI$1) {
40186
+ if (qualifiedName.namespaceURI?.href === XMLNS_NAMESPACE_URI$1) {
40119
40187
  this.serializedXML = "";
40120
40188
  } else {
40189
+ const nodeName = qualifiedName.getPrefixedName();
40121
40190
  this.serializedXML = ` ${nodeName}="${escapeXMLText(value, true)}"`;
40122
40191
  }
40123
40192
  }
@@ -40126,21 +40195,20 @@ class RootAttributeDefinition {
40126
40195
  }
40127
40196
  }
40128
40197
 
40129
- const isNonNamespaceDeclarationDOMAttr = (domAttr) => {
40130
- return domAttr.namespaceURI !== XMLNS_NAMESPACE_URI$1;
40198
+ const isNonNamespaceAttribute = (attribute) => {
40199
+ return attribute.qualifiedName.namespaceURI?.href !== XMLNS_NAMESPACE_URI$1;
40131
40200
  };
40132
40201
  class RootAttributeMap extends Map {
40133
- static from(root, domRootSourceElement) {
40134
- const domAttrs = Array.from(domRootSourceElement.attributes);
40135
- const nonNamespaceDeclarationDOMAttrs = domAttrs.filter(isNonNamespaceDeclarationDOMAttr);
40136
- const attributes = nonNamespaceDeclarationDOMAttrs.map((source) => {
40137
- return new RootAttributeDefinition(root, source);
40202
+ static from(root, instanceNode) {
40203
+ const nonNamespaceAttributes = instanceNode.attributes.filter(isNonNamespaceAttribute);
40204
+ const definitions = nonNamespaceAttributes.map((attribute) => {
40205
+ return new RootAttributeDefinition(root, attribute);
40138
40206
  });
40139
- return new this(attributes);
40207
+ return new this(definitions);
40140
40208
  }
40141
- constructor(attributes) {
40209
+ constructor(definitions) {
40142
40210
  super(
40143
- attributes.map((attribute) => {
40211
+ definitions.map((attribute) => {
40144
40212
  return [attribute.qualifiedName, attribute];
40145
40213
  })
40146
40214
  );
@@ -40148,23 +40216,21 @@ class RootAttributeMap extends Map {
40148
40216
  }
40149
40217
 
40150
40218
  class SubtreeDefinition extends DescendentNodeDefinition {
40151
- constructor(parent, bind, bodyElement, node) {
40219
+ constructor(parent, bind, bodyElement, template) {
40152
40220
  if (bodyElement != null && (bodyElement.category !== "structure" || bodyElement.type === "repeat")) {
40153
40221
  throw new Error(`Unexpected body element for nodeset ${bind.nodeset}`);
40154
40222
  }
40155
40223
  super(parent, bind, bodyElement);
40156
- this.node = node;
40224
+ this.template = template;
40157
40225
  const { root } = parent;
40158
- this.qualifiedName = new QualifiedName(node);
40226
+ this.qualifiedName = template.qualifiedName;
40159
40227
  this.namespaceDeclarations = new NamespaceDeclarationMap(this);
40160
- this.children = root.buildSubtree(this);
40228
+ this.children = root.buildSubtree(this, template);
40161
40229
  }
40162
40230
  type = "subtree";
40163
40231
  namespaceDeclarations;
40164
40232
  qualifiedName;
40165
40233
  children;
40166
- instances = null;
40167
- defaultValue = null;
40168
40234
  toJSON() {
40169
40235
  const { parent, bodyElement, bind, root, ...rest } = this;
40170
40236
  return rest;
@@ -40173,8 +40239,8 @@ class SubtreeDefinition extends DescendentNodeDefinition {
40173
40239
 
40174
40240
  class RootDefinition extends NodeDefinition {
40175
40241
  constructor(form, model, submission, classes) {
40176
- const { primaryInstanceRoot } = form.xformDOM;
40177
- const qualifiedName = new QualifiedName(primaryInstanceRoot);
40242
+ const template = model.instance.root;
40243
+ const qualifiedName = template.qualifiedName;
40178
40244
  const nodeName = qualifiedName.getPrefixedName();
40179
40245
  const nodeset = `/${nodeName}`;
40180
40246
  const bind = model.binds.get(nodeset);
@@ -40187,32 +40253,30 @@ class RootDefinition extends NodeDefinition {
40187
40253
  this.submission = submission;
40188
40254
  this.classes = classes;
40189
40255
  this.qualifiedName = qualifiedName;
40190
- this.node = primaryInstanceRoot;
40191
- this.attributes = RootAttributeMap.from(this, primaryInstanceRoot);
40256
+ this.template = template;
40257
+ this.attributes = RootAttributeMap.from(this, template);
40192
40258
  this.namespaceDeclarations = new NamespaceDeclarationMap(this);
40193
- this.children = this.buildSubtree(this);
40259
+ this.children = this.buildSubtree(this, template);
40194
40260
  }
40195
40261
  type = "root";
40196
40262
  qualifiedName;
40197
40263
  bodyElement = null;
40198
40264
  root = this;
40199
40265
  parent = null;
40266
+ template;
40200
40267
  namespaceDeclarations;
40201
40268
  attributes;
40202
40269
  children;
40203
- instances = null;
40204
- node;
40205
- defaultValue = null;
40206
40270
  isTranslated = false;
40207
- buildSubtree(parent) {
40271
+ buildSubtree(parent, node) {
40208
40272
  const { form, model } = this;
40209
40273
  const { body } = form;
40210
40274
  const { binds } = model;
40211
- const { bind: parentBind, node } = parent;
40275
+ const { bind: parentBind } = parent;
40212
40276
  const { nodeset: parentNodeset } = parentBind;
40213
40277
  const childrenByName = /* @__PURE__ */ new Map();
40214
- for (const child of node.children) {
40215
- const { nodeName } = child;
40278
+ for (const child of node.childElements) {
40279
+ const nodeName = child.qualifiedName.getPrefixedName();
40216
40280
  let elements = childrenByName.get(nodeName);
40217
40281
  if (elements == null) {
40218
40282
  elements = [child];
@@ -40227,14 +40291,13 @@ class RootDefinition extends NodeDefinition {
40227
40291
  const bodyElement = body.getBodyElement(nodeset);
40228
40292
  const [firstChild, ...restChildren] = children;
40229
40293
  if (bodyElement?.type === "repeat") {
40230
- return RepeatRangeDefinition.from(parent, bind, bodyElement, children);
40294
+ return RepeatDefinition.from(parent, bind, bodyElement, children);
40231
40295
  }
40232
40296
  if (restChildren.length) {
40233
40297
  throw new Error(`Unexpected: multiple elements for non-repeat nodeset: ${nodeset}`);
40234
40298
  }
40235
40299
  const element = firstChild;
40236
- const isLeafNode = element.childElementCount === 0;
40237
- if (isLeafNode) {
40300
+ if (element.isLeafElement()) {
40238
40301
  if (bodyElement?.type === "range") {
40239
40302
  return RangeNodeDefinition.from(parent, bind, bodyElement, element);
40240
40303
  }
@@ -40249,17 +40312,69 @@ class RootDefinition extends NodeDefinition {
40249
40312
  }
40250
40313
  }
40251
40314
 
40315
+ class SubmissionDefinition {
40316
+ submissionAction;
40317
+ submissionMethod = "post";
40318
+ encryptionKey;
40319
+ constructor(xformDOM) {
40320
+ const submissionElement = getSubmissionElement(xformDOM.model);
40321
+ let submissionAction = null;
40322
+ let submissionMethod;
40323
+ let encryptionKey = null;
40324
+ if (submissionElement == null) {
40325
+ submissionAction = null;
40326
+ submissionMethod = "post";
40327
+ encryptionKey = null;
40328
+ } else {
40329
+ const method = submissionElement.getAttribute("method")?.trim();
40330
+ if (method == null || method === "post" || method === "form-data-post") {
40331
+ submissionMethod = "post";
40332
+ } else {
40333
+ throw new Error(`Unexpected <submission method>: ${method}`);
40334
+ }
40335
+ const action = submissionElement.getAttribute("action");
40336
+ if (action != null) {
40337
+ submissionAction = new URL(action.trim());
40338
+ }
40339
+ encryptionKey = submissionElement.getAttribute("base64RsaPublicKey");
40340
+ }
40341
+ this.submissionAction = submissionAction;
40342
+ this.submissionMethod = submissionMethod;
40343
+ this.encryptionKey = encryptionKey;
40344
+ }
40345
+ }
40346
+
40252
40347
  class ModelDefinition {
40253
40348
  constructor(form) {
40254
40349
  this.form = form;
40255
- const submission = new FormSubmissionDefinition(form.xformDOM);
40350
+ const submission = new SubmissionDefinition(form.xformDOM);
40256
40351
  this.binds = ModelBindMap.fromModel(this);
40352
+ this.instance = parseStaticDocumentFromDOMSubtree(form.xformDOM.primaryInstanceRoot, {
40353
+ nodesetPrefix: "/"
40354
+ });
40257
40355
  this.root = new RootDefinition(form, this, submission, form.body.classes);
40356
+ this.nodes = nodeDefinitionMap(this.root);
40258
40357
  this.itextTranslations = ItextTranslationsDefinition.from(form.xformDOM);
40259
40358
  }
40260
40359
  binds;
40261
40360
  root;
40361
+ nodes;
40362
+ instance;
40262
40363
  itextTranslations;
40364
+ getNodeDefinition(nodeset) {
40365
+ const definition = this.nodes.get(nodeset);
40366
+ if (definition == null) {
40367
+ throw new ErrorProductionDesignPendingError(`No definition for nodeset: ${nodeset}`);
40368
+ }
40369
+ return definition;
40370
+ }
40371
+ getRootDefinition(instance) {
40372
+ const definition = this.getNodeDefinition(instance.root.nodeset);
40373
+ if (definition !== this.root) {
40374
+ throw new ErrorProductionDesignPendingError();
40375
+ }
40376
+ return definition;
40377
+ }
40263
40378
  toJSON() {
40264
40379
  const { form, ...rest } = this;
40265
40380
  return rest;
@@ -40305,13 +40420,30 @@ class JRResourceURL extends URL {
40305
40420
  }
40306
40421
  }
40307
40422
 
40308
- class SecondaryInstanceRootDefinition extends StaticElement {
40309
- [XFORMS_LOCAL_NAME] = "instance";
40310
- [XFORMS_KNOWN_ATTRIBUTE] = "id";
40311
- }
40423
+ const assertSecondaryInstanceDefinition = ({ root }) => {
40424
+ const id = root.getAttributeValue("id");
40425
+ if (id == null) {
40426
+ throw new Error();
40427
+ }
40428
+ };
40312
40429
 
40313
- class SecondaryInstanceDefinition extends StaticDocument {
40314
- }
40430
+ const defineSecondaryInstance = (instanceId, secondaryInstanceRoot) => {
40431
+ const doc = new StaticDocument({
40432
+ documentRoot: {
40433
+ name: "instance",
40434
+ attributes: [
40435
+ {
40436
+ name: "id",
40437
+ value: instanceId
40438
+ }
40439
+ ],
40440
+ children: [secondaryInstanceRoot]
40441
+ },
40442
+ nodesetPrefix: `instance('${instanceId}')`
40443
+ });
40444
+ assertSecondaryInstanceDefinition(doc);
40445
+ return doc;
40446
+ };
40315
40447
 
40316
40448
  class SecondaryInstanceSource {
40317
40449
  constructor(format, instanceId, resourceURL, domElement) {
@@ -40326,24 +40458,8 @@ class BlankSecondaryInstanceSource extends SecondaryInstanceSource {
40326
40458
  constructor(instanceId, resourceURL, domElement) {
40327
40459
  super("blank", instanceId, resourceURL, domElement);
40328
40460
  }
40329
- /**
40330
- * @todo there is really no sense in using the DOM for this, other than it was
40331
- * quicker/more ergonomic than constructing the requisite {@link StaticNode}
40332
- * structures directly. Pretty good sign those constructor signatures could
40333
- * use some TLC!
40334
- */
40335
40461
  parseDefinition() {
40336
- const xmlDocument = this.domElement.ownerDocument.implementation.createDocument(
40337
- XFORMS_NAMESPACE_URI$1,
40338
- "instance"
40339
- );
40340
- const instanceElement = xmlDocument.documentElement;
40341
- instanceElement.setAttribute("id", this.instanceId);
40342
- return parseStaticDocumentFromDOMSubtree(
40343
- SecondaryInstanceDefinition,
40344
- SecondaryInstanceRootDefinition,
40345
- instanceElement
40346
- );
40462
+ return defineSecondaryInstance(this.instanceId, "");
40347
40463
  }
40348
40464
  }
40349
40465
 
@@ -40406,80 +40522,28 @@ const stripTrailingEmptyCells = (columns, row) => {
40406
40522
  }
40407
40523
  return result;
40408
40524
  };
40409
- class CSVExternalSecondaryInstanceColumnElement extends StaticElement {
40410
- constructor(parent, column) {
40411
- const { columnName, cellValue } = column;
40412
- super(
40413
- parent,
40414
- () => [],
40415
- (self) => [new StaticText(self, cellValue)],
40416
- {
40417
- namespaceURI: XFORMS_NAMESPACE_URI$1,
40418
- localName: columnName
40419
- }
40420
- );
40421
- }
40422
- }
40423
- class CSVExternalSecondaryInstanceItemElement extends StaticElement {
40424
- constructor(parent, item) {
40425
- super(
40426
- parent,
40427
- () => [],
40428
- (self) => {
40429
- return item.map((column) => {
40430
- return new CSVExternalSecondaryInstanceColumnElement(self, column);
40431
- });
40432
- },
40433
- {
40434
- namespaceURI: XFORMS_NAMESPACE_URI$1,
40435
- localName: "item"
40436
- }
40437
- );
40438
- }
40439
- }
40440
- class CSVExternalSecondaryInstanceRootElement extends StaticElement {
40441
- constructor(parent, items) {
40442
- super(
40443
- parent,
40444
- () => [],
40445
- (self) => {
40446
- return items.map((item) => {
40447
- return new CSVExternalSecondaryInstanceItemElement(self, item);
40448
- });
40449
- },
40450
- {
40451
- namespaceURI: XFORMS_NAMESPACE_URI$1,
40452
- localName: "root"
40453
- }
40454
- );
40455
- }
40456
- }
40457
- class CSVExternalSecondaryInstanceDocumentElement extends SecondaryInstanceRootDefinition {
40458
- constructor(instanceId, parent, items) {
40459
- super(
40460
- parent,
40461
- (self) => [
40462
- new StaticAttribute(self, {
40463
- namespaceURI: XFORMS_NAMESPACE_URI$1,
40464
- localName: "id",
40465
- value: instanceId
40466
- })
40467
- ],
40468
- (self) => [new CSVExternalSecondaryInstanceRootElement(self, items)],
40469
- {
40470
- namespaceURI: XFORMS_NAMESPACE_URI$1,
40471
- localName: "instance"
40472
- }
40473
- );
40474
- }
40475
- }
40476
- class CSVExternalSecondaryInstanceDefinition extends SecondaryInstanceDefinition {
40477
- constructor(instanceId, items) {
40478
- super((self) => {
40479
- return new CSVExternalSecondaryInstanceDocumentElement(instanceId, self, items);
40480
- });
40481
- }
40482
- }
40525
+ const columnChildOption = (column) => {
40526
+ const { columnName, cellValue } = column;
40527
+ return {
40528
+ name: columnName,
40529
+ children: [cellValue]
40530
+ };
40531
+ };
40532
+ const itemChildOption$1 = (item) => {
40533
+ return {
40534
+ name: "item",
40535
+ children: item.map(columnChildOption)
40536
+ };
40537
+ };
40538
+ const rootChildOption$1 = (items) => {
40539
+ return {
40540
+ name: "root",
40541
+ children: items.map(itemChildOption$1)
40542
+ };
40543
+ };
40544
+ const csvExternalSecondaryInstanceDefinition = (instanceId, items) => {
40545
+ return defineSecondaryInstance(instanceId, rootChildOption$1(items));
40546
+ };
40483
40547
  class CSVExternalSecondaryInstanceSource extends ExternalSecondaryInstanceSource {
40484
40548
  /**
40485
40549
  * Based on
@@ -40567,7 +40631,7 @@ class CSVExternalSecondaryInstanceSource extends ExternalSecondaryInstanceSource
40567
40631
  delimiter: meta.delimiter
40568
40632
  });
40569
40633
  const items = this.toItems(columns, rows);
40570
- return new CSVExternalSecondaryInstanceDefinition(this.instanceId, items);
40634
+ return csvExternalSecondaryInstanceDefinition(this.instanceId, items);
40571
40635
  }
40572
40636
  }
40573
40637
 
@@ -40816,134 +40880,72 @@ const serializeCoordinates = (coordinates) => {
40816
40880
  const [longitude, latitude] = coordinates;
40817
40881
  return `${latitude} ${longitude} 0 0`;
40818
40882
  };
40819
- class GeoJSONSecondaryInstanceFeatureGeometryElement extends StaticElement {
40820
- static from(parent, feature) {
40821
- const { geometry } = feature;
40822
- switch (geometry.type) {
40823
- case "LineString":
40824
- return new this(parent, geometry.coordinates);
40825
- case "Point":
40826
- return new this(parent, [geometry.coordinates]);
40827
- case "Polygon":
40828
- return new this(parent, geometry.coordinates[0] ?? []);
40829
- default:
40830
- throw new UnreachableError$1(geometry);
40831
- }
40832
- }
40833
- constructor(parent, points) {
40834
- const values = points.map(serializeCoordinates);
40835
- const value = values.join("; ");
40836
- super(
40837
- parent,
40838
- () => [],
40839
- (self) => [new StaticText(self, value)],
40840
- {
40841
- namespaceURI: XFORMS_NAMESPACE_URI$1,
40842
- localName: "geometry"
40843
- }
40844
- );
40845
- }
40846
- }
40847
- class GeoJSONSecondaryInstanceFeaturePropertyElement extends StaticElement {
40848
- static *buildPropertyElements(parent, feature) {
40849
- const { properties } = feature;
40850
- if (properties == null) {
40851
- return [];
40852
- }
40853
- const { id: propertiesId, ...nonIdProperties } = properties;
40854
- const { id = propertiesId } = feature;
40855
- if (id !== undefined) {
40856
- yield new this(parent, "id", String(id));
40883
+ const geometryValues = (geometry) => {
40884
+ switch (geometry.type) {
40885
+ case "LineString":
40886
+ return geometry.coordinates.map(serializeCoordinates);
40887
+ case "Point":
40888
+ return [serializeCoordinates(geometry.coordinates)];
40889
+ case "Polygon": {
40890
+ const [coordinates = []] = geometry.coordinates;
40891
+ return coordinates.map(serializeCoordinates);
40857
40892
  }
40858
- for (const [propertyName, propertyValue] of Object.entries(nonIdProperties)) {
40859
- yield new this(parent, propertyName, String(propertyValue));
40860
- }
40861
- }
40862
- constructor(parent, propertyName, propertyValue) {
40863
- super(
40864
- parent,
40865
- () => [],
40866
- (self) => [new StaticText(self, propertyValue)],
40867
- {
40868
- namespaceURI: XFORMS_NAMESPACE_URI$1,
40869
- localName: propertyName
40870
- }
40871
- );
40872
- }
40873
- }
40874
- class GeoJSONSecondaryInstanceFeatureItemElement extends StaticElement {
40875
- constructor(parent, feature) {
40876
- super(
40877
- parent,
40878
- () => [],
40879
- (self) => {
40880
- const geometry = GeoJSONSecondaryInstanceFeatureGeometryElement.from(self, feature);
40881
- const properties = GeoJSONSecondaryInstanceFeaturePropertyElement.buildPropertyElements(
40882
- self,
40883
- feature
40884
- );
40885
- return [geometry, ...properties];
40886
- },
40887
- {
40888
- namespaceURI: XFORMS_NAMESPACE_URI$1,
40889
- localName: "item"
40890
- }
40891
- );
40893
+ default:
40894
+ throw new UnreachableError$1(geometry);
40892
40895
  }
40893
- }
40894
- class GeoJSONSecondaryInstanceRootElement extends StaticElement {
40895
- constructor(parent, featureCollection) {
40896
- super(
40897
- parent,
40898
- () => [],
40899
- (self) => {
40900
- return featureCollection.features.map((feature) => {
40901
- return new GeoJSONSecondaryInstanceFeatureItemElement(self, feature);
40902
- });
40903
- },
40904
- {
40905
- namespaceURI: XFORMS_NAMESPACE_URI$1,
40906
- localName: "root"
40907
- }
40908
- );
40896
+ };
40897
+ const geometryChildElementOption = (feature) => {
40898
+ const { geometry } = feature;
40899
+ const values = geometryValues(geometry);
40900
+ const value = values.join("; ");
40901
+ return {
40902
+ name: "geometry",
40903
+ children: [value]
40904
+ };
40905
+ };
40906
+ const propertyChildOption = (propertyName, propertyValue) => {
40907
+ return {
40908
+ name: propertyName,
40909
+ children: [propertyValue]
40910
+ };
40911
+ };
40912
+ function* propertyChildOptions(feature) {
40913
+ const { properties } = feature;
40914
+ if (properties == null) {
40915
+ return [];
40909
40916
  }
40910
- }
40911
- class GeoJSONExternalSecondaryInstanceDocumentElement extends SecondaryInstanceRootDefinition {
40912
- constructor(instanceId, parent, featureCollection) {
40913
- super(
40914
- parent,
40915
- (self) => [
40916
- new StaticAttribute(self, {
40917
- namespaceURI: XFORMS_NAMESPACE_URI$1,
40918
- localName: "id",
40919
- value: instanceId
40920
- })
40921
- ],
40922
- (self) => [new GeoJSONSecondaryInstanceRootElement(self, featureCollection)],
40923
- {
40924
- namespaceURI: XFORMS_NAMESPACE_URI$1,
40925
- localName: "instance"
40926
- }
40927
- );
40917
+ const { id: propertiesId, ...nonIdProperties } = properties;
40918
+ const { id = propertiesId } = feature;
40919
+ if (id !== undefined) {
40920
+ yield propertyChildOption("id", String(id));
40928
40921
  }
40929
- }
40930
- class GeoJSONExternalSecondaryInstanceDefinition extends SecondaryInstanceDefinition {
40931
- constructor(instanceId, featureCollection) {
40932
- super((self) => {
40933
- return new GeoJSONExternalSecondaryInstanceDocumentElement(
40934
- instanceId,
40935
- self,
40936
- featureCollection
40937
- );
40938
- });
40922
+ for (const [propertyName, propertyValue] of Object.entries(nonIdProperties)) {
40923
+ yield propertyChildOption(propertyName, String(propertyValue));
40939
40924
  }
40940
40925
  }
40926
+ const itemChildOption = (feature) => {
40927
+ const geometry = geometryChildElementOption(feature);
40928
+ const properties = propertyChildOptions(feature);
40929
+ return {
40930
+ name: "item",
40931
+ children: [geometry, ...properties]
40932
+ };
40933
+ };
40934
+ const rootChildOption = (featureCollection) => {
40935
+ return {
40936
+ name: "root",
40937
+ children: featureCollection.features.map(itemChildOption)
40938
+ };
40939
+ };
40940
+ const geoJSONExternalSecondaryInstanceDefinition = (instanceId, featureCollection) => {
40941
+ return defineSecondaryInstance(instanceId, rootChildOption(featureCollection));
40942
+ };
40941
40943
  class GeoJSONExternalSecondaryInstanceSource extends ExternalSecondaryInstanceSource {
40942
40944
  parseDefinition() {
40943
40945
  const { data } = this.resource;
40944
40946
  const value = JSON.parse(data);
40945
40947
  assertFeatureCollection(value);
40946
- return new GeoJSONExternalSecondaryInstanceDefinition(this.instanceId, value);
40948
+ return geoJSONExternalSecondaryInstanceDefinition(this.instanceId, value);
40947
40949
  }
40948
40950
  }
40949
40951
 
@@ -40952,11 +40954,11 @@ class InternalSecondaryInstanceSource extends SecondaryInstanceSource {
40952
40954
  super("internal", instanceId, resourceURL, domElement);
40953
40955
  }
40954
40956
  parseDefinition() {
40955
- return parseStaticDocumentFromDOMSubtree(
40956
- SecondaryInstanceDefinition,
40957
- SecondaryInstanceRootDefinition,
40958
- this.domElement
40959
- );
40957
+ const doc = parseStaticDocumentFromDOMSubtree(this.domElement, {
40958
+ nodesetPrefix: `instance('${this.instanceId}')`
40959
+ });
40960
+ assertSecondaryInstanceDefinition(doc);
40961
+ return doc;
40960
40962
  }
40961
40963
  }
40962
40964
 
@@ -40976,11 +40978,9 @@ class XMLExternalSecondaryInstanceSource extends ExternalSecondaryInstanceSource
40976
40978
  const instanceElement = xmlDocument.documentElement;
40977
40979
  instanceElement.setAttribute("id", this.instanceId);
40978
40980
  instanceElement.innerHTML = this.resource.data;
40979
- return parseStaticDocumentFromDOMSubtree(
40980
- SecondaryInstanceDefinition,
40981
- SecondaryInstanceRootDefinition,
40982
- instanceElement
40983
- );
40981
+ const doc = parseStaticDocumentFromDOMSubtree(instanceElement);
40982
+ assertSecondaryInstanceDefinition(doc);
40983
+ return doc;
40984
40984
  }
40985
40985
  }
40986
40986
 
@@ -41049,6 +41049,208 @@ class SecondaryInstancesDefinition extends Map {
41049
41049
  }
41050
41050
  }
41051
41051
 
41052
+ class BaseFormResult {
41053
+ status;
41054
+ warnings;
41055
+ error;
41056
+ constructor(options) {
41057
+ this.status = options.status;
41058
+ this.warnings = options.warnings;
41059
+ this.error = options.error;
41060
+ }
41061
+ }
41062
+
41063
+ const failedFormResultMethodFactory = (cause) => {
41064
+ return () => {
41065
+ throw new Error(cause.message, { cause });
41066
+ };
41067
+ };
41068
+ class FormFailureResult extends BaseFormResult {
41069
+ createInstance;
41070
+ editInstance;
41071
+ restoreInstance;
41072
+ constructor(options) {
41073
+ const { error, warnings } = options;
41074
+ super({
41075
+ status: "failure",
41076
+ warnings,
41077
+ error
41078
+ });
41079
+ this.createInstance = failedFormResultMethodFactory(error);
41080
+ this.editInstance = failedFormResultMethodFactory(error);
41081
+ this.restoreInstance = failedFormResultMethodFactory(error);
41082
+ }
41083
+ }
41084
+
41085
+ const wrapInstanceXML = (model, instanceXML) => {
41086
+ const defaultNamespace = model.root.namespaceDeclarations.get(null);
41087
+ const defaultNamespaceURI = defaultNamespace?.declaredURI?.href;
41088
+ if (defaultNamespaceURI == null) {
41089
+ return `<wrapped>${instanceXML}</wrapped>`;
41090
+ }
41091
+ return (
41092
+ /* xml */
41093
+ `<wrapped xmlns="${escapeXMLText(defaultNamespaceURI, true)}">
41094
+ ${instanceXML}
41095
+ </wrapped>`
41096
+ );
41097
+ };
41098
+ const assertSoleChildElement = (element) => {
41099
+ if (element == null) {
41100
+ throw new ErrorProductionDesignPendingError("Expected a child element");
41101
+ }
41102
+ const { parentNode } = element;
41103
+ if (parentNode == null) {
41104
+ throw new ErrorProductionDesignPendingError("Expected element to be a child of a parent node");
41105
+ }
41106
+ if (element !== parentNode.firstElementChild || element !== parentNode.lastElementChild) {
41107
+ throw new ErrorProductionDesignPendingError(
41108
+ "Expected child element to be parent node's only element child."
41109
+ );
41110
+ }
41111
+ };
41112
+ const getWrappedInstanceRootElement = (xml) => {
41113
+ const domParser = new DOMParser();
41114
+ const doc = domParser.parseFromString(xml, "text/xml");
41115
+ const { documentElement } = doc;
41116
+ const [root] = documentElement.children;
41117
+ assertSoleChildElement(root);
41118
+ return root;
41119
+ };
41120
+ const parseInstanceXML = (model, instanceXML) => {
41121
+ const wrappedXML = wrapInstanceXML(model, instanceXML);
41122
+ const root = getWrappedInstanceRootElement(wrappedXML);
41123
+ return parseStaticDocumentFromDOMSubtree(root);
41124
+ };
41125
+
41126
+ class MalformedInstanceDataError extends ErrorProductionDesignPendingError {
41127
+ }
41128
+
41129
+ const resolveInstanceAttachmentMapSource = async (input) => {
41130
+ const inputEntries = Array.from(input.entries());
41131
+ if (inputEntries.length > 0) {
41132
+ const fileNames = Array.from(input.keys());
41133
+ const errors = fileNames.map((fileName) => {
41134
+ return new Error(`Failed to resolve instance attachment with file name "${fileName}"`);
41135
+ });
41136
+ throw new AggregateError(errors, "Not implemented: instance attachment resource resolution");
41137
+ }
41138
+ const entries = await Promise.all(
41139
+ inputEntries.map(async ([fileName, resolveAttachment]) => {
41140
+ const response = await resolveAttachment();
41141
+ const blob = await response.blob();
41142
+ const value = new File([blob], fileName);
41143
+ return [fileName, value];
41144
+ })
41145
+ );
41146
+ return { entries: () => entries };
41147
+ };
41148
+ const assertKeyedInstanceDataFile = (key, file) => {
41149
+ if (file.name !== key) {
41150
+ throw new MalformedInstanceDataError(
41151
+ `Unexpected InstanceData file. Expected file name to match key, got key: ${JSON.stringify(key)} and file name: ${JSON.stringify(file.name)}`
41152
+ );
41153
+ }
41154
+ };
41155
+ const assertInstanceDataEntry = (entry) => {
41156
+ const [key, value] = entry;
41157
+ if (!(value instanceof File)) {
41158
+ throw new MalformedInstanceDataError(
41159
+ `Unexpected non-file attachment in InstanceData for key: ${key}`
41160
+ );
41161
+ }
41162
+ assertKeyedInstanceDataFile(key, value);
41163
+ };
41164
+ class InstanceAttachmentMap extends Map {
41165
+ static from(sources) {
41166
+ return new this(sources);
41167
+ }
41168
+ /**
41169
+ * @todo
41170
+ * @see {@link resolveInstanceAttachmentMapSource}
41171
+ */
41172
+ static async resolve(input) {
41173
+ const source = await resolveInstanceAttachmentMapSource(input);
41174
+ return new this([source]);
41175
+ }
41176
+ constructor(sources) {
41177
+ super();
41178
+ for (const source of sources) {
41179
+ for (const entry of source.entries()) {
41180
+ const [key] = entry;
41181
+ if (key === INSTANCE_FILE_NAME) {
41182
+ continue;
41183
+ }
41184
+ if (this.has(key)) {
41185
+ throw new MalformedInstanceDataError(
41186
+ `Unexpected InstanceData entry. Duplicate instance attachment for key: ${JSON.stringify(key)}`
41187
+ );
41188
+ }
41189
+ assertInstanceDataEntry(entry);
41190
+ const [, value] = entry;
41191
+ this.set(key, value);
41192
+ }
41193
+ }
41194
+ }
41195
+ }
41196
+
41197
+ const resolveInstanceXML = async (input) => {
41198
+ const instanceResult = await input.resolveInstance();
41199
+ if (typeof instanceResult === "string") {
41200
+ return instanceResult;
41201
+ }
41202
+ if (instanceResult instanceof Blob) {
41203
+ return getBlobText(instanceResult);
41204
+ }
41205
+ return instanceResult.text();
41206
+ };
41207
+ const parseInstanceDocument = (model, instanceXML) => {
41208
+ const doc = parseInstanceXML(model, instanceXML);
41209
+ const expectedId = model.instance.root.getAttributeValue("id");
41210
+ const actualId = doc.root.getAttributeValue("id");
41211
+ if (expectedId !== actualId) {
41212
+ throw new ErrorProductionDesignPendingError(
41213
+ `Invalid instance input. Expected instance id to be "${expectedId}", got: "${actualId}"`
41214
+ );
41215
+ }
41216
+ return doc;
41217
+ };
41218
+ class InitialInstanceState {
41219
+ static async from(model, data) {
41220
+ return this.resolve(model, {
41221
+ inputType: "FORM_INSTANCE_INPUT_RESOLVED",
41222
+ data
41223
+ });
41224
+ }
41225
+ static async resolve(model, input) {
41226
+ if (input.inputType === "FORM_INSTANCE_INPUT_RESOLVED") {
41227
+ const { data } = input;
41228
+ const [instanceData] = data;
41229
+ const instanceFile = instanceData.get(INSTANCE_FILE_NAME);
41230
+ const instanceXML2 = await getBlobText(instanceFile);
41231
+ const attachments2 = InstanceAttachmentMap.from(data);
41232
+ return new this(model, {
41233
+ instanceXML: instanceXML2,
41234
+ attachments: attachments2
41235
+ });
41236
+ }
41237
+ const [instanceXML, attachments] = await Promise.all([
41238
+ resolveInstanceXML(input),
41239
+ InstanceAttachmentMap.resolve(input.attachments)
41240
+ ]);
41241
+ return new this(model, {
41242
+ instanceXML,
41243
+ attachments
41244
+ });
41245
+ }
41246
+ document;
41247
+ attachments;
41248
+ constructor(model, options) {
41249
+ this.document = parseInstanceDocument(model, options.instanceXML);
41250
+ this.attachments = options.attachments;
41251
+ }
41252
+ }
41253
+
41052
41254
  const isEngineXPathNode = (value) => {
41053
41255
  return typeof value === "object" && value != null && XPathNodeKindKey in value;
41054
41256
  };
@@ -41360,53 +41562,51 @@ class EngineXPathEvaluator extends XFormsXPathEvaluator {
41360
41562
  }
41361
41563
  }
41362
41564
 
41363
- const createInstanceSubmissionState = (node) => {
41565
+ const createPrimaryInstanceState = (node) => {
41364
41566
  return {
41365
- get submissionXML() {
41366
- return node.root.submissionState.submissionXML;
41567
+ get instanceXML() {
41568
+ return node.root.instanceState.instanceXML;
41367
41569
  }
41368
41570
  };
41369
41571
  };
41370
41572
 
41371
41573
  class InstanceFile extends File {
41372
- name = SUBMISSION_INSTANCE_FILE_NAME;
41373
- type = SUBMISSION_INSTANCE_FILE_TYPE;
41574
+ name = INSTANCE_FILE_NAME;
41575
+ type = INSTANCE_FILE_TYPE;
41374
41576
  constructor(instanceRoot) {
41375
- const { submissionXML } = instanceRoot.submissionState;
41376
- super([submissionXML], SUBMISSION_INSTANCE_FILE_NAME, {
41377
- type: SUBMISSION_INSTANCE_FILE_TYPE
41577
+ const { instanceXML } = instanceRoot.instanceState;
41578
+ super([instanceXML], INSTANCE_FILE_NAME, {
41579
+ type: INSTANCE_FILE_TYPE
41378
41580
  });
41379
41581
  }
41380
41582
  }
41381
- const assertSubmissionData = (data) => {
41382
- const instanceFile = data.get(SUBMISSION_INSTANCE_FILE_NAME);
41583
+ const assertInstanceData = (data) => {
41584
+ const instanceFile = data.get(INSTANCE_FILE_NAME);
41383
41585
  if (!(instanceFile instanceof InstanceFile)) {
41384
- throw new Error(`Invalid SubmissionData`);
41586
+ throw new Error(`Invalid InstanceData`);
41385
41587
  }
41386
41588
  };
41387
- class InstanceSubmissionData extends FormData {
41589
+ class InstanceData extends FormData {
41388
41590
  constructor(instanceFile, attachments) {
41389
41591
  super();
41390
41592
  this.instanceFile = instanceFile;
41391
41593
  this.attachments = attachments;
41392
- this.set(SUBMISSION_INSTANCE_FILE_NAME, instanceFile);
41594
+ this.set(INSTANCE_FILE_NAME, instanceFile);
41393
41595
  attachments.forEach((attachment) => {
41394
41596
  const { name } = attachment;
41395
- if (name === SUBMISSION_INSTANCE_FILE_NAME && attachment !== instanceFile) {
41396
- throw new Error(
41397
- `Failed to add conflicting attachment with name ${SUBMISSION_INSTANCE_FILE_NAME}`
41398
- );
41597
+ if (name === INSTANCE_FILE_NAME && attachment !== instanceFile) {
41598
+ throw new Error(`Failed to add conflicting attachment with name ${INSTANCE_FILE_NAME}`);
41399
41599
  }
41400
41600
  this.set(name, attachment);
41401
41601
  });
41402
41602
  }
41403
41603
  static from(instanceFile, attachments) {
41404
41604
  const data = new this(instanceFile, attachments);
41405
- assertSubmissionData(data);
41605
+ assertInstanceData(data);
41406
41606
  return data;
41407
41607
  }
41408
41608
  }
41409
- const validateSubmission = (instanceRoot) => {
41609
+ const validateInstance = (instanceRoot) => {
41410
41610
  const { violations } = instanceRoot.validationState;
41411
41611
  if (violations.length === 0) {
41412
41612
  return {
@@ -41419,48 +41619,50 @@ const validateSubmission = (instanceRoot) => {
41419
41619
  violations
41420
41620
  };
41421
41621
  };
41422
- const monolithicSubmissionResult = (validation, definition, instanceFile, attachments) => {
41423
- const data = InstanceSubmissionData.from(instanceFile, attachments);
41622
+ const monolithicInstancePayload = (validation, submissionMeta, instanceFile, attachments) => {
41623
+ const data = InstanceData.from(instanceFile, attachments);
41424
41624
  return {
41625
+ payloadType: "monolithic",
41425
41626
  ...validation,
41426
- definition,
41427
- data
41627
+ submissionMeta,
41628
+ data: [data]
41428
41629
  };
41429
41630
  };
41430
- const chunkedSubmissionResult = (validation, definition, instanceFile, attachments, options) => {
41631
+ const chunkedInstancePayload = (validation, submissionMeta, instanceFile, attachments, options) => {
41431
41632
  if (attachments.length > 0 || options.maxSize !== Infinity) {
41432
- throw new Error("Submission chunking pending implementation");
41633
+ throw new Error("InstancePayload chunking pending implementation");
41433
41634
  }
41434
- const data = InstanceSubmissionData.from(instanceFile, attachments);
41635
+ const data = InstanceData.from(instanceFile, attachments);
41435
41636
  return {
41637
+ payloadType: "chunked",
41436
41638
  ...validation,
41437
- definition,
41639
+ submissionMeta,
41438
41640
  data: [data]
41439
41641
  };
41440
41642
  };
41441
- const prepareSubmission = (instanceRoot, options) => {
41442
- const validation = validateSubmission(instanceRoot);
41443
- const definition = instanceRoot.definition.submission;
41643
+ const prepareInstancePayload = (instanceRoot, options) => {
41644
+ const validation = validateInstance(instanceRoot);
41645
+ const submissionMeta = instanceRoot.definition.submission;
41444
41646
  const instanceFile = new InstanceFile(instanceRoot);
41445
41647
  const attachments = [];
41446
- switch (options.chunked) {
41648
+ switch (options.payloadType) {
41447
41649
  case "chunked":
41448
- return chunkedSubmissionResult(
41650
+ return chunkedInstancePayload(
41449
41651
  validation,
41450
- definition,
41652
+ submissionMeta,
41451
41653
  instanceFile,
41452
41654
  attachments,
41453
41655
  options
41454
41656
  );
41455
41657
  case "monolithic":
41456
- return monolithicSubmissionResult(
41658
+ return monolithicInstancePayload(
41457
41659
  validation,
41458
- definition,
41660
+ submissionMeta,
41459
41661
  instanceFile,
41460
41662
  attachments
41461
41663
  );
41462
41664
  default:
41463
- throw new UnreachableError$1(options.chunked);
41665
+ throw new UnreachableError$1(options.payloadType);
41464
41666
  }
41465
41667
  };
41466
41668
 
@@ -41688,14 +41890,20 @@ const createSharedNodeState = (scope, spec, options) => {
41688
41890
  };
41689
41891
  };
41690
41892
 
41893
+ const createUniqueId = (() => {
41894
+ const { crypto } = globalThis;
41895
+ return crypto?.randomUUID?.bind(crypto) ?? createUniqueId$1;
41896
+ })();
41897
+
41691
41898
  const nodeID = (id) => {
41692
41899
  return `node:${id}`;
41693
41900
  };
41694
41901
 
41695
41902
  class InstanceNode {
41696
- constructor(engineConfig, parent, definition, options) {
41697
- this.engineConfig = engineConfig;
41903
+ constructor(instanceConfig, parent, instanceNode, definition, options) {
41904
+ this.instanceConfig = instanceConfig;
41698
41905
  this.parent = parent;
41906
+ this.instanceNode = instanceNode;
41699
41907
  this.definition = definition;
41700
41908
  const self = this;
41701
41909
  if (parent == null) {
@@ -41710,8 +41918,8 @@ class InstanceNode {
41710
41918
  }
41711
41919
  this.computeReference = options?.computeReference ?? this.computeChildStepReference;
41712
41920
  this.scope = options?.scope ?? createReactiveScope();
41713
- this.engineConfig = engineConfig;
41714
- this.nodeId = nodeID(engineConfig.createUniqueId());
41921
+ this.instanceConfig = instanceConfig;
41922
+ this.nodeId = nodeID(createUniqueId());
41715
41923
  this.definition = definition;
41716
41924
  }
41717
41925
  rootDocument;
@@ -41770,12 +41978,12 @@ class InstanceNode {
41770
41978
  }
41771
41979
  }
41772
41980
 
41773
- const createRootSubmissionState = (node) => {
41981
+ const createRootInstanceState = (node) => {
41774
41982
  return {
41775
- get submissionXML() {
41983
+ get instanceXML() {
41776
41984
  const { namespaceDeclarations, attributes } = node.definition;
41777
41985
  const serializedChildren = node.currentState.children.map((child) => {
41778
- return child.submissionState.submissionXML;
41986
+ return child.instanceState.instanceXML;
41779
41987
  });
41780
41988
  return serializeParentElementXML(node.definition.qualifiedName, serializedChildren, {
41781
41989
  namespaceDeclarations,
@@ -41892,9 +42100,10 @@ const createComputedExpression = (context, dependentExpression, options = {}) =>
41892
42100
  };
41893
42101
 
41894
42102
  class DescendantNode extends InstanceNode {
41895
- constructor(parent, definition, options) {
41896
- super(parent.engineConfig, parent, definition, options);
42103
+ constructor(parent, instanceNode, definition, options) {
42104
+ super(parent.instanceConfig, parent, instanceNode, definition, options);
41897
42105
  this.parent = parent;
42106
+ this.instanceNode = instanceNode;
41898
42107
  this.definition = definition;
41899
42108
  if (this.isRoot()) {
41900
42109
  this.root = this;
@@ -41902,7 +42111,7 @@ class DescendantNode extends InstanceNode {
41902
42111
  this.root = parent.root;
41903
42112
  }
41904
42113
  const { evaluator } = parent;
41905
- if (definition.type === "repeat-range") {
42114
+ if (definition.type === "repeat") {
41906
42115
  this[XPathNodeKindKey] = XFORMS_XPATH_NODE_RANGE_KIND;
41907
42116
  } else {
41908
42117
  this[XPathNodeKindKey] = "element";
@@ -42020,14 +42229,14 @@ class DescendantNode extends InstanceNode {
42020
42229
  }
42021
42230
  }
42022
42231
 
42023
- const createParentNodeSubmissionState = (node) => {
42232
+ const createParentNodeInstanceState = (node) => {
42024
42233
  return {
42025
- get submissionXML() {
42234
+ get instanceXML() {
42026
42235
  if (!node.currentState.relevant) {
42027
42236
  return "";
42028
42237
  }
42029
42238
  const serializedChildren = node.currentState.children.map((child) => {
42030
- return child.submissionState.submissionXML;
42239
+ return child.instanceState.instanceXML;
42031
42240
  });
42032
42241
  return serializeParentElementXML(node.definition.qualifiedName, serializedChildren);
42033
42242
  }
@@ -42134,15 +42343,12 @@ class Group extends DescendantNode {
42134
42343
  nodeOptions = null;
42135
42344
  currentState;
42136
42345
  validationState;
42137
- submissionState;
42138
- constructor(parent, definition) {
42139
- super(parent, definition);
42346
+ instanceState;
42347
+ constructor(parent, instanceNode, definition) {
42348
+ super(parent, instanceNode, definition);
42140
42349
  this.appearances = definition.bodyElement.appearances;
42141
42350
  const childrenState = createChildrenState(this);
42142
42351
  this.childrenState = childrenState;
42143
- const sharedStateOptions = {
42144
- clientStateFactory: this.engineConfig.stateFactory
42145
- };
42146
42352
  const state = createSharedNodeState(
42147
42353
  this.scope,
42148
42354
  {
@@ -42156,7 +42362,7 @@ class Group extends DescendantNode {
42156
42362
  valueOptions: null,
42157
42363
  value: null
42158
42364
  },
42159
- sharedStateOptions
42365
+ this.instanceConfig
42160
42366
  );
42161
42367
  this.state = state;
42162
42368
  this.engineState = state.engineState;
@@ -42166,8 +42372,8 @@ class Group extends DescendantNode {
42166
42372
  childrenState
42167
42373
  );
42168
42374
  childrenState.setChildren(buildChildren(this));
42169
- this.validationState = createAggregatedViolations(this, sharedStateOptions);
42170
- this.submissionState = createParentNodeSubmissionState(this);
42375
+ this.validationState = createAggregatedViolations(this, this.instanceConfig);
42376
+ this.instanceState = createParentNodeInstanceState(this);
42171
42377
  }
42172
42378
  getChildren() {
42173
42379
  return this.childrenState.getChildren();
@@ -42182,10 +42388,10 @@ const createFieldHint = (context, definition) => {
42182
42388
  return createTextRange(context, "hint", hintDefinition);
42183
42389
  };
42184
42390
 
42185
- const createValueNodeSubmissionState = (node) => {
42391
+ const createValueNodeInstanceState = (node) => {
42186
42392
  const { qualifiedName } = node.definition;
42187
42393
  return {
42188
- get submissionXML() {
42394
+ get instanceXML() {
42189
42395
  if (!node.currentState.relevant) {
42190
42396
  return "";
42191
42397
  }
@@ -42195,18 +42401,17 @@ const createValueNodeSubmissionState = (node) => {
42195
42401
  };
42196
42402
  };
42197
42403
 
42198
- const isInstanceFirstLoad = (valueSource) => {
42199
- return valueSource === "FORM_DEFAULT";
42404
+ const isInstanceFirstLoad = (context) => {
42405
+ return context.rootDocument.initializationMode === "create";
42200
42406
  };
42201
- const getInitialValue$1 = (context, options) => {
42202
- const { initialValueSource = "FORM_DEFAULT" } = options;
42203
- if (initialValueSource === "FORM_DEFAULT") {
42204
- const { defaultValue } = context.definition;
42205
- return context.decodeInstanceValue(defaultValue);
42206
- }
42207
- throw new ErrorProductionDesignPendingError("Edit implementation pending");
42407
+ const isEditInitialLoad = (context) => {
42408
+ return context.rootDocument.initializationMode === "edit";
42208
42409
  };
42209
- const createRelevantValueState$1 = (context, baseValueState) => {
42410
+ const getInitialValue = (context) => {
42411
+ const sourceNode = context.instanceNode ?? context.definition.template;
42412
+ return context.decodeInstanceValue(sourceNode.value);
42413
+ };
42414
+ const createRelevantValueState = (context, baseValueState) => {
42210
42415
  return context.scope.runTask(() => {
42211
42416
  const [getRelevantValue, setValue] = baseValueState;
42212
42417
  const getValue = createMemo(() => {
@@ -42218,7 +42423,7 @@ const createRelevantValueState$1 = (context, baseValueState) => {
42218
42423
  return [getValue, setValue];
42219
42424
  });
42220
42425
  };
42221
- const guardDownstreamReadonlyWrites$1 = (context, baseState) => {
42426
+ const guardDownstreamReadonlyWrites = (context, baseState) => {
42222
42427
  const { readonly } = context.definition.bind;
42223
42428
  if (readonly.isDefaultExpression) {
42224
42429
  return baseState;
@@ -42234,9 +42439,12 @@ const guardDownstreamReadonlyWrites$1 = (context, baseState) => {
42234
42439
  return [getValue, setValue];
42235
42440
  };
42236
42441
  const PRELOAD_UID_EXPRESSION = 'concat("uuid:", uuid())';
42237
- const setPreloadUIDValue = (context, valueState, options) => {
42442
+ const shouldPreloadUID = (context) => {
42443
+ return isInstanceFirstLoad(context) || isEditInitialLoad(context);
42444
+ };
42445
+ const setPreloadUIDValue = (context, valueState) => {
42238
42446
  const { preload } = context.definition.bind;
42239
- if (preload?.type !== "uid" || !isInstanceFirstLoad(options?.initialValueSource)) {
42447
+ if (preload?.type !== "uid" || !shouldPreloadUID(context)) {
42240
42448
  return;
42241
42449
  }
42242
42450
  const preloadUIDValue = context.evaluator.evaluateString(PRELOAD_UID_EXPRESSION, {
@@ -42245,7 +42453,7 @@ const setPreloadUIDValue = (context, valueState, options) => {
42245
42453
  const [, setValue] = valueState;
42246
42454
  setValue(preloadUIDValue);
42247
42455
  };
42248
- const createCalculation$1 = (context, setRelevantValue, calculateDefinition) => {
42456
+ const createCalculation = (context, setRelevantValue, calculateDefinition) => {
42249
42457
  context.scope.runTask(() => {
42250
42458
  const calculate = createComputedExpression(context, calculateDefinition, {
42251
42459
  defaultValue: ""
@@ -42259,18 +42467,18 @@ const createCalculation$1 = (context, setRelevantValue, calculateDefinition) =>
42259
42467
  });
42260
42468
  });
42261
42469
  };
42262
- const createInstanceValueState = (context, options = {}) => {
42470
+ const createInstanceValueState = (context) => {
42263
42471
  return context.scope.runTask(() => {
42264
- const initialValue = getInitialValue$1(context, options);
42472
+ const initialValue = getInitialValue(context);
42265
42473
  const baseValueState = createSignal(initialValue);
42266
- const relevantValueState = createRelevantValueState$1(context, baseValueState);
42267
- setPreloadUIDValue(context, relevantValueState, options);
42474
+ const relevantValueState = createRelevantValueState(context, baseValueState);
42475
+ setPreloadUIDValue(context, relevantValueState);
42268
42476
  const { calculate } = context.definition.bind;
42269
42477
  if (calculate != null) {
42270
42478
  const [, setValue] = relevantValueState;
42271
- createCalculation$1(context, setValue, calculate);
42479
+ createCalculation(context, setValue, calculate);
42272
42480
  }
42273
- return guardDownstreamReadonlyWrites$1(context, relevantValueState);
42481
+ return guardDownstreamReadonlyWrites(context, relevantValueState);
42274
42482
  });
42275
42483
  };
42276
42484
 
@@ -42378,6 +42586,24 @@ const createValidationState = (context, options) => {
42378
42586
  };
42379
42587
 
42380
42588
  class ValueNode extends DescendantNode {
42589
+ constructor(parent, instanceNode, definition, codec) {
42590
+ super(parent, instanceNode, definition);
42591
+ this.instanceNode = instanceNode;
42592
+ this.valueType = definition.valueType;
42593
+ this.decodeInstanceValue = codec.decodeInstanceValue;
42594
+ const instanceValueState = createInstanceValueState(this);
42595
+ const valueState = codec.createRuntimeValueState(instanceValueState);
42596
+ const [getInstanceValue] = instanceValueState;
42597
+ const [, setValueState] = valueState;
42598
+ this.getInstanceValue = getInstanceValue;
42599
+ this.setValueState = setValueState;
42600
+ this.getXPathValue = () => {
42601
+ return this.getInstanceValue();
42602
+ };
42603
+ this.valueState = valueState;
42604
+ this.validation = createValidationState(this, this.instanceConfig);
42605
+ this.instanceState = createValueNodeInstanceState(this);
42606
+ }
42381
42607
  validation;
42382
42608
  getInstanceValue;
42383
42609
  valueState;
@@ -42391,28 +42617,7 @@ class ValueNode extends DescendantNode {
42391
42617
  get validationState() {
42392
42618
  return this.validation.currentState;
42393
42619
  }
42394
- submissionState;
42395
- constructor(parent, definition, codec) {
42396
- super(parent, definition);
42397
- this.valueType = definition.valueType;
42398
- this.decodeInstanceValue = codec.decodeInstanceValue;
42399
- const instanceValueState = createInstanceValueState(this, {
42400
- initialValueSource: "FORM_DEFAULT"
42401
- });
42402
- const valueState = codec.createRuntimeValueState(instanceValueState);
42403
- const [getInstanceValue] = instanceValueState;
42404
- const [, setValueState] = valueState;
42405
- this.getInstanceValue = getInstanceValue;
42406
- this.setValueState = setValueState;
42407
- this.getXPathValue = () => {
42408
- return this.getInstanceValue();
42409
- };
42410
- this.valueState = valueState;
42411
- this.validation = createValidationState(this, {
42412
- clientStateFactory: this.engineConfig.stateFactory
42413
- });
42414
- this.submissionState = createValueNodeSubmissionState(this);
42415
- }
42620
+ instanceState;
42416
42621
  // ValidationContext
42417
42622
  getViolation() {
42418
42623
  return this.validation.engineState.violation;
@@ -42449,8 +42654,8 @@ const nodeOptionsFactoryByType = {
42449
42654
  intent: () => null
42450
42655
  };
42451
42656
  class InputControl extends ValueNode {
42452
- static from(parent, definition) {
42453
- return new this(parent, definition);
42657
+ static from(parent, instanceNode, definition) {
42658
+ return new this(parent, instanceNode, definition);
42454
42659
  }
42455
42660
  // XFormsXPathElement
42456
42661
  [XPathNodeKindKey] = "element";
@@ -42462,14 +42667,11 @@ class InputControl extends ValueNode {
42462
42667
  appearances;
42463
42668
  nodeOptions;
42464
42669
  currentState;
42465
- constructor(parent, definition) {
42670
+ constructor(parent, instanceNode, definition) {
42466
42671
  const codec = getSharedValueCodec(definition.valueType);
42467
- super(parent, definition, codec);
42672
+ super(parent, instanceNode, definition, codec);
42468
42673
  this.appearances = definition.bodyElement.appearances;
42469
42674
  this.nodeOptions = nodeOptionsFactoryByType[definition.valueType](definition.bodyElement);
42470
- const sharedStateOptions = {
42471
- clientStateFactory: this.engineConfig.stateFactory
42472
- };
42473
42675
  const state = createSharedNodeState(
42474
42676
  this.scope,
42475
42677
  {
@@ -42484,7 +42686,7 @@ class InputControl extends ValueNode {
42484
42686
  value: this.valueState,
42485
42687
  instanceValue: this.getInstanceValue
42486
42688
  },
42487
- sharedStateOptions
42689
+ this.instanceConfig
42488
42690
  );
42489
42691
  this.state = state;
42490
42692
  this.engineState = state.engineState;
@@ -42497,8 +42699,8 @@ class InputControl extends ValueNode {
42497
42699
  }
42498
42700
 
42499
42701
  class ModelValue extends ValueNode {
42500
- static from(parent, definition) {
42501
- return new this(parent, definition);
42702
+ static from(parent, instanceNode, definition) {
42703
+ return new this(parent, instanceNode, definition);
42502
42704
  }
42503
42705
  // XFormsXPathElement
42504
42706
  [XPathNodeKindKey] = "element";
@@ -42510,12 +42712,9 @@ class ModelValue extends ValueNode {
42510
42712
  appearances = null;
42511
42713
  nodeOptions = null;
42512
42714
  currentState;
42513
- constructor(parent, definition) {
42715
+ constructor(parent, instanceNode, definition) {
42514
42716
  const codec = getSharedValueCodec(definition.valueType);
42515
- super(parent, definition, codec);
42516
- const sharedStateOptions = {
42517
- clientStateFactory: this.engineConfig.stateFactory
42518
- };
42717
+ super(parent, instanceNode, definition, codec);
42519
42718
  const state = createSharedNodeState(
42520
42719
  this.scope,
42521
42720
  {
@@ -42530,7 +42729,7 @@ class ModelValue extends ValueNode {
42530
42729
  value: this.valueState,
42531
42730
  instanceValue: this.getInstanceValue
42532
42731
  },
42533
- sharedStateOptions
42732
+ this.instanceConfig
42534
42733
  );
42535
42734
  this.state = state;
42536
42735
  this.engineState = state.engineState;
@@ -42617,13 +42816,10 @@ class Note extends ValueNode {
42617
42816
  appearances;
42618
42817
  nodeOptions = null;
42619
42818
  currentState;
42620
- constructor(parent, definition) {
42819
+ constructor(parent, instanceNode, definition) {
42621
42820
  const codec = getNoteCodec(definition.valueType);
42622
- super(parent, definition, codec);
42821
+ super(parent, instanceNode, definition, codec);
42623
42822
  this.appearances = definition.bodyElement.appearances;
42624
- const sharedStateOptions = {
42625
- clientStateFactory: this.engineConfig.stateFactory
42626
- };
42627
42823
  const isReadonly = createNoteReadonlyThunk(this, definition);
42628
42824
  const noteTextComputation = createNoteText(this, definition.noteTextDefinition);
42629
42825
  let noteText;
@@ -42660,7 +42856,7 @@ class Note extends ValueNode {
42660
42856
  value: this.valueState,
42661
42857
  instanceValue: this.getInstanceValue
42662
42858
  },
42663
- sharedStateOptions
42859
+ this.instanceConfig
42664
42860
  );
42665
42861
  this.state = state;
42666
42862
  this.engineState = state.engineState;
@@ -42707,8 +42903,8 @@ class RangeCodec extends ValueCodec {
42707
42903
  }
42708
42904
 
42709
42905
  class RangeControl extends ValueNode {
42710
- static from(parent, definition) {
42711
- return new this(parent, definition);
42906
+ static from(parent, instanceNode, definition) {
42907
+ return new this(parent, instanceNode, definition);
42712
42908
  }
42713
42909
  // XFormsXPathElement
42714
42910
  [XPathNodeKindKey] = "element";
@@ -42720,14 +42916,11 @@ class RangeControl extends ValueNode {
42720
42916
  appearances;
42721
42917
  nodeOptions = null;
42722
42918
  currentState;
42723
- constructor(parent, definition) {
42919
+ constructor(parent, instanceNode, definition) {
42724
42920
  const baseCodec = getSharedValueCodec(definition.valueType);
42725
42921
  const codec = new RangeCodec(baseCodec, definition);
42726
- super(parent, definition, codec);
42922
+ super(parent, instanceNode, definition, codec);
42727
42923
  this.appearances = definition.bodyElement.appearances;
42728
- const sharedStateOptions = {
42729
- clientStateFactory: this.engineConfig.stateFactory
42730
- };
42731
42924
  const state = createSharedNodeState(
42732
42925
  this.scope,
42733
42926
  {
@@ -42742,7 +42935,7 @@ class RangeControl extends ValueNode {
42742
42935
  value: this.valueState,
42743
42936
  instanceValue: this.getInstanceValue
42744
42937
  },
42745
- sharedStateOptions
42938
+ this.instanceConfig
42746
42939
  );
42747
42940
  this.state = state;
42748
42941
  this.engineState = state.engineState;
@@ -42754,6 +42947,256 @@ class RangeControl extends ValueNode {
42754
42947
  }
42755
42948
  }
42756
42949
 
42950
+ class RankMissingValueError extends Error {
42951
+ constructor(message) {
42952
+ super(message);
42953
+ }
42954
+ }
42955
+
42956
+ class XFormsSpecViolationError extends Error {
42957
+ }
42958
+
42959
+ class RankValueTypeError extends XFormsSpecViolationError {
42960
+ constructor(definition) {
42961
+ const { valueType } = definition;
42962
+ super(
42963
+ `Ranks of type ${valueType} are not currently supported. If this functionality would be useful for your form, your feedback is welcome!`
42964
+ );
42965
+ }
42966
+ }
42967
+
42968
+ class ValueArrayCodec extends ValueCodec {
42969
+ decodeItemValue;
42970
+ constructor(baseCodec, encodeValue, decodeValue) {
42971
+ const decodeItemValue = (value) => {
42972
+ const decoded = baseCodec.decodeValue(value);
42973
+ if (decoded == null) {
42974
+ throw new ErrorProductionDesignPendingError(
42975
+ `Failed to decode item value: ${JSON.stringify(value)}`
42976
+ );
42977
+ }
42978
+ return decoded;
42979
+ };
42980
+ super(baseCodec.valueType, encodeValue, decodeValue);
42981
+ this.decodeItemValue = decodeItemValue;
42982
+ }
42983
+ }
42984
+
42985
+ class BaseItemCodec extends ValueArrayCodec {
42986
+ constructor(baseCodec, encodeValue, decodeValue) {
42987
+ super(baseCodec, encodeValue, decodeValue);
42988
+ }
42989
+ }
42990
+
42991
+ class MultipleValueItemCodec extends BaseItemCodec {
42992
+ constructor(baseCodec) {
42993
+ const encodeValue = (value) => {
42994
+ return value.join(" ");
42995
+ };
42996
+ const decodeValue = (value) => {
42997
+ return xmlXPathWhitespaceSeparatedList(value, {
42998
+ ignoreEmpty: true
42999
+ });
43000
+ };
43001
+ super(baseCodec, encodeValue, decodeValue);
43002
+ }
43003
+ }
43004
+
43005
+ const derivedItemLabel = (context, value) => {
43006
+ const chunk = new TextChunk(context, "literal", value);
43007
+ return new TextRange("form-derived", "item-label", [chunk]);
43008
+ };
43009
+ const createItemLabel = (context, definition) => {
43010
+ const { label, value } = definition;
43011
+ if (label == null) {
43012
+ return () => derivedItemLabel(context, value);
43013
+ }
43014
+ return createTextRange(context, "item-label", label);
43015
+ };
43016
+ const createTranslatedStaticItems = (control, items) => {
43017
+ return control.scope.runTask(() => {
43018
+ const labeledItems = items.map((item) => {
43019
+ const { value } = item;
43020
+ const label = createItemLabel(control, item);
43021
+ return () => ({
43022
+ value,
43023
+ label: label()
43024
+ });
43025
+ });
43026
+ return createMemo(() => {
43027
+ return labeledItems.map((item) => item());
43028
+ });
43029
+ });
43030
+ };
43031
+ class ItemsetItemEvaluationContext {
43032
+ constructor(control, contextNode) {
43033
+ this.contextNode = contextNode;
43034
+ this.isAttached = control.isAttached;
43035
+ this.scope = control.scope;
43036
+ this.evaluator = control.evaluator;
43037
+ this.contextReference = control.contextReference;
43038
+ this.getActiveLanguage = control.getActiveLanguage;
43039
+ }
43040
+ isAttached;
43041
+ scope;
43042
+ evaluator;
43043
+ contextReference;
43044
+ getActiveLanguage;
43045
+ }
43046
+ const createItemsetItemLabel = (context, definition, itemValue) => {
43047
+ const { label } = definition;
43048
+ if (label == null) {
43049
+ return createMemo(() => {
43050
+ return derivedItemLabel(context, itemValue());
43051
+ });
43052
+ }
43053
+ return createTextRange(context, "item-label", label);
43054
+ };
43055
+ const createItemsetItems = (control, itemset) => {
43056
+ return control.scope.runTask(() => {
43057
+ const itemNodes = createComputedExpression(control, itemset.nodes, {
43058
+ defaultValue: []
43059
+ });
43060
+ const itemsCache = new UpsertableMap();
43061
+ return createMemo(() => {
43062
+ return itemNodes().map((itemNode) => {
43063
+ return itemsCache.upsert(itemNode, () => {
43064
+ const context = new ItemsetItemEvaluationContext(control, itemNode);
43065
+ const value = createComputedExpression(context, itemset.value, {
43066
+ defaultValue: ""
43067
+ });
43068
+ const label = createItemsetItemLabel(context, itemset, value);
43069
+ return {
43070
+ label,
43071
+ value
43072
+ };
43073
+ });
43074
+ });
43075
+ });
43076
+ });
43077
+ };
43078
+ const createItemset = (control, itemset) => {
43079
+ return control.scope.runTask(() => {
43080
+ const itemsetItems = createItemsetItems(control, itemset);
43081
+ return createMemo(() => {
43082
+ return itemsetItems().map((item) => {
43083
+ return {
43084
+ label: item.label(),
43085
+ value: item.value()
43086
+ };
43087
+ });
43088
+ });
43089
+ });
43090
+ };
43091
+ const createItemCollection = (control) => {
43092
+ const { items, itemset } = control.definition.bodyElement;
43093
+ if (itemset != null) {
43094
+ return createItemset(control, itemset);
43095
+ }
43096
+ return createTranslatedStaticItems(control, items);
43097
+ };
43098
+
43099
+ const assertRankNodeDefinition = (definition) => {
43100
+ if (definition.valueType !== "string") {
43101
+ throw new RankValueTypeError(definition);
43102
+ }
43103
+ };
43104
+ const isBlankValueState = (values) => {
43105
+ return values.length === 0;
43106
+ };
43107
+ class RankControl extends ValueNode {
43108
+ static from(parent, instanceNode, definition) {
43109
+ assertRankNodeDefinition(definition);
43110
+ return new this(parent, instanceNode, definition);
43111
+ }
43112
+ mapOptionsByValue;
43113
+ getInstanceValue;
43114
+ // XFormsXPathElement
43115
+ [XPathNodeKindKey] = "element";
43116
+ // InstanceNode
43117
+ state;
43118
+ engineState;
43119
+ // RankNode
43120
+ nodeType = "rank";
43121
+ appearances;
43122
+ nodeOptions = null;
43123
+ currentState;
43124
+ constructor(parent, instanceNode, definition) {
43125
+ const codec = new MultipleValueItemCodec(sharedValueCodecs.string);
43126
+ super(parent, instanceNode, definition, codec);
43127
+ this.appearances = definition.bodyElement.appearances;
43128
+ const valueOptions = createItemCollection(this);
43129
+ const mapOptionsByValue = this.scope.runTask(() => {
43130
+ return createMemo(() => {
43131
+ return new Map(valueOptions().map((item) => [item.value, item]));
43132
+ });
43133
+ });
43134
+ this.mapOptionsByValue = mapOptionsByValue;
43135
+ const baseValueState = this.valueState;
43136
+ const [baseGetValue, setValue] = baseValueState;
43137
+ const getValue = this.scope.runTask(() => {
43138
+ return createMemo(() => {
43139
+ const options = valueOptions();
43140
+ const values = baseGetValue();
43141
+ if (isBlankValueState(values)) {
43142
+ return values;
43143
+ }
43144
+ const optionValues = new Set(options.map((option) => option.value));
43145
+ const currentValues = values.filter((value) => optionValues.has(value));
43146
+ return Array.from(
43147
+ /* @__PURE__ */ new Set([
43148
+ ...currentValues,
43149
+ /**
43150
+ * @see {@link getValue} ToDo paragraph 1.
43151
+ */
43152
+ ...optionValues
43153
+ ])
43154
+ );
43155
+ });
43156
+ });
43157
+ const valueState = [getValue, setValue];
43158
+ this.getInstanceValue = this.scope.runTask(() => {
43159
+ return createMemo(() => codec.encodeValue(getValue()));
43160
+ });
43161
+ const state = createSharedNodeState(
43162
+ this.scope,
43163
+ {
43164
+ reference: this.contextReference,
43165
+ readonly: this.isReadonly,
43166
+ relevant: this.isRelevant,
43167
+ required: this.isRequired,
43168
+ label: createNodeLabel(this, definition),
43169
+ hint: createFieldHint(this, definition),
43170
+ children: null,
43171
+ valueOptions,
43172
+ value: valueState,
43173
+ instanceValue: this.getInstanceValue
43174
+ },
43175
+ this.instanceConfig
43176
+ );
43177
+ this.state = state;
43178
+ this.engineState = state.engineState;
43179
+ this.currentState = state.currentState;
43180
+ }
43181
+ getValueLabel(value) {
43182
+ const valueOption = this.currentState.valueOptions.find((item) => item.value === value);
43183
+ return valueOption?.label ?? null;
43184
+ }
43185
+ setValues(valuesInOrder) {
43186
+ if (isBlankValueState(valuesInOrder)) {
43187
+ this.setValueState(valuesInOrder);
43188
+ return this.root;
43189
+ }
43190
+ const sourceValues = Array.from(this.mapOptionsByValue().keys());
43191
+ const hasAllValues = sourceValues.every((sourceValue) => valuesInOrder.includes(sourceValue));
43192
+ if (!hasAllValues) {
43193
+ throw new RankMissingValueError("There are missing options. Rank should have all options.");
43194
+ }
43195
+ this.setValueState(valuesInOrder);
43196
+ return this.root;
43197
+ }
43198
+ }
43199
+
42757
43200
  const insertAtIndex = (currentValues, insertionIndex, newValues) => {
42758
43201
  const { length } = currentValues;
42759
43202
  if (insertionIndex > length) {
@@ -42771,24 +43214,49 @@ const insertAtIndex = (currentValues, insertionIndex, newValues) => {
42771
43214
  ];
42772
43215
  };
42773
43216
 
42774
- const createNodeRangeSubmissionState = (node) => {
43217
+ const createNodeRangeInstanceState = (node) => {
42775
43218
  return {
42776
- get submissionXML() {
43219
+ get instanceXML() {
42777
43220
  const serializedChildren = node.currentState.children.map((child) => {
42778
- return child.submissionState.submissionXML;
43221
+ return child.instanceState.instanceXML;
42779
43222
  });
42780
43223
  return serializedChildren.join("");
42781
43224
  }
42782
43225
  };
42783
43226
  };
42784
43227
 
43228
+ class TemplatedNodeAttributeSerializationError extends Error {
43229
+ constructor() {
43230
+ super("Template attribute omission not implemented");
43231
+ }
43232
+ }
43233
+
43234
+ const createTemplatedNodeInstanceState = (node) => {
43235
+ return {
43236
+ get instanceXML() {
43237
+ if (!node.currentState.relevant) {
43238
+ return "";
43239
+ }
43240
+ const serializedChildren = node.currentState.children.map((child) => {
43241
+ return child.instanceState.instanceXML;
43242
+ });
43243
+ const { attributes } = node.currentState;
43244
+ if (attributes != null) {
43245
+ throw new TemplatedNodeAttributeSerializationError();
43246
+ }
43247
+ return serializeParentElementXML(node.definition.qualifiedName, serializedChildren);
43248
+ }
43249
+ };
43250
+ };
43251
+
42785
43252
  class RepeatInstance extends DescendantNode {
42786
- constructor(parent, definition, options) {
43253
+ constructor(parent, instanceNode, options) {
43254
+ const { definition } = parent;
42787
43255
  const { precedingInstance } = options;
42788
43256
  const precedingIndex = precedingInstance?.currentIndex ?? (() => -1);
42789
43257
  const initialIndex = precedingIndex() + 1;
42790
43258
  const [currentIndex, setCurrentIndex] = createSignal(initialIndex);
42791
- super(parent, definition, {
43259
+ super(parent, instanceNode, definition, {
42792
43260
  computeReference: () => {
42793
43261
  const currentPosition = currentIndex() + 1;
42794
43262
  return `${parent.contextReference()}[${currentPosition}]`;
@@ -42799,9 +43267,6 @@ class RepeatInstance extends DescendantNode {
42799
43267
  const childrenState = createChildrenState(this);
42800
43268
  this.childrenState = childrenState;
42801
43269
  this.currentIndex = currentIndex;
42802
- const sharedStateOptions = {
42803
- clientStateFactory: this.engineConfig.stateFactory
42804
- };
42805
43270
  const state = createSharedNodeState(
42806
43271
  this.scope,
42807
43272
  {
@@ -42812,11 +43277,12 @@ class RepeatInstance extends DescendantNode {
42812
43277
  // TODO: only-child <group><label>
42813
43278
  label: createNodeLabel(this, definition),
42814
43279
  hint: null,
43280
+ attributes: null,
42815
43281
  children: childrenState.childIds,
42816
43282
  valueOptions: null,
42817
43283
  value: null
42818
43284
  },
42819
- sharedStateOptions
43285
+ this.instanceConfig
42820
43286
  );
42821
43287
  this.state = state;
42822
43288
  this.engineState = state.engineState;
@@ -42830,8 +43296,8 @@ class RepeatInstance extends DescendantNode {
42830
43296
  createComputed(on(computeCurrentIndex, setCurrentIndex, { defer: true }));
42831
43297
  });
42832
43298
  childrenState.setChildren(buildChildren(this));
42833
- this.validationState = createAggregatedViolations(this, sharedStateOptions);
42834
- this.submissionState = createParentNodeSubmissionState(this);
43299
+ this.validationState = createAggregatedViolations(this, this.instanceConfig);
43300
+ this.instanceState = createTemplatedNodeInstanceState(this);
42835
43301
  }
42836
43302
  childrenState;
42837
43303
  currentIndex;
@@ -42864,7 +43330,7 @@ class RepeatInstance extends DescendantNode {
42864
43330
  nodeOptions = null;
42865
43331
  currentState;
42866
43332
  validationState;
42867
- submissionState;
43333
+ instanceState;
42868
43334
  getChildren() {
42869
43335
  return this.childrenState.getChildren();
42870
43336
  }
@@ -42906,15 +43372,12 @@ class BaseRepeatRange extends DescendantNode {
42906
43372
  engineState;
42907
43373
  nodeOptions = null;
42908
43374
  currentState;
42909
- submissionState;
43375
+ instanceState;
42910
43376
  constructor(parent, definition) {
42911
- super(parent, definition);
43377
+ super(parent, definition.template, definition);
42912
43378
  const repeatRange = this;
42913
43379
  const childrenState = createChildrenState(repeatRange);
42914
43380
  this.childrenState = childrenState;
42915
- const sharedStateOptions = {
42916
- clientStateFactory: this.engineConfig.stateFactory
42917
- };
42918
43381
  const state = createSharedNodeState(
42919
43382
  this.scope,
42920
43383
  {
@@ -42928,7 +43391,7 @@ class BaseRepeatRange extends DescendantNode {
42928
43391
  valueOptions: null,
42929
43392
  value: null
42930
43393
  },
42931
- sharedStateOptions
43394
+ this.instanceConfig
42932
43395
  );
42933
43396
  this.state = state;
42934
43397
  this.engineState = state.engineState;
@@ -42937,7 +43400,7 @@ class BaseRepeatRange extends DescendantNode {
42937
43400
  state.currentState,
42938
43401
  childrenState
42939
43402
  );
42940
- this.submissionState = createNodeRangeSubmissionState(this);
43403
+ this.instanceState = createNodeRangeInstanceState(this);
42941
43404
  }
42942
43405
  getLastIndex() {
42943
43406
  return this.engineState.children.length - 1;
@@ -42945,7 +43408,7 @@ class BaseRepeatRange extends DescendantNode {
42945
43408
  getInstanceIndex(instance) {
42946
43409
  return this.engineState.children.indexOf(instance.nodeId);
42947
43410
  }
42948
- createChildren(afterIndex, definitions) {
43411
+ createChildren(afterIndex, instanceNodes) {
42949
43412
  return this.scope.runTask(() => {
42950
43413
  let initialPrecedingInstance;
42951
43414
  if (afterIndex === -1) {
@@ -42958,7 +43421,7 @@ class BaseRepeatRange extends DescendantNode {
42958
43421
  initialPrecedingInstance = instance;
42959
43422
  }
42960
43423
  const repeatRange = this;
42961
- return definitions.reduce((acc, definition) => {
43424
+ return instanceNodes.reduce((acc, definition) => {
42962
43425
  const precedingInstance = acc[acc.length - 1] ?? initialPrecedingInstance;
42963
43426
  const newInstance = new RepeatInstance(repeatRange, definition, {
42964
43427
  precedingInstance
@@ -42968,10 +43431,10 @@ class BaseRepeatRange extends DescendantNode {
42968
43431
  }, []);
42969
43432
  });
42970
43433
  }
42971
- addChildren(afterIndex, definitions) {
43434
+ addChildren(afterIndex, instanceNodes) {
42972
43435
  return this.scope.runTask(() => {
42973
43436
  const initialIndex = afterIndex + 1;
42974
- const newInstances = this.createChildren(afterIndex, definitions);
43437
+ const newInstances = this.createChildren(afterIndex, instanceNodes);
42975
43438
  return this.childrenState.setChildren((currentInstances) => {
42976
43439
  return insertAtIndex(currentInstances, initialIndex, newInstances);
42977
43440
  });
@@ -42995,25 +43458,33 @@ class BaseRepeatRange extends DescendantNode {
42995
43458
  }
42996
43459
 
42997
43460
  class RepeatRangeControlled extends BaseRepeatRange {
43461
+ isInstanceCreation;
43462
+ countControlType;
42998
43463
  // RepeatRangeControlledNode
42999
43464
  nodeType = "repeat-range:controlled";
43000
43465
  appearances;
43001
43466
  validationState;
43002
- constructor(parent, definition) {
43467
+ constructor(parent, instanceNodes, definition) {
43003
43468
  super(parent, definition);
43469
+ this.isInstanceCreation = parent.rootDocument.initializationMode === "create";
43004
43470
  this.appearances = definition.bodyElement.appearances;
43005
- this.initializeControlledChildrenState(definition);
43006
- this.validationState = createAggregatedViolations(this, {
43007
- clientStateFactory: this.engineConfig.stateFactory
43008
- });
43471
+ if (definition.count.isConstantExpression()) {
43472
+ this.countControlType = "REPEAT_COUNT_CONTROL_FIXED";
43473
+ } else {
43474
+ this.countControlType = "REPEAT_COUNT_CONTROL_DYNAMIC";
43475
+ }
43476
+ this.initializeControlledChildrenState(definition, instanceNodes);
43477
+ this.validationState = createAggregatedViolations(this, this.instanceConfig);
43009
43478
  }
43010
- initializeControlledChildrenState(definition) {
43479
+ initializeControlledChildrenState(definition, instanceNodes) {
43011
43480
  this.scope.runTask(() => {
43012
- const { count, instances, template } = definition;
43481
+ const { count, template } = definition;
43482
+ const repeatInstanceNodes = definition.omitTemplate(instanceNodes);
43013
43483
  const computeCount = createComputedExpression(this, count, {
43014
43484
  defaultValue: 0
43015
43485
  });
43016
- createComputed((previousCount) => {
43486
+ createComputed((previousCountComputation = null) => {
43487
+ const previousCount = previousCountComputation ?? 0;
43017
43488
  let currentCount = computeCount();
43018
43489
  if (Number.isFinite(currentCount) && currentCount < 0) {
43019
43490
  currentCount = 0;
@@ -43026,21 +43497,57 @@ class RepeatRangeControlled extends BaseRepeatRange {
43026
43497
  Number.isNaN(currentCount)) {
43027
43498
  return previousCount;
43028
43499
  }
43500
+ this.warnDroppedInstanceNodes(repeatInstanceNodes, previousCountComputation, currentCount);
43029
43501
  if (currentCount > previousCount) {
43030
43502
  const delta = currentCount - previousCount;
43031
- const definitions = Array(delta).fill(template).map((baseDefinition, index) => {
43503
+ const inputNodes = Array(delta).fill(null).map((_, index) => {
43032
43504
  const instanceIndex = previousCount + index;
43033
- return instances[instanceIndex] ?? baseDefinition;
43505
+ return repeatInstanceNodes[instanceIndex] ?? template;
43034
43506
  });
43035
- this.addChildren(previousCount - 1, definitions);
43507
+ this.addChildren(previousCount - 1, inputNodes);
43036
43508
  } else {
43037
43509
  const delta = previousCount - currentCount;
43038
43510
  this.removeChildren(currentCount, delta);
43039
43511
  }
43040
43512
  return currentCount;
43041
- }, 0);
43513
+ });
43042
43514
  });
43043
43515
  }
43516
+ /**
43517
+ * Note: we do not warn about dropping "excess" repeat instances...
43518
+ *
43519
+ * - ... after the instance is fully loaded: dropping repeat instances after
43520
+ * that point is an expected behavior of _dynamically-controlled repeats_
43521
+ * (i.e. those defined with `jr:count`), and it does not occur for
43522
+ * _fixed-controlled repeats_ (i.e. defined with `jr:noAddRemove`);
43523
+ *
43524
+ * - ... for dynamic (`jr:count`) repeats _in newly created form instances_, i.e. instances whose input instance
43525
+ * nodes are derived from the _form definition_: those form-defined repeat
43526
+ * instances are not "dropped", instead they're retained in memory to be
43527
+ * added as count is recomputed to a larger value.
43528
+ *
43529
+ * @todo ^ it is pretty likely that retain-in-memory behavior also applies to
43530
+ * instance state which has been serialized and restored as well! In this way,
43531
+ * it's possible we're not really "dropping" those nodes, only deferring their
43532
+ * restoration. Is this what we want?
43533
+ *
43534
+ * @todo Design and produce {@link LoadFormWarnings | warnings} as values!
43535
+ */
43536
+ warnDroppedInstanceNodes(repeatInstanceNodes, previousCountComputation, initialCount) {
43537
+ if (this.isInstanceCreation) {
43538
+ return;
43539
+ }
43540
+ const isInstanceLoad = previousCountComputation == null;
43541
+ if (isInstanceLoad && this.countControlType === "REPEAT_COUNT_CONTROL_DYNAMIC") {
43542
+ return;
43543
+ }
43544
+ const droppedCount = repeatInstanceNodes.length - initialCount;
43545
+ if (droppedCount > 0) {
43546
+ console.warn(
43547
+ `Dropped ${droppedCount} repeat instances for repeat range ${this.contextReference()}`
43548
+ );
43549
+ }
43550
+ }
43044
43551
  }
43045
43552
 
43046
43553
  class RepeatRangeUncontrolled extends BaseRepeatRange {
@@ -43048,13 +43555,11 @@ class RepeatRangeUncontrolled extends BaseRepeatRange {
43048
43555
  nodeType = "repeat-range:uncontrolled";
43049
43556
  appearances;
43050
43557
  validationState;
43051
- constructor(parent, definition) {
43558
+ constructor(parent, instanceNodes, definition) {
43052
43559
  super(parent, definition);
43053
43560
  this.appearances = definition.bodyElement.appearances;
43054
- this.addChildren(-1, definition.instances);
43055
- this.validationState = createAggregatedViolations(this, {
43056
- clientStateFactory: this.engineConfig.stateFactory
43057
- });
43561
+ this.addChildren(-1, definition.omitTemplate(instanceNodes));
43562
+ this.validationState = createAggregatedViolations(this, this.instanceConfig);
43058
43563
  }
43059
43564
  // RepeatRangeUncontrolledNode
43060
43565
  addInstances(afterIndex = this.getLastIndex(), count = 1) {
@@ -43085,9 +43590,6 @@ class RepeatRangeUncontrolled extends BaseRepeatRange {
43085
43590
  }
43086
43591
  }
43087
43592
 
43088
- class XFormsSpecViolationError extends Error {
43089
- }
43090
-
43091
43593
  class SelectValueTypeError extends XFormsSpecViolationError {
43092
43594
  constructor(definition) {
43093
43595
  const { valueType } = definition;
@@ -43097,43 +43599,6 @@ class SelectValueTypeError extends XFormsSpecViolationError {
43097
43599
  }
43098
43600
  }
43099
43601
 
43100
- class ValueArrayCodec extends ValueCodec {
43101
- decodeItemValue;
43102
- constructor(baseCodec, encodeValue, decodeValue) {
43103
- const decodeItemValue = (value) => {
43104
- const decoded = baseCodec.decodeValue(value);
43105
- if (decoded == null) {
43106
- throw new ErrorProductionDesignPendingError(
43107
- `Failed to decode item value: ${JSON.stringify(value)}`
43108
- );
43109
- }
43110
- return decoded;
43111
- };
43112
- super(baseCodec.valueType, encodeValue, decodeValue);
43113
- this.decodeItemValue = decodeItemValue;
43114
- }
43115
- }
43116
-
43117
- class BaseItemCodec extends ValueArrayCodec {
43118
- constructor(baseCodec, encodeValue, decodeValue) {
43119
- super(baseCodec, encodeValue, decodeValue);
43120
- }
43121
- }
43122
-
43123
- class MultipleValueItemCodec extends BaseItemCodec {
43124
- constructor(baseCodec) {
43125
- const encodeValue = (value) => {
43126
- return value.join(" ");
43127
- };
43128
- const decodeValue = (value) => {
43129
- return xmlXPathWhitespaceSeparatedList(value, {
43130
- ignoreEmpty: true
43131
- });
43132
- };
43133
- super(baseCodec, encodeValue, decodeValue);
43134
- }
43135
- }
43136
-
43137
43602
  const encodeValueFactory = (baseCodec) => {
43138
43603
  return (values) => {
43139
43604
  const [value] = values;
@@ -43169,109 +43634,15 @@ const getSelectCodec = (definition) => {
43169
43634
  }
43170
43635
  };
43171
43636
 
43172
- const derivedItemLabel = (context, value) => {
43173
- const chunk = new TextChunk(context, "literal", value);
43174
- return new TextRange("form-derived", "item-label", [chunk]);
43175
- };
43176
- const createItemLabel = (context, definition) => {
43177
- const { label, value } = definition;
43178
- if (label == null) {
43179
- return () => derivedItemLabel(context, value);
43180
- }
43181
- return createTextRange(context, "item-label", label);
43182
- };
43183
- const createTranslatedStaticItems = (control, items) => {
43184
- return control.scope.runTask(() => {
43185
- const labeledItems = items.map((item) => {
43186
- const { value } = item;
43187
- const label = createItemLabel(control, item);
43188
- return () => ({
43189
- value,
43190
- label: label()
43191
- });
43192
- });
43193
- return createMemo(() => {
43194
- return labeledItems.map((item) => item());
43195
- });
43196
- });
43197
- };
43198
- class ItemsetItemEvaluationContext {
43199
- constructor(control, contextNode) {
43200
- this.contextNode = contextNode;
43201
- this.isAttached = control.isAttached;
43202
- this.scope = control.scope;
43203
- this.evaluator = control.evaluator;
43204
- this.contextReference = control.contextReference;
43205
- this.getActiveLanguage = control.getActiveLanguage;
43206
- }
43207
- isAttached;
43208
- scope;
43209
- evaluator;
43210
- contextReference;
43211
- getActiveLanguage;
43212
- }
43213
- const createItemsetItemLabel = (context, definition, itemValue) => {
43214
- const { label } = definition;
43215
- if (label == null) {
43216
- return createMemo(() => {
43217
- return derivedItemLabel(context, itemValue());
43218
- });
43219
- }
43220
- return createTextRange(context, "item-label", label);
43221
- };
43222
- const createItemsetItems = (control, itemset) => {
43223
- return control.scope.runTask(() => {
43224
- const itemNodes = createComputedExpression(control, itemset.nodes, {
43225
- defaultValue: []
43226
- });
43227
- const itemsCache = new UpsertableMap();
43228
- return createMemo(() => {
43229
- return itemNodes().map((itemNode) => {
43230
- return itemsCache.upsert(itemNode, () => {
43231
- const context = new ItemsetItemEvaluationContext(control, itemNode);
43232
- const value = createComputedExpression(context, itemset.value, {
43233
- defaultValue: ""
43234
- });
43235
- const label = createItemsetItemLabel(context, itemset, value);
43236
- return {
43237
- label,
43238
- value
43239
- };
43240
- });
43241
- });
43242
- });
43243
- });
43244
- };
43245
- const createItemset = (control, itemset) => {
43246
- return control.scope.runTask(() => {
43247
- const itemsetItems = createItemsetItems(control, itemset);
43248
- return createMemo(() => {
43249
- return itemsetItems().map((item) => {
43250
- return {
43251
- label: item.label(),
43252
- value: item.value()
43253
- };
43254
- });
43255
- });
43256
- });
43257
- };
43258
- const createItemCollection = (control) => {
43259
- const { items, itemset } = control.definition.bodyElement;
43260
- if (itemset != null) {
43261
- return createItemset(control, itemset);
43262
- }
43263
- return createTranslatedStaticItems(control, items);
43264
- };
43265
-
43266
43637
  const assertSupportedSelectValueType = (definition) => {
43267
43638
  if (definition.valueType !== "string") {
43268
43639
  throw new SelectValueTypeError(definition);
43269
43640
  }
43270
43641
  };
43271
43642
  class SelectControl extends ValueNode {
43272
- static from(parent, definition) {
43643
+ static from(parent, instanceNode, definition) {
43273
43644
  assertSupportedSelectValueType(definition);
43274
- return new this(parent, definition);
43645
+ return new this(parent, instanceNode, definition);
43275
43646
  }
43276
43647
  mapOptionsByValue;
43277
43648
  getInstanceValue;
@@ -43286,9 +43657,9 @@ class SelectControl extends ValueNode {
43286
43657
  appearances;
43287
43658
  nodeOptions = null;
43288
43659
  currentState;
43289
- constructor(parent, definition) {
43660
+ constructor(parent, instanceNode, definition) {
43290
43661
  const codec = getSelectCodec(definition);
43291
- super(parent, definition, codec);
43662
+ super(parent, instanceNode, definition, codec);
43292
43663
  this.appearances = definition.bodyElement.appearances;
43293
43664
  this.selectType = definition.bodyElement.type;
43294
43665
  const valueOptions = createItemCollection(this);
@@ -43314,9 +43685,6 @@ class SelectControl extends ValueNode {
43314
43685
  return codec.encodeValue(getValue());
43315
43686
  });
43316
43687
  });
43317
- const sharedStateOptions = {
43318
- clientStateFactory: this.engineConfig.stateFactory
43319
- };
43320
43688
  const state = createSharedNodeState(
43321
43689
  this.scope,
43322
43690
  {
@@ -43331,7 +43699,7 @@ class SelectControl extends ValueNode {
43331
43699
  value: valueState,
43332
43700
  instanceValue: this.getInstanceValue
43333
43701
  },
43334
- sharedStateOptions
43702
+ this.instanceConfig
43335
43703
  );
43336
43704
  this.state = state;
43337
43705
  this.engineState = state.engineState;
@@ -43401,14 +43769,11 @@ class Subtree extends DescendantNode {
43401
43769
  nodeOptions = null;
43402
43770
  currentState;
43403
43771
  validationState;
43404
- submissionState;
43405
- constructor(parent, definition) {
43406
- super(parent, definition);
43772
+ instanceState;
43773
+ constructor(parent, instanceNode, definition) {
43774
+ super(parent, instanceNode, definition);
43407
43775
  const childrenState = createChildrenState(this);
43408
43776
  this.childrenState = childrenState;
43409
- const sharedStateOptions = {
43410
- clientStateFactory: this.engineConfig.stateFactory
43411
- };
43412
43777
  const state = createSharedNodeState(
43413
43778
  this.scope,
43414
43779
  {
@@ -43422,7 +43787,7 @@ class Subtree extends DescendantNode {
43422
43787
  valueOptions: null,
43423
43788
  value: null
43424
43789
  },
43425
- sharedStateOptions
43790
+ this.instanceConfig
43426
43791
  );
43427
43792
  this.state = state;
43428
43793
  this.engineState = state.engineState;
@@ -43432,8 +43797,8 @@ class Subtree extends DescendantNode {
43432
43797
  childrenState
43433
43798
  );
43434
43799
  childrenState.setChildren(buildChildren(this));
43435
- this.validationState = createAggregatedViolations(this, sharedStateOptions);
43436
- this.submissionState = createParentNodeSubmissionState(this);
43800
+ this.validationState = createAggregatedViolations(this, this.instanceConfig);
43801
+ this.instanceState = createParentNodeInstanceState(this);
43437
43802
  }
43438
43803
  getChildren() {
43439
43804
  return this.childrenState.getChildren();
@@ -43477,13 +43842,13 @@ class TriggerCodec extends ValueCodec {
43477
43842
 
43478
43843
  const codec = new TriggerCodec();
43479
43844
  class TriggerControl extends ValueNode {
43480
- static from(parent, definition) {
43845
+ static from(parent, instanceNode, definition) {
43481
43846
  if (definition.valueType !== "string") {
43482
43847
  throw new ErrorProductionDesignPendingError(
43483
43848
  `Unsupported trigger value type: ${definition.valueType}`
43484
43849
  );
43485
43850
  }
43486
- return new this(parent, definition);
43851
+ return new this(parent, instanceNode, definition);
43487
43852
  }
43488
43853
  // XFormsXPathElement
43489
43854
  [XPathNodeKindKey] = "element";
@@ -43495,12 +43860,9 @@ class TriggerControl extends ValueNode {
43495
43860
  appearances;
43496
43861
  nodeOptions = null;
43497
43862
  currentState;
43498
- constructor(parent, definition) {
43499
- super(parent, definition, codec);
43863
+ constructor(parent, instanceNode, definition) {
43864
+ super(parent, instanceNode, definition, codec);
43500
43865
  this.appearances = definition.bodyElement.appearances;
43501
- const sharedStateOptions = {
43502
- clientStateFactory: this.engineConfig.stateFactory
43503
- };
43504
43866
  const state = createSharedNodeState(
43505
43867
  this.scope,
43506
43868
  {
@@ -43515,7 +43877,7 @@ class TriggerControl extends ValueNode {
43515
43877
  value: this.valueState,
43516
43878
  instanceValue: this.getInstanceValue
43517
43879
  },
43518
- sharedStateOptions
43880
+ this.instanceConfig
43519
43881
  );
43520
43882
  this.state = state;
43521
43883
  this.engineState = state.engineState;
@@ -43528,86 +43890,59 @@ class TriggerControl extends ValueNode {
43528
43890
  }
43529
43891
  }
43530
43892
 
43531
- class RankMissingValueError extends Error {
43532
- constructor(message) {
43533
- super(message);
43893
+ class TempUnsupportedControlEncodeError extends Error {
43894
+ constructor() {
43895
+ super(`Cannot encode state: not implemented`);
43534
43896
  }
43535
43897
  }
43536
-
43537
- class RankValueTypeError extends XFormsSpecViolationError {
43538
- constructor(definition) {
43539
- const { valueType } = definition;
43540
- super(
43541
- `Ranks of type ${valueType} are not currently supported. If this functionality would be useful for your form, your feedback is welcome!`
43542
- );
43898
+ class TempUnsupportedControlCodec extends ValueCodec {
43899
+ constructor(valueType) {
43900
+ const encodeValue = (input) => {
43901
+ if (typeof input === "string") {
43902
+ return input;
43903
+ }
43904
+ throw new TempUnsupportedControlEncodeError();
43905
+ };
43906
+ const decodeValue = identity;
43907
+ super(valueType, encodeValue, decodeValue);
43543
43908
  }
43544
43909
  }
43545
43910
 
43546
- const assertRankNodeDefinition = (definition) => {
43547
- if (definition.valueType !== "string") {
43548
- throw new RankValueTypeError(definition);
43549
- }
43550
- };
43551
- const isBlankValueState = (values) => {
43552
- return values.length === 0;
43911
+ const codecs = {
43912
+ string: new TempUnsupportedControlCodec("string"),
43913
+ int: new TempUnsupportedControlCodec("int"),
43914
+ decimal: new TempUnsupportedControlCodec("decimal"),
43915
+ boolean: new TempUnsupportedControlCodec("boolean"),
43916
+ date: new TempUnsupportedControlCodec("date"),
43917
+ time: new TempUnsupportedControlCodec("time"),
43918
+ dateTime: new TempUnsupportedControlCodec("dateTime"),
43919
+ geopoint: new TempUnsupportedControlCodec("geopoint"),
43920
+ geotrace: new TempUnsupportedControlCodec("geotrace"),
43921
+ geoshape: new TempUnsupportedControlCodec("geoshape"),
43922
+ binary: new TempUnsupportedControlCodec("binary"),
43923
+ barcode: new TempUnsupportedControlCodec("barcode"),
43924
+ intent: new TempUnsupportedControlCodec("intent")
43553
43925
  };
43554
- class RankControl extends ValueNode {
43555
- static from(parent, definition) {
43556
- assertRankNodeDefinition(definition);
43557
- return new this(parent, definition);
43926
+ class UnsupportedControlWriteError extends Error {
43927
+ constructor(type) {
43928
+ super(`Cannot write state for node (type: ${type}) - not implemented`);
43558
43929
  }
43559
- mapOptionsByValue;
43560
- getInstanceValue;
43930
+ }
43931
+ class UploadControl extends ValueNode {
43561
43932
  // XFormsXPathElement
43562
43933
  [XPathNodeKindKey] = "element";
43563
43934
  // InstanceNode
43564
43935
  state;
43565
43936
  engineState;
43566
- // RankNode
43567
- nodeType = "rank";
43937
+ // UploadNode
43938
+ nodeType = "upload";
43568
43939
  appearances;
43569
43940
  nodeOptions = null;
43570
43941
  currentState;
43571
- constructor(parent, definition) {
43572
- const codec = new MultipleValueItemCodec(sharedValueCodecs.string);
43573
- super(parent, definition, codec);
43942
+ constructor(parent, instanceNode, definition) {
43943
+ const codec = codecs[definition.valueType];
43944
+ super(parent, instanceNode, definition, codec);
43574
43945
  this.appearances = definition.bodyElement.appearances;
43575
- const valueOptions = createItemCollection(this);
43576
- const mapOptionsByValue = this.scope.runTask(() => {
43577
- return createMemo(() => {
43578
- return new Map(valueOptions().map((item) => [item.value, item]));
43579
- });
43580
- });
43581
- this.mapOptionsByValue = mapOptionsByValue;
43582
- const baseValueState = this.valueState;
43583
- const [baseGetValue, setValue] = baseValueState;
43584
- const getValue = this.scope.runTask(() => {
43585
- return createMemo(() => {
43586
- const options = valueOptions();
43587
- const values = baseGetValue();
43588
- if (isBlankValueState(values)) {
43589
- return values;
43590
- }
43591
- const optionValues = new Set(options.map((option) => option.value));
43592
- const currentValues = values.filter((value) => optionValues.has(value));
43593
- return Array.from(
43594
- /* @__PURE__ */ new Set([
43595
- ...currentValues,
43596
- /**
43597
- * @see {@link getValue} ToDo paragraph 1.
43598
- */
43599
- ...optionValues
43600
- ])
43601
- );
43602
- });
43603
- });
43604
- const valueState = [getValue, setValue];
43605
- this.getInstanceValue = this.scope.runTask(() => {
43606
- return createMemo(() => codec.encodeValue(getValue()));
43607
- });
43608
- const sharedStateOptions = {
43609
- clientStateFactory: this.engineConfig.stateFactory
43610
- };
43611
43946
  const state = createSharedNodeState(
43612
43947
  this.scope,
43613
43948
  {
@@ -43618,209 +43953,218 @@ class RankControl extends ValueNode {
43618
43953
  label: createNodeLabel(this, definition),
43619
43954
  hint: createFieldHint(this, definition),
43620
43955
  children: null,
43621
- valueOptions,
43622
- value: valueState,
43956
+ valueOptions: null,
43957
+ value: this.valueState,
43623
43958
  instanceValue: this.getInstanceValue
43624
43959
  },
43625
- sharedStateOptions
43960
+ this.instanceConfig
43626
43961
  );
43627
43962
  this.state = state;
43628
43963
  this.engineState = state.engineState;
43629
43964
  this.currentState = state.currentState;
43630
43965
  }
43631
- getValueLabel(value) {
43632
- const valueOption = this.currentState.valueOptions.find((item) => item.value === value);
43633
- return valueOption?.label ?? null;
43634
- }
43635
- setValues(valuesInOrder) {
43636
- if (isBlankValueState(valuesInOrder)) {
43637
- this.setValueState(valuesInOrder);
43638
- return this.root;
43639
- }
43640
- const sourceValues = Array.from(this.mapOptionsByValue().keys());
43641
- const hasAllValues = sourceValues.every((sourceValue) => valuesInOrder.includes(sourceValue));
43642
- if (!hasAllValues) {
43643
- throw new RankMissingValueError("There are missing options. Rank should have all options.");
43644
- }
43645
- this.setValueState(valuesInOrder);
43646
- return this.root;
43966
+ // UnsupportedControlNode
43967
+ setValue(_) {
43968
+ throw new UnsupportedControlWriteError(this.nodeType);
43647
43969
  }
43648
43970
  }
43649
43971
 
43650
- const createLeafNodeSubmissionState = (node) => {
43651
- return {
43652
- get submissionXML() {
43653
- if (!node.currentState.relevant) {
43654
- return "";
43972
+ const META_LOCAL_NAME = "meta";
43973
+ const INSTANCE_ID_LOCAL_NAME = "instanceID";
43974
+ const DEPRECATED_ID_LOCAL_NAME = "deprecatedID";
43975
+ const META_NAMESPACE_URIS = [OPENROSA_XFORMS_NAMESPACE_URI$1, XFORMS_NAMESPACE_URI$1];
43976
+ const isMetaNamespacedName = (qualifiedName) => {
43977
+ const namespaceURI = qualifiedName.namespaceURI?.href;
43978
+ return namespaceURI != null && META_NAMESPACE_URIS.includes(namespaceURI);
43979
+ };
43980
+ const isMetaName = (qualifiedName) => {
43981
+ return isMetaNamespacedName(qualifiedName) && qualifiedName.localName === META_LOCAL_NAME;
43982
+ };
43983
+ const isDirectRootDescendant = (parent) => {
43984
+ return parent.parent === parent.root;
43985
+ };
43986
+ const isBaseMetaDefinition = (definition) => {
43987
+ return isMetaName(definition.qualifiedName);
43988
+ };
43989
+ const isMetaSubroot = (options) => {
43990
+ const { nodeType } = options.parent;
43991
+ return (nodeType === "subtree" || nodeType === "group") && isDirectRootDescendant(options.parent) && isBaseMetaDefinition(options.parent.definition);
43992
+ };
43993
+ const isEditModeInstance = (primaryInstance) => {
43994
+ return primaryInstance.initializationMode === "edit";
43995
+ };
43996
+ const isEditModeMetaSubroot = (subroot) => {
43997
+ return isEditModeInstance(subroot.parent.rootDocument);
43998
+ };
43999
+ const isLeafNodeInitOptions = (options) => {
44000
+ const { instanceNodes } = options;
44001
+ const [instanceNode, ...rest] = instanceNodes;
44002
+ return instanceNode != null && rest.length === 0 && instanceNode.isLeafElement();
44003
+ };
44004
+ const findMetaLeafChild = (subroot, localName) => {
44005
+ const metaName = subroot.parent.definition.qualifiedName;
44006
+ const namespaceURI = metaName.namespaceURI.href;
44007
+ const result = Array.from(subroot.children.entries()).find(
44008
+ (entry) => {
44009
+ const [, child] = entry;
44010
+ if (!isLeafNodeInitOptions(child)) {
44011
+ return false;
43655
44012
  }
43656
- const value = node.encodeValue(node.currentState.value);
43657
- const xmlValue = escapeXMLText(value);
43658
- return serializeLeafElementXML(node.definition.qualifiedName, xmlValue);
44013
+ const [instanceNode] = child.instanceNodes;
44014
+ const { qualifiedName } = instanceNode;
44015
+ return qualifiedName.localName === localName && qualifiedName.namespaceURI?.href === namespaceURI;
43659
44016
  }
43660
- };
44017
+ );
44018
+ return result ?? null;
43661
44019
  };
43662
-
43663
- const getInitialValue = (context, options) => {
43664
- const { initialValueSource = "FORM_DEFAULT" } = options;
43665
- if (initialValueSource === "FORM_DEFAULT") {
43666
- return context.definition.defaultValue;
44020
+ const getInstanceIDValue = (subroot) => {
44021
+ const [, child = null] = findMetaLeafChild(subroot, INSTANCE_ID_LOCAL_NAME) ?? [];
44022
+ if (child == null) {
44023
+ return null;
43667
44024
  }
43668
- throw new ErrorProductionDesignPendingError("Edit implementation pending");
44025
+ const [instanceIDNode] = child.instanceNodes;
44026
+ return instanceIDNode.value;
43669
44027
  };
43670
- const createRelevantValueState = (context, baseValueState) => {
43671
- return context.scope.runTask(() => {
43672
- const [getRelevantValue, setValue] = baseValueState;
43673
- const getValue = createMemo(() => {
43674
- if (context.isRelevant()) {
43675
- return getRelevantValue();
43676
- }
43677
- return "";
43678
- });
43679
- return [getValue, setValue];
43680
- });
44028
+ const assertStaticLeafElement = (element) => {
44029
+ if (!element.isLeafElement()) {
44030
+ throw new ErrorProductionDesignPendingError(
44031
+ `Expected a leaf element, got a non-leaf element at nodeset: ${element.nodeset}`
44032
+ );
44033
+ }
43681
44034
  };
43682
- const createRuntimeValueState = (context, relevantValueState) => {
43683
- const { decodeValue, encodeValue } = context;
43684
- return context.scope.runTask(() => {
43685
- const [primaryInstanceValue, setPrimaryInstanceValue] = relevantValueState;
43686
- const getRuntimeValue = createMemo(() => {
43687
- return decodeValue(primaryInstanceValue());
43688
- });
43689
- const setRuntimeValue = (value) => {
43690
- const encodedValue = encodeValue(value);
43691
- return decodeValue(setPrimaryInstanceValue(encodedValue));
43692
- };
43693
- return [getRuntimeValue, setRuntimeValue];
44035
+ const buildMetaValueElement = (subroot, localName, value) => {
44036
+ const { qualifiedName, nodeset } = subroot.parent.definition;
44037
+ const { namespaceURI, prefix } = qualifiedName;
44038
+ const { root } = new StaticDocument({
44039
+ documentRoot: {
44040
+ name: {
44041
+ namespaceURI,
44042
+ prefix,
44043
+ localName
44044
+ },
44045
+ children: [value]
44046
+ },
44047
+ nodesetPrefix: nodeset
43694
44048
  });
44049
+ assertStaticLeafElement(root);
44050
+ return root;
43695
44051
  };
43696
- const guardDownstreamReadonlyWrites = (context, baseState) => {
43697
- const { readonly } = context.definition.bind;
43698
- if (readonly.isDefaultExpression) {
43699
- return baseState;
43700
- }
43701
- const [getValue, baseSetValue] = baseState;
43702
- const setValue = (value) => {
43703
- if (context.isReadonly()) {
43704
- const reference = untrack(() => context.contextReference());
43705
- throw new Error(`Cannot write to readonly field: ${reference}`);
43706
- }
43707
- return baseSetValue(value);
44052
+ const buildDeprecatedIDDefinition = (subroot, instanceNode) => {
44053
+ const nodeset = instanceNode.nodeset;
44054
+ const bind = subroot.model.binds.getOrCreateBindDefinition(nodeset);
44055
+ return new LeafNodeDefinition(subroot.parent.definition, bind, null, instanceNode);
44056
+ };
44057
+ const buildDeprecatedID = (subroot, value) => {
44058
+ const instanceNode = buildMetaValueElement(subroot, DEPRECATED_ID_LOCAL_NAME, value);
44059
+ const definition = buildDeprecatedIDDefinition(subroot, instanceNode);
44060
+ return {
44061
+ childNodeset: instanceNode.nodeset,
44062
+ definition,
44063
+ instanceNodes: [instanceNode]
43708
44064
  };
43709
- return [getValue, setValue];
43710
44065
  };
43711
- const createCalculation = (context, setValue, calculateDefinition) => {
43712
- context.scope.runTask(() => {
43713
- const calculate = createComputedExpression(context, calculateDefinition, {
43714
- defaultValue: ""
43715
- });
43716
- createComputed(() => {
43717
- if (context.isAttached() && context.isRelevant()) {
43718
- const calculated = calculate();
43719
- const value = context.decodeValue(calculated);
43720
- setValue(value);
43721
- }
43722
- });
43723
- });
44066
+ const updateDeprecatedID = (subroot, child, value) => {
44067
+ const instanceNode = buildMetaValueElement(subroot, DEPRECATED_ID_LOCAL_NAME, value);
44068
+ return {
44069
+ childNodeset: child.childNodeset,
44070
+ definition: child.definition,
44071
+ instanceNodes: [instanceNode]
44072
+ };
43724
44073
  };
43725
- const createValueState = (context, options = {}) => {
43726
- return context.scope.runTask(() => {
43727
- const initialValue = getInitialValue(context, options);
43728
- const baseValueState = createSignal(initialValue);
43729
- const valueState = createRelevantValueState(context, baseValueState);
43730
- const runtimeState = createRuntimeValueState(context, valueState);
43731
- const { calculate } = context.definition.bind;
43732
- if (calculate != null) {
43733
- const [, setValue] = runtimeState;
43734
- createCalculation(context, setValue, calculate);
43735
- }
43736
- return guardDownstreamReadonlyWrites(context, runtimeState);
43737
- });
44074
+ const replace = (values, index, value) => {
44075
+ const results = values.slice();
44076
+ results.splice(index, 1, value);
44077
+ return results;
43738
44078
  };
43739
-
43740
- class UnsupportedControlValueEncodeError extends Error {
43741
- constructor(type) {
43742
- super(`Cannot encode state for node (type: ${type}) - not implemented`);
44079
+ const replaceOrConcat = (values, index, value) => {
44080
+ if (index == null) {
44081
+ return values.concat(value);
43743
44082
  }
43744
- }
43745
- class UnsupportedControlWriteError extends Error {
43746
- constructor(type) {
43747
- super(`Cannot write state for node (type: ${type}) - not implemented`);
44083
+ return replace(values, index, value);
44084
+ };
44085
+ const populateDeprecatedID = (subroot) => {
44086
+ const value = getInstanceIDValue(subroot);
44087
+ if (value == null) {
44088
+ return subroot;
43748
44089
  }
43749
- }
43750
- class UnsupportedControl extends DescendantNode {
43751
- validation;
43752
- state;
43753
- // XFormsXPathElement
43754
- [XPathNodeKindKey] = "element";
43755
- // InstanceNode
43756
- engineState;
43757
- appearances;
43758
- nodeOptions = null;
43759
- currentState;
43760
- get validationState() {
43761
- return this.validation.currentState;
44090
+ const [index, currentDeprecatedID] = findMetaLeafChild(subroot, DEPRECATED_ID_LOCAL_NAME) ?? [
44091
+ null
44092
+ ];
44093
+ let deprecatedID;
44094
+ if (currentDeprecatedID == null) {
44095
+ deprecatedID = buildDeprecatedID(subroot, value);
44096
+ } else {
44097
+ deprecatedID = updateDeprecatedID(subroot, currentDeprecatedID, value);
43762
44098
  }
43763
- submissionState;
43764
- encodeValue = (instanceValue) => {
43765
- const encoded = instanceValue;
43766
- if (typeof encoded === "string") {
43767
- return encoded;
43768
- }
43769
- throw new UnsupportedControlValueEncodeError(this.nodeType);
43770
- };
43771
- decodeValue = (instanceValue) => {
43772
- return identity$1(instanceValue);
44099
+ return {
44100
+ model: subroot.model,
44101
+ parent: subroot.parent,
44102
+ children: replaceOrConcat(subroot.children, index, deprecatedID)
43773
44103
  };
43774
- constructor(parent, definition) {
43775
- super(parent, definition);
43776
- this.appearances = definition.bodyElement.appearances;
43777
- const sharedStateOptions = {
43778
- clientStateFactory: this.engineConfig.stateFactory
43779
- };
43780
- const stateSpec = {
43781
- reference: this.contextReference,
43782
- readonly: this.isReadonly,
43783
- relevant: this.isRelevant,
43784
- required: this.isRequired,
43785
- label: createNodeLabel(this, definition),
43786
- hint: createFieldHint(this, definition),
43787
- children: null,
43788
- valueOptions: null,
43789
- value: createValueState(this)
43790
- };
43791
- const state = createSharedNodeState(this.scope, stateSpec, sharedStateOptions);
43792
- this.state = state;
43793
- this.engineState = state.engineState;
43794
- this.currentState = state.currentState;
43795
- this.validation = createValidationState(this, sharedStateOptions);
43796
- this.submissionState = createLeafNodeSubmissionState(this);
43797
- }
43798
- // XFormsXPathElement
43799
- getXPathValue() {
43800
- return this.encodeValue(this.engineState.value);
44104
+ };
44105
+ const normalizeMetaSubroot = (subroot) => {
44106
+ if (isEditModeMetaSubroot(subroot)) {
44107
+ return populateDeprecatedID(subroot);
43801
44108
  }
43802
- // ValidationContext
43803
- getViolation() {
43804
- return this.validation.engineState.violation;
44109
+ return subroot;
44110
+ };
44111
+ const normalizeChildInitOptions = (options) => {
44112
+ if (isMetaSubroot(options)) {
44113
+ return normalizeMetaSubroot(options);
43805
44114
  }
43806
- isBlank() {
43807
- return this.engineState.value === "";
44115
+ return options;
44116
+ };
44117
+
44118
+ const collectModelChildNodesets = (parentTemplate) => {
44119
+ const nodesets = parentTemplate.childElements.map(({ nodeset }) => {
44120
+ return nodeset;
44121
+ });
44122
+ return Array.from(new Set(nodesets));
44123
+ };
44124
+ const groupChildElementsByNodeset = (parent) => {
44125
+ const result = /* @__PURE__ */ new Map();
44126
+ for (const child of parent.childElements) {
44127
+ const { nodeset } = child;
44128
+ const group = result.get(nodeset);
44129
+ if (group == null) {
44130
+ result.set(nodeset, [child]);
44131
+ } else {
44132
+ group.push(child);
44133
+ }
43808
44134
  }
43809
- // InstanceNode
43810
- getChildren() {
43811
- return [];
44135
+ return result;
44136
+ };
44137
+ const assertChildNodeDefinition = (definition, childNodeset) => {
44138
+ if (definition.type === "root") {
44139
+ throw new Error(`Unexpected root definition for child nodeset: ${childNodeset}`);
43812
44140
  }
43813
- // UnsupportedControlNode
43814
- setValue(_) {
43815
- throw new UnsupportedControlWriteError(this.nodeType);
44141
+ };
44142
+ const childrenInitOptions = (parent) => {
44143
+ const { model } = parent.rootDocument;
44144
+ const childNodesets = collectModelChildNodesets(parent.definition.template);
44145
+ let instanceChildren;
44146
+ if (parent.instanceNode == null) {
44147
+ instanceChildren = null;
44148
+ } else {
44149
+ instanceChildren = groupChildElementsByNodeset(parent.instanceNode);
43816
44150
  }
43817
- }
43818
-
43819
- class UploadControl extends UnsupportedControl {
43820
- nodeType = "upload";
43821
- // ValueContext
43822
- contextNode = this;
43823
- }
44151
+ const children = childNodesets.map((childNodeset) => {
44152
+ const definition = model.getNodeDefinition(childNodeset);
44153
+ assertChildNodeDefinition(definition, childNodeset);
44154
+ const instanceNodes = instanceChildren?.get(childNodeset) ?? [];
44155
+ return {
44156
+ childNodeset,
44157
+ definition,
44158
+ instanceNodes
44159
+ };
44160
+ });
44161
+ const baseResult = {
44162
+ parent,
44163
+ model,
44164
+ children
44165
+ };
44166
+ return normalizeChildInitOptions(baseResult);
44167
+ };
43824
44168
 
43825
44169
  const isSubtreeDefinition = (definition) => {
43826
44170
  return definition.bodyElement == null;
@@ -43855,52 +44199,56 @@ const isUploadNodeDefinition = (definition) => {
43855
44199
  return definition.bodyElement.type === "upload";
43856
44200
  };
43857
44201
  const buildChildren = (parent) => {
43858
- const { children } = parent.definition;
43859
- return children.map((child) => {
43860
- switch (child.type) {
44202
+ const { children } = childrenInitOptions(parent);
44203
+ return children.map(({ instanceNodes, definition }) => {
44204
+ const [instanceNode = null] = instanceNodes;
44205
+ switch (definition.type) {
43861
44206
  case "subtree": {
43862
- if (isSubtreeDefinition(child)) {
43863
- return new Subtree(parent, child);
44207
+ if (isSubtreeDefinition(definition)) {
44208
+ return new Subtree(parent, instanceNode, definition);
43864
44209
  }
43865
- return new Group(parent, child);
44210
+ return new Group(parent, instanceNode, definition);
43866
44211
  }
43867
- case "repeat-range": {
43868
- if (child.isControlled()) {
43869
- return new RepeatRangeControlled(parent, child);
44212
+ case "repeat": {
44213
+ if (definition.isControlled()) {
44214
+ return new RepeatRangeControlled(parent, instanceNodes, definition);
43870
44215
  }
43871
- return new RepeatRangeUncontrolled(parent, child);
44216
+ return new RepeatRangeUncontrolled(parent, instanceNodes, definition);
43872
44217
  }
43873
44218
  case "leaf-node": {
43874
- if (child instanceof NoteNodeDefinition) {
43875
- return new Note(parent, child);
44219
+ if (instanceNode != null && !instanceNode.isLeafElement()) {
44220
+ throw new ErrorProductionDesignPendingError();
43876
44221
  }
43877
- const leafChild = child;
44222
+ if (definition instanceof NoteNodeDefinition) {
44223
+ return new Note(parent, instanceNode, definition);
44224
+ }
44225
+ const leafChild = definition;
43878
44226
  if (isModelValueDefinition(leafChild)) {
43879
- return ModelValue.from(parent, leafChild);
44227
+ return ModelValue.from(parent, instanceNode, leafChild);
43880
44228
  }
43881
44229
  if (isInputDefinition(leafChild)) {
43882
- return InputControl.from(parent, leafChild);
44230
+ return InputControl.from(parent, instanceNode, leafChild);
43883
44231
  }
43884
44232
  if (isSelectDefinition(leafChild)) {
43885
- return SelectControl.from(parent, leafChild);
44233
+ return SelectControl.from(parent, instanceNode, leafChild);
43886
44234
  }
43887
44235
  if (isRankDefinition(leafChild)) {
43888
- return RankControl.from(parent, leafChild);
44236
+ return RankControl.from(parent, instanceNode, leafChild);
43889
44237
  }
43890
44238
  if (isTriggerNodeDefinition(leafChild)) {
43891
- return TriggerControl.from(parent, leafChild);
44239
+ return TriggerControl.from(parent, instanceNode, leafChild);
43892
44240
  }
43893
44241
  if (isRangeLeafNodeDefinition(leafChild)) {
43894
44242
  assertRangeNodeDefinition(leafChild);
43895
- return RangeControl.from(parent, leafChild);
44243
+ return RangeControl.from(parent, instanceNode, leafChild);
43896
44244
  }
43897
44245
  if (isUploadNodeDefinition(leafChild)) {
43898
- return new UploadControl(parent, leafChild);
44246
+ return new UploadControl(parent, instanceNode, leafChild);
43899
44247
  }
43900
44248
  throw new UnreachableError$1(leafChild);
43901
44249
  }
43902
44250
  default: {
43903
- throw new UnreachableError$1(child);
44251
+ throw new UnreachableError$1(definition);
43904
44252
  }
43905
44253
  }
43906
44254
  });
@@ -43927,27 +44275,20 @@ class Root extends DescendantNode {
43927
44275
  classes;
43928
44276
  currentState;
43929
44277
  validationState;
43930
- submissionState;
43931
- // ClientReactiveSubmittableInstance
43932
- get submissionDefinition() {
43933
- return this.definition.submission;
43934
- }
43935
- // RootNode
44278
+ instanceState;
43936
44279
  languages;
43937
44280
  constructor(parent) {
43938
- const { definition } = parent;
44281
+ const { definition, instanceNode: instance } = parent;
44282
+ const instanceNode = instance.root;
43939
44283
  const { nodeset: reference } = definition;
43940
44284
  const computeReference = () => reference;
43941
- super(parent, definition, {
44285
+ super(parent, instanceNode, definition, {
43942
44286
  computeReference
43943
44287
  });
43944
44288
  this.classes = parent.classes;
43945
44289
  const childrenState = createChildrenState(this);
43946
44290
  this.childrenState = childrenState;
43947
44291
  this.languages = parent.languages;
43948
- const sharedStateOptions = {
43949
- clientStateFactory: this.engineConfig.stateFactory
43950
- };
43951
44292
  const state = createSharedNodeState(
43952
44293
  this.scope,
43953
44294
  {
@@ -43962,7 +44303,7 @@ class Root extends DescendantNode {
43962
44303
  value: null,
43963
44304
  children: childrenState.childIds
43964
44305
  },
43965
- sharedStateOptions
44306
+ this.instanceConfig
43966
44307
  );
43967
44308
  this.state = state;
43968
44309
  this.engineState = state.engineState;
@@ -43972,8 +44313,8 @@ class Root extends DescendantNode {
43972
44313
  childrenState
43973
44314
  );
43974
44315
  childrenState.setChildren(buildChildren(this));
43975
- this.validationState = createAggregatedViolations(this, sharedStateOptions);
43976
- this.submissionState = createRootSubmissionState(this);
44316
+ this.validationState = createAggregatedViolations(this, this.instanceConfig);
44317
+ this.instanceState = createRootInstanceState(this);
43977
44318
  }
43978
44319
  getChildren() {
43979
44320
  return this.childrenState.getChildren();
@@ -43983,16 +44324,22 @@ class Root extends DescendantNode {
43983
44324
  this.rootDocument.setLanguage(language);
43984
44325
  return this;
43985
44326
  }
43986
- prepareSubmission(options) {
43987
- return this.rootDocument.prepareSubmission(options);
44327
+ prepareInstancePayload(options) {
44328
+ return this.rootDocument.prepareInstancePayload(options);
43988
44329
  }
43989
44330
  }
43990
44331
 
43991
44332
  const PRIMARY_INSTANCE_REFERENCE = "/";
43992
44333
  class PrimaryInstance extends InstanceNode {
44334
+ /**
44335
+ * @todo this will be populated as we introduce other initialization modes!
44336
+ */
44337
+ initializationMode = "create";
44338
+ model;
43993
44339
  // InstanceNode
43994
44340
  state;
43995
44341
  engineState;
44342
+ instanceNode;
43996
44343
  getChildren;
43997
44344
  hasReadonlyAncestor = () => false;
43998
44345
  isReadonly = () => false;
@@ -44002,7 +44349,7 @@ class PrimaryInstance extends InstanceNode {
44002
44349
  setActiveLanguage;
44003
44350
  // XFormsXPathDocument
44004
44351
  [XPathNodeKindKey] = "document";
44005
- // PrimaryInstanceDocument, ClientReactiveSubmittableInstance
44352
+ // PrimaryInstanceDocument, ClientReactiveSerializableInstance
44006
44353
  nodeType = "primary-instance";
44007
44354
  appearances = null;
44008
44355
  nodeOptions = null;
@@ -44010,7 +44357,7 @@ class PrimaryInstance extends InstanceNode {
44010
44357
  root;
44011
44358
  currentState;
44012
44359
  validationState;
44013
- submissionState;
44360
+ instanceState;
44014
44361
  languages;
44015
44362
  // TranslationContext (+ EvaluationContext)
44016
44363
  getActiveLanguage;
@@ -44018,12 +44365,18 @@ class PrimaryInstance extends InstanceNode {
44018
44365
  isAttached;
44019
44366
  evaluator;
44020
44367
  contextNode = this;
44021
- constructor(scope, model, secondaryInstances, engineConfig) {
44022
- const { root: definition } = model;
44023
- super(engineConfig, null, definition, {
44368
+ constructor(options) {
44369
+ const { mode, initialState, scope, model, secondaryInstances, config } = options;
44370
+ const { instance: modelInstance } = model;
44371
+ const activeInstance = initialState?.document ?? modelInstance;
44372
+ const definition = model.getRootDefinition(activeInstance);
44373
+ super(config, null, activeInstance, definition, {
44024
44374
  scope,
44025
44375
  computeReference: () => PRIMARY_INSTANCE_REFERENCE
44026
44376
  });
44377
+ this.initializationMode = mode;
44378
+ this.model = model;
44379
+ this.instanceNode = activeInstance;
44027
44380
  const [isAttached, setIsAttached] = createSignal(false);
44028
44381
  this.isAttached = isAttached;
44029
44382
  const evaluator = new EngineXPathEvaluator({
@@ -44054,9 +44407,7 @@ class PrimaryInstance extends InstanceNode {
44054
44407
  value: null,
44055
44408
  children: childrenState.childIds
44056
44409
  };
44057
- const state = createSharedNodeState(scope, stateSpec, {
44058
- clientStateFactory: engineConfig.stateFactory
44059
- });
44410
+ const state = createSharedNodeState(scope, stateSpec, config);
44060
44411
  this.state = state;
44061
44412
  this.engineState = state.engineState;
44062
44413
  this.currentState = materializeCurrentStateChildren(scope, state.currentState, childrenState);
@@ -44067,7 +44418,7 @@ class PrimaryInstance extends InstanceNode {
44067
44418
  return root.validationState.violations;
44068
44419
  }
44069
44420
  };
44070
- this.submissionState = createInstanceSubmissionState(this);
44421
+ this.instanceState = createPrimaryInstanceState(this);
44071
44422
  childrenState.setChildren([root]);
44072
44423
  setIsAttached(true);
44073
44424
  }
@@ -44103,43 +44454,188 @@ class PrimaryInstance extends InstanceNode {
44103
44454
  this.evaluator.setActiveLanguage(availableFormLanguage.language);
44104
44455
  return this.setActiveLanguage(availableFormLanguage);
44105
44456
  }
44106
- // PrimaryInstanceDocument, ClientReactiveSubmittableInstance
44107
- prepareSubmission(options) {
44108
- const result = prepareSubmission(this, {
44109
- chunked: options?.chunked ?? "monolithic",
44457
+ // PrimaryInstanceDocument
44458
+ prepareInstancePayload(options) {
44459
+ const result = prepareInstancePayload(this, {
44460
+ payloadType: options?.payloadType ?? "monolithic",
44110
44461
  maxSize: options?.maxSize ?? Infinity
44111
44462
  });
44112
44463
  return Promise.resolve(result);
44113
44464
  }
44114
44465
  }
44115
44466
 
44116
- const buildInstanceConfig = (options = {}) => {
44467
+ class FormInstance {
44468
+ constructor(formResult, options) {
44469
+ this.formResult = formResult;
44470
+ const { mode, initialState } = options;
44471
+ const config = {
44472
+ clientStateFactory: options.instanceConfig.stateFactory ?? identity
44473
+ };
44474
+ const primaryInstanceOptions = {
44475
+ ...options.instanceOptions,
44476
+ mode,
44477
+ initialState,
44478
+ config
44479
+ };
44480
+ const { root } = new PrimaryInstance(primaryInstanceOptions);
44481
+ this.mode = mode;
44482
+ this.root = root;
44483
+ }
44484
+ mode;
44485
+ root;
44486
+ }
44487
+
44488
+ class BaseInstantiableFormResult extends BaseFormResult {
44489
+ createInstance;
44490
+ editInstance;
44491
+ restoreInstance;
44492
+ constructor(options) {
44493
+ const { status, warnings, error, instanceOptions } = options;
44494
+ super({
44495
+ status,
44496
+ warnings,
44497
+ error
44498
+ });
44499
+ this.createInstance = (instanceConfig = {}) => {
44500
+ this.assertInstantiable();
44501
+ return new FormInstance(this, {
44502
+ mode: "create",
44503
+ instanceOptions,
44504
+ initialState: null,
44505
+ instanceConfig
44506
+ });
44507
+ };
44508
+ this.editInstance = async (input, instanceConfig = {}) => {
44509
+ this.assertInstantiable();
44510
+ const initialState = await InitialInstanceState.resolve(instanceOptions.model, input);
44511
+ return new FormInstance(this, {
44512
+ mode: "edit",
44513
+ instanceOptions,
44514
+ initialState,
44515
+ instanceConfig
44516
+ });
44517
+ };
44518
+ this.restoreInstance = async (input, instanceConfig = {}) => {
44519
+ this.assertInstantiable();
44520
+ const initialState = await InitialInstanceState.from(instanceOptions.model, input.data);
44521
+ return new FormInstance(this, {
44522
+ mode: "restore",
44523
+ instanceOptions,
44524
+ initialState,
44525
+ instanceConfig
44526
+ });
44527
+ };
44528
+ }
44529
+ isInstantiable() {
44530
+ const self = this;
44531
+ return self.status !== "failure";
44532
+ }
44533
+ assertInstantiable() {
44534
+ if (!this.isInstantiable()) {
44535
+ throw new ErrorProductionDesignPendingError(
44536
+ 'Failed to instantiate from result with status: "failure"'
44537
+ );
44538
+ }
44539
+ }
44540
+ }
44541
+
44542
+ class FormSuccessResult extends BaseInstantiableFormResult {
44543
+ constructor(options) {
44544
+ super({
44545
+ status: "success",
44546
+ ...options
44547
+ });
44548
+ }
44549
+ }
44550
+
44551
+ const createPotentiallyClientOwnedReactiveScope = () => {
44552
+ const clientOwner = getOwner();
44553
+ return createReactiveScope({ owner: clientOwner });
44554
+ };
44555
+ let unboundGlobalFetch;
44556
+ if (typeof globalThis.fetch === "function") {
44557
+ unboundGlobalFetch = (...args) => {
44558
+ return globalThis.fetch(...args);
44559
+ };
44560
+ } else {
44561
+ unboundGlobalFetch = () => {
44562
+ throw new Error("fetch is not supported in this environment");
44563
+ };
44564
+ }
44565
+ const resolveOptions = (options) => {
44117
44566
  return {
44118
- createUniqueId,
44119
- fetchFormDefinition: options.fetchFormDefinition ?? fetch,
44120
- fetchFormAttachment: options.fetchFormAttachment ?? fetch,
44121
- missingResourceBehavior: options.missingResourceBehavior ?? MISSING_RESOURCE_BEHAVIOR.DEFAULT,
44122
- stateFactory: options.stateFactory ?? identity$1
44567
+ fetchFormDefinition: options?.fetchFormDefinition ?? unboundGlobalFetch,
44568
+ fetchFormAttachment: options?.fetchFormAttachment ?? unboundGlobalFetch,
44569
+ missingResourceBehavior: options?.missingResourceBehavior ?? MISSING_RESOURCE_BEHAVIOR.DEFAULT
44123
44570
  };
44124
44571
  };
44125
- const initializeForm$1 = async (input, options = {}) => {
44126
- const owner = getOwner();
44127
- const scope = createReactiveScope({ owner });
44128
- const engineConfig = buildInstanceConfig(options.config);
44129
- const sourceXML = await retrieveSourceXMLResource(input, {
44130
- fetchResource: engineConfig.fetchFormDefinition
44131
- });
44132
- const xformDOM = XFormDOM.from(sourceXML);
44133
- const secondaryInstances = await SecondaryInstancesDefinition.load(xformDOM, {
44134
- fetchResource: engineConfig.fetchFormAttachment,
44135
- missingResourceBehavior: engineConfig.missingResourceBehavior
44136
- });
44137
- const form = new XFormDefinition(xformDOM);
44138
- const primaryInstance = new PrimaryInstance(scope, form.model, secondaryInstances, engineConfig);
44139
- return primaryInstance.root;
44572
+ const loadFormResult = async (scope, formResource, options) => {
44573
+ const { fetchFormDefinition, fetchFormAttachment, missingResourceBehavior } = options;
44574
+ try {
44575
+ const sourceXML = await retrieveFormDefinition(formResource, {
44576
+ fetchFormDefinition
44577
+ });
44578
+ const xformDOM = XFormDOM.from(sourceXML);
44579
+ const { model } = new XFormDefinition(xformDOM);
44580
+ const secondaryInstances = await SecondaryInstancesDefinition.load(xformDOM, {
44581
+ fetchResource: fetchFormAttachment,
44582
+ missingResourceBehavior
44583
+ });
44584
+ const instanceOptions = {
44585
+ scope,
44586
+ model,
44587
+ secondaryInstances
44588
+ };
44589
+ return new FormSuccessResult({
44590
+ warnings: null,
44591
+ error: null,
44592
+ scope,
44593
+ formResource,
44594
+ instanceOptions
44595
+ });
44596
+ } catch (caught) {
44597
+ let cause;
44598
+ if (caught instanceof Error) {
44599
+ cause = caught;
44600
+ } else {
44601
+ cause = new Error("Unknown form load error", { cause: caught });
44602
+ }
44603
+ const error = new LoadFormFailureError(formResource, [cause]);
44604
+ return new FormFailureResult({
44605
+ warnings: null,
44606
+ error
44607
+ });
44608
+ }
44609
+ };
44610
+ const loadForm = (formResource, options) => {
44611
+ const scope = createPotentiallyClientOwnedReactiveScope();
44612
+ const resolvedOptions = resolveOptions(options);
44613
+ return loadFormResult(scope, formResource, resolvedOptions);
44614
+ };
44615
+
44616
+ const createInstance = async (formResource, options) => {
44617
+ const form = await loadForm(formResource, options?.form);
44618
+ if (form.status === "failure") {
44619
+ throw form.error;
44620
+ }
44621
+ return form.createInstance(options?.instance);
44140
44622
  };
44141
44623
 
44142
- const initializeForm = initializeForm$1;
44624
+ const editInstance = async (formResource, input, options) => {
44625
+ const form = await loadForm(formResource, options?.form);
44626
+ if (form.status === "failure") {
44627
+ throw form.error;
44628
+ }
44629
+ return form.editInstance(input, options?.instance);
44630
+ };
44631
+
44632
+ const restoreInstance = async (formResource, input, options) => {
44633
+ const form = await loadForm(formResource, options?.form);
44634
+ if (form.status === "failure") {
44635
+ throw form.error;
44636
+ }
44637
+ return form.restoreInstance(input, options?.instance);
44638
+ };
44143
44639
 
44144
- export { constants, initializeForm };
44640
+ export { constants, createInstance, editInstance, loadForm, restoreInstance };
44145
44641
  //# sourceMappingURL=solid.js.map