@archie/devtools 0.0.25 → 0.0.27
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/dist/chunk-4VGQJ3PW.mjs +577 -0
- package/dist/client/client.js +23 -29
- package/dist/client/client.mjs +23 -29
- package/dist/collection-binding.d.mts +156 -0
- package/dist/collection-binding.d.ts +156 -0
- package/dist/collection-binding.js +553 -0
- package/dist/collection-binding.mjs +521 -0
- package/dist/index.js +9 -10
- package/dist/index.mjs +7 -575
- package/dist/inspector.standalone.js +262 -10
- package/package.json +6 -1
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var getDirname = () => path.dirname(getFilename());
|
|
6
|
-
var __dirname = /* @__PURE__ */ getDirname();
|
|
1
|
+
import {
|
|
2
|
+
__dirname,
|
|
3
|
+
babelPluginEditorMeta
|
|
4
|
+
} from "./chunk-4VGQJ3PW.mjs";
|
|
7
5
|
|
|
8
6
|
// src/index.ts
|
|
9
7
|
import { readFileSync } from "fs";
|
|
@@ -139,16 +137,16 @@ function babelPluginDndAuto({ types: t }, opts = {}) {
|
|
|
139
137
|
return {
|
|
140
138
|
name: "babel-plugin-dnd-auto",
|
|
141
139
|
visitor: {
|
|
142
|
-
ExportDefaultDeclaration(
|
|
140
|
+
ExportDefaultDeclaration(path, state) {
|
|
143
141
|
const filename = state.filename ?? "";
|
|
144
142
|
if (fileExclude.test(filename)) return;
|
|
145
143
|
if (fileMatch && !fileMatch.test(filename)) return;
|
|
146
|
-
const { declaration } =
|
|
144
|
+
const { declaration } = path.node;
|
|
147
145
|
if (!t.isFunctionDeclaration(declaration)) return;
|
|
148
146
|
const componentName = declaration.id?.name ?? "Component";
|
|
149
147
|
const scopeCounter = { n: 0 };
|
|
150
148
|
let didTransform = false;
|
|
151
|
-
|
|
149
|
+
path.traverse({
|
|
152
150
|
ReturnStatement(retPath) {
|
|
153
151
|
const fnParent = retPath.getFunctionParent();
|
|
154
152
|
if (fnParent?.node !== declaration) return;
|
|
@@ -176,572 +174,6 @@ function babelPluginDndAuto({ types: t }, opts = {}) {
|
|
|
176
174
|
};
|
|
177
175
|
}
|
|
178
176
|
|
|
179
|
-
// src/babel-plugin-editor-meta.ts
|
|
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
|
-
}
|
|
211
|
-
function isPackageImport(src) {
|
|
212
|
-
if (src.startsWith(".") || src.startsWith("/")) return false;
|
|
213
|
-
if (src.startsWith("@")) {
|
|
214
|
-
const slashIdx = src.indexOf("/");
|
|
215
|
-
if (slashIdx === 1) return false;
|
|
216
|
-
if (slashIdx > 1) return true;
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
if (src.startsWith("~/") || src.startsWith("#/")) return false;
|
|
220
|
-
return true;
|
|
221
|
-
}
|
|
222
|
-
function babelPluginEditorMeta({ types: t }, opts = {}) {
|
|
223
|
-
const {
|
|
224
|
-
fileExclude = /node_modules/,
|
|
225
|
-
instrumentImported = true,
|
|
226
|
-
includeHostSourceRef = false,
|
|
227
|
-
origin = "screen"
|
|
228
|
-
} = opts;
|
|
229
|
-
function getJSXTagName(el) {
|
|
230
|
-
const { name } = el;
|
|
231
|
-
if (t.isJSXIdentifier(name)) return name.name;
|
|
232
|
-
if (t.isJSXMemberExpression(name)) {
|
|
233
|
-
const parts = [];
|
|
234
|
-
let current = name;
|
|
235
|
-
while (t.isJSXMemberExpression(current)) {
|
|
236
|
-
parts.unshift(current.property.name);
|
|
237
|
-
current = current.object;
|
|
238
|
-
}
|
|
239
|
-
if (t.isJSXIdentifier(current)) parts.unshift(current.name);
|
|
240
|
-
return parts.join(".");
|
|
241
|
-
}
|
|
242
|
-
return "";
|
|
243
|
-
}
|
|
244
|
-
function isHostLikeMemberExpressionName(name) {
|
|
245
|
-
if (!t.isJSXMemberExpression(name)) return false;
|
|
246
|
-
const propertyName = name.property.name;
|
|
247
|
-
return propertyName[0] === propertyName[0].toLowerCase();
|
|
248
|
-
}
|
|
249
|
-
function computeNodeId(file, line, col, componentName) {
|
|
250
|
-
return `${file}:${line}:${col}:${componentName}`;
|
|
251
|
-
}
|
|
252
|
-
function isMovable(path2) {
|
|
253
|
-
const elPath = path2.parentPath;
|
|
254
|
-
if (!elPath) return false;
|
|
255
|
-
const parentEl = elPath.parentPath;
|
|
256
|
-
if (!parentEl || !parentEl.isJSXElement()) return false;
|
|
257
|
-
const siblings = parentEl.node.children.filter(
|
|
258
|
-
(c) => t.isJSXElement(c)
|
|
259
|
-
);
|
|
260
|
-
return siblings.length >= 2;
|
|
261
|
-
}
|
|
262
|
-
function getParentNodeId(path2, file) {
|
|
263
|
-
const elPath = path2.parentPath;
|
|
264
|
-
if (!elPath) return null;
|
|
265
|
-
let ancestor = elPath.parentPath;
|
|
266
|
-
while (ancestor) {
|
|
267
|
-
if (ancestor.isJSXElement()) {
|
|
268
|
-
const opening = ancestor.node.openingElement;
|
|
269
|
-
const loc = opening.loc?.start;
|
|
270
|
-
if (loc) {
|
|
271
|
-
const tag = getJSXTagName(opening);
|
|
272
|
-
return computeNodeId(file, loc.line, loc.column + 1, tag);
|
|
273
|
-
}
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
ancestor = ancestor.parentPath;
|
|
277
|
-
}
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
function extractStaticProps(attrs) {
|
|
281
|
-
const props = [];
|
|
282
|
-
let hasAny = false;
|
|
283
|
-
for (const attr of attrs) {
|
|
284
|
-
if (t.isJSXSpreadAttribute(attr)) continue;
|
|
285
|
-
if (!t.isJSXAttribute(attr)) continue;
|
|
286
|
-
const keyName = t.isJSXIdentifier(attr.name) ? attr.name.name : attr.name.name.name;
|
|
287
|
-
if (keyName === "__editorMeta") continue;
|
|
288
|
-
let value;
|
|
289
|
-
if (attr.value === null || attr.value === void 0) {
|
|
290
|
-
value = t.booleanLiteral(true);
|
|
291
|
-
} else if (t.isStringLiteral(attr.value)) {
|
|
292
|
-
value = attr.value;
|
|
293
|
-
} else if (t.isJSXExpressionContainer(attr.value)) {
|
|
294
|
-
const expr = attr.value.expression;
|
|
295
|
-
if (t.isNumericLiteral(expr)) {
|
|
296
|
-
value = expr;
|
|
297
|
-
} else if (t.isBooleanLiteral(expr)) {
|
|
298
|
-
value = expr;
|
|
299
|
-
} else if (t.isNullLiteral(expr)) {
|
|
300
|
-
value = expr;
|
|
301
|
-
} else if (t.isStringLiteral(expr)) {
|
|
302
|
-
value = expr;
|
|
303
|
-
} else {
|
|
304
|
-
value = t.stringLiteral("__dynamic__");
|
|
305
|
-
}
|
|
306
|
-
} else {
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
props.push(t.objectProperty(t.stringLiteral(keyName), value));
|
|
310
|
-
hasAny = true;
|
|
311
|
-
}
|
|
312
|
-
return hasAny ? t.objectExpression(props) : null;
|
|
313
|
-
}
|
|
314
|
-
function isMetaStripSpreadExpression(arg) {
|
|
315
|
-
if (!t.isCallExpression(arg)) return false;
|
|
316
|
-
if (!t.isArrowFunctionExpression(arg.callee)) return false;
|
|
317
|
-
const [firstParam] = arg.callee.params;
|
|
318
|
-
if (!firstParam || !t.isObjectPattern(firstParam)) return false;
|
|
319
|
-
return firstParam.properties.some((prop) => {
|
|
320
|
-
if (!t.isObjectProperty(prop)) return false;
|
|
321
|
-
if (!t.isIdentifier(prop.key)) return false;
|
|
322
|
-
return prop.key.name === "__editorMeta";
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
function hasTruthyAsChildProp(attrs) {
|
|
326
|
-
for (const attr of attrs) {
|
|
327
|
-
if (!t.isJSXAttribute(attr) || !t.isJSXIdentifier(attr.name, { name: "asChild" })) {
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
if (attr.value == null) return true;
|
|
331
|
-
if (t.isJSXExpressionContainer(attr.value)) {
|
|
332
|
-
const expr = attr.value.expression;
|
|
333
|
-
if (t.isBooleanLiteral(expr)) return expr.value;
|
|
334
|
-
}
|
|
335
|
-
if (t.isStringLiteral(attr.value)) return attr.value.value !== "false";
|
|
336
|
-
return true;
|
|
337
|
-
}
|
|
338
|
-
return false;
|
|
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
|
-
}
|
|
365
|
-
function sanitizeSpreadAttributes(attrs) {
|
|
366
|
-
for (const attr of attrs) {
|
|
367
|
-
if (!t.isJSXSpreadAttribute(attr)) continue;
|
|
368
|
-
if (isMetaStripSpreadExpression(attr.argument)) continue;
|
|
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
|
-
}
|
|
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
|
-
);
|
|
609
|
-
}
|
|
610
|
-
return {
|
|
611
|
-
name: "babel-plugin-editor-meta",
|
|
612
|
-
visitor: {
|
|
613
|
-
CallExpression(path2, state) {
|
|
614
|
-
const filename = state.filename ?? "";
|
|
615
|
-
if (fileExclude.test(filename)) return;
|
|
616
|
-
const callee = path2.node.callee;
|
|
617
|
-
let isCreateElement = false;
|
|
618
|
-
let isCloneElement = false;
|
|
619
|
-
if (t.isIdentifier(callee, { name: "createElement" })) {
|
|
620
|
-
isCreateElement = true;
|
|
621
|
-
} else if (t.isMemberExpression(callee) && t.isIdentifier(callee.property, { name: "createElement" })) {
|
|
622
|
-
isCreateElement = true;
|
|
623
|
-
} else if (t.isIdentifier(callee, { name: "cloneElement" })) {
|
|
624
|
-
isCloneElement = true;
|
|
625
|
-
} else if (t.isMemberExpression(callee) && t.isIdentifier(callee.property, { name: "cloneElement" })) {
|
|
626
|
-
isCloneElement = true;
|
|
627
|
-
}
|
|
628
|
-
if (!isCreateElement && !isCloneElement) return;
|
|
629
|
-
const args = path2.node.arguments;
|
|
630
|
-
if (args.length < 2) return;
|
|
631
|
-
if (isCreateElement && !t.isStringLiteral(args[0])) return;
|
|
632
|
-
const propsArg = args[1];
|
|
633
|
-
if (!propsArg || t.isNullLiteral(propsArg)) return;
|
|
634
|
-
if (!t.isExpression(propsArg)) return;
|
|
635
|
-
if (isMetaStripSpreadExpression(propsArg)) return;
|
|
636
|
-
args[1] = buildPayloadFilter(propsArg);
|
|
637
|
-
},
|
|
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;
|
|
643
|
-
const filename = state.filename ?? "";
|
|
644
|
-
if (fileExclude.test(filename)) return;
|
|
645
|
-
const existing = path2.node.attributes.find(
|
|
646
|
-
(a) => t.isJSXAttribute(a) && t.isJSXIdentifier(a.name, { name: "__editorMeta" })
|
|
647
|
-
);
|
|
648
|
-
if (existing) return;
|
|
649
|
-
const loc = path2.node.loc?.start;
|
|
650
|
-
if (!loc) return;
|
|
651
|
-
const root = state.file.opts.root ?? "";
|
|
652
|
-
const file = root ? nodePath.relative(root, filename) : filename;
|
|
653
|
-
const line = loc.line;
|
|
654
|
-
const col = loc.column + 1;
|
|
655
|
-
const componentName = getJSXTagName(path2.node);
|
|
656
|
-
if (!componentName) return;
|
|
657
|
-
const isHostLikeMemberExpression = isHostLikeMemberExpressionName(path2.node.name);
|
|
658
|
-
const isHostElement = componentName[0] === componentName[0].toLowerCase();
|
|
659
|
-
sanitizeSpreadAttributes(path2.node.attributes);
|
|
660
|
-
if (hasTruthyAsChildProp(path2.node.attributes)) {
|
|
661
|
-
return;
|
|
662
|
-
}
|
|
663
|
-
let rootName = null;
|
|
664
|
-
if (t.isJSXIdentifier(path2.node.name)) {
|
|
665
|
-
rootName = path2.node.name.name;
|
|
666
|
-
} else if (t.isJSXMemberExpression(path2.node.name)) {
|
|
667
|
-
let cur = path2.node.name;
|
|
668
|
-
while (t.isJSXMemberExpression(cur)) cur = cur.object;
|
|
669
|
-
if (t.isJSXIdentifier(cur)) rootName = cur.name;
|
|
670
|
-
}
|
|
671
|
-
if (rootName) {
|
|
672
|
-
const binding = path2.scope.getBinding(rootName);
|
|
673
|
-
if (binding) {
|
|
674
|
-
const bp = binding.path;
|
|
675
|
-
if (bp.isImportSpecifier() || bp.isImportDefaultSpecifier() || bp.isImportNamespaceSpecifier()) {
|
|
676
|
-
if (!instrumentImported) return;
|
|
677
|
-
const decl = bp.parentPath;
|
|
678
|
-
if (decl?.isImportDeclaration()) {
|
|
679
|
-
const src = decl.node.source.value;
|
|
680
|
-
if (isPackageImport(src) && !isHostLikeMemberExpression) return;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
const programScope = path2.scope.getProgramParent();
|
|
684
|
-
if (binding.scope !== programScope) return;
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
const nodeId = computeNodeId(file, line, col, componentName);
|
|
688
|
-
const isKitOrigin = origin === "kit" || hasSlotAttr;
|
|
689
|
-
const movable = isKitOrigin ? false : isMovable(path2);
|
|
690
|
-
const parentNodeId = getParentNodeId(path2, file);
|
|
691
|
-
const staticPropsObj = extractStaticProps(path2.node.attributes);
|
|
692
|
-
const { bindings, owner } = collectPropBindings(path2, path2.node.attributes);
|
|
693
|
-
const metaObj = t.objectExpression([
|
|
694
|
-
t.objectProperty(t.identifier("nodeId"), t.stringLiteral(nodeId)),
|
|
695
|
-
t.objectProperty(t.identifier("file"), t.stringLiteral(file)),
|
|
696
|
-
t.objectProperty(t.identifier("line"), t.numericLiteral(line)),
|
|
697
|
-
t.objectProperty(t.identifier("col"), t.numericLiteral(col)),
|
|
698
|
-
t.objectProperty(t.identifier("componentName"), t.stringLiteral(componentName)),
|
|
699
|
-
t.objectProperty(
|
|
700
|
-
t.identifier("staticProps"),
|
|
701
|
-
staticPropsObj ?? t.nullLiteral()
|
|
702
|
-
),
|
|
703
|
-
t.objectProperty(t.identifier("movable"), t.booleanLiteral(movable)),
|
|
704
|
-
t.objectProperty(
|
|
705
|
-
t.identifier("parentNodeId"),
|
|
706
|
-
parentNodeId ? t.stringLiteral(parentNodeId) : t.nullLiteral()
|
|
707
|
-
)
|
|
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
|
-
}
|
|
725
|
-
if (isHostElement && includeHostSourceRef) {
|
|
726
|
-
path2.node.attributes.push(
|
|
727
|
-
t.jsxAttribute(
|
|
728
|
-
t.jsxIdentifier("data-archie-source-ref"),
|
|
729
|
-
t.stringLiteral(`${file}::${line}::${col}`)
|
|
730
|
-
)
|
|
731
|
-
);
|
|
732
|
-
}
|
|
733
|
-
const metaThunk = t.arrowFunctionExpression([], metaObj);
|
|
734
|
-
path2.node.attributes.push(
|
|
735
|
-
t.jsxAttribute(
|
|
736
|
-
t.jsxIdentifier("__editorMeta"),
|
|
737
|
-
t.jsxExpressionContainer(metaThunk)
|
|
738
|
-
)
|
|
739
|
-
);
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
|
|
745
177
|
// src/index.ts
|
|
746
178
|
var LOCAL_INSPECTOR_SERVE_PATH = "/_archie/inspector.js";
|
|
747
179
|
function archieDevTools(options = {}) {
|