= (props) => {
editor.registerPlugin(plugin);
return () => editor.unregisterPlugin(pluginKey);
- }, [props.editor, element]);
+ // TODO: 检验是否应该是 props.editor
+ }, [props, element]);
return (
diff --git a/packages/client/src/tiptap/wrappers/attachment/index.tsx b/packages/client/src/tiptap/wrappers/attachment/index.tsx
index 43940fa6..390c5abe 100644
--- a/packages/client/src/tiptap/wrappers/attachment/index.tsx
+++ b/packages/client/src/tiptap/wrappers/attachment/index.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useRef } from 'react';
+import { useCallback, useEffect, useRef } from 'react';
import cls from 'classnames';
import { NodeViewWrapper } from '@tiptap/react';
import { Button, Typography, Spin, Collapsible, Space } from '@douyinfe/semi-ui';
@@ -20,36 +20,39 @@ export const AttachmentWrapper = ({ editor, node, updateAttributes }) => {
const [loading, toggleLoading] = useToggle(false);
const [visible, toggleVisible] = useToggle(false);
- const selectFile = () => {
+ const selectFile = useCallback(() => {
if (!isEditable || url) return;
isEditable && $upload.current.click();
- };
+ }, [isEditable, url]);
- const handleFile = async (e) => {
- const file = e.target.files && e.target.files[0];
- const fileInfo = {
- fileName: extractFilename(file.name),
- fileSize: file.size,
- fileType: file.type,
- fileExt: extractFileExtension(file.name),
- };
- toggleLoading(true);
- try {
- const url = await uploadFile(file);
- updateAttributes({ ...fileInfo, url });
- toggleLoading(false);
- } catch (error) {
- updateAttributes({ error: '文件上传失败:' + (error && error.message) || '未知错误' });
- toggleLoading(false);
- }
- };
+ const handleFile = useCallback(
+ async (e) => {
+ const file = e.target.files && e.target.files[0];
+ const fileInfo = {
+ fileName: extractFilename(file.name),
+ fileSize: file.size,
+ fileType: file.type,
+ fileExt: extractFileExtension(file.name),
+ };
+ toggleLoading(true);
+ try {
+ const url = await uploadFile(file);
+ updateAttributes({ ...fileInfo, url });
+ toggleLoading(false);
+ } catch (error) {
+ updateAttributes({ error: '文件上传失败:' + (error && error.message) || '未知错误' });
+ toggleLoading(false);
+ }
+ },
+ [toggleLoading, updateAttributes]
+ );
useEffect(() => {
if (!url && !hasTrigger) {
selectFile();
updateAttributes({ hasTrigger: true });
}
- }, [url, hasTrigger]);
+ }, [url, hasTrigger, selectFile, updateAttributes]);
const content = (() => {
if (isEditable && !url) {
diff --git a/packages/client/src/tiptap/wrappers/callout/index.tsx b/packages/client/src/tiptap/wrappers/callout/index.tsx
index 369190c1..cd3661e7 100644
--- a/packages/client/src/tiptap/wrappers/callout/index.tsx
+++ b/packages/client/src/tiptap/wrappers/callout/index.tsx
@@ -8,9 +8,12 @@ export const CalloutWrapper = ({ editor, node, updateAttributes }) => {
const { isEditable } = editor;
const { emoji, textColor, borderColor, backgroundColor } = node.attrs;
- const onSelectEmoji = useCallback((emoji) => {
- updateAttributes({ emoji });
- }, []);
+ const onSelectEmoji = useCallback(
+ (emoji) => {
+ updateAttributes({ emoji });
+ },
+ [updateAttributes]
+ );
return (
diff --git a/packages/client/src/tiptap/wrappers/document-children/index.tsx b/packages/client/src/tiptap/wrappers/document-children/index.tsx
index 5da66111..b346e410 100644
--- a/packages/client/src/tiptap/wrappers/document-children/index.tsx
+++ b/packages/client/src/tiptap/wrappers/document-children/index.tsx
@@ -17,7 +17,7 @@ export const DocumentChildrenWrapper = ({ editor, node, updateAttributes }) => {
const { pathname, query } = useRouter();
let { wikiId, documentId } = node.attrs;
if (!wikiId) {
- query?.wikiId;
+ wikiId = query?.wikiId;
}
if (!documentId) {
documentId = query?.documentId;
@@ -31,7 +31,7 @@ export const DocumentChildrenWrapper = ({ editor, node, updateAttributes }) => {
if (attrs.wikiId !== wikiId || attrs.documentId !== documentId) {
updateAttributes({ wikiId, documentId });
}
- }, [node.attrs, wikiId, documentId]);
+ }, [node.attrs, wikiId, documentId, updateAttributes]);
return (
);
- }, [wikiId, documentId]);
+ }, [wikiId, documentId, isEditable, isShare, title]);
return (
diff --git a/packages/client/src/tiptap/wrappers/emoji-list/index.tsx b/packages/client/src/tiptap/wrappers/emoji-list/index.tsx
index 3ad829da..052f1790 100644
--- a/packages/client/src/tiptap/wrappers/emoji-list/index.tsx
+++ b/packages/client/src/tiptap/wrappers/emoji-list/index.tsx
@@ -81,3 +81,5 @@ export const EmojiList: React.FC = forwardRef((props, ref) => {
);
});
+
+EmojiList.displayName = 'EmojiList';
diff --git a/packages/client/src/tiptap/wrappers/iframe/index.tsx b/packages/client/src/tiptap/wrappers/iframe/index.tsx
index 088513a2..5164c790 100644
--- a/packages/client/src/tiptap/wrappers/iframe/index.tsx
+++ b/packages/client/src/tiptap/wrappers/iframe/index.tsx
@@ -13,9 +13,12 @@ export const IframeWrapper = ({ editor, node, updateAttributes }) => {
const { url, width, height } = node.attrs;
const { width: maxWidth } = getEditorContainerDOMSize(editor);
- const onResize = useCallback((size) => {
- updateAttributes({ width: size.width, height: size.height });
- }, []);
+ const onResize = useCallback(
+ (size) => {
+ updateAttributes({ width: size.width, height: size.height });
+ },
+ [updateAttributes]
+ );
return (
diff --git a/packages/client/src/tiptap/wrappers/image/index.tsx b/packages/client/src/tiptap/wrappers/image/index.tsx
index cf201387..ed21fc1d 100644
--- a/packages/client/src/tiptap/wrappers/image/index.tsx
+++ b/packages/client/src/tiptap/wrappers/image/index.tsx
@@ -22,44 +22,50 @@ export const ImageWrapper = ({ editor, node, updateAttributes }) => {
const $upload = useRef();
const [loading, toggleLoading] = useToggle(false);
- const onResize = useCallback((size) => {
- updateAttributes({ height: size.height, width: size.width });
- }, []);
+ const onResize = useCallback(
+ (size) => {
+ updateAttributes({ height: size.height, width: size.width });
+ },
+ [updateAttributes]
+ );
const selectFile = useCallback(() => {
if (!isEditable || error || src) return;
isEditable && $upload.current.click();
}, [isEditable, error, src]);
- const handleFile = useCallback(async (e) => {
- const file = e.target.files && e.target.files[0];
+ const handleFile = useCallback(
+ async (e) => {
+ const file = e.target.files && e.target.files[0];
- const fileInfo = {
- fileName: extractFilename(file.name),
- fileSize: file.size,
- fileType: file.type,
- fileExt: extractFileExtension(file.name),
- };
+ const fileInfo = {
+ fileName: extractFilename(file.name),
+ fileSize: file.size,
+ fileType: file.type,
+ fileExt: extractFileExtension(file.name),
+ };
- toggleLoading(true);
+ toggleLoading(true);
- try {
- const src = await uploadFile(file);
- const size = await getImageWidthHeight(file);
- updateAttributes({ ...fileInfo, ...size, src });
- toggleLoading(false);
- } catch (error) {
- updateAttributes({ error: '图片上传失败:' + (error && error.message) || '未知错误' });
- toggleLoading(false);
- }
- }, []);
+ try {
+ const src = await uploadFile(file);
+ const size = await getImageWidthHeight(file);
+ updateAttributes({ ...fileInfo, ...size, src });
+ toggleLoading(false);
+ } catch (error) {
+ updateAttributes({ error: '图片上传失败:' + (error && error.message) || '未知错误' });
+ toggleLoading(false);
+ }
+ },
+ [updateAttributes, toggleLoading]
+ );
useEffect(() => {
if (!src && !hasTrigger) {
selectFile();
updateAttributes({ hasTrigger: true });
}
- }, [src, hasTrigger]);
+ }, [src, hasTrigger, selectFile, updateAttributes]);
return (
diff --git a/packages/client/src/tiptap/wrappers/katex/index.tsx b/packages/client/src/tiptap/wrappers/katex/index.tsx
index 5bf64ff9..1fd270ea 100644
--- a/packages/client/src/tiptap/wrappers/katex/index.tsx
+++ b/packages/client/src/tiptap/wrappers/katex/index.tsx
@@ -32,7 +32,7 @@ export const KatexWrapper = ({ editor, node, updateAttributes }) => {
) : (
点击输入公式
),
- [text]
+ [text, formatText]
);
const onVisibleChange = useCallback(
@@ -42,7 +42,7 @@ export const KatexWrapper = ({ editor, node, updateAttributes }) => {
updateAttributes({ defaultShowPicker: false });
}
},
- [defaultShowPicker, updateAttributes, createUser, user]
+ [defaultShowPicker, toggleVisible, updateAttributes, createUser, user]
);
useEffect(() => {
@@ -50,7 +50,7 @@ export const KatexWrapper = ({ editor, node, updateAttributes }) => {
toggleVisible(true);
setTimeout(() => ref.current?.focus(), 100);
}
- }, [defaultShowPicker, createUser, user]);
+ }, [defaultShowPicker, toggleVisible, createUser, user]);
return (
diff --git a/packages/client/src/tiptap/wrappers/mention-list/index.tsx b/packages/client/src/tiptap/wrappers/mention-list/index.tsx
index 4913951e..eb3109f7 100644
--- a/packages/client/src/tiptap/wrappers/mention-list/index.tsx
+++ b/packages/client/src/tiptap/wrappers/mention-list/index.tsx
@@ -81,3 +81,5 @@ export const MentionList: React.FC = forwardRef((props, ref) => {
);
});
+
+MentionList.displayName = 'MentionList';
diff --git a/packages/client/src/tiptap/wrappers/menu-list/index.tsx b/packages/client/src/tiptap/wrappers/menu-list/index.tsx
index 45717fdb..905b8255 100644
--- a/packages/client/src/tiptap/wrappers/menu-list/index.tsx
+++ b/packages/client/src/tiptap/wrappers/menu-list/index.tsx
@@ -87,3 +87,5 @@ export const MenuList: React.FC = forwardRef((props, ref) => {
);
});
+
+MenuList.displayName = 'MenuList';
diff --git a/packages/client/src/tiptap/wrappers/mind/index.tsx b/packages/client/src/tiptap/wrappers/mind/index.tsx
index 6557dd32..1eebd3a6 100644
--- a/packages/client/src/tiptap/wrappers/mind/index.tsx
+++ b/packages/client/src/tiptap/wrappers/mind/index.tsx
@@ -47,7 +47,7 @@ export const MindWrapper = ({ editor, node, updateAttributes }) => {
style={{ ...INHERIT_SIZE_STYLE, overflow: 'hidden' }}
>
);
- }, [loading, error, width, height]);
+ }, [loading, error]);
const onResize = useCallback(
(size) => {
@@ -69,11 +69,12 @@ export const MindWrapper = ({ editor, node, updateAttributes }) => {
.catch((e) => {
setError(e);
});
- }, []);
+ }, [toggleLoading]);
// 初始化渲染
useEffect(() => {
- if (loading || !$container.current) return;
+ const container = $container.current;
+ if (loading || !container) return;
const onChange = () => {
updateAttributes({ data: mind.getAllData() });
@@ -89,8 +90,8 @@ export const MindWrapper = ({ editor, node, updateAttributes }) => {
isEnter = false;
};
- $container.current.addEventListener('onmouseenter', onMouseEnter);
- $container.current.addEventListener('onMouseLeave', onMouseLeave);
+ container.addEventListener('onmouseenter', onMouseEnter);
+ container.addEventListener('onMouseLeave', onMouseLeave);
try {
mind = new window.MindElixir({
@@ -115,16 +116,18 @@ export const MindWrapper = ({ editor, node, updateAttributes }) => {
}
return () => {
- if ($container.current) {
- $container.current.removeEventListener('onmouseenter', onMouseEnter);
- $container.current.removeEventListener('onMouseLeave', onMouseLeave);
+ if (container) {
+ container.removeEventListener('onmouseenter', onMouseEnter);
+ container.removeEventListener('onMouseLeave', onMouseLeave);
}
if (mind) {
mind.destroy();
}
};
- }, [loading, editor, updateAttributes]);
+ // data 的更新交给下方 effect
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [loading, editor, updateAttributes, toggleLoading]);
useEffect(() => {
const mind = $mind.current;
diff --git a/packages/client/src/tiptap/wrappers/mind/mind-elixir/linkDiv.ts b/packages/client/src/tiptap/wrappers/mind/mind-elixir/linkDiv.ts
index 0021d7a7..30111db8 100644
--- a/packages/client/src/tiptap/wrappers/mind/mind-elixir/linkDiv.ts
+++ b/packages/client/src/tiptap/wrappers/mind/mind-elixir/linkDiv.ts
@@ -14,8 +14,8 @@ import { SIDE, GAP, TURNPOINT_R, PRIMARY_NODE_HORIZONTAL_GAP, PRIMARY_NODE_VERTI
* @param {object} primaryNode process the specific primary node only
*/
export default function linkDiv(primaryNode) {
- var primaryNodeHorizontalGap = this.primaryNodeHorizontalGap || PRIMARY_NODE_HORIZONTAL_GAP;
- var primaryNodeVerticalGap = this.primaryNodeVerticalGap || PRIMARY_NODE_VERTICAL_GAP;
+ const primaryNodeHorizontalGap = this.primaryNodeHorizontalGap || PRIMARY_NODE_HORIZONTAL_GAP;
+ const primaryNodeVerticalGap = this.primaryNodeVerticalGap || PRIMARY_NODE_VERTICAL_GAP;
console.time('linkDiv');
const root = this.root;
root.style.cssText = `top:${10000 - root.offsetHeight / 2}px;left:${10000 - root.offsetWidth / 2}px;`;
diff --git a/packages/client/src/tiptap/wrappers/mind/mind-elixir/plugin/nodeMenu.tsx b/packages/client/src/tiptap/wrappers/mind/mind-elixir/plugin/nodeMenu.tsx
index eb816f67..b432519e 100644
--- a/packages/client/src/tiptap/wrappers/mind/mind-elixir/plugin/nodeMenu.tsx
+++ b/packages/client/src/tiptap/wrappers/mind/mind-elixir/plugin/nodeMenu.tsx
@@ -86,6 +86,7 @@ const Toolbar = ({ mind, toggleBold, setFontColor, setBackgroundColor, setLink }
return () => {
mind.bus.removeListener('selectNode', listener);
};
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
diff --git a/packages/client/src/tiptap/wrappers/mind/mind-elixir/utils/dom.ts b/packages/client/src/tiptap/wrappers/mind/mind-elixir/utils/dom.ts
index 5be4e1d9..9cf555c3 100644
--- a/packages/client/src/tiptap/wrappers/mind/mind-elixir/utils/dom.ts
+++ b/packages/client/src/tiptap/wrappers/mind/mind-elixir/utils/dom.ts
@@ -137,6 +137,7 @@ export function createInputDiv(tpc: Topic) {
div.addEventListener('blur', () => {
if (!div) return; // 防止重复blur
const node = tpc.nodeObj;
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const topic = div.textContent!.trim();
if (topic === '') node.topic = origin;
else node.topic = topic;
diff --git a/packages/client/src/tiptap/wrappers/mind/mind-elixir/utils/index.ts b/packages/client/src/tiptap/wrappers/mind/mind-elixir/utils/index.ts
index 2968860f..30ed8006 100644
--- a/packages/client/src/tiptap/wrappers/mind/mind-elixir/utils/index.ts
+++ b/packages/client/src/tiptap/wrappers/mind/mind-elixir/utils/index.ts
@@ -51,11 +51,12 @@ export function refreshIds(data: NodeObj) {
}
export const throttle = (fn: (any) => void, wait: number) => {
- var pre = Date.now();
+ let pre = Date.now();
return function () {
- var context = this;
- var args = arguments;
- var now = Date.now();
+ const context = this;
+ // eslint-disable-next-line prefer-rest-params
+ const args = arguments;
+ const now = Date.now();
if (now - pre >= wait) {
fn.apply(context, args);
pre = Date.now();
@@ -78,7 +79,7 @@ export function getArrowPoints(p3x: number, p3y: number, p4x: number, p4y: numbe
}
const arrowLength = 20;
const arrowAngle = 30;
- var a1 = angle + arrowAngle;
+ const a1 = angle + arrowAngle;
const a2 = angle - arrowAngle;
return {
x1: p4x + Math.cos((Math.PI * a1) / 180) * arrowLength,
diff --git a/packages/client/src/tiptap/wrappers/mind/mind-elixir/utils/pubsub.ts b/packages/client/src/tiptap/wrappers/mind/mind-elixir/utils/pubsub.ts
index b50ccfd0..64a96dec 100644
--- a/packages/client/src/tiptap/wrappers/mind/mind-elixir/utils/pubsub.ts
+++ b/packages/client/src/tiptap/wrappers/mind/mind-elixir/utils/pubsub.ts
@@ -11,19 +11,19 @@ Bus.prototype = {
},
fire: function (type, ...payload) {
if (this.handlers[type] instanceof Array) {
- var handlers = this.handlers[type];
- for (var i = 0; i < handlers.length; i++) {
+ const handlers = this.handlers[type];
+ for (let i = 0; i < handlers.length; i++) {
handlers[i](...payload);
}
}
},
removeListener: function (type, handler) {
if (!this.handlers[type]) return;
- var handlers = this.handlers[type];
+ const handlers = this.handlers[type];
if (!handler) {
handlers.length = 0;
} else if (handlers.length) {
- for (var i = 0; i < handlers.length; i++) {
+ for (let i = 0; i < handlers.length; i++) {
if (handlers[i] === handler) {
this.handlers[type].splice(i, 1);
}
diff --git a/packages/client/src/tiptap/wrappers/status/index.tsx b/packages/client/src/tiptap/wrappers/status/index.tsx
index 5c4f22a4..82a4155c 100644
--- a/packages/client/src/tiptap/wrappers/status/index.tsx
+++ b/packages/client/src/tiptap/wrappers/status/index.tsx
@@ -72,7 +72,7 @@ export const StatusWrapper = ({ editor, node, updateAttributes }) => {
updateAttributes({ defaultShowPicker: false });
}
},
- [defaultShowPicker, updateAttributes, createUser, user]
+ [defaultShowPicker, toggleVisible, updateAttributes, createUser, user]
);
useEffect(() => {
@@ -80,7 +80,7 @@ export const StatusWrapper = ({ editor, node, updateAttributes }) => {
toggleVisible(true);
setTimeout(() => ref.current?.focus(), 100);
}
- }, [defaultShowPicker, createUser, user]);
+ }, [defaultShowPicker, toggleVisible, createUser, user]);
useEffect(() => {
if (visible) {