@ctzhian/tiptap 2.5.0 → 2.5.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.
@@ -3,6 +3,7 @@ import 'core-js/actual/array/find-last';
3
3
  interface EditorDiffProps {
4
4
  oldHtml: string;
5
5
  newHtml: string;
6
+ baseUrl?: string;
6
7
  }
7
- declare const EditorDiff: ({ oldHtml, newHtml }: EditorDiffProps) => React.JSX.Element;
8
+ declare const EditorDiff: ({ oldHtml, newHtml, baseUrl }: EditorDiffProps) => React.JSX.Element;
8
9
  export default EditorDiff;
@@ -8,10 +8,12 @@ import useTiptap from "../hook";
8
8
 
9
9
  var EditorDiff = function EditorDiff(_ref) {
10
10
  var oldHtml = _ref.oldHtml,
11
- newHtml = _ref.newHtml;
11
+ newHtml = _ref.newHtml,
12
+ baseUrl = _ref.baseUrl;
12
13
  var editorRef = useTiptap({
13
14
  editable: false,
14
15
  content: newHtml,
16
+ baseUrl: baseUrl,
15
17
  exclude: ['youtube', 'mention']
16
18
  });
17
19
  useEffect(function () {
@@ -3,11 +3,35 @@ import { hasMarksInSelection } from "../../util";
3
3
  import { Divider, Paper, Stack } from '@mui/material';
4
4
  import { useEditorState } from '@tiptap/react';
5
5
  import { BubbleMenu } from '@tiptap/react/menus';
6
- import React from 'react';
6
+ import React, { useEffect, useRef } from 'react';
7
7
  import { ToolbarItem } from "../Toolbar";
8
8
  var CustomBubbleMenu = function CustomBubbleMenu(_ref) {
9
9
  var editor = _ref.editor,
10
10
  more = _ref.more;
11
+ // 跟踪编辑器是否已经完全初始化
12
+ var isInitializedRef = useRef(false);
13
+ var initTimeoutRef = useRef(null);
14
+
15
+ // 当编辑器挂载后,延迟一段时间标记为已初始化
16
+ useEffect(function () {
17
+ if (editor && editor.view) {
18
+ // 清除之前的定时器
19
+ if (initTimeoutRef.current) {
20
+ clearTimeout(initTimeoutRef.current);
21
+ }
22
+
23
+ // 延迟标记为已初始化,确保编辑器状态稳定
24
+ initTimeoutRef.current = setTimeout(function () {
25
+ isInitializedRef.current = true;
26
+ }, 100);
27
+ }
28
+ return function () {
29
+ if (initTimeoutRef.current) {
30
+ clearTimeout(initTimeoutRef.current);
31
+ }
32
+ };
33
+ }, [editor]);
34
+
11
35
  // const theme = useTheme()
12
36
 
13
37
  // const THEME_TEXT_COLOR = [
@@ -73,7 +97,38 @@ var CustomBubbleMenu = function CustomBubbleMenu(_ref) {
73
97
  offset: 8,
74
98
  flip: true
75
99
  },
76
- shouldShow: function shouldShow() {
100
+ shouldShow: function shouldShow(_ref2) {
101
+ var editor = _ref2.editor;
102
+ // 确保编辑器已初始化
103
+ if (!editor || !editor.state || !editor.view) {
104
+ return false;
105
+ }
106
+
107
+ // 如果编辑器还没有完全初始化,不显示
108
+ if (!isInitializedRef.current) {
109
+ return false;
110
+ }
111
+ var _editor$state = editor.state,
112
+ selection = _editor$state.selection,
113
+ doc = _editor$state.doc;
114
+
115
+ // 如果没有选中文本(选择为空或起始和结束位置相同),不显示
116
+ if (selection.empty || selection.from === selection.to) {
117
+ return false;
118
+ }
119
+
120
+ // 检查选中的文本内容是否真的有意义(不是空白字符)
121
+ // 使用 textBetween 获取选中范围内的文本,排除空白字符
122
+ var selectedText = doc.textBetween(selection.from, selection.to, ' ', ' ');
123
+ if (!selectedText || selectedText.trim().length === 0) {
124
+ return false;
125
+ }
126
+
127
+ // 如果文档为空(只有默认段落且无内容),不显示
128
+ if (editor.isEmpty) {
129
+ return false;
130
+ }
131
+
77
132
  // 表格多选单元格时禁止弹出气泡菜单
78
133
  // if (editor.state.selection.constructor.name === '_CellSelection') {
79
134
  // const cellSelection = editor.state.selection as any;
@@ -84,7 +139,9 @@ var CustomBubbleMenu = function CustomBubbleMenu(_ref) {
84
139
  // return cellSelection.$anchorCell.pos !== cellSelection.$headCell.pos;
85
140
  // }
86
141
  // }
87
- if (editor.state.selection.empty || editor.isActive('image') || editor.isActive('video') || editor.isActive('audio') || editor.isActive('emoji') || editor.isActive('codeBlock') || editor.isActive('blockMath') || editor.isActive('inlineMath') || editor.isActive('blockLink') || editor.isActive('inlineLink') || editor.isActive('blockAttachment') || editor.isActive('inlineAttachment') || editor.isActive('horizontalRule') || editor.isActive('iframe') || editor.isActive('yamlFormat') || editor.isActive('flow') || editor.isActive('table')) {
142
+
143
+ // 在某些特定节点类型时不显示
144
+ if (editor.isActive('image') || editor.isActive('video') || editor.isActive('audio') || editor.isActive('emoji') || editor.isActive('codeBlock') || editor.isActive('blockMath') || editor.isActive('inlineMath') || editor.isActive('blockLink') || editor.isActive('inlineLink') || editor.isActive('blockAttachment') || editor.isActive('inlineAttachment') || editor.isActive('horizontalRule') || editor.isActive('iframe') || editor.isActive('yamlFormat') || editor.isActive('flow') || editor.isActive('table')) {
88
145
  return false;
89
146
  }
90
147
  return true;
@@ -1,5 +1,5 @@
1
1
  import { Extension } from '@tiptap/core';
2
2
  export declare const TableExtension: ({ editable }: {
3
3
  editable: boolean;
4
- }) => (Extension<any, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableHeaderOptions, any>)[];
4
+ }) => (import("@tiptap/core").Node<import("@tiptap/extension-table").TableOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableHeaderOptions, any> | Extension<any, any>)[];
5
5
  export default TableExtension;
package/package.json CHANGED
@@ -1,10 +1,24 @@
1
1
  {
2
2
  "name": "@ctzhian/tiptap",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "基于 Tiptap 二次开发的编辑器组件",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "start": "npm run dev",
10
+ "dev": "dumi dev",
11
+ "build": "rm -rf dist && father build",
12
+ "build:watch": "father dev",
13
+ "docs:build": "dumi build",
14
+ "docs:preview": "dumi preview",
15
+ "prepare": "husky install && dumi setup",
16
+ "doctor": "father doctor",
17
+ "lint": "npm run lint:es && npm run lint:css",
18
+ "lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
19
+ "lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
20
+ "pre": "pnpm build && pnpm link --global"
21
+ },
8
22
  "authors": [
9
23
  "ky.kyy@qq.com"
10
24
  ],
@@ -128,18 +142,5 @@
128
142
  "react-image-crop": "^11.0.10",
129
143
  "react-photo-view": "^1.2.7",
130
144
  "uuid": "^11.1.0"
131
- },
132
- "scripts": {
133
- "start": "npm run dev",
134
- "dev": "dumi dev",
135
- "build": "rm -rf dist && father build",
136
- "build:watch": "father dev",
137
- "docs:build": "dumi build",
138
- "docs:preview": "dumi preview",
139
- "doctor": "father doctor",
140
- "lint": "npm run lint:es && npm run lint:css",
141
- "lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
142
- "lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
143
- "pre": "pnpm build && pnpm link --global"
144
145
  }
145
- }
146
+ }