@lushly-dev/fast-element 3.0.1-preview.0 → 3.0.1-preview.1
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/CHANGELOG.md +6 -0
- package/dist/command/command.api.json +7857 -0
- package/dist/context/context.api.json +1084 -0
- package/dist/declarative/declarative.api.json +8130 -0
- package/dist/definition-schema/definition-schema.api.json +2689 -0
- package/dist/di/di.api.json +4945 -0
- package/dist/dts/arrays.d.ts +2 -0
- package/dist/dts/binding/binding.d.ts +59 -0
- package/dist/dts/binding/exports.d.ts +9 -0
- package/dist/dts/binding/normalize.d.ts +9 -0
- package/dist/dts/binding/one-time.d.ts +11 -0
- package/dist/dts/binding/one-way.d.ts +20 -0
- package/dist/dts/binding/signal.d.ts +36 -0
- package/dist/dts/binding/two-way.d.ts +44 -0
- package/dist/dts/command/behavior.d.ts +94 -0
- package/dist/dts/command/behaviors/confirm-behavior.d.ts +139 -0
- package/dist/dts/command/behaviors/undo-behavior.d.ts +178 -0
- package/dist/dts/command/command.d.ts +79 -0
- package/dist/dts/command/component-registry.d.ts +50 -0
- package/dist/dts/command/components/confirm-dialog.d.ts +117 -0
- package/dist/dts/command/index.d.ts +21 -0
- package/dist/dts/command/registry.d.ts +201 -0
- package/dist/dts/command/schema-validation.d.ts +45 -0
- package/dist/dts/command/types.d.ts +332 -0
- package/dist/dts/command/validation.d.ts +116 -0
- package/dist/dts/command/weak-ref.d.ts +11 -0
- package/dist/dts/components/attributes.d.ts +153 -0
- package/dist/dts/components/definition-schema-transforms.d.ts +9 -0
- package/dist/dts/components/element-controller.d.ts +349 -0
- package/dist/dts/components/element-hydration.d.ts +2 -0
- package/dist/dts/components/enable-hydration.d.ts +66 -0
- package/dist/dts/components/fast-definitions.d.ts +211 -0
- package/dist/dts/components/fast-element-registry.d.ts +23 -0
- package/dist/dts/components/fast-element.d.ts +91 -0
- package/dist/dts/components/hydration-tracker.d.ts +110 -0
- package/dist/dts/components/hydration.d.ts +52 -0
- package/dist/dts/components/schema.d.ts +205 -0
- package/dist/dts/context.d.ts +171 -0
- package/dist/dts/debug.d.ts +5 -0
- package/dist/dts/declarative/attribute-map.d.ts +58 -0
- package/dist/dts/declarative/debug.d.ts +4 -0
- package/dist/dts/declarative/index.d.ts +14 -0
- package/dist/dts/declarative/interfaces.d.ts +8 -0
- package/dist/dts/declarative/observer-map-utilities.d.ts +58 -0
- package/dist/dts/declarative/observer-map.d.ts +89 -0
- package/dist/dts/declarative/runtime.d.ts +5 -0
- package/dist/dts/declarative/syntax.d.ts +21 -0
- package/dist/dts/declarative/template-bridge.d.ts +33 -0
- package/dist/dts/declarative/template-parser.d.ts +98 -0
- package/dist/dts/declarative/template.d.ts +9 -0
- package/dist/dts/declarative/utilities.d.ts +358 -0
- package/dist/dts/definition-schema/api.d.ts +42 -0
- package/dist/dts/definition-schema/cem.d.ts +78 -0
- package/dist/dts/definition-schema/extension.d.ts +18 -0
- package/dist/dts/definition-schema/extract.d.ts +38 -0
- package/dist/dts/definition-schema/index.d.ts +9 -0
- package/dist/dts/definition-schema/storage.d.ts +35 -0
- package/dist/dts/definition-schema/types.d.ts +176 -0
- package/dist/dts/dev-mode.d.ts +13 -0
- package/dist/dts/di/di.d.ts +894 -0
- package/dist/dts/dom-policy.d.ts +101 -0
- package/dist/dts/dom.d.ts +88 -0
- package/dist/dts/hydration/diagnostics.d.ts +93 -0
- package/dist/dts/hydration/exports.d.ts +18 -0
- package/dist/dts/hydration/hydration-debugger.d.ts +35 -0
- package/dist/dts/hydration/messages.d.ts +62 -0
- package/dist/dts/hydration/runtime.d.ts +7 -0
- package/dist/dts/hydration/target-builder.d.ts +107 -0
- package/dist/dts/index.d.ts +51 -0
- package/dist/dts/index.debug.d.ts +1 -0
- package/dist/dts/index.rollup.d.ts +1 -0
- package/dist/dts/index.rollup.debug.d.ts +1 -0
- package/dist/dts/interfaces.d.ts +106 -0
- package/dist/dts/metadata.d.ts +26 -0
- package/dist/dts/observation/arrays.d.ts +248 -0
- package/dist/dts/observation/notifier.d.ts +127 -0
- package/dist/dts/observation/observable.d.ts +276 -0
- package/dist/dts/observation/update-queue.d.ts +40 -0
- package/dist/dts/observation/volatile.d.ts +9 -0
- package/dist/dts/platform.d.ts +87 -0
- package/dist/dts/registry.d.ts +2 -0
- package/dist/dts/render.d.ts +7 -0
- package/dist/dts/schema.d.ts +1 -0
- package/dist/dts/scoped/detection.d.ts +55 -0
- package/dist/dts/scoped/index.d.ts +68 -0
- package/dist/dts/scoped/mixin.d.ts +118 -0
- package/dist/dts/scoped/registry.d.ts +76 -0
- package/dist/dts/scoped/types.d.ts +48 -0
- package/dist/dts/state/exports.d.ts +3 -0
- package/dist/dts/state/reactive.d.ts +8 -0
- package/dist/dts/state/state.d.ts +141 -0
- package/dist/dts/state/visitor.d.ts +6 -0
- package/dist/dts/state/watch.d.ts +10 -0
- package/dist/dts/styles/css-directive.d.ts +50 -0
- package/dist/dts/styles/css.d.ts +34 -0
- package/dist/dts/styles/element-styles.d.ts +61 -0
- package/dist/dts/styles/host.d.ts +65 -0
- package/dist/dts/styles/style-strategy.d.ts +42 -0
- package/dist/dts/templating/children.d.ts +62 -0
- package/dist/dts/templating/compiler.d.ts +54 -0
- package/dist/dts/templating/html-binding-directive.d.ts +155 -0
- package/dist/dts/templating/html-directive.d.ts +218 -0
- package/dist/dts/templating/html.d.ts +1 -0
- package/dist/dts/templating/hydration-view.d.ts +130 -0
- package/dist/dts/templating/markup.d.ts +48 -0
- package/dist/dts/templating/node-observation.d.ts +99 -0
- package/dist/dts/templating/ref.d.ts +23 -0
- package/dist/dts/templating/render.d.ts +318 -0
- package/dist/dts/templating/repeat.d.ts +131 -0
- package/dist/dts/templating/slotted.d.ts +38 -0
- package/dist/dts/templating/template.d.ts +221 -0
- package/dist/dts/templating/view.d.ts +268 -0
- package/dist/dts/templating/when.d.ts +12 -0
- package/dist/dts/testing/exports.d.ts +3 -0
- package/dist/dts/testing/fakes.d.ts +15 -0
- package/dist/dts/testing/fixture.d.ts +84 -0
- package/dist/dts/testing/models.d.ts +20 -0
- package/dist/dts/testing/timeout.d.ts +7 -0
- package/dist/dts/trust/index.d.ts +8 -0
- package/dist/dts/trust/types.d.ts +48 -0
- package/dist/dts/trust/utils.d.ts +26 -0
- package/dist/dts/tsdoc-metadata.json +11 -0
- package/dist/dts/utilities.d.ts +76 -0
- package/dist/esm/arrays.js +1 -0
- package/dist/esm/binding/binding.js +18 -0
- package/dist/esm/binding/exports.js +6 -0
- package/dist/esm/binding/normalize.js +17 -0
- package/dist/esm/binding/one-time.js +21 -0
- package/dist/esm/binding/one-way.js +30 -0
- package/dist/esm/binding/signal.js +99 -0
- package/dist/esm/binding/two-way.js +110 -0
- package/dist/esm/command/behavior.js +155 -0
- package/dist/esm/command/behaviors/confirm-behavior.js +225 -0
- package/dist/esm/command/behaviors/undo-behavior.js +312 -0
- package/dist/esm/command/command.js +104 -0
- package/dist/esm/command/component-registry.js +107 -0
- package/dist/esm/command/components/confirm-dialog.js +370 -0
- package/dist/esm/command/index.js +22 -0
- package/dist/esm/command/registry.js +752 -0
- package/dist/esm/command/schema-validation.js +194 -0
- package/dist/esm/command/types.js +86 -0
- package/dist/esm/command/validation.js +511 -0
- package/dist/esm/command/weak-ref.js +5 -0
- package/dist/esm/components/attributes.js +219 -0
- package/dist/esm/components/definition-schema-transforms.js +23 -0
- package/dist/esm/components/element-controller.js +839 -0
- package/dist/esm/components/element-hydration.js +2 -0
- package/dist/esm/components/enable-hydration.js +123 -0
- package/dist/esm/components/fast-definitions.js +294 -0
- package/dist/esm/components/fast-element-registry.js +67 -0
- package/dist/esm/components/fast-element.js +82 -0
- package/dist/esm/components/hydration-tracker.js +210 -0
- package/dist/esm/components/hydration.js +187 -0
- package/dist/esm/components/schema.js +253 -0
- package/dist/esm/context.js +185 -0
- package/dist/esm/debug.js +71 -0
- package/dist/esm/declarative/attribute-map.js +121 -0
- package/dist/esm/declarative/debug.js +4 -0
- package/dist/esm/declarative/index.js +10 -0
- package/dist/esm/declarative/interfaces.js +9 -0
- package/dist/esm/declarative/observer-map-utilities.js +565 -0
- package/dist/esm/declarative/observer-map.js +216 -0
- package/dist/esm/declarative/runtime.js +14 -0
- package/dist/esm/declarative/syntax.js +36 -0
- package/dist/esm/declarative/template-bridge.js +160 -0
- package/dist/esm/declarative/template-parser.js +306 -0
- package/dist/esm/declarative/template.js +116 -0
- package/dist/esm/declarative/utilities.js +1069 -0
- package/dist/esm/definition-schema/api.js +129 -0
- package/dist/esm/definition-schema/cem.js +89 -0
- package/dist/esm/definition-schema/extension.js +53 -0
- package/dist/esm/definition-schema/extract.js +167 -0
- package/dist/esm/definition-schema/index.js +8 -0
- package/dist/esm/definition-schema/storage.js +58 -0
- package/dist/esm/definition-schema/types.js +8 -0
- package/dist/esm/dev-mode.js +22 -0
- package/dist/esm/di/di.js +1440 -0
- package/dist/esm/dom-policy.js +374 -0
- package/dist/esm/dom.js +101 -0
- package/dist/esm/hydration/diagnostics.js +50 -0
- package/dist/esm/hydration/exports.js +6 -0
- package/dist/esm/hydration/hydration-debugger.js +112 -0
- package/dist/esm/hydration/messages.js +84 -0
- package/dist/esm/hydration/runtime.js +33 -0
- package/dist/esm/hydration/target-builder.js +264 -0
- package/dist/esm/index.debug.js +3 -0
- package/dist/esm/index.js +49 -0
- package/dist/esm/index.rollup.debug.js +6 -0
- package/dist/esm/index.rollup.js +4 -0
- package/dist/esm/interfaces.js +55 -0
- package/dist/esm/metadata.js +63 -0
- package/dist/esm/observation/arrays.js +661 -0
- package/dist/esm/observation/notifier.js +164 -0
- package/dist/esm/observation/observable.js +324 -0
- package/dist/esm/observation/update-queue.js +56 -0
- package/dist/esm/observation/volatile.js +16 -0
- package/dist/esm/platform.js +98 -0
- package/dist/esm/registry.js +2 -0
- package/dist/esm/render.js +1 -0
- package/dist/esm/schema.js +1 -0
- package/dist/esm/scoped/detection.js +102 -0
- package/dist/esm/scoped/index.js +69 -0
- package/dist/esm/scoped/mixin.js +127 -0
- package/dist/esm/scoped/registry.js +125 -0
- package/dist/esm/scoped/types.js +4 -0
- package/dist/esm/state/exports.js +3 -0
- package/dist/esm/state/reactive.js +34 -0
- package/dist/esm/state/state.js +148 -0
- package/dist/esm/state/visitor.js +28 -0
- package/dist/esm/state/watch.js +36 -0
- package/dist/esm/styles/css-directive.js +36 -0
- package/dist/esm/styles/css.js +56 -0
- package/dist/esm/styles/element-styles.js +144 -0
- package/dist/esm/styles/host.js +1 -0
- package/dist/esm/styles/style-strategy.js +1 -0
- package/dist/esm/templating/children.js +67 -0
- package/dist/esm/templating/compiler.js +359 -0
- package/dist/esm/templating/html-binding-directive.js +288 -0
- package/dist/esm/templating/html-directive.js +113 -0
- package/dist/esm/templating/html.js +1 -0
- package/dist/esm/templating/hydration-view.js +228 -0
- package/dist/esm/templating/markup.js +83 -0
- package/dist/esm/templating/node-observation.js +84 -0
- package/dist/esm/templating/ref.js +21 -0
- package/dist/esm/templating/render.js +468 -0
- package/dist/esm/templating/repeat.js +434 -0
- package/dist/esm/templating/slotted.js +49 -0
- package/dist/esm/templating/template.js +206 -0
- package/dist/esm/templating/view.js +298 -0
- package/dist/esm/templating/when.js +22 -0
- package/dist/esm/testing/exports.js +3 -0
- package/dist/esm/testing/fakes.js +107 -0
- package/dist/esm/testing/fixture.js +86 -0
- package/dist/esm/testing/models.js +58 -0
- package/dist/esm/testing/timeout.js +24 -0
- package/dist/esm/trust/index.js +7 -0
- package/dist/esm/trust/types.js +6 -0
- package/dist/esm/trust/utils.js +126 -0
- package/dist/esm/utilities.js +140 -0
- package/dist/fast-element.api.json +26798 -0
- package/dist/fast-element.d.ts +3985 -0
- package/dist/fast-element.debug.js +7618 -0
- package/dist/fast-element.debug.min.js +3 -0
- package/dist/fast-element.js +7617 -0
- package/dist/fast-element.min.js +3 -0
- package/dist/fast-element.untrimmed.d.ts +4103 -0
- package/dist/observation/arrays/arrays.api.json +2621 -0
- package/dist/scoped/scoped.api.json +891 -0
- package/dist/trust/trust.api.json +629 -0
- package/package.json +12 -12
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { DOM } from "../dom.js";
|
|
2
|
+
import { isString } from "../interfaces.js";
|
|
3
|
+
import { Observable } from "../observation/observable.js";
|
|
4
|
+
import { Updates } from "../observation/update-queue.js";
|
|
5
|
+
import { createMetadataLocator } from "../platform.js";
|
|
6
|
+
const booleanMode = "boolean";
|
|
7
|
+
const reflectMode = "reflect";
|
|
8
|
+
/**
|
|
9
|
+
* Metadata used to configure a custom attribute's behavior.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export const AttributeConfiguration = Object.freeze({
|
|
13
|
+
/**
|
|
14
|
+
* Locates all attribute configurations associated with a type.
|
|
15
|
+
*/
|
|
16
|
+
locate: createMetadataLocator(),
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* A {@link ValueConverter} that converts to and from `boolean` values.
|
|
20
|
+
* @remarks
|
|
21
|
+
* Used automatically when the `boolean` {@link AttributeMode} is selected.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export const booleanConverter = {
|
|
25
|
+
toView(value) {
|
|
26
|
+
return value ? "" : null;
|
|
27
|
+
},
|
|
28
|
+
fromView(value) {
|
|
29
|
+
return !!value;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* A {@link ValueConverter} that converts to and from `boolean` values. `null`, `undefined`, `""`,
|
|
34
|
+
* and `void` values are converted to `null`.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export const nullableBooleanConverter = {
|
|
38
|
+
toView(value) {
|
|
39
|
+
return typeof value === "boolean" ? value.toString() : "";
|
|
40
|
+
},
|
|
41
|
+
fromView(value) {
|
|
42
|
+
return [null, undefined, void 0].includes(value)
|
|
43
|
+
? null
|
|
44
|
+
: booleanConverter.fromView(value);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
function toNumber(value) {
|
|
48
|
+
if (value === null || value === undefined) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const number = value * 1;
|
|
52
|
+
return isNaN(number) ? null : number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A {@link ValueConverter} that converts to and from `number` values.
|
|
56
|
+
* @remarks
|
|
57
|
+
* This converter allows for nullable numbers, returning `null` if the
|
|
58
|
+
* input was `null`, `undefined`, or `NaN`.
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
export const nullableNumberConverter = {
|
|
62
|
+
toView(value) {
|
|
63
|
+
const output = toNumber(value);
|
|
64
|
+
return output ? output.toString() : output;
|
|
65
|
+
},
|
|
66
|
+
fromView: toNumber,
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* An implementation of {@link Accessor} that supports reactivity,
|
|
70
|
+
* change callbacks, attribute reflection, and type conversion for
|
|
71
|
+
* custom elements.
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
export class AttributeDefinition {
|
|
75
|
+
/**
|
|
76
|
+
* Creates an instance of AttributeDefinition.
|
|
77
|
+
* @param Owner - The class constructor that owns this attribute.
|
|
78
|
+
* @param name - The name of the property associated with the attribute.
|
|
79
|
+
* @param attribute - The name of the attribute in HTML.
|
|
80
|
+
* @param mode - The {@link AttributeMode} that describes the behavior of this attribute.
|
|
81
|
+
* @param converter - A {@link ValueConverter} that integrates with the property getter/setter
|
|
82
|
+
* to convert values to and from a DOM string.
|
|
83
|
+
*/
|
|
84
|
+
constructor(Owner, name, attribute = name.toLowerCase(), mode = reflectMode, converter) {
|
|
85
|
+
this.guards = new Set();
|
|
86
|
+
this.Owner = Owner;
|
|
87
|
+
this.name = name;
|
|
88
|
+
this.attribute = attribute;
|
|
89
|
+
this.mode = mode;
|
|
90
|
+
this.converter = converter;
|
|
91
|
+
this.fieldName = `_${name}`;
|
|
92
|
+
this.callbackName = `${name}Changed`;
|
|
93
|
+
this.hasCallback = this.callbackName in Owner.prototype;
|
|
94
|
+
if (mode === booleanMode && converter === void 0) {
|
|
95
|
+
this.converter = booleanConverter;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Sets the value of the attribute/property on the source element.
|
|
100
|
+
* @param source - The source element to access.
|
|
101
|
+
* @param newValue - The value to set the attribute/property to.
|
|
102
|
+
*/
|
|
103
|
+
setValue(source, newValue) {
|
|
104
|
+
const oldValue = source[this.fieldName];
|
|
105
|
+
const converter = this.converter;
|
|
106
|
+
if (converter !== void 0) {
|
|
107
|
+
newValue = converter.fromView(newValue);
|
|
108
|
+
}
|
|
109
|
+
if (oldValue !== newValue) {
|
|
110
|
+
source[this.fieldName] = newValue;
|
|
111
|
+
this.tryReflectToAttribute(source);
|
|
112
|
+
if (this.hasCallback) {
|
|
113
|
+
source[this.callbackName](oldValue, newValue);
|
|
114
|
+
}
|
|
115
|
+
source.$fastController.notify(this.name);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Gets the value of the attribute/property on the source element.
|
|
120
|
+
* @param source - The source element to access.
|
|
121
|
+
*/
|
|
122
|
+
getValue(source) {
|
|
123
|
+
Observable.track(source, this.name);
|
|
124
|
+
return source[this.fieldName];
|
|
125
|
+
}
|
|
126
|
+
/** @internal */
|
|
127
|
+
onAttributeChangedCallback(element, value) {
|
|
128
|
+
if (this.guards.has(element)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this.guards.add(element);
|
|
132
|
+
if (this.mode === booleanMode) {
|
|
133
|
+
// Native HTML boolean attribute semantics: presence of the attribute
|
|
134
|
+
// (any string value, including "") means `true`; `null` (the value
|
|
135
|
+
// passed by the platform on `removeAttribute`) means `false`.
|
|
136
|
+
this.setValue(element, value !== null);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this.setValue(element, value);
|
|
140
|
+
}
|
|
141
|
+
this.guards.delete(element);
|
|
142
|
+
}
|
|
143
|
+
tryReflectToAttribute(element) {
|
|
144
|
+
const mode = this.mode;
|
|
145
|
+
const guards = this.guards;
|
|
146
|
+
if (guards.has(element) || mode === "fromView") {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
Updates.enqueue(() => {
|
|
150
|
+
guards.add(element);
|
|
151
|
+
const latestValue = element[this.fieldName];
|
|
152
|
+
switch (mode) {
|
|
153
|
+
case reflectMode: {
|
|
154
|
+
const converter = this.converter;
|
|
155
|
+
DOM.setAttribute(element, this.attribute, converter !== void 0
|
|
156
|
+
? converter.toView(latestValue)
|
|
157
|
+
: latestValue);
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case booleanMode:
|
|
161
|
+
DOM.setBooleanAttribute(element, this.attribute, latestValue);
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
guards.delete(element);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Collects all attribute definitions associated with the owner.
|
|
169
|
+
* @param Owner - The class constructor to collect attribute for.
|
|
170
|
+
* @param attributeLists - Any existing attributes to collect and merge with those associated with the owner.
|
|
171
|
+
* @internal
|
|
172
|
+
*/
|
|
173
|
+
static collect(Owner, ...attributeLists) {
|
|
174
|
+
const attributes = [];
|
|
175
|
+
attributeLists.push(AttributeConfiguration.locate(Owner));
|
|
176
|
+
for (let i = 0, ii = attributeLists.length; i < ii; ++i) {
|
|
177
|
+
const list = attributeLists[i];
|
|
178
|
+
if (list === void 0) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
for (let j = 0, jj = list.length; j < jj; ++j) {
|
|
182
|
+
const config = list[j];
|
|
183
|
+
if (isString(config)) {
|
|
184
|
+
attributes.push(new AttributeDefinition(Owner, config));
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
attributes.push(new AttributeDefinition(Owner, config.property, config.attribute, config.mode, config.converter));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return attributes;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
export function attr(configOrTarget, prop) {
|
|
195
|
+
let config;
|
|
196
|
+
function decorator($target, $prop) {
|
|
197
|
+
if (arguments.length > 1) {
|
|
198
|
+
// Non invocation:
|
|
199
|
+
// - @attr
|
|
200
|
+
// Invocation with or w/o opts:
|
|
201
|
+
// - @attr()
|
|
202
|
+
// - @attr({...opts})
|
|
203
|
+
config.property = $prop;
|
|
204
|
+
}
|
|
205
|
+
AttributeConfiguration.locate($target.constructor).push(config);
|
|
206
|
+
}
|
|
207
|
+
if (arguments.length > 1) {
|
|
208
|
+
// Non invocation:
|
|
209
|
+
// - @attr
|
|
210
|
+
config = {};
|
|
211
|
+
decorator(configOrTarget, prop);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
// Invocation with or w/o opts:
|
|
215
|
+
// - @attr()
|
|
216
|
+
// - @attr({...opts})
|
|
217
|
+
config = configOrTarget === void 0 ? {} : configOrTarget;
|
|
218
|
+
return decorator;
|
|
219
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const definitionSchemaTransformsKey = Symbol("definitionSchemaTransforms");
|
|
2
|
+
let schemaTransformOrder = 0;
|
|
3
|
+
export function setDefinitionSchemaTransform(definition, key, transform, priority) {
|
|
4
|
+
var _a;
|
|
5
|
+
const target = definition;
|
|
6
|
+
const transforms = ((_a = target[definitionSchemaTransformsKey]) !== null && _a !== void 0 ? _a : (target[definitionSchemaTransformsKey] = []));
|
|
7
|
+
const existingIndex = transforms.findIndex(record => record.key === key);
|
|
8
|
+
if (existingIndex !== -1) {
|
|
9
|
+
transforms.splice(existingIndex, 1);
|
|
10
|
+
}
|
|
11
|
+
transforms.push({
|
|
12
|
+
key,
|
|
13
|
+
transform,
|
|
14
|
+
order: schemaTransformOrder++,
|
|
15
|
+
priority,
|
|
16
|
+
});
|
|
17
|
+
transforms.sort((a, b) => a.priority - b.priority || a.order - b.order);
|
|
18
|
+
}
|
|
19
|
+
export function getDefinitionSchemaTransforms(definition) {
|
|
20
|
+
var _a;
|
|
21
|
+
const transforms = definition === null || definition === void 0 ? void 0 : definition[definitionSchemaTransformsKey];
|
|
22
|
+
return (_a = transforms === null || transforms === void 0 ? void 0 : transforms.map(record => record.transform)) !== null && _a !== void 0 ? _a : [];
|
|
23
|
+
}
|