@jbpark/live-editor 1.4.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/README.ko.md +1 -1
- package/README.md +1 -1
- package/dist/ast-CXRFs1hO.mjs +788 -0
- package/dist/ast-CXRFs1hO.mjs.map +1 -0
- package/dist/{ast-fX6Whrjc.mjs → document-BkOqiV4R.mjs} +9940 -9340
- package/dist/document-BkOqiV4R.mjs.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +112 -60
- package/dist/index.mjs.map +1 -1
- package/dist/utils/ast/index.d.mts +23 -3
- package/dist/utils/ast/index.mjs +3 -2
- package/dist/utils/index.d.mts +2 -1
- package/dist/utils/index.mjs +3 -2
- package/dist/{utils-INSWI9h0.mjs → utils-YMe7_mya.mjs} +14 -40
- package/dist/{utils-INSWI9h0.mjs.map → utils-YMe7_mya.mjs.map} +1 -1
- package/package.json +8 -2
- package/dist/ast-fX6Whrjc.mjs.map +0 -1
- package/dist/enums-3yleLgqV.mjs +0 -1237
- package/dist/enums-3yleLgqV.mjs.map +0 -1
|
@@ -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,31 @@ 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
|
+
code: string;
|
|
1617
|
+
ast: File;
|
|
1618
|
+
container: JSXElement;
|
|
1619
|
+
}
|
|
1620
|
+
declare const parseDocument: (code: string) => DocumentTree | undefined;
|
|
1621
|
+
declare const clearDocumentParseCache: () => void;
|
|
1622
|
+
declare const getSections: (doc: DocumentTree) => Section[];
|
|
1623
|
+
declare const generateDocumentCode: (doc: DocumentTree) => string;
|
|
1624
|
+
declare const replaceDocumentSections: (fullCode: string, sectionCodes: string[]) => string;
|
|
1625
|
+
declare const generateSectionPreview: (fullCode: string, sectionCode: string) => string;
|
|
1626
|
+
declare const generateSectionPreviews: (fullCode: string, sectionCodes: string[]) => string[];
|
|
1627
|
+
//#endregion
|
|
1612
1628
|
//#region src/utils/ast/update.d.ts
|
|
1613
|
-
|
|
1629
|
+
interface UpdateResult {
|
|
1630
|
+
code: string;
|
|
1631
|
+
success: boolean;
|
|
1632
|
+
}
|
|
1633
|
+
declare const update: (code: string, dataId: string, label: string, value: string) => UpdateResult;
|
|
1614
1634
|
declare const bulkUpdate: (raw: string, entries: {
|
|
1615
1635
|
dataId: string;
|
|
1616
1636
|
label: string;
|
|
1617
1637
|
value: string;
|
|
1618
|
-
}[]) =>
|
|
1638
|
+
}[]) => UpdateResult;
|
|
1619
1639
|
//#endregion
|
|
1620
1640
|
//#region src/utils/ast/tree.d.ts
|
|
1621
1641
|
declare const replaceIds: (code: string, generateId?: () => string) => string;
|
|
@@ -1629,5 +1649,5 @@ interface ValidationResult {
|
|
|
1629
1649
|
}
|
|
1630
1650
|
declare const validateBindingValue: (binding: BindingItem, value: unknown) => ValidationResult;
|
|
1631
1651
|
//#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 };
|
|
1652
|
+
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, generateSectionPreviews, getCurrentValue, getSections, parseArrayExpression, parseBinding, parseDocument, parseValue, replaceDocumentSections, replaceIds, update, validateBindingValue };
|
|
1633
1653
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/utils/ast/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as getSections, i as generateSectionPreviews, n as generateDocumentCode, o as parseDocument, r as generateSectionPreview, s as replaceDocumentSections, t as clearDocumentParseCache } from "../../document-BkOqiV4R.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, y as generateCode } from "../../ast-CXRFs1hO.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, generateSectionPreviews, getCurrentValue, getSections, parseArrayExpression, parseBinding, parseDocument, parseValue, replaceDocumentSections, replaceIds, update, validateBindingValue };
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -20,8 +20,9 @@ declare const detectTypeScript: (code: string) => boolean;
|
|
|
20
20
|
declare const extractSections: (code: string) => Section[];
|
|
21
21
|
declare const replaceSections: (code: string, sections: string[]) => string;
|
|
22
22
|
declare const generateSection: (code: string, fullCode: string) => string;
|
|
23
|
+
declare const generateSections: (codes: string[], fullCode: string) => string[];
|
|
23
24
|
declare const getCachedScriptBlob: (src: string) => Promise<string>;
|
|
24
25
|
declare const preloadScripts: (scripts: string[]) => void;
|
|
25
26
|
//#endregion
|
|
26
|
-
export { baseModules, clearCompilationCache, cn, compile, detectTypeScript, extractSections, generateSection, getCachedScriptBlob, preloadScripts, replaceSections, transformCode };
|
|
27
|
+
export { baseModules, clearCompilationCache, cn, compile, detectTypeScript, extractSections, generateSection, generateSections, getCachedScriptBlob, preloadScripts, replaceSections, transformCode };
|
|
27
28
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../document-BkOqiV4R.mjs";
|
|
2
|
+
import { a as detectTypeScript, c as generateSections, d as replaceSections, f as transformCode, i as compile, l as getCachedScriptBlob, n as clearCompilationCache, o as extractSections, r as cn, s as generateSection, t as baseModules, u as preloadScripts } from "../utils-YMe7_mya.mjs";
|
|
2
3
|
|
|
3
|
-
export { baseModules, clearCompilationCache, cn, compile, detectTypeScript, extractSections, generateSection, getCachedScriptBlob, preloadScripts, replaceSections, transformCode };
|
|
4
|
+
export { baseModules, clearCompilationCache, cn, compile, detectTypeScript, extractSections, generateSection, generateSections, getCachedScriptBlob, preloadScripts, replaceSections, transformCode };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as getSections, c as createBoundedCache, i as generateSectionPreviews, m as CONFIG, o as parseDocument, r as generateSectionPreview, s as replaceDocumentSections, v as REGEX, y as TS_PATTERNS } from "./document-BkOqiV4R.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 =
|
|
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
|
-
|
|
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,19 @@ const compileModule = (code, modules) => {
|
|
|
2011
2008
|
return module;
|
|
2012
2009
|
};
|
|
2013
2010
|
const extractSections = (code) => {
|
|
2014
|
-
|
|
2015
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
return fullCode
|
|
2018
|
+
return generateSectionPreview(fullCode, code);
|
|
2019
|
+
};
|
|
2020
|
+
const generateSections = (codes, fullCode) => {
|
|
2021
|
+
return generateSectionPreviews(fullCode, codes);
|
|
2040
2022
|
};
|
|
2041
|
-
const scriptCache =
|
|
2023
|
+
const scriptCache = createBoundedCache(CONFIG.CACHE_LIMIT, (_src, blobUrl) => URL.revokeObjectURL(blobUrl));
|
|
2042
2024
|
const loadingScriptCache = /* @__PURE__ */ new Map();
|
|
2043
2025
|
const getCachedScriptBlob = async (src) => {
|
|
2044
2026
|
const cached = scriptCache.get(src);
|
|
@@ -2048,14 +2030,6 @@ const getCachedScriptBlob = async (src) => {
|
|
|
2048
2030
|
const promise = fetch(src).then((res) => res.text()).then((text) => {
|
|
2049
2031
|
const blob = new Blob([text], { type: "application/javascript" });
|
|
2050
2032
|
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
2033
|
scriptCache.set(src, blobUrl);
|
|
2060
2034
|
loadingScriptCache.delete(src);
|
|
2061
2035
|
return blobUrl;
|
|
@@ -2068,5 +2042,5 @@ const preloadScripts = (scripts) => {
|
|
|
2068
2042
|
};
|
|
2069
2043
|
|
|
2070
2044
|
//#endregion
|
|
2071
|
-
export { detectTypeScript as a,
|
|
2072
|
-
//# sourceMappingURL=utils-
|
|
2045
|
+
export { detectTypeScript as a, generateSections as c, replaceSections as d, transformCode as f, compile as i, getCachedScriptBlob as l, clearCompilationCache as n, extractSections as o, cn as r, generateSection as s, baseModules as t, preloadScripts as u };
|
|
2046
|
+
//# sourceMappingURL=utils-YMe7_mya.mjs.map
|