@ja-platform/parser-core 0.0.0-dev-20261105194022 → 0.0.0-dev-20261113191340
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/@types/attributes/TextAttribute.d.ts +9 -2
- package/dist/@types/index.d.ts +1 -1
- package/dist/@types/nodes/Node.d.ts +2 -2
- package/dist/@types/parsed/ParsedArrayNode.d.ts +3 -4
- package/dist/@types/parsed/ParsedContentNode.d.ts +3 -2
- package/dist/@types/parsed/ParsedEitherNode.d.ts +3 -2
- package/dist/@types/parsed/ParsedNode.d.ts +7 -19
- package/dist/@types/parsed/ParsedRecordNode.d.ts +3 -2
- package/dist/@types/values/ParsedNodeValues.d.ts +3 -5
- package/dist/@types/values/ParsedProviderValue.d.ts +4 -0
- package/dist/@types/values/ParsedValue.d.ts +3 -12
- package/dist/@types/values/ValueProviderContext.d.ts +5 -0
- package/dist/attributes/TextAttribute.js +18 -0
- package/dist/attributes/TextAttribute.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/nodes/Node.js +4 -5
- package/dist/nodes/Node.js.map +1 -1
- package/dist/parsed/ParsedArrayNode.js +2 -6
- package/dist/parsed/ParsedArrayNode.js.map +1 -1
- package/dist/parsed/ParsedContentNode.js +4 -4
- package/dist/parsed/ParsedContentNode.js.map +1 -1
- package/dist/parsed/ParsedEitherNode.js +3 -3
- package/dist/parsed/ParsedEitherNode.js.map +1 -1
- package/dist/parsed/ParsedNode.js +37 -66
- package/dist/parsed/ParsedNode.js.map +1 -1
- package/dist/parsed/ParsedRecordNode.js +3 -3
- package/dist/parsed/ParsedRecordNode.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/values/ParsedNodeValues.js +17 -53
- package/dist/values/ParsedNodeValues.js.map +1 -1
- package/dist/values/ParsedProviderValue.js +5 -1
- package/dist/values/ParsedProviderValue.js.map +1 -1
- package/dist/values/ParsedValue.js +4 -25
- package/dist/values/ParsedValue.js.map +1 -1
- package/dist/values/ValueProviderContext.js +3 -0
- package/dist/values/ValueProviderContext.js.map +1 -0
- package/package.json +6 -6
- package/dist/@types/attributes/ContentTextAttribute.d.ts +0 -16
- package/dist/attributes/ContentTextAttribute.js +0 -29
- package/dist/attributes/ContentTextAttribute.js.map +0 -1
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { AttributeParseEvent } from '../AttributeParseEvent';
|
|
2
|
-
import { Attribute, AttributeGenerics, AttributeOptions } from './Attribute';
|
|
2
|
+
import { Attribute, AttributeGenerics, AttributeOptions, StringifyDirective } from './Attribute';
|
|
3
|
+
import type { AttributeInput } from '../input/AttributeInput';
|
|
4
|
+
import type { NodeInput } from '../input/NodeInput';
|
|
5
|
+
import type { ParsedNode } from '../parsed/ParsedNode';
|
|
3
6
|
import { FormatStringExpression, ConstantExpression, EvaluatedExpression } from '@ja-platform/parser-expressions';
|
|
4
7
|
export type CombinedTextExpression = ConstantExpression<string> | FormatStringExpression | EvaluatedExpression;
|
|
5
|
-
export type TextAttributeOptions<Value = string> = AttributeOptions<Value, Value
|
|
8
|
+
export type TextAttributeOptions<Value = string> = AttributeOptions<Value, Value> & {
|
|
9
|
+
allowContentFromNode?: boolean;
|
|
10
|
+
};
|
|
6
11
|
export interface TextAttributeGenerics<Value = string> extends AttributeGenerics {
|
|
7
12
|
Value: CombinedTextExpression | null;
|
|
8
13
|
Options: TextAttributeOptions<Value>;
|
|
@@ -14,6 +19,8 @@ export declare class TextAttribute<T extends TextAttributeGenerics<unknown> = Te
|
|
|
14
19
|
static TYPE: string;
|
|
15
20
|
constructor(options: Options);
|
|
16
21
|
static isInstanceOf(attr: Attribute): attr is TextAttribute<TextAttributeGenerics<unknown>>;
|
|
22
|
+
protected getInput(node?: NodeInput): AttributeInput | undefined;
|
|
23
|
+
stringify(value: T['Value'], parent: ParsedNode): StringifyDirective;
|
|
17
24
|
protected getParsedValue(event: AttributeParseEvent): CombinedTextExpression | null;
|
|
18
25
|
protected validateInput(event: AttributeParseEvent, expression: CombinedTextExpression): void;
|
|
19
26
|
serialize(): any;
|
package/dist/@types/index.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export * from './attributes/Attribute';
|
|
|
5
5
|
export * from './attributes/BooleanAttribute';
|
|
6
6
|
export * from './attributes/ConstantBooleanAttribute';
|
|
7
7
|
export * from './attributes/ConstantTextAttribute';
|
|
8
|
-
export * from './attributes/ContentTextAttribute';
|
|
9
8
|
export * from './attributes/ExpressionAttribute';
|
|
10
9
|
export * from './attributes/FunctionAttribute';
|
|
11
10
|
export * from './attributes/ListAttribute';
|
|
@@ -41,3 +40,4 @@ export * from './source/SourceReference';
|
|
|
41
40
|
export * from './input/AttributeInput';
|
|
42
41
|
export * from './input/NodeInput';
|
|
43
42
|
export * from './input/AttributeParseContext';
|
|
43
|
+
export * from './values/ValueProviderContext';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ParseEvent } from '../ParseEvent';
|
|
2
2
|
import type { NodeInput, NodeInputSelector, NodeInputSelection } from '../input/NodeInput';
|
|
3
3
|
import { Attribute } from '../attributes/Attribute';
|
|
4
|
-
import {
|
|
4
|
+
import { TextAttribute, TextAttributeGenerics } from '../attributes/TextAttribute';
|
|
5
5
|
import { CommonEntity, CommonEntityGenerics, CommonEntityOptions } from '../entities/CommonEntity';
|
|
6
6
|
import { ParsedNode } from '../parsed/ParsedNode';
|
|
7
7
|
import { ParsedNodeShape } from '../parsed/ParsedNodeTypes';
|
|
@@ -73,7 +73,7 @@ export declare class Node<G extends NodeGenerics<any> = NodeGenerics<any>> exten
|
|
|
73
73
|
getNode(name: string): Node<any>;
|
|
74
74
|
getAttribute(name: string): Attribute;
|
|
75
75
|
removeAttribute(name: string): this;
|
|
76
|
-
getContentAttribute():
|
|
76
|
+
getContentAttribute(): TextAttribute<TextAttributeGenerics<unknown>> | null;
|
|
77
77
|
getTemplate(cursor?: string): {
|
|
78
78
|
template?: string;
|
|
79
79
|
templates?: {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
1
|
+
import { type ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
2
|
+
import type { ValueProviderContext } from '../values/ValueProviderContext';
|
|
2
3
|
import { ParsedExpressionValue } from './ParsedNodeTypes';
|
|
3
4
|
import { TreeNode } from '@journeyapps/common-tree';
|
|
4
5
|
import type { SourceReference } from '../source/SourceReference';
|
|
5
6
|
import { Node } from '../nodes/Node';
|
|
6
|
-
import { AbstractValueProvider } from '../values/AbstractValueProvider';
|
|
7
7
|
import { ParsedDiagnostic } from './ParsedDiagnostic';
|
|
8
8
|
import { ParsedNode } from './ParsedNode';
|
|
9
9
|
export interface ParsedArrayNodeOptions {
|
|
@@ -23,9 +23,8 @@ export declare class ParsedArrayNode<Child extends ParsedArrayNodeChild = Parsed
|
|
|
23
23
|
/**
|
|
24
24
|
* Resolve repeated children in order, preserving nested arrays.
|
|
25
25
|
*/
|
|
26
|
-
valueTree(): ParsedNodeValuesLike<ParsedExpressionValue<Child>[]>;
|
|
26
|
+
valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<ParsedExpressionValue<Child>[]>;
|
|
27
27
|
at(index: number): Child | undefined;
|
|
28
|
-
setValueProviders(providers: readonly AbstractValueProvider[]): this;
|
|
29
28
|
pushError({ message, source, type }: ParsedDiagnostic): ParsedDiagnostic;
|
|
30
29
|
errors(): ParsedDiagnostic[];
|
|
31
30
|
hasErrors(): boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { type ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
2
|
+
import type { ValueProviderContext } from '../values/ValueProviderContext';
|
|
1
3
|
import { ParsedNode } from './ParsedNode';
|
|
2
4
|
import { ParsedNodeShapeValue } from './ParsedNodeTypes';
|
|
3
|
-
import { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
4
5
|
export type ParsedContentNodeShape<Expression extends ParsedNodeShapeValue> = {
|
|
5
6
|
content?: Expression;
|
|
6
7
|
};
|
|
@@ -9,5 +10,5 @@ export type ParsedContentNodeShape<Expression extends ParsedNodeShapeValue> = {
|
|
|
9
10
|
*/
|
|
10
11
|
export declare class ParsedContentNode<Expression extends ParsedNodeShapeValue, Value> extends ParsedNode<ParsedContentNodeShape<Expression>, Value | undefined> {
|
|
11
12
|
content(): Expression | undefined;
|
|
12
|
-
valueTree(): ParsedNodeValuesLike<Value | undefined>;
|
|
13
|
+
valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<Value | undefined>;
|
|
13
14
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { type ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
2
|
+
import type { ValueProviderContext } from '../values/ValueProviderContext';
|
|
1
3
|
import { ParsedNode } from './ParsedNode';
|
|
2
4
|
import type { ParsedChild } from './ParsedNodeTypes';
|
|
3
|
-
import { type ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
4
5
|
/** Preserve the selected branch's value without adding an object to the output. */
|
|
5
6
|
export declare class ParsedEitherNode<Value> extends ParsedNode<{
|
|
6
7
|
value?: ParsedChild;
|
|
7
8
|
}, Value | undefined> {
|
|
8
|
-
valueTree(): ParsedNodeValuesLike<Value | undefined>;
|
|
9
|
+
valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<Value | undefined>;
|
|
9
10
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
1
|
+
import type { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
2
2
|
import { TreeNode, TreeNodeListener } from '@journeyapps/common-tree';
|
|
3
3
|
import { ParseEvent } from '../ParseEvent';
|
|
4
4
|
import type { NodeInput } from '../input/NodeInput';
|
|
@@ -7,8 +7,7 @@ import { ParsedAttribute } from './ParsedAttribute';
|
|
|
7
7
|
import { ParsedDiagnostic, ParsedValidationDiagnostic } from './ParsedDiagnostic';
|
|
8
8
|
import type { ValidationContext } from '@ja-platform/parser-expressions';
|
|
9
9
|
import { ParsedChild, ParsedChildNamesMarker, ParsedNodeAttribute, ParsedNodeAttributeShape, ParsedNodeAttributeName, ParsedNodeChild, ParsedNodeExpressionKey, ParsedNodeKnownChildKey, ParsedNodeValue, ParsedNodeValueRequest, ParsedNodeValueRequestKey, ParsedNodeRequiredAttributeName, ParsedNodeShape, ParsedNodeUntypedExpressionKey } from './ParsedNodeTypes';
|
|
10
|
-
import {
|
|
11
|
-
import { AbstractValueProvider } from '../values/AbstractValueProvider';
|
|
10
|
+
import type { ValueProviderContext } from '../values/ValueProviderContext';
|
|
12
11
|
export interface ParsedNodeOptions extends ParseEvent {
|
|
13
12
|
definition: Node<any>;
|
|
14
13
|
key?: string;
|
|
@@ -36,10 +35,8 @@ export interface ParsedNodeListener<Shape extends ParsedNodeShape = ParsedNodeSh
|
|
|
36
35
|
postValidation?(event: NodeValidationEvent<Shape, Value>): void;
|
|
37
36
|
}
|
|
38
37
|
export declare class ParsedNode<T extends ParsedNodeShape = ParsedNodeShape, Value = ParsedNodeValue<T>> extends TreeNode<ParsedNodeListener<any, any>> {
|
|
39
|
-
private readonly parsedValues;
|
|
40
38
|
private attributesByKey;
|
|
41
39
|
private childrenByKey;
|
|
42
|
-
private valueProviders?;
|
|
43
40
|
readonly definition: Node<any>;
|
|
44
41
|
readonly input?: NodeInput;
|
|
45
42
|
readonly parseParentNode?: ParsedNode;
|
|
@@ -51,19 +48,11 @@ export declare class ParsedNode<T extends ParsedNodeShape = ParsedNodeShape, Val
|
|
|
51
48
|
registerListener(listener: Partial<ParsedNodeListener<T, Value>>): () => void;
|
|
52
49
|
get children(): ParsedNode[];
|
|
53
50
|
getRoot(): ParsedNode;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* Resolve this node's attributes and descendants through their value providers.
|
|
60
|
-
* Include declared defaults for absent children without creating parsed nodes.
|
|
61
|
-
*/
|
|
62
|
-
valueTree(): ParsedNodeValuesLike<Value>;
|
|
63
|
-
/**
|
|
64
|
-
* Collect retained attribute sources for a value container to own and release.
|
|
65
|
-
*/
|
|
66
|
-
protected collectAttributeValues(attributeKeys: readonly string[]): Array<readonly [string, ParsedValue<unknown>]>;
|
|
51
|
+
value<const Keys extends readonly ParsedNodeValueRequestKey<T, Value>[]>(attributes: Keys, provider: ValueProviderContext): ParsedNodeValuesLike<ParsedNodeValueRequest<T, Value, Keys>>;
|
|
52
|
+
value<RequestedValue = any>(attributes: readonly ParsedNodeUntypedExpressionKey<T>[], provider: ValueProviderContext): ParsedNodeValuesLike<RequestedValue>;
|
|
53
|
+
protected createValues(attributeKeys: readonly string[], provider: ValueProviderContext): ParsedNodeValuesLike<any>;
|
|
54
|
+
/** Assemble this node's flat attribute set and its child trees. */
|
|
55
|
+
valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<Value>;
|
|
67
56
|
attribute<Key extends Extract<ParsedNodeRequiredAttributeName<T>, ParsedNodeExpressionKey<T>>>(key: Key): ParsedNodeAttribute<T, Key>;
|
|
68
57
|
attribute<Key extends Exclude<ParsedNodeExpressionKey<T>, ParsedNodeRequiredAttributeName<T>>>(key: Key): ParsedNodeAttribute<T, Key> | undefined;
|
|
69
58
|
attribute<Attribute extends ParsedAttribute = ParsedAttribute>(key: string): Attribute | undefined;
|
|
@@ -95,7 +84,6 @@ export declare class ParsedNode<T extends ParsedNodeShape = ParsedNodeShape, Val
|
|
|
95
84
|
childEntries(): ParsedChild[];
|
|
96
85
|
nodes(): ParsedNode[];
|
|
97
86
|
private flattenParsedArray;
|
|
98
|
-
private getParsedValue;
|
|
99
87
|
private addParsedAttribute;
|
|
100
88
|
private addParsedChild;
|
|
101
89
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ParsedNode } from './ParsedNode';
|
|
2
1
|
import { type ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
2
|
+
import type { ValueProviderContext } from '../values/ValueProviderContext';
|
|
3
|
+
import { ParsedNode } from './ParsedNode';
|
|
3
4
|
/** Only document keys become entries; the entry definition does not imply a default key. */
|
|
4
5
|
export declare class ParsedRecordNode<Entry extends ParsedNode<any, any>, Value> extends ParsedNode<Record<string, Entry>, Record<string, Value>> {
|
|
5
|
-
valueTree(): ParsedNodeValuesLike<Record<string, Value>>;
|
|
6
|
+
valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<Record<string, Value>>;
|
|
6
7
|
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { BaseObserver } from '@journeyapps/common-utils';
|
|
2
2
|
export interface ParsedNodeValuesListener<T> {
|
|
3
|
-
changed
|
|
4
|
-
disposed
|
|
3
|
+
changed?(value: T): void;
|
|
4
|
+
disposed?(): void;
|
|
5
5
|
}
|
|
6
6
|
export interface ParsedNodeValuesLike<T> {
|
|
7
7
|
readonly current: T;
|
|
8
8
|
registerListener(listener: Partial<ParsedNodeValuesListener<T>>): () => void;
|
|
9
9
|
dispose(): void;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Combine attribute or descendant values into one disposable value.
|
|
13
|
-
*/
|
|
11
|
+
/** Owns attribute or descendant evaluations and their combined current value. */
|
|
14
12
|
export declare class ParsedNodeValues<T> extends BaseObserver<ParsedNodeValuesListener<T>> implements ParsedNodeValuesLike<T> {
|
|
15
13
|
private readonly sources;
|
|
16
14
|
private readonly compose;
|
|
@@ -27,5 +27,9 @@ export declare class ParsedProviderValue<T> extends BaseObserver<ParsedProviderV
|
|
|
27
27
|
* Change activity without changing the stored value.
|
|
28
28
|
*/
|
|
29
29
|
setActive(active: boolean): void;
|
|
30
|
+
/**
|
|
31
|
+
* Stop updates and release subscriptions, preserving the final snapshot.
|
|
32
|
+
* To withdraw this contribution and select a fallback, call setActive(false) first.
|
|
33
|
+
*/
|
|
30
34
|
dispose(): void;
|
|
31
35
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseObserver } from '@journeyapps/common-utils';
|
|
2
2
|
import type { AbstractValueProvider } from './AbstractValueProvider';
|
|
3
|
-
import { ParsedAttribute } from '../parsed/ParsedAttribute';
|
|
3
|
+
import type { ParsedAttribute } from '../parsed/ParsedAttribute';
|
|
4
4
|
import { ParsedProviderValue } from './ParsedProviderValue';
|
|
5
5
|
export interface ParsedValueListener<T> {
|
|
6
6
|
changed?: (value: T) => void;
|
|
@@ -13,26 +13,17 @@ export interface ParsedValueLike<T> {
|
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Creates contributions from providers ordered from lowest to highest priority.
|
|
16
|
-
* Subscribes to every contribution and
|
|
16
|
+
* Subscribes to every contribution and keeps the current winning value.
|
|
17
17
|
*/
|
|
18
18
|
export declare class ParsedValue<T> extends BaseObserver<ParsedValueListener<T | undefined>> {
|
|
19
19
|
private readonly attribute;
|
|
20
20
|
current: T | undefined;
|
|
21
21
|
readonly providerValues: readonly ParsedProviderValue<unknown>[];
|
|
22
|
-
private
|
|
23
|
-
private released;
|
|
22
|
+
private disposed;
|
|
24
23
|
private readonly deregister;
|
|
25
24
|
private selected?;
|
|
26
25
|
constructor(attribute: ParsedAttribute, providers: readonly AbstractValueProvider[]);
|
|
27
26
|
get activeValue(): ParsedProviderValue<unknown> | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* Keep this resolved value and its contributions alive for another consumer.
|
|
30
|
-
*/
|
|
31
|
-
retain(): this;
|
|
32
|
-
/**
|
|
33
|
-
* Dispose contributions when the last consumer releases this value.
|
|
34
|
-
*/
|
|
35
|
-
release(): void;
|
|
36
27
|
dispose(): void;
|
|
37
28
|
private refresh;
|
|
38
29
|
}
|
|
@@ -17,6 +17,21 @@ class TextAttribute extends Attribute_1.Attribute {
|
|
|
17
17
|
static isInstanceOf(attr) {
|
|
18
18
|
return attr.type === TextAttribute.TYPE;
|
|
19
19
|
}
|
|
20
|
+
getInput(node) {
|
|
21
|
+
const attribute = super.getInput(node);
|
|
22
|
+
if (attribute || !this.options.allowContentFromNode)
|
|
23
|
+
return attribute;
|
|
24
|
+
const content = node === null || node === void 0 ? void 0 : node.content();
|
|
25
|
+
if (!content)
|
|
26
|
+
return undefined;
|
|
27
|
+
return Object.assign(Object.assign({}, content), { location: AttributeInput_1.AttributeInputLocation.CONTENT });
|
|
28
|
+
}
|
|
29
|
+
stringify(value, parent) {
|
|
30
|
+
const directive = super.stringify(value, parent);
|
|
31
|
+
if (!this.options.allowContentFromNode)
|
|
32
|
+
return directive;
|
|
33
|
+
return Object.assign(Object.assign({}, directive), { isAttribute: !parent.content() });
|
|
34
|
+
}
|
|
20
35
|
getParsedValue(event) {
|
|
21
36
|
let expression = super.getParsedValue(event);
|
|
22
37
|
if (expression instanceof parser_expressions_1.FormatStringExpression && expression.parameters.length === 0) {
|
|
@@ -41,6 +56,9 @@ class TextAttribute extends Attribute_1.Attribute {
|
|
|
41
56
|
});
|
|
42
57
|
}
|
|
43
58
|
serialize() {
|
|
59
|
+
if (this.options.allowContentFromNode) {
|
|
60
|
+
return Object.assign(Object.assign({}, super.serialize()), { type: 'content-text' });
|
|
61
|
+
}
|
|
44
62
|
return Object.assign(Object.assign({}, super.serialize()), { type: 'text' });
|
|
45
63
|
}
|
|
46
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAttribute.js","sourceRoot":"","sources":["../../src/attributes/TextAttribute.ts"],"names":[],"mappings":";;;AAAA,4DAAiE;AAEjE,
|
|
1
|
+
{"version":3,"file":"TextAttribute.js","sourceRoot":"","sources":["../../src/attributes/TextAttribute.ts"],"names":[],"mappings":";;;AAAA,4DAAiE;AAEjE,2CAAiG;AAIjG,wEAQyC;AACzC,wEAA2D;AAc3D,mBAGE,SAAQ,qBAAmC;IAG3C,YAAY,OAAgB;;QAC1B,KAAK,CAAC,aAAa,CAAC,IAAI,kCACnB,OAAO,KACV,SAAS,QAAE,OAAO,CAAC,SAAS,mCAAI,6BAAQ,EACxC,MAAM,QACJ,OAAO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CAAC,MAAM,CAAC,EAAE,CAAC;gBAC5B,SAAS,EAAE,6BAAQ;gBACnB,MAAM,EAAE,UAAU,CAAC,MAAM;gBACzB,KAAK,EAAE,UAAU,CAAC,KAAK;aACxB,CAAC,CAAC;QACL,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QACtC,OAAO,UAAU,CAAC;IACpB,CAAC;IAES,aAAa,CAAC,KAA0B,EAAE,UAAkC;;;QACpF,MAAA,MAAA,KAAK,CAAC,OAAO,0CAAE,kBAAkB,mDAAG;YAClC,SAAS,EAAE,IAAI;YACf,UAAU;YACV,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM;YAC1B,QAAQ,QAAE,KAAK,CAAC,KAAK,CAAC,QAAQ,mCAAI,uCAAsB,CAAC,SAAS;SACnE,CAAC,CAAC;IACL,CAAC;IAED,SAAS;QACP,IAAI,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;YACtC,uCAAY,KAAK,CAAC,SAAS,EAAE,KAAE,IAAI,EAAE,cAAc,IAAG;QACxD,CAAC;QACD,uCACK,KAAK,CAAC,SAAS,EAAE,KACpB,IAAI,EAAE,MAAM,IACZ;IACJ,CAAC;CACF;;AAnEQ,kBAAI,GAAG,gBAAgB,CAAC","sourcesContent":["import { AttributeInputLocation } from '../input/AttributeInput';\nimport { AttributeParseEvent } from '../AttributeParseEvent';\nimport { Attribute, AttributeGenerics, AttributeOptions, StringifyDirective } from './Attribute';\nimport type { AttributeInput } from '../input/AttributeInput';\nimport type { NodeInput } from '../input/NodeInput';\nimport type { ParsedNode } from '../parsed/ParsedNode';\nimport {\n FormatStringExpression,\n ConstantExpression,\n CombinedParser,\n FunctionExpressionParser,\n EvaluatedExpressionParser,\n FormatStringExpressionParser,\n EvaluatedExpression\n} from '@ja-platform/parser-expressions';\nimport { textType } from '@ja-platform/parser-type-system';\n\nexport type CombinedTextExpression = ConstantExpression<string> | FormatStringExpression | EvaluatedExpression;\n\nexport type TextAttributeOptions<Value = string> = AttributeOptions<Value, Value> & {\n allowContentFromNode?: boolean;\n};\n\nexport interface TextAttributeGenerics<Value = string> extends AttributeGenerics {\n Value: CombinedTextExpression | null;\n Options: TextAttributeOptions<Value>;\n NormalizedValue: Value;\n}\n\nexport class TextAttribute<\n T extends TextAttributeGenerics<unknown> = TextAttributeGenerics,\n Options extends T['Options'] = T['Options']\n> extends Attribute<T & { Options: Options }> {\n static TYPE = 'text-attribute';\n\n constructor(options: Options) {\n super(TextAttribute.TYPE, {\n ...options,\n valueType: options.valueType ?? textType,\n syntax:\n options.syntax ??\n new CombinedParser<CombinedTextExpression>([\n new FunctionExpressionParser(),\n new EvaluatedExpressionParser(),\n new FormatStringExpressionParser()\n ]),\n configurable: options.configurable ?? true\n });\n }\n\n static isInstanceOf(attr: Attribute): attr is TextAttribute<TextAttributeGenerics<unknown>> {\n return attr.type === TextAttribute.TYPE;\n }\n\n protected getInput(node?: NodeInput): AttributeInput | undefined {\n const attribute = super.getInput(node);\n if (attribute || !this.options.allowContentFromNode) return attribute;\n const content = node?.content();\n if (!content) return undefined;\n return { ...content, location: AttributeInputLocation.CONTENT };\n }\n\n stringify(value: T['Value'], parent: ParsedNode): StringifyDirective {\n const directive = super.stringify(value, parent);\n if (!this.options.allowContentFromNode) return directive;\n return { ...directive, isAttribute: !parent.content() };\n }\n\n protected getParsedValue(event: AttributeParseEvent): CombinedTextExpression | null {\n let expression = super.getParsedValue(event);\n if (expression instanceof FormatStringExpression && expression.parameters.length === 0) {\n expression = new ConstantExpression({\n value: expression.render([]),\n valueType: textType,\n tokens: expression.tokens,\n start: expression.start\n });\n }\n this.validateInput(event, expression);\n return expression;\n }\n\n protected validateInput(event: AttributeParseEvent, expression: CombinedTextExpression): void {\n event.context?.validateExpression?.({\n attribute: this,\n expression,\n source: event.input.source,\n location: event.input.location ?? AttributeInputLocation.ATTRIBUTE\n });\n }\n\n serialize(): any {\n if (this.options.allowContentFromNode) {\n return { ...super.serialize(), type: 'content-text' };\n }\n return {\n ...super.serialize(),\n type: 'text'\n };\n }\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,6 @@ __exportStar(require("./attributes/Attribute"), exports);
|
|
|
21
21
|
__exportStar(require("./attributes/BooleanAttribute"), exports);
|
|
22
22
|
__exportStar(require("./attributes/ConstantBooleanAttribute"), exports);
|
|
23
23
|
__exportStar(require("./attributes/ConstantTextAttribute"), exports);
|
|
24
|
-
__exportStar(require("./attributes/ContentTextAttribute"), exports);
|
|
25
24
|
__exportStar(require("./attributes/ExpressionAttribute"), exports);
|
|
26
25
|
__exportStar(require("./attributes/FunctionAttribute"), exports);
|
|
27
26
|
__exportStar(require("./attributes/ListAttribute"), exports);
|
|
@@ -57,4 +56,5 @@ __exportStar(require("./source/SourceReference"), exports);
|
|
|
57
56
|
__exportStar(require("./input/AttributeInput"), exports);
|
|
58
57
|
__exportStar(require("./input/NodeInput"), exports);
|
|
59
58
|
__exportStar(require("./input/AttributeParseContext"), exports);
|
|
59
|
+
__exportStar(require("./values/ValueProviderContext"), exports);
|
|
60
60
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,+CAA6B;AAC7B,6DAA2C;AAC3C,yDAAuC;AACvC,gEAA8C;AAC9C,wEAAsD;AACtD,qEAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,+CAA6B;AAC7B,6DAA2C;AAC3C,yDAAuC;AACvC,gEAA8C;AAC9C,wEAAsD;AACtD,qEAAmD;AACnD,mEAAiD;AACjD,iEAA+C;AAC/C,6DAA2C;AAC3C,+DAA6C;AAC7C,6DAA2C;AAC3C,4DAA0C;AAC1C,kEAAgD;AAChD,6DAA2C;AAC3C,4DAA0C;AAC1C,0DAAwC;AACxC,+CAA6B;AAC7B,sDAAoC;AACpC,2DAAyC;AACzC,qDAAmC;AACnC,qDAAmC;AACnC,4DAA0C;AAC1C,4DAA0C;AAC1C,2DAAyC;AACzC,2DAAyC;AACzC,6DAA2C;AAC3C,4DAA0C;AAC1C,sDAAoC;AACpC,2DAAyC;AACzC,iEAA+C;AAC/C,2EAAyD;AACzD,sEAAoD;AACpD,4DAA0C;AAC1C,+DAA6C;AAC7C,qEAAmD;AACnD,uDAAqC;AACrC,wDAAsC;AAEtC,2DAAyC;AACzC,yDAAuC;AACvC,oDAAkC;AAClC,gEAA8C;AAE9C,gEAA8C","sourcesContent":["export * from './AttributeParseEvent';\nexport * from './ParseEvent';\nexport * from './attributes/ConditionType';\nexport * from './attributes/Attribute';\nexport * from './attributes/BooleanAttribute';\nexport * from './attributes/ConstantBooleanAttribute';\nexport * from './attributes/ConstantTextAttribute';\nexport * from './attributes/ExpressionAttribute';\nexport * from './attributes/FunctionAttribute';\nexport * from './attributes/ListAttribute';\nexport * from './attributes/NumberAttribute';\nexport * from './attributes/PathAttribute';\nexport * from './attributes/SetAttribute';\nexport * from './attributes/TextArrayAttribute';\nexport * from './attributes/TextAttribute';\nexport * from './entities/AbstractEntity';\nexport * from './entities/CommonEntity';\nexport * from './nodes/Node';\nexport * from './nodes/ContentNode';\nexport * from './nodes/NodeAlternatives';\nexport * from './nodes/RecordNode';\nexport * from './nodes/EitherNode';\nexport * from './parsed/ParsedEitherNode';\nexport * from './parsed/ParsedRecordNode';\nexport * from './parsed/ParsedArrayNode';\nexport * from './parsed/ParsedAttribute';\nexport * from './parsed/ParsedContentNode';\nexport * from './parsed/ParsedDiagnostic';\nexport * from './parsed/ParsedNode';\nexport * from './parsed/ParsedNodeTypes';\nexport * from './values/AbstractValueProvider';\nexport * from './values/ConstantExpressionValueProvider';\nexport * from './values/ParserDefaultValueProvider';\nexport * from './values/ParsedNodeValues';\nexport * from './values/ParsedProviderValue';\nexport * from './values/MappedParsedProviderValue';\nexport * from './values/ParsedValue';\nexport * from './utils/types/valueOf';\n\nexport * from './source/SourceReference';\nexport * from './input/AttributeInput';\nexport * from './input/NodeInput';\nexport * from './input/AttributeParseContext';\n\nexport * from './values/ValueProviderContext';\n"]}
|
package/dist/nodes/Node.js
CHANGED
|
@@ -36,7 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.Node = void 0;
|
|
37
37
|
const AttributeInput_1 = require("../input/AttributeInput");
|
|
38
38
|
const _ = __importStar(require("lodash"));
|
|
39
|
-
const
|
|
39
|
+
const TextAttribute_1 = require("../attributes/TextAttribute");
|
|
40
40
|
const CommonEntity_1 = require("../entities/CommonEntity");
|
|
41
41
|
const ParsedArrayNode_1 = require("../parsed/ParsedArrayNode");
|
|
42
42
|
const ParsedNode_1 = require("../parsed/ParsedNode");
|
|
@@ -93,9 +93,8 @@ class Node extends CommonEntity_1.CommonEntity {
|
|
|
93
93
|
return this;
|
|
94
94
|
}
|
|
95
95
|
getContentAttribute() {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
96
|
+
var _a;
|
|
97
|
+
return ((_a = this.attributes.find((attribute) => attribute instanceof TextAttribute_1.TextAttribute && !!attribute.options.allowContentFromNode)) !== null && _a !== void 0 ? _a : null);
|
|
99
98
|
}
|
|
100
99
|
getTemplate(cursor) {
|
|
101
100
|
if (cursor == null) {
|
|
@@ -219,7 +218,7 @@ class Node extends CommonEntity_1.CommonEntity {
|
|
|
219
218
|
if (!event.input)
|
|
220
219
|
return;
|
|
221
220
|
const attributeNames = this.attributes
|
|
222
|
-
.filter((attribute) => !(attribute instanceof
|
|
221
|
+
.filter((attribute) => !(attribute instanceof TextAttribute_1.TextAttribute && attribute.options.allowContentFromNode))
|
|
223
222
|
.map((attribute) => attribute.name);
|
|
224
223
|
this.nodes.forEach((definition) => {
|
|
225
224
|
const selection = event.input.selectChildren(definition.inputSelectors, attributeNames);
|
package/dist/nodes/Node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Node.js","sourceRoot":"","sources":["../../src/nodes/Node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4DAAiE;AAEjE,MAAY,CAAC,mCAAe;AAE5B,6EAA0E;AAC1E,2DAAmG;AACnG,+DAA4D;AAC5D,qDAAkD;AAiElD,UAAmE,SAAQ,2BAAe;IAIxF,YAAY,OAAqB;QAC/B,IAAI,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACxC,IAAI,YAAY,KAAK,SAAS,IAAI,OAAO,CAAC,UAAU;YAAE,YAAY,GAAG,EAAE,CAAC;QACxE,KAAK,iCACA,OAAO,KACV,YAAY;YACZ,4CAA4C;YAC5C,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,EAAE,IAClC,CAAC;QAEH,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;IACnC,CAAC;IAED,SAAS;QACP,uCACK,KAAK,CAAC,SAAS,EAAE,KACpB,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EACjC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EACjC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EACvB,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;gBAChC,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;YAC1B,CAAC,CAAC,EACF,UAAU,EAAE,IAAI,CAAC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ation } from '../input/AttributeInput';\nimport type { NodeInput, NodeInputSelector, NodeInputSelection } from '../input/NodeInput';\nimport * as _ from 'lodash';\nimport { Attribute } from '../attributes/Attribute';\nimport { ContentTextAttribute } from '../attributes/ContentTextAttribute';\nimport { CommonEntity, CommonEntityGenerics, CommonEntityOptions } from '../entities/CommonEntity';\nimport { ParsedArrayNode } from '../parsed/ParsedArrayNode';\nimport { ParsedNode } from '../parsed/ParsedNode';\nimport { ParsedNodeShape } from '../parsed/ParsedNodeTypes';\nimport type { NodeValidationContext } from '../parsed/ParsedNode';\n\nexport interface NodeListener<Shape extends ParsedNodeShape = ParsedNodeShape> {\n /**\n * before the node is parsed\n */\n preParse?({ event, parentEvent }: { event: ParseEvent; parentEvent: ParseEvent }): any;\n\n /**\n * Before child inputs are parsed.\n */\n preChildrenParse?(event: ParseEvent): void;\n\n /**\n * Once this node has been parsed\n */\n postParse?({ parsed, parentEvent }: { parsed: ParsedNode<Shape>; parentEvent: ParseEvent }): any;\n}\n\n/**\n * Represents a template for a node\n */\nexport interface NodeTemplate {\n /**\n * Name of the node\n */\n name: string;\n /**\n * The string version of the template\n * @example <table attr1=\"${cursor}\" />\n */\n template?: string;\n /**\n * if `template` is not defined, the attributes to make up the template:\n * @example ['attr1']\n */\n attrs?: string[];\n}\n\nexport interface NodeOptions extends CommonEntityOptions {\n isMultiple?: boolean;\n defaultValue?: unknown;\n isRequired?: boolean;\n templates?: NodeTemplate[];\n}\n\nexport interface NodeGenerics<\n Shape extends ParsedNodeShape = ParsedNodeShape,\n Parsed extends ParsedNode<Shape, any> = ParsedNode<Shape>,\n Value = unknown\n> extends CommonEntityGenerics {\n Shape: Shape;\n Parsed: Parsed;\n Value: Value;\n Options: NodeOptions;\n Listener: NodeListener<Shape>;\n}\n\nexport interface ParseTreeOptions extends ParseEvent {\n parentEvent?: ParseEvent;\n key?: string;\n}\n\nexport class Node<G extends NodeGenerics<any> = NodeGenerics<any>> extends CommonEntity<G> {\n attributes: Attribute[];\n nodes: Node<any>[];\n\n constructor(options: G['Options']) {\n let defaultValue = options.defaultValue;\n if (defaultValue === undefined && options.isMultiple) defaultValue = [];\n super({\n ...options,\n defaultValue,\n // templates should always be an empty array\n templates: options.templates || []\n });\n\n this.attributes = [];\n this.nodes = [];\n this.listeners = [];\n }\n\n get name() {\n return this.options.name;\n }\n\n get defaultValue(): G['Value'] | G['Value'][] | undefined {\n return this.options.defaultValue;\n }\n\n serialize(): any {\n return {\n ...super.serialize(),\n multiple: this.options.isMultiple,\n required: this.options.isRequired,\n docs: this.options.docs,\n children: this.nodes.map((node) => {\n return node.serialize();\n }),\n attributes: this.attributes.map((attr) => {\n return attr.serialize();\n })\n };\n }\n\n getNodes(name: string): Node<any>[] {\n return this.nodes.filter((n) => n.name == name);\n }\n\n getNode(name: string): Node<any> {\n for (let node of this.nodes) {\n if (node.name === name) {\n return node;\n }\n }\n }\n\n getAttribute(name: string): Attribute {\n for (let attr of this.attributes) {\n if (attr.name === name) {\n return attr;\n }\n }\n }\n\n removeAttribute(name: string) {\n const index = _.findIndex(this.attributes, (item) => {\n return item.name == name;\n });\n\n if (index < 0) {\n return this;\n }\n\n this.attributes.splice(index, 1);\n return this;\n }\n\n getContentAttribute(): ContentTextAttribute | null {\n return this.attributes.find((attr) => {\n return attr instanceof ContentTextAttribute;\n }) as ContentTextAttribute;\n }\n\n getTemplate(cursor?: string): { template?: string; templates?: { name: string; template: string }[] } {\n if (cursor == null) {\n cursor = '${cursor}';\n }\n // use the named templates\n if (this.options.templates.length > 0) {\n return {\n templates: this.options.templates.map((template) => {\n if (template.template) {\n return {\n name: template.name,\n template: template.template\n };\n }\n\n let first = true;\n const attrs = template.attrs.map((attr) => {\n return `${attr}=\"${first ? cursor : ''}\"`;\n first = false;\n });\n\n return {\n name: template.name,\n template: `<${this.name} ${attrs.join(' ')} />`\n };\n })\n };\n }\n\n // no children, so put the first attribute\n if (this.nodes.length === 0 && this.attributes.length > 0) {\n return {\n template: `<${this.name} ${this.attributes[0].name}=\"${cursor}\" />`\n };\n }\n\n // normal node\n return {\n template: `<${this.name}>${cursor}</${this.name}>`\n };\n }\n\n addAttributes(attrs: Attribute[]) {\n attrs.forEach((a) => this.addAttribute(a));\n }\n\n addAttribute(attribute: Attribute): Node<G> {\n if (this.attributes.find((x) => x.name === attribute.name)) {\n this.replaceAttribute(attribute);\n } else {\n this.attributes.push(attribute);\n attribute.setParent(this);\n }\n\n return this;\n }\n\n replaceAttribute(attribute: Attribute): Node<G> {\n const index = this.attributes.findIndex((attr) => attr.name === attribute.name);\n if (index === -1) {\n return;\n }\n\n this.attributes[index] = attribute;\n attribute.setParent(this);\n return this;\n }\n\n addNode(node: Node<any>): Node<G> {\n this.nodes.push(node);\n node.setParent(this);\n return this;\n }\n\n registerListener(listener: NodeListener<G['Shape']>) {\n return super.registerListener(listener as G['Listener']);\n }\n\n parse(options: ParseTreeOptions): G['Parsed'] | null {\n if (!this.shouldParse(options)) {\n return null;\n }\n return this.parseTree(options);\n }\n\n parseTree(options: ParseTreeOptions): G['Parsed'] {\n this.fireListeners((listener) => {\n listener.preParse?.({ event: options, parentEvent: options.parentEvent });\n });\n\n const result = this.createParsedNode(options);\n this.buildParsedNode({ parsed: result, options });\n\n this.validateParsedNode({ parsed: result, parentEvent: options.parentEvent });\n\n return result;\n }\n\n validateParsedNode({\n parsed,\n parentEvent\n }: {\n parsed: ParsedNode<G['Shape'], G['Value']>;\n parentEvent?: ParseEvent;\n }): void {\n this.fireListeners((listener) => listener.postParse?.({ parsed, parentEvent }));\n }\n\n protected shouldParse(_options: ParseTreeOptions): boolean {\n return true;\n }\n\n protected createParsedNode(options: ParseTreeOptions): G['Parsed'] {\n return new ParsedNode<G['Shape'], G['Value']>({\n definition: this,\n ...options\n }) as G['Parsed'];\n }\n\n protected buildParsedNode({\n parsed,\n options\n }: {\n parsed: ParsedNode<G['Shape'], G['Value']>;\n options: ParseTreeOptions;\n }): void {\n this.parseAttributes({ parsed, event: options });\n options.prepareNode?.(parsed);\n this.parseChildren({ parsed, options });\n }\n\n protected parseAttributes({\n parsed,\n event\n }: {\n parsed: ParsedNode<G['Shape'], G['Value']>;\n event: ParseEvent;\n }): void {\n this.attributes.forEach((definition: Attribute) => {\n try {\n const attribute = definition.parse(event.input, event);\n parsed.setAttribute(attribute);\n if (attribute.input?.location === AttributeInputLocation.CONTENT) {\n parsed.setContent(attribute.expression());\n }\n } catch (ex) {\n parsed.pushError({\n message: `failed to parse attribute: ${definition.options.name} on node ${this.options.name}`\n });\n console.error(`failed to parse attribute: ${definition.options.name} on node ${this.options.name}`, ex);\n }\n });\n }\n\n protected parseChildren({\n parsed,\n options\n }: {\n parsed: ParsedNode<G['Shape'], G['Value']>;\n options: ParseTreeOptions;\n }): void {\n const event = options;\n this.fireListeners((listener) => listener.preChildrenParse?.({ ...event, parsedNode: parsed }));\n\n if (!event.input) return;\n const attributeNames = this.attributes\n .filter((attribute) => !(attribute instanceof ContentTextAttribute))\n .map((attribute) => attribute.name);\n\n this.nodes.forEach((definition) => {\n const selection = event.input.selectChildren(definition.inputSelectors, attributeNames);\n selection.diagnostics.forEach((diagnostic) => parsed.pushError(diagnostic));\n definition.parseChildrenInto({ parent: parsed, inputs: selection.inputs, options, selection });\n });\n }\n\n get inputSelectors(): readonly NodeInputSelector[] {\n return [{ name: this.name, key: this.options.key, isMultiple: this.options.isMultiple }];\n }\n\n parseChildrenInto({\n parent,\n inputs,\n options,\n selection\n }: {\n parent: ParsedNode;\n inputs: NodeInput[];\n options: ParseTreeOptions;\n selection?: NodeInputSelection;\n }): void {\n const matchingInputs = inputs.filter((input) => input.name === this.options.name);\n parent.registerListener({\n postValidation: ({ context }) => {\n this.validateChildCount({ context, definition: this, matchingInputs });\n }\n });\n\n if (this.options.isMultiple) {\n const arrayNode = new ParsedArrayNode({\n definition: this,\n key: this.options.key,\n inputPresent: selection?.present,\n source: selection?.source\n });\n\n matchingInputs.forEach((input, index) => {\n const child = this.parseInput({ parent, options, input, key: `${index}` });\n if (child) {\n arrayNode.addChild(child);\n }\n });\n\n parent.setChild(this.options.key, arrayNode);\n return;\n }\n\n for (const input of matchingInputs) {\n const child = this.parseInput({ parent, options, input, key: this.options.key });\n if (child) {\n parent.setChild(this.options.key, child);\n return;\n }\n }\n }\n\n parseInput({\n parent,\n options,\n input,\n key\n }: {\n parent: ParsedNode;\n options: ParseTreeOptions;\n input: NodeInput;\n key: string;\n }): ParsedNode | null {\n return this.parse({\n ...options,\n input,\n parentNode: parent,\n parentEvent: options,\n key\n });\n }\n\n protected validateChildCount({\n context,\n definition,\n matchingInputs\n }: {\n context: NodeValidationContext;\n definition: Node<any>;\n matchingInputs: NodeInput[];\n }): void {\n if (definition.options.isRequired) {\n if (!definition.options.isMultiple && matchingInputs.length !== 1) {\n context.report({ message: `<${this.options.name}> must contain exactly one '<${definition.options.name}/>'` });\n }\n\n if (definition.options.isMultiple && matchingInputs.length === 0) {\n context.report({ message: `<${this.options.name}> must contain at least one '<${definition.options.name}/>'` });\n }\n } else if (!definition.options.isMultiple && matchingInputs.length > 1) {\n context.report({\n message: `<${this.options.name}> cannot contain more than one '<${definition.options.name}/>'`\n });\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Node.js","sourceRoot":"","sources":["../../src/nodes/Node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4DAAiE;AAEjE,MAAY,CAAC,mCAAe;AAE5B,+DAAmF;AACnF,2DAAmG;AACnG,+DAA4D;AAC5D,qDAAkD;AAiElD,UAAmE,SAAQ,2BAAe;IAIxF,YAAY,OAAqB;QAC/B,IAAI,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACxC,IAAI,YAAY,KAAK,SAAS,IAAI,OAAO,CAAC,UAAU;YAAE,YAAY,GAAG,EAAE,CAAC;QACxE,KAAK,iCACA,OAAO,KACV,YAAY;YACZ,4CAA4C;YAC5C,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,EAAE,IAClC,CAAC;QAEH,IAA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O,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,gCAAgC,UAAU,CAAC,OAAO,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;YACjH,CAAC;YAED,IAAI,UAAU,CAAC,OAAO,CAAC,UAAU,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACjE,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,iCAAiC,UAAU,CAAC,OAAO,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;YAClH,CAAC;QACH,CAAC;aAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvE,OAAO,CAAC,MAAM,CAAC;gBACb,OAAO,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,oCAAoC,UAAU,CAAC,OAAO,CAAC,IAAI,KAAK;aAC/F,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ParseEvent } from '../ParseEvent';\nimport { AttributeInputLocation } from '../input/AttributeInput';\nimport type { NodeInput, NodeInputSelector, NodeInputSelection } from '../input/NodeInput';\nimport * as _ from 'lodash';\nimport { Attribute } from '../attributes/Attribute';\nimport { TextAttribute, TextAttributeGenerics } from '../attributes/TextAttribute';\nimport { CommonEntity, CommonEntityGenerics, CommonEntityOptions } from '../entities/CommonEntity';\nimport { ParsedArrayNode } from '../parsed/ParsedArrayNode';\nimport { ParsedNode } from '../parsed/ParsedNode';\nimport { ParsedNodeShape } from '../parsed/ParsedNodeTypes';\nimport type { NodeValidationContext } from '../parsed/ParsedNode';\n\nexport interface NodeListener<Shape extends ParsedNodeShape = ParsedNodeShape> {\n /**\n * before the node is parsed\n */\n preParse?({ event, parentEvent }: { event: ParseEvent; parentEvent: ParseEvent }): any;\n\n /**\n * Before child inputs are parsed.\n */\n preChildrenParse?(event: ParseEvent): void;\n\n /**\n * Once this node has been parsed\n */\n postParse?({ parsed, parentEvent }: { parsed: ParsedNode<Shape>; parentEvent: ParseEvent }): any;\n}\n\n/**\n * Represents a template for a node\n */\nexport interface NodeTemplate {\n /**\n * Name of the node\n */\n name: string;\n /**\n * The string version of the template\n * @example <table attr1=\"${cursor}\" />\n */\n template?: string;\n /**\n * if `template` is not defined, the attributes to make up the template:\n * @example ['attr1']\n */\n attrs?: string[];\n}\n\nexport interface NodeOptions extends CommonEntityOptions {\n isMultiple?: boolean;\n defaultValue?: unknown;\n isRequired?: boolean;\n templates?: NodeTemplate[];\n}\n\nexport interface NodeGenerics<\n Shape extends ParsedNodeShape = ParsedNodeShape,\n Parsed extends ParsedNode<Shape, any> = ParsedNode<Shape>,\n Value = unknown\n> extends CommonEntityGenerics {\n Shape: Shape;\n Parsed: Parsed;\n Value: Value;\n Options: NodeOptions;\n Listener: NodeListener<Shape>;\n}\n\nexport interface ParseTreeOptions extends ParseEvent {\n parentEvent?: ParseEvent;\n key?: string;\n}\n\nexport class Node<G extends NodeGenerics<any> = NodeGenerics<any>> extends CommonEntity<G> {\n attributes: Attribute[];\n nodes: Node<any>[];\n\n constructor(options: G['Options']) {\n let defaultValue = options.defaultValue;\n if (defaultValue === undefined && options.isMultiple) defaultValue = [];\n super({\n ...options,\n defaultValue,\n // templates should always be an empty array\n templates: options.templates || []\n });\n\n this.attributes = [];\n this.nodes = [];\n this.listeners = [];\n }\n\n get name() {\n return this.options.name;\n }\n\n get defaultValue(): G['Value'] | G['Value'][] | undefined {\n return this.options.defaultValue;\n }\n\n serialize(): any {\n return {\n ...super.serialize(),\n multiple: this.options.isMultiple,\n required: this.options.isRequired,\n docs: this.options.docs,\n children: this.nodes.map((node) => {\n return node.serialize();\n }),\n attributes: this.attributes.map((attr) => {\n return attr.serialize();\n })\n };\n }\n\n getNodes(name: string): Node<any>[] {\n return this.nodes.filter((n) => n.name == name);\n }\n\n getNode(name: string): Node<any> {\n for (let node of this.nodes) {\n if (node.name === name) {\n return node;\n }\n }\n }\n\n getAttribute(name: string): Attribute {\n for (let attr of this.attributes) {\n if (attr.name === name) {\n return attr;\n }\n }\n }\n\n removeAttribute(name: string) {\n const index = _.findIndex(this.attributes, (item) => {\n return item.name == name;\n });\n\n if (index < 0) {\n return this;\n }\n\n this.attributes.splice(index, 1);\n return this;\n }\n\n getContentAttribute(): TextAttribute<TextAttributeGenerics<unknown>> | null {\n return (\n this.attributes.find(\n (attribute): attribute is TextAttribute<TextAttributeGenerics<unknown>> =>\n attribute instanceof TextAttribute && !!attribute.options.allowContentFromNode\n ) ?? null\n );\n }\n\n getTemplate(cursor?: string): { template?: string; templates?: { name: string; template: string }[] } {\n if (cursor == null) {\n cursor = '${cursor}';\n }\n // use the named templates\n if (this.options.templates.length > 0) {\n return {\n templates: this.options.templates.map((template) => {\n if (template.template) {\n return {\n name: template.name,\n template: template.template\n };\n }\n\n let first = true;\n const attrs = template.attrs.map((attr) => {\n return `${attr}=\"${first ? cursor : ''}\"`;\n first = false;\n });\n\n return {\n name: template.name,\n template: `<${this.name} ${attrs.join(' ')} />`\n };\n })\n };\n }\n\n // no children, so put the first attribute\n if (this.nodes.length === 0 && this.attributes.length > 0) {\n return {\n template: `<${this.name} ${this.attributes[0].name}=\"${cursor}\" />`\n };\n }\n\n // normal node\n return {\n template: `<${this.name}>${cursor}</${this.name}>`\n };\n }\n\n addAttributes(attrs: Attribute[]) {\n attrs.forEach((a) => this.addAttribute(a));\n }\n\n addAttribute(attribute: Attribute): Node<G> {\n if (this.attributes.find((x) => x.name === attribute.name)) {\n this.replaceAttribute(attribute);\n } else {\n this.attributes.push(attribute);\n attribute.setParent(this);\n }\n\n return this;\n }\n\n replaceAttribute(attribute: Attribute): Node<G> {\n const index = this.attributes.findIndex((attr) => attr.name === attribute.name);\n if (index === -1) {\n return;\n }\n\n this.attributes[index] = attribute;\n attribute.setParent(this);\n return this;\n }\n\n addNode(node: Node<any>): Node<G> {\n this.nodes.push(node);\n node.setParent(this);\n return this;\n }\n\n registerListener(listener: NodeListener<G['Shape']>) {\n return super.registerListener(listener as G['Listener']);\n }\n\n parse(options: ParseTreeOptions): G['Parsed'] | null {\n if (!this.shouldParse(options)) {\n return null;\n }\n return this.parseTree(options);\n }\n\n parseTree(options: ParseTreeOptions): G['Parsed'] {\n this.fireListeners((listener) => {\n listener.preParse?.({ event: options, parentEvent: options.parentEvent });\n });\n\n const result = this.createParsedNode(options);\n this.buildParsedNode({ parsed: result, options });\n\n this.validateParsedNode({ parsed: result, parentEvent: options.parentEvent });\n\n return result;\n }\n\n validateParsedNode({\n parsed,\n parentEvent\n }: {\n parsed: ParsedNode<G['Shape'], G['Value']>;\n parentEvent?: ParseEvent;\n }): void {\n this.fireListeners((listener) => listener.postParse?.({ parsed, parentEvent }));\n }\n\n protected shouldParse(_options: ParseTreeOptions): boolean {\n return true;\n }\n\n protected createParsedNode(options: ParseTreeOptions): G['Parsed'] {\n return new ParsedNode<G['Shape'], G['Value']>({\n definition: this,\n ...options\n }) as G['Parsed'];\n }\n\n protected buildParsedNode({\n parsed,\n options\n }: {\n parsed: ParsedNode<G['Shape'], G['Value']>;\n options: ParseTreeOptions;\n }): void {\n this.parseAttributes({ parsed, event: options });\n options.prepareNode?.(parsed);\n this.parseChildren({ parsed, options });\n }\n\n protected parseAttributes({\n parsed,\n event\n }: {\n parsed: ParsedNode<G['Shape'], G['Value']>;\n event: ParseEvent;\n }): void {\n this.attributes.forEach((definition: Attribute) => {\n try {\n const attribute = definition.parse(event.input, event);\n parsed.setAttribute(attribute);\n if (attribute.input?.location === AttributeInputLocation.CONTENT) {\n parsed.setContent(attribute.expression());\n }\n } catch (ex) {\n parsed.pushError({\n message: `failed to parse attribute: ${definition.options.name} on node ${this.options.name}`\n });\n console.error(`failed to parse attribute: ${definition.options.name} on node ${this.options.name}`, ex);\n }\n });\n }\n\n protected parseChildren({\n parsed,\n options\n }: {\n parsed: ParsedNode<G['Shape'], G['Value']>;\n options: ParseTreeOptions;\n }): void {\n const event = options;\n this.fireListeners((listener) => listener.preChildrenParse?.({ ...event, parsedNode: parsed }));\n\n if (!event.input) return;\n const attributeNames = this.attributes\n .filter((attribute) => !(attribute instanceof TextAttribute && attribute.options.allowContentFromNode))\n .map((attribute) => attribute.name);\n\n this.nodes.forEach((definition) => {\n const selection = event.input.selectChildren(definition.inputSelectors, attributeNames);\n selection.diagnostics.forEach((diagnostic) => parsed.pushError(diagnostic));\n definition.parseChildrenInto({ parent: parsed, inputs: selection.inputs, options, selection });\n });\n }\n\n get inputSelectors(): readonly NodeInputSelector[] {\n return [{ name: this.name, key: this.options.key, isMultiple: this.options.isMultiple }];\n }\n\n parseChildrenInto({\n parent,\n inputs,\n options,\n selection\n }: {\n parent: ParsedNode;\n inputs: NodeInput[];\n options: ParseTreeOptions;\n selection?: NodeInputSelection;\n }): void {\n const matchingInputs = inputs.filter((input) => input.name === this.options.name);\n parent.registerListener({\n postValidation: ({ context }) => {\n this.validateChildCount({ context, definition: this, matchingInputs });\n }\n });\n\n if (this.options.isMultiple) {\n const arrayNode = new ParsedArrayNode({\n definition: this,\n key: this.options.key,\n inputPresent: selection?.present,\n source: selection?.source\n });\n\n matchingInputs.forEach((input, index) => {\n const child = this.parseInput({ parent, options, input, key: `${index}` });\n if (child) {\n arrayNode.addChild(child);\n }\n });\n\n parent.setChild(this.options.key, arrayNode);\n return;\n }\n\n for (const input of matchingInputs) {\n const child = this.parseInput({ parent, options, input, key: this.options.key });\n if (child) {\n parent.setChild(this.options.key, child);\n return;\n }\n }\n }\n\n parseInput({\n parent,\n options,\n input,\n key\n }: {\n parent: ParsedNode;\n options: ParseTreeOptions;\n input: NodeInput;\n key: string;\n }): ParsedNode | null {\n return this.parse({\n ...options,\n input,\n parentNode: parent,\n parentEvent: options,\n key\n });\n }\n\n protected validateChildCount({\n context,\n definition,\n matchingInputs\n }: {\n context: NodeValidationContext;\n definition: Node<any>;\n matchingInputs: NodeInput[];\n }): void {\n if (definition.options.isRequired) {\n if (!definition.options.isMultiple && matchingInputs.length !== 1) {\n context.report({ message: `<${this.options.name}> must contain exactly one '<${definition.options.name}/>'` });\n }\n\n if (definition.options.isMultiple && matchingInputs.length === 0) {\n context.report({ message: `<${this.options.name}> must contain at least one '<${definition.options.name}/>'` });\n }\n } else if (!definition.options.isMultiple && matchingInputs.length > 1) {\n context.report({\n message: `<${this.options.name}> cannot contain more than one '<${definition.options.name}/>'`\n });\n }\n }\n}\n"]}
|
|
@@ -18,18 +18,14 @@ class ParsedArrayNode extends common_tree_1.TreeNode {
|
|
|
18
18
|
/**
|
|
19
19
|
* Resolve repeated children in order, preserving nested arrays.
|
|
20
20
|
*/
|
|
21
|
-
valueTree() {
|
|
22
|
-
return new ParsedNodeValues_1.ParsedNodeValues(this.nodes().map((child) => child.valueTree()), (values) => { var _a; return [
|
|
21
|
+
valueTree(provider) {
|
|
22
|
+
return new ParsedNodeValues_1.ParsedNodeValues(this.nodes().map((child) => child.valueTree(provider)), (values) => { var _a; return [
|
|
23
23
|
...(values.length === 0 && !this.inputPresent ? ((_a = this.definition.defaultValue) !== null && _a !== void 0 ? _a : []) : values)
|
|
24
24
|
]; });
|
|
25
25
|
}
|
|
26
26
|
at(index) {
|
|
27
27
|
return this.nodes()[index];
|
|
28
28
|
}
|
|
29
|
-
setValueProviders(providers) {
|
|
30
|
-
this.nodes().forEach((child) => child.setValueProviders(providers));
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
29
|
pushError({ message, source, type }) {
|
|
34
30
|
var _a;
|
|
35
31
|
const diagnostic = this.diagnostics.pushError({ message, source, type });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParsedArrayNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedArrayNode.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ParsedArrayNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedArrayNode.ts"],"names":[],"mappings":";;;AAAA,iEAAyF;AAG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AO,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5E,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;IACnC,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;IACtC,CAAC;IAED,GAAG,CAAI,EAAqC;QAC1C,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import { ParsedNodeValues, type ParsedNodeValuesLike } from '../values/ParsedNodeValues';\nimport type { ValueProviderContext } from '../values/ValueProviderContext';\nimport { ParsedExpressionValue } from './ParsedNodeTypes';\nimport { TreeNode } from '@journeyapps/common-tree';\n\nimport type { SourceReference } from '../source/SourceReference';\nimport { Node } from '../nodes/Node';\nimport { ParsedDiagnostic, ParsedDiagnosticStore } from './ParsedDiagnostic';\nimport { ParsedNode } from './ParsedNode';\n\nexport interface ParsedArrayNodeOptions {\n definition: Node<any>;\n key: string;\n inputPresent?: boolean;\n source?: SourceReference;\n}\n\nexport type ParsedArrayNodeChild = ParsedNode<any, any> | ParsedArrayNode<any>;\n\nexport class ParsedArrayNode<Child extends ParsedArrayNodeChild = ParsedNode<any, any>> extends TreeNode {\n public readonly definition: Node<any>;\n readonly inputPresent?: boolean;\n readonly source?: SourceReference;\n private readonly diagnostics = new ParsedDiagnosticStore();\n\n constructor(options: ParsedArrayNodeOptions) {\n super(options.key);\n this.definition = options.definition;\n this.inputPresent = options.inputPresent;\n this.source = options.source;\n }\n\n nodes(): Child[] {\n return this.getNodes<Child>();\n }\n\n /**\n * Resolve repeated children in order, preserving nested arrays.\n */\n valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<ParsedExpressionValue<Child>[]> {\n return new ParsedNodeValues(\n this.nodes().map((child) => child.valueTree(provider)),\n (values) =>\n [\n ...(values.length === 0 && !this.inputPresent ? (this.definition.defaultValue ?? []) : values)\n ] as ParsedExpressionValue<Child>[]\n );\n }\n\n at(index: number): Child | undefined {\n return this.nodes()[index];\n }\n\n pushError({ message, source, type }: ParsedDiagnostic): ParsedDiagnostic {\n const diagnostic = this.diagnostics.pushError({ message, source, type });\n if (source) {\n this.getParent<ParsedNode>()?.reportDiagnostic({ source, message, type });\n }\n return diagnostic;\n }\n\n errors(): ParsedDiagnostic[] {\n return this.diagnostics.errors();\n }\n\n hasErrors(): boolean {\n return this.diagnostics.hasErrors();\n }\n\n map<T>(cb: (node: Child, index: number) => T): T[] {\n return this.nodes().map(cb);\n }\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParsedContentNode = void 0;
|
|
4
|
-
const ParsedNode_1 = require("./ParsedNode");
|
|
5
4
|
const ParsedNodeValues_1 = require("../values/ParsedNodeValues");
|
|
5
|
+
const ParsedNode_1 = require("./ParsedNode");
|
|
6
6
|
/**
|
|
7
7
|
* A node whose element content resolves to the codec's value rather than an object.
|
|
8
8
|
*/
|
|
@@ -10,9 +10,9 @@ class ParsedContentNode extends ParsedNode_1.ParsedNode {
|
|
|
10
10
|
content() {
|
|
11
11
|
return super.content();
|
|
12
12
|
}
|
|
13
|
-
valueTree() {
|
|
14
|
-
const
|
|
15
|
-
return new ParsedNodeValues_1.ParsedNodeValues([source], ([value]) => value);
|
|
13
|
+
valueTree(provider) {
|
|
14
|
+
const source = this.createValues(['content'], provider);
|
|
15
|
+
return new ParsedNodeValues_1.ParsedNodeValues([source], ([value]) => value.content);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
exports.ParsedContentNode = ParsedContentNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParsedContentNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedContentNode.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ParsedContentNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedContentNode.ts"],"names":[],"mappings":";;;AAAA,iEAAyF;AAEzF,6CAA0C;AAO1C;;GAEG;AACH,uBAA+E,SAAQ,uBAGtF;IACC,OAAO;QACL,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;IAED,SAAS,CAAC,QAA8B;QACtC,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,CAAC;QACxD,OAAO,IAAI,mCAAgB,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAE,KAA6B,CAAC,OAAO,CAAC,CAAC;IAC7F,CAAC;CACF","sourcesContent":["import { ParsedNodeValues, type ParsedNodeValuesLike } from '../values/ParsedNodeValues';\nimport type { ValueProviderContext } from '../values/ValueProviderContext';\nimport { ParsedNode } from './ParsedNode';\nimport { ParsedNodeShapeValue } from './ParsedNodeTypes';\n\nexport type ParsedContentNodeShape<Expression extends ParsedNodeShapeValue> = {\n content?: Expression;\n};\n\n/**\n * A node whose element content resolves to the codec's value rather than an object.\n */\nexport class ParsedContentNode<Expression extends ParsedNodeShapeValue, Value> extends ParsedNode<\n ParsedContentNodeShape<Expression>,\n Value | undefined\n> {\n content(): Expression | undefined {\n return super.content();\n }\n\n valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<Value | undefined> {\n const source = this.createValues(['content'], provider);\n return new ParsedNodeValues([source], ([value]) => (value as { content?: Value }).content);\n }\n}\n"]}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParsedEitherNode = void 0;
|
|
4
|
-
const ParsedNode_1 = require("./ParsedNode");
|
|
5
4
|
const ParsedNodeValues_1 = require("../values/ParsedNodeValues");
|
|
5
|
+
const ParsedNode_1 = require("./ParsedNode");
|
|
6
6
|
/** Preserve the selected branch's value without adding an object to the output. */
|
|
7
7
|
class ParsedEitherNode extends ParsedNode_1.ParsedNode {
|
|
8
|
-
valueTree() {
|
|
8
|
+
valueTree(provider) {
|
|
9
9
|
const selected = this.child('value');
|
|
10
10
|
if (!selected)
|
|
11
11
|
return new ParsedNodeValues_1.ParsedNodeValues([], () => undefined);
|
|
12
|
-
return selected.valueTree();
|
|
12
|
+
return selected.valueTree(provider);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
exports.ParsedEitherNode = ParsedEitherNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParsedEitherNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedEitherNode.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ParsedEitherNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedEitherNode.ts"],"names":[],"mappings":";;;AAAA,iEAAyF;AAEzF,6CAA0C;AAG1C,mFAAmF;AACnF,sBAAqC,SAAQ,uBAAsD;IACjG,SAAS,CAAC,QAA8B;QACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrC,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,mCAAgB,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAChE,OAAO,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAgC,CAAC;IACrE,CAAC;CACF","sourcesContent":["import { ParsedNodeValues, type ParsedNodeValuesLike } from '../values/ParsedNodeValues';\nimport type { ValueProviderContext } from '../values/ValueProviderContext';\nimport { ParsedNode } from './ParsedNode';\nimport type { ParsedChild } from './ParsedNodeTypes';\n\n/** Preserve the selected branch's value without adding an object to the output. */\nexport class ParsedEitherNode<Value> extends ParsedNode<{ value?: ParsedChild }, Value | undefined> {\n valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<Value | undefined> {\n const selected = this.child('value');\n if (!selected) return new ParsedNodeValues([], () => undefined);\n return selected.valueTree(provider) as ParsedNodeValuesLike<Value>;\n }\n}\n"]}
|