@microsoft/webui-framework 0.0.19 → 0.0.21
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 +73 -22
- package/dist/component-asset/asset.d.ts +22 -0
- package/dist/component-asset/asset.js +171 -0
- package/dist/component-asset/loader.d.ts +1 -0
- package/dist/component-asset/loader.js +104 -0
- package/dist/component-asset/manifest.d.ts +20 -0
- package/dist/component-asset/manifest.js +1 -0
- package/dist/component-asset/resources.d.ts +4 -0
- package/dist/component-asset/resources.js +83 -0
- package/dist/component-asset.d.ts +3 -29
- package/dist/component-asset.js +1 -135
- package/dist/element.d.ts +0 -4
- package/dist/element.js +8 -67
- package/dist/lifecycle.d.ts +17 -0
- package/dist/lifecycle.js +66 -3
- package/dist/static-host.js +4 -2
- package/dist/streaming-activation.d.ts +2 -0
- package/dist/streaming-activation.js +13 -0
- package/dist/streaming-bootstrap.d.ts +2 -0
- package/dist/streaming-bootstrap.js +48 -0
- package/dist/streaming-cleanup.d.ts +4 -0
- package/dist/streaming-cleanup.js +66 -0
- package/dist/streaming-coordinator.d.ts +7 -0
- package/dist/streaming-coordinator.js +364 -0
- package/dist/streaming-deferred.d.ts +22 -0
- package/dist/streaming-deferred.js +287 -0
- package/dist/streaming-dom.d.ts +32 -0
- package/dist/streaming-dom.js +148 -0
- package/dist/streaming-entry.d.ts +1 -0
- package/dist/streaming-entry.js +2 -0
- package/dist/streaming-install.d.ts +2 -0
- package/dist/streaming-install.js +25 -0
- package/dist/streaming-mode.d.ts +5 -0
- package/dist/streaming-mode.js +14 -0
- package/dist/streaming-protocol.d.ts +32 -0
- package/dist/streaming-protocol.js +27 -0
- package/dist/streaming-state.d.ts +1 -0
- package/dist/streaming-state.js +13 -0
- package/dist/streaming.d.ts +5 -0
- package/dist/streaming.js +9 -0
- package/dist/template-element.d.ts +9 -1
- package/dist/template-element.js +112 -42
- package/dist/template-types.d.ts +1 -1
- package/dist/template.d.ts +2 -0
- package/dist/template.js +74 -25
- package/package.json +9 -3
package/dist/template.js
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
import { dispatchTemplatesRegistered } from './template-events.js';
|
|
1
|
+
import { dispatchTemplatesRegistered, templateRegistrationDetail, TEMPLATES_REGISTERED_EVENT, } from './template-events.js';
|
|
2
2
|
const WEBUI_DATA_ID = 'webui-data';
|
|
3
3
|
const normalizedTemplates = new WeakSet();
|
|
4
|
+
const assetNormalizedTemplates = new WeakSet();
|
|
4
5
|
let webuiDataLoaded = false;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
loadWebUIDataBlock();
|
|
9
|
-
meta = window.__webui?.templates?.[name];
|
|
10
|
-
}
|
|
11
|
-
if (meta)
|
|
12
|
-
normalizeTemplate(name, meta);
|
|
13
|
-
return meta;
|
|
14
|
-
}
|
|
15
|
-
export function getTemplateRegistry() {
|
|
16
|
-
loadWebUIDataBlock();
|
|
17
|
-
return window.__webui?.templates;
|
|
18
|
-
}
|
|
19
|
-
export function registerTemplateData(templates, templateFns) {
|
|
6
|
+
const pendingTemplateDefinitions = new Map();
|
|
7
|
+
function acceptTemplateData(templates, templateFns) {
|
|
8
|
+
prepareTemplateData(templates, templateFns);
|
|
20
9
|
const w = window;
|
|
21
10
|
if (!w.__webui)
|
|
22
11
|
w.__webui = {};
|
|
@@ -32,16 +21,73 @@ export function registerTemplateData(templates, templateFns) {
|
|
|
32
21
|
}
|
|
33
22
|
}
|
|
34
23
|
const names = Object.keys(templates);
|
|
35
|
-
let hasTemplates = false;
|
|
36
24
|
for (let i = 0; i < names.length; i++) {
|
|
37
25
|
const tag = names[i];
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
w.__webui.templates[tag] = templates[tag];
|
|
27
|
+
}
|
|
28
|
+
for (let i = 0; i < names.length; i++) {
|
|
29
|
+
const pending = pendingTemplateDefinitions.get(names[i]);
|
|
30
|
+
if (!pending)
|
|
31
|
+
continue;
|
|
32
|
+
pendingTemplateDefinitions.delete(names[i]);
|
|
33
|
+
pending.define();
|
|
34
|
+
}
|
|
35
|
+
return names.length > 0;
|
|
36
|
+
}
|
|
37
|
+
if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
|
|
38
|
+
window.addEventListener(TEMPLATES_REGISTERED_EVENT, (event) => {
|
|
39
|
+
const templates = templateRegistrationDetail(event)?.templates;
|
|
40
|
+
if (templates)
|
|
41
|
+
acceptTemplateData(templates);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export function getTemplate(name) {
|
|
45
|
+
let meta = window.__webui?.templates?.[name];
|
|
46
|
+
if (!meta) {
|
|
47
|
+
loadWebUIDataBlock();
|
|
48
|
+
meta = window.__webui?.templates?.[name];
|
|
42
49
|
}
|
|
43
|
-
if (
|
|
50
|
+
if (meta)
|
|
51
|
+
normalizeTemplate(name, meta);
|
|
52
|
+
return meta;
|
|
53
|
+
}
|
|
54
|
+
export function getTemplateRegistry() {
|
|
55
|
+
loadWebUIDataBlock();
|
|
56
|
+
return window.__webui?.templates;
|
|
57
|
+
}
|
|
58
|
+
export function registerTemplateData(templates, templateFns) {
|
|
59
|
+
if (acceptTemplateData(templates, templateFns)) {
|
|
44
60
|
dispatchTemplatesRegistered(templates);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function prepareTemplateData(templates, templateFns) {
|
|
64
|
+
const names = Object.keys(templates);
|
|
65
|
+
for (let i = 0; i < names.length; i++) {
|
|
66
|
+
const name = names[i];
|
|
67
|
+
normalizeTemplate(name, templates[name], templateFns?.[name]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function prepareAssetTemplateData(templates, templateFns) {
|
|
71
|
+
const names = Object.keys(templates);
|
|
72
|
+
for (let i = 0; i < names.length; i++) {
|
|
73
|
+
const name = names[i];
|
|
74
|
+
const meta = templates[name];
|
|
75
|
+
if (assetNormalizedTemplates.has(meta))
|
|
76
|
+
continue;
|
|
77
|
+
normalizeTemplateConditions(name, meta, templateFns?.[name] ?? []);
|
|
78
|
+
normalizedTemplates.add(meta);
|
|
79
|
+
assetNormalizedTemplates.add(meta);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function deferTemplateDefinition(tagName, ctor, define) {
|
|
83
|
+
const pending = pendingTemplateDefinitions.get(tagName);
|
|
84
|
+
if (pending) {
|
|
85
|
+
if (pending.ctor === ctor) {
|
|
86
|
+
throw new Error(`[WebUI] <${tagName}> is already pending definition.`);
|
|
87
|
+
}
|
|
88
|
+
throw new Error(`[WebUI] <${tagName}> already has a pending authored definition.`);
|
|
89
|
+
}
|
|
90
|
+
pendingTemplateDefinitions.set(tagName, { ctor, define });
|
|
45
91
|
}
|
|
46
92
|
function loadWebUIDataBlock() {
|
|
47
93
|
if (webuiDataLoaded || window.__webui?.state !== undefined || typeof document === 'undefined')
|
|
@@ -62,10 +108,14 @@ function loadWebUIDataBlock() {
|
|
|
62
108
|
el.remove();
|
|
63
109
|
webuiDataLoaded = true;
|
|
64
110
|
}
|
|
65
|
-
function normalizeTemplate(name, meta) {
|
|
111
|
+
function normalizeTemplate(name, meta, suppliedFns) {
|
|
66
112
|
if (normalizedTemplates.has(meta))
|
|
67
113
|
return;
|
|
68
|
-
const fns = window.__webui?.templateFns?.[name] ?? [];
|
|
114
|
+
const fns = suppliedFns ?? window.__webui?.templateFns?.[name] ?? [];
|
|
115
|
+
normalizeTemplateConditions(name, meta, fns);
|
|
116
|
+
normalizedTemplates.add(meta);
|
|
117
|
+
}
|
|
118
|
+
function normalizeTemplateConditions(name, meta, fns) {
|
|
69
119
|
const stack = [meta];
|
|
70
120
|
while (stack.length > 0) {
|
|
71
121
|
const block = stack.pop();
|
|
@@ -89,7 +139,6 @@ function normalizeTemplate(name, meta) {
|
|
|
89
139
|
stack.push(children[i]);
|
|
90
140
|
}
|
|
91
141
|
}
|
|
92
|
-
normalizedTemplates.add(meta);
|
|
93
142
|
}
|
|
94
143
|
function normalizeCondition(tagName, condition, fns) {
|
|
95
144
|
const first = condition[0];
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/webui-framework",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "WebUI Framework Next — Preact-inspired lightweight Web Component runtime with SSR hydration
|
|
5
|
+
"description": "WebUI Framework Next — Preact-inspired lightweight Web Component runtime with SSR hydration and compiled-template path mapping.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
"types": "./dist/component-asset.d.ts",
|
|
17
17
|
"default": "./dist/component-asset.js"
|
|
18
18
|
}
|
|
19
|
+
},
|
|
20
|
+
"./streaming.js": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/streaming-entry.d.ts",
|
|
23
|
+
"default": "./dist/streaming-entry.js"
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
26
|
},
|
|
21
27
|
"files": [
|
|
@@ -25,7 +31,7 @@
|
|
|
25
31
|
"@playwright/test": "^1.61.1",
|
|
26
32
|
"@types/node": "^26.1.0",
|
|
27
33
|
"typescript": "^6.0.3",
|
|
28
|
-
"@microsoft/webui-test-support": "0.0.
|
|
34
|
+
"@microsoft/webui-test-support": "0.0.21"
|
|
29
35
|
},
|
|
30
36
|
"scripts": {
|
|
31
37
|
"build": "tsc",
|