@ecomcx/ecomweb-editor 1.29.1 → 1.31.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/block-desc.ts +5 -5
- package/src/locales/en/block-style.ts +55 -0
- package/src/locales/en/index.ts +3 -1
- package/src/locales/en/placeholders.ts +96 -0
- package/src/locales/vi/block-desc.ts +5 -5
- package/src/locales/vi/block-style.ts +58 -0
- package/src/locales/vi/index.ts +3 -1
- package/src/locales/vi/placeholders.ts +95 -0
- package/src/shared/panel-store.ts +5 -4
- package/src/v2/blocks/compat.tsx +91 -5
- package/src/v2/blocks/form.tsx +3 -0
- package/src/v2/blocks/index.ts +19 -1
- package/src/v2/blocks/layout.tsx +182 -61
- package/src/v2/blocks/media.tsx +72 -71
- package/src/v2/blocks/text.tsx +48 -17
- package/src/v2/blocks/theme.tsx +73 -12
- package/src/v2/blocks/widgets.tsx +48 -11
- package/src/v2/canvas/block-list.tsx +4 -4
- package/src/v2/canvas/canvas-css.ts +95 -6
- package/src/v2/canvas/server-block.tsx +7 -4
- package/src/v2/core/host.ts +9 -0
- package/src/v2/core/registry.ts +3 -1
- package/src/v2/core/structure.ts +2 -1
- package/src/v2/editor.css +6 -2
- package/src/v2/index.ts +3 -0
- package/src/v2/ui/ai.tsx +9 -5
- package/src/v2/ui/attr-form.tsx +2 -2
- package/src/v2/ui/attr-hints.ts +6 -2
- package/src/v2/ui/background-panel.tsx +116 -50
- package/src/v2/ui/block-style-panel.tsx +78 -0
- package/src/v2/ui/inspector.tsx +34 -14
- package/src/v2/ui/layout-panel.tsx +35 -26
- package/src/v2/{blocks → ui}/media-actions.tsx +4 -3
- package/src/v2/ui/placeholders.tsx +205 -0
- package/src/v2/ui/style-supports.ts +2 -0
- package/src/v2/ui/style-tab.tsx +16 -9
- package/src/v2/ui/toolbar.tsx +9 -4
package/src/v2/blocks/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CORE_NODES, coreControlsFor, type AttrSpec, type BlockAttrSpec } from "@ecomcx/ecomweb-content";
|
|
1
2
|
import { messages } from "../../i18n";
|
|
2
3
|
import type { V2Labels } from "../labels";
|
|
3
4
|
import type { BlockType, BlockTypeRegistry } from "../core/registry";
|
|
@@ -17,6 +18,23 @@ const TITLE_KEYS: Partial<Record<string, keyof V2Labels>> = {
|
|
|
17
18
|
pullquote: "pullquote", cover: "cover", customHtml: "html", embed: "embed",
|
|
18
19
|
};
|
|
19
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Ô Kiểu dáng lõi (core-controls) khai thêm vào thuộc tính của khối, ẩn khỏi form Cài đặt (sửa ở tab Kiểu dáng) — để danh mục khối
|
|
23
|
+
* gửi cho AI (aiCatalog) biết tên / giá trị hợp lệ. Khối chưa khai `attributes` giữ mô tả của CORE_NODES (cũng ẩn) như trước.
|
|
24
|
+
*/
|
|
25
|
+
function withStyleAttrs(t: BlockType): BlockType["attributes"] {
|
|
26
|
+
const ctl = Object.entries(coreControlsFor(t.name));
|
|
27
|
+
if (!ctl.length) return t.attributes;
|
|
28
|
+
const hidden = (s: AttrSpec): BlockAttrSpec => ({ ...s, control: "hidden" });
|
|
29
|
+
const base = t.attributes ?? Object.fromEntries(Object.entries(CORE_NODES[t.name]?.attrs ?? {}).map(([k, s]) => [k, hidden(s)]));
|
|
30
|
+
return {
|
|
31
|
+
...base,
|
|
32
|
+
...Object.fromEntries(ctl.map(([k, s]) => [k, hidden(s.type === "number"
|
|
33
|
+
? { type: "number", min: s.min, max: s.max }
|
|
34
|
+
: { type: "string", ...(s.type === "enum" ? { enum: s.options?.map((o) => (typeof o === "string" ? o : o.value)) } : {}) })])),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
20
38
|
export function coreBlockTypes(labels: V2Labels): BlockType[] {
|
|
21
39
|
const names = messages("blockTitles", labels.lang);
|
|
22
40
|
return [...textBlocks(), ...layoutBlocks(), ...mediaBlocks(), ...formBlocks(labels.lang), ...widgetBlocks(labels.lang), ...themeBlocks()].map((t) => {
|
|
@@ -25,7 +43,7 @@ export function coreBlockTypes(labels: V2Labels): BlockType[] {
|
|
|
25
43
|
const title = key ? String(labels[key]) : str(names[t.name]) ?? t.title;
|
|
26
44
|
// Biến thể đứng riêng (Hàng ngang / Xếp dọc / Lưới) theo ngôn ngữ
|
|
27
45
|
const variations = t.variations?.map((v) => { const vt = str(names[`${t.name}/${v.name}`]); return vt ? { ...v, title: vt } : v; });
|
|
28
|
-
return { ...t, title, variations, description: t.description ?? blockDescription(t.name, labels.lang) };
|
|
46
|
+
return { ...t, title, variations, description: t.description ?? blockDescription(t.name, labels.lang), attributes: withStyleAttrs(t) };
|
|
29
47
|
});
|
|
30
48
|
}
|
|
31
49
|
|
package/src/v2/blocks/layout.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { blockShell, buttonWrapShell, colorCss, coverParts, spacingValue } from "@ecomcx/ecomweb-content";
|
|
2
2
|
import { ChevronsUpDown, Columns2, Columns3, Columns4, Info, LayoutPanelLeft, Minus, MousePointerClick, PanelTop, RectangleHorizontal, Square, Table2, Image as ImageIcon } from "lucide-react";
|
|
3
|
-
import type
|
|
3
|
+
import { useEffect, useSyncExternalStore, type CSSProperties } from "react";
|
|
4
4
|
import { InnerBlocks } from "../canvas/block-list";
|
|
5
5
|
import { withoutOverridden } from "./inline-style";
|
|
6
6
|
import { makeBlock } from "../core/model";
|
|
@@ -13,7 +13,7 @@ import { ColumnHandles, useActiveWithin } from "./resize";
|
|
|
13
13
|
import { layoutFor, layoutKind } from "../ui/layout-panel";
|
|
14
14
|
import { normalizeStyle, type BlockStyle } from "@ecomcx/ecomweb-content";
|
|
15
15
|
import { ToolButton } from "../ui/toolbar";
|
|
16
|
-
import {
|
|
16
|
+
import { AddItemButton, MediaPlaceholder } from "../ui/placeholders";
|
|
17
17
|
import type { MediaItem } from "../../shared/types";
|
|
18
18
|
import { LayoutGrid, Rows3, Columns3 as RowIcon } from "lucide-react";
|
|
19
19
|
import { useMsgs } from "../i18n";
|
|
@@ -31,9 +31,23 @@ const shellProps = (bp: BlockEditProps["blockProps"], type: string, attrs: Recor
|
|
|
31
31
|
return { ...merge(bp, sh.className ?? "", sh.style as CSSProperties, attrs), ...sh.attrs };
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
function GroupEdit({ block, blockProps }: BlockEditProps) {
|
|
34
|
+
function GroupEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
35
|
+
const tp = useMsgs("placeholders");
|
|
36
|
+
const style: BlockStyle = normalizeStyle(block.attrs.style) ?? {};
|
|
37
|
+
// Nhóm mới chèn (chưa chọn bố cục, chưa có nội dung): hỏi bố cục ngay trong khối như WordPress — đoạn văn bên trong vẫn gõ được ngay (gõ "/nhom" rồi gõ tiếp)
|
|
38
|
+
const kids = block.content ?? [];
|
|
39
|
+
const fresh = editable && !style.layout && (!kids.length || (kids.length === 1 && kids[0].type === "paragraph" && !kids[0].inline?.length));
|
|
40
|
+
const items: Array<["stack" | "row" | "grid", typeof Square, string]> = [["stack", Rows3, tp.layoutStack], ["row", RowIcon, tp.layoutRow], ["grid", LayoutGrid, tp.layoutGrid]];
|
|
35
41
|
return (
|
|
36
|
-
<div {...shellProps(blockProps, "group", block.attrs)}>
|
|
42
|
+
<div {...shellProps(blockProps, "group", block.attrs)} data-ecx-placeholder={fresh ? "layout" : undefined}>
|
|
43
|
+
{fresh && (
|
|
44
|
+
<div className="ecx-media-placeholder ecx-ph-choose" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
|
|
45
|
+
<p className="ecx-ph-title">{tp.chooseLayout}</p>
|
|
46
|
+
<div className="ecx-ph-choices">
|
|
47
|
+
{items.map(([k, I, label]) => <button key={k} type="button" className="ecx-ph-choice" onClick={() => setAttrs({ style: normalizeStyle({ ...style, layout: layoutFor(k) }) })}><I className="ecx-icon" aria-hidden />{label}</button>)}
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
)}
|
|
37
51
|
<InnerBlocks parent={block} />
|
|
38
52
|
</div>
|
|
39
53
|
);
|
|
@@ -88,15 +102,16 @@ function ButtonsEdit({ block, blockProps }: BlockEditProps) {
|
|
|
88
102
|
return <div {...shellProps(blockProps, "buttons", block.attrs)}><InnerBlocks parent={block} appender="none" /></div>;
|
|
89
103
|
}
|
|
90
104
|
|
|
91
|
-
function ButtonEdit({ block, blockProps, setAttrs, editable
|
|
105
|
+
function ButtonEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
92
106
|
const { store } = useEditor();
|
|
107
|
+
const tp = useMsgs("placeholders");
|
|
93
108
|
const a = block.attrs;
|
|
94
109
|
const bound = useBindingPreview(block, "text");
|
|
95
110
|
const inGroup = store.locate(block.id)?.parent?.type === "buttons";
|
|
96
111
|
// Website: nút đứng riêng nằm trong đoạn <p class="ecx-buttons"> (căn lề); trong khối "buttons" thì là chính thẻ <a>
|
|
97
112
|
const link = (
|
|
98
113
|
<a {...shellProps(inGroup ? blockProps : ({} as BlockEditProps["blockProps"]), "button", a)} onClick={(e) => e.preventDefault()}>
|
|
99
|
-
{bound.bound ? <BoundText preview={bound} /> : <RichText blockId={block.id} field="text" tagName="span" value={String(a.text ?? "")} onChange={(v) => setAttrs({ text: v })} placeholder={
|
|
114
|
+
{bound.bound ? <BoundText preview={bound} /> : <RichText blockId={block.id} field="text" tagName="span" value={String(a.text ?? "")} onChange={(v) => setAttrs({ text: v })} placeholder={tp.buttonText} placeholderAlways editable={editable} />}
|
|
100
115
|
</a>
|
|
101
116
|
);
|
|
102
117
|
if (inGroup) return link;
|
|
@@ -105,7 +120,11 @@ function ButtonEdit({ block, blockProps, setAttrs, editable, labels }: BlockEdit
|
|
|
105
120
|
}
|
|
106
121
|
|
|
107
122
|
function SpacerEdit({ block, blockProps }: BlockEditProps) {
|
|
108
|
-
|
|
123
|
+
const tp = useMsgs("placeholders");
|
|
124
|
+
const props = shellProps(blockProps, "spacer", block.attrs);
|
|
125
|
+
const h = props.style?.height ?? block.attrs.height;
|
|
126
|
+
// Nhãn kích thước chỉ trong trình soạn (CSS ::before, không thêm phần tử con — website là div rỗng)
|
|
127
|
+
return <div {...props} data-ecx-size={tp.spacer.replace("{size}", String(h ?? ""))} />;
|
|
109
128
|
}
|
|
110
129
|
|
|
111
130
|
function SeparatorEdit({ blockProps }: BlockEditProps) {
|
|
@@ -113,63 +132,148 @@ function SeparatorEdit({ blockProps }: BlockEditProps) {
|
|
|
113
132
|
}
|
|
114
133
|
|
|
115
134
|
function CalloutEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
116
|
-
const
|
|
135
|
+
const tp = useMsgs("placeholders");
|
|
117
136
|
const title = String(block.attrs.title ?? "");
|
|
118
137
|
return (
|
|
119
138
|
<div {...shellProps(blockProps, "callout", block.attrs)}>
|
|
120
|
-
{/* website chỉ in tiêu đề khi có chữ:
|
|
121
|
-
{(title ||
|
|
139
|
+
{/* website chỉ in tiêu đề khi có chữ: trình soạn luôn có ô tiêu đề (gợi ý "không bắt buộc") để thấy chỗ gõ */}
|
|
140
|
+
{(title || editable) && <RichText blockId={block.id} field="title" tagName="p" className="ecx-callout-title cms-callout-title" style={{ margin: 0, fontWeight: 600 }} value={title} onChange={(v) => setAttrs({ title: v })} placeholder={tp.calloutTitle} placeholderAlways editable={editable} />}
|
|
122
141
|
<InnerBlocks parent={block} />
|
|
123
142
|
</div>
|
|
124
143
|
);
|
|
125
144
|
}
|
|
126
145
|
|
|
127
146
|
function DetailsEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
147
|
+
const tp = useMsgs("placeholders");
|
|
128
148
|
return (
|
|
129
149
|
<details {...(merge(blockProps, "ecx-details") as object)} open>
|
|
130
150
|
<summary onClick={(e) => e.preventDefault()}>
|
|
131
|
-
<RichText blockId={block.id} field="summary" tagName="span" value={String(block.attrs.summary ?? "")} onChange={(v) => setAttrs({ summary: v })} placeholder=
|
|
151
|
+
<RichText blockId={block.id} field="summary" tagName="span" value={String(block.attrs.summary ?? "")} onChange={(v) => setAttrs({ summary: v })} placeholder={tp.detailsSummary} placeholderAlways editable={editable} />
|
|
132
152
|
</summary>
|
|
133
153
|
<InnerBlocks parent={block} />
|
|
134
154
|
</details>
|
|
135
155
|
);
|
|
136
156
|
}
|
|
137
157
|
|
|
138
|
-
|
|
139
|
-
|
|
158
|
+
/** Nút "+ Thêm …" cuối khối chứa nhiều mục (accordion, carousel): chỉ khi đang thao tác trong khối. */
|
|
159
|
+
function AddChild({ block, label, make }: { block: BlockEditProps["block"]; label: string; make(): ReturnType<typeof makeBlock> }) {
|
|
160
|
+
const { store } = useEditor();
|
|
161
|
+
const active = useActiveWithin(block.id);
|
|
162
|
+
const loc = store.locate(block.id);
|
|
163
|
+
if (!active || !loc || !store.canInsertInto(block.id)) return null;
|
|
164
|
+
return <AddItemButton label={label} onClick={() => { const b = make(); store.insert(loc.docId, block.id, block.content?.length ?? 0, [b]); }} />;
|
|
140
165
|
}
|
|
141
166
|
|
|
142
|
-
function
|
|
143
|
-
|
|
167
|
+
function AccordionEdit({ block, blockProps, editable }: BlockEditProps) {
|
|
168
|
+
const tp = useMsgs("placeholders");
|
|
169
|
+
return <div {...(merge(blockProps, "ecx-accordion") as object)}><InnerBlocks parent={block} />{editable && <AddChild block={block} label={tp.addItem} make={() => makeBlock("details", { summary: "" }, [makeBlock("paragraph")])} />}</div>;
|
|
144
170
|
}
|
|
145
171
|
|
|
146
|
-
|
|
172
|
+
/** Thẻ đang mở của từng khối tabs trên khung soạn (không lưu vào nội dung — website luôn mở thẻ đầu). */
|
|
173
|
+
const openTabs = new Map<string, number>();
|
|
174
|
+
const tabListeners = new Set<() => void>();
|
|
175
|
+
const setOpenTab = (id: string, i: number) => { openTabs.set(id, i); tabListeners.forEach((l) => l()); };
|
|
176
|
+
const useOpenTab = (id: string) => useSyncExternalStore((l) => { tabListeners.add(l); return () => { tabListeners.delete(l); }; }, () => openTabs.get(id) ?? 0);
|
|
177
|
+
|
|
178
|
+
/** Tabs như website (TabsClient): thanh tiêu đề (vai trò tablist / tab) + một thẻ hiện; tiêu đề gõ ngay trên thanh, trống = "Tab N". */
|
|
179
|
+
function TabsEdit({ block, blockProps, editable }: BlockEditProps) {
|
|
180
|
+
const { store } = useEditor();
|
|
181
|
+
const tp = useMsgs("placeholders");
|
|
182
|
+
const active = useOpenTab(block.id);
|
|
183
|
+
const tabs = (block.content ?? []).filter((c) => c.type === "tab");
|
|
147
184
|
return (
|
|
148
|
-
<div {...(merge(blockProps, "ecx-
|
|
149
|
-
<
|
|
185
|
+
<div {...(merge(blockProps, "ecx-tabs") as object)}>
|
|
186
|
+
<div role="tablist" className="ecx-tabs-list">
|
|
187
|
+
{tabs.map((tab, i) => (
|
|
188
|
+
<div key={tab.id} role="tab" aria-selected={i === active} tabIndex={-1} className={cx("ecx-tab-button", i === active && "is-active")} onMouseDown={() => setOpenTab(block.id, i)}>
|
|
189
|
+
<RichText blockId={tab.id} field="title" tagName="span" value={String(tab.attrs.title ?? "")} onChange={(v) => store.setAttrs([tab.id], { title: v })} placeholder={tp.tabTitle} placeholderAlways editable={editable} />
|
|
190
|
+
</div>
|
|
191
|
+
))}
|
|
192
|
+
{/* Nút thêm tab nằm ngay trên hàng tab */}
|
|
193
|
+
{editable && store.canInsertInto(block.id) && <AddItemButton label={tp.addTab} onClick={() => {
|
|
194
|
+
const loc = store.locate(block.id);
|
|
195
|
+
if (!loc) return;
|
|
196
|
+
store.insert(loc.docId, block.id, block.content?.length ?? 0, [makeBlock("tab", { title: "" }, [makeBlock("paragraph")])]);
|
|
197
|
+
setOpenTab(block.id, tabs.length);
|
|
198
|
+
}} />}
|
|
199
|
+
</div>
|
|
150
200
|
<InnerBlocks parent={block} />
|
|
151
201
|
</div>
|
|
152
202
|
);
|
|
153
203
|
}
|
|
154
204
|
|
|
155
|
-
function
|
|
156
|
-
|
|
205
|
+
function TabEdit({ block, blockProps }: BlockEditProps) {
|
|
206
|
+
const { store } = useEditor();
|
|
207
|
+
const loc = store.locate(block.id);
|
|
208
|
+
const parentId = loc?.parent?.id ?? "";
|
|
209
|
+
const index = (loc?.parent?.content ?? []).filter((c) => c.type === "tab").findIndex((c) => c.id === block.id);
|
|
210
|
+
const open = useOpenTab(parentId) === index;
|
|
211
|
+
const within = useActiveWithin(block.id);
|
|
212
|
+
// Chọn khối nằm trong thẻ đang ẩn (danh sách khối, tìm kiếm…) → mở thẻ đó
|
|
213
|
+
useEffect(() => { if (within && !open && parentId) setOpenTab(parentId, index); }, [within, open, parentId, index]);
|
|
214
|
+
return (
|
|
215
|
+
<div {...(merge(blockProps, "ecx-tab ecx-tab-panel", open ? undefined : { display: "none" }) as object)} role="tabpanel">
|
|
216
|
+
<InnerBlocks parent={block} />
|
|
217
|
+
</div>
|
|
218
|
+
);
|
|
157
219
|
}
|
|
158
220
|
|
|
159
|
-
function
|
|
160
|
-
|
|
221
|
+
function CarouselEdit({ block, blockProps, editable }: BlockEditProps) {
|
|
222
|
+
const tp = useMsgs("placeholders");
|
|
223
|
+
return <div {...(merge(blockProps, "ecx-carousel") as object)}><InnerBlocks parent={block} />{editable && <AddChild block={block} label={tp.addSlide} make={() => makeBlock("group", {}, [makeBlock("paragraph")])} />}</div>;
|
|
161
224
|
}
|
|
162
225
|
|
|
163
|
-
|
|
226
|
+
/** Shortcode: ô nhập tên luôn hiện ngay trên khối. */
|
|
227
|
+
function ShortcodeEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
228
|
+
const tp = useMsgs("placeholders");
|
|
229
|
+
const name = String(block.attrs.name ?? "");
|
|
230
|
+
if (!editable) return <div {...(merge(blockProps, "ecx-shortcode", { fontFamily: "monospace", opacity: 0.8 }) as object)}>[{name || "shortcode"}]</div>;
|
|
231
|
+
return (
|
|
232
|
+
<div {...(merge(blockProps, "ecx-shortcode ecx-media-placeholder ecx-ph-inline") as object)} data-ecx-placeholder="shortcode">
|
|
233
|
+
<label className="ecx-ph-row" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
|
|
234
|
+
<span className="ecx-ph-mono" aria-hidden>[ ]</span>
|
|
235
|
+
<span className="ecx-ph-label">{tp.shortcodeName}</span>
|
|
236
|
+
<input className="ecx-input ecx-ph-mono" value={name} placeholder="shortcode" onChange={(e) => setAttrs({ name: e.target.value.replace(/[^\w-]/g, "") || undefined })} />
|
|
237
|
+
</label>
|
|
238
|
+
</div>
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const pad2 = (n: number) => String(n).padStart(2, "0");
|
|
243
|
+
/** ISO / chuỗi ngày → giá trị ô datetime-local (giờ máy). */
|
|
244
|
+
const toLocalInput = (v: unknown) => { const d = new Date(String(v ?? "")); return Number.isFinite(d.getTime()) ? `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}T${pad2(d.getHours())}:${pad2(d.getMinutes())}` : ""; };
|
|
245
|
+
|
|
246
|
+
function CountdownEdit({ block, blockProps, setAttrs, editable, labels }: BlockEditProps) {
|
|
164
247
|
const a = block.attrs;
|
|
165
|
-
|
|
166
|
-
|
|
248
|
+
const tp = useMsgs("placeholders");
|
|
249
|
+
const valid = Number.isFinite(Date.parse(String(a.target ?? "")));
|
|
250
|
+
const active = useActiveWithin(block.id);
|
|
251
|
+
// Chọn ngày giờ ngay trong khối (thiếu / sai thời điểm: website không vẽ khối → nói rõ, không để khối "mất tích" im lặng)
|
|
252
|
+
if (!valid || (editable && active)) return (
|
|
253
|
+
<div {...(merge(blockProps, "ecx-countdown ecx-media-placeholder", {}) as object)} data-ecx-placeholder="countdown">
|
|
254
|
+
<span className="ecx-ph-digits" aria-hidden>00 : 00 : 00 : 00</span>
|
|
255
|
+
{editable && <label className="ecx-ph-row" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
|
|
256
|
+
<span className="ecx-ph-label">{tp.countdownTarget}</span>
|
|
257
|
+
<input className="ecx-input" type="datetime-local" value={toLocalInput(a.target)} onChange={(e) => setAttrs({ target: e.target.value ? new Date(e.target.value).toISOString() : undefined })} />
|
|
258
|
+
</label>}
|
|
259
|
+
{!valid && <p className="ecx-placeholder-hint">{labels.countdownNoTarget}</p>}
|
|
260
|
+
</div>
|
|
261
|
+
);
|
|
167
262
|
return <div {...(merge(blockProps, "ecx-countdown", { textAlign: "center" }) as object)}>{a.label ? <p style={{ margin: 0 }}>{String(a.label)}</p> : null}<strong>{String(a.target)}</strong></div>;
|
|
168
263
|
}
|
|
169
264
|
|
|
170
|
-
|
|
265
|
+
/** Sao xám → bấm vào sao để chấm ngay trên khối. */
|
|
266
|
+
function RatingEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
267
|
+
const tp = useMsgs("placeholders");
|
|
171
268
|
const max = Math.min(10, Math.max(1, Number(block.attrs.max) || 5)), v = Number(block.attrs.value) || 0;
|
|
172
|
-
return
|
|
269
|
+
return (
|
|
270
|
+
<div {...(merge(blockProps, "ecx-rating") as object)} aria-label={`${v}/${max}`} title={editable ? tp.rateHint : undefined} data-ecx-placeholder={editable && !v ? "rating" : undefined}>
|
|
271
|
+
{Array.from({ length: max }, (_, i) => editable
|
|
272
|
+
? <button key={i} type="button" className="ecx-ph-star" contentEditable={false} aria-label={tp.rateStar.replace("{n}", String(i + 1))} aria-pressed={i < Math.round(v)} onMouseDown={(e) => e.stopPropagation()} onClick={() => setAttrs({ value: i + 1 })} style={{ color: i < Math.round(v) ? "#f59e0b" : "#d4d4d8" }}>★</button>
|
|
273
|
+
: <span key={i} style={{ color: i < Math.round(v) ? "#f59e0b" : "#d4d4d8" }}>★</span>)}
|
|
274
|
+
{editable && !v && <span className="ecx-placeholder-hint" contentEditable={false}>{tp.rateHint}</span>}
|
|
275
|
+
</div>
|
|
276
|
+
);
|
|
173
277
|
}
|
|
174
278
|
|
|
175
279
|
function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
|
|
@@ -177,34 +281,34 @@ function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
|
|
|
177
281
|
const src = typeof a.src === "string" ? a.src : "";
|
|
178
282
|
const { host } = useEditor();
|
|
179
283
|
const select = (items: MediaItem[]) => setAttrs({ src: items[0].url, alt: items[0].alt || undefined, mediaId: items[0].id });
|
|
180
|
-
const drop = useFileDrop("image", select);
|
|
181
284
|
const t = useMsgs("blocks"); // hook phải gọi trước mọi return sớm: chọn ảnh/màu làm đổi nhánh render
|
|
285
|
+
const tp = useMsgs("placeholders");
|
|
182
286
|
// Chưa có ảnh lẫn màu: chỗ chọn ảnh nền hoặc màu nền (không để khối trắng trơn vô hình)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
<
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
</div>
|
|
194
|
-
</div>
|
|
287
|
+
const st = normalizeStyle(a.style);
|
|
288
|
+
if (!src && !a.overlay && !st?.color?.background && !st?.gradient && !st?.background?.image) {
|
|
289
|
+
// Ảnh hoặc chỉ cần màu nền (không bắt buộc ảnh)
|
|
290
|
+
const colors = (
|
|
291
|
+
<span className="ecx-chip-row" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
|
|
292
|
+
<span className="ecx-ph-label">{t.background}</span>
|
|
293
|
+
{Object.entries(host.presets?.colors ?? { primary: "#1a597b", black: "#111", muted: "#757575" }).map(([name, c]) => (
|
|
294
|
+
<button key={name} type="button" className="ecx-chip ecx-chip-swatch" title={name} aria-label={`${t.background}: ${name}`} style={{ background: c }} onClick={() => setAttrs({ overlay: name, opacity: 100 })} />
|
|
295
|
+
))}
|
|
296
|
+
</span>
|
|
195
297
|
);
|
|
298
|
+
return <MediaPlaceholder kind="image" blockProps={merge(blockProps, "ecx-cover-placeholder") as BlockEditProps["blockProps"]} title={tp.dropCover} onSelect={select} onUrl={(url) => setAttrs({ src: url })} extra={colors} />;
|
|
196
299
|
}
|
|
197
|
-
const { overlay,
|
|
300
|
+
const { overlay, fixed, imgStyle, overlayStyle } = coverParts(a);
|
|
198
301
|
return (
|
|
199
302
|
<div {...shellProps(blockProps, "cover", a)}>
|
|
200
|
-
{src && !fixed && <img className="ecx-cover-img" src={src} alt={String(a.alt ?? "")} draggable={false} />}
|
|
201
|
-
{overlay && <span className="ecx-cover-overlay" aria-hidden="true" style={
|
|
303
|
+
{src && !fixed && <img className="ecx-cover-img" src={src} alt={String(a.alt ?? "")} draggable={false} style={imgStyle as CSSProperties} />}
|
|
304
|
+
{overlay && <span className="ecx-cover-overlay" aria-hidden="true" style={overlayStyle as CSSProperties} />}
|
|
202
305
|
<div className="ecx-cover-inner"><InnerBlocks parent={block} /></div>
|
|
203
306
|
</div>
|
|
204
307
|
);
|
|
205
308
|
}
|
|
206
309
|
|
|
207
310
|
function MediaTextEdit({ block, blockProps }: BlockEditProps) {
|
|
311
|
+
// Ô ảnh rỗng = vùng thả lớn (cùng kiểu ô thả với khối Ảnh)
|
|
208
312
|
const a = block.attrs;
|
|
209
313
|
return (
|
|
210
314
|
<div {...shellProps(blockProps, "mediaText", a)}>
|
|
@@ -214,21 +318,37 @@ function MediaTextEdit({ block, blockProps }: BlockEditProps) {
|
|
|
214
318
|
);
|
|
215
319
|
}
|
|
216
320
|
|
|
217
|
-
/**
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const { store, labels } = useEditor();
|
|
321
|
+
/** Chỗ chọn ảnh trong khối (ảnh + chữ, hộp ảnh, lời chứng thực…): vùng thả + Tải lên / Thư viện / URL. */
|
|
322
|
+
export function MediaPick({ blockId, compact }: { blockId: string; compact?: boolean }) {
|
|
323
|
+
const { store } = useEditor();
|
|
221
324
|
const select = (items: MediaItem[]) => store.setAttrs([blockId], { src: items[0].url, alt: items[0].alt || undefined, mediaId: items[0].id });
|
|
222
|
-
|
|
325
|
+
return <MediaPlaceholder kind="image" compact={compact} className="ecx-media-pick" onSelect={select} onUrl={(url) => store.setAttrs([blockId], { src: url })} />;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** Bảng mới chèn: hỏi số cột / hàng trước (thay cho bảng trống cỡ cố định). */
|
|
329
|
+
function TableSetup({ block, blockProps }: BlockEditProps) {
|
|
330
|
+
const { store } = useEditor();
|
|
331
|
+
const tp = useMsgs("placeholders");
|
|
332
|
+
const create = (cols: number, rows: number) => {
|
|
333
|
+
const c = Math.min(12, Math.max(1, cols || 2)), r = Math.min(50, Math.max(1, rows || 2));
|
|
334
|
+
const content = Array.from({ length: r }, (_, i) => makeBlock("tableRow", {}, Array.from({ length: c }, () => cell(i === 0 && r > 1))));
|
|
335
|
+
store.replace(block.id, [{ ...block, content }], { select: { ids: [], editing: content[0].content![0].content![0].id }, caret: { id: content[0].content![0].content![0].id, offset: 0 } });
|
|
336
|
+
};
|
|
223
337
|
return (
|
|
224
|
-
<div
|
|
225
|
-
<
|
|
226
|
-
<
|
|
338
|
+
<div {...merge(blockProps, "ecx-table ecx-media-placeholder ecx-ph-table")} data-ecx-placeholder="table">
|
|
339
|
+
<p className="ecx-ph-title"><Table2 className="ecx-icon" aria-hidden />{tp.createTable}</p>
|
|
340
|
+
<form className="ecx-ph-row" contentEditable={false} onMouseDown={(e) => e.stopPropagation()} onSubmit={(e) => { e.preventDefault(); const f = new FormData(e.currentTarget); create(Number(f.get("cols")), Number(f.get("rows"))); }}>
|
|
341
|
+
<label className="ecx-ph-field"><span className="ecx-ph-label">{tp.columns}</span><input className="ecx-input" name="cols" type="number" min={1} max={12} defaultValue={2} /></label>
|
|
342
|
+
<label className="ecx-ph-field"><span className="ecx-ph-label">{tp.rows}</span><input className="ecx-input" name="rows" type="number" min={1} max={50} defaultValue={2} /></label>
|
|
343
|
+
<button type="submit" className="ecx-btn ecx-btn-primary">{tp.create}</button>
|
|
344
|
+
</form>
|
|
227
345
|
</div>
|
|
228
346
|
);
|
|
229
347
|
}
|
|
230
348
|
|
|
231
|
-
function TableEdit(
|
|
349
|
+
function TableEdit(props: BlockEditProps) {
|
|
350
|
+
const { block, blockProps } = props;
|
|
351
|
+
if (!block.content?.length && props.editable) return <TableSetup {...props} />;
|
|
232
352
|
return (
|
|
233
353
|
<div {...merge(blockProps, "ecx-table table-wrap")}>
|
|
234
354
|
<table className={block.attrs.fixed ? "is-fixed" : undefined}><tbody><InnerBlocks parent={block} appender="none" /></tbody></table>
|
|
@@ -244,7 +364,8 @@ function CellEdit({ block, blockProps }: BlockEditProps) {
|
|
|
244
364
|
return <Tag {...(blockProps as object)} colSpan={span(block.attrs.colspan)} rowSpan={span(block.attrs.rowspan)}><InnerBlocks parent={block} appender="none" /></Tag>;
|
|
245
365
|
}
|
|
246
366
|
|
|
247
|
-
|
|
367
|
+
// Cột mới chèn để trống (nút "+ Thêm khối" giữa cột); cột đều không đặt `width` (website chia đều), cột lệch đặt % thật (33 / 67)
|
|
368
|
+
const col = (width?: number) => makeBlock("column", width ? { width } : {}, []);
|
|
248
369
|
const columns = (...widths: number[]) => makeBlock("columns", {}, widths.map((w) => col(w)));
|
|
249
370
|
const cell = (header = false) => makeBlock(header ? "tableHeader" : "tableCell", {}, [makeBlock("paragraph")]);
|
|
250
371
|
|
|
@@ -266,13 +387,13 @@ export function layoutBlocks(): BlockType[] {
|
|
|
266
387
|
{
|
|
267
388
|
name: "columns", title: "Cột", icon: Columns2, category: "design", keywords: "cot columns bo cuc layout", kind: "container", edit: ColumnsEdit,
|
|
268
389
|
attributes: { verticalAlign: { type: "string", enum: ["top", "center", "bottom"] }, stack: { type: "boolean", default: true } },
|
|
269
|
-
create: () => columns(
|
|
390
|
+
create: () => columns(0, 0), contextToolbar: ColumnsTools,
|
|
270
391
|
variations: [
|
|
271
|
-
{ name: "50-50", title: "50 / 50", icon: Columns2, create: () => columns(
|
|
272
|
-
{ name: "33-33-33", title: "33 / 33 / 33", icon: Columns3, create: () => columns(
|
|
273
|
-
{ name: "
|
|
274
|
-
{ name: "
|
|
275
|
-
{ name: "25x4", title: "25 / 25 / 25 / 25", icon: Columns4, create: () => columns(
|
|
392
|
+
{ name: "50-50", title: "50 / 50", icon: Columns2, create: () => columns(0, 0) },
|
|
393
|
+
{ name: "33-33-33", title: "33 / 33 / 33", icon: Columns3, create: () => columns(0, 0, 0) },
|
|
394
|
+
{ name: "33-66", title: "33 / 66", icon: LayoutPanelLeft, create: () => columns(33, 67) },
|
|
395
|
+
{ name: "66-33", title: "66 / 33", icon: LayoutPanelLeft, create: () => columns(67, 33) },
|
|
396
|
+
{ name: "25x4", title: "25 / 25 / 25 / 25", icon: Columns4, create: () => columns(0, 0, 0, 0) },
|
|
276
397
|
],
|
|
277
398
|
supports: { style: true, anchor: true, className: true },
|
|
278
399
|
},
|
|
@@ -343,12 +464,12 @@ export function layoutBlocks(): BlockType[] {
|
|
|
343
464
|
{
|
|
344
465
|
name: "mediaText", title: "Ảnh + chữ", icon: LayoutPanelLeft, category: "media", keywords: "anh chu media text", kind: "container", edit: MediaTextEdit,
|
|
345
466
|
attributes: { src: { type: "url", control: "media" }, alt: { type: "string" }, position: { type: "string", enum: ["left", "right"], default: "left" }, width: { type: "integer", default: 50, min: 20, max: 80 }, verticalAlign: { type: "string", enum: ["top", "center", "bottom"], default: "center" }, stack: { type: "boolean", default: true } },
|
|
346
|
-
create: () => makeBlock("mediaText", {}, [makeBlock("paragraph")]), supports: { style: true, anchor: true, className: true },
|
|
467
|
+
create: () => makeBlock("mediaText", {}, [makeBlock("heading", { level: 3 }), makeBlock("paragraph")]), supports: { style: true, anchor: true, className: true },
|
|
347
468
|
},
|
|
348
469
|
{
|
|
349
470
|
name: "table", title: "Bảng", icon: Table2, category: "text", keywords: "bang table", kind: "container", edit: TableEdit,
|
|
350
471
|
attributes: { footer: { type: "boolean", default: false }, fixed: { type: "boolean", default: false } },
|
|
351
|
-
create: () => makeBlock("table", {}, [
|
|
472
|
+
create: () => makeBlock("table", {}, []), contextToolbar: TableTools,
|
|
352
473
|
supports: { style: true, anchor: true, className: true, blockStyle: true },
|
|
353
474
|
},
|
|
354
475
|
{ name: "tableRow", title: "Hàng", icon: Table2, kind: "container", edit: RowEdit, hidden: true },
|