@ecomcx/ecomweb-editor 1.33.0 → 1.34.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 +2 -1
- package/src/locales/en/background.ts +5 -0
- package/src/locales/en/bindings.ts +4 -0
- package/src/locales/en/block-desc.ts +4 -11
- package/src/locales/en/block-style.ts +17 -6
- package/src/locales/en/block-titles.ts +38 -16
- package/src/locales/en/blocks.ts +36 -6
- package/src/locales/en/columns.ts +1 -0
- package/src/locales/en/controls.ts +1 -1
- package/src/locales/en/hints.ts +241 -12
- package/src/locales/en/index.ts +3 -1
- package/src/locales/en/layout.ts +13 -0
- package/src/locales/en/motion.ts +16 -0
- package/src/locales/en/palette.ts +8 -0
- package/src/locales/en/parts.ts +2 -1
- package/src/locales/en/pattern-overrides.ts +14 -0
- package/src/locales/en/placeholders.ts +6 -3
- package/src/locales/en/v2.ts +2 -0
- package/src/locales/vi/attrs.ts +3 -2
- package/src/locales/vi/background.ts +5 -0
- package/src/locales/vi/bindings.ts +4 -0
- package/src/locales/vi/block-desc.ts +7 -14
- package/src/locales/vi/block-style.ts +18 -7
- package/src/locales/vi/block-titles.ts +48 -26
- package/src/locales/vi/blocks.ts +36 -6
- package/src/locales/vi/columns.ts +1 -0
- package/src/locales/vi/controls.ts +1 -1
- package/src/locales/vi/hints.ts +241 -12
- package/src/locales/vi/index.ts +3 -1
- package/src/locales/vi/layout.ts +13 -0
- package/src/locales/vi/motion.ts +16 -0
- package/src/locales/vi/palette.ts +8 -0
- package/src/locales/vi/parts.ts +2 -1
- package/src/locales/vi/pattern-overrides.ts +14 -0
- package/src/locales/vi/placeholders.ts +7 -4
- package/src/locales/vi/v2.ts +2 -0
- package/src/v2/blocks/columns-inspector.tsx +11 -2
- package/src/v2/blocks/index.ts +9 -6
- package/src/v2/blocks/layout-options.tsx +80 -0
- package/src/v2/blocks/layout.tsx +331 -124
- package/src/v2/blocks/media.tsx +51 -21
- package/src/v2/blocks/resize.tsx +50 -19
- package/src/v2/blocks/social-icons.ts +22 -0
- package/src/v2/blocks/text.tsx +12 -50
- package/src/v2/blocks/theme.tsx +13 -19
- package/src/v2/blocks/tools.tsx +24 -2
- package/src/v2/blocks/widgets.tsx +84 -28
- package/src/v2/canvas/block-list.tsx +30 -4
- package/src/v2/canvas/canvas-css.ts +81 -9
- package/src/v2/canvas/canvas.tsx +63 -7
- package/src/v2/canvas/dnd.ts +7 -0
- package/src/v2/canvas/variation-picker.tsx +63 -0
- package/src/v2/context.tsx +48 -0
- package/src/v2/core/bindings.ts +6 -1
- package/src/v2/core/block-presets.ts +10 -0
- package/src/v2/core/clipboard.ts +5 -5
- package/src/v2/core/host.ts +2 -0
- package/src/v2/core/model.ts +6 -6
- package/src/v2/core/registry.ts +15 -0
- package/src/v2/core/store.ts +9 -9
- package/src/v2/core/structure.ts +1 -3
- package/src/v2/editor.css +74 -0
- package/src/v2/editor.tsx +22 -7
- package/src/v2/text/rich-text.tsx +20 -5
- package/src/v2/ui/ai-markdown.ts +52 -0
- package/src/v2/ui/ai.tsx +81 -14
- package/src/v2/ui/attr-form.tsx +26 -6
- package/src/v2/ui/attr-hints.ts +115 -16
- package/src/v2/ui/background-panel.tsx +22 -0
- package/src/v2/ui/bg-video-preview.tsx +7 -0
- package/src/v2/ui/bindings.tsx +7 -2
- package/src/v2/ui/block-icons.tsx +3 -10
- package/src/v2/ui/block-live-preview.tsx +21 -0
- package/src/v2/ui/block-style-panel.tsx +3 -1
- package/src/v2/ui/command-palette.tsx +125 -0
- package/src/v2/ui/icon-picker.tsx +88 -21
- package/src/v2/ui/icon-svg.tsx +21 -0
- package/src/v2/ui/inserter.tsx +62 -12
- package/src/v2/ui/inspector.tsx +12 -6
- package/src/v2/ui/layout-panel.tsx +1 -1
- package/src/v2/ui/motion-panel.tsx +22 -13
- package/src/v2/ui/option-thumbs.tsx +81 -0
- package/src/v2/ui/pattern-library.tsx +2 -1
- package/src/v2/ui/pattern-overrides.tsx +67 -0
- package/src/v2/ui/placeholders.tsx +21 -2
- package/src/v2/ui/preset-bar.tsx +5 -5
- package/src/v2/ui/style-supports.ts +2 -3
- package/src/v2/ui/style-tab.tsx +83 -20
- package/src/v2/ui/toolbar.tsx +40 -6
- package/src/v2/ui/transform-panel.tsx +77 -0
package/src/v2/ui/inserter.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LiveBlockPreview } from "./block-live-preview";
|
|
1
2
|
import { freshWithDefaults } from "../core/block-presets";
|
|
2
3
|
import { leavesItem } from "../core/structure";
|
|
3
4
|
import { blockDescription } from "./block-descriptions";
|
|
@@ -23,6 +24,7 @@ export interface InsertOption {
|
|
|
23
24
|
description?: string;
|
|
24
25
|
icon?: ComponentType<{ className?: string }>;
|
|
25
26
|
keywords: string;
|
|
27
|
+
aliases?: string[];
|
|
26
28
|
category: string;
|
|
27
29
|
/** Loại khối gốc (kiểm tra chỗ đặt được). */
|
|
28
30
|
type: string;
|
|
@@ -32,6 +34,9 @@ export interface InsertOption {
|
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
/** Các lựa chọn chèn: khối + biến thể có hàm tạo riêng (cột 30/70…). */
|
|
37
|
+
const LEGACY_BLOCKS = new Set(["details", "testimonial"]);
|
|
38
|
+
const PAGE_THEME_BLOCKS = new Set(["search", "query", "icon"]);
|
|
39
|
+
|
|
35
40
|
export function useInsertOptions(): InsertOption[] {
|
|
36
41
|
const { registry, prefs, host, labels } = useEditor();
|
|
37
42
|
const hidden = usePrefs(prefs).hiddenBlockTypes;
|
|
@@ -42,24 +47,27 @@ export function useInsertOptions(): InsertOption[] {
|
|
|
42
47
|
const out: InsertOption[] = [];
|
|
43
48
|
const hide = new Set(hidden);
|
|
44
49
|
for (const t of registry.all()) {
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
// Bộ khối gọn: khối cũ đã gộp vào khối khác và khối giao diện (tên website, bài, bình luận…) chỉ hiện khi sửa template; nội dung cũ vẫn hiển thị
|
|
51
|
+
const tpl = t.templateOnly || (t.category === "theme" && !PAGE_THEME_BLOCKS.has(t.name));
|
|
52
|
+
if (t.hidden || hide.has(t.name)) continue;
|
|
53
|
+
if (!host.showAllBlocks && (LEGACY_BLOCKS.has(t.name) || (tpl && host.scope !== "template"))) continue;
|
|
54
|
+
out.push({ key: t.name, title: t.title, description: t.description, icon: t.icon, keywords: t.keywords ?? "", aliases: t.aliases, category: t.category ?? "other", type: t.name, create: () => registry.create(t.name) });
|
|
47
55
|
for (const v of t.variations ?? []) {
|
|
48
|
-
if (!v.create) continue;
|
|
56
|
+
if (!v.create || (v.legacy && !host.showAllBlocks)) continue;
|
|
49
57
|
out.push({ key: `${t.name}/${v.name}`, title: v.standalone ? v.title : `${t.title} ${v.title}`, description: v.description, icon: v.icon ?? t.icon, keywords: `${t.keywords ?? ""} ${v.keywords ?? ""}`, category: t.category ?? "other", type: t.name, create: v.create });
|
|
50
58
|
}
|
|
51
59
|
}
|
|
52
60
|
if (host.ai) out.push({ key: "ai-write", title: labels.aiWrite, description: labels.aiWriteHint, icon: Sparkles, keywords: "ai viet write gpt claude tro ly", category: "text", type: "paragraph", create: () => makeBlock("paragraph"), action: "ai-write" });
|
|
53
61
|
return out;
|
|
54
|
-
}, [registry, version, hidden, host.scope, host.ai, labels]);
|
|
62
|
+
}, [registry, version, hidden, host.scope, host.showAllBlocks, host.ai, labels]);
|
|
55
63
|
}
|
|
56
64
|
|
|
57
65
|
/** Lọc + xếp hạng: tên trùng hẳn > tên bắt đầu bằng chữ gõ > một từ trong tên > từ khoá; tiếng Việt không dấu. */
|
|
58
66
|
export function rankOptions(list: InsertOption[], query: string): InsertOption[] {
|
|
59
67
|
const q = norm(query.trim());
|
|
60
68
|
if (!q) return list;
|
|
61
|
-
const
|
|
62
|
-
const title = norm(
|
|
69
|
+
const scoreTitle = (raw: string, i: InsertOption) => {
|
|
70
|
+
const title = norm(raw);
|
|
63
71
|
if (title === q) return 4; // "/anh" → Ảnh trước Ảnh bìa, Ảnh + chữ
|
|
64
72
|
if (title.startsWith(q)) return 3;
|
|
65
73
|
if (title.split(/\s+/).some((w) => w.startsWith(q))) return 2;
|
|
@@ -68,6 +76,7 @@ export function rankOptions(list: InsertOption[], query: string): InsertOption[]
|
|
|
68
76
|
const parts = q.split(/\s+/);
|
|
69
77
|
return parts.length > 1 && parts.every((p) => words.some((w) => w.startsWith(p))) ? 0.5 : 0;
|
|
70
78
|
};
|
|
79
|
+
const score = (i: InsertOption) => Math.max(scoreTitle(i.title, i), ...(i.aliases ?? []).map((a) => scoreTitle(a, i)));
|
|
71
80
|
return list.map((i) => [i, score(i)] as const).filter(([, s]) => s > 0).sort((a, b) => b[1] - a[1]).map(([i]) => i);
|
|
72
81
|
}
|
|
73
82
|
|
|
@@ -83,6 +92,15 @@ export function applyInsert(ctx: ReturnType<typeof useEditor>, req: InserterRequ
|
|
|
83
92
|
prefs.countInsert(opt.type);
|
|
84
93
|
if (req.mode === "slash" && req.blockId) {
|
|
85
94
|
const b = store.block(req.blockId);
|
|
95
|
+
const topId = node.attrs.align === "full" ? store.locate(req.blockId)?.ancestors[0] : undefined;
|
|
96
|
+
if (b && topId) {
|
|
97
|
+
// Khối rộng hết trang (Phần…) gõ "/" trong khối khác: đặt sau khối cấp cao nhất, bỏ đoạn "/từ khoá"
|
|
98
|
+
store.insertAfter(topId, [node], { replaceEmpty: false });
|
|
99
|
+
if (inlineLength(b.inline) <= (req.query?.length ?? 0) + 1) store.remove([req.blockId], { focusNeighbor: false });
|
|
100
|
+
ui.openInserter(null);
|
|
101
|
+
afterInsert(ctx, node, opt.key.includes("/"));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
86
104
|
// Đoạn chỉ còn "/từ khoá" → thay cả đoạn bằng khối mới
|
|
87
105
|
const parentType = store.locate(req.blockId)?.parent?.type;
|
|
88
106
|
if (b && leavesItem(parentType, node.type)) {
|
|
@@ -93,6 +111,17 @@ export function applyInsert(ctx: ReturnType<typeof useEditor>, req: InserterRequ
|
|
|
93
111
|
else store.insertAfter(req.blockId, [node]);
|
|
94
112
|
} else store.insert(req.docId, req.parentId, req.index, [node]);
|
|
95
113
|
ui.openInserter(null);
|
|
114
|
+
afterInsert(ctx, node, opt.key.includes("/"));
|
|
115
|
+
}
|
|
116
|
+
/** Việc sau mọi lần chèn khối (bảng chèn, gõ "/", rê thả): đánh dấu chữ mẫu chưa sửa, bật ô chọn bố cục nếu khối có, rồi đưa con trỏ vào ô chữ đầu tiên. */
|
|
117
|
+
function afterInsert(ctx: ReturnType<typeof useEditor>, node: BNode, variation = false) {
|
|
118
|
+
const mark = (n: BNode) => { ctx.ui.fresh.add(n.id); if (Array.isArray(n.content)) n.content.forEach(mark); };
|
|
119
|
+
mark(node);
|
|
120
|
+
const t = ctx.registry.get(node.type);
|
|
121
|
+
// Ô biến thể (Slider ảnh bìa…) đã chọn sẵn kiểu: không hỏi bố cục nữa
|
|
122
|
+
if (!variation && t?.layouts?.length && t.layoutsOnInsert !== false) ctx.ui.requestPick(node.id);
|
|
123
|
+
ctx.ui.focusFirstField(node.id);
|
|
124
|
+
ctx.ui.markInsertAnchor(node.id);
|
|
96
125
|
}
|
|
97
126
|
function focusOpts(node: BNode) {
|
|
98
127
|
const text = firstTextId(node);
|
|
@@ -226,7 +255,7 @@ function suggestions(options: InsertOption[], counts: Record<string, number>): I
|
|
|
226
255
|
|
|
227
256
|
const CATEGORY_ORDER = ["text", "media", "design", "widgets", "theme", "embed"];
|
|
228
257
|
/** Thư viện khối (cột trái): tìm, theo nhóm; bấm để chèn sau khối đang chọn, kéo thả vào khung soạn. */
|
|
229
|
-
export function InserterPanel({ onInserted, onClose }: { onInserted?(): void; onClose?(): void }) {
|
|
258
|
+
export function InserterPanel({ onInserted, onClose, initialQuery }: { onInserted?(): void; onClose?(): void; initialQuery?: string }) {
|
|
230
259
|
const ctx = useEditor();
|
|
231
260
|
const { store, labels } = ctx;
|
|
232
261
|
useUiTick();
|
|
@@ -255,7 +284,7 @@ export function InserterPanel({ onInserted, onClose }: { onInserted?(): void; on
|
|
|
255
284
|
frameDoc?.addEventListener("keydown", onKey);
|
|
256
285
|
return () => { document.removeEventListener("keydown", onKey); frameDoc?.removeEventListener("keydown", onKey); };
|
|
257
286
|
}, [onClose, ctx.ui]);
|
|
258
|
-
const [query, setQuery] = useState("");
|
|
287
|
+
const [query, setQuery] = useState(initialQuery ?? "");
|
|
259
288
|
const [tab, setTab] = useState<"blocks" | "patterns" | "media">("blocks");
|
|
260
289
|
const [hover, setHover] = useState<{ o: InsertOption; rect: DOMRect; y: number } | null>(null);
|
|
261
290
|
const results = rankOptions(options, query);
|
|
@@ -267,29 +296,50 @@ export function InserterPanel({ onInserted, onClose }: { onInserted?(): void; on
|
|
|
267
296
|
const lastInserted = useRef<string | null>(null);
|
|
268
297
|
const groups = query ? [["", results] as const] : [...CATEGORY_ORDER, ...new Set(results.map((r) => r.category).filter((c) => !CATEGORY_ORDER.includes(c)))].map((c) => [c, results.filter((r) => r.category === c)] as const).filter(([, l]) => l.length);
|
|
269
298
|
const insert = (o: InsertOption) => {
|
|
299
|
+
// Lệnh riêng (Viết bằng AI): mở hộp thay vì chèn một đoạn trống — trước đây bấm ở bảng này chỉ ra đoạn văn rỗng, hộp AI không hiện
|
|
300
|
+
if (o.action === "ai-write") {
|
|
301
|
+
setHover(null);
|
|
302
|
+
const curId = store.currentIds[store.currentIds.length - 1];
|
|
303
|
+
const loc = curId ? store.locate(curId) : null;
|
|
304
|
+
const empty = !!loc && loc.block.type === "paragraph" && !loc.block.inline?.length;
|
|
305
|
+
const docId = loc?.docId ?? store.activeDocId;
|
|
306
|
+
ctx.ui.openAiWrite?.({ blockId: empty ? curId : undefined, docId, parentId: loc?.parent?.id ?? null, index: loc ? loc.index + (empty ? 0 : 1) : store.getState().docs[docId].blocks.length });
|
|
307
|
+
onInserted?.();
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
270
310
|
const node = freshWithDefaults(o.create());
|
|
311
|
+
setHover(null);
|
|
271
312
|
ctx.prefs.countInsert(o.type);
|
|
272
313
|
const cur = store.currentIds[store.currentIds.length - 1];
|
|
273
314
|
// Đoạn trống đang chọn mà chính lần chèn trước vừa tạo thì giữ lại (chèn tiếp ra sau nó); đoạn trống của người dùng thì thay như WordPress
|
|
274
|
-
const
|
|
275
|
-
|
|
315
|
+
const curLoc0 = cur ? store.locate(cur) : null;
|
|
316
|
+
// Khối rộng hết trang (Phần, Ảnh bìa hết trang) không nằm trong khối khác: đặt ngay sau khối cấp cao nhất đang chứa vùng chọn
|
|
317
|
+
const top = node.attrs.align === "full" && curLoc0?.ancestors.length ? curLoc0.ancestors[0] : null;
|
|
318
|
+
const curLoc = top ? store.locate(top) : curLoc0;
|
|
319
|
+
const curBlock = top ? store.block(top) : cur ? store.block(cur) : null;
|
|
320
|
+
// Vừa chèn một khối từ bảng này và vùng chọn vẫn là chỗ con trỏ tự vào (người dùng chưa bấm đi đâu): chèn tiếp NGAY SAU khối đó, cùng cấp — không lồng vào trong nó
|
|
321
|
+
const anchor = ctx.ui.insertAnchor;
|
|
322
|
+
const sameSel = !!anchor && !!store.block(anchor.id) && store.currentIds.join(",") === anchor.sel && cur !== anchor.id;
|
|
276
323
|
// Đang chọn khối chứa còn trống (Nhóm, Cột… vừa tạo): chèn VÀO trong nó — chèn ra sau thì phải kéo vào thêm một bước
|
|
277
324
|
if (curLoc && curBlock && Array.isArray(curBlock.content) && curBlock.content.length === 0 && canContain(curBlock.type, node.type)) store.insert(curLoc.docId, cur, 0, [node]);
|
|
278
|
-
else if (
|
|
325
|
+
else if (sameSel && anchor && store.locate(anchor.id)) store.insertAfter(node.attrs.align === "full" && store.locate(anchor.id)!.ancestors.length ? store.locate(anchor.id)!.ancestors[0] : anchor.id, [node], { replaceEmpty: false });
|
|
326
|
+
else if (cur && curLoc) store.insertAfter(top ?? cur, [node], { replaceEmpty: !top && cur !== lastInserted.current });
|
|
279
327
|
else {
|
|
280
328
|
const docId = store.activeDocId;
|
|
281
329
|
store.insert(docId, null, store.getState().docs[docId].blocks.length, [node]);
|
|
282
330
|
}
|
|
283
331
|
lastInserted.current = node.id;
|
|
332
|
+
afterInsert(ctx, node, o.key.includes("/"));
|
|
284
333
|
onInserted?.();
|
|
285
334
|
};
|
|
286
335
|
return (
|
|
287
336
|
<div ref={panelRef} className="ecx-inserter-panel" role="dialog" aria-label={labels.addBlock} onMouseLeave={() => setHover(null)}>
|
|
288
337
|
{hover && (
|
|
289
338
|
// Thẻ xem trước khi rê chuột: biểu tượng, tên, mô tả của khối
|
|
290
|
-
<div className="ecx-block-preview" role="tooltip" style={{ left: Math.round(hover.rect.right + 8), top: Math.round(Math.min(hover.y, window.innerHeight -
|
|
339
|
+
<div className="ecx-block-preview" role="tooltip" style={{ left: Math.round(hover.rect.right + 8), top: Math.round(Math.min(hover.y, window.innerHeight - 330)) }}>
|
|
291
340
|
{hover.o.icon ? <hover.o.icon className="ecx-icon" /> : <Blocks className="ecx-icon" />}
|
|
292
341
|
<strong>{hover.o.title}</strong>
|
|
342
|
+
<LiveBlockPreview id={hover.o.key} create={hover.o.create} />
|
|
293
343
|
<p>{hover.o.description ?? blockDescription(hover.o.type, labels.lang) ?? ""}</p>
|
|
294
344
|
</div>
|
|
295
345
|
)}
|
package/src/v2/ui/inspector.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Device } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { VariationGrid } from "../canvas/variation-picker";
|
|
2
3
|
import { CONTAINER_TAGS, CORE_BLOCK_STYLES, controlValue, optionValue } from "@ecomcx/ecomweb-content";
|
|
3
4
|
import { Blocks, Info, LayoutPanelTop, Paintbrush, SlidersHorizontal } from "lucide-react";
|
|
4
5
|
import { useState, useSyncExternalStore } from "react";
|
|
@@ -7,6 +8,7 @@ import { useEditor, useEditorState, useUiTick } from "../context";
|
|
|
7
8
|
import type { BNode } from "../core/model";
|
|
8
9
|
import { AttrForm, Field, attrName, cx } from "./attr-form";
|
|
9
10
|
import { BindingsPanel, CORE_BINDABLE } from "./bindings";
|
|
11
|
+
import { OverrideKeySection, PatternOverridesSection } from "./pattern-overrides";
|
|
10
12
|
import { StyleTab } from "./style-tab";
|
|
11
13
|
import { LayoutSection } from "./layout-panel";
|
|
12
14
|
import { GroupWidthSection } from "./group-width";
|
|
@@ -22,12 +24,11 @@ import { ColorInput } from "./color-field";
|
|
|
22
24
|
import { UnitInput } from "./unit-controls";
|
|
23
25
|
import { useMsgs } from "../i18n";
|
|
24
26
|
|
|
25
|
-
/** Khối "khung" (như Container / Section của Elementor): ô Nền đặt ngay tab Cài đặt — chỗ người dùng tìm đầu tiên. */
|
|
26
27
|
// Nền của Nhóm / Cột nằm ở tab Kiểu dáng như bộ khối lớn; ảnh bìa: nền là nội dung chính nên ở Cài đặt
|
|
27
|
-
const BG_IN_SETTINGS = new Set(["cover"
|
|
28
|
+
const BG_IN_SETTINGS = new Set(["cover"]);
|
|
28
29
|
/** Khối chứa đổi được thẻ HTML (attrs.tagName). */
|
|
29
30
|
const TAGGED = new Set(["group", "column", "columns"]);
|
|
30
|
-
const BG_FIRST = new Set(["column", "columns", "row", "stack", "grid"]);
|
|
31
|
+
const BG_FIRST = new Set(["column", "columns", "row", "stack", "grid", "group"]);
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* Bảng cài đặt của khối đang chọn (như Elementor): thẻ khối, tab Cài đặt (nội dung: form + phần riêng của khối), tab Kiểu dáng
|
|
@@ -37,6 +38,7 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
|
|
|
37
38
|
const { store, registry, labels, ui } = useEditor();
|
|
38
39
|
useUiTick();
|
|
39
40
|
const t = useMsgs("controls");
|
|
41
|
+
const tb = useMsgs("blocks") as unknown as Record<string, string>;
|
|
40
42
|
const sel = useEditorState((s) => s.selection);
|
|
41
43
|
useEditorState((s) => s.revision);
|
|
42
44
|
const [tab, setTab] = useState<"settings" | "style" | "advanced">("settings");
|
|
@@ -57,13 +59,13 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
|
|
|
57
59
|
const hasParts = single && blockControls().some((c) => c.partsOnly && c.parts && (c.blocks === "*" || c.blocks.includes(first.type)));
|
|
58
60
|
const Custom = single ? type?.inspector : undefined;
|
|
59
61
|
const styled = type?.supports?.style !== false && !store.isContentOnly(first.id);
|
|
60
|
-
const bindable = type?.bindable ?? CORE_BINDABLE[first.type];
|
|
62
|
+
const bindable = type?.bindable ?? (CORE_BINDABLE[first.type] as string[] | undefined);
|
|
61
63
|
const variants = [...(CORE_BLOCK_STYLES[first.type] ?? []).map((name) => ({ name, label: (t.blockStyle as Record<string, string>)[name] ?? name })), ...(blockStyles?.[first.type] ?? [])];
|
|
62
64
|
return (
|
|
63
65
|
<div className="ecx-inspector">
|
|
64
66
|
<div className="ecx-block-card">
|
|
65
67
|
<Icon className="ecx-icon ecx-card-icon" />
|
|
66
|
-
<strong>{nodes.length > 1 ? `${nodes.length} ${labels.blocks}` : (typeof first.attrs.customName === "string" && first.attrs.customName) || (type?.title ?? first.type)}</strong>
|
|
68
|
+
<strong>{nodes.length > 1 ? `${nodes.length} ${labels.blocks}` : (typeof first.attrs.customName === "string" && first.attrs.customName) || (type?.titleOf?.(first.attrs) ?? type?.title ?? first.type)}</strong>
|
|
67
69
|
{/* Mô tả khối: nút ⓘ (rê / bấm) thay cho 2–3 dòng chữ chiếm chỗ đầu bảng */}
|
|
68
70
|
{type?.description && nodes.length === 1 && <span className="ecx-card-info" tabIndex={0} role="note" aria-label={type.description} title={type.description}><Info className="ecx-icon" /><span className="ecx-card-tip">{type.description}</span></span>}
|
|
69
71
|
</div>
|
|
@@ -79,11 +81,13 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
|
|
|
79
81
|
{tab === "settings" || (tab === "style" && !styled) ? (
|
|
80
82
|
<div className="ecx-panel">
|
|
81
83
|
{single && first.type === "group" && <GroupWidthSection attrs={first.attrs} setAttrs={setAttrs} />}
|
|
84
|
+
{single && type?.layouts?.length && !disabled && <div className="ecx-layout-section"><span className="ecx-field-label">{tb.layoutLabel}</span><VariationGrid type={type} attrs={first.attrs} onPick={(v) => setAttrs(v.attrs)} /></div>}
|
|
82
85
|
{same && type && <AttrForm type={type} attrs={first.attrs} onChange={setAttrs} />}
|
|
86
|
+
{single && styled && <BlockStyleSections tab="settings" type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />}
|
|
83
87
|
{styled && single && BG_IN_SETTINGS.has(first.type) && <BackgroundControl key={first.id} type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />}
|
|
84
|
-
{styled && single && first.type === "group" && <DividerSection key={`d${first.id}`} attrs={first.attrs} setAttrs={setAttrs} />}
|
|
85
88
|
{styled && single && <LayoutSection type={first.type} style={first.attrs.style} onChange={(st) => setAttrs({ style: st ?? undefined })} device={device} />}
|
|
86
89
|
{Custom && <Custom block={first} attrs={first.attrs} setAttrs={setAttrs} blockProps={null as never} selected editable labels={labels} />}
|
|
90
|
+
{single && first.type === "syncedPattern" && <PatternOverridesSection block={first} setAttrs={setAttrs} />}
|
|
87
91
|
{same && nodes.length === 1 && <PluginPanels type={first.type} attrs={first.attrs} setAttrs={setAttrs} />}
|
|
88
92
|
{nodes.length === 1 && bindable?.length && <BindingsPanel block={first} bindable={bindable} onChange={(b) => setAttrs({ bindings: b })} />}
|
|
89
93
|
</div>
|
|
@@ -91,6 +95,7 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
|
|
|
91
95
|
<div className="ecx-panel">
|
|
92
96
|
{/* Khối chứa: Nền là mục đầu của tab Kiểu dáng (như bộ khối lớn) */}
|
|
93
97
|
{single && BG_FIRST.has(first.type) && <BackgroundControl key={first.id} type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />}
|
|
98
|
+
{single && (first.type === "group" || first.type === "columns") && <DividerSection key={`d${first.id}`} attrs={first.attrs} setAttrs={setAttrs} />}
|
|
94
99
|
<StyleTab type={first.type} style={first.attrs.style} onChange={(st) => setAttrs({ style: st ?? undefined })} device={device} onDeviceChange={setDevice} part="style"
|
|
95
100
|
variants={variants.length ? variants : undefined} variant={(first.attrs.blockStyle as string) ?? null} onVariantChange={(v) => setAttrs({ blockStyle: v ?? undefined })}
|
|
96
101
|
parts={hasParts}
|
|
@@ -117,6 +122,7 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
|
|
|
117
122
|
<Field label={attrName("className", labels.lang) ?? "className"}><input className="ecx-input" value={String(first.attrs.className ?? "")} onChange={(e) => setAttrs({ className: e.target.value || undefined })} /></Field>
|
|
118
123
|
</Section>
|
|
119
124
|
)}
|
|
125
|
+
{single && <OverrideKeySection block={first} setAttrs={setAttrs} />}
|
|
120
126
|
{nodes.length === 1 && <PluginPanels type={first.type} attrs={first.attrs} setAttrs={setAttrs} tab="advanced" />}
|
|
121
127
|
</div>
|
|
122
128
|
)}
|
|
@@ -10,7 +10,7 @@ import { Row, Section, Seg, cx } from "./style-controls";
|
|
|
10
10
|
* Giá trị theo khổ (hướng, căn, số cột) sửa theo khổ đang chọn ở bảng Kiểu dáng (`device`).
|
|
11
11
|
*/
|
|
12
12
|
/** Khối chứa (có khối con) mới có mục Bố cục. */
|
|
13
|
-
const CONTAINERS = new Set(["group", "cover", "blockquote", "
|
|
13
|
+
const CONTAINERS = new Set(["group", "cover", "blockquote", "details", "query", "postTemplate"]);
|
|
14
14
|
|
|
15
15
|
type Kind = "flow" | "row" | "stack" | "grid";
|
|
16
16
|
export const layoutKind = (l?: BlockLayout): Kind => (!l ? "flow" : l.type === "grid" ? "grid" : l.direction?.base === "column" ? "stack" : "row");
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { MOTION_HOVER, MOTION_IN, normalizeStyle, type BlockStyle } from "@ecomcx/ecomweb-content";
|
|
1
|
+
import { MOTION_EASE, MOTION_HOVER, MOTION_IN, MOTION_LOOP, MOTION_PARALLAX, normalizeStyle, type BlockStyle } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { PickTiles, motionHoverThumb, motionInThumb } from "./option-thumbs";
|
|
2
3
|
import { Play } from "lucide-react";
|
|
3
4
|
import { useSyncExternalStore } from "react";
|
|
4
5
|
import { onAnimationsChange, pluginAnimations } from "../../shared/animation-store";
|
|
@@ -55,12 +56,9 @@ export function MotionPanel({ type, style: raw, onChange }: { type: string; styl
|
|
|
55
56
|
return (
|
|
56
57
|
<Section title={t.title} defaultOpen={false} modified={!!style.motion} summary={m.in ? (t.in as Record<string, string>)[m.in] ?? m.in : ct.noMotion} onReset={() => onChange(normalizeStyle({ ...style, motion: undefined }) ?? null)}>
|
|
57
58
|
<Row label={t.scroll}>
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
{
|
|
61
|
-
<button key={id} type="button" role="radio" aria-checked={m.in === id} className={cx("ecx-chip", m.in === id && "is-active")} onClick={() => set({ in: id }, true)}>{t.in[id]}</button>
|
|
62
|
-
))}
|
|
63
|
-
</div>
|
|
59
|
+
<PickTiles label={t.scroll} value={m.in && (MOTION_IN as readonly string[]).includes(m.in) ? m.in : undefined} none={{ label: t.none }}
|
|
60
|
+
options={MOTION_IN.map((id) => ({ id, label: t.in[id], thumb: motionInThumb(id) }))}
|
|
61
|
+
onChange={(v) => (v === undefined ? set({ in: undefined, duration: undefined, delay: undefined, repeat: undefined, stagger: undefined }) : set({ in: v }, true))} />
|
|
64
62
|
{plugin.length > 0 && (
|
|
65
63
|
<select className="ecx-input" aria-label={t.more} value={isPlugin ? m.in : ""} onChange={(e) => e.target.value && set({ in: e.target.value }, true)}>
|
|
66
64
|
<option value="">{t.more}…</option>
|
|
@@ -76,6 +74,11 @@ export function MotionPanel({ type, style: raw, onChange }: { type: string; styl
|
|
|
76
74
|
<Seg label={t.speed} value={m.duration ?? "normal"} onChange={(v) => set({ duration: !v || v === "normal" ? undefined : v }, true)}
|
|
77
75
|
options={[["fast", t.fast, t.fast], ["normal", t.normal, t.normal], ["slow", t.slow, t.slow]]} />
|
|
78
76
|
</Row>
|
|
77
|
+
<Row label={t.ease}>
|
|
78
|
+
<select className="ecx-input" aria-label={t.ease} value={m.ease ?? "smooth"} onChange={(e) => set({ ease: e.target.value === "smooth" ? undefined : (e.target.value as Motion["ease"]) }, true)}>
|
|
79
|
+
{MOTION_EASE.map((id) => <option key={id} value={id}>{t.eases[id]}</option>)}
|
|
80
|
+
</select>
|
|
81
|
+
</Row>
|
|
79
82
|
<Row label={t.delay}>
|
|
80
83
|
<select className="ecx-input" aria-label={t.delay} value={m.delay ?? 0} onChange={(e) => set({ delay: Number(e.target.value) || undefined }, true)}>
|
|
81
84
|
{[...new Set([...DELAYS, m.delay ?? 0])].sort((a, b) => a - b).map((d) => <option key={d} value={d}>{d} ms</option>)}
|
|
@@ -87,13 +90,19 @@ export function MotionPanel({ type, style: raw, onChange }: { type: string; styl
|
|
|
87
90
|
</>
|
|
88
91
|
)}
|
|
89
92
|
|
|
93
|
+
<Row label={t.loop}>
|
|
94
|
+
<PickTiles label={t.loop} value={m.loop} none={{ label: t.none }} options={MOTION_LOOP.map((id) => ({ id, label: t.loops[id], thumb: motionHoverThumb("grow") }))} onChange={(v) => set({ loop: v as Motion["loop"], parallax: v ? undefined : m.parallax })} />
|
|
95
|
+
</Row>
|
|
96
|
+
{!m.in && !m.loop && (
|
|
97
|
+
<Row label={t.parallax}>
|
|
98
|
+
<select className="ecx-input" aria-label={t.parallax} value={m.parallax ?? ""} onChange={(e) => set({ parallax: (e.target.value || undefined) as Motion["parallax"] })}>
|
|
99
|
+
<option value="">{t.none}</option>
|
|
100
|
+
{MOTION_PARALLAX.map((id) => <option key={id} value={id}>{t.parallaxes[id]}</option>)}
|
|
101
|
+
</select>
|
|
102
|
+
</Row>
|
|
103
|
+
)}
|
|
90
104
|
<Row label={t.hover}>
|
|
91
|
-
<
|
|
92
|
-
<button type="button" role="radio" aria-checked={!m.hover} className={cx("ecx-chip", !m.hover && "is-active")} onClick={() => set({ hover: undefined })}>{t.none}</button>
|
|
93
|
-
{MOTION_HOVER.map((id) => (
|
|
94
|
-
<button key={id} type="button" role="radio" aria-checked={m.hover === id} className={cx("ecx-chip", m.hover === id && "is-active")} onClick={() => set({ hover: id })}>{t.hv[id]}</button>
|
|
95
|
-
))}
|
|
96
|
-
</div>
|
|
105
|
+
<PickTiles label={t.hover} value={m.hover} none={{ label: t.none }} options={MOTION_HOVER.map((id) => ({ id, label: t.hv[id], thumb: motionHoverThumb(id) }))} onChange={(v) => set({ hover: v as (typeof MOTION_HOVER)[number] | undefined })} />
|
|
97
106
|
</Row>
|
|
98
107
|
</Section>
|
|
99
108
|
);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { cx } from "./style-controls";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Ô chọn bằng hình (thẻ icon hai lớp): mỗi lựa chọn là một hình nhỏ có nhãn — lớp sau = trạng thái đầu / khung tham chiếu (nét đứt, mờ),
|
|
6
|
+
* lớp trước = kết quả — để người dùng thường nhìn là hiểu (trượt lên, phóng to, bóng đổ, khung tròn…) thay vì đọc tên rồi đoán.
|
|
7
|
+
*/
|
|
8
|
+
export interface PickOption { id: string; label: string; thumb: ReactNode }
|
|
9
|
+
|
|
10
|
+
export function PickTiles({ value, options, onChange, label, none }: { value: string | undefined; options: PickOption[]; onChange(v: string | undefined): void; label: string; none?: { label: string } }) {
|
|
11
|
+
const all: PickOption[] = none ? [{ id: "", label: none.label, thumb: <Frame><rect x="20" y="12" width="24" height="20" rx="3" className="is-solid" /></Frame> }, ...options] : options;
|
|
12
|
+
return (
|
|
13
|
+
<div className="ecx-pick-grid" role="radiogroup" aria-label={label}>
|
|
14
|
+
{all.map((o) => {
|
|
15
|
+
const on = (value ?? "") === o.id;
|
|
16
|
+
return (
|
|
17
|
+
<button key={o.id || "none"} type="button" role="radio" aria-checked={on} aria-label={o.label} title={o.label} className={cx("ecx-pick", on && "is-active")} onClick={() => onChange(o.id === "" ? undefined : on ? undefined : o.id)}>
|
|
18
|
+
{o.thumb}
|
|
19
|
+
<span className="ecx-pick-label">{o.label}</span>
|
|
20
|
+
</button>
|
|
21
|
+
);
|
|
22
|
+
})}
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const Frame = ({ children }: { children: ReactNode }) => <svg className="ecx-pick-thumb" viewBox="0 0 64 44" aria-hidden="true">{children}</svg>;
|
|
28
|
+
/** Hộp tham chiếu (lớp sau, nét đứt) và hộp kết quả (lớp trước, đặc). */
|
|
29
|
+
const ghost = (x: number, y: number, w: number, h: number, extra?: Record<string, unknown>) => <rect key={`g${x}${y}${w}`} x={x} y={y} width={w} height={h} rx="3" className="is-ghost" {...extra} />;
|
|
30
|
+
const solid = (x: number, y: number, w: number, h: number, extra?: Record<string, unknown>) => <rect key={`s${x}${y}${w}`} x={x} y={y} width={w} height={h} rx="3" className="is-solid" {...extra} />;
|
|
31
|
+
const arrow = (d: string) => <path key={`a${d}`} d={d} className="is-arrow" fill="none" />;
|
|
32
|
+
|
|
33
|
+
/** Hình cho hiệu ứng khi cuộn tới (MOTION_IN). */
|
|
34
|
+
export function motionInThumb(id: string): ReactNode {
|
|
35
|
+
const W = 24, H = 18, cx0 = 20, cy0 = 13;
|
|
36
|
+
switch (id) {
|
|
37
|
+
case "fade": return <Frame>{ghost(cx0, cy0, W, H, { opacity: 0.5 })}{solid(cx0, cy0, W, H, { opacity: 0.45 })}</Frame>;
|
|
38
|
+
case "slide-up": return <Frame>{ghost(cx0, cy0 + 9, W, H)}{solid(cx0, cy0 - 3, W, H)}{arrow("M32 40V32M29 35l3-3 3 3")}</Frame>;
|
|
39
|
+
case "slide-down": return <Frame>{ghost(cx0, cy0 - 9, W, H)}{solid(cx0, cy0 + 3, W, H)}{arrow("M32 4v8M29 9l3 3 3-3")}</Frame>;
|
|
40
|
+
case "slide-left": return <Frame>{ghost(cx0 + 12, cy0, W, H)}{solid(cx0 - 6, cy0, W, H)}{arrow("M60 22h-8M55 19l-3 3 3 3")}</Frame>;
|
|
41
|
+
case "slide-right": return <Frame>{ghost(cx0 - 12, cy0, W, H)}{solid(cx0 + 6, cy0, W, H)}{arrow("M4 22h8M9 19l3 3-3 3")}</Frame>;
|
|
42
|
+
case "zoom-in": return <Frame>{ghost(26, 17, 12, 10)}{solid(18, 11, 28, 22)}</Frame>;
|
|
43
|
+
case "zoom-out": return <Frame>{ghost(14, 8, 36, 28)}{solid(24, 15, 16, 14)}</Frame>;
|
|
44
|
+
case "blur-in": return <Frame><g filter="url(#ecx-blur)">{ghost(cx0, cy0, W, H)}</g><defs><filter id="ecx-blur"><feGaussianBlur stdDeviation="2.2" /></filter></defs>{solid(cx0, cy0, W, H)}</Frame>;
|
|
45
|
+
default: return <Frame>{solid(cx0, cy0, W, H)}</Frame>;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Hình cho hiệu ứng rê chuột (MOTION_HOVER). */
|
|
50
|
+
export function motionHoverThumb(id: string): ReactNode {
|
|
51
|
+
switch (id) {
|
|
52
|
+
case "lift": return <Frame>{ghost(20, 17, 24, 18)}{solid(20, 10, 24, 18)}{arrow("M32 38v-3M29 37l3 3 3-3")}</Frame>;
|
|
53
|
+
case "grow": return <Frame>{ghost(22, 14, 20, 16)}{solid(16, 9, 32, 26)}</Frame>;
|
|
54
|
+
case "brighten": return <Frame>{ghost(20, 13, 24, 18, { opacity: 0.35 })}{solid(20, 13, 24, 18, { opacity: 0.9 })}<path d="M50 8l1.5 3 3 1.5-3 1.5L50 17l-1.5-3-3-1.5 3-1.5z" className="is-solid" /></Frame>;
|
|
55
|
+
case "glow": return <Frame>{ghost(15, 8, 34, 28, { opacity: 0.3, rx: 10 })}{ghost(17, 10, 30, 24, { opacity: 0.45, rx: 8 })}{solid(20, 13, 24, 18)}</Frame>;
|
|
56
|
+
default: return <Frame>{solid(20, 13, 24, 18)}</Frame>;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Hình cho khung icon (không khung / tròn / vuông) và các tuỳ chọn tương tự. */
|
|
61
|
+
export function frameThumb(id: string): ReactNode {
|
|
62
|
+
const star = <path d="M32 14l2.4 5 5.4.7-4 3.8 1 5.4L32 26.2l-4.8 2.7 1-5.4-4-3.8 5.4-.7z" className="is-glyph" />;
|
|
63
|
+
switch (id) {
|
|
64
|
+
case "circle": return <Frame><circle cx="32" cy="22" r="15" className="is-solid" />{star}</Frame>;
|
|
65
|
+
case "square": return <Frame><rect x="17" y="7" width="30" height="30" rx="5" className="is-solid" />{star}</Frame>;
|
|
66
|
+
default: return <Frame><rect x="17" y="7" width="30" height="30" rx="5" className="is-ghost" /><path d="M32 14l2.4 5 5.4.7-4 3.8 1 5.4L32 26.2l-4.8 2.7 1-5.4-4-3.8 5.4-.7z" className="is-solid" /></Frame>;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Hình cho độ đậm của bóng đổ (sm → xl): lớp sau = bóng, lớp trước = hộp. */
|
|
71
|
+
export function shadowThumb(id: string): ReactNode {
|
|
72
|
+
const spread = { sm: 1.5, md: 3, lg: 5, xl: 7 }[id] ?? 3;
|
|
73
|
+
return <Frame>{ghost(20 - spread / 2, 13 + spread, 24 + spread, 18 + spread / 2, { opacity: 0.35, rx: 5 })}{solid(20, 12, 24, 18)}</Frame>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Hiệu ứng rê chuột của Hộp icon: không / phóng to / lật. */
|
|
77
|
+
export function iconHoverThumb(id: string): ReactNode {
|
|
78
|
+
if (id === "grow") return motionHoverThumb("grow");
|
|
79
|
+
if (id === "flip") return <Frame>{ghost(14, 13, 14, 18)}{solid(36, 13, 14, 18)}<path d="M20 8c6-5 18-5 24 0M41 5l3 3-4 2" className="is-arrow" fill="none" /></Frame>;
|
|
80
|
+
return motionHoverThumb("none");
|
|
81
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CONTENT_VERSION } from "@ecomcx/ecomweb-content";
|
|
1
2
|
import { LayoutTemplate, Search, Sparkles, X } from "lucide-react";
|
|
2
3
|
import { useEffect, useMemo, useRef, useState, useSyncExternalStore, type ReactNode } from "react";
|
|
3
4
|
import { norm } from "../../shared/util";
|
|
@@ -78,7 +79,7 @@ function Preview({ nodes, height, render }: { nodes: RichNode[]; height: number;
|
|
|
78
79
|
ro.observe(el);
|
|
79
80
|
return () => { io.disconnect(); ro.disconnect(); };
|
|
80
81
|
}, []);
|
|
81
|
-
const value = useMemo(() => ({ version:
|
|
82
|
+
const value = useMemo(() => ({ version: CONTENT_VERSION, blocks: [{ type: "richtext", data: { type: "doc", content: nodes } }] }), [nodes]);
|
|
82
83
|
return (
|
|
83
84
|
<div ref={box} className="ecx-lib-preview" style={{ height }} aria-hidden="true">
|
|
84
85
|
{seen && (
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CORE_BINDABLE, OVERRIDE_KEY, patternOverridables } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { Repeat2 } from "lucide-react";
|
|
3
|
+
import { useEditor, useEditorState } from "../context";
|
|
4
|
+
import { docFromBlocks, type BNode } from "../core/model";
|
|
5
|
+
import { useMsgs } from "../i18n";
|
|
6
|
+
import { Field, cx } from "./attr-form";
|
|
7
|
+
import { Section } from "./style-controls";
|
|
8
|
+
|
|
9
|
+
const ATTR_LABEL = (t: Record<string, string>, attr: string) => t[`attr${attr[0].toUpperCase()}${attr.slice(1)}`] ?? attr;
|
|
10
|
+
|
|
11
|
+
/** Trong tài liệu của mẫu: bật "cho phép sửa riêng" cho khối → chỗ dùng mẫu đặt được chữ / ảnh / liên kết riêng cho khối này (tab Nâng cao). */
|
|
12
|
+
export function OverrideKeySection({ block, setAttrs }: { block: BNode; setAttrs(a: Record<string, unknown>): void }) {
|
|
13
|
+
const { store } = useEditor();
|
|
14
|
+
const t = useMsgs("patternOverrides");
|
|
15
|
+
const loc = store.locate(block.id);
|
|
16
|
+
if (!loc || !loc.docId.startsWith("pattern:") || !CORE_BINDABLE[block.type]) return null;
|
|
17
|
+
const key = typeof block.attrs.overrideKey === "string" ? block.attrs.overrideKey : "";
|
|
18
|
+
return (
|
|
19
|
+
<Section title={t.allowTitle} defaultOpen={!!key}>
|
|
20
|
+
<label className="ecx-check">
|
|
21
|
+
<input type="checkbox" checked={!!key} onChange={(e) => setAttrs({ overrideKey: e.target.checked ? `o-${block.id.replace(/[^a-z0-9]/gi, "").toLowerCase().slice(-8)}` : undefined })} /> {t.allow}
|
|
22
|
+
</label>
|
|
23
|
+
<p className="ecx-muted">{t.allowHelp}</p>
|
|
24
|
+
{key && (
|
|
25
|
+
<Field label={t.key}>
|
|
26
|
+
<input className="ecx-input" value={key} aria-label={t.key} onChange={(e) => { const v = e.target.value.toLowerCase().replace(/[^a-z0-9-]/g, "").slice(0, 40); if (OVERRIDE_KEY.test(v)) setAttrs({ overrideKey: v }); }} />
|
|
27
|
+
</Field>
|
|
28
|
+
)}
|
|
29
|
+
</Section>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Khối "Mẫu đồng bộ": liệt kê các ô mẫu cho sửa riêng — nhập giá trị riêng cho chỗ dùng này; để trống = theo mẫu. */
|
|
34
|
+
export function PatternOverridesSection({ block, setAttrs }: { block: BNode; setAttrs(a: Record<string, unknown>): void }) {
|
|
35
|
+
const { store, host, registry } = useEditor();
|
|
36
|
+
useEditorState((s) => s.docs);
|
|
37
|
+
const t = useMsgs("patternOverrides");
|
|
38
|
+
const ref = Number(block.attrs.ref);
|
|
39
|
+
const docId = host.documents?.idOf?.({ kind: "pattern", ref }) ?? `pattern:${ref}`;
|
|
40
|
+
const blocks = store.getState().docs[docId]?.blocks;
|
|
41
|
+
if (!ref || !blocks) return null;
|
|
42
|
+
const list = patternOverridables({ version: 2, blocks: [{ type: "richtext", data: docFromBlocks(blocks) }] });
|
|
43
|
+
const current = (block.attrs.overrides as Record<string, Record<string, string>> | undefined) ?? {};
|
|
44
|
+
const set = (key: string, attr: string, v: string) => {
|
|
45
|
+
const next: Record<string, Record<string, string>> = { ...current, [key]: { ...(current[key] ?? {}) } };
|
|
46
|
+
if (v) next[key][attr] = v; else delete next[key][attr];
|
|
47
|
+
if (!Object.keys(next[key]).length) delete next[key];
|
|
48
|
+
setAttrs({ overrides: Object.keys(next).length ? next : undefined });
|
|
49
|
+
};
|
|
50
|
+
return (
|
|
51
|
+
<Section title={t.title} defaultOpen>
|
|
52
|
+
{list.length === 0 && <p className="ecx-muted"><Repeat2 className="ecx-icon ecx-icon-sm" /> {t.none}</p>}
|
|
53
|
+
{list.map((o) => (
|
|
54
|
+
<div key={o.key} className="ecx-binding-row" data-override={o.key}>
|
|
55
|
+
<span className="ecx-field-label">{registry.get(o.type)?.title ?? o.type}</span>
|
|
56
|
+
{o.attrs.filter((a) => a in o.values || a === "content").map((attr) => (
|
|
57
|
+
<Field key={attr} label={ATTR_LABEL(t as unknown as Record<string, string>, attr)}>
|
|
58
|
+
<input className={cx("ecx-input")} value={current[o.key]?.[attr] ?? ""} placeholder={o.values[attr] || t.followPattern} aria-label={`${o.key}: ${attr}`}
|
|
59
|
+
onChange={(e) => set(o.key, attr, e.target.value.slice(0, 2000))} />
|
|
60
|
+
</Field>
|
|
61
|
+
))}
|
|
62
|
+
</div>
|
|
63
|
+
))}
|
|
64
|
+
<p className="ecx-muted">{t.help}</p>
|
|
65
|
+
</Section>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -66,13 +66,32 @@ export interface TextPlaceholderProps {
|
|
|
66
66
|
id?: string;
|
|
67
67
|
className?: string;
|
|
68
68
|
style?: CSSProperties;
|
|
69
|
+
/** Phím bấm trong ô (Enter / Backspace để thêm, xoá mục). */
|
|
70
|
+
onKeyDown?(e: { key: string; shiftKey: boolean; preventDefault(): void; currentTarget: HTMLInputElement | HTMLTextAreaElement }): void;
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
/** Ô gõ ngay trên khối: chữ gợi ý luôn hiện khi trống, cỡ chữ = cỡ chữ thật của chỗ đặt ô (kế thừa font). */
|
|
72
|
-
export function TextPlaceholder({ value, onChange, placeholder, multiline, label, required, id, className, style }: TextPlaceholderProps) {
|
|
74
|
+
export function TextPlaceholder({ value, onChange, placeholder, multiline, label, required, id, className, style, onKeyDown }: TextPlaceholderProps) {
|
|
75
|
+
const { ui } = useEditor();
|
|
76
|
+
const bid = (el: Element) => el.closest("[data-ecx-block]")?.getAttribute("data-ecx-block") ?? "";
|
|
73
77
|
const props = {
|
|
74
78
|
...stop, id, className: cx("ecx-ph-text", className), style, value, placeholder, required, "aria-label": label ?? placeholder, "aria-required": required || undefined,
|
|
75
|
-
"data-ecx-placeholder": "text",
|
|
79
|
+
"data-ecx-placeholder": "text", onKeyDown,
|
|
80
|
+
// Chữ mẫu chưa sửa và ô đã lấy nét (tự vào lúc chèn, đang chọn hết): giữ nguyên vùng chọn khi bấm — không để trình duyệt đặt con trỏ vào giữa chữ mẫu
|
|
81
|
+
onMouseDown: (e: { stopPropagation(): void; preventDefault(): void; currentTarget: HTMLInputElement | HTMLTextAreaElement }) => {
|
|
82
|
+
e.stopPropagation();
|
|
83
|
+
const el = e.currentTarget;
|
|
84
|
+
if (ui.fresh.has(bid(el)) && el.ownerDocument.activeElement === el && el.selectionStart !== el.selectionEnd) e.preventDefault();
|
|
85
|
+
},
|
|
86
|
+
// Chữ mẫu chưa sửa: bấm vào là chọn hết (gõ là thay)
|
|
87
|
+
onFocus: (e: { currentTarget: HTMLInputElement | HTMLTextAreaElement }) => { if (ui.fresh.has(bid(e.currentTarget))) e.currentTarget.select(); },
|
|
88
|
+
// Chữ mẫu chưa sửa: bấm vào (kể cả khi con trỏ đã tự vào ô lúc chèn) cũng chọn hết — bấm rồi gõ là thay, không chèn vào giữa chữ mẫu
|
|
89
|
+
onClick: (e: { currentTarget: HTMLInputElement | HTMLTextAreaElement }) => {
|
|
90
|
+
const el = e.currentTarget;
|
|
91
|
+
// Trình duyệt thu con trỏ về một điểm SAU sự kiện click (khi ô đã lấy nét sẵn và đang chọn hết) → chọn lại hết sau một nhịp
|
|
92
|
+
if (ui.fresh.has(bid(el))) setTimeout(() => { if (ui.fresh.has(bid(el)) && el.ownerDocument.activeElement === el && el.selectionStart === el.selectionEnd) el.select(); }, 0);
|
|
93
|
+
},
|
|
94
|
+
onChange: (e: { target: HTMLInputElement | HTMLTextAreaElement }) => { ui.fresh.delete(bid(e.target)); onChange(e.target.value); },
|
|
76
95
|
};
|
|
77
96
|
return multiline ? <textarea {...props} rows={2} /> : <input {...props} type="text" />;
|
|
78
97
|
}
|
package/src/v2/ui/preset-bar.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Check, ChevronDown, RotateCcw, Save, Star, Trash2 } from "lucide-react";
|
|
2
2
|
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
3
3
|
import { blockControls } from "../../shared/panel-store";
|
|
4
|
-
import { applyStyle, ensurePresets, onPresetsChange, pickStyle, presetsSnapshot, sameStyle, setPresets, styleKeys, type BlockPresetMap } from "../core/block-presets";
|
|
4
|
+
import { applyStyle, ensurePresets, localBlockPresets, onPresetsChange, pickStyle, presetsSnapshot, sameStyle, setPresets, styleKeys, type BlockPresetMap } from "../core/block-presets";
|
|
5
5
|
import type { BNode } from "../core/model";
|
|
6
6
|
import { useEditor } from "../context";
|
|
7
7
|
import { useMsgs } from "../i18n";
|
|
@@ -15,7 +15,8 @@ export function PresetBar({ block, setAttrs }: { block: BNode; setAttrs(a: Recor
|
|
|
15
15
|
const { host } = useEditor();
|
|
16
16
|
const t = useMsgs("presets");
|
|
17
17
|
const map = useSyncExternalStore(onPresetsChange, presetsSnapshot, presetsSnapshot);
|
|
18
|
-
|
|
18
|
+
const store = host.blockPresets ?? localBlockPresets;
|
|
19
|
+
useEffect(() => ensurePresets(store.load), [store]);
|
|
19
20
|
const [open, setOpen] = useState(false);
|
|
20
21
|
const [naming, setNaming] = useState<string | null>(null);
|
|
21
22
|
const [busy, setBusy] = useState(false);
|
|
@@ -26,7 +27,6 @@ export function PresetBar({ block, setAttrs }: { block: BNode; setAttrs(a: Recor
|
|
|
26
27
|
document.addEventListener("mousedown", out, true);
|
|
27
28
|
return () => document.removeEventListener("mousedown", out, true);
|
|
28
29
|
}, [open]);
|
|
29
|
-
if (!host.blockPresets) return null;
|
|
30
30
|
const keys = styleKeys(block.type, blockControls());
|
|
31
31
|
const cur = pickStyle(block.attrs, keys);
|
|
32
32
|
const entry = map?.[block.type] ?? {};
|
|
@@ -36,11 +36,11 @@ export function PresetBar({ block, setAttrs }: { block: BNode; setAttrs(a: Recor
|
|
|
36
36
|
const isDefault = !match && sameStyle(cur, pickStyle(def, keys));
|
|
37
37
|
const label = match ? match.name : t.default;
|
|
38
38
|
const edited = !match && !isDefault;
|
|
39
|
-
const canSave = !!
|
|
39
|
+
const canSave = !!store.save;
|
|
40
40
|
|
|
41
41
|
const save = async (next: BlockPresetMap) => {
|
|
42
42
|
setBusy(true);
|
|
43
|
-
try { setPresets((await
|
|
43
|
+
try { setPresets((await store.save!(next as Record<string, unknown>)) as BlockPresetMap); }
|
|
44
44
|
finally { setBusy(false); }
|
|
45
45
|
};
|
|
46
46
|
const withEntry = (patch: Partial<typeof entry>) => ({ ...(map ?? {}), [block.type]: { ...entry, ...patch } });
|
|
@@ -10,9 +10,8 @@ const MINIMAL: StyleGroup[] = ["spacing", "visibility"];
|
|
|
10
10
|
|
|
11
11
|
/** Khối lõi có bộ nhóm riêng; khối khác: khối chứa có đủ (kể cả ảnh nền), khối còn lại có mọi nhóm trừ ảnh nền. */
|
|
12
12
|
const CORE: Record<string, StyleGroup[]> = {
|
|
13
|
-
spacer: MINIMAL,
|
|
14
|
-
|
|
15
|
-
image: MEDIA, gallery: MEDIA, video: MEDIA, youtube: MEDIA, embed: MEDIA, featuredImage: MEDIA, siteLogo: MEDIA, avatar: MEDIA,
|
|
13
|
+
spacer: MINIMAL, customHtml: MINIMAL, shortcode: MINIMAL, audio: MINIMAL,
|
|
14
|
+
image: MEDIA, gallery: MEDIA, video: MEDIA, embed: MEDIA, featuredImage: MEDIA, siteLogo: MEDIA, avatar: MEDIA,
|
|
16
15
|
icon: ["color", "spacing", "hover", "motion", "visibility"],
|
|
17
16
|
socialLinks: ["color", "spacing", "motion", "visibility"],
|
|
18
17
|
// Màu nút (Thường / Rê chuột) ở mục Nút riêng (core-controls) — không lặp nhóm Màu chung (dữ liệu cũ có màu vẫn hiện để sửa)
|