@ja-platform/parser-core 0.0.0-dev-20261021213526 → 0.0.0-dev-20261027003550

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.
Files changed (69) hide show
  1. package/README.md +50 -0
  2. package/dist/@types/AttributeParseEvent.d.ts +5 -14
  3. package/dist/@types/ParseEvent.d.ts +11 -0
  4. package/dist/@types/attributes/Attribute.d.ts +9 -5
  5. package/dist/@types/attributes/ContentTextAttribute.d.ts +4 -6
  6. package/dist/@types/attributes/TextAttribute.d.ts +2 -2
  7. package/dist/@types/index.d.ts +9 -1
  8. package/dist/@types/input/AttributeInput.d.ts +28 -0
  9. package/dist/@types/input/AttributeParseContext.d.ts +21 -0
  10. package/dist/@types/input/NodeInput.d.ts +35 -0
  11. package/dist/@types/nodes/ContentNode.d.ts +5 -5
  12. package/dist/@types/nodes/EitherNode.d.ts +32 -0
  13. package/dist/@types/nodes/Node.d.ts +19 -20
  14. package/dist/@types/nodes/NodeAlternatives.d.ts +7 -4
  15. package/dist/@types/nodes/RecordNode.d.ts +16 -0
  16. package/dist/@types/parsed/ParsedArrayNode.d.ts +6 -1
  17. package/dist/@types/parsed/ParsedAttribute.d.ts +5 -8
  18. package/dist/@types/parsed/ParsedDiagnostic.d.ts +7 -3
  19. package/dist/@types/parsed/ParsedEitherNode.d.ts +9 -0
  20. package/dist/@types/parsed/ParsedNode.d.ts +5 -7
  21. package/dist/@types/parsed/ParsedRecordNode.d.ts +6 -0
  22. package/dist/@types/source/SourceReference.d.ts +9 -0
  23. package/dist/AttributeParseEvent.js.map +1 -1
  24. package/dist/{XMLParseEvent.js → ParseEvent.js} +1 -1
  25. package/dist/ParseEvent.js.map +1 -0
  26. package/dist/attributes/Attribute.js +33 -55
  27. package/dist/attributes/Attribute.js.map +1 -1
  28. package/dist/attributes/ContentTextAttribute.js +9 -24
  29. package/dist/attributes/ContentTextAttribute.js.map +1 -1
  30. package/dist/attributes/NumberAttribute.js +1 -1
  31. package/dist/attributes/NumberAttribute.js.map +1 -1
  32. package/dist/attributes/TextAttribute.js +11 -9
  33. package/dist/attributes/TextAttribute.js.map +1 -1
  34. package/dist/index.js +9 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/input/AttributeInput.js +14 -0
  37. package/dist/input/AttributeInput.js.map +1 -0
  38. package/dist/input/AttributeParseContext.js +3 -0
  39. package/dist/input/AttributeParseContext.js.map +1 -0
  40. package/dist/input/NodeInput.js +14 -0
  41. package/dist/input/NodeInput.js.map +1 -0
  42. package/dist/nodes/ContentNode.js +13 -11
  43. package/dist/nodes/ContentNode.js.map +1 -1
  44. package/dist/nodes/EitherNode.js +95 -0
  45. package/dist/nodes/EitherNode.js.map +1 -0
  46. package/dist/nodes/Node.js +44 -37
  47. package/dist/nodes/Node.js.map +1 -1
  48. package/dist/nodes/NodeAlternatives.js +28 -21
  49. package/dist/nodes/NodeAlternatives.js.map +1 -1
  50. package/dist/nodes/RecordNode.js +36 -0
  51. package/dist/nodes/RecordNode.js.map +1 -0
  52. package/dist/parsed/ParsedArrayNode.js +9 -5
  53. package/dist/parsed/ParsedArrayNode.js.map +1 -1
  54. package/dist/parsed/ParsedAttribute.js +8 -6
  55. package/dist/parsed/ParsedAttribute.js.map +1 -1
  56. package/dist/parsed/ParsedDiagnostic.js +4 -2
  57. package/dist/parsed/ParsedDiagnostic.js.map +1 -1
  58. package/dist/parsed/ParsedEitherNode.js +16 -0
  59. package/dist/parsed/ParsedEitherNode.js.map +1 -0
  60. package/dist/parsed/ParsedNode.js +15 -12
  61. package/dist/parsed/ParsedNode.js.map +1 -1
  62. package/dist/parsed/ParsedRecordNode.js +14 -0
  63. package/dist/parsed/ParsedRecordNode.js.map +1 -0
  64. package/dist/source/SourceReference.js +3 -0
  65. package/dist/source/SourceReference.js.map +1 -0
  66. package/dist/tsconfig.tsbuildinfo +1 -1
  67. package/package.json +5 -6
  68. package/dist/@types/XMLParseEvent.d.ts +0 -37
  69. package/dist/XMLParseEvent.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ParseEvent.js","sourceRoot":"","sources":["../src/ParseEvent.ts"],"names":[],"mappings":"","sourcesContent":["import type { NodeInput } from './input/NodeInput';\nimport type { AttributeParseContext } from './input/AttributeParseContext';\nimport type { ParsedNode } from './parsed/ParsedNode';\nimport type { ValidationContext } from '@ja-platform/parser-expressions';\n\nexport interface ParseEvent extends AttributeParseContext {\n input?: NodeInput;\n parsedNode?: ParsedNode;\n scope?: ValidationContext;\n /** Prepare a node after its attributes and before its children are parsed. */\n prepareNode?(node: ParsedNode): void;\n}\n"]}
@@ -1,40 +1,7 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.Attribute = void 0;
37
- const xml = __importStar(require("@journeyapps/common-xml"));
4
+ const AttributeInput_1 = require("../input/AttributeInput");
38
5
  const parser_expressions_1 = require("@ja-platform/parser-expressions");
39
6
  const parser_type_system_1 = require("@ja-platform/parser-type-system");
40
7
  const CommonEntity_1 = require("../entities/CommonEntity");
@@ -84,10 +51,10 @@ class Attribute extends CommonEntity_1.CommonEntity {
84
51
  serialize() {
85
52
  return Object.assign(Object.assign({}, super.serialize()), { required: this.options.required, defaultValue: this.options.defaultValue, docs: this.options.docs, type: 'standard', advanced: !!this.options.advanced });
86
53
  }
87
- getParsedValue(event, _parseContext) {
54
+ getParsedValue(event) {
88
55
  var _a, _b;
89
56
  var _c;
90
- return ((_c = (_b = (_a = event.helper).parseAttributeExpression) === null || _b === void 0 ? void 0 : _b.call(_a, { attribute: this, source: event.input.value })) !== null && _c !== void 0 ? _c : this.options.syntax.parse(event.input.value));
57
+ return ((_c = (_b = (_a = event.context) === null || _a === void 0 ? void 0 : _a.parseAttributeExpression) === null || _b === void 0 ? void 0 : _b.call(_a, { attribute: this, source: event.input.value })) !== null && _c !== void 0 ? _c : this.options.syntax.parse(event.input.value));
91
58
  }
92
59
  stringify(value, parent) {
93
60
  if (value == null) {
@@ -104,38 +71,49 @@ class Attribute extends CommonEntity_1.CommonEntity {
104
71
  createParsedAttribute(options) {
105
72
  return new ParsedAttribute_1.ParsedAttribute(options);
106
73
  }
107
- getInput(event) {
108
- var _a;
109
- return {
110
- value: event.element == null ? null : xml.getAttribute(event.element, this.options.name),
111
- source: event.element == null ? null : ((_a = xml.attributeNode(event.element, this.options.name)) !== null && _a !== void 0 ? _a : event.element)
112
- };
74
+ getInput(node) {
75
+ return node === null || node === void 0 ? void 0 : node.attribute(this.name);
76
+ }
77
+ parse(node, context) {
78
+ return this.parseInput(this.getInput(node), context);
113
79
  }
114
- parse(event, parseContext = {}) {
115
- const input = this.getInput(event);
80
+ /** Instantiate an attribute from document input, or from its definition alone. */
81
+ parseInput(input, context) {
82
+ var _a;
83
+ var _b;
116
84
  let expression = null;
117
85
  let failure;
118
86
  try {
119
- if (input.value != null) {
120
- expression = this.getParsedValue(Object.assign(Object.assign({}, event), { input: Object.assign(Object.assign({}, input), { value: input.value }) }), parseContext);
87
+ if ((input === null || input === void 0 ? void 0 : input.kind) === AttributeInput_1.AttributeInputKind.LITERAL) {
88
+ const valueType = this.options.valueType;
89
+ if (!valueType) {
90
+ throw new SyntaxError(`Attribute ${this.name} does not support native literal input`);
91
+ }
92
+ expression = new parser_expressions_1.ConstantExpression({
93
+ value: valueType.parse(input.value),
94
+ valueType,
95
+ tokens: [],
96
+ start: (_b = (_a = input.source) === null || _a === void 0 ? void 0 : _a.range.start) !== null && _b !== void 0 ? _b : 0
97
+ });
98
+ }
99
+ else if (input) {
100
+ expression = this.getParsedValue({ input, context });
121
101
  }
122
102
  }
123
103
  catch (error) {
124
- if (!(error instanceof SyntaxError)) {
104
+ if (!(error instanceof SyntaxError))
125
105
  throw error;
126
- }
127
106
  failure = error;
128
107
  }
129
- const parsedAttribute = this.createParsedAttribute({
108
+ const parsed = this.createParsedAttribute({
130
109
  definition: this,
131
- event,
132
110
  expression,
133
- parseContext
111
+ input,
112
+ reportError: (diagnostic) => context === null || context === void 0 ? void 0 : context.report(diagnostic)
134
113
  });
135
- if (failure) {
136
- parsedAttribute.pushError({ message: failure.message, element: input.source });
137
- }
138
- return parsedAttribute;
114
+ if (failure)
115
+ parsed.pushError({ message: failure.message });
116
+ return parsed;
139
117
  }
140
118
  }
141
119
  exports.Attribute = Attribute;
@@ -1 +1 @@
1
- {"version":3,"file":"Attribute.js","sourceRoot":"","sources":["../../src/attributes/Attribute.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAY,GAAG,oDAAgC;AAC/C,wEASyC;AACzC,wEAAiE;AACjE,2DAAmG;AAEnG,+DAAoF;AA2DpF,eAAwE,SAAQ,2BAAe;IAK7F,YAAY,IAAY,EA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AAC,CAAC;QACjF,CAAC;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;;AAnIQ,cAAI,GAAG,gBAAgB,CAAC","sourcesContent":["import { AttributeParseEvent, AttributeParseInput } from '../AttributeParseEvent';\nimport { XMLParseEvent } from '../XMLParseEvent';\nimport * as xml from '@journeyapps/common-xml';\nimport {\n AbstractExpression,\n ExpressionParser,\n ConstantExpression,\n EvaluatedExpression,\n CombinedParser,\n FunctionExpressionParser,\n EvaluatedExpressionParser,\n ConstantExpressionParser\n} from '@ja-platform/parser-expressions';\nimport { Type, textType } from '@ja-platform/parser-type-system';\nimport { CommonEntity, CommonEntityListener, CommonEntityOptions } from '../entities/CommonEntity';\nimport { Node } from '../nodes/Node';\nimport { ParsedAttribute, ParsedAttributeOptions } from '../parsed/ParsedAttribute';\nimport { ParsedNode } from '../parsed/ParsedNode';\n\nexport type CombinedAttributeExpression = EvaluatedExpression | ConstantExpression<unknown>;\n\nexport interface AttributeListener extends CommonEntityListener {}\n\nexport interface NodeChecker {\n hasAttributeType(type: string): boolean;\n}\n\nexport interface AttributeOptions<DEFAULT = any, VALUE = unknown> extends CommonEntityOptions {\n /**\n * Accepted expression syntax. Defaults to prefixed code followed by constant text.\n */\n syntax?: ExpressionParser<AbstractExpression>;\n /**\n * Conversion and literal validation for the resolved attribute value.\n */\n valueType?: Type<VALUE>;\n required?: boolean;\n configurable?: boolean;\n advanced?: boolean;\n fragmentNamespace?: string;\n\n defaultValue?: DEFAULT;\n /**\n * The interim value to use when the component attribute is still being evaluated (ie. setting up watches),\n * will fallback to `defaultValue` if not set.\n */\n loadingValue?: DEFAULT;\n /**\n * By default autowatch is enabled, disable it if the attribute relies on parameters such as $object\n * (used quite often in query-widget) which need to have watches setup in virtual tables\n * @deprecated\n */\n autoWatch?: boolean;\n /**\n * Indicates that the attribute is considered deprecated\n */\n deprecated?: boolean;\n /**\n * Ensures that functions returned by this attribute will be mapped to string identifiers in the runtime\n */\n mapGeneratedFunctions?: boolean;\n}\n\nexport interface AttributeGenerics<O extends AttributeOptions = AttributeOptions> {\n Options: O;\n Listener: AttributeListener;\n Value: any;\n NormalizedValue: unknown;\n}\n\nexport interface StringifyDirective {\n isAttribute: boolean;\n value: string | null;\n}\n\nexport class Attribute<G extends AttributeGenerics = AttributeGenerics> extends CommonEntity<G> {\n static TYPE = 'base-attribute';\n parent: Node<any>;\n type: string;\n\n constructor(type: string, options: G['Options']) {\n super({\n ...options,\n syntax:\n options.syntax ??\n new CombinedParser<CombinedAttributeExpression>([\n new FunctionExpressionParser(),\n new EvaluatedExpressionParser(),\n new ConstantExpressionParser(options.valueType ?? textType)\n ]),\n autoWatch: options.autoWatch ?? true,\n configurable: options.configurable ?? false,\n advanced: options.advanced ?? false\n });\n this.type = type;\n }\n\n get key() {\n return this.options.key;\n }\n\n get defaultValue() {\n return this.options.defaultValue;\n }\n\n get name() {\n return this.options.name;\n }\n\n normalizeValue(value: unknown): G['NormalizedValue'] {\n return (this.options.valueType ? this.options.valueType.parse(value) : value) as G['NormalizedValue'];\n }\n\n isEnclosedWith(checkerCB: (helper: NodeChecker) => boolean) {\n let node: Node = this.parent;\n\n const checker: NodeChecker = {\n hasAttributeType(type: string): boolean {\n for (let attr of node.attributes) {\n if (attr.constructor.name === type) {\n return true;\n }\n }\n }\n };\n // keep checking the parent\n do {\n if (checkerCB(checker)) {\n return true;\n }\n\n node = node.parent;\n } while (!!node);\n return false;\n }\n\n serialize(): any {\n return {\n ...super.serialize(),\n required: this.options.required,\n defaultValue: this.options.defaultValue,\n\n docs: this.options.docs,\n type: 'standard',\n advanced: !!this.options.advanced\n };\n }\n\n protected getParsedValue(event: AttributeParseEvent, _parseContext?: Record<string, any>): G['Value'] {\n return (\n event.helper.parseAttributeExpression?.({ attribute: this, source: event.input.value }) ??\n this.options.syntax.parse(event.input.value)\n );\n }\n\n stringify(value: G['Value'], parent: ParsedNode): StringifyDirective {\n if (value == null) {\n return {\n isAttribute: true,\n value: null\n };\n }\n\n return {\n isAttribute: true,\n value: value.raw()\n };\n }\n\n createParsedAttribute(options: ParsedAttributeOptions<G['Value'], this>): ParsedAttribute<G['Value'], this> {\n return new ParsedAttribute(options);\n }\n\n protected getInput(event: XMLParseEvent<ParsedNode>): AttributeParseInput {\n return {\n value: event.element == null ? null : xml.getAttribute(event.element, this.options.name),\n source: event.element == null ? null : (xml.attributeNode(event.element, this.options.name) ?? event.element)\n };\n }\n\n parse(event: XMLParseEvent<ParsedNode>, parseContext: Record<string, any> = {}) {\n const input = this.getInput(event);\n let expression: G['Value'] = null;\n let failure: SyntaxError;\n try {\n if (input.value != null) {\n expression = this.getParsedValue({ ...event, input: { ...input, value: input.value } }, parseContext);\n }\n } catch (error) {\n if (!(error instanceof SyntaxError)) {\n throw error;\n }\n failure = error;\n }\n\n const parsedAttribute = this.createParsedAttribute({\n definition: this,\n event,\n expression,\n parseContext\n });\n\n if (failure) {\n parsedAttribute.pushError({ message: failure.message, element: input.source });\n }\n return parsedAttribute;\n }\n}\n"]}
1
+ {"version":3,"file":"Attribute.js","sourceRoot":"","sources":["../../src/attributes/Attribute.ts"],"names":[],"mappings":";;;AAAA,4DAA6D;AAK7D,wEASyC;AACzC,wEAAiE;AACjE,2DAAmG;AAEnG,+DAAoF;AA2DpF,eAAwE,SAAQ,2BAAe;IAK7F,YAAY,IAAY,EAAE,OAAqB;;QAC7C,KAAK,iCACA,OAAO,KACV,MAAM,QACJ,OAAO,CAAC,MAAM,mCACd,IAAI,mCAAc,CAA8B;gBAC9C,IAAI,6CAAwB,EAAE;gBAC9B,IAAI,8CAAyB,EAAE;gBAC/B,IAAI,6CAAwB,OAAC,OAAO,CAAC,SAAS,mCAAI,6BAAQ,CAAC;aAC5D,CAAC,EACJ,SAAS,QAAE,OAAO,CAAC,SAAS,mCAAI,IAAI,EACpC,YAAY,QAAE,OAAO,CAAC,YAAY,mCAAI,KAAK,EAC3C,QAAQ,QAAE,OAAO,CAAC,QAAQ,mCAAI,KAAK,IACnC,CAAC;QACH,IAAI,C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AkB,CAAC,OAAO,EAAE,CAAC;gBAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;gBACzC,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,MAAM,IAAI,WAAW,CAAC,aAAa,IAAI,CAAC,IAAI,wCAAwC,CAAC,CAAC;gBACxF,CAAC;gBACD,UAAU,GAAG,IAAI,uCAAkB,CAAC;oBAClC,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;oBACnC,SAAS;oBACT,MAAM,EAAE,EAAE;oBACV,KAAK,QAAE,MAAA,KAAK,CAAC,MAAM,0CAAE,KAAK,CAAC,KAAK,mCAAI,CAAC;iBACtC,CAAC,CAAC;YACL,CAAC;iBAAM,IAAI,KAAK,EAAE,CAAC;gBACjB,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,CAAC,KAAK,YAAY,WAAW,CAAC;gBAAE,MAAM,KAAK,CAAC;YACjD,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC;YACxC,UAAU,EAAE,IAAI;YAChB,UAAU;YACV,KAAK;YACL,WAAW,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC,UAAU,CAAC;SACzD,CAAC,CAAC;QACH,IAAI,OAAO;YAAE,MAAM,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAC5D,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;;AAzIQ,cAAI,GAAG,gBAAgB,CAAC","sourcesContent":["import { AttributeInputKind } from '../input/AttributeInput';\nimport type { NodeInput } from '../input/NodeInput';\nimport type { AttributeInput } from '../input/AttributeInput';\nimport type { AttributeParseContext } from '../input/AttributeParseContext';\nimport { AttributeParseEvent } from '../AttributeParseEvent';\nimport {\n AbstractExpression,\n ExpressionParser,\n ConstantExpression,\n EvaluatedExpression,\n CombinedParser,\n FunctionExpressionParser,\n EvaluatedExpressionParser,\n ConstantExpressionParser\n} from '@ja-platform/parser-expressions';\nimport { Type, textType } from '@ja-platform/parser-type-system';\nimport { CommonEntity, CommonEntityListener, CommonEntityOptions } from '../entities/CommonEntity';\nimport { Node } from '../nodes/Node';\nimport { ParsedAttribute, ParsedAttributeOptions } from '../parsed/ParsedAttribute';\nimport { ParsedNode } from '../parsed/ParsedNode';\n\nexport type CombinedAttributeExpression = EvaluatedExpression | ConstantExpression<unknown>;\n\nexport interface AttributeListener extends CommonEntityListener {}\n\nexport interface NodeChecker {\n hasAttributeType(type: string): boolean;\n}\n\nexport interface AttributeOptions<DEFAULT = any, VALUE = unknown> extends CommonEntityOptions {\n /**\n * Accepted expression syntax. Defaults to prefixed code followed by constant text.\n */\n syntax?: ExpressionParser<AbstractExpression>;\n /**\n * Conversion and literal validation for the resolved attribute value.\n */\n valueType?: Type<VALUE>;\n required?: boolean;\n configurable?: boolean;\n advanced?: boolean;\n fragmentNamespace?: string;\n\n defaultValue?: DEFAULT;\n /**\n * The interim value to use when the component attribute is still being evaluated (ie. setting up watches),\n * will fallback to `defaultValue` if not set.\n */\n loadingValue?: DEFAULT;\n /**\n * By default autowatch is enabled, disable it if the attribute relies on parameters such as $object\n * (used quite often in query-widget) which need to have watches setup in virtual tables\n * @deprecated\n */\n autoWatch?: boolean;\n /**\n * Indicates that the attribute is considered deprecated\n */\n deprecated?: boolean;\n /**\n * Ensures that functions returned by this attribute will be mapped to string identifiers in the runtime\n */\n mapGeneratedFunctions?: boolean;\n}\n\nexport interface AttributeGenerics<O extends AttributeOptions = AttributeOptions> {\n Options: O;\n Listener: AttributeListener;\n Value: any;\n NormalizedValue: unknown;\n}\n\nexport interface StringifyDirective {\n isAttribute: boolean;\n value: string | null;\n}\n\nexport class Attribute<G extends AttributeGenerics = AttributeGenerics> extends CommonEntity<G> {\n static TYPE = 'base-attribute';\n parent: Node<any>;\n type: string;\n\n constructor(type: string, options: G['Options']) {\n super({\n ...options,\n syntax:\n options.syntax ??\n new CombinedParser<CombinedAttributeExpression>([\n new FunctionExpressionParser(),\n new EvaluatedExpressionParser(),\n new ConstantExpressionParser(options.valueType ?? textType)\n ]),\n autoWatch: options.autoWatch ?? true,\n configurable: options.configurable ?? false,\n advanced: options.advanced ?? false\n });\n this.type = type;\n }\n\n get key() {\n return this.options.key;\n }\n\n get defaultValue() {\n return this.options.defaultValue;\n }\n\n get name() {\n return this.options.name;\n }\n\n normalizeValue(value: unknown): G['NormalizedValue'] {\n return (this.options.valueType ? this.options.valueType.parse(value) : value) as G['NormalizedValue'];\n }\n\n isEnclosedWith(checkerCB: (helper: NodeChecker) => boolean) {\n let node: Node = this.parent;\n\n const checker: NodeChecker = {\n hasAttributeType(type: string): boolean {\n for (let attr of node.attributes) {\n if (attr.constructor.name === type) {\n return true;\n }\n }\n }\n };\n // keep checking the parent\n do {\n if (checkerCB(checker)) {\n return true;\n }\n\n node = node.parent;\n } while (!!node);\n return false;\n }\n\n serialize(): any {\n return {\n ...super.serialize(),\n required: this.options.required,\n defaultValue: this.options.defaultValue,\n\n docs: this.options.docs,\n type: 'standard',\n advanced: !!this.options.advanced\n };\n }\n\n protected getParsedValue(event: AttributeParseEvent): G['Value'] {\n return (\n event.context?.parseAttributeExpression?.({ attribute: this, source: event.input.value }) ??\n this.options.syntax.parse(event.input.value)\n );\n }\n\n stringify(value: G['Value'], parent: ParsedNode): StringifyDirective {\n if (value == null) {\n return {\n isAttribute: true,\n value: null\n };\n }\n\n return {\n isAttribute: true,\n value: value.raw()\n };\n }\n\n createParsedAttribute(options: ParsedAttributeOptions<G['Value'], this>): ParsedAttribute<G['Value'], this> {\n return new ParsedAttribute(options);\n }\n\n protected getInput(node?: NodeInput): AttributeInput | undefined {\n return node?.attribute(this.name);\n }\n\n parse(node?: NodeInput, context?: AttributeParseContext) {\n return this.parseInput(this.getInput(node), context);\n }\n\n /** Instantiate an attribute from document input, or from its definition alone. */\n parseInput(input?: AttributeInput, context?: AttributeParseContext) {\n let expression: G['Value'] = null;\n let failure: SyntaxError | undefined;\n try {\n if (input?.kind === AttributeInputKind.LITERAL) {\n const valueType = this.options.valueType;\n if (!valueType) {\n throw new SyntaxError(`Attribute ${this.name} does not support native literal input`);\n }\n expression = new ConstantExpression({\n value: valueType.parse(input.value),\n valueType,\n tokens: [],\n start: input.source?.range.start ?? 0\n });\n } else if (input) {\n expression = this.getParsedValue({ input, context });\n }\n } catch (error) {\n if (!(error instanceof SyntaxError)) throw error;\n failure = error;\n }\n const parsed = this.createParsedAttribute({\n definition: this,\n expression,\n input,\n reportError: (diagnostic) => context?.report(diagnostic)\n });\n if (failure) parsed.pushError({ message: failure.message });\n return parsed;\n }\n}\n"]}
@@ -1,36 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ContentTextAttribute = void 0;
4
+ const AttributeInput_1 = require("../input/AttributeInput");
4
5
  const TextAttribute_1 = require("./TextAttribute");
5
- const common_xml_1 = require("@journeyapps/common-xml");
6
6
  class ContentTextAttribute extends TextAttribute_1.TextAttribute {
7
7
  constructor(options) {
8
8
  super(options);
9
9
  this.type = ContentTextAttribute.TYPE;
10
10
  }
11
- getInput(event) {
12
- var _a;
13
- var _b;
14
- const input = super.getInput(event);
15
- if (input.value != null) {
16
- return input;
17
- }
18
- return { value: (_b = (_a = event.element) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : null, source: event.element };
19
- }
20
- getParsedValue(event, parseContext = {}) {
21
- const expression = super.getParsedValue(event, parseContext);
22
- if ((0, common_xml_1.getAttribute)(event.element, this.options.name) == null) {
23
- parseContext['_content'] = expression;
24
- }
25
- return expression;
26
- }
27
- validateInput(event, expression, parseContext) {
28
- var _a, _b;
29
- if ((0, common_xml_1.getAttribute)(event.element, this.options.name) != null) {
30
- super.validateInput(event, expression, parseContext);
31
- return;
32
- }
33
- (_b = (_a = event.helper).validateFormatContent) === null || _b === void 0 ? void 0 : _b.call(_a, { element: event.element, scope: event.scope, expression });
11
+ getInput(node) {
12
+ const attribute = node === null || node === void 0 ? void 0 : node.attribute(this.name);
13
+ if (attribute)
14
+ return attribute;
15
+ const content = node === null || node === void 0 ? void 0 : node.content();
16
+ if (!content)
17
+ return undefined;
18
+ return Object.assign(Object.assign({}, content), { location: AttributeInput_1.AttributeInputLocation.CONTENT });
34
19
  }
35
20
  stringify(value, parent) {
36
21
  return Object.assign(Object.assign({}, super.stringify(value, parent)), { isAttribute: !parent.content() });
@@ -1 +1 @@
1
- {"version":3,"file":"ContentTextAttribute.js","sourceRoot":"","sources":["../../src/attributes/ContentTextAttribute.ts"],"names":[],"mappings":";;;AACA,mDAAqH;AAIrH,wDAAuD;AAIvD,0BAAkC,SAAQ,6BAIzC;IAGC,YAAY,OAAoC;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC,IAAI,CAAC;IACxC,CAAC;IAES,QAAQ,CAAC,KAAgC;;;QACjD,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACpC,IAAI,KAAK,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,EAAE,KAAK,QAAE,MAAA,KAAK,CAAC,OAAO,0CAAE,WAAW,mCAAI,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAC9E,CAAC;IAES,cAAc,CACtB,KAA0B,EAC1B,YAAY,GAAwB,EAAE;QAEtC,MAAM,UAAU,GAAG,KAAK,CAAC,cAAc,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QAC7D,IAAI,IAAA,yBAAY,EAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;YAC3D,YAAY,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;QACxC,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IAES,aAAa,CACrB,KAA0B,EAC1B,UAAkC,EAClC,YAAiC;;QAEjC,IAAI,IAAA,yBAAY,EAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;YAC3D,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;YACrD,OAAO;QACT,CAAC;QACD,MAAA,MAAA,KAAK,CAAC,MAAM,EAAC,qBAAqB,mDAAG,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;IACnG,CAAC;IAED,SAAS,CAAC,KAAqC,EAAE,MAAkB;QACjE,uCACK,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,KACjC,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,IAC9B;IACJ,CAAC;IAED,SAAS;QACP,uCACK,KAAK,CAAC,SAAS,EAAE,KACpB,IAAI,EAAE,cAAc,IACpB;IACJ,CAAC;CACF;;AAnDQ,yBAAI,GAAG,wBAAwB,CAAC","sourcesContent":["import { AttributeParseEvent, AttributeParseInput } from '../AttributeParseEvent';\nimport { CombinedTextExpression, TextAttribute, TextAttributeGenerics, TextAttributeOptions } from './TextAttribute';\nimport { StringifyDirective } from './Attribute';\nimport { ParsedNode } from '../parsed/ParsedNode';\nimport { XMLParseEvent } from '../XMLParseEvent';\nimport { getAttribute } from '@journeyapps/common-xml';\n\nexport interface ContentTextAttributeOptions extends Omit<TextAttributeOptions, 'configurable'> {}\n\nexport class ContentTextAttribute extends TextAttribute<\n TextAttributeGenerics & {\n Options: ContentTextAttributeOptions;\n }\n> {\n static TYPE = 'content-text-attribute';\n\n constructor(options: ContentTextAttributeOptions) {\n super(options);\n this.type = ContentTextAttribute.TYPE;\n }\n\n protected getInput(event: XMLParseEvent<ParsedNode>): AttributeParseInput {\n const input = super.getInput(event);\n if (input.value != null) {\n return input;\n }\n return { value: event.element?.textContent ?? null, source: event.element };\n }\n\n protected getParsedValue(\n event: AttributeParseEvent,\n parseContext: Record<string, any> = {}\n ): CombinedTextExpression | null {\n const expression = super.getParsedValue(event, parseContext);\n if (getAttribute(event.element, this.options.name) == null) {\n parseContext['_content'] = expression;\n }\n return expression;\n }\n\n protected validateInput(\n event: AttributeParseEvent,\n expression: CombinedTextExpression,\n parseContext: Record<string, any>\n ): void {\n if (getAttribute(event.element, this.options.name) != null) {\n super.validateInput(event, expression, parseContext);\n return;\n }\n event.helper.validateFormatContent?.({ element: event.element, scope: event.scope, expression });\n }\n\n stringify(value: TextAttributeGenerics['Value'], parent: ParsedNode): StringifyDirective {\n return {\n ...super.stringify(value, parent),\n isAttribute: !parent.content()\n };\n }\n\n serialize(): any {\n return {\n ...super.serialize(),\n type: 'content-text'\n };\n }\n}\n"]}
1
+ {"version":3,"file":"ContentTextAttribute.js","sourceRoot":"","sources":["../../src/attributes/ContentTextAttribute.ts"],"names":[],"mappings":";;;AAAA,4DAAiE;AAGjE,mDAA6F;AAM7F,0BAAkC,SAAQ,6BAIzC;IAGC,YAAY,OAAoC;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC,IAAI,CAAC;IACxC,CAAC;IAES,QAAQ,CAAC,IAAgB;QACjC,MAAM,SAAS,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,SAAS;YAAE,OAAO,SAAS,CAAC;QAChC,MAAM,OAAO,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,EAAE,CAAC;QAChC,IAAI,CAAC,OAAO;YAAE,OAAO,SAAS,CAAC;QAC/B,uCAAY,OAAO,KAAE,QAAQ,EAAE,uCAAsB,CAAC,OAAO,IAAG;IAClE,CAAC;IAED,SAAS,CAAC,KAAqC,EAAE,MAAkB;QACjE,uCACK,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,KACjC,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,IAC9B;IACJ,CAAC;IAED,SAAS;QACP,uCACK,KAAK,CAAC,SAAS,EAAE,KACpB,IAAI,EAAE,cAAc,IACpB;IACJ,CAAC;CACF;;AA5BQ,yBAAI,GAAG,wBAAwB,CAAC","sourcesContent":["import { AttributeInputLocation } from '../input/AttributeInput';\nimport type { NodeInput } from '../input/NodeInput';\nimport type { AttributeInput } from '../input/AttributeInput';\nimport { TextAttribute, TextAttributeGenerics, TextAttributeOptions } from './TextAttribute';\nimport { StringifyDirective } from './Attribute';\nimport { ParsedNode } from '../parsed/ParsedNode';\n\nexport interface ContentTextAttributeOptions extends Omit<TextAttributeOptions, 'configurable'> {}\n\nexport class ContentTextAttribute extends TextAttribute<\n TextAttributeGenerics & {\n Options: ContentTextAttributeOptions;\n }\n> {\n static TYPE = 'content-text-attribute';\n\n constructor(options: ContentTextAttributeOptions) {\n super(options);\n this.type = ContentTextAttribute.TYPE;\n }\n\n protected getInput(node?: NodeInput): AttributeInput | undefined {\n const attribute = node?.attribute(this.name);\n if (attribute) return attribute;\n const content = node?.content();\n if (!content) return undefined;\n return { ...content, location: AttributeInputLocation.CONTENT };\n }\n\n stringify(value: TextAttributeGenerics['Value'], parent: ParsedNode): StringifyDirective {\n return {\n ...super.stringify(value, parent),\n isAttribute: !parent.content()\n };\n }\n\n serialize(): any {\n return {\n ...super.serialize(),\n type: 'content-text'\n };\n }\n}\n"]}
@@ -35,7 +35,7 @@ class NumberAttribute extends Attribute_1.Attribute {
35
35
  if (value < min || value > max) {
36
36
  context.report({
37
37
  token: expression.tokens[0],
38
- message: `${parsed.sourceElement.nodeName}: Attribute ${name}="${expression.raw()}" is outside of allowable range [${min}, ${max}].`
38
+ message: `${parsed.definition.name}: Attribute ${name}="${expression.raw()}" is outside of allowable range [${min}, ${max}].`
39
39
  });
40
40
  }
41
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"NumberAttribute.js","sourceRoot":"","sources":["../../src/attributes/NumberAttribute.ts"],"names":[],"mappings":";;;AACA,wEAA0F;AAC1F,wEAA6D;AAC7D,2CAA6E;AAoB7E,qBAA6B,SAAQ,qBAAkC;IAGrE,MAAM,CAAC,YAAY,CAAC,IAAe;QACjC,OAAO,IAAI,CAAC,IAAI,KAAK,eAAe,CAAC,IAAI,CAAC;IAC5C,CAAC;IAED,YAAY,OAA2C;;QACrD,KAAK,CAAC,eAAe,CAAC,IAAI,kCACrB,OAAO,KACV,SAAS,QAAE,OAAO,CAAC,SAAS,mCAAI,+BAAU,EAC1C,YAAY,QAAE,OAAO,CAAC,YAAY,mCAAI,IAAI,IAC1C,CAAC;IACL,CAAC;IAES,cAAc,CAAC,KAA0B;QACjD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;QAChC,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,SAAS,CAAC,MAAiB;QACzB,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxB,MAAM,CAAC,gBAAgB,CAAC;YACtB,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;gBACxB,MAAM,CAAC,gBAAgB,CAAC;oBACtB,cAAc,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;;wBAC9B,MAAM,UAAU,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;wBAC3D,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;wBACrC,IAAI,UAAU,YAAY,uCAAkB,IAAI,KAAK,EAAE,CAAC;4BACtD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC;4BACjC,MAAM,GAAG,SAAG,KAAK,CAAC,GAAG,mCAAI,MAAM,CAAC,iBAAiB,CAAC;4BAClD,MAAM,GAAG,SAAG,KAAK,CAAC,GAAG,mCAAI,MAAM,CAAC,iBAAiB,CAAC;4BAClD,IAAI,KAAK,GAAG,GAAG,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;gCAC/B,OAAO,CAAC,MAAM,CAAC;oCACb,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;oCAC3B,OAAO,EAAE,GAAG,MAAM,CAAC,aAAa,CAAC,QAAQ,eAAe,IAAI,KAAK,UAAU,CAAC,GAAG,EAAE,oCAAoC,GAAG,KAAK,GAAG,IAAI;iCACrI,CAAC,CAAC;4BACL,CAAC;wBACH,CAAC;oBACH,CAAC;iBACF,CAAC,CAAC;YACL,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IACD,SAAS;QACP,uCACK,KAAK,CAAC,SAAS,EAAE,KACpB,IAAI,EAAE,QAAQ,IACd;IACJ,CAAC;CACF;;AApDQ,oBAAI,GAAG,kBAAkB,CAAC","sourcesContent":["import { AttributeParseEvent } from '../AttributeParseEvent';\nimport { EvaluatedExpression, ConstantExpression } from '@ja-platform/parser-expressions';\nimport { numberType } from '@ja-platform/parser-type-system';\nimport { Attribute, AttributeGenerics, AttributeOptions } from './Attribute';\nimport type { Node } from '../nodes/Node';\n\nexport type CombinedNumberExpression = EvaluatedExpression | ConstantExpression<number>;\n\nexport interface NumberAttributeRange {\n min?: number;\n max?: number;\n}\n\nexport interface NumberAttributeOptions extends AttributeOptions<number, number> {\n range?: NumberAttributeRange;\n}\n\nexport interface NumberAttributeGenerics extends AttributeGenerics {\n Options: NumberAttributeOptions;\n Value: CombinedNumberExpression | null;\n NormalizedValue: number;\n}\n\nexport class NumberAttribute extends Attribute<NumberAttributeGenerics> {\n static TYPE = 'number-attribute';\n\n static isInstanceOf(attr: Attribute): attr is NumberAttribute {\n return attr.type === NumberAttribute.TYPE;\n }\n\n constructor(options: NumberAttributeGenerics['Options']) {\n super(NumberAttribute.TYPE, {\n ...options,\n valueType: options.valueType ?? numberType,\n configurable: options.configurable ?? true\n });\n }\n\n protected getParsedValue(event: AttributeParseEvent): NumberAttributeGenerics['Value'] {\n const value = event.input.value;\n if (value.trim() === '') {\n return null;\n }\n return super.getParsedValue(event);\n }\n\n setParent(parent: Node<any>) {\n super.setParent(parent);\n parent.registerListener({\n postParse: ({ parsed }) => {\n parsed.registerListener({\n postValidation: ({ context }) => {\n const expression = parsed.attrExpression(this.options.key);\n const { name, range } = this.options;\n if (expression instanceof ConstantExpression && range) {\n const value = expression.value();\n const min = range.min ?? Number.NEGATIVE_INFINITY;\n const max = range.max ?? Number.POSITIVE_INFINITY;\n if (value < min || value > max) {\n context.report({\n token: expression.tokens[0],\n message: `${parsed.sourceElement.nodeName}: Attribute ${name}=\"${expression.raw()}\" is outside of allowable range [${min}, ${max}].`\n });\n }\n }\n }\n });\n }\n });\n }\n serialize(): any {\n return {\n ...super.serialize(),\n type: 'number'\n };\n }\n}\n"]}
1
+ {"version":3,"file":"NumberAttribute.js","sourceRoot":"","sources":["../../src/attributes/NumberAttribute.ts"],"names":[],"mappings":";;;AACA,wEAA0F;AAC1F,wEAA6D;AAC7D,2CAA6E;AAoB7E,qBAA6B,SAAQ,qBAAkC;IAGrE,MAAM,CAAC,YAAY,CAAC,IAAe;QACjC,OAAO,IAAI,CAAC,IAAI,KAAK,eAAe,CAAC,IAAI,CAAC;IAC5C,CAAC;IAED,YAAY,OAA2C;;QACrD,KAAK,CAAC,eAAe,CAAC,IAAI,kCACr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E,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,eAAe,IAAI,KAAK,UAAU,CAAC,GAAG,EAAE,oCAAoC,GAAG,KAAK,GAAG,IAAI;iCAC9H,CAAC,CAAC;4BACL,CAAC;wBACH,CAAC;oBACH,CAAC;iBACF,CAAC,CAAC;YACL,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IACD,SAAS;QACP,uCACK,KAAK,CAAC,SAAS,EAAE,KACpB,IAAI,EAAE,QAAQ,IACd;IACJ,CAAC;CACF;;AApDQ,oBAAI,GAAG,kBAAkB,CAAC","sourcesContent":["import { AttributeParseEvent } from '../AttributeParseEvent';\nimport { EvaluatedExpression, ConstantExpression } from '@ja-platform/parser-expressions';\nimport { numberType } from '@ja-platform/parser-type-system';\nimport { Attribute, AttributeGenerics, AttributeOptions } from './Attribute';\nimport type { Node } from '../nodes/Node';\n\nexport type CombinedNumberExpression = EvaluatedExpression | ConstantExpression<number>;\n\nexport interface NumberAttributeRange {\n min?: number;\n max?: number;\n}\n\nexport interface NumberAttributeOptions extends AttributeOptions<number, number> {\n range?: NumberAttributeRange;\n}\n\nexport interface NumberAttributeGenerics extends AttributeGenerics {\n Options: NumberAttributeOptions;\n Value: CombinedNumberExpression | null;\n NormalizedValue: number;\n}\n\nexport class NumberAttribute extends Attribute<NumberAttributeGenerics> {\n static TYPE = 'number-attribute';\n\n static isInstanceOf(attr: Attribute): attr is NumberAttribute {\n return attr.type === NumberAttribute.TYPE;\n }\n\n constructor(options: NumberAttributeGenerics['Options']) {\n super(NumberAttribute.TYPE, {\n ...options,\n valueType: options.valueType ?? numberType,\n configurable: options.configurable ?? true\n });\n }\n\n protected getParsedValue(event: AttributeParseEvent): NumberAttributeGenerics['Value'] {\n const value = event.input.value;\n if (value.trim() === '') {\n return null;\n }\n return super.getParsedValue(event);\n }\n\n setParent(parent: Node<any>) {\n super.setParent(parent);\n parent.registerListener({\n postParse: ({ parsed }) => {\n parsed.registerListener({\n postValidation: ({ context }) => {\n const expression = parsed.attrExpression(this.options.key);\n const { name, range } = this.options;\n if (expression instanceof ConstantExpression && range) {\n const value = expression.value();\n const min = range.min ?? Number.NEGATIVE_INFINITY;\n const max = range.max ?? Number.POSITIVE_INFINITY;\n if (value < min || value > max) {\n context.report({\n token: expression.tokens[0],\n message: `${parsed.definition.name}: Attribute ${name}=\"${expression.raw()}\" is outside of allowable range [${min}, ${max}].`\n });\n }\n }\n }\n });\n }\n });\n }\n serialize(): any {\n return {\n ...super.serialize(),\n type: 'number'\n };\n }\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TextAttribute = void 0;
4
+ const AttributeInput_1 = require("../input/AttributeInput");
4
5
  const Attribute_1 = require("./Attribute");
5
6
  const parser_expressions_1 = require("@ja-platform/parser-expressions");
6
7
  const parser_type_system_1 = require("@ja-platform/parser-type-system");
@@ -16,18 +17,19 @@ class TextAttribute extends Attribute_1.Attribute {
16
17
  static isInstanceOf(attr) {
17
18
  return attr.type === TextAttribute.TYPE;
18
19
  }
19
- getParsedValue(event, parseContext = {}) {
20
- const expression = super.getParsedValue(event, parseContext);
21
- this.validateInput(event, expression, parseContext);
20
+ getParsedValue(event) {
21
+ const expression = super.getParsedValue(event);
22
+ this.validateInput(event, expression);
22
23
  return expression;
23
24
  }
24
- validateInput(event, expression, parseContext) {
25
+ validateInput(event, expression) {
25
26
  var _a, _b;
26
- (_b = (_a = event.helper).validateFormatAttribute) === null || _b === void 0 ? void 0 : _b.call(_a, {
27
- element: event.element,
28
- attribute: this.options.name,
29
- scope: event.scope,
30
- expression
27
+ var _c;
28
+ (_b = (_a = event.context) === null || _a === void 0 ? void 0 : _a.validateExpression) === null || _b === void 0 ? void 0 : _b.call(_a, {
29
+ attribute: this,
30
+ expression,
31
+ source: event.input.source,
32
+ location: (_c = event.input.location) !== null && _c !== void 0 ? _c : AttributeInput_1.AttributeInputLocation.ATTRIBUTE
31
33
  });
32
34
  }
33
35
  serialize() {
@@ -1 +1 @@
1
- {"version":3,"file":"TextAttribute.js","sourceRoot":"","sources":["../../src/attributes/TextAttribute.ts"],"names":[],"mappings":";;;AACA,2CAA6E;AAC7E,wEAOyC;AACzC,wEAA2D;AAY3D,mBAA6F,SAAQ,qBAAY;IAG/G,YAAY,OAAqB;;QAC/B,KAAK,CAAC,aAAa,CAAC,IAAI,kCACnB,OAAO,KACV,SAAS,QAAE,OAAO,CAAC,SAAS,mCAAI,6BAAQ,EACxC,MAAM,QACJ,OAAO,CAAC,MAAM,mCACd,IAAI,mCAAc,CAAyB;gBACzC,IAAI,6CAAwB,EAAE;gBAC9B,IAAI,8CAAyB,EAAE;gBAC/B,IAAI,iDAA4B,EAAE;aACnC,CAAC,EACJ,YAAY,QAAE,OAAO,CAAC,YAAY,mCAAI,IAAI,IAC1C,CAAC;IACL,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,IAAe;QACjC,OAAO,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,IAAI,CAAC;IAC1C,CAAC;IAES,cAAc,CACtB,KAA0B,EAC1B,YAAY,GAAwB,EAAE;QAEtC,MAAM,UAAU,GAAG,KAAK,CAAC,cAAc,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QAC7D,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;QACpD,OAAO,UAAU,CAAC;IACpB,CAAC;IAES,aAAa,CACrB,KAA0B,EAC1B,UAAkC,EAClC,YAAiC;;QAEjC,MAAA,MAAA,KAAK,CAAC,MAAM,EAAC,uBAAuB,mDAAG;YACrC,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED,SAAS;QACP,uCACK,KAAK,CAAC,SAAS,EAAE,KACpB,IAAI,EAAE,MAAM,IACZ;IACJ,CAAC;CACF;;AAjDQ,kBAAI,GAAG,gBAAgB,CAAC","sourcesContent":["import { AttributeParseEvent } from '../AttributeParseEvent';\nimport { Attribute, AttributeGenerics, AttributeOptions } from './Attribute';\nimport {\n FormatStringExpression,\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 = FormatStringExpression | EvaluatedExpression;\n\nexport type TextAttributeOptions<Value = string> = AttributeOptions<Value, Value>;\n\nexport interface TextAttributeGenerics<Value = string> extends AttributeGenerics {\n Value: CombinedTextExpression | null;\n Options: TextAttributeOptions<Value>;\n NormalizedValue: Value;\n}\n\nexport class TextAttribute<T extends TextAttributeGenerics<unknown> = TextAttributeGenerics> extends Attribute<T> {\n static TYPE = 'text-attribute';\n\n constructor(options: T['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 getParsedValue(\n event: AttributeParseEvent,\n parseContext: Record<string, any> = {}\n ): CombinedTextExpression | null {\n const expression = super.getParsedValue(event, parseContext);\n this.validateInput(event, expression, parseContext);\n return expression;\n }\n\n protected validateInput(\n event: AttributeParseEvent,\n expression: CombinedTextExpression,\n parseContext: Record<string, any>\n ): void {\n event.helper.validateFormatAttribute?.({\n element: event.element,\n attribute: this.options.name,\n scope: event.scope,\n expression\n });\n }\n\n serialize(): any {\n return {\n ...super.serialize(),\n type: 'text'\n };\n }\n}\n"]}
1
+ {"version":3,"file":"TextAttribute.js","sourceRoot":"","sources":["../../src/attributes/TextA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ttributeParseEvent } from '../AttributeParseEvent';\nimport { Attribute, AttributeGenerics, AttributeOptions } from './Attribute';\nimport {\n FormatStringExpression,\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 = FormatStringExpression | EvaluatedExpression;\n\nexport type TextAttributeOptions<Value = string> = AttributeOptions<Value, Value>;\n\nexport interface TextAttributeGenerics<Value = string> extends AttributeGenerics {\n Value: CombinedTextExpression | null;\n Options: TextAttributeOptions<Value>;\n NormalizedValue: Value;\n}\n\nexport class TextAttribute<T extends TextAttributeGenerics<unknown> = TextAttributeGenerics> extends Attribute<T> {\n static TYPE = 'text-attribute';\n\n constructor(options: T['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 getParsedValue(event: AttributeParseEvent): CombinedTextExpression | null {\n const expression = super.getParsedValue(event);\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 return {\n ...super.serialize(),\n type: 'text'\n };\n }\n}\n"]}
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./AttributeParseEvent"), exports);
18
- __exportStar(require("./XMLParseEvent"), exports);
18
+ __exportStar(require("./ParseEvent"), exports);
19
19
  __exportStar(require("./attributes/ConditionType"), exports);
20
20
  __exportStar(require("./attributes/Attribute"), exports);
21
21
  __exportStar(require("./attributes/BooleanAttribute"), exports);
@@ -35,6 +35,10 @@ __exportStar(require("./entities/CommonEntity"), exports);
35
35
  __exportStar(require("./nodes/Node"), exports);
36
36
  __exportStar(require("./nodes/ContentNode"), exports);
37
37
  __exportStar(require("./nodes/NodeAlternatives"), exports);
38
+ __exportStar(require("./nodes/RecordNode"), exports);
39
+ __exportStar(require("./nodes/EitherNode"), exports);
40
+ __exportStar(require("./parsed/ParsedEitherNode"), exports);
41
+ __exportStar(require("./parsed/ParsedRecordNode"), exports);
38
42
  __exportStar(require("./parsed/ParsedArrayNode"), exports);
39
43
  __exportStar(require("./parsed/ParsedAttribute"), exports);
40
44
  __exportStar(require("./parsed/ParsedContentNode"), exports);
@@ -48,4 +52,8 @@ __exportStar(require("./values/ParsedNodeValues"), exports);
48
52
  __exportStar(require("./values/ParsedProviderValue"), exports);
49
53
  __exportStar(require("./values/ParsedValue"), exports);
50
54
  __exportStar(require("./utils/types/valueOf"), exports);
55
+ __exportStar(require("./source/SourceReference"), exports);
56
+ __exportStar(require("./input/AttributeInput"), exports);
57
+ __exportStar(require("./input/NodeInput"), exports);
58
+ __exportStar(require("./input/AttributeParseContext"), exports);
51
59
  //# 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,kDAAgC;AAChC,6DAA2C;AAC3C,yDAAuC;AACvC,gEAA8C;AAC9C,wEAAsD;AACtD,qEAAmD;AACnD,oEAAkD;AAClD,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,2DAAyC;AACzC,2DAAyC;AACzC,6DAA2C;AAC3C,4DAA0C;AAC1C,sDAAoC;AACpC,2DAAyC;AACzC,iEAA+C;AAC/C,2EAAyD;AACzD,sEAAoD;AACpD,4DAA0C;AAC1C,+DAA6C;AAC7C,uDAAqC;AACrC,wDAAsC","sourcesContent":["export * from './AttributeParseEvent';\nexport * from './XMLParseEvent';\nexport * from './attributes/ConditionType';\nexport * from './attributes/Attribute';\nexport * from './attributes/BooleanAttribute';\nexport * from './attributes/ConstantBooleanAttribute';\nexport * from './attributes/ConstantTextAttribute';\nexport * from './attributes/ContentTextAttribute';\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 './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/ParsedValue';\nexport * from './utils/types/valueOf';\n"]}
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,oEAAkD;AAClD,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,uDAAqC;AACrC,wDAAsC;AAEtC,2DAAyC;AACzC,yDAAuC;AACvC,oDAAkC;AAClC,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/ContentTextAttribute';\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/ParsedValue';\nexport * from './utils/types/valueOf';\n\nexport * from './source/SourceReference';\nexport * from './input/AttributeInput';\nexport * from './input/NodeInput';\nexport * from './input/AttributeParseContext';\n"]}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttributeInputLocation = exports.AttributeInputKind = void 0;
4
+ var AttributeInputKind;
5
+ (function (AttributeInputKind) {
6
+ AttributeInputKind["TEXT"] = "text";
7
+ AttributeInputKind["LITERAL"] = "literal";
8
+ })(AttributeInputKind || (exports.AttributeInputKind = AttributeInputKind = {}));
9
+ var AttributeInputLocation;
10
+ (function (AttributeInputLocation) {
11
+ AttributeInputLocation["ATTRIBUTE"] = "attribute";
12
+ AttributeInputLocation["CONTENT"] = "content";
13
+ })(AttributeInputLocation || (exports.AttributeInputLocation = AttributeInputLocation = {}));
14
+ //# sourceMappingURL=AttributeInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttributeInput.js","sourceRoot":"","sources":["../../src/input/AttributeInput.ts"],"names":[],"mappings":";;;AAEA,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,mCAAa,CAAA;IACb,yCAAmB,CAAA;AACrB,CAAC,EAHW,kBAAkB,aAAlB,kBAAkB,GAAlB,kBAAkB,QAG7B;AAED,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,iDAAuB,CAAA;IACvB,6CAAmB,CAAA;AACrB,CAAC,EAHW,sBAAsB,aAAtB,sBAAsB,GAAtB,sBAAsB,QAGjC","sourcesContent":["import type { SourceReference } from '../source/SourceReference';\n\nexport enum AttributeInputKind {\n TEXT = 'text',\n LITERAL = 'literal'\n}\n\nexport enum AttributeInputLocation {\n ATTRIBUTE = 'attribute',\n CONTENT = 'content'\n}\n\nexport type AttributeLiteralValue =\n | string\n | number\n | boolean\n | null\n | readonly AttributeLiteralValue[]\n | { readonly [key: string]: AttributeLiteralValue };\n\nexport interface AttributeInputBase {\n readonly source?: SourceReference;\n readonly location?: AttributeInputLocation;\n}\n\n/** Text is interpreted using the attribute's expression syntax. */\nexport interface TextAttributeInput extends AttributeInputBase {\n readonly kind: AttributeInputKind.TEXT;\n readonly value: string;\n}\n\n/** Native data bypasses expression syntax and uses the attribute's value type. */\nexport interface LiteralAttributeInput extends AttributeInputBase {\n readonly kind: AttributeInputKind.LITERAL;\n readonly value: AttributeLiteralValue;\n}\n\n/** Undefined input means absent; a literal null is explicitly authored. */\nexport type AttributeInput = TextAttributeInput | LiteralAttributeInput;\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=AttributeParseContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttributeParseContext.js","sourceRoot":"","sources":["../../src/input/AttributeParseContext.ts"],"names":[],"mappings":"","sourcesContent":["import type { AttributeInputLocation } from './AttributeInput';\nimport type { AbstractExpression } from '@ja-platform/parser-expressions';\nimport type { Attribute } from '../attributes/Attribute';\nimport type { ParsedDiagnostic } from '../parsed/ParsedDiagnostic';\nimport type { SourceReference } from '../source/SourceReference';\nimport type { ParsedNode } from '../parsed/ParsedNode';\n\nexport interface AttributeParseContext {\n /** The enclosing parsed node, e.g. the field containing an option node. */\n parentNode?: ParsedNode;\n validateExpression?(input: {\n attribute: Attribute;\n expression: AbstractExpression;\n source?: SourceReference;\n location?: AttributeInputLocation;\n }): void;\n report(diagnostic: ParsedDiagnostic): void;\n parseAttributeExpression?(input: { attribute: Attribute; source: string }): AbstractExpression | undefined;\n}\n"]}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeInputKind = void 0;
4
+ var NodeInputKind;
5
+ (function (NodeInputKind) {
6
+ NodeInputKind["STRING"] = "string";
7
+ NodeInputKind["NUMBER"] = "number";
8
+ NodeInputKind["BOOLEAN"] = "boolean";
9
+ NodeInputKind["NULL"] = "null";
10
+ NodeInputKind["OBJECT"] = "object";
11
+ NodeInputKind["ARRAY"] = "array";
12
+ NodeInputKind["ELEMENT"] = "element";
13
+ })(NodeInputKind || (exports.NodeInputKind = NodeInputKind = {}));
14
+ //# sourceMappingURL=NodeInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeInput.js","sourceRoot":"","sources":["../../src/input/NodeInput.ts"],"names":[],"mappings":";;;AAiBA,IAAY,aAQX;AARD,WAAY,aAAa;IACvB,kCAAiB,CAAA;IACjB,kCAAiB,CAAA;IACjB,oCAAmB,CAAA;IACnB,8BAAa,CAAA;IACb,kCAAiB,CAAA;IACjB,gCAAe,CAAA;IACf,oCAAmB,CAAA;AACrB,CAAC,EARW,aAAa,aAAb,aAAa,GAAb,aAAa,QAQxB","sourcesContent":["import type { AttributeInput } from './AttributeInput';\nimport type { ParsedDiagnostic } from '../parsed/ParsedDiagnostic';\nimport type { SourceReference } from '../source/SourceReference';\n\nexport interface NodeInputSelector {\n name: string;\n key: string;\n isMultiple?: boolean;\n}\n\nexport interface NodeInputSelection {\n inputs: NodeInput[];\n present: boolean;\n source?: SourceReference;\n diagnostics: ParsedDiagnostic[];\n}\n\nexport enum NodeInputKind {\n STRING = 'string',\n NUMBER = 'number',\n BOOLEAN = 'boolean',\n NULL = 'null',\n OBJECT = 'object',\n ARRAY = 'array',\n ELEMENT = 'element'\n}\n\nexport interface NodeInput {\n readonly kind: NodeInputKind;\n readonly name: string;\n readonly source?: SourceReference;\n attribute(name: string): AttributeInput | undefined;\n content(): AttributeInput | undefined;\n children(): Iterable<NodeInput>;\n /** Select named entries, reporting inputs that cannot represent a record. */\n recordEntries(): NodeInputSelection;\n /** Select declared children in document order, retaining explicit empty collections. */\n selectChildren(selectors: readonly NodeInputSelector[], attributeNames?: readonly string[]): NodeInputSelection;\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ContentNode = exports.ContentValueAttribute = void 0;
4
+ const AttributeInput_1 = require("../input/AttributeInput");
4
5
  const parser_expressions_1 = require("@ja-platform/parser-expressions");
5
6
  const Attribute_1 = require("../attributes/Attribute");
6
7
  const ParsedContentNode_1 = require("../parsed/ParsedContentNode");
@@ -9,10 +10,11 @@ const Node_1 = require("./Node");
9
10
  * Adapt element content to the shared value-provider pipeline.
10
11
  */
11
12
  class ContentValueAttribute extends Attribute_1.Attribute {
12
- getInput(event) {
13
- var _a;
14
- var _b;
15
- return { value: (_b = (_a = event.element) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : null, source: event.element };
13
+ getInput(node) {
14
+ const content = node === null || node === void 0 ? void 0 : node.content();
15
+ if (!content)
16
+ return undefined;
17
+ return Object.assign(Object.assign({}, content), { location: AttributeInput_1.AttributeInputLocation.CONTENT });
16
18
  }
17
19
  stringify(value) {
18
20
  var _a;
@@ -36,19 +38,19 @@ class ContentNode extends Node_1.Node {
36
38
  }));
37
39
  }
38
40
  createParsedNode(options) {
39
- return new ParsedContentNode_1.ParsedContentNode({
40
- definition: this,
41
- event: options.event,
42
- key: options.key,
43
- valueProviders: options.valueProviders
44
- });
41
+ return new ParsedContentNode_1.ParsedContentNode(Object.assign({ definition: this }, options));
45
42
  }
46
43
  parseAttributes({ parsed, event }) {
47
44
  var _a, _b;
48
45
  super.parseAttributes({ parsed, event });
49
46
  const expression = parsed.attribute('content').expression();
50
47
  if (expression instanceof parser_expressions_1.FormatStringExpression || expression instanceof parser_expressions_1.EvaluatedExpression) {
51
- (_b = (_a = event.helper).validateFormatContent) === null || _b === void 0 ? void 0 : _b.call(_a, { element: event.element, scope: event.scope, expression });
48
+ (_a = event.validateExpression) === null || _a === void 0 ? void 0 : _a.call(event, {
49
+ attribute: parsed.attribute('content').definition,
50
+ expression,
51
+ source: (_b = parsed.attribute('content').input) === null || _b === void 0 ? void 0 : _b.source,
52
+ location: AttributeInput_1.AttributeInputLocation.CONTENT
53
+ });
52
54
  }
53
55
  parsed.setContent(expression);
54
56
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ContentNode.js","sourceRoot":"","sources":["../../src/nodes/ContentNode.ts"],"names":[],"mappings":";;;AAAA,wEAOyC;AAEzC,uDAAoD;AAIpD,mEAAwF;AAExF,iCAAyD;AAsBzD;;GAEG;AACH,2BAAmC,SAAQ,qBAAS;IACxC,QAAQ,CAAC,KAAgC;;;QACjD,OAAO,EAAE,KAAK,QAAE,MAAA,KAAK,CAAC,OAAO,0CAAE,WAAW,mCAAI,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAC9E,CAAC;IAED,SAAS,CAAC,KAAyB;;QACjC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,QAAE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,GAAG,EAAE,mCAAI,IAAI,EAAE,CAAC;IAC7D,CAAC;CACF;;AAED;;GAEG;AACH,iBAAmG,SAAQ,WAE1G;IACC,YAAY,OAA8C;;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,YAAY,CACf,IAAI,qBAAqB,CAAC,eAAe,EAAE;YACzC,IAAI,EAAE,SAAS;YACf,GAAG,EAAE,SAAS;YACd,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,YAAY,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY;YACnE,MAAM,QAAE,OAAO,CAAC,MAAM,mCAAI,IAAI,6CAAwB,CAAC,OAAO,CAAC,SAAS,CAAC;SAC1E,CAAC,CACH,CAAC;IACJ,CAAC;IAES,gBAAgB,CAAC,OAAyB;QAClD,OAAO,IAAI,qCAAiB,CAAC;YAC3B,UAAU,EAAE,IAAI;YAChB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,cAAc,EAAE,OAAO,CAAC,cAAc;SACvC,CAAC,CAAC;IACL,CAAC;IAES,eAAe,CAAC,EACxB,MAAM,EACN,KAAK,EAIN;;QACC,KAAK,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QACzC,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;QAC5D,IAAI,UAAU,YAAY,2CAAsB,IAAI,UAAU,YAAY,wCAAmB,EAAE,CAAC;YAC9F,MAAA,MAAA,KAAK,CAAC,MAAM,EAAC,qBAAqB,mDAAG,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;QACnG,CAAC;QACD,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC;CACF","sourcesContent":["import {\n ConstantExpression,\n ConstantExpressionParser,\n ExpressionParser,\n AbstractExpression,\n FormatStringExpression,\n EvaluatedExpression\n} from '@ja-platform/parser-expressions';\nimport { Type } from '@ja-platform/parser-type-system';\nimport { Attribute } from '../attributes/Attribute';\nimport { AttributeParseInput } from '../AttributeParseEvent';\nimport { XMLParseEvent } from '../XMLParseEvent';\nimport { ParsedNode } from '../parsed/ParsedNode';\nimport { ParsedContentNode, ParsedContentNodeShape } from '../parsed/ParsedContentNode';\nimport { ParseTreeOptions } from './Node';\nimport { Node, NodeGenerics, NodeOptions } from './Node';\n\nexport type NodeDefaultOptions<Value> =\n { isMultiple?: false; defaultValue?: Value } | { isMultiple: true; defaultValue?: Value[] };\n\nexport type ContentNodeOptions<Value, Expression extends AbstractExpression = ConstantExpression<Value>> = Omit<\n NodeOptions,\n 'isMultiple' | 'defaultValue'\n> &\n NodeDefaultOptions<Value> & {\n valueType: Type<Value>;\n syntax?: ExpressionParser<Expression>;\n };\n\ninterface ContentNodeGenerics<Value, Expression extends AbstractExpression> extends NodeGenerics<\n ParsedContentNodeShape<Expression>,\n ParsedContentNode<Expression, Value>,\n Value | undefined\n> {\n Options: ContentNodeOptions<Value, Expression>;\n}\n\n/**\n * Adapt element content to the shared value-provider pipeline.\n */\nexport class ContentValueAttribute extends Attribute {\n protected getInput(event: XMLParseEvent<ParsedNode>): AttributeParseInput {\n return { value: event.element?.textContent ?? null, source: event.element };\n }\n\n stringify(value: AbstractExpression) {\n return { isAttribute: false, value: value?.raw() ?? null };\n }\n}\n\n/**\n * Parse element content using its declared value type and optional expression syntax.\n */\nexport class ContentNode<Value, Expression extends AbstractExpression = ConstantExpression<Value>> extends Node<\n ContentNodeGenerics<Value, Expression>\n> {\n constructor(options: ContentNodeOptions<Value, Expression>) {\n super(options);\n this.addAttribute(\n new ContentValueAttribute('content-value', {\n name: 'content',\n key: 'content',\n valueType: options.valueType,\n defaultValue: options.isMultiple ? undefined : options.defaultValue,\n syntax: options.syntax ?? new ConstantExpressionParser(options.valueType)\n })\n );\n }\n\n protected createParsedNode(options: ParseTreeOptions): ParsedContentNode<Expression, Value> {\n return new ParsedContentNode({\n definition: this,\n event: options.event,\n key: options.key,\n valueProviders: options.valueProviders\n });\n }\n\n protected parseAttributes({\n parsed,\n event\n }: {\n parsed: ParsedContentNode<Expression, Value>;\n event: XMLParseEvent<ParsedNode>;\n }): void {\n super.parseAttributes({ parsed, event });\n const expression = parsed.attribute('content').expression();\n if (expression instanceof FormatStringExpression || expression instanceof EvaluatedExpression) {\n event.helper.validateFormatContent?.({ element: event.element, scope: event.scope, expression });\n }\n parsed.setContent(expression);\n }\n}\n"]}
1
+ {"version":3,"file":"ContentNode.js","sourceRoot":"","sources":["../../src/nodes/ContentNode.ts"],"names":[],"mappings":";;;AAAA,4DAAiE;AAGjE,wEAOyC;AAEzC,uDAAoD;AAGpD,mEAAwF;AAExF,iCAAyD;AAsBzD;;GA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AAY,2CAAsB,IAAI,UAAU,YAAY,wCAAmB,EAAE,CAAC;YAC9F,MAAA,KAAK,CAAC,kBAAkB,+CAAxB,KAAK,EAAsB;gBACzB,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,UAAU;gBACjD,UAAU;gBACV,MAAM,EAAE,MAAA,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,KAAK,0CAAE,MAAM;gBACjD,QAAQ,EAAE,uCAAsB,CAAC,OAAO;aACzC,CAAC,CAAC;QACL,CAAC;QACD,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC;CACF","sourcesContent":["import { AttributeInputLocation } from '../input/AttributeInput';\nimport type { NodeInput } from '../input/NodeInput';\nimport type { AttributeInput } from '../input/AttributeInput';\nimport {\n ConstantExpression,\n ConstantExpressionParser,\n ExpressionParser,\n AbstractExpression,\n FormatStringExpression,\n EvaluatedExpression\n} from '@ja-platform/parser-expressions';\nimport { Type } from '@ja-platform/parser-type-system';\nimport { Attribute } from '../attributes/Attribute';\nimport { ParseEvent } from '../ParseEvent';\nimport { ParsedNode } from '../parsed/ParsedNode';\nimport { ParsedContentNode, ParsedContentNodeShape } from '../parsed/ParsedContentNode';\nimport { ParseTreeOptions } from './Node';\nimport { Node, NodeGenerics, NodeOptions } from './Node';\n\nexport type NodeDefaultOptions<Value> =\n { isMultiple?: false; defaultValue?: Value } | { isMultiple: true; defaultValue?: Value[] };\n\nexport type ContentNodeOptions<Value, Expression extends AbstractExpression = ConstantExpression<Value>> = Omit<\n NodeOptions,\n 'isMultiple' | 'defaultValue'\n> &\n NodeDefaultOptions<Value> & {\n valueType: Type<Value>;\n syntax?: ExpressionParser<Expression>;\n };\n\ninterface ContentNodeGenerics<Value, Expression extends AbstractExpression> extends NodeGenerics<\n ParsedContentNodeShape<Expression>,\n ParsedContentNode<Expression, Value>,\n Value | undefined\n> {\n Options: ContentNodeOptions<Value, Expression>;\n}\n\n/**\n * Adapt element content to the shared value-provider pipeline.\n */\nexport class ContentValueAttribute extends Attribute {\n protected getInput(node?: NodeInput): AttributeInput | undefined {\n const content = node?.content();\n if (!content) return undefined;\n return { ...content, location: AttributeInputLocation.CONTENT };\n }\n\n stringify(value: AbstractExpression) {\n return { isAttribute: false, value: value?.raw() ?? null };\n }\n}\n\n/**\n * Parse element content using its declared value type and optional expression syntax.\n */\nexport class ContentNode<Value, Expression extends AbstractExpression = ConstantExpression<Value>> extends Node<\n ContentNodeGenerics<Value, Expression>\n> {\n constructor(options: ContentNodeOptions<Value, Expression>) {\n super(options);\n this.addAttribute(\n new ContentValueAttribute('content-value', {\n name: 'content',\n key: 'content',\n valueType: options.valueType,\n defaultValue: options.isMultiple ? undefined : options.defaultValue,\n syntax: options.syntax ?? new ConstantExpressionParser(options.valueType)\n })\n );\n }\n\n protected createParsedNode(options: ParseTreeOptions): ParsedContentNode<Expression, Value> {\n return new ParsedContentNode({\n definition: this,\n ...options\n });\n }\n\n protected parseAttributes({\n parsed,\n event\n }: {\n parsed: ParsedContentNode<Expression, Value>;\n event: ParseEvent;\n }): void {\n super.parseAttributes({ parsed, event });\n const expression = parsed.attribute('content').expression();\n if (expression instanceof FormatStringExpression || expression instanceof EvaluatedExpression) {\n event.validateExpression?.({\n attribute: parsed.attribute('content').definition,\n expression,\n source: parsed.attribute('content').input?.source,\n location: AttributeInputLocation.CONTENT\n });\n }\n parsed.setContent(expression);\n }\n}\n"]}