@blocklet/editor 2.5.59 → 2.5.61
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/lib/ext/PostLinkEmbedPlugin/PostLinkNode.d.ts +1 -0
- package/lib/ext/PostLinkEmbedPlugin/PostLinkNode.js +4 -1
- package/lib/ext/PostLinkEmbedPlugin/fixInvalidPostLinkNodes.d.ts +1 -0
- package/lib/ext/PostLinkEmbedPlugin/fixInvalidPostLinkNodes.js +15 -0
- package/lib/main/viewer/viewer.js +2 -0
- package/package.json +2 -2
|
@@ -25,6 +25,7 @@ export declare class PostLinkNode extends DecoratorNode<JSX.Element> {
|
|
|
25
25
|
exportJSON(): SerializedPostLinkNode;
|
|
26
26
|
createDOM(config: EditorConfig): HTMLElement;
|
|
27
27
|
updateDOM(): false;
|
|
28
|
+
getPostInfo(): PostInfo;
|
|
28
29
|
decorate(): JSX.Element;
|
|
29
30
|
}
|
|
30
31
|
export declare function $createPostLinkNode(postInfo: PostInfo): PostLinkNode;
|
|
@@ -69,7 +69,7 @@ function PostLinkComponent(postInfo) {
|
|
|
69
69
|
}, title: postInfo.title ?? link, children: postInfo.title ?? link }), !!postInfo.external && (_jsx(Box, { component: "i", className: "iconify", "data-icon": "majesticons:external-link-line", sx: { flex: '0 0 auto', width: 16, height: 16, ml: 0.5, color: 'grey.600' } }))] }));
|
|
70
70
|
}
|
|
71
71
|
function convertPostElement(domNode) {
|
|
72
|
-
if (domNode instanceof HTMLElement) {
|
|
72
|
+
if (domNode instanceof HTMLElement && domNode.getAttribute('data-lexical-post-link-json')) {
|
|
73
73
|
const postInfo = domNode.getAttribute('data-lexical-post-link-json');
|
|
74
74
|
const node = $createPostLinkNode(safeParseJSON(postInfo, {}));
|
|
75
75
|
return { node };
|
|
@@ -125,6 +125,9 @@ export class PostLinkNode extends DecoratorNode {
|
|
|
125
125
|
updateDOM() {
|
|
126
126
|
return false;
|
|
127
127
|
}
|
|
128
|
+
getPostInfo() {
|
|
129
|
+
return this.__postInfo;
|
|
130
|
+
}
|
|
128
131
|
decorate() {
|
|
129
132
|
return (_jsx(Suspense, { fallback: null, children: _jsx(PostLinkComponent, { ...this.__postInfo }) }));
|
|
130
133
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useFixInvalidPostLinkNodes(): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { PostLinkNode } from './PostLinkNode';
|
|
4
|
+
// 移除 postInfo 为空的无效 PostLinkNode (可能是复制粘贴产生的)
|
|
5
|
+
export function useFixInvalidPostLinkNodes() {
|
|
6
|
+
const [editor] = useLexicalComposerContext();
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
function transform(node) {
|
|
9
|
+
if (!node.getPostInfo()) {
|
|
10
|
+
node.remove();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return editor.registerNodeTransform(PostLinkNode, transform);
|
|
14
|
+
}, [editor]);
|
|
15
|
+
}
|
|
@@ -23,7 +23,9 @@ import { StyledEditorContent } from '../styled-editor-content';
|
|
|
23
23
|
import CheckboxPlugin from '../../ext/CheckboxPlugin';
|
|
24
24
|
import { VideoPathFixerPlugin } from '../../ext/VideoPathFixerPlugin';
|
|
25
25
|
import ImagePathFixerPlugin from '../../ext/ImagePathFixerPlugin';
|
|
26
|
+
import { useFixInvalidPostLinkNodes } from '../../ext/PostLinkEmbedPlugin/fixInvalidPostLinkNodes';
|
|
26
27
|
export function EditorViewer({ children, prepend, onChange, editorRef, onReady, enableHeadingsIdPlugin, onCheckboxChange, }) {
|
|
27
28
|
const hasNodes = useHasNodes();
|
|
29
|
+
useFixInvalidPostLinkNodes();
|
|
28
30
|
return (_jsxs(_Fragment, { children: [prepend, _jsx(VideoPathFixerPlugin, {}), _jsx(ImagePathFixerPlugin, {}), _jsx(StyledEditorContent, { className: "be-content", children: _jsx(RichTextPlugin, { contentEditable: _jsx(ContentEditable, { className: cx('be-editable', 'notranslate') }), ErrorBoundary: LexicalErrorBoundary }) }), _jsx(MarkdownShortcutPlugin, {}), hasNodes('code', 'code-highlight') && _jsx(CodeHighlightPlugin, {}), hasNodes('list', 'listitem') && _jsx(ListPlugin, {}), hasNodes('list', 'listitem') && _jsx(CheckListPlugin, {}), hasNodes('link') && _jsx(LinkPlugin, {}), hasNodes('link') && _jsx(ClickableLinkPlugin, {}), _jsx(TabFocusPlugin, {}), hasNodes('table', 'tablerow', 'tablecell') && (_jsx(TablePlugin, { hasCellMerge: true, hasCellBackgroundColor: true, hasHorizontalScroll: true })), hasNodes('collapsible-container', 'collapsible-content', 'collapsible-title') && _jsx(CollapsiblePlugin, {}), onChange && _jsx(OnChangePlugin, { onChange: onChange }), enableHeadingsIdPlugin && _jsx(HeadingsIdPlugin, {}), _jsx(EditorHolderPlugin, {}), editorRef && _jsx(EditorRefPlugin, { editorRef: editorRef }), onReady && _jsx(EditorReadyPlugin, { onReady: onReady }), _jsx(CheckboxPlugin, { send: onCheckboxChange }), children] }));
|
|
29
31
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/editor",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.61",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"ufo": "^1.5.4",
|
|
74
74
|
"url-join": "^4.0.1",
|
|
75
75
|
"zustand": "^4.5.5",
|
|
76
|
-
"@blocklet/pdf": "2.5.
|
|
76
|
+
"@blocklet/pdf": "2.5.61"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@babel/core": "^7.25.2",
|