@ecomcx/ecomweb-editor 1.33.0 → 1.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/locales/en/attrs.ts +2 -1
- package/src/locales/en/background.ts +5 -0
- package/src/locales/en/bindings.ts +4 -0
- package/src/locales/en/block-desc.ts +4 -11
- package/src/locales/en/block-style.ts +17 -6
- package/src/locales/en/block-titles.ts +38 -16
- package/src/locales/en/blocks.ts +36 -6
- package/src/locales/en/columns.ts +1 -0
- package/src/locales/en/controls.ts +1 -1
- package/src/locales/en/hints.ts +241 -12
- package/src/locales/en/index.ts +3 -1
- package/src/locales/en/layout.ts +13 -0
- package/src/locales/en/motion.ts +16 -0
- package/src/locales/en/palette.ts +8 -0
- package/src/locales/en/parts.ts +2 -1
- package/src/locales/en/pattern-overrides.ts +14 -0
- package/src/locales/en/placeholders.ts +6 -3
- package/src/locales/en/v2.ts +2 -0
- package/src/locales/vi/attrs.ts +3 -2
- package/src/locales/vi/background.ts +5 -0
- package/src/locales/vi/bindings.ts +4 -0
- package/src/locales/vi/block-desc.ts +7 -14
- package/src/locales/vi/block-style.ts +18 -7
- package/src/locales/vi/block-titles.ts +48 -26
- package/src/locales/vi/blocks.ts +36 -6
- package/src/locales/vi/columns.ts +1 -0
- package/src/locales/vi/controls.ts +1 -1
- package/src/locales/vi/hints.ts +241 -12
- package/src/locales/vi/index.ts +3 -1
- package/src/locales/vi/layout.ts +13 -0
- package/src/locales/vi/motion.ts +16 -0
- package/src/locales/vi/palette.ts +8 -0
- package/src/locales/vi/parts.ts +2 -1
- package/src/locales/vi/pattern-overrides.ts +14 -0
- package/src/locales/vi/placeholders.ts +7 -4
- package/src/locales/vi/v2.ts +2 -0
- package/src/v2/blocks/columns-inspector.tsx +11 -2
- package/src/v2/blocks/index.ts +9 -6
- package/src/v2/blocks/layout-options.tsx +80 -0
- package/src/v2/blocks/layout.tsx +331 -124
- package/src/v2/blocks/media.tsx +51 -21
- package/src/v2/blocks/resize.tsx +50 -19
- package/src/v2/blocks/social-icons.ts +22 -0
- package/src/v2/blocks/text.tsx +12 -50
- package/src/v2/blocks/theme.tsx +13 -19
- package/src/v2/blocks/tools.tsx +24 -2
- package/src/v2/blocks/widgets.tsx +84 -28
- package/src/v2/canvas/block-list.tsx +30 -4
- package/src/v2/canvas/canvas-css.ts +81 -9
- package/src/v2/canvas/canvas.tsx +63 -7
- package/src/v2/canvas/dnd.ts +7 -0
- package/src/v2/canvas/variation-picker.tsx +63 -0
- package/src/v2/context.tsx +48 -0
- package/src/v2/core/bindings.ts +6 -1
- package/src/v2/core/block-presets.ts +10 -0
- package/src/v2/core/clipboard.ts +5 -5
- package/src/v2/core/host.ts +2 -0
- package/src/v2/core/model.ts +6 -6
- package/src/v2/core/registry.ts +15 -0
- package/src/v2/core/store.ts +9 -9
- package/src/v2/core/structure.ts +1 -3
- package/src/v2/editor.css +74 -0
- package/src/v2/editor.tsx +22 -7
- package/src/v2/text/rich-text.tsx +20 -5
- package/src/v2/ui/ai-markdown.ts +52 -0
- package/src/v2/ui/ai.tsx +81 -14
- package/src/v2/ui/attr-form.tsx +26 -6
- package/src/v2/ui/attr-hints.ts +115 -16
- package/src/v2/ui/background-panel.tsx +22 -0
- package/src/v2/ui/bg-video-preview.tsx +7 -0
- package/src/v2/ui/bindings.tsx +7 -2
- package/src/v2/ui/block-icons.tsx +3 -10
- package/src/v2/ui/block-live-preview.tsx +21 -0
- package/src/v2/ui/block-style-panel.tsx +3 -1
- package/src/v2/ui/command-palette.tsx +125 -0
- package/src/v2/ui/icon-picker.tsx +88 -21
- package/src/v2/ui/icon-svg.tsx +21 -0
- package/src/v2/ui/inserter.tsx +62 -12
- package/src/v2/ui/inspector.tsx +12 -6
- package/src/v2/ui/layout-panel.tsx +1 -1
- package/src/v2/ui/motion-panel.tsx +22 -13
- package/src/v2/ui/option-thumbs.tsx +81 -0
- package/src/v2/ui/pattern-library.tsx +2 -1
- package/src/v2/ui/pattern-overrides.tsx +67 -0
- package/src/v2/ui/placeholders.tsx +21 -2
- package/src/v2/ui/preset-bar.tsx +5 -5
- package/src/v2/ui/style-supports.ts +2 -3
- package/src/v2/ui/style-tab.tsx +83 -20
- package/src/v2/ui/toolbar.tsx +40 -6
- package/src/v2/ui/transform-panel.tsx +77 -0
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import { CORE_NODES,
|
|
1
|
+
import { CORE_NODES, colorCss, iconListClass, resolveIcon, widgetMarkup, type WidgetEl } from "@ecomcx/ecomweb-content";
|
|
2
|
+
import { IconPicker } from "../ui/icon-picker";
|
|
3
|
+
import { ColorInput } from "../ui/color-field";
|
|
4
|
+
import { IconSvg } from "../ui/icon-svg";
|
|
2
5
|
import { BarChart3, Hash, Image as ImageIcon, ListChecks, MapPin, Quote, Star } from "lucide-react";
|
|
3
|
-
import { createElement, type CSSProperties, type ReactNode } from "react";
|
|
6
|
+
import { createElement, useEffect, useRef, useSyncExternalStore, type CSSProperties, type ReactNode } from "react";
|
|
7
|
+
import { useEditor } from "../context";
|
|
4
8
|
import { makeBlock } from "../core/model";
|
|
5
9
|
import type { BlockEditProps, BlockType } from "../core/registry";
|
|
6
10
|
import { useMsgs } from "../i18n";
|
|
7
11
|
import { messages } from "../../i18n";
|
|
8
12
|
import { RichText } from "../text/rich-text";
|
|
9
13
|
import { Section } from "../ui/style-controls";
|
|
14
|
+
import { IconTool } from "./tools";
|
|
10
15
|
import { MediaPick } from "./layout";
|
|
11
16
|
import { useActiveWithin } from "./resize";
|
|
12
17
|
import { AddItemButton, TextPlaceholder } from "../ui/placeholders";
|
|
18
|
+
import { iconBoxLayouts, iconListLayouts, progressLayouts, testimonialLayouts } from "./layout-options";
|
|
13
19
|
|
|
14
20
|
const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
|
|
15
21
|
|
|
@@ -56,51 +62,97 @@ function WidgetEdit(props: BlockEditProps) {
|
|
|
56
62
|
/** Icon List trên khung soạn: mỗi dòng gõ ngay trên khối (dòng trống website bỏ qua) + "+ Thêm dòng". */
|
|
57
63
|
function IconListEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
58
64
|
const tp = useMsgs("placeholders");
|
|
59
|
-
const
|
|
65
|
+
const { ui } = useEditor();
|
|
66
|
+
const activeIdx = useSyncExternalStore(ui.subscribe, () => ui.activeItem.get(block.id) ?? 0);
|
|
67
|
+
const items: Array<{ text: string; href?: string; icon?: string; tip?: string; color?: string; iconBg?: string; textColor?: string }> = Array.isArray(block.attrs.items) ? block.attrs.items : [];
|
|
60
68
|
const list = items.length || !editable ? items : [{ text: "" }];
|
|
61
69
|
const save = (next: typeof items) => setAttrs({ items: next });
|
|
62
70
|
const stroke = Math.min(4, Math.max(0.5, Number(block.attrs.stroke) || 2));
|
|
63
|
-
const icon = (name?: string) => name === "none" ? null : <
|
|
71
|
+
const icon = (name?: string, it?: { color?: string; iconBg?: string }) => name === "none" ? null : <IconSvg className="ecx-widget-icon" style={{ ...(colorCss(it?.color) ? { color: colorCss(it?.color) } : {}), ...(colorCss(it?.iconBg) ? { background: colorCss(it?.iconBg) } : {}) }} name={resolveIcon(name) ? name : resolveIcon(block.attrs.icon) ? block.attrs.icon : "check"} stroke={stroke} />;
|
|
72
|
+
const ul = useRef<HTMLUListElement | null>(null);
|
|
73
|
+
const focusAt = useRef<number | null>(null);
|
|
74
|
+
// Sau khi thêm / xoá mục, đưa con trỏ vào đúng mục (Enter → mục mới, Backspace → mục trước)
|
|
75
|
+
useEffect(() => { if (focusAt.current != null) { ul.current?.querySelectorAll<HTMLInputElement>("li input")[focusAt.current]?.focus(); focusAt.current = null; } });
|
|
76
|
+
/** Enter: thêm mục ngay dưới; Backspace ở mục trống: xoá mục, về mục trước. */
|
|
77
|
+
const key = (i: number) => (e: { key: string; shiftKey: boolean; preventDefault(): void; currentTarget: HTMLInputElement | HTMLTextAreaElement }) => {
|
|
78
|
+
if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); focusAt.current = i + 1; save([...list.slice(0, i + 1), { text: "" }, ...list.slice(i + 1)]); }
|
|
79
|
+
else if (e.key === "Backspace" && e.currentTarget.value === "" && list.length > 1) { e.preventDefault(); focusAt.current = Math.max(0, i - 1); save(list.filter((_, k) => k !== i)); }
|
|
80
|
+
};
|
|
64
81
|
return (
|
|
65
|
-
<ul {...blockProps} className={cx(blockProps.className, iconListClass(block.attrs))}>
|
|
82
|
+
<ul {...blockProps} ref={(el) => { ul.current = el; const r = (blockProps as { ref?: unknown }).ref; if (typeof r === "function") (r as (n: HTMLUListElement | null) => void)(el); else if (r && typeof r === "object") (r as { current: unknown }).current = el; }} className={cx(blockProps.className, iconListClass(block.attrs))}>
|
|
66
83
|
{list.map((it, i) => (
|
|
67
|
-
<li key={i}>{icon(it.icon)}{editable
|
|
68
|
-
? <TextPlaceholder value={it.text} placeholder={i === 0 ? tp.iconListItem : `${tp.addRow}…`} label={`${tp.addRow} ${i + 1}`} onChange={(v) => save(list.map((x, k) => (k === i ? { ...x, text: v } : x)))}
|
|
69
|
-
: <span>{it.text}</span>}</li>
|
|
84
|
+
<li key={i} className={editable && i === activeIdx ? "is-item-active" : undefined} data-ecx-tip={it.tip?.trim() ? it.tip.trim().slice(0, 120) : undefined} onFocusCapture={() => ui.setActiveItem(block.id, i)}>{icon(it.icon, it)}{editable
|
|
85
|
+
? <span style={colorCss(it.textColor) ? { color: colorCss(it.textColor) } : undefined}><TextPlaceholder value={it.text} placeholder={i === 0 ? tp.iconListItem : `${tp.addRow}…`} label={`${tp.addRow} ${i + 1}`} onKeyDown={key(i)} onChange={(v) => save(list.map((x, k) => (k === i ? { ...x, text: v } : x)))} /></span>
|
|
86
|
+
: <span style={colorCss(it.textColor) ? { color: colorCss(it.textColor) } : undefined}>{it.text}</span>}</li>
|
|
70
87
|
))}
|
|
71
|
-
{editable && <li className="ecx-ph-list-add"><AddItemButton label={tp.addRow} onClick={() => save([...list, { text: "" }])} /></li>}
|
|
88
|
+
{editable && <li className="ecx-ph-list-add"><AddItemButton label={tp.addRow} onClick={() => { focusAt.current = list.length; save([...list, { text: "" }]); }} /></li>}
|
|
72
89
|
</ul>
|
|
73
90
|
);
|
|
74
91
|
}
|
|
75
92
|
|
|
76
93
|
/** Các mục của Icon List: mỗi mục một hàng — chữ, icon riêng (theo danh sách / tên icon / không icon), liên kết; thêm / xoá mục. Dòng trống website bỏ qua. */
|
|
77
|
-
|
|
94
|
+
/** Icon ngay trên thanh: Icon Box (khi đầu hộp là icon) — chọn một lần, thấy ngay trên khối. */
|
|
95
|
+
function IconBoxTool({ block, setAttrs }: BlockEditProps) {
|
|
96
|
+
const media = block.attrs.media;
|
|
97
|
+
if (media && media !== "icon") return null;
|
|
98
|
+
return <IconTool value={block.attrs.icon as string | undefined} onChange={(v) => setAttrs({ icon: v ?? "star" })} />;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Icon List: có mục đang chọn thì đổi icon của mục đó; chưa chọn mục nào thì đổi icon chung của danh sách. */
|
|
102
|
+
function IconListTool({ block, attrs, setAttrs }: BlockEditProps) {
|
|
103
|
+
const { ui } = useEditor();
|
|
104
|
+
useSyncExternalStore(ui.subscribe, ui.getTick);
|
|
105
|
+
const items: Array<{ text: string; href?: string; icon?: string; tip?: string; color?: string; iconBg?: string; textColor?: string }> = Array.isArray(attrs.items) ? attrs.items : [];
|
|
106
|
+
const sel = ui.activeItem.get(block.id);
|
|
107
|
+
const item = sel != null ? items[sel] : undefined;
|
|
108
|
+
if (!item) return <IconTool value={attrs.icon as string | undefined} onChange={(v) => setAttrs({ icon: v ?? "check" })} />;
|
|
109
|
+
return <IconTool value={item.icon && item.icon !== "none" ? item.icon : (attrs.icon as string | undefined)} allowNone
|
|
110
|
+
onChange={(v) => setAttrs({ items: items.map((x, k) => { if (k !== sel) return x; const n = { ...x }; if (v) n.icon = v; else n.icon = "none"; return n; }) })} />;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function IconListInspector({ block, attrs, setAttrs }: BlockEditProps) {
|
|
78
114
|
const t = useMsgs("blocks") as Record<string, string>;
|
|
79
115
|
const h = useMsgs("hints") as Record<string, string>;
|
|
80
|
-
const
|
|
116
|
+
const { ui } = useEditor();
|
|
117
|
+
useSyncExternalStore(ui.subscribe, ui.getTick);
|
|
118
|
+
const items: Array<{ text: string; href?: string; icon?: string; tip?: string; color?: string; iconBg?: string; textColor?: string }> = Array.isArray(attrs.items) ? attrs.items : [];
|
|
119
|
+
const sel = Math.min(Math.max(ui.activeItem.get(block.id) ?? 0, 0), Math.max(0, items.length - 1));
|
|
81
120
|
const patch = (i: number, p: Record<string, string | undefined>) => setAttrs({ items: items.map((x, k) => {
|
|
82
121
|
if (k !== i) return x;
|
|
83
122
|
const next: Record<string, unknown> = { ...x, ...p };
|
|
84
123
|
for (const key of Object.keys(next)) if (next[key] === undefined || (key !== "text" && next[key] === "")) delete next[key];
|
|
85
124
|
return next;
|
|
86
125
|
}) });
|
|
126
|
+
const pick = (i: number) => ui.setActiveItem(block.id, i);
|
|
127
|
+
const move = (i: number, d: number) => { const j = i + d; if (j < 0 || j >= items.length) return; const next = items.slice(); [next[i], next[j]] = [next[j], next[i]]; setAttrs({ items: next }); pick(j); };
|
|
87
128
|
return (
|
|
88
129
|
<Section title={t.iconListItems} defaultOpen>
|
|
89
130
|
{items.map((it, i) => (
|
|
90
|
-
<div key={i} className="ecx-item-row" data-icon-list-item>
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
<
|
|
94
|
-
|
|
95
|
-
<
|
|
96
|
-
{
|
|
97
|
-
|
|
98
|
-
<input className="ecx-input" type="url" inputMode="url" aria-label={`${t.iconListLink} ${i + 1}`} placeholder={t.iconListLink} value={it.href ?? ""} onChange={(e) => patch(i, { href: e.target.value || undefined })} />
|
|
131
|
+
<div key={i} className={cx("ecx-item-row", i === sel && "is-active")} data-icon-list-item data-active={i === sel ? "" : undefined} onFocusCapture={() => pick(i)} onMouseDown={() => pick(i)}>
|
|
132
|
+
<div className="ecx-item-row-head">
|
|
133
|
+
<span className="ecx-item-n" aria-hidden="true">{i + 1}</span>
|
|
134
|
+
<input className="ecx-input" aria-label={`${t.iconListText} ${i + 1}`} placeholder={t.iconListText} value={it.text ?? ""} onChange={(e) => patch(i, { text: e.target.value })} />
|
|
135
|
+
{i === sel && <>
|
|
136
|
+
<button type="button" className="ecx-tool" aria-label={`${t.iconListUp} ${i + 1}`} title={t.iconListUp} disabled={i === 0} onClick={() => move(i, -1)}>↑</button>
|
|
137
|
+
<button type="button" className="ecx-tool" aria-label={`${t.iconListDown} ${i + 1}`} title={t.iconListDown} disabled={i === items.length - 1} onClick={() => move(i, 1)}>↓</button>
|
|
138
|
+
</>}
|
|
99
139
|
<button type="button" className="ecx-tool" aria-label={`${t.iconListRemove} ${i + 1}`} title={t.iconListRemove} onClick={() => setAttrs({ items: items.filter((_, k) => k !== i) })}>×</button>
|
|
100
140
|
</div>
|
|
141
|
+
{i === sel && (
|
|
142
|
+
<div className="ecx-item-row-sub">
|
|
143
|
+
<IconPicker label={`${t.iconListIcon} ${i + 1}`} value={it.icon} defaultLabel={t.iconListIconDefault} noneValue="none" onChange={(v) => patch(i, { icon: v })} />
|
|
144
|
+
<input className="ecx-input" type="url" inputMode="url" aria-label={`${t.iconListLink} ${i + 1}`} placeholder={t.iconListLink} value={it.href ?? ""} onChange={(e) => patch(i, { href: e.target.value || undefined })} />
|
|
145
|
+
<input className="ecx-input" aria-label={`${t.iconListTip} ${i + 1}`} placeholder={t.iconListTip} maxLength={120} value={it.tip ?? ""} onChange={(e) => patch(i, { tip: e.target.value || undefined })} />
|
|
146
|
+
<div className="ecx-item-colors">
|
|
147
|
+
<ColorInput label={`${t.iconListColor} ${i + 1}`} value={it.color} onChange={(v) => patch(i, { color: v })} />
|
|
148
|
+
<ColorInput label={`${t.iconListBg} ${i + 1}`} value={it.iconBg} onChange={(v) => patch(i, { iconBg: v })} />
|
|
149
|
+
<ColorInput label={`${t.iconListTextColor} ${i + 1}`} value={it.textColor} onChange={(v) => patch(i, { textColor: v })} />
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
)}
|
|
101
153
|
</div>
|
|
102
154
|
))}
|
|
103
|
-
{items.length < 50 && <button type="button" className="ecx-btn" onClick={() => setAttrs({ items: [...items, { text: "" }] })}>+ {t.iconListAdd}</button>}
|
|
155
|
+
{items.length < 50 && <button type="button" className="ecx-btn" onClick={() => { setAttrs({ items: [...items, { text: "" }] }); pick(items.length); }}>+ {t.iconListAdd}</button>}
|
|
104
156
|
</Section>
|
|
105
157
|
);
|
|
106
158
|
}
|
|
@@ -111,20 +163,24 @@ const ICON_BOX_ORDER = ["media", "icon", "number", "src", "alt", "width", "heigh
|
|
|
111
163
|
function ordered<T>(attrs: Record<string, T>, order: string[]): Record<string, T> {
|
|
112
164
|
return Object.fromEntries([...order.filter((k) => k in attrs), ...Object.keys(attrs).filter((k) => !order.includes(k))].map((k) => [k, attrs[k]]));
|
|
113
165
|
}
|
|
114
|
-
const
|
|
166
|
+
const OVERLAY_ORDER = ["media", "src", "alt", "title", "subtitle", "level", "href", "linkTarget", "ratio", "hAlign", "vAlign", "subtitleMode", "imageEffect", "overlayColor", "overlayOpacity", "restOpacity", "frame", "frameInset", "divider"];
|
|
167
|
+
const ICON_SELECT = { type: "string" as const };
|
|
115
168
|
|
|
116
169
|
/** Khối widget của lõi; `lang` = ngôn ngữ của trình soạn (chữ mẫu khi chèn). */
|
|
117
170
|
export function widgetBlocks(lang?: string): BlockType[] {
|
|
118
171
|
const m = messages("blocks", lang) as Record<string, string>;
|
|
119
172
|
const base = { kind: "atom" as const, category: "widgets", edit: WidgetEdit, supports: { style: true, anchor: true, className: true } };
|
|
120
173
|
return [
|
|
121
|
-
{ ...base, name: "iconBox", title: "Icon Box", icon: Star, keywords: "icon box hop bieu tuong tinh nang dich vu feature", attributes: ordered({ ...spec("iconBox"), icon: { ...ICON_SELECT, default: "star" }, src: { type: "url", control: "media" } }, ICON_BOX_ORDER), create: () => makeBlock("iconBox", { icon: "star", title:
|
|
174
|
+
{ ...base, name: "iconBox", toolbar: IconBoxTool, layouts: iconBoxLayouts(m), layoutsOnInsert: false, layoutOwns: ["position"], title: "Icon Box", icon: Star, keywords: "icon box hop bieu tuong tinh nang dich vu feature", attributes: ordered({ ...spec("iconBox"), icon: { ...ICON_SELECT, default: "star" }, src: { type: "url", control: "media" } }, ICON_BOX_ORDER), create: () => makeBlock("iconBox", { icon: "star", title: m.sampleBoxTitle, text: m.sampleBoxText }), summary: (a) => a.title },
|
|
122
175
|
// Hộp ảnh đã gộp vào Hộp icon (media = ảnh): ẩn khỏi trình chèn, nội dung cũ vẫn sửa được
|
|
123
176
|
{ ...base, hidden: true, name: "imageBox", title: "Image Box", icon: ImageIcon, keywords: "image box hop anh the card dich vu", attributes: { ...spec("imageBox"), src: { type: "url", control: "media" } }, create: () => makeBlock("imageBox", { title: "", text: "" }), summary: (a) => a.title },
|
|
124
|
-
|
|
125
|
-
{ ...base, name: "
|
|
126
|
-
|
|
127
|
-
{ ...base, name: "
|
|
128
|
-
{ ...base, name: "
|
|
177
|
+
// Ảnh phủ chữ: ảnh + lớp màu + khung viền + chữ hiện khi rê chuột (thẻ chuyên mục, bộ sưu tập, dự án)
|
|
178
|
+
{ ...base, name: "imageOverlay", title: "Image Overlay", icon: ImageIcon, keywords: "anh phu chu image overlay hover the chuyen muc bo suu tap du an banner", attributes: ordered({ ...spec("imageOverlay"), src: { type: "url", control: "media" }, overlayColor: { type: "string", control: "color" } }, OVERLAY_ORDER),
|
|
179
|
+
create: () => makeBlock("imageOverlay", { title: m.sampleOverlayTitle, subtitle: m.sampleOverlaySubtitle, overlayColor: "primary", overlayOpacity: 65, imageEffect: "zoom", ratio: "4/3" }), summary: (a) => a.title },
|
|
180
|
+
{ ...base, name: "iconList", toolbar: IconListTool, layouts: iconListLayouts(m), layoutOwns: ["layout"], title: "Icon List", icon: ListChecks, keywords: "icon list danh sach bieu tuong loi ich checklist", inspector: IconListInspector, attributes: { ...spec("iconList"), icon: { ...ICON_SELECT, default: "check" } }, create: () => makeBlock("iconList", { items: [m.sampleList1, m.sampleList2, m.sampleList3, m.sampleList4].map((text) => ({ text })) }) },
|
|
181
|
+
{ ...base, name: "counter", title: "Counter", icon: Hash, keywords: "counter dem so con so thong ke number", attributes: spec("counter"), create: () => makeBlock("counter", { end: 1200, suffix: "+", title: m.sampleCounterTitle, textAlign: "center" }), summary: (a) => a.title },
|
|
182
|
+
{ ...base, name: "testimonial", layouts: testimonialLayouts(m), layoutOwns: ["variant"], title: "Testimonial", icon: Quote, keywords: "testimonial loi chung thuc danh gia khach hang review", attributes: ordered({ ...spec("testimonial"), src: { type: "url", control: "media" } }, ["variant", "quoteMark", "rating", "quote", "name", "role", "src", "alt", "textAlign"]), create: () => makeBlock("testimonial", { quote: m.sampleQuote, name: m.sampleName, role: m.sampleRole, rating: 5 }), summary: (a) => a.name },
|
|
183
|
+
{ ...base, name: "map", title: "Map", icon: MapPin, keywords: "map ban do dia chi google maps vi tri", attributes: ordered(spec("map") ?? {}, ["address", "title", "zoom", "height", "mapType"]), create: () => makeBlock("map", { address: m.sampleAddress }), summary: (a) => a.address },
|
|
184
|
+
{ ...base, name: "progressBar", layouts: progressLayouts(m), layoutsOnInsert: false, layoutOwns: ["textPosition"], title: "Progress Bar", icon: BarChart3, keywords: "progress bar thanh tien do ky nang phan tram", attributes: spec("progressBar"), create: () => makeBlock("progressBar", { label: m.sampleSkill, value: 80 }), summary: (a) => a.label },
|
|
129
185
|
];
|
|
130
186
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { controlsCss, normalizeStyle, styleClass, widthClass } from "@ecomcx/ecomweb-content";
|
|
2
2
|
import { blockControls } from "../../shared/panel-store";
|
|
3
|
-
import { Component, memo, useCallback, useContext, useEffect, useMemo, useRef, type ErrorInfo, type MouseEvent, type PointerEvent, type ReactElement, type ReactNode } from "react";
|
|
3
|
+
import { Component, memo, useCallback, useContext, useEffect, useMemo, useRef, useSyncExternalStore, type ErrorInfo, type MouseEvent, type PointerEvent, type ReactElement, type ReactNode } from "react";
|
|
4
4
|
import { DocScopeProvider, LoopPostContext, useDocScope, useEditor, useEditorState } from "../context";
|
|
5
5
|
import { ServerBlock } from "./server-block";
|
|
6
|
+
import { VariationChooser } from "./variation-picker";
|
|
6
7
|
import { startDrag } from "./dnd";
|
|
7
8
|
import { docIdOf, type NestedDocRef } from "../core/host";
|
|
8
9
|
import { blocksFromDoc, makeBlock, type BNode } from "../core/model";
|
|
@@ -23,7 +24,7 @@ export function sectionOf(store: ReturnType<typeof useEditor>["store"], el: HTML
|
|
|
23
24
|
|
|
24
25
|
/** Props gắn vào phần tử gốc của khối: chọn, viền, kiểu dáng, neo. */
|
|
25
26
|
/** Khối chứa mà con phủ kín: có nhãn rê chuột để bấm chọn chính khối chứa (xem canvas-css). */
|
|
26
|
-
const LABELED = new Set(["query", "postTemplate", "queryEmpty", "templatePart", "tabs", "tab", "accordion", "details", "carousel", "columns", "column", "buttons", "form", "mediaText", "cover"]);
|
|
27
|
+
const LABELED = new Set(["query", "postTemplate", "queryEmpty", "templatePart", "tabs", "tab", "accordion", "details", "popup", "testimonials", "carousel", "columns", "column", "buttons", "form", "mediaText", "cover"]);
|
|
27
28
|
|
|
28
29
|
export function useBlockProps(block: BNode, state: { selected: boolean; editing: boolean; mode: EditingMode }): BlockProps {
|
|
29
30
|
const ctx = useEditor();
|
|
@@ -120,10 +121,14 @@ export const Block = memo(function Block({ node }: { node: BNode }) {
|
|
|
120
121
|
const type = registry.get(node.type);
|
|
121
122
|
const blockProps = useBlockProps(node, { selected, editing, mode: scope.mode });
|
|
122
123
|
const setAttrs = useCallback((attrs: Record<string, unknown>) => store.setAttrs([node.id], attrs), [node.id, store]);
|
|
124
|
+
const { ui } = useEditor();
|
|
125
|
+
const picking = useSyncExternalStore(ui.subscribe, () => ui.pickIds.has(node.id));
|
|
126
|
+
// (Hook phải gọi trước mọi return sớm — ô chọn bố cục trả về sớm khi đang chờ chọn.) Khối trong vòng lặp bài (query › postTemplate) giữ giao diện của trình soạn: website chỉ biết bài của trang, không biết bài của vòng lặp
|
|
127
|
+
const loop = useContext(LoopPostContext);
|
|
123
128
|
const Edit = type?.edit ?? FallbackEdit;
|
|
124
129
|
const props: BlockEditProps = { block: node, attrs: node.attrs, setAttrs, blockProps, selected: selected || editing, editable: scope.mode !== "disabled", labels };
|
|
125
|
-
|
|
126
|
-
|
|
130
|
+
if (picking && type?.layouts?.length && scope.mode !== "disabled")
|
|
131
|
+
return <BlockBoundary id={node.id} type={node.type}><VariationChooser type={type} attrs={node.attrs} blockProps={blockProps as unknown as Record<string, unknown>} onPick={(v) => { setAttrs(v.attrs); ui.resolvePick(node.id); }} onSkip={() => ui.resolvePick(node.id, true)} /></BlockBoundary>;
|
|
127
132
|
// editWhenSelected: đang chọn → ô giữ chỗ của trình soạn; vẫn đi qua ServerBlock để ô nhập không bị dựng lại (mất focus) khi chọn / bỏ chọn
|
|
128
133
|
if (type?.serverRender && host.renderBlock && !loop)
|
|
129
134
|
return <BlockBoundary id={node.id} type={node.type}><ServerBlock node={node} blockProps={blockProps} fallback={<Edit {...props} />} live={!(type.editWhenSelected && (selected || editing) && scope.mode !== "disabled")} /></BlockBoundary>;
|
|
@@ -168,15 +173,36 @@ export function InnerBlocks({ parent, appender = "auto" }: { parent: BNode; appe
|
|
|
168
173
|
const kids = parent.content ?? [];
|
|
169
174
|
const { store } = useEditor();
|
|
170
175
|
const showAppender = appender === "auto" && scope.mode === "default" && !kids.length && store.canInsertInto(parent.id);
|
|
176
|
+
// Khối chứa đã có nội dung (Cột, Nhóm, Tab, Hộp lưu ý): nút "+" nhỏ ngay dưới khối cuối, hiện khi rê chuột / chọn — để thấy chỗ thêm tiếp và chỗ thả (như dòng "gõ / để chọn khối" của WordPress)
|
|
177
|
+
const showTail = appender === "auto" && scope.mode === "default" && kids.length > 0 && TAIL_PARENTS.has(parent.type) && !isFlowLayout(parent) && store.canInsertInto(parent.id);
|
|
171
178
|
const elements = useBlockElements(kids);
|
|
172
179
|
return (
|
|
173
180
|
<>
|
|
174
181
|
{elements}
|
|
175
182
|
{showAppender && <Appender docId={scope.docId} parentId={parent.id} index={0} />}
|
|
183
|
+
{showTail && <TailAppender docId={scope.docId} parentId={parent.id} index={kids.length} />}
|
|
176
184
|
</>
|
|
177
185
|
);
|
|
178
186
|
}
|
|
179
187
|
|
|
188
|
+
const TAIL_PARENTS = new Set(["column", "group", "tab"]);
|
|
189
|
+
/** Nhóm dạng hàng ngang / lưới: thêm một ô vào hàng sẽ làm lệch bố cục → không có nút + cuối (dùng thanh công cụ / bảng chèn). */
|
|
190
|
+
const isFlowLayout = (b: BNode) => { const t = (b.attrs.style as { layout?: { type?: string } } | undefined)?.layout?.type; return t === "flex" || t === "grid"; };
|
|
191
|
+
|
|
192
|
+
/** Nút "+" nhỏ cuối khối chứa đã có nội dung: ẩn khi không rê chuột / chọn. */
|
|
193
|
+
function TailAppender({ docId, parentId, index }: { docId: string; parentId: string; index: number }) {
|
|
194
|
+
const { ui, labels } = useEditor();
|
|
195
|
+
return (
|
|
196
|
+
<button type="button" className="ecx-tail-appender" title={labels.addBlock} aria-label={labels.addBlock} contentEditable={false} data-ecx-ui="" tabIndex={-1}
|
|
197
|
+
onMouseDown={(e) => { e.preventDefault(); e.stopPropagation(); }}
|
|
198
|
+
onClick={(e) => {
|
|
199
|
+
const r = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
200
|
+
const f = ui.canvasFrame?.getBoundingClientRect();
|
|
201
|
+
ui.openInserter({ mode: "appender", docId, parentId, index, rect: { left: (f?.left ?? 0) + r.left, top: (f?.top ?? 0) + r.top, bottom: (f?.top ?? 0) + r.bottom } });
|
|
202
|
+
}} data-ecx-placeholder="add"><span aria-hidden="true">+</span></button>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
180
206
|
/** Nút "+" chèn khối vào khối chứa trống. */
|
|
181
207
|
export function Appender({ docId, parentId, index }: { docId: string; parentId: string | null; index: number }) {
|
|
182
208
|
const { ui, labels } = useEditor();
|
|
@@ -81,6 +81,19 @@ span[data-ecx-rich][data-empty][data-placeholder] { display: inline-block; verti
|
|
|
81
81
|
.ecx-appender:hover { opacity: 1; border-color: var(--ecx-ui); color: var(--ecx-ui); }
|
|
82
82
|
|
|
83
83
|
.ecx-placeholder-block, .ecx-media-placeholder { display: flex; flex-direction: column; gap: .5rem; padding: 1rem; border: 1px dashed color-mix(in srgb, currentColor 30%, transparent); border-radius: 6px; font: 14px/1.4 var(--ecx-ui-font); }
|
|
84
|
+
.ecx-variation-chooser { display: flex; flex-direction: column; gap: 12px; padding: 16px; border: 1px dashed color-mix(in srgb, currentColor 30%, transparent); border-radius: 8px; font: 14px/1.4 var(--ecx-ui-font); }
|
|
85
|
+
.ecx-variation-title { font-weight: 600; text-transform: uppercase; letter-spacing: .04em; font-size: 12px; text-align: center; }
|
|
86
|
+
.ecx-variation-chooser .ecx-variations { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; max-width: 640px; width: 100%; margin: 0 auto; }
|
|
87
|
+
.ecx-variation-chooser .ecx-variation { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 8px 8px; border: 1px solid color-mix(in srgb, currentColor 22%, transparent); border-radius: 8px; background: transparent; color: inherit; font: 12px/1.25 var(--ecx-ui-font); cursor: pointer; }
|
|
88
|
+
.ecx-variation-chooser .ecx-variation:hover, .ecx-variation-chooser .ecx-variation:focus-visible { border-color: var(--ecx-ui); outline: none; box-shadow: 0 0 0 1px var(--ecx-ui); }
|
|
89
|
+
.ecx-variation-chooser .ecx-vthumb { width: 100%; height: auto; }
|
|
90
|
+
.ecx-variation-chooser .ecx-vthumb rect { fill: color-mix(in srgb, currentColor 18%, transparent); }
|
|
91
|
+
.ecx-variation-chooser .ecx-vthumb rect.is-box, .ecx-variation-chooser .ecx-vthumb polygon.is-box { fill: transparent; stroke: color-mix(in srgb, currentColor 32%, transparent); stroke-width: 1.2; }
|
|
92
|
+
.ecx-variation-chooser .ecx-vthumb .is-accent { fill: var(--ecx-ui); stroke: none; }
|
|
93
|
+
.ecx-variation-chooser .ecx-vthumb rect.is-box.is-accent { fill: transparent; stroke: var(--ecx-ui); }
|
|
94
|
+
.ecx-variation-chooser .ecx-vthumb path.is-line { fill: none; stroke: var(--ecx-ui); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
|
|
95
|
+
.ecx-variation-skip { align-self: center; border: 0; background: none; color: inherit; opacity: .7; text-decoration: underline; font: 13px var(--ecx-ui-font); cursor: pointer; }
|
|
96
|
+
.ecx-variation-skip:hover { opacity: 1; }
|
|
84
97
|
.ecx-placeholder-block.is-unknown { border-color: #d97706; background: rgba(217, 119, 6, .05); }
|
|
85
98
|
.ecx-placeholder-title { display: inline-flex; align-items: center; gap: .4rem; font-weight: 600; }
|
|
86
99
|
.ecx-placeholder-summary { opacity: .65; font-size: 12px; }
|
|
@@ -137,13 +150,15 @@ body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select:
|
|
|
137
150
|
.ecx-doc-title .ecx-doc-title-input, .ecx-doc-title .ecx-doc-title-input:focus { border: 0; border-radius: 0; outline: none; box-shadow: none; padding: 0; background: transparent; min-height: 0; }
|
|
138
151
|
.ecx-col-handles { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
|
|
139
152
|
/* Dải kéo đệm trên / dưới của khối bố cục đang chọn */
|
|
140
|
-
.ecx-block.is-selected:has(> .ecx-pad-handles) { position: relative; }
|
|
153
|
+
:where(.ecx-block.is-selected:has(> .ecx-pad-handles)) { position: relative; }
|
|
141
154
|
/* Khối bố cục đang chọn: chỗ trống nắm được để kéo đổi chỗ; khối con / chữ giữ con trỏ thường */
|
|
142
155
|
.ecx-block[data-ecx-grab] { cursor: grab; }
|
|
143
156
|
.ecx-block[data-ecx-grab] .ecx-block, .ecx-block[data-ecx-grab] [data-ecx-rich] { cursor: auto; }
|
|
144
157
|
.ecx-pad-handles { position: absolute; inset: 0; max-width: none; margin: 0; pointer-events: none; z-index: 7; }
|
|
145
|
-
.ecx-block.is-selected:has(> .ecx-cw-handles) { position: relative; }
|
|
158
|
+
:where(.ecx-block.is-selected:has(> .ecx-cw-handles)) { position: relative; }
|
|
146
159
|
.ecx-cw-handles { position: absolute; inset: 0; max-width: none; margin: 0; pointer-events: none; z-index: 8; }
|
|
160
|
+
.ecx-cw-guide { position: absolute; top: 0; bottom: 0; border-left: 1px dashed var(--ecx-ui); border-right: 1px dashed var(--ecx-ui); background: color-mix(in srgb, var(--ecx-ui) 6%, transparent); pointer-events: none; opacity: .7; }
|
|
161
|
+
.ecx-cw-guide.is-dragging { background: color-mix(in srgb, var(--ecx-ui) 14%, transparent); opacity: 1; }
|
|
147
162
|
.ecx-cw-handle { position: absolute; top: 50%; width: 10px; height: 44px; margin: -22px 0 0 4px; border-radius: 6px; background: var(--ecx-ui); box-shadow: 0 0 0 2px #fff; cursor: ew-resize; pointer-events: auto; opacity: .55; touch-action: none; }
|
|
148
163
|
.ecx-cw-handle.is-left { margin-left: -14px; }
|
|
149
164
|
.ecx-cw-handle:hover, .ecx-cw-handle.is-dragging { opacity: 1; }
|
|
@@ -163,6 +178,10 @@ body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select:
|
|
|
163
178
|
.ecx-pad-zone.is-top::after { top: calc(50% - 2px); }
|
|
164
179
|
.ecx-pad-zone.is-bottom::after { bottom: calc(50% - 2px); }
|
|
165
180
|
.ecx-pad-zone:hover::after, .ecx-pad-zone.is-dragging::after { opacity: 1; }
|
|
181
|
+
/* Hai cạnh trái / phải: dải đứng, kéo ngang */
|
|
182
|
+
.ecx-pad-zone.is-left, .ecx-pad-zone.is-right { top: 0; bottom: 0; left: auto; right: auto; cursor: ew-resize; }
|
|
183
|
+
.ecx-pad-zone.is-left { left: 0; } .ecx-pad-zone.is-right { right: 0; }
|
|
184
|
+
.ecx-pad-zone.is-left::after, .ecx-pad-zone.is-right::after { top: 50%; left: 50%; width: 4px; height: 36px; margin: -18px 0 0 -2px; }
|
|
166
185
|
.ecx-col-handle { position: absolute; width: 12px; margin-left: -6px; cursor: col-resize; pointer-events: auto; touch-action: none; }
|
|
167
186
|
.ecx-col-handle.is-dragging::before, .ecx-col-handle.is-dragging::after { position: absolute; top: 8px; padding: 1px 6px; border-radius: 4px; background: var(--ecx-ui); color: #fff; font: 600 11px/1.5 system-ui, sans-serif; white-space: nowrap; pointer-events: none; }
|
|
168
187
|
.ecx-col-handle.is-dragging::before { content: attr(data-left); right: 14px; }
|
|
@@ -196,7 +215,12 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
|
|
|
196
215
|
|
|
197
216
|
/* Chỉ trong trình soạn: khối "vô hình" trên website vẫn thấy được để chọn / sửa */
|
|
198
217
|
.ecx-spacer { background: repeating-linear-gradient(-45deg, transparent 0 6px, color-mix(in srgb, var(--ecx-ui) 8%, transparent) 6px 7px); }
|
|
199
|
-
.ecx-block.ecx-column:not(.is-selected):not(.is-editing) { outline: 1px dashed color-mix(in srgb, currentColor 16%, transparent); outline-offset: -1px; min-height:
|
|
218
|
+
.ecx-block.ecx-column:not(.is-selected):not(.is-editing) { outline: 1px dashed color-mix(in srgb, currentColor 16%, transparent); outline-offset: -1px; min-height: 96px; }
|
|
219
|
+
/* Nút + cuối khối chứa (Cột, Nhóm, Tab, Hộp lưu ý): hiện khi rê chuột vào khối trong cùng / khi đang chọn hoặc gõ trong khối */
|
|
220
|
+
.ecx-tail-appender { display: none; align-items: center; justify-content: center; width: 100%; height: 26px; margin: 6px 0 0; padding: 0; border: 1px dashed color-mix(in srgb, var(--ecx-ui) 55%, transparent); border-radius: 6px; background: transparent; color: var(--ecx-ui); font: 600 16px/1 var(--ecx-ui-font); cursor: pointer; opacity: 0; pointer-events: none; transition: opacity .12s ease; }
|
|
221
|
+
.ecx-tail-appender:hover { background: color-mix(in srgb, var(--ecx-ui) 8%, transparent); border-style: solid; }
|
|
222
|
+
.ecx-block:hover:not(:has(.ecx-block:hover > .ecx-tail-appender)) > .ecx-tail-appender, .ecx-block.is-selected > .ecx-tail-appender, .ecx-block:has(> * > .is-editing, > .is-editing, > .is-selected) > .ecx-tail-appender { display: flex; opacity: 1; pointer-events: auto; }
|
|
223
|
+
.is-zoomed-out .ecx-tail-appender, [data-ecx-preview] .ecx-tail-appender { display: none !important; }
|
|
200
224
|
.ecx-block.ecx-column:not(.is-selected):hover { outline-color: color-mix(in srgb, var(--ecx-ui) 55%, transparent); }
|
|
201
225
|
.ecx-media-placeholder.is-drop-target { outline: 2px dashed var(--ecx-ui); background: color-mix(in srgb, var(--ecx-ui) 6%, transparent); }
|
|
202
226
|
.ecx-placeholder-hint { margin: 4px 0 10px; font: 13px/1.5 var(--ecx-ui-font); opacity: .75; }
|
|
@@ -277,13 +301,61 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
|
|
|
277
301
|
.ecx-add-item:hover, .ecx-add-item:focus-visible { opacity: 1; border-color: var(--ecx-ui); color: var(--ecx-ui); }
|
|
278
302
|
.ecx-tabs-list .ecx-add-item { margin: 0 0 0 8px; align-self: center; }
|
|
279
303
|
/* Thanh chuyển slide của carousel (chỉ trên khung soạn) */
|
|
280
|
-
.ecx-carousel-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin:
|
|
304
|
+
.ecx-carousel-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 6px 0 0; font: 600 12px/1 var(--ecx-ui-font); user-select: none; }
|
|
281
305
|
.ecx-carousel-nav:empty { display: none; }
|
|
282
306
|
.ecx-carousel-nav .ecx-add-item { margin: 0 0 0 8px; }
|
|
283
307
|
.ecx-carousel-nav button { display: inline-flex; align-items: center; justify-content: center; min-width: 28px; height: 28px; padding: 0 6px; border: 1px solid #c9d0d7; border-radius: 6px; background: #fff; color: #1f2d38; font: inherit; cursor: pointer; }
|
|
284
308
|
.ecx-carousel-nav button[aria-current="true"] { border-color: var(--ecx-ui); background: var(--ecx-ui); color: #fff; }
|
|
285
309
|
.ecx-carousel-nav button:disabled { opacity: .4; cursor: default; }
|
|
286
310
|
.ecx-carousel-nav .ecx-icon { width: 16px; height: 16px; }
|
|
311
|
+
[data-ecx-preview] .ecx-add-item, [data-ecx-preview] .ecx-carousel-nav, [data-ecx-preview] .ecx-countdown-setup, [data-ecx-preview] .ph-list-add { display: none !important; }
|
|
312
|
+
.ecx-icon-list > li.is-item-active { outline: 2px solid var(--ecx-ui); outline-offset: 2px; border-radius: 4px; }
|
|
313
|
+
.ecx-countdown-setup { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 10px; padding: 8px 10px; border: 1px dashed color-mix(in srgb, currentColor 25%, transparent); border-radius: 8px; font: 12px/1.3 var(--ecx-ui-font); }
|
|
314
|
+
.ecx-countdown-setup .ecx-ph-row { display: flex; align-items: center; gap: 8px; margin: 0; }
|
|
315
|
+
.ecx-countdown-setup .ecx-input { height: 30px; }
|
|
316
|
+
.ecx-carousel-nav .ecx-carousel-del { margin-left: 4px; color: #b42318; }
|
|
317
|
+
.ecx-carousel-nav .ecx-carousel-count { margin-left: auto; opacity: .6; font-weight: 500; }
|
|
318
|
+
.ecx-carousel-nav { min-width: 0; padding-top: 4px; }
|
|
319
|
+
/* Mỗi slide hiện thành một khung riêng trên khung soạn (website không vẽ khung này). Slide nào cũng nằm thật trong track cuộn ngang */
|
|
320
|
+
.ecx-carousel { margin-top: 0; margin-bottom: 0; } /* chỉ trên / dưới: lề trái / phải tự động giữ Slider nằm giữa cột như website */
|
|
321
|
+
.ecx-carousel-track { scroll-snap-type: none; } /* khung soạn: không bám mép — bám mép giằng co với con trỏ khi gõ và với lệnh cuộn tới slide */
|
|
322
|
+
.ecx-carousel-track > [data-ecx-block][data-type="group"] { min-height: 140px; padding: 20px; border: 1px dashed color-mix(in srgb, currentColor 28%, transparent); border-radius: 8px; box-sizing: border-box; }
|
|
323
|
+
/* Popup khi soạn: nút mở ở trên, nội dung popup luôn mở trong khung nét đứt có nhãn */
|
|
324
|
+
.ecx-popup-frame { position: relative; margin-top: 10px; padding: 26px 16px 12px; border: 1px dashed color-mix(in srgb, currentColor 32%, transparent); border-radius: 10px; }
|
|
325
|
+
.ecx-popup-frame-label { position: absolute; top: 6px; left: 12px; font: 600 11px/1 system-ui, sans-serif; letter-spacing: .02em; text-transform: uppercase; opacity: .55; user-select: none; }
|
|
326
|
+
.ecx-countdown-setup [role="radio"] { font: 500 13px/1 system-ui, sans-serif; padding: 8px 12px; border-radius: 6px; border: 1px solid color-mix(in srgb, currentColor 25%, transparent); background: transparent; color: inherit; cursor: pointer; }
|
|
327
|
+
.ecx-countdown-setup [role="radio"][aria-checked="true"] { background: var(--ecx-color-primary, #1a597b); border-color: transparent; color: white; }
|
|
328
|
+
.ecx-countdown-setup .ecx-ph-inline-field { display: inline-flex; align-items: center; gap: 8px; margin-right: 12px; }
|
|
329
|
+
/* Tiêu đề có chữ gõ: khung soạn hiện từ đầu tiên (website gõ lần lượt các từ) — vẽ bằng ::after, không chen vào ô sửa chữ */
|
|
330
|
+
[data-ecx-typed]::after { content: " " attr(data-ecx-typed); color: var(--ecx-typed-color, inherit); border-right: .08em solid currentColor; padding-right: .04em; }
|
|
331
|
+
.ecx-popup-trigger-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
|
|
332
|
+
.ecx-popup-preview-btn { font: 500 12px/1 system-ui, sans-serif; padding: 6px 10px; border-radius: 6px; border: 1px solid color-mix(in srgb, currentColor 28%, transparent); background: transparent; color: inherit; cursor: pointer; opacity: .75; }
|
|
333
|
+
.ecx-popup-preview-btn:hover { opacity: 1; }
|
|
334
|
+
.ecx-popup-preview-close { position: sticky; float: right; top: 0; margin: -1.25rem -1.25rem 0 0; width: 28px; height: 28px; border: 0; border-radius: 999px; background: #111827; color: white; font: 400 18px/1 system-ui; cursor: pointer; }
|
|
335
|
+
/* Xem thử: khung nội dung thành hộp thoại giữa màn hình với nền tối như trên website (vẫn sửa được các khối bên trong) */
|
|
336
|
+
.ecx-popup.is-previewing .ecx-popup-frame { --_w: 40rem; position: fixed; z-index: 60; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(var(--_w), calc(100% - 2rem)); max-height: 80vh; overflow: auto; box-sizing: border-box; padding: 2rem; border: 0; border-radius: 12px; background: var(--ecx-color-background, white); box-shadow: 0 0 0 100vmax rgb(0 0 0 / var(--ecx-popup-dim, .6)), 0 24px 64px rgb(0 0 0 / .3); }
|
|
337
|
+
.ecx-popup.is-previewing.is-size-sm .ecx-popup-frame { --_w: 28rem; }
|
|
338
|
+
.ecx-popup.is-previewing.is-size-lg .ecx-popup-frame { --_w: 56rem; }
|
|
339
|
+
.ecx-popup.is-previewing.is-size-xl .ecx-popup-frame { --_w: 72rem; }
|
|
340
|
+
.ecx-popup.is-previewing .ecx-popup-frame-label { display: none; }
|
|
341
|
+
.ecx-popup.is-previewing .ecx-popup-preview-btn { display: none; }
|
|
342
|
+
|
|
343
|
+
/* Image Overlay chưa có ảnh: ô chọn ảnh ở trên, chữ nằm dưới (không phủ lên ô chọn ảnh) và dùng màu chữ của trang để đọc được */
|
|
344
|
+
.ecx-image-overlay:not(:has(img)) { aspect-ratio: auto; background: none; color: inherit; overflow: visible; border-radius: 0; }
|
|
345
|
+
.ecx-image-overlay:not(:has(img)) .ecx-image-overlay-media { position: static; }
|
|
346
|
+
.ecx-image-overlay:not(:has(img)) .ecx-image-overlay-tint { display: none; }
|
|
347
|
+
.ecx-image-overlay:not(:has(img)) .ecx-image-overlay-body { position: static; padding: 10px 4px 0; align-items: center; text-align: center; }
|
|
348
|
+
.ecx-image-overlay:not(:has(img)) .ecx-image-overlay-body::before { display: none; }
|
|
349
|
+
|
|
350
|
+
/* Ảnh phủ chữ khi soạn: chữ luôn hiện rõ và gõ được (website chỉ hiện khi rê); khối rỗng vẫn có khung cao để thấy */
|
|
351
|
+
[data-ecx-block][data-type="imageOverlay"] { min-height: 160px; }
|
|
352
|
+
[data-ecx-block][data-type="imageOverlay"] .ecx-image-overlay-body { pointer-events: auto; }
|
|
353
|
+
[data-ecx-block][data-type="imageOverlay"] :is(.ecx-image-overlay-title, .ecx-image-overlay-subtitle, .ecx-image-overlay-divider) { opacity: 1; transform: none; }
|
|
354
|
+
[data-ecx-block][data-type="imageOverlay"] .ecx-image-overlay-tint { opacity: max(var(--ecx-ov-rest, 0), .25); }
|
|
355
|
+
[data-ecx-block][data-type="imageOverlay"]:is(:hover, :focus-within) .ecx-image-overlay-tint { opacity: var(--ecx-ov-hover, .6); }
|
|
356
|
+
/* Slider có chiều cao riêng (tỉ lệ / tối thiểu): slide là nền đầy khung nên bỏ viền nét đứt và mức 140px dành cho thẻ trơn */
|
|
357
|
+
.ecx-carousel[data-height="min"] > .ecx-carousel-track > [data-ecx-block][data-type="group"] { min-height: var(--ecx-min-h, 24rem); border-style: none; border-radius: 0; }
|
|
358
|
+
.ecx-carousel[data-height="ratio"] > .ecx-carousel-track > [data-ecx-block][data-type="group"] { min-height: 0; aspect-ratio: var(--ecx-ratio, 16/9); border-style: none; border-radius: 0; }
|
|
287
359
|
.ecx-social .ecx-add-item, .ecx-social-add .ecx-add-item { margin: 0; }
|
|
288
360
|
.ecx-ph-list-add { list-style: none; }
|
|
289
361
|
.ecx-ph-list-add .ecx-add-item { margin-top: 2px; }
|
|
@@ -312,18 +384,18 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
|
|
|
312
384
|
.ecx-ph-table .ecx-ph-field { flex: 0 1 110px; }
|
|
313
385
|
/* Khoảng trống: sọc mờ + kích thước; đường kẻ: vùng bấm cao ≥ 40px (không đổi bố cục) */
|
|
314
386
|
.ecx-spacer[data-ecx-size] { display: flex; align-items: center; justify-content: center; min-height: 24px; }
|
|
315
|
-
.ecx-spacer[data-ecx-size]::
|
|
316
|
-
.ecx-spacer[data-ecx-size]:hover::
|
|
317
|
-
.ecx-rating[data-ecx-placeholder] { display: flex; align-items: center; gap: 2px; min-height: 40px; }
|
|
318
|
-
.ecx-rating[data-ecx-placeholder] .ecx-placeholder-hint { margin: 0 0 0 8px; }
|
|
387
|
+
.ecx-spacer[data-ecx-size]::after { position: relative; z-index: 1; content: attr(data-ecx-size); padding: 2px 8px; border-radius: 4px; background: rgb(255 255 255 / .85); color: #33414d; font: 12px/1.4 var(--ecx-ui-font); opacity: 0; transition: opacity .15s; pointer-events: none; }
|
|
388
|
+
.ecx-spacer[data-ecx-size]:hover::after, .ecx-spacer.is-selected[data-ecx-size]::after { opacity: 1; }
|
|
319
389
|
hr.ecx-block { position: relative; overflow: visible; }
|
|
320
390
|
hr.ecx-block::before { content: ""; position: absolute; left: 0; right: 0; top: -20px; bottom: -20px; }
|
|
321
391
|
`;
|
|
322
392
|
|
|
323
393
|
export const CONTAINER_LABEL_CSS = `
|
|
324
394
|
/* Khối chứa mà con phủ kín (Danh sách bài, Khuôn mỗi bài, Phần mẫu, Tabs…): rê chuột hiện nhãn ở góc trên trái, bấm nhãn = chọn khối chứa */
|
|
325
|
-
.ecx-canvas-root [data-ecx-label]:hover { position: relative; }
|
|
395
|
+
.ecx-canvas-root :where([data-ecx-label]:hover) { position: relative; }
|
|
326
396
|
.ecx-canvas-root [data-ecx-label]:hover:not(:has([data-ecx-label]:hover))::before {
|
|
327
397
|
content: attr(data-ecx-label); position: absolute; top: 0; left: 0; z-index: 30; padding: 2px 8px; border-radius: 0 0 6px 0; background: var(--ecx-ui, #1a597b); color: #fff;
|
|
328
398
|
font: 600 11px/18px var(--ecx-ui-font, system-ui); letter-spacing: .02em; cursor: pointer; pointer-events: auto; white-space: nowrap; }
|
|
399
|
+
/* Cột / Nhóm (con không phủ kín, chữ nằm sát góc trên trái): nhãn đặt NGAY TRÊN mép khối — không che chữ, không chặn bấm vào chữ */
|
|
400
|
+
.ecx-canvas-root [data-ecx-label]:is([data-type="column"], [data-type="group"], [data-type="buttons"]):hover:not(:has([data-ecx-label]:hover))::before { transform: translateY(-100%); border-radius: 6px 6px 0 0; }
|
|
329
401
|
`;
|
package/src/v2/canvas/canvas.tsx
CHANGED
|
@@ -29,6 +29,8 @@ export interface CanvasProps {
|
|
|
29
29
|
/** Vẽ thêm quanh nội dung (vd tiêu đề bài phía trên). */
|
|
30
30
|
before?: ReactNode;
|
|
31
31
|
after?: ReactNode;
|
|
32
|
+
/** Khung chỉ xem (xem trước khối / thư viện mẫu): không mang dấu nhận diện khung soạn chính (`data-ecx-canvas`). */
|
|
33
|
+
preview?: boolean;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
const SRC_DOC = `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"></head><body class="ecx-canvas-body"></body></html>`;
|
|
@@ -41,7 +43,7 @@ export const DESKTOP_MIN_WIDTH = 1025;
|
|
|
41
43
|
/** Thu nhỏ dưới tỉ lệ này thì chữ quá nhỏ để đọc / gõ (máy thật là điện thoại, tablet dọc): vẽ đúng bề rộng khung, không thu. */
|
|
42
44
|
export const MIN_FIT = 0.6;
|
|
43
45
|
|
|
44
|
-
export function Canvas({ device: deviceProp, className, contentClassName = "ecx-content", before, after }: CanvasProps) {
|
|
46
|
+
export function Canvas({ device: deviceProp, className, contentClassName = "ecx-content", before, after, preview }: CanvasProps) {
|
|
45
47
|
const { ui, labels } = useEditor();
|
|
46
48
|
const frameRef = useRef<HTMLIFrameElement>(null);
|
|
47
49
|
const [doc, setDoc] = useState<Document | null>(null);
|
|
@@ -61,9 +63,10 @@ export function Canvas({ device: deviceProp, className, contentClassName = "ecx-
|
|
|
61
63
|
if (!f || !d) return;
|
|
62
64
|
ui.canvasFrame = f;
|
|
63
65
|
ui.canvasDoc = d;
|
|
66
|
+
if (preview) d.documentElement.setAttribute("data-ecx-preview", "");
|
|
64
67
|
setDoc(d);
|
|
65
68
|
ui.bump();
|
|
66
|
-
}, [ui]);
|
|
69
|
+
}, [ui, preview]);
|
|
67
70
|
|
|
68
71
|
// srcDoc có thể đã nạp xong trước khi React gắn onLoad
|
|
69
72
|
useLayoutEffect(() => {
|
|
@@ -86,7 +89,7 @@ export function Canvas({ device: deviceProp, className, contentClassName = "ecx-
|
|
|
86
89
|
return (
|
|
87
90
|
<div ref={wrapRef} className={["ecx-canvas-wrap", `is-${device}`, zoom !== 1 && "is-zoomed-out", className].filter(Boolean).join(" ")}>
|
|
88
91
|
<iframe ref={frameRef} className="ecx-canvas-frame" title={labels.canvas} srcDoc={SRC_DOC} onLoad={onLoad}
|
|
89
|
-
style={style} data-ecx-canvas
|
|
92
|
+
style={style} {...(preview ? { "data-ecx-preview": "" } : { "data-ecx-canvas": "" })} />
|
|
90
93
|
{doc && createPortal(<CanvasWrapper><CanvasRoot doc={doc} contentClassName={contentClassName} before={before} after={after} /></CanvasWrapper>, doc.body)}
|
|
91
94
|
</div>
|
|
92
95
|
);
|
|
@@ -113,6 +116,7 @@ function CanvasRoot({ doc, contentClassName, before, after }: { doc: Document; c
|
|
|
113
116
|
const title = useEditorState(useCallback((s) => s.docs[activeId]?.title, [activeId]));
|
|
114
117
|
useCanvasDocument(doc);
|
|
115
118
|
useCanvasStyles(doc);
|
|
119
|
+
useHoverPreview(doc);
|
|
116
120
|
useCanvasKeys(doc);
|
|
117
121
|
useCanvasEvents(doc);
|
|
118
122
|
useMoveAnimation(doc);
|
|
@@ -152,6 +156,50 @@ function useCanvasDocument(doc: Document) {
|
|
|
152
156
|
}
|
|
153
157
|
|
|
154
158
|
/** CSS trong iframe: nền của trình soạn, CSS website (host), preset theme, kiểu dáng các khối. */
|
|
159
|
+
/**
|
|
160
|
+
* Xem trước trạng thái rê chuột của một khối: lấy mọi quy tắc :hover có nhắc class riêng của khối (ecx-s-… / ecx-c-…), sao thành quy tắc thường
|
|
161
|
+
* (`:hover` → `:not(#ecx-hv)` để thắng quy tắc nền về độ ưu tiên). Quy tắc của theme / khối khác không bị đụng.
|
|
162
|
+
*/
|
|
163
|
+
function useHoverPreview(doc: Document) {
|
|
164
|
+
const { ui, store } = useEditor();
|
|
165
|
+
const tick = useUiTick();
|
|
166
|
+
const selected = useEditorState((s) => s.selection.ids.join(",") + "|" + (s.selection.editing ?? ""));
|
|
167
|
+
// Chọn khối khác (hoặc bỏ chọn) → tự tắt xem trước
|
|
168
|
+
useLayoutEffect(() => { if (ui.previewHoverId && !store.currentIds.includes(ui.previewHoverId)) ui.setPreviewHover(null); }, [selected, ui, store]);
|
|
169
|
+
useLayoutEffect(() => {
|
|
170
|
+
doc.getElementById("ecx-hover-preview")?.remove();
|
|
171
|
+
const id = ui.previewHoverId;
|
|
172
|
+
if (!id) return;
|
|
173
|
+
const el = doc.querySelector<HTMLElement>(`[data-ecx-block="${CSS.escape(id)}"]`);
|
|
174
|
+
if (!el) return;
|
|
175
|
+
const classes = [...el.classList].filter((c) => /^ecx-(s|c)-/.test(c));
|
|
176
|
+
if (!classes.length) return;
|
|
177
|
+
const mine = (sel: string) => classes.some((c) => sel.includes(`.${c}`));
|
|
178
|
+
const out: string[] = [];
|
|
179
|
+
const walk = (rules: CSSRuleList, wrap: string[]) => {
|
|
180
|
+
for (const r of Array.from(rules)) {
|
|
181
|
+
// Quy tắc thuộc cửa sổ của iframe: `instanceof` với lớp của cửa sổ chính luôn sai → nhận biết bằng thuộc tính
|
|
182
|
+
if ("selectorText" in r) {
|
|
183
|
+
const r2 = r as CSSStyleRule;
|
|
184
|
+
if (!r2.selectorText.includes(":hover") || !mine(r2.selectorText)) continue;
|
|
185
|
+
const sel = r2.selectorText.split(",").filter((s) => s.includes(":hover") && mine(s)).map((s) => s.replace(/:hover/g, ":not(#ecx-hv)")).join(",");
|
|
186
|
+
if (sel) out.push(wrap.reduce((css, w) => `${w}{${css}}`, `${sel}{${r2.style.cssText}}`));
|
|
187
|
+
} else if ("cssRules" in r) {
|
|
188
|
+
const g = r as CSSGroupingRule & { conditionText?: string };
|
|
189
|
+
walk(g.cssRules, g.conditionText !== undefined && !("supportText" in r) && !("name" in r) ? [...wrap, `@media ${g.conditionText}`] : wrap);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
for (const sheet of Array.from(doc.styleSheets)) { try { walk(sheet.cssRules, []); } catch { /* CSS từ nguồn khác: không đọc được, bỏ qua */ } }
|
|
194
|
+
if (!out.length) return;
|
|
195
|
+
const st = doc.createElement("style");
|
|
196
|
+
st.id = "ecx-hover-preview";
|
|
197
|
+
st.textContent = out.join("\n");
|
|
198
|
+
doc.head.appendChild(st);
|
|
199
|
+
return () => st.remove();
|
|
200
|
+
}, [doc, ui, tick, ui.previewHoverId]);
|
|
201
|
+
}
|
|
202
|
+
|
|
155
203
|
function useCanvasStyles(doc: Document) {
|
|
156
204
|
const { host, store } = useEditor();
|
|
157
205
|
const head = doc.head;
|
|
@@ -256,14 +304,22 @@ function useCanvasEvents(doc: Document) {
|
|
|
256
304
|
if (ae?.isContentEditable) doc.querySelector<HTMLElement>(".ecx-canvas-root")?.focus({ preventScroll: true });
|
|
257
305
|
});
|
|
258
306
|
// Chuột phải / Shift+F10 / phím Menu trên khối → menu của khối (BlockContextMenu); Shift + chuột phải giữ menu của trình duyệt (chính tả, dán…)
|
|
307
|
+
// Chuột phải làm ô chữ bên dưới nhận tiêu điểm → vùng chọn nhiều khối (vd các ô bảng bôi đen) bị thu về một khối: nhớ lại lúc nhấn
|
|
308
|
+
let selAtDown: ReturnType<typeof store.getState>["selection"] | null = null;
|
|
309
|
+
const rememberSel = (e: MouseEvent) => { if (e.button === 2) selAtDown = store.getState().selection; };
|
|
310
|
+
doc.addEventListener("mousedown", rememberSel, true);
|
|
259
311
|
const menu = (e: MouseEvent) => {
|
|
260
312
|
const el = (e.target as Element | null)?.closest?.<HTMLElement>("[data-ecx-block]");
|
|
261
313
|
const id = el?.dataset.ecxBlock;
|
|
262
314
|
if (!id || !ui.canvasFrame || (e.shiftKey && e.button === 2) || store.modeOf(id) === "disabled") return;
|
|
263
315
|
e.preventDefault();
|
|
264
|
-
const sel = store.getState().selection;
|
|
265
|
-
|
|
316
|
+
const sel = selAtDown && selAtDown.ids.length > 1 ? selAtDown : store.getState().selection;
|
|
317
|
+
selAtDown = null;
|
|
318
|
+
// Chuột phải bên trong khối đang chọn (vd đoạn chữ trong ô bảng đang bôi đen) → giữ nguyên vùng chọn, không thu về một khối
|
|
319
|
+
const inSel = sel.ids.includes(id) || (sel.ids.length > 1 && (store.locate(id)?.ancestors ?? []).some((a) => sel.ids.includes(a)));
|
|
320
|
+
const ids = inSel ? sel.ids : sel.editing === id ? [id] : null;
|
|
266
321
|
if (!ids) store.select([id], { editing: null });
|
|
322
|
+
else if (ids.length > 1) store.select(ids, { editing: null });
|
|
267
323
|
const f = ui.canvasFrame.getBoundingClientRect();
|
|
268
324
|
const scale = f.width / (ui.canvasFrame.offsetWidth || f.width) || 1;
|
|
269
325
|
// Mở bằng bàn phím: không có toạ độ chuột → neo dưới góc trái của khối
|
|
@@ -274,7 +330,7 @@ function useCanvasEvents(doc: Document) {
|
|
|
274
330
|
return () => {
|
|
275
331
|
win.removeEventListener("scroll", bump); win.removeEventListener("resize", bump); ro.disconnect(); cancelAnimationFrame(raf); unsub();
|
|
276
332
|
doc.removeEventListener("mousemove", moved); document.removeEventListener("mousemove", moved);
|
|
277
|
-
doc.removeEventListener("contextmenu", menu);
|
|
333
|
+
doc.removeEventListener("contextmenu", menu); doc.removeEventListener("mousedown", rememberSel, true);
|
|
278
334
|
};
|
|
279
335
|
}, [doc, ui, store]);
|
|
280
336
|
}
|
|
@@ -448,7 +504,7 @@ function useCanvasKeys(doc: Document) {
|
|
|
448
504
|
}
|
|
449
505
|
|
|
450
506
|
/** Khối không chọn riêng bằng phím mũi tên (đi thẳng vào chữ bên trong). */
|
|
451
|
-
const HIDDEN_NAV = new Set(["listItem", "
|
|
507
|
+
const HIDDEN_NAV = new Set(["listItem", "tableRow"]);
|
|
452
508
|
|
|
453
509
|
/** Thôi thu nhỏ: phần đang chọn cuộn vào giữa màn hình. */
|
|
454
510
|
export function zoomIn(store: { getState(): { selection: { ids: string[] } } }, ui: { setZoomOut(v: boolean): void; blockEl(id: string): HTMLElement | null }) {
|
package/src/v2/canvas/dnd.ts
CHANGED
|
@@ -169,6 +169,13 @@ function findTarget(ctx: EditorContextValue, x: number, y: number, src: Source):
|
|
|
169
169
|
|
|
170
170
|
let el = doc.elementFromPoint(ix, iy) as HTMLElement | null;
|
|
171
171
|
let blockEl = el?.closest<HTMLElement>("[data-ecx-block]") ?? null;
|
|
172
|
+
// Phần dùng chung (header / footer) có lớp phủ cùng cỡ nằm trên khối con: lấy khối SÂU nhất (theo DOM) dưới con trỏ
|
|
173
|
+
const domDepth = (b: HTMLElement) => { let n = 0; for (let p = b.parentElement; p; p = p.parentElement) if (p.hasAttribute("data-ecx-block")) n++; return n; };
|
|
174
|
+
let depth = blockEl ? domDepth(blockEl) : -1;
|
|
175
|
+
for (const e of doc.elementsFromPoint(ix, iy)) {
|
|
176
|
+
const b = (e as HTMLElement).closest<HTMLElement>("[data-ecx-block]");
|
|
177
|
+
if (b && domDepth(b) > depth) { blockEl = b; depth = domDepth(b); }
|
|
178
|
+
}
|
|
172
179
|
// Không thả vào chính khối đang kéo / con của nó
|
|
173
180
|
while (blockEl && src.ids.some((id) => blockEl!.dataset.ecxBlock === id || isInside(store, blockEl!.dataset.ecxBlock!, id))) {
|
|
174
181
|
blockEl = blockEl.parentElement?.closest<HTMLElement>("[data-ecx-block]") ?? null;
|