@ecomcx/ecomweb-editor 1.20.0 → 1.22.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 (69) hide show
  1. package/README.md +15 -0
  2. package/package.json +3 -3
  3. package/src/i18n/index.ts +74 -0
  4. package/src/index.ts +3 -1
  5. package/src/legacy/basic.tsx +8 -30
  6. package/src/legacy/dynamic.tsx +15 -39
  7. package/src/locales/en/attrs.ts +72 -0
  8. package/src/locales/en/bindings.ts +26 -0
  9. package/src/locales/en/block-desc.ts +53 -0
  10. package/src/locales/en/block-titles.ts +43 -0
  11. package/src/locales/en/blocks.ts +39 -0
  12. package/src/locales/en/controls.ts +18 -0
  13. package/src/locales/en/hints.ts +142 -0
  14. package/src/locales/en/index.ts +20 -0
  15. package/src/locales/en/layout.ts +37 -0
  16. package/src/locales/en/legacy-basic.ts +54 -0
  17. package/src/locales/en/legacy-dynamic.ts +73 -0
  18. package/src/locales/en/legacy.ts +67 -0
  19. package/src/locales/en/motion.ts +33 -0
  20. package/src/locales/en/pattern-lib.ts +151 -0
  21. package/src/locales/en/patterns.ts +45 -0
  22. package/src/locales/en/shortcuts.ts +19 -0
  23. package/src/locales/en/v2.ts +177 -0
  24. package/src/locales/vi/attrs.ts +72 -0
  25. package/src/locales/vi/bindings.ts +26 -0
  26. package/src/locales/vi/block-desc.ts +53 -0
  27. package/src/locales/vi/block-titles.ts +43 -0
  28. package/src/locales/vi/blocks.ts +39 -0
  29. package/src/locales/vi/controls.ts +18 -0
  30. package/src/locales/vi/hints.ts +142 -0
  31. package/src/locales/vi/index.ts +24 -0
  32. package/src/locales/vi/layout.ts +37 -0
  33. package/src/locales/vi/legacy-basic.ts +54 -0
  34. package/src/locales/vi/legacy-dynamic.ts +73 -0
  35. package/src/locales/vi/legacy.ts +67 -0
  36. package/src/locales/vi/motion.ts +33 -0
  37. package/src/locales/vi/pattern-lib.ts +151 -0
  38. package/src/locales/vi/patterns.ts +45 -0
  39. package/src/locales/vi/shortcuts.ts +19 -0
  40. package/src/locales/vi/v2.ts +177 -0
  41. package/src/shared/animation-store.ts +38 -0
  42. package/src/shared/labels.ts +11 -134
  43. package/src/shared/patterns-kit.ts +7 -0
  44. package/src/shared/patterns-library.ts +152 -0
  45. package/src/shared/patterns.ts +6 -32
  46. package/src/v2/blocks/index.ts +5 -11
  47. package/src/v2/blocks/inline-style.ts +30 -0
  48. package/src/v2/blocks/layout.tsx +84 -14
  49. package/src/v2/blocks/media.tsx +21 -17
  50. package/src/v2/blocks/theme.tsx +43 -22
  51. package/src/v2/canvas/canvas.tsx +9 -1
  52. package/src/v2/core/bindings.ts +9 -8
  53. package/src/v2/core/model.ts +2 -2
  54. package/src/v2/editor.tsx +7 -4
  55. package/src/v2/i18n.ts +14 -0
  56. package/src/v2/index.ts +3 -1
  57. package/src/v2/labels.ts +11 -348
  58. package/src/v2/ui/attr-form.tsx +14 -29
  59. package/src/v2/ui/attr-hints.ts +87 -74
  60. package/src/v2/ui/bindings.tsx +10 -12
  61. package/src/v2/ui/block-descriptions.ts +6 -33
  62. package/src/v2/ui/inserter.tsx +2 -2
  63. package/src/v2/ui/inspector.tsx +7 -5
  64. package/src/v2/ui/layout-panel.tsx +3 -14
  65. package/src/v2/ui/motion-panel.tsx +99 -0
  66. package/src/v2/ui/options.tsx +6 -13
  67. package/src/v2/ui/style-controls.tsx +7 -6
  68. package/src/v2/ui/style-tab.tsx +9 -4
  69. package/src/v2/ui/unit-controls.tsx +6 -5
@@ -2,6 +2,7 @@ import type { Device } from "@ecomcx/ecomweb-content";
2
2
  import { ChevronRight } from "lucide-react";
3
3
  import { useState, type ComponentType, type ReactNode } from "react";
4
4
  import { useEditor } from "../context";
5
+ import { useMsgs } from "../i18n";
5
6
 
6
7
  /** Thành phần chung của tab Kiểu dáng (cùng một giao diện cho mọi mục). */
7
8
  export const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
@@ -18,10 +19,10 @@ export function Seg<T extends string>({ value, options, onChange, label }: { val
18
19
  );
19
20
  }
20
21
  export function Row({ label, children, device }: { label: string; children: ReactNode; device?: Device }) {
21
- const { labels } = useEditor();
22
+ const t = useMsgs("controls");
22
23
  return (
23
24
  <div className="ecx-style-row">
24
- <span className="ecx-field-label">{label}{device && device !== "base" && <em className="ecx-device-tag">{device === "tablet" ? labels.lang === "vi" ? "Máy tính bảng" : "Tablet" : labels.lang === "vi" ? "Điện thoại" : "Mobile"}</em>}</span>
25
+ <span className="ecx-field-label">{label}{device && device !== "base" && <em className="ecx-device-tag">{device === "tablet" ? t.tablet : t.mobile}</em>}</span>
25
26
  {children}
26
27
  </div>
27
28
  );
@@ -36,19 +37,19 @@ export function Section({ title, children, more, defaultOpen = true, modified, o
36
37
  const { labels } = useEditor();
37
38
  const [open, setOpen] = useState(defaultOpen);
38
39
  const [showMore, setShowMore] = useState(!!moreOpen);
39
- const vi = labels.lang === "vi";
40
+ const t = useMsgs("controls");
40
41
  return (
41
42
  <section className="ecx-style-section">
42
43
  <div className="ecx-style-section-head">
43
44
  <button type="button" className="ecx-style-section-toggle" aria-expanded={open} onClick={() => setOpen(!open)}>
44
- <ChevronRight className={cx("ecx-icon ecx-icon-sm ecx-chevron", open && "is-open")} aria-hidden />{title}{modified && <span className="ecx-dot" aria-label={vi ? "đã chỉnh" : "modified"} />}
45
+ <ChevronRight className={cx("ecx-icon ecx-icon-sm ecx-chevron", open && "is-open")} aria-hidden />{title}{modified && <span className="ecx-dot" aria-label={t.modified} />}
45
46
  </button>
46
- {modified && onReset && <button type="button" className="ecx-link-btn" onClick={onReset}>{vi ? "Đặt lại" : "Reset"}</button>}
47
+ {modified && onReset && <button type="button" className="ecx-link-btn" onClick={onReset}>{t.reset}</button>}
47
48
  </div>
48
49
  {open && (
49
50
  <div className="ecx-style-section-body">
50
51
  {children}
51
- {more && (showMore || moreOpen ? more : <button type="button" className="ecx-link-btn ecx-more-btn" onClick={() => setShowMore(true)}>{vi ? "+ Thêm tuỳ chọn" : "+ More options"}</button>)}
52
+ {more && (showMore || moreOpen ? more : <button type="button" className="ecx-link-btn ecx-more-btn" onClick={() => setShowMore(true)}>{t.moreOptions}</button>)}
52
53
  </div>
53
54
  )}
54
55
  </section>
@@ -1,12 +1,14 @@
1
1
  import { normalizeStyle, type BlockStyle, type Device } from "@ecomcx/ecomweb-content";
2
2
  import { AlignCenter, AlignJustify, AlignLeft, AlignRight, Monitor, Smartphone, Tablet } from "lucide-react";
3
3
  import { useEffect, useState, type ReactNode } from "react";
4
- import { enLabels, viLabels, type EditorLabels } from "../../shared/labels";
4
+ import { labelsLegacy, type EditorLabels } from "../../shared/labels";
5
5
  import { useEditor } from "../context";
6
6
  import { ColorInput } from "./color-field";
7
7
  import { LayoutEffectsPanel } from "./layout-panel";
8
+ import { MotionPanel } from "./motion-panel";
8
9
  import { Section, Seg, cx } from "./style-controls";
9
10
  import { SpacingControl, UnitInput } from "./unit-controls";
11
+ import { useMsgs } from "../i18n";
10
12
 
11
13
  /**
12
14
  * Tab Kiểu dáng của khối (attrs.style, @ecomcx/ecomweb-content): một giao diện thống nhất cho chữ, màu, khoảng cách,
@@ -42,7 +44,8 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
42
44
  variants?: Array<{ name: string; label: string }>; variant?: string | null; onVariantChange?(v: string | null): void;
43
45
  }) {
44
46
  const { host, labels } = useEditor();
45
- const t = labels.lang === "vi" ? viLabels : enLabels;
47
+ const t = labelsLegacy(labels.lang);
48
+ const ct = useMsgs("controls");
46
49
  const presets = host.presets;
47
50
  const sizes = presets?.fontSizes ? Object.keys(presets.fontSizes) : SIZES;
48
51
  const spaces = presets?.spacing ? ["0", ...Object.keys(presets.spacing)] : SPACES;
@@ -133,8 +136,8 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
133
136
  <Section title={t.style_spacing} modified={has(SPACING)} onReset={() => reset(SPACING)} moreOpen={has(["gap", "width", "maxWidth", "minHeight"])}
134
137
  more={<>{(["gap", "width", "maxWidth", "minHeight"] as const).map((k) =>
135
138
  row(k, t[`style_${k}`], <ValueInput label={t[`style_${k}`]} value={get(k)} inherited={inherited(k)} check={ok(k)} placeholder={k === "gap" ? "md, 24px" : "100%, 640px, 60vh"} onCommit={(v) => set(k, v)} />))}</>}>
136
- <SpacingControl label={t.style_padding} steps={spaces} value={get("padding")} inherited={inherited("padding")} onChange={(v) => set("padding", v)} labels={{ vertical: labels.lang === "vi" ? "dọc" : "vertical", horizontal: labels.lang === "vi" ? "ngang" : "horizontal", link: t.linkSides, unlink: t.unlinkSides }} />
137
- <SpacingControl label={t.style_margin} steps={spaces} value={get("margin")} inherited={inherited("margin")} onChange={(v) => set("margin", v)} labels={{ vertical: labels.lang === "vi" ? "dọc" : "vertical", horizontal: labels.lang === "vi" ? "ngang" : "horizontal", link: t.linkSides, unlink: t.unlinkSides }} />
139
+ <SpacingControl label={t.style_padding} steps={spaces} value={get("padding")} inherited={inherited("padding")} onChange={(v) => set("padding", v)} labels={{ vertical: ct.vertical, horizontal: ct.horizontal, link: t.linkSides, unlink: t.unlinkSides }} />
140
+ <SpacingControl label={t.style_margin} steps={spaces} value={get("margin")} inherited={inherited("margin")} onChange={(v) => set("margin", v)} labels={{ vertical: ct.vertical, horizontal: ct.horizontal, link: t.linkSides, unlink: t.unlinkSides }} />
138
141
  </Section>
139
142
 
140
143
  <Section title={t.style_border} modified={has(["border", "radius"])} onReset={() => reset(["border", "radius"])} defaultOpen={has(["border", "radius"])}>
@@ -147,6 +150,8 @@ export function StyleTab({ type, style: raw, onChange, device, onDeviceChange, v
147
150
 
148
151
  <LayoutEffectsPanel type={type} style={raw} onChange={onChange} device={device} />
149
152
 
153
+ <MotionPanel type={type} style={raw} onChange={onChange} />
154
+
150
155
  <Section title={t.style_visibility} modified={has(["hide"])} onReset={() => reset(["hide"])} defaultOpen={has(["hide"])}>
151
156
  {(["desktop", "tablet", "mobile"] as const).map((d) => (
152
157
  <label key={d} className="ecx-check"><input type="checkbox" checked={!!style.hide?.includes(d)}
@@ -3,6 +3,7 @@ import { Link2, Link2Off, SlidersHorizontal } from "lucide-react";
3
3
  import { useEffect, useState } from "react";
4
4
  import { useEditor } from "../context";
5
5
  import { cx } from "./style-controls";
6
+ import { useMsgs } from "../i18n";
6
7
 
7
8
  /**
8
9
  * Điều khiển giá trị có đơn vị (cỡ viền, bo góc, khoảng cách…): ô số + chọn đơn vị + thanh kéo.
@@ -16,7 +17,7 @@ const parse = (v: unknown): { n: string; unit: string } | null => {
16
17
  };
17
18
 
18
19
  export function UnitInput({ value, onChange, label, max = 100, units = UNITS, slider = true }: { value?: string; onChange(v: string | undefined): void; label: string; max?: number; units?: string[]; slider?: boolean }) {
19
- const vi = useEditor().labels.lang === "vi";
20
+ const t = useMsgs("controls");
20
21
  const p = parse(value);
21
22
  const [n, setN] = useState(p?.n ?? "");
22
23
  const [unit, setUnit] = useState(p?.unit ?? units[0]);
@@ -28,11 +29,11 @@ export function UnitInput({ value, onChange, label, max = 100, units = UNITS, sl
28
29
  <div className="ecx-unit-input">
29
30
  <input type="number" inputMode="decimal" aria-label={label} value={n} placeholder={p ? undefined : value ?? ""} step={unit === "px" || unit === "%" ? 1 : 0.1}
30
31
  onChange={(e) => { setN(e.target.value); emit(e.target.value, unit); }} />
31
- <select aria-label={`${label}: ${vi ? "đơn vị" : "unit"}`} value={unit} onChange={(e) => { setUnit(e.target.value); if (n !== "") emit(n, e.target.value); }}>
32
+ <select aria-label={`${label}: ${t.unit}`} value={unit} onChange={(e) => { setUnit(e.target.value); if (n !== "") emit(n, e.target.value); }}>
32
33
  {units.map((u) => <option key={u} value={u}>{u}</option>)}
33
34
  </select>
34
35
  </div>
35
- {slider && <input type="range" className="ecx-unit-slider" aria-label={`${label}: ${vi ? "thanh kéo" : "slider"}`} min={0} max={sliderMax} step={unit === "px" || unit === "%" ? 1 : 0.1} value={n === "" ? 0 : Math.min(sliderMax, Number(n))}
36
+ {slider && <input type="range" className="ecx-unit-slider" aria-label={`${label}: ${t.slider}`} min={0} max={sliderMax} step={unit === "px" || unit === "%" ? 1 : 0.1} value={n === "" ? 0 : Math.min(sliderMax, Number(n))}
36
37
  onChange={(e) => { setN(e.target.value); emit(e.target.value, unit); }} />}
37
38
  </div>
38
39
  );
@@ -40,7 +41,7 @@ export function UnitInput({ value, onChange, label, max = 100, units = UNITS, sl
40
41
 
41
42
  /** Thanh kéo theo bậc preset + nút sang giá trị tuỳ chỉnh. */
42
43
  function StepSlider({ value, steps, onChange, label, sideIcon }: { value?: string; steps: string[]; onChange(v: string | undefined): void; label: string; sideIcon?: string }) {
43
- const vi = useEditor().labels.lang === "vi";
44
+ const t = useMsgs("controls");
44
45
  const isPreset = value === undefined || steps.includes(value);
45
46
  const [custom, setCustom] = useState(!isPreset);
46
47
  useEffect(() => { if (!isPreset) setCustom(true); }, [isPreset]);
@@ -57,7 +58,7 @@ function StepSlider({ value, steps, onChange, label, sideIcon }: { value?: strin
57
58
  <span className="ecx-step-value">{idx < 0 ? "—" : steps[idx].toUpperCase()}</span>
58
59
  </div>
59
60
  )}
60
- <button type="button" className={cx("ecx-tool", custom && "is-active")} aria-pressed={custom} title={custom ? (vi ? "Dùng cỡ có sẵn" : "Use presets") : (vi ? "Giá trị tuỳ chỉnh" : "Custom value")} aria-label={`${label}: ${custom ? (vi ? "dùng cỡ có sẵn" : "use presets") : (vi ? "giá trị tuỳ chỉnh" : "custom value")}`}
61
+ <button type="button" className={cx("ecx-tool", custom && "is-active")} aria-pressed={custom} title={custom ? (t.usePresets) : (t.customValue)} aria-label={`${label}: ${custom ? (t.usePresets2) : (t.customValue2)}`}
61
62
  onClick={() => { setCustom(!custom); if (custom && !isPreset) onChange(undefined); }}><SlidersHorizontal className="ecx-icon ecx-icon-sm" /></button>
62
63
  </div>
63
64
  );