@ecomcx/ecomweb-editor 1.31.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 (88) 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 +5 -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 +9 -1
  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 +5 -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 +9 -1
  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/form.tsx +4 -4
  42. package/src/v2/blocks/index.ts +10 -4
  43. package/src/v2/blocks/inline-style.ts +1 -1
  44. package/src/v2/blocks/layout.tsx +173 -42
  45. package/src/v2/blocks/media.tsx +22 -13
  46. package/src/v2/blocks/resize.tsx +172 -4
  47. package/src/v2/blocks/text.tsx +14 -7
  48. package/src/v2/blocks/theme.tsx +10 -5
  49. package/src/v2/blocks/tools.tsx +50 -5
  50. package/src/v2/blocks/widgets.tsx +44 -16
  51. package/src/v2/canvas/block-list.tsx +17 -2
  52. package/src/v2/canvas/canvas-css.ts +54 -4
  53. package/src/v2/canvas/canvas.tsx +20 -3
  54. package/src/v2/canvas/dnd.ts +34 -3
  55. package/src/v2/canvas/move-animation.ts +94 -0
  56. package/src/v2/canvas/spacing-viz.ts +51 -0
  57. package/src/v2/core/block-presets.ts +68 -0
  58. package/src/v2/core/host.ts +5 -0
  59. package/src/v2/core/structure.ts +2 -1
  60. package/src/v2/editor.css +238 -9
  61. package/src/v2/editor.tsx +8 -2
  62. package/src/v2/ui/attr-form.tsx +40 -11
  63. package/src/v2/ui/attr-hints.ts +104 -6
  64. package/src/v2/ui/background-panel.tsx +65 -21
  65. package/src/v2/ui/block-icons.tsx +152 -0
  66. package/src/v2/ui/block-menu.ts +22 -0
  67. package/src/v2/ui/block-style-panel.tsx +14 -3
  68. package/src/v2/ui/color-field.tsx +74 -9
  69. package/src/v2/ui/divider-panel.tsx +58 -0
  70. package/src/v2/ui/group-width.tsx +38 -0
  71. package/src/v2/ui/icon-picker.tsx +51 -0
  72. package/src/v2/ui/inserter.tsx +51 -7
  73. package/src/v2/ui/inspector.tsx +48 -16
  74. package/src/v2/ui/layout-panel.tsx +5 -47
  75. package/src/v2/ui/list-view.tsx +81 -7
  76. package/src/v2/ui/motion-panel.tsx +2 -1
  77. package/src/v2/ui/parts-panel.tsx +164 -0
  78. package/src/v2/ui/pattern-library.tsx +228 -0
  79. package/src/v2/ui/preset-bar.tsx +83 -0
  80. package/src/v2/ui/style-controls.tsx +65 -15
  81. package/src/v2/ui/style-supports.ts +1 -1
  82. package/src/v2/ui/style-tab.tsx +127 -41
  83. package/src/v2/ui/toolbar.tsx +52 -13
  84. package/src/v2/ui/unit-controls.tsx +88 -39
  85. package/src/locales/en/patterns.ts +0 -50
  86. package/src/locales/vi/patterns.ts +0 -50
  87. package/src/shared/patterns-kit.ts +0 -7
  88. 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";
17
+ import { Dropdown, MenuItem, ToolButton } from "../ui/toolbar";
18
+ import { useSiteColors } from "../ui/color-field";
16
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,11 +31,14 @@ 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, setAttrs, editable }: BlockEditProps) {
39
+ function GroupEdit({ block, blockProps, setAttrs, editable, selected }: BlockEditProps) {
35
40
  const tp = useMsgs("placeholders");
41
+ const { store } = useEditor();
36
42
  const style: BlockStyle = normalizeStyle(block.attrs.style) ?? {};
37
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)
38
44
  const kids = block.content ?? [];
@@ -40,21 +46,26 @@ function GroupEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
40
46
  const items: Array<["stack" | "row" | "grid", typeof Square, string]> = [["stack", Rows3, tp.layoutStack], ["row", RowIcon, tp.layoutRow], ["grid", LayoutGrid, tp.layoutGrid]];
41
47
  return (
42
48
  <div {...shellProps(blockProps, "group", block.attrs)} data-ecx-placeholder={fresh ? "layout" : undefined}>
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 */}
43
51
  {fresh && (
44
52
  <div className="ecx-media-placeholder ecx-ph-choose" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
45
53
  <p className="ecx-ph-title">{tp.chooseLayout}</p>
46
54
  <div className="ecx-ph-choices">
47
- {items.map(([k, I, label]) => <button key={k} type="button" className="ecx-ph-choice" onClick={() => setAttrs({ style: normalizeStyle({ ...style, layout: layoutFor(k) }) })}><I className="ecx-icon" aria-hidden />{label}</button>)}
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>)}
48
56
  </div>
49
57
  </div>
50
58
  )}
51
- <InnerBlocks parent={block} />
59
+ {selected && editable && <PaddingHandles blockId={block.id} />}
60
+ {selected && editable && !fresh && <ContentWidthHandles blockId={block.id} />}
52
61
  </div>
53
62
  );
54
63
  }
55
64
 
56
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). */
57
- function GroupLayoutTools({ attrs, setAttrs, labels }: BlockEditProps) {
66
+ function GroupLayoutTools({ block, attrs, setAttrs, labels }: BlockEditProps) {
67
+ const { store } = useEditor();
68
+ const colors = useSiteColors();
58
69
  const style: BlockStyle = normalizeStyle(attrs.style) ?? {};
59
70
  const kind = layoutKind(style.layout);
60
71
  const t = useMsgs("blocks");
@@ -64,21 +75,67 @@ function GroupLayoutTools({ attrs, setAttrs, labels }: BlockEditProps) {
64
75
  {items.map(([k, I, label]) => (
65
76
  <ToolButton key={k} label={label} active={kind === k} onClick={() => setAttrs({ style: normalizeStyle({ ...style, layout: layoutFor(k, style.layout) }) })}><I className="ecx-icon" /></ToolButton>
66
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>
67
97
  </>
68
98
  );
69
99
  }
70
100
  const groupWith = (layout?: BlockStyle["layout"], kids = 1) => makeBlock("group", layout ? { style: { layout } } : {}, Array.from({ length: kids }, () => makeBlock("paragraph")));
71
101
 
72
- 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) {
73
107
  const { store } = useEditor();
74
108
  const t = useMsgs("blocks");
109
+ const tp = useMsgs("placeholders");
75
110
  const a = block.attrs;
76
111
  const active = useActiveWithin(block.id);
77
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
+ );
78
134
  return (
79
135
  <div {...merge(blockProps, shell.className!, shell.style as CSSProperties, block.attrs)}>
80
136
  <InnerBlocks parent={block} appender="none" />
81
137
  {active && editable && block.content!.length > 1 && <ColumnHandles block={block} />}
138
+ {selected && editable && <PaddingHandles blockId={block.id} />}
82
139
  {active && editable && block.content!.length < 6 && store.canInsertInto(block.id) && (
83
140
  <button type="button" className="ecx-add-column" contentEditable={false} title={t.addColumn} aria-label={t.addColumn}
84
141
  onMouseDown={(e) => { e.preventDefault(); e.stopPropagation(); }} onClick={() => addColumnTo(store, block)}>+</button>
@@ -87,13 +144,14 @@ function ColumnsEdit({ block, blockProps, editable, labels }: BlockEditProps) {
87
144
  );
88
145
  }
89
146
 
90
- function ColumnEdit({ block, blockProps }: BlockEditProps) {
147
+ function ColumnEdit({ block, blockProps, selected, editable }: BlockEditProps) {
91
148
  const { store } = useEditor();
92
149
  const parent = store.locate(block.id)?.parent;
93
150
  const shell = blockShell("column", block.attrs, parent ? { type: parent.type, attrs: parent.attrs } : undefined)!;
94
151
  return (
95
152
  <div {...merge(blockProps, shell.className!, shell.style as CSSProperties, block.attrs)}>
96
153
  <InnerBlocks parent={block} />
154
+ {selected && editable && <PaddingHandles blockId={block.id} />}
97
155
  </div>
98
156
  );
99
157
  }
@@ -108,10 +166,16 @@ function ButtonEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
108
166
  const a = block.attrs;
109
167
  const bound = useBindingPreview(block, "text");
110
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>;
111
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>
112
173
  const link = (
113
174
  <a {...shellProps(inGroup ? blockProps : ({} as BlockEditProps["blockProps"]), "button", a)} onClick={(e) => e.preventDefault()}>
114
- {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} />}
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}
115
179
  </a>
116
180
  );
117
181
  if (inGroup) return link;
@@ -119,12 +183,12 @@ function ButtonEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
119
183
  return <p {...merge(blockProps, wrap.className ?? "", wrap.style as CSSProperties)}>{link}</p>;
120
184
  }
121
185
 
122
- function SpacerEdit({ block, blockProps }: BlockEditProps) {
186
+ function SpacerEdit({ block, blockProps, selected, editable }: BlockEditProps) {
123
187
  const tp = useMsgs("placeholders");
124
188
  const props = shellProps(blockProps, "spacer", block.attrs);
125
189
  const h = props.style?.height ?? block.attrs.height;
126
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)
127
- return <div {...props} data-ecx-size={tp.spacer.replace("{size}", String(h ?? ""))} />;
191
+ return <div {...props} data-ecx-size={tp.spacer.replace("{size}", String(h ?? ""))}>{selected && editable && <HeightHandle blockId={block.id} />}</div>;
128
192
  }
129
193
 
130
194
  function SeparatorEdit({ blockProps }: BlockEditProps) {
@@ -166,7 +230,9 @@ function AddChild({ block, label, make }: { block: BlockEditProps["block"]; labe
166
230
 
167
231
  function AccordionEdit({ block, blockProps, editable }: BlockEditProps) {
168
232
  const tp = useMsgs("placeholders");
169
- return <div {...(merge(blockProps, "ecx-accordion") as object)}><InnerBlocks parent={block} />{editable && <AddChild block={block} label={tp.addItem} make={() => makeBlock("details", { summary: "" }, [makeBlock("paragraph")])} />}</div>;
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>;
170
236
  }
171
237
 
172
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). */
@@ -182,13 +248,20 @@ function TabsEdit({ block, blockProps, editable }: BlockEditProps) {
182
248
  const active = useOpenTab(block.id);
183
249
  const tabs = (block.content ?? []).filter((c) => c.type === "tab");
184
250
  return (
185
- <div {...(merge(blockProps, "ecx-tabs") as object)}>
186
- <div role="tablist" className="ecx-tabs-list">
187
- {tabs.map((tab, i) => (
188
- <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)}>
189
- <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} />
190
- </div>
191
- ))}
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
+ })}
192
265
  {/* Nút thêm tab nằm ngay trên hàng tab */}
193
266
  {editable && store.canInsertInto(block.id) && <AddItemButton label={tp.addTab} onClick={() => {
194
267
  const loc = store.locate(block.id);
@@ -202,6 +275,29 @@ function TabsEdit({ block, blockProps, editable }: BlockEditProps) {
202
275
  );
203
276
  }
204
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
+
205
301
  function TabEdit({ block, blockProps }: BlockEditProps) {
206
302
  const { store } = useEditor();
207
303
  const loc = store.locate(block.id);
@@ -212,7 +308,7 @@ function TabEdit({ block, blockProps }: BlockEditProps) {
212
308
  // Chọn khối nằm trong thẻ đang ẩn (danh sách khối, tìm kiếm…) → mở thẻ đó
213
309
  useEffect(() => { if (within && !open && parentId) setOpenTab(parentId, index); }, [within, open, parentId, index]);
214
310
  return (
215
- <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">
216
312
  <InnerBlocks parent={block} />
217
313
  </div>
218
314
  );
@@ -246,7 +342,8 @@ const toLocalInput = (v: unknown) => { const d = new Date(String(v ?? "")); retu
246
342
  function CountdownEdit({ block, blockProps, setAttrs, editable, labels }: BlockEditProps) {
247
343
  const a = block.attrs;
248
344
  const tp = useMsgs("placeholders");
249
- const valid = Number.isFinite(Date.parse(String(a.target ?? "")));
345
+ const valid = Number.isFinite(countdownTarget(a));
346
+ const tz = typeof a.timezone === "string" && a.timezone ? a.timezone : "";
250
347
  const active = useActiveWithin(block.id);
251
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)
252
349
  if (!valid || (editable && active)) return (
@@ -254,12 +351,42 @@ function CountdownEdit({ block, blockProps, setAttrs, editable, labels }: BlockE
254
351
  <span className="ecx-ph-digits" aria-hidden>00 : 00 : 00 : 00</span>
255
352
  {editable && <label className="ecx-ph-row" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
256
353
  <span className="ecx-ph-label">{tp.countdownTarget}</span>
257
- <input className="ecx-input" type="datetime-local" value={toLocalInput(a.target)} onChange={(e) => setAttrs({ target: e.target.value ? new Date(e.target.value).toISOString() : undefined })} />
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>
258
367
  </label>}
259
368
  {!valid && <p className="ecx-placeholder-hint">{labels.countdownNoTarget}</p>}
260
369
  </div>
261
370
  );
262
- 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>;
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
+ );
263
390
  }
264
391
 
265
392
  /** Sao xám → bấm vào sao để chấm ngay trên khối. */
@@ -373,7 +500,7 @@ export function layoutBlocks(): BlockType[] {
373
500
  return [
374
501
  {
375
502
  name: "group", title: "Nhóm", icon: Square, category: "design", keywords: "nhom group khung section container", kind: "container", edit: GroupEdit,
376
- 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" } },
377
504
  create: (attrs) => makeBlock("group", attrs ?? {}, [makeBlock("paragraph")]),
378
505
  toolbar: GroupLayoutTools,
379
506
  variations: [
@@ -386,8 +513,9 @@ export function layoutBlocks(): BlockType[] {
386
513
  },
387
514
  {
388
515
  name: "columns", title: "Cột", icon: Columns2, category: "design", keywords: "cot columns bo cuc layout", kind: "container", edit: ColumnsEdit,
389
- attributes: { verticalAlign: { type: "string", enum: ["top", "center", "bottom"] }, stack: { type: "boolean", default: true } },
390
- create: () => columns(0, 0), 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,
391
519
  variations: [
392
520
  { name: "50-50", title: "50 / 50", icon: Columns2, create: () => columns(0, 0) },
393
521
  { name: "33-33-33", title: "33 / 33 / 33", icon: Columns3, create: () => columns(0, 0, 0) },
@@ -397,17 +525,19 @@ export function layoutBlocks(): BlockType[] {
397
525
  ],
398
526
  supports: { style: true, anchor: true, className: true },
399
527
  },
400
- { 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 } },
401
529
  {
402
530
  name: "buttons", title: "Nút", icon: MousePointerClick, category: "design", keywords: "nut button cta lien ket", kind: "container", edit: ButtonsEdit,
403
- 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" } },
404
532
  create: () => makeBlock("buttons", {}, [makeBlock("button", { variant: "primary" })]), contextToolbar: ButtonsTools,
405
533
  supports: { style: true, anchor: true, className: true },
406
534
  },
407
535
  {
408
536
  name: "button", title: "Nút", icon: MousePointerClick, kind: "atom", edit: ButtonEdit, hidden: true,
409
- 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" } },
410
- 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,
411
541
  supports: { style: true, className: true }, summary: (a) => a.text,
412
542
  },
413
543
  {
@@ -427,16 +557,17 @@ export function layoutBlocks(): BlockType[] {
427
557
  },
428
558
  {
429
559
  name: "accordion", title: "Accordion", icon: PanelTop, category: "text", keywords: "accordion faq hoi dap nhieu muc", kind: "container", edit: AccordionEdit,
430
- 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 } },
431
561
  create: () => makeBlock("accordion", {}, [makeBlock("details", { summary: "" }, [makeBlock("paragraph")]), makeBlock("details", { summary: "" }, [makeBlock("paragraph")])]), supports: { style: true, anchor: true, className: true },
432
562
  },
433
563
  {
434
564
  name: "tabs", title: "Tabs", icon: PanelTop, category: "text", keywords: "tabs the tab chuyen doi noi dung", kind: "container", edit: TabsEdit,
435
- create: () => makeBlock("tabs", {}, [makeBlock("tab", { title: "" }, [makeBlock("paragraph")]), makeBlock("tab", { title: "" }, [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 },
436
567
  },
437
568
  {
438
569
  name: "tab", title: "Tab", icon: PanelTop, category: "text", keywords: "tab", kind: "container", edit: TabEdit, hidden: true, structure: { parents: ["tabs"] },
439
- 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")]),
440
571
  },
441
572
  {
442
573
  name: "carousel", title: "Carousel", icon: Columns3, category: "design", keywords: "carousel slider slide truot anh", kind: "container", edit: CarouselEdit,
@@ -449,7 +580,7 @@ export function layoutBlocks(): BlockType[] {
449
580
  },
450
581
  {
451
582
  name: "countdown", title: "Đếm ngược", icon: Square, category: "design", keywords: "dem nguoc countdown khuyen mai sale", kind: "atom", edit: CountdownEdit,
452
- 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 },
453
584
  },
454
585
  {
455
586
  name: "rating", title: "Đánh giá sao", icon: Square, category: "design", keywords: "danh gia sao rating review", kind: "atom", edit: RatingEdit,
@@ -50,8 +50,8 @@ function GalleryEdit({ block, blockProps, setAttrs, editable, selected }: BlockE
50
50
  const cols = Math.min(6, Math.max(1, Number(block.attrs.columns) || 3));
51
51
  const add = (items: MediaItem[]) => setAttrs({ images: [...images, ...((mediaAttrs("gallery", items).images ?? []) as typeof images)] });
52
52
  return (
53
- <figure {...blockProps} className={cx(blockProps.className, blockShell("gallery", block.attrs)!.className)} style={{ ...(blockProps.style ?? {}), ...(blockShell("gallery", block.attrs)!.style as CSSProperties) }}>
54
- {images.map((im, i) => <figure key={i} className="ecx-gallery-item cms-gallery-item" style={{ margin: 0 }}><img src={safe(im.src)} alt={im.alt ?? ""} draggable={false} style={{ width: "100%", height: "100%", objectFit: "cover", aspectRatio: "1" }} /></figure>)}
53
+ <figure {...blockProps} className={cx(blockProps.className, blockShell("gallery", block.attrs)!.className, (block.attrs.layout === "masonry" || block.attrs.imageCrop === false) && "is-natural")} style={{ ...(blockProps.style ?? {}), ...(blockShell("gallery", block.attrs)!.style as CSSProperties) }}>
54
+ {images.map((im, i) => <figure key={i} className="ecx-gallery-item cms-gallery-item" style={{ margin: 0 }}><img src={safe(im.src)} alt={im.alt ?? ""} draggable={false} style={block.attrs.layout === "masonry" || block.attrs.imageCrop === false ? { width: "100%", height: "auto", display: "block" } : { width: "100%", height: "100%", objectFit: "cover", aspectRatio: "1" }} /></figure>)}
55
55
  {/* Có ảnh rồi vẫn còn ô "+" cuối lưới để thêm tiếp (chỉ khi đang chọn: website không có ô này) */}
56
56
  {editable && selected && <MediaPlaceholder kind="gallery" compact title={tp.addImage} icon={Plus} className="ecx-gallery-add" onSelect={add} />}
57
57
  {block.attrs.caption ? <figcaption className="ecx-gallery-caption cms-gallery-caption" style={{ gridColumn: "1 / -1" }}>{String(block.attrs.caption)}</figcaption> : null}
@@ -201,7 +201,7 @@ function SocialInspector({ attrs, setAttrs, labels }: BlockEditProps) {
201
201
  function GalleryInspector({ attrs, setAttrs }: BlockEditProps) {
202
202
  const t = useMsgs("blocks");
203
203
  const { host } = useEditor();
204
- type Img = { src: string; alt?: string; width?: number; height?: number; id?: number | string };
204
+ type Img = { src: string; alt?: string; width?: number; height?: number; id?: number | string; href?: string };
205
205
  const images = (Array.isArray(attrs.images) ? attrs.images : []) as Img[];
206
206
  const save = (next: Img[]) => setAttrs({ images: next });
207
207
  const patch = (i: number, p: Partial<Img>) => save(images.map((im, k) => (k === i ? { ...im, ...p } : im)));
@@ -218,6 +218,7 @@ function GalleryInspector({ attrs, setAttrs }: BlockEditProps) {
218
218
  <div key={`${i}-${im.src}`} className="ecx-social-row" data-gallery-row={i}>
219
219
  <img src={isSafeUrl(im.src) ? im.src : ""} alt="" width={36} height={36} style={{ objectFit: "cover", borderRadius: 4, flex: "none" }} />
220
220
  <input className="ecx-input" type="text" aria-label={format(t.imageAltN, { n: i + 1 })} placeholder={t.imageAltN.replace("{n}", String(i + 1))} value={im.alt ?? ""} onChange={(e) => patch(i, { alt: e.target.value })} />
221
+ <input className="ecx-input" type="url" inputMode="url" aria-label={format(t.imageLinkN, { n: i + 1 })} placeholder={t.imageLink} value={im.href ?? ""} onChange={(e) => patch(i, { href: e.target.value || undefined })} />
221
222
  <span className="ecx-social-row-tools">
222
223
  <button type="button" className="ecx-tool" aria-label={t.up} disabled={i === 0} onClick={() => move(i, -1)}><ArrowUp className="ecx-icon ecx-icon-sm" /></button>
223
224
  <button type="button" className="ecx-tool" aria-label={t.down} disabled={i === images.length - 1} onClick={() => move(i, 1)}><ArrowDown className="ecx-icon ecx-icon-sm" /></button>
@@ -233,27 +234,35 @@ function GalleryInspector({ attrs, setAttrs }: BlockEditProps) {
233
234
  function TocEdit({ block, blockProps }: BlockEditProps) {
234
235
  const t = useMsgs("blocks");
235
236
  const tp = useMsgs("placeholders");
236
- const max = Math.min(4, Math.max(2, Number(block.attrs.maxLevel) || 3));
237
+ const a = block.attrs;
238
+ const min = Math.min(6, Math.max(2, Number(a.minLevel) || 2));
239
+ const max = Math.min(6, Math.max(min, Number(a.maxLevel) || 3));
240
+ const title = String(a.title || t.contents);
241
+ const list = <TocItems minLevel={min} maxLevel={max} listStyle={String(a.listStyle ?? "numbers")} columns={Number(a.columns) || 1} empty={<p className="ecx-placeholder-hint ecx-ph-note" contentEditable={false}>{tp.tocHint.replace("{n}", String(max))}</p>} />;
242
+ // Khung soạn luôn mở danh sách (kể cả "bắt đầu thu gọn") để thấy được nội dung
237
243
  return (
238
- <nav {...(blockProps as object)} className={cx(blockProps.className, "ecx-toc")}>
239
- <p className="ecx-toc-title">{String(block.attrs.title || (t.contents))}</p>
240
- <TocItems maxLevel={max} empty={<p className="ecx-placeholder-hint ecx-ph-note" contentEditable={false}>{tp.tocHint.replace("{n}", String(max))}</p>} />
244
+ <nav {...(blockProps as object)} className={cx(blockProps.className, "ecx-toc", a.smoothScroll === true && "is-smooth")}>
245
+ {a.collapsible === true
246
+ ? <details className="ecx-toc-details" open><summary className="ecx-toc-title" onClick={(e) => e.preventDefault()}>{title}</summary>{list}</details>
247
+ : <>{a.showTitle !== false && <p className="ecx-toc-title">{title}</p>}{list}</>}
241
248
  </nav>
242
249
  );
243
250
  }
244
251
 
245
- /** Mục lục xem trước: tiêu đề của tài liệu đang soạn. */
246
- function TocItems({ maxLevel, empty }: { maxLevel: number; empty?: ReactNode }) {
252
+ /** Mục lục xem trước: tiêu đề của tài liệu đang soạn (cùng lớp CSS với website). */
253
+ function TocItems({ minLevel, maxLevel, listStyle, columns, empty }: { minLevel: number; maxLevel: number; listStyle: string; columns: number; empty?: ReactNode }) {
247
254
  const { store } = useEditor();
248
255
  const doc = store.getState().docs[store.activeDocId];
249
256
  const items: Array<{ level: number; text: string }> = [];
250
257
  const walk = (list: typeof doc.blocks) => list.forEach((b) => {
251
- if (b.type === "heading" && Number(b.attrs.level) >= 2 && Number(b.attrs.level) <= maxLevel) items.push({ level: Number(b.attrs.level), text: (b.inline ?? []).map((n) => n.text ?? "").join("") });
258
+ if (b.type === "heading" && Number(b.attrs.level) >= minLevel && Number(b.attrs.level) <= maxLevel) items.push({ level: Number(b.attrs.level), text: (typeof b.attrs.tocTitle === "string" && b.attrs.tocTitle.trim()) || (b.inline ?? []).map((n) => n.text ?? "").join("") });
252
259
  if (b.content) walk(b.content);
253
260
  });
254
261
  if (doc) walk(doc.blocks);
255
262
  if (!items.length && empty) return <>{empty}</>;
256
- return <ol>{items.map((h, i) => <li key={i} style={h.level > 2 ? { marginLeft: `${h.level - 2}em` } : undefined}>{h.text || "…"}</li>)}</ol>;
263
+ const List = listStyle === "bullets" || listStyle === "none" ? "ul" : "ol";
264
+ const cols = Math.min(3, Math.max(1, columns));
265
+ return <List className={cx("ecx-toc-list", listStyle === "none" && "is-plain", cols > 1 && `has-cols-${cols}`)}>{items.map((h, i) => <li key={i} style={h.level > minLevel ? { marginLeft: `${h.level - minLevel}em` } : undefined}>{h.text || "…"}</li>)}</List>;
257
266
  }
258
267
 
259
268
  export function mediaBlocks(): BlockType[] {
@@ -264,7 +273,7 @@ export function mediaBlocks(): BlockType[] {
264
273
  attributes: { ...media, alt: { type: "string", control: "textarea" }, title: { type: "string" }, width: { type: "number" }, height: { type: "number" }, size: { type: "string", default: "large" }, align: { type: "string", enum: ["left", "right", "center", "wide", "full"] }, href: { type: "url" }, linkTarget: { type: "string", enum: ["_self", "_blank"] }, lightbox: { type: "boolean", default: false } },
265
274
  supports: { style: true, anchor: true, className: true, blockStyle: true }, summary: (a) => a.alt || a.src,
266
275
  },
267
- { name: "gallery", title: "Gallery", icon: Images, category: "media", keywords: "gallery bo suu tap nhieu anh album", kind: "atom", edit: GalleryEdit, inspector: GalleryInspector, attributes: { images: { type: "json", default: [] }, columns: { type: "integer", default: 3, min: 1, max: 6 }, caption: { type: "string" }, linkTo: { type: "string", enum: ["none", "media"], default: "media" }, imageCrop: { type: "boolean", default: true }, lightbox: { type: "boolean", default: false } }, supports: { style: true, anchor: true, className: true } },
276
+ { name: "gallery", title: "Gallery", icon: Images, category: "media", keywords: "gallery bo suu tap nhieu anh album", kind: "atom", edit: GalleryEdit, inspector: GalleryInspector, attributes: { layout: { type: "string", enum: ["grid", "masonry"], default: "grid" }, images: { type: "json", default: [] }, columns: { type: "integer", default: 3, min: 1, max: 6 }, caption: { type: "string" }, linkTo: { type: "string", enum: ["none", "media"], default: "media" }, imageCrop: { type: "boolean", default: true }, lightbox: { type: "boolean", default: false } }, supports: { style: true, anchor: true, className: true } },
268
277
  { name: "video", title: "Video", icon: Video, category: "media", keywords: "video mp4 phim", kind: "atom", edit: VideoEdit, attributes: { ...media, name: { type: "string" }, mime: { type: "string" }, poster: { type: "url", control: "media" }, autoplay: { type: "boolean", default: false }, loop: { type: "boolean", default: false }, muted: { type: "boolean", default: false }, controls: { type: "boolean", default: true }, playsInline: { type: "boolean", default: true }, preload: { type: "string", enum: ["none", "metadata", "auto"], default: "metadata" } }, supports: { style: true, anchor: true } },
269
278
  { name: "audio", title: "Âm thanh", icon: Music, category: "media", keywords: "am thanh audio nhac mp3 podcast", kind: "atom", edit: AudioEdit, attributes: { ...media, name: { type: "string" }, mime: { type: "string" }, autoplay: { type: "boolean", default: false }, loop: { type: "boolean", default: false }, preload: { type: "string", enum: ["none", "metadata", "auto"], default: "metadata" } }, supports: { style: true, anchor: true } },
270
279
  { name: "file", title: "Tệp", icon: FileIcon, category: "media", keywords: "tep file pdf tai xuong download tai lieu", kind: "atom", edit: FileEdit, attributes: { ...media, name: { type: "string" }, mime: { type: "string" }, size: { type: "number" }, embed: { type: "boolean", default: true }, download: { type: "boolean" } }, supports: { style: true, anchor: true } },
@@ -272,6 +281,6 @@ export function mediaBlocks(): BlockType[] {
272
281
  { name: "embed", title: "Nhúng", icon: Globe, category: "embed", keywords: "nhung embed youtube vimeo tiktok facebook twitter x instagram spotify google map", kind: "atom", edit: EmbedEdit, attributes: { url: { type: "url" }, caption: { type: "string" } }, supports: { style: true, anchor: true }, summary: (a) => a.url },
273
282
  { name: "customHtml", title: "HTML tuỳ chỉnh", icon: Code2, category: "widgets", keywords: "html tuy chinh custom code", kind: "atom", edit: HtmlEdit, attributes: { html: { type: "string", control: "textarea" } } },
274
283
  { name: "socialLinks", title: "Mạng xã hội", icon: Share2, category: "widgets", keywords: "mang xa hoi social facebook zalo youtube tiktok", kind: "atom", edit: SocialEdit, inspector: SocialInspector, attributes: { links: { type: "json", default: [] }, size: { type: "string", enum: ["small", "medium", "large"], default: "medium" }, align: { type: "string", enum: ["left", "center", "right"] }, showLabels: { type: "boolean", default: false } }, supports: { style: true, anchor: true, className: true } },
275
- { name: "tableOfContents", title: "Mục lục", icon: ListTree, category: "widgets", keywords: "muc luc table of contents toc", kind: "atom", edit: TocEdit, attributes: { title: { type: "string" }, maxLevel: { type: "integer", default: 3, min: 2, max: 4 } }, supports: { style: true, anchor: true } },
284
+ { name: "tableOfContents", title: "Mục lục", icon: ListTree, category: "widgets", keywords: "muc luc table of contents toc", kind: "atom", edit: TocEdit, attributes: { title: { type: "string" }, minLevel: { type: "integer", default: 2, min: 2, max: 6 }, maxLevel: { type: "integer", default: 3, min: 2, max: 6 }, collapsible: { type: "boolean", default: false }, startCollapsed: { type: "boolean", default: false }, listStyle: { type: "string", enum: ["numbers", "bullets", "none"], default: "numbers" }, columns: { type: "integer", default: 1, min: 1, max: 3 }, smoothScroll: { type: "boolean", default: false }, highlight: { type: "boolean", default: false }, showTitle: { type: "boolean", default: true } }, supports: { style: true, anchor: true } },
276
285
  ];
277
286
  }