@ecomcx/ecomweb-editor 1.27.0 → 1.28.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/background.ts +22 -0
- package/src/locales/en/block-desc.ts +30 -1
- package/src/locales/en/index.ts +2 -1
- package/src/locales/en/v2.ts +5 -0
- package/src/locales/vi/background.ts +22 -0
- package/src/locales/vi/block-desc.ts +30 -1
- package/src/locales/vi/index.ts +2 -1
- package/src/locales/vi/v2.ts +5 -0
- package/src/shared/block-defs.ts +5 -0
- package/src/shared/panel-store.ts +65 -7
- package/src/v2/blocks/compat.tsx +1 -0
- package/src/v2/blocks/index.ts +2 -1
- package/src/v2/canvas/block-list.tsx +3 -1
- package/src/v2/canvas/canvas.tsx +80 -7
- package/src/v2/canvas/dnd.ts +15 -2
- package/src/v2/context.tsx +6 -0
- package/src/v2/core/registry.ts +2 -1
- package/src/v2/editor.css +21 -0
- package/src/v2/editor.tsx +20 -6
- package/src/v2/index.ts +3 -3
- package/src/v2/ui/background-panel.tsx +83 -0
- package/src/v2/ui/block-menu.ts +19 -0
- package/src/v2/ui/inserter.tsx +21 -6
- package/src/v2/ui/inspector.tsx +45 -8
- package/src/v2/ui/layout-panel.tsx +5 -5
- package/src/v2/ui/section-adder.tsx +58 -0
- package/src/v2/ui/style-supports.ts +29 -0
- package/src/v2/ui/style-tab.tsx +24 -15
- package/src/v2/ui/toolbar.tsx +123 -34
- package/src/v2/ui/unit-controls.tsx +2 -2
package/src/v2/editor.tsx
CHANGED
|
@@ -10,6 +10,7 @@ import { Canvas, type Device } from "./canvas/canvas";
|
|
|
10
10
|
import { EditorContext, EditorUi, useEditor, useEditorState, useUiTick, type EditorContextValue } from "./context";
|
|
11
11
|
import type { EditorHost } from "./core/host";
|
|
12
12
|
import { InserterPanel, InserterPopover } from "./ui/inserter";
|
|
13
|
+
import { SectionAdder } from "./ui/section-adder";
|
|
13
14
|
import { AiWrite } from "./ui/ai";
|
|
14
15
|
import { labelsV2, type V2Labels } from "./labels";
|
|
15
16
|
import { localesVersion, onLocalesChange } from "../i18n";
|
|
@@ -20,7 +21,7 @@ import { ListView } from "./ui/list-view";
|
|
|
20
21
|
import { PrefsStore, usePrefs, type PrefsStorage } from "./prefs";
|
|
21
22
|
import { Breadcrumbs, CodeEditor, MoreMenu } from "./ui/options";
|
|
22
23
|
import { EditorStore, type DocRecord } from "./core/store";
|
|
23
|
-
import { BlockToolbar, DropIndicator, ToolButton } from "./ui/toolbar";
|
|
24
|
+
import { BlockContextMenu, BlockToolbar, DropIndicator, ToolButton } from "./ui/toolbar";
|
|
24
25
|
|
|
25
26
|
const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
|
|
26
27
|
|
|
@@ -181,7 +182,8 @@ function EditorShell({ className, onSave, header, actions, menuExtra, canvasBefo
|
|
|
181
182
|
const [left, setLeft] = useState<"inserter" | "list" | null>(() => (ctx.prefs.get().showListView ? "list" : null));
|
|
182
183
|
useEffect(() => { ctx.ui.browseAll = () => setLeft("inserter"); return () => { ctx.ui.browseAll = null; }; }, [ctx.ui]);
|
|
183
184
|
const [right, setRight] = useState(true);
|
|
184
|
-
|
|
185
|
+
// Khổ ban đầu do ứng dụng chọn; sau đó dùng chung qua ui.device (DeviceSwitcher, tab Kiểu dáng)
|
|
186
|
+
useEffect(() => { if (defaultDevice) ctx.ui.setDevice(defaultDevice); }, [ctx.ui, defaultDevice]);
|
|
185
187
|
const [saving, setSaving] = useState<"idle" | "saving" | "saved" | "error">("idle");
|
|
186
188
|
const [error, setError] = useState<string | null>(null);
|
|
187
189
|
useEditorState((s) => s.revision);
|
|
@@ -235,9 +237,7 @@ function EditorShell({ className, onSave, header, actions, menuExtra, canvasBefo
|
|
|
235
237
|
{p.mode === "visual" && <ZoomToggle />}
|
|
236
238
|
</div>
|
|
237
239
|
<div className="ecx-topbar-end">
|
|
238
|
-
<
|
|
239
|
-
{([["desktop", Monitor, labels.deviceDesktop], ["tablet", Tablet, labels.deviceTablet], ["mobile", Smartphone, labels.deviceMobile]] as const).map(([d, I, text]) => <ToolButton key={d} label={text} active={device === d} onClick={() => setDevice(d)}><I className="ecx-icon" /></ToolButton>)}
|
|
240
|
-
</div>
|
|
240
|
+
<DeviceSwitcher />
|
|
241
241
|
{!p.distractionFree && <ToolButton label={labels.settings} active={right} onClick={() => setRight(!right)}><PanelRight className="ecx-icon" /></ToolButton>}
|
|
242
242
|
{actions}
|
|
243
243
|
<MoreMenu extra={menuExtra} />
|
|
@@ -252,7 +252,7 @@ function EditorShell({ className, onSave, header, actions, menuExtra, canvasBefo
|
|
|
252
252
|
{p.fixedToolbar && p.mode === "visual" && <div className="ecx-fixed-toolbar"><BlockToolbar placement="fixed" /></div>}
|
|
253
253
|
<div className="ecx-body">
|
|
254
254
|
{left && !p.distractionFree && <aside className="ecx-left">{left === "inserter" ? <InserterPanel onClose={() => setLeft(null)} /> : <ListView />}</aside>}
|
|
255
|
-
<main className="ecx-main">{p.mode === "code" ? <CodeEditor /> : <Canvas
|
|
255
|
+
<main className="ecx-main">{p.mode === "code" ? <CodeEditor /> : <Canvas before={canvasBefore} />}</main>
|
|
256
256
|
{right && !p.distractionFree && <aside className="ecx-right"><Inspector blockStyles={blockStyles} /></aside>}
|
|
257
257
|
</div>
|
|
258
258
|
{p.showBreadcrumbs && !p.distractionFree && p.mode === "visual" && <Breadcrumbs />}
|
|
@@ -261,6 +261,18 @@ function EditorShell({ className, onSave, header, actions, menuExtra, canvasBefo
|
|
|
261
261
|
);
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
+
/** Chọn khổ màn hình đang soạn (máy tính / máy tính bảng / điện thoại): khung soạn và tab Kiểu dáng cùng theo. */
|
|
265
|
+
export function DeviceSwitcher() {
|
|
266
|
+
const { ui, labels } = useEditor();
|
|
267
|
+
useUiTick();
|
|
268
|
+
return (
|
|
269
|
+
<div className="ecx-tool-group" role="group" aria-label={labels.devices}>
|
|
270
|
+
{([["desktop", Monitor, labels.deviceDesktop], ["tablet", Tablet, labels.deviceTablet], ["mobile", Smartphone, labels.deviceMobile]] as const).map(([d, I, text]) =>
|
|
271
|
+
<ToolButton key={d} label={text} active={ui.device === d} aria-pressed={ui.device === d} onClick={() => ui.setDevice(d)}><I className="ecx-icon" /></ToolButton>)}
|
|
272
|
+
</div>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
264
276
|
/** Bật / tắt hiện template quanh trang (khi có template bao quanh). */
|
|
265
277
|
function ZoomToggle() {
|
|
266
278
|
const { ui, labels } = useEditor();
|
|
@@ -292,7 +304,9 @@ export function EditorOverlays() {
|
|
|
292
304
|
return (
|
|
293
305
|
<>
|
|
294
306
|
<BlockToolbar />
|
|
307
|
+
<BlockContextMenu />
|
|
295
308
|
<InserterPopover />
|
|
309
|
+
<SectionAdder />
|
|
296
310
|
<AiWrite />
|
|
297
311
|
<DropIndicator />
|
|
298
312
|
<LiveRegion />
|
package/src/v2/index.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* khung soạn là iframe mang CSS của website, sửa header/footer ngay trong template, một lịch sử hoàn tác xuyên tài liệu,
|
|
4
4
|
* mỗi khối chữ là một ProseMirror nhỏ (gõ tiếng Việt ổn định). Đọc/ghi đúng định dạng của @ecomcx/ecomweb-content.
|
|
5
5
|
*/
|
|
6
|
-
export { BlockEditor, EditorProvider, EditorOverlays, saveAll, blocksFromContent, contentFromBlocks, splitContent, type BlockEditorProps, type EditorProviderProps } from "./editor";
|
|
6
|
+
export { BlockEditor, DeviceSwitcher, EditorProvider, EditorOverlays, saveAll, blocksFromContent, contentFromBlocks, splitContent, type BlockEditorProps, type EditorProviderProps } from "./editor";
|
|
7
7
|
export { Canvas, DEVICE_WIDTH, type CanvasProps, type Device } from "./canvas/canvas";
|
|
8
|
-
export { BlockToolbar, DropIndicator, ToolButton, Dropdown, MenuItem } from "./ui/toolbar";
|
|
8
|
+
export { BlockToolbar, BlockContextMenu, DropIndicator, ToolButton, Dropdown, MenuItem } from "./ui/toolbar";
|
|
9
9
|
export { InserterPanel, InserterPopover, rankOptions, useInsertOptions, type InsertOption } from "./ui/inserter";
|
|
10
10
|
export { Inspector } from "./ui/inspector";
|
|
11
11
|
export { AttrForm } from "./ui/attr-form";
|
|
@@ -30,7 +30,7 @@ export { registerBindingSource, unregisterBindingSource, bindingSources, Binding
|
|
|
30
30
|
export { storeAnimation as registerAnimation, dropAnimation as unregisterAnimation, pluginAnimations, type MotionEffect } from "../shared/animation-store";
|
|
31
31
|
export { defineBlock, type BlockDefinition } from "@ecomcx/ecomweb-content";
|
|
32
32
|
export { registerBlock, unregisterBlock, registeredBlocks, type RegisterBlockOptions } from "../shared/block-defs";
|
|
33
|
-
export { registerBlockPanel, unregisterBlockPanel, blockPanels, type BlockPanel, type BlockPanelProps } from "../shared/panel-store";
|
|
33
|
+
export { registerBlockPanel, unregisterBlockPanel, blockPanels, registerBlockAction, unregisterBlockAction, onBlockReady, registerBlockAssets, type BlockPanel, type BlockPanelProps, type BlockAction, type BlockActionContext, type BlockReadyFn, type BlockAsset } from "../shared/panel-store";
|
|
34
34
|
export { registerPattern, unregisterPattern, registeredPatterns, registerCorePatterns, patternNodes, PATTERN_CATEGORIES, type Pattern } from "../shared/patterns";
|
|
35
35
|
export { viLabels, enLabels, labelsLegacy, type EditorLabels } from "../shared/labels";
|
|
36
36
|
export { StylePanel } from "../shared/style-panel";
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { normalizeStyle, type BlockBackground, type BlockStyle, type Device } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { useEditor } from "../context";
|
|
4
|
+
import { useMsgs } from "../i18n";
|
|
5
|
+
import { ColorInput } from "./color-field";
|
|
6
|
+
import { Row, Section, Seg, cx } from "./style-controls";
|
|
7
|
+
|
|
8
|
+
/** Điểm lấy nét chọn nhanh: lưới 3×3 (trên-trái … dưới-phải). */
|
|
9
|
+
const POSITIONS = ["0% 0%", "50% 0%", "100% 0%", "0% 50%", "50% 50%", "100% 50%", "0% 100%", "50% 100%", "100% 100%"];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Mục "Ảnh nền" của tab Kiểu dáng (attrs.style.background, @ecomcx/ecomweb-content 1.22): ảnh từ thư viện media (hoặc dán URL),
|
|
13
|
+
* ảnh / cách phủ / điểm lấy nét riêng theo khổ màn hình đang chọn, lặp, cố định khi cuộn, lớp phủ màu + độ mờ.
|
|
14
|
+
*/
|
|
15
|
+
export function BackgroundPanel({ style: raw, onChange, device }: { style: unknown; onChange(style: BlockStyle | null): void; device: Device }) {
|
|
16
|
+
const { host } = useEditor();
|
|
17
|
+
const t = useMsgs("background");
|
|
18
|
+
const style: BlockStyle = normalizeStyle(raw) ?? {};
|
|
19
|
+
const bg: BlockBackground = style.background ?? {};
|
|
20
|
+
const [url, setUrl] = useState("");
|
|
21
|
+
|
|
22
|
+
const commit = (next: Record<string, unknown> | undefined) => onChange(normalizeStyle({ ...style, background: next }) ?? null);
|
|
23
|
+
const set = (patch: Record<string, unknown>) => commit({ ...bg, ...patch });
|
|
24
|
+
/** Giá trị theo khổ đang chọn (ảnh, cách phủ, điểm lấy nét). */
|
|
25
|
+
const setAt = (k: "image" | "size" | "position", v: string | undefined) => {
|
|
26
|
+
const r: Record<string, string | undefined> = { ...(bg[k] ?? {}) };
|
|
27
|
+
if (v) r[device] = v; else delete r[device];
|
|
28
|
+
set({ [k]: Object.keys(r).length ? r : undefined });
|
|
29
|
+
};
|
|
30
|
+
const image = bg.image?.[device];
|
|
31
|
+
const inherited = device === "mobile" ? bg.image?.tablet ?? bg.image?.base : device === "tablet" ? bg.image?.base : undefined;
|
|
32
|
+
const pick = async () => {
|
|
33
|
+
const [item] = (await host.media?.pick({ kind: "image", multiple: false })) ?? [];
|
|
34
|
+
if (item) setAt("image", item.sizes?.large?.url ?? item.url);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Section title={t.title} modified={!!style.background} onReset={() => commit(undefined)} defaultOpen={!!style.background}>
|
|
39
|
+
<Row label={t.image} device={device}>
|
|
40
|
+
<div className="ecx-bg-image">
|
|
41
|
+
{(image ?? inherited) && <img src={image ?? inherited} alt="" className={cx("ecx-bg-thumb", !image && "is-inherited")} style={{ objectPosition: bg.position?.[device] ?? bg.position?.base ?? "50% 50%" }} />}
|
|
42
|
+
<div className="ecx-bg-actions">
|
|
43
|
+
{host.media && <button type="button" className="ecx-btn" onClick={pick}>{image ? t.replace : t.choose}</button>}
|
|
44
|
+
{image && <button type="button" className="ecx-btn" onClick={() => setAt("image", undefined)}>{t.remove}</button>}
|
|
45
|
+
</div>
|
|
46
|
+
{!host.media && (
|
|
47
|
+
<input className="ecx-input" value={url} placeholder="https://…" aria-label={t.url}
|
|
48
|
+
onChange={(e) => setUrl(e.target.value)} onBlur={() => { setAt("image", url.trim() || undefined); setUrl(""); }} />
|
|
49
|
+
)}
|
|
50
|
+
{inherited && !image && <p className="ecx-muted">{t.inherited}</p>}
|
|
51
|
+
</div>
|
|
52
|
+
</Row>
|
|
53
|
+
{bg.image && (
|
|
54
|
+
<>
|
|
55
|
+
<Row label={t.size} device={device}>
|
|
56
|
+
<Seg label={t.size} value={bg.size?.[device]} onChange={(v) => setAt("size", v)}
|
|
57
|
+
options={[["cover", t.cover, t.cover_help], ["contain", t.contain, t.contain_help], ["auto", t.auto, t.auto_help]]} />
|
|
58
|
+
</Row>
|
|
59
|
+
<Row label={t.focal} device={device}>
|
|
60
|
+
<div role="radiogroup" aria-label={t.focal} className="ecx-bg-focal">
|
|
61
|
+
{POSITIONS.map((p) => (
|
|
62
|
+
<button key={p} type="button" role="radio" aria-checked={(bg.position?.[device] ?? (device === "base" ? "50% 50%" : undefined)) === p} title={p} aria-label={p}
|
|
63
|
+
className={cx("ecx-bg-focal-dot", (bg.position?.[device] ?? (device === "base" ? "50% 50%" : undefined)) === p && "is-active")}
|
|
64
|
+
onClick={() => setAt("position", p === "50% 50%" && device === "base" ? undefined : p)} />
|
|
65
|
+
))}
|
|
66
|
+
</div>
|
|
67
|
+
</Row>
|
|
68
|
+
<label className="ecx-check"><input type="checkbox" checked={!!bg.repeat} onChange={(e) => set({ repeat: e.target.checked || undefined })} /> {t.repeat}</label>
|
|
69
|
+
<label className="ecx-check"><input type="checkbox" checked={!!bg.fixed} onChange={(e) => set({ fixed: e.target.checked || undefined })} /> {t.fixed}</label>
|
|
70
|
+
</>
|
|
71
|
+
)}
|
|
72
|
+
<Row label={t.overlay}>
|
|
73
|
+
<ColorInput label={t.overlay} value={bg.overlay} onChange={(v) => set({ overlay: v, overlayOpacity: v ? bg.overlayOpacity : undefined })} />
|
|
74
|
+
</Row>
|
|
75
|
+
{bg.overlay && (
|
|
76
|
+
<Row label={`${t.opacity}: ${bg.overlayOpacity ?? 50}%`}>
|
|
77
|
+
<input type="range" min={0} max={100} step={5} value={bg.overlayOpacity ?? 50} aria-label={t.opacity}
|
|
78
|
+
onChange={(e) => set({ overlayOpacity: Number(e.target.value) === 50 ? undefined : Number(e.target.value) })} />
|
|
79
|
+
</Row>
|
|
80
|
+
)}
|
|
81
|
+
</Section>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Chép / dán kiểu dáng (chỉ `attrs.style`) + vị trí menu chuột phải. */
|
|
2
|
+
|
|
3
|
+
// shortcut: chỉ nhớ trong phiên (bộ nhớ của trang admin, giữ khi chuyển bài trong SPA), mất khi tải lại — cần chép giữa tab thì chuyển sang localStorage.
|
|
4
|
+
let copied: { style?: Record<string, unknown> } | null = null;
|
|
5
|
+
|
|
6
|
+
export function copyStyle(attrs: Record<string, unknown>) {
|
|
7
|
+
const s = attrs.style;
|
|
8
|
+
copied = { style: s && typeof s === "object" ? structuredClone(s as Record<string, unknown>) : undefined };
|
|
9
|
+
}
|
|
10
|
+
export const hasCopiedStyle = () => copied !== null;
|
|
11
|
+
/** Thuộc tính để dán (bản sao mới mỗi lần); khối nguồn không có kiểu dáng → dán = bỏ kiểu dáng. null = chưa chép. */
|
|
12
|
+
export const pastedStyle = (): { style: Record<string, unknown> | undefined } | null => copied && { style: copied.style && structuredClone(copied.style) };
|
|
13
|
+
|
|
14
|
+
/** Góc trên-trái của menu (w×h) mở tại (x, y): sát mép phải / dưới thì lật sang trái / lên trên, luôn cách mép 8px. */
|
|
15
|
+
export function menuPosition(x: number, y: number, w: number, h: number, vw: number, vh: number) {
|
|
16
|
+
const left = x + w > vw - 8 ? x - w : x;
|
|
17
|
+
const top = y + h > vh - 8 ? y - h : y;
|
|
18
|
+
return { left: Math.round(Math.max(8, Math.min(left, vw - 8 - w))), top: Math.round(Math.max(8, Math.min(top, vh - 8 - h))) };
|
|
19
|
+
}
|
package/src/v2/ui/inserter.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import { useEditor, useUiTick, type InserterRequest } from "../context";
|
|
|
7
7
|
import { cloneBlock, inlineLength, makeBlock, type BNode } from "../core/model";
|
|
8
8
|
import type { BlockType } from "../core/registry";
|
|
9
9
|
import { canContain } from "../core/structure";
|
|
10
|
-
import { startDragNew } from "../canvas/dnd";
|
|
10
|
+
import { startDragBlocks, startDragNew } from "../canvas/dnd";
|
|
11
11
|
import { usePrefs } from "../prefs";
|
|
12
12
|
import { onPatternsChange, patternBlocks, registeredPatterns, type Pattern } from "../core/patterns";
|
|
13
13
|
import { useSyncExternalStore } from "react";
|
|
@@ -115,6 +115,9 @@ export function InserterPopover() {
|
|
|
115
115
|
const options = useAllowed(req, useInsertOptions());
|
|
116
116
|
const [query, setQuery] = useState("");
|
|
117
117
|
const [active, setActive] = useState(0);
|
|
118
|
+
// Giữa hai section cấp trên cùng (nút "+ Thêm section"): có thêm tab Mẫu để chèn cả section tại chỗ
|
|
119
|
+
const [patternTab, setPatternTab] = useState(false);
|
|
120
|
+
useEffect(() => { setPatternTab(false); }, [req]);
|
|
118
121
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
119
122
|
const listRef = useRef<HTMLDivElement>(null);
|
|
120
123
|
const q = req?.mode === "slash" ? req.query ?? "" : query;
|
|
@@ -168,7 +171,15 @@ export function InserterPopover() {
|
|
|
168
171
|
else if (e.key === "Escape") { e.preventDefault(); ui.openInserter(null); }
|
|
169
172
|
}} />
|
|
170
173
|
)}
|
|
171
|
-
{
|
|
174
|
+
{req.mode === "between" && !req.parentId && (
|
|
175
|
+
<div className="ecx-tabs" role="tablist">
|
|
176
|
+
<button type="button" role="tab" aria-selected={!patternTab} className={!patternTab ? "is-active" : undefined} onClick={() => setPatternTab(false)}>{labels.blocks}</button>
|
|
177
|
+
<button type="button" role="tab" aria-selected={patternTab} className={patternTab ? "is-active" : undefined} onClick={() => setPatternTab(true)}>{labels.patterns}</button>
|
|
178
|
+
</div>
|
|
179
|
+
)}
|
|
180
|
+
{patternTab ? (
|
|
181
|
+
<div className="ecx-inserter-list ecx-inserter-patterns"><PatternList query={query} at={req} onInserted={() => ui.openInserter(null)} /></div>
|
|
182
|
+
) : quick ? (
|
|
172
183
|
<>
|
|
173
184
|
<div className="ecx-quick-grid" role="listbox" aria-label={labels.blocks}>
|
|
174
185
|
{quick.map((o, i) => (
|
|
@@ -312,8 +323,9 @@ export function InserterPanel({ onInserted, onClose }: { onInserted?(): void; on
|
|
|
312
323
|
}
|
|
313
324
|
|
|
314
325
|
/** Mẫu (lõi, theme, plugin, người dùng tạo): bấm chèn sau khối đang chọn; mẫu đồng bộ chèn thành tham chiếu. */
|
|
315
|
-
function PatternList({ query, onInserted }: { query: string; onInserted?(): void }) {
|
|
316
|
-
const
|
|
326
|
+
function PatternList({ query, onInserted, at }: { query: string; onInserted?(): void; at?: { docId: string; parentId: string | null; index: number } }) {
|
|
327
|
+
const ctx = useEditor();
|
|
328
|
+
const { store, labels } = ctx;
|
|
317
329
|
const all = useSyncExternalStore(onPatternsChange, registeredPatterns, registeredPatterns);
|
|
318
330
|
const q = norm(query.trim());
|
|
319
331
|
const list = q ? all.filter((p) => norm(`${p.title} ${p.keywords ?? ""} ${p.category}`).includes(q)) : all;
|
|
@@ -324,8 +336,11 @@ function PatternList({ query, onInserted }: { query: string; onInserted?(): void
|
|
|
324
336
|
const nodes = patternBlocks(p);
|
|
325
337
|
if (!nodes.length) return;
|
|
326
338
|
const cur = store.currentIds[store.currentIds.length - 1];
|
|
327
|
-
if (
|
|
339
|
+
if (at) store.insert(at.docId, at.parentId, at.index, nodes, { focus: false });
|
|
340
|
+
else if (cur && store.locate(cur)) store.insertAfter(cur, nodes, { focus: false });
|
|
328
341
|
else { const docId = store.activeDocId; store.insert(docId, null, store.getState().docs[docId].blocks.length, nodes, { focus: false }); }
|
|
342
|
+
// Mẫu nhiều khối: chọn khối đầu (không chọn cả nhóm → tab Cài đặt có nội dung, không chồng nhãn)
|
|
343
|
+
if (nodes.length > 1) store.select([nodes[0].id]);
|
|
329
344
|
onInserted?.();
|
|
330
345
|
};
|
|
331
346
|
if (!list.length) return <p className="ecx-muted">{labels.noResults}</p>;
|
|
@@ -335,7 +350,7 @@ function PatternList({ query, onInserted }: { query: string; onInserted?(): void
|
|
|
335
350
|
<section key={c}>
|
|
336
351
|
<h3 className="ecx-panel-heading">{catName(c)}</h3>
|
|
337
352
|
{list.filter((p) => p.category === c).map((p) => (
|
|
338
|
-
<button key={p.name} type="button" className="ecx-pattern-card" data-pattern={p.name} onClick={() => insert(p)}>
|
|
353
|
+
<button key={p.name} type="button" className="ecx-pattern-card" data-pattern={p.name} onPointerDown={(e) => startDragBlocks(ctx, e, () => patternBlocks(p))} onClick={() => insert(p)}>
|
|
339
354
|
<strong>{p.title}</strong>{p.description && <span className="ecx-muted">{p.description}</span>}
|
|
340
355
|
</button>
|
|
341
356
|
))}
|
package/src/v2/ui/inspector.tsx
CHANGED
|
@@ -2,22 +2,27 @@ import type { Device } from "@ecomcx/ecomweb-content";
|
|
|
2
2
|
import { CORE_BLOCK_STYLES } from "@ecomcx/ecomweb-content";
|
|
3
3
|
import { Blocks } from "lucide-react";
|
|
4
4
|
import { useState, useSyncExternalStore } from "react";
|
|
5
|
-
import { blockPanelsFor, onBlockPanelsChange } from "../../shared/panel-store";
|
|
6
|
-
import { useEditor, useEditorState } from "../context";
|
|
5
|
+
import { blockPanelsFor, onBlockPanelsChange, type BlockPanel } from "../../shared/panel-store";
|
|
6
|
+
import { useEditor, useEditorState, useUiTick } from "../context";
|
|
7
7
|
import type { BNode } from "../core/model";
|
|
8
8
|
import { AttrForm, Field, attrName, cx } from "./attr-form";
|
|
9
9
|
import { BindingsPanel, CORE_BINDABLE } from "./bindings";
|
|
10
10
|
import { StyleTab } from "./style-tab";
|
|
11
|
+
import { ColorInput } from "./color-field";
|
|
12
|
+
import { UnitInput } from "./unit-controls";
|
|
11
13
|
import { useMsgs } from "../i18n";
|
|
12
14
|
|
|
13
15
|
/** Bảng cài đặt của khối đang chọn: thẻ khối, tab Cài đặt (form + phần riêng của khối), tab Kiểu dáng. */
|
|
14
16
|
export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<{ name: string; label: string }>> }) {
|
|
15
|
-
const { store, registry, labels } = useEditor();
|
|
17
|
+
const { store, registry, labels, ui } = useEditor();
|
|
18
|
+
useUiTick();
|
|
16
19
|
const t = useMsgs("controls");
|
|
17
20
|
const sel = useEditorState((s) => s.selection);
|
|
18
21
|
useEditorState((s) => s.revision);
|
|
19
22
|
const [tab, setTab] = useState<"settings" | "style">("settings");
|
|
20
|
-
|
|
23
|
+
// Khổ dùng chung với khung soạn: chọn "Điện thoại" ở đây thì khung soạn cũng thu về khổ điện thoại
|
|
24
|
+
const device: Device = ui.device === "desktop" ? "base" : ui.device;
|
|
25
|
+
const setDevice = (d: Device) => ui.setDevice(d === "base" ? "desktop" : d);
|
|
21
26
|
const ids = sel.ids.length ? sel.ids : sel.editing ? [sel.editing] : [];
|
|
22
27
|
const nodes = ids.map((id) => store.block(id)).filter(Boolean) as BNode[];
|
|
23
28
|
if (!nodes.length) return <div className="ecx-inspector is-empty"><p className="ecx-muted">{labels.noSelection}</p></div>;
|
|
@@ -60,6 +65,7 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
|
|
|
60
65
|
<div className="ecx-panel">
|
|
61
66
|
<StyleTab type={first.type} style={first.attrs.style} onChange={(st) => setAttrs({ style: st ?? undefined })} device={device} onDeviceChange={setDevice}
|
|
62
67
|
variants={variants.length ? variants : undefined} variant={(first.attrs.blockStyle as string) ?? null} onVariantChange={(v) => setAttrs({ blockStyle: v ?? undefined })} />
|
|
68
|
+
{same && nodes.length === 1 && <PluginPanels type={first.type} attrs={first.attrs} setAttrs={setAttrs} tab="style" />}
|
|
63
69
|
</div>
|
|
64
70
|
)}
|
|
65
71
|
</>
|
|
@@ -69,19 +75,50 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
|
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
/** Panel của plugin (registerBlockPanel) cho loại khối đang chọn. */
|
|
72
|
-
function PluginPanels({ type, attrs, setAttrs }: { type: string; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void }) {
|
|
78
|
+
function PluginPanels({ type, attrs, setAttrs, tab = "block" }: { type: string; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void; tab?: "block" | "style" }) {
|
|
73
79
|
const { host } = useEditor();
|
|
74
|
-
useSyncExternalStore(onBlockPanelsChange, () => blockPanelsFor(type).length, () => 0);
|
|
75
|
-
const panels = blockPanelsFor(type);
|
|
80
|
+
useSyncExternalStore(onBlockPanelsChange, () => blockPanelsFor(type, tab).length, () => 0);
|
|
81
|
+
const panels = blockPanelsFor(type, tab);
|
|
76
82
|
if (!panels.length) return null;
|
|
77
83
|
return (
|
|
78
84
|
<>
|
|
79
85
|
{panels.map((p) => (
|
|
80
86
|
<details key={p.id} className="ecx-advanced" open>
|
|
81
87
|
<summary>{host.translate ? host.translate(p.title) : p.title}</summary>
|
|
82
|
-
<p.component type={type} attrs={attrs} setAttrs={setAttrs} />
|
|
88
|
+
{p.component ? <p.component type={type} attrs={attrs} setAttrs={setAttrs} /> : <ControlFields panel={p} attrs={attrs} setAttrs={setAttrs} />}
|
|
83
89
|
</details>
|
|
84
90
|
))}
|
|
85
91
|
</>
|
|
86
92
|
);
|
|
87
93
|
}
|
|
94
|
+
|
|
95
|
+
/** Ô tự vẽ cho thuộc tính khai `type` của panel không có component riêng. */
|
|
96
|
+
function ControlFields({ panel, attrs, setAttrs }: { panel: BlockPanel; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void }) {
|
|
97
|
+
const { host } = useEditor();
|
|
98
|
+
const tr = (s?: string) => (s && host.translate ? host.translate(s) : s);
|
|
99
|
+
return (
|
|
100
|
+
<>
|
|
101
|
+
{Object.entries(panel.attributes ?? {}).map(([name, spec]) => {
|
|
102
|
+
if (!("type" in spec)) return null;
|
|
103
|
+
const label = tr(spec.label) ?? name;
|
|
104
|
+
const v = attrs[name];
|
|
105
|
+
const set = (x: unknown) => setAttrs({ [name]: x === "" ? undefined : x });
|
|
106
|
+
if (spec.type === "color") return <ColorInput key={name} label={label} value={v} onChange={set} />;
|
|
107
|
+
if (spec.type === "length") return <UnitInput key={name} label={label} value={v} onChange={set} />;
|
|
108
|
+
if (spec.type === "enum") return (
|
|
109
|
+
<Field key={name} label={label}>
|
|
110
|
+
<select className="ecx-input" value={v ?? ""} onChange={(e) => set(e.target.value)}>
|
|
111
|
+
<option value="">—</option>
|
|
112
|
+
{spec.options?.map((o) => <option key={o} value={o}>{o}</option>)}
|
|
113
|
+
</select>
|
|
114
|
+
</Field>
|
|
115
|
+
);
|
|
116
|
+
return (
|
|
117
|
+
<Field key={name} label={label}>
|
|
118
|
+
<input className="ecx-input" type="number" min={spec.min} max={spec.max} value={v ?? ""} onChange={(e) => set(e.target.value === "" ? undefined : Number(e.target.value))} />
|
|
119
|
+
</Field>
|
|
120
|
+
);
|
|
121
|
+
})}
|
|
122
|
+
</>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
@@ -21,7 +21,7 @@ export function layoutFor(kind: Kind, prev?: BlockLayout): BlockLayout | undefin
|
|
|
21
21
|
return { type: "flex", direction: { base: kind === "stack" ? "column" : "row" }, ...(prev?.justify ? { justify: prev.justify } : {}), ...(prev?.align ? { align: prev.align } : {}) };
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function LayoutEffectsPanel({ type, style: raw, onChange, device }: { type: string; style: unknown; onChange(style: BlockStyle | null): void; device: Device }) {
|
|
24
|
+
export function LayoutEffectsPanel({ type, style: raw, onChange, device, effects = true, hover = true }: { type: string; style: unknown; onChange(style: BlockStyle | null): void; device: Device; effects?: boolean; hover?: boolean }) {
|
|
25
25
|
const { labels, host } = useEditor();
|
|
26
26
|
const t = useMsgs("layout");
|
|
27
27
|
const style: BlockStyle = normalizeStyle(raw) ?? {};
|
|
@@ -92,7 +92,7 @@ export function LayoutEffectsPanel({ type, style: raw, onChange, device }: { typ
|
|
|
92
92
|
</Section>
|
|
93
93
|
)}
|
|
94
94
|
|
|
95
|
-
<Section title={t.effects} defaultOpen={!!(style.gradient || style.shadow || style.aspectRatio || style.position)}>
|
|
95
|
+
{effects && <Section title={t.effects} defaultOpen={!!(style.gradient || style.shadow || style.aspectRatio || style.position)}>
|
|
96
96
|
<Row label={t.gradient}>
|
|
97
97
|
<div className="ecx-chip-row">
|
|
98
98
|
<button type="button" className={cx("ecx-chip", !style.gradient && "is-active")} onClick={() => set({ gradient: undefined })}>{t.none}</button>
|
|
@@ -124,9 +124,9 @@ export function LayoutEffectsPanel({ type, style: raw, onChange, device }: { typ
|
|
|
124
124
|
</select>
|
|
125
125
|
</Row>
|
|
126
126
|
<label className="ecx-check"><input type="checkbox" checked={!!style.position} onChange={(e) => set({ position: e.target.checked ? { type: "sticky" } : undefined })} /> {t.sticky}</label>
|
|
127
|
-
</Section>
|
|
127
|
+
</Section>}
|
|
128
128
|
|
|
129
|
-
<Section title={t.hover} defaultOpen={!!style.hover}>
|
|
129
|
+
{hover && <Section title={t.hover} defaultOpen={!!style.hover}>
|
|
130
130
|
{(["text", "background"] as const).map((k) => (
|
|
131
131
|
<Row key={k} label={t[k]}>
|
|
132
132
|
<ColorInput label={t[k]} value={style.hover?.color?.[k]} onChange={(v) => set({ hover: { ...style.hover, color: { ...style.hover?.color, [k]: v } } })} />
|
|
@@ -141,7 +141,7 @@ export function LayoutEffectsPanel({ type, style: raw, onChange, device }: { typ
|
|
|
141
141
|
</select>
|
|
142
142
|
</Row>
|
|
143
143
|
<label className="ecx-check"><input type="checkbox" checked={!!style.hover?.lift} onChange={(e) => set({ hover: { ...style.hover, lift: e.target.checked || undefined } })} /> {t.lift}</label>
|
|
144
|
-
</Section>
|
|
144
|
+
</Section>}
|
|
145
145
|
</div>
|
|
146
146
|
);
|
|
147
147
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Plus } from "lucide-react";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { useEditor, useUiTick } from "../context";
|
|
4
|
+
|
|
5
|
+
/** Khoảng (px) quanh ranh giới hai section mà rê chuột vào thì hiện nút. */
|
|
6
|
+
const ZONE = 14;
|
|
7
|
+
|
|
8
|
+
/** Chỉ số chèn khi con trỏ ở gần ranh giới giữa các khối cấp trên cùng (trên khối đầu, giữa hai khối, dưới khối cuối); xa ranh giới → null. */
|
|
9
|
+
export function boundaryAt(rects: Array<{ top: number; bottom: number }>, y: number, zone = ZONE): { index: number; y: number } | null {
|
|
10
|
+
for (let i = 0; i <= rects.length; i++) {
|
|
11
|
+
const edge = i === 0 ? rects[0]?.top : i === rects.length ? rects[i - 1].bottom : (rects[i - 1].bottom + rects[i].top) / 2;
|
|
12
|
+
if (edge !== undefined && Math.abs(y - edge) <= zone) return { index: i, y: edge };
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Nút "+ Thêm section" (như Elementor): rê chuột tới ranh giới giữa hai section cấp trên cùng của tài liệu đang soạn → hiện nút giữa khung;
|
|
19
|
+
* bấm mở popover chèn tại đúng chỗ đó (tab Khối / Mẫu).
|
|
20
|
+
*/
|
|
21
|
+
export function SectionAdder() {
|
|
22
|
+
const { ui, store, labels } = useEditor();
|
|
23
|
+
useUiTick();
|
|
24
|
+
const [spot, setSpot] = useState<{ index: number; x: number; y: number; left: number } | null>(null);
|
|
25
|
+
const doc = ui.canvasDoc;
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!doc) return;
|
|
28
|
+
const move = (e: MouseEvent) => {
|
|
29
|
+
if (ui.drag || ui.zoomOut || ui.inserter) return setSpot(null);
|
|
30
|
+
const docId = store.activeDocId;
|
|
31
|
+
const d = store.getState().docs[docId];
|
|
32
|
+
if (!d || d.mode !== "default" || !d.blocks.length) return setSpot(null);
|
|
33
|
+
const rects = d.blocks.map((b) => ui.blockRect(b.id)).filter((r): r is DOMRect => !!r);
|
|
34
|
+
const f = ui.canvasFrame?.getBoundingClientRect();
|
|
35
|
+
if (!f || rects.length !== d.blocks.length) return setSpot(null);
|
|
36
|
+
const scale = f.width / (ui.canvasFrame!.offsetWidth || f.width) || 1;
|
|
37
|
+
const y = f.top + e.clientY * scale;
|
|
38
|
+
const hit = boundaryAt(rects, y);
|
|
39
|
+
setSpot(hit ? { index: hit.index, y: hit.y, x: f.left + f.width / 2, left: f.left } : null);
|
|
40
|
+
};
|
|
41
|
+
// Không ẩn khi chuột rời khung soạn: nút nằm ở trang ngoài, rời khung để bấm nút là chuyện bình thường
|
|
42
|
+
const leave = () => setSpot(null);
|
|
43
|
+
doc.addEventListener("mousemove", move);
|
|
44
|
+
doc.addEventListener("scroll", leave);
|
|
45
|
+
return () => { doc.removeEventListener("mousemove", move); doc.removeEventListener("scroll", leave); };
|
|
46
|
+
}, [doc, ui, store]);
|
|
47
|
+
if (!spot || ui.drag || ui.inserter) return null;
|
|
48
|
+
return (
|
|
49
|
+
<button type="button" className="ecx-section-adder" style={{ top: Math.round(spot.y - 14), left: Math.round(spot.x - 14) }} aria-label={labels.addSection} title={labels.addSection}
|
|
50
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
51
|
+
onClick={() => {
|
|
52
|
+
ui.openInserter({ mode: "between", docId: store.activeDocId, parentId: null, index: spot.index, rect: { left: Math.max(spot.left + 8, spot.x - 160), top: spot.y, bottom: spot.y + 14 } });
|
|
53
|
+
setSpot(null);
|
|
54
|
+
}}>
|
|
55
|
+
<Plus className="ecx-icon" />
|
|
56
|
+
</button>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BlockType } from "../core/registry";
|
|
2
|
+
|
|
3
|
+
/** Nhóm của tab Kiểu dáng. Khối chỉ hiện nhóm nó hỗ trợ (như `supports` trong block.json của WordPress). */
|
|
4
|
+
export type StyleGroup = "typography" | "color" | "background" | "spacing" | "border" | "effects" | "hover" | "motion" | "visibility";
|
|
5
|
+
|
|
6
|
+
export const STYLE_GROUPS: readonly StyleGroup[] = ["typography", "color", "background", "spacing", "border", "effects", "hover", "motion", "visibility"];
|
|
7
|
+
const NO_BACKGROUND = STYLE_GROUPS.filter((g) => g !== "background");
|
|
8
|
+
const MEDIA: StyleGroup[] = ["spacing", "border", "effects", "hover", "motion", "visibility"];
|
|
9
|
+
const MINIMAL: StyleGroup[] = ["spacing", "visibility"];
|
|
10
|
+
|
|
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
|
+
const CORE: Record<string, StyleGroup[]> = {
|
|
13
|
+
spacer: MINIMAL, pageBreak: ["visibility"], customHtml: MINIMAL, shortcode: MINIMAL, audio: MINIMAL,
|
|
14
|
+
horizontalRule: ["color", "spacing", "border", "visibility"],
|
|
15
|
+
image: MEDIA, gallery: MEDIA, video: MEDIA, youtube: MEDIA, embed: MEDIA, featuredImage: MEDIA, siteLogo: MEDIA, avatar: MEDIA,
|
|
16
|
+
icon: ["color", "spacing", "motion", "visibility"],
|
|
17
|
+
socialLinks: ["color", "spacing", "motion", "visibility"],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Nhóm kiểu dáng của một loại khối. Khối plugin khai `supports.style` là mảng nhóm để chọn; `true` / không khai = mặc định như trên.
|
|
22
|
+
* Nhóm khối đã có giá trị vẫn hiện (để sửa / xoá) dù không nằm trong danh sách — xem StyleTab.
|
|
23
|
+
*/
|
|
24
|
+
export function styleGroups(name: string, type?: BlockType): Set<StyleGroup> {
|
|
25
|
+
const s = type?.supports?.style;
|
|
26
|
+
if (Array.isArray(s)) return new Set(s.filter((g): g is StyleGroup => STYLE_GROUPS.includes(g as StyleGroup)));
|
|
27
|
+
if (CORE[name]) return new Set(CORE[name]);
|
|
28
|
+
return new Set(type?.kind === "container" ? STYLE_GROUPS : NO_BACKGROUND);
|
|
29
|
+
}
|
package/src/v2/ui/style-tab.tsx
CHANGED
|
@@ -3,10 +3,12 @@ import { AlignCenter, AlignJustify, AlignLeft, AlignRight, Monitor, Smartphone,
|
|
|
3
3
|
import { useEffect, useState, type ReactNode } from "react";
|
|
4
4
|
import { labelsLegacy, type EditorLabels } from "../../shared/labels";
|
|
5
5
|
import { useEditor } from "../context";
|
|
6
|
+
import { BackgroundPanel } from "./background-panel";
|
|
6
7
|
import { ColorInput } from "./color-field";
|
|
7
8
|
import { LayoutEffectsPanel } from "./layout-panel";
|
|
8
9
|
import { MotionPanel } from "./motion-panel";
|
|
9
10
|
import { Section, Seg, cx } from "./style-controls";
|
|
11
|
+
import { styleGroups, type StyleGroup } from "./style-supports";
|
|
10
12
|
import { SpacingControl, UnitInput } from "./unit-controls";
|
|
11
13
|
import { useMsgs } from "../i18n";
|
|
12
14
|
|
|
@@ -43,7 +45,7 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
43
45
|
type: string; style: unknown; onChange(style: BlockStyle | null): void; device: Device; onDeviceChange(d: Device): void;
|
|
44
46
|
variants?: Array<{ name: string; label: string }>; variant?: string | null; onVariantChange?(v: string | null): void;
|
|
45
47
|
}) {
|
|
46
|
-
const { host, labels } = useEditor();
|
|
48
|
+
const { host, labels, registry } = useEditor();
|
|
47
49
|
const t = labelsLegacy(labels.lang);
|
|
48
50
|
const ct = useMsgs("controls");
|
|
49
51
|
const presets = host.presets;
|
|
@@ -86,6 +88,9 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
86
88
|
const row = (k: string, label: string, control: ReactNode) => (
|
|
87
89
|
<div className="ecx-style-row" key={k}><span className="ecx-field-label">{label}{tag(k)}</span>{control}</div>
|
|
88
90
|
);
|
|
91
|
+
// Nhóm khối hỗ trợ; nhóm đã có giá trị vẫn hiện để sửa / xoá (dữ liệu cũ, khối dán từ nơi khác)
|
|
92
|
+
const groups = styleGroups(type, registry.get(type));
|
|
93
|
+
const show = (g: StyleGroup, keys: string[]) => groups.has(g) || keys.some((k) => style[k] !== undefined);
|
|
89
94
|
const appearance = `${style.fontWeight ?? ""}${style.fontStyle === "italic" ? "i" : ""}`;
|
|
90
95
|
|
|
91
96
|
return (
|
|
@@ -108,7 +113,7 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
108
113
|
</div>
|
|
109
114
|
)}
|
|
110
115
|
|
|
111
|
-
<Section title={t.style_typography} modified={has(TYPO)} onReset={() => reset(TYPO)} moreOpen={has(["fontFamily", "letterSpacing", "textDecoration", "textTransform"])}
|
|
116
|
+
{show("typography", TYPO) && <Section title={t.style_typography} modified={has(TYPO)} onReset={() => reset(TYPO)} moreOpen={has(["fontFamily", "letterSpacing", "textDecoration", "textTransform"])}
|
|
112
117
|
more={<>
|
|
113
118
|
{row("fontFamily", t.style_fontFamily,
|
|
114
119
|
<select className="ecx-input" value={style.fontFamily ?? ""} aria-label={t.style_fontFamily} onChange={(e) => set("fontFamily", e.target.value || undefined)}>
|
|
@@ -122,8 +127,9 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
122
127
|
options={[["none", "—", t.none], ["uppercase", "AB", t.upper], ["lowercase", "ab", t.lower], ["capitalize", "Ab", t.capitalize]]} />)}
|
|
123
128
|
</>}>
|
|
124
129
|
{row("fontSize", t.style_fontSize, <>
|
|
125
|
-
<Seg label={t.style_fontSize} value={get("fontSize")} onChange={(v) => set("fontSize", v)} options={sizes.map((v) => [v, v.toUpperCase(), v] as [string, string, string])} />
|
|
126
|
-
|
|
130
|
+
<Seg label={t.style_fontSize} value={get("fontSize")} onChange={(v) => set("fontSize", v)} options={sizes.map((v) => [v, v.toUpperCase(), presets?.fontSizes?.[v] ? `${v} · ${presets.fontSizes[v]}` : v] as [string, string, string])} />
|
|
131
|
+
{/* Cỡ tuỳ chỉnh: ô số + đơn vị + thanh kéo (preset chọn ở hàng trên; giá trị clamp() cũ hiện làm gợi ý) */}
|
|
132
|
+
<UnitInput label={`${t.style_fontSize}: ${t.custom}`} value={sizes.includes(get("fontSize")) ? undefined : get("fontSize")} placeholder={inherited("fontSize") ?? "18px"} units={["px", "rem", "em"]} max={96} onChange={(v) => set("fontSize", v)} />
|
|
127
133
|
</>)}
|
|
128
134
|
{row("appearance", t.style_appearance,
|
|
129
135
|
<select className="ecx-input" value={appearance} aria-label={t.style_appearance} onChange={(e) => {
|
|
@@ -136,38 +142,41 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
136
142
|
{row("lineHeight", t.style_lineHeight, <ValueInput label={t.style_lineHeight} value={get("lineHeight")} inherited={inherited("lineHeight")} check={ok("lineHeight")} placeholder="1.5" onCommit={(v) => set("lineHeight", v == null ? undefined : Number(v))} />)}
|
|
137
143
|
{row("textAlign", t.textAlign, <Seg label={t.textAlign} value={get("textAlign")} onChange={(v) => set("textAlign", v)}
|
|
138
144
|
options={[["left", AlignLeft, t.alignLeft], ["center", AlignCenter, t.alignCenter], ["right", AlignRight, t.alignRight], ["justify", AlignJustify, t.alignJustify]]} />)}
|
|
139
|
-
</Section>
|
|
145
|
+
</Section>}
|
|
140
146
|
|
|
141
|
-
<Section title={t.style_color} modified={has(["color"])} onReset={() => reset(["color"])}>
|
|
147
|
+
{show("color", ["color"]) && <Section title={t.style_color} modified={has(["color"])} onReset={() => reset(["color"])}>
|
|
142
148
|
{row("text", t.style_text, <ColorInput label={t.style_text} value={style.color?.text} onChange={(v) => setGroup("color", "text", v)} />)}
|
|
143
149
|
{row("background", t.style_background, <ColorInput label={t.style_background} value={style.color?.background} onChange={(v) => setGroup("color", "background", v)} />)}
|
|
144
|
-
</Section>
|
|
150
|
+
</Section>}
|
|
145
151
|
|
|
146
|
-
<
|
|
152
|
+
{show("background", ["background"]) && <BackgroundPanel style={raw} onChange={onChange} device={device} />}
|
|
153
|
+
|
|
154
|
+
{show("spacing", SPACING) && <Section title={t.style_spacing} modified={has(SPACING)} onReset={() => reset(SPACING)} moreOpen={has(["gap", "width", "maxWidth", "minHeight"])}
|
|
147
155
|
more={<>{(["gap", "width", "maxWidth", "minHeight"] as const).map((k) =>
|
|
148
156
|
row(k, t[`style_${k}`], <ValueInput label={t[`style_${k}`]} value={get(k)} inherited={inherited(k)} check={ok(k)} placeholder={k === "gap" ? "md, 24px" : "100%, 640px, 60vh"} onCommit={(v) => set(k, v)} />))}</>}>
|
|
149
157
|
<SpacingControl label={t.style_padding} steps={spaces} value={get("padding")} inherited={inherited("padding")} onChange={(v) => set("padding", v)} labels={{ vertical: ct.vertical, horizontal: ct.horizontal, top: ct.sideTop, right: ct.sideRight, bottom: ct.sideBottom, left: ct.sideLeft, link: t.linkSides, unlink: t.unlinkSides }} />
|
|
150
158
|
<SpacingControl label={t.style_margin} steps={spaces} value={get("margin")} inherited={inherited("margin")} onChange={(v) => set("margin", v)} labels={{ vertical: ct.vertical, horizontal: ct.horizontal, top: ct.sideTop, right: ct.sideRight, bottom: ct.sideBottom, left: ct.sideLeft, link: t.linkSides, unlink: t.unlinkSides }} />
|
|
151
|
-
</Section>
|
|
159
|
+
</Section>}
|
|
152
160
|
|
|
153
|
-
<Section title={t.style_border} modified={has(["border", "radius"])} onReset={() => reset(["border", "radius"])} defaultOpen={has(["border", "radius"])}>
|
|
161
|
+
{show("border", ["border", "radius"]) && <Section title={t.style_border} modified={has(["border", "radius"])} onReset={() => reset(["border", "radius"])} defaultOpen={has(["border", "radius"])}>
|
|
154
162
|
{row("borderWidth", t.style_borderWidth, <UnitInput label={t.style_borderWidth} value={style.border?.width} max={20} units={["px", "em", "rem"]} onChange={(v) => setGroup("border", "width", v)} />)}
|
|
155
163
|
{row("borderStyle", t.style_borderStyle, <Seg label={t.style_borderStyle} value={style.border?.style} onChange={(v) => setGroup("border", "style", v)}
|
|
156
164
|
options={[["solid", "—", t.border_solid], ["dashed", "- -", t.border_dashed], ["dotted", "···", t.border_dotted]]} />)}
|
|
157
165
|
{row("borderColor", t.style_borderColor, <ColorInput label={t.style_borderColor} value={style.border?.color} onChange={(v) => setGroup("border", "color", v)} />)}
|
|
158
166
|
{row("radius", t.style_radius, <UnitInput label={t.style_radius} value={typeof style.radius === "string" ? style.radius : undefined} max={60} units={["px", "%", "em", "rem"]} onChange={(v) => set("radius", v)} />)}
|
|
159
|
-
</Section>
|
|
167
|
+
</Section>}
|
|
160
168
|
|
|
161
|
-
<LayoutEffectsPanel type={type} style={raw} onChange={onChange} device={device}
|
|
169
|
+
<LayoutEffectsPanel type={type} style={raw} onChange={onChange} device={device}
|
|
170
|
+
effects={show("effects", ["gradient", "shadow", "aspectRatio", "position"])} hover={show("hover", ["hover"])} />
|
|
162
171
|
|
|
163
|
-
<MotionPanel type={type} style={raw} onChange={onChange} />
|
|
172
|
+
{show("motion", ["motion"]) && <MotionPanel type={type} style={raw} onChange={onChange} />}
|
|
164
173
|
|
|
165
|
-
<Section title={t.style_visibility} modified={has(["hide"])} onReset={() => reset(["hide"])} defaultOpen={has(["hide"])}>
|
|
174
|
+
{show("visibility", ["hide"]) && <Section title={t.style_visibility} modified={has(["hide"])} onReset={() => reset(["hide"])} defaultOpen={has(["hide"])}>
|
|
166
175
|
{(["desktop", "tablet", "mobile"] as const).map((d) => (
|
|
167
176
|
<label key={d} className="ecx-check"><input type="checkbox" checked={!!style.hide?.includes(d)}
|
|
168
177
|
onChange={(e) => set("hide", e.target.checked ? [...(style.hide ?? []), d] : (style.hide ?? []).filter((x) => x !== d))} /> {t[`hide_${d}`]}</label>
|
|
169
178
|
))}
|
|
170
|
-
</Section>
|
|
179
|
+
</Section>}
|
|
171
180
|
</div>
|
|
172
181
|
);
|
|
173
182
|
}
|