@getodk/xforms-engine 0.1.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 (208) hide show
  1. package/README.md +44 -0
  2. package/dist/.vite/manifest.json +7 -0
  3. package/dist/XFormDOM.d.ts +31 -0
  4. package/dist/XFormDataType.d.ts +26 -0
  5. package/dist/XFormDefinition.d.ts +14 -0
  6. package/dist/body/BodyDefinition.d.ts +52 -0
  7. package/dist/body/BodyElementDefinition.d.ts +32 -0
  8. package/dist/body/RepeatDefinition.d.ts +15 -0
  9. package/dist/body/UnsupportedBodyElementDefinition.d.ts +10 -0
  10. package/dist/body/control/ControlDefinition.d.ts +16 -0
  11. package/dist/body/control/InputDefinition.d.ts +5 -0
  12. package/dist/body/control/select/ItemDefinition.d.ts +13 -0
  13. package/dist/body/control/select/ItemsetDefinition.d.ts +16 -0
  14. package/dist/body/control/select/ItemsetNodesetContext.d.ts +11 -0
  15. package/dist/body/control/select/ItemsetNodesetExpression.d.ts +5 -0
  16. package/dist/body/control/select/ItemsetValueExpression.d.ts +6 -0
  17. package/dist/body/control/select/SelectDefinition.d.ts +23 -0
  18. package/dist/body/group/BaseGroupDefinition.d.ts +46 -0
  19. package/dist/body/group/LogicalGroupDefinition.d.ts +6 -0
  20. package/dist/body/group/PresentationGroupDefinition.d.ts +11 -0
  21. package/dist/body/group/RepeatGroupDefinition.d.ts +12 -0
  22. package/dist/body/group/StructuralGroupDefinition.d.ts +6 -0
  23. package/dist/body/text/HintDefinition.d.ts +11 -0
  24. package/dist/body/text/LabelDefinition.d.ts +20 -0
  25. package/dist/body/text/TextElementDefinition.d.ts +32 -0
  26. package/dist/body/text/TextElementOutputPart.d.ts +12 -0
  27. package/dist/body/text/TextElementPart.d.ts +12 -0
  28. package/dist/body/text/TextElementReferencePart.d.ts +6 -0
  29. package/dist/body/text/TextElementStaticPart.d.ts +6 -0
  30. package/dist/client/BaseNode.d.ts +138 -0
  31. package/dist/client/EngineConfig.d.ts +78 -0
  32. package/dist/client/FormLanguage.d.ts +63 -0
  33. package/dist/client/GroupNode.d.ts +24 -0
  34. package/dist/client/OpaqueReactiveObjectFactory.d.ts +70 -0
  35. package/dist/client/RepeatInstanceNode.d.ts +28 -0
  36. package/dist/client/RepeatRangeNode.d.ts +94 -0
  37. package/dist/client/RootNode.d.ts +31 -0
  38. package/dist/client/SelectNode.d.ts +60 -0
  39. package/dist/client/StringNode.d.ts +41 -0
  40. package/dist/client/SubtreeNode.d.ts +52 -0
  41. package/dist/client/TextRange.d.ts +55 -0
  42. package/dist/client/hierarchy.d.ts +48 -0
  43. package/dist/client/index.d.ts +11 -0
  44. package/dist/client/node-types.d.ts +1 -0
  45. package/dist/expression/DependencyContext.d.ts +12 -0
  46. package/dist/expression/DependentExpression.d.ts +43 -0
  47. package/dist/index.d.ts +16 -0
  48. package/dist/index.js +37622 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/instance/Group.d.ts +31 -0
  51. package/dist/instance/RepeatInstance.d.ts +60 -0
  52. package/dist/instance/RepeatRange.d.ts +81 -0
  53. package/dist/instance/Root.d.ts +70 -0
  54. package/dist/instance/SelectField.d.ts +45 -0
  55. package/dist/instance/StringField.d.ts +39 -0
  56. package/dist/instance/Subtree.d.ts +30 -0
  57. package/dist/instance/abstract/DescendantNode.d.ts +76 -0
  58. package/dist/instance/abstract/InstanceNode.d.ts +107 -0
  59. package/dist/instance/children.d.ts +2 -0
  60. package/dist/instance/hierarchy.d.ts +12 -0
  61. package/dist/instance/identity.d.ts +7 -0
  62. package/dist/instance/index.d.ts +8 -0
  63. package/dist/instance/internal-api/EvaluationContext.d.ts +34 -0
  64. package/dist/instance/internal-api/InstanceConfig.d.ts +8 -0
  65. package/dist/instance/internal-api/SubscribableDependency.d.ts +59 -0
  66. package/dist/instance/internal-api/TranslationContext.d.ts +4 -0
  67. package/dist/instance/internal-api/ValueContext.d.ts +22 -0
  68. package/dist/instance/resource.d.ts +10 -0
  69. package/dist/instance/text/FormattedTextStub.d.ts +1 -0
  70. package/dist/instance/text/TextChunk.d.ts +11 -0
  71. package/dist/instance/text/TextRange.d.ts +10 -0
  72. package/dist/lib/dom/query.d.ts +20 -0
  73. package/dist/lib/reactivity/createChildrenState.d.ts +36 -0
  74. package/dist/lib/reactivity/createComputedExpression.d.ts +12 -0
  75. package/dist/lib/reactivity/createSelectItems.d.ts +16 -0
  76. package/dist/lib/reactivity/createValueState.d.ts +44 -0
  77. package/dist/lib/reactivity/materializeCurrentStateChildren.d.ts +18 -0
  78. package/dist/lib/reactivity/node-state/createClientState.d.ts +9 -0
  79. package/dist/lib/reactivity/node-state/createCurrentState.d.ts +6 -0
  80. package/dist/lib/reactivity/node-state/createEngineState.d.ts +5 -0
  81. package/dist/lib/reactivity/node-state/createSharedNodeState.d.ts +22 -0
  82. package/dist/lib/reactivity/node-state/createSpecifiedPropertyDescriptor.d.ts +6 -0
  83. package/dist/lib/reactivity/node-state/createSpecifiedState.d.ts +139 -0
  84. package/dist/lib/reactivity/node-state/representations.d.ts +25 -0
  85. package/dist/lib/reactivity/scope.d.ts +23 -0
  86. package/dist/lib/reactivity/text/createFieldHint.d.ts +5 -0
  87. package/dist/lib/reactivity/text/createNodeLabel.d.ts +5 -0
  88. package/dist/lib/reactivity/text/createTextRange.d.ts +19 -0
  89. package/dist/lib/reactivity/types.d.ts +21 -0
  90. package/dist/lib/unique-id.d.ts +27 -0
  91. package/dist/lib/xpath/analysis.d.ts +22 -0
  92. package/dist/model/BindComputation.d.ts +30 -0
  93. package/dist/model/BindDefinition.d.ts +31 -0
  94. package/dist/model/BindElement.d.ts +6 -0
  95. package/dist/model/DescendentNodeDefinition.d.ts +25 -0
  96. package/dist/model/ModelBindMap.d.ts +15 -0
  97. package/dist/model/ModelDefinition.d.ts +10 -0
  98. package/dist/model/NodeDefinition.d.ts +74 -0
  99. package/dist/model/RepeatInstanceDefinition.d.ts +15 -0
  100. package/dist/model/RepeatSequenceDefinition.d.ts +19 -0
  101. package/dist/model/RepeatTemplateDefinition.d.ts +29 -0
  102. package/dist/model/RootDefinition.d.ts +24 -0
  103. package/dist/model/SubtreeDefinition.d.ts +14 -0
  104. package/dist/model/ValueNodeDefinition.d.ts +15 -0
  105. package/dist/solid.js +37273 -0
  106. package/dist/solid.js.map +1 -0
  107. package/package.json +87 -0
  108. package/src/XFormDOM.ts +224 -0
  109. package/src/XFormDataType.ts +64 -0
  110. package/src/XFormDefinition.ts +40 -0
  111. package/src/body/BodyDefinition.ts +202 -0
  112. package/src/body/BodyElementDefinition.ts +62 -0
  113. package/src/body/RepeatDefinition.ts +54 -0
  114. package/src/body/UnsupportedBodyElementDefinition.ts +17 -0
  115. package/src/body/control/ControlDefinition.ts +42 -0
  116. package/src/body/control/InputDefinition.ts +9 -0
  117. package/src/body/control/select/ItemDefinition.ts +31 -0
  118. package/src/body/control/select/ItemsetDefinition.ts +36 -0
  119. package/src/body/control/select/ItemsetNodesetContext.ts +26 -0
  120. package/src/body/control/select/ItemsetNodesetExpression.ts +8 -0
  121. package/src/body/control/select/ItemsetValueExpression.ts +11 -0
  122. package/src/body/control/select/SelectDefinition.ts +74 -0
  123. package/src/body/group/BaseGroupDefinition.ts +137 -0
  124. package/src/body/group/LogicalGroupDefinition.ts +11 -0
  125. package/src/body/group/PresentationGroupDefinition.ts +28 -0
  126. package/src/body/group/RepeatGroupDefinition.ts +91 -0
  127. package/src/body/group/StructuralGroupDefinition.ts +11 -0
  128. package/src/body/text/HintDefinition.ts +26 -0
  129. package/src/body/text/LabelDefinition.ts +54 -0
  130. package/src/body/text/TextElementDefinition.ts +97 -0
  131. package/src/body/text/TextElementOutputPart.ts +27 -0
  132. package/src/body/text/TextElementPart.ts +31 -0
  133. package/src/body/text/TextElementReferencePart.ts +21 -0
  134. package/src/body/text/TextElementStaticPart.ts +26 -0
  135. package/src/client/BaseNode.ts +180 -0
  136. package/src/client/EngineConfig.ts +83 -0
  137. package/src/client/FormLanguage.ts +77 -0
  138. package/src/client/GroupNode.ts +33 -0
  139. package/src/client/OpaqueReactiveObjectFactory.ts +100 -0
  140. package/src/client/README.md +39 -0
  141. package/src/client/RepeatInstanceNode.ts +41 -0
  142. package/src/client/RepeatRangeNode.ts +100 -0
  143. package/src/client/RootNode.ts +36 -0
  144. package/src/client/SelectNode.ts +69 -0
  145. package/src/client/StringNode.ts +46 -0
  146. package/src/client/SubtreeNode.ts +57 -0
  147. package/src/client/TextRange.ts +63 -0
  148. package/src/client/hierarchy.ts +63 -0
  149. package/src/client/index.ts +29 -0
  150. package/src/client/node-types.ts +10 -0
  151. package/src/expression/DependencyContext.ts +53 -0
  152. package/src/expression/DependentExpression.ts +102 -0
  153. package/src/index.ts +35 -0
  154. package/src/instance/Group.ts +82 -0
  155. package/src/instance/RepeatInstance.ts +164 -0
  156. package/src/instance/RepeatRange.ts +214 -0
  157. package/src/instance/Root.ts +264 -0
  158. package/src/instance/SelectField.ts +204 -0
  159. package/src/instance/StringField.ts +93 -0
  160. package/src/instance/Subtree.ts +79 -0
  161. package/src/instance/abstract/DescendantNode.ts +182 -0
  162. package/src/instance/abstract/InstanceNode.ts +257 -0
  163. package/src/instance/children.ts +52 -0
  164. package/src/instance/hierarchy.ts +54 -0
  165. package/src/instance/identity.ts +11 -0
  166. package/src/instance/index.ts +37 -0
  167. package/src/instance/internal-api/EvaluationContext.ts +41 -0
  168. package/src/instance/internal-api/InstanceConfig.ts +9 -0
  169. package/src/instance/internal-api/SubscribableDependency.ts +61 -0
  170. package/src/instance/internal-api/TranslationContext.ts +5 -0
  171. package/src/instance/internal-api/ValueContext.ts +27 -0
  172. package/src/instance/resource.ts +75 -0
  173. package/src/instance/text/FormattedTextStub.ts +8 -0
  174. package/src/instance/text/TextChunk.ts +20 -0
  175. package/src/instance/text/TextRange.ts +23 -0
  176. package/src/lib/dom/query.ts +49 -0
  177. package/src/lib/reactivity/createChildrenState.ts +60 -0
  178. package/src/lib/reactivity/createComputedExpression.ts +114 -0
  179. package/src/lib/reactivity/createSelectItems.ts +163 -0
  180. package/src/lib/reactivity/createValueState.ts +258 -0
  181. package/src/lib/reactivity/materializeCurrentStateChildren.ts +121 -0
  182. package/src/lib/reactivity/node-state/createClientState.ts +51 -0
  183. package/src/lib/reactivity/node-state/createCurrentState.ts +27 -0
  184. package/src/lib/reactivity/node-state/createEngineState.ts +18 -0
  185. package/src/lib/reactivity/node-state/createSharedNodeState.ts +79 -0
  186. package/src/lib/reactivity/node-state/createSpecifiedPropertyDescriptor.ts +85 -0
  187. package/src/lib/reactivity/node-state/createSpecifiedState.ts +229 -0
  188. package/src/lib/reactivity/node-state/representations.ts +64 -0
  189. package/src/lib/reactivity/scope.ts +106 -0
  190. package/src/lib/reactivity/text/createFieldHint.ts +16 -0
  191. package/src/lib/reactivity/text/createNodeLabel.ts +16 -0
  192. package/src/lib/reactivity/text/createTextRange.ts +155 -0
  193. package/src/lib/reactivity/types.ts +27 -0
  194. package/src/lib/unique-id.ts +34 -0
  195. package/src/lib/xpath/analysis.ts +241 -0
  196. package/src/model/BindComputation.ts +88 -0
  197. package/src/model/BindDefinition.ts +104 -0
  198. package/src/model/BindElement.ts +8 -0
  199. package/src/model/DescendentNodeDefinition.ts +56 -0
  200. package/src/model/ModelBindMap.ts +71 -0
  201. package/src/model/ModelDefinition.ts +19 -0
  202. package/src/model/NodeDefinition.ts +146 -0
  203. package/src/model/RepeatInstanceDefinition.ts +39 -0
  204. package/src/model/RepeatSequenceDefinition.ts +53 -0
  205. package/src/model/RepeatTemplateDefinition.ts +150 -0
  206. package/src/model/RootDefinition.ts +121 -0
  207. package/src/model/SubtreeDefinition.ts +50 -0
  208. package/src/model/ValueNodeDefinition.ts +39 -0
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # @getodk/xforms-engine
2
+
3
+ Implementation of the [ODK XForms specification](https://getodk.github.io/xforms-spec/)'s data model and computation logic. This package does not handle presentation or user interaction. Those aspects of forms are meant to be handled by a client. Presently, those clients are:
4
+
5
+ - [`@getodk/web-forms`](../web-forms)
6
+ - [`@getodk/ui-solid`](../ui-solid)
7
+
8
+ ## Install
9
+
10
+ Install with `npm` (or the equivalent command for your preferred package manager):
11
+
12
+ ```sh
13
+ npm install @getodk/xforms-engine
14
+ ```
15
+
16
+ ## Development
17
+
18
+ > [!NOTE]
19
+ > All commands should be run from the root of the monorepo, not this package's subdirectory.
20
+
21
+ Test commands:
22
+
23
+ ```sh
24
+ # Single run
25
+ yarn workspace @getodk/xforms-engine test-node:jsdom
26
+ yarn workspace @getodk/xforms-engine test-browser:chromium
27
+ yarn workspace @getodk/xforms-engine test-browser:firefox
28
+ yarn workspace @getodk/xforms-engine test-browser:webkit
29
+
30
+ # Watch mode (convenient during development)
31
+ yarn workspace @getodk/xforms-engine test-watch:jsdom
32
+ yarn workspace @getodk/xforms-engine test-watch:chromium
33
+ yarn workspace @getodk/xforms-engine test-watch:firefox
34
+ yarn workspace @getodk/xforms-engine test-watch:webkit
35
+ ```
36
+
37
+ ## Supported/tested environments
38
+
39
+ - Browsers (latest versions):
40
+ - Chrome/Chromium-based browsers (tested only in Chromium)
41
+ - Firefox
42
+ - Safari/WebKit (tested in WebKit directly)
43
+ - Non-browser runtimes with a DOM compatibility environement:
44
+ - Node (current/LTS; tested with [jsdom](https://github.com/jsdom/jsdom)). Server-side rendering of forms is not presently supported or targeted beyond testing, though it may be considered in the future. Inclusion of Node in the automated test suites helps us to keep this option open.
@@ -0,0 +1,7 @@
1
+ {
2
+ "src/index.ts": {
3
+ "file": "solid.js",
4
+ "src": "src/index.ts",
5
+ "isEntry": true
6
+ }
7
+ }
@@ -0,0 +1,31 @@
1
+ import { XFormsXPathEvaluator } from '@getodk/xpath';
2
+ interface XFormDOMNormalizationOptions {
3
+ readonly isNormalized: boolean;
4
+ }
5
+ export declare class XFormDOM {
6
+ protected readonly sourceXML: string;
7
+ static from(sourceXML: string): XFormDOM;
8
+ protected readonly normalizedXML: string;
9
+ readonly rootEvaluator: XFormsXPathEvaluator;
10
+ readonly primaryInstanceEvaluator: XFormsXPathEvaluator;
11
+ readonly xformDocument: XMLDocument;
12
+ readonly html: Element;
13
+ readonly head: Element;
14
+ readonly title: Element;
15
+ readonly model: Element;
16
+ readonly primaryInstance: Element;
17
+ readonly primaryInstanceRoot: Element;
18
+ readonly body: Element;
19
+ protected constructor(sourceXML: string, options: XFormDOMNormalizationOptions);
20
+ createInstance(): XFormDOM;
21
+ toJSON(): Omit<this, "xformDocument" | "html" | "rootEvaluator" | "primaryInstanceEvaluator" | "head" | "title" | "model" | "primaryInstance" | "primaryInstanceRoot" | "createInstance" | "toJSON"> & {
22
+ xformDocument: string;
23
+ html: string;
24
+ head: string;
25
+ title: string;
26
+ model: string;
27
+ primaryInstance: string;
28
+ primaryInstanceRoot: string;
29
+ };
30
+ }
31
+ export {};
@@ -0,0 +1,26 @@
1
+ import type { CollectionValues } from '../../common/types/collections/CollectionValues.ts';
2
+ /**
3
+ * Like JavaRosa. Presumably for explicit types which aren't impelemnted?
4
+ */
5
+ declare const UNSUPPORTED_DATA_TYPE = "UNSUPPORTED";
6
+ export type UnsupportedDataType = typeof UNSUPPORTED_DATA_TYPE;
7
+ /**
8
+ * Like JavaRosa. Presumably for e.g. groups with explicit binds (`relevant` etc)?
9
+ */
10
+ declare const NULL_DATA_TYPE = "NULL";
11
+ export type NullDataType = typeof NULL_DATA_TYPE;
12
+ /**
13
+ * As in ODK XForms Spec.
14
+ *
15
+ * TODO: it's unclear why JavaRosa's `DataType` hews closely to the spec, but
16
+ * has certain differences (e.g. string -> TEXT, int -> INTEGER). It's also
17
+ * not immediately clear how additive types like CHOICE and MULTIPLE_ITEMS
18
+ * square with the underlying spec types.
19
+ */
20
+ export declare const XFORM_SPEC_DATA_TYPES: readonly ["string", "int", "boolean", "decimal", "date", "time", "dateTime", "geopoint", "geotrace", "geoshape", "binary", "barcode", "intent"];
21
+ export type XFormSpecDataType = CollectionValues<typeof XFORM_SPEC_DATA_TYPES>;
22
+ export type XFormDataType = NullDataType | UnsupportedDataType | XFormSpecDataType;
23
+ declare const DEFAULT_XFORM_DATA_TYPE = "string";
24
+ export type DefaultXFormDataType = typeof DEFAULT_XFORM_DATA_TYPE;
25
+ export declare const bindDataType: (bindType: string | null) => XFormDataType;
26
+ export {};
@@ -0,0 +1,14 @@
1
+ import { XFormDOM } from './XFormDOM.ts';
2
+ import { BodyDefinition } from './body/BodyDefinition.ts';
3
+ import { ModelDefinition } from './model/ModelDefinition.ts';
4
+ export declare class XFormDefinition {
5
+ readonly sourceXML: string;
6
+ readonly xformDOM: XFormDOM;
7
+ readonly xformDocument: XMLDocument;
8
+ readonly id: string;
9
+ readonly title: string;
10
+ readonly rootReference: string;
11
+ readonly body: BodyDefinition;
12
+ readonly model: ModelDefinition;
13
+ constructor(sourceXML: string);
14
+ }
@@ -0,0 +1,52 @@
1
+ import type { XFormDefinition } from '../XFormDefinition.ts';
2
+ import { DependencyContext } from '../expression/DependencyContext.ts';
3
+ import { UnsupportedBodyElementDefinition } from './UnsupportedBodyElementDefinition.ts';
4
+ import { InputDefinition } from './control/InputDefinition.ts';
5
+ import type { AnySelectDefinition } from './control/select/SelectDefinition.ts';
6
+ import { LogicalGroupDefinition } from './group/LogicalGroupDefinition.ts';
7
+ import { PresentationGroupDefinition } from './group/PresentationGroupDefinition.ts';
8
+ import { RepeatGroupDefinition } from './group/RepeatGroupDefinition.ts';
9
+ import { StructuralGroupDefinition } from './group/StructuralGroupDefinition.ts';
10
+ export interface BodyElementParentContext {
11
+ readonly reference: string | null;
12
+ readonly element: Element;
13
+ }
14
+ type SupportedBodyElementDefinition = RepeatGroupDefinition | LogicalGroupDefinition | PresentationGroupDefinition | StructuralGroupDefinition | InputDefinition | AnySelectDefinition;
15
+ export type AnyBodyElementDefinition = SupportedBodyElementDefinition | UnsupportedBodyElementDefinition;
16
+ export type BodyElementDefinitionArray = readonly AnyBodyElementDefinition[];
17
+ export type AnyBodyElementType = AnyBodyElementDefinition['type'];
18
+ export type AnyGroupElementDefinition = Extract<AnyBodyElementDefinition, {
19
+ readonly type: `${string}-group`;
20
+ }>;
21
+ export type NonRepeatGroupElementDefinition = Exclude<AnyGroupElementDefinition, {
22
+ readonly type: 'repeat-group';
23
+ }>;
24
+ export declare const groupElementDefinition: (element: AnyBodyElementDefinition) => AnyGroupElementDefinition | null;
25
+ export type AnyControlElementDefinition = Extract<AnyBodyElementDefinition, {
26
+ readonly category: 'control';
27
+ }>;
28
+ export declare const controlElementDefinition: (element: AnyBodyElementDefinition) => AnyControlElementDefinition | null;
29
+ type BodyElementReference = string;
30
+ declare class BodyElementMap extends Map<BodyElementReference, AnyBodyElementDefinition> {
31
+ constructor(elements: BodyElementDefinitionArray);
32
+ protected mapElementsByReference(elements: BodyElementDefinitionArray): void;
33
+ set(reference: BodyElementReference, element: AnyBodyElementDefinition): this;
34
+ getBodyElementType(reference: BodyElementReference): AnyBodyElementType | null;
35
+ toJSON(): {
36
+ [k: string]: AnyBodyElementDefinition;
37
+ };
38
+ }
39
+ export declare class BodyDefinition extends DependencyContext {
40
+ protected readonly form: XFormDefinition;
41
+ static getChildElementDefinitions(form: XFormDefinition, parent: BodyElementParentContext, parentElement: Element, children?: readonly Element[]): readonly AnyBodyElementDefinition[];
42
+ readonly element: Element;
43
+ readonly elements: readonly AnyBodyElementDefinition[];
44
+ protected readonly elementsByReference: BodyElementMap;
45
+ readonly parentReference: null;
46
+ readonly reference: string;
47
+ constructor(form: XFormDefinition);
48
+ getBodyElement(reference: string): AnyBodyElementDefinition | null;
49
+ getRepeatGroup(reference: string): RepeatGroupDefinition | null;
50
+ toJSON(): Omit<this, "toJSON" | "form" | "isTranslated" | "registerDependentExpression" | "dependencyExpressions" | "getBodyElement" | "getRepeatGroup">;
51
+ }
52
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { XFormDefinition } from '../XFormDefinition.ts';
2
+ import { DependencyContext } from '../expression/DependencyContext.ts';
3
+ import type { BodyElementParentContext } from './BodyDefinition.ts';
4
+ import type { HintDefinition } from './text/HintDefinition.ts';
5
+ import type { LabelDefinition } from './text/LabelDefinition.ts';
6
+ /**
7
+ * These category names roughly correspond to each of the ODK XForms spec's
8
+ * {@link https://getodk.github.io/xforms-spec/#body-elements | Body Elements}
9
+ * tables.
10
+ */
11
+ type BodyElementCategory = 'control' | 'structure' | 'support' | 'UNSUPPORTED';
12
+ export declare abstract class BodyElementDefinition<Type extends string> extends DependencyContext {
13
+ protected readonly form: XFormDefinition;
14
+ readonly parent: BodyElementParentContext;
15
+ readonly element: Element;
16
+ static isCompatible(localName: string, element: Element): boolean;
17
+ abstract readonly category: BodyElementCategory;
18
+ abstract readonly type: Type;
19
+ readonly hint: HintDefinition | null;
20
+ readonly label: LabelDefinition | null;
21
+ readonly reference: string | null;
22
+ readonly parentReference: string | null;
23
+ protected constructor(form: XFormDefinition, parent: BodyElementParentContext, element: Element);
24
+ toJSON(): object;
25
+ }
26
+ type BodyElementDefinitionClass = Pick<typeof BodyElementDefinition, keyof typeof BodyElementDefinition>;
27
+ export type BodyElementDefinitionConstructor = BodyElementDefinitionClass & (new (form: XFormDefinition, element: Element) => BodyElementDefinition<any>);
28
+ type BodyElementDefinitionInstance = InstanceType<BodyElementDefinitionConstructor>;
29
+ export type TypedBodyElementDefinition<Type extends string> = Extract<BodyElementDefinitionInstance, {
30
+ readonly type: Type;
31
+ }>;
32
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { XFormDefinition } from '../XFormDefinition.ts';
2
+ import type { BodyElementDefinitionArray } from './BodyDefinition.ts';
3
+ import { BodyElementDefinition } from './BodyElementDefinition.ts';
4
+ import type { RepeatGroupDefinition } from './group/RepeatGroupDefinition.ts';
5
+ export declare class RepeatDefinition extends BodyElementDefinition<'repeat'> {
6
+ readonly groupDefinition: RepeatGroupDefinition;
7
+ readonly category = "structure";
8
+ readonly type = "repeat";
9
+ readonly reference: string;
10
+ readonly countExpression: string | null;
11
+ readonly isFixedCount: boolean;
12
+ readonly children: BodyElementDefinitionArray;
13
+ constructor(form: XFormDefinition, groupDefinition: RepeatGroupDefinition, element: Element);
14
+ toJSON(): Omit<this, "toJSON" | "form" | "parent" | "isTranslated" | "registerDependentExpression" | "dependencyExpressions" | "groupDefinition">;
15
+ }
@@ -0,0 +1,10 @@
1
+ import type { XFormDefinition } from '../XFormDefinition.ts';
2
+ import type { BodyElementParentContext } from './BodyDefinition.ts';
3
+ import { BodyElementDefinition } from './BodyElementDefinition.ts';
4
+ export declare class UnsupportedBodyElementDefinition extends BodyElementDefinition<'UNSUPPORTED'> {
5
+ static isCompatible(): boolean;
6
+ readonly category = "UNSUPPORTED";
7
+ readonly type = "UNSUPPORTED";
8
+ readonly reference: null;
9
+ constructor(form: XFormDefinition, parent: BodyElementParentContext, element: Element);
10
+ }
@@ -0,0 +1,16 @@
1
+ import type { XFormDefinition } from '../../XFormDefinition.ts';
2
+ import type { BodyElementParentContext } from '../BodyDefinition.ts';
3
+ import { BodyElementDefinition } from '../BodyElementDefinition.ts';
4
+ import { HintDefinition } from '../text/HintDefinition.ts';
5
+ import { LabelDefinition } from '../text/LabelDefinition.ts';
6
+ type ControlType = 'input' | 'range' | 'rank' | 'select' | 'select1' | 'trigger' | 'upload';
7
+ export declare abstract class ControlDefinition<Type extends ControlType> extends BodyElementDefinition<Type> {
8
+ readonly category = "control";
9
+ abstract readonly type: Type;
10
+ readonly reference: string;
11
+ readonly label: LabelDefinition | null;
12
+ readonly hint: HintDefinition | null;
13
+ constructor(form: XFormDefinition, parent: BodyElementParentContext, element: Element);
14
+ }
15
+ export type AnyControlDefinition = ControlDefinition<any>;
16
+ export {};
@@ -0,0 +1,5 @@
1
+ import { ControlDefinition } from './ControlDefinition.ts';
2
+ export declare class InputDefinition extends ControlDefinition<'input'> {
3
+ static isCompatible(localName: string): boolean;
4
+ readonly type = "input";
5
+ }
@@ -0,0 +1,13 @@
1
+ import { type ItemElement } from '../../../lib/dom/query.ts';
2
+ import type { XFormDefinition } from '../../../XFormDefinition.ts';
3
+ import { BodyElementDefinition } from '../../BodyElementDefinition.ts';
4
+ import { LabelDefinition } from '../../text/LabelDefinition.ts';
5
+ import type { AnySelectDefinition } from './SelectDefinition.ts';
6
+ export declare class ItemDefinition extends BodyElementDefinition<'item'> {
7
+ readonly parent: AnySelectDefinition;
8
+ readonly category = "support";
9
+ readonly type = "item";
10
+ readonly label: LabelDefinition | null;
11
+ readonly value: string;
12
+ constructor(form: XFormDefinition, parent: AnySelectDefinition, element: ItemElement);
13
+ }
@@ -0,0 +1,16 @@
1
+ import { type ItemsetElement } from '../../../lib/dom/query.ts';
2
+ import type { XFormDefinition } from '../../../XFormDefinition.ts';
3
+ import { BodyElementDefinition } from '../../BodyElementDefinition.ts';
4
+ import { LabelDefinition } from '../../text/LabelDefinition.ts';
5
+ import { ItemsetNodesetExpression } from './ItemsetNodesetExpression.ts';
6
+ import { ItemsetValueExpression } from './ItemsetValueExpression.ts';
7
+ import type { AnySelectDefinition } from './SelectDefinition.ts';
8
+ export declare class ItemsetDefinition extends BodyElementDefinition<'itemset'> {
9
+ readonly category = "support";
10
+ readonly type = "itemset";
11
+ readonly reference: string;
12
+ readonly label: LabelDefinition | null;
13
+ readonly nodes: ItemsetNodesetExpression;
14
+ readonly value: ItemsetValueExpression;
15
+ constructor(form: XFormDefinition, select: AnySelectDefinition, element: ItemsetElement);
16
+ }
@@ -0,0 +1,11 @@
1
+ import { DependencyContext } from '../../../expression/DependencyContext.ts';
2
+ import type { AnyDependentExpression } from '../../../expression/DependentExpression.ts';
3
+ import type { ItemsetDefinition } from './ItemsetDefinition.ts';
4
+ export declare class ItemsetNodesetContext extends DependencyContext {
5
+ protected readonly itemset: ItemsetDefinition;
6
+ readonly parentReference: null;
7
+ readonly reference: string;
8
+ constructor(itemset: ItemsetDefinition, nodesetExpression: string);
9
+ set isTranslated(value: true);
10
+ registerDependentExpression(expression: AnyDependentExpression): void;
11
+ }
@@ -0,0 +1,5 @@
1
+ import { DependentExpression } from '../../../expression/DependentExpression.ts';
2
+ import type { ItemsetDefinition } from './ItemsetDefinition.ts';
3
+ export declare class ItemsetNodesetExpression extends DependentExpression<'nodes'> {
4
+ constructor(itemset: ItemsetDefinition, nodesetExpression: string);
5
+ }
@@ -0,0 +1,6 @@
1
+ import { DependentExpression } from '../../../expression/DependentExpression.ts';
2
+ import type { ItemsetDefinition } from './ItemsetDefinition.ts';
3
+ export declare class ItemsetValueExpression extends DependentExpression<'string'> {
4
+ readonly itemset: ItemsetDefinition;
5
+ constructor(itemset: ItemsetDefinition, expression: string);
6
+ }
@@ -0,0 +1,23 @@
1
+ import type { CollectionValues } from '../../../../../common/types/collections/CollectionValues.ts';
2
+ import type { LocalNamedElement } from '../../../../../common/types/dom.ts';
3
+ import type { XFormDefinition } from '../../../XFormDefinition.ts';
4
+ import type { AnyBodyElementDefinition, BodyElementParentContext } from '../../BodyDefinition.ts';
5
+ import { ControlDefinition } from '../ControlDefinition.ts';
6
+ import { ItemDefinition } from './ItemDefinition.ts';
7
+ import { ItemsetDefinition } from './ItemsetDefinition.ts';
8
+ declare const selectLocalNames: Set<"select" | "rank" | "select1">;
9
+ export type SelectType = CollectionValues<typeof selectLocalNames>;
10
+ export interface SelectElement extends LocalNamedElement<SelectType> {
11
+ }
12
+ export declare class SelectDefinition<Type extends SelectType> extends ControlDefinition<Type> {
13
+ static isCompatible(localName: string, element: Element): boolean;
14
+ static isSelect(element: AnyBodyElementDefinition): element is AnySelectDefinition;
15
+ readonly type: Type;
16
+ readonly element: SelectElement;
17
+ readonly itemset: ItemsetDefinition | null;
18
+ readonly items: readonly ItemDefinition[];
19
+ constructor(form: XFormDefinition, parent: BodyElementParentContext, element: Element);
20
+ toJSON(): {};
21
+ }
22
+ export type AnySelectDefinition = SelectDefinition<SelectType>;
23
+ export {};
@@ -0,0 +1,46 @@
1
+ import type { XFormDefinition } from '../../XFormDefinition.ts';
2
+ import { type BodyElementDefinitionArray, type BodyElementParentContext } from '../BodyDefinition.ts';
3
+ import { BodyElementDefinition } from '../BodyElementDefinition.ts';
4
+ import { LabelDefinition } from '../text/LabelDefinition.ts';
5
+ /**
6
+ * These type names are derived from **and expand upon** the language used in
7
+ * the ODK XForms spec to describe various group usage. Whereas the spec
8
+ * language allows for a group to be described as more than one case, the intent
9
+ * here is to establish exclusive naming which may or may not compound. As such:
10
+ *
11
+ * - `logical-group`, per spec language, is a group with a `ref`; its usage here
12
+ * differs from the spec language in that it _may_ have a `<label>` child but
13
+ * is not also treated as a `presentation-group` (which is only used for
14
+ * groups which do not have a `ref`)
15
+ * - `presentation-group` is a group with a `<label>` child; its usage here
16
+ * differs from the spec language in that `presentation-group` does **not**
17
+ * have a `ref`
18
+ * - `repeat-group` is not mentioned by the spec; it is an extension of
19
+ * `logical-group`, wherein its `ref` is the same as its immediate `<repeat>`
20
+ * child's `nodeset` (usage of each attribute is normalized during
21
+ * initialization, in {@link XFormDOM})
22
+ * - `structural-group` is any `<group>` element which does not satisfy any of
23
+ * the other usage scenarios; this isn't exactly the terminology used, but is
24
+ * the most closely fitting name for the concept where the other sceanarios
25
+ * do not apply
26
+ *
27
+ * A more succinct decision tree:
28
+ *
29
+ * - `<group ref="$ref"><repeat nodeset="$ref">` -> `repeat-group`, else
30
+ * - `<group ref="$ref">` -> `logical-group`, else
31
+ * - `<group><label>` -> `presentation-group`, else
32
+ * - `<group>` -> `structural-group`
33
+ */
34
+ export type GroupType = 'logical-group' | 'presentation-group' | 'repeat-group' | 'structural-group';
35
+ export declare abstract class BaseGroupDefinition<Type extends GroupType> extends BodyElementDefinition<Type> {
36
+ private static groupTypes;
37
+ protected static getGroupType(localName: string, element: Element): GroupType | null;
38
+ readonly category = "structure";
39
+ readonly children: BodyElementDefinitionArray;
40
+ readonly reference: string | null;
41
+ readonly label: LabelDefinition | null;
42
+ constructor(form: XFormDefinition, parent: BodyElementParentContext, element: Element, children?: BodyElementDefinitionArray);
43
+ getChildren(element: Element): BodyElementDefinitionArray;
44
+ }
45
+ export declare const repeatGroup: <T extends BaseGroupDefinition<any>>(groupDefinition: T) => Extract<T, BaseGroupDefinition<"repeat-group">> | null;
46
+ export declare const nonRepeatGroup: <T extends BaseGroupDefinition<any>>(groupDefinition: T) => Exclude<T, BaseGroupDefinition<"repeat-group">> | null;
@@ -0,0 +1,6 @@
1
+ import { BaseGroupDefinition } from './BaseGroupDefinition.ts';
2
+ export declare class LogicalGroupDefinition extends BaseGroupDefinition<'logical-group'> {
3
+ static isCompatible(localName: string, element: Element): boolean;
4
+ readonly type = "logical-group";
5
+ }
6
+ export type LogicalGroupDefinitionClass = typeof LogicalGroupDefinition;
@@ -0,0 +1,11 @@
1
+ import type { XFormDefinition } from '../../XFormDefinition.ts';
2
+ import type { BodyElementParentContext } from '../BodyDefinition.ts';
3
+ import { LabelDefinition } from '../text/LabelDefinition.ts';
4
+ import { BaseGroupDefinition } from './BaseGroupDefinition.ts';
5
+ export declare class PresentationGroupDefinition extends BaseGroupDefinition<'presentation-group'> {
6
+ static isCompatible(localName: string, element: Element): boolean;
7
+ readonly type = "presentation-group";
8
+ readonly label: LabelDefinition;
9
+ constructor(form: XFormDefinition, parent: BodyElementParentContext, element: Element);
10
+ }
11
+ export type PresentationGroupDefinitionClass = typeof PresentationGroupDefinition;
@@ -0,0 +1,12 @@
1
+ import type { XFormDefinition } from '../../XFormDefinition.ts';
2
+ import type { BodyElementDefinitionArray, BodyElementParentContext } from '../BodyDefinition.ts';
3
+ import { RepeatDefinition } from '../RepeatDefinition.ts';
4
+ import { BaseGroupDefinition } from './BaseGroupDefinition.ts';
5
+ export declare class RepeatGroupDefinition extends BaseGroupDefinition<'repeat-group'> {
6
+ static isCompatible(localName: string, element: Element): boolean;
7
+ readonly type = "repeat-group";
8
+ readonly repeat: RepeatDefinition;
9
+ get repeatChildren(): BodyElementDefinitionArray;
10
+ constructor(form: XFormDefinition, parent: BodyElementParentContext, element: Element);
11
+ }
12
+ export type RepeatGroupDefinitionClass = typeof RepeatGroupDefinition;
@@ -0,0 +1,6 @@
1
+ import { BaseGroupDefinition } from './BaseGroupDefinition.ts';
2
+ export declare class StructuralGroupDefinition extends BaseGroupDefinition<'structural-group'> {
3
+ static isCompatible(localName: string, element: Element): boolean;
4
+ readonly type = "structural-group";
5
+ }
6
+ export type StructuralGroupDefinitionClass = typeof StructuralGroupDefinition;
@@ -0,0 +1,11 @@
1
+ import type { XFormDefinition } from '../../XFormDefinition.ts';
2
+ import type { AnyControlDefinition } from '../control/ControlDefinition.ts';
3
+ import type { TextElement } from './TextElementDefinition.ts';
4
+ import { TextElementDefinition } from './TextElementDefinition.ts';
5
+ export interface HintElement extends TextElement {
6
+ readonly localName: 'hint';
7
+ }
8
+ export declare class HintDefinition extends TextElementDefinition<'hint'> {
9
+ static forElement(form: XFormDefinition, definition: AnyControlDefinition): HintDefinition | null;
10
+ readonly type = "hint";
11
+ }
@@ -0,0 +1,20 @@
1
+ import type { XFormDefinition } from '../../XFormDefinition.ts';
2
+ import type { AnyControlDefinition } from '../control/ControlDefinition.ts';
3
+ import type { ItemDefinition } from '../control/select/ItemDefinition.ts';
4
+ import type { ItemsetDefinition } from '../control/select/ItemsetDefinition.ts';
5
+ import type { BaseGroupDefinition } from '../group/BaseGroupDefinition.ts';
6
+ import type { TextElement, TextElementOwner } from './TextElementDefinition.ts';
7
+ import { TextElementDefinition } from './TextElementDefinition.ts';
8
+ export interface LabelElement extends TextElement {
9
+ readonly localName: 'label';
10
+ }
11
+ type StaticLabelContext = Exclude<TextElementOwner, ItemsetDefinition>;
12
+ export declare class LabelDefinition extends TextElementDefinition<'label'> {
13
+ protected static staticDefinition(form: XFormDefinition, definition: StaticLabelContext): LabelDefinition | null;
14
+ static forControl(form: XFormDefinition, control: AnyControlDefinition): LabelDefinition | null;
15
+ static forGroup(form: XFormDefinition, group: BaseGroupDefinition<any>): LabelDefinition | null;
16
+ static forItem(form: XFormDefinition, item: ItemDefinition): LabelDefinition | null;
17
+ static forItemset(form: XFormDefinition, itemset: ItemsetDefinition): LabelDefinition | null;
18
+ readonly type = "label";
19
+ }
20
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { XFormDefinition } from '../../XFormDefinition.ts';
2
+ import { type AnyDependentExpression } from '../../expression/DependentExpression.ts';
3
+ import type { AnyGroupElementDefinition } from '../BodyDefinition.ts';
4
+ import { BodyElementDefinition } from '../BodyElementDefinition.ts';
5
+ import type { InputDefinition } from '../control/InputDefinition.ts';
6
+ import type { ItemDefinition } from '../control/select/ItemDefinition.ts';
7
+ import type { ItemsetDefinition } from '../control/select/ItemsetDefinition.ts';
8
+ import type { AnySelectDefinition } from '../control/select/SelectDefinition.ts';
9
+ import { TextElementOutputPart } from './TextElementOutputPart.ts';
10
+ import { TextElementReferencePart } from './TextElementReferencePart.ts';
11
+ import { TextElementStaticPart } from './TextElementStaticPart.ts';
12
+ export type TextElementType = 'hint' | 'label';
13
+ export interface TextElement extends Element {
14
+ readonly localName: TextElementType;
15
+ }
16
+ export type TextElementOwner = AnyGroupElementDefinition | AnySelectDefinition | InputDefinition | ItemDefinition | ItemsetDefinition;
17
+ export type TextElementChild = TextElementOutputPart | TextElementStaticPart;
18
+ export declare abstract class TextElementDefinition<Type extends TextElementType> extends BodyElementDefinition<Type> {
19
+ readonly owner: TextElementOwner;
20
+ readonly category = "support";
21
+ abstract readonly type: Type;
22
+ readonly reference: string | null;
23
+ readonly parentReference: string | null;
24
+ readonly referenceExpression: TextElementReferencePart | null;
25
+ readonly children: readonly TextElementChild[];
26
+ get isTranslated(): boolean;
27
+ set isTranslated(value: true);
28
+ protected constructor(form: XFormDefinition, owner: TextElementOwner, element: TextElement);
29
+ registerDependentExpression(expression: AnyDependentExpression): void;
30
+ toJSON(): object;
31
+ }
32
+ export type AnyTextElementDefinition = TextElementDefinition<TextElementType>;
@@ -0,0 +1,12 @@
1
+ import type { AnyTextElementDefinition } from './TextElementDefinition.ts';
2
+ import { TextElementPart } from './TextElementPart.ts';
3
+ interface OutputElement extends Element {
4
+ readonly localName: 'output';
5
+ getAttribute(name: 'value'): string;
6
+ getAttribute(name: string): string | null;
7
+ }
8
+ export declare class TextElementOutputPart extends TextElementPart<'output'> {
9
+ static from(context: AnyTextElementDefinition, element: Element): TextElementOutputPart | null;
10
+ protected constructor(context: AnyTextElementDefinition, element: OutputElement);
11
+ }
12
+ export {};
@@ -0,0 +1,12 @@
1
+ import { DependentExpression } from '../../expression/DependentExpression.ts';
2
+ import type { AnyTextElementDefinition } from './TextElementDefinition.ts';
3
+ import type { TextElementOutputPart } from './TextElementOutputPart.ts';
4
+ import type { TextElementReferencePart } from './TextElementReferencePart.ts';
5
+ import type { TextElementStaticPart } from './TextElementStaticPart.ts';
6
+ export type TextElementPartType = 'output' | 'reference' | 'static';
7
+ export declare abstract class TextElementPart<Type extends TextElementPartType> extends DependentExpression<'string'> {
8
+ readonly type: Type;
9
+ readonly stringValue?: string;
10
+ constructor(type: Type, context: AnyTextElementDefinition, expression: string);
11
+ }
12
+ export type AnyTextElementPart = TextElementOutputPart | TextElementReferencePart | TextElementStaticPart;
@@ -0,0 +1,6 @@
1
+ import type { AnyTextElementDefinition, TextElement } from './TextElementDefinition.ts';
2
+ import { TextElementPart } from './TextElementPart.ts';
3
+ export declare class TextElementReferencePart extends TextElementPart<'reference'> {
4
+ static from(context: AnyTextElementDefinition, element: TextElement): TextElementReferencePart | null;
5
+ protected constructor(context: AnyTextElementDefinition, expression: string);
6
+ }
@@ -0,0 +1,6 @@
1
+ import type { AnyTextElementDefinition } from './TextElementDefinition.ts';
2
+ import { TextElementPart } from './TextElementPart.ts';
3
+ export declare class TextElementStaticPart extends TextElementPart<'static'> {
4
+ readonly stringValue: string;
5
+ constructor(context: AnyTextElementDefinition, node: Text);
6
+ }