@lushly-dev/fast-element 3.0.1-preview.0 → 3.0.1-preview.2
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 +12 -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 +16 -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 +109 -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 +313 -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 +755 -0
- package/dist/esm/command/schema-validation.js +194 -0
- package/dist/esm/command/types.js +86 -0
- package/dist/esm/command/validation.js +508 -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 +840 -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 +211 -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 +122 -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 +1441 -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 +57 -0
- package/dist/esm/observation/arrays.js +661 -0
- package/dist/esm/observation/notifier.js +162 -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 +7604 -0
- package/dist/fast-element.debug.min.js +3 -0
- package/dist/fast-element.js +7603 -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 +21 -23
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { Message } from "./interfaces.js";
|
|
2
|
+
import { Metadata } from "./metadata.js";
|
|
3
|
+
import { FAST } from "./platform.js";
|
|
4
|
+
const contextsByName = new Map();
|
|
5
|
+
const contextEventType = "context-request";
|
|
6
|
+
let requestStrategy;
|
|
7
|
+
/**
|
|
8
|
+
* Enables using:
|
|
9
|
+
* {@link https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md | W3C Community Context protocol.}
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export const Context = Object.freeze({
|
|
13
|
+
/**
|
|
14
|
+
* The event type used for W3C Context Protocol requests.
|
|
15
|
+
*/
|
|
16
|
+
eventType: contextEventType,
|
|
17
|
+
/**
|
|
18
|
+
* Returns a FASTContext object from the global context registry matching the given name if found.
|
|
19
|
+
* Otherwise, returns a new FASTContext with this name.
|
|
20
|
+
* @param name - The name of the FASTContext to get or create.
|
|
21
|
+
* @returns A FASTContext object.
|
|
22
|
+
*/
|
|
23
|
+
for(name) {
|
|
24
|
+
let c = contextsByName.get(name);
|
|
25
|
+
if (c === void 0) {
|
|
26
|
+
c = Context.create(name);
|
|
27
|
+
contextsByName.set(name, c);
|
|
28
|
+
}
|
|
29
|
+
return c;
|
|
30
|
+
},
|
|
31
|
+
/**
|
|
32
|
+
* Creates a W3C Community Protocol-based Context object to use in requesting/providing
|
|
33
|
+
* context through the DOM.
|
|
34
|
+
* @param name - The name to use for the connext. Useful in debugging.
|
|
35
|
+
* @param initialValue - An optional initial value to use if a context handler isn't found.
|
|
36
|
+
*/
|
|
37
|
+
create(name, initialValue) {
|
|
38
|
+
const Interface = function (target, property, index) {
|
|
39
|
+
if (target == null || new.target !== undefined) {
|
|
40
|
+
throw FAST.error(Message.noRegistrationForContext, {
|
|
41
|
+
name: Interface.name,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (property) {
|
|
45
|
+
Context.defineProperty(target, property, Interface);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const types = Metadata.getOrCreateAnnotationParamTypes(target);
|
|
49
|
+
types[index] = Interface;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
Interface.$isInterface = true;
|
|
53
|
+
Interface.initialValue = initialValue;
|
|
54
|
+
Reflect.defineProperty(Interface, "name", { value: name });
|
|
55
|
+
Interface.handle = (target, callback) => Context.handle(target, callback, Interface);
|
|
56
|
+
Interface.provide = (target, value) => Context.provide(target, Interface, value);
|
|
57
|
+
Interface.get = (target) => Context.get(target, Interface);
|
|
58
|
+
Interface.request = (target, callback, multiple) => Context.request(target, Interface, callback, multiple);
|
|
59
|
+
Interface.toString = () => `Context<${Interface.name}>`;
|
|
60
|
+
return Interface;
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* Sets the strategy used by all FAST-specific context requests made through the
|
|
64
|
+
* Context.request, Context.get, Context.defineProperty, and ContextDecorator APIs.
|
|
65
|
+
* @param strategy - The strategy to use. By default, the strategy is Context.dispatch.
|
|
66
|
+
*/
|
|
67
|
+
setDefaultRequestStrategy(strategy) {
|
|
68
|
+
requestStrategy = strategy;
|
|
69
|
+
},
|
|
70
|
+
/**
|
|
71
|
+
* Gets the context value for the target node or returns the initial value if
|
|
72
|
+
* a context handler is not found.
|
|
73
|
+
* @param target - The target to get the context for.
|
|
74
|
+
* @param context - The context to locate.
|
|
75
|
+
* @returns The context value.
|
|
76
|
+
* @remarks
|
|
77
|
+
* Uses the default request strategy to locate the context. If no context is found
|
|
78
|
+
* then the initial value of the context is returned.
|
|
79
|
+
*/
|
|
80
|
+
get(target, context) {
|
|
81
|
+
var _a;
|
|
82
|
+
let value;
|
|
83
|
+
requestStrategy(target, context, found => (value = found), false);
|
|
84
|
+
return (_a = value) !== null && _a !== void 0 ? _a : context.initialValue;
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Requests the context value for the target node.
|
|
88
|
+
* @param target - The target to request the context for.
|
|
89
|
+
* @param context - The context to locate.
|
|
90
|
+
* @param callback - A callback to invoke with the context value.
|
|
91
|
+
* @param multiple - Whether the context requestor expects to handle updates
|
|
92
|
+
* to the context value after the initial request.
|
|
93
|
+
* @remarks
|
|
94
|
+
* Uses the default request strategy to locate the context.
|
|
95
|
+
*/
|
|
96
|
+
request(target, context, callback, multiple = false) {
|
|
97
|
+
requestStrategy(target, context, callback, multiple);
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
*
|
|
101
|
+
* @param target - The target to dispatch the context event on.
|
|
102
|
+
* @param context - The context to locate.
|
|
103
|
+
* @param callback - The callback to invoke with the context value.
|
|
104
|
+
* @param multiple - Whether the context requestor expects to handle updates
|
|
105
|
+
* to the context value after the initial request.
|
|
106
|
+
* @remarks
|
|
107
|
+
* This API does NOT use the default request strategy. It always dispatches
|
|
108
|
+
* an event through the DOM.
|
|
109
|
+
*/
|
|
110
|
+
dispatch(target, context, callback, multiple = false) {
|
|
111
|
+
target.dispatchEvent(new ContextEvent(context, callback, multiple));
|
|
112
|
+
},
|
|
113
|
+
/**
|
|
114
|
+
* Enables an event target to provide a context value.
|
|
115
|
+
* @param target - The target to provide the context value for.
|
|
116
|
+
* @param context - The context to provide the value for.
|
|
117
|
+
* @param value - The value to provide for the context.
|
|
118
|
+
*/
|
|
119
|
+
provide(target, context, value) {
|
|
120
|
+
Context.handle(target, (event) => {
|
|
121
|
+
event.stopImmediatePropagation();
|
|
122
|
+
event.callback(value);
|
|
123
|
+
}, context);
|
|
124
|
+
},
|
|
125
|
+
/**
|
|
126
|
+
*
|
|
127
|
+
* @param target - The target on which to handle context requests.
|
|
128
|
+
* @param callback - The callback to invoke when a context request is received.
|
|
129
|
+
* @param context - The context to handle requests for.
|
|
130
|
+
* @remarks
|
|
131
|
+
* If a context is not provided then the callback will be invoked for all context
|
|
132
|
+
* requests that are received on the target.
|
|
133
|
+
*/
|
|
134
|
+
handle(target, callback, context) {
|
|
135
|
+
if (context) {
|
|
136
|
+
target.addEventListener(contextEventType, (event) => {
|
|
137
|
+
if (event.context === context) {
|
|
138
|
+
callback(event);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
target.addEventListener(contextEventType, callback);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
/**
|
|
147
|
+
* Defines a getter-only property on the target that will return the context
|
|
148
|
+
* value for the target.
|
|
149
|
+
* @param target - The target to define the property on.
|
|
150
|
+
* @param propertyName - The name of the property to define.
|
|
151
|
+
* @param context - The context that will be used to retrieve the property value.
|
|
152
|
+
* @remarks
|
|
153
|
+
* Uses the default request strategy to locate the context and will return the
|
|
154
|
+
* initialValue if the context isn't handled.
|
|
155
|
+
*/
|
|
156
|
+
defineProperty(target, propertyName, context) {
|
|
157
|
+
const field = Symbol.for(`fast:di:${propertyName}`);
|
|
158
|
+
Reflect.defineProperty(target, propertyName, {
|
|
159
|
+
get: function () {
|
|
160
|
+
var _a;
|
|
161
|
+
return (_a = this[field]) !== null && _a !== void 0 ? _a : (this[field] = Context.get(this, context));
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
Context.setDefaultRequestStrategy(Context.dispatch);
|
|
167
|
+
/**
|
|
168
|
+
* An event fired by a context requester to signal it desires a named context.
|
|
169
|
+
*
|
|
170
|
+
* A provider should inspect the `context` property of the event to determine if it has a value that can
|
|
171
|
+
* satisfy the request, calling the `callback` with the requested value if so.
|
|
172
|
+
*
|
|
173
|
+
* If the requested context event contains a truthy `multiple` value, then a provider can call the callback
|
|
174
|
+
* multiple times if the value is changed, if this is the case the provider should pass a `dispose`
|
|
175
|
+
* method to the callback which requesters can invoke to indicate they no longer wish to receive these updates.
|
|
176
|
+
* @public
|
|
177
|
+
*/
|
|
178
|
+
export class ContextEvent extends Event {
|
|
179
|
+
constructor(context, callback, multiple) {
|
|
180
|
+
super(contextEventType, { bubbles: true, composed: true });
|
|
181
|
+
this.context = context;
|
|
182
|
+
this.callback = callback;
|
|
183
|
+
this.multiple = multiple;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { FAST, getDebugMessageLookup } from "./platform.js";
|
|
2
|
+
const baseDebugMessages = {
|
|
3
|
+
[1101 /* needsArrayObservation */]: "Must call ArrayObserver.enable() before observing arrays.",
|
|
4
|
+
[1201 /* onlySetDOMPolicyOnce */]: "The DOM Policy can only be set once.",
|
|
5
|
+
[1202 /* bindingInnerHTMLRequiresTrustedTypes */]: "To bind innerHTML, you must use a TrustedTypesPolicy.",
|
|
6
|
+
[1203 /* twoWayBindingRequiresObservables */]: "View=>Model update skipped. To use twoWay binding, the target property must be observable.",
|
|
7
|
+
[1204 /* hostBindingWithoutHost */]: "No host element is present. Cannot bind host with ${name}.",
|
|
8
|
+
[1205 /* unsupportedBindingBehavior */]: "The requested binding behavior is not supported by the binding engine.",
|
|
9
|
+
[1206 /* directCallToHTMLTagNotAllowed */]: "Calling html`` as a normal function invalidates the security guarantees provided by FAST.",
|
|
10
|
+
[1207 /* onlySetTemplatePolicyOnce */]: "The DOM Policy for an HTML template can only be set once.",
|
|
11
|
+
[1208 /* cannotSetTemplatePolicyAfterCompilation */]: "The DOM Policy cannot be set after a template is compiled.",
|
|
12
|
+
[1209 /* blockedByDOMPolicy */]: "'${aspectName}' on '${tagName}' is blocked by the current DOMPolicy.",
|
|
13
|
+
[1210 /* invalidHydrationAttributeMarker */]: "Invalid data-fe attribute value '${value}'. Expected a positive integer.",
|
|
14
|
+
[1211 /* duplicateRenderInstruction */]: "Replacing existing RenderInstruction for '${type}' with name '${name}'.",
|
|
15
|
+
[1401 /* missingElementDefinition */]: "Missing FASTElement definition.",
|
|
16
|
+
[1501 /* noRegistrationForContext */]: "No registration for Context/Interface '${name}'.",
|
|
17
|
+
[1502 /* noFactoryForResolver */]: "Dependency injection resolver for '${key}' returned a null factory.",
|
|
18
|
+
[1503 /* invalidResolverStrategy */]: "Invalid dependency injection resolver strategy specified '${strategy}'.",
|
|
19
|
+
[1504 /* cannotAutoregisterDependency */]: "Unable to autoregister dependency.",
|
|
20
|
+
[1505 /* cannotResolveKey */]: "Unable to resolve dependency injection key '${key}'.",
|
|
21
|
+
[1506 /* cannotConstructNativeFunction */]:
|
|
22
|
+
/* eslint-disable-next-line max-len */
|
|
23
|
+
"'${name}' is a native function and therefore cannot be safely constructed by DI. If this is intentional, please use a callback or cachedCallback resolver.",
|
|
24
|
+
[1507 /* cannotJITRegisterNonConstructor */]: "Attempted to jitRegister something that is not a constructor '${value}'. Did you forget to register this dependency?",
|
|
25
|
+
[1508 /* cannotJITRegisterIntrinsic */]: "Attempted to jitRegister an intrinsic type '${value}'. Did you forget to add @inject(Key)?",
|
|
26
|
+
[1509 /* cannotJITRegisterInterface */]: "Attempted to jitRegister an interface '${value}'.",
|
|
27
|
+
[1510 /* invalidResolver */]: "A valid resolver was not returned from the register method.",
|
|
28
|
+
[1511 /* invalidKey */]: "Key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?",
|
|
29
|
+
[1512 /* noDefaultResolver */]: "'${key}' not registered. Did you forget to add @singleton()?",
|
|
30
|
+
[1513 /* cyclicDependency */]: "Cyclic dependency found '${name}'.",
|
|
31
|
+
[1514 /* connectUpdateRequiresController */]: "Injected properties that are updated on changes to DOM connectivity require the target object to be an instance of FASTElement.",
|
|
32
|
+
[1601 /* invalidAttributeMarkerName */]: "Invalid attribute marker name: ${name}. Expected format is ${expectedFormat}.",
|
|
33
|
+
[1602 /* invalidCompactAttributeMarkerValues */]: "Invalid compact attribute marker values in ${markerName}. Both index and count must be positive integers.",
|
|
34
|
+
[1604 /* invalidCompactAttributeMarkerName */]: "Invalid compact attribute marker name: ${name}. Expected format is ${expectedFormat}.",
|
|
35
|
+
};
|
|
36
|
+
const allPlaceholders = /(\$\{\w+?})/g;
|
|
37
|
+
const placeholder = /\$\{(\w+?)}/g;
|
|
38
|
+
const noValues = Object.freeze({});
|
|
39
|
+
function formatMessage(message, values) {
|
|
40
|
+
return message
|
|
41
|
+
.split(allPlaceholders)
|
|
42
|
+
.map(v => {
|
|
43
|
+
var _a;
|
|
44
|
+
const replaced = v.replace(placeholder, "$1");
|
|
45
|
+
return String((_a = values[replaced]) !== null && _a !== void 0 ? _a : v);
|
|
46
|
+
})
|
|
47
|
+
.join("");
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Enables human-readable FAST debug messages.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export function enableDebug() {
|
|
54
|
+
const debugMessages = getDebugMessageLookup();
|
|
55
|
+
Object.assign(debugMessages, baseDebugMessages);
|
|
56
|
+
Object.assign(FAST, {
|
|
57
|
+
addMessages(messages) {
|
|
58
|
+
Object.assign(debugMessages, messages);
|
|
59
|
+
},
|
|
60
|
+
warn(code, values = noValues) {
|
|
61
|
+
var _a;
|
|
62
|
+
const message = (_a = debugMessages[code]) !== null && _a !== void 0 ? _a : "Unknown Warning";
|
|
63
|
+
console.warn(formatMessage(message, values));
|
|
64
|
+
},
|
|
65
|
+
error(code, values = noValues) {
|
|
66
|
+
var _a;
|
|
67
|
+
const message = (_a = debugMessages[code]) !== null && _a !== void 0 ? _a : "Unknown Error";
|
|
68
|
+
return new Error(formatMessage(message, values));
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { AttributeDefinition } from "../components/attributes.js";
|
|
2
|
+
import { setDefinitionSchemaTransform } from "../components/definition-schema-transforms.js";
|
|
3
|
+
import { hasFASTElementTemplateResolver, trackLateAttributeDefinition, } from "../components/fast-definitions.js";
|
|
4
|
+
import { Observable } from "../observation/observable.js";
|
|
5
|
+
export { Schema, schemaRegistry, } from "../components/schema.js";
|
|
6
|
+
const attributeMapSchemaTransformKey = "attribute-map";
|
|
7
|
+
const attributeMapSchemaTransformPriority = 0;
|
|
8
|
+
function defineAttributeMap(definition, schema, config) {
|
|
9
|
+
new AttributeMap(definition.type.prototype, schema, definition, config).defineProperties();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a FAST element extension that enables schema-driven attribute mapping
|
|
13
|
+
* for the resolved definition. When called without arguments, uses the default
|
|
14
|
+
* attribute-mapping behavior. The extension uses `definition.schema` immediately
|
|
15
|
+
* for manual schemas, or the schema generated/augmented by `declarativeTemplate()`.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export function attributeMap(config = {}) {
|
|
19
|
+
return definition => {
|
|
20
|
+
const hasTemplateResolver = hasFASTElementTemplateResolver(definition);
|
|
21
|
+
if (definition.schema && !hasTemplateResolver) {
|
|
22
|
+
defineAttributeMap(definition, definition.schema, config);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!hasTemplateResolver) {
|
|
26
|
+
throw new Error("attributeMap requires a schema. Provide one via FASTElement definition or use declarativeTemplate().");
|
|
27
|
+
}
|
|
28
|
+
setDefinitionSchemaTransform(definition, attributeMapSchemaTransformKey, ({ definition, schema }) => defineAttributeMap(definition, schema, config), attributeMapSchemaTransformPriority);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Converts a camelCase string to kebab-case.
|
|
33
|
+
*
|
|
34
|
+
* @example camelToKebab("fooBar") // "foo-bar"
|
|
35
|
+
* @example camelToKebab("myCustomProp") // "my-custom-prop"
|
|
36
|
+
* @example camelToKebab("label") // "label"
|
|
37
|
+
*/
|
|
38
|
+
function camelToKebab(str) {
|
|
39
|
+
return str.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* AttributeMap provides functionality for detecting simple (leaf) properties in
|
|
43
|
+
* a generated JSON schema and defining them as attr properties on a class prototype.
|
|
44
|
+
*
|
|
45
|
+
* A property is a candidate for attr when its schema entry has no nested `properties`,
|
|
46
|
+
* no `type`, and no `anyOf` — for example, a plain `foo` binding.
|
|
47
|
+
*
|
|
48
|
+
* When `attribute-name-strategy` is `"camelCase"` (the default), the binding key is treated as a
|
|
49
|
+
* camelCase property name and the HTML attribute name is derived by converting it to
|
|
50
|
+
* kebab-case (e.g. property `fooBar` → attribute `foo-bar`). This matches the
|
|
51
|
+
* build-time `attribute-name-strategy` option in `@microsoft/fast-build`.
|
|
52
|
+
*
|
|
53
|
+
* When `attribute-name-strategy` is `"none"`, the binding key is used
|
|
54
|
+
* as both the attribute name and property name — no normalization is applied.
|
|
55
|
+
*
|
|
56
|
+
* Properties already decorated with `attr` or `observable` on the class are left
|
|
57
|
+
* untouched.
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export class AttributeMap {
|
|
61
|
+
constructor(classPrototype, schema, definition, config) {
|
|
62
|
+
this.classPrototype = classPrototype;
|
|
63
|
+
this.schema = schema;
|
|
64
|
+
this.definition = definition;
|
|
65
|
+
this.config = config;
|
|
66
|
+
}
|
|
67
|
+
defineProperties() {
|
|
68
|
+
var _a;
|
|
69
|
+
var _b;
|
|
70
|
+
const propertyNames = this.schema.getRootProperties();
|
|
71
|
+
const existingAccessorNames = new Set(Observable.getAccessors(this.classPrototype).map(a => a.name));
|
|
72
|
+
const strategy = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a["attribute-name-strategy"]) !== null && _b !== void 0 ? _b : "camelCase";
|
|
73
|
+
for (const propertyName of propertyNames) {
|
|
74
|
+
const propertySchema = this.schema.getSchema(propertyName);
|
|
75
|
+
// Only create @attr for leaf properties:
|
|
76
|
+
// - no nested properties (not a dot-syntax path)
|
|
77
|
+
// - no type (not an explicitly typed value like an array)
|
|
78
|
+
// - no anyOf (not a child element reference)
|
|
79
|
+
if (!propertySchema ||
|
|
80
|
+
propertySchema.properties ||
|
|
81
|
+
propertySchema.type ||
|
|
82
|
+
propertySchema.anyOf) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
// Skip if the property already has an accessor (from @attr or @observable)
|
|
86
|
+
if (existingAccessorNames.has(propertyName)) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
// Derive the HTML attribute name from the property name.
|
|
90
|
+
// With "camelCase" strategy, convert camelCase to kebab-case
|
|
91
|
+
// (e.g. fooBar → foo-bar). With "none", use the property name as-is.
|
|
92
|
+
const attributeName = strategy === "camelCase" ? camelToKebab(propertyName) : propertyName;
|
|
93
|
+
const attrDef = new AttributeDefinition(this.classPrototype.constructor, propertyName, attributeName);
|
|
94
|
+
Observable.defineProperty(this.classPrototype, attrDef);
|
|
95
|
+
// Mutate the existing observedAttributes array on the class.
|
|
96
|
+
// FAST's FASTElementDefinition sets observedAttributes via
|
|
97
|
+
// Reflect.defineProperty with a concrete array value (non-configurable,
|
|
98
|
+
// non-writable), so the descriptor cannot be replaced. However, the
|
|
99
|
+
// array itself is mutable, and pushing into it works because
|
|
100
|
+
// registry.define() — which causes the browser to snapshot
|
|
101
|
+
// observedAttributes — is called AFTER this method runs.
|
|
102
|
+
const existingObservedAttrs = this.classPrototype.constructor.observedAttributes;
|
|
103
|
+
if (Array.isArray(existingObservedAttrs) &&
|
|
104
|
+
!existingObservedAttrs.includes(attributeName)) {
|
|
105
|
+
existingObservedAttrs.push(attributeName);
|
|
106
|
+
}
|
|
107
|
+
if (this.definition) {
|
|
108
|
+
this.definition.attributeLookup[attributeName] = attrDef;
|
|
109
|
+
this.definition.propertyLookup[propertyName] = attrDef;
|
|
110
|
+
const attrs = this.definition.attributes;
|
|
111
|
+
if (Array.isArray(attrs) &&
|
|
112
|
+
!attrs.some((existing) => existing.name === attrDef.name ||
|
|
113
|
+
existing.attribute === attrDef.attribute)) {
|
|
114
|
+
attrs.push(attrDef);
|
|
115
|
+
}
|
|
116
|
+
if (this.definition.isDefined) {
|
|
117
|
+
trackLateAttributeDefinition(this.definition, attrDef);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export const debugMessages = {
|
|
2
|
+
[2000 /* noTemplateProvided */]: "The first child of the <f-template> must be a <template>, this is missing from ${name}.",
|
|
3
|
+
[2001 /* moreThanOneTemplateProvided */]: "There can only be one <template> inside the <f-template>; remove any extra <template> elements and keep exactly one for ${name}.",
|
|
4
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { AttributeConfiguration, AttributeDefinition, } from "../components/attributes.js";
|
|
2
|
+
export { FASTElementDefinition, } from "../components/fast-definitions.js";
|
|
3
|
+
export { Schema, schemaRegistry, } from "../components/schema.js";
|
|
4
|
+
export { DOMAspect } from "../dom.js";
|
|
5
|
+
export { DOMPolicy, } from "../dom-policy.js";
|
|
6
|
+
export { ElementStyles, } from "../styles/element-styles.js";
|
|
7
|
+
export { ViewTemplate, } from "../templating/template.js";
|
|
8
|
+
export { HTMLView } from "../templating/view.js";
|
|
9
|
+
export { declarativeTemplate } from "./template.js";
|
|
10
|
+
export { TemplateParser } from "./template-parser.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Warning and error messages.
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export var Message;
|
|
6
|
+
(function (Message) {
|
|
7
|
+
Message[Message["noTemplateProvided"] = 2000] = "noTemplateProvided";
|
|
8
|
+
Message[Message["moreThanOneTemplateProvided"] = 2001] = "moreThanOneTemplateProvided";
|
|
9
|
+
})(Message || (Message = {}));
|