@getodk/xforms-engine 0.8.0 → 0.10.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/InputNode.d.ts +4 -2
- package/dist/client/NoteNode.d.ts +4 -2
- package/dist/client/SelectNode.d.ts +1 -0
- package/dist/client/TextRange.d.ts +4 -0
- package/dist/index.js +14474 -28463
- package/dist/index.js.map +1 -1
- package/dist/instance/SelectControl.d.ts +1 -0
- package/dist/instance/text/TextRange.d.ts +11 -1
- package/dist/integration/xpath/adapter/traversal.d.ts +2 -2
- package/dist/lib/codecs/DateValueCodec.d.ts +7 -0
- package/dist/lib/codecs/getSharedValueCodec.d.ts +3 -2
- package/dist/lib/reactivity/text/createTextRange.d.ts +1 -2
- package/dist/parse/expression/TextChunkExpression.d.ts +16 -0
- package/dist/parse/text/ItemsetLabelDefinition.d.ts +2 -4
- package/dist/parse/text/MessageDefinition.d.ts +3 -7
- package/dist/parse/text/abstract/TextElementDefinition.d.ts +2 -8
- package/dist/parse/text/abstract/TextRangeDefinition.d.ts +2 -2
- package/dist/solid.js +14474 -28463
- package/dist/solid.js.map +1 -1
- package/package.json +4 -3
- package/src/client/InputNode.ts +4 -0
- package/src/client/NoteNode.ts +4 -0
- package/src/client/SelectNode.ts +2 -0
- package/src/client/TextRange.ts +5 -1
- package/src/instance/SelectControl.ts +6 -0
- package/src/instance/text/TextRange.ts +21 -1
- package/src/integration/xpath/adapter/traversal.ts +4 -2
- package/src/lib/codecs/DateValueCodec.ts +94 -0
- package/src/lib/codecs/getSharedValueCodec.ts +5 -3
- package/src/lib/reactivity/text/createTextRange.ts +56 -43
- package/src/lib/reactivity/validation/createValidation.ts +1 -3
- package/src/parse/expression/TextChunkExpression.ts +78 -0
- package/src/parse/text/ItemsetLabelDefinition.ts +8 -12
- package/src/parse/text/MessageDefinition.ts +9 -16
- package/src/parse/text/abstract/TextElementDefinition.ts +10 -26
- package/src/parse/text/abstract/TextRangeDefinition.ts +2 -2
- package/src/parse/xpath/semantic-analysis.ts +7 -2
- package/dist/parse/expression/TextLiteralExpression.d.ts +0 -9
- package/dist/parse/expression/TextOutputExpression.d.ts +0 -7
- package/dist/parse/expression/TextReferenceExpression.d.ts +0 -7
- package/dist/parse/expression/TextTranslationExpression.d.ts +0 -8
- package/dist/parse/expression/abstract/TextChunkExpression.d.ts +0 -17
- package/src/parse/expression/TextLiteralExpression.ts +0 -19
- package/src/parse/expression/TextOutputExpression.ts +0 -25
- package/src/parse/expression/TextReferenceExpression.ts +0 -14
- package/src/parse/expression/TextTranslationExpression.ts +0 -38
- package/src/parse/expression/abstract/TextChunkExpression.ts +0 -38
|
@@ -2,10 +2,7 @@ import { isElementNode, isTextNode } from '@getodk/common/lib/dom/predicates.ts'
|
|
|
2
2
|
import type { ElementTextRole } from '../../../client/TextRange.ts';
|
|
3
3
|
import type { XFormDefinition } from '../../../parse/XFormDefinition.ts';
|
|
4
4
|
import type { ItemDefinition } from '../../body/control/ItemDefinition.ts';
|
|
5
|
-
import {
|
|
6
|
-
import { TextOutputExpression } from '../../expression/TextOutputExpression.ts';
|
|
7
|
-
import { TextReferenceExpression } from '../../expression/TextReferenceExpression.ts';
|
|
8
|
-
import { TextTranslationExpression } from '../../expression/TextTranslationExpression.ts';
|
|
5
|
+
import { TextChunkExpression } from '../../expression/TextChunkExpression.ts';
|
|
9
6
|
import { parseNodesetReference } from '../../xpath/reference-parsing.ts';
|
|
10
7
|
import type { HintDefinition } from '../HintDefinition.ts';
|
|
11
8
|
import type { ItemLabelDefinition } from '../ItemLabelDefinition.ts';
|
|
@@ -14,27 +11,12 @@ import type { LabelDefinition, LabelOwner } from '../LabelDefinition.ts';
|
|
|
14
11
|
import type { TextSourceNode } from './TextRangeDefinition.ts';
|
|
15
12
|
import { TextRangeDefinition } from './TextRangeDefinition.ts';
|
|
16
13
|
|
|
17
|
-
// prettier-ignore
|
|
18
|
-
export type RefAttributeChunk =
|
|
19
|
-
| TextReferenceExpression
|
|
20
|
-
| TextTranslationExpression;
|
|
21
|
-
|
|
22
|
-
// prettier-ignore
|
|
23
|
-
type TextElementChildChunk =
|
|
24
|
-
| TextOutputExpression
|
|
25
|
-
| TextLiteralExpression;
|
|
26
|
-
|
|
27
|
-
// prettier-ignore
|
|
28
|
-
type TextElementChunks =
|
|
29
|
-
| readonly [RefAttributeChunk]
|
|
30
|
-
| readonly TextElementChildChunk[];
|
|
31
|
-
|
|
32
14
|
type TextElementOwner = ItemDefinition | LabelOwner;
|
|
33
15
|
|
|
34
16
|
export abstract class TextElementDefinition<
|
|
35
17
|
Role extends ElementTextRole,
|
|
36
18
|
> extends TextRangeDefinition<Role> {
|
|
37
|
-
readonly chunks:
|
|
19
|
+
readonly chunks: ReadonlyArray<TextChunkExpression<'nodes' | 'string'>>;
|
|
38
20
|
|
|
39
21
|
constructor(form: XFormDefinition, owner: TextElementOwner, sourceNode: TextSourceNode<Role>) {
|
|
40
22
|
super(form, owner, sourceNode);
|
|
@@ -45,20 +27,22 @@ export abstract class TextElementDefinition<
|
|
|
45
27
|
if (refExpression == null) {
|
|
46
28
|
this.chunks = Array.from(sourceNode.childNodes).flatMap((childNode) => {
|
|
47
29
|
if (isElementNode(childNode)) {
|
|
48
|
-
return
|
|
30
|
+
return TextChunkExpression.fromOutput(context, childNode) ?? [];
|
|
49
31
|
}
|
|
50
32
|
|
|
51
33
|
if (isTextNode(childNode)) {
|
|
52
|
-
return
|
|
34
|
+
return TextChunkExpression.fromLiteral(context, childNode.data);
|
|
53
35
|
}
|
|
54
36
|
|
|
55
37
|
return [];
|
|
56
38
|
});
|
|
57
39
|
} else {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
40
|
+
const expression = TextChunkExpression.fromTranslation(context, refExpression);
|
|
41
|
+
if (expression != null) {
|
|
42
|
+
this.chunks = [expression];
|
|
43
|
+
} else {
|
|
44
|
+
this.chunks = [TextChunkExpression.fromReference(context, refExpression)];
|
|
45
|
+
}
|
|
62
46
|
}
|
|
63
47
|
}
|
|
64
48
|
}
|
|
@@ -2,7 +2,7 @@ import type { LocalNamedElement } from '@getodk/common/types/dom.ts';
|
|
|
2
2
|
import type { TextRole } from '../../../client/TextRange.ts';
|
|
3
3
|
import type { XFormDefinition } from '../../../parse/XFormDefinition.ts';
|
|
4
4
|
import { DependencyContext } from '../../expression/abstract/DependencyContext.ts';
|
|
5
|
-
import type {
|
|
5
|
+
import type { TextChunkExpression } from '../../expression/TextChunkExpression.ts';
|
|
6
6
|
import type { AnyMessageDefinition } from '../MessageDefinition.ts';
|
|
7
7
|
import type { AnyTextElementDefinition } from './TextElementDefinition.ts';
|
|
8
8
|
|
|
@@ -24,7 +24,7 @@ export abstract class TextRangeDefinition<Role extends TextRole> extends Depende
|
|
|
24
24
|
readonly parentReference: string | null;
|
|
25
25
|
readonly reference: string | null;
|
|
26
26
|
|
|
27
|
-
abstract readonly chunks:
|
|
27
|
+
abstract readonly chunks: ReadonlyArray<TextChunkExpression<'nodes' | 'string'>>;
|
|
28
28
|
|
|
29
29
|
override get isTranslated(): boolean {
|
|
30
30
|
return (
|
|
@@ -117,9 +117,14 @@ export type TranslationExpression = LocalNamedFunctionCallLiteral<'itext'>;
|
|
|
117
117
|
export const isTranslationExpression = (
|
|
118
118
|
expression: string
|
|
119
119
|
): expression is TranslationExpression => {
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
let result;
|
|
121
|
+
try {
|
|
122
|
+
result = expressionParser.parse(expression);
|
|
123
|
+
} catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
122
126
|
|
|
127
|
+
const functionCallNode = findTypedPrincipalExpressionNode(['function_call'], result.rootNode);
|
|
123
128
|
if (functionCallNode == null) {
|
|
124
129
|
return false;
|
|
125
130
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AnyTextRangeDefinition } from '../text/abstract/TextRangeDefinition.ts';
|
|
2
|
-
import { TextChunkExpression } from './abstract/TextChunkExpression.ts';
|
|
3
|
-
export type TextLiteralSourceNode = Attr | Text;
|
|
4
|
-
export declare class TextLiteralExpression extends TextChunkExpression<'literal'> {
|
|
5
|
-
readonly stringValue: string;
|
|
6
|
-
static from(context: AnyTextRangeDefinition, stringValue: string): TextLiteralExpression;
|
|
7
|
-
readonly source = "literal";
|
|
8
|
-
private constructor();
|
|
9
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AnyTextRangeDefinition } from '../text/abstract/TextRangeDefinition.ts';
|
|
2
|
-
import { TextChunkExpression } from './abstract/TextChunkExpression.ts';
|
|
3
|
-
export declare class TextOutputExpression extends TextChunkExpression<'output'> {
|
|
4
|
-
static from(context: AnyTextRangeDefinition, element: Element): TextOutputExpression | null;
|
|
5
|
-
readonly source = "output";
|
|
6
|
-
private constructor();
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AnyTextRangeDefinition } from '../text/abstract/TextRangeDefinition.ts';
|
|
2
|
-
import { TextChunkExpression } from './abstract/TextChunkExpression.ts';
|
|
3
|
-
export declare class TextReferenceExpression extends TextChunkExpression<'reference'> {
|
|
4
|
-
static from(context: AnyTextRangeDefinition, refExpression: string): TextReferenceExpression;
|
|
5
|
-
readonly source = "reference";
|
|
6
|
-
private constructor();
|
|
7
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { AnyTextRangeDefinition } from '../text/abstract/TextRangeDefinition.ts';
|
|
2
|
-
import { TextChunkExpression } from './abstract/TextChunkExpression.ts';
|
|
3
|
-
export declare class TextTranslationExpression extends TextChunkExpression<'translation'> {
|
|
4
|
-
static fromMessage(context: AnyTextRangeDefinition, maybeExpression: string): TextTranslationExpression | null;
|
|
5
|
-
static from(context: AnyTextRangeDefinition, maybeExpression: string): TextTranslationExpression | null;
|
|
6
|
-
readonly source = "translation";
|
|
7
|
-
private constructor();
|
|
8
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { TextChunkSource } from '../../../client/TextRange.ts';
|
|
2
|
-
import { AnyTextRangeDefinition } from '../../text/abstract/TextRangeDefinition.ts';
|
|
3
|
-
import { TextLiteralExpression } from '../TextLiteralExpression.ts';
|
|
4
|
-
import { TextOutputExpression } from '../TextOutputExpression.ts';
|
|
5
|
-
import { TextReferenceExpression } from '../TextReferenceExpression.ts';
|
|
6
|
-
import { TextTranslationExpression } from '../TextTranslationExpression.ts';
|
|
7
|
-
import { DependentExpression } from './DependentExpression.ts';
|
|
8
|
-
interface TextChunkExpressionOptions {
|
|
9
|
-
readonly isTranslated?: true;
|
|
10
|
-
}
|
|
11
|
-
export declare abstract class TextChunkExpression<Source extends TextChunkSource> extends DependentExpression<'string'> {
|
|
12
|
-
abstract readonly source: Source;
|
|
13
|
-
readonly stringValue?: string;
|
|
14
|
-
constructor(context: AnyTextRangeDefinition, expression: string, options?: TextChunkExpressionOptions);
|
|
15
|
-
}
|
|
16
|
-
export type AnyTextChunkExpression = TextLiteralExpression | TextOutputExpression | TextReferenceExpression | TextTranslationExpression;
|
|
17
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { AnyTextRangeDefinition } from '../text/abstract/TextRangeDefinition.ts';
|
|
2
|
-
import { TextChunkExpression } from './abstract/TextChunkExpression.ts';
|
|
3
|
-
|
|
4
|
-
export type TextLiteralSourceNode = Attr | Text;
|
|
5
|
-
|
|
6
|
-
export class TextLiteralExpression extends TextChunkExpression<'literal'> {
|
|
7
|
-
static from(context: AnyTextRangeDefinition, stringValue: string): TextLiteralExpression {
|
|
8
|
-
return new this(context, stringValue);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
readonly source = 'literal';
|
|
12
|
-
|
|
13
|
-
private constructor(
|
|
14
|
-
context: AnyTextRangeDefinition,
|
|
15
|
-
override readonly stringValue: string
|
|
16
|
-
) {
|
|
17
|
-
super(context, 'null');
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { KnownAttributeLocalNamedElement } from '@getodk/common/types/dom.ts';
|
|
2
|
-
import type { AnyTextRangeDefinition } from '../text/abstract/TextRangeDefinition.ts';
|
|
3
|
-
import { TextChunkExpression } from './abstract/TextChunkExpression.ts';
|
|
4
|
-
|
|
5
|
-
interface OutputElement extends KnownAttributeLocalNamedElement<'output', 'value'> {}
|
|
6
|
-
|
|
7
|
-
const isOutputElement = (element: Element): element is OutputElement => {
|
|
8
|
-
return element.localName === 'output' && element.hasAttribute('value');
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export class TextOutputExpression extends TextChunkExpression<'output'> {
|
|
12
|
-
static from(context: AnyTextRangeDefinition, element: Element): TextOutputExpression | null {
|
|
13
|
-
if (isOutputElement(element)) {
|
|
14
|
-
return new this(context, element);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
readonly source = 'output';
|
|
21
|
-
|
|
22
|
-
private constructor(context: AnyTextRangeDefinition, element: OutputElement) {
|
|
23
|
-
super(context, element.getAttribute('value'));
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { AnyTextRangeDefinition } from '../text/abstract/TextRangeDefinition.ts';
|
|
2
|
-
import { TextChunkExpression } from './abstract/TextChunkExpression.ts';
|
|
3
|
-
|
|
4
|
-
export class TextReferenceExpression extends TextChunkExpression<'reference'> {
|
|
5
|
-
static from(context: AnyTextRangeDefinition, refExpression: string): TextReferenceExpression {
|
|
6
|
-
return new this(context, refExpression);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
readonly source = 'reference';
|
|
10
|
-
|
|
11
|
-
private constructor(context: AnyTextRangeDefinition, refExpression: string) {
|
|
12
|
-
super(context, refExpression);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { expressionParser } from '@getodk/xpath/expressionParser.js';
|
|
2
|
-
import type { AnyTextRangeDefinition } from '../text/abstract/TextRangeDefinition.ts';
|
|
3
|
-
import type { TranslationExpression } from '../xpath/semantic-analysis.ts';
|
|
4
|
-
import { isTranslationExpression } from '../xpath/semantic-analysis.ts';
|
|
5
|
-
import { TextChunkExpression } from './abstract/TextChunkExpression.ts';
|
|
6
|
-
|
|
7
|
-
export class TextTranslationExpression extends TextChunkExpression<'translation'> {
|
|
8
|
-
static fromMessage(
|
|
9
|
-
context: AnyTextRangeDefinition,
|
|
10
|
-
maybeExpression: string
|
|
11
|
-
): TextTranslationExpression | null {
|
|
12
|
-
try {
|
|
13
|
-
expressionParser.parse(maybeExpression);
|
|
14
|
-
} catch {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (isTranslationExpression(maybeExpression)) {
|
|
19
|
-
return new this(context, maybeExpression);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static from(context: AnyTextRangeDefinition, maybeExpression: string) {
|
|
26
|
-
if (isTranslationExpression(maybeExpression)) {
|
|
27
|
-
return new this(context, maybeExpression);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
readonly source = 'translation';
|
|
34
|
-
|
|
35
|
-
private constructor(context: AnyTextRangeDefinition, expression: TranslationExpression) {
|
|
36
|
-
super(context, expression, { isTranslated: true });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { TextChunkSource } from '../../../client/TextRange.ts';
|
|
2
|
-
import type { AnyTextRangeDefinition } from '../../text/abstract/TextRangeDefinition.ts';
|
|
3
|
-
import type { TextLiteralExpression } from '../TextLiteralExpression.ts';
|
|
4
|
-
import type { TextOutputExpression } from '../TextOutputExpression.ts';
|
|
5
|
-
import type { TextReferenceExpression } from '../TextReferenceExpression.ts';
|
|
6
|
-
import type { TextTranslationExpression } from '../TextTranslationExpression.ts';
|
|
7
|
-
import { DependentExpression } from './DependentExpression.ts';
|
|
8
|
-
|
|
9
|
-
interface TextChunkExpressionOptions {
|
|
10
|
-
readonly isTranslated?: true;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export abstract class TextChunkExpression<
|
|
14
|
-
Source extends TextChunkSource,
|
|
15
|
-
> extends DependentExpression<'string'> {
|
|
16
|
-
abstract readonly source: Source;
|
|
17
|
-
readonly stringValue?: string;
|
|
18
|
-
|
|
19
|
-
constructor(
|
|
20
|
-
context: AnyTextRangeDefinition,
|
|
21
|
-
expression: string,
|
|
22
|
-
options: TextChunkExpressionOptions = {}
|
|
23
|
-
) {
|
|
24
|
-
super(context, 'string', expression, {
|
|
25
|
-
semanticDependencies: {
|
|
26
|
-
translations: options.isTranslated,
|
|
27
|
-
},
|
|
28
|
-
ignoreContextReference: true,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// prettier-ignore
|
|
34
|
-
export type AnyTextChunkExpression =
|
|
35
|
-
| TextLiteralExpression
|
|
36
|
-
| TextOutputExpression
|
|
37
|
-
| TextReferenceExpression
|
|
38
|
-
| TextTranslationExpression;
|