@ecomcx/ecomweb-editor 1.29.1 → 1.31.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/block-desc.ts +5 -5
- package/src/locales/en/block-style.ts +55 -0
- package/src/locales/en/index.ts +3 -1
- package/src/locales/en/placeholders.ts +96 -0
- package/src/locales/vi/block-desc.ts +5 -5
- package/src/locales/vi/block-style.ts +58 -0
- package/src/locales/vi/index.ts +3 -1
- package/src/locales/vi/placeholders.ts +95 -0
- package/src/shared/panel-store.ts +5 -4
- package/src/v2/blocks/compat.tsx +91 -5
- package/src/v2/blocks/form.tsx +3 -0
- package/src/v2/blocks/index.ts +19 -1
- package/src/v2/blocks/layout.tsx +182 -61
- package/src/v2/blocks/media.tsx +72 -71
- package/src/v2/blocks/text.tsx +48 -17
- package/src/v2/blocks/theme.tsx +73 -12
- package/src/v2/blocks/widgets.tsx +48 -11
- package/src/v2/canvas/block-list.tsx +4 -4
- package/src/v2/canvas/canvas-css.ts +95 -6
- package/src/v2/canvas/server-block.tsx +7 -4
- package/src/v2/core/host.ts +9 -0
- package/src/v2/core/registry.ts +3 -1
- package/src/v2/core/structure.ts +2 -1
- package/src/v2/editor.css +6 -2
- package/src/v2/index.ts +3 -0
- package/src/v2/ui/ai.tsx +9 -5
- package/src/v2/ui/attr-form.tsx +2 -2
- package/src/v2/ui/attr-hints.ts +6 -2
- package/src/v2/ui/background-panel.tsx +116 -50
- package/src/v2/ui/block-style-panel.tsx +78 -0
- package/src/v2/ui/inspector.tsx +34 -14
- package/src/v2/ui/layout-panel.tsx +35 -26
- package/src/v2/{blocks → ui}/media-actions.tsx +4 -3
- package/src/v2/ui/placeholders.tsx +205 -0
- package/src/v2/ui/style-supports.ts +2 -0
- package/src/v2/ui/style-tab.tsx +16 -9
- package/src/v2/ui/toolbar.tsx +9 -4
|
@@ -3,86 +3,152 @@ import { useState } from "react";
|
|
|
3
3
|
import { useEditor } from "../context";
|
|
4
4
|
import { useMsgs } from "../i18n";
|
|
5
5
|
import { ColorInput } from "./color-field";
|
|
6
|
+
import { GradientField } from "./layout-panel";
|
|
6
7
|
import { Row, Section, Seg, cx } from "./style-controls";
|
|
7
8
|
|
|
8
9
|
/** Điểm lấy nét chọn nhanh: lưới 3×3 (trên-trái … dưới-phải). */
|
|
9
10
|
const POSITIONS = ["0% 0%", "50% 0%", "100% 0%", "0% 50%", "50% 50%", "100% 50%", "0% 100%", "50% 100%", "100% 100%"];
|
|
11
|
+
type Kind = "color" | "gradient" | "image";
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
+
* Ô Nền thống nhất (như nhóm Background của Elementor): thẻ Thường / Rê chuột, loại Màu | Chuyển màu | Ảnh.
|
|
15
|
+
* Không có kho riêng — ghi vào trường sẵn có: style.color.background, style.gradient, style.background (ảnh theo khổ, cách phủ,
|
|
16
|
+
* điểm lấy nét, lặp, cố định, lớp phủ), style.hover.color.background. Khối bìa: ảnh / lớp phủ / cố định là attrs của khối
|
|
17
|
+
* (src, overlay, opacity, fixed, focal) — ảnh bìa là <img> phủ kín, chữ nằm trên. Nhóm có màu nền cũ (attrs.background) được
|
|
18
|
+
* hiện và chuyển sang style khi sửa.
|
|
14
19
|
*/
|
|
15
|
-
export function
|
|
20
|
+
export function BackgroundControl({ type, attrs, setAttrs, device }: { type: string; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void; device: Device }) {
|
|
16
21
|
const { host } = useEditor();
|
|
17
22
|
const t = useMsgs("background");
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
const style: BlockStyle = normalizeStyle(raw) ?? {};
|
|
23
|
+
const b = useMsgs("blockStyle");
|
|
24
|
+
const cover = type === "cover";
|
|
25
|
+
const style: BlockStyle = normalizeStyle(attrs.style) ?? {};
|
|
23
26
|
const bg: BlockBackground = style.background ?? {};
|
|
27
|
+
const legacy = type === "group" && typeof attrs.background === "string" ? attrs.background : undefined;
|
|
28
|
+
const hasImage = cover ? !!attrs.src : !!bg.image;
|
|
29
|
+
const [kind, setKind] = useState<Kind>(hasImage ? "image" : style.gradient ? "gradient" : "color");
|
|
30
|
+
const [state, setState] = useState<"normal" | "hover">("normal");
|
|
24
31
|
const [url, setUrl] = useState("");
|
|
25
32
|
|
|
26
|
-
const
|
|
27
|
-
const
|
|
33
|
+
const commitStyle = (next: BlockStyle, extra: Record<string, unknown> = {}) => setAttrs({ ...extra, style: normalizeStyle(next) ?? undefined });
|
|
34
|
+
const setBg = (patch: Record<string, unknown>) => commitStyle({ ...style, background: { ...bg, ...patch } as BlockBackground });
|
|
35
|
+
// Ảnh nền chỉ nhận đường dẫn tương đối hoặc https → URL media cùng website (site http) đổi thành "/uploads/…"
|
|
36
|
+
const sameOriginPath = (v: string) => { try { const u = new URL(v, location.href); return u.origin === location.origin ? u.pathname + u.search : v; } catch { return v; } };
|
|
28
37
|
/** Giá trị theo khổ đang chọn (ảnh, cách phủ, điểm lấy nét). */
|
|
29
38
|
const setAt = (k: "image" | "size" | "position", v: string | undefined) => {
|
|
30
39
|
const r: Record<string, string | undefined> = { ...(bg[k] ?? {}) };
|
|
31
40
|
if (v && k === "image") v = sameOriginPath(v);
|
|
32
41
|
if (v) r[device] = v; else delete r[device];
|
|
33
|
-
|
|
42
|
+
setBg({ [k]: Object.keys(r).length ? r : undefined });
|
|
34
43
|
};
|
|
35
|
-
const
|
|
36
|
-
|
|
44
|
+
const setColor = (v: string | undefined) => {
|
|
45
|
+
const next: BlockStyle = { ...style, color: { ...style.color, background: v } };
|
|
46
|
+
if (legacy === undefined) return commitStyle(next);
|
|
47
|
+
// Màu cũ của nhóm kéo theo khoảng đệm + bo góc trong vỏ → giữ nguyên dáng khi chuyển sang style
|
|
48
|
+
if (!next.radius && attrs.align !== "full") next.radius = "12px";
|
|
49
|
+
commitStyle(next, { background: undefined, ...(attrs.padding ? {} : { padding: "medium" }) });
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const image = cover ? (attrs.src as string | undefined) : bg.image?.[device];
|
|
53
|
+
const inherited = cover ? undefined : device === "mobile" ? bg.image?.tablet ?? bg.image?.base : device === "tablet" ? bg.image?.base : undefined;
|
|
54
|
+
const focal = cover ? (typeof attrs.focal === "string" ? attrs.focal : undefined) : bg.position?.[device];
|
|
55
|
+
const setImage = (src: string | undefined, item?: { alt?: string; id?: unknown }) => cover
|
|
56
|
+
? setAttrs({ src: src ? sameOriginPath(src) : undefined, ...(item ? { alt: item.alt || undefined, mediaId: item.id } : src ? {} : { mediaId: undefined }) })
|
|
57
|
+
: setAt("image", src);
|
|
37
58
|
const pick = async () => {
|
|
38
59
|
const [item] = (await host.media?.pick({ kind: "image", multiple: false })) ?? [];
|
|
39
|
-
if (item)
|
|
60
|
+
if (item) setImage(item.sizes?.large?.url ?? item.url, item);
|
|
61
|
+
};
|
|
62
|
+
const overlay = cover ? attrs.overlay : bg.overlay;
|
|
63
|
+
const opacity = cover ? Number(attrs.opacity ?? 50) : bg.overlayOpacity ?? 50;
|
|
64
|
+
const setOverlay = (v: string | undefined) => cover ? setAttrs({ overlay: v }) : setBg({ overlay: v, overlayOpacity: v ? bg.overlayOpacity : undefined });
|
|
65
|
+
const setOpacity = (n: number) => cover ? setAttrs({ opacity: n === 50 ? undefined : n }) : setBg({ overlayOpacity: n === 50 ? undefined : n });
|
|
66
|
+
const modified = !!(style.color?.background || style.gradient || style.background || style.hover?.color?.background || legacy || (cover && (attrs.src || attrs.overlay)));
|
|
67
|
+
const reset = () => {
|
|
68
|
+
const next: BlockStyle = { ...style, gradient: undefined, background: undefined, color: { ...style.color, background: undefined }, hover: style.hover && { ...style.hover, color: { ...style.hover.color, background: undefined } } };
|
|
69
|
+
commitStyle(next, { ...(legacy ? { background: undefined } : {}), ...(cover ? { src: undefined, mediaId: undefined, overlay: undefined, opacity: undefined, fixed: undefined, focal: undefined } : {}) });
|
|
40
70
|
};
|
|
41
71
|
|
|
42
72
|
return (
|
|
43
|
-
<Section title={
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
{
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
</div>
|
|
51
|
-
{!host.media && (
|
|
52
|
-
<input className="ecx-input" value={url} placeholder="https://…" aria-label={t.url}
|
|
53
|
-
onChange={(e) => setUrl(e.target.value)} onBlur={() => { setAt("image", url.trim() || undefined); setUrl(""); }} />
|
|
54
|
-
)}
|
|
55
|
-
{inherited && !image && <p className="ecx-muted">{t.inherited}</p>}
|
|
56
|
-
</div>
|
|
57
|
-
</Row>
|
|
58
|
-
{bg.image && (
|
|
73
|
+
<Section title={b.bg.title} modified={modified} onReset={reset}>
|
|
74
|
+
<div role="tablist" className="ecx-seg is-text ecx-state-tabs">
|
|
75
|
+
{(["normal", "hover"] as const).map((s) => (
|
|
76
|
+
<button key={s} type="button" role="tab" aria-selected={state === s} className={cx("ecx-seg-btn", state === s && "is-active")} onClick={() => setState(s)}>{b[s]}</button>
|
|
77
|
+
))}
|
|
78
|
+
</div>
|
|
79
|
+
{state === "hover" ? (
|
|
59
80
|
<>
|
|
60
|
-
<Row label={
|
|
61
|
-
<
|
|
62
|
-
options={[["cover", t.cover, t.cover_help], ["contain", t.contain, t.contain_help], ["auto", t.auto, t.auto_help]]} />
|
|
81
|
+
<Row label={b.bg.hoverColor}>
|
|
82
|
+
<ColorInput label={b.bg.hoverColor} value={style.hover?.color?.background} onChange={(v) => commitStyle({ ...style, hover: { ...style.hover, color: { ...style.hover?.color, background: v } } })} />
|
|
63
83
|
</Row>
|
|
64
|
-
<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
84
|
+
<p className="ecx-muted">{b.bg.hoverNote}</p>
|
|
85
|
+
</>
|
|
86
|
+
) : (
|
|
87
|
+
<>
|
|
88
|
+
<Row label={b.bg.type}>
|
|
89
|
+
<div role="radiogroup" aria-label={b.bg.type} className="ecx-seg is-text">
|
|
90
|
+
{(["color", "gradient", "image"] as const).map((k) => (
|
|
91
|
+
<button key={k} type="button" role="radio" aria-checked={kind === k} className={cx("ecx-seg-btn", kind === k && "is-active")} onClick={() => setKind(k)}>{b.bg[k]}</button>
|
|
70
92
|
))}
|
|
71
93
|
</div>
|
|
72
94
|
</Row>
|
|
73
|
-
|
|
74
|
-
|
|
95
|
+
{kind === "color" && (
|
|
96
|
+
<Row label={b.bg.color}>
|
|
97
|
+
<ColorInput label={b.bg.color} value={style.color?.background ?? legacy} onChange={setColor} />
|
|
98
|
+
{legacy && !style.color?.background && <p className="ecx-muted">{b.bg.legacy}</p>}
|
|
99
|
+
</Row>
|
|
100
|
+
)}
|
|
101
|
+
{kind === "gradient" && <Row label={b.bg.gradient}><GradientField value={style.gradient} onChange={(g) => commitStyle({ ...style, gradient: g })} /></Row>}
|
|
102
|
+
{kind === "image" && (
|
|
103
|
+
<>
|
|
104
|
+
<Row label={t.image} device={cover ? undefined : device}>
|
|
105
|
+
<div className="ecx-bg-image">
|
|
106
|
+
{(image ?? inherited) && <img src={image ?? inherited} alt="" className={cx("ecx-bg-thumb", !image && "is-inherited")} style={{ objectPosition: focal ?? bg.position?.base ?? "50% 50%" }} />}
|
|
107
|
+
<div className="ecx-bg-actions">
|
|
108
|
+
{host.media && <button type="button" className="ecx-btn" onClick={pick}>{image ? t.replace : t.choose}</button>}
|
|
109
|
+
{image && <button type="button" className="ecx-btn" onClick={() => setImage(undefined)}>{t.remove}</button>}
|
|
110
|
+
</div>
|
|
111
|
+
{!host.media && (
|
|
112
|
+
<input className="ecx-input" value={url} placeholder="https://…" aria-label={t.url}
|
|
113
|
+
onChange={(e) => setUrl(e.target.value)} onBlur={() => { setImage(url.trim() || undefined); setUrl(""); }} />
|
|
114
|
+
)}
|
|
115
|
+
{inherited && !image && <p className="ecx-muted">{t.inherited}</p>}
|
|
116
|
+
</div>
|
|
117
|
+
</Row>
|
|
118
|
+
{hasImage && (
|
|
119
|
+
<>
|
|
120
|
+
{!cover && (
|
|
121
|
+
<Row label={t.size} device={device}>
|
|
122
|
+
<Seg label={t.size} value={bg.size?.[device]} onChange={(v) => setAt("size", v)}
|
|
123
|
+
options={[["cover", t.cover, t.cover_help], ["contain", t.contain, t.contain_help], ["auto", t.auto, t.auto_help]]} />
|
|
124
|
+
</Row>
|
|
125
|
+
)}
|
|
126
|
+
<Row label={t.focal} device={cover ? undefined : device}>
|
|
127
|
+
<div role="radiogroup" aria-label={t.focal} className="ecx-bg-focal">
|
|
128
|
+
{POSITIONS.map((p) => {
|
|
129
|
+
const on = (focal ?? (cover || device === "base" ? "50% 50%" : undefined)) === p;
|
|
130
|
+
const v = p === "50% 50%" && (cover || device === "base") ? undefined : p;
|
|
131
|
+
return <button key={p} type="button" role="radio" aria-checked={on} title={p} aria-label={p} className={cx("ecx-bg-focal-dot", on && "is-active")}
|
|
132
|
+
onClick={() => (cover ? setAttrs({ focal: v }) : setAt("position", v))} />;
|
|
133
|
+
})}
|
|
134
|
+
</div>
|
|
135
|
+
</Row>
|
|
136
|
+
{!cover && <label className="ecx-check"><input type="checkbox" checked={!!bg.repeat} onChange={(e) => setBg({ repeat: e.target.checked || undefined })} /> {t.repeat}</label>}
|
|
137
|
+
<label className="ecx-check"><input type="checkbox" checked={cover ? !!attrs.fixed : !!bg.fixed} onChange={(e) => (cover ? setAttrs({ fixed: e.target.checked || undefined }) : setBg({ fixed: e.target.checked || undefined }))} /> {t.fixed}</label>
|
|
138
|
+
</>
|
|
139
|
+
)}
|
|
140
|
+
<Row label={t.overlay}>
|
|
141
|
+
<ColorInput label={t.overlay} value={overlay} onChange={setOverlay} />
|
|
142
|
+
</Row>
|
|
143
|
+
{(overlay || (cover && attrs.src)) && (
|
|
144
|
+
<Row label={`${t.opacity}: ${opacity}%`}>
|
|
145
|
+
<input type="range" min={0} max={100} step={5} value={opacity} aria-label={t.opacity} onChange={(e) => setOpacity(Number(e.target.value))} />
|
|
146
|
+
</Row>
|
|
147
|
+
)}
|
|
148
|
+
</>
|
|
149
|
+
)}
|
|
75
150
|
</>
|
|
76
151
|
)}
|
|
77
|
-
<Row label={t.overlay}>
|
|
78
|
-
<ColorInput label={t.overlay} value={bg.overlay} onChange={(v) => set({ overlay: v, overlayOpacity: v ? bg.overlayOpacity : undefined })} />
|
|
79
|
-
</Row>
|
|
80
|
-
{bg.overlay && (
|
|
81
|
-
<Row label={`${t.opacity}: ${bg.overlayOpacity ?? 50}%`}>
|
|
82
|
-
<input type="range" min={0} max={100} step={5} value={bg.overlayOpacity ?? 50} aria-label={t.opacity}
|
|
83
|
-
onChange={(e) => set({ overlayOpacity: Number(e.target.value) === 50 ? undefined : Number(e.target.value) })} />
|
|
84
|
-
</Row>
|
|
85
|
-
)}
|
|
86
152
|
</Section>
|
|
87
153
|
);
|
|
88
154
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { coreControlsFor, optionValue, type ControlSpec, type Device } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { useMsgs } from "../i18n";
|
|
4
|
+
import { ColorInput } from "./color-field";
|
|
5
|
+
import { Row, Section, cx } from "./style-controls";
|
|
6
|
+
import { UnitInput } from "./unit-controls";
|
|
7
|
+
|
|
8
|
+
type State = "normal" | "hover" | "active";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Mục Kiểu dáng riêng của khối lõi (như tab Style của từng widget Elementor: Danh sách › khoảng cách, đường kẻ; Icon › màu, cỡ…).
|
|
12
|
+
* Ô khai ở @ecomcx/ecomweb-content core-controls → website và khung soạn sinh cùng CSS (controlsCss). Ô `responsive` sửa theo khổ
|
|
13
|
+
* đang chọn ở đầu tab; ô có `state` nằm trong thẻ Rê chuột / Đang mở của mục.
|
|
14
|
+
*/
|
|
15
|
+
export function BlockStyleSections({ type, attrs, setAttrs, device }: { type: string; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void; device: Device }) {
|
|
16
|
+
const t = useMsgs("blockStyle");
|
|
17
|
+
const sections = new Map<string, Array<[string, ControlSpec]>>();
|
|
18
|
+
for (const [name, spec] of Object.entries(coreControlsFor(type))) {
|
|
19
|
+
const k = spec.section ?? "text";
|
|
20
|
+
sections.set(k, [...(sections.get(k) ?? []), [name, spec]]);
|
|
21
|
+
}
|
|
22
|
+
if (!sections.size) return null;
|
|
23
|
+
return <>{[...sections].map(([key, list]) => <ControlSection key={key} title={(t.section as Record<string, string>)[key] ?? key} list={list} attrs={attrs} setAttrs={setAttrs} device={device} />)}</>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function ControlSection({ title, list, attrs, setAttrs, device }: { title: string; list: Array<[string, ControlSpec]>; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void; device: Device }) {
|
|
27
|
+
const t = useMsgs("blockStyle");
|
|
28
|
+
const states = [...new Set(list.map(([, s]) => s.state ?? "normal"))] as State[];
|
|
29
|
+
const [state, setState] = useState<State>("normal");
|
|
30
|
+
const modified = list.some(([k]) => attrs[k] !== undefined);
|
|
31
|
+
const shown = list.filter(([, s]) => (s.state ?? "normal") === state);
|
|
32
|
+
return (
|
|
33
|
+
<Section title={title} modified={modified} onReset={() => setAttrs(Object.fromEntries(list.map(([k]) => [k, undefined])))}>
|
|
34
|
+
{states.length > 1 && (
|
|
35
|
+
<div role="tablist" className="ecx-seg is-text ecx-state-tabs">
|
|
36
|
+
{(["normal", "hover", "active"] as const).filter((s) => states.includes(s)).map((s) => (
|
|
37
|
+
<button key={s} type="button" role="tab" aria-selected={state === s} className={cx("ecx-seg-btn", state === s && "is-active")} onClick={() => setState(s)}>{t[s]}</button>
|
|
38
|
+
))}
|
|
39
|
+
</div>
|
|
40
|
+
)}
|
|
41
|
+
{shown.map(([name, spec]) => <ControlField key={name} name={name} spec={spec} value={attrs[name]} device={device} onChange={(v) => setAttrs({ [name]: v })} />)}
|
|
42
|
+
</Section>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Một ô: giá trị theo khổ (`responsive`) lưu `{ base, tablet, mobile }`, khổ chưa đặt hiện giá trị kế thừa làm gợi ý. */
|
|
47
|
+
function ControlField({ name, spec, value, device, onChange }: { name: string; spec: ControlSpec; value: unknown; device: Device; onChange(v: unknown): void }) {
|
|
48
|
+
const t = useMsgs("blockStyle");
|
|
49
|
+
const label = (t.attr as Record<string, string>)[name] ?? name;
|
|
50
|
+
const map = spec.responsive ? (value && typeof value === "object" ? value as Record<string, unknown> : value === undefined ? {} : { base: value }) : null;
|
|
51
|
+
const v = map ? map[device] : value;
|
|
52
|
+
const inherited = map && device !== "base" && v === undefined ? (device === "mobile" ? map.tablet ?? map.base : map.base) : undefined;
|
|
53
|
+
const set = (x: unknown) => {
|
|
54
|
+
if (!map) return onChange(x === "" ? undefined : x);
|
|
55
|
+
const next = { ...map };
|
|
56
|
+
if (x === undefined || x === "") delete next[device]; else next[device] = x;
|
|
57
|
+
const keys = Object.keys(next);
|
|
58
|
+
onChange(!keys.length ? undefined : keys.length === 1 && keys[0] === "base" ? next.base : next);
|
|
59
|
+
};
|
|
60
|
+
const dev = spec.responsive ? device : undefined;
|
|
61
|
+
if (spec.type === "color") return <Row label={label} device={dev}><ColorInput label={label} value={typeof v === "string" ? v : undefined} onChange={set} /></Row>;
|
|
62
|
+
if (spec.type === "length") return <Row label={label} device={dev}><UnitInput label={label} value={typeof v === "string" ? v : undefined} placeholder={typeof inherited === "string" ? inherited : undefined} units={["px", "rem", "em", "%"]} onChange={set} /></Row>;
|
|
63
|
+
if (spec.type === "number") return (
|
|
64
|
+
<Row label={`${label}${typeof v === "number" ? `: ${v}` : ""}`} device={dev}>
|
|
65
|
+
<input type="range" className="ecx-range" min={spec.min} max={spec.max} step={spec.step ?? 1} value={typeof v === "number" ? v : spec.max ?? 1} aria-label={label}
|
|
66
|
+
onChange={(e) => set(Number(e.target.value) === spec.max ? undefined : Number(e.target.value))} />
|
|
67
|
+
</Row>
|
|
68
|
+
);
|
|
69
|
+
const opts = t.opt as Record<string, string>;
|
|
70
|
+
return (
|
|
71
|
+
<Row label={label} device={dev}>
|
|
72
|
+
<select className="ecx-input" aria-label={label} value={typeof v === "string" ? v : ""} onChange={(e) => set(e.target.value || undefined)}>
|
|
73
|
+
<option value="">{typeof inherited === "string" ? `↳ ${opts[inherited] ?? inherited}` : "—"}</option>
|
|
74
|
+
{spec.options?.map((o) => { const x = optionValue(o); return <option key={x} value={x}>{opts[x] ?? x}</option>; })}
|
|
75
|
+
</select>
|
|
76
|
+
</Row>
|
|
77
|
+
);
|
|
78
|
+
}
|
package/src/v2/ui/inspector.tsx
CHANGED
|
@@ -8,18 +8,27 @@ import type { BNode } from "../core/model";
|
|
|
8
8
|
import { AttrForm, Field, attrName, cx } from "./attr-form";
|
|
9
9
|
import { BindingsPanel, CORE_BINDABLE } from "./bindings";
|
|
10
10
|
import { StyleTab } from "./style-tab";
|
|
11
|
+
import { BackgroundControl } from "./background-panel";
|
|
12
|
+
import { BlockStyleSections } from "./block-style-panel";
|
|
13
|
+
import { styleGroups } from "./style-supports";
|
|
11
14
|
import { ColorInput } from "./color-field";
|
|
12
15
|
import { UnitInput } from "./unit-controls";
|
|
13
16
|
import { useMsgs } from "../i18n";
|
|
14
17
|
|
|
15
|
-
/**
|
|
18
|
+
/** Khối "khung" (như Container / Section của Elementor): ô Nền đặt ngay tab Cài đặt — chỗ người dùng tìm đầu tiên. */
|
|
19
|
+
const BG_IN_SETTINGS = new Set(["group", "column", "cover"]);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Bảng cài đặt của khối đang chọn (như Elementor): thẻ khối, tab Cài đặt (nội dung: form + phần riêng của khối), tab Kiểu dáng
|
|
23
|
+
* (mục riêng của khối từ core-controls + ô Nền + chữ / màu) và tab Nâng cao (khoảng cách, viền, hiệu ứng, chuyển động, ẩn hiện, neo / class).
|
|
24
|
+
*/
|
|
16
25
|
export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<{ name: string; label: string }>> }) {
|
|
17
26
|
const { store, registry, labels, ui } = useEditor();
|
|
18
27
|
useUiTick();
|
|
19
28
|
const t = useMsgs("controls");
|
|
20
29
|
const sel = useEditorState((s) => s.selection);
|
|
21
30
|
useEditorState((s) => s.revision);
|
|
22
|
-
const [tab, setTab] = useState<"settings" | "style">("settings");
|
|
31
|
+
const [tab, setTab] = useState<"settings" | "style" | "advanced">("settings");
|
|
23
32
|
// Khổ dùng chung với khung soạn: chọn "Điện thoại" ở đây thì khung soạn cũng thu về khổ điện thoại
|
|
24
33
|
const device: Device = ui.device === "desktop" ? "base" : ui.device;
|
|
25
34
|
const setDevice = (d: Device) => ui.setDevice(d === "base" ? "desktop" : d);
|
|
@@ -32,7 +41,9 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
|
|
|
32
41
|
const Icon = type?.icon ?? Blocks;
|
|
33
42
|
const disabled = store.modeOf(first.id) === "disabled";
|
|
34
43
|
const setAttrs = (a: Record<string, unknown>) => store.setAttrs(ids, a);
|
|
35
|
-
const
|
|
44
|
+
const single = same && nodes.length === 1;
|
|
45
|
+
const Custom = single ? type?.inspector : undefined;
|
|
46
|
+
const styled = type?.supports?.style !== false && !store.isContentOnly(first.id);
|
|
36
47
|
const bindable = type?.bindable ?? CORE_BINDABLE[first.type];
|
|
37
48
|
const variants = [...(CORE_BLOCK_STYLES[first.type] ?? []).map((name) => ({ name, label: (t.blockStyle as Record<string, string>)[name] ?? name })), ...(blockStyles?.[first.type] ?? [])];
|
|
38
49
|
return (
|
|
@@ -45,28 +56,37 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
|
|
|
45
56
|
<>
|
|
46
57
|
<div className="ecx-tabs" role="tablist">
|
|
47
58
|
<button type="button" role="tab" aria-selected={tab === "settings"} className={cx(tab === "settings" && "is-active")} onClick={() => setTab("settings")}>{labels.settings}</button>
|
|
48
|
-
{
|
|
59
|
+
{styled && <button type="button" role="tab" aria-selected={tab === "style"} className={cx(tab === "style" && "is-active")} onClick={() => setTab("style")}>{t.styles}</button>}
|
|
60
|
+
{(styled || nodes.length === 1) && <button type="button" role="tab" aria-selected={tab === "advanced"} className={cx(tab === "advanced" && "is-active")} onClick={() => setTab("advanced")}>{t.advanced}</button>}
|
|
49
61
|
</div>
|
|
50
|
-
{tab === "settings" ? (
|
|
62
|
+
{tab === "settings" || (tab === "style" && !styled) ? (
|
|
51
63
|
<div className="ecx-panel">
|
|
52
64
|
{same && type && <AttrForm type={type} attrs={first.attrs} onChange={setAttrs} />}
|
|
65
|
+
{styled && single && BG_IN_SETTINGS.has(first.type) && <BackgroundControl key={first.id} type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />}
|
|
53
66
|
{Custom && <Custom block={first} attrs={first.attrs} setAttrs={setAttrs} blockProps={null as never} selected editable labels={labels} />}
|
|
54
67
|
{same && nodes.length === 1 && <PluginPanels type={first.type} attrs={first.attrs} setAttrs={setAttrs} />}
|
|
55
68
|
{nodes.length === 1 && bindable?.length && <BindingsPanel block={first} bindable={bindable} onChange={(b) => setAttrs({ bindings: b })} />}
|
|
69
|
+
</div>
|
|
70
|
+
) : tab === "style" ? (
|
|
71
|
+
<div className="ecx-panel">
|
|
72
|
+
<StyleTab type={first.type} style={first.attrs.style} onChange={(st) => setAttrs({ style: st ?? undefined })} device={device} onDeviceChange={setDevice} part="style"
|
|
73
|
+
variants={variants.length ? variants : undefined} variant={(first.attrs.blockStyle as string) ?? null} onVariantChange={(v) => setAttrs({ blockStyle: v ?? undefined })}
|
|
74
|
+
lead={single && <>
|
|
75
|
+
<BlockStyleSections type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />
|
|
76
|
+
{!BG_IN_SETTINGS.has(first.type) && (styleGroups(first.type, type).has("background") || !!(first.attrs.style as { background?: unknown } | undefined)?.background) && <BackgroundControl key={first.id} type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />}
|
|
77
|
+
</>} />
|
|
78
|
+
{single && <PluginPanels type={first.type} attrs={first.attrs} setAttrs={setAttrs} tab="style" />}
|
|
79
|
+
</div>
|
|
80
|
+
) : (
|
|
81
|
+
<div className="ecx-panel">
|
|
82
|
+
{styled && <StyleTab type={first.type} style={first.attrs.style} onChange={(st) => setAttrs({ style: st ?? undefined })} device={device} onDeviceChange={setDevice} part="advanced" />}
|
|
56
83
|
{nodes.length === 1 && (
|
|
57
|
-
<
|
|
58
|
-
<summary>{t.advanced}</summary>
|
|
84
|
+
<div className="ecx-form">
|
|
59
85
|
<Field label={attrName("anchor", labels.lang) ?? "anchor"}><input className="ecx-input" value={String(first.attrs.anchor ?? "")} onChange={(e) => setAttrs({ anchor: e.target.value.replace(/[^\w-]/g, "") || undefined })} /></Field>
|
|
60
86
|
<Field label={attrName("className", labels.lang) ?? "className"}><input className="ecx-input" value={String(first.attrs.className ?? "")} onChange={(e) => setAttrs({ className: e.target.value || undefined })} /></Field>
|
|
61
|
-
</
|
|
87
|
+
</div>
|
|
62
88
|
)}
|
|
63
89
|
</div>
|
|
64
|
-
) : (
|
|
65
|
-
<div className="ecx-panel">
|
|
66
|
-
<StyleTab type={first.type} style={first.attrs.style} onChange={(st) => setAttrs({ style: st ?? undefined })} device={device} onDeviceChange={setDevice}
|
|
67
|
-
variants={variants.length ? variants : undefined} variant={(first.attrs.blockStyle as string) ?? null} onVariantChange={(v) => setAttrs({ blockStyle: v ?? undefined })} />
|
|
68
|
-
{same && nodes.length === 1 && <PluginPanels type={first.type} attrs={first.attrs} setAttrs={setAttrs} tab="style" />}
|
|
69
|
-
</div>
|
|
70
90
|
)}
|
|
71
91
|
</>
|
|
72
92
|
)}
|
|
@@ -21,7 +21,40 @@ export function layoutFor(kind: Kind, prev?: BlockLayout): BlockLayout | undefin
|
|
|
21
21
|
return { type: "flex", direction: { base: kind === "stack" ? "column" : "row" }, ...(prev?.justify ? { justify: prev.justify } : {}), ...(prev?.align ? { align: prev.align } : {}) };
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
/** Nền chuyển màu: preset của theme hoặc hai màu + góc (dùng ở mục Hiệu ứng và ô Nền). */
|
|
25
|
+
export function GradientField({ value, onChange }: { value?: string; onChange(g: string | undefined): void }) {
|
|
26
|
+
const { host } = useEditor();
|
|
27
|
+
const t = useMsgs("layout");
|
|
28
|
+
const gradPresets = Object.keys(host.presets?.gradients ?? {});
|
|
29
|
+
const g = value && !gradPresets.includes(value) ? /^linear-gradient\((\d{1,3})deg, (#[0-9a-f]{3,8}) 0%, (#[0-9a-f]{3,8}) 100%\)$/i.exec(value) : null;
|
|
30
|
+
const [angle, setAngle] = useState(g ? Number(g[1]) : 135);
|
|
31
|
+
const [c1, setC1] = useState(g?.[2] ?? "#1a597b");
|
|
32
|
+
const [c2, setC2] = useState(g?.[3] ?? "#f26251");
|
|
33
|
+
const applyCustom = (a = angle, x = c1, y = c2) => onChange(normalizeGradient(`linear-gradient(${a}deg, ${x} 0%, ${y} 100%)`));
|
|
34
|
+
return (
|
|
35
|
+
<>
|
|
36
|
+
<div className="ecx-chip-row">
|
|
37
|
+
<button type="button" className={cx("ecx-chip", !value && "is-active")} onClick={() => onChange(undefined)}>{t.none}</button>
|
|
38
|
+
{gradPresets.map((name) => (
|
|
39
|
+
<button key={name} type="button" className={cx("ecx-chip ecx-chip-swatch", value === name && "is-active")} title={name} aria-label={name}
|
|
40
|
+
style={{ background: host.presets!.gradients![name] }} onClick={() => onChange(name)} />
|
|
41
|
+
))}
|
|
42
|
+
<button type="button" className={cx("ecx-chip ecx-chip-swatch", g && "is-active")} title={t.custom}
|
|
43
|
+
style={{ background: `linear-gradient(${angle}deg, ${c1}, ${c2})` }} onClick={() => applyCustom()} />
|
|
44
|
+
</div>
|
|
45
|
+
{g && (
|
|
46
|
+
<div className="ecx-gradient-edit">
|
|
47
|
+
<label>{t.from} <input type="color" value={c1} onChange={(e) => { setC1(e.target.value); applyCustom(angle, e.target.value, c2); }} /></label>
|
|
48
|
+
<label>{t.to} <input type="color" value={c2} onChange={(e) => { setC2(e.target.value); applyCustom(angle, c1, e.target.value); }} /></label>
|
|
49
|
+
<label>{t.angle} <input type="range" min={0} max={360} step={15} value={angle} onChange={(e) => { setAngle(Number(e.target.value)); applyCustom(Number(e.target.value)); }} aria-label={t.angle} /> {angle}°</label>
|
|
50
|
+
</div>
|
|
51
|
+
)}
|
|
52
|
+
</>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** `gradient` = false khi khối đã có ô Nền (chuyển màu sửa ở đó, không lặp lại ở Hiệu ứng). */
|
|
57
|
+
export function LayoutEffectsPanel({ type, style: raw, onChange, device, effects = true, hover = true, gradient = true }: { type: string; style: unknown; onChange(style: BlockStyle | null): void; device: Device; effects?: boolean; hover?: boolean; gradient?: boolean }) {
|
|
25
58
|
const { labels, host } = useEditor();
|
|
26
59
|
const t = useMsgs("layout");
|
|
27
60
|
const style: BlockStyle = normalizeStyle(raw) ?? {};
|
|
@@ -40,13 +73,6 @@ export function LayoutEffectsPanel({ type, style: raw, onChange, device, effects
|
|
|
40
73
|
return Object.keys(next).length ? next : undefined;
|
|
41
74
|
};
|
|
42
75
|
|
|
43
|
-
// Nền chuyển màu: preset của theme hoặc hai màu + góc
|
|
44
|
-
const gradPresets = Object.keys(host.presets?.gradients ?? {});
|
|
45
|
-
const g = style.gradient && !gradPresets.includes(style.gradient) ? /^linear-gradient\((\d{1,3})deg, (#[0-9a-f]{3,8}) 0%, (#[0-9a-f]{3,8}) 100%\)$/i.exec(style.gradient) : null;
|
|
46
|
-
const [angle, setAngle] = useState(g ? Number(g[1]) : 135);
|
|
47
|
-
const [c1, setC1] = useState(g?.[2] ?? "#1a597b");
|
|
48
|
-
const [c2, setC2] = useState(g?.[3] ?? "#f26251");
|
|
49
|
-
const applyCustom = (a = angle, x = c1, y = c2) => set({ gradient: normalizeGradient(`linear-gradient(${a}deg, ${x} 0%, ${y} 100%)`) });
|
|
50
76
|
const shadows = ["sm", "md", "lg", "xl", ...Object.keys(host.presets?.shadows ?? {}).filter((s) => !["sm", "md", "lg", "xl"].includes(s))];
|
|
51
77
|
|
|
52
78
|
return (
|
|
@@ -93,24 +119,7 @@ export function LayoutEffectsPanel({ type, style: raw, onChange, device, effects
|
|
|
93
119
|
)}
|
|
94
120
|
|
|
95
121
|
{effects && <Section title={t.effects} defaultOpen={!!(style.gradient || style.shadow || style.aspectRatio || style.position)}>
|
|
96
|
-
<Row label={t.gradient}>
|
|
97
|
-
<div className="ecx-chip-row">
|
|
98
|
-
<button type="button" className={cx("ecx-chip", !style.gradient && "is-active")} onClick={() => set({ gradient: undefined })}>{t.none}</button>
|
|
99
|
-
{gradPresets.map((name) => (
|
|
100
|
-
<button key={name} type="button" className={cx("ecx-chip ecx-chip-swatch", style.gradient === name && "is-active")} title={name} aria-label={name}
|
|
101
|
-
style={{ background: host.presets!.gradients![name] }} onClick={() => set({ gradient: name })} />
|
|
102
|
-
))}
|
|
103
|
-
<button type="button" className={cx("ecx-chip ecx-chip-swatch", g && "is-active")} title={t.custom}
|
|
104
|
-
style={{ background: `linear-gradient(${angle}deg, ${c1}, ${c2})` }} onClick={() => applyCustom()} />
|
|
105
|
-
</div>
|
|
106
|
-
{g && (
|
|
107
|
-
<div className="ecx-gradient-edit">
|
|
108
|
-
<label>{t.from} <input type="color" value={c1} onChange={(e) => { setC1(e.target.value); applyCustom(angle, e.target.value, c2); }} /></label>
|
|
109
|
-
<label>{t.to} <input type="color" value={c2} onChange={(e) => { setC2(e.target.value); applyCustom(angle, c1, e.target.value); }} /></label>
|
|
110
|
-
<label>{t.angle} <input type="range" min={0} max={360} step={15} value={angle} onChange={(e) => { setAngle(Number(e.target.value)); applyCustom(Number(e.target.value)); }} aria-label={t.angle} /> {angle}°</label>
|
|
111
|
-
</div>
|
|
112
|
-
)}
|
|
113
|
-
</Row>
|
|
122
|
+
{gradient && <Row label={t.gradient}><GradientField value={style.gradient} onChange={(g) => set({ gradient: g })} /></Row>}
|
|
114
123
|
<Row label={t.shadow}>
|
|
115
124
|
<select className="ecx-input" aria-label={t.shadow} value={style.shadow ?? ""} onChange={(e) => set({ shadow: e.target.value || undefined })}>
|
|
116
125
|
<option value="">—</option><option value="none">{t.none}</option>
|
|
@@ -19,7 +19,7 @@ export function mediaAttrs(kind: MediaKind, items: MediaItem[]): Record<string,
|
|
|
19
19
|
* Chọn media ngay trên khối: Tải lên (có thể kéo thả tệp vào cả vùng), Thư viện, Chèn từ URL. Dùng cho ảnh, gallery,
|
|
20
20
|
* video, âm thanh, tệp, ảnh bìa, ảnh + chữ.
|
|
21
21
|
*/
|
|
22
|
-
export function MediaActions({ kind, onSelect, onUrl, compact, extra }: { kind: MediaKind; onSelect(items: MediaItem[]): void; onUrl?(url: string): void; compact?: boolean; extra?: ReactNode }) {
|
|
22
|
+
export function MediaActions({ kind, onSelect, onUrl, compact, extra, accept }: { kind: MediaKind; onSelect(items: MediaItem[]): void; onUrl?(url: string): void; compact?: boolean; extra?: ReactNode; accept?: string }) {
|
|
23
23
|
const { host, labels } = useEditor();
|
|
24
24
|
const file = useRef<HTMLInputElement>(null);
|
|
25
25
|
const [busy, setBusy] = useState(false);
|
|
@@ -49,7 +49,7 @@ export function MediaActions({ kind, onSelect, onUrl, compact, extra }: { kind:
|
|
|
49
49
|
</form>
|
|
50
50
|
)}
|
|
51
51
|
{error && <p className="ecx-media-error" role="alert">{error}</p>}
|
|
52
|
-
<input ref={file} type="file" hidden accept={ACCEPT[kind] || undefined} multiple={kind === "gallery"} onChange={(e) => { void upload([...(e.target.files ?? [])]); e.target.value = ""; }} />
|
|
52
|
+
<input ref={file} type="file" hidden accept={accept ?? (ACCEPT[kind] || undefined)} multiple={kind === "gallery"} onChange={(e) => { void upload([...(e.target.files ?? [])]); e.target.value = ""; }} />
|
|
53
53
|
</div>
|
|
54
54
|
);
|
|
55
55
|
}
|
|
@@ -64,7 +64,8 @@ export function useFileDrop(kind: MediaKind, onSelect: (items: MediaItem[]) => v
|
|
|
64
64
|
over,
|
|
65
65
|
props: {
|
|
66
66
|
onDragOver: (e: DragEvent) => { if (!hasFiles(e)) return; e.preventDefault(); setOver(true); },
|
|
67
|
-
|
|
67
|
+
// Rời sang phần tử con vẫn ở trong vùng: giữ trạng thái (không nhấp nháy)
|
|
68
|
+
onDragLeave: (e: DragEvent) => { if (!(e.currentTarget as Node).contains(e.relatedTarget as Node | null)) setOver(false); },
|
|
68
69
|
onDrop: async (e: DragEvent) => {
|
|
69
70
|
if (!hasFiles(e)) return;
|
|
70
71
|
e.preventDefault(); setOver(false);
|