@jbpark/live-editor 4.1.1 → 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.
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/dist/{ast-jab6hQrT.js → ast-BFbDWO-l.js} +288 -229
- package/dist/ast-BFbDWO-l.js.map +1 -0
- package/dist/{boundary-D2IFja-3.js → boundary-B17cepvm.js} +12 -9
- package/dist/boundary-B17cepvm.js.map +1 -0
- package/dist/{compile-CBOAtQMz.js → compile-0Dvp8zp5.js} +37 -5
- package/dist/compile-0Dvp8zp5.js.map +1 -0
- package/dist/{constants-BD3FZKWE.js → constants-CKvdqZtO.js} +11 -4
- package/dist/constants-CKvdqZtO.js.map +1 -0
- package/dist/{context-DQ-UtoyS.js → context-93X3gyfJ.js} +2 -2
- package/dist/{context-DQ-UtoyS.js.map → context-93X3gyfJ.js.map} +1 -1
- package/dist/{core-DaXVtvH5.js → core-B3ruccKb.js} +2 -2
- package/dist/{core-DaXVtvH5.js.map → core-B3ruccKb.js.map} +1 -1
- package/dist/{detect-typescript-b0A751v2.js → detect-typescript-5MV4mCM7.js} +2 -2
- package/dist/{detect-typescript-b0A751v2.js.map → detect-typescript-5MV4mCM7.js.map} +1 -1
- package/dist/dnd/index.d.ts +2 -2
- package/dist/dnd/index.js +2 -2
- package/dist/{dnd-CMrXfD8O.js → dnd-Z1KS16Fy.js} +969 -322
- package/dist/dnd-Z1KS16Fy.js.map +1 -0
- package/dist/{document-J9Lo9p81.d.ts → document-Ct4jW78J.d.ts} +42 -22
- package/dist/{document-C5Dypv4_.js → document-cEEdFERz.js} +138 -46
- package/dist/document-cEEdFERz.js.map +1 -0
- package/dist/editor/index.js +2 -2
- package/dist/{editor-C3tQaMlU.js → editor-DvMruljw.js} +2 -2
- package/dist/{editor-C3tQaMlU.js.map → editor-DvMruljw.js.map} +1 -1
- package/dist/error/index.d.ts +1 -1
- package/dist/error/index.js +2 -2
- package/dist/{error-KW8XCcjH.js → error-DWhxQEom.js} +2 -2
- package/dist/{error-KW8XCcjH.js.map → error-DWhxQEom.js.map} +1 -1
- package/dist/{index-DNNj_0ba.d.ts → index-C4SGQ3Ci.d.ts} +4 -3
- package/dist/{index-C4t0OawE.d.ts → index-CtlUYnWq.d.ts} +131 -34
- package/dist/{index-B_p74BRM.d.ts → index-w3kLcCXl.d.ts} +29 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/preview/index.js +2 -2
- package/dist/{preview-BwEfltgi.js → preview-C_UzpGWh.js} +3 -3
- package/dist/{preview-BwEfltgi.js.map → preview-C_UzpGWh.js.map} +1 -1
- package/dist/provider/index.js +1 -1
- package/dist/sections-GJQ63uEB.js +24 -0
- package/dist/sections-GJQ63uEB.js.map +1 -0
- package/dist/{use-dynamic-tailwind-DuGLeDR3.js → use-dynamic-tailwind-DpbjmATF.js} +20 -11
- package/dist/use-dynamic-tailwind-DpbjmATF.js.map +1 -0
- package/dist/utils/ast/index.d.ts +3 -3
- package/dist/utils/ast/index.js +3 -3
- package/dist/utils/index.d.ts +7 -6
- package/dist/utils/index.js +5 -5
- package/package.json +1 -1
- package/dist/ast-jab6hQrT.js.map +0 -1
- package/dist/boundary-D2IFja-3.js.map +0 -1
- package/dist/compile-CBOAtQMz.js.map +0 -1
- package/dist/constants-BD3FZKWE.js.map +0 -1
- package/dist/dnd-CMrXfD8O.js.map +0 -1
- package/dist/document-C5Dypv4_.js.map +0 -1
- package/dist/sections-B7dWoNVJ.js +0 -19
- package/dist/sections-B7dWoNVJ.js.map +0 -1
- package/dist/use-dynamic-tailwind-DuGLeDR3.js.map +0 -1
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
//#region src/types/index.d.ts
|
|
2
|
-
interface Module {
|
|
3
|
-
exports: {
|
|
4
|
-
default?: React.ComponentType<Record<string, unknown>>;
|
|
5
|
-
};
|
|
6
|
-
error?: string;
|
|
7
|
-
}
|
|
8
|
-
interface Section {
|
|
9
|
-
id: string;
|
|
10
|
-
name: string;
|
|
11
|
-
code: string;
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
1
|
//#region node_modules/.pnpm/@babel+types@7.29.8/node_modules/@babel/types/lib/index-legacy.d.ts
|
|
15
2
|
// NOTE: This file is autogenerated. Do not modify.
|
|
16
3
|
// See packages/babel-types/scripts/generators/typescript-legacy.ts for script used.
|
|
@@ -1507,27 +1494,60 @@ type TSType = TSAnyKeyword | TSBooleanKeyword | TSBigIntKeyword | TSIntrinsicKey
|
|
|
1507
1494
|
type TSBaseType = TSAnyKeyword | TSBooleanKeyword | TSBigIntKeyword | TSIntrinsicKeyword | TSNeverKeyword | TSNullKeyword | TSNumberKeyword | TSObjectKeyword | TSStringKeyword | TSSymbolKeyword | TSUndefinedKeyword | TSUnknownKeyword | TSVoidKeyword | TSThisType | TSTemplateLiteralType | TSLiteralType;
|
|
1508
1495
|
type ModuleDeclaration = ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration | ImportDeclaration;
|
|
1509
1496
|
//#endregion
|
|
1497
|
+
//#region src/types/index.d.ts
|
|
1498
|
+
interface Module {
|
|
1499
|
+
exports: {
|
|
1500
|
+
default?: React.ComponentType<Record<string, unknown>>;
|
|
1501
|
+
};
|
|
1502
|
+
error?: string;
|
|
1503
|
+
}
|
|
1504
|
+
interface Section {
|
|
1505
|
+
id: string;
|
|
1506
|
+
name: string;
|
|
1507
|
+
code: string;
|
|
1508
|
+
}
|
|
1509
|
+
//#endregion
|
|
1510
1510
|
//#region src/utils/ast/document.d.ts
|
|
1511
|
+
interface DocumentOptions {
|
|
1512
|
+
containerId?: string;
|
|
1513
|
+
}
|
|
1514
|
+
interface SectionOptions extends DocumentOptions {
|
|
1515
|
+
sectionNameFallback?: (index: number) => string;
|
|
1516
|
+
}
|
|
1517
|
+
type DocumentProblem = {
|
|
1518
|
+
reason: 'parse-error';
|
|
1519
|
+
error: unknown;
|
|
1520
|
+
} | {
|
|
1521
|
+
reason: 'container-not-found';
|
|
1522
|
+
containerId: string;
|
|
1523
|
+
};
|
|
1524
|
+
type DocumentInspection = {
|
|
1525
|
+
ok: true;
|
|
1526
|
+
doc: DocumentTree;
|
|
1527
|
+
} | ({
|
|
1528
|
+
ok: false;
|
|
1529
|
+
} & DocumentProblem);
|
|
1511
1530
|
interface DocumentTree {
|
|
1512
1531
|
code: string;
|
|
1513
1532
|
ast: File;
|
|
1514
1533
|
container: JSXElement;
|
|
1515
1534
|
}
|
|
1516
|
-
declare const
|
|
1535
|
+
declare const inspectDocument: (code: string, { containerId }?: DocumentOptions) => DocumentInspection;
|
|
1536
|
+
declare const parseDocument: (code: string, options?: DocumentOptions) => DocumentTree | undefined;
|
|
1517
1537
|
declare const clearDocumentParseCache: () => void;
|
|
1518
|
-
declare const getSections: (doc: DocumentTree) => Section[];
|
|
1519
|
-
declare const fillSectionIds: (code: string, generateId?: () => string) => string;
|
|
1538
|
+
declare const getSections: (doc: DocumentTree, { sectionNameFallback }?: SectionOptions) => Section[];
|
|
1539
|
+
declare const fillSectionIds: (code: string, generateId?: () => string, options?: DocumentOptions) => string;
|
|
1520
1540
|
declare const generateDocumentCode: (doc: DocumentTree) => string;
|
|
1521
|
-
declare const replaceDocumentSections: (fullCode: string, sectionCodes: string[]) => string;
|
|
1522
|
-
declare const generateSectionPreview: (fullCode: string, sectionCode: string) => string;
|
|
1523
|
-
declare const generateSectionPreviews: (fullCode: string, sectionCodes: string[]) => string[];
|
|
1541
|
+
declare const replaceDocumentSections: (fullCode: string, sectionCodes: string[], options?: DocumentOptions) => string;
|
|
1542
|
+
declare const generateSectionPreview: (fullCode: string, sectionCode: string, options?: DocumentOptions) => string;
|
|
1543
|
+
declare const generateSectionPreviews: (fullCode: string, sectionCodes: string[], options?: DocumentOptions) => string[];
|
|
1524
1544
|
interface SectionPreviewCache {
|
|
1525
1545
|
compute: (fullCode: string, sections: {
|
|
1526
1546
|
id: string;
|
|
1527
1547
|
code: string;
|
|
1528
|
-
}[]) => string[];
|
|
1548
|
+
}[], options?: DocumentOptions) => string[];
|
|
1529
1549
|
}
|
|
1530
1550
|
declare const createSectionPreviewCache: () => SectionPreviewCache;
|
|
1531
1551
|
//#endregion
|
|
1532
|
-
export { Module as _,
|
|
1533
|
-
//# sourceMappingURL=document-
|
|
1552
|
+
export { ObjectExpression as C, Node as S, Module as _, SectionOptions as a, Expression as b, createSectionPreviewCache as c, generateSectionPreview as d, generateSectionPreviews as f, replaceDocumentSections as g, parseDocument as h, DocumentTree as i, fillSectionIds as l, inspectDocument as m, DocumentOptions as n, SectionPreviewCache as o, getSections as p, DocumentProblem as r, clearDocumentParseCache as s, DocumentInspection as t, generateDocumentCode as u, Section as v, File as x, ArrayExpression as y };
|
|
1553
|
+
//# sourceMappingURL=document-Ct4jW78J.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as CONFIG, r as DATA_ATTR } from "./constants-
|
|
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);
|
|
@@ -38376,26 +38405,72 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
38376
38405
|
traverse.cache = cache;
|
|
38377
38406
|
}));
|
|
38378
38407
|
//#endregion
|
|
38408
|
+
//#region src/utils/ast/jsx-name.ts
|
|
38409
|
+
var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
38410
|
+
const getJSXTagName = (opening) => {
|
|
38411
|
+
if (import_lib$3.isJSXIdentifier(opening.name)) return opening.name.name;
|
|
38412
|
+
if (import_lib$3.isJSXMemberExpression(opening.name)) return resolveMemberName(opening.name);
|
|
38413
|
+
return "";
|
|
38414
|
+
};
|
|
38415
|
+
const resolveMemberName = (expr) => {
|
|
38416
|
+
const parts = [];
|
|
38417
|
+
const collectMemberParts = (node) => {
|
|
38418
|
+
if (import_lib$3.isJSXIdentifier(node)) parts.push(node.name);
|
|
38419
|
+
else if (import_lib$3.isJSXMemberExpression(node)) {
|
|
38420
|
+
collectMemberParts(node.object);
|
|
38421
|
+
if (import_lib$3.isJSXIdentifier(node.property)) parts.push(node.property.name);
|
|
38422
|
+
}
|
|
38423
|
+
};
|
|
38424
|
+
collectMemberParts(expr.object);
|
|
38425
|
+
if (import_lib$3.isJSXIdentifier(expr.property)) parts.push(expr.property.name);
|
|
38426
|
+
return parts.join(".");
|
|
38427
|
+
};
|
|
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
|
|
38379
38459
|
//#region src/utils/ast/document.ts
|
|
38380
|
-
|
|
38381
|
-
const traverse = typeof import_lib$1.default === "function" ? import_lib$1.default : import_lib$1.default.default;
|
|
38382
|
-
const APP_CONTAINER_ID = "app-container";
|
|
38460
|
+
const traverse = typeof import_lib.default === "function" ? import_lib.default : import_lib.default.default;
|
|
38383
38461
|
const SECTION_TAG = "section";
|
|
38384
38462
|
const DATA_NAME_ATTR = "data-name";
|
|
38385
|
-
const
|
|
38386
|
-
|
|
38387
|
-
return import_lib$2.isJSXIdentifier(name) ? name.name : "";
|
|
38388
|
-
};
|
|
38389
|
-
const getAttr = (element, attrName) => element.openingElement.attributes.find((a) => import_lib$2.isJSXAttribute(a) && import_lib$2.isJSXIdentifier(a.name) && a.name.name === attrName);
|
|
38463
|
+
const defaultSectionName = (index) => `Section ${index + 1}`;
|
|
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);
|
|
38390
38465
|
const getAttrValue = (element, attrName) => {
|
|
38391
38466
|
const attr = getAttr(element, attrName);
|
|
38392
|
-
return attr && import_lib$
|
|
38467
|
+
return attr && import_lib$3.isStringLiteral(attr.value) ? attr.value.value : void 0;
|
|
38393
38468
|
};
|
|
38394
|
-
const isSectionElement = (node) => import_lib$
|
|
38395
|
-
const findContainer = (ast) => {
|
|
38469
|
+
const isSectionElement = (node) => import_lib$3.isJSXElement(node) && getJSXTagName(node.openingElement) === SECTION_TAG;
|
|
38470
|
+
const findContainer = (ast, containerId) => {
|
|
38396
38471
|
let container;
|
|
38397
38472
|
traverse(ast, { JSXElement(path) {
|
|
38398
|
-
if (getAttrValue(path.node, "id") ===
|
|
38473
|
+
if (getAttrValue(path.node, "id") === containerId) {
|
|
38399
38474
|
container = path.node;
|
|
38400
38475
|
path.stop();
|
|
38401
38476
|
}
|
|
@@ -38409,52 +38484,69 @@ const findOutermostSections = (children) => {
|
|
|
38409
38484
|
sections.push(child);
|
|
38410
38485
|
continue;
|
|
38411
38486
|
}
|
|
38412
|
-
if (import_lib$
|
|
38487
|
+
if (import_lib$3.isJSXElement(child) || import_lib$3.isJSXFragment(child)) sections.push(...findOutermostSections(child.children));
|
|
38413
38488
|
}
|
|
38414
38489
|
return sections;
|
|
38415
38490
|
};
|
|
38416
38491
|
const documentCache = createBoundedCache(CONFIG.DOCUMENT_CACHE_LIMIT);
|
|
38417
|
-
const buildDocument = (code) => {
|
|
38492
|
+
const buildDocument = (code, containerId) => {
|
|
38493
|
+
let ast;
|
|
38418
38494
|
try {
|
|
38419
|
-
|
|
38495
|
+
ast = (0, import_lib$2.parse)(code, {
|
|
38420
38496
|
sourceType: "module",
|
|
38421
38497
|
plugins: ["jsx", "typescript"]
|
|
38422
38498
|
});
|
|
38423
|
-
|
|
38424
|
-
|
|
38499
|
+
} catch (error) {
|
|
38500
|
+
console.warn("⚠️ Failed to parse document", error);
|
|
38501
|
+
return {
|
|
38502
|
+
ok: false,
|
|
38503
|
+
reason: "parse-error",
|
|
38504
|
+
error
|
|
38505
|
+
};
|
|
38506
|
+
}
|
|
38507
|
+
const container = findContainer(ast, containerId);
|
|
38508
|
+
return container ? {
|
|
38509
|
+
ok: true,
|
|
38510
|
+
doc: {
|
|
38425
38511
|
code,
|
|
38426
38512
|
ast,
|
|
38427
38513
|
container
|
|
38428
|
-
}
|
|
38429
|
-
}
|
|
38430
|
-
|
|
38431
|
-
|
|
38432
|
-
|
|
38514
|
+
}
|
|
38515
|
+
} : {
|
|
38516
|
+
ok: false,
|
|
38517
|
+
reason: "container-not-found",
|
|
38518
|
+
containerId
|
|
38519
|
+
};
|
|
38520
|
+
};
|
|
38521
|
+
const inspectDocument = (code, { containerId = DEFAULT_CONTAINER_ID } = {}) => {
|
|
38522
|
+
const key = `${containerId}\0${code}`;
|
|
38523
|
+
const cached = documentCache.get(key);
|
|
38524
|
+
if (cached) return cached;
|
|
38525
|
+
const inspection = buildDocument(code, containerId);
|
|
38526
|
+
documentCache.set(key, inspection);
|
|
38527
|
+
return inspection;
|
|
38433
38528
|
};
|
|
38434
|
-
const parseDocument = (code) => {
|
|
38435
|
-
const
|
|
38436
|
-
|
|
38437
|
-
const doc = buildDocument(code);
|
|
38438
|
-
documentCache.set(code, doc ?? null);
|
|
38439
|
-
return doc;
|
|
38529
|
+
const parseDocument = (code, options) => {
|
|
38530
|
+
const inspection = inspectDocument(code, options);
|
|
38531
|
+
return inspection.ok ? inspection.doc : void 0;
|
|
38440
38532
|
};
|
|
38441
38533
|
const clearDocumentParseCache = () => {
|
|
38442
38534
|
documentCache.clear();
|
|
38443
38535
|
};
|
|
38444
38536
|
registerEditorCache(clearDocumentParseCache);
|
|
38445
|
-
const getSections = (doc) => findOutermostSections(doc.container.children).map((node, index) => ({
|
|
38537
|
+
const getSections = (doc, { sectionNameFallback = defaultSectionName } = {}) => findOutermostSections(doc.container.children).map((node, index) => ({
|
|
38446
38538
|
id: getAttrValue(node, DATA_ATTR.ID) || `${index}`,
|
|
38447
|
-
name: getAttrValue(node, DATA_NAME_ATTR) ||
|
|
38539
|
+
name: getAttrValue(node, DATA_NAME_ATTR) || sectionNameFallback(index),
|
|
38448
38540
|
code: doc.code.slice(node.start, node.end)
|
|
38449
38541
|
}));
|
|
38450
|
-
const fillSectionIds = (code, generateId = () => nanoid(6)) => {
|
|
38451
|
-
const doc = parseDocument(code);
|
|
38542
|
+
const fillSectionIds = (code, generateId = () => nanoid(6), options) => {
|
|
38543
|
+
const doc = parseDocument(code, options);
|
|
38452
38544
|
if (!doc) return code;
|
|
38453
38545
|
const seen = /* @__PURE__ */ new Set();
|
|
38454
38546
|
const edits = [];
|
|
38455
38547
|
findOutermostSections(doc.container.children).forEach((node) => {
|
|
38456
38548
|
const attr = getAttr(node, DATA_ATTR.ID);
|
|
38457
|
-
const id = attr && import_lib$
|
|
38549
|
+
const id = attr && import_lib$3.isStringLiteral(attr.value) ? attr.value.value : void 0;
|
|
38458
38550
|
if (id && !seen.has(id)) {
|
|
38459
38551
|
seen.add(id);
|
|
38460
38552
|
return;
|
|
@@ -38494,8 +38586,8 @@ const commonSuffixLength = (a, b, limit) => {
|
|
|
38494
38586
|
while (i < limit && a[a.length - 1 - i] === b[b.length - 1 - i]) i++;
|
|
38495
38587
|
return i;
|
|
38496
38588
|
};
|
|
38497
|
-
const replaceDocumentSections = (fullCode, sectionCodes) => {
|
|
38498
|
-
const doc = parseDocument(fullCode);
|
|
38589
|
+
const replaceDocumentSections = (fullCode, sectionCodes, options) => {
|
|
38590
|
+
const doc = parseDocument(fullCode, options);
|
|
38499
38591
|
if (!doc) return fullCode;
|
|
38500
38592
|
const sections = findOutermostSections(doc.container.children);
|
|
38501
38593
|
if (sections.length === 0) {
|
|
@@ -38521,9 +38613,9 @@ const replaceDocumentSections = (fullCode, sectionCodes) => {
|
|
|
38521
38613
|
const end = sections[oldChangedEndExclusive - 1].end;
|
|
38522
38614
|
return spliceCode(fullCode, start, end, newChanged.join("\n"));
|
|
38523
38615
|
};
|
|
38524
|
-
const generateSectionPreview = (fullCode, sectionCode) => generateSectionPreviews(fullCode, [sectionCode])[0];
|
|
38525
|
-
const generateSectionPreviews = (fullCode, sectionCodes) => {
|
|
38526
|
-
const doc = parseDocument(fullCode);
|
|
38616
|
+
const generateSectionPreview = (fullCode, sectionCode, options) => generateSectionPreviews(fullCode, [sectionCode], options)[0];
|
|
38617
|
+
const generateSectionPreviews = (fullCode, sectionCodes, options) => {
|
|
38618
|
+
const doc = parseDocument(fullCode, options);
|
|
38527
38619
|
const span = doc && getContainerInnerSpan(doc.container);
|
|
38528
38620
|
if (!span) return sectionCodes.map(() => fullCode);
|
|
38529
38621
|
return sectionCodes.map((sectionCode) => spliceCode(fullCode, span.start, span.end, sectionCode));
|
|
@@ -38532,8 +38624,8 @@ const createSectionPreviewCache = () => {
|
|
|
38532
38624
|
let containerPrefix = null;
|
|
38533
38625
|
let containerSuffix = null;
|
|
38534
38626
|
let previewsById = /* @__PURE__ */ new Map();
|
|
38535
|
-
const compute = (fullCode, sections) => {
|
|
38536
|
-
const doc = parseDocument(fullCode);
|
|
38627
|
+
const compute = (fullCode, sections, options) => {
|
|
38628
|
+
const doc = parseDocument(fullCode, options);
|
|
38537
38629
|
const span = doc && getContainerInnerSpan(doc.container);
|
|
38538
38630
|
if (!span) {
|
|
38539
38631
|
containerPrefix = null;
|
|
@@ -38551,7 +38643,7 @@ const createSectionPreviewCache = () => {
|
|
|
38551
38643
|
nextPreviewsById.set(section.id, cached);
|
|
38552
38644
|
return cached.preview;
|
|
38553
38645
|
}
|
|
38554
|
-
const preview = spliceCode(fullCode, span.start, span.end, section.code);
|
|
38646
|
+
const preview = spliceCode(fullCode, span.start, span.end, fillIdsFrom(section.code, section.id));
|
|
38555
38647
|
nextPreviewsById.set(section.id, {
|
|
38556
38648
|
code: section.code,
|
|
38557
38649
|
preview
|
|
@@ -38566,6 +38658,6 @@ const createSectionPreviewCache = () => {
|
|
|
38566
38658
|
return { compute };
|
|
38567
38659
|
};
|
|
38568
38660
|
//#endregion
|
|
38569
|
-
export { generateSectionPreview as a,
|
|
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 };
|
|
38570
38662
|
|
|
38571
|
-
//# sourceMappingURL=document-
|
|
38663
|
+
//# sourceMappingURL=document-cEEdFERz.js.map
|