@ecomcx/ecomweb-editor 1.17.0 → 1.17.1
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/Editor.tsx +8 -7
- package/src/boundary.tsx +17 -0
- package/src/handle.tsx +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecomcx/ecomweb-editor",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.1",
|
|
4
4
|
"description": "Trình soạn thảo nội dung dạng khối (TipTap) của CMS — dùng độc lập trong mọi dự án React: ảnh responsive kéo đổi kích thước, gallery, video, bảng, slash menu, mở rộng bằng plugin.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/src/Editor.tsx
CHANGED
|
@@ -25,6 +25,7 @@ import type { PatternHost } from "./synced";
|
|
|
25
25
|
import { BlockHandle, BlockKeys } from "./handle";
|
|
26
26
|
import { BlockSettingsBar, layoutItems } from "./layoutUi";
|
|
27
27
|
import { BlockToolbar } from "./toolbar";
|
|
28
|
+
import { OverlayBoundary } from "./boundary";
|
|
28
29
|
import { CanvasHandles } from "./handles";
|
|
29
30
|
import { documentStyleCss, presetsCss } from "./styleattr";
|
|
30
31
|
import type { StylePresets } from "@ecomcx/ecomweb-content";
|
|
@@ -409,16 +410,16 @@ export function Editor({ initial, onChange, media, labels, extensions: localPack
|
|
|
409
410
|
return (
|
|
410
411
|
<div className={cx("cms-editor", className)}>
|
|
411
412
|
{editor && <div className={cx("cms-ed-toolbar", toolbarClassName)}><Toolbar editor={editor} t={t} requestMedia={requestMedia} items={items} /></div>}
|
|
412
|
-
{editor && <SelectionMenu editor={editor} t={t}
|
|
413
|
+
{editor && <OverlayBoundary editor={editor} name="SelectionMenu"><SelectionMenu editor={editor} t={t} /></OverlayBoundary>}
|
|
413
414
|
{editor && <DocumentStyles editor={editor} presets={presets} />}
|
|
414
415
|
<EditorContent editor={editor} />
|
|
415
416
|
<SlashMenu store={slash} t={t} />
|
|
416
|
-
{editor && <BlockHandle editor={editor} t={t} menuRequest={menuRequest}
|
|
417
|
-
{editor && <AskPopover store={asker} editor={editor} t={t}
|
|
418
|
-
{editor && <BlockSettingsBar editor={editor} t={t}
|
|
419
|
-
{editor && <BlockToolbar editor={editor} t={t} media={media} requestMedia={requestMedia}
|
|
420
|
-
{editor && <CanvasHandles editor={editor} t={t}
|
|
421
|
-
{editor && <Stats editor={editor} t={t}
|
|
417
|
+
{editor && <OverlayBoundary editor={editor} name="BlockHandle"><BlockHandle editor={editor} t={t} menuRequest={menuRequest} /></OverlayBoundary>}
|
|
418
|
+
{editor && <OverlayBoundary editor={editor} name="AskPopover"><AskPopover store={asker} editor={editor} t={t} /></OverlayBoundary>}
|
|
419
|
+
{editor && <OverlayBoundary editor={editor} name="BlockSettingsBar"><BlockSettingsBar editor={editor} t={t} /></OverlayBoundary>}
|
|
420
|
+
{editor && <OverlayBoundary editor={editor} name="BlockToolbar"><BlockToolbar editor={editor} t={t} media={media} requestMedia={requestMedia} /></OverlayBoundary>}
|
|
421
|
+
{editor && <OverlayBoundary editor={editor} name="CanvasHandles"><CanvasHandles editor={editor} t={t} /></OverlayBoundary>}
|
|
422
|
+
{editor && <OverlayBoundary editor={editor} name="Stats"><Stats editor={editor} t={t} /></OverlayBoundary>}
|
|
422
423
|
</div>
|
|
423
424
|
);
|
|
424
425
|
}
|
package/src/boundary.tsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Component, type ReactNode } from "react";
|
|
2
|
+
import type { Editor as TiptapEditor } from "@tiptap/react";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Bọc phần nổi của trình soạn (tay kéo, thanh khối, menu chọn chữ…): lỗi khi vẽ chỉ ẩn phần đó, không làm sập trình soạn
|
|
6
|
+
* hay cả trang chứa nó; giao dịch kế tiếp của trình soạn thì vẽ lại.
|
|
7
|
+
*/
|
|
8
|
+
export class OverlayBoundary extends Component<{ editor: TiptapEditor; name: string; children: ReactNode }, { failed: boolean }> {
|
|
9
|
+
state = { failed: false };
|
|
10
|
+
static getDerivedStateFromError() { return { failed: true }; }
|
|
11
|
+
componentDidCatch(error: Error) {
|
|
12
|
+
console.warn(`[editor] ${this.props.name}:`, error);
|
|
13
|
+
const reset = () => { this.props.editor.off("transaction", reset); this.setState({ failed: false }); };
|
|
14
|
+
this.props.editor.on("transaction", reset);
|
|
15
|
+
}
|
|
16
|
+
render() { return this.state.failed ? null : this.props.children; }
|
|
17
|
+
}
|
package/src/handle.tsx
CHANGED
|
@@ -85,7 +85,7 @@ export function BlockHandle({ editor, t, menuRequest }: { editor: TiptapEditor;
|
|
|
85
85
|
if (menuOpen.current) return;
|
|
86
86
|
let block = hover.current;
|
|
87
87
|
// Khối đang trỏ chuột có thể đã đổi chỗ / bị xoá sau giao dịch → kiểm lại
|
|
88
|
-
if (block) { const n = editor.state.doc.nodeAt(block.pos); block = n ? blockFromPos(editor.state.doc, block.pos) : null; }
|
|
88
|
+
if (block) { const n = block.pos < editor.state.doc.content.size ? editor.state.doc.nodeAt(block.pos) : null; block = n ? blockFromPos(editor.state.doc, block.pos) : null; }
|
|
89
89
|
if (!block && (editor.isFocused || overHandle.current)) block = currentBlock(editor.state);
|
|
90
90
|
const dom = block ? (view.nodeDOM(block.pos) as HTMLElement | null) : null;
|
|
91
91
|
setShown(block && dom?.getBoundingClientRect ? { block, rect: dom.getBoundingClientRect() } : null);
|
|
@@ -131,6 +131,8 @@ export function BlockHandle({ editor, t, menuRequest }: { editor: TiptapEditor;
|
|
|
131
131
|
|
|
132
132
|
if (!shown) return null;
|
|
133
133
|
const { block, rect } = shown;
|
|
134
|
+
// Khối đã bị xoá / tài liệu ngắn lại sau giao dịch (vd chọn tất cả rồi xoá) mà chưa kịp tính lại vị trí → chưa vẽ
|
|
135
|
+
if (block.pos >= editor.state.doc.content.size || editor.state.doc.nodeAt(block.pos) !== block.node) return null;
|
|
134
136
|
const $p = editor.state.doc.resolve(Math.min(block.pos, editor.state.doc.content.size));
|
|
135
137
|
const index = $p.index(), count = $p.parent.childCount;
|
|
136
138
|
const hasParent = !!parentBlock(editor.state.doc, block);
|