@ecomcx/ecomweb-editor 1.31.0 → 1.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/locales/en/attrs.ts +10 -0
- package/src/locales/en/background.ts +17 -0
- package/src/locales/en/bindings.ts +1 -1
- package/src/locales/en/block-desc.ts +2 -0
- package/src/locales/en/block-style.ts +7 -4
- package/src/locales/en/block-titles.ts +2 -0
- package/src/locales/en/blocks.ts +12 -3
- package/src/locales/en/columns.ts +12 -0
- package/src/locales/en/controls.ts +21 -0
- package/src/locales/en/hints.ts +289 -1
- package/src/locales/en/index.ts +5 -2
- package/src/locales/en/layout.ts +32 -0
- package/src/locales/en/legacy.ts +1 -1
- package/src/locales/en/library.ts +38 -0
- package/src/locales/en/parts.ts +12 -0
- package/src/locales/en/placeholders.ts +12 -1
- package/src/locales/en/presets.ts +6 -0
- package/src/locales/en/v2.ts +21 -0
- package/src/locales/vi/attrs.ts +10 -0
- package/src/locales/vi/background.ts +17 -0
- package/src/locales/vi/bindings.ts +1 -1
- package/src/locales/vi/block-desc.ts +2 -0
- package/src/locales/vi/block-style.ts +7 -4
- package/src/locales/vi/block-titles.ts +2 -0
- package/src/locales/vi/blocks.ts +12 -3
- package/src/locales/vi/columns.ts +12 -0
- package/src/locales/vi/controls.ts +21 -0
- package/src/locales/vi/hints.ts +290 -2
- package/src/locales/vi/index.ts +5 -2
- package/src/locales/vi/layout.ts +32 -0
- package/src/locales/vi/legacy.ts +1 -1
- package/src/locales/vi/library.ts +38 -0
- package/src/locales/vi/parts.ts +12 -0
- package/src/locales/vi/placeholders.ts +12 -1
- package/src/locales/vi/presets.ts +6 -0
- package/src/locales/vi/v2.ts +21 -0
- package/src/shared/panel-store.ts +3 -3
- package/src/shared/patterns.ts +3 -52
- package/src/shared/style-panel.tsx +2 -2
- package/src/shared/types.ts +2 -0
- package/src/v2/blocks/columns-inspector.tsx +210 -0
- package/src/v2/blocks/form.tsx +4 -4
- package/src/v2/blocks/index.ts +10 -4
- package/src/v2/blocks/inline-style.ts +1 -1
- package/src/v2/blocks/layout.tsx +211 -44
- package/src/v2/blocks/media.tsx +22 -13
- package/src/v2/blocks/resize.tsx +172 -4
- package/src/v2/blocks/text.tsx +14 -7
- package/src/v2/blocks/theme.tsx +63 -19
- package/src/v2/blocks/tools.tsx +50 -5
- package/src/v2/blocks/widgets.tsx +44 -16
- package/src/v2/canvas/block-list.tsx +23 -3
- package/src/v2/canvas/canvas-css.ts +70 -4
- package/src/v2/canvas/canvas.tsx +22 -5
- package/src/v2/canvas/dnd.ts +34 -3
- package/src/v2/canvas/move-animation.ts +94 -0
- package/src/v2/canvas/spacing-viz.ts +51 -0
- package/src/v2/core/block-presets.ts +68 -0
- package/src/v2/core/host.ts +6 -1
- package/src/v2/core/structure.ts +2 -1
- package/src/v2/editor.css +238 -9
- package/src/v2/editor.tsx +8 -2
- package/src/v2/ui/attr-form.tsx +59 -12
- package/src/v2/ui/attr-hints.ts +140 -9
- package/src/v2/ui/background-panel.tsx +65 -21
- package/src/v2/ui/bindings.tsx +3 -0
- package/src/v2/ui/block-icons.tsx +152 -0
- package/src/v2/ui/block-menu.ts +22 -0
- package/src/v2/ui/block-style-panel.tsx +14 -3
- package/src/v2/ui/color-field.tsx +74 -9
- package/src/v2/ui/divider-panel.tsx +58 -0
- package/src/v2/ui/group-width.tsx +38 -0
- package/src/v2/ui/icon-picker.tsx +51 -0
- package/src/v2/ui/inserter.tsx +61 -12
- package/src/v2/ui/inspector.tsx +48 -16
- package/src/v2/ui/layout-panel.tsx +5 -47
- package/src/v2/ui/list-view.tsx +81 -7
- package/src/v2/ui/motion-panel.tsx +2 -1
- package/src/v2/ui/parts-panel.tsx +164 -0
- package/src/v2/ui/pattern-library.tsx +228 -0
- package/src/v2/ui/preset-bar.tsx +83 -0
- package/src/v2/ui/style-controls.tsx +65 -15
- package/src/v2/ui/style-supports.ts +1 -1
- package/src/v2/ui/style-tab.tsx +127 -41
- package/src/v2/ui/toolbar.tsx +52 -13
- package/src/v2/ui/unit-controls.tsx +88 -39
- package/src/locales/en/patterns.ts +0 -50
- package/src/locales/vi/patterns.ts +0 -50
- package/src/shared/patterns-kit.ts +0 -7
- package/src/shared/patterns-library.ts +0 -172
package/src/shared/types.ts
CHANGED
|
@@ -30,6 +30,8 @@ export interface MediaProvider {
|
|
|
30
30
|
get?(id: MediaItem["id"]): Promise<MediaItem | null>;
|
|
31
31
|
/** Tải tệp lên thư viện media (nút "Tải lên", kéo thả tệp vào khối). Không có → chỉ chọn từ thư viện / URL. */
|
|
32
32
|
upload?(files: File[]): Promise<MediaItem[]>;
|
|
33
|
+
/** Tệp mới nhất trong thư viện (tab Media của bảng chèn khối). Không có → không hiện tab. */
|
|
34
|
+
list?(options: { kind: "image" | "video" | "audio"; search?: string }): Promise<MediaItem[]>;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
/** Nội dung lưu trữ: danh sách khối (sẵn sàng cho page builder). */
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { normalizeStyle, type BlockStyle, type Device } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { AlignCenter, AlignCenterHorizontal, AlignEndHorizontal, AlignHorizontalDistributeCenter, AlignHorizontalSpaceAround, AlignHorizontalSpaceBetween, AlignLeft, AlignRight, AlignStartHorizontal, ArrowDown, ArrowLeft, ArrowRight, ArrowUp, StretchHorizontal } from "lucide-react";
|
|
3
|
+
import type { CSSProperties } from "react";
|
|
4
|
+
import { useEditor } from "../context";
|
|
5
|
+
import type { BNode } from "../core/model";
|
|
6
|
+
import type { BlockEditProps } from "../core/registry";
|
|
7
|
+
import { useMsgs } from "../i18n";
|
|
8
|
+
import { Row, Section, Seg, cx } from "../ui/style-controls";
|
|
9
|
+
import { byStep } from "../ui/style-tab";
|
|
10
|
+
import { UnitInput } from "../ui/unit-controls";
|
|
11
|
+
import { DividerSection } from "../ui/divider-panel";
|
|
12
|
+
import { makeBlock } from "../core/model";
|
|
13
|
+
|
|
14
|
+
type Responsive<T> = T | Partial<Record<Device, T>>;
|
|
15
|
+
/** Đọc / ghi giá trị theo khổ (một giá trị trần = base). */
|
|
16
|
+
const atDevice = <T,>(v: Responsive<T> | undefined, d: Device): T | undefined => (v && typeof v === "object" && !Array.isArray(v) ? (v as Partial<Record<Device, T>>)[d] : d === "base" ? (v as T | undefined) : undefined);
|
|
17
|
+
function withDevice<T>(v: Responsive<T> | undefined, d: Device, x: T | undefined): Responsive<T> | undefined {
|
|
18
|
+
const map: Partial<Record<Device, T>> = v && typeof v === "object" && !Array.isArray(v) ? { ...(v as Partial<Record<Device, T>>) } : v !== undefined ? { base: v as T } : {};
|
|
19
|
+
if (x === undefined) delete map[d]; else map[d] = x;
|
|
20
|
+
const keys = Object.keys(map);
|
|
21
|
+
return !keys.length ? undefined : keys.length === 1 && keys[0] === "base" ? map.base : map;
|
|
22
|
+
}
|
|
23
|
+
/** Như withDevice nhưng luôn trả dạng { base, tablet, mobile } (kiểu Responsive của style). */
|
|
24
|
+
function mapDevice<T>(v: Responsive<T> | undefined, d: Device, x: T | undefined): Partial<Record<Device, T>> | undefined {
|
|
25
|
+
const r = withDevice(v, d, x);
|
|
26
|
+
return r === undefined ? undefined : r && typeof r === "object" && !Array.isArray(r) ? (r as Partial<Record<Device, T>>) : { base: r as T };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Bố cục có sẵn theo số cột (tỉ lệ %, tổng 100); "equal" = chia đều (không lưu độ rộng). */
|
|
30
|
+
export const LAYOUTS: Record<number, number[][]> = {
|
|
31
|
+
1: [[100]],
|
|
32
|
+
2: [[50, 50], [67, 33], [33, 67], [75, 25], [25, 75]],
|
|
33
|
+
3: [[33, 33, 34], [50, 25, 25], [25, 25, 50], [25, 50, 25], [20, 60, 20], [15, 70, 15]],
|
|
34
|
+
4: [[25, 25, 25, 25], [40, 20, 20, 20], [20, 20, 20, 40]],
|
|
35
|
+
5: [[20, 20, 20, 20, 20]],
|
|
36
|
+
6: [[17, 17, 17, 17, 16, 16]],
|
|
37
|
+
};
|
|
38
|
+
const equalOf = (w: number[]) => w.every((x) => Math.abs(x - w[0]) <= 1);
|
|
39
|
+
/** Độ rộng hiện tại của các cột (cột không đặt = chia đều phần còn lại). */
|
|
40
|
+
export function widthsOf(cols: BNode[]): number[] {
|
|
41
|
+
const set = cols.map((c) => Number(c.attrs.width) || 0);
|
|
42
|
+
const free = cols.filter((_, i) => !set[i]).length;
|
|
43
|
+
const rest = Math.max(0, 100 - set.reduce((a, b) => a + b, 0));
|
|
44
|
+
return set.map((w) => w || (free ? rest / free : 0));
|
|
45
|
+
}
|
|
46
|
+
const same = (a: number[], b: number[]) => a.length === b.length && a.every((x, i) => Math.abs(x - b[i]) <= 1.5);
|
|
47
|
+
|
|
48
|
+
function Thumb({ widths, stack, active, onClick, title }: { widths: number[]; stack?: "column" | "column-reverse"; active: boolean; onClick(): void; title: string }) {
|
|
49
|
+
return (
|
|
50
|
+
<button type="button" className={cx("ecx-layout-thumb", stack && "is-stack", active && "is-active")} title={title} aria-label={title} aria-pressed={active} onClick={onClick}>
|
|
51
|
+
{(stack === "column-reverse" ? [...widths].reverse() : widths).map((w, i) => <i key={i} style={{ flex: stack ? undefined : w } as CSSProperties} data-n={stack === "column-reverse" ? widths.length - i : i + 1} />)}
|
|
52
|
+
</button>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Tab Cài đặt của Bộ cột (như khối Hàng của bộ khối lớn): số cột, bố cục theo khổ màn hình (máy tính: tỉ lệ cột; máy tính bảng / điện thoại:
|
|
58
|
+
* như khổ lớn hơn, hàng ngang, xếp dọc, xếp dọc đảo), khe cột / khe hàng theo bậc, căn dọc các cột.
|
|
59
|
+
*/
|
|
60
|
+
export function ColumnsInspector({ block, attrs, setAttrs }: BlockEditProps) {
|
|
61
|
+
const { store, ui, host } = useEditor();
|
|
62
|
+
const t = useMsgs("columns");
|
|
63
|
+
const device: Device = ui.device === "desktop" ? "base" : ui.device;
|
|
64
|
+
const cols = block.content ?? [];
|
|
65
|
+
const n = cols.length;
|
|
66
|
+
const widths = widthsOf(cols);
|
|
67
|
+
const spaces = host.presets?.spacing ? ["0", ...byStep(Object.keys(host.presets.spacing))] : ["0", "xs", "sm", "md", "lg", "xl"];
|
|
68
|
+
|
|
69
|
+
const setCount = (k: number) => {
|
|
70
|
+
if (k > n) {
|
|
71
|
+
// Thêm cột từ bảng: chia đều lại, giữ Bộ cột đang chọn (không nhảy con trỏ vào cột mới như nút + trên khối)
|
|
72
|
+
const added = Array.from({ length: k - n }, () => makeBlock("column", {}, [makeBlock("paragraph")]));
|
|
73
|
+
store.replace(block.id, [{ ...block, content: [...cols.map((c) => ({ ...c, attrs: { ...c.attrs, width: undefined } })), ...added] }], { select: { ids: [block.id], editing: null } });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (k < 1 || k === n) return;
|
|
77
|
+
// Bớt cột: nội dung của các cột bị bỏ dồn vào cột cuối còn lại (không mất chữ)
|
|
78
|
+
const keep = cols.slice(0, k).map((c) => ({ ...c, attrs: { ...c.attrs, width: undefined } }));
|
|
79
|
+
const moved = cols.slice(k).flatMap((c) => c.content ?? []);
|
|
80
|
+
keep[k - 1] = { ...keep[k - 1], content: [...(keep[k - 1].content ?? []), ...moved] };
|
|
81
|
+
store.replace(block.id, [{ ...block, content: keep }], { select: { ids: [block.id], editing: null } });
|
|
82
|
+
};
|
|
83
|
+
const setWidths = (w: number[]) => {
|
|
84
|
+
const eq = equalOf(w);
|
|
85
|
+
store.batch(() => cols.forEach((c, i) => store.setAttrs([c.id], { width: eq ? undefined : w[i] })));
|
|
86
|
+
};
|
|
87
|
+
const dir = atDevice<string>(attrs.columnsDirection as Responsive<string>, device);
|
|
88
|
+
const setDir = (v: string | undefined) => setAttrs({ columnsDirection: withDevice(attrs.columnsDirection as Responsive<string>, device, v) });
|
|
89
|
+
const gap = (k: "columnsGap" | "columnsRowGap") => atDevice<string>(attrs[k] as Responsive<string>, device);
|
|
90
|
+
const setGap = (k: "columnsGap" | "columnsRowGap", v: string | undefined) => setAttrs({ [k]: withDevice(attrs[k] as Responsive<string>, device, v) });
|
|
91
|
+
const valign = (attrs.verticalAlign as string | undefined) ?? "top";
|
|
92
|
+
const rowStyle = (normalizeStyle(attrs.style) ?? {}) as BlockStyle;
|
|
93
|
+
const rowMax = atDevice<string>(rowStyle.maxWidth as Responsive<string>, device);
|
|
94
|
+
// Đặt rộng tối đa mà chưa có lề → lề trái / phải tự động để hàng nằm giữa (lề đã đặt thì giữ)
|
|
95
|
+
const setRowMax = (v: string | undefined) => setAttrs({ style: normalizeStyle({ ...rowStyle, maxWidth: mapDevice(rowStyle.maxWidth as Responsive<string>, device, v), ...(v && !rowStyle.margin ? { margin: { base: { left: "auto", right: "auto" } } } : {}) }) ?? undefined });
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<>
|
|
99
|
+
<Section title={t.secLayout} defaultOpen>
|
|
100
|
+
<Row label={t.count}>
|
|
101
|
+
<div className="ecx-stepper">
|
|
102
|
+
<button type="button" aria-label={t.fewer} disabled={n <= 1} onClick={() => setCount(n - 1)}>−</button>
|
|
103
|
+
<output aria-live="polite">{n}</output>
|
|
104
|
+
<button type="button" aria-label={t.more} disabled={n >= 6} onClick={() => setCount(n + 1)}>+</button>
|
|
105
|
+
</div>
|
|
106
|
+
</Row>
|
|
107
|
+
<Row label={<>{t.layout}<em className="ecx-device-tag">{device === "base" ? t.desktop : device === "tablet" ? t.tablet : t.mobile}</em></>} device={device}
|
|
108
|
+
onReset={device !== "base" && dir ? () => setDir(undefined) : device === "base" && !equalOf(widths) ? () => setWidths(widths.map(() => 100 / n)) : undefined}>
|
|
109
|
+
<div className="ecx-layout-thumbs">
|
|
110
|
+
{device === "base"
|
|
111
|
+
? (LAYOUTS[n] ?? [Array(n).fill(100 / n)]).map((w) => <Thumb key={w.join("-")} widths={w} active={same(widths, w) || (equalOf(w) && equalOf(widths))} title={w.map((x) => `${x}%`).join(" / ")} onClick={() => setWidths(w)} />)
|
|
112
|
+
: <>
|
|
113
|
+
{/* Bộ cột tự xuống dòng khi hẹp (mặc định): trên điện thoại "mặc định" thực ra là xếp dọc → vẽ đúng như khung soạn */}
|
|
114
|
+
<Thumb widths={widths} stack={device === "mobile" && attrs.stack !== false ? "column" : undefined} active={!dir} title={device === "mobile" && attrs.stack !== false ? t.autoStack : t.inherit} onClick={() => setDir(undefined)} />
|
|
115
|
+
<Thumb widths={widths} stack="column" active={dir === "column"} title={t.stack} onClick={() => setDir("column")} />
|
|
116
|
+
<Thumb widths={widths} stack="column-reverse" active={dir === "column-reverse"} title={t.stackReverse} onClick={() => setDir("column-reverse")} />
|
|
117
|
+
</>}
|
|
118
|
+
</div>
|
|
119
|
+
{device === "base" && !LAYOUTS[n]?.some((w) => same(widths, w)) && <p className="ecx-field-help">{t.custom}: {widths.map((x) => `${Math.round(x)}%`).join(" / ")}</p>}
|
|
120
|
+
</Row>
|
|
121
|
+
{(["columnsGap", "columnsRowGap"] as const).map((k) => (
|
|
122
|
+
<Row key={k} label={k === "columnsGap" ? t.gap : t.rowGap} device={device} onReset={gap(k) !== undefined ? () => setGap(k, undefined) : undefined}>
|
|
123
|
+
<Seg label={k === "columnsGap" ? t.gap : t.rowGap} value={spaces.includes(gap(k) ?? "") ? gap(k) : undefined} onChange={(v) => setGap(k, v)}
|
|
124
|
+
options={spaces.map((s) => [s, s === "0" ? "0" : s.toUpperCase(), s] as [string, string, string])} />
|
|
125
|
+
<UnitInput label={`${k === "columnsGap" ? t.gap : t.rowGap}: px`} value={gap(k) && !spaces.includes(gap(k)!) ? gap(k) : undefined} units={["px", "rem", "%"]} max={160} onChange={(v) => setGap(k, v)} />
|
|
126
|
+
</Row>
|
|
127
|
+
))}
|
|
128
|
+
<Row label={t.valign}>
|
|
129
|
+
<Seg label={t.valign} value={valign} onChange={(v) => setAttrs({ verticalAlign: v === "top" ? undefined : v })}
|
|
130
|
+
options={[["top", AlignStartHorizontal, t.top], ["center", AlignCenterHorizontal, t.middle], ["bottom", AlignEndHorizontal, t.bottom], ["stretch", StretchHorizontal, t.stretch]]} />
|
|
131
|
+
</Row>
|
|
132
|
+
</Section>
|
|
133
|
+
<Section title={t.secMaxWidth} modified={!!rowMax} defaultOpen={!!rowMax}>
|
|
134
|
+
<Row label={t.rowMaxWidth} device={device} onReset={rowMax ? () => setRowMax(undefined) : undefined}>
|
|
135
|
+
<UnitInput label={t.rowMaxWidth} value={rowMax} units={["px", "rem", "%"]} max={1600} onChange={setRowMax} />
|
|
136
|
+
</Row>
|
|
137
|
+
</Section>
|
|
138
|
+
<DividerSection attrs={attrs} setAttrs={setAttrs} />
|
|
139
|
+
</>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Tab Cài đặt của một Cột: cách xếp các khối bên trong (hướng, căn ngang, căn dọc, khe) — style.layout flex, theo khổ. */
|
|
144
|
+
export function ColumnInspector({ attrs, setAttrs }: BlockEditProps) {
|
|
145
|
+
const { ui, host } = useEditor();
|
|
146
|
+
const t = useMsgs("columns");
|
|
147
|
+
const device: Device = ui.device === "desktop" ? "base" : ui.device;
|
|
148
|
+
const style = (normalizeStyle(attrs.style) ?? {}) as BlockStyle;
|
|
149
|
+
const layout: NonNullable<BlockStyle["layout"]> = style.layout ?? { type: "flex", direction: { base: "column" } };
|
|
150
|
+
const spaces = host.presets?.spacing ? ["0", ...byStep(Object.keys(host.presets.spacing))] : ["0", "xs", "sm", "md", "lg", "xl"];
|
|
151
|
+
const put = (patch: Partial<NonNullable<BlockStyle["layout"]>>) => setAttrs({ style: normalizeStyle({ ...style, layout: { ...layout, ...patch, type: "flex" } }) });
|
|
152
|
+
const field = <K extends "direction" | "justify" | "align">(k: K) => atDevice<string>(layout[k] as Responsive<string>, device);
|
|
153
|
+
const setField = (k: "direction" | "justify" | "align", v: string | undefined) => put({ [k]: mapDevice(layout[k] as Responsive<string>, device, v) } as never);
|
|
154
|
+
const vertical = (field("direction") ?? atDevice<string>(layout.direction as Responsive<string>, "base") ?? "column").startsWith("column");
|
|
155
|
+
// Trục chính có thêm dàn đều: giữa các khối / quanh các khối / đều nhau
|
|
156
|
+
const spread: [string, typeof ArrowDown, string][] = [["between", AlignHorizontalSpaceBetween, t.between], ["around", AlignHorizontalSpaceAround, t.around], ["evenly", AlignHorizontalDistributeCenter, t.evenly]];
|
|
157
|
+
const resp = <K extends "textAlign" | "maxWidth">(k: K) => atDevice<string>(style[k] as Responsive<string>, device);
|
|
158
|
+
const setResp = (k: "textAlign" | "maxWidth", v: string | undefined) => setAttrs({ style: normalizeStyle({ ...style, [k]: mapDevice(style[k] as Responsive<string>, device, v) }) ?? undefined });
|
|
159
|
+
const href = typeof attrs.href === "string" ? attrs.href : "";
|
|
160
|
+
const gap = atDevice<string>(style.gap as Responsive<string>, device);
|
|
161
|
+
const setGap = (v: string | undefined) => setAttrs({ style: normalizeStyle({ ...style, gap: mapDevice(style.gap as Responsive<string>, device, v), ...(v === undefined ? {} : { layout }) }) ?? undefined });
|
|
162
|
+
return (
|
|
163
|
+
<>
|
|
164
|
+
<Section title={t.secFlex} defaultOpen>
|
|
165
|
+
<Row label={t.direction} device={device} onReset={field("direction") && device !== "base" ? () => setField("direction", undefined) : undefined}>
|
|
166
|
+
<Seg label={t.direction} value={field("direction") ?? (device === "base" ? "column" : undefined)} onChange={(v) => setField("direction", v ?? "column")}
|
|
167
|
+
options={[["column", ArrowDown, t.vertical], ["row", ArrowRight, t.horizontal], ["column-reverse", ArrowUp, t.verticalReverse], ["row-reverse", ArrowLeft, t.horizontalReverse]]} />
|
|
168
|
+
</Row>
|
|
169
|
+
{/* Căn theo trục: dọc → căn ngang là align, căn dọc là justify; ngang thì ngược lại */}
|
|
170
|
+
<Row label={t.halign} device={device} onReset={field(vertical ? "align" : "justify") ? () => setField(vertical ? "align" : "justify", undefined) : undefined}>
|
|
171
|
+
<Seg label={t.halign} value={field(vertical ? "align" : "justify")} onChange={(v) => setField(vertical ? "align" : "justify", v)}
|
|
172
|
+
options={vertical
|
|
173
|
+
? [["start", AlignStartHorizontal, t.left], ["center", AlignCenterHorizontal, t.center], ["end", AlignEndHorizontal, t.right], ["stretch", StretchHorizontal, t.fill]]
|
|
174
|
+
: [["start", AlignStartHorizontal, t.left], ["center", AlignCenterHorizontal, t.center], ["end", AlignEndHorizontal, t.right], ...spread]} />
|
|
175
|
+
</Row>
|
|
176
|
+
<Row label={t.valign} device={device} onReset={field(vertical ? "justify" : "align") ? () => setField(vertical ? "justify" : "align", undefined) : undefined}>
|
|
177
|
+
<Seg label={t.valign} value={field(vertical ? "justify" : "align")} onChange={(v) => setField(vertical ? "justify" : "align", v)}
|
|
178
|
+
options={vertical
|
|
179
|
+
? [["start", AlignStartHorizontal, t.top], ["center", AlignCenterHorizontal, t.middle], ["end", AlignEndHorizontal, t.bottom], ...spread]
|
|
180
|
+
: [["start", AlignStartHorizontal, t.top], ["center", AlignCenterHorizontal, t.middle], ["end", AlignEndHorizontal, t.bottom], ["stretch", StretchHorizontal, t.fill]]} />
|
|
181
|
+
</Row>
|
|
182
|
+
<Row label={t.innerGap} device={device} onReset={gap !== undefined ? () => setGap(undefined) : undefined}>
|
|
183
|
+
<Seg label={t.innerGap} value={spaces.includes(gap ?? "") ? gap : undefined} onChange={setGap}
|
|
184
|
+
options={spaces.map((s) => [s, s === "0" ? "0" : s.toUpperCase(), s] as [string, string, string])} />
|
|
185
|
+
<UnitInput label={`${t.innerGap}: px`} value={gap && !spaces.includes(gap) ? gap : undefined} units={["px", "rem", "em"]} max={160} onChange={setGap} />
|
|
186
|
+
</Row>
|
|
187
|
+
<Row label={t.textAlign} device={device} onReset={resp("textAlign") ? () => setResp("textAlign", undefined) : undefined}>
|
|
188
|
+
<Seg label={t.textAlign} value={resp("textAlign")} onChange={(v) => setResp("textAlign", v)}
|
|
189
|
+
options={[["left", AlignLeft, t.left], ["center", AlignCenter, t.center], ["right", AlignRight, t.right]]} />
|
|
190
|
+
</Row>
|
|
191
|
+
</Section>
|
|
192
|
+
<Section title={t.secMaxWidth} modified={!!resp("maxWidth")} defaultOpen={!!resp("maxWidth")}>
|
|
193
|
+
<Row label={t.maxWidth} device={device} onReset={resp("maxWidth") ? () => setResp("maxWidth", undefined) : undefined}>
|
|
194
|
+
<UnitInput label={t.maxWidth} value={resp("maxWidth")} units={["px", "rem", "%"]} max={1600} onChange={(v) => setResp("maxWidth", v)} />
|
|
195
|
+
</Row>
|
|
196
|
+
</Section>
|
|
197
|
+
{/* Liên kết phủ cả cột (cả cột thành một vùng bấm) */}
|
|
198
|
+
<Section title={t.overlayLink} modified={!!href} defaultOpen={!!href}>
|
|
199
|
+
<Row label={t.linkUrl}>
|
|
200
|
+
<input className="ecx-input" type="url" inputMode="url" aria-label={t.overlayLink} placeholder="https://… / /duong-dan" value={href} onChange={(e) => setAttrs({ href: e.target.value || undefined })} />
|
|
201
|
+
{href && <>
|
|
202
|
+
<p className="ecx-field-help">{t.overlayNote}</p>
|
|
203
|
+
<label className="ecx-check-row"><input type="checkbox" role="switch" className="ecx-switch" checked={attrs.linkTarget === "_blank"} onChange={(e) => setAttrs({ linkTarget: e.target.checked ? "_blank" : undefined })} /> {t.newTab}</label>
|
|
204
|
+
<input className="ecx-input" aria-label={t.linkLabel} placeholder={t.linkLabel} value={typeof attrs.linkLabel === "string" ? attrs.linkLabel : ""} onChange={(e) => setAttrs({ linkLabel: e.target.value || undefined })} />
|
|
205
|
+
</>}
|
|
206
|
+
</Row>
|
|
207
|
+
</Section>
|
|
208
|
+
</>
|
|
209
|
+
);
|
|
210
|
+
}
|
package/src/v2/blocks/form.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CORE_NODES, FORM_FIELD_NAME, blockShell } from "@ecomcx/ecomweb-content";
|
|
1
|
+
import { CORE_NODES, FORM_FIELD_NAME, blockShell, formClass } from "@ecomcx/ecomweb-content";
|
|
2
2
|
import { ClipboardList, TextCursorInput } from "lucide-react";
|
|
3
3
|
import { useEffect, type CSSProperties } from "react";
|
|
4
4
|
import { InnerBlocks } from "../canvas/block-list";
|
|
@@ -32,11 +32,11 @@ function FormEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
|
32
32
|
// Mẫu (pattern) chèn vào chưa có mã: tạo một lần để máy chủ nhận ra form này
|
|
33
33
|
useEffect(() => { if (editable && !a.formId) setAttrs({ formId: newFormId() }); }, [editable, a.formId, setAttrs]);
|
|
34
34
|
return (
|
|
35
|
-
<div {...merge(blockProps,
|
|
35
|
+
<div {...merge(blockProps, formClass(a))} data-form-id={String(a.formId ?? "")}>
|
|
36
36
|
<InnerBlocks parent={block} />
|
|
37
37
|
{editable && <AddBlockButton parentId={block.id} label={tp.addField} className="is-inline" />}
|
|
38
38
|
<div className="ecx-form-actions">
|
|
39
|
-
<span className={blockShell("button", { variant: "primary" })?.className} style={blockShell("button", { variant: "primary" })?.style as CSSProperties} role="presentation">
|
|
39
|
+
<span className={blockShell("button", { variant: "primary" })?.className} style={(({ background: _b, color: _c, ...rest }) => rest)(blockShell("button", { variant: "primary" })?.style as CSSProperties)} role="presentation">
|
|
40
40
|
<RichText blockId={block.id} field="submitText" tagName="span" value={String(a.submitText ?? "")} onChange={(v) => setAttrs({ submitText: v })} placeholder={t.formSubmit} placeholderAlways editable={editable} />
|
|
41
41
|
</span>
|
|
42
42
|
</div>
|
|
@@ -66,7 +66,7 @@ function FieldEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
|
66
66
|
const ph = String(a.placeholder ?? "");
|
|
67
67
|
const check = kind === "checkbox" || kind === "consent";
|
|
68
68
|
return (
|
|
69
|
-
<div {...merge(blockProps, cx("ecx-field", `is-${kind}`, a.width === "half"
|
|
69
|
+
<div {...merge(blockProps, cx("ecx-field", `is-${kind}`, (a.width === "half" || a.width === "third") && `is-${a.width}`, check && "is-check"))}>
|
|
70
70
|
{check ? <label><input type="checkbox" disabled tabIndex={-1} /> <span>{label}{star}</span></label> : <label>{label}{star}</label>}
|
|
71
71
|
{kind === "textarea" ? <textarea disabled tabIndex={-1} placeholder={ph} />
|
|
72
72
|
: kind === "select" ? <select disabled tabIndex={-1}><option>{opts[0] ?? ph ?? "—"}</option></select>
|
package/src/v2/blocks/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BLOCK_ICONS, columnsIcon } from "../ui/block-icons";
|
|
1
2
|
import { CORE_NODES, coreControlsFor, type AttrSpec, type BlockAttrSpec } from "@ecomcx/ecomweb-content";
|
|
2
3
|
import { messages } from "../../i18n";
|
|
3
4
|
import type { V2Labels } from "../labels";
|
|
@@ -26,10 +27,13 @@ function withStyleAttrs(t: BlockType): BlockType["attributes"] {
|
|
|
26
27
|
const ctl = Object.entries(coreControlsFor(t.name));
|
|
27
28
|
if (!ctl.length) return t.attributes;
|
|
28
29
|
const hidden = (s: AttrSpec): BlockAttrSpec => ({ ...s, control: "hidden" });
|
|
29
|
-
|
|
30
|
+
// Thuộc tính gốc (CORE_NODES, ẩn) + thuộc tính khối tự khai đè lên — khối khai vài ô riêng (vd tabs) không làm mất thuộc tính gốc
|
|
31
|
+
// Thuộc tính khối tự khai đứng trước và giữ thứ tự của khối (thứ tự ô ở bảng phải); thuộc tính gốc còn lại thêm vào sau, ẩn
|
|
32
|
+
const base = { ...t.attributes, ...Object.fromEntries(Object.entries(CORE_NODES[t.name]?.attrs ?? {}).filter(([k]) => !t.attributes?.[k]).map(([k, s]) => [k, hidden(s)])) };
|
|
30
33
|
return {
|
|
31
34
|
...base,
|
|
32
|
-
|
|
35
|
+
// thuộc tính khối tự khai (vd tabs.tabsAlign hiện ở Cài đặt) giữ nguyên
|
|
36
|
+
...Object.fromEntries(ctl.filter(([k]) => !base?.[k]).map(([k, s]) => [k, hidden(s.type === "number"
|
|
33
37
|
? { type: "number", min: s.min, max: s.max }
|
|
34
38
|
: { type: "string", ...(s.type === "enum" ? { enum: s.options?.map((o) => (typeof o === "string" ? o : o.value)) } : {}) })])),
|
|
35
39
|
};
|
|
@@ -42,8 +46,10 @@ export function coreBlockTypes(labels: V2Labels): BlockType[] {
|
|
|
42
46
|
const str = (v: unknown) => (typeof v === "string" ? v : undefined);
|
|
43
47
|
const title = key ? String(labels[key]) : str(names[t.name]) ?? t.title;
|
|
44
48
|
// Biến thể đứng riêng (Hàng ngang / Xếp dọc / Lưới) theo ngôn ngữ
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
// Icon 2 lớp của bộ lõi (block-icons.tsx); biến thể dùng icon riêng nếu có, không thì icon của khối
|
|
50
|
+
const icon = BLOCK_ICONS[t.name] ?? t.icon;
|
|
51
|
+
const variations = t.variations?.map((v) => { const vt = str(names[`${t.name}/${v.name}`]); return { ...v, ...(vt ? { title: vt } : {}), icon: BLOCK_ICONS[v.name] ?? (t.name === "columns" ? columnsIcon(v.name) : undefined) ?? (BLOCK_ICONS[t.name] ? icon : v.icon) }; });
|
|
52
|
+
return { ...t, title, icon, variations, description: t.description ?? blockDescription(t.name, labels.lang), attributes: withStyleAttrs(t) };
|
|
47
53
|
});
|
|
48
54
|
}
|
|
49
55
|
|
|
@@ -23,7 +23,7 @@ export function withoutOverridden(inline: CSSProperties, rawStyle: unknown): CSS
|
|
|
23
23
|
if (style.fontWeight) drop.add("fontWeight");
|
|
24
24
|
if (style.textAlign) drop.add("textAlign");
|
|
25
25
|
if (style.color?.text) drop.add("color");
|
|
26
|
-
if (style.color?.background) { drop.add("background"); drop.add("backgroundColor"); }
|
|
26
|
+
if (style.color?.background || style.gradient || style.textGradient) { drop.add("background"); drop.add("backgroundColor"); }
|
|
27
27
|
if (style.border) SIDES.forEach((x) => drop.add(`border${x}`));
|
|
28
28
|
if (style.radius) drop.add("borderRadius");
|
|
29
29
|
return Object.fromEntries(Object.entries(inline).filter(([k]) => !drop.has(k))) as CSSProperties;
|