@ctzhian/tiptap 1.4.0 → 1.4.2

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.
@@ -75,6 +75,9 @@ var EditorToolbar = function EditorToolbar(_ref) {
75
75
  input: {
76
76
  display: 'none'
77
77
  },
78
+ '&:hover': {
79
+ bgcolor: 'background.paper2'
80
+ },
78
81
  '&.tool-active': {
79
82
  bgcolor: 'background.paper2',
80
83
  color: 'primary.main',
@@ -140,7 +140,8 @@ var EditorFontSize = function EditorFontSize(_ref) {
140
140
  }, /*#__PURE__*/React.createElement(Box, {
141
141
  sx: {
142
142
  textAlign: 'center',
143
- fontSize: '0.875rem'
143
+ fontSize: '0.875rem',
144
+ width: '100%'
144
145
  }
145
146
  }, it));
146
147
  }));
@@ -42,10 +42,10 @@ var ToolbarItem = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
42
42
  className: className,
43
43
  disabled: disabled,
44
44
  sx: _objectSpread({
45
+ minHeight: '36px',
45
46
  minWidth: '36px',
46
47
  p: 1,
47
48
  color: 'text.primary',
48
- borderRadius: 'var(--mui-shape-borderRadius)',
49
49
  '&.tool-active': {
50
50
  bgcolor: 'background.paper2',
51
51
  color: 'primary.main'
@@ -4,10 +4,12 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
4
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
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
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- import { Box, Stack } from "@mui/material";
7
+ import { addOpacityToColor } from "../../util";
8
+ import { Box, Stack, useTheme } from "@mui/material";
8
9
  import React, { useState } from "react";
9
10
  var TableSizePicker = function TableSizePicker(_ref) {
10
11
  var onConfirm = _ref.onConfirm;
12
+ var theme = useTheme();
11
13
  var _useState = useState(0),
12
14
  _useState2 = _slicedToArray(_useState, 2),
13
15
  cols = _useState2[0],
@@ -52,16 +54,21 @@ var TableSizePicker = function TableSizePicker(_ref) {
52
54
  return onConfirm(c, r);
53
55
  },
54
56
  sx: {
55
- width: '18px',
56
- height: '18px',
57
57
  borderRadius: '3px',
58
+ overflow: 'hidden',
59
+ cursor: 'pointer',
60
+ bgcolor: 'background.default',
58
61
  border: '1px solid',
59
- borderColor: 'divider',
60
- bgcolor: activeCell ? 'primary.main' : 'background.default',
62
+ borderColor: 'divider'
63
+ }
64
+ }, /*#__PURE__*/React.createElement(Box, {
65
+ sx: {
66
+ width: '18px',
67
+ height: '18px',
61
68
  transition: 'background-color 0.12s ease',
62
- cursor: 'pointer'
69
+ bgcolor: activeCell ? addOpacityToColor(theme.palette.primary.main, 0.5) : theme.palette.background.default
63
70
  }
64
- });
71
+ }));
65
72
  }));
66
73
  })), /*#__PURE__*/React.createElement(Box, {
67
74
  sx: {
@@ -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;
@@ -12,6 +12,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
12
12
  import { Extension } from '@tiptap/core';
13
13
  import { Table, TableCell, TableHeader, TableRow } from '@tiptap/extension-table';
14
14
  import { Plugin, TextSelection } from '@tiptap/pm/state';
15
+ import { Decoration, DecorationSet } from '@tiptap/pm/view';
15
16
  import { createTableContextMenuPlugin } from "../component/Table";
16
17
  export var TableExtension = function TableExtension(_ref) {
17
18
  var editable = _ref.editable;
@@ -173,6 +174,36 @@ export var TableExtension = function TableExtension(_ref) {
173
174
  return editable ? [createTableContextMenuPlugin(this.editor)] : [];
174
175
  }
175
176
  }),
177
+ // 选中表格时为 table 添加聚焦样式类名
178
+ Extension.create({
179
+ name: 'tableActiveClass',
180
+ addProseMirrorPlugins: function addProseMirrorPlugins() {
181
+ if (!editable) return [];
182
+ return [new Plugin({
183
+ props: {
184
+ decorations: function decorations(state) {
185
+ var selection = state.selection,
186
+ doc = state.doc;
187
+ var $from = selection.$from;
188
+ // 如果当前不在表格内,移除装饰
189
+ // 通过向上寻找最近的 table 节点
190
+ for (var depth = $from.depth; depth > 0; depth--) {
191
+ var node = $from.node(depth);
192
+ if (node.type.name === 'table') {
193
+ var from = $from.before(depth);
194
+ var to = $from.after(depth);
195
+ var deco = Decoration.node(from, to, {
196
+ class: 'table-focus'
197
+ });
198
+ return DecorationSet.create(doc, [deco]);
199
+ }
200
+ }
201
+ return null;
202
+ }
203
+ }
204
+ })];
205
+ }
206
+ }),
176
207
  // Safari 中文输入 deleteCompositionText 修复
177
208
  Extension.create({
178
209
  name: 'safariCompositionDeleteFix',
package/dist/index.css CHANGED
@@ -368,19 +368,24 @@
368
368
  }
369
369
 
370
370
  /* 表格悬停时显示所有列边框 - 只在编辑模式下生效 */
371
- .tiptap.ProseMirror[contenteditable="true"] table:hover {
371
+ .tiptap.ProseMirror[contenteditable="true"] table:hover,
372
+ .tiptap.ProseMirror[contenteditable="true"] .table-focus table {
372
373
  border-left: 1px dotted var(--mui-palette-divider);
373
374
  border-right: 1px dotted var(--mui-palette-divider);
374
375
  }
375
376
 
376
377
  .tiptap.ProseMirror[contenteditable="true"] table:hover td,
377
- .tiptap.ProseMirror[contenteditable="true"] table:hover th {
378
+ .tiptap.ProseMirror[contenteditable="true"] table:hover th,
379
+ .tiptap.ProseMirror[contenteditable="true"] .table-focus td,
380
+ .tiptap.ProseMirror[contenteditable="true"] .table-focus th {
378
381
  border-right-color: var(--mui-palette-divider);
379
382
  border-right-style: dotted;
380
383
  }
381
384
 
382
385
  .tiptap.ProseMirror[contenteditable="true"] table:hover td:last-child,
383
- .tiptap.ProseMirror[contenteditable="true"] table:hover th:last-child {
386
+ .tiptap.ProseMirror[contenteditable="true"] table:hover th:last-child,
387
+ .tiptap.ProseMirror[contenteditable="true"] .table-focus td:last-child,
388
+ .tiptap.ProseMirror[contenteditable="true"] .table-focus th:last-child {
384
389
  border-right-color: transparent;
385
390
  }
386
391
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctzhian/tiptap",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "基于 Tiptap 二次开发的编辑器组件",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",