@ecomcx/ecomweb-editor 1.30.0 → 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/index.ts +2 -1
- package/src/locales/en/placeholders.ts +96 -0
- package/src/locales/vi/index.ts +2 -1
- package/src/locales/vi/placeholders.ts +95 -0
- package/src/v2/blocks/compat.tsx +91 -5
- package/src/v2/blocks/form.tsx +3 -0
- package/src/v2/blocks/layout.tsx +143 -52
- 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 +88 -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/{blocks → ui}/media-actions.tsx +4 -3
- package/src/v2/ui/placeholders.tsx +205 -0
- package/src/v2/ui/toolbar.tsx +7 -3
package/src/v2/blocks/layout.tsx
CHANGED
|
@@ -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,30 +132,41 @@ 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]); }} />;
|
|
165
|
+
}
|
|
166
|
+
|
|
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>;
|
|
140
170
|
}
|
|
141
171
|
|
|
142
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). */
|
|
@@ -148,7 +178,7 @@ const useOpenTab = (id: string) => useSyncExternalStore((l) => { tabListeners.ad
|
|
|
148
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". */
|
|
149
179
|
function TabsEdit({ block, blockProps, editable }: BlockEditProps) {
|
|
150
180
|
const { store } = useEditor();
|
|
151
|
-
const
|
|
181
|
+
const tp = useMsgs("placeholders");
|
|
152
182
|
const active = useOpenTab(block.id);
|
|
153
183
|
const tabs = (block.content ?? []).filter((c) => c.type === "tab");
|
|
154
184
|
return (
|
|
@@ -156,9 +186,16 @@ function TabsEdit({ block, blockProps, editable }: BlockEditProps) {
|
|
|
156
186
|
<div role="tablist" className="ecx-tabs-list">
|
|
157
187
|
{tabs.map((tab, i) => (
|
|
158
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)}>
|
|
159
|
-
<RichText blockId={tab.id} field="title" tagName="span" value={String(tab.attrs.title ?? "")} onChange={(v) => store.setAttrs([tab.id], { title: v })} placeholder={
|
|
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} />
|
|
160
190
|
</div>
|
|
161
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
|
+
}} />}
|
|
162
199
|
</div>
|
|
163
200
|
<InnerBlocks parent={block} />
|
|
164
201
|
</div>
|
|
@@ -181,24 +218,62 @@ function TabEdit({ block, blockProps }: BlockEditProps) {
|
|
|
181
218
|
);
|
|
182
219
|
}
|
|
183
220
|
|
|
184
|
-
function CarouselEdit({ block, blockProps }: BlockEditProps) {
|
|
185
|
-
|
|
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>;
|
|
186
224
|
}
|
|
187
225
|
|
|
188
|
-
|
|
189
|
-
|
|
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
|
+
);
|
|
190
240
|
}
|
|
191
241
|
|
|
192
|
-
|
|
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) {
|
|
193
247
|
const a = block.attrs;
|
|
194
|
-
|
|
195
|
-
|
|
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
|
+
);
|
|
196
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>;
|
|
197
263
|
}
|
|
198
264
|
|
|
199
|
-
|
|
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");
|
|
200
268
|
const max = Math.min(10, Math.max(1, Number(block.attrs.max) || 5)), v = Number(block.attrs.value) || 0;
|
|
201
|
-
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
|
+
);
|
|
202
277
|
}
|
|
203
278
|
|
|
204
279
|
function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
|
|
@@ -206,23 +281,21 @@ function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
|
|
|
206
281
|
const src = typeof a.src === "string" ? a.src : "";
|
|
207
282
|
const { host } = useEditor();
|
|
208
283
|
const select = (items: MediaItem[]) => setAttrs({ src: items[0].url, alt: items[0].alt || undefined, mediaId: items[0].id });
|
|
209
|
-
const drop = useFileDrop("image", select);
|
|
210
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");
|
|
211
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)
|
|
212
287
|
const st = normalizeStyle(a.style);
|
|
213
288
|
if (!src && !a.overlay && !st?.color?.background && !st?.gradient && !st?.background?.image) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
<
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
))}
|
|
223
|
-
</div>
|
|
224
|
-
</div>
|
|
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>
|
|
225
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} />;
|
|
226
299
|
}
|
|
227
300
|
const { overlay, fixed, imgStyle, overlayStyle } = coverParts(a);
|
|
228
301
|
return (
|
|
@@ -235,6 +308,7 @@ function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
|
|
|
235
308
|
}
|
|
236
309
|
|
|
237
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)
|
|
238
312
|
const a = block.attrs;
|
|
239
313
|
return (
|
|
240
314
|
<div {...shellProps(blockProps, "mediaText", a)}>
|
|
@@ -244,21 +318,37 @@ function MediaTextEdit({ block, blockProps }: BlockEditProps) {
|
|
|
244
318
|
);
|
|
245
319
|
}
|
|
246
320
|
|
|
247
|
-
/**
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
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();
|
|
251
324
|
const select = (items: MediaItem[]) => store.setAttrs([blockId], { src: items[0].url, alt: items[0].alt || undefined, mediaId: items[0].id });
|
|
252
|
-
|
|
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
|
+
};
|
|
253
337
|
return (
|
|
254
|
-
<div
|
|
255
|
-
<
|
|
256
|
-
<
|
|
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>
|
|
257
345
|
</div>
|
|
258
346
|
);
|
|
259
347
|
}
|
|
260
348
|
|
|
261
|
-
function TableEdit(
|
|
349
|
+
function TableEdit(props: BlockEditProps) {
|
|
350
|
+
const { block, blockProps } = props;
|
|
351
|
+
if (!block.content?.length && props.editable) return <TableSetup {...props} />;
|
|
262
352
|
return (
|
|
263
353
|
<div {...merge(blockProps, "ecx-table table-wrap")}>
|
|
264
354
|
<table className={block.attrs.fixed ? "is-fixed" : undefined}><tbody><InnerBlocks parent={block} appender="none" /></tbody></table>
|
|
@@ -274,7 +364,8 @@ function CellEdit({ block, blockProps }: BlockEditProps) {
|
|
|
274
364
|
return <Tag {...(blockProps as object)} colSpan={span(block.attrs.colspan)} rowSpan={span(block.attrs.rowspan)}><InnerBlocks parent={block} appender="none" /></Tag>;
|
|
275
365
|
}
|
|
276
366
|
|
|
277
|
-
|
|
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 } : {}, []);
|
|
278
369
|
const columns = (...widths: number[]) => makeBlock("columns", {}, widths.map((w) => col(w)));
|
|
279
370
|
const cell = (header = false) => makeBlock(header ? "tableHeader" : "tableCell", {}, [makeBlock("paragraph")]);
|
|
280
371
|
|
|
@@ -296,13 +387,13 @@ export function layoutBlocks(): BlockType[] {
|
|
|
296
387
|
{
|
|
297
388
|
name: "columns", title: "Cột", icon: Columns2, category: "design", keywords: "cot columns bo cuc layout", kind: "container", edit: ColumnsEdit,
|
|
298
389
|
attributes: { verticalAlign: { type: "string", enum: ["top", "center", "bottom"] }, stack: { type: "boolean", default: true } },
|
|
299
|
-
create: () => columns(
|
|
390
|
+
create: () => columns(0, 0), contextToolbar: ColumnsTools,
|
|
300
391
|
variations: [
|
|
301
|
-
{ name: "50-50", title: "50 / 50", icon: Columns2, create: () => columns(
|
|
302
|
-
{ name: "33-33-33", title: "33 / 33 / 33", icon: Columns3, 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) },
|
|
303
394
|
{ name: "33-66", title: "33 / 66", icon: LayoutPanelLeft, create: () => columns(33, 67) },
|
|
304
395
|
{ name: "66-33", title: "66 / 33", icon: LayoutPanelLeft, create: () => columns(67, 33) },
|
|
305
|
-
{ name: "25x4", title: "25 / 25 / 25 / 25", icon: Columns4, create: () => columns(
|
|
396
|
+
{ name: "25x4", title: "25 / 25 / 25 / 25", icon: Columns4, create: () => columns(0, 0, 0, 0) },
|
|
306
397
|
],
|
|
307
398
|
supports: { style: true, anchor: true, className: true },
|
|
308
399
|
},
|
|
@@ -341,7 +432,7 @@ export function layoutBlocks(): BlockType[] {
|
|
|
341
432
|
},
|
|
342
433
|
{
|
|
343
434
|
name: "tabs", title: "Tabs", icon: PanelTop, category: "text", keywords: "tabs the tab chuyen doi noi dung", kind: "container", edit: TabsEdit,
|
|
344
|
-
create: () => makeBlock("tabs", {}, [makeBlock("tab", { title: "
|
|
435
|
+
create: () => makeBlock("tabs", {}, [makeBlock("tab", { title: "" }, [makeBlock("paragraph")]), makeBlock("tab", { title: "" }, [makeBlock("paragraph")])]), supports: { style: true, anchor: true, className: true },
|
|
345
436
|
},
|
|
346
437
|
{
|
|
347
438
|
name: "tab", title: "Tab", icon: PanelTop, category: "text", keywords: "tab", kind: "container", edit: TabEdit, hidden: true, structure: { parents: ["tabs"] },
|
|
@@ -373,12 +464,12 @@ export function layoutBlocks(): BlockType[] {
|
|
|
373
464
|
{
|
|
374
465
|
name: "mediaText", title: "Ảnh + chữ", icon: LayoutPanelLeft, category: "media", keywords: "anh chu media text", kind: "container", edit: MediaTextEdit,
|
|
375
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 } },
|
|
376
|
-
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 },
|
|
377
468
|
},
|
|
378
469
|
{
|
|
379
470
|
name: "table", title: "Bảng", icon: Table2, category: "text", keywords: "bang table", kind: "container", edit: TableEdit,
|
|
380
471
|
attributes: { footer: { type: "boolean", default: false }, fixed: { type: "boolean", default: false } },
|
|
381
|
-
create: () => makeBlock("table", {}, [
|
|
472
|
+
create: () => makeBlock("table", {}, []), contextToolbar: TableTools,
|
|
382
473
|
supports: { style: true, anchor: true, className: true, blockStyle: true },
|
|
383
474
|
},
|
|
384
475
|
{ name: "tableRow", title: "Hàng", icon: Table2, kind: "container", edit: RowEdit, hidden: true },
|