@ctzhian/tiptap 1.13.4 → 1.13.5

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.
@@ -173,7 +173,8 @@ var Reader = function Reader() {
173
173
  marginBottom: '30px'
174
174
  }
175
175
  }, /*#__PURE__*/React.createElement(EditorToolbar, {
176
- editor: editor
176
+ editor: editor,
177
+ mode: "advanced"
177
178
  })), /*#__PURE__*/React.createElement(Box, {
178
179
  sx: {
179
180
  '.tiptap': {
@@ -4,6 +4,13 @@ import { ToolbarItemType } from '../type';
4
4
  interface EditorToolbarProps {
5
5
  editor: Editor;
6
6
  menuInToolbarMore?: ToolbarItemType[];
7
+ /**
8
+ * Toolbar 模式
9
+ * - advanced:展示全部工具
10
+ * - simple:只展示常用工具,并尽量保持单行
11
+ */
12
+ mode?: 'simple' | 'advanced';
13
+ onModeChange?: (mode: 'simple' | 'advanced') => void;
7
14
  }
8
- declare const EditorToolbar: ({ editor, menuInToolbarMore }: EditorToolbarProps) => React.JSX.Element;
15
+ declare const EditorToolbar: ({ editor, menuInToolbarMore, mode, onModeChange, }: EditorToolbarProps) => React.JSX.Element;
9
16
  export default EditorToolbar;
@@ -1,12 +1,37 @@
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; }
1
7
  import { Box, Divider, Stack } from '@mui/material';
2
8
  import { useEditorState } from '@tiptap/react';
3
9
  import React from 'react';
4
- import { AiGenerate2Icon, ArrowGoBackLineIcon, ArrowGoForwardLineIcon, BoldIcon, EraserLineIcon, ItalicIcon, LinkIcon, MarkPenLineIcon, StrikethroughIcon, SubscriptIcon, SuperscriptIcon, UnderlineIcon } from "../component/Icons";
10
+ import { AiGenerate2Icon, ArrowGoBackLineIcon, ArrowGoForwardLineIcon, BoldIcon, CodeBoxLineIcon, CollapseHorizontalLine, EraserLineIcon, ExpandHorizontalLineIcon, ItalicIcon, LinkIcon, MarkPenLineIcon, StrikethroughIcon, SubscriptIcon, SuperscriptIcon, UnderlineIcon } from "../component/Icons";
5
11
  import { EditorAlignSelect, EditorFontBgColor, EditorFontColor, EditorFontSize, EditorHeading, EditorInsert, EditorListSelect, EditorMore, EditorVerticalAlignSelect, ToolbarItem } from "../component/Toolbar";
6
12
  import { hasMarksInSelection } from "../util";
7
13
  var EditorToolbar = function EditorToolbar(_ref) {
8
14
  var editor = _ref.editor,
9
- menuInToolbarMore = _ref.menuInToolbarMore;
15
+ menuInToolbarMore = _ref.menuInToolbarMore,
16
+ mode = _ref.mode,
17
+ onModeChange = _ref.onModeChange;
18
+ var _React$useState = React.useState(function () {
19
+ return mode !== null && mode !== void 0 ? mode : 'advanced';
20
+ }),
21
+ _React$useState2 = _slicedToArray(_React$useState, 2),
22
+ toolbarMode = _React$useState2[0],
23
+ setToolbarMode = _React$useState2[1];
24
+ React.useEffect(function () {
25
+ if (typeof mode !== 'undefined') {
26
+ setToolbarMode(mode);
27
+ }
28
+ }, [mode]);
29
+ var isSimpleMode = toolbarMode === 'simple';
30
+ var handleToggleMode = React.useCallback(function () {
31
+ var nextMode = isSimpleMode ? 'advanced' : 'simple';
32
+ setToolbarMode(nextMode);
33
+ onModeChange === null || onModeChange === void 0 || onModeChange(nextMode);
34
+ }, [isSimpleMode, onModeChange]);
10
35
  var _useEditorState = useEditorState({
11
36
  editor: editor,
12
37
  selector: function selector(ctx) {
@@ -23,7 +48,8 @@ var EditorToolbar = function EditorToolbar(_ref) {
23
48
  isSubscript: ctx.editor.isActive('subscript'),
24
49
  isLink: ctx.editor.isActive('link'),
25
50
  isHighlight: ctx.editor.isActive('highlight'),
26
- 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)
51
+ 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),
52
+ isCodeBlock: ctx.editor.isActive('codeBlock')
27
53
  };
28
54
  }
29
55
  }),
@@ -38,16 +64,19 @@ var EditorToolbar = function EditorToolbar(_ref) {
38
64
  isSubscript = _useEditorState.isSubscript,
39
65
  isLink = _useEditorState.isLink,
40
66
  isAiWriting = _useEditorState.isAiWriting,
41
- isHighlight = _useEditorState.isHighlight;
67
+ isHighlight = _useEditorState.isHighlight,
68
+ isCodeBlock = _useEditorState.isCodeBlock;
42
69
  return /*#__PURE__*/React.createElement(Box, {
43
70
  className: "editor-toolbar"
44
71
  }, /*#__PURE__*/React.createElement(Stack, {
45
72
  direction: "row",
46
73
  alignItems: "center",
47
- justifyContent: "center",
48
- flexWrap: 'wrap',
74
+ justifyContent: isSimpleMode ? 'flex-start' : 'center',
75
+ flexWrap: isSimpleMode ? 'nowrap' : 'wrap',
49
76
  sx: {
50
77
  minHeight: '44px',
78
+ overflowX: isSimpleMode ? 'auto' : 'visible',
79
+ columnGap: 0.5,
51
80
  '.MuiSelect-root': {
52
81
  minWidth: '36px',
53
82
  bgcolor: 'background.paper',
@@ -72,7 +101,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
72
101
  }
73
102
  }
74
103
  }
75
- }, editor.options.extensions.find(function (it) {
104
+ }, !isSimpleMode && editor.options.extensions.find(function (it) {
76
105
  return it.name === 'aiWriting';
77
106
  }) && /*#__PURE__*/React.createElement(ToolbarItem, {
78
107
  text: 'AI 伴写',
@@ -86,7 +115,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
86
115
  return editor.chain().focus().setAiWriting(!isAiWriting).run();
87
116
  },
88
117
  className: isAiWriting ? 'tool-active' : ''
89
- }), /*#__PURE__*/React.createElement(EditorInsert, {
118
+ }), !isSimpleMode && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditorInsert, {
90
119
  editor: editor
91
120
  }), /*#__PURE__*/React.createElement(Divider, {
92
121
  orientation: "vertical",
@@ -96,7 +125,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
96
125
  height: 20,
97
126
  alignSelf: 'center'
98
127
  }
99
- }), /*#__PURE__*/React.createElement(ToolbarItem, {
128
+ })), /*#__PURE__*/React.createElement(ToolbarItem, {
100
129
  tip: '撤销',
101
130
  shortcutKey: ['ctrl', 'Z'],
102
131
  icon: /*#__PURE__*/React.createElement(ArrowGoBackLineIcon, {
@@ -141,7 +170,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
141
170
  }
142
171
  }), /*#__PURE__*/React.createElement(EditorHeading, {
143
172
  editor: editor
144
- }), /*#__PURE__*/React.createElement(EditorFontSize, {
173
+ }), !isSimpleMode && /*#__PURE__*/React.createElement(EditorFontSize, {
145
174
  editor: editor
146
175
  }), /*#__PURE__*/React.createElement(Divider, {
147
176
  orientation: "vertical",
@@ -175,7 +204,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
175
204
  return editor.chain().focus().toggleItalic().run();
176
205
  },
177
206
  className: isItalic ? 'tool-active' : ''
178
- }), /*#__PURE__*/React.createElement(ToolbarItem, {
207
+ }), !isSimpleMode && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ToolbarItem, {
179
208
  tip: '删除线',
180
209
  shortcutKey: ['ctrl', 'shift', 'S'],
181
210
  icon: /*#__PURE__*/React.createElement(StrikethroughIcon, {
@@ -199,7 +228,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
199
228
  return editor.chain().focus().toggleUnderline().run();
200
229
  },
201
230
  className: isUnderline ? 'tool-active' : ''
202
- }), /*#__PURE__*/React.createElement(ToolbarItem, {
231
+ })), !isSimpleMode && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ToolbarItem, {
203
232
  tip: '高亮',
204
233
  shortcutKey: ['ctrl', 'shift', 'H'],
205
234
  icon: /*#__PURE__*/React.createElement(MarkPenLineIcon, {
@@ -247,9 +276,21 @@ var EditorToolbar = function EditorToolbar(_ref) {
247
276
  height: 20,
248
277
  alignSelf: 'center'
249
278
  }
250
- }), /*#__PURE__*/React.createElement(EditorListSelect, {
279
+ })), /*#__PURE__*/React.createElement(EditorListSelect, {
251
280
  editor: editor
252
- }), /*#__PURE__*/React.createElement(ToolbarItem, {
281
+ }), isSimpleMode ? /*#__PURE__*/React.createElement(ToolbarItem, {
282
+ tip: '代码块',
283
+ shortcutKey: ['ctrl', 'alt', 'C'],
284
+ icon: /*#__PURE__*/React.createElement(CodeBoxLineIcon, {
285
+ sx: {
286
+ fontSize: '1rem'
287
+ }
288
+ }),
289
+ onClick: function onClick() {
290
+ return editor.chain().focus().toggleCodeBlock().run();
291
+ },
292
+ className: isCodeBlock ? 'tool-active' : ''
293
+ }) : /*#__PURE__*/React.createElement(ToolbarItem, {
253
294
  tip: '链接',
254
295
  shortcutKey: ['ctrl', '1'],
255
296
  icon: /*#__PURE__*/React.createElement(LinkIcon, {
@@ -268,7 +309,7 @@ var EditorToolbar = function EditorToolbar(_ref) {
268
309
  }).run();
269
310
  },
270
311
  className: isLink ? 'tool-active' : ''
271
- }), /*#__PURE__*/React.createElement(EditorAlignSelect, {
312
+ }), !isSimpleMode && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditorAlignSelect, {
272
313
  editor: editor
273
314
  }), /*#__PURE__*/React.createElement(EditorVerticalAlignSelect, {
274
315
  editor: editor
@@ -282,6 +323,20 @@ var EditorToolbar = function EditorToolbar(_ref) {
282
323
  }
283
324
  }), /*#__PURE__*/React.createElement(EditorMore, {
284
325
  more: menuInToolbarMore
326
+ })), isSimpleMode && menuInToolbarMore !== null && menuInToolbarMore !== void 0 && menuInToolbarMore.length ? /*#__PURE__*/React.createElement(EditorMore, {
327
+ more: menuInToolbarMore
328
+ }) : null, mode === 'simple' && /*#__PURE__*/React.createElement(ToolbarItem, {
329
+ tip: isSimpleMode ? '切换为复杂模式' : '切换为简单模式',
330
+ icon: isSimpleMode ? /*#__PURE__*/React.createElement(ExpandHorizontalLineIcon, {
331
+ sx: {
332
+ fontSize: '1rem'
333
+ }
334
+ }) : /*#__PURE__*/React.createElement(CollapseHorizontalLine, {
335
+ sx: {
336
+ fontSize: '1rem'
337
+ }
338
+ }),
339
+ onClick: handleToggleMode
285
340
  })));
286
341
  };
287
342
  export default EditorToolbar;
@@ -0,0 +1,6 @@
1
+ import { SvgIconProps } from "@mui/material";
2
+ import * as React from "react";
3
+ export declare const CollapseHorizontalLine: {
4
+ (props: SvgIconProps): React.JSX.Element;
5
+ displayName: string;
6
+ };
@@ -0,0 +1,13 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+ import { SvgIcon } from "@mui/material";
3
+ import * as React from "react";
4
+ export var CollapseHorizontalLine = function CollapseHorizontalLine(props) {
5
+ return /*#__PURE__*/React.createElement(SvgIcon, _extends({
6
+ viewBox: "0 0 24 24",
7
+ version: "1.1",
8
+ xmlns: "http://www.w3.org/2000/svg"
9
+ }, props), /*#__PURE__*/React.createElement("path", {
10
+ d: "M13.5 12 18.4497 7.05029 19.864 8.46451 17.3284 11H23V13H17.3284L19.8615 15.5331 18.4473 16.9473 13.5 12ZM1 13H6.67084L4.13584 15.535 5.55005 16.9493 10.5 11.9996 5.55025 7.0498 4.13604 8.46402 6.67206 11H1V13Z"
11
+ }));
12
+ };
13
+ CollapseHorizontalLine.displayName = 'collapse-horizontal-line';
@@ -0,0 +1,6 @@
1
+ import { SvgIconProps } from '@mui/material';
2
+ import * as React from 'react';
3
+ export declare const ExpandHorizontalLineIcon: {
4
+ (props: SvgIconProps): React.JSX.Element;
5
+ displayName: string;
6
+ };
@@ -0,0 +1,13 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+ import { SvgIcon } from '@mui/material';
3
+ import * as React from 'react';
4
+ export var ExpandHorizontalLineIcon = function ExpandHorizontalLineIcon(props) {
5
+ return /*#__PURE__*/React.createElement(SvgIcon, _extends({
6
+ viewBox: "0 0 24 24",
7
+ version: "1.1",
8
+ xmlns: "http://www.w3.org/2000/svg"
9
+ }, props), /*#__PURE__*/React.createElement("path", {
10
+ d: "M0.5 12L5.44975 7.05029L6.86396 8.46451L4.32843 11H10V13H4.32843L6.86148 15.5331L5.44727 16.9473L0.5 12ZM14 13H19.6708L17.1358 15.535L18.55 16.9493L23.5 11.9996L18.5503 7.0498L17.136 8.46402L19.6721 11H14V13Z"
11
+ }));
12
+ };
13
+ ExpandHorizontalLineIcon.displayName = 'expand-horizontal-line';
@@ -134,3 +134,5 @@ export { UserSmileFillIcon } from './user-smile-fill-icon';
134
134
  export { VolumeMuteLineIcon } from './volume-mute-line-icon';
135
135
  export { VolumeUpLineIcon } from './volume-up-line-icon';
136
136
  export { WindowFillIcon } from './window-fill-icon';
137
+ export { CollapseHorizontalLine } from './collapse-horizontal-line';
138
+ export { ExpandHorizontalLineIcon } from './expand-horizontal-line';
@@ -136,4 +136,6 @@ export { UploadIcon } from "./upload-icon";
136
136
  export { UserSmileFillIcon } from "./user-smile-fill-icon";
137
137
  export { VolumeMuteLineIcon } from "./volume-mute-line-icon";
138
138
  export { VolumeUpLineIcon } from "./volume-up-line-icon";
139
- export { WindowFillIcon } from "./window-fill-icon";
139
+ export { WindowFillIcon } from "./window-fill-icon";
140
+ export { CollapseHorizontalLine } from "./collapse-horizontal-line";
141
+ export { ExpandHorizontalLineIcon } from "./expand-horizontal-line";
@@ -1,4 +1,4 @@
1
1
  import { UploadFunction } from "../../type";
2
2
  export declare const FileHandlerExtension: (props: {
3
3
  onUpload?: UploadFunction;
4
- }) => import("@tiptap/core").Extension<Omit<import("@tiptap/extension-file-handler").FileHandlePluginOptions, "editor" | "key">, any>;
4
+ }) => import("@tiptap/core").Extension<Omit<import("@tiptap/extension-file-handler").FileHandlePluginOptions, "key" | "editor">, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctzhian/tiptap",
3
- "version": "1.13.4",
3
+ "version": "1.13.5",
4
4
  "description": "基于 Tiptap 二次开发的编辑器组件",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",