@ecomcx/ecomweb-editor 1.25.1 → 1.25.3
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 +1 -1
- package/src/locales/en/block-titles.ts +15 -3
- package/src/locales/en/blocks.ts +5 -0
- package/src/locales/en/controls.ts +4 -0
- package/src/locales/en/hints.ts +45 -0
- package/src/locales/en/v2.ts +2 -0
- package/src/locales/vi/block-titles.ts +12 -0
- package/src/locales/vi/blocks.ts +5 -0
- package/src/locales/vi/controls.ts +4 -0
- package/src/locales/vi/hints.ts +45 -0
- package/src/locales/vi/v2.ts +2 -0
- package/src/shared/color-swatch.tsx +4 -2
- package/src/v2/blocks/compat.tsx +3 -1
- package/src/v2/blocks/media-actions.tsx +2 -1
- package/src/v2/blocks/media.tsx +35 -2
- package/src/v2/blocks/theme.tsx +48 -5
- package/src/v2/canvas/canvas-css.ts +8 -4
- package/src/v2/canvas/canvas.tsx +23 -4
- package/src/v2/canvas/dnd.ts +18 -0
- package/src/v2/core/host.ts +1 -1
- package/src/v2/core/media.ts +11 -0
- package/src/v2/core/store.ts +3 -3
- package/src/v2/core/structure.ts +3 -0
- package/src/v2/editor.css +4 -0
- package/src/v2/editor.tsx +1 -1
- package/src/v2/ui/attr-form.tsx +7 -3
- package/src/v2/ui/attr-hints.ts +22 -2
- package/src/v2/ui/color-field.tsx +7 -2
- package/src/v2/ui/inserter.tsx +40 -6
- package/src/v2/ui/list-view.tsx +7 -3
- package/src/v2/ui/style-tab.tsx +15 -5
- package/src/v2/ui/unit-controls.tsx +5 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecomcx/ecomweb-editor",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.3",
|
|
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": {
|
|
@@ -32,10 +32,22 @@ export const blockTitles = {
|
|
|
32
32
|
postAuthor: "Author",
|
|
33
33
|
postTerms: "Terms",
|
|
34
34
|
comments: "Comments",
|
|
35
|
-
queryTitle: "
|
|
36
|
-
termDescription: "
|
|
35
|
+
queryTitle: "Archive title",
|
|
36
|
+
termDescription: "Term description",
|
|
37
37
|
breadcrumbs: "Breadcrumb",
|
|
38
|
-
|
|
38
|
+
countdown: "Countdown",
|
|
39
|
+
rating: "Star rating",
|
|
40
|
+
readMore: "Read more",
|
|
41
|
+
commentsCount: "Comment count",
|
|
42
|
+
avatar: "Author avatar",
|
|
43
|
+
queryTotal: "Total posts",
|
|
44
|
+
termList: "Category / tag list",
|
|
45
|
+
loginout: "Log in / Log out",
|
|
46
|
+
footnotes: "Footnotes",
|
|
47
|
+
pageBreak: "Page break",
|
|
48
|
+
pageList: "Page list",
|
|
49
|
+
archives: "Monthly archives",
|
|
50
|
+
postNavigation: "Previous / next post",
|
|
39
51
|
query: "Query loop",
|
|
40
52
|
postTemplate: "Post template",
|
|
41
53
|
pagination: "Pagination",
|
package/src/locales/en/blocks.ts
CHANGED
|
@@ -18,9 +18,14 @@ export const blocks = {
|
|
|
18
18
|
down: "Down",
|
|
19
19
|
removeLink: "Remove link",
|
|
20
20
|
addLink: "Add link",
|
|
21
|
+
galleryImages: "Gallery images",
|
|
22
|
+
imageAltN: "Image {n} description",
|
|
23
|
+
removeImage: "Remove image",
|
|
24
|
+
addImages: "Add images",
|
|
21
25
|
contents: "Contents",
|
|
22
26
|
menu: "Menu",
|
|
23
27
|
noMenuIsAssigned: "No menu is assigned to this location — assign one in Appearance › Menus, or pick another location.",
|
|
28
|
+
searchLabel: "Search", searchPlaceholder: "Search the site…", searchButton: "Search",
|
|
24
29
|
categoryName: "Category name",
|
|
25
30
|
category: "Category: ",
|
|
26
31
|
theDescriptionOfThe: "The description of the category / tag being viewed.",
|
package/src/locales/en/hints.ts
CHANGED
|
@@ -139,4 +139,49 @@ export const hints = {
|
|
|
139
139
|
"imageSize.medium": "Medium",
|
|
140
140
|
"imageSize.large": "Large",
|
|
141
141
|
"imageSize.full": "Full size",
|
|
142
|
+
"gallery.linkTo.label": "Link images",
|
|
143
|
+
"gallery.linkTo.opt.none": "None",
|
|
144
|
+
"gallery.linkTo.opt.media": "Open full image",
|
|
145
|
+
"gallery.imageCrop.label": "Crop images to fit",
|
|
146
|
+
"gallery.lightbox.label": "Enlarge on click",
|
|
147
|
+
"countdown.expiredText.label": "Text when expired",
|
|
148
|
+
"navigation.overlayMenu.label": "Collapse into menu button",
|
|
149
|
+
"navigation.overlayMenu.opt.never": "Never",
|
|
150
|
+
"navigation.overlayMenu.opt.mobile": "Mobile",
|
|
151
|
+
"navigation.overlayMenu.opt.always": "Always",
|
|
152
|
+
"search.showLabel.label": "Show label",
|
|
153
|
+
"search.buttonPosition.label": "Button position",
|
|
154
|
+
"search.buttonPosition.opt.right": "Right",
|
|
155
|
+
"search.buttonPosition.opt.left": "Left",
|
|
156
|
+
"search.buttonPosition.opt.below": "Below",
|
|
157
|
+
"languageSwitcher.display.opt.inline": "Inline",
|
|
158
|
+
"languageSwitcher.display.opt.dropdown": "Dropdown",
|
|
159
|
+
"postAuthor.showName.label": "Show name",
|
|
160
|
+
"postAuthor.showBio.label": "Show bio",
|
|
161
|
+
"postAuthor.avatarSize.label": "Avatar size",
|
|
162
|
+
"comments.avatarSize.label": "Avatar size",
|
|
163
|
+
"comments.showDate.label": "Show date",
|
|
164
|
+
"comments.order.opt.asc": "Oldest first",
|
|
165
|
+
"comments.order.opt.desc": "Newest first",
|
|
166
|
+
"termList.showCount.label": "Show post count",
|
|
167
|
+
"termList.hideEmpty.label": "Hide empty",
|
|
168
|
+
"termList.hierarchical.label": "Show hierarchy",
|
|
169
|
+
"termList.display.opt.list": "List",
|
|
170
|
+
"termList.display.opt.cloud": "Tag cloud",
|
|
171
|
+
"loginout.loginText.label": "“Log in” text",
|
|
172
|
+
"loginout.logoutText.label": "“Log out” text",
|
|
173
|
+
"pageList.parentId.label": "Only children of (page ID)",
|
|
174
|
+
"archives.showCount.label": "Show post count",
|
|
175
|
+
"icon.name.opt.check": "Check",
|
|
176
|
+
"icon.name.opt.x": "X",
|
|
177
|
+
"icon.name.opt.star": "Star",
|
|
178
|
+
"icon.name.opt.heart": "Heart",
|
|
179
|
+
"icon.name.opt.arrowRight": "Arrow right",
|
|
180
|
+
"icon.name.opt.phone": "Phone",
|
|
181
|
+
"icon.name.opt.mail": "Mail",
|
|
182
|
+
"icon.name.opt.mapPin": "Map pin",
|
|
183
|
+
"icon.name.opt.clock": "Clock",
|
|
184
|
+
"icon.name.opt.info": "Info",
|
|
185
|
+
"icon.name.opt.alert": "Alert",
|
|
186
|
+
"icon.name.opt.externalLink": "External link",
|
|
142
187
|
};
|
package/src/locales/en/v2.ts
CHANGED
|
@@ -35,6 +35,18 @@ export const blockTitles = {
|
|
|
35
35
|
queryTitle: "Tiêu đề trang lưu trữ",
|
|
36
36
|
termDescription: "Mô tả chuyên mục",
|
|
37
37
|
breadcrumbs: "Breadcrumb",
|
|
38
|
+
countdown: "Đếm ngược",
|
|
39
|
+
rating: "Đánh giá sao",
|
|
40
|
+
readMore: "Đọc tiếp",
|
|
41
|
+
commentsCount: "Số bình luận",
|
|
42
|
+
avatar: "Ảnh đại diện tác giả",
|
|
43
|
+
queryTotal: "Tổng số bài",
|
|
44
|
+
termList: "Danh sách chuyên mục / thẻ",
|
|
45
|
+
loginout: "Đăng nhập / Đăng xuất",
|
|
46
|
+
footnotes: "Chú thích cuối bài",
|
|
47
|
+
pageBreak: "Ngắt trang",
|
|
48
|
+
pageList: "Danh sách trang",
|
|
49
|
+
archives: "Lưu trữ theo tháng",
|
|
38
50
|
postNavigation: "Bài trước / bài sau",
|
|
39
51
|
query: "Danh sách bài",
|
|
40
52
|
postTemplate: "Khuôn mỗi bài",
|
package/src/locales/vi/blocks.ts
CHANGED
|
@@ -18,9 +18,14 @@ export const blocks = {
|
|
|
18
18
|
down: "Xuống",
|
|
19
19
|
removeLink: "Xoá liên kết",
|
|
20
20
|
addLink: "Thêm liên kết",
|
|
21
|
+
galleryImages: "Ảnh trong gallery",
|
|
22
|
+
imageAltN: "Mô tả ảnh {n}",
|
|
23
|
+
removeImage: "Xoá ảnh",
|
|
24
|
+
addImages: "Thêm ảnh",
|
|
21
25
|
contents: "Mục lục",
|
|
22
26
|
menu: "Menu",
|
|
23
27
|
noMenuIsAssigned: "Chưa có menu nào gán cho vị trí này — gán ở Giao diện › Menu, hoặc chọn vị trí khác trong bảng cài đặt.",
|
|
28
|
+
searchLabel: "Tìm kiếm", searchPlaceholder: "Tìm trên website…", searchButton: "Tìm",
|
|
24
29
|
categoryName: "Tên chuyên mục",
|
|
25
30
|
category: "Chuyên mục: ",
|
|
26
31
|
theDescriptionOfThe: "Mô tả của chuyên mục / thẻ đang xem.",
|
package/src/locales/vi/hints.ts
CHANGED
|
@@ -139,4 +139,49 @@ export const hints = {
|
|
|
139
139
|
"imageSize.medium": "Vừa",
|
|
140
140
|
"imageSize.large": "Lớn",
|
|
141
141
|
"imageSize.full": "Gốc",
|
|
142
|
+
"gallery.linkTo.label": "Liên kết ảnh",
|
|
143
|
+
"gallery.linkTo.opt.none": "Không",
|
|
144
|
+
"gallery.linkTo.opt.media": "Mở ảnh gốc",
|
|
145
|
+
"gallery.imageCrop.label": "Cắt ảnh cho đều khung",
|
|
146
|
+
"gallery.lightbox.label": "Phóng to khi bấm",
|
|
147
|
+
"countdown.expiredText.label": "Chữ khi hết giờ",
|
|
148
|
+
"navigation.overlayMenu.label": "Thu gọn thành nút menu",
|
|
149
|
+
"navigation.overlayMenu.opt.never": "Không",
|
|
150
|
+
"navigation.overlayMenu.opt.mobile": "Điện thoại",
|
|
151
|
+
"navigation.overlayMenu.opt.always": "Luôn luôn",
|
|
152
|
+
"search.showLabel.label": "Hiện nhãn",
|
|
153
|
+
"search.buttonPosition.label": "Vị trí nút",
|
|
154
|
+
"search.buttonPosition.opt.right": "Phải",
|
|
155
|
+
"search.buttonPosition.opt.left": "Trái",
|
|
156
|
+
"search.buttonPosition.opt.below": "Bên dưới",
|
|
157
|
+
"languageSwitcher.display.opt.inline": "Dàn hàng",
|
|
158
|
+
"languageSwitcher.display.opt.dropdown": "Danh sách xổ xuống",
|
|
159
|
+
"postAuthor.showName.label": "Hiện tên",
|
|
160
|
+
"postAuthor.showBio.label": "Hiện giới thiệu",
|
|
161
|
+
"postAuthor.avatarSize.label": "Cỡ ảnh đại diện",
|
|
162
|
+
"comments.avatarSize.label": "Cỡ ảnh đại diện",
|
|
163
|
+
"comments.showDate.label": "Hiện ngày",
|
|
164
|
+
"comments.order.opt.asc": "Cũ trước",
|
|
165
|
+
"comments.order.opt.desc": "Mới trước",
|
|
166
|
+
"termList.showCount.label": "Hiện số bài",
|
|
167
|
+
"termList.hideEmpty.label": "Ẩn mục trống",
|
|
168
|
+
"termList.hierarchical.label": "Hiện theo cấp",
|
|
169
|
+
"termList.display.opt.list": "Danh sách",
|
|
170
|
+
"termList.display.opt.cloud": "Đám mây thẻ",
|
|
171
|
+
"loginout.loginText.label": "Chữ “Đăng nhập”",
|
|
172
|
+
"loginout.logoutText.label": "Chữ “Đăng xuất”",
|
|
173
|
+
"pageList.parentId.label": "Chỉ trang con của (mã trang)",
|
|
174
|
+
"archives.showCount.label": "Hiện số bài",
|
|
175
|
+
"icon.name.opt.check": "Dấu tick",
|
|
176
|
+
"icon.name.opt.x": "Dấu X",
|
|
177
|
+
"icon.name.opt.star": "Ngôi sao",
|
|
178
|
+
"icon.name.opt.heart": "Trái tim",
|
|
179
|
+
"icon.name.opt.arrowRight": "Mũi tên phải",
|
|
180
|
+
"icon.name.opt.phone": "Điện thoại",
|
|
181
|
+
"icon.name.opt.mail": "Thư",
|
|
182
|
+
"icon.name.opt.mapPin": "Ghim bản đồ",
|
|
183
|
+
"icon.name.opt.clock": "Đồng hồ",
|
|
184
|
+
"icon.name.opt.info": "Thông tin",
|
|
185
|
+
"icon.name.opt.alert": "Cảnh báo",
|
|
186
|
+
"icon.name.opt.externalLink": "Liên kết ngoài",
|
|
142
187
|
};
|
package/src/locales/vi/v2.ts
CHANGED
|
@@ -9,9 +9,11 @@ const EMPTY: CSSProperties = { background: "linear-gradient(to top right, transp
|
|
|
9
9
|
*/
|
|
10
10
|
export function ColorSwatchInput({ value, onChange, label, className, size = 26 }: { value?: string; onChange(hex: string): void; label: string; className?: string; size?: number }) {
|
|
11
11
|
const hex = value && /^#[0-9a-f]{6}$/i.test(value) ? value : undefined;
|
|
12
|
+
// rgb()/hsl()/tên màu hợp lệ cũng hiện đúng màu (bảng chọn của trình duyệt vẫn chỉ nhận #rrggbb nên ô input giữ `hex`)
|
|
13
|
+
const shown = hex ?? (value && typeof CSS !== "undefined" && CSS.supports?.("color", value) ? value : undefined);
|
|
12
14
|
return (
|
|
13
|
-
<label className={className} title={
|
|
14
|
-
style={{ position: "relative", display: "inline-block", width: size, height: size, flex: "none", borderRadius: 6, border: "1px solid rgb(0 0 0 / .18)", cursor: "pointer", overflow: "hidden", ...(
|
|
15
|
+
<label className={className} title={shown ?? label} data-empty={shown ? undefined : ""}
|
|
16
|
+
style={{ position: "relative", display: "inline-block", width: size, height: size, flex: "none", borderRadius: 6, border: "1px solid rgb(0 0 0 / .18)", cursor: "pointer", overflow: "hidden", ...(shown ? { background: shown } : EMPTY) }}>
|
|
15
17
|
<input type="color" aria-label={label} value={hex ?? "#ffffff"} onChange={(e) => onChange(e.target.value)}
|
|
16
18
|
style={{ position: "absolute", inset: 0, width: "100%", height: "100%", opacity: 0, cursor: "pointer", border: 0, padding: 0 }} />
|
|
17
19
|
</label>
|
package/src/v2/blocks/compat.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { blockDefaults } from "@ecomcx/ecomweb-content";
|
|
1
2
|
import { Blocks } from "lucide-react";
|
|
2
3
|
import type { ComponentType } from "react";
|
|
3
4
|
import { blockOptions, onBlockDefinitionsChange, registeredBlocks, type BlockEditProps as V1EditProps } from "../../shared/block-defs";
|
|
@@ -40,7 +41,8 @@ export function syncPluginBlocks(registry: BlockTypeRegistry): () => void {
|
|
|
40
41
|
// 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)
|
|
41
42
|
serverRender: !o.edit && def.content !== "blocks",
|
|
42
43
|
create: (attrs) => {
|
|
43
|
-
|
|
44
|
+
// blockDefaults kèm "_v" = phiên bản khối: thiếu nó website coi dữ liệu mới là bản 1 rồi chạy migrate lên dữ liệu đã ở bản mới
|
|
45
|
+
const defaults = blockDefaults(def);
|
|
44
46
|
const content = def.content === "blocks" ? (o.initialContent?.() ?? [{ type: "paragraph" }]).map((n) => fromRich(n as never)) : undefined;
|
|
45
47
|
return makeBlock(def.name, { ...defaults, ...attrs }, content);
|
|
46
48
|
},
|
|
@@ -3,6 +3,7 @@ import { Link2, Upload } from "lucide-react";
|
|
|
3
3
|
import { useRef, useState, type DragEvent, type ReactNode } from "react";
|
|
4
4
|
import type { MediaItem, MediaKind } from "../../shared/types";
|
|
5
5
|
import { useEditor } from "../context";
|
|
6
|
+
import { mediaSrcsets } from "../core/media";
|
|
6
7
|
|
|
7
8
|
const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
|
|
8
9
|
const ACCEPT: Record<MediaKind, string> = { image: "image/*", gallery: "image/*", video: "video/*", audio: "audio/*", file: "" };
|
|
@@ -11,7 +12,7 @@ const ACCEPT: Record<MediaKind, string> = { image: "image/*", gallery: "image/*"
|
|
|
11
12
|
export function mediaAttrs(kind: MediaKind, items: MediaItem[]): Record<string, unknown> {
|
|
12
13
|
if (kind === "gallery") return { images: items.map((m) => ({ src: m.url, alt: m.alt, width: m.width ?? undefined, height: m.height ?? undefined, id: m.id })) };
|
|
13
14
|
const m = items[0];
|
|
14
|
-
return { src: m.url, alt: kind === "image" ? m.alt || undefined : undefined, name: kind !== "image" ? m.fileName : undefined, mime: m.mimeType, mediaId: m.id, width: kind === "image" ? m.width ?? undefined : undefined, height: kind === "image" ? m.height ?? undefined : undefined };
|
|
15
|
+
return { src: m.url, alt: kind === "image" ? m.alt || undefined : undefined, name: kind !== "image" ? m.fileName : undefined, mime: m.mimeType, mediaId: m.id, ...(kind === "image" ? mediaSrcsets(m) : {}), width: kind === "image" ? m.width ?? undefined : undefined, height: kind === "image" ? m.height ?? undefined : undefined };
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
/**
|
package/src/v2/blocks/media.tsx
CHANGED
|
@@ -81,8 +81,8 @@ function FileEdit({ block, blockProps }: BlockEditProps) {
|
|
|
81
81
|
function YoutubeEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
|
|
82
82
|
const m = String(block.attrs.src ?? "").match(/(?:v=|youtu\.be\/|embed\/)([\w-]{11})/);
|
|
83
83
|
const [draft, setDraft] = useState("");
|
|
84
|
+
const t = useMsgs("blocks"); // hook phải gọi trước mọi return sớm (đổi số hook khi dán link → React #300)
|
|
84
85
|
if (!m) {
|
|
85
|
-
const t = useMsgs("blocks");
|
|
86
86
|
return (
|
|
87
87
|
<div {...blockProps} className={cx(blockProps.className, "ecx-media-placeholder")}>
|
|
88
88
|
<span className="ecx-placeholder-title"><Play className="ecx-icon" />YouTube</span>
|
|
@@ -196,6 +196,39 @@ function SocialInspector({ attrs, setAttrs, labels }: BlockEditProps) {
|
|
|
196
196
|
);
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
+
/** Danh sách ảnh của gallery trong bảng cài đặt: thêm (nhiều ảnh), mô tả (alt) từng ảnh, đổi thứ tự, xoá. */
|
|
200
|
+
function GalleryInspector({ attrs, setAttrs }: BlockEditProps) {
|
|
201
|
+
const t = useMsgs("blocks");
|
|
202
|
+
const { host } = useEditor();
|
|
203
|
+
type Img = { src: string; alt?: string; width?: number; height?: number; id?: number | string };
|
|
204
|
+
const images = (Array.isArray(attrs.images) ? attrs.images : []) as Img[];
|
|
205
|
+
const save = (next: Img[]) => setAttrs({ images: next });
|
|
206
|
+
const patch = (i: number, p: Partial<Img>) => save(images.map((im, k) => (k === i ? { ...im, ...p } : im)));
|
|
207
|
+
const move = (i: number, d: -1 | 1) => { const n = [...images]; [n[i], n[i + d]] = [n[i + d], n[i]]; save(n); };
|
|
208
|
+
const add = async () => {
|
|
209
|
+
if (!host.media) return;
|
|
210
|
+
const items = await host.media.pick({ kind: "image", multiple: true });
|
|
211
|
+
if (items.length) save([...images, ...((mediaAttrs("gallery", items).images ?? []) as Img[])]);
|
|
212
|
+
};
|
|
213
|
+
return (
|
|
214
|
+
<div className="ecx-gallery-editor" role="group" aria-label={t.galleryImages}>
|
|
215
|
+
<span className="ecx-field-label">{t.galleryImages}</span>
|
|
216
|
+
{images.map((im, i) => (
|
|
217
|
+
<div key={`${i}-${im.src}`} className="ecx-social-row" data-gallery-row={i}>
|
|
218
|
+
<img src={isSafeUrl(im.src) ? im.src : ""} alt="" width={36} height={36} style={{ objectFit: "cover", borderRadius: 4, flex: "none" }} />
|
|
219
|
+
<input className="ecx-input" type="text" aria-label={format(t.imageAltN, { n: i + 1 })} placeholder={t.imageAltN.replace("{n}", String(i + 1))} value={im.alt ?? ""} onChange={(e) => patch(i, { alt: e.target.value })} />
|
|
220
|
+
<span className="ecx-social-row-tools">
|
|
221
|
+
<button type="button" className="ecx-tool" aria-label={t.up} disabled={i === 0} onClick={() => move(i, -1)}><ArrowUp className="ecx-icon ecx-icon-sm" /></button>
|
|
222
|
+
<button type="button" className="ecx-tool" aria-label={t.down} disabled={i === images.length - 1} onClick={() => move(i, 1)}><ArrowDown className="ecx-icon ecx-icon-sm" /></button>
|
|
223
|
+
<button type="button" className="ecx-tool" aria-label={t.removeImage} onClick={() => save(images.filter((_, k) => k !== i))}><X className="ecx-icon ecx-icon-sm" /></button>
|
|
224
|
+
</span>
|
|
225
|
+
</div>
|
|
226
|
+
))}
|
|
227
|
+
{host.media && <button type="button" className="ecx-btn" onClick={add}><Plus className="ecx-icon ecx-icon-sm" /> {t.addImages}</button>}
|
|
228
|
+
</div>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
199
232
|
function TocEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
200
233
|
const t = useMsgs("blocks");
|
|
201
234
|
return (
|
|
@@ -227,7 +260,7 @@ export function mediaBlocks(): BlockType[] {
|
|
|
227
260
|
attributes: { ...media, alt: { type: "string", control: "textarea" }, title: { type: "string" }, width: { type: "number" }, height: { type: "number" }, size: { type: "string", default: "large" }, align: { type: "string", enum: ["left", "right", "center", "wide", "full"] }, href: { type: "url" }, linkTarget: { type: "string", enum: ["_self", "_blank"] }, lightbox: { type: "boolean", default: false } },
|
|
228
261
|
supports: { style: true, anchor: true, className: true, blockStyle: true }, summary: (a) => a.alt || a.src,
|
|
229
262
|
},
|
|
230
|
-
{ name: "gallery", title: "Gallery", icon: Images, category: "media", keywords: "gallery bo suu tap nhieu anh album", kind: "atom", edit: GalleryEdit, attributes: { images: { type: "json", default: [] }, columns: { type: "integer", default: 3, min: 1, max: 6 }, caption: { type: "string" }, linkTo: { type: "string", enum: ["none", "media"], default: "media" }, imageCrop: { type: "boolean", default: true }, lightbox: { type: "boolean", default: false } }, supports: { style: true, anchor: true, className: true } },
|
|
263
|
+
{ name: "gallery", title: "Gallery", icon: Images, category: "media", keywords: "gallery bo suu tap nhieu anh album", kind: "atom", edit: GalleryEdit, inspector: GalleryInspector, attributes: { images: { type: "json", default: [] }, columns: { type: "integer", default: 3, min: 1, max: 6 }, caption: { type: "string" }, linkTo: { type: "string", enum: ["none", "media"], default: "media" }, imageCrop: { type: "boolean", default: true }, lightbox: { type: "boolean", default: false } }, supports: { style: true, anchor: true, className: true } },
|
|
231
264
|
{ name: "video", title: "Video", icon: Video, category: "media", keywords: "video mp4 phim", kind: "atom", edit: VideoEdit, attributes: { ...media, name: { type: "string" }, mime: { type: "string" }, poster: { type: "url", control: "media" }, autoplay: { type: "boolean", default: false }, loop: { type: "boolean", default: false }, muted: { type: "boolean", default: false }, controls: { type: "boolean", default: true }, playsInline: { type: "boolean", default: true }, preload: { type: "string", enum: ["none", "metadata", "auto"], default: "metadata" } }, supports: { style: true, anchor: true } },
|
|
232
265
|
{ name: "audio", title: "Âm thanh", icon: Music, category: "media", keywords: "am thanh audio nhac mp3 podcast", kind: "atom", edit: AudioEdit, attributes: { ...media, name: { type: "string" }, mime: { type: "string" }, autoplay: { type: "boolean", default: false }, loop: { type: "boolean", default: false }, preload: { type: "string", enum: ["none", "metadata", "auto"], default: "metadata" } }, supports: { style: true, anchor: true } },
|
|
233
266
|
{ name: "file", title: "Tệp", icon: FileIcon, category: "media", keywords: "tep file pdf tai xuong download tai lieu", kind: "atom", edit: FileEdit, attributes: { ...media, name: { type: "string" }, mime: { type: "string" }, size: { type: "number" }, embed: { type: "boolean", default: true }, download: { type: "boolean" } }, supports: { style: true, anchor: true } },
|
package/src/v2/blocks/theme.tsx
CHANGED
|
@@ -66,10 +66,20 @@ function NavigationEdit({ block, blockProps, selected }: BlockEditProps) {
|
|
|
66
66
|
</div>
|
|
67
67
|
);
|
|
68
68
|
}
|
|
69
|
+
/** Giống hệt website (SearchFormClient trong theme-sdk): cùng class `search-form` / `search-button-*`, nhãn, vị trí nút — để CSS của theme và các thuộc tính "Hiện nhãn", "Vị trí nút" thấy ngay trong khung soạn. */
|
|
69
70
|
function SearchEdit({ block, blockProps }: BlockEditProps) {
|
|
71
|
+
const t = useMsgs("blocks");
|
|
72
|
+
const pos = String(block.attrs.buttonPosition ?? "right");
|
|
73
|
+
const button = <button type="button" tabIndex={-1}>{String(block.attrs.buttonText || t.searchButton)}</button>;
|
|
70
74
|
return (
|
|
71
75
|
<div {...merge(blockProps, "ecx-search")}>
|
|
72
|
-
<form onSubmit={(e) => e.preventDefault()}
|
|
76
|
+
<form role="search" onSubmit={(e) => e.preventDefault()} style={pos === "below" ? { display: "flex", flexDirection: "column", gap: 8 } : undefined}
|
|
77
|
+
className={`search-form${pos !== "right" ? ` search-button-${pos}` : ""}`}>
|
|
78
|
+
{block.attrs.showLabel === true && <label className="search-label">{t.searchLabel}</label>}
|
|
79
|
+
{pos === "left" && button}
|
|
80
|
+
<input type="search" placeholder={String(block.attrs.placeholder || t.searchPlaceholder)} aria-label={t.searchLabel} readOnly tabIndex={-1} />
|
|
81
|
+
{pos !== "left" && button}
|
|
82
|
+
</form>
|
|
73
83
|
</div>
|
|
74
84
|
);
|
|
75
85
|
}
|
|
@@ -111,7 +121,10 @@ function PostAuthorEdit({ blockProps }: BlockEditProps) {
|
|
|
111
121
|
}
|
|
112
122
|
function PostTermsEdit({ block, blockProps }: BlockEditProps) {
|
|
113
123
|
const d = useDynamic();
|
|
114
|
-
|
|
124
|
+
const names = d.post?.terms?.length ? d.post.terms : block.attrs.taxonomy === "post_tag" ? ["Thẻ A", "Thẻ B"] : ["Chuyên mục A", "Chuyên mục B"];
|
|
125
|
+
const sep = String(block.attrs.separator ?? ", ");
|
|
126
|
+
// website dựng mỗi mục là <a rel="tag"> (TermLinks) → canvas cũng là liên kết để ăn đúng kiểu liên kết của theme
|
|
127
|
+
return <p {...merge(blockProps, "ecx-post-terms")}>{names.map((n, i) => <span key={i}>{i > 0 && sep}<a href="#" rel="tag" onClick={(e) => e.preventDefault()}>{n}</a></span>)}</p>;
|
|
115
128
|
}
|
|
116
129
|
function ReadMoreEdit({ block, blockProps }: BlockEditProps) {
|
|
117
130
|
return <p {...merge(blockProps, "ecx-read-more", align(block.attrs))}><a href="#" onClick={(e) => e.preventDefault()}>{String(block.attrs.text || "Đọc tiếp")}</a></p>;
|
|
@@ -154,9 +167,35 @@ function PageListEdit({ blockProps }: BlockEditProps) {
|
|
|
154
167
|
function ArchivesEdit({ block, blockProps }: BlockEditProps) {
|
|
155
168
|
return <ul {...merge(blockProps, "ecx-archives")}>{["11/2026", "10/2026"].map((m, i) => <li key={m}>{m}{block.attrs.showCount === false ? "" : ` (${4 - i})`}</li>)}</ul>;
|
|
156
169
|
}
|
|
157
|
-
|
|
170
|
+
/** Cùng markup / class với khu bình luận của website (theme-sdk Comments) → CSS của theme tô canvas như website: 1 bình luận mẫu + form. */
|
|
171
|
+
function CommentsEdit({ block, blockProps }: BlockEditProps) {
|
|
158
172
|
const d = useDynamic();
|
|
159
|
-
|
|
173
|
+
const size = Math.min(128, Math.max(16, Number(block.attrs.avatarSize) || 40));
|
|
174
|
+
const field = { readOnly: true, tabIndex: -1 } as const;
|
|
175
|
+
return (
|
|
176
|
+
<section {...merge(blockProps, "comments-area")}>
|
|
177
|
+
<h2 className="comments-title">{String(block.attrs.title || "Bình luận")} ({d.post?.comments ?? 0})</h2>
|
|
178
|
+
<ol className="comment-list">
|
|
179
|
+
<li className="comment">
|
|
180
|
+
<article>
|
|
181
|
+
<header className="comment-meta">
|
|
182
|
+
<span className="comment-avatar avatar" style={{ display: "inline-block", width: size, height: size, borderRadius: "50%", background: "rgba(127,127,127,.3)", verticalAlign: "middle" }} />
|
|
183
|
+
<b className="comment-author">Người đọc</b>
|
|
184
|
+
{block.attrs.showDate === false ? null : <>{" · "}<time>01/11/2026</time></>}
|
|
185
|
+
</header>
|
|
186
|
+
<div className="comment-content"><p>Bình luận mẫu — website hiện bình luận thật của bài.</p></div>
|
|
187
|
+
</article>
|
|
188
|
+
</li>
|
|
189
|
+
</ol>
|
|
190
|
+
<form className="comment-form" onSubmit={(e) => e.preventDefault()}>
|
|
191
|
+
<h3>Để lại bình luận</h3>
|
|
192
|
+
<p><label>Bình luận *<textarea rows={5} {...field} /></label></p>
|
|
193
|
+
<p className="comment-form-row"><label>Tên *<input {...field} /></label><label>Email *<input type="email" {...field} /></label></p>
|
|
194
|
+
<p><label>Website<input type="url" {...field} /></label></p>
|
|
195
|
+
<p><button type="button" tabIndex={-1}>Gửi bình luận</button></p>
|
|
196
|
+
</form>
|
|
197
|
+
</section>
|
|
198
|
+
);
|
|
160
199
|
}
|
|
161
200
|
/** Tiêu đề trang lưu trữ / tìm kiếm (H1 của trang chuyên mục, thẻ, tác giả…). */
|
|
162
201
|
function QueryTitleEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
@@ -175,7 +214,11 @@ function BreadcrumbsEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
|
175
214
|
const d = useDynamic();
|
|
176
215
|
const t = useMsgs("blocks");
|
|
177
216
|
const sep = String(block.attrs.separator ?? "›");
|
|
178
|
-
|
|
217
|
+
// Như website: giữa = chuyên mục đầu tiên của bài (trang không có thì bỏ), cuối = tiêu đề bài / trang lưu trữ. Chưa có mẫu → chữ giữ chỗ.
|
|
218
|
+
// Host cũ chưa gửi `category` → term đầu tiên (thường là chuyên mục)
|
|
219
|
+
const middle = d.post ? ("category" in d.post ? d.post.category : d.post.terms?.[0]) : d.archive ? undefined : t.category2;
|
|
220
|
+
const current = d.post?.title || d.archive?.title || t.currentPage;
|
|
221
|
+
const items = [...(block.attrs.showHome !== false ? [t.home] : []), ...(middle ? [middle] : []), ...(block.attrs.showCurrent !== false ? [current] : [])];
|
|
179
222
|
return (
|
|
180
223
|
<nav {...(merge(blockProps, "ecx-breadcrumbs") as object)}>
|
|
181
224
|
<ol>{items.map((t, i) => <li key={i}>{i > 0 && <span className="ecx-breadcrumbs-sep" aria-hidden="true">{sep}</span>}{i < items.length - 1 ? <a>{t}</a> : <span>{t}</span>}</li>)}</ol>
|
|
@@ -16,8 +16,11 @@ body.ecx-canvas-body { padding: 0; }
|
|
|
16
16
|
.ecx-server-html [class*="stagger"], .ecx-server-html [class*="reveal"], .ecx-server-html [class*="animate"], .ecx-server-html [class*="fade-"], .ecx-server-html [class*="aos"], .ecx-server-html [data-aos] { opacity: 1 !important; visibility: visible !important; transform: none !important; animation: none !important; transition: none !important; }
|
|
17
17
|
.ecx-canvas-root { min-height: 100vh; padding: 2rem clamp(1rem, 4vw, 3rem) 40vh; box-sizing: border-box; outline: none; }
|
|
18
18
|
.ecx-canvas-root > * { max-width: var(--ecx-content-width, 760px); margin-left: auto; margin-right: auto; }
|
|
19
|
-
|
|
20
|
-
.ecx-canvas-root > .ecx-
|
|
19
|
+
/* Mặc định của trình soạn: độ ưu tiên chỉ bằng "1 class" (:where) — đứng sau dòng trên nên thắng nó, nhưng CSS theme nạp sau (vd .ecx-template > * { max-width: 960px }) thắng lại, như trên website */
|
|
20
|
+
:where(.ecx-canvas-root) > :is(.ecx-nested, .ecx-cover, [data-type="columns"], .ecx-align-wide) { max-width: var(--ecx-wide-width, 1200px); }
|
|
21
|
+
.ecx-canvas-root > .ecx-align-full { max-width: none; }
|
|
22
|
+
/* Header/footer trong template: mặc định rộng hết (cùng mức ưu tiên — theme giới hạn bề rộng phần con của template thì canvas theo) */
|
|
23
|
+
:where(.ecx-canvas-root) > .ecx-template-part { max-width: none; }
|
|
21
24
|
.ecx-canvas-root.is-wide > * { max-width: var(--ecx-wide-width, 1120px); }
|
|
22
25
|
/* Template (theme dựng bằng khối): website không giới hạn bề rộng khối con và không có lề soạn — canvas làm y hệt, theme tự quyết bằng CSS của nó
|
|
23
26
|
(chỉ đổi giá trị mặc định của biến, nên CSS theme vẫn thắng nếu có đặt max-width cho .ecx-template > *). */
|
|
@@ -41,6 +44,7 @@ pre [data-ecx-rich], pre[data-ecx-rich] { white-space: pre-wrap; }
|
|
|
41
44
|
/* min(100%, …) = 0 trong khung co theo nội dung (nút) → dùng độ dài chữ gợi ý, chặn tràn bằng max-width */
|
|
42
45
|
[data-ecx-rich][data-empty][data-placeholder] { min-width: calc(var(--ecx-ph, 0) * .6em); max-width: 100%; }
|
|
43
46
|
span[data-ecx-rich][data-empty][data-placeholder] { display: inline-block; vertical-align: top; }
|
|
47
|
+
[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 */
|
|
44
48
|
[data-ecx-rich][data-empty][data-placeholder]::before { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
|
|
45
49
|
.ProseMirror-hideselection *::selection { background: transparent; }
|
|
46
50
|
.ProseMirror-selectednode { outline: 2px solid var(--ecx-ui); }
|
|
@@ -140,9 +144,9 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
|
|
|
140
144
|
.ecx-media-error { color: #b42318; font: 12px var(--ecx-ui-font); margin: 6px 0 0; }
|
|
141
145
|
.ecx-cover-placeholder { min-height: 220px; }
|
|
142
146
|
.ecx-btn-ghost { background: none; border-color: transparent; }
|
|
143
|
-
/* tay nắm cột / nút thêm cột định vị theo khối cột (website không cần) */
|
|
147
|
+
/* tay nắm cột / nút thêm cột định vị theo khối cột (website không cần); nút nằm trong khối cột, góc dưới phải: không tràn khung canvas (thanh cuộn ngang) và không bị thanh công cụ nổi (ở trên khối đang chọn) che */
|
|
144
148
|
.ecx-canvas-root .ecx-columns { position: relative; }
|
|
145
|
-
.ecx-add-column { position: absolute; right:
|
|
149
|
+
.ecx-add-column { position: absolute; right: 4px; bottom: 4px; z-index: 7; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px; background: #0f1e29; color: #fff; font: 600 18px/1 var(--ecx-ui-font); cursor: pointer; box-shadow: 0 2px 6px rgb(0 0 0 / .2); }
|
|
146
150
|
.ecx-add-column:hover { background: var(--ecx-ui); }
|
|
147
151
|
.is-zoomed-out .ecx-add-column { display: none; }
|
|
148
152
|
`;
|
package/src/v2/canvas/canvas.tsx
CHANGED
|
@@ -31,11 +31,22 @@ const SRC_DOC = `<!doctype html><html><head><meta charset="utf-8"><meta name="vi
|
|
|
31
31
|
/** Khung soạn: iframe mang CSS của website → soạn thấy đúng phông, màu, khoảng cách; media query theo bề rộng thiết bị. */
|
|
32
32
|
/** Tỉ lệ của chế độ thu nhỏ. */
|
|
33
33
|
export const ZOOM_OUT = 0.5;
|
|
34
|
+
/** 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. */
|
|
35
|
+
export const DESKTOP_MIN_WIDTH = 1100;
|
|
34
36
|
|
|
35
37
|
export function Canvas({ device = "desktop", className, contentClassName = "ecx-content", before, after }: CanvasProps) {
|
|
36
38
|
const { ui, labels } = useEditor();
|
|
37
39
|
const frameRef = useRef<HTMLIFrameElement>(null);
|
|
38
40
|
const [doc, setDoc] = useState<Document | null>(null);
|
|
41
|
+
const wrapRef = useRef<HTMLDivElement>(null);
|
|
42
|
+
const [wrapW, setWrapW] = useState(0);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
const el = wrapRef.current;
|
|
45
|
+
if (!el) return;
|
|
46
|
+
const ro = new ResizeObserver(() => setWrapW(el.clientWidth));
|
|
47
|
+
ro.observe(el); setWrapW(el.clientWidth);
|
|
48
|
+
return () => ro.disconnect();
|
|
49
|
+
}, []);
|
|
39
50
|
|
|
40
51
|
const onLoad = useCallback(() => {
|
|
41
52
|
const f = frameRef.current;
|
|
@@ -58,11 +69,12 @@ export function Canvas({ device = "desktop", className, contentClassName = "ecx-
|
|
|
58
69
|
useUiTick();
|
|
59
70
|
const width = DEVICE_WIDTH[device];
|
|
60
71
|
// 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ệ
|
|
61
|
-
const
|
|
72
|
+
const fit = !width && wrapW > 0 && wrapW < DESKTOP_MIN_WIDTH ? wrapW / DESKTOP_MIN_WIDTH : 1;
|
|
73
|
+
const zoom = (ui.zoomOut ? ZOOM_OUT : 1) * fit;
|
|
62
74
|
const style = zoom === 1 ? { width: width ? `${width}px` : "100%" }
|
|
63
75
|
: { width: width ? `${width}px` : `${100 / zoom}%`, height: `${100 / zoom}%`, transform: `scale(${zoom})`, transformOrigin: width ? "top center" : "top left", flex: "none" };
|
|
64
76
|
return (
|
|
65
|
-
<div className={["ecx-canvas-wrap", `is-${device}`, zoom !== 1 && "is-zoomed-out", className].filter(Boolean).join(" ")}>
|
|
77
|
+
<div ref={wrapRef} className={["ecx-canvas-wrap", `is-${device}`, zoom !== 1 && "is-zoomed-out", className].filter(Boolean).join(" ")}>
|
|
66
78
|
<iframe ref={frameRef} className="ecx-canvas-frame" title={labels.canvas} srcDoc={SRC_DOC} onLoad={onLoad}
|
|
67
79
|
style={style} data-ecx-canvas="" />
|
|
68
80
|
{doc && createPortal(<CanvasWrapper><CanvasRoot doc={doc} contentClassName={contentClassName} before={before} after={after} /></CanvasWrapper>, doc.body)}
|
|
@@ -233,14 +245,18 @@ const typing = (el: Element | null) => !!el && ((el as HTMLElement).isContentEdi
|
|
|
233
245
|
function useCanvasKeys(doc: Document) {
|
|
234
246
|
const { store, ui } = useEditor();
|
|
235
247
|
useEffect(() => {
|
|
248
|
+
// Phím gõ khi focus ở Cây khối (trang ngoài, không phải iframe): cũng chạy như trong khung soạn
|
|
249
|
+
const fromTree = (e: KeyboardEvent) => e.target instanceof Element && e.target.ownerDocument !== doc && !!e.target.closest(".ecx-listview");
|
|
236
250
|
const onKey = (e: KeyboardEvent) => {
|
|
237
251
|
// Ô gõ (ProseMirror) đã xử lý phím này
|
|
238
252
|
if (e.defaultPrevented) return;
|
|
253
|
+
const outer = fromTree(e);
|
|
254
|
+
if (e.target instanceof Element && e.target.ownerDocument !== doc && !outer) return; // phím của trang ngoài ngoài Cây khối: không phải của khung soạn
|
|
239
255
|
const mod = e.metaKey || e.ctrlKey;
|
|
240
256
|
const k = e.key.toLowerCase();
|
|
241
257
|
if (mod && k === "z") { e.preventDefault(); if (e.shiftKey) store.redo(); else store.undo(); return; }
|
|
242
258
|
if (mod && k === "y") { e.preventDefault(); store.redo(); return; }
|
|
243
|
-
if (typing(doc.activeElement)) return;
|
|
259
|
+
if (typing(outer ? (e.target as Element) : doc.activeElement)) return;
|
|
244
260
|
// Phím điều hướng của trình duyệt khi không gõ chữ (Safari: ⌘← / ⌘→ = quay lại / tới trang; Backspace ở trình duyệt cũ)
|
|
245
261
|
// → chặn, không thì rời trình soạn và mất bài đang sửa
|
|
246
262
|
if ((e.metaKey || e.altKey) && (e.key === "ArrowLeft" || e.key === "ArrowRight") && !store.getState().range) { e.preventDefault(); return; }
|
|
@@ -304,7 +320,8 @@ function useCanvasKeys(doc: Document) {
|
|
|
304
320
|
const next = order[i + dir];
|
|
305
321
|
if (!next) return;
|
|
306
322
|
if (e.shiftKey) store.selectRange(next.id); else store.select([next.id], { editing: null });
|
|
307
|
-
|
|
323
|
+
if (outer) document.querySelector<HTMLElement>(`.ecx-listview [data-block="${next.id}"]`)?.focus(); // đang ở Cây khối: giữ focus ở cây
|
|
324
|
+
else ui.blockEl(next.id)?.focus({ preventScroll: false });
|
|
308
325
|
return;
|
|
309
326
|
}
|
|
310
327
|
if (mod && e.shiftKey && k === "d") { e.preventDefault(); store.duplicate(ids); return; }
|
|
@@ -347,11 +364,13 @@ function useCanvasKeys(doc: Document) {
|
|
|
347
364
|
};
|
|
348
365
|
const cut = (e: ClipboardEvent) => onCopy(e, true);
|
|
349
366
|
doc.addEventListener("keydown", onKey);
|
|
367
|
+
document.addEventListener("keydown", onKey); // Cây khối nằm ở trang ngoài
|
|
350
368
|
doc.addEventListener("copy", onCopy as EventListener);
|
|
351
369
|
doc.addEventListener("cut", cut as EventListener);
|
|
352
370
|
doc.addEventListener("paste", onPaste as EventListener);
|
|
353
371
|
return () => {
|
|
354
372
|
doc.removeEventListener("keydown", onKey);
|
|
373
|
+
document.removeEventListener("keydown", onKey);
|
|
355
374
|
doc.removeEventListener("copy", onCopy as EventListener);
|
|
356
375
|
doc.removeEventListener("cut", cut as EventListener);
|
|
357
376
|
doc.removeEventListener("paste", onPaste as EventListener);
|
package/src/v2/canvas/dnd.ts
CHANGED
|
@@ -112,6 +112,24 @@ function toParent(ctx: EditorContextValue, ev: PointerEvent) {
|
|
|
112
112
|
|
|
113
113
|
function findTarget(ctx: EditorContextValue, x: number, y: number, src: Source): DropTarget | null {
|
|
114
114
|
const { ui, store } = ctx;
|
|
115
|
+
// Thả trên một hàng của Cây khối (trang ngoài): trước / sau khối của hàng đó, leo lên cha nếu chỗ này không nhận
|
|
116
|
+
const row = document.elementFromPoint(x, y)?.closest<HTMLElement>(".ecx-listview .ecx-list-row[data-block]");
|
|
117
|
+
if (row?.dataset.block) {
|
|
118
|
+
let id = row.dataset.block;
|
|
119
|
+
if (src.ids.some((sid) => sid === id || isInside(store, id, sid))) return null;
|
|
120
|
+
const r = row.getBoundingClientRect();
|
|
121
|
+
const after = y > r.top + r.height / 2;
|
|
122
|
+
for (let guard = 0; guard < 12; guard++) {
|
|
123
|
+
const loc = store.locate(id);
|
|
124
|
+
if (!loc) return null;
|
|
125
|
+
if (canContainAll(loc.parent?.type ?? null, src.types)) {
|
|
126
|
+
return { docId: loc.docId, parentId: loc.parent?.id ?? null, index: loc.index + (after ? 1 : 0), rect: { left: r.left, top: (after ? r.bottom : r.top) - 2, width: r.width, height: 4 }, horizontal: false };
|
|
127
|
+
}
|
|
128
|
+
if (!loc.parent) return null;
|
|
129
|
+
id = loc.parent.id;
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
115
133
|
const frame = ui.canvasFrame, doc = ui.canvasDoc;
|
|
116
134
|
if (!frame || !doc) return null;
|
|
117
135
|
const f = frame.getBoundingClientRect();
|
package/src/v2/core/host.ts
CHANGED
|
@@ -76,7 +76,7 @@ export interface DocumentHost {
|
|
|
76
76
|
save?(ref: NestedDocRef, blocks: BNode[], content: SavedContent): Promise<void>;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
export type DynamicPost = { title?: string; date?: string; author?: string; excerpt?: string; image?: string | null; terms?: string[]; comments?: number; link?: string; /** Nội dung đã lưu của bài (ContentDoc) — khối "Nội dung bài" trong template vẽ nội dung thật thay vì khung giữ chỗ. */ content?: unknown };
|
|
79
|
+
export type DynamicPost = { title?: string; date?: string; author?: string; excerpt?: string; image?: string | null; terms?: string[]; /** Chuyên mục đầu tiên (breadcrumb như website); không có = bài/trang không thuộc chuyên mục nào. */ category?: string; comments?: number; link?: string; /** Nội dung đã lưu của bài (ContentDoc) — khối "Nội dung bài" trong template vẽ nội dung thật thay vì khung giữ chỗ. */ content?: unknown };
|
|
80
80
|
|
|
81
81
|
/** Thiết lập của khối "Danh sách bài" (attrs của query). */
|
|
82
82
|
export interface QueryArgs { inherit: boolean; postType: string; perPage: number; category?: string; tag?: string; orderBy: string; order: "asc" | "desc" }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MediaItem } from "../../shared/types";
|
|
2
|
+
|
|
3
|
+
/** srcset (gốc + các cỡ đã tạo) và bản WebP của ảnh thư viện → trình duyệt chọn file vừa khung (điện thoại không tải ảnh gốc). Dưới 2 cỡ thì không cần. */
|
|
4
|
+
export function mediaSrcsets(m: MediaItem): { srcset?: string; webpSrcset?: string } {
|
|
5
|
+
const cands = Object.values(m.sizes ?? {}).filter((s) => s?.url && s.width > 0).map((s) => ({ w: s.width, url: s.url, webp: s.webpUrl }));
|
|
6
|
+
if (m.width && m.width > 0) cands.push({ w: m.width, url: m.url, webp: m.webpUrl });
|
|
7
|
+
const uniq = [...new Map(cands.map((c) => [c.w, c])).values()].sort((a, b) => a.w - b.w);
|
|
8
|
+
if (uniq.length < 2) return {};
|
|
9
|
+
const webp = uniq.filter((c) => c.webp);
|
|
10
|
+
return { srcset: uniq.map((c) => `${c.url} ${c.w}w`).join(", "), webpSrcset: webp.length > 1 ? webp.map((c) => `${c.webp} ${c.w}w`).join(", ") : undefined };
|
|
11
|
+
}
|
package/src/v2/core/store.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RichNode } from "@ecomcx/ecomweb-content";
|
|
2
2
|
import { cloneBlock, inlineLength, joinInline, kindOf, makeBlock, splitInline, type BNode } from "./model";
|
|
3
3
|
import { findBlock, flatten, insertBlocks, mapBlock, moveBlocks, removeBlocks, setAttrs, sibling, topLevelOrdered, type Location } from "./ops";
|
|
4
|
-
import { canContain, fixTree } from "./structure";
|
|
4
|
+
import { canContain, leavesItem, fixTree } from "./structure";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Store của trình soạn: nhiều tài liệu cùng lúc (bài/template đang mở + header, footer, mẫu đồng bộ lồng bên trong),
|
|
@@ -470,7 +470,7 @@ export class EditorStore {
|
|
|
470
470
|
const loc = this.locate(afterId);
|
|
471
471
|
if (!loc) return;
|
|
472
472
|
const target = loc.block;
|
|
473
|
-
if (opts.replaceEmpty !== false && target.type === "paragraph" && !inlineLength(target.inline) && canContain(loc.parent?.type ?? null, nodes[0].type) && this.canRemove(afterId)) {
|
|
473
|
+
if (opts.replaceEmpty !== false && target.type === "paragraph" && !inlineLength(target.inline) && canContain(loc.parent?.type ?? null, nodes[0].type) && !leavesItem(loc.parent?.type, nodes[0].type) && this.canRemove(afterId)) {
|
|
474
474
|
const focusId = opts.focus !== false ? firstText(nodes[0]) : null;
|
|
475
475
|
this.commit(loc.docId, mapBlock(this.state.docs[loc.docId].blocks, afterId, () => nodes), {
|
|
476
476
|
select: focusId ? { ids: [], editing: focusId } : { ids: nodes.map((n) => n.id), editing: null },
|
|
@@ -480,7 +480,7 @@ export class EditorStore {
|
|
|
480
480
|
}
|
|
481
481
|
// Khối không đặt được ở cấp này (vd chèn nhóm sau một listItem): leo lên tới cấp đặt được
|
|
482
482
|
let at: Location & { docId: string } = loc;
|
|
483
|
-
while (at.parent && !canContain(at.parent.type, nodes[0].type)) {
|
|
483
|
+
while (at.parent && (!canContain(at.parent.type, nodes[0].type) || leavesItem(at.parent.type, nodes[0].type))) {
|
|
484
484
|
const up = this.locate(at.parent.id);
|
|
485
485
|
if (!up) break;
|
|
486
486
|
at = up;
|
package/src/v2/core/structure.ts
CHANGED
|
@@ -38,6 +38,9 @@ const RULES: Record<string, StructureRule> = {
|
|
|
38
38
|
tableHeader: { parents: ["tableRow"], required: p },
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
/** Mục danh sách / việc chỉ nhận chữ và danh sách lồng: khối lớn (bảng, ảnh, nhóm…) chèn mới thì phải ra ngoài danh sách. */
|
|
42
|
+
export const leavesItem = (parentType: string | null | undefined, child: string) => (parentType === "listItem" || parentType === "taskItem") && !/^(paragraph|bulletList|orderedList|taskList)$/.test(child);
|
|
43
|
+
|
|
41
44
|
const extra = new Map<string, StructureRule>();
|
|
42
45
|
export function setStructureRule(type: string, rule: StructureRule | null) {
|
|
43
46
|
if (rule) extra.set(type, rule);
|
package/src/v2/editor.css
CHANGED
|
@@ -302,6 +302,10 @@ body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select:
|
|
|
302
302
|
.ecx-side-icon.is-all { border-style: solid; border-color: var(--ecx-ed-muted); }
|
|
303
303
|
.ecx-side-icon.is-vertical { border-top: 2px solid var(--ecx-ed-fg); border-bottom: 2px solid var(--ecx-ed-fg); }
|
|
304
304
|
.ecx-side-icon.is-horizontal { border-left: 2px solid var(--ecx-ed-fg); border-right: 2px solid var(--ecx-ed-fg); }
|
|
305
|
+
.ecx-side-icon.is-top { border-top: 2px solid var(--ecx-ed-fg); }
|
|
306
|
+
.ecx-side-icon.is-right { border-right: 2px solid var(--ecx-ed-fg); }
|
|
307
|
+
.ecx-side-icon.is-bottom { border-bottom: 2px solid var(--ecx-ed-fg); }
|
|
308
|
+
.ecx-side-icon.is-left { border-left: 2px solid var(--ecx-ed-fg); }
|
|
305
309
|
.ecx-spacing { display: flex; flex-direction: column; gap: 8px; }
|
|
306
310
|
.ecx-spacing-head { display: flex; align-items: center; justify-content: space-between; }
|
|
307
311
|
.ecx-inherit { margin-left: 6px; font-style: normal; font-weight: 400; color: var(--ecx-ed-muted); font-size: 11px; }
|
package/src/v2/editor.tsx
CHANGED
|
@@ -250,7 +250,7 @@ function EditorShell({ className, onSave, header, actions, menuExtra, canvasBefo
|
|
|
250
250
|
{error && <div className="ecx-notice is-error" role="alert">{error}</div>}
|
|
251
251
|
{p.fixedToolbar && p.mode === "visual" && <div className="ecx-fixed-toolbar"><BlockToolbar placement="fixed" /></div>}
|
|
252
252
|
<div className="ecx-body">
|
|
253
|
-
{left && !p.distractionFree && <aside className="ecx-left">{left === "inserter" ? <InserterPanel /> : <ListView />}</aside>}
|
|
253
|
+
{left && !p.distractionFree && <aside className="ecx-left">{left === "inserter" ? <InserterPanel onClose={() => setLeft(null)} /> : <ListView />}</aside>}
|
|
254
254
|
<main className="ecx-main">{p.mode === "code" ? <CodeEditor /> : <Canvas device={device} before={canvasBefore} />}</main>
|
|
255
255
|
{right && !p.distractionFree && <aside className="ecx-right"><Inspector blockStyles={blockStyles} /></aside>}
|
|
256
256
|
</div>
|
package/src/v2/ui/attr-form.tsx
CHANGED
|
@@ -4,8 +4,10 @@ import { useEditor } from "../context";
|
|
|
4
4
|
import type { Choice, ChoiceKind } from "../core/host";
|
|
5
5
|
import type { BlockType } from "../core/registry";
|
|
6
6
|
import { messages } from "../../i18n";
|
|
7
|
+
import { blockOptions } from "../../shared/block-defs";
|
|
7
8
|
import { DEFAULT_IMAGE_SIZES, hintOf, hintText, imageSizeLabel, optionLabel, type AttrHint } from "./attr-hints";
|
|
8
9
|
import { ColorInput } from "./color-field";
|
|
10
|
+
import { mediaSrcsets } from "../core/media";
|
|
9
11
|
|
|
10
12
|
export const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
|
|
11
13
|
|
|
@@ -81,6 +83,8 @@ function ChoiceField({ hint, attrs, value, set, label }: { hint: AttrHint; attrs
|
|
|
81
83
|
export function AttrForm({ type, attrs, onChange }: { type: BlockType; attrs: Record<string, any>; onChange(a: Record<string, unknown>): void }) {
|
|
82
84
|
const { host, labels } = useEditor();
|
|
83
85
|
const lang = labels.lang;
|
|
86
|
+
// Khối plugin: nhãn "%khoá%" dịch bằng hàm dịch đăng ký cùng khối (namespace của plugin); không có thì dịch của host
|
|
87
|
+
const translate = blockOptions(type.name).translate ?? host.translate;
|
|
84
88
|
const entries = Object.entries(type.attributes ?? {})
|
|
85
89
|
.map(([k, s]) => [k, s, hintOf(type.name, k)] as const)
|
|
86
90
|
.filter(([k, s, h]) => !HIDDEN_ATTRS.has(k) && controlOf(s) !== "hidden" && h.control !== "hidden" && (!h.when || h.when(attrs)));
|
|
@@ -88,7 +92,7 @@ export function AttrForm({ type, attrs, onChange }: { type: BlockType; attrs: Re
|
|
|
88
92
|
return (
|
|
89
93
|
<div className="ecx-form">
|
|
90
94
|
{entries.map(([k, spec, hint]) => {
|
|
91
|
-
const label = hintText(hint, "label", lang) ?? attrLabel(k, spec, lang,
|
|
95
|
+
const label = hintText(hint, "label", lang) ?? attrLabel(k, spec, lang, translate);
|
|
92
96
|
const value = attrs[k] ?? spec.default;
|
|
93
97
|
const set = (v: unknown) => onChange({ [k]: v === "" || v === spec.default ? undefined : v });
|
|
94
98
|
const helpText = hintText(hint, "help", lang);
|
|
@@ -96,7 +100,7 @@ export function AttrForm({ type, attrs, onChange }: { type: BlockType; attrs: Re
|
|
|
96
100
|
const num = spec.type === "integer" || spec.type === "number";
|
|
97
101
|
const opts = (): Array<[string, string]> => hint.options
|
|
98
102
|
? hint.options.map((v) => [String(v), optionLabel(hint, v, lang)])
|
|
99
|
-
: (spec.enum ?? []).map((v, i) => [String(v), spec.enumLabels?.[i] ? (
|
|
103
|
+
: (spec.enum ?? []).map((v, i) => [String(v), spec.enumLabels?.[i] ? (translate?.(spec.enumLabels[i]) ?? spec.enumLabels[i]) : optionLabel(hint, v, lang)]);
|
|
100
104
|
const parse = (v: string) => (v === "" ? undefined : num ? Number(v) : v);
|
|
101
105
|
switch (hint.control ?? controlOf(spec)) {
|
|
102
106
|
case "checkbox":
|
|
@@ -153,7 +157,7 @@ export function AttrForm({ type, attrs, onChange }: { type: BlockType; attrs: Re
|
|
|
153
157
|
<Field key={k} label={label}>
|
|
154
158
|
<span className="ecx-color-row">
|
|
155
159
|
<input className="ecx-input" type="url" value={value == null ? "" : String(value)} onChange={(e) => set(e.target.value)} placeholder="https://…" />
|
|
156
|
-
{host.media && <button type="button" className="ecx-btn" onClick={async () => { const [m] = await host.media!.pick({ kind: "image", multiple: false }); if (m) onChange({ [k]: m.url, ...(k === "src" ? { mediaId: m.id, alt: attrs.alt ?? (m.alt || undefined) } : {}) }); }}>{labels.chooseImage}</button>}
|
|
160
|
+
{host.media && <button type="button" className="ecx-btn" onClick={async () => { const [m] = await host.media!.pick({ kind: "image", multiple: false }); if (m) onChange({ [k]: m.url, ...(k === "src" ? { mediaId: m.id, alt: attrs.alt ?? (m.alt || undefined), width: m.width ?? undefined, height: m.height ?? undefined, srcset: mediaSrcsets(m).srcset, webpSrcset: mediaSrcsets(m).webpSrcset } : {}) /* đổi ảnh thì kích thước khai báo theo ảnh mới (không giữ cỡ ảnh cũ → méo tỉ lệ / nhảy layout) */ }); }}>{labels.chooseImage}</button>}
|
|
157
161
|
</span>
|
|
158
162
|
{help}
|
|
159
163
|
</Field>
|
package/src/v2/ui/attr-hints.ts
CHANGED
|
@@ -90,9 +90,29 @@ export const ATTR_HINTS: Record<string, AttrHint> = {
|
|
|
90
90
|
"socialLinks.align": { control: "segmented", options: ALIGN },
|
|
91
91
|
"navigation.location": { control: "choice", choice: { kind: "menuLocation" }, help: true },
|
|
92
92
|
"navigation.orientation": { control: "segmented", options: ["horizontal", "vertical"] },
|
|
93
|
-
"navigation.overlayMenu": { control: "segmented", options: ["never", "mobile", "always"] },
|
|
93
|
+
"navigation.overlayMenu": { control: "segmented", label: true, options: ["never", "mobile", "always"] },
|
|
94
|
+
"gallery.linkTo": { control: "segmented", label: true, options: ["none", "media"] },
|
|
95
|
+
"gallery.imageCrop": { label: true },
|
|
96
|
+
"gallery.lightbox": { label: true },
|
|
97
|
+
"countdown.expiredText": { label: true },
|
|
98
|
+
"search.showLabel": { label: true },
|
|
99
|
+
"search.buttonPosition": { control: "segmented", label: true, options: ["right", "left", "below"] },
|
|
100
|
+
"postAuthor.showName": { label: true },
|
|
101
|
+
"postAuthor.showBio": { label: true },
|
|
102
|
+
"postAuthor.avatarSize": { label: true },
|
|
103
|
+
"comments.avatarSize": { label: true },
|
|
104
|
+
"comments.showDate": { label: true },
|
|
105
|
+
"comments.order": { control: "segmented", options: ["asc", "desc"] },
|
|
106
|
+
"termList.display": { control: "segmented", options: ["list", "cloud"] },
|
|
107
|
+
"termList.showCount": { label: true },
|
|
108
|
+
"termList.hideEmpty": { label: true },
|
|
109
|
+
"termList.hierarchical": { label: true },
|
|
110
|
+
"loginout.loginText": { label: true },
|
|
111
|
+
"loginout.logoutText": { label: true },
|
|
112
|
+
"pageList.parentId": { label: true },
|
|
113
|
+
"archives.showCount": { label: true },
|
|
114
|
+
"icon.name": { control: "select", options: ["check", "x", "star", "heart", "arrowRight", "phone", "mail", "mapPin", "clock", "info", "alert", "externalLink"] },
|
|
94
115
|
"languageSwitcher.display": { control: "segmented", options: ["inline", "dropdown"] },
|
|
95
|
-
"gallery.linkTo": { control: "segmented", options: ["none", "media"] },
|
|
96
116
|
"postTerms.taxonomy": { control: "choice", choice: { kind: "taxonomy" } },
|
|
97
117
|
"query.postType": { control: "choice", choice: { kind: "postType" }, when: notInherit },
|
|
98
118
|
"query.category": { control: "choice", choice: { kind: "term", args: () => ({ taxonomy: "category" }) }, when: notInherit },
|
|
@@ -3,14 +3,19 @@ import { useEditor } from "../context";
|
|
|
3
3
|
|
|
4
4
|
const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
|
|
5
5
|
|
|
6
|
+
// Theme không khai màu thì website dùng các màu mặc định này (core CSS) — vẫn cho chọn, như bản soạn cũ (shared/style-panel.tsx COLORS)
|
|
7
|
+
const DEFAULT_COLORS = { primary: "#2563eb", muted: "#6b7280", surface: "#f4f4f5", white: "#ffffff", black: "#111111" };
|
|
8
|
+
|
|
6
9
|
/** Ô màu: preset của theme + bảng chọn màu + bỏ màu. */
|
|
7
10
|
export function ColorInput({ value, onChange, label }: { value?: string; onChange(v: string | undefined): void; label: string }) {
|
|
8
11
|
const { host } = useEditor();
|
|
9
|
-
const
|
|
12
|
+
const declared = host.presets?.colors;
|
|
13
|
+
const colorMap: Record<string, string> = declared && Object.keys(declared).length ? declared : DEFAULT_COLORS;
|
|
14
|
+
const presets = Object.entries(colorMap);
|
|
10
15
|
return (
|
|
11
16
|
<div className="ecx-chip-row">
|
|
12
17
|
{presets.map(([name, c]) => <button key={name} type="button" className={cx("ecx-chip ecx-chip-swatch", value === name && "is-active")} title={name} aria-label={`${label}: ${name}`} style={{ background: c }} onClick={() => onChange(value === name ? undefined : name)} />)}
|
|
13
|
-
<ColorSwatchInput value={value} onChange={onChange} label={label} size={28} />
|
|
18
|
+
<ColorSwatchInput value={value && (colorMap[value] ?? value)} onChange={onChange} label={label} size={28} />
|
|
14
19
|
{value && <button type="button" className="ecx-chip" onClick={() => onChange(undefined)}>×</button>}
|
|
15
20
|
</div>
|
|
16
21
|
);
|
package/src/v2/ui/inserter.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { leavesItem } from "../core/structure";
|
|
1
2
|
import { blockDescription } from "./block-descriptions";
|
|
2
3
|
import { Blocks } from "lucide-react";
|
|
3
4
|
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ComponentType } from "react";
|
|
@@ -70,7 +71,12 @@ export function applyInsert(ctx: ReturnType<typeof useEditor>, req: InserterRequ
|
|
|
70
71
|
if (req.mode === "slash" && req.blockId) {
|
|
71
72
|
const b = store.block(req.blockId);
|
|
72
73
|
// Đoạn chỉ còn "/từ khoá" → thay cả đoạn bằng khối mới
|
|
73
|
-
|
|
74
|
+
const parentType = store.locate(req.blockId)?.parent?.type;
|
|
75
|
+
if (b && leavesItem(parentType, node.type)) {
|
|
76
|
+
// trong mục danh sách: khối mới ra sau danh sách, bỏ đoạn "/từ khoá" (mục còn lại tự có đoạn trống)
|
|
77
|
+
store.insertAfter(req.blockId, [node], { replaceEmpty: false });
|
|
78
|
+
store.remove([req.blockId], { focusNeighbor: false });
|
|
79
|
+
} else if (b && inlineLength(b.inline) <= (req.query?.length ?? 0) + 1) store.replace(req.blockId, [node], focusOpts(node));
|
|
74
80
|
else store.insertAfter(req.blockId, [node]);
|
|
75
81
|
} else store.insert(req.docId, req.parentId, req.index, [node]);
|
|
76
82
|
ui.openInserter(null);
|
|
@@ -191,31 +197,59 @@ function suggestions(options: InsertOption[], counts: Record<string, number>): I
|
|
|
191
197
|
|
|
192
198
|
const CATEGORY_ORDER = ["text", "media", "design", "widgets", "theme", "embed"];
|
|
193
199
|
/** Thư viện khối (cột trái): tìm, theo nhóm; bấm để chèn sau khối đang chọn, kéo thả vào khung soạn. */
|
|
194
|
-
export function InserterPanel({ onInserted }: { onInserted?(): void }) {
|
|
200
|
+
export function InserterPanel({ onInserted, onClose }: { onInserted?(): void; onClose?(): void }) {
|
|
195
201
|
const ctx = useEditor();
|
|
196
202
|
const { store, labels } = ctx;
|
|
197
|
-
|
|
203
|
+
useUiTick();
|
|
204
|
+
const all = useInsertOptions();
|
|
205
|
+
// Khối có luật vị trí (vd "Tổng số bài" chỉ trong Query): ẩn khi từ chỗ đang chọn đi lên tới gốc không có cấp nào nhận
|
|
206
|
+
const cur = store.currentIds[store.currentIds.length - 1];
|
|
207
|
+
const loc = cur ? store.locate(cur) : null;
|
|
208
|
+
// Chèn vào đúng cấp của khối đang chọn (anh em của nó) → chỉ xét cha trực tiếp; xét cả tổ tiên thì khối như "Tổng số bài" hiện ra nhưng bị loại lặng lẽ khi chèn
|
|
209
|
+
const parentType = loc?.ancestors.length ? store.block(loc.ancestors[loc.ancestors.length - 1])?.type ?? null : null;
|
|
210
|
+
const options = all.filter((o) => canContain(parentType, o.type));
|
|
211
|
+
const panelRef = useRef<HTMLDivElement>(null);
|
|
212
|
+
// Escape đóng bảng (khi focus đang ở bảng hoặc chưa ở đâu cả; đang gõ trong khung soạn thì Escape thuộc về khung soạn)
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
if (!onClose) return;
|
|
215
|
+
const onKey = (e: KeyboardEvent) => {
|
|
216
|
+
if (e.key !== "Escape" || ctx.ui.inserter) return;
|
|
217
|
+
const a = document.activeElement as HTMLElement | null;
|
|
218
|
+
if (a && !panelRef.current?.contains(a) && (a.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(a.tagName))) return;
|
|
219
|
+
onClose();
|
|
220
|
+
};
|
|
221
|
+
// Nút "Thêm khối" giữ focus trong khung soạn (iframe) nên phím Esc có thể rơi vào tài liệu của khung soạn, không phải trang ngoài
|
|
222
|
+
const frameDoc = ctx.ui.canvasDoc;
|
|
223
|
+
document.addEventListener("keydown", onKey);
|
|
224
|
+
frameDoc?.addEventListener("keydown", onKey);
|
|
225
|
+
return () => { document.removeEventListener("keydown", onKey); frameDoc?.removeEventListener("keydown", onKey); };
|
|
226
|
+
}, [onClose, ctx.ui]);
|
|
198
227
|
const [query, setQuery] = useState("");
|
|
199
228
|
const [tab, setTab] = useState<"blocks" | "patterns">("blocks");
|
|
200
229
|
const [hover, setHover] = useState<{ o: InsertOption; rect: DOMRect; y: number } | null>(null);
|
|
201
230
|
const results = rankOptions(options, query);
|
|
202
231
|
const catLabel: Record<string, string> = { text: labels.catText, media: labels.catMedia, design: labels.catDesign, widgets: labels.catWidgets, theme: labels.catTheme, embed: labels.catEmbed };
|
|
203
232
|
const p = usePrefs(ctx.prefs);
|
|
204
|
-
|
|
233
|
+
// "Đã dùng nhiều" tính một lần lúc mở bảng: chèn xong mà mục này hiện/đổi thì cả lưới khối nhảy xuống, bấm nhanh liên tiếp dễ trượt sang khối khác
|
|
234
|
+
const counts = useRef(p.insertCounts).current;
|
|
235
|
+
const mostUsed = p.mostUsedBlocks && !query ? options.filter((o) => !o.key.includes("/") && (counts[o.type] ?? 0) > 0).sort((a, b) => (counts[b.type] ?? 0) - (counts[a.type] ?? 0)).slice(0, 6) : [];
|
|
236
|
+
const lastInserted = useRef<string | null>(null);
|
|
205
237
|
const groups = query ? [["", results] as const] : [...CATEGORY_ORDER, ...new Set(results.map((r) => r.category).filter((c) => !CATEGORY_ORDER.includes(c)))].map((c) => [c, results.filter((r) => r.category === c)] as const).filter(([, l]) => l.length);
|
|
206
238
|
const insert = (o: InsertOption) => {
|
|
207
239
|
const node = o.create();
|
|
208
240
|
ctx.prefs.countInsert(o.type);
|
|
209
241
|
const cur = store.currentIds[store.currentIds.length - 1];
|
|
210
|
-
|
|
242
|
+
// Đoạn trống đang chọn mà chính lần chèn trước vừa tạo thì giữ lại (chèn tiếp ra sau nó); đoạn trống của người dùng thì thay như WordPress
|
|
243
|
+
if (cur && store.locate(cur)) store.insertAfter(cur, [node], { replaceEmpty: cur !== lastInserted.current });
|
|
211
244
|
else {
|
|
212
245
|
const docId = store.activeDocId;
|
|
213
246
|
store.insert(docId, null, store.getState().docs[docId].blocks.length, [node]);
|
|
214
247
|
}
|
|
248
|
+
lastInserted.current = node.id;
|
|
215
249
|
onInserted?.();
|
|
216
250
|
};
|
|
217
251
|
return (
|
|
218
|
-
<div className="ecx-inserter-panel" onMouseLeave={() => setHover(null)}>
|
|
252
|
+
<div ref={panelRef} className="ecx-inserter-panel" role="dialog" aria-label={labels.addBlock} onMouseLeave={() => setHover(null)}>
|
|
219
253
|
{hover && (
|
|
220
254
|
// Thẻ xem trước khi rê chuột: biểu tượng, tên, mô tả của khối
|
|
221
255
|
<div className="ecx-block-preview" role="tooltip" style={{ left: Math.round(hover.rect.right + 8), top: Math.round(Math.min(hover.y, window.innerHeight - 160)) }}>
|
package/src/v2/ui/list-view.tsx
CHANGED
|
@@ -25,17 +25,18 @@ export function ListView() {
|
|
|
25
25
|
if (!doc) return null;
|
|
26
26
|
return (
|
|
27
27
|
<div className="ecx-listview" role="tree" aria-label={labels.listView}>
|
|
28
|
-
{doc.blocks.map((b) => <ListRow key={b.id} node={b} depth={0} />)}
|
|
28
|
+
{doc.blocks.map((b, i) => <ListRow key={b.id} node={b} depth={0} first={i === 0} />)}
|
|
29
29
|
{!doc.blocks.length && <p className="ecx-muted ecx-list-empty">{labels.listEmpty}</p>}
|
|
30
30
|
|
|
31
31
|
</div>
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function ListRow({ node, depth }: { node: BNode; depth: number }) {
|
|
35
|
+
function ListRow({ node, depth, first }: { node: BNode; depth: number; first?: boolean }) {
|
|
36
36
|
const ctx = useEditor();
|
|
37
37
|
const { store, registry, ui, host } = ctx;
|
|
38
38
|
const selected = useEditorState(useCallback((s) => s.selection.ids.includes(node.id) || s.selection.editing === node.id, [node.id]));
|
|
39
|
+
const anySelected = useEditorState((s) => s.selection.ids.length > 0 || !!s.selection.editing);
|
|
39
40
|
const [open, setOpen] = useState(depth < 1);
|
|
40
41
|
const type = registry.get(node.type);
|
|
41
42
|
const Icon = type?.icon ?? Blocks;
|
|
@@ -48,12 +49,15 @@ function ListRow({ node, depth }: { node: BNode; depth: number }) {
|
|
|
48
49
|
return (
|
|
49
50
|
<div role="treeitem" aria-selected={selected} aria-expanded={hasKids ? open : undefined} aria-level={depth + 1}>
|
|
50
51
|
<div className={cx("ecx-list-row", selected && "is-selected", nestedId && "is-nested")} style={{ paddingLeft: 8 + depth * 14 }} data-block={node.id}
|
|
52
|
+
// Một tabstop cho cả cây (hàng đang chọn, không thì hàng đầu); mũi tên di chuyển, Enter/Space chọn (WAI-ARIA tree)
|
|
53
|
+
tabIndex={selected || (first && !anySelected) ? 0 : -1}
|
|
54
|
+
onKeyDown={(e) => { if ((e.key === "Enter" || e.key === " ") && e.target === e.currentTarget) { e.preventDefault(); store.select([node.id], { editing: null }); } }}
|
|
51
55
|
onClick={(e) => {
|
|
52
56
|
if (e.shiftKey) store.selectRange(node.id);
|
|
53
57
|
else store.select([node.id], { editing: null });
|
|
54
58
|
ui.blockEl(node.id)?.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
|
55
59
|
}}>
|
|
56
|
-
{hasKids ? <button type="button" className="ecx-twisty" aria-label={open ?
|
|
60
|
+
{hasKids ? <button type="button" className="ecx-twisty" aria-label={open ? ctx.labels.collapse : ctx.labels.expand} onClick={(e) => { e.stopPropagation(); setOpen(!open); }}>{open ? <ChevronDown className="ecx-icon" /> : <ChevronRight className="ecx-icon" />}</button> : <span className="ecx-twisty" />}
|
|
57
61
|
<Icon className="ecx-icon" />
|
|
58
62
|
<span className="ecx-list-title">{blockLabel(node, type)}</span>
|
|
59
63
|
{!!(node.attrs.lock || node.attrs.templateLock) && <Lock className="ecx-icon ecx-icon-sm" aria-label={ctx.labels.locked} />}
|
package/src/v2/ui/style-tab.tsx
CHANGED
|
@@ -69,8 +69,18 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
69
69
|
commit(next);
|
|
70
70
|
};
|
|
71
71
|
const setGroup = (k: "color" | "border", sub: string, v: unknown) => set(k, { ...(style[k] ?? {}), [sub]: v });
|
|
72
|
-
|
|
73
|
-
const
|
|
72
|
+
// Khoá theo khổ (cỡ chữ, khoảng cách…): chỉ bỏ giá trị của khổ đang chọn, không xoá các khổ khác
|
|
73
|
+
const reset = (keys: string[]) => {
|
|
74
|
+
const next: Style = { ...style };
|
|
75
|
+
for (const k of keys) {
|
|
76
|
+
if (RESPONSIVE.has(k) && device !== "base" && style[k] && typeof style[k] === "object") {
|
|
77
|
+
const r = { ...style[k] }; delete r[device];
|
|
78
|
+
next[k] = Object.keys(r).length ? r : undefined;
|
|
79
|
+
} else delete next[k];
|
|
80
|
+
}
|
|
81
|
+
commit(next);
|
|
82
|
+
};
|
|
83
|
+
const has = (keys: string[]) => keys.some((k) => RESPONSIVE.has(k) && device !== "base" ? style[k]?.[device] !== undefined : style[k] !== undefined);
|
|
74
84
|
const ok = (k: string) => (v: string) => !!normalizeStyle({ [k]: v });
|
|
75
85
|
const tag = (k: string) => RESPONSIVE.has(k) && device !== "base" ? <em className="ecx-device-tag">{t[`device_${device}` as keyof EditorLabels]}</em> : null;
|
|
76
86
|
const row = (k: string, label: string, control: ReactNode) => (
|
|
@@ -113,7 +123,7 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
113
123
|
</>}>
|
|
114
124
|
{row("fontSize", t.style_fontSize, <>
|
|
115
125
|
<Seg label={t.style_fontSize} value={get("fontSize")} onChange={(v) => set("fontSize", v)} options={sizes.map((v) => [v, v.toUpperCase(), v] as [string, string, string])} />
|
|
116
|
-
<ValueInput label={`${t.style_fontSize}: ${t.custom}`} value={sizes.includes(get("fontSize")) ? undefined : get("fontSize")} inherited={inherited("fontSize")} check={ok("fontSize")} placeholder="18px, 1.25rem" onCommit={(v) => set("fontSize", v)} />
|
|
126
|
+
<ValueInput label={`${t.style_fontSize}: ${t.custom}`} value={sizes.includes(get("fontSize")) ? undefined : get("fontSize")} inherited={inherited("fontSize")} check={(v) => sizes.includes(v) || (ok("fontSize")(v) && /^([\d.]|(calc|clamp|min|max|var)\()/.test(v))} placeholder="18px, 1.25rem" onCommit={(v) => set("fontSize", v)} />
|
|
117
127
|
</>)}
|
|
118
128
|
{row("appearance", t.style_appearance,
|
|
119
129
|
<select className="ecx-input" value={appearance} aria-label={t.style_appearance} onChange={(e) => {
|
|
@@ -136,8 +146,8 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
136
146
|
<Section title={t.style_spacing} modified={has(SPACING)} onReset={() => reset(SPACING)} moreOpen={has(["gap", "width", "maxWidth", "minHeight"])}
|
|
137
147
|
more={<>{(["gap", "width", "maxWidth", "minHeight"] as const).map((k) =>
|
|
138
148
|
row(k, t[`style_${k}`], <ValueInput label={t[`style_${k}`]} value={get(k)} inherited={inherited(k)} check={ok(k)} placeholder={k === "gap" ? "md, 24px" : "100%, 640px, 60vh"} onCommit={(v) => set(k, v)} />))}</>}>
|
|
139
|
-
<SpacingControl label={t.style_padding} steps={spaces} value={get("padding")} inherited={inherited("padding")} onChange={(v) => set("padding", v)} labels={{ vertical: ct.vertical, horizontal: ct.horizontal, link: t.linkSides, unlink: t.unlinkSides }} />
|
|
140
|
-
<SpacingControl label={t.style_margin} steps={spaces} value={get("margin")} inherited={inherited("margin")} onChange={(v) => set("margin", v)} labels={{ vertical: ct.vertical, horizontal: ct.horizontal, link: t.linkSides, unlink: t.unlinkSides }} />
|
|
149
|
+
<SpacingControl label={t.style_padding} steps={spaces} value={get("padding")} inherited={inherited("padding")} onChange={(v) => set("padding", v)} labels={{ vertical: ct.vertical, horizontal: ct.horizontal, top: ct.sideTop, right: ct.sideRight, bottom: ct.sideBottom, left: ct.sideLeft, link: t.linkSides, unlink: t.unlinkSides }} />
|
|
150
|
+
<SpacingControl label={t.style_margin} steps={spaces} value={get("margin")} inherited={inherited("margin")} onChange={(v) => set("margin", v)} labels={{ vertical: ct.vertical, horizontal: ct.horizontal, top: ct.sideTop, right: ct.sideRight, bottom: ct.sideBottom, left: ct.sideLeft, link: t.linkSides, unlink: t.unlinkSides }} />
|
|
141
151
|
</Section>
|
|
142
152
|
|
|
143
153
|
<Section title={t.style_border} modified={has(["border", "radius"])} onReset={() => reset(["border", "radius"])} defaultOpen={has(["border", "radius"])}>
|
|
@@ -69,7 +69,7 @@ const sidesOf = (v: Box): Record<string, string> => (typeof v === "object" && v
|
|
|
69
69
|
|
|
70
70
|
/** Lề trong / ngoài: liên kết (một giá trị) hoặc dọc + ngang. */
|
|
71
71
|
export function SpacingControl({ label, value, onChange, steps, inherited, labels }: {
|
|
72
|
-
label: string; value: Box; onChange(v: Box): void; steps: string[]; inherited?: string; labels: { vertical: string; horizontal: string; link: string; unlink: string };
|
|
72
|
+
label: string; value: Box; onChange(v: Box): void; steps: string[]; inherited?: string; labels: { vertical: string; horizontal: string; link: string; unlink: string; top: string; right: string; bottom: string; left: string };
|
|
73
73
|
}) {
|
|
74
74
|
const sides = sidesOf(value);
|
|
75
75
|
const [linked, setLinked] = useState(typeof value !== "object" || value === null || (sides.top === sides.bottom && sides.left === sides.right && sides.top === sides.left));
|
|
@@ -92,8 +92,10 @@ export function SpacingControl({ label, value, onChange, steps, inherited, label
|
|
|
92
92
|
{linked
|
|
93
93
|
? <StepSlider label={label} steps={steps} value={typeof value === "string" ? value : sides.top} onChange={(v) => set(["top", "right", "bottom", "left"], v)} sideIcon="is-all" />
|
|
94
94
|
: <>
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
{/* Bỏ liên kết: bốn cạnh riêng (đặt lệch được, vd chỉ padding-bottom) */}
|
|
96
|
+
{(["top", "right", "bottom", "left"] as const).map((side) => (
|
|
97
|
+
<StepSlider key={side} label={`${label} ${labels[side]}`} steps={steps} value={sides[side]} onChange={(v) => set([side], v)} sideIcon={`is-${side}`} />
|
|
98
|
+
))}
|
|
97
99
|
</>}
|
|
98
100
|
</div>
|
|
99
101
|
);
|