@ecomcx/ecomweb-editor 1.31.0 → 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/locales/en/attrs.ts +10 -0
- package/src/locales/en/background.ts +17 -0
- package/src/locales/en/block-desc.ts +1 -0
- package/src/locales/en/block-style.ts +7 -4
- package/src/locales/en/block-titles.ts +1 -0
- package/src/locales/en/blocks.ts +10 -2
- package/src/locales/en/columns.ts +12 -0
- package/src/locales/en/controls.ts +21 -0
- package/src/locales/en/hints.ts +215 -1
- package/src/locales/en/index.ts +5 -2
- package/src/locales/en/layout.ts +32 -0
- package/src/locales/en/legacy.ts +1 -1
- package/src/locales/en/library.ts +38 -0
- package/src/locales/en/parts.ts +12 -0
- package/src/locales/en/placeholders.ts +9 -1
- package/src/locales/en/presets.ts +6 -0
- package/src/locales/en/v2.ts +21 -0
- package/src/locales/vi/attrs.ts +10 -0
- package/src/locales/vi/background.ts +17 -0
- package/src/locales/vi/block-desc.ts +1 -0
- package/src/locales/vi/block-style.ts +7 -4
- package/src/locales/vi/block-titles.ts +1 -0
- package/src/locales/vi/blocks.ts +10 -2
- package/src/locales/vi/columns.ts +12 -0
- package/src/locales/vi/controls.ts +21 -0
- package/src/locales/vi/hints.ts +216 -2
- package/src/locales/vi/index.ts +5 -2
- package/src/locales/vi/layout.ts +32 -0
- package/src/locales/vi/legacy.ts +1 -1
- package/src/locales/vi/library.ts +38 -0
- package/src/locales/vi/parts.ts +12 -0
- package/src/locales/vi/placeholders.ts +9 -1
- package/src/locales/vi/presets.ts +6 -0
- package/src/locales/vi/v2.ts +21 -0
- package/src/shared/panel-store.ts +3 -3
- package/src/shared/patterns.ts +3 -52
- package/src/shared/style-panel.tsx +2 -2
- package/src/shared/types.ts +2 -0
- package/src/v2/blocks/columns-inspector.tsx +210 -0
- package/src/v2/blocks/form.tsx +4 -4
- package/src/v2/blocks/index.ts +10 -4
- package/src/v2/blocks/inline-style.ts +1 -1
- package/src/v2/blocks/layout.tsx +173 -42
- package/src/v2/blocks/media.tsx +22 -13
- package/src/v2/blocks/resize.tsx +172 -4
- package/src/v2/blocks/text.tsx +14 -7
- package/src/v2/blocks/theme.tsx +10 -5
- package/src/v2/blocks/tools.tsx +50 -5
- package/src/v2/blocks/widgets.tsx +44 -16
- package/src/v2/canvas/block-list.tsx +17 -2
- package/src/v2/canvas/canvas-css.ts +54 -4
- package/src/v2/canvas/canvas.tsx +20 -3
- package/src/v2/canvas/dnd.ts +34 -3
- package/src/v2/canvas/move-animation.ts +94 -0
- package/src/v2/canvas/spacing-viz.ts +51 -0
- package/src/v2/core/block-presets.ts +68 -0
- package/src/v2/core/host.ts +5 -0
- package/src/v2/core/structure.ts +2 -1
- package/src/v2/editor.css +238 -9
- package/src/v2/editor.tsx +8 -2
- package/src/v2/ui/attr-form.tsx +40 -11
- package/src/v2/ui/attr-hints.ts +104 -6
- package/src/v2/ui/background-panel.tsx +65 -21
- package/src/v2/ui/block-icons.tsx +152 -0
- package/src/v2/ui/block-menu.ts +22 -0
- package/src/v2/ui/block-style-panel.tsx +14 -3
- package/src/v2/ui/color-field.tsx +74 -9
- package/src/v2/ui/divider-panel.tsx +58 -0
- package/src/v2/ui/group-width.tsx +38 -0
- package/src/v2/ui/icon-picker.tsx +51 -0
- package/src/v2/ui/inserter.tsx +51 -7
- package/src/v2/ui/inspector.tsx +48 -16
- package/src/v2/ui/layout-panel.tsx +5 -47
- package/src/v2/ui/list-view.tsx +81 -7
- package/src/v2/ui/motion-panel.tsx +2 -1
- package/src/v2/ui/parts-panel.tsx +164 -0
- package/src/v2/ui/pattern-library.tsx +228 -0
- package/src/v2/ui/preset-bar.tsx +83 -0
- package/src/v2/ui/style-controls.tsx +65 -15
- package/src/v2/ui/style-supports.ts +1 -1
- package/src/v2/ui/style-tab.tsx +127 -41
- package/src/v2/ui/toolbar.tsx +52 -13
- package/src/v2/ui/unit-controls.tsx +88 -39
- package/src/locales/en/patterns.ts +0 -50
- package/src/locales/vi/patterns.ts +0 -50
- package/src/shared/patterns-kit.ts +0 -7
- package/src/shared/patterns-library.ts +0 -172
package/src/v2/ui/toolbar.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WIDE_BLOCKS } from "@ecomcx/ecomweb-content";
|
|
2
2
|
import { clearCells, mergeRange, selectedCellRect } from "../core/tables";
|
|
3
3
|
import { AiTools } from "./ai";
|
|
4
|
-
import { Eraser, TableCellsMerge, StickyNote, Keyboard, MoveHorizontal, Maximize2, RectangleHorizontal, AlignCenter, AlignLeft, AlignRight, ArrowUpLeft, Bold, ChevronDown, ChevronUp, Code, Copy, CopyPlus, GripVertical, IndentDecrease, IndentIncrease, Italic, Link2, Link2Off, MoreVertical, PanelTop, Strikethrough, Trash2, Underline, Ungroup, Group as GroupIcon, Blocks, ArrowUpToLine, ArrowDownToLine, Shapes, Lock, Subscript, Superscript, Highlighter, Paintbrush, ClipboardPaste } from "lucide-react";
|
|
4
|
+
import { Eraser, TableCellsMerge, StickyNote, Keyboard, MoveHorizontal, Maximize2, RectangleHorizontal, AlignCenter, AlignLeft, AlignRight, ArrowUpLeft, Bold, ChevronDown, ChevronUp, Code, Copy, CopyPlus, GripVertical, IndentDecrease, IndentIncrease, Italic, Link2, Link2Off, MoreVertical, PanelTop, Strikethrough, Trash2, Underline, Ungroup, Group as GroupIcon, Blocks, ArrowUpToLine, ArrowDownToLine, Shapes, Lock, Subscript, Superscript, Highlighter, Paintbrush, ClipboardPaste, Scissors, PenLine, Eye, EyeOff } from "lucide-react";
|
|
5
5
|
import { TextSelection } from "prosemirror-state";
|
|
6
6
|
import type { EditorView } from "prosemirror-view";
|
|
7
7
|
import { useEffect, useLayoutEffect, useRef, useState, type ComponentType, type KeyboardEvent as ReactKeyboardEvent, type ReactNode } from "react";
|
|
@@ -19,7 +19,7 @@ import type { BlockTransform } from "../core/registry";
|
|
|
19
19
|
import { insertSibling, richViews } from "../text/rich-text";
|
|
20
20
|
import { canContain } from "../core/structure";
|
|
21
21
|
import { blockActionsFor } from "../../shared/panel-store";
|
|
22
|
-
import { copyStyle, hasCopiedStyle, menuPosition, pastedStyle } from "./block-menu";
|
|
22
|
+
import { copyStyle, hasCopiedStyle, isHidden, menuPosition, pastedStyle, toggleHidden } from "./block-menu";
|
|
23
23
|
|
|
24
24
|
const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
|
|
25
25
|
|
|
@@ -90,7 +90,7 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
|
|
|
90
90
|
const sel = useEditorState((s) => s.selection);
|
|
91
91
|
useEditorState((s) => s.revision);
|
|
92
92
|
const [link, setLink] = useState<string | null>(null);
|
|
93
|
-
const [
|
|
93
|
+
const [dialog, setDialog] = useState<"lock" | "rename" | null>(null);
|
|
94
94
|
useEffect(() => { ui.openLink = (key) => setLink(key); return () => { ui.openLink = null; }; }, [ui]);
|
|
95
95
|
|
|
96
96
|
const ids = sel.ids.length ? sel.ids : sel.editing ? [sel.editing] : [];
|
|
@@ -208,7 +208,7 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
|
|
|
208
208
|
<ToolButton label={labels.moveDown} onClick={() => store.moveBy(ordered, 1)}><ChevronDown className="ecx-icon ecx-icon-sm" /></ToolButton>
|
|
209
209
|
</div>
|
|
210
210
|
</>}
|
|
211
|
-
{isLocked && <ToolButton label={labels.locked} onClick={() =>
|
|
211
|
+
{isLocked && <ToolButton label={labels.locked} onClick={() => setDialog("lock")} className="ecx-lock-badge"><Lock className="ecx-icon" /></ToolButton>}
|
|
212
212
|
</div>
|
|
213
213
|
{sameType && type?.variations?.some((v) => v.attrs && v.isActive) && (
|
|
214
214
|
<div className="ecx-tool-group">
|
|
@@ -250,13 +250,25 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
|
|
|
250
250
|
{Extra && <div className="ecx-tool-group"><Extra {...editProps} /></div>}
|
|
251
251
|
{(nodes.length === 1 || cellSel) && contextTools(loc.ancestors, first.id)}
|
|
252
252
|
{nested && <div className="ecx-tool-group"><ToolButton label={labels.editOriginal} className="ecx-tool-wide" onClick={() => store.enterFocus(nested)}><PanelTop className="ecx-icon" /><span className="ecx-tool-text">{labels.editOriginal}</span></ToolButton></div>}
|
|
253
|
+
{/* Chép / dán kiểu dáng ngay trên thanh (như các bộ khối lớn) — vẫn còn trong menu ⋮ */}
|
|
254
|
+
{nodes.length === 1 && !type?.plain && (
|
|
255
|
+
<div className="ecx-tool-group">
|
|
256
|
+
<Dropdown label={labels.copyPasteStyle} trigger={<Paintbrush className="ecx-icon" />}>
|
|
257
|
+
{(close) => <>
|
|
258
|
+
<MenuItem icon={Paintbrush} label={labels.copyStyle} onClick={() => { close(); copyStyle(first.attrs); ui.announce(labels.styleCopied); }} />
|
|
259
|
+
{hasCopiedStyle() && ordered.every((id) => !store.isContentOnly(id) && store.modeOf(id) !== "disabled") && <MenuItem icon={ClipboardPaste} label={labels.pasteStyle} onClick={() => { close(); store.setAttrs(ordered, pastedStyle()!); }} />}
|
|
260
|
+
</>}
|
|
261
|
+
</Dropdown>
|
|
262
|
+
</div>
|
|
263
|
+
)}
|
|
253
264
|
<div className="ecx-tool-group">
|
|
254
265
|
<Dropdown label={labels.more} trigger={<MoreVertical className="ecx-icon" />}>
|
|
255
|
-
{(close) => <BlockMenuItems ids={ids} close={close}
|
|
266
|
+
{(close) => <BlockMenuItems ids={ids} close={close} onDialog={setDialog} />}
|
|
256
267
|
</Dropdown>
|
|
257
268
|
</div>
|
|
258
269
|
</div>
|
|
259
|
-
{
|
|
270
|
+
{dialog === "lock" && <LockDialog block={first} onClose={() => setDialog(null)} />}
|
|
271
|
+
{dialog === "rename" && <RenameDialog block={first} onClose={() => setDialog(null)} />}
|
|
260
272
|
{link && view && (() => {
|
|
261
273
|
const anchor = fixed ? document.querySelector(".ecx-toolbar.is-fixed")?.getBoundingClientRect() : null;
|
|
262
274
|
return <LinkPopover viewKey={link} top={anchor ? anchor.bottom + 4 : top + height + 4} left={anchor ? anchor.left : left} onClose={() => setLink(null)} />;
|
|
@@ -308,7 +320,7 @@ function MarkTools({ view, onLink }: { view: EditorView; onLink(): void }) {
|
|
|
308
320
|
}
|
|
309
321
|
|
|
310
322
|
/** Mục của menu ⋮ trên thanh công cụ khối — dùng chung với menu chuột phải (BlockContextMenu). */
|
|
311
|
-
function BlockMenuItems({ ids, close,
|
|
323
|
+
export function BlockMenuItems({ ids, close, onDialog }: { ids: string[]; close(): void; onDialog(kind: "lock" | "rename"): void }) {
|
|
312
324
|
const ctx = useEditor();
|
|
313
325
|
const { store, ui, labels } = ctx;
|
|
314
326
|
const nodes = ids.map((id) => store.block(id)).filter(Boolean) as BNode[];
|
|
@@ -322,11 +334,13 @@ function BlockMenuItems({ ids, close, onLock }: { ids: string[]; close(): void;
|
|
|
322
334
|
const insertable = store.canInsertInto(parent?.id ?? null);
|
|
323
335
|
const canGroup = canContain(parent?.type ?? null, "group");
|
|
324
336
|
const styleEditable = ordered.every((id) => !store.isContentOnly(id) && store.modeOf(id) !== "disabled");
|
|
337
|
+
const hidden = isHidden(first);
|
|
325
338
|
const copy = async () => {
|
|
326
339
|
const s = serializeBlocks(ordered.map((id) => store.block(id)!));
|
|
327
340
|
try {
|
|
328
341
|
await navigator.clipboard.write([new ClipboardItem({ "text/plain": new Blob([s.text], { type: "text/plain" }), "text/html": new Blob([s.html], { type: "text/html" }) })]);
|
|
329
|
-
|
|
342
|
+
return true;
|
|
343
|
+
} catch { return false; /* trình duyệt chặn ghi clipboard: người dùng vẫn chép được bằng Ctrl+C */ }
|
|
330
344
|
};
|
|
331
345
|
/** Tạo mẫu từ các khối đang chọn; mẫu đồng bộ → thay khối bằng tham chiếu tới mẫu. */
|
|
332
346
|
const createPattern = async () => {
|
|
@@ -346,7 +360,8 @@ function BlockMenuItems({ ids, close, onLock }: { ids: string[]; close(): void;
|
|
|
346
360
|
<MenuItem icon={ArrowUpToLine} label={labels.insertBefore} shortcut={`${mod}⌥T`} onClick={() => { close(); insertSibling(store, ordered[0], 0); }} />
|
|
347
361
|
<MenuItem icon={ArrowDownToLine} label={labels.insertAfter} shortcut={`${mod}⌥Y`} onClick={() => { close(); insertSibling(store, ordered[ordered.length - 1], 1); }} />
|
|
348
362
|
</>}
|
|
349
|
-
<MenuItem icon={Copy} label={labels.copy} onClick={() => { close(); void copy(); }} />
|
|
363
|
+
<MenuItem icon={Copy} label={labels.copy} shortcut={`${mod}C`} onClick={() => { close(); void copy(); }} />
|
|
364
|
+
{removable && <MenuItem icon={Scissors} label={labels.cut} shortcut={`${mod}X`} onClick={() => { close(); void copy().then((ok) => { if (ok) store.remove(ordered); }); /* chép không được thì không xoá */ }} />}
|
|
350
365
|
<MenuItem icon={Paintbrush} label={labels.copyStyle} onClick={() => { close(); copyStyle(first.attrs); ui.announce(labels.styleCopied); }} />
|
|
351
366
|
{hasCopiedStyle() && styleEditable && <MenuItem icon={ClipboardPaste} label={labels.pasteStyle} onClick={() => { close(); store.setAttrs(ordered, pastedStyle()!); }} />}
|
|
352
367
|
{ctx.host.createPattern && <MenuItem icon={Shapes} label={labels.createPattern} onClick={() => { close(); void createPattern(); }} />}
|
|
@@ -359,7 +374,9 @@ function BlockMenuItems({ ids, close, onLock }: { ids: string[]; close(): void;
|
|
|
359
374
|
))}
|
|
360
375
|
{canGroup && removable && movable && insertable && <MenuItem icon={GroupIcon} label={labels.group} onClick={() => { close(); store.wrap(ordered, "group"); }} />}
|
|
361
376
|
{nodes.length === 1 && first.content && first.type === "group" && removable && <MenuItem icon={Ungroup} label={labels.ungroup} onClick={() => { close(); store.unwrap(first.id); }} />}
|
|
362
|
-
{nodes.length === 1 && !store.isContentOnly(first.id) && <MenuItem icon={Lock} label={labels.lock} onClick={() => { close();
|
|
377
|
+
{nodes.length === 1 && !store.isContentOnly(first.id) && <MenuItem icon={Lock} label={labels.lock} onClick={() => { close(); onDialog("lock"); }} />}
|
|
378
|
+
{nodes.length === 1 && <MenuItem icon={PenLine} label={labels.rename} onClick={() => { close(); onDialog("rename"); }} />}
|
|
379
|
+
{styleEditable && <MenuItem icon={hidden ? Eye : EyeOff} label={hidden ? labels.show : labels.hide} onClick={() => { close(); toggleHidden(store, ordered); }} />}
|
|
363
380
|
{removable && <MenuItem icon={Trash2} label={labels.remove} shortcut="⇧⌥Z" danger onClick={() => { close(); store.remove(ordered); }} />}
|
|
364
381
|
</>
|
|
365
382
|
);
|
|
@@ -375,7 +392,7 @@ export function BlockContextMenu() {
|
|
|
375
392
|
const at = ui.contextMenu;
|
|
376
393
|
const ref = useRef<HTMLDivElement>(null);
|
|
377
394
|
const [pos, setPos] = useState<{ top: number; left: number } | null>(null);
|
|
378
|
-
const [
|
|
395
|
+
const [dlg, setDlg] = useState<{ kind: "lock" | "rename"; block: BNode } | null>(null);
|
|
379
396
|
// refocus: bàn phím quay về khối (Esc / Tab) hoặc khung soạn (chọn mục xong — khối có thể đã bị xoá / thay)
|
|
380
397
|
const close = (refocus?: "block" | "canvas") => {
|
|
381
398
|
const id = ui.contextMenu?.ids[0];
|
|
@@ -418,10 +435,11 @@ export function BlockContextMenu() {
|
|
|
418
435
|
else if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); close("block"); }
|
|
419
436
|
else if (e.key === "Tab") { e.preventDefault(); close("block"); }
|
|
420
437
|
}}>
|
|
421
|
-
<BlockMenuItems ids={at.ids} close={() => close("canvas")}
|
|
438
|
+
<BlockMenuItems ids={at.ids} close={() => close("canvas")} onDialog={(kind) => { const b = store.block(at.ids[0]); if (b) setDlg({ kind, block: b }); }} />
|
|
422
439
|
</div>
|
|
423
440
|
)}
|
|
424
|
-
{lock && <LockDialog block={
|
|
441
|
+
{dlg?.kind === "lock" && <LockDialog block={dlg.block} onClose={() => setDlg(null)} />}
|
|
442
|
+
{dlg?.kind === "rename" && <RenameDialog block={dlg.block} onClose={() => setDlg(null)} />}
|
|
425
443
|
</>
|
|
426
444
|
);
|
|
427
445
|
}
|
|
@@ -542,3 +560,24 @@ function LockDialog({ block, onClose }: { block: BNode; onClose(): void }) {
|
|
|
542
560
|
</div>
|
|
543
561
|
);
|
|
544
562
|
}
|
|
563
|
+
|
|
564
|
+
/** Đổi tên khối (chỉ trong trình soạn: cây khối, bảng cài đặt, đường dẫn khối). Để trống = tên mặc định. */
|
|
565
|
+
function RenameDialog({ block, onClose }: { block: BNode; onClose(): void }) {
|
|
566
|
+
const { store, labels, registry } = useEditor();
|
|
567
|
+
const [name, setName] = useState(typeof block.attrs.customName === "string" ? block.attrs.customName : "");
|
|
568
|
+
const save = () => { store.setAttrs([block.id], { customName: name.trim().slice(0, 80) || undefined }); onClose(); };
|
|
569
|
+
return (
|
|
570
|
+
<div className="ecx-modal-backdrop" onMouseDown={(e) => { if (e.target === e.currentTarget) onClose(); }} onKeyDown={(e) => { if (e.key === "Escape") onClose(); else trapTab(e); }}>
|
|
571
|
+
<div className="ecx-modal" role="dialog" aria-modal="true" aria-label={labels.renameTitle}>
|
|
572
|
+
<header className="ecx-modal-header"><h2>{labels.renameTitle}</h2></header>
|
|
573
|
+
<form className="ecx-lock-body" onSubmit={(e) => { e.preventDefault(); save(); }}>
|
|
574
|
+
<input className="ecx-input" value={name} maxLength={80} placeholder={registry.get(block.type)?.title ?? block.type} aria-label={labels.renameTitle} autoFocus onChange={(e) => setName(e.target.value)} />
|
|
575
|
+
<div className="ecx-popover-actions">
|
|
576
|
+
<button type="button" className="ecx-btn" onClick={onClose}>{labels.cancel}</button>
|
|
577
|
+
<button type="submit" className="ecx-btn ecx-btn-primary">{labels.save}</button>
|
|
578
|
+
</div>
|
|
579
|
+
</form>
|
|
580
|
+
</div>
|
|
581
|
+
</div>
|
|
582
|
+
);
|
|
583
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { normalizeStyle } from "@ecomcx/ecomweb-content";
|
|
2
|
-
import { Link2, Link2Off
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
2
|
+
import { Link2, Link2Off } from "lucide-react";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import { useEditor } from "../context";
|
|
5
|
-
import { cx } from "./style-controls";
|
|
5
|
+
import { Row, cx } from "./style-controls";
|
|
6
|
+
import type { Device } from "@ecomcx/ecomweb-content";
|
|
7
|
+
import { hideSpacingViz, showSpacingViz, type Side, type SpacingKind } from "../canvas/spacing-viz";
|
|
6
8
|
import { useMsgs } from "../i18n";
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -45,41 +47,72 @@ export function UnitInput({ value, onChange, label, max = 100, units = UNITS, sl
|
|
|
45
47
|
);
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Một giá trị cho cả 4 (cạnh viền / góc bo), hoặc tách từng cái: xích bật = một ô, tắt = 4 ô nhỏ.
|
|
52
|
+
* Giá trị: chuỗi (cả 4) hoặc `{ [khoá]: chuỗi }`; 4 ô bằng nhau thì gộp lại thành chuỗi.
|
|
53
|
+
*/
|
|
54
|
+
export function FourInput({ label, value, keys, keyLabels, units, max, onChange, onReset, corners }: {
|
|
55
|
+
/** Góc bo (nhãn "từng góc") thay cho cạnh. */
|
|
56
|
+
corners?: boolean; label: string; value?: string | Partial<Record<string, string>>; keys: readonly string[]; keyLabels: Record<string, string>;
|
|
57
|
+
units?: string[]; max?: number; onChange(v: string | Record<string, string> | undefined): void; onReset?(): void;
|
|
58
|
+
}) {
|
|
50
59
|
const t = useMsgs("controls");
|
|
51
|
-
const
|
|
52
|
-
const [
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
const [linked, setLinked] = useState(typeof value !== "object" || !value);
|
|
61
|
+
const each = (typeof value === "object" && value ? value : value ? Object.fromEntries(keys.map((k) => [k, value])) : {}) as Record<string, string>;
|
|
62
|
+
const setOne = (k: string, v: string | undefined) => {
|
|
63
|
+
const next = { ...each }; if (v === undefined) delete next[k]; else next[k] = v;
|
|
64
|
+
const vals = keys.map((x) => next[x]);
|
|
65
|
+
onChange(!Object.keys(next).length ? undefined : vals.every((x) => x !== undefined && x === vals[0]) ? vals[0] : next);
|
|
66
|
+
};
|
|
55
67
|
return (
|
|
56
|
-
<
|
|
57
|
-
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
)}
|
|
67
|
-
<button type="button" className={cx("ecx-tool", custom && "is-active")} aria-pressed={custom} title={custom ? (t.usePresets) : (t.customValue)} aria-label={`${label}: ${custom ? (t.usePresets2) : (t.customValue2)}`}
|
|
68
|
-
onClick={() => { setCustom(!custom); if (custom && !isPreset) onChange(undefined); }}><SlidersHorizontal className="ecx-icon ecx-icon-sm" /></button>
|
|
69
|
-
</div>
|
|
68
|
+
<Row label={label} onReset={onReset}
|
|
69
|
+
extra={<button type="button" className={cx("ecx-link-toggle", linked && "is-on")} aria-pressed={!linked} title={linked ? (corners ? t.unlinkCorners : t.unlinkSides) : (corners ? t.linkCorners : t.linkSides)} aria-label={`${label}: ${corners ? t.unlinkCorners : t.unlinkSides}`}
|
|
70
|
+
onClick={() => { if (!linked && typeof value === "object") onChange(each[keys[0]]); setLinked(!linked); }}>{linked ? <Link2 className="ecx-icon" /> : <Link2Off className="ecx-icon" />}</button>}>
|
|
71
|
+
{linked
|
|
72
|
+
? <UnitInput label={label} value={typeof value === "string" ? value : undefined} placeholder={typeof value === "object" ? "—" : undefined} units={units} max={max} onChange={onChange} />
|
|
73
|
+
: <div className="ecx-four">{keys.map((k) => (
|
|
74
|
+
<label key={k} className="ecx-four-cell"><small>{keyLabels[k]}</small>
|
|
75
|
+
<UnitInput label={`${label} ${keyLabels[k]}`} value={each[k]} units={units} max={max} slider={false} onChange={(v) => setOne(k, v)} /></label>
|
|
76
|
+
))}</div>}
|
|
77
|
+
</Row>
|
|
70
78
|
);
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
type Box = string | Record<string, string> | undefined;
|
|
74
82
|
const sidesOf = (v: Box): Record<string, string> => (typeof v === "object" && v ? v : v ? { top: v, right: v, bottom: v, left: v } : {});
|
|
83
|
+
const SIDES: Side[] = ["top", "right", "bottom", "left"];
|
|
75
84
|
|
|
76
|
-
/**
|
|
77
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Đệm / lề bốn cạnh: 4 ô Trên · Phải · Dưới · Trái (vạch đậm ở đúng cạnh, hiện tên bậc hoặc số), xích = 4 cạnh như nhau.
|
|
87
|
+
* Rê chuột lên ô → khối đang chọn được tô vùng đệm (bên trong) / lề (bên ngoài) trên khung soạn. Bấm ô → bảng chọn bậc + giá trị tuỳ chỉnh.
|
|
88
|
+
*/
|
|
89
|
+
export function SpacingControl({ label, value, onChange, steps, inherited, labels, kind = "padding", device, onReset, vizTarget }: {
|
|
78
90
|
label: string; value: Box; onChange(v: Box): void; steps: string[]; inherited?: string; labels: { vertical: string; horizontal: string; link: string; unlink: string; top: string; right: string; bottom: string; left: string };
|
|
91
|
+
kind?: SpacingKind; device?: Device; onReset?(): void;
|
|
92
|
+
/** Phần tử được tô (mặc định: khối đang chọn) — vd một phần của khối. */
|
|
93
|
+
vizTarget?(): HTMLElement | null;
|
|
79
94
|
}) {
|
|
95
|
+
const { store, ui } = useEditor();
|
|
96
|
+
const t = useMsgs("controls");
|
|
80
97
|
const sides = sidesOf(value);
|
|
81
98
|
const [linked, setLinked] = useState(typeof value !== "object" || value === null || (sides.top === sides.bottom && sides.left === sides.right && sides.top === sides.left));
|
|
99
|
+
const [open, setOpen] = useState<Side | null>(null);
|
|
100
|
+
const hover = useRef<Side | null>(null);
|
|
101
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
82
102
|
const ok = (v: string) => !!normalizeStyle({ padding: v });
|
|
103
|
+
const blockEl = () => { if (vizTarget) return vizTarget(); const s = store.getState().selection; const id = s.ids[0] ?? s.editing; return id ? ui.blockEl(id) : null; };
|
|
104
|
+
const names = () => Object.fromEntries(SIDES.map((s) => [s, sides[s] && steps.includes(sides[s]) ? sides[s].toUpperCase() : undefined])) as Partial<Record<Side, string>>;
|
|
105
|
+
const viz = (side: Side | null) => { if (!side) { hideSpacingViz(ui.canvasDoc); return; } showSpacingViz(blockEl(), kind, linked ? SIDES : [side], names()); };
|
|
106
|
+
// Giá trị đổi khi đang rê / đang mở bảng chọn: vẽ lại lớp tô sau khi khối nhận CSS mới
|
|
107
|
+
useEffect(() => { const s = open ?? hover.current; if (!s) return; const r = requestAnimationFrame(() => viz(s)); return () => cancelAnimationFrame(r); });
|
|
108
|
+
useEffect(() => () => hideSpacingViz(ui.canvasDoc), [ui]);
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
if (!open) return;
|
|
111
|
+
const out = (e: MouseEvent) => { if (!ref.current?.contains(e.target as Node)) { setOpen(null); viz(hover.current); } };
|
|
112
|
+
const esc = (e: KeyboardEvent) => { if (e.key === "Escape") { e.stopPropagation(); setOpen(null); viz(null); } };
|
|
113
|
+
document.addEventListener("mousedown", out, true); document.addEventListener("keydown", esc, true);
|
|
114
|
+
return () => { document.removeEventListener("mousedown", out, true); document.removeEventListener("keydown", esc, true); };
|
|
115
|
+
});
|
|
83
116
|
const set = (keys: string[], v: string | undefined) => {
|
|
84
117
|
if (v !== undefined && !ok(v)) return;
|
|
85
118
|
const next = { ...sides };
|
|
@@ -87,22 +120,38 @@ export function SpacingControl({ label, value, onChange, steps, inherited, label
|
|
|
87
120
|
const vals = Object.values(next);
|
|
88
121
|
onChange(!vals.length ? undefined : vals.length === 4 && vals.every((x) => x === vals[0]) ? vals[0] : next);
|
|
89
122
|
};
|
|
123
|
+
const target = (side: Side) => (linked ? SIDES : [side]);
|
|
124
|
+
const shown = (v?: string) => (v === undefined ? "–" : steps.includes(v) ? (v === "0" ? "0" : v.toUpperCase()) : v);
|
|
125
|
+
const cur = open ? sides[open] : undefined;
|
|
90
126
|
return (
|
|
91
|
-
<div className="ecx-
|
|
92
|
-
<
|
|
93
|
-
<
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
127
|
+
<div className="ecx-box4" ref={ref} onMouseLeave={() => { hover.current = null; if (!open) viz(null); }}>
|
|
128
|
+
<Row label={<>{label}{inherited && <em className="ecx-inherit">{inherited}</em>}</>} device={device} onReset={onReset}
|
|
129
|
+
extra={<button type="button" className={cx("ecx-link-toggle", linked && "is-on")} aria-pressed={linked} title={linked ? labels.unlink : labels.link} aria-label={`${label}: ${linked ? labels.unlink : labels.link}`}
|
|
130
|
+
onClick={() => setLinked(!linked)}>{linked ? <Link2 className="ecx-icon" /> : <Link2Off className="ecx-icon" />}</button>}>
|
|
131
|
+
<div className="ecx-box4-grid">
|
|
132
|
+
{SIDES.map((side) => (
|
|
133
|
+
<button key={side} type="button" className={cx("ecx-box4-cell", `is-${side}`, sides[side] !== undefined && "is-set", open && target(open).includes(side) && "is-open")}
|
|
134
|
+
aria-label={`${label} ${labels[side]}: ${shown(sides[side])}`} aria-haspopup="dialog" aria-expanded={open === side}
|
|
135
|
+
onMouseEnter={() => { hover.current = side; viz(side); }} onFocus={() => viz(side)} onBlur={() => { if (!open) viz(null); }}
|
|
136
|
+
onClick={() => setOpen(open === side ? null : side)}>
|
|
137
|
+
<small>{labels[side]}</small><b>{shown(sides[side])}</b>
|
|
138
|
+
</button>
|
|
139
|
+
))}
|
|
140
|
+
</div>
|
|
141
|
+
</Row>
|
|
142
|
+
{open && (
|
|
143
|
+
// key: đổi cạnh thì ô số mới, không giữ số đã gõ của cạnh trước
|
|
144
|
+
<div key={open} className="ecx-box4-pop" role="dialog" aria-label={`${label} ${linked ? "" : labels[open]}`}>
|
|
145
|
+
<div className="ecx-pop-title">{label}{linked ? "" : ` · ${labels[open]}`}</div>
|
|
146
|
+
<div className="ecx-box4-steps" role="radiogroup" aria-label={label}>
|
|
147
|
+
{steps.map((st) => (
|
|
148
|
+
<button key={st} type="button" role="radio" aria-checked={cur === st} className={cx("ecx-chip", cur === st && "is-active")} onClick={() => set(target(open), st)}>{st === "0" ? "0" : st.toUpperCase()}</button>
|
|
104
149
|
))}
|
|
105
|
-
|
|
150
|
+
</div>
|
|
151
|
+
<UnitInput label={`${label}: ${t.customValue}`} value={cur && !steps.includes(cur) ? cur : undefined} max={160} onChange={(v) => set(target(open), v)} />
|
|
152
|
+
<div className="ecx-pop-foot"><button type="button" className="ecx-link-btn" onClick={() => set(target(open), undefined)}>{t.reset}</button><button type="button" className="ecx-link-btn" onClick={() => { setOpen(null); viz(null); }}>OK</button></div>
|
|
153
|
+
</div>
|
|
154
|
+
)}
|
|
106
155
|
</div>
|
|
107
156
|
);
|
|
108
157
|
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/** Text of the 8 basic patterns (names, descriptions, placeholder content). */
|
|
2
|
-
export const patterns = {
|
|
3
|
-
hero: "Hero cover",
|
|
4
|
-
heroD: "Big heading over a background image + 2 buttons",
|
|
5
|
-
heroTitle: "A headline that stands out",
|
|
6
|
-
heroText: "One short sentence about what you offer your customers.",
|
|
7
|
-
start: "Get started",
|
|
8
|
-
learn: "Learn more",
|
|
9
|
-
features: "Three features",
|
|
10
|
-
featuresD: "Heading + 3 feature columns",
|
|
11
|
-
featuresTitle: "Why choose us",
|
|
12
|
-
f1: "Fast",
|
|
13
|
-
f2: "Secure",
|
|
14
|
-
f3: "Easy",
|
|
15
|
-
fText: "A short description of this benefit.",
|
|
16
|
-
cta: "Call to action",
|
|
17
|
-
ctaD: "Highlighted box with a button",
|
|
18
|
-
ctaTitle: "Ready to start?",
|
|
19
|
-
ctaText: "Sign up today for a special offer.",
|
|
20
|
-
ctaBtn: "Contact us",
|
|
21
|
-
pricing: "Pricing — 3 plans",
|
|
22
|
-
pricingD: "3 plan cards with a feature list",
|
|
23
|
-
basic: "Basic",
|
|
24
|
-
pro: "Pro",
|
|
25
|
-
biz: "Business",
|
|
26
|
-
perMonth: "/month",
|
|
27
|
-
choose: "Choose plan",
|
|
28
|
-
item: "Feature",
|
|
29
|
-
faq: "FAQ",
|
|
30
|
-
faqD: "Heading + collapsible questions",
|
|
31
|
-
q: "Question",
|
|
32
|
-
a: "A short answer.",
|
|
33
|
-
testimonial: "Testimonial",
|
|
34
|
-
testimonialD: "Pullquote with a name",
|
|
35
|
-
quote: "Great service, I will recommend it to my friends.",
|
|
36
|
-
who: "Jane Doe, CEO",
|
|
37
|
-
intro: "Media + intro",
|
|
38
|
-
introD: "Image on one side, text and button on the other",
|
|
39
|
-
introTitle: "About us",
|
|
40
|
-
introText: "A short introduction to the company, its mission and values.",
|
|
41
|
-
contact: "Contact",
|
|
42
|
-
contactD: "Heading, short intro and a contact form",
|
|
43
|
-
contactTitle: "Get in touch",
|
|
44
|
-
contactText: "Address · Phone · Email",
|
|
45
|
-
send: "Send",
|
|
46
|
-
thanks: "Thank you! We will get back to you soon.",
|
|
47
|
-
name: "Full name",
|
|
48
|
-
email: "Email",
|
|
49
|
-
message: "Message",
|
|
50
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/** Chữ của 8 mẫu cơ bản (tên, mô tả, nội dung giữ chỗ). */
|
|
2
|
-
export const patterns = {
|
|
3
|
-
hero: "Ảnh bìa giới thiệu",
|
|
4
|
-
heroD: "Tiêu đề lớn trên ảnh nền + 2 nút",
|
|
5
|
-
heroTitle: "Tiêu đề thật ấn tượng",
|
|
6
|
-
heroText: "Một câu ngắn nói rõ bạn mang lại điều gì cho khách hàng.",
|
|
7
|
-
start: "Bắt đầu ngay",
|
|
8
|
-
learn: "Tìm hiểu thêm",
|
|
9
|
-
features: "Ba tính năng",
|
|
10
|
-
featuresD: "Tiêu đề + 3 cột tính năng",
|
|
11
|
-
featuresTitle: "Vì sao chọn chúng tôi",
|
|
12
|
-
f1: "Nhanh",
|
|
13
|
-
f2: "An toàn",
|
|
14
|
-
f3: "Dễ dùng",
|
|
15
|
-
fText: "Mô tả ngắn về lợi ích này.",
|
|
16
|
-
cta: "Kêu gọi hành động",
|
|
17
|
-
ctaD: "Khung nổi bật với nút",
|
|
18
|
-
ctaTitle: "Sẵn sàng bắt đầu?",
|
|
19
|
-
ctaText: "Đăng ký hôm nay để nhận ưu đãi.",
|
|
20
|
-
ctaBtn: "Liên hệ ngay",
|
|
21
|
-
pricing: "Bảng giá 3 gói",
|
|
22
|
-
pricingD: "3 gói dạng thẻ, có danh sách quyền lợi",
|
|
23
|
-
basic: "Cơ bản",
|
|
24
|
-
pro: "Chuyên nghiệp",
|
|
25
|
-
biz: "Doanh nghiệp",
|
|
26
|
-
perMonth: "/tháng",
|
|
27
|
-
choose: "Chọn gói",
|
|
28
|
-
item: "Quyền lợi",
|
|
29
|
-
faq: "Câu hỏi thường gặp",
|
|
30
|
-
faqD: "Tiêu đề + các câu hỏi thu gọn",
|
|
31
|
-
q: "Câu hỏi",
|
|
32
|
-
a: "Câu trả lời ngắn gọn.",
|
|
33
|
-
testimonial: "Cảm nhận khách hàng",
|
|
34
|
-
testimonialD: "Trích dẫn nổi bật kèm tên",
|
|
35
|
-
quote: "Dịch vụ tuyệt vời, tôi sẽ giới thiệu cho bạn bè.",
|
|
36
|
-
who: "Nguyễn Văn A, Giám đốc",
|
|
37
|
-
intro: "Ảnh + giới thiệu",
|
|
38
|
-
introD: "Ảnh một bên, chữ và nút bên kia",
|
|
39
|
-
introTitle: "Về chúng tôi",
|
|
40
|
-
introText: "Giới thiệu ngắn về công ty, sứ mệnh và giá trị.",
|
|
41
|
-
contact: "Liên hệ",
|
|
42
|
-
contactD: "Tiêu đề, giới thiệu ngắn và form liên hệ",
|
|
43
|
-
contactTitle: "Liên hệ với chúng tôi",
|
|
44
|
-
contactText: "Địa chỉ · Số điện thoại · Email",
|
|
45
|
-
send: "Gửi",
|
|
46
|
-
thanks: "Cảm ơn bạn! Chúng tôi sẽ liên hệ lại sớm.",
|
|
47
|
-
name: "Họ và tên",
|
|
48
|
-
email: "Email",
|
|
49
|
-
message: "Nội dung",
|
|
50
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/** Hàm dựng khối dùng chung cho mẫu của lõi (patterns.ts, patterns-library.ts). */
|
|
2
|
-
export const text = (s: string, marks?: Array<{ type: string }>) => (marks ? { type: "text", text: s, marks } : { type: "text", text: s });
|
|
3
|
-
export const p = (s: string, attrs?: Record<string, unknown>) => ({ type: "paragraph", ...(attrs ? { attrs } : {}), content: [text(s)] });
|
|
4
|
-
export const h = (level: number, s: string, attrs: Record<string, unknown> = {}) => ({ type: "heading", attrs: { level, ...attrs }, content: [text(s)] });
|
|
5
|
-
export const btn = (s: string, variant = "primary") => ({ type: "button", attrs: { text: s, href: "#", variant } });
|
|
6
|
-
export const buttons = (align: string, ...list: object[]) => ({ type: "buttons", attrs: { align }, content: list });
|
|
7
|
-
|