@jbpark/live-editor 1.5.0 → 1.6.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/{ast-DyDLUN5F.mjs → ast-CXRFs1hO.mjs} +122 -93
- package/dist/ast-CXRFs1hO.mjs.map +1 -0
- package/dist/{document-BGG0pNR2.mjs → document-BkOqiV4R.mjs} +69 -75
- package/dist/document-BkOqiV4R.mjs.map +1 -0
- package/dist/index.mjs +23 -19
- package/dist/index.mjs.map +1 -1
- package/dist/utils/ast/index.d.mts +3 -1
- package/dist/utils/ast/index.mjs +3 -3
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/index.mjs +3 -3
- package/dist/{utils-UTqUJaVs.mjs → utils-YMe7_mya.mjs} +6 -3
- package/dist/{utils-UTqUJaVs.mjs.map → utils-YMe7_mya.mjs.map} +1 -1
- package/package.json +2 -1
- package/dist/ast-DyDLUN5F.mjs.map +0 -1
- package/dist/document-BGG0pNR2.mjs.map +0 -1
|
@@ -40183,8 +40183,16 @@ var require_lib = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
40183
40183
|
//#region src/utils/cache.ts
|
|
40184
40184
|
const createBoundedCache = (limit, onEvict) => {
|
|
40185
40185
|
const store = /* @__PURE__ */ new Map();
|
|
40186
|
+
const get = (key) => {
|
|
40187
|
+
if (!store.has(key)) return;
|
|
40188
|
+
const value = store.get(key);
|
|
40189
|
+
store.delete(key);
|
|
40190
|
+
store.set(key, value);
|
|
40191
|
+
return value;
|
|
40192
|
+
};
|
|
40186
40193
|
const set = (key, value) => {
|
|
40187
|
-
if (store.
|
|
40194
|
+
if (store.has(key)) store.delete(key);
|
|
40195
|
+
else if (store.size >= limit) {
|
|
40188
40196
|
const oldestKey = store.keys().next().value;
|
|
40189
40197
|
if (oldestKey !== void 0) {
|
|
40190
40198
|
const oldestValue = store.get(oldestKey);
|
|
@@ -40196,7 +40204,7 @@ const createBoundedCache = (limit, onEvict) => {
|
|
|
40196
40204
|
};
|
|
40197
40205
|
return {
|
|
40198
40206
|
has: (key) => store.has(key),
|
|
40199
|
-
get
|
|
40207
|
+
get,
|
|
40200
40208
|
set,
|
|
40201
40209
|
delete: (key) => store.delete(key),
|
|
40202
40210
|
clear: () => store.clear(),
|
|
@@ -40206,56 +40214,26 @@ const createBoundedCache = (limit, onEvict) => {
|
|
|
40206
40214
|
};
|
|
40207
40215
|
};
|
|
40208
40216
|
|
|
40209
|
-
//#endregion
|
|
40210
|
-
//#region src/utils/ast/helpers.ts
|
|
40211
|
-
var import_lib$1 = /* @__PURE__ */ __toESM(require_lib$3(), 1);
|
|
40212
|
-
var import_lib$2 = require_lib$7();
|
|
40213
|
-
var import_lib$3 = /* @__PURE__ */ __toESM(require_lib$4(), 1);
|
|
40214
|
-
const wrap = (code) => {
|
|
40215
|
-
return `<>${code}</>`;
|
|
40216
|
-
};
|
|
40217
|
-
const unwrap = (generated) => {
|
|
40218
|
-
return generated.replace(/^<>\s*/g, "").replace(/\s*<\/>\s*;?\s*$/g, "").trim();
|
|
40219
|
-
};
|
|
40220
|
-
const attrValue = ({ value, isStringLiteral }) => {
|
|
40221
|
-
if (value === null) return null;
|
|
40222
|
-
if (isStringLiteral) return import_lib$3.stringLiteral(value);
|
|
40223
|
-
const trimmed = value.trim();
|
|
40224
|
-
if (REGEX.NUMBER.test(trimmed)) return import_lib$3.jsxExpressionContainer(import_lib$3.numericLiteral(parseFloat(trimmed)));
|
|
40225
|
-
if (REGEX.BOOLEAN_OR_NULL.test(trimmed)) {
|
|
40226
|
-
const expr = (0, import_lib$2.parseExpression)(trimmed, { plugins: ["jsx", "typescript"] });
|
|
40227
|
-
return import_lib$3.jsxExpressionContainer(expr);
|
|
40228
|
-
}
|
|
40229
|
-
try {
|
|
40230
|
-
const expr = (0, import_lib$2.parseExpression)(trimmed, { plugins: ["jsx", "typescript"] });
|
|
40231
|
-
return import_lib$3.jsxExpressionContainer(expr);
|
|
40232
|
-
} catch {
|
|
40233
|
-
return import_lib$3.stringLiteral(trimmed);
|
|
40234
|
-
}
|
|
40235
|
-
};
|
|
40236
|
-
const generateCode = (node) => {
|
|
40237
|
-
return (0, import_lib$1.default)(node, { jsescOption: { minimal: true } }).code;
|
|
40238
|
-
};
|
|
40239
|
-
|
|
40240
40217
|
//#endregion
|
|
40241
40218
|
//#region src/utils/ast/document.ts
|
|
40242
|
-
var import_lib =
|
|
40219
|
+
var import_lib = require_lib$7();
|
|
40220
|
+
var import_lib$1 = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
40221
|
+
var import_lib$2 = /* @__PURE__ */ __toESM(require_lib$4(), 1);
|
|
40243
40222
|
const APP_CONTAINER_ID = "app-container";
|
|
40244
40223
|
const SECTION_TAG = "section";
|
|
40245
40224
|
const DATA_NAME_ATTR = "data-name";
|
|
40246
40225
|
const getTagName = (element) => {
|
|
40247
40226
|
const name = element.openingElement.name;
|
|
40248
|
-
return import_lib$
|
|
40227
|
+
return import_lib$2.isJSXIdentifier(name) ? name.name : "";
|
|
40249
40228
|
};
|
|
40250
40229
|
const getAttrValue = (element, attrName) => {
|
|
40251
|
-
const attr = element.openingElement.attributes.find((a) => import_lib$
|
|
40252
|
-
return attr && import_lib$
|
|
40230
|
+
const attr = element.openingElement.attributes.find((a) => import_lib$2.isJSXAttribute(a) && import_lib$2.isJSXIdentifier(a.name) && a.name.name === attrName);
|
|
40231
|
+
return attr && import_lib$2.isStringLiteral(attr.value) ? attr.value.value : void 0;
|
|
40253
40232
|
};
|
|
40254
|
-
const isSectionElement = (node) => import_lib$
|
|
40255
|
-
const isBlankJSXText = (node) => import_lib$3.isJSXText(node) && !node.value.trim();
|
|
40233
|
+
const isSectionElement = (node) => import_lib$2.isJSXElement(node) && getTagName(node) === SECTION_TAG;
|
|
40256
40234
|
const findContainer = (ast) => {
|
|
40257
40235
|
let container;
|
|
40258
|
-
(0, import_lib.default)(ast, { JSXElement(path) {
|
|
40236
|
+
(0, import_lib$1.default)(ast, { JSXElement(path) {
|
|
40259
40237
|
if (getAttrValue(path.node, "id") === APP_CONTAINER_ID) {
|
|
40260
40238
|
container = path.node;
|
|
40261
40239
|
path.stop();
|
|
@@ -40263,22 +40241,27 @@ const findContainer = (ast) => {
|
|
|
40263
40241
|
} });
|
|
40264
40242
|
return container;
|
|
40265
40243
|
};
|
|
40266
|
-
const
|
|
40267
|
-
const
|
|
40268
|
-
const
|
|
40269
|
-
|
|
40270
|
-
|
|
40271
|
-
|
|
40272
|
-
|
|
40273
|
-
|
|
40274
|
-
|
|
40275
|
-
return
|
|
40244
|
+
const findOutermostSections = (children) => {
|
|
40245
|
+
const sections = [];
|
|
40246
|
+
for (const child of children) {
|
|
40247
|
+
if (isSectionElement(child)) {
|
|
40248
|
+
sections.push(child);
|
|
40249
|
+
continue;
|
|
40250
|
+
}
|
|
40251
|
+
if (import_lib$2.isJSXElement(child) || import_lib$2.isJSXFragment(child)) sections.push(...findOutermostSections(child.children));
|
|
40252
|
+
}
|
|
40253
|
+
return sections;
|
|
40276
40254
|
};
|
|
40277
|
-
const
|
|
40255
|
+
const documentCache = createBoundedCache(CONFIG.CACHE_LIMIT);
|
|
40256
|
+
const buildDocument = (code) => {
|
|
40278
40257
|
try {
|
|
40279
|
-
const ast =
|
|
40258
|
+
const ast = (0, import_lib.parse)(code, {
|
|
40259
|
+
sourceType: "module",
|
|
40260
|
+
plugins: ["jsx", "typescript"]
|
|
40261
|
+
});
|
|
40280
40262
|
const container = findContainer(ast);
|
|
40281
40263
|
return container ? {
|
|
40264
|
+
code,
|
|
40282
40265
|
ast,
|
|
40283
40266
|
container
|
|
40284
40267
|
} : void 0;
|
|
@@ -40287,40 +40270,51 @@ const parseDocument = (code) => {
|
|
|
40287
40270
|
return;
|
|
40288
40271
|
}
|
|
40289
40272
|
};
|
|
40273
|
+
const parseDocument = (code) => {
|
|
40274
|
+
const cached = documentCache.get(code);
|
|
40275
|
+
if (cached !== void 0) return cached ?? void 0;
|
|
40276
|
+
const doc = buildDocument(code);
|
|
40277
|
+
documentCache.set(code, doc ?? null);
|
|
40278
|
+
return doc;
|
|
40279
|
+
};
|
|
40290
40280
|
const clearDocumentParseCache = () => {
|
|
40291
|
-
|
|
40281
|
+
documentCache.clear();
|
|
40292
40282
|
};
|
|
40293
|
-
const getSections = (doc) => doc.container.children
|
|
40283
|
+
const getSections = (doc) => findOutermostSections(doc.container.children).map((node, index) => ({
|
|
40294
40284
|
id: `${index}`,
|
|
40295
40285
|
name: getAttrValue(node, DATA_NAME_ATTR) || `${index + 1}번째 컴포넌트`,
|
|
40296
|
-
code:
|
|
40286
|
+
code: doc.code.slice(node.start, node.end)
|
|
40297
40287
|
}));
|
|
40298
|
-
const generateDocumentCode = (doc) =>
|
|
40299
|
-
const
|
|
40300
|
-
|
|
40301
|
-
|
|
40302
|
-
|
|
40303
|
-
|
|
40304
|
-
|
|
40305
|
-
return;
|
|
40306
|
-
}
|
|
40288
|
+
const generateDocumentCode = (doc) => doc.code;
|
|
40289
|
+
const getContainerInnerSpan = (container) => {
|
|
40290
|
+
if (!container.closingElement) return;
|
|
40291
|
+
return {
|
|
40292
|
+
start: container.openingElement.end,
|
|
40293
|
+
end: container.closingElement.start
|
|
40294
|
+
};
|
|
40307
40295
|
};
|
|
40296
|
+
const spliceCode = (code, start, end, replacement) => code.slice(0, start) + replacement + code.slice(end);
|
|
40308
40297
|
const replaceDocumentSections = (fullCode, sectionCodes) => {
|
|
40309
40298
|
const doc = parseDocument(fullCode);
|
|
40310
40299
|
if (!doc) return fullCode;
|
|
40311
|
-
const
|
|
40312
|
-
const
|
|
40313
|
-
|
|
40314
|
-
|
|
40300
|
+
const sections = findOutermostSections(doc.container.children);
|
|
40301
|
+
const replacement = sectionCodes.join("\n");
|
|
40302
|
+
if (sections.length > 0) {
|
|
40303
|
+
const start = sections[0].start;
|
|
40304
|
+
const end = sections[sections.length - 1].end;
|
|
40305
|
+
return spliceCode(fullCode, start, end, replacement);
|
|
40306
|
+
}
|
|
40307
|
+
const span = getContainerInnerSpan(doc.container);
|
|
40308
|
+
return span ? spliceCode(fullCode, span.end, span.end, replacement) : fullCode;
|
|
40315
40309
|
};
|
|
40316
|
-
const generateSectionPreview = (fullCode, sectionCode) =>
|
|
40310
|
+
const generateSectionPreview = (fullCode, sectionCode) => generateSectionPreviews(fullCode, [sectionCode])[0];
|
|
40311
|
+
const generateSectionPreviews = (fullCode, sectionCodes) => {
|
|
40317
40312
|
const doc = parseDocument(fullCode);
|
|
40318
|
-
const
|
|
40319
|
-
if (!
|
|
40320
|
-
|
|
40321
|
-
return generateDocumentCode(doc);
|
|
40313
|
+
const span = doc && getContainerInnerSpan(doc.container);
|
|
40314
|
+
if (!span) return sectionCodes.map(() => fullCode);
|
|
40315
|
+
return sectionCodes.map((sectionCode) => spliceCode(fullCode, span.start, span.end, sectionCode));
|
|
40322
40316
|
};
|
|
40323
40317
|
|
|
40324
40318
|
//#endregion
|
|
40325
|
-
export {
|
|
40326
|
-
//# sourceMappingURL=document-
|
|
40319
|
+
export { DRAGGABLE_ITEMS as _, getSections as a, __toESM as b, createBoundedCache as c, require_lib$4 as d, require_lib$7 as f, DEFAULT_TEMPLATE as g, DATA_ATTR as h, generateSectionPreviews as i, require_lib as l, CONFIG as m, generateDocumentCode as n, parseDocument as o, BINDING_PROP as p, generateSectionPreview as r, replaceDocumentSections as s, clearDocumentParseCache as t, require_lib$3 as u, REGEX as v, TS_PATTERNS as y };
|
|
40320
|
+
//# sourceMappingURL=document-BkOqiV4R.mjs.map
|