@brad-frost-web/eddie-render 0.65.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 +127 -0
- package/cdn/eddie-render.js +947 -0
- package/cdn/eddie-render.js.map +1 -0
- package/dist/composer/index.d.ts +75 -0
- package/dist/composer/index.d.ts.map +1 -0
- package/dist/composer/index.js +292 -0
- package/dist/composer/index.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/render.d.ts +92 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +457 -0
- package/dist/render.js.map +1 -0
- package/dist/serialize.d.ts +29 -0
- package/dist/serialize.d.ts.map +1 -0
- package/dist/serialize.js +128 -0
- package/dist/serialize.js.map +1 -0
- package/dist/spec.d.ts +59 -0
- package/dist/spec.d.ts.map +1 -0
- package/dist/spec.js +364 -0
- package/dist/spec.js.map +1 -0
- package/dist/types.d.ts +180 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +15 -0
- package/dist/types.js.map +1 -0
- package/dist/validate/anti-pattern-selector.d.ts +75 -0
- package/dist/validate/anti-pattern-selector.d.ts.map +1 -0
- package/dist/validate/anti-pattern-selector.js +254 -0
- package/dist/validate/anti-pattern-selector.js.map +1 -0
- package/dist/validate/index.d.ts +36 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +334 -0
- package/dist/validate/index.js.map +1 -0
- package/package.json +50 -0
package/dist/render.js
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The surface host (#1898): applies `a2ui-eddie/1.0` messages and SpecStream
|
|
3
|
+
* patches to a canonical spec, validates, and renders Eddie DOM by node id.
|
|
4
|
+
*
|
|
5
|
+
* Rendering is reconciliation, not innerHTML: every spec element owns one DOM
|
|
6
|
+
* element, keyed by its resolved props; a changed node re-renders in place and
|
|
7
|
+
* untouched nodes keep their element, scroll position, and open state. That is
|
|
8
|
+
* realtime-ui PR #9 (section patching by id) generalised from HTML strings to
|
|
9
|
+
* catalog nodes, which is the whole reason the wire carries ids.
|
|
10
|
+
*
|
|
11
|
+
* Refusal is a first-class outcome. A turn that fails strict validation never
|
|
12
|
+
* reaches the committed spec: the previous surface stays on screen, a refusal
|
|
13
|
+
* renders in the host's refusal region, and a `refusal` event carries the
|
|
14
|
+
* issues (A2UI error codes included) so a composer can self-correct.
|
|
15
|
+
*/
|
|
16
|
+
import { serializeSpec, expand, resolveValue, scalarProps } from './serialize.js';
|
|
17
|
+
import { applyMessage, applyPatchOp, cloneSpec, emptySpec, parsePatchLine, reachableIds } from './spec.js';
|
|
18
|
+
import { RESERVED_KEYS, TEXT_NODE, } from './types.js';
|
|
19
|
+
import { validateSpec } from './validate/index.js';
|
|
20
|
+
const PENDING_ATTR = 'data-eddie-pending';
|
|
21
|
+
const ID_ATTR = 'data-eddie-id';
|
|
22
|
+
export class SurfaceHost extends EventTarget {
|
|
23
|
+
element;
|
|
24
|
+
surfaceId;
|
|
25
|
+
ready;
|
|
26
|
+
catalog = null;
|
|
27
|
+
committed = emptySpec();
|
|
28
|
+
mounted = new Map();
|
|
29
|
+
surfaceRoot = null;
|
|
30
|
+
refusalRegion;
|
|
31
|
+
opts;
|
|
32
|
+
loadedScripts = new Set();
|
|
33
|
+
constructor(element, opts) {
|
|
34
|
+
super();
|
|
35
|
+
this.element = element;
|
|
36
|
+
this.opts = opts;
|
|
37
|
+
this.surfaceId = opts.surfaceId ?? 'main';
|
|
38
|
+
this.refusalRegion = opts.refusalRegion ?? this.createRefusalRegion();
|
|
39
|
+
this.ready = this.loadCatalog(opts.catalog);
|
|
40
|
+
element.addEventListener('click', (ev) => this.onActivate(ev));
|
|
41
|
+
}
|
|
42
|
+
/** The committed (rendered, canonical) spec. A copy; mutate through a turn. */
|
|
43
|
+
get spec() {
|
|
44
|
+
return cloneSpec(this.committed);
|
|
45
|
+
}
|
|
46
|
+
get catalogDocument() {
|
|
47
|
+
return this.catalog;
|
|
48
|
+
}
|
|
49
|
+
/** Validate a spec against this host's catalog without touching the surface. */
|
|
50
|
+
validate(spec) {
|
|
51
|
+
return validateSpec(spec, this.requireCatalog());
|
|
52
|
+
}
|
|
53
|
+
/** Apply messages as one turn: validate strictly, then commit or refuse. */
|
|
54
|
+
apply(messages) {
|
|
55
|
+
const turn = this.beginTurn();
|
|
56
|
+
turn.message(messages);
|
|
57
|
+
return turn.end();
|
|
58
|
+
}
|
|
59
|
+
/** Apply SpecStream lines as one turn. */
|
|
60
|
+
applyPatchLines(lines) {
|
|
61
|
+
const turn = this.beginTurn();
|
|
62
|
+
turn.push(lines);
|
|
63
|
+
return turn.end();
|
|
64
|
+
}
|
|
65
|
+
/** Clear the surface (a `deleteSurface`). */
|
|
66
|
+
reset() {
|
|
67
|
+
this.committed = emptySpec();
|
|
68
|
+
this.render(this.committed, { provisional: false });
|
|
69
|
+
this.clearRefusals();
|
|
70
|
+
}
|
|
71
|
+
beginTurn() {
|
|
72
|
+
const catalog = this.requireCatalog();
|
|
73
|
+
const working = cloneSpec(this.committed);
|
|
74
|
+
let open = true;
|
|
75
|
+
// Ids re-created during ANY paint of this turn, provisional or final — the final
|
|
76
|
+
// paint alone would report nothing, since the provisional pass already did the work.
|
|
77
|
+
const turnTouched = new Set();
|
|
78
|
+
let cleared = false;
|
|
79
|
+
const provisional = () => {
|
|
80
|
+
const check = validateSpec(working, catalog, { streaming: true });
|
|
81
|
+
// Provisional paint only when nothing is structurally wrong yet; a
|
|
82
|
+
// half-arrived stream is fine, an unknown node is not worth painting.
|
|
83
|
+
if (!check.issues.some((i) => i.severity === 'error' && i.code !== 'DANGLING_CHILD' && i.code !== 'MISSING_ROOT')) {
|
|
84
|
+
for (const id of this.render(working, { provisional: true }))
|
|
85
|
+
turnTouched.add(id);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
working,
|
|
90
|
+
push: (lines) => {
|
|
91
|
+
if (!open)
|
|
92
|
+
throw new Error('Turn already ended');
|
|
93
|
+
const list = Array.isArray(lines) ? lines : lines.split('\n');
|
|
94
|
+
const applied = [];
|
|
95
|
+
for (const line of list) {
|
|
96
|
+
const op = parsePatchLine(line);
|
|
97
|
+
if (!op)
|
|
98
|
+
continue;
|
|
99
|
+
try {
|
|
100
|
+
applyPatchOp(working, op);
|
|
101
|
+
applied.push(op);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// A bad op is reported by the strict validation at end(); ignore here.
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (applied.length)
|
|
108
|
+
provisional();
|
|
109
|
+
return applied;
|
|
110
|
+
},
|
|
111
|
+
pushOp: (op) => {
|
|
112
|
+
if (!open)
|
|
113
|
+
throw new Error('Turn already ended');
|
|
114
|
+
applyPatchOp(working, op);
|
|
115
|
+
provisional();
|
|
116
|
+
},
|
|
117
|
+
message: (messages) => {
|
|
118
|
+
if (!open)
|
|
119
|
+
throw new Error('Turn already ended');
|
|
120
|
+
for (const m of Array.isArray(messages) ? messages : [messages]) {
|
|
121
|
+
if (applyMessage(working, m).kind === 'deleteSurface')
|
|
122
|
+
cleared = true;
|
|
123
|
+
else
|
|
124
|
+
cleared = false;
|
|
125
|
+
}
|
|
126
|
+
if (!cleared)
|
|
127
|
+
provisional();
|
|
128
|
+
},
|
|
129
|
+
end: () => {
|
|
130
|
+
if (!open)
|
|
131
|
+
throw new Error('Turn already ended');
|
|
132
|
+
open = false;
|
|
133
|
+
if (cleared) {
|
|
134
|
+
// A deleteSurface is not a spec to validate; an empty surface is the committed state.
|
|
135
|
+
this.reset();
|
|
136
|
+
this.dispatchEvent(new CustomEvent('render', { detail: { spec: cloneSpec(this.committed), issues: [], touched: [] } }));
|
|
137
|
+
return { ok: true, issues: [], outcome: 'committed', touched: [] };
|
|
138
|
+
}
|
|
139
|
+
const result = validateSpec(working, catalog);
|
|
140
|
+
if (result.ok) {
|
|
141
|
+
this.committed = working;
|
|
142
|
+
for (const id of this.render(working, { provisional: false }))
|
|
143
|
+
turnTouched.add(id);
|
|
144
|
+
const touched = [...turnTouched];
|
|
145
|
+
this.clearRefusals();
|
|
146
|
+
this.dispatchEvent(new CustomEvent('render', { detail: { spec: cloneSpec(working), issues: result.issues, touched } }));
|
|
147
|
+
return { ...result, outcome: 'committed', touched };
|
|
148
|
+
}
|
|
149
|
+
this.render(this.committed, { provisional: false });
|
|
150
|
+
this.showRefusals(result.issues);
|
|
151
|
+
this.dispatchEvent(new CustomEvent('refusal', { detail: { issues: result.issues, surfaceId: this.surfaceId } }));
|
|
152
|
+
return { ...result, outcome: 'refused', touched: [] };
|
|
153
|
+
},
|
|
154
|
+
abort: () => {
|
|
155
|
+
open = false;
|
|
156
|
+
this.render(this.committed, { provisional: false });
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
// -------------------------------------------------------------------------
|
|
161
|
+
// Rendering
|
|
162
|
+
// -------------------------------------------------------------------------
|
|
163
|
+
/** Render a spec into the this. Returns the ids whose elements were created or replaced. */
|
|
164
|
+
render(spec, { provisional }) {
|
|
165
|
+
const catalog = this.requireCatalog();
|
|
166
|
+
const doc = this.element.ownerDocument;
|
|
167
|
+
const touched = [];
|
|
168
|
+
const live = new Set();
|
|
169
|
+
if (this.opts.scripts !== false)
|
|
170
|
+
this.ensureScripts(spec, catalog);
|
|
171
|
+
const dataModel = spec.dataModel;
|
|
172
|
+
const resolve = (value) => {
|
|
173
|
+
const v = resolveValue(value, dataModel);
|
|
174
|
+
if (v && typeof v === 'object' && !Array.isArray(v) && v.bind === 'client') {
|
|
175
|
+
const path = typeof value === 'object' && value && 'path' in value ? String(value.path) : '';
|
|
176
|
+
return this.opts.bind ? this.opts.bind(path) : undefined;
|
|
177
|
+
}
|
|
178
|
+
return v;
|
|
179
|
+
};
|
|
180
|
+
const mount = (id, slotAttr) => {
|
|
181
|
+
live.add(id);
|
|
182
|
+
const el = spec.elements[id];
|
|
183
|
+
const existing = this.mounted.get(id);
|
|
184
|
+
if (!el) {
|
|
185
|
+
if (existing?.kind === 'pending')
|
|
186
|
+
return existing.el;
|
|
187
|
+
const placeholder = doc.createElement('span');
|
|
188
|
+
placeholder.setAttribute(PENDING_ATTR, id);
|
|
189
|
+
placeholder.hidden = true;
|
|
190
|
+
this.mounted.set(id, { el: placeholder, key: 'pending', childHost: null, anchor: null, kind: 'pending' });
|
|
191
|
+
return placeholder;
|
|
192
|
+
}
|
|
193
|
+
const def = catalog.components[el.component];
|
|
194
|
+
const key = this.keyFor(el, resolve, slotAttr);
|
|
195
|
+
let m = existing;
|
|
196
|
+
if (!m || m.key !== key || m.kind === 'pending') {
|
|
197
|
+
m = this.create(doc, id, el, def, resolve, key);
|
|
198
|
+
if (existing && existing.el.parentNode)
|
|
199
|
+
existing.el.replaceWith(m.el);
|
|
200
|
+
this.mounted.set(id, m);
|
|
201
|
+
touched.push(id);
|
|
202
|
+
}
|
|
203
|
+
if (m.el instanceof Element) {
|
|
204
|
+
if (slotAttr)
|
|
205
|
+
m.el.setAttribute('slot', slotAttr);
|
|
206
|
+
else
|
|
207
|
+
m.el.removeAttribute('slot');
|
|
208
|
+
}
|
|
209
|
+
// Children: default slot then named slots, in spec order.
|
|
210
|
+
if (m.childHost) {
|
|
211
|
+
const desired = [];
|
|
212
|
+
for (const child of el.children ?? [])
|
|
213
|
+
desired.push(mount(String(child)));
|
|
214
|
+
for (const [slotKey, list] of Object.entries(el.slots ?? {})) {
|
|
215
|
+
const attr = def?.metadata.extensions.eddie_slotAttrs?.[slotKey] ?? slotKey;
|
|
216
|
+
for (const child of list)
|
|
217
|
+
desired.push(mount(String(child), attr));
|
|
218
|
+
}
|
|
219
|
+
this.syncChildren(m.childHost, m.anchor, desired);
|
|
220
|
+
}
|
|
221
|
+
return m.el;
|
|
222
|
+
};
|
|
223
|
+
if (spec.root && spec.elements[spec.root]) {
|
|
224
|
+
const rootNode = mount(spec.root);
|
|
225
|
+
if (this.surfaceRoot !== rootNode) {
|
|
226
|
+
if (this.surfaceRoot?.parentNode)
|
|
227
|
+
this.surfaceRoot.replaceWith(rootNode);
|
|
228
|
+
else
|
|
229
|
+
this.element.appendChild(rootNode);
|
|
230
|
+
this.surfaceRoot = rootNode;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else if (this.surfaceRoot) {
|
|
234
|
+
this.surfaceRoot.remove();
|
|
235
|
+
this.surfaceRoot = null;
|
|
236
|
+
}
|
|
237
|
+
for (const id of [...this.mounted.keys()]) {
|
|
238
|
+
if (!live.has(id)) {
|
|
239
|
+
const m = this.mounted.get(id);
|
|
240
|
+
m.el.remove();
|
|
241
|
+
this.mounted.delete(id);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (provisional)
|
|
245
|
+
this.element.setAttribute('data-eddie-provisional', '');
|
|
246
|
+
else
|
|
247
|
+
this.element.removeAttribute('data-eddie-provisional');
|
|
248
|
+
return touched;
|
|
249
|
+
}
|
|
250
|
+
keyFor(el, resolve, slotAttr) {
|
|
251
|
+
const props = {};
|
|
252
|
+
for (const [k, v] of Object.entries(el)) {
|
|
253
|
+
if (k === 'children' || k === 'slots')
|
|
254
|
+
continue;
|
|
255
|
+
props[k] = RESERVED_KEYS.has(k) ? v : resolve(v);
|
|
256
|
+
}
|
|
257
|
+
return JSON.stringify([props, slotAttr ?? '']);
|
|
258
|
+
}
|
|
259
|
+
create(doc, id, el, def, resolve, key) {
|
|
260
|
+
if (!def) {
|
|
261
|
+
const unknown = doc.createElement('span');
|
|
262
|
+
unknown.setAttribute(ID_ATTR, id);
|
|
263
|
+
unknown.setAttribute('data-eddie-unknown', el.component);
|
|
264
|
+
unknown.hidden = true;
|
|
265
|
+
return { el: unknown, key, childHost: null, anchor: null, kind: 'unknown' };
|
|
266
|
+
}
|
|
267
|
+
const ext = def.metadata.extensions;
|
|
268
|
+
if (ext.eddie_kind === 'text' || el.component === TEXT_NODE) {
|
|
269
|
+
const text = String(resolve(el.text) ?? '');
|
|
270
|
+
const tag = typeof el.tagName === 'string' ? el.tagName : '';
|
|
271
|
+
if (!tag)
|
|
272
|
+
return { el: doc.createTextNode(text), key, childHost: null, anchor: null, kind: 'text' };
|
|
273
|
+
const node = doc.createElement(tag);
|
|
274
|
+
node.textContent = text;
|
|
275
|
+
node.setAttribute(ID_ATTR, id);
|
|
276
|
+
return { el: node, key, childHost: null, anchor: null, kind: 'text' };
|
|
277
|
+
}
|
|
278
|
+
if (ext.eddie_kind === 'composition') {
|
|
279
|
+
const { before, after } = expand(def, el, this.resolvedProps(el, resolve));
|
|
280
|
+
const tpl = doc.createElement('template');
|
|
281
|
+
tpl.innerHTML = `${before}<!--eddie:children-->${after}`;
|
|
282
|
+
const frag = tpl.content;
|
|
283
|
+
let root;
|
|
284
|
+
if (frag.children.length === 1)
|
|
285
|
+
root = frag.firstElementChild;
|
|
286
|
+
else {
|
|
287
|
+
root = doc.createElement('div');
|
|
288
|
+
root.append(frag);
|
|
289
|
+
}
|
|
290
|
+
const walker = doc.createTreeWalker(root, 128 /* NodeFilter.SHOW_COMMENT */);
|
|
291
|
+
let anchor = null;
|
|
292
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
|
|
293
|
+
if (n.nodeValue === 'eddie:children') {
|
|
294
|
+
anchor = n;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
root.setAttribute(ID_ATTR, id);
|
|
299
|
+
this.applyCommon(root, el);
|
|
300
|
+
return { el: root, key, childHost: anchor?.parentElement ?? root, anchor, kind: 'composition' };
|
|
301
|
+
}
|
|
302
|
+
const node = doc.createElement(ext.eddie_tag);
|
|
303
|
+
node.setAttribute(ID_ATTR, id);
|
|
304
|
+
for (const [k, v] of scalarProps(el, {})) {
|
|
305
|
+
const value = resolve(v);
|
|
306
|
+
if (value === true)
|
|
307
|
+
node.setAttribute(k, '');
|
|
308
|
+
else if (value === false || value === undefined || value === null)
|
|
309
|
+
node.removeAttribute(k);
|
|
310
|
+
else
|
|
311
|
+
node.setAttribute(k, String(value));
|
|
312
|
+
}
|
|
313
|
+
for (const [k, raw] of Object.entries(el)) {
|
|
314
|
+
if (RESERVED_KEYS.has(k))
|
|
315
|
+
continue;
|
|
316
|
+
const value = resolve(raw);
|
|
317
|
+
if (value && typeof value === 'object')
|
|
318
|
+
node[k] = value; // structured data (chart series, option lists): Lit keeps pre-upgrade values
|
|
319
|
+
}
|
|
320
|
+
this.applyCommon(node, el);
|
|
321
|
+
return { el: node, key, childHost: node, anchor: null, kind: 'primitive' };
|
|
322
|
+
}
|
|
323
|
+
resolvedProps(el, resolve) {
|
|
324
|
+
const out = {};
|
|
325
|
+
for (const [k, v] of Object.entries(el))
|
|
326
|
+
if (!RESERVED_KEYS.has(k))
|
|
327
|
+
out[k] = resolve(v);
|
|
328
|
+
return out;
|
|
329
|
+
}
|
|
330
|
+
applyCommon(node, el) {
|
|
331
|
+
const a = el.accessibility;
|
|
332
|
+
if (a?.label)
|
|
333
|
+
node.setAttribute('aria-label', a.label);
|
|
334
|
+
if (a?.description)
|
|
335
|
+
node.setAttribute('aria-description', a.description);
|
|
336
|
+
if (a?.live)
|
|
337
|
+
node.setAttribute('aria-live', a.live);
|
|
338
|
+
if (a?.hidden)
|
|
339
|
+
node.setAttribute('hidden', '');
|
|
340
|
+
if (el.action)
|
|
341
|
+
node.setAttribute('data-eddie-action', el.action.name);
|
|
342
|
+
}
|
|
343
|
+
/** Put `desired` under `host` (before `anchor` when there is one) in order, removing nothing that is not ours. */
|
|
344
|
+
syncChildren(host, anchor, desired) {
|
|
345
|
+
const ours = new Set(desired);
|
|
346
|
+
const managed = new Set();
|
|
347
|
+
for (const m of this.mounted.values())
|
|
348
|
+
managed.add(m.el);
|
|
349
|
+
for (const child of [...host.childNodes]) {
|
|
350
|
+
if (managed.has(child) && !ours.has(child))
|
|
351
|
+
child.remove();
|
|
352
|
+
}
|
|
353
|
+
let cursor = anchor ?? null;
|
|
354
|
+
// Insert in reverse before the anchor (or at the end), so order is preserved without index math.
|
|
355
|
+
for (let i = desired.length - 1; i >= 0; i--) {
|
|
356
|
+
const node = desired[i];
|
|
357
|
+
if (cursor) {
|
|
358
|
+
if (node.nextSibling !== cursor || node.parentNode !== host)
|
|
359
|
+
host.insertBefore(node, cursor);
|
|
360
|
+
}
|
|
361
|
+
else if (node.parentNode !== host || node.nextSibling !== null) {
|
|
362
|
+
host.appendChild(node);
|
|
363
|
+
}
|
|
364
|
+
cursor = node;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
// -------------------------------------------------------------------------
|
|
368
|
+
// Refusals, actions, scripts, catalog
|
|
369
|
+
// -------------------------------------------------------------------------
|
|
370
|
+
createRefusalRegion() {
|
|
371
|
+
const doc = this.element.ownerDocument;
|
|
372
|
+
const region = doc.createElement('div');
|
|
373
|
+
region.setAttribute('data-eddie-refusals', '');
|
|
374
|
+
region.setAttribute('aria-live', 'polite');
|
|
375
|
+
this.element.parentNode?.insertBefore(region, this.element);
|
|
376
|
+
return region;
|
|
377
|
+
}
|
|
378
|
+
showRefusals(issues) {
|
|
379
|
+
const doc = this.element.ownerDocument;
|
|
380
|
+
const errors = issues.filter((i) => i.severity === 'error');
|
|
381
|
+
const alert = doc.createElement('ed-alert');
|
|
382
|
+
alert.setAttribute('variant', 'error');
|
|
383
|
+
alert.setAttribute('heading', `Refused ${errors.length} change${errors.length === 1 ? '' : 's'}`);
|
|
384
|
+
for (const issue of errors.slice(0, 6)) {
|
|
385
|
+
const p = doc.createElement('p');
|
|
386
|
+
p.textContent = `${issue.code}${issue.id ? ` (${issue.id})` : ''}: ${issue.message}${issue.fix ? ` ${issue.fix}` : ''}`;
|
|
387
|
+
alert.appendChild(p);
|
|
388
|
+
}
|
|
389
|
+
this.refusalRegion.appendChild(alert);
|
|
390
|
+
const max = this.opts.maxRefusals ?? 3;
|
|
391
|
+
while (this.refusalRegion.children.length > max)
|
|
392
|
+
this.refusalRegion.firstElementChild?.remove();
|
|
393
|
+
}
|
|
394
|
+
clearRefusals() {
|
|
395
|
+
this.refusalRegion.replaceChildren();
|
|
396
|
+
}
|
|
397
|
+
onActivate(ev) {
|
|
398
|
+
const target = ev.target;
|
|
399
|
+
const actor = target?.closest?.(`[data-eddie-action]`);
|
|
400
|
+
if (!actor || !this.element.contains(actor))
|
|
401
|
+
return;
|
|
402
|
+
const id = actor.getAttribute(ID_ATTR);
|
|
403
|
+
const el = id ? this.committed.elements[id] : undefined;
|
|
404
|
+
if (!id || !el?.action)
|
|
405
|
+
return;
|
|
406
|
+
const detail = {
|
|
407
|
+
name: el.action.name,
|
|
408
|
+
surfaceId: this.surfaceId,
|
|
409
|
+
sourceComponentId: id,
|
|
410
|
+
timestamp: new Date().toISOString(),
|
|
411
|
+
...(el.action.context ? { context: el.action.context } : {}),
|
|
412
|
+
};
|
|
413
|
+
this.dispatchEvent(new CustomEvent('action', { detail }));
|
|
414
|
+
}
|
|
415
|
+
ensureScripts(spec, catalog) {
|
|
416
|
+
const doc = this.element.ownerDocument;
|
|
417
|
+
for (const id of reachableIds(spec)) {
|
|
418
|
+
const def = catalog.components[spec.elements[id]?.component ?? ''];
|
|
419
|
+
const tag = def?.metadata.extensions.eddie_scriptTag;
|
|
420
|
+
if (!tag)
|
|
421
|
+
continue;
|
|
422
|
+
for (const m of tag.matchAll(/src="([^"]+)"/g)) {
|
|
423
|
+
const src = m[1];
|
|
424
|
+
if (this.loadedScripts.has(src) || doc.querySelector(`script[src="${src}"]`))
|
|
425
|
+
continue;
|
|
426
|
+
const s = doc.createElement('script');
|
|
427
|
+
s.type = 'module';
|
|
428
|
+
s.src = src;
|
|
429
|
+
doc.head.appendChild(s);
|
|
430
|
+
this.loadedScripts.add(src);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
async loadCatalog(source) {
|
|
435
|
+
if (typeof source !== 'string') {
|
|
436
|
+
this.catalog = source;
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
const res = await fetch(source);
|
|
440
|
+
if (!res.ok)
|
|
441
|
+
throw new Error(`Catalog fetch failed: HTTP ${res.status} for ${source}`);
|
|
442
|
+
this.catalog = (await res.json());
|
|
443
|
+
}
|
|
444
|
+
requireCatalog() {
|
|
445
|
+
if (!this.catalog)
|
|
446
|
+
throw new Error('Catalog not loaded yet — await this.ready first.');
|
|
447
|
+
return this.catalog;
|
|
448
|
+
}
|
|
449
|
+
/** The committed surface as markup (what the validator's anti-pattern pass sees). */
|
|
450
|
+
toMarkup() {
|
|
451
|
+
return serializeSpec(this.committed, this.requireCatalog()).markup;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
export function createSurfaceHost(element, opts) {
|
|
455
|
+
return new SurfaceHost(element, opts);
|
|
456
|
+
}
|
|
457
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC3G,OAAO,EACL,aAAa,EACb,SAAS,GAUV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AA+CnD,MAAM,YAAY,GAAG,oBAAoB,CAAC;AAC1C,MAAM,OAAO,GAAG,eAAe,CAAC;AAEhC,MAAM,OAAO,WAAY,SAAQ,WAAW;IACjC,OAAO,CAAU;IACjB,SAAS,CAAS;IAClB,KAAK,CAAgB;IACtB,OAAO,GAAmB,IAAI,CAAC;IAC/B,SAAS,GAAS,SAAS,EAAE,CAAC;IAC9B,OAAO,GAAG,IAAI,GAAG,EAAmB,CAAC;IACrC,WAAW,GAAgB,IA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G,CAAC,MAAM,QAAQ,MAAM,EAAE,CAAC,CAAC;QACvF,IAAI,CAAC,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAY,CAAC;IAC/C,CAAC;IAEO,cAAc;QACpB,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QAEvF,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,qFAAqF;IACrF,QAAQ;QACN,OAAO,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC;IACrE,CAAC;CACF;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAgB,EAAE,IAAwB;IAC1E,OAAO,IAAI,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialise a spec to Eddie markup without a DOM — the expanded tree as a
|
|
3
|
+
* string. The validator runs the anti-pattern selector core over it, so a
|
|
4
|
+
* rule means the same thing on a file (`eddie_validate_file`) and on a
|
|
5
|
+
* surface (`validateSpec`). The renderer's DOM output follows the same
|
|
6
|
+
* expansion rules in `render.ts`; the two share `expand()` below.
|
|
7
|
+
*/
|
|
8
|
+
import { type Catalog, type CatalogComponent, type Spec, type SpecElement } from './types.js';
|
|
9
|
+
export declare function escapeAttr(value: unknown): string;
|
|
10
|
+
export declare function escapeText(value: unknown): string;
|
|
11
|
+
/** Resolve an A2UI bound value (`{ path }`) against the data model; literals pass through. */
|
|
12
|
+
export declare function resolveValue(value: unknown, dataModel: Record<string, unknown>): unknown;
|
|
13
|
+
/** Scalar props of an element (reserved keys and structured values excluded), resolved. */
|
|
14
|
+
export declare function scalarProps(el: SpecElement, dataModel: Record<string, unknown>): Array<[string, string | number | boolean]>;
|
|
15
|
+
/**
|
|
16
|
+
* Split a composition node's expansion skeleton at its `{{children}}` marker
|
|
17
|
+
* and substitute `{{prop}}` placeholders. Returns the markup before and after
|
|
18
|
+
* the children marker. Unknown placeholders render empty.
|
|
19
|
+
*/
|
|
20
|
+
export declare function expand(def: CatalogComponent, el: SpecElement, dataModel: Record<string, unknown>): {
|
|
21
|
+
before: string;
|
|
22
|
+
after: string;
|
|
23
|
+
};
|
|
24
|
+
/** Serialise, returning the markup and a way to map a markup offset back to an element id. */
|
|
25
|
+
export declare function serializeSpec(spec: Spec, catalog: Catalog): {
|
|
26
|
+
markup: string;
|
|
27
|
+
idOf: (offset: number) => string | undefined;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=serialize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAA4B,KAAK,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAExH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEjD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEjD;AAED,8FAA8F;AAC9F,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAaxF;AAED,2FAA2F;AAC3F,wBAAgB,WAAW,CAAC,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,CAU3H;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,gBAAgB,EAAE,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAYpI;AAED,8FAA8F;AAC9F,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAA;CAAE,CAiE5H"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialise a spec to Eddie markup without a DOM — the expanded tree as a
|
|
3
|
+
* string. The validator runs the anti-pattern selector core over it, so a
|
|
4
|
+
* rule means the same thing on a file (`eddie_validate_file`) and on a
|
|
5
|
+
* surface (`validateSpec`). The renderer's DOM output follows the same
|
|
6
|
+
* expansion rules in `render.ts`; the two share `expand()` below.
|
|
7
|
+
*/
|
|
8
|
+
import { RESERVED_KEYS, TEXT_NODE } from './types.js';
|
|
9
|
+
export function escapeAttr(value) {
|
|
10
|
+
return String(value).replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<');
|
|
11
|
+
}
|
|
12
|
+
export function escapeText(value) {
|
|
13
|
+
return String(value).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
14
|
+
}
|
|
15
|
+
/** Resolve an A2UI bound value (`{ path }`) against the data model; literals pass through. */
|
|
16
|
+
export function resolveValue(value, dataModel) {
|
|
17
|
+
if (value && typeof value === 'object' && !Array.isArray(value) && 'path' in value) {
|
|
18
|
+
const pointer = String(value.path);
|
|
19
|
+
let cur = dataModel;
|
|
20
|
+
for (const key of pointer.replace(/^\//, '').split('/').filter(Boolean)) {
|
|
21
|
+
if (cur === null || typeof cur !== 'object')
|
|
22
|
+
return undefined;
|
|
23
|
+
cur = cur[key.replace(/~1/g, '/').replace(/~0/g, '~')];
|
|
24
|
+
}
|
|
25
|
+
return cur;
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
/** Scalar props of an element (reserved keys and structured values excluded), resolved. */
|
|
30
|
+
export function scalarProps(el, dataModel) {
|
|
31
|
+
const out = [];
|
|
32
|
+
for (const [key, raw] of Object.entries(el)) {
|
|
33
|
+
if (RESERVED_KEYS.has(key))
|
|
34
|
+
continue;
|
|
35
|
+
const value = resolveValue(raw, dataModel);
|
|
36
|
+
if (value === undefined || value === null)
|
|
37
|
+
continue;
|
|
38
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')
|
|
39
|
+
out.push([key, value]);
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Split a composition node's expansion skeleton at its `{{children}}` marker
|
|
45
|
+
* and substitute `{{prop}}` placeholders. Returns the markup before and after
|
|
46
|
+
* the children marker. Unknown placeholders render empty.
|
|
47
|
+
*/
|
|
48
|
+
export function expand(def, el, dataModel) {
|
|
49
|
+
const skeleton = def.metadata.extensions.eddie_expansion ?? `<${def.metadata.extensions.eddie_tag}>{{children}}</${def.metadata.extensions.eddie_tag}>`;
|
|
50
|
+
const substituted = skeleton.replace(/\{\{(?!children\}\})([a-zA-Z_][\w]*)\}\}/g, (_m, name) => {
|
|
51
|
+
const value = resolveValue(el[name], dataModel);
|
|
52
|
+
return value === undefined || value === null ? '' : escapeAttr(value);
|
|
53
|
+
});
|
|
54
|
+
const idx = substituted.indexOf('{{children}}');
|
|
55
|
+
if (idx === -1)
|
|
56
|
+
return { before: substituted, after: '' };
|
|
57
|
+
return { before: substituted.slice(0, idx), after: substituted.slice(idx + '{{children}}'.length) };
|
|
58
|
+
}
|
|
59
|
+
/** Serialise, returning the markup and a way to map a markup offset back to an element id. */
|
|
60
|
+
export function serializeSpec(spec, catalog) {
|
|
61
|
+
const marks = [];
|
|
62
|
+
let out = '';
|
|
63
|
+
// An id already on the current path is a cycle; the validator reports it, the serializer must not recurse into it.
|
|
64
|
+
const path = new Set();
|
|
65
|
+
const visit = (id, slot) => {
|
|
66
|
+
const el = spec.elements[id];
|
|
67
|
+
if (!el || path.has(id))
|
|
68
|
+
return;
|
|
69
|
+
path.add(id);
|
|
70
|
+
try {
|
|
71
|
+
visitNode(id, el, slot);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
path.delete(id);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const visitNode = (id, el, slot) => {
|
|
78
|
+
const def = catalog.components[el.component];
|
|
79
|
+
const slotAttr = slot ? ` slot="${escapeAttr(slot)}"` : '';
|
|
80
|
+
marks.push({ start: out.length, id });
|
|
81
|
+
if (!def) {
|
|
82
|
+
out += `<unknown data-eddie-id="${escapeAttr(id)}"${slotAttr}></unknown>`;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const ext = def.metadata.extensions;
|
|
86
|
+
if (ext.eddie_kind === 'text' || el.component === TEXT_NODE) {
|
|
87
|
+
const tag = typeof el.tagName === 'string' ? el.tagName : '';
|
|
88
|
+
const text = escapeText(resolveValue(el.text, spec.dataModel) ?? '');
|
|
89
|
+
out += tag ? `<${tag}${slotAttr}>${text}</${tag}>` : text;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const children = () => {
|
|
93
|
+
for (const child of el.children ?? [])
|
|
94
|
+
visit(String(child));
|
|
95
|
+
for (const [slotKey, list] of Object.entries(el.slots ?? {})) {
|
|
96
|
+
const attr = ext.eddie_slotAttrs?.[slotKey] ?? slotKey;
|
|
97
|
+
for (const child of list)
|
|
98
|
+
visit(String(child), attr);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
if (ext.eddie_kind === 'composition') {
|
|
102
|
+
const { before, after } = expand(def, el, spec.dataModel);
|
|
103
|
+
out += slot ? before.replace(/^(<[a-zA-Z][^>\s]*)/, `$1${slotAttr}`) : before;
|
|
104
|
+
children();
|
|
105
|
+
out += after;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const attrs = scalarProps(el, spec.dataModel)
|
|
109
|
+
.map(([k, v]) => (v === true ? ` ${k}` : v === false ? '' : ` ${k}="${escapeAttr(v)}"`))
|
|
110
|
+
.join('');
|
|
111
|
+
out += `<${ext.eddie_tag}${attrs}${slotAttr}>`;
|
|
112
|
+
children();
|
|
113
|
+
out += `</${ext.eddie_tag}>`;
|
|
114
|
+
};
|
|
115
|
+
if (spec.root)
|
|
116
|
+
visit(spec.root);
|
|
117
|
+
return {
|
|
118
|
+
markup: out,
|
|
119
|
+
idOf: (offset) => {
|
|
120
|
+
let best;
|
|
121
|
+
for (const m of marks)
|
|
122
|
+
if (m.start <= offset)
|
|
123
|
+
best = m.id;
|
|
124
|
+
return best;
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=serialize.js.map
|