@ecomcx/ecomweb-editor 1.31.0 → 1.33.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 +10 -0
- package/src/locales/en/background.ts +17 -0
- package/src/locales/en/bindings.ts +1 -1
- package/src/locales/en/block-desc.ts +2 -0
- package/src/locales/en/block-style.ts +7 -4
- package/src/locales/en/block-titles.ts +2 -0
- package/src/locales/en/blocks.ts +12 -3
- package/src/locales/en/columns.ts +12 -0
- package/src/locales/en/controls.ts +21 -0
- package/src/locales/en/hints.ts +289 -1
- package/src/locales/en/index.ts +5 -2
- package/src/locales/en/layout.ts +32 -0
- package/src/locales/en/legacy.ts +1 -1
- package/src/locales/en/library.ts +38 -0
- package/src/locales/en/parts.ts +12 -0
- package/src/locales/en/placeholders.ts +12 -1
- package/src/locales/en/presets.ts +6 -0
- package/src/locales/en/v2.ts +21 -0
- package/src/locales/vi/attrs.ts +10 -0
- package/src/locales/vi/background.ts +17 -0
- package/src/locales/vi/bindings.ts +1 -1
- package/src/locales/vi/block-desc.ts +2 -0
- package/src/locales/vi/block-style.ts +7 -4
- package/src/locales/vi/block-titles.ts +2 -0
- package/src/locales/vi/blocks.ts +12 -3
- package/src/locales/vi/columns.ts +12 -0
- package/src/locales/vi/controls.ts +21 -0
- package/src/locales/vi/hints.ts +290 -2
- package/src/locales/vi/index.ts +5 -2
- package/src/locales/vi/layout.ts +32 -0
- package/src/locales/vi/legacy.ts +1 -1
- package/src/locales/vi/library.ts +38 -0
- package/src/locales/vi/parts.ts +12 -0
- package/src/locales/vi/placeholders.ts +12 -1
- package/src/locales/vi/presets.ts +6 -0
- package/src/locales/vi/v2.ts +21 -0
- package/src/shared/panel-store.ts +3 -3
- package/src/shared/patterns.ts +3 -52
- package/src/shared/style-panel.tsx +2 -2
- package/src/shared/types.ts +2 -0
- package/src/v2/blocks/columns-inspector.tsx +210 -0
- package/src/v2/blocks/form.tsx +4 -4
- package/src/v2/blocks/index.ts +10 -4
- package/src/v2/blocks/inline-style.ts +1 -1
- package/src/v2/blocks/layout.tsx +211 -44
- package/src/v2/blocks/media.tsx +22 -13
- package/src/v2/blocks/resize.tsx +172 -4
- package/src/v2/blocks/text.tsx +14 -7
- package/src/v2/blocks/theme.tsx +63 -19
- package/src/v2/blocks/tools.tsx +50 -5
- package/src/v2/blocks/widgets.tsx +44 -16
- package/src/v2/canvas/block-list.tsx +23 -3
- package/src/v2/canvas/canvas-css.ts +70 -4
- package/src/v2/canvas/canvas.tsx +22 -5
- package/src/v2/canvas/dnd.ts +34 -3
- package/src/v2/canvas/move-animation.ts +94 -0
- package/src/v2/canvas/spacing-viz.ts +51 -0
- package/src/v2/core/block-presets.ts +68 -0
- package/src/v2/core/host.ts +6 -1
- package/src/v2/core/structure.ts +2 -1
- package/src/v2/editor.css +238 -9
- package/src/v2/editor.tsx +8 -2
- package/src/v2/ui/attr-form.tsx +59 -12
- package/src/v2/ui/attr-hints.ts +140 -9
- package/src/v2/ui/background-panel.tsx +65 -21
- package/src/v2/ui/bindings.tsx +3 -0
- package/src/v2/ui/block-icons.tsx +152 -0
- package/src/v2/ui/block-menu.ts +22 -0
- package/src/v2/ui/block-style-panel.tsx +14 -3
- package/src/v2/ui/color-field.tsx +74 -9
- package/src/v2/ui/divider-panel.tsx +58 -0
- package/src/v2/ui/group-width.tsx +38 -0
- package/src/v2/ui/icon-picker.tsx +51 -0
- package/src/v2/ui/inserter.tsx +61 -12
- package/src/v2/ui/inspector.tsx +48 -16
- package/src/v2/ui/layout-panel.tsx +5 -47
- package/src/v2/ui/list-view.tsx +81 -7
- package/src/v2/ui/motion-panel.tsx +2 -1
- package/src/v2/ui/parts-panel.tsx +164 -0
- package/src/v2/ui/pattern-library.tsx +228 -0
- package/src/v2/ui/preset-bar.tsx +83 -0
- package/src/v2/ui/style-controls.tsx +65 -15
- package/src/v2/ui/style-supports.ts +1 -1
- package/src/v2/ui/style-tab.tsx +127 -41
- package/src/v2/ui/toolbar.tsx +52 -13
- package/src/v2/ui/unit-controls.tsx +88 -39
- package/src/locales/en/patterns.ts +0 -50
- package/src/locales/vi/patterns.ts +0 -50
- package/src/shared/patterns-kit.ts +0 -7
- package/src/shared/patterns-library.ts +0 -172
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { CORE_NODES, ICON_NAMES, ICON_PATHS, 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 {
|
|
9
|
+
import { Section } from "../ui/style-controls";
|
|
10
10
|
import { MediaPick } from "./layout";
|
|
11
11
|
import { useActiveWithin } from "./resize";
|
|
12
12
|
import { AddItemButton, TextPlaceholder } from "../ui/placeholders";
|
|
@@ -18,7 +18,7 @@ const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "strin
|
|
|
18
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).
|
|
19
19
|
*/
|
|
20
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" };
|
|
21
|
+
const FIELD_PH: Record<string, string> = { title: "boxTitle", text: "boxText", quote: "testimonialQuote", name: "testimonialName", role: "testimonialRole", label: "skill", address: "mapAddress" };
|
|
22
22
|
|
|
23
23
|
function WidgetEdit(props: BlockEditProps) {
|
|
24
24
|
const { block, blockProps, setAttrs, editable } = props;
|
|
@@ -59,9 +59,10 @@ function IconListEdit({ block, blockProps, setAttrs, editable }: BlockEditProps)
|
|
|
59
59
|
const items: Array<{ text: string; href?: string; icon?: string }> = Array.isArray(block.attrs.items) ? block.attrs.items : [];
|
|
60
60
|
const list = items.length || !editable ? items : [{ text: "" }];
|
|
61
61
|
const save = (next: typeof items) => setAttrs({ items: next });
|
|
62
|
-
const
|
|
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>;
|
|
63
64
|
return (
|
|
64
|
-
<ul {...blockProps} className={cx(blockProps.className,
|
|
65
|
+
<ul {...blockProps} className={cx(blockProps.className, iconListClass(block.attrs))}>
|
|
65
66
|
{list.map((it, i) => (
|
|
66
67
|
<li key={i}>{icon(it.icon)}{editable
|
|
67
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)))} />
|
|
@@ -72,19 +73,44 @@ function IconListEdit({ block, blockProps, setAttrs, editable }: BlockEditProps)
|
|
|
72
73
|
);
|
|
73
74
|
}
|
|
74
75
|
|
|
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. */
|
|
76
77
|
function IconListInspector({ attrs, setAttrs }: BlockEditProps) {
|
|
77
78
|
const t = useMsgs("blocks") as Record<string, string>;
|
|
79
|
+
const h = useMsgs("hints") as Record<string, string>;
|
|
78
80
|
const items: Array<{ text: string; href?: string; icon?: string }> = Array.isArray(attrs.items) ? attrs.items : [];
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
+
);
|
|
85
106
|
}
|
|
86
107
|
|
|
87
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
|
+
}
|
|
88
114
|
const ICON_SELECT = { type: "string" as const, enum: ICON_NAMES };
|
|
89
115
|
|
|
90
116
|
/** Khối widget của lõi; `lang` = ngôn ngữ của trình soạn (chữ mẫu khi chèn). */
|
|
@@ -92,11 +118,13 @@ export function widgetBlocks(lang?: string): BlockType[] {
|
|
|
92
118
|
const m = messages("blocks", lang) as Record<string, string>;
|
|
93
119
|
const base = { kind: "atom" as const, category: "widgets", edit: WidgetEdit, supports: { style: true, anchor: true, className: true } };
|
|
94
120
|
return [
|
|
95
|
-
{ ...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: "", text: "" }), summary: (a) => a.title },
|
|
96
|
-
|
|
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 },
|
|
97
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: "" }] }) },
|
|
98
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 },
|
|
99
|
-
{ ...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: "", name: "", role: "" }), summary: (a) => a.name },
|
|
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 },
|
|
100
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 },
|
|
101
129
|
];
|
|
102
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";
|
|
@@ -21,8 +22,12 @@ export function sectionOf(store: ReturnType<typeof useEditor>["store"], el: HTML
|
|
|
21
22
|
}
|
|
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. */
|
|
25
|
+
/** Khối chứa mà con phủ kín: có nhãn rê chuột để bấm chọn chính khối chứa (xem canvas-css). */
|
|
26
|
+
const LABELED = new Set(["query", "postTemplate", "queryEmpty", "templatePart", "tabs", "tab", "accordion", "details", "carousel", "columns", "column", "buttons", "form", "mediaText", "cover"]);
|
|
27
|
+
|
|
24
28
|
export function useBlockProps(block: BNode, state: { selected: boolean; editing: boolean; mode: EditingMode }): BlockProps {
|
|
25
|
-
const
|
|
29
|
+
const ctx = useEditor();
|
|
30
|
+
const { store, registry, ui } = ctx;
|
|
26
31
|
const a = block.attrs;
|
|
27
32
|
const style = a.style && typeof a.style === "object" ? normalizeStyle(a.style) : undefined;
|
|
28
33
|
const type = registry.get(block.type);
|
|
@@ -42,7 +47,8 @@ export function useBlockProps(block: BNode, state: { selected: boolean; editing:
|
|
|
42
47
|
if (store.modeOf(block.id) === "disabled") return;
|
|
43
48
|
const rich = target.closest<HTMLElement>("[data-ecx-rich]");
|
|
44
49
|
if (rich && rich.isContentEditable && !e.shiftKey) return; // bấm vào chữ: ProseMirror đặt con trỏ, focus báo đang gõ
|
|
45
|
-
|
|
50
|
+
// Ô nhập / nút thật của khối đặt chỗ tự xử lý; riêng vùng đánh dấu data-ecx-inert (bản xem trước không bấm được, vd khối Tìm kiếm) thì bấm vào là chọn khối
|
|
51
|
+
if (target.closest("input, textarea, select, button, [contenteditable=true]") && !target.closest("[data-ecx-inert]") && !e.shiftKey) return;
|
|
46
52
|
// Bấm vào phần đệm của ô bảng: con trỏ vào chữ trong ô (như bấm vào ô của Word / WordPress), không chọn cả ô
|
|
47
53
|
if ((block.type === "tableCell" || block.type === "tableHeader") && !e.shiftKey && !e.metaKey && !e.ctrlKey) {
|
|
48
54
|
const text = block.content?.find((b) => b.inline);
|
|
@@ -60,10 +66,23 @@ export function useBlockProps(block: BNode, state: { selected: boolean; editing:
|
|
|
60
66
|
if (own.isContentEditable) own.ownerDocument.querySelector<HTMLElement>(".ecx-canvas-root")?.focus({ preventScroll: true });
|
|
61
67
|
else own.focus({ preventScroll: true });
|
|
62
68
|
}, [block.id, store, ui]);
|
|
69
|
+
// 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)
|
|
70
|
+
const grab = state.selected && type?.kind !== "text";
|
|
71
|
+
const onPointerDown = useCallback((e: PointerEvent<HTMLElement>) => {
|
|
72
|
+
const t = e.target as HTMLElement;
|
|
73
|
+
if (e.button !== 0 || e.shiftKey || e.metaKey || e.ctrlKey || ui.zoomOut) return;
|
|
74
|
+
if (t.closest("[data-ecx-block]")?.getAttribute("data-ecx-block") !== block.id) return;
|
|
75
|
+
// Chỉ xét trong khối (cả khung soạn là contenteditable)
|
|
76
|
+
const hit = t.closest("[data-ecx-rich], input, textarea, select, button, a, [contenteditable=true], .ecx-pad-handles, .ecx-col-handles, .ecx-image-handle");
|
|
77
|
+
if (hit && e.currentTarget.contains(hit) && !hit.closest("[data-ecx-inert]")) return;
|
|
78
|
+
const ids = store.getState().selection.ids;
|
|
79
|
+
startDrag(ctx, e, ids.includes(block.id) ? ids : [block.id]);
|
|
80
|
+
}, [block.id, ctx, store, ui]);
|
|
63
81
|
return {
|
|
64
82
|
ref: null,
|
|
65
83
|
"data-ecx-block": block.id,
|
|
66
84
|
"data-type": block.type,
|
|
85
|
+
...(LABELED.has(block.type) ? { "data-ecx-label": type?.title ?? block.type } : {}),
|
|
67
86
|
tabIndex: type?.kind === "text" ? undefined : -1,
|
|
68
87
|
id: typeof a.anchor === "string" ? a.anchor : undefined,
|
|
69
88
|
className: cx(
|
|
@@ -78,6 +97,7 @@ export function useBlockProps(block: BNode, state: { selected: boolean; editing:
|
|
|
78
97
|
typeof a.className === "string" && a.className,
|
|
79
98
|
),
|
|
80
99
|
onMouseDown,
|
|
100
|
+
...(grab ? { onPointerDown, "data-ecx-grab": "" } : {}),
|
|
81
101
|
};
|
|
82
102
|
}
|
|
83
103
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Nạp TRƯỚC CSS của website nên không đè kiểu dáng nội dung; dùng outline (theme hầu như không dùng) để không đổi bố cục.
|
|
4
4
|
*/
|
|
5
5
|
export const CANVAS_CSS = String.raw`
|
|
6
|
-
:root { --ecx-ui-font: "Be Vietnam Pro", ui-sans-serif, system-ui, sans-serif; --ecx-ui: #1a597b; --ecx-ui-nested: #
|
|
6
|
+
:root { --ecx-ui-font: "Be Vietnam Pro", ui-sans-serif, system-ui, sans-serif; --ecx-ui: #1a597b; --ecx-ui-nested: #f26251; --ecx-ui-soft: color-mix(in srgb, var(--ecx-ui) 8%, transparent); color-scheme: light; }
|
|
7
7
|
html, body { margin: 0; min-height: 100%; }
|
|
8
8
|
body.ecx-canvas-body { padding: 0; }
|
|
9
9
|
/* Nền trắng chỉ là mặc định (độ ưu tiên 0): theme nền tối / có màu nền riêng trên body thì canvas phải theo theme */
|
|
@@ -64,9 +64,10 @@ span[data-ecx-rich][data-empty][data-placeholder] { min-width: calc(var(--ecx-ph
|
|
|
64
64
|
span[data-ecx-rich][data-empty][data-placeholder] { display: inline-block; vertical-align: top; }
|
|
65
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 */
|
|
66
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:
|
|
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 */
|
|
68
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) */
|
|
69
|
-
[data-ecx-rich][data-empty][data-placeholder]::before { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
|
|
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) */
|
|
70
71
|
.ProseMirror-hideselection *::selection { background: transparent; }
|
|
71
72
|
.ProseMirror-selectednode { outline: 2px solid var(--ecx-ui); }
|
|
72
73
|
.ecx-inline-atom { padding: 0 .25em; border-radius: 4px; background: var(--ecx-ui-soft); font-size: .85em; }
|
|
@@ -117,6 +118,14 @@ span[data-ecx-rich][data-empty][data-placeholder] { display: inline-block; verti
|
|
|
117
118
|
.ecx-drop-indicator { position: absolute; z-index: 50; background: var(--ecx-ui); border-radius: 2px; pointer-events: none; }
|
|
118
119
|
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none !important; }
|
|
119
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; } }
|
|
120
129
|
|
|
121
130
|
/* Làm nổi khối đang sửa: các khối cấp cao nhất khác mờ đi */
|
|
122
131
|
.is-spotlight > .ecx-block:not(.is-selected):not(.is-editing):not(:has(.is-selected, .is-editing)) { opacity: .3; transition: opacity .2s ease; }
|
|
@@ -127,7 +136,37 @@ body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select:
|
|
|
127
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 */
|
|
128
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; }
|
|
129
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; }
|
|
130
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 */
|
|
131
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; }
|
|
132
171
|
.ecx-col-handle:hover::after { opacity: 1; }
|
|
133
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); }
|
|
@@ -170,7 +209,7 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
|
|
|
170
209
|
.ecx-canvas-root .ecx-table table { width: 100%; border-collapse: collapse; }
|
|
171
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; }
|
|
172
211
|
/* Tabs: thanh tiêu đề luôn thấy và bấm được (thẻ đang ẩn: display none inline) */
|
|
173
|
-
.ecx-canvas-root .ecx-tabs-list {
|
|
212
|
+
.ecx-canvas-root .ecx-tabs-list { min-height: 2.5em; }
|
|
174
213
|
.ecx-canvas-root .ecx-tab-button { cursor: pointer; }
|
|
175
214
|
.ecx-canvas-root .ecx-tab-button [data-ecx-rich] { display: inline-block; min-width: 3em; }
|
|
176
215
|
.ecx-btn-ghost { background: none; border-color: transparent; }
|
|
@@ -217,6 +256,14 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
|
|
|
217
256
|
.ecx-ph-choice:hover, .ecx-ph-choice:focus-visible { border-color: var(--ecx-ui); color: var(--ecx-ui); }
|
|
218
257
|
.ecx-ph-choice .ecx-icon { width: 24px; height: 24px; }
|
|
219
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); }
|
|
220
267
|
/* Ô gõ của plugin / icon list: kế thừa phông + cỡ chữ của chỗ đặt ô */
|
|
221
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; }
|
|
222
269
|
.ecx-ph-text::placeholder { color: inherit; opacity: .85; }
|
|
@@ -229,11 +276,22 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
|
|
|
229
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; }
|
|
230
277
|
.ecx-add-item:hover, .ecx-add-item:focus-visible { opacity: 1; border-color: var(--ecx-ui); color: var(--ecx-ui); }
|
|
231
278
|
.ecx-tabs-list .ecx-add-item { margin: 0 0 0 8px; align-self: center; }
|
|
279
|
+
/* Thanh chuyển slide của carousel (chỉ trên khung soạn) */
|
|
280
|
+
.ecx-carousel-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 8px 0 0; font: 600 12px/1 var(--ecx-ui-font); user-select: none; }
|
|
281
|
+
.ecx-carousel-nav:empty { display: none; }
|
|
282
|
+
.ecx-carousel-nav .ecx-add-item { margin: 0 0 0 8px; }
|
|
283
|
+
.ecx-carousel-nav button { display: inline-flex; align-items: center; justify-content: center; min-width: 28px; height: 28px; padding: 0 6px; border: 1px solid #c9d0d7; border-radius: 6px; background: #fff; color: #1f2d38; font: inherit; cursor: pointer; }
|
|
284
|
+
.ecx-carousel-nav button[aria-current="true"] { border-color: var(--ecx-ui); background: var(--ecx-ui); color: #fff; }
|
|
285
|
+
.ecx-carousel-nav button:disabled { opacity: .4; cursor: default; }
|
|
286
|
+
.ecx-carousel-nav .ecx-icon { width: 16px; height: 16px; }
|
|
232
287
|
.ecx-social .ecx-add-item, .ecx-social-add .ecx-add-item { margin: 0; }
|
|
233
288
|
.ecx-ph-list-add { list-style: none; }
|
|
234
289
|
.ecx-ph-list-add .ecx-add-item { margin-top: 2px; }
|
|
235
290
|
.ecx-gallery-add { grid-column: auto; min-height: 0; aspect-ratio: 1; }
|
|
236
291
|
.ecx-gallery-add .ecx-placeholder-hint { display: none; }
|
|
292
|
+
/* Ả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 */
|
|
293
|
+
.ecx-gallery.is-natural { align-items: start; }
|
|
294
|
+
.ecx-gallery.is-natural .ecx-gallery-add { aspect-ratio: auto; min-height: 7rem; }
|
|
237
295
|
/* Mã nguồn: chọn ngôn ngữ trên khối; danh sách số: số bắt đầu */
|
|
238
296
|
.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; }
|
|
239
297
|
.ecx-ph-corner > label, .ecx-ph-corner > span { background: #fff; color: #33414d; border-radius: 4px; padding: 1px 6px; }
|
|
@@ -261,3 +319,11 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
|
|
|
261
319
|
hr.ecx-block { position: relative; overflow: visible; }
|
|
262
320
|
hr.ecx-block::before { content: ""; position: absolute; left: 0; right: 0; top: -20px; bottom: -20px; }
|
|
263
321
|
`;
|
|
322
|
+
|
|
323
|
+
export const CONTAINER_LABEL_CSS = `
|
|
324
|
+
/* Khối chứa mà con phủ kín (Danh sách bài, Khuôn mỗi bài, Phần mẫu, Tabs…): rê chuột hiện nhãn ở góc trên trái, bấm nhãn = chọn khối chứa */
|
|
325
|
+
.ecx-canvas-root [data-ecx-label]:hover { position: relative; }
|
|
326
|
+
.ecx-canvas-root [data-ecx-label]:hover:not(:has([data-ecx-label]:hover))::before {
|
|
327
|
+
content: attr(data-ecx-label); position: absolute; top: 0; left: 0; z-index: 30; padding: 2px 8px; border-radius: 0 0 6px 0; background: var(--ecx-ui, #1a597b); color: #fff;
|
|
328
|
+
font: 600 11px/18px var(--ecx-ui-font, system-ui); letter-spacing: .02em; cursor: pointer; pointer-events: auto; white-space: nowrap; }
|
|
329
|
+
`;
|
package/src/v2/canvas/canvas.tsx
CHANGED
|
@@ -7,12 +7,13 @@ import { DocBlocks } from "./block-list";
|
|
|
7
7
|
import { BLOCKS_MIME, blocksFromClipboard, serializeBlocks } from "../core/clipboard";
|
|
8
8
|
import { DocScopeProvider, useEditor, useEditorState, useUiTick } from "../context";
|
|
9
9
|
import { usePrefs } from "../prefs";
|
|
10
|
-
import { CANVAS_CSS } from "./canvas-css";
|
|
10
|
+
import { CANVAS_CSS, CONTAINER_LABEL_CSS } from "./canvas-css";
|
|
11
11
|
import { applyDocumentAttrs } from "./document-attrs";
|
|
12
12
|
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 (
|
|
@@ -158,7 +160,7 @@ function useCanvasStyles(doc: Document) {
|
|
|
158
160
|
const add = (el: HTMLElement) => { head.appendChild(el); nodes.push(el); };
|
|
159
161
|
const base = doc.createElement("style");
|
|
160
162
|
base.dataset.ecx = "canvas";
|
|
161
|
-
base.textContent = CANVAS_CSS;
|
|
163
|
+
base.textContent = CANVAS_CSS + CONTAINER_LABEL_CSS;
|
|
162
164
|
add(base);
|
|
163
165
|
for (const s of host.canvasStyles ?? []) {
|
|
164
166
|
if (typeof s === "string") {
|
|
@@ -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
|
|
289
|
-
const fromTopbar = mod && (k === "z" || k === "y") && e.target instanceof Element && e.target.ownerDocument !== doc && !typing(e.target) &&
|
|
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
|
};
|
package/src/v2/canvas/dnd.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { useEditor } from "../context";
|
|
3
|
+
import type { BNode } from "../core/model";
|
|
4
|
+
import type { EditorState } from "../core/store";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Khối trượt về chỗ mới khi thứ tự đổi (lên / xuống, kéo thả, chèn, xoá, hoàn tác) thay vì nhảy (kiểu FLIP):
|
|
8
|
+
* thứ tự trong cây đổi → đo vị trí cũ ngay lúc store báo (DOM chưa vẽ lại) → khung hình kế tiếp đo vị trí mới →
|
|
9
|
+
* đặt khối về chỗ cũ rồi thả về 0. Gõ chữ không đổi thứ tự → không đo, không chạy.
|
|
10
|
+
*/
|
|
11
|
+
export const MOVE_MS = 340;
|
|
12
|
+
// Dừng êm, không nảy (như lò xo tắt dần): quãng đường còn lại giảm theo hàm mũ, hằng số thời gian 75ms → ~35% sau 40ms, ~70% sau 100ms
|
|
13
|
+
const TAU = 75;
|
|
14
|
+
export const MOVE_EASE = `linear(${Array.from({ length: 21 }, (_, i) => { const t = (i / 20) * MOVE_MS; return ((1 - Math.exp(-t / TAU)) / (1 - Math.exp(-MOVE_MS / TAU))).toFixed(3) + ` ${i * 5}%`; }).join(", ")})`;
|
|
15
|
+
// Trình duyệt chưa hiểu linear(): đường cong gần giống
|
|
16
|
+
const FALLBACK_EASE = "cubic-bezier(.25, .7, .3, 1)";
|
|
17
|
+
|
|
18
|
+
/** Vị trí của mọi khối trong cây: id → "cha:thứ tự". */
|
|
19
|
+
export function orderMap(docs: EditorState["docs"]): Map<string, string> {
|
|
20
|
+
const out = new Map<string, string>();
|
|
21
|
+
const walk = (list: readonly BNode[], parent: string) => list.forEach((b, i) => { out.set(b.id, `${parent}:${i}`); if (b.content) walk(b.content, b.id); });
|
|
22
|
+
for (const d of Object.values(docs)) walk(d.blocks, d.id);
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Khối cần trượt: đã có trước, đổi chỗ trong cây, và vị trí trên màn hình đổi; bỏ khối con khi khối cha cùng trượt một quãng. */
|
|
27
|
+
export function movesToAnimate(before: Map<string, string>, after: Map<string, string>, oldRects: Map<string, DOMRect>, newRect: (id: string) => DOMRect | null, parentOf: (id: string) => string | null) {
|
|
28
|
+
const moves = new Map<string, { dx: number; dy: number }>();
|
|
29
|
+
for (const id of after.keys()) {
|
|
30
|
+
const o = oldRects.get(id);
|
|
31
|
+
if (!before.has(id) || !o) continue; // khối mới chèn: hiện ngay
|
|
32
|
+
const n = newRect(id);
|
|
33
|
+
if (!n) continue;
|
|
34
|
+
const dx = o.left - n.left, dy = o.top - n.top;
|
|
35
|
+
if (Math.abs(dx) < 1 && Math.abs(dy) < 1) continue;
|
|
36
|
+
moves.set(id, { dx, dy });
|
|
37
|
+
}
|
|
38
|
+
// Khối cha đã trượt → khối con đi theo; chỉ trượt riêng phần chênh lệch
|
|
39
|
+
const abs = new Map(moves);
|
|
40
|
+
for (const [id, m] of abs) {
|
|
41
|
+
for (let p = parentOf(id); p; p = parentOf(p)) {
|
|
42
|
+
const pm = abs.get(p);
|
|
43
|
+
if (!pm) continue;
|
|
44
|
+
const rx = m.dx - pm.dx, ry = m.dy - pm.dy;
|
|
45
|
+
if (Math.abs(rx) < 1 && Math.abs(ry) < 1) moves.delete(id); else moves.set(id, { dx: rx, dy: ry });
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return moves;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function useMoveAnimation(doc: Document) {
|
|
53
|
+
const { store } = useEditor();
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const win = doc.defaultView;
|
|
56
|
+
if (!win) return;
|
|
57
|
+
let docs = store.getState().docs;
|
|
58
|
+
let order = orderMap(docs);
|
|
59
|
+
let raf = 0;
|
|
60
|
+
const els = () => doc.querySelectorAll<HTMLElement>("[data-ecx-block]");
|
|
61
|
+
const off = store.subscribe(() => {
|
|
62
|
+
const next = store.getState().docs;
|
|
63
|
+
if (next === docs) return;
|
|
64
|
+
const nextOrder = orderMap(next);
|
|
65
|
+
docs = next;
|
|
66
|
+
let changed = nextOrder.size !== order.size;
|
|
67
|
+
if (!changed) for (const [id, p] of nextOrder) if (order.get(id) !== p) { changed = true; break; }
|
|
68
|
+
const before = order;
|
|
69
|
+
order = nextOrder;
|
|
70
|
+
if (!changed || win.matchMedia?.("(prefers-reduced-motion: reduce)").matches) return;
|
|
71
|
+
// DOM vẫn là bản cũ: đo vị trí cũ (bỏ phần đang trượt dở)
|
|
72
|
+
const old = new Map<string, DOMRect>();
|
|
73
|
+
for (const el of els()) {
|
|
74
|
+
for (const a of el.getAnimations?.() ?? []) if (a.id === "ecx-move") a.finish();
|
|
75
|
+
old.set(el.dataset.ecxBlock!, el.getBoundingClientRect());
|
|
76
|
+
}
|
|
77
|
+
win.cancelAnimationFrame(raf);
|
|
78
|
+
raf = win.requestAnimationFrame(() => {
|
|
79
|
+
const byId = new Map<string, HTMLElement>();
|
|
80
|
+
for (const el of els()) byId.set(el.dataset.ecxBlock!, el);
|
|
81
|
+
const parentOf = (id: string) => byId.get(id)?.parentElement?.closest<HTMLElement>("[data-ecx-block]")?.dataset.ecxBlock ?? null;
|
|
82
|
+
const moves = movesToAnimate(before, nextOrder, old, (id) => byId.get(id)?.getBoundingClientRect() ?? null, parentOf);
|
|
83
|
+
for (const [id, { dx, dy }] of moves) {
|
|
84
|
+
const el = byId.get(id);
|
|
85
|
+
if (!el?.animate) continue;
|
|
86
|
+
const frames = [{ transform: `translate(${dx}px, ${dy}px)` }, { transform: "translate(0, 0)" }];
|
|
87
|
+
try { el.animate(frames, { duration: MOVE_MS, easing: MOVE_EASE, id: "ecx-move" }); }
|
|
88
|
+
catch { el.animate(frames, { duration: MOVE_MS, easing: FALLBACK_EASE, id: "ecx-move" }); }
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
return () => { off(); win.cancelAnimationFrame(raf); };
|
|
93
|
+
}, [doc, store]);
|
|
94
|
+
}
|