@ecomcx/ecomweb-editor 1.30.0 → 1.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/locales/en/index.ts +2 -1
- package/src/locales/en/placeholders.ts +96 -0
- package/src/locales/vi/index.ts +2 -1
- package/src/locales/vi/placeholders.ts +95 -0
- package/src/v2/blocks/compat.tsx +91 -5
- package/src/v2/blocks/form.tsx +3 -0
- package/src/v2/blocks/layout.tsx +143 -52
- package/src/v2/blocks/media.tsx +72 -71
- package/src/v2/blocks/text.tsx +48 -17
- package/src/v2/blocks/theme.tsx +73 -12
- package/src/v2/blocks/widgets.tsx +48 -11
- package/src/v2/canvas/block-list.tsx +4 -4
- package/src/v2/canvas/canvas-css.ts +88 -6
- package/src/v2/canvas/server-block.tsx +7 -4
- package/src/v2/core/host.ts +9 -0
- package/src/v2/core/registry.ts +3 -1
- package/src/v2/core/structure.ts +2 -1
- package/src/v2/editor.css +6 -2
- package/src/v2/index.ts +3 -0
- package/src/v2/ui/ai.tsx +9 -5
- package/src/v2/ui/attr-form.tsx +2 -2
- package/src/v2/{blocks → ui}/media-actions.tsx +4 -3
- package/src/v2/ui/placeholders.tsx +205 -0
- package/src/v2/ui/toolbar.tsx +7 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CORE_NODES, ICON_NAMES, widgetMarkup, type WidgetEl } from "@ecomcx/ecomweb-content";
|
|
1
|
+
import { CORE_NODES, ICON_NAMES, ICON_PATHS, widgetMarkup, type WidgetEl } from "@ecomcx/ecomweb-content";
|
|
2
2
|
import { BarChart3, Hash, Image as ImageIcon, ListChecks, Quote, Star } from "lucide-react";
|
|
3
3
|
import { createElement, type CSSProperties, type ReactNode } from "react";
|
|
4
4
|
import { makeBlock } from "../core/model";
|
|
@@ -8,6 +8,8 @@ import { messages } from "../../i18n";
|
|
|
8
8
|
import { RichText } from "../text/rich-text";
|
|
9
9
|
import { Field } from "../ui/attr-form";
|
|
10
10
|
import { MediaPick } from "./layout";
|
|
11
|
+
import { useActiveWithin } from "./resize";
|
|
12
|
+
import { AddItemButton, TextPlaceholder } from "../ui/placeholders";
|
|
11
13
|
|
|
12
14
|
const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "string" && x !== "").join(" ");
|
|
13
15
|
|
|
@@ -15,17 +17,33 @@ const cx = (...c: unknown[]) => c.filter((x): x is string => typeof x === "strin
|
|
|
15
17
|
* Widget lõi trên khung soạn: cùng cây markup với website (@ecomcx/ecomweb-content widgetMarkup) → vẽ y hệt.
|
|
16
18
|
* Ô chữ (`field`) gõ trực tiếp trên khối, chỗ ảnh trống (`slot`) là ô chọn ảnh; số / thanh tiến độ hiện giá trị cuối (không chạy hiệu ứng).
|
|
17
19
|
*/
|
|
18
|
-
|
|
20
|
+
/** Gợi ý của từng ô chữ theo khối (không còn chữ mẫu thật dễ quên sửa). */
|
|
21
|
+
const FIELD_PH: Record<string, string> = { title: "boxTitle", text: "boxText", quote: "testimonialQuote", name: "testimonialName", role: "testimonialRole", label: "skill" };
|
|
22
|
+
|
|
23
|
+
function WidgetEdit(props: BlockEditProps) {
|
|
24
|
+
const { block, blockProps, setAttrs, editable } = props;
|
|
19
25
|
const t = useMsgs("blocks") as Record<string, string>;
|
|
26
|
+
const tp = useMsgs("placeholders") as unknown as Record<string, string>;
|
|
27
|
+
const active = useActiveWithin(block.id);
|
|
28
|
+
if (block.type === "iconList") return <IconListEdit {...props} />;
|
|
20
29
|
const tree = widgetMarkup(block.type, block.attrs, true);
|
|
21
|
-
if (!tree
|
|
30
|
+
if (!tree) return <div {...blockProps} className={cx(blockProps.className, "ecx-placeholder-block")}>{t.widgetEmpty}</div>;
|
|
31
|
+
const ph = (f: string) => (block.type === "counter" && f === "title" ? tp.counterTitle : tp[FIELD_PH[f] ?? ""] ?? t[`widget_${f}`]);
|
|
22
32
|
const draw = (el: WidgetEl | string, key: number, root?: boolean): ReactNode => {
|
|
23
33
|
if (typeof el === "string") return el;
|
|
24
34
|
if (el.field) {
|
|
25
35
|
const f = el.field;
|
|
26
|
-
return <RichText key={key} blockId={block.id} field={f} tagName="span" value={String(block.attrs[f] ?? "")} onChange={(v) => setAttrs({ [f]: v })} placeholder={
|
|
36
|
+
return <RichText key={key} blockId={block.id} field={f} tagName="span" value={String(block.attrs[f] ?? "")} onChange={(v) => setAttrs({ [f]: v })} placeholder={ph(f)} placeholderAlways editable={editable} />;
|
|
27
37
|
}
|
|
28
|
-
const kids = el.slot === "media" ? [<MediaPick key="pick" blockId={block.id} />] : (el.children ?? []).map((c, i) => draw(c, i));
|
|
38
|
+
const kids = el.slot === "media" ? [<MediaPick key="pick" blockId={block.id} compact />] : (el.children ?? []).map((c, i) => draw(c, i));
|
|
39
|
+
// Bộ đếm: ô nhập số ngay trong khối khi đang chọn (nhắc chỉ dùng số thật)
|
|
40
|
+
if (root && block.type === "counter" && editable && active) kids.push(
|
|
41
|
+
<label key="end" className="ecx-ph-row ecx-ph-inline-field" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
|
|
42
|
+
<span className="ecx-ph-label">{tp.counterEnd}</span>
|
|
43
|
+
<input className="ecx-input" type="number" value={Number(block.attrs.end ?? 0)} onChange={(e) => setAttrs({ end: Number(e.target.value) || 0 })} />
|
|
44
|
+
<span className="ecx-placeholder-hint">{tp.counterHint}</span>
|
|
45
|
+
</label>,
|
|
46
|
+
);
|
|
29
47
|
const props: Record<string, unknown> = { key, ...el.props, className: el.className, style: el.style as CSSProperties };
|
|
30
48
|
if (el.tag === "a") props.onClick = (e: Event) => e.preventDefault();
|
|
31
49
|
if (el.tag === "img") props.draggable = false;
|
|
@@ -35,6 +53,25 @@ function WidgetEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
|
35
53
|
return <>{draw(tree, 0, true)}</>;
|
|
36
54
|
}
|
|
37
55
|
|
|
56
|
+
/** 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
|
+
function IconListEdit({ block, blockProps, setAttrs, editable }: BlockEditProps) {
|
|
58
|
+
const tp = useMsgs("placeholders");
|
|
59
|
+
const items: Array<{ text: string; href?: string; icon?: string }> = Array.isArray(block.attrs.items) ? block.attrs.items : [];
|
|
60
|
+
const list = items.length || !editable ? items : [{ text: "" }];
|
|
61
|
+
const save = (next: typeof items) => setAttrs({ items: next });
|
|
62
|
+
const icon = (name?: string) => <svg className="ecx-widget-icon" viewBox="0 0 24 24" width={24} height={24} fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" focusable="false"><path d={ICON_PATHS[String(name ?? "")] ?? ICON_PATHS[String(block.attrs.icon ?? "check")] ?? ICON_PATHS.check} /></svg>;
|
|
63
|
+
return (
|
|
64
|
+
<ul {...blockProps} className={cx(blockProps.className, "ecx-icon-list", block.attrs.layout === "inline" && "is-inline")}>
|
|
65
|
+
{list.map((it, i) => (
|
|
66
|
+
<li key={i}>{icon(it.icon)}{editable
|
|
67
|
+
? <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)))} />
|
|
68
|
+
: <span>{it.text}</span>}</li>
|
|
69
|
+
))}
|
|
70
|
+
{editable && <li className="ecx-ph-list-add"><AddItemButton label={tp.addRow} onClick={() => save([...list, { text: "" }])} /></li>}
|
|
71
|
+
</ul>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
38
75
|
/** Danh sách mục của Icon List: mỗi dòng một mục, "chữ | đường dẫn" (đường dẫn tuỳ chọn); dòng trống giữ khi đang gõ, website bỏ qua. Icon riêng từng mục: chỉ qua dữ liệu (AI / mẫu). */
|
|
39
76
|
function IconListInspector({ attrs, setAttrs }: BlockEditProps) {
|
|
40
77
|
const t = useMsgs("blocks") as Record<string, string>;
|
|
@@ -55,11 +92,11 @@ export function widgetBlocks(lang?: string): BlockType[] {
|
|
|
55
92
|
const m = messages("blocks", lang) as Record<string, string>;
|
|
56
93
|
const base = { kind: "atom" as const, category: "widgets", edit: WidgetEdit, supports: { style: true, anchor: true, className: true } };
|
|
57
94
|
return [
|
|
58
|
-
{ ...base, name: "iconBox", title: "Icon Box", icon: Star, keywords: "icon box hop bieu tuong tinh nang dich vu feature", attributes: { ...spec("iconBox"), icon: { ...ICON_SELECT, default: "star" } }, create: () => makeBlock("iconBox", { icon: "star", title:
|
|
59
|
-
{ ...base, 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:
|
|
60
|
-
{ ...base, name: "iconList", 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: [
|
|
61
|
-
{ ...base, name: "counter", title: "Counter", icon: Hash, keywords: "counter dem so con so thong ke number", attributes: spec("counter"), create: () => makeBlock("counter", { end:
|
|
62
|
-
{ ...base, name: "testimonial", title: "Testimonial", icon: Quote, keywords: "testimonial loi chung thuc danh gia khach hang review", attributes: { ...spec("testimonial"), src: { type: "url", control: "media" } }, create: () => makeBlock("testimonial", { quote:
|
|
63
|
-
{ ...base, name: "progressBar", title: "Progress Bar", icon: BarChart3, keywords: "progress bar thanh tien do ky nang phan tram", attributes: spec("progressBar"), create: () => makeBlock("progressBar", { label:
|
|
95
|
+
{ ...base, name: "iconBox", title: "Icon Box", icon: Star, keywords: "icon box hop bieu tuong tinh nang dich vu feature", attributes: { ...spec("iconBox"), icon: { ...ICON_SELECT, default: "star" } }, create: () => makeBlock("iconBox", { icon: "star", title: "", text: "" }), summary: (a) => a.title },
|
|
96
|
+
{ ...base, 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 },
|
|
97
|
+
{ ...base, name: "iconList", 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: [{ text: "" }, { text: "" }] }) },
|
|
98
|
+
{ ...base, name: "counter", title: "Counter", icon: Hash, keywords: "counter dem so con so thong ke number", attributes: spec("counter"), create: () => makeBlock("counter", { end: 0, suffix: "+", title: "", textAlign: "center" }), summary: (a) => a.title },
|
|
99
|
+
{ ...base, name: "testimonial", title: "Testimonial", icon: Quote, keywords: "testimonial loi chung thuc danh gia khach hang review", attributes: { ...spec("testimonial"), src: { type: "url", control: "media" } }, create: () => makeBlock("testimonial", { quote: "", name: "", role: "" }), summary: (a) => a.name },
|
|
100
|
+
{ ...base, name: "progressBar", title: "Progress Bar", icon: BarChart3, keywords: "progress bar thanh tien do ky nang phan tram", attributes: spec("progressBar"), create: () => makeBlock("progressBar", { label: "", value: 80 }), summary: (a) => a.label },
|
|
64
101
|
];
|
|
65
102
|
}
|
|
@@ -64,7 +64,6 @@ export function useBlockProps(block: BNode, state: { selected: boolean; editing:
|
|
|
64
64
|
ref: null,
|
|
65
65
|
"data-ecx-block": block.id,
|
|
66
66
|
"data-type": block.type,
|
|
67
|
-
"data-ecx-title": state.selected ? type?.title ?? block.type : undefined,
|
|
68
67
|
tabIndex: type?.kind === "text" ? undefined : -1,
|
|
69
68
|
id: typeof a.anchor === "string" ? a.anchor : undefined,
|
|
70
69
|
className: cx(
|
|
@@ -105,8 +104,9 @@ export const Block = memo(function Block({ node }: { node: BNode }) {
|
|
|
105
104
|
const props: BlockEditProps = { block: node, attrs: node.attrs, setAttrs, blockProps, selected: selected || editing, editable: scope.mode !== "disabled", labels };
|
|
106
105
|
// 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
|
|
107
106
|
const loop = useContext(LoopPostContext);
|
|
107
|
+
// 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
|
|
108
108
|
if (type?.serverRender && host.renderBlock && !loop)
|
|
109
|
-
return <BlockBoundary id={node.id} type={node.type}><ServerBlock node={node} blockProps={blockProps} fallback={<Edit {...props} />} /></BlockBoundary>;
|
|
109
|
+
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>;
|
|
110
110
|
return <BlockBoundary id={node.id} type={node.type}><Edit {...props} /></BlockBoundary>;
|
|
111
111
|
});
|
|
112
112
|
|
|
@@ -161,13 +161,13 @@ export function InnerBlocks({ parent, appender = "auto" }: { parent: BNode; appe
|
|
|
161
161
|
export function Appender({ docId, parentId, index }: { docId: string; parentId: string | null; index: number }) {
|
|
162
162
|
const { ui, labels } = useEditor();
|
|
163
163
|
return (
|
|
164
|
-
<button type="button" className="ecx-appender"
|
|
164
|
+
<button type="button" className="ecx-appender" title={labels.addBlock} contentEditable={false}
|
|
165
165
|
onMouseDown={(e) => { e.preventDefault(); e.stopPropagation(); }}
|
|
166
166
|
onClick={(e) => {
|
|
167
167
|
const r = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
168
168
|
const f = ui.canvasFrame?.getBoundingClientRect();
|
|
169
169
|
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 } });
|
|
170
|
-
}}>+</button>
|
|
170
|
+
}} data-ecx-placeholder="add"><span aria-hidden="true">+</span> {labels.addBlock}</button>
|
|
171
171
|
);
|
|
172
172
|
}
|
|
173
173
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Nạp TRƯỚC CSS của website nên không đè kiểu dáng nội dung; dùng outline (theme hầu như không dùng) để không đổi bố cục.
|
|
4
4
|
*/
|
|
5
5
|
export const CANVAS_CSS = String.raw`
|
|
6
|
-
:root { --ecx-ui-font: "Be Vietnam Pro", ui-sans-serif, system-ui, sans-serif; --ecx-ui: #1a597b; --ecx-ui-nested: #
|
|
6
|
+
:root { --ecx-ui-font: "Be Vietnam Pro", ui-sans-serif, system-ui, sans-serif; --ecx-ui: #1a597b; --ecx-ui-nested: #7c3aed; --ecx-ui-soft: color-mix(in srgb, var(--ecx-ui) 8%, transparent); color-scheme: light; }
|
|
7
7
|
html, body { margin: 0; min-height: 100%; }
|
|
8
8
|
body.ecx-canvas-body { padding: 0; }
|
|
9
9
|
/* Nền trắng chỉ là mặc định (độ ưu tiên 0): theme nền tối / có màu nền riêng trên body thì canvas phải theo theme */
|
|
@@ -49,15 +49,13 @@ body.ecx-canvas-body { padding: 0; }
|
|
|
49
49
|
.ecx-block.is-selected:is([data-type="tableCell"], [data-type="tableHeader"], [data-type="tableRow"])::after { display: none; }
|
|
50
50
|
/* Đang kéo bôi vùng ô: tắt bôi chữ của trình duyệt (chỉ tô ô) */
|
|
51
51
|
.ecx-cell-selecting, .ecx-cell-selecting * { user-select: none !important; -webkit-user-select: none !important; caret-color: transparent; }
|
|
52
|
-
/* Nhãn loại khối (chỉ khi chọn, khối cấp thường; khối lồng đã có .ecx-nested-label). Không đổi bố cục: absolute, không nhận chuột */
|
|
53
|
-
.ecx-block.is-selected:not(.ecx-nested):not(.ecx-column)[data-type]::after { content: attr(data-ecx-title); position: absolute; left: -2px; top: -3px; transform: translateY(-100%); padding: 1px 8px; border-radius: 4px 4px 0 0; background: var(--ecx-ui); color: #fff; font: 600 11px/1.7 var(--ecx-ui-font); letter-spacing: 0; text-transform: none; white-space: nowrap; pointer-events: none; z-index: 5; }
|
|
54
|
-
.ecx-block.is-selected[data-ecx-title=""]::after { content: none; }
|
|
55
52
|
.ecx-block.is-selected.ecx-nested { outline-color: var(--ecx-ui-nested) !important; }
|
|
56
53
|
[data-ecx-rich] { outline: none; white-space: pre-wrap; word-wrap: break-word; caret-color: currentColor; min-height: 1em; }
|
|
57
54
|
[data-ecx-rich]:focus { outline: none; }
|
|
58
55
|
pre [data-ecx-rich], pre[data-ecx-rich] { white-space: pre-wrap; }
|
|
59
|
-
|
|
60
|
-
[data-ecx-rich][data-empty]
|
|
56
|
+
/* Ô chữ rỗng luôn hiện gợi ý theo vai trò (cả khi chưa chọn khối), cỡ chữ = cỡ chữ thật của ô; độ đậm .7 giữ tương phản ≥ 4.5:1 với màu chữ của theme */
|
|
57
|
+
[data-ecx-rich][data-empty][data-placeholder]::before { content: attr(data-placeholder); opacity: .85; pointer-events: none; position: absolute; }
|
|
58
|
+
[data-ecx-rich][data-empty]:not([data-placeholder-always]):not(:focus)::before, [data-ecx-rich][contenteditable="false"][data-empty]::before { content: none; }
|
|
61
59
|
[data-ecx-rich][data-empty] { position: relative; }
|
|
62
60
|
/* min(100%, …) = 0 trong khung co theo nội dung (nút) → dùng độ dài chữ gợi ý, chặn tràn bằng max-width */
|
|
63
61
|
/* Chỉ ô chữ dạng span (nút, nhãn…): đoạn văn trống KHÔNG đặt max-width — luật này ưu tiên cao hơn cột chữ của khung soạn,
|
|
@@ -65,6 +63,9 @@ pre [data-ecx-rich], pre[data-ecx-rich] { white-space: pre-wrap; }
|
|
|
65
63
|
span[data-ecx-rich][data-empty][data-placeholder] { min-width: calc(var(--ecx-ph, 0) * .6em); max-width: 100%; }
|
|
66
64
|
span[data-ecx-rich][data-empty][data-placeholder] { display: inline-block; vertical-align: top; }
|
|
67
65
|
[data-ecx-rich][data-empty][data-placeholder] { min-width: 0; } /* ô lưới/flex trống không bị chữ gợi ý (nowrap) đẩy rộng hơn khung */
|
|
66
|
+
[data-ecx-rich][data-empty][data-placeholder][contenteditable="true"] { opacity: 1 !important; } /* phần tử vốn mờ (chức danh, chú thích): gợi ý không mờ chồng mờ */
|
|
67
|
+
.ecx-button [data-ecx-rich][data-empty][data-placeholder]::before { opacity: 1; font-style: italic; } /* chữ trên nền màu nút: mờ đi là không đủ tương phản */
|
|
68
|
+
[data-ecx-rich][data-empty][data-placeholder] { flex: 1 1 8em; } /* trong hàng ngang (flex): ô trống không co về 0px (gợi ý là ::before absolute) */
|
|
68
69
|
[data-ecx-rich][data-empty][data-placeholder]::before { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
|
|
69
70
|
.ProseMirror-hideselection *::selection { background: transparent; }
|
|
70
71
|
.ProseMirror-selectednode { outline: 2px solid var(--ecx-ui); }
|
|
@@ -178,4 +179,85 @@ img[data-ecx-bound] { outline: 2px solid color-mix(in srgb, var(--ecx-ui) 45%, t
|
|
|
178
179
|
.ecx-add-column { position: absolute; right: 4px; bottom: 4px; z-index: 7; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px; background: #0f1e29; color: #fff; font: 600 18px/1 var(--ecx-ui-font); cursor: pointer; box-shadow: 0 2px 6px rgb(0 0 0 / .2); }
|
|
179
180
|
.ecx-add-column:hover { background: var(--ecx-ui); }
|
|
180
181
|
.is-zoomed-out .ecx-add-column { display: none; }
|
|
182
|
+
|
|
183
|
+
/* ===== Ô giữ chỗ (chỉ trình soạn; website không vẽ gì khi ô trống) ===== */
|
|
184
|
+
.ecx-ph-drop { align-items: center; justify-content: center; text-align: center; gap: 6px; min-height: 168px; padding: 24px 16px; box-sizing: border-box; border: 2px dashed #b8c2cc; border-radius: 10px; background: #f7f9fb; color: #33414d; transition: border-color .15s, color .15s, background .15s; }
|
|
185
|
+
.ecx-ph-drop.is-compact { min-height: 112px; padding: 14px 12px; }
|
|
186
|
+
.ecx-ph-drop:hover { border-color: var(--ecx-ui); color: var(--ecx-ui); }
|
|
187
|
+
.ecx-ph-drop.is-drop-target, .ecx-media-placeholder.is-drop-target { border-style: solid; border-color: var(--ecx-ui); background: color-mix(in srgb, var(--ecx-ui) 12%, #fff); color: var(--ecx-ui); outline: none; }
|
|
188
|
+
.ecx-ph-icon { width: 28px; height: 28px; }
|
|
189
|
+
.ecx-ph-title { display: inline-flex; align-items: center; justify-content: center; gap: 6px; margin: 0; font: 600 15px/1.4 var(--ecx-ui-font); }
|
|
190
|
+
.ecx-ph-drop .ecx-placeholder-hint { margin: 0 0 6px; color: #4a5763; opacity: 1; }
|
|
191
|
+
.ecx-ph-drop .ecx-media-actions { justify-content: center; }
|
|
192
|
+
.ecx-ph-drop .ecx-media-buttons { justify-content: center; }
|
|
193
|
+
.ecx-media-placeholder { color: #33414d; background: #f7f9fb; border-color: #b8c2cc; }
|
|
194
|
+
.ecx-ph-link, .ecx-ph-pick, .ecx-ph-choose, .ecx-ph-table, .ecx-ph-inline { border: 2px dashed #b8c2cc; border-radius: 10px; padding: 16px; gap: 8px; }
|
|
195
|
+
.ecx-ph-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; font: 13px/1.4 var(--ecx-ui-font); }
|
|
196
|
+
.ecx-ph-row .ecx-input { min-width: 0; }
|
|
197
|
+
.ecx-ph-link .ecx-ph-row .ecx-input { flex: 1 1 220px; }
|
|
198
|
+
.ecx-ph-label { font: 600 12px/1.4 var(--ecx-ui-font); color: #33414d; }
|
|
199
|
+
.ecx-ph-field { display: flex; flex-direction: column; gap: 4px; flex: 1 1 140px; min-width: 0; }
|
|
200
|
+
.ecx-ph-field .ecx-input { height: 36px; flex: none; width: 100%; box-sizing: border-box; }
|
|
201
|
+
.ecx-ph-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
|
|
202
|
+
.ecx-ph-fields .is-media { grid-column: 1 / -1; }
|
|
203
|
+
.ecx-ph-req { color: #b42318; }
|
|
204
|
+
.ecx-ph-thumb { position: relative; display: inline-block; }
|
|
205
|
+
.ecx-ph-thumb img { display: block; max-width: 160px; max-height: 120px; border-radius: 6px; }
|
|
206
|
+
.ecx-ph-thumb .ecx-tool { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .3); cursor: pointer; }
|
|
207
|
+
.ecx-ph-auto { align-items: stretch; }
|
|
208
|
+
.ecx-ph-auto.is-missing, .ecx-ph-theme.is-missing { border: 2px solid #f59e0b; }
|
|
209
|
+
.ecx-ph-missing { margin: 0; padding: 6px 10px; border-radius: 6px; background: #fff4e5; color: #8a2c0d; font: 600 12px/1.4 var(--ecx-ui-font); }
|
|
210
|
+
.ecx-ph-missing.is-note { margin-top: 6px; }
|
|
211
|
+
.ecx-ph-badge { display: inline-flex; align-self: flex-start; align-items: center; padding: 2px 8px; border-radius: 999px; font: 600 11px/1.6 var(--ecx-ui-font); }
|
|
212
|
+
.ecx-ph-badge.is-missing { background: #fff4e5; color: #8a2c0d; border: 1px solid #f59e0b; }
|
|
213
|
+
.ecx-ph-theme { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px; border-radius: 8px; background: #fffaf3; color: #33414d; font: 13px/1.4 var(--ecx-ui-font); }
|
|
214
|
+
.ecx-featured-image .ecx-ph-theme { height: 100%; box-sizing: border-box; justify-content: center; align-items: center; text-align: center; }
|
|
215
|
+
.ecx-ph-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
|
|
216
|
+
.ecx-ph-choice { display: inline-flex; flex-direction: column; align-items: center; gap: 6px; min-width: 96px; padding: 14px 12px; border: 1px solid #c9d0d7; border-radius: 8px; background: #fff; color: #1f2d38; font: 600 13px var(--ecx-ui-font); cursor: pointer; }
|
|
217
|
+
.ecx-ph-choice:hover, .ecx-ph-choice:focus-visible { border-color: var(--ecx-ui); color: var(--ecx-ui); }
|
|
218
|
+
.ecx-ph-choice .ecx-icon { width: 24px; height: 24px; }
|
|
219
|
+
.ecx-ph-choose { align-items: center; text-align: center; }
|
|
220
|
+
/* Ô gõ của plugin / icon list: kế thừa phông + cỡ chữ của chỗ đặt ô */
|
|
221
|
+
.ecx-ph-text { box-sizing: border-box; width: 100%; min-width: 4em; margin: 0; padding: 0 0 1px; border: 0; border-bottom: 1px dashed color-mix(in srgb, currentColor 35%, transparent); border-radius: 0; background: transparent; color: inherit; font: inherit; letter-spacing: inherit; line-height: inherit; resize: vertical; outline: none; field-sizing: content; }
|
|
222
|
+
.ecx-ph-text::placeholder { color: inherit; opacity: .85; }
|
|
223
|
+
.ecx-ph-text:focus { border-bottom-color: var(--ecx-ui); }
|
|
224
|
+
.ecx-ph-field .ecx-ph-text.ecx-input { border: 1px solid #c9d0d7; border-radius: 6px; padding: 6px 8px; height: auto; min-height: 36px; background: #fff; color: #1f2d38; font: 14px/1.4 var(--ecx-ui-font); }
|
|
225
|
+
.ecx-ph-field .ecx-ph-text::placeholder { color: #5b6873; opacity: 1; }
|
|
226
|
+
/* Nút "+ Thêm khối" giữa khối chứa trống, "+ Thêm …" cuối danh sách */
|
|
227
|
+
.ecx-appender { gap: 6px; min-height: 56px; border: 2px dashed color-mix(in srgb, currentColor 35%, transparent); border-radius: 8px; font: 600 14px/1 var(--ecx-ui-font); opacity: .85; }
|
|
228
|
+
.ecx-appender .ecx-icon { width: 18px; height: 18px; }
|
|
229
|
+
.ecx-add-item { display: inline-flex; align-items: center; gap: 4px; margin: 6px 0 0; padding: 6px 10px; border: 1px dashed color-mix(in srgb, currentColor 40%, transparent); border-radius: 6px; background: transparent; color: inherit; font: 600 13px/1.2 var(--ecx-ui-font); cursor: pointer; opacity: .85; }
|
|
230
|
+
.ecx-add-item:hover, .ecx-add-item:focus-visible { opacity: 1; border-color: var(--ecx-ui); color: var(--ecx-ui); }
|
|
231
|
+
.ecx-tabs-list .ecx-add-item { margin: 0 0 0 8px; align-self: center; }
|
|
232
|
+
.ecx-social .ecx-add-item, .ecx-social-add .ecx-add-item { margin: 0; }
|
|
233
|
+
.ecx-ph-list-add { list-style: none; }
|
|
234
|
+
.ecx-ph-list-add .ecx-add-item { margin-top: 2px; }
|
|
235
|
+
.ecx-gallery-add { grid-column: auto; min-height: 0; aspect-ratio: 1; }
|
|
236
|
+
.ecx-gallery-add .ecx-placeholder-hint { display: none; }
|
|
237
|
+
/* Mã nguồn: chọn ngôn ngữ trên khối; danh sách số: số bắt đầu */
|
|
238
|
+
.ecx-ph-corner { display: flex; justify-content: flex-end; align-items: center; gap: 6px; margin: 0 0 6px; font: 12px var(--ecx-ui-font); white-space: normal; }
|
|
239
|
+
.ecx-ph-corner > label, .ecx-ph-corner > span { background: #fff; color: #33414d; border-radius: 4px; padding: 1px 6px; }
|
|
240
|
+
.ecx-ph-corner .ecx-input { width: auto; height: 28px; font-size: 12px; }
|
|
241
|
+
.ecx-ph-corner.is-list { list-style: none; justify-content: flex-start; margin: 6px 0 0; }
|
|
242
|
+
.ecx-ph-corner.is-list input { width: 72px; }
|
|
243
|
+
.ecx-ph-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
|
|
244
|
+
.ecx-ph-digits { font: 600 28px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .05em; }
|
|
245
|
+
.ecx-ph-star { padding: 0 1px; border: 0; background: none; font: inherit; line-height: 1; cursor: pointer; }
|
|
246
|
+
.ecx-ph-star:hover { transform: scale(1.15); }
|
|
247
|
+
.ecx-ph-tabs { display: flex; align-items: center; gap: 6px; margin: 0 0 6px; font: 600 12px var(--ecx-ui-font); }
|
|
248
|
+
.ecx-ph-tab { padding: 4px 10px; border: 1px solid #c9d0d7; border-radius: 6px; background: #fff; color: #33414d; font: 600 12px var(--ecx-ui-font); cursor: pointer; }
|
|
249
|
+
.ecx-ph-tab.is-active { background: var(--ecx-ui); border-color: var(--ecx-ui); color: #fff; }
|
|
250
|
+
.ecx-ph-tab:disabled { opacity: .5; cursor: default; }
|
|
251
|
+
.ecx-ph-inline-field { margin-top: 8px; justify-content: center; }
|
|
252
|
+
.ecx-ph-inline-field .ecx-input { width: 110px; flex: none; }
|
|
253
|
+
.ecx-ph-note { margin: .25rem 0; }
|
|
254
|
+
.ecx-ph-table .ecx-ph-field { flex: 0 1 110px; }
|
|
255
|
+
/* 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) */
|
|
256
|
+
.ecx-spacer[data-ecx-size] { display: flex; align-items: center; justify-content: center; min-height: 24px; }
|
|
257
|
+
.ecx-spacer[data-ecx-size]::before { 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; }
|
|
258
|
+
.ecx-spacer[data-ecx-size]:hover::before, .ecx-spacer.is-selected[data-ecx-size]::before { opacity: 1; }
|
|
259
|
+
.ecx-rating[data-ecx-placeholder] { display: flex; align-items: center; gap: 2px; min-height: 40px; }
|
|
260
|
+
.ecx-rating[data-ecx-placeholder] .ecx-placeholder-hint { margin: 0 0 0 8px; }
|
|
261
|
+
hr.ecx-block { position: relative; overflow: visible; }
|
|
262
|
+
hr.ecx-block::before { content: ""; position: absolute; left: 0; right: 0; top: -20px; bottom: -20px; }
|
|
181
263
|
`;
|
|
@@ -3,6 +3,7 @@ import { useEditor } from "../context";
|
|
|
3
3
|
import { docFromBlocks, type BNode } from "../core/model";
|
|
4
4
|
import type { BlockEditProps } from "../core/registry";
|
|
5
5
|
import { sanitizeServerHtml } from "./server-html";
|
|
6
|
+
import { useMsgs } from "../i18n";
|
|
6
7
|
|
|
7
8
|
const MEDIA = "img, svg, video, canvas, picture, iframe, input, select, textarea, button, hr";
|
|
8
9
|
/** Có chữ hoặc ảnh / hình / ô nhập nào thấy được không (khung rỗng thì không). */
|
|
@@ -20,8 +21,9 @@ const CACHE_LIMIT = 300;
|
|
|
20
21
|
* Khối động / khối của theme-plugin do **website** vẽ bằng chính code + CSS của theme (host.renderBlock) — khung soạn thấy
|
|
21
22
|
* đúng menu riêng, breadcrumb thật… như trang thật. Đang tải hoặc website không vẽ được → giao diện của trình soạn (`fallback`).
|
|
22
23
|
*/
|
|
23
|
-
export function ServerBlock({ node, blockProps, fallback }: { node: BNode; blockProps: BlockEditProps["blockProps"]; fallback: ReactNode }) {
|
|
24
|
+
export function ServerBlock({ node, blockProps, fallback, live = true }: { node: BNode; blockProps: BlockEditProps["blockProps"]; fallback: ReactNode; live?: boolean }) {
|
|
24
25
|
const { host } = useEditor();
|
|
26
|
+
const tp = useMsgs("placeholders");
|
|
25
27
|
const json = docFromBlocks([node]).content?.[0];
|
|
26
28
|
const key = JSON.stringify(json ?? null);
|
|
27
29
|
const [html, setHtml] = useState<string | null | undefined>(() => cache.get(key));
|
|
@@ -38,10 +40,11 @@ export function ServerBlock({ node, blockProps, fallback }: { node: BNode; block
|
|
|
38
40
|
}, 250);
|
|
39
41
|
return () => { alive = false; clearTimeout(timer); };
|
|
40
42
|
}, [key, host]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
41
|
-
|
|
43
|
+
// fallback luôn là con đầu của cùng một Fragment ở mọi nhánh dưới → đổi nhánh không dựng lại ô nhập đang gõ
|
|
44
|
+
if (!live || !html) return <>{fallback}</>;
|
|
42
45
|
const clean = sanitizeServerHtml(html, document);
|
|
43
|
-
// Website vẽ ra rỗng (thiếu dữ liệu
|
|
44
|
-
if (!hasVisibleContent(clean)) return <
|
|
46
|
+
// Website vẽ ra rỗng (thiếu dữ liệu, theme chưa hỗ trợ khối…) → ô giữ chỗ của trình soạn (nhập được ngay) + nói rõ website chưa vẽ gì
|
|
47
|
+
if (!hasVisibleContent(clean)) return <>{fallback}<p className="ecx-ph-missing is-note" contentEditable={false}>{tp.serverEmpty}</p></>;
|
|
45
48
|
return (
|
|
46
49
|
<div {...blockProps} className={[blockProps.className, "ecx-server-block"].filter(Boolean).join(" ")} contentEditable={false}>
|
|
47
50
|
{/* pointer-events: none → bấm vào là chọn khối, không mở liên kết / gửi form của trang thật */}
|
package/src/v2/core/host.ts
CHANGED
|
@@ -29,6 +29,13 @@ export interface EditorHost {
|
|
|
29
29
|
canvasContentClass?: string;
|
|
30
30
|
/** Mở nơi sửa menu của một vị trí (khối Menu đang chọn hiện nút "Sửa menu"). Không có → không hiện nút. */
|
|
31
31
|
editMenu?(location: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* Mở trang quản trị để nhập dữ liệu còn thiếu của khối giao diện (ô giữ chỗ cam): "menus" (tạo / chọn menu), "customize" (logo, tên
|
|
34
|
+
* website), "newPost" (viết bài đầu tiên; args.postType). Không có → không hiện nút.
|
|
35
|
+
*/
|
|
36
|
+
openAdmin?(target: "menus" | "customize" | "settings" | "newPost", args?: Record<string, string>): void;
|
|
37
|
+
/** Đặt logo cho cả website từ ô thả logo của khối Logo (trả về khi đã lưu). Không có → ô thả logo chỉ có nút mở Tuỳ biến. */
|
|
38
|
+
setSiteLogo?(item: import("../../shared/types").MediaItem): Promise<void>;
|
|
32
39
|
/**
|
|
33
40
|
* Website vẽ giúp một khối (nút nội dung dạng JSON như khi lưu) bằng code + CSS của theme → HTML. null = không vẽ được
|
|
34
41
|
* (trình soạn dùng giao diện của mình). Dùng cho khối có `serverRender` (khối động, khối plugin/theme không có `edit`).
|
|
@@ -58,6 +65,8 @@ export interface EditorHost {
|
|
|
58
65
|
*/
|
|
59
66
|
ai?: {
|
|
60
67
|
run(task: string, text: string, opts?: { language?: string; instruction?: string }): Promise<string>;
|
|
68
|
+
/** Viết nội dung mới theo yêu cầu; `nodes` là khối dạng lưu (tiêu đề, danh sách…) — có thì chèn đúng khối, không thì tách `text` thành đoạn văn. */
|
|
69
|
+
write?(prompt: string): Promise<{ text: string; nodes?: unknown[] }>;
|
|
61
70
|
/** Mô tả (alt) cho ảnh trong thư viện media; không có = khối Ảnh không hiện nút AI. */
|
|
62
71
|
altText?(mediaId: number, language?: string): Promise<string>;
|
|
63
72
|
};
|
package/src/v2/core/registry.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface BlockEditProps {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
export type BlockProps = HTMLAttributes<HTMLElement> & { ref: Ref<any>; "data-ecx-block": string; "data-type": string
|
|
25
|
+
export type BlockProps = HTMLAttributes<HTMLElement> & { ref: Ref<any>; "data-ecx-block": string; "data-type": string };
|
|
26
26
|
|
|
27
27
|
export type BlockCategory = "text" | "media" | "design" | "widgets" | "theme" | "embed" | (string & {});
|
|
28
28
|
|
|
@@ -79,6 +79,8 @@ export interface BlockType {
|
|
|
79
79
|
* ServerSideRender chỉ cho khối động của plugin). `edit` chỉ dùng khi đang tải / website không vẽ được / khối nằm trong vòng lặp bài.
|
|
80
80
|
*/
|
|
81
81
|
serverRender?: boolean;
|
|
82
|
+
/** Khối `serverRender`: đang chọn thì vẽ `edit` (ô giữ chỗ để nhập), bỏ chọn mới hiện bản website vẽ. */
|
|
83
|
+
editWhenSelected?: boolean;
|
|
82
84
|
/** Thanh công cụ riêng của khối (chèn vào thanh công cụ nổi). */
|
|
83
85
|
toolbar?: ComponentType<BlockEditProps>;
|
|
84
86
|
/**
|
package/src/v2/core/structure.ts
CHANGED
|
@@ -32,7 +32,8 @@ const RULES: Record<string, StructureRule> = {
|
|
|
32
32
|
column: { parents: ["columns"], wrapSelfWith: "columns" },
|
|
33
33
|
buttons: { allowedChildren: ["button"], removeWhenEmpty: true },
|
|
34
34
|
button: { parents: ["buttons"], wrapSelfWith: "buttons" },
|
|
35
|
-
|
|
35
|
+
// Bảng rỗng (vừa chèn, chưa chọn kích thước) giữ lại: trình soạn hỏi số cột / hàng, website không vẽ bảng không có hàng
|
|
36
|
+
table: { allowedChildren: ["tableRow"], wrapChildrenWith: "tableRow" },
|
|
36
37
|
tableRow: { parents: ["table"], allowedChildren: ["tableCell", "tableHeader"], wrapChildrenWith: "tableCell", removeWhenEmpty: true },
|
|
37
38
|
tableCell: { parents: ["tableRow"], required: p },
|
|
38
39
|
tableHeader: { parents: ["tableRow"], required: p },
|
package/src/v2/editor.css
CHANGED
|
@@ -174,13 +174,17 @@ select.ecx-input { padding-right: 6px; }
|
|
|
174
174
|
.ecx-list-row:hover .ecx-list-drag { opacity: 1; }
|
|
175
175
|
|
|
176
176
|
/* Kéo thả */
|
|
177
|
-
.ecx-drop-line { position: fixed; z-index: 45; background: var(--ecx-ed-accent, #1a597b); border-radius: 2px; pointer-events: none; box-shadow: 0 0 0 1px #fff; }
|
|
177
|
+
.ecx-drop-line { position: fixed; z-index: 45; background: var(--ecx-ed-accent, #1a597b); border-radius: 2px; pointer-events: none; box-shadow: 0 0 0 1px #fff, 0 0 0 7px color-mix(in srgb, var(--ecx-ed-accent, #1a597b) 22%, transparent); } /* vị trí thả: dải xanh rõ, không chỉ vạch mảnh */
|
|
178
|
+
.ecx-drop-line { transform-origin: center; animation: ecx-drop-grow .2s ease-out; }
|
|
179
|
+
.ecx-drop-line[data-horizontal] { animation-name: ecx-drop-grow-y; }
|
|
180
|
+
@keyframes ecx-drop-grow { from { transform: scaleX(0); opacity: 0; } }
|
|
181
|
+
@keyframes ecx-drop-grow-y { from { transform: scaleY(0); opacity: 0; } }
|
|
178
182
|
.ecx-drag-chip.is-blocked { opacity: .55; }
|
|
179
183
|
.ecx-drag-chip { display: inline-flex; align-items: center; gap: 6px; position: fixed; z-index: 46; padding: 3px 8px; background: var(--ecx-ed-fg, #0f1e29); color: var(--ecx-ed-panel, #fff); border-radius: 6px; font: 600 12px var(--ecx-ed-font, system-ui); pointer-events: none; box-shadow: var(--ecx-ed-shadow); }
|
|
180
184
|
body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select: none !important; }
|
|
181
185
|
|
|
182
186
|
@media (prefers-reduced-motion: reduce) {
|
|
183
|
-
.ecx-toolbar, .ecx-menu, .ecx-popover, .ecx-left, .ecx-right { animation: none; }
|
|
187
|
+
.ecx-toolbar, .ecx-menu, .ecx-popover, .ecx-left, .ecx-right, .ecx-drop-line { animation: none; }
|
|
184
188
|
.ecx-pattern-card:hover, .ecx-tool:active:not(:disabled) { transform: none; }
|
|
185
189
|
}
|
|
186
190
|
|
package/src/v2/index.ts
CHANGED
|
@@ -9,6 +9,9 @@ export { BlockToolbar, BlockContextMenu, DropIndicator, ToolButton, Dropdown, Me
|
|
|
9
9
|
export { InserterPanel, InserterPopover, rankOptions, useInsertOptions, type InsertOption } from "./ui/inserter";
|
|
10
10
|
export { Inspector } from "./ui/inspector";
|
|
11
11
|
export { AttrForm } from "./ui/attr-form";
|
|
12
|
+
export { MediaPlaceholder, TextPlaceholder, LinkPlaceholder, PickPlaceholder, AddBlockButton, AddItemButton, MissingNote, type MediaPlaceholderProps, type TextPlaceholderProps, type LinkPlaceholderProps, type PickPlaceholderProps, type AddBlockButtonProps } from "./ui/placeholders";
|
|
13
|
+
export { MediaActions, useFileDrop } from "./ui/media-actions";
|
|
14
|
+
export { placeholderFields } from "./blocks/compat";
|
|
12
15
|
export { ListView, blockLabel } from "./ui/list-view";
|
|
13
16
|
export { Block, InnerBlocks, NestedDoc, DocBlocks, Appender, FallbackEdit, useBlockProps } from "./canvas/block-list";
|
|
14
17
|
export { RichText, richViews, type RichTextProps } from "./text/rich-text";
|
package/src/v2/ui/ai.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Sparkles } from "lucide-react";
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
3
|
import { useEditor } from "../context";
|
|
4
|
-
import {
|
|
4
|
+
import type { RichNode } from "@ecomcx/ecomweb-content";
|
|
5
|
+
import { fromRich, inlineText, makeBlock, type BNode } from "../core/model";
|
|
5
6
|
import { Modal } from "./options";
|
|
6
7
|
import { Dropdown, MenuItem, ToolButton } from "./toolbar";
|
|
7
8
|
|
|
@@ -95,19 +96,22 @@ export function AiWrite() {
|
|
|
95
96
|
const { host, labels, store, ui } = useEditor();
|
|
96
97
|
const [at, setAt] = useState<{ blockId?: string; docId: string; parentId: string | null; index: number } | null>(null);
|
|
97
98
|
const [prompt, setPrompt] = useState("");
|
|
98
|
-
const [state, setState] = useState<{ loading: boolean; text?: string; error?: string }>({ loading: false });
|
|
99
|
+
const [state, setState] = useState<{ loading: boolean; text?: string; nodes?: RichNode[]; error?: string }>({ loading: false });
|
|
99
100
|
useEffect(() => { ui.openAiWrite = (a) => { setAt(a); setPrompt(""); setState({ loading: false }); }; return () => { ui.openAiWrite = null; }; }, [ui]);
|
|
100
101
|
if (!at || !host.ai) return null;
|
|
101
102
|
const run = async () => {
|
|
102
103
|
if (!prompt.trim()) return;
|
|
103
104
|
setState({ loading: true });
|
|
104
|
-
try {
|
|
105
|
-
|
|
105
|
+
try {
|
|
106
|
+
const r = host.ai!.write ? await host.ai!.write(prompt.trim()) : { text: await host.ai!.run("write", prompt.trim(), {}) };
|
|
107
|
+
setState({ loading: false, text: r.text, nodes: Array.isArray(r.nodes) && r.nodes.length ? r.nodes as RichNode[] : undefined });
|
|
108
|
+
} catch (e) { setState({ loading: false, error: (e as Error).message }); }
|
|
106
109
|
};
|
|
107
110
|
const paragraphs = (state.text ?? "").split(/\n{2,}/).map((p) => p.trim()).filter(Boolean);
|
|
108
111
|
const insert = () => {
|
|
109
112
|
if (!paragraphs.length) return;
|
|
110
|
-
|
|
113
|
+
// Có khối dạng lưu (tiêu đề, danh sách) thì chèn đúng khối; ứng dụng cũ chỉ trả chữ → mỗi đoạn một khối đoạn văn
|
|
114
|
+
const nodes = state.nodes ? state.nodes.map(fromRich) : paragraphs.map((p) => makeBlock("paragraph", {}, p));
|
|
111
115
|
store.batch(() => {
|
|
112
116
|
if (at.blockId && store.block(at.blockId)) store.replace(at.blockId, nodes);
|
|
113
117
|
else store.insert(at.docId, at.parentId, at.index, nodes);
|
package/src/v2/ui/attr-form.tsx
CHANGED
|
@@ -16,10 +16,10 @@ export const attrName = (name: string, lang: string): string | undefined => { co
|
|
|
16
16
|
/** Thuộc tính sửa ở chỗ khác (thanh công cụ, trên khung soạn) hoặc dữ liệu kỹ thuật. */
|
|
17
17
|
const HIDDEN_ATTRS = new Set(["style", "blockStyle", "anchor", "className", "mediaId", "srcset", "webpSrcset", "images", "links", "colwidth", "colspan", "rowspan", "_v", "id"]); // gộp ô: dùng lệnh Gộp / Tách của công cụ bảng (sửa số tay làm lệch bảng)
|
|
18
18
|
|
|
19
|
-
const attrLabel = (name: string, spec: BlockAttrSpec, lang: string, translate?: (s: string) => string) =>
|
|
19
|
+
export const attrLabel = (name: string, spec: BlockAttrSpec, lang: string, translate?: (s: string) => string) =>
|
|
20
20
|
spec.label ? (translate ? translate(spec.label) : spec.label) : attrName(name, lang) ?? name;
|
|
21
21
|
|
|
22
|
-
function controlOf(spec: BlockAttrSpec): NonNullable<BlockAttrSpec["control"]> {
|
|
22
|
+
export function controlOf(spec: BlockAttrSpec): NonNullable<BlockAttrSpec["control"]> {
|
|
23
23
|
if (spec.control) return spec.control;
|
|
24
24
|
if (spec.enum) return "select";
|
|
25
25
|
switch (spec.type) {
|
|
@@ -19,7 +19,7 @@ export function mediaAttrs(kind: MediaKind, items: MediaItem[]): Record<string,
|
|
|
19
19
|
* Chọn media ngay trên khối: Tải lên (có thể kéo thả tệp vào cả vùng), Thư viện, Chèn từ URL. Dùng cho ảnh, gallery,
|
|
20
20
|
* video, âm thanh, tệp, ảnh bìa, ảnh + chữ.
|
|
21
21
|
*/
|
|
22
|
-
export function MediaActions({ kind, onSelect, onUrl, compact, extra }: { kind: MediaKind; onSelect(items: MediaItem[]): void; onUrl?(url: string): void; compact?: boolean; extra?: ReactNode }) {
|
|
22
|
+
export function MediaActions({ kind, onSelect, onUrl, compact, extra, accept }: { kind: MediaKind; onSelect(items: MediaItem[]): void; onUrl?(url: string): void; compact?: boolean; extra?: ReactNode; accept?: string }) {
|
|
23
23
|
const { host, labels } = useEditor();
|
|
24
24
|
const file = useRef<HTMLInputElement>(null);
|
|
25
25
|
const [busy, setBusy] = useState(false);
|
|
@@ -49,7 +49,7 @@ export function MediaActions({ kind, onSelect, onUrl, compact, extra }: { kind:
|
|
|
49
49
|
</form>
|
|
50
50
|
)}
|
|
51
51
|
{error && <p className="ecx-media-error" role="alert">{error}</p>}
|
|
52
|
-
<input ref={file} type="file" hidden accept={ACCEPT[kind] || undefined} multiple={kind === "gallery"} onChange={(e) => { void upload([...(e.target.files ?? [])]); e.target.value = ""; }} />
|
|
52
|
+
<input ref={file} type="file" hidden accept={accept ?? (ACCEPT[kind] || undefined)} multiple={kind === "gallery"} onChange={(e) => { void upload([...(e.target.files ?? [])]); e.target.value = ""; }} />
|
|
53
53
|
</div>
|
|
54
54
|
);
|
|
55
55
|
}
|
|
@@ -64,7 +64,8 @@ export function useFileDrop(kind: MediaKind, onSelect: (items: MediaItem[]) => v
|
|
|
64
64
|
over,
|
|
65
65
|
props: {
|
|
66
66
|
onDragOver: (e: DragEvent) => { if (!hasFiles(e)) return; e.preventDefault(); setOver(true); },
|
|
67
|
-
|
|
67
|
+
// Rời sang phần tử con vẫn ở trong vùng: giữ trạng thái (không nhấp nháy)
|
|
68
|
+
onDragLeave: (e: DragEvent) => { if (!(e.currentTarget as Node).contains(e.relatedTarget as Node | null)) setOver(false); },
|
|
68
69
|
onDrop: async (e: DragEvent) => {
|
|
69
70
|
if (!hasFiles(e)) return;
|
|
70
71
|
e.preventDefault(); setOver(false);
|