@ecomcx/ecomweb-editor 1.31.0 → 1.33.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 (91) 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/bindings.ts +1 -1
  5. package/src/locales/en/block-desc.ts +2 -0
  6. package/src/locales/en/block-style.ts +7 -4
  7. package/src/locales/en/block-titles.ts +2 -0
  8. package/src/locales/en/blocks.ts +12 -3
  9. package/src/locales/en/columns.ts +12 -0
  10. package/src/locales/en/controls.ts +21 -0
  11. package/src/locales/en/hints.ts +289 -1
  12. package/src/locales/en/index.ts +5 -2
  13. package/src/locales/en/layout.ts +32 -0
  14. package/src/locales/en/legacy.ts +1 -1
  15. package/src/locales/en/library.ts +38 -0
  16. package/src/locales/en/parts.ts +12 -0
  17. package/src/locales/en/placeholders.ts +12 -1
  18. package/src/locales/en/presets.ts +6 -0
  19. package/src/locales/en/v2.ts +21 -0
  20. package/src/locales/vi/attrs.ts +10 -0
  21. package/src/locales/vi/background.ts +17 -0
  22. package/src/locales/vi/bindings.ts +1 -1
  23. package/src/locales/vi/block-desc.ts +2 -0
  24. package/src/locales/vi/block-style.ts +7 -4
  25. package/src/locales/vi/block-titles.ts +2 -0
  26. package/src/locales/vi/blocks.ts +12 -3
  27. package/src/locales/vi/columns.ts +12 -0
  28. package/src/locales/vi/controls.ts +21 -0
  29. package/src/locales/vi/hints.ts +290 -2
  30. package/src/locales/vi/index.ts +5 -2
  31. package/src/locales/vi/layout.ts +32 -0
  32. package/src/locales/vi/legacy.ts +1 -1
  33. package/src/locales/vi/library.ts +38 -0
  34. package/src/locales/vi/parts.ts +12 -0
  35. package/src/locales/vi/placeholders.ts +12 -1
  36. package/src/locales/vi/presets.ts +6 -0
  37. package/src/locales/vi/v2.ts +21 -0
  38. package/src/shared/panel-store.ts +3 -3
  39. package/src/shared/patterns.ts +3 -52
  40. package/src/shared/style-panel.tsx +2 -2
  41. package/src/shared/types.ts +2 -0
  42. package/src/v2/blocks/columns-inspector.tsx +210 -0
  43. package/src/v2/blocks/form.tsx +4 -4
  44. package/src/v2/blocks/index.ts +10 -4
  45. package/src/v2/blocks/inline-style.ts +1 -1
  46. package/src/v2/blocks/layout.tsx +211 -44
  47. package/src/v2/blocks/media.tsx +22 -13
  48. package/src/v2/blocks/resize.tsx +172 -4
  49. package/src/v2/blocks/text.tsx +14 -7
  50. package/src/v2/blocks/theme.tsx +63 -19
  51. package/src/v2/blocks/tools.tsx +50 -5
  52. package/src/v2/blocks/widgets.tsx +44 -16
  53. package/src/v2/canvas/block-list.tsx +23 -3
  54. package/src/v2/canvas/canvas-css.ts +70 -4
  55. package/src/v2/canvas/canvas.tsx +22 -5
  56. package/src/v2/canvas/dnd.ts +34 -3
  57. package/src/v2/canvas/move-animation.ts +94 -0
  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 +6 -1
  61. package/src/v2/core/structure.ts +2 -1
  62. package/src/v2/editor.css +238 -9
  63. package/src/v2/editor.tsx +8 -2
  64. package/src/v2/ui/attr-form.tsx +59 -12
  65. package/src/v2/ui/attr-hints.ts +140 -9
  66. package/src/v2/ui/background-panel.tsx +65 -21
  67. package/src/v2/ui/bindings.tsx +3 -0
  68. package/src/v2/ui/block-icons.tsx +152 -0
  69. package/src/v2/ui/block-menu.ts +22 -0
  70. package/src/v2/ui/block-style-panel.tsx +14 -3
  71. package/src/v2/ui/color-field.tsx +74 -9
  72. package/src/v2/ui/divider-panel.tsx +58 -0
  73. package/src/v2/ui/group-width.tsx +38 -0
  74. package/src/v2/ui/icon-picker.tsx +51 -0
  75. package/src/v2/ui/inserter.tsx +61 -12
  76. package/src/v2/ui/inspector.tsx +48 -16
  77. package/src/v2/ui/layout-panel.tsx +5 -47
  78. package/src/v2/ui/list-view.tsx +81 -7
  79. package/src/v2/ui/motion-panel.tsx +2 -1
  80. package/src/v2/ui/parts-panel.tsx +164 -0
  81. package/src/v2/ui/pattern-library.tsx +228 -0
  82. package/src/v2/ui/preset-bar.tsx +83 -0
  83. package/src/v2/ui/style-controls.tsx +65 -15
  84. package/src/v2/ui/style-supports.ts +1 -1
  85. package/src/v2/ui/style-tab.tsx +127 -41
  86. package/src/v2/ui/toolbar.tsx +52 -13
  87. package/src/v2/ui/unit-controls.tsx +88 -39
  88. package/src/locales/en/patterns.ts +0 -50
  89. package/src/locales/vi/patterns.ts +0 -50
  90. package/src/shared/patterns-kit.ts +0 -7
  91. package/src/shared/patterns-library.ts +0 -172
@@ -1,6 +1,12 @@
1
1
  import { useCallback, useLayoutEffect, useRef, useState } from "react";
2
+ import { normalizeStyle, type BlockStyle } from "@ecomcx/ecomweb-content";
2
3
  import { useEditor, useEditorState } from "../context";
4
+ import { hideSpacingViz, showSpacingViz } from "../canvas/spacing-viz";
3
5
  import type { BNode } from "../core/model";
6
+ import { labelsLegacy } from "../../shared/labels";
7
+
8
+ /** Thả tay nắm: focus về khung soạn để ⌘Z / Delete… thuộc về trình soạn ngay. */
9
+ const focusCanvas = (el: HTMLElement) => el.ownerDocument.querySelector<HTMLElement>(".ecx-canvas-root")?.focus({ preventScroll: true });
4
10
 
5
11
  /** Khối hoặc khối con của nó đang được chọn / gõ (hiện tay nắm đổi cỡ). */
6
12
  export function useActiveWithin(id: string) {
@@ -20,7 +26,7 @@ export function ColumnHandles({ block }: { block: BNode }) {
20
26
  const ref = useRef<HTMLSpanElement>(null);
21
27
  const [gaps, setGaps] = useState<Array<{ left: number; top: number; height: number }>>([]);
22
28
  const cols = block.content ?? [];
23
- useLayoutEffect(() => {
29
+ const measure = () => {
24
30
  const host = ref.current?.parentElement;
25
31
  if (!host) return;
26
32
  const hr = host.getBoundingClientRect();
@@ -32,7 +38,16 @@ export function ColumnHandles({ block }: { block: BNode }) {
32
38
  return { left: (a.right + b.left) / 2 - hr.left, top: Math.min(a.top, b.top) - hr.top, height: Math.max(a.bottom, b.bottom) - Math.min(a.top, b.top) };
33
39
  }).filter(Boolean) as Array<{ left: number; top: number; height: number }>;
34
40
  setGaps((prev) => (JSON.stringify(prev) === JSON.stringify(next) ? prev : next));
35
- });
41
+ };
42
+ useLayoutEffect(measure);
43
+ // Đổi khổ màn hình / thu nhỏ khung: cột có thể xuống dòng mà không vẽ lại → đo lại, không để tay kéo nằm ngoài khung (tràn ngang)
44
+ useLayoutEffect(() => {
45
+ const host = ref.current?.parentElement;
46
+ if (!host) return;
47
+ const ro = new ResizeObserver(measure);
48
+ ro.observe(host);
49
+ return () => ro.disconnect();
50
+ }, []);
36
51
  const start = (i: number, e: React.PointerEvent) => {
37
52
  e.preventDefault();
38
53
  e.stopPropagation();
@@ -44,9 +59,12 @@ export function ColumnHandles({ block }: { block: BNode }) {
44
59
  const pair = widths[i] + widths[i + 1];
45
60
  const handle = e.currentTarget as HTMLElement;
46
61
  handle.setPointerCapture(e.pointerId);
62
+ handle.classList.add("is-dragging");
47
63
  const move = (ev: PointerEvent) => {
48
64
  const ratio = Math.min(0.9, Math.max(0.1, (ev.clientX - a.left) / (b.right - a.left)));
49
65
  const wa = Math.round(pair * ratio), wb = Math.round(pair - pair * ratio);
66
+ // Nhãn % hai bên tay nắm khi đang kéo
67
+ handle.dataset.left = `${wa}%`; handle.dataset.right = `${wb}%`;
50
68
  const ids = cols.map((c) => c.id);
51
69
  store.batch(() => {
52
70
  widths.forEach((w, k) => {
@@ -55,7 +73,7 @@ export function ColumnHandles({ block }: { block: BNode }) {
55
73
  });
56
74
  });
57
75
  };
58
- const up = () => { handle.removeEventListener("pointermove", move); handle.removeEventListener("pointerup", up); store.breakMerge(); };
76
+ const up = () => { handle.removeEventListener("pointermove", move); handle.removeEventListener("pointerup", up); handle.classList.remove("is-dragging"); store.breakMerge(); focusCanvas(handle); };
59
77
  handle.addEventListener("pointermove", move);
60
78
  handle.addEventListener("pointerup", up);
61
79
  };
@@ -102,10 +120,160 @@ export function ImageHandle({ blockId }: { blockId: string }) {
102
120
  const w = Math.round(Math.min(max, Math.max(48, ev.clientX - r.left)));
103
121
  store.setAttrs([blockId], { width: w, height: Math.round(w * ratio) || undefined });
104
122
  };
105
- const up = () => { handle.removeEventListener("pointermove", move); handle.removeEventListener("pointerup", up); store.breakMerge(); };
123
+ const up = () => { handle.removeEventListener("pointermove", move); handle.removeEventListener("pointerup", up); store.breakMerge(); focusCanvas(handle); };
106
124
  handle.addEventListener("pointermove", move);
107
125
  handle.addEventListener("pointerup", up);
108
126
  };
109
127
  return <span ref={ref} className="ecx-image-handle" contentEditable={false} title={labels.resize} style={pos ? { left: pos.left - 7, top: pos.top - 7 } : { visibility: "hidden" }}
110
128
  onPointerDown={start} onMouseDown={(e) => e.stopPropagation()} />;
111
129
  }
130
+
131
+ /** Kéo mép dưới để đổi chiều cao khối (Khoảng trống): ghi `attrs.height` = "NNpx". Dùng chung kiểu tay nắm của dải đệm. */
132
+ export function HeightHandle({ blockId }: { blockId: string }) {
133
+ const { store, ui, labels } = useEditor();
134
+ const start = (e: React.PointerEvent) => {
135
+ e.preventDefault();
136
+ e.stopPropagation();
137
+ const handle = e.currentTarget as HTMLElement;
138
+ const el = ui.blockEl(blockId);
139
+ if (!el) return;
140
+ const h0 = el.getBoundingClientRect().height, y0 = e.clientY;
141
+ handle.setPointerCapture(e.pointerId);
142
+ handle.classList.add("is-dragging");
143
+ const move = (ev: PointerEvent) => store.setAttrs([blockId], { height: `${Math.max(8, Math.round(h0 + ev.clientY - y0))}px` });
144
+ const up = () => {
145
+ handle.removeEventListener("pointermove", move); handle.removeEventListener("pointerup", up);
146
+ handle.classList.remove("is-dragging"); store.breakMerge(); focusCanvas(handle);
147
+ };
148
+ handle.addEventListener("pointermove", move);
149
+ handle.addEventListener("pointerup", up);
150
+ };
151
+ return (
152
+ <span className="ecx-pad-handles" contentEditable={false} aria-hidden="true">
153
+ <span className="ecx-pad-handle is-bottom" title={labels.resize} onPointerDown={start} onMouseDown={(e) => e.stopPropagation()} />
154
+ </span>
155
+ );
156
+ }
157
+
158
+ /**
159
+ * Vùng kéo đệm / lề trên, dưới của khối bố cục đang chọn (Nhóm, Bộ cột, Cột): vùng rộng hết khối, cao bằng giá trị thật; kéo đổi giá trị
160
+ * của khổ màn hình đang xem (lưu px, giữ các cạnh khác); rê / kéo thì vùng được tô kèm số px — như ô Đệm / Lề ở bảng bên phải.
161
+ */
162
+ export function PaddingHandles({ blockId }: { blockId: string }) {
163
+ const { store, ui, labels: v2 } = useEditor();
164
+ const L = labelsLegacy(v2.lang);
165
+ const ref = useRef<HTMLSpanElement>(null);
166
+ // Cỡ thật (px) của đệm / lề trên, dưới: vùng kéo cao đúng bằng nó (tối thiểu 8px) — kéo ở bất kỳ đâu trong vùng
167
+ const [px, setPx] = useState({ pt: 0, pb: 0, mt: 0, mb: 0 });
168
+ useLayoutEffect(() => {
169
+ const el = ui.blockEl(blockId);
170
+ if (!el) return;
171
+ const cs = el.ownerDocument.defaultView!.getComputedStyle(el), n = (k: string) => Math.round(parseFloat(cs.getPropertyValue(k)) || 0);
172
+ const next = { pt: n("padding-top"), pb: n("padding-bottom"), mt: n("margin-top"), mb: n("margin-bottom") };
173
+ setPx((p) => (p.pt === next.pt && p.pb === next.pb && p.mt === next.mt && p.mb === next.mb ? p : next));
174
+ });
175
+ const start = (kind: "padding" | "margin", side: "top" | "bottom", e: React.PointerEvent) => {
176
+ e.preventDefault();
177
+ e.stopPropagation();
178
+ const handle = e.currentTarget as HTMLElement;
179
+ const el = ui.blockEl(blockId);
180
+ if (!el) return;
181
+ const startPx = parseFloat(el.ownerDocument.defaultView!.getComputedStyle(el).getPropertyValue(`${kind}-${side}`)) || 0;
182
+ const y0 = e.clientY;
183
+ const device = ui.device === "desktop" ? "base" : ui.device;
184
+ handle.setPointerCapture(e.pointerId);
185
+ handle.classList.add("is-dragging");
186
+ const move = (ev: PointerEvent) => {
187
+ // Đệm dưới / lề dưới: kéo xuống là tăng; đệm trên: kéo xuống tăng; lề trên: kéo lên tăng
188
+ const d = ev.clientY - y0;
189
+ const px = Math.max(0, Math.round(startPx + (kind === "margin" && side === "top" ? -d : d)));
190
+ const node = store.block(blockId);
191
+ if (!node) return;
192
+ const style = (normalizeStyle(node.attrs.style) ?? {}) as BlockStyle & Record<"padding" | "margin", Record<string, unknown> | undefined>;
193
+ const cur = style[kind]?.[device];
194
+ const sides = typeof cur === "object" && cur ? { ...(cur as Record<string, string>) } : typeof cur === "string" ? { top: cur, right: cur, bottom: cur, left: cur } : {};
195
+ sides[side] = `${px}px`;
196
+ store.setAttrs([blockId], { style: normalizeStyle({ ...style, [kind]: { ...(style[kind] ?? {}), [device]: sides } }) ?? undefined });
197
+ requestAnimationFrame(() => showSpacingViz(ui.blockEl(blockId), kind, [side]));
198
+ };
199
+ const up = () => {
200
+ handle.removeEventListener("pointermove", move); handle.removeEventListener("pointerup", up);
201
+ handle.classList.remove("is-dragging"); hideSpacingViz(ui.canvasDoc); store.breakMerge(); focusCanvas(handle);
202
+ };
203
+ handle.addEventListener("pointermove", move);
204
+ handle.addEventListener("pointerup", up);
205
+ };
206
+ const zones = [
207
+ ["padding", "top", { top: 0, height: Math.max(8, px.pt) }],
208
+ ["padding", "bottom", { bottom: 0, height: Math.max(8, px.pb) }],
209
+ ["margin", "top", { top: -Math.max(8, px.mt), height: Math.max(8, px.mt) }],
210
+ ["margin", "bottom", { bottom: -Math.max(8, px.mb), height: Math.max(8, px.mb) }],
211
+ ] as const;
212
+ return (
213
+ <span ref={ref} className="ecx-pad-handles" contentEditable={false} aria-hidden="true">
214
+ {zones.map(([kind, side, pos]) => (
215
+ <span key={kind + side} className={`ecx-pad-zone is-${kind} is-${side}`} style={pos} title={kind === "padding" ? L.style_padding : L.style_margin} data-ecx-zone={`${kind}-${side}`}
216
+ onPointerDown={(e) => start(kind, side, e)} onMouseDown={(e) => e.stopPropagation()}
217
+ onPointerEnter={() => showSpacingViz(ui.blockEl(blockId), kind, [side])}
218
+ onPointerLeave={(e) => { if (!(e.currentTarget as HTMLElement).classList.contains("is-dragging")) hideSpacingViz(ui.canvasDoc); }} />
219
+ ))}
220
+ </span>
221
+ );
222
+ }
223
+
224
+ /**
225
+ * Tay kéo độ rộng nội dung bên trong của Nhóm: hai tay ở hai mép vùng nội dung (khối con đầu tiên); kéo vào / ra là đổi độ rộng đối xứng,
226
+ * số px hiện cạnh tay khi kéo. Kéo hết cỡ ra mép = về "Hết khối". Lưu vào `contentWidth` như ô ở bảng Cài đặt.
227
+ */
228
+ export function ContentWidthHandles({ blockId }: { blockId: string }) {
229
+ const { store, ui } = useEditor();
230
+ const [box, setBox] = useState<{ left: number; right: number; max: number } | null>(null);
231
+ const [drag, setDrag] = useState<number | null>(null);
232
+ /** Đo theo giá trị ràng buộc (max-width của khối con), không theo kích thước khối con — hàng ngang / lưới / xếp dọc làm khối con co theo chữ. */
233
+ const measure = () => {
234
+ const el = ui.blockEl(blockId), kid = el?.querySelector(":scope > [data-ecx-block]") as HTMLElement | null;
235
+ if (!el || !kid) return null;
236
+ const win = el.ownerDocument.defaultView!, cs = win.getComputedStyle(el), g = el.getBoundingClientRect();
237
+ const padL = parseFloat(cs.paddingLeft) || 0, max = Math.round(g.width - padL - (parseFloat(cs.paddingRight) || 0));
238
+ const mwRaw = win.getComputedStyle(kid).maxWidth, mw = mwRaw.endsWith("px") ? parseFloat(mwRaw) : NaN;
239
+ const width = Math.min(max, Number.isFinite(mw) ? Math.round(mw) : max);
240
+ const left = Math.round(padL + (max - width) / 2);
241
+ return { left, right: left + width, max, width };
242
+ };
243
+ useLayoutEffect(() => {
244
+ const m = measure();
245
+ setBox((p) => (!m ? null : p && p.left === m.left && p.right === m.right && p.max === m.max ? p : { left: m.left, right: m.right, max: m.max }));
246
+ });
247
+ const start = (dir: 1 | -1, e: React.PointerEvent) => {
248
+ e.preventDefault(); e.stopPropagation();
249
+ const handle = e.currentTarget as HTMLElement, m = measure();
250
+ if (!m) return;
251
+ const x0 = e.clientX;
252
+ handle.setPointerCapture(e.pointerId);
253
+ handle.classList.add("is-dragging");
254
+ const move = (ev: PointerEvent) => {
255
+ const w = Math.min(m.max, Math.max(240, Math.round(m.width + 2 * dir * (ev.clientX - x0))));
256
+ const node = store.block(blockId);
257
+ if (!node) return;
258
+ setDrag(w);
259
+ store.setAttrs([blockId], { constrained: undefined, contentWidth: w >= m.max ? undefined : `${w}px` });
260
+ };
261
+ const up = () => {
262
+ handle.removeEventListener("pointermove", move); handle.removeEventListener("pointerup", up);
263
+ handle.classList.remove("is-dragging"); setDrag(null); store.breakMerge(); focusCanvas(handle);
264
+ };
265
+ handle.addEventListener("pointermove", move);
266
+ handle.addEventListener("pointerup", up);
267
+ };
268
+ if (!box) return null;
269
+ return (
270
+ <span className="ecx-cw-handles" contentEditable={false} aria-hidden="true">
271
+ {([["left", box.left, -1], ["right", box.right, 1]] as const).map(([side, x, dir]) => (
272
+ <span key={side} className={`ecx-cw-handle is-${side}`} style={{ left: x }} data-ecx-zone={`content-width-${side}`}
273
+ onPointerDown={(e) => start(dir === 1 ? 1 : -1, e)} onMouseDown={(e) => e.stopPropagation()}>
274
+ {drag !== null && <span className="ecx-cw-tip">{drag}px</span>}
275
+ </span>
276
+ ))}
277
+ </span>
278
+ );
279
+ }
@@ -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";
@@ -10,9 +10,16 @@ import { useActiveWithin } from "./resize";
10
10
  import { BoundText, useBindingPreview } from "../ui/bindings";
11
11
  import { useMsgs } from "../i18n";
12
12
  import { useEditor } from "../context";
13
+ import { withoutOverridden } from "./inline-style";
13
14
 
14
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)
15
- 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 }; };
16
23
  const HEADING_ICONS = [Heading1, Heading1, Heading2, Heading3, Heading4, Heading5, Heading6];
17
24
 
18
25
  function ParagraphEdit({ block, blockProps, editable }: BlockEditProps) {
@@ -23,7 +30,7 @@ function ParagraphEdit({ block, blockProps, editable }: BlockEditProps) {
23
30
  // Gợi ý theo vai trò: mục danh sách / việc khác đoạn văn thường
24
31
  const parent = store.locate(block.id)?.parent?.type;
25
32
  const ph = parent === "listItem" ? tp.listItem : parent === "taskItem" ? tp.taskItem : tp.paragraph;
26
- return <RichText blockId={block.id} value={block.inline} tagName="p" blockProps={blockProps} style={align(block.attrs)} placeholder={ph} placeholderAlways editable={editable} />;
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} />;
27
34
  }
28
35
 
29
36
  function HeadingEdit({ block, blockProps, editable }: BlockEditProps) {
@@ -31,7 +38,7 @@ function HeadingEdit({ block, blockProps, editable }: BlockEditProps) {
31
38
  const level = Math.min(6, Math.max(1, Number(block.attrs.level) || 2));
32
39
  const bound = useBindingPreview(block, "content");
33
40
  if (bound.bound) return <BoundText tagName={`h${level}`} preview={bound} blockProps={blockProps} style={align(block.attrs, "heading")} />;
34
- return <RichText blockId={block.id} value={block.inline} tagName={`h${level}`} blockProps={blockProps} style={align(block.attrs, "heading")} placeholder={tp.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} />;
35
42
  }
36
43
 
37
44
  const CODE_LANGS = ["html", "css", "javascript", "typescript", "json", "bash", "python", "php", "sql", "csharp", "yaml", "markdown"];
@@ -141,12 +148,12 @@ export function textBlocks(): BlockType[] {
141
148
  return [
142
149
  {
143
150
  name: "paragraph", title: "Đoạn văn", icon: Pilcrow, category: "text", keywords: "doan van text paragraph p", kind: "text", edit: ParagraphEdit,
144
- 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" } },
145
152
  supports: { style: true, anchor: true, className: true }, transforms: textTransforms("paragraph"),
146
153
  },
147
154
  {
148
155
  name: "heading", title: "Tiêu đề", icon: Heading2, category: "text", keywords: "tieu de heading h1 h2 h3 h4", kind: "text", edit: HeadingEdit,
149
- 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" } },
150
157
  create: (attrs) => makeBlock("heading", { level: 2, ...attrs }),
151
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 })),
152
159
  supports: { style: true, anchor: true, className: true }, transforms: textTransforms("heading"),
@@ -178,7 +185,7 @@ export function textBlocks(): BlockType[] {
178
185
  },
179
186
  {
180
187
  name: "codeBlock", title: "Mã nguồn", icon: SquareCode, category: "text", keywords: "ma code nguon", kind: "text", edit: CodeEdit, multiline: true, plain: true,
181
- 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
182
189
  transforms: [{ to: "paragraph", convert: (b) => textsOf(b).map((i) => makeBlock("paragraph", {}, inlineText(i))) }, { to: "preformatted", convert: toTextBlocks("preformatted") }],
183
190
  },
184
191
  {
@@ -1,6 +1,7 @@
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";
1
+ import { ListFilter, 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, spacingValue } from "@ecomcx/ecomweb-content";
4
+ import { useChoices } from "../ui/attr-form";
4
5
  import { Block, DocBlocks, InnerBlocks, NestedDoc } from "../canvas/block-list";
5
6
  import { DocScopeProvider, LoopPostContext, useDocScope, useDynamicData, useEditor, useEditorState } from "../context";
6
7
  import type { DynamicPost, QueryArgs } from "../core/host";
@@ -73,7 +74,8 @@ function NavigationEdit({ block, blockProps, selected }: BlockEditProps) {
73
74
  const { labels } = useEditor();
74
75
  const location = String(block.attrs.location ?? "primary");
75
76
  const items = d.menus?.[location];
76
- const mobile = block.attrs.mobile !== false;
77
+ const overlay = ["never", "mobile", "tablet", "always"].includes(String(block.attrs.overlayMenu)) ? String(block.attrs.overlayMenu) : block.attrs.mobile === false ? "never" : "mobile";
78
+ const mobile = overlay !== "never";
77
79
  const t = useMsgs("blocks");
78
80
  const tp = useMsgs("placeholders");
79
81
  const { host } = useEditor();
@@ -94,9 +96,9 @@ function NavigationEdit({ block, blockProps, selected }: BlockEditProps) {
94
96
  }
95
97
  const menu = <nav className="ecx-navigation-menu" aria-label={location}><ul>{items.map((it, i) => <li key={i}><a href={it.url} onClick={(e) => e.preventDefault()}>{it.title}</a></li>)}</ul></nav>;
96
98
  return (
97
- <div {...merge(blockProps, cx("ecx-navigation", `ecx-navigation-${block.attrs.orientation ?? "horizontal"}`, mobile && "has-mobile"))}>
98
- <div className="ecx-navigation-items">{menu}</div>
99
- {mobile && <details className="ecx-navigation-toggle"><summary aria-label={t.menu}>☰</summary>{menu}</details>}
99
+ <div {...merge(blockProps, cx("ecx-navigation", `ecx-navigation-${block.attrs.orientation ?? "horizontal"}`, mobile && "has-mobile", overlay === "tablet" && "bp-tablet", overlay === "always" && "overlay-always"))}>
100
+ {overlay !== "always" && <div className="ecx-navigation-items">{menu}</div>}
101
+ {mobile && <div className="ecx-nav-drawer"><button type="button" className="ecx-nav-burger" tabIndex={-1} aria-label={t.menu}><svg viewBox="0 0 24 24" width={24} height={24} fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" aria-hidden="true" focusable="false"><path d="M4 7h16M4 12h16M4 17h16" /></svg></button></div>}
100
102
  <EditMenuButton location={location} selected={selected} />
101
103
  </div>
102
104
  );
@@ -105,16 +107,34 @@ function NavigationEdit({ block, blockProps, selected }: BlockEditProps) {
105
107
  function SearchEdit({ block, blockProps }: BlockEditProps) {
106
108
  const t = useMsgs("blocks");
107
109
  const pos = String(block.attrs.buttonPosition ?? "right");
108
- const button = <button type="button" tabIndex={-1}>{String(block.attrs.buttonText || t.searchButton)}</button>;
109
- return (
110
- <div {...merge(blockProps, "ecx-search")}>
111
- <form role="search" onSubmit={(e) => e.preventDefault()} style={pos === "below" ? { display: "flex", flexDirection: "column", gap: 8 } : undefined}
110
+ const label = String(block.attrs.buttonText || t.searchButton);
111
+ const button = block.attrs.buttonStyle === "icon"
112
+ ? <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>
113
+ : <button type="button" tabIndex={-1}>{label}</button>;
114
+ const collapse = block.attrs.collapse === "tablet" || block.attrs.collapse === "mobile" ? String(block.attrs.collapse) : undefined;
115
+ const form = (
116
+ <form role="search" data-ecx-inert="" onSubmit={(e) => e.preventDefault()} style={pos === "below" ? { display: "flex", flexDirection: "column", gap: 8 } : undefined}
112
117
  className={`search-form${pos !== "right" ? ` search-button-${pos}` : ""}`}>
113
118
  {block.attrs.showLabel === true && <label className="search-label">{t.searchLabel}</label>}
114
119
  {pos === "left" && button}
115
120
  <input type="search" placeholder={String(block.attrs.placeholder || t.searchPlaceholder)} aria-label={t.searchLabel} readOnly tabIndex={-1} />
121
+ {block.attrs.scopeSelect === true && (
122
+ <select className="search-scope" aria-label={t.searchScope} tabIndex={-1} onMouseDown={(e) => e.preventDefault()}>
123
+ <option>{t.searchAll}</option>
124
+ {String(block.attrs.scopes ?? "").split(",").map((x) => x.trim()).filter(Boolean).map((x) => { const [v, ...r] = x.split(":"); return <option key={x}>{r.join(":").trim() || v}</option>; })}
125
+ </select>
126
+ )}
116
127
  {pos !== "left" && button}
117
128
  </form>
129
+ );
130
+ return (
131
+ <div {...merge(blockProps, "ecx-search")}>
132
+ {collapse ? (
133
+ <div className={`ecx-search-collapse collapse-${collapse}`}>
134
+ <button type="button" className="ecx-search-toggle" tabIndex={-1} aria-label={label}><svg viewBox="0 0 24 24" width={20} height={20} fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" focusable="false"><path d={SEARCH_ICON_PATH} /></svg></button>
135
+ <div className="ecx-search-panel">{form}</div>
136
+ </div>
137
+ ) : form}
118
138
  </div>
119
139
  );
120
140
  }
@@ -193,7 +213,9 @@ function LoginOutEdit({ block, blockProps }: BlockEditProps) {
193
213
  function IconEdit({ block, blockProps }: BlockEditProps) {
194
214
  const size = Math.min(128, Math.max(12, Number(block.attrs.size) || 24));
195
215
  const path = ICON_PATHS[String(block.attrs.name ?? "star")] ?? ICON_PATHS.star;
196
- 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>;
216
+ const stroke = Math.min(4, Math.max(0.5, Number(block.attrs.stroke) || 2));
217
+ const shape = block.attrs.iconStyle === "circle" || block.attrs.iconStyle === "square" ? block.attrs.iconStyle : undefined;
218
+ 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>;
197
219
  }
198
220
  function FootnotesEdit({ block, blockProps }: BlockEditProps) {
199
221
  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>;
@@ -333,6 +355,7 @@ export function queryArgs(a: Record<string, unknown>): QueryArgs {
333
355
  inherit: a.inherit !== false, postType: typeof a.postType === "string" && a.postType ? a.postType : "post",
334
356
  perPage: Math.min(100, Math.max(1, Number(a.perPage) || 10)),
335
357
  category: typeof a.category === "string" && a.category ? a.category : undefined, tag: typeof a.tag === "string" && a.tag ? a.tag : undefined,
358
+ taxonomy: typeof a.taxonomy === "string" && a.taxonomy && (a.term || a.terms) ? a.taxonomy : undefined, term: typeof a.term === "string" && a.term ? a.term : typeof a.terms === "string" && a.terms ? a.terms.split(",")[0].trim() : undefined,
336
359
  orderBy: typeof a.orderBy === "string" ? a.orderBy : "date", order: a.order === "asc" ? "asc" : "desc",
337
360
  };
338
361
  }
@@ -369,14 +392,17 @@ function PostTemplateEdit({ block, blockProps, editable, labels }: BlockEditProp
369
392
  const q = queryArgs(queryAttrs);
370
393
  const posts = useQueryPosts(q);
371
394
  const [active, setActive] = useState(0);
372
- const grid = block.attrs.layout === "grid";
395
+ const grid = block.attrs.layout === "grid" || block.attrs.layout === "carousel";
396
+ const carousel = block.attrs.layout === "carousel";
397
+ const responsive = block.attrs.layout === "grid" && (Number(block.attrs.columnsTablet) > 0 || Number(block.attrs.columnsMobile) > 0);
373
398
  const cols = Math.min(6, Math.max(1, Number(block.attrs.columns) || 3));
374
- const count = posts ? Math.max(1, Math.min(posts.length, q.perPage, 6)) : 3;
399
+ const gap = spacingValue(block.attrs.gap) ?? "1.5rem";
400
+ const count = posts ? Math.max(1, Math.min(posts.length, q.perPage, carousel ? cols : 6)) : 3;
375
401
  const current = Math.min(active, count - 1);
376
402
  const t = useMsgs("blocks");
377
403
  const tp = useMsgs("placeholders");
378
404
  return (
379
- <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 : ""}>
405
+ <ul {...(merge(blockProps, cx("ecx-post-template", grid && "is-grid", responsive && "is-responsive"), responsive ? { "--per": cols, "--per-tablet": Number(block.attrs.columnsTablet) || Math.min(cols, 3), "--per-mobile": Number(block.attrs.columnsMobile) || Math.min(cols, 2), "--gap": gap } as CSSProperties : grid ? { display: "grid", gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))`, gap } : undefined) as object)} data-ecx-posts={posts ? posts.length : ""}>
380
406
  {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>}
381
407
  {Array.from({ length: count }, (_, i) => {
382
408
  const post = posts?.[i] ?? null;
@@ -404,6 +430,23 @@ function PaginationEdit({ block, blockProps }: BlockEditProps) {
404
430
  const single = posts !== undefined && posts.length < perPage;
405
431
  return <nav {...(merge(blockProps, cx("ecx-pagination", single && "is-single")) as object)} style={single ? { opacity: 0.45 } : undefined}>{single ? "‹ 1 ›" : "‹ 1 2 3 ›"}</nav>;
406
432
  }
433
+ /** Thanh lọc: cùng markup với website (QueryFilterBar) — mục phân loại thật lấy từ ứng dụng, không có thì mục mẫu. */
434
+ function QueryFilterEdit({ block, blockProps }: BlockEditProps) {
435
+ const t = useMsgs("blocks");
436
+ const a = block.attrs;
437
+ const style = ["none", "links", "chips", "select"].includes(String(a.termStyle)) ? String(a.termStyle) : "links";
438
+ const choices = useChoices("term", { taxonomy: String(a.taxonomy ?? "") });
439
+ const names = (a.taxonomy ? choices : null)?.map((c) => c.label).slice(0, 8) ?? ["Danh mục 1", "Danh mục 2", "Danh mục 3"];
440
+ return (
441
+ <div {...merge(blockProps, "ecx-query-filter")}>
442
+ {style === "select" && <select tabIndex={-1} aria-label={String(a.taxonomy ?? "")}><option>{String(a.allLabel || t.filterAll)}</option></select>}
443
+ {(style === "links" || style === "chips") && <nav className="ecx-filter-terms"><a className="is-active">{String(a.allLabel || t.filterAll)}</a>{names.map((n) => <a key={n}>{n}</a>)}</nav>}
444
+ {a.showSearch === true && <input type="search" readOnly tabIndex={-1} placeholder={String(a.placeholder || t.filterSearch)} />}
445
+ {a.showSort === true && <select tabIndex={-1} aria-label={t.filterSort}><option>{t.filterNewest}</option></select>}
446
+ {style === "none" && !a.showSearch && !a.showSort && <span className="ecx-muted">{t.filterEmpty}</span>}
447
+ </div>
448
+ );
449
+ }
407
450
  function QueryEmptyEdit({ block, blockProps, labels }: BlockEditProps) {
408
451
  const { posts } = useParentQueryPosts(block);
409
452
  // Danh sách đang có bài → khối "không có bài" không hiện trên website: thu gọn thành nhãn mờ (vẫn chọn / sửa được khi bấm vào)
@@ -453,8 +496,8 @@ export function themeBlocks(): BlockType[] {
453
496
  { name: "siteTitle", title: "Tên website", icon: Type, category: theme, keywords: "ten website site title", kind: "atom", edit: SiteTitleEdit, attributes: { level: { type: "integer", default: 0, min: 0, max: 6 }, link: { type: "boolean", default: true }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
454
497
  { 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 } },
455
498
  { 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 } },
456
- { 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 },
457
- { 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 } },
499
+ { 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", "tablet", "always"], default: "mobile" } }, supports: { style: true, className: true }, summary: (a) => a.location },
500
+ { 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" }, scopeSelect: { type: "boolean", default: false }, scopes: { type: "string" }, collapse: { type: "string", enum: ["never", "tablet", "mobile"], default: "never" } }, supports: { style: true, className: true } },
458
501
  { 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 } },
459
502
  { 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 } },
460
503
  { 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 } },
@@ -471,7 +514,7 @@ export function themeBlocks(): BlockType[] {
471
514
  { 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"] } },
472
515
  { 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 },
473
516
  { 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 } },
474
- { 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 },
517
+ { 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 },
475
518
  { 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 } },
476
519
  { name: "pageBreak", title: "Ngắt trang", icon: PanelTop, category: theme, keywords: "ngat trang page break nextpage", kind: "atom", edit: PageBreakEdit, supports: { className: true } },
477
520
  { 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 } },
@@ -482,13 +525,14 @@ export function themeBlocks(): BlockType[] {
482
525
  { name: "postNavigation", title: "Bài trước / bài sau", icon: ArrowLeftRight, category: theme, keywords: "bai truoc bai sau dieu huong post navigation", kind: "atom", edit: PostNavigationEdit, attributes: { showTitle: { type: "boolean", default: true } }, supports: { style: true, className: true } },
483
526
  {
484
527
  name: "query", title: "Danh sách bài", icon: Rows3, category: theme, keywords: "danh sach bai query loop tin tuc", kind: "container", edit: QueryEdit,
485
- 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 } },
528
+ 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" }, taxonomy: { type: "string" }, term: { type: "string" }, terms: { type: "string" }, termMode: { type: "string", enum: ["any", "all", "none"], default: "any" }, source: { type: "string", enum: ["latest", "manual", "related"], default: "latest" }, include: { type: "string" }, metaKey: { type: "string" }, metaCompare: { type: "string", enum: ["=", "!=", ">", ">=", "<", "<=", "LIKE", "EXISTS", "NOT EXISTS"], default: "=" }, metaValue: { type: "string" }, metaValue2: { type: "string" }, dateRange: { type: "string", enum: ["any", "7", "30", "90", "365"], default: "any" }, after: { type: "string" }, before: { type: "string" }, parent: { type: "integer", min: 1 }, offset: { type: "integer", min: 0, max: 1000 }, excludeCurrent: { type: "boolean", default: true }, authorCurrent: { type: "boolean", default: false }, urlFilters: { type: "boolean", default: false }, 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 } },
486
529
  // 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)
487
530
  create: () => makeBlock("query", { inherit: true }, []),
488
531
  supports: { style: true, className: true },
489
532
  },
490
- { 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"] } },
533
+ { name: "postTemplate", title: "Khuôn mỗi bài", icon: LayoutTemplate, kind: "container", edit: PostTemplateEdit, hidden: true, attributes: { layout: { type: "string", enum: ["list", "grid", "carousel"], default: "list" }, columns: { type: "integer", default: 3, min: 1, max: 6 }, columnsTablet: { type: "integer", min: 1, max: 6 }, columnsMobile: { type: "integer", min: 1, max: 4 }, gap: { type: "string" }, arrows: { type: "boolean", default: true } }, structure: { parents: ["query"] } },
491
534
  { name: "pagination", title: "Phân trang", icon: ListOrdered, kind: "atom", edit: PaginationEdit, attributes: { type: { type: "string", enum: ["numbers", "prevNext", "both"], default: "both" }, midSize: { type: "integer", default: 2, min: 0, max: 5 } }, hidden: true, structure: { parents: ["query"] } },
535
+ { name: "queryFilter", title: "Thanh lọc", icon: ListFilter, category: theme, keywords: "loc bo loc thanh loc filter danh muc sap xep tim", kind: "atom", edit: QueryFilterEdit, attributes: { taxonomy: { type: "string" }, termStyle: { type: "string", enum: ["none", "links", "chips", "select"], default: "links" }, allLabel: { type: "string" }, showSearch: { type: "boolean", default: false }, showSort: { type: "boolean", default: false }, sortOptions: { type: "string" }, placeholder: { type: "string" }, submitText: { type: "string" }, action: { type: "string" } }, supports: { style: true, className: true, align: true } },
492
536
  { name: "queryEmpty", title: "Khi không có bài", icon: SquareDashed, kind: "container", edit: QueryEmptyEdit, hidden: true, structure: { parents: ["query"] } },
493
537
  { name: "templatePart", title: "Phần dùng chung", icon: PanelTop, category: theme, keywords: "phan dung chung template part header footer", kind: "atom", edit: TemplatePartEdit, attributes: { slug: { type: "string" }, tagName: { type: "string", enum: ["div", "header", "footer", "aside", "section"], default: "div" } }, summary: (a) => a.slug },
494
538
  { name: "syncedPattern", title: "Mẫu đồng bộ", icon: Repeat2, category: "widgets", keywords: "mau dong bo synced pattern reusable", kind: "atom", edit: SyncedPatternEdit, attributes: { ref: { type: "integer" } }, hidden: true },
@@ -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
  }