@wc-bindable/composite 0.8.0
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/README.md +379 -0
- package/dist/createCompositeTarget.d.ts +16 -0
- package/dist/createCompositeTarget.d.ts.map +1 -0
- package/dist/createCompositeTarget.js +143 -0
- package/dist/createCompositeTarget.js.map +1 -0
- package/dist/declarative.d.ts +162 -0
- package/dist/declarative.d.ts.map +1 -0
- package/dist/declarative.js +491 -0
- package/dist/declarative.js.map +1 -0
- package/dist/engine.d.ts +118 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +447 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/lit.d.ts +138 -0
- package/dist/lit.d.ts.map +1 -0
- package/dist/lit.js +273 -0
- package/dist/lit.js.map +1 -0
- package/dist/logger.d.ts +29 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +44 -0
- package/dist/logger.js.map +1 -0
- package/dist/reservedNames.d.ts +25 -0
- package/dist/reservedNames.d.ts.map +1 -0
- package/dist/reservedNames.js +77 -0
- package/dist/reservedNames.js.map +1 -0
- package/dist/types.d.ts +91 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/package.json +46 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @wc-bindable/composite — reference implementation of the wc-bindable
|
|
2
|
+
// Composition profile (SPEC-extensions.md § Extension 4 / COMPOSITE.md).
|
|
3
|
+
//
|
|
4
|
+
// Expose many wc-bindable source targets as one wc-bindable shell target, so
|
|
5
|
+
// existing `bind()` / framework-adapter / `@wc-bindable/remote` consumers work
|
|
6
|
+
// against the composed shell unchanged. Implements tier T1 (observation) and
|
|
7
|
+
// tier T2 (local facade); tier T3 (the Extension-1 surface) is not implemented.
|
|
8
|
+
export { createCompositeTarget } from "./createCompositeTarget.js";
|
|
9
|
+
export { defineComposite, defineCompositeClass, registerCompositeDefinitions, } from "./declarative.js";
|
|
10
|
+
// Lower-level building blocks, exported for tooling and advanced composition.
|
|
11
|
+
export { planComposition, declarationsFromSources, CompositeEngine, CompositeUpdateEvent, SHELL_EVENT_PREFIX, } from "./engine.js";
|
|
12
|
+
export { isReservedComposedName, isReservedSourceId, reservedComposedNameReason, } from "./reservedNames.js";
|
|
13
|
+
export { consoleLogger, silentLogger } from "./logger.js";
|
|
14
|
+
export { COMPOSITE_PROFILE_VERSION, COMPOSITE_TIERS_SYMBOL, } from "./types.js";
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yEAAyE;AACzE,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAC7E,gFAAgF;AAEhF,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,4BAA4B,GAK7B,MAAM,kBAAkB,CAAC;AAE1B,8EAA8E;AAC9E,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,oBAAoB,EACpB,kBAAkB,GAEnB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,YAAY,EAAe,MAAM,aAAa,CAAC;AAEvE,OAAO,EACL,yBAAyB,EACzB,sBAAsB,GAOvB,MAAM,YAAY,CAAC"}
|
package/dist/lit.d.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { LitElement, type ReactiveController, type ReactiveControllerHost } from "lit";
|
|
2
|
+
import { ref as litRef } from "lit/directives/ref.js";
|
|
3
|
+
import { type WcBindableDeclaration } from "@wc-bindable/core";
|
|
4
|
+
import { type DefineCompositeClassOptions, type SourceSpec } from "./declarative.js";
|
|
5
|
+
import type { CompositeShell, ExposeConfig } from "./types.js";
|
|
6
|
+
import type { Logger } from "./logger.js";
|
|
7
|
+
/**
|
|
8
|
+
* A `LitElement` subclass that is also a composite wc-bindable shell. Instances
|
|
9
|
+
* expose composed property getters, the optional T2 facade, the tier-claim
|
|
10
|
+
* symbol, and an idempotent `dispose()`, and re-render on composed updates.
|
|
11
|
+
*/
|
|
12
|
+
export type CompositeLitElementClass = (new () => LitElement & {
|
|
13
|
+
dispose(): void;
|
|
14
|
+
}) & {
|
|
15
|
+
wcBindable: WcBindableDeclaration;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Build a Lit base class for a composite shell. Subclass it, add a `render()`
|
|
19
|
+
* that reads the composed values, and register it with `@customElement` (or
|
|
20
|
+
* `customElements.define`).
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { html } from "lit";
|
|
24
|
+
* import { customElement } from "lit/decorators.js";
|
|
25
|
+
* import { CompositeLitElement } from "@wc-bindable/composite/lit";
|
|
26
|
+
*
|
|
27
|
+
* const Base = await CompositeLitElement({
|
|
28
|
+
* sources: [{ id: "s3", tag: "s3-uploader" }, { id: "ai", tag: "ai-agent" }],
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* @customElement("my-ai-workbench")
|
|
32
|
+
* class MyAiWorkbench extends Base {
|
|
33
|
+
* render() {
|
|
34
|
+
* return html`
|
|
35
|
+
* <progress .value=${this["s3.progress"] ?? 0}></progress>
|
|
36
|
+
* <p>${this["ai.answer"]}</p>
|
|
37
|
+
* <button @click=${() => { this["ai.prompt"] = "hi"; this["ai.run"](); }}>Run</button>
|
|
38
|
+
* `;
|
|
39
|
+
* }
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* Like {@link defineCompositeClass}, this awaits `customElements.whenDefined()`
|
|
44
|
+
* for every source tag first, so the synthesized `static wcBindable` is fully
|
|
45
|
+
* determined (and statically inherited by the subclass).
|
|
46
|
+
*
|
|
47
|
+
* **Shadow-root sharing.** The base creates the source elements in the element's
|
|
48
|
+
* shadow root during `connectedCallback` (synchronously, so an external
|
|
49
|
+
* `bind(el, …)` right after connection sees the composed surface). Lit then
|
|
50
|
+
* renders the author's `render()` output into that *same* shadow root — its
|
|
51
|
+
* content is inserted after the sources, so the two never clash and
|
|
52
|
+
* `static styles` are adopted as usual. A subclass overriding
|
|
53
|
+
* `connectedCallback` MUST call `super.connectedCallback()`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function CompositeLitElement(options: DefineCompositeClassOptions): Promise<CompositeLitElementClass>;
|
|
56
|
+
export interface CompositeControllerOptions {
|
|
57
|
+
/**
|
|
58
|
+
* Expected source specs: a stable id paired with the source custom-element
|
|
59
|
+
* tag. The host renders one element per spec and tags it with the matching
|
|
60
|
+
* {@link CompositeController.ref} directive; the controller composes those
|
|
61
|
+
* rendered instances once all are attached and defined.
|
|
62
|
+
*/
|
|
63
|
+
sources: SourceSpec[];
|
|
64
|
+
/** What the shell exposes. Defaults to `"all-prefixed"`. */
|
|
65
|
+
expose?: ExposeConfig;
|
|
66
|
+
/** Materialize a T2 local facade on the shell. Defaults per `createCompositeTarget`. */
|
|
67
|
+
localFacade?: boolean;
|
|
68
|
+
/** Claim remote compatibility on the shell's tier claim. */
|
|
69
|
+
remoteCompatible?: boolean;
|
|
70
|
+
/** Logger for getter-failure / delegation reports. Defaults to the console logger. */
|
|
71
|
+
logger?: Logger;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A Lit `ReactiveController` that composes source elements the host renders in
|
|
75
|
+
* its **own** template — the controller does not create or place the sources, so
|
|
76
|
+
* the author keeps full control of the DOM. Tag each rendered source with the
|
|
77
|
+
* directive returned by {@link CompositeController.ref}; once every expected
|
|
78
|
+
* source is attached and defined, the controller builds a real composite shell
|
|
79
|
+
* (via `createCompositeTarget`) over those instances, exposes the composed values
|
|
80
|
+
* on {@link CompositeController.values} (re-requesting a host update on each
|
|
81
|
+
* change), and exposes the shell itself on {@link CompositeController.shell}.
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* import { LitElement, html } from "lit";
|
|
85
|
+
* import { customElement } from "lit/decorators.js";
|
|
86
|
+
* import { CompositeController } from "@wc-bindable/composite/lit";
|
|
87
|
+
*
|
|
88
|
+
* @customElement("my-ai-workbench")
|
|
89
|
+
* class MyAiWorkbench extends LitElement {
|
|
90
|
+
* #c = new CompositeController(this, {
|
|
91
|
+
* sources: [{ id: "s3", tag: "s3-uploader" }, { id: "ai", tag: "ai-agent" }],
|
|
92
|
+
* });
|
|
93
|
+
* render() {
|
|
94
|
+
* return html`
|
|
95
|
+
* <s3-uploader ${this.#c.ref("s3")}></s3-uploader>
|
|
96
|
+
* <ai-agent ${this.#c.ref("ai")}></ai-agent>
|
|
97
|
+
* <p>${this.#c.values["ai.answer"]}</p>
|
|
98
|
+
* <button @click=${() => { this.#c.shell!["ai.prompt"] = "hi"; this.#c.shell!["ai.run"](); }}>
|
|
99
|
+
* Run
|
|
100
|
+
* </button>
|
|
101
|
+
* `;
|
|
102
|
+
* }
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* Unlike {@link CompositeLitElement} (where the host element *is* the shell), the
|
|
107
|
+
* host here is a plain Lit component using composition internally; the composed
|
|
108
|
+
* shell is the separate, headless `createCompositeTarget` value on `.shell`,
|
|
109
|
+
* which the author can also hand to `@wc-bindable/remote` or bind elsewhere. The
|
|
110
|
+
* controller follows the usual controller lifecycle: when the host disconnects,
|
|
111
|
+
* the source ref directives detach, the shell is torn down, and a reconnect
|
|
112
|
+
* rebuilds it (so `.shell` identity is not stable across disconnects — use
|
|
113
|
+
* `createCompositeTarget` directly or {@link CompositeLitElement} if you need a
|
|
114
|
+
* stable external shell).
|
|
115
|
+
*/
|
|
116
|
+
export declare class CompositeController<V extends object = Record<string, unknown>> implements ReactiveController {
|
|
117
|
+
#private;
|
|
118
|
+
/** The latest composed property values, replaced (not mutated) on each update. */
|
|
119
|
+
values: V;
|
|
120
|
+
constructor(host: ReactiveControllerHost, options: CompositeControllerOptions);
|
|
121
|
+
/** The composed shell once all sources are attached and defined, else `undefined`. */
|
|
122
|
+
get shell(): CompositeShell | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* The Lit `ref` directive to apply to the source element rendered for `id`.
|
|
125
|
+
* The callback is memoized per id so re-renders do not churn the binding.
|
|
126
|
+
*/
|
|
127
|
+
ref(id: string): ReturnType<typeof litRef>;
|
|
128
|
+
hostDisconnected(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Idempotent **terminal** teardown: tears down the shell (sources are
|
|
131
|
+
* borrowed) and puts the controller into a disposed state so no later ref
|
|
132
|
+
* callback or reconnect can rebuild it. Use it when you are done with the
|
|
133
|
+
* controller for good; for an ordinary disconnect, the controller already
|
|
134
|
+
* tears the shell down and rebuilds on reconnect without any call.
|
|
135
|
+
*/
|
|
136
|
+
dispose(): void;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=lit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lit.d.ts","sourceRoot":"","sources":["../src/lit.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,KAAK,kBAAkB,EAAE,KAAK,sBAAsB,EAAE,MAAM,KAAK,CAAC;AACvF,OAAO,EAAE,GAAG,IAAI,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAsB,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,EAGL,KAAK,2BAA2B,EAChC,KAAK,UAAU,EAChB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,KA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.
|
|
2
|
+
//
|
|
3
|
+
// `CompositeLitElement(options)` returns a `LitElement` base class that *is* a
|
|
4
|
+
// full composite shell — it carries the synthesized `static wcBindable`, the
|
|
5
|
+
// per-instance tier claim, the T1 property getters, the optional T2 facade, and
|
|
6
|
+
// `dispose()`, exactly like the vanilla `defineCompositeClass` base — and on top
|
|
7
|
+
// of that re-renders the author's `render()` whenever a composed value changes.
|
|
8
|
+
//
|
|
9
|
+
// It builds on the same `synthesizeComposite` / `setupCompositeInstance`
|
|
10
|
+
// machinery as the vanilla path, so the source elements are created once in the
|
|
11
|
+
// element's shadow root and the composed surface behaves identically; Lit simply
|
|
12
|
+
// renders the author's UI into the *same* shadow root, after the sources.
|
|
13
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
14
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
15
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
16
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
17
|
+
};
|
|
18
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
19
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
20
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
21
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
22
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
23
|
+
};
|
|
24
|
+
var _CompositeController_instances, _CompositeController_host, _CompositeController_sources, _CompositeController_expose, _CompositeController_localFacade, _CompositeController_remoteCompatible, _CompositeController_logger, _CompositeController_instances_1, _CompositeController_refCallbacks, _CompositeController_shell, _CompositeController_unbind, _CompositeController_defined, _CompositeController_disposed, _CompositeController_onSourceRef, _CompositeController_tryBuild, _CompositeController_teardownShell;
|
|
25
|
+
import { LitElement } from "lit";
|
|
26
|
+
import { ref as litRef } from "lit/directives/ref.js";
|
|
27
|
+
import { bind, isWcBindable } from "@wc-bindable/core";
|
|
28
|
+
import { synthesizeComposite, setupCompositeInstance, } from "./declarative.js";
|
|
29
|
+
import { createCompositeTarget } from "./createCompositeTarget.js";
|
|
30
|
+
const documentRef = typeof document !== "undefined" ? document : undefined;
|
|
31
|
+
const customElementsRef = typeof customElements !== "undefined" ? customElements : undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Build a Lit base class for a composite shell. Subclass it, add a `render()`
|
|
34
|
+
* that reads the composed values, and register it with `@customElement` (or
|
|
35
|
+
* `customElements.define`).
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { html } from "lit";
|
|
39
|
+
* import { customElement } from "lit/decorators.js";
|
|
40
|
+
* import { CompositeLitElement } from "@wc-bindable/composite/lit";
|
|
41
|
+
*
|
|
42
|
+
* const Base = await CompositeLitElement({
|
|
43
|
+
* sources: [{ id: "s3", tag: "s3-uploader" }, { id: "ai", tag: "ai-agent" }],
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* @customElement("my-ai-workbench")
|
|
47
|
+
* class MyAiWorkbench extends Base {
|
|
48
|
+
* render() {
|
|
49
|
+
* return html`
|
|
50
|
+
* <progress .value=${this["s3.progress"] ?? 0}></progress>
|
|
51
|
+
* <p>${this["ai.answer"]}</p>
|
|
52
|
+
* <button @click=${() => { this["ai.prompt"] = "hi"; this["ai.run"](); }}>Run</button>
|
|
53
|
+
* `;
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* Like {@link defineCompositeClass}, this awaits `customElements.whenDefined()`
|
|
59
|
+
* for every source tag first, so the synthesized `static wcBindable` is fully
|
|
60
|
+
* determined (and statically inherited by the subclass).
|
|
61
|
+
*
|
|
62
|
+
* **Shadow-root sharing.** The base creates the source elements in the element's
|
|
63
|
+
* shadow root during `connectedCallback` (synchronously, so an external
|
|
64
|
+
* `bind(el, …)` right after connection sees the composed surface). Lit then
|
|
65
|
+
* renders the author's `render()` output into that *same* shadow root — its
|
|
66
|
+
* content is inserted after the sources, so the two never clash and
|
|
67
|
+
* `static styles` are adopted as usual. A subclass overriding
|
|
68
|
+
* `connectedCallback` MUST call `super.connectedCallback()`.
|
|
69
|
+
*/
|
|
70
|
+
export async function CompositeLitElement(options) {
|
|
71
|
+
var _CompositeLit_instances, _CompositeLit_engine, _CompositeLit_unbind, _CompositeLit_setup, _CompositeLit_setupComposite;
|
|
72
|
+
if (!customElementsRef || !documentRef) {
|
|
73
|
+
throw new Error("@wc-bindable/composite/lit: CompositeLitElement requires a DOM");
|
|
74
|
+
}
|
|
75
|
+
const synth = await synthesizeComposite(options);
|
|
76
|
+
class CompositeLit extends LitElement {
|
|
77
|
+
constructor() {
|
|
78
|
+
super(...arguments);
|
|
79
|
+
_CompositeLit_instances.add(this);
|
|
80
|
+
_CompositeLit_engine.set(this, void 0);
|
|
81
|
+
_CompositeLit_unbind.set(this, void 0);
|
|
82
|
+
_CompositeLit_setup.set(this, false);
|
|
83
|
+
}
|
|
84
|
+
connectedCallback() {
|
|
85
|
+
__classPrivateFieldGet(this, _CompositeLit_instances, "m", _CompositeLit_setupComposite).call(this);
|
|
86
|
+
// After the composite surface exists, let Lit run its own connect +
|
|
87
|
+
// first-update cycle. Lit's createRenderRoot reuses the shadow root we
|
|
88
|
+
// already attached (ReactiveElement: `this.shadowRoot ?? attachShadow`)
|
|
89
|
+
// and adopts `static styles` into it, then renders after the sources.
|
|
90
|
+
super.connectedCallback();
|
|
91
|
+
}
|
|
92
|
+
/** Idempotent terminal teardown (§ 10). Does not dispose the source elements. */
|
|
93
|
+
dispose() {
|
|
94
|
+
__classPrivateFieldGet(this, _CompositeLit_unbind, "f")?.call(this);
|
|
95
|
+
__classPrivateFieldSet(this, _CompositeLit_unbind, undefined, "f");
|
|
96
|
+
__classPrivateFieldGet(this, _CompositeLit_engine, "f")?.dispose();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
_CompositeLit_engine = new WeakMap(), _CompositeLit_unbind = new WeakMap(), _CompositeLit_setup = new WeakMap(), _CompositeLit_instances = new WeakSet(), _CompositeLit_setupComposite = function _CompositeLit_setupComposite() {
|
|
100
|
+
if (__classPrivateFieldGet(this, _CompositeLit_setup, "f"))
|
|
101
|
+
return; // reconnect: listeners were kept, nothing to do
|
|
102
|
+
const shadow = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
103
|
+
__classPrivateFieldSet(this, _CompositeLit_engine, setupCompositeInstance(this, shadow, synth), "f");
|
|
104
|
+
// Re-render whenever a composed value changes. Composed names are dotted
|
|
105
|
+
// strings, not Lit reactive properties, so Lit would not otherwise observe
|
|
106
|
+
// them — bridge each shell update to requestUpdate().
|
|
107
|
+
__classPrivateFieldSet(this, _CompositeLit_unbind, bind(this, () => this.requestUpdate()), "f");
|
|
108
|
+
__classPrivateFieldSet(this, _CompositeLit_setup, true, "f");
|
|
109
|
+
};
|
|
110
|
+
CompositeLit.wcBindable = synth.plan.declaration;
|
|
111
|
+
return CompositeLit;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A Lit `ReactiveController` that composes source elements the host renders in
|
|
115
|
+
* its **own** template — the controller does not create or place the sources, so
|
|
116
|
+
* the author keeps full control of the DOM. Tag each rendered source with the
|
|
117
|
+
* directive returned by {@link CompositeController.ref}; once every expected
|
|
118
|
+
* source is attached and defined, the controller builds a real composite shell
|
|
119
|
+
* (via `createCompositeTarget`) over those instances, exposes the composed values
|
|
120
|
+
* on {@link CompositeController.values} (re-requesting a host update on each
|
|
121
|
+
* change), and exposes the shell itself on {@link CompositeController.shell}.
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { LitElement, html } from "lit";
|
|
125
|
+
* import { customElement } from "lit/decorators.js";
|
|
126
|
+
* import { CompositeController } from "@wc-bindable/composite/lit";
|
|
127
|
+
*
|
|
128
|
+
* @customElement("my-ai-workbench")
|
|
129
|
+
* class MyAiWorkbench extends LitElement {
|
|
130
|
+
* #c = new CompositeController(this, {
|
|
131
|
+
* sources: [{ id: "s3", tag: "s3-uploader" }, { id: "ai", tag: "ai-agent" }],
|
|
132
|
+
* });
|
|
133
|
+
* render() {
|
|
134
|
+
* return html`
|
|
135
|
+
* <s3-uploader ${this.#c.ref("s3")}></s3-uploader>
|
|
136
|
+
* <ai-agent ${this.#c.ref("ai")}></ai-agent>
|
|
137
|
+
* <p>${this.#c.values["ai.answer"]}</p>
|
|
138
|
+
* <button @click=${() => { this.#c.shell!["ai.prompt"] = "hi"; this.#c.shell!["ai.run"](); }}>
|
|
139
|
+
* Run
|
|
140
|
+
* </button>
|
|
141
|
+
* `;
|
|
142
|
+
* }
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* Unlike {@link CompositeLitElement} (where the host element *is* the shell), the
|
|
147
|
+
* host here is a plain Lit component using composition internally; the composed
|
|
148
|
+
* shell is the separate, headless `createCompositeTarget` value on `.shell`,
|
|
149
|
+
* which the author can also hand to `@wc-bindable/remote` or bind elsewhere. The
|
|
150
|
+
* controller follows the usual controller lifecycle: when the host disconnects,
|
|
151
|
+
* the source ref directives detach, the shell is torn down, and a reconnect
|
|
152
|
+
* rebuilds it (so `.shell` identity is not stable across disconnects — use
|
|
153
|
+
* `createCompositeTarget` directly or {@link CompositeLitElement} if you need a
|
|
154
|
+
* stable external shell).
|
|
155
|
+
*/
|
|
156
|
+
export class CompositeController {
|
|
157
|
+
constructor(host, options) {
|
|
158
|
+
_CompositeController_instances.add(this);
|
|
159
|
+
/** The latest composed property values, replaced (not mutated) on each update. */
|
|
160
|
+
this.values = {};
|
|
161
|
+
_CompositeController_host.set(this, void 0);
|
|
162
|
+
_CompositeController_sources.set(this, void 0);
|
|
163
|
+
_CompositeController_expose.set(this, void 0);
|
|
164
|
+
_CompositeController_localFacade.set(this, void 0);
|
|
165
|
+
_CompositeController_remoteCompatible.set(this, void 0);
|
|
166
|
+
_CompositeController_logger.set(this, void 0);
|
|
167
|
+
_CompositeController_instances_1.set(this, new Map());
|
|
168
|
+
_CompositeController_refCallbacks.set(this, new Map());
|
|
169
|
+
_CompositeController_shell.set(this, void 0);
|
|
170
|
+
_CompositeController_unbind.set(this, void 0);
|
|
171
|
+
_CompositeController_defined.set(this, false);
|
|
172
|
+
_CompositeController_disposed.set(this, false);
|
|
173
|
+
__classPrivateFieldSet(this, _CompositeController_host, host, "f");
|
|
174
|
+
__classPrivateFieldSet(this, _CompositeController_sources, options.sources.slice(), "f");
|
|
175
|
+
__classPrivateFieldSet(this, _CompositeController_expose, options.expose, "f");
|
|
176
|
+
__classPrivateFieldSet(this, _CompositeController_localFacade, options.localFacade, "f");
|
|
177
|
+
__classPrivateFieldSet(this, _CompositeController_remoteCompatible, options.remoteCompatible, "f");
|
|
178
|
+
__classPrivateFieldSet(this, _CompositeController_logger, options.logger, "f");
|
|
179
|
+
host.addController(this);
|
|
180
|
+
// Wait for every source tag's definition before composing, so the
|
|
181
|
+
// synthesized declaration is finalized before the shell is observable
|
|
182
|
+
// (§ 11). Already-defined tags resolve on a microtask.
|
|
183
|
+
if (customElementsRef) {
|
|
184
|
+
Promise.all(__classPrivateFieldGet(this, _CompositeController_sources, "f").map((s) => customElementsRef.whenDefined(s.tag))).then(() => {
|
|
185
|
+
__classPrivateFieldSet(this, _CompositeController_defined, true, "f");
|
|
186
|
+
__classPrivateFieldGet(this, _CompositeController_instances, "m", _CompositeController_tryBuild).call(this);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
__classPrivateFieldSet(this, _CompositeController_defined, true, "f");
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/** The composed shell once all sources are attached and defined, else `undefined`. */
|
|
194
|
+
get shell() {
|
|
195
|
+
return __classPrivateFieldGet(this, _CompositeController_shell, "f");
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The Lit `ref` directive to apply to the source element rendered for `id`.
|
|
199
|
+
* The callback is memoized per id so re-renders do not churn the binding.
|
|
200
|
+
*/
|
|
201
|
+
ref(id) {
|
|
202
|
+
let cb = __classPrivateFieldGet(this, _CompositeController_refCallbacks, "f").get(id);
|
|
203
|
+
if (!cb) {
|
|
204
|
+
cb = (el) => __classPrivateFieldGet(this, _CompositeController_instances, "m", _CompositeController_onSourceRef).call(this, id, el);
|
|
205
|
+
__classPrivateFieldGet(this, _CompositeController_refCallbacks, "f").set(id, cb);
|
|
206
|
+
}
|
|
207
|
+
return litRef(cb);
|
|
208
|
+
}
|
|
209
|
+
hostDisconnected() {
|
|
210
|
+
// The source ref directives fire `undefined` on disconnect, which already
|
|
211
|
+
// tears the shell down; this is a defensive backstop for hosts whose parts
|
|
212
|
+
// do not propagate disconnection. NOT terminal — a reconnect rebuilds.
|
|
213
|
+
__classPrivateFieldGet(this, _CompositeController_instances, "m", _CompositeController_teardownShell).call(this);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Idempotent **terminal** teardown: tears down the shell (sources are
|
|
217
|
+
* borrowed) and puts the controller into a disposed state so no later ref
|
|
218
|
+
* callback or reconnect can rebuild it. Use it when you are done with the
|
|
219
|
+
* controller for good; for an ordinary disconnect, the controller already
|
|
220
|
+
* tears the shell down and rebuilds on reconnect without any call.
|
|
221
|
+
*/
|
|
222
|
+
dispose() {
|
|
223
|
+
if (__classPrivateFieldGet(this, _CompositeController_disposed, "f"))
|
|
224
|
+
return;
|
|
225
|
+
__classPrivateFieldSet(this, _CompositeController_disposed, true, "f");
|
|
226
|
+
__classPrivateFieldGet(this, _CompositeController_host, "f").removeController(this);
|
|
227
|
+
__classPrivateFieldGet(this, _CompositeController_instances_1, "f").clear();
|
|
228
|
+
__classPrivateFieldGet(this, _CompositeController_instances, "m", _CompositeController_teardownShell).call(this);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
_CompositeController_host = new WeakMap(), _CompositeController_sources = new WeakMap(), _CompositeController_expose = new WeakMap(), _CompositeController_localFacade = new WeakMap(), _CompositeController_remoteCompatible = new WeakMap(), _CompositeController_logger = new WeakMap(), _CompositeController_instances_1 = new WeakMap(), _CompositeController_refCallbacks = new WeakMap(), _CompositeController_shell = new WeakMap(), _CompositeController_unbind = new WeakMap(), _CompositeController_defined = new WeakMap(), _CompositeController_disposed = new WeakMap(), _CompositeController_instances = new WeakSet(), _CompositeController_onSourceRef = function _CompositeController_onSourceRef(id, el) {
|
|
232
|
+
if (__classPrivateFieldGet(this, _CompositeController_disposed, "f"))
|
|
233
|
+
return; // terminal: never rebuild after dispose()
|
|
234
|
+
if (el) {
|
|
235
|
+
__classPrivateFieldGet(this, _CompositeController_instances_1, "f").set(id, el);
|
|
236
|
+
__classPrivateFieldGet(this, _CompositeController_instances, "m", _CompositeController_tryBuild).call(this);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
__classPrivateFieldGet(this, _CompositeController_instances_1, "f").delete(id);
|
|
240
|
+
// A source detached → the current shell is stale; tear it down so a later
|
|
241
|
+
// reattach rebuilds against the fresh instances.
|
|
242
|
+
__classPrivateFieldGet(this, _CompositeController_instances, "m", _CompositeController_teardownShell).call(this);
|
|
243
|
+
}
|
|
244
|
+
}, _CompositeController_tryBuild = function _CompositeController_tryBuild() {
|
|
245
|
+
if (__classPrivateFieldGet(this, _CompositeController_disposed, "f") || __classPrivateFieldGet(this, _CompositeController_shell, "f") || !__classPrivateFieldGet(this, _CompositeController_defined, "f"))
|
|
246
|
+
return;
|
|
247
|
+
const sources = {};
|
|
248
|
+
for (const spec of __classPrivateFieldGet(this, _CompositeController_sources, "f")) {
|
|
249
|
+
const el = __classPrivateFieldGet(this, _CompositeController_instances_1, "f").get(spec.id);
|
|
250
|
+
if (!el || !isWcBindable(el))
|
|
251
|
+
return; // wait until every source is ready
|
|
252
|
+
sources[spec.id] = el;
|
|
253
|
+
}
|
|
254
|
+
const shell = createCompositeTarget({
|
|
255
|
+
sources,
|
|
256
|
+
expose: __classPrivateFieldGet(this, _CompositeController_expose, "f"),
|
|
257
|
+
localFacade: __classPrivateFieldGet(this, _CompositeController_localFacade, "f"),
|
|
258
|
+
remoteCompatible: __classPrivateFieldGet(this, _CompositeController_remoteCompatible, "f"),
|
|
259
|
+
logger: __classPrivateFieldGet(this, _CompositeController_logger, "f"),
|
|
260
|
+
});
|
|
261
|
+
__classPrivateFieldSet(this, _CompositeController_shell, shell, "f");
|
|
262
|
+
__classPrivateFieldSet(this, _CompositeController_unbind, bind(shell, (name, value) => {
|
|
263
|
+
this.values = { ...this.values, [name]: value };
|
|
264
|
+
__classPrivateFieldGet(this, _CompositeController_host, "f").requestUpdate();
|
|
265
|
+
}), "f");
|
|
266
|
+
__classPrivateFieldGet(this, _CompositeController_host, "f").requestUpdate();
|
|
267
|
+
}, _CompositeController_teardownShell = function _CompositeController_teardownShell() {
|
|
268
|
+
__classPrivateFieldGet(this, _CompositeController_unbind, "f")?.call(this);
|
|
269
|
+
__classPrivateFieldSet(this, _CompositeController_unbind, undefined, "f");
|
|
270
|
+
__classPrivateFieldGet(this, _CompositeController_shell, "f")?.dispose();
|
|
271
|
+
__classPrivateFieldSet(this, _CompositeController_shell, undefined, "f");
|
|
272
|
+
};
|
|
273
|
+
//# sourceMappingURL=lit.js.map
|
package/dist/lit.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lit.js","sourceRoot":"","sources":["../src/lit.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,EAAE;AACF,+EAA+E;AAC/E,6EAA6E;AAC7E,gFAAgF;AAChF,iFAAiF;AACjF,gFAAgF;AAChF,EAAE;AACF,yEAAyE;AACzE,gFAAgF;AAChF,iFAAiF;AACjF,0EAA0E;;;;;;;;;;;;;AAE1E,OAAO,EAAE,UAAU,EAAwD,MAAM,KAAK,CAAC;A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AED,MAAM,KAAK,GAAG,qBAAqB,CAAC;QAClC,OAAO;QACP,MAAM,EAAE,uBAAA,IAAI,mCAAQ;QACpB,WAAW,EAAE,uBAAA,IAAI,wCAAa;QAC9B,gBAAgB,EAAE,uBAAA,IAAI,6CAAkB;QACxC,MAAM,EAAE,uBAAA,IAAI,mCAAQ;KACrB,CAAC,CAAC;IACH,uBAAA,IAAI,8BAAU,KAAK,MAAA,CAAC;IACpB,uBAAA,IAAI,+BAAW,IAAI,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACzC,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAO,CAAC;QACrD,uBAAA,IAAI,iCAAM,CAAC,aAAa,EAAE,CAAC;IAC7B,CAAC,CAAC,MAAA,CAAC;IACH,uBAAA,IAAI,iCAAM,CAAC,aAAa,EAAE,CAAC;AAC7B,CAAC;IAGC,uBAAA,IAAI,mCAAQ,EAAE,KAAd,IAAI,CAAY,CAAC;IACjB,uBAAA,IAAI,+BAAW,SAAS,MAAA,CAAC;IACzB,uBAAA,IAAI,kCAAO,EAAE,OAAO,EAAE,CAAC;IACvB,uBAAA,IAAI,8BAAU,SAAS,MAAA,CAAC;AAC1B,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal structured logger surface, mirroring the shape `@wc-bindable/remote`
|
|
3
|
+
* uses. The composite reference implementation routes getter-failure reports
|
|
4
|
+
* (COMPOSITE.md § 12) through `reportError` where available and otherwise to
|
|
5
|
+
* this injected logger at error level — see the "Reference-implementation
|
|
6
|
+
* choice" note in § 12.
|
|
7
|
+
*/
|
|
8
|
+
export interface Logger {
|
|
9
|
+
debug(message: string, ...args: unknown[]): void;
|
|
10
|
+
warn(message: string, ...args: unknown[]): void;
|
|
11
|
+
error(message: string, ...args: unknown[]): void;
|
|
12
|
+
}
|
|
13
|
+
/** Default logger that writes to the host `console`. */
|
|
14
|
+
export declare const consoleLogger: Logger;
|
|
15
|
+
/** A logger that drops everything — useful for tests and quiet embeddings. */
|
|
16
|
+
export declare const silentLogger: Logger;
|
|
17
|
+
/**
|
|
18
|
+
* Report a non-fatal error per COMPOSITE.md § 12's priority order, adapted to
|
|
19
|
+
* the reference-implementation choice: prefer the global `reportError` (so the
|
|
20
|
+
* error surfaces to host error reporting exactly as core's uncaught getter
|
|
21
|
+
* throw would), and otherwise fall back to the injected logger at error level.
|
|
22
|
+
* The deferred-re-throw path is intentionally avoided because it can terminate
|
|
23
|
+
* a Node process for a single getter bug (§ 12 note).
|
|
24
|
+
*
|
|
25
|
+
* This MUST NOT throw and MUST NOT abort the caller's synchronous loop — a
|
|
26
|
+
* hostile `reportError` is caught and demoted to the logger.
|
|
27
|
+
*/
|
|
28
|
+
export declare function reportComposite(error: unknown, logger: Logger): void;
|
|
29
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CAClD;AAED,wDAAwD;AACxD,eAAO,MAAM,aAAa,EAAE,MAI3B,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,YAAY,EAAE,MAI1B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAiBpE"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Default logger that writes to the host `console`. */
|
|
2
|
+
export const consoleLogger = {
|
|
3
|
+
debug: (message, ...args) => console.debug(message, ...args),
|
|
4
|
+
warn: (message, ...args) => console.warn(message, ...args),
|
|
5
|
+
error: (message, ...args) => console.error(message, ...args),
|
|
6
|
+
};
|
|
7
|
+
/** A logger that drops everything — useful for tests and quiet embeddings. */
|
|
8
|
+
export const silentLogger = {
|
|
9
|
+
debug: () => { },
|
|
10
|
+
warn: () => { },
|
|
11
|
+
error: () => { },
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Report a non-fatal error per COMPOSITE.md § 12's priority order, adapted to
|
|
15
|
+
* the reference-implementation choice: prefer the global `reportError` (so the
|
|
16
|
+
* error surfaces to host error reporting exactly as core's uncaught getter
|
|
17
|
+
* throw would), and otherwise fall back to the injected logger at error level.
|
|
18
|
+
* The deferred-re-throw path is intentionally avoided because it can terminate
|
|
19
|
+
* a Node process for a single getter bug (§ 12 note).
|
|
20
|
+
*
|
|
21
|
+
* This MUST NOT throw and MUST NOT abort the caller's synchronous loop — a
|
|
22
|
+
* hostile `reportError` is caught and demoted to the logger.
|
|
23
|
+
*/
|
|
24
|
+
export function reportComposite(error, logger) {
|
|
25
|
+
const globalReportError = globalThis
|
|
26
|
+
.reportError;
|
|
27
|
+
if (typeof globalReportError === "function") {
|
|
28
|
+
try {
|
|
29
|
+
globalReportError(error);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// Secondary error from a hostile reportError is best-effort: fall through
|
|
34
|
+
// to the logger so the primary error is still observable (§ 12).
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
logger.error("[wc-bindable/composite] getter/delegation error", error);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// The logger itself must never break the fan-out lo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AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reserved-name policy for composed names (COMPOSITE.md § 4).
|
|
3
|
+
*
|
|
4
|
+
* `@wc-bindable/composite` depends only on `@wc-bindable/core`, so it cannot
|
|
5
|
+
* import `@wc-bindable/remote`'s wire validator. Per § 4 a separate-package
|
|
6
|
+
* implementation MUST instead track the SPEC-extensions.md § Reserved names
|
|
7
|
+
* definition itself. This module is that tracked copy; keep it in lockstep with
|
|
8
|
+
* `packages/remote/src/transport/messageValidation.ts`.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Is `name` rejected as a composed property / input / command name?
|
|
12
|
+
*
|
|
13
|
+
* The reference implementation rejects the entire remote wire reserved-name set
|
|
14
|
+
* (the `@wc-bindable/` case-insensitive prefix plus the pollution names) by
|
|
15
|
+
* default — even when remote compatibility is not claimed — because a name that
|
|
16
|
+
* can never be remoted has little upside and silently makes the shell
|
|
17
|
+
* impossible to expose through `@wc-bindable/remote` later (§ 4). It also
|
|
18
|
+
* rejects the fixed-API members.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isReservedComposedName(name: string): boolean;
|
|
21
|
+
/** Human-readable reason a composed name is reserved (for error messages). */
|
|
22
|
+
export declare function reservedComposedNameReason(name: string): string | undefined;
|
|
23
|
+
/** Is `id` rejected as a source id (§ 3)? */
|
|
24
|
+
export declare function isReservedSourceId(id: string): boolean;
|
|
25
|
+
//# sourceMappingURL=reservedNames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reservedNames.d.ts","sourceRoot":"","sources":["../src/reservedNames.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA+CH;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAM5D;AAED,8EAA8E;AAC9E,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK3E;AAED,6CAA6C;AAC7C,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEtD"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reserved-name policy for composed names (COMPOSITE.md § 4).
|
|
3
|
+
*
|
|
4
|
+
* `@wc-bindable/composite` depends only on `@wc-bindable/core`, so it cannot
|
|
5
|
+
* import `@wc-bindable/remote`'s wire validator. Per § 4 a separate-package
|
|
6
|
+
* implementation MUST instead track the SPEC-extensions.md § Reserved names
|
|
7
|
+
* definition itself. This module is that tracked copy; keep it in lockstep with
|
|
8
|
+
* `packages/remote/src/transport/messageValidation.ts`.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The wire-namespace prefix. A composed *name* (not event name) that begins with
|
|
12
|
+
* this prefix case-insensitively is rejected under remote compatibility — and by
|
|
13
|
+
* default here, per § 4's reference-implementation SHOULD-reject-by-default
|
|
14
|
+
* guidance. The match length is always derived from the prefix's own `.length`
|
|
15
|
+
* (see {@link hasWireNamespacePrefix}); there is no hand-maintained magic number.
|
|
16
|
+
*/
|
|
17
|
+
const WIRE_NAMESPACE_PREFIX = "@wc-bindable/";
|
|
18
|
+
/** Prototype-pollution-prone strings, rejected as composed names everywhere. */
|
|
19
|
+
const POLLUTION_NAMES = new Set([
|
|
20
|
+
"__proto__",
|
|
21
|
+
"prototype",
|
|
22
|
+
"constructor",
|
|
23
|
+
]);
|
|
24
|
+
/**
|
|
25
|
+
* Fixed public-API members every composed shell needs (COMPOSITE.md § 4
|
|
26
|
+
* "Fixed-API collisions", all-tiers base set). A composed name equal to one of
|
|
27
|
+
* these would shadow discovery / the bind-target EventTarget surface, so it is
|
|
28
|
+
* rejected on every shell. `dispose` is included because this implementation
|
|
29
|
+
* always materializes a `dispose()` terminal on the shell (§ 10).
|
|
30
|
+
*/
|
|
31
|
+
const FIXED_API_NAMES = new Set([
|
|
32
|
+
"constructor",
|
|
33
|
+
"addEventListener",
|
|
34
|
+
"removeEventListener",
|
|
35
|
+
"dispatchEvent",
|
|
36
|
+
"dispose",
|
|
37
|
+
]);
|
|
38
|
+
/** Source ids that would corrupt a plain-object lookup map (§ 3 guidance). */
|
|
39
|
+
const POLLUTION_SOURCE_IDS = new Set([
|
|
40
|
+
"__proto__",
|
|
41
|
+
"prototype",
|
|
42
|
+
"constructor",
|
|
43
|
+
]);
|
|
44
|
+
function hasWireNamespacePrefix(name) {
|
|
45
|
+
return (name.length >= WIRE_NAMESPACE_PREFIX.length &&
|
|
46
|
+
name.slice(0, WIRE_NAMESPACE_PREFIX.length).toLowerCase() === WIRE_NAMESPACE_PREFIX);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Is `name` rejected as a composed property / input / command name?
|
|
50
|
+
*
|
|
51
|
+
* The reference implementation rejects the entire remote wire reserved-name set
|
|
52
|
+
* (the `@wc-bindable/` case-insensitive prefix plus the pollution names) by
|
|
53
|
+
* default — even when remote compatibility is not claimed — because a name that
|
|
54
|
+
* can never be remoted has little upside and silently makes the shell
|
|
55
|
+
* impossible to expose through `@wc-bindable/remote` later (§ 4). It also
|
|
56
|
+
* rejects the fixed-API members.
|
|
57
|
+
*/
|
|
58
|
+
export function isReservedComposedName(name) {
|
|
59
|
+
return (POLLUTION_NAMES.has(name) ||
|
|
60
|
+
FIXED_API_NAMES.has(name) ||
|
|
61
|
+
hasWireNamespacePrefix(name));
|
|
62
|
+
}
|
|
63
|
+
/** Human-readable reason a composed name is reserved (for error messages). */
|
|
64
|
+
export function reservedComposedNameReason(name) {
|
|
65
|
+
if (POLLUTION_NAMES.has(name))
|
|
66
|
+
return "prototype-pollution-prone name";
|
|
67
|
+
if (FIXED_API_NAMES.has(name))
|
|
68
|
+
return "shadows a fixed shell API member";
|
|
69
|
+
if (hasWireNamespacePrefix(name))
|
|
70
|
+
return "uses the reserved @wc-bindable/ wire prefix";
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
/** Is `id` rejected as a source id (§ 3)? */
|
|
74
|
+
export function isReservedSourceId(id) {
|
|
75
|
+
return id.length === 0 || id.includes(".") || POLLUTION_SOURCE_IDS.has(id);
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=reservedNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reservedNames.js","sourceRoot":"","sources":["../src/reservedNames.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;GAMG;AACH,MAAM,qBAAqB,GAAG,eAAe,CAAC;AAE9C,gFAAgF;AAChF,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IACnD,WAAW;IACX,WAAW;IACX,aAAa;CACd,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC;IACnD,aAAa;IACb,kBAAkB;IAClB,qBAAqB;IACrB,eAAe;IACf,SAAS;CACV,CAAC,CAAC;AAEH,8EAA8E;AAC9E,MAAM,oBAAoB,GAAwB,IAAI,GAAG,CAAC;IACxD,WAAW;IACX,WAAW;IACX,aAAa;CACd,CAAC,CAAC;AAEH,SAAS,sBAAsB,CAAC,IAAY;IAC1C,OAAO,CACL,IAAI,CAAC,MAAM,IAAI,qBAAqB,CAAC,MAAM;QAC3C,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,qBAAqB,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,KAAK,qBAAqB,CACpF,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,OAAO,CACL,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC;QACzB,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC;QACzB,sBAAsB,CAAC,IAAI,CAAC,CAC7B,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,0BAA0B,CAAC,IAAY;IACrD,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CA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