@getodk/xforms-engine 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (392) hide show
  1. package/README.md +1 -1
  2. package/dist/client/BaseNode.d.ts +18 -3
  3. package/dist/client/BaseValueNode.d.ts +32 -0
  4. package/dist/client/EngineConfig.d.ts +49 -48
  5. package/dist/client/GroupNode.d.ts +1 -0
  6. package/dist/client/InputNode.d.ts +82 -0
  7. package/dist/client/ModelValueNode.d.ts +13 -7
  8. package/dist/client/NoteNode.d.ts +26 -9
  9. package/dist/client/RangeNode.d.ts +36 -0
  10. package/dist/client/RankNode.d.ts +46 -0
  11. package/dist/client/RootNode.d.ts +37 -7
  12. package/dist/client/SelectNode.d.ts +47 -25
  13. package/dist/client/SubtreeNode.d.ts +1 -0
  14. package/dist/client/TriggerNode.d.ts +10 -6
  15. package/dist/client/ValueType.d.ts +3 -0
  16. package/dist/client/constants.d.ts +50 -0
  17. package/dist/client/hierarchy.d.ts +8 -8
  18. package/dist/client/identity.d.ts +14 -0
  19. package/dist/client/node-types.d.ts +3 -2
  20. package/dist/client/resources.d.ts +93 -0
  21. package/dist/client/submission/SubmissionData.d.ts +7 -0
  22. package/dist/client/submission/SubmissionDefinition.d.ts +14 -0
  23. package/dist/client/submission/SubmissionInstanceFile.d.ts +6 -0
  24. package/dist/client/submission/SubmissionOptions.d.ts +23 -0
  25. package/dist/client/submission/SubmissionResult.d.ts +91 -0
  26. package/dist/client/submission/SubmissionState.d.ts +12 -0
  27. package/dist/client/unsupported/UnsupportedControlNode.d.ts +1 -3
  28. package/dist/client/validation.d.ts +2 -2
  29. package/dist/error/ErrorProductionDesignPendingError.d.ts +7 -0
  30. package/dist/error/RankMissingValueError.d.ts +3 -0
  31. package/dist/error/RankValueTypeError.d.ts +6 -0
  32. package/dist/error/SelectValueTypeError.d.ts +15 -0
  33. package/dist/error/ValueTypeInvariantError.d.ts +17 -0
  34. package/dist/error/XFormsSpecViolationError.d.ts +2 -0
  35. package/dist/error/XPathFunctionalityError.d.ts +14 -0
  36. package/dist/error/XPathFunctionalityNotSupportedError.d.ts +7 -0
  37. package/dist/error/XPathFunctionalityPendingError.d.ts +7 -0
  38. package/dist/index.d.ts +12 -4
  39. package/dist/index.js +17864 -14655
  40. package/dist/index.js.map +1 -1
  41. package/dist/instance/Group.d.ts +10 -4
  42. package/dist/instance/InputControl.d.ts +38 -0
  43. package/dist/instance/ModelValue.d.ts +17 -25
  44. package/dist/instance/Note.d.ts +16 -21
  45. package/dist/instance/PrimaryInstance.d.ts +85 -0
  46. package/dist/instance/RangeControl.d.ts +34 -0
  47. package/dist/instance/RankControl.d.ts +40 -0
  48. package/dist/instance/Root.d.ts +30 -25
  49. package/dist/instance/SelectControl.d.ts +66 -0
  50. package/dist/instance/Subtree.d.ts +11 -5
  51. package/dist/instance/TriggerControl.d.ts +13 -19
  52. package/dist/instance/abstract/DescendantNode.d.ts +32 -25
  53. package/dist/instance/abstract/InstanceNode.d.ts +52 -30
  54. package/dist/instance/abstract/UnsupportedControl.d.ts +11 -3
  55. package/dist/instance/abstract/ValueNode.d.ts +47 -0
  56. package/dist/instance/hierarchy.d.ts +13 -12
  57. package/dist/instance/identity.d.ts +2 -7
  58. package/dist/instance/internal-api/EvaluationContext.d.ts +53 -12
  59. package/dist/instance/internal-api/InstanceConfig.d.ts +8 -2
  60. package/dist/instance/internal-api/InstanceValueContext.d.ts +22 -0
  61. package/dist/instance/internal-api/PrimaryInstanceDocument.d.ts +36 -0
  62. package/dist/instance/internal-api/TranslationContext.d.ts +3 -2
  63. package/dist/instance/internal-api/ValidationContext.d.ts +3 -4
  64. package/dist/instance/internal-api/ValueContext.d.ts +2 -1
  65. package/dist/instance/internal-api/submission/ClientReactiveSubmittableInstance.d.ts +14 -0
  66. package/dist/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.d.ts +32 -0
  67. package/dist/instance/internal-api/submission/ClientReactiveSubmittableParentNode.d.ts +19 -0
  68. package/dist/instance/internal-api/submission/ClientReactiveSubmittableValueNode.d.ts +18 -0
  69. package/dist/instance/repeat/BaseRepeatRange.d.ts +40 -83
  70. package/dist/instance/repeat/RepeatInstance.d.ts +12 -29
  71. package/dist/instance/repeat/RepeatRangeControlled.d.ts +2 -2
  72. package/dist/instance/repeat/RepeatRangeUncontrolled.d.ts +2 -2
  73. package/dist/instance/resource.d.ts +1 -1
  74. package/dist/instance/text/TextRange.d.ts +1 -1
  75. package/dist/instance/unsupported/UploadControl.d.ts +3 -1
  76. package/dist/integration/xpath/EngineXPathEvaluator.d.ts +14 -0
  77. package/dist/integration/xpath/adapter/XFormsXPathNode.d.ts +71 -0
  78. package/dist/integration/xpath/adapter/engineDOMAdapter.d.ts +5 -0
  79. package/dist/integration/xpath/adapter/kind.d.ts +32 -0
  80. package/dist/integration/xpath/adapter/names.d.ts +6 -0
  81. package/dist/integration/xpath/adapter/traversal.d.ts +26 -0
  82. package/dist/integration/xpath/adapter/values.d.ts +2 -0
  83. package/dist/integration/xpath/static-dom/StaticAttribute.d.ts +26 -0
  84. package/dist/integration/xpath/static-dom/StaticDocument.d.ts +15 -0
  85. package/dist/integration/xpath/static-dom/StaticElement.d.ts +48 -0
  86. package/dist/integration/xpath/static-dom/StaticNode.d.ts +33 -0
  87. package/dist/integration/xpath/static-dom/StaticText.d.ts +16 -0
  88. package/dist/lib/client-reactivity/submission/createInstanceSubmissionState.d.ts +3 -0
  89. package/dist/lib/client-reactivity/submission/createLeafNodeSubmissionState.d.ts +3 -0
  90. package/dist/lib/client-reactivity/submission/createNodeRangeSubmissionState.d.ts +4 -0
  91. package/dist/lib/client-reactivity/submission/createParentNodeSubmissionState.d.ts +4 -0
  92. package/dist/lib/client-reactivity/submission/createRootSubmissionState.d.ts +3 -0
  93. package/dist/lib/client-reactivity/submission/createValueNodeSubmissionState.d.ts +3 -0
  94. package/dist/lib/client-reactivity/submission/prepareSubmission.d.ts +8 -0
  95. package/dist/lib/codecs/DecimalValueCodec.d.ts +6 -0
  96. package/dist/lib/codecs/Geopoint/Geopoint.d.ts +48 -0
  97. package/dist/lib/codecs/Geopoint/GeopointValueCodec.d.ts +5 -0
  98. package/dist/lib/codecs/IntValueCodec.d.ts +6 -0
  99. package/dist/lib/codecs/NoteCodec.d.ts +8 -0
  100. package/dist/lib/codecs/RangeCodec.d.ts +8 -0
  101. package/dist/lib/codecs/StringValueCodec.d.ts +4 -0
  102. package/dist/lib/codecs/TriggerCodec.d.ts +7 -0
  103. package/dist/lib/codecs/ValueArrayCodec.d.ts +11 -0
  104. package/dist/lib/codecs/ValueCodec.d.ts +30 -0
  105. package/dist/lib/codecs/ValueTypePlaceholderCodec.d.ts +12 -0
  106. package/dist/lib/codecs/getNoteCodec.d.ts +3 -0
  107. package/dist/lib/codecs/getSelectCodec.d.ts +5 -0
  108. package/dist/lib/codecs/getSharedValueCodec.d.ts +48 -0
  109. package/dist/lib/codecs/items/BaseItemCodec.d.ts +9 -0
  110. package/dist/lib/codecs/items/MultipleValueItemCodec.d.ts +14 -0
  111. package/dist/lib/codecs/items/SingleValueItemCodec.d.ts +24 -0
  112. package/dist/lib/dom/query.d.ts +4 -2
  113. package/dist/lib/names/NamespaceDeclaration.d.ts +45 -0
  114. package/dist/lib/names/NamespaceDeclarationMap.d.ts +137 -0
  115. package/dist/lib/names/NamespaceURL.d.ts +30 -0
  116. package/dist/lib/names/QualifiedName.d.ts +113 -0
  117. package/dist/lib/number-parsers.d.ts +2 -0
  118. package/dist/lib/reactivity/createChildrenState.d.ts +7 -5
  119. package/dist/lib/reactivity/createComputedExpression.d.ts +18 -5
  120. package/dist/lib/reactivity/createInstanceValueState.d.ts +40 -0
  121. package/dist/lib/reactivity/createItemCollection.d.ts +21 -0
  122. package/dist/lib/reactivity/createNoteReadonlyThunk.d.ts +2 -2
  123. package/dist/lib/reactivity/createTranslationState.d.ts +19 -0
  124. package/dist/lib/reactivity/createValueState.d.ts +6 -10
  125. package/dist/lib/reactivity/materializeCurrentStateChildren.d.ts +4 -4
  126. package/dist/lib/xml-serialization.d.ts +50 -0
  127. package/dist/parse/XFormDOM.d.ts +18 -7
  128. package/dist/parse/XFormDefinition.d.ts +1 -2
  129. package/dist/parse/attachments/FormAttachmentResource.d.ts +27 -0
  130. package/dist/parse/body/BodyDefinition.d.ts +4 -4
  131. package/dist/parse/body/RepeatElementDefinition.d.ts +1 -1
  132. package/dist/parse/body/appearance/inputAppearanceParser.d.ts +1 -1
  133. package/dist/parse/body/appearance/rangeAppearanceParser.d.ts +3 -0
  134. package/dist/parse/body/control/{InputDefinition.d.ts → InputControlDefinition.d.ts} +4 -1
  135. package/dist/parse/body/control/ItemDefinition.d.ts +14 -0
  136. package/dist/parse/body/control/ItemsetDefinition.d.ts +18 -0
  137. package/dist/parse/body/control/RangeControlDefinition.d.ts +31 -2
  138. package/dist/parse/body/control/RankControlDefinition.d.ts +7 -3
  139. package/dist/parse/body/control/{select/SelectDefinition.d.ts → SelectControlDefinition.d.ts} +9 -9
  140. package/dist/parse/expression/ItemsetNodesetExpression.d.ts +1 -1
  141. package/dist/parse/expression/ItemsetValueExpression.d.ts +1 -1
  142. package/dist/parse/expression/abstract/DependencyContext.d.ts +0 -5
  143. package/dist/parse/expression/abstract/DependentExpression.d.ts +2 -3
  144. package/dist/parse/model/BindDefinition.d.ts +6 -5
  145. package/dist/parse/model/BindPreloadDefinition.d.ts +42 -0
  146. package/dist/parse/model/BindTypeDefinition.d.ts +20 -0
  147. package/dist/parse/model/DescendentNodeDefinition.d.ts +4 -14
  148. package/dist/parse/model/FormSubmissionDefinition.d.ts +8 -0
  149. package/dist/parse/model/ItextTranslation/ItextTranslationDefinition.d.ts +4 -0
  150. package/dist/parse/model/ItextTranslation/ItextTranslationRootDefinition.d.ts +9 -0
  151. package/dist/parse/model/ItextTranslation/ItextTranslationsDefinition.d.ts +8 -0
  152. package/dist/parse/model/LeafNodeDefinition.d.ts +9 -4
  153. package/dist/parse/model/ModelBindMap.d.ts +1 -1
  154. package/dist/parse/model/ModelDefinition.d.ts +2 -0
  155. package/dist/parse/model/NodeDefinition.d.ts +16 -20
  156. package/dist/parse/model/NoteNodeDefinition.d.ts +9 -8
  157. package/dist/parse/model/RangeNodeDefinition.d.ts +41 -0
  158. package/dist/parse/model/RepeatInstanceDefinition.d.ts +7 -4
  159. package/dist/parse/model/RepeatRangeDefinition.d.ts +7 -4
  160. package/dist/parse/model/RepeatTemplateDefinition.d.ts +7 -4
  161. package/dist/parse/model/RootAttributeDefinition.d.ts +24 -0
  162. package/dist/parse/model/RootAttributeMap.d.ts +23 -0
  163. package/dist/parse/model/RootDefinition.d.ts +12 -9
  164. package/dist/parse/model/SecondaryInstance/SecondaryInstanceDefinition.d.ts +4 -0
  165. package/dist/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.d.ts +7 -0
  166. package/dist/parse/model/SecondaryInstance/SecondaryInstancesDefinition.d.ts +13 -0
  167. package/dist/parse/model/SecondaryInstance/sources/BlankSecondaryInstanceSource.d.ts +14 -0
  168. package/dist/parse/model/SecondaryInstance/sources/CSVExternalSecondaryInstance.d.ts +22 -0
  169. package/dist/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceResource.d.ts +23 -0
  170. package/dist/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceSource.d.ts +9 -0
  171. package/dist/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.d.ts +5 -0
  172. package/dist/parse/model/SecondaryInstance/sources/InternalSecondaryInstanceSource.d.ts +7 -0
  173. package/dist/parse/model/SecondaryInstance/sources/SecondaryInstanceSource.d.ts +13 -0
  174. package/dist/parse/model/SecondaryInstance/sources/XMLExternalSecondaryInstanceSource.d.ts +12 -0
  175. package/dist/parse/model/SubtreeDefinition.d.ts +7 -4
  176. package/dist/parse/shared/parseStaticDocumentFromDOMSubtree.d.ts +23 -0
  177. package/dist/parse/text/ItemLabelDefinition.d.ts +1 -1
  178. package/dist/parse/text/ItemsetLabelDefinition.d.ts +2 -2
  179. package/dist/parse/text/abstract/TextElementDefinition.d.ts +1 -1
  180. package/dist/parse/text/abstract/TextRangeDefinition.d.ts +0 -2
  181. package/dist/parse/xpath/semantic-analysis.d.ts +6 -3
  182. package/dist/solid.js +15437 -12246
  183. package/dist/solid.js.map +1 -1
  184. package/package.json +18 -13
  185. package/src/client/BaseNode.ts +21 -6
  186. package/src/client/BaseValueNode.ts +35 -0
  187. package/src/client/EngineConfig.ts +52 -51
  188. package/src/client/GroupNode.ts +1 -0
  189. package/src/client/InputNode.ts +113 -0
  190. package/src/client/ModelValueNode.ts +31 -7
  191. package/src/client/NoteNode.ts +45 -9
  192. package/src/client/RangeNode.ts +51 -0
  193. package/src/client/RankNode.ts +54 -0
  194. package/src/client/RootNode.ts +43 -7
  195. package/src/client/SelectNode.ts +53 -26
  196. package/src/client/SubtreeNode.ts +1 -0
  197. package/src/client/TriggerNode.ts +12 -6
  198. package/src/client/ValueType.ts +4 -0
  199. package/src/client/constants.ts +67 -0
  200. package/src/client/hierarchy.ts +12 -13
  201. package/src/client/identity.ts +16 -0
  202. package/src/client/node-types.ts +13 -7
  203. package/src/client/resources.ts +118 -0
  204. package/src/client/submission/SubmissionData.ts +12 -0
  205. package/src/client/submission/SubmissionDefinition.ts +16 -0
  206. package/src/client/submission/SubmissionInstanceFile.ts +9 -0
  207. package/src/client/submission/SubmissionOptions.ts +28 -0
  208. package/src/client/submission/SubmissionResult.ts +124 -0
  209. package/src/client/submission/SubmissionState.ts +14 -0
  210. package/src/client/unsupported/UnsupportedControlNode.ts +2 -6
  211. package/src/client/validation.ts +2 -2
  212. package/src/error/ErrorProductionDesignPendingError.ts +6 -0
  213. package/src/error/RankMissingValueError.ts +5 -0
  214. package/src/error/RankValueTypeError.ts +13 -0
  215. package/src/error/SelectValueTypeError.ts +22 -0
  216. package/src/error/ValueTypeInvariantError.ts +22 -0
  217. package/src/error/XFormsSpecViolationError.ts +1 -0
  218. package/src/error/XPathFunctionalityError.ts +26 -0
  219. package/src/error/XPathFunctionalityNotSupportedError.ts +18 -0
  220. package/src/error/XPathFunctionalityPendingError.ts +18 -0
  221. package/src/index.ts +12 -13
  222. package/src/instance/Group.ts +18 -5
  223. package/src/instance/InputControl.ts +159 -0
  224. package/src/instance/ModelValue.ts +48 -53
  225. package/src/instance/Note.ts +40 -49
  226. package/src/instance/PrimaryInstance.ts +245 -0
  227. package/src/instance/RangeControl.ts +113 -0
  228. package/src/instance/RankControl.ts +199 -0
  229. package/src/instance/Root.ts +63 -134
  230. package/src/instance/SelectControl.ts +219 -0
  231. package/src/instance/Subtree.ts +20 -7
  232. package/src/instance/TriggerControl.ts +44 -66
  233. package/src/instance/abstract/DescendantNode.ts +91 -51
  234. package/src/instance/abstract/InstanceNode.ts +113 -107
  235. package/src/instance/abstract/UnsupportedControl.ts +29 -5
  236. package/src/instance/abstract/ValueNode.ts +128 -0
  237. package/src/instance/children.ts +80 -40
  238. package/src/instance/hierarchy.ts +39 -30
  239. package/src/instance/identity.ts +3 -9
  240. package/src/instance/index.ts +25 -7
  241. package/src/instance/internal-api/EvaluationContext.ts +60 -13
  242. package/src/instance/internal-api/InstanceConfig.ts +9 -2
  243. package/src/instance/internal-api/InstanceValueContext.ts +26 -0
  244. package/src/instance/internal-api/PrimaryInstanceDocument.ts +53 -0
  245. package/src/instance/internal-api/TranslationContext.ts +3 -2
  246. package/src/instance/internal-api/ValidationContext.ts +3 -4
  247. package/src/instance/internal-api/ValueContext.ts +2 -1
  248. package/src/instance/internal-api/submission/ClientReactiveSubmittableInstance.ts +20 -0
  249. package/src/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.ts +43 -0
  250. package/src/instance/internal-api/submission/ClientReactiveSubmittableParentNode.ts +26 -0
  251. package/src/instance/internal-api/submission/ClientReactiveSubmittableValueNode.ts +24 -0
  252. package/src/instance/repeat/BaseRepeatRange.ts +52 -131
  253. package/src/instance/repeat/RepeatInstance.ts +21 -46
  254. package/src/instance/repeat/RepeatRangeControlled.ts +5 -5
  255. package/src/instance/repeat/RepeatRangeUncontrolled.ts +2 -4
  256. package/src/instance/resource.ts +5 -2
  257. package/src/instance/text/TextChunk.ts +1 -1
  258. package/src/instance/unsupported/UploadControl.ts +5 -1
  259. package/src/integration/xpath/EngineXPathEvaluator.ts +22 -0
  260. package/src/integration/xpath/adapter/XFormsXPathNode.ts +126 -0
  261. package/src/integration/xpath/adapter/engineDOMAdapter.ts +57 -0
  262. package/src/integration/xpath/adapter/kind.ts +114 -0
  263. package/src/integration/xpath/adapter/names.ts +148 -0
  264. package/src/integration/xpath/adapter/traversal.ts +229 -0
  265. package/src/integration/xpath/adapter/values.ts +5 -0
  266. package/src/integration/xpath/static-dom/StaticAttribute.ts +41 -0
  267. package/src/integration/xpath/static-dom/StaticDocument.ts +36 -0
  268. package/src/integration/xpath/static-dom/StaticElement.ts +119 -0
  269. package/src/integration/xpath/static-dom/StaticNode.ts +68 -0
  270. package/src/integration/xpath/static-dom/StaticText.ts +28 -0
  271. package/src/lib/client-reactivity/README.md +0 -0
  272. package/src/lib/client-reactivity/submission/createInstanceSubmissionState.ts +12 -0
  273. package/src/lib/client-reactivity/submission/createLeafNodeSubmissionState.ts +20 -0
  274. package/src/lib/client-reactivity/submission/createNodeRangeSubmissionState.ts +17 -0
  275. package/src/lib/client-reactivity/submission/createParentNodeSubmissionState.ts +22 -0
  276. package/src/lib/client-reactivity/submission/createRootSubmissionState.ts +19 -0
  277. package/src/lib/client-reactivity/submission/createValueNodeSubmissionState.ts +21 -0
  278. package/src/lib/client-reactivity/submission/prepareSubmission.ts +172 -0
  279. package/src/lib/codecs/DecimalValueCodec.ts +46 -0
  280. package/src/lib/codecs/Geopoint/Geopoint.ts +150 -0
  281. package/src/lib/codecs/Geopoint/GeopointValueCodec.ts +20 -0
  282. package/src/lib/codecs/IntValueCodec.ts +100 -0
  283. package/src/lib/codecs/NoteCodec.ts +32 -0
  284. package/src/lib/codecs/RangeCodec.ts +65 -0
  285. package/src/lib/codecs/StringValueCodec.ts +11 -0
  286. package/src/lib/codecs/TriggerCodec.ts +64 -0
  287. package/src/lib/codecs/ValueArrayCodec.ts +42 -0
  288. package/src/lib/codecs/ValueCodec.ts +106 -0
  289. package/src/lib/codecs/ValueTypePlaceholderCodec.ts +19 -0
  290. package/src/lib/codecs/getNoteCodec.ts +27 -0
  291. package/src/lib/codecs/getSelectCodec.ts +27 -0
  292. package/src/lib/codecs/getSharedValueCodec.ts +79 -0
  293. package/src/lib/codecs/items/BaseItemCodec.ts +20 -0
  294. package/src/lib/codecs/items/MultipleValueItemCodec.ts +28 -0
  295. package/src/lib/codecs/items/SingleValueItemCodec.ts +67 -0
  296. package/src/lib/dom/query.ts +8 -2
  297. package/src/lib/names/NamespaceDeclaration.ts +106 -0
  298. package/src/lib/names/NamespaceDeclarationMap.ts +228 -0
  299. package/src/lib/names/NamespaceURL.ts +44 -0
  300. package/src/lib/names/QualifiedName.ts +170 -0
  301. package/src/lib/number-parsers.ts +25 -0
  302. package/src/lib/reactivity/createChildrenState.ts +8 -6
  303. package/src/lib/reactivity/createComputedExpression.ts +57 -34
  304. package/src/lib/reactivity/createInstanceValueState.ts +216 -0
  305. package/src/lib/reactivity/createItemCollection.ts +173 -0
  306. package/src/lib/reactivity/createNoteReadonlyThunk.ts +12 -7
  307. package/src/lib/reactivity/createTranslationState.ts +61 -0
  308. package/src/lib/reactivity/createValueState.ts +62 -120
  309. package/src/lib/reactivity/materializeCurrentStateChildren.ts +7 -7
  310. package/src/lib/reactivity/text/createTextRange.ts +4 -3
  311. package/src/lib/reactivity/validation/createAggregatedViolations.ts +1 -1
  312. package/src/lib/reactivity/validation/createValidation.ts +2 -3
  313. package/src/lib/xml-serialization.ts +163 -0
  314. package/src/parse/XFormDOM.ts +231 -76
  315. package/src/parse/XFormDefinition.ts +2 -10
  316. package/src/parse/attachments/FormAttachmentResource.ts +40 -0
  317. package/src/parse/body/BodyDefinition.ts +7 -7
  318. package/src/parse/body/appearance/inputAppearanceParser.ts +1 -1
  319. package/src/parse/body/appearance/rangeAppearanceParser.ts +11 -0
  320. package/src/parse/body/control/InputControlDefinition.ts +29 -0
  321. package/src/parse/body/control/{select/ItemDefinition.ts → ItemDefinition.ts} +8 -6
  322. package/src/parse/body/control/{select/ItemsetDefinition.ts → ItemsetDefinition.ts} +11 -9
  323. package/src/parse/body/control/RangeControlDefinition.ts +91 -6
  324. package/src/parse/body/control/RankControlDefinition.ts +25 -7
  325. package/src/parse/body/control/{select/SelectDefinition.ts → SelectControlDefinition.ts} +9 -9
  326. package/src/parse/expression/ItemsetNodesetExpression.ts +1 -1
  327. package/src/parse/expression/ItemsetValueExpression.ts +1 -1
  328. package/src/parse/expression/abstract/DependencyContext.ts +0 -26
  329. package/src/parse/expression/abstract/DependentExpression.ts +2 -13
  330. package/src/parse/model/BindDefinition.ts +9 -8
  331. package/src/parse/model/BindPreloadDefinition.ts +100 -0
  332. package/src/parse/model/BindTypeDefinition.ts +175 -0
  333. package/src/parse/model/DescendentNodeDefinition.ts +7 -31
  334. package/src/parse/model/FormSubmissionDefinition.ts +44 -0
  335. package/src/parse/model/ItextTranslation/ItextTranslationDefinition.ts +4 -0
  336. package/src/parse/model/ItextTranslation/ItextTranslationRootDefinition.ts +42 -0
  337. package/src/parse/model/ItextTranslation/ItextTranslationsDefinition.ts +31 -0
  338. package/src/parse/model/LeafNodeDefinition.ts +15 -5
  339. package/src/parse/model/ModelBindMap.ts +6 -8
  340. package/src/parse/model/ModelDefinition.ts +6 -1
  341. package/src/parse/model/NodeDefinition.ts +24 -48
  342. package/src/parse/model/NoteNodeDefinition.ts +11 -10
  343. package/src/parse/model/RangeNodeDefinition.ts +118 -0
  344. package/src/parse/model/RepeatInstanceDefinition.ts +11 -7
  345. package/src/parse/model/RepeatRangeDefinition.ts +11 -7
  346. package/src/parse/model/RepeatTemplateDefinition.ts +11 -7
  347. package/src/parse/model/RootAttributeDefinition.ts +45 -0
  348. package/src/parse/model/RootAttributeMap.ts +44 -0
  349. package/src/parse/model/RootDefinition.ts +31 -29
  350. package/src/parse/model/SecondaryInstance/SecondaryInstanceDefinition.ts +4 -0
  351. package/src/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.ts +12 -0
  352. package/src/parse/model/SecondaryInstance/SecondaryInstancesDefinition.ts +102 -0
  353. package/src/parse/model/SecondaryInstance/sources/BlankSecondaryInstanceSource.ts +40 -0
  354. package/src/parse/model/SecondaryInstance/sources/CSVExternalSecondaryInstance.ts +288 -0
  355. package/src/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceResource.ts +222 -0
  356. package/src/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceSource.ts +22 -0
  357. package/src/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.ts +415 -0
  358. package/src/parse/model/SecondaryInstance/sources/InternalSecondaryInstanceSource.ts +19 -0
  359. package/src/parse/model/SecondaryInstance/sources/SecondaryInstanceSource.ts +29 -0
  360. package/src/parse/model/SecondaryInstance/sources/XMLExternalSecondaryInstanceSource.ts +32 -0
  361. package/src/parse/model/SubtreeDefinition.ts +12 -12
  362. package/src/parse/shared/parseStaticDocumentFromDOMSubtree.ts +149 -0
  363. package/src/parse/text/ItemLabelDefinition.ts +1 -1
  364. package/src/parse/text/ItemsetLabelDefinition.ts +2 -2
  365. package/src/parse/text/abstract/TextElementDefinition.ts +1 -1
  366. package/src/parse/text/abstract/TextRangeDefinition.ts +0 -6
  367. package/src/parse/xpath/semantic-analysis.ts +33 -3
  368. package/dist/client/StringNode.d.ts +0 -46
  369. package/dist/client/unsupported/RangeNode.d.ts +0 -9
  370. package/dist/client/unsupported/RankNode.d.ts +0 -9
  371. package/dist/instance/SelectField.d.ts +0 -50
  372. package/dist/instance/StringField.d.ts +0 -44
  373. package/dist/instance/internal-api/SubscribableDependency.d.ts +0 -59
  374. package/dist/instance/unsupported/RangeControl.d.ts +0 -4
  375. package/dist/instance/unsupported/RankControl.d.ts +0 -4
  376. package/dist/lib/reactivity/createSelectItems.d.ts +0 -16
  377. package/dist/parse/XFormDataType.d.ts +0 -25
  378. package/dist/parse/body/control/select/ItemDefinition.d.ts +0 -13
  379. package/dist/parse/body/control/select/ItemsetDefinition.d.ts +0 -17
  380. package/dist/parse/body/control/select/ItemsetNodesetContext.d.ts +0 -11
  381. package/src/client/StringNode.ts +0 -52
  382. package/src/client/unsupported/RangeNode.ts +0 -14
  383. package/src/client/unsupported/RankNode.ts +0 -14
  384. package/src/instance/SelectField.ts +0 -226
  385. package/src/instance/StringField.ts +0 -120
  386. package/src/instance/internal-api/SubscribableDependency.ts +0 -61
  387. package/src/instance/unsupported/RangeControl.ts +0 -5
  388. package/src/instance/unsupported/RankControl.ts +0 -5
  389. package/src/lib/reactivity/createSelectItems.ts +0 -168
  390. package/src/parse/XFormDataType.ts +0 -62
  391. package/src/parse/body/control/InputDefinition.ts +0 -22
  392. package/src/parse/body/control/select/ItemsetNodesetContext.ts +0 -26
@@ -1,226 +0,0 @@
1
- import { xmlXPathWhitespaceSeparatedList } from '@getodk/common/lib/string/whitespace.ts';
2
- import type { Accessor } from 'solid-js';
3
- import { untrack } from 'solid-js';
4
- import type { SelectItem, SelectNode, SelectNodeAppearances } from '../client/SelectNode.ts';
5
- import type { TextRange } from '../client/TextRange.ts';
6
- import type { AnyViolation, LeafNodeValidationState } from '../client/validation.ts';
7
- import { createSelectItems } from '../lib/reactivity/createSelectItems.ts';
8
- import { createValueState } from '../lib/reactivity/createValueState.ts';
9
- import type { CurrentState } from '../lib/reactivity/node-state/createCurrentState.ts';
10
- import type { EngineState } from '../lib/reactivity/node-state/createEngineState.ts';
11
- import type { SharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
12
- import { createSharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
13
- import { createFieldHint } from '../lib/reactivity/text/createFieldHint.ts';
14
- import { createNodeLabel } from '../lib/reactivity/text/createNodeLabel.ts';
15
- import type { SimpleAtomicState } from '../lib/reactivity/types.ts';
16
- import type { SharedValidationState } from '../lib/reactivity/validation/createValidation.ts';
17
- import { createValidationState } from '../lib/reactivity/validation/createValidation.ts';
18
- import type { AnySelectDefinition } from '../parse/body/control/select/SelectDefinition.ts';
19
- import type { LeafNodeDefinition } from '../parse/model/LeafNodeDefinition.ts';
20
- import type { Root } from './Root.ts';
21
- import type { DescendantNodeStateSpec } from './abstract/DescendantNode.ts';
22
- import { DescendantNode } from './abstract/DescendantNode.ts';
23
- import type { GeneralParentNode } from './hierarchy.ts';
24
- import type { EvaluationContext } from './internal-api/EvaluationContext.ts';
25
- import type { SubscribableDependency } from './internal-api/SubscribableDependency.ts';
26
- import type { ValidationContext } from './internal-api/ValidationContext.ts';
27
- import type { ValueContext } from './internal-api/ValueContext.ts';
28
-
29
- export interface SelectFieldDefinition extends LeafNodeDefinition {
30
- readonly bodyElement: AnySelectDefinition;
31
- }
32
-
33
- interface SelectFieldStateSpec extends DescendantNodeStateSpec<readonly SelectItem[]> {
34
- readonly label: Accessor<TextRange<'label'> | null>;
35
- readonly hint: Accessor<TextRange<'hint'> | null>;
36
- readonly children: null;
37
- readonly value: SimpleAtomicState<readonly SelectItem[]>;
38
- readonly valueOptions: Accessor<readonly SelectItem[]>;
39
- }
40
-
41
- export class SelectField
42
- extends DescendantNode<SelectFieldDefinition, SelectFieldStateSpec, null>
43
- implements
44
- SelectNode,
45
- EvaluationContext,
46
- SubscribableDependency,
47
- ValidationContext,
48
- ValueContext<readonly SelectItem[]>
49
- {
50
- private readonly selectExclusive: boolean;
51
- private readonly validation: SharedValidationState;
52
-
53
- // InstanceNode
54
- protected readonly state: SharedNodeState<SelectFieldStateSpec>;
55
- protected override engineState: EngineState<SelectFieldStateSpec>;
56
-
57
- // SelectNode
58
- readonly nodeType = 'select';
59
- readonly appearances: SelectNodeAppearances;
60
- readonly currentState: CurrentState<SelectFieldStateSpec>;
61
-
62
- get validationState(): LeafNodeValidationState {
63
- return this.validation.currentState;
64
- }
65
-
66
- // ValueContext
67
- readonly encodeValue = (runtimeValue: readonly SelectItem[]): string => {
68
- const itemValues = new Set(runtimeValue.map(({ value }) => value));
69
-
70
- return Array.from(itemValues).join(' ');
71
- };
72
-
73
- readonly decodeValue = (instanceValue: string): readonly SelectItem[] => {
74
- return this.scope.runTask(() => {
75
- const values = xmlXPathWhitespaceSeparatedList(instanceValue, {
76
- ignoreEmpty: true,
77
- });
78
-
79
- const items = this.getSelectItemsByValue();
80
-
81
- return values
82
- .map((value) => {
83
- return items.get(value);
84
- })
85
- .filter((item): item is SelectItem => {
86
- return item != null;
87
- });
88
- });
89
- };
90
-
91
- protected readonly getValueOptions: Accessor<readonly SelectItem[]>;
92
-
93
- constructor(parent: GeneralParentNode, definition: SelectFieldDefinition) {
94
- super(parent, definition);
95
-
96
- this.appearances = definition.bodyElement.appearances;
97
- this.selectExclusive = definition.bodyElement.type === 'select1';
98
-
99
- const valueOptions = createSelectItems(this);
100
-
101
- this.getValueOptions = valueOptions;
102
-
103
- const sharedStateOptions = {
104
- clientStateFactory: this.engineConfig.stateFactory,
105
- };
106
-
107
- const state = createSharedNodeState(
108
- this.scope,
109
- {
110
- reference: this.contextReference,
111
- readonly: this.isReadonly,
112
- relevant: this.isRelevant,
113
- required: this.isRequired,
114
-
115
- label: createNodeLabel(this, definition),
116
- hint: createFieldHint(this, definition),
117
- children: null,
118
- value: createValueState(this),
119
- valueOptions,
120
- },
121
- sharedStateOptions
122
- );
123
-
124
- this.state = state;
125
- this.engineState = state.engineState;
126
- this.currentState = state.currentState;
127
- this.validation = createValidationState(this, sharedStateOptions);
128
- }
129
-
130
- protected getSelectItemsByValue(
131
- valueOptions: readonly SelectItem[] = this.getValueOptions()
132
- ): ReadonlyMap<string, SelectItem> {
133
- return new Map(
134
- valueOptions.map((item) => {
135
- return [item.value, item];
136
- })
137
- );
138
- }
139
-
140
- protected updateSelectedItemValues(values: readonly string[]) {
141
- const itemsByValue = untrack(() => this.getSelectItemsByValue());
142
-
143
- const items = values.flatMap((value) => {
144
- const item = itemsByValue.get(value);
145
-
146
- if (item == null) {
147
- return [];
148
- }
149
-
150
- return item ?? [];
151
- });
152
-
153
- this.state.setProperty('value', items);
154
- }
155
-
156
- protected setSelectedItemValue(value: string | null) {
157
- if (value == null) {
158
- this.state.setProperty('value', []);
159
-
160
- return;
161
- }
162
-
163
- this.updateSelectedItemValues([value]);
164
- }
165
-
166
- // SelectNode
167
- select(selectedItem: SelectItem): Root {
168
- const { engineState, root } = this;
169
-
170
- if (this.selectExclusive) {
171
- this.setSelectedItemValue(selectedItem.value);
172
-
173
- return root;
174
- }
175
-
176
- const currentValues = engineState.value.map(({ value }) => {
177
- return value;
178
- });
179
-
180
- const selectedValue = selectedItem.value;
181
-
182
- if (currentValues.includes(selectedValue)) {
183
- return root;
184
- }
185
-
186
- this.updateSelectedItemValues(currentValues.concat(selectedValue));
187
-
188
- return root;
189
- }
190
-
191
- deselect(deselectedItem: SelectItem): Root {
192
- const { engineState, root } = this;
193
-
194
- const currentValues = engineState.value.map(({ value }) => {
195
- return value;
196
- });
197
-
198
- const selectedValue = deselectedItem.value;
199
-
200
- if (!currentValues.includes(selectedValue)) {
201
- return root;
202
- }
203
-
204
- const updatedValues = currentValues.filter((value) => {
205
- return value !== selectedValue;
206
- });
207
-
208
- this.updateSelectedItemValues(updatedValues);
209
-
210
- return root;
211
- }
212
-
213
- // InstanceNode
214
- getChildren(): readonly [] {
215
- return [];
216
- }
217
-
218
- // ValidationContext
219
- getViolation(): AnyViolation | null {
220
- return this.validation.engineState.violation;
221
- }
222
-
223
- isBlank(): boolean {
224
- return this.engineState.value.length === 0;
225
- }
226
- }
@@ -1,120 +0,0 @@
1
- import { identity } from '@getodk/common/lib/identity.ts';
2
- import type { Accessor } from 'solid-js';
3
- import type { StringNode, StringNodeAppearances } from '../client/StringNode.ts';
4
- import type { TextRange } from '../client/TextRange.ts';
5
- import type { AnyViolation, LeafNodeValidationState } from '../client/validation.ts';
6
- import { createValueState } from '../lib/reactivity/createValueState.ts';
7
- import type { CurrentState } from '../lib/reactivity/node-state/createCurrentState.ts';
8
- import type { EngineState } from '../lib/reactivity/node-state/createEngineState.ts';
9
- import type { SharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
10
- import { createSharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
11
- import { createFieldHint } from '../lib/reactivity/text/createFieldHint.ts';
12
- import { createNodeLabel } from '../lib/reactivity/text/createNodeLabel.ts';
13
- import type { SimpleAtomicState } from '../lib/reactivity/types.ts';
14
- import type { SharedValidationState } from '../lib/reactivity/validation/createValidation.ts';
15
- import { createValidationState } from '../lib/reactivity/validation/createValidation.ts';
16
- import type { InputDefinition } from '../parse/body/control/InputDefinition.ts';
17
- import type { LeafNodeDefinition } from '../parse/model/LeafNodeDefinition.ts';
18
- import type { Root } from './Root.ts';
19
- import type { DescendantNodeStateSpec } from './abstract/DescendantNode.ts';
20
- import { DescendantNode } from './abstract/DescendantNode.ts';
21
- import type { GeneralParentNode } from './hierarchy.ts';
22
- import type { EvaluationContext } from './internal-api/EvaluationContext.ts';
23
- import type { SubscribableDependency } from './internal-api/SubscribableDependency.ts';
24
- import type { ValidationContext } from './internal-api/ValidationContext.ts';
25
- import type { ValueContext } from './internal-api/ValueContext.ts';
26
-
27
- export interface StringFieldDefinition extends LeafNodeDefinition {
28
- readonly bodyElement: InputDefinition;
29
- }
30
-
31
- interface StringFieldStateSpec extends DescendantNodeStateSpec<string> {
32
- readonly label: Accessor<TextRange<'label'> | null>;
33
- readonly hint: Accessor<TextRange<'hint'> | null>;
34
- readonly children: null;
35
- readonly value: SimpleAtomicState<string>;
36
- readonly valueOptions: null;
37
- }
38
-
39
- export class StringField
40
- extends DescendantNode<StringFieldDefinition, StringFieldStateSpec, null>
41
- implements
42
- StringNode,
43
- EvaluationContext,
44
- SubscribableDependency,
45
- ValidationContext,
46
- ValueContext<string>
47
- {
48
- private readonly validation: SharedValidationState;
49
- protected readonly state: SharedNodeState<StringFieldStateSpec>;
50
-
51
- // InstanceNode
52
- protected engineState: EngineState<StringFieldStateSpec>;
53
-
54
- // StringNode
55
- readonly nodeType = 'string';
56
- readonly appearances: StringNodeAppearances;
57
- readonly currentState: CurrentState<StringFieldStateSpec>;
58
-
59
- get validationState(): LeafNodeValidationState {
60
- return this.validation.currentState;
61
- }
62
-
63
- // ValueContext
64
- readonly encodeValue = identity<string>;
65
-
66
- readonly decodeValue = identity<string>;
67
-
68
- constructor(parent: GeneralParentNode, definition: StringFieldDefinition) {
69
- super(parent, definition);
70
-
71
- this.appearances = definition.bodyElement.appearances;
72
-
73
- const sharedStateOptions = {
74
- clientStateFactory: this.engineConfig.stateFactory,
75
- };
76
-
77
- const state = createSharedNodeState(
78
- this.scope,
79
- {
80
- reference: this.contextReference,
81
- readonly: this.isReadonly,
82
- relevant: this.isRelevant,
83
- required: this.isRequired,
84
-
85
- label: createNodeLabel(this, definition),
86
- hint: createFieldHint(this, definition),
87
- children: null,
88
- valueOptions: null,
89
- value: createValueState(this),
90
- },
91
- sharedStateOptions
92
- );
93
-
94
- this.state = state;
95
- this.engineState = state.engineState;
96
- this.currentState = state.currentState;
97
- this.validation = createValidationState(this, sharedStateOptions);
98
- }
99
-
100
- // ValidationContext
101
- getViolation(): AnyViolation | null {
102
- return this.validation.engineState.violation;
103
- }
104
-
105
- isBlank(): boolean {
106
- return this.engineState.value === '';
107
- }
108
-
109
- // InstanceNode
110
- getChildren(): readonly [] {
111
- return [];
112
- }
113
-
114
- // StringNode
115
- setValue(value: string): Root {
116
- this.state.setProperty('value', value);
117
-
118
- return this.root;
119
- }
120
- }
@@ -1,61 +0,0 @@
1
- import type { ReactiveScope } from '../../lib/reactivity/scope.ts';
2
- import type { EvaluationContext } from './EvaluationContext.ts';
3
-
4
- /**
5
- * Provides a common interface to explicitly establish a reactive subscription
6
- * to a form node, regardless of which node-specific details might trigger
7
- * reactive updates. This is primarily intended for use in coordination with a
8
- * node's {@link EvaluationContext} interface, so that computed expression
9
- * evaluations can be re-executed when their dependencies update, without
10
- * requiring a given evaluation to handle node-specific logic to determine
11
- * when/whether updates have occurred.
12
- *
13
- * @example Given a form with these bindings:
14
- *
15
- * ```xml
16
- * <bind nodeset="/data/field-1" />
17
- * <bind nodeset="/data/field-2" type="int" />
18
- * <bind nodeset="/data/group-a" relevant="/data/field-1 != ''" />
19
- * <bind nodeset="/data/group-a/field-a-1" calculate="/data/field-2 * 2" />
20
- * ```
21
- *
22
- * The field `/data/group-a/field-a-1`'s calculate has two dependencies:
23
- *
24
- * - `/data-field-2` (explicit)
25
- * - `/data/group-a` (implicit: non-relevance is inherited)
26
- *
27
- * (This is an oversimplification, but it helps to illustrate the concept.)
28
- *
29
- * The first dependency's subscription is clearly concerned with that leaf
30
- * node's value. In which case, that node's `subscribe` method should react to
31
- * updates to its value (e.g. its `currentState.value` or the internal reactive
32
- * representation thereof).
33
- *
34
- * Whereas the second dependency has no value (no parent nodes do); instead, the
35
- * subscription would be concerned with that node's relevance. In which case,
36
- * that node's `subscribe` method should react to updates to its relevance state
37
- * (e.g. its `currentState.relevant` or the internal reactive represeentation
38
- * thereof).
39
- *
40
- * @example Given a form with:
41
- *
42
- * ```xml
43
- * <!-- model -->
44
- * <bind nodeset="/data/repeat-a/field-a-1" calculate="position(..)" />
45
- * <!-- body -->
46
- * <repeat nodeset="/data/repeat-a" />
47
- * ```
48
- *
49
- * The field `/data/repeat-a/field-a-1` has a dependency on its containing
50
- * repeat instance. That node also doesn't have a value, and here the dynamic
51
- * aspect of the dependency is the node's current position. Here the node's
52
- * `subscribe` method should react to changes in its position (likely indirectly
53
- * by reading its `contextReference`).
54
- *
55
- * @see {@link EvaluationContext}
56
- * @see {@link EvaluationContext.contextReference}
57
- */
58
- export interface SubscribableDependency {
59
- readonly scope: ReactiveScope;
60
- readonly subscribe: VoidFunction;
61
- }
@@ -1,5 +0,0 @@
1
- import { UnsupportedControl } from '../abstract/UnsupportedControl.ts';
2
-
3
- export class RangeControl extends UnsupportedControl<'range'> {
4
- readonly nodeType = 'range';
5
- }
@@ -1,5 +0,0 @@
1
- import { UnsupportedControl } from '../abstract/UnsupportedControl.ts';
2
-
3
- export class RankControl extends UnsupportedControl<'rank'> {
4
- readonly nodeType = 'rank';
5
- }
@@ -1,168 +0,0 @@
1
- import { UpsertableMap } from '@getodk/common/lib/collections/UpsertableMap.ts';
2
- import type { XFormsXPathEvaluator } from '@getodk/xpath';
3
- import type { Accessor } from 'solid-js';
4
- import { createMemo } from 'solid-js';
5
- import type { TextRange as ClientTextRange } from '../../client/TextRange.ts';
6
- import type { SelectItem } from '../../index.ts';
7
- import type { SelectField } from '../../instance/SelectField.ts';
8
- import type {
9
- EvaluationContext,
10
- EvaluationContextRoot,
11
- } from '../../instance/internal-api/EvaluationContext.ts';
12
- import type { SubscribableDependency } from '../../instance/internal-api/SubscribableDependency.ts';
13
- import { TextChunk } from '../../instance/text/TextChunk.ts';
14
- import { TextRange } from '../../instance/text/TextRange.ts';
15
- import type { ItemDefinition } from '../../parse/body/control/select/ItemDefinition.ts';
16
- import type { ItemsetDefinition } from '../../parse/body/control/select/ItemsetDefinition.ts';
17
- import { createComputedExpression } from './createComputedExpression.ts';
18
- import type { ReactiveScope } from './scope.ts';
19
- import { createTextRange } from './text/createTextRange.ts';
20
-
21
- type DerivedItemLabel = ClientTextRange<'item-label', 'form-derived'>;
22
-
23
- const derivedItemLabel = (context: EvaluationContext, value: string): DerivedItemLabel => {
24
- const chunk = new TextChunk(context.root, 'literal', value);
25
-
26
- return new TextRange('form-derived', 'item-label', [chunk]);
27
- };
28
-
29
- const createSelectItemLabel = (
30
- context: EvaluationContext,
31
- definition: ItemDefinition
32
- ): Accessor<ClientTextRange<'item-label'>> => {
33
- const { label, value } = definition;
34
-
35
- if (label == null) {
36
- return () => derivedItemLabel(context, value);
37
- }
38
-
39
- return createTextRange(context, 'item-label', label);
40
- };
41
-
42
- const createTranslatedStaticSelectItems = (
43
- selectField: SelectField,
44
- items: readonly ItemDefinition[]
45
- ): Accessor<readonly SelectItem[]> => {
46
- return selectField.scope.runTask(() => {
47
- const labeledItems = items.map((item) => {
48
- const { value } = item;
49
- const label = createSelectItemLabel(selectField, item);
50
-
51
- return () => ({
52
- value,
53
- label: label(),
54
- });
55
- });
56
-
57
- return createMemo(() => {
58
- return labeledItems.map((item) => item());
59
- });
60
- });
61
- };
62
-
63
- class ItemsetItemEvaluationContext implements EvaluationContext {
64
- readonly scope: ReactiveScope;
65
- readonly evaluator: XFormsXPathEvaluator;
66
- readonly root: EvaluationContextRoot;
67
- readonly contextReference: Accessor<string>;
68
-
69
- constructor(
70
- private readonly selectField: SelectField,
71
- readonly contextNode: Node
72
- ) {
73
- this.scope = selectField.scope;
74
- this.evaluator = selectField.evaluator;
75
- this.root = selectField.root;
76
- this.contextReference = selectField.contextReference;
77
- }
78
-
79
- getSubscribableDependenciesByReference(reference: string): readonly SubscribableDependency[] {
80
- return this.selectField.getSubscribableDependenciesByReference(reference);
81
- }
82
- }
83
-
84
- const createSelectItemsetItemLabel = (
85
- context: EvaluationContext,
86
- definition: ItemsetDefinition,
87
- itemValue: Accessor<string>
88
- ): Accessor<ClientTextRange<'item-label'>> => {
89
- const { label } = definition;
90
-
91
- if (label == null) {
92
- return createMemo(() => {
93
- return derivedItemLabel(context, itemValue());
94
- });
95
- }
96
-
97
- return createTextRange(context, 'item-label', label);
98
- };
99
-
100
- interface ItemsetItem {
101
- label(): ClientTextRange<'item-label'>;
102
- value(): string;
103
- }
104
-
105
- const createItemsetItems = (
106
- selectField: SelectField,
107
- itemset: ItemsetDefinition
108
- ): Accessor<readonly ItemsetItem[]> => {
109
- return selectField.scope.runTask(() => {
110
- const itemNodes = createComputedExpression(selectField, itemset.nodes);
111
- const itemsCache = new UpsertableMap<Node, ItemsetItem>();
112
-
113
- return createMemo(() => {
114
- return itemNodes().map((itemNode) => {
115
- return itemsCache.upsert(itemNode, () => {
116
- const context = new ItemsetItemEvaluationContext(selectField, itemNode);
117
- const value = createComputedExpression(context, itemset.value);
118
- const label = createSelectItemsetItemLabel(context, itemset, value);
119
-
120
- return {
121
- label,
122
- value,
123
- };
124
- });
125
- });
126
- });
127
- });
128
- };
129
-
130
- const createItemset = (
131
- selectField: SelectField,
132
- itemset: ItemsetDefinition
133
- ): Accessor<readonly SelectItem[]> => {
134
- return selectField.scope.runTask(() => {
135
- const itemsetItems = createItemsetItems(selectField, itemset);
136
-
137
- return createMemo(() => {
138
- return itemsetItems().map((item) => {
139
- return {
140
- label: item.label(),
141
- value: item.value(),
142
- };
143
- });
144
- });
145
- });
146
- };
147
-
148
- /**
149
- * Creates a reactive computation of a {@link SelectField}'s
150
- * {@link SelectItem}s, in support of the field's `valueOptions`.
151
- *
152
- * - Selects defined with static `<item>`s will compute to an corresponding
153
- * static list of items.
154
- * - Selects defined with a computed `<itemset>` will compute to a reactive list
155
- * of items.
156
- * - Items of both will produce {@link SelectItem.label | labels} reactive to
157
- * their appropriate dependencies (whether relative to the itemset item node,
158
- * referencing a form's `itext` translations, etc).
159
- */
160
- export const createSelectItems = (selectField: SelectField): Accessor<readonly SelectItem[]> => {
161
- const { items, itemset } = selectField.definition.bodyElement;
162
-
163
- if (itemset == null) {
164
- return createTranslatedStaticSelectItems(selectField, items);
165
- }
166
-
167
- return createItemset(selectField, itemset);
168
- };
@@ -1,62 +0,0 @@
1
- import type { CollectionValues } from '@getodk/common/types/collections/CollectionValues.ts';
2
-
3
- /**
4
- * Like JavaRosa. Presumably for explicit types which aren't impelemnted?
5
- */
6
- const UNSUPPORTED_DATA_TYPE = 'UNSUPPORTED';
7
-
8
- export type UnsupportedDataType = typeof UNSUPPORTED_DATA_TYPE;
9
-
10
- /**
11
- * Like JavaRosa. Presumably for e.g. groups with explicit binds (`relevant` etc)?
12
- */
13
- export type NullDataType = 'NULL';
14
-
15
- /**
16
- * As in ODK XForms Spec.
17
- *
18
- * TODO: it's unclear why JavaRosa's `DataType` hews closely to the spec, but
19
- * has certain differences (e.g. string -> TEXT, int -> INTEGER). It's also
20
- * not immediately clear how additive types like CHOICE and MULTIPLE_ITEMS
21
- * square with the underlying spec types.
22
- */
23
- export const XFORM_SPEC_DATA_TYPES = [
24
- 'string',
25
- 'int',
26
- 'boolean',
27
- 'decimal',
28
- 'date',
29
- 'time',
30
- 'dateTime',
31
- 'geopoint',
32
- 'geotrace',
33
- 'geoshape',
34
- 'binary',
35
- 'barcode',
36
- 'intent',
37
- ] as const;
38
-
39
- const isSupportedDataType = (bindType: string): bindType is XFormSpecDataType =>
40
- XFORM_SPEC_DATA_TYPES.includes(bindType as XFormSpecDataType);
41
-
42
- export type XFormSpecDataType = CollectionValues<typeof XFORM_SPEC_DATA_TYPES>;
43
-
44
- export type XFormDataType = NullDataType | UnsupportedDataType | XFormSpecDataType;
45
-
46
- const DEFAULT_XFORM_DATA_TYPE = 'string';
47
-
48
- export type DefaultXFormDataType = typeof DEFAULT_XFORM_DATA_TYPE;
49
-
50
- // TODO: groups -> NULL?
51
- // TODO: XSD namespace
52
- export const bindDataType = (bindType: string | null): XFormDataType => {
53
- if (bindType == null) {
54
- return DEFAULT_XFORM_DATA_TYPE;
55
- }
56
-
57
- if (isSupportedDataType(bindType)) {
58
- return bindType;
59
- }
60
-
61
- return UNSUPPORTED_DATA_TYPE;
62
- };
@@ -1,22 +0,0 @@
1
- import type { XFormDefinition } from '../../XFormDefinition.ts';
2
- import {
3
- inputAppearanceParser,
4
- type InputAppearanceDefinition,
5
- } from '../appearance/inputAppearanceParser.ts';
6
- import type { BodyElementParentContext } from '../BodyDefinition.ts';
7
- import { ControlDefinition } from './ControlDefinition.ts';
8
-
9
- export class InputDefinition extends ControlDefinition<'input'> {
10
- static override isCompatible(localName: string): boolean {
11
- return localName === 'input';
12
- }
13
-
14
- readonly type = 'input';
15
- readonly appearances: InputAppearanceDefinition;
16
-
17
- constructor(form: XFormDefinition, parent: BodyElementParentContext, element: Element) {
18
- super(form, parent, element);
19
-
20
- this.appearances = inputAppearanceParser.parseFrom(element, 'appearance');
21
- }
22
- }