@ja-platform/parser-core 0.0.0-dev-20261019214152
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/AttributeParseEvent.d.ts +15 -0
- package/dist/@types/XMLParseEvent.d.ts +37 -0
- package/dist/@types/attributes/AttributeDefaults.d.ts +7 -0
- package/dist/@types/attributes/ConditionType.d.ts +10 -0
- package/dist/@types/attributes/V5Attribute.d.ts +103 -0
- package/dist/@types/attributes/V5BooleanAttribute.d.ts +19 -0
- package/dist/@types/attributes/V5ConstantBooleanAttribute.d.ts +15 -0
- package/dist/@types/attributes/V5ConstantTextAttribute.d.ts +15 -0
- package/dist/@types/attributes/V5ContentTextAttribute.d.ts +18 -0
- package/dist/@types/attributes/V5ExpressionAttribute.d.ts +17 -0
- package/dist/@types/attributes/V5FunctionAttribute.d.ts +9 -0
- package/dist/@types/attributes/V5ListAttribute.d.ts +21 -0
- package/dist/@types/attributes/V5NumberAttribute.d.ts +27 -0
- package/dist/@types/attributes/V5PathAttribue.d.ts +11 -0
- package/dist/@types/attributes/V5SetAttribute.d.ts +18 -0
- package/dist/@types/attributes/V5TextArrayAttribute.d.ts +15 -0
- package/dist/@types/attributes/V5TextAttribute.d.ts +20 -0
- package/dist/@types/attributes/index.d.ts +15 -0
- package/dist/@types/entities/V5AbstractEntity.d.ts +15 -0
- package/dist/@types/entities/V5CommonEntity.d.ts +28 -0
- package/dist/@types/entities/index.d.ts +2 -0
- package/dist/@types/events/V5EditorContext.d.ts +43 -0
- package/dist/@types/index.d.ts +36 -0
- package/dist/@types/nodes/V5ContentNode.d.ts +45 -0
- package/dist/@types/nodes/V5Node.d.ts +128 -0
- package/dist/@types/nodes/V5NodeAlternatives.d.ts +24 -0
- package/dist/@types/parsed/ParsedArrayNode.d.ts +28 -0
- package/dist/@types/parsed/ParsedAttribute.d.ts +28 -0
- package/dist/@types/parsed/ParsedContentNode.d.ts +13 -0
- package/dist/@types/parsed/ParsedDiagnostic.d.ts +12 -0
- package/dist/@types/parsed/ParsedNode.d.ts +103 -0
- package/dist/@types/parsed/ParsedNodeTypes.d.ts +64 -0
- package/dist/@types/parsed/index.d.ts +6 -0
- package/dist/@types/utils/types/valueOf.d.ts +3 -0
- package/dist/@types/values/AbstractValueProvider.d.ts +16 -0
- package/dist/@types/values/ConstantExpressionValueProvider.d.ts +9 -0
- package/dist/@types/values/ParsedNodeValues.d.ts +24 -0
- package/dist/@types/values/ParsedProviderValue.d.ts +31 -0
- package/dist/@types/values/ParsedValue.d.ts +38 -0
- package/dist/@types/values/ParserDefaultValueProvider.d.ts +9 -0
- package/dist/AttributeParseEvent.js +3 -0
- package/dist/AttributeParseEvent.js.map +1 -0
- package/dist/XMLParseEvent.js +3 -0
- package/dist/XMLParseEvent.js.map +1 -0
- package/dist/attributes/AttributeDefaults.js +15 -0
- package/dist/attributes/AttributeDefaults.js.map +1 -0
- package/dist/attributes/ConditionType.js +26 -0
- package/dist/attributes/ConditionType.js.map +1 -0
- package/dist/attributes/V5Attribute.js +162 -0
- package/dist/attributes/V5Attribute.js.map +1 -0
- package/dist/attributes/V5BooleanAttribute.js +45 -0
- package/dist/attributes/V5BooleanAttribute.js.map +1 -0
- package/dist/attributes/V5ConstantBooleanAttribute.js +22 -0
- package/dist/attributes/V5ConstantBooleanAttribute.js.map +1 -0
- package/dist/attributes/V5ConstantTextAttribute.js +22 -0
- package/dist/attributes/V5ConstantTextAttribute.js.map +1 -0
- package/dist/attributes/V5ContentTextAttribute.js +44 -0
- package/dist/attributes/V5ContentTextAttribute.js.map +1 -0
- package/dist/attributes/V5ExpressionAttribute.js +30 -0
- package/dist/attributes/V5ExpressionAttribute.js.map +1 -0
- package/dist/attributes/V5FunctionAttribute.js +14 -0
- package/dist/attributes/V5FunctionAttribute.js.map +1 -0
- package/dist/attributes/V5ListAttribute.js +38 -0
- package/dist/attributes/V5ListAttribute.js.map +1 -0
- package/dist/attributes/V5NumberAttribute.js +64 -0
- package/dist/attributes/V5NumberAttribute.js.map +1 -0
- package/dist/attributes/V5PathAttribue.js +15 -0
- package/dist/attributes/V5PathAttribue.js.map +1 -0
- package/dist/attributes/V5SetAttribute.js +27 -0
- package/dist/attributes/V5SetAttribute.js.map +1 -0
- package/dist/attributes/V5TextArrayAttribute.js +40 -0
- package/dist/attributes/V5TextArrayAttribute.js.map +1 -0
- package/dist/attributes/V5TextAttribute.js +52 -0
- package/dist/attributes/V5TextAttribute.js.map +1 -0
- package/dist/attributes/index.js +32 -0
- package/dist/attributes/index.js.map +1 -0
- package/dist/entities/V5AbstractEntity.js +17 -0
- package/dist/entities/V5AbstractEntity.js.map +1 -0
- package/dist/entities/V5CommonEntity.js +33 -0
- package/dist/entities/V5CommonEntity.js.map +1 -0
- package/dist/entities/index.js +19 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/events/V5EditorContext.js +3 -0
- package/dist/events/V5EditorContext.js.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes/V5ContentNode.js +57 -0
- package/dist/nodes/V5ContentNode.js.map +1 -0
- package/dist/nodes/V5Node.js +277 -0
- package/dist/nodes/V5Node.js.map +1 -0
- package/dist/nodes/V5NodeAlternatives.js +119 -0
- package/dist/nodes/V5NodeAlternatives.js.map +1 -0
- package/dist/parsed/ParsedArrayNode.js +48 -0
- package/dist/parsed/ParsedArrayNode.js.map +1 -0
- package/dist/parsed/ParsedAttribute.js +41 -0
- package/dist/parsed/ParsedAttribute.js.map +1 -0
- package/dist/parsed/ParsedContentNode.js +19 -0
- package/dist/parsed/ParsedContentNode.js.map +1 -0
- package/dist/parsed/ParsedDiagnostic.js +21 -0
- package/dist/parsed/ParsedDiagnostic.js.map +1 -0
- package/dist/parsed/ParsedNode.js +240 -0
- package/dist/parsed/ParsedNode.js.map +1 -0
- package/dist/parsed/ParsedNodeTypes.js +3 -0
- package/dist/parsed/ParsedNodeTypes.js.map +1 -0
- package/dist/parsed/index.js +23 -0
- package/dist/parsed/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/types/valueOf.js +3 -0
- package/dist/utils/types/valueOf.js.map +1 -0
- package/dist/values/AbstractValueProvider.js +45 -0
- package/dist/values/AbstractValueProvider.js.map +1 -0
- package/dist/values/ConstantExpressionValueProvider.js +22 -0
- package/dist/values/ConstantExpressionValueProvider.js.map +1 -0
- package/dist/values/ParsedNodeValues.js +80 -0
- package/dist/values/ParsedNodeValues.js.map +1 -0
- package/dist/values/ParsedProviderValue.js +44 -0
- package/dist/values/ParsedProviderValue.js.map +1 -0
- package/dist/values/ParsedValue.js +73 -0
- package/dist/values/ParsedValue.js.map +1 -0
- package/dist/values/ParserDefaultValueProvider.js +16 -0
- package/dist/values/ParserDefaultValueProvider.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { XMLParseEvent } from '../XMLParseEvent';
|
|
2
|
+
import { XMLElement } from '@journeyapps/domparser/lib';
|
|
3
|
+
import { V5Attribute } from '../attributes/V5Attribute';
|
|
4
|
+
import { V5ContentTextAttribute } from '../attributes/V5ContentTextAttribute';
|
|
5
|
+
import { V5CommonEntity, V5CommonEntityGenerics, V5CommonEntityOptions } from '../entities/V5CommonEntity';
|
|
6
|
+
import { ParsedNode } from '../parsed/ParsedNode';
|
|
7
|
+
import { ParsedNodeShape } from '../parsed/ParsedNodeTypes';
|
|
8
|
+
import { AbstractValueProvider } from '../values/AbstractValueProvider';
|
|
9
|
+
import type { NodeValidationContext } from '../parsed/ParsedNode';
|
|
10
|
+
export interface V5NodeListener<Shape extends ParsedNodeShape = ParsedNodeShape> {
|
|
11
|
+
/**
|
|
12
|
+
* before the node is parsed
|
|
13
|
+
*/
|
|
14
|
+
preParse?({ event, parentEvent }: {
|
|
15
|
+
event: XMLParseEvent<ParsedNode>;
|
|
16
|
+
parentEvent: XMLParseEvent<ParsedNode>;
|
|
17
|
+
}): any;
|
|
18
|
+
/**
|
|
19
|
+
* Before child elements are parsed.
|
|
20
|
+
*/
|
|
21
|
+
preChildrenParse?(event: XMLParseEvent<ParsedNode>): void;
|
|
22
|
+
/**
|
|
23
|
+
* Once this node has been parsed
|
|
24
|
+
*/
|
|
25
|
+
postParse?({ parsed, parentEvent }: {
|
|
26
|
+
parsed: ParsedNode<Shape>;
|
|
27
|
+
parentEvent: XMLParseEvent<ParsedNode>;
|
|
28
|
+
}): any;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Represents a template for a node
|
|
32
|
+
*/
|
|
33
|
+
export interface V5Template {
|
|
34
|
+
/**
|
|
35
|
+
* Name of the node
|
|
36
|
+
*/
|
|
37
|
+
name: string;
|
|
38
|
+
/**
|
|
39
|
+
* The string version of the template
|
|
40
|
+
* @example <table attr1="${cursor}" />
|
|
41
|
+
*/
|
|
42
|
+
template?: string;
|
|
43
|
+
/**
|
|
44
|
+
* if `template` is not defined, the attributes to make up the template:
|
|
45
|
+
* @example ['attr1']
|
|
46
|
+
*/
|
|
47
|
+
attrs?: string[];
|
|
48
|
+
}
|
|
49
|
+
export interface V5NodeOptions extends V5CommonEntityOptions {
|
|
50
|
+
isMultiple?: boolean;
|
|
51
|
+
defaultValue?: unknown;
|
|
52
|
+
isRequired?: boolean;
|
|
53
|
+
templates?: V5Template[];
|
|
54
|
+
}
|
|
55
|
+
export interface V5NodeGenerics<Shape extends ParsedNodeShape = ParsedNodeShape, Parsed extends ParsedNode<Shape, any> = ParsedNode<Shape>, Value = unknown> extends V5CommonEntityGenerics {
|
|
56
|
+
Shape: Shape;
|
|
57
|
+
Parsed: Parsed;
|
|
58
|
+
Value: Value;
|
|
59
|
+
Options: V5NodeOptions;
|
|
60
|
+
Listener: V5NodeListener<Shape>;
|
|
61
|
+
}
|
|
62
|
+
export interface ParseTreeOptions {
|
|
63
|
+
event: XMLParseEvent<ParsedNode>;
|
|
64
|
+
parentEvent?: XMLParseEvent<ParsedNode>;
|
|
65
|
+
key?: string;
|
|
66
|
+
valueProviders?: readonly AbstractValueProvider[];
|
|
67
|
+
}
|
|
68
|
+
export declare class V5Node<G extends V5NodeGenerics<any> = V5NodeGenerics<any>> extends V5CommonEntity<G> {
|
|
69
|
+
attributes: V5Attribute[];
|
|
70
|
+
nodes: V5Node<any>[];
|
|
71
|
+
constructor(options: G['Options']);
|
|
72
|
+
get name(): string;
|
|
73
|
+
get defaultValue(): G['Value'] | G['Value'][] | undefined;
|
|
74
|
+
serialize(): any;
|
|
75
|
+
getNodes(name: string): V5Node<any>[];
|
|
76
|
+
getNode(name: string): V5Node<any>;
|
|
77
|
+
getAttribute(name: string): V5Attribute;
|
|
78
|
+
removeAttribute(name: string): this;
|
|
79
|
+
getContentAttribute(): V5ContentTextAttribute | null;
|
|
80
|
+
getTemplate(cursor?: string): {
|
|
81
|
+
template?: string;
|
|
82
|
+
templates?: {
|
|
83
|
+
name: string;
|
|
84
|
+
template: string;
|
|
85
|
+
}[];
|
|
86
|
+
};
|
|
87
|
+
addAttributes(attrs: V5Attribute[]): void;
|
|
88
|
+
addAttribute(attribute: V5Attribute): V5Node<G>;
|
|
89
|
+
replaceAttribute(attribute: V5Attribute): V5Node<G>;
|
|
90
|
+
addNode(node: V5Node<any>): V5Node<G>;
|
|
91
|
+
registerListener(listener: V5NodeListener<G['Shape']>): () => void;
|
|
92
|
+
parse(options: ParseTreeOptions): G['Parsed'] | null;
|
|
93
|
+
parseTree(options: ParseTreeOptions): G['Parsed'];
|
|
94
|
+
validateParsedNode({ parsed, parentEvent }: {
|
|
95
|
+
parsed: ParsedNode<G['Shape'], G['Value']>;
|
|
96
|
+
parentEvent?: XMLParseEvent<ParsedNode>;
|
|
97
|
+
}): void;
|
|
98
|
+
protected shouldParse(_options: ParseTreeOptions): boolean;
|
|
99
|
+
protected createParsedNode(options: ParseTreeOptions): G['Parsed'];
|
|
100
|
+
protected buildParsedNode({ parsed, options }: {
|
|
101
|
+
parsed: ParsedNode<G['Shape'], G['Value']>;
|
|
102
|
+
options: ParseTreeOptions;
|
|
103
|
+
}): void;
|
|
104
|
+
protected parseAttributes({ parsed, event }: {
|
|
105
|
+
parsed: ParsedNode<G['Shape'], G['Value']>;
|
|
106
|
+
event: XMLParseEvent<ParsedNode>;
|
|
107
|
+
}): void;
|
|
108
|
+
protected parseChildren({ parsed, options }: {
|
|
109
|
+
parsed: ParsedNode<G['Shape'], G['Value']>;
|
|
110
|
+
options: ParseTreeOptions;
|
|
111
|
+
}): void;
|
|
112
|
+
parseChildrenInto({ parent, elements, options }: {
|
|
113
|
+
parent: ParsedNode;
|
|
114
|
+
elements: XMLElement[];
|
|
115
|
+
options: ParseTreeOptions;
|
|
116
|
+
}): void;
|
|
117
|
+
parseElement({ parent, options, element, key }: {
|
|
118
|
+
parent: ParsedNode;
|
|
119
|
+
options: ParseTreeOptions;
|
|
120
|
+
element: XMLElement;
|
|
121
|
+
key: string;
|
|
122
|
+
}): ParsedNode | null;
|
|
123
|
+
protected validateChildElementCount({ context, definition, matchingElements }: {
|
|
124
|
+
context: NodeValidationContext;
|
|
125
|
+
definition: V5Node<any>;
|
|
126
|
+
matchingElements: XMLElement[];
|
|
127
|
+
}): void;
|
|
128
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ParsedNode, ParsedNodeShape } from '../parsed';
|
|
2
|
+
import { ParseTreeOptions, V5Node, V5NodeGenerics, V5NodeOptions } from './V5Node';
|
|
3
|
+
import { XMLElement } from '@journeyapps/domparser/lib';
|
|
4
|
+
export interface V5NodeAlternativesOptions extends Omit<V5NodeOptions, 'name'> {
|
|
5
|
+
key: string;
|
|
6
|
+
alternatives: V5Node<any>[];
|
|
7
|
+
exclusive?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class V5NodeAlternatives<Shape extends ParsedNodeShape = ParsedNodeShape> extends V5Node<V5NodeGenerics<Shape>> {
|
|
10
|
+
private readonly exclusiveValue;
|
|
11
|
+
private readonly alternatives;
|
|
12
|
+
constructor(options: V5NodeAlternativesOptions);
|
|
13
|
+
get exclusive(): boolean;
|
|
14
|
+
parseChildrenInto({ parent, elements, options }: {
|
|
15
|
+
parent: ParsedNode;
|
|
16
|
+
elements: XMLElement[];
|
|
17
|
+
options: ParseTreeOptions;
|
|
18
|
+
}): void;
|
|
19
|
+
private parseAlternativeElement;
|
|
20
|
+
private getMatchingAlternatives;
|
|
21
|
+
private validateAlternativeCount;
|
|
22
|
+
private validateDefinitionCount;
|
|
23
|
+
parse(_options: ParseTreeOptions): ParsedNode<Shape> | null;
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
2
|
+
import { ParsedExpressionValue } from './ParsedNodeTypes';
|
|
3
|
+
import { TreeNode } from '@journeyapps/common-tree';
|
|
4
|
+
import { V5Node } from '../nodes/V5Node';
|
|
5
|
+
import { AbstractValueProvider } from '../values/AbstractValueProvider';
|
|
6
|
+
import { ParsedDiagnostic } from './ParsedDiagnostic';
|
|
7
|
+
import { ParsedNode } from './ParsedNode';
|
|
8
|
+
export interface ParsedArrayNodeOptions {
|
|
9
|
+
definition: V5Node<any>;
|
|
10
|
+
key: string;
|
|
11
|
+
}
|
|
12
|
+
export type ParsedArrayNodeChild = ParsedNode<any, any> | ParsedArrayNode<any>;
|
|
13
|
+
export declare class ParsedArrayNode<Child extends ParsedArrayNodeChild = ParsedNode<any, any>> extends TreeNode {
|
|
14
|
+
readonly definition: V5Node<any>;
|
|
15
|
+
private readonly diagnostics;
|
|
16
|
+
constructor(options: ParsedArrayNodeOptions);
|
|
17
|
+
nodes(): Child[];
|
|
18
|
+
/**
|
|
19
|
+
* Resolve repeated children in order, preserving nested arrays.
|
|
20
|
+
*/
|
|
21
|
+
valueTree(): ParsedNodeValuesLike<ParsedExpressionValue<Child>[]>;
|
|
22
|
+
at(index: number): Child | undefined;
|
|
23
|
+
setValueProviders(providers: readonly AbstractValueProvider[]): this;
|
|
24
|
+
pushError({ message, element, type }: ParsedDiagnostic): ParsedDiagnostic;
|
|
25
|
+
errors(): ParsedDiagnostic[];
|
|
26
|
+
hasErrors(): boolean;
|
|
27
|
+
map<T>(cb: (node: Child, index: number) => T): T[];
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TreeEntity } from '@journeyapps/common-tree';
|
|
2
|
+
import { XMLParseEvent } from '../XMLParseEvent';
|
|
3
|
+
import { XMLPositional } from '@journeyapps/common-xml';
|
|
4
|
+
import { V5Attribute } from '../attributes/V5Attribute';
|
|
5
|
+
import { ParsedDiagnostic } from './ParsedDiagnostic';
|
|
6
|
+
import { ParsedNode } from './ParsedNode';
|
|
7
|
+
export interface ParsedAttributeOptions<Expression = any, Definition extends V5Attribute = V5Attribute> {
|
|
8
|
+
definition: Definition;
|
|
9
|
+
event: XMLParseEvent<ParsedNode>;
|
|
10
|
+
expression: Expression;
|
|
11
|
+
parseContext?: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
export declare class ParsedAttribute<Expression = any, Definition extends V5Attribute = V5Attribute> extends TreeEntity {
|
|
14
|
+
readonly definition: Definition;
|
|
15
|
+
private expressionValue;
|
|
16
|
+
readonly sourceElement: XMLPositional;
|
|
17
|
+
readonly parseContext?: Record<string, any>;
|
|
18
|
+
private readonly diagnostics;
|
|
19
|
+
private readonly reportError;
|
|
20
|
+
constructor(options: ParsedAttributeOptions<Expression, Definition>);
|
|
21
|
+
get name(): string;
|
|
22
|
+
expression(): Expression;
|
|
23
|
+
setExpression(value: Expression): void;
|
|
24
|
+
pushError({ message, element, type }: ParsedDiagnostic): ParsedDiagnostic;
|
|
25
|
+
errors(): ParsedDiagnostic[];
|
|
26
|
+
hasErrors(): boolean;
|
|
27
|
+
stringify(): import("../attributes/V5Attribute").StringifyDirective;
|
|
28
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ParsedNode } from './ParsedNode';
|
|
2
|
+
import { ParsedNodeShapeValue } from './ParsedNodeTypes';
|
|
3
|
+
import { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
4
|
+
export type ParsedContentNodeShape<Expression extends ParsedNodeShapeValue> = {
|
|
5
|
+
content?: Expression;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A node whose element content resolves to the codec's value rather than an object.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ParsedContentNode<Expression extends ParsedNodeShapeValue, Value> extends ParsedNode<ParsedContentNodeShape<Expression>, Value | undefined> {
|
|
11
|
+
content(): Expression | undefined;
|
|
12
|
+
valueTree(): ParsedNodeValuesLike<Value | undefined>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { XMLDiagnostic as ParsedDiagnostic } from '@journeyapps/common-xml';
|
|
2
|
+
import type { ExpressionDiagnostic } from '@ja-platform/parser-expressions';
|
|
3
|
+
export type { XMLDiagnostic as ParsedDiagnostic } from '@journeyapps/common-xml';
|
|
4
|
+
export interface ParsedValidationDiagnostic extends ParsedDiagnostic {
|
|
5
|
+
token?: ExpressionDiagnostic['token'];
|
|
6
|
+
}
|
|
7
|
+
export declare class ParsedDiagnosticStore {
|
|
8
|
+
private readonly diagnostics;
|
|
9
|
+
pushError({ message, element, type }: ParsedDiagnostic): ParsedDiagnostic;
|
|
10
|
+
errors(): ParsedDiagnostic[];
|
|
11
|
+
hasErrors(): boolean;
|
|
12
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
2
|
+
import { TreeNode, TreeNodeListener } from '@journeyapps/common-tree';
|
|
3
|
+
import { XMLParseEvent } from '../XMLParseEvent';
|
|
4
|
+
import { XMLElement } from '@journeyapps/domparser/lib';
|
|
5
|
+
import { V5Node } from '../nodes/V5Node';
|
|
6
|
+
import { ParsedAttribute } from './ParsedAttribute';
|
|
7
|
+
import { ParsedDiagnostic, ParsedValidationDiagnostic } from './ParsedDiagnostic';
|
|
8
|
+
import type { ValidationContext } from '@ja-platform/parser-expressions';
|
|
9
|
+
import { ParsedChild, ParsedChildNamesMarker, ParsedNodeAttribute, ParsedNodeAttributeShape, ParsedNodeAttributeName, ParsedNodeChild, ParsedNodeDefinition, ParsedNodeExpressionKey, ParsedNodeKnownChildKey, ParsedNodeValue, ParsedNodeValueRequest, ParsedNodeValueRequestKey, ParsedNodeRequiredAttributeName, ParsedNodeShape, ParsedNodeUntypedExpressionKey } from './ParsedNodeTypes';
|
|
10
|
+
import { ParsedValue } from '../values/ParsedValue';
|
|
11
|
+
import { AbstractValueProvider } from '../values/AbstractValueProvider';
|
|
12
|
+
export interface ParsedNodeOptions {
|
|
13
|
+
definition: V5Node<any>;
|
|
14
|
+
event: XMLParseEvent<ParsedNode>;
|
|
15
|
+
key?: string;
|
|
16
|
+
valueProviders?: readonly AbstractValueProvider[];
|
|
17
|
+
}
|
|
18
|
+
export interface ParsedNodeValidationContext {
|
|
19
|
+
scope: ValidationContext;
|
|
20
|
+
}
|
|
21
|
+
export interface NodeValidationEvent<Shape extends ParsedNodeShape = ParsedNodeShape, Value = ParsedNodeValue<Shape>> {
|
|
22
|
+
node: ParsedNode<Shape, Value>;
|
|
23
|
+
context: NodeValidationContext;
|
|
24
|
+
}
|
|
25
|
+
export interface NodeValidationContext {
|
|
26
|
+
readonly scope: ValidationContext;
|
|
27
|
+
report(diagnostic: ParsedValidationDiagnostic): void;
|
|
28
|
+
}
|
|
29
|
+
export interface ParsedNodeListener<Shape extends ParsedNodeShape = ParsedNodeShape, Value = ParsedNodeValue<Shape>> extends TreeNodeListener {
|
|
30
|
+
/**
|
|
31
|
+
* Report diagnostics and introduce child scopes before validating expressions and descendants.
|
|
32
|
+
* Hooks run in registration order during explicit validation, independently of parsing.
|
|
33
|
+
*/
|
|
34
|
+
preValidation?(event: NodeValidationEvent<Shape, Value>): void;
|
|
35
|
+
/**
|
|
36
|
+
* Validate this node after its expressions and descendants using the resulting context.
|
|
37
|
+
*/
|
|
38
|
+
postValidation?(event: NodeValidationEvent<Shape, Value>): void;
|
|
39
|
+
}
|
|
40
|
+
export declare class ParsedNode<T extends ParsedNodeShape = ParsedNodeShape, Value = ParsedNodeValue<T>> extends TreeNode<ParsedNodeListener<any, any>> {
|
|
41
|
+
private readonly parsedValues;
|
|
42
|
+
private attributesByKey;
|
|
43
|
+
private childrenByKey;
|
|
44
|
+
private valueProviders?;
|
|
45
|
+
readonly definition: ParsedNodeDefinition<T>;
|
|
46
|
+
readonly sourceElement: XMLElement;
|
|
47
|
+
readonly parseParentNode?: ParsedNode;
|
|
48
|
+
private parsedContent;
|
|
49
|
+
private readonly diagnostics;
|
|
50
|
+
private readonly reportError;
|
|
51
|
+
constructor(options: ParsedNodeOptions);
|
|
52
|
+
get type(): string;
|
|
53
|
+
registerListener(listener: Partial<ParsedNodeListener<T, Value>>): () => void;
|
|
54
|
+
get children(): ParsedNode[];
|
|
55
|
+
getRoot(): ParsedNode;
|
|
56
|
+
get parsedValueProviders(): readonly AbstractValueProvider[] | undefined;
|
|
57
|
+
setValueProviders(providers: readonly AbstractValueProvider[]): this;
|
|
58
|
+
value<const Keys extends readonly ParsedNodeValueRequestKey<T, Value>[]>(attributes: Keys): ParsedNodeValuesLike<ParsedNodeValueRequest<T, Value, Keys>>;
|
|
59
|
+
value<RequestedValue = any>(attributes: readonly ParsedNodeUntypedExpressionKey<T>[]): ParsedNodeValuesLike<RequestedValue>;
|
|
60
|
+
/**
|
|
61
|
+
* Resolve this node's attributes and descendants through their value providers.
|
|
62
|
+
* Include declared defaults for absent children without creating parsed nodes.
|
|
63
|
+
*/
|
|
64
|
+
valueTree(): ParsedNodeValuesLike<Value>;
|
|
65
|
+
/**
|
|
66
|
+
* Collect retained attribute sources for a value container to own and release.
|
|
67
|
+
*/
|
|
68
|
+
protected collectAttributeValues(attributeKeys: readonly string[]): Array<readonly [string, ParsedValue<unknown>]>;
|
|
69
|
+
attribute<Key extends Extract<ParsedNodeRequiredAttributeName<T>, ParsedNodeExpressionKey<T>>>(key: Key): ParsedNodeAttribute<T, Key>;
|
|
70
|
+
attribute<Key extends Exclude<ParsedNodeExpressionKey<T>, ParsedNodeRequiredAttributeName<T>>>(key: Key): ParsedNodeAttribute<T, Key> | undefined;
|
|
71
|
+
attribute<Attribute extends ParsedAttribute = ParsedAttribute>(key: string): Attribute | undefined;
|
|
72
|
+
attrExpression<Key extends ParsedNodeExpressionKey<T>>(key: Key): ParsedNodeAttributeShape<T>[Key] | undefined;
|
|
73
|
+
attrExpression<Value = any>(key: ParsedNodeUntypedExpressionKey<T>): Value | undefined;
|
|
74
|
+
attributes(): ParsedAttribute[];
|
|
75
|
+
attributes<const Names extends readonly ParsedNodeAttributeName<T>[]>(names: Names): ParsedAttribute[];
|
|
76
|
+
content(): any;
|
|
77
|
+
setContent(content: any): this;
|
|
78
|
+
/**
|
|
79
|
+
* Validate attribute expressions and descendants against the supplied scope.
|
|
80
|
+
* Diagnostics are returned without changing parse errors or reading values.
|
|
81
|
+
*/
|
|
82
|
+
validate({ scope }: ParsedNodeValidationContext): ParsedValidationDiagnostic[];
|
|
83
|
+
pushError({ message, element, type }: ParsedDiagnostic): ParsedDiagnostic;
|
|
84
|
+
reportDiagnostic(diagnostic: ParsedDiagnostic): void;
|
|
85
|
+
errors(options?: {
|
|
86
|
+
deep?: boolean;
|
|
87
|
+
}): ParsedDiagnostic[];
|
|
88
|
+
hasErrors(options?: {
|
|
89
|
+
deep?: boolean;
|
|
90
|
+
}): boolean;
|
|
91
|
+
child(key: string): ParsedChild | undefined;
|
|
92
|
+
setChild(key: string, child: ParsedChild): this;
|
|
93
|
+
removeChild(key: string): this;
|
|
94
|
+
setAttribute(attribute: ParsedAttribute): this;
|
|
95
|
+
node<Key extends ParsedNodeKnownChildKey<T>>(key: Key): ParsedNodeChild<T, Key> | undefined;
|
|
96
|
+
node<Child extends ParsedChild = ParsedChild>(key: T extends ParsedChildNamesMarker<any> ? never : string): Child | undefined;
|
|
97
|
+
childEntries(): ParsedChild[];
|
|
98
|
+
nodes(): ParsedNode[];
|
|
99
|
+
private flattenParsedArray;
|
|
100
|
+
private getParsedValue;
|
|
101
|
+
private addParsedAttribute;
|
|
102
|
+
private addParsedChild;
|
|
103
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ConstantExpression, FormatStringExpression, AbstractExpression } from '@ja-platform/parser-expressions';
|
|
2
|
+
import type { V5Node } from '../nodes/V5Node';
|
|
3
|
+
import type { ParsedArrayNode } from './ParsedArrayNode';
|
|
4
|
+
import type { ParsedAttribute } from './ParsedAttribute';
|
|
5
|
+
import type { ParsedNode } from './ParsedNode';
|
|
6
|
+
export type ParsedChild = ParsedNode<any, any> | ParsedArrayNode<any>;
|
|
7
|
+
export type ParsedExpression = AbstractExpression;
|
|
8
|
+
export interface ParsedNodeShape {
|
|
9
|
+
[key: string]: ParsedNodeShapeValue;
|
|
10
|
+
}
|
|
11
|
+
declare const ParsedAttributeNamesSymbol: unique symbol;
|
|
12
|
+
declare const ParsedExpressionNamesSymbol: unique symbol;
|
|
13
|
+
declare const ParsedImplicitExpressionNamesSymbol: unique symbol;
|
|
14
|
+
declare const ParsedChildNamesSymbol: unique symbol;
|
|
15
|
+
declare const ParsedRequiredAttributeNamesSymbol: unique symbol;
|
|
16
|
+
declare const ParsedConstantAttributeNamesSymbol: unique symbol;
|
|
17
|
+
export interface ParsedAttributeNamesMarker<Names extends string> {
|
|
18
|
+
readonly [ParsedAttributeNamesSymbol]?: Names;
|
|
19
|
+
}
|
|
20
|
+
export interface ParsedExpressionNamesMarker<Names extends string> {
|
|
21
|
+
readonly [ParsedExpressionNamesSymbol]?: Names;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Expression names contributed by a specialized node independently of its declared fields.
|
|
25
|
+
*/
|
|
26
|
+
export interface ParsedImplicitExpressionNamesMarker<Names extends string> {
|
|
27
|
+
readonly [ParsedImplicitExpressionNamesSymbol]?: Names;
|
|
28
|
+
}
|
|
29
|
+
type ParsedImplicitExpressionName<Shape> = Shape extends ParsedImplicitExpressionNamesMarker<infer Names> ? Names : never;
|
|
30
|
+
export interface ParsedChildNamesMarker<Names extends string> {
|
|
31
|
+
readonly [ParsedChildNamesSymbol]?: Names;
|
|
32
|
+
}
|
|
33
|
+
export interface ParsedRequiredAttributeNamesMarker<Names extends string> {
|
|
34
|
+
readonly [ParsedRequiredAttributeNamesSymbol]?: Names;
|
|
35
|
+
}
|
|
36
|
+
export interface ParsedConstantAttributeNamesMarker<Names extends string> {
|
|
37
|
+
readonly [ParsedConstantAttributeNamesSymbol]?: Names;
|
|
38
|
+
}
|
|
39
|
+
export type ParsedNodeAttributeName<T> = T extends ParsedAttributeNamesMarker<infer Names> ? Names : string;
|
|
40
|
+
export type ParsedNodeExpressionName<T> = T extends ParsedExpressionNamesMarker<infer Names> ? Names : never;
|
|
41
|
+
export type ParsedNodeChildName<T> = T extends ParsedChildNamesMarker<infer Names> ? Names : never;
|
|
42
|
+
export type ParsedNodeRequiredAttributeName<T> = T extends ParsedRequiredAttributeNamesMarker<infer Names> ? Names : never;
|
|
43
|
+
export type ParsedNodeConstantAttributeName<T> = T extends ParsedConstantAttributeNamesMarker<infer Names> ? Names : never;
|
|
44
|
+
export type ParsedNodeShapeValue = ParsedExpression | ParsedNode<any, any> | ParsedArrayNode<any> | ParsedNodeShapeValue[] | null | undefined;
|
|
45
|
+
export type ParsedNodeDefinition<T> = V5Node<any>;
|
|
46
|
+
export type ParsedNodeAttributeShape<T> = T extends V5Node ? ParsedNodeShape : T;
|
|
47
|
+
export type ParsedNodeShapeKey<Shape> = Extract<keyof ParsedNodeAttributeShape<Shape>, string>;
|
|
48
|
+
export type ParsedNodeChildKey<Shape> = {
|
|
49
|
+
[Key in ParsedNodeShapeKey<Shape>]: NonNullable<ParsedNodeAttributeShape<Shape>[Key]> extends ParsedChild ? Key : never;
|
|
50
|
+
}[ParsedNodeShapeKey<Shape>];
|
|
51
|
+
export type ParsedNodeKnownChildKey<Shape> = Shape extends ParsedChildNamesMarker<any> ? Extract<ParsedNodeChildName<Shape>, ParsedNodeShapeKey<Shape>> : ParsedNodeChildKey<Shape>;
|
|
52
|
+
export type ParsedNodeExpressionKey<Shape> = Shape extends ParsedExpressionNamesMarker<any> ? Extract<ParsedNodeExpressionName<Shape> | ParsedImplicitExpressionName<Shape>, ParsedNodeShapeKey<Shape>> : Exclude<ParsedNodeShapeKey<Shape>, ParsedNodeChildKey<Shape>>;
|
|
53
|
+
export type ParsedNodeUntypedExpressionKey<Shape> = string extends ParsedNodeExpressionKey<Shape> ? string : never;
|
|
54
|
+
export type ParsedNodeAttribute<Shape, Key extends ParsedNodeExpressionKey<Shape>> = Key extends ParsedNodeConstantAttributeName<Shape> ? ParsedAttribute<Extract<ParsedNodeAttributeShape<Shape>[Key], ConstantExpression<any> | null>> : ParsedAttribute<ParsedNodeAttributeShape<Shape>[Key]>;
|
|
55
|
+
export type ParsedNodeChild<Shape, Key extends ParsedNodeKnownChildKey<Shape>> = Extract<NonNullable<ParsedNodeAttributeShape<Shape>[Key]>, ParsedChild>;
|
|
56
|
+
export type ParsedExpressionValue<Value> = Value extends null | undefined ? Value : Value extends ConstantExpression<any> ? ReturnType<Value['value']> : Value extends FormatStringExpression ? string : Value extends AbstractExpression ? any : Value extends ParsedNode<any, infer NodeValue> ? NodeValue : Value extends ParsedArrayNode<infer Child> ? Child extends ParsedNode<any, infer ChildValue> ? ChildValue[] : Child extends ParsedArrayNode<infer NestedChild> ? ParsedExpressionValue<ParsedArrayNode<NestedChild>>[] : ParsedNodeValue<ParsedNodeShape>[] : Value extends Array<infer Item> ? ParsedExpressionValue<Item>[] : Value;
|
|
57
|
+
export type ParsedNodeValue<Shape = ParsedNodeShape> = {
|
|
58
|
+
[Key in keyof Shape]?: ParsedExpressionValue<Shape[Key]>;
|
|
59
|
+
};
|
|
60
|
+
export type ParsedNodeValueRequestKey<Shape, Value> = Extract<ParsedNodeExpressionKey<Shape>, (keyof Value & string) | ParsedImplicitExpressionName<Shape>>;
|
|
61
|
+
export type ParsedNodeValueRequest<Shape, Value, Keys extends readonly ParsedNodeValueRequestKey<Shape, Value>[]> = Pick<Value & {
|
|
62
|
+
[Key in ParsedImplicitExpressionName<Shape>]?: Key extends keyof ParsedNodeAttributeShape<Shape> ? ParsedExpressionValue<ParsedNodeAttributeShape<Shape>[Key]> : never;
|
|
63
|
+
}, Keys[number]>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseObserver } from '@journeyapps/common-utils';
|
|
2
|
+
import type { ParsedAttribute } from '../parsed/ParsedAttribute';
|
|
3
|
+
import { ParsedProviderValue } from './ParsedProviderValue';
|
|
4
|
+
export interface ParsedValueProviderListener {
|
|
5
|
+
dirty?: () => any;
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class AbstractValueProvider extends BaseObserver<ParsedValueProviderListener> {
|
|
8
|
+
private readonly providerValues;
|
|
9
|
+
constructor();
|
|
10
|
+
dispose(): void;
|
|
11
|
+
value<T>(attribute: ParsedAttribute): ParsedProviderValue<T>;
|
|
12
|
+
protected refreshProviderValues(resolve: (attribute: ParsedAttribute) => any): void;
|
|
13
|
+
protected getProviderValues<TValue extends ParsedProviderValue<any> = ParsedProviderValue<any>>(): TValue[];
|
|
14
|
+
protected fireDirty(): void;
|
|
15
|
+
protected abstract createProviderValue<T>(attribute: ParsedAttribute): ParsedProviderValue<T>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ParsedAttribute } from '../parsed/ParsedAttribute';
|
|
2
|
+
import { AbstractValueProvider } from './AbstractValueProvider';
|
|
3
|
+
import { ParsedProviderValue } from './ParsedProviderValue';
|
|
4
|
+
/**
|
|
5
|
+
* Resolve literal expressions synchronously without an evaluation scope.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ConstantExpressionValueProvider extends AbstractValueProvider {
|
|
8
|
+
protected createProviderValue<T>(attribute: ParsedAttribute): ParsedProviderValue<T>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseObserver } from '@journeyapps/common-utils';
|
|
2
|
+
export interface ParsedNodeValuesListener<T> {
|
|
3
|
+
changed?: (value: T) => void;
|
|
4
|
+
disposed?: () => void;
|
|
5
|
+
}
|
|
6
|
+
export interface ParsedNodeValuesLike<T> {
|
|
7
|
+
readonly current: T;
|
|
8
|
+
registerListener(listener: Partial<ParsedNodeValuesListener<T>>): () => void;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Combine attribute or descendant values into one disposable value.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ParsedNodeValues<T> extends BaseObserver<ParsedNodeValuesListener<T>> implements ParsedNodeValuesLike<T> {
|
|
15
|
+
private readonly sources;
|
|
16
|
+
private readonly compose;
|
|
17
|
+
current: T;
|
|
18
|
+
private readonly deregister;
|
|
19
|
+
private disposed;
|
|
20
|
+
constructor(sources: readonly ParsedNodeValuesLike<unknown>[], compose: (values: readonly unknown[]) => T);
|
|
21
|
+
update(value: T): void;
|
|
22
|
+
dispose(): void;
|
|
23
|
+
private read;
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BaseObserver } from '@journeyapps/common-utils';
|
|
2
|
+
import type { AbstractValueProvider } from './AbstractValueProvider';
|
|
3
|
+
export interface ParsedProviderValueListener<T> {
|
|
4
|
+
changed?: (value: T | undefined) => void;
|
|
5
|
+
disposed?: () => void;
|
|
6
|
+
activeChanged?: (active: boolean) => void;
|
|
7
|
+
}
|
|
8
|
+
export interface ParsedProviderValueOptions<T> {
|
|
9
|
+
value?: T;
|
|
10
|
+
active: boolean;
|
|
11
|
+
provider?: AbstractValueProvider;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* One provider's contribution. Activity is independent of its stored value and subscription lifetime.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ParsedProviderValue<T> extends BaseObserver<ParsedProviderValueListener<T>> {
|
|
17
|
+
current: T | undefined;
|
|
18
|
+
active: boolean;
|
|
19
|
+
private disposed;
|
|
20
|
+
readonly provider?: AbstractValueProvider;
|
|
21
|
+
constructor(options: ParsedProviderValueOptions<T>);
|
|
22
|
+
/**
|
|
23
|
+
* Change the stored value without changing whether this contribution is active.
|
|
24
|
+
*/
|
|
25
|
+
setValue(value: T | undefined): void;
|
|
26
|
+
/**
|
|
27
|
+
* Change activity without changing the stored value.
|
|
28
|
+
*/
|
|
29
|
+
setActive(active: boolean): void;
|
|
30
|
+
dispose(): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BaseObserver } from '@journeyapps/common-utils';
|
|
2
|
+
import type { AbstractValueProvider } from './AbstractValueProvider';
|
|
3
|
+
import { ParsedAttribute } from '../parsed/ParsedAttribute';
|
|
4
|
+
import { ParsedProviderValue } from './ParsedProviderValue';
|
|
5
|
+
export interface ParsedValueListener<T> {
|
|
6
|
+
changed?: (value: T) => void;
|
|
7
|
+
disposed?: () => void;
|
|
8
|
+
}
|
|
9
|
+
export interface ParsedValueLike<T> {
|
|
10
|
+
readonly current: T;
|
|
11
|
+
registerListener(listener: Partial<ParsedValueListener<T>>): () => void;
|
|
12
|
+
dispose(): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates contributions from providers ordered from lowest to highest priority.
|
|
16
|
+
* Subscribes to every contribution and caches the last active value.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ParsedValue<T> extends BaseObserver<ParsedValueListener<T | undefined>> {
|
|
19
|
+
private readonly attribute;
|
|
20
|
+
current: T | undefined;
|
|
21
|
+
readonly providerValues: readonly ParsedProviderValue<unknown>[];
|
|
22
|
+
private retainCount;
|
|
23
|
+
private released;
|
|
24
|
+
private readonly deregister;
|
|
25
|
+
private selected?;
|
|
26
|
+
constructor(attribute: ParsedAttribute, providers: readonly AbstractValueProvider[]);
|
|
27
|
+
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
|
+
dispose(): void;
|
|
37
|
+
private refresh;
|
|
38
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ParsedAttribute } from '../parsed/ParsedAttribute';
|
|
2
|
+
import { AbstractValueProvider } from './AbstractValueProvider';
|
|
3
|
+
import { ParsedProviderValue } from './ParsedProviderValue';
|
|
4
|
+
/**
|
|
5
|
+
* Resolve declared defaults as literal values, including null and falsy values.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ParserDefaultValueProvider extends AbstractValueProvider {
|
|
8
|
+
protected createProviderValue<T>(attribute: ParsedAttribute): ParsedProviderValue<T>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttributeParseEvent.js","sourceRoot":"","sources":["../src/AttributeParseEvent.ts"],"names":[],"mappings":"","sourcesContent":["import type { XMLPositional } from '@journeyapps/common-xml';\nimport type { XMLParseEvent } from './XMLParseEvent';\nimport type { ParsedNode } from './parsed/ParsedNode';\n\nexport interface AttributeParseInput {\n value: string | null;\n source: XMLPositional;\n}\n\n/**\n * An XML parse event with the input selected for an attribute codec.\n */\nexport interface AttributeParseEvent<Node extends ParsedNode<any, any> = any> extends XMLParseEvent<Node> {\n input: AttributeParseInput & { value: string };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"XMLParseEvent.js","sourceRoot":"","sources":["../src/XMLParseEvent.ts"],"names":[],"mappings":"","sourcesContent":["import type { ParsedDiagnostic } from './parsed/ParsedDiagnostic';\nimport type { XMLElement } from '@journeyapps/domparser/types';\nimport type {\n AbstractExpression,\n ValidationContext,\n FormatStringExpression,\n EvaluatedExpression\n} from '@ja-platform/parser-expressions';\nimport type { ParsedNode } from './parsed/ParsedNode';\nimport type { V5Attribute } from './attributes/V5Attribute';\n\nexport interface XMLParseEventHelper<\n Node extends ParsedNode = ParsedNode,\n Scope extends ValidationContext = ValidationContext,\n Expression extends AbstractExpression = FormatStringExpression | EvaluatedExpression\n> {\n /**\n * Resolve context-specific syntax before using the attribute's parser.\n */\n parseAttributeExpression?({\n attribute,\n source\n }: {\n attribute: V5Attribute;\n source: string;\n }): AbstractExpression | undefined;\n /**\n * Prepare a node after its attributes and before its children are parsed.\n */\n prepareNode?(node: Node): void;\n validateFormatAttribute?({\n element,\n attribute,\n scope,\n expression\n }: {\n element: XMLElement;\n attribute: string;\n scope: Scope;\n expression: Expression;\n }): void;\n validateFormatContent?({\n element,\n scope,\n expression\n }: {\n element: XMLElement;\n scope: Scope;\n expression: Expression;\n }): void;\n pushError(diagnostic: ParsedDiagnostic): void;\n}\n\nexport interface XMLParseEvent<ParentNode, Helper extends XMLParseEventHelper = XMLParseEventHelper> {\n element: XMLElement;\n parentNode?: ParentNode;\n parsedNode?: ParentNode;\n scope?: ValidationContext;\n helper: Helper;\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fanDefaultValue = fanDefaultValue;
|
|
4
|
+
const V5Attribute_1 = require("./V5Attribute");
|
|
5
|
+
/**
|
|
6
|
+
* Normalize a scalar declaration to all supported size variants.
|
|
7
|
+
*/
|
|
8
|
+
function fanDefaultValue(defaultValue) {
|
|
9
|
+
return {
|
|
10
|
+
[V5Attribute_1.ComponentSize.SMALL]: defaultValue,
|
|
11
|
+
[V5Attribute_1.ComponentSize.MEDIUM]: defaultValue,
|
|
12
|
+
[V5Attribute_1.ComponentSize.LARGE]: defaultValue
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=AttributeDefaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttributeDefaults.js","sourceRoot":"","sources":["../../src/attributes/AttributeDefaults.ts"],"names":[],"mappings":";;;AAAA,+CAA8C;AAE9C;;GAEG;AACH,yBAAmC,YAAe;IAChD,OAAO;QACL,CAAC,2BAAa,CAAC,KAAK,CAAC,EAAE,YAAY;QACnC,CAAC,2BAAa,CAAC,MAAM,CAAC,EAAE,YAAY;QACpC,CAAC,2BAAa,CAAC,KAAK,CAAC,EAAE,YAAY;KACpC,CAAC;AACJ,CAAC","sourcesContent":["import { ComponentSize } from './V5Attribute';\n\n/**\n * Normalize a scalar declaration to all supported size variants.\n */\nexport function fanDefaultValue<T>(defaultValue: T): { [k in ComponentSize]: T } {\n return {\n [ComponentSize.SMALL]: defaultValue,\n [ComponentSize.MEDIUM]: defaultValue,\n [ComponentSize.LARGE]: defaultValue\n };\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConditionType = void 0;
|
|
4
|
+
const parser_type_system_1 = require("@ja-platform/parser-type-system");
|
|
5
|
+
/**
|
|
6
|
+
* Convert resolved conditions, including the presence of objects and non-boolean fields.
|
|
7
|
+
* Literal boolean syntax is validated separately by BooleanType.
|
|
8
|
+
*/
|
|
9
|
+
class ConditionType extends parser_type_system_1.BooleanType {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this._typeName = 'condition';
|
|
13
|
+
this.name = 'condition';
|
|
14
|
+
}
|
|
15
|
+
parse(value) {
|
|
16
|
+
if (typeof value === 'boolean' ||
|
|
17
|
+
typeof value === 'number' ||
|
|
18
|
+
(typeof value === 'string' &&
|
|
19
|
+
(['true', 'false'].includes(value.trim()) || (value.trim() !== '' && Number.isFinite(Number(value)))))) {
|
|
20
|
+
return super.parse(value);
|
|
21
|
+
}
|
|
22
|
+
return !!value;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.ConditionType = ConditionType;
|
|
26
|
+
//# sourceMappingURL=ConditionType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConditionType.js","sourceRoot":"","sources":["../../src/attributes/ConditionType.ts"],"names":[],"mappings":";;;AAAA,wEAA8D;AAE9D;;;GAGG;AACH,mBAA2B,SAAQ,gCAAW;IAA9C;;QACW,cAAS,GAAG,WAAW,CAAC;QACxB,SAAI,GAAG,WAAW,CAAC;IAa9B,CAAC;IAXC,KAAK,CAAC,KAAc;QAClB,IACE,OAAO,KAAK,KAAK,SAAS;YAC1B,OAAO,KAAK,KAAK,QAAQ;YACzB,CAAC,OAAO,KAAK,KAAK,QAAQ;gBACxB,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EACxG,CAAC;YACD,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,CAAC,CAAC,KAAK,CAAC;IACjB,CAAC;CACF","sourcesContent":["import { BooleanType } from '@ja-platform/parser-type-system';\n\n/**\n * Convert resolved conditions, including the presence of objects and non-boolean fields.\n * Literal boolean syntax is validated separately by BooleanType.\n */\nexport class ConditionType extends BooleanType {\n readonly _typeName = 'condition';\n readonly name = 'condition';\n\n parse(value: unknown): boolean {\n if (\n typeof value === 'boolean' ||\n typeof value === 'number' ||\n (typeof value === 'string' &&\n (['true', 'false'].includes(value.trim()) || (value.trim() !== '' && Number.isFinite(Number(value)))))\n ) {\n return super.parse(value);\n }\n return !!value;\n }\n}\n"]}
|