@jbpark/live-editor 4.6.1 → 6.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 (91) hide show
  1. package/README.ko.md +37 -35
  2. package/README.md +37 -35
  3. package/dist/{boundary-BLB80tyw.js → boundary-CySnDUs2.js} +5 -4
  4. package/dist/boundary-CySnDUs2.js.map +1 -0
  5. package/dist/{compile-Dxas-D05.js → compile-my0AjsCw.js} +8 -7
  6. package/dist/compile-my0AjsCw.js.map +1 -0
  7. package/dist/constants-st9gnJ5g.js +55 -0
  8. package/dist/constants-st9gnJ5g.js.map +1 -0
  9. package/dist/{context-B8MzP7_p.js → context-Bjq0CvBE.js} +3 -3
  10. package/dist/{context-B8MzP7_p.js.map → context-Bjq0CvBE.js.map} +1 -1
  11. package/dist/{core-Bgfek364.js → core-BNVuH8-l.js} +51 -14
  12. package/dist/core-BNVuH8-l.js.map +1 -0
  13. package/dist/{detect-typescript-Dr_oLniM.js → detect-typescript-CMF0FVKD.js} +2 -2
  14. package/dist/{detect-typescript-Dr_oLniM.js.map → detect-typescript-CMF0FVKD.js.map} +1 -1
  15. package/dist/dnd/index.d.ts +3 -2
  16. package/dist/dnd/index.js +3 -2
  17. package/dist/dnd-BvjEDo-x.js +4197 -0
  18. package/dist/dnd-BvjEDo-x.js.map +1 -0
  19. package/dist/document-BQhb7YR8.d.ts +17 -0
  20. package/dist/{document-CHO215iP.js → document-uHqw0mvr.js} +194 -109
  21. package/dist/document-uHqw0mvr.js.map +1 -0
  22. package/dist/edit-options-C_r9aCz4.d.ts +100 -0
  23. package/dist/editor/index.d.ts +1 -1
  24. package/dist/editor/index.js +2 -2
  25. package/dist/{editor-CMElfHer.js → editor-CvnzrM9J.js} +2 -2
  26. package/dist/{editor-CMElfHer.js.map → editor-CvnzrM9J.js.map} +1 -1
  27. package/dist/error/index.d.ts +1 -1
  28. package/dist/error/index.js +2 -2
  29. package/dist/{error-CN_GCnXB.js → error-CFzvnLCf.js} +18 -32
  30. package/dist/error-CFzvnLCf.js.map +1 -0
  31. package/dist/{index-DpDU1IAw.d.ts → index-92L7F440.d.ts} +2 -2
  32. package/dist/{index-DrWtSKXu.d.ts → index-BZpZwrxT.d.ts} +2 -2
  33. package/dist/index-C8h8TcIl.d.ts +15 -0
  34. package/dist/{index-13BDSrQc.d.ts → index-C93npmTU.d.ts} +4 -6
  35. package/dist/{index-DQkL37eL.d.ts → index-CqsS207F.d.ts} +6 -12
  36. package/dist/{index-CiWB0zFb.d.ts → index-DQcdHg_V.d.ts} +18 -136
  37. package/dist/{index-CRwEhJ7w.d.ts → index-DfIvkht8.d.ts} +3 -3
  38. package/dist/index.d.ts +12 -11
  39. package/dist/index.js +6 -6
  40. package/dist/index.js.map +1 -1
  41. package/dist/{messages-IBPs4TkZ.d.ts → messages-BpN3QIhj.d.ts} +8 -2
  42. package/dist/{messages-CSrMI4Rm.js → messages-DrINcRdG.js} +8 -2
  43. package/dist/messages-DrINcRdG.js.map +1 -0
  44. package/dist/preview/index.d.ts +2 -2
  45. package/dist/preview/index.js +2 -3
  46. package/dist/{preview-CtyG5UbH.js → preview-B05MkVIQ.js} +16 -13
  47. package/dist/preview-B05MkVIQ.js.map +1 -0
  48. package/dist/provider/index.d.ts +2 -2
  49. package/dist/provider/index.js +2 -2
  50. package/dist/{sections-jYuqS4KB.js → sections-DhH_aVf5.js} +4 -7
  51. package/dist/sections-DhH_aVf5.js.map +1 -0
  52. package/dist/style.css +809 -4950
  53. package/dist/{validate-DB59Z_Nx.d.ts → types-Czps1Txy.d.ts} +12 -28
  54. package/dist/ui-kit/index.d.ts +22 -0
  55. package/dist/{constants-DU17Tdwo.js → ui-kit/index.js} +147 -54
  56. package/dist/ui-kit/index.js.map +1 -0
  57. package/dist/ui-kit/style.css +5039 -0
  58. package/dist/update-2PJbwoS8.d.ts +68 -0
  59. package/dist/{items-BXXtMUNI.js → update-BuYQJqjq.js} +143 -392
  60. package/dist/update-BuYQJqjq.js.map +1 -0
  61. package/dist/{use-dynamic-tailwind-BP1toJkW.js → use-dynamic-tailwind-B3l1qZRW.js} +318 -287
  62. package/dist/use-dynamic-tailwind-B3l1qZRW.js.map +1 -0
  63. package/dist/use-field-state-iQGW0vc6.js +131 -0
  64. package/dist/use-field-state-iQGW0vc6.js.map +1 -0
  65. package/dist/utils/ast/index.d.ts +47 -4
  66. package/dist/utils/ast/index.js +4 -64
  67. package/dist/utils/ast/index.js.map +1 -1
  68. package/dist/utils/index.d.ts +13 -32
  69. package/dist/utils/index.js +4 -26
  70. package/dist/validate-CZz30Pnb.js +122 -0
  71. package/dist/validate-CZz30Pnb.js.map +1 -0
  72. package/dist/validate-CiA1LF6S.d.ts +33 -0
  73. package/package.json +20 -10
  74. package/dist/boundary-BLB80tyw.js.map +0 -1
  75. package/dist/compile-Dxas-D05.js.map +0 -1
  76. package/dist/constants-DU17Tdwo.js.map +0 -1
  77. package/dist/core-Bgfek364.js.map +0 -1
  78. package/dist/dnd-V8NAxd_R.js +0 -2755
  79. package/dist/dnd-V8NAxd_R.js.map +0 -1
  80. package/dist/document-CHO215iP.js.map +0 -1
  81. package/dist/document-DqRSCtsx.d.ts +0 -1614
  82. package/dist/error-CN_GCnXB.js.map +0 -1
  83. package/dist/index-C_PfR4X9.d.ts +0 -734
  84. package/dist/items-BXXtMUNI.js.map +0 -1
  85. package/dist/messages-CSrMI4Rm.js.map +0 -1
  86. package/dist/preview-CtyG5UbH.js.map +0 -1
  87. package/dist/sections-jYuqS4KB.js.map +0 -1
  88. package/dist/use-dynamic-tailwind-BP1toJkW.js.map +0 -1
  89. package/dist/utils/index.js.map +0 -1
  90. package/dist/validate-iLo8IONY.js +0 -64
  91. package/dist/validate-iLo8IONY.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { $ as jsxClosingFragment, A as isJSXElement, B as isObjectExpression, C as booleanLiteral, D as isExpression, E as isBooleanLiteral, F as isJSXOpeningElement, G as isTSAsExpression, H as isParenthesizedExpression, I as isJSXSpreadAttribute, J as isTSTypeAssertion, K as isTSNonNullExpression, L as isJSXText, M as isJSXExpressionContainer, N as isJSXFragment, O as isIdentifier, P as isJSXIdentifier, Q as jsxClosingElement, R as isNullLiteral, S as arrayExpression, T as isArrayExpression, U as isSpreadElement, V as isObjectProperty, W as isStringLiteral, X as isUnaryExpression, Y as isTemplateLiteral, Z as jsxAttribute, _ as generateCode, _t as parse, at as jsxOpeningElement, b as getJSXTagName, ct as nullLiteral, d as traverse, dt as objectProperty, et as jsxElement, ft as stringLiteral, g as attrValue, gt as unaryExpression, ht as traverseFast, it as jsxMemberExpression, j as isJSXEmptyExpression, k as isJSXAttribute, lt as numericLiteral, mt as templateLiteral, nt as jsxFragment, ot as jsxOpeningFragment, pt as templateElement, q as isTSSatisfiesExpression, rt as jsxIdentifier, st as jsxText, tt as jsxExpressionContainer, ut as objectExpression, v as unwrap, vt as parseExpression, w as identifier, x as nanoid, y as wrap, z as isNumericLiteral } from "./document-CHO215iP.js";
2
- import { c as RESERVED_BINDING_PROPERTIES, n as CONFIG, r as DATA_ATTR, s as REGEX, t as BINDING_PROP } from "./constants-DU17Tdwo.js";
1
+ import { $ as jsxOpeningFragment, A as isJSXText, B as isTSSatisfiesExpression, C as isJSXElement, D as isJSXIdentifier, E as isJSXFragment, F as isParenthesizedExpression, G as jsxClosingElement, H as isTemplateLiteral, J as jsxExpressionContainer, K as jsxClosingFragment, L as isStringLiteral, M as isNumericLiteral, N as isObjectExpression, O as isJSXOpeningElement, P as isObjectProperty, Q as jsxOpeningElement, R as isTSAsExpression, S as isJSXAttribute, T as isJSXExpressionContainer, U as isUnaryExpression, V as isTSTypeAssertion, W as jsxAttribute, X as jsxIdentifier, Y as jsxFragment, Z as jsxMemberExpression, _ as identifier, at as stringLiteral, c as traverse, ct as traverseFast, d as applyEdits, dt as parseExpression, et as jsxText, f as getJSXTagName, g as booleanLiteral, h as arrayExpression, it as objectProperty, j as isNullLiteral, k as isJSXSpreadAttribute, lt as unaryExpression, m as generate, nt as numericLiteral, p as nanoid, q as jsxElement, rt as objectExpression, tt as nullLiteral, ut as parse, v as isArrayExpression, w as isJSXEmptyExpression, x as isIdentifier, y as isBooleanLiteral, z as isTSNonNullExpression } from "./document-uHqw0mvr.js";
2
+ import { n as CONFIG, o as REGEX, r as DATA_ATTR, s as RESERVED_BINDING_PROPERTIES, t as BINDING_PROP } from "./constants-st9gnJ5g.js";
3
3
  import { n as registerEditorCache } from "./editor-caches-ClMvdcQF.js";
4
4
  import { t as createBoundedCache } from "./cache-B0-XcIxJ.js";
5
5
  import { z } from "zod";
@@ -14,9 +14,40 @@ const BINDING_TYPES = [
14
14
  "jsx",
15
15
  "richtext",
16
16
  "date",
17
- "url"
17
+ "url",
18
+ "email",
19
+ "tel",
20
+ "time",
21
+ "datetime"
18
22
  ];
19
23
  //#endregion
24
+ //#region src/utils/ast/helpers.ts
25
+ const wrap = (code) => {
26
+ return `<>${code}</>`;
27
+ };
28
+ const unwrap = (generated) => {
29
+ return generated.replace(/^<>\s*/g, "").replace(/\s*<\/>\s*;?\s*$/g, "").trim();
30
+ };
31
+ const attrValue = ({ value, isStringLiteral }) => {
32
+ if (value === null) return null;
33
+ if (isStringLiteral) return stringLiteral(value);
34
+ const trimmed = value.trim();
35
+ if (REGEX.NUMBER.test(trimmed)) return jsxExpressionContainer(numericLiteral(parseFloat(trimmed)));
36
+ if (REGEX.BOOLEAN_OR_NULL.test(trimmed)) {
37
+ const expr = parseExpression(trimmed, { plugins: ["jsx", "typescript"] });
38
+ return jsxExpressionContainer(expr);
39
+ }
40
+ try {
41
+ const expr = parseExpression(trimmed, { plugins: ["jsx", "typescript"] });
42
+ return jsxExpressionContainer(expr);
43
+ } catch {
44
+ return stringLiteral(trimmed);
45
+ }
46
+ };
47
+ const generateCode = (node) => {
48
+ return generate(node, { jsescOption: { minimal: true } }).code;
49
+ };
50
+ //#endregion
20
51
  //#region src/utils/ast/value.ts
21
52
  const dedent = (str) => {
22
53
  const lines = str.replace(/^\n/, "").replace(/\n\s*$/, "").split("\n");
@@ -169,6 +200,8 @@ const extractObjectProperties = (element) => {
169
200
  //#endregion
170
201
  //#region src/utils/ast/binding.ts
171
202
  const bindingTypeSchema = z.enum(BINDING_TYPES);
203
+ const countSchema = z.number().int().nonnegative();
204
+ const dateSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2})?$/);
172
205
  const bindingOptionSchema = z.object({
173
206
  label: z.string(),
174
207
  value: z.string()
@@ -204,7 +237,16 @@ const KNOWN_BINDING_KEYS = /* @__PURE__ */ new Set([
204
237
  "min",
205
238
  "max",
206
239
  "pattern",
207
- "required"
240
+ "patternMessage",
241
+ "required",
242
+ "minLength",
243
+ "maxLength",
244
+ "step",
245
+ "minItems",
246
+ "maxItems",
247
+ "minDate",
248
+ "maxDate",
249
+ "protocols"
208
250
  ]);
209
251
  const isPlainObject = (value) => {
210
252
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -221,7 +263,16 @@ const sanitizeField = (raw) => {
221
263
  min: pick(z.number(), raw.min),
222
264
  max: pick(z.number(), raw.max),
223
265
  pattern: pick(z.string(), raw.pattern),
266
+ patternMessage: pick(z.string(), raw.patternMessage),
224
267
  required: pick(z.boolean(), raw.required),
268
+ minLength: pick(countSchema, raw.minLength),
269
+ maxLength: pick(countSchema, raw.maxLength),
270
+ step: pick(z.number().positive(), raw.step),
271
+ minItems: pick(countSchema, raw.minItems),
272
+ maxItems: pick(countSchema, raw.maxItems),
273
+ minDate: pick(dateSchema, raw.minDate),
274
+ maxDate: pick(dateSchema, raw.maxDate),
275
+ protocols: pick(z.array(z.string().min(1)), raw.protocols),
225
276
  meta: metaEntries.length > 0 ? Object.fromEntries(metaEntries) : void 0
226
277
  };
227
278
  return Object.fromEntries(Object.entries(field).filter(([, value]) => value !== void 0));
@@ -345,7 +396,11 @@ const getCurrentValue = (node, property) => {
345
396
  const STRING_VALUED_TYPES = /* @__PURE__ */ new Set([
346
397
  "string",
347
398
  "url",
399
+ "email",
400
+ "tel",
348
401
  "date",
402
+ "time",
403
+ "datetime",
349
404
  "color",
350
405
  "jsx",
351
406
  "richtext"
@@ -381,6 +436,33 @@ const findEditableChildren = (node) => {
381
436
  return editableChildren;
382
437
  };
383
438
  //#endregion
439
+ //#region src/utils/selection.ts
440
+ const removeIndices = (items, indices) => {
441
+ return items.filter((_, index) => !indices.has(index));
442
+ };
443
+ /**
444
+ * Shifts every selected index up/down by one step as a block, preserving
445
+ * relative order — scattered selections stop moving individually once they
446
+ * hit an unselected neighbor, so the whole group slides together instead of
447
+ * items passing through each other.
448
+ */
449
+ const moveSelectedIndices = (items, indices, direction) => {
450
+ const next = [...items];
451
+ const nextIndices = new Set(indices);
452
+ const ordered = [...indices].sort((a, b) => direction === "up" ? a - b : b - a);
453
+ for (const index of ordered) {
454
+ const target = direction === "up" ? index - 1 : index + 1;
455
+ if (target < 0 || target >= next.length || nextIndices.has(target)) continue;
456
+ [next[index], next[target]] = [next[target], next[index]];
457
+ nextIndices.delete(index);
458
+ nextIndices.add(target);
459
+ }
460
+ return {
461
+ items: next,
462
+ indices: nextIndices
463
+ };
464
+ };
465
+ //#endregion
384
466
  //#region src/utils/ast/extract.ts
385
467
  const collectText = (children) => {
386
468
  return children.filter((c) => isJSXText(c)).map((c) => c.value.trim()).filter((v) => v.length).join(" ");
@@ -646,106 +728,6 @@ function clearExtractCache() {
646
728
  }
647
729
  registerEditorCache(clearExtractCache);
648
730
  //#endregion
649
- //#region src/utils/selection.ts
650
- const removeIndices = (items, indices) => {
651
- return items.filter((_, index) => !indices.has(index));
652
- };
653
- /**
654
- * Shifts every selected index up/down by one step as a block, preserving
655
- * relative order — scattered selections stop moving individually once they
656
- * hit an unselected neighbor, so the whole group slides together instead of
657
- * items passing through each other.
658
- */
659
- const moveSelectedIndices = (items, indices, direction) => {
660
- const next = [...items];
661
- const nextIndices = new Set(indices);
662
- const ordered = [...indices].sort((a, b) => direction === "up" ? a - b : b - a);
663
- for (const index of ordered) {
664
- const target = direction === "up" ? index - 1 : index + 1;
665
- if (target < 0 || target >= next.length || nextIndices.has(target)) continue;
666
- [next[index], next[target]] = [next[target], next[index]];
667
- nextIndices.delete(index);
668
- nextIndices.add(target);
669
- }
670
- return {
671
- items: next,
672
- indices: nextIndices
673
- };
674
- };
675
- //#endregion
676
- //#region src/utils/ast/patch.ts
677
- const hasOnlyLayoutNewlines = (content) => {
678
- let index = 0;
679
- while (index < content.length) {
680
- const char = content[index];
681
- if (char === "`" || char === "<") return false;
682
- if (char === "\"" || char === "'") {
683
- const next = skipStringLiteral(content, index);
684
- if (next === -1) return false;
685
- index = next;
686
- continue;
687
- }
688
- if (char === "/") {
689
- const following = content[index + 1];
690
- if (following === "/") {
691
- const lineEnd = content.indexOf("\n", index + 2);
692
- index = lineEnd === -1 ? content.length : lineEnd;
693
- continue;
694
- }
695
- if (following === "*") {
696
- const commentEnd = content.indexOf("*/", index + 2);
697
- if (commentEnd === -1) return false;
698
- index = commentEnd + 2;
699
- continue;
700
- }
701
- return false;
702
- }
703
- index++;
704
- }
705
- return true;
706
- };
707
- const skipStringLiteral = (content, start) => {
708
- const quote = content[start];
709
- for (let index = start + 1; index < content.length; index++) {
710
- const char = content[index];
711
- if (char === "\\") {
712
- const escaped = content[index + 1];
713
- if (escaped === "\n" || escaped === "\r") return -1;
714
- index++;
715
- continue;
716
- }
717
- if (char === quote) return index + 1;
718
- if (char === "\n") return -1;
719
- }
720
- return -1;
721
- };
722
- const lineIndentAt = (source, offset) => {
723
- const lineStart = source.lastIndexOf("\n", offset - 1) + 1;
724
- return /^[ \t]*/.exec(source.slice(lineStart, offset))?.[0] ?? "";
725
- };
726
- const lineTerminatorOf = (source) => {
727
- return source.includes("\r\n") ? "\r\n" : "\n";
728
- };
729
- const applyEdits = (source, edits) => {
730
- if (edits.length === 0) return source;
731
- const ordered = [...edits].sort((a, b) => a.start - b.start || a.end - b.end);
732
- 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}`);
733
- for (let i = 1; i < ordered.length; i++) {
734
- const previous = ordered[i - 1];
735
- const current = ordered[i];
736
- if (current.start < previous.end) throw new Error(`Overlapping source edits: [${previous.start}, ${previous.end}) and [${current.start}, ${current.end})`);
737
- }
738
- let result = "";
739
- let cursor = 0;
740
- const terminator = lineTerminatorOf(source);
741
- for (const edit of ordered) {
742
- const content = edit.indent && edit.content.includes("\n") && hasOnlyLayoutNewlines(edit.content) ? edit.content.replace(/\n/g, `${terminator}${lineIndentAt(source, edit.start)}`) : edit.content;
743
- result += source.slice(cursor, edit.start) + content;
744
- cursor = edit.end;
745
- }
746
- return result + source.slice(cursor);
747
- };
748
- //#endregion
749
731
  //#region src/utils/ast/children.ts
750
732
  const modeledSignatures = (nodes) => nodes.map((node) => {
751
733
  const jsx = nodeToJSX(node);
@@ -792,6 +774,24 @@ const copySource = (source, usedIds) => {
792
774
  });
793
775
  return applyEdits(source, edits);
794
776
  };
777
+ const insertChildren = (source, parent, last, copies) => {
778
+ const closing = parent.closingElement.start;
779
+ if (last?.start != null && last.end != null) {
780
+ const lineStart = source.lastIndexOf("\n", last.start - 1) + 1;
781
+ const indent = source.slice(lineStart, last.start);
782
+ const after = /^[ \t]*(\r?\n)/.exec(source.slice(last.end, closing));
783
+ if (after && /^[ \t]*$/.test(indent)) return {
784
+ start: last.end,
785
+ end: last.end,
786
+ content: copies.map((copy) => `${after[1]}${indent}${copy}`).join("")
787
+ };
788
+ }
789
+ return {
790
+ start: closing,
791
+ end: closing,
792
+ content: copies.join("")
793
+ };
794
+ };
795
795
  const editChildrenSource = (source, parent, input, options) => {
796
796
  try {
797
797
  if (!parent.closingElement || parent.start == null || parent.end == null) return null;
@@ -807,14 +807,7 @@ const editChildrenSource = (source, parent, input, options) => {
807
807
  end: child.end,
808
808
  content: next[index] ?? ""
809
809
  }));
810
- if (next.length > children.length) {
811
- const at = parent.closingElement.start;
812
- edits.push({
813
- start: at,
814
- end: at,
815
- content: next.slice(children.length).join("")
816
- });
817
- }
810
+ if (next.length > children.length) edits.push(insertChildren(source, parent, children.at(-1), next.slice(children.length)));
818
811
  return edits;
819
812
  };
820
813
  if (Array.isArray(value)) {
@@ -868,22 +861,12 @@ const editChildrenSource = (source, parent, input, options) => {
868
861
  }));
869
862
  case "duplicate": {
870
863
  if (!indicesAreValid(action.indices, raw.length)) return null;
871
- const content = [...action.indices].sort((a, b) => a - b).map((index) => copySource(raw[index], usedIds)).join("");
872
- const at = parent.closingElement.start;
873
- return [{
874
- start: at,
875
- end: at,
876
- content
877
- }];
864
+ const copies = [...action.indices].sort((a, b) => a - b).map((index) => copySource(raw[index], usedIds));
865
+ return [insertChildren(source, parent, children.at(-1), copies)];
878
866
  }
879
867
  case "append": {
880
- const content = copySource(raw[0] ?? "<div></div>", usedIds);
881
- const at = parent.closingElement.start;
882
- return [{
883
- start: at,
884
- end: at,
885
- content
886
- }];
868
+ const copy = copySource(raw[0] ?? "<div></div>", usedIds);
869
+ return [insertChildren(source, parent, children.at(-1), [copy])];
887
870
  }
888
871
  default: return null;
889
872
  }
@@ -922,10 +905,6 @@ const valueToExpression = (value) => {
922
905
  }
923
906
  return null;
924
907
  };
925
- const arrayExpressionToCode = (elements) => {
926
- const nextAst = arrayExpression(elements);
927
- return generateCode(nextAst);
928
- };
929
908
  //#endregion
930
909
  //#region src/utils/ast/edit-source.ts
931
910
  const childrenRange = (element) => {
@@ -942,19 +921,23 @@ const findAttribute = (opening, propertyName) => {
942
921
  const attributeInsertPoint = (opening) => {
943
922
  return opening.attributes[opening.attributes.length - 1]?.end ?? opening.name.end ?? null;
944
923
  };
924
+ const escapeJsxText = (value) => value.replace(/&(?=#?[A-Za-z0-9]+;)/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\{/g, "&#123;").replace(/\}/g, "&#125;");
945
925
  const editInnerText = (source, element, value) => {
946
926
  const range = childrenRange(element);
947
927
  if (!range) return [];
928
+ const text = escapeJsxText(value);
948
929
  const [only] = element.children;
949
930
  if (element.children.length === 1 && isJSXText(only) && only.start != null && only.end != null) {
950
931
  const raw = source.slice(only.start, only.end);
951
932
  if (raw.trim() !== "") {
952
- const leading = raw.length - raw.trimStart().length;
953
- const trailing = raw.length - raw.trimEnd().length;
933
+ const leadingSpace = raw.slice(0, raw.length - raw.trimStart().length);
934
+ const trailingSpace = raw.slice(raw.trimEnd().length);
935
+ const leading = /[\r\n]/.test(leadingSpace) ? leadingSpace.length : 0;
936
+ const trailing = /[\r\n]/.test(trailingSpace) ? trailingSpace.length : 0;
954
937
  return [{
955
938
  start: only.start + leading,
956
939
  end: only.end - trailing,
957
- content: value
940
+ content: text
958
941
  }];
959
942
  }
960
943
  }
@@ -967,7 +950,7 @@ const editInnerText = (source, element, value) => {
967
950
  edits.push({
968
951
  start: range.end,
969
952
  end: range.end,
970
- content: value
953
+ content: text
971
954
  });
972
955
  return edits;
973
956
  };
@@ -1037,12 +1020,25 @@ const structuralSource = (value) => {
1037
1020
  return null;
1038
1021
  }
1039
1022
  };
1023
+ const hasControlCharacter = (value) => Array.from(value).some((char) => char.charCodeAt(0) < 32);
1024
+ const jsxStringValue = (value) => {
1025
+ if (hasControlCharacter(value)) return jsxExpressionContainer(stringLiteral(value));
1026
+ const quote = value.includes("\"") && !value.includes("'") ? "'" : "\"";
1027
+ const text = value.replace(/&(?=#?[A-Za-z0-9]+;)/g, "&amp;");
1028
+ const escaped = quote === "\"" ? text.replace(/"/g, "&quot;") : text;
1029
+ const literal = stringLiteral(value);
1030
+ literal.extra = {
1031
+ raw: `${quote}${escaped}${quote}`,
1032
+ rawValue: value
1033
+ };
1034
+ return literal;
1035
+ };
1040
1036
  const buildAttributeValue = (value, type, current) => {
1041
1037
  if (type === "array" || type === "object") {
1042
1038
  if (typeof value === "string") try {
1043
1039
  return jsxExpressionContainer(parseExpression(value.trim(), { plugins: ["jsx", "typescript"] }));
1044
1040
  } catch {
1045
- return stringLiteral(value);
1041
+ return jsxStringValue(value);
1046
1042
  }
1047
1043
  const expr = valueToExpression(value);
1048
1044
  return expr ? jsxExpressionContainer(expr) : stringLiteral("");
@@ -1052,10 +1048,10 @@ const buildAttributeValue = (value, type, current) => {
1052
1048
  const structural = structuralSource(value);
1053
1049
  if (structural) return jsxExpressionContainer(structural);
1054
1050
  }
1055
- return stringLiteral(value);
1051
+ return jsxStringValue(value);
1056
1052
  }
1057
1053
  const expr = valueToExpression(value);
1058
- return expr ? jsxExpressionContainer(expr) : stringLiteral(String(value));
1054
+ return expr ? jsxExpressionContainer(expr) : jsxStringValue(String(value));
1059
1055
  };
1060
1056
  const editAttribute = (opening, propertyName, value, type) => {
1061
1057
  const attribute = findAttribute(opening, propertyName);
@@ -1080,8 +1076,16 @@ const editAttribute = (opening, propertyName, value, type) => {
1080
1076
  indent: true
1081
1077
  }];
1082
1078
  };
1079
+ const TRAILING_COMMENTS = /^[ \t]*(?:\/\*[^\r\n]*?\*\/[ \t]*)*(?:\/\/[^\r\n]*)?\r?\n/;
1083
1080
  const removeAttribute = (source, attribute) => {
1084
1081
  if (attribute.start == null || attribute.end == null) return null;
1082
+ const lineStart = source.lastIndexOf("\n", attribute.start - 1) + 1;
1083
+ const rest = TRAILING_COMMENTS.exec(source.slice(attribute.end));
1084
+ if (/^[ \t]*$/.test(source.slice(lineStart, attribute.start)) && rest) return [{
1085
+ start: lineStart,
1086
+ end: attribute.end + rest[0].length,
1087
+ content: ""
1088
+ }];
1085
1089
  let start = attribute.start;
1086
1090
  while (start > 0 && /\s/.test(source[start - 1])) start -= 1;
1087
1091
  return [{
@@ -1302,260 +1306,7 @@ const updateAll = (raw, entries, options = {}) => {
1302
1306
  code: current
1303
1307
  };
1304
1308
  };
1305
- /**
1306
- * @deprecated Not atomic: when an entry fails, the ones before and after it
1307
- * are still applied, and the returned `code` carries them. Use `updateAll`,
1308
- * which applies every entry or none. Will be removed in the next major.
1309
- */
1310
- const bulkUpdate = (raw, entries) => {
1311
- let current = raw;
1312
- const failures = [];
1313
- for (const entry of entries) {
1314
- const result = update(current, entry.dataId, entry.label, entry.value, entry.property);
1315
- current = result.code;
1316
- if (!result.success && result.failure) failures.push(result.failure);
1317
- }
1318
- return failures.length > 0 ? {
1319
- code: current,
1320
- success: false,
1321
- failures
1322
- } : {
1323
- code: current,
1324
- success: true
1325
- };
1326
- };
1327
- //#endregion
1328
- //#region src/utils/ast/array-source.ts
1329
- const commaIn = (source, start, end) => {
1330
- let comma = null;
1331
- for (let at = start; at < end; at++) {
1332
- if (/\s/.test(source[at])) continue;
1333
- if (source.startsWith("/*", at)) {
1334
- const close = source.indexOf("*/", at + 2);
1335
- if (close < 0 || close + 2 > end) return null;
1336
- at = close + 1;
1337
- } else if (source.startsWith("//", at)) {
1338
- const newline = source.indexOf("\n", at + 2);
1339
- at = newline < 0 ? end : newline;
1340
- } else if (source[at] === "," && comma === null) comma = at;
1341
- else return null;
1342
- }
1343
- return comma;
1344
- };
1345
- const denseArraySource = (source) => {
1346
- const array = parseArrayExpression(source);
1347
- if (!array || array.elements.some((node) => !isExpression(node) || node.extra?.parenthesized)) return null;
1348
- const elements = array.elements;
1349
- const commas = elements.slice(0, -1).map((node, index) => commaIn(source, node.end, elements[index + 1].start));
1350
- if (commas.some((comma) => comma === null)) return null;
1351
- const last = elements.at(-1);
1352
- return {
1353
- array,
1354
- elements,
1355
- commas,
1356
- trailing: last ? commaIn(source, last.end, array.end - 1) : null
1357
- };
1358
- };
1359
- const canStructurallyEditArray = (source) => denseArraySource(source) !== null;
1360
- const validArrayIndices = (indices, length) => [...indices].every((index) => Number.isInteger(index) && index >= 0 && index < length);
1361
- const reorderArraySource = (source, elements, next) => applyEdits(source, elements.map((node, index) => ({
1362
- start: node.start,
1363
- end: node.end,
1364
- content: source.slice(next[index].start, next[index].end)
1365
- })));
1366
- const removeArraySource = (source, data, indices) => {
1367
- const edits = [];
1368
- const removedCommas = /* @__PURE__ */ new Set();
1369
- const { elements, commas, trailing } = data;
1370
- for (let index = 0; index < elements.length; index++) {
1371
- if (!indices.has(index)) continue;
1372
- const start = index;
1373
- while (index + 1 < elements.length && indices.has(index + 1)) index++;
1374
- for (let current = start; current <= index; current++) {
1375
- const node = elements[current];
1376
- edits.push({
1377
- start: node.start,
1378
- end: node.end,
1379
- content: ""
1380
- });
1381
- if (current < elements.length - 1) removedCommas.add(commas[current]);
1382
- }
1383
- if (index === elements.length - 1) {
1384
- if (trailing !== null) removedCommas.add(trailing);
1385
- else if (start > 0) removedCommas.add(commas[start - 1]);
1386
- }
1387
- }
1388
- for (const comma of removedCommas) edits.push({
1389
- start: comma,
1390
- end: comma + 1,
1391
- content: ""
1392
- });
1393
- return applyEdits(source, edits);
1394
- };
1395
- const appendArraySource = (source, data, copies) => {
1396
- const last = data.elements.at(-1);
1397
- if (!last || copies.length === 0) return source;
1398
- return applyEdits(source, [{
1399
- start: last.end,
1400
- end: last.end,
1401
- content: `, ${copies.join(", ")}`
1402
- }]);
1403
- };
1404
- //#endregion
1405
- //#region src/utils/ast/items.ts
1406
- const elementsOf = (code) => parseArrayExpression(code)?.elements ?? null;
1407
- const kindOf = (element) => isObjectExpression(element) ? "object" : "primitive";
1408
- const parseItems = (code) => {
1409
- return elementsOf(code)?.flatMap((node, index) => isExpression(node) ? [{
1410
- index,
1411
- kind: kindOf(node),
1412
- node
1413
- }] : []) ?? null;
1414
- };
1415
- const resolveRenderLeaf = (render, key) => {
1416
- const leaf = render?.[key];
1417
- return leaf && "type" in leaf ? leaf : null;
1418
- };
1419
- const toTemplateRaw = (value) => {
1420
- return value.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${").replace(/\r/g, "\\r");
1421
- };
1422
- const buildPropertyValue = (value, declaredType, renderLeaf, current) => {
1423
- if (renderLeaf?.property === BINDING_PROP.INNER_HTML) {
1424
- const raw = String(value);
1425
- return templateLiteral([templateElement({
1426
- raw: toTemplateRaw(raw),
1427
- cooked: raw
1428
- }, true)], []);
1429
- }
1430
- if (renderLeaf?.type === "jsx" || isJSXElement(current) || isJSXFragment(current)) {
1431
- const trimmed = String(value).trim();
1432
- if (!trimmed.startsWith("<")) return stringLiteral(trimmed);
1433
- try {
1434
- return parseExpression(trimmed, { plugins: ["jsx", "typescript"] });
1435
- } catch {
1436
- return;
1437
- }
1438
- }
1439
- if (declaredType === "array" || declaredType === "object") {
1440
- if (typeof value === "string") try {
1441
- return parseExpression(value, { plugins: ["jsx", "typescript"] });
1442
- } catch {
1443
- return;
1444
- }
1445
- if (!isLosslesslyEvaluable(current)) return;
1446
- return valueToExpression(value) ?? void 0;
1447
- }
1448
- return createNodeFromValue(declaredType, parseValue(value)) ?? void 0;
1449
- };
1450
- const updateArrayItemProperty = (code, index, key, value, render) => {
1451
- const elements = elementsOf(code);
1452
- const element = elements?.[index];
1453
- if (!elements || !isObjectExpression(element)) return null;
1454
- const target = element.properties.find((property) => isObjectProperty(property) && isIdentifier(property.key) && property.key.name === key);
1455
- if (!target) return null;
1456
- const declaredType = extractObjectProperties(element)[key]?.type ?? "string";
1457
- const nextValue = buildPropertyValue(value, declaredType, resolveRenderLeaf(render, key), target.value);
1458
- if (!nextValue) return null;
1459
- let serialized = typeof value === "string" && (declaredType === "array" || declaredType === "object" || isJSXElement(nextValue) || isJSXFragment(nextValue)) ? value.trim() : generateCode(nextValue);
1460
- if (nextValue.trailingComments?.some((comment) => comment.type === "CommentLine")) serialized += "\n";
1461
- const content = target.shorthand ? `${key}: ${serialized}` : serialized;
1462
- return applyEdits(code, [{
1463
- start: target.value.start,
1464
- end: target.value.end,
1465
- content
1466
- }]);
1467
- };
1468
- const updateArrayItemValue = (code, index, value) => {
1469
- const elements = elementsOf(code);
1470
- const element = elements?.[index];
1471
- if (!elements || !isExpression(element)) return null;
1472
- const nextValue = createNodeFromValue(extractNodeValue(element).type, parseValue(value));
1473
- if (!nextValue) return null;
1474
- return applyEdits(code, [{
1475
- start: element.start,
1476
- end: element.end,
1477
- content: generateCode(nextValue)
1478
- }]);
1479
- };
1480
- const moveArrayItem = (code, from, to) => {
1481
- const data = denseArraySource(code);
1482
- if (!data || !validArrayIndices([from], data.elements.length) || !Number.isInteger(to)) return null;
1483
- const next = [...data.elements];
1484
- const [moved] = next.splice(from, 1);
1485
- next.splice(to, 0, moved);
1486
- return reorderArraySource(code, data.elements, next);
1487
- };
1488
- const moveArrayItems = (code, indices, direction) => {
1489
- const data = denseArraySource(code);
1490
- if (!data || !validArrayIndices(indices, data.elements.length) || !["up", "down"].includes(direction)) return null;
1491
- const next = moveSelectedIndices(data.elements, indices, direction);
1492
- return {
1493
- code: reorderArraySource(code, data.elements, next.items),
1494
- indices: next.indices
1495
- };
1496
- };
1497
- const removeArrayItems = (code, indices, kind) => {
1498
- const data = denseArraySource(code);
1499
- if (!data || !validArrayIndices(indices, data.elements.length)) return null;
1500
- const remaining = removeIndices(data.elements, indices);
1501
- if (!(kind === void 0 ? remaining : remaining.filter((node) => kindOf(node) === kind)).length) return null;
1502
- return removeArraySource(code, data, indices);
1503
- };
1504
- const copyItem = (code, element, generateId, usedIds) => {
1505
- const edits = [];
1506
- let unsupported = false;
1507
- const reserveId = (id) => {
1508
- if (usedIds.has(id)) unsupported = true;
1509
- usedIds.add(id);
1510
- return JSON.stringify(id);
1511
- };
1512
- traverseFast(element, (node) => {
1513
- if (!isJSXOpeningElement(node)) return;
1514
- const ids = node.attributes.filter((attr) => isJSXAttribute(attr) && isJSXIdentifier(attr.name, { name: "data-id" }));
1515
- const attr = ids[0];
1516
- if (ids.length > 1 || attr && (!isStringLiteral(attr.value) || node.attributes.slice(node.attributes.indexOf(attr) + 1).some((a) => isJSXSpreadAttribute(a)))) {
1517
- unsupported = true;
1518
- return;
1519
- }
1520
- if (attr && isStringLiteral(attr.value)) edits.push({
1521
- start: attr.value.start,
1522
- end: attr.value.end,
1523
- content: reserveId(generateId())
1524
- });
1525
- });
1526
- if (isObjectExpression(element)) {
1527
- const keys = element.properties.filter((prop) => isObjectProperty(prop) && !prop.computed && (isIdentifier(prop.key, { name: "key" }) || isStringLiteral(prop.key, { value: "key" })));
1528
- const key = keys[0];
1529
- if (keys.length > 1 || key && (!isStringLiteral(key.value) || element.properties.slice(element.properties.indexOf(key) + 1).some((prop) => isSpreadElement(prop) || "computed" in prop && prop.computed))) return null;
1530
- if (key && isStringLiteral(key.value)) edits.push({
1531
- start: key.value.start,
1532
- end: key.value.end,
1533
- content: reserveId(`${key.value.value}-${generateId()}`)
1534
- });
1535
- }
1536
- if (unsupported) return null;
1537
- return applyEdits(code.slice(element.start, element.end), edits.map((edit) => ({
1538
- ...edit,
1539
- start: edit.start - element.start,
1540
- end: edit.end - element.start
1541
- })));
1542
- };
1543
- const duplicateArrayItems = (code, indices, generateId = () => nanoid(6)) => {
1544
- const data = denseArraySource(code);
1545
- if (!data || !indices.size || !validArrayIndices(indices, data.elements.length)) return null;
1546
- const usedIds = /* @__PURE__ */ new Set();
1547
- traverseFast(data.array, (node) => {
1548
- if (isJSXAttribute(node) && isJSXIdentifier(node.name, { name: "data-id" }) && isStringLiteral(node.value)) usedIds.add(node.value.value);
1549
- else if (isObjectProperty(node) && !node.computed && (isIdentifier(node.key, { name: "key" }) || isStringLiteral(node.key, { value: "key" })) && isStringLiteral(node.value)) usedIds.add(node.value.value);
1550
- });
1551
- const copies = [...indices].sort((a, b) => a - b).map((index) => copyItem(code, data.elements[index], generateId, usedIds));
1552
- return copies.every((copy) => copy !== null) ? appendArraySource(code, data, copies) : null;
1553
- };
1554
- const appendArrayItem = (code, kind, generateId = () => nanoid(6)) => {
1555
- const index = denseArraySource(code)?.elements.findIndex((node) => kindOf(node) === kind) ?? -1;
1556
- return index < 0 ? null : duplicateArrayItems(code, /* @__PURE__ */ new Set([index]), generateId);
1557
- };
1558
1309
  //#endregion
1559
- export { extractNodeValue as A, getStructuredValue as C, readNodeBindings as D, parseBindingExpression as E, parseArrayExpression as M, parseValue as N, resolveBindings as O, unwrapExpression as P, getRegistryBindings as S, parseBinding as T, clearExtractCache as _, parseItems as a, getCurrentValue as b, updateArrayItemValue as c, update as d, updateAll as f, moveSelectedIndices as g, getChildrenSignatures as h, moveArrayItems as i, extractObjectProperties as j, canLosslesslyEvaluateSource as k, canStructurallyEditArray as l, createNodeFromValue as m, duplicateArrayItems as n, removeArrayItems as o, arrayExpressionToCode as p, moveArrayItem as r, updateArrayItemProperty as s, appendArrayItem as t, bulkUpdate as u, extract as v, isComponentTagName as w, getKeyBindings as x, findEditableChildren as y };
1310
+ export { parseArrayExpression as _, getChildrenSignatures as a, generateCode as b, removeIndices as c, getStructuredValue as d, readNodeBindings as f, isLosslesslyEvaluable as g, extractObjectProperties as h, valueToExpression as i, findEditableChildren as l, extractNodeValue as m, updateAll as n, extract as o, canLosslesslyEvaluateSource as p, createNodeFromValue as r, moveSelectedIndices as s, update as t, getCurrentValue as u, parseValue as v, unwrapExpression as y };
1560
1311
 
1561
- //# sourceMappingURL=items-BXXtMUNI.js.map
1312
+ //# sourceMappingURL=update-BuYQJqjq.js.map