@ctzhian/tiptap 1.6.2 → 1.6.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,7 +1,7 @@
1
- var _excluded = ["className"];
2
- 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); }
3
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
4
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
5
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
6
  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."); }
7
7
  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); }
@@ -9,10 +9,11 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
9
9
  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; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
11
  import { getShortcutKeyText } from "../../util";
12
- import { Box, MenuItem, Select, Stack, Tooltip } from "@mui/material";
12
+ import { Box, Typography } from "@mui/material";
13
13
  import React, { useEffect, useState } from "react";
14
- import { ArrowDownSLineIcon, H1Icon, H2Icon, H3Icon, H4Icon, H5Icon, H6Icon, HeadingIcon } from "../Icons";
15
- import ToolItem from "./Item";
14
+ import { ArrowDownSLineIcon, H1Icon, H2Icon, H3Icon, H4Icon, H5Icon, H6Icon, TextIcon } from "../Icons";
15
+ import Menu from "../Menu";
16
+ import { default as ToolbarItem } from "./Item";
16
17
  var EditorHeading = function EditorHeading(_ref) {
17
18
  var editor = _ref.editor;
18
19
  var _useState = useState("paragraph"),
@@ -21,12 +22,12 @@ var EditorHeading = function EditorHeading(_ref) {
21
22
  setSelectedValue = _useState2[1];
22
23
  var HeadingOptions = [{
23
24
  id: 'paragraph',
24
- icon: /*#__PURE__*/React.createElement(HeadingIcon, {
25
+ icon: /*#__PURE__*/React.createElement(TextIcon, {
25
26
  sx: {
26
27
  fontSize: '1rem'
27
28
  }
28
29
  }),
29
- label: 'Paragraph',
30
+ label: '正文',
30
31
  shortcutKey: ['ctrl', 'alt', '0']
31
32
  }, {
32
33
  id: '1',
@@ -35,7 +36,7 @@ var EditorHeading = function EditorHeading(_ref) {
35
36
  fontSize: '1rem'
36
37
  }
37
38
  }),
38
- label: 'Heading 1',
39
+ label: '标题1',
39
40
  shortcutKey: ['ctrl', 'alt', '1']
40
41
  }, {
41
42
  id: '2',
@@ -44,7 +45,7 @@ var EditorHeading = function EditorHeading(_ref) {
44
45
  fontSize: '1rem'
45
46
  }
46
47
  }),
47
- label: 'Heading 2',
48
+ label: '标题2',
48
49
  shortcutKey: ['ctrl', 'alt', '2']
49
50
  }, {
50
51
  id: '3',
@@ -53,7 +54,7 @@ var EditorHeading = function EditorHeading(_ref) {
53
54
  fontSize: '1rem'
54
55
  }
55
56
  }),
56
- label: 'Heading 3',
57
+ label: '标题3',
57
58
  shortcutKey: ['ctrl', 'alt', '3']
58
59
  }, {
59
60
  id: '4',
@@ -62,7 +63,7 @@ var EditorHeading = function EditorHeading(_ref) {
62
63
  fontSize: '1rem'
63
64
  }
64
65
  }),
65
- label: 'Heading 4',
66
+ label: '标题4',
66
67
  shortcutKey: ['ctrl', 'alt', '4']
67
68
  }, {
68
69
  id: '5',
@@ -71,7 +72,7 @@ var EditorHeading = function EditorHeading(_ref) {
71
72
  fontSize: '1rem'
72
73
  }
73
74
  }),
74
- label: 'Heading 5',
75
+ label: '标题5',
75
76
  shortcutKey: ['ctrl', 'alt', '5']
76
77
  }, {
77
78
  id: '6',
@@ -80,15 +81,14 @@ var EditorHeading = function EditorHeading(_ref) {
80
81
  fontSize: '1rem'
81
82
  }
82
83
  }),
83
- label: 'Heading 6',
84
+ label: '标题6',
84
85
  shortcutKey: ['ctrl', 'alt', '6']
85
86
  }];
86
87
  var updateSelection = function updateSelection() {
87
88
  var level = editor.getAttributes("heading").level || "paragraph";
88
89
  setSelectedValue(level);
89
90
  };
90
- var handleChange = function handleChange(e) {
91
- var value = e.target.value;
91
+ var handleChange = function handleChange(value) {
92
92
  setSelectedValue(value);
93
93
  if (value !== 'paragraph') {
94
94
  var level = parseInt(value);
@@ -107,79 +107,67 @@ var EditorHeading = function EditorHeading(_ref) {
107
107
  editor.off('transaction', updateSelection);
108
108
  };
109
109
  }, [editor]);
110
- return /*#__PURE__*/React.createElement(Select, {
111
- value: selectedValue,
112
- className: ['1', '2', '3', '4', '5', '6'].includes(String(selectedValue)) ? "tool-active" : "",
113
- onChange: handleChange,
114
- sx: {
115
- bgcolor: 'transparent',
116
- '&:hover .MuiOutlinedInput-notchedOutline': {
117
- borderWidth: '0px !important',
118
- borderColor: 'transparent !important'
119
- },
120
- '&.Mui-focused .MuiOutlinedInput-notchedOutline': {
121
- borderWidth: '0px !important',
122
- borderColor: 'transparent !important'
123
- }
124
- },
125
- renderValue: function renderValue(value) {
126
- var _HeadingOptions$find;
127
- return /*#__PURE__*/React.createElement(ToolItem, {
128
- tip: '标题',
129
- icon: /*#__PURE__*/React.createElement(Stack, {
130
- direction: 'row',
131
- alignItems: 'center',
132
- sx: {
133
- mr: 0.5,
134
- width: '1.5rem'
135
- }
136
- }, ((_HeadingOptions$find = HeadingOptions.find(function (it) {
137
- return it.id === String(value);
138
- })) === null || _HeadingOptions$find === void 0 ? void 0 : _HeadingOptions$find.icon) || /*#__PURE__*/React.createElement(HeadingIcon, {
139
- sx: {
140
- fontSize: '1rem'
141
- }
142
- }))
143
- });
144
- },
145
- IconComponent: function IconComponent(_ref2) {
146
- var className = _ref2.className,
147
- rest = _objectWithoutProperties(_ref2, _excluded);
148
- return /*#__PURE__*/React.createElement(ArrowDownSLineIcon, _extends({
110
+ return /*#__PURE__*/React.createElement(Menu, {
111
+ context: /*#__PURE__*/React.createElement(ToolbarItem, {
112
+ tip: '标题',
113
+ text: /*#__PURE__*/React.createElement(Box, {
114
+ sx: {
115
+ position: 'relative',
116
+ pr: 1
117
+ }
118
+ }, /*#__PURE__*/React.createElement(Box, {
119
+ sx: {
120
+ width: '38px',
121
+ textAlign: 'left'
122
+ }
123
+ }, HeadingOptions.filter(function (it) {
124
+ return it.id === String(selectedValue);
125
+ })[0].label), /*#__PURE__*/React.createElement(ArrowDownSLineIcon, {
149
126
  sx: {
150
127
  position: 'absolute',
151
- right: 2,
128
+ right: -6,
129
+ top: '50%',
130
+ transform: 'translateY(-50%)',
152
131
  flexSelf: 'center',
153
132
  fontSize: '1rem',
154
133
  flexShrink: 0,
155
134
  mr: 0,
156
135
  color: 'text.disabled',
157
- transform: className !== null && className !== void 0 && className.includes('MuiSelect-iconOpen') ? 'rotate(-180deg)' : 'none',
158
- transition: 'transform 0.3s',
159
136
  cursor: 'pointer',
160
137
  pointerEvents: 'none'
161
138
  }
162
- }, rest));
163
- }
164
- }, HeadingOptions.map(function (it) {
165
- return /*#__PURE__*/React.createElement(MenuItem, {
166
- key: it.id,
167
- value: it.id
168
- }, /*#__PURE__*/React.createElement(Tooltip, {
169
- arrow: true,
170
- title: getShortcutKeyText(it.shortcutKey),
171
- placement: "right"
172
- }, /*#__PURE__*/React.createElement(Stack, {
173
- direction: 'row',
174
- alignItems: 'center',
175
- justifyContent: "center",
176
- gap: 1
177
- }, it.icon, /*#__PURE__*/React.createElement(Box, {
139
+ }))
140
+ }),
141
+ anchorOrigin: {
142
+ vertical: 'bottom',
143
+ horizontal: 'left'
144
+ },
145
+ transformOrigin: {
146
+ vertical: 'top',
147
+ horizontal: 'left'
148
+ },
149
+ arrowIcon: /*#__PURE__*/React.createElement(ArrowDownSLineIcon, {
178
150
  sx: {
179
- ml: 1,
180
- fontSize: '0.875rem'
151
+ fontSize: '1rem',
152
+ transform: 'rotate(-90deg)'
181
153
  }
182
- }, it.label))));
183
- }));
154
+ }),
155
+ list: _toConsumableArray(HeadingOptions.map(function (it) {
156
+ return {
157
+ label: it.label,
158
+ key: it.id,
159
+ icon: it.icon,
160
+ extra: /*#__PURE__*/React.createElement(Typography, {
161
+ sx: {
162
+ fontSize: '12px',
163
+ color: 'text.disabled'
164
+ }
165
+ }, getShortcutKeyText(it.shortcutKey, ' ')),
166
+ onClick: function onClick() {
167
+ return handleChange(it.id);
168
+ }
169
+ };
170
+ }))
171
+ });
184
172
  };
185
173
  export default EditorHeading;
@@ -1,5 +1,5 @@
1
- import { Editor } from "@tiptap/react";
2
- import React from "react";
1
+ import { Editor } from '@tiptap/react';
2
+ import React from 'react';
3
3
  interface EditorInsertProps {
4
4
  editor: Editor;
5
5
  }