@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/style-tab.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeStyle, type BlockStyle, type Device } from "@ecomcx/ecomweb-content";
|
|
1
|
+
import { normalizeStyle, scopeCustomCss, CUSTOM_CSS_MAX, type BlockStyle, type Device } from "@ecomcx/ecomweb-content";
|
|
2
2
|
import { AlignCenter, AlignJustify, AlignLeft, AlignRight } from "lucide-react";
|
|
3
3
|
import { useEffect, useState, type ReactNode } from "react";
|
|
4
4
|
import { labelsLegacy, type EditorLabels } from "../../shared/labels";
|
|
@@ -6,6 +6,7 @@ import { useEditor } from "../context";
|
|
|
6
6
|
import { ColorInput } from "./color-field";
|
|
7
7
|
import { GradientField } from "./layout-panel";
|
|
8
8
|
import { MotionPanel } from "./motion-panel";
|
|
9
|
+
import { PlaceTransformPanels } from "./transform-panel";
|
|
9
10
|
import { Row, Section, Seg, StateTabs, cx } from "./style-controls";
|
|
10
11
|
import { styleGroups, type StyleGroup } from "./style-supports";
|
|
11
12
|
import { FourInput, SpacingControl, UnitInput } from "./unit-controls";
|
|
@@ -31,6 +32,21 @@ const STEP_ORDER = ["0", "none", "3xs", "2xs", "xxs", "xs", "sm", "md", "base",
|
|
|
31
32
|
export const byStep = (keys: string[]) => [...keys].sort((a, b) => { const i = STEP_ORDER.indexOf(a), j = STEP_ORDER.indexOf(b); return (i < 0 ? 99 : i) - (j < 0 ? 99 : j); });
|
|
32
33
|
|
|
33
34
|
/** Ô giá trị (preset như `lg` hoặc `16px`, `1.5rem`…): lưu khi rời ô / Enter; sai thì viền đỏ, không lưu. */
|
|
35
|
+
/** CSS riêng của khối: ô soạn có nháp riêng (chỉ ghi vào khối khi rời ô — không chen từng phím vào lịch sử hoàn tác), báo ngay phần bị lọc bỏ. */
|
|
36
|
+
function CustomCssField({ value, onCommit, lt }: { value: string; onCommit(v: string | undefined): void; lt: Record<string, string> }) {
|
|
37
|
+
const [draft, setDraft] = useState(value);
|
|
38
|
+
useEffect(() => setDraft(value), [value]);
|
|
39
|
+
const report = scopeCustomCss(draft, ".x");
|
|
40
|
+
return (
|
|
41
|
+
<>
|
|
42
|
+
<textarea className="ecx-input ecx-css-input" rows={6} spellCheck={false} aria-label={lt.customCss} placeholder={lt.customCssExample} maxLength={CUSTOM_CSS_MAX} value={draft}
|
|
43
|
+
onChange={(e) => setDraft(e.target.value)} onBlur={() => { if (draft !== value) onCommit(draft.trim() ? draft : undefined); }} />
|
|
44
|
+
<p className="ecx-field-help">{lt.customCssHelp}</p>
|
|
45
|
+
{report.dropped.length > 0 && <ul className="ecx-field-warn" role="alert">{report.dropped.map((d) => <li key={d}>{lt.customCssDropped}: {d}</li>)}</ul>}
|
|
46
|
+
</>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
34
50
|
function ValueInput({ value, onCommit, check, placeholder, label, inherited }: { value?: string | number; onCommit(v: string | null): void; check(v: string): boolean; placeholder?: string; label: string; inherited?: string }) {
|
|
35
51
|
const [text, setText] = useState(value == null ? "" : String(value));
|
|
36
52
|
const [bad, setBad] = useState(false);
|
|
@@ -135,6 +151,8 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
135
151
|
const container = registry.get(type)?.kind === "container";
|
|
136
152
|
// Trạng thái rê chuột nằm ngay trong mục Màu / Viền (công tắc Thường · Rê chuột), không còn mục "Khi rê chuột" riêng
|
|
137
153
|
const hoverOk = groups.has("hover") || style.hover !== undefined;
|
|
154
|
+
const { store: hvStore, ui: hvUi } = useEditor();
|
|
155
|
+
const hvId = hvStore.currentIds[hvStore.currentIds.length - 1] ?? null;
|
|
138
156
|
const fxOk = groups.has("effects") || ["gradient", "shadow", "aspectRatio", "position"].some((k) => style[k] !== undefined);
|
|
139
157
|
const setHover = (patch: NonNullable<BlockStyle["hover"]>) => set("hover", { ...style.hover, ...patch });
|
|
140
158
|
const shadows = ["sm", "md", "lg", "xl", ...Object.keys(presets?.shadows ?? {}).filter((x) => !["sm", "md", "lg", "xl"].includes(x))];
|
|
@@ -146,24 +164,9 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
146
164
|
);
|
|
147
165
|
const appearance = `${style.fontWeight ?? ""}${style.fontStyle === "italic" ? "i" : ""}`;
|
|
148
166
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
{part !== "advanced" && variants && variants.length > 0 && (
|
|
153
|
-
<div className="ecx-style-row">
|
|
154
|
-
<span className="ecx-field-label">{t.blockVariant}</span>
|
|
155
|
-
<div role="radiogroup" aria-label={t.blockVariant} className="ecx-seg is-text">
|
|
156
|
-
{[{ name: "", label: t.variant_default }, ...variants].map((v) => (
|
|
157
|
-
<button key={v.name || "default"} type="button" role="radio" aria-checked={(variant ?? "") === v.name} className={cx("ecx-seg-btn", (variant ?? "") === v.name && "is-active")}
|
|
158
|
-
onClick={() => onVariantChange?.(v.name || null)}>{v.label}</button>
|
|
159
|
-
))}
|
|
160
|
-
</div>
|
|
161
|
-
</div>
|
|
162
|
-
)}
|
|
163
|
-
|
|
164
|
-
{parts && lead}
|
|
165
|
-
|
|
166
|
-
{show("typography", TYPO) && <Section title={t.style_typography} modified={has(TYPO)} onReset={() => reset(TYPO)} moreOpen={has(["fontFamily", "letterSpacing", "textDecoration", "textTransform", "textShadow", "writingMode"])}
|
|
167
|
+
// Khối chứa (Section, Hàng, Cột, Nhóm…): Màu / Nền / Viền lên trước, Kiểu chữ xuống sau — việc người dùng cần trước hết; khối chữ thì ngược lại
|
|
168
|
+
const typographySection = (
|
|
169
|
+
show("typography", TYPO) && <Section title={t.style_typography} modified={has(TYPO)} onReset={() => reset(TYPO)} moreOpen={has(["fontFamily", "letterSpacing", "textDecoration", "textTransform", "textShadow", "writingMode"])}
|
|
167
170
|
more={<>
|
|
168
171
|
{row("fontFamily", t.style_fontFamily,
|
|
169
172
|
<select className="ecx-input" value={style.fontFamily ?? ""} aria-label={t.style_fontFamily} onChange={(e) => set("fontFamily", e.target.value || undefined)}>
|
|
@@ -195,7 +198,32 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
195
198
|
{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))} />)}
|
|
196
199
|
{row("textAlign", t.textAlign, <Seg label={t.textAlign} value={get("textAlign")} onChange={(v) => set("textAlign", v)}
|
|
197
200
|
options={[["left", AlignLeft, t.alignLeft], ["center", AlignCenter, t.alignCenter], ["right", AlignRight, t.alignRight], ["justify", AlignJustify, t.alignJustify]]} />)}
|
|
198
|
-
</Section>
|
|
201
|
+
</Section>
|
|
202
|
+
);
|
|
203
|
+
return (
|
|
204
|
+
<div className="ecx-style-tab">
|
|
205
|
+
{part !== "advanced" && hvId && (
|
|
206
|
+
<label className="ecx-check-row ecx-hover-preview-toggle">
|
|
207
|
+
<input type="checkbox" role="switch" className="ecx-switch" checked={hvUi.previewHoverId === hvId} onChange={(e) => hvUi.setPreviewHover(e.target.checked ? hvId : null)} />
|
|
208
|
+
<span>{lt.hoverPreview}</span>
|
|
209
|
+
</label>
|
|
210
|
+
)}
|
|
211
|
+
|
|
212
|
+
{part !== "advanced" && variants && variants.length > 0 && (
|
|
213
|
+
<div className="ecx-style-row">
|
|
214
|
+
<span className="ecx-field-label">{t.blockVariant}</span>
|
|
215
|
+
<div role="radiogroup" aria-label={t.blockVariant} className="ecx-seg is-text">
|
|
216
|
+
{[{ name: "", label: t.variant_default }, ...variants].map((v) => (
|
|
217
|
+
<button key={v.name || "default"} type="button" role="radio" aria-checked={(variant ?? "") === v.name} className={cx("ecx-seg-btn", (variant ?? "") === v.name && "is-active")}
|
|
218
|
+
onClick={() => onVariantChange?.(v.name || null)}>{v.label}</button>
|
|
219
|
+
))}
|
|
220
|
+
</div>
|
|
221
|
+
</div>
|
|
222
|
+
)}
|
|
223
|
+
|
|
224
|
+
{parts && lead}
|
|
225
|
+
|
|
226
|
+
{!container && typographySection}
|
|
199
227
|
|
|
200
228
|
{show("color", ["color", "textGradient", "link"]) && <Section title={t.style_color} modified={has(["color", "textGradient", "link"]) || !!style.hover?.color} onReset={() => commit({ ...style, color: undefined, textGradient: undefined, link: undefined, hover: style.hover && { ...style.hover, color: undefined } })}>
|
|
201
229
|
{hoverOk && <StateTabs value={colorState} onChange={setColorState} />}
|
|
@@ -258,10 +286,45 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
|
|
|
258
286
|
</>}
|
|
259
287
|
</Section>}
|
|
260
288
|
|
|
289
|
+
{container && typographySection}
|
|
290
|
+
|
|
291
|
+
{part === "advanced" && <PlaceTransformPanels style={style} device={device} commit={commit} />}
|
|
292
|
+
|
|
293
|
+
{part === "advanced" && <Section title={lt.backdrop} modified={!!style.backdropBlur} defaultOpen={!!style.backdropBlur} onReset={() => set("backdropBlur", undefined)}>
|
|
294
|
+
<label className="ecx-textshadow-row"><span>{lt.backdropBlur}: {style.backdropBlur ?? "0px"}</span>
|
|
295
|
+
<input type="range" className="ecx-range" min={0} max={40} step={1} aria-label={lt.backdropBlur} value={parseInt(style.backdropBlur ?? "0", 10) || 0}
|
|
296
|
+
onChange={(e) => set("backdropBlur", Number(e.target.value) > 0 ? `${e.target.value}px` : undefined)} /></label>
|
|
297
|
+
<p className="ecx-field-help">{lt.backdropHelp}</p>
|
|
298
|
+
</Section>}
|
|
299
|
+
|
|
261
300
|
{part === "advanced" && fxOk && <Section title={lt.sticky} modified={!!style.position} defaultOpen={!!style.position}>
|
|
262
301
|
<label className="ecx-check"><input type="checkbox" checked={!!style.position} onChange={(e) => set("position", e.target.checked ? { type: "sticky" } : undefined)} /> {lt.sticky}</label>
|
|
263
302
|
</Section>}
|
|
264
303
|
|
|
304
|
+
{part === "advanced" && <Section title={lt.audience} modified={!!style.audience} defaultOpen={!!style.audience} onReset={() => set("audience", undefined)}>
|
|
305
|
+
<div className="ecx-seg" role="radiogroup" aria-label={lt.audience}>
|
|
306
|
+
{([["", lt.audienceAll], ["guest", lt.audienceGuest], ["user", lt.audienceUser]] as const).map(([k, label]) => (
|
|
307
|
+
<label key={k} className="ecx-check"><input type="radio" name="ecx-audience" checked={(style.audience ?? "") === k} onChange={() => set("audience", k ? (k as "guest" | "user") : undefined)} /> {label}</label>))}
|
|
308
|
+
</div>
|
|
309
|
+
<p className="ecx-field-help">{lt.audienceHelp}</p>
|
|
310
|
+
</Section>}
|
|
311
|
+
|
|
312
|
+
{part === "advanced" && <Section title={lt.schedule} modified={!!style.schedule} defaultOpen={!!style.schedule} onReset={() => set("schedule", undefined)}>
|
|
313
|
+
{(["from", "until"] as const).map((k) => {
|
|
314
|
+
const iso = style.schedule?.[k];
|
|
315
|
+
const d = iso ? new Date(iso) : null;
|
|
316
|
+
const local = d && Number.isFinite(d.getTime()) ? `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}T${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}` : "";
|
|
317
|
+
return row(`schedule-${k}`, k === "from" ? lt.scheduleFrom : lt.scheduleUntil,
|
|
318
|
+
<input className="ecx-input" type="datetime-local" aria-label={k === "from" ? lt.scheduleFrom : lt.scheduleUntil} value={local}
|
|
319
|
+
onChange={(e) => { const next = { ...(style.schedule ?? {}) }; if (e.target.value) next[k] = new Date(e.target.value).toISOString(); else delete next[k]; set("schedule", Object.keys(next).length ? next : undefined); }} />);
|
|
320
|
+
})}
|
|
321
|
+
<p className="ecx-field-help">{lt.scheduleHelp}</p>
|
|
322
|
+
</Section>}
|
|
323
|
+
|
|
324
|
+
{part === "advanced" && <Section title={lt.customCss} modified={!!style.customCss} defaultOpen={!!style.customCss}>
|
|
325
|
+
<CustomCssField value={style.customCss ?? ""} onCommit={(v) => set("customCss", v)} lt={lt as Record<string, string>} />
|
|
326
|
+
</Section>}
|
|
327
|
+
|
|
265
328
|
{show("motion", ["motion"]) && <MotionPanel type={type} style={raw} onChange={onChange} />}
|
|
266
329
|
|
|
267
330
|
{show("visibility", ["hide"]) && <Section title={t.style_visibility} modified={has(["hide"])} onReset={() => reset(["hide"])} defaultOpen={has(["hide"])}>
|
package/src/v2/ui/toolbar.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { WIDE_BLOCKS } from "@ecomcx/ecomweb-content";
|
|
2
|
-
import { clearCells, mergeRange, selectedCellRect } from "../core/tables";
|
|
1
|
+
import { WIDE_BLOCKS, CONTENT_VERSION } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { addColumn, addRow, canMerge, canSplit, clearCells, deleteColumn, deleteRow, hasHeaderRow, mergeCells, mergeRange, selectedCellRect, splitCell, tableContext, toggleHeaderRow } 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, Scissors, PenLine, Eye, EyeOff } 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, ArrowLeftToLine, ArrowRightToLine, TableCellsSplit, Heading } 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";
|
|
@@ -9,7 +9,7 @@ import { createPortal } from "react-dom";
|
|
|
9
9
|
import { serializeBlocks } from "../core/clipboard";
|
|
10
10
|
|
|
11
11
|
/** Khối → nội dung lưu (ContentDoc). */
|
|
12
|
-
const contentFromBlocks = (blocks: BNode[]) => ({ version:
|
|
12
|
+
const contentFromBlocks = (blocks: BNode[]) => ({ version: CONTENT_VERSION, blocks: [{ type: "richtext", data: docFromBlocks(blocks) }] });
|
|
13
13
|
import { useEditor, useEditorState, useUiTick } from "../context";
|
|
14
14
|
import { usePrefs } from "../prefs";
|
|
15
15
|
import { startDrag } from "../canvas/dnd";
|
|
@@ -126,7 +126,7 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
|
|
|
126
126
|
const view = editingText ? activeView(ui.activeRich, sel.editing!) : null;
|
|
127
127
|
const ordered = topLevelOrdered(store.getState().docs[loc.docId].blocks, ids);
|
|
128
128
|
const parent = loc.parent;
|
|
129
|
-
const listItem = parent && (parent.type === "listItem"
|
|
129
|
+
const listItem = parent && (parent.type === "listItem") && loc.index === 0 ? parent : null;
|
|
130
130
|
const transforms = sameType ? (type?.transforms ?? []).filter((t) => nodes.length === 1 || t.multiple) : [];
|
|
131
131
|
const height = 44;
|
|
132
132
|
// Trên khối; không đủ chỗ (khối sát mép trên khung) thì xuống dưới khối nếu còn chỗ — không đè lên dòng chữ đang gõ
|
|
@@ -176,7 +176,7 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
|
|
|
176
176
|
|
|
177
177
|
return (
|
|
178
178
|
<>
|
|
179
|
-
<div className={fixed ? "ecx-toolbar is-fixed" : "ecx-toolbar"} role="toolbar" aria-label={type?.title ?? first.type} style={fixed ? undefined : { top, left, maxWidth: maxW }} data-block={first.id}
|
|
179
|
+
<div ref={fixed ? undefined : (el) => { if (el && rect && frame) { /* Đo bề ngang thật: thanh dài (tiêu đề, danh sách…) không được tràn khỏi khung soạn đè lên bảng phải */ const l = Math.round(Math.max(frame.left + 4, Math.min(rect.left, frame.right - 4 - el.offsetWidth))); if (el.style.left !== `${l}px`) el.style.left = `${l}px`; } }} className={fixed ? "ecx-toolbar is-fixed" : "ecx-toolbar"} role="toolbar" aria-label={type?.title ?? first.type} style={fixed ? undefined : { top, left, maxWidth: maxW }} data-block={first.id}
|
|
180
180
|
onKeyDown={(e) => {
|
|
181
181
|
// Bàn phím trên thanh công cụ: ←/→ đi giữa các nút, Esc quay về khối
|
|
182
182
|
const buttons = Array.from(e.currentTarget.querySelectorAll<HTMLButtonElement>(":scope > .ecx-tool-group button:not(:disabled), :scope > .ecx-tool-group .ecx-dropdown > button"));
|
|
@@ -353,8 +353,42 @@ export function BlockMenuItems({ ids, close, onDialog }: { ids: string[]; close(
|
|
|
353
353
|
if (ordered.length > 1) store.remove(ordered.slice(1), { focusNeighbor: false });
|
|
354
354
|
});
|
|
355
355
|
};
|
|
356
|
+
// Bảng: chuột phải trong ô / trên vùng ô đang bôi đen → thao tác của bảng (chèn / xoá hàng, cột, gộp, tách ô, hàng tiêu đề)
|
|
357
|
+
const tctx = first.type === "table" ? null : tableContext(store, first.id);
|
|
358
|
+
const cellRange = ids.length > 0 ? selectedCellRect(store, ids) : null;
|
|
359
|
+
const onlyCells = nodes.length > 0 && nodes.every((n) => n.type === "tableCell" || n.type === "tableHeader");
|
|
360
|
+
const tableItems = tctx && (
|
|
361
|
+
<>
|
|
362
|
+
{cellRange && ids.length > 1 && <MenuItem icon={TableCellsMerge} label={labels.mergeCells} onClick={() => { close(); mergeRange(store, cellRange.table, cellRange.docId, cellRange.rect); }} />}
|
|
363
|
+
{cellRange && <MenuItem icon={Eraser} label={labels.clearCells} onClick={() => { close(); clearCells(store, cellRange.table, ids); }} />}
|
|
364
|
+
{!(cellRange && ids.length > 1) && canMerge(tctx, "right") && <MenuItem icon={TableCellsMerge} label={labels.mergeRight} onClick={() => { close(); mergeCells(store, tctx, "right"); }} />}
|
|
365
|
+
{!(cellRange && ids.length > 1) && canMerge(tctx, "down") && <MenuItem icon={TableCellsMerge} label={labels.mergeDown} onClick={() => { close(); mergeCells(store, tctx, "down"); }} />}
|
|
366
|
+
{canSplit(tctx) && <MenuItem icon={TableCellsSplit} label={labels.splitCell} onClick={() => { close(); splitCell(store, tctx); }} />}
|
|
367
|
+
<MenuItem icon={ArrowUpToLine} label={labels.rowBefore} onClick={() => { close(); addRow(store, tctx, false); }} />
|
|
368
|
+
<MenuItem icon={ArrowDownToLine} label={labels.rowAfter} onClick={() => { close(); addRow(store, tctx, true); }} />
|
|
369
|
+
<MenuItem icon={ArrowLeftToLine} label={labels.colBefore} onClick={() => { close(); addColumn(store, tctx, false); }} />
|
|
370
|
+
<MenuItem icon={ArrowRightToLine} label={labels.colAfter} onClick={() => { close(); addColumn(store, tctx, true); }} />
|
|
371
|
+
<MenuItem icon={Heading} label={`${labels.headerRow}${hasHeaderRow(tctx.table) ? " ✓" : ""}`} onClick={() => { close(); toggleHeaderRow(store, tctx); }} />
|
|
372
|
+
<MenuItem icon={Trash2} label={labels.deleteRow} danger onClick={() => { close(); deleteRow(store, tctx); }} />
|
|
373
|
+
<MenuItem icon={Trash2} label={labels.deleteColumn} danger onClick={() => { close(); deleteColumn(store, tctx); }} />
|
|
374
|
+
</>
|
|
375
|
+
);
|
|
376
|
+
// Khối con của một phần tử lặp (cột, tab, mục accordion, slide, nút…): chuột phải ngay trong chữ vẫn nhân đôi / xoá được phần tử đó, không phải chọn lên cha trước
|
|
377
|
+
const REPEAT = new Set(["column", "tab", "details", "button", "listItem"]);
|
|
378
|
+
const repeatLoc = REPEAT.has(first.type) ? null : [...loc.ancestors].reverse().map((id) => store.locate(id)).find((l) => l && REPEAT.has(l.block.type) && l.parent && (l.parent.content?.length ?? 0) > 1) ?? null;
|
|
379
|
+
const repeatItems = repeatLoc && !tctx && (
|
|
380
|
+
<>
|
|
381
|
+
<MenuItem icon={CopyPlus} label={`${labels.duplicate}: ${ctx.registry.get(repeatLoc.block.type)?.title ?? repeatLoc.block.type}`} onClick={() => { close(); store.duplicate([repeatLoc.block.id]); }} />
|
|
382
|
+
{store.canRemove(repeatLoc.block.id) && <MenuItem icon={Trash2} label={`${labels.remove}: ${ctx.registry.get(repeatLoc.block.type)?.title ?? repeatLoc.block.type}`} danger onClick={() => { close(); store.remove([repeatLoc.block.id]); }} />}
|
|
383
|
+
<MenuItem icon={ArrowUpLeft} label={labels.selectParent} onClick={() => { close(); store.select([repeatLoc.block.id], { editing: null }); }} />
|
|
384
|
+
</>
|
|
385
|
+
);
|
|
386
|
+
// Đang bôi đen nhiều ô: chỉ có thao tác của bảng (nhân đôi / cắt / xoá "ô" không có nghĩa)
|
|
387
|
+
if (onlyCells && tableItems) return tableItems;
|
|
356
388
|
return (
|
|
357
389
|
<>
|
|
390
|
+
{tableItems && <>{tableItems}<div className="ecx-menu-sep" role="separator" /></>}
|
|
391
|
+
{repeatItems && <>{repeatItems}<div className="ecx-menu-sep" role="separator" /></>}
|
|
358
392
|
{insertable && <>
|
|
359
393
|
<MenuItem icon={CopyPlus} label={labels.duplicate} shortcut={`${mod}⇧D`} onClick={() => { close(); store.duplicate(ordered); }} />
|
|
360
394
|
<MenuItem icon={ArrowUpToLine} label={labels.insertBefore} shortcut={`${mod}⌥T`} onClick={() => { close(); insertSibling(store, ordered[0], 0); }} />
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { PLACE_TYPES, TRANSFORM_ORIGINS, normalizeStyle, type BlockStyle, type Device } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { useMsgs } from "../i18n";
|
|
3
|
+
import { Row, Section, Seg } from "./style-controls";
|
|
4
|
+
import { UnitInput } from "./unit-controls";
|
|
5
|
+
|
|
6
|
+
type Style = BlockStyle & Record<string, any>;
|
|
7
|
+
type Resp<T> = Partial<Record<Device, T>> | undefined;
|
|
8
|
+
|
|
9
|
+
/** Giá trị của khổ đang xem; chưa đặt thì hiện giá trị kế thừa (khổ lớn hơn) để người dùng biết đang thừa hưởng gì. */
|
|
10
|
+
const own = <T,>(r: Resp<T>, d: Device): T | undefined => r?.[d];
|
|
11
|
+
const inherit = <T,>(r: Resp<T>, d: Device): T | undefined => (d === "base" ? undefined : d === "mobile" ? r?.tablet ?? r?.base : r?.base);
|
|
12
|
+
const put = <T,>(r: Resp<T>, d: Device, v: T | undefined): Resp<T> => {
|
|
13
|
+
const next = { ...(r ?? {}) };
|
|
14
|
+
if (v === undefined) delete next[d]; else next[d] = v;
|
|
15
|
+
return Object.keys(next).length ? next : undefined;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Hai mục của tab Nâng cao: "Vị trí" (relative / absolute / fixed + lệch trên / phải / dưới / trái) và "Biến đổi" (xoay, phóng, nghiêng, dịch, điểm gốc).
|
|
20
|
+
* Mọi giá trị theo khổ màn hình đang chọn (ở đầu tab); khổ nhỏ chưa đặt thì kế thừa khổ lớn — như Elementor.
|
|
21
|
+
*/
|
|
22
|
+
export function PlaceTransformPanels({ style, device, commit }: { style: Style; device: Device; commit(next: Style): void }) {
|
|
23
|
+
const t = useMsgs("layout");
|
|
24
|
+
const place = style.place as Style["place"];
|
|
25
|
+
const tr = style.transform as Style["transform"];
|
|
26
|
+
const setPlace = (patch: Partial<NonNullable<Style["place"]>> | null) => commit({ ...style, place: patch === null ? undefined : { ...(place ?? { type: "relative" }), ...patch } as never });
|
|
27
|
+
const setTr = (patch: Partial<NonNullable<Style["transform"]>>) => {
|
|
28
|
+
const next = { ...(tr ?? {}), ...patch } as NonNullable<Style["transform"]>;
|
|
29
|
+
for (const k of Object.keys(next) as Array<keyof typeof next>) if (next[k] === undefined) delete next[k];
|
|
30
|
+
commit({ ...style, transform: Object.keys(next).length ? next : undefined } as never);
|
|
31
|
+
};
|
|
32
|
+
const num = (key: "rotate" | "scale" | "skewX" | "skewY", label: string, min: number, max: number, step: number, unit: string) => {
|
|
33
|
+
const v = own(tr?.[key], device), inh = inherit(tr?.[key], device);
|
|
34
|
+
const shown = v ?? inh ?? (key === "scale" ? 1 : 0);
|
|
35
|
+
return (
|
|
36
|
+
<Row key={key} label={label} device={device} onReset={v !== undefined ? () => setTr({ [key]: put(tr?.[key], device, undefined) }) : undefined}>
|
|
37
|
+
<div className="ecx-unit-row">
|
|
38
|
+
<input type="range" className="ecx-range" min={min} max={max} step={step} aria-label={label} value={shown} onChange={(e) => setTr({ [key]: put(tr?.[key], device, Number(e.target.value)) })} />
|
|
39
|
+
<span className="ecx-range-value">{shown}{unit}{v === undefined && inh !== undefined ? ` (${t.inheritedValue})` : ""}</span>
|
|
40
|
+
</div>
|
|
41
|
+
</Row>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
const len = (key: "x" | "y", label: string) => (
|
|
45
|
+
<Row key={key} label={label} device={device}>
|
|
46
|
+
<UnitInput label={label} value={own(tr?.[key], device)} placeholder={inherit(tr?.[key], device)} max={300} onChange={(v) => setTr({ [key]: put(tr?.[key], device, v) })} />
|
|
47
|
+
</Row>
|
|
48
|
+
);
|
|
49
|
+
const side = (k: "top" | "right" | "bottom" | "left", label: string) => (
|
|
50
|
+
<Row key={k} label={label} device={device}>
|
|
51
|
+
<UnitInput label={`${t.placeTitle}: ${label}`} value={own(place?.[k], device)} placeholder={inherit(place?.[k], device)} max={400} onChange={(v) => setPlace({ [k]: put(place?.[k], device, v) })} />
|
|
52
|
+
</Row>
|
|
53
|
+
);
|
|
54
|
+
return (
|
|
55
|
+
<>
|
|
56
|
+
<Section title={t.placeTitle} modified={!!place} defaultOpen={!!place} onReset={() => setPlace(null)} summary={place ? (t as Record<string, string>)[`placeType${place.type[0].toUpperCase()}${place.type.slice(1)}`] : undefined}>
|
|
57
|
+
<Row label={t.placeType}>
|
|
58
|
+
<Seg label={t.placeType} value={place?.type} options={[...PLACE_TYPES.map((p): [typeof p, string, string] => { const l = (t as Record<string, string>)[`placeType${p[0].toUpperCase()}${p.slice(1)}`]; return [p, l, l]; })]} onChange={(v) => (v ? setPlace({ type: v }) : setPlace(null))} />
|
|
59
|
+
</Row>
|
|
60
|
+
{place && <>{side("top", t.placeTop)}{side("right", t.placeRight)}{side("bottom", t.placeBottom)}{side("left", t.placeLeft)}<p className="ecx-field-help">{place.type === "absolute" ? t.placeHelpAbsolute : place.type === "fixed" ? t.placeHelpFixed : t.placeHelpRelative}</p></>}
|
|
61
|
+
</Section>
|
|
62
|
+
<Section title={t.transformTitle} modified={!!tr} defaultOpen={!!tr} onReset={() => commit({ ...style, transform: undefined } as never)}>
|
|
63
|
+
{num("rotate", t.rotate, -180, 180, 1, "°")}
|
|
64
|
+
{num("scale", t.scale, 0.1, 3, 0.05, "×")}
|
|
65
|
+
{num("skewX", t.skewX, -45, 45, 1, "°")}
|
|
66
|
+
{num("skewY", t.skewY, -45, 45, 1, "°")}
|
|
67
|
+
{len("x", t.moveX)}
|
|
68
|
+
{len("y", t.moveY)}
|
|
69
|
+
<Row label={t.origin}>
|
|
70
|
+
<select className="ecx-input" aria-label={t.origin} value={tr?.origin ?? "center"} onChange={(e) => setTr({ origin: e.target.value === "center" ? undefined : e.target.value })}>
|
|
71
|
+
{TRANSFORM_ORIGINS.map((o) => <option key={o} value={o}>{(t as Record<string, string>)[`origin_${o.replace(" ", "_")}`]}</option>)}
|
|
72
|
+
</select>
|
|
73
|
+
</Row>
|
|
74
|
+
</Section>
|
|
75
|
+
</>
|
|
76
|
+
);
|
|
77
|
+
}
|