@ecomcx/ecomweb-editor 1.30.0 → 1.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/package.json +3 -3
  2. package/src/locales/en/attrs.ts +10 -0
  3. package/src/locales/en/background.ts +17 -0
  4. package/src/locales/en/block-desc.ts +1 -0
  5. package/src/locales/en/block-style.ts +7 -4
  6. package/src/locales/en/block-titles.ts +1 -0
  7. package/src/locales/en/blocks.ts +10 -2
  8. package/src/locales/en/columns.ts +12 -0
  9. package/src/locales/en/controls.ts +21 -0
  10. package/src/locales/en/hints.ts +215 -1
  11. package/src/locales/en/index.ts +6 -2
  12. package/src/locales/en/layout.ts +32 -0
  13. package/src/locales/en/legacy.ts +1 -1
  14. package/src/locales/en/library.ts +38 -0
  15. package/src/locales/en/parts.ts +12 -0
  16. package/src/locales/en/placeholders.ts +104 -0
  17. package/src/locales/en/presets.ts +6 -0
  18. package/src/locales/en/v2.ts +21 -0
  19. package/src/locales/vi/attrs.ts +10 -0
  20. package/src/locales/vi/background.ts +17 -0
  21. package/src/locales/vi/block-desc.ts +1 -0
  22. package/src/locales/vi/block-style.ts +7 -4
  23. package/src/locales/vi/block-titles.ts +1 -0
  24. package/src/locales/vi/blocks.ts +10 -2
  25. package/src/locales/vi/columns.ts +12 -0
  26. package/src/locales/vi/controls.ts +21 -0
  27. package/src/locales/vi/hints.ts +216 -2
  28. package/src/locales/vi/index.ts +6 -2
  29. package/src/locales/vi/layout.ts +32 -0
  30. package/src/locales/vi/legacy.ts +1 -1
  31. package/src/locales/vi/library.ts +38 -0
  32. package/src/locales/vi/parts.ts +12 -0
  33. package/src/locales/vi/placeholders.ts +103 -0
  34. package/src/locales/vi/presets.ts +6 -0
  35. package/src/locales/vi/v2.ts +21 -0
  36. package/src/shared/panel-store.ts +3 -3
  37. package/src/shared/patterns.ts +3 -52
  38. package/src/shared/style-panel.tsx +2 -2
  39. package/src/shared/types.ts +2 -0
  40. package/src/v2/blocks/columns-inspector.tsx +210 -0
  41. package/src/v2/blocks/compat.tsx +91 -5
  42. package/src/v2/blocks/form.tsx +7 -4
  43. package/src/v2/blocks/index.ts +10 -4
  44. package/src/v2/blocks/inline-style.ts +1 -1
  45. package/src/v2/blocks/layout.tsx +305 -83
  46. package/src/v2/blocks/media.tsx +91 -81
  47. package/src/v2/blocks/resize.tsx +172 -4
  48. package/src/v2/blocks/text.tsx +60 -22
  49. package/src/v2/blocks/theme.tsx +83 -17
  50. package/src/v2/blocks/tools.tsx +50 -5
  51. package/src/v2/blocks/widgets.tsx +85 -20
  52. package/src/v2/canvas/block-list.tsx +21 -6
  53. package/src/v2/canvas/canvas-css.ts +139 -7
  54. package/src/v2/canvas/canvas.tsx +20 -3
  55. package/src/v2/canvas/dnd.ts +34 -3
  56. package/src/v2/canvas/move-animation.ts +94 -0
  57. package/src/v2/canvas/server-block.tsx +7 -4
  58. package/src/v2/canvas/spacing-viz.ts +51 -0
  59. package/src/v2/core/block-presets.ts +68 -0
  60. package/src/v2/core/host.ts +14 -0
  61. package/src/v2/core/registry.ts +3 -1
  62. package/src/v2/core/structure.ts +4 -2
  63. package/src/v2/editor.css +244 -11
  64. package/src/v2/editor.tsx +8 -2
  65. package/src/v2/index.ts +3 -0
  66. package/src/v2/ui/ai.tsx +9 -5
  67. package/src/v2/ui/attr-form.tsx +42 -13
  68. package/src/v2/ui/attr-hints.ts +104 -6
  69. package/src/v2/ui/background-panel.tsx +65 -21
  70. package/src/v2/ui/block-icons.tsx +152 -0
  71. package/src/v2/ui/block-menu.ts +22 -0
  72. package/src/v2/ui/block-style-panel.tsx +14 -3
  73. package/src/v2/ui/color-field.tsx +74 -9
  74. package/src/v2/ui/divider-panel.tsx +58 -0
  75. package/src/v2/ui/group-width.tsx +38 -0
  76. package/src/v2/ui/icon-picker.tsx +51 -0
  77. package/src/v2/ui/inserter.tsx +51 -7
  78. package/src/v2/ui/inspector.tsx +48 -16
  79. package/src/v2/ui/layout-panel.tsx +5 -47
  80. package/src/v2/ui/list-view.tsx +81 -7
  81. package/src/v2/{blocks → ui}/media-actions.tsx +4 -3
  82. package/src/v2/ui/motion-panel.tsx +2 -1
  83. package/src/v2/ui/parts-panel.tsx +164 -0
  84. package/src/v2/ui/pattern-library.tsx +228 -0
  85. package/src/v2/ui/placeholders.tsx +205 -0
  86. package/src/v2/ui/preset-bar.tsx +83 -0
  87. package/src/v2/ui/style-controls.tsx +65 -15
  88. package/src/v2/ui/style-supports.ts +1 -1
  89. package/src/v2/ui/style-tab.tsx +127 -41
  90. package/src/v2/ui/toolbar.tsx +59 -16
  91. package/src/v2/ui/unit-controls.tsx +88 -39
  92. package/src/locales/en/patterns.ts +0 -50
  93. package/src/locales/vi/patterns.ts +0 -50
  94. package/src/shared/patterns-kit.ts +0 -7
  95. package/src/shared/patterns-library.ts +0 -172
@@ -1,14 +1,14 @@
1
1
  import { normalizeStyle, type BlockStyle, type Device } from "@ecomcx/ecomweb-content";
2
- import { AlignCenter, AlignJustify, AlignLeft, AlignRight, Monitor, Smartphone, Tablet } from "lucide-react";
2
+ import { AlignCenter, AlignJustify, AlignLeft, AlignRight } from "lucide-react";
3
3
  import { useEffect, useState, type ReactNode } from "react";
4
4
  import { labelsLegacy, type EditorLabels } from "../../shared/labels";
5
5
  import { useEditor } from "../context";
6
6
  import { ColorInput } from "./color-field";
7
- import { LayoutEffectsPanel } from "./layout-panel";
7
+ import { GradientField } from "./layout-panel";
8
8
  import { MotionPanel } from "./motion-panel";
9
- import { Section, Seg, cx } from "./style-controls";
9
+ import { Row, Section, Seg, StateTabs, cx } from "./style-controls";
10
10
  import { styleGroups, type StyleGroup } from "./style-supports";
11
- import { SpacingControl, UnitInput } from "./unit-controls";
11
+ import { FourInput, SpacingControl, UnitInput } from "./unit-controls";
12
12
  import { useMsgs } from "../i18n";
13
13
 
14
14
  /**
@@ -17,12 +17,18 @@ import { useMsgs } from "../i18n";
17
17
  * chưa đặt cho khổ nhỏ thì hiện giá trị kế thừa từ khổ lớn hơn.
18
18
  */
19
19
  type Style = BlockStyle & Record<string, any>;
20
- const RESPONSIVE = new Set(["padding", "margin", "gap", "width", "maxWidth", "minHeight", "fontSize", "lineHeight", "letterSpacing", "textAlign"]);
20
+ const RESPONSIVE = new Set(["padding", "margin", "gap", "width", "maxWidth", "minHeight", "fontSize", "lineHeight", "letterSpacing", "textAlign", "order"]);
21
21
  const SIZES = ["sm", "md", "lg", "xl", "2xl"];
22
22
  const SPACES = ["0", "xs", "sm", "md", "lg", "xl", "2xl"];
23
23
  const WEIGHTS = ["300", "400", "500", "600", "700", "800", "900"];
24
- const TYPO = ["fontFamily", "fontSize", "lineHeight", "letterSpacing", "fontWeight", "fontStyle", "textDecoration", "textTransform", "textAlign"];
25
- const SPACING = ["padding", "margin", "gap", "width", "maxWidth", "minHeight"];
24
+ const TYPO = ["fontFamily", "fontSize", "lineHeight", "letterSpacing", "fontWeight", "fontStyle", "textDecoration", "textTransform", "textAlign", "textShadow", "writingMode"];
25
+ const SPACING = ["padding", "margin"];
26
+ const STRUCTURE = ["gap", "width", "maxWidth", "minHeight", "aspectRatio", "zIndex", "grow", "order"];
27
+ type State = "normal" | "hover";
28
+
29
+ /** Bậc preset theo cỡ tăng dần (theme có thể khai lộn thứ tự: lg trước md). Tên lạ giữ thứ tự khai, đứng sau. */
30
+ const STEP_ORDER = ["0", "none", "3xs", "2xs", "xxs", "xs", "sm", "md", "base", "lg", "xl", "2xl", "xxl", "3xl", "4xl", "5xl", "6xl"];
31
+ export const byStep = (keys: string[]) => [...keys].sort((a, b) => { const i = STEP_ORDER.indexOf(a), j = STEP_ORDER.indexOf(b); return (i < 0 ? 99 : i) - (j < 0 ? 99 : j); });
26
32
 
27
33
  /** Ô giá trị (preset như `lg` hoặc `16px`, `1.5rem`…): lưu khi rời ô / Enter; sai thì viền đỏ, không lưu. */
28
34
  function ValueInput({ value, onCommit, check, placeholder, label, inherited }: { value?: string | number; onCommit(v: string | null): void; check(v: string): boolean; placeholder?: string; label: string; inherited?: string }) {
@@ -44,18 +50,44 @@ function ValueInput({ value, onCommit, check, placeholder, label, inherited }: {
44
50
  * `part`: "style" = biến thể, chữ, màu (tab Kiểu dáng); "advanced" = khoảng cách, viền, bố cục / hiệu ứng, hover, chuyển động, ẩn hiện
45
51
  * (tab Nâng cao — lớp chung của mọi khối như Advanced của Elementor); bỏ trống = tất cả. Ô Nền vẽ ở BackgroundControl.
46
52
  */
47
- export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, variants, variant, onVariantChange, part, lead }: {
53
+ function TextShadowRow({ style, set }: { style: BlockStyle; set(k: "textShadow", v: BlockStyle["textShadow"]): void }) {
54
+ const lt = useMsgs("layout") as Record<string, string>;
55
+ const sh = style.textShadow;
56
+ const put = (p: Partial<NonNullable<BlockStyle["textShadow"]>>) => set("textShadow", { x: 0, y: 2, blur: 4, color: "black/30", ...sh, ...p });
57
+ return (
58
+ <>
59
+ <label className="ecx-check-row"><input type="checkbox" role="switch" className="ecx-switch" aria-label={lt.textShadow} checked={!!sh} onChange={(e) => set("textShadow", e.target.checked ? { x: 0, y: 2, blur: 4, color: "black/30" } : undefined)} /> {lt.textShadow}</label>
60
+ {sh && (
61
+ <div className="ecx-textshadow">
62
+ {([["x", lt.tsX, -20, 20], ["y", lt.tsY, -20, 20], ["blur", lt.tsBlur, 0, 40]] as const).map(([k, label, min, max]) => (
63
+ <label key={k} className="ecx-textshadow-row"><span>{label}: {sh[k]}px</span><input type="range" className="ecx-range" min={min} max={max} aria-label={label} value={sh[k]} onChange={(e) => put({ [k]: Number(e.target.value) })} /></label>
64
+ ))}
65
+ <ColorInput label={lt.tsColor} value={sh.color} onChange={(c) => put({ color: c ?? "black/30" })} />
66
+ </div>
67
+ )}
68
+ </>
69
+ );
70
+ }
71
+
72
+ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, variants, variant, onVariantChange, part, lead, parts, structure }: {
48
73
  type: string; style: unknown; onChange(style: BlockStyle | null): void; device: Device; onDeviceChange(d: Device): void;
49
74
  variants?: Array<{ name: string; label: string }>; variant?: string | null; onVariantChange?(v: string | null): void; part?: "style" | "advanced";
50
75
  /** Mục vẽ sau Chữ / Màu (mục riêng của khối, ô Nền). */
51
76
  lead?: ReactNode;
77
+ /** Ô đứng đầu mục Cấu trúc (vd thẻ HTML của khối chứa — là thuộc tính của khối, không nằm trong style). */
78
+ structure?: ReactNode;
79
+ /** Khối chia phần: các phần đứng đầu; Kiểu chữ / Màu chung của cả khối chỉ hiện khi đã có giá trị (nội dung cũ). */
80
+ parts?: boolean;
52
81
  }) {
53
82
  const { host, labels, registry } = useEditor();
54
83
  const t = labelsLegacy(labels.lang);
55
84
  const ct = useMsgs("controls");
85
+ const lt = useMsgs("layout");
86
+ const [colorState, setColorState] = useState<State>("normal");
87
+ const [borderState, setBorderState] = useState<State>("normal");
56
88
  const presets = host.presets;
57
- const sizes = presets?.fontSizes ? Object.keys(presets.fontSizes) : SIZES;
58
- const spaces = presets?.spacing ? ["0", ...Object.keys(presets.spacing)] : SPACES;
89
+ const sizes = presets?.fontSizes ? byStep(Object.keys(presets.fontSizes)) : SIZES;
90
+ const spaces = presets?.spacing ? ["0", ...byStep(Object.keys(presets.spacing))] : SPACES;
59
91
  const fonts = presets?.fonts ? Object.keys(presets.fonts) : ["body", "heading", "mono"];
60
92
  const style: Style = (normalizeStyle(raw) ?? {}) as Style;
61
93
 
@@ -75,7 +107,7 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
75
107
  } else next[k] = v === "" ? undefined : v;
76
108
  commit(next);
77
109
  };
78
- const setGroup = (k: "color" | "border", sub: string, v: unknown) => set(k, { ...(style[k] ?? {}), [sub]: v });
110
+ const setGroup = (k: "color" | "border" | "link", sub: string, v: unknown) => set(k, { ...(style[k] ?? {}), [sub]: v });
79
111
  // Khoá theo khổ (cỡ chữ, khoảng cách…): chỉ bỏ giá trị của khổ đang chọn, không xoá các khổ khác
80
112
  const reset = (keys: string[]) => {
81
113
  const next: Style = { ...style };
@@ -89,23 +121,33 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
89
121
  };
90
122
  const has = (keys: string[]) => keys.some((k) => RESPONSIVE.has(k) && device !== "base" ? style[k]?.[device] !== undefined : style[k] !== undefined);
91
123
  const ok = (k: string) => (v: string) => !!normalizeStyle({ [k]: v });
92
- const tag = (k: string) => RESPONSIVE.has(k) && device !== "base" ? <em className="ecx-device-tag">{t[`device_${device}` as keyof EditorLabels]}</em> : null;
93
- const row = (k: string, label: string, control: ReactNode) => (
94
- <div className="ecx-style-row" key={k}><span className="ecx-field-label">{label}{tag(k)}</span>{control}</div>
95
- );
124
+ // Ô chuẩn: cụm khổ màn hình nếu ô chỉnh theo khổ; nút ↶ khi ô (ở khổ đang xem) đã có giá trị
125
+ const KEYS: Record<string, string[]> = { appearance: ["fontWeight", "fontStyle"], decoration: ["textDecoration"], transform: ["textTransform"], borderWidth: [], borderStyle: [], borderColor: [] };
126
+ const row = (k: string, label: string, control: ReactNode) => {
127
+ const keys = KEYS[k] ?? [k];
128
+ return <Row key={k} label={label} device={RESPONSIVE.has(k) ? device : undefined} onReset={keys.length && has(keys) ? () => reset(keys) : undefined}>{control}</Row>;
129
+ };
96
130
  // Nhóm khối hỗ trợ; nhóm đã có giá trị vẫn hiện để sửa / xoá (dữ liệu cũ, khối dán từ nơi khác)
97
131
  const groups = styleGroups(type, registry.get(type));
98
- const inPart = (g: StyleGroup) => !part || (part === "style") === ["typography", "color"].includes(g);
99
- const show = (g: StyleGroup, keys: string[]) => inPart(g) && (groups.has(g) || keys.some((k) => style[k] !== undefined));
132
+ // Như bộ khối lớn: Kiểu dáng = chữ, màu, viền, nền & hiệu ứng, khi rê chuột; Nâng cao = khoảng cách, bố cục, ghim, chuyển động, hiển thị
133
+ const inPart = (g: StyleGroup) => !part || (part === "style") === ["typography", "color", "border"].includes(g);
134
+ const show = (g: StyleGroup, keys: string[]) => inPart(g) && ((groups.has(g) && !(parts && (g === "typography" || g === "color"))) || keys.some((k) => style[k] !== undefined));
135
+ const container = registry.get(type)?.kind === "container";
136
+ // Trạng thái rê chuột nằm ngay trong mục Màu / Viền (công tắc Thường · Rê chuột), không còn mục "Khi rê chuột" riêng
137
+ const hoverOk = groups.has("hover") || style.hover !== undefined;
138
+ const fxOk = groups.has("effects") || ["gradient", "shadow", "aspectRatio", "position"].some((k) => style[k] !== undefined);
139
+ const setHover = (patch: NonNullable<BlockStyle["hover"]>) => set("hover", { ...style.hover, ...patch });
140
+ const shadows = ["sm", "md", "lg", "xl", ...Object.keys(presets?.shadows ?? {}).filter((x) => !["sm", "md", "lg", "xl"].includes(x))];
141
+ const shadowSelect = (value: string | undefined, onPick: (v: string | undefined) => void, label: string, none = true) => (
142
+ <select className="ecx-input" aria-label={label} value={value ?? ""} onChange={(e) => onPick(e.target.value || undefined)}>
143
+ <option value="">—</option>{none && <option value="none">{lt.none}</option>}
144
+ {shadows.map((x) => <option key={x} value={x}>{x.toUpperCase()}</option>)}
145
+ </select>
146
+ );
100
147
  const appearance = `${style.fontWeight ?? ""}${style.fontStyle === "italic" ? "i" : ""}`;
101
148
 
102
149
  return (
103
150
  <div className="ecx-style-tab">
104
- <div className="ecx-style-device">
105
- <span className="ecx-field-label">{t.device}</span>
106
- <Seg label={t.device} value={device} onChange={(d) => onDeviceChange(d ?? "base")}
107
- options={[["base", Monitor, t.device_base], ["tablet", Tablet, t.device_tablet], ["mobile", Smartphone, t.device_mobile]]} />
108
- </div>
109
151
 
110
152
  {part !== "advanced" && variants && variants.length > 0 && (
111
153
  <div className="ecx-style-row">
@@ -119,7 +161,9 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
119
161
  </div>
120
162
  )}
121
163
 
122
- {show("typography", TYPO) && <Section title={t.style_typography} modified={has(TYPO)} onReset={() => reset(TYPO)} moreOpen={has(["fontFamily", "letterSpacing", "textDecoration", "textTransform"])}
164
+ {parts && lead}
165
+
166
+ {show("typography", TYPO) && <Section title={t.style_typography} modified={has(TYPO)} onReset={() => reset(TYPO)} moreOpen={has(["fontFamily", "letterSpacing", "textDecoration", "textTransform", "textShadow", "writingMode"])}
123
167
  more={<>
124
168
  {row("fontFamily", t.style_fontFamily,
125
169
  <select className="ecx-input" value={style.fontFamily ?? ""} aria-label={t.style_fontFamily} onChange={(e) => set("fontFamily", e.target.value || undefined)}>
@@ -131,6 +175,9 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
131
175
  options={[["none", "—", t.none], ["underline", "U̲", t.underlineText], ["line-through", "S̶", t.strikeText]]} />)}
132
176
  {row("transform", t.style_transform, <Seg label={t.style_transform} value={style.textTransform} onChange={(v) => set("textTransform", v)}
133
177
  options={[["none", "—", t.none], ["uppercase", "AB", t.upper], ["lowercase", "ab", t.lower], ["capitalize", "Ab", t.capitalize]]} />)}
178
+ {row("writingMode", lt.writingMode, <Seg label={lt.writingMode} value={style.writingMode ?? "horizontal"} onChange={(v) => set("writingMode", v === "vertical" ? "vertical" : undefined)}
179
+ options={[["horizontal", lt.wmHorizontal, lt.wmHorizontal], ["vertical", lt.wmVertical, lt.wmVertical]]} />)}
180
+ <TextShadowRow style={style} set={set} />
134
181
  </>}>
135
182
  {row("fontSize", t.style_fontSize, <>
136
183
  <Seg label={t.style_fontSize} value={get("fontSize")} onChange={(v) => set("fontSize", v)} options={sizes.map((v) => [v, v.toUpperCase(), presets?.fontSizes?.[v] ? `${v} · ${presets.fontSizes[v]}` : v] as [string, string, string])} />
@@ -150,31 +197,70 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
150
197
  options={[["left", AlignLeft, t.alignLeft], ["center", AlignCenter, t.alignCenter], ["right", AlignRight, t.alignRight], ["justify", AlignJustify, t.alignJustify]]} />)}
151
198
  </Section>}
152
199
 
153
- {show("color", ["color"]) && <Section title={t.style_color} modified={has(["color"])} onReset={() => reset(["color"])}>
154
- {row("text", t.style_text, <ColorInput label={t.style_text} value={style.color?.text} onChange={(v) => setGroup("color", "text", v)} />)}
155
- {/* Khối có ô Nền: màu nền sửa ở đó (một chỗ) */}
156
- {(!groups.has("background") || part === undefined) && row("background", t.style_background, <ColorInput label={t.style_background} value={style.color?.background} onChange={(v) => setGroup("color", "background", v)} />)}
200
+ {show("color", ["color", "textGradient", "link"]) && <Section title={t.style_color} modified={has(["color", "textGradient", "link"]) || !!style.hover?.color} onReset={() => commit({ ...style, color: undefined, textGradient: undefined, link: undefined, hover: style.hover && { ...style.hover, color: undefined } })}>
201
+ {hoverOk && <StateTabs value={colorState} onChange={setColorState} />}
202
+ {hoverOk && colorState === "hover" ? <>
203
+ <ColorInput label={t.style_text} value={style.hover?.color?.text} onChange={(v) => setHover({ color: { ...style.hover?.color, text: v } })} />
204
+ {!groups.has("background") && <ColorInput label={t.style_background} value={style.hover?.color?.background} onChange={(v) => setHover({ color: { ...style.hover?.color, background: v } })} />}
205
+ {container && <ColorInput label={t.style_linkHover} value={style.link?.hover} onChange={(v) => setGroup("link", "hover", v)} />}
206
+ </> : <>
207
+ <ColorInput label={t.style_text} value={style.color?.text} onChange={(v) => setGroup("color", "text", v)} />
208
+ {/* Khối có ô Nền: màu nền / nền chuyển màu sửa ở đó (một chỗ) */}
209
+ {!groups.has("background") && <ColorInput label={t.style_background} value={style.color?.background} onChange={(v) => setGroup("color", "background", v)} />}
210
+ {!groups.has("background") && fxOk && <Row label={lt.gradient} onReset={has(["gradient"]) ? () => reset(["gradient"]) : undefined}><GradientField value={style.gradient} onChange={(v) => set("gradient", v)} /></Row>}
211
+ <Row label={t.style_textGradient} onReset={has(["textGradient"]) ? () => reset(["textGradient"]) : undefined}><GradientField value={style.textGradient} onChange={(v) => set("textGradient", v)} /></Row>
212
+ {/* Khối chứa: màu liên kết của nội dung bên trong (Đoạn / Tiêu đề có mục Liên kết riêng) */}
213
+ {container && <ColorInput label={t.style_link} value={style.link?.color} onChange={(v) => setGroup("link", "color", v)} />}
214
+ {container && !hoverOk && <ColorInput label={t.style_linkHover} value={style.link?.hover} onChange={(v) => setGroup("link", "hover", v)} />}
215
+ </>}
157
216
  </Section>}
158
217
 
159
- {lead}
218
+ {!parts && lead}
160
219
 
161
- {show("spacing", SPACING) && <Section title={t.style_spacing} modified={has(SPACING)} onReset={() => reset(SPACING)} moreOpen={has(["gap", "width", "maxWidth", "minHeight"])}
162
- more={<>{(["gap", "width", "maxWidth", "minHeight"] as const).map((k) =>
163
- row(k, t[`style_${k}`], <ValueInput label={t[`style_${k}`]} value={get(k)} inherited={inherited(k)} check={ok(k)} placeholder={k === "gap" ? "md, 24px" : "100%, 640px, 60vh"} onCommit={(v) => set(k, v)} />))}</>}>
164
- <SpacingControl label={t.style_padding} steps={spaces} value={get("padding")} inherited={inherited("padding")} onChange={(v) => set("padding", v)} labels={{ vertical: ct.vertical, horizontal: ct.horizontal, top: ct.sideTop, right: ct.sideRight, bottom: ct.sideBottom, left: ct.sideLeft, link: t.linkSides, unlink: t.unlinkSides }} />
165
- <SpacingControl label={t.style_margin} steps={spaces} value={get("margin")} inherited={inherited("margin")} onChange={(v) => set("margin", v)} labels={{ vertical: ct.vertical, horizontal: ct.horizontal, top: ct.sideTop, right: ct.sideRight, bottom: ct.sideBottom, left: ct.sideLeft, link: t.linkSides, unlink: t.unlinkSides }} />
220
+ {show("spacing", SPACING) && <Section title={t.style_spacing} modified={has(SPACING)} onReset={() => reset(SPACING)}>
221
+ <SpacingControl kind="padding" device={device} onReset={has(["padding"]) ? () => reset(["padding"]) : undefined} label={t.style_padding} steps={spaces} value={get("padding")} inherited={inherited("padding")} onChange={(v) => set("padding", v)} labels={{ vertical: ct.vertical, horizontal: ct.horizontal, top: ct.sideTop, right: ct.sideRight, bottom: ct.sideBottom, left: ct.sideLeft, link: t.linkSides, unlink: t.unlinkSides }} />
222
+ <SpacingControl kind="margin" device={device} onReset={has(["margin"]) ? () => reset(["margin"]) : undefined} label={t.style_margin} steps={spaces} value={get("margin")} inherited={inherited("margin")} onChange={(v) => set("margin", v)} labels={{ vertical: ct.vertical, horizontal: ct.horizontal, top: ct.sideTop, right: ct.sideRight, bottom: ct.sideBottom, left: ct.sideLeft, link: t.linkSides, unlink: t.unlinkSides }} />
166
223
  </Section>}
167
224
 
168
- {show("border", ["border", "radius"]) && <Section title={t.style_border} modified={has(["border", "radius"])} onReset={() => reset(["border", "radius"])} defaultOpen={has(["border", "radius"])}>
169
- {row("borderWidth", t.style_borderWidth, <UnitInput label={t.style_borderWidth} value={style.border?.width} max={20} units={["px", "em", "rem"]} onChange={(v) => setGroup("border", "width", v)} />)}
170
- {row("borderStyle", t.style_borderStyle, <Seg label={t.style_borderStyle} value={style.border?.style} onChange={(v) => setGroup("border", "style", v)}
171
- options={[["solid", "—", t.border_solid], ["dashed", "- -", t.border_dashed], ["dotted", "···", t.border_dotted]]} />)}
172
- {row("borderColor", t.style_borderColor, <ColorInput label={t.style_borderColor} value={style.border?.color} onChange={(v) => setGroup("border", "color", v)} />)}
173
- {row("radius", t.style_radius, <UnitInput label={t.style_radius} value={typeof style.radius === "string" ? style.radius : undefined} max={60} units={["px", "%", "em", "rem"]} onChange={(v) => set("radius", v)} />)}
225
+ {/* Cấu trúc: kích thước khối (rộng, rộng tối đa, cao tối thiểu, tỉ lệ khung), khe giữa khối con */}
226
+ {inPart("spacing") && (groups.has("spacing") || has(STRUCTURE)) && <Section title={ct.structure} modified={has(STRUCTURE)} onReset={() => reset(STRUCTURE)} defaultOpen={has(STRUCTURE)}>
227
+ {structure}
228
+ {(["width", "maxWidth", "minHeight", ...(container ? ["gap" as const] : [])] as const).map((k) =>
229
+ row(k, t[`style_${k}`], <ValueInput label={t[`style_${k}`]} value={get(k)} inherited={inherited(k)} check={ok(k)} placeholder={k === "gap" ? "md, 24px" : "100%, 640px, 60vh"} onCommit={(v) => set(k, v)} />))}
230
+ {container && ([["zIndex", -1, 9999], ["grow", 0, 10], ["order", -10, 10]] as const).map(([k, min, max]) =>
231
+ row(k, ct[k], <input className="ecx-input" type="number" min={min} max={max} step={1} aria-label={ct[k]} value={get(k) ?? ""} placeholder={inherited(k)}
232
+ onChange={(e) => set(k, e.target.value === "" ? undefined : Number(e.target.value))} />))}
233
+ {container && <p className="ecx-field-help">{ct.orderHelp}</p>}
234
+ {fxOk && row("aspectRatio", lt.ratio,
235
+ <select className="ecx-input" aria-label={lt.ratio} value={style.aspectRatio ?? ""} onChange={(e) => set("aspectRatio", e.target.value || undefined)}>
236
+ <option value="">—</option>
237
+ {["1/1", "4/3", "3/2", "16/9", "21/9", "3/4", "2/3", "9/16"].map((r) => <option key={r} value={r}>{r.replace("/", ":")}</option>)}
238
+ </select>)}
174
239
  </Section>}
175
240
 
176
- {part !== "style" && <LayoutEffectsPanel type={type} style={raw} onChange={onChange} device={device}
177
- effects={show("effects", ["gradient", "shadow", "aspectRatio", "position"])} hover={show("hover", ["hover"])} gradient={!groups.has("background")} />}
241
+ {inPart("border") && (groups.has("border") || fxOk || has(["border", "radius"]) || !!(style.hover?.border || style.hover?.shadow || style.hover?.lift)) && <Section title={t.style_border} modified={has(["border", "radius", "shadow"]) || !!(style.hover?.border || style.hover?.shadow || style.hover?.lift)}
242
+ onReset={() => commit({ ...style, border: undefined, radius: undefined, shadow: undefined, hover: style.hover && { ...style.hover, border: undefined, shadow: undefined, lift: undefined } })}
243
+ defaultOpen={has(["border", "radius", "shadow"])}>
244
+ {hoverOk && <StateTabs value={borderState} onChange={setBorderState} />}
245
+ {hoverOk && borderState === "hover" ? <>
246
+ <ColorInput label={t.style_borderColor} value={style.hover?.border?.color} onChange={(v) => setHover({ border: v ? { color: v } : undefined })} />
247
+ <Row label={lt.shadow}>{shadowSelect(style.hover?.shadow, (v) => setHover({ shadow: v }), `${lt.hover} ${lt.shadow}`, false)}</Row>
248
+ <label className="ecx-check"><input type="checkbox" checked={!!style.hover?.lift} onChange={(e) => setHover({ lift: e.target.checked || undefined })} /> {lt.lift}</label>
249
+ </> : <>
250
+ {(groups.has("border") || has(["border", "radius"])) && <>
251
+ <FourInput label={t.style_borderWidth} keys={["top", "right", "bottom", "left"]} keyLabels={{ top: ct.sideTop, right: ct.sideRight, bottom: ct.sideBottom, left: ct.sideLeft }} value={style.border?.width} max={20} units={["px", "em", "rem"]} onChange={(v) => setGroup("border", "width", v)} />
252
+ {row("borderStyle", t.style_borderStyle, <Seg label={t.style_borderStyle} value={style.border?.style} onChange={(v) => setGroup("border", "style", v)}
253
+ options={[["solid", "—", t.border_solid], ["dashed", "- -", t.border_dashed], ["dotted", "···", t.border_dotted]]} />)}
254
+ <ColorInput label={t.style_borderColor} value={style.border?.color} onChange={(v) => setGroup("border", "color", v)} />
255
+ <FourInput label={t.style_radius} corners keys={["topLeft", "topRight", "bottomRight", "bottomLeft"]} keyLabels={{ topLeft: ct.cornerTopLeft, topRight: ct.cornerTopRight, bottomRight: ct.cornerBottomRight, bottomLeft: ct.cornerBottomLeft }} value={style.radius} max={60} units={["px", "%", "em", "rem"]} onReset={has(["radius"]) ? () => reset(["radius"]) : undefined} onChange={(v) => set("radius", v)} />
256
+ </>}
257
+ {fxOk && row("shadow", lt.shadow, shadowSelect(style.shadow, (v) => set("shadow", v), lt.shadow))}
258
+ </>}
259
+ </Section>}
260
+
261
+ {part === "advanced" && fxOk && <Section title={lt.sticky} modified={!!style.position} defaultOpen={!!style.position}>
262
+ <label className="ecx-check"><input type="checkbox" checked={!!style.position} onChange={(e) => set("position", e.target.checked ? { type: "sticky" } : undefined)} /> {lt.sticky}</label>
263
+ </Section>}
178
264
 
179
265
  {show("motion", ["motion"]) && <MotionPanel type={type} style={raw} onChange={onChange} />}
180
266
 
@@ -1,7 +1,7 @@
1
1
  import { WIDE_BLOCKS } from "@ecomcx/ecomweb-content";
2
2
  import { clearCells, mergeRange, selectedCellRect } from "../core/tables";
3
3
  import { AiTools } from "./ai";
4
- import { Eraser, TableCellsMerge, StickyNote, Keyboard, MoveHorizontal, Maximize2, RectangleHorizontal, AlignCenter, AlignLeft, AlignRight, ArrowUpLeft, Bold, ChevronDown, ChevronUp, Code, Copy, CopyPlus, GripVertical, IndentDecrease, IndentIncrease, Italic, Link2, Link2Off, MoreVertical, PanelTop, Strikethrough, Trash2, Underline, Ungroup, Group as GroupIcon, Blocks, ArrowUpToLine, ArrowDownToLine, Shapes, Lock, Subscript, Superscript, Highlighter, Paintbrush, ClipboardPaste } from "lucide-react";
4
+ import { Eraser, TableCellsMerge, StickyNote, Keyboard, MoveHorizontal, Maximize2, RectangleHorizontal, AlignCenter, AlignLeft, AlignRight, ArrowUpLeft, Bold, ChevronDown, ChevronUp, Code, Copy, CopyPlus, GripVertical, IndentDecrease, IndentIncrease, Italic, Link2, Link2Off, MoreVertical, PanelTop, Strikethrough, Trash2, Underline, Ungroup, Group as GroupIcon, Blocks, ArrowUpToLine, ArrowDownToLine, Shapes, Lock, Subscript, Superscript, Highlighter, Paintbrush, ClipboardPaste, Scissors, PenLine, Eye, EyeOff } from "lucide-react";
5
5
  import { TextSelection } from "prosemirror-state";
6
6
  import type { EditorView } from "prosemirror-view";
7
7
  import { useEffect, useLayoutEffect, useRef, useState, type ComponentType, type KeyboardEvent as ReactKeyboardEvent, type ReactNode } from "react";
@@ -19,7 +19,7 @@ import type { BlockTransform } from "../core/registry";
19
19
  import { insertSibling, richViews } from "../text/rich-text";
20
20
  import { canContain } from "../core/structure";
21
21
  import { blockActionsFor } from "../../shared/panel-store";
22
- import { copyStyle, hasCopiedStyle, menuPosition, pastedStyle } from "./block-menu";
22
+ import { copyStyle, hasCopiedStyle, isHidden, menuPosition, pastedStyle, toggleHidden } from "./block-menu";
23
23
 
24
24
  const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
25
25
 
@@ -90,7 +90,7 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
90
90
  const sel = useEditorState((s) => s.selection);
91
91
  useEditorState((s) => s.revision);
92
92
  const [link, setLink] = useState<string | null>(null);
93
- const [lockOpen, setLockOpen] = useState(false);
93
+ const [dialog, setDialog] = useState<"lock" | "rename" | null>(null);
94
94
  useEffect(() => { ui.openLink = (key) => setLink(key); return () => { ui.openLink = null; }; }, [ui]);
95
95
 
96
96
  const ids = sel.ids.length ? sel.ids : sel.editing ? [sel.editing] : [];
@@ -119,6 +119,9 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
119
119
  const type = registry.get(first.type);
120
120
  const sameType = nodes.every((n) => n.type === first.type);
121
121
  const Icon = type?.icon ?? Blocks;
122
+ // Tên khối nằm trong thanh công cụ (nút đầu: biểu tượng + tên + ▾ đổi loại) — thay nhãn tên riêng trên khối (bị thanh đè)
123
+ const variation = sameType && nodes.length === 1 ? type?.variations?.find((v) => v.standalone && v.isActive?.(first.attrs)) : undefined;
124
+ const name = nodes.length > 1 ? `${nodes.length} ${labels.blocks}` : variation?.title ?? type?.title ?? first.type;
122
125
  const editingText = !sel.ids.length && !!sel.editing;
123
126
  const view = editingText ? activeView(ui.activeRich, sel.editing!) : null;
124
127
  const ordered = topLevelOrdered(store.getState().docs[loc.docId].blocks, ids);
@@ -191,13 +194,13 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
191
194
  <div className="ecx-tool-group">
192
195
  {parent && <ToolButton label={labels.selectParent} onClick={() => store.select([parent.id], { editing: null })}><ArrowUpLeft className="ecx-icon" /></ToolButton>}
193
196
  {transforms.length && removable && !store.isContentOnly(first.id) ? (
194
- <Dropdown label={labels.transform} trigger={<><Icon className="ecx-icon" /><ChevronDown className="ecx-icon ecx-icon-sm" /></>}>
197
+ <Dropdown label={`${name} · ${labels.transform}`} className="ecx-toolbar-type" trigger={<><Icon className="ecx-icon" /><span className="ecx-tool-text ecx-toolbar-name">{name}</span><ChevronDown className="ecx-icon ecx-icon-sm" /></>}>
195
198
  {(close) => transforms.map((t, i) => {
196
199
  const target = registry.get(t.to);
197
200
  return <MenuItem key={i} icon={target?.icon} label={`${target?.title ?? t.to}${t.title ? ` ${t.title}` : ""}`} onClick={() => { close(); doTransform(t); }} />;
198
201
  })}
199
202
  </Dropdown>
200
- ) : <span className="ecx-tool is-static" title={type?.title}><Icon className="ecx-icon" /></span>}
203
+ ) : <span className="ecx-tool is-static ecx-toolbar-type" title={name}><Icon className="ecx-icon" /><span className="ecx-tool-text ecx-toolbar-name">{name}</span></span>}
201
204
  {movable && <>
202
205
  <ToolButton label={labels.drag} className="ecx-drag-handle" onPointerDown={(e: React.PointerEvent) => startDrag(ctx, e, ordered)}><GripVertical className="ecx-icon" /></ToolButton>
203
206
  <div className="ecx-movers">
@@ -205,7 +208,7 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
205
208
  <ToolButton label={labels.moveDown} onClick={() => store.moveBy(ordered, 1)}><ChevronDown className="ecx-icon ecx-icon-sm" /></ToolButton>
206
209
  </div>
207
210
  </>}
208
- {isLocked && <ToolButton label={labels.locked} onClick={() => setLockOpen(true)} className="ecx-lock-badge"><Lock className="ecx-icon" /></ToolButton>}
211
+ {isLocked && <ToolButton label={labels.locked} onClick={() => setDialog("lock")} className="ecx-lock-badge"><Lock className="ecx-icon" /></ToolButton>}
209
212
  </div>
210
213
  {sameType && type?.variations?.some((v) => v.attrs && v.isActive) && (
211
214
  <div className="ecx-tool-group">
@@ -247,13 +250,25 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
247
250
  {Extra && <div className="ecx-tool-group"><Extra {...editProps} /></div>}
248
251
  {(nodes.length === 1 || cellSel) && contextTools(loc.ancestors, first.id)}
249
252
  {nested && <div className="ecx-tool-group"><ToolButton label={labels.editOriginal} className="ecx-tool-wide" onClick={() => store.enterFocus(nested)}><PanelTop className="ecx-icon" /><span className="ecx-tool-text">{labels.editOriginal}</span></ToolButton></div>}
253
+ {/* Chép / dán kiểu dáng ngay trên thanh (như các bộ khối lớn) — vẫn còn trong menu ⋮ */}
254
+ {nodes.length === 1 && !type?.plain && (
255
+ <div className="ecx-tool-group">
256
+ <Dropdown label={labels.copyPasteStyle} trigger={<Paintbrush className="ecx-icon" />}>
257
+ {(close) => <>
258
+ <MenuItem icon={Paintbrush} label={labels.copyStyle} onClick={() => { close(); copyStyle(first.attrs); ui.announce(labels.styleCopied); }} />
259
+ {hasCopiedStyle() && ordered.every((id) => !store.isContentOnly(id) && store.modeOf(id) !== "disabled") && <MenuItem icon={ClipboardPaste} label={labels.pasteStyle} onClick={() => { close(); store.setAttrs(ordered, pastedStyle()!); }} />}
260
+ </>}
261
+ </Dropdown>
262
+ </div>
263
+ )}
250
264
  <div className="ecx-tool-group">
251
265
  <Dropdown label={labels.more} trigger={<MoreVertical className="ecx-icon" />}>
252
- {(close) => <BlockMenuItems ids={ids} close={close} onLock={() => setLockOpen(true)} />}
266
+ {(close) => <BlockMenuItems ids={ids} close={close} onDialog={setDialog} />}
253
267
  </Dropdown>
254
268
  </div>
255
269
  </div>
256
- {lockOpen && <LockDialog block={first} onClose={() => setLockOpen(false)} />}
270
+ {dialog === "lock" && <LockDialog block={first} onClose={() => setDialog(null)} />}
271
+ {dialog === "rename" && <RenameDialog block={first} onClose={() => setDialog(null)} />}
257
272
  {link && view && (() => {
258
273
  const anchor = fixed ? document.querySelector(".ecx-toolbar.is-fixed")?.getBoundingClientRect() : null;
259
274
  return <LinkPopover viewKey={link} top={anchor ? anchor.bottom + 4 : top + height + 4} left={anchor ? anchor.left : left} onClose={() => setLink(null)} />;
@@ -305,7 +320,7 @@ function MarkTools({ view, onLink }: { view: EditorView; onLink(): void }) {
305
320
  }
306
321
 
307
322
  /** Mục của menu ⋮ trên thanh công cụ khối — dùng chung với menu chuột phải (BlockContextMenu). */
308
- function BlockMenuItems({ ids, close, onLock }: { ids: string[]; close(): void; onLock(): void }) {
323
+ export function BlockMenuItems({ ids, close, onDialog }: { ids: string[]; close(): void; onDialog(kind: "lock" | "rename"): void }) {
309
324
  const ctx = useEditor();
310
325
  const { store, ui, labels } = ctx;
311
326
  const nodes = ids.map((id) => store.block(id)).filter(Boolean) as BNode[];
@@ -319,11 +334,13 @@ function BlockMenuItems({ ids, close, onLock }: { ids: string[]; close(): void;
319
334
  const insertable = store.canInsertInto(parent?.id ?? null);
320
335
  const canGroup = canContain(parent?.type ?? null, "group");
321
336
  const styleEditable = ordered.every((id) => !store.isContentOnly(id) && store.modeOf(id) !== "disabled");
337
+ const hidden = isHidden(first);
322
338
  const copy = async () => {
323
339
  const s = serializeBlocks(ordered.map((id) => store.block(id)!));
324
340
  try {
325
341
  await navigator.clipboard.write([new ClipboardItem({ "text/plain": new Blob([s.text], { type: "text/plain" }), "text/html": new Blob([s.html], { type: "text/html" }) })]);
326
- } catch { /* trình duyệt chặn ghi clipboard: người dùng vẫn chép được bằng Ctrl+C */ }
342
+ return true;
343
+ } catch { return false; /* trình duyệt chặn ghi clipboard: người dùng vẫn chép được bằng Ctrl+C */ }
327
344
  };
328
345
  /** Tạo mẫu từ các khối đang chọn; mẫu đồng bộ → thay khối bằng tham chiếu tới mẫu. */
329
346
  const createPattern = async () => {
@@ -343,7 +360,8 @@ function BlockMenuItems({ ids, close, onLock }: { ids: string[]; close(): void;
343
360
  <MenuItem icon={ArrowUpToLine} label={labels.insertBefore} shortcut={`${mod}⌥T`} onClick={() => { close(); insertSibling(store, ordered[0], 0); }} />
344
361
  <MenuItem icon={ArrowDownToLine} label={labels.insertAfter} shortcut={`${mod}⌥Y`} onClick={() => { close(); insertSibling(store, ordered[ordered.length - 1], 1); }} />
345
362
  </>}
346
- <MenuItem icon={Copy} label={labels.copy} onClick={() => { close(); void copy(); }} />
363
+ <MenuItem icon={Copy} label={labels.copy} shortcut={`${mod}C`} onClick={() => { close(); void copy(); }} />
364
+ {removable && <MenuItem icon={Scissors} label={labels.cut} shortcut={`${mod}X`} onClick={() => { close(); void copy().then((ok) => { if (ok) store.remove(ordered); }); /* chép không được thì không xoá */ }} />}
347
365
  <MenuItem icon={Paintbrush} label={labels.copyStyle} onClick={() => { close(); copyStyle(first.attrs); ui.announce(labels.styleCopied); }} />
348
366
  {hasCopiedStyle() && styleEditable && <MenuItem icon={ClipboardPaste} label={labels.pasteStyle} onClick={() => { close(); store.setAttrs(ordered, pastedStyle()!); }} />}
349
367
  {ctx.host.createPattern && <MenuItem icon={Shapes} label={labels.createPattern} onClick={() => { close(); void createPattern(); }} />}
@@ -356,7 +374,9 @@ function BlockMenuItems({ ids, close, onLock }: { ids: string[]; close(): void;
356
374
  ))}
357
375
  {canGroup && removable && movable && insertable && <MenuItem icon={GroupIcon} label={labels.group} onClick={() => { close(); store.wrap(ordered, "group"); }} />}
358
376
  {nodes.length === 1 && first.content && first.type === "group" && removable && <MenuItem icon={Ungroup} label={labels.ungroup} onClick={() => { close(); store.unwrap(first.id); }} />}
359
- {nodes.length === 1 && !store.isContentOnly(first.id) && <MenuItem icon={Lock} label={labels.lock} onClick={() => { close(); onLock(); }} />}
377
+ {nodes.length === 1 && !store.isContentOnly(first.id) && <MenuItem icon={Lock} label={labels.lock} onClick={() => { close(); onDialog("lock"); }} />}
378
+ {nodes.length === 1 && <MenuItem icon={PenLine} label={labels.rename} onClick={() => { close(); onDialog("rename"); }} />}
379
+ {styleEditable && <MenuItem icon={hidden ? Eye : EyeOff} label={hidden ? labels.show : labels.hide} onClick={() => { close(); toggleHidden(store, ordered); }} />}
360
380
  {removable && <MenuItem icon={Trash2} label={labels.remove} shortcut="⇧⌥Z" danger onClick={() => { close(); store.remove(ordered); }} />}
361
381
  </>
362
382
  );
@@ -372,7 +392,7 @@ export function BlockContextMenu() {
372
392
  const at = ui.contextMenu;
373
393
  const ref = useRef<HTMLDivElement>(null);
374
394
  const [pos, setPos] = useState<{ top: number; left: number } | null>(null);
375
- const [lock, setLock] = useState<BNode | null>(null);
395
+ const [dlg, setDlg] = useState<{ kind: "lock" | "rename"; block: BNode } | null>(null);
376
396
  // refocus: bàn phím quay về khối (Esc / Tab) hoặc khung soạn (chọn mục xong — khối có thể đã bị xoá / thay)
377
397
  const close = (refocus?: "block" | "canvas") => {
378
398
  const id = ui.contextMenu?.ids[0];
@@ -415,10 +435,11 @@ export function BlockContextMenu() {
415
435
  else if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); close("block"); }
416
436
  else if (e.key === "Tab") { e.preventDefault(); close("block"); }
417
437
  }}>
418
- <BlockMenuItems ids={at.ids} close={() => close("canvas")} onLock={() => setLock(store.block(at.ids[0]) ?? null)} />
438
+ <BlockMenuItems ids={at.ids} close={() => close("canvas")} onDialog={(kind) => { const b = store.block(at.ids[0]); if (b) setDlg({ kind, block: b }); }} />
419
439
  </div>
420
440
  )}
421
- {lock && <LockDialog block={lock} onClose={() => setLock(null)} />}
441
+ {dlg?.kind === "lock" && <LockDialog block={dlg.block} onClose={() => setDlg(null)} />}
442
+ {dlg?.kind === "rename" && <RenameDialog block={dlg.block} onClose={() => setDlg(null)} />}
422
443
  </>
423
444
  );
424
445
  }
@@ -491,7 +512,8 @@ export function DropIndicator() {
491
512
  if (!ui.drag) return null;
492
513
  return (
493
514
  <>
494
- {t && <div className="ecx-drop-line" style={{ left: t.rect.left, top: t.rect.top, width: t.rect.width, height: t.rect.height }} data-horizontal={t.horizontal || undefined} />}
515
+ {/* key theo chỗ thả: sang chỗ mới thì thanh chạy lại từ giữa ra hai đầu (như WordPress) */}
516
+ {t && <div key={`${t.docId}:${t.parentId}:${t.index}`} className="ecx-drop-line" style={{ left: t.rect.left, top: t.rect.top, width: t.rect.width, height: t.rect.height }} data-horizontal={t.horizontal || undefined} />}
495
517
  <div className={t ? "ecx-drag-chip" : "ecx-drag-chip is-blocked"} style={{ left: ui.drag.x + 12, top: ui.drag.y + 12 }}>{(() => {
496
518
  // Tên khối đang kéo (nhiều khối: số lượng); không có chỗ thả hợp lệ → mờ đi
497
519
  const type = registry.get(ui.drag.newType ?? store.block(ui.drag.ids[0] ?? "")?.type ?? "");
@@ -538,3 +560,24 @@ function LockDialog({ block, onClose }: { block: BNode; onClose(): void }) {
538
560
  </div>
539
561
  );
540
562
  }
563
+
564
+ /** Đổi tên khối (chỉ trong trình soạn: cây khối, bảng cài đặt, đường dẫn khối). Để trống = tên mặc định. */
565
+ function RenameDialog({ block, onClose }: { block: BNode; onClose(): void }) {
566
+ const { store, labels, registry } = useEditor();
567
+ const [name, setName] = useState(typeof block.attrs.customName === "string" ? block.attrs.customName : "");
568
+ const save = () => { store.setAttrs([block.id], { customName: name.trim().slice(0, 80) || undefined }); onClose(); };
569
+ return (
570
+ <div className="ecx-modal-backdrop" onMouseDown={(e) => { if (e.target === e.currentTarget) onClose(); }} onKeyDown={(e) => { if (e.key === "Escape") onClose(); else trapTab(e); }}>
571
+ <div className="ecx-modal" role="dialog" aria-modal="true" aria-label={labels.renameTitle}>
572
+ <header className="ecx-modal-header"><h2>{labels.renameTitle}</h2></header>
573
+ <form className="ecx-lock-body" onSubmit={(e) => { e.preventDefault(); save(); }}>
574
+ <input className="ecx-input" value={name} maxLength={80} placeholder={registry.get(block.type)?.title ?? block.type} aria-label={labels.renameTitle} autoFocus onChange={(e) => setName(e.target.value)} />
575
+ <div className="ecx-popover-actions">
576
+ <button type="button" className="ecx-btn" onClick={onClose}>{labels.cancel}</button>
577
+ <button type="submit" className="ecx-btn ecx-btn-primary">{labels.save}</button>
578
+ </div>
579
+ </form>
580
+ </div>
581
+ </div>
582
+ );
583
+ }