@ecomcx/ecomweb-editor 1.31.0 → 1.33.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/package.json +3 -3
  2. package/src/locales/en/attrs.ts +10 -0
  3. package/src/locales/en/background.ts +17 -0
  4. package/src/locales/en/bindings.ts +1 -1
  5. package/src/locales/en/block-desc.ts +2 -0
  6. package/src/locales/en/block-style.ts +7 -4
  7. package/src/locales/en/block-titles.ts +2 -0
  8. package/src/locales/en/blocks.ts +12 -3
  9. package/src/locales/en/columns.ts +12 -0
  10. package/src/locales/en/controls.ts +21 -0
  11. package/src/locales/en/hints.ts +289 -1
  12. package/src/locales/en/index.ts +5 -2
  13. package/src/locales/en/layout.ts +32 -0
  14. package/src/locales/en/legacy.ts +1 -1
  15. package/src/locales/en/library.ts +38 -0
  16. package/src/locales/en/parts.ts +12 -0
  17. package/src/locales/en/placeholders.ts +12 -1
  18. package/src/locales/en/presets.ts +6 -0
  19. package/src/locales/en/v2.ts +21 -0
  20. package/src/locales/vi/attrs.ts +10 -0
  21. package/src/locales/vi/background.ts +17 -0
  22. package/src/locales/vi/bindings.ts +1 -1
  23. package/src/locales/vi/block-desc.ts +2 -0
  24. package/src/locales/vi/block-style.ts +7 -4
  25. package/src/locales/vi/block-titles.ts +2 -0
  26. package/src/locales/vi/blocks.ts +12 -3
  27. package/src/locales/vi/columns.ts +12 -0
  28. package/src/locales/vi/controls.ts +21 -0
  29. package/src/locales/vi/hints.ts +290 -2
  30. package/src/locales/vi/index.ts +5 -2
  31. package/src/locales/vi/layout.ts +32 -0
  32. package/src/locales/vi/legacy.ts +1 -1
  33. package/src/locales/vi/library.ts +38 -0
  34. package/src/locales/vi/parts.ts +12 -0
  35. package/src/locales/vi/placeholders.ts +12 -1
  36. package/src/locales/vi/presets.ts +6 -0
  37. package/src/locales/vi/v2.ts +21 -0
  38. package/src/shared/panel-store.ts +3 -3
  39. package/src/shared/patterns.ts +3 -52
  40. package/src/shared/style-panel.tsx +2 -2
  41. package/src/shared/types.ts +2 -0
  42. package/src/v2/blocks/columns-inspector.tsx +210 -0
  43. package/src/v2/blocks/form.tsx +4 -4
  44. package/src/v2/blocks/index.ts +10 -4
  45. package/src/v2/blocks/inline-style.ts +1 -1
  46. package/src/v2/blocks/layout.tsx +211 -44
  47. package/src/v2/blocks/media.tsx +22 -13
  48. package/src/v2/blocks/resize.tsx +172 -4
  49. package/src/v2/blocks/text.tsx +14 -7
  50. package/src/v2/blocks/theme.tsx +63 -19
  51. package/src/v2/blocks/tools.tsx +50 -5
  52. package/src/v2/blocks/widgets.tsx +44 -16
  53. package/src/v2/canvas/block-list.tsx +23 -3
  54. package/src/v2/canvas/canvas-css.ts +70 -4
  55. package/src/v2/canvas/canvas.tsx +22 -5
  56. package/src/v2/canvas/dnd.ts +34 -3
  57. package/src/v2/canvas/move-animation.ts +94 -0
  58. package/src/v2/canvas/spacing-viz.ts +51 -0
  59. package/src/v2/core/block-presets.ts +68 -0
  60. package/src/v2/core/host.ts +6 -1
  61. package/src/v2/core/structure.ts +2 -1
  62. package/src/v2/editor.css +238 -9
  63. package/src/v2/editor.tsx +8 -2
  64. package/src/v2/ui/attr-form.tsx +59 -12
  65. package/src/v2/ui/attr-hints.ts +140 -9
  66. package/src/v2/ui/background-panel.tsx +65 -21
  67. package/src/v2/ui/bindings.tsx +3 -0
  68. package/src/v2/ui/block-icons.tsx +152 -0
  69. package/src/v2/ui/block-menu.ts +22 -0
  70. package/src/v2/ui/block-style-panel.tsx +14 -3
  71. package/src/v2/ui/color-field.tsx +74 -9
  72. package/src/v2/ui/divider-panel.tsx +58 -0
  73. package/src/v2/ui/group-width.tsx +38 -0
  74. package/src/v2/ui/icon-picker.tsx +51 -0
  75. package/src/v2/ui/inserter.tsx +61 -12
  76. package/src/v2/ui/inspector.tsx +48 -16
  77. package/src/v2/ui/layout-panel.tsx +5 -47
  78. package/src/v2/ui/list-view.tsx +81 -7
  79. package/src/v2/ui/motion-panel.tsx +2 -1
  80. package/src/v2/ui/parts-panel.tsx +164 -0
  81. package/src/v2/ui/pattern-library.tsx +228 -0
  82. package/src/v2/ui/preset-bar.tsx +83 -0
  83. package/src/v2/ui/style-controls.tsx +65 -15
  84. package/src/v2/ui/style-supports.ts +1 -1
  85. package/src/v2/ui/style-tab.tsx +127 -41
  86. package/src/v2/ui/toolbar.tsx +52 -13
  87. package/src/v2/ui/unit-controls.tsx +88 -39
  88. package/src/locales/en/patterns.ts +0 -50
  89. package/src/locales/vi/patterns.ts +0 -50
  90. package/src/shared/patterns-kit.ts +0 -7
  91. package/src/shared/patterns-library.ts +0 -172
@@ -0,0 +1,152 @@
1
+ import type { ComponentType } from "react";
2
+
3
+ /**
4
+ * Bộ icon 2 lớp của khối lõi (tự vẽ, lưới 24px): lớp nền nhạt (0) + lớp đặc màu thương hiệu (1) + chi tiết trắng (2).
5
+ * Màu lấy từ biến CSS `--ecx-ico-a` / `--ecx-ico-b` (editor.css) → cùng một bộ hợp sáng / tối, đang chọn / không.
6
+ */
7
+ type Shape = ["r", number, number, number, number, number?, Layer?] | ["c", number, number, number, Layer?] | ["p", string, Layer?] | ["s", string, Layer?];
8
+ type Layer = 0 | 1 | 2;
9
+ const FILL = ["var(--ecx-ico-b)", "var(--ecx-ico-a)", "var(--ecx-ico-w, #fff)"];
10
+
11
+ function draw(shapes: Shape[]): ComponentType<{ className?: string }> {
12
+ const Icon = ({ className }: { className?: string }) => (
13
+ <svg className={className ? `${className} ecx-duo` : "ecx-duo"} viewBox="0 0 24 24" width={24} height={24} aria-hidden="true" focusable="false">
14
+ {shapes.map((s, i) => {
15
+ if (s[0] === "r") return <rect key={i} x={s[1]} y={s[2]} width={s[3]} height={s[4]} rx={s[5] ?? 0} fill={FILL[s[6] ?? 1]} />;
16
+ if (s[0] === "c") return <circle key={i} cx={s[1]} cy={s[2]} r={s[3]} fill={FILL[s[4] ?? 1]} />;
17
+ if (s[0] === "s") return <path key={i} d={s[1]} fill="none" stroke={FILL[s[2] ?? 1]} strokeWidth={1.8} strokeLinecap="round" strokeLinejoin="round" />;
18
+ return <path key={i} d={s[1]} fill={FILL[s[2] ?? 1]} />;
19
+ })}
20
+ </svg>
21
+ );
22
+ return Icon;
23
+ }
24
+
25
+ // Mảnh dùng lại
26
+ const lines = (x: number, y: number, w: number[], gap = 4, h = 2): Shape[] => w.map((wi, i) => ["r", x, y + i * gap, wi, h, h / 2, 1] as Shape);
27
+ const frame = (layer: Layer = 0): Shape => ["r", 2, 3, 20, 18, 3, layer];
28
+ const photo: Shape[] = [["r", 2, 4, 20, 16, 3, 0], ["c", 8, 9, 2], ["p", "M3 18l6-6 3.5 3.5L16 11l5 6v1.5A1.5 1.5 0 0 1 19.5 20h-15A1.5 1.5 0 0 1 3 18.5z"]];
29
+ const H = "M7 6h2.6v4.7h4.8V6H17v12h-2.6v-5h-4.8v5H7z";
30
+ const quote = "M6 8h4v4c0 2.3-1.3 3.7-3.5 4l-.5-1.6c1-.4 1.5-1.1 1.5-2.4H6zm8 0h4v4c0 2.3-1.3 3.7-3.5 4l-.5-1.6c1-.4 1.5-1.1 1.5-2.4H14z";
31
+ const star = "M12 3.5l2.6 5.3 5.8.8-4.2 4.1 1 5.8L12 16.8l-5.2 2.7 1-5.8-4.2-4.1 5.8-.8z";
32
+ const pin = "M12 2a6.5 6.5 0 0 1 6.5 6.5c0 4.6-6.5 12.5-6.5 12.5S5.5 13.1 5.5 8.5A6.5 6.5 0 0 1 12 2z";
33
+ const play = "M10 8.5l6 3.5-6 3.5z";
34
+
35
+ const I = {
36
+ // Chữ
37
+ paragraph: draw([["r", 2, 2, 20, 20, 4, 0], ["p", "M10 5h7v2h-2v12h-2V7h-1v12H10v-6.2A3.9 3.9 0 0 1 10 5z"]]),
38
+ heading: draw([["r", 2, 2, 20, 20, 4, 0], ["p", H]]),
39
+ bulletList: draw([["c", 5, 6, 2], ["c", 5, 12, 2], ["c", 5, 18, 2], ["r", 9, 5, 13, 2.2, 1.1, 0], ["r", 9, 11, 13, 2.2, 1.1, 0], ["r", 9, 17, 10, 2.2, 1.1, 0]]),
40
+ orderedList: draw([["p", "M4 4h2v5H4.5V5.5H4zM3.5 13.5c0-1 .8-1.6 1.7-1.6s1.6.6 1.6 1.4c0 .9-.7 1.4-1.6 2.2h1.7V17H3.5v-1c1.6-1.3 2-1.8 2-2.3 0-.3-.2-.5-.4-.5s-.4.2-.4.5z"], ["r", 9, 5, 13, 2.2, 1.1, 0], ["r", 9, 11, 13, 2.2, 1.1, 0], ["r", 9, 17, 10, 2.2, 1.1, 0]]),
41
+ taskList: draw([["r", 2, 3, 6, 6, 1.5], ["s", "M3.6 6l1.3 1.3L6.6 5", 2], ["r", 2, 14, 6, 6, 1.5, 0], ["r", 10, 5, 12, 2.2, 1.1, 0], ["r", 10, 16, 9, 2.2, 1.1, 0]]),
42
+ blockquote: draw([["r", 2, 3, 20, 18, 3, 0], ["p", quote]]),
43
+ pullquote: draw([["r", 2, 3, 20, 2, 1], ["r", 2, 19, 20, 2, 1], ["r", 2, 6.5, 20, 11, 2, 0], ["p", "M7 9h3v3c0 1.7-1 2.8-2.6 3l-.4-1.2c.8-.3 1.1-.8 1.1-1.8H7zm7 0h3v3c0 1.7-1 2.8-2.6 3l-.4-1.2c.8-.3 1.1-.8 1.1-1.8H14z"]]),
44
+ codeBlock: draw([frame(), ["p", "M9.5 8.5L6 12l3.5 3.5 1.2-1.2L8.4 12l2.3-2.3zm5 0l-1.2 1.2 2.3 2.3-2.3 2.3 1.2 1.2L18 12z"]]),
45
+ preformatted: draw([frame(), ...lines(5, 7, [12, 8, 10])]),
46
+ customHtml: draw([frame(), ["p", "M8 8.5L4.5 12 8 15.5l1.2-1.2L6.9 12l2.3-2.3zm8 0l-1.2 1.2 2.3 2.3-2.3 2.3 1.2 1.2L19.5 12zM13.2 7l-3.6 10h1.7L14.9 7z"]]),
47
+ callout: draw([["r", 2, 3, 20, 18, 3, 0], ["r", 2, 3, 3, 18, 1.5], ["c", 12, 8, 1.5], ["r", 10.7, 11, 2.6, 7, 1.3]]),
48
+ details: draw([["r", 2, 3, 20, 6, 2], ["s", "M17 5l1.5 1.5L20 5", 2], ["r", 2, 11, 20, 10, 2, 0], ...lines(5, 14, [12, 8])]),
49
+ accordion: draw([["r", 2, 2, 20, 6, 2], ["s", "M16.5 4.3l1.5 1.5 1.5-1.5", 2], ["r", 2, 9.5, 20, 5.5, 2, 0], ["r", 2, 16.5, 20, 5.5, 2, 0]]),
50
+ tabs: draw([["r", 2, 8, 20, 13, 2.5, 0], ["p", "M2 6.5A2.5 2.5 0 0 1 4.5 4H10l1.5 4H2z"], ["r", 12, 4, 6, 3.5, 1.2, 0], ...lines(5, 12, [10, 7])]),
51
+ tab: draw([["p", "M2 6.5A2.5 2.5 0 0 1 4.5 4H10l1.5 4H2z"], ["r", 2, 8, 20, 13, 2.5, 0], ...lines(5, 12, [10, 7])]),
52
+ footnotes: draw([["r", 2, 3, 20, 18, 3, 0], ...lines(5, 7, [14, 10]), ["r", 5, 14, 2, 2, 1], ["r", 9, 14, 10, 2, 1]]),
53
+ // Media
54
+ image: draw(photo),
55
+ gallery: draw([["r", 2, 2, 9, 12, 2, 0], ["r", 13, 2, 9, 7, 2], ["r", 2, 16, 9, 6, 2], ["r", 13, 11, 9, 11, 2, 0]]),
56
+ cover: draw([["r", 2, 3, 20, 18, 3], ["r", 6, 10, 12, 2.2, 1.1, 2], ["r", 8, 14, 8, 1.8, .9, 2]]),
57
+ mediaText: draw([["r", 2, 4, 9, 16, 2], ["c", 5.5, 8.5, 1.4, 2], ...lines(13, 7, [9, 7, 8]), ["r", 13, 15, 6, 3, 1.5, 0]]),
58
+ video: draw([["r", 2, 4, 20, 16, 3, 0], ["c", 12, 12, 5], ["p", play, 2]]),
59
+ youtube: draw([["r", 2, 5, 20, 14, 4], ["p", play, 2]]),
60
+ audio: draw([["r", 2, 2, 20, 20, 4, 0], ["p", "M15 5v8.2A2.8 2.8 0 1 1 13 10.6V7l-4 1v7.2A2.8 2.8 0 1 1 7 12.6V6.5z"]]),
61
+ file: draw([["p", "M6 2h8l5 5v13a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z", 0], ["p", "M14 2l5 5h-3a2 2 0 0 1-2-2z"], ...lines(7, 12, [10, 7])]),
62
+ embed: draw([["r", 2, 3, 20, 18, 3, 0], ["p", "M10.6 13.4a3 3 0 0 0 4.2 0l2.5-2.5a3 3 0 1 0-4.2-4.2l-.8.8 1.2 1.2.8-.8a1.3 1.3 0 0 1 1.8 1.8l-2.5 2.5a1.3 1.3 0 0 1-1.8 0zM13.4 10.6a3 3 0 0 0-4.2 0l-2.5 2.5a3 3 0 1 0 4.2 4.2l.8-.8-1.2-1.2-.8.8a1.3 1.3 0 0 1-1.8-1.8l2.5-2.5a1.3 1.3 0 0 1 1.8 0z"]]),
63
+ // Bố cục
64
+ group: draw([["r", 2, 3, 20, 18, 3, 0], ["r", 5, 6, 14, 12, 2]]),
65
+ row: draw([["r", 2, 5, 20, 14, 3, 0], ["r", 4, 8, 4.5, 8, 1.2], ["r", 9.75, 8, 4.5, 8, 1.2], ["r", 15.5, 8, 4.5, 8, 1.2]]),
66
+ stack: draw([["r", 4, 2, 16, 20, 3, 0], ["r", 6.5, 5, 11, 4, 1.2], ["r", 6.5, 10, 11, 4, 1.2], ["r", 6.5, 15, 11, 4, 1.2]]),
67
+ grid: draw([["r", 2, 2, 20, 20, 3, 0], ["r", 4.5, 4.5, 6.5, 6.5, 1.5], ["r", 13, 4.5, 6.5, 6.5, 1.5], ["r", 4.5, 13, 6.5, 6.5, 1.5], ["r", 13, 13, 6.5, 6.5, 1.5]]),
68
+ columns: draw([["r", 2, 4, 20, 16, 3, 0], ["r", 4, 6, 7, 12, 1.5], ["r", 13, 6, 7, 12, 1.5]]),
69
+ column: draw([["r", 2, 4, 20, 16, 3, 0], ["r", 8, 6, 8, 12, 1.5]]),
70
+ spacer: draw([["r", 2, 2, 20, 3, 1.5, 0], ["r", 2, 19, 20, 3, 1.5, 0], ["p", "M12 6.5l3 3h-2v5h2l-3 3-3-3h2v-5H9z"]]),
71
+ horizontalRule: draw([["r", 2, 5, 20, 3, 1.5, 0], ["r", 2, 10.75, 20, 2.5, 1.25], ["r", 2, 16, 20, 3, 1.5, 0]]),
72
+ pageBreak: draw([["r", 4, 2, 16, 7, 2, 0], ["r", 4, 15, 16, 7, 2, 0], ["r", 2, 11, 4, 2, 1], ["r", 9, 11, 6, 2, 1], ["r", 18, 11, 4, 2, 1]]),
73
+ carousel: draw([["r", 5, 4, 14, 14, 2.5], ["r", 1, 6, 3, 10, 1.5, 0], ["r", 20, 6, 3, 10, 1.5, 0], ["c", 9.5, 20.5, 1], ["c", 12, 20.5, 1, 0], ["c", 14.5, 20.5, 1, 0]]),
74
+ // Thiết kế / widget
75
+ buttons: draw([["r", 1, 7, 10, 10, 5], ["r", 13, 7, 10, 10, 5, 0]]),
76
+ button: draw([["r", 1, 6, 22, 12, 6, 0], ["r", 3, 8, 18, 8, 4], ["r", 7, 11, 10, 2, 1, 2]]),
77
+ table: draw([["r", 2, 3, 20, 18, 2.5, 0], ["r", 2, 3, 20, 5, 2.5], ["r", 8.5, 8, 1.5, 13, 0, 1], ["r", 15, 8, 1.5, 13, 0, 1], ["r", 2, 13.5, 20, 1.5, 0, 1]]),
78
+ tableRow: draw([["r", 2, 3, 20, 18, 2.5, 0], ["r", 2, 9.5, 20, 5, 1]]),
79
+ tableCell: draw([["r", 2, 3, 20, 18, 2.5, 0], ["r", 8.5, 9.5, 7, 5, 1]]),
80
+ tableHeader: draw([["r", 2, 3, 20, 18, 2.5, 0], ["r", 2, 3, 20, 5, 2.5]]),
81
+ iconBox: draw([["r", 2, 2, 20, 20, 4, 0], ["c", 12, 8.5, 3.5], ["r", 6, 14, 12, 2, 1], ["r", 8, 17.5, 8, 1.6, .8]]),
82
+ imageBox: draw([["r", 2, 2, 20, 20, 4, 0], ["r", 5, 5, 14, 8, 2], ["p", "M6 12l3.5-3.5 2 2L14 8l4 4z", 2], ["r", 6, 15, 12, 2, 1], ["r", 8, 18.5, 8, 1.4, .7]]),
83
+ iconList: draw([["c", 5, 6, 2.5], ["c", 5, 12, 2.5], ["c", 5, 18, 2.5], ["r", 9.5, 4.8, 12, 2.4, 1.2, 0], ["r", 9.5, 10.8, 12, 2.4, 1.2, 0], ["r", 9.5, 16.8, 9, 2.4, 1.2, 0]]),
84
+ icon: draw([["r", 2, 2, 20, 20, 5, 0], ["p", star]]),
85
+ counter: draw([["r", 1.5, 5, 21, 14, 3, 0], ["r", 4, 8, 4.5, 8, 1.2], ["r", 9.75, 8, 4.5, 8, 1.2], ["r", 15.5, 8, 4.5, 8, 1.2]]),
86
+ countdown: draw([["c", 12, 13, 9, 0], ["r", 9, 1.5, 6, 2.5, 1.2], ["p", "M12 6.5a6.5 6.5 0 1 1-6.5 6.5H12z"]]),
87
+ progressBar: draw([["r", 2, 6, 20, 4, 2, 0], ["r", 2, 6, 13, 4, 2], ["r", 2, 14, 20, 4, 2, 0], ["r", 2, 14, 7, 4, 2]]),
88
+ testimonial: draw([["p", "M3 4h18a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-9l-5 4v-4H3a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z", 0], ["p", quote]]),
89
+ rating: draw([["r", 2, 2, 20, 20, 5, 0], ["p", star]]),
90
+ socialLinks: draw([["c", 6, 12, 3.2], ["c", 18, 6, 3.2], ["c", 18, 18, 3.2], ["p", "M7.6 10.9l8.6-4.5.9 1.6-8.6 4.5zm0 2.2l.9-1.6 8.6 4.5-.9 1.6z", 0]]),
91
+ tableOfContents: draw([["r", 2, 2, 20, 20, 3, 0], ["r", 5, 6, 10, 2.2, 1.1], ["r", 8, 11, 10, 2.2, 1.1], ["r", 8, 16, 7, 2.2, 1.1]]),
92
+ form: draw([["r", 2, 3, 20, 5, 2, 0], ["r", 2, 10, 20, 5, 2, 0], ["r", 12, 17, 10, 5, 2.5], ["r", 4, 4.8, 6, 1.4, .7]]),
93
+ formField: draw([["r", 2, 7, 20, 10, 2.5, 0], ["r", 5, 10.5, 1.6, 3, .8]]),
94
+ shortcode: draw([["r", 2, 3, 20, 18, 3, 0], ["p", "M8 7h3v1.6H9.6v6.8H11V17H8zm8 0h-3v1.6h1.4v6.8H13V17h3z"]]),
95
+ syncedPattern: draw([["r", 2, 2, 9, 9, 2], ["r", 13, 2, 9, 9, 2, 0], ["r", 2, 13, 9, 9, 2, 0], ["r", 13, 13, 9, 9, 2]]),
96
+ templatePart: draw([["r", 2, 2, 20, 5, 2], ["r", 2, 9, 20, 6, 2, 0], ["r", 2, 17, 20, 5, 2]]),
97
+ // Giao diện / dữ liệu
98
+ siteLogo: draw([["c", 12, 12, 10, 0], ["p", "M6.5 16l4-6 3 4 1.5-2 2.5 4z"]]),
99
+ siteTitle: draw([["r", 2, 5, 20, 14, 3, 0], ["p", "M6 8h12v2.5h-4.7V17h-2.6v-6.5H6z"]]),
100
+ siteTagline: draw([["r", 2, 5, 20, 14, 3, 0], ...lines(5, 9, [14, 9], 4, 2)]),
101
+ navigation: draw([["r", 2, 8, 20, 8, 3, 0], ["r", 4.5, 11, 4, 2, 1], ["r", 10, 11, 4, 2, 1], ["r", 15.5, 11, 4, 2, 1]]),
102
+ search: draw([["c", 10, 10, 7, 0], ["c", 10, 10, 4.2, 2], ["p", "M14.6 13.2l7 7-1.6 1.6-7-7z"], ["p", "M10 3a7 7 0 1 1 0 14 7 7 0 0 1 0-14zm0 2.8a4.2 4.2 0 1 0 0 8.4 4.2 4.2 0 0 0 0-8.4z"]]),
103
+ languageSwitcher: draw([["c", 12, 12, 10, 0], ["p", "M12 2c2.5 2.7 3.8 6 3.8 10S14.5 19.3 12 22c-2.5-2.7-3.8-6-3.8-10S9.5 4.7 12 2zm0 2.9C10.7 6.8 10 9.2 10 12s.7 5.2 2 7.1c1.3-1.9 2-4.3 2-7.1s-.7-5.2-2-7.1zM2.5 11h19v2h-19z"]]),
104
+ copyright: draw([["c", 12, 12, 10, 0], ["p", "M12 6.5a5.5 5.5 0 0 1 5 3.2l-2 .9a3.3 3.3 0 1 0 0 2.8l2 .9A5.5 5.5 0 1 1 12 6.5z"]]),
105
+ loginout: draw([["r", 10, 3, 11, 18, 3, 0], ["p", "M3 11h8.2L9 8.8l1.4-1.4L15 12l-4.6 4.6L9 15.2l2.2-2.2H3z"]]),
106
+ query: draw([["r", 2, 2, 20, 9, 2.5, 0], ["r", 4, 4, 6, 5, 1.2], ...lines(12, 4.5, [8, 5], 3.2, 1.8), ["r", 2, 13, 20, 9, 2.5, 0], ["r", 4, 15, 6, 5, 1.2], ...lines(12, 15.5, [8, 5], 3.2, 1.8)]),
107
+ postTemplate: draw([["r", 2, 3, 20, 18, 3, 0], ["r", 5, 6, 14, 6, 1.5], ...lines(5, 14, [14, 9])]),
108
+ queryEmpty: draw([["r", 2, 3, 20, 18, 3, 0], ["c", 12, 12, 4.5], ["p", "M9.8 9.8l4.4 4.4-1 .9-4.3-4.3z", 2]]),
109
+ queryTotal: draw([["r", 2, 5, 20, 14, 3, 0], ["p", "M7 8h2v8H7zm4 0h6v2h-4v1h3a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1h-5v-2h4v-1h-3a1 1 0 0 1-1-1v-3a1 1 0 0 1 1-1z"]]),
110
+ queryTitle: draw([["r", 2, 3, 20, 18, 3, 0], ["p", H]]),
111
+ pagination: draw([["r", 1, 8, 6, 8, 2], ["r", 9, 8, 6, 8, 2, 0], ["r", 17, 8, 6, 8, 2, 0]]),
112
+ postTitle: draw([["r", 2, 2, 20, 20, 4, 0], ["p", "M6 6h12v2.6h-4.7V18h-2.6V8.6H6z"]]),
113
+ postContent: draw([["r", 4, 2, 16, 20, 3, 0], ...lines(7, 6, [10, 10, 10, 6])]),
114
+ postExcerpt: draw([["r", 2, 4, 20, 16, 3, 0], ...lines(5, 8, [14, 10]), ["c", 17, 15.5, 1], ["c", 13.5, 15.5, 1]]),
115
+ featuredImage: draw([...photo, ["c", 18.5, 5.5, 3.5], ["p", "M18.5 3.4l.6 1.4 1.5.1-1.1 1 .3 1.5-1.3-.8-1.3.8.3-1.5-1.1-1 1.5-.1z", 2]]),
116
+ postDate: draw([["r", 2, 4, 20, 18, 3, 0], ["r", 2, 4, 20, 5, 3], ["r", 6, 2, 2, 4, 1], ["r", 16, 2, 2, 4, 1], ["r", 6, 12, 3, 3, 1], ["r", 10.5, 12, 3, 3, 1], ["r", 15, 12, 3, 3, 1]]),
117
+ postAuthor: draw([["c", 12, 12, 10, 0], ["c", 12, 9.5, 3.5], ["p", "M5.5 18.5a7.5 7.5 0 0 1 13 0A10 10 0 0 1 12 22a10 10 0 0 1-6.5-3.5z"]]),
118
+ avatar: draw([["c", 12, 12, 10, 0], ["c", 12, 9.5, 3.5], ["p", "M5.5 18.5a7.5 7.5 0 0 1 13 0A10 10 0 0 1 12 22a10 10 0 0 1-6.5-3.5z"]]),
119
+ postTerms: draw([["p", "M3 4.5A1.5 1.5 0 0 1 4.5 3h7l9.4 9.4a1.5 1.5 0 0 1 0 2.1l-6.4 6.4a1.5 1.5 0 0 1-2.1 0L3 11.5z", 0], ["c", 7.5, 7.5, 2]]),
120
+ termList: draw([["p", "M3 4.5A1.5 1.5 0 0 1 4.5 3H10l7 7-6 6-8-8z", 0], ["c", 7, 7, 1.6], ["r", 13, 17, 9, 2, 1], ["r", 13, 20, 6, 2, 1]]),
121
+ termDescription: draw([["r", 2, 3, 20, 18, 3, 0], ["p", "M5 6h5.5l3 3-3 3H5z"], ...lines(5, 15, [14])]),
122
+ comments: draw([["p", "M3 3h14a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H9l-4 3.5V15H3a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z", 0], ...lines(4.5, 6.5, [10, 7], 3.5, 1.8), ["p", "M21 9h1a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1h-1v3l-3.5-3H11a1 1 0 0 1-1-1v-1h8a3 3 0 0 0 3-3z"]]),
123
+ commentsCount: draw([["p", "M3 3h18a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2h-9l-5 4v-4H3a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z", 0], ["p", "M10 7h2v7h-2zm-3 2.5h2v4.5H7zM13 9.5h2v4.5h-2zm3-1.5h2v6h-2z"]]),
124
+ readMore: draw([["r", 2, 6, 20, 12, 6, 0], ["p", "M12 9.2l4.3 2.8-4.3 2.8V13H7v-2h5z"]]),
125
+ postNavigation: draw([["r", 1, 6, 10, 12, 3, 0], ["r", 13, 6, 10, 12, 3], ["p", "M7.5 9L4.5 12l3 3 1-1-2-2 2-2zM16.5 9l-1 1 2 2-2 2 1 1 3-3z", 2]]),
126
+ breadcrumbs: draw([["r", 1, 8, 6, 8, 2], ["s", "M8.5 9.5l2.5 2.5-2.5 2.5", 0], ["r", 12, 8, 4.5, 8, 2, 0], ["r", 18.5, 8, 4.5, 8, 2, 0]]),
127
+ pageList: draw([["r", 2, 2, 8, 6, 1.5], ["r", 7, 10, 15, 4, 1.5, 0], ["r", 7, 17, 15, 4, 1.5, 0], ["r", 4, 8, 1.6, 11, .8, 0]]),
128
+ archives: draw([["r", 2, 3, 20, 6, 2], ["r", 3.5, 10, 17, 11, 2, 0], ["r", 9, 13, 6, 2, 1]]),
129
+ listItem: draw([["c", 6, 12, 2.5], ["r", 10.5, 10.8, 11, 2.4, 1.2, 0]]),
130
+ taskItem: draw([["r", 3, 8, 8, 8, 2], ["r", 13, 10.8, 9, 2.4, 1.2, 0]]),
131
+ map: draw([["p", "M2 6l6-3 8 3 6-3v15l-6 3-8-3-6 3z", 0], ["p", pin], ["c", 12, 8.5, 2.3, 2]]),
132
+ videoPopup: draw([["r", 2, 4, 20, 16, 3, 0], ["c", 12, 12, 5], ["p", play, 2]]),
133
+ };
134
+
135
+ /** Icon bộ cột theo tỉ lệ ("33-66" → hai cột 1/3, 2/3). */
136
+ const colsCache = new Map<string, ComponentType<{ className?: string }>>();
137
+ export function columnsIcon(name: string): ComponentType<{ className?: string }> | undefined {
138
+ const rep = /^(\d+)x(\d+)$/.exec(name); // "25x4" = 4 cột 25
139
+ const w = rep ? Array.from({ length: Number(rep[2]) }, () => Number(rep[1])) : name.split("-").map(Number);
140
+ if (w.length < 2 || w.some((x) => !(x > 0))) return undefined;
141
+ if (!colsCache.has(name)) {
142
+ const gap = 1.5, inner = 16 - gap * (w.length - 1), sum = w.reduce((a, b) => a + b, 0);
143
+ let x = 4;
144
+ const shapes: Shape[] = [["r", 2, 4, 20, 16, 3, 0]];
145
+ for (const wi of w) { const cw = (inner * wi) / sum; shapes.push(["r", x, 6, cw, 12, 1.2, 1]); x += cw + gap; }
146
+ colsCache.set(name, draw(shapes));
147
+ }
148
+ return colsCache.get(name);
149
+ }
150
+
151
+ /** Icon 2 lớp theo tên khối lõi; khối plugin / khối lạ giữ icon của chính nó. */
152
+ export const BLOCK_ICONS: Record<string, ComponentType<{ className?: string }>> = I;
@@ -1,3 +1,5 @@
1
+ import type { BNode } from "../core/model";
2
+ import type { EditorStore } from "../core/store";
1
3
  /** Chép / dán kiểu dáng (chỉ `attrs.style`) + vị trí menu chuột phải. */
2
4
 
3
5
  // shortcut: chỉ nhớ trong phiên (bộ nhớ của trang admin, giữ khi chuyển bài trong SPA), mất khi tải lại — cần chép giữa tab thì chuyển sang localStorage.
@@ -17,3 +19,23 @@ export function menuPosition(x: number, y: number, w: number, h: number, vw: num
17
19
  const top = y + h > vh - 8 ? y - h : y;
18
20
  return { left: Math.round(Math.max(8, Math.min(left, vw - 8 - w))), top: Math.round(Math.max(8, Math.min(top, vh - 8 - h))) };
19
21
  }
22
+
23
+ const ALL_DEVICES = ["desktop", "tablet", "mobile"] as const;
24
+ /** Khối ẩn hẳn (mọi khổ màn hình) — dùng chung `style.hide` của ô "Ẩn trên thiết bị". */
25
+ export const isHidden = (b: BNode) => { const h = (b.attrs.style as { hide?: string[] } | undefined)?.hide; return !!h && ALL_DEVICES.every((d) => h.includes(d)); };
26
+ /** Ẩn / hiện các khối: ẩn = ẩn mọi khổ; hiện = bỏ hết ẩn (cả ẩn theo từng khổ). */
27
+ export function toggleHidden(store: EditorStore, ids: string[]) {
28
+ const first = store.block(ids[0]);
29
+ if (!first) return;
30
+ const hide = !isHidden(first);
31
+ store.batch(() => {
32
+ for (const id of ids) {
33
+ const b = store.block(id);
34
+ if (!b) continue;
35
+ const { hide: _drop, ...rest } = (b.attrs.style as Record<string, unknown> | undefined) ?? {};
36
+ const style = hide ? { ...rest, hide: [...ALL_DEVICES] } : rest;
37
+ store.setAttrs([id], { style: Object.keys(style).length ? style : undefined });
38
+ }
39
+ });
40
+ }
41
+
@@ -6,21 +6,32 @@ import { Row, Section, cx } from "./style-controls";
6
6
  import { UnitInput } from "./unit-controls";
7
7
 
8
8
  type State = "normal" | "hover" | "active";
9
+ /** Ô rời mà phần (attrs.parts) chưa thay được — luôn hiện ở khối đã chia phần. */
10
+ const KEEP = new Set(["imageFit", "imageOpacity", "imageFilter", "imageHoverEffect", "imageHoverOpacity", "imageHoverFilter", "iconListGap", "iconListColumnGap", "iconListIconGap", "iconListDivider", "tabsGap", "accGap", "buttonSize", "buttonWidth", "buttonIconColor", "buttonIconHoverColor", "buttonIconSize", "progressHeight", "iconBoxImageWidth", "tabsTitleWidth", "tabsPanelMinHeight", "searchPlaceholderColor", "searchMaxWidth", "galleryGap"]);
9
11
 
10
12
  /**
11
13
  * Mục Kiểu dáng riêng của khối lõi (như tab Style của từng widget Elementor: Danh sách › khoảng cách, đường kẻ; Icon › màu, cỡ…).
12
14
  * Ô khai ở @ecomcx/ecomweb-content core-controls → website và khung soạn sinh cùng CSS (controlsCss). Ô `responsive` sửa theo khổ
13
15
  * đang chọn ở đầu tab; ô có `state` nằm trong thẻ Rê chuột / Đang mở của mục.
14
16
  */
15
- export function BlockStyleSections({ type, attrs, setAttrs, device }: { type: string; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void; device: Device }) {
17
+ /** `legacyOnly`: khối đã chia phần (attrs.parts) — chỉ hiện mục ô rời đã có giá trị (nội dung cũ), để sửa / xoá. */
18
+ export function BlockStyleSections({ type, attrs, setAttrs, device, legacyOnly }: { type: string; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void; device: Device; legacyOnly?: boolean }) {
16
19
  const t = useMsgs("blockStyle");
17
20
  const sections = new Map<string, Array<[string, ControlSpec]>>();
18
21
  for (const [name, spec] of Object.entries(coreControlsFor(type))) {
22
+ if (name === "tabsAlign") continue; // sửa ở tab Cài đặt
19
23
  const k = spec.section ?? "text";
20
24
  sections.set(k, [...(sections.get(k) ?? []), [name, spec]]);
21
25
  }
26
+ const reduced = new Set<string>(); // mục chỉ còn ô phần chưa thay: tên "… · tuỳ chọn khác" để khỏi trùng tên phần
27
+ sections.delete("columns"); // khe cột / khe hàng / hướng xếp: đã có ở tab Cài đặt (ColumnsInspector)
28
+ if (legacyOnly) for (const [k, list] of sections) {
29
+ if (list.some(([n]) => attrs[n] !== undefined)) continue;
30
+ const keep = list.filter(([n]) => KEEP.has(n));
31
+ if (keep.length) { sections.set(k, keep); if (keep.length < list.length) reduced.add(k); } else sections.delete(k);
32
+ }
22
33
  if (!sections.size) return null;
23
- return <>{[...sections].map(([key, list]) => <ControlSection key={key} title={(t.section as Record<string, string>)[key] ?? key} list={list} attrs={attrs} setAttrs={setAttrs} device={device} />)}</>;
34
+ return <>{[...sections].map(([key, list]) => <ControlSection key={key} title={`${(t.section as Record<string, string>)[key] ?? key}${reduced.has(key) ? ` · ${t.more}` : ""}`} list={list} attrs={attrs} setAttrs={setAttrs} device={device} />)}</>;
24
35
  }
25
36
 
26
37
  function ControlSection({ title, list, attrs, setAttrs, device }: { title: string; list: Array<[string, ControlSpec]>; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void; device: Device }) {
@@ -58,7 +69,7 @@ function ControlField({ name, spec, value, device, onChange }: { name: string; s
58
69
  onChange(!keys.length ? undefined : keys.length === 1 && keys[0] === "base" ? next.base : next);
59
70
  };
60
71
  const dev = spec.responsive ? device : undefined;
61
- if (spec.type === "color") return <Row label={label} device={dev}><ColorInput label={label} value={typeof v === "string" ? v : undefined} onChange={set} /></Row>;
72
+ if (spec.type === "color") return dev ? <Row label={label} device={dev}><ColorInput label={label} value={typeof v === "string" ? v : undefined} onChange={set} /></Row> : <ColorInput label={label} value={typeof v === "string" ? v : undefined} onChange={set} />;
62
73
  if (spec.type === "length") return <Row label={label} device={dev}><UnitInput label={label} value={typeof v === "string" ? v : undefined} placeholder={typeof inherited === "string" ? inherited : undefined} units={["px", "rem", "em", "%"]} onChange={set} /></Row>;
63
74
  if (spec.type === "number") return (
64
75
  <Row label={`${label}${typeof v === "number" ? `: ${v}` : ""}`} device={dev}>
@@ -1,22 +1,87 @@
1
+ import { useEffect, useRef, useState } from "react";
1
2
  import { ColorSwatchInput } from "../../shared/color-swatch";
2
3
  import { useEditor } from "../context";
4
+ import { useMsgs } from "../i18n";
3
5
 
4
6
  const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
5
7
 
6
8
  // Theme không khai màu thì website dùng các màu mặc định này (core CSS) — vẫn cho chọn, như bản soạn cũ (shared/style-panel.tsx COLORS)
7
- const DEFAULT_COLORS = { primary: "#2563eb", muted: "#6b7280", surface: "#f4f4f5", white: "#ffffff", black: "#111111" };
9
+ const DEFAULT_COLORS = { primary: "#1a597b", muted: "#5d6a75", surface: "#f3f4f6", white: "#ffffff", black: "#111111" };
8
10
 
9
- /** Ô màu: preset của theme + bảng chọn màu + bỏ màu. */
10
- export function ColorInput({ value, onChange, label }: { value?: string; onChange(v: string | undefined): void; label: string }) {
11
+ /** Tách giá trị màu thành màu gốc + độ đậm 1–100: `primary/40` → primary 40; `#1a597bcc` → #1a597b 80; còn lại (rgb / hsl / tên) → đậm 100, không chỉnh được. */
12
+ export function splitAlpha(v?: string): { base?: string; alpha: number; editable: boolean } {
13
+ if (!v) return { alpha: 100, editable: false };
14
+ const m = /^([a-z][a-z0-9-]{0,30})\/([1-9]\d?)$/.exec(v);
15
+ if (m) return { base: m[1], alpha: Number(m[2]), editable: true };
16
+ if (/^#[0-9a-f]{8}$/i.test(v)) return { base: v.slice(0, 7), alpha: Math.round((parseInt(v.slice(7), 16) / 255) * 100), editable: true };
17
+ if (/^#[0-9a-f]{6}$/i.test(v) || /^#[0-9a-f]{3}$/i.test(v)) return { base: v, alpha: 100, editable: true };
18
+ if (/^[a-z][a-z0-9-]{0,30}$/.test(v)) return { base: v, alpha: 100, editable: true };
19
+ return { base: v, alpha: 100, editable: false };
20
+ }
21
+ /** Ghép lại: preset → `name/NN`, hex → #rrggbbaa; đậm 100 → bỏ phần độ đậm. */
22
+ export function joinAlpha(base: string, alpha: number): string {
23
+ const a = Math.min(100, Math.max(1, Math.round(alpha)));
24
+ if (a >= 100) return base;
25
+ if (/^#[0-9a-f]{3}$/i.test(base)) base = "#" + [...base.slice(1)].map((c) => c + c).join("");
26
+ if (/^#[0-9a-f]{6}$/i.test(base)) return base + Math.round((a / 100) * 255).toString(16).padStart(2, "0");
27
+ return `${base}/${a}`;
28
+ }
29
+
30
+ export function useSiteColors(): Record<string, string> {
11
31
  const { host } = useEditor();
12
32
  const declared = host.presets?.colors;
13
- const colorMap: Record<string, string> = declared && Object.keys(declared).length ? declared : DEFAULT_COLORS;
14
- const presets = Object.entries(colorMap);
33
+ return declared && Object.keys(declared).length ? declared : DEFAULT_COLORS;
34
+ }
35
+
36
+ /**
37
+ * Ô màu gọn: một dòng [chấm màu] tên ô … tên màu. Bấm mở bảng: màu của website (đổi bảng màu website là cả trang đổi theo),
38
+ * màu tự chọn, về mặc định. Thay cho lưới chấm màu luôn mở (tốn chỗ khi khối có nhiều ô màu).
39
+ */
40
+ export function ColorInput({ value, onChange, label }: { value?: string; onChange(v: string | undefined): void; label: string }) {
41
+ const colors = useSiteColors();
42
+ const t = useMsgs("controls");
43
+ const [open, setOpen] = useState(false);
44
+ const ref = useRef<HTMLDivElement>(null);
45
+ useEffect(() => {
46
+ if (!open) return;
47
+ const out = (e: MouseEvent) => { if (!ref.current?.contains(e.target as Node)) setOpen(false); };
48
+ const esc = (e: KeyboardEvent) => { if (e.key === "Escape") { e.stopPropagation(); setOpen(false); } };
49
+ document.addEventListener("mousedown", out, true); document.addEventListener("keydown", esc, true);
50
+ return () => { document.removeEventListener("mousedown", out, true); document.removeEventListener("keydown", esc, true); };
51
+ }, [open]);
52
+ const { base, alpha, editable } = splitAlpha(value);
53
+ const baseCss = base ? colors[base] ?? base : undefined;
54
+ // Xem trước có độ đậm: trộn màu gốc với trong suốt (cùng công thức website dùng)
55
+ const css = baseCss ? (alpha < 100 ? `color-mix(in srgb, ${baseCss} ${alpha}%, transparent)` : baseCss) : undefined;
15
56
  return (
16
- <div className="ecx-chip-row">
17
- {presets.map(([name, c]) => <button key={name} type="button" className={cx("ecx-chip ecx-chip-swatch", value === name && "is-active")} title={name} aria-label={`${label}: ${name}`} style={{ background: c }} onClick={() => onChange(value === name ? undefined : name)} />)}
18
- <ColorSwatchInput value={value && (colorMap[value] ?? value)} onChange={onChange} label={label} size={28} />
19
- {value && <button type="button" className="ecx-chip" onClick={() => onChange(undefined)}>×</button>}
57
+ <div className="ecx-color-field" ref={ref}>
58
+ <button type="button" className={cx("ecx-color-row-btn", open && "is-open")} aria-haspopup="dialog" aria-expanded={open} onClick={() => setOpen(!open)}>
59
+ <span className={cx("ecx-color-dot", !css && "is-none")} style={css ? { background: css } : undefined} />
60
+ <span className="ecx-color-name">{label}</span>
61
+ <span className="ecx-color-value">{value ? (alpha < 100 ? `${(colors[base ?? ""] ? base : (base ?? "").toUpperCase())} · ${alpha}%` : colors[value] ? value : value.toUpperCase()) : t.noColor}</span>
62
+ </button>
63
+ {open && (
64
+ <div className="ecx-color-pop" role="dialog" aria-label={label}>
65
+ <div className="ecx-pop-title">{t.siteColors}</div>
66
+ <div className="ecx-color-grid">
67
+ {Object.entries(colors).map(([name, c]) => (
68
+ <button key={name} type="button" className={cx("ecx-color-cell", base === name && "is-active")} title={name} aria-label={`${label}: ${name}`} aria-pressed={base === name}
69
+ style={{ background: c }} onClick={() => { onChange(alpha < 100 ? joinAlpha(name, alpha) : name); setOpen(false); }} />
70
+ ))}
71
+ </div>
72
+ <label className="ecx-color-alpha">
73
+ <span>{t.colorOpacity}</span>
74
+ <input type="range" min={1} max={100} step={1} value={alpha} disabled={!value || !editable} aria-label={`${label}: ${t.colorOpacity}`}
75
+ onChange={(e) => base && onChange(joinAlpha(base, Number(e.target.value)))} />
76
+ <output>{alpha}%</output>
77
+ </label>
78
+ <p className="ecx-pop-hint">{t.colorHint}</p>
79
+ <div className="ecx-pop-foot">
80
+ <span className="ecx-pop-custom"><ColorSwatchInput value={baseCss && /^#[0-9a-f]{6}$/i.test(baseCss) ? baseCss : baseCss} onChange={(v) => onChange(alpha < 100 ? joinAlpha(v, alpha) : v)} label={`${label}: ${t.customColor}`} size={24} /> {t.customColor}</span>
81
+ {value && <button type="button" className="ecx-link-btn" onClick={() => { onChange(undefined); setOpen(false); }}>{t.clearColor}</button>}
82
+ </div>
83
+ </div>
84
+ )}
20
85
  </div>
21
86
  );
22
87
  }
@@ -0,0 +1,58 @@
1
+ import { DIVIDER_PATHS, DIVIDER_SHAPES, normalizeStyle, type BlockDivider, type BlockStyle } from "@ecomcx/ecomweb-content";
2
+ import { useMsgs } from "../i18n";
3
+ import { ColorInput } from "./color-field";
4
+ import { Row, Section, cx } from "./style-controls";
5
+
6
+ type Side = "top" | "bottom";
7
+
8
+ /**
9
+ * Đường chia trên / dưới của Nhóm (tab Cài đặt): hình tự vẽ (sóng, vòm, vát, tam giác, răng cưa) tô màu của khối kế bên.
10
+ * Ghi vào style.divider; chọn hình là bật, "Không" là tắt.
11
+ */
12
+ export function DividerSection({ attrs, setAttrs }: { attrs: Record<string, unknown>; setAttrs(a: Record<string, unknown>): void }) {
13
+ const t = useMsgs("layout") as Record<string, string>;
14
+ const style = (normalizeStyle(attrs.style) ?? {}) as BlockStyle;
15
+ const div = style.divider ?? {};
16
+ const commit = (next: BlockStyle["divider"]) => setAttrs({ style: normalizeStyle({ ...style, divider: next }) ?? undefined });
17
+ const patch = (side: Side, p: Partial<BlockDivider> | null) => {
18
+ const cur = div[side];
19
+ const nextSide = p === null ? undefined : ({ color: "white", ...cur, ...p } as BlockDivider);
20
+ const next = { ...div, [side]: nextSide };
21
+ if (!next.top) delete next.top;
22
+ if (!next.bottom) delete next.bottom;
23
+ commit(Object.keys(next).length ? next : undefined);
24
+ };
25
+ const side = (s: Side) => {
26
+ const d = div[s];
27
+ return (
28
+ <div className="ecx-divider-side" data-ecx-divider={s} key={s}>
29
+ <Row label={s === "top" ? t.dividerTop : t.dividerBottom}>
30
+ <div role="radiogroup" aria-label={s === "top" ? t.dividerTop : t.dividerBottom} className="ecx-divider-shapes">
31
+ <button type="button" role="radio" aria-checked={!d} className={cx("ecx-divider-shape", !d && "is-active")} onClick={() => patch(s, null)}>{t.dividerNone}</button>
32
+ {DIVIDER_SHAPES.map((shape) => (
33
+ <button key={shape} type="button" role="radio" aria-checked={d?.shape === shape} aria-label={t[`divider_${shape}`]} title={t[`divider_${shape}`]} className={cx("ecx-divider-shape", d?.shape === shape && "is-active")} onClick={() => patch(s, { shape })}>
34
+ <svg viewBox="0 0 1200 100" preserveAspectRatio="none" aria-hidden="true"><path d={DIVIDER_PATHS[shape]} fill="currentColor" transform={s === "top" ? "matrix(1 0 0 -1 0 100)" : undefined} /></svg>
35
+ </button>
36
+ ))}
37
+ </div>
38
+ </Row>
39
+ {d && (
40
+ <>
41
+ <ColorInput label={t.dividerColor} value={d.color} onChange={(c) => patch(s, { color: c ?? "white" })} />
42
+ <Row label={`${t.dividerHeight}: ${d.height ?? 80}px`}>
43
+ <input type="range" className="ecx-range" min={10} max={300} step={5} aria-label={t.dividerHeight} value={d.height ?? 80} onChange={(e) => patch(s, { height: Number(e.target.value) })} />
44
+ </Row>
45
+ <label className="ecx-check"><input type="checkbox" checked={!!d.flip} onChange={(e) => patch(s, { flip: e.target.checked ? true : undefined })} /> {t.dividerFlip}</label>
46
+ </>
47
+ )}
48
+ </div>
49
+ );
50
+ };
51
+ return (
52
+ <Section title={t.dividerTitle} modified={!!(div.top || div.bottom)} onReset={() => commit(undefined)} defaultOpen={div.top || div.bottom ? true : undefined}>
53
+ {side("top")}
54
+ {side("bottom")}
55
+ <p className="ecx-muted">{t.dividerHelp}</p>
56
+ </Section>
57
+ );
58
+ }
@@ -0,0 +1,38 @@
1
+ import { useMsgs } from "../i18n";
2
+ import { Row, Section, Seg } from "./style-controls";
3
+ import { UnitInput } from "./unit-controls";
4
+
5
+ type Mode = "fill" | "site" | "custom";
6
+
7
+ /**
8
+ * Độ rộng của Nhóm ở tab Cài đặt (thay cho nút "Độ rộng" rời + ô tích "giữ chữ theo bề rộng cột chữ"):
9
+ * độ rộng của khối (nội dung / rộng / đầy màn) và độ rộng nội dung bên trong (hết khối / theo website / tự nhập số).
10
+ */
11
+ export function GroupWidthSection({ attrs, setAttrs }: { attrs: Record<string, unknown>; setAttrs(a: Record<string, unknown>): void }) {
12
+ const t = useMsgs("layout") as Record<string, string>;
13
+ const align = attrs.align === "wide" || attrs.align === "full" ? (attrs.align as string) : "content";
14
+ const custom = typeof attrs.contentWidth === "string" && attrs.contentWidth !== "";
15
+ const mode: Mode = custom ? "custom" : attrs.constrained === true ? "site" : "fill";
16
+ const setMode = (m: Mode | undefined) => {
17
+ if (m === "custom") setAttrs({ contentWidth: String(attrs.contentWidth || "900px"), constrained: undefined });
18
+ else setAttrs({ contentWidth: undefined, constrained: m === "site" ? true : undefined });
19
+ };
20
+ return (
21
+ <Section title={t.groupWidth} defaultOpen>
22
+ <Row label={t.blockWidth}>
23
+ <Seg label={t.blockWidth} value={align} onChange={(v) => setAttrs({ align: v === "wide" || v === "full" ? v : undefined })}
24
+ options={[["content", t.bwContent, t.bwContent], ["wide", t.bwWide, t.bwWide], ["full", t.bwFull, t.bwFull]]} />
25
+ </Row>
26
+ <Row label={t.contentWidth}>
27
+ <Seg<Mode> label={t.contentWidth} value={mode} onChange={setMode}
28
+ options={[["fill", t.cwFill, t.cwFill], ["site", t.cwSite, t.cwSite], ["custom", t.cwCustom, t.cwCustom]]} />
29
+ </Row>
30
+ {custom && (
31
+ <Row label={t.cwValue} onReset={() => setAttrs({ contentWidth: undefined })}>
32
+ <UnitInput label={t.cwValue} value={String(attrs.contentWidth)} max={1600} units={["px", "rem", "%"]} onChange={(v) => setAttrs({ contentWidth: v })} />
33
+ </Row>
34
+ )}
35
+ <p className="ecx-muted">{t.cwHelp}</p>
36
+ </Section>
37
+ );
38
+ }
@@ -0,0 +1,51 @@
1
+ import { ICON_NAMES, ICON_PATHS } from "@ecomcx/ecomweb-content";
2
+ import { ChevronDown, X } from "lucide-react";
3
+ import { useEffect, useMemo, useRef, useState } from "react";
4
+ import { useMsgs } from "../i18n";
5
+ import { cx } from "./style-controls";
6
+
7
+ const Svg = ({ name, size = 20 }: { name: string; size?: number }) => (
8
+ <svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d={ICON_PATHS[name]} /></svg>
9
+ );
10
+
11
+ /**
12
+ * Ô chọn icon: ô hiện icon đang chọn + mũi tên; bấm mở lưới icon có ô tìm (như bảng chọn icon của các bộ khối lớn).
13
+ * `allowNone`: có lựa chọn "Không có icon" (vd nút).
14
+ */
15
+ export function IconPicker({ value, onChange, label, allowNone }: { value?: string; onChange(v: string | undefined): void; label: string; allowNone?: boolean }) {
16
+ const t = useMsgs("controls");
17
+ const [open, setOpen] = useState(false);
18
+ const [q, setQ] = useState("");
19
+ const ref = useRef<HTMLDivElement>(null);
20
+ useEffect(() => {
21
+ if (!open) return;
22
+ const out = (e: MouseEvent) => { if (!ref.current?.contains(e.target as Node)) setOpen(false); };
23
+ const esc = (e: KeyboardEvent) => { if (e.key === "Escape") { e.stopPropagation(); setOpen(false); } };
24
+ document.addEventListener("mousedown", out, true); document.addEventListener("keydown", esc, true);
25
+ return () => { document.removeEventListener("mousedown", out, true); document.removeEventListener("keydown", esc, true); };
26
+ }, [open]);
27
+ const names = useMemo(() => { const k = q.trim().toLowerCase(); return (ICON_NAMES as readonly string[]).filter((n) => !k || n.toLowerCase().includes(k)); }, [q]);
28
+ const has = !!value && !!ICON_PATHS[value];
29
+ return (
30
+ <div className="ecx-icon-picker" ref={ref}>
31
+ <button type="button" className={cx("ecx-icon-picker-btn", open && "is-open")} aria-haspopup="dialog" aria-expanded={open} aria-label={label} onClick={() => setOpen(!open)}>
32
+ {has ? <Svg name={value!} size={22} /> : <span className="ecx-muted">{t.noIcon}</span>}
33
+ <span className="ecx-icon-picker-name">{has ? value : ""}</span>
34
+ <ChevronDown className="ecx-icon" />
35
+ </button>
36
+ {open && (
37
+ // preventDefault: ô này nằm trong <label> của form — không chặn thì bấm trong bảng kích lại nút mở (bảng đóng rồi mở lại)
38
+ <div className="ecx-icon-pop" role="dialog" aria-label={label} onClick={(e) => e.preventDefault()}>
39
+ <input className="ecx-input" autoFocus placeholder={t.searchIcons} value={q} onChange={(e) => setQ(e.target.value)} />
40
+ <div className="ecx-icon-grid" role="listbox" aria-label={label}>
41
+ {allowNone && <button type="button" role="option" aria-selected={!has} title={t.noIcon} className={cx("ecx-icon-cell", !has && "is-active")} onClick={() => { onChange(undefined); setOpen(false); }}><X className="ecx-icon" /></button>}
42
+ {names.map((n) => (
43
+ <button key={n} type="button" role="option" aria-selected={value === n} title={n} className={cx("ecx-icon-cell", value === n && "is-active")} onClick={() => { onChange(n); setOpen(false); }}><Svg name={n} /></button>
44
+ ))}
45
+ </div>
46
+ {!names.length && <p className="ecx-pop-hint">{t.noIconFound}</p>}
47
+ </div>
48
+ )}
49
+ </div>
50
+ );
51
+ }