@getodk/xforms-engine 0.1.0 → 0.2.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 (157) hide show
  1. package/dist/.vite/manifest.json +1 -0
  2. package/dist/XFormDOM.d.ts +1 -0
  3. package/dist/XFormDataType.d.ts +2 -1
  4. package/dist/XFormDefinition.d.ts +1 -0
  5. package/dist/body/BodyDefinition.d.ts +27 -9
  6. package/dist/body/BodyElementDefinition.d.ts +5 -4
  7. package/dist/body/RepeatElementDefinition.d.ts +19 -0
  8. package/dist/body/UnsupportedBodyElementDefinition.d.ts +3 -2
  9. package/dist/body/appearance/inputAppearanceParser.d.ts +4 -0
  10. package/dist/body/appearance/selectAppearanceParser.d.ts +4 -0
  11. package/dist/body/appearance/structureElementAppearanceParser.d.ts +4 -0
  12. package/dist/body/control/ControlDefinition.d.ts +5 -2
  13. package/dist/body/control/InputDefinition.d.ts +6 -0
  14. package/dist/body/control/select/ItemDefinition.d.ts +4 -3
  15. package/dist/body/control/select/ItemsetDefinition.d.ts +4 -3
  16. package/dist/body/control/select/ItemsetNodesetContext.d.ts +3 -2
  17. package/dist/body/control/select/ItemsetNodesetExpression.d.ts +2 -1
  18. package/dist/body/control/select/ItemsetValueExpression.d.ts +2 -1
  19. package/dist/body/control/select/SelectDefinition.d.ts +16 -5
  20. package/dist/body/group/BaseGroupDefinition.d.ts +6 -10
  21. package/dist/body/group/LogicalGroupDefinition.d.ts +1 -0
  22. package/dist/body/group/PresentationGroupDefinition.d.ts +3 -2
  23. package/dist/body/group/StructuralGroupDefinition.d.ts +1 -0
  24. package/dist/body/text/HintDefinition.d.ts +4 -4
  25. package/dist/body/text/LabelDefinition.d.ts +9 -7
  26. package/dist/body/text/TextElementDefinition.d.ts +9 -8
  27. package/dist/body/text/TextElementOutputPart.d.ts +2 -1
  28. package/dist/body/text/TextElementPart.d.ts +5 -4
  29. package/dist/body/text/TextElementReferencePart.d.ts +2 -1
  30. package/dist/body/text/TextElementStaticPart.d.ts +2 -1
  31. package/dist/client/BaseNode.d.ts +9 -3
  32. package/dist/client/EngineConfig.d.ts +2 -1
  33. package/dist/client/GroupNode.d.ts +10 -6
  34. package/dist/client/NodeAppearances.d.ts +15 -0
  35. package/dist/client/RepeatInstanceNode.d.ts +10 -6
  36. package/dist/client/RepeatRangeNode.d.ts +11 -7
  37. package/dist/client/RootNode.d.ts +24 -4
  38. package/dist/client/SelectNode.d.ts +10 -6
  39. package/dist/client/StringNode.d.ts +9 -5
  40. package/dist/client/SubtreeNode.d.ts +6 -4
  41. package/dist/client/TextRange.d.ts +2 -1
  42. package/dist/client/hierarchy.d.ts +9 -8
  43. package/dist/client/index.d.ts +3 -2
  44. package/dist/expression/DependencyContext.d.ts +2 -1
  45. package/dist/expression/DependentExpression.d.ts +3 -2
  46. package/dist/index.d.ts +2 -1
  47. package/dist/index.js +1882 -1757
  48. package/dist/index.js.map +1 -1
  49. package/dist/instance/Group.d.ts +15 -15
  50. package/dist/instance/RepeatInstance.d.ts +39 -15
  51. package/dist/instance/RepeatRange.d.ts +98 -20
  52. package/dist/instance/Root.d.ts +25 -39
  53. package/dist/instance/SelectField.d.ts +17 -17
  54. package/dist/instance/StringField.d.ts +17 -17
  55. package/dist/instance/Subtree.d.ts +13 -13
  56. package/dist/instance/abstract/DescendantNode.d.ts +26 -18
  57. package/dist/instance/abstract/InstanceNode.d.ts +44 -46
  58. package/dist/instance/children.d.ts +2 -1
  59. package/dist/instance/hierarchy.d.ts +8 -7
  60. package/dist/instance/index.d.ts +4 -3
  61. package/dist/instance/internal-api/EvaluationContext.d.ts +10 -8
  62. package/dist/instance/internal-api/InstanceConfig.d.ts +3 -2
  63. package/dist/instance/internal-api/SubscribableDependency.d.ts +2 -1
  64. package/dist/instance/internal-api/TranslationContext.d.ts +2 -1
  65. package/dist/instance/internal-api/ValueContext.d.ts +6 -5
  66. package/dist/instance/resource.d.ts +3 -2
  67. package/dist/instance/text/TextChunk.d.ts +4 -3
  68. package/dist/instance/text/TextRange.d.ts +2 -1
  69. package/dist/lib/TokenListParser.d.ts +84 -0
  70. package/dist/lib/dom/query.d.ts +8 -2
  71. package/dist/lib/reactivity/createChildrenState.d.ts +4 -3
  72. package/dist/lib/reactivity/createComputedExpression.d.ts +4 -3
  73. package/dist/lib/reactivity/createSelectItems.d.ts +4 -3
  74. package/dist/lib/reactivity/createValueState.d.ts +3 -2
  75. package/dist/lib/reactivity/materializeCurrentStateChildren.d.ts +6 -4
  76. package/dist/lib/reactivity/node-state/createClientState.d.ts +7 -6
  77. package/dist/lib/reactivity/node-state/createCurrentState.d.ts +5 -4
  78. package/dist/lib/reactivity/node-state/createEngineState.d.ts +4 -3
  79. package/dist/lib/reactivity/node-state/createSharedNodeState.d.ts +7 -6
  80. package/dist/lib/reactivity/node-state/createSpecifiedPropertyDescriptor.d.ts +2 -1
  81. package/dist/lib/reactivity/node-state/createSpecifiedState.d.ts +3 -2
  82. package/dist/lib/reactivity/node-state/representations.d.ts +2 -1
  83. package/dist/lib/reactivity/scope.d.ts +2 -1
  84. package/dist/lib/reactivity/text/createFieldHint.d.ts +4 -3
  85. package/dist/lib/reactivity/text/createNodeLabel.d.ts +4 -3
  86. package/dist/lib/reactivity/text/createTextRange.d.ts +6 -5
  87. package/dist/lib/reactivity/types.d.ts +2 -1
  88. package/dist/lib/xpath/analysis.d.ts +2 -1
  89. package/dist/model/BindComputation.d.ts +2 -1
  90. package/dist/model/BindDefinition.d.ts +6 -5
  91. package/dist/model/DescendentNodeDefinition.d.ts +6 -6
  92. package/dist/model/ModelBindMap.d.ts +4 -3
  93. package/dist/model/ModelDefinition.d.ts +2 -1
  94. package/dist/model/NodeDefinition.d.ts +20 -19
  95. package/dist/model/RepeatInstanceDefinition.d.ts +7 -7
  96. package/dist/model/{RepeatSequenceDefinition.d.ts → RepeatRangeDefinition.d.ts} +7 -6
  97. package/dist/model/RepeatTemplateDefinition.d.ts +8 -8
  98. package/dist/model/RootDefinition.d.ts +8 -5
  99. package/dist/model/SubtreeDefinition.d.ts +5 -4
  100. package/dist/model/ValueNodeDefinition.d.ts +5 -5
  101. package/dist/solid.js +1873 -1751
  102. package/dist/solid.js.map +1 -1
  103. package/package.json +14 -18
  104. package/src/XFormDOM.ts +81 -8
  105. package/src/body/BodyDefinition.ts +38 -23
  106. package/src/body/RepeatElementDefinition.ts +70 -0
  107. package/src/body/appearance/inputAppearanceParser.ts +39 -0
  108. package/src/body/appearance/selectAppearanceParser.ts +38 -0
  109. package/src/body/appearance/structureElementAppearanceParser.ts +7 -0
  110. package/src/body/control/ControlDefinition.ts +4 -0
  111. package/src/body/control/InputDefinition.ts +13 -0
  112. package/src/body/control/select/SelectDefinition.ts +14 -5
  113. package/src/body/group/BaseGroupDefinition.ts +11 -49
  114. package/src/body/text/LabelDefinition.ts +15 -1
  115. package/src/body/text/TextElementDefinition.ts +5 -5
  116. package/src/client/BaseNode.ts +9 -1
  117. package/src/client/GroupNode.ts +6 -2
  118. package/src/client/NodeAppearances.ts +22 -0
  119. package/src/client/RepeatInstanceNode.ts +4 -0
  120. package/src/client/RepeatRangeNode.ts +6 -2
  121. package/src/client/RootNode.ts +22 -0
  122. package/src/client/SelectNode.ts +4 -0
  123. package/src/client/StringNode.ts +4 -0
  124. package/src/client/SubtreeNode.ts +1 -0
  125. package/src/instance/Group.ts +14 -9
  126. package/src/instance/RepeatInstance.ts +59 -15
  127. package/src/instance/RepeatRange.ts +133 -15
  128. package/src/instance/Root.ts +20 -64
  129. package/src/instance/SelectField.ts +7 -7
  130. package/src/instance/StringField.ts +8 -7
  131. package/src/instance/Subtree.ts +10 -7
  132. package/src/instance/abstract/DescendantNode.ts +45 -43
  133. package/src/instance/abstract/InstanceNode.ts +69 -86
  134. package/src/instance/children.ts +17 -7
  135. package/src/instance/index.ts +1 -1
  136. package/src/instance/internal-api/EvaluationContext.ts +5 -6
  137. package/src/instance/internal-api/ValueContext.ts +2 -2
  138. package/src/lib/TokenListParser.ts +156 -0
  139. package/src/lib/dom/query.ts +13 -0
  140. package/src/lib/reactivity/createChildrenState.ts +51 -6
  141. package/src/lib/reactivity/createComputedExpression.ts +1 -1
  142. package/src/lib/reactivity/createSelectItems.ts +4 -6
  143. package/src/lib/reactivity/createValueState.ts +6 -6
  144. package/src/lib/reactivity/materializeCurrentStateChildren.ts +3 -1
  145. package/src/model/DescendentNodeDefinition.ts +1 -2
  146. package/src/model/ModelDefinition.ts +1 -1
  147. package/src/model/NodeDefinition.ts +12 -12
  148. package/src/model/RepeatInstanceDefinition.ts +8 -13
  149. package/src/model/{RepeatSequenceDefinition.ts → RepeatRangeDefinition.ts} +6 -6
  150. package/src/model/RepeatTemplateDefinition.ts +10 -15
  151. package/src/model/RootDefinition.ts +6 -12
  152. package/src/model/SubtreeDefinition.ts +3 -3
  153. package/src/model/ValueNodeDefinition.ts +2 -3
  154. package/dist/body/RepeatDefinition.d.ts +0 -15
  155. package/dist/body/group/RepeatGroupDefinition.d.ts +0 -12
  156. package/src/body/RepeatDefinition.ts +0 -54
  157. package/src/body/group/RepeatGroupDefinition.ts +0 -91
@@ -1,9 +1,9 @@
1
1
  import { JAVAROSA_NAMESPACE_URI } from '@getodk/common/constants/xmlns.ts';
2
- import type { RepeatDefinition } from '../body/RepeatDefinition.ts';
2
+ import type { RepeatElementDefinition } from '../body/RepeatElementDefinition.ts';
3
3
  import { BindDefinition } from './BindDefinition.ts';
4
4
  import { DescendentNodeDefinition } from './DescendentNodeDefinition.ts';
5
5
  import type { ChildNodeDefinition, NodeDefinition } from './NodeDefinition.ts';
6
- import type { RepeatSequenceDefinition } from './RepeatSequenceDefinition.ts';
6
+ import type { RepeatRangeDefinition } from './RepeatRangeDefinition.ts';
7
7
 
8
8
  const repeatTemplates = new WeakMap<BindDefinition, RepeatTemplateDefinition>();
9
9
 
@@ -73,14 +73,14 @@ interface ParsedRepeatNodes {
73
73
  }
74
74
 
75
75
  export class RepeatTemplateDefinition
76
- extends DescendentNodeDefinition<'repeat-template', RepeatDefinition>
76
+ extends DescendentNodeDefinition<'repeat-template', RepeatElementDefinition>
77
77
  implements NodeDefinition<'repeat-template'>
78
78
  {
79
79
  static parseModelNodes(
80
- sequence: RepeatSequenceDefinition,
80
+ range: RepeatRangeDefinition,
81
81
  modelNodes: readonly [Element, ...Element[]]
82
82
  ): ParsedRepeatNodes {
83
- const { bind } = sequence;
83
+ const { bind } = range;
84
84
 
85
85
  let template = repeatTemplates.get(bind);
86
86
  let instanceNodes: readonly Element[];
@@ -89,7 +89,7 @@ export class RepeatTemplateDefinition
89
89
  const [templateNode, ...rest] = splitInstanceNodes(modelNodes);
90
90
 
91
91
  instanceNodes = rest;
92
- template = new this(sequence, templateNode);
92
+ template = new this(range, templateNode);
93
93
  } else {
94
94
  // TODO: this is under the assumption that for any depth > 1, if a
95
95
  // template has already been defined for the given form definition, any
@@ -121,17 +121,12 @@ export class RepeatTemplateDefinition
121
121
  readonly defaultValue = null;
122
122
 
123
123
  protected constructor(
124
- protected readonly sequence: RepeatSequenceDefinition,
124
+ range: RepeatRangeDefinition,
125
125
  protected readonly templateNode: ExplicitRepeatTemplateElement
126
126
  ) {
127
- const {
128
- bind,
129
- bodyElement: repeatGroupBodyElement,
130
- parent: repeatSequenceParent,
131
- root,
132
- } = sequence;
127
+ const { bind, bodyElement, parent, root } = range;
133
128
 
134
- super(repeatSequenceParent, bind, repeatGroupBodyElement.repeat);
129
+ super(parent, bind, bodyElement);
135
130
 
136
131
  const node = templateNode.cloneNode(true) as Element;
137
132
 
@@ -143,7 +138,7 @@ export class RepeatTemplateDefinition
143
138
  }
144
139
 
145
140
  toJSON() {
146
- const { bind, bodyElement, parent, root, sequence, ...rest } = this;
141
+ const { bind, bodyElement, parent, root, ...rest } = this;
147
142
 
148
143
  return rest;
149
144
  }
@@ -1,5 +1,5 @@
1
1
  import type { XFormDefinition } from '../XFormDefinition.ts';
2
- import type { RepeatGroupDefinition } from '../body/group/RepeatGroupDefinition.ts';
2
+ import type { BodyClassList } from '../body/BodyDefinition.ts';
3
3
  import type { BindDefinition } from './BindDefinition.ts';
4
4
  import type { ModelDefinition } from './ModelDefinition.ts';
5
5
  import type {
@@ -7,7 +7,7 @@ import type {
7
7
  NodeDefinition,
8
8
  ParentNodeDefinition,
9
9
  } from './NodeDefinition.ts';
10
- import { RepeatSequenceDefinition } from './RepeatSequenceDefinition.ts';
10
+ import { RepeatRangeDefinition } from './RepeatRangeDefinition.ts';
11
11
  import { SubtreeDefinition } from './SubtreeDefinition.ts';
12
12
  import { ValueNodeDefinition } from './ValueNodeDefinition.ts';
13
13
 
@@ -29,7 +29,8 @@ export class RootDefinition implements NodeDefinition<'root'> {
29
29
 
30
30
  constructor(
31
31
  protected readonly form: XFormDefinition,
32
- protected readonly model: ModelDefinition
32
+ protected readonly model: ModelDefinition,
33
+ readonly classes: BodyClassList
33
34
  ) {
34
35
  // TODO: theoretically the pertinent step in the bind's `nodeset` *could* be
35
36
  // namespaced. It also may make more sense to determine the root nodeset
@@ -86,16 +87,9 @@ export class RootDefinition implements NodeDefinition<'root'> {
86
87
  const bind = binds.getOrCreateBindDefinition(nodeset);
87
88
  const bodyElement = body.getBodyElement(nodeset);
88
89
  const [firstChild, ...restChildren] = children;
89
- const repeatGroup = body.getRepeatGroup(nodeset);
90
90
 
91
- if (repeatGroup != null) {
92
- const repeatDefinition = (bodyElement as RepeatGroupDefinition).repeat;
93
-
94
- if (repeatDefinition == null) {
95
- throw 'TODO: this is why I have hesitated to pick an "is repeat" predicate direction';
96
- }
97
-
98
- return new RepeatSequenceDefinition(parent, bind, repeatGroup, children);
91
+ if (bodyElement?.type === 'repeat') {
92
+ return new RepeatRangeDefinition(parent, bind, bodyElement, children);
99
93
  }
100
94
 
101
95
  if (restChildren.length) {
@@ -1,6 +1,6 @@
1
1
  import type {
2
2
  AnyBodyElementDefinition,
3
- NonRepeatGroupElementDefinition,
3
+ AnyGroupElementDefinition,
4
4
  } from '../body/BodyDefinition.ts';
5
5
  import type { BindDefinition } from './BindDefinition.ts';
6
6
  import { DescendentNodeDefinition } from './DescendentNodeDefinition.ts';
@@ -11,7 +11,7 @@ import type {
11
11
  } from './NodeDefinition.ts';
12
12
 
13
13
  export class SubtreeDefinition
14
- extends DescendentNodeDefinition<'subtree', NonRepeatGroupElementDefinition | null>
14
+ extends DescendentNodeDefinition<'subtree', AnyGroupElementDefinition | null>
15
15
  implements NodeDefinition<'subtree'>
16
16
  {
17
17
  readonly type = 'subtree';
@@ -29,7 +29,7 @@ export class SubtreeDefinition
29
29
  ) {
30
30
  if (
31
31
  bodyElement != null &&
32
- (bodyElement.category !== 'structure' || bodyElement.type === 'repeat-group')
32
+ (bodyElement.category !== 'structure' || bodyElement.type === 'repeat')
33
33
  ) {
34
34
  throw new Error(`Unexpected body element for nodeset ${bind.nodeset}`);
35
35
  }
@@ -1,11 +1,10 @@
1
- import type { AnyBodyElementDefinition } from '../body/BodyDefinition.ts';
2
- import type { AnyControlDefinition } from '../body/control/ControlDefinition.ts';
1
+ import type { AnyBodyElementDefinition, ControlElementDefinition } from '../body/BodyDefinition.ts';
3
2
  import type { BindDefinition } from './BindDefinition.ts';
4
3
  import { DescendentNodeDefinition } from './DescendentNodeDefinition.ts';
5
4
  import type { NodeDefinition, ParentNodeDefinition } from './NodeDefinition.ts';
6
5
 
7
6
  export class ValueNodeDefinition
8
- extends DescendentNodeDefinition<'value-node', AnyControlDefinition | null>
7
+ extends DescendentNodeDefinition<'value-node', ControlElementDefinition | null>
9
8
  implements NodeDefinition<'value-node'>
10
9
  {
11
10
  readonly type = 'value-node';
@@ -1,15 +0,0 @@
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
- }
@@ -1,12 +0,0 @@
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;
@@ -1,54 +0,0 @@
1
- import { JAVAROSA_NAMESPACE_URI } from '@getodk/common/constants/xmlns.ts';
2
- import type { XFormDefinition } from '../XFormDefinition.ts';
3
- import type { BodyElementDefinitionArray } from './BodyDefinition.ts';
4
- import { BodyElementDefinition } from './BodyElementDefinition.ts';
5
- import type { RepeatGroupDefinition } from './group/RepeatGroupDefinition.ts';
6
-
7
- export class RepeatDefinition extends BodyElementDefinition<'repeat'> {
8
- override readonly category = 'structure';
9
- readonly type = 'repeat';
10
- override readonly reference: string;
11
-
12
- // TODO: this will fall into the growing category of non-`BindExpression`
13
- // cases which have roughly the same design story.
14
- readonly countExpression: string | null;
15
-
16
- readonly isFixedCount: boolean;
17
-
18
- readonly children: BodyElementDefinitionArray;
19
-
20
- constructor(
21
- form: XFormDefinition,
22
- readonly groupDefinition: RepeatGroupDefinition,
23
- element: Element
24
- ) {
25
- super(form, groupDefinition, element);
26
-
27
- const reference = element.getAttribute('nodeset');
28
-
29
- if (reference == null) {
30
- throw new Error('Invalid repeat: missing `nodeset` reference');
31
- }
32
-
33
- this.reference = reference;
34
- this.countExpression = element.getAttributeNS(JAVAROSA_NAMESPACE_URI, 'count');
35
- this.children = groupDefinition.getChildren(element);
36
-
37
- // Spec says this can be either `true()` or `false()`. That said, it
38
- // could also presumably be `true ( )` or whatever.
39
- const noAddRemove =
40
- element
41
- .getAttributeNS(JAVAROSA_NAMESPACE_URI, 'noAddRemove')
42
- ?.trim()
43
- .replaceAll(/\s+/g, '') ?? 'false()';
44
-
45
- // TODO: **probably** safe to disregard anything else?
46
- this.isFixedCount = noAddRemove === 'true()';
47
- }
48
-
49
- override toJSON() {
50
- const { form, groupDefinition, parent, ...rest } = this;
51
-
52
- return rest;
53
- }
54
- }
@@ -1,91 +0,0 @@
1
- import { getRepeatElement } from '../../lib/dom/query.ts';
2
- import type { XFormDefinition } from '../../XFormDefinition.ts';
3
- import type { BodyElementDefinitionArray, BodyElementParentContext } from '../BodyDefinition.ts';
4
- import { RepeatDefinition } from '../RepeatDefinition.ts';
5
- import { BaseGroupDefinition } from './BaseGroupDefinition.ts';
6
-
7
- /**
8
- * TODO: The `RepeatGroupDefinition`/`RepeatDefinition` types are currently
9
- * expected to always pair, mirroring the corresponding XForm structure, e.g.
10
- *
11
- * ```xml
12
- * <group ref="/root/rep"> <!-- RepeatGroupDefinition -->
13
- * <repeat nodeset="/root/rep" /> <!-- RepeatDefinition -->
14
- * </group>
15
- * ```
16
- *
17
- * This structure has already been a source of one bug (where a recursive walk
18
- * through a `BodyDefinition`'s descendants failed to reach the children of
19
- * `RepeatDefinition`s). It seems likely this will continue to be a footgun.
20
- * After some discussion with @lognaturel, I concluded that the pairing isn't
21
- * strictly necessary, as this should be considered invalid:
22
- *
23
- * ```xml
24
- * <group ref="/root/rep">
25
- * <repeat nodeset="/root/rep" />
26
- * <input ref="/root/rep/not-a-repeat-child" />
27
- * </group>
28
- * ```
29
- *
30
- * It **may** make sense to collapse these types in the future, but I've held
31
- * off, following another discussion with @lognaturel. There's some potential
32
- * for group/repeat labeling ambiguity.
33
- *
34
- * - The current design accommodates sharing a repeat-containing group's label
35
- * across multiple repeat instances, but
36
- * - The
37
- * {@link https://github.com/getodk/xforms-spec/blob/791753a09fabd3d64d8cb95776dc0cef71fa4446/_sections/60-repeats.md?plain=1#L46 | ODK XForms spec suggests}
38
- * a repeat's first group might be a better candidate
39
- *
40
- * Example of such a structure:
41
- *
42
- * ```xml
43
- * <group ref="/root/foo">
44
- * <label>Foo (outer label)</label>
45
- * <repeat nodeset="/root/foo">
46
- * <group>
47
- * <label>Foo (inner label)</label>
48
- * <!-- ... -->
49
- * </group>
50
- * </repeat>
51
- * </group>
52
- * ```
53
- */
54
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
55
- // @ts-ignore - All this so I could attach a JSDoc comment to something other
56
- // than the actual class...
57
- // eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-unused-vars
58
- interface IgnoreMeIAmJustHereForTheJSDoc {}
59
-
60
- export class RepeatGroupDefinition extends BaseGroupDefinition<'repeat-group'> {
61
- static override isCompatible(localName: string, element: Element): boolean {
62
- return this.getGroupType(localName, element) === 'repeat-group';
63
- }
64
-
65
- readonly type = 'repeat-group';
66
-
67
- readonly repeat: RepeatDefinition;
68
-
69
- get repeatChildren(): BodyElementDefinitionArray {
70
- return this.repeat.children;
71
- }
72
-
73
- constructor(form: XFormDefinition, parent: BodyElementParentContext, element: Element) {
74
- // TODO: this has already been queried at least twice before reaching this
75
- // point!
76
- const repeat = getRepeatElement(element);
77
-
78
- // TODO: and as such, this should not happen
79
- if (repeat == null) {
80
- throw new Error('Invalid repeat-group');
81
- }
82
-
83
- super(form, parent, element);
84
-
85
- const repeatDefinition = new RepeatDefinition(form, this, repeat);
86
-
87
- this.repeat = repeatDefinition;
88
- }
89
- }
90
-
91
- export type RepeatGroupDefinitionClass = typeof RepeatGroupDefinition;