@ecomcx/ecomweb-editor 1.31.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.
- package/package.json +3 -3
- package/src/locales/en/attrs.ts +10 -0
- package/src/locales/en/background.ts +17 -0
- package/src/locales/en/block-desc.ts +1 -0
- package/src/locales/en/block-style.ts +7 -4
- package/src/locales/en/block-titles.ts +1 -0
- package/src/locales/en/blocks.ts +10 -2
- package/src/locales/en/columns.ts +12 -0
- package/src/locales/en/controls.ts +21 -0
- package/src/locales/en/hints.ts +215 -1
- package/src/locales/en/index.ts +5 -2
- package/src/locales/en/layout.ts +32 -0
- package/src/locales/en/legacy.ts +1 -1
- package/src/locales/en/library.ts +38 -0
- package/src/locales/en/parts.ts +12 -0
- package/src/locales/en/placeholders.ts +9 -1
- package/src/locales/en/presets.ts +6 -0
- package/src/locales/en/v2.ts +21 -0
- package/src/locales/vi/attrs.ts +10 -0
- package/src/locales/vi/background.ts +17 -0
- package/src/locales/vi/block-desc.ts +1 -0
- package/src/locales/vi/block-style.ts +7 -4
- package/src/locales/vi/block-titles.ts +1 -0
- package/src/locales/vi/blocks.ts +10 -2
- package/src/locales/vi/columns.ts +12 -0
- package/src/locales/vi/controls.ts +21 -0
- package/src/locales/vi/hints.ts +216 -2
- package/src/locales/vi/index.ts +5 -2
- package/src/locales/vi/layout.ts +32 -0
- package/src/locales/vi/legacy.ts +1 -1
- package/src/locales/vi/library.ts +38 -0
- package/src/locales/vi/parts.ts +12 -0
- package/src/locales/vi/placeholders.ts +9 -1
- package/src/locales/vi/presets.ts +6 -0
- package/src/locales/vi/v2.ts +21 -0
- package/src/shared/panel-store.ts +3 -3
- package/src/shared/patterns.ts +3 -52
- package/src/shared/style-panel.tsx +2 -2
- package/src/shared/types.ts +2 -0
- package/src/v2/blocks/columns-inspector.tsx +210 -0
- package/src/v2/blocks/form.tsx +4 -4
- package/src/v2/blocks/index.ts +10 -4
- package/src/v2/blocks/inline-style.ts +1 -1
- package/src/v2/blocks/layout.tsx +173 -42
- package/src/v2/blocks/media.tsx +22 -13
- package/src/v2/blocks/resize.tsx +172 -4
- package/src/v2/blocks/text.tsx +14 -7
- package/src/v2/blocks/theme.tsx +10 -5
- package/src/v2/blocks/tools.tsx +50 -5
- package/src/v2/blocks/widgets.tsx +44 -16
- package/src/v2/canvas/block-list.tsx +17 -2
- package/src/v2/canvas/canvas-css.ts +54 -4
- package/src/v2/canvas/canvas.tsx +20 -3
- package/src/v2/canvas/dnd.ts +34 -3
- package/src/v2/canvas/move-animation.ts +94 -0
- package/src/v2/canvas/spacing-viz.ts +51 -0
- package/src/v2/core/block-presets.ts +68 -0
- package/src/v2/core/host.ts +5 -0
- package/src/v2/core/structure.ts +2 -1
- package/src/v2/editor.css +238 -9
- package/src/v2/editor.tsx +8 -2
- package/src/v2/ui/attr-form.tsx +40 -11
- package/src/v2/ui/attr-hints.ts +104 -6
- package/src/v2/ui/background-panel.tsx +65 -21
- package/src/v2/ui/block-icons.tsx +152 -0
- package/src/v2/ui/block-menu.ts +22 -0
- package/src/v2/ui/block-style-panel.tsx +14 -3
- package/src/v2/ui/color-field.tsx +74 -9
- package/src/v2/ui/divider-panel.tsx +58 -0
- package/src/v2/ui/group-width.tsx +38 -0
- package/src/v2/ui/icon-picker.tsx +51 -0
- package/src/v2/ui/inserter.tsx +51 -7
- package/src/v2/ui/inspector.tsx +48 -16
- package/src/v2/ui/layout-panel.tsx +5 -47
- package/src/v2/ui/list-view.tsx +81 -7
- package/src/v2/ui/motion-panel.tsx +2 -1
- package/src/v2/ui/parts-panel.tsx +164 -0
- package/src/v2/ui/pattern-library.tsx +228 -0
- package/src/v2/ui/preset-bar.tsx +83 -0
- package/src/v2/ui/style-controls.tsx +65 -15
- package/src/v2/ui/style-supports.ts +1 -1
- package/src/v2/ui/style-tab.tsx +127 -41
- package/src/v2/ui/toolbar.tsx +52 -13
- package/src/v2/ui/unit-controls.tsx +88 -39
- package/src/locales/en/patterns.ts +0 -50
- package/src/locales/vi/patterns.ts +0 -50
- package/src/shared/patterns-kit.ts +0 -7
- package/src/shared/patterns-library.ts +0 -172
package/src/v2/blocks/resize.tsx
CHANGED
|
@@ -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
|
-
|
|
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
|
+
}
|
package/src/v2/blocks/text.tsx
CHANGED
|
@@ -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
|
-
|
|
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",
|
|
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
|
{
|
package/src/v2/blocks/theme.tsx
CHANGED
|
@@ -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";
|
|
@@ -105,7 +105,10 @@ function NavigationEdit({ block, blockProps, selected }: BlockEditProps) {
|
|
|
105
105
|
function SearchEdit({ block, blockProps }: BlockEditProps) {
|
|
106
106
|
const t = useMsgs("blocks");
|
|
107
107
|
const pos = String(block.attrs.buttonPosition ?? "right");
|
|
108
|
-
const
|
|
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>;
|
|
109
112
|
return (
|
|
110
113
|
<div {...merge(blockProps, "ecx-search")}>
|
|
111
114
|
<form role="search" onSubmit={(e) => e.preventDefault()} style={pos === "below" ? { display: "flex", flexDirection: "column", gap: 8 } : undefined}
|
|
@@ -193,7 +196,9 @@ function LoginOutEdit({ block, blockProps }: BlockEditProps) {
|
|
|
193
196
|
function IconEdit({ block, blockProps }: BlockEditProps) {
|
|
194
197
|
const size = Math.min(128, Math.max(12, Number(block.attrs.size) || 24));
|
|
195
198
|
const path = ICON_PATHS[String(block.attrs.name ?? "star")] ?? ICON_PATHS.star;
|
|
196
|
-
|
|
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>;
|
|
197
202
|
}
|
|
198
203
|
function FootnotesEdit({ block, blockProps }: BlockEditProps) {
|
|
199
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>;
|
|
@@ -454,7 +459,7 @@ export function themeBlocks(): BlockType[] {
|
|
|
454
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 } },
|
|
455
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 } },
|
|
456
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 },
|
|
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 } },
|
|
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 } },
|
|
458
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 } },
|
|
459
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 } },
|
|
460
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 } },
|
|
@@ -471,7 +476,7 @@ export function themeBlocks(): BlockType[] {
|
|
|
471
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"] } },
|
|
472
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 },
|
|
473
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 } },
|
|
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 },
|
|
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 },
|
|
475
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 } },
|
|
476
481
|
{ name: "pageBreak", title: "Ngắt trang", icon: PanelTop, category: theme, keywords: "ngat trang page break nextpage", kind: "atom", edit: PageBreakEdit, supports: { className: true } },
|
|
477
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 } },
|
package/src/v2/blocks/tools.tsx
CHANGED
|
@@ -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
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { CORE_NODES, ICON_NAMES, ICON_PATHS, widgetMarkup, type WidgetEl } from "@ecomcx/ecomweb-content";
|
|
2
|
-
import { BarChart3, Hash, Image as ImageIcon, ListChecks, Quote, Star } from "lucide-react";
|
|
1
|
+
import { CORE_NODES, ICON_NAMES, ICON_PATHS, iconListClass, widgetMarkup, type WidgetEl } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { BarChart3, Hash, Image as ImageIcon, ListChecks, MapPin, Quote, Star } from "lucide-react";
|
|
3
3
|
import { createElement, type CSSProperties, type ReactNode } from "react";
|
|
4
4
|
import { makeBlock } from "../core/model";
|
|
5
5
|
import type { BlockEditProps, BlockType } from "../core/registry";
|
|
6
6
|
import { useMsgs } from "../i18n";
|
|
7
7
|
import { messages } from "../../i18n";
|
|
8
8
|
import { RichText } from "../text/rich-text";
|
|
9
|
-
import {
|
|
9
|
+
import { Section } from "../ui/style-controls";
|
|
10
10
|
import { MediaPick } from "./layout";
|
|
11
11
|
import { useActiveWithin } from "./resize";
|
|
12
12
|
import { AddItemButton, TextPlaceholder } from "../ui/placeholders";
|
|
@@ -18,7 +18,7 @@ const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "strin
|
|
|
18
18
|
* Ô chữ (`field`) gõ trực tiếp trên khối, chỗ ảnh trống (`slot`) là ô chọn ảnh; số / thanh tiến độ hiện giá trị cuối (không chạy hiệu ứng).
|
|
19
19
|
*/
|
|
20
20
|
/** Gợi ý của từng ô chữ theo khối (không còn chữ mẫu thật dễ quên sửa). */
|
|
21
|
-
const FIELD_PH: Record<string, string> = { title: "boxTitle", text: "boxText", quote: "testimonialQuote", name: "testimonialName", role: "testimonialRole", label: "skill" };
|
|
21
|
+
const FIELD_PH: Record<string, string> = { title: "boxTitle", text: "boxText", quote: "testimonialQuote", name: "testimonialName", role: "testimonialRole", label: "skill", address: "mapAddress" };
|
|
22
22
|
|
|
23
23
|
function WidgetEdit(props: BlockEditProps) {
|
|
24
24
|
const { block, blockProps, setAttrs, editable } = props;
|
|
@@ -59,9 +59,10 @@ function IconListEdit({ block, blockProps, setAttrs, editable }: BlockEditProps)
|
|
|
59
59
|
const items: Array<{ text: string; href?: string; icon?: string }> = Array.isArray(block.attrs.items) ? block.attrs.items : [];
|
|
60
60
|
const list = items.length || !editable ? items : [{ text: "" }];
|
|
61
61
|
const save = (next: typeof items) => setAttrs({ items: next });
|
|
62
|
-
const
|
|
62
|
+
const stroke = Math.min(4, Math.max(0.5, Number(block.attrs.stroke) || 2));
|
|
63
|
+
const icon = (name?: string) => name === "none" ? null : <svg className="ecx-widget-icon" viewBox="0 0 24 24" width={24} height={24} fill="none" stroke="currentColor" strokeWidth={stroke} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" focusable="false"><path d={ICON_PATHS[String(name ?? "")] ?? ICON_PATHS[String(block.attrs.icon ?? "check")] ?? ICON_PATHS.check} /></svg>;
|
|
63
64
|
return (
|
|
64
|
-
<ul {...blockProps} className={cx(blockProps.className,
|
|
65
|
+
<ul {...blockProps} className={cx(blockProps.className, iconListClass(block.attrs))}>
|
|
65
66
|
{list.map((it, i) => (
|
|
66
67
|
<li key={i}>{icon(it.icon)}{editable
|
|
67
68
|
? <TextPlaceholder value={it.text} placeholder={i === 0 ? tp.iconListItem : `${tp.addRow}…`} label={`${tp.addRow} ${i + 1}`} onChange={(v) => save(list.map((x, k) => (k === i ? { ...x, text: v } : x)))} />
|
|
@@ -72,19 +73,44 @@ function IconListEdit({ block, blockProps, setAttrs, editable }: BlockEditProps)
|
|
|
72
73
|
);
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
/**
|
|
76
|
+
/** Các mục của Icon List: mỗi mục một hàng — chữ, icon riêng (theo danh sách / tên icon / không icon), liên kết; thêm / xoá mục. Dòng trống website bỏ qua. */
|
|
76
77
|
function IconListInspector({ attrs, setAttrs }: BlockEditProps) {
|
|
77
78
|
const t = useMsgs("blocks") as Record<string, string>;
|
|
79
|
+
const h = useMsgs("hints") as Record<string, string>;
|
|
78
80
|
const items: Array<{ text: string; href?: string; icon?: string }> = Array.isArray(attrs.items) ? attrs.items : [];
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
const patch = (i: number, p: Record<string, string | undefined>) => setAttrs({ items: items.map((x, k) => {
|
|
82
|
+
if (k !== i) return x;
|
|
83
|
+
const next: Record<string, unknown> = { ...x, ...p };
|
|
84
|
+
for (const key of Object.keys(next)) if (next[key] === undefined || (key !== "text" && next[key] === "")) delete next[key];
|
|
85
|
+
return next;
|
|
86
|
+
}) });
|
|
87
|
+
return (
|
|
88
|
+
<Section title={t.iconListItems} defaultOpen>
|
|
89
|
+
{items.map((it, i) => (
|
|
90
|
+
<div key={i} className="ecx-item-row" data-icon-list-item>
|
|
91
|
+
<input className="ecx-input" aria-label={`${t.iconListText} ${i + 1}`} placeholder={t.iconListText} value={it.text ?? ""} onChange={(e) => patch(i, { text: e.target.value })} />
|
|
92
|
+
<div className="ecx-item-row-sub">
|
|
93
|
+
<select className="ecx-input" aria-label={`${t.iconListIcon} ${i + 1}`} value={it.icon ?? ""} onChange={(e) => patch(i, { icon: e.target.value || undefined })}>
|
|
94
|
+
<option value="">{t.iconListIconDefault}</option>
|
|
95
|
+
<option value="none">{t.iconListIconNone}</option>
|
|
96
|
+
{ICON_NAMES.map((n) => <option key={n} value={n}>{h[`iconList.icon.opt.${n}`] ?? n}</option>)}
|
|
97
|
+
</select>
|
|
98
|
+
<input className="ecx-input" type="url" inputMode="url" aria-label={`${t.iconListLink} ${i + 1}`} placeholder={t.iconListLink} value={it.href ?? ""} onChange={(e) => patch(i, { href: e.target.value || undefined })} />
|
|
99
|
+
<button type="button" className="ecx-tool" aria-label={`${t.iconListRemove} ${i + 1}`} title={t.iconListRemove} onClick={() => setAttrs({ items: items.filter((_, k) => k !== i) })}>×</button>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
))}
|
|
103
|
+
{items.length < 50 && <button type="button" className="ecx-btn" onClick={() => setAttrs({ items: [...items, { text: "" }] })}>+ {t.iconListAdd}</button>}
|
|
104
|
+
</Section>
|
|
105
|
+
);
|
|
85
106
|
}
|
|
86
107
|
|
|
87
108
|
const spec = (name: string) => CORE_NODES[name]?.attrs;
|
|
109
|
+
/** Thứ tự ô ở bảng phải: phần đầu hộp (icon / ảnh / số) trước, rồi chữ, rồi liên kết. Ô không kể tên giữ thứ tự cũ ở cuối. */
|
|
110
|
+
const ICON_BOX_ORDER = ["media", "icon", "number", "src", "alt", "width", "height", "iconStyle", "position", "verticalAlign", "hover", "title", "text", "level", "textAlign", "href", "linkMode", "buttonText", "fullHeight"];
|
|
111
|
+
function ordered<T>(attrs: Record<string, T>, order: string[]): Record<string, T> {
|
|
112
|
+
return Object.fromEntries([...order.filter((k) => k in attrs), ...Object.keys(attrs).filter((k) => !order.includes(k))].map((k) => [k, attrs[k]]));
|
|
113
|
+
}
|
|
88
114
|
const ICON_SELECT = { type: "string" as const, enum: ICON_NAMES };
|
|
89
115
|
|
|
90
116
|
/** Khối widget của lõi; `lang` = ngôn ngữ của trình soạn (chữ mẫu khi chèn). */
|
|
@@ -92,11 +118,13 @@ export function widgetBlocks(lang?: string): BlockType[] {
|
|
|
92
118
|
const m = messages("blocks", lang) as Record<string, string>;
|
|
93
119
|
const base = { kind: "atom" as const, category: "widgets", edit: WidgetEdit, supports: { style: true, anchor: true, className: true } };
|
|
94
120
|
return [
|
|
95
|
-
{ ...base, name: "iconBox", title: "Icon Box", icon: Star, keywords: "icon box hop bieu tuong tinh nang dich vu feature", attributes: { ...spec("iconBox"), icon: { ...ICON_SELECT, default: "star" } }, create: () => makeBlock("iconBox", { icon: "star", title: "", text: "" }), summary: (a) => a.title },
|
|
96
|
-
|
|
121
|
+
{ ...base, name: "iconBox", title: "Icon Box", icon: Star, keywords: "icon box hop bieu tuong tinh nang dich vu feature", attributes: ordered({ ...spec("iconBox"), icon: { ...ICON_SELECT, default: "star" }, src: { type: "url", control: "media" } }, ICON_BOX_ORDER), create: () => makeBlock("iconBox", { icon: "star", title: "", text: "" }), summary: (a) => a.title },
|
|
122
|
+
// Hộp ảnh đã gộp vào Hộp icon (media = ảnh): ẩn khỏi trình chèn, nội dung cũ vẫn sửa được
|
|
123
|
+
{ ...base, hidden: true, name: "imageBox", title: "Image Box", icon: ImageIcon, keywords: "image box hop anh the card dich vu", attributes: { ...spec("imageBox"), src: { type: "url", control: "media" } }, create: () => makeBlock("imageBox", { title: "", text: "" }), summary: (a) => a.title },
|
|
97
124
|
{ ...base, name: "iconList", title: "Icon List", icon: ListChecks, keywords: "icon list danh sach bieu tuong loi ich checklist", inspector: IconListInspector, attributes: { ...spec("iconList"), icon: { ...ICON_SELECT, default: "check" } }, create: () => makeBlock("iconList", { items: [{ text: "" }, { text: "" }] }) },
|
|
98
125
|
{ ...base, name: "counter", title: "Counter", icon: Hash, keywords: "counter dem so con so thong ke number", attributes: spec("counter"), create: () => makeBlock("counter", { end: 0, suffix: "+", title: "", textAlign: "center" }), summary: (a) => a.title },
|
|
99
|
-
{ ...base, name: "testimonial", title: "Testimonial", icon: Quote, keywords: "testimonial loi chung thuc danh gia khach hang review", attributes: { ...spec("testimonial"), src: { type: "url", control: "media" } }, create: () => makeBlock("testimonial", { quote: "", name: "", role: "" }), summary: (a) => a.name },
|
|
126
|
+
{ ...base, name: "testimonial", title: "Testimonial", icon: Quote, keywords: "testimonial loi chung thuc danh gia khach hang review", attributes: ordered({ ...spec("testimonial"), src: { type: "url", control: "media" } }, ["variant", "quoteMark", "rating", "quote", "name", "role", "src", "alt", "textAlign"]), create: () => makeBlock("testimonial", { quote: "", name: "", role: "" }), summary: (a) => a.name },
|
|
127
|
+
{ ...base, name: "map", title: "Map", icon: MapPin, keywords: "map ban do dia chi google maps vi tri", attributes: ordered(spec("map") ?? {}, ["address", "title", "zoom", "height", "mapType"]), create: () => makeBlock("map", { address: "" }), summary: (a) => a.address },
|
|
100
128
|
{ ...base, name: "progressBar", title: "Progress Bar", icon: BarChart3, keywords: "progress bar thanh tien do ky nang phan tram", attributes: spec("progressBar"), create: () => makeBlock("progressBar", { label: "", value: 80 }), summary: (a) => a.label },
|
|
101
129
|
];
|
|
102
130
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { controlsCss, normalizeStyle, styleClass, widthClass } from "@ecomcx/ecomweb-content";
|
|
2
2
|
import { blockControls } from "../../shared/panel-store";
|
|
3
|
-
import { Component, memo, useCallback, useContext, useEffect, useMemo, useRef, type ErrorInfo, type MouseEvent, type ReactElement, type ReactNode } from "react";
|
|
3
|
+
import { Component, memo, useCallback, useContext, useEffect, useMemo, useRef, type ErrorInfo, type MouseEvent, type PointerEvent, type ReactElement, type ReactNode } from "react";
|
|
4
4
|
import { DocScopeProvider, LoopPostContext, useDocScope, useEditor, useEditorState } from "../context";
|
|
5
5
|
import { ServerBlock } from "./server-block";
|
|
6
|
+
import { startDrag } from "./dnd";
|
|
6
7
|
import { docIdOf, type NestedDocRef } from "../core/host";
|
|
7
8
|
import { blocksFromDoc, makeBlock, type BNode } from "../core/model";
|
|
8
9
|
import type { BlockEditProps, BlockProps } from "../core/registry";
|
|
@@ -22,7 +23,8 @@ export function sectionOf(store: ReturnType<typeof useEditor>["store"], el: HTML
|
|
|
22
23
|
|
|
23
24
|
/** Props gắn vào phần tử gốc của khối: chọn, viền, kiểu dáng, neo. */
|
|
24
25
|
export function useBlockProps(block: BNode, state: { selected: boolean; editing: boolean; mode: EditingMode }): BlockProps {
|
|
25
|
-
const
|
|
26
|
+
const ctx = useEditor();
|
|
27
|
+
const { store, registry, ui } = ctx;
|
|
26
28
|
const a = block.attrs;
|
|
27
29
|
const style = a.style && typeof a.style === "object" ? normalizeStyle(a.style) : undefined;
|
|
28
30
|
const type = registry.get(block.type);
|
|
@@ -60,6 +62,18 @@ export function useBlockProps(block: BNode, state: { selected: boolean; editing:
|
|
|
60
62
|
if (own.isContentEditable) own.ownerDocument.querySelector<HTMLElement>(".ecx-canvas-root")?.focus({ preventScroll: true });
|
|
61
63
|
else own.focus({ preventScroll: true });
|
|
62
64
|
}, [block.id, store, ui]);
|
|
65
|
+
// Khối bố cục đang chọn: nắm chỗ trống (không phải chữ, ô nhập, khối con) rồi kéo = đổi chỗ như tay nắm ⠿ (bấm thường vẫn là bấm)
|
|
66
|
+
const grab = state.selected && type?.kind !== "text";
|
|
67
|
+
const onPointerDown = useCallback((e: PointerEvent<HTMLElement>) => {
|
|
68
|
+
const t = e.target as HTMLElement;
|
|
69
|
+
if (e.button !== 0 || e.shiftKey || e.metaKey || e.ctrlKey || ui.zoomOut) return;
|
|
70
|
+
if (t.closest("[data-ecx-block]")?.getAttribute("data-ecx-block") !== block.id) return;
|
|
71
|
+
// Chỉ xét trong khối (cả khung soạn là contenteditable)
|
|
72
|
+
const hit = t.closest("[data-ecx-rich], input, textarea, select, button, a, [contenteditable=true], .ecx-pad-handles, .ecx-col-handles, .ecx-image-handle");
|
|
73
|
+
if (hit && e.currentTarget.contains(hit)) return;
|
|
74
|
+
const ids = store.getState().selection.ids;
|
|
75
|
+
startDrag(ctx, e, ids.includes(block.id) ? ids : [block.id]);
|
|
76
|
+
}, [block.id, ctx, store, ui]);
|
|
63
77
|
return {
|
|
64
78
|
ref: null,
|
|
65
79
|
"data-ecx-block": block.id,
|
|
@@ -78,6 +92,7 @@ export function useBlockProps(block: BNode, state: { selected: boolean; editing:
|
|
|
78
92
|
typeof a.className === "string" && a.className,
|
|
79
93
|
),
|
|
80
94
|
onMouseDown,
|
|
95
|
+
...(grab ? { onPointerDown, "data-ecx-grab": "" } : {}),
|
|
81
96
|
};
|
|
82
97
|
}
|
|
83
98
|
|