@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
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TemplateMeta } from './template.js';
|
|
2
|
+
export declare const TEMPLATES_REGISTERED_EVENT = "webui:templates-registered";
|
|
3
|
+
export declare function dispatchTemplatesRegistered(templates: Record<string, TemplateMeta>): void;
|
|
4
|
+
export declare function templateRegistrationDetail(event: Event): {
|
|
5
|
+
templates?: Record<string, TemplateMeta>;
|
|
6
|
+
} | undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const TEMPLATES_REGISTERED_EVENT = 'webui:templates-registered';
|
|
2
|
+
export function dispatchTemplatesRegistered(templates) {
|
|
3
|
+
if (typeof window === 'undefined' ||
|
|
4
|
+
typeof CustomEvent !== 'function' ||
|
|
5
|
+
typeof window.dispatchEvent !== 'function') {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
window.dispatchEvent(new CustomEvent(TEMPLATES_REGISTERED_EVENT, {
|
|
9
|
+
detail: { templates },
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
12
|
+
export function templateRegistrationDetail(event) {
|
|
13
|
+
const detail = event.detail;
|
|
14
|
+
if (!detail || typeof detail !== 'object')
|
|
15
|
+
return undefined;
|
|
16
|
+
const templates = detail.templates;
|
|
17
|
+
const payload = {
|
|
18
|
+
templates: typeof templates === 'object' && templates !== null
|
|
19
|
+
? templates
|
|
20
|
+
: undefined,
|
|
21
|
+
};
|
|
22
|
+
return payload.templates ? payload : undefined;
|
|
23
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { TemplateMeta } from './template.js';
|
|
2
|
+
export declare function templateHasRoot(meta: TemplateMeta, root: string): boolean;
|
|
3
|
+
export declare function templateRootForAttribute(meta: TemplateMeta, attrName: string): string | undefined;
|
|
4
|
+
export declare function templateNeedsStaticHost(meta: TemplateMeta): boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function templateHasRoot(meta, root) {
|
|
2
|
+
const roots = meta.tr;
|
|
3
|
+
if (!roots)
|
|
4
|
+
return false;
|
|
5
|
+
for (let i = 0; i < roots.length; i++) {
|
|
6
|
+
if (roots[i] === root)
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
export function templateRootForAttribute(meta, attrName) {
|
|
12
|
+
const roots = meta.tr;
|
|
13
|
+
const attrs = meta.ta;
|
|
14
|
+
if (!roots || !attrs)
|
|
15
|
+
return undefined;
|
|
16
|
+
for (let i = 0; i < attrs.length && i < roots.length; i++) {
|
|
17
|
+
if (attrs[i] === attrName)
|
|
18
|
+
return roots[i];
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
export function templateNeedsStaticHost(meta) {
|
|
23
|
+
return !!meta.th;
|
|
24
|
+
}
|
package/dist/template-types.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Template type definitions — shared across packages without pulling in
|
|
3
|
-
* the global `Window` augmentation from `template.ts`.
|
|
4
|
-
*/
|
|
5
1
|
export type CompiledAttrPart = string | [path: string];
|
|
6
2
|
export type TemplateNodePath = number[];
|
|
7
3
|
export type TemplateSlotPath = [
|
|
@@ -15,24 +11,28 @@ export type CompiledAttrGroupMeta = [
|
|
|
15
11
|
start: number,
|
|
16
12
|
count: number
|
|
17
13
|
];
|
|
18
|
-
/**
|
|
19
|
-
* Compiled condition — JSON metadata carries a function index plus the paths it
|
|
20
|
-
* references. The Rust compiler emits the actual function bodies in a separate
|
|
21
|
-
* closure array, and the runtime normalizes indexes to functions once.
|
|
22
|
-
*
|
|
23
|
-
* - `[0]` — evaluator function or component-local function index
|
|
24
|
-
* - `[1]` — referenced paths for the reactive path index
|
|
25
|
-
*/
|
|
26
14
|
export type CompiledConditionFn = (v: (path: string, s?: unknown) => unknown, s?: unknown) => boolean;
|
|
27
15
|
export type CompiledCondition = [fn: CompiledConditionFn, paths: string[]];
|
|
28
16
|
export type SerializedCompiledCondition = [fnIndex: number, paths: string[]];
|
|
29
17
|
export type TemplateCondition = CompiledCondition | SerializedCompiledCondition;
|
|
30
18
|
export type CompiledConditionalMeta = [condition: TemplateCondition, blockIndex: number, slot: TemplateSlotPath];
|
|
31
19
|
export type CompiledAttrMeta = [name: string, kind: 0, value: string] | [name: string, kind: 1, value: string] | [name: string, kind: 2, condition: TemplateCondition] | [name: string, kind: 3, parts: CompiledAttrPart[]];
|
|
32
|
-
export type CompiledRepeatMeta = [
|
|
20
|
+
export type CompiledRepeatMeta = [
|
|
21
|
+
collection: string,
|
|
22
|
+
itemVar: string,
|
|
23
|
+
blockIndex: number,
|
|
24
|
+
slot: TemplateSlotPath,
|
|
25
|
+
keyPath?: string
|
|
26
|
+
];
|
|
33
27
|
export type CompiledEventArg = ['e'] | ['p', string] | ['s', string] | ['n', number] | ['b', number] | ['z'];
|
|
34
28
|
export type CompiledEventArgs = CompiledEventArg[];
|
|
35
|
-
export type
|
|
29
|
+
export type CompiledEventBindingMeta = [
|
|
30
|
+
handler: string,
|
|
31
|
+
args: CompiledEventArgs,
|
|
32
|
+
target: TemplateNodePath,
|
|
33
|
+
usesEvent?: 1
|
|
34
|
+
];
|
|
35
|
+
export type CompiledEventGroupMeta = [name: string, bindings: CompiledEventBindingMeta[]];
|
|
36
36
|
export interface TemplateBlockMeta {
|
|
37
37
|
h: string;
|
|
38
38
|
tx?: CompiledTextRunMeta[];
|
|
@@ -40,12 +40,14 @@ export interface TemplateBlockMeta {
|
|
|
40
40
|
ag?: CompiledAttrGroupMeta[];
|
|
41
41
|
c?: CompiledConditionalMeta[];
|
|
42
42
|
r?: CompiledRepeatMeta[];
|
|
43
|
-
|
|
43
|
+
eg?: CompiledEventGroupMeta[];
|
|
44
44
|
}
|
|
45
45
|
export interface TemplateMeta extends TemplateBlockMeta {
|
|
46
46
|
b?: TemplateBlockMeta[];
|
|
47
47
|
sa?: string;
|
|
48
48
|
re?: [string, string, CompiledEventArgs][];
|
|
49
|
-
|
|
49
|
+
tr?: string[];
|
|
50
|
+
ta?: string[];
|
|
50
51
|
sd?: boolean;
|
|
52
|
+
th?: boolean | 1;
|
|
51
53
|
}
|
package/dist/template-types.js
CHANGED
package/dist/template.d.ts
CHANGED
|
@@ -1,31 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
* Template registry — stores compiled metadata objects from the Rust compiler.
|
|
3
|
-
*
|
|
4
|
-
* Each entry is a metadata object with:
|
|
5
|
-
* - `h` — static HTML for the component template
|
|
6
|
-
* - `tx` — text runs `[slot, parts]` for text binding positions
|
|
7
|
-
* - `a` — attribute binding metadata
|
|
8
|
-
* - `ag` — attribute target groups `[path, startIndex, count]`
|
|
9
|
-
* - `c` — conditional blocks `[conditionRef, blockIndex, slot]`
|
|
10
|
-
* - `r` — repeat/for blocks `[collection, itemVar, blockIndex, slot]`
|
|
11
|
-
* - `e` — element events `[eventName, handlerName, argSpecs, targetPath]`
|
|
12
|
-
* - `b` — nested compiled block metadata
|
|
13
|
-
* - `sa` — adopted stylesheet specifier for CSS module strategy
|
|
14
|
-
* - `sd` — shadow DOM flag for client-created components
|
|
15
|
-
* - `re` — root events on the host element
|
|
16
|
-
*/
|
|
17
|
-
export type { CompiledAttrGroupMeta, CompiledAttrMeta, CompiledAttrPart, CompiledCondition, CompiledConditionFn, CompiledConditionalMeta, CompiledEventArg, CompiledEventArgs, SerializedCompiledCondition, TemplateCondition, CompiledTextRunMeta, TemplateBlockMeta, TemplateMeta, TemplateNodePath, TemplateSlotPath, } from './template-types.js';
|
|
1
|
+
export type { CompiledAttrGroupMeta, CompiledAttrMeta, CompiledAttrPart, CompiledCondition, CompiledConditionFn, CompiledConditionalMeta, CompiledEventArg, CompiledEventArgs, CompiledEventBindingMeta, CompiledEventGroupMeta, SerializedCompiledCondition, TemplateCondition, CompiledTextRunMeta, TemplateBlockMeta, TemplateMeta, TemplateNodePath, TemplateSlotPath, } from './template-types.js';
|
|
18
2
|
import type { CompiledConditionFn, TemplateMeta } from './template-types.js';
|
|
19
3
|
declare global {
|
|
20
4
|
interface Window {
|
|
21
|
-
/** Consolidated SSR metadata loaded from `#webui-data` or partial responses. */
|
|
22
5
|
__webui?: {
|
|
23
6
|
state?: Record<string, unknown>;
|
|
24
7
|
templates?: Record<string, TemplateMeta>;
|
|
25
8
|
templateFns?: Record<string, CompiledConditionFn[]>;
|
|
9
|
+
templateHostExclusions?: Set<string>;
|
|
26
10
|
[key: string]: unknown;
|
|
27
11
|
};
|
|
28
12
|
}
|
|
29
13
|
}
|
|
30
14
|
export declare function getTemplate(name: string): TemplateMeta | undefined;
|
|
15
|
+
export declare function getTemplateRegistry(): Record<string, TemplateMeta> | undefined;
|
|
31
16
|
export declare function registerTemplateData(templates: Record<string, TemplateMeta>, templateFns?: Record<string, CompiledConditionFn[]>): void;
|
package/dist/template.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// Licensed under the MIT license.
|
|
1
|
+
import { dispatchTemplatesRegistered } from './template-events.js';
|
|
3
2
|
const WEBUI_DATA_ID = 'webui-data';
|
|
4
3
|
const normalizedTemplates = new WeakSet();
|
|
5
4
|
let webuiDataLoaded = false;
|
|
@@ -13,6 +12,10 @@ export function getTemplate(name) {
|
|
|
13
12
|
normalizeTemplate(name, meta);
|
|
14
13
|
return meta;
|
|
15
14
|
}
|
|
15
|
+
export function getTemplateRegistry() {
|
|
16
|
+
loadWebUIDataBlock();
|
|
17
|
+
return window.__webui?.templates;
|
|
18
|
+
}
|
|
16
19
|
export function registerTemplateData(templates, templateFns) {
|
|
17
20
|
const w = window;
|
|
18
21
|
if (!w.__webui)
|
|
@@ -29,12 +32,16 @@ export function registerTemplateData(templates, templateFns) {
|
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
const names = Object.keys(templates);
|
|
35
|
+
let hasTemplates = false;
|
|
32
36
|
for (let i = 0; i < names.length; i++) {
|
|
33
37
|
const tag = names[i];
|
|
34
38
|
const meta = templates[tag];
|
|
35
39
|
w.__webui.templates[tag] = meta;
|
|
36
40
|
normalizeTemplate(tag, meta);
|
|
41
|
+
hasTemplates = true;
|
|
37
42
|
}
|
|
43
|
+
if (hasTemplates)
|
|
44
|
+
dispatchTemplatesRegistered(templates);
|
|
38
45
|
}
|
|
39
46
|
function loadWebUIDataBlock() {
|
|
40
47
|
if (webuiDataLoaded || window.__webui?.state !== undefined || typeof document === 'undefined')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/webui-framework",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "WebUI Framework Next — Preact-inspired lightweight Web Component runtime with SSR hydration. 15KB minified, compiled-template path mapping, no hydration markers.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,16 +10,22 @@
|
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"default": "./dist/index.js"
|
|
12
12
|
}
|
|
13
|
+
},
|
|
14
|
+
"./component-asset.js": {
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/component-asset.d.ts",
|
|
17
|
+
"default": "./dist/component-asset.js"
|
|
18
|
+
}
|
|
13
19
|
}
|
|
14
20
|
},
|
|
15
21
|
"files": [
|
|
16
22
|
"dist/"
|
|
17
23
|
],
|
|
18
24
|
"devDependencies": {
|
|
19
|
-
"@playwright/test": "^1.
|
|
20
|
-
"@types/node": "^
|
|
21
|
-
"typescript": "^
|
|
22
|
-
"@microsoft/webui-test-support": "0.0.
|
|
25
|
+
"@playwright/test": "^1.61.1",
|
|
26
|
+
"@types/node": "^26.1.0",
|
|
27
|
+
"typescript": "^6.0.3",
|
|
28
|
+
"@microsoft/webui-test-support": "0.0.19"
|
|
23
29
|
},
|
|
24
30
|
"scripts": {
|
|
25
31
|
"build": "tsc",
|