@ecomcx/ecomweb-editor 1.22.0 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecomcx/ecomweb-editor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"description": "Trình soạn nội dung dạng khối của CMS — dùng độc lập trong mọi dự án React (1.x: TipTap; ./v2: cây khối, khung soạn iframe, sửa header/footer tại chỗ).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"*.css"
|
|
30
30
|
],
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@ecomcx/ecomweb-content": "^1.
|
|
32
|
+
"@ecomcx/ecomweb-content": "^1.18.0",
|
|
33
33
|
"react": ">=18",
|
|
34
34
|
"react-dom": ">=18"
|
|
35
35
|
},
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"prosemirror-view": "1.42.7"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@ecomcx/ecomweb-content": "^1.
|
|
63
|
+
"@ecomcx/ecomweb-content": "^1.18.0",
|
|
64
64
|
"@playwright/test": "1.53.0",
|
|
65
65
|
"@types/react": "19.2.2",
|
|
66
66
|
"@types/react-dom": "19.2.2",
|
package/src/legacy/dynamic.tsx
CHANGED
|
@@ -24,7 +24,7 @@ const SPECS: Array<[string, LucideIcon, "none" | "blocks", Record<string, BlockA
|
|
|
24
24
|
["siteLogo", Image, "none", { width: i("width", { min: 16, max: 600, default: 120 }), link: b("link", { default: true }) }],
|
|
25
25
|
["siteTagline", Text, "none", { textAlign: align }],
|
|
26
26
|
["navigation", Menu, "none", { location: s("location", { default: "primary" }), orientation: s("orientation", { enum: ["horizontal", "vertical"], enumLabels: ["horizontal", "vertical"], default: "horizontal" }), mobile: b("mobile", { default: true }) }],
|
|
27
|
-
["search", Search, "none", { placeholder: s("placeholder"), buttonText: s("buttonText") }],
|
|
27
|
+
["search", Search, "none", { placeholder: s("placeholder"), buttonText: s("buttonText"), postType: s("postType"), showLabel: b("showLabel", { default: false }), buttonPosition: s("buttonPosition", { enum: ["right", "left", "below"], enumLabels: ["right", "left", "below"], default: "right" }) }],
|
|
28
28
|
["languageSwitcher", Languages, "none", { display: s("display", { enum: ["inline", "dropdown"], enumLabels: ["inline", "dropdown"], default: "inline" }) }],
|
|
29
29
|
["copyright", Copyright, "none", { text: s("text"), textAlign: align }],
|
|
30
30
|
["postTitle", Heading1, "none", { level: i("level", { min: 1, max: 6, default: 1 }), link: b("link", { default: false }), textAlign: align }],
|
|
@@ -34,11 +34,15 @@ const SPECS: Array<[string, LucideIcon, "none" | "blocks", Record<string, BlockA
|
|
|
34
34
|
["postDate", Calendar, "none", { textAlign: align }],
|
|
35
35
|
["postAuthor", User, "none", { avatar: b("avatar", { default: false }), showName: b("showName", { default: true }), showBio: b("showBio", { default: false }), avatarSize: i("avatarSize", { min: 16, max: 128, default: 32 }), link: b("link", { default: true }) }],
|
|
36
36
|
["postTerms", Tags, "none", { taxonomy: s("taxonomy", { default: "category" }), separator: s("separator", { default: ", " }) }],
|
|
37
|
-
["comments", MessageSquare, "none", { title: s("title") }],
|
|
37
|
+
["comments", MessageSquare, "none", { title: s("title"), perPage: i("perPage", { min: 1, max: 50 }), order: s("order", { enum: ["asc", "desc"], enumLabels: ["asc", "desc"] }), avatarSize: i("avatarSize", { min: 16, max: 128, default: 40 }), showDate: b("showDate", { default: true }) }],
|
|
38
38
|
["readMore", ChevronsRight, "none", { text: s("text"), textAlign: align }],
|
|
39
39
|
["commentsCount", MessageSquare, "none", { textAlign: align }],
|
|
40
40
|
["avatar", User, "none", { size: i("size", { min: 16, max: 256, default: 48 }), link: b("link", { default: true }) }],
|
|
41
41
|
["queryTotal", List, "none", { textAlign: align }],
|
|
42
|
+
["termList", Tags, "none", { taxonomy: s("taxonomy", { default: "category" }), display: s("display", { enum: ["list", "cloud"], enumLabels: ["list", "cloud"], default: "list" }), showCount: b("showCount", { default: false }), hierarchical: b("hierarchical", { default: false }), hideEmpty: b("hideEmpty", { default: true }) }],
|
|
43
|
+
["pageList", List, "none", { parentId: i("parentId", { min: 1 }), depth: i("depth", { min: 1, max: 3, default: 2 }) }],
|
|
44
|
+
["archives", Calendar, "none", { showCount: b("showCount", { default: true }), limit: i("limit", { min: 1, max: 60, default: 12 }) }],
|
|
45
|
+
["loginout", User, "none", { loginText: s("loginText"), logoutText: s("logoutText"), textAlign: align }],
|
|
42
46
|
["queryTitle", Heading1, "none", { level: i("level", { min: 1, max: 6, default: 1 }), prefix: b("prefix", { default: false }), textAlign: align }],
|
|
43
47
|
["termDescription", AlignLeft, "none", { textAlign: align }],
|
|
44
48
|
["breadcrumbs", ChevronsRight, "none", { separator: s("separator", { default: "›" }), showHome: b("showHome", { default: true }), showCurrent: b("showCurrent", { default: true }) }],
|
package/src/locales/en/v2.ts
CHANGED
package/src/locales/vi/v2.ts
CHANGED
package/src/v2/blocks/theme.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AlignLeft, ArrowLeftRight, CalendarDays, ChevronsRight, Heading1, Copyright, FileText, Globe2, Image as ImageIcon, LayoutTemplate, ListOrdered, Menu, MessageSquare, PanelTop, Repeat2, Rows3, Search, SquareDashed, Tag, Type, User } from "lucide-react";
|
|
1
|
+
import { Star, AlignLeft, ArrowLeftRight, CalendarDays, ChevronsRight, Heading1, Copyright, FileText, Globe2, Image as ImageIcon, LayoutTemplate, ListOrdered, Menu, MessageSquare, PanelTop, Repeat2, Rows3, Search, SquareDashed, Tag, Type, User } from "lucide-react";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useState, type CSSProperties, type ReactNode } from "react";
|
|
3
3
|
import { Block, DocBlocks, InnerBlocks, NestedDoc } from "../canvas/block-list";
|
|
4
4
|
import { DocScopeProvider, LoopPostContext, useDocScope, useDynamicData, useEditor, useEditorState } from "../context";
|
|
@@ -114,6 +114,33 @@ function AvatarEdit({ block, blockProps }: BlockEditProps) {
|
|
|
114
114
|
function QueryTotalEdit({ blockProps, block }: BlockEditProps) {
|
|
115
115
|
return <p {...merge(blockProps, "ecx-query-total", align(block.attrs))}>0</p>;
|
|
116
116
|
}
|
|
117
|
+
function TermListEdit({ block, blockProps }: BlockEditProps) {
|
|
118
|
+
const cloud = block.attrs.display === "cloud";
|
|
119
|
+
const sample = block.attrs.taxonomy === "post_tag" ? ["Thẻ A", "Thẻ B", "Thẻ C"] : ["Chuyên mục A", "Chuyên mục B", "Chuyên mục C"];
|
|
120
|
+
const n = (i: number) => (block.attrs.showCount ? ` (${3 - i})` : "");
|
|
121
|
+
return cloud
|
|
122
|
+
? <p {...merge(blockProps, "ecx-term-list is-cloud")}>{sample.map((x, i) => <span key={x} style={{ marginRight: "0.5em", fontSize: `${1.3 - i * 0.2}em` }}>{x}{n(i)}</span>)}</p>
|
|
123
|
+
: <ul {...merge(blockProps, "ecx-term-list")}>{sample.map((x, i) => <li key={x}>{x}{n(i)}</li>)}</ul>;
|
|
124
|
+
}
|
|
125
|
+
function LoginOutEdit({ block, blockProps }: BlockEditProps) {
|
|
126
|
+
return <p {...merge(blockProps, "ecx-loginout", align(block.attrs))}><a href="#" onClick={(e) => e.preventDefault()}>{String(block.attrs.loginText || "Đăng nhập")}</a></p>;
|
|
127
|
+
}
|
|
128
|
+
function IconEdit({ block, blockProps }: BlockEditProps) {
|
|
129
|
+
const size = Math.min(128, Math.max(12, Number(block.attrs.size) || 24));
|
|
130
|
+
return <div {...merge(blockProps, "ecx-icon-block", align(block.attrs))}><span style={{ display: "inline-flex", alignItems: "center", gap: 6 }}><Star width={size} height={size} />{String(block.attrs.name ?? "star")}</span></div>;
|
|
131
|
+
}
|
|
132
|
+
function FootnotesEdit({ block, blockProps }: BlockEditProps) {
|
|
133
|
+
return <aside {...merge(blockProps, "ecx-footnotes")}>{block.attrs.title ? <p className="ecx-footnotes-title">{String(block.attrs.title)}</p> : null}<ol><li>Chú thích 1</li><li>Chú thích 2</li></ol></aside>;
|
|
134
|
+
}
|
|
135
|
+
function PageBreakEdit({ blockProps }: BlockEditProps) {
|
|
136
|
+
return <div {...merge(blockProps, "ecx-page-break")} style={{ ...(blockProps.style ?? {}), borderTop: "2px dashed currentColor", opacity: 0.5, textAlign: "center", fontSize: 12 }}>Ngắt trang</div>;
|
|
137
|
+
}
|
|
138
|
+
function PageListEdit({ blockProps }: BlockEditProps) {
|
|
139
|
+
return <nav {...merge(blockProps, "ecx-page-list")}><ul><li>Trang A<ul><li>Trang con</li></ul></li><li>Trang B</li></ul></nav>;
|
|
140
|
+
}
|
|
141
|
+
function ArchivesEdit({ block, blockProps }: BlockEditProps) {
|
|
142
|
+
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>;
|
|
143
|
+
}
|
|
117
144
|
function CommentsEdit({ blockProps }: BlockEditProps) {
|
|
118
145
|
const d = useDynamic();
|
|
119
146
|
return <div {...merge(blockProps, "ecx-comments")}><MessageSquare className="ecx-icon" /> {d.post?.comments ?? 0}</div>;
|
|
@@ -280,7 +307,7 @@ export function themeBlocks(): BlockType[] {
|
|
|
280
307
|
{ name: "siteLogo", title: "Logo", icon: ImageIcon, category: theme, keywords: "logo", kind: "atom", edit: SiteLogoEdit, attributes: { width: { type: "number", default: 120 }, link: { type: "boolean", default: true } }, supports: { style: true, className: true } },
|
|
281
308
|
{ name: "siteTagline", title: "Khẩu hiệu", icon: Type, category: theme, keywords: "khau hieu tagline mo ta", kind: "atom", edit: SiteTaglineEdit, attributes: { textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
282
309
|
{ name: "navigation", title: "Menu", icon: Menu, category: theme, keywords: "menu dieu huong navigation", kind: "atom", edit: NavigationEdit, attributes: { location: { type: "string", default: "primary" }, orientation: { type: "string", enum: ["horizontal", "vertical"], default: "horizontal" }, mobile: { type: "boolean", default: true }, overlayMenu: { type: "string", enum: ["never", "mobile", "always"], default: "mobile" } }, supports: { style: true, className: true }, summary: (a) => a.location },
|
|
283
|
-
{ name: "search", title: "Tìm kiếm", icon: Search, category: theme, keywords: "tim kiem search", kind: "atom", edit: SearchEdit, attributes: { placeholder: { type: "string" }, buttonText: { type: "string" } }, supports: { style: true, className: true } },
|
|
310
|
+
{ name: "search", title: "Tìm kiếm", icon: Search, category: theme, keywords: "tim kiem search", kind: "atom", edit: SearchEdit, attributes: { placeholder: { type: "string" }, buttonText: { type: "string" }, postType: { type: "string" }, showLabel: { type: "boolean", default: false }, buttonPosition: { type: "string", enum: ["right", "left", "below"], default: "right" } }, supports: { style: true, className: true } },
|
|
284
311
|
{ name: "languageSwitcher", title: "Chọn ngôn ngữ", icon: Globe2, category: theme, keywords: "ngon ngu language", kind: "atom", edit: LanguageEdit, attributes: { display: { type: "string", enum: ["inline", "dropdown"], default: "inline" } }, supports: { style: true, className: true } },
|
|
285
312
|
{ name: "copyright", title: "Bản quyền", icon: Copyright, category: theme, keywords: "ban quyen copyright", kind: "atom", edit: CopyrightEdit, attributes: { text: { type: "string" }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
286
313
|
{ name: "postTitle", title: "Tiêu đề bài", icon: Type, category: theme, keywords: "tieu de bai post title", kind: "atom", edit: PostTitleEdit, attributes: { level: { type: "integer", default: 1, min: 1, max: 6 }, link: { type: "boolean", default: false }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
@@ -290,11 +317,18 @@ export function themeBlocks(): BlockType[] {
|
|
|
290
317
|
{ name: "postDate", title: "Ngày đăng", icon: CalendarDays, category: theme, keywords: "ngay dang date", kind: "atom", edit: PostDateEdit, attributes: { textAlign: TEXT_ALIGN, displayType: { type: "string", enum: ["published", "modified"], default: "published" } }, supports: { style: true, className: true } },
|
|
291
318
|
{ name: "postAuthor", title: "Tác giả", icon: User, category: theme, keywords: "tac gia author", kind: "atom", edit: PostAuthorEdit, attributes: { avatar: { type: "boolean", default: false }, showName: { type: "boolean", default: true }, showBio: { type: "boolean", default: false }, avatarSize: { type: "integer", default: 32, min: 16, max: 128 }, link: { type: "boolean", default: true } }, supports: { style: true, className: true } },
|
|
292
319
|
{ name: "postTerms", title: "Chuyên mục / thẻ", icon: Tag, category: theme, keywords: "chuyen muc the category tag terms", kind: "atom", edit: PostTermsEdit, attributes: { taxonomy: { type: "string", default: "category" }, separator: { type: "string", default: ", " } }, supports: { style: true, className: true } },
|
|
293
|
-
{ name: "comments", title: "Bình luận", icon: MessageSquare, category: theme, keywords: "binh luan comments", kind: "atom", edit: CommentsEdit, attributes: { title: { type: "string" } } },
|
|
320
|
+
{ name: "comments", title: "Bình luận", icon: MessageSquare, category: theme, keywords: "binh luan comments", kind: "atom", edit: CommentsEdit, attributes: { title: { type: "string" }, perPage: { type: "integer", min: 1, max: 50 }, order: { type: "string", enum: ["asc", "desc"] }, avatarSize: { type: "integer", default: 40, min: 16, max: 128 }, showDate: { type: "boolean", default: true } } },
|
|
294
321
|
{ name: "readMore", title: "Đọc tiếp", icon: ChevronsRight, category: theme, keywords: "doc tiep read more", kind: "atom", edit: ReadMoreEdit, attributes: { text: { type: "string" }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
295
322
|
{ name: "commentsCount", title: "Số bình luận", icon: MessageSquare, category: theme, keywords: "so binh luan comments count", kind: "atom", edit: CommentsCountEdit, attributes: { textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
296
323
|
{ name: "avatar", title: "Ảnh đại diện tác giả", icon: ImageIcon, category: theme, keywords: "avatar anh dai dien tac gia", kind: "atom", edit: AvatarEdit, attributes: { size: { type: "integer", default: 48, min: 16, max: 256 }, link: { type: "boolean", default: true } }, supports: { style: true, className: true } },
|
|
297
324
|
{ name: "queryTotal", title: "Tổng số bài", icon: ListOrdered, category: theme, keywords: "tong so bai total", kind: "atom", edit: QueryTotalEdit, attributes: { textAlign: TEXT_ALIGN }, supports: { style: true, className: true }, structure: { parents: ["query"] } },
|
|
325
|
+
{ name: "termList", title: "Danh sách chuyên mục / thẻ", icon: Tag, category: theme, keywords: "danh sach chuyen muc the category tag cloud term list", kind: "atom", edit: TermListEdit, attributes: { taxonomy: { type: "string", default: "category" }, display: { type: "string", enum: ["list", "cloud"], default: "list" }, showCount: { type: "boolean", default: false }, hierarchical: { type: "boolean", default: false }, hideEmpty: { type: "boolean", default: true } }, supports: { style: true, className: true }, summary: (a) => a.taxonomy },
|
|
326
|
+
{ name: "loginout", title: "Đăng nhập / Đăng xuất", icon: User, category: theme, keywords: "dang nhap dang xuat login logout", kind: "atom", edit: LoginOutEdit, attributes: { loginText: { type: "string" }, logoutText: { type: "string" }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
327
|
+
{ name: "icon", title: "Icon", icon: Star, category: theme, keywords: "icon bieu tuong", kind: "atom", edit: IconEdit, attributes: { name: { type: "string", enum: ["check", "x", "star", "heart", "arrowRight", "phone", "mail", "mapPin", "clock", "info", "alert", "externalLink"], default: "star" }, size: { type: "integer", default: 24, min: 12, max: 128 }, label: { type: "string" }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true }, summary: (a) => a.name },
|
|
328
|
+
{ name: "footnotes", title: "Chú thích cuối bài", icon: ListOrdered, category: theme, keywords: "chu thich cuoi bai footnotes", kind: "atom", edit: FootnotesEdit, attributes: { title: { type: "string" } }, supports: { style: true, className: true } },
|
|
329
|
+
{ name: "pageBreak", title: "Ngắt trang", icon: PanelTop, category: theme, keywords: "ngat trang page break nextpage", kind: "atom", edit: PageBreakEdit, supports: { className: true } },
|
|
330
|
+
{ name: "pageList", title: "Danh sách trang", icon: ListOrdered, category: theme, keywords: "danh sach trang page list sitemap", kind: "atom", edit: PageListEdit, attributes: { parentId: { type: "integer", min: 1 }, depth: { type: "integer", default: 2, min: 1, max: 3 } }, supports: { style: true, className: true } },
|
|
331
|
+
{ name: "archives", title: "Lưu trữ theo tháng", icon: CalendarDays, category: theme, keywords: "luu tru thang archives", kind: "atom", edit: ArchivesEdit, attributes: { showCount: { type: "boolean", default: true }, limit: { type: "integer", default: 12, min: 1, max: 60 } }, supports: { style: true, className: true } },
|
|
298
332
|
{ name: "queryTitle", title: "Tiêu đề trang lưu trữ", icon: Heading1, category: theme, keywords: "tieu de luu tru chuyen muc archive query title h1", kind: "atom", edit: QueryTitleEdit, attributes: { level: { type: "integer", default: 1, min: 1, max: 6 }, prefix: { type: "boolean", default: false }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
299
333
|
{ name: "termDescription", title: "Mô tả chuyên mục", icon: AlignLeft, category: theme, keywords: "mo ta chuyen muc term description", kind: "atom", edit: TermDescriptionEdit, attributes: { textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
300
334
|
{ name: "breadcrumbs", title: "Breadcrumb", icon: ChevronsRight, category: theme, keywords: "breadcrumb duong dan dieu huong", kind: "atom", edit: BreadcrumbsEdit, attributes: { separator: { type: "string", default: "›" }, showHome: { type: "boolean", default: true }, showCurrent: { type: "boolean", default: true } }, supports: { style: true, className: true } },
|
package/src/v2/core/clipboard.ts
CHANGED
|
@@ -10,7 +10,7 @@ export const BLOCKS_MIME = "application/x-ecx-blocks";
|
|
|
10
10
|
// ---------------------------------------------------------------------------
|
|
11
11
|
// HTML → khối
|
|
12
12
|
// ---------------------------------------------------------------------------
|
|
13
|
-
const MARK_TAGS: Record<string, string> = { STRONG: "bold", B: "bold", EM: "italic", I: "italic", U: "underline", S: "strike", DEL: "strike", STRIKE: "strike", CODE: "code", SUB: "subscript", SUP: "superscript", MARK: "highlight" };
|
|
13
|
+
const MARK_TAGS: Record<string, string> = { STRONG: "bold", B: "bold", EM: "italic", I: "italic", U: "underline", S: "strike", DEL: "strike", STRIKE: "strike", CODE: "code", KBD: "kbd", SUB: "subscript", SUP: "superscript", MARK: "highlight" };
|
|
14
14
|
const BLOCK_TAGS = new Set(["P", "DIV", "H1", "H2", "H3", "H4", "H5", "H6", "UL", "OL", "LI", "BLOCKQUOTE", "PRE", "HR", "TABLE", "FIGURE", "IMG", "SECTION", "ARTICLE", "HEADER", "FOOTER", "MAIN", "ASIDE", "NAV", "DL", "DT", "DD"]);
|
|
15
15
|
|
|
16
16
|
function inlineOf(node: globalThis.Node, marks: RichMark[] = [], out: RichNode[] = []): RichNode[] {
|
|
@@ -187,7 +187,7 @@ export function serializeBlocks(nodes: BNode[]): { json: string; text: string; h
|
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
const esc = (s: string) => s.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]!);
|
|
190
|
-
const MARK_HTML: Record<string, string> = { bold: "strong", italic: "em", underline: "u", strike: "s", code: "code", subscript: "sub", superscript: "sup", highlight: "mark" };
|
|
190
|
+
const MARK_HTML: Record<string, string> = { bold: "strong", italic: "em", underline: "u", strike: "s", code: "code", kbd: "kbd", subscript: "sub", superscript: "sup", highlight: "mark" };
|
|
191
191
|
/** HTML đơn giản (dán sang Word, email…). */
|
|
192
192
|
export function richToHtml(nodes: RichNode[]): string {
|
|
193
193
|
const inl = (list: RichNode[] = []) => list.map((n) => {
|
|
@@ -23,6 +23,8 @@ const marks: Record<string, MarkSpec> = {
|
|
|
23
23
|
underline: simple("u"),
|
|
24
24
|
strike: simple("s", ["del", "strike"]),
|
|
25
25
|
code: { ...simple("code"), excludes: "_" },
|
|
26
|
+
footnote: { attrs: { note: { default: "" } }, inclusive: false, parseDOM: [{ tag: "span[data-ecx-footnote]", getAttrs: (d) => ({ note: (d as HTMLElement).getAttribute("data-ecx-footnote") ?? "" }) }], toDOM: (m) => ["span", { "data-ecx-footnote": String(m.attrs.note), class: "ecx-footnote-mark" }, 0] },
|
|
27
|
+
kbd: { ...simple("kbd"), excludes: "_" },
|
|
26
28
|
subscript: { ...simple("sub"), excludes: "superscript" },
|
|
27
29
|
superscript: { ...simple("sup"), excludes: "subscript" },
|
|
28
30
|
highlight: { attrs: { color: { default: null } }, parseDOM: [{ tag: "mark" }], toDOM: (m) => ["mark", m.attrs.color ? { style: `background:${m.attrs.color}` } : {}, 0] },
|
package/src/v2/ui/toolbar.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AlignCenter, AlignLeft, AlignRight, ArrowUpLeft, Bold, ChevronDown, ChevronUp, Code, Copy, CopyPlus, GripVertical, IndentDecrease, IndentIncrease, Italic, Link2, Link2Off, MoreVertical, PanelTop, Strikethrough, Trash2, Underline, Ungroup, Group as GroupIcon, Blocks, ArrowUpToLine, ArrowDownToLine, Shapes, Lock, Subscript, Superscript, Highlighter } from "lucide-react";
|
|
1
|
+
import { StickyNote, Keyboard, AlignCenter, AlignLeft, AlignRight, ArrowUpLeft, Bold, ChevronDown, ChevronUp, Code, Copy, CopyPlus, GripVertical, IndentDecrease, IndentIncrease, Italic, Link2, Link2Off, MoreVertical, PanelTop, Strikethrough, Trash2, Underline, Ungroup, Group as GroupIcon, Blocks, ArrowUpToLine, ArrowDownToLine, Shapes, Lock, Subscript, Superscript, Highlighter } from "lucide-react";
|
|
2
2
|
import { TextSelection } from "prosemirror-state";
|
|
3
3
|
import type { EditorView } from "prosemirror-view";
|
|
4
4
|
import { useEffect, useLayoutEffect, useRef, useState, type ComponentType, type ReactNode } from "react";
|
|
@@ -276,14 +276,19 @@ function MarkTools({ view, onLink }: { view: EditorView; onLink(): void }) {
|
|
|
276
276
|
const type = view.state.schema.marks[name];
|
|
277
277
|
const { from, to, empty } = view.state.selection;
|
|
278
278
|
const tr = view.state.tr;
|
|
279
|
-
if (
|
|
279
|
+
if (name === "footnote") {
|
|
280
|
+
// shortcut: hỏi nội dung bằng prompt() của trình duyệt, nâng thành popover khi cần sửa chú thích có sẵn
|
|
281
|
+
if (empty) return;
|
|
282
|
+
if (isActive(name)) tr.removeMark(from, to, type);
|
|
283
|
+
else { const note = window.prompt(labels.footnote)?.trim(); if (!note) return; tr.addMark(from, to, type.create({ note })); }
|
|
284
|
+
} else if (empty) tr.setStoredMarks(isActive(name) ? (view.state.storedMarks ?? view.state.selection.$from.marks()).filter((m) => m.type !== type) : [...(view.state.storedMarks ?? view.state.selection.$from.marks()), type.create()]);
|
|
280
285
|
else if (isActive(name)) tr.removeMark(from, to, type);
|
|
281
286
|
else tr.addMark(from, to, type.create());
|
|
282
287
|
view.dispatch(tr);
|
|
283
288
|
view.focus();
|
|
284
289
|
};
|
|
285
290
|
const main: Array<[string, typeof Bold, string, string]> = [["bold", Bold, labels.bold, `${mod}B`], ["italic", Italic, labels.italic, `${mod}I`], ["underline", Underline, labels.underline, `${mod}U`]];
|
|
286
|
-
const more: Array<[string, typeof Bold, string]> = [["strike", Strikethrough, labels.strike], ["code", Code, labels.code], ["subscript", Subscript, labels.subscript], ["superscript", Superscript, labels.superscript], ["highlight", Highlighter, labels.highlight]];
|
|
291
|
+
const more: Array<[string, typeof Bold, string]> = [["strike", Strikethrough, labels.strike], ["code", Code, labels.code], ["kbd", Keyboard, labels.kbd], ["footnote", StickyNote, labels.footnote], ["subscript", Subscript, labels.subscript], ["superscript", Superscript, labels.superscript], ["highlight", Highlighter, labels.highlight]];
|
|
287
292
|
return (
|
|
288
293
|
<div className="ecx-tool-group">
|
|
289
294
|
{main.map(([name, I, l, k]) => <ToolButton key={name} label={`${l} (${k})`} active={isActive(name)} onClick={() => toggle(name)}><I className="ecx-icon" /></ToolButton>)}
|