@jbpark/live-editor 1.3.0 → 1.5.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.
@@ -1,3 +1,5 @@
1
+ import { n as Section } from "../../index-DdSjzvA3.mjs";
2
+
1
3
  //#region src/utils/ast/types.d.ts
2
4
  interface Attribute {
3
5
  name: string;
@@ -1609,13 +1611,29 @@ declare const generateCode: (node: Node) => string;
1609
1611
  declare function extract(raw: string): DataAttrNode[];
1610
1612
  declare function clearExtractCache(): void;
1611
1613
  //#endregion
1614
+ //#region src/utils/ast/document.d.ts
1615
+ interface DocumentTree {
1616
+ ast: File;
1617
+ container: JSXElement;
1618
+ }
1619
+ declare const parseDocument: (code: string) => DocumentTree | undefined;
1620
+ declare const clearDocumentParseCache: () => void;
1621
+ declare const getSections: (doc: DocumentTree) => Section[];
1622
+ declare const generateDocumentCode: (doc: DocumentTree) => string;
1623
+ declare const replaceDocumentSections: (fullCode: string, sectionCodes: string[]) => string;
1624
+ declare const generateSectionPreview: (fullCode: string, sectionCode: string) => string;
1625
+ //#endregion
1612
1626
  //#region src/utils/ast/update.d.ts
1613
- declare const update: (code: string, dataId: string, label: string, value: string) => string;
1627
+ interface UpdateResult {
1628
+ code: string;
1629
+ success: boolean;
1630
+ }
1631
+ declare const update: (code: string, dataId: string, label: string, value: string) => UpdateResult;
1614
1632
  declare const bulkUpdate: (raw: string, entries: {
1615
1633
  dataId: string;
1616
1634
  label: string;
1617
1635
  value: string;
1618
- }[]) => string;
1636
+ }[]) => UpdateResult;
1619
1637
  //#endregion
1620
1638
  //#region src/utils/ast/tree.d.ts
1621
1639
  declare const replaceIds: (code: string, generateId?: () => string) => string;
@@ -1629,5 +1647,5 @@ interface ValidationResult {
1629
1647
  }
1630
1648
  declare const validateBindingValue: (binding: BindingItem, value: unknown) => ValidationResult;
1631
1649
  //#endregion
1632
- export { type BindingItem, type BindingOption, type BindingRenderLeaf, type BindingRenderMap, type BindingType, type DataAttrNode, type EditableNodeValueType, type ExtractedNodeValue, type NodeValueType, type ValidationResult, arrayExpressionToCode, bulkUpdate, clearExtractCache, clone, createNodeFromValue, extract, extractNodeValue, extractObjectProperties, fillIds, findEditableChildren, generateCode, getCurrentValue, parseArrayExpression, parseBinding, parseValue, replaceIds, update, validateBindingValue };
1650
+ export { type BindingItem, type BindingOption, type BindingRenderLeaf, type BindingRenderMap, type BindingType, type DataAttrNode, type DocumentTree, type EditableNodeValueType, type ExtractedNodeValue, type NodeValueType, type ValidationResult, arrayExpressionToCode, bulkUpdate, clearDocumentParseCache, clearExtractCache, clone, createNodeFromValue, extract, extractNodeValue, extractObjectProperties, fillIds, findEditableChildren, generateCode, generateDocumentCode, generateSectionPreview, getCurrentValue, getSections, parseArrayExpression, parseBinding, parseDocument, parseValue, replaceDocumentSections, replaceIds, update, validateBindingValue };
1633
1651
  //# sourceMappingURL=index.d.mts.map
@@ -1,3 +1,4 @@
1
- import { _ as parseArrayExpression, a as bulkUpdate, c as extract, d as getCurrentValue, f as parseBinding, g as extractObjectProperties, h as extractNodeValue, i as replaceIds, m as createNodeFromValue, n as clone, o as update, p as arrayExpressionToCode, r as fillIds, s as clearExtractCache, t as validateBindingValue, u as findEditableChildren, v as parseValue, y as generateCode } from "../../ast-fX6Whrjc.mjs";
1
+ import { a as parseDocument, c as generateCode, i as getSections, n as generateDocumentCode, o as replaceDocumentSections, r as generateSectionPreview, t as clearDocumentParseCache } from "../../document-BGG0pNR2.mjs";
2
+ import { _ as parseArrayExpression, a as bulkUpdate, c as extract, d as getCurrentValue, f as parseBinding, g as extractObjectProperties, h as extractNodeValue, i as replaceIds, m as createNodeFromValue, n as clone, o as update, p as arrayExpressionToCode, r as fillIds, s as clearExtractCache, t as validateBindingValue, u as findEditableChildren, v as parseValue } from "../../ast-DyDLUN5F.mjs";
2
3
 
3
- export { arrayExpressionToCode, bulkUpdate, clearExtractCache, clone, createNodeFromValue, extract, extractNodeValue, extractObjectProperties, fillIds, findEditableChildren, generateCode, getCurrentValue, parseArrayExpression, parseBinding, parseValue, replaceIds, update, validateBindingValue };
4
+ export { arrayExpressionToCode, bulkUpdate, clearDocumentParseCache, clearExtractCache, clone, createNodeFromValue, extract, extractNodeValue, extractObjectProperties, fillIds, findEditableChildren, generateCode, generateDocumentCode, generateSectionPreview, getCurrentValue, getSections, parseArrayExpression, parseBinding, parseDocument, parseValue, replaceDocumentSections, replaceIds, update, validateBindingValue };
@@ -1,3 +1,4 @@
1
- import { a as detectTypeScript, c as getCachedScriptBlob, d as transformCode, i as compile, l as preloadScripts, n as clearCompilationCache, o as extractSections, r as cn, s as generateSection, t as baseModules, u as replaceSections } from "../utils-INSWI9h0.mjs";
1
+ import "../document-BGG0pNR2.mjs";
2
+ import { a as detectTypeScript, c as getCachedScriptBlob, d as transformCode, i as compile, l as preloadScripts, n as clearCompilationCache, o as extractSections, r as cn, s as generateSection, t as baseModules, u as replaceSections } from "../utils-UTqUJaVs.mjs";
2
3
 
3
4
  export { baseModules, clearCompilationCache, cn, compile, detectTypeScript, extractSections, generateSection, getCachedScriptBlob, preloadScripts, replaceSections, transformCode };
@@ -1,4 +1,4 @@
1
- import { n as CONFIG, o as REGEX, s as TS_PATTERNS } from "./enums-3yleLgqV.mjs";
1
+ import { a as parseDocument, b as REGEX, d as createBoundedCache, g as CONFIG, i as getSections, o as replaceDocumentSections, r as generateSectionPreview, x as TS_PATTERNS } from "./document-BGG0pNR2.mjs";
2
2
  import React from "react";
3
3
  import * as Babel from "@babel/standalone";
4
4
  import * as ui from "@jbpark/ui-kit";
@@ -1921,7 +1921,7 @@ const baseModules = {
1921
1921
  "ui-kit": ui,
1922
1922
  "ui-kit/utils": utils
1923
1923
  };
1924
- const compilationCache = /* @__PURE__ */ new Map();
1924
+ const compilationCache = createBoundedCache(CONFIG.CACHE_LIMIT);
1925
1925
  const simpleHash = (str) => {
1926
1926
  let hash = 0;
1927
1927
  if (str.length === 0) return "0";
@@ -1940,10 +1940,6 @@ const compile = (code, modules) => {
1940
1940
  const cacheKey = createCacheKey(code, modules);
1941
1941
  if (compilationCache.has(cacheKey)) return compilationCache.get(cacheKey);
1942
1942
  const result = compileModule(code, modules);
1943
- if (compilationCache.size >= CONFIG.CACHE_LIMIT) {
1944
- const firstKey = compilationCache.keys().next().value;
1945
- if (firstKey) compilationCache.delete(firstKey);
1946
- }
1947
1943
  compilationCache.set(cacheKey, result);
1948
1944
  return result;
1949
1945
  };
@@ -1981,7 +1977,8 @@ const transformCode = (code) => {
1981
1977
  }
1982
1978
  };
1983
1979
  const detectTypeScript = (code) => {
1984
- return TS_PATTERNS.some((pattern) => pattern.test(code));
1980
+ const withoutModuleLines = code.replace(REGEX.MODULE_IMPORT_EXPORT_LINE, "");
1981
+ return TS_PATTERNS.some((pattern) => pattern.test(withoutModuleLines));
1985
1982
  };
1986
1983
  const compileModule = (code, modules) => {
1987
1984
  const jsCode = detectTypeScript(code) ? compileTypeScript(code) : code;
@@ -2011,34 +2008,16 @@ const compileModule = (code, modules) => {
2011
2008
  return module;
2012
2009
  };
2013
2010
  const extractSections = (code) => {
2014
- return [...code.replace(REGEX.COMMENT, "").matchAll(REGEX.SECTION)].map((m, i) => {
2015
- const sectionCode = m[0];
2016
- const dataNameMatch = sectionCode.match(REGEX.DATA_NAME);
2017
- return {
2018
- code: sectionCode,
2019
- id: `${i}`,
2020
- name: dataNameMatch?.[1] || `${i + 1}번째 컴포넌트`
2021
- };
2022
- });
2011
+ const doc = parseDocument(code);
2012
+ return doc ? getSections(doc) : [];
2023
2013
  };
2024
2014
  const replaceSections = (code, sections) => {
2025
- const comments = [...code.matchAll(REGEX.COMMENT)].map((match) => match[0]);
2026
- const cleanCode = code.replace(REGEX.SECTION, "");
2027
- const match = cleanCode.match(REGEX.CONTAINER);
2028
- if (match) {
2029
- const [, openTag, , closeTag] = match;
2030
- const allContent = [...sections, ...comments].join("\n");
2031
- return cleanCode.replace(REGEX.CONTAINER, `${openTag}\n${allContent}\n${closeTag}`);
2032
- }
2033
- return code;
2015
+ return replaceDocumentSections(code, sections);
2034
2016
  };
2035
2017
  const generateSection = (code, fullCode) => {
2036
- const match = fullCode.match(REGEX.CONTAINER);
2037
- if (!match) return fullCode;
2038
- const [, openTag, , closeTag] = match;
2039
- return fullCode.replace(REGEX.CONTAINER, `${openTag}\n${code}\n${closeTag}`);
2018
+ return generateSectionPreview(fullCode, code);
2040
2019
  };
2041
- const scriptCache = /* @__PURE__ */ new Map();
2020
+ const scriptCache = createBoundedCache(CONFIG.CACHE_LIMIT, (_src, blobUrl) => URL.revokeObjectURL(blobUrl));
2042
2021
  const loadingScriptCache = /* @__PURE__ */ new Map();
2043
2022
  const getCachedScriptBlob = async (src) => {
2044
2023
  const cached = scriptCache.get(src);
@@ -2048,14 +2027,6 @@ const getCachedScriptBlob = async (src) => {
2048
2027
  const promise = fetch(src).then((res) => res.text()).then((text) => {
2049
2028
  const blob = new Blob([text], { type: "application/javascript" });
2050
2029
  const blobUrl = URL.createObjectURL(blob);
2051
- if (scriptCache.size >= CONFIG.CACHE_LIMIT) {
2052
- const firstKey = scriptCache.keys().next().value;
2053
- if (firstKey) {
2054
- const evictedUrl = scriptCache.get(firstKey);
2055
- if (evictedUrl) URL.revokeObjectURL(evictedUrl);
2056
- scriptCache.delete(firstKey);
2057
- }
2058
- }
2059
2030
  scriptCache.set(src, blobUrl);
2060
2031
  loadingScriptCache.delete(src);
2061
2032
  return blobUrl;
@@ -2069,4 +2040,4 @@ const preloadScripts = (scripts) => {
2069
2040
 
2070
2041
  //#endregion
2071
2042
  export { detectTypeScript as a, getCachedScriptBlob as c, transformCode as d, compile as i, preloadScripts as l, clearCompilationCache as n, extractSections as o, cn as r, generateSection as s, baseModules as t, replaceSections as u };
2072
- //# sourceMappingURL=utils-INSWI9h0.mjs.map
2043
+ //# sourceMappingURL=utils-UTqUJaVs.mjs.map