@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,13 +1,15 @@
1
- import { CORE_NODES, ICON_NAMES, widgetMarkup, type WidgetEl } from "@ecomcx/ecomweb-content";
2
- import { BarChart3, Hash, Image as ImageIcon, ListChecks, Quote, Star } from "lucide-react";
1
+ import { CORE_NODES, ICON_NAMES, ICON_PATHS, iconListClass, widgetMarkup, type WidgetEl } from "@ecomcx/ecomweb-content";
2
+ import { BarChart3, Hash, Image as ImageIcon, ListChecks, MapPin, Quote, Star } from "lucide-react";
3
3
  import { createElement, type CSSProperties, type ReactNode } from "react";
4
4
  import { makeBlock } from "../core/model";
5
5
  import type { BlockEditProps, BlockType } from "../core/registry";
6
6
  import { useMsgs } from "../i18n";
7
7
  import { messages } from "../../i18n";
8
8
  import { RichText } from "../text/rich-text";
9
- import { Field } from "../ui/attr-form";
9
+ import { Section } from "../ui/style-controls";
10
10
  import { MediaPick } from "./layout";
11
+ import { useActiveWithin } from "./resize";
12
+ import { AddItemButton, TextPlaceholder } from "../ui/placeholders";
11
13
 
12
14
  const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
13
15
 
@@ -15,17 +17,33 @@ const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "strin
15
17
  * Widget lõi trên khung soạn: cùng cây markup với website (@ecomcx/ecomweb-content widgetMarkup) → vẽ y hệt.
16
18
  * Ô chữ (`field`) gõ trực tiếp trên khối, chỗ ảnh trống (`slot`) là ô chọn ảnh; số / thanh tiến độ hiện giá trị cuối (không chạy hiệu ứng).
17
19
  */
18
- function WidgetEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
20
+ /** Gợi ý của từng ô chữ theo khối (không còn chữ mẫu thật dễ quên sửa). */
21
+ const FIELD_PH: Record<string, string> = { title: "boxTitle", text: "boxText", quote: "testimonialQuote", name: "testimonialName", role: "testimonialRole", label: "skill", address: "mapAddress" };
22
+
23
+ function WidgetEdit(props: BlockEditProps) {
24
+ const { block, blockProps, setAttrs, editable } = props;
19
25
  const t = useMsgs("blocks") as Record<string, string>;
26
+ const tp = useMsgs("placeholders") as unknown as Record<string, string>;
27
+ const active = useActiveWithin(block.id);
28
+ if (block.type === "iconList") return <IconListEdit {...props} />;
20
29
  const tree = widgetMarkup(block.type, block.attrs, true);
21
- if (!tree || (block.type === "iconList" && !tree.children?.length)) return <div {...blockProps} className={cx(blockProps.className, "ecx-placeholder-block")}>{t.widgetEmpty}</div>;
30
+ if (!tree) return <div {...blockProps} className={cx(blockProps.className, "ecx-placeholder-block")}>{t.widgetEmpty}</div>;
31
+ const ph = (f: string) => (block.type === "counter" && f === "title" ? tp.counterTitle : tp[FIELD_PH[f] ?? ""] ?? t[`widget_${f}`]);
22
32
  const draw = (el: WidgetEl | string, key: number, root?: boolean): ReactNode => {
23
33
  if (typeof el === "string") return el;
24
34
  if (el.field) {
25
35
  const f = el.field;
26
- return <RichText key={key} blockId={block.id} field={f} tagName="span" value={String(block.attrs[f] ?? "")} onChange={(v) => setAttrs({ [f]: v })} placeholder={t[`widget_${f}`]} placeholderAlways editable={editable} />;
36
+ return <RichText key={key} blockId={block.id} field={f} tagName="span" value={String(block.attrs[f] ?? "")} onChange={(v) => setAttrs({ [f]: v })} placeholder={ph(f)} placeholderAlways editable={editable} />;
27
37
  }
28
- const kids = el.slot === "media" ? [<MediaPick key="pick" blockId={block.id} />] : (el.children ?? []).map((c, i) => draw(c, i));
38
+ const kids = el.slot === "media" ? [<MediaPick key="pick" blockId={block.id} compact />] : (el.children ?? []).map((c, i) => draw(c, i));
39
+ // Bộ đếm: ô nhập số ngay trong khối khi đang chọn (nhắc chỉ dùng số thật)
40
+ if (root && block.type === "counter" && editable && active) kids.push(
41
+ <label key="end" className="ecx-ph-row ecx-ph-inline-field" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
42
+ <span className="ecx-ph-label">{tp.counterEnd}</span>
43
+ <input className="ecx-input" type="number" value={Number(block.attrs.end ?? 0)} onChange={(e) => setAttrs({ end: Number(e.target.value) || 0 })} />
44
+ <span className="ecx-placeholder-hint">{tp.counterHint}</span>
45
+ </label>,
46
+ );
29
47
  const props: Record<string, unknown> = { key, ...el.props, className: el.className, style: el.style as CSSProperties };
30
48
  if (el.tag === "a") props.onClick = (e: Event) => e.preventDefault();
31
49
  if (el.tag === "img") props.draggable = false;
@@ -35,19 +53,64 @@ function WidgetEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
35
53
  return <>{draw(tree, 0, true)}</>;
36
54
  }
37
55
 
38
- /** Danh sách mục của Icon List: mỗi dòng một mục, "chữ | đường dẫn" (đường dẫn tuỳ chọn); dòng trống giữ khi đang gõ, website bỏ qua. Icon riêng từng mục: chỉ qua dữ liệu (AI / mẫu). */
56
+ /** Icon List trên khung soạn: mỗi dòng gõ ngay trên khối (dòng trống website bỏ qua) + "+ Thêm dòng". */
57
+ function IconListEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
58
+ const tp = useMsgs("placeholders");
59
+ const items: Array<{ text: string; href?: string; icon?: string }> = Array.isArray(block.attrs.items) ? block.attrs.items : [];
60
+ const list = items.length || !editable ? items : [{ text: "" }];
61
+ const save = (next: typeof items) => setAttrs({ items: next });
62
+ const stroke = Math.min(4, Math.max(0.5, Number(block.attrs.stroke) || 2));
63
+ const icon = (name?: string) => name === "none" ? null : <svg className="ecx-widget-icon" viewBox="0 0 24 24" width={24} height={24} fill="none" stroke="currentColor" strokeWidth={stroke} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" focusable="false"><path d={ICON_PATHS[String(name ?? "")] ?? ICON_PATHS[String(block.attrs.icon ?? "check")] ?? ICON_PATHS.check} /></svg>;
64
+ return (
65
+ <ul {...blockProps} className={cx(blockProps.className, iconListClass(block.attrs))}>
66
+ {list.map((it, i) => (
67
+ <li key={i}>{icon(it.icon)}{editable
68
+ ? <TextPlaceholder value={it.text} placeholder={i === 0 ? tp.iconListItem : `${tp.addRow}…`} label={`${tp.addRow} ${i + 1}`} onChange={(v) => save(list.map((x, k) => (k === i ? { ...x, text: v } : x)))} />
69
+ : <span>{it.text}</span>}</li>
70
+ ))}
71
+ {editable && <li className="ecx-ph-list-add"><AddItemButton label={tp.addRow} onClick={() => save([...list, { text: "" }])} /></li>}
72
+ </ul>
73
+ );
74
+ }
75
+
76
+ /** Các mục của Icon List: mỗi mục một hàng — chữ, icon riêng (theo danh sách / tên icon / không icon), liên kết; thêm / xoá mục. Dòng trống website bỏ qua. */
39
77
  function IconListInspector({ attrs, setAttrs }: BlockEditProps) {
40
78
  const t = useMsgs("blocks") as Record<string, string>;
79
+ const h = useMsgs("hints") as Record<string, string>;
41
80
  const items: Array<{ text: string; href?: string; icon?: string }> = Array.isArray(attrs.items) ? attrs.items : [];
42
- const value = items.map((it) => (it.href ? `${it.text} | ${it.href}` : it.text)).join("\n");
43
- const parse = (s: string) => s.split("\n").slice(0, 50).map((line, i) => {
44
- const [text, href] = line.split("|").map((x) => x.trim());
45
- return { ...(items[i]?.icon ? { icon: items[i].icon } : {}), text: text ?? "", ...(href ? { href } : {}) };
46
- });
47
- return <Field label={t.iconListItems}><textarea className="ecx-input" rows={6} value={value} data-icon-list-items onChange={(e) => setAttrs({ items: parse(e.target.value) })} /></Field>;
81
+ const patch = (i: number, p: Record<string, string | undefined>) => setAttrs({ items: items.map((x, k) => {
82
+ if (k !== i) return x;
83
+ const next: Record<string, unknown> = { ...x, ...p };
84
+ for (const key of Object.keys(next)) if (next[key] === undefined || (key !== "text" && next[key] === "")) delete next[key];
85
+ return next;
86
+ }) });
87
+ return (
88
+ <Section title={t.iconListItems} defaultOpen>
89
+ {items.map((it, i) => (
90
+ <div key={i} className="ecx-item-row" data-icon-list-item>
91
+ <input className="ecx-input" aria-label={`${t.iconListText} ${i + 1}`} placeholder={t.iconListText} value={it.text ?? ""} onChange={(e) => patch(i, { text: e.target.value })} />
92
+ <div className="ecx-item-row-sub">
93
+ <select className="ecx-input" aria-label={`${t.iconListIcon} ${i + 1}`} value={it.icon ?? ""} onChange={(e) => patch(i, { icon: e.target.value || undefined })}>
94
+ <option value="">{t.iconListIconDefault}</option>
95
+ <option value="none">{t.iconListIconNone}</option>
96
+ {ICON_NAMES.map((n) => <option key={n} value={n}>{h[`iconList.icon.opt.${n}`] ?? n}</option>)}
97
+ </select>
98
+ <input className="ecx-input" type="url" inputMode="url" aria-label={`${t.iconListLink} ${i + 1}`} placeholder={t.iconListLink} value={it.href ?? ""} onChange={(e) => patch(i, { href: e.target.value || undefined })} />
99
+ <button type="button" className="ecx-tool" aria-label={`${t.iconListRemove} ${i + 1}`} title={t.iconListRemove} onClick={() => setAttrs({ items: items.filter((_, k) => k !== i) })}>×</button>
100
+ </div>
101
+ </div>
102
+ ))}
103
+ {items.length < 50 && <button type="button" className="ecx-btn" onClick={() => setAttrs({ items: [...items, { text: "" }] })}>+ {t.iconListAdd}</button>}
104
+ </Section>
105
+ );
48
106
  }
49
107
 
50
108
  const spec = (name: string) => CORE_NODES[name]?.attrs;
109
+ /** Thứ tự ô ở bảng phải: phần đầu hộp (icon / ảnh / số) trước, rồi chữ, rồi liên kết. Ô không kể tên giữ thứ tự cũ ở cuối. */
110
+ const ICON_BOX_ORDER = ["media", "icon", "number", "src", "alt", "width", "height", "iconStyle", "position", "verticalAlign", "hover", "title", "text", "level", "textAlign", "href", "linkMode", "buttonText", "fullHeight"];
111
+ function ordered<T>(attrs: Record<string, T>, order: string[]): Record<string, T> {
112
+ return Object.fromEntries([...order.filter((k) => k in attrs), ...Object.keys(attrs).filter((k) => !order.includes(k))].map((k) => [k, attrs[k]]));
113
+ }
51
114
  const ICON_SELECT = { type: "string" as const, enum: ICON_NAMES };
52
115
 
53
116
  /** Khối widget của lõi; `lang` = ngôn ngữ của trình soạn (chữ mẫu khi chèn). */
@@ -55,11 +118,13 @@ export function widgetBlocks(lang?: string): BlockType[] {
55
118
  const m = messages("blocks", lang) as Record<string, string>;
56
119
  const base = { kind: "atom" as const, category: "widgets", edit: WidgetEdit, supports: { style: true, anchor: true, className: true } };
57
120
  return [
58
- { ...base, name: "iconBox", title: "Icon Box", icon: Star, keywords: "icon box hop bieu tuong tinh nang dich vu feature", attributes: { ...spec("iconBox"), icon: { ...ICON_SELECT, default: "star" } }, create: () => makeBlock("iconBox", { icon: "star", title: m.sampleTitle, text: m.sampleText }), summary: (a) => a.title },
59
- { ...base, name: "imageBox", title: "Image Box", icon: ImageIcon, keywords: "image box hop anh the card dich vu", attributes: { ...spec("imageBox"), src: { type: "url", control: "media" } }, create: () => makeBlock("imageBox", { title: m.sampleTitle, text: m.sampleText }), summary: (a) => a.title },
60
- { ...base, name: "iconList", title: "Icon List", icon: ListChecks, keywords: "icon list danh sach bieu tuong loi ich checklist", inspector: IconListInspector, attributes: { ...spec("iconList"), icon: { ...ICON_SELECT, default: "check" } }, create: () => makeBlock("iconList", { items: [m.sampleItem1, m.sampleItem2, m.sampleItem3].map((text) => ({ text })) }) },
61
- { ...base, name: "counter", title: "Counter", icon: Hash, keywords: "counter dem so con so thong ke number", attributes: spec("counter"), create: () => makeBlock("counter", { end: 100, suffix: "+", title: m.sampleCounter, textAlign: "center" }), summary: (a) => a.title },
62
- { ...base, name: "testimonial", title: "Testimonial", icon: Quote, keywords: "testimonial loi chung thuc danh gia khach hang review", attributes: { ...spec("testimonial"), src: { type: "url", control: "media" } }, create: () => makeBlock("testimonial", { quote: m.sampleQuote, name: m.sampleName, role: m.sampleRole }), summary: (a) => a.name },
63
- { ...base, name: "progressBar", title: "Progress Bar", icon: BarChart3, keywords: "progress bar thanh tien do ky nang phan tram", attributes: spec("progressBar"), create: () => makeBlock("progressBar", { label: m.sampleSkill, value: 80 }), summary: (a) => a.label },
121
+ { ...base, name: "iconBox", title: "Icon Box", icon: Star, keywords: "icon box hop bieu tuong tinh nang dich vu feature", attributes: ordered({ ...spec("iconBox"), icon: { ...ICON_SELECT, default: "star" }, src: { type: "url", control: "media" } }, ICON_BOX_ORDER), create: () => makeBlock("iconBox", { icon: "star", title: "", text: "" }), summary: (a) => a.title },
122
+ // Hộp ảnh đã gộp vào Hộp icon (media = ảnh): ẩn khỏi trình chèn, nội dung cũ vẫn sửa được
123
+ { ...base, hidden: true, name: "imageBox", title: "Image Box", icon: ImageIcon, keywords: "image box hop anh the card dich vu", attributes: { ...spec("imageBox"), src: { type: "url", control: "media" } }, create: () => makeBlock("imageBox", { title: "", text: "" }), summary: (a) => a.title },
124
+ { ...base, name: "iconList", title: "Icon List", icon: ListChecks, keywords: "icon list danh sach bieu tuong loi ich checklist", inspector: IconListInspector, attributes: { ...spec("iconList"), icon: { ...ICON_SELECT, default: "check" } }, create: () => makeBlock("iconList", { items: [{ text: "" }, { text: "" }] }) },
125
+ { ...base, name: "counter", title: "Counter", icon: Hash, keywords: "counter dem so con so thong ke number", attributes: spec("counter"), create: () => makeBlock("counter", { end: 0, suffix: "+", title: "", textAlign: "center" }), summary: (a) => a.title },
126
+ { ...base, name: "testimonial", title: "Testimonial", icon: Quote, keywords: "testimonial loi chung thuc danh gia khach hang review", attributes: ordered({ ...spec("testimonial"), src: { type: "url", control: "media" } }, ["variant", "quoteMark", "rating", "quote", "name", "role", "src", "alt", "textAlign"]), create: () => makeBlock("testimonial", { quote: "", name: "", role: "" }), summary: (a) => a.name },
127
+ { ...base, name: "map", title: "Map", icon: MapPin, keywords: "map ban do dia chi google maps vi tri", attributes: ordered(spec("map") ?? {}, ["address", "title", "zoom", "height", "mapType"]), create: () => makeBlock("map", { address: "" }), summary: (a) => a.address },
128
+ { ...base, name: "progressBar", title: "Progress Bar", icon: BarChart3, keywords: "progress bar thanh tien do ky nang phan tram", attributes: spec("progressBar"), create: () => makeBlock("progressBar", { label: "", value: 80 }), summary: (a) => a.label },
64
129
  ];
65
130
  }
@@ -1,8 +1,9 @@
1
1
  import { controlsCss, normalizeStyle, styleClass, widthClass } from "@ecomcx/ecomweb-content";
2
2
  import { blockControls } from "../../shared/panel-store";
3
- import { Component, memo, useCallback, useContext, useEffect, useMemo, useRef, type ErrorInfo, type MouseEvent, type ReactElement, type ReactNode } from "react";
3
+ import { Component, memo, useCallback, useContext, useEffect, useMemo, useRef, type ErrorInfo, type MouseEvent, type PointerEvent, type ReactElement, type ReactNode } from "react";
4
4
  import { DocScopeProvider, LoopPostContext, useDocScope, useEditor, useEditorState } from "../context";
5
5
  import { ServerBlock } from "./server-block";
6
+ import { startDrag } from "./dnd";
6
7
  import { docIdOf, type NestedDocRef } from "../core/host";
7
8
  import { blocksFromDoc, makeBlock, type BNode } from "../core/model";
8
9
  import type { BlockEditProps, BlockProps } from "../core/registry";
@@ -22,7 +23,8 @@ export function sectionOf(store: ReturnType<typeof useEditor>["store"], el: HTML
22
23
 
23
24
  /** Props gắn vào phần tử gốc của khối: chọn, viền, kiểu dáng, neo. */
24
25
  export function useBlockProps(block: BNode, state: { selected: boolean; editing: boolean; mode: EditingMode }): BlockProps {
25
- const { store, registry, ui } = useEditor();
26
+ const ctx = useEditor();
27
+ const { store, registry, ui } = ctx;
26
28
  const a = block.attrs;
27
29
  const style = a.style && typeof a.style === "object" ? normalizeStyle(a.style) : undefined;
28
30
  const type = registry.get(block.type);
@@ -60,11 +62,22 @@ export function useBlockProps(block: BNode, state: { selected: boolean; editing:
60
62
  if (own.isContentEditable) own.ownerDocument.querySelector<HTMLElement>(".ecx-canvas-root")?.focus({ preventScroll: true });
61
63
  else own.focus({ preventScroll: true });
62
64
  }, [block.id, store, ui]);
65
+ // Khối bố cục đang chọn: nắm chỗ trống (không phải chữ, ô nhập, khối con) rồi kéo = đổi chỗ như tay nắm ⠿ (bấm thường vẫn là bấm)
66
+ const grab = state.selected && type?.kind !== "text";
67
+ const onPointerDown = useCallback((e: PointerEvent<HTMLElement>) => {
68
+ const t = e.target as HTMLElement;
69
+ if (e.button !== 0 || e.shiftKey || e.metaKey || e.ctrlKey || ui.zoomOut) return;
70
+ if (t.closest("[data-ecx-block]")?.getAttribute("data-ecx-block") !== block.id) return;
71
+ // Chỉ xét trong khối (cả khung soạn là contenteditable)
72
+ const hit = t.closest("[data-ecx-rich], input, textarea, select, button, a, [contenteditable=true], .ecx-pad-handles, .ecx-col-handles, .ecx-image-handle");
73
+ if (hit && e.currentTarget.contains(hit)) return;
74
+ const ids = store.getState().selection.ids;
75
+ startDrag(ctx, e, ids.includes(block.id) ? ids : [block.id]);
76
+ }, [block.id, ctx, store, ui]);
63
77
  return {
64
78
  ref: null,
65
79
  "data-ecx-block": block.id,
66
80
  "data-type": block.type,
67
- "data-ecx-title": state.selected ? type?.title ?? block.type : undefined,
68
81
  tabIndex: type?.kind === "text" ? undefined : -1,
69
82
  id: typeof a.anchor === "string" ? a.anchor : undefined,
70
83
  className: cx(
@@ -79,6 +92,7 @@ export function useBlockProps(block: BNode, state: { selected: boolean; editing:
79
92
  typeof a.className === "string" && a.className,
80
93
  ),
81
94
  onMouseDown,
95
+ ...(grab ? { onPointerDown, "data-ecx-grab": "" } : {}),
82
96
  };
83
97
  }
84
98
 
@@ -105,8 +119,9 @@ export const Block = memo(function Block({ node }: { node: BNode }) {
105
119
  const props: BlockEditProps = { block: node, attrs: node.attrs, setAttrs, blockProps, selected: selected || editing, editable: scope.mode !== "disabled", labels };
106
120
  // Khối trong vòng lặp bài (query › postTemplate) giữ giao diện của trình soạn: website chỉ biết bài của trang, không biết bài của vòng lặp
107
121
  const loop = useContext(LoopPostContext);
122
+ // editWhenSelected: đang chọn → ô giữ chỗ của trình soạn; vẫn đi qua ServerBlock để ô nhập không bị dựng lại (mất focus) khi chọn / bỏ chọn
108
123
  if (type?.serverRender && host.renderBlock && !loop)
109
- return <BlockBoundary id={node.id} type={node.type}><ServerBlock node={node} blockProps={blockProps} fallback={<Edit {...props} />} /></BlockBoundary>;
124
+ return <BlockBoundary id={node.id} type={node.type}><ServerBlock node={node} blockProps={blockProps} fallback={<Edit {...props} />} live={!(type.editWhenSelected && (selected || editing) && scope.mode !== "disabled")} /></BlockBoundary>;
110
125
  return <BlockBoundary id={node.id} type={node.type}><Edit {...props} /></BlockBoundary>;
111
126
  });
112
127
 
@@ -161,13 +176,13 @@ export function InnerBlocks({ parent, appender = "auto" }: { parent: BNode; appe
161
176
  export function Appender({ docId, parentId, index }: { docId: string; parentId: string | null; index: number }) {
162
177
  const { ui, labels } = useEditor();
163
178
  return (
164
- <button type="button" className="ecx-appender" aria-label={labels.addBlock} title={labels.addBlock} contentEditable={false}
179
+ <button type="button" className="ecx-appender" title={labels.addBlock} contentEditable={false}
165
180
  onMouseDown={(e) => { e.preventDefault(); e.stopPropagation(); }}
166
181
  onClick={(e) => {
167
182
  const r = (e.currentTarget as HTMLElement).getBoundingClientRect();
168
183
  const f = ui.canvasFrame?.getBoundingClientRect();
169
184
  ui.openInserter({ mode: "appender", docId, parentId, index, rect: { left: (f?.left ?? 0) + r.left, top: (f?.top ?? 0) + r.top, bottom: (f?.top ?? 0) + r.bottom } });
170
- }}>+</button>
185
+ }} data-ecx-placeholder="add"><span aria-hidden="true">+</span> {labels.addBlock}</button>
171
186
  );
172
187
  }
173
188
 
@@ -49,15 +49,13 @@ body.ecx-canvas-body { padding: 0; }
49
49
  .ecx-block.is-selected:is([data-type="tableCell"], [data-type="tableHeader"], [data-type="tableRow"])::after { display: none; }
50
50
  /* Đang kéo bôi vùng ô: tắt bôi chữ của trình duyệt (chỉ tô ô) */
51
51
  .ecx-cell-selecting, .ecx-cell-selecting * { user-select: none !important; -webkit-user-select: none !important; caret-color: transparent; }
52
- /* Nhãn loại khối (chỉ khi chọn, khối cấp thường; khối lồng đã có .ecx-nested-label). Không đổi bố cục: absolute, không nhận chuột */
53
- .ecx-block.is-selected:not(.ecx-nested):not(.ecx-column)[data-type]::after { content: attr(data-ecx-title); position: absolute; left: -2px; top: -3px; transform: translateY(-100%); padding: 1px 8px; border-radius: 4px 4px 0 0; background: var(--ecx-ui); color: #fff; font: 600 11px/1.7 var(--ecx-ui-font); letter-spacing: 0; text-transform: none; white-space: nowrap; pointer-events: none; z-index: 5; }
54
- .ecx-block.is-selected[data-ecx-title=""]::after { content: none; }
55
52
  .ecx-block.is-selected.ecx-nested { outline-color: var(--ecx-ui-nested) !important; }
56
53
  [data-ecx-rich] { outline: none; white-space: pre-wrap; word-wrap: break-word; caret-color: currentColor; min-height: 1em; }
57
54
  [data-ecx-rich]:focus { outline: none; }
58
55
  pre [data-ecx-rich], pre[data-ecx-rich] { white-space: pre-wrap; }
59
- [data-ecx-rich][data-empty][data-placeholder]::before { content: attr(data-placeholder); opacity: .45; pointer-events: none; position: absolute; }
60
- [data-ecx-rich][data-empty]:not([data-placeholder-always]):not(:focus)::before { content: none; }
56
+ /* Ô chữ rỗng luôn hiện gợi ý theo vai trò (cả khi chưa chọn khối), cỡ chữ = cỡ chữ thật của ô; độ đậm .7 giữ tương phản ≥ 4.5:1 với màu chữ của theme */
57
+ [data-ecx-rich][data-empty][data-placeholder]::before { content: attr(data-placeholder); opacity: .85; pointer-events: none; position: absolute; }
58
+ [data-ecx-rich][data-empty]:not([data-placeholder-always]):not(:focus)::before, [data-ecx-rich][contenteditable="false"][data-empty]::before { content: none; }
61
59
  [data-ecx-rich][data-empty] { position: relative; }
62
60
  /* min(100%, …) = 0 trong khung co theo nội dung (nút) → dùng độ dài chữ gợi ý, chặn tràn bằng max-width */
63
61
  /* Chỉ ô chữ dạng span (nút, nhãn…): đoạn văn trống KHÔNG đặt max-width — luật này ưu tiên cao hơn cột chữ của khung soạn,
@@ -65,7 +63,11 @@ pre [data-ecx-rich], pre[data-ecx-rich] { white-space: pre-wrap; }
65
63
  span[data-ecx-rich][data-empty][data-placeholder] { min-width: calc(var(--ecx-ph, 0) * .6em); max-width: 100%; }
66
64
  span[data-ecx-rich][data-empty][data-placeholder] { display: inline-block; vertical-align: top; }
67
65
  [data-ecx-rich][data-empty][data-placeholder] { min-width: 0; } /* ô lưới/flex trống không bị chữ gợi ý (nowrap) đẩy rộng hơn khung */
68
- [data-ecx-rich][data-empty][data-placeholder]::before { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
66
+ [data-ecx-rich][data-empty][data-placeholder][contenteditable="true"] { opacity: 1 !important; } /* phần tử vốn mờ (chức danh, chú thích): gợi ý không mờ chồng mờ */
67
+ .ecx-button [data-ecx-rich][data-empty][data-placeholder]::before { opacity: .8; font-style: normal; left: 0; right: 0; text-align: center; } /* chữ gợi ý trên nền màu nút: sáng vừa đủ tương phản, không nghiêng */
68
+ .ecx-button span[data-ecx-rich][data-empty][data-placeholder] { min-width: calc(var(--ecx-ph, 0) * .75em); } /* chữ đậm của nút rộng hơn chữ thường: chừa chỗ để gợi ý không bị cắt */
69
+ [data-ecx-rich][data-empty][data-placeholder] { flex: 1 1 8em; } /* trong hàng ngang (flex): ô trống không co về 0px (gợi ý là ::before absolute) */
70
+ [data-ecx-rich][data-empty][data-placeholder]::before { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; left: 0; right: 0; } /* bám hai mép của ô (căn giữa / cỡ chữ lớn: không tràn ra ngoài khối) */
69
71
  .ProseMirror-hideselection *::selection { background: transparent; }
70
72
  .ProseMirror-selectednode { outline: 2px solid var(--ecx-ui); }
71
73
  .ecx-inline-atom { padding: 0 .25em; border-radius: 4px; background: var(--ecx-ui-soft); font-size: .85em; }
@@ -116,6 +118,14 @@ span[data-ecx-rich][data-empty][data-placeholder] { display: inline-block; verti
116
118
  .ecx-drop-indicator { position: absolute; z-index: 50; background: var(--ecx-ui); border-radius: 2px; pointer-events: none; }
117
119
  body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none !important; }
118
120
  .ecx-block.is-dragging-source { opacity: .35; }
121
+ /* Tô vùng đệm (trong) / lề (ngoài) khi rê ô Đệm / Lề ở bảng bên phải */
122
+ .ecx-spacing-viz { position: fixed; z-index: 60; pointer-events: none; display: grid; place-items: center; overflow: hidden; background: rgb(74 163 120 / .22); box-shadow: inset 0 0 0 1px rgb(46 125 90 / .45); }
123
+ .ecx-spacing-viz.is-margin { background: rgb(232 137 12 / .18); box-shadow: inset 0 0 0 1px rgb(184 104 0 / .45); }
124
+ .ecx-spacing-viz span { padding: 1px 6px; border-radius: 4px; background: rgb(255 255 255 / .9); color: #1f6b47; font: 600 11px/1.4 system-ui, sans-serif; white-space: nowrap; }
125
+ .ecx-spacing-viz.is-margin span { color: #8a4b00; }
126
+ /* Khối chứa sắp nhận khối thả: nền + viền nhẹ, trễ 100ms để lướt chuột qua không nháy */
127
+ .ecx-block.is-drop-parent { outline: 1px dashed color-mix(in srgb, var(--ecx-ui) 55%, transparent); outline-offset: 2px; box-shadow: inset 0 0 0 100vmax color-mix(in srgb, var(--ecx-ui) 6%, transparent); transition: outline-color .1s linear .1s, box-shadow .1s linear .1s; }
128
+ @media (prefers-reduced-motion: reduce) { .ecx-block.is-drop-parent { transition: none; } }
119
129
 
120
130
  /* Làm nổi khối đang sửa: các khối cấp cao nhất khác mờ đi */
121
131
  .is-spotlight > .ecx-block:not(.is-selected):not(.is-editing):not(:has(.is-selected, .is-editing)) { opacity: .3; transition: opacity .2s ease; }
@@ -126,7 +136,37 @@ body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select:
126
136
  /* Theme thường tạo kiểu mọi ô nhập (textarea { border; padding } textarea:focus { outline }) — ô tiêu đề không được mang khung ô nhập */
127
137
  .ecx-doc-title .ecx-doc-title-input, .ecx-doc-title .ecx-doc-title-input:focus { border: 0; border-radius: 0; outline: none; box-shadow: none; padding: 0; background: transparent; min-height: 0; }
128
138
  .ecx-col-handles { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
139
+ /* Dải kéo đệm trên / dưới của khối bố cục đang chọn */
140
+ .ecx-block.is-selected:has(> .ecx-pad-handles) { position: relative; }
141
+ /* Khối bố cục đang chọn: chỗ trống nắm được để kéo đổi chỗ; khối con / chữ giữ con trỏ thường */
142
+ .ecx-block[data-ecx-grab] { cursor: grab; }
143
+ .ecx-block[data-ecx-grab] .ecx-block, .ecx-block[data-ecx-grab] [data-ecx-rich] { cursor: auto; }
144
+ .ecx-pad-handles { position: absolute; inset: 0; max-width: none; margin: 0; pointer-events: none; z-index: 7; }
145
+ .ecx-block.is-selected:has(> .ecx-cw-handles) { position: relative; }
146
+ .ecx-cw-handles { position: absolute; inset: 0; max-width: none; margin: 0; pointer-events: none; z-index: 8; }
147
+ .ecx-cw-handle { position: absolute; top: 50%; width: 10px; height: 44px; margin: -22px 0 0 4px; border-radius: 6px; background: var(--ecx-ui); box-shadow: 0 0 0 2px #fff; cursor: ew-resize; pointer-events: auto; opacity: .55; touch-action: none; }
148
+ .ecx-cw-handle.is-left { margin-left: -14px; }
149
+ .ecx-cw-handle:hover, .ecx-cw-handle.is-dragging { opacity: 1; }
150
+ .ecx-cw-tip { position: absolute; top: -28px; left: 50%; transform: translateX(-50%); padding: 2px 8px; border-radius: 4px; background: var(--ecx-ui); color: #fff; font: 600 12px/1.4 system-ui, sans-serif; white-space: nowrap; pointer-events: none; }
151
+ .ecx-pad-handle { position: absolute; left: 0; width: min(40%, 320px); height: 12px; cursor: ns-resize; pointer-events: auto; touch-action: none; }
152
+ /* vắt qua mép: khối không đệm thì tay nắm chỉ lấn 6px, không che chữ của khối con */
153
+ .ecx-pad-handle.is-top { top: -6px; }
154
+ .ecx-pad-handle.is-bottom { bottom: -6px; }
155
+ .ecx-pad-handle::after { content: ""; position: absolute; left: 16px; width: 36px; height: 4px; border-radius: 3px; background: var(--ecx-ui); opacity: 0; transition: opacity .1s linear; }
156
+ .ecx-pad-handle.is-top::after { top: 4px; }
157
+ .ecx-pad-handle.is-bottom::after { bottom: 4px; }
158
+ .ecx-pad-handle:hover::after, .ecx-pad-handle.is-dragging::after { opacity: 1; }
159
+ /* Vùng kéo đệm / lề của khối bố cục đang chọn: rộng hết khối, cao bằng giá trị thật — kéo ở đâu trong vùng cũng được */
160
+ .ecx-pad-zone { position: absolute; left: 0; right: 0; cursor: ns-resize; pointer-events: auto; touch-action: none; }
161
+ /* vạch kéo ở 1/4 bề rộng: giữa mép dưới là nút "+ Thêm section" */
162
+ .ecx-pad-zone::after { content: ""; position: absolute; left: 25%; width: 36px; height: 4px; margin-left: -18px; border-radius: 3px; background: var(--ecx-ui); opacity: 0; transition: opacity .1s linear; }
163
+ .ecx-pad-zone.is-top::after { top: calc(50% - 2px); }
164
+ .ecx-pad-zone.is-bottom::after { bottom: calc(50% - 2px); }
165
+ .ecx-pad-zone:hover::after, .ecx-pad-zone.is-dragging::after { opacity: 1; }
129
166
  .ecx-col-handle { position: absolute; width: 12px; margin-left: -6px; cursor: col-resize; pointer-events: auto; touch-action: none; }
167
+ .ecx-col-handle.is-dragging::before, .ecx-col-handle.is-dragging::after { position: absolute; top: 8px; padding: 1px 6px; border-radius: 4px; background: var(--ecx-ui); color: #fff; font: 600 11px/1.5 system-ui, sans-serif; white-space: nowrap; pointer-events: none; }
168
+ .ecx-col-handle.is-dragging::before { content: attr(data-left); right: 14px; }
169
+ .ecx-col-handle.is-dragging::after { content: attr(data-right); left: 14px; width: auto; bottom: auto; opacity: 1; } /* ghi đè vạch 2px của ::after thường: nhãn % bên phải không bị cắt */
130
170
  .ecx-col-handle::after { content: ""; position: absolute; left: 5px; top: 0; bottom: 0; width: 2px; background: var(--ecx-ui); opacity: .35; border-radius: 1px; }
131
171
  .ecx-col-handle:hover::after { opacity: 1; }
132
172
  .ecx-image-handle { position: absolute; z-index: 6; width: 14px; height: 14px; border: 2px solid #fff; border-radius: 50%; background: var(--ecx-ui); cursor: nwse-resize; touch-action: none; box-shadow: 0 0 0 1px var(--ecx-ui); }
@@ -169,7 +209,7 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
169
209
  .ecx-canvas-root .ecx-table table { width: 100%; border-collapse: collapse; }
170
210
  .ecx-canvas-root .ecx-table :is(td, th) { min-width: 3em; height: 2.5em; outline: 1px dashed color-mix(in srgb, currentColor 22%, transparent); outline-offset: -1px; }
171
211
  /* Tabs: thanh tiêu đề luôn thấy và bấm được (thẻ đang ẩn: display none inline) */
172
- .ecx-canvas-root .ecx-tabs-list { display: flex; flex-wrap: wrap; min-height: 2.5em; }
212
+ .ecx-canvas-root .ecx-tabs-list { min-height: 2.5em; }
173
213
  .ecx-canvas-root .ecx-tab-button { cursor: pointer; }
174
214
  .ecx-canvas-root .ecx-tab-button [data-ecx-rich] { display: inline-block; min-width: 3em; }
175
215
  .ecx-btn-ghost { background: none; border-color: transparent; }
@@ -178,4 +218,96 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
178
218
  .ecx-add-column { position: absolute; right: 4px; bottom: 4px; z-index: 7; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px; background: #0f1e29; color: #fff; font: 600 18px/1 var(--ecx-ui-font); cursor: pointer; box-shadow: 0 2px 6px rgb(0 0 0 / .2); }
179
219
  .ecx-add-column:hover { background: var(--ecx-ui); }
180
220
  .is-zoomed-out .ecx-add-column { display: none; }
221
+
222
+ /* ===== Ô giữ chỗ (chỉ trình soạn; website không vẽ gì khi ô trống) ===== */
223
+ .ecx-ph-drop { align-items: center; justify-content: center; text-align: center; gap: 6px; min-height: 168px; padding: 24px 16px; box-sizing: border-box; border: 2px dashed #b8c2cc; border-radius: 10px; background: #f7f9fb; color: #33414d; transition: border-color .15s, color .15s, background .15s; }
224
+ .ecx-ph-drop.is-compact { min-height: 112px; padding: 14px 12px; }
225
+ .ecx-ph-drop:hover { border-color: var(--ecx-ui); color: var(--ecx-ui); }
226
+ .ecx-ph-drop.is-drop-target, .ecx-media-placeholder.is-drop-target { border-style: solid; border-color: var(--ecx-ui); background: color-mix(in srgb, var(--ecx-ui) 12%, #fff); color: var(--ecx-ui); outline: none; }
227
+ .ecx-ph-icon { width: 28px; height: 28px; }
228
+ .ecx-ph-title { display: inline-flex; align-items: center; justify-content: center; gap: 6px; margin: 0; font: 600 15px/1.4 var(--ecx-ui-font); }
229
+ .ecx-ph-drop .ecx-placeholder-hint { margin: 0 0 6px; color: #4a5763; opacity: 1; }
230
+ .ecx-ph-drop .ecx-media-actions { justify-content: center; }
231
+ .ecx-ph-drop .ecx-media-buttons { justify-content: center; }
232
+ .ecx-media-placeholder { color: #33414d; background: #f7f9fb; border-color: #b8c2cc; }
233
+ .ecx-ph-link, .ecx-ph-pick, .ecx-ph-choose, .ecx-ph-table, .ecx-ph-inline { border: 2px dashed #b8c2cc; border-radius: 10px; padding: 16px; gap: 8px; }
234
+ .ecx-ph-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; font: 13px/1.4 var(--ecx-ui-font); }
235
+ .ecx-ph-row .ecx-input { min-width: 0; }
236
+ .ecx-ph-link .ecx-ph-row .ecx-input { flex: 1 1 220px; }
237
+ .ecx-ph-label { font: 600 12px/1.4 var(--ecx-ui-font); color: #33414d; }
238
+ .ecx-ph-field { display: flex; flex-direction: column; gap: 4px; flex: 1 1 140px; min-width: 0; }
239
+ .ecx-ph-field .ecx-input { height: 36px; flex: none; width: 100%; box-sizing: border-box; }
240
+ .ecx-ph-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
241
+ .ecx-ph-fields .is-media { grid-column: 1 / -1; }
242
+ .ecx-ph-req { color: #b42318; }
243
+ .ecx-ph-thumb { position: relative; display: inline-block; }
244
+ .ecx-ph-thumb img { display: block; max-width: 160px; max-height: 120px; border-radius: 6px; }
245
+ .ecx-ph-thumb .ecx-tool { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .3); cursor: pointer; }
246
+ .ecx-ph-auto { align-items: stretch; }
247
+ .ecx-ph-auto.is-missing, .ecx-ph-theme.is-missing { border: 2px solid #f59e0b; }
248
+ .ecx-ph-missing { margin: 0; padding: 6px 10px; border-radius: 6px; background: #fff4e5; color: #8a2c0d; font: 600 12px/1.4 var(--ecx-ui-font); }
249
+ .ecx-ph-missing.is-note { margin-top: 6px; }
250
+ .ecx-ph-badge { display: inline-flex; align-self: flex-start; align-items: center; padding: 2px 8px; border-radius: 999px; font: 600 11px/1.6 var(--ecx-ui-font); }
251
+ .ecx-ph-badge.is-missing { background: #fff4e5; color: #8a2c0d; border: 1px solid #f59e0b; }
252
+ .ecx-ph-theme { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px; border-radius: 8px; background: #fffaf3; color: #33414d; font: 13px/1.4 var(--ecx-ui-font); }
253
+ .ecx-featured-image .ecx-ph-theme { height: 100%; box-sizing: border-box; justify-content: center; align-items: center; text-align: center; }
254
+ .ecx-ph-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
255
+ .ecx-ph-choice { display: inline-flex; flex-direction: column; align-items: center; gap: 6px; min-width: 96px; padding: 14px 12px; border: 1px solid #c9d0d7; border-radius: 8px; background: #fff; color: #1f2d38; font: 600 13px var(--ecx-ui-font); cursor: pointer; }
256
+ .ecx-ph-choice:hover, .ecx-ph-choice:focus-visible { border-color: var(--ecx-ui); color: var(--ecx-ui); }
257
+ .ecx-ph-choice .ecx-icon { width: 24px; height: 24px; }
258
+ .ecx-ph-choose { align-items: center; text-align: center; }
259
+ /* Lưới chọn bố cục cột khi vừa chèn Bộ cột: mỗi ô vẽ tỉ lệ các cột */
260
+ .ecx-col-layouts { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; width: 100%; max-width: 640px; }
261
+ .ecx-col-layout { display: flex; gap: 3px; height: 44px; padding: 6px; border: 1px solid #c9d0d7; border-radius: 6px; background: #fff; cursor: pointer; }
262
+ .ecx-col-layout span { flex-basis: 0; border-radius: 2px; background: #c3ccd5; }
263
+ .ecx-col-layout:hover, .ecx-col-layout:focus-visible { border-color: var(--ecx-ui); outline: none; }
264
+ .ecx-col-layout:hover span, .ecx-col-layout:focus-visible span { background: var(--ecx-ui); }
265
+ .ecx-ph-skip { border: 0; background: none; padding: 2px 4px; color: #4a5a68; font: 13px var(--ecx-ui-font); text-decoration: underline; cursor: pointer; }
266
+ .ecx-ph-skip:hover { color: var(--ecx-ui); }
267
+ /* Ô gõ của plugin / icon list: kế thừa phông + cỡ chữ của chỗ đặt ô */
268
+ .ecx-ph-text { box-sizing: border-box; width: 100%; min-width: 4em; margin: 0; padding: 0 0 1px; border: 0; border-bottom: 1px dashed color-mix(in srgb, currentColor 35%, transparent); border-radius: 0; background: transparent; color: inherit; font: inherit; letter-spacing: inherit; line-height: inherit; resize: vertical; outline: none; field-sizing: content; }
269
+ .ecx-ph-text::placeholder { color: inherit; opacity: .85; }
270
+ .ecx-ph-text:focus { border-bottom-color: var(--ecx-ui); }
271
+ .ecx-ph-field .ecx-ph-text.ecx-input { border: 1px solid #c9d0d7; border-radius: 6px; padding: 6px 8px; height: auto; min-height: 36px; background: #fff; color: #1f2d38; font: 14px/1.4 var(--ecx-ui-font); }
272
+ .ecx-ph-field .ecx-ph-text::placeholder { color: #5b6873; opacity: 1; }
273
+ /* Nút "+ Thêm khối" giữa khối chứa trống, "+ Thêm …" cuối danh sách */
274
+ .ecx-appender { gap: 6px; min-height: 56px; border: 2px dashed color-mix(in srgb, currentColor 35%, transparent); border-radius: 8px; font: 600 14px/1 var(--ecx-ui-font); opacity: .85; }
275
+ .ecx-appender .ecx-icon { width: 18px; height: 18px; }
276
+ .ecx-add-item { display: inline-flex; align-items: center; gap: 4px; margin: 6px 0 0; padding: 6px 10px; border: 1px dashed color-mix(in srgb, currentColor 40%, transparent); border-radius: 6px; background: transparent; color: inherit; font: 600 13px/1.2 var(--ecx-ui-font); cursor: pointer; opacity: .85; }
277
+ .ecx-add-item:hover, .ecx-add-item:focus-visible { opacity: 1; border-color: var(--ecx-ui); color: var(--ecx-ui); }
278
+ .ecx-tabs-list .ecx-add-item { margin: 0 0 0 8px; align-self: center; }
279
+ .ecx-social .ecx-add-item, .ecx-social-add .ecx-add-item { margin: 0; }
280
+ .ecx-ph-list-add { list-style: none; }
281
+ .ecx-ph-list-add .ecx-add-item { margin-top: 2px; }
282
+ .ecx-gallery-add { grid-column: auto; min-height: 0; aspect-ratio: 1; }
283
+ .ecx-gallery-add .ecx-placeholder-hint { display: none; }
284
+ /* Ảnh giữ tỉ lệ (không cắt / masonry): ô "+" không còn là ô vuông khổng lồ, ảnh không bị kéo giãn theo hàng */
285
+ .ecx-gallery.is-natural { align-items: start; }
286
+ .ecx-gallery.is-natural .ecx-gallery-add { aspect-ratio: auto; min-height: 7rem; }
287
+ /* Mã nguồn: chọn ngôn ngữ trên khối; danh sách số: số bắt đầu */
288
+ .ecx-ph-corner { display: flex; justify-content: flex-end; align-items: center; gap: 6px; margin: 0 0 6px; font: 12px var(--ecx-ui-font); white-space: normal; }
289
+ .ecx-ph-corner > label, .ecx-ph-corner > span { background: #fff; color: #33414d; border-radius: 4px; padding: 1px 6px; }
290
+ .ecx-ph-corner .ecx-input { width: auto; height: 28px; font-size: 12px; }
291
+ .ecx-ph-corner.is-list { list-style: none; justify-content: flex-start; margin: 6px 0 0; }
292
+ .ecx-ph-corner.is-list input { width: 72px; }
293
+ .ecx-ph-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
294
+ .ecx-ph-digits { font: 600 28px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .05em; }
295
+ .ecx-ph-star { padding: 0 1px; border: 0; background: none; font: inherit; line-height: 1; cursor: pointer; }
296
+ .ecx-ph-star:hover { transform: scale(1.15); }
297
+ .ecx-ph-tabs { display: flex; align-items: center; gap: 6px; margin: 0 0 6px; font: 600 12px var(--ecx-ui-font); }
298
+ .ecx-ph-tab { padding: 4px 10px; border: 1px solid #c9d0d7; border-radius: 6px; background: #fff; color: #33414d; font: 600 12px var(--ecx-ui-font); cursor: pointer; }
299
+ .ecx-ph-tab.is-active { background: var(--ecx-ui); border-color: var(--ecx-ui); color: #fff; }
300
+ .ecx-ph-tab:disabled { opacity: .5; cursor: default; }
301
+ .ecx-ph-inline-field { margin-top: 8px; justify-content: center; }
302
+ .ecx-ph-inline-field .ecx-input { width: 110px; flex: none; }
303
+ .ecx-ph-note { margin: .25rem 0; }
304
+ .ecx-ph-table .ecx-ph-field { flex: 0 1 110px; }
305
+ /* Khoảng trống: sọc mờ + kích thước; đường kẻ: vùng bấm cao ≥ 40px (không đổi bố cục) */
306
+ .ecx-spacer[data-ecx-size] { display: flex; align-items: center; justify-content: center; min-height: 24px; }
307
+ .ecx-spacer[data-ecx-size]::before { content: attr(data-ecx-size); padding: 2px 8px; border-radius: 4px; background: rgb(255 255 255 / .85); color: #33414d; font: 12px/1.4 var(--ecx-ui-font); opacity: 0; transition: opacity .15s; pointer-events: none; }
308
+ .ecx-spacer[data-ecx-size]:hover::before, .ecx-spacer.is-selected[data-ecx-size]::before { opacity: 1; }
309
+ .ecx-rating[data-ecx-placeholder] { display: flex; align-items: center; gap: 2px; min-height: 40px; }
310
+ .ecx-rating[data-ecx-placeholder] .ecx-placeholder-hint { margin: 0 0 0 8px; }
311
+ hr.ecx-block { position: relative; overflow: visible; }
312
+ hr.ecx-block::before { content: ""; position: absolute; left: 0; right: 0; top: -20px; bottom: -20px; }
181
313
  `;
@@ -13,6 +13,7 @@ import { wrapperNodes } from "./wrapper-props";
13
13
  import { makeBlock, type BNode } from "../core/model";
14
14
  import { flatten, topLevelOrdered } from "../core/ops";
15
15
  import { useTableRangeSelect } from "./table-select";
16
+ import { useMoveAnimation } from "./move-animation";
16
17
  import { clearCells, deleteRow, selectedCellRect, tableContext } from "../core/tables";
17
18
  import { insertSibling, now, richViews } from "../text/rich-text";
18
19
 
@@ -114,6 +115,7 @@ function CanvasRoot({ doc, contentClassName, before, after }: { doc: Document; c
114
115
  useCanvasStyles(doc);
115
116
  useCanvasKeys(doc);
116
117
  useCanvasEvents(doc);
118
+ useMoveAnimation(doc);
117
119
  useTableRangeSelect(doc);
118
120
  const hasRange = useRangeHighlight(doc);
119
121
  return (
@@ -246,6 +248,13 @@ function useCanvasEvents(doc: Document) {
246
248
  win.addEventListener("resize", bump);
247
249
  const ro = new ResizeObserver(bump);
248
250
  ro.observe(doc.body);
251
+ // Chọn cả khối (nút "Chọn khối cha", Cây khối, Esc…) trong khi tiêu điểm bàn phím còn ở ô gõ chữ bên trong:
252
+ // đưa tiêu điểm ra khung soạn, để ⌘⇧D / Delete / ⌘C tác động lên khối đang chọn chứ không lên đoạn văn bên trong.
253
+ const unsub = store.subscribe(() => {
254
+ if (!store.getState().selection.ids.length) return;
255
+ const ae = doc.activeElement as HTMLElement | null;
256
+ if (ae?.isContentEditable) doc.querySelector<HTMLElement>(".ecx-canvas-root")?.focus({ preventScroll: true });
257
+ });
249
258
  // Chuột phải / Shift+F10 / phím Menu trên khối → menu của khối (BlockContextMenu); Shift + chuột phải giữ menu của trình duyệt (chính tả, dán…)
250
259
  const menu = (e: MouseEvent) => {
251
260
  const el = (e.target as Element | null)?.closest?.<HTMLElement>("[data-ecx-block]");
@@ -263,7 +272,7 @@ function useCanvasEvents(doc: Document) {
263
272
  };
264
273
  doc.addEventListener("contextmenu", menu);
265
274
  return () => {
266
- win.removeEventListener("scroll", bump); win.removeEventListener("resize", bump); ro.disconnect(); cancelAnimationFrame(raf);
275
+ win.removeEventListener("scroll", bump); win.removeEventListener("resize", bump); ro.disconnect(); cancelAnimationFrame(raf); unsub();
267
276
  doc.removeEventListener("mousemove", moved); document.removeEventListener("mousemove", moved);
268
277
  doc.removeEventListener("contextmenu", menu);
269
278
  };
@@ -285,8 +294,8 @@ function useCanvasKeys(doc: Document) {
285
294
  const outer = fromTree(e);
286
295
  const mod = e.metaKey || e.ctrlKey;
287
296
  const k = e.key.toLowerCase();
288
- // Vừa bấm nút trên thanh đầu (Lưu, Hoàn tác…): focus ở trang ngoài (nút Lưu tắt sau khi lưu → focus về body) — ⌘Z/⌘Y vẫn là của trình soạn
289
- const fromTopbar = mod && (k === "z" || k === "y") && e.target instanceof Element && e.target.ownerDocument !== doc && !typing(e.target) && (!!e.target.closest(".ecx-topbar") || e.target === e.target.ownerDocument.body);
297
+ // Vừa bấm nút ở trang ngoài (thanh đầu, ô khối của thư viện, nút bảng phải…): focus ở trang ngoài (nút Lưu tắt sau khi lưu → focus về body) — ⌘Z/⌘Y vẫn là của trình soạn
298
+ const fromTopbar = mod && (k === "z" || k === "y") && e.target instanceof Element && e.target.ownerDocument !== doc && !typing(e.target) && !e.target.closest("[role=dialog], [role=menu], [aria-modal=true]");
290
299
  if (e.target instanceof Element && e.target.ownerDocument !== doc && !outer && !fromTopbar) return; // phím của trang ngoài ngoài Cây khối: không phải của khung soạn
291
300
  if (mod && k === "z") { e.preventDefault(); if (e.shiftKey) store.redo(); else store.undo(); return; }
292
301
  if (mod && k === "y") { e.preventDefault(); store.redo(); return; }
@@ -316,6 +325,12 @@ function useCanvasKeys(doc: Document) {
316
325
  }
317
326
  if (e.key === "Backspace" && !store.getState().selection.ids.length) { e.preventDefault(); return; }
318
327
  const ids = store.getState().selection.ids;
328
+ // Alt+Shift+↑ / ↓: đưa khối đang chọn lên / xuống một bước (giống nút Lên / Xuống của thanh công cụ)
329
+ if (e.altKey && e.shiftKey && !mod && ids.length && (e.key === "ArrowUp" || e.key === "ArrowDown")) {
330
+ e.preventDefault();
331
+ store.moveBy(ids, e.key === "ArrowUp" ? -1 : 1);
332
+ return;
333
+ }
319
334
  if (mod && k === "a") {
320
335
  e.preventDefault();
321
336
  store.select(store.getState().docs[store.activeDocId].blocks.map((b) => b.id), { editing: null });
@@ -378,6 +393,8 @@ function useCanvasKeys(doc: Document) {
378
393
  }
379
394
  if (mod && e.shiftKey && k === "d") { e.preventDefault(); store.duplicate(ids); return; }
380
395
  if (e.altKey && e.shiftKey && k === "z") { e.preventDefault(); store.remove(ids); return; }
396
+ // ⇧⌥⌘T / ⇧⌥⌘Y: chuyển khối lên / xuống (trượt về chỗ mới — move-animation)
397
+ if (mod && e.altKey && e.shiftKey && (e.code === "KeyT" || e.code === "KeyY")) { e.preventDefault(); store.moveBy(ids, e.code === "KeyT" ? -1 : 1); return; }
381
398
  if (mod && e.altKey && k === "t") { e.preventDefault(); insertSibling(store, ids[0], 0); return; }
382
399
  if (mod && e.altKey && k === "y") { e.preventDefault(); insertSibling(store, ids[ids.length - 1], 1); return; }
383
400
  };
@@ -3,6 +3,7 @@ import type { EditorContextValue, DropTarget } from "../context";
3
3
  import type { InsertOption } from "../ui/inserter";
4
4
  import type { BNode } from "../core/model";
5
5
  import { canContain } from "../core/structure";
6
+ import { freshWithDefaults } from "../core/block-presets";
6
7
  import { sectionOf } from "./block-list";
7
8
 
8
9
  /**
@@ -35,7 +36,8 @@ export function startDragBlocks(ctx: EditorContextValue, e: ReactPointerEvent, c
35
36
 
36
37
  function begin(ctx: EditorContextValue, e: ReactPointerEvent, src: Source) {
37
38
  const { ui, store } = ctx;
38
- const sx = e.clientX, sy = e.clientY;
39
+ // Nắm từ trong khung soạn (iframe) → đổi toạ độ về trang ngoài như lúc kéo
40
+ const { x: sx, y: sy } = toParent(ctx, e.nativeEvent);
39
41
  const handle = e.currentTarget as HTMLElement;
40
42
  let started = false;
41
43
  let scrollTimer = 0;
@@ -53,8 +55,18 @@ function begin(ctx: EditorContextValue, e: ReactPointerEvent, src: Source) {
53
55
  }
54
56
  const target = unlocked(store, findTarget(ctx, x, y, src));
55
57
  ui.setDrag({ ids: src.ids, newType: src.newType, x, y, target });
58
+ markParent(target?.parentId ?? null);
56
59
  autoScroll(ctx, y);
57
60
  };
61
+ // Khối chứa sắp nhận khối thả (cột, nhóm…) báo nền nhẹ (CSS trễ 100ms: lướt qua không nháy)
62
+ let parentEl: HTMLElement | null = null;
63
+ const markParent = (id: string | null) => {
64
+ const el = id ? ui.blockEl(id) : null;
65
+ if (el === parentEl) return;
66
+ parentEl?.classList.remove("is-drop-parent");
67
+ el?.classList.add("is-drop-parent");
68
+ parentEl = el;
69
+ };
58
70
  const cleanup = () => {
59
71
  document.removeEventListener("pointermove", move);
60
72
  document.removeEventListener("pointerup", up);
@@ -67,6 +79,7 @@ function begin(ctx: EditorContextValue, e: ReactPointerEvent, src: Source) {
67
79
  document.body.classList.remove("is-dragging");
68
80
  ui.canvasDoc?.body.classList.remove("is-dragging");
69
81
  for (const id of src.ids) ui.blockEl(id)?.classList.remove("is-dragging-source");
82
+ markParent(null);
70
83
  clearInterval(scrollTimer);
71
84
  try { handle.releasePointerCapture(pointerId); } catch { /* không giữ */ }
72
85
  };
@@ -77,7 +90,7 @@ function begin(ctx: EditorContextValue, e: ReactPointerEvent, src: Source) {
77
90
  ui.setDrag(null);
78
91
  if (!wasStarted || !target) return;
79
92
  if (src.create) {
80
- const made = src.create();
93
+ const made = freshWithDefaults(src.create());
81
94
  const nodes = Array.isArray(made) ? made : [made];
82
95
  store.insert(target.docId, target.parentId, target.index, nodes);
83
96
  if (nodes.length > 1) store.select([nodes[0].id]);
@@ -93,7 +106,8 @@ function begin(ctx: EditorContextValue, e: ReactPointerEvent, src: Source) {
93
106
  ui.setDrag(null);
94
107
  };
95
108
  // Kéo bị huỷ (mất con trỏ, đổi cửa sổ) → bỏ kéo, không để nhãn kéo kẹt trên màn hình
96
- const cancel = () => { cleanup(); ui.setDrag(null); };
109
+ // (focus chuyển vào khung soạn — nắm khối ngay trong iframe — cũng làm trang ngoài "blur": không phải huỷ)
110
+ const cancel = (ev?: Event) => { if (ev?.type === "blur" && document.activeElement === ui.canvasFrame) return; cleanup(); ui.setDrag(null); };
97
111
  document.addEventListener("pointercancel", cancel);
98
112
  window.addEventListener("blur", cancel);
99
113
  document.addEventListener("pointermove", move);
@@ -194,6 +208,23 @@ function findTarget(ctx: EditorContextValue, x: number, y: number, src: Source):
194
208
  if (node.content && !node.content.length && canContainAll(node.type, src.types)) {
195
209
  return { docId: loc.docId, parentId: node.id, index: 0, rect: toParentRect(r), horizontal: false };
196
210
  }
211
+ // Con trỏ nằm trong khoảng trống bên trong khối chứa (đệm, khe giữa các khối con): thả vào GIỮA các khối con gần nhất,
212
+ // không nhảy ra trước / sau cả khối. Sát mép khối (≤ 16px) vẫn là trước / sau khối đó, để đưa khối ra ngoài nhóm.
213
+ if (id === blockEl.dataset.ecxBlock && node.content?.length && canContainAll(node.type, src.types)) {
214
+ const el = ui.blockEl(id)!, row0 = isRow(el);
215
+ const edge = Math.min(16, (row0 ? r.width : r.height) / 4);
216
+ const inner = row0 ? ix > r.left + edge && ix < r.right - edge : iy > r.top + edge && iy < r.bottom - edge;
217
+ const kids = node.content.map((k) => ui.blockEl(k.id)?.getBoundingClientRect()).filter((x): x is DOMRect => !!x);
218
+ if (inner && kids.length === node.content.length) {
219
+ let idx = kids.length;
220
+ for (let i = 0; i < kids.length; i++) if (row0 ? ix < kids[i].left + kids[i].width / 2 : iy < kids[i].top + kids[i].height / 2) { idx = i; break; }
221
+ const ref = kids[Math.min(idx, kids.length - 1)];
222
+ const line = row0
223
+ ? new DOMRect((idx < kids.length ? ref.left : ref.right) - 2, ref.top, 4, ref.height)
224
+ : new DOMRect(ref.left, (idx < kids.length ? ref.top : ref.bottom) - 2, ref.width, 4);
225
+ return { docId: loc.docId, parentId: node.id, index: idx, rect: toParentRect(line), horizontal: row0 };
226
+ }
227
+ }
197
228
  const parentEl = ui.blockEl(id)!.parentElement;
198
229
  const horizontal = !!parentEl && isRow(parentEl);
199
230
  const after = horizontal ? ix > r.left + r.width / 2 : iy > r.top + r.height / 2;