@ecomcx/ecomweb-editor 1.19.0 → 1.21.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 (71) 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 +7 -35
  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 +19 -14
  49. package/src/v2/blocks/media.tsx +22 -18
  50. package/src/v2/blocks/text.tsx +2 -1
  51. package/src/v2/blocks/theme.tsx +22 -19
  52. package/src/v2/canvas/canvas.tsx +9 -1
  53. package/src/v2/core/bindings.ts +9 -8
  54. package/src/v2/editor.css +15 -1
  55. package/src/v2/editor.tsx +7 -4
  56. package/src/v2/i18n.ts +14 -0
  57. package/src/v2/index.ts +3 -1
  58. package/src/v2/labels.ts +11 -340
  59. package/src/v2/ui/attr-form.tsx +14 -29
  60. package/src/v2/ui/attr-hints.ts +84 -54
  61. package/src/v2/ui/bindings.tsx +10 -12
  62. package/src/v2/ui/block-descriptions.ts +6 -33
  63. package/src/v2/ui/inserter.tsx +2 -2
  64. package/src/v2/ui/inspector.tsx +7 -5
  65. package/src/v2/ui/layout-panel.tsx +3 -14
  66. package/src/v2/ui/motion-panel.tsx +99 -0
  67. package/src/v2/ui/options.tsx +6 -13
  68. package/src/v2/ui/style-controls.tsx +7 -6
  69. package/src/v2/ui/style-tab.tsx +9 -4
  70. package/src/v2/ui/toolbar.tsx +10 -5
  71. 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)}
@@ -1,4 +1,4 @@
1
- import { AlignCenter, AlignLeft, AlignRight, ArrowUpLeft, Bold, ChevronDown, ChevronUp, Code, Copy, CopyPlus, GripVertical, IndentDecrease, IndentIncrease, Italic, Link2, Link2Off, MoreVertical, PanelTop, Strikethrough, Trash2, Underline, Ungroup, Group as GroupIcon, Blocks, ArrowUpToLine, ArrowDownToLine, Shapes, Lock } from "lucide-react";
1
+ import { AlignCenter, AlignLeft, AlignRight, ArrowUpLeft, Bold, ChevronDown, ChevronUp, Code, Copy, CopyPlus, GripVertical, IndentDecrease, IndentIncrease, Italic, Link2, Link2Off, MoreVertical, PanelTop, Strikethrough, Trash2, Underline, Ungroup, Group as GroupIcon, Blocks, ArrowUpToLine, ArrowDownToLine, Shapes, Lock, Subscript, Superscript, Highlighter } from "lucide-react";
2
2
  import { TextSelection } from "prosemirror-state";
3
3
  import type { EditorView } from "prosemirror-view";
4
4
  import { useEffect, useLayoutEffect, useRef, useState, type ComponentType, type ReactNode } from "react";
@@ -97,9 +97,10 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
97
97
  });
98
98
  const nodes = ids.map((id) => store.block(id)).filter(Boolean) as BNode[];
99
99
  const fixed = placement === "fixed";
100
+ const coarse = typeof matchMedia === "function" && matchMedia("(pointer: coarse)").matches;
100
101
  if (fixed !== fixedPref) return null;
101
102
  if (fixed && !nodes.length) return <span className="ecx-toolbar-hint">{labels.toolbarHint}</span>;
102
- if (!nodes.length || ui.drag || ui.inserter?.mode === "slash" || (ui.typing && !link && !fixed)) return null;
103
+ if (!nodes.length || ui.drag || ui.inserter?.mode === "slash" || (ui.typing && !link && !fixed && !coarse)) return null;
103
104
  const loc = store.locate(nodes[0].id);
104
105
  if (!loc || store.getState().docs[loc.docId].mode === "disabled") return null;
105
106
  const frame = ui.canvasFrame?.getBoundingClientRect();
@@ -117,7 +118,7 @@ export function BlockToolbar({ placement = "floating" }: { placement?: "floating
117
118
  const transforms = sameType ? (type?.transforms ?? []).filter((t) => nodes.length === 1 || t.multiple) : [];
118
119
  const height = 44;
119
120
  const top = fixed || !rect || !frame ? 0 : Math.round(Math.max(frame.top + 4, rect.top - height - 8));
120
- const left = fixed || !rect || !frame ? 0 : Math.round(Math.max(frame.left + 4, Math.min(rect.left, frame.right - 420)));
121
+ const left = fixed || !rect || !frame ? 0 : Math.round(Math.max(frame.left + 4, Math.min(rect.left, frame.right - Math.min(420, window.innerWidth - 8))));
121
122
  const editProps = { block: first, attrs: first.attrs, setAttrs: (a: Record<string, unknown>) => store.setAttrs(ids, a), blockProps: null as never, selected: true, editable: true, labels };
122
123
  const Extra = sameType && nodes.length === 1 ? type?.toolbar : undefined;
123
124
  const hasAlign = sameType && !!type?.attributes?.textAlign;
@@ -281,11 +282,15 @@ function MarkTools({ view, onLink }: { view: EditorView; onLink(): void }) {
281
282
  view.dispatch(tr);
282
283
  view.focus();
283
284
  };
284
- const tools: Array<[string, typeof Bold, string, string]> = [["bold", Bold, labels.bold, `${mod}B`], ["italic", Italic, labels.italic, `${mod}I`], ["underline", Underline, labels.underline, `${mod}U`], ["strike", Strikethrough, labels.strike, `${mod}⇧X`], ["code", Code, labels.code, `${mod}E`]];
285
+ const main: Array<[string, typeof Bold, string, string]> = [["bold", Bold, labels.bold, `${mod}B`], ["italic", Italic, labels.italic, `${mod}I`], ["underline", Underline, labels.underline, `${mod}U`]];
286
+ const more: Array<[string, typeof Bold, string]> = [["strike", Strikethrough, labels.strike], ["code", Code, labels.code], ["subscript", Subscript, labels.subscript], ["superscript", Superscript, labels.superscript], ["highlight", Highlighter, labels.highlight]];
285
287
  return (
286
288
  <div className="ecx-tool-group">
287
- {tools.map(([name, I, l, k]) => <ToolButton key={name} label={`${l} (${k})`} active={isActive(name)} onClick={() => toggle(name)}><I className="ecx-icon" /></ToolButton>)}
289
+ {main.map(([name, I, l, k]) => <ToolButton key={name} label={`${l} (${k})`} active={isActive(name)} onClick={() => toggle(name)}><I className="ecx-icon" /></ToolButton>)}
288
290
  <ToolButton label={`${labels.link} (${mod}K)`} active={isActive("link")} onClick={onLink}><Link2 className="ecx-icon" /></ToolButton>
291
+ <Dropdown label={labels.moreFormats} trigger={<ChevronDown className="ecx-icon ecx-icon-sm" />}>
292
+ {(close) => more.map(([name, I, l]) => <MenuItem key={name} icon={I} label={isActive(name) ? `✓ ${l}` : l} onClick={() => { close(); toggle(name); }} />)}
293
+ </Dropdown>
289
294
  </div>
290
295
  );
291
296
  }
@@ -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
  );