@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.
- package/README.md +44 -0
- package/dist/.vite/manifest.json +7 -0
- package/dist/XFormDOM.d.ts +31 -0
- package/dist/XFormDataType.d.ts +26 -0
- package/dist/XFormDefinition.d.ts +14 -0
- package/dist/body/BodyDefinition.d.ts +52 -0
- package/dist/body/BodyElementDefinition.d.ts +32 -0
- package/dist/body/RepeatDefinition.d.ts +15 -0
- package/dist/body/UnsupportedBodyElementDefinition.d.ts +10 -0
- package/dist/body/control/ControlDefinition.d.ts +16 -0
- package/dist/body/control/InputDefinition.d.ts +5 -0
- package/dist/body/control/select/ItemDefinition.d.ts +13 -0
- package/dist/body/control/select/ItemsetDefinition.d.ts +16 -0
- package/dist/body/control/select/ItemsetNodesetContext.d.ts +11 -0
- package/dist/body/control/select/ItemsetNodesetExpression.d.ts +5 -0
- package/dist/body/control/select/ItemsetValueExpression.d.ts +6 -0
- package/dist/body/control/select/SelectDefinition.d.ts +23 -0
- package/dist/body/group/BaseGroupDefinition.d.ts +46 -0
- package/dist/body/group/LogicalGroupDefinition.d.ts +6 -0
- package/dist/body/group/PresentationGroupDefinition.d.ts +11 -0
- package/dist/body/group/RepeatGroupDefinition.d.ts +12 -0
- package/dist/body/group/StructuralGroupDefinition.d.ts +6 -0
- package/dist/body/text/HintDefinition.d.ts +11 -0
- package/dist/body/text/LabelDefinition.d.ts +20 -0
- package/dist/body/text/TextElementDefinition.d.ts +32 -0
- package/dist/body/text/TextElementOutputPart.d.ts +12 -0
- package/dist/body/text/TextElementPart.d.ts +12 -0
- package/dist/body/text/TextElementReferencePart.d.ts +6 -0
- package/dist/body/text/TextElementStaticPart.d.ts +6 -0
- package/dist/client/BaseNode.d.ts +138 -0
- package/dist/client/EngineConfig.d.ts +78 -0
- package/dist/client/FormLanguage.d.ts +63 -0
- package/dist/client/GroupNode.d.ts +24 -0
- package/dist/client/OpaqueReactiveObjectFactory.d.ts +70 -0
- package/dist/client/RepeatInstanceNode.d.ts +28 -0
- package/dist/client/RepeatRangeNode.d.ts +94 -0
- package/dist/client/RootNode.d.ts +31 -0
- package/dist/client/SelectNode.d.ts +60 -0
- package/dist/client/StringNode.d.ts +41 -0
- package/dist/client/SubtreeNode.d.ts +52 -0
- package/dist/client/TextRange.d.ts +55 -0
- package/dist/client/hierarchy.d.ts +48 -0
- package/dist/client/index.d.ts +11 -0
- package/dist/client/node-types.d.ts +1 -0
- package/dist/expression/DependencyContext.d.ts +12 -0
- package/dist/expression/DependentExpression.d.ts +43 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +37622 -0
- package/dist/index.js.map +1 -0
- package/dist/instance/Group.d.ts +31 -0
- package/dist/instance/RepeatInstance.d.ts +60 -0
- package/dist/instance/RepeatRange.d.ts +81 -0
- package/dist/instance/Root.d.ts +70 -0
- package/dist/instance/SelectField.d.ts +45 -0
- package/dist/instance/StringField.d.ts +39 -0
- package/dist/instance/Subtree.d.ts +30 -0
- package/dist/instance/abstract/DescendantNode.d.ts +76 -0
- package/dist/instance/abstract/InstanceNode.d.ts +107 -0
- package/dist/instance/children.d.ts +2 -0
- package/dist/instance/hierarchy.d.ts +12 -0
- package/dist/instance/identity.d.ts +7 -0
- package/dist/instance/index.d.ts +8 -0
- package/dist/instance/internal-api/EvaluationContext.d.ts +34 -0
- package/dist/instance/internal-api/InstanceConfig.d.ts +8 -0
- package/dist/instance/internal-api/SubscribableDependency.d.ts +59 -0
- package/dist/instance/internal-api/TranslationContext.d.ts +4 -0
- package/dist/instance/internal-api/ValueContext.d.ts +22 -0
- package/dist/instance/resource.d.ts +10 -0
- package/dist/instance/text/FormattedTextStub.d.ts +1 -0
- package/dist/instance/text/TextChunk.d.ts +11 -0
- package/dist/instance/text/TextRange.d.ts +10 -0
- package/dist/lib/dom/query.d.ts +20 -0
- package/dist/lib/reactivity/createChildrenState.d.ts +36 -0
- package/dist/lib/reactivity/createComputedExpression.d.ts +12 -0
- package/dist/lib/reactivity/createSelectItems.d.ts +16 -0
- package/dist/lib/reactivity/createValueState.d.ts +44 -0
- package/dist/lib/reactivity/materializeCurrentStateChildren.d.ts +18 -0
- package/dist/lib/reactivity/node-state/createClientState.d.ts +9 -0
- package/dist/lib/reactivity/node-state/createCurrentState.d.ts +6 -0
- package/dist/lib/reactivity/node-state/createEngineState.d.ts +5 -0
- package/dist/lib/reactivity/node-state/createSharedNodeState.d.ts +22 -0
- package/dist/lib/reactivity/node-state/createSpecifiedPropertyDescriptor.d.ts +6 -0
- package/dist/lib/reactivity/node-state/createSpecifiedState.d.ts +139 -0
- package/dist/lib/reactivity/node-state/representations.d.ts +25 -0
- package/dist/lib/reactivity/scope.d.ts +23 -0
- package/dist/lib/reactivity/text/createFieldHint.d.ts +5 -0
- package/dist/lib/reactivity/text/createNodeLabel.d.ts +5 -0
- package/dist/lib/reactivity/text/createTextRange.d.ts +19 -0
- package/dist/lib/reactivity/types.d.ts +21 -0
- package/dist/lib/unique-id.d.ts +27 -0
- package/dist/lib/xpath/analysis.d.ts +22 -0
- package/dist/model/BindComputation.d.ts +30 -0
- package/dist/model/BindDefinition.d.ts +31 -0
- package/dist/model/BindElement.d.ts +6 -0
- package/dist/model/DescendentNodeDefinition.d.ts +25 -0
- package/dist/model/ModelBindMap.d.ts +15 -0
- package/dist/model/ModelDefinition.d.ts +10 -0
- package/dist/model/NodeDefinition.d.ts +74 -0
- package/dist/model/RepeatInstanceDefinition.d.ts +15 -0
- package/dist/model/RepeatSequenceDefinition.d.ts +19 -0
- package/dist/model/RepeatTemplateDefinition.d.ts +29 -0
- package/dist/model/RootDefinition.d.ts +24 -0
- package/dist/model/SubtreeDefinition.d.ts +14 -0
- package/dist/model/ValueNodeDefinition.d.ts +15 -0
- package/dist/solid.js +37273 -0
- package/dist/solid.js.map +1 -0
- package/package.json +87 -0
- package/src/XFormDOM.ts +224 -0
- package/src/XFormDataType.ts +64 -0
- package/src/XFormDefinition.ts +40 -0
- package/src/body/BodyDefinition.ts +202 -0
- package/src/body/BodyElementDefinition.ts +62 -0
- package/src/body/RepeatDefinition.ts +54 -0
- package/src/body/UnsupportedBodyElementDefinition.ts +17 -0
- package/src/body/control/ControlDefinition.ts +42 -0
- package/src/body/control/InputDefinition.ts +9 -0
- package/src/body/control/select/ItemDefinition.ts +31 -0
- package/src/body/control/select/ItemsetDefinition.ts +36 -0
- package/src/body/control/select/ItemsetNodesetContext.ts +26 -0
- package/src/body/control/select/ItemsetNodesetExpression.ts +8 -0
- package/src/body/control/select/ItemsetValueExpression.ts +11 -0
- package/src/body/control/select/SelectDefinition.ts +74 -0
- package/src/body/group/BaseGroupDefinition.ts +137 -0
- package/src/body/group/LogicalGroupDefinition.ts +11 -0
- package/src/body/group/PresentationGroupDefinition.ts +28 -0
- package/src/body/group/RepeatGroupDefinition.ts +91 -0
- package/src/body/group/StructuralGroupDefinition.ts +11 -0
- package/src/body/text/HintDefinition.ts +26 -0
- package/src/body/text/LabelDefinition.ts +54 -0
- package/src/body/text/TextElementDefinition.ts +97 -0
- package/src/body/text/TextElementOutputPart.ts +27 -0
- package/src/body/text/TextElementPart.ts +31 -0
- package/src/body/text/TextElementReferencePart.ts +21 -0
- package/src/body/text/TextElementStaticPart.ts +26 -0
- package/src/client/BaseNode.ts +180 -0
- package/src/client/EngineConfig.ts +83 -0
- package/src/client/FormLanguage.ts +77 -0
- package/src/client/GroupNode.ts +33 -0
- package/src/client/OpaqueReactiveObjectFactory.ts +100 -0
- package/src/client/README.md +39 -0
- package/src/client/RepeatInstanceNode.ts +41 -0
- package/src/client/RepeatRangeNode.ts +100 -0
- package/src/client/RootNode.ts +36 -0
- package/src/client/SelectNode.ts +69 -0
- package/src/client/StringNode.ts +46 -0
- package/src/client/SubtreeNode.ts +57 -0
- package/src/client/TextRange.ts +63 -0
- package/src/client/hierarchy.ts +63 -0
- package/src/client/index.ts +29 -0
- package/src/client/node-types.ts +10 -0
- package/src/expression/DependencyContext.ts +53 -0
- package/src/expression/DependentExpression.ts +102 -0
- package/src/index.ts +35 -0
- package/src/instance/Group.ts +82 -0
- package/src/instance/RepeatInstance.ts +164 -0
- package/src/instance/RepeatRange.ts +214 -0
- package/src/instance/Root.ts +264 -0
- package/src/instance/SelectField.ts +204 -0
- package/src/instance/StringField.ts +93 -0
- package/src/instance/Subtree.ts +79 -0
- package/src/instance/abstract/DescendantNode.ts +182 -0
- package/src/instance/abstract/InstanceNode.ts +257 -0
- package/src/instance/children.ts +52 -0
- package/src/instance/hierarchy.ts +54 -0
- package/src/instance/identity.ts +11 -0
- package/src/instance/index.ts +37 -0
- package/src/instance/internal-api/EvaluationContext.ts +41 -0
- package/src/instance/internal-api/InstanceConfig.ts +9 -0
- package/src/instance/internal-api/SubscribableDependency.ts +61 -0
- package/src/instance/internal-api/TranslationContext.ts +5 -0
- package/src/instance/internal-api/ValueContext.ts +27 -0
- package/src/instance/resource.ts +75 -0
- package/src/instance/text/FormattedTextStub.ts +8 -0
- package/src/instance/text/TextChunk.ts +20 -0
- package/src/instance/text/TextRange.ts +23 -0
- package/src/lib/dom/query.ts +49 -0
- package/src/lib/reactivity/createChildrenState.ts +60 -0
- package/src/lib/reactivity/createComputedExpression.ts +114 -0
- package/src/lib/reactivity/createSelectItems.ts +163 -0
- package/src/lib/reactivity/createValueState.ts +258 -0
- package/src/lib/reactivity/materializeCurrentStateChildren.ts +121 -0
- package/src/lib/reactivity/node-state/createClientState.ts +51 -0
- package/src/lib/reactivity/node-state/createCurrentState.ts +27 -0
- package/src/lib/reactivity/node-state/createEngineState.ts +18 -0
- package/src/lib/reactivity/node-state/createSharedNodeState.ts +79 -0
- package/src/lib/reactivity/node-state/createSpecifiedPropertyDescriptor.ts +85 -0
- package/src/lib/reactivity/node-state/createSpecifiedState.ts +229 -0
- package/src/lib/reactivity/node-state/representations.ts +64 -0
- package/src/lib/reactivity/scope.ts +106 -0
- package/src/lib/reactivity/text/createFieldHint.ts +16 -0
- package/src/lib/reactivity/text/createNodeLabel.ts +16 -0
- package/src/lib/reactivity/text/createTextRange.ts +155 -0
- package/src/lib/reactivity/types.ts +27 -0
- package/src/lib/unique-id.ts +34 -0
- package/src/lib/xpath/analysis.ts +241 -0
- package/src/model/BindComputation.ts +88 -0
- package/src/model/BindDefinition.ts +104 -0
- package/src/model/BindElement.ts +8 -0
- package/src/model/DescendentNodeDefinition.ts +56 -0
- package/src/model/ModelBindMap.ts +71 -0
- package/src/model/ModelDefinition.ts +19 -0
- package/src/model/NodeDefinition.ts +146 -0
- package/src/model/RepeatInstanceDefinition.ts +39 -0
- package/src/model/RepeatSequenceDefinition.ts +53 -0
- package/src/model/RepeatTemplateDefinition.ts +150 -0
- package/src/model/RootDefinition.ts +121 -0
- package/src/model/SubtreeDefinition.ts +50 -0
- package/src/model/ValueNodeDefinition.ts +39 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ReactiveScope } from '../../lib/reactivity/scope.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Provides a common interface to explicitly establish a reactive subscription
|
|
4
|
+
* to a form node, regardless of which node-specific details might trigger
|
|
5
|
+
* reactive updates. This is primarily intended for use in coordination with a
|
|
6
|
+
* node's {@link EvaluationContext} interface, so that computed expression
|
|
7
|
+
* evaluations can be re-executed when their dependencies update, without
|
|
8
|
+
* requiring a given evaluation to handle node-specific logic to determine
|
|
9
|
+
* when/whether updates have occurred.
|
|
10
|
+
*
|
|
11
|
+
* @example Given a form with these bindings:
|
|
12
|
+
*
|
|
13
|
+
* ```xml
|
|
14
|
+
* <bind nodeset="/data/field-1" />
|
|
15
|
+
* <bind nodeset="/data/field-2" type="int" />
|
|
16
|
+
* <bind nodeset="/data/group-a" relevant="/data/field-1 != ''" />
|
|
17
|
+
* <bind nodeset="/data/group-a/field-a-1" calculate="/data/field-2 * 2" />
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* The field `/data/group-a/field-a-1`'s calculate has two dependencies:
|
|
21
|
+
*
|
|
22
|
+
* - `/data-field-2` (explicit)
|
|
23
|
+
* - `/data/group-a` (implicit: non-relevance is inherited)
|
|
24
|
+
*
|
|
25
|
+
* (This is an oversimplification, but it helps to illustrate the concept.)
|
|
26
|
+
*
|
|
27
|
+
* The first dependency's subscription is clearly concerned with that leaf
|
|
28
|
+
* node's value. In which case, that node's `subscribe` method should react to
|
|
29
|
+
* updates to its value (e.g. its `currentState.value` or the internal reactive
|
|
30
|
+
* representation thereof).
|
|
31
|
+
*
|
|
32
|
+
* Whereas the second dependency has no value (no parent nodes do); instead, the
|
|
33
|
+
* subscription would be concerned with that node's relevance. In which case,
|
|
34
|
+
* that node's `subscribe` method should react to updates to its relevance state
|
|
35
|
+
* (e.g. its `currentState.relevant` or the internal reactive represeentation
|
|
36
|
+
* thereof).
|
|
37
|
+
*
|
|
38
|
+
* @example Given a form with:
|
|
39
|
+
*
|
|
40
|
+
* ```xml
|
|
41
|
+
* <!-- model -->
|
|
42
|
+
* <bind nodeset="/data/repeat-a/field-a-1" calculate="position(..)" />
|
|
43
|
+
* <!-- body -->
|
|
44
|
+
* <repeat nodeset="/data/repeat-a" />
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* The field `/data/repeat-a/field-a-1` has a dependency on its containing
|
|
48
|
+
* repeat instance. That node also doesn't have a value, and here the dynamic
|
|
49
|
+
* aspect of the dependency is the node's current position. Here the node's
|
|
50
|
+
* `subscribe` method should react to changes in its position (likely indirectly
|
|
51
|
+
* by reading its `contextReference`).
|
|
52
|
+
*
|
|
53
|
+
* @see {@link EvaluationContext}
|
|
54
|
+
* @see {@link EvaluationContext.contextReference}
|
|
55
|
+
*/
|
|
56
|
+
export interface SubscribableDependency {
|
|
57
|
+
readonly scope: ReactiveScope;
|
|
58
|
+
readonly subscribe: VoidFunction;
|
|
59
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ReactiveScope } from '../../lib/reactivity/scope.ts';
|
|
2
|
+
import type { BindComputation } from '../../model/BindComputation.ts';
|
|
3
|
+
import type { EvaluationContext } from './EvaluationContext.ts';
|
|
4
|
+
export type InstanceValue = string;
|
|
5
|
+
interface ValueContextDefinitionBind {
|
|
6
|
+
readonly calculate: BindComputation<'calculate'> | null;
|
|
7
|
+
readonly readonly: BindComputation<'readonly'>;
|
|
8
|
+
}
|
|
9
|
+
export interface ValueContextDefinition {
|
|
10
|
+
readonly bind: ValueContextDefinitionBind;
|
|
11
|
+
readonly defaultValue: InstanceValue;
|
|
12
|
+
}
|
|
13
|
+
export interface ValueContext<RuntimeValue> extends EvaluationContext {
|
|
14
|
+
readonly scope: ReactiveScope;
|
|
15
|
+
readonly definition: ValueContextDefinition;
|
|
16
|
+
readonly contextNode: Element;
|
|
17
|
+
get isReadonly(): boolean;
|
|
18
|
+
get isRelevant(): boolean;
|
|
19
|
+
readonly encodeValue: (this: unknown, runtimeValue: RuntimeValue) => InstanceValue;
|
|
20
|
+
readonly decodeValue: (this: unknown, instanceValue: InstanceValue) => RuntimeValue;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FetchResource, FetchResourceResponse } from '../client/EngineConfig.ts';
|
|
2
|
+
import type { FormResource } from '../client/index.ts';
|
|
3
|
+
export type { FetchResource, FetchResourceResponse, FormResource };
|
|
4
|
+
export interface ResourceOptions {
|
|
5
|
+
readonly fetchResource: FetchResource;
|
|
6
|
+
}
|
|
7
|
+
declare const resourceXMLPrefix = "<";
|
|
8
|
+
type ResourceXMLPrefix = typeof resourceXMLPrefix;
|
|
9
|
+
type ResourceXML = `${ResourceXMLPrefix}${string}`;
|
|
10
|
+
export declare const retrieveSourceXMLResource: (resource: FormResource, options: ResourceOptions) => Promise<ResourceXML>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const FormattedTextStub: Record<PropertyKey, unknown>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ActiveLanguage } from '../../client/FormLanguage.ts';
|
|
2
|
+
import type { TextChunk as ClientTextChunk, TextChunkSource } from '../../client/TextRange.ts';
|
|
3
|
+
import type { TranslationContext } from '../internal-api/TranslationContext.ts';
|
|
4
|
+
export declare class TextChunk implements ClientTextChunk {
|
|
5
|
+
readonly context: TranslationContext;
|
|
6
|
+
readonly source: TextChunkSource;
|
|
7
|
+
readonly asString: string;
|
|
8
|
+
get formatted(): Record<PropertyKey, unknown>;
|
|
9
|
+
get language(): ActiveLanguage;
|
|
10
|
+
constructor(context: TranslationContext, source: TextChunkSource, asString: string);
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TextRange as ClientTextRange, TextChunk } from '../../client/TextRange.ts';
|
|
2
|
+
export type TextRole = 'hint' | 'label';
|
|
3
|
+
export declare class TextRange<Role extends TextRole> implements ClientTextRange<Role> {
|
|
4
|
+
readonly role: Role;
|
|
5
|
+
protected readonly chunks: readonly TextChunk[];
|
|
6
|
+
[Symbol.iterator](): Generator<TextChunk, void, undefined>;
|
|
7
|
+
get formatted(): Record<PropertyKey, unknown>;
|
|
8
|
+
get asString(): string;
|
|
9
|
+
constructor(role: Role, chunks: readonly TextChunk[]);
|
|
10
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { KnownAttributeLocalNamedElement, LocalNamedElement } from '../../../../common/types/dom.ts';
|
|
2
|
+
import type { SelectElement } from '../../body/control/select/SelectDefinition';
|
|
3
|
+
export interface HintElement extends LocalNamedElement<'hint'> {
|
|
4
|
+
}
|
|
5
|
+
export interface ItemElement extends LocalNamedElement<'item'> {
|
|
6
|
+
}
|
|
7
|
+
export interface ItemsetElement extends KnownAttributeLocalNamedElement<'itemset', 'nodeset'> {
|
|
8
|
+
}
|
|
9
|
+
export interface LabelElement extends LocalNamedElement<'label'> {
|
|
10
|
+
}
|
|
11
|
+
export interface RepeatElement extends KnownAttributeLocalNamedElement<'repeat', 'nodeset'> {
|
|
12
|
+
}
|
|
13
|
+
export interface ValueElement extends LocalNamedElement<'value'> {
|
|
14
|
+
}
|
|
15
|
+
export declare const getHintElement: (parent: Element) => HintElement | null;
|
|
16
|
+
export declare const getItemElements: (parent: SelectElement) => readonly ItemElement[];
|
|
17
|
+
export declare const getItemsetElement: (parent: Element) => ItemsetElement | null;
|
|
18
|
+
export declare const getLabelElement: (parent: Element) => LabelElement | null;
|
|
19
|
+
export declare const getRepeatElement: (parent: Element) => RepeatElement | null;
|
|
20
|
+
export declare const getValueElement: (parent: ItemElement | ItemsetElement) => ValueElement | null;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Accessor, type Setter, type Signal } from 'solid-js';
|
|
2
|
+
import type { AnyChildNode, AnyParentNode } from '../../instance/hierarchy.ts';
|
|
3
|
+
import type { NodeID } from '../../instance/identity.ts';
|
|
4
|
+
export interface ChildrenState<Child extends AnyChildNode> {
|
|
5
|
+
readonly children: Signal<readonly Child[]>;
|
|
6
|
+
readonly getChildren: Accessor<readonly Child[]>;
|
|
7
|
+
readonly setChildren: Setter<readonly Child[]>;
|
|
8
|
+
readonly childIds: Accessor<readonly NodeID[]>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates a synchronized pair of:
|
|
12
|
+
*
|
|
13
|
+
* - Internal children state suitable for all parent node types
|
|
14
|
+
* - The same children state computed as an array of each child's {@link NodeID}
|
|
15
|
+
*
|
|
16
|
+
* This state is used, in tandem with {@link materializeCurrentStateChildren},
|
|
17
|
+
* to ensure children in **client-facing** state are not written into nested
|
|
18
|
+
* {@link OpaqueReactiveObjectFactory} calls.
|
|
19
|
+
*
|
|
20
|
+
* The produced {@link ChildrenState.children} (and its get/set convenience
|
|
21
|
+
* methods) signal is intended to be used to store the engine's children state,
|
|
22
|
+
* and update that state when appropriate (when appending children of any parent
|
|
23
|
+
* node during form initialization, and when appending repeat instances and
|
|
24
|
+
* their descendants subsequently during a form session).
|
|
25
|
+
*
|
|
26
|
+
* The produced {@link ChildrenState.childIds} memo is intended to be used to
|
|
27
|
+
* specify each parent node's `children` in an instance of {@link EngineState}.
|
|
28
|
+
* In so doing, the node's corresponding (internal, synchronized)
|
|
29
|
+
* {@link ClientState} will likewise store only the children's {@link NodeID}s.
|
|
30
|
+
*
|
|
31
|
+
* As a client reacts to changes in a given parent node's `children` state, that
|
|
32
|
+
* node's {@link CurrentState} should produce the child nodes corresponding to
|
|
33
|
+
* those {@link NodeID}s with the aforementioned
|
|
34
|
+
* {@link materializeCurrentStateChildren}.
|
|
35
|
+
*/
|
|
36
|
+
export declare const createChildrenState: <Parent extends AnyParentNode, Child extends AnyChildNode>(parent: Parent) => ChildrenState<Child>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Accessor } from 'solid-js';
|
|
2
|
+
import type { DependentExpression, DependentExpressionResultType } from '../../expression/DependentExpression.ts';
|
|
3
|
+
import type { EvaluationContext } from '../../instance/internal-api/EvaluationContext.ts';
|
|
4
|
+
interface ComputedExpressionResults {
|
|
5
|
+
readonly boolean: boolean;
|
|
6
|
+
readonly nodes: Node[];
|
|
7
|
+
readonly string: string;
|
|
8
|
+
}
|
|
9
|
+
type EvaluatedExpression<Type extends DependentExpressionResultType> = ComputedExpressionResults[Type];
|
|
10
|
+
type ComputedExpression<Type extends DependentExpressionResultType> = Accessor<EvaluatedExpression<Type>>;
|
|
11
|
+
export declare const createComputedExpression: <Type extends "string" | "boolean" | "nodes">(context: EvaluationContext, dependentExpression: DependentExpression<Type>) => ComputedExpression<Type>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Accessor } from 'solid-js';
|
|
2
|
+
import type { SelectItem } from '../../index.ts';
|
|
3
|
+
import type { SelectField } from '../../instance/SelectField.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a reactive computation of a {@link SelectField}'s
|
|
6
|
+
* {@link SelectItem}s, in support of the field's `valueOptions`.
|
|
7
|
+
*
|
|
8
|
+
* - Selects defined with static `<item>`s will compute to an corresponding
|
|
9
|
+
* static list of items.
|
|
10
|
+
* - Selects defined with a computed `<itemset>` will compute to a reactive list
|
|
11
|
+
* of items.
|
|
12
|
+
* - Items of both will produce {@link SelectItem.label | labels} reactive to
|
|
13
|
+
* their appropriate dependencies (whether relative to the itemset item node,
|
|
14
|
+
* referencing a form's `itext` translations, etc).
|
|
15
|
+
*/
|
|
16
|
+
export declare const createSelectItems: (selectField: SelectField) => Accessor<readonly SelectItem[]>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ValueContext } from '../../instance/internal-api/ValueContext.ts';
|
|
2
|
+
import type { SimpleAtomicState } from './types.ts';
|
|
3
|
+
type InitialValueSource = 'FORM_DEFAULT' | 'PRIMARY_INSTANCE';
|
|
4
|
+
export interface ValueStateOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Specifies the source of a {@link createValueState} signal's initial
|
|
7
|
+
* value state, where:
|
|
8
|
+
*
|
|
9
|
+
* - 'FORM_DEFAULT': Derives the initial state from the form's
|
|
10
|
+
* definition of the node itself. This is the default option, appropriate
|
|
11
|
+
* when initializing a form without additional primary instance data. In
|
|
12
|
+
* other words, this value should not be used for edits.
|
|
13
|
+
*
|
|
14
|
+
* - 'PRIMARY_INSTANCE': Derives the initial state from the current text
|
|
15
|
+
* content of the {@link ValueNode.contextNode} (currently an XML DOM
|
|
16
|
+
* backing store/source of thruth for primary instance state). This option
|
|
17
|
+
* should be specified when initializing a form with existing primary
|
|
18
|
+
* instance data, such as when editing a previous submission.
|
|
19
|
+
*
|
|
20
|
+
* @default 'FORM_DEFAULT'
|
|
21
|
+
*
|
|
22
|
+
* Specifies whether a {@link createV} signal's initial state
|
|
23
|
+
* should be derived from the current text content of the
|
|
24
|
+
* {@link ValueNode.contextNode | primary instance DOM state}.
|
|
25
|
+
*/
|
|
26
|
+
readonly initialValueSource?: InitialValueSource;
|
|
27
|
+
}
|
|
28
|
+
type ValueState<RuntimeValue> = SimpleAtomicState<RuntimeValue>;
|
|
29
|
+
/**
|
|
30
|
+
* Provides a consistent interface for value nodes of any type which:
|
|
31
|
+
*
|
|
32
|
+
* - derives initial state from either the existing primary instance state (e.g.
|
|
33
|
+
* for edits) or the node's definition (e.g. initializing a new submission)
|
|
34
|
+
* - decodes primary instance state into the value node's runtime type
|
|
35
|
+
* - encodes and persists updated values to the primary instance
|
|
36
|
+
* - initializes reactive computation of `calculate` bind expressions for those
|
|
37
|
+
* nodes defined with one
|
|
38
|
+
* - ensures any downstream reactive dependencies are updated only after writes
|
|
39
|
+
* (whether performed by a client, or by a reactive `calculate` computation)
|
|
40
|
+
* are persisted, ensuring a consistent view of state when downstream
|
|
41
|
+
* computations perform XPath evaluations against that primary instance state
|
|
42
|
+
*/
|
|
43
|
+
export declare const createValueState: <RuntimeValue>(context: ValueContext<RuntimeValue>, options?: ValueStateOptions) => ValueState<RuntimeValue>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AnyChildNode } from '../../instance/hierarchy.ts';
|
|
2
|
+
import type { NodeID } from '../../instance/identity.ts';
|
|
3
|
+
import type { ChildrenState } from './createChildrenState.ts';
|
|
4
|
+
export interface EncodedParentState {
|
|
5
|
+
readonly children: readonly NodeID[];
|
|
6
|
+
}
|
|
7
|
+
export type MaterializedChildren<BaseState extends EncodedParentState, Child extends AnyChildNode | null> = Omit<BaseState, 'children'> & {
|
|
8
|
+
readonly children: readonly Child[];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Creates a wrapper proxy around a parent node's {@link CurrentState} to map
|
|
12
|
+
* `children` state, which is written to the node's (internal, synchronized)
|
|
13
|
+
* {@link ClientState} as an array of {@link NodeID}s, back to the node objects
|
|
14
|
+
* corresponding to those IDs.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link createChildrenState} for further detail.
|
|
17
|
+
*/
|
|
18
|
+
export declare const materializeCurrentStateChildren: <Child extends AnyChildNode, ParentState extends EncodedParentState>(currentState: ParentState, childrenState: ChildrenState<Child>) => MaterializedChildren<ParentState, Child>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ShallowMutable } from '../../../../../common/types/helpers.js';
|
|
2
|
+
import type { OpaqueReactiveObjectFactory } from '../../../index.ts';
|
|
3
|
+
import type { ReactiveScope } from '../scope.ts';
|
|
4
|
+
import type { EngineState } from './createEngineState.ts';
|
|
5
|
+
import type { SpecifiedState, StateSpec } from './createSpecifiedState.ts';
|
|
6
|
+
import type { InternalClientRepresentation } from './representations.ts';
|
|
7
|
+
export type SpecifiedClientStateFactory<Factory extends OpaqueReactiveObjectFactory, Spec extends StateSpec> = ShallowMutable<SpecifiedState<Spec>> extends Parameters<Factory>[0] ? Factory : never;
|
|
8
|
+
export type ClientState<Spec extends StateSpec> = InternalClientRepresentation<SpecifiedState<Spec>>;
|
|
9
|
+
export declare const createClientState: <Factory extends OpaqueReactiveObjectFactory, Spec extends StateSpec>(scope: ReactiveScope, engineState: EngineState<Spec>, clientStateFactory: SpecifiedClientStateFactory<Factory, Spec>) => ClientState<Spec>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReactiveScope } from '../scope.ts';
|
|
2
|
+
import type { ClientState } from './createClientState.ts';
|
|
3
|
+
import type { SpecifiedState, StateSpec } from './createSpecifiedState.ts';
|
|
4
|
+
import type { ReadonlyClientRepresentation } from './representations.ts';
|
|
5
|
+
export type CurrentState<Spec extends StateSpec> = ReadonlyClientRepresentation<SpecifiedState<Spec>>;
|
|
6
|
+
export declare const createCurrentState: <Spec extends StateSpec>(scope: ReactiveScope, clientState: ClientState<Spec>) => CurrentState<Spec>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ReactiveScope } from '../scope.ts';
|
|
2
|
+
import type { SpecifiedState, StateSpec } from './createSpecifiedState.ts';
|
|
3
|
+
import type { EngineRepresentation } from './representations.ts';
|
|
4
|
+
export type EngineState<Spec extends StateSpec> = EngineRepresentation<SpecifiedState<Spec>>;
|
|
5
|
+
export declare const createEngineState: <Spec extends StateSpec>(scope: ReactiveScope, spec: Spec) => EngineState<Spec>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { OpaqueReactiveObjectFactory } from '../../../index.ts';
|
|
2
|
+
import type { ReactiveScope } from '../scope.ts';
|
|
3
|
+
import type { ClientState, SpecifiedClientStateFactory } from './createClientState.ts';
|
|
4
|
+
import type { CurrentState } from './createCurrentState.ts';
|
|
5
|
+
import type { EngineState } from './createEngineState.ts';
|
|
6
|
+
import type { MutablePropertySpec, SpecifiedState, StateSpec } from './createSpecifiedState.ts';
|
|
7
|
+
type MutableKeyOf<Spec extends StateSpec> = {
|
|
8
|
+
[K in string & keyof Spec]: Spec[K] extends MutablePropertySpec<any> ? K : never;
|
|
9
|
+
}[string & keyof Spec];
|
|
10
|
+
type SetEnginePropertyState<Spec extends StateSpec> = <K extends MutableKeyOf<Spec>>(key: K, newValue: SpecifiedState<Spec>[K]) => SpecifiedState<Spec>[K];
|
|
11
|
+
export interface SharedNodeState<Spec extends StateSpec> {
|
|
12
|
+
readonly spec: Spec;
|
|
13
|
+
readonly engineState: EngineState<Spec>;
|
|
14
|
+
readonly clientState: ClientState<Spec>;
|
|
15
|
+
readonly currentState: CurrentState<Spec>;
|
|
16
|
+
readonly setProperty: SetEnginePropertyState<Spec>;
|
|
17
|
+
}
|
|
18
|
+
interface SharedNodeStateOptions<Factory extends OpaqueReactiveObjectFactory, Spec extends StateSpec> {
|
|
19
|
+
readonly clientStateFactory: SpecifiedClientStateFactory<Factory, Spec>;
|
|
20
|
+
}
|
|
21
|
+
export declare const createSharedNodeState: <Factory extends OpaqueReactiveObjectFactory, Spec extends StateSpec>(scope: ReactiveScope, spec: Spec, options: SharedNodeStateOptions<Factory, Spec>) => SharedNodeState<Spec>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { StatePropertySpec } from './createSpecifiedState.ts';
|
|
2
|
+
export interface SpecifiedPropertyDescriptor<T = any> extends TypedPropertyDescriptor<T> {
|
|
3
|
+
readonly configurable: true;
|
|
4
|
+
readonly enumerable: true;
|
|
5
|
+
}
|
|
6
|
+
export declare const createSpecifiedPropertyDescriptor: <T>(propertySpec: StatePropertySpec<T>) => SpecifiedPropertyDescriptor<T>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { Accessor, Signal } from 'solid-js';
|
|
2
|
+
import type { SimpleAtomicState } from '../types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Specifies a state object's property as mutable. Basic usage:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { createSignal } from 'solid-js';
|
|
8
|
+
*
|
|
9
|
+
* const count = createSignal(1);
|
|
10
|
+
*
|
|
11
|
+
* const state = createSpecifiedState({ count });
|
|
12
|
+
* // ^? { count: number }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* While basic usage involves passing a Solid {@link Signal}, a
|
|
16
|
+
* {@link SimpleAtomicState} type is also supported, allowing a slightly more
|
|
17
|
+
* permissive setter type.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link SimpleAtomicState} and its related types for more detail.
|
|
20
|
+
*
|
|
21
|
+
* A property specified with this type will be used to define a reactively
|
|
22
|
+
* mutable property on the resulting state object where:
|
|
23
|
+
*
|
|
24
|
+
* - Reading the property will read its value from the provided spec's getter
|
|
25
|
+
* function, establishing an internally reactive subscription.
|
|
26
|
+
*
|
|
27
|
+
* - Mutating the property will pass the assigned value to the provided spec's
|
|
28
|
+
* setter function, triggering any downstream computations—whether that
|
|
29
|
+
* computation is associated with the provided spec itself, or reads from the
|
|
30
|
+
* derived property.
|
|
31
|
+
*
|
|
32
|
+
* - All such mutations will be propagated to any derived (client) state object.
|
|
33
|
+
*/
|
|
34
|
+
export type MutablePropertySpec<T> = SimpleAtomicState<T> | Signal<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Specifies a state object's property as reactively computed, and read-only.
|
|
37
|
+
* Basic usage:
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { createMemo, createSignal } from 'solid-js';
|
|
41
|
+
*
|
|
42
|
+
* const [count, setCount] = createSignal(1);
|
|
43
|
+
* const doubleCount = createMemo(() => count() * 2);
|
|
44
|
+
*
|
|
45
|
+
* const state = createSpecifiedState({ doubleCount });
|
|
46
|
+
* // ^? { readonly doubleCount: number }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* Note: ideally, the produced type would better reflect the computed nature of
|
|
50
|
+
* the resulting property. Unfortunately this isn't currently supported by the
|
|
51
|
+
* TypeScript type system (by inferring the derived state type). This tradeoff
|
|
52
|
+
* is reasonable for internal engine use, but should not be used to derive types
|
|
53
|
+
* which will be directly consumed by clients.
|
|
54
|
+
*
|
|
55
|
+
* Any property specified by a thunk (zero-argument function) is supported. A
|
|
56
|
+
* property specified with this type will be used to define a reactively
|
|
57
|
+
* readable property on the resulting state object where:
|
|
58
|
+
*
|
|
59
|
+
* - Reading the property will read its value on each access, establishing an
|
|
60
|
+
* internally reactive subscription (presuming the input property spec is
|
|
61
|
+
* itself reactive).
|
|
62
|
+
*
|
|
63
|
+
* - Mutating the property will throw a {@link TypeError}, just as it would when
|
|
64
|
+
* attempting to mutate a normal `get` accessor.
|
|
65
|
+
*
|
|
66
|
+
* - Any change which would result in a reactive update in the property spec
|
|
67
|
+
* itself will be propagated to any derived (client) state object.
|
|
68
|
+
*/
|
|
69
|
+
export type ComputedPropertySpec<T> = Accessor<T>;
|
|
70
|
+
/**
|
|
71
|
+
* @see {@link StaticPropertySpec}
|
|
72
|
+
*/
|
|
73
|
+
type NonStaticValue = Function | Signal<any> | SimpleAtomicState<any>;
|
|
74
|
+
/**
|
|
75
|
+
* Specifies a state object's property with a static value, immutable for the
|
|
76
|
+
* lifetime of that state object. Basic usage:
|
|
77
|
+
*
|
|
78
|
+
* ```ts
|
|
79
|
+
* const state = createSpecifiedState({ num: 10 });
|
|
80
|
+
* // ^? { readonly num: number }
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* Properties will be specified as static when they are none of:
|
|
84
|
+
*
|
|
85
|
+
* - {@link MutablePropertySpec}
|
|
86
|
+
* - {@link ComputedPropertySpec}
|
|
87
|
+
* - Any function with a non-zero arity (which are not supported for specifying
|
|
88
|
+
* a state object's properties at all)
|
|
89
|
+
*
|
|
90
|
+
* Any property so specified will produce a property where:
|
|
91
|
+
*
|
|
92
|
+
* - Reading the property will produce the provided static value.
|
|
93
|
+
*
|
|
94
|
+
* - Mutating the property will throw a {@link TypeError}, just as it would when
|
|
95
|
+
* attempting to mutate a normal `get` accessor (or a
|
|
96
|
+
* {@link PropertyDescriptor} with `writable: false`).
|
|
97
|
+
*
|
|
98
|
+
* - The property will reflect the same static value on any derived (client)
|
|
99
|
+
* state object.
|
|
100
|
+
*/
|
|
101
|
+
export type StaticPropertySpec<T> = Exclude<T, NonStaticValue>;
|
|
102
|
+
/**
|
|
103
|
+
* Every state property may be specified with any of these types:
|
|
104
|
+
*
|
|
105
|
+
* - {@link MutablePropertySpec}
|
|
106
|
+
* - {@link ComputedPropertySpec}
|
|
107
|
+
* - {@link StaticPropertySpec}
|
|
108
|
+
*/
|
|
109
|
+
export type StatePropertySpec<T = any> = MutablePropertySpec<T> | ComputedPropertySpec<T> | StaticPropertySpec<T>;
|
|
110
|
+
export declare const isMutablePropertySpec: <T>(propertySpec: StatePropertySpec<T>) => propertySpec is MutablePropertySpec<T>;
|
|
111
|
+
export declare const isComputedPropertySpec: <T>(propertySpec: StatePropertySpec<T>) => propertySpec is ComputedPropertySpec<T>;
|
|
112
|
+
export declare const isStaticPropertySpec: <T>(propertySpec: StatePropertySpec<T>) => propertySpec is Exclude<T, NonStaticValue>;
|
|
113
|
+
export type StateSpec = Record<string, StatePropertySpec>;
|
|
114
|
+
type SpecifiedStatePropertyValue<PropertySpec extends StatePropertySpec> = PropertySpec extends StatePropertySpec<infer T> ? T : never;
|
|
115
|
+
type DerivedMutableKeys<Spec extends StateSpec> = {
|
|
116
|
+
[K in keyof Spec]: Spec[K] extends MutablePropertySpec<any> ? K : never;
|
|
117
|
+
}[keyof Spec];
|
|
118
|
+
type DerivedMutableState<Spec extends StateSpec> = {
|
|
119
|
+
-readonly [K in DerivedMutableKeys<Spec>]: SpecifiedStatePropertyValue<Spec[K]>;
|
|
120
|
+
};
|
|
121
|
+
type DerivedReadableKeys<Spec extends StateSpec> = Exclude<keyof Spec, DerivedMutableKeys<Spec>>;
|
|
122
|
+
type DerivedReadableState<Spec extends StateSpec> = {
|
|
123
|
+
readonly [K in DerivedReadableKeys<Spec>]: SpecifiedStatePropertyValue<Spec[K]>;
|
|
124
|
+
};
|
|
125
|
+
export type SpecifiedState<Spec extends StateSpec> = (DerivedMutableState<Spec> & DerivedReadableState<Spec>) extends infer DerivedState ? {
|
|
126
|
+
[K in keyof Spec]: K extends keyof DerivedState ? DerivedState[K] : never;
|
|
127
|
+
} : never;
|
|
128
|
+
/**
|
|
129
|
+
* Produces an (internally) reactive object whose properties may be a mix of:
|
|
130
|
+
*
|
|
131
|
+
* - {@link MutablePropertySpec | mutable} (atomically reactive when mutated by
|
|
132
|
+
* engine internal logic; reactively propagated as read-only to clients)
|
|
133
|
+
* - {@link ComputedPropertySpec | computed} (read-only, reactive to changes in
|
|
134
|
+
* derived state; reactively propagated as read-only to clients)
|
|
135
|
+
* - {@link StaticPropertySpec | static} (read-only, immutable after creation;
|
|
136
|
+
* statically propagated as read-only to clients)
|
|
137
|
+
*/
|
|
138
|
+
export declare const createSpecifiedState: <Spec extends StateSpec>(spec: Spec) => SpecifiedState<Spec>;
|
|
139
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ShallowMutable } from '../../../../../common/types/helpers.js';
|
|
2
|
+
declare const ENGINE_REPRESENTATION: unique symbol;
|
|
3
|
+
type ENGINE_REPRESENTATION = typeof ENGINE_REPRESENTATION;
|
|
4
|
+
declare const INTERNAL_CLIENT_REPRESENTATION: unique symbol;
|
|
5
|
+
type INTERNAL_CLIENT_REPRESENTATION = typeof INTERNAL_CLIENT_REPRESENTATION;
|
|
6
|
+
declare const READONLY_CLIENT_REPRESENTATION: unique symbol;
|
|
7
|
+
type READONLY_CLIENT_REPRESENTATION = typeof READONLY_CLIENT_REPRESENTATION;
|
|
8
|
+
type RepresentationType = ENGINE_REPRESENTATION | INTERNAL_CLIENT_REPRESENTATION | READONLY_CLIENT_REPRESENTATION;
|
|
9
|
+
type TypedRepresentation<Type extends RepresentationType, T> = T & {
|
|
10
|
+
readonly [K in RepresentationType]?: K extends Type ? K : never;
|
|
11
|
+
};
|
|
12
|
+
export type EngineRepresentation<T extends object> = TypedRepresentation<ENGINE_REPRESENTATION, ShallowMutable<T>>;
|
|
13
|
+
export declare const declareEngineRepresentation: <T extends object>(stateObject: T) => EngineRepresentation<T>;
|
|
14
|
+
export type InternalClientRepresentation<T extends object> = TypedRepresentation<INTERNAL_CLIENT_REPRESENTATION, ShallowMutable<T>>;
|
|
15
|
+
export declare const declareInternalClientRepresentation: <T extends object>(stateObject: T) => InternalClientRepresentation<T>;
|
|
16
|
+
export type ReadonlyClientRepresentation<T> = TypedRepresentation<READONLY_CLIENT_REPRESENTATION, T>;
|
|
17
|
+
/**
|
|
18
|
+
* Provides a static type mechanism to reduce the chance of mistakenly assigning
|
|
19
|
+
* one state representation to another (e.g. `engineState = clientState` or
|
|
20
|
+
* `doSomethingWithCurrentState(engineState)`). Each representation is either
|
|
21
|
+
* fully or partially assignable to the other, but this bit of indirection should
|
|
22
|
+
* prevent that (unless one of the types is widened to {@link T}).
|
|
23
|
+
*/
|
|
24
|
+
export declare const declareReadonlyClientRepresentation: <T extends object>(stateObject: Readonly<T>) => ReadonlyClientRepresentation<T>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Owner } from 'solid-js';
|
|
2
|
+
type ReactiveScopeTask<T> = (scope: ReactiveScope) => T;
|
|
3
|
+
type RunReactiveScopeTask = <T>(task: ReactiveScopeTask<T>) => T;
|
|
4
|
+
export interface ReactiveScope {
|
|
5
|
+
readonly owner: Owner;
|
|
6
|
+
readonly dispose: VoidFunction;
|
|
7
|
+
readonly runTask: RunReactiveScopeTask;
|
|
8
|
+
}
|
|
9
|
+
interface CreateReactiveScopeOptions {
|
|
10
|
+
readonly owner?: Owner | null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates a reactive scope for internal engine use. This currently uses Solid's
|
|
14
|
+
* implementation of reactivity, and makes no attempt to obscure that. As such,
|
|
15
|
+
* all of the terms and types exposed are intentionally direct references to
|
|
16
|
+
* their concepts in Solid.
|
|
17
|
+
*
|
|
18
|
+
* This reactive scope is suitable for isolating reactivity between tests. It is
|
|
19
|
+
* also suitable for scoping reactivity for nodes in engine/client state, as
|
|
20
|
+
* well as creating nested scopes for their descendants.
|
|
21
|
+
*/
|
|
22
|
+
export declare const createReactiveScope: (options?: CreateReactiveScopeOptions) => ReactiveScope;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Accessor } from 'solid-js';
|
|
2
|
+
import type { EvaluationContext } from '../../../instance/internal-api/EvaluationContext.ts';
|
|
3
|
+
import { TextRange } from '../../../instance/text/TextRange.ts';
|
|
4
|
+
import type { ValueNodeDefinition } from '../../../model/ValueNodeDefinition.ts';
|
|
5
|
+
export declare const createFieldHint: (context: EvaluationContext, definition: ValueNodeDefinition) => Accessor<TextRange<'hint'> | null>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Accessor } from 'solid-js';
|
|
2
|
+
import type { EvaluationContext } from '../../../instance/internal-api/EvaluationContext.ts';
|
|
3
|
+
import { TextRange } from '../../../instance/text/TextRange.ts';
|
|
4
|
+
import type { AnyNodeDefinition } from '../../../model/NodeDefinition.ts';
|
|
5
|
+
export declare const createNodeLabel: (context: EvaluationContext, definition: AnyNodeDefinition) => Accessor<TextRange<'label'> | null>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Accessor } from 'solid-js';
|
|
2
|
+
import type { TextElementDefinition } from '../../../body/text/TextElementDefinition.ts';
|
|
3
|
+
import type { EvaluationContext } from '../../../instance/internal-api/EvaluationContext.ts';
|
|
4
|
+
import { TextRange, type TextRole } from '../../../instance/text/TextRange.ts';
|
|
5
|
+
interface CreateTextRangeOptions<FallbackValue extends string | null> {
|
|
6
|
+
readonly fallbackValue?: FallbackValue;
|
|
7
|
+
}
|
|
8
|
+
type ComputedTextRange<Role extends TextRole, Definition extends TextElementDefinition<Role> | null, FallbackValue extends string | null> = Accessor<Definition extends null ? FallbackValue extends null ? TextRange<Role> | null : TextRange<Role> : TextRange<Role>>;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a text range (e.g. label or hint) from the provided definition,
|
|
11
|
+
* reactive to:
|
|
12
|
+
*
|
|
13
|
+
* - The form's current language (e.g. `<label ref="jr:itext('text-id')" />`)
|
|
14
|
+
* - Direct `<output>` references within the label's children
|
|
15
|
+
*
|
|
16
|
+
* @todo This does not yet handle itext translations **with** outputs!
|
|
17
|
+
*/
|
|
18
|
+
export declare const createTextRange: <Role extends TextRole, Definition extends TextElementDefinition<Role> | null, FallbackValue extends string | null = null>(context: EvaluationContext, role: Role, definition: Definition, options?: CreateTextRangeOptions<FallbackValue> | undefined) => ComputedTextRange<Role, Definition, FallbackValue>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Accessor, Setter } from 'solid-js';
|
|
2
|
+
/**
|
|
3
|
+
* A write interface to reactive atomic state. This type is intended to be used
|
|
4
|
+
* as a relaxed version of {@link Setter}, where its callback form isn't
|
|
5
|
+
* required for conforming implementations.
|
|
6
|
+
*/
|
|
7
|
+
export type SimpleAtomicStateSetter<T> = (newValue: T) => T;
|
|
8
|
+
/**
|
|
9
|
+
* A read/write interface to reactive atomic state. This type is intended to be
|
|
10
|
+
* used as a relaxed version of {@link Signal}, with a
|
|
11
|
+
* {@link SimpleAtomicStateSetter | simpler setter type}.
|
|
12
|
+
*/
|
|
13
|
+
export type SimpleAtomicState<T> = readonly [
|
|
14
|
+
get: Accessor<T>,
|
|
15
|
+
set: SimpleAtomicStateSetter<T>
|
|
16
|
+
];
|
|
17
|
+
export type AtomicStateSetter<T> = Setter<T> | SimpleAtomicStateSetter<T>;
|
|
18
|
+
export type AtomicState<T> = readonly [
|
|
19
|
+
get: Accessor<T>,
|
|
20
|
+
set: AtomicStateSetter<T>
|
|
21
|
+
];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* **WARNING:** Uniqueness is not guaranteed across multiple sessions. Do not
|
|
3
|
+
* use IDs produced by this function in persistence scenarios, or where external
|
|
4
|
+
* interfaces expect stronger uniqueness guarantees.
|
|
5
|
+
*/
|
|
6
|
+
export type CreateUniqueId = () => string;
|
|
7
|
+
/**
|
|
8
|
+
* Where available, uses the
|
|
9
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API | Web Crypto API}'s
|
|
10
|
+
* {@link crypto.randomUUID | `randomUUID`}.
|
|
11
|
+
*
|
|
12
|
+
* Notes on supported environments:
|
|
13
|
+
*
|
|
14
|
+
* - Browsers: only available in a
|
|
15
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts | secure context}
|
|
16
|
+
* - Node: >= v19.0.0
|
|
17
|
+
* - Deno: >= 1.11
|
|
18
|
+
* - Bun: fully supported, unknown minimum version
|
|
19
|
+
*
|
|
20
|
+
* Where `randomUUID` is not supported, falls back to an internal implementation
|
|
21
|
+
* with weaker uniqueness constraints.
|
|
22
|
+
*
|
|
23
|
+
* **WARNING:** Uniqueness is not guaranteed across multiple sessions. Do not
|
|
24
|
+
* use IDs produced by this function in persistence scenarios, or where external
|
|
25
|
+
* interfaces expect stronger uniqueness guarantees.
|
|
26
|
+
*/
|
|
27
|
+
export declare const createUniqueId: CreateUniqueId;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AnySyntaxNode } from '@getodk/xpath/static/grammar/SyntaxNode.js';
|
|
2
|
+
export type SingleChildNode = Extract<AnySyntaxNode, {
|
|
3
|
+
readonly children: readonly [AnySyntaxNode];
|
|
4
|
+
}>;
|
|
5
|
+
export declare const isItextFunctionCalled: (expression: string) => boolean;
|
|
6
|
+
interface GetNodesetDependenciesOptions {
|
|
7
|
+
readonly contextReference?: string | null;
|
|
8
|
+
/**
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
readonly ignoreContextReference?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Ignores location path sub-expressions whose full text is `null`. While this
|
|
14
|
+
* is technically a valid relative name test step, it seems that real forms in
|
|
15
|
+
* the wild use it as if XPath had an actual `null` token/value.
|
|
16
|
+
*
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
readonly ignoreNullExpressions?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare const getNodesetDependencies: (expression: string, options?: GetNodesetDependenciesOptions) => Set<string>;
|
|
22
|
+
export {};
|