@ecomcx/ecomweb-editor 1.32.0 → 1.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/package.json +3 -3
  2. package/src/locales/en/attrs.ts +2 -1
  3. package/src/locales/en/background.ts +5 -0
  4. package/src/locales/en/bindings.ts +5 -1
  5. package/src/locales/en/block-desc.ts +5 -11
  6. package/src/locales/en/block-style.ts +17 -6
  7. package/src/locales/en/block-titles.ts +38 -15
  8. package/src/locales/en/blocks.ts +37 -6
  9. package/src/locales/en/columns.ts +1 -0
  10. package/src/locales/en/controls.ts +1 -1
  11. package/src/locales/en/hints.ts +315 -12
  12. package/src/locales/en/index.ts +3 -1
  13. package/src/locales/en/layout.ts +13 -0
  14. package/src/locales/en/motion.ts +16 -0
  15. package/src/locales/en/palette.ts +8 -0
  16. package/src/locales/en/parts.ts +2 -1
  17. package/src/locales/en/pattern-overrides.ts +14 -0
  18. package/src/locales/en/placeholders.ts +9 -3
  19. package/src/locales/en/v2.ts +2 -0
  20. package/src/locales/vi/attrs.ts +3 -2
  21. package/src/locales/vi/background.ts +5 -0
  22. package/src/locales/vi/bindings.ts +5 -1
  23. package/src/locales/vi/block-desc.ts +8 -14
  24. package/src/locales/vi/block-style.ts +18 -7
  25. package/src/locales/vi/block-titles.ts +48 -25
  26. package/src/locales/vi/blocks.ts +37 -6
  27. package/src/locales/vi/columns.ts +1 -0
  28. package/src/locales/vi/controls.ts +1 -1
  29. package/src/locales/vi/hints.ts +315 -12
  30. package/src/locales/vi/index.ts +3 -1
  31. package/src/locales/vi/layout.ts +13 -0
  32. package/src/locales/vi/motion.ts +16 -0
  33. package/src/locales/vi/palette.ts +8 -0
  34. package/src/locales/vi/parts.ts +2 -1
  35. package/src/locales/vi/pattern-overrides.ts +14 -0
  36. package/src/locales/vi/placeholders.ts +10 -4
  37. package/src/locales/vi/v2.ts +2 -0
  38. package/src/v2/blocks/columns-inspector.tsx +11 -2
  39. package/src/v2/blocks/index.ts +9 -6
  40. package/src/v2/blocks/layout-options.tsx +80 -0
  41. package/src/v2/blocks/layout.tsx +349 -106
  42. package/src/v2/blocks/media.tsx +51 -21
  43. package/src/v2/blocks/resize.tsx +50 -19
  44. package/src/v2/blocks/social-icons.ts +22 -0
  45. package/src/v2/blocks/text.tsx +12 -50
  46. package/src/v2/blocks/theme.tsx +62 -29
  47. package/src/v2/blocks/tools.tsx +24 -2
  48. package/src/v2/blocks/widgets.tsx +84 -28
  49. package/src/v2/canvas/block-list.tsx +36 -5
  50. package/src/v2/canvas/canvas-css.ts +95 -7
  51. package/src/v2/canvas/canvas.tsx +65 -9
  52. package/src/v2/canvas/dnd.ts +7 -0
  53. package/src/v2/canvas/variation-picker.tsx +63 -0
  54. package/src/v2/context.tsx +48 -0
  55. package/src/v2/core/bindings.ts +6 -1
  56. package/src/v2/core/block-presets.ts +10 -0
  57. package/src/v2/core/clipboard.ts +5 -5
  58. package/src/v2/core/host.ts +3 -1
  59. package/src/v2/core/model.ts +6 -6
  60. package/src/v2/core/registry.ts +15 -0
  61. package/src/v2/core/store.ts +9 -9
  62. package/src/v2/core/structure.ts +1 -3
  63. package/src/v2/editor.css +74 -0
  64. package/src/v2/editor.tsx +22 -7
  65. package/src/v2/text/rich-text.tsx +20 -5
  66. package/src/v2/ui/ai-markdown.ts +52 -0
  67. package/src/v2/ui/ai.tsx +81 -14
  68. package/src/v2/ui/attr-form.tsx +45 -7
  69. package/src/v2/ui/attr-hints.ts +151 -19
  70. package/src/v2/ui/background-panel.tsx +22 -0
  71. package/src/v2/ui/bg-video-preview.tsx +7 -0
  72. package/src/v2/ui/bindings.tsx +9 -1
  73. package/src/v2/ui/block-icons.tsx +3 -10
  74. package/src/v2/ui/block-live-preview.tsx +21 -0
  75. package/src/v2/ui/block-style-panel.tsx +3 -1
  76. package/src/v2/ui/command-palette.tsx +125 -0
  77. package/src/v2/ui/icon-picker.tsx +88 -21
  78. package/src/v2/ui/icon-svg.tsx +21 -0
  79. package/src/v2/ui/inserter.tsx +72 -17
  80. package/src/v2/ui/inspector.tsx +12 -6
  81. package/src/v2/ui/layout-panel.tsx +1 -1
  82. package/src/v2/ui/motion-panel.tsx +22 -13
  83. package/src/v2/ui/option-thumbs.tsx +81 -0
  84. package/src/v2/ui/pattern-library.tsx +2 -1
  85. package/src/v2/ui/pattern-overrides.tsx +67 -0
  86. package/src/v2/ui/placeholders.tsx +21 -2
  87. package/src/v2/ui/preset-bar.tsx +5 -5
  88. package/src/v2/ui/style-supports.ts +2 -3
  89. package/src/v2/ui/style-tab.tsx +83 -20
  90. package/src/v2/ui/toolbar.tsx +40 -6
  91. package/src/v2/ui/transform-panel.tsx +77 -0
@@ -0,0 +1,125 @@
1
+ import { Search } from "lucide-react";
2
+ import { useEffect, useMemo, useRef, useState } from "react";
3
+ import { useEditor } from "../context";
4
+ import { useMsgs } from "../i18n";
5
+ import { copyStyle, hasCopiedStyle, pastedStyle } from "./block-menu";
6
+ import { cx } from "./style-controls";
7
+ import { useInsertOptions } from "./inserter";
8
+
9
+ export interface PaletteActions {
10
+ save(): void;
11
+ toggleList(): void;
12
+ toggleSettings(): void;
13
+ openInserter(query?: string): void;
14
+ }
15
+ interface Command { id: string; group: string; title: string; hint?: string; keywords?: string; run(): void }
16
+
17
+ const norm = (s: string) => s.normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/đ/g, "d").toLowerCase();
18
+ const plain = (b: { inline?: Array<{ type: string; text?: string }> }) => (b.inline ?? []).map((n) => (n.type === "text" ? n.text ?? "" : "")).join("").trim();
19
+
20
+ /**
21
+ * Bảng lệnh: một ô tìm cho mọi thứ — thao tác (lưu, hoàn tác, nhân đôi, xoá, chuyển…), chế độ xem (khổ máy, danh sách, cài đặt),
22
+ * chèn khối (theo tên, kể cả tên cũ tiếng Việt) và nhảy tới khối trong trang theo chữ đang có. Mở bằng ⌘⇧P / Ctrl+Shift+P hoặc nút trên thanh.
23
+ */
24
+ export function CommandPalette({ open, onClose, actions }: { open: boolean; onClose(): void; actions: PaletteActions }) {
25
+ const ctx = useEditor();
26
+ const { store, ui, labels } = ctx;
27
+ const t = useMsgs("palette");
28
+ const blocks = useInsertOptions();
29
+ const [q, setQ] = useState("");
30
+ const [active, setActive] = useState(0);
31
+ const input = useRef<HTMLInputElement>(null);
32
+ useEffect(() => { if (open) { setQ(""); setActive(0); requestAnimationFrame(() => input.current?.focus()); } }, [open]);
33
+
34
+ const commands = useMemo<Command[]>(() => {
35
+ if (!open) return [];
36
+ const sel = store.currentIds;
37
+ const first = sel[0];
38
+ const loc = first ? store.locate(first) : null;
39
+ const act = (title: string, run: () => void, hint?: string, keywords = ""): Command => ({ id: `a:${title}`, group: t.groupActions, title, hint, keywords, run });
40
+ const list: Command[] = [
41
+ act(t.save, actions.save, "⌘S", "luu save"),
42
+ act(t.undo, () => store.undo(), "⌘Z", "hoan tac undo"),
43
+ act(t.redo, () => store.redo(), "⌘⇧Z", "lam lai redo"),
44
+ ];
45
+ if (loc?.parent) list.push(act(t.selectParent, () => store.select([loc.parent!.id], { editing: null }), "", "khoi cha parent"));
46
+ if (first) {
47
+ list.push(
48
+ act(t.duplicate, () => store.duplicate(sel), "", "nhan doi duplicate copy"),
49
+ act(t.remove, () => store.remove(sel), "", "xoa delete remove"),
50
+ act(t.moveUp, () => store.moveBy(sel, -1), "", "len up"),
51
+ act(t.moveDown, () => store.moveBy(sel, 1), "", "xuong down"),
52
+ act(t.copyStyle, () => { const b = store.block(first); if (b) copyStyle(b.attrs); }, "", "chep kieu style"),
53
+ );
54
+ if (hasCopiedStyle()) list.push(act(t.pasteStyle, () => store.setAttrs(sel, pastedStyle()!), "", "dan kieu style paste"));
55
+ }
56
+ const view = (title: string, run: () => void, keywords: string): Command => ({ id: `v:${title}`, group: t.groupView, title, keywords, run });
57
+ list.push(
58
+ view(t.desktop, () => ui.setDevice("desktop"), "may tinh desktop"),
59
+ view(t.tablet, () => ui.setDevice("tablet"), "may tinh bang tablet"),
60
+ view(t.mobile, () => ui.setDevice("mobile"), "dien thoai mobile phone"),
61
+ view(t.listView, actions.toggleList, "danh sach khoi list tree navigator"),
62
+ view(t.settings, actions.toggleSettings, "cai dat settings inspector bang phai"),
63
+ view(t.inserter, () => actions.openInserter(), "chen khoi insert add"),
64
+ view(t.zoomOut, () => ui.setZoomOut(!ui.zoomOut), "thu nho zoom sap xep"),
65
+ );
66
+ return list;
67
+ }, [open, store, ui, actions, t, store.currentIds.join(",")]); // eslint-disable-line react-hooks/exhaustive-deps
68
+
69
+ const results = useMemo<Command[]>(() => {
70
+ const k = norm(q.trim());
71
+ const match = (c: Command) => !k || norm(`${c.title} ${c.keywords ?? ""}`).includes(k) || k.split(/\s+/).every((w) => norm(`${c.title} ${c.keywords ?? ""}`).includes(w));
72
+ const out = commands.filter(match);
73
+ if (k.length >= 2) {
74
+ // Chèn khối: tên khối (kể cả tên cũ) khớp ô tìm → chạy thì mở bảng chèn đúng từ khoá đó để chèn vào chỗ đang chọn
75
+ const ins = blocks.filter((o) => norm(`${o.title} ${o.keywords} ${(o.aliases ?? []).join(" ")}`).includes(k)).slice(0, 8);
76
+ for (const o of ins) out.push({ id: `i:${o.key}`, group: t.groupInsert, title: `${t.insert}: ${o.title}`, run: () => actions.openInserter(o.title) });
77
+ // Đi tới khối theo chữ đang có trong trang
78
+ let n = 0;
79
+ const docs = store.getState().docs;
80
+ const walk = (docId: string, list: Array<{ id: string; type: string; inline?: Array<{ type: string; text?: string }>; content?: unknown[]; attrs: Record<string, unknown> }>) => {
81
+ for (const b of list) {
82
+ if (n >= 8) return;
83
+ const text = plain(b) || String(b.attrs.title ?? b.attrs.text ?? b.attrs.summary ?? b.attrs.label ?? "");
84
+ if (text && norm(text).includes(k)) { n++; out.push({ id: `g:${b.id}`, group: t.groupGoto, title: `${t.goto}: ${text.slice(0, 60)}`, hint: ctx.registry.get(b.type)?.title ?? b.type, run: () => { store.select([b.id], { editing: null }); requestAnimationFrame(() => ui.blockEl(b.id)?.scrollIntoView({ block: "center", behavior: "smooth" })); } }); }
85
+ if (Array.isArray(b.content)) walk(docId, b.content as never);
86
+ }
87
+ };
88
+ for (const [id, d] of Object.entries(docs)) walk(id, (d as unknown as { blocks: never[] }).blocks);
89
+ }
90
+ return out.slice(0, 40);
91
+ }, [q, commands, blocks, store, ui, ctx.registry, actions, t]);
92
+
93
+ useEffect(() => setActive(0), [q]);
94
+ if (!open) return null;
95
+ const run = (c?: Command) => { if (!c) return; onClose(); setTimeout(() => c.run(), 0); };
96
+ const groups: Array<[string, Command[]]> = [];
97
+ for (const c of results) { const g = groups.find((x) => x[0] === c.group); if (g) g[1].push(c); else groups.push([c.group, [c]]); }
98
+ return (
99
+ <div className="ecx-palette-backdrop" onMouseDown={(e) => { if (e.target === e.currentTarget) onClose(); }}>
100
+ <div className="ecx-palette" role="dialog" aria-modal="true" aria-label={t.title}
101
+ onKeyDown={(e) => {
102
+ if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); onClose(); }
103
+ else if (e.key === "ArrowDown") { e.preventDefault(); setActive((a) => Math.min(results.length - 1, a + 1)); }
104
+ else if (e.key === "ArrowUp") { e.preventDefault(); setActive((a) => Math.max(0, a - 1)); }
105
+ else if (e.key === "Enter") { e.preventDefault(); run(results[active]); }
106
+ }}>
107
+ <div className="ecx-palette-input"><Search className="ecx-icon" aria-hidden /><input ref={input} role="combobox" aria-expanded aria-controls="ecx-palette-list" aria-activedescendant={results[active] ? `ecx-pal-${active}` : undefined} placeholder={t.placeholder} aria-label={t.title} value={q} onChange={(e) => setQ(e.target.value)} /></div>
108
+ <div className="ecx-palette-list" id="ecx-palette-list" role="listbox">
109
+ {groups.map(([g, list]) => (
110
+ <div key={g} role="presentation">
111
+ <div className="ecx-palette-group">{g}</div>
112
+ {list.map((c) => { const i = results.indexOf(c); return (
113
+ <button key={c.id} id={`ecx-pal-${i}`} type="button" role="option" aria-selected={i === active} className={cx("ecx-palette-item", i === active && "is-active")} onMouseMove={() => setActive(i)} onClick={() => run(c)}>
114
+ <span>{c.title}</span>{c.hint && <kbd>{c.hint}</kbd>}
115
+ </button>
116
+ ); })}
117
+ </div>
118
+ ))}
119
+ {!results.length && <p className="ecx-palette-empty">{t.empty}</p>}
120
+ </div>
121
+ <div className="ecx-palette-foot">{t.hint}{labels ? "" : ""}</div>
122
+ </div>
123
+ </div>
124
+ );
125
+ }
@@ -1,21 +1,20 @@
1
- import { ICON_NAMES, ICON_PATHS } from "@ecomcx/ecomweb-content";
2
- import { ChevronDown, X } from "lucide-react";
1
+ import { ICON_CORE_COUNT, ICON_NAMES, SVG_ICON_MAX, isSvgIconValue, resolveIcon, toSvgIconValue } from "@ecomcx/ecomweb-content";
2
+ import { ChevronDown, Upload, X } from "lucide-react";
3
3
  import { useEffect, useMemo, useRef, useState } from "react";
4
4
  import { useMsgs } from "../i18n";
5
+ import { IconSvg } from "./icon-svg"; // đồng thời nạp thư viện icon
5
6
  import { cx } from "./style-controls";
6
7
 
7
- const Svg = ({ name, size = 20 }: { name: string; size?: number }) => (
8
- <svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d={ICON_PATHS[name]} /></svg>
9
- );
8
+ const PAGE = 160;
10
9
 
11
10
  /**
12
- * Ô chọn icon: ô hiện icon đang chọn + mũi tên; bấm mở lưới icon có ô tìm (như bảng chọn icon của các bộ khối lớn).
13
- * `allowNone`: có lựa chọn "Không có icon" (vd nút).
11
+ * Ô chọn icon: ô hiện icon đang chọn + mũi tên; bấm mở hộp có hai tab — "Thư viện" (≈1.900 icon, có ô tìm) và "SVG riêng" (dán mã SVG hoặc chọn file .svg).
12
+ * `allowNone`: có lựa chọn "Không có icon" (vd nút). `defaultLabel`: thêm ô "mặc định" (giá trị trống, vd icon của từng mục theo icon chung của danh sách);
13
+ * khi đó `noneValue` là giá trị lưu cho "Không có icon".
14
14
  */
15
- export function IconPicker({ value, onChange, label, allowNone }: { value?: string; onChange(v: string | undefined): void; label: string; allowNone?: boolean }) {
15
+ export function IconPicker({ value, onChange, label, allowNone, defaultLabel, noneValue }: { value?: string; onChange(v: string | undefined): void; label: string; allowNone?: boolean; defaultLabel?: string; noneValue?: string }) {
16
16
  const t = useMsgs("controls");
17
17
  const [open, setOpen] = useState(false);
18
- const [q, setQ] = useState("");
19
18
  const ref = useRef<HTMLDivElement>(null);
20
19
  useEffect(() => {
21
20
  if (!open) return;
@@ -24,28 +23,96 @@ export function IconPicker({ value, onChange, label, allowNone }: { value?: stri
24
23
  document.addEventListener("mousedown", out, true); document.addEventListener("keydown", esc, true);
25
24
  return () => { document.removeEventListener("mousedown", out, true); document.removeEventListener("keydown", esc, true); };
26
25
  }, [open]);
27
- const names = useMemo(() => { const k = q.trim().toLowerCase(); return (ICON_NAMES as readonly string[]).filter((n) => !k || n.toLowerCase().includes(k)); }, [q]);
28
- const has = !!value && !!ICON_PATHS[value];
26
+ const has = !!value && !!resolveIcon(value);
27
+ const text = has ? (isSvgIconValue(value) ? t.iconCustom : value) : value === noneValue && noneValue ? t.noIcon : defaultLabel ?? t.noIcon;
29
28
  return (
30
29
  <div className="ecx-icon-picker" ref={ref}>
31
30
  <button type="button" className={cx("ecx-icon-picker-btn", open && "is-open")} aria-haspopup="dialog" aria-expanded={open} aria-label={label} onClick={() => setOpen(!open)}>
32
- {has ? <Svg name={value!} size={22} /> : <span className="ecx-muted">{t.noIcon}</span>}
33
- <span className="ecx-icon-picker-name">{has ? value : ""}</span>
31
+ {has ? <IconSvg name={value} size={22} /> : <span className="ecx-muted">{text}</span>}
32
+ <span className="ecx-icon-picker-name">{has ? text : ""}</span>
34
33
  <ChevronDown className="ecx-icon" />
35
34
  </button>
36
35
  {open && (
37
36
  // preventDefault: ô này nằm trong <label> của form — không chặn thì bấm trong bảng kích lại nút mở (bảng đóng rồi mở lại)
38
37
  <div className="ecx-icon-pop" role="dialog" aria-label={label} onClick={(e) => e.preventDefault()}>
39
- <input className="ecx-input" autoFocus placeholder={t.searchIcons} value={q} onChange={(e) => setQ(e.target.value)} />
40
- <div className="ecx-icon-grid" role="listbox" aria-label={label}>
41
- {allowNone && <button type="button" role="option" aria-selected={!has} title={t.noIcon} className={cx("ecx-icon-cell", !has && "is-active")} onClick={() => { onChange(undefined); setOpen(false); }}><X className="ecx-icon" /></button>}
42
- {names.map((n) => (
43
- <button key={n} type="button" role="option" aria-selected={value === n} title={n} className={cx("ecx-icon-cell", value === n && "is-active")} onClick={() => { onChange(n); setOpen(false); }}><Svg name={n} /></button>
44
- ))}
45
- </div>
46
- {!names.length && <p className="ecx-pop-hint">{t.noIconFound}</p>}
38
+ <IconGrid value={value} label={label} allowNone={allowNone} defaultLabel={defaultLabel} noneValue={noneValue} onPick={(v) => { onChange(v); setOpen(false); }} />
47
39
  </div>
48
40
  )}
49
41
  </div>
50
42
  );
51
43
  }
44
+
45
+ /** Hộp chọn icon: tab Thư viện (tìm + lưới) / SVG riêng — dùng trong ô chọn icon của bảng phải và trong thanh công cụ của khối. */
46
+ export function IconGrid({ value, onPick, label, allowNone, defaultLabel, noneValue, className }: { value?: string; onPick(v: string | undefined): void; label: string; allowNone?: boolean; defaultLabel?: string; noneValue?: string; className?: string }) {
47
+ const t = useMsgs("controls");
48
+ const [tab, setTab] = useState<"library" | "svg">(isSvgIconValue(value) ? "svg" : "library");
49
+ return (
50
+ <div className={className}>
51
+ <div className="ecx-icon-tabs" role="tablist" aria-label={label}>
52
+ <button type="button" role="tab" aria-selected={tab === "library"} className={cx("ecx-icon-tab", tab === "library" && "is-active")} onClick={() => setTab("library")}>{t.iconLibrary}</button>
53
+ <button type="button" role="tab" aria-selected={tab === "svg"} className={cx("ecx-icon-tab", tab === "svg" && "is-active")} onClick={() => setTab("svg")}>{t.iconCustom}</button>
54
+ </div>
55
+ {tab === "library" ? <LibraryTab value={value} onPick={onPick} label={label} allowNone={allowNone} defaultLabel={defaultLabel} noneValue={noneValue} /> : <SvgTab value={value} onPick={onPick} />}
56
+ </div>
57
+ );
58
+ }
59
+
60
+ function LibraryTab({ value, onPick, label, allowNone, defaultLabel, noneValue }: { value?: string; onPick(v: string | undefined): void; label: string; allowNone?: boolean; defaultLabel?: string; noneValue?: string }) {
61
+ const t = useMsgs("controls");
62
+ const [q, setQ] = useState("");
63
+ const [shown, setShown] = useState(PAGE);
64
+ // Bộ lõi (tên quen thuộc) đứng trước, rồi tới thư viện; tìm theo tên không dấu, bỏ gạch nối
65
+ const all = ICON_NAMES as readonly string[];
66
+ const names = useMemo(() => {
67
+ const k = q.trim().toLowerCase().replace(/[\s_]+/g, "-");
68
+ if (!k) return all;
69
+ const starts: string[] = [], has: string[] = [];
70
+ for (const n of all) { const l = n.toLowerCase(); if (l.startsWith(k)) starts.push(n); else if (l.includes(k) || l.replace(/-/g, "").includes(k.replace(/-/g, ""))) has.push(n); }
71
+ return [...starts, ...has];
72
+ }, [q, all]);
73
+ useEffect(() => setShown(PAGE), [q]);
74
+ const has = !!value && !!resolveIcon(value) && !isSvgIconValue(value);
75
+ const none = (noneValue ?? "") !== "" && value === noneValue;
76
+ return (
77
+ <>
78
+ <input className="ecx-input" autoFocus placeholder={`${t.searchIcons} (${all.length})`} value={q} onChange={(e) => setQ(e.target.value)} aria-label={t.searchIcons} />
79
+ <div className="ecx-icon-grid" role="listbox" aria-label={label}>
80
+ {defaultLabel && <button type="button" role="option" aria-selected={!value} title={defaultLabel} className={cx("ecx-icon-cell", !value && "is-active")} onClick={() => onPick(undefined)}><span className="ecx-icon-cell-text">{defaultLabel}</span></button>}
81
+ {(allowNone || noneValue) && <button type="button" role="option" aria-selected={defaultLabel ? none : !has} title={t.noIcon} className={cx("ecx-icon-cell", (defaultLabel ? none : !has) && "is-active")} onClick={() => onPick(noneValue)}><X className="ecx-icon" /></button>}
82
+ {names.slice(0, shown).map((n) => (
83
+ <button key={n} type="button" role="option" aria-selected={value === n} title={n} className={cx("ecx-icon-cell", value === n && "is-active")} onClick={() => onPick(n)}><IconSvg name={n} /></button>
84
+ ))}
85
+ </div>
86
+ {names.length > shown && <button type="button" className="ecx-link-btn" onClick={() => setShown(shown + PAGE * 3)}>{t.iconMore.replace("{n}", String(names.length - shown))}</button>}
87
+ {!names.length && <p className="ecx-pop-hint">{t.noIconFound}</p>}
88
+ {all.length <= ICON_CORE_COUNT && <p className="ecx-pop-hint">{t.iconLibraryLoading}</p>}
89
+ </>
90
+ );
91
+ }
92
+
93
+ function SvgTab({ value, onPick }: { value?: string; onPick(v: string | undefined): void }) {
94
+ const t = useMsgs("controls");
95
+ const [code, setCode] = useState("");
96
+ const [error, setError] = useState(false);
97
+ const file = useRef<HTMLInputElement>(null);
98
+ const parsed = useMemo(() => (code.trim() ? toSvgIconValue(code) : null), [code]);
99
+ useEffect(() => setError(false), [code]);
100
+ const loadFile = async (f?: File | null) => {
101
+ if (!f) return;
102
+ if (f.size > 200_000) { setError(true); return; }
103
+ setCode(await f.text());
104
+ };
105
+ return (
106
+ <div className="ecx-icon-svg">
107
+ <p className="ecx-pop-hint">{t.iconCustomHint}</p>
108
+ <textarea className="ecx-input" rows={5} spellCheck={false} placeholder={'<svg viewBox="0 0 24 24">…</svg>'} aria-label={t.iconCustomCode} value={code} onChange={(e) => setCode(e.target.value)} />
109
+ <div className="ecx-icon-svg-row">
110
+ <button type="button" className="ecx-link-btn" onClick={() => file.current?.click()}><Upload className="ecx-icon ecx-icon-sm" aria-hidden /> {t.iconCustomFile}</button>
111
+ <input ref={file} type="file" accept=".svg,image/svg+xml" hidden onChange={(e) => { void loadFile(e.target.files?.[0]); e.target.value = ""; }} />
112
+ <span className="ecx-icon-svg-preview" aria-label={t.iconCustomPreview}>{parsed ? <IconSvg name={parsed} size={32} /> : isSvgIconValue(value) && !code ? <IconSvg name={value} size={32} /> : null}</span>
113
+ </div>
114
+ {(error || (code.trim() && !parsed)) && <p className="ecx-pop-hint" role="alert">{t.iconCustomInvalid.replace("{max}", String(SVG_ICON_MAX))}</p>}
115
+ <button type="button" className="ecx-btn ecx-btn-primary" disabled={!parsed} onClick={() => parsed && onPick(parsed)}>{t.iconCustomUse}</button>
116
+ </div>
117
+ );
118
+ }
@@ -0,0 +1,21 @@
1
+ import { createElement, type ReactNode } from "react";
2
+ import { registerIconLibrary, resolveIcon, type SvgIconNode } from "@ecomcx/ecomweb-content";
3
+ import { ICON_LIBRARY } from "@ecomcx/ecomweb-content/icon-library";
4
+
5
+ // ≈1.900 icon của thư viện: nạp một lần khi trình soạn khởi động (cùng thư viện với website)
6
+ registerIconLibrary(ICON_LIBRARY);
7
+
8
+ const camel = (props: Record<string, string>): Record<string, string> => Object.fromEntries(Object.entries(props).map(([k, v]) => [k.replace(/-([a-z])/g, (_, c: string) => c.toUpperCase()), v]));
9
+ const node = (n: SvgIconNode, key: number): ReactNode => createElement(n.tag, { key, ...camel(n.props) }, ...n.children.map(node));
10
+
11
+ /** Vẽ icon theo giá trị lưu (tên trong bảng / thư viện, hoặc SVG riêng `svg:…` đã lọc) — cùng cách với website. Không có icon → null. */
12
+ export function IconSvg({ name, size = 24, stroke = 2, className, label, style }: { name?: unknown; size?: number; stroke?: number; className?: string; label?: string; style?: import("react").CSSProperties }): ReactNode {
13
+ const r = resolveIcon(name);
14
+ if (!r) return null;
15
+ const a11y = label ? { role: "img", "aria-label": label } : { "aria-hidden": true as const, focusable: "false" as const };
16
+ if (r.kind === "svg") {
17
+ const root = camel(r.icon.root);
18
+ return <svg className={className} style={style && Object.keys(style).length ? style : undefined} width={size} height={size} viewBox={r.icon.viewBox} fill={root.fill ?? "currentColor"} {...(root.stroke ? { stroke: root.stroke } : {})} {...(root.strokeWidth ? { strokeWidth: root.strokeWidth } : {})} {...(root.strokeLinecap ? { strokeLinecap: root.strokeLinecap as "round" } : {})} {...(root.strokeLinejoin ? { strokeLinejoin: root.strokeLinejoin as "round" } : {})} {...a11y}>{r.icon.children.map(node)}</svg>;
19
+ }
20
+ return <svg className={className} style={style && Object.keys(style).length ? style : undefined} width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={stroke} strokeLinecap="round" strokeLinejoin="round" {...a11y}><path d={r.d} /></svg>;
21
+ }
@@ -1,3 +1,4 @@
1
+ import { LiveBlockPreview } from "./block-live-preview";
1
2
  import { freshWithDefaults } from "../core/block-presets";
2
3
  import { leavesItem } from "../core/structure";
3
4
  import { blockDescription } from "./block-descriptions";
@@ -7,7 +8,7 @@ import { cx } from "./attr-form";
7
8
  import type { MediaItem } from "../../shared/types";
8
9
  import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ComponentType } from "react";
9
10
  import { norm } from "../../shared/util";
10
- import { useEditor, useUiTick, type InserterRequest } from "../context";
11
+ import { useEditor, useEditorState, useUiTick, type InserterRequest } from "../context";
11
12
  import { cloneBlock, inlineLength, makeBlock, type BNode } from "../core/model";
12
13
  import type { BlockType } from "../core/registry";
13
14
  import { canContain } from "../core/structure";
@@ -23,6 +24,7 @@ export interface InsertOption {
23
24
  description?: string;
24
25
  icon?: ComponentType<{ className?: string }>;
25
26
  keywords: string;
27
+ aliases?: string[];
26
28
  category: string;
27
29
  /** Loại khối gốc (kiểm tra chỗ đặt được). */
28
30
  type: string;
@@ -32,6 +34,9 @@ export interface InsertOption {
32
34
  }
33
35
 
34
36
  /** Các lựa chọn chèn: khối + biến thể có hàm tạo riêng (cột 30/70…). */
37
+ const LEGACY_BLOCKS = new Set(["details", "testimonial"]);
38
+ const PAGE_THEME_BLOCKS = new Set(["search", "query", "icon"]);
39
+
35
40
  export function useInsertOptions(): InsertOption[] {
36
41
  const { registry, prefs, host, labels } = useEditor();
37
42
  const hidden = usePrefs(prefs).hiddenBlockTypes;
@@ -42,24 +47,27 @@ export function useInsertOptions(): InsertOption[] {
42
47
  const out: InsertOption[] = [];
43
48
  const hide = new Set(hidden);
44
49
  for (const t of registry.all()) {
45
- if (t.hidden || hide.has(t.name) || (t.templateOnly && host.scope !== "template")) continue;
46
- out.push({ key: t.name, title: t.title, description: t.description, icon: t.icon, keywords: t.keywords ?? "", category: t.category ?? "other", type: t.name, create: () => registry.create(t.name) });
50
+ // Bộ khối gọn: khối cũ đã gộp vào khối khác và khối giao diện (tên website, bài, bình luận…) chỉ hiện khi sửa template; nội dung cũ vẫn hiển thị
51
+ const tpl = t.templateOnly || (t.category === "theme" && !PAGE_THEME_BLOCKS.has(t.name));
52
+ if (t.hidden || hide.has(t.name)) continue;
53
+ if (!host.showAllBlocks && (LEGACY_BLOCKS.has(t.name) || (tpl && host.scope !== "template"))) continue;
54
+ out.push({ key: t.name, title: t.title, description: t.description, icon: t.icon, keywords: t.keywords ?? "", aliases: t.aliases, category: t.category ?? "other", type: t.name, create: () => registry.create(t.name) });
47
55
  for (const v of t.variations ?? []) {
48
- if (!v.create) continue;
56
+ if (!v.create || (v.legacy && !host.showAllBlocks)) continue;
49
57
  out.push({ key: `${t.name}/${v.name}`, title: v.standalone ? v.title : `${t.title} ${v.title}`, description: v.description, icon: v.icon ?? t.icon, keywords: `${t.keywords ?? ""} ${v.keywords ?? ""}`, category: t.category ?? "other", type: t.name, create: v.create });
50
58
  }
51
59
  }
52
60
  if (host.ai) out.push({ key: "ai-write", title: labels.aiWrite, description: labels.aiWriteHint, icon: Sparkles, keywords: "ai viet write gpt claude tro ly", category: "text", type: "paragraph", create: () => makeBlock("paragraph"), action: "ai-write" });
53
61
  return out;
54
- }, [registry, version, hidden, host.scope, host.ai, labels]);
62
+ }, [registry, version, hidden, host.scope, host.showAllBlocks, host.ai, labels]);
55
63
  }
56
64
 
57
65
  /** Lọc + xếp hạng: tên trùng hẳn > tên bắt đầu bằng chữ gõ > một từ trong tên > từ khoá; tiếng Việt không dấu. */
58
66
  export function rankOptions(list: InsertOption[], query: string): InsertOption[] {
59
67
  const q = norm(query.trim());
60
68
  if (!q) return list;
61
- const score = (i: InsertOption) => {
62
- const title = norm(i.title);
69
+ const scoreTitle = (raw: string, i: InsertOption) => {
70
+ const title = norm(raw);
63
71
  if (title === q) return 4; // "/anh" → Ảnh trước Ảnh bìa, Ảnh + chữ
64
72
  if (title.startsWith(q)) return 3;
65
73
  if (title.split(/\s+/).some((w) => w.startsWith(q))) return 2;
@@ -68,6 +76,7 @@ export function rankOptions(list: InsertOption[], query: string): InsertOption[]
68
76
  const parts = q.split(/\s+/);
69
77
  return parts.length > 1 && parts.every((p) => words.some((w) => w.startsWith(p))) ? 0.5 : 0;
70
78
  };
79
+ const score = (i: InsertOption) => Math.max(scoreTitle(i.title, i), ...(i.aliases ?? []).map((a) => scoreTitle(a, i)));
71
80
  return list.map((i) => [i, score(i)] as const).filter(([, s]) => s > 0).sort((a, b) => b[1] - a[1]).map(([i]) => i);
72
81
  }
73
82
 
@@ -83,6 +92,15 @@ export function applyInsert(ctx: ReturnType<typeof useEditor>, req: InserterRequ
83
92
  prefs.countInsert(opt.type);
84
93
  if (req.mode === "slash" && req.blockId) {
85
94
  const b = store.block(req.blockId);
95
+ const topId = node.attrs.align === "full" ? store.locate(req.blockId)?.ancestors[0] : undefined;
96
+ if (b && topId) {
97
+ // Khối rộng hết trang (Phần…) gõ "/" trong khối khác: đặt sau khối cấp cao nhất, bỏ đoạn "/từ khoá"
98
+ store.insertAfter(topId, [node], { replaceEmpty: false });
99
+ if (inlineLength(b.inline) <= (req.query?.length ?? 0) + 1) store.remove([req.blockId], { focusNeighbor: false });
100
+ ui.openInserter(null);
101
+ afterInsert(ctx, node, opt.key.includes("/"));
102
+ return;
103
+ }
86
104
  // Đoạn chỉ còn "/từ khoá" → thay cả đoạn bằng khối mới
87
105
  const parentType = store.locate(req.blockId)?.parent?.type;
88
106
  if (b && leavesItem(parentType, node.type)) {
@@ -93,6 +111,17 @@ export function applyInsert(ctx: ReturnType<typeof useEditor>, req: InserterRequ
93
111
  else store.insertAfter(req.blockId, [node]);
94
112
  } else store.insert(req.docId, req.parentId, req.index, [node]);
95
113
  ui.openInserter(null);
114
+ afterInsert(ctx, node, opt.key.includes("/"));
115
+ }
116
+ /** Việc sau mọi lần chèn khối (bảng chèn, gõ "/", rê thả): đánh dấu chữ mẫu chưa sửa, bật ô chọn bố cục nếu khối có, rồi đưa con trỏ vào ô chữ đầu tiên. */
117
+ function afterInsert(ctx: ReturnType<typeof useEditor>, node: BNode, variation = false) {
118
+ const mark = (n: BNode) => { ctx.ui.fresh.add(n.id); if (Array.isArray(n.content)) n.content.forEach(mark); };
119
+ mark(node);
120
+ const t = ctx.registry.get(node.type);
121
+ // Ô biến thể (Slider ảnh bìa…) đã chọn sẵn kiểu: không hỏi bố cục nữa
122
+ if (!variation && t?.layouts?.length && t.layoutsOnInsert !== false) ctx.ui.requestPick(node.id);
123
+ ctx.ui.focusFirstField(node.id);
124
+ ctx.ui.markInsertAnchor(node.id);
96
125
  }
97
126
  function focusOpts(node: BNode) {
98
127
  const text = firstTextId(node);
@@ -147,15 +176,20 @@ export function InserterPopover() {
147
176
  }, [ctx, ui]);
148
177
  useLayoutEffect(() => { listRef.current?.querySelector(`[data-index="${active}"]`)?.scrollIntoView({ block: "nearest" }); }, [active]);
149
178
 
150
- // Bấm ra ngoài: đóng
179
+ // Bấm ra ngoài: đóng. Pha capture vì nhiều khối chặn mousedown (stopPropagation) trước khi tới document.
151
180
  useEffect(() => {
152
181
  if (!req || req.mode === "slash") return;
153
182
  const close = (e: MouseEvent) => { if (!(e.target as Element).closest?.(".ecx-inserter-popover")) ui.openInserter(null); };
154
183
  const frameDoc = ui.canvasDoc;
155
- document.addEventListener("mousedown", close);
156
- frameDoc?.addEventListener("mousedown", close);
157
- return () => { document.removeEventListener("mousedown", close); frameDoc?.removeEventListener("mousedown", close); };
184
+ document.addEventListener("mousedown", close, true);
185
+ frameDoc?.addEventListener("mousedown", close, true);
186
+ return () => { document.removeEventListener("mousedown", close, true); frameDoc?.removeEventListener("mousedown", close, true); };
158
187
  }, [req, ui]);
188
+ // Chọn khối khác bằng đường không bấm chuột (danh sách khối, phím tắt…): đóng
189
+ const selKey = useEditorState((s) => (s.selection.ids.length ? s.selection.ids : [s.selection.editing ?? ""]).join(","));
190
+ const openSel = useRef<string | null>(null);
191
+ useEffect(() => { openSel.current = req && req.mode !== "slash" ? selKey : null; }, [req]); // eslint-disable-line react-hooks/exhaustive-deps
192
+ useEffect(() => { if (openSel.current !== null && selKey !== openSel.current) ui.openInserter(null); }, [selKey, ui]);
159
193
 
160
194
  if (!req) return null;
161
195
  if (req.mode === "slash" && !results.length) return null;
@@ -221,7 +255,7 @@ function suggestions(options: InsertOption[], counts: Record<string, number>): I
221
255
 
222
256
  const CATEGORY_ORDER = ["text", "media", "design", "widgets", "theme", "embed"];
223
257
  /** Thư viện khối (cột trái): tìm, theo nhóm; bấm để chèn sau khối đang chọn, kéo thả vào khung soạn. */
224
- export function InserterPanel({ onInserted, onClose }: { onInserted?(): void; onClose?(): void }) {
258
+ export function InserterPanel({ onInserted, onClose, initialQuery }: { onInserted?(): void; onClose?(): void; initialQuery?: string }) {
225
259
  const ctx = useEditor();
226
260
  const { store, labels } = ctx;
227
261
  useUiTick();
@@ -250,7 +284,7 @@ export function InserterPanel({ onInserted, onClose }: { onInserted?(): void; on
250
284
  frameDoc?.addEventListener("keydown", onKey);
251
285
  return () => { document.removeEventListener("keydown", onKey); frameDoc?.removeEventListener("keydown", onKey); };
252
286
  }, [onClose, ctx.ui]);
253
- const [query, setQuery] = useState("");
287
+ const [query, setQuery] = useState(initialQuery ?? "");
254
288
  const [tab, setTab] = useState<"blocks" | "patterns" | "media">("blocks");
255
289
  const [hover, setHover] = useState<{ o: InsertOption; rect: DOMRect; y: number } | null>(null);
256
290
  const results = rankOptions(options, query);
@@ -262,29 +296,50 @@ export function InserterPanel({ onInserted, onClose }: { onInserted?(): void; on
262
296
  const lastInserted = useRef<string | null>(null);
263
297
  const groups = query ? [["", results] as const] : [...CATEGORY_ORDER, ...new Set(results.map((r) => r.category).filter((c) => !CATEGORY_ORDER.includes(c)))].map((c) => [c, results.filter((r) => r.category === c)] as const).filter(([, l]) => l.length);
264
298
  const insert = (o: InsertOption) => {
299
+ // Lệnh riêng (Viết bằng AI): mở hộp thay vì chèn một đoạn trống — trước đây bấm ở bảng này chỉ ra đoạn văn rỗng, hộp AI không hiện
300
+ if (o.action === "ai-write") {
301
+ setHover(null);
302
+ const curId = store.currentIds[store.currentIds.length - 1];
303
+ const loc = curId ? store.locate(curId) : null;
304
+ const empty = !!loc && loc.block.type === "paragraph" && !loc.block.inline?.length;
305
+ const docId = loc?.docId ?? store.activeDocId;
306
+ ctx.ui.openAiWrite?.({ blockId: empty ? curId : undefined, docId, parentId: loc?.parent?.id ?? null, index: loc ? loc.index + (empty ? 0 : 1) : store.getState().docs[docId].blocks.length });
307
+ onInserted?.();
308
+ return;
309
+ }
265
310
  const node = freshWithDefaults(o.create());
311
+ setHover(null);
266
312
  ctx.prefs.countInsert(o.type);
267
313
  const cur = store.currentIds[store.currentIds.length - 1];
268
314
  // Đoạn trống đang chọn mà chính lần chèn trước vừa tạo thì giữ lại (chèn tiếp ra sau nó); đoạn trống của người dùng thì thay như WordPress
269
- const curLoc = cur ? store.locate(cur) : null;
270
- const curBlock = cur ? store.block(cur) : null;
315
+ const curLoc0 = cur ? store.locate(cur) : null;
316
+ // Khối rộng hết trang (Phần, Ảnh bìa hết trang) không nằm trong khối khác: đặt ngay sau khối cấp cao nhất đang chứa vùng chọn
317
+ const top = node.attrs.align === "full" && curLoc0?.ancestors.length ? curLoc0.ancestors[0] : null;
318
+ const curLoc = top ? store.locate(top) : curLoc0;
319
+ const curBlock = top ? store.block(top) : cur ? store.block(cur) : null;
320
+ // Vừa chèn một khối từ bảng này và vùng chọn vẫn là chỗ con trỏ tự vào (người dùng chưa bấm đi đâu): chèn tiếp NGAY SAU khối đó, cùng cấp — không lồng vào trong nó
321
+ const anchor = ctx.ui.insertAnchor;
322
+ const sameSel = !!anchor && !!store.block(anchor.id) && store.currentIds.join(",") === anchor.sel && cur !== anchor.id;
271
323
  // Đang chọn khối chứa còn trống (Nhóm, Cột… vừa tạo): chèn VÀO trong nó — chèn ra sau thì phải kéo vào thêm một bước
272
324
  if (curLoc && curBlock && Array.isArray(curBlock.content) && curBlock.content.length === 0 && canContain(curBlock.type, node.type)) store.insert(curLoc.docId, cur, 0, [node]);
273
- else if (cur && curLoc) store.insertAfter(cur, [node], { replaceEmpty: cur !== lastInserted.current });
325
+ else if (sameSel && anchor && store.locate(anchor.id)) store.insertAfter(node.attrs.align === "full" && store.locate(anchor.id)!.ancestors.length ? store.locate(anchor.id)!.ancestors[0] : anchor.id, [node], { replaceEmpty: false });
326
+ else if (cur && curLoc) store.insertAfter(top ?? cur, [node], { replaceEmpty: !top && cur !== lastInserted.current });
274
327
  else {
275
328
  const docId = store.activeDocId;
276
329
  store.insert(docId, null, store.getState().docs[docId].blocks.length, [node]);
277
330
  }
278
331
  lastInserted.current = node.id;
332
+ afterInsert(ctx, node, o.key.includes("/"));
279
333
  onInserted?.();
280
334
  };
281
335
  return (
282
336
  <div ref={panelRef} className="ecx-inserter-panel" role="dialog" aria-label={labels.addBlock} onMouseLeave={() => setHover(null)}>
283
337
  {hover && (
284
338
  // Thẻ xem trước khi rê chuột: biểu tượng, tên, mô tả của khối
285
- <div className="ecx-block-preview" role="tooltip" style={{ left: Math.round(hover.rect.right + 8), top: Math.round(Math.min(hover.y, window.innerHeight - 160)) }}>
339
+ <div className="ecx-block-preview" role="tooltip" style={{ left: Math.round(hover.rect.right + 8), top: Math.round(Math.min(hover.y, window.innerHeight - 330)) }}>
286
340
  {hover.o.icon ? <hover.o.icon className="ecx-icon" /> : <Blocks className="ecx-icon" />}
287
341
  <strong>{hover.o.title}</strong>
342
+ <LiveBlockPreview id={hover.o.key} create={hover.o.create} />
288
343
  <p>{hover.o.description ?? blockDescription(hover.o.type, labels.lang) ?? ""}</p>
289
344
  </div>
290
345
  )}
@@ -1,4 +1,5 @@
1
1
  import type { Device } from "@ecomcx/ecomweb-content";
2
+ import { VariationGrid } from "../canvas/variation-picker";
2
3
  import { CONTAINER_TAGS, CORE_BLOCK_STYLES, controlValue, optionValue } from "@ecomcx/ecomweb-content";
3
4
  import { Blocks, Info, LayoutPanelTop, Paintbrush, SlidersHorizontal } from "lucide-react";
4
5
  import { useState, useSyncExternalStore } from "react";
@@ -7,6 +8,7 @@ import { useEditor, useEditorState, useUiTick } from "../context";
7
8
  import type { BNode } from "../core/model";
8
9
  import { AttrForm, Field, attrName, cx } from "./attr-form";
9
10
  import { BindingsPanel, CORE_BINDABLE } from "./bindings";
11
+ import { OverrideKeySection, PatternOverridesSection } from "./pattern-overrides";
10
12
  import { StyleTab } from "./style-tab";
11
13
  import { LayoutSection } from "./layout-panel";
12
14
  import { GroupWidthSection } from "./group-width";
@@ -22,12 +24,11 @@ import { ColorInput } from "./color-field";
22
24
  import { UnitInput } from "./unit-controls";
23
25
  import { useMsgs } from "../i18n";
24
26
 
25
- /** Khối "khung" (như Container / Section của Elementor): ô Nền đặt ngay tab Cài đặt — chỗ người dùng tìm đầu tiên. */
26
27
  // Nền của Nhóm / Cột nằm ở tab Kiểu dáng như bộ khối lớn; ảnh bìa: nền là nội dung chính nên ở Cài đặt
27
- const BG_IN_SETTINGS = new Set(["cover", "group"]);
28
+ const BG_IN_SETTINGS = new Set(["cover"]);
28
29
  /** Khối chứa đổi được thẻ HTML (attrs.tagName). */
29
30
  const TAGGED = new Set(["group", "column", "columns"]);
30
- const BG_FIRST = new Set(["column", "columns", "row", "stack", "grid"]);
31
+ const BG_FIRST = new Set(["column", "columns", "row", "stack", "grid", "group"]);
31
32
 
32
33
  /**
33
34
  * Bảng cài đặt của khối đang chọn (như Elementor): thẻ khối, tab Cài đặt (nội dung: form + phần riêng của khối), tab Kiểu dáng
@@ -37,6 +38,7 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
37
38
  const { store, registry, labels, ui } = useEditor();
38
39
  useUiTick();
39
40
  const t = useMsgs("controls");
41
+ const tb = useMsgs("blocks") as unknown as Record<string, string>;
40
42
  const sel = useEditorState((s) => s.selection);
41
43
  useEditorState((s) => s.revision);
42
44
  const [tab, setTab] = useState<"settings" | "style" | "advanced">("settings");
@@ -57,13 +59,13 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
57
59
  const hasParts = single && blockControls().some((c) => c.partsOnly && c.parts && (c.blocks === "*" || c.blocks.includes(first.type)));
58
60
  const Custom = single ? type?.inspector : undefined;
59
61
  const styled = type?.supports?.style !== false && !store.isContentOnly(first.id);
60
- const bindable = type?.bindable ?? CORE_BINDABLE[first.type];
62
+ const bindable = type?.bindable ?? (CORE_BINDABLE[first.type] as string[] | undefined);
61
63
  const variants = [...(CORE_BLOCK_STYLES[first.type] ?? []).map((name) => ({ name, label: (t.blockStyle as Record<string, string>)[name] ?? name })), ...(blockStyles?.[first.type] ?? [])];
62
64
  return (
63
65
  <div className="ecx-inspector">
64
66
  <div className="ecx-block-card">
65
67
  <Icon className="ecx-icon ecx-card-icon" />
66
- <strong>{nodes.length > 1 ? `${nodes.length} ${labels.blocks}` : (typeof first.attrs.customName === "string" && first.attrs.customName) || (type?.title ?? first.type)}</strong>
68
+ <strong>{nodes.length > 1 ? `${nodes.length} ${labels.blocks}` : (typeof first.attrs.customName === "string" && first.attrs.customName) || (type?.titleOf?.(first.attrs) ?? type?.title ?? first.type)}</strong>
67
69
  {/* Mô tả khối: nút ⓘ (rê / bấm) thay cho 2–3 dòng chữ chiếm chỗ đầu bảng */}
68
70
  {type?.description && nodes.length === 1 && <span className="ecx-card-info" tabIndex={0} role="note" aria-label={type.description} title={type.description}><Info className="ecx-icon" /><span className="ecx-card-tip">{type.description}</span></span>}
69
71
  </div>
@@ -79,11 +81,13 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
79
81
  {tab === "settings" || (tab === "style" && !styled) ? (
80
82
  <div className="ecx-panel">
81
83
  {single && first.type === "group" && <GroupWidthSection attrs={first.attrs} setAttrs={setAttrs} />}
84
+ {single && type?.layouts?.length && !disabled && <div className="ecx-layout-section"><span className="ecx-field-label">{tb.layoutLabel}</span><VariationGrid type={type} attrs={first.attrs} onPick={(v) => setAttrs(v.attrs)} /></div>}
82
85
  {same && type && <AttrForm type={type} attrs={first.attrs} onChange={setAttrs} />}
86
+ {single && styled && <BlockStyleSections tab="settings" type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />}
83
87
  {styled && single && BG_IN_SETTINGS.has(first.type) && <BackgroundControl key={first.id} type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />}
84
- {styled && single && first.type === "group" && <DividerSection key={`d${first.id}`} attrs={first.attrs} setAttrs={setAttrs} />}
85
88
  {styled && single && <LayoutSection type={first.type} style={first.attrs.style} onChange={(st) => setAttrs({ style: st ?? undefined })} device={device} />}
86
89
  {Custom && <Custom block={first} attrs={first.attrs} setAttrs={setAttrs} blockProps={null as never} selected editable labels={labels} />}
90
+ {single && first.type === "syncedPattern" && <PatternOverridesSection block={first} setAttrs={setAttrs} />}
87
91
  {same && nodes.length === 1 && <PluginPanels type={first.type} attrs={first.attrs} setAttrs={setAttrs} />}
88
92
  {nodes.length === 1 && bindable?.length && <BindingsPanel block={first} bindable={bindable} onChange={(b) => setAttrs({ bindings: b })} />}
89
93
  </div>
@@ -91,6 +95,7 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
91
95
  <div className="ecx-panel">
92
96
  {/* Khối chứa: Nền là mục đầu của tab Kiểu dáng (như bộ khối lớn) */}
93
97
  {single && BG_FIRST.has(first.type) && <BackgroundControl key={first.id} type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />}
98
+ {single && (first.type === "group" || first.type === "columns") && <DividerSection key={`d${first.id}`} attrs={first.attrs} setAttrs={setAttrs} />}
94
99
  <StyleTab type={first.type} style={first.attrs.style} onChange={(st) => setAttrs({ style: st ?? undefined })} device={device} onDeviceChange={setDevice} part="style"
95
100
  variants={variants.length ? variants : undefined} variant={(first.attrs.blockStyle as string) ?? null} onVariantChange={(v) => setAttrs({ blockStyle: v ?? undefined })}
96
101
  parts={hasParts}
@@ -117,6 +122,7 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
117
122
  <Field label={attrName("className", labels.lang) ?? "className"}><input className="ecx-input" value={String(first.attrs.className ?? "")} onChange={(e) => setAttrs({ className: e.target.value || undefined })} /></Field>
118
123
  </Section>
119
124
  )}
125
+ {single && <OverrideKeySection block={first} setAttrs={setAttrs} />}
120
126
  {nodes.length === 1 && <PluginPanels type={first.type} attrs={first.attrs} setAttrs={setAttrs} tab="advanced" />}
121
127
  </div>
122
128
  )}
@@ -10,7 +10,7 @@ import { Row, Section, Seg, cx } from "./style-controls";
10
10
  * Giá trị theo khổ (hướng, căn, số cột) sửa theo khổ đang chọn ở bảng Kiểu dáng (`device`).
11
11
  */
12
12
  /** Khối chứa (có khối con) mới có mục Bố cục. */
13
- const CONTAINERS = new Set(["group", "cover", "blockquote", "callout", "details", "query", "postTemplate", "mediaText"]);
13
+ const CONTAINERS = new Set(["group", "cover", "blockquote", "details", "query", "postTemplate"]);
14
14
 
15
15
  type Kind = "flow" | "row" | "stack" | "grid";
16
16
  export const layoutKind = (l?: BlockLayout): Kind => (!l ? "flow" : l.type === "grid" ? "grid" : l.direction?.base === "column" ? "stack" : "row");