@ecomcx/ecomweb-editor 1.26.0 → 1.26.2
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 +1 -1
- package/src/locales/en/v2.ts +8 -0
- package/src/locales/vi/v2.ts +8 -0
- package/src/v2/blocks/media.tsx +4 -1
- package/src/v2/context.tsx +2 -0
- package/src/v2/core/host.ts +5 -1
- package/src/v2/editor.css +2 -0
- package/src/v2/editor.tsx +2 -0
- package/src/v2/ui/ai.tsx +65 -3
- package/src/v2/ui/inserter.tsx +12 -4
- package/src/v2/ui/options.tsx +6 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecomcx/ecomweb-editor",
|
|
3
|
-
"version": "1.26.
|
|
3
|
+
"version": "1.26.2",
|
|
4
4
|
"description": "Trình soạn nội dung dạng khối của CMS — dùng độc lập trong mọi dự án React (1.x: TipTap; ./v2: cây khối, khung soạn iframe, sửa header/footer tại chỗ).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/src/locales/en/v2.ts
CHANGED
|
@@ -58,6 +58,14 @@ export const v2 = {
|
|
|
58
58
|
aiReplace: "Replace",
|
|
59
59
|
aiInsertBelow: "Insert below",
|
|
60
60
|
aiRetry: "Try again",
|
|
61
|
+
aiWrite: "Write with AI",
|
|
62
|
+
aiWriteHint: "AI writes paragraphs from your request",
|
|
63
|
+
aiWritePrompt: "What should the AI write? E.g. a short intro to a tea shop, 3 sentences",
|
|
64
|
+
aiWriteRun: "Write",
|
|
65
|
+
aiInsert: "Insert into post",
|
|
66
|
+
aiAlt: "Generate image description (alt) with AI",
|
|
67
|
+
aiAltNoMedia: "Pick the image from the media library first",
|
|
68
|
+
aiAltDone: "Description filled in",
|
|
61
69
|
widthDefault: "Text column",
|
|
62
70
|
widthWide: "Wide",
|
|
63
71
|
widthFull: "Full width",
|
package/src/locales/vi/v2.ts
CHANGED
|
@@ -58,6 +58,14 @@ export const v2 = {
|
|
|
58
58
|
aiReplace: "Thay thế",
|
|
59
59
|
aiInsertBelow: "Chèn bên dưới",
|
|
60
60
|
aiRetry: "Thử lại",
|
|
61
|
+
aiWrite: "Viết bằng AI",
|
|
62
|
+
aiWriteHint: "AI viết đoạn văn từ yêu cầu của bạn",
|
|
63
|
+
aiWritePrompt: "Bạn muốn AI viết gì? Ví dụ: giới thiệu ngắn về cửa hàng trà, 3 câu",
|
|
64
|
+
aiWriteRun: "Viết",
|
|
65
|
+
aiInsert: "Chèn vào bài",
|
|
66
|
+
aiAlt: "Tạo mô tả ảnh (alt) bằng AI",
|
|
67
|
+
aiAltNoMedia: "Chọn ảnh từ thư viện media trước",
|
|
68
|
+
aiAltDone: "Đã điền mô tả",
|
|
61
69
|
widthDefault: "Theo cột chữ",
|
|
62
70
|
widthWide: "Rộng",
|
|
63
71
|
widthFull: "Toàn trang",
|
package/src/v2/blocks/media.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import { blockShell, embedInfo, isSafeUrl } from "@ecomcx/ecomweb-content";
|
|
|
2
2
|
import { ArrowDown, ArrowUp, Code2, File as FileIcon, Image as ImageIcon, Images, ListTree, Music, Plus, Share2, Video, Play, Globe, X } from "lucide-react";
|
|
3
3
|
import { useState, type CSSProperties } from "react";
|
|
4
4
|
import { useEditor } from "../context";
|
|
5
|
+
import { AiAltButton } from "../ui/ai";
|
|
5
6
|
import type { BlockEditProps, BlockType } from "../core/registry";
|
|
6
7
|
import { RichText } from "../text/rich-text";
|
|
7
8
|
import { BoundText, useBindingPreview } from "../ui/bindings";
|
|
@@ -28,6 +29,8 @@ function MediaPlaceholder({ blockId, kind, icon: Icon, title, blockProps }: { bl
|
|
|
28
29
|
);
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
function ImageAiTools({ attrs, setAttrs }: BlockEditProps) { return <AiAltButton attrs={attrs} setAttrs={setAttrs} />; }
|
|
33
|
+
|
|
31
34
|
function ImageEdit({ block, blockProps, setAttrs, editable, labels, selected }: BlockEditProps) {
|
|
32
35
|
const a = block.attrs;
|
|
33
36
|
const bSrc = useBindingPreview(block, "src"), bAlt = useBindingPreview(block, "alt"), bCap = useBindingPreview(block, "caption");
|
|
@@ -256,7 +259,7 @@ export function mediaBlocks(): BlockType[] {
|
|
|
256
259
|
const media = { src: { type: "url" as const, control: "media" as const }, mediaId: { type: "json" as const }, caption: { type: "string" as const } };
|
|
257
260
|
return [
|
|
258
261
|
{
|
|
259
|
-
name: "image", title: "Ảnh", icon: ImageIcon, category: "media", keywords: "anh hinh image photo", kind: "atom", edit: ImageEdit,
|
|
262
|
+
name: "image", title: "Ảnh", icon: ImageIcon, category: "media", keywords: "anh hinh image photo", kind: "atom", edit: ImageEdit, toolbar: ImageAiTools,
|
|
260
263
|
attributes: { ...media, alt: { type: "string", control: "textarea" }, title: { type: "string" }, width: { type: "number" }, height: { type: "number" }, size: { type: "string", default: "large" }, align: { type: "string", enum: ["left", "right", "center", "wide", "full"] }, href: { type: "url" }, linkTarget: { type: "string", enum: ["_self", "_blank"] }, lightbox: { type: "boolean", default: false } },
|
|
261
264
|
supports: { style: true, anchor: true, className: true, blockStyle: true }, summary: (a) => a.alt || a.src,
|
|
262
265
|
},
|
package/src/v2/context.tsx
CHANGED
|
@@ -42,6 +42,8 @@ export class EditorUi {
|
|
|
42
42
|
activeRich: string | null = null;
|
|
43
43
|
/** Mở hộp sửa liên kết cho ô gõ (khoá richViews). */
|
|
44
44
|
openLink: ((viewKey: string) => void) | null = null;
|
|
45
|
+
/** Mở hộp "Viết bằng AI": chèn ở vị trí (khối chứa lệnh /ai thì thay khối đó). */
|
|
46
|
+
openAiWrite: ((at: { blockId?: string; docId: string; parentId: string | null; index: number }) => void) | null = null;
|
|
45
47
|
|
|
46
48
|
subscribe = (l: () => void) => { this.listeners.add(l); return () => { this.listeners.delete(l); }; };
|
|
47
49
|
getTick = () => this.tick;
|
package/src/v2/core/host.ts
CHANGED
|
@@ -56,7 +56,11 @@ export interface EditorHost {
|
|
|
56
56
|
* Trợ lý AI (ứng dụng gọi nhà cung cấp, trình soạn chỉ gửi chữ và nhận chữ). Không có → không hiện menu AI.
|
|
57
57
|
* `task`: rewrite | shorten | expand | fix | summarize | translate | custom. Lỗi: ném Error có thông báo cho người dùng.
|
|
58
58
|
*/
|
|
59
|
-
ai?: {
|
|
59
|
+
ai?: {
|
|
60
|
+
run(task: string, text: string, opts?: { language?: string; instruction?: string }): Promise<string>;
|
|
61
|
+
/** Mô tả (alt) cho ảnh trong thư viện media; không có = khối Ảnh không hiện nút AI. */
|
|
62
|
+
altText?(mediaId: number, language?: string): Promise<string>;
|
|
63
|
+
};
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
/** Nội dung lưu (ContentDoc của @ecomcx/ecomweb-content). */
|
package/src/v2/editor.css
CHANGED
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
.ecx-tool-primary:hover:not(:disabled) { background: var(--ecx-ed-accent-hover); color: var(--ecx-ed-accent-fg); }
|
|
63
63
|
.ecx-tool-primary.is-active { background: var(--ecx-ed-fg); color: var(--ecx-ed-panel); }
|
|
64
64
|
.ecx-tool-text { font-weight: 500; white-space: nowrap; color: inherit; }
|
|
65
|
+
.ecx-tool-text:has(> .ecx-icon) { display: inline-flex; align-items: center; gap: 4px; }
|
|
65
66
|
.ecx-tool-group { display: flex; align-items: center; }
|
|
66
67
|
.ecx-tool:active:not(:disabled) { transform: scale(.97); }
|
|
67
68
|
|
|
@@ -206,6 +207,7 @@ body.is-dragging, body.is-dragging * { cursor: grabbing !important; user-select:
|
|
|
206
207
|
.ecx-modal-backdrop { position: fixed; inset: 0; z-index: 1100; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgb(15 30 41 / .4); animation: ecx-pop .16s var(--ecx-ed-ease); }
|
|
207
208
|
.ecx-modal { width: 100%; max-width: 480px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--ecx-ed-panel); color: var(--ecx-ed-fg); border: 1px solid var(--ecx-ed-line); border-radius: 12px; box-shadow: 0 24px 64px -12px rgb(14 40 58 / .35); font: 13px/1.45 var(--ecx-ed-font); overflow: hidden; }
|
|
208
209
|
.ecx-modal.is-wide { max-width: 760px; height: min(620px, calc(100vh - 32px)); }
|
|
210
|
+
.ecx-modal.is-wide:has(.ecx-ai-body) { height: auto; max-width: 640px; } /* hộp AI: cao vừa nội dung, không để khoảng trống */
|
|
209
211
|
.ecx-modal-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--ecx-ed-line); }
|
|
210
212
|
.ecx-modal-header h2 { margin: 0; font-size: 15px; font-weight: 600; }
|
|
211
213
|
.ecx-prefs { display: flex; min-height: 0; flex: 1; }
|
package/src/v2/editor.tsx
CHANGED
|
@@ -10,6 +10,7 @@ import { Canvas, type Device } from "./canvas/canvas";
|
|
|
10
10
|
import { EditorContext, EditorUi, useEditor, useEditorState, useUiTick, type EditorContextValue } from "./context";
|
|
11
11
|
import type { EditorHost } from "./core/host";
|
|
12
12
|
import { InserterPanel, InserterPopover } from "./ui/inserter";
|
|
13
|
+
import { AiWrite } from "./ui/ai";
|
|
13
14
|
import { labelsV2, type V2Labels } from "./labels";
|
|
14
15
|
import { localesVersion, onLocalesChange } from "../i18n";
|
|
15
16
|
import { blocksFromDoc, docFromBlocks, type BNode } from "./core/model";
|
|
@@ -292,6 +293,7 @@ export function EditorOverlays() {
|
|
|
292
293
|
<>
|
|
293
294
|
<BlockToolbar />
|
|
294
295
|
<InserterPopover />
|
|
296
|
+
<AiWrite />
|
|
295
297
|
<DropIndicator />
|
|
296
298
|
<LiveRegion />
|
|
297
299
|
</>
|
package/src/v2/ui/ai.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Sparkles } from "lucide-react";
|
|
2
|
-
import { useState } from "react";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
3
|
import { useEditor } from "../context";
|
|
4
4
|
import { inlineText, makeBlock, type BNode } from "../core/model";
|
|
5
5
|
import { Modal } from "./options";
|
|
6
|
-
import { Dropdown, MenuItem } from "./toolbar";
|
|
6
|
+
import { Dropdown, MenuItem, ToolButton } from "./toolbar";
|
|
7
7
|
|
|
8
8
|
type Job = { task: string; label: string; language?: string; instruction?: string };
|
|
9
9
|
|
|
@@ -45,7 +45,7 @@ export function AiTools({ block }: { block: BNode }) {
|
|
|
45
45
|
];
|
|
46
46
|
return (
|
|
47
47
|
<>
|
|
48
|
-
<Dropdown label={labels.ai} trigger={<Sparkles className="ecx-icon" />}>
|
|
48
|
+
<Dropdown label={labels.ai} trigger={<span className="ecx-tool-text"><Sparkles className="ecx-icon" />AI</span>}>
|
|
49
49
|
{(close) => <>
|
|
50
50
|
{items.map((j) => <MenuItem key={j.label} label={j.label} onClick={() => { close(); void run(j); }} />)}
|
|
51
51
|
<MenuItem label={labels.aiCustom} onClick={() => { close(); ask(); }} />
|
|
@@ -70,3 +70,65 @@ export function AiTools({ block }: { block: BNode }) {
|
|
|
70
70
|
</>
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
|
+
|
|
74
|
+
/** Khối Ảnh: nút "Tạo mô tả (alt) bằng AI" trên thanh công cụ (ảnh phải chọn từ thư viện media để biết mediaId). */
|
|
75
|
+
export function AiAltButton({ attrs, setAttrs }: { attrs: Record<string, unknown>; setAttrs(a: Record<string, unknown>): void }) {
|
|
76
|
+
const { host, labels } = useEditor();
|
|
77
|
+
const [busy, setBusy] = useState(false);
|
|
78
|
+
if (!host.ai?.altText) return null;
|
|
79
|
+
const id = Number(attrs.mediaId);
|
|
80
|
+
const run = async () => {
|
|
81
|
+
if (!Number.isFinite(id) || id <= 0) { window.alert(labels.aiAltNoMedia); return; }
|
|
82
|
+
setBusy(true);
|
|
83
|
+
try { setAttrs({ alt: (await host.ai!.altText!(id, labels.lang === "vi" ? "Vietnamese" : "English")).trim() }); }
|
|
84
|
+
catch (e) { window.alert((e as Error).message); }
|
|
85
|
+
finally { setBusy(false); }
|
|
86
|
+
};
|
|
87
|
+
return <ToolButton label={labels.aiAlt} onClick={() => void run()} disabled={busy} data-ai-alt><Sparkles className="ecx-icon" /><span className="ecx-tool-text">Alt</span></ToolButton>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Lệnh /ai: hộp "Viết bằng AI" — gõ yêu cầu, xem kết quả, rồi chèn (thay khối chứa "/ai" nếu gọi từ lệnh gạch chéo).
|
|
92
|
+
* Một bước hoàn tác; không tự chèn khi chưa bấm.
|
|
93
|
+
*/
|
|
94
|
+
export function AiWrite() {
|
|
95
|
+
const { host, labels, store, ui } = useEditor();
|
|
96
|
+
const [at, setAt] = useState<{ blockId?: string; docId: string; parentId: string | null; index: number } | null>(null);
|
|
97
|
+
const [prompt, setPrompt] = useState("");
|
|
98
|
+
const [state, setState] = useState<{ loading: boolean; text?: string; error?: string }>({ loading: false });
|
|
99
|
+
useEffect(() => { ui.openAiWrite = (a) => { setAt(a); setPrompt(""); setState({ loading: false }); }; return () => { ui.openAiWrite = null; }; }, [ui]);
|
|
100
|
+
if (!at || !host.ai) return null;
|
|
101
|
+
const run = async () => {
|
|
102
|
+
if (!prompt.trim()) return;
|
|
103
|
+
setState({ loading: true });
|
|
104
|
+
try { setState({ loading: false, text: await host.ai!.run("write", prompt.trim(), {}) }); }
|
|
105
|
+
catch (e) { setState({ loading: false, error: (e as Error).message }); }
|
|
106
|
+
};
|
|
107
|
+
const paragraphs = (state.text ?? "").split(/\n{2,}/).map((p) => p.trim()).filter(Boolean);
|
|
108
|
+
const insert = () => {
|
|
109
|
+
if (!paragraphs.length) return;
|
|
110
|
+
const nodes = paragraphs.map((p) => makeBlock("paragraph", {}, p));
|
|
111
|
+
store.batch(() => {
|
|
112
|
+
if (at.blockId && store.block(at.blockId)) store.replace(at.blockId, nodes);
|
|
113
|
+
else store.insert(at.docId, at.parentId, at.index, nodes);
|
|
114
|
+
});
|
|
115
|
+
setAt(null);
|
|
116
|
+
};
|
|
117
|
+
return (
|
|
118
|
+
<Modal title={labels.aiWrite} onClose={() => setAt(null)} wide>
|
|
119
|
+
<div className="ecx-ai-body" data-ecx-ai-write>
|
|
120
|
+
<textarea className="ecx-input" rows={3} value={prompt} onChange={(e) => setPrompt(e.target.value)} placeholder={labels.aiWritePrompt} data-ai-write-prompt
|
|
121
|
+
onKeyDown={(e) => { if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) { e.preventDefault(); void run(); } }} />
|
|
122
|
+
{state.loading && <p className="ecx-ai-wait" role="status">{labels.aiWorking}</p>}
|
|
123
|
+
{state.error && <p className="ecx-ai-error" role="alert">{state.error}</p>}
|
|
124
|
+
{state.text && <div className="ecx-ai-text" data-ecx-ai-result>{paragraphs.map((p, i) => <p key={i}>{p}</p>)}</div>}
|
|
125
|
+
<p className="ecx-ai-note">{labels.aiNote}</p>
|
|
126
|
+
<div className="ecx-popover-actions">
|
|
127
|
+
<button type="button" className="ecx-btn" onClick={() => setAt(null)}>{labels.cancel}</button>
|
|
128
|
+
<button type="button" className="ecx-btn" onClick={() => void run()} disabled={state.loading || !prompt.trim()} data-ai-write-run>{state.text ? labels.aiRetry : labels.aiWriteRun}</button>
|
|
129
|
+
{state.text && <button type="button" className="ecx-btn ecx-btn-primary" onClick={insert} data-ai-write-insert>{labels.aiInsert}</button>}
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
</Modal>
|
|
133
|
+
);
|
|
134
|
+
}
|
package/src/v2/ui/inserter.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { leavesItem } from "../core/structure";
|
|
2
2
|
import { blockDescription } from "./block-descriptions";
|
|
3
|
-
import { Blocks } from "lucide-react";
|
|
3
|
+
import { Blocks, Sparkles } from "lucide-react";
|
|
4
4
|
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ComponentType } from "react";
|
|
5
5
|
import { norm } from "../../shared/util";
|
|
6
6
|
import { useEditor, useUiTick, type InserterRequest } from "../context";
|
|
7
|
-
import { cloneBlock, inlineLength, type BNode } from "../core/model";
|
|
7
|
+
import { cloneBlock, inlineLength, makeBlock, type BNode } from "../core/model";
|
|
8
8
|
import type { BlockType } from "../core/registry";
|
|
9
9
|
import { canContain } from "../core/structure";
|
|
10
10
|
import { startDragNew } from "../canvas/dnd";
|
|
@@ -23,11 +23,13 @@ export interface InsertOption {
|
|
|
23
23
|
/** Loại khối gốc (kiểm tra chỗ đặt được). */
|
|
24
24
|
type: string;
|
|
25
25
|
create(): BNode;
|
|
26
|
+
/** Lệnh riêng thay vì chèn khối (vd "ai-write" mở hộp Viết bằng AI). */
|
|
27
|
+
action?: "ai-write";
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
/** Các lựa chọn chèn: khối + biến thể có hàm tạo riêng (cột 30/70…). */
|
|
29
31
|
export function useInsertOptions(): InsertOption[] {
|
|
30
|
-
const { registry, prefs, host } = useEditor();
|
|
32
|
+
const { registry, prefs, host, labels } = useEditor();
|
|
31
33
|
const hidden = usePrefs(prefs).hiddenBlockTypes;
|
|
32
34
|
const [version, setVersion] = useState(registry.getVersion());
|
|
33
35
|
useEffect(() => registry.subscribe(() => setVersion(registry.getVersion())), [registry]);
|
|
@@ -43,8 +45,9 @@ export function useInsertOptions(): InsertOption[] {
|
|
|
43
45
|
out.push({ key: `${t.name}/${v.name}`, title: v.standalone ? v.title : `${t.title} ${v.title}`, description: v.description, icon: v.icon ?? t.icon, keywords: `${t.keywords ?? ""} ${v.keywords ?? ""}`, category: t.category ?? "other", type: t.name, create: v.create });
|
|
44
46
|
}
|
|
45
47
|
}
|
|
48
|
+
if (host.ai) out.push({ key: "ai-write", title: labels.aiWrite, description: labels.aiWriteHint, icon: Sparkles, keywords: "ai viet write gpt claude tro ly", category: "text", type: "paragraph", create: () => makeBlock("paragraph"), action: "ai-write" });
|
|
46
49
|
return out;
|
|
47
|
-
}, [registry, version, hidden, host.scope]);
|
|
50
|
+
}, [registry, version, hidden, host.scope, host.ai, labels]);
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
/** Lọc + xếp hạng: tên trùng hẳn > tên bắt đầu bằng chữ gõ > một từ trong tên > từ khoá; tiếng Việt không dấu. */
|
|
@@ -67,6 +70,11 @@ export function rankOptions(list: InsertOption[], query: string): InsertOption[]
|
|
|
67
70
|
/** Chèn một lựa chọn theo yêu cầu (slash: thay đoạn "/…"; nút "+": vào vị trí). */
|
|
68
71
|
export function applyInsert(ctx: ReturnType<typeof useEditor>, req: InserterRequest, opt: InsertOption) {
|
|
69
72
|
const { store, ui, prefs } = ctx;
|
|
73
|
+
if (opt.action === "ai-write") {
|
|
74
|
+
ui.openInserter(null);
|
|
75
|
+
ui.openAiWrite?.({ blockId: req.mode === "slash" ? req.blockId : undefined, docId: req.docId, parentId: req.parentId ?? null, index: req.index ?? 0 });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
70
78
|
const node = opt.create();
|
|
71
79
|
prefs.countInsert(opt.type);
|
|
72
80
|
if (req.mode === "slash" && req.blockId) {
|
package/src/v2/ui/options.tsx
CHANGED
|
@@ -78,13 +78,16 @@ export function MoreMenu({ extra }: { extra?: (close: () => void) => ReactNode }
|
|
|
78
78
|
export function Modal({ title, onClose, children, wide }: { title: string; onClose(): void; children: ReactNode; wide?: boolean }) {
|
|
79
79
|
const ref = useRef<HTMLDivElement>(null);
|
|
80
80
|
const { labels } = useEditor();
|
|
81
|
+
// onClose qua ref: người gọi hay truyền hàm mới mỗi lần vẽ — chạy lại effect mỗi phím gõ sẽ trả focus về chỗ cũ (ô nhập trong hộp mất focus)
|
|
82
|
+
const closeRef = useRef(onClose);
|
|
83
|
+
closeRef.current = onClose;
|
|
81
84
|
useEffect(() => {
|
|
82
85
|
const prev = document.activeElement as HTMLElement | null;
|
|
83
|
-
ref.current?.querySelector<HTMLElement>("
|
|
84
|
-
const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") { e.preventDefault(); e.stopPropagation();
|
|
86
|
+
ref.current?.querySelector<HTMLElement>("textarea, input, button, [tabindex]")?.focus();
|
|
87
|
+
const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); closeRef.current(); } };
|
|
85
88
|
document.addEventListener("keydown", onKey, true);
|
|
86
89
|
return () => { document.removeEventListener("keydown", onKey, true); prev?.focus?.(); };
|
|
87
|
-
}, [
|
|
90
|
+
}, []);
|
|
88
91
|
return (
|
|
89
92
|
<div className="ecx-modal-backdrop" onMouseDown={(e) => { if (e.target === e.currentTarget) onClose(); }}>
|
|
90
93
|
<div ref={ref} className={cx("ecx-modal", wide && "is-wide")} role="dialog" aria-modal="true" aria-label={title}>
|