@ecomcx/ecomweb-editor 1.32.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 +5 -1
- package/src/locales/en/block-desc.ts +5 -11
- package/src/locales/en/block-style.ts +17 -6
- package/src/locales/en/block-titles.ts +38 -15
- package/src/locales/en/blocks.ts +37 -6
- package/src/locales/en/columns.ts +1 -0
- package/src/locales/en/controls.ts +1 -1
- package/src/locales/en/hints.ts +315 -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 +9 -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 +5 -1
- package/src/locales/vi/block-desc.ts +8 -14
- package/src/locales/vi/block-style.ts +18 -7
- package/src/locales/vi/block-titles.ts +48 -25
- package/src/locales/vi/blocks.ts +37 -6
- package/src/locales/vi/columns.ts +1 -0
- package/src/locales/vi/controls.ts +1 -1
- package/src/locales/vi/hints.ts +315 -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 +10 -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 +349 -106
- 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 +62 -29
- package/src/v2/blocks/tools.tsx +24 -2
- package/src/v2/blocks/widgets.tsx +84 -28
- package/src/v2/canvas/block-list.tsx +36 -5
- package/src/v2/canvas/canvas-css.ts +95 -7
- package/src/v2/canvas/canvas.tsx +65 -9
- 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 +3 -1
- 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 +45 -7
- package/src/v2/ui/attr-hints.ts +151 -19
- 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 +9 -1
- 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 +72 -17
- 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
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { MOTION_HOVER, MOTION_IN, normalizeStyle, type BlockStyle } from "@ecomcx/ecomweb-content";
|
|
1
|
+
import { MOTION_EASE, MOTION_HOVER, MOTION_IN, MOTION_LOOP, MOTION_PARALLAX, normalizeStyle, type BlockStyle } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { PickTiles, motionHoverThumb, motionInThumb } from "./option-thumbs";
|
|
2
3
|
import { Play } from "lucide-react";
|
|
3
4
|
import { useSyncExternalStore } from "react";
|
|
4
5
|
import { onAnimationsChange, pluginAnimations } from "../../shared/animation-store";
|
|
@@ -55,12 +56,9 @@ export function MotionPanel({ type, style: raw, onChange }: { type: string; styl
|
|
|
55
56
|
return (
|
|
56
57
|
<Section title={t.title} defaultOpen={false} modified={!!style.motion} summary={m.in ? (t.in as Record<string, string>)[m.in] ?? m.in : ct.noMotion} onReset={() => onChange(normalizeStyle({ ...style, motion: undefined }) ?? null)}>
|
|
57
58
|
<Row label={t.scroll}>
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
{
|
|
61
|
-
<button key={id} type="button" role="radio" aria-checked={m.in === id} className={cx("ecx-chip", m.in === id && "is-active")} onClick={() => set({ in: id }, true)}>{t.in[id]}</button>
|
|
62
|
-
))}
|
|
63
|
-
</div>
|
|
59
|
+
<PickTiles label={t.scroll} value={m.in && (MOTION_IN as readonly string[]).includes(m.in) ? m.in : undefined} none={{ label: t.none }}
|
|
60
|
+
options={MOTION_IN.map((id) => ({ id, label: t.in[id], thumb: motionInThumb(id) }))}
|
|
61
|
+
onChange={(v) => (v === undefined ? set({ in: undefined, duration: undefined, delay: undefined, repeat: undefined, stagger: undefined }) : set({ in: v }, true))} />
|
|
64
62
|
{plugin.length > 0 && (
|
|
65
63
|
<select className="ecx-input" aria-label={t.more} value={isPlugin ? m.in : ""} onChange={(e) => e.target.value && set({ in: e.target.value }, true)}>
|
|
66
64
|
<option value="">{t.more}…</option>
|
|
@@ -76,6 +74,11 @@ export function MotionPanel({ type, style: raw, onChange }: { type: string; styl
|
|
|
76
74
|
<Seg label={t.speed} value={m.duration ?? "normal"} onChange={(v) => set({ duration: !v || v === "normal" ? undefined : v }, true)}
|
|
77
75
|
options={[["fast", t.fast, t.fast], ["normal", t.normal, t.normal], ["slow", t.slow, t.slow]]} />
|
|
78
76
|
</Row>
|
|
77
|
+
<Row label={t.ease}>
|
|
78
|
+
<select className="ecx-input" aria-label={t.ease} value={m.ease ?? "smooth"} onChange={(e) => set({ ease: e.target.value === "smooth" ? undefined : (e.target.value as Motion["ease"]) }, true)}>
|
|
79
|
+
{MOTION_EASE.map((id) => <option key={id} value={id}>{t.eases[id]}</option>)}
|
|
80
|
+
</select>
|
|
81
|
+
</Row>
|
|
79
82
|
<Row label={t.delay}>
|
|
80
83
|
<select className="ecx-input" aria-label={t.delay} value={m.delay ?? 0} onChange={(e) => set({ delay: Number(e.target.value) || undefined }, true)}>
|
|
81
84
|
{[...new Set([...DELAYS, m.delay ?? 0])].sort((a, b) => a - b).map((d) => <option key={d} value={d}>{d} ms</option>)}
|
|
@@ -87,13 +90,19 @@ export function MotionPanel({ type, style: raw, onChange }: { type: string; styl
|
|
|
87
90
|
</>
|
|
88
91
|
)}
|
|
89
92
|
|
|
93
|
+
<Row label={t.loop}>
|
|
94
|
+
<PickTiles label={t.loop} value={m.loop} none={{ label: t.none }} options={MOTION_LOOP.map((id) => ({ id, label: t.loops[id], thumb: motionHoverThumb("grow") }))} onChange={(v) => set({ loop: v as Motion["loop"], parallax: v ? undefined : m.parallax })} />
|
|
95
|
+
</Row>
|
|
96
|
+
{!m.in && !m.loop && (
|
|
97
|
+
<Row label={t.parallax}>
|
|
98
|
+
<select className="ecx-input" aria-label={t.parallax} value={m.parallax ?? ""} onChange={(e) => set({ parallax: (e.target.value || undefined) as Motion["parallax"] })}>
|
|
99
|
+
<option value="">{t.none}</option>
|
|
100
|
+
{MOTION_PARALLAX.map((id) => <option key={id} value={id}>{t.parallaxes[id]}</option>)}
|
|
101
|
+
</select>
|
|
102
|
+
</Row>
|
|
103
|
+
)}
|
|
90
104
|
<Row label={t.hover}>
|
|
91
|
-
<
|
|
92
|
-
<button type="button" role="radio" aria-checked={!m.hover} className={cx("ecx-chip", !m.hover && "is-active")} onClick={() => set({ hover: undefined })}>{t.none}</button>
|
|
93
|
-
{MOTION_HOVER.map((id) => (
|
|
94
|
-
<button key={id} type="button" role="radio" aria-checked={m.hover === id} className={cx("ecx-chip", m.hover === id && "is-active")} onClick={() => set({ hover: id })}>{t.hv[id]}</button>
|
|
95
|
-
))}
|
|
96
|
-
</div>
|
|
105
|
+
<PickTiles label={t.hover} value={m.hover} none={{ label: t.none }} options={MOTION_HOVER.map((id) => ({ id, label: t.hv[id], thumb: motionHoverThumb(id) }))} onChange={(v) => set({ hover: v as (typeof MOTION_HOVER)[number] | undefined })} />
|
|
97
106
|
</Row>
|
|
98
107
|
</Section>
|
|
99
108
|
);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { cx } from "./style-controls";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Ô chọn bằng hình (thẻ icon hai lớp): mỗi lựa chọn là một hình nhỏ có nhãn — lớp sau = trạng thái đầu / khung tham chiếu (nét đứt, mờ),
|
|
6
|
+
* lớp trước = kết quả — để người dùng thường nhìn là hiểu (trượt lên, phóng to, bóng đổ, khung tròn…) thay vì đọc tên rồi đoán.
|
|
7
|
+
*/
|
|
8
|
+
export interface PickOption { id: string; label: string; thumb: ReactNode }
|
|
9
|
+
|
|
10
|
+
export function PickTiles({ value, options, onChange, label, none }: { value: string | undefined; options: PickOption[]; onChange(v: string | undefined): void; label: string; none?: { label: string } }) {
|
|
11
|
+
const all: PickOption[] = none ? [{ id: "", label: none.label, thumb: <Frame><rect x="20" y="12" width="24" height="20" rx="3" className="is-solid" /></Frame> }, ...options] : options;
|
|
12
|
+
return (
|
|
13
|
+
<div className="ecx-pick-grid" role="radiogroup" aria-label={label}>
|
|
14
|
+
{all.map((o) => {
|
|
15
|
+
const on = (value ?? "") === o.id;
|
|
16
|
+
return (
|
|
17
|
+
<button key={o.id || "none"} type="button" role="radio" aria-checked={on} aria-label={o.label} title={o.label} className={cx("ecx-pick", on && "is-active")} onClick={() => onChange(o.id === "" ? undefined : on ? undefined : o.id)}>
|
|
18
|
+
{o.thumb}
|
|
19
|
+
<span className="ecx-pick-label">{o.label}</span>
|
|
20
|
+
</button>
|
|
21
|
+
);
|
|
22
|
+
})}
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const Frame = ({ children }: { children: ReactNode }) => <svg className="ecx-pick-thumb" viewBox="0 0 64 44" aria-hidden="true">{children}</svg>;
|
|
28
|
+
/** Hộp tham chiếu (lớp sau, nét đứt) và hộp kết quả (lớp trước, đặc). */
|
|
29
|
+
const ghost = (x: number, y: number, w: number, h: number, extra?: Record<string, unknown>) => <rect key={`g${x}${y}${w}`} x={x} y={y} width={w} height={h} rx="3" className="is-ghost" {...extra} />;
|
|
30
|
+
const solid = (x: number, y: number, w: number, h: number, extra?: Record<string, unknown>) => <rect key={`s${x}${y}${w}`} x={x} y={y} width={w} height={h} rx="3" className="is-solid" {...extra} />;
|
|
31
|
+
const arrow = (d: string) => <path key={`a${d}`} d={d} className="is-arrow" fill="none" />;
|
|
32
|
+
|
|
33
|
+
/** Hình cho hiệu ứng khi cuộn tới (MOTION_IN). */
|
|
34
|
+
export function motionInThumb(id: string): ReactNode {
|
|
35
|
+
const W = 24, H = 18, cx0 = 20, cy0 = 13;
|
|
36
|
+
switch (id) {
|
|
37
|
+
case "fade": return <Frame>{ghost(cx0, cy0, W, H, { opacity: 0.5 })}{solid(cx0, cy0, W, H, { opacity: 0.45 })}</Frame>;
|
|
38
|
+
case "slide-up": return <Frame>{ghost(cx0, cy0 + 9, W, H)}{solid(cx0, cy0 - 3, W, H)}{arrow("M32 40V32M29 35l3-3 3 3")}</Frame>;
|
|
39
|
+
case "slide-down": return <Frame>{ghost(cx0, cy0 - 9, W, H)}{solid(cx0, cy0 + 3, W, H)}{arrow("M32 4v8M29 9l3 3 3-3")}</Frame>;
|
|
40
|
+
case "slide-left": return <Frame>{ghost(cx0 + 12, cy0, W, H)}{solid(cx0 - 6, cy0, W, H)}{arrow("M60 22h-8M55 19l-3 3 3 3")}</Frame>;
|
|
41
|
+
case "slide-right": return <Frame>{ghost(cx0 - 12, cy0, W, H)}{solid(cx0 + 6, cy0, W, H)}{arrow("M4 22h8M9 19l3 3-3 3")}</Frame>;
|
|
42
|
+
case "zoom-in": return <Frame>{ghost(26, 17, 12, 10)}{solid(18, 11, 28, 22)}</Frame>;
|
|
43
|
+
case "zoom-out": return <Frame>{ghost(14, 8, 36, 28)}{solid(24, 15, 16, 14)}</Frame>;
|
|
44
|
+
case "blur-in": return <Frame><g filter="url(#ecx-blur)">{ghost(cx0, cy0, W, H)}</g><defs><filter id="ecx-blur"><feGaussianBlur stdDeviation="2.2" /></filter></defs>{solid(cx0, cy0, W, H)}</Frame>;
|
|
45
|
+
default: return <Frame>{solid(cx0, cy0, W, H)}</Frame>;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Hình cho hiệu ứng rê chuột (MOTION_HOVER). */
|
|
50
|
+
export function motionHoverThumb(id: string): ReactNode {
|
|
51
|
+
switch (id) {
|
|
52
|
+
case "lift": return <Frame>{ghost(20, 17, 24, 18)}{solid(20, 10, 24, 18)}{arrow("M32 38v-3M29 37l3 3 3-3")}</Frame>;
|
|
53
|
+
case "grow": return <Frame>{ghost(22, 14, 20, 16)}{solid(16, 9, 32, 26)}</Frame>;
|
|
54
|
+
case "brighten": return <Frame>{ghost(20, 13, 24, 18, { opacity: 0.35 })}{solid(20, 13, 24, 18, { opacity: 0.9 })}<path d="M50 8l1.5 3 3 1.5-3 1.5L50 17l-1.5-3-3-1.5 3-1.5z" className="is-solid" /></Frame>;
|
|
55
|
+
case "glow": return <Frame>{ghost(15, 8, 34, 28, { opacity: 0.3, rx: 10 })}{ghost(17, 10, 30, 24, { opacity: 0.45, rx: 8 })}{solid(20, 13, 24, 18)}</Frame>;
|
|
56
|
+
default: return <Frame>{solid(20, 13, 24, 18)}</Frame>;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Hình cho khung icon (không khung / tròn / vuông) và các tuỳ chọn tương tự. */
|
|
61
|
+
export function frameThumb(id: string): ReactNode {
|
|
62
|
+
const star = <path d="M32 14l2.4 5 5.4.7-4 3.8 1 5.4L32 26.2l-4.8 2.7 1-5.4-4-3.8 5.4-.7z" className="is-glyph" />;
|
|
63
|
+
switch (id) {
|
|
64
|
+
case "circle": return <Frame><circle cx="32" cy="22" r="15" className="is-solid" />{star}</Frame>;
|
|
65
|
+
case "square": return <Frame><rect x="17" y="7" width="30" height="30" rx="5" className="is-solid" />{star}</Frame>;
|
|
66
|
+
default: return <Frame><rect x="17" y="7" width="30" height="30" rx="5" className="is-ghost" /><path d="M32 14l2.4 5 5.4.7-4 3.8 1 5.4L32 26.2l-4.8 2.7 1-5.4-4-3.8 5.4-.7z" className="is-solid" /></Frame>;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Hình cho độ đậm của bóng đổ (sm → xl): lớp sau = bóng, lớp trước = hộp. */
|
|
71
|
+
export function shadowThumb(id: string): ReactNode {
|
|
72
|
+
const spread = { sm: 1.5, md: 3, lg: 5, xl: 7 }[id] ?? 3;
|
|
73
|
+
return <Frame>{ghost(20 - spread / 2, 13 + spread, 24 + spread, 18 + spread / 2, { opacity: 0.35, rx: 5 })}{solid(20, 12, 24, 18)}</Frame>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Hiệu ứng rê chuột của Hộp icon: không / phóng to / lật. */
|
|
77
|
+
export function iconHoverThumb(id: string): ReactNode {
|
|
78
|
+
if (id === "grow") return motionHoverThumb("grow");
|
|
79
|
+
if (id === "flip") return <Frame>{ghost(14, 13, 14, 18)}{solid(36, 13, 14, 18)}<path d="M20 8c6-5 18-5 24 0M41 5l3 3-4 2" className="is-arrow" fill="none" /></Frame>;
|
|
80
|
+
return motionHoverThumb("none");
|
|
81
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CONTENT_VERSION } from "@ecomcx/ecomweb-content";
|
|
1
2
|
import { LayoutTemplate, Search, Sparkles, X } from "lucide-react";
|
|
2
3
|
import { useEffect, useMemo, useRef, useState, useSyncExternalStore, type ReactNode } from "react";
|
|
3
4
|
import { norm } from "../../shared/util";
|
|
@@ -78,7 +79,7 @@ function Preview({ nodes, height, render }: { nodes: RichNode[]; height: number;
|
|
|
78
79
|
ro.observe(el);
|
|
79
80
|
return () => { io.disconnect(); ro.disconnect(); };
|
|
80
81
|
}, []);
|
|
81
|
-
const value = useMemo(() => ({ version:
|
|
82
|
+
const value = useMemo(() => ({ version: CONTENT_VERSION, blocks: [{ type: "richtext", data: { type: "doc", content: nodes } }] }), [nodes]);
|
|
82
83
|
return (
|
|
83
84
|
<div ref={box} className="ecx-lib-preview" style={{ height }} aria-hidden="true">
|
|
84
85
|
{seen && (
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CORE_BINDABLE, OVERRIDE_KEY, patternOverridables } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { Repeat2 } from "lucide-react";
|
|
3
|
+
import { useEditor, useEditorState } from "../context";
|
|
4
|
+
import { docFromBlocks, type BNode } from "../core/model";
|
|
5
|
+
import { useMsgs } from "../i18n";
|
|
6
|
+
import { Field, cx } from "./attr-form";
|
|
7
|
+
import { Section } from "./style-controls";
|
|
8
|
+
|
|
9
|
+
const ATTR_LABEL = (t: Record<string, string>, attr: string) => t[`attr${attr[0].toUpperCase()}${attr.slice(1)}`] ?? attr;
|
|
10
|
+
|
|
11
|
+
/** Trong tài liệu của mẫu: bật "cho phép sửa riêng" cho khối → chỗ dùng mẫu đặt được chữ / ảnh / liên kết riêng cho khối này (tab Nâng cao). */
|
|
12
|
+
export function OverrideKeySection({ block, setAttrs }: { block: BNode; setAttrs(a: Record<string, unknown>): void }) {
|
|
13
|
+
const { store } = useEditor();
|
|
14
|
+
const t = useMsgs("patternOverrides");
|
|
15
|
+
const loc = store.locate(block.id);
|
|
16
|
+
if (!loc || !loc.docId.startsWith("pattern:") || !CORE_BINDABLE[block.type]) return null;
|
|
17
|
+
const key = typeof block.attrs.overrideKey === "string" ? block.attrs.overrideKey : "";
|
|
18
|
+
return (
|
|
19
|
+
<Section title={t.allowTitle} defaultOpen={!!key}>
|
|
20
|
+
<label className="ecx-check">
|
|
21
|
+
<input type="checkbox" checked={!!key} onChange={(e) => setAttrs({ overrideKey: e.target.checked ? `o-${block.id.replace(/[^a-z0-9]/gi, "").toLowerCase().slice(-8)}` : undefined })} /> {t.allow}
|
|
22
|
+
</label>
|
|
23
|
+
<p className="ecx-muted">{t.allowHelp}</p>
|
|
24
|
+
{key && (
|
|
25
|
+
<Field label={t.key}>
|
|
26
|
+
<input className="ecx-input" value={key} aria-label={t.key} onChange={(e) => { const v = e.target.value.toLowerCase().replace(/[^a-z0-9-]/g, "").slice(0, 40); if (OVERRIDE_KEY.test(v)) setAttrs({ overrideKey: v }); }} />
|
|
27
|
+
</Field>
|
|
28
|
+
)}
|
|
29
|
+
</Section>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Khối "Mẫu đồng bộ": liệt kê các ô mẫu cho sửa riêng — nhập giá trị riêng cho chỗ dùng này; để trống = theo mẫu. */
|
|
34
|
+
export function PatternOverridesSection({ block, setAttrs }: { block: BNode; setAttrs(a: Record<string, unknown>): void }) {
|
|
35
|
+
const { store, host, registry } = useEditor();
|
|
36
|
+
useEditorState((s) => s.docs);
|
|
37
|
+
const t = useMsgs("patternOverrides");
|
|
38
|
+
const ref = Number(block.attrs.ref);
|
|
39
|
+
const docId = host.documents?.idOf?.({ kind: "pattern", ref }) ?? `pattern:${ref}`;
|
|
40
|
+
const blocks = store.getState().docs[docId]?.blocks;
|
|
41
|
+
if (!ref || !blocks) return null;
|
|
42
|
+
const list = patternOverridables({ version: 2, blocks: [{ type: "richtext", data: docFromBlocks(blocks) }] });
|
|
43
|
+
const current = (block.attrs.overrides as Record<string, Record<string, string>> | undefined) ?? {};
|
|
44
|
+
const set = (key: string, attr: string, v: string) => {
|
|
45
|
+
const next: Record<string, Record<string, string>> = { ...current, [key]: { ...(current[key] ?? {}) } };
|
|
46
|
+
if (v) next[key][attr] = v; else delete next[key][attr];
|
|
47
|
+
if (!Object.keys(next[key]).length) delete next[key];
|
|
48
|
+
setAttrs({ overrides: Object.keys(next).length ? next : undefined });
|
|
49
|
+
};
|
|
50
|
+
return (
|
|
51
|
+
<Section title={t.title} defaultOpen>
|
|
52
|
+
{list.length === 0 && <p className="ecx-muted"><Repeat2 className="ecx-icon ecx-icon-sm" /> {t.none}</p>}
|
|
53
|
+
{list.map((o) => (
|
|
54
|
+
<div key={o.key} className="ecx-binding-row" data-override={o.key}>
|
|
55
|
+
<span className="ecx-field-label">{registry.get(o.type)?.title ?? o.type}</span>
|
|
56
|
+
{o.attrs.filter((a) => a in o.values || a === "content").map((attr) => (
|
|
57
|
+
<Field key={attr} label={ATTR_LABEL(t as unknown as Record<string, string>, attr)}>
|
|
58
|
+
<input className={cx("ecx-input")} value={current[o.key]?.[attr] ?? ""} placeholder={o.values[attr] || t.followPattern} aria-label={`${o.key}: ${attr}`}
|
|
59
|
+
onChange={(e) => set(o.key, attr, e.target.value.slice(0, 2000))} />
|
|
60
|
+
</Field>
|
|
61
|
+
))}
|
|
62
|
+
</div>
|
|
63
|
+
))}
|
|
64
|
+
<p className="ecx-muted">{t.help}</p>
|
|
65
|
+
</Section>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -66,13 +66,32 @@ export interface TextPlaceholderProps {
|
|
|
66
66
|
id?: string;
|
|
67
67
|
className?: string;
|
|
68
68
|
style?: CSSProperties;
|
|
69
|
+
/** Phím bấm trong ô (Enter / Backspace để thêm, xoá mục). */
|
|
70
|
+
onKeyDown?(e: { key: string; shiftKey: boolean; preventDefault(): void; currentTarget: HTMLInputElement | HTMLTextAreaElement }): void;
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
/** Ô gõ ngay trên khối: chữ gợi ý luôn hiện khi trống, cỡ chữ = cỡ chữ thật của chỗ đặt ô (kế thừa font). */
|
|
72
|
-
export function TextPlaceholder({ value, onChange, placeholder, multiline, label, required, id, className, style }: TextPlaceholderProps) {
|
|
74
|
+
export function TextPlaceholder({ value, onChange, placeholder, multiline, label, required, id, className, style, onKeyDown }: TextPlaceholderProps) {
|
|
75
|
+
const { ui } = useEditor();
|
|
76
|
+
const bid = (el: Element) => el.closest("[data-ecx-block]")?.getAttribute("data-ecx-block") ?? "";
|
|
73
77
|
const props = {
|
|
74
78
|
...stop, id, className: cx("ecx-ph-text", className), style, value, placeholder, required, "aria-label": label ?? placeholder, "aria-required": required || undefined,
|
|
75
|
-
"data-ecx-placeholder": "text",
|
|
79
|
+
"data-ecx-placeholder": "text", onKeyDown,
|
|
80
|
+
// Chữ mẫu chưa sửa và ô đã lấy nét (tự vào lúc chèn, đang chọn hết): giữ nguyên vùng chọn khi bấm — không để trình duyệt đặt con trỏ vào giữa chữ mẫu
|
|
81
|
+
onMouseDown: (e: { stopPropagation(): void; preventDefault(): void; currentTarget: HTMLInputElement | HTMLTextAreaElement }) => {
|
|
82
|
+
e.stopPropagation();
|
|
83
|
+
const el = e.currentTarget;
|
|
84
|
+
if (ui.fresh.has(bid(el)) && el.ownerDocument.activeElement === el && el.selectionStart !== el.selectionEnd) e.preventDefault();
|
|
85
|
+
},
|
|
86
|
+
// Chữ mẫu chưa sửa: bấm vào là chọn hết (gõ là thay)
|
|
87
|
+
onFocus: (e: { currentTarget: HTMLInputElement | HTMLTextAreaElement }) => { if (ui.fresh.has(bid(e.currentTarget))) e.currentTarget.select(); },
|
|
88
|
+
// Chữ mẫu chưa sửa: bấm vào (kể cả khi con trỏ đã tự vào ô lúc chèn) cũng chọn hết — bấm rồi gõ là thay, không chèn vào giữa chữ mẫu
|
|
89
|
+
onClick: (e: { currentTarget: HTMLInputElement | HTMLTextAreaElement }) => {
|
|
90
|
+
const el = e.currentTarget;
|
|
91
|
+
// Trình duyệt thu con trỏ về một điểm SAU sự kiện click (khi ô đã lấy nét sẵn và đang chọn hết) → chọn lại hết sau một nhịp
|
|
92
|
+
if (ui.fresh.has(bid(el))) setTimeout(() => { if (ui.fresh.has(bid(el)) && el.ownerDocument.activeElement === el && el.selectionStart === el.selectionEnd) el.select(); }, 0);
|
|
93
|
+
},
|
|
94
|
+
onChange: (e: { target: HTMLInputElement | HTMLTextAreaElement }) => { ui.fresh.delete(bid(e.target)); onChange(e.target.value); },
|
|
76
95
|
};
|
|
77
96
|
return multiline ? <textarea {...props} rows={2} /> : <input {...props} type="text" />;
|
|
78
97
|
}
|
package/src/v2/ui/preset-bar.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Check, ChevronDown, RotateCcw, Save, Star, Trash2 } from "lucide-react";
|
|
2
2
|
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
3
3
|
import { blockControls } from "../../shared/panel-store";
|
|
4
|
-
import { applyStyle, ensurePresets, onPresetsChange, pickStyle, presetsSnapshot, sameStyle, setPresets, styleKeys, type BlockPresetMap } from "../core/block-presets";
|
|
4
|
+
import { applyStyle, ensurePresets, localBlockPresets, onPresetsChange, pickStyle, presetsSnapshot, sameStyle, setPresets, styleKeys, type BlockPresetMap } from "../core/block-presets";
|
|
5
5
|
import type { BNode } from "../core/model";
|
|
6
6
|
import { useEditor } from "../context";
|
|
7
7
|
import { useMsgs } from "../i18n";
|
|
@@ -15,7 +15,8 @@ export function PresetBar({ block, setAttrs }: { block: BNode; setAttrs(a: Recor
|
|
|
15
15
|
const { host } = useEditor();
|
|
16
16
|
const t = useMsgs("presets");
|
|
17
17
|
const map = useSyncExternalStore(onPresetsChange, presetsSnapshot, presetsSnapshot);
|
|
18
|
-
|
|
18
|
+
const store = host.blockPresets ?? localBlockPresets;
|
|
19
|
+
useEffect(() => ensurePresets(store.load), [store]);
|
|
19
20
|
const [open, setOpen] = useState(false);
|
|
20
21
|
const [naming, setNaming] = useState<string | null>(null);
|
|
21
22
|
const [busy, setBusy] = useState(false);
|
|
@@ -26,7 +27,6 @@ export function PresetBar({ block, setAttrs }: { block: BNode; setAttrs(a: Recor
|
|
|
26
27
|
document.addEventListener("mousedown", out, true);
|
|
27
28
|
return () => document.removeEventListener("mousedown", out, true);
|
|
28
29
|
}, [open]);
|
|
29
|
-
if (!host.blockPresets) return null;
|
|
30
30
|
const keys = styleKeys(block.type, blockControls());
|
|
31
31
|
const cur = pickStyle(block.attrs, keys);
|
|
32
32
|
const entry = map?.[block.type] ?? {};
|
|
@@ -36,11 +36,11 @@ export function PresetBar({ block, setAttrs }: { block: BNode; setAttrs(a: Recor
|
|
|
36
36
|
const isDefault = !match && sameStyle(cur, pickStyle(def, keys));
|
|
37
37
|
const label = match ? match.name : t.default;
|
|
38
38
|
const edited = !match && !isDefault;
|
|
39
|
-
const canSave = !!
|
|
39
|
+
const canSave = !!store.save;
|
|
40
40
|
|
|
41
41
|
const save = async (next: BlockPresetMap) => {
|
|
42
42
|
setBusy(true);
|
|
43
|
-
try { setPresets((await
|
|
43
|
+
try { setPresets((await store.save!(next as Record<string, unknown>)) as BlockPresetMap); }
|
|
44
44
|
finally { setBusy(false); }
|
|
45
45
|
};
|
|
46
46
|
const withEntry = (patch: Partial<typeof entry>) => ({ ...(map ?? {}), [block.type]: { ...entry, ...patch } });
|
|
@@ -10,9 +10,8 @@ const MINIMAL: StyleGroup[] = ["spacing", "visibility"];
|
|
|
10
10
|
|
|
11
11
|
/** Khối lõi có bộ nhóm riêng; khối khác: khối chứa có đủ (kể cả ảnh nền), khối còn lại có mọi nhóm trừ ảnh nền. */
|
|
12
12
|
const CORE: Record<string, StyleGroup[]> = {
|
|
13
|
-
spacer: MINIMAL,
|
|
14
|
-
|
|
15
|
-
image: MEDIA, gallery: MEDIA, video: MEDIA, youtube: MEDIA, embed: MEDIA, featuredImage: MEDIA, siteLogo: MEDIA, avatar: MEDIA,
|
|
13
|
+
spacer: MINIMAL, customHtml: MINIMAL, shortcode: MINIMAL, audio: MINIMAL,
|
|
14
|
+
image: MEDIA, gallery: MEDIA, video: MEDIA, embed: MEDIA, featuredImage: MEDIA, siteLogo: MEDIA, avatar: MEDIA,
|
|
16
15
|
icon: ["color", "spacing", "hover", "motion", "visibility"],
|
|
17
16
|
socialLinks: ["color", "spacing", "motion", "visibility"],
|
|
18
17
|
// Màu nút (Thường / Rê chuột) ở mục Nút riêng (core-controls) — không lặp nhóm Màu chung (dữ liệu cũ có màu vẫn hiện để sửa)
|
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); }} />
|