@jbpark/live-editor 1.0.3 → 1.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.
- package/dist/{ast-UXy9dqvD.mjs → ast-fX6Whrjc.mjs} +148 -139
- package/dist/ast-fX6Whrjc.mjs.map +1 -0
- package/dist/index.mjs +577 -356
- package/dist/index.mjs.map +1 -1
- package/dist/utils/ast/index.d.mts +2 -1
- package/dist/utils/ast/index.mjs +1 -1
- package/package.json +4 -3
- package/dist/ast-UXy9dqvD.mjs.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { n as CONFIG, o as REGEX, r as DATA_ATTR, t as BINDING_PROP } from "./enums-3yleLgqV.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
+
import { z } from "zod";
|
|
3
4
|
import crypto from "crypto";
|
|
4
5
|
|
|
5
6
|
//#region \0rolldown/runtime.js
|
|
@@ -26732,141 +26733,21 @@ var require_lib$4 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
26732
26733
|
}));
|
|
26733
26734
|
|
|
26734
26735
|
//#endregion
|
|
26735
|
-
//#region src/utils/ast/
|
|
26736
|
-
|
|
26737
|
-
|
|
26738
|
-
|
|
26739
|
-
|
|
26740
|
-
|
|
26741
|
-
|
|
26742
|
-
|
|
26743
|
-
|
|
26744
|
-
|
|
26745
|
-
|
|
26746
|
-
|
|
26747
|
-
|
|
26748
|
-
|
|
26749
|
-
|
|
26750
|
-
const nested = parseRenderObject(renderProp.value);
|
|
26751
|
-
if (nested) leaf.render = nested;
|
|
26752
|
-
}
|
|
26753
|
-
map[key] = leaf;
|
|
26754
|
-
} else {
|
|
26755
|
-
const nested = parseRenderObject(prop.value);
|
|
26756
|
-
if (nested) map[key] = nested;
|
|
26757
|
-
}
|
|
26758
|
-
});
|
|
26759
|
-
return Object.keys(map).length > 0 ? map : null;
|
|
26760
|
-
};
|
|
26761
|
-
const parseBinding = (bindingValue) => {
|
|
26762
|
-
if (!bindingValue) return [];
|
|
26763
|
-
try {
|
|
26764
|
-
const ast = (0, import_lib$2.parseExpression)(bindingValue, { plugins: ["jsx", "typescript"] });
|
|
26765
|
-
if (import_lib$3.isArrayExpression(ast)) return ast.elements.map((element) => {
|
|
26766
|
-
if (import_lib$3.isObjectExpression(element)) {
|
|
26767
|
-
const labelProp = element.properties.find((p) => import_lib$3.isObjectProperty(p) && import_lib$3.isIdentifier(p.key) && p.key.name === "label" && import_lib$3.isStringLiteral(p.value));
|
|
26768
|
-
const propertyProp = element.properties.find((p) => import_lib$3.isObjectProperty(p) && import_lib$3.isIdentifier(p.key) && p.key.name === "property" && import_lib$3.isStringLiteral(p.value));
|
|
26769
|
-
const optionsProp = element.properties.find((p) => import_lib$3.isObjectProperty(p) && import_lib$3.isIdentifier(p.key) && p.key.name === "options" && import_lib$3.isArrayExpression(p.value));
|
|
26770
|
-
const typePropEarly = element.properties.find((p) => import_lib$3.isObjectProperty(p) && import_lib$3.isIdentifier(p.key) && p.key.name === "type" && import_lib$3.isStringLiteral(p.value));
|
|
26771
|
-
const isRichtext = (typePropEarly ? typePropEarly.value.value : void 0) === "richtext";
|
|
26772
|
-
if (labelProp && (propertyProp || isRichtext)) {
|
|
26773
|
-
const binding = {
|
|
26774
|
-
label: labelProp.value.value,
|
|
26775
|
-
property: propertyProp ? propertyProp.value.value : BINDING_PROP.INNER_HTML
|
|
26776
|
-
};
|
|
26777
|
-
const typeProp = typePropEarly;
|
|
26778
|
-
if (typeProp) {
|
|
26779
|
-
const typeValue = typeProp.value.value;
|
|
26780
|
-
if ([
|
|
26781
|
-
"array",
|
|
26782
|
-
"object",
|
|
26783
|
-
"string",
|
|
26784
|
-
"number",
|
|
26785
|
-
"boolean",
|
|
26786
|
-
"color",
|
|
26787
|
-
"jsx",
|
|
26788
|
-
"richtext",
|
|
26789
|
-
"date",
|
|
26790
|
-
"url",
|
|
26791
|
-
"icon-picker",
|
|
26792
|
-
"asset-picker"
|
|
26793
|
-
].includes(typeValue)) binding.type = typeValue;
|
|
26794
|
-
}
|
|
26795
|
-
const renderProp = element.properties.find((p) => import_lib$3.isObjectProperty(p) && import_lib$3.isIdentifier(p.key) && p.key.name === "render" && import_lib$3.isObjectExpression(p.value));
|
|
26796
|
-
if (renderProp && import_lib$3.isObjectExpression(renderProp.value)) {
|
|
26797
|
-
const renderMap = parseRenderObject(renderProp.value);
|
|
26798
|
-
if (renderMap) binding.render = renderMap;
|
|
26799
|
-
}
|
|
26800
|
-
if (optionsProp && import_lib$3.isArrayExpression(optionsProp.value)) {
|
|
26801
|
-
const options = optionsProp.value.elements.map((el) => {
|
|
26802
|
-
if (import_lib$3.isObjectExpression(el)) {
|
|
26803
|
-
const labelProp = el.properties.find((p) => import_lib$3.isObjectProperty(p) && import_lib$3.isIdentifier(p.key) && p.key.name === "label" && import_lib$3.isStringLiteral(p.value));
|
|
26804
|
-
const valueProp = el.properties.find((p) => import_lib$3.isObjectProperty(p) && import_lib$3.isIdentifier(p.key) && p.key.name === "value" && import_lib$3.isStringLiteral(p.value));
|
|
26805
|
-
if (labelProp && valueProp) return {
|
|
26806
|
-
label: labelProp.value.value,
|
|
26807
|
-
value: valueProp.value.value
|
|
26808
|
-
};
|
|
26809
|
-
}
|
|
26810
|
-
return null;
|
|
26811
|
-
}).filter((item) => item !== null);
|
|
26812
|
-
if (options.length > 0) binding.options = options;
|
|
26813
|
-
}
|
|
26814
|
-
const minProp = element.properties.find((p) => import_lib$3.isObjectProperty(p) && import_lib$3.isIdentifier(p.key) && p.key.name === "min" && import_lib$3.isNumericLiteral(p.value));
|
|
26815
|
-
if (minProp) binding.min = minProp.value.value;
|
|
26816
|
-
const maxProp = element.properties.find((p) => import_lib$3.isObjectProperty(p) && import_lib$3.isIdentifier(p.key) && p.key.name === "max" && import_lib$3.isNumericLiteral(p.value));
|
|
26817
|
-
if (maxProp) binding.max = maxProp.value.value;
|
|
26818
|
-
const patternProp = element.properties.find((p) => import_lib$3.isObjectProperty(p) && import_lib$3.isIdentifier(p.key) && p.key.name === "pattern" && import_lib$3.isStringLiteral(p.value));
|
|
26819
|
-
if (patternProp) binding.pattern = patternProp.value.value;
|
|
26820
|
-
const requiredProp = element.properties.find((p) => import_lib$3.isObjectProperty(p) && import_lib$3.isIdentifier(p.key) && p.key.name === "required" && import_lib$3.isBooleanLiteral(p.value));
|
|
26821
|
-
if (requiredProp) binding.required = requiredProp.value.value;
|
|
26822
|
-
return binding;
|
|
26823
|
-
}
|
|
26824
|
-
}
|
|
26825
|
-
return null;
|
|
26826
|
-
}).filter((item) => item !== null);
|
|
26827
|
-
} catch (error) {
|
|
26828
|
-
console.error("❌ Binding parsing error:", error);
|
|
26829
|
-
}
|
|
26830
|
-
return [];
|
|
26831
|
-
};
|
|
26832
|
-
const getCurrentValue = (node, property) => {
|
|
26833
|
-
switch (property) {
|
|
26834
|
-
case BINDING_PROP.INNER_TEXT: return node.textContent || "";
|
|
26835
|
-
case BINDING_PROP.INNER_HTML: {
|
|
26836
|
-
const dsiAttr = node.attributes.find((a) => a.name === "dangerouslySetInnerHTML");
|
|
26837
|
-
if (dsiAttr?.value) try {
|
|
26838
|
-
const expr = (0, import_lib$2.parseExpression)(dsiAttr.value, { plugins: ["jsx", "typescript"] });
|
|
26839
|
-
if (import_lib$3.isObjectExpression(expr)) {
|
|
26840
|
-
const htmlProp = expr.properties.find((p) => import_lib$3.isObjectProperty(p) && import_lib$3.isIdentifier(p.key) && p.key.name === "__html");
|
|
26841
|
-
if (htmlProp) {
|
|
26842
|
-
if (import_lib$3.isStringLiteral(htmlProp.value)) return htmlProp.value.value;
|
|
26843
|
-
if (import_lib$3.isTemplateLiteral(htmlProp.value) && htmlProp.value.expressions.length === 0) return htmlProp.value.quasis[0]?.value.cooked ?? htmlProp.value.quasis[0]?.value.raw ?? "";
|
|
26844
|
-
}
|
|
26845
|
-
}
|
|
26846
|
-
} catch {}
|
|
26847
|
-
return node.rawChildren || node.textContent || "";
|
|
26848
|
-
}
|
|
26849
|
-
case BINDING_PROP.CHILDREN: return JSON.stringify(node?.children || []);
|
|
26850
|
-
default: return node.attributes.find((attr) => attr.name === property)?.value || "";
|
|
26851
|
-
}
|
|
26852
|
-
};
|
|
26853
|
-
const hasEditableBindings = (node) => {
|
|
26854
|
-
const bindingAttr = node.dataAttributes.find((attr) => attr.name === DATA_ATTR.BINDING);
|
|
26855
|
-
if (!bindingAttr?.value) return false;
|
|
26856
|
-
return (node.bindings || parseBinding(bindingAttr.value)).length > 0;
|
|
26857
|
-
};
|
|
26858
|
-
const findEditableChildren = (node) => {
|
|
26859
|
-
const editableChildren = [];
|
|
26860
|
-
const traverse = (children) => {
|
|
26861
|
-
if (!children) return;
|
|
26862
|
-
for (const child of children) {
|
|
26863
|
-
if (hasEditableBindings(child)) editableChildren.push(child);
|
|
26864
|
-
traverse(child.children);
|
|
26865
|
-
}
|
|
26866
|
-
};
|
|
26867
|
-
traverse(node.children);
|
|
26868
|
-
return editableChildren;
|
|
26869
|
-
};
|
|
26736
|
+
//#region src/utils/ast/types.ts
|
|
26737
|
+
const BINDING_TYPES = [
|
|
26738
|
+
"array",
|
|
26739
|
+
"object",
|
|
26740
|
+
"string",
|
|
26741
|
+
"number",
|
|
26742
|
+
"boolean",
|
|
26743
|
+
"color",
|
|
26744
|
+
"jsx",
|
|
26745
|
+
"richtext",
|
|
26746
|
+
"date",
|
|
26747
|
+
"url",
|
|
26748
|
+
"icon-picker",
|
|
26749
|
+
"asset-picker"
|
|
26750
|
+
];
|
|
26870
26751
|
|
|
26871
26752
|
//#endregion
|
|
26872
26753
|
//#region node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js
|
|
@@ -33101,6 +32982,8 @@ var require_lib$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
33101
32982
|
//#endregion
|
|
33102
32983
|
//#region src/utils/ast/helpers.ts
|
|
33103
32984
|
var import_lib$1 = /* @__PURE__ */ __toESM(require_lib$3(), 1);
|
|
32985
|
+
var import_lib$2 = require_lib$7();
|
|
32986
|
+
var import_lib$3 = /* @__PURE__ */ __toESM(require_lib$4(), 1);
|
|
33104
32987
|
const wrap = (code) => {
|
|
33105
32988
|
return `<>${code}</>`;
|
|
33106
32989
|
};
|
|
@@ -33151,8 +33034,13 @@ const evaluateLiteral = (node) => {
|
|
|
33151
33034
|
if (import_lib$3.isObjectExpression(node)) {
|
|
33152
33035
|
const result = {};
|
|
33153
33036
|
for (const prop of node.properties) {
|
|
33154
|
-
if (!import_lib$3.isObjectProperty(prop)
|
|
33155
|
-
|
|
33037
|
+
if (!import_lib$3.isObjectProperty(prop)) continue;
|
|
33038
|
+
let key = null;
|
|
33039
|
+
if (import_lib$3.isIdentifier(prop.key)) key = prop.key.name;
|
|
33040
|
+
else if (import_lib$3.isStringLiteral(prop.key)) key = prop.key.value;
|
|
33041
|
+
else if (import_lib$3.isNumericLiteral(prop.key)) key = String(prop.key.value);
|
|
33042
|
+
if (key === null) continue;
|
|
33043
|
+
result[key] = evaluateLiteral(prop.value);
|
|
33156
33044
|
}
|
|
33157
33045
|
return result;
|
|
33158
33046
|
}
|
|
@@ -33261,6 +33149,127 @@ const arrayExpressionToCode = (elements) => {
|
|
|
33261
33149
|
return generateCode(import_lib$3.arrayExpression(elements));
|
|
33262
33150
|
};
|
|
33263
33151
|
|
|
33152
|
+
//#endregion
|
|
33153
|
+
//#region src/utils/ast/binding.ts
|
|
33154
|
+
const bindingTypeSchema = z.enum(BINDING_TYPES);
|
|
33155
|
+
const bindingOptionSchema = z.object({
|
|
33156
|
+
label: z.string(),
|
|
33157
|
+
value: z.string()
|
|
33158
|
+
});
|
|
33159
|
+
const bindingRenderLeafSchema = z.object({
|
|
33160
|
+
type: bindingTypeSchema,
|
|
33161
|
+
property: z.string().optional()
|
|
33162
|
+
});
|
|
33163
|
+
const rawBindingItemSchema = z.object({
|
|
33164
|
+
label: z.string(),
|
|
33165
|
+
property: z.string().optional(),
|
|
33166
|
+
type: bindingTypeSchema.optional(),
|
|
33167
|
+
options: z.array(bindingOptionSchema).optional(),
|
|
33168
|
+
min: z.number().optional(),
|
|
33169
|
+
max: z.number().optional(),
|
|
33170
|
+
pattern: z.string().optional(),
|
|
33171
|
+
required: z.boolean().optional()
|
|
33172
|
+
});
|
|
33173
|
+
const isPlainObject = (value) => {
|
|
33174
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33175
|
+
};
|
|
33176
|
+
const sanitizeRenderMap = (value) => {
|
|
33177
|
+
if (!isPlainObject(value)) return;
|
|
33178
|
+
const map = {};
|
|
33179
|
+
for (const [key, raw] of Object.entries(value)) {
|
|
33180
|
+
if (!isPlainObject(raw)) continue;
|
|
33181
|
+
if ("type" in raw) {
|
|
33182
|
+
const leaf = bindingRenderLeafSchema.safeParse(raw);
|
|
33183
|
+
if (leaf.success) {
|
|
33184
|
+
const render = sanitizeRenderMap(raw.render);
|
|
33185
|
+
map[key] = render ? {
|
|
33186
|
+
...leaf.data,
|
|
33187
|
+
render
|
|
33188
|
+
} : leaf.data;
|
|
33189
|
+
}
|
|
33190
|
+
continue;
|
|
33191
|
+
}
|
|
33192
|
+
const nested = sanitizeRenderMap(raw);
|
|
33193
|
+
if (nested) map[key] = nested;
|
|
33194
|
+
}
|
|
33195
|
+
return Object.keys(map).length > 0 ? map : void 0;
|
|
33196
|
+
};
|
|
33197
|
+
const parseBinding = (bindingValue) => {
|
|
33198
|
+
if (!bindingValue) return [];
|
|
33199
|
+
const ast = parseArrayExpression(bindingValue);
|
|
33200
|
+
if (!ast) return [];
|
|
33201
|
+
const raw = evaluateLiteral(ast);
|
|
33202
|
+
if (!Array.isArray(raw)) return [];
|
|
33203
|
+
const items = [];
|
|
33204
|
+
for (const rawItem of raw) {
|
|
33205
|
+
if (!isPlainObject(rawItem)) continue;
|
|
33206
|
+
const sanitizedType = bindingTypeSchema.safeParse(rawItem.type);
|
|
33207
|
+
const sanitizedOptions = Array.isArray(rawItem.options) ? rawItem.options.map((option) => {
|
|
33208
|
+
const parsed = bindingOptionSchema.safeParse(option);
|
|
33209
|
+
return parsed.success ? parsed.data : null;
|
|
33210
|
+
}).filter((option) => option !== null) : void 0;
|
|
33211
|
+
const parsed = rawBindingItemSchema.safeParse({
|
|
33212
|
+
...rawItem,
|
|
33213
|
+
type: sanitizedType.success ? sanitizedType.data : void 0,
|
|
33214
|
+
options: sanitizedOptions?.length ? sanitizedOptions : void 0
|
|
33215
|
+
});
|
|
33216
|
+
if (!parsed.success) continue;
|
|
33217
|
+
const { label, property, type, options, min, max, pattern, required } = parsed.data;
|
|
33218
|
+
if (property === void 0 && type !== "richtext") continue;
|
|
33219
|
+
const render = sanitizeRenderMap(rawItem.render);
|
|
33220
|
+
items.push({
|
|
33221
|
+
label,
|
|
33222
|
+
property: property ?? BINDING_PROP.INNER_HTML,
|
|
33223
|
+
...type !== void 0 && { type },
|
|
33224
|
+
...options?.length && { options },
|
|
33225
|
+
...render && { render },
|
|
33226
|
+
...min !== void 0 && { min },
|
|
33227
|
+
...max !== void 0 && { max },
|
|
33228
|
+
...pattern !== void 0 && { pattern },
|
|
33229
|
+
...required !== void 0 && { required }
|
|
33230
|
+
});
|
|
33231
|
+
}
|
|
33232
|
+
return items;
|
|
33233
|
+
};
|
|
33234
|
+
const getCurrentValue = (node, property) => {
|
|
33235
|
+
switch (property) {
|
|
33236
|
+
case BINDING_PROP.INNER_TEXT: return node.textContent || "";
|
|
33237
|
+
case BINDING_PROP.INNER_HTML: {
|
|
33238
|
+
const dsiAttr = node.attributes.find((a) => a.name === "dangerouslySetInnerHTML");
|
|
33239
|
+
if (dsiAttr?.value) try {
|
|
33240
|
+
const expr = (0, import_lib$2.parseExpression)(dsiAttr.value, { plugins: ["jsx", "typescript"] });
|
|
33241
|
+
if (import_lib$3.isObjectExpression(expr)) {
|
|
33242
|
+
const htmlProp = expr.properties.find((p) => import_lib$3.isObjectProperty(p) && import_lib$3.isIdentifier(p.key) && p.key.name === "__html");
|
|
33243
|
+
if (htmlProp) {
|
|
33244
|
+
if (import_lib$3.isStringLiteral(htmlProp.value)) return htmlProp.value.value;
|
|
33245
|
+
if (import_lib$3.isTemplateLiteral(htmlProp.value) && htmlProp.value.expressions.length === 0) return htmlProp.value.quasis[0]?.value.cooked ?? htmlProp.value.quasis[0]?.value.raw ?? "";
|
|
33246
|
+
}
|
|
33247
|
+
}
|
|
33248
|
+
} catch {}
|
|
33249
|
+
return node.rawChildren || node.textContent || "";
|
|
33250
|
+
}
|
|
33251
|
+
case BINDING_PROP.CHILDREN: return JSON.stringify(node?.children || []);
|
|
33252
|
+
default: return node.attributes.find((attr) => attr.name === property)?.value || "";
|
|
33253
|
+
}
|
|
33254
|
+
};
|
|
33255
|
+
const hasEditableBindings = (node) => {
|
|
33256
|
+
const bindingAttr = node.dataAttributes.find((attr) => attr.name === DATA_ATTR.BINDING);
|
|
33257
|
+
if (!bindingAttr?.value) return false;
|
|
33258
|
+
return (node.bindings || parseBinding(bindingAttr.value)).length > 0;
|
|
33259
|
+
};
|
|
33260
|
+
const findEditableChildren = (node) => {
|
|
33261
|
+
const editableChildren = [];
|
|
33262
|
+
const traverse = (children) => {
|
|
33263
|
+
if (!children) return;
|
|
33264
|
+
for (const child of children) {
|
|
33265
|
+
if (hasEditableBindings(child)) editableChildren.push(child);
|
|
33266
|
+
traverse(child.children);
|
|
33267
|
+
}
|
|
33268
|
+
};
|
|
33269
|
+
traverse(node.children);
|
|
33270
|
+
return editableChildren;
|
|
33271
|
+
};
|
|
33272
|
+
|
|
33264
33273
|
//#endregion
|
|
33265
33274
|
//#region node_modules/.pnpm/@babel+traverse@7.28.6/node_modules/@babel/traverse/lib/path/lib/virtual-types.js
|
|
33266
33275
|
var require_virtual_types = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
@@ -39707,5 +39716,5 @@ const validateBindingValue = (binding, value) => {
|
|
|
39707
39716
|
};
|
|
39708
39717
|
|
|
39709
39718
|
//#endregion
|
|
39710
|
-
export { __toESM as S,
|
|
39711
|
-
//# sourceMappingURL=ast-
|
|
39719
|
+
export { __toESM as S, parseArrayExpression as _, bulkUpdate as a, require_lib$4 as b, extract as c, getCurrentValue as d, parseBinding as f, extractObjectProperties as g, extractNodeValue as h, replaceIds as i, nanoid as l, createNodeFromValue as m, clone as n, update as o, arrayExpressionToCode as p, fillIds as r, clearExtractCache as s, validateBindingValue as t, findEditableChildren as u, parseValue as v, require_lib$7 as x, generateCode as y };
|
|
39720
|
+
//# sourceMappingURL=ast-fX6Whrjc.mjs.map
|