@archie/devtools 0.0.22 → 0.0.23
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 +6 -0
- package/dist/client/client.js +10 -4
- package/dist/client/client.mjs +10 -4
- package/dist/index.d.mts +182 -1
- package/dist/index.d.ts +182 -1
- package/dist/index.js +322 -38
- package/dist/index.mjs +322 -38
- package/dist/inspector.standalone.js +44 -4
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -178,6 +178,36 @@ function babelPluginDndAuto({ types: t }, opts = {}) {
|
|
|
178
178
|
|
|
179
179
|
// src/babel-plugin-editor-meta.ts
|
|
180
180
|
import * as nodePath from "path";
|
|
181
|
+
var KIT_SLOT_ATTR = "data-kit-slot";
|
|
182
|
+
var MAX_SLOT_SEGMENTS = 4;
|
|
183
|
+
var NON_BINDING_ATTRS = /* @__PURE__ */ new Set(["__editorMeta", "key", "ref", KIT_SLOT_ATTR]);
|
|
184
|
+
var STRUCTURAL_ATTRS = /* @__PURE__ */ new Set([
|
|
185
|
+
"id",
|
|
186
|
+
"htmlFor",
|
|
187
|
+
"slot",
|
|
188
|
+
"name",
|
|
189
|
+
"type",
|
|
190
|
+
"role",
|
|
191
|
+
// The camelCase carrier of the SAME durable key as `data-agent-id`: kit
|
|
192
|
+
// components take `agentId` and render it as the data attribute. Found on the
|
|
193
|
+
// real corpus (×4) — blocking only the dashed form would have left the prop
|
|
194
|
+
// form routable, and a durable key with a string-literal usage value sails
|
|
195
|
+
// straight through the usage-value law.
|
|
196
|
+
"agentId"
|
|
197
|
+
]);
|
|
198
|
+
function isNonContentAttribute(name) {
|
|
199
|
+
if (/^on[A-Z]/.test(name)) return true;
|
|
200
|
+
if (name.startsWith("data-")) return true;
|
|
201
|
+
return STRUCTURAL_ATTRS.has(name);
|
|
202
|
+
}
|
|
203
|
+
function normalizeSlot(raw) {
|
|
204
|
+
const value = raw.trim();
|
|
205
|
+
if (!value) return null;
|
|
206
|
+
const segments = value.split("/");
|
|
207
|
+
if (segments.length > MAX_SLOT_SEGMENTS) return null;
|
|
208
|
+
if (segments.some((segment) => segment.trim() === "")) return null;
|
|
209
|
+
return value;
|
|
210
|
+
}
|
|
181
211
|
function isPackageImport(src) {
|
|
182
212
|
if (src.startsWith(".") || src.startsWith("/")) return false;
|
|
183
213
|
if (src.startsWith("@")) {
|
|
@@ -193,7 +223,8 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
193
223
|
const {
|
|
194
224
|
fileExclude = /node_modules/,
|
|
195
225
|
instrumentImported = true,
|
|
196
|
-
includeHostSourceRef = false
|
|
226
|
+
includeHostSourceRef = false,
|
|
227
|
+
origin = "screen"
|
|
197
228
|
} = opts;
|
|
198
229
|
function getJSXTagName(el) {
|
|
199
230
|
const { name } = el;
|
|
@@ -306,29 +337,275 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
306
337
|
}
|
|
307
338
|
return false;
|
|
308
339
|
}
|
|
340
|
+
function buildPayloadFilter(payload) {
|
|
341
|
+
return t.callExpression(
|
|
342
|
+
t.arrowFunctionExpression(
|
|
343
|
+
[
|
|
344
|
+
t.objectPattern([
|
|
345
|
+
t.objectProperty(
|
|
346
|
+
t.identifier("__editorMeta"),
|
|
347
|
+
t.identifier("_$em"),
|
|
348
|
+
false,
|
|
349
|
+
false
|
|
350
|
+
),
|
|
351
|
+
t.objectProperty(
|
|
352
|
+
t.stringLiteral(KIT_SLOT_ATTR),
|
|
353
|
+
t.identifier("_$ks"),
|
|
354
|
+
false,
|
|
355
|
+
false
|
|
356
|
+
),
|
|
357
|
+
t.restElement(t.identifier("_$r"))
|
|
358
|
+
])
|
|
359
|
+
],
|
|
360
|
+
t.identifier("_$r")
|
|
361
|
+
),
|
|
362
|
+
[t.objectExpression([t.spreadElement(payload)])]
|
|
363
|
+
);
|
|
364
|
+
}
|
|
309
365
|
function sanitizeSpreadAttributes(attrs) {
|
|
310
366
|
for (const attr of attrs) {
|
|
311
367
|
if (!t.isJSXSpreadAttribute(attr)) continue;
|
|
312
368
|
if (isMetaStripSpreadExpression(attr.argument)) continue;
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
)
|
|
329
|
-
|
|
330
|
-
|
|
369
|
+
attr.argument = buildPayloadFilter(attr.argument);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function consumeKitSlot(attrs) {
|
|
373
|
+
let slot = null;
|
|
374
|
+
let found = false;
|
|
375
|
+
for (const attr of attrs) {
|
|
376
|
+
if (!t.isJSXAttribute(attr)) continue;
|
|
377
|
+
if (!t.isJSXIdentifier(attr.name, { name: KIT_SLOT_ATTR })) continue;
|
|
378
|
+
found = true;
|
|
379
|
+
if (slot !== null) continue;
|
|
380
|
+
const { value } = attr;
|
|
381
|
+
if (t.isStringLiteral(value)) {
|
|
382
|
+
slot = normalizeSlot(value.value);
|
|
383
|
+
} else if (t.isJSXExpressionContainer(value) && t.isStringLiteral(value.expression)) {
|
|
384
|
+
slot = normalizeSlot(value.expression.value);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (!found) return { slot: null, found: false, attrs };
|
|
388
|
+
return {
|
|
389
|
+
slot,
|
|
390
|
+
found: true,
|
|
391
|
+
attrs: attrs.filter(
|
|
392
|
+
(attr) => !(t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name, { name: KIT_SLOT_ATTR }))
|
|
393
|
+
)
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
function getFunctionName(fn) {
|
|
397
|
+
const node = fn.node;
|
|
398
|
+
if (t.isFunctionDeclaration(node) && node.id) return node.id.name;
|
|
399
|
+
if (t.isFunctionExpression(node) && node.id) return node.id.name;
|
|
400
|
+
const parent = fn.parentPath;
|
|
401
|
+
if (parent?.isVariableDeclarator() && t.isIdentifier(parent.node.id)) {
|
|
402
|
+
return parent.node.id.name;
|
|
403
|
+
}
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
function buildPropMap(pattern) {
|
|
407
|
+
const map = /* @__PURE__ */ new Map();
|
|
408
|
+
for (const prop of pattern.properties) {
|
|
409
|
+
if (!t.isObjectProperty(prop) || prop.computed) continue;
|
|
410
|
+
const key = t.isIdentifier(prop.key) ? prop.key.name : t.isStringLiteral(prop.key) ? prop.key.value : null;
|
|
411
|
+
if (!key) continue;
|
|
412
|
+
const value = prop.value;
|
|
413
|
+
if (t.isIdentifier(value)) {
|
|
414
|
+
map.set(value.name, key);
|
|
415
|
+
} else if (t.isAssignmentPattern(value) && t.isIdentifier(value.left)) {
|
|
416
|
+
map.set(value.left.name, key);
|
|
417
|
+
}
|
|
331
418
|
}
|
|
419
|
+
return map;
|
|
420
|
+
}
|
|
421
|
+
function resolvePropContext(path2) {
|
|
422
|
+
let fn = path2.getFunctionParent();
|
|
423
|
+
while (fn) {
|
|
424
|
+
const [first] = fn.node.params;
|
|
425
|
+
if (first && t.isObjectPattern(first)) {
|
|
426
|
+
if (fn.scope.parent !== fn.scope.getProgramParent()) return null;
|
|
427
|
+
return {
|
|
428
|
+
componentScope: fn.scope,
|
|
429
|
+
propMap: buildPropMap(first),
|
|
430
|
+
componentName: getFunctionName(fn)
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
fn = fn.getFunctionParent();
|
|
434
|
+
}
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
function resolveProp(name, scope, ctx) {
|
|
438
|
+
const prop = ctx.propMap.get(name);
|
|
439
|
+
if (!prop) return null;
|
|
440
|
+
const binding = scope.getBinding(name);
|
|
441
|
+
if (!binding) return null;
|
|
442
|
+
if (binding.scope !== ctx.componentScope) return null;
|
|
443
|
+
if (!binding.constant) return null;
|
|
444
|
+
return prop;
|
|
445
|
+
}
|
|
446
|
+
function isScopeWithinComponent(scope, ctx) {
|
|
447
|
+
let current = scope;
|
|
448
|
+
while (current) {
|
|
449
|
+
if (current === ctx.componentScope) return true;
|
|
450
|
+
current = current.parent;
|
|
451
|
+
}
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
function resolveLocalConstInit(name, scope, ctx) {
|
|
455
|
+
const binding = scope.getBinding(name);
|
|
456
|
+
if (!binding) return null;
|
|
457
|
+
if (!binding.constant) return null;
|
|
458
|
+
const declarator = binding.path;
|
|
459
|
+
if (!declarator.isVariableDeclarator()) return null;
|
|
460
|
+
if (!isScopeWithinComponent(binding.scope, ctx)) return null;
|
|
461
|
+
const init = declarator.node.init;
|
|
462
|
+
if (!init || !t.isExpression(init)) return null;
|
|
463
|
+
return { init, scope: declarator.scope };
|
|
464
|
+
}
|
|
465
|
+
function isStaticStringLiteral(node) {
|
|
466
|
+
if (t.isStringLiteral(node)) return true;
|
|
467
|
+
return t.isTemplateLiteral(node) && node.expressions.length === 0;
|
|
468
|
+
}
|
|
469
|
+
function collectPropIdentifiers(node, scope, ctx, out = []) {
|
|
470
|
+
if (!node) return out;
|
|
471
|
+
const visit = (child) => collectPropIdentifiers(child, scope, ctx, out);
|
|
472
|
+
if (t.isIdentifier(node)) {
|
|
473
|
+
const prop = resolveProp(node.name, scope, ctx);
|
|
474
|
+
if (prop && !out.includes(prop)) out.push(prop);
|
|
475
|
+
return out;
|
|
476
|
+
}
|
|
477
|
+
if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) {
|
|
478
|
+
visit(node.object);
|
|
479
|
+
if (node.computed) visit(node.property);
|
|
480
|
+
return out;
|
|
481
|
+
}
|
|
482
|
+
if (t.isCallExpression(node) || t.isOptionalCallExpression(node)) {
|
|
483
|
+
visit(node.callee);
|
|
484
|
+
node.arguments.forEach((arg) => visit(arg));
|
|
485
|
+
return out;
|
|
486
|
+
}
|
|
487
|
+
if (t.isTemplateLiteral(node)) {
|
|
488
|
+
node.expressions.forEach((expr) => visit(expr));
|
|
489
|
+
return out;
|
|
490
|
+
}
|
|
491
|
+
if (t.isConditionalExpression(node)) {
|
|
492
|
+
visit(node.test);
|
|
493
|
+
visit(node.consequent);
|
|
494
|
+
visit(node.alternate);
|
|
495
|
+
return out;
|
|
496
|
+
}
|
|
497
|
+
if (t.isLogicalExpression(node) || t.isBinaryExpression(node)) {
|
|
498
|
+
visit(node.left);
|
|
499
|
+
visit(node.right);
|
|
500
|
+
return out;
|
|
501
|
+
}
|
|
502
|
+
if (t.isUnaryExpression(node) || t.isAwaitExpression(node)) {
|
|
503
|
+
visit(node.argument);
|
|
504
|
+
return out;
|
|
505
|
+
}
|
|
506
|
+
if (t.isArrayExpression(node)) {
|
|
507
|
+
node.elements.forEach((el) => visit(el));
|
|
508
|
+
return out;
|
|
509
|
+
}
|
|
510
|
+
if (t.isObjectExpression(node)) {
|
|
511
|
+
for (const prop of node.properties) {
|
|
512
|
+
if (t.isObjectProperty(prop)) {
|
|
513
|
+
if (prop.computed) visit(prop.key);
|
|
514
|
+
visit(prop.value);
|
|
515
|
+
} else if (t.isSpreadElement(prop)) {
|
|
516
|
+
visit(prop.argument);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return out;
|
|
520
|
+
}
|
|
521
|
+
if (t.isSpreadElement(node)) {
|
|
522
|
+
visit(node.argument);
|
|
523
|
+
return out;
|
|
524
|
+
}
|
|
525
|
+
if (t.isTSAsExpression(node) || t.isTSNonNullExpression(node) || t.isTypeCastExpression(node)) {
|
|
526
|
+
visit(node.expression);
|
|
527
|
+
return out;
|
|
528
|
+
}
|
|
529
|
+
return out;
|
|
530
|
+
}
|
|
531
|
+
function classifyExpression(expr, scope, ctx, hop) {
|
|
532
|
+
if (t.isIdentifier(expr)) {
|
|
533
|
+
const prop = resolveProp(expr.name, scope, ctx);
|
|
534
|
+
if (prop) return { kind: "direct", prop };
|
|
535
|
+
if (hop > 0) return null;
|
|
536
|
+
const local = resolveLocalConstInit(expr.name, scope, ctx);
|
|
537
|
+
if (!local) return null;
|
|
538
|
+
const inner = classifyExpression(local.init, local.scope, ctx, hop + 1);
|
|
539
|
+
if (!inner) return null;
|
|
540
|
+
return { kind: inner.kind === "formatted" ? "formatted" : "derived", prop: inner.prop };
|
|
541
|
+
}
|
|
542
|
+
if (t.isLogicalExpression(expr) && (expr.operator === "||" || expr.operator === "??") && isStaticStringLiteral(expr.right)) {
|
|
543
|
+
const left = classifyExpression(expr.left, scope, ctx, hop);
|
|
544
|
+
if (!left) return null;
|
|
545
|
+
return { kind: left.kind === "formatted" ? "formatted" : "derived", prop: left.prop };
|
|
546
|
+
}
|
|
547
|
+
const props = collectPropIdentifiers(expr, scope, ctx);
|
|
548
|
+
return props.length > 0 ? { kind: "formatted", prop: props[0] } : null;
|
|
549
|
+
}
|
|
550
|
+
function meaningfulChildren(children) {
|
|
551
|
+
return children.filter((child) => {
|
|
552
|
+
if (t.isJSXText(child)) return child.value.trim() !== "";
|
|
553
|
+
if (t.isJSXExpressionContainer(child)) return !t.isJSXEmptyExpression(child.expression);
|
|
554
|
+
return true;
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
function collectPropBindings(path2, attrs) {
|
|
558
|
+
const ctx = resolvePropContext(path2);
|
|
559
|
+
if (!ctx || ctx.propMap.size === 0) return { bindings: [], owner: null };
|
|
560
|
+
if (ctx.componentName === null) return { bindings: [], owner: null };
|
|
561
|
+
const scope = path2.scope;
|
|
562
|
+
const bindings = [];
|
|
563
|
+
const elementPath = path2.parentPath;
|
|
564
|
+
if (elementPath && elementPath.isJSXElement()) {
|
|
565
|
+
const children = meaningfulChildren(elementPath.node.children);
|
|
566
|
+
const isSoleChild = children.length === 1;
|
|
567
|
+
for (const child of children) {
|
|
568
|
+
if (!t.isJSXExpressionContainer(child)) continue;
|
|
569
|
+
const expression = child.expression;
|
|
570
|
+
if (t.isJSXEmptyExpression(expression)) continue;
|
|
571
|
+
const verdict = classifyExpression(expression, scope, ctx, 0);
|
|
572
|
+
if (!verdict) continue;
|
|
573
|
+
bindings.push({
|
|
574
|
+
target: "children",
|
|
575
|
+
prop: verdict.prop,
|
|
576
|
+
kind: isSoleChild ? verdict.kind : "formatted"
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
for (const attr of attrs) {
|
|
581
|
+
if (!t.isJSXAttribute(attr)) continue;
|
|
582
|
+
const name = t.isJSXIdentifier(attr.name) ? attr.name.name : `${attr.name.namespace.name}:${attr.name.name.name}`;
|
|
583
|
+
if (NON_BINDING_ATTRS.has(name)) continue;
|
|
584
|
+
const value = attr.value;
|
|
585
|
+
if (!t.isJSXExpressionContainer(value)) continue;
|
|
586
|
+
const expression = value.expression;
|
|
587
|
+
if (t.isJSXEmptyExpression(expression)) continue;
|
|
588
|
+
const verdict = classifyExpression(expression, scope, ctx, 0);
|
|
589
|
+
if (!verdict) continue;
|
|
590
|
+
bindings.push({
|
|
591
|
+
target: `attr:${name}`,
|
|
592
|
+
prop: verdict.prop,
|
|
593
|
+
// M2b: machine-contract attributes are reported, never offered.
|
|
594
|
+
kind: isNonContentAttribute(name) ? "formatted" : verdict.kind
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
return { bindings, owner: bindings.length > 0 ? ctx.componentName : null };
|
|
598
|
+
}
|
|
599
|
+
function propBindingsToAst(bindings) {
|
|
600
|
+
return t.arrayExpression(
|
|
601
|
+
bindings.map(
|
|
602
|
+
(binding) => t.objectExpression([
|
|
603
|
+
t.objectProperty(t.identifier("target"), t.stringLiteral(binding.target)),
|
|
604
|
+
t.objectProperty(t.identifier("prop"), t.stringLiteral(binding.prop)),
|
|
605
|
+
t.objectProperty(t.identifier("kind"), t.stringLiteral(binding.kind))
|
|
606
|
+
])
|
|
607
|
+
)
|
|
608
|
+
);
|
|
332
609
|
}
|
|
333
610
|
return {
|
|
334
611
|
name: "babel-plugin-editor-meta",
|
|
@@ -356,25 +633,13 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
356
633
|
if (!propsArg || t.isNullLiteral(propsArg)) return;
|
|
357
634
|
if (!t.isExpression(propsArg)) return;
|
|
358
635
|
if (isMetaStripSpreadExpression(propsArg)) return;
|
|
359
|
-
args[1] =
|
|
360
|
-
t.arrowFunctionExpression(
|
|
361
|
-
[
|
|
362
|
-
t.objectPattern([
|
|
363
|
-
t.objectProperty(
|
|
364
|
-
t.identifier("__editorMeta"),
|
|
365
|
-
t.identifier("_$em"),
|
|
366
|
-
false,
|
|
367
|
-
false
|
|
368
|
-
),
|
|
369
|
-
t.restElement(t.identifier("_$r"))
|
|
370
|
-
])
|
|
371
|
-
],
|
|
372
|
-
t.identifier("_$r")
|
|
373
|
-
),
|
|
374
|
-
[t.objectExpression([t.spreadElement(propsArg)])]
|
|
375
|
-
);
|
|
636
|
+
args[1] = buildPayloadFilter(propsArg);
|
|
376
637
|
},
|
|
377
638
|
JSXOpeningElement(path2, state) {
|
|
639
|
+
const consumed = consumeKitSlot(path2.node.attributes);
|
|
640
|
+
path2.node.attributes = consumed.attrs;
|
|
641
|
+
const slot = consumed.slot;
|
|
642
|
+
const hasSlotAttr = consumed.found;
|
|
378
643
|
const filename = state.filename ?? "";
|
|
379
644
|
if (fileExclude.test(filename)) return;
|
|
380
645
|
const existing = path2.node.attributes.find(
|
|
@@ -420,9 +685,11 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
420
685
|
}
|
|
421
686
|
}
|
|
422
687
|
const nodeId = computeNodeId(file, line, col, componentName);
|
|
423
|
-
const
|
|
688
|
+
const isKitOrigin = origin === "kit" || hasSlotAttr;
|
|
689
|
+
const movable = isKitOrigin ? false : isMovable(path2);
|
|
424
690
|
const parentNodeId = getParentNodeId(path2, file);
|
|
425
691
|
const staticPropsObj = extractStaticProps(path2.node.attributes);
|
|
692
|
+
const { bindings, owner } = collectPropBindings(path2, path2.node.attributes);
|
|
426
693
|
const metaObj = t.objectExpression([
|
|
427
694
|
t.objectProperty(t.identifier("nodeId"), t.stringLiteral(nodeId)),
|
|
428
695
|
t.objectProperty(t.identifier("file"), t.stringLiteral(file)),
|
|
@@ -439,6 +706,22 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
439
706
|
parentNodeId ? t.stringLiteral(parentNodeId) : t.nullLiteral()
|
|
440
707
|
)
|
|
441
708
|
]);
|
|
709
|
+
if (slot !== null) {
|
|
710
|
+
metaObj.properties.push(
|
|
711
|
+
t.objectProperty(t.identifier("slot"), t.stringLiteral(slot))
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
if (bindings.length > 0) {
|
|
715
|
+
metaObj.properties.push(
|
|
716
|
+
t.objectProperty(t.identifier("propBindings"), propBindingsToAst(bindings))
|
|
717
|
+
);
|
|
718
|
+
metaObj.properties.push(
|
|
719
|
+
t.objectProperty(
|
|
720
|
+
t.identifier("propOwner"),
|
|
721
|
+
owner ? t.stringLiteral(owner) : t.nullLiteral()
|
|
722
|
+
)
|
|
723
|
+
);
|
|
724
|
+
}
|
|
442
725
|
if (isHostElement && includeHostSourceRef) {
|
|
443
726
|
path2.node.attributes.push(
|
|
444
727
|
t.jsxAttribute(
|
|
@@ -447,10 +730,11 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
|
447
730
|
)
|
|
448
731
|
);
|
|
449
732
|
}
|
|
733
|
+
const metaThunk = t.arrowFunctionExpression([], metaObj);
|
|
450
734
|
path2.node.attributes.push(
|
|
451
735
|
t.jsxAttribute(
|
|
452
736
|
t.jsxIdentifier("__editorMeta"),
|
|
453
|
-
t.jsxExpressionContainer(
|
|
737
|
+
t.jsxExpressionContainer(metaThunk)
|
|
454
738
|
)
|
|
455
739
|
);
|
|
456
740
|
}
|
|
@@ -95,6 +95,28 @@
|
|
|
95
95
|
var FIBER_KEY_PREFIX = "__reactFiber$"
|
|
96
96
|
var PROPS_KEY_PREFIX = "__reactProps$"
|
|
97
97
|
|
|
98
|
+
// ARCH-883 P0-1: babel-plugin-editor-meta.ts (TypeScript context) now
|
|
99
|
+
// emits __editorMeta as a zero-arg function, not the object literal
|
|
100
|
+
// directly, so React never writes it into the DOM. Every extraction
|
|
101
|
+
// site below must invoke the value when it is a function. Mirrors
|
|
102
|
+
// readEditorMetaValue in fiber-bridge.ts — if this changes, update
|
|
103
|
+
// that copy to maintain parity.
|
|
104
|
+
function resolveEditorMetaValue(value) {
|
|
105
|
+
if (typeof value === "function") {
|
|
106
|
+
// Each call re-evaluates the plugin-emitted `() => ({...})`
|
|
107
|
+
// closure and returns a FRESH object literal — never rely on
|
|
108
|
+
// meta object identity (`===`) across two separate reads, even
|
|
109
|
+
// within the same render (mirrors readEditorMetaValue in
|
|
110
|
+
// fiber-bridge.ts).
|
|
111
|
+
return value()
|
|
112
|
+
}
|
|
113
|
+
// Twin parity with fiber-bridge.ts's readEditorMetaValue: only
|
|
114
|
+
// undefined/null is a miss, not "any falsy value" — __editorMeta is
|
|
115
|
+
// always an object or a function in practice, so this is a no-op
|
|
116
|
+
// today, but keeps the two implementations provably equivalent.
|
|
117
|
+
return value === undefined || value === null ? null : value
|
|
118
|
+
}
|
|
119
|
+
|
|
98
120
|
function hasEditorMetaInFiberChain(fiber) {
|
|
99
121
|
var current = fiber
|
|
100
122
|
while (current) {
|
|
@@ -195,7 +217,7 @@
|
|
|
195
217
|
var fiber = getFiberFromElement(el)
|
|
196
218
|
while (fiber) {
|
|
197
219
|
if (fiber.memoizedProps && fiber.memoizedProps.__editorMeta) {
|
|
198
|
-
return fiber.memoizedProps.__editorMeta
|
|
220
|
+
return resolveEditorMetaValue(fiber.memoizedProps.__editorMeta)
|
|
199
221
|
}
|
|
200
222
|
fiber = fiber["return"]
|
|
201
223
|
}
|
|
@@ -205,7 +227,7 @@
|
|
|
205
227
|
function getDirectEditorMetaFromElement(el) {
|
|
206
228
|
var fiber = getFiberFromElement(el)
|
|
207
229
|
if (fiber && fiber.memoizedProps && fiber.memoizedProps.__editorMeta) {
|
|
208
|
-
return fiber.memoizedProps.__editorMeta
|
|
230
|
+
return resolveEditorMetaValue(fiber.memoizedProps.__editorMeta)
|
|
209
231
|
}
|
|
210
232
|
return null
|
|
211
233
|
}
|
|
@@ -231,7 +253,7 @@
|
|
|
231
253
|
break
|
|
232
254
|
}
|
|
233
255
|
if (current.memoizedProps && current.memoizedProps.__editorMeta) {
|
|
234
|
-
return current.memoizedProps.__editorMeta
|
|
256
|
+
return resolveEditorMetaValue(current.memoizedProps.__editorMeta)
|
|
235
257
|
}
|
|
236
258
|
current = current["return"]
|
|
237
259
|
}
|
|
@@ -864,9 +886,14 @@
|
|
|
864
886
|
postMessageToParent({
|
|
865
887
|
type: "INSPECTOR_SCRIPT_LOADED",
|
|
866
888
|
timestamp: Date.now(),
|
|
867
|
-
version: "2.1.
|
|
889
|
+
version: "2.1.1",
|
|
868
890
|
protocolVersion: 1,
|
|
869
891
|
capabilities: {
|
|
892
|
+
// 2.1.1: function-valued __editorMeta props are invoked before any
|
|
893
|
+
// postMessage, so meta payloads stay structured-cloneable. Hosts can
|
|
894
|
+
// gate on this bit to confirm the deployed CDN artifact carries the
|
|
895
|
+
// fix (the 2.1.0 URL is overwritten in place on publish).
|
|
896
|
+
functionValuedEditorMeta: true,
|
|
870
897
|
inspect: true,
|
|
871
898
|
dndMove: true,
|
|
872
899
|
dndResize: true,
|
|
@@ -2020,6 +2047,19 @@
|
|
|
2020
2047
|
: null,
|
|
2021
2048
|
attributes: attributes,
|
|
2022
2049
|
inspectorSource: inspectorInfo,
|
|
2050
|
+
// ARCH-883 F1 — FORWARD THE META WHOLE. The plugin now also emits
|
|
2051
|
+
// `slot`, `propBindings` and `propOwner` (SDD §2.3/§2.6) and the editor
|
|
2052
|
+
// host routes edits off them; field-picking here would silently strip
|
|
2053
|
+
// them and turn every kit-internal edit into a gap. `inspectorSource`
|
|
2054
|
+
// above is the deliberately narrow structure — this one is not.
|
|
2055
|
+
//
|
|
2056
|
+
// Unlike P0-1 this needs no deploy ordering: the extra keys are plain
|
|
2057
|
+
// data, so an already-published standalone.js forwards them unchanged
|
|
2058
|
+
// through `postMessage`'s structured clone. Whether a given PAGE has
|
|
2059
|
+
// them depends on the plugin that built it, which the host resolves via
|
|
2060
|
+
// `deriveEditorCapabilities(kitRuntimeVersion)` (SDD §2.5) — never from
|
|
2061
|
+
// this script's version. The slot string is opaque here; validating it
|
|
2062
|
+
// against kit-runtime's `slot-vocabulary` is the host's job.
|
|
2023
2063
|
editorMeta: editorMeta ? editorMeta.meta : null,
|
|
2024
2064
|
computedStyles: {
|
|
2025
2065
|
display: computed.display,
|