@ecomcx/ecomweb-editor 1.30.0 → 1.32.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 (95) 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/block-desc.ts +1 -0
  5. package/src/locales/en/block-style.ts +7 -4
  6. package/src/locales/en/block-titles.ts +1 -0
  7. package/src/locales/en/blocks.ts +10 -2
  8. package/src/locales/en/columns.ts +12 -0
  9. package/src/locales/en/controls.ts +21 -0
  10. package/src/locales/en/hints.ts +215 -1
  11. package/src/locales/en/index.ts +6 -2
  12. package/src/locales/en/layout.ts +32 -0
  13. package/src/locales/en/legacy.ts +1 -1
  14. package/src/locales/en/library.ts +38 -0
  15. package/src/locales/en/parts.ts +12 -0
  16. package/src/locales/en/placeholders.ts +104 -0
  17. package/src/locales/en/presets.ts +6 -0
  18. package/src/locales/en/v2.ts +21 -0
  19. package/src/locales/vi/attrs.ts +10 -0
  20. package/src/locales/vi/background.ts +17 -0
  21. package/src/locales/vi/block-desc.ts +1 -0
  22. package/src/locales/vi/block-style.ts +7 -4
  23. package/src/locales/vi/block-titles.ts +1 -0
  24. package/src/locales/vi/blocks.ts +10 -2
  25. package/src/locales/vi/columns.ts +12 -0
  26. package/src/locales/vi/controls.ts +21 -0
  27. package/src/locales/vi/hints.ts +216 -2
  28. package/src/locales/vi/index.ts +6 -2
  29. package/src/locales/vi/layout.ts +32 -0
  30. package/src/locales/vi/legacy.ts +1 -1
  31. package/src/locales/vi/library.ts +38 -0
  32. package/src/locales/vi/parts.ts +12 -0
  33. package/src/locales/vi/placeholders.ts +103 -0
  34. package/src/locales/vi/presets.ts +6 -0
  35. package/src/locales/vi/v2.ts +21 -0
  36. package/src/shared/panel-store.ts +3 -3
  37. package/src/shared/patterns.ts +3 -52
  38. package/src/shared/style-panel.tsx +2 -2
  39. package/src/shared/types.ts +2 -0
  40. package/src/v2/blocks/columns-inspector.tsx +210 -0
  41. package/src/v2/blocks/compat.tsx +91 -5
  42. package/src/v2/blocks/form.tsx +7 -4
  43. package/src/v2/blocks/index.ts +10 -4
  44. package/src/v2/blocks/inline-style.ts +1 -1
  45. package/src/v2/blocks/layout.tsx +305 -83
  46. package/src/v2/blocks/media.tsx +91 -81
  47. package/src/v2/blocks/resize.tsx +172 -4
  48. package/src/v2/blocks/text.tsx +60 -22
  49. package/src/v2/blocks/theme.tsx +83 -17
  50. package/src/v2/blocks/tools.tsx +50 -5
  51. package/src/v2/blocks/widgets.tsx +85 -20
  52. package/src/v2/canvas/block-list.tsx +21 -6
  53. package/src/v2/canvas/canvas-css.ts +139 -7
  54. package/src/v2/canvas/canvas.tsx +20 -3
  55. package/src/v2/canvas/dnd.ts +34 -3
  56. package/src/v2/canvas/move-animation.ts +94 -0
  57. package/src/v2/canvas/server-block.tsx +7 -4
  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 +14 -0
  61. package/src/v2/core/registry.ts +3 -1
  62. package/src/v2/core/structure.ts +4 -2
  63. package/src/v2/editor.css +244 -11
  64. package/src/v2/editor.tsx +8 -2
  65. package/src/v2/index.ts +3 -0
  66. package/src/v2/ui/ai.tsx +9 -5
  67. package/src/v2/ui/attr-form.tsx +42 -13
  68. package/src/v2/ui/attr-hints.ts +104 -6
  69. package/src/v2/ui/background-panel.tsx +65 -21
  70. package/src/v2/ui/block-icons.tsx +152 -0
  71. package/src/v2/ui/block-menu.ts +22 -0
  72. package/src/v2/ui/block-style-panel.tsx +14 -3
  73. package/src/v2/ui/color-field.tsx +74 -9
  74. package/src/v2/ui/divider-panel.tsx +58 -0
  75. package/src/v2/ui/group-width.tsx +38 -0
  76. package/src/v2/ui/icon-picker.tsx +51 -0
  77. package/src/v2/ui/inserter.tsx +51 -7
  78. package/src/v2/ui/inspector.tsx +48 -16
  79. package/src/v2/ui/layout-panel.tsx +5 -47
  80. package/src/v2/ui/list-view.tsx +81 -7
  81. package/src/v2/{blocks → ui}/media-actions.tsx +4 -3
  82. package/src/v2/ui/motion-panel.tsx +2 -1
  83. package/src/v2/ui/parts-panel.tsx +164 -0
  84. package/src/v2/ui/pattern-library.tsx +228 -0
  85. package/src/v2/ui/placeholders.tsx +205 -0
  86. package/src/v2/ui/preset-bar.tsx +83 -0
  87. package/src/v2/ui/style-controls.tsx +65 -15
  88. package/src/v2/ui/style-supports.ts +1 -1
  89. package/src/v2/ui/style-tab.tsx +127 -41
  90. package/src/v2/ui/toolbar.tsx +59 -16
  91. package/src/v2/ui/unit-controls.tsx +88 -39
  92. package/src/locales/en/patterns.ts +0 -50
  93. package/src/locales/vi/patterns.ts +0 -50
  94. package/src/shared/patterns-kit.ts +0 -7
  95. package/src/shared/patterns-library.ts +0 -172
@@ -1,26 +1,29 @@
1
- import { blockShell, buttonWrapShell, colorCss, coverParts, spacingValue } from "@ecomcx/ecomweb-content";
2
- import { ChevronsUpDown, Columns2, Columns3, Columns4, Info, LayoutPanelLeft, Minus, MousePointerClick, PanelTop, RectangleHorizontal, Square, Table2, Image as ImageIcon } from "lucide-react";
3
- import { useEffect, useSyncExternalStore, type CSSProperties } from "react";
1
+ import { COUNTDOWN_ZONES, ICON_NAMES, ICON_PATHS, countdownParts, countdownTarget, wallInZone, blockShell, buttonIcon, buttonWrapShell, colorCss, controlsCss, coverParts, spacingValue, tabsClass } from "@ecomcx/ecomweb-content";
2
+ import { blockControls } from "../../shared/panel-store";
3
+ import { ChevronLeft, ChevronRight, Plus, ChevronsUpDown, Columns2, Columns3, Columns4, Info, LayoutPanelLeft, Minus, MousePointerClick, PanelTop, RectangleHorizontal, Square, Table2, Image as ImageIcon } from "lucide-react";
4
+ import { useEffect, useState, useSyncExternalStore, type CSSProperties } from "react";
4
5
  import { InnerBlocks } from "../canvas/block-list";
5
6
  import { withoutOverridden } from "./inline-style";
6
- import { makeBlock } from "../core/model";
7
+ import { makeBlock, type BNode } from "../core/model";
7
8
  import type { BlockEditProps, BlockType } from "../core/registry";
8
9
  import { RichText } from "../text/rich-text";
9
10
  import { BoundText, useBindingPreview } from "../ui/bindings";
10
11
  import { useEditor } from "../context";
11
- import { ButtonsTools, ColumnsTools, TableTools, addColumnTo } from "./tools";
12
- import { ColumnHandles, useActiveWithin } from "./resize";
12
+ import { ButtonLinkTool, ButtonsTools, ColumnsTools, TableTools, addColumnTo } from "./tools";
13
+ import { ColumnHandles, ContentWidthHandles, HeightHandle, PaddingHandles, useActiveWithin } from "./resize";
14
+ import { ColumnInspector, ColumnsInspector } from "./columns-inspector";
13
15
  import { layoutFor, layoutKind } from "../ui/layout-panel";
14
16
  import { normalizeStyle, type BlockStyle } from "@ecomcx/ecomweb-content";
15
- import { ToolButton } from "../ui/toolbar";
16
- import { MediaActions, useFileDrop } from "./media-actions";
17
+ import { Dropdown, MenuItem, ToolButton } from "../ui/toolbar";
18
+ import { useSiteColors } from "../ui/color-field";
19
+ import { AddItemButton, MediaPlaceholder } from "../ui/placeholders";
17
20
  import type { MediaItem } from "../../shared/types";
18
- import { LayoutGrid, Rows3, Columns3 as RowIcon } from "lucide-react";
21
+ import { LayoutGrid, Rows3, Columns3 as RowIcon, MoveHorizontal, Palette } from "lucide-react";
19
22
  import { useMsgs } from "../i18n";
20
23
 
21
24
  const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
22
25
  const PADDING: Record<string, string> = { none: "0", small: "0.75rem", medium: "1.5rem", large: "3rem" };
23
- const TONES: Record<string, string> = { info: "#2563eb", success: "#16a34a", warning: "#d97706", danger: "#dc2626" };
26
+ const TONES: Record<string, string> = { info: "#1a597b", success: "#16a34a", warning: "#d97706", danger: "#dc2626" };
24
27
  /** Gộp props của khối với class + style inline riêng; `attrs` có `style` thì bỏ phần inline mà kiểu dáng đã thay (khớp website). */
25
28
  const merge = (bp: BlockEditProps["blockProps"], className: string, style?: CSSProperties, attrs?: Record<string, unknown>) =>
26
29
  ({ ...bp, className: cx(bp.className, className), style: { ...(bp.style ?? {}), ...(attrs?.style ? withoutOverridden(style ?? {}, attrs.style) : style) } });
@@ -28,19 +31,41 @@ const merge = (bp: BlockEditProps["blockProps"], className: string, style?: CSSP
28
31
  /** Props của vỏ khối lấy từ markup dùng chung với website: thẻ-class-style-thuộc tính cố định + props của canvas (id, chọn khối). */
29
32
  const shellProps = (bp: BlockEditProps["blockProps"], type: string, attrs: Record<string, unknown>, parent?: { type: string; attrs?: Record<string, unknown> }) => {
30
33
  const sh = blockShell(type, attrs, parent)!;
31
- return { ...merge(bp, sh.className ?? "", sh.style as CSSProperties, attrs), ...sh.attrs };
34
+ // Phần nhắm chính thẻ khối (vd phần "Nút" = chính <a>) cũng gỡ inline trùng như attrs.style (khớp website)
35
+ const self = controlsCss(blockControls(), type, attrs)?.self;
36
+ return { ...merge(bp, sh.className ?? "", sh.style as CSSProperties, self ? { style: { ...self, ...(normalizeStyle(attrs.style) ?? {}) } } : attrs), ...sh.attrs };
32
37
  };
33
38
 
34
- function GroupEdit({ block, blockProps }: BlockEditProps) {
39
+ function GroupEdit({ block, blockProps, setAttrs, editable, selected }: BlockEditProps) {
40
+ const tp = useMsgs("placeholders");
41
+ const { store } = useEditor();
42
+ const style: BlockStyle = normalizeStyle(block.attrs.style) ?? {};
43
+ // Nhóm mới chèn (chưa chọn bố cục, chưa có nội dung): hỏi bố cục ngay trong khối như WordPress — đoạn văn bên trong vẫn gõ được ngay (gõ "/nhom" rồi gõ tiếp)
44
+ const kids = block.content ?? [];
45
+ const fresh = editable && !style.layout && (!kids.length || (kids.length === 1 && kids[0].type === "paragraph" && !kids[0].inline?.length));
46
+ const items: Array<["stack" | "row" | "grid", typeof Square, string]> = [["stack", Rows3, tp.layoutStack], ["row", RowIcon, tp.layoutRow], ["grid", LayoutGrid, tp.layoutGrid]];
35
47
  return (
36
- <div {...shellProps(blockProps, "group", block.attrs)}>
48
+ <div {...shellProps(blockProps, "group", block.attrs)} data-ecx-placeholder={fresh ? "layout" : undefined}>
37
49
  <InnerBlocks parent={block} />
50
+ {/* Chọn bố cục nằm dưới đoạn văn: thanh công cụ nổi của đoạn nằm phía trên, không che các nút */}
51
+ {fresh && (
52
+ <div className="ecx-media-placeholder ecx-ph-choose" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
53
+ <p className="ecx-ph-title">{tp.chooseLayout}</p>
54
+ <div className="ecx-ph-choices">
55
+ {items.map(([k, I, label]) => <button key={k} type="button" className="ecx-ph-choice" onClick={() => { setAttrs({ style: normalizeStyle({ ...style, layout: layoutFor(k) }) }); const first = kids[0]; if (first?.type === "paragraph") store.focusText(first.id, 0); }}><I className="ecx-icon" aria-hidden />{label}</button>)}
56
+ </div>
57
+ </div>
58
+ )}
59
+ {selected && editable && <PaddingHandles blockId={block.id} />}
60
+ {selected && editable && !fresh && <ContentWidthHandles blockId={block.id} />}
38
61
  </div>
39
62
  );
40
63
  }
41
64
 
42
65
  /** Thanh công cụ của nhóm: đổi nhanh Nhóm / Hàng ngang / Xếp dọc / Lưới (giữ các kiểu dáng khác). */
43
- function GroupLayoutTools({ attrs, setAttrs, labels }: BlockEditProps) {
66
+ function GroupLayoutTools({ block, attrs, setAttrs, labels }: BlockEditProps) {
67
+ const { store } = useEditor();
68
+ const colors = useSiteColors();
44
69
  const style: BlockStyle = normalizeStyle(attrs.style) ?? {};
45
70
  const kind = layoutKind(style.layout);
46
71
  const t = useMsgs("blocks");
@@ -50,21 +75,67 @@ function GroupLayoutTools({ attrs, setAttrs, labels }: BlockEditProps) {
50
75
  {items.map(([k, I, label]) => (
51
76
  <ToolButton key={k} label={label} active={kind === k} onClick={() => setAttrs({ style: normalizeStyle({ ...style, layout: layoutFor(k, style.layout) }) })}><I className="ecx-icon" /></ToolButton>
52
77
  ))}
78
+ <Dropdown label={t.contentWidth} trigger={<span className="ecx-tool-text" data-ecx-content-width={attrs.contentWidth || (attrs.constrained ? "site" : "fill")}><MoveHorizontal className="ecx-icon" /></span>}>
79
+ {(close) => ([["fill", t.cwFill], ["site", t.cwSite], ["720px", "720px"], ["960px", "960px"], ["1140px", "1140px"]] as const).map(([v, l]) => {
80
+ const cur = attrs.contentWidth || (attrs.constrained ? "site" : "fill");
81
+ return <MenuItem key={v} label={(v === cur ? "✓ " : "") + l} onClick={() => { close(); setAttrs({ constrained: v === "site" ? true : undefined, contentWidth: v.endsWith("px") ? v : undefined }); }} />;
82
+ })}
83
+ </Dropdown>
84
+ <Dropdown label={t.quickColor} trigger={<span className="ecx-tool-text"><Palette className="ecx-icon" /></span>}>
85
+ {(close) => (
86
+ <div className="ecx-quick-colors" role="group" aria-label={t.quickColor}>
87
+ {Object.entries(colors).map(([name, css]) => (
88
+ <button key={name} type="button" className="ecx-color-dot" title={name} aria-label={name} data-color={name} style={{ background: css }}
89
+ onClick={() => { close(); /* Nhóm chưa có đệm: thêm đệm vừa để chữ không dính sát mép vùng màu */ setAttrs({ style: normalizeStyle({ ...style, color: { ...style.color, background: name } }), ...(!attrs.padding && !style.padding ? { padding: "medium" } : {}) }); }} />
90
+ ))}
91
+ <button type="button" className="ecx-color-dot is-none" title={t.noColor} aria-label={t.noColor} data-color="none"
92
+ onClick={() => { close(); setAttrs({ style: normalizeStyle({ ...style, color: { ...style.color, background: undefined } }) }); }} />
93
+ </div>
94
+ )}
95
+ </Dropdown>
96
+ <ToolButton label={t.addSectionBelow} onClick={() => store.insertAfter(block.id, [makeBlock("group", {}, [makeBlock("paragraph")])], { replaceEmpty: false })}><Plus className="ecx-icon" /></ToolButton>
53
97
  </>
54
98
  );
55
99
  }
56
100
  const groupWith = (layout?: BlockStyle["layout"], kids = 1) => makeBlock("group", layout ? { style: { layout } } : {}, Array.from({ length: kids }, () => makeBlock("paragraph")));
57
101
 
58
- function ColumnsEdit({ block, blockProps, editable, labels }: BlockEditProps) {
102
+ /** Bố cục cột cho lưới chọn khi vừa chèn Bộ cột (0 = chia đều). */
103
+ const COLUMN_LAYOUTS: number[][] = [[100], [0, 0], [67, 33], [33, 67], [0, 0, 0], [50, 25, 25], [25, 25, 50], [25, 50, 25], [20, 60, 20], [0, 0, 0, 0], [40, 20, 20, 20], [20, 20, 20, 40], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]];
104
+ const layoutName = (w: number[]) => w.map((x) => (x || Math.round(100 / w.length))).join(" / ");
105
+
106
+ function ColumnsEdit({ block, blockProps, editable, labels, selected }: BlockEditProps) {
59
107
  const { store } = useEditor();
60
108
  const t = useMsgs("blocks");
109
+ const tp = useMsgs("placeholders");
61
110
  const a = block.attrs;
62
111
  const active = useActiveWithin(block.id);
63
112
  const shell = blockShell("columns", a)!; // vỏ dùng chung với website (@ecomcx/ecomweb-content)
113
+ const pick = (widths: number[]) => {
114
+ const cols = widths.map((w) => makeBlock("column", w && widths.length > 1 ? { width: w } : {}, [makeBlock("paragraph")]));
115
+ const first = cols[0].content![0].id;
116
+ store.replace(block.id, [{ ...block, content: cols }], { select: { ids: [], editing: first }, caret: { id: first, offset: 0 } });
117
+ };
118
+ // Lệnh chèn "Bộ cột" tạo khối chưa có cột: hỏi bố cục ngay trên khung soạn (biến thể 50 / 50… đã có cột thì không hỏi)
119
+ if (editable && !block.content?.length) return (
120
+ <div {...merge(blockProps, "", undefined, block.attrs)} data-ecx-placeholder="columns">
121
+ <div className="ecx-media-placeholder ecx-ph-choose" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
122
+ <p className="ecx-ph-title">{tp.chooseColumns}</p>
123
+ <div className="ecx-col-layouts">
124
+ {COLUMN_LAYOUTS.map((w) => (
125
+ <button key={w.join("-")} type="button" className="ecx-col-layout" aria-label={layoutName(w)} title={layoutName(w)} onClick={() => pick(w)}>
126
+ {w.map((x, i) => <span key={i} style={{ flexGrow: x || 1 }} />)}
127
+ </button>
128
+ ))}
129
+ </div>
130
+ <button type="button" className="ecx-ph-skip" onClick={() => pick([0, 0])}>{tp.skip}</button>
131
+ </div>
132
+ </div>
133
+ );
64
134
  return (
65
135
  <div {...merge(blockProps, shell.className!, shell.style as CSSProperties, block.attrs)}>
66
136
  <InnerBlocks parent={block} appender="none" />
67
137
  {active && editable && block.content!.length > 1 && <ColumnHandles block={block} />}
138
+ {selected && editable && <PaddingHandles blockId={block.id} />}
68
139
  {active && editable && block.content!.length < 6 && store.canInsertInto(block.id) && (
69
140
  <button type="button" className="ecx-add-column" contentEditable={false} title={t.addColumn} aria-label={t.addColumn}
70
141
  onMouseDown={(e) => { e.preventDefault(); e.stopPropagation(); }} onClick={() => addColumnTo(store, block)}>+</button>
@@ -73,13 +144,14 @@ function ColumnsEdit({ block, blockProps, editable, labels }: BlockEditProps) {
73
144
  );
74
145
  }
75
146
 
76
- function ColumnEdit({ block, blockProps }: BlockEditProps) {
147
+ function ColumnEdit({ block, blockProps, selected, editable }: BlockEditProps) {
77
148
  const { store } = useEditor();
78
149
  const parent = store.locate(block.id)?.parent;
79
150
  const shell = blockShell("column", block.attrs, parent ? { type: parent.type, attrs: parent.attrs } : undefined)!;
80
151
  return (
81
152
  <div {...merge(blockProps, shell.className!, shell.style as CSSProperties, block.attrs)}>
82
153
  <InnerBlocks parent={block} />
154
+ {selected && editable && <PaddingHandles blockId={block.id} />}
83
155
  </div>
84
156
  );
85
157
  }
@@ -88,15 +160,22 @@ function ButtonsEdit({ block, blockProps }: BlockEditProps) {
88
160
  return <div {...shellProps(blockProps, "buttons", block.attrs)}><InnerBlocks parent={block} appender="none" /></div>;
89
161
  }
90
162
 
91
- function ButtonEdit({ block, blockProps, setAttrs, editable, labels }: BlockEditProps) {
163
+ function ButtonEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
92
164
  const { store } = useEditor();
165
+ const tp = useMsgs("placeholders");
93
166
  const a = block.attrs;
94
167
  const bound = useBindingPreview(block, "text");
95
168
  const inGroup = store.locate(block.id)?.parent?.type === "buttons";
169
+ // Icon của nút (content buttonIcon — cùng svg với website)
170
+ const ic = buttonIcon(a);
171
+ const icon = ic && <svg className="ecx-widget-icon" viewBox="0 0 24 24" width={24} height={24} fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d={String((ic.children?.[0] as { props?: { d?: string } })?.props?.d ?? "")} /></svg>;
96
172
  // Website: nút đứng riêng nằm trong đoạn <p class="ecx-buttons"> (căn lề); trong khối "buttons" thì là chính thẻ <a>
97
173
  const link = (
98
174
  <a {...shellProps(inGroup ? blockProps : ({} as BlockEditProps["blockProps"]), "button", a)} onClick={(e) => e.preventDefault()}>
99
- {bound.bound ? <BoundText preview={bound} /> : <RichText blockId={block.id} field="text" tagName="span" value={String(a.text ?? "")} onChange={(v) => setAttrs({ text: v })} placeholder={labels.buttonText} placeholderAlways editable={editable} />}
175
+ {icon && (a.iconPosition !== "right" || a.iconOnly === true) && icon}
176
+ {/* Chỉ icon: chữ sửa ở ô "Chữ" bên phải (thành nhãn cho trình đọc màn hình) */}
177
+ {icon && a.iconOnly === true ? null : bound.bound ? <BoundText preview={bound} /> : <RichText blockId={block.id} field="text" tagName="span" value={String(a.text ?? "")} onChange={(v) => setAttrs({ text: v })} placeholder={tp.buttonText} placeholderAlways editable={editable} />}
178
+ {icon && a.iconPosition === "right" && a.iconOnly !== true && icon}
100
179
  </a>
101
180
  );
102
181
  if (inGroup) return link;
@@ -104,8 +183,12 @@ function ButtonEdit({ block, blockProps, setAttrs, editable, labels }: BlockEdit
104
183
  return <p {...merge(blockProps, wrap.className ?? "", wrap.style as CSSProperties)}>{link}</p>;
105
184
  }
106
185
 
107
- function SpacerEdit({ block, blockProps }: BlockEditProps) {
108
- return <div {...shellProps(blockProps, "spacer", block.attrs)} />;
186
+ function SpacerEdit({ block, blockProps, selected, editable }: BlockEditProps) {
187
+ const tp = useMsgs("placeholders");
188
+ const props = shellProps(blockProps, "spacer", block.attrs);
189
+ const h = props.style?.height ?? block.attrs.height;
190
+ // Nhãn kích thước chỉ trong trình soạn (CSS ::before, không thêm phần tử con — website là div rỗng)
191
+ return <div {...props} data-ecx-size={tp.spacer.replace("{size}", String(h ?? ""))}>{selected && editable && <HeightHandle blockId={block.id} />}</div>;
109
192
  }
110
193
 
111
194
  function SeparatorEdit({ blockProps }: BlockEditProps) {
@@ -113,30 +196,43 @@ function SeparatorEdit({ blockProps }: BlockEditProps) {
113
196
  }
114
197
 
115
198
  function CalloutEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
116
- const active = useActiveWithin(block.id);
199
+ const tp = useMsgs("placeholders");
117
200
  const title = String(block.attrs.title ?? "");
118
201
  return (
119
202
  <div {...shellProps(blockProps, "callout", block.attrs)}>
120
- {/* website chỉ in tiêu đề khi có chữ: canvas chỉ hiện ô tiêu đề trống lúc đang chọn khối */}
121
- {(title || (active && editable)) && <RichText blockId={block.id} field="title" tagName="p" className="ecx-callout-title cms-callout-title" style={{ margin: 0, fontWeight: 600 }} value={title} onChange={(v) => setAttrs({ title: v })} placeholder="…" editable={editable} />}
203
+ {/* website chỉ in tiêu đề khi có chữ: trình soạn luôn có ô tiêu đề (gợi ý "không bắt buộc") để thấy chỗ gõ */}
204
+ {(title || editable) && <RichText blockId={block.id} field="title" tagName="p" className="ecx-callout-title cms-callout-title" style={{ margin: 0, fontWeight: 600 }} value={title} onChange={(v) => setAttrs({ title: v })} placeholder={tp.calloutTitle} placeholderAlways editable={editable} />}
122
205
  <InnerBlocks parent={block} />
123
206
  </div>
124
207
  );
125
208
  }
126
209
 
127
210
  function DetailsEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
211
+ const tp = useMsgs("placeholders");
128
212
  return (
129
213
  <details {...(merge(blockProps, "ecx-details") as object)} open>
130
214
  <summary onClick={(e) => e.preventDefault()}>
131
- <RichText blockId={block.id} field="summary" tagName="span" value={String(block.attrs.summary ?? "")} onChange={(v) => setAttrs({ summary: v })} placeholder="…" placeholderAlways editable={editable} />
215
+ <RichText blockId={block.id} field="summary" tagName="span" value={String(block.attrs.summary ?? "")} onChange={(v) => setAttrs({ summary: v })} placeholder={tp.detailsSummary} placeholderAlways editable={editable} />
132
216
  </summary>
133
217
  <InnerBlocks parent={block} />
134
218
  </details>
135
219
  );
136
220
  }
137
221
 
138
- function AccordionEdit({ block, blockProps }: BlockEditProps) {
139
- return <div {...(merge(blockProps, "ecx-accordion") as object)}><InnerBlocks parent={block} /></div>;
222
+ /** Nút "+ Thêm …" cuối khối chứa nhiều mục (accordion, carousel): chỉ khi đang thao tác trong khối. */
223
+ function AddChild({ block, label, make }: { block: BlockEditProps["block"]; label: string; make(): ReturnType<typeof makeBlock> }) {
224
+ const { store } = useEditor();
225
+ const active = useActiveWithin(block.id);
226
+ const loc = store.locate(block.id);
227
+ if (!active || !loc || !store.canInsertInto(block.id)) return null;
228
+ return <AddItemButton label={label} onClick={() => { const b = make(); store.insert(loc.docId, block.id, block.content?.length ?? 0, [b]); }} />;
229
+ }
230
+
231
+ function AccordionEdit({ block, blockProps, editable }: BlockEditProps) {
232
+ const tp = useMsgs("placeholders");
233
+ const a = block.attrs;
234
+ const cls = cx("ecx-accordion", Number(a.columns) === 2 && "is-cols-2", `has-icon-${["plus", "none"].includes(String(a.icon)) ? a.icon : "arrow"}`, a.iconSide === "left" && "is-icon-left");
235
+ return <div {...(merge(blockProps, cls) as object)}><InnerBlocks parent={block} />{editable && <AddChild block={block} label={tp.addItem} make={() => makeBlock("details", { summary: "" }, [makeBlock("paragraph")])} />}</div>;
140
236
  }
141
237
 
142
238
  /** Thẻ đang mở của từng khối tabs trên khung soạn (không lưu vào nội dung — website luôn mở thẻ đầu). */
@@ -148,23 +244,60 @@ const useOpenTab = (id: string) => useSyncExternalStore((l) => { tabListeners.ad
148
244
  /** Tabs như website (TabsClient): thanh tiêu đề (vai trò tablist / tab) + một thẻ hiện; tiêu đề gõ ngay trên thanh, trống = "Tab N". */
149
245
  function TabsEdit({ block, blockProps, editable }: BlockEditProps) {
150
246
  const { store } = useEditor();
151
- const t = useMsgs("blockStyle");
247
+ const tp = useMsgs("placeholders");
152
248
  const active = useOpenTab(block.id);
153
249
  const tabs = (block.content ?? []).filter((c) => c.type === "tab");
154
250
  return (
155
- <div {...(merge(blockProps, "ecx-tabs") as object)}>
156
- <div role="tablist" className="ecx-tabs-list">
157
- {tabs.map((tab, i) => (
158
- <div key={tab.id} role="tab" aria-selected={i === active} tabIndex={-1} className={cx("ecx-tab-button", i === active && "is-active")} onMouseDown={() => setOpenTab(block.id, i)}>
159
- <RichText blockId={tab.id} field="title" tagName="span" value={String(tab.attrs.title ?? "")} onChange={(v) => store.setAttrs([tab.id], { title: v })} placeholder={t.tabTitle.replace("{n}", String(i + 1))} placeholderAlways editable={editable} />
160
- </div>
161
- ))}
251
+ <div {...(merge(blockProps, tabsClass(block.attrs)) as object)}>
252
+ <div role="tablist" className="ecx-tabs-list" aria-orientation={block.attrs.orientation === "vertical" ? "vertical" : undefined}>
253
+ {tabs.map((tab, i) => {
254
+ const icon = ICON_PATHS[String(tab.attrs.icon ?? "")];
255
+ return (
256
+ <div key={tab.id} role="tab" aria-selected={i === active} tabIndex={-1} className={cx("ecx-tab-button", i === active && "is-active")} style={{ "--i": i } as CSSProperties} onMouseDown={() => setOpenTab(block.id, i)}>
257
+ {icon && <svg className="ecx-tab-icon" viewBox="0 0 24 24" width={18} height={18} fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d={icon} /></svg>}
258
+ <span className="ecx-tab-label">
259
+ <RichText blockId={tab.id} field="title" tagName="span" value={String(tab.attrs.title ?? "")} onChange={(v) => store.setAttrs([tab.id], { title: v })} placeholder={tp.tabTitle} placeholderAlways editable={editable} />
260
+ {!!tab.attrs.subtitle && <small className="ecx-tab-subtitle">{String(tab.attrs.subtitle)}</small>}
261
+ </span>
262
+ </div>
263
+ );
264
+ })}
265
+ {/* Nút thêm tab nằm ngay trên hàng tab */}
266
+ {editable && store.canInsertInto(block.id) && <AddItemButton label={tp.addTab} onClick={() => {
267
+ const loc = store.locate(block.id);
268
+ if (!loc) return;
269
+ store.insert(loc.docId, block.id, block.content?.length ?? 0, [makeBlock("tab", { title: "" }, [makeBlock("paragraph")])]);
270
+ setOpenTab(block.id, tabs.length);
271
+ }} />}
162
272
  </div>
163
273
  <InnerBlocks parent={block} />
164
274
  </div>
165
275
  );
166
276
  }
167
277
 
278
+ /** Thanh công cụ khi đang ở trong Tabs: dời tab đang mở sang trái / phải, thêm tab. */
279
+ function TabsTools({ ancestor }: { ancestor: BNode; currentId: string }) {
280
+ const { store } = useEditor();
281
+ const tp = useMsgs("placeholders");
282
+ const open = useOpenTab(ancestor.id);
283
+ const tabs = (ancestor.content ?? []).filter((c) => c.type === "tab");
284
+ const cur = tabs[open];
285
+ const move = (dir: -1 | 1) => { if (!cur) return; store.moveBy([cur.id], dir); setOpenTab(ancestor.id, open + dir); };
286
+ const canEdit = store.canInsertInto(ancestor.id);
287
+ return (
288
+ <>
289
+ <ToolButton label={tp.moveTabLeft} disabled={!canEdit || open <= 0} onClick={() => move(-1)}><ChevronLeft className="ecx-icon" /></ToolButton>
290
+ <ToolButton label={tp.moveTabRight} disabled={!canEdit || open >= tabs.length - 1} onClick={() => move(1)}><ChevronRight className="ecx-icon" /></ToolButton>
291
+ <ToolButton label={tp.addTab} disabled={!canEdit} onClick={() => {
292
+ const loc = store.locate(ancestor.id);
293
+ if (!loc) return;
294
+ store.insert(loc.docId, ancestor.id, ancestor.content?.length ?? 0, [makeBlock("tab", { title: "" }, [makeBlock("paragraph")])], { focus: false });
295
+ setOpenTab(ancestor.id, tabs.length);
296
+ }}><Plus className="ecx-icon" /></ToolButton>
297
+ </>
298
+ );
299
+ }
300
+
168
301
  function TabEdit({ block, blockProps }: BlockEditProps) {
169
302
  const { store } = useEditor();
170
303
  const loc = store.locate(block.id);
@@ -175,30 +308,99 @@ function TabEdit({ block, blockProps }: BlockEditProps) {
175
308
  // Chọn khối nằm trong thẻ đang ẩn (danh sách khối, tìm kiếm…) → mở thẻ đó
176
309
  useEffect(() => { if (within && !open && parentId) setOpenTab(parentId, index); }, [within, open, parentId, index]);
177
310
  return (
178
- <div {...(merge(blockProps, "ecx-tab ecx-tab-panel", open ? undefined : { display: "none" }) as object)} role="tabpanel">
311
+ <div {...(merge(blockProps, "ecx-tab ecx-tab-panel", { "--i": index, ...(open ? {} : { display: "none" }) } as CSSProperties) as object)} role="tabpanel">
179
312
  <InnerBlocks parent={block} />
180
313
  </div>
181
314
  );
182
315
  }
183
316
 
184
- function CarouselEdit({ block, blockProps }: BlockEditProps) {
185
- return <div {...(merge(blockProps, "ecx-carousel") as object)}><InnerBlocks parent={block} /></div>;
317
+ function CarouselEdit({ block, blockProps, editable }: BlockEditProps) {
318
+ const tp = useMsgs("placeholders");
319
+ return <div {...(merge(blockProps, "ecx-carousel") as object)}><InnerBlocks parent={block} />{editable && <AddChild block={block} label={tp.addSlide} make={() => makeBlock("group", {}, [makeBlock("paragraph")])} />}</div>;
186
320
  }
187
321
 
188
- function ShortcodeEdit({ block, blockProps }: BlockEditProps) {
189
- return <div {...(merge(blockProps, "ecx-shortcode", { fontFamily: "monospace", opacity: 0.8 }) as object)}>[{String(block.attrs.name || "shortcode")}]</div>;
322
+ /** Shortcode: ô nhập tên luôn hiện ngay trên khối. */
323
+ function ShortcodeEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
324
+ const tp = useMsgs("placeholders");
325
+ const name = String(block.attrs.name ?? "");
326
+ if (!editable) return <div {...(merge(blockProps, "ecx-shortcode", { fontFamily: "monospace", opacity: 0.8 }) as object)}>[{name || "shortcode"}]</div>;
327
+ return (
328
+ <div {...(merge(blockProps, "ecx-shortcode ecx-media-placeholder ecx-ph-inline") as object)} data-ecx-placeholder="shortcode">
329
+ <label className="ecx-ph-row" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
330
+ <span className="ecx-ph-mono" aria-hidden>[ ]</span>
331
+ <span className="ecx-ph-label">{tp.shortcodeName}</span>
332
+ <input className="ecx-input ecx-ph-mono" value={name} placeholder="shortcode" onChange={(e) => setAttrs({ name: e.target.value.replace(/[^\w-]/g, "") || undefined })} />
333
+ </label>
334
+ </div>
335
+ );
190
336
  }
191
337
 
192
- function CountdownEdit({ block, blockProps, labels }: BlockEditProps) {
338
+ const pad2 = (n: number) => String(n).padStart(2, "0");
339
+ /** ISO / chuỗi ngày → giá trị ô datetime-local (giờ máy). */
340
+ const toLocalInput = (v: unknown) => { const d = new Date(String(v ?? "")); return Number.isFinite(d.getTime()) ? `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}T${pad2(d.getHours())}:${pad2(d.getMinutes())}` : ""; };
341
+
342
+ function CountdownEdit({ block, blockProps, setAttrs, editable, labels }: BlockEditProps) {
193
343
  const a = block.attrs;
194
- // Thiếu / sai thời điểm: website không vẽ khối → trong trình soạn nói rõ, không để khối "mất tích" im lặng
195
- if (!Number.isFinite(Date.parse(String(a.target ?? "")))) return <div {...(merge(blockProps, "ecx-countdown ecx-placeholder-block", {}) as object)}>{a.label ? <strong>{String(a.label)}</strong> : null}<span>{labels.countdownNoTarget}</span></div>;
196
- return <div {...(merge(blockProps, "ecx-countdown", { textAlign: "center" }) as object)}>{a.label ? <p style={{ margin: 0 }}>{String(a.label)}</p> : null}<strong>{String(a.target)}</strong></div>;
344
+ const tp = useMsgs("placeholders");
345
+ const valid = Number.isFinite(countdownTarget(a));
346
+ const tz = typeof a.timezone === "string" && a.timezone ? a.timezone : "";
347
+ const active = useActiveWithin(block.id);
348
+ // Chọn ngày giờ ngay trong khối (thiếu / sai thời điểm: website không vẽ khối → nói rõ, không để khối "mất tích" im lặng)
349
+ if (!valid || (editable && active)) return (
350
+ <div {...(merge(blockProps, "ecx-countdown ecx-media-placeholder", {}) as object)} data-ecx-placeholder="countdown">
351
+ <span className="ecx-ph-digits" aria-hidden>00 : 00 : 00 : 00</span>
352
+ {editable && <label className="ecx-ph-row" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
353
+ <span className="ecx-ph-label">{tp.countdownTarget}</span>
354
+ <input className="ecx-input" type="datetime-local" value={tz ? String(a.target ?? "").slice(0, 16) : toLocalInput(a.target)}
355
+ onChange={(e) => setAttrs({ target: e.target.value ? (tz ? e.target.value : new Date(e.target.value).toISOString()) : undefined })} />
356
+ </label>}
357
+ {editable && <label className="ecx-ph-row" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
358
+ <span className="ecx-ph-label">{tp.countdownZone}</span>
359
+ <select className="ecx-input" aria-label={tp.countdownZone} value={tz} onChange={(e) => {
360
+ const next = e.target.value, ms = countdownTarget(a);
361
+ // Đổi múi giờ giữ nguyên thời điểm đã đặt: giờ tường mới (hoặc ISO của máy khi về "Theo máy người xem")
362
+ setAttrs({ timezone: next || undefined, ...(Number.isFinite(ms) ? { target: next ? wallInZone(ms, next) : new Date(ms).toISOString() } : {}) });
363
+ }}>
364
+ <option value="">{tp.countdownZoneLocal}</option>
365
+ {COUNTDOWN_ZONES.map((z) => <option key={z} value={z}>{z}</option>)}
366
+ </select>
367
+ </label>}
368
+ {!valid && <p className="ecx-placeholder-hint">{labels.countdownNoTarget}</p>}
369
+ </div>
370
+ );
371
+ return <CountdownPreview block={block} blockProps={blockProps} />;
372
+ }
373
+
374
+ /** Đếm ngược chạy thật như website (cùng countdownParts + markup), nhãn đơn vị theo ngôn ngữ trình soạn. */
375
+ function CountdownPreview({ block, blockProps }: Pick<BlockEditProps, "block" | "blockProps">) {
376
+ const a = block.attrs;
377
+ const tp = useMsgs("placeholders");
378
+ const [now, setNow] = useState(() => Date.now());
379
+ useEffect(() => { const id = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(id); }, []);
380
+ const left = Math.max(0, countdownTarget(a) - now);
381
+ const cls = cx("ecx-countdown", a.layout === "inline" && "is-inline", a.divider === true && "has-divider");
382
+ if (left === 0 && a.expiredText) return <div {...(merge(blockProps, "ecx-countdown is-expired") as object)}>{String(a.expiredText)}</div>;
383
+ return (
384
+ <div {...(merge(blockProps, cls) as object)} role="timer">
385
+ {a.label ? <p className="ecx-countdown-label">{String(a.label)}</p> : null}
386
+ <div className="ecx-countdown-parts">{countdownParts(a, left, { d: tp.cdDays, h: tp.cdHours, m: tp.cdMinutes, s: tp.cdSeconds }).map((p) => <span key={p.u} className={`ecx-countdown-${p.u}`}><strong>{p.value}</strong><small>{p.label}</small></span>)}</div>
387
+ {a.postText ? <p className="ecx-countdown-post">{String(a.postText)}</p> : null}
388
+ </div>
389
+ );
197
390
  }
198
391
 
199
- function RatingEdit({ block, blockProps }: BlockEditProps) {
392
+ /** Sao xám → bấm vào sao để chấm ngay trên khối. */
393
+ function RatingEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
394
+ const tp = useMsgs("placeholders");
200
395
  const max = Math.min(10, Math.max(1, Number(block.attrs.max) || 5)), v = Number(block.attrs.value) || 0;
201
- return <div {...(merge(blockProps, "ecx-rating") as object)} aria-label={`${v}/${max}`}>{Array.from({ length: max }, (_, i) => <span key={i} style={{ color: i < Math.round(v) ? "#f59e0b" : "#d4d4d8" }}>★</span>)}</div>;
396
+ return (
397
+ <div {...(merge(blockProps, "ecx-rating") as object)} aria-label={`${v}/${max}`} title={editable ? tp.rateHint : undefined} data-ecx-placeholder={editable && !v ? "rating" : undefined}>
398
+ {Array.from({ length: max }, (_, i) => editable
399
+ ? <button key={i} type="button" className="ecx-ph-star" contentEditable={false} aria-label={tp.rateStar.replace("{n}", String(i + 1))} aria-pressed={i < Math.round(v)} onMouseDown={(e) => e.stopPropagation()} onClick={() => setAttrs({ value: i + 1 })} style={{ color: i < Math.round(v) ? "#f59e0b" : "#d4d4d8" }}>★</button>
400
+ : <span key={i} style={{ color: i < Math.round(v) ? "#f59e0b" : "#d4d4d8" }}>★</span>)}
401
+ {editable && !v && <span className="ecx-placeholder-hint" contentEditable={false}>{tp.rateHint}</span>}
402
+ </div>
403
+ );
202
404
  }
203
405
 
204
406
  function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
@@ -206,23 +408,21 @@ function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
206
408
  const src = typeof a.src === "string" ? a.src : "";
207
409
  const { host } = useEditor();
208
410
  const select = (items: MediaItem[]) => setAttrs({ src: items[0].url, alt: items[0].alt || undefined, mediaId: items[0].id });
209
- const drop = useFileDrop("image", select);
210
411
  const t = useMsgs("blocks"); // hook phải gọi trước mọi return sớm: chọn ảnh/màu làm đổi nhánh render
412
+ const tp = useMsgs("placeholders");
211
413
  // Chưa có ảnh lẫn màu: chỗ chọn ảnh nền hoặc màu nền (không để khối trắng trơn vô hình)
212
414
  const st = normalizeStyle(a.style);
213
415
  if (!src && !a.overlay && !st?.color?.background && !st?.gradient && !st?.background?.image) {
214
- return (
215
- <div {...merge(blockProps, cx("ecx-media-placeholder ecx-cover-placeholder", drop.over && "is-drop-target"))} {...drop.props}>
216
- <span className="ecx-placeholder-title"><ImageIcon className="ecx-icon" />{t.cover}</span>
217
- <p className="ecx-placeholder-hint">{t.pickABackgroundImage}</p>
218
- <MediaActions kind="image" onSelect={select} onUrl={(url) => setAttrs({ src: url })} />
219
- <div className="ecx-chip-row" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
220
- {Object.entries(host.presets?.colors ?? { primary: "#1a597b", black: "#111", muted: "#757575" }).map(([name, c]) => (
221
- <button key={name} type="button" className="ecx-chip ecx-chip-swatch" title={name} aria-label={`${t.background}: ${name}`} style={{ background: c }} onClick={() => setAttrs({ overlay: name, opacity: 100 })} />
222
- ))}
223
- </div>
224
- </div>
416
+ // Ảnh hoặc chỉ cần màu nền (không bắt buộc ảnh)
417
+ const colors = (
418
+ <span className="ecx-chip-row" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
419
+ <span className="ecx-ph-label">{t.background}</span>
420
+ {Object.entries(host.presets?.colors ?? { primary: "#1a597b", black: "#111", muted: "#757575" }).map(([name, c]) => (
421
+ <button key={name} type="button" className="ecx-chip ecx-chip-swatch" title={name} aria-label={`${t.background}: ${name}`} style={{ background: c }} onClick={() => setAttrs({ overlay: name, opacity: 100 })} />
422
+ ))}
423
+ </span>
225
424
  );
425
+ return <MediaPlaceholder kind="image" blockProps={merge(blockProps, "ecx-cover-placeholder") as BlockEditProps["blockProps"]} title={tp.dropCover} onSelect={select} onUrl={(url) => setAttrs({ src: url })} extra={colors} />;
226
426
  }
227
427
  const { overlay, fixed, imgStyle, overlayStyle } = coverParts(a);
228
428
  return (
@@ -235,6 +435,7 @@ function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
235
435
  }
236
436
 
237
437
  function MediaTextEdit({ block, blockProps }: BlockEditProps) {
438
+ // Ô ảnh rỗng = vùng thả lớn (cùng kiểu ô thả với khối Ảnh)
238
439
  const a = block.attrs;
239
440
  return (
240
441
  <div {...shellProps(blockProps, "mediaText", a)}>
@@ -244,21 +445,37 @@ function MediaTextEdit({ block, blockProps }: BlockEditProps) {
244
445
  );
245
446
  }
246
447
 
247
- /** Ô chọn ảnh dùng chung (ảnh bìa, ảnh + chữ). */
248
- /** Chỗ chọn ảnh trong khối (ảnh + chữ…): tải lên / thư viện / URL, kéo thả tệp. */
249
- export function MediaPick({ blockId }: { blockId: string }) {
250
- const { store, labels } = useEditor();
448
+ /** Chỗ chọn ảnh trong khối (ảnh + chữ, hộp ảnh, lời chứng thực…): vùng thả + Tải lên / Thư viện / URL. */
449
+ export function MediaPick({ blockId, compact }: { blockId: string; compact?: boolean }) {
450
+ const { store } = useEditor();
251
451
  const select = (items: MediaItem[]) => store.setAttrs([blockId], { src: items[0].url, alt: items[0].alt || undefined, mediaId: items[0].id });
252
- const drop = useFileDrop("image", select);
452
+ return <MediaPlaceholder kind="image" compact={compact} className="ecx-media-pick" onSelect={select} onUrl={(url) => store.setAttrs([blockId], { src: url })} />;
453
+ }
454
+
455
+ /** Bảng mới chèn: hỏi số cột / hàng trước (thay cho bảng trống cỡ cố định). */
456
+ function TableSetup({ block, blockProps }: BlockEditProps) {
457
+ const { store } = useEditor();
458
+ const tp = useMsgs("placeholders");
459
+ const create = (cols: number, rows: number) => {
460
+ const c = Math.min(12, Math.max(1, cols || 2)), r = Math.min(50, Math.max(1, rows || 2));
461
+ const content = Array.from({ length: r }, (_, i) => makeBlock("tableRow", {}, Array.from({ length: c }, () => cell(i === 0 && r > 1))));
462
+ store.replace(block.id, [{ ...block, content }], { select: { ids: [], editing: content[0].content![0].content![0].id }, caret: { id: content[0].content![0].content![0].id, offset: 0 } });
463
+ };
253
464
  return (
254
- <div className={cx("ecx-media-placeholder ecx-media-pick", drop.over && "is-drop-target")} {...drop.props}>
255
- <span className="ecx-placeholder-title"><ImageIcon className="ecx-icon" />{labels.image}</span>
256
- <MediaActions kind="image" compact onSelect={select} onUrl={(url) => store.setAttrs([blockId], { src: url })} />
465
+ <div {...merge(blockProps, "ecx-table ecx-media-placeholder ecx-ph-table")} data-ecx-placeholder="table">
466
+ <p className="ecx-ph-title"><Table2 className="ecx-icon" aria-hidden />{tp.createTable}</p>
467
+ <form className="ecx-ph-row" contentEditable={false} onMouseDown={(e) => e.stopPropagation()} onSubmit={(e) => { e.preventDefault(); const f = new FormData(e.currentTarget); create(Number(f.get("cols")), Number(f.get("rows"))); }}>
468
+ <label className="ecx-ph-field"><span className="ecx-ph-label">{tp.columns}</span><input className="ecx-input" name="cols" type="number" min={1} max={12} defaultValue={2} /></label>
469
+ <label className="ecx-ph-field"><span className="ecx-ph-label">{tp.rows}</span><input className="ecx-input" name="rows" type="number" min={1} max={50} defaultValue={2} /></label>
470
+ <button type="submit" className="ecx-btn ecx-btn-primary">{tp.create}</button>
471
+ </form>
257
472
  </div>
258
473
  );
259
474
  }
260
475
 
261
- function TableEdit({ block, blockProps }: BlockEditProps) {
476
+ function TableEdit(props: BlockEditProps) {
477
+ const { block, blockProps } = props;
478
+ if (!block.content?.length && props.editable) return <TableSetup {...props} />;
262
479
  return (
263
480
  <div {...merge(blockProps, "ecx-table table-wrap")}>
264
481
  <table className={block.attrs.fixed ? "is-fixed" : undefined}><tbody><InnerBlocks parent={block} appender="none" /></tbody></table>
@@ -274,7 +491,8 @@ function CellEdit({ block, blockProps }: BlockEditProps) {
274
491
  return <Tag {...(blockProps as object)} colSpan={span(block.attrs.colspan)} rowSpan={span(block.attrs.rowspan)}><InnerBlocks parent={block} appender="none" /></Tag>;
275
492
  }
276
493
 
277
- const col = (width?: number) => makeBlock("column", width ? { width } : {}, [makeBlock("paragraph")]);
494
+ // Cột mới chèn để trống (nút "+ Thêm khối" giữa cột); cột đều không đặt `width` (website chia đều), cột lệch đặt % thật (33 / 67)
495
+ const col = (width?: number) => makeBlock("column", width ? { width } : {}, []);
278
496
  const columns = (...widths: number[]) => makeBlock("columns", {}, widths.map((w) => col(w)));
279
497
  const cell = (header = false) => makeBlock(header ? "tableHeader" : "tableCell", {}, [makeBlock("paragraph")]);
280
498
 
@@ -282,7 +500,7 @@ export function layoutBlocks(): BlockType[] {
282
500
  return [
283
501
  {
284
502
  name: "group", title: "Nhóm", icon: Square, category: "design", keywords: "nhom group khung section container", kind: "container", edit: GroupEdit,
285
- attributes: { background: { type: "string", control: "color" }, textColor: { type: "string", control: "color" }, padding: { type: "string", enum: ["none", "small", "medium", "large"], default: "medium" }, constrained: { type: "boolean", default: false } },
503
+ attributes: { background: { type: "string", control: "color" }, textColor: { type: "string", control: "color" }, padding: { type: "string", enum: ["none", "small", "medium", "large"], default: "medium" }, constrained: { type: "boolean", default: false, control: "hidden" }, contentWidth: { type: "string", control: "hidden" } },
286
504
  create: (attrs) => makeBlock("group", attrs ?? {}, [makeBlock("paragraph")]),
287
505
  toolbar: GroupLayoutTools,
288
506
  variations: [
@@ -295,28 +513,31 @@ export function layoutBlocks(): BlockType[] {
295
513
  },
296
514
  {
297
515
  name: "columns", title: "Cột", icon: Columns2, category: "design", keywords: "cot columns bo cuc layout", kind: "container", edit: ColumnsEdit,
298
- attributes: { verticalAlign: { type: "string", enum: ["top", "center", "bottom"] }, stack: { type: "boolean", default: true } },
299
- create: () => columns(1, 1), contextToolbar: ColumnsTools,
516
+ // Cài đặt vẽ ở ColumnsInspector (số cột, bố cục theo khổ, khe, căn dọc) — ô tự sinh ẩn
517
+ attributes: { verticalAlign: { type: "string", enum: ["top", "center", "bottom", "stretch"], control: "hidden" }, stack: { type: "boolean", default: true, control: "hidden" } },
518
+ create: () => columns(), contextToolbar: ColumnsTools, inspector: ColumnsInspector,
300
519
  variations: [
301
- { name: "50-50", title: "50 / 50", icon: Columns2, create: () => columns(1, 1) },
302
- { name: "33-33-33", title: "33 / 33 / 33", icon: Columns3, create: () => columns(1, 1, 1) },
520
+ { name: "50-50", title: "50 / 50", icon: Columns2, create: () => columns(0, 0) },
521
+ { name: "33-33-33", title: "33 / 33 / 33", icon: Columns3, create: () => columns(0, 0, 0) },
303
522
  { name: "33-66", title: "33 / 66", icon: LayoutPanelLeft, create: () => columns(33, 67) },
304
523
  { name: "66-33", title: "66 / 33", icon: LayoutPanelLeft, create: () => columns(67, 33) },
305
- { name: "25x4", title: "25 / 25 / 25 / 25", icon: Columns4, create: () => columns(1, 1, 1, 1) },
524
+ { name: "25x4", title: "25 / 25 / 25 / 25", icon: Columns4, create: () => columns(0, 0, 0, 0) },
306
525
  ],
307
526
  supports: { style: true, anchor: true, className: true },
308
527
  },
309
- { name: "column", title: "Cột", icon: RectangleHorizontal, kind: "container", edit: ColumnEdit, hidden: true, attributes: { width: { type: "number", min: 1, max: 100 } }, create: () => col(), supports: { style: true } },
528
+ { name: "column", title: "Cột", icon: RectangleHorizontal, kind: "container", edit: ColumnEdit, inspector: ColumnInspector, hidden: true, attributes: { width: { type: "number", min: 1, max: 100, control: "hidden" }, href: { type: "url", control: "hidden" }, linkTarget: { type: "string", enum: ["_self", "_blank"], control: "hidden" }, linkLabel: { type: "string", control: "hidden" } }, create: () => col(), supports: { style: true } },
310
529
  {
311
530
  name: "buttons", title: "Nút", icon: MousePointerClick, category: "design", keywords: "nut button cta lien ket", kind: "container", edit: ButtonsEdit,
312
- attributes: { align: { type: "string", enum: ["left", "center", "right", "space-between"] } },
531
+ attributes: { align: { type: "string", enum: ["left", "center", "right", "space-between"] }, orientation: { type: "string", enum: ["horizontal", "vertical"], default: "horizontal" } },
313
532
  create: () => makeBlock("buttons", {}, [makeBlock("button", { variant: "primary" })]), contextToolbar: ButtonsTools,
314
533
  supports: { style: true, anchor: true, className: true },
315
534
  },
316
535
  {
317
536
  name: "button", title: "Nút", icon: MousePointerClick, kind: "atom", edit: ButtonEdit, hidden: true,
318
- attributes: { text: { type: "string" }, href: { type: "url" }, target: { type: "string", enum: ["_self", "_blank"] }, rel: { type: "string" }, variant: { type: "string", enum: ["primary", "secondary", "outline"], default: "primary" } },
319
- create: (attrs) => makeBlock("button", { variant: "primary", ...attrs }),
537
+ attributes: { text: { type: "string" }, href: { type: "url" }, target: { type: "string", enum: ["_self", "_blank"] }, rel: { type: "string" }, variant: { type: "string", enum: ["primary", "secondary", "outline"], default: "primary" },
538
+ icon: { type: "string" }, iconPosition: { type: "string", enum: ["left", "right"] }, width: { type: "string", enum: ["auto", "full"] }, ariaLabel: { type: "string" },
539
+ iconOnly: { type: "boolean", default: false }, iconReveal: { type: "boolean", default: false } },
540
+ create: (attrs) => makeBlock("button", { variant: "primary", ...attrs }), toolbar: ButtonLinkTool,
320
541
  supports: { style: true, className: true }, summary: (a) => a.text,
321
542
  },
322
543
  {
@@ -336,16 +557,17 @@ export function layoutBlocks(): BlockType[] {
336
557
  },
337
558
  {
338
559
  name: "accordion", title: "Accordion", icon: PanelTop, category: "text", keywords: "accordion faq hoi dap nhieu muc", kind: "container", edit: AccordionEdit,
339
- attributes: { multiple: { type: "boolean", default: false } },
560
+ attributes: { multiple: { type: "boolean", default: false }, columns: { type: "number", enum: [1, 2], default: 1 }, icon: { type: "string", enum: ["arrow", "plus", "none"], default: "arrow" }, iconSide: { type: "string", enum: ["left", "right"], default: "right" }, titleTag: { type: "string", enum: ["div", "h2", "h3", "h4", "h5", "h6"], default: "div" }, startOpen: { type: "string", enum: ["none", "first", "all"], default: "none" }, faq: { type: "boolean", default: false } },
340
561
  create: () => makeBlock("accordion", {}, [makeBlock("details", { summary: "" }, [makeBlock("paragraph")]), makeBlock("details", { summary: "" }, [makeBlock("paragraph")])]), supports: { style: true, anchor: true, className: true },
341
562
  },
342
563
  {
343
564
  name: "tabs", title: "Tabs", icon: PanelTop, category: "text", keywords: "tabs the tab chuyen doi noi dung", kind: "container", edit: TabsEdit,
344
- create: () => makeBlock("tabs", {}, [makeBlock("tab", { title: "Tab 1" }, [makeBlock("paragraph")]), makeBlock("tab", { title: "Tab 2" }, [makeBlock("paragraph")])]), supports: { style: true, anchor: true, className: true },
565
+ attributes: { tabsAlign: { type: "string", enum: ["flex-start", "center", "flex-end", "space-between"] }, initial: { type: "number", min: 1 }, orientation: { type: "string", enum: ["horizontal", "vertical"], default: "horizontal" }, mobileAccordion: { type: "boolean", default: false }, iconPosition: { type: "string", enum: ["left", "right", "top"], default: "left" }, iconOnly: { type: "boolean", default: false } },
566
+ create: () => makeBlock("tabs", {}, [makeBlock("tab", { title: "" }, [makeBlock("paragraph")]), makeBlock("tab", { title: "" }, [makeBlock("paragraph")])]), contextToolbar: TabsTools, supports: { style: true, anchor: true, className: true },
345
567
  },
346
568
  {
347
569
  name: "tab", title: "Tab", icon: PanelTop, category: "text", keywords: "tab", kind: "container", edit: TabEdit, hidden: true, structure: { parents: ["tabs"] },
348
- attributes: { title: { type: "string" } }, create: () => makeBlock("tab", { title: "" }, [makeBlock("paragraph")]),
570
+ attributes: { title: { type: "string" }, icon: { type: "string", enum: ICON_NAMES }, subtitle: { type: "string" } }, supports: { anchor: true }, create: () => makeBlock("tab", { title: "" }, [makeBlock("paragraph")]),
349
571
  },
350
572
  {
351
573
  name: "carousel", title: "Carousel", icon: Columns3, category: "design", keywords: "carousel slider slide truot anh", kind: "container", edit: CarouselEdit,
@@ -358,7 +580,7 @@ export function layoutBlocks(): BlockType[] {
358
580
  },
359
581
  {
360
582
  name: "countdown", title: "Đếm ngược", icon: Square, category: "design", keywords: "dem nguoc countdown khuyen mai sale", kind: "atom", edit: CountdownEdit,
361
- attributes: { target: { type: "string" }, label: { type: "string" }, expiredText: { type: "string" } }, supports: { style: true, anchor: true, className: true },
583
+ attributes: { target: { type: "string" }, timezone: { type: "string", enum: [...COUNTDOWN_ZONES], control: "hidden" }, label: { type: "string" }, postText: { type: "string" }, expiredText: { type: "string" }, layout: { type: "string", enum: ["block", "inline"], default: "block" }, divider: { type: "boolean", default: false }, pad: { type: "boolean", default: true }, showDays: { type: "boolean", default: true }, showSeconds: { type: "boolean", default: true }, daysLabel: { type: "string" }, hoursLabel: { type: "string" }, minutesLabel: { type: "string" }, secondsLabel: { type: "string" } }, supports: { style: true, anchor: true, className: true },
362
584
  },
363
585
  {
364
586
  name: "rating", title: "Đánh giá sao", icon: Square, category: "design", keywords: "danh gia sao rating review", kind: "atom", edit: RatingEdit,
@@ -373,12 +595,12 @@ export function layoutBlocks(): BlockType[] {
373
595
  {
374
596
  name: "mediaText", title: "Ảnh + chữ", icon: LayoutPanelLeft, category: "media", keywords: "anh chu media text", kind: "container", edit: MediaTextEdit,
375
597
  attributes: { src: { type: "url", control: "media" }, alt: { type: "string" }, position: { type: "string", enum: ["left", "right"], default: "left" }, width: { type: "integer", default: 50, min: 20, max: 80 }, verticalAlign: { type: "string", enum: ["top", "center", "bottom"], default: "center" }, stack: { type: "boolean", default: true } },
376
- create: () => makeBlock("mediaText", {}, [makeBlock("paragraph")]), supports: { style: true, anchor: true, className: true },
598
+ create: () => makeBlock("mediaText", {}, [makeBlock("heading", { level: 3 }), makeBlock("paragraph")]), supports: { style: true, anchor: true, className: true },
377
599
  },
378
600
  {
379
601
  name: "table", title: "Bảng", icon: Table2, category: "text", keywords: "bang table", kind: "container", edit: TableEdit,
380
602
  attributes: { footer: { type: "boolean", default: false }, fixed: { type: "boolean", default: false } },
381
- create: () => makeBlock("table", {}, [0, 1, 2].map((r) => makeBlock("tableRow", {}, [cell(r === 0), cell(r === 0), cell(r === 0)]))), contextToolbar: TableTools,
603
+ create: () => makeBlock("table", {}, []), contextToolbar: TableTools,
382
604
  supports: { style: true, anchor: true, className: true, blockStyle: true },
383
605
  },
384
606
  { name: "tableRow", title: "Hàng", icon: Table2, kind: "container", edit: RowEdit, hidden: true },