@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.
- package/README.md +15 -0
- package/package.json +3 -3
- package/src/i18n/index.ts +74 -0
- package/src/index.ts +3 -1
- package/src/legacy/basic.tsx +8 -30
- package/src/legacy/dynamic.tsx +15 -39
- package/src/locales/en/attrs.ts +72 -0
- package/src/locales/en/bindings.ts +26 -0
- package/src/locales/en/block-desc.ts +53 -0
- package/src/locales/en/block-titles.ts +43 -0
- package/src/locales/en/blocks.ts +39 -0
- package/src/locales/en/controls.ts +18 -0
- package/src/locales/en/hints.ts +142 -0
- package/src/locales/en/index.ts +20 -0
- package/src/locales/en/layout.ts +37 -0
- package/src/locales/en/legacy-basic.ts +54 -0
- package/src/locales/en/legacy-dynamic.ts +73 -0
- package/src/locales/en/legacy.ts +67 -0
- package/src/locales/en/motion.ts +33 -0
- package/src/locales/en/pattern-lib.ts +151 -0
- package/src/locales/en/patterns.ts +45 -0
- package/src/locales/en/shortcuts.ts +19 -0
- package/src/locales/en/v2.ts +177 -0
- package/src/locales/vi/attrs.ts +72 -0
- package/src/locales/vi/bindings.ts +26 -0
- package/src/locales/vi/block-desc.ts +53 -0
- package/src/locales/vi/block-titles.ts +43 -0
- package/src/locales/vi/blocks.ts +39 -0
- package/src/locales/vi/controls.ts +18 -0
- package/src/locales/vi/hints.ts +142 -0
- package/src/locales/vi/index.ts +24 -0
- package/src/locales/vi/layout.ts +37 -0
- package/src/locales/vi/legacy-basic.ts +54 -0
- package/src/locales/vi/legacy-dynamic.ts +73 -0
- package/src/locales/vi/legacy.ts +67 -0
- package/src/locales/vi/motion.ts +33 -0
- package/src/locales/vi/pattern-lib.ts +151 -0
- package/src/locales/vi/patterns.ts +45 -0
- package/src/locales/vi/shortcuts.ts +19 -0
- package/src/locales/vi/v2.ts +177 -0
- package/src/shared/animation-store.ts +38 -0
- package/src/shared/labels.ts +11 -134
- package/src/shared/patterns-kit.ts +7 -0
- package/src/shared/patterns-library.ts +152 -0
- package/src/shared/patterns.ts +6 -32
- package/src/v2/blocks/index.ts +5 -11
- package/src/v2/blocks/inline-style.ts +30 -0
- package/src/v2/blocks/layout.tsx +84 -14
- package/src/v2/blocks/media.tsx +21 -17
- package/src/v2/blocks/theme.tsx +43 -22
- package/src/v2/canvas/canvas.tsx +9 -1
- package/src/v2/core/bindings.ts +9 -8
- package/src/v2/core/model.ts +2 -2
- package/src/v2/editor.tsx +7 -4
- package/src/v2/i18n.ts +14 -0
- package/src/v2/index.ts +3 -1
- package/src/v2/labels.ts +11 -348
- package/src/v2/ui/attr-form.tsx +14 -29
- package/src/v2/ui/attr-hints.ts +87 -74
- package/src/v2/ui/bindings.tsx +10 -12
- package/src/v2/ui/block-descriptions.ts +6 -33
- package/src/v2/ui/inserter.tsx +2 -2
- package/src/v2/ui/inspector.tsx +7 -5
- package/src/v2/ui/layout-panel.tsx +3 -14
- package/src/v2/ui/motion-panel.tsx +99 -0
- package/src/v2/ui/options.tsx +6 -13
- package/src/v2/ui/style-controls.tsx +7 -6
- package/src/v2/ui/style-tab.tsx +9 -4
- 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
|
|
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" ?
|
|
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
|
|
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={
|
|
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}>{
|
|
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)}>{
|
|
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>
|
package/src/v2/ui/style-tab.tsx
CHANGED
|
@@ -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 {
|
|
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
|
|
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:
|
|
137
|
-
<SpacingControl label={t.style_margin} steps={spaces} value={get("margin")} inherited={inherited("margin")} onChange={(v) => set("margin", v)} labels={{ vertical:
|
|
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
|
|
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}: ${
|
|
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}: ${
|
|
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
|
|
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 ? (
|
|
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
|
);
|