@jbpark/live-editor 4.2.0 → 4.3.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.
Files changed (34) hide show
  1. package/dist/{ast-CMD20ykx.js → ast-BFbDWO-l.js} +198 -208
  2. package/dist/ast-BFbDWO-l.js.map +1 -0
  3. package/dist/{boundary-D2IFja-3.js → boundary-B17cepvm.js} +12 -9
  4. package/dist/boundary-B17cepvm.js.map +1 -0
  5. package/dist/dnd/index.d.ts +2 -2
  6. package/dist/dnd/index.js +2 -2
  7. package/dist/{dnd-DBaH2L8N.js → dnd-Z1KS16Fy.js} +462 -222
  8. package/dist/dnd-Z1KS16Fy.js.map +1 -0
  9. package/dist/{document-C3eCRQlj.js → document-cEEdFERz.js} +79 -20
  10. package/dist/document-cEEdFERz.js.map +1 -0
  11. package/dist/error/index.d.ts +1 -1
  12. package/dist/error/index.js +2 -2
  13. package/dist/{error-KW8XCcjH.js → error-DWhxQEom.js} +2 -2
  14. package/dist/{error-KW8XCcjH.js.map → error-DWhxQEom.js.map} +1 -1
  15. package/dist/{index-DNNj_0ba.d.ts → index-C4SGQ3Ci.d.ts} +4 -3
  16. package/dist/{index-DVgwXnPa.d.ts → index-CtlUYnWq.d.ts} +25 -3
  17. package/dist/index.d.ts +4 -4
  18. package/dist/index.js +3 -3
  19. package/dist/index.js.map +1 -1
  20. package/dist/preview/index.js +2 -2
  21. package/dist/{preview-B9Jhv1Up.js → preview-C_UzpGWh.js} +3 -3
  22. package/dist/{preview-B9Jhv1Up.js.map → preview-C_UzpGWh.js.map} +1 -1
  23. package/dist/{sections-A4TAXUP8.js → sections-GJQ63uEB.js} +2 -2
  24. package/dist/{sections-A4TAXUP8.js.map → sections-GJQ63uEB.js.map} +1 -1
  25. package/dist/{use-dynamic-tailwind-BDfytfYC.js → use-dynamic-tailwind-DpbjmATF.js} +5 -5
  26. package/dist/use-dynamic-tailwind-DpbjmATF.js.map +1 -0
  27. package/dist/utils/ast/index.js +2 -2
  28. package/dist/utils/index.js +2 -2
  29. package/package.json +1 -1
  30. package/dist/ast-CMD20ykx.js.map +0 -1
  31. package/dist/boundary-D2IFja-3.js.map +0 -1
  32. package/dist/dnd-DBaH2L8N.js.map +0 -1
  33. package/dist/document-C3eCRQlj.js.map +0 -1
  34. package/dist/use-dynamic-tailwind-BDfytfYC.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { i as DEFAULT_CONTAINER_ID, n as CONFIG, r as DATA_ATTR } from "./constants-CKvdqZtO.js";
1
+ import { i as DEFAULT_CONTAINER_ID, n as CONFIG, r as DATA_ATTR, s as REGEX } from "./constants-CKvdqZtO.js";
2
2
  import { n as registerEditorCache } from "./editor-caches-ClMvdcQF.js";
3
3
  import { t as createBoundedCache } from "./cache-B0-XcIxJ.js";
4
4
  //#region \0rolldown/runtime.js
@@ -32710,9 +32710,38 @@ var require_lib$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
32710
32710
  exports.default = generate;
32711
32711
  }));
32712
32712
  //#endregion
32713
+ //#region src/utils/ast/helpers.ts
32714
+ var import_lib$1 = /* @__PURE__ */ __toESM(require_lib$3(), 1);
32715
+ var import_lib$2 = require_lib$7();
32716
+ var import_lib$3 = /* @__PURE__ */ __toESM(require_lib$4(), 1);
32717
+ const generate = typeof import_lib$1.default === "function" ? import_lib$1.default : import_lib$1.default.default;
32718
+ const wrap = (code) => {
32719
+ return `<>${code}</>`;
32720
+ };
32721
+ const unwrap = (generated) => {
32722
+ return generated.replace(/^<>\s*/g, "").replace(/\s*<\/>\s*;?\s*$/g, "").trim();
32723
+ };
32724
+ const attrValue = ({ value, isStringLiteral }) => {
32725
+ if (value === null) return null;
32726
+ if (isStringLiteral) return import_lib$3.stringLiteral(value);
32727
+ const trimmed = value.trim();
32728
+ if (REGEX.NUMBER.test(trimmed)) return import_lib$3.jsxExpressionContainer(import_lib$3.numericLiteral(parseFloat(trimmed)));
32729
+ if (REGEX.BOOLEAN_OR_NULL.test(trimmed)) {
32730
+ const expr = (0, import_lib$2.parseExpression)(trimmed, { plugins: ["jsx", "typescript"] });
32731
+ return import_lib$3.jsxExpressionContainer(expr);
32732
+ }
32733
+ try {
32734
+ const expr = (0, import_lib$2.parseExpression)(trimmed, { plugins: ["jsx", "typescript"] });
32735
+ return import_lib$3.jsxExpressionContainer(expr);
32736
+ } catch {
32737
+ return import_lib$3.stringLiteral(trimmed);
32738
+ }
32739
+ };
32740
+ const generateCode = (node) => {
32741
+ return generate(node, { jsescOption: { minimal: true } }).code;
32742
+ };
32743
+ //#endregion
32713
32744
  //#region node_modules/.pnpm/nanoid@3.3.18/node_modules/nanoid/index.browser.js
32714
- var import_lib = require_lib$7();
32715
- var import_lib$2 = /* @__PURE__ */ __toESM(require_lib$4(), 1);
32716
32745
  let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
32717
32746
  byte &= 63;
32718
32747
  if (byte < 36) id += byte.toString(36);
@@ -38377,37 +38406,67 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports) => {
38377
38406
  }));
38378
38407
  //#endregion
38379
38408
  //#region src/utils/ast/jsx-name.ts
38380
- var import_lib$1 = /* @__PURE__ */ __toESM(require_lib(), 1);
38409
+ var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
38381
38410
  const getJSXTagName = (opening) => {
38382
- if (import_lib$2.isJSXIdentifier(opening.name)) return opening.name.name;
38383
- if (import_lib$2.isJSXMemberExpression(opening.name)) return resolveMemberName(opening.name);
38411
+ if (import_lib$3.isJSXIdentifier(opening.name)) return opening.name.name;
38412
+ if (import_lib$3.isJSXMemberExpression(opening.name)) return resolveMemberName(opening.name);
38384
38413
  return "";
38385
38414
  };
38386
38415
  const resolveMemberName = (expr) => {
38387
38416
  const parts = [];
38388
38417
  const collectMemberParts = (node) => {
38389
- if (import_lib$2.isJSXIdentifier(node)) parts.push(node.name);
38390
- else if (import_lib$2.isJSXMemberExpression(node)) {
38418
+ if (import_lib$3.isJSXIdentifier(node)) parts.push(node.name);
38419
+ else if (import_lib$3.isJSXMemberExpression(node)) {
38391
38420
  collectMemberParts(node.object);
38392
- if (import_lib$2.isJSXIdentifier(node.property)) parts.push(node.property.name);
38421
+ if (import_lib$3.isJSXIdentifier(node.property)) parts.push(node.property.name);
38393
38422
  }
38394
38423
  };
38395
38424
  collectMemberParts(expr.object);
38396
- if (import_lib$2.isJSXIdentifier(expr.property)) parts.push(expr.property.name);
38425
+ if (import_lib$3.isJSXIdentifier(expr.property)) parts.push(expr.property.name);
38397
38426
  return parts.join(".");
38398
38427
  };
38399
38428
  //#endregion
38429
+ //#region src/utils/ast/tree.ts
38430
+ const replaceIds = (code, generateId = () => nanoid(6)) => {
38431
+ return code.replace(new RegExp(`${DATA_ATTR.ID}="[^"]*"`, "g"), () => {
38432
+ return `${DATA_ATTR.ID}="${generateId()}"`;
38433
+ });
38434
+ };
38435
+ const fillIds = (code, generateId = () => nanoid(6)) => {
38436
+ return code.replace(new RegExp(`${DATA_ATTR.ID}=""`, "g"), () => {
38437
+ return `${DATA_ATTR.ID}="${generateId()}"`;
38438
+ });
38439
+ };
38440
+ const fillIdsFrom = (code, prefix) => {
38441
+ const taken = new Set(Array.from(code.matchAll(new RegExp(`${DATA_ATTR.ID}="([^"]*)"`, "g")), (match) => match[1]));
38442
+ let count = 0;
38443
+ return fillIds(code, () => {
38444
+ let id;
38445
+ do {
38446
+ count++;
38447
+ id = `${prefix}-${count}`;
38448
+ } while (taken.has(id));
38449
+ return id;
38450
+ });
38451
+ };
38452
+ const clone = (element, generateId = () => nanoid(6)) => {
38453
+ const cloned = import_lib$3.cloneNode(element, true);
38454
+ const generatedCode = generateCode(cloned);
38455
+ const code = replaceIds(generatedCode, generateId);
38456
+ return (0, import_lib$2.parseExpression)(code, { plugins: ["jsx", "typescript"] });
38457
+ };
38458
+ //#endregion
38400
38459
  //#region src/utils/ast/document.ts
38401
- const traverse = typeof import_lib$1.default === "function" ? import_lib$1.default : import_lib$1.default.default;
38460
+ const traverse = typeof import_lib.default === "function" ? import_lib.default : import_lib.default.default;
38402
38461
  const SECTION_TAG = "section";
38403
38462
  const DATA_NAME_ATTR = "data-name";
38404
38463
  const defaultSectionName = (index) => `Section ${index + 1}`;
38405
- const getAttr = (element, attrName) => element.openingElement.attributes.find((a) => import_lib$2.isJSXAttribute(a) && import_lib$2.isJSXIdentifier(a.name) && a.name.name === attrName);
38464
+ const getAttr = (element, attrName) => element.openingElement.attributes.find((a) => import_lib$3.isJSXAttribute(a) && import_lib$3.isJSXIdentifier(a.name) && a.name.name === attrName);
38406
38465
  const getAttrValue = (element, attrName) => {
38407
38466
  const attr = getAttr(element, attrName);
38408
- return attr && import_lib$2.isStringLiteral(attr.value) ? attr.value.value : void 0;
38467
+ return attr && import_lib$3.isStringLiteral(attr.value) ? attr.value.value : void 0;
38409
38468
  };
38410
- const isSectionElement = (node) => import_lib$2.isJSXElement(node) && getJSXTagName(node.openingElement) === SECTION_TAG;
38469
+ const isSectionElement = (node) => import_lib$3.isJSXElement(node) && getJSXTagName(node.openingElement) === SECTION_TAG;
38411
38470
  const findContainer = (ast, containerId) => {
38412
38471
  let container;
38413
38472
  traverse(ast, { JSXElement(path) {
@@ -38425,7 +38484,7 @@ const findOutermostSections = (children) => {
38425
38484
  sections.push(child);
38426
38485
  continue;
38427
38486
  }
38428
- if (import_lib$2.isJSXElement(child) || import_lib$2.isJSXFragment(child)) sections.push(...findOutermostSections(child.children));
38487
+ if (import_lib$3.isJSXElement(child) || import_lib$3.isJSXFragment(child)) sections.push(...findOutermostSections(child.children));
38429
38488
  }
38430
38489
  return sections;
38431
38490
  };
@@ -38433,7 +38492,7 @@ const documentCache = createBoundedCache(CONFIG.DOCUMENT_CACHE_LIMIT);
38433
38492
  const buildDocument = (code, containerId) => {
38434
38493
  let ast;
38435
38494
  try {
38436
- ast = (0, import_lib.parse)(code, {
38495
+ ast = (0, import_lib$2.parse)(code, {
38437
38496
  sourceType: "module",
38438
38497
  plugins: ["jsx", "typescript"]
38439
38498
  });
@@ -38487,7 +38546,7 @@ const fillSectionIds = (code, generateId = () => nanoid(6), options) => {
38487
38546
  const edits = [];
38488
38547
  findOutermostSections(doc.container.children).forEach((node) => {
38489
38548
  const attr = getAttr(node, DATA_ATTR.ID);
38490
- const id = attr && import_lib$2.isStringLiteral(attr.value) ? attr.value.value : void 0;
38549
+ const id = attr && import_lib$3.isStringLiteral(attr.value) ? attr.value.value : void 0;
38491
38550
  if (id && !seen.has(id)) {
38492
38551
  seen.add(id);
38493
38552
  return;
@@ -38584,7 +38643,7 @@ const createSectionPreviewCache = () => {
38584
38643
  nextPreviewsById.set(section.id, cached);
38585
38644
  return cached.preview;
38586
38645
  }
38587
- const preview = spliceCode(fullCode, span.start, span.end, section.code);
38646
+ const preview = spliceCode(fullCode, span.start, span.end, fillIdsFrom(section.code, section.id));
38588
38647
  nextPreviewsById.set(section.id, {
38589
38648
  code: section.code,
38590
38649
  preview
@@ -38599,6 +38658,6 @@ const createSectionPreviewCache = () => {
38599
38658
  return { compute };
38600
38659
  };
38601
38660
  //#endregion
38602
- export { __toESM as _, generateSectionPreview as a, inspectDocument as c, traverse as d, getJSXTagName as f, require_lib$7 as g, require_lib$4 as h, generateDocumentCode as i, parseDocument as l, require_lib$3 as m, createSectionPreviewCache as n, generateSectionPreviews as o, nanoid as p, fillSectionIds as r, getSections as s, clearDocumentParseCache as t, replaceDocumentSections as u };
38661
+ export { require_lib$7 as C, require_lib$4 as S, nanoid as _, generateSectionPreview as a, unwrap as b, inspectDocument as c, traverse as d, clone as f, getJSXTagName as g, replaceIds as h, generateDocumentCode as i, parseDocument as l, fillIdsFrom as m, createSectionPreviewCache as n, generateSectionPreviews as o, fillIds as p, fillSectionIds as r, getSections as s, clearDocumentParseCache as t, replaceDocumentSections as u, attrValue as v, __toESM as w, wrap as x, generateCode as y };
38603
38662
 
38604
- //# sourceMappingURL=document-C3eCRQlj.js.map
38663
+ //# sourceMappingURL=document-cEEdFERz.js.map