@ctzhian/tiptap 1.7.5-beta.2 → 1.7.5-beta.3

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.
@@ -1,68 +1,54 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
1
  import { Box, Divider, Stack } from '@mui/material';
8
- import React, { useEffect, useState } from 'react';
2
+ import { useEditorState } from '@tiptap/react';
3
+ import React from 'react';
9
4
  import { AiGenerate2Icon, ArrowGoBackLineIcon, ArrowGoForwardLineIcon, BoldIcon, EraserLineIcon, ItalicIcon, LinkIcon, MarkPenLineIcon, StrikethroughIcon, SubscriptIcon, SuperscriptIcon, UnderlineIcon } from "../component/Icons";
10
5
  import { EditorAlignSelect, EditorFontBgColor, EditorFontColor, EditorFontSize, EditorHeading, EditorInsert, EditorListSelect, EditorMore, EditorVerticalAlignSelect, ToolbarItem } from "../component/Toolbar";
6
+ import { hasMarksInSelection } from "../util";
11
7
  var EditorToolbar = function EditorToolbar(_ref) {
12
8
  var editor = _ref.editor,
13
9
  menuInToolbarMore = _ref.menuInToolbarMore;
14
- var _useState = useState({
15
- undo: false,
16
- redo: false,
17
- format: false,
18
- quote: false,
19
- bold: false,
20
- italic: false,
21
- strike: false,
22
- underline: false,
23
- superscript: false,
24
- subscript: false,
25
- details: false,
26
- table: false,
27
- link: false,
28
- alert: false,
29
- iframe: false,
30
- aiWriting: false,
31
- highlight: false
10
+ var _useEditorState = useEditorState({
11
+ editor: editor,
12
+ selector: function selector(ctx) {
13
+ var _ctx$editor$can$chain, _ctx$editor$can$chain2, _ctx$editor$storage;
14
+ return {
15
+ isUndo: (_ctx$editor$can$chain = ctx.editor.can().chain().undo().run()) !== null && _ctx$editor$can$chain !== void 0 ? _ctx$editor$can$chain : false,
16
+ isRedo: (_ctx$editor$can$chain2 = ctx.editor.can().chain().redo().run()) !== null && _ctx$editor$can$chain2 !== void 0 ? _ctx$editor$can$chain2 : false,
17
+ isFormat: hasMarksInSelection(ctx.editor.state),
18
+ isQuote: ctx.editor.isActive('blockquote'),
19
+ isBold: ctx.editor.isActive('bold'),
20
+ isItalic: ctx.editor.isActive('italic'),
21
+ isStrike: ctx.editor.isActive('strike'),
22
+ isUnderline: ctx.editor.isActive('underline'),
23
+ isSuperscript: ctx.editor.isActive('superscript'),
24
+ isSubscript: ctx.editor.isActive('subscript'),
25
+ isDetails: ctx.editor.isActive('details'),
26
+ isTable: ctx.editor.isActive('table'),
27
+ isLink: ctx.editor.isActive('link'),
28
+ isAlert: ctx.editor.isActive('alert'),
29
+ isIframe: ctx.editor.isActive('iframe'),
30
+ isHighlight: ctx.editor.isActive('highlight'),
31
+ isAiWriting: !!((_ctx$editor$storage = ctx.editor.storage) !== null && _ctx$editor$storage !== void 0 && (_ctx$editor$storage = _ctx$editor$storage.aiWriting) !== null && _ctx$editor$storage !== void 0 && _ctx$editor$storage.enabled)
32
+ };
33
+ }
32
34
  }),
33
- _useState2 = _slicedToArray(_useState, 2),
34
- active = _useState2[0],
35
- setActive = _useState2[1];
36
- var updateSelection = function updateSelection() {
37
- var _editor$can$chain$und, _editor$can$chain$red, _editor$can$chain$uns, _editor$storage;
38
- setActive({
39
- undo: (_editor$can$chain$und = editor.can().chain().undo().run()) !== null && _editor$can$chain$und !== void 0 ? _editor$can$chain$und : false,
40
- redo: (_editor$can$chain$red = editor.can().chain().redo().run()) !== null && _editor$can$chain$red !== void 0 ? _editor$can$chain$red : false,
41
- format: (_editor$can$chain$uns = editor.can().chain().unsetAllMarks().run()) !== null && _editor$can$chain$uns !== void 0 ? _editor$can$chain$uns : false,
42
- quote: editor.isActive('blockquote'),
43
- bold: editor.isActive('bold'),
44
- italic: editor.isActive('italic'),
45
- strike: editor.isActive('strike'),
46
- underline: editor.isActive('underline'),
47
- superscript: editor.isActive('superscript'),
48
- subscript: editor.isActive('subscript'),
49
- details: editor.isActive('details'),
50
- table: editor.isActive('table'),
51
- link: editor.isActive('link'),
52
- alert: editor.isActive('alert'),
53
- iframe: editor.isActive('iframe'),
54
- aiWriting: !!((_editor$storage = editor.storage) !== null && _editor$storage !== void 0 && (_editor$storage = _editor$storage.aiWriting) !== null && _editor$storage !== void 0 && _editor$storage.enabled),
55
- highlight: editor.isActive('highlight')
56
- });
57
- };
58
- useEffect(function () {
59
- editor.on('selectionUpdate', updateSelection);
60
- editor.on('transaction', updateSelection);
61
- return function () {
62
- editor.off('selectionUpdate', updateSelection);
63
- editor.off('transaction', updateSelection);
64
- };
65
- }, [editor]);
35
+ isUndo = _useEditorState.isUndo,
36
+ isRedo = _useEditorState.isRedo,
37
+ isFormat = _useEditorState.isFormat,
38
+ isQuote = _useEditorState.isQuote,
39
+ isBold = _useEditorState.isBold,
40
+ isItalic = _useEditorState.isItalic,
41
+ isStrike = _useEditorState.isStrike,
42
+ isUnderline = _useEditorState.isUnderline,
43
+ isSuperscript = _useEditorState.isSuperscript,
44
+ isSubscript = _useEditorState.isSubscript,
45
+ isDetails = _useEditorState.isDetails,
46
+ isTable = _useEditorState.isTable,
47
+ isLink = _useEditorState.isLink,
48
+ isAlert = _useEditorState.isAlert,
49
+ isIframe = _useEditorState.isIframe,
50
+ isAiWriting = _useEditorState.isAiWriting,
51
+ isHighlight = _useEditorState.isHighlight;
66
52
  return /*#__PURE__*/React.createElement(Box, {
67
53
  className: "editor-toolbar"
68
54
  }, /*#__PURE__*/React.createElement(Stack, {
@@ -107,9 +93,9 @@ var EditorToolbar = function EditorToolbar(_ref) {
107
93
  }
108
94
  }),
109
95
  onClick: function onClick() {
110
- return editor.chain().focus().setAiWriting(!active.aiWriting).run();
96
+ return editor.chain().focus().setAiWriting(!isAiWriting).run();
111
97
  },
112
- className: active.aiWriting ? 'tool-active' : ''
98
+ className: isAiWriting ? 'tool-active' : ''
113
99
  }), /*#__PURE__*/React.createElement(EditorInsert, {
114
100
  editor: editor
115
101
  }), /*#__PURE__*/React.createElement(Divider, {
@@ -131,7 +117,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
131
117
  onClick: function onClick() {
132
118
  return editor.chain().focus().undo().run();
133
119
  },
134
- disabled: !active.undo
120
+ disabled: !isUndo
135
121
  }), /*#__PURE__*/React.createElement(ToolbarItem, {
136
122
  tip: '重做',
137
123
  shortcutKey: ['ctrl', 'Y'],
@@ -143,7 +129,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
143
129
  onClick: function onClick() {
144
130
  return editor.chain().focus().redo().run();
145
131
  },
146
- disabled: !active.redo
132
+ disabled: !isRedo
147
133
  }), /*#__PURE__*/React.createElement(ToolbarItem, {
148
134
  tip: '清除格式',
149
135
  icon: /*#__PURE__*/React.createElement(EraserLineIcon, {
@@ -151,7 +137,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
151
137
  fontSize: '1rem'
152
138
  }
153
139
  }),
154
- disabled: !active.format,
140
+ disabled: !isFormat,
155
141
  onClick: function onClick() {
156
142
  return editor.chain().focus().unsetAllMarks().run();
157
143
  }
@@ -186,7 +172,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
186
172
  onClick: function onClick() {
187
173
  return editor.chain().focus().toggleBold().run();
188
174
  },
189
- className: active.bold ? 'tool-active' : ''
175
+ className: isBold ? 'tool-active' : ''
190
176
  }), /*#__PURE__*/React.createElement(ToolbarItem, {
191
177
  tip: '斜体',
192
178
  shortcutKey: ['ctrl', 'I'],
@@ -198,7 +184,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
198
184
  onClick: function onClick() {
199
185
  return editor.chain().focus().toggleItalic().run();
200
186
  },
201
- className: active.italic ? 'tool-active' : ''
187
+ className: isItalic ? 'tool-active' : ''
202
188
  }), /*#__PURE__*/React.createElement(ToolbarItem, {
203
189
  tip: '删除线',
204
190
  shortcutKey: ['ctrl', 'shift', 'S'],
@@ -210,7 +196,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
210
196
  onClick: function onClick() {
211
197
  return editor.chain().focus().toggleStrike().run();
212
198
  },
213
- className: active.strike ? 'tool-active' : ''
199
+ className: isStrike ? 'tool-active' : ''
214
200
  }), /*#__PURE__*/React.createElement(ToolbarItem, {
215
201
  tip: '下划线',
216
202
  shortcutKey: ['ctrl', 'U'],
@@ -222,7 +208,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
222
208
  onClick: function onClick() {
223
209
  return editor.chain().focus().toggleUnderline().run();
224
210
  },
225
- className: active.underline ? 'tool-active' : ''
211
+ className: isUnderline ? 'tool-active' : ''
226
212
  }), /*#__PURE__*/React.createElement(ToolbarItem, {
227
213
  tip: '高亮',
228
214
  shortcutKey: ['ctrl', 'shift', 'H'],
@@ -234,7 +220,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
234
220
  onClick: function onClick() {
235
221
  return editor.chain().focus().toggleHighlight().run();
236
222
  },
237
- className: active.highlight ? 'tool-active' : ''
223
+ className: isHighlight ? 'tool-active' : ''
238
224
  }), /*#__PURE__*/React.createElement(ToolbarItem, {
239
225
  tip: '上标',
240
226
  shortcutKey: ['ctrl', '.'],
@@ -246,7 +232,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
246
232
  onClick: function onClick() {
247
233
  return editor.chain().focus().toggleSuperscript().run();
248
234
  },
249
- className: active.superscript ? 'tool-active' : ''
235
+ className: isSuperscript ? 'tool-active' : ''
250
236
  }), /*#__PURE__*/React.createElement(ToolbarItem, {
251
237
  tip: '下标',
252
238
  shortcutKey: ['ctrl', ','],
@@ -258,7 +244,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
258
244
  onClick: function onClick() {
259
245
  return editor.chain().focus().toggleSubscript().run();
260
246
  },
261
- className: active.subscript ? 'tool-active' : ''
247
+ className: isSubscript ? 'tool-active' : ''
262
248
  }), /*#__PURE__*/React.createElement(EditorFontColor, {
263
249
  editor: editor
264
250
  }), /*#__PURE__*/React.createElement(EditorFontBgColor, {
@@ -291,7 +277,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
291
277
  title: text
292
278
  }).run();
293
279
  },
294
- className: active.link ? 'tool-active' : ''
280
+ className: isLink ? 'tool-active' : ''
295
281
  }), /*#__PURE__*/React.createElement(EditorAlignSelect, {
296
282
  editor: editor
297
283
  }), /*#__PURE__*/React.createElement(EditorVerticalAlignSelect, {
@@ -48,7 +48,7 @@ var CustomBubbleMenu = function CustomBubbleMenu(_ref) {
48
48
  isUnderline: ctx.editor.isActive('underline'),
49
49
  isCode: ctx.editor.isActive('code'),
50
50
  isHighlight: ctx.editor.isActive('highlight'),
51
- hasAnyMarks: ctx.editor.state.selection.empty ? ctx.editor.state.selection.$from.marks().length > 0 : hasMarksInSelection(ctx.editor.state)
51
+ hasAnyMarks: hasMarksInSelection(ctx.editor.state)
52
52
  // isSuperscript: ctx.editor.isActive('superscript'),
53
53
  // isSubscript: ctx.editor.isActive('subscript'),
54
54
  };
@@ -16,6 +16,9 @@ export var insertNodeAfterPosition = function insertNodeAfterPosition(editor, po
16
16
  editor.chain().focus().insertContentAt(pos, nodeContent).run();
17
17
  };
18
18
  export var hasMarksInSelection = function hasMarksInSelection(state) {
19
+ if (state.selection.empty) {
20
+ return false;
21
+ }
19
22
  var _state$selection = state.selection,
20
23
  from = _state$selection.from,
21
24
  to = _state$selection.to;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctzhian/tiptap",
3
- "version": "1.7.5-beta.2",
3
+ "version": "1.7.5-beta.3",
4
4
  "description": "基于 Tiptap 二次开发的编辑器组件",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",