@ecomcx/ecomweb-editor 1.27.0 → 1.28.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/background.ts +22 -0
- package/src/locales/en/block-desc.ts +30 -1
- package/src/locales/en/index.ts +2 -1
- package/src/locales/en/v2.ts +5 -0
- package/src/locales/vi/background.ts +22 -0
- package/src/locales/vi/block-desc.ts +30 -1
- package/src/locales/vi/index.ts +2 -1
- package/src/locales/vi/v2.ts +5 -0
- package/src/shared/block-defs.ts +5 -0
- package/src/shared/panel-store.ts +65 -7
- package/src/v2/blocks/compat.tsx +1 -0
- package/src/v2/blocks/index.ts +2 -1
- package/src/v2/canvas/block-list.tsx +3 -1
- package/src/v2/canvas/canvas.tsx +80 -7
- package/src/v2/canvas/dnd.ts +15 -2
- package/src/v2/context.tsx +6 -0
- package/src/v2/core/registry.ts +2 -1
- package/src/v2/editor.css +21 -0
- package/src/v2/editor.tsx +20 -6
- package/src/v2/index.ts +3 -3
- package/src/v2/ui/background-panel.tsx +83 -0
- package/src/v2/ui/block-menu.ts +19 -0
- package/src/v2/ui/inserter.tsx +21 -6
- package/src/v2/ui/inspector.tsx +45 -8
- package/src/v2/ui/layout-panel.tsx +5 -5
- package/src/v2/ui/section-adder.tsx +58 -0
- package/src/v2/ui/style-supports.ts +29 -0
- package/src/v2/ui/style-tab.tsx +24 -15
- package/src/v2/ui/toolbar.tsx +123 -34
- package/src/v2/ui/unit-controls.tsx +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecomcx/ecomweb-editor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0",
|
|
4
4
|
"description": "Trình soạn nội dung dạng khối của CMS — dùng độc lập trong mọi dự án React (1.x: TipTap; ./v2: cây khối, khung soạn iframe, sửa header/footer tại chỗ).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"*.css"
|
|
30
30
|
],
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@ecomcx/ecomweb-content": "^1.
|
|
32
|
+
"@ecomcx/ecomweb-content": "^1.22.0",
|
|
33
33
|
"react": ">=18",
|
|
34
34
|
"react-dom": ">=18"
|
|
35
35
|
},
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"prosemirror-view": "1.42.7"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@ecomcx/ecomweb-content": "^1.
|
|
48
|
+
"@ecomcx/ecomweb-content": "^1.22.0",
|
|
49
49
|
"@playwright/test": "1.53.0",
|
|
50
50
|
"@types/react": "19.2.2",
|
|
51
51
|
"@types/react-dom": "19.2.2",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Background image section of the Style tab (image, size, focal point, repeat, fixed, overlay). */
|
|
2
|
+
export const background = {
|
|
3
|
+
title: "Background image",
|
|
4
|
+
image: "Image",
|
|
5
|
+
choose: "Choose image",
|
|
6
|
+
replace: "Replace",
|
|
7
|
+
remove: "Remove",
|
|
8
|
+
url: "Image URL",
|
|
9
|
+
inherited: "Using the image of the larger screen. Choose another image to override it for this screen.",
|
|
10
|
+
size: "Fit",
|
|
11
|
+
cover: "Cover",
|
|
12
|
+
cover_help: "Fill the block, the image may be cropped",
|
|
13
|
+
contain: "Contain",
|
|
14
|
+
contain_help: "Show the whole image, may leave empty space",
|
|
15
|
+
auto: "Original",
|
|
16
|
+
auto_help: "Keep the image's original size",
|
|
17
|
+
focal: "Focal point",
|
|
18
|
+
repeat: "Repeat image",
|
|
19
|
+
fixed: "Fixed while scrolling (parallax, desktop only)",
|
|
20
|
+
overlay: "Overlay",
|
|
21
|
+
opacity: "Overlay strength",
|
|
22
|
+
};
|
|
@@ -20,7 +20,7 @@ export const blockDesc = {
|
|
|
20
20
|
file: "A downloadable file (PDF…), optionally embedded.",
|
|
21
21
|
youtube: "Embed a YouTube video.",
|
|
22
22
|
embed: "Embed content from a URL.",
|
|
23
|
-
group: "Gather blocks in a container to style them together.",
|
|
23
|
+
group: "Gather blocks in a container to style them together: background colour, gradient or background image (Styles), spacing, row / stack / grid layout.",
|
|
24
24
|
columns: "Display content in columns; drag to resize.",
|
|
25
25
|
buttons: "Prompt visitors to take action with buttons.",
|
|
26
26
|
spacer: "Add white space between blocks.",
|
|
@@ -52,4 +52,33 @@ export const blockDesc = {
|
|
|
52
52
|
templatePart: "A shared part (header, footer…) — edit once, update everywhere.",
|
|
53
53
|
form: "Basic contact / sign-up form: submissions are kept in the admin and emailed. Advanced forms: plugins.",
|
|
54
54
|
formField: "One field of a form: text, email, phone, message, choice, consent…",
|
|
55
|
+
column: "One column inside Columns; set its width, can have its own background or background image.",
|
|
56
|
+
button: "A linked button (primary / secondary / outline) inside Buttons.",
|
|
57
|
+
accordion: "Collapsible items (FAQ) — each item is a Details block.",
|
|
58
|
+
tabs: "Content split into tabs; click a tab name to switch.",
|
|
59
|
+
tab: "One tab inside Tabs: its title and content.",
|
|
60
|
+
carousel: "Sliding slides (images, cards, testimonials); choose how many show at once.",
|
|
61
|
+
shortcode: "Insert a plugin feature by its shortcode.",
|
|
62
|
+
countdown: "Countdown timer to a date (sale, event).",
|
|
63
|
+
rating: "Star rating (e.g. 4.5 / 5).",
|
|
64
|
+
icon: "Small icon (check, star, phone…) with size and colour.",
|
|
65
|
+
footnotes: "Numbered footnotes at the end of the post.",
|
|
66
|
+
pageBreak: "Split the post into several pages.",
|
|
67
|
+
readMore: "“Read more” link to the post (in post lists).",
|
|
68
|
+
commentsCount: "Number of comments on the post.",
|
|
69
|
+
avatar: "The post author’s avatar.",
|
|
70
|
+
queryTotal: "Total number of posts found by the list.",
|
|
71
|
+
loginout: "Log in / Log out link depending on the visitor.",
|
|
72
|
+
termList: "List of categories / tags (list or cloud).",
|
|
73
|
+
pageList: "The site’s pages, by level.",
|
|
74
|
+
archives: "Links to posts by month.",
|
|
75
|
+
postTemplate: "How each post looks inside a post list.",
|
|
76
|
+
pagination: "Previous / next and page numbers for a post list.",
|
|
77
|
+
queryEmpty: "Content shown when the post list is empty.",
|
|
78
|
+
syncedPattern: "Shared pattern — edit once, changes on every page using it.",
|
|
79
|
+
listItem: "One list item.",
|
|
80
|
+
taskItem: "One to-do with a checkbox.",
|
|
81
|
+
tableRow: "One table row.",
|
|
82
|
+
tableHeader: "Table header cell.",
|
|
83
|
+
tableCell: "One table cell.",
|
|
55
84
|
};
|
package/src/locales/en/index.ts
CHANGED
|
@@ -12,9 +12,10 @@ import { layout } from "./layout";
|
|
|
12
12
|
import { legacyBasic } from "./legacy-basic";
|
|
13
13
|
import { legacyDynamic } from "./legacy-dynamic";
|
|
14
14
|
import { motion } from "./motion";
|
|
15
|
+
import { background } from "./background";
|
|
15
16
|
import { patternLib } from "./pattern-lib";
|
|
16
17
|
import { patterns } from "./patterns";
|
|
17
18
|
import { shortcuts } from "./shortcuts";
|
|
18
19
|
|
|
19
20
|
/** Tiếng Anh: đủ khoá như vi/ (thiếu khoá là lỗi biên dịch) và là ngôn ngữ dự phòng của mọi ngôn ngữ khác. */
|
|
20
|
-
export const en: typeof vi = { v2, legacy, attrs, bindings, blockDesc, blockTitles, blocks, controls, hints, layout, legacyBasic, legacyDynamic, motion, patternLib, patterns, shortcuts };
|
|
21
|
+
export const en: typeof vi = { v2, legacy, attrs, background, bindings, blockDesc, blockTitles, blocks, controls, hints, layout, legacyBasic, legacyDynamic, motion, patternLib, patterns, shortcuts };
|
package/src/locales/en/v2.ts
CHANGED
|
@@ -5,6 +5,7 @@ export const v2 = {
|
|
|
5
5
|
typeSlash: "Type / to choose a block",
|
|
6
6
|
emptyDoc: "Start writing or type / to insert a block",
|
|
7
7
|
addBlock: "Add block",
|
|
8
|
+
addSection: "Add section",
|
|
8
9
|
search: "Search blocks",
|
|
9
10
|
noResults: "No blocks found",
|
|
10
11
|
blocks: "Blocks",
|
|
@@ -20,6 +21,10 @@ export const v2 = {
|
|
|
20
21
|
group: "Group",
|
|
21
22
|
ungroup: "Ungroup",
|
|
22
23
|
copy: "Copy",
|
|
24
|
+
copyStyle: "Copy style",
|
|
25
|
+
pasteStyle: "Paste style",
|
|
26
|
+
styleCopied: "Style copied",
|
|
27
|
+
blockMenu: "Block actions",
|
|
23
28
|
more: "More",
|
|
24
29
|
transform: "Transform",
|
|
25
30
|
bold: "Bold",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Mục Ảnh nền trong tab Kiểu dáng (ảnh, cách phủ, điểm lấy nét, lặp, cố định, lớp phủ). */
|
|
2
|
+
export const background = {
|
|
3
|
+
title: "Ảnh nền",
|
|
4
|
+
image: "Ảnh",
|
|
5
|
+
choose: "Chọn ảnh",
|
|
6
|
+
replace: "Đổi ảnh",
|
|
7
|
+
remove: "Bỏ ảnh",
|
|
8
|
+
url: "Đường dẫn ảnh",
|
|
9
|
+
inherited: "Đang dùng ảnh của khổ lớn hơn. Chọn ảnh khác để thay riêng cho khổ này.",
|
|
10
|
+
size: "Cách phủ",
|
|
11
|
+
cover: "Phủ kín",
|
|
12
|
+
cover_help: "Ảnh phủ kín khối, có thể bị cắt bớt",
|
|
13
|
+
contain: "Vừa khung",
|
|
14
|
+
contain_help: "Hiện trọn ảnh, có thể còn khoảng trống",
|
|
15
|
+
auto: "Gốc",
|
|
16
|
+
auto_help: "Giữ kích thước gốc của ảnh",
|
|
17
|
+
focal: "Điểm lấy nét",
|
|
18
|
+
repeat: "Lặp lại ảnh",
|
|
19
|
+
fixed: "Cố định khi cuộn (parallax, chỉ trên máy tính)",
|
|
20
|
+
overlay: "Lớp phủ",
|
|
21
|
+
opacity: "Độ đậm lớp phủ",
|
|
22
|
+
};
|
|
@@ -20,7 +20,7 @@ export const blockDesc = {
|
|
|
20
20
|
file: "Liên kết tải tệp (PDF…), có thể xem ngay trên trang.",
|
|
21
21
|
youtube: "Nhúng video YouTube.",
|
|
22
22
|
embed: "Nhúng nội dung từ địa chỉ (Facebook, TikTok, bản đồ…).",
|
|
23
|
-
group: "Gom nhiều khối vào một khung để tô nền, căn lề, bố cục
|
|
23
|
+
group: "Gom nhiều khối vào một khung để tô nền (màu, chuyển màu, ảnh nền trong Kiểu dáng), căn lề, bố cục hàng / cột / lưới.",
|
|
24
24
|
columns: "Chia nội dung thành nhiều cột, kéo để đổi độ rộng.",
|
|
25
25
|
buttons: "Một hoặc nhiều nút kêu gọi hành động.",
|
|
26
26
|
spacer: "Khoảng trống giữa các khối.",
|
|
@@ -52,4 +52,33 @@ export const blockDesc = {
|
|
|
52
52
|
templatePart: "Phần dùng chung (header, footer…) — sửa một nơi, đổi mọi trang.",
|
|
53
53
|
form: "Form liên hệ / đăng ký cơ bản: bài gửi lưu trong admin và báo qua email. Form nâng cao: plugin.",
|
|
54
54
|
formField: "Một ô của form: chữ, email, điện thoại, nội dung, chọn, đồng ý…",
|
|
55
|
+
column: "Một cột trong khối Cột; chỉnh độ rộng, có thể tô nền / ảnh nền riêng.",
|
|
56
|
+
button: "Một nút bấm có liên kết (chính / phụ / viền) — nằm trong khối Nút.",
|
|
57
|
+
accordion: "Nhiều mục gập / mở (câu hỏi thường gặp) — mỗi mục là khối Nội dung ẩn.",
|
|
58
|
+
tabs: "Nội dung chia thẻ, bấm tên thẻ để chuyển.",
|
|
59
|
+
tab: "Một thẻ trong khối Thẻ: tên thẻ và nội dung bên trong.",
|
|
60
|
+
carousel: "Trình chiếu nhiều trang trượt (ảnh, thẻ, lời chứng thực), chọn số trang hiện cùng lúc.",
|
|
61
|
+
shortcode: "Chèn tính năng của plugin bằng mã ngắn.",
|
|
62
|
+
countdown: "Đồng hồ đếm ngược tới một thời điểm (khuyến mãi, sự kiện).",
|
|
63
|
+
rating: "Số sao đánh giá (ví dụ 4,5 / 5).",
|
|
64
|
+
icon: "Biểu tượng nhỏ (dấu tích, sao, điện thoại…) đổi cỡ và màu.",
|
|
65
|
+
footnotes: "Danh sách chú thích cuối bài, tự đánh số.",
|
|
66
|
+
pageBreak: "Ngắt bài thành nhiều trang.",
|
|
67
|
+
readMore: "Liên kết “Đọc tiếp” tới bài (dùng trong danh sách bài).",
|
|
68
|
+
commentsCount: "Số bình luận của bài.",
|
|
69
|
+
avatar: "Ảnh đại diện của tác giả bài.",
|
|
70
|
+
queryTotal: "Tổng số bài tìm thấy của danh sách.",
|
|
71
|
+
loginout: "Liên kết Đăng nhập / Đăng xuất theo trạng thái người xem.",
|
|
72
|
+
termList: "Danh sách chuyên mục / thẻ (dạng danh sách hoặc đám mây).",
|
|
73
|
+
pageList: "Danh sách các trang của website, theo cấp.",
|
|
74
|
+
archives: "Liên kết lưu trữ bài theo tháng.",
|
|
75
|
+
postTemplate: "Khuôn hiển thị mỗi bài trong khối Danh sách bài.",
|
|
76
|
+
pagination: "Nút trang trước / sau và số trang của danh sách bài.",
|
|
77
|
+
queryEmpty: "Nội dung hiện khi danh sách bài không có bài nào.",
|
|
78
|
+
syncedPattern: "Mẫu dùng chung — sửa một nơi, đổi ở mọi trang dùng nó.",
|
|
79
|
+
listItem: "Một mục của danh sách.",
|
|
80
|
+
taskItem: "Một việc có ô đánh dấu trong danh sách việc.",
|
|
81
|
+
tableRow: "Một hàng của bảng.",
|
|
82
|
+
tableHeader: "Ô tiêu đề của bảng.",
|
|
83
|
+
tableCell: "Một ô của bảng.",
|
|
55
84
|
};
|
package/src/locales/vi/index.ts
CHANGED
|
@@ -17,8 +17,9 @@ import { layout } from "./layout";
|
|
|
17
17
|
import { legacyBasic } from "./legacy-basic";
|
|
18
18
|
import { legacyDynamic } from "./legacy-dynamic";
|
|
19
19
|
import { motion } from "./motion";
|
|
20
|
+
import { background } from "./background";
|
|
20
21
|
import { patternLib } from "./pattern-lib";
|
|
21
22
|
import { patterns } from "./patterns";
|
|
22
23
|
import { shortcuts } from "./shortcuts";
|
|
23
24
|
|
|
24
|
-
export const vi = { v2, legacy, attrs, bindings, blockDesc, blockTitles, blocks, controls, hints, layout, legacyBasic, legacyDynamic, motion, patternLib, patterns, shortcuts };
|
|
25
|
+
export const vi = { v2, legacy, attrs, background, bindings, blockDesc, blockTitles, blocks, controls, hints, layout, legacyBasic, legacyDynamic, motion, patternLib, patterns, shortcuts };
|
package/src/locales/vi/v2.ts
CHANGED
|
@@ -5,6 +5,7 @@ export const v2 = {
|
|
|
5
5
|
typeSlash: "Gõ / để chọn khối",
|
|
6
6
|
emptyDoc: "Bắt đầu viết hoặc gõ / để chèn khối",
|
|
7
7
|
addBlock: "Thêm khối",
|
|
8
|
+
addSection: "Thêm section",
|
|
8
9
|
search: "Tìm khối",
|
|
9
10
|
noResults: "Không tìm thấy khối",
|
|
10
11
|
blocks: "Khối",
|
|
@@ -20,6 +21,10 @@ export const v2 = {
|
|
|
20
21
|
group: "Gom vào nhóm",
|
|
21
22
|
ungroup: "Bỏ nhóm",
|
|
22
23
|
copy: "Sao chép",
|
|
24
|
+
copyStyle: "Chép kiểu dáng",
|
|
25
|
+
pasteStyle: "Dán kiểu dáng",
|
|
26
|
+
styleCopied: "Đã chép kiểu dáng",
|
|
27
|
+
blockMenu: "Thao tác với khối",
|
|
23
28
|
more: "Thêm",
|
|
24
29
|
transform: "Đổi loại khối",
|
|
25
30
|
bold: "Đậm",
|
package/src/shared/block-defs.ts
CHANGED
|
@@ -22,6 +22,11 @@ export interface RegisterBlockOptions {
|
|
|
22
22
|
translate?(text: string): string;
|
|
23
23
|
/** Khối của theme: chỉ chèn được khi soạn template / phần dùng chung (host.scope = "template"), không chèn vào bài viết. */
|
|
24
24
|
templateOnly?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Nhóm của tab Kiểu dáng khối hiện: "typography" "color" "background" "spacing" "border" "effects" "hover" "motion" "visibility".
|
|
27
|
+
* Không khai → khối chứa có đủ, khối khác có mọi nhóm trừ ảnh nền. [] = không có tab Kiểu dáng.
|
|
28
|
+
*/
|
|
29
|
+
styleGroups?: string[];
|
|
25
30
|
/** Khối chứa khối khác: nội dung có sẵn khi chèn (mặc định một đoạn văn trống). */
|
|
26
31
|
initialContent?(): Array<Record<string, unknown>>;
|
|
27
32
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Kho panel plugin (registerBlockPanel) — đăng ký ở đây, trình soạn đọc. */
|
|
2
2
|
import type { ComponentType } from "react";
|
|
3
|
+
import { defineBlockControls, type BlockControls, type ControlSpec } from "@ecomcx/ecomweb-content";
|
|
3
4
|
|
|
4
5
|
/** Props của panel plugin trong tab "Khối". */
|
|
5
6
|
export interface BlockPanelProps {
|
|
@@ -16,27 +17,84 @@ export interface BlockPanel {
|
|
|
16
17
|
id: string;
|
|
17
18
|
/** Tiêu đề mục trong tab "Khối" (nhận "%khoá%" — admin dịch theo plugin). */
|
|
18
19
|
title: string;
|
|
19
|
-
/** Loại khối áp dụng; bỏ trống = mọi khối. */
|
|
20
|
-
blocks?: string[];
|
|
20
|
+
/** Loại khối áp dụng; bỏ trống hoặc "*" = mọi khối. */
|
|
21
|
+
blocks?: string[] | "*";
|
|
22
|
+
/** Tab đặt panel: "block" (mặc định) hoặc "style" (tab Kiểu dáng). */
|
|
23
|
+
tab?: "block" | "style";
|
|
21
24
|
/** Thứ tự (nhỏ đứng trước, mặc định 10). */
|
|
22
25
|
order?: number;
|
|
23
26
|
/**
|
|
24
27
|
* Thuộc tính thêm vào khối (kể cả khối lõi), vd { lazy: { default: true } } — cần khai báo để trình soạn lưu được.
|
|
25
28
|
* Bắt buộc có `blocks` khi khai báo thuộc tính. Website đọc được qua filter "post.blocks" hoặc renderer của plugin.
|
|
26
29
|
*/
|
|
27
|
-
attributes?: Record<string, { default?: unknown }>;
|
|
28
|
-
|
|
30
|
+
attributes?: Record<string, { default?: unknown; label?: string } | (ControlSpec & { label?: string })>;
|
|
31
|
+
/** Giao diện riêng; bỏ trống = trình soạn tự vẽ ô cho các thuộc tính có `type`. */
|
|
32
|
+
component?: ComponentType<BlockPanelProps>;
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
|
|
32
36
|
const panels = new Map<string, BlockPanel>();
|
|
33
37
|
const listeners = new Set<() => void>();
|
|
34
38
|
let snapshot: BlockPanel[] = [];
|
|
35
|
-
const changed = () => {
|
|
36
|
-
|
|
39
|
+
const changed = () => {
|
|
40
|
+
snapshot = [...panels.values()].sort((a, b) => (a.order ?? 10) - (b.order ?? 10));
|
|
41
|
+
controls = snapshot.flatMap((p) => { const t = typed(p); return Object.keys(t).length ? [{ id: p.id, blocks: p.blocks ?? "*", attributes: t }] : []; });
|
|
42
|
+
listeners.forEach((l) => l());
|
|
43
|
+
};
|
|
44
|
+
/** Thuộc tính có `type` + `css` → ô điều khiển khai CSS (kiểm khai báo ngay lúc đăng ký: sai → ném lỗi). */
|
|
45
|
+
const typed = (p: BlockPanel) => Object.fromEntries(Object.entries(p.attributes ?? {}).filter(([, s]) => "type" in s && s.type)) as Record<string, ControlSpec>;
|
|
46
|
+
let controls: BlockControls[] = [];
|
|
47
|
+
export function registerBlockPanel(panel: BlockPanel) {
|
|
48
|
+
const t = typed(panel);
|
|
49
|
+
if (Object.keys(t).length) defineBlockControls({ id: panel.id, blocks: panel.blocks ?? "*", attributes: t });
|
|
50
|
+
panels.set(panel.id, panel); changed();
|
|
51
|
+
}
|
|
37
52
|
export function unregisterBlockPanel(id: string) { const had = panels.delete(id); if (had) changed(); return had; }
|
|
38
53
|
|
|
39
54
|
/** Panel áp dụng cho một loại khối. */
|
|
40
|
-
export const blockPanelsFor = (type: string) => snapshot.filter((p) =>
|
|
55
|
+
export const blockPanelsFor = (type: string, tab: "block" | "style" = "block") => snapshot.filter((p) => (p.blocks === undefined || p.blocks === "*" || p.blocks.includes(type)) && (p.tab ?? "block") === tab);
|
|
56
|
+
/** Ô điều khiển khai CSS của mọi panel (đầu vào của controlsCss — cùng hàm website dùng). */
|
|
57
|
+
export const blockControls = () => controls;
|
|
41
58
|
export const blockPanels = () => snapshot;
|
|
42
59
|
export function onBlockPanelsChange(l: () => void) { listeners.add(l); return () => { listeners.delete(l); }; }
|
|
60
|
+
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
// Hành động trên khối (registerBlockAction) — menu ⋮ của thanh công cụ khối
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
export interface BlockActionContext {
|
|
65
|
+
/** Các khối đang chọn (id, loại, thuộc tính). */
|
|
66
|
+
blocks: Array<{ id: string; type: string; attrs: Record<string, any> }>;
|
|
67
|
+
/** Đổi thuộc tính các khối đang chọn. */
|
|
68
|
+
setAttrs(attrs: Record<string, unknown>): void;
|
|
69
|
+
}
|
|
70
|
+
export interface BlockAction {
|
|
71
|
+
/** Mã duy nhất "slug-plugin/tên". */
|
|
72
|
+
id: string;
|
|
73
|
+
/** Nhãn trong menu (nhận "%khoá%"). */
|
|
74
|
+
label: string;
|
|
75
|
+
icon?: ComponentType<{ className?: string }>;
|
|
76
|
+
/** Loại khối áp dụng; bỏ trống / "*" = mọi khối. */
|
|
77
|
+
blocks?: string[] | "*";
|
|
78
|
+
run(ctx: BlockActionContext): void | Promise<void>;
|
|
79
|
+
}
|
|
80
|
+
const actions = new Map<string, BlockAction>();
|
|
81
|
+
let actionList: BlockAction[] = [];
|
|
82
|
+
export function registerBlockAction(a: BlockAction) { actions.set(a.id, a); actionList = [...actions.values()]; listeners.forEach((l) => l()); }
|
|
83
|
+
export function unregisterBlockAction(id: string) { const had = actions.delete(id); if (had) { actionList = [...actions.values()]; listeners.forEach((l) => l()); } return had; }
|
|
84
|
+
export const blockActionsFor = (types: string[]) => actionList.filter((a) => !a.blocks || a.blocks === "*" || types.every((t) => (a.blocks as string[]).includes(t)));
|
|
85
|
+
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
// Khối sẵn sàng (onBlockReady) + asset theo nhu cầu — khung soạn (iframe) đọc
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
export type BlockReadyFn = (el: HTMLElement, attrs: Record<string, unknown>) => void | (() => void);
|
|
90
|
+
export interface BlockAsset { kind: "script" | "style"; src: string; when: { blocks?: string[]; className?: string } }
|
|
91
|
+
let ready: Array<{ type: string; fn: BlockReadyFn }> = [];
|
|
92
|
+
let assets: BlockAsset[] = [];
|
|
93
|
+
export function onBlockReady(type: string, fn: BlockReadyFn) {
|
|
94
|
+
const e = { type, fn };
|
|
95
|
+
ready = [...ready, e]; listeners.forEach((l) => l());
|
|
96
|
+
return () => { ready = ready.filter((x) => x !== e); listeners.forEach((l) => l()); };
|
|
97
|
+
}
|
|
98
|
+
export function registerBlockAssets(list: BlockAsset[]) { assets = [...assets, ...list]; listeners.forEach((l) => l()); }
|
|
99
|
+
export const blockReadyFns = () => ready;
|
|
100
|
+
export const blockAssets = () => assets;
|
package/src/v2/blocks/compat.tsx
CHANGED
|
@@ -37,6 +37,7 @@ export function syncPluginBlocks(registry: BlockTypeRegistry): () => void {
|
|
|
37
37
|
description: def.description ? t(def.description) : undefined,
|
|
38
38
|
icon: o.icon ?? Blocks,
|
|
39
39
|
templateOnly: o.templateOnly,
|
|
40
|
+
...(o.styleGroups ? { supports: { style: o.styleGroups.length ? o.styleGroups : false } } : {}),
|
|
40
41
|
edit: o.edit ? wrapV1Edit(o.edit) : undefined,
|
|
41
42
|
// Không có xem trước riêng và không chứa khối con → website vẽ bằng renderer của theme/plugin (viết khối một lần)
|
|
42
43
|
serverRender: !o.edit && def.content !== "blocks",
|
package/src/v2/blocks/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { mediaBlocks } from "./media";
|
|
|
6
6
|
import { textBlocks } from "./text";
|
|
7
7
|
import { themeBlocks } from "./theme";
|
|
8
8
|
import { formBlocks } from "./form";
|
|
9
|
+
import { blockDescription } from "../ui/block-descriptions";
|
|
9
10
|
|
|
10
11
|
/** Tên khối theo ngôn ngữ giao diện (khối có nhãn trong bộ chữ). */
|
|
11
12
|
const TITLE_KEYS: Partial<Record<string, keyof V2Labels>> = {
|
|
@@ -23,7 +24,7 @@ export function coreBlockTypes(labels: V2Labels): BlockType[] {
|
|
|
23
24
|
const title = key ? String(labels[key]) : str(names[t.name]) ?? t.title;
|
|
24
25
|
// Biến thể đứng riêng (Hàng ngang / Xếp dọc / Lưới) theo ngôn ngữ
|
|
25
26
|
const variations = t.variations?.map((v) => { const vt = str(names[`${t.name}/${v.name}`]); return vt ? { ...v, title: vt } : v; });
|
|
26
|
-
return { ...t, title, variations };
|
|
27
|
+
return { ...t, title, variations, description: t.description ?? blockDescription(t.name, labels.lang) };
|
|
27
28
|
});
|
|
28
29
|
}
|
|
29
30
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { normalizeStyle, styleClass, widthClass } from "@ecomcx/ecomweb-content";
|
|
1
|
+
import { controlsCss, normalizeStyle, styleClass, widthClass } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { blockControls } from "../../shared/panel-store";
|
|
2
3
|
import { Component, memo, useCallback, useContext, useEffect, useMemo, useRef, type ErrorInfo, type MouseEvent, type ReactElement, type ReactNode } from "react";
|
|
3
4
|
import { DocScopeProvider, LoopPostContext, useDocScope, useEditor, useEditorState } from "../context";
|
|
4
5
|
import { ServerBlock } from "./server-block";
|
|
@@ -72,6 +73,7 @@ export function useBlockProps(block: BNode, state: { selected: boolean; editing:
|
|
|
72
73
|
state.editing && "is-editing",
|
|
73
74
|
state.mode === "disabled" && "is-locked",
|
|
74
75
|
style && styleClass(style),
|
|
76
|
+
controlsCss(blockControls(), block.type, a)?.cls,
|
|
75
77
|
widthClass(block.type, a),
|
|
76
78
|
typeof a.blockStyle === "string" && `ecx-is-${a.blockStyle}`,
|
|
77
79
|
typeof a.className === "string" && a.className,
|
package/src/v2/canvas/canvas.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { collectStyles, normalizeStyle, presetCss, type BlockStyle } from "@ecomcx/ecomweb-content";
|
|
1
|
+
import { collectStyles, controlsCss, normalizeStyle, presetCss, type BlockStyle } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { blockAssets, blockControls, blockReadyFns, onBlockPanelsChange } from "../../shared/panel-store";
|
|
2
3
|
import { createElement, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, type ReactNode } from "react";
|
|
3
4
|
import { onAnimationsChange, pluginAnimations } from "../../shared/animation-store";
|
|
4
5
|
import { createPortal } from "react-dom";
|
|
@@ -19,6 +20,7 @@ export type Device = "desktop" | "tablet" | "mobile";
|
|
|
19
20
|
export const DEVICE_WIDTH: Record<Device, number | null> = { desktop: null, tablet: 768, mobile: 390 };
|
|
20
21
|
|
|
21
22
|
export interface CanvasProps {
|
|
23
|
+
/** Bỏ trống = theo `ui.device` (khổ dùng chung với tab Kiểu dáng). */
|
|
22
24
|
device?: Device;
|
|
23
25
|
className?: string;
|
|
24
26
|
/** Class của vùng nội dung trong iframe (theme thường tạo kiểu .ecx-content / .entry-content). */
|
|
@@ -34,11 +36,11 @@ const SRC_DOC = `<!doctype html><html><head><meta charset="utf-8"><meta name="vi
|
|
|
34
36
|
/** Tỉ lệ của chế độ thu nhỏ. */
|
|
35
37
|
export const ZOOM_OUT = 0.5;
|
|
36
38
|
/** Khổ "Máy tính" luôn vẽ rộng ít nhất bằng này (> 1024 để CSS tablet của website không áp lên); chỗ hẹp hơn thì thu nhỏ vừa khung thay vì vẽ hẹp. */
|
|
37
|
-
export const DESKTOP_MIN_WIDTH =
|
|
39
|
+
export const DESKTOP_MIN_WIDTH = 1025;
|
|
38
40
|
/** Thu nhỏ dưới tỉ lệ này thì chữ quá nhỏ để đọc / gõ (máy thật là điện thoại, tablet dọc): vẽ đúng bề rộng khung, không thu. */
|
|
39
41
|
export const MIN_FIT = 0.6;
|
|
40
42
|
|
|
41
|
-
export function Canvas({ device
|
|
43
|
+
export function Canvas({ device: deviceProp, className, contentClassName = "ecx-content", before, after }: CanvasProps) {
|
|
42
44
|
const { ui, labels } = useEditor();
|
|
43
45
|
const frameRef = useRef<HTMLIFrameElement>(null);
|
|
44
46
|
const [doc, setDoc] = useState<Document | null>(null);
|
|
@@ -71,6 +73,8 @@ export function Canvas({ device = "desktop", className, contentClassName = "ecx-
|
|
|
71
73
|
useEffect(() => () => { if (ui.canvasFrame === frameRef.current) { ui.canvasFrame = null; ui.canvasDoc = null; } }, [ui]);
|
|
72
74
|
|
|
73
75
|
useUiTick();
|
|
76
|
+
// Không truyền device → theo khổ dùng chung của trình soạn (DeviceSwitcher, tab Kiểu dáng)
|
|
77
|
+
const device = deviceProp ?? ui.device;
|
|
74
78
|
const width = DEVICE_WIDTH[device];
|
|
75
79
|
// Thu nhỏ: khung soạn vẽ ở cỡ gấp đôi rồi thu còn một nửa → thấy cả trang, toạ độ kéo thả / thanh công cụ tự tính theo tỉ lệ
|
|
76
80
|
const ratio = !width && wrapW > 0 && wrapW < DESKTOP_MIN_WIDTH ? wrapW / DESKTOP_MIN_WIDTH : 1;
|
|
@@ -194,8 +198,12 @@ function useCanvasStyles(doc: Document) {
|
|
|
194
198
|
const docs = useEditorState((s) => s.docs);
|
|
195
199
|
// Kiểu dáng gom theo từng cây khối (cache theo tham chiếu): gõ chữ không đổi style → không duyệt lại cả tài liệu dài
|
|
196
200
|
const perTree = useRef(new WeakMap<BNode[], BlockStyle[]>());
|
|
201
|
+
const controls = useSyncExternalStore(onBlockPanelsChange, blockControls, blockControls);
|
|
197
202
|
const css = useMemo(() => {
|
|
198
203
|
const styles: BlockStyle[] = [];
|
|
204
|
+
// Ô điều khiển khai CSS của plugin — cùng hàm controlsCss website dùng
|
|
205
|
+
const ctrl = new Map<string, string>();
|
|
206
|
+
if (controls.length) for (const d of Object.values(docs)) for (const b of flatten(d.blocks)) { const c = controlsCss(controls, b.type, b.attrs); if (c) ctrl.set(c.cls, c.css); }
|
|
199
207
|
for (const d of Object.values(docs)) {
|
|
200
208
|
let list = perTree.current.get(d.blocks);
|
|
201
209
|
if (!list) {
|
|
@@ -205,8 +213,9 @@ function useCanvasStyles(doc: Document) {
|
|
|
205
213
|
}
|
|
206
214
|
styles.push(...list);
|
|
207
215
|
}
|
|
208
|
-
return collectStyles(styles);
|
|
209
|
-
}, [docs]);
|
|
216
|
+
return collectStyles(styles) + [...ctrl.values()].join("");
|
|
217
|
+
}, [docs, controls]);
|
|
218
|
+
usePluginRuntime(doc, docs);
|
|
210
219
|
void store;
|
|
211
220
|
useLayoutEffect(() => {
|
|
212
221
|
let el = head.querySelector<HTMLStyleElement>("style[data-ecx=blocks]");
|
|
@@ -224,7 +233,7 @@ function useCanvasStyles(doc: Document) {
|
|
|
224
233
|
|
|
225
234
|
/** Cuộn / đổi cỡ trong iframe → thanh công cụ đo lại vị trí. */
|
|
226
235
|
function useCanvasEvents(doc: Document) {
|
|
227
|
-
const { ui } = useEditor();
|
|
236
|
+
const { ui, store } = useEditor();
|
|
228
237
|
useEffect(() => {
|
|
229
238
|
const win = doc.defaultView!;
|
|
230
239
|
let raf = 0;
|
|
@@ -237,11 +246,28 @@ function useCanvasEvents(doc: Document) {
|
|
|
237
246
|
win.addEventListener("resize", bump);
|
|
238
247
|
const ro = new ResizeObserver(bump);
|
|
239
248
|
ro.observe(doc.body);
|
|
249
|
+
// 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
|
+
const menu = (e: MouseEvent) => {
|
|
251
|
+
const el = (e.target as Element | null)?.closest?.<HTMLElement>("[data-ecx-block]");
|
|
252
|
+
const id = el?.dataset.ecxBlock;
|
|
253
|
+
if (!id || !ui.canvasFrame || (e.shiftKey && e.button === 2) || store.modeOf(id) === "disabled") return;
|
|
254
|
+
e.preventDefault();
|
|
255
|
+
const sel = store.getState().selection;
|
|
256
|
+
const ids = sel.ids.includes(id) ? sel.ids : sel.editing === id ? [id] : null;
|
|
257
|
+
if (!ids) store.select([id], { editing: null });
|
|
258
|
+
const f = ui.canvasFrame.getBoundingClientRect();
|
|
259
|
+
const scale = f.width / (ui.canvasFrame.offsetWidth || f.width) || 1;
|
|
260
|
+
// Mở bằng bàn phím: không có toạ độ chuột → neo dưới góc trái của khối
|
|
261
|
+
const r = !e.clientX && !e.clientY ? ui.blockRect(id) : null;
|
|
262
|
+
ui.openContextMenu({ x: r ? r.left : f.left + e.clientX * scale, y: r ? r.top + Math.min(r.height, 24) : f.top + e.clientY * scale, ids: ids ?? [id] });
|
|
263
|
+
};
|
|
264
|
+
doc.addEventListener("contextmenu", menu);
|
|
240
265
|
return () => {
|
|
241
266
|
win.removeEventListener("scroll", bump); win.removeEventListener("resize", bump); ro.disconnect(); cancelAnimationFrame(raf);
|
|
242
267
|
doc.removeEventListener("mousemove", moved); document.removeEventListener("mousemove", moved);
|
|
268
|
+
doc.removeEventListener("contextmenu", menu);
|
|
243
269
|
};
|
|
244
|
-
}, [doc, ui]);
|
|
270
|
+
}, [doc, ui, store]);
|
|
245
271
|
}
|
|
246
272
|
|
|
247
273
|
/** Đang gõ chữ / ô nhập: phím thuộc về ô đó. */
|
|
@@ -447,3 +473,50 @@ function useRangeHighlight(doc: Document): boolean {
|
|
|
447
473
|
}, [range, revision, doc, store, ui]);
|
|
448
474
|
return !!range;
|
|
449
475
|
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* onBlockReady + asset theo nhu cầu của plugin trong khung soạn (iframe): gọi lại khi khối đổi thuộc tính (dọn bản cũ trước),
|
|
479
|
+
* dọn khi khối rời DOM; asset nạp một lần khi nội dung có khối / class khớp.
|
|
480
|
+
*/
|
|
481
|
+
function usePluginRuntime(doc: Document, docs: Record<string, { blocks: BNode[] }>) {
|
|
482
|
+
const ready = useSyncExternalStore(onBlockPanelsChange, blockReadyFns, blockReadyFns);
|
|
483
|
+
const assets = useSyncExternalStore(onBlockPanelsChange, blockAssets, blockAssets);
|
|
484
|
+
const live = useRef(new Map<HTMLElement, { attrs: unknown; cleanups: Array<void | (() => void)> }>());
|
|
485
|
+
useEffect(() => {
|
|
486
|
+
const byId = new Map<string, BNode>();
|
|
487
|
+
for (const d of Object.values(docs)) for (const b of flatten(d.blocks)) byId.set(b.id, b);
|
|
488
|
+
if (assets.length) {
|
|
489
|
+
const types = new Set([...byId.values()].map((b) => b.type));
|
|
490
|
+
const classes = [...byId.values()].flatMap((b) => (typeof b.attrs.className === "string" ? b.attrs.className.split(/\s+/) : []));
|
|
491
|
+
for (const a of assets) {
|
|
492
|
+
const hit = a.when.blocks?.some((t) => types.has(t)) || (!!a.when.className && classes.some((c) => c.startsWith(a.when.className!)));
|
|
493
|
+
if (!hit || doc.head.querySelector(`[data-ecx-asset="${CSS.escape(a.src)}"]`)) continue;
|
|
494
|
+
const el = a.kind === "style" ? Object.assign(doc.createElement("link"), { rel: "stylesheet", href: a.src }) : Object.assign(doc.createElement("script"), { src: a.src, async: true });
|
|
495
|
+
el.dataset.ecxAsset = a.src;
|
|
496
|
+
doc.head.append(el);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
const run = () => {
|
|
500
|
+
const seen = new Set<HTMLElement>();
|
|
501
|
+
if (ready.length) for (const el of doc.querySelectorAll<HTMLElement>("[data-ecx-block]")) {
|
|
502
|
+
const b = byId.get(el.dataset.ecxBlock!);
|
|
503
|
+
if (!b) continue;
|
|
504
|
+
const fns = ready.filter((r) => r.type === "*" || r.type === b.type);
|
|
505
|
+
if (!fns.length) continue;
|
|
506
|
+
seen.add(el);
|
|
507
|
+
const cur = live.current.get(el);
|
|
508
|
+
if (cur && cur.attrs === b.attrs) continue;
|
|
509
|
+
cur?.cleanups.forEach((c) => { try { c?.(); } catch { /* bỏ qua */ } });
|
|
510
|
+
live.current.set(el, { attrs: b.attrs, cleanups: fns.map((r) => { try { return r.fn(el, b.attrs); } catch (e) { console.warn("[ecomweb-editor] onBlockReady", b.type, e); } }) });
|
|
511
|
+
}
|
|
512
|
+
for (const [el, v] of live.current) if (!seen.has(el)) { v.cleanups.forEach((c) => { try { c?.(); } catch { /* bỏ qua */ } }); live.current.delete(el); }
|
|
513
|
+
};
|
|
514
|
+
run();
|
|
515
|
+
if (!ready.length) return;
|
|
516
|
+
// Khối vẽ lại / thêm / bỏ mà tài liệu không đổi tham chiếu (vd ServerBlock tải xong)
|
|
517
|
+
const mo = new MutationObserver(run);
|
|
518
|
+
mo.observe(doc.body, { childList: true, subtree: true });
|
|
519
|
+
return () => mo.disconnect();
|
|
520
|
+
}, [doc, docs, ready, assets]);
|
|
521
|
+
useEffect(() => () => { for (const v of live.current.values()) v.cleanups.forEach((c) => { try { c?.(); } catch { /* bỏ qua */ } }); live.current.clear(); }, []);
|
|
522
|
+
}
|
package/src/v2/canvas/dnd.ts
CHANGED
|
@@ -23,7 +23,15 @@ export function startDragNew(ctx: EditorContextValue, e: ReactPointerEvent, opti
|
|
|
23
23
|
begin(ctx, e, { ids: [], types: [option.type], create: () => option.create(), newType: option.type });
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
interface Source { ids: string[]; types: string[]; create?: () => BNode; newType?: string }
|
|
26
|
+
interface Source { ids: string[]; types: string[]; create?: () => BNode | BNode[]; newType?: string }
|
|
27
|
+
|
|
28
|
+
/** Kéo một mẫu (nhiều khối) từ thư viện vào khung soạn: thả = chèn cả mẫu, chọn khối đầu của mẫu. */
|
|
29
|
+
export function startDragBlocks(ctx: EditorContextValue, e: ReactPointerEvent, create: () => BNode[]) {
|
|
30
|
+
if (e.button !== 0) return;
|
|
31
|
+
const sample = create();
|
|
32
|
+
if (!sample.length) return;
|
|
33
|
+
begin(ctx, e, { ids: [], types: sample.map((n) => n.type), create, newType: sample[0].type });
|
|
34
|
+
}
|
|
27
35
|
|
|
28
36
|
function begin(ctx: EditorContextValue, e: ReactPointerEvent, src: Source) {
|
|
29
37
|
const { ui, store } = ctx;
|
|
@@ -68,7 +76,12 @@ function begin(ctx: EditorContextValue, e: ReactPointerEvent, src: Source) {
|
|
|
68
76
|
cleanup();
|
|
69
77
|
ui.setDrag(null);
|
|
70
78
|
if (!wasStarted || !target) return;
|
|
71
|
-
if (src.create)
|
|
79
|
+
if (src.create) {
|
|
80
|
+
const made = src.create();
|
|
81
|
+
const nodes = Array.isArray(made) ? made : [made];
|
|
82
|
+
store.insert(target.docId, target.parentId, target.index, nodes);
|
|
83
|
+
if (nodes.length > 1) store.select([nodes[0].id]);
|
|
84
|
+
}
|
|
72
85
|
else store.moveTo(src.ids, target.docId, target.parentId, target.index);
|
|
73
86
|
// Không để click sau khi thả chèn thêm khối (thư viện khối)
|
|
74
87
|
handle.addEventListener("click", (c) => { c.stopPropagation(); c.preventDefault(); }, { capture: true, once: true });
|
package/src/v2/context.tsx
CHANGED
|
@@ -32,6 +32,9 @@ export class EditorUi {
|
|
|
32
32
|
typing = false;
|
|
33
33
|
/** Thu nhỏ: cả trang trong tầm nhìn, chỉ chọn / sắp xếp các phần (khối cấp cao nhất). */
|
|
34
34
|
zoomOut = false;
|
|
35
|
+
/** Khổ màn hình đang soạn: khung soạn vẽ theo bề rộng này, tab Kiểu dáng sửa giá trị của khổ này (dùng chung, đổi một nơi thì nơi kia theo). */
|
|
36
|
+
device: "desktop" | "tablet" | "mobile" = "desktop";
|
|
37
|
+
setDevice(d: "desktop" | "tablet" | "mobile") { if (this.device !== d) { this.device = d; this.bump(); } }
|
|
35
38
|
/** Mở thư viện khối đầy đủ (cột trái) — nút "Xem tất cả" của chèn nhanh; ứng dụng / BlockEditor gán. */
|
|
36
39
|
browseAll: (() => void) | null = null;
|
|
37
40
|
setZoomOut(v: boolean) { if (this.zoomOut !== v) { this.zoomOut = v; this.bump(); } }
|
|
@@ -69,6 +72,9 @@ export class EditorUi {
|
|
|
69
72
|
/** Alt+F10: đưa bàn phím lên thanh công cụ của khối. */
|
|
70
73
|
focusToolbar() { document.querySelector<HTMLElement>(".ecx-toolbar button:not(:disabled)")?.focus(); }
|
|
71
74
|
setDrag(d: DragState | null) { this.drag = d; this.bump(); }
|
|
75
|
+
/** Menu chuột phải đang mở: vị trí theo toạ độ trang ngoài + các khối áp dụng. */
|
|
76
|
+
contextMenu: { x: number; y: number; ids: string[] } | null = null;
|
|
77
|
+
openContextMenu(m: { x: number; y: number; ids: string[] } | null) { if (m || this.contextMenu) { this.contextMenu = m; this.bump(); } }
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
export interface InserterRequest {
|
package/src/v2/core/registry.ts
CHANGED
|
@@ -96,7 +96,8 @@ export interface BlockType {
|
|
|
96
96
|
plain?: boolean;
|
|
97
97
|
/** Khối chữ: chữ gợi ý khi trống. */
|
|
98
98
|
placeholder?: string | ((labels: V2Labels) => string);
|
|
99
|
-
|
|
99
|
+
/** style: false = không có tab Kiểu dáng; mảng nhóm ("typography", "color", "background"…) = chỉ hiện các nhóm đó (xem ui/style-supports.ts). */
|
|
100
|
+
supports?: { style?: boolean | string[]; anchor?: boolean; className?: boolean; blockStyle?: boolean; align?: boolean };
|
|
100
101
|
/** Tóm tắt một dòng (cây khối, khung chung). */
|
|
101
102
|
summary?(attrs: Record<string, any>): string | undefined;
|
|
102
103
|
}
|
package/src/v2/editor.css
CHANGED
|
@@ -338,3 +338,24 @@ body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select:
|
|
|
338
338
|
.ecx-ai-note { margin: 0; font-size: 12px; color: var(--ecx-ed-muted, #667085); }
|
|
339
339
|
@keyframes ecx-ai-pulse { 50% { opacity: .45; } }
|
|
340
340
|
@media (prefers-reduced-motion: reduce) { .ecx-ai-wait { animation: none; } }
|
|
341
|
+
|
|
342
|
+
/* Ảnh nền (tab Kiểu dáng) */
|
|
343
|
+
.ecx-bg-image { display: grid; gap: 8px; }
|
|
344
|
+
.ecx-bg-thumb { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; border: 1px solid var(--ecx-ed-line); background: var(--ecx-ed-subtle); }
|
|
345
|
+
.ecx-bg-thumb.is-inherited { opacity: .55; }
|
|
346
|
+
.ecx-bg-actions { display: flex; gap: 6px; flex-wrap: wrap; }
|
|
347
|
+
.ecx-bg-focal { display: grid; grid-template-columns: repeat(3, 28px); gap: 4px; }
|
|
348
|
+
.ecx-bg-focal-dot { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--ecx-ed-line-strong); background: var(--ecx-ed-panel); cursor: pointer; position: relative; }
|
|
349
|
+
.ecx-bg-focal-dot::after { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--ecx-ed-line-strong); }
|
|
350
|
+
.ecx-bg-focal-dot:hover { background: var(--ecx-ed-hover); }
|
|
351
|
+
.ecx-bg-focal-dot.is-active { border-color: var(--ecx-ed-accent); background: var(--ecx-ed-accent-soft); }
|
|
352
|
+
.ecx-bg-focal-dot.is-active::after { background: var(--ecx-ed-accent); }
|
|
353
|
+
.ecx-bg-focal-dot:focus-visible { outline: 2px solid var(--ecx-ed-accent); outline-offset: 1px; }
|
|
354
|
+
|
|
355
|
+
/* Nút "+ Thêm section" giữa hai section cấp trên cùng */
|
|
356
|
+
.ecx-section-adder { position: fixed; z-index: 30; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 999px; border: 0; background: var(--ecx-ed-accent); color: var(--ecx-ed-accent-fg); box-shadow: var(--ecx-ed-shadow); cursor: pointer; }
|
|
357
|
+
.ecx-section-adder:hover { background: var(--ecx-ed-accent-hover); }
|
|
358
|
+
.ecx-section-adder:focus-visible { outline: 2px solid var(--ecx-ed-accent); outline-offset: 2px; }
|
|
359
|
+
.ecx-section-adder .ecx-icon { width: 16px; height: 16px; }
|
|
360
|
+
.ecx-inserter-popover .ecx-tabs { margin-bottom: 6px; }
|
|
361
|
+
.ecx-inserter-patterns { max-height: 320px; overflow-y: auto; }
|