@ecomcx/ecomweb-editor 1.20.0 → 1.22.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 (69) hide show
  1. package/README.md +15 -0
  2. package/package.json +3 -3
  3. package/src/i18n/index.ts +74 -0
  4. package/src/index.ts +3 -1
  5. package/src/legacy/basic.tsx +8 -30
  6. package/src/legacy/dynamic.tsx +15 -39
  7. package/src/locales/en/attrs.ts +72 -0
  8. package/src/locales/en/bindings.ts +26 -0
  9. package/src/locales/en/block-desc.ts +53 -0
  10. package/src/locales/en/block-titles.ts +43 -0
  11. package/src/locales/en/blocks.ts +39 -0
  12. package/src/locales/en/controls.ts +18 -0
  13. package/src/locales/en/hints.ts +142 -0
  14. package/src/locales/en/index.ts +20 -0
  15. package/src/locales/en/layout.ts +37 -0
  16. package/src/locales/en/legacy-basic.ts +54 -0
  17. package/src/locales/en/legacy-dynamic.ts +73 -0
  18. package/src/locales/en/legacy.ts +67 -0
  19. package/src/locales/en/motion.ts +33 -0
  20. package/src/locales/en/pattern-lib.ts +151 -0
  21. package/src/locales/en/patterns.ts +45 -0
  22. package/src/locales/en/shortcuts.ts +19 -0
  23. package/src/locales/en/v2.ts +177 -0
  24. package/src/locales/vi/attrs.ts +72 -0
  25. package/src/locales/vi/bindings.ts +26 -0
  26. package/src/locales/vi/block-desc.ts +53 -0
  27. package/src/locales/vi/block-titles.ts +43 -0
  28. package/src/locales/vi/blocks.ts +39 -0
  29. package/src/locales/vi/controls.ts +18 -0
  30. package/src/locales/vi/hints.ts +142 -0
  31. package/src/locales/vi/index.ts +24 -0
  32. package/src/locales/vi/layout.ts +37 -0
  33. package/src/locales/vi/legacy-basic.ts +54 -0
  34. package/src/locales/vi/legacy-dynamic.ts +73 -0
  35. package/src/locales/vi/legacy.ts +67 -0
  36. package/src/locales/vi/motion.ts +33 -0
  37. package/src/locales/vi/pattern-lib.ts +151 -0
  38. package/src/locales/vi/patterns.ts +45 -0
  39. package/src/locales/vi/shortcuts.ts +19 -0
  40. package/src/locales/vi/v2.ts +177 -0
  41. package/src/shared/animation-store.ts +38 -0
  42. package/src/shared/labels.ts +11 -134
  43. package/src/shared/patterns-kit.ts +7 -0
  44. package/src/shared/patterns-library.ts +152 -0
  45. package/src/shared/patterns.ts +6 -32
  46. package/src/v2/blocks/index.ts +5 -11
  47. package/src/v2/blocks/inline-style.ts +30 -0
  48. package/src/v2/blocks/layout.tsx +84 -14
  49. package/src/v2/blocks/media.tsx +21 -17
  50. package/src/v2/blocks/theme.tsx +43 -22
  51. package/src/v2/canvas/canvas.tsx +9 -1
  52. package/src/v2/core/bindings.ts +9 -8
  53. package/src/v2/core/model.ts +2 -2
  54. package/src/v2/editor.tsx +7 -4
  55. package/src/v2/i18n.ts +14 -0
  56. package/src/v2/index.ts +3 -1
  57. package/src/v2/labels.ts +11 -348
  58. package/src/v2/ui/attr-form.tsx +14 -29
  59. package/src/v2/ui/attr-hints.ts +87 -74
  60. package/src/v2/ui/bindings.tsx +10 -12
  61. package/src/v2/ui/block-descriptions.ts +6 -33
  62. package/src/v2/ui/inserter.tsx +2 -2
  63. package/src/v2/ui/inspector.tsx +7 -5
  64. package/src/v2/ui/layout-panel.tsx +3 -14
  65. package/src/v2/ui/motion-panel.tsx +99 -0
  66. package/src/v2/ui/options.tsx +6 -13
  67. package/src/v2/ui/style-controls.tsx +7 -6
  68. package/src/v2/ui/style-tab.tsx +9 -4
  69. package/src/v2/ui/unit-controls.tsx +6 -5
@@ -1,3 +1,4 @@
1
+ import { format, messages } from "../../i18n";
1
2
  import type { ChoiceKind } from "../core/host";
2
3
 
3
4
  /**
@@ -5,10 +6,13 @@ import type { ChoiceKind } from "../core/host";
5
6
  * "horizontal"), ô chọn lấy dữ liệu thật từ ứng dụng (vị trí menu, loại bài, chuyên mục…), thanh kéo, gợi ý,
6
7
  * và điều kiện hiện. Khoá: "khối.thuộc_tính" hoặc "*.thuộc_tính" (mọi khối).
7
8
  */
8
- export type Opt = [value: string | number, vi: string, en: string];
9
+ /** Giá trị của một lựa chọn; nhãn lấy từ src/locales/<ngôn ngữ>/hints.ts (khoá "khối.thuộc_tính.opt.<giá trị>"). */
10
+ export type Opt = string | number;
9
11
  export interface AttrHint {
10
- /** Nhãn riêng cho thuộc tính ở khối này (vi, en). */
11
- label?: [string, string];
12
+ /** Thuộc tính có nhãn riêng ở khối này (chữ: hints "<khoá>.label"). */
13
+ label?: true;
14
+ /** Khoá của hint (do hintOf điền) — dùng tra chữ. */
15
+ key?: string;
12
16
  control?: "select" | "segmented" | "range" | "choice" | "newTab" | "suggest" | "code" | "hidden";
13
17
  options?: Opt[];
14
18
  /** Ô chọn lấy dữ liệu từ ứng dụng (host.choices); tham số tính từ thuộc tính hiện tại. */
@@ -20,110 +24,119 @@ export interface AttrHint {
20
24
  unit?: string;
21
25
  /** Chỉ hiện khi điều kiện đúng (vd chuyên mục chỉ khi không "theo trang đang xem"). */
22
26
  when?: (attrs: Record<string, unknown>) => boolean;
23
- /** Ghi chú dưới ô. */
24
- help?: [string, string];
27
+ /** Có ghi chú dưới ô (chữ: hints "<khoá>.help"). */
28
+ help?: true;
25
29
  }
26
30
 
27
- const ALIGN: Opt[] = [["left", "Trái", "Left"], ["center", "Giữa", "Center"], ["right", "Phải", "Right"]];
28
- const V_ALIGN: Opt[] = [["top", "Trên", "Top"], ["center", "Giữa", "Middle"], ["bottom", "Dưới", "Bottom"]];
29
- const SIZES: Opt[] = [["small", "Nhỏ", "Small"], ["medium", "Vừa", "Medium"], ["large", "Lớn", "Large"]];
30
- const levels = (from: number, to: number, zero?: [string, string]): Opt[] => [
31
- ...(zero ? [[0, zero[0], zero[1]] as Opt] : []),
32
- ...Array.from({ length: to - from + 1 }, (_, i) => [from + i, `Tiêu đề ${from + i} (H${from + i})`, `Heading ${from + i} (H${from + i})`] as Opt),
31
+ const ALIGN: Opt[] = ["left", "center", "right"];
32
+ const V_ALIGN: Opt[] = ["top", "center", "bottom"];
33
+ const SIZES: Opt[] = ["small", "medium", "large"];
34
+ const levels = (from: number, to: number, zero?: boolean): Opt[] => [
35
+ ...(zero ? [0] : []),
36
+ ...Array.from({ length: to - from + 1 }, (_, i) => from + i),
33
37
  ];
34
38
  const notInherit = (a: Record<string, unknown>) => a.inherit === false;
35
39
 
36
40
  export const ATTR_HINTS: Record<string, AttrHint> = {
37
- "*.textAlign": { control: "segmented", options: [...ALIGN, ["justify", "Đều hai bên", "Justify"]] },
41
+ "*.textAlign": { control: "segmented", options: [...ALIGN, "justify"] },
38
42
  "*.mime": { control: "hidden" },
39
43
  "video.name": { control: "hidden" },
40
- "video.autoplay": { label: ["Tự phát (sẽ tắt tiếng)", "Autoplay (muted)"] },
41
- "video.loop": { label: ["Lặp lại", "Loop"] },
42
- "video.muted": { label: ["Tắt tiếng", "Muted"] },
43
- "video.controls": { label: ["Hiện thanh điều khiển", "Show controls"] },
44
- "video.playsInline": { label: ["Phát ngay trong trang (iPhone)", "Play inline (iPhone)"] },
45
- "video.preload": { control: "select", label: ["Tải trước", "Preload"], options: [["none", "Không", "None"], ["metadata", "Thông tin video", "Metadata"], ["auto", "Cả video", "All"]] },
46
- "audio.autoplay": { label: ["Tự phát", "Autoplay"] },
47
- "audio.loop": { label: ["Lặp lại", "Loop"] },
48
- "audio.preload": { control: "select", label: ["Tải trước", "Preload"], options: [["none", "Không", "None"], ["metadata", "Thông tin", "Metadata"], ["auto", "Cả tệp", "All"]] },
44
+ "video.autoplay": { label: true },
45
+ "video.loop": { label: true },
46
+ "video.muted": { label: true },
47
+ "video.controls": { label: true },
48
+ "video.playsInline": { label: true },
49
+ "video.preload": { control: "select", label: true, options: ["none", "metadata", "auto"] },
50
+ "audio.autoplay": { label: true },
51
+ "audio.loop": { label: true },
52
+ "audio.preload": { control: "select", label: true, options: ["none", "metadata", "auto"] },
49
53
  "file.size": { control: "hidden" },
50
- "file.name": { label: ["Tên hiển thị", "Display name"] },
51
- "file.src": { label: ["Tệp", "File"] },
52
- "video.src": { label: ["Địa chỉ video", "Video URL"] },
53
- "audio.src": { label: ["Địa chỉ âm thanh", "Audio URL"] },
54
- "youtube.src": { label: ["Đường dẫn YouTube", "YouTube link"] },
55
- "youtube.start": { label: ["Bắt đầu từ giây", "Start at second"] },
56
- "image.src": { label: ["Địa chỉ ảnh", "Image URL"] },
57
- "cover.src": { label: ["Ảnh nền", "Background image"] },
58
- "pullquote.citation": { label: ["Nguồn trích dẫn", "Citation"] },
54
+ "file.name": { label: true },
55
+ "file.src": { label: true },
56
+ "video.src": { label: true },
57
+ "audio.src": { label: true },
58
+ "youtube.src": { label: true },
59
+ "youtube.start": { label: true },
60
+ "image.src": { label: true },
61
+ "cover.src": { label: true },
62
+ "pullquote.citation": { label: true },
59
63
  "audio.name": { control: "hidden" },
60
- "heading.level": { control: "select", options: levels(1, 6), help: ["Tiêu đề trang / bài đã là H1 — trong nội dung nên bắt đầu từ H2 và không nhảy cấp (SEO).", "The page / post title is already the H1 — start content headings at H2 and don't skip levels (SEO)."] },
64
+ "heading.level": { control: "select", options: levels(1, 6), help: true },
61
65
  "postTitle.level": { control: "select", options: levels(1, 6) },
62
- "queryTitle.level": { control: "select", options: levels(1, 6), help: ["Trang lưu trữ / tìm kiếm chỉ nên có đúng một H1 — chính là khối này.", "Archive / search pages should have exactly one H1 — this block."] },
63
- "breadcrumbs.separator": { control: "segmented", options: [["›", "›", "›"], ["/", "/", "/"], ["»", "»", "»"], ["→", "→", "→"]] },
64
- "siteTitle.level": { control: "select", options: levels(1, 6, ["Đoạn văn (không phải tiêu đề)", "Paragraph (not a heading)"]) },
66
+ "queryTitle.level": { control: "select", options: levels(1, 6), help: true },
67
+ "breadcrumbs.separator": { control: "segmented", options: ["›", "/", "»", "→"] },
68
+ "siteTitle.level": { control: "select", options: levels(1, 6, true) },
65
69
  "tableOfContents.maxLevel": { control: "select", options: levels(2, 6) },
66
70
  "codeBlock.language": { control: "suggest", suggestions: ["plaintext", "html", "css", "javascript", "typescript", "jsx", "tsx", "json", "php", "python", "bash", "sql", "csharp", "java", "go", "rust", "yaml", "markdown", "xml"] },
67
71
  "customHtml.html": { control: "code" },
68
- "group.padding": { control: "segmented", options: [["none", "Không", "None"], ["small", "Nhỏ", "Small"], ["medium", "Vừa", "Medium"], ["large", "Lớn", "Large"]] },
72
+ "group.padding": { control: "segmented", options: ["none", "small", "medium", "large"] },
69
73
  "columns.verticalAlign": { control: "segmented", options: V_ALIGN },
70
74
  "mediaText.verticalAlign": { control: "segmented", options: V_ALIGN },
71
75
  "cover.contentAlign": { control: "segmented", options: V_ALIGN },
72
76
  "cover.opacity": { control: "range", min: 0, max: 100, step: 5, unit: "%" },
73
- "mediaText.position": { control: "segmented", options: [["left", "Ảnh bên trái", "Media left"], ["right", "Ảnh bên phải", "Media right"]] },
77
+ "mediaText.position": { control: "segmented", options: ["left", "right"] },
74
78
  "mediaText.width": { control: "range", min: 15, max: 85, step: 5, unit: "%" },
75
- "buttons.align": { control: "segmented", options: [...ALIGN, ["space-between", "Dàn đều", "Space between"]] },
76
- "button.variant": { control: "segmented", options: [["primary", "Chính", "Primary"], ["secondary", "Phụ", "Secondary"], ["outline", "Viền", "Outline"]] },
79
+ "buttons.align": { control: "segmented", options: [...ALIGN, "space-between"] },
80
+ "button.variant": { control: "segmented", options: ["primary", "secondary", "outline"] },
77
81
  "button.target": { control: "newTab" },
78
- "button.rel": { when: (a) => !!a.href, help: ["Vd: nofollow, sponsored (liên kết quảng cáo)", "e.g. nofollow, sponsored"] },
79
- "spacer.height": { control: "suggest", suggestions: ["xs", "sm", "md", "lg", "xl", "2xl", "2rem", "4rem", "80px"], help: ["Cỡ có sẵn của theme (xs → 2xl) hoặc độ dài (vd 3rem, 80px)", "Theme size (xs → 2xl) or a length (e.g. 3rem, 80px)"] },
80
- "callout.tone": { control: "segmented", options: [["info", "Thông tin", "Info"], ["success", "Thành công", "Success"], ["warning", "Cảnh báo", "Warning"], ["danger", "Nguy hiểm", "Danger"]] },
81
- "image.align": { control: "select", options: [...ALIGN, ["wide", "Rộng", "Wide"], ["full", "Tràn màn hình", "Full width"]] },
82
+ "button.rel": { when: (a) => !!a.href, help: true },
83
+ "spacer.height": { control: "suggest", suggestions: ["xs", "sm", "md", "lg", "xl", "2xl", "2rem", "4rem", "80px"], help: true },
84
+ "callout.tone": { control: "segmented", options: ["info", "success", "warning", "danger"] },
85
+ "image.align": { control: "select", options: [...ALIGN, "wide", "full"] },
82
86
  "image.size": { control: "choice", choice: { kind: "imageSize" } },
83
87
  "featuredImage.size": { control: "choice", choice: { kind: "imageSize" } },
84
- "featuredImage.aspect": { control: "select", options: [["auto", "Theo ảnh", "Original"], ["16/9", "16:9", "16:9"], ["4/3", "4:3", "4:3"], ["1/1", "Vuông 1:1", "Square 1:1"], ["3/4", "Dọc 3:4", "Portrait 3:4"]] },
88
+ "featuredImage.aspect": { control: "select", options: ["auto", "16/9", "4/3", "1/1", "3/4"] },
85
89
  "socialLinks.size": { control: "segmented", options: SIZES },
86
90
  "socialLinks.align": { control: "segmented", options: ALIGN },
87
- "navigation.location": { control: "choice", choice: { kind: "menuLocation" }, help: ["Menu gán cho vị trí này ở Giao diện › Menu", "The menu assigned to this location in Appearance › Menus"] },
88
- "navigation.orientation": { control: "segmented", options: [["horizontal", "Ngang", "Horizontal"], ["vertical", "Dọc", "Vertical"]] },
91
+ "navigation.location": { control: "choice", choice: { kind: "menuLocation" }, help: true },
92
+ "navigation.orientation": { control: "segmented", options: ["horizontal", "vertical"] },
93
+ "navigation.overlayMenu": { control: "segmented", options: ["never", "mobile", "always"] },
94
+ "languageSwitcher.display": { control: "segmented", options: ["inline", "dropdown"] },
95
+ "gallery.linkTo": { control: "segmented", options: ["none", "media"] },
89
96
  "postTerms.taxonomy": { control: "choice", choice: { kind: "taxonomy" } },
90
97
  "query.postType": { control: "choice", choice: { kind: "postType" }, when: notInherit },
91
98
  "query.category": { control: "choice", choice: { kind: "term", args: () => ({ taxonomy: "category" }) }, when: notInherit },
92
99
  "query.tag": { control: "choice", choice: { kind: "term", args: () => ({ taxonomy: "post_tag" }) }, when: notInherit },
93
100
  "query.perPage": { when: notInherit },
94
- "query.orderBy": { control: "select", options: [["date", "Ngày đăng", "Date"], ["modified", "Ngày sửa", "Modified"], ["title", "Tiêu đề", "Title"], ["comment_count", "Số bình luận", "Comments"], ["menu_order", "Thứ tự tự đặt", "Custom order"], ["rand", "Ngẫu nhiên", "Random"]], when: notInherit },
95
- "query.authorId": { label: ["Mã tác giả", "Author ID"], when: notInherit },
96
- "query.search": { label: ["Từ khoá", "Search keyword"], when: notInherit },
97
- "query.exclude": { label: ["Loại trừ bài (mã, cách nhau bằng dấu phẩy)", "Exclude posts (IDs, comma-separated)"], when: notInherit },
98
- "query.sticky": { control: "select", options: [["any", "Tất cả", "All"], ["only", "Chỉ bài ghim", "Sticky only"], ["exclude", "Bỏ bài ghim", "Hide sticky"]], when: notInherit },
99
- "image.href": { label: ["Liên kết khi bấm vào ảnh", "Link when clicked"] },
100
- "image.linkTarget": { control: "segmented", label: ["Mở liên kết", "Open link"], options: [["_self", "Cùng tab", "Same tab"], ["_blank", "Tab mới", "New tab"]] },
101
- "orderedList.reversed": { label: ["Đếm ngược", "Reversed"] },
102
- "blockquote.citation": { label: ["Nguồn trích dẫn", "Citation"] },
103
- "postDate.displayType": { control: "segmented", label: ["Hiện ngày", "Show date"], options: [["published", "Đăng", "Published"], ["modified", "Sửa lần cuối", "Last modified"]] },
104
- "query.paginate": { label: ["Phân trang (?qpage=)", "Paginate (?qpage=)"], help: ["Bật khi khối nằm trong trang thường; trang lưu trữ dùng \"Kế thừa\"", "Use on regular pages; archives use \"Inherit\""], when: notInherit },
105
- "query.orderByMeta": { label: ["Sắp xếp theo trường tuỳ biến", "Order by custom field"], help: ["Khoá phải khai báo filterable; thay cho \"Sắp xếp theo\"", "Key must be declared filterable; replaces \"Order by\""], when: notInherit },
106
- "query.order": { control: "segmented", options: [["desc", "Mới → cũ / Z → A", "Descending"], ["asc", "Cũ → mới / A → Z", "Ascending"]], when: notInherit },
107
- "query.inherit": { help: ["Trang danh mục / tìm kiếm / lưu trữ: hiện đúng bài của trang đó", "On archive / search pages, show that page's posts"] },
108
- "postTemplate.layout": { control: "segmented", options: [["list", "Danh sách", "List"], ["grid", "Lưới", "Grid"]] },
101
+ "query.orderBy": { control: "select", options: ["date", "modified", "title", "comment_count", "menu_order", "rand"], when: notInherit },
102
+ "query.authorId": { label: true, when: notInherit },
103
+ "query.search": { label: true, when: notInherit },
104
+ "query.exclude": { label: true, when: notInherit },
105
+ "query.sticky": { control: "select", options: ["any", "only", "exclude"], when: notInherit },
106
+ "image.href": { label: true },
107
+ "image.linkTarget": { control: "segmented", label: true, options: ["_self", "_blank"] },
108
+ "orderedList.reversed": { label: true },
109
+ "blockquote.citation": { label: true },
110
+ "postDate.displayType": { control: "segmented", label: true, options: ["published", "modified"] },
111
+ "query.paginate": { label: true, help: true, when: notInherit },
112
+ "query.orderByMeta": { label: true, help: true, when: notInherit },
113
+ "query.order": { control: "segmented", options: ["desc", "asc"], when: notInherit },
114
+ "query.inherit": { help: true },
115
+ "postTemplate.layout": { control: "segmented", options: ["list", "grid"] },
109
116
  "postTemplate.columns": { control: "range", min: 1, max: 6, step: 1, when: (a) => a.layout === "grid" },
110
117
  "templatePart.slug": { control: "choice", choice: { kind: "templatePart" } },
111
- "templatePart.tagName": { control: "select", options: [["div", "Khối thường (div)", "Generic (div)"], ["header", "Đầu trang (header)", "Header"], ["footer", "Chân trang (footer)", "Footer"], ["aside", "Cột phụ (aside)", "Aside"], ["section", "Mục (section)", "Section"]] },
118
+ "templatePart.tagName": { control: "select", options: ["div", "header", "footer", "aside", "section"] },
112
119
  };
113
120
 
114
- /** Nhãn mặc định của giá trị chọn khi chưa có trong ATTR_HINTS. */
115
- const VALUE_LABELS: Record<string, [string, string]> = {
116
- left: ["Trái", "Left"], center: ["Giữa", "Center"], right: ["Phải", "Right"], justify: ["Đều hai bên", "Justify"], top: ["Trên", "Top"], bottom: ["Dưới", "Bottom"],
117
- none: ["Không", "None"], small: ["Nhỏ", "Small"], medium: ["Vừa", "Medium"], large: ["Lớn", "Large"], wide: ["Rộng", "Wide"], full: ["Tràn màn hình", "Full width"],
118
- auto: ["Tự động", "Auto"], horizontal: ["Ngang", "Horizontal"], vertical: ["Dọc", "Vertical"], _self: ["Cùng tab", "Same tab"], _blank: ["Tab mới", "New tab"],
119
- };
121
+ export function hintOf(block: string, attr: string): AttrHint {
122
+ const key = ATTR_HINTS[`${block}.${attr}`] ? `${block}.${attr}` : ATTR_HINTS[`*.${attr}`] ? `*.${attr}` : "";
123
+ return { ...(key ? ATTR_HINTS[key] : {}), key };
124
+ }
125
+
126
+ const text = (v: unknown): string | undefined => (typeof v === "string" ? v : undefined);
127
+
128
+ /** Chữ nhãn / ghi chú của hint theo ngôn ngữ (undefined nếu hint không khai báo). */
129
+ export const hintText = (hint: AttrHint, part: "label" | "help", lang: string): string | undefined =>
130
+ hint[part] && hint.key ? text(messages("hints", lang)[`${hint.key}.${part}`]) : undefined;
120
131
 
121
- export const hintOf = (block: string, attr: string): AttrHint => ATTR_HINTS[`${block}.${attr}`] ?? ATTR_HINTS[`*.${attr}`] ?? {};
122
- export function optionLabel(hint: AttrHint, value: unknown, lang: "vi" | "en", fallback?: string): string {
123
- const o = hint.options?.find((x) => String(x[0]) === String(value));
124
- if (o) return lang === "vi" ? o[1] : o[2];
125
- return fallback ?? VALUE_LABELS[String(value)]?.[lang === "vi" ? 0 : 1] ?? String(value);
132
+ /** Nhãn của giá trị chọn: riêng của hint, rồi mẫu "Tiêu đề N", rồi nhãn chung của giá trị, cuối cùng là giá trị thô. */
133
+ export function optionLabel(hint: AttrHint, value: unknown, lang: string, fallback?: string): string {
134
+ const t = messages("hints", lang);
135
+ const v = String(value);
136
+ if (hint.options?.some((x) => String(x) === v)) return text(t[`${hint.key}.opt.${v}`]) ?? (typeof value === "number" && value > 0 ? format(text(t.levelOption) ?? v, { n: value }) : undefined) ?? text(t[`value.${v}`]) ?? v;
137
+ return fallback ?? text(t[`value.${v}`]) ?? v;
126
138
  }
127
139
 
128
- /** Cỡ ảnh mặc định khi ứng dụng không khai báo. */
129
- export const DEFAULT_IMAGE_SIZES: Opt[] = [["thumbnail", "Nhỏ (thumbnail)", "Thumbnail"], ["medium", "Vừa", "Medium"], ["large", "Lớn", "Large"], ["full", "Gốc", "Full size"]];
140
+ /** Cỡ ảnh mặc định khi ứng dụng không khai báo (nhãn: hints "imageSize.<cỡ>"). */
141
+ export const DEFAULT_IMAGE_SIZES: Opt[] = ["thumbnail", "medium", "large", "full"];
142
+ export const imageSizeLabel = (size: string, lang: string): string => text(messages("hints", lang)[`imageSize.${size}`]) ?? size;
@@ -1,6 +1,7 @@
1
1
  import { Database, Unlink } from "lucide-react";
2
2
  import { createElement, useEffect, useState, useSyncExternalStore, type CSSProperties } from "react";
3
- import { useDynamicData, useEditor } from "../context";
3
+ import { useDynamicData } from "../context";
4
+ import { useMsgs } from "../i18n";
4
5
  import { bindingSource, bindingSources, bindingsOf, subscribeBindingSources, type Binding } from "../core/bindings";
5
6
  import type { BNode } from "../core/model";
6
7
  import type { BlockProps } from "../core/registry";
@@ -29,13 +30,10 @@ export function useBindingPreview(block: BNode, attr: string): { bound: boolean;
29
30
 
30
31
  /** Mục "Gắn dữ liệu" của bảng cài đặt: mỗi thuộc tính gắn được một dòng chọn nguồn + trường. */
31
32
  export function BindingsPanel({ block, bindable, onChange }: { block: BNode; bindable: string[]; onChange(bindings: Record<string, Binding> | undefined): void }) {
32
- const { labels } = useEditor();
33
33
  const all = useSyncExternalStore(subscribeBindingSources, bindingSources, bindingSources);
34
34
  const current = bindingsOf(block) ?? {};
35
- const vi = labels.lang === "vi";
36
- const ATTR: Record<string, string> = vi
37
- ? { content: "Nội dung", src: "Ảnh", alt: "Mô tả ảnh", caption: "Chú thích", text: "Chữ trên nút", href: "Liên kết" }
38
- : { content: "Content", src: "Image", alt: "Alt text", caption: "Caption", text: "Button text", href: "Link" };
35
+ const t = useMsgs("bindings");
36
+ const ATTR: Record<string, string> = { content: t.attrContent, src: t.attrSrc, alt: t.attrAlt, caption: t.attrCaption, text: t.attrText, href: t.attrHref };
39
37
  const set = (attr: string, b: Binding | undefined) => {
40
38
  const next = { ...current };
41
39
  if (b) next[attr] = b; else delete next[attr];
@@ -43,8 +41,8 @@ export function BindingsPanel({ block, bindable, onChange }: { block: BNode; bin
43
41
  };
44
42
  return (
45
43
  <details className="ecx-advanced ecx-bindings" open={Object.keys(current).length > 0}>
46
- <summary><Database className="ecx-icon ecx-icon-sm" /> {vi ? "Gắn dữ liệu" : "Bind data"}</summary>
47
- <p className="ecx-muted">{vi ? "Lấy giá trị từ dữ liệu của website khi hiển thị (tiêu đề bài, trường meta, dữ liệu của plugin…) thay cho chữ gõ tay." : "Show a value from site data at render time (post title, meta field, plugin data…) instead of typed text."}</p>
44
+ <summary><Database className="ecx-icon ecx-icon-sm" /> {t.panelTitle}</summary>
45
+ <p className="ecx-muted">{t.panelHelp}</p>
48
46
  {bindable.map((attr) => {
49
47
  const b = current[attr];
50
48
  const src = b ? all.find((s) => s.name === b.source) : undefined;
@@ -54,16 +52,16 @@ export function BindingsPanel({ block, bindable, onChange }: { block: BNode; bin
54
52
  <div key={attr} className="ecx-binding-row" data-binding={attr}>
55
53
  <span className="ecx-field-label">{ATTR[attr] ?? attr}</span>
56
54
  <div className="ecx-color-row">
57
- <select className="ecx-input" aria-label={`${ATTR[attr] ?? attr}: ${vi ? "nguồn" : "source"}`} value={b?.source ?? ""}
55
+ <select className="ecx-input" aria-label={`${ATTR[attr] ?? attr}: ${t.source}`} value={b?.source ?? ""}
58
56
  onChange={(e) => { const s = all.find((x) => x.name === e.target.value); set(attr, s ? { source: s.name, args: s.fields?.length ? { [s.argKey ?? "field"]: s.fields[0].value } : {} } : undefined); }}>
59
- <option value="">{vi ? "— Không gắn —" : "— Not bound —"}</option>
57
+ <option value="">{t.notBound}</option>
60
58
  {options.map((s) => <option key={s.name} value={s.name}>{s.label}</option>)}
61
59
  {b && !src && <option value={b.source}>{b.source}</option>}
62
60
  </select>
63
- {b && <button type="button" className="ecx-tool" aria-label={vi ? "Bỏ gắn" : "Unbind"} title={vi ? "Bỏ gắn" : "Unbind"} onClick={() => set(attr, undefined)}><Unlink className="ecx-icon" /></button>}
61
+ {b && <button type="button" className="ecx-tool" aria-label={t.unbind} title={t.unbind} onClick={() => set(attr, undefined)}><Unlink className="ecx-icon" /></button>}
64
62
  </div>
65
63
  {b && (src?.fields?.length
66
- ? <select className="ecx-input" aria-label={`${ATTR[attr] ?? attr}: ${vi ? "trường" : "field"}`} value={String(b.args?.[argKey] ?? "")} onChange={(e) => set(attr, { ...b, args: { ...b.args, [argKey]: e.target.value } })}>
64
+ ? <select className="ecx-input" aria-label={`${ATTR[attr] ?? attr}: ${t.field}`} value={String(b.args?.[argKey] ?? "")} onChange={(e) => set(attr, { ...b, args: { ...b.args, [argKey]: e.target.value } })}>
67
65
  {src.fields.map((f) => <option key={f.value} value={f.value}>{f.label}</option>)}
68
66
  </select>
69
67
  : <input className="ecx-input" aria-label={`${ATTR[attr] ?? attr}: ${argKey}`} placeholder={argKey} value={String(b.args?.[argKey] ?? "")}
@@ -1,34 +1,7 @@
1
- /** Mô tả ngắn của khối lõi (thẻ xem trước khi rê chuột trong thư viện khối). */
2
- const D: Record<string, [string, string]> = {
3
- paragraph: ["Đoạn chữ thường — nền tảng của mọi nội dung.", "Start with the basic building block of all narrative."],
4
- heading: ["Tiêu đề mục (H2–H6), giúp người đọc và Google hiểu cấu trúc trang.", "Introduce sections and organise content for readers and search engines."],
5
- bulletList: ["Danh sách gạch đầu dòng.", "A bulleted list."], orderedList: ["Danh sách đánh số theo thứ tự.", "A numbered list."],
6
- taskList: ["Danh sách việc có ô đánh dấu.", "A checklist."], blockquote: ["Trích dẫn lời của ai đó.", "Give quoted text visual emphasis."],
7
- codeBlock: ["Hiện mã nguồn, giữ nguyên khoảng trắng.", "Display code snippets that respect spacing."], preformatted: ["Chữ giữ nguyên khoảng trắng và xuống dòng.", "Text that respects spacing and tabs."],
8
- pullquote: ["Trích dẫn nổi bật, chữ lớn ở giữa trang.", "A large, eye-catching quote."], details: ["Nội dung ẩn, bấm để mở (câu hỏi thường gặp…).", "Hide content until the visitor opens it (FAQ…)."],
9
- table: ["Bảng dữ liệu hàng / cột, gộp ô được.", "Rows and columns of data; cells can be merged."],
10
- image: ["Ảnh có chú thích, alt cho SEO, đổi cỡ bằng tay kéo.", "An image with caption and alt text; drag to resize."],
11
- gallery: ["Nhiều ảnh xếp lưới.", "Several images in a grid."], cover: ["Ảnh hoặc màu nền lớn với chữ đè lên — phần mở đầu trang.", "A large image or colour with text on top — a page hero."],
12
- mediaText: ["Ảnh và chữ đặt cạnh nhau để bố cục hấp dẫn hơn.", "Media and text side by side for a richer layout."],
13
- video: ["Video tải lên hoặc từ địa chỉ.", "An uploaded or linked video."], audio: ["Tệp âm thanh có trình phát.", "An audio player."],
14
- file: ["Liên kết tải tệp (PDF…), có thể xem ngay trên trang.", "A downloadable file (PDF…), optionally embedded."],
15
- youtube: ["Nhúng video YouTube.", "Embed a YouTube video."], embed: ["Nhúng nội dung từ địa chỉ (Facebook, TikTok, bản đồ…).", "Embed content from a URL."],
16
- group: ["Gom nhiều khối vào một khung để tô nền, căn lề, bố cục chung.", "Gather blocks in a container to style them together."],
17
- columns: ["Chia nội dung thành nhiều cột, kéo để đổi độ rộng.", "Display content in columns; drag to resize."],
18
- buttons: ["Một hoặc nhiều nút kêu gọi hành động.", "Prompt visitors to take action with buttons."], spacer: ["Khoảng trống giữa các khối.", "Add white space between blocks."],
19
- horizontalRule: ["Đường kẻ ngăn cách các phần.", "Separate sections with a line."], callout: ["Hộp lưu ý / cảnh báo nổi bật.", "Highlight a tip or warning."],
20
- customHtml: ["Chèn HTML tự viết (đã được làm sạch).", "Add custom (sanitised) HTML."], socialLinks: ["Biểu tượng liên kết mạng xã hội.", "Icons linking to social profiles."],
21
- tableOfContents: ["Mục lục tự sinh từ các tiêu đề trong bài.", "An automatic table of contents from headings."],
22
- siteTitle: ["Tên website (lấy từ Cài đặt).", "The site title from Settings."], siteLogo: ["Logo của website.", "The site logo."], siteTagline: ["Khẩu hiệu của website.", "The site tagline."],
23
- navigation: ["Menu điều hướng theo vị trí của theme.", "A navigation menu for a theme location."], search: ["Ô tìm kiếm.", "A search form."],
24
- languageSwitcher: ["Chuyển ngôn ngữ của website.", "Switch the site language."], copyright: ["Dòng bản quyền với năm hiện tại.", "A copyright line with the current year."],
25
- postTitle: ["Tiêu đề của bài đang xem.", "The current post's title."], postContent: ["Nội dung của bài đang xem.", "The current post's content."],
26
- postExcerpt: ["Tóm tắt của bài.", "The post excerpt."], featuredImage: ["Ảnh đại diện của bài.", "The post's featured image."], postDate: ["Ngày đăng bài.", "The publish date."],
27
- postAuthor: ["Tác giả bài viết.", "The post author."], postTerms: ["Chuyên mục / thẻ của bài.", "The post's categories or tags."], comments: ["Bình luận của bài.", "The post comments."],
28
- queryTitle: ["Tiêu đề (H1) của trang chuyên mục, thẻ, tác giả, kết quả tìm kiếm.", "The H1 of category, tag, author and search pages."],
29
- termDescription: ["Mô tả của chuyên mục / thẻ đang xem.", "The current category / tag description."],
30
- breadcrumbs: ["Đường dẫn Trang chủ › Chuyên mục › Bài, kèm dữ liệu cấu trúc cho Google.", "Home › Category › Post trail with structured data for Google."],
31
- postNavigation: ["Liên kết tới bài trước và bài sau.", "Links to the previous and next posts."],
32
- query: ["Danh sách bài theo điều kiện (chuyên mục, số bài, sắp xếp).", "A list of posts by criteria."], templatePart: ["Phần dùng chung (header, footer…) — sửa một nơi, đổi mọi trang.", "A shared part (header, footer…) — edit once, update everywhere."],
1
+ import { messages } from "../../i18n";
2
+
3
+ /** Mô tả ngắn của khối lõi (thẻ xem trước khi rê chuột trong thư viện khối). Chữ nằm ở src/locales/<ngôn ngữ>/blockDesc.ts, khoá = tên khối. */
4
+ export const blockDescription = (type: string, lang: string): string | undefined => {
5
+ const d = messages("blockDesc", lang)[type];
6
+ return typeof d === "string" ? d : undefined;
33
7
  };
34
- export const blockDescription = (type: string, lang: "vi" | "en") => D[type]?.[lang === "vi" ? 0 : 1];
@@ -10,7 +10,7 @@ import { startDragNew } from "../canvas/dnd";
10
10
  import { usePrefs } from "../prefs";
11
11
  import { onPatternsChange, patternBlocks, registeredPatterns, type Pattern } from "../core/patterns";
12
12
  import { useSyncExternalStore } from "react";
13
- import { enLabels, viLabels } from "../../shared/labels";
13
+ import { labelsLegacy } from "../../shared/labels";
14
14
 
15
15
  export interface InsertOption {
16
16
  key: string;
@@ -269,7 +269,7 @@ function PatternList({ query, onInserted }: { query: string; onInserted?(): void
269
269
  const q = norm(query.trim());
270
270
  const list = q ? all.filter((p) => norm(`${p.title} ${p.keywords ?? ""} ${p.category}`).includes(q)) : all;
271
271
  const cats = [...new Set(list.map((p) => p.category))];
272
- const v1 = labels.lang === "vi" ? viLabels : enLabels;
272
+ const v1 = labelsLegacy(labels.lang);
273
273
  const catName = (c: string) => String((v1 as Record<string, unknown>)[`cat_${c}`] ?? c);
274
274
  const insert = (p: Pattern) => {
275
275
  const nodes = patternBlocks(p);
@@ -5,13 +5,15 @@ import { useState, useSyncExternalStore } from "react";
5
5
  import { blockPanelsFor, onBlockPanelsChange } from "../../shared/panel-store";
6
6
  import { useEditor, useEditorState } from "../context";
7
7
  import type { BNode } from "../core/model";
8
- import { ATTR_LABELS, AttrForm, Field, cx } from "./attr-form";
8
+ import { AttrForm, Field, attrName, cx } from "./attr-form";
9
9
  import { BindingsPanel, CORE_BINDABLE } from "./bindings";
10
10
  import { StyleTab } from "./style-tab";
11
+ import { useMsgs } from "../i18n";
11
12
 
12
13
  /** Bảng cài đặt của khối đang chọn: thẻ khối, tab Cài đặt (form + phần riêng của khối), tab Kiểu dáng. */
13
14
  export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<{ name: string; label: string }>> }) {
14
15
  const { store, registry, labels } = useEditor();
16
+ const t = useMsgs("controls");
15
17
  const sel = useEditorState((s) => s.selection);
16
18
  useEditorState((s) => s.revision);
17
19
  const [tab, setTab] = useState<"settings" | "style">("settings");
@@ -38,7 +40,7 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
38
40
  <>
39
41
  <div className="ecx-tabs" role="tablist">
40
42
  <button type="button" role="tab" aria-selected={tab === "settings"} className={cx(tab === "settings" && "is-active")} onClick={() => setTab("settings")}>{labels.settings}</button>
41
- {type?.supports?.style !== false && !store.isContentOnly(first.id) && <button type="button" role="tab" aria-selected={tab === "style"} className={cx(tab === "style" && "is-active")} onClick={() => setTab("style")}>{labels.lang === "vi" ? "Kiểu dáng" : "Styles"}</button>}
43
+ {type?.supports?.style !== false && !store.isContentOnly(first.id) && <button type="button" role="tab" aria-selected={tab === "style"} className={cx(tab === "style" && "is-active")} onClick={() => setTab("style")}>{t.styles}</button>}
42
44
  </div>
43
45
  {tab === "settings" ? (
44
46
  <div className="ecx-panel">
@@ -48,9 +50,9 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
48
50
  {nodes.length === 1 && bindable?.length && <BindingsPanel block={first} bindable={bindable} onChange={(b) => setAttrs({ bindings: b })} />}
49
51
  {nodes.length === 1 && (
50
52
  <details className="ecx-advanced">
51
- <summary>{labels.lang === "vi" ? "Nâng cao" : "Advanced"}</summary>
52
- <Field label={ATTR_LABELS.anchor[labels.lang === "vi" ? 0 : 1]}><input className="ecx-input" value={String(first.attrs.anchor ?? "")} onChange={(e) => setAttrs({ anchor: e.target.value.replace(/[^\w-]/g, "") || undefined })} /></Field>
53
- <Field label={ATTR_LABELS.className[labels.lang === "vi" ? 0 : 1]}><input className="ecx-input" value={String(first.attrs.className ?? "")} onChange={(e) => setAttrs({ className: e.target.value || undefined })} /></Field>
53
+ <summary>{t.advanced}</summary>
54
+ <Field label={attrName("anchor", labels.lang) ?? "anchor"}><input className="ecx-input" value={String(first.attrs.anchor ?? "")} onChange={(e) => setAttrs({ anchor: e.target.value.replace(/[^\w-]/g, "") || undefined })} /></Field>
55
+ <Field label={attrName("className", labels.lang) ?? "className"}><input className="ecx-input" value={String(first.attrs.className ?? "")} onChange={(e) => setAttrs({ className: e.target.value || undefined })} /></Field>
54
56
  </details>
55
57
  )}
56
58
  </div>
@@ -2,6 +2,7 @@ import { normalizeGradient, normalizeStyle, type BlockLayout, type BlockStyle, t
2
2
  import { AlignCenterVertical, AlignEndVertical, AlignStartVertical, ArrowDown, ArrowRight, Columns3, LayoutGrid, Rows3, Square, StretchVertical, AlignHorizontalSpaceBetween, AlignHorizontalJustifyCenter, AlignHorizontalJustifyEnd, AlignHorizontalJustifyStart } from "lucide-react";
3
3
  import { useState } from "react";
4
4
  import { useEditor } from "../context";
5
+ import { useMsgs } from "../i18n";
5
6
  import { ColorInput } from "./color-field";
6
7
  import { Row, Section, Seg, cx } from "./style-controls";
7
8
 
@@ -9,18 +10,6 @@ import { Row, Section, Seg, cx } from "./style-controls";
9
10
  * Bố cục, nền chuyển màu, bóng, tỉ lệ, ghim và hover (@ecomcx/ecomweb-content 1.15) — phần thêm của tab Kiểu dáng.
10
11
  * Giá trị theo khổ (hướng, căn, số cột) sửa theo khổ đang chọn ở bảng Kiểu dáng (`device`).
11
12
  */
12
- const V = { vi: {
13
- layout: "Bố cục", type: "Kiểu", flow: "Nhóm", row: "Hàng ngang", stack: "Xếp dọc", grid: "Lưới", direction: "Hướng", justify: "Căn ngang", align: "Căn dọc",
14
- wrap: "Cho xuống dòng", columns: "Số cột", auto: "Tự chia", minWidth: "Rộng tối thiểu mỗi cột", effects: "Nền & hiệu ứng", gradient: "Nền chuyển màu",
15
- angle: "Góc", from: "Từ", to: "Đến", none: "Không", shadow: "Đổ bóng", ratio: "Tỉ lệ khung", sticky: "Ghim khi cuộn", top: "Cách mép trên",
16
- hover: "Khi rê chuột", text: "Màu chữ", background: "Màu nền", border: "Màu viền", lift: "Nhấc lên", start: "Đầu", center: "Giữa", end: "Cuối", between: "Dàn đều", stretch: "Kéo giãn",
17
- }, en: {
18
- layout: "Layout", type: "Type", flow: "Group", row: "Row", stack: "Stack", grid: "Grid", direction: "Direction", justify: "Justify", align: "Align",
19
- wrap: "Allow wrapping", columns: "Columns", auto: "Auto", minWidth: "Minimum column width", effects: "Background & effects", gradient: "Gradient",
20
- angle: "Angle", from: "From", to: "To", none: "None", shadow: "Shadow", ratio: "Aspect ratio", sticky: "Sticky", top: "Top offset",
21
- hover: "Hover", text: "Text color", background: "Background", border: "Border color", lift: "Lift", start: "Start", center: "Center", end: "End", between: "Space between", stretch: "Stretch",
22
- } };
23
-
24
13
  /** Khối chứa (có khối con) mới có mục Bố cục. */
25
14
  const CONTAINERS = new Set(["group", "column", "cover", "blockquote", "callout", "details", "query", "postTemplate", "mediaText"]);
26
15
 
@@ -34,7 +23,7 @@ export function layoutFor(kind: Kind, prev?: BlockLayout): BlockLayout | undefin
34
23
 
35
24
  export function LayoutEffectsPanel({ type, style: raw, onChange, device }: { type: string; style: unknown; onChange(style: BlockStyle | null): void; device: Device }) {
36
25
  const { labels, host } = useEditor();
37
- const t = V[labels.lang];
26
+ const t = useMsgs("layout");
38
27
  const style: BlockStyle = normalizeStyle(raw) ?? {};
39
28
  const set = (patch: Partial<BlockStyle>) => {
40
29
  const next = { ...style, ...patch } as Record<string, unknown>;
@@ -111,7 +100,7 @@ export function LayoutEffectsPanel({ type, style: raw, onChange, device }: { typ
111
100
  <button key={name} type="button" className={cx("ecx-chip ecx-chip-swatch", style.gradient === name && "is-active")} title={name} aria-label={name}
112
101
  style={{ background: host.presets!.gradients![name] }} onClick={() => set({ gradient: name })} />
113
102
  ))}
114
- <button type="button" className={cx("ecx-chip ecx-chip-swatch", g && "is-active")} title={labels.lang === "vi" ? "Tuỳ chỉnh" : "Custom"}
103
+ <button type="button" className={cx("ecx-chip ecx-chip-swatch", g && "is-active")} title={t.custom}
115
104
  style={{ background: `linear-gradient(${angle}deg, ${c1}, ${c2})` }} onClick={() => applyCustom()} />
116
105
  </div>
117
106
  {g && (
@@ -0,0 +1,99 @@
1
+ import { MOTION_HOVER, MOTION_IN, normalizeStyle, type BlockStyle } from "@ecomcx/ecomweb-content";
2
+ import { Play } from "lucide-react";
3
+ import { useSyncExternalStore } from "react";
4
+ import { onAnimationsChange, pluginAnimations } from "../../shared/animation-store";
5
+ import { useEditor, useEditorState } from "../context";
6
+ import { useMsgs } from "../i18n";
7
+ import { Row, Section, Seg, cx } from "./style-controls";
8
+
9
+ /**
10
+ * Mục "Chuyển động" của tab Kiểu dáng (attrs.style.motion, @ecomcx/ecomweb-content 1.16): hiệu ứng khi cuộn tới và khi rê chuột,
11
+ * chọn bằng một cú bấm. Hiệu ứng lõi hiện thành chip; hiệu ứng của plugin (registerAnimation) nằm trong danh sách "Hiệu ứng khác".
12
+ * Chọn xong tự chạy thử ngay trong khung soạn; nút "Xem thử" chạy lại. Khung soạn không bao giờ ẩn khối (chỉ website mới ẩn trước khi cuộn tới).
13
+ */
14
+ type Motion = NonNullable<BlockStyle["motion"]>;
15
+
16
+
17
+ const DELAYS = [0, 100, 200, 300, 500, 800, 1200];
18
+ const DURATION_MS = { fast: 300, normal: 600, slow: 1000 } as const;
19
+
20
+ /** Chạy lại hiệu ứng cuộn của một khối trong khung soạn: gỡ rồi đặt lại `is-in` (CSS của khối gắn animation vào `.is-in`). */
21
+ export function previewMotion(el: HTMLElement | null, m: Motion | undefined) {
22
+ if (!el || !m?.in) return;
23
+ el.classList.remove("is-in");
24
+ void el.offsetWidth; // đo lại để trình duyệt khởi động lại animation
25
+ el.classList.add("is-in");
26
+ const total = DURATION_MS[m.duration ?? "normal"] + (m.delay ?? 0) + (m.stagger ? 12 * 80 : 0) + 100;
27
+ window.setTimeout(() => el.classList.remove("is-in"), total);
28
+ }
29
+
30
+ export function MotionPanel({ type, style: raw, onChange }: { type: string; style: unknown; onChange(style: BlockStyle | null): void }) {
31
+ const { labels, registry, ui } = useEditor();
32
+ const t = useMsgs("motion");
33
+ const plugin = useSyncExternalStore(onAnimationsChange, pluginAnimations, pluginAnimations);
34
+ const sel = useEditorState((s) => s.selection);
35
+ const blockId = sel.ids[0] ?? sel.editing;
36
+ const style: BlockStyle = normalizeStyle(raw) ?? {};
37
+ const m: Motion = style.motion ?? {};
38
+ const container = registry.get(type)?.kind === "container";
39
+
40
+ const set = (patch: Partial<Motion>, preview = false) => {
41
+ const next: Record<string, unknown> = { ...m, ...patch };
42
+ for (const k of Object.keys(next)) if (next[k] === undefined || next[k] === false) delete next[k];
43
+ const merged = normalizeStyle({ ...style, motion: Object.keys(next).length ? next : undefined }) ?? null;
44
+ onChange(merged);
45
+ // Chờ khung soạn nhận CSS mới của khối rồi mới chạy thử
46
+ if (preview) window.setTimeout(() => previewMotion(blockId ? ui.blockEl(blockId) : null, merged?.motion), 120);
47
+ };
48
+
49
+ const coreIn = MOTION_IN as readonly string[];
50
+ const isPlugin = !!m.in && !coreIn.includes(m.in);
51
+ const groups = new Map<string, typeof plugin>();
52
+ for (const e of plugin) groups.set(e.group ?? t.plugin, [...(groups.get(e.group ?? t.plugin) ?? []), e]);
53
+
54
+ return (
55
+ <Section title={t.title} defaultOpen={!!style.motion} modified={!!style.motion} onReset={() => onChange(normalizeStyle({ ...style, motion: undefined }) ?? null)}>
56
+ <Row label={t.scroll}>
57
+ <div className="ecx-chip-row" role="radiogroup" aria-label={t.scroll}>
58
+ <button type="button" role="radio" aria-checked={!m.in} className={cx("ecx-chip", !m.in && "is-active")} onClick={() => set({ in: undefined, duration: undefined, delay: undefined, repeat: undefined, stagger: undefined })}>{t.none}</button>
59
+ {MOTION_IN.map((id) => (
60
+ <button key={id} type="button" role="radio" aria-checked={m.in === id} className={cx("ecx-chip", m.in === id && "is-active")} onClick={() => set({ in: id }, true)}>{t.in[id]}</button>
61
+ ))}
62
+ </div>
63
+ {plugin.length > 0 && (
64
+ <select className="ecx-input" aria-label={t.more} value={isPlugin ? m.in : ""} onChange={(e) => e.target.value && set({ in: e.target.value }, true)}>
65
+ <option value="">{t.more}…</option>
66
+ {[...groups].map(([g, list]) => <optgroup key={g} label={g}>{list.map((e) => <option key={e.id} value={e.id}>{e.label}</option>)}</optgroup>)}
67
+ </select>
68
+ )}
69
+ {isPlugin && !plugin.some((e) => e.id === m.in) && <p className="ecx-muted">{m.in}</p>}
70
+ </Row>
71
+
72
+ {m.in && (
73
+ <>
74
+ <Row label={t.speed}>
75
+ <Seg label={t.speed} value={m.duration ?? "normal"} onChange={(v) => set({ duration: !v || v === "normal" ? undefined : v }, true)}
76
+ options={[["fast", t.fast, t.fast], ["normal", t.normal, t.normal], ["slow", t.slow, t.slow]]} />
77
+ </Row>
78
+ <Row label={t.delay}>
79
+ <select className="ecx-input" aria-label={t.delay} value={m.delay ?? 0} onChange={(e) => set({ delay: Number(e.target.value) || undefined }, true)}>
80
+ {[...new Set([...DELAYS, m.delay ?? 0])].sort((a, b) => a - b).map((d) => <option key={d} value={d}>{d} ms</option>)}
81
+ </select>
82
+ </Row>
83
+ {container && <label className="ecx-check"><input type="checkbox" checked={!!m.stagger} onChange={(e) => set({ stagger: e.target.checked || undefined }, true)} /> {t.stagger}</label>}
84
+ <label className="ecx-check"><input type="checkbox" checked={!!m.repeat} onChange={(e) => set({ repeat: e.target.checked || undefined })} /> {t.repeat}</label>
85
+ <button type="button" className="ecx-link-btn" onClick={() => previewMotion(blockId ? ui.blockEl(blockId) : null, m)}><Play className="ecx-icon ecx-icon-sm" aria-hidden /> {t.preview}</button>
86
+ </>
87
+ )}
88
+
89
+ <Row label={t.hover}>
90
+ <div className="ecx-chip-row" role="radiogroup" aria-label={t.hover}>
91
+ <button type="button" role="radio" aria-checked={!m.hover} className={cx("ecx-chip", !m.hover && "is-active")} onClick={() => set({ hover: undefined })}>{t.none}</button>
92
+ {MOTION_HOVER.map((id) => (
93
+ <button key={id} type="button" role="radio" aria-checked={m.hover === id} className={cx("ecx-chip", m.hover === id && "is-active")} onClick={() => set({ hover: id })}>{t.hv[id]}</button>
94
+ ))}
95
+ </div>
96
+ </Row>
97
+ </Section>
98
+ );
99
+ }
@@ -3,6 +3,7 @@ import { Check, ChevronRight, Code2, Copy, Keyboard, MoreVertical, SlidersHorizo
3
3
  import { useEffect, useMemo, useRef, useState, type ReactNode } from "react";
4
4
  import { serializeBlocks } from "../core/clipboard";
5
5
  import { useEditor, useEditorState } from "../context";
6
+ import { useMsgs } from "../i18n";
6
7
  import { blocksFromDoc, type BNode } from "../core/model";
7
8
  import { usePrefs, type EditorPrefs } from "../prefs";
8
9
  import { blockLabel } from "./list-view";
@@ -169,19 +170,11 @@ export function PreferencesModal({ onClose }: { onClose(): void }) {
169
170
  /** Bảng phím tắt. */
170
171
  export function ShortcutsModal({ onClose }: { onClose(): void }) {
171
172
  const { labels } = useEditor();
172
- const vi = labels.lang === "vi";
173
- const rows: Array<[string, string]> = vi ? [
174
- [`${MOD}+Z / ${MOD}+⇧+Z`, "Hoàn tác / làm lại (xuyên header, footer)"], [`${MOD}+S`, "Lưu mọi phần đã đổi"], ["/", "Chèn khối (gõ ở đoạn trống)"],
175
- ["Enter / ⇧+Enter", "Tách khối / xuống dòng trong khối"], ["Tab / ⇧+Tab", "Lồng / đưa mục danh sách ra"], ["Esc", "Chọn cả khối"],
176
- [`${MOD}+A ×2`, "Chọn mọi khối"], [`${MOD}+⇧+D`, "Nhân bản khối"], ["⇧+⌥+Z", "Xoá khối"], [`${MOD}+⌥+T / Y`, "Thêm khối phía trên / dưới"],
177
- [`${MOD}+⇧+⌥+T / Y`, "Đưa khối lên / xuống"], ["Alt+F10", "Lên thanh công cụ của khối"], [`${MOD}+B / I / U`, "Đậm / nghiêng / gạch chân"],
178
- [`${MOD}+K`, "Liên kết"], [`${MOD}+E`, "Mã trong dòng"], ["## · - · 1. · > · ``` · ---", "Gõ tắt: tiêu đề, danh sách, trích dẫn, mã, đường kẻ"],
179
- ] : [
180
- [`${MOD}+Z / ${MOD}+⇧+Z`, "Undo / redo (across header and footer)"], [`${MOD}+S`, "Save every changed part"], ["/", "Insert a block (in an empty paragraph)"],
181
- ["Enter / ⇧+Enter", "Split block / line break"], ["Tab / ⇧+Tab", "Indent / outdent list item"], ["Esc", "Select the whole block"],
182
- [`${MOD}+A ×2`, "Select all blocks"], [`${MOD}+⇧+D`, "Duplicate"], ["⇧+⌥+Z", "Delete block"], [`${MOD}+⌥+T / Y`, "Insert before / after"],
183
- [`${MOD}+⇧+⌥+T / Y`, "Move up / down"], ["Alt+F10", "Go to the block toolbar"], [`${MOD}+B / I / U`, "Bold / italic / underline"],
184
- [`${MOD}+K`, "Link"], [`${MOD}+E`, "Inline code"], ["## · - · 1. · > · ``` · ---", "Shortcuts: heading, list, quote, code, separator"],
173
+ const t = useMsgs("shortcuts");
174
+ const rows: Array<[string, string]> = [
175
+ [`${MOD}+Z / ${MOD}+⇧+Z`, t.undo], [`${MOD}+S`, t.save], ["/", t.insert], ["Enter / ⇧+Enter", t.split], ["Tab / ⇧+Tab", t.indent], ["Esc", t.esc],
176
+ [`${MOD}+A ×2`, t.selectAll], [`${MOD}+⇧+D`, t.duplicate], ["⇧+⌥+Z", t.remove], [`${MOD}+⌥+T / Y`, t.around], [`${MOD}+⇧+⌥+T / Y`, t.move],
177
+ ["Alt+F10", t.toolbar], [`${MOD}+B / I / U`, t.marks], [`${MOD}+K`, t.link], [`${MOD}+E`, t.code], ["## · - · 1. · > · ``` · ---", t.markdown],
185
178
  ];
186
179
  return (
187
180
  <Modal title={labels.shortcuts} onClose={onClose}>