@ecomcx/ecomweb-editor 1.31.0 → 1.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/package.json +3 -3
  2. package/src/locales/en/attrs.ts +10 -0
  3. package/src/locales/en/background.ts +17 -0
  4. package/src/locales/en/block-desc.ts +1 -0
  5. package/src/locales/en/block-style.ts +7 -4
  6. package/src/locales/en/block-titles.ts +1 -0
  7. package/src/locales/en/blocks.ts +10 -2
  8. package/src/locales/en/columns.ts +12 -0
  9. package/src/locales/en/controls.ts +21 -0
  10. package/src/locales/en/hints.ts +215 -1
  11. package/src/locales/en/index.ts +5 -2
  12. package/src/locales/en/layout.ts +32 -0
  13. package/src/locales/en/legacy.ts +1 -1
  14. package/src/locales/en/library.ts +38 -0
  15. package/src/locales/en/parts.ts +12 -0
  16. package/src/locales/en/placeholders.ts +9 -1
  17. package/src/locales/en/presets.ts +6 -0
  18. package/src/locales/en/v2.ts +21 -0
  19. package/src/locales/vi/attrs.ts +10 -0
  20. package/src/locales/vi/background.ts +17 -0
  21. package/src/locales/vi/block-desc.ts +1 -0
  22. package/src/locales/vi/block-style.ts +7 -4
  23. package/src/locales/vi/block-titles.ts +1 -0
  24. package/src/locales/vi/blocks.ts +10 -2
  25. package/src/locales/vi/columns.ts +12 -0
  26. package/src/locales/vi/controls.ts +21 -0
  27. package/src/locales/vi/hints.ts +216 -2
  28. package/src/locales/vi/index.ts +5 -2
  29. package/src/locales/vi/layout.ts +32 -0
  30. package/src/locales/vi/legacy.ts +1 -1
  31. package/src/locales/vi/library.ts +38 -0
  32. package/src/locales/vi/parts.ts +12 -0
  33. package/src/locales/vi/placeholders.ts +9 -1
  34. package/src/locales/vi/presets.ts +6 -0
  35. package/src/locales/vi/v2.ts +21 -0
  36. package/src/shared/panel-store.ts +3 -3
  37. package/src/shared/patterns.ts +3 -52
  38. package/src/shared/style-panel.tsx +2 -2
  39. package/src/shared/types.ts +2 -0
  40. package/src/v2/blocks/columns-inspector.tsx +210 -0
  41. package/src/v2/blocks/form.tsx +4 -4
  42. package/src/v2/blocks/index.ts +10 -4
  43. package/src/v2/blocks/inline-style.ts +1 -1
  44. package/src/v2/blocks/layout.tsx +173 -42
  45. package/src/v2/blocks/media.tsx +22 -13
  46. package/src/v2/blocks/resize.tsx +172 -4
  47. package/src/v2/blocks/text.tsx +14 -7
  48. package/src/v2/blocks/theme.tsx +10 -5
  49. package/src/v2/blocks/tools.tsx +50 -5
  50. package/src/v2/blocks/widgets.tsx +44 -16
  51. package/src/v2/canvas/block-list.tsx +17 -2
  52. package/src/v2/canvas/canvas-css.ts +54 -4
  53. package/src/v2/canvas/canvas.tsx +20 -3
  54. package/src/v2/canvas/dnd.ts +34 -3
  55. package/src/v2/canvas/move-animation.ts +94 -0
  56. package/src/v2/canvas/spacing-viz.ts +51 -0
  57. package/src/v2/core/block-presets.ts +68 -0
  58. package/src/v2/core/host.ts +5 -0
  59. package/src/v2/core/structure.ts +2 -1
  60. package/src/v2/editor.css +238 -9
  61. package/src/v2/editor.tsx +8 -2
  62. package/src/v2/ui/attr-form.tsx +40 -11
  63. package/src/v2/ui/attr-hints.ts +104 -6
  64. package/src/v2/ui/background-panel.tsx +65 -21
  65. package/src/v2/ui/block-icons.tsx +152 -0
  66. package/src/v2/ui/block-menu.ts +22 -0
  67. package/src/v2/ui/block-style-panel.tsx +14 -3
  68. package/src/v2/ui/color-field.tsx +74 -9
  69. package/src/v2/ui/divider-panel.tsx +58 -0
  70. package/src/v2/ui/group-width.tsx +38 -0
  71. package/src/v2/ui/icon-picker.tsx +51 -0
  72. package/src/v2/ui/inserter.tsx +51 -7
  73. package/src/v2/ui/inspector.tsx +48 -16
  74. package/src/v2/ui/layout-panel.tsx +5 -47
  75. package/src/v2/ui/list-view.tsx +81 -7
  76. package/src/v2/ui/motion-panel.tsx +2 -1
  77. package/src/v2/ui/parts-panel.tsx +164 -0
  78. package/src/v2/ui/pattern-library.tsx +228 -0
  79. package/src/v2/ui/preset-bar.tsx +83 -0
  80. package/src/v2/ui/style-controls.tsx +65 -15
  81. package/src/v2/ui/style-supports.ts +1 -1
  82. package/src/v2/ui/style-tab.tsx +127 -41
  83. package/src/v2/ui/toolbar.tsx +52 -13
  84. package/src/v2/ui/unit-controls.tsx +88 -39
  85. package/src/locales/en/patterns.ts +0 -50
  86. package/src/locales/vi/patterns.ts +0 -50
  87. package/src/shared/patterns-kit.ts +0 -7
  88. package/src/shared/patterns-library.ts +0 -172
@@ -1,22 +1,87 @@
1
+ import { useEffect, useRef, useState } from "react";
1
2
  import { ColorSwatchInput } from "../../shared/color-swatch";
2
3
  import { useEditor } from "../context";
4
+ import { useMsgs } from "../i18n";
3
5
 
4
6
  const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
5
7
 
6
8
  // Theme không khai màu thì website dùng các màu mặc định này (core CSS) — vẫn cho chọn, như bản soạn cũ (shared/style-panel.tsx COLORS)
7
- const DEFAULT_COLORS = { primary: "#2563eb", muted: "#6b7280", surface: "#f4f4f5", white: "#ffffff", black: "#111111" };
9
+ const DEFAULT_COLORS = { primary: "#1a597b", muted: "#5d6a75", surface: "#f3f4f6", white: "#ffffff", black: "#111111" };
8
10
 
9
- /** Ô màu: preset của theme + bảng chọn màu + bỏ màu. */
10
- export function ColorInput({ value, onChange, label }: { value?: string; onChange(v: string | undefined): void; label: string }) {
11
+ /** Tách giá trị màu thành màu gốc + độ đậm 1–100: `primary/40` → primary 40; `#1a597bcc` → #1a597b 80; còn lại (rgb / hsl / tên) → đậm 100, không chỉnh được. */
12
+ export function splitAlpha(v?: string): { base?: string; alpha: number; editable: boolean } {
13
+ if (!v) return { alpha: 100, editable: false };
14
+ const m = /^([a-z][a-z0-9-]{0,30})\/([1-9]\d?)$/.exec(v);
15
+ if (m) return { base: m[1], alpha: Number(m[2]), editable: true };
16
+ if (/^#[0-9a-f]{8}$/i.test(v)) return { base: v.slice(0, 7), alpha: Math.round((parseInt(v.slice(7), 16) / 255) * 100), editable: true };
17
+ if (/^#[0-9a-f]{6}$/i.test(v) || /^#[0-9a-f]{3}$/i.test(v)) return { base: v, alpha: 100, editable: true };
18
+ if (/^[a-z][a-z0-9-]{0,30}$/.test(v)) return { base: v, alpha: 100, editable: true };
19
+ return { base: v, alpha: 100, editable: false };
20
+ }
21
+ /** Ghép lại: preset → `name/NN`, hex → #rrggbbaa; đậm 100 → bỏ phần độ đậm. */
22
+ export function joinAlpha(base: string, alpha: number): string {
23
+ const a = Math.min(100, Math.max(1, Math.round(alpha)));
24
+ if (a >= 100) return base;
25
+ if (/^#[0-9a-f]{3}$/i.test(base)) base = "#" + [...base.slice(1)].map((c) => c + c).join("");
26
+ if (/^#[0-9a-f]{6}$/i.test(base)) return base + Math.round((a / 100) * 255).toString(16).padStart(2, "0");
27
+ return `${base}/${a}`;
28
+ }
29
+
30
+ export function useSiteColors(): Record<string, string> {
11
31
  const { host } = useEditor();
12
32
  const declared = host.presets?.colors;
13
- const colorMap: Record<string, string> = declared && Object.keys(declared).length ? declared : DEFAULT_COLORS;
14
- const presets = Object.entries(colorMap);
33
+ return declared && Object.keys(declared).length ? declared : DEFAULT_COLORS;
34
+ }
35
+
36
+ /**
37
+ * Ô màu gọn: một dòng [chấm màu] tên ô … tên màu. Bấm mở bảng: màu của website (đổi bảng màu website là cả trang đổi theo),
38
+ * màu tự chọn, về mặc định. Thay cho lưới chấm màu luôn mở (tốn chỗ khi khối có nhiều ô màu).
39
+ */
40
+ export function ColorInput({ value, onChange, label }: { value?: string; onChange(v: string | undefined): void; label: string }) {
41
+ const colors = useSiteColors();
42
+ const t = useMsgs("controls");
43
+ const [open, setOpen] = useState(false);
44
+ const ref = useRef<HTMLDivElement>(null);
45
+ useEffect(() => {
46
+ if (!open) return;
47
+ const out = (e: MouseEvent) => { if (!ref.current?.contains(e.target as Node)) setOpen(false); };
48
+ const esc = (e: KeyboardEvent) => { if (e.key === "Escape") { e.stopPropagation(); setOpen(false); } };
49
+ document.addEventListener("mousedown", out, true); document.addEventListener("keydown", esc, true);
50
+ return () => { document.removeEventListener("mousedown", out, true); document.removeEventListener("keydown", esc, true); };
51
+ }, [open]);
52
+ const { base, alpha, editable } = splitAlpha(value);
53
+ const baseCss = base ? colors[base] ?? base : undefined;
54
+ // Xem trước có độ đậm: trộn màu gốc với trong suốt (cùng công thức website dùng)
55
+ const css = baseCss ? (alpha < 100 ? `color-mix(in srgb, ${baseCss} ${alpha}%, transparent)` : baseCss) : undefined;
15
56
  return (
16
- <div className="ecx-chip-row">
17
- {presets.map(([name, c]) => <button key={name} type="button" className={cx("ecx-chip ecx-chip-swatch", value === name && "is-active")} title={name} aria-label={`${label}: ${name}`} style={{ background: c }} onClick={() => onChange(value === name ? undefined : name)} />)}
18
- <ColorSwatchInput value={value && (colorMap[value] ?? value)} onChange={onChange} label={label} size={28} />
19
- {value && <button type="button" className="ecx-chip" onClick={() => onChange(undefined)}>×</button>}
57
+ <div className="ecx-color-field" ref={ref}>
58
+ <button type="button" className={cx("ecx-color-row-btn", open && "is-open")} aria-haspopup="dialog" aria-expanded={open} onClick={() => setOpen(!open)}>
59
+ <span className={cx("ecx-color-dot", !css && "is-none")} style={css ? { background: css } : undefined} />
60
+ <span className="ecx-color-name">{label}</span>
61
+ <span className="ecx-color-value">{value ? (alpha < 100 ? `${(colors[base ?? ""] ? base : (base ?? "").toUpperCase())} · ${alpha}%` : colors[value] ? value : value.toUpperCase()) : t.noColor}</span>
62
+ </button>
63
+ {open && (
64
+ <div className="ecx-color-pop" role="dialog" aria-label={label}>
65
+ <div className="ecx-pop-title">{t.siteColors}</div>
66
+ <div className="ecx-color-grid">
67
+ {Object.entries(colors).map(([name, c]) => (
68
+ <button key={name} type="button" className={cx("ecx-color-cell", base === name && "is-active")} title={name} aria-label={`${label}: ${name}`} aria-pressed={base === name}
69
+ style={{ background: c }} onClick={() => { onChange(alpha < 100 ? joinAlpha(name, alpha) : name); setOpen(false); }} />
70
+ ))}
71
+ </div>
72
+ <label className="ecx-color-alpha">
73
+ <span>{t.colorOpacity}</span>
74
+ <input type="range" min={1} max={100} step={1} value={alpha} disabled={!value || !editable} aria-label={`${label}: ${t.colorOpacity}`}
75
+ onChange={(e) => base && onChange(joinAlpha(base, Number(e.target.value)))} />
76
+ <output>{alpha}%</output>
77
+ </label>
78
+ <p className="ecx-pop-hint">{t.colorHint}</p>
79
+ <div className="ecx-pop-foot">
80
+ <span className="ecx-pop-custom"><ColorSwatchInput value={baseCss && /^#[0-9a-f]{6}$/i.test(baseCss) ? baseCss : baseCss} onChange={(v) => onChange(alpha < 100 ? joinAlpha(v, alpha) : v)} label={`${label}: ${t.customColor}`} size={24} /> {t.customColor}</span>
81
+ {value && <button type="button" className="ecx-link-btn" onClick={() => { onChange(undefined); setOpen(false); }}>{t.clearColor}</button>}
82
+ </div>
83
+ </div>
84
+ )}
20
85
  </div>
21
86
  );
22
87
  }
@@ -0,0 +1,58 @@
1
+ import { DIVIDER_PATHS, DIVIDER_SHAPES, normalizeStyle, type BlockDivider, type BlockStyle } from "@ecomcx/ecomweb-content";
2
+ import { useMsgs } from "../i18n";
3
+ import { ColorInput } from "./color-field";
4
+ import { Row, Section, cx } from "./style-controls";
5
+
6
+ type Side = "top" | "bottom";
7
+
8
+ /**
9
+ * Đường chia trên / dưới của Nhóm (tab Cài đặt): hình tự vẽ (sóng, vòm, vát, tam giác, răng cưa) tô màu của khối kế bên.
10
+ * Ghi vào style.divider; chọn hình là bật, "Không" là tắt.
11
+ */
12
+ export function DividerSection({ attrs, setAttrs }: { attrs: Record<string, unknown>; setAttrs(a: Record<string, unknown>): void }) {
13
+ const t = useMsgs("layout") as Record<string, string>;
14
+ const style = (normalizeStyle(attrs.style) ?? {}) as BlockStyle;
15
+ const div = style.divider ?? {};
16
+ const commit = (next: BlockStyle["divider"]) => setAttrs({ style: normalizeStyle({ ...style, divider: next }) ?? undefined });
17
+ const patch = (side: Side, p: Partial<BlockDivider> | null) => {
18
+ const cur = div[side];
19
+ const nextSide = p === null ? undefined : ({ color: "white", ...cur, ...p } as BlockDivider);
20
+ const next = { ...div, [side]: nextSide };
21
+ if (!next.top) delete next.top;
22
+ if (!next.bottom) delete next.bottom;
23
+ commit(Object.keys(next).length ? next : undefined);
24
+ };
25
+ const side = (s: Side) => {
26
+ const d = div[s];
27
+ return (
28
+ <div className="ecx-divider-side" data-ecx-divider={s} key={s}>
29
+ <Row label={s === "top" ? t.dividerTop : t.dividerBottom}>
30
+ <div role="radiogroup" aria-label={s === "top" ? t.dividerTop : t.dividerBottom} className="ecx-divider-shapes">
31
+ <button type="button" role="radio" aria-checked={!d} className={cx("ecx-divider-shape", !d && "is-active")} onClick={() => patch(s, null)}>{t.dividerNone}</button>
32
+ {DIVIDER_SHAPES.map((shape) => (
33
+ <button key={shape} type="button" role="radio" aria-checked={d?.shape === shape} aria-label={t[`divider_${shape}`]} title={t[`divider_${shape}`]} className={cx("ecx-divider-shape", d?.shape === shape && "is-active")} onClick={() => patch(s, { shape })}>
34
+ <svg viewBox="0 0 1200 100" preserveAspectRatio="none" aria-hidden="true"><path d={DIVIDER_PATHS[shape]} fill="currentColor" transform={s === "top" ? "matrix(1 0 0 -1 0 100)" : undefined} /></svg>
35
+ </button>
36
+ ))}
37
+ </div>
38
+ </Row>
39
+ {d && (
40
+ <>
41
+ <ColorInput label={t.dividerColor} value={d.color} onChange={(c) => patch(s, { color: c ?? "white" })} />
42
+ <Row label={`${t.dividerHeight}: ${d.height ?? 80}px`}>
43
+ <input type="range" className="ecx-range" min={10} max={300} step={5} aria-label={t.dividerHeight} value={d.height ?? 80} onChange={(e) => patch(s, { height: Number(e.target.value) })} />
44
+ </Row>
45
+ <label className="ecx-check"><input type="checkbox" checked={!!d.flip} onChange={(e) => patch(s, { flip: e.target.checked ? true : undefined })} /> {t.dividerFlip}</label>
46
+ </>
47
+ )}
48
+ </div>
49
+ );
50
+ };
51
+ return (
52
+ <Section title={t.dividerTitle} modified={!!(div.top || div.bottom)} onReset={() => commit(undefined)} defaultOpen={div.top || div.bottom ? true : undefined}>
53
+ {side("top")}
54
+ {side("bottom")}
55
+ <p className="ecx-muted">{t.dividerHelp}</p>
56
+ </Section>
57
+ );
58
+ }
@@ -0,0 +1,38 @@
1
+ import { useMsgs } from "../i18n";
2
+ import { Row, Section, Seg } from "./style-controls";
3
+ import { UnitInput } from "./unit-controls";
4
+
5
+ type Mode = "fill" | "site" | "custom";
6
+
7
+ /**
8
+ * Độ rộng của Nhóm ở tab Cài đặt (thay cho nút "Độ rộng" rời + ô tích "giữ chữ theo bề rộng cột chữ"):
9
+ * độ rộng của khối (nội dung / rộng / đầy màn) và độ rộng nội dung bên trong (hết khối / theo website / tự nhập số).
10
+ */
11
+ export function GroupWidthSection({ attrs, setAttrs }: { attrs: Record<string, unknown>; setAttrs(a: Record<string, unknown>): void }) {
12
+ const t = useMsgs("layout") as Record<string, string>;
13
+ const align = attrs.align === "wide" || attrs.align === "full" ? (attrs.align as string) : "content";
14
+ const custom = typeof attrs.contentWidth === "string" && attrs.contentWidth !== "";
15
+ const mode: Mode = custom ? "custom" : attrs.constrained === true ? "site" : "fill";
16
+ const setMode = (m: Mode | undefined) => {
17
+ if (m === "custom") setAttrs({ contentWidth: String(attrs.contentWidth || "900px"), constrained: undefined });
18
+ else setAttrs({ contentWidth: undefined, constrained: m === "site" ? true : undefined });
19
+ };
20
+ return (
21
+ <Section title={t.groupWidth} defaultOpen>
22
+ <Row label={t.blockWidth}>
23
+ <Seg label={t.blockWidth} value={align} onChange={(v) => setAttrs({ align: v === "wide" || v === "full" ? v : undefined })}
24
+ options={[["content", t.bwContent, t.bwContent], ["wide", t.bwWide, t.bwWide], ["full", t.bwFull, t.bwFull]]} />
25
+ </Row>
26
+ <Row label={t.contentWidth}>
27
+ <Seg<Mode> label={t.contentWidth} value={mode} onChange={setMode}
28
+ options={[["fill", t.cwFill, t.cwFill], ["site", t.cwSite, t.cwSite], ["custom", t.cwCustom, t.cwCustom]]} />
29
+ </Row>
30
+ {custom && (
31
+ <Row label={t.cwValue} onReset={() => setAttrs({ contentWidth: undefined })}>
32
+ <UnitInput label={t.cwValue} value={String(attrs.contentWidth)} max={1600} units={["px", "rem", "%"]} onChange={(v) => setAttrs({ contentWidth: v })} />
33
+ </Row>
34
+ )}
35
+ <p className="ecx-muted">{t.cwHelp}</p>
36
+ </Section>
37
+ );
38
+ }
@@ -0,0 +1,51 @@
1
+ import { ICON_NAMES, ICON_PATHS } from "@ecomcx/ecomweb-content";
2
+ import { ChevronDown, X } from "lucide-react";
3
+ import { useEffect, useMemo, useRef, useState } from "react";
4
+ import { useMsgs } from "../i18n";
5
+ import { cx } from "./style-controls";
6
+
7
+ const Svg = ({ name, size = 20 }: { name: string; size?: number }) => (
8
+ <svg viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d={ICON_PATHS[name]} /></svg>
9
+ );
10
+
11
+ /**
12
+ * Ô chọn icon: ô hiện icon đang chọn + mũi tên; bấm mở lưới icon có ô tìm (như bảng chọn icon của các bộ khối lớn).
13
+ * `allowNone`: có lựa chọn "Không có icon" (vd nút).
14
+ */
15
+ export function IconPicker({ value, onChange, label, allowNone }: { value?: string; onChange(v: string | undefined): void; label: string; allowNone?: boolean }) {
16
+ const t = useMsgs("controls");
17
+ const [open, setOpen] = useState(false);
18
+ const [q, setQ] = useState("");
19
+ const ref = useRef<HTMLDivElement>(null);
20
+ useEffect(() => {
21
+ if (!open) return;
22
+ const out = (e: MouseEvent) => { if (!ref.current?.contains(e.target as Node)) setOpen(false); };
23
+ const esc = (e: KeyboardEvent) => { if (e.key === "Escape") { e.stopPropagation(); setOpen(false); } };
24
+ document.addEventListener("mousedown", out, true); document.addEventListener("keydown", esc, true);
25
+ return () => { document.removeEventListener("mousedown", out, true); document.removeEventListener("keydown", esc, true); };
26
+ }, [open]);
27
+ const names = useMemo(() => { const k = q.trim().toLowerCase(); return (ICON_NAMES as readonly string[]).filter((n) => !k || n.toLowerCase().includes(k)); }, [q]);
28
+ const has = !!value && !!ICON_PATHS[value];
29
+ return (
30
+ <div className="ecx-icon-picker" ref={ref}>
31
+ <button type="button" className={cx("ecx-icon-picker-btn", open && "is-open")} aria-haspopup="dialog" aria-expanded={open} aria-label={label} onClick={() => setOpen(!open)}>
32
+ {has ? <Svg name={value!} size={22} /> : <span className="ecx-muted">{t.noIcon}</span>}
33
+ <span className="ecx-icon-picker-name">{has ? value : ""}</span>
34
+ <ChevronDown className="ecx-icon" />
35
+ </button>
36
+ {open && (
37
+ // preventDefault: ô này nằm trong <label> của form — không chặn thì bấm trong bảng kích lại nút mở (bảng đóng rồi mở lại)
38
+ <div className="ecx-icon-pop" role="dialog" aria-label={label} onClick={(e) => e.preventDefault()}>
39
+ <input className="ecx-input" autoFocus placeholder={t.searchIcons} value={q} onChange={(e) => setQ(e.target.value)} />
40
+ <div className="ecx-icon-grid" role="listbox" aria-label={label}>
41
+ {allowNone && <button type="button" role="option" aria-selected={!has} title={t.noIcon} className={cx("ecx-icon-cell", !has && "is-active")} onClick={() => { onChange(undefined); setOpen(false); }}><X className="ecx-icon" /></button>}
42
+ {names.map((n) => (
43
+ <button key={n} type="button" role="option" aria-selected={value === n} title={n} className={cx("ecx-icon-cell", value === n && "is-active")} onClick={() => { onChange(n); setOpen(false); }}><Svg name={n} /></button>
44
+ ))}
45
+ </div>
46
+ {!names.length && <p className="ecx-pop-hint">{t.noIconFound}</p>}
47
+ </div>
48
+ )}
49
+ </div>
50
+ );
51
+ }
@@ -1,6 +1,10 @@
1
+ import { freshWithDefaults } from "../core/block-presets";
1
2
  import { leavesItem } from "../core/structure";
2
3
  import { blockDescription } from "./block-descriptions";
3
- import { Blocks, Sparkles } from "lucide-react";
4
+ import { Blocks, Sparkles, X } from "lucide-react";
5
+ import { mediaAttrs } from "./media-actions";
6
+ import { cx } from "./attr-form";
7
+ import type { MediaItem } from "../../shared/types";
4
8
  import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ComponentType } from "react";
5
9
  import { norm } from "../../shared/util";
6
10
  import { useEditor, useUiTick, type InserterRequest } from "../context";
@@ -75,7 +79,7 @@ export function applyInsert(ctx: ReturnType<typeof useEditor>, req: InserterRequ
75
79
  ui.openAiWrite?.({ blockId: req.mode === "slash" ? req.blockId : undefined, docId: req.docId, parentId: req.parentId ?? null, index: req.index ?? 0 });
76
80
  return;
77
81
  }
78
- const node = opt.create();
82
+ const node = freshWithDefaults(opt.create());
79
83
  prefs.countInsert(opt.type);
80
84
  if (req.mode === "slash" && req.blockId) {
81
85
  const b = store.block(req.blockId);
@@ -247,7 +251,7 @@ export function InserterPanel({ onInserted, onClose }: { onInserted?(): void; on
247
251
  return () => { document.removeEventListener("keydown", onKey); frameDoc?.removeEventListener("keydown", onKey); };
248
252
  }, [onClose, ctx.ui]);
249
253
  const [query, setQuery] = useState("");
250
- const [tab, setTab] = useState<"blocks" | "patterns">("blocks");
254
+ const [tab, setTab] = useState<"blocks" | "patterns" | "media">("blocks");
251
255
  const [hover, setHover] = useState<{ o: InsertOption; rect: DOMRect; y: number } | null>(null);
252
256
  const results = rankOptions(options, query);
253
257
  const catLabel: Record<string, string> = { text: labels.catText, media: labels.catMedia, design: labels.catDesign, widgets: labels.catWidgets, theme: labels.catTheme, embed: labels.catEmbed };
@@ -258,7 +262,7 @@ export function InserterPanel({ onInserted, onClose }: { onInserted?(): void; on
258
262
  const lastInserted = useRef<string | null>(null);
259
263
  const groups = query ? [["", results] as const] : [...CATEGORY_ORDER, ...new Set(results.map((r) => r.category).filter((c) => !CATEGORY_ORDER.includes(c)))].map((c) => [c, results.filter((r) => r.category === c)] as const).filter(([, l]) => l.length);
260
264
  const insert = (o: InsertOption) => {
261
- const node = o.create();
265
+ const node = freshWithDefaults(o.create());
262
266
  ctx.prefs.countInsert(o.type);
263
267
  const cur = store.currentIds[store.currentIds.length - 1];
264
268
  // Đoạn trống đang chọn mà chính lần chèn trước vừa tạo thì giữ lại (chèn tiếp ra sau nó); đoạn trống của người dùng thì thay như WordPress
@@ -284,12 +288,17 @@ export function InserterPanel({ onInserted, onClose }: { onInserted?(): void; on
284
288
  <p>{hover.o.description ?? blockDescription(hover.o.type, labels.lang) ?? ""}</p>
285
289
  </div>
286
290
  )}
287
- <div className="ecx-tabs" role="tablist">
291
+ <div className="ecx-tabs">
292
+ <div className="ecx-tablist" role="tablist">
288
293
  <button type="button" role="tab" aria-selected={tab === "blocks"} className={tab === "blocks" ? "is-active" : undefined} onClick={() => setTab("blocks")}>{labels.blocks}</button>
289
294
  <button type="button" role="tab" aria-selected={tab === "patterns"} className={tab === "patterns" ? "is-active" : undefined} onClick={() => setTab("patterns")}>{labels.patterns}</button>
295
+ {ctx.host.media?.list && <button type="button" role="tab" aria-selected={tab === "media"} className={tab === "media" ? "is-active" : undefined} onClick={() => setTab("media")}>{labels.mediaTab}</button>}
296
+ </div>
297
+ {onClose && <button type="button" className="ecx-left-close" aria-label={labels.close} title={labels.close} onClick={onClose}><X className="ecx-icon" /></button>}
290
298
  </div>
291
- <input className="ecx-search" placeholder={labels.search} value={query} onChange={(e) => setQuery(e.target.value)} aria-label={labels.search} />
292
- {tab === "patterns" ? <PatternList query={query} onInserted={onInserted} /> : <>
299
+ <input className="ecx-search" placeholder={tab === "media" ? labels.searchMedia : labels.search} value={query} onChange={(e) => setQuery(e.target.value)} aria-label={tab === "media" ? labels.searchMedia : labels.search} />
300
+ {tab === "media" ? <MediaList query={query} onPick={(kind, m) => insert({ key: kind, title: kind, keywords: "", category: "media", type: kind, create: () => makeBlock(kind, { ...ctx.registry.create(kind).attrs, ...mediaAttrs(kind, [m]) }) })} />
301
+ : tab === "patterns" ? <PatternList query={query} onInserted={onInserted} /> : <>
293
302
  {mostUsed.length > 0 && (
294
303
  <section data-section="most-used">
295
304
  <h3 className="ecx-panel-heading">{labels.mostUsedTitle}</h3>
@@ -322,6 +331,41 @@ export function InserterPanel({ onInserted, onClose }: { onInserted?(): void; on
322
331
  );
323
332
  }
324
333
 
334
+ type MediaTabKind = "image" | "video" | "audio";
335
+ /** Tab Media: tệp mới nhất của thư viện theo loại; bấm = chèn khối Ảnh / Video / Âm thanh sau khối đang chọn. */
336
+ function MediaList({ query, onPick }: { query: string; onPick(kind: MediaTabKind, m: MediaItem): void }) {
337
+ const { host, labels } = useEditor();
338
+ const [kind, setKind] = useState<MediaTabKind>("image");
339
+ const [items, setItems] = useState<MediaItem[] | null>(null);
340
+ const [failed, setFailed] = useState(false);
341
+ useEffect(() => {
342
+ let live = true;
343
+ setItems(null); setFailed(false);
344
+ // Gõ tìm: chờ ngừng gõ rồi mới hỏi thư viện
345
+ const t = setTimeout(() => {
346
+ host.media!.list!({ kind, search: query.trim() || undefined }).then((l) => { if (live) setItems(l); }, () => { if (live) setFailed(true); });
347
+ }, query ? 250 : 0);
348
+ return () => { live = false; clearTimeout(t); };
349
+ }, [host.media, kind, query]);
350
+ const kinds: Array<[MediaTabKind, string]> = [["image", labels.image], ["video", "Video"], ["audio", labels.audio]];
351
+ return (
352
+ <>
353
+ <div className="ecx-seg is-text ecx-media-kinds" role="radiogroup" aria-label={labels.mediaTab}>
354
+ {kinds.map(([k, l]) => <button key={k} type="button" role="radio" aria-checked={kind === k} className={cx("ecx-seg-btn", kind === k && "is-active")} onClick={() => setKind(k)}>{l}</button>)}
355
+ </div>
356
+ {failed ? <p className="ecx-muted">{labels.loadFailed}</p> : !items ? <p className="ecx-muted">{labels.loading}</p> : !items.length ? <p className="ecx-muted">{labels.noResults}</p> : (
357
+ <div className={cx("ecx-media-grid", kind !== "image" && "is-files")}>
358
+ {items.map((m) => (
359
+ <button key={m.id} type="button" className="ecx-media-item" title={m.title || m.fileName} onClick={() => onPick(kind, m)}>
360
+ {kind === "image" ? <img src={m.sizes?.thumbnail?.url ?? m.sizes?.medium?.url ?? m.url} alt={m.alt || m.fileName} loading="lazy" /> : <span>{m.title || m.fileName}</span>}
361
+ </button>
362
+ ))}
363
+ </div>
364
+ )}
365
+ </>
366
+ );
367
+ }
368
+
325
369
  /** Mẫu (lõi, theme, plugin, người dùng tạo): bấm chèn sau khối đang chọn; mẫu đồng bộ chèn thành tham chiếu. */
326
370
  function PatternList({ query, onInserted, at }: { query: string; onInserted?(): void; at?: { docId: string; parentId: string | null; index: number } }) {
327
371
  const ctx = useEditor();
@@ -1,6 +1,6 @@
1
1
  import type { Device } from "@ecomcx/ecomweb-content";
2
- import { CORE_BLOCK_STYLES, controlValue, optionValue } from "@ecomcx/ecomweb-content";
3
- import { Blocks } from "lucide-react";
2
+ import { CONTAINER_TAGS, CORE_BLOCK_STYLES, controlValue, optionValue } from "@ecomcx/ecomweb-content";
3
+ import { Blocks, Info, LayoutPanelTop, Paintbrush, SlidersHorizontal } from "lucide-react";
4
4
  import { useState, useSyncExternalStore } from "react";
5
5
  import { blockPanelsFor, onBlockPanelsChange, type BlockPanel } from "../../shared/panel-store";
6
6
  import { useEditor, useEditorState, useUiTick } from "../context";
@@ -8,15 +8,26 @@ 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 { LayoutSection } from "./layout-panel";
12
+ import { GroupWidthSection } from "./group-width";
13
+ import { DividerSection } from "./divider-panel";
14
+ import { Row, Section, SectionGroup } from "./style-controls";
11
15
  import { BackgroundControl } from "./background-panel";
12
16
  import { BlockStyleSections } from "./block-style-panel";
17
+ import { PartsSections } from "./parts-panel";
18
+ import { PresetBar } from "./preset-bar";
19
+ import { blockControls } from "../../shared/panel-store";
13
20
  import { styleGroups } from "./style-supports";
14
21
  import { ColorInput } from "./color-field";
15
22
  import { UnitInput } from "./unit-controls";
16
23
  import { useMsgs } from "../i18n";
17
24
 
18
25
  /** 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"]);
26
+ // Nền của Nhóm / Cột nằm ở tab Kiểu dáng như bộ khối lớn; ảnh bìa: nền là nội dung chính nên ở Cài đặt
27
+ const BG_IN_SETTINGS = new Set(["cover", "group"]);
28
+ /** Khối chứa đổi được thẻ HTML (attrs.tagName). */
29
+ const TAGGED = new Set(["group", "column", "columns"]);
30
+ const BG_FIRST = new Set(["column", "columns", "row", "stack", "grid"]);
20
31
 
21
32
  /**
22
33
  * 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
@@ -42,6 +53,8 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
42
53
  const disabled = store.modeOf(first.id) === "disabled";
43
54
  const setAttrs = (a: Record<string, unknown>) => store.setAttrs(ids, a);
44
55
  const single = same && nodes.length === 1;
56
+ // Phần thay hẳn Kiểu chữ / Màu chung (khối ghép) — khối chỉ có phần phụ (tiêu đề: chữ tô sáng, liên kết) vẫn giữ mục chung
57
+ const hasParts = single && blockControls().some((c) => c.partsOnly && c.parts && (c.blocks === "*" || c.blocks.includes(first.type)));
45
58
  const Custom = single ? type?.inspector : undefined;
46
59
  const styled = type?.supports?.style !== false && !store.isContentOnly(first.id);
47
60
  const bindable = type?.bindable ?? CORE_BINDABLE[first.type];
@@ -50,44 +63,64 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
50
63
  <div className="ecx-inspector">
51
64
  <div className="ecx-block-card">
52
65
  <Icon className="ecx-icon ecx-card-icon" />
53
- <div><strong>{nodes.length > 1 ? `${nodes.length} ${labels.blocks}` : type?.title ?? first.type}</strong>{type?.description && nodes.length === 1 && <p className="ecx-muted">{type.description}</p>}</div>
66
+ <strong>{nodes.length > 1 ? `${nodes.length} ${labels.blocks}` : (typeof first.attrs.customName === "string" && first.attrs.customName) || (type?.title ?? first.type)}</strong>
67
+ {/* Mô tả khối: nút ⓘ (rê / bấm) thay cho 2–3 dòng chữ chiếm chỗ đầu bảng */}
68
+ {type?.description && nodes.length === 1 && <span className="ecx-card-info" tabIndex={0} role="note" aria-label={type.description} title={type.description}><Info className="ecx-icon" /><span className="ecx-card-tip">{type.description}</span></span>}
54
69
  </div>
70
+ {single && styled && !disabled && <PresetBar block={first} setAttrs={setAttrs} />}
55
71
  {disabled ? <p className="ecx-muted">{labels.readOnly}</p> : (
56
72
  <>
57
73
  <div className="ecx-tabs" role="tablist">
58
- <button type="button" role="tab" aria-selected={tab === "settings"} className={cx(tab === "settings" && "is-active")} onClick={() => setTab("settings")}>{labels.settings}</button>
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>}
74
+ <button type="button" role="tab" aria-selected={tab === "settings"} className={cx(tab === "settings" && "is-active")} onClick={() => setTab("settings")}><LayoutPanelTop className="ecx-icon" />{labels.settings}</button>
75
+ {styled && <button type="button" role="tab" aria-selected={tab === "style"} className={cx(tab === "style" && "is-active")} onClick={() => setTab("style")}><Paintbrush className="ecx-icon" />{t.styles}</button>}
76
+ {(styled || nodes.length === 1) && <button type="button" role="tab" aria-selected={tab === "advanced"} className={cx(tab === "advanced" && "is-active")} onClick={() => setTab("advanced")}><SlidersHorizontal className="ecx-icon" />{t.advanced}</button>}
61
77
  </div>
78
+ <SectionGroup key={`${first.id}:${tab}`}>
62
79
  {tab === "settings" || (tab === "style" && !styled) ? (
63
80
  <div className="ecx-panel">
81
+ {single && first.type === "group" && <GroupWidthSection attrs={first.attrs} setAttrs={setAttrs} />}
64
82
  {same && type && <AttrForm type={type} attrs={first.attrs} onChange={setAttrs} />}
65
83
  {styled && single && BG_IN_SETTINGS.has(first.type) && <BackgroundControl key={first.id} type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />}
84
+ {styled && single && first.type === "group" && <DividerSection key={`d${first.id}`} attrs={first.attrs} setAttrs={setAttrs} />}
85
+ {styled && single && <LayoutSection type={first.type} style={first.attrs.style} onChange={(st) => setAttrs({ style: st ?? undefined })} device={device} />}
66
86
  {Custom && <Custom block={first} attrs={first.attrs} setAttrs={setAttrs} blockProps={null as never} selected editable labels={labels} />}
67
87
  {same && nodes.length === 1 && <PluginPanels type={first.type} attrs={first.attrs} setAttrs={setAttrs} />}
68
88
  {nodes.length === 1 && bindable?.length && <BindingsPanel block={first} bindable={bindable} onChange={(b) => setAttrs({ bindings: b })} />}
69
89
  </div>
70
90
  ) : tab === "style" ? (
71
91
  <div className="ecx-panel">
92
+ {/* Khối chứa: Nền là mục đầu của tab Kiểu dáng (như bộ khối lớn) */}
93
+ {single && BG_FIRST.has(first.type) && <BackgroundControl key={first.id} type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />}
72
94
  <StyleTab type={first.type} style={first.attrs.style} onChange={(st) => setAttrs({ style: st ?? undefined })} device={device} onDeviceChange={setDevice} part="style"
73
95
  variants={variants.length ? variants : undefined} variant={(first.attrs.blockStyle as string) ?? null} onVariantChange={(v) => setAttrs({ blockStyle: v ?? undefined })}
96
+ parts={hasParts}
74
97
  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} />}
98
+ <PartsSections blockId={first.id} type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} />
99
+ <BlockStyleSections type={first.type} attrs={first.attrs} setAttrs={setAttrs} device={device} legacyOnly={hasParts} />
100
+ {!BG_IN_SETTINGS.has(first.type) && !BG_FIRST.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
101
  </>} />
78
102
  {single && <PluginPanels type={first.type} attrs={first.attrs} setAttrs={setAttrs} tab="style" />}
79
103
  </div>
80
104
  ) : (
81
105
  <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" />}
106
+ {styled && <StyleTab type={first.type} style={first.attrs.style} onChange={(st) => setAttrs({ style: st ?? undefined })} device={device} onDeviceChange={setDevice} part="advanced"
107
+ structure={single && TAGGED.has(first.type) && (
108
+ <Row label={t.htmlTag} onReset={first.attrs.tagName ? () => setAttrs({ tagName: undefined }) : undefined}>
109
+ <select className="ecx-input" aria-label={t.htmlTag} value={String(first.attrs.tagName ?? "div")} onChange={(e) => setAttrs({ tagName: e.target.value === "div" ? undefined : e.target.value })}>
110
+ {CONTAINER_TAGS.map((x) => <option key={x} value={x}>{x}</option>)}
111
+ </select>
112
+ </Row>
113
+ )} />}
83
114
  {nodes.length === 1 && (
84
- <div className="ecx-form">
115
+ <Section title={t.advanced} defaultOpen>
85
116
  <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>
86
117
  <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>
87
- </div>
118
+ </Section>
88
119
  )}
120
+ {nodes.length === 1 && <PluginPanels type={first.type} attrs={first.attrs} setAttrs={setAttrs} tab="advanced" />}
89
121
  </div>
90
122
  )}
123
+ </SectionGroup>
91
124
  </>
92
125
  )}
93
126
  </div>
@@ -95,7 +128,7 @@ export function Inspector({ blockStyles }: { blockStyles?: Record<string, Array<
95
128
  }
96
129
 
97
130
  /** Panel của plugin (registerBlockPanel) cho loại khối đang chọn. */
98
- function PluginPanels({ type, attrs, setAttrs, tab = "block" }: { type: string; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void; tab?: "block" | "style" }) {
131
+ function PluginPanels({ type, attrs, setAttrs, tab = "block" }: { type: string; attrs: Record<string, any>; setAttrs(a: Record<string, unknown>): void; tab?: "block" | "style" | "advanced" }) {
99
132
  const { host } = useEditor();
100
133
  useSyncExternalStore(onBlockPanelsChange, () => blockPanelsFor(type, tab).length, () => 0);
101
134
  const panels = blockPanelsFor(type, tab);
@@ -103,10 +136,9 @@ function PluginPanels({ type, attrs, setAttrs, tab = "block" }: { type: string;
103
136
  return (
104
137
  <>
105
138
  {panels.map((p) => (
106
- <details key={p.id} className="ecx-advanced" open>
107
- <summary>{host.translate ? host.translate(p.title) : p.title}</summary>
139
+ <Section key={p.id} title={host.translate ? host.translate(p.title) : p.title} defaultOpen={false}>
108
140
  {p.component ? <p.component type={type} attrs={attrs} setAttrs={setAttrs} /> : <ControlFields panel={p} attrs={attrs} setAttrs={setAttrs} />}
109
- </details>
141
+ </Section>
110
142
  ))}
111
143
  </>
112
144
  );
@@ -3,7 +3,6 @@ import { AlignCenterVertical, AlignEndVertical, AlignStartVertical, ArrowDown, A
3
3
  import { useState } from "react";
4
4
  import { useEditor } from "../context";
5
5
  import { useMsgs } from "../i18n";
6
- import { ColorInput } from "./color-field";
7
6
  import { Row, Section, Seg, cx } from "./style-controls";
8
7
 
9
8
  /**
@@ -11,7 +10,7 @@ import { Row, Section, Seg, cx } from "./style-controls";
11
10
  * Giá trị theo khổ (hướng, căn, số cột) sửa theo khổ đang chọn ở bảng Kiểu dáng (`device`).
12
11
  */
13
12
  /** Khối chứa (có khối con) mới có mục Bố cục. */
14
- const CONTAINERS = new Set(["group", "column", "cover", "blockquote", "callout", "details", "query", "postTemplate", "mediaText"]);
13
+ const CONTAINERS = new Set(["group", "cover", "blockquote", "callout", "details", "query", "postTemplate", "mediaText"]);
15
14
 
16
15
  type Kind = "flow" | "row" | "stack" | "grid";
17
16
  export const layoutKind = (l?: BlockLayout): Kind => (!l ? "flow" : l.type === "grid" ? "grid" : l.direction?.base === "column" ? "stack" : "row");
@@ -53,9 +52,8 @@ export function GradientField({ value, onChange }: { value?: string; onChange(g:
53
52
  );
54
53
  }
55
54
 
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 }) {
58
- const { labels, host } = useEditor();
55
+ /** Mục Bố cục của khối chứa (tab Cài đặt): nhóm / hàng ngang / xếp dọc / lưới, hướng, căn, số cột — theo khổ đang chọn. */
56
+ export function LayoutSection({ type, style: raw, onChange, device }: { type: string; style: unknown; onChange(style: BlockStyle | null): void; device: Device }) {
59
57
  const t = useMsgs("layout");
60
58
  const style: BlockStyle = normalizeStyle(raw) ?? {};
61
59
  const set = (patch: Partial<BlockStyle>) => {
@@ -73,12 +71,9 @@ export function LayoutEffectsPanel({ type, style: raw, onChange, device, effects
73
71
  return Object.keys(next).length ? next : undefined;
74
72
  };
75
73
 
76
- const shadows = ["sm", "md", "lg", "xl", ...Object.keys(host.presets?.shadows ?? {}).filter((s) => !["sm", "md", "lg", "xl"].includes(s))];
77
-
74
+ if (!CONTAINERS.has(type)) return null;
78
75
  return (
79
- <div className="ecx-layout-panel">
80
- {CONTAINERS.has(type) && (
81
- <Section title={t.layout}>
76
+ <Section title={t.layout} defaultOpen={l ? true : undefined}>
82
77
  <Row label={t.type}>
83
78
  <Seg<Kind> label={t.type} value={kind} onChange={(k) => set({ layout: layoutFor(k ?? "flow", l) })}
84
79
  options={[["flow", Square, t.flow], ["row", Columns3, t.row], ["stack", Rows3, t.stack], ["grid", LayoutGrid, t.grid]]} />
@@ -116,42 +111,5 @@ export function LayoutEffectsPanel({ type, style: raw, onChange, device, effects
116
111
  )}
117
112
  </>}
118
113
  </Section>
119
- )}
120
-
121
- {effects && <Section title={t.effects} defaultOpen={!!(style.gradient || style.shadow || style.aspectRatio || style.position)}>
122
- {gradient && <Row label={t.gradient}><GradientField value={style.gradient} onChange={(g) => set({ gradient: g })} /></Row>}
123
- <Row label={t.shadow}>
124
- <select className="ecx-input" aria-label={t.shadow} value={style.shadow ?? ""} onChange={(e) => set({ shadow: e.target.value || undefined })}>
125
- <option value="">—</option><option value="none">{t.none}</option>
126
- {shadows.map((s) => <option key={s} value={s}>{s.toUpperCase()}</option>)}
127
- </select>
128
- </Row>
129
- <Row label={t.ratio}>
130
- <select className="ecx-input" aria-label={t.ratio} value={style.aspectRatio ?? ""} onChange={(e) => set({ aspectRatio: e.target.value || undefined })}>
131
- <option value="">—</option>
132
- {["1/1", "4/3", "3/2", "16/9", "21/9", "3/4", "2/3", "9/16"].map((r) => <option key={r} value={r}>{r.replace("/", ":")}</option>)}
133
- </select>
134
- </Row>
135
- <label className="ecx-check"><input type="checkbox" checked={!!style.position} onChange={(e) => set({ position: e.target.checked ? { type: "sticky" } : undefined })} /> {t.sticky}</label>
136
- </Section>}
137
-
138
- {hover && <Section title={t.hover} defaultOpen={!!style.hover}>
139
- {(["text", "background"] as const).map((k) => (
140
- <Row key={k} label={t[k]}>
141
- <ColorInput label={t[k]} value={style.hover?.color?.[k]} onChange={(v) => set({ hover: { ...style.hover, color: { ...style.hover?.color, [k]: v } } })} />
142
- </Row>
143
- ))}
144
- <Row label={t.border}>
145
- <ColorInput label={t.border} value={style.hover?.border?.color} onChange={(v) => set({ hover: { ...style.hover, border: v ? { color: v } : undefined } })} />
146
- </Row>
147
- <Row label={t.shadow}>
148
- <select className="ecx-input" aria-label={`${t.hover} ${t.shadow}`} value={style.hover?.shadow ?? ""} onChange={(e) => set({ hover: { ...style.hover, shadow: e.target.value || undefined } })}>
149
- <option value="">—</option>{shadows.map((s) => <option key={s} value={s}>{s.toUpperCase()}</option>)}
150
- </select>
151
- </Row>
152
- <label className="ecx-check"><input type="checkbox" checked={!!style.hover?.lift} onChange={(e) => set({ hover: { ...style.hover, lift: e.target.checked || undefined } })} /> {t.lift}</label>
153
- </Section>}
154
- </div>
155
114
  );
156
115
  }
157
-