@getodk/xforms-engine 0.13.0 → 0.15.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.
- package/dist/client/AttributeNode.d.ts +53 -0
- package/dist/client/BaseItem.d.ts +6 -0
- package/dist/client/GroupNode.d.ts +4 -4
- package/dist/client/MarkdownNode.d.ts +33 -0
- package/dist/client/RankNode.d.ts +2 -4
- package/dist/client/SelectNode.d.ts +2 -5
- package/dist/client/TextRange.d.ts +2 -2
- package/dist/client/hierarchy.d.ts +1 -2
- package/dist/client/index.d.ts +2 -1
- package/dist/client/node-types.d.ts +2 -2
- package/dist/client/validation.d.ts +7 -1
- package/dist/index.js +10758 -402
- package/dist/index.js.map +1 -1
- package/dist/instance/Attribute.d.ts +58 -0
- package/dist/instance/Group.d.ts +4 -0
- package/dist/instance/PrimaryInstance.d.ts +4 -0
- package/dist/instance/Root.d.ts +4 -0
- package/dist/instance/UploadControl.d.ts +4 -0
- package/dist/instance/abstract/InstanceNode.d.ts +7 -4
- package/dist/instance/abstract/ValueNode.d.ts +1 -0
- package/dist/instance/attachments/buildAttributes.d.ts +3 -0
- package/dist/instance/hierarchy.d.ts +6 -6
- package/dist/instance/internal-api/AttributeContext.d.ts +29 -0
- package/dist/instance/internal-api/serialization/ClientReactiveSerializableAttributeNode.d.ts +16 -0
- package/dist/instance/internal-api/serialization/ClientReactiveSerializableParentNode.d.ts +2 -0
- package/dist/instance/internal-api/serialization/ClientReactiveSerializableTemplatedNode.d.ts +2 -2
- package/dist/instance/markdown/MarkdownNode.d.ts +75 -0
- package/dist/instance/repeat/BaseRepeatRange.d.ts +5 -0
- package/dist/instance/repeat/RepeatInstance.d.ts +4 -2
- package/dist/instance/text/TextChunk.d.ts +0 -1
- package/dist/instance/text/TextRange.d.ts +2 -1
- package/dist/instance/text/markdownFormat.d.ts +3 -0
- package/dist/integration/xpath/adapter/XFormsXPathNode.d.ts +2 -2
- package/dist/lib/client-reactivity/instance-state/createAttributeNodeInstanceState.d.ts +3 -0
- package/dist/lib/client-reactivity/instance-state/createTemplatedNodeInstanceState.d.ts +0 -3
- package/dist/lib/names/NamespaceDeclarationMap.d.ts +1 -1
- package/dist/lib/reactivity/createAttributeState.d.ts +16 -0
- package/dist/lib/reactivity/createAttributeValueState.d.ts +15 -0
- package/dist/lib/reactivity/createItemCollection.d.ts +5 -7
- package/dist/lib/xml-serialization.d.ts +5 -9
- package/dist/parse/XFormDOM.d.ts +1 -1
- package/dist/parse/body/BodyDefinition.d.ts +2 -8
- package/dist/parse/body/GroupElementDefinition.d.ts +22 -0
- package/dist/parse/body/control/ItemsetDefinition.d.ts +3 -0
- package/dist/parse/expression/ItemPropertyExpression.d.ts +6 -0
- package/dist/parse/model/AttributeDefinition.d.ts +22 -0
- package/dist/parse/model/{RootAttributeMap.d.ts → AttributeDefinitionMap.d.ts} +4 -10
- package/dist/parse/model/{SubtreeDefinition.d.ts → GroupDefinition.d.ts} +8 -4
- package/dist/parse/model/LeafNodeDefinition.d.ts +1 -0
- package/dist/parse/model/NodeDefinition.d.ts +13 -9
- package/dist/parse/model/RepeatDefinition.d.ts +5 -2
- package/dist/parse/model/RootDefinition.d.ts +3 -3
- package/dist/parse/text/LabelDefinition.d.ts +4 -5
- package/dist/solid.js +10758 -402
- package/dist/solid.js.map +1 -1
- package/package.json +6 -5
- package/src/client/AttributeNode.ts +62 -0
- package/src/client/BaseItem.ts +7 -0
- package/src/client/GroupNode.ts +4 -10
- package/src/client/MarkdownNode.ts +53 -0
- package/src/client/RankNode.ts +2 -5
- package/src/client/SelectNode.ts +2 -6
- package/src/client/TextRange.ts +2 -2
- package/src/client/hierarchy.ts +0 -2
- package/src/client/index.ts +2 -1
- package/src/client/node-types.ts +1 -1
- package/src/client/validation.ts +9 -1
- package/src/instance/Attribute.ts +164 -0
- package/src/instance/Group.ts +17 -1
- package/src/instance/InputControl.ts +1 -0
- package/src/instance/ModelValue.ts +1 -0
- package/src/instance/Note.ts +1 -0
- package/src/instance/PrimaryInstance.ts +17 -0
- package/src/instance/RangeControl.ts +1 -0
- package/src/instance/RankControl.ts +1 -0
- package/src/instance/Root.ts +16 -0
- package/src/instance/SelectControl.ts +1 -0
- package/src/instance/TriggerControl.ts +1 -0
- package/src/instance/UploadControl.ts +14 -0
- package/src/instance/abstract/DescendantNode.ts +5 -1
- package/src/instance/abstract/InstanceNode.ts +6 -3
- package/src/instance/abstract/ValueNode.ts +1 -0
- package/src/instance/attachments/buildAttributes.ts +8 -0
- package/src/instance/children/buildChildren.ts +1 -17
- package/src/instance/children/normalizeChildInitOptions.ts +44 -59
- package/src/instance/hierarchy.ts +3 -7
- package/src/instance/internal-api/AttributeContext.ts +34 -0
- package/src/instance/internal-api/serialization/ClientReactiveSerializableAttributeNode.ts +19 -0
- package/src/instance/internal-api/serialization/ClientReactiveSerializableParentNode.ts +2 -0
- package/src/instance/internal-api/serialization/ClientReactiveSerializableTemplatedNode.ts +2 -3
- package/src/instance/markdown/MarkdownNode.ts +115 -0
- package/src/instance/repeat/BaseRepeatRange.ts +14 -0
- package/src/instance/repeat/RepeatInstance.ts +14 -5
- package/src/instance/text/TextChunk.ts +0 -5
- package/src/instance/text/TextRange.ts +5 -3
- package/src/instance/text/markdownFormat.ts +214 -0
- package/src/integration/xpath/adapter/XFormsXPathNode.ts +3 -1
- package/src/integration/xpath/adapter/names.ts +0 -1
- package/src/lib/client-reactivity/instance-state/createAttributeNodeInstanceState.ts +16 -0
- package/src/lib/client-reactivity/instance-state/createParentNodeInstanceState.ts +5 -5
- package/src/lib/client-reactivity/instance-state/createRootInstanceState.ts +6 -9
- package/src/lib/client-reactivity/instance-state/createTemplatedNodeInstanceState.ts +5 -15
- package/src/lib/names/NamespaceDeclarationMap.ts +1 -1
- package/src/lib/reactivity/createAttributeState.ts +51 -0
- package/src/lib/reactivity/createAttributeValueState.ts +189 -0
- package/src/lib/reactivity/createItemCollection.ts +25 -9
- package/src/lib/xml-serialization.ts +30 -34
- package/src/parse/body/BodyDefinition.ts +7 -34
- package/src/parse/body/GroupElementDefinition.ts +47 -0
- package/src/parse/body/control/ItemsetDefinition.ts +7 -0
- package/src/parse/expression/ItemPropertyExpression.ts +12 -0
- package/src/parse/model/AttributeDefinition.ts +58 -0
- package/src/parse/model/{RootAttributeMap.ts → AttributeDefinitionMap.ts} +7 -13
- package/src/parse/model/{SubtreeDefinition.ts → GroupDefinition.ts} +12 -8
- package/src/parse/model/LeafNodeDefinition.ts +1 -0
- package/src/parse/model/NodeDefinition.ts +19 -12
- package/src/parse/model/RepeatDefinition.ts +10 -3
- package/src/parse/model/RootDefinition.ts +6 -6
- package/src/parse/model/nodeDefinitionMap.ts +1 -1
- package/src/parse/text/LabelDefinition.ts +4 -9
- package/dist/client/SubtreeNode.d.ts +0 -56
- package/dist/error/TemplatedNodeAttributeSerializationError.d.ts +0 -22
- package/dist/instance/Subtree.d.ts +0 -38
- package/dist/instance/text/FormattedTextStub.d.ts +0 -1
- package/dist/parse/body/group/BaseGroupDefinition.d.ts +0 -40
- package/dist/parse/body/group/LogicalGroupDefinition.d.ts +0 -6
- package/dist/parse/body/group/PresentationGroupDefinition.d.ts +0 -11
- package/dist/parse/body/group/StructuralGroupDefinition.d.ts +0 -6
- package/dist/parse/model/RootAttributeDefinition.d.ts +0 -21
- package/src/client/SubtreeNode.ts +0 -61
- package/src/error/TemplatedNodeAttributeSerializationError.ts +0 -24
- package/src/instance/Subtree.ts +0 -102
- package/src/instance/text/FormattedTextStub.ts +0 -8
- package/src/parse/body/group/BaseGroupDefinition.ts +0 -89
- package/src/parse/body/group/LogicalGroupDefinition.ts +0 -11
- package/src/parse/body/group/PresentationGroupDefinition.ts +0 -28
- package/src/parse/body/group/StructuralGroupDefinition.ts +0 -11
- package/src/parse/model/RootAttributeDefinition.ts +0 -44
package/src/instance/Subtree.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { XPathNodeKindKey } from '@getodk/xpath';
|
|
2
|
-
import type { Accessor } from 'solid-js';
|
|
3
|
-
import type { FormNodeID } from '../client/identity.ts';
|
|
4
|
-
import type { InstanceState } from '../client/serialization/InstanceState.ts';
|
|
5
|
-
import type { SubtreeDefinition, SubtreeNode } from '../client/SubtreeNode.ts';
|
|
6
|
-
import type { AncestorNodeValidationState } from '../client/validation.ts';
|
|
7
|
-
import type { XFormsXPathElement } from '../integration/xpath/adapter/XFormsXPathNode.ts';
|
|
8
|
-
import type { StaticElement } from '../integration/xpath/static-dom/StaticElement.ts';
|
|
9
|
-
import { createParentNodeInstanceState } from '../lib/client-reactivity/instance-state/createParentNodeInstanceState.ts';
|
|
10
|
-
import type { ChildrenState } from '../lib/reactivity/createChildrenState.ts';
|
|
11
|
-
import { createChildrenState } from '../lib/reactivity/createChildrenState.ts';
|
|
12
|
-
import type { MaterializedChildren } from '../lib/reactivity/materializeCurrentStateChildren.ts';
|
|
13
|
-
import { materializeCurrentStateChildren } from '../lib/reactivity/materializeCurrentStateChildren.ts';
|
|
14
|
-
import type { CurrentState } from '../lib/reactivity/node-state/createCurrentState.ts';
|
|
15
|
-
import type { EngineState } from '../lib/reactivity/node-state/createEngineState.ts';
|
|
16
|
-
import type { SharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
|
|
17
|
-
import { createSharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
|
|
18
|
-
import { createAggregatedViolations } from '../lib/reactivity/validation/createAggregatedViolations.ts';
|
|
19
|
-
import type { DescendantNodeSharedStateSpec } from './abstract/DescendantNode.ts';
|
|
20
|
-
import { DescendantNode } from './abstract/DescendantNode.ts';
|
|
21
|
-
import { buildChildren } from './children/buildChildren.ts';
|
|
22
|
-
import type { GeneralChildNode, GeneralParentNode } from './hierarchy.ts';
|
|
23
|
-
import type { EvaluationContext } from './internal-api/EvaluationContext.ts';
|
|
24
|
-
import type { ClientReactiveSerializableParentNode } from './internal-api/serialization/ClientReactiveSerializableParentNode.ts';
|
|
25
|
-
|
|
26
|
-
interface SubtreeStateSpec extends DescendantNodeSharedStateSpec {
|
|
27
|
-
readonly label: null;
|
|
28
|
-
readonly hint: null;
|
|
29
|
-
readonly children: Accessor<readonly FormNodeID[]>;
|
|
30
|
-
readonly valueOptions: null;
|
|
31
|
-
readonly value: null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export class Subtree
|
|
35
|
-
extends DescendantNode<SubtreeDefinition, SubtreeStateSpec, GeneralParentNode, GeneralChildNode>
|
|
36
|
-
implements
|
|
37
|
-
SubtreeNode,
|
|
38
|
-
XFormsXPathElement,
|
|
39
|
-
EvaluationContext,
|
|
40
|
-
ClientReactiveSerializableParentNode<GeneralChildNode>
|
|
41
|
-
{
|
|
42
|
-
private readonly childrenState: ChildrenState<GeneralChildNode>;
|
|
43
|
-
|
|
44
|
-
override readonly [XPathNodeKindKey] = 'element';
|
|
45
|
-
|
|
46
|
-
// InstanceNode
|
|
47
|
-
protected readonly state: SharedNodeState<SubtreeStateSpec>;
|
|
48
|
-
protected readonly engineState: EngineState<SubtreeStateSpec>;
|
|
49
|
-
|
|
50
|
-
// SubtreeNode
|
|
51
|
-
readonly nodeType = 'subtree';
|
|
52
|
-
readonly appearances = null;
|
|
53
|
-
readonly nodeOptions = null;
|
|
54
|
-
readonly currentState: MaterializedChildren<CurrentState<SubtreeStateSpec>, GeneralChildNode>;
|
|
55
|
-
readonly validationState: AncestorNodeValidationState;
|
|
56
|
-
readonly instanceState: InstanceState;
|
|
57
|
-
|
|
58
|
-
constructor(
|
|
59
|
-
parent: GeneralParentNode,
|
|
60
|
-
instanceNode: StaticElement | null,
|
|
61
|
-
definition: SubtreeDefinition
|
|
62
|
-
) {
|
|
63
|
-
super(parent, instanceNode, definition);
|
|
64
|
-
|
|
65
|
-
const childrenState = createChildrenState<Subtree, GeneralChildNode>(this);
|
|
66
|
-
|
|
67
|
-
this.childrenState = childrenState;
|
|
68
|
-
|
|
69
|
-
const state = createSharedNodeState(
|
|
70
|
-
this.scope,
|
|
71
|
-
{
|
|
72
|
-
reference: this.contextReference,
|
|
73
|
-
readonly: this.isReadonly,
|
|
74
|
-
relevant: this.isRelevant,
|
|
75
|
-
required: this.isRequired,
|
|
76
|
-
|
|
77
|
-
label: null,
|
|
78
|
-
hint: null,
|
|
79
|
-
children: childrenState.childIds,
|
|
80
|
-
valueOptions: null,
|
|
81
|
-
value: null,
|
|
82
|
-
},
|
|
83
|
-
this.instanceConfig
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
this.state = state;
|
|
87
|
-
this.engineState = state.engineState;
|
|
88
|
-
this.currentState = materializeCurrentStateChildren(
|
|
89
|
-
this.scope,
|
|
90
|
-
state.currentState,
|
|
91
|
-
childrenState
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
childrenState.setChildren(buildChildren(this));
|
|
95
|
-
this.validationState = createAggregatedViolations(this, this.instanceConfig);
|
|
96
|
-
this.instanceState = createParentNodeInstanceState(this);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
getChildren(): readonly GeneralChildNode[] {
|
|
100
|
-
return this.childrenState.getChildren();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { UpsertableMap } from '@getodk/common/lib/collections/UpsertableMap.ts';
|
|
2
|
-
import { getLabelElement } from '../../../lib/dom/query.ts';
|
|
3
|
-
import { LabelDefinition } from '../../text/LabelDefinition.ts';
|
|
4
|
-
import type { XFormDefinition } from '../../XFormDefinition.ts';
|
|
5
|
-
import { parseNodesetReference } from '../../xpath/reference-parsing.ts';
|
|
6
|
-
import type { StructureElementAppearanceDefinition } from '../appearance/structureElementAppearanceParser.ts';
|
|
7
|
-
import { structureElementAppearanceParser } from '../appearance/structureElementAppearanceParser.ts';
|
|
8
|
-
import {
|
|
9
|
-
type BodyElementDefinitionArray,
|
|
10
|
-
type BodyElementParentContext,
|
|
11
|
-
} from '../BodyDefinition.ts';
|
|
12
|
-
import { BodyElementDefinition } from '../BodyElementDefinition.ts';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* These type names are derived from **and expand upon** the language used in
|
|
16
|
-
* the ODK XForms spec to describe various group usage. Whereas the spec
|
|
17
|
-
* language allows for a group to be described as more than one case, the intent
|
|
18
|
-
* here is to establish exclusive naming which may or may not compound. As such:
|
|
19
|
-
*
|
|
20
|
-
* - `logical-group`, per spec language, is a group with a `ref`; its usage here
|
|
21
|
-
* differs from the spec language in that it _may_ have a `<label>` child but
|
|
22
|
-
* is not also treated as a `presentation-group` (which is only used for
|
|
23
|
-
* groups which do not have a `ref`)
|
|
24
|
-
* - `presentation-group` is a group with a `<label>` child; its usage here
|
|
25
|
-
* differs from the spec language in that `presentation-group` does **not**
|
|
26
|
-
* have a `ref`
|
|
27
|
-
* - `structural-group` is any `<group>` element which does not satisfy any of
|
|
28
|
-
* the other usage scenarios; this isn't exactly the terminology used, but is
|
|
29
|
-
* the most closely fitting name for the concept where the other sceanarios
|
|
30
|
-
* do not apply
|
|
31
|
-
*
|
|
32
|
-
* A more succinct decision tree:
|
|
33
|
-
*
|
|
34
|
-
* - `<group ref="$ref">` -> `logical-group`, else
|
|
35
|
-
* - `<group><label>` -> `presentation-group`, else
|
|
36
|
-
* - `<group>` -> `structural-group`
|
|
37
|
-
*/
|
|
38
|
-
export type GroupType = 'logical-group' | 'presentation-group' | 'structural-group';
|
|
39
|
-
|
|
40
|
-
export abstract class BaseGroupDefinition<
|
|
41
|
-
Type extends GroupType,
|
|
42
|
-
> extends BodyElementDefinition<Type> {
|
|
43
|
-
// TODO: does this really accomplish anything? It seems highly unlikely it
|
|
44
|
-
// has enough performance benefit to outweigh its memory and lookup costs.
|
|
45
|
-
private static groupTypes = new UpsertableMap<Element, GroupType | null>();
|
|
46
|
-
|
|
47
|
-
protected static getGroupType(localName: string, element: Element): GroupType | null {
|
|
48
|
-
return this.groupTypes.upsert(element, () => {
|
|
49
|
-
if (localName !== 'group') {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (element.hasAttribute('ref')) {
|
|
54
|
-
return 'logical-group';
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const label = getLabelElement(element);
|
|
58
|
-
|
|
59
|
-
if (label == null) {
|
|
60
|
-
return 'structural-group';
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return 'presentation-group';
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
override readonly category = 'structure';
|
|
68
|
-
|
|
69
|
-
readonly children: BodyElementDefinitionArray;
|
|
70
|
-
|
|
71
|
-
override readonly reference: string | null;
|
|
72
|
-
readonly appearances: StructureElementAppearanceDefinition;
|
|
73
|
-
override readonly label: LabelDefinition | null;
|
|
74
|
-
|
|
75
|
-
constructor(form: XFormDefinition, parent: BodyElementParentContext, element: Element) {
|
|
76
|
-
super(form, parent, element);
|
|
77
|
-
|
|
78
|
-
const childElements = Array.from(element.children).filter((child) => {
|
|
79
|
-
const childName = child.localName;
|
|
80
|
-
|
|
81
|
-
return childName !== 'label';
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
this.children = this.body.getChildElementDefinitions(form, this, element, childElements);
|
|
85
|
-
this.reference = parseNodesetReference(parent, element, 'ref');
|
|
86
|
-
this.appearances = structureElementAppearanceParser.parseFrom(element, 'appearance');
|
|
87
|
-
this.label = LabelDefinition.forGroup(form, this);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { BaseGroupDefinition } from './BaseGroupDefinition.ts';
|
|
2
|
-
|
|
3
|
-
export class LogicalGroupDefinition extends BaseGroupDefinition<'logical-group'> {
|
|
4
|
-
static override isCompatible(localName: string, element: Element): boolean {
|
|
5
|
-
return this.getGroupType(localName, element) === 'logical-group';
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
readonly type = 'logical-group';
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type LogicalGroupDefinitionClass = typeof LogicalGroupDefinition;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { LabelDefinition } from '../../text/LabelDefinition.ts';
|
|
2
|
-
import type { XFormDefinition } from '../../XFormDefinition.ts';
|
|
3
|
-
import type { BodyElementParentContext } from '../BodyDefinition.ts';
|
|
4
|
-
import { BaseGroupDefinition } from './BaseGroupDefinition.ts';
|
|
5
|
-
|
|
6
|
-
export class PresentationGroupDefinition extends BaseGroupDefinition<'presentation-group'> {
|
|
7
|
-
static override isCompatible(localName: string, element: Element): boolean {
|
|
8
|
-
return this.getGroupType(localName, element) === 'presentation-group';
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
readonly type = 'presentation-group';
|
|
12
|
-
|
|
13
|
-
override readonly label: LabelDefinition;
|
|
14
|
-
|
|
15
|
-
constructor(form: XFormDefinition, parent: BodyElementParentContext, element: Element) {
|
|
16
|
-
super(form, parent, element);
|
|
17
|
-
|
|
18
|
-
const label = LabelDefinition.forGroup(form, this);
|
|
19
|
-
|
|
20
|
-
if (label == null) {
|
|
21
|
-
throw new Error('Invalid presentation-group: missing label');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
this.label = label;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type PresentationGroupDefinitionClass = typeof PresentationGroupDefinition;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { BaseGroupDefinition } from './BaseGroupDefinition.ts';
|
|
2
|
-
|
|
3
|
-
export class StructuralGroupDefinition extends BaseGroupDefinition<'structural-group'> {
|
|
4
|
-
static override isCompatible(localName: string, element: Element): boolean {
|
|
5
|
-
return this.getGroupType(localName, element) === 'structural-group';
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
readonly type = 'structural-group';
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type StructuralGroupDefinitionClass = typeof StructuralGroupDefinition;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { XMLNS_NAMESPACE_URI } from '@getodk/common/constants/xmlns.ts';
|
|
2
|
-
import type { NamedNodeDefinition } from '../../lib/names/NamespaceDeclarationMap.ts';
|
|
3
|
-
import { QualifiedName } from '../../lib/names/QualifiedName.ts';
|
|
4
|
-
import { escapeXMLText } from '../../lib/xml-serialization.ts';
|
|
5
|
-
import type { RootDefinition } from './RootDefinition.ts';
|
|
6
|
-
|
|
7
|
-
interface RootAttributeSource {
|
|
8
|
-
readonly qualifiedName: QualifiedName;
|
|
9
|
-
readonly value: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @todo This class is named and typed to emphasize its intentionally narrow
|
|
14
|
-
* usage and purpose. It **intentionally** avoids addressing the much broader
|
|
15
|
-
* set of concerns around modeling attributes in primary instance/submissions.
|
|
16
|
-
*/
|
|
17
|
-
export class RootAttributeDefinition implements NamedNodeDefinition {
|
|
18
|
-
private readonly serializedXML: string;
|
|
19
|
-
|
|
20
|
-
readonly parent: RootDefinition;
|
|
21
|
-
readonly qualifiedName: QualifiedName;
|
|
22
|
-
readonly value: string;
|
|
23
|
-
|
|
24
|
-
constructor(root: RootDefinition, source: RootAttributeSource) {
|
|
25
|
-
const { qualifiedName, value } = source;
|
|
26
|
-
|
|
27
|
-
this.parent = root;
|
|
28
|
-
this.qualifiedName = qualifiedName;
|
|
29
|
-
this.value = value;
|
|
30
|
-
|
|
31
|
-
// We serialize namespace declarations separately
|
|
32
|
-
if (qualifiedName.namespaceURI?.href === XMLNS_NAMESPACE_URI) {
|
|
33
|
-
this.serializedXML = '';
|
|
34
|
-
} else {
|
|
35
|
-
const nodeName = qualifiedName.getPrefixedName();
|
|
36
|
-
|
|
37
|
-
this.serializedXML = ` ${nodeName}="${escapeXMLText(value, true)}"`;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
serializeAttributeXML(): string {
|
|
42
|
-
return this.serializedXML;
|
|
43
|
-
}
|
|
44
|
-
}
|