@ecomcx/ecomweb-editor 1.25.2 → 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/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/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 +34 -1
- package/src/v2/blocks/theme.tsx +44 -4
- package/src/v2/canvas/canvas-css.ts +5 -2
- 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/editor.css +4 -0
- package/src/v2/editor.tsx +1 -1
- package/src/v2/ui/attr-form.tsx +7 -3
- package/src/v2/ui/color-field.tsx +7 -2
- package/src/v2/ui/inserter.tsx +28 -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/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/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
|
@@ -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
|
}
|
|
@@ -157,9 +167,35 @@ function PageListEdit({ blockProps }: BlockEditProps) {
|
|
|
157
167
|
function ArchivesEdit({ block, blockProps }: BlockEditProps) {
|
|
158
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>;
|
|
159
169
|
}
|
|
160
|
-
|
|
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) {
|
|
161
172
|
const d = useDynamic();
|
|
162
|
-
|
|
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
|
+
);
|
|
163
199
|
}
|
|
164
200
|
/** Tiêu đề trang lưu trữ / tìm kiếm (H1 của trang chuyên mục, thẻ, tác giả…). */
|
|
165
201
|
function QueryTitleEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
@@ -178,7 +214,11 @@ function BreadcrumbsEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
|
178
214
|
const d = useDynamic();
|
|
179
215
|
const t = useMsgs("blocks");
|
|
180
216
|
const sep = String(block.attrs.separator ?? "›");
|
|
181
|
-
|
|
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] : [])];
|
|
182
222
|
return (
|
|
183
223
|
<nav {...(merge(blockProps, "ecx-breadcrumbs") as object)}>
|
|
184
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 > *). */
|
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/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>
|
|
@@ -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
|
@@ -197,7 +197,7 @@ function suggestions(options: InsertOption[], counts: Record<string, number>): I
|
|
|
197
197
|
|
|
198
198
|
const CATEGORY_ORDER = ["text", "media", "design", "widgets", "theme", "embed"];
|
|
199
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. */
|
|
200
|
-
export function InserterPanel({ onInserted }: { onInserted?(): void }) {
|
|
200
|
+
export function InserterPanel({ onInserted, onClose }: { onInserted?(): void; onClose?(): void }) {
|
|
201
201
|
const ctx = useEditor();
|
|
202
202
|
const { store, labels } = ctx;
|
|
203
203
|
useUiTick();
|
|
@@ -205,29 +205,51 @@ export function InserterPanel({ onInserted }: { onInserted?(): void }) {
|
|
|
205
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
206
|
const cur = store.currentIds[store.currentIds.length - 1];
|
|
207
207
|
const loc = cur ? store.locate(cur) : null;
|
|
208
|
-
|
|
209
|
-
const
|
|
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]);
|
|
210
227
|
const [query, setQuery] = useState("");
|
|
211
228
|
const [tab, setTab] = useState<"blocks" | "patterns">("blocks");
|
|
212
229
|
const [hover, setHover] = useState<{ o: InsertOption; rect: DOMRect; y: number } | null>(null);
|
|
213
230
|
const results = rankOptions(options, query);
|
|
214
231
|
const catLabel: Record<string, string> = { text: labels.catText, media: labels.catMedia, design: labels.catDesign, widgets: labels.catWidgets, theme: labels.catTheme, embed: labels.catEmbed };
|
|
215
232
|
const p = usePrefs(ctx.prefs);
|
|
216
|
-
|
|
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);
|
|
217
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);
|
|
218
238
|
const insert = (o: InsertOption) => {
|
|
219
239
|
const node = o.create();
|
|
220
240
|
ctx.prefs.countInsert(o.type);
|
|
221
241
|
const cur = store.currentIds[store.currentIds.length - 1];
|
|
222
|
-
|
|
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 });
|
|
223
244
|
else {
|
|
224
245
|
const docId = store.activeDocId;
|
|
225
246
|
store.insert(docId, null, store.getState().docs[docId].blocks.length, [node]);
|
|
226
247
|
}
|
|
248
|
+
lastInserted.current = node.id;
|
|
227
249
|
onInserted?.();
|
|
228
250
|
};
|
|
229
251
|
return (
|
|
230
|
-
<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)}>
|
|
231
253
|
{hover && (
|
|
232
254
|
// Thẻ xem trước khi rê chuột: biểu tượng, tên, mô tả của khối
|
|
233
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
|
);
|