@ja-platform/parser-core 0.0.0-dev-20261105194022 → 0.0.0-dev-20261113191340
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/attributes/TextAttribute.d.ts +9 -2
- package/dist/@types/index.d.ts +1 -1
- package/dist/@types/nodes/Node.d.ts +2 -2
- package/dist/@types/parsed/ParsedArrayNode.d.ts +3 -4
- package/dist/@types/parsed/ParsedContentNode.d.ts +3 -2
- package/dist/@types/parsed/ParsedEitherNode.d.ts +3 -2
- package/dist/@types/parsed/ParsedNode.d.ts +7 -19
- package/dist/@types/parsed/ParsedRecordNode.d.ts +3 -2
- package/dist/@types/values/ParsedNodeValues.d.ts +3 -5
- package/dist/@types/values/ParsedProviderValue.d.ts +4 -0
- package/dist/@types/values/ParsedValue.d.ts +3 -12
- package/dist/@types/values/ValueProviderContext.d.ts +5 -0
- package/dist/attributes/TextAttribute.js +18 -0
- package/dist/attributes/TextAttribute.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/nodes/Node.js +4 -5
- package/dist/nodes/Node.js.map +1 -1
- package/dist/parsed/ParsedArrayNode.js +2 -6
- package/dist/parsed/ParsedArrayNode.js.map +1 -1
- package/dist/parsed/ParsedContentNode.js +4 -4
- package/dist/parsed/ParsedContentNode.js.map +1 -1
- package/dist/parsed/ParsedEitherNode.js +3 -3
- package/dist/parsed/ParsedEitherNode.js.map +1 -1
- package/dist/parsed/ParsedNode.js +37 -66
- package/dist/parsed/ParsedNode.js.map +1 -1
- package/dist/parsed/ParsedRecordNode.js +3 -3
- package/dist/parsed/ParsedRecordNode.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/values/ParsedNodeValues.js +17 -53
- package/dist/values/ParsedNodeValues.js.map +1 -1
- package/dist/values/ParsedProviderValue.js +5 -1
- package/dist/values/ParsedProviderValue.js.map +1 -1
- package/dist/values/ParsedValue.js +4 -25
- package/dist/values/ParsedValue.js.map +1 -1
- package/dist/values/ValueProviderContext.js +3 -0
- package/dist/values/ValueProviderContext.js.map +1 -0
- package/package.json +6 -6
- package/dist/@types/attributes/ContentTextAttribute.d.ts +0 -16
- package/dist/attributes/ContentTextAttribute.js +0 -29
- package/dist/attributes/ContentTextAttribute.js.map +0 -1
|
@@ -4,14 +4,13 @@ exports.ParsedValue = void 0;
|
|
|
4
4
|
const common_utils_1 = require("@journeyapps/common-utils");
|
|
5
5
|
/**
|
|
6
6
|
* Creates contributions from providers ordered from lowest to highest priority.
|
|
7
|
-
* Subscribes to every contribution and
|
|
7
|
+
* Subscribes to every contribution and keeps the current winning value.
|
|
8
8
|
*/
|
|
9
9
|
class ParsedValue extends common_utils_1.BaseObserver {
|
|
10
10
|
constructor(attribute, providers) {
|
|
11
11
|
super();
|
|
12
12
|
this.attribute = attribute;
|
|
13
|
-
this.
|
|
14
|
-
this.released = false;
|
|
13
|
+
this.disposed = false;
|
|
15
14
|
this.providerValues = Object.freeze(providers
|
|
16
15
|
.map((provider) => provider.value(attribute))
|
|
17
16
|
.filter((value) => value !== undefined));
|
|
@@ -24,29 +23,9 @@ class ParsedValue extends common_utils_1.BaseObserver {
|
|
|
24
23
|
get activeValue() {
|
|
25
24
|
return this.selected;
|
|
26
25
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Keep this resolved value and its contributions alive for another consumer.
|
|
29
|
-
*/
|
|
30
|
-
retain() {
|
|
31
|
-
if (!this.released) {
|
|
32
|
-
this.retainCount++;
|
|
33
|
-
}
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Dispose contributions when the last consumer releases this value.
|
|
38
|
-
*/
|
|
39
|
-
release() {
|
|
40
|
-
if (this.retainCount > 0) {
|
|
41
|
-
this.retainCount--;
|
|
42
|
-
}
|
|
43
|
-
if (this.retainCount === 0) {
|
|
44
|
-
this.dispose();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
26
|
dispose() {
|
|
48
|
-
if (!this.
|
|
49
|
-
this.
|
|
27
|
+
if (!this.disposed) {
|
|
28
|
+
this.disposed = true;
|
|
50
29
|
this.deregister.forEach((unsubscribe) => unsubscribe());
|
|
51
30
|
this.providerValues.forEach((value) => value.dispose());
|
|
52
31
|
this.iterateListeners((listener) => { var _a; return (_a = listener.disposed) === null || _a === void 0 ? void 0 : _a.call(listener); });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParsedValue.js","sourceRoot":"","sources":["../../src/values/ParsedValue.ts"],"names":[],"mappings":";;;AAAA,4DAAyD;AAgBzD;;;GAGG;AACH,iBAA4B,SAAQ,2BAAgD;
|
|
1
|
+
{"version":3,"file":"ParsedValue.js","sourceRoot":"","sources":["../../src/values/ParsedValue.ts"],"names":[],"mappings":";;;AAAA,4DAAyD;AAgBzD;;;GAGG;AACH,iBAA4B,SAAQ,2BAAgD;IAOlF,YACmB,SAA0B,EAC3C,SAA2C;QAE3C,KAAK,EAAE,CAAC;QAHS,cAAS,GAAT,SAAS,CAAiB;QALrC,aAAQ,GAAG,KAAK,CAAC;QASvB,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,MAAM,CACjC,SAAS;aACN,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;aAC5C,MAAM,CAAC,CAAC,KAAK,EAAyC,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CACjF,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAClD,KAAK,CAAC,gBAAgB,CAAC;YACrB,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE;YAC7B,aAAa,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE;SACpC,CAAC,CACH,CAAC;QACF,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;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,EAAW,IAAI,CAAC,OAAO,CAAC,GAAA,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;CACF","sourcesContent":["import { BaseObserver } from '@journeyapps/common-utils';\nimport type { AbstractValueProvider } from './AbstractValueProvider';\nimport type { ParsedAttribute } from '../parsed/ParsedAttribute';\nimport { ParsedProviderValue } from './ParsedProviderValue';\n\nexport interface ParsedValueListener<T> {\n changed?: (value: T) => void;\n disposed?: () => void;\n}\n\nexport interface ParsedValueLike<T> {\n readonly current: T;\n registerListener(listener: Partial<ParsedValueListener<T>>): () => void;\n dispose(): void;\n}\n\n/**\n * Creates contributions from providers ordered from lowest to highest priority.\n * Subscribes to every contribution and keeps the current winning value.\n */\nexport class ParsedValue<T> extends BaseObserver<ParsedValueListener<T | undefined>> {\n current: T | undefined;\n readonly providerValues: readonly ParsedProviderValue<unknown>[];\n private disposed = false;\n private readonly deregister: (() => void)[];\n private selected?: ParsedProviderValue<unknown>;\n\n constructor(\n private readonly attribute: ParsedAttribute,\n providers: readonly AbstractValueProvider[]\n ) {\n super();\n this.providerValues = Object.freeze(\n providers\n .map((provider) => provider.value(attribute))\n .filter((value): value is ParsedProviderValue<unknown> => value !== undefined)\n );\n this.deregister = this.providerValues.map((value) =>\n value.registerListener({\n changed: () => this.refresh(),\n activeChanged: () => this.refresh()\n })\n );\n this.refresh();\n }\n\n get activeValue(): ParsedProviderValue<unknown> | undefined {\n return this.selected;\n }\n\n dispose(): void {\n if (!this.disposed) {\n this.disposed = true;\n this.deregister.forEach((unsubscribe) => unsubscribe());\n this.providerValues.forEach((value) => value.dispose());\n this.iterateListeners((listener) => listener.disposed?.());\n }\n }\n\n private refresh(): void {\n let selected: ParsedProviderValue<unknown> | undefined;\n for (const value of this.providerValues) {\n if (value.active) {\n selected = value;\n }\n }\n // Keep the winning entry current even when another provider supplies the same resolved value.\n this.selected = selected;\n let current = selected?.current;\n if (current != null) {\n current = this.attribute.definition.normalizeValue(current);\n }\n if (!Object.is(this.current, current)) {\n this.current = current as T | undefined;\n this.iterateListeners((listener) => listener.changed?.(this.current));\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValueProviderContext.js","sourceRoot":"","sources":["../../src/values/ValueProviderContext.ts"],"names":[],"mappings":"","sourcesContent":["import type { AbstractValueProvider } from './AbstractValueProvider';\n\n/** Supplies the provider order for independently owned parsed-node evaluations. */\nexport interface ValueProviderContext {\n readonly providers: readonly AbstractValueProvider[];\n}\n"]}
|
package/package.json
CHANGED
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
"registry": "https://registry.npmjs.org/",
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.0.0-dev-
|
|
12
|
+
"version": "0.0.0-dev-20261113191340",
|
|
13
13
|
"description": "Reusable parser definitions, parsed trees and values",
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"typings": "./dist/@types/index.d.ts",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ja-platform/parser-expressions": "0.0.0-dev-
|
|
18
|
-
"@ja-platform/parser-type-system": "0.0.0-dev-
|
|
19
|
-
"@journeyapps/common-tree": "
|
|
20
|
-
"@journeyapps/common-utils": "
|
|
17
|
+
"@ja-platform/parser-expressions": "0.0.0-dev-20261113191340",
|
|
18
|
+
"@ja-platform/parser-type-system": "0.0.0-dev-20261113191340",
|
|
19
|
+
"@journeyapps/common-tree": "3.0.3",
|
|
20
|
+
"@journeyapps/common-utils": "2.0.0",
|
|
21
21
|
"lodash": "^4.18.1",
|
|
22
22
|
"type-fest": "^5.10.0"
|
|
23
23
|
},
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"node": "^22.19.0 || ^24.11.0 || >=26.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@journeyapps/common-xml": "
|
|
31
|
+
"@journeyapps/common-xml": "6.0.0",
|
|
32
32
|
"vitest": "^5.0.5"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { NodeInput } from '../input/NodeInput';
|
|
2
|
-
import type { AttributeInput } from '../input/AttributeInput';
|
|
3
|
-
import { TextAttribute, TextAttributeGenerics, TextAttributeOptions } from './TextAttribute';
|
|
4
|
-
import { StringifyDirective } from './Attribute';
|
|
5
|
-
import { ParsedNode } from '../parsed/ParsedNode';
|
|
6
|
-
export interface ContentTextAttributeOptions extends Omit<TextAttributeOptions, 'configurable'> {
|
|
7
|
-
}
|
|
8
|
-
export declare class ContentTextAttribute extends TextAttribute<TextAttributeGenerics & {
|
|
9
|
-
Options: ContentTextAttributeOptions;
|
|
10
|
-
}> {
|
|
11
|
-
static TYPE: string;
|
|
12
|
-
constructor(options: ContentTextAttributeOptions);
|
|
13
|
-
protected getInput(node?: NodeInput): AttributeInput | undefined;
|
|
14
|
-
stringify(value: TextAttributeGenerics['Value'], parent: ParsedNode): StringifyDirective;
|
|
15
|
-
serialize(): any;
|
|
16
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ContentTextAttribute = void 0;
|
|
4
|
-
const AttributeInput_1 = require("../input/AttributeInput");
|
|
5
|
-
const TextAttribute_1 = require("./TextAttribute");
|
|
6
|
-
class ContentTextAttribute extends TextAttribute_1.TextAttribute {
|
|
7
|
-
constructor(options) {
|
|
8
|
-
super(options);
|
|
9
|
-
this.type = ContentTextAttribute.TYPE;
|
|
10
|
-
}
|
|
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 });
|
|
19
|
-
}
|
|
20
|
-
stringify(value, parent) {
|
|
21
|
-
return Object.assign(Object.assign({}, super.stringify(value, parent)), { isAttribute: !parent.content() });
|
|
22
|
-
}
|
|
23
|
-
serialize() {
|
|
24
|
-
return Object.assign(Object.assign({}, super.serialize()), { type: 'content-text' });
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.ContentTextAttribute = ContentTextAttribute;
|
|
28
|
-
ContentTextAttribute.TYPE = 'content-text-attribute';
|
|
29
|
-
//# sourceMappingURL=ContentTextAttribute.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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"]}
|