@ecomcx/ecomweb-editor 1.18.0 → 1.20.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.
Files changed (87) hide show
  1. package/package.json +25 -7
  2. package/src/index.ts +26 -25
  3. package/src/{ask.tsx → legacy/ask.tsx} +2 -2
  4. package/src/{blockMeta.ts → legacy/block-meta.ts} +1 -1
  5. package/src/{blocks.tsx → legacy/blocks.tsx} +8 -32
  6. package/src/{content.ts → legacy/content.ts} +1 -1
  7. package/src/{handle.tsx → legacy/drag-handle.tsx} +3 -3
  8. package/src/{dynamic.tsx → legacy/dynamic.tsx} +7 -3
  9. package/src/{Editor.tsx → legacy/editor.tsx} +9 -9
  10. package/src/{extensions.ts → legacy/extensions.ts} +1 -1
  11. package/src/legacy/insert-pattern.ts +13 -0
  12. package/src/{inserter.tsx → legacy/inserter.tsx} +6 -5
  13. package/src/{inspector.tsx → legacy/inspector.tsx} +7 -7
  14. package/src/{layoutUi.tsx → legacy/layout-ui.tsx} +6 -5
  15. package/src/{layout.tsx → legacy/layout.tsx} +2 -2
  16. package/src/{media.ts → legacy/media.ts} +1 -1
  17. package/src/{nodes.tsx → legacy/nodes.tsx} +2 -2
  18. package/src/{outline.tsx → legacy/outline.tsx} +4 -4
  19. package/src/legacy/panels.ts +22 -0
  20. package/src/{rank.ts → legacy/rank.ts} +2 -2
  21. package/src/{registry.ts → legacy/registry.ts} +1 -1
  22. package/src/{handles.tsx → legacy/resize-handles.tsx} +1 -1
  23. package/src/{styleattr.ts → legacy/style-attr.ts} +15 -1
  24. package/src/{synced.tsx → legacy/synced.tsx} +2 -2
  25. package/src/{toolbar.tsx → legacy/toolbar.tsx} +7 -7
  26. package/src/{unknown.tsx → legacy/unknown.tsx} +1 -1
  27. package/src/shared/block-defs.ts +38 -0
  28. package/src/shared/color-swatch.tsx +19 -0
  29. package/src/{panels.ts → shared/panel-store.ts} +4 -21
  30. package/src/{patterns.ts → shared/patterns.ts} +0 -12
  31. package/src/{stylepanel.tsx → shared/style-panel.tsx} +2 -2
  32. package/src/{types.ts → shared/types.ts} +2 -0
  33. package/src/v2/blocks/compat.tsx +51 -0
  34. package/src/v2/blocks/index.ts +42 -0
  35. package/src/v2/blocks/layout.tsx +281 -0
  36. package/src/v2/blocks/media-actions.tsx +76 -0
  37. package/src/v2/blocks/media.tsx +234 -0
  38. package/src/v2/blocks/resize.tsx +111 -0
  39. package/src/v2/blocks/text.tsx +150 -0
  40. package/src/v2/blocks/theme.tsx +293 -0
  41. package/src/v2/blocks/tools.tsx +72 -0
  42. package/src/v2/canvas/block-list.tsx +216 -0
  43. package/src/v2/canvas/canvas-css.ts +131 -0
  44. package/src/v2/canvas/canvas.tsx +379 -0
  45. package/src/v2/canvas/dnd.ts +192 -0
  46. package/src/v2/context.tsx +146 -0
  47. package/src/v2/core/bindings.ts +64 -0
  48. package/src/v2/core/clipboard.ts +238 -0
  49. package/src/v2/core/host.ts +80 -0
  50. package/src/v2/core/model.ts +157 -0
  51. package/src/v2/core/ops.ts +151 -0
  52. package/src/v2/core/patterns.ts +10 -0
  53. package/src/v2/core/registry.ts +135 -0
  54. package/src/v2/core/store.ts +804 -0
  55. package/src/v2/core/structure.ts +106 -0
  56. package/src/v2/core/tables.ts +194 -0
  57. package/src/v2/editor.css +324 -0
  58. package/src/v2/editor.tsx +288 -0
  59. package/src/v2/index.ts +28 -0
  60. package/src/v2/labels.ts +349 -0
  61. package/src/v2/prefs.ts +69 -0
  62. package/src/v2/text/paste.ts +75 -0
  63. package/src/v2/text/rich-schema.ts +96 -0
  64. package/src/v2/text/rich-text.tsx +512 -0
  65. package/src/v2/ui/attr-form.tsx +182 -0
  66. package/src/v2/ui/attr-hints.ts +129 -0
  67. package/src/v2/ui/bindings.tsx +91 -0
  68. package/src/v2/ui/block-descriptions.ts +34 -0
  69. package/src/v2/ui/color-field.tsx +17 -0
  70. package/src/v2/ui/doc-title.tsx +45 -0
  71. package/src/v2/ui/inserter.tsx +300 -0
  72. package/src/v2/ui/inspector.tsx +85 -0
  73. package/src/v2/ui/layout-panel.tsx +159 -0
  74. package/src/v2/ui/list-view.tsx +65 -0
  75. package/src/v2/ui/options.tsx +242 -0
  76. package/src/v2/ui/style-controls.tsx +57 -0
  77. package/src/v2/ui/style-tab.tsx +158 -0
  78. package/src/v2/ui/toolbar.tsx +402 -0
  79. package/src/v2/ui/unit-controls.tsx +99 -0
  80. /package/src/{basic.tsx → legacy/basic.tsx} +0 -0
  81. /package/src/{blockops.ts → legacy/block-ops.ts} +0 -0
  82. /package/src/{boundary.tsx → legacy/boundary.tsx} +0 -0
  83. /package/src/{editor.css → legacy/editor.css} +0 -0
  84. /package/src/{insert.ts → legacy/insert.ts} +0 -0
  85. /package/src/{labels.ts → shared/labels.ts} +0 -0
  86. /package/src/{paste.ts → shared/paste.ts} +0 -0
  87. /package/src/{util.ts → shared/util.ts} +0 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ecomcx/ecomweb-editor",
3
- "version": "1.18.0",
4
- "description": "Trình soạn thảo nội dung dạng khối (TipTap) của CMS — dùng độc lập trong mọi dự án React: ảnh responsive kéo đổi kích thước, gallery, video, bảng, slash menu, mở rộng bằng plugin.",
3
+ "version": "1.20.0",
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": {
7
7
  "type": "git",
@@ -17,7 +17,9 @@
17
17
  "types": "./src/index.ts",
18
18
  "exports": {
19
19
  ".": "./src/index.ts",
20
- "./style.css": "./src/editor.css"
20
+ "./style.css": "./src/legacy/editor.css",
21
+ "./v2": "./src/v2/index.ts",
22
+ "./v2/style.css": "./src/v2/editor.css"
21
23
  },
22
24
  "files": [
23
25
  "src",
@@ -27,11 +29,11 @@
27
29
  "*.css"
28
30
  ],
29
31
  "peerDependencies": {
32
+ "@ecomcx/ecomweb-content": "^1.15.0",
30
33
  "react": ">=18",
31
34
  "react-dom": ">=18"
32
35
  },
33
36
  "dependencies": {
34
- "@ecomcx/ecomweb-content": "^1.14.0",
35
37
  "@tiptap/core": "3.32.0",
36
38
  "@tiptap/extension-highlight": "3.32.0",
37
39
  "@tiptap/extension-image": "3.32.0",
@@ -47,19 +49,35 @@
47
49
  "@tiptap/react": "3.32.0",
48
50
  "@tiptap/starter-kit": "3.32.0",
49
51
  "@tiptap/suggestion": "3.32.0",
50
- "lucide-react": "1.56.0"
52
+ "lucide-react": "1.56.0",
53
+ "prosemirror-commands": "1.7.2",
54
+ "prosemirror-history": "1.5.1",
55
+ "prosemirror-inputrules": "1.5.1",
56
+ "prosemirror-keymap": "1.2.3",
57
+ "prosemirror-model": "1.25.12",
58
+ "prosemirror-state": "1.4.4",
59
+ "prosemirror-transform": "1.12.3",
60
+ "prosemirror-view": "1.42.7"
51
61
  },
52
62
  "devDependencies": {
63
+ "@ecomcx/ecomweb-content": "^1.15.0",
64
+ "@playwright/test": "1.53.0",
53
65
  "@types/react": "19.2.2",
54
66
  "@types/react-dom": "19.2.2",
67
+ "@vitejs/plugin-react": "4.5.2",
68
+ "axe-core": "4.10.3",
55
69
  "esbuild": "0.25.12",
56
70
  "react": "19.2.0",
57
71
  "react-dom": "19.2.0",
58
- "typescript": "5.9.3"
72
+ "typescript": "5.9.3",
73
+ "vite": "6.3.5"
59
74
  },
60
75
  "scripts": {
61
76
  "typecheck": "tsc --noEmit -p .",
62
- "test": "node scripts/test.mjs"
77
+ "test": "node scripts/check-layers.mjs && node scripts/test.mjs",
78
+ "playground": "vite --config playground/vite.config.ts",
79
+ "e2e": "playwright test",
80
+ "prepublishOnly": "node scripts/check-publish.mjs"
63
81
  },
64
82
  "bundleDependencies": [
65
83
  "@tiptap/core",
package/src/index.ts CHANGED
@@ -1,29 +1,30 @@
1
- export { Editor, type EditorProps } from "./Editor";
2
- export { contentToEditor, editorToContent } from "./content";
3
- export { viLabels, enLabels, type EditorLabels } from "./labels";
4
- export { imageAttrs, galleryImage } from "./media";
5
- export { CmsImage, Gallery, VideoNode, AudioNode, FileNode } from "./nodes";
6
- export { registerEditorExtension, unregisterEditorExtension, registeredExtensions } from "./registry";
7
- export type { ContentDoc, EditorExtensionPack, InsertItem, MediaItem, MediaKind, MediaProvider, MediaSize } from "./types";
8
- export { registerBlock, unregisterBlock, registeredBlocks, blockNode, type BlockEditProps, type RegisterBlockOptions } from "./blocks";
1
+ export { Editor, type EditorProps } from "./legacy/editor";
2
+ export { contentToEditor, editorToContent } from "./legacy/content";
3
+ export { viLabels, enLabels, type EditorLabels } from "./shared/labels";
4
+ export { imageAttrs, galleryImage } from "./legacy/media";
5
+ export { CmsImage, Gallery, VideoNode, AudioNode, FileNode } from "./legacy/nodes";
6
+ export { registerEditorExtension, unregisterEditorExtension, registeredExtensions } from "./legacy/registry";
7
+ export type { ContentDoc, EditorExtensionPack, InsertItem, MediaItem, MediaKind, MediaProvider, MediaSize } from "./shared/types";
8
+ export { registerBlock, unregisterBlock, registeredBlocks, blockNode, type BlockEditProps, type RegisterBlockOptions } from "./legacy/blocks";
9
9
  export { defineBlock, type BlockDefinition } from "@ecomcx/ecomweb-content";
10
10
  /** Lớp TipTap cấp thấp (Node, Mark, Extension…) — cho ứng dụng nhúng cần viết extension riêng; plugin nên dùng defineBlock/registerBlock. */
11
11
  export { Node, Mark, Extension, mergeAttributes, getSchema } from "@tiptap/core";
12
- export { askOf, type Ask, type AskField, type AskOptions, type AskResult } from "./ask";
13
- export { blockFromPos, currentBlock, deleteBlock, duplicateBlock, insertParagraphAfter, markContainer, moveBlock, parentBlock, type BlockRef } from "./blockops";
14
- export { runBlockAction, type BlockAction } from "./handle";
15
- export { Columns, Column, Group, Callout, ButtonNode, EmbedNode, COLUMN_PRESETS, setColumnCount, setColumnWidths } from "./layout";
16
- export { cleanPastedHtml } from "./paste";
17
- export { BlockInspector } from "./inspector";
18
- export { StylePanel } from "./stylepanel";
19
- export { BlockStyleAttr } from "./styleattr";
20
- export { BlockInserter, insertItem } from "./inserter";
21
- export { BlockTree } from "./outline";
22
- export { blockInfo, type BlockInfo } from "./blockMeta";
23
- export { blockTree, moveBlockTo, type BlockTreeItem } from "./blockops";
24
- export { registerDynamicBlocks, setDynamicPreview, DYNAMIC_BLOCKS, type DynamicPreviewData } from "./dynamic";
25
- export { registerBasicBlocks, Preformatted, SOCIAL_SERVICES } from "./basic";
26
- export { registerPattern, unregisterPattern, registeredPatterns, registerCorePatterns, insertPattern, patternNodes, PATTERN_CATEGORIES, type Pattern } from "./patterns";
27
- export { SyncedPattern, refreshSyncedPatterns, type PatternHost } from "./synced";
28
- export { registerBlockPanel, unregisterBlockPanel, type BlockPanel, type BlockPanelProps } from "./panels";
12
+ export { askOf, type Ask, type AskField, type AskOptions, type AskResult } from "./legacy/ask";
13
+ export { blockFromPos, currentBlock, deleteBlock, duplicateBlock, insertParagraphAfter, markContainer, moveBlock, parentBlock, type BlockRef } from "./legacy/block-ops";
14
+ export { runBlockAction, type BlockAction } from "./legacy/drag-handle";
15
+ export { Columns, Column, Group, Callout, ButtonNode, EmbedNode, COLUMN_PRESETS, setColumnCount, setColumnWidths } from "./legacy/layout";
16
+ export { cleanPastedHtml } from "./shared/paste";
17
+ export { BlockInspector } from "./legacy/inspector";
18
+ export { StylePanel } from "./shared/style-panel";
19
+ export { BlockStyleAttr } from "./legacy/style-attr";
20
+ export { BlockInserter, insertItem } from "./legacy/inserter";
21
+ export { BlockTree } from "./legacy/outline";
22
+ export { blockInfo, type BlockInfo } from "./legacy/block-meta";
23
+ export { blockTree, moveBlockTo, type BlockTreeItem } from "./legacy/block-ops";
24
+ export { registerDynamicBlocks, setDynamicPreview, DYNAMIC_BLOCKS, type DynamicPreviewData } from "./legacy/dynamic";
25
+ export { registerBasicBlocks, Preformatted, SOCIAL_SERVICES } from "./legacy/basic";
26
+ export { registerPattern, unregisterPattern, registeredPatterns, registerCorePatterns, patternNodes, PATTERN_CATEGORIES, type Pattern } from "./shared/patterns";
27
+ export { insertPattern } from "./legacy/insert-pattern";
28
+ export { SyncedPattern, refreshSyncedPatterns, type PatternHost } from "./legacy/synced";
29
+ export { registerBlockPanel, unregisterBlockPanel, type BlockPanel, type BlockPanelProps } from "./legacy/panels";
29
30
  export type { Editor as TiptapEditor } from "@tiptap/core";
@@ -1,8 +1,8 @@
1
1
  import type { Editor as TiptapEditor } from "@tiptap/core";
2
2
  import { useEffect, useId, useLayoutEffect, useRef, useState, useSyncExternalStore, type KeyboardEvent } from "react";
3
3
  import { createPortal } from "react-dom";
4
- import type { EditorLabels } from "./labels";
5
- import { cx } from "./util";
4
+ import type { EditorLabels } from "../shared/labels";
5
+ import { cx } from "../shared/util";
6
6
 
7
7
  /**
8
8
  * Hộp nhập nhỏ đặt cạnh chỗ đang soạn (thay window.prompt): link, alt, chú thích, YouTube, shortcode, cài đặt khối.
@@ -3,7 +3,7 @@ import {
3
3
  RectangleHorizontal, SquareCode, SquareDashed, Table2, TriangleAlert, Video, type LucideIcon,
4
4
  } from "lucide-react";
5
5
  import { pluginBlockInfo } from "./blocks";
6
- import type { EditorLabels } from "./labels";
6
+ import type { EditorLabels } from "../shared/labels";
7
7
  import { UNKNOWN_BLOCK } from "./unknown";
8
8
 
9
9
  export interface BlockInfo { title: string; icon: LucideIcon; description?: string }
@@ -4,48 +4,26 @@ import { BLOCK_VERSION_ATTR, blockDefaults, type BlockAttrSpec, type BlockDefini
4
4
  import { Blocks, type LucideIcon } from "lucide-react";
5
5
  import type { ComponentType, ReactNode } from "react";
6
6
  import { registerEditorExtension, unregisterEditorExtension } from "./registry";
7
- import { cx } from "./util";
8
- import { markContainer } from "./blockops";
7
+ import { cx } from "../shared/util";
8
+ import { markContainer } from "./block-ops";
9
9
  import { insertBlock } from "./insert";
10
10
 
11
- /** Props của phần xem trước tuỳ chỉnh trong trình soạn (tuỳ chọn — mặc định trình soạn tự hiển thị). */
12
- export interface BlockEditProps {
13
- attrs: Record<string, any>;
14
- setAttrs(attrs: Record<string, unknown>): void;
15
- selected: boolean;
16
- /** Nội dung bên trong (khối có content "inline"/"blocks") — đặt vào chỗ muốn người dùng gõ. */
17
- children?: ReactNode;
18
- }
19
-
20
- export interface RegisterBlockOptions {
21
- /** Biểu tượng trong slash menu và khung khối. */
22
- icon?: LucideIcon;
23
- /** Xem trước tuỳ chỉnh trong trình soạn; không có → khung chung + form cài đặt sinh từ attributes. */
24
- edit?: ComponentType<BlockEditProps>;
25
- /** Dịch nhãn ("%khoá%" → chữ theo ngôn ngữ admin) — admin truyền vào. */
26
- translate?(text: string): string;
27
- /** Khối chứa khối khác: nội dung có sẵn khi chèn (mặc định một đoạn văn trống). */
28
- initialContent?(): Array<Record<string, unknown>>;
29
- }
11
+ import { blockDefinition, blockOptions, dropBlockDefinition, storeBlockDefinition, type BlockEditProps, type RegisterBlockOptions } from "../shared/block-defs";
12
+ export { registeredBlocks, type BlockEditProps, type RegisterBlockOptions } from "../shared/block-defs";
30
13
 
31
14
  /** Chọn một ảnh (điều khiển "media" trong form cài đặt) — Editor đặt bằng nguồn media của ứng dụng. */
32
15
  let imagePicker: (() => Promise<{ url: string; id?: unknown; alt?: string } | null>) | null = null;
33
16
  export function setImagePicker(fn: typeof imagePicker) { imagePicker = fn; }
34
17
 
35
- const blocks = new Map<string, BlockDefinition>();
36
- const options = new Map<string, RegisterBlockOptions>();
37
-
38
18
  /** Tên (đã dịch) + biểu tượng của khối plugin — cho trình chèn, cây khối, tab "Khối". */
39
19
  export function pluginBlockInfo(name: string): { title: string; description?: string; icon: LucideIcon; def: BlockDefinition; translate(s: string): string } | null {
40
- const def = blocks.get(name);
20
+ const def = blockDefinition(name);
41
21
  if (!def) return null;
42
- const o = options.get(name) ?? {};
22
+ const o = blockOptions(name);
43
23
  const t = o.translate ?? ((x: string) => x);
44
24
  return { title: t(def.title), description: def.description ? t(def.description) : undefined, icon: o.icon ?? Blocks, def, translate: t };
45
25
  }
46
26
 
47
- /** Khối đang đăng ký (để chuẩn hoá + nâng phiên bản khi mở bài: contentToEditor). */
48
- export const registeredBlocks = (): BlockDefinition[] => [...blocks.values()];
49
27
 
50
28
  function controlOf(spec: BlockAttrSpec): NonNullable<BlockAttrSpec["control"]> {
51
29
  if (spec.control) return spec.control;
@@ -164,8 +142,7 @@ export function blockNode(def: BlockDefinition, opts: RegisterBlockOptions = {})
164
142
  */
165
143
  export function registerBlock(def: BlockDefinition, opts: RegisterBlockOptions = {}) {
166
144
  const t = opts.translate ?? ((s: string) => s);
167
- blocks.set(def.name, def);
168
- options.set(def.name, opts);
145
+ storeBlockDefinition(def, opts);
169
146
  registerEditorExtension({
170
147
  name: `block:${def.name}`,
171
148
  extensions: [blockNode(def, opts)],
@@ -183,7 +160,6 @@ export function registerBlock(def: BlockDefinition, opts: RegisterBlockOptions =
183
160
  }
184
161
 
185
162
  export function unregisterBlock(name: string) {
186
- blocks.delete(name);
187
- options.delete(name);
163
+ dropBlockDefinition(name);
188
164
  unregisterEditorExtension(`block:${name}`);
189
165
  }
@@ -1,6 +1,6 @@
1
1
  import { normalizeContent } from "@ecomcx/ecomweb-content";
2
2
  import { registeredBlocks } from "./blocks";
3
- import type { ContentDoc } from "./types";
3
+ import type { ContentDoc } from "../shared/types";
4
4
 
5
5
  /** Nội dung đã lưu → nội dung cho trình soạn. Khối "html" (vd nội dung nhập từ hệ thống cũ) được TipTap tự chuyển thành rich text. */
6
6
  export function contentToEditor(content?: ContentDoc | null): { main: any; others: ContentDoc["blocks"] } {
@@ -4,9 +4,9 @@ import { ArrowDown, ArrowUp, Copy, CornerLeftUp, GripVertical, Plus, Shapes, Tra
4
4
  import { useEffect, useRef, useState, type DragEvent, type KeyboardEvent } from "react";
5
5
  import { createPortal } from "react-dom";
6
6
  import { createPatternFrom, patternHostOf } from "./synced";
7
- import { blockFromPos, currentBlock, deleteBlock, duplicateBlock, insertParagraphAfter, insertParagraphBefore, moveBlock, parentBlock, type BlockRef } from "./blockops";
8
- import type { EditorLabels } from "./labels";
9
- import { cx } from "./util";
7
+ import { blockFromPos, currentBlock, deleteBlock, duplicateBlock, insertParagraphAfter, insertParagraphBefore, moveBlock, parentBlock, type BlockRef } from "./block-ops";
8
+ import type { EditorLabels } from "../shared/labels";
9
+ import { cx } from "../shared/util";
10
10
 
11
11
  const mac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform);
12
12
  const key = (s: string) => (mac ? s.replace("Mod", "⌘").replace("Shift", "⇧").replace("Alt", "⌥").replace(/-/g, "") : s.replace("Mod", "Ctrl").replace(/-/g, "+"));
@@ -1,6 +1,6 @@
1
1
  import { DYNAMIC_NODES, defineBlock, type BlockAttrSpec, type BlockDefinition } from "@ecomcx/ecomweb-content";
2
2
  import {
3
- AlignLeft, Calendar, Copyright, FileText, Globe, Heading1, Image, Languages, LayoutTemplate, List, ListX, Menu, MessageSquare, MoreHorizontal,
3
+ AlignLeft, ArrowLeftRight, Calendar, ChevronsRight, Copyright, FileText, Globe, Heading1, Image, Languages, LayoutTemplate, List, ListX, Menu, MessageSquare, MoreHorizontal,
4
4
  PanelTop, Repeat, Search, Tags, Text, Type, User, type LucideIcon,
5
5
  } from "lucide-react";
6
6
  import { useSyncExternalStore, type ReactNode } from "react";
@@ -14,7 +14,7 @@ type Dict = Record<string, string>;
14
14
  const vi: Dict = {
15
15
  siteTitle: "Tên website", siteLogo: "Logo", siteTagline: "Khẩu hiệu", navigation: "Menu", search: "Tìm kiếm", languageSwitcher: "Chọn ngôn ngữ",
16
16
  copyright: "Bản quyền", postTitle: "Tiêu đề bài/trang", postContent: "Nội dung bài/trang", postExcerpt: "Sapo", featuredImage: "Ảnh đại diện",
17
- postDate: "Ngày đăng", postAuthor: "Tác giả", postTerms: "Chuyên mục / thẻ", comments: "Bình luận", query: "Danh sách bài",
17
+ postDate: "Ngày đăng", postAuthor: "Tác giả", postTerms: "Chuyên mục / thẻ", comments: "Bình luận", queryTitle: "Tiêu đề trang lưu trữ", termDescription: "Mô tả chuyên mục", breadcrumbs: "Breadcrumb", postNavigation: "Bài trước / bài sau", query: "Danh sách bài",
18
18
  postTemplate: "Khuôn mỗi bài", pagination: "Phân trang", queryEmpty: "Khi không có bài", templatePart: "Phần dùng chung",
19
19
  level: "Cấp tiêu đề (0 = chữ thường)", link: "Có liên kết", textAlign: "Căn chữ", width: "Rộng (px)", location: "Vị trí menu",
20
20
  orientation: "Hướng", horizontal: "Ngang", vertical: "Dọc", mobile: "Nút menu trên điện thoại", placeholder: "Chữ gợi ý", buttonText: "Chữ trên nút",
@@ -29,7 +29,7 @@ const vi: Dict = {
29
29
  const en: Dict = {
30
30
  siteTitle: "Site title", siteLogo: "Logo", siteTagline: "Tagline", navigation: "Navigation", search: "Search", languageSwitcher: "Language switcher",
31
31
  copyright: "Copyright", postTitle: "Post/page title", postContent: "Post/page content", postExcerpt: "Excerpt", featuredImage: "Featured image",
32
- postDate: "Date", postAuthor: "Author", postTerms: "Categories / tags", comments: "Comments", query: "Post list",
32
+ postDate: "Date", postAuthor: "Author", postTerms: "Categories / tags", comments: "Comments", queryTitle: "Archive title", termDescription: "Term description", breadcrumbs: "Breadcrumbs", postNavigation: "Previous / next post", query: "Post list",
33
33
  postTemplate: "Post template", pagination: "Pagination", queryEmpty: "No results", templatePart: "Template part",
34
34
  level: "Heading level (0 = text)", link: "Link", textAlign: "Text align", width: "Width (px)", location: "Menu location",
35
35
  orientation: "Orientation", horizontal: "Horizontal", vertical: "Vertical", mobile: "Menu button on mobile", placeholder: "Placeholder", buttonText: "Button text",
@@ -63,6 +63,10 @@ const SPECS: Array<[string, LucideIcon, "none" | "blocks", Record<string, BlockA
63
63
  ["postAuthor", User, "none", { avatar: b("avatar", { default: false }) }],
64
64
  ["postTerms", Tags, "none", { taxonomy: s("taxonomy", { default: "category" }), separator: s("separator", { default: ", " }) }],
65
65
  ["comments", MessageSquare, "none", {}],
66
+ ["queryTitle", Heading1, "none", { level: i("level", { min: 1, max: 6, default: 1 }), prefix: b("prefix", { default: false }), textAlign: align }],
67
+ ["termDescription", AlignLeft, "none", { textAlign: align }],
68
+ ["breadcrumbs", ChevronsRight, "none", { separator: s("separator", { default: "›" }), showHome: b("showHome", { default: true }), showCurrent: b("showCurrent", { default: true }) }],
69
+ ["postNavigation", ArrowLeftRight, "none", { showTitle: b("showTitle", { default: true }) }],
66
70
  ["query", List, "blocks", {
67
71
  inherit: b("inherit", { default: true }), postType: s("postType", { default: "post" }), perPage: i("perPage", { min: 1, max: 50, default: 10 }),
68
72
  category: s("category"), tag: s("tag"),
@@ -10,33 +10,33 @@ import {
10
10
  } from "lucide-react";
11
11
  import { useEffect, useMemo, useRef, useState, useSyncExternalStore, type ReactNode } from "react";
12
12
  import { createPortal } from "react-dom";
13
- import { viLabels, type EditorLabels } from "./labels";
13
+ import { viLabels, type EditorLabels } from "../shared/labels";
14
14
  import { galleryImage, imageAttrs } from "./media";
15
15
  import { coreExtensions, knownTypes } from "./extensions";
16
16
  import { unwrapUnknown, wrapUnknown } from "./unknown";
17
17
  import { onExtensionsChange, registeredExtensions } from "./registry";
18
18
  import { DYNAMIC_BLOCKS } from "./dynamic";
19
- import type { EditorExtensionPack, InsertItem, MediaItem, MediaKind, MediaProvider } from "./types";
20
- import { cx } from "./util";
19
+ import type { EditorExtensionPack, InsertItem, MediaItem, MediaKind, MediaProvider } from "../shared/types";
20
+ import { cx } from "../shared/util";
21
21
  import { rankItems } from "./rank";
22
22
  export { rankItems } from "./rank";
23
23
  import { AskPopover, askOf, createAskStore, type Ask } from "./ask";
24
24
  import type { PatternHost } from "./synced";
25
- import { BlockHandle, BlockKeys } from "./handle";
26
- import { BlockSettingsBar, layoutItems } from "./layoutUi";
25
+ import { BlockHandle, BlockKeys } from "./drag-handle";
26
+ import { BlockSettingsBar, layoutItems } from "./layout-ui";
27
27
  import { BlockToolbar } from "./toolbar";
28
28
  import { OverlayBoundary } from "./boundary";
29
- import { CanvasHandles } from "./handles";
30
- import { documentStyleCss, presetsCss } from "./styleattr";
29
+ import { CanvasHandles } from "./resize-handles";
30
+ import { documentStyleCss, presetsCss } from "./style-attr";
31
31
  import type { StylePresets } from "@ecomcx/ecomweb-content";
32
32
  import { registerBasicBlocks } from "./basic";
33
- import { registerCorePatterns } from "./patterns";
33
+ import { registerCorePatterns } from "../shared/patterns";
34
34
  import { setImagePicker } from "./blocks";
35
35
 
36
36
  // Bộ khối cơ bản có sẵn ở mọi trình soạn (ứng dụng gọi lại registerBasicBlocks("en") để đổi nhãn)
37
37
  registerBasicBlocks();
38
38
  registerCorePatterns();
39
- import { cleanPastedHtml, isUrl } from "./paste";
39
+ import { cleanPastedHtml, isUrl } from "../shared/paste";
40
40
  import { handleInsertDrop } from "./inserter";
41
41
  import { embedInfo } from "@ecomcx/ecomweb-content";
42
42
 
@@ -14,7 +14,7 @@ import { AudioNode, CmsImage, EditorContext, FileNode, Gallery, VideoNode } from
14
14
  import { SyncedPattern } from "./synced";
15
15
  import { UnknownBlock, UnknownInline, UnknownMark } from "./unknown";
16
16
  import { layoutExtensions } from "./layout";
17
- import { BlockStyleAttr } from "./styleattr";
17
+ import { BlockStyleAttr } from "./style-attr";
18
18
 
19
19
  /**
20
20
  * Mọi khối + định dạng lõi mà trình soạn hiểu — khớp với định dạng nội dung của CMS (@ecomcx/ecomweb-content CORE_NODES/CORE_MARKS):
@@ -0,0 +1,13 @@
1
+ import type { Editor as TiptapEditor } from "@tiptap/core";
2
+ import { patternNodes, type Pattern } from "../shared/patterns";
3
+
4
+ /** Chèn mẫu dưới khối đang chọn (dòng trống đang có con trỏ → thay dòng đó). */
5
+ export function insertPattern(editor: TiptapEditor, p: Pattern) {
6
+ const nodes = p.synced && p.ref ? [{ type: "syncedPattern", attrs: { ref: p.ref } }] : patternNodes(p);
7
+ if (!nodes.length) return false;
8
+ const { $from, empty } = editor.state.selection;
9
+ if (empty && $from.depth > 0 && $from.parent.type.name === "paragraph" && $from.parent.content.size === 0)
10
+ return editor.chain().focus().insertContentAt({ from: $from.before(), to: $from.after() }, nodes).run();
11
+ const after = $from.depth > 0 ? $from.after(1) : editor.state.doc.content.size;
12
+ return editor.chain().focus().insertContentAt(after, nodes).run();
13
+ }
@@ -4,15 +4,16 @@ import { TextSelection } from "@tiptap/pm/state";
4
4
  import type { EditorView } from "@tiptap/pm/view";
5
5
  import { Search } from "lucide-react";
6
6
  import { useId, useMemo, useState, useSyncExternalStore, type DragEvent } from "react";
7
- import { blockFromPos, currentBlock, insertParagraphAfter } from "./blockops";
8
- import { viLabels, type EditorLabels } from "./labels";
7
+ import { blockFromPos, currentBlock, insertParagraphAfter } from "./block-ops";
8
+ import { viLabels, type EditorLabels } from "../shared/labels";
9
9
  import { labelsOf } from "./nodes";
10
- import type { InsertItem } from "./types";
10
+ import type { InsertItem } from "../shared/types";
11
11
  import { DYNAMIC_NODES } from "@ecomcx/ecomweb-content";
12
12
  import { rankItems } from "./rank";
13
13
  import { DOMSerializer } from "@tiptap/pm/model";
14
- import { PATTERN_CATEGORIES, insertPattern, onPatternsChange, patternNodes, registeredPatterns, type Pattern } from "./patterns";
15
- import { cx, norm } from "./util";
14
+ import { PATTERN_CATEGORIES, onPatternsChange, patternNodes, registeredPatterns, type Pattern } from "../shared/patterns";
15
+ import { insertPattern } from "./insert-pattern";
16
+ import { cx, norm } from "../shared/util";
16
17
 
17
18
  /** Kiểu dữ liệu kéo từ trình chèn vào trình soạn. */
18
19
  export const INSERT_MIME = "application/x-cms-insert";
@@ -4,16 +4,16 @@ import { NodeSelection } from "@tiptap/pm/state";
4
4
  import { AlignCenter, AlignJustify, AlignLeft, AlignRight, ArrowDown, ArrowUp, ChevronRight, Copy, Trash2 } from "lucide-react";
5
5
  import { Component, useEffect, useId, useState, useSyncExternalStore, type ReactNode } from "react";
6
6
  import { CORE_BLOCK_STYLES, normalizeAnchor, normalizeClassName, type Device, type StylePresets } from "@ecomcx/ecomweb-content";
7
- import { StylePanel } from "./stylepanel";
7
+ import { StylePanel } from "../shared/style-panel";
8
8
  import { blockPanels, onBlockPanelsChange } from "./panels";
9
9
  import { BlockAttributesForm, pluginBlockInfo } from "./blocks";
10
- import { blockInfo } from "./blockMeta";
11
- import { currentBlock, parentBlock, setBlockAttrs, type BlockRef } from "./blockops";
12
- import { runBlockAction } from "./handle";
13
- import { viLabels, type EditorLabels } from "./labels";
14
- import { LAYOUT_TYPES, LayoutSettings } from "./layoutUi";
10
+ import { blockInfo } from "./block-meta";
11
+ import { currentBlock, parentBlock, setBlockAttrs, type BlockRef } from "./block-ops";
12
+ import { runBlockAction } from "./drag-handle";
13
+ import { viLabels, type EditorLabels } from "../shared/labels";
14
+ import { LAYOUT_TYPES, LayoutSettings } from "./layout-ui";
15
15
  import { labelsOf } from "./nodes";
16
- import { cx } from "./util";
16
+ import { cx } from "../shared/util";
17
17
 
18
18
  /**
19
19
  * Tab "Khối": cài đặt của khối đang chọn, đường dẫn khối cha (bấm để chọn khối cha),
@@ -7,13 +7,14 @@ import { AlignCenter, AlignLeft, AlignRight, Columns2, Columns3, Globe, Info, Pe
7
7
  import { useEffect, useRef, useState, type ReactNode } from "react";
8
8
  import { createPortal } from "react-dom";
9
9
  import { askOf } from "./ask";
10
- import { setBlockAttrs } from "./blockops";
10
+ import { setBlockAttrs } from "./block-ops";
11
11
  import { insertBlock } from "./insert";
12
12
  export { insertBlock } from "./insert";
13
- import type { EditorLabels } from "./labels";
13
+ import type { EditorLabels } from "../shared/labels";
14
14
  import { COLUMN_PRESETS, emptyColumn, safeColor, setColumnCount, setColumnWidths } from "./layout";
15
- import type { InsertItem } from "./types";
16
- import { cx } from "./util";
15
+ import type { InsertItem } from "../shared/types";
16
+ import { cx } from "../shared/util";
17
+ import { ColorSwatchInput } from "../shared/color-swatch";
17
18
 
18
19
  // ---------------------------------------------------------------------------
19
20
  // Lệnh chèn (slash menu)
@@ -109,7 +110,7 @@ function ColorField({ value, onChange, label, t }: { value: string | null; onCha
109
110
  <span className="cms-ed-color">
110
111
  <label className="cms-ed-color-label">
111
112
  <span>{label}</span>
112
- <input type="color" aria-label={label} value={safeColor(value)?.startsWith("#") && value!.length === 7 ? value! : "#ffffff"} onChange={(e) => onChange(e.target.value)} />
113
+ <ColorSwatchInput value={value ?? undefined} onChange={onChange} label={label} size={22} />
113
114
  </label>
114
115
  {value && <button type="button" className="cms-ed-text-btn" onMouseDown={(e) => e.preventDefault()} onClick={() => onChange(null)}>{t.noColor}</button>}
115
116
  </span>
@@ -2,9 +2,9 @@ import { Node, mergeAttributes, type Editor } from "@tiptap/core";
2
2
  import { NodeViewWrapper, ReactNodeViewRenderer, type ReactNodeViewProps } from "@tiptap/react";
3
3
  import { embedInfo } from "@ecomcx/ecomweb-content";
4
4
  import { ExternalLink, Link2 } from "lucide-react";
5
- import { markContainer } from "./blockops";
5
+ import { markContainer } from "./block-ops";
6
6
  import { labelsOf } from "./nodes";
7
- import { cx } from "./util";
7
+ import { cx } from "../shared/util";
8
8
 
9
9
  /**
10
10
  * Khối bố cục — khớp CORE_NODES của @ecomcx/ecomweb-content 1.2: cột (columns > column), nhóm, hộp lưu ý, nút, nhúng theo đường dẫn.
@@ -1,4 +1,4 @@
1
- import type { MediaItem, MediaSize } from "./types";
1
+ import type { MediaItem, MediaSize } from "../shared/types";
2
2
 
3
3
  /** Cỡ cùng tỉ lệ ≤ cỡ được chọn → srcset (trình duyệt tự chọn file vừa đủ). */
4
4
  function candidates(m: MediaItem, size: string): MediaSize[] {
@@ -3,8 +3,8 @@ import Image from "@tiptap/extension-image";
3
3
  import { NodeViewWrapper, ReactNodeViewRenderer, type ReactNodeViewProps } from "@tiptap/react";
4
4
  import { FileText, Music, Video as VideoIcon } from "lucide-react";
5
5
  import type { ReactNode } from "react";
6
- import { viLabels, type EditorLabels } from "./labels";
7
- import { cx } from "./util";
6
+ import { viLabels, type EditorLabels } from "../shared/labels";
7
+ import { cx } from "../shared/util";
8
8
  import type { Ask } from "./ask";
9
9
 
10
10
  /** Ngữ cảnh dùng chung cho node view (chữ giao diện…), đặt bởi component Editor. */
@@ -5,11 +5,11 @@ import type { Node as PMNode } from "@tiptap/pm/model";
5
5
  import { embedInfo } from "@ecomcx/ecomweb-content";
6
6
  import { ChevronDown, ChevronRight } from "lucide-react";
7
7
  import { useRef, useState, type DragEvent, type KeyboardEvent } from "react";
8
- import { blockInfo } from "./blockMeta";
9
- import { blockTree, currentBlock, moveBlockTo, type BlockTreeItem } from "./blockops";
10
- import { viLabels, type EditorLabels } from "./labels";
8
+ import { blockInfo } from "./block-meta";
9
+ import { blockTree, currentBlock, moveBlockTo, type BlockTreeItem } from "./block-ops";
10
+ import { viLabels, type EditorLabels } from "../shared/labels";
11
11
  import { labelsOf } from "./nodes";
12
- import { cx } from "./util";
12
+ import { cx } from "../shared/util";
13
13
 
14
14
  /** Mô tả ngắn của khối trong cây (chữ đầu, alt ảnh, đường dẫn nhúng…). */
15
15
  function preview(node: PMNode): string {
@@ -0,0 +1,22 @@
1
+ import { Extension } from "@tiptap/core";
2
+ import { registerEditorExtension, unregisterEditorExtension } from "./registry";
3
+ import { dropPanel, storePanel, type BlockPanel } from "../shared/panel-store";
4
+ export { blockPanelsFor, blockPanels, onBlockPanelsChange, type BlockPanel, type BlockPanelProps } from "../shared/panel-store";
5
+
6
+ /** Thêm panel vào tab "Khối" (BlockInspector) cho một số loại khối hoặc mọi khối. */
7
+ export function registerBlockPanel(panel: BlockPanel) {
8
+ storePanel(panel);
9
+ if (panel.attributes && panel.blocks?.length) {
10
+ const attrs = Object.fromEntries(Object.entries(panel.attributes).map(([k, spec]) => [k, { default: spec.default ?? null, renderHTML: () => ({}), parseHTML: () => spec.default ?? null }]));
11
+ registerEditorExtension({
12
+ name: `panel:${panel.id}`,
13
+ extensions: [Extension.create({ name: `cmsPanel_${panel.id.replace(/[^\w]/g, "_")}`, addGlobalAttributes: () => [{ types: panel.blocks!, attributes: attrs }] })],
14
+ });
15
+ }
16
+ }
17
+
18
+ export function unregisterBlockPanel(id: string) {
19
+ if (!dropPanel(id)) return;
20
+ unregisterEditorExtension(`panel:${id}`);
21
+ }
22
+
@@ -1,5 +1,5 @@
1
- import type { InsertItem } from "./types";
2
- import { norm } from "./util";
1
+ import type { InsertItem } from "../shared/types";
2
+ import { norm } from "../shared/util";
3
3
 
4
4
  /**
5
5
  * Lọc + xếp hạng lệnh: tên bắt đầu bằng chữ gõ > một từ trong tên bắt đầu bằng chữ gõ > từ khoá bắt đầu bằng chữ gõ
@@ -1,4 +1,4 @@
1
- import type { EditorExtensionPack } from "./types";
1
+ import type { EditorExtensionPack } from "../shared/types";
2
2
 
3
3
  /**
4
4
  * Plugin đăng ký thêm khối cho mọi trình soạn trong ứng dụng.
@@ -4,7 +4,7 @@ import type { Node as PMNode } from "@tiptap/pm/model";
4
4
  import { normalizeStyle, type Box, type Device } from "@ecomcx/ecomweb-content";
5
5
  import { useEffect, useState, type PointerEvent as ReactPointerEvent, type ReactElement } from "react";
6
6
  import { createPortal } from "react-dom";
7
- import type { EditorLabels } from "./labels";
7
+ import type { EditorLabels } from "../shared/labels";
8
8
 
9
9
  /** Khối kéo chỉnh khoảng đệm được (chọn cả khối). */
10
10
  const PADDED = new Set(["group", "cover", "columns", "column", "callout", "mediaText", "details", "pullquote"]);
@@ -1,8 +1,14 @@
1
1
  import { Extension, type Editor as TiptapEditor } from "@tiptap/core";
2
- import { collectStyles, normalizeAnchor, normalizeBlockStyleName, normalizeClassName, normalizeStyle, presetCss, styleClass, type BlockStyle, type StylePresets } from "@ecomcx/ecomweb-content";
2
+ import { collectStyles, normalizeAnchor, normalizeBindings, normalizeBlockStyleName, normalizeLock, normalizeTemplateLock, normalizeClassName, normalizeStyle, presetCss, styleClass, type BlockStyle, type StylePresets } from "@ecomcx/ecomweb-content";
3
3
 
4
4
  const SKIP = new Set(["doc", "text", "hardBreak", "tableRow"]);
5
5
 
6
+ const json = (key: string, data: string, norm: (v: unknown) => unknown) => ({
7
+ default: null, keepOnSplit: false,
8
+ parseHTML: (el: HTMLElement) => { try { return norm(JSON.parse(el.getAttribute(data) ?? "null")) ?? null; } catch { return null; } },
9
+ renderHTML: (attrs: Record<string, any>) => { const v = norm(attrs[key]); return v ? { [data]: JSON.stringify(v) } : {}; },
10
+ });
11
+
6
12
  /**
7
13
  * Kiểu dáng khối (`attrs.style`, @ecomcx/ecomweb-content) cho mọi loại khối của trình soạn: lưu trong JSON, hiện bằng class `ecx-s-…`
8
14
  * (cùng CSS với website), sao chép/dán giữ nguyên qua `data-ecx-style`. Khối mới tách ra (Enter) không kế thừa.
@@ -39,6 +45,14 @@ export const BlockStyleAttr = Extension.create({
39
45
  parseHTML: (el: HTMLElement) => normalizeAnchor(el.getAttribute("data-ecx-anchor")) ?? null,
40
46
  renderHTML: (attrs: Record<string, any>) => { const v = normalizeAnchor(attrs.anchor); return v ? { "data-ecx-anchor": v } : {}; },
41
47
  },
48
+ // Gắn dữ liệu / khoá khối (1.15): trình soạn 1.x không sửa nhưng phải giữ nguyên khi lưu
49
+ bindings: json("bindings", "data-ecx-bindings", normalizeBindings),
50
+ lock: json("lock", "data-ecx-lock", normalizeLock),
51
+ templateLock: {
52
+ default: null, keepOnSplit: false,
53
+ parseHTML: (el: HTMLElement) => normalizeTemplateLock(el.getAttribute("data-ecx-template-lock")) ?? null,
54
+ renderHTML: (attrs: Record<string, any>) => { const v = normalizeTemplateLock(attrs.templateLock); return v ? { "data-ecx-template-lock": v } : {}; },
55
+ },
42
56
  },
43
57
  }];
44
58
  },
@@ -4,8 +4,8 @@ import { NodeViewWrapper, ReactNodeViewRenderer, type ReactNodeViewProps } from
4
4
  import { Pencil, Repeat2, Unlink } from "lucide-react";
5
5
  import { useEffect, useMemo, useState } from "react";
6
6
  import { labelsOf } from "./nodes";
7
- import { patternNodes } from "./patterns";
8
- import { cx } from "./util";
7
+ import { patternNodes } from "../shared/patterns";
8
+ import { cx } from "../shared/util";
9
9
 
10
10
  /**
11
11
  * Mẫu đồng bộ: khối `syncedPattern { ref }` chỉ là tham chiếu — nội dung lấy từ mẫu gốc (ứng dụng cung cấp qua PatternHost),
@@ -8,14 +8,14 @@ import {
8
8
  import { useEffect, useRef, useState, type ReactNode } from "react";
9
9
  import { createPortal } from "react-dom";
10
10
  import { askOf } from "./ask";
11
- import { blockInfo } from "./blockMeta";
12
- import { currentBlock, parentBlock, type BlockRef } from "./blockops";
13
- import { runBlockAction, startBlockDrag, type BlockAction } from "./handle";
14
- import type { EditorLabels } from "./labels";
15
- import { LAYOUT_TYPES } from "./layoutUi";
11
+ import { blockInfo } from "./block-meta";
12
+ import { currentBlock, parentBlock, type BlockRef } from "./block-ops";
13
+ import { runBlockAction, startBlockDrag, type BlockAction } from "./drag-handle";
14
+ import type { EditorLabels } from "../shared/labels";
15
+ import { LAYOUT_TYPES } from "./layout-ui";
16
16
  import { imageAttrs } from "./media";
17
- import type { MediaKind, MediaProvider } from "./types";
18
- import { cx } from "./util";
17
+ import type { MediaKind, MediaProvider } from "../shared/types";
18
+ import { cx } from "../shared/util";
19
19
 
20
20
  type RequestMedia = (editor: TiptapEditor, kind: MediaKind) => void;
21
21
  const TEXT = new Set(["paragraph", "heading", "bulletList", "orderedList", "taskList", "blockquote", "codeBlock"]);