@jbpark/live-editor 1.12.0 → 1.13.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-9E8pNi7j.mjs → ast-Dq1EfxA5.js} +113 -135
- package/dist/ast-Dq1EfxA5.js.map +1 -0
- package/dist/{document-DocoSXLT.mjs → document-CSIscFpL.js} +54 -369
- package/dist/document-CSIscFpL.js.map +1 -0
- package/dist/{document-BVWq-dmf.d.mts → document-DXOwpvWM.d.ts} +15 -3
- package/dist/{utils/ast/index.d.mts → index-BVjSMVya.d.ts} +3 -3
- package/dist/{index.d.mts → index.d.ts} +18 -2
- package/dist/{index.mjs → index.js} +139 -59
- package/dist/index.js.map +1 -0
- package/dist/{tailwind-CzPhj3D9.mjs → tailwind-CzPhj3D9.js} +1 -1
- package/dist/tailwind-CzPhj3D9.js.map +1 -0
- package/dist/utils/ast/index.d.ts +3 -0
- package/dist/utils/ast/{index.mjs → index.js} +2 -2
- package/dist/utils/{index.d.mts → index.d.ts} +2 -3
- package/dist/utils/{index.mjs → index.js} +2 -2
- package/dist/utils/tailwind/{index.d.mts → index.d.ts} +1 -1
- package/dist/utils/tailwind/{index.mjs → index.js} +1 -1
- package/dist/{utils-DP9WPbBJ.mjs → utils-B11t9ZYd.js} +2 -2
- package/dist/utils-B11t9ZYd.js.map +1 -0
- package/package.json +9 -11
- package/dist/ast-9E8pNi7j.mjs.map +0 -1
- package/dist/document-DocoSXLT.mjs.map +0 -1
- package/dist/index-C8h8TcIl.d.mts +0 -15
- package/dist/index.mjs.map +0 -1
- package/dist/tailwind-CzPhj3D9.mjs.map +0 -1
- package/dist/utils-DP9WPbBJ.mjs.map +0 -1
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { d as require_lib, f as require_lib$2, g as DATA_ATTR, h as CONFIG, l as
|
|
1
|
+
import { d as require_lib, f as require_lib$2, g as DATA_ATTR, h as CONFIG, l as traverse, m as BINDING_PROP, p as require_lib$1, u as createBoundedCache, x as __toESM, y as REGEX } from "./document-CSIscFpL.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import crypto from "crypto";
|
|
4
3
|
//#region src/utils/ast/types.ts
|
|
5
|
-
var import_lib$
|
|
6
|
-
var import_lib$
|
|
4
|
+
var import_lib$1 = require_lib$1();
|
|
5
|
+
var import_lib$2 = /* @__PURE__ */ __toESM(require_lib$2(), 1);
|
|
7
6
|
const BINDING_TYPES = [
|
|
8
7
|
"array",
|
|
9
8
|
"object",
|
|
@@ -20,7 +19,8 @@ const BINDING_TYPES = [
|
|
|
20
19
|
];
|
|
21
20
|
//#endregion
|
|
22
21
|
//#region src/utils/ast/helpers.ts
|
|
23
|
-
var import_lib
|
|
22
|
+
var import_lib = /* @__PURE__ */ __toESM(require_lib(), 1);
|
|
23
|
+
const generate = typeof import_lib.default === "function" ? import_lib.default : import_lib.default.default;
|
|
24
24
|
const wrap = (code) => {
|
|
25
25
|
return `<>${code}</>`;
|
|
26
26
|
};
|
|
@@ -29,22 +29,22 @@ const unwrap = (generated) => {
|
|
|
29
29
|
};
|
|
30
30
|
const attrValue = ({ value, isStringLiteral }) => {
|
|
31
31
|
if (value === null) return null;
|
|
32
|
-
if (isStringLiteral) return import_lib$
|
|
32
|
+
if (isStringLiteral) return import_lib$2.stringLiteral(value);
|
|
33
33
|
const trimmed = value.trim();
|
|
34
|
-
if (REGEX.NUMBER.test(trimmed)) return import_lib$
|
|
34
|
+
if (REGEX.NUMBER.test(trimmed)) return import_lib$2.jsxExpressionContainer(import_lib$2.numericLiteral(parseFloat(trimmed)));
|
|
35
35
|
if (REGEX.BOOLEAN_OR_NULL.test(trimmed)) {
|
|
36
|
-
const expr = (0, import_lib$
|
|
37
|
-
return import_lib$
|
|
36
|
+
const expr = (0, import_lib$1.parseExpression)(trimmed, { plugins: ["jsx", "typescript"] });
|
|
37
|
+
return import_lib$2.jsxExpressionContainer(expr);
|
|
38
38
|
}
|
|
39
39
|
try {
|
|
40
|
-
const expr = (0, import_lib$
|
|
41
|
-
return import_lib$
|
|
40
|
+
const expr = (0, import_lib$1.parseExpression)(trimmed, { plugins: ["jsx", "typescript"] });
|
|
41
|
+
return import_lib$2.jsxExpressionContainer(expr);
|
|
42
42
|
} catch {
|
|
43
|
-
return import_lib$
|
|
43
|
+
return import_lib$2.stringLiteral(trimmed);
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
const generateCode = (node) => {
|
|
47
|
-
return (
|
|
47
|
+
return generate(node, { jsescOption: { minimal: true } }).code;
|
|
48
48
|
};
|
|
49
49
|
//#endregion
|
|
50
50
|
//#region src/utils/ast/value.ts
|
|
@@ -58,23 +58,23 @@ const dedent = (str) => {
|
|
|
58
58
|
return indent === Infinity ? str.trim() : lines.map((line) => line.slice(indent)).join("\n");
|
|
59
59
|
};
|
|
60
60
|
const evaluateLiteral = (node) => {
|
|
61
|
-
if (import_lib$
|
|
62
|
-
if (import_lib$
|
|
63
|
-
if (import_lib$
|
|
64
|
-
if (import_lib$
|
|
65
|
-
if (import_lib$
|
|
66
|
-
if (import_lib$
|
|
67
|
-
if (import_lib$
|
|
68
|
-
if (import_lib$
|
|
69
|
-
if (import_lib$
|
|
70
|
-
if (import_lib$
|
|
61
|
+
if (import_lib$2.isStringLiteral(node)) return node.value;
|
|
62
|
+
if (import_lib$2.isNumericLiteral(node)) return node.value;
|
|
63
|
+
if (import_lib$2.isBooleanLiteral(node)) return node.value;
|
|
64
|
+
if (import_lib$2.isNullLiteral(node)) return null;
|
|
65
|
+
if (import_lib$2.isIdentifier(node) && node.name === "undefined") return;
|
|
66
|
+
if (import_lib$2.isUnaryExpression(node) && node.operator === "-" && import_lib$2.isNumericLiteral(node.argument)) return -node.argument.value;
|
|
67
|
+
if (import_lib$2.isTemplateLiteral(node) && node.expressions.length === 0) return node.quasis[0]?.value.cooked ?? node.quasis[0]?.value.raw ?? "";
|
|
68
|
+
if (import_lib$2.isJSXElement(node) || import_lib$2.isJSXFragment(node)) return generateCode(node);
|
|
69
|
+
if (import_lib$2.isArrayExpression(node)) return node.elements.map((element) => element ? evaluateLiteral(element) : null);
|
|
70
|
+
if (import_lib$2.isObjectExpression(node)) {
|
|
71
71
|
const result = {};
|
|
72
72
|
for (const prop of node.properties) {
|
|
73
|
-
if (!import_lib$
|
|
73
|
+
if (!import_lib$2.isObjectProperty(prop)) continue;
|
|
74
74
|
let key = null;
|
|
75
|
-
if (import_lib$
|
|
76
|
-
else if (import_lib$
|
|
77
|
-
else if (import_lib$
|
|
75
|
+
if (import_lib$2.isIdentifier(prop.key)) key = prop.key.name;
|
|
76
|
+
else if (import_lib$2.isStringLiteral(prop.key)) key = prop.key.value;
|
|
77
|
+
else if (import_lib$2.isNumericLiteral(prop.key)) key = String(prop.key.value);
|
|
78
78
|
if (key === null) continue;
|
|
79
79
|
result[key] = evaluateLiteral(prop.value);
|
|
80
80
|
}
|
|
@@ -94,31 +94,31 @@ const parseValue = (value) => {
|
|
|
94
94
|
}
|
|
95
95
|
if (trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]")) {
|
|
96
96
|
try {
|
|
97
|
-
const ast = (0, import_lib$
|
|
98
|
-
if (import_lib$
|
|
97
|
+
const ast = (0, import_lib$1.parseExpression)(trimmed, { plugins: ["jsx", "typescript"] });
|
|
98
|
+
if (import_lib$2.isObjectExpression(ast) || import_lib$2.isArrayExpression(ast)) return evaluateLiteral(ast);
|
|
99
99
|
} catch {}
|
|
100
100
|
return value;
|
|
101
101
|
}
|
|
102
102
|
return value;
|
|
103
103
|
};
|
|
104
104
|
const extractNodeValue = (node) => {
|
|
105
|
-
if (import_lib$
|
|
105
|
+
if (import_lib$2.isBooleanLiteral(node)) return {
|
|
106
106
|
type: "boolean",
|
|
107
107
|
value: node.value
|
|
108
108
|
};
|
|
109
|
-
if (import_lib$
|
|
109
|
+
if (import_lib$2.isNumericLiteral(node)) return {
|
|
110
110
|
type: "number",
|
|
111
111
|
value: node.value
|
|
112
112
|
};
|
|
113
|
-
if (import_lib$
|
|
113
|
+
if (import_lib$2.isUnaryExpression(node) && node.operator === "-" && import_lib$2.isNumericLiteral(node.argument)) return {
|
|
114
114
|
type: "number",
|
|
115
115
|
value: -node.argument.value
|
|
116
116
|
};
|
|
117
|
-
if (import_lib$
|
|
117
|
+
if (import_lib$2.isStringLiteral(node)) return {
|
|
118
118
|
type: "string",
|
|
119
119
|
value: node.value
|
|
120
120
|
};
|
|
121
|
-
if (import_lib$
|
|
121
|
+
if (import_lib$2.isTemplateLiteral(node)) {
|
|
122
122
|
if (node.expressions.length === 0 && node.quasis.length === 1) return {
|
|
123
123
|
type: "string",
|
|
124
124
|
value: dedent(node.quasis[0].value.cooked ?? node.quasis[0].value.raw)
|
|
@@ -128,19 +128,19 @@ const extractNodeValue = (node) => {
|
|
|
128
128
|
value: generateCode(node)
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
|
-
if (import_lib$
|
|
131
|
+
if (import_lib$2.isNullLiteral(node)) return {
|
|
132
132
|
type: "null",
|
|
133
133
|
value: null
|
|
134
134
|
};
|
|
135
|
-
if (import_lib$
|
|
135
|
+
if (import_lib$2.isArrayExpression(node)) return {
|
|
136
136
|
type: "array",
|
|
137
137
|
value: generateCode(node)
|
|
138
138
|
};
|
|
139
|
-
if (import_lib$
|
|
139
|
+
if (import_lib$2.isObjectExpression(node)) return {
|
|
140
140
|
type: "object",
|
|
141
141
|
value: generateCode(node)
|
|
142
142
|
};
|
|
143
|
-
if (import_lib$
|
|
143
|
+
if (import_lib$2.isJSXElement(node) || import_lib$2.isJSXFragment(node)) return {
|
|
144
144
|
type: "string",
|
|
145
145
|
value: generateCode(node)
|
|
146
146
|
};
|
|
@@ -151,10 +151,10 @@ const extractNodeValue = (node) => {
|
|
|
151
151
|
};
|
|
152
152
|
const createNodeFromValue = (type, value) => {
|
|
153
153
|
switch (type) {
|
|
154
|
-
case "boolean": return import_lib$
|
|
155
|
-
case "number": return import_lib$
|
|
156
|
-
case "string": return import_lib$
|
|
157
|
-
case "null": return import_lib$
|
|
154
|
+
case "boolean": return import_lib$2.booleanLiteral(value === true);
|
|
155
|
+
case "number": return import_lib$2.numericLiteral(Number(value));
|
|
156
|
+
case "string": return import_lib$2.stringLiteral(String(value));
|
|
157
|
+
case "null": return import_lib$2.nullLiteral();
|
|
158
158
|
case "array":
|
|
159
159
|
case "object":
|
|
160
160
|
case "unknown": return null;
|
|
@@ -163,8 +163,8 @@ const createNodeFromValue = (type, value) => {
|
|
|
163
163
|
};
|
|
164
164
|
const parseArrayExpression = (value) => {
|
|
165
165
|
try {
|
|
166
|
-
const ast = (0, import_lib$
|
|
167
|
-
if (!import_lib$
|
|
166
|
+
const ast = (0, import_lib$1.parseExpression)(value, { plugins: ["jsx", "typescript"] });
|
|
167
|
+
if (!import_lib$2.isArrayExpression(ast)) return null;
|
|
168
168
|
return ast;
|
|
169
169
|
} catch (error) {
|
|
170
170
|
console.error("❌ Array parsing error:", error);
|
|
@@ -174,7 +174,7 @@ const parseArrayExpression = (value) => {
|
|
|
174
174
|
const extractObjectProperties = (element) => {
|
|
175
175
|
const properties = {};
|
|
176
176
|
element.properties.forEach((prop) => {
|
|
177
|
-
if (import_lib$
|
|
177
|
+
if (import_lib$2.isObjectProperty(prop) && import_lib$2.isIdentifier(prop.key)) {
|
|
178
178
|
const key = prop.key.name;
|
|
179
179
|
if (key === "children") return;
|
|
180
180
|
const extracted = extractNodeValue(prop.value);
|
|
@@ -187,7 +187,7 @@ const extractObjectProperties = (element) => {
|
|
|
187
187
|
return properties;
|
|
188
188
|
};
|
|
189
189
|
const arrayExpressionToCode = (elements) => {
|
|
190
|
-
const nextAst = import_lib$
|
|
190
|
+
const nextAst = import_lib$2.arrayExpression(elements);
|
|
191
191
|
return generateCode(nextAst);
|
|
192
192
|
};
|
|
193
193
|
//#endregion
|
|
@@ -278,12 +278,12 @@ const getCurrentValue = (node, property) => {
|
|
|
278
278
|
case BINDING_PROP.INNER_HTML: {
|
|
279
279
|
const dsiAttr = node.attributes.find((a) => a.name === "dangerouslySetInnerHTML");
|
|
280
280
|
if (dsiAttr?.value) try {
|
|
281
|
-
const expr = (0, import_lib$
|
|
282
|
-
if (import_lib$
|
|
283
|
-
const htmlProp = expr.properties.find((p) => import_lib$
|
|
281
|
+
const expr = (0, import_lib$1.parseExpression)(dsiAttr.value, { plugins: ["jsx", "typescript"] });
|
|
282
|
+
if (import_lib$2.isObjectExpression(expr)) {
|
|
283
|
+
const htmlProp = expr.properties.find((p) => import_lib$2.isObjectProperty(p) && import_lib$2.isIdentifier(p.key) && p.key.name === "__html");
|
|
284
284
|
if (htmlProp) {
|
|
285
|
-
if (import_lib$
|
|
286
|
-
if (import_lib$
|
|
285
|
+
if (import_lib$2.isStringLiteral(htmlProp.value)) return htmlProp.value.value;
|
|
286
|
+
if (import_lib$2.isTemplateLiteral(htmlProp.value) && htmlProp.value.expressions.length === 0) return htmlProp.value.quasis[0]?.value.cooked ?? htmlProp.value.quasis[0]?.value.raw ?? "";
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
} catch {}
|
|
@@ -311,65 +311,43 @@ const findEditableChildren = (node) => {
|
|
|
311
311
|
return editableChildren;
|
|
312
312
|
};
|
|
313
313
|
//#endregion
|
|
314
|
-
//#region node_modules/.pnpm/nanoid@3.3.18/node_modules/nanoid/
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
let poolOffset;
|
|
322
|
-
let fillPool = (bytes) => {
|
|
323
|
-
if (bytes < 0) throw new RangeError("Wrong ID size");
|
|
324
|
-
try {
|
|
325
|
-
if (!pool || pool.length < bytes) {
|
|
326
|
-
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
327
|
-
crypto.randomFillSync(pool);
|
|
328
|
-
poolOffset = 0;
|
|
329
|
-
} else if (poolOffset + bytes > pool.length) {
|
|
330
|
-
crypto.randomFillSync(pool);
|
|
331
|
-
poolOffset = 0;
|
|
332
|
-
}
|
|
333
|
-
} catch (e) {
|
|
334
|
-
pool = void 0;
|
|
335
|
-
throw e;
|
|
336
|
-
}
|
|
337
|
-
poolOffset += bytes;
|
|
338
|
-
};
|
|
339
|
-
let nanoid = (size = 21) => {
|
|
340
|
-
fillPool(size |= 0);
|
|
341
|
-
let id = "";
|
|
342
|
-
for (let i = poolOffset - size; i < poolOffset; i++) id += urlAlphabet[pool[i] & 63];
|
|
314
|
+
//#region node_modules/.pnpm/nanoid@3.3.18/node_modules/nanoid/index.browser.js
|
|
315
|
+
let nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
|
316
|
+
byte &= 63;
|
|
317
|
+
if (byte < 36) id += byte.toString(36);
|
|
318
|
+
else if (byte < 62) id += (byte - 26).toString(36).toUpperCase();
|
|
319
|
+
else if (byte > 62) id += "-";
|
|
320
|
+
else id += "_";
|
|
343
321
|
return id;
|
|
344
|
-
};
|
|
322
|
+
}, "");
|
|
345
323
|
//#endregion
|
|
346
324
|
//#region src/utils/ast/extract.ts
|
|
347
325
|
const collectText = (children) => {
|
|
348
|
-
return children.filter((c) => import_lib$
|
|
326
|
+
return children.filter((c) => import_lib$2.isJSXText(c)).map((c) => c.value.trim()).filter((v) => v.length).join(" ");
|
|
349
327
|
};
|
|
350
328
|
const getTagName = (opening) => {
|
|
351
|
-
if (import_lib$
|
|
352
|
-
if (import_lib$
|
|
329
|
+
if (import_lib$2.isJSXIdentifier(opening.name)) return opening.name.name;
|
|
330
|
+
if (import_lib$2.isJSXMemberExpression(opening.name)) return resolveMemberName(opening.name);
|
|
353
331
|
return "";
|
|
354
332
|
};
|
|
355
333
|
const resolveMemberName = (expr) => {
|
|
356
334
|
const parts = [];
|
|
357
335
|
const collectMemberParts = (node) => {
|
|
358
|
-
if (import_lib$
|
|
359
|
-
else if (import_lib$
|
|
336
|
+
if (import_lib$2.isJSXIdentifier(node)) parts.push(node.name);
|
|
337
|
+
else if (import_lib$2.isJSXMemberExpression(node)) {
|
|
360
338
|
collectMemberParts(node.object);
|
|
361
|
-
if (import_lib$
|
|
339
|
+
if (import_lib$2.isJSXIdentifier(node.property)) parts.push(node.property.name);
|
|
362
340
|
}
|
|
363
341
|
};
|
|
364
342
|
collectMemberParts(expr.object);
|
|
365
|
-
if (import_lib$
|
|
343
|
+
if (import_lib$2.isJSXIdentifier(expr.property)) parts.push(expr.property.name);
|
|
366
344
|
return parts.join(".");
|
|
367
345
|
};
|
|
368
346
|
const parseJSXName = (tagName) => {
|
|
369
347
|
const parts = tagName.split(".");
|
|
370
|
-
if (parts.length === 1) return import_lib$
|
|
371
|
-
let expr = import_lib$
|
|
372
|
-
for (let i = 1; i < parts.length; i++) expr = import_lib$
|
|
348
|
+
if (parts.length === 1) return import_lib$2.jsxIdentifier(parts[0]);
|
|
349
|
+
let expr = import_lib$2.jsxIdentifier(parts[0]);
|
|
350
|
+
for (let i = 1; i < parts.length; i++) expr = import_lib$2.jsxMemberExpression(expr, import_lib$2.jsxIdentifier(parts[i]));
|
|
373
351
|
return expr;
|
|
374
352
|
};
|
|
375
353
|
const extractCache = createBoundedCache(CONFIG.CACHE_LIMIT);
|
|
@@ -377,15 +355,15 @@ const extractAttributes = (attributes) => {
|
|
|
377
355
|
const allAttrs = [];
|
|
378
356
|
const dataAttrs = [];
|
|
379
357
|
for (const attr of attributes) {
|
|
380
|
-
if (!import_lib$
|
|
358
|
+
if (!import_lib$2.isJSXAttribute(attr) || !import_lib$2.isJSXIdentifier(attr.name)) continue;
|
|
381
359
|
const name = attr.name.name;
|
|
382
360
|
let value = null;
|
|
383
361
|
let isStringLiteral = false;
|
|
384
362
|
if (attr.value) {
|
|
385
|
-
if (import_lib$
|
|
363
|
+
if (import_lib$2.isStringLiteral(attr.value)) {
|
|
386
364
|
value = attr.value.value;
|
|
387
365
|
isStringLiteral = true;
|
|
388
|
-
} else if (import_lib$
|
|
366
|
+
} else if (import_lib$2.isJSXExpressionContainer(attr.value)) try {
|
|
389
367
|
value = generateCode(attr.value.expression);
|
|
390
368
|
isStringLiteral = false;
|
|
391
369
|
} catch {
|
|
@@ -407,7 +385,7 @@ const extractAttributes = (attributes) => {
|
|
|
407
385
|
};
|
|
408
386
|
const buildChildElements = (node) => {
|
|
409
387
|
const childElements = [];
|
|
410
|
-
if (node.textContent) childElements.push(import_lib$
|
|
388
|
+
if (node.textContent) childElements.push(import_lib$2.jsxText(node.textContent));
|
|
411
389
|
node.children?.forEach((child) => {
|
|
412
390
|
const childJSX = nodeToJSX(child);
|
|
413
391
|
if (childJSX) childElements.push(childJSX);
|
|
@@ -418,22 +396,22 @@ const nodeToJSX = (node) => {
|
|
|
418
396
|
try {
|
|
419
397
|
if (node.isFragment) {
|
|
420
398
|
const childElements = buildChildElements(node);
|
|
421
|
-
return import_lib$
|
|
399
|
+
return import_lib$2.jsxFragment(import_lib$2.jsxOpeningFragment(), import_lib$2.jsxClosingFragment(), childElements);
|
|
422
400
|
}
|
|
423
401
|
if (node.tagName === "div" && node.dataAttributes.some((attr) => attr.name === "data-item")) {
|
|
424
402
|
if (node.children) return nodeToJSX(node.children[0]);
|
|
425
403
|
return null;
|
|
426
404
|
}
|
|
427
405
|
const attributes = node.attributes.map((attr) => {
|
|
428
|
-
const attrName = import_lib$
|
|
429
|
-
if (!attr.value) return import_lib$
|
|
430
|
-
return import_lib$
|
|
406
|
+
const attrName = import_lib$2.jsxIdentifier(attr.name);
|
|
407
|
+
if (!attr.value) return import_lib$2.jsxAttribute(attrName, null);
|
|
408
|
+
return import_lib$2.jsxAttribute(attrName, attrValue(attr));
|
|
431
409
|
});
|
|
432
410
|
const elementName = parseJSXName(node.tagName);
|
|
433
|
-
const openingElement = import_lib$
|
|
434
|
-
const closingElement = import_lib$
|
|
411
|
+
const openingElement = import_lib$2.jsxOpeningElement(elementName, attributes);
|
|
412
|
+
const closingElement = import_lib$2.jsxClosingElement(elementName);
|
|
435
413
|
const children = buildChildElements(node);
|
|
436
|
-
return import_lib$
|
|
414
|
+
return import_lib$2.jsxElement(openingElement, closingElement, children, false);
|
|
437
415
|
} catch (error) {
|
|
438
416
|
console.error("❌ DataAttrNode to JSX conversion error:", error);
|
|
439
417
|
return null;
|
|
@@ -463,21 +441,21 @@ const createFragmentNode = (textContent, children) => ({
|
|
|
463
441
|
isFragment: true
|
|
464
442
|
});
|
|
465
443
|
const processChildrenBinding = (jsxElement, processedNodes, shouldWrap = true) => {
|
|
466
|
-
const jsxChildren = jsxElement.children.filter((child) => import_lib$
|
|
444
|
+
const jsxChildren = jsxElement.children.filter((child) => import_lib$2.isJSXElement(child) || import_lib$2.isJSXFragment(child));
|
|
467
445
|
if (!jsxChildren.length) return;
|
|
468
446
|
const childrenNodes = [];
|
|
469
447
|
jsxChildren.forEach((child) => {
|
|
470
|
-
if (import_lib$
|
|
448
|
+
if (import_lib$2.isJSXElement(child)) {
|
|
471
449
|
const childResults = extractFromNode(child, processedNodes);
|
|
472
450
|
if (shouldWrap) {
|
|
473
451
|
const wrapperNode = createWrapperNode(collectText(child.children), childResults);
|
|
474
452
|
childrenNodes.push(wrapperNode);
|
|
475
453
|
} else childrenNodes.push(...childResults);
|
|
476
|
-
} else if (import_lib$
|
|
454
|
+
} else if (import_lib$2.isJSXFragment(child)) {
|
|
477
455
|
processedNodes?.add(child);
|
|
478
456
|
const fragmentChildren = [];
|
|
479
457
|
child.children.forEach((fragmentChild) => {
|
|
480
|
-
if (import_lib$
|
|
458
|
+
if (import_lib$2.isJSXElement(fragmentChild)) {
|
|
481
459
|
const childResults = extractFromNode(fragmentChild, processedNodes);
|
|
482
460
|
fragmentChildren.push(...childResults);
|
|
483
461
|
}
|
|
@@ -491,21 +469,21 @@ const processChildrenBinding = (jsxElement, processedNodes, shouldWrap = true) =
|
|
|
491
469
|
return childrenNodes.length ? childrenNodes : void 0;
|
|
492
470
|
};
|
|
493
471
|
const skipItemsChildren = (jsxElement, processedNodes, propertyName = "items") => {
|
|
494
|
-
const itemsAttr = jsxElement.openingElement.attributes.find((attr) => import_lib$
|
|
495
|
-
if (!itemsAttr || !import_lib$
|
|
496
|
-
if (itemsAttr.value && import_lib$
|
|
497
|
-
if (import_lib$
|
|
498
|
-
if (import_lib$
|
|
472
|
+
const itemsAttr = jsxElement.openingElement.attributes.find((attr) => import_lib$2.isJSXAttribute(attr) && import_lib$2.isJSXIdentifier(attr.name) && attr.name.name === propertyName);
|
|
473
|
+
if (!itemsAttr || !import_lib$2.isJSXAttribute(itemsAttr)) return;
|
|
474
|
+
if (itemsAttr.value && import_lib$2.isJSXExpressionContainer(itemsAttr.value) && import_lib$2.isArrayExpression(itemsAttr.value.expression)) itemsAttr.value.expression.elements.forEach((element) => {
|
|
475
|
+
if (import_lib$2.isObjectExpression(element)) element.properties.forEach((prop) => {
|
|
476
|
+
if (import_lib$2.isObjectProperty(prop) && import_lib$2.isIdentifier(prop.key) && import_lib$2.isJSXElement(prop.value)) markProcessedJSX(prop.value, processedNodes);
|
|
499
477
|
});
|
|
500
478
|
});
|
|
501
479
|
};
|
|
502
480
|
const markProcessedJSX = (node, processedNodes) => {
|
|
503
|
-
if (import_lib$
|
|
481
|
+
if (import_lib$2.isJSXElement(node) || import_lib$2.isJSXFragment(node)) {
|
|
504
482
|
processedNodes.add(node);
|
|
505
483
|
node.children.forEach((child) => markProcessedJSX(child, processedNodes));
|
|
506
484
|
return;
|
|
507
485
|
}
|
|
508
|
-
if (import_lib$
|
|
486
|
+
if (import_lib$2.isJSXExpressionContainer(node) || import_lib$2.isParenthesizedExpression(node)) markProcessedJSX(node.expression, processedNodes);
|
|
509
487
|
};
|
|
510
488
|
const readNodeBindingInfo = (node) => {
|
|
511
489
|
const opening = node.openingElement;
|
|
@@ -530,14 +508,14 @@ const readNodeBindingInfo = (node) => {
|
|
|
530
508
|
};
|
|
531
509
|
const parseToNodes = (raw) => {
|
|
532
510
|
const wrapped = wrap(raw);
|
|
533
|
-
const ast = (0, import_lib$
|
|
511
|
+
const ast = (0, import_lib$1.parse)(wrapped, {
|
|
534
512
|
sourceType: "module",
|
|
535
513
|
plugins: ["jsx", "typescript"],
|
|
536
514
|
errorRecovery: true
|
|
537
515
|
});
|
|
538
516
|
const results = [];
|
|
539
517
|
const processedNodes = /* @__PURE__ */ new WeakSet();
|
|
540
|
-
(
|
|
518
|
+
traverse(ast, { JSXElement(path) {
|
|
541
519
|
if (processedNodes.has(path.node)) return;
|
|
542
520
|
const { tagName, allAttrs, dataAttrs, bindings, childrenBinding, arrayBindings, rawChildren } = readNodeBindingInfo(path.node);
|
|
543
521
|
if (!tagName || !dataAttrs.length) return;
|
|
@@ -595,13 +573,13 @@ function clearExtractCache() {
|
|
|
595
573
|
//#region src/utils/ast/update.ts
|
|
596
574
|
const updateInnerText = (path, value) => {
|
|
597
575
|
const jsxChildren = path.node.children;
|
|
598
|
-
for (let i = jsxChildren.length - 1; i >= 0; i--) if (import_lib$
|
|
599
|
-
jsxChildren.push(import_lib$
|
|
576
|
+
for (let i = jsxChildren.length - 1; i >= 0; i--) if (import_lib$2.isJSXText(jsxChildren[i])) jsxChildren.splice(i, 1);
|
|
577
|
+
jsxChildren.push(import_lib$2.jsxText(value));
|
|
600
578
|
return true;
|
|
601
579
|
};
|
|
602
580
|
const injectPlaceholder = (prefix, value, placeholders, { asRawContent = false } = {}) => {
|
|
603
581
|
const name = `__${prefix}_${nanoid(6)}__`;
|
|
604
|
-
const container = import_lib$
|
|
582
|
+
const container = import_lib$2.jsxExpressionContainer(import_lib$2.identifier(name));
|
|
605
583
|
placeholders.set(asRawContent ? `{${name}}` : name, value);
|
|
606
584
|
return container;
|
|
607
585
|
};
|
|
@@ -626,15 +604,15 @@ const updateChildren = (path, value) => {
|
|
|
626
604
|
const updateRichtext = (path, value) => {
|
|
627
605
|
path.node.children = [];
|
|
628
606
|
const opening = path.node.openingElement;
|
|
629
|
-
const htmlObject = import_lib$
|
|
630
|
-
const existingAttr = opening.attributes.find((a) => import_lib$
|
|
631
|
-
if (existingAttr && import_lib$
|
|
632
|
-
else opening.attributes.push(import_lib$
|
|
607
|
+
const htmlObject = import_lib$2.objectExpression([import_lib$2.objectProperty(import_lib$2.identifier("__html"), import_lib$2.stringLiteral(value))]);
|
|
608
|
+
const existingAttr = opening.attributes.find((a) => import_lib$2.isJSXAttribute(a) && import_lib$2.isJSXIdentifier(a.name) && a.name.name === "dangerouslySetInnerHTML");
|
|
609
|
+
if (existingAttr && import_lib$2.isJSXAttribute(existingAttr)) existingAttr.value = import_lib$2.jsxExpressionContainer(htmlObject);
|
|
610
|
+
else opening.attributes.push(import_lib$2.jsxAttribute(import_lib$2.jsxIdentifier("dangerouslySetInnerHTML"), import_lib$2.jsxExpressionContainer(htmlObject)));
|
|
633
611
|
return true;
|
|
634
612
|
};
|
|
635
613
|
const updateAttribute = (opening, propertyName, value) => {
|
|
636
|
-
const customAttr = opening.attributes.find((attr) => import_lib$
|
|
637
|
-
if (customAttr && import_lib$
|
|
614
|
+
const customAttr = opening.attributes.find((attr) => import_lib$2.isJSXAttribute(attr) && import_lib$2.isJSXIdentifier(attr.name) && attr.name.name === propertyName);
|
|
615
|
+
if (customAttr && import_lib$2.isJSXAttribute(customAttr)) {
|
|
638
616
|
const trimmed = value.trim();
|
|
639
617
|
const isExpression = trimmed.startsWith("[") || trimmed.startsWith("{") || REGEX.NUMBER.test(trimmed) || REGEX.BOOLEAN_OR_NULL.test(trimmed);
|
|
640
618
|
customAttr.value = attrValue({
|
|
@@ -649,22 +627,22 @@ const updateAttribute = (opening, propertyName, value) => {
|
|
|
649
627
|
const update = (code, dataId, label, value) => {
|
|
650
628
|
try {
|
|
651
629
|
const wrapped = wrap(code);
|
|
652
|
-
const ast = (0, import_lib$
|
|
630
|
+
const ast = (0, import_lib$1.parse)(wrapped, {
|
|
653
631
|
sourceType: "module",
|
|
654
632
|
plugins: ["jsx", "typescript"]
|
|
655
633
|
});
|
|
656
634
|
let changed = false;
|
|
657
635
|
const jsxPlaceholders = /* @__PURE__ */ new Map();
|
|
658
|
-
(
|
|
636
|
+
traverse(ast, { JSXElement(path) {
|
|
659
637
|
const opening = path.node.openingElement;
|
|
660
638
|
if (!opening.attributes.find((attr) => {
|
|
661
|
-
return import_lib$
|
|
639
|
+
return import_lib$2.isJSXAttribute(attr) && import_lib$2.isJSXIdentifier(attr.name) && attr.name.name === DATA_ATTR.ID && attr.value && import_lib$2.isStringLiteral(attr.value) && attr.value.value === dataId;
|
|
662
640
|
})) return;
|
|
663
|
-
const bindingAttr = opening.attributes.find((attr) => import_lib$
|
|
641
|
+
const bindingAttr = opening.attributes.find((attr) => import_lib$2.isJSXAttribute(attr) && import_lib$2.isJSXIdentifier(attr.name) && attr.name.name === DATA_ATTR.BINDING);
|
|
664
642
|
if (!bindingAttr?.value) return;
|
|
665
643
|
let bindingValue = "";
|
|
666
|
-
if (import_lib$
|
|
667
|
-
else if (import_lib$
|
|
644
|
+
if (import_lib$2.isStringLiteral(bindingAttr.value)) bindingValue = bindingAttr.value.value;
|
|
645
|
+
else if (import_lib$2.isJSXExpressionContainer(bindingAttr.value)) try {
|
|
668
646
|
bindingValue = generateCode(bindingAttr.value.expression);
|
|
669
647
|
} catch {
|
|
670
648
|
return;
|
|
@@ -683,8 +661,8 @@ const update = (code, dataId, label, value) => {
|
|
|
683
661
|
changed = updateChildren(path, value);
|
|
684
662
|
break;
|
|
685
663
|
default: if (propertyBinding.type === "jsx") {
|
|
686
|
-
const attr = opening.attributes.find((a) => import_lib$
|
|
687
|
-
if (attr && import_lib$
|
|
664
|
+
const attr = opening.attributes.find((a) => import_lib$2.isJSXAttribute(a) && import_lib$2.isJSXIdentifier(a.name) && a.name.name === propertyBinding.property);
|
|
665
|
+
if (attr && import_lib$2.isJSXAttribute(attr)) {
|
|
688
666
|
attr.value = injectPlaceholder("JSX", value.trim(), jsxPlaceholders);
|
|
689
667
|
changed = true;
|
|
690
668
|
}
|
|
@@ -735,10 +713,10 @@ const fillIds = (code, generateId = () => nanoid(6)) => {
|
|
|
735
713
|
});
|
|
736
714
|
};
|
|
737
715
|
const clone = (element, generateId = () => nanoid(6)) => {
|
|
738
|
-
const cloned = import_lib$
|
|
716
|
+
const cloned = import_lib$2.cloneNode(element, true);
|
|
739
717
|
const generatedCode = generateCode(cloned);
|
|
740
718
|
const code = replaceIds(generatedCode, generateId);
|
|
741
|
-
return (0, import_lib$
|
|
719
|
+
return (0, import_lib$1.parseExpression)(code, { plugins: ["jsx", "typescript"] });
|
|
742
720
|
};
|
|
743
721
|
//#endregion
|
|
744
722
|
//#region src/utils/ast/validate.ts
|
|
@@ -792,4 +770,4 @@ const validateBindingValue = (binding, value) => {
|
|
|
792
770
|
//#endregion
|
|
793
771
|
export { parseArrayExpression as _, bulkUpdate as a, 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, generateCode as y };
|
|
794
772
|
|
|
795
|
-
//# sourceMappingURL=ast-
|
|
773
|
+
//# sourceMappingURL=ast-Dq1EfxA5.js.map
|