@ecomcx/ecomweb-editor 1.20.0 → 1.21.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 +7 -35
- 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 +19 -14
- package/src/v2/blocks/media.tsx +19 -15
- package/src/v2/blocks/theme.tsx +20 -17
- package/src/v2/canvas/canvas.tsx +9 -1
- package/src/v2/core/bindings.ts +9 -8
- 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 +84 -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>
|
|
@@ -132,15 +137,15 @@ function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
|
|
|
132
137
|
const drop = useFileDrop("image", select);
|
|
133
138
|
// 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
139
|
if (!src && !a.overlay) {
|
|
135
|
-
const
|
|
140
|
+
const t = useMsgs("blocks");
|
|
136
141
|
return (
|
|
137
142
|
<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">{
|
|
143
|
+
<span className="ecx-placeholder-title"><ImageIcon className="ecx-icon" />{t.cover}</span>
|
|
144
|
+
<p className="ecx-placeholder-hint">{t.pickABackgroundImage}</p>
|
|
140
145
|
<MediaActions kind="image" onSelect={select} onUrl={(url) => setAttrs({ src: url })} />
|
|
141
146
|
<div className="ecx-chip-row" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
|
|
142
147
|
{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={`${
|
|
148
|
+
<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
149
|
))}
|
|
145
150
|
</div>
|
|
146
151
|
</div>
|
|
@@ -148,7 +153,7 @@ function CoverEdit({ block, blockProps, setAttrs, labels }: BlockEditProps) {
|
|
|
148
153
|
}
|
|
149
154
|
const overlay = colorCss(a.overlay) ?? (src ? "#000" : undefined);
|
|
150
155
|
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") })}>
|
|
156
|
+
<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
157
|
{src && <img className="ecx-cover-img" src={src} alt={String(a.alt ?? "")} draggable={false} />}
|
|
153
158
|
{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
159
|
<div className="ecx-cover-inner"><InnerBlocks parent={block} /></div>
|
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
|
);
|
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
|
}
|
|
@@ -106,20 +107,21 @@ function CommentsEdit({ blockProps }: BlockEditProps) {
|
|
|
106
107
|
/** Tiêu đề trang lưu trữ / tìm kiếm (H1 của trang chuyên mục, thẻ, tác giả…). */
|
|
107
108
|
function QueryTitleEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
108
109
|
const d = useDynamic();
|
|
109
|
-
const
|
|
110
|
+
const t = useMsgs("blocks");
|
|
110
111
|
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 ? (
|
|
112
|
+
const name = d.archive?.title ?? (t.categoryName);
|
|
113
|
+
return <Tag {...merge(blockProps, "ecx-query-title", align(block.attrs))}>{block.attrs.prefix ? (t.category) : ""}{name}</Tag>;
|
|
113
114
|
}
|
|
114
115
|
function TermDescriptionEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
116
|
+
const t = useMsgs("blocks");
|
|
115
117
|
const d = useDynamic();
|
|
116
|
-
return <div {...merge(blockProps, "ecx-term-description", align(block.attrs))}>{d.archive?.description || (
|
|
118
|
+
return <div {...merge(blockProps, "ecx-term-description", align(block.attrs))}>{d.archive?.description || (t.theDescriptionOfThe)}</div>;
|
|
117
119
|
}
|
|
118
120
|
function BreadcrumbsEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
119
121
|
const d = useDynamic();
|
|
120
|
-
const
|
|
122
|
+
const t = useMsgs("blocks");
|
|
121
123
|
const sep = String(block.attrs.separator ?? "›");
|
|
122
|
-
const items = [...(block.attrs.showHome !== false ? [
|
|
124
|
+
const items = [...(block.attrs.showHome !== false ? [t.home] : []), t.category2, ...(block.attrs.showCurrent !== false ? [d.post?.title || (t.currentPage)] : [])];
|
|
123
125
|
return (
|
|
124
126
|
<nav {...(merge(blockProps, "ecx-breadcrumbs") as object)}>
|
|
125
127
|
<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 +129,19 @@ function BreadcrumbsEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
|
127
129
|
);
|
|
128
130
|
}
|
|
129
131
|
function PostNavigationEdit({ block, blockProps, labels }: BlockEditProps) {
|
|
130
|
-
const
|
|
132
|
+
const t = useMsgs("blocks");
|
|
131
133
|
const titles = block.attrs.showTitle !== false;
|
|
132
134
|
return (
|
|
133
135
|
<nav {...(merge(blockProps, "ecx-post-navigation") as object)}>
|
|
134
|
-
<a className="ecx-post-navigation-prev"><span>{
|
|
135
|
-
<a className="ecx-post-navigation-next"><span>{
|
|
136
|
+
<a className="ecx-post-navigation-prev"><span>{t.previous}</span>{titles && <strong>{t.previousPostTitle}</strong>}</a>
|
|
137
|
+
<a className="ecx-post-navigation-next"><span>{t.next}</span>{titles && <strong>{t.nextPostTitle}</strong>}</a>
|
|
136
138
|
</nav>
|
|
137
139
|
);
|
|
138
140
|
}
|
|
139
141
|
|
|
140
142
|
function PostContentEdit({ blockProps }: BlockEditProps) {
|
|
141
143
|
const { labels } = useEditor();
|
|
144
|
+
const t = useMsgs("blocks");
|
|
142
145
|
const scope = useDocScope();
|
|
143
146
|
const frameId = useEditorState((s) => s.frameId);
|
|
144
147
|
const rootId = useEditorState((s) => s.rootId);
|
|
@@ -150,7 +153,7 @@ function PostContentEdit({ blockProps }: BlockEditProps) {
|
|
|
150
153
|
</div>
|
|
151
154
|
);
|
|
152
155
|
}
|
|
153
|
-
return <div {...merge(blockProps, "ecx-post-content ecx-content-placeholder")}><FileText className="ecx-icon" /> {
|
|
156
|
+
return <div {...merge(blockProps, "ecx-post-content ecx-content-placeholder")}><FileText className="ecx-icon" /> {t.postContent}</div>;
|
|
154
157
|
}
|
|
155
158
|
|
|
156
159
|
function QueryEdit({ block, blockProps }: BlockEditProps) {
|
|
@@ -202,15 +205,15 @@ function PostTemplateEdit({ block, blockProps, editable, labels }: BlockEditProp
|
|
|
202
205
|
const cols = Math.min(6, Math.max(1, Number(block.attrs.columns) || 3));
|
|
203
206
|
const count = posts ? Math.max(1, Math.min(posts.length, q.perPage, 6)) : 3;
|
|
204
207
|
const current = Math.min(active, count - 1);
|
|
205
|
-
const
|
|
208
|
+
const t = useMsgs("blocks");
|
|
206
209
|
return (
|
|
207
210
|
<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">{
|
|
211
|
+
{posts && !posts.length && <li className="ecx-post ecx-post-none">{t.noPostsMatchThese}</li>}
|
|
209
212
|
{Array.from({ length: count }, (_, i) => {
|
|
210
213
|
const post = posts?.[i] ?? null;
|
|
211
214
|
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
215
|
return (
|
|
213
|
-
<li key={i} className="ecx-post ecx-post-preview" data-ecx-post-index={i} title={
|
|
216
|
+
<li key={i} className="ecx-post ecx-post-preview" data-ecx-post-index={i} title={t.clickToEditThe}
|
|
214
217
|
onMouseDownCapture={(e) => { if (!editable || ui.zoomOut || e.button !== 0) return; e.preventDefault(); e.stopPropagation(); setActive(i); }}>
|
|
215
218
|
<LoopPostContext.Provider value={post}><PreviewBlocks nodes={block.content ?? []} tag={`p${i}`} /></LoopPostContext.Provider>
|
|
216
219
|
</li>
|
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/editor.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RichNode } from "@ecomcx/ecomweb-content";
|
|
2
2
|
import { normalizeContent } from "@ecomcx/ecomweb-content";
|
|
3
3
|
import { ListTree, Monitor, Plus, Redo2, Smartphone, Tablet, Undo2, X, PanelRight, ZoomOut } from "lucide-react";
|
|
4
|
-
import { useEffect, useMemo, useRef, useState, type ReactNode } from "react";
|
|
4
|
+
import { useEffect, useMemo, useRef, useState, useSyncExternalStore, type ReactNode } from "react";
|
|
5
5
|
import { coreBlockTypes, registerCoreBlocks } from "./blocks";
|
|
6
6
|
import { registeredPatterns, syncPluginBlocks } from "./blocks/compat";
|
|
7
7
|
import { registerCorePatterns } from "../shared/patterns";
|
|
@@ -10,7 +10,8 @@ import { Canvas, type Device } from "./canvas/canvas";
|
|
|
10
10
|
import { EditorContext, EditorUi, useEditor, useEditorState, useUiTick, type EditorContextValue } from "./context";
|
|
11
11
|
import type { EditorHost } from "./core/host";
|
|
12
12
|
import { InserterPanel, InserterPopover } from "./ui/inserter";
|
|
13
|
-
import {
|
|
13
|
+
import { labelsV2, type V2Labels } from "./labels";
|
|
14
|
+
import { localesVersion, onLocalesChange } from "../i18n";
|
|
14
15
|
import { blocksFromDoc, docFromBlocks, type BNode } from "./core/model";
|
|
15
16
|
import { BlockTypeRegistry } from "./core/registry";
|
|
16
17
|
import { Inspector } from "./ui/inspector";
|
|
@@ -50,7 +51,8 @@ export interface EditorProviderProps {
|
|
|
50
51
|
title?: string;
|
|
51
52
|
host?: EditorHost;
|
|
52
53
|
labels?: Partial<V2Labels>;
|
|
53
|
-
|
|
54
|
+
/** Mã ngôn ngữ giao diện: "vi", "en" hoặc ngôn ngữ đã đăng ký bằng registerLocale. Mặc định "vi". */
|
|
55
|
+
lang?: string;
|
|
54
56
|
registry?: BlockTypeRegistry;
|
|
55
57
|
/** Cho chèn khối giao diện (tên website, menu, danh sách bài, phần dùng chung). */
|
|
56
58
|
dynamicBlocks?: boolean;
|
|
@@ -69,7 +71,8 @@ export interface EditorProviderProps {
|
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
export function EditorProvider({ store: given, value, kind, title, host = {}, labels, lang, registry: givenRegistry, dynamicBlocks, frame, prefsStorage, prefs: givenPrefs, onChange, children }: EditorProviderProps) {
|
|
72
|
-
const
|
|
74
|
+
const localeTick = useSyncExternalStore(onLocalesChange, localesVersion, localesVersion);
|
|
75
|
+
const base = useMemo(() => labelsV2(lang), [lang, localeTick]);
|
|
73
76
|
const allLabels = useMemo(() => ({ ...base, ...labels }), [base, labels]);
|
|
74
77
|
const registry = useMemo(() => {
|
|
75
78
|
if (givenRegistry) return givenRegistry;
|
package/src/v2/i18n.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import { localesVersion, msgs, onLocalesChange } from "../i18n";
|
|
3
|
+
import type { vi } from "../locales/vi";
|
|
4
|
+
import { useEditor } from "./context";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Chữ của một nhóm theo ngôn ngữ của trình soạn (`labels.lang`): `const t = useMsgs("motion"); t.title`.
|
|
8
|
+
* Tự vẽ lại khi có ngôn ngữ / bản dịch mới được đăng ký lúc đang chạy (registerLocale).
|
|
9
|
+
*/
|
|
10
|
+
export function useMsgs<K extends keyof typeof vi>(ns: K): (typeof vi)[K] {
|
|
11
|
+
const { labels } = useEditor();
|
|
12
|
+
useSyncExternalStore(onLocalesChange, localesVersion, localesVersion);
|
|
13
|
+
return msgs(ns, labels.lang);
|
|
14
|
+
}
|
package/src/v2/index.ts
CHANGED
|
@@ -20,9 +20,11 @@ export { blocksFromDoc, docFromBlocks, fromRich, toRich, makeBlock, cloneBlock,
|
|
|
20
20
|
export { findBlock, flatten, mapBlock, insertBlocks, removeBlocks, moveBlocks } from "./core/ops";
|
|
21
21
|
export { canContain, fixTree, setStructureRule, type StructureRule } from "./core/structure";
|
|
22
22
|
export { htmlToRich, textToRich, richToHtml, BLOCKS_MIME } from "./core/clipboard";
|
|
23
|
-
export { viV2, enV2, type V2Labels } from "./labels";
|
|
23
|
+
export { viV2, enV2, labelsV2, type V2Labels } from "./labels";
|
|
24
|
+
export { registerLocale, availableLocales, type Messages } from "../i18n";
|
|
24
25
|
export type { EditorHost, DocumentHost, DynamicData, DynamicPost, QueryArgs, Choice, ChoiceKind, NestedDocRef, LoadedDoc, SavedContent } from "./core/host";
|
|
25
26
|
export { MoreMenu, PreferencesModal, ShortcutsModal, CodeEditor, Breadcrumbs } from "./ui/options";
|
|
26
27
|
export { PrefsStore, localPrefsStorage, usePrefs, DEFAULT_PREFS, type EditorPrefs, type PrefsStorage } from "./prefs";
|
|
27
28
|
export { DocTitle } from "./ui/doc-title";
|
|
28
29
|
export { registerBindingSource, unregisterBindingSource, bindingSources, BindingsPanel, BoundText, useBindingPreview, CORE_BINDABLE, type EditorBindingSource, type Binding } from "./ui/bindings";
|
|
30
|
+
export { storeAnimation as registerAnimation, dropAnimation as unregisterAnimation, pluginAnimations, type MotionEffect } from "../shared/animation-store";
|