@ecomcx/ecomweb-editor 1.30.0 → 1.32.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 (95) hide show
  1. package/package.json +3 -3
  2. package/src/locales/en/attrs.ts +10 -0
  3. package/src/locales/en/background.ts +17 -0
  4. package/src/locales/en/block-desc.ts +1 -0
  5. package/src/locales/en/block-style.ts +7 -4
  6. package/src/locales/en/block-titles.ts +1 -0
  7. package/src/locales/en/blocks.ts +10 -2
  8. package/src/locales/en/columns.ts +12 -0
  9. package/src/locales/en/controls.ts +21 -0
  10. package/src/locales/en/hints.ts +215 -1
  11. package/src/locales/en/index.ts +6 -2
  12. package/src/locales/en/layout.ts +32 -0
  13. package/src/locales/en/legacy.ts +1 -1
  14. package/src/locales/en/library.ts +38 -0
  15. package/src/locales/en/parts.ts +12 -0
  16. package/src/locales/en/placeholders.ts +104 -0
  17. package/src/locales/en/presets.ts +6 -0
  18. package/src/locales/en/v2.ts +21 -0
  19. package/src/locales/vi/attrs.ts +10 -0
  20. package/src/locales/vi/background.ts +17 -0
  21. package/src/locales/vi/block-desc.ts +1 -0
  22. package/src/locales/vi/block-style.ts +7 -4
  23. package/src/locales/vi/block-titles.ts +1 -0
  24. package/src/locales/vi/blocks.ts +10 -2
  25. package/src/locales/vi/columns.ts +12 -0
  26. package/src/locales/vi/controls.ts +21 -0
  27. package/src/locales/vi/hints.ts +216 -2
  28. package/src/locales/vi/index.ts +6 -2
  29. package/src/locales/vi/layout.ts +32 -0
  30. package/src/locales/vi/legacy.ts +1 -1
  31. package/src/locales/vi/library.ts +38 -0
  32. package/src/locales/vi/parts.ts +12 -0
  33. package/src/locales/vi/placeholders.ts +103 -0
  34. package/src/locales/vi/presets.ts +6 -0
  35. package/src/locales/vi/v2.ts +21 -0
  36. package/src/shared/panel-store.ts +3 -3
  37. package/src/shared/patterns.ts +3 -52
  38. package/src/shared/style-panel.tsx +2 -2
  39. package/src/shared/types.ts +2 -0
  40. package/src/v2/blocks/columns-inspector.tsx +210 -0
  41. package/src/v2/blocks/compat.tsx +91 -5
  42. package/src/v2/blocks/form.tsx +7 -4
  43. package/src/v2/blocks/index.ts +10 -4
  44. package/src/v2/blocks/inline-style.ts +1 -1
  45. package/src/v2/blocks/layout.tsx +305 -83
  46. package/src/v2/blocks/media.tsx +91 -81
  47. package/src/v2/blocks/resize.tsx +172 -4
  48. package/src/v2/blocks/text.tsx +60 -22
  49. package/src/v2/blocks/theme.tsx +83 -17
  50. package/src/v2/blocks/tools.tsx +50 -5
  51. package/src/v2/blocks/widgets.tsx +85 -20
  52. package/src/v2/canvas/block-list.tsx +21 -6
  53. package/src/v2/canvas/canvas-css.ts +139 -7
  54. package/src/v2/canvas/canvas.tsx +20 -3
  55. package/src/v2/canvas/dnd.ts +34 -3
  56. package/src/v2/canvas/move-animation.ts +94 -0
  57. package/src/v2/canvas/server-block.tsx +7 -4
  58. package/src/v2/canvas/spacing-viz.ts +51 -0
  59. package/src/v2/core/block-presets.ts +68 -0
  60. package/src/v2/core/host.ts +14 -0
  61. package/src/v2/core/registry.ts +3 -1
  62. package/src/v2/core/structure.ts +4 -2
  63. package/src/v2/editor.css +244 -11
  64. package/src/v2/editor.tsx +8 -2
  65. package/src/v2/index.ts +3 -0
  66. package/src/v2/ui/ai.tsx +9 -5
  67. package/src/v2/ui/attr-form.tsx +42 -13
  68. package/src/v2/ui/attr-hints.ts +104 -6
  69. package/src/v2/ui/background-panel.tsx +65 -21
  70. package/src/v2/ui/block-icons.tsx +152 -0
  71. package/src/v2/ui/block-menu.ts +22 -0
  72. package/src/v2/ui/block-style-panel.tsx +14 -3
  73. package/src/v2/ui/color-field.tsx +74 -9
  74. package/src/v2/ui/divider-panel.tsx +58 -0
  75. package/src/v2/ui/group-width.tsx +38 -0
  76. package/src/v2/ui/icon-picker.tsx +51 -0
  77. package/src/v2/ui/inserter.tsx +51 -7
  78. package/src/v2/ui/inspector.tsx +48 -16
  79. package/src/v2/ui/layout-panel.tsx +5 -47
  80. package/src/v2/ui/list-view.tsx +81 -7
  81. package/src/v2/{blocks → ui}/media-actions.tsx +4 -3
  82. package/src/v2/ui/motion-panel.tsx +2 -1
  83. package/src/v2/ui/parts-panel.tsx +164 -0
  84. package/src/v2/ui/pattern-library.tsx +228 -0
  85. package/src/v2/ui/placeholders.tsx +205 -0
  86. package/src/v2/ui/preset-bar.tsx +83 -0
  87. package/src/v2/ui/style-controls.tsx +65 -15
  88. package/src/v2/ui/style-supports.ts +1 -1
  89. package/src/v2/ui/style-tab.tsx +127 -41
  90. package/src/v2/ui/toolbar.tsx +59 -16
  91. package/src/v2/ui/unit-controls.tsx +88 -39
  92. package/src/locales/en/patterns.ts +0 -50
  93. package/src/locales/vi/patterns.ts +0 -50
  94. package/src/shared/patterns-kit.ts +0 -7
  95. package/src/shared/patterns-library.ts +0 -172
@@ -1,4 +1,4 @@
1
- import { blockCitation, blockShell } from "@ecomcx/ecomweb-content";
1
+ import { ICON_NAMES, blockCitation, blockShell } from "@ecomcx/ecomweb-content";
2
2
  import { Code, Heading1, Heading2, Heading3, Heading4, Heading5, Heading6, List, ListChecks, ListOrdered, Pilcrow, Quote, SquareCode, TextQuote, Type } from "lucide-react";
3
3
  import type { CSSProperties } from "react";
4
4
  import { InnerBlocks } from "../canvas/block-list";
@@ -8,56 +8,93 @@ import type { BlockEditProps, BlockTransform, BlockType } from "../core/registry
8
8
  import { RichText } from "../text/rich-text";
9
9
  import { useActiveWithin } from "./resize";
10
10
  import { BoundText, useBindingPreview } from "../ui/bindings";
11
+ import { useMsgs } from "../i18n";
12
+ import { useEditor } from "../context";
13
+ import { withoutOverridden } from "./inline-style";
11
14
 
12
15
  // Căn chữ lấy từ vỏ dùng chung với website: căn trái không in style (trước đây canvas in thừa)
13
- const align = (a: Record<string, unknown>, type = "paragraph"): CSSProperties | undefined => blockShell(type, a)?.style as CSSProperties | undefined;
16
+ // Căn chữ của thuộc tính (Cài đặt) mà Kiểu dáng › Căn chữ đã đặt thì bỏ phần inline — giống renderer website (inline luôn thắng class kiểu dáng)
17
+ const align = (a: Record<string, unknown>, type = "paragraph"): CSSProperties | undefined => {
18
+ const st = blockShell(type, a)?.style as CSSProperties | undefined;
19
+ return st && a.style ? withoutOverridden(st, a.style) : st;
20
+ };
21
+ /** Class + chú thích của icon cạnh chữ (cùng vỏ với website). */
22
+ const iconProps = (a: Record<string, unknown>, type = "paragraph") => { const sh = blockShell(type, a); return { className: sh?.className, title: sh?.attrs?.title }; };
14
23
  const HEADING_ICONS = [Heading1, Heading1, Heading2, Heading3, Heading4, Heading5, Heading6];
15
24
 
16
- function ParagraphEdit({ block, blockProps, editable, labels }: BlockEditProps) {
25
+ function ParagraphEdit({ block, blockProps, editable }: BlockEditProps) {
17
26
  const bound = useBindingPreview(block, "content");
27
+ const tp = useMsgs("placeholders");
28
+ const { store } = useEditor();
18
29
  if (bound.bound) return <BoundText tagName="p" preview={bound} blockProps={blockProps} style={align(block.attrs)} />;
19
- return <RichText blockId={block.id} value={block.inline} tagName="p" blockProps={blockProps} style={align(block.attrs)} placeholder={labels.typeSlash} editable={editable} />;
30
+ // Gợi ý theo vai trò: mục danh sách / việc khác đoạn văn thường
31
+ const parent = store.locate(block.id)?.parent?.type;
32
+ const ph = parent === "listItem" ? tp.listItem : parent === "taskItem" ? tp.taskItem : tp.paragraph;
33
+ return <RichText blockId={block.id} value={block.inline} tagName="p" blockProps={{ ...blockProps, title: iconProps(block.attrs).title }} className={iconProps(block.attrs).className} style={align(block.attrs)} placeholder={ph} placeholderAlways editable={editable} />;
20
34
  }
21
35
 
22
- function HeadingEdit({ block, blockProps, editable, labels }: BlockEditProps) {
36
+ function HeadingEdit({ block, blockProps, editable }: BlockEditProps) {
37
+ const tp = useMsgs("placeholders");
23
38
  const level = Math.min(6, Math.max(1, Number(block.attrs.level) || 2));
24
39
  const bound = useBindingPreview(block, "content");
25
40
  if (bound.bound) return <BoundText tagName={`h${level}`} preview={bound} blockProps={blockProps} style={align(block.attrs, "heading")} />;
26
- return <RichText blockId={block.id} value={block.inline} tagName={`h${level}`} blockProps={blockProps} style={align(block.attrs, "heading")} placeholder={labels.heading} placeholderAlways editable={editable} />;
41
+ return <RichText blockId={block.id} value={block.inline} tagName={`h${level}`} blockProps={{ ...blockProps, title: iconProps(block.attrs, "heading").title }} className={iconProps(block.attrs, "heading").className} style={align(block.attrs, "heading")} placeholder={tp.heading} placeholderAlways editable={editable} />;
27
42
  }
28
43
 
29
- function CodeEdit({ block, blockProps, editable, labels }: BlockEditProps) {
44
+ const CODE_LANGS = ["html", "css", "javascript", "typescript", "json", "bash", "python", "php", "sql", "csharp", "yaml", "markdown"];
45
+ function CodeEdit({ block, blockProps, editable, setAttrs }: BlockEditProps) {
30
46
  const lang = typeof block.attrs.language === "string" ? block.attrs.language : undefined;
47
+ const tp = useMsgs("placeholders");
48
+ const active = useActiveWithin(block.id);
31
49
  return (
32
50
  <pre {...blockProps}>
33
- <RichText blockId={block.id} value={block.inline} tagName="code" className={lang ? `language-${lang}` : undefined} multiline plain placeholder={labels.codeBlock} placeholderAlways editable={editable} />
51
+ {/* Chọn ngôn ngữ ngay trên khối (chỉ trình soạn) */}
52
+ {editable && active && (
53
+ <label className="ecx-ph-corner" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
54
+ <span className="ecx-ph-label">{tp.language}</span>
55
+ <select className="ecx-input" value={lang ?? ""} onChange={(e) => setAttrs({ language: e.target.value || undefined })}>
56
+ <option value="">{tp.languageAuto}</option>
57
+ {[...new Set([...(lang ? [lang] : []), ...CODE_LANGS])].map((l) => <option key={l} value={l}>{l}</option>)}
58
+ </select>
59
+ </label>
60
+ )}
61
+ <RichText blockId={block.id} value={block.inline} tagName="code" className={lang ? `language-${lang}` : undefined} multiline plain placeholder={tp.code} placeholderAlways editable={editable} />
34
62
  </pre>
35
63
  );
36
64
  }
37
65
 
38
- function PreformattedEdit({ block, blockProps, editable, labels }: BlockEditProps) {
39
- return <RichText blockId={block.id} value={block.inline} tagName="pre" className="ecx-pre" blockProps={blockProps} breakOnEnter placeholder={labels.preformatted} placeholderAlways editable={editable} />;
66
+ function PreformattedEdit({ block, blockProps, editable }: BlockEditProps) {
67
+ const tp = useMsgs("placeholders");
68
+ return <RichText blockId={block.id} value={block.inline} tagName="pre" className="ecx-pre" blockProps={blockProps} breakOnEnter placeholder={tp.preformatted} placeholderAlways editable={editable} />;
40
69
  }
41
70
 
42
- function PullquoteEdit({ block, blockProps, editable, labels, setAttrs }: BlockEditProps) {
43
- const active = useActiveWithin(block.id);
71
+ function PullquoteEdit({ block, blockProps, editable, setAttrs }: BlockEditProps) {
72
+ const tp = useMsgs("placeholders");
44
73
  const cite = blockCitation(block.attrs) ?? "";
45
74
  const sh = blockShell("pullquote", block.attrs)!;
46
75
  return (
47
76
  <figure {...blockProps} className={`${blockProps.className} ${sh.className}`}>
48
- <blockquote><RichText blockId={block.id} value={block.inline} tagName="p" placeholder={labels.pullquote} placeholderAlways editable={editable} /></blockquote>
49
- {/* website chỉ in nguồn khi có chữ: canvas chỉ hiện ô nguồn trống lúc đang chọn khối */}
50
- {(cite || (active && editable)) && <RichText blockId={block.id} field="citation" tagName="figcaption" value={cite} onChange={(v) => setAttrs({ citation: v })} placeholder={labels.caption} editable={editable} />}
77
+ <blockquote><RichText blockId={block.id} value={block.inline} tagName="p" placeholder={tp.quote} placeholderAlways editable={editable} /></blockquote>
78
+ {/* website chỉ in nguồn khi có chữ: trình soạn luôn có ô người nói để thấy chỗ gõ */}
79
+ {(cite || editable) && <RichText blockId={block.id} field="citation" tagName="figcaption" value={cite} onChange={(v) => setAttrs({ citation: v })} placeholder={tp.speaker} placeholderAlways editable={editable} />}
51
80
  </figure>
52
81
  );
53
82
  }
54
83
 
55
- function ListEdit({ block, blockProps }: BlockEditProps) {
84
+ function ListEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
56
85
  const Tag = block.type === "orderedList" ? "ol" : "ul";
57
86
  const start = Number(block.attrs.start);
87
+ const tp = useMsgs("placeholders");
88
+ const active = useActiveWithin(block.id);
58
89
  return (
59
90
  <Tag {...(blockProps as object)} className={`${blockProps.className}${block.type === "taskList" ? " ecx-task-list task-list" : ""}`} start={Tag === "ol" && start > 1 ? start : undefined}>
60
91
  <InnerBlocks parent={block} appender="none" />
92
+ {/* Số bắt đầu chỉnh ngay trên khối (chỉ khi đang thao tác trong danh sách số) */}
93
+ {Tag === "ol" && editable && active && (
94
+ <li className="ecx-ph-corner is-list" contentEditable={false} onMouseDown={(e) => e.stopPropagation()} role="presentation">
95
+ <label><span className="ecx-ph-label">{tp.startAt}</span> <input className="ecx-input" type="number" min={1} value={start > 0 ? start : 1} onChange={(e) => setAttrs({ start: Math.max(1, Number(e.target.value) || 1) })} /></label>
96
+ </li>
97
+ )}
61
98
  </Tag>
62
99
  );
63
100
  }
@@ -75,13 +112,14 @@ function TaskItemEdit({ block, blockProps, setAttrs, editable }: BlockEditProps)
75
112
  );
76
113
  }
77
114
 
78
- function QuoteEdit({ block, blockProps, editable, setAttrs, labels }: BlockEditProps) {
115
+ function QuoteEdit({ block, blockProps, editable, setAttrs }: BlockEditProps) {
79
116
  const cite = blockCitation(block.attrs);
80
- // Website in <cite> sau nội dung khi có nguồn: canvas cũng vậy (sửa tại chỗ); đặt / xoá nguồn ở bảng cài đặt khối
117
+ const tp = useMsgs("placeholders");
118
+ // Website in <cite> sau nội dung khi có nguồn: trình soạn luôn có ô nguồn ("— Thêm nguồn…") để sửa tại chỗ
81
119
  return (
82
120
  <blockquote {...blockProps}>
83
121
  <InnerBlocks parent={block} />
84
- {cite !== undefined && <RichText blockId={block.id} field="citation" tagName="cite" value={cite} onChange={(v) => setAttrs({ citation: v || undefined })} placeholder={labels.caption} editable={editable} />}
122
+ {(cite !== undefined || editable) && <RichText blockId={block.id} field="citation" tagName="cite" value={cite ?? ""} onChange={(v) => setAttrs({ citation: v || undefined })} placeholder={tp.citation} placeholderAlways editable={editable} />}
85
123
  </blockquote>
86
124
  );
87
125
  }
@@ -110,12 +148,12 @@ export function textBlocks(): BlockType[] {
110
148
  return [
111
149
  {
112
150
  name: "paragraph", title: "Đoạn văn", icon: Pilcrow, category: "text", keywords: "doan van text paragraph p", kind: "text", edit: ParagraphEdit,
113
- attributes: { textAlign: { type: "string", enum: ["left", "center", "right", "justify"] } },
151
+ attributes: { textAlign: { type: "string", enum: ["left", "center", "right", "justify"] }, icon: { type: "string", enum: [...ICON_NAMES] }, iconPosition: { type: "string", enum: ["left", "right"], default: "left" }, iconTitle: { type: "string" } },
114
152
  supports: { style: true, anchor: true, className: true }, transforms: textTransforms("paragraph"),
115
153
  },
116
154
  {
117
155
  name: "heading", title: "Tiêu đề", icon: Heading2, category: "text", keywords: "tieu de heading h1 h2 h3 h4", kind: "text", edit: HeadingEdit,
118
- attributes: { level: { type: "integer", default: 2, min: 1, max: 6 }, textAlign: { type: "string", enum: ["left", "center", "right", "justify"] } },
156
+ attributes: { level: { type: "integer", default: 2, min: 1, max: 6 }, textAlign: { type: "string", enum: ["left", "center", "right", "justify"] }, icon: { type: "string", enum: [...ICON_NAMES] }, iconPosition: { type: "string", enum: ["left", "right"], default: "left" }, iconTitle: { type: "string" }, tocTitle: { type: "string" } },
119
157
  create: (attrs) => makeBlock("heading", { level: 2, ...attrs }),
120
158
  variations: [1, 2, 3, 4, 5, 6].map((level) => ({ name: `h${level}`, title: `H${level}`, icon: HEADING_ICONS[level], keywords: `h${level}`, attrs: { level }, isActive: (a) => Number(a.level) === level })),
121
159
  supports: { style: true, anchor: true, className: true }, transforms: textTransforms("heading"),
@@ -147,7 +185,7 @@ export function textBlocks(): BlockType[] {
147
185
  },
148
186
  {
149
187
  name: "codeBlock", title: "Mã nguồn", icon: SquareCode, category: "text", keywords: "ma code nguon", kind: "text", edit: CodeEdit, multiline: true, plain: true,
150
- attributes: { language: { type: "string", label: "Ngôn ngữ" } },
188
+ attributes: { language: { type: "string" } }, // nhãn lấy từ locales/*/attrs.ts (language) theo ngôn ngữ đang dùng
151
189
  transforms: [{ to: "paragraph", convert: (b) => textsOf(b).map((i) => makeBlock("paragraph", {}, inlineText(i))) }, { to: "preformatted", convert: toTextBlocks("preformatted") }],
152
190
  },
153
191
  {
@@ -1,6 +1,6 @@
1
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
- import { ICON_PATHS } from "@ecomcx/ecomweb-content";
3
+ import { ICON_PATHS, SEARCH_ICON_PATH } from "@ecomcx/ecomweb-content";
4
4
  import { Block, DocBlocks, InnerBlocks, NestedDoc } from "../canvas/block-list";
5
5
  import { DocScopeProvider, LoopPostContext, useDocScope, useDynamicData, useEditor, useEditorState } from "../context";
6
6
  import type { DynamicPost, QueryArgs } from "../core/host";
@@ -8,6 +8,7 @@ import type { BNode } from "../core/model";
8
8
  import { blocksFromDoc, makeBlock } from "../core/model";
9
9
  import type { BlockEditProps, BlockType } from "../core/registry";
10
10
  import { useMsgs } from "../i18n";
11
+ import { MediaPlaceholder } from "../ui/placeholders";
11
12
 
12
13
  const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
13
14
  const align = (a: Record<string, unknown>): CSSProperties | undefined => (typeof a.textAlign === "string" ? { textAlign: a.textAlign as CSSProperties["textAlign"] } : undefined);
@@ -29,10 +30,35 @@ function SiteTaglineEdit({ block, blockProps }: BlockEditProps) {
29
30
  const d = useDynamic();
30
31
  return <p {...merge(blockProps, "ecx-site-tagline", align(block.attrs))}>{d.site?.tagline || "Tagline"}</p>;
31
32
  }
32
- function SiteLogoEdit({ block, blockProps }: BlockEditProps) {
33
+ /** Nhãn của ô giữ chỗ khối giao diện: cam = thiếu dữ liệu (kèm nút đi tới chỗ nhập). */
34
+ function Missing({ children }: { children: ReactNode }) {
35
+ return <span className="ecx-ph-badge is-missing" contentEditable={false}>{children}</span>;
36
+ }
37
+ /** Nút đi tới trang quản trị nhập dữ liệu còn thiếu (host.openAdmin). */
38
+ function AdminButton({ target, args, children, primary }: { target: Parameters<NonNullable<ReturnType<typeof useEditor>["host"]["openAdmin"]>>[0]; args?: Record<string, string>; children: ReactNode; primary?: boolean }) {
39
+ const { host } = useEditor();
40
+ if (!host.openAdmin) return null;
41
+ return <button type="button" className={cx("ecx-btn", primary && "ecx-btn-primary")} contentEditable={false} onMouseDown={(e) => e.stopPropagation()} onClick={() => host.openAdmin!(target, args)}>{children}</button>;
42
+ }
43
+
44
+ function SiteLogoEdit({ block, blockProps, editable }: BlockEditProps) {
33
45
  const d = useDynamic();
46
+ const { host } = useEditor();
47
+ const tp = useMsgs("placeholders");
48
+ const [saved, setSaved] = useState<string | null>(null);
34
49
  const w = Number(block.attrs.width) || 120;
35
- return <div {...merge(blockProps, "ecx-site-logo")}>{d.site?.logo ? <img src={d.site.logo} alt="" width={w} draggable={false} /> : <span className="ecx-logo-placeholder" style={{ width: w }}><ImageIcon className="ecx-icon" /></span>}</div>;
50
+ const logo = d.site?.logo || saved;
51
+ if (logo || !editable) return <div {...merge(blockProps, "ecx-site-logo")}>{logo ? <img src={logo} alt="" width={w} draggable={false} /> : <span className="ecx-logo-placeholder" style={{ width: w }}><ImageIcon className="ecx-icon" /></span>}</div>;
52
+ // Chưa có logo: ô thả logo — chọn xong là đổi logo cho cả website (host.setSiteLogo); không có thì nút mở Tuỳ biến
53
+ return (
54
+ <div {...merge(blockProps, "ecx-site-logo ecx-ph-theme is-missing")} data-ecx-placeholder="logo">
55
+ <Missing>{tp.noLogo}</Missing>
56
+ {host.setSiteLogo
57
+ ? <MediaPlaceholder kind="image" compact title={tp.dropLogo} onSelect={(items) => { host.setSiteLogo!(items[0]).then(() => setSaved(items[0].url), () => {}); }} />
58
+ : <AdminButton target="customize" primary>{tp.openSettings}</AdminButton>}
59
+ <p className="ecx-placeholder-hint">{tp.logoAll}</p>
60
+ </div>
61
+ );
36
62
  }
37
63
  /** Menu: cùng markup với website (theme-sdk) — nav.ecx-navigation-menu > ul > li > a, nút ☰ cho điện thoại. */
38
64
  /** Nút nhỏ trên khối Menu đang chọn: mở nơi sửa menu của ứng dụng nhúng. */
@@ -49,12 +75,20 @@ function NavigationEdit({ block, blockProps, selected }: BlockEditProps) {
49
75
  const items = d.menus?.[location];
50
76
  const mobile = block.attrs.mobile !== false;
51
77
  const t = useMsgs("blocks");
78
+ const tp = useMsgs("placeholders");
79
+ const { host } = useEditor();
52
80
  if (!items?.length) {
81
+ // Vị trí chưa có menu: nhãn cam + nút tạo / chọn menu (thay cho cột liên kết trống)
53
82
  return (
54
- <div {...merge(blockProps, "ecx-navigation ecx-placeholder-block")}>
55
- <span className="ecx-placeholder-title"><Menu className="ecx-icon" /> {t.menu} · {location}</span>
56
- <span className="ecx-placeholder-summary">{t.noMenuIsAssigned}</span>
57
- <EditMenuButton location={location} selected={selected} />
83
+ <div {...merge(blockProps, "ecx-navigation ecx-media-placeholder ecx-ph-theme is-missing")} data-ecx-placeholder="menu">
84
+ <span className="ecx-placeholder-title"><Menu className="ecx-icon" /> {t.menu}</span>
85
+ <Missing>{tp.menuEmpty.replace("{location}", location)}</Missing>
86
+ {host.editMenu && (
87
+ <span className="ecx-ph-row" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
88
+ <button type="button" className="ecx-btn ecx-btn-primary" onClick={() => host.editMenu!(location)}>{tp.createMenu}</button>
89
+ <button type="button" className="ecx-btn" onClick={() => host.editMenu!(location)}>{tp.pickMenu}</button>
90
+ </span>
91
+ )}
58
92
  </div>
59
93
  );
60
94
  }
@@ -71,7 +105,10 @@ function NavigationEdit({ block, blockProps, selected }: BlockEditProps) {
71
105
  function SearchEdit({ block, blockProps }: BlockEditProps) {
72
106
  const t = useMsgs("blocks");
73
107
  const pos = String(block.attrs.buttonPosition ?? "right");
74
- const button = <button type="button" tabIndex={-1}>{String(block.attrs.buttonText || t.searchButton)}</button>;
108
+ const label = String(block.attrs.buttonText || t.searchButton);
109
+ const button = block.attrs.buttonStyle === "icon"
110
+ ? <button type="button" tabIndex={-1} aria-label={label} title={label}><svg viewBox="0 0 24 24" width={18} height={18} fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" focusable="false"><path d={SEARCH_ICON_PATH} /></svg></button>
111
+ : <button type="button" tabIndex={-1}>{label}</button>;
75
112
  return (
76
113
  <div {...merge(blockProps, "ecx-search")}>
77
114
  <form role="search" onSubmit={(e) => e.preventDefault()} style={pos === "below" ? { display: "flex", flexDirection: "column", gap: 8 } : undefined}
@@ -105,10 +142,14 @@ function PostExcerptEdit({ block, blockProps }: BlockEditProps) {
105
142
  }
106
143
  function FeaturedImageEdit({ block, blockProps }: BlockEditProps) {
107
144
  const d = useDynamic();
145
+ const tp = useMsgs("placeholders");
108
146
  const ratio = block.attrs.aspect && block.attrs.aspect !== "auto" ? String(block.attrs.aspect) : undefined;
109
147
  return (
110
148
  <div {...merge(blockProps, "ecx-featured-image", { aspectRatio: ratio ?? (d.post?.image ? undefined : "16/9"), overflow: "hidden" })}>
111
- {d.post?.image ? <img src={d.post.image} alt="" draggable={false} style={{ width: "100%", height: "100%", objectFit: "cover" }} /> : <span className="ecx-image-placeholder"><ImageIcon className="ecx-icon" /></span>}
149
+ {d.post?.image ? <img src={d.post.image} alt="" draggable={false} style={{ width: "100%", height: "100%", objectFit: "cover" }} /> : (
150
+ // Giải thích thay vì khung trống
151
+ <span className="ecx-image-placeholder ecx-ph-theme" data-ecx-placeholder="featured"><ImageIcon className="ecx-icon" /><Missing>{tp.noFeatured}</Missing><span className="ecx-placeholder-hint">{tp.noFeaturedHint}</span></span>
152
+ )}
112
153
  </div>
113
154
  );
114
155
  }
@@ -155,7 +196,9 @@ function LoginOutEdit({ block, blockProps }: BlockEditProps) {
155
196
  function IconEdit({ block, blockProps }: BlockEditProps) {
156
197
  const size = Math.min(128, Math.max(12, Number(block.attrs.size) || 24));
157
198
  const path = ICON_PATHS[String(block.attrs.name ?? "star")] ?? ICON_PATHS.star;
158
- return <div {...merge(blockProps, "ecx-icon-block", align(block.attrs))}><svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden><path d={path} /></svg></div>;
199
+ const stroke = Math.min(4, Math.max(0.5, Number(block.attrs.stroke) || 2));
200
+ const shape = block.attrs.iconStyle === "circle" || block.attrs.iconStyle === "square" ? block.attrs.iconStyle : undefined;
201
+ return <div {...merge(blockProps, "ecx-icon-block", align(block.attrs))}><span className={`ecx-icon-shape${shape ? ` is-${shape}` : ""}`} style={shape ? { padding: Math.round(size * 0.4) } : undefined}><svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={stroke} strokeLinecap="round" strokeLinejoin="round" aria-hidden><path d={path} /></svg></span></div>;
159
202
  }
160
203
  function FootnotesEdit({ block, blockProps }: BlockEditProps) {
161
204
  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>;
@@ -246,7 +289,7 @@ function sampleContentNodes(content: unknown): BNode[] | null {
246
289
  return nodes.length ? nodes : null;
247
290
  }
248
291
  function PostContentEdit({ blockProps }: BlockEditProps) {
249
- const { labels } = useEditor();
292
+ const tp = useMsgs("placeholders");
250
293
  const sample = sampleContentNodes(useDynamicData().post?.content);
251
294
  const t = useMsgs("blocks");
252
295
  const scope = useDocScope();
@@ -262,10 +305,31 @@ function PostContentEdit({ blockProps }: BlockEditProps) {
262
305
  }
263
306
  // Có bài mẫu → nội dung thật của bài (chỉ xem; sửa nội dung ở trình soạn bài); chưa có → khung giữ chỗ
264
307
  if (sample) return <div {...merge(blockProps, "ecx-post-content ecx-content")}><PreviewBlocks nodes={sample} tag="sample-content" /></div>;
265
- return <div {...merge(blockProps, "ecx-post-content ecx-content-placeholder")}><FileText className="ecx-icon" /> {t.postContent}</div>;
308
+ return <div {...merge(blockProps, "ecx-post-content ecx-content-placeholder")} data-ecx-placeholder="post-content"><FileText className="ecx-icon" /> <span><strong>{t.postContent}</strong><br /><span className="ecx-placeholder-hint">{tp.postContentHint}</span></span></div>;
266
309
  }
267
310
 
268
- function QueryEdit({ block, blockProps }: BlockEditProps) {
311
+ /** Kiểu hiển thị của danh sách bài khi chèn (như Query Loop của WordPress: chọn mẫu trước rồi hiện bài thật). */
312
+ const QUERY_LAYOUTS = {
313
+ list: () => [makeBlock("postTemplate", { layout: "list" }, [makeBlock("postTitle", { level: 2, link: true }), makeBlock("postDate"), makeBlock("postExcerpt")]), makeBlock("pagination")],
314
+ grid: () => [makeBlock("postTemplate", { layout: "grid", columns: 3 }, [makeBlock("postTitle", { level: 3, link: true }), makeBlock("postExcerpt")]), makeBlock("pagination")],
315
+ cards: () => [makeBlock("postTemplate", { layout: "grid", columns: 3 }, [makeBlock("featuredImage", { link: true, aspect: "16/9" }), makeBlock("postTitle", { level: 3, link: true }), makeBlock("postDate")]), makeBlock("pagination")],
316
+ };
317
+ function QueryEdit({ block, blockProps, editable }: BlockEditProps) {
318
+ const { store } = useEditor();
319
+ const tp = useMsgs("placeholders");
320
+ if (editable && !block.content?.length) {
321
+ const items: Array<[keyof typeof QUERY_LAYOUTS, typeof Rows3, string]> = [["list", Rows3, tp.queryList], ["grid", LayoutTemplate, tp.queryGrid], ["cards", ImageIcon, tp.queryCards]];
322
+ return (
323
+ <div {...merge(blockProps, "ecx-query")} data-ecx-placeholder="query">
324
+ <div className="ecx-media-placeholder ecx-ph-choose" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
325
+ <p className="ecx-ph-title">{tp.queryChoose}</p>
326
+ <div className="ecx-ph-choices">
327
+ {items.map(([k, I, label]) => <button key={k} type="button" className="ecx-ph-choice" onClick={() => store.replace(block.id, [{ ...block, content: QUERY_LAYOUTS[k]() }])}><I className="ecx-icon" aria-hidden />{label}</button>)}
328
+ </div>
329
+ </div>
330
+ </div>
331
+ );
332
+ }
269
333
  return <div {...merge(blockProps, "ecx-query")}><InnerBlocks parent={block} /></div>;
270
334
  }
271
335
  /** Thiết lập của khối query (mặc định giống website). */
@@ -315,9 +379,10 @@ function PostTemplateEdit({ block, blockProps, editable, labels }: BlockEditProp
315
379
  const count = posts ? Math.max(1, Math.min(posts.length, q.perPage, 6)) : 3;
316
380
  const current = Math.min(active, count - 1);
317
381
  const t = useMsgs("blocks");
382
+ const tp = useMsgs("placeholders");
318
383
  return (
319
384
  <ul {...(merge(blockProps, cx("ecx-post-template", grid && "is-grid"), grid ? { display: "grid", gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))`, gap: "1.5rem" } : undefined) as object)} data-ecx-posts={posts ? posts.length : ""}>
320
- {posts && !posts.length && <li className="ecx-post ecx-post-none">{t.noPostsMatchThese}</li>}
385
+ {posts && !posts.length && <li className="ecx-post ecx-post-none ecx-ph-theme is-missing" data-ecx-placeholder="no-posts"><Missing>{tp.noPosts}</Missing> <span className="ecx-placeholder-hint">{tp.noPostsHint}</span> <AdminButton target="newPost" args={{ postType: q.postType }}>+ {tp.writeFirst}</AdminButton></li>}
321
386
  {Array.from({ length: count }, (_, i) => {
322
387
  const post = posts?.[i] ?? null;
323
388
  if (i === current) return <li key="edit" className={cx("ecx-post", count > 1 && "is-active")}><LoopPostContext.Provider value={post}><InnerBlocks parent={block} /></LoopPostContext.Provider></li>;
@@ -394,7 +459,7 @@ export function themeBlocks(): BlockType[] {
394
459
  { 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 } },
395
460
  { 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 } },
396
461
  { 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 },
397
- { 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 } },
462
+ { 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" }, buttonStyle: { type: "string", enum: ["text", "icon"], default: "text" } }, supports: { style: true, className: true } },
398
463
  { 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 } },
399
464
  { 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 } },
400
465
  { 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 } },
@@ -411,7 +476,7 @@ export function themeBlocks(): BlockType[] {
411
476
  { 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"] } },
412
477
  { 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 },
413
478
  { 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 } },
414
- { 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 },
479
+ { 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, stroke: { type: "number", default: 2, min: 0.5, max: 4 }, iconStyle: { type: "string", enum: ["plain", "circle", "square"], default: "plain" }, href: { type: "url" }, linkTarget: { type: "string", enum: ["_self", "_blank"] } }, supports: { style: true, className: true }, summary: (a) => a.name },
415
480
  { 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 } },
416
481
  { name: "pageBreak", title: "Ngắt trang", icon: PanelTop, category: theme, keywords: "ngat trang page break nextpage", kind: "atom", edit: PageBreakEdit, supports: { className: true } },
417
482
  { 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 } },
@@ -423,7 +488,8 @@ export function themeBlocks(): BlockType[] {
423
488
  {
424
489
  name: "query", title: "Danh sách bài", icon: Rows3, category: theme, keywords: "danh sach bai query loop tin tuc", kind: "container", edit: QueryEdit,
425
490
  attributes: { inherit: { type: "boolean", default: true }, postType: { type: "string", default: "post" }, perPage: { type: "integer", default: 10, min: 1, max: 100 }, category: { type: "string" }, tag: { type: "string" }, orderBy: { type: "string", enum: ["date", "title", "modified", "menu_order", "comment_count", "rand"], default: "date" }, order: { type: "string", enum: ["desc", "asc"], default: "desc" }, authorId: { type: "integer", min: 1 }, search: { type: "string" }, exclude: { type: "string" }, sticky: { type: "string", enum: ["any", "only", "exclude"], default: "any" }, orderByMeta: { type: "string" }, paginate: { type: "boolean", default: false } },
426
- create: () => makeBlock("query", { inherit: true }, [makeBlock("postTemplate", { layout: "list" }, [makeBlock("postTitle", { level: 2, link: true }), makeBlock("postExcerpt")]), makeBlock("pagination")]),
491
+ // Mới chèn: chưa có khuôn → hỏi kiểu hiển thị trước (Danh sách / Lưới / Thẻ có ảnh)
492
+ create: () => makeBlock("query", { inherit: true }, []),
427
493
  supports: { style: true, className: true },
428
494
  },
429
495
  { name: "postTemplate", title: "Khuôn mỗi bài", icon: LayoutTemplate, kind: "container", edit: PostTemplateEdit, hidden: true, attributes: { layout: { type: "string", enum: ["list", "grid"], default: "list" }, columns: { type: "integer", default: 3, min: 1, max: 6 } }, structure: { parents: ["query"] } },
@@ -1,8 +1,12 @@
1
- import { Columns2, Minus, Plus, Table2, ArrowUpToLine, ArrowDownToLine, ArrowLeftToLine, ArrowRightToLine, Trash2, Heading, TableCellsMerge, TableCellsSplit } from "lucide-react";
1
+ import { AlignCenter, AlignCenterHorizontal, AlignEndHorizontal, AlignHorizontalSpaceBetween, AlignLeft, AlignRight, AlignStartHorizontal, Link2, StretchHorizontal, Columns2, Minus, Plus, Table2, ArrowUpToLine, ArrowDownToLine, ArrowLeftToLine, ArrowRightToLine, Trash2, Heading, TableCellsMerge, TableCellsSplit } from "lucide-react";
2
2
  import { useEditor } from "../context";
3
3
  import { makeBlock, type BNode } from "../core/model";
4
4
  import { addColumn, addRow, canMerge, canSplit, deleteColumn, deleteRow, hasHeaderRow, mergeCells, splitCell, tableContext, toggleHeaderRow } from "../core/tables";
5
5
  import { Dropdown, MenuItem, ToolButton } from "../ui/toolbar";
6
+ import { useState } from "react";
7
+ import { useMsgs } from "../i18n";
8
+ import { isSafeUrl } from "@ecomcx/ecomweb-content";
9
+ import type { BlockEditProps } from "../core/registry";
6
10
 
7
11
  /** Công cụ bảng khi đang gõ trong ô (hoặc chọn cả bảng). */
8
12
  export function TableTools({ ancestor, currentId }: { ancestor: BNode; currentId: string }) {
@@ -56,17 +60,58 @@ export function ColumnsTools({ ancestor }: { ancestor: BNode; currentId: string
56
60
  <span className="ecx-tool is-static" title={`${cols.length} ${labels.columns}`}><Columns2 className="ecx-icon" /></span>
57
61
  <ToolButton label={labels.removeColumn} disabled={cols.length <= 1} onClick={remove}><Minus className="ecx-icon" /></ToolButton>
58
62
  <ToolButton label={labels.addColumn} disabled={cols.length >= 6} onClick={add}><Plus className="ecx-icon" /></ToolButton>
63
+ <VAlignTool row={ancestor} />
59
64
  </>
60
65
  );
61
66
  }
62
67
 
68
+ /** Căn dọc các cột ngay trên thanh (cùng thuộc tính verticalAlign với bảng bên phải). */
69
+ function VAlignTool({ row }: { row: BNode }) {
70
+ const { store } = useEditor();
71
+ const t = useMsgs("columns");
72
+ const cur = (row.attrs.verticalAlign as string | undefined) ?? "top";
73
+ const opts = [["top", AlignStartHorizontal, t.top], ["center", AlignCenterHorizontal, t.middle], ["bottom", AlignEndHorizontal, t.bottom], ["stretch", StretchHorizontal, t.stretch]] as const;
74
+ const Cur = opts.find(([v]) => v === cur)?.[1] ?? AlignStartHorizontal;
75
+ return (
76
+ <Dropdown label={t.valign} trigger={<Cur className="ecx-icon" />}>
77
+ {(close) => opts.map(([v, I, l]) => <MenuItem key={v} icon={I} label={(v === cur ? "✓ " : "") + l} onClick={() => { close(); store.setAttrs([row.id], { verticalAlign: v === "top" ? undefined : v }); }} />)}
78
+ </Dropdown>
79
+ );
80
+ }
81
+
63
82
  /** Thêm nút vào nhóm nút. */
64
83
  export function ButtonsTools({ ancestor }: { ancestor: BNode; currentId: string }) {
65
84
  const { store, labels } = useEditor();
85
+ const cur = (ancestor.attrs.align as string | undefined) ?? "left";
86
+ const opts = [["left", AlignLeft, labels.alignLeft], ["center", AlignCenter, labels.alignCenter], ["right", AlignRight, labels.alignRight], ["space-between", AlignHorizontalSpaceBetween, labels.spaceBetween]] as const;
87
+ const Cur = opts.find(([v]) => v === cur)?.[1] ?? AlignLeft;
88
+ return (
89
+ <>
90
+ <Dropdown label={labels.buttonsAlign} trigger={<Cur className="ecx-icon" />}>
91
+ {(close) => opts.map(([v, I, l]) => <MenuItem key={v} icon={I} label={(v === cur ? "✓ " : "") + l} onClick={() => { close(); store.setAttrs([ancestor.id], { align: v === "left" ? undefined : v }); }} />)}
92
+ </Dropdown>
93
+ <ToolButton label={labels.addButton} onClick={() => {
94
+ const btn = makeBlock("button", { variant: "primary" });
95
+ store.insert(store.locate(ancestor.id)!.docId, ancestor.id, ancestor.content?.length ?? 0, [btn], { focus: false });
96
+ }}><Plus className="ecx-icon" /></ToolButton>
97
+ </>
98
+ );
99
+ }
100
+
101
+ /** Liên kết của nút ngay trên thanh: ô địa chỉ + mở tab mới (cùng thuộc tính href / target với bảng bên phải). */
102
+ export function ButtonLinkTool({ block, setAttrs }: BlockEditProps) {
103
+ const { labels } = useEditor();
104
+ const [url, setUrl] = useState((block.attrs.href as string | undefined) ?? "");
105
+ const ok = !url.trim() || isSafeUrl(url.trim());
66
106
  return (
67
- <ToolButton label={labels.addButton} onClick={() => {
68
- const btn = makeBlock("button", { variant: "primary" });
69
- store.insert(store.locate(ancestor.id)!.docId, ancestor.id, ancestor.content?.length ?? 0, [btn], { focus: false });
70
- }}><Plus className="ecx-icon" /></ToolButton>
107
+ <Dropdown label={labels.buttonLink} trigger={<Link2 className="ecx-icon" />}>
108
+ {(close) => (
109
+ <form className="ecx-tool-form" onSubmit={(e) => { e.preventDefault(); if (!ok) return; setAttrs({ href: url.trim() || undefined }); close(); }}>
110
+ <input className="ecx-input" type="text" inputMode="url" autoFocus aria-label={labels.buttonLink} placeholder="https://…" aria-invalid={!ok} value={url} onChange={(e) => setUrl(e.target.value)} />
111
+ <label className="ecx-check"><input type="checkbox" checked={block.attrs.target === "_blank"} onChange={(e) => setAttrs({ target: e.target.checked ? "_blank" : undefined })} />{labels.openNewTab}</label>
112
+ <button type="submit" className="ecx-btn" disabled={!ok}>{labels.apply}</button>
113
+ </form>
114
+ )}
115
+ </Dropdown>
71
116
  );
72
117
  }