@microsoft/webui-framework 0.0.17 → 0.0.19
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 +164 -70
- package/dist/component-asset.d.ts +30 -0
- package/dist/component-asset.js +213 -0
- package/dist/decorators.d.ts +3 -53
- package/dist/decorators.js +96 -171
- package/dist/element/diff.d.ts +3 -21
- package/dist/element/diff.js +201 -131
- package/dist/element/markers.d.ts +0 -44
- package/dist/element/markers.js +18 -59
- package/dist/element/styles.d.ts +0 -10
- package/dist/element/styles.js +2 -63
- package/dist/element/types.d.ts +20 -47
- package/dist/element/types.js +3 -3
- package/dist/element.d.ts +13 -131
- package/dist/element.js +102 -1355
- package/dist/hydration-mismatch.d.ts +22 -0
- package/dist/hydration-mismatch.js +88 -0
- package/dist/index.d.ts +0 -19
- package/dist/index.js +2 -21
- package/dist/lifecycle.d.ts +0 -8
- package/dist/lifecycle.js +0 -32
- package/dist/static-host.d.ts +1 -0
- package/dist/static-host.js +66 -0
- package/dist/template-element.d.ts +87 -0
- package/dist/template-element.js +1392 -0
- package/dist/template-events.d.ts +6 -0
- package/dist/template-events.js +23 -0
- package/dist/template-roots.d.ts +4 -0
- package/dist/template-roots.js +24 -0
- package/dist/template-types.d.ts +18 -16
- package/dist/template-types.js +0 -2
- package/dist/template.d.ts +3 -18
- package/dist/template.js +9 -2
- package/package.json +11 -5
package/dist/element/types.d.ts
CHANGED
|
@@ -1,41 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
* Shared runtime types for the WebUI element system.
|
|
3
|
-
*
|
|
4
|
-
* These types define the binding data structures that are created once during
|
|
5
|
-
* hydration and then read on every reactive update. Each binding holds a
|
|
6
|
-
* direct DOM node reference so that updates can patch the DOM in O(1) per
|
|
7
|
-
* binding without any tree walking or selector queries.
|
|
8
|
-
*
|
|
9
|
-
* ## Key concepts
|
|
10
|
-
*
|
|
11
|
-
* - **TemplateInstance** — a connected block of DOM with its bindings. The
|
|
12
|
-
* root component has one instance; conditionals and repeat items each get
|
|
13
|
-
* their own nested instance.
|
|
14
|
-
*
|
|
15
|
-
* - **ScopeFrame** — a linked-list frame for repeat variable scoping.
|
|
16
|
-
* `@for(item of items)` creates a frame `{ name: 'item', value, parent }`.
|
|
17
|
-
* Nested repeats chain frames so inner bindings can resolve outer variables.
|
|
18
|
-
*/
|
|
19
|
-
import type { CompiledAttrMeta, CompiledAttrPart, CompiledCondition } from '../template.js';
|
|
20
|
-
/** Direct reference to a text node bound to a property path. */
|
|
1
|
+
import type { CompiledAttrPart, CompiledCondition } from '../template.js';
|
|
21
2
|
export interface TextBinding {
|
|
22
3
|
node: Text;
|
|
23
4
|
path?: string;
|
|
24
5
|
parts?: CompiledAttrPart[];
|
|
25
6
|
scope?: ScopeFrame;
|
|
26
|
-
/** When true, the binding renders unescaped HTML via innerHTML on the
|
|
27
|
-
* parent element instead of setting Text.data. Corresponds to the
|
|
28
|
-
* triple-brace `{{{expr}}}` template syntax. */
|
|
29
7
|
raw?: boolean;
|
|
30
|
-
/** The parent element for raw bindings — innerHTML is set here. */
|
|
31
8
|
rawParent?: Element;
|
|
32
9
|
}
|
|
33
|
-
/** Attribute binding kind constants (matches compiled metadata). */
|
|
34
10
|
export declare const ATTR_KIND_ATTRIBUTE = 0;
|
|
35
11
|
export declare const ATTR_KIND_COMPLEX = 1;
|
|
36
12
|
export declare const ATTR_KIND_BOOLEAN = 2;
|
|
37
13
|
export declare const ATTR_KIND_TEMPLATE = 3;
|
|
38
|
-
|
|
14
|
+
export declare function hasNativeLiveProperty(element: Element, name: string): boolean;
|
|
39
15
|
export interface AttrBinding {
|
|
40
16
|
element: Element;
|
|
41
17
|
name: string;
|
|
@@ -49,24 +25,35 @@ export interface ScopeFrame {
|
|
|
49
25
|
name: string;
|
|
50
26
|
value: unknown;
|
|
51
27
|
parent?: ScopeFrame;
|
|
28
|
+
known?: boolean;
|
|
52
29
|
}
|
|
53
30
|
export interface TemplateInstance {
|
|
54
31
|
scope?: ScopeFrame;
|
|
32
|
+
parent?: TemplateInstance;
|
|
33
|
+
container: (ParentNode & Node) | null;
|
|
55
34
|
nodes: Node[];
|
|
56
35
|
texts: TextBinding[];
|
|
57
36
|
attrs: AttrBinding[];
|
|
58
37
|
conds: CondBinding[];
|
|
59
38
|
repeats: RepeatBinding[];
|
|
39
|
+
cleanups?: Array<() => void>;
|
|
60
40
|
}
|
|
61
|
-
/** Direct reference to a conditional block with anchor + nested compiled block. */
|
|
62
41
|
export interface CondBinding {
|
|
63
42
|
condition: CompiledCondition;
|
|
64
43
|
blockIndex: number;
|
|
65
44
|
anchor: Comment;
|
|
66
45
|
scope?: ScopeFrame;
|
|
46
|
+
owner: TemplateInstance;
|
|
67
47
|
instance: TemplateInstance | null;
|
|
68
48
|
}
|
|
69
|
-
|
|
49
|
+
export type RepeatKey = string | number;
|
|
50
|
+
export interface RepeatKeyState {
|
|
51
|
+
path: string;
|
|
52
|
+
warned: boolean;
|
|
53
|
+
keys: RepeatKey[];
|
|
54
|
+
nextKeys: RepeatKey[];
|
|
55
|
+
map: Map<RepeatKey, TemplateInstance | null>;
|
|
56
|
+
}
|
|
70
57
|
export interface RepeatBinding {
|
|
71
58
|
markerId: number;
|
|
72
59
|
collection: string;
|
|
@@ -77,30 +64,16 @@ export interface RepeatBinding {
|
|
|
77
64
|
end: Comment | null;
|
|
78
65
|
scope?: ScopeFrame;
|
|
79
66
|
owner: TemplateInstance;
|
|
80
|
-
instances:
|
|
81
|
-
|
|
82
|
-
attrMap: Record<string, string>;
|
|
83
|
-
rootBindings: CompiledAttrMeta[];
|
|
84
|
-
/** Set to true once the collection has been explicitly set by client code. */
|
|
67
|
+
instances: TemplateInstance[];
|
|
68
|
+
keyState?: RepeatKeyState;
|
|
85
69
|
synced?: boolean;
|
|
86
70
|
}
|
|
87
|
-
export interface RepeatItemInstance {
|
|
88
|
-
key: string | null;
|
|
89
|
-
value: unknown;
|
|
90
|
-
instance: TemplateInstance;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Minimal host interface for repeat operations.
|
|
94
|
-
*
|
|
95
|
-
* Repeat functions need access to host capabilities (value resolution,
|
|
96
|
-
* block lookup, instance management) without depending on the full
|
|
97
|
-
* WebUIElement class.
|
|
98
|
-
*/
|
|
99
71
|
export interface RepeatHost {
|
|
100
72
|
$resolveValue(path: string, scope?: ScopeFrame): unknown;
|
|
101
|
-
|
|
102
|
-
$createBlockInstance(blockIndex: number, scope?: ScopeFrame): TemplateInstance | null;
|
|
73
|
+
$hasStateRoot(path: string, scope?: ScopeFrame): boolean;
|
|
74
|
+
$createBlockInstance(blockIndex: number, scope?: ScopeFrame, parent?: TemplateInstance, container?: ParentNode & Node): TemplateInstance | null;
|
|
103
75
|
$updateInstance(instance: TemplateInstance): void;
|
|
104
76
|
$removeInstance(instance: TemplateInstance): void;
|
|
77
|
+
$changeStructure(removedFrom?: TemplateInstance): void;
|
|
105
78
|
$insertInstanceAfter(cursor: Node | null, container: ParentNode & Node, instance: TemplateInstance): Node | null;
|
|
106
79
|
}
|
package/dist/element/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT license.
|
|
3
|
-
/** Attribute binding kind constants (matches compiled metadata). */
|
|
4
1
|
export const ATTR_KIND_ATTRIBUTE = 0;
|
|
5
2
|
export const ATTR_KIND_COMPLEX = 1;
|
|
6
3
|
export const ATTR_KIND_BOOLEAN = 2;
|
|
7
4
|
export const ATTR_KIND_TEMPLATE = 3;
|
|
5
|
+
export function hasNativeLiveProperty(element, name) {
|
|
6
|
+
return element.localName.indexOf('-') === -1 && name in element;
|
|
7
|
+
}
|
package/dist/element.d.ts
CHANGED
|
@@ -1,140 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { TemplateElement } from './template-element.js';
|
|
2
|
+
import type { TemplateBlockMeta, TemplateNodePath } from './template.js';
|
|
2
3
|
import type { ScopeFrame, TemplateInstance } from './element/types.js';
|
|
3
|
-
export declare class WebUIElement extends
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
private $hydrated;
|
|
8
|
-
private $dirtyPaths;
|
|
9
|
-
private $pendingFlush;
|
|
10
|
-
/** Cached condition resolver — avoids allocating a closure per evaluation. */
|
|
11
|
-
private $resolver;
|
|
12
|
-
private $pathIndex?;
|
|
13
|
-
/** Bindings that reference non-observable paths — updated on every flush. */
|
|
14
|
-
private $wildcardBindings?;
|
|
15
|
-
static define(tagName: string): void;
|
|
16
|
-
connectedCallback(): void;
|
|
17
|
-
/** Mount the component after children are available. */
|
|
18
|
-
private $mount;
|
|
19
|
-
disconnectedCallback(): void;
|
|
20
|
-
/**
|
|
21
|
-
* Permanently destroy this component's own bindings and DOM references.
|
|
22
|
-
* Each component is responsible for its own cleanup — child WebUI
|
|
23
|
-
* elements handle theirs via their own `disconnectedCallback`.
|
|
24
|
-
*/
|
|
25
|
-
$destroy(): void;
|
|
26
|
-
/** Break all DOM references held by a binding instance and its nested blocks. */
|
|
27
|
-
private $teardown;
|
|
28
|
-
/** Dispatch a bubbling custom event. Uses composed:true when in shadow DOM. */
|
|
4
|
+
export declare class WebUIElement extends TemplateElement {
|
|
5
|
+
protected $observableNames(): Set<string>;
|
|
6
|
+
protected $shouldApplySSRState(key: string): boolean;
|
|
7
|
+
protected $syncAuthoredAttributes(): void;
|
|
29
8
|
$emit(name: string, detail?: unknown): boolean;
|
|
30
|
-
|
|
31
|
-
*
|
|
32
|
-
* Each property is set through its reactive setter, which coalesces
|
|
33
|
-
* updates into a single pending microtask. We then synchronously
|
|
34
|
-
* flush those pending path updates so the DOM is current before any
|
|
35
|
-
* view-transition snapshot captures it.
|
|
36
|
-
*/
|
|
37
|
-
setState(state: Record<string, unknown>): void;
|
|
38
|
-
/**
|
|
39
|
-
* Apply SSR state from `window.__webui.state`.
|
|
40
|
-
*
|
|
41
|
-
* The handler emits all SSR metadata in a single consolidated
|
|
42
|
-
* `window.__webui` script block. State lives at `.state` — the same
|
|
43
|
-
* props passed to the server render so observables match the DOM.
|
|
44
|
-
* Only observable properties are set — unknown keys are ignored.
|
|
45
|
-
*
|
|
46
|
-
* Writes directly to the backing field (`_prop`) to avoid triggering
|
|
47
|
-
* reactive updates before bindings are wired.
|
|
48
|
-
*/
|
|
49
|
-
private $applySSRState;
|
|
50
|
-
/** Reactive update — called by @observable/@attr setters. */
|
|
51
|
-
$update(path?: string): void;
|
|
52
|
-
/** Synchronously flush all queued path updates. Call this when you need
|
|
53
|
-
* the DOM to reflect pending property changes immediately. */
|
|
54
|
-
$flushUpdates(): void;
|
|
55
|
-
/** Flush all queued path updates. Handles re-entrant setter calls. */
|
|
56
|
-
private $flush;
|
|
57
|
-
private $resolve;
|
|
58
|
-
private $resolveSSR;
|
|
59
|
-
private $parseTemplate;
|
|
60
|
-
private $createStagingRoot;
|
|
61
|
-
private $appendStagedChildren;
|
|
62
|
-
private $releaseStagingRepeatContainers;
|
|
63
|
-
private $wire;
|
|
64
|
-
/**
|
|
65
|
-
* Hydrate SSR-rendered DOM against compiled template metadata.
|
|
66
|
-
*
|
|
67
|
-
* When pathStart=0 (default): ssrRoot is a container with children
|
|
68
|
-
* (top-level component hydration).
|
|
69
|
-
*
|
|
70
|
-
* When pathStart=1: ssrRoot is a block element itself (repeat item
|
|
71
|
-
* in-place hydration). The leading [0] wrapper segment is skipped
|
|
72
|
-
* so compiled paths resolve directly against the element.
|
|
73
|
-
*/
|
|
74
|
-
private $hydrate;
|
|
75
|
-
/** Collect sibling nodes between a start marker and an end marker comment. */
|
|
76
|
-
private $collectBetween;
|
|
77
|
-
/**
|
|
78
|
-
* Hydrate a conditional block's content — shared by top-level and
|
|
79
|
-
* repeat-item conditional hydration paths.
|
|
80
|
-
*/
|
|
81
|
-
private $hydrateCondContent;
|
|
82
|
-
/**
|
|
83
|
-
* Find the next marker comment with the given data among a parent's children.
|
|
84
|
-
* Starts searching from `after` (exclusive) if provided, or from firstChild.
|
|
85
|
-
*/
|
|
86
|
-
private $findMarker;
|
|
87
|
-
/**
|
|
88
|
-
* Check whether there is non-marker content between a conditional
|
|
89
|
-
* start anchor and its closing marker. Used during SSR hydration to
|
|
90
|
-
* detect server-rendered conditional content even when the runtime
|
|
91
|
-
* condition value has not been set yet (e.g. complex property from a
|
|
92
|
-
* parent repeat binding that hydrates after its children).
|
|
93
|
-
*/
|
|
94
|
-
private $hasContentAfterMarker;
|
|
95
|
-
/**
|
|
96
|
-
* Find existing SSR text node by mapping template text-node ordinal.
|
|
97
|
-
*
|
|
98
|
-
* Similar to `$resolveSSR`, the SSR DOM may contain extra text nodes
|
|
99
|
-
* inside structural blocks (`<if>`/`<for>`) that are not in the
|
|
100
|
-
* compiled template. We skip `<!--wc-->...<!--/wc-->` and
|
|
101
|
-
* `<!--wr-->...<!--/wr-->` ranges to keep text ordinals aligned.
|
|
102
|
-
*/
|
|
103
|
-
private $findSSRText;
|
|
104
|
-
/** Find the SSR insertion reference for an empty text slot. */
|
|
105
|
-
private $findSSRSlotRef;
|
|
106
|
-
/** Extract root tag name from block metadata. */
|
|
107
|
-
private $rootTag;
|
|
108
|
-
/** Wire attribute bindings using a resolver (shared by $wire and $hydrate). */
|
|
109
|
-
private $wireAttrs;
|
|
110
|
-
/** Wire events + root events + refs (shared by $wire and $hydrate). */
|
|
111
|
-
private $finalize;
|
|
112
|
-
/** Wire events using a resolver function (works for both client and SSR). */
|
|
9
|
+
protected $finalize(instance: TemplateInstance, root: Node, meta: TemplateBlockMeta, resolver: (root: Node, path: TemplateNodePath) => Node | null, scope?: ScopeFrame): void;
|
|
113
10
|
private $wireEvents;
|
|
114
|
-
|
|
11
|
+
private $resolveDelegatedEvents;
|
|
115
12
|
private $wireRoot;
|
|
116
|
-
|
|
13
|
+
private $addDelegatedEvent;
|
|
14
|
+
private $dispatchDelegatedEvent;
|
|
117
15
|
private $addEvent;
|
|
16
|
+
private $addCleanup;
|
|
17
|
+
private $callEventHandler;
|
|
18
|
+
private $callEventHandlerWithCurrentTarget;
|
|
118
19
|
private $resolveEventArgs;
|
|
119
20
|
private $resolveEventArg;
|
|
120
|
-
/** Find w-ref attributes and assign to component properties. */
|
|
121
21
|
private $wireRefs;
|
|
122
|
-
/** Create an AttrBinding from compiled metadata. */
|
|
123
|
-
private $makeAttr;
|
|
124
|
-
/** Build attrMap and rootBindings for a repeat block. */
|
|
125
|
-
private $repeatMaps;
|
|
126
|
-
private $buildPathIndex;
|
|
127
|
-
private $updateBindings;
|
|
128
|
-
$updateInstance(instance: TemplateInstance): void;
|
|
129
|
-
private $patchText;
|
|
130
|
-
private $patchAttr;
|
|
131
|
-
private $toggleCond;
|
|
132
|
-
$resolveValue(path: string, scope?: ScopeFrame): unknown;
|
|
133
|
-
private $resolveParts;
|
|
134
|
-
$block(blockIndex: number): TemplateBlockMeta | undefined;
|
|
135
|
-
$createBlockInstance(blockIndex: number, scope?: ScopeFrame): TemplateInstance | null;
|
|
136
|
-
$removeInstance(instance: TemplateInstance): void;
|
|
137
|
-
$insertInstanceAfter(cursor: Node | null, container: ParentNode & Node, instance: TemplateInstance): Node | null;
|
|
138
|
-
/** Extract the single dynamic path from a compiled attr parts array. */
|
|
139
|
-
private $singleDynamic;
|
|
140
22
|
}
|