@archie/devtools 0.0.47 → 0.1.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/dist/index.js CHANGED
@@ -205,6 +205,7 @@ function babelPluginDndAuto({ types: t }, opts = {}) {
205
205
  }
206
206
 
207
207
  // src/babel-plugin-editor-meta.ts
208
+ var import_editor_protocol = require("@8base-archie/editor-protocol");
208
209
  var nodePath = __toESM(require("path"));
209
210
  function meaningfulChildren(t, children) {
210
211
  return children.filter((child) => {
@@ -260,7 +261,8 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
260
261
  instrumentImported = true,
261
262
  includeHostSourceRef = false,
262
263
  origin = "screen",
263
- templateOrigin = false
264
+ templateOrigin = false,
265
+ allowLegacyIds = true
264
266
  } = opts;
265
267
  function getJSXTagName(el) {
266
268
  const { name } = el;
@@ -308,6 +310,77 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
308
310
  function computeNodeId(file, line, col, componentName) {
309
311
  return `${file}:${line}:${col}:${componentName}`;
310
312
  }
313
+ function readVidAttr(attrs) {
314
+ for (const attr of attrs) {
315
+ if (!t.isJSXAttribute(attr)) continue;
316
+ if (!t.isJSXIdentifier(attr.name, { name: import_editor_protocol.VID_ATTR })) continue;
317
+ const { value } = attr;
318
+ let raw = null;
319
+ if (t.isStringLiteral(value)) {
320
+ raw = value.value;
321
+ } else if (t.isJSXExpressionContainer(value) && t.isStringLiteral(value.expression)) {
322
+ raw = value.expression.value;
323
+ }
324
+ if (raw !== null && import_editor_protocol.VID_PATTERN.test(raw)) return raw;
325
+ return null;
326
+ }
327
+ return null;
328
+ }
329
+ function computeDynamicType(path) {
330
+ let current = path.parentPath;
331
+ while (current) {
332
+ if (current.isJSXExpressionContainer()) {
333
+ const expr = current.node.expression;
334
+ if (t.isConditionalExpression(expr) || t.isLogicalExpression(expr)) {
335
+ return "CONDITIONAL";
336
+ }
337
+ }
338
+ if (current.isArrowFunctionExpression() || current.isFunctionExpression()) {
339
+ const call = current.parentPath;
340
+ if (call?.isCallExpression()) {
341
+ const callee = call.node.callee;
342
+ if (t.isMemberExpression(callee) && !callee.computed && t.isIdentifier(callee.property) && /^(map|flatMap|forEach)$/.test(callee.property.name)) {
343
+ return "ARRAY";
344
+ }
345
+ }
346
+ break;
347
+ }
348
+ if (current.isFunctionDeclaration()) break;
349
+ current = current.parentPath;
350
+ }
351
+ return "STATIC";
352
+ }
353
+ const SHELL_FILE_RE = /(^|\/)shell\.jsx$/;
354
+ const SHELL_DIR_RE = /(^|\/)components\/shell\//;
355
+ const CHROME_ANCESTOR_TAGS = /* @__PURE__ */ new Set(["nav", "aside", "header"]);
356
+ function computeIsChrome(file, path) {
357
+ if (SHELL_FILE_RE.test(file) || SHELL_DIR_RE.test(file)) return true;
358
+ let current = path.parentPath;
359
+ while (current) {
360
+ if (current.isJSXElement()) {
361
+ const tag = getJSXTagName(current.node.openingElement);
362
+ if (CHROME_ANCESTOR_TAGS.has(tag)) return true;
363
+ }
364
+ current = current.parentPath;
365
+ }
366
+ return false;
367
+ }
368
+ function computeContainerKind(path) {
369
+ const elPath = path.parentPath;
370
+ if (!elPath?.isJSXElement()) return "none";
371
+ const children = meaningfulChildren(t, elPath.node.children);
372
+ if (children.length === 0) return "none";
373
+ const allPlain = children.every((c) => t.isJSXElement(c) || t.isJSXText(c));
374
+ return allPlain ? "plain" : "expression";
375
+ }
376
+ function computeLockReason(isKitOrigin, isChrome, dynamicType, containerKind) {
377
+ if (isKitOrigin) return "KIT_INTERNAL";
378
+ if (isChrome) return "CHROME_STRUCTURAL";
379
+ if (dynamicType === "ARRAY") return "DYNAMIC_ARRAY";
380
+ if (dynamicType === "CONDITIONAL") return "DYNAMIC_CONDITIONAL";
381
+ if (containerKind === "expression") return "EXPRESSION_CONTAINER";
382
+ return void 0;
383
+ }
311
384
  function isMovable(path) {
312
385
  const elPath = path.parentPath;
313
386
  if (!elPath) return false;
@@ -325,6 +398,9 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
325
398
  while (ancestor) {
326
399
  if (ancestor.isJSXElement()) {
327
400
  const opening = ancestor.node.openingElement;
401
+ const parentVid = readVidAttr(opening.attributes);
402
+ if (parentVid) return parentVid;
403
+ if (!allowLegacyIds) return null;
328
404
  const loc = opening.loc?.start;
329
405
  if (loc) {
330
406
  const tag = getJSXTagName(opening);
@@ -951,7 +1027,9 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
951
1027
  return;
952
1028
  }
953
1029
  }
954
- const nodeId = computeNodeId(file, line, col, componentName);
1030
+ const vid = readVidAttr(path.node.attributes);
1031
+ if (!vid && !allowLegacyIds) return;
1032
+ const nodeId = vid ?? computeNodeId(file, line, col, componentName);
955
1033
  const isKitOrigin = origin === "kit" || hasSlotAttr;
956
1034
  const movable = isKitOrigin ? false : isMovable(path);
957
1035
  const parentNodeId = getParentNodeId(path, file);
@@ -973,6 +1051,24 @@ function babelPluginEditorMeta({ types: t }, opts = {}) {
973
1051
  parentNodeId ? t.stringLiteral(parentNodeId) : t.nullLiteral()
974
1052
  )
975
1053
  ]);
1054
+ if (vid) {
1055
+ const dynamicType = computeDynamicType(path);
1056
+ const isChrome = computeIsChrome(file, path);
1057
+ const containerKind = computeContainerKind(path);
1058
+ const lockReason = computeLockReason(isKitOrigin, isChrome, dynamicType, containerKind);
1059
+ metaObj.properties.push(
1060
+ t.objectProperty(t.identifier("vid"), t.stringLiteral(vid)),
1061
+ t.objectProperty(t.identifier("isKitOrigin"), t.booleanLiteral(isKitOrigin)),
1062
+ t.objectProperty(t.identifier("dynamicType"), t.stringLiteral(dynamicType)),
1063
+ t.objectProperty(t.identifier("isChrome"), t.booleanLiteral(isChrome)),
1064
+ t.objectProperty(t.identifier("containerKind"), t.stringLiteral(containerKind))
1065
+ );
1066
+ if (lockReason) {
1067
+ metaObj.properties.push(
1068
+ t.objectProperty(t.identifier("lockReason"), t.stringLiteral(lockReason))
1069
+ );
1070
+ }
1071
+ }
976
1072
  if (isKitOrigin) {
977
1073
  if (templateOrigin) {
978
1074
  metaObj.properties.push(
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __dirname,
3
3
  babelPluginEditorMeta
4
- } from "./chunk-P5XMHBFS.mjs";
4
+ } from "./chunk-THKKWDMJ.mjs";
5
5
 
6
6
  // src/index.ts
7
7
  import { readFileSync } from "fs";