@jbpark/live-editor 4.1.1 → 4.2.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 (50) hide show
  1. package/README.ko.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/{ast-jab6hQrT.js → ast-CMD20ykx.js} +94 -25
  4. package/dist/ast-CMD20ykx.js.map +1 -0
  5. package/dist/{compile-CBOAtQMz.js → compile-0Dvp8zp5.js} +37 -5
  6. package/dist/compile-0Dvp8zp5.js.map +1 -0
  7. package/dist/{constants-BD3FZKWE.js → constants-CKvdqZtO.js} +11 -4
  8. package/dist/constants-CKvdqZtO.js.map +1 -0
  9. package/dist/{context-DQ-UtoyS.js → context-93X3gyfJ.js} +2 -2
  10. package/dist/{context-DQ-UtoyS.js.map → context-93X3gyfJ.js.map} +1 -1
  11. package/dist/{core-DaXVtvH5.js → core-B3ruccKb.js} +2 -2
  12. package/dist/{core-DaXVtvH5.js.map → core-B3ruccKb.js.map} +1 -1
  13. package/dist/{detect-typescript-b0A751v2.js → detect-typescript-5MV4mCM7.js} +2 -2
  14. package/dist/{detect-typescript-b0A751v2.js.map → detect-typescript-5MV4mCM7.js.map} +1 -1
  15. package/dist/dnd/index.d.ts +2 -2
  16. package/dist/dnd/index.js +2 -2
  17. package/dist/{dnd-CMrXfD8O.js → dnd-DBaH2L8N.js} +545 -138
  18. package/dist/dnd-DBaH2L8N.js.map +1 -0
  19. package/dist/{document-C5Dypv4_.js → document-C3eCRQlj.js} +71 -38
  20. package/dist/document-C3eCRQlj.js.map +1 -0
  21. package/dist/{document-J9Lo9p81.d.ts → document-Ct4jW78J.d.ts} +42 -22
  22. package/dist/editor/index.js +2 -2
  23. package/dist/{editor-C3tQaMlU.js → editor-DvMruljw.js} +2 -2
  24. package/dist/{editor-C3tQaMlU.js.map → editor-DvMruljw.js.map} +1 -1
  25. package/dist/{index-C4t0OawE.d.ts → index-DVgwXnPa.d.ts} +109 -34
  26. package/dist/{index-B_p74BRM.d.ts → index-w3kLcCXl.d.ts} +29 -5
  27. package/dist/index.d.ts +4 -4
  28. package/dist/index.js +4 -4
  29. package/dist/index.js.map +1 -1
  30. package/dist/preview/index.js +2 -2
  31. package/dist/{preview-BwEfltgi.js → preview-B9Jhv1Up.js} +2 -2
  32. package/dist/{preview-BwEfltgi.js.map → preview-B9Jhv1Up.js.map} +1 -1
  33. package/dist/provider/index.js +1 -1
  34. package/dist/sections-A4TAXUP8.js +24 -0
  35. package/dist/sections-A4TAXUP8.js.map +1 -0
  36. package/dist/{use-dynamic-tailwind-DuGLeDR3.js → use-dynamic-tailwind-BDfytfYC.js} +16 -7
  37. package/dist/use-dynamic-tailwind-BDfytfYC.js.map +1 -0
  38. package/dist/utils/ast/index.d.ts +3 -3
  39. package/dist/utils/ast/index.js +3 -3
  40. package/dist/utils/index.d.ts +7 -6
  41. package/dist/utils/index.js +5 -5
  42. package/package.json +1 -1
  43. package/dist/ast-jab6hQrT.js.map +0 -1
  44. package/dist/compile-CBOAtQMz.js.map +0 -1
  45. package/dist/constants-BD3FZKWE.js.map +0 -1
  46. package/dist/dnd-CMrXfD8O.js.map +0 -1
  47. package/dist/document-C5Dypv4_.js.map +0 -1
  48. package/dist/sections-B7dWoNVJ.js +0 -19
  49. package/dist/sections-B7dWoNVJ.js.map +0 -1
  50. package/dist/use-dynamic-tailwind-DuGLeDR3.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { n as CONFIG, r as DATA_ATTR } from "./constants-BD3FZKWE.js";
1
+ import { i as DEFAULT_CONTAINER_ID, n as CONFIG, r as DATA_ATTR } 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
@@ -38376,26 +38376,42 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports) => {
38376
38376
  traverse.cache = cache;
38377
38377
  }));
38378
38378
  //#endregion
38379
- //#region src/utils/ast/document.ts
38379
+ //#region src/utils/ast/jsx-name.ts
38380
38380
  var import_lib$1 = /* @__PURE__ */ __toESM(require_lib(), 1);
38381
+ 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);
38384
+ return "";
38385
+ };
38386
+ const resolveMemberName = (expr) => {
38387
+ const parts = [];
38388
+ const collectMemberParts = (node) => {
38389
+ if (import_lib$2.isJSXIdentifier(node)) parts.push(node.name);
38390
+ else if (import_lib$2.isJSXMemberExpression(node)) {
38391
+ collectMemberParts(node.object);
38392
+ if (import_lib$2.isJSXIdentifier(node.property)) parts.push(node.property.name);
38393
+ }
38394
+ };
38395
+ collectMemberParts(expr.object);
38396
+ if (import_lib$2.isJSXIdentifier(expr.property)) parts.push(expr.property.name);
38397
+ return parts.join(".");
38398
+ };
38399
+ //#endregion
38400
+ //#region src/utils/ast/document.ts
38381
38401
  const traverse = typeof import_lib$1.default === "function" ? import_lib$1.default : import_lib$1.default.default;
38382
- const APP_CONTAINER_ID = "app-container";
38383
38402
  const SECTION_TAG = "section";
38384
38403
  const DATA_NAME_ATTR = "data-name";
38385
- const getTagName = (element) => {
38386
- const name = element.openingElement.name;
38387
- return import_lib$2.isJSXIdentifier(name) ? name.name : "";
38388
- };
38404
+ const defaultSectionName = (index) => `Section ${index + 1}`;
38389
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);
38390
38406
  const getAttrValue = (element, attrName) => {
38391
38407
  const attr = getAttr(element, attrName);
38392
38408
  return attr && import_lib$2.isStringLiteral(attr.value) ? attr.value.value : void 0;
38393
38409
  };
38394
- const isSectionElement = (node) => import_lib$2.isJSXElement(node) && getTagName(node) === SECTION_TAG;
38395
- const findContainer = (ast) => {
38410
+ const isSectionElement = (node) => import_lib$2.isJSXElement(node) && getJSXTagName(node.openingElement) === SECTION_TAG;
38411
+ const findContainer = (ast, containerId) => {
38396
38412
  let container;
38397
38413
  traverse(ast, { JSXElement(path) {
38398
- if (getAttrValue(path.node, "id") === APP_CONTAINER_ID) {
38414
+ if (getAttrValue(path.node, "id") === containerId) {
38399
38415
  container = path.node;
38400
38416
  path.stop();
38401
38417
  }
@@ -38414,41 +38430,58 @@ const findOutermostSections = (children) => {
38414
38430
  return sections;
38415
38431
  };
38416
38432
  const documentCache = createBoundedCache(CONFIG.DOCUMENT_CACHE_LIMIT);
38417
- const buildDocument = (code) => {
38433
+ const buildDocument = (code, containerId) => {
38434
+ let ast;
38418
38435
  try {
38419
- const ast = (0, import_lib.parse)(code, {
38436
+ ast = (0, import_lib.parse)(code, {
38420
38437
  sourceType: "module",
38421
38438
  plugins: ["jsx", "typescript"]
38422
38439
  });
38423
- const container = findContainer(ast);
38424
- return container ? {
38440
+ } catch (error) {
38441
+ console.warn("⚠️ Failed to parse document", error);
38442
+ return {
38443
+ ok: false,
38444
+ reason: "parse-error",
38445
+ error
38446
+ };
38447
+ }
38448
+ const container = findContainer(ast, containerId);
38449
+ return container ? {
38450
+ ok: true,
38451
+ doc: {
38425
38452
  code,
38426
38453
  ast,
38427
38454
  container
38428
- } : void 0;
38429
- } catch (e) {
38430
- console.warn("⚠️ Failed to parse document", e);
38431
- return;
38432
- }
38455
+ }
38456
+ } : {
38457
+ ok: false,
38458
+ reason: "container-not-found",
38459
+ containerId
38460
+ };
38461
+ };
38462
+ const inspectDocument = (code, { containerId = DEFAULT_CONTAINER_ID } = {}) => {
38463
+ const key = `${containerId}\0${code}`;
38464
+ const cached = documentCache.get(key);
38465
+ if (cached) return cached;
38466
+ const inspection = buildDocument(code, containerId);
38467
+ documentCache.set(key, inspection);
38468
+ return inspection;
38433
38469
  };
38434
- const parseDocument = (code) => {
38435
- const cached = documentCache.get(code);
38436
- if (cached !== void 0) return cached ?? void 0;
38437
- const doc = buildDocument(code);
38438
- documentCache.set(code, doc ?? null);
38439
- return doc;
38470
+ const parseDocument = (code, options) => {
38471
+ const inspection = inspectDocument(code, options);
38472
+ return inspection.ok ? inspection.doc : void 0;
38440
38473
  };
38441
38474
  const clearDocumentParseCache = () => {
38442
38475
  documentCache.clear();
38443
38476
  };
38444
38477
  registerEditorCache(clearDocumentParseCache);
38445
- const getSections = (doc) => findOutermostSections(doc.container.children).map((node, index) => ({
38478
+ const getSections = (doc, { sectionNameFallback = defaultSectionName } = {}) => findOutermostSections(doc.container.children).map((node, index) => ({
38446
38479
  id: getAttrValue(node, DATA_ATTR.ID) || `${index}`,
38447
- name: getAttrValue(node, DATA_NAME_ATTR) || `${index + 1}번째 컴포넌트`,
38480
+ name: getAttrValue(node, DATA_NAME_ATTR) || sectionNameFallback(index),
38448
38481
  code: doc.code.slice(node.start, node.end)
38449
38482
  }));
38450
- const fillSectionIds = (code, generateId = () => nanoid(6)) => {
38451
- const doc = parseDocument(code);
38483
+ const fillSectionIds = (code, generateId = () => nanoid(6), options) => {
38484
+ const doc = parseDocument(code, options);
38452
38485
  if (!doc) return code;
38453
38486
  const seen = /* @__PURE__ */ new Set();
38454
38487
  const edits = [];
@@ -38494,8 +38527,8 @@ const commonSuffixLength = (a, b, limit) => {
38494
38527
  while (i < limit && a[a.length - 1 - i] === b[b.length - 1 - i]) i++;
38495
38528
  return i;
38496
38529
  };
38497
- const replaceDocumentSections = (fullCode, sectionCodes) => {
38498
- const doc = parseDocument(fullCode);
38530
+ const replaceDocumentSections = (fullCode, sectionCodes, options) => {
38531
+ const doc = parseDocument(fullCode, options);
38499
38532
  if (!doc) return fullCode;
38500
38533
  const sections = findOutermostSections(doc.container.children);
38501
38534
  if (sections.length === 0) {
@@ -38521,9 +38554,9 @@ const replaceDocumentSections = (fullCode, sectionCodes) => {
38521
38554
  const end = sections[oldChangedEndExclusive - 1].end;
38522
38555
  return spliceCode(fullCode, start, end, newChanged.join("\n"));
38523
38556
  };
38524
- const generateSectionPreview = (fullCode, sectionCode) => generateSectionPreviews(fullCode, [sectionCode])[0];
38525
- const generateSectionPreviews = (fullCode, sectionCodes) => {
38526
- const doc = parseDocument(fullCode);
38557
+ const generateSectionPreview = (fullCode, sectionCode, options) => generateSectionPreviews(fullCode, [sectionCode], options)[0];
38558
+ const generateSectionPreviews = (fullCode, sectionCodes, options) => {
38559
+ const doc = parseDocument(fullCode, options);
38527
38560
  const span = doc && getContainerInnerSpan(doc.container);
38528
38561
  if (!span) return sectionCodes.map(() => fullCode);
38529
38562
  return sectionCodes.map((sectionCode) => spliceCode(fullCode, span.start, span.end, sectionCode));
@@ -38532,8 +38565,8 @@ const createSectionPreviewCache = () => {
38532
38565
  let containerPrefix = null;
38533
38566
  let containerSuffix = null;
38534
38567
  let previewsById = /* @__PURE__ */ new Map();
38535
- const compute = (fullCode, sections) => {
38536
- const doc = parseDocument(fullCode);
38568
+ const compute = (fullCode, sections, options) => {
38569
+ const doc = parseDocument(fullCode, options);
38537
38570
  const span = doc && getContainerInnerSpan(doc.container);
38538
38571
  if (!span) {
38539
38572
  containerPrefix = null;
@@ -38566,6 +38599,6 @@ const createSectionPreviewCache = () => {
38566
38599
  return { compute };
38567
38600
  };
38568
38601
  //#endregion
38569
- export { generateSectionPreview as a, parseDocument as c, nanoid as d, require_lib$3 as f, __toESM as h, generateDocumentCode as i, replaceDocumentSections as l, require_lib$7 as m, createSectionPreviewCache as n, generateSectionPreviews as o, require_lib$4 as p, fillSectionIds as r, getSections as s, clearDocumentParseCache as t, traverse as u };
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 };
38570
38603
 
38571
- //# sourceMappingURL=document-C5Dypv4_.js.map
38604
+ //# sourceMappingURL=document-C3eCRQlj.js.map