@jbpark/live-editor 3.2.0 → 4.0.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.
Files changed (52) hide show
  1. package/dist/ast-CZwpVrJv.js +851 -0
  2. package/dist/ast-CZwpVrJv.js.map +1 -0
  3. package/dist/{boundary-BTP1nfG6.js → boundary-C90q3YsT.js} +8 -7
  4. package/dist/boundary-C90q3YsT.js.map +1 -0
  5. package/dist/{context-649REFsj.js → context-Y-M9fViD.js} +4 -8
  6. package/dist/context-Y-M9fViD.js.map +1 -0
  7. package/dist/{core-D3q5rpuz.js → core-Co8Nlq16.js} +2 -2
  8. package/dist/core-Co8Nlq16.js.map +1 -0
  9. package/dist/dnd/index.d.ts +2 -2
  10. package/dist/dnd/index.js +2 -2
  11. package/dist/{dnd-DTT37EbA.js → dnd-ClnGRNaY.js} +386 -324
  12. package/dist/dnd-ClnGRNaY.js.map +1 -0
  13. package/dist/editor/index.d.ts +1 -1
  14. package/dist/editor/index.js +2 -2
  15. package/dist/{editor-LzqHe_-F.js → editor-COKGtmfE.js} +3 -3
  16. package/dist/{editor-LzqHe_-F.js.map → editor-COKGtmfE.js.map} +1 -1
  17. package/dist/error/index.d.ts +1 -1
  18. package/dist/error/index.js +2 -2
  19. package/dist/{error-CO0EbMlA.js → error-o0SBwtTv.js} +2 -2
  20. package/dist/{error-CO0EbMlA.js.map → error-o0SBwtTv.js.map} +1 -1
  21. package/dist/{document-C6bNHl7l.js → extract-abHYmNsu.js} +927 -42
  22. package/dist/extract-abHYmNsu.js.map +1 -0
  23. package/dist/{index-Ba8jGXSM.d.ts → index-BQdZ6LrR.d.ts} +5 -1
  24. package/dist/{index-DxbG789f.d.ts → index-B_p74BRM.d.ts} +29 -14
  25. package/dist/{index-CCynrS6c.d.ts → index-DNNj_0ba.d.ts} +3 -2
  26. package/dist/{index-lgHdCda5.d.ts → index-DQkL37eL.d.ts} +10 -2
  27. package/dist/{index-DswWDEXZ.d.ts → index-Doh4VTXr.d.ts} +65 -35
  28. package/dist/index.d.ts +7 -7
  29. package/dist/index.js +5 -5
  30. package/dist/index.js.map +1 -1
  31. package/dist/preview/index.d.ts +2 -2
  32. package/dist/preview/index.js +3 -2
  33. package/dist/{preview-CWT0lgwq.js → preview-DKyKKcu7.js} +4 -4
  34. package/dist/{preview-CWT0lgwq.js.map → preview-DKyKKcu7.js.map} +1 -1
  35. package/dist/provider/index.js +1 -1
  36. package/dist/{use-dynamic-tailwind-DAhKGsY4.js → use-dynamic-tailwind-BF8TQ3Yy.js} +83 -27
  37. package/dist/use-dynamic-tailwind-BF8TQ3Yy.js.map +1 -0
  38. package/dist/utils/ast/index.d.ts +2 -2
  39. package/dist/utils/ast/index.js +3 -3
  40. package/dist/utils/index.d.ts +4 -7
  41. package/dist/utils/index.js +3 -3
  42. package/dist/{utils-WyxPYZGh.js → utils-BQ7WL7Jh.js} +33 -16
  43. package/dist/{utils-WyxPYZGh.js.map → utils-BQ7WL7Jh.js.map} +1 -1
  44. package/package.json +3 -1
  45. package/dist/ast-Bx2Avo4d.js +0 -1530
  46. package/dist/ast-Bx2Avo4d.js.map +0 -1
  47. package/dist/boundary-BTP1nfG6.js.map +0 -1
  48. package/dist/context-649REFsj.js.map +0 -1
  49. package/dist/core-D3q5rpuz.js.map +0 -1
  50. package/dist/dnd-DTT37EbA.js.map +0 -1
  51. package/dist/document-C6bNHl7l.js.map +0 -1
  52. package/dist/use-dynamic-tailwind-DAhKGsY4.js.map +0 -1
@@ -1,1530 +0,0 @@
1
- import { C as __toESM, _ as CONFIG, d as createBoundedCache, f as nanoid, g as BINDING_PROP, h as require_lib$1, m as require_lib$2, p as require_lib, u as traverse, v as DATA_ATTR, x as REGEX } from "./document-C6bNHl7l.js";
2
- import { z } from "zod";
3
- //#region src/utils/ast/types.ts
4
- var import_lib$1 = require_lib$1();
5
- var import_lib$2 = /* @__PURE__ */ __toESM(require_lib$2(), 1);
6
- const BINDING_TYPES = [
7
- "array",
8
- "object",
9
- "string",
10
- "number",
11
- "boolean",
12
- "color",
13
- "jsx",
14
- "richtext",
15
- "date",
16
- "url",
17
- "icon-picker",
18
- "asset-picker"
19
- ];
20
- //#endregion
21
- //#region src/utils/ast/helpers.ts
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
- const wrap = (code) => {
25
- return `<>${code}</>`;
26
- };
27
- const unwrap = (generated) => {
28
- return generated.replace(/^<>\s*/g, "").replace(/\s*<\/>\s*;?\s*$/g, "").trim();
29
- };
30
- const attrValue = ({ value, isStringLiteral }) => {
31
- if (value === null) return null;
32
- if (isStringLiteral) return import_lib$2.stringLiteral(value);
33
- const trimmed = value.trim();
34
- if (REGEX.NUMBER.test(trimmed)) return import_lib$2.jsxExpressionContainer(import_lib$2.numericLiteral(parseFloat(trimmed)));
35
- if (REGEX.BOOLEAN_OR_NULL.test(trimmed)) {
36
- const expr = (0, import_lib$1.parseExpression)(trimmed, { plugins: ["jsx", "typescript"] });
37
- return import_lib$2.jsxExpressionContainer(expr);
38
- }
39
- try {
40
- const expr = (0, import_lib$1.parseExpression)(trimmed, { plugins: ["jsx", "typescript"] });
41
- return import_lib$2.jsxExpressionContainer(expr);
42
- } catch {
43
- return import_lib$2.stringLiteral(trimmed);
44
- }
45
- };
46
- const generateCode = (node) => {
47
- return generate(node, { jsescOption: { minimal: true } }).code;
48
- };
49
- //#endregion
50
- //#region src/utils/ast/value.ts
51
- const dedent = (str) => {
52
- const lines = str.replace(/^\n/, "").replace(/\n\s*$/, "").split("\n");
53
- const indent = lines.reduce((min, line) => {
54
- if (!line.trim()) return min;
55
- const match = line.match(/^(\s*)/);
56
- return Math.min(min, match?.[1]?.length ?? 0);
57
- }, Infinity);
58
- return indent === Infinity ? str.trim() : lines.map((line) => line.slice(indent)).join("\n");
59
- };
60
- const unwrapExpression = (node) => {
61
- let current = node;
62
- while (import_lib$2.isTSAsExpression(current) || import_lib$2.isTSSatisfiesExpression(current) || import_lib$2.isTSNonNullExpression(current) || import_lib$2.isTSTypeAssertion(current) || import_lib$2.isParenthesizedExpression(current)) current = current.expression;
63
- return current;
64
- };
65
- const evaluateLiteral = (rawNode) => {
66
- const node = unwrapExpression(rawNode);
67
- if (import_lib$2.isStringLiteral(node)) return node.value;
68
- if (import_lib$2.isNumericLiteral(node)) return node.value;
69
- if (import_lib$2.isBooleanLiteral(node)) return node.value;
70
- if (import_lib$2.isNullLiteral(node)) return null;
71
- if (import_lib$2.isIdentifier(node) && node.name === "undefined") return;
72
- if (import_lib$2.isUnaryExpression(node) && node.operator === "-" && import_lib$2.isNumericLiteral(node.argument)) return -node.argument.value;
73
- if (import_lib$2.isTemplateLiteral(node) && node.expressions.length === 0) return node.quasis[0]?.value.cooked ?? node.quasis[0]?.value.raw ?? "";
74
- if (import_lib$2.isJSXElement(node) || import_lib$2.isJSXFragment(node)) return generateCode(node);
75
- if (import_lib$2.isArrayExpression(node)) return node.elements.map((element) => element ? evaluateLiteral(element) : null);
76
- if (import_lib$2.isObjectExpression(node)) {
77
- const result = {};
78
- for (const prop of node.properties) {
79
- if (!import_lib$2.isObjectProperty(prop)) continue;
80
- let key = null;
81
- if (import_lib$2.isIdentifier(prop.key)) key = prop.key.name;
82
- else if (import_lib$2.isStringLiteral(prop.key)) key = prop.key.value;
83
- else if (import_lib$2.isNumericLiteral(prop.key)) key = String(prop.key.value);
84
- if (key === null) continue;
85
- result[key] = evaluateLiteral(prop.value);
86
- }
87
- return result;
88
- }
89
- };
90
- const parseValue = (value) => {
91
- if (typeof value !== "string") return value;
92
- const trimmed = value.trim();
93
- if (!trimmed) return value;
94
- if (REGEX.NUMBER.test(trimmed)) return parseFloat(trimmed);
95
- if (REGEX.BOOLEAN_OR_NULL.test(trimmed)) {
96
- if (trimmed === "true") return true;
97
- if (trimmed === "false") return false;
98
- if (trimmed === "null") return null;
99
- if (trimmed === "undefined") return;
100
- }
101
- if (trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]")) {
102
- try {
103
- const ast = (0, import_lib$1.parseExpression)(trimmed, { plugins: ["jsx", "typescript"] });
104
- if (import_lib$2.isObjectExpression(ast) || import_lib$2.isArrayExpression(ast)) return evaluateLiteral(ast);
105
- } catch {}
106
- return value;
107
- }
108
- return value;
109
- };
110
- const MAX_FLATTEN_DEPTH = 20;
111
- const isEditablePrimitive = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean";
112
- const flattenEditableValue = (value) => {
113
- const parsed = parseValue(value);
114
- if (typeof parsed !== "object" || parsed === null || Object.keys(parsed).length === 0) return null;
115
- const entries = [];
116
- const walk = (node, path, depth) => {
117
- if (depth > MAX_FLATTEN_DEPTH) return;
118
- if (isEditablePrimitive(node)) {
119
- entries.push({
120
- path,
121
- value: node
122
- });
123
- return;
124
- }
125
- if (Array.isArray(node)) {
126
- node.forEach((item, index) => walk(item, [...path, index], depth + 1));
127
- return;
128
- }
129
- if (typeof node === "object" && node !== null) Object.entries(node).forEach(([key, item]) => walk(item, [...path, key], depth + 1));
130
- };
131
- walk(parsed, [], 0);
132
- return entries.length ? entries : null;
133
- };
134
- const setEditableValue = (value, path, next) => {
135
- if (!path.length) return value;
136
- const parsed = parseValue(value);
137
- if (typeof parsed !== "object" || parsed === null) return value;
138
- const root = Array.isArray(parsed) ? [...parsed] : { ...parsed };
139
- let cursor = root;
140
- for (let i = 0; i < path.length - 1; i++) {
141
- const key = path[i];
142
- const child = cursor[key];
143
- if (typeof child !== "object" || child === null) return value;
144
- const clonedChild = Array.isArray(child) ? [...child] : { ...child };
145
- cursor[key] = clonedChild;
146
- cursor = clonedChild;
147
- }
148
- const lastKey = path[path.length - 1];
149
- if (!(lastKey in cursor)) return value;
150
- cursor[lastKey] = next;
151
- return JSON.stringify(root);
152
- };
153
- const extractNodeValue = (node) => {
154
- if (import_lib$2.isBooleanLiteral(node)) return {
155
- type: "boolean",
156
- value: node.value
157
- };
158
- if (import_lib$2.isNumericLiteral(node)) return {
159
- type: "number",
160
- value: node.value
161
- };
162
- if (import_lib$2.isUnaryExpression(node) && node.operator === "-" && import_lib$2.isNumericLiteral(node.argument)) return {
163
- type: "number",
164
- value: -node.argument.value
165
- };
166
- if (import_lib$2.isStringLiteral(node)) return {
167
- type: "string",
168
- value: node.value
169
- };
170
- if (import_lib$2.isTemplateLiteral(node)) {
171
- if (node.expressions.length === 0 && node.quasis.length === 1) return {
172
- type: "string",
173
- value: dedent(node.quasis[0].value.cooked ?? node.quasis[0].value.raw)
174
- };
175
- return {
176
- type: "string",
177
- value: generateCode(node)
178
- };
179
- }
180
- if (import_lib$2.isNullLiteral(node)) return {
181
- type: "null",
182
- value: null
183
- };
184
- if (import_lib$2.isArrayExpression(node)) return {
185
- type: "array",
186
- value: generateCode(node)
187
- };
188
- if (import_lib$2.isObjectExpression(node)) return {
189
- type: "object",
190
- value: generateCode(node)
191
- };
192
- if (import_lib$2.isJSXElement(node) || import_lib$2.isJSXFragment(node)) return {
193
- type: "string",
194
- value: generateCode(node)
195
- };
196
- return {
197
- type: "unknown",
198
- value: null
199
- };
200
- };
201
- const createNodeFromValue = (type, value) => {
202
- switch (type) {
203
- case "boolean": return import_lib$2.booleanLiteral(value === true);
204
- case "number": return import_lib$2.numericLiteral(Number(value));
205
- case "string": return import_lib$2.stringLiteral(String(value));
206
- case "null": return import_lib$2.nullLiteral();
207
- case "array":
208
- case "object":
209
- case "unknown": return null;
210
- default: return null;
211
- }
212
- };
213
- const valueToExpression = (value) => {
214
- if (typeof value === "string") return import_lib$2.stringLiteral(value);
215
- if (typeof value === "number") return value < 0 ? import_lib$2.unaryExpression("-", import_lib$2.numericLiteral(-value)) : import_lib$2.numericLiteral(value);
216
- if (typeof value === "boolean") return import_lib$2.booleanLiteral(value);
217
- if (value === null) return import_lib$2.nullLiteral();
218
- if (Array.isArray(value)) return import_lib$2.arrayExpression(value.map((item) => valueToExpression(item) ?? import_lib$2.nullLiteral()));
219
- if (typeof value === "object") {
220
- const properties = [];
221
- for (const [key, item] of Object.entries(value)) {
222
- const expr = valueToExpression(item);
223
- if (expr === null) continue;
224
- properties.push(import_lib$2.objectProperty(import_lib$2.stringLiteral(key), expr));
225
- }
226
- return import_lib$2.objectExpression(properties);
227
- }
228
- return null;
229
- };
230
- const parseArrayExpression = (value) => {
231
- try {
232
- const ast = unwrapExpression((0, import_lib$1.parseExpression)(value, { plugins: ["jsx", "typescript"] }));
233
- if (!import_lib$2.isArrayExpression(ast)) return null;
234
- return ast;
235
- } catch (error) {
236
- console.error("❌ Array parsing error:", error);
237
- return null;
238
- }
239
- };
240
- const extractObjectProperties = (element) => {
241
- const properties = {};
242
- element.properties.forEach((prop) => {
243
- if (import_lib$2.isObjectProperty(prop) && import_lib$2.isIdentifier(prop.key)) {
244
- const key = prop.key.name;
245
- if (key === "children" || import_lib$2.isJSXElement(prop.value) || import_lib$2.isJSXFragment(prop.value)) return;
246
- const extracted = extractNodeValue(prop.value);
247
- properties[key] = {
248
- ...extracted,
249
- astNode: prop.value
250
- };
251
- }
252
- });
253
- return properties;
254
- };
255
- const arrayExpressionToCode = (elements) => {
256
- const nextAst = import_lib$2.arrayExpression(elements);
257
- return generateCode(nextAst);
258
- };
259
- //#endregion
260
- //#region src/utils/ast/binding.ts
261
- const bindingTypeSchema = z.enum(BINDING_TYPES);
262
- const bindingOptionSchema = z.object({
263
- label: z.string(),
264
- value: z.string()
265
- });
266
- const bindingRenderLeafSchema = z.object({ property: z.string().optional() });
267
- const rawBindingItemSchema = z.object({
268
- label: z.string(),
269
- property: z.string().optional(),
270
- type: bindingTypeSchema.optional(),
271
- widget: z.string().optional(),
272
- options: z.array(bindingOptionSchema).optional(),
273
- min: z.number().optional(),
274
- max: z.number().optional(),
275
- pattern: z.string().optional(),
276
- required: z.boolean().optional()
277
- }).passthrough();
278
- const KNOWN_BINDING_KEYS = /* @__PURE__ */ new Set([
279
- "label",
280
- "property",
281
- "type",
282
- "widget",
283
- "options",
284
- "render",
285
- "min",
286
- "max",
287
- "pattern",
288
- "required"
289
- ]);
290
- const WIDGET_TYPE_ALIASES = /* @__PURE__ */ new Set(["icon-picker", "asset-picker"]);
291
- const isPlainObject = (value) => {
292
- return typeof value === "object" && value !== null && !Array.isArray(value);
293
- };
294
- const sanitizeRenderMap = (value) => {
295
- if (!isPlainObject(value)) return;
296
- const map = {};
297
- for (const [key, raw] of Object.entries(value)) {
298
- if (!isPlainObject(raw)) continue;
299
- if ("type" in raw) {
300
- const sanitizedType = bindingTypeSchema.safeParse(raw.type);
301
- const leaf = bindingRenderLeafSchema.safeParse(raw);
302
- if (leaf.success) {
303
- const render = sanitizeRenderMap(raw.render);
304
- const typedLeaf = {
305
- ...leaf.data,
306
- type: sanitizedType.success ? sanitizedType.data : void 0
307
- };
308
- map[key] = render ? {
309
- ...typedLeaf,
310
- render
311
- } : typedLeaf;
312
- }
313
- continue;
314
- }
315
- const nested = sanitizeRenderMap(raw);
316
- if (nested) map[key] = nested;
317
- }
318
- return Object.keys(map).length > 0 ? map : void 0;
319
- };
320
- const buildBindingItems = (raw) => {
321
- if (!Array.isArray(raw)) return [];
322
- const items = [];
323
- for (const rawItem of raw) {
324
- if (!isPlainObject(rawItem)) continue;
325
- const sanitizedType = bindingTypeSchema.safeParse(rawItem.type);
326
- const isWidgetAlias = sanitizedType.success && WIDGET_TYPE_ALIASES.has(sanitizedType.data);
327
- const normalizedType = isWidgetAlias ? "string" : sanitizedType.success ? sanitizedType.data : void 0;
328
- const derivedWidget = isWidgetAlias ? sanitizedType.data : void 0;
329
- const sanitizedOptions = Array.isArray(rawItem.options) ? rawItem.options.map((option) => {
330
- const parsed = bindingOptionSchema.safeParse(option);
331
- return parsed.success ? parsed.data : null;
332
- }).filter((option) => option !== null) : void 0;
333
- const parsed = rawBindingItemSchema.safeParse({
334
- ...rawItem,
335
- type: normalizedType,
336
- options: sanitizedOptions?.length ? sanitizedOptions : void 0
337
- });
338
- if (!parsed.success) continue;
339
- const { label, property, type, widget: explicitWidget, options, min, max, pattern, required } = parsed.data;
340
- const widget = explicitWidget ?? derivedWidget;
341
- if (property === void 0 && type !== "richtext") continue;
342
- const render = sanitizeRenderMap(rawItem.render);
343
- const metaEntries = Object.entries(parsed.data).filter(([key]) => !KNOWN_BINDING_KEYS.has(key));
344
- const meta = metaEntries.length > 0 ? Object.fromEntries(metaEntries) : void 0;
345
- items.push({
346
- label,
347
- property: property ?? BINDING_PROP.INNER_HTML,
348
- ...type !== void 0 && { type },
349
- ...widget !== void 0 && { widget },
350
- ...options?.length && { options },
351
- ...render && { render },
352
- ...min !== void 0 && { min },
353
- ...max !== void 0 && { max },
354
- ...pattern !== void 0 && { pattern },
355
- ...required !== void 0 && { required },
356
- ...meta && { meta }
357
- });
358
- }
359
- return items;
360
- };
361
- const parseBinding = (bindingValue) => {
362
- if (!bindingValue) return [];
363
- const ast = parseArrayExpression(bindingValue);
364
- if (!ast) return [];
365
- return buildBindingItems(evaluateLiteral(ast));
366
- };
367
- const parseBindingExpression = (expression) => buildBindingItems(evaluateLiteral(expression));
368
- const getCurrentValue = (node, property) => {
369
- switch (property) {
370
- case BINDING_PROP.INNER_TEXT: return node.textContent || "";
371
- case BINDING_PROP.INNER_HTML: {
372
- const dsiAttr = node.attributes.find((a) => a.name === "dangerouslySetInnerHTML");
373
- if (dsiAttr?.value) try {
374
- const expr = (0, import_lib$1.parseExpression)(dsiAttr.value, { plugins: ["jsx", "typescript"] });
375
- if (import_lib$2.isObjectExpression(expr)) {
376
- const htmlProp = expr.properties.find((p) => import_lib$2.isObjectProperty(p) && import_lib$2.isIdentifier(p.key) && p.key.name === "__html");
377
- if (htmlProp) {
378
- if (import_lib$2.isStringLiteral(htmlProp.value)) return htmlProp.value.value;
379
- 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 ?? "";
380
- }
381
- }
382
- } catch {}
383
- return node.rawChildren || node.textContent || "";
384
- }
385
- case BINDING_PROP.CHILDREN: return JSON.stringify(node?.children || []);
386
- default: return node.attributes.find((attr) => attr.name === property)?.value || "";
387
- }
388
- };
389
- const STRING_VALUED_TYPES = /* @__PURE__ */ new Set([
390
- "string",
391
- "url",
392
- "date",
393
- "color",
394
- "jsx",
395
- "richtext",
396
- "icon-picker",
397
- "asset-picker"
398
- ]);
399
- const getStructuredValue = (node, property, type) => {
400
- switch (property) {
401
- case BINDING_PROP.INNER_TEXT:
402
- case BINDING_PROP.INNER_HTML: return getCurrentValue(node, property);
403
- case BINDING_PROP.CHILDREN: return node.children ?? [];
404
- default: {
405
- const raw = getCurrentValue(node, property);
406
- if (node.attributes.find((a) => a.name === property)?.isStringLiteral || type && STRING_VALUED_TYPES.has(type)) return raw;
407
- return parseValue(raw);
408
- }
409
- }
410
- };
411
- const hasEditableBindings = (node) => {
412
- const bindingAttr = node.dataAttributes.find((attr) => attr.name === DATA_ATTR.BINDING);
413
- if (!bindingAttr?.value) return false;
414
- return (node.bindings || parseBinding(bindingAttr.value)).length > 0;
415
- };
416
- const findEditableChildren = (node) => {
417
- const editableChildren = [];
418
- const traverse = (children) => {
419
- if (!children) return;
420
- for (const child of children) {
421
- if (hasEditableBindings(child)) editableChildren.push(child);
422
- traverse(child.children);
423
- }
424
- };
425
- traverse(node.children);
426
- return editableChildren;
427
- };
428
- //#endregion
429
- //#region src/utils/selection.ts
430
- const removeIndices = (items, indices) => {
431
- return items.filter((_, index) => !indices.has(index));
432
- };
433
- /**
434
- * Shifts every selected index up/down by one step as a block, preserving
435
- * relative order — scattered selections stop moving individually once they
436
- * hit an unselected neighbor, so the whole group slides together instead of
437
- * items passing through each other.
438
- */
439
- const moveSelectedIndices = (items, indices, direction) => {
440
- const next = [...items];
441
- const nextIndices = new Set(indices);
442
- const ordered = [...indices].sort((a, b) => direction === "up" ? a - b : b - a);
443
- for (const index of ordered) {
444
- const target = direction === "up" ? index - 1 : index + 1;
445
- if (target < 0 || target >= next.length || nextIndices.has(target)) continue;
446
- [next[index], next[target]] = [next[target], next[index]];
447
- nextIndices.delete(index);
448
- nextIndices.add(target);
449
- }
450
- return {
451
- items: next,
452
- indices: nextIndices
453
- };
454
- };
455
- //#endregion
456
- //#region src/utils/ast/patch.ts
457
- const hasOnlyLayoutNewlines = (content) => {
458
- let index = 0;
459
- while (index < content.length) {
460
- const char = content[index];
461
- if (char === "`" || char === "<") return false;
462
- if (char === "\"" || char === "'") {
463
- const next = skipStringLiteral(content, index);
464
- if (next === -1) return false;
465
- index = next;
466
- continue;
467
- }
468
- if (char === "/") {
469
- const following = content[index + 1];
470
- if (following === "/") {
471
- const lineEnd = content.indexOf("\n", index + 2);
472
- index = lineEnd === -1 ? content.length : lineEnd;
473
- continue;
474
- }
475
- if (following === "*") {
476
- const commentEnd = content.indexOf("*/", index + 2);
477
- if (commentEnd === -1) return false;
478
- index = commentEnd + 2;
479
- continue;
480
- }
481
- return false;
482
- }
483
- index++;
484
- }
485
- return true;
486
- };
487
- const skipStringLiteral = (content, start) => {
488
- const quote = content[start];
489
- for (let index = start + 1; index < content.length; index++) {
490
- const char = content[index];
491
- if (char === "\\") {
492
- const escaped = content[index + 1];
493
- if (escaped === "\n" || escaped === "\r") return -1;
494
- index++;
495
- continue;
496
- }
497
- if (char === quote) return index + 1;
498
- if (char === "\n") return -1;
499
- }
500
- return -1;
501
- };
502
- const lineIndentAt = (source, offset) => {
503
- const lineStart = source.lastIndexOf("\n", offset - 1) + 1;
504
- return /^[ \t]*/.exec(source.slice(lineStart, offset))?.[0] ?? "";
505
- };
506
- const lineTerminatorOf = (source) => {
507
- return source.includes("\r\n") ? "\r\n" : "\n";
508
- };
509
- const applyEdits = (source, edits) => {
510
- if (edits.length === 0) return source;
511
- const ordered = [...edits].sort((a, b) => a.start - b.start || a.end - b.end);
512
- for (const edit of ordered) if (!Number.isInteger(edit.start) || !Number.isInteger(edit.end) || edit.start < 0 || edit.end > source.length || edit.start > edit.end) throw new Error(`Invalid source edit [${edit.start}, ${edit.end}) for a source of length ${source.length}`);
513
- for (let i = 1; i < ordered.length; i++) {
514
- const previous = ordered[i - 1];
515
- const current = ordered[i];
516
- if (current.start < previous.end) throw new Error(`Overlapping source edits: [${previous.start}, ${previous.end}) and [${current.start}, ${current.end})`);
517
- }
518
- let result = "";
519
- let cursor = 0;
520
- const terminator = lineTerminatorOf(source);
521
- for (const edit of ordered) {
522
- const content = edit.indent && edit.content.includes("\n") && hasOnlyLayoutNewlines(edit.content) ? edit.content.replace(/\n/g, `${terminator}${lineIndentAt(source, edit.start)}`) : edit.content;
523
- result += source.slice(cursor, edit.start) + content;
524
- cursor = edit.end;
525
- }
526
- return result + source.slice(cursor);
527
- };
528
- //#endregion
529
- //#region src/utils/ast/array-source.ts
530
- const commaIn = (source, start, end) => {
531
- let comma = null;
532
- for (let at = start; at < end; at++) {
533
- if (/\s/.test(source[at])) continue;
534
- if (source.startsWith("/*", at)) {
535
- const close = source.indexOf("*/", at + 2);
536
- if (close < 0 || close + 2 > end) return null;
537
- at = close + 1;
538
- } else if (source.startsWith("//", at)) {
539
- const newline = source.indexOf("\n", at + 2);
540
- at = newline < 0 ? end : newline;
541
- } else if (source[at] === "," && comma === null) comma = at;
542
- else return null;
543
- }
544
- return comma;
545
- };
546
- const denseArraySource = (source) => {
547
- const array = parseArrayExpression(source);
548
- if (!array || array.elements.some((node) => !import_lib$2.isExpression(node) || node.extra?.parenthesized)) return null;
549
- const elements = array.elements;
550
- const commas = elements.slice(0, -1).map((node, index) => commaIn(source, node.end, elements[index + 1].start));
551
- if (commas.some((comma) => comma === null)) return null;
552
- const last = elements.at(-1);
553
- return {
554
- array,
555
- elements,
556
- commas,
557
- trailing: last ? commaIn(source, last.end, array.end - 1) : null
558
- };
559
- };
560
- const validArrayIndices = (indices, length) => [...indices].every((index) => Number.isInteger(index) && index >= 0 && index < length);
561
- const reorderArraySource = (source, elements, next) => applyEdits(source, elements.map((node, index) => ({
562
- start: node.start,
563
- end: node.end,
564
- content: source.slice(next[index].start, next[index].end)
565
- })));
566
- const removeArraySource = (source, data, indices) => {
567
- const edits = [];
568
- const removedCommas = /* @__PURE__ */ new Set();
569
- const { elements, commas, trailing } = data;
570
- for (let index = 0; index < elements.length; index++) {
571
- if (!indices.has(index)) continue;
572
- const start = index;
573
- while (index + 1 < elements.length && indices.has(index + 1)) index++;
574
- for (let current = start; current <= index; current++) {
575
- const node = elements[current];
576
- edits.push({
577
- start: node.start,
578
- end: node.end,
579
- content: ""
580
- });
581
- if (current < elements.length - 1) removedCommas.add(commas[current]);
582
- }
583
- if (index === elements.length - 1) {
584
- if (trailing !== null) removedCommas.add(trailing);
585
- else if (start > 0) removedCommas.add(commas[start - 1]);
586
- }
587
- }
588
- for (const comma of removedCommas) edits.push({
589
- start: comma,
590
- end: comma + 1,
591
- content: ""
592
- });
593
- return applyEdits(source, edits);
594
- };
595
- const appendArraySource = (source, data, copies) => {
596
- const last = data.elements.at(-1);
597
- if (!last || copies.length === 0) return source;
598
- return applyEdits(source, [{
599
- start: last.end,
600
- end: last.end,
601
- content: `, ${copies.join(", ")}`
602
- }]);
603
- };
604
- //#endregion
605
- //#region src/utils/ast/items.ts
606
- const elementsOf = (code) => parseArrayExpression(code)?.elements ?? null;
607
- const kindOf = (element) => import_lib$2.isObjectExpression(element) ? "object" : "primitive";
608
- const parseItems = (code) => {
609
- return elementsOf(code)?.flatMap((node, index) => import_lib$2.isExpression(node) ? [{
610
- index,
611
- kind: kindOf(node),
612
- node
613
- }] : []) ?? null;
614
- };
615
- const resolveRenderLeaf = (render, key) => {
616
- const leaf = render?.[key];
617
- return leaf && "type" in leaf ? leaf : null;
618
- };
619
- const isLosslesslyEvaluable = (node) => {
620
- if (import_lib$2.isStringLiteral(node) || import_lib$2.isNumericLiteral(node) || import_lib$2.isBooleanLiteral(node) || import_lib$2.isNullLiteral(node)) return true;
621
- if (import_lib$2.isUnaryExpression(node) && node.operator === "-" && import_lib$2.isNumericLiteral(node.argument)) return true;
622
- if (import_lib$2.isTemplateLiteral(node)) return node.expressions.length === 0;
623
- if (import_lib$2.isArrayExpression(node)) return node.elements.every((element) => element !== null && isLosslesslyEvaluable(element));
624
- if (import_lib$2.isObjectExpression(node)) return node.properties.every((property) => import_lib$2.isObjectProperty(property) && !property.computed && (import_lib$2.isIdentifier(property.key) || import_lib$2.isStringLiteral(property.key) || import_lib$2.isNumericLiteral(property.key)) && isLosslesslyEvaluable(property.value));
625
- return false;
626
- };
627
- const toTemplateRaw = (value) => {
628
- return value.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${").replace(/\r/g, "\\r");
629
- };
630
- const buildPropertyValue = (value, declaredType, renderLeaf, current) => {
631
- if (renderLeaf?.property === BINDING_PROP.INNER_HTML) {
632
- const raw = String(value);
633
- return import_lib$2.templateLiteral([import_lib$2.templateElement({
634
- raw: toTemplateRaw(raw),
635
- cooked: raw
636
- }, true)], []);
637
- }
638
- if (renderLeaf?.type === "jsx" || import_lib$2.isJSXElement(current) || import_lib$2.isJSXFragment(current)) {
639
- const trimmed = String(value).trim();
640
- if (!trimmed.startsWith("<")) return import_lib$2.stringLiteral(trimmed);
641
- try {
642
- return (0, import_lib$1.parseExpression)(trimmed, { plugins: ["jsx", "typescript"] });
643
- } catch {
644
- return;
645
- }
646
- }
647
- if (declaredType === "array" || declaredType === "object") {
648
- if (typeof value === "string") try {
649
- return (0, import_lib$1.parseExpression)(value, { plugins: ["jsx", "typescript"] });
650
- } catch {
651
- return;
652
- }
653
- if (!isLosslesslyEvaluable(current)) return;
654
- return valueToExpression(value) ?? void 0;
655
- }
656
- return createNodeFromValue(declaredType, parseValue(value)) ?? void 0;
657
- };
658
- const updateArrayItemProperty = (code, index, key, value, render) => {
659
- const elements = elementsOf(code);
660
- const element = elements?.[index];
661
- if (!elements || !import_lib$2.isObjectExpression(element)) return null;
662
- const target = element.properties.find((property) => import_lib$2.isObjectProperty(property) && import_lib$2.isIdentifier(property.key) && property.key.name === key);
663
- if (!target) return null;
664
- const declaredType = extractObjectProperties(element)[key]?.type ?? "string";
665
- const nextValue = buildPropertyValue(value, declaredType, resolveRenderLeaf(render, key), target.value);
666
- if (!nextValue) return null;
667
- let serialized = typeof value === "string" && (declaredType === "array" || declaredType === "object" || import_lib$2.isJSXElement(nextValue) || import_lib$2.isJSXFragment(nextValue)) ? value.trim() : generateCode(nextValue);
668
- if (nextValue.trailingComments?.some((comment) => comment.type === "CommentLine")) serialized += "\n";
669
- const content = target.shorthand ? `${key}: ${serialized}` : serialized;
670
- return applyEdits(code, [{
671
- start: target.value.start,
672
- end: target.value.end,
673
- content
674
- }]);
675
- };
676
- const updateArrayItemValue = (code, index, value) => {
677
- const elements = elementsOf(code);
678
- const element = elements?.[index];
679
- if (!elements || !import_lib$2.isExpression(element)) return null;
680
- const nextValue = createNodeFromValue(extractNodeValue(element).type, parseValue(value));
681
- if (!nextValue) return null;
682
- return applyEdits(code, [{
683
- start: element.start,
684
- end: element.end,
685
- content: generateCode(nextValue)
686
- }]);
687
- };
688
- const moveArrayItem = (code, from, to) => {
689
- const data = denseArraySource(code);
690
- if (!data || !validArrayIndices([from], data.elements.length) || !Number.isInteger(to)) return null;
691
- const next = [...data.elements];
692
- const [moved] = next.splice(from, 1);
693
- next.splice(to, 0, moved);
694
- return reorderArraySource(code, data.elements, next);
695
- };
696
- const moveArrayItems = (code, indices, direction) => {
697
- const data = denseArraySource(code);
698
- if (!data || !validArrayIndices(indices, data.elements.length) || !["up", "down"].includes(direction)) return null;
699
- const next = moveSelectedIndices(data.elements, indices, direction);
700
- return {
701
- code: reorderArraySource(code, data.elements, next.items),
702
- indices: next.indices
703
- };
704
- };
705
- const removeArrayItems = (code, indices, kind) => {
706
- const data = denseArraySource(code);
707
- if (!data || !validArrayIndices(indices, data.elements.length)) return null;
708
- const remaining = removeIndices(data.elements, indices);
709
- if (!(kind === void 0 ? remaining : remaining.filter((node) => kindOf(node) === kind)).length) return null;
710
- return removeArraySource(code, data, indices);
711
- };
712
- const copyItem = (code, element, generateId, usedIds) => {
713
- const edits = [];
714
- let unsupported = false;
715
- const reserveId = (id) => {
716
- if (usedIds.has(id)) unsupported = true;
717
- usedIds.add(id);
718
- return JSON.stringify(id);
719
- };
720
- import_lib$2.traverseFast(element, (node) => {
721
- if (!import_lib$2.isJSXOpeningElement(node)) return;
722
- const ids = node.attributes.filter((attr) => import_lib$2.isJSXAttribute(attr) && import_lib$2.isJSXIdentifier(attr.name, { name: "data-id" }));
723
- const attr = ids[0];
724
- if (ids.length > 1 || attr && (!import_lib$2.isStringLiteral(attr.value) || node.attributes.slice(node.attributes.indexOf(attr) + 1).some((a) => import_lib$2.isJSXSpreadAttribute(a)))) {
725
- unsupported = true;
726
- return;
727
- }
728
- if (attr && import_lib$2.isStringLiteral(attr.value)) edits.push({
729
- start: attr.value.start,
730
- end: attr.value.end,
731
- content: reserveId(generateId())
732
- });
733
- });
734
- if (import_lib$2.isObjectExpression(element)) {
735
- const keys = element.properties.filter((prop) => import_lib$2.isObjectProperty(prop) && !prop.computed && (import_lib$2.isIdentifier(prop.key, { name: "key" }) || import_lib$2.isStringLiteral(prop.key, { value: "key" })));
736
- const key = keys[0];
737
- if (keys.length > 1 || key && (!import_lib$2.isStringLiteral(key.value) || element.properties.slice(element.properties.indexOf(key) + 1).some((prop) => import_lib$2.isSpreadElement(prop) || "computed" in prop && prop.computed))) return null;
738
- if (key && import_lib$2.isStringLiteral(key.value)) edits.push({
739
- start: key.value.start,
740
- end: key.value.end,
741
- content: reserveId(`${key.value.value}-${generateId()}`)
742
- });
743
- }
744
- if (unsupported) return null;
745
- return applyEdits(code.slice(element.start, element.end), edits.map((edit) => ({
746
- ...edit,
747
- start: edit.start - element.start,
748
- end: edit.end - element.start
749
- })));
750
- };
751
- const duplicateArrayItems = (code, indices, generateId = () => nanoid(6)) => {
752
- const data = denseArraySource(code);
753
- if (!data || !indices.size || !validArrayIndices(indices, data.elements.length)) return null;
754
- const usedIds = /* @__PURE__ */ new Set();
755
- import_lib$2.traverseFast(data.array, (node) => {
756
- if (import_lib$2.isJSXAttribute(node) && import_lib$2.isJSXIdentifier(node.name, { name: "data-id" }) && import_lib$2.isStringLiteral(node.value)) usedIds.add(node.value.value);
757
- else if (import_lib$2.isObjectProperty(node) && !node.computed && (import_lib$2.isIdentifier(node.key, { name: "key" }) || import_lib$2.isStringLiteral(node.key, { value: "key" })) && import_lib$2.isStringLiteral(node.value)) usedIds.add(node.value.value);
758
- });
759
- const copies = [...indices].sort((a, b) => a - b).map((index) => copyItem(code, data.elements[index], generateId, usedIds));
760
- return copies.every((copy) => copy !== null) ? appendArraySource(code, data, copies) : null;
761
- };
762
- const appendArrayItem = (code, kind, generateId = () => nanoid(6)) => {
763
- const index = denseArraySource(code)?.elements.findIndex((node) => kindOf(node) === kind) ?? -1;
764
- return index < 0 ? null : duplicateArrayItems(code, /* @__PURE__ */ new Set([index]), generateId);
765
- };
766
- //#endregion
767
- //#region src/utils/ast/extract.ts
768
- const collectText = (children) => {
769
- return children.filter((c) => import_lib$2.isJSXText(c)).map((c) => c.value.trim()).filter((v) => v.length).join(" ");
770
- };
771
- const getTagName = (opening) => {
772
- if (import_lib$2.isJSXIdentifier(opening.name)) return opening.name.name;
773
- if (import_lib$2.isJSXMemberExpression(opening.name)) return resolveMemberName(opening.name);
774
- return "";
775
- };
776
- const resolveMemberName = (expr) => {
777
- const parts = [];
778
- const collectMemberParts = (node) => {
779
- if (import_lib$2.isJSXIdentifier(node)) parts.push(node.name);
780
- else if (import_lib$2.isJSXMemberExpression(node)) {
781
- collectMemberParts(node.object);
782
- if (import_lib$2.isJSXIdentifier(node.property)) parts.push(node.property.name);
783
- }
784
- };
785
- collectMemberParts(expr.object);
786
- if (import_lib$2.isJSXIdentifier(expr.property)) parts.push(expr.property.name);
787
- return parts.join(".");
788
- };
789
- const parseJSXName = (tagName) => {
790
- const parts = tagName.split(".");
791
- if (parts.length === 1) return import_lib$2.jsxIdentifier(parts[0]);
792
- let expr = import_lib$2.jsxIdentifier(parts[0]);
793
- for (let i = 1; i < parts.length; i++) expr = import_lib$2.jsxMemberExpression(expr, import_lib$2.jsxIdentifier(parts[i]));
794
- return expr;
795
- };
796
- const extractCache = createBoundedCache(CONFIG.CACHE_LIMIT);
797
- const extractAttributes = (attributes, source) => {
798
- const allAttrs = [];
799
- const dataAttrs = [];
800
- for (const attr of attributes) {
801
- if (!import_lib$2.isJSXAttribute(attr) || !import_lib$2.isJSXIdentifier(attr.name)) continue;
802
- const name = attr.name.name;
803
- let value = null;
804
- let isStringLiteral = false;
805
- if (attr.value) {
806
- if (import_lib$2.isStringLiteral(attr.value)) {
807
- value = attr.value.value;
808
- isStringLiteral = true;
809
- } else if (import_lib$2.isJSXExpressionContainer(attr.value)) try {
810
- const expression = attr.value.expression;
811
- const structural = import_lib$2.isArrayExpression(unwrapExpression(expression)) || import_lib$2.isObjectExpression(unwrapExpression(expression));
812
- value = source && structural && expression.start != null && expression.end != null ? source.slice(expression.start, expression.end) : generateCode(expression);
813
- isStringLiteral = false;
814
- } catch {
815
- value = null;
816
- }
817
- }
818
- const entry = {
819
- name,
820
- value,
821
- isStringLiteral
822
- };
823
- allAttrs.push(entry);
824
- if (name.startsWith("data-")) dataAttrs.push(entry);
825
- }
826
- return {
827
- allAttrs,
828
- dataAttrs
829
- };
830
- };
831
- const buildChildElements = (node) => {
832
- const childElements = [];
833
- if (node.textContent) childElements.push(import_lib$2.jsxText(node.textContent));
834
- node.children?.forEach((child) => {
835
- const childJSX = nodeToJSX(child);
836
- if (childJSX) childElements.push(childJSX);
837
- });
838
- return childElements;
839
- };
840
- const nodeToJSX = (node) => {
841
- try {
842
- if (node.isFragment) {
843
- const childElements = buildChildElements(node);
844
- return import_lib$2.jsxFragment(import_lib$2.jsxOpeningFragment(), import_lib$2.jsxClosingFragment(), childElements);
845
- }
846
- if (node.tagName === "div" && node.dataAttributes.some((attr) => attr.name === "data-item")) {
847
- if (node.children) return nodeToJSX(node.children[0]);
848
- return null;
849
- }
850
- const attributes = node.attributes.map((attr) => {
851
- const attrName = import_lib$2.jsxIdentifier(attr.name);
852
- if (!attr.value) return import_lib$2.jsxAttribute(attrName, null);
853
- return import_lib$2.jsxAttribute(attrName, attrValue(attr));
854
- });
855
- const elementName = parseJSXName(node.tagName);
856
- const openingElement = import_lib$2.jsxOpeningElement(elementName, attributes);
857
- const closingElement = import_lib$2.jsxClosingElement(elementName);
858
- const children = buildChildElements(node);
859
- return import_lib$2.jsxElement(openingElement, closingElement, children, false);
860
- } catch (error) {
861
- console.error("❌ DataAttrNode to JSX conversion error:", error);
862
- return null;
863
- }
864
- };
865
- const createWrapperNode = (textContent, children) => ({
866
- tagName: "div",
867
- id: nanoid(6),
868
- attributes: [{
869
- name: DATA_ATTR.ITEM,
870
- value: "true"
871
- }],
872
- dataAttributes: [{
873
- name: DATA_ATTR.ITEM,
874
- value: "true"
875
- }],
876
- textContent,
877
- children
878
- });
879
- const createFragmentNode = (textContent, children) => ({
880
- tagName: "",
881
- id: nanoid(6),
882
- attributes: [],
883
- dataAttributes: [],
884
- textContent,
885
- children,
886
- isFragment: true
887
- });
888
- const processChildrenBinding = (jsxElement, processedNodes, shouldWrap = true, source) => {
889
- const jsxChildren = jsxElement.children.filter((child) => import_lib$2.isJSXElement(child) || import_lib$2.isJSXFragment(child));
890
- if (!jsxChildren.length) return;
891
- const childrenNodes = [];
892
- jsxChildren.forEach((child) => {
893
- if (import_lib$2.isJSXElement(child)) {
894
- const childResults = extractFromNode(child, processedNodes, source);
895
- if (shouldWrap) {
896
- const wrapperNode = createWrapperNode(collectText(child.children), childResults);
897
- wrapperNode.source = source?.slice(child.start, child.end);
898
- const dataId = childResults[0]?.dataAttributes.find((attr) => attr.name === DATA_ATTR.ID)?.value;
899
- if (dataId) wrapperNode.id = `child:${dataId}`;
900
- childrenNodes.push(wrapperNode);
901
- } else childrenNodes.push(...childResults);
902
- } else if (import_lib$2.isJSXFragment(child)) {
903
- processedNodes?.add(child);
904
- const fragmentChildren = [];
905
- child.children.forEach((fragmentChild) => {
906
- if (import_lib$2.isJSXElement(fragmentChild)) {
907
- const childResults = extractFromNode(fragmentChild, processedNodes, source);
908
- fragmentChildren.push(...childResults);
909
- }
910
- });
911
- if (fragmentChildren.length) {
912
- const fragmentNode = createFragmentNode(collectText(child.children), fragmentChildren);
913
- fragmentNode.source = source?.slice(child.start, child.end);
914
- childrenNodes.push(fragmentNode);
915
- }
916
- }
917
- });
918
- return childrenNodes.length ? childrenNodes : void 0;
919
- };
920
- const skipItemsChildren = (jsxElement, processedNodes, propertyName = "items") => {
921
- const itemsAttr = jsxElement.openingElement.attributes.find((attr) => import_lib$2.isJSXAttribute(attr) && import_lib$2.isJSXIdentifier(attr.name) && attr.name.name === propertyName);
922
- if (!itemsAttr || !import_lib$2.isJSXAttribute(itemsAttr)) return;
923
- if (itemsAttr.value && import_lib$2.isJSXExpressionContainer(itemsAttr.value) && import_lib$2.isArrayExpression(itemsAttr.value.expression)) itemsAttr.value.expression.elements.forEach((element) => {
924
- if (import_lib$2.isObjectExpression(element)) element.properties.forEach((prop) => {
925
- if (import_lib$2.isObjectProperty(prop) && import_lib$2.isIdentifier(prop.key) && import_lib$2.isJSXElement(prop.value)) markProcessedJSX(prop.value, processedNodes);
926
- });
927
- });
928
- };
929
- const markProcessedJSX = (node, processedNodes) => {
930
- if (import_lib$2.isJSXElement(node) || import_lib$2.isJSXFragment(node)) {
931
- processedNodes.add(node);
932
- node.children.forEach((child) => markProcessedJSX(child, processedNodes));
933
- return;
934
- }
935
- if (import_lib$2.isJSXExpressionContainer(node) || import_lib$2.isParenthesizedExpression(node)) markProcessedJSX(node.expression, processedNodes);
936
- };
937
- const getBindingExpression = (opening) => {
938
- for (const attr of opening.attributes) if (import_lib$2.isJSXAttribute(attr) && import_lib$2.isJSXIdentifier(attr.name) && attr.name.name === DATA_ATTR.BINDING && attr.value && import_lib$2.isJSXExpressionContainer(attr.value)) {
939
- const expression = unwrapExpression(attr.value.expression);
940
- if (import_lib$2.isArrayExpression(expression)) return expression;
941
- }
942
- return null;
943
- };
944
- const readNodeBindingInfo = (node, source) => {
945
- const opening = node.openingElement;
946
- const tagName = getTagName(opening);
947
- const { allAttrs, dataAttrs } = extractAttributes(opening.attributes, source);
948
- const bindingAttr = dataAttrs.find((attr) => attr.name === DATA_ATTR.BINDING);
949
- const bindingExpr = getBindingExpression(opening);
950
- const bindings = bindingExpr ? parseBindingExpression(bindingExpr) : bindingAttr?.value ? parseBinding(bindingAttr.value) : [];
951
- const childrenBinding = bindings.find((b) => b.property === BINDING_PROP.CHILDREN);
952
- const arrayBindings = bindings.filter((b) => b.property === BINDING_PROP.ITEMS || b.type === "array");
953
- const innerHtmlBinding = bindings.find((b) => b.property === BINDING_PROP.INNER_HTML);
954
- let rawChildren;
955
- if (innerHtmlBinding && node.children.length > 0) rawChildren = node.children.map((child) => generateCode(child)).join("").trim();
956
- return {
957
- tagName,
958
- allAttrs,
959
- dataAttrs,
960
- bindings,
961
- childrenBinding,
962
- arrayBindings,
963
- rawChildren
964
- };
965
- };
966
- const parseToNodes = (raw) => {
967
- const wrapped = wrap(raw);
968
- const ast = (0, import_lib$1.parse)(wrapped, {
969
- sourceType: "module",
970
- plugins: ["jsx", "typescript"],
971
- errorRecovery: true
972
- });
973
- const results = [];
974
- const processedNodes = /* @__PURE__ */ new WeakSet();
975
- traverse(ast, { JSXElement(path) {
976
- if (processedNodes.has(path.node)) return;
977
- const { tagName, allAttrs, dataAttrs, bindings, childrenBinding, arrayBindings, rawChildren } = readNodeBindingInfo(path.node, wrapped);
978
- if (!tagName || !dataAttrs.length) return;
979
- let childrenNodes;
980
- if (childrenBinding) childrenNodes = processChildrenBinding(path.node, processedNodes, true, wrapped);
981
- for (const arrayBinding of arrayBindings) skipItemsChildren(path.node, processedNodes, arrayBinding.property);
982
- results.push({
983
- tagName,
984
- attributes: allAttrs,
985
- dataAttributes: dataAttrs,
986
- textContent: collectText(path.node.children),
987
- rawChildren,
988
- children: childrenNodes,
989
- bindings,
990
- loc: path.node.loc ? {
991
- start: {
992
- line: path.node.loc.start.line,
993
- column: path.node.loc.start.column
994
- },
995
- end: {
996
- line: path.node.loc.end.line,
997
- column: path.node.loc.end.column
998
- }
999
- } : void 0
1000
- });
1001
- } });
1002
- return results;
1003
- };
1004
- function extract(raw) {
1005
- if (extractCache.has(raw)) return extractCache.get(raw);
1006
- const results = parseToNodes(raw);
1007
- extractCache.set(raw, results);
1008
- return results;
1009
- }
1010
- function extractFromNode(node, processedNodes, source) {
1011
- processedNodes?.add(node);
1012
- const { tagName, allAttrs, dataAttrs, bindings, childrenBinding, rawChildren } = readNodeBindingInfo(node, source);
1013
- let childrenNodes;
1014
- if (childrenBinding) childrenNodes = processChildrenBinding(node, processedNodes, true, source);
1015
- if (!childrenNodes) childrenNodes = processChildrenBinding(node, processedNodes, false, source);
1016
- return [{
1017
- tagName,
1018
- attributes: allAttrs,
1019
- dataAttributes: dataAttrs,
1020
- textContent: collectText(node.children),
1021
- rawChildren,
1022
- children: childrenNodes,
1023
- bindings
1024
- }];
1025
- }
1026
- function clearExtractCache() {
1027
- extractCache.clear();
1028
- }
1029
- //#endregion
1030
- //#region src/utils/ast/children.ts
1031
- const modeledSignatures = (nodes) => nodes.map((node) => {
1032
- const jsx = nodeToJSX(node);
1033
- if (!jsx) throw new Error("Invalid child node");
1034
- return generateCode(jsx);
1035
- });
1036
- const getChildrenSignatures = (nodes) => {
1037
- const modeled = modeledSignatures(nodes);
1038
- return nodes.map((node, index) => JSON.stringify([node.source ?? null, modeled[index]]));
1039
- };
1040
- const indicesAreValid = (indices, count) => Array.isArray(indices) && new Set(indices).size === indices.length && indices.every((index) => Number.isInteger(index) && index >= 0 && index < count);
1041
- const copySource = (source, usedIds) => {
1042
- const node = (0, import_lib$1.parseExpression)(source, { plugins: ["jsx", "typescript"] });
1043
- const edits = [];
1044
- const newId = () => {
1045
- let id = nanoid(12);
1046
- while (usedIds.has(id)) id = nanoid(12);
1047
- usedIds.add(id);
1048
- return id;
1049
- };
1050
- import_lib$2.traverseFast(node, (child) => {
1051
- if (!import_lib$2.isJSXOpeningElement(child)) return;
1052
- const ids = child.attributes.filter((attr) => import_lib$2.isJSXAttribute(attr) && import_lib$2.isJSXIdentifier(attr.name, { name: "data-id" }));
1053
- if (ids.length > 1) throw new Error("Duplicate data-id attributes");
1054
- const attr = ids[0];
1055
- if (attr && child.attributes.slice(child.attributes.indexOf(attr) + 1).some((attribute) => import_lib$2.isJSXSpreadAttribute(attribute))) throw new Error("A spread may override the copied data-id");
1056
- if (attr) {
1057
- const value = attr.value;
1058
- if (!import_lib$2.isStringLiteral(value) || value.start == null || value.end == null) throw new Error("Cannot copy a dynamic data-id");
1059
- edits.push({
1060
- start: value.start,
1061
- end: value.end,
1062
- content: JSON.stringify(newId())
1063
- });
1064
- } else {
1065
- const at = child.attributes.at(-1)?.end ?? child.name.end;
1066
- if (at == null) throw new Error("Missing opening element span");
1067
- edits.push({
1068
- start: at,
1069
- end: at,
1070
- content: ` data-id="${newId()}"`
1071
- });
1072
- }
1073
- });
1074
- return applyEdits(source, edits);
1075
- };
1076
- const editChildrenSource = (source, parent, input) => {
1077
- try {
1078
- if (!parent.closingElement || parent.start == null || parent.end == null) return null;
1079
- const value = typeof input === "string" ? JSON.parse(input) : input;
1080
- const children = parent.children.filter((child) => import_lib$2.isJSXElement(child) || import_lib$2.isJSXFragment(child));
1081
- const raw = children.map((child) => source.slice(child.start, child.end));
1082
- const models = extract(source.slice(parent.start, parent.end))[0]?.children ?? [];
1083
- if (models.length !== children.length) return null;
1084
- const signatures = modeledSignatures(models);
1085
- const replaceSlots = (next) => {
1086
- const edits = children.map((child, index) => ({
1087
- start: child.start,
1088
- end: child.end,
1089
- content: next[index] ?? ""
1090
- }));
1091
- if (next.length > children.length) {
1092
- const at = parent.closingElement.start;
1093
- edits.push({
1094
- start: at,
1095
- end: at,
1096
- content: next.slice(children.length).join("")
1097
- });
1098
- }
1099
- return edits;
1100
- };
1101
- if (Array.isArray(value)) {
1102
- const desired = modeledSignatures(value);
1103
- const lossless = raw.every((text, index) => generateCode((0, import_lib$1.parseExpression)(text, { plugins: ["jsx", "typescript"] })) === signatures[index]);
1104
- const consumed = /* @__PURE__ */ new Set();
1105
- const next = desired.map((signature, position) => {
1106
- const index = signatures.findIndex((candidate, i) => candidate === signature && !consumed.has(i) && (value[position].source === void 0 || value[position].source === raw[i]));
1107
- if (index >= 0) {
1108
- consumed.add(index);
1109
- return raw[index];
1110
- }
1111
- if (!lossless || value[position].source !== void 0 && !raw.includes(value[position].source)) throw new Error("Use children commands to copy or edit unsupported source");
1112
- return signature;
1113
- });
1114
- const countIds = (text) => {
1115
- const counts = /* @__PURE__ */ new Map();
1116
- import_lib$2.traverseFast((0, import_lib$1.parseExpression)(text, { plugins: ["jsx", "typescript"] }), (node) => {
1117
- if (import_lib$2.isJSXAttribute(node) && import_lib$2.isJSXIdentifier(node.name, { name: "data-id" }) && import_lib$2.isStringLiteral(node.value)) counts.set(node.value.value, (counts.get(node.value.value) ?? 0) + 1);
1118
- });
1119
- return counts;
1120
- };
1121
- const previousIds = countIds(source);
1122
- if ([...countIds(applyEdits(source, replaceSlots(next)))].some(([id, count]) => count > 1 && count > (previousIds.get(id) ?? 0))) return null;
1123
- return replaceSlots(next);
1124
- }
1125
- const request = value;
1126
- if (request?.kind !== "children-edit" || !Array.isArray(request.expected) || request.expected.length !== signatures.length || !getChildrenSignatures(models).every((signature, index) => signature === request.expected[index]) || !request.action) return null;
1127
- const { action } = request;
1128
- const usedIds = /* @__PURE__ */ new Set();
1129
- import_lib$2.traverseFast(parent, (node) => {
1130
- if (import_lib$2.isJSXAttribute(node) && import_lib$2.isJSXIdentifier(node.name, { name: "data-id" }) && import_lib$2.isStringLiteral(node.value)) usedIds.add(node.value.value);
1131
- });
1132
- switch (action.type) {
1133
- case "move": {
1134
- if (!indicesAreValid([action.from], raw.length) || !indicesAreValid([action.to], raw.length)) return null;
1135
- const next = [...raw];
1136
- const [moved] = next.splice(action.from, 1);
1137
- next.splice(action.to, 0, moved);
1138
- return replaceSlots(next);
1139
- }
1140
- case "move-selected":
1141
- if (!indicesAreValid(action.indices, raw.length) || !["up", "down"].includes(action.direction)) return null;
1142
- return replaceSlots(moveSelectedIndices(raw, new Set(action.indices), action.direction).items);
1143
- case "remove":
1144
- if (!indicesAreValid(action.indices, raw.length)) return null;
1145
- return action.indices.map((index) => ({
1146
- start: children[index].start,
1147
- end: children[index].end,
1148
- content: ""
1149
- }));
1150
- case "duplicate": {
1151
- if (!indicesAreValid(action.indices, raw.length)) return null;
1152
- const content = [...action.indices].sort((a, b) => a - b).map((index) => copySource(raw[index], usedIds)).join("");
1153
- const at = parent.closingElement.start;
1154
- return [{
1155
- start: at,
1156
- end: at,
1157
- content
1158
- }];
1159
- }
1160
- case "append": {
1161
- const content = copySource(raw[0] ?? "<div></div>", usedIds);
1162
- const at = parent.closingElement.start;
1163
- return [{
1164
- start: at,
1165
- end: at,
1166
- content
1167
- }];
1168
- }
1169
- default: return null;
1170
- }
1171
- } catch {
1172
- return null;
1173
- }
1174
- };
1175
- //#endregion
1176
- //#region src/utils/ast/update.ts
1177
- const childrenRange = (element) => {
1178
- const { openingElement, closingElement } = element;
1179
- if (!closingElement || openingElement.end == null || closingElement.start == null) return null;
1180
- return {
1181
- start: openingElement.end,
1182
- end: closingElement.start
1183
- };
1184
- };
1185
- const findAttribute = (opening, propertyName) => {
1186
- return opening.attributes.find((attr) => import_lib$2.isJSXAttribute(attr) && import_lib$2.isJSXIdentifier(attr.name) && attr.name.name === propertyName);
1187
- };
1188
- const attributeInsertPoint = (opening) => {
1189
- return opening.attributes[opening.attributes.length - 1]?.end ?? opening.name.end ?? null;
1190
- };
1191
- const editInnerText = (source, element, value) => {
1192
- const range = childrenRange(element);
1193
- if (!range) return [];
1194
- const [only] = element.children;
1195
- if (element.children.length === 1 && import_lib$2.isJSXText(only) && only.start != null && only.end != null) {
1196
- const raw = source.slice(only.start, only.end);
1197
- if (raw.trim() !== "") {
1198
- const leading = raw.length - raw.trimStart().length;
1199
- const trailing = raw.length - raw.trimEnd().length;
1200
- return [{
1201
- start: only.start + leading,
1202
- end: only.end - trailing,
1203
- content: value
1204
- }];
1205
- }
1206
- }
1207
- const edits = [];
1208
- for (const child of element.children) if (import_lib$2.isJSXText(child) && child.start != null && child.end != null) edits.push({
1209
- start: child.start,
1210
- end: child.end,
1211
- content: ""
1212
- });
1213
- edits.push({
1214
- start: range.end,
1215
- end: range.end,
1216
- content: value
1217
- });
1218
- return edits;
1219
- };
1220
- const editInnerHTML = (element, value) => {
1221
- const range = childrenRange(element);
1222
- if (!range) return [];
1223
- return [{
1224
- start: range.start,
1225
- end: range.end,
1226
- content: value
1227
- }];
1228
- };
1229
- const editRichtext = (element, value) => {
1230
- const edits = [];
1231
- const range = childrenRange(element);
1232
- if (range && range.start !== range.end) edits.push({
1233
- start: range.start,
1234
- end: range.end,
1235
- content: ""
1236
- });
1237
- const opening = element.openingElement;
1238
- const attribute = import_lib$2.jsxAttribute(import_lib$2.jsxIdentifier("dangerouslySetInnerHTML"), import_lib$2.jsxExpressionContainer(import_lib$2.objectExpression([import_lib$2.objectProperty(import_lib$2.identifier("__html"), import_lib$2.stringLiteral(value))])));
1239
- const content = generateCode(attribute);
1240
- const existing = findAttribute(opening, "dangerouslySetInnerHTML");
1241
- if (existing && existing.start != null && existing.end != null) {
1242
- edits.push({
1243
- start: existing.start,
1244
- end: existing.end,
1245
- content,
1246
- indent: true
1247
- });
1248
- return edits;
1249
- }
1250
- const insertAt = attributeInsertPoint(opening);
1251
- if (insertAt == null) return null;
1252
- edits.push({
1253
- start: insertAt,
1254
- end: insertAt,
1255
- content: ` ${content}`,
1256
- indent: true
1257
- });
1258
- return edits;
1259
- };
1260
- const editJsxAttribute = (opening, propertyName, value) => {
1261
- const attribute = findAttribute(opening, propertyName);
1262
- if (!attribute) return null;
1263
- const content = `{${String(value).trim()}}`;
1264
- if (attribute.value?.start != null && attribute.value.end != null) return [{
1265
- start: attribute.value.start,
1266
- end: attribute.value.end,
1267
- content
1268
- }];
1269
- const insertAt = attribute.name.end;
1270
- if (insertAt == null) return null;
1271
- return [{
1272
- start: insertAt,
1273
- end: insertAt,
1274
- content: `=${content}`
1275
- }];
1276
- };
1277
- const holdsStructuralExpression = (value) => import_lib$2.isJSXExpressionContainer(value) && (import_lib$2.isArrayExpression(unwrapExpression(value.expression)) || import_lib$2.isObjectExpression(unwrapExpression(value.expression)));
1278
- const structuralSource = (value) => {
1279
- try {
1280
- const expression = (0, import_lib$1.parseExpression)(value.trim(), { plugins: ["jsx", "typescript"] });
1281
- return import_lib$2.isArrayExpression(unwrapExpression(expression)) || import_lib$2.isObjectExpression(unwrapExpression(expression)) ? expression : null;
1282
- } catch {
1283
- return null;
1284
- }
1285
- };
1286
- const buildAttributeValue = (value, type, current) => {
1287
- if (type === "array" || type === "object") {
1288
- if (typeof value === "string") try {
1289
- return import_lib$2.jsxExpressionContainer((0, import_lib$1.parseExpression)(value.trim(), { plugins: ["jsx", "typescript"] }));
1290
- } catch {
1291
- return import_lib$2.stringLiteral(value);
1292
- }
1293
- const expr = valueToExpression(value);
1294
- return expr ? import_lib$2.jsxExpressionContainer(expr) : import_lib$2.stringLiteral("");
1295
- }
1296
- if (typeof value === "string") {
1297
- if (holdsStructuralExpression(current) && !(type && STRING_VALUED_TYPES.has(type))) {
1298
- const structural = structuralSource(value);
1299
- if (structural) return import_lib$2.jsxExpressionContainer(structural);
1300
- }
1301
- return import_lib$2.stringLiteral(value);
1302
- }
1303
- const expr = valueToExpression(value);
1304
- return expr ? import_lib$2.jsxExpressionContainer(expr) : import_lib$2.stringLiteral(String(value));
1305
- };
1306
- const editAttribute = (opening, propertyName, value, type) => {
1307
- const attribute = findAttribute(opening, propertyName);
1308
- if (!attribute || attribute.start == null || attribute.end == null) return null;
1309
- if (typeof value === "string" && (type === "array" || type === "object" || holdsStructuralExpression(attribute.value) && !(type && STRING_VALUED_TYPES.has(type)))) {
1310
- const expression = structuralSource(value);
1311
- if (expression && import_lib$2.isJSXExpressionContainer(attribute.value)) {
1312
- const text = value.trim();
1313
- const lineComment = expression.trailingComments?.some((comment) => comment.type === "CommentLine");
1314
- return [{
1315
- start: attribute.value.expression.start,
1316
- end: attribute.value.expression.end,
1317
- content: `${text}${lineComment ? "\n" : ""}`
1318
- }];
1319
- }
1320
- }
1321
- const content = generateCode(import_lib$2.jsxAttribute(attribute.name, buildAttributeValue(value, type, attribute.value)));
1322
- return [{
1323
- start: attribute.start,
1324
- end: attribute.end,
1325
- content,
1326
- indent: true
1327
- }];
1328
- };
1329
- const update = (code, dataId, label, value, property) => {
1330
- try {
1331
- const wrapped = wrap(code);
1332
- const ast = (0, import_lib$1.parse)(wrapped, {
1333
- sourceType: "module",
1334
- plugins: ["jsx", "typescript"]
1335
- });
1336
- let changed = false;
1337
- let failure;
1338
- const edits = [];
1339
- const collect = (result, onNull) => {
1340
- if (!result) {
1341
- failure = onNull();
1342
- return;
1343
- }
1344
- edits.push(...result);
1345
- changed = true;
1346
- };
1347
- traverse(ast, { JSXElement(path) {
1348
- const opening = path.node.openingElement;
1349
- if (!opening.attributes.find((attr) => {
1350
- 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;
1351
- })) return;
1352
- const bindingAttr = opening.attributes.find((attr) => import_lib$2.isJSXAttribute(attr) && import_lib$2.isJSXIdentifier(attr.name) && attr.name.name === DATA_ATTR.BINDING);
1353
- if (!bindingAttr?.value) {
1354
- failure = {
1355
- reason: "no-binding",
1356
- dataId
1357
- };
1358
- return;
1359
- }
1360
- let bindingValue = "";
1361
- if (import_lib$2.isStringLiteral(bindingAttr.value)) bindingValue = bindingAttr.value.value;
1362
- else if (import_lib$2.isJSXExpressionContainer(bindingAttr.value)) try {
1363
- bindingValue = generateCode(bindingAttr.value.expression);
1364
- } catch (error) {
1365
- failure = {
1366
- reason: "parse-error",
1367
- error
1368
- };
1369
- return;
1370
- }
1371
- const matches = parseBinding(bindingValue).filter((binding) => property !== void 0 ? binding.property === property : binding.label === label);
1372
- if (matches.length === 0) {
1373
- failure = {
1374
- reason: "binding-not-declared",
1375
- dataId,
1376
- label,
1377
- property
1378
- };
1379
- return;
1380
- }
1381
- if (matches.length > 1) {
1382
- failure = {
1383
- reason: "duplicate-binding",
1384
- dataId,
1385
- label,
1386
- property,
1387
- count: matches.length
1388
- };
1389
- return;
1390
- }
1391
- const propertyBinding = matches[0];
1392
- const prop = propertyBinding.property;
1393
- switch (prop) {
1394
- case BINDING_PROP.INNER_TEXT:
1395
- collect(editInnerText(wrapped, path.node, String(value)), () => ({
1396
- reason: "parse-error",
1397
- error: /* @__PURE__ */ new Error(`could not update "${prop}"`)
1398
- }));
1399
- break;
1400
- case BINDING_PROP.INNER_HTML:
1401
- collect(propertyBinding.type === "richtext" ? editRichtext(path.node, String(value)) : editInnerHTML(path.node, String(value)), () => ({
1402
- reason: "parse-error",
1403
- error: /* @__PURE__ */ new Error(`could not update "${prop}"`)
1404
- }));
1405
- break;
1406
- case BINDING_PROP.CHILDREN:
1407
- collect(editChildrenSource(wrapped, path.node, value), () => ({
1408
- reason: "parse-error",
1409
- error: /* @__PURE__ */ new Error("Unsupported or stale children edit; source was preserved")
1410
- }));
1411
- break;
1412
- default: collect(propertyBinding.type === "jsx" ? editJsxAttribute(opening, prop, value) : editAttribute(opening, prop, value, propertyBinding.type), () => ({
1413
- reason: "attribute-not-found",
1414
- dataId,
1415
- property: prop
1416
- }));
1417
- }
1418
- } });
1419
- if (!changed) return {
1420
- code,
1421
- success: false,
1422
- failure: failure ?? {
1423
- reason: "element-not-found",
1424
- dataId
1425
- }
1426
- };
1427
- return {
1428
- code: unwrap(applyEdits(wrapped, edits)),
1429
- success: true
1430
- };
1431
- } catch (error) {
1432
- console.error("❌ Code update error:", error);
1433
- return {
1434
- code,
1435
- success: false,
1436
- failure: {
1437
- reason: "parse-error",
1438
- error
1439
- }
1440
- };
1441
- }
1442
- };
1443
- const bulkUpdate = (raw, entries) => {
1444
- let current = raw;
1445
- const failures = [];
1446
- for (const entry of entries) {
1447
- const result = update(current, entry.dataId, entry.label, entry.value, entry.property);
1448
- current = result.code;
1449
- if (!result.success && result.failure) failures.push(result.failure);
1450
- }
1451
- return failures.length > 0 ? {
1452
- code: current,
1453
- success: false,
1454
- failures
1455
- } : {
1456
- code: current,
1457
- success: true
1458
- };
1459
- };
1460
- //#endregion
1461
- //#region src/utils/ast/tree.ts
1462
- const replaceIds = (code, generateId = () => nanoid(6)) => {
1463
- return code.replace(new RegExp(`${DATA_ATTR.ID}="[^"]*"`, "g"), () => {
1464
- return `${DATA_ATTR.ID}="${generateId()}"`;
1465
- });
1466
- };
1467
- const fillIds = (code, generateId = () => nanoid(6)) => {
1468
- return code.replace(new RegExp(`${DATA_ATTR.ID}=""`, "g"), () => {
1469
- return `${DATA_ATTR.ID}="${generateId()}"`;
1470
- });
1471
- };
1472
- const clone = (element, generateId = () => nanoid(6)) => {
1473
- const cloned = import_lib$2.cloneNode(element, true);
1474
- const generatedCode = generateCode(cloned);
1475
- const code = replaceIds(generatedCode, generateId);
1476
- return (0, import_lib$1.parseExpression)(code, { plugins: ["jsx", "typescript"] });
1477
- };
1478
- //#endregion
1479
- //#region src/utils/ast/validate.ts
1480
- const VALID = { valid: true };
1481
- const validateBindingValue = (binding, value) => {
1482
- if (value === "" || value === null || value === void 0) {
1483
- if (binding.required) return {
1484
- valid: false,
1485
- message: "This field is required."
1486
- };
1487
- return VALID;
1488
- }
1489
- if (typeof value === "number") {
1490
- if (binding.min !== void 0 && value < binding.min) return {
1491
- valid: false,
1492
- message: `Must be at least ${binding.min}.`
1493
- };
1494
- if (binding.max !== void 0 && value > binding.max) return {
1495
- valid: false,
1496
- message: `Must be at most ${binding.max}.`
1497
- };
1498
- }
1499
- if (typeof value === "string" && binding.pattern) {
1500
- let regex;
1501
- try {
1502
- regex = new RegExp(binding.pattern);
1503
- } catch {
1504
- return VALID;
1505
- }
1506
- if (!regex.test(value)) return {
1507
- valid: false,
1508
- message: "Value does not match the required format."
1509
- };
1510
- }
1511
- if (typeof value === "string" && binding.type === "url") try {
1512
- new URL(value);
1513
- } catch {
1514
- return {
1515
- valid: false,
1516
- message: "Must be a valid URL."
1517
- };
1518
- }
1519
- if (typeof value === "string" && binding.type === "date") {
1520
- if (Number.isNaN(Date.parse(value))) return {
1521
- valid: false,
1522
- message: "Must be a valid date."
1523
- };
1524
- }
1525
- return VALID;
1526
- };
1527
- //#endregion
1528
- export { parseValue as A, parseBindingExpression as C, extractObjectProperties as D, extractNodeValue as E, generateCode as M, flattenEditableValue as O, parseBinding as S, createNodeFromValue as T, updateArrayItemValue as _, bulkUpdate as a, getCurrentValue as b, clearExtractCache as c, duplicateArrayItems as d, moveArrayItem as f, updateArrayItemProperty as g, removeArrayItems as h, replaceIds as i, setEditableValue as j, parseArrayExpression as k, extract as l, parseItems as m, clone as n, update as o, moveArrayItems as p, fillIds as r, getChildrenSignatures as s, validateBindingValue as t, appendArrayItem as u, moveSelectedIndices as v, arrayExpressionToCode as w, getStructuredValue as x, findEditableChildren as y };
1529
-
1530
- //# sourceMappingURL=ast-Bx2Avo4d.js.map