@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
package/src/v2/blocks/layout.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import { colorCss, 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
3
|
import type { CSSProperties } from "react";
|
|
4
4
|
import { InnerBlocks } from "../canvas/block-list";
|
|
5
|
+
import { withoutOverridden } from "./inline-style";
|
|
5
6
|
import { makeBlock } from "../core/model";
|
|
6
7
|
import type { BlockEditProps, BlockType } from "../core/registry";
|
|
7
8
|
import { RichText } from "../text/rich-text";
|
|
@@ -15,18 +16,21 @@ import { ToolButton } from "../ui/toolbar";
|
|
|
15
16
|
import { MediaActions, useFileDrop } from "./media-actions";
|
|
16
17
|
import type { MediaItem } from "../../shared/types";
|
|
17
18
|
import { LayoutGrid, Rows3, Columns3 as RowIcon } from "lucide-react";
|
|
19
|
+
import { useMsgs } from "../i18n";
|
|
18
20
|
|
|
19
21
|
const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
|
|
20
22
|
const PADDING: Record<string, string> = { none: "0", small: "0.75rem", medium: "1.5rem", large: "3rem" };
|
|
21
23
|
const TONES: Record<string, string> = { info: "#2563eb", success: "#16a34a", warning: "#d97706", danger: "#dc2626" };
|
|
22
|
-
|
|
24
|
+
/** Gộp props của khối với class + style inline riêng; `attrs` có `style` thì bỏ phần inline mà kiểu dáng đã thay (khớp website). */
|
|
25
|
+
const merge = (bp: BlockEditProps["blockProps"], className: string, style?: CSSProperties, attrs?: Record<string, unknown>) =>
|
|
26
|
+
({ ...bp, className: cx(bp.className, className), style: { ...(bp.style ?? {}), ...(attrs?.style ? withoutOverridden(style ?? {}, attrs.style) : style) } });
|
|
23
27
|
|
|
24
28
|
function GroupEdit({ block, blockProps }: BlockEditProps) {
|
|
25
29
|
const a = block.attrs;
|
|
26
30
|
const bg = colorCss(a.background), fg = colorCss(a.textColor);
|
|
27
31
|
const pad = PADDING[a.padding as string] ?? (bg ? PADDING.medium : undefined);
|
|
28
32
|
return (
|
|
29
|
-
<div {...merge(blockProps, cx("ecx-group cms-group", a.padding && `ecx-group-${a.padding} cms-group-${a.padding}`), { background: bg, color: fg, padding: pad, borderRadius: bg ? 12 : undefined })}>
|
|
33
|
+
<div {...merge(blockProps, cx("ecx-group cms-group", a.padding && `ecx-group-${a.padding} cms-group-${a.padding}`), { background: bg, color: fg, padding: pad, borderRadius: bg ? 12 : undefined }, a)}>
|
|
30
34
|
<InnerBlocks parent={block} />
|
|
31
35
|
</div>
|
|
32
36
|
);
|
|
@@ -36,8 +40,8 @@ function GroupEdit({ block, blockProps }: BlockEditProps) {
|
|
|
36
40
|
function GroupLayoutTools({ attrs, setAttrs, labels }: BlockEditProps) {
|
|
37
41
|
const style: BlockStyle = normalizeStyle(attrs.style) ?? {};
|
|
38
42
|
const kind = layoutKind(style.layout);
|
|
39
|
-
const
|
|
40
|
-
const items: Array<["flow" | "row" | "stack" | "grid", typeof Square, string]> = [["flow", Square,
|
|
43
|
+
const t = useMsgs("blocks");
|
|
44
|
+
const items: Array<["flow" | "row" | "stack" | "grid", typeof Square, string]> = [["flow", Square, t.group], ["row", RowIcon, t.row], ["stack", Rows3, t.stack], ["grid", LayoutGrid, t.grid]];
|
|
41
45
|
return (
|
|
42
46
|
<>
|
|
43
47
|
{items.map(([k, I, label]) => (
|
|
@@ -50,16 +54,17 @@ const groupWith = (layout?: BlockStyle["layout"], kids = 1) => makeBlock("group"
|
|
|
50
54
|
|
|
51
55
|
function ColumnsEdit({ block, blockProps, editable, labels }: BlockEditProps) {
|
|
52
56
|
const { store } = useEditor();
|
|
57
|
+
const t = useMsgs("blocks");
|
|
53
58
|
const a = block.attrs;
|
|
54
59
|
const stack = a.stack !== false;
|
|
55
60
|
const active = useActiveWithin(block.id);
|
|
56
61
|
const alignItems = a.verticalAlign === "center" ? "center" : a.verticalAlign === "bottom" ? "flex-end" : "flex-start";
|
|
57
62
|
return (
|
|
58
|
-
<div {...merge(blockProps, cx("ecx-columns cms-columns", a.verticalAlign && `ecx-columns-${a.verticalAlign}`, stack && "is-stack"), { display: "flex", flexWrap: stack ? "wrap" : "nowrap", gap: "1.5rem", alignItems, position: "relative" })}>
|
|
63
|
+
<div {...merge(blockProps, cx("ecx-columns cms-columns", a.verticalAlign && `ecx-columns-${a.verticalAlign}`, stack && "is-stack"), { display: "flex", flexWrap: stack ? "wrap" : "nowrap", gap: "1.5rem", alignItems, position: "relative" }, block.attrs)}>
|
|
59
64
|
<InnerBlocks parent={block} appender="none" />
|
|
60
65
|
{active && editable && block.content!.length > 1 && <ColumnHandles block={block} />}
|
|
61
66
|
{active && editable && block.content!.length < 6 && store.canInsertInto(block.id) && (
|
|
62
|
-
<button type="button" className="ecx-add-column" contentEditable={false} title={
|
|
67
|
+
<button type="button" className="ecx-add-column" contentEditable={false} title={t.addColumn} aria-label={t.addColumn}
|
|
63
68
|
onMouseDown={(e) => { e.preventDefault(); e.stopPropagation(); }} onClick={() => addColumnTo(store, block)}>+</button>
|
|
64
69
|
)}
|
|
65
70
|
</div>
|
|
@@ -69,7 +74,7 @@ function ColumnsEdit({ block, blockProps, editable, labels }: BlockEditProps) {
|
|
|
69
74
|
function ColumnEdit({ block, blockProps }: BlockEditProps) {
|
|
70
75
|
const w = Number(block.attrs.width) > 0 ? Number(block.attrs.width) : 1;
|
|
71
76
|
return (
|
|
72
|
-
<div {...merge(blockProps, "ecx-column cms-column", { flex: `${w} 1 0`, minWidth: "min(100%, 14rem)" })}>
|
|
77
|
+
<div {...merge(blockProps, "ecx-column cms-column", { flex: `${w} 1 0`, minWidth: "min(100%, 14rem)" }, block.attrs)}>
|
|
73
78
|
<InnerBlocks parent={block} />
|
|
74
79
|
</div>
|
|
75
80
|
);
|
|
@@ -89,7 +94,7 @@ function ButtonEdit({ block, blockProps, setAttrs, editable, labels }: BlockEdit
|
|
|
89
94
|
? { background: "var(--ecx-button-secondary-bg, var(--cms-button-secondary-bg, rgba(127,127,127,.15)))", color: "inherit" }
|
|
90
95
|
: { background: "var(--ecx-button-bg, var(--cms-button-bg, var(--primary, #18181b)))", color: "var(--ecx-button-fg, var(--cms-button-fg, #fff))" };
|
|
91
96
|
return (
|
|
92
|
-
<span {...merge(blockProps, cx("ecx-button cms-button", `ecx-button-${variant} cms-button-${variant}`), { display: "inline-block", padding: "0.6em 1.2em", borderRadius: 8, fontWeight: 600, lineHeight: 1.2, ...look })}>
|
|
97
|
+
<span {...merge(blockProps, cx("ecx-button cms-button", `ecx-button-${variant} cms-button-${variant}`), { display: "inline-block", padding: "0.6em 1.2em", borderRadius: 8, fontWeight: 600, lineHeight: 1.2, ...look }, a)}>
|
|
93
98
|
{bound.bound ? <BoundText preview={bound} /> : <RichText blockId={block.id} field="text" tagName="span" value={String(a.text ?? "")} onChange={(v) => setAttrs({ text: v })} placeholder={labels.buttonText} placeholderAlways editable={editable} />}
|
|
94
99
|
</span>
|
|
95
100
|
);
|
|
@@ -106,7 +111,7 @@ function SeparatorEdit({ blockProps }: BlockEditProps) {
|
|
|
106
111
|
function CalloutEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
107
112
|
const tone = TONES[block.attrs.tone as string] ? (block.attrs.tone as string) : "info";
|
|
108
113
|
return (
|
|
109
|
-
<div {...merge(blockProps, cx("ecx-callout cms-callout", `ecx-callout-${tone} cms-callout-${tone}`), { borderLeft: `4px solid ${TONES[tone]}`, background: `color-mix(in srgb, ${TONES[tone]} 8%, transparent)`, padding: "0.75rem 1rem", borderRadius: 8 })} role="note">
|
|
114
|
+
<div {...merge(blockProps, cx("ecx-callout cms-callout", `ecx-callout-${tone} cms-callout-${tone}`), { borderLeft: `4px solid ${TONES[tone]}`, background: `color-mix(in srgb, ${TONES[tone]} 8%, transparent)`, padding: "0.75rem 1rem", borderRadius: 8 }, block.attrs)} role="note">
|
|
110
115
|
<RichText blockId={block.id} field="title" tagName="p" className="ecx-callout-title cms-callout-title" style={{ margin: 0, fontWeight: 600 }} value={String(block.attrs.title ?? "")} onChange={(v) => setAttrs({ title: v })} placeholder="…" editable={editable} />
|
|
111
116
|
<InnerBlocks parent={block} />
|
|
112
117
|
</div>
|
|
@@ -124,6 +129,41 @@ function DetailsEdit({ block, blockProps, setAttrs, editable }: BlockEditProps)
|
|
|
124
129
|
);
|
|
125
130
|
}
|
|
126
131
|
|
|
132
|
+
function AccordionEdit({ block, blockProps }: BlockEditProps) {
|
|
133
|
+
return <div {...(merge(blockProps, "ecx-accordion") as object)}><InnerBlocks parent={block} /></div>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function TabsEdit({ block, blockProps }: BlockEditProps) {
|
|
137
|
+
return <div {...(merge(blockProps, "ecx-tabs") as object)}><InnerBlocks parent={block} /></div>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function TabEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
141
|
+
return (
|
|
142
|
+
<div {...(merge(blockProps, "ecx-tab", { borderLeft: "3px solid rgba(127,127,127,.4)", paddingLeft: 12, marginBlock: 8 }) as object)}>
|
|
143
|
+
<RichText blockId={block.id} field="title" tagName="strong" value={String(block.attrs.title ?? "")} onChange={(v) => setAttrs({ title: v })} placeholder="Tab…" placeholderAlways editable={editable} />
|
|
144
|
+
<InnerBlocks parent={block} />
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function CarouselEdit({ block, blockProps }: BlockEditProps) {
|
|
150
|
+
return <div {...(merge(blockProps, "ecx-carousel") as object)}><InnerBlocks parent={block} /></div>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function ShortcodeEdit({ block, blockProps }: BlockEditProps) {
|
|
154
|
+
return <div {...(merge(blockProps, "ecx-shortcode", { fontFamily: "monospace", opacity: 0.8 }) as object)}>[{String(block.attrs.name || "shortcode")}]</div>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function CountdownEdit({ block, blockProps }: BlockEditProps) {
|
|
158
|
+
const a = block.attrs;
|
|
159
|
+
return <div {...(merge(blockProps, "ecx-countdown", { textAlign: "center" }) as object)}>{a.label ? <p style={{ margin: 0 }}>{String(a.label)}</p> : null}<strong>{a.target ? String(a.target) : "00 : 00 : 00 : 00"}</strong></div>;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function RatingEdit({ block, blockProps }: BlockEditProps) {
|
|
163
|
+
const max = Math.min(10, Math.max(1, Number(block.attrs.max) || 5)), v = Number(block.attrs.value) || 0;
|
|
164
|
+
return <div {...(merge(blockProps, "ecx-rating") as object)} aria-label={`${v}/${max}`}>{Array.from({ length: max }, (_, i) => <span key={i} style={{ color: i < Math.round(v) ? "#f59e0b" : "#d4d4d8" }}>★</span>)}</div>;
|
|
165
|
+
}
|
|
166
|
+
|
|
127
167
|
function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
|
|
128
168
|
const a = block.attrs;
|
|
129
169
|
const src = typeof a.src === "string" ? a.src : "";
|
|
@@ -132,15 +172,15 @@ function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
|
|
|
132
172
|
const drop = useFileDrop("image", select);
|
|
133
173
|
// 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)
|
|
134
174
|
if (!src && !a.overlay) {
|
|
135
|
-
const
|
|
175
|
+
const t = useMsgs("blocks");
|
|
136
176
|
return (
|
|
137
177
|
<div {...merge(blockProps, cx("ecx-media-placeholder ecx-cover-placeholder", drop.over && "is-drop-target"))} {...drop.props}>
|
|
138
|
-
<span className="ecx-placeholder-title"><ImageIcon className="ecx-icon" />{
|
|
139
|
-
<p className="ecx-placeholder-hint">{
|
|
178
|
+
<span className="ecx-placeholder-title"><ImageIcon className="ecx-icon" />{t.cover}</span>
|
|
179
|
+
<p className="ecx-placeholder-hint">{t.pickABackgroundImage}</p>
|
|
140
180
|
<MediaActions kind="image" onSelect={select} onUrl={(url) => setAttrs({ src: url })} />
|
|
141
181
|
<div className="ecx-chip-row" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
|
|
142
182
|
{Object.entries(host.presets?.colors ?? { primary: "#1a597b", black: "#111", muted: "#757575" }).map(([name, c]) => (
|
|
143
|
-
<button key={name} type="button" className="ecx-chip ecx-chip-swatch" title={name} aria-label={`${
|
|
183
|
+
<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 })} />
|
|
144
184
|
))}
|
|
145
185
|
</div>
|
|
146
186
|
</div>
|
|
@@ -148,7 +188,7 @@ function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
|
|
|
148
188
|
}
|
|
149
189
|
const overlay = colorCss(a.overlay) ?? (src ? "#000" : undefined);
|
|
150
190
|
return (
|
|
151
|
-
<div {...merge(blockProps, cx("ecx-cover", a.contentAlign && a.contentAlign !== "center" && `is-${a.contentAlign}`, a.fixed && src && "is-fixed"), { minHeight: spacingValue(a.minHeight ?? "400px") })}>
|
|
191
|
+
<div {...merge(blockProps, cx("ecx-cover", a.contentAlign && a.contentAlign !== "center" && `is-${a.contentAlign}`, a.fixed && src && "is-fixed"), { minHeight: spacingValue(a.minHeight ?? "400px") }, a)}>
|
|
152
192
|
{src && <img className="ecx-cover-img" src={src} alt={String(a.alt ?? "")} draggable={false} />}
|
|
153
193
|
{overlay && <span className="ecx-cover-overlay" aria-hidden="true" style={{ background: overlay, opacity: Math.min(100, Math.max(0, Number(a.opacity ?? 50))) / 100 }} />}
|
|
154
194
|
<div className="ecx-cover-inner"><InnerBlocks parent={block} /></div>
|
|
@@ -257,6 +297,36 @@ export function layoutBlocks(): BlockType[] {
|
|
|
257
297
|
attributes: { summary: { type: "string" }, open: { type: "boolean", default: false } },
|
|
258
298
|
create: () => makeBlock("details", {}, [makeBlock("paragraph")]), supports: { style: true, anchor: true, className: true },
|
|
259
299
|
},
|
|
300
|
+
{
|
|
301
|
+
name: "accordion", title: "Accordion", icon: PanelTop, category: "text", keywords: "accordion faq hoi dap nhieu muc", kind: "container", edit: AccordionEdit,
|
|
302
|
+
attributes: { multiple: { type: "boolean", default: false } },
|
|
303
|
+
create: () => makeBlock("accordion", {}, [makeBlock("details", { summary: "" }, [makeBlock("paragraph")]), makeBlock("details", { summary: "" }, [makeBlock("paragraph")])]), supports: { style: true, anchor: true, className: true },
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
name: "tabs", title: "Tabs", icon: PanelTop, category: "text", keywords: "tabs the tab chuyen doi noi dung", kind: "container", edit: TabsEdit,
|
|
307
|
+
create: () => makeBlock("tabs", {}, [makeBlock("tab", { title: "" }, [makeBlock("paragraph")]), makeBlock("tab", { title: "" }, [makeBlock("paragraph")])]), supports: { style: true, anchor: true, className: true },
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
name: "tab", title: "Tab", icon: PanelTop, category: "text", keywords: "tab", kind: "container", edit: TabEdit, hidden: true, structure: { parents: ["tabs"] },
|
|
311
|
+
attributes: { title: { type: "string" } }, create: () => makeBlock("tab", { title: "" }, [makeBlock("paragraph")]),
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
name: "carousel", title: "Carousel", icon: Columns3, category: "design", keywords: "carousel slider slide truot anh", kind: "container", edit: CarouselEdit,
|
|
315
|
+
attributes: { slidesPerView: { type: "integer", default: 1, min: 1, max: 4 } },
|
|
316
|
+
create: () => makeBlock("carousel", { slidesPerView: 1 }, [makeBlock("group", {}, [makeBlock("paragraph")]), makeBlock("group", {}, [makeBlock("paragraph")])]), supports: { style: true, anchor: true, className: true },
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
name: "shortcode", title: "Shortcode", icon: Square, category: "design", keywords: "shortcode ma nhung plugin", kind: "atom", edit: ShortcodeEdit,
|
|
320
|
+
attributes: { name: { type: "string" }, args: { type: "json", default: {} } }, supports: { style: true, anchor: true, className: true },
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
name: "countdown", title: "Đếm ngược", icon: Square, category: "design", keywords: "dem nguoc countdown khuyen mai sale", kind: "atom", edit: CountdownEdit,
|
|
324
|
+
attributes: { target: { type: "string" }, label: { type: "string" }, expiredText: { type: "string" } }, supports: { style: true, anchor: true, className: true },
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
name: "rating", title: "Đánh giá sao", icon: Square, category: "design", keywords: "danh gia sao rating review", kind: "atom", edit: RatingEdit,
|
|
328
|
+
attributes: { value: { type: "number", default: 5, min: 0, max: 10 }, max: { type: "integer", default: 5, min: 1, max: 10 }, label: { type: "string" } }, supports: { style: true, anchor: true, className: true },
|
|
329
|
+
},
|
|
260
330
|
{
|
|
261
331
|
name: "cover", title: "Ảnh bìa", icon: ImageIcon, category: "media", keywords: "anh bia cover banner hero", kind: "container", edit: CoverEdit,
|
|
262
332
|
attributes: { src: { type: "url", control: "media" }, alt: { type: "string" }, overlay: { type: "string", control: "color" }, opacity: { type: "integer", default: 50, min: 0, max: 100 }, minHeight: { type: "string", default: "400px" }, contentAlign: { type: "string", enum: ["top", "center", "bottom"], default: "center" }, fixed: { type: "boolean", default: false } },
|
package/src/v2/blocks/media.tsx
CHANGED
|
@@ -8,6 +8,8 @@ import { BoundText, useBindingPreview } from "../ui/bindings";
|
|
|
8
8
|
import { ImageHandle } from "./resize";
|
|
9
9
|
import { MediaActions, mediaAttrs, useFileDrop } from "./media-actions";
|
|
10
10
|
import type { MediaItem, MediaKind } from "../../shared/types";
|
|
11
|
+
import { useMsgs } from "../i18n";
|
|
12
|
+
import { format } from "../../i18n";
|
|
11
13
|
|
|
12
14
|
const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
|
|
13
15
|
const safe = (u: unknown) => (typeof u === "string" && isSafeUrl(u) ? u : "");
|
|
@@ -79,14 +81,14 @@ function YoutubeEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
|
|
|
79
81
|
const m = String(block.attrs.src ?? "").match(/(?:v=|youtu\.be\/|embed\/)([\w-]{11})/);
|
|
80
82
|
const [draft, setDraft] = useState("");
|
|
81
83
|
if (!m) {
|
|
82
|
-
const
|
|
84
|
+
const t = useMsgs("blocks");
|
|
83
85
|
return (
|
|
84
86
|
<div {...blockProps} className={cx(blockProps.className, "ecx-media-placeholder")}>
|
|
85
87
|
<span className="ecx-placeholder-title"><Play className="ecx-icon" />YouTube</span>
|
|
86
|
-
<p className="ecx-placeholder-hint">{
|
|
88
|
+
<p className="ecx-placeholder-hint">{t.pasteAYoutubeLink}</p>
|
|
87
89
|
<form className="ecx-media-actions" contentEditable={false} onMouseDown={(e) => e.stopPropagation()} onSubmit={(e) => { e.preventDefault(); if (/(?:v=|youtu\.be\/|embed\/)[\w-]{11}/.test(draft)) setAttrs({ src: draft.trim() }); }}>
|
|
88
90
|
<input className="ecx-input" type="url" placeholder="https://youtu.be/…" value={draft} onChange={(e) => setDraft(e.target.value)} aria-label="YouTube URL" />
|
|
89
|
-
<button type="submit" className="ecx-btn ecx-btn-primary">{
|
|
91
|
+
<button type="submit" className="ecx-btn ecx-btn-primary">{t.embed}</button>
|
|
90
92
|
</form>
|
|
91
93
|
</div>
|
|
92
94
|
);
|
|
@@ -143,13 +145,14 @@ type SocialLink = { service: string; url: string; label?: string };
|
|
|
143
145
|
const linksOf = (a: Record<string, unknown>) => (Array.isArray(a.links) ? a.links : []) as SocialLink[];
|
|
144
146
|
|
|
145
147
|
function SocialEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
148
|
+
const t = useMsgs("blocks");
|
|
146
149
|
const links = linksOf(block.attrs).filter((l) => l.url);
|
|
147
150
|
const a = block.attrs;
|
|
148
151
|
if (!links.length) {
|
|
149
152
|
return (
|
|
150
153
|
<div {...(blockProps as object)} className={cx(blockProps.className, "ecx-placeholder-block")}>
|
|
151
|
-
<span className="ecx-placeholder-title"><Share2 className="ecx-icon" /> {
|
|
152
|
-
<span className="ecx-placeholder-summary">{
|
|
154
|
+
<span className="ecx-placeholder-title"><Share2 className="ecx-icon" /> {t.socialLinks}</span>
|
|
155
|
+
<span className="ecx-placeholder-summary">{t.addLinksInThe}</span>
|
|
153
156
|
</div>
|
|
154
157
|
);
|
|
155
158
|
}
|
|
@@ -163,38 +166,39 @@ function SocialEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
|
163
166
|
/** Danh sách liên kết mạng xã hội trong bảng cài đặt: chọn mạng, dán địa chỉ, đổi thứ tự, xoá. */
|
|
164
167
|
function SocialInspector({ attrs, setAttrs, labels }: BlockEditProps) {
|
|
165
168
|
const links = linksOf(attrs);
|
|
166
|
-
const
|
|
169
|
+
const t = useMsgs("blocks");
|
|
167
170
|
const save = (next: SocialLink[]) => setAttrs({ links: next });
|
|
168
171
|
const patch = (i: number, p: Partial<SocialLink>) => save(links.map((l, k) => (k === i ? { ...l, ...p } : l)));
|
|
169
172
|
const move = (i: number, d: -1 | 1) => { const n = [...links]; [n[i], n[i + d]] = [n[i + d], n[i]]; save(n); };
|
|
170
173
|
return (
|
|
171
|
-
<div className="ecx-social-editor" role="group" aria-label={
|
|
172
|
-
<span className="ecx-field-label">{
|
|
174
|
+
<div className="ecx-social-editor" role="group" aria-label={t.socialLinks2}>
|
|
175
|
+
<span className="ecx-field-label">{t.links}</span>
|
|
173
176
|
{links.map((l, i) => (
|
|
174
177
|
<div key={i} className="ecx-social-row" data-social-row={i}>
|
|
175
|
-
<select className="ecx-input" aria-label={
|
|
178
|
+
<select className="ecx-input" aria-label={format(t.network, { n: i + 1 })} value={l.service} onChange={(e) => patch(i, { service: e.target.value })}>
|
|
176
179
|
{SOCIAL.map(([v, n]) => <option key={v} value={v}>{n}</option>)}
|
|
177
180
|
</select>
|
|
178
|
-
<input className="ecx-input" type="url" aria-label={
|
|
181
|
+
<input className="ecx-input" type="url" aria-label={format(t.urlN, { n: i + 1 })} placeholder={l.service === "email" ? "mailto:ban@congty.vn" : "https://…"} value={l.url}
|
|
179
182
|
aria-invalid={!!l.url && !isSafeUrl(l.url) || undefined} onChange={(e) => patch(i, { url: e.target.value.trim() })} />
|
|
180
183
|
<span className="ecx-social-row-tools">
|
|
181
|
-
<button type="button" className="ecx-tool" aria-label={
|
|
182
|
-
<button type="button" className="ecx-tool" aria-label={
|
|
183
|
-
<button type="button" className="ecx-tool" aria-label={
|
|
184
|
+
<button type="button" className="ecx-tool" aria-label={t.up} disabled={i === 0} onClick={() => move(i, -1)}><ArrowUp className="ecx-icon ecx-icon-sm" /></button>
|
|
185
|
+
<button type="button" className="ecx-tool" aria-label={t.down} disabled={i === links.length - 1} onClick={() => move(i, 1)}><ArrowDown className="ecx-icon ecx-icon-sm" /></button>
|
|
186
|
+
<button type="button" className="ecx-tool" aria-label={t.removeLink} onClick={() => save(links.filter((_, k) => k !== i))}><X className="ecx-icon ecx-icon-sm" /></button>
|
|
184
187
|
</span>
|
|
185
188
|
</div>
|
|
186
189
|
))}
|
|
187
190
|
<button type="button" className="ecx-btn" onClick={() => save([...links, { service: SOCIAL.find(([v]) => !links.some((l) => l.service === v))?.[0] ?? "website", url: "" }])}>
|
|
188
|
-
<Plus className="ecx-icon ecx-icon-sm" /> {
|
|
191
|
+
<Plus className="ecx-icon ecx-icon-sm" /> {t.addLink}
|
|
189
192
|
</button>
|
|
190
193
|
</div>
|
|
191
194
|
);
|
|
192
195
|
}
|
|
193
196
|
|
|
194
197
|
function TocEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
198
|
+
const t = useMsgs("blocks");
|
|
195
199
|
return (
|
|
196
200
|
<nav {...(blockProps as object)} className={cx(blockProps.className, "ecx-toc")}>
|
|
197
|
-
<p className="ecx-toc-title">{String(block.attrs.title || (
|
|
201
|
+
<p className="ecx-toc-title">{String(block.attrs.title || (t.contents))}</p>
|
|
198
202
|
<TocItems maxLevel={Math.min(4, Math.max(2, Number(block.attrs.maxLevel) || 3))} />
|
|
199
203
|
</nav>
|
|
200
204
|
);
|
|
@@ -218,10 +222,10 @@ export function mediaBlocks(): BlockType[] {
|
|
|
218
222
|
return [
|
|
219
223
|
{
|
|
220
224
|
name: "image", title: "Ảnh", icon: ImageIcon, category: "media", keywords: "anh hinh image photo", kind: "atom", edit: ImageEdit,
|
|
221
|
-
attributes: { ...media, alt: { type: "string", control: "textarea" }, title: { type: "string" }, width: { type: "number" }, height: { type: "number" }, size: { type: "string", default: "large" }, align: { type: "string", enum: ["left", "right", "center", "wide", "full"] }, href: { type: "url" }, linkTarget: { type: "string", enum: ["_self", "_blank"] } },
|
|
225
|
+
attributes: { ...media, alt: { type: "string", control: "textarea" }, title: { type: "string" }, width: { type: "number" }, height: { type: "number" }, size: { type: "string", default: "large" }, align: { type: "string", enum: ["left", "right", "center", "wide", "full"] }, href: { type: "url" }, linkTarget: { type: "string", enum: ["_self", "_blank"] }, lightbox: { type: "boolean", default: false } },
|
|
222
226
|
supports: { style: true, anchor: true, className: true, blockStyle: true }, summary: (a) => a.alt || a.src,
|
|
223
227
|
},
|
|
224
|
-
{ name: "gallery", title: "Gallery", icon: Images, category: "media", keywords: "gallery bo suu tap nhieu anh album", kind: "atom", edit: GalleryEdit, attributes: { images: { type: "json", default: [] }, columns: { type: "integer", default: 3, min: 1, max: 6 }, caption: { type: "string" } }, supports: { style: true, anchor: true, className: true } },
|
|
228
|
+
{ name: "gallery", title: "Gallery", icon: Images, category: "media", keywords: "gallery bo suu tap nhieu anh album", kind: "atom", edit: GalleryEdit, attributes: { images: { type: "json", default: [] }, columns: { type: "integer", default: 3, min: 1, max: 6 }, caption: { type: "string" }, linkTo: { type: "string", enum: ["none", "media"], default: "media" }, imageCrop: { type: "boolean", default: true }, lightbox: { type: "boolean", default: false } }, supports: { style: true, anchor: true, className: true } },
|
|
225
229
|
{ name: "video", title: "Video", icon: Video, category: "media", keywords: "video mp4 phim", kind: "atom", edit: VideoEdit, attributes: { ...media, name: { type: "string" }, mime: { type: "string" }, poster: { type: "url", control: "media" }, autoplay: { type: "boolean", default: false }, loop: { type: "boolean", default: false }, muted: { type: "boolean", default: false }, controls: { type: "boolean", default: true }, playsInline: { type: "boolean", default: true }, preload: { type: "string", enum: ["none", "metadata", "auto"], default: "metadata" } }, supports: { style: true, anchor: true } },
|
|
226
230
|
{ name: "audio", title: "Âm thanh", icon: Music, category: "media", keywords: "am thanh audio nhac mp3 podcast", kind: "atom", edit: AudioEdit, attributes: { ...media, name: { type: "string" }, mime: { type: "string" }, autoplay: { type: "boolean", default: false }, loop: { type: "boolean", default: false }, preload: { type: "string", enum: ["none", "metadata", "auto"], default: "metadata" } }, supports: { style: true, anchor: true } },
|
|
227
231
|
{ name: "file", title: "Tệp", icon: FileIcon, category: "media", keywords: "tep file pdf tai xuong download tai lieu", kind: "atom", edit: FileEdit, attributes: { ...media, name: { type: "string" }, mime: { type: "string" }, size: { type: "number" }, embed: { type: "boolean", default: true }, download: { type: "boolean" } }, supports: { style: true, anchor: true } },
|
package/src/v2/blocks/theme.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import type { DynamicPost, QueryArgs } from "../core/host";
|
|
|
6
6
|
import type { BNode } from "../core/model";
|
|
7
7
|
import { makeBlock } from "../core/model";
|
|
8
8
|
import type { BlockEditProps, BlockType } from "../core/registry";
|
|
9
|
+
import { useMsgs } from "../i18n";
|
|
9
10
|
|
|
10
11
|
const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
|
|
11
12
|
const align = (a: Record<string, unknown>): CSSProperties | undefined => (typeof a.textAlign === "string" ? { textAlign: a.textAlign as CSSProperties["textAlign"] } : undefined);
|
|
@@ -37,12 +38,12 @@ function NavigationEdit({ block, blockProps }: BlockEditProps) {
|
|
|
37
38
|
const location = String(block.attrs.location ?? "primary");
|
|
38
39
|
const items = d.menus?.[location];
|
|
39
40
|
const mobile = block.attrs.mobile !== false;
|
|
40
|
-
const
|
|
41
|
+
const t = useMsgs("blocks");
|
|
41
42
|
if (!items?.length) {
|
|
42
43
|
return (
|
|
43
44
|
<div {...merge(blockProps, "ecx-navigation ecx-placeholder-block")}>
|
|
44
|
-
<span className="ecx-placeholder-title"><Menu className="ecx-icon" /> {
|
|
45
|
-
<span className="ecx-placeholder-summary">{
|
|
45
|
+
<span className="ecx-placeholder-title"><Menu className="ecx-icon" /> {t.menu} · {location}</span>
|
|
46
|
+
<span className="ecx-placeholder-summary">{t.noMenuIsAssigned}</span>
|
|
46
47
|
</div>
|
|
47
48
|
);
|
|
48
49
|
}
|
|
@@ -50,7 +51,7 @@ function NavigationEdit({ block, blockProps }: BlockEditProps) {
|
|
|
50
51
|
return (
|
|
51
52
|
<div {...merge(blockProps, cx("ecx-navigation", `ecx-navigation-${block.attrs.orientation ?? "horizontal"}`, mobile && "has-mobile"))}>
|
|
52
53
|
<div className="ecx-navigation-items">{menu}</div>
|
|
53
|
-
{mobile && <details className="ecx-navigation-toggle"><summary aria-label={
|
|
54
|
+
{mobile && <details className="ecx-navigation-toggle"><summary aria-label={t.menu}>☰</summary>{menu}</details>}
|
|
54
55
|
</div>
|
|
55
56
|
);
|
|
56
57
|
}
|
|
@@ -99,6 +100,20 @@ function PostTermsEdit({ block, blockProps }: BlockEditProps) {
|
|
|
99
100
|
const d = useDynamic();
|
|
100
101
|
return <p {...merge(blockProps, "ecx-post-terms")}>{(d.post?.terms?.length ? d.post.terms : block.attrs.taxonomy === "post_tag" ? ["Thẻ A", "Thẻ B"] : ["Chuyên mục A", "Chuyên mục B"]).join(String(block.attrs.separator ?? ", "))}</p>;
|
|
101
102
|
}
|
|
103
|
+
function ReadMoreEdit({ block, blockProps }: BlockEditProps) {
|
|
104
|
+
return <p {...merge(blockProps, "ecx-read-more", align(block.attrs))}><a href="#" onClick={(e) => e.preventDefault()}>{String(block.attrs.text || "Đọc tiếp")}</a></p>;
|
|
105
|
+
}
|
|
106
|
+
function CommentsCountEdit({ block, blockProps }: BlockEditProps) {
|
|
107
|
+
const d = useDynamic();
|
|
108
|
+
return <p {...merge(blockProps, "ecx-comments-count", align(block.attrs))}>{d.post?.comments ?? 0}</p>;
|
|
109
|
+
}
|
|
110
|
+
function AvatarEdit({ block, blockProps }: BlockEditProps) {
|
|
111
|
+
const size = Math.min(256, Math.max(16, Number(block.attrs.size) || 48));
|
|
112
|
+
return <span {...merge(blockProps, "ecx-avatar")}><span style={{ display: "inline-block", width: size, height: size, borderRadius: "50%", background: "rgba(127,127,127,.3)" }} /></span>;
|
|
113
|
+
}
|
|
114
|
+
function QueryTotalEdit({ blockProps, block }: BlockEditProps) {
|
|
115
|
+
return <p {...merge(blockProps, "ecx-query-total", align(block.attrs))}>0</p>;
|
|
116
|
+
}
|
|
102
117
|
function CommentsEdit({ blockProps }: BlockEditProps) {
|
|
103
118
|
const d = useDynamic();
|
|
104
119
|
return <div {...merge(blockProps, "ecx-comments")}><MessageSquare className="ecx-icon" /> {d.post?.comments ?? 0}</div>;
|
|
@@ -106,20 +121,21 @@ function CommentsEdit({ blockProps }: BlockEditProps) {
|
|
|
106
121
|
/** Tiêu đề trang lưu trữ / tìm kiếm (H1 của trang chuyên mục, thẻ, tác giả…). */
|
|
107
122
|
function QueryTitleEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
108
123
|
const d = useDynamic();
|
|
109
|
-
const
|
|
124
|
+
const t = useMsgs("blocks");
|
|
110
125
|
const Tag = `h${Math.min(6, Math.max(1, Number(block.attrs.level) || 1))}` as "h1";
|
|
111
|
-
const name = d.archive?.title ?? (
|
|
112
|
-
return <Tag {...merge(blockProps, "ecx-query-title", align(block.attrs))}>{block.attrs.prefix ? (
|
|
126
|
+
const name = d.archive?.title ?? (t.categoryName);
|
|
127
|
+
return <Tag {...merge(blockProps, "ecx-query-title", align(block.attrs))}>{block.attrs.prefix ? (t.category) : ""}{name}</Tag>;
|
|
113
128
|
}
|
|
114
129
|
function TermDescriptionEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
130
|
+
const t = useMsgs("blocks");
|
|
115
131
|
const d = useDynamic();
|
|
116
|
-
return <div {...merge(blockProps, "ecx-term-description", align(block.attrs))}>{d.archive?.description || (
|
|
132
|
+
return <div {...merge(blockProps, "ecx-term-description", align(block.attrs))}>{d.archive?.description || (t.theDescriptionOfThe)}</div>;
|
|
117
133
|
}
|
|
118
134
|
function BreadcrumbsEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
119
135
|
const d = useDynamic();
|
|
120
|
-
const
|
|
136
|
+
const t = useMsgs("blocks");
|
|
121
137
|
const sep = String(block.attrs.separator ?? "›");
|
|
122
|
-
const items = [...(block.attrs.showHome !== false ? [
|
|
138
|
+
const items = [...(block.attrs.showHome !== false ? [t.home] : []), t.category2, ...(block.attrs.showCurrent !== false ? [d.post?.title || (t.currentPage)] : [])];
|
|
123
139
|
return (
|
|
124
140
|
<nav {...(merge(blockProps, "ecx-breadcrumbs") as object)}>
|
|
125
141
|
<ol>{items.map((t, i) => <li key={i}>{i > 0 && <span className="ecx-breadcrumbs-sep" aria-hidden="true">{sep}</span>}{i < items.length - 1 ? <a>{t}</a> : <span>{t}</span>}</li>)}</ol>
|
|
@@ -127,18 +143,19 @@ function BreadcrumbsEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
|
127
143
|
);
|
|
128
144
|
}
|
|
129
145
|
function PostNavigationEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
130
|
-
const
|
|
146
|
+
const t = useMsgs("blocks");
|
|
131
147
|
const titles = block.attrs.showTitle !== false;
|
|
132
148
|
return (
|
|
133
149
|
<nav {...(merge(blockProps, "ecx-post-navigation") as object)}>
|
|
134
|
-
<a className="ecx-post-navigation-prev"><span>{
|
|
135
|
-
<a className="ecx-post-navigation-next"><span>{
|
|
150
|
+
<a className="ecx-post-navigation-prev"><span>{t.previous}</span>{titles && <strong>{t.previousPostTitle}</strong>}</a>
|
|
151
|
+
<a className="ecx-post-navigation-next"><span>{t.next}</span>{titles && <strong>{t.nextPostTitle}</strong>}</a>
|
|
136
152
|
</nav>
|
|
137
153
|
);
|
|
138
154
|
}
|
|
139
155
|
|
|
140
156
|
function PostContentEdit({ blockProps }: BlockEditProps) {
|
|
141
157
|
const { labels } = useEditor();
|
|
158
|
+
const t = useMsgs("blocks");
|
|
142
159
|
const scope = useDocScope();
|
|
143
160
|
const frameId = useEditorState((s) => s.frameId);
|
|
144
161
|
const rootId = useEditorState((s) => s.rootId);
|
|
@@ -150,7 +167,7 @@ function PostContentEdit({ blockProps }: BlockEditProps) {
|
|
|
150
167
|
</div>
|
|
151
168
|
);
|
|
152
169
|
}
|
|
153
|
-
return <div {...merge(blockProps, "ecx-post-content ecx-content-placeholder")}><FileText className="ecx-icon" /> {
|
|
170
|
+
return <div {...merge(blockProps, "ecx-post-content ecx-content-placeholder")}><FileText className="ecx-icon" /> {t.postContent}</div>;
|
|
154
171
|
}
|
|
155
172
|
|
|
156
173
|
function QueryEdit({ block, blockProps }: BlockEditProps) {
|
|
@@ -202,15 +219,15 @@ function PostTemplateEdit({ block, blockProps, editable, labels }: BlockEditProp
|
|
|
202
219
|
const cols = Math.min(6, Math.max(1, Number(block.attrs.columns) || 3));
|
|
203
220
|
const count = posts ? Math.max(1, Math.min(posts.length, q.perPage, 6)) : 3;
|
|
204
221
|
const current = Math.min(active, count - 1);
|
|
205
|
-
const
|
|
222
|
+
const t = useMsgs("blocks");
|
|
206
223
|
return (
|
|
207
224
|
<ul {...(merge(blockProps, cx("ecx-post-template", grid && "is-grid"), grid ? { display: "grid", gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))`, gap: "1.5rem" } : undefined) as object)} data-ecx-posts={posts ? posts.length : ""}>
|
|
208
|
-
{posts && !posts.length && <li className="ecx-post ecx-post-none">{
|
|
225
|
+
{posts && !posts.length && <li className="ecx-post ecx-post-none">{t.noPostsMatchThese}</li>}
|
|
209
226
|
{Array.from({ length: count }, (_, i) => {
|
|
210
227
|
const post = posts?.[i] ?? null;
|
|
211
228
|
if (i === current) return <li key="edit" className={cx("ecx-post", count > 1 && "is-active")}><LoopPostContext.Provider value={post}><InnerBlocks parent={block} /></LoopPostContext.Provider></li>;
|
|
212
229
|
return (
|
|
213
|
-
<li key={i} className="ecx-post ecx-post-preview" data-ecx-post-index={i} title={
|
|
230
|
+
<li key={i} className="ecx-post ecx-post-preview" data-ecx-post-index={i} title={t.clickToEditThe}
|
|
214
231
|
onMouseDownCapture={(e) => { if (!editable || ui.zoomOut || e.button !== 0) return; e.preventDefault(); e.stopPropagation(); setActive(i); }}>
|
|
215
232
|
<LoopPostContext.Provider value={post}><PreviewBlocks nodes={block.content ?? []} tag={`p${i}`} /></LoopPostContext.Provider>
|
|
216
233
|
</li>
|
|
@@ -262,18 +279,22 @@ export function themeBlocks(): BlockType[] {
|
|
|
262
279
|
{ name: "siteTitle", title: "Tên website", icon: Type, category: theme, keywords: "ten website site title", kind: "atom", edit: SiteTitleEdit, attributes: { level: { type: "integer", default: 0, min: 0, max: 6 }, link: { type: "boolean", default: true }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
263
280
|
{ name: "siteLogo", title: "Logo", icon: ImageIcon, category: theme, keywords: "logo", kind: "atom", edit: SiteLogoEdit, attributes: { width: { type: "number", default: 120 }, link: { type: "boolean", default: true } }, supports: { style: true, className: true } },
|
|
264
281
|
{ name: "siteTagline", title: "Khẩu hiệu", icon: Type, category: theme, keywords: "khau hieu tagline mo ta", kind: "atom", edit: SiteTaglineEdit, attributes: { textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
265
|
-
{ name: "navigation", title: "Menu", icon: Menu, category: theme, keywords: "menu dieu huong navigation", kind: "atom", edit: NavigationEdit, attributes: { location: { type: "string", default: "primary" }, orientation: { type: "string", enum: ["horizontal", "vertical"], default: "horizontal" }, mobile: { type: "boolean", default: true } }, supports: { style: true, className: true }, summary: (a) => a.location },
|
|
282
|
+
{ name: "navigation", title: "Menu", icon: Menu, category: theme, keywords: "menu dieu huong navigation", kind: "atom", edit: NavigationEdit, attributes: { location: { type: "string", default: "primary" }, orientation: { type: "string", enum: ["horizontal", "vertical"], default: "horizontal" }, mobile: { type: "boolean", default: true }, overlayMenu: { type: "string", enum: ["never", "mobile", "always"], default: "mobile" } }, supports: { style: true, className: true }, summary: (a) => a.location },
|
|
266
283
|
{ name: "search", title: "Tìm kiếm", icon: Search, category: theme, keywords: "tim kiem search", kind: "atom", edit: SearchEdit, attributes: { placeholder: { type: "string" }, buttonText: { type: "string" } }, supports: { style: true, className: true } },
|
|
267
|
-
{ name: "languageSwitcher", title: "Chọn ngôn ngữ", icon: Globe2, category: theme, keywords: "ngon ngu language", kind: "atom", edit: LanguageEdit, supports: { style: true, className: true } },
|
|
284
|
+
{ name: "languageSwitcher", title: "Chọn ngôn ngữ", icon: Globe2, category: theme, keywords: "ngon ngu language", kind: "atom", edit: LanguageEdit, attributes: { display: { type: "string", enum: ["inline", "dropdown"], default: "inline" } }, supports: { style: true, className: true } },
|
|
268
285
|
{ name: "copyright", title: "Bản quyền", icon: Copyright, category: theme, keywords: "ban quyen copyright", kind: "atom", edit: CopyrightEdit, attributes: { text: { type: "string" }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
269
286
|
{ name: "postTitle", title: "Tiêu đề bài", icon: Type, category: theme, keywords: "tieu de bai post title", kind: "atom", edit: PostTitleEdit, attributes: { level: { type: "integer", default: 1, min: 1, max: 6 }, link: { type: "boolean", default: false }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
270
287
|
{ name: "postContent", title: "Nội dung bài", icon: FileText, category: theme, keywords: "noi dung bai post content", kind: "atom", edit: PostContentEdit },
|
|
271
288
|
{ name: "postExcerpt", title: "Tóm tắt bài", icon: FileText, category: theme, keywords: "tom tat excerpt", kind: "atom", edit: PostExcerptEdit, attributes: { moreText: { type: "string" } }, supports: { style: true, className: true } },
|
|
272
289
|
{ name: "featuredImage", title: "Ảnh đại diện", icon: ImageIcon, category: theme, keywords: "anh dai dien featured image thumbnail", kind: "atom", edit: FeaturedImageEdit, attributes: { size: { type: "string", default: "large" }, link: { type: "boolean", default: false }, aspect: { type: "string", enum: ["auto", "16/9", "4/3", "1/1", "3/4"], default: "auto" } }, supports: { style: true, className: true } },
|
|
273
290
|
{ name: "postDate", title: "Ngày đăng", icon: CalendarDays, category: theme, keywords: "ngay dang date", kind: "atom", edit: PostDateEdit, attributes: { textAlign: TEXT_ALIGN, displayType: { type: "string", enum: ["published", "modified"], default: "published" } }, supports: { style: true, className: true } },
|
|
274
|
-
{ name: "postAuthor", title: "Tác giả", icon: User, category: theme, keywords: "tac gia author", kind: "atom", edit: PostAuthorEdit, attributes: { avatar: { type: "boolean", default: false } }, supports: { style: true, className: true } },
|
|
291
|
+
{ name: "postAuthor", title: "Tác giả", icon: User, category: theme, keywords: "tac gia author", kind: "atom", edit: PostAuthorEdit, attributes: { avatar: { type: "boolean", default: false }, showName: { type: "boolean", default: true }, showBio: { type: "boolean", default: false }, avatarSize: { type: "integer", default: 32, min: 16, max: 128 }, link: { type: "boolean", default: true } }, supports: { style: true, className: true } },
|
|
275
292
|
{ name: "postTerms", title: "Chuyên mục / thẻ", icon: Tag, category: theme, keywords: "chuyen muc the category tag terms", kind: "atom", edit: PostTermsEdit, attributes: { taxonomy: { type: "string", default: "category" }, separator: { type: "string", default: ", " } }, supports: { style: true, className: true } },
|
|
276
|
-
{ name: "comments", title: "Bình luận", icon: MessageSquare, category: theme, keywords: "binh luan comments", kind: "atom", edit: CommentsEdit },
|
|
293
|
+
{ name: "comments", title: "Bình luận", icon: MessageSquare, category: theme, keywords: "binh luan comments", kind: "atom", edit: CommentsEdit, attributes: { title: { type: "string" } } },
|
|
294
|
+
{ name: "readMore", title: "Đọc tiếp", icon: ChevronsRight, category: theme, keywords: "doc tiep read more", kind: "atom", edit: ReadMoreEdit, attributes: { text: { type: "string" }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
295
|
+
{ name: "commentsCount", title: "Số bình luận", icon: MessageSquare, category: theme, keywords: "so binh luan comments count", kind: "atom", edit: CommentsCountEdit, attributes: { textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
296
|
+
{ name: "avatar", title: "Ảnh đại diện tác giả", icon: ImageIcon, category: theme, keywords: "avatar anh dai dien tac gia", kind: "atom", edit: AvatarEdit, attributes: { size: { type: "integer", default: 48, min: 16, max: 256 }, link: { type: "boolean", default: true } }, supports: { style: true, className: true } },
|
|
297
|
+
{ name: "queryTotal", title: "Tổng số bài", icon: ListOrdered, category: theme, keywords: "tong so bai total", kind: "atom", edit: QueryTotalEdit, attributes: { textAlign: TEXT_ALIGN }, supports: { style: true, className: true }, structure: { parents: ["query"] } },
|
|
277
298
|
{ name: "queryTitle", title: "Tiêu đề trang lưu trữ", icon: Heading1, category: theme, keywords: "tieu de luu tru chuyen muc archive query title h1", kind: "atom", edit: QueryTitleEdit, attributes: { level: { type: "integer", default: 1, min: 1, max: 6 }, prefix: { type: "boolean", default: false }, textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
278
299
|
{ name: "termDescription", title: "Mô tả chuyên mục", icon: AlignLeft, category: theme, keywords: "mo ta chuyen muc term description", kind: "atom", edit: TermDescriptionEdit, attributes: { textAlign: TEXT_ALIGN }, supports: { style: true, className: true } },
|
|
279
300
|
{ name: "breadcrumbs", title: "Breadcrumb", icon: ChevronsRight, category: theme, keywords: "breadcrumb duong dan dieu huong", kind: "atom", edit: BreadcrumbsEdit, attributes: { separator: { type: "string", default: "›" }, showHome: { type: "boolean", default: true }, showCurrent: { type: "boolean", default: true } }, supports: { style: true, className: true } },
|
|
@@ -285,7 +306,7 @@ export function themeBlocks(): BlockType[] {
|
|
|
285
306
|
supports: { style: true, className: true },
|
|
286
307
|
},
|
|
287
308
|
{ name: "postTemplate", title: "Khuôn mỗi bài", icon: LayoutTemplate, kind: "container", edit: PostTemplateEdit, hidden: true, attributes: { layout: { type: "string", enum: ["list", "grid"], default: "list" }, columns: { type: "integer", default: 3, min: 1, max: 6 } }, structure: { parents: ["query"] } },
|
|
288
|
-
{ name: "pagination", title: "Phân trang", icon: ListOrdered, kind: "atom", edit: PaginationEdit, hidden: true, structure: { parents: ["query"] } },
|
|
309
|
+
{ name: "pagination", title: "Phân trang", icon: ListOrdered, kind: "atom", edit: PaginationEdit, attributes: { type: { type: "string", enum: ["numbers", "prevNext", "both"], default: "both" }, midSize: { type: "integer", default: 2, min: 0, max: 5 } }, hidden: true, structure: { parents: ["query"] } },
|
|
289
310
|
{ name: "queryEmpty", title: "Khi không có bài", icon: SquareDashed, kind: "container", edit: QueryEmptyEdit, hidden: true, structure: { parents: ["query"] } },
|
|
290
311
|
{ name: "templatePart", title: "Phần dùng chung", icon: PanelTop, category: theme, keywords: "phan dung chung template part header footer", kind: "atom", edit: TemplatePartEdit, attributes: { slug: { type: "string" }, tagName: { type: "string", enum: ["div", "header", "footer", "aside", "section"], default: "div" } }, summary: (a) => a.slug },
|
|
291
312
|
{ name: "syncedPattern", title: "Mẫu đồng bộ", icon: Repeat2, category: "widgets", keywords: "mau dong bo synced pattern reusable", kind: "atom", edit: SyncedPatternEdit, attributes: { ref: { type: "integer" } }, hidden: true },
|
package/src/v2/canvas/canvas.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { collectStyles, normalizeStyle, presetCss, type BlockStyle } from "@ecomcx/ecomweb-content";
|
|
2
|
-
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from "react";
|
|
2
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, type ReactNode } from "react";
|
|
3
|
+
import { onAnimationsChange, pluginAnimations } from "../../shared/animation-store";
|
|
3
4
|
import { createPortal } from "react-dom";
|
|
4
5
|
import { DocBlocks } from "./block-list";
|
|
5
6
|
import { BLOCKS_MIME, blocksFromClipboard, serializeBlocks } from "../core/clipboard";
|
|
@@ -177,6 +178,13 @@ function useCanvasStyles(doc: Document) {
|
|
|
177
178
|
if (!el) { el = doc.createElement("style"); el.dataset.ecx = "blocks"; head.appendChild(el); }
|
|
178
179
|
el.textContent = css;
|
|
179
180
|
}, [css, doc, head]);
|
|
181
|
+
// Keyframes của hiệu ứng plugin (registerAnimation) để xem thử trong khung soạn
|
|
182
|
+
const animations = useSyncExternalStore(onAnimationsChange, pluginAnimations, pluginAnimations);
|
|
183
|
+
useLayoutEffect(() => {
|
|
184
|
+
let el = head.querySelector<HTMLStyleElement>("style[data-ecx=motion]");
|
|
185
|
+
if (!el) { el = doc.createElement("style"); el.dataset.ecx = "motion"; head.appendChild(el); }
|
|
186
|
+
el.textContent = animations.map((a) => a.css ?? "").join("\n");
|
|
187
|
+
}, [animations, doc, head]);
|
|
180
188
|
}
|
|
181
189
|
|
|
182
190
|
/** Cuộn / đổi cỡ trong iframe → thanh công cụ đo lại vị trí. */
|
package/src/v2/core/bindings.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { msgs } from "../../i18n";
|
|
1
2
|
import type { DynamicData } from "./host";
|
|
2
3
|
import type { BNode } from "./model";
|
|
3
4
|
|
|
@@ -36,13 +37,13 @@ export const bindingSource = (name: string) => sources.get(name);
|
|
|
36
37
|
export const subscribeBindingSources = (l: () => void) => { listeners.add(l); return () => { listeners.delete(l); }; };
|
|
37
38
|
|
|
38
39
|
/** Nguồn lõi (trùng tên với CORE_BINDING_SOURCES của theme-sdk). Nhãn theo ngôn ngữ. */
|
|
39
|
-
export function registerCoreBindingSources(lang:
|
|
40
|
-
const
|
|
40
|
+
export function registerCoreBindingSources(lang: string) {
|
|
41
|
+
const t = msgs("bindings", lang);
|
|
41
42
|
registerBindingSource({
|
|
42
|
-
name: "core/post", label:
|
|
43
|
+
name: "core/post", label: t.srcPost,
|
|
43
44
|
fields: [
|
|
44
|
-
{ value: "title", label:
|
|
45
|
-
{ value: "author", label:
|
|
45
|
+
{ value: "title", label: t.fTitle }, { value: "excerpt", label: t.fExcerpt }, { value: "date", label: t.fDate },
|
|
46
|
+
{ value: "author", label: t.fAuthor }, { value: "link", label: t.fLink }, { value: "featuredImage", label: t.fFeaturedImage },
|
|
46
47
|
],
|
|
47
48
|
preview: (args, { dynamic }) => {
|
|
48
49
|
const p = dynamic?.post;
|
|
@@ -53,10 +54,10 @@ export function registerCoreBindingSources(lang: "vi" | "en") {
|
|
|
53
54
|
}
|
|
54
55
|
},
|
|
55
56
|
});
|
|
56
|
-
registerBindingSource({ name: "core/post-meta", label:
|
|
57
|
+
registerBindingSource({ name: "core/post-meta", label: t.srcPostMeta, argKey: "key", preview: (args) => (args.key ? `{${args.key}}` : undefined) });
|
|
57
58
|
registerBindingSource({
|
|
58
|
-
name: "core/site", label:
|
|
59
|
-
fields: [{ value: "title", label:
|
|
59
|
+
name: "core/site", label: t.srcSite,
|
|
60
|
+
fields: [{ value: "title", label: t.fSiteTitle }, { value: "tagline", label: t.fTagline }, { value: "url", label: "URL" }, { value: "logo", label: "Logo" }],
|
|
60
61
|
preview: (args, { dynamic }) => (args.field === "title" ? dynamic?.site?.title : args.field === "tagline" ? dynamic?.site?.tagline : args.field === "logo" ? dynamic?.site?.logo ?? undefined : undefined),
|
|
61
62
|
});
|
|
62
63
|
}
|
package/src/v2/core/model.ts
CHANGED
|
@@ -31,11 +31,11 @@ const CORE_KINDS: Record<string, BlockKind> = {
|
|
|
31
31
|
paragraph: "text", heading: "text", codeBlock: "text", preformatted: "text",
|
|
32
32
|
bulletList: "container", orderedList: "container", listItem: "container", taskList: "container", taskItem: "container",
|
|
33
33
|
blockquote: "container", columns: "container", column: "container", group: "container", callout: "container",
|
|
34
|
-
buttons: "container", cover: "container", mediaText: "container", pullquote: "text", details: "container",
|
|
34
|
+
buttons: "container", cover: "container", mediaText: "container", pullquote: "text", details: "container", accordion: "container", tabs: "container", tab: "container", carousel: "container",
|
|
35
35
|
table: "container", tableRow: "container", tableCell: "container", tableHeader: "container",
|
|
36
36
|
query: "container", postTemplate: "container", queryEmpty: "container", stack: "container",
|
|
37
37
|
horizontalRule: "atom", image: "atom", gallery: "atom", video: "atom", audio: "atom", file: "atom", youtube: "atom",
|
|
38
|
-
button: "atom", embed: "atom", spacer: "atom", customHtml: "atom", socialLinks: "atom", tableOfContents: "atom",
|
|
38
|
+
button: "atom", embed: "atom", spacer: "atom", customHtml: "atom", socialLinks: "atom", tableOfContents: "atom", countdown: "atom", rating: "atom", shortcode: "atom",
|
|
39
39
|
};
|
|
40
40
|
const kindOverrides = new Map<string, BlockKind>();
|
|
41
41
|
export function setBlockKind(type: string, kind: BlockKind) { kindOverrides.set(type, kind); }
|