@ecomcx/ecomweb-editor 1.25.2 → 1.26.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.
- package/package.json +3 -3
- package/src/locales/en/attrs.ts +1 -0
- package/src/locales/en/block-titles.ts +15 -3
- package/src/locales/en/blocks.ts +5 -0
- package/src/locales/en/controls.ts +4 -0
- package/src/locales/en/v2.ts +24 -0
- package/src/locales/vi/attrs.ts +1 -0
- package/src/locales/vi/block-titles.ts +12 -0
- package/src/locales/vi/blocks.ts +5 -0
- package/src/locales/vi/controls.ts +4 -0
- package/src/locales/vi/v2.ts +24 -0
- package/src/shared/color-swatch.tsx +4 -2
- package/src/v2/blocks/compat.tsx +3 -1
- package/src/v2/blocks/layout.tsx +6 -4
- package/src/v2/blocks/media-actions.tsx +2 -1
- package/src/v2/blocks/media.tsx +34 -1
- package/src/v2/blocks/theme.tsx +44 -4
- package/src/v2/canvas/block-list.tsx +7 -1
- package/src/v2/canvas/canvas-css.ts +33 -8
- package/src/v2/canvas/canvas.tsx +49 -4
- package/src/v2/canvas/dnd.ts +20 -0
- package/src/v2/canvas/table-select.ts +74 -0
- package/src/v2/core/host.ts +6 -1
- package/src/v2/core/media.ts +11 -0
- package/src/v2/core/tables.ts +69 -0
- package/src/v2/editor.css +14 -0
- package/src/v2/editor.tsx +1 -1
- package/src/v2/prefs.ts +10 -2
- package/src/v2/text/rich-text.tsx +2 -1
- package/src/v2/ui/ai.tsx +72 -0
- package/src/v2/ui/attr-form.tsx +7 -3
- package/src/v2/ui/color-field.tsx +7 -2
- package/src/v2/ui/inserter.tsx +36 -7
- package/src/v2/ui/list-view.tsx +7 -3
- package/src/v2/ui/options.tsx +1 -1
- package/src/v2/ui/style-tab.tsx +15 -5
- package/src/v2/ui/toolbar.tsx +51 -8
- package/src/v2/ui/unit-controls.tsx +5 -3
package/src/v2/ui/inserter.tsx
CHANGED
|
@@ -47,12 +47,13 @@ export function useInsertOptions(): InsertOption[] {
|
|
|
47
47
|
}, [registry, version, hidden, host.scope]);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/** Lọc + xếp hạng: tên bắt đầu bằng chữ gõ > một từ trong tên > từ khoá; tiếng Việt không dấu. */
|
|
50
|
+
/** Lọc + xếp hạng: tên trùng hẳn > tên bắt đầu bằng chữ gõ > một từ trong tên > từ khoá; tiếng Việt không dấu. */
|
|
51
51
|
export function rankOptions(list: InsertOption[], query: string): InsertOption[] {
|
|
52
52
|
const q = norm(query.trim());
|
|
53
53
|
if (!q) return list;
|
|
54
54
|
const score = (i: InsertOption) => {
|
|
55
55
|
const title = norm(i.title);
|
|
56
|
+
if (title === q) return 4; // "/anh" → Ảnh trước Ảnh bìa, Ảnh + chữ
|
|
56
57
|
if (title.startsWith(q)) return 3;
|
|
57
58
|
if (title.split(/\s+/).some((w) => w.startsWith(q))) return 2;
|
|
58
59
|
const words = [...title.split(/\s+/), ...norm(i.keywords).split(/\s+/)];
|
|
@@ -197,7 +198,7 @@ function suggestions(options: InsertOption[], counts: Record<string, number>): I
|
|
|
197
198
|
|
|
198
199
|
const CATEGORY_ORDER = ["text", "media", "design", "widgets", "theme", "embed"];
|
|
199
200
|
/** Thư viện khối (cột trái): tìm, theo nhóm; bấm để chèn sau khối đang chọn, kéo thả vào khung soạn. */
|
|
200
|
-
export function InserterPanel({ onInserted }: { onInserted?(): void }) {
|
|
201
|
+
export function InserterPanel({ onInserted, onClose }: { onInserted?(): void; onClose?(): void }) {
|
|
201
202
|
const ctx = useEditor();
|
|
202
203
|
const { store, labels } = ctx;
|
|
203
204
|
useUiTick();
|
|
@@ -205,29 +206,57 @@ export function InserterPanel({ onInserted }: { onInserted?(): void }) {
|
|
|
205
206
|
// Khối có luật vị trí (vd "Tổng số bài" chỉ trong Query): ẩn khi từ chỗ đang chọn đi lên tới gốc không có cấp nào nhận
|
|
206
207
|
const cur = store.currentIds[store.currentIds.length - 1];
|
|
207
208
|
const loc = cur ? store.locate(cur) : null;
|
|
208
|
-
|
|
209
|
-
const
|
|
209
|
+
// Chèn vào đúng cấp của khối đang chọn (anh em của nó) → chỉ xét cha trực tiếp; xét cả tổ tiên thì khối như "Tổng số bài" hiện ra nhưng bị loại lặng lẽ khi chèn
|
|
210
|
+
const parentType = loc?.ancestors.length ? store.block(loc.ancestors[loc.ancestors.length - 1])?.type ?? null : null;
|
|
211
|
+
const options = all.filter((o) => canContain(parentType, o.type));
|
|
212
|
+
const panelRef = useRef<HTMLDivElement>(null);
|
|
213
|
+
// Mở bảng (nút Thêm khối) → focus vào ô tìm của bảng như WordPress; người dùng bàn phím gõ tìm ngay, Tab đi trong bảng
|
|
214
|
+
useEffect(() => { panelRef.current?.querySelector<HTMLInputElement>("input")?.focus({ preventScroll: true }); }, []);
|
|
215
|
+
// Escape đóng bảng (khi focus đang ở bảng hoặc chưa ở đâu cả; đang gõ trong khung soạn thì Escape thuộc về khung soạn)
|
|
216
|
+
useEffect(() => {
|
|
217
|
+
if (!onClose) return;
|
|
218
|
+
const onKey = (e: KeyboardEvent) => {
|
|
219
|
+
if (e.key !== "Escape" || ctx.ui.inserter) return;
|
|
220
|
+
const a = document.activeElement as HTMLElement | null;
|
|
221
|
+
if (a && !panelRef.current?.contains(a) && (a.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(a.tagName))) return;
|
|
222
|
+
onClose();
|
|
223
|
+
};
|
|
224
|
+
// Nút "Thêm khối" giữ focus trong khung soạn (iframe) nên phím Esc có thể rơi vào tài liệu của khung soạn, không phải trang ngoài
|
|
225
|
+
const frameDoc = ctx.ui.canvasDoc;
|
|
226
|
+
document.addEventListener("keydown", onKey);
|
|
227
|
+
frameDoc?.addEventListener("keydown", onKey);
|
|
228
|
+
return () => { document.removeEventListener("keydown", onKey); frameDoc?.removeEventListener("keydown", onKey); };
|
|
229
|
+
}, [onClose, ctx.ui]);
|
|
210
230
|
const [query, setQuery] = useState("");
|
|
211
231
|
const [tab, setTab] = useState<"blocks" | "patterns">("blocks");
|
|
212
232
|
const [hover, setHover] = useState<{ o: InsertOption; rect: DOMRect; y: number } | null>(null);
|
|
213
233
|
const results = rankOptions(options, query);
|
|
214
234
|
const catLabel: Record<string, string> = { text: labels.catText, media: labels.catMedia, design: labels.catDesign, widgets: labels.catWidgets, theme: labels.catTheme, embed: labels.catEmbed };
|
|
215
235
|
const p = usePrefs(ctx.prefs);
|
|
216
|
-
|
|
236
|
+
// "Đã dùng nhiều" tính một lần lúc mở bảng: chèn xong mà mục này hiện/đổi thì cả lưới khối nhảy xuống, bấm nhanh liên tiếp dễ trượt sang khối khác
|
|
237
|
+
const counts = useRef(p.insertCounts).current;
|
|
238
|
+
const mostUsed = p.mostUsedBlocks && !query ? options.filter((o) => !o.key.includes("/") && (counts[o.type] ?? 0) > 0).sort((a, b) => (counts[b.type] ?? 0) - (counts[a.type] ?? 0)).slice(0, 6) : [];
|
|
239
|
+
const lastInserted = useRef<string | null>(null);
|
|
217
240
|
const groups = query ? [["", results] as const] : [...CATEGORY_ORDER, ...new Set(results.map((r) => r.category).filter((c) => !CATEGORY_ORDER.includes(c)))].map((c) => [c, results.filter((r) => r.category === c)] as const).filter(([, l]) => l.length);
|
|
218
241
|
const insert = (o: InsertOption) => {
|
|
219
242
|
const node = o.create();
|
|
220
243
|
ctx.prefs.countInsert(o.type);
|
|
221
244
|
const cur = store.currentIds[store.currentIds.length - 1];
|
|
222
|
-
|
|
245
|
+
// Đoạn trống đang chọn mà chính lần chèn trước vừa tạo thì giữ lại (chèn tiếp ra sau nó); đoạn trống của người dùng thì thay như WordPress
|
|
246
|
+
const curLoc = cur ? store.locate(cur) : null;
|
|
247
|
+
const curBlock = cur ? store.block(cur) : null;
|
|
248
|
+
// Đang chọn khối chứa còn trống (Nhóm, Cột… vừa tạo): chèn VÀO trong nó — chèn ra sau thì phải kéo vào thêm một bước
|
|
249
|
+
if (curLoc && curBlock && Array.isArray(curBlock.content) && curBlock.content.length === 0 && canContain(curBlock.type, node.type)) store.insert(curLoc.docId, cur, 0, [node]);
|
|
250
|
+
else if (cur && curLoc) store.insertAfter(cur, [node], { replaceEmpty: cur !== lastInserted.current });
|
|
223
251
|
else {
|
|
224
252
|
const docId = store.activeDocId;
|
|
225
253
|
store.insert(docId, null, store.getState().docs[docId].blocks.length, [node]);
|
|
226
254
|
}
|
|
255
|
+
lastInserted.current = node.id;
|
|
227
256
|
onInserted?.();
|
|
228
257
|
};
|
|
229
258
|
return (
|
|
230
|
-
<div className="ecx-inserter-panel" onMouseLeave={() => setHover(null)}>
|
|
259
|
+
<div ref={panelRef} className="ecx-inserter-panel" role="dialog" aria-label={labels.addBlock} onMouseLeave={() => setHover(null)}>
|
|
231
260
|
{hover && (
|
|
232
261
|
// Thẻ xem trước khi rê chuột: biểu tượng, tên, mô tả của khối
|
|
233
262
|
<div className="ecx-block-preview" role="tooltip" style={{ left: Math.round(hover.rect.right + 8), top: Math.round(Math.min(hover.y, window.innerHeight - 160)) }}>
|
package/src/v2/ui/list-view.tsx
CHANGED
|
@@ -25,17 +25,18 @@ export function ListView() {
|
|
|
25
25
|
if (!doc) return null;
|
|
26
26
|
return (
|
|
27
27
|
<div className="ecx-listview" role="tree" aria-label={labels.listView}>
|
|
28
|
-
{doc.blocks.map((b) => <ListRow key={b.id} node={b} depth={0} />)}
|
|
28
|
+
{doc.blocks.map((b, i) => <ListRow key={b.id} node={b} depth={0} first={i === 0} />)}
|
|
29
29
|
{!doc.blocks.length && <p className="ecx-muted ecx-list-empty">{labels.listEmpty}</p>}
|
|
30
30
|
|
|
31
31
|
</div>
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function ListRow({ node, depth }: { node: BNode; depth: number }) {
|
|
35
|
+
function ListRow({ node, depth, first }: { node: BNode; depth: number; first?: boolean }) {
|
|
36
36
|
const ctx = useEditor();
|
|
37
37
|
const { store, registry, ui, host } = ctx;
|
|
38
38
|
const selected = useEditorState(useCallback((s) => s.selection.ids.includes(node.id) || s.selection.editing === node.id, [node.id]));
|
|
39
|
+
const anySelected = useEditorState((s) => s.selection.ids.length > 0 || !!s.selection.editing);
|
|
39
40
|
const [open, setOpen] = useState(depth < 1);
|
|
40
41
|
const type = registry.get(node.type);
|
|
41
42
|
const Icon = type?.icon ?? Blocks;
|
|
@@ -48,12 +49,15 @@ function ListRow({ node, depth }: { node: BNode; depth: number }) {
|
|
|
48
49
|
return (
|
|
49
50
|
<div role="treeitem" aria-selected={selected} aria-expanded={hasKids ? open : undefined} aria-level={depth + 1}>
|
|
50
51
|
<div className={cx("ecx-list-row", selected && "is-selected", nestedId && "is-nested")} style={{ paddingLeft: 8 + depth * 14 }} data-block={node.id}
|
|
52
|
+
// Một tabstop cho cả cây (hàng đang chọn, không thì hàng đầu); mũi tên di chuyển, Enter/Space chọn (WAI-ARIA tree)
|
|
53
|
+
tabIndex={selected || (first && !anySelected) ? 0 : -1}
|
|
54
|
+
onKeyDown={(e) => { if ((e.key === "Enter" || e.key === " ") && e.target === e.currentTarget) { e.preventDefault(); store.select([node.id], { editing: null }); } }}
|
|
51
55
|
onClick={(e) => {
|
|
52
56
|
if (e.shiftKey) store.selectRange(node.id);
|
|
53
57
|
else store.select([node.id], { editing: null });
|
|
54
58
|
ui.blockEl(node.id)?.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
|
55
59
|
}}>
|
|
56
|
-
{hasKids ? <button type="button" className="ecx-twisty" aria-label={open ?
|
|
60
|
+
{hasKids ? <button type="button" className="ecx-twisty" aria-label={open ? ctx.labels.collapse : ctx.labels.expand} onClick={(e) => { e.stopPropagation(); setOpen(!open); }}>{open ? <ChevronDown className="ecx-icon" /> : <ChevronRight className="ecx-icon" />}</button> : <span className="ecx-twisty" />}
|
|
57
61
|
<Icon className="ecx-icon" />
|
|
58
62
|
<span className="ecx-list-title">{blockLabel(node, type)}</span>
|
|
59
63
|
{!!(node.attrs.lock || node.attrs.templateLock) && <Lock className="ecx-icon ecx-icon-sm" aria-label={ctx.labels.locked} />}
|
package/src/v2/ui/options.tsx
CHANGED
|
@@ -75,7 +75,7 @@ export function MoreMenu({ extra }: { extra?: (close: () => void) => ReactNode }
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/** Hộp thoại dùng chung (Esc / bấm nền để đóng, giữ focus trong hộp). */
|
|
78
|
-
function Modal({ title, onClose, children, wide }: { title: string; onClose(): void; children: ReactNode; wide?: boolean }) {
|
|
78
|
+
export function Modal({ title, onClose, children, wide }: { title: string; onClose(): void; children: ReactNode; wide?: boolean }) {
|
|
79
79
|
const ref = useRef<HTMLDivElement>(null);
|
|
80
80
|
const { labels } = useEditor();
|
|
81
81
|
useEffect(() => {
|
package/src/v2/ui/style-tab.tsx
CHANGED
|
@@ -69,8 +69,18 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
69
69
|
commit(next);
|
|
70
70
|
};
|
|
71
71
|
const setGroup = (k: "color" | "border", sub: string, v: unknown) => set(k, { ...(style[k] ?? {}), [sub]: v });
|
|
72
|
-
|
|
73
|
-
const
|
|
72
|
+
// 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
|
|
73
|
+
const reset = (keys: string[]) => {
|
|
74
|
+
const next: Style = { ...style };
|
|
75
|
+
for (const k of keys) {
|
|
76
|
+
if (RESPONSIVE.has(k) && device !== "base" && style[k] && typeof style[k] === "object") {
|
|
77
|
+
const r = { ...style[k] }; delete r[device];
|
|
78
|
+
next[k] = Object.keys(r).length ? r : undefined;
|
|
79
|
+
} else delete next[k];
|
|
80
|
+
}
|
|
81
|
+
commit(next);
|
|
82
|
+
};
|
|
83
|
+
const has = (keys: string[]) => keys.some((k) => RESPONSIVE.has(k) && device !== "base" ? style[k]?.[device] !== undefined : style[k] !== undefined);
|
|
74
84
|
const ok = (k: string) => (v: string) => !!normalizeStyle({ [k]: v });
|
|
75
85
|
const tag = (k: string) => RESPONSIVE.has(k) && device !== "base" ? <em className="ecx-device-tag">{t[`device_${device}` as keyof EditorLabels]}</em> : null;
|
|
76
86
|
const row = (k: string, label: string, control: ReactNode) => (
|
|
@@ -113,7 +123,7 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
113
123
|
</>}>
|
|
114
124
|
{row("fontSize", t.style_fontSize, <>
|
|
115
125
|
<Seg label={t.style_fontSize} value={get("fontSize")} onChange={(v) => set("fontSize", v)} options={sizes.map((v) => [v, v.toUpperCase(), v] as [string, string, string])} />
|
|
116
|
-
<ValueInput label={`${t.style_fontSize}: ${t.custom}`} value={sizes.includes(get("fontSize")) ? undefined : get("fontSize")} inherited={inherited("fontSize")} check={ok("fontSize")} placeholder="18px, 1.25rem" onCommit={(v) => set("fontSize", v)} />
|
|
126
|
+
<ValueInput label={`${t.style_fontSize}: ${t.custom}`} value={sizes.includes(get("fontSize")) ? undefined : get("fontSize")} inherited={inherited("fontSize")} check={(v) => sizes.includes(v) || (ok("fontSize")(v) && /^([\d.]|(calc|clamp|min|max|var)\()/.test(v))} placeholder="18px, 1.25rem" onCommit={(v) => set("fontSize", v)} />
|
|
117
127
|
</>)}
|
|
118
128
|
{row("appearance", t.style_appearance,
|
|
119
129
|
<select className="ecx-input" value={appearance} aria-label={t.style_appearance} onChange={(e) => {
|
|
@@ -136,8 +146,8 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
136
146
|
<Section title={t.style_spacing} modified={has(SPACING)} onReset={() => reset(SPACING)} moreOpen={has(["gap", "width", "maxWidth", "minHeight"])}
|
|
137
147
|
more={<>{(["gap", "width", "maxWidth", "minHeight"] as const).map((k) =>
|
|
138
148
|
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)} />))}</>}>
|
|
139
|
-
<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, link: t.linkSides, unlink: t.unlinkSides }} />
|
|
140
|
-
<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, link: t.linkSides, unlink: t.unlinkSides }} />
|
|
149
|
+
<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 }} />
|
|
150
|
+
<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 }} />
|
|
141
151
|
</Section>
|
|
142
152
|
|
|
143
153
|
<Section title={t.style_border} modified={has(["border", "radius"])} onReset={() => reset(["border", "radius"])} defaultOpen={has(["border", "radius"])}>
|
package/src/v2/ui/toolbar.tsx
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WIDE_BLOCKS } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { clearCells, mergeRange, selectedCellRect } from "../core/tables";
|
|
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 } from "lucide-react";
|
|
2
5
|
import { TextSelection } from "prosemirror-state";
|
|
3
6
|
import type { EditorView } from "prosemirror-view";
|
|
4
|
-
import { useEffect, useLayoutEffect, useRef, useState, type ComponentType, type ReactNode } from "react";
|
|
7
|
+
import { useEffect, useLayoutEffect, useRef, useState, type ComponentType, type KeyboardEvent as ReactKeyboardEvent, type ReactNode } from "react";
|
|
5
8
|
import { createPortal } from "react-dom";
|
|
6
9
|
import { serializeBlocks } from "../core/clipboard";
|
|
7
10
|
|
|
@@ -92,7 +95,10 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
|
|
|
92
95
|
// Đo vị trí SAU khi DOM của khung soạn cập nhật (khối vừa tạo chưa có DOM lúc vẽ thanh công cụ)
|
|
93
96
|
const [rect, setRect] = useState<DOMRect | null>(null);
|
|
94
97
|
useLayoutEffect(() => {
|
|
95
|
-
|
|
98
|
+
// Trong bảng: thanh công cụ neo theo cả bảng (như WordPress) — neo theo ô thì thanh đè lên hàng phía trên
|
|
99
|
+
const loc0 = ids[0] ? store.locate(ids[0]) : null;
|
|
100
|
+
const table = loc0 ? [...loc0.ancestors].reverse().find((a) => store.block(a)?.type === "table") : undefined;
|
|
101
|
+
const r = table ? ui.blockRect(table) : unionRect(ids.map((id) => ui.blockRect(id)));
|
|
96
102
|
setRect((prev) => (prev && r && prev.x === r.x && prev.y === r.y && prev.width === r.width && prev.height === r.height ? prev : r));
|
|
97
103
|
});
|
|
98
104
|
const nodes = ids.map((id) => store.block(id)).filter(Boolean) as BNode[];
|
|
@@ -117,11 +123,22 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
|
|
|
117
123
|
const listItem = parent && (parent.type === "listItem" || parent.type === "taskItem") && loc.index === 0 ? parent : null;
|
|
118
124
|
const transforms = sameType ? (type?.transforms ?? []).filter((t) => nodes.length === 1 || t.multiple) : [];
|
|
119
125
|
const height = 44;
|
|
120
|
-
|
|
121
|
-
const
|
|
126
|
+
// Trên khối; không đủ chỗ (khối sát mép trên khung) thì xuống dưới khối nếu còn chỗ — không đè lên dòng chữ đang gõ
|
|
127
|
+
const above = rect && frame ? rect.top - height - 8 : 0;
|
|
128
|
+
const below = rect && frame && above < frame.top + 4 && rect.bottom + 8 + height <= frame.bottom - 4 ? rect.bottom + 8 : null;
|
|
129
|
+
const top = fixed || !rect || !frame ? 0 : Math.round(below ?? Math.max(frame.top + 4, above));
|
|
130
|
+
// Bề ngang theo KHUNG SOẠN (khổ Điện thoại 390px hẹp hơn cửa sổ): thanh dài hơn khung thì cuộn ngang trong khung, không tràn ra ngoài
|
|
131
|
+
const maxW = frame ? Math.max(120, frame.width - 8) : undefined;
|
|
132
|
+
const left = fixed || !rect || !frame ? 0 : Math.round(Math.max(frame.left + 4, Math.min(rect.left, frame.right - 4 - Math.min(420, maxW!))));
|
|
122
133
|
const editProps = { block: first, attrs: first.attrs, setAttrs: (a: Record<string, unknown>) => store.setAttrs(ids, a), blockProps: null as never, selected: true, editable: true, labels };
|
|
123
134
|
const Extra = sameType && nodes.length === 1 ? type?.toolbar : undefined;
|
|
124
135
|
const hasAlign = sameType && !!type?.attributes?.textAlign;
|
|
136
|
+
// Độ rộng (như alignwide/alignfull của WP): chỉ khối cấp cao nhất — khối lồng trong nhóm/cột theo bề rộng của khối cha
|
|
137
|
+
const hasWidth = sameType && !parent && WIDE_BLOCKS.includes(first.type);
|
|
138
|
+
// Vùng ô đang bôi đen (không gõ chữ): gộp cả vùng / xoá nội dung
|
|
139
|
+
const cellRange = sel.ids.length ? selectedCellRect(store, sel.ids) : null;
|
|
140
|
+
const cellSel = cellRange ? { ...cellRange, many: sel.ids.length > 1 } : null;
|
|
141
|
+
const width = first.attrs.align === "wide" || first.attrs.align === "full" ? (first.attrs.align as string) : "";
|
|
125
142
|
|
|
126
143
|
const doTransform = (t: BlockTransform) => {
|
|
127
144
|
const res = t.convert(ordered.map((id) => store.block(id)!));
|
|
@@ -171,7 +188,7 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
|
|
|
171
188
|
|
|
172
189
|
return (
|
|
173
190
|
<>
|
|
174
|
-
<div className={fixed ? "ecx-toolbar is-fixed" : "ecx-toolbar"} role="toolbar" aria-label={type?.title ?? first.type} style={fixed ? undefined : { top, left }} data-block={first.id}
|
|
191
|
+
<div className={fixed ? "ecx-toolbar is-fixed" : "ecx-toolbar"} role="toolbar" aria-label={type?.title ?? first.type} style={fixed ? undefined : { top, left, maxWidth: maxW }} data-block={first.id}
|
|
175
192
|
onKeyDown={(e) => {
|
|
176
193
|
// Bàn phím trên thanh công cụ: ←/→ đi giữa các nút, Esc quay về khối
|
|
177
194
|
const buttons = Array.from(e.currentTarget.querySelectorAll<HTMLButtonElement>(":scope > .ecx-tool-group button:not(:disabled), :scope > .ecx-tool-group .ecx-dropdown > button"));
|
|
@@ -219,6 +236,22 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
|
|
|
219
236
|
))}
|
|
220
237
|
</div>
|
|
221
238
|
)}
|
|
239
|
+
{cellSel && (
|
|
240
|
+
<div className="ecx-tool-group" data-ecx-cell-tools>
|
|
241
|
+
{cellSel.many && <ToolButton label={labels.mergeCells} className="ecx-tool-wide" onClick={() => mergeRange(store, cellSel.table, cellSel.docId, cellSel.rect)}><TableCellsMerge className="ecx-icon" /><span className="ecx-tool-text">{labels.mergeCells}</span></ToolButton>}
|
|
242
|
+
<ToolButton label={labels.clearCells} onClick={() => clearCells(store, cellSel.table, ids)}><Eraser className="ecx-icon" /></ToolButton>
|
|
243
|
+
</div>
|
|
244
|
+
)}
|
|
245
|
+
{hasWidth && (
|
|
246
|
+
<div className="ecx-tool-group">
|
|
247
|
+
<Dropdown label={labels.width} trigger={<span className="ecx-tool-text" data-ecx-width={width || "default"}>{width === "full" ? <Maximize2 className="ecx-icon" /> : width === "wide" ? <MoveHorizontal className="ecx-icon" /> : <RectangleHorizontal className="ecx-icon" />}</span>}>
|
|
248
|
+
{(close) => ([["", RectangleHorizontal, labels.widthDefault], ["wide", MoveHorizontal, labels.widthWide], ["full", Maximize2, labels.widthFull]] as const).map(([v, I, l]) => (
|
|
249
|
+
<MenuItem key={v || "default"} icon={I} label={(v === width ? "✓ " : "") + l} onClick={() => { close(); if (v !== width) store.setAttrs(ids, { align: v || undefined }); }} />
|
|
250
|
+
))}
|
|
251
|
+
</Dropdown>
|
|
252
|
+
</div>
|
|
253
|
+
)}
|
|
254
|
+
{nodes.length === 1 && first.inline && !type?.plain && ctx.host.ai && <div className="ecx-tool-group"><AiTools block={first} /></div>}
|
|
222
255
|
{view && !type?.plain && !type?.multiline && <MarkTools view={view} onLink={() => setLink(ui.activeRich ?? sel.editing)} />}
|
|
223
256
|
{listItem && (
|
|
224
257
|
<div className="ecx-tool-group">
|
|
@@ -227,7 +260,7 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
|
|
|
227
260
|
</div>
|
|
228
261
|
)}
|
|
229
262
|
{Extra && <div className="ecx-tool-group"><Extra {...editProps} /></div>}
|
|
230
|
-
{nodes.length === 1 && contextTools(loc.ancestors, first.id)}
|
|
263
|
+
{(nodes.length === 1 || cellSel) && contextTools(loc.ancestors, first.id)}
|
|
231
264
|
{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>}
|
|
232
265
|
<div className="ecx-tool-group">
|
|
233
266
|
<Dropdown label={labels.more} trigger={<MoreVertical className="ecx-icon" />}>
|
|
@@ -380,6 +413,16 @@ export function DropIndicator() {
|
|
|
380
413
|
}
|
|
381
414
|
|
|
382
415
|
/** Hộp khoá khối: không cho di chuyển / xoá; khối chứa: khoá bố cục bên trong hoặc chỉ cho sửa nội dung. */
|
|
416
|
+
/** Tab / Shift+Tab xoay vòng trong hộp thoại (tự chuyển focus — WebKit mặc định không Tab tới nút nên focus thoát ra ngoài). */
|
|
417
|
+
function trapTab(e: ReactKeyboardEvent<HTMLElement>) {
|
|
418
|
+
if (e.key !== "Tab") return;
|
|
419
|
+
const items = [...e.currentTarget.querySelectorAll<HTMLElement>('button:not([disabled]), input:not([disabled]), select, textarea, a[href], [tabindex]:not([tabindex="-1"])')];
|
|
420
|
+
if (!items.length) return;
|
|
421
|
+
e.preventDefault();
|
|
422
|
+
const i = items.indexOf(e.target as HTMLElement);
|
|
423
|
+
items[(i + (e.shiftKey ? -1 : 1) + items.length) % items.length].focus();
|
|
424
|
+
}
|
|
425
|
+
|
|
383
426
|
function LockDialog({ block, onClose }: { block: BNode; onClose(): void }) {
|
|
384
427
|
const { store, labels } = useEditor();
|
|
385
428
|
const lock = (block.attrs.lock as { move?: boolean; remove?: boolean } | undefined) ?? {};
|
|
@@ -389,7 +432,7 @@ function LockDialog({ block, onClose }: { block: BNode; onClose(): void }) {
|
|
|
389
432
|
store.setAttrs([block.id], { lock: next.move || next.remove ? next : undefined });
|
|
390
433
|
};
|
|
391
434
|
return (
|
|
392
|
-
<div className="ecx-modal-backdrop" onMouseDown={(e) => { if (e.target === e.currentTarget) onClose(); }} onKeyDown={(e) => { if (e.key === "Escape") onClose(); }}>
|
|
435
|
+
<div className="ecx-modal-backdrop" onMouseDown={(e) => { if (e.target === e.currentTarget) onClose(); }} onKeyDown={(e) => { if (e.key === "Escape") onClose(); else trapTab(e); }}>
|
|
393
436
|
<div className="ecx-modal" role="dialog" aria-modal="true" aria-label={labels.lockTitle}>
|
|
394
437
|
<header className="ecx-modal-header"><h2>{labels.lockTitle}</h2></header>
|
|
395
438
|
<div className="ecx-lock-body">
|
|
@@ -69,7 +69,7 @@ const sidesOf = (v: Box): Record<string, string> => (typeof v === "object" && v
|
|
|
69
69
|
|
|
70
70
|
/** Lề trong / ngoài: liên kết (một giá trị) hoặc dọc + ngang. */
|
|
71
71
|
export function SpacingControl({ label, value, onChange, steps, inherited, labels }: {
|
|
72
|
-
label: string; value: Box; onChange(v: Box): void; steps: string[]; inherited?: string; labels: { vertical: string; horizontal: string; link: string; unlink: string };
|
|
72
|
+
label: string; value: Box; onChange(v: Box): void; steps: string[]; inherited?: string; labels: { vertical: string; horizontal: string; link: string; unlink: string; top: string; right: string; bottom: string; left: string };
|
|
73
73
|
}) {
|
|
74
74
|
const sides = sidesOf(value);
|
|
75
75
|
const [linked, setLinked] = useState(typeof value !== "object" || value === null || (sides.top === sides.bottom && sides.left === sides.right && sides.top === sides.left));
|
|
@@ -92,8 +92,10 @@ export function SpacingControl({ label, value, onChange, steps, inherited, label
|
|
|
92
92
|
{linked
|
|
93
93
|
? <StepSlider label={label} steps={steps} value={typeof value === "string" ? value : sides.top} onChange={(v) => set(["top", "right", "bottom", "left"], v)} sideIcon="is-all" />
|
|
94
94
|
: <>
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
{/* Bỏ liên kết: bốn cạnh riêng (đặt lệch được, vd chỉ padding-bottom) */}
|
|
96
|
+
{(["top", "right", "bottom", "left"] as const).map((side) => (
|
|
97
|
+
<StepSlider key={side} label={`${label} ${labels[side]}`} steps={steps} value={sides[side]} onChange={(v) => set([side], v)} sideIcon={`is-${side}`} />
|
|
98
|
+
))}
|
|
97
99
|
</>}
|
|
98
100
|
</div>
|
|
99
101
|
);
|