@ctzhian/tiptap 1.1.2 → 1.2.0

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.
@@ -81,7 +81,7 @@ var Reader = function Reader() {
81
81
  }
82
82
  return onUpload;
83
83
  }(),
84
- content: "<blockquote><p>\u98DE\u673A\u554A\u6B7B\u4E86\u6253\u98DE\u673A\u554A\u6536\u5230\u4E86</p></blockquote><p></p>"
84
+ content: "<div class=\"tableWrapper\"><table style=\"min-width: 400px;\"><colgroup><col style=\"min-width: 100px;\"><col style=\"min-width: 100px;\"><col style=\"min-width: 100px;\"><col style=\"min-width: 100px;\"></colgroup><tbody><tr class=\"table-row\"><th class=\"table-header\" colspan=\"1\" rowspan=\"1\"><p>fasldkf</p></th><th class=\"table-header\" colspan=\"1\" rowspan=\"1\"><p>2fdslkajf</p></th><th class=\"table-header\" colspan=\"1\" rowspan=\"1\"><p>fk</p></th><th class=\"table-header\" colspan=\"1\" rowspan=\"1\"><p>fjakdsl fjsdak</p></th></tr><tr class=\"table-row\"><td colspan=\"1\" rowspan=\"1\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>fsafd</p></td><td colspan=\"1\" rowspan=\"1\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>fasdffads</p></td><td colspan=\"1\" rowspan=\"1\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>afsfa</p></td><td colspan=\"1\" rowspan=\"1\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>fasdfa</p></td></tr><tr class=\"table-row\"><td colspan=\"1\" rowspan=\"1\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>afsdfsda</p></td><td colspan=\"1\" rowspan=\"1\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>fdasfas</p></td><td colspan=\"1\" rowspan=\"1\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>dsfasdfadsfa</p></td><td colspan=\"1\" rowspan=\"1\" data-background-color=\"transparent\" style=\"background-color: transparent;\"><p>faffaffddafs fadf fsad</p></td></tr></tbody></table></div><p></p>"
85
85
  }),
86
86
  editor = _useTiptap.editor;
87
87
  return /*#__PURE__*/React.createElement(EditorThemeProvider, {
@@ -45,7 +45,7 @@ var SelectionText = function SelectionText(_ref) {
45
45
  superscript: editor.isActive('superscript'),
46
46
  subscript: editor.isActive('subscript')
47
47
  });
48
- setHideColor(editor.isActive('code') || editor.isActive('codeBlock') || editor.isActive('inlineMath') || editor.isActive('blockMath'));
48
+ setHideColor(editor.isActive('codeBlock') || editor.isActive('inlineMath') || editor.isActive('blockMath'));
49
49
  };
50
50
  useEffect(function () {
51
51
  editor.on('selectionUpdate', updateSelection);
@@ -69,7 +69,7 @@ var SelectionText = function SelectionText(_ref) {
69
69
  var editorProps = _ref2.editor,
70
70
  from = _ref2.from,
71
71
  to = _ref2.to;
72
- if (editorProps.state.selection.empty || editorProps.isActive('code') || editorProps.isActive('image') || editorProps.isActive('video') || editorProps.isActive('audio') || editorProps.isActive('emoji') || editorProps.isActive('codeBlock') || editorProps.isActive('blockLink') || editorProps.isActive('inlineLink') || editorProps.isActive('blockAttachment') || editorProps.isActive('inlineAttachment')) {
72
+ if (editorProps.state.selection.empty || editorProps.isActive('image') || editorProps.isActive('video') || editorProps.isActive('audio') || editorProps.isActive('emoji') || editorProps.isActive('codeBlock') || editorProps.isActive('blockLink') || editorProps.isActive('inlineLink') || editorProps.isActive('blockAttachment') || editorProps.isActive('inlineAttachment')) {
73
73
  return false;
74
74
  }
75
75
  return true;
@@ -1,9 +1,11 @@
1
+ import { Strategy } from '@floating-ui/dom';
1
2
  import React from 'react';
2
3
  export interface FloatingPopoverProps {
3
4
  open: boolean;
4
5
  anchorEl: HTMLElement | null;
5
6
  onClose: () => void;
6
7
  children: React.ReactNode;
8
+ strategy?: Strategy;
7
9
  placement?: 'top' | 'bottom' | 'left' | 'right';
8
10
  offset?: number;
9
11
  className?: string;
@@ -13,11 +13,14 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
13
  import { autoUpdate, computePosition, flip, offset, shift } from '@floating-ui/dom';
14
14
  import { Paper } from '@mui/material';
15
15
  import React, { useEffect, useRef, useState } from 'react';
16
+ import { createPortal } from 'react-dom';
16
17
  export var FloatingPopover = function FloatingPopover(_ref) {
17
18
  var open = _ref.open,
18
19
  anchorEl = _ref.anchorEl,
19
20
  onClose = _ref.onClose,
20
21
  children = _ref.children,
22
+ _ref$strategy = _ref.strategy,
23
+ strategy = _ref$strategy === void 0 ? 'absolute' : _ref$strategy,
21
24
  _ref$placement = _ref.placement,
22
25
  placement = _ref$placement === void 0 ? 'bottom' : _ref$placement,
23
26
  _ref$offset = _ref.offset,
@@ -38,6 +41,7 @@ export var FloatingPopover = function FloatingPopover(_ref) {
38
41
  if (!popoverRef.current) return;
39
42
  computePosition(anchorEl, popoverRef.current, {
40
43
  placement: placement,
44
+ strategy: strategy,
41
45
  middleware: [offset(offsetValue), flip(), shift({
42
46
  padding: 8
43
47
  })]
@@ -78,7 +82,7 @@ export var FloatingPopover = function FloatingPopover(_ref) {
78
82
  };
79
83
  }, [open, onClose, anchorEl]);
80
84
  if (!open) return null;
81
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
85
+ return /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
82
86
  style: {
83
87
  position: 'fixed',
84
88
  top: 0,
@@ -92,13 +96,13 @@ export var FloatingPopover = function FloatingPopover(_ref) {
92
96
  ref: popoverRef,
93
97
  className: className,
94
98
  style: _objectSpread({
95
- position: 'absolute',
99
+ position: strategy,
96
100
  left: position.x,
97
101
  top: position.y,
98
102
  zIndex: 1300,
99
103
  borderRadius: 'var(--mui-shape-borderRadius)'
100
104
  }, style),
101
105
  elevation: 8
102
- }, children));
106
+ }, children)), document.body);
103
107
  };
104
108
  export default FloatingPopover;
@@ -35,7 +35,7 @@ var EditorFontSize = function EditorFontSize(_ref) {
35
35
  var headingLevel = headingAttrs.level;
36
36
  switch (headingLevel) {
37
37
  case 1:
38
- fontSize = '28';
38
+ fontSize = '30';
39
39
  break;
40
40
  case 2:
41
41
  fontSize = '24';
@@ -47,10 +47,10 @@ var EditorFontSize = function EditorFontSize(_ref) {
47
47
  fontSize = '18';
48
48
  break;
49
49
  case 5:
50
- fontSize = '16';
50
+ fontSize = '18';
51
51
  break;
52
52
  case 6:
53
- fontSize = '14';
53
+ fontSize = '16';
54
54
  break;
55
55
  default:
56
56
  fontSize = defaultFontSize;
@@ -94,7 +94,7 @@ var LinkViewWrapper = function LinkViewWrapper(_ref) {
94
94
  };
95
95
  var handleDeleteLink = function handleDeleteLink() {
96
96
  editor.commands.deleteNode(node.type);
97
- editor.commands.insertContent("[".concat(attrs.title || getLinkTitle(attrs.href), "](").concat(attrs.href, ")"));
97
+ editor.commands.insertContent(attrs.title || getLinkTitle(attrs.href));
98
98
  };
99
99
  var handleCopyLink = useCallback( /*#__PURE__*/function () {
100
100
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
@@ -14,6 +14,7 @@ import { CharacterCount, Placeholder } from '@tiptap/extensions';
14
14
  import StarterKit from '@tiptap/starter-kit';
15
15
  import { PLACEHOLDER } from "../contants/placeholder";
16
16
  import { SlashCommands, StructuredDiffExtension } from "./extension";
17
+ import { CodeExtension } from "./mark/Code";
17
18
  import { AlertExtension, AudioExtension, BlockAttachmentExtension, BlockLinkExtension, CodeBlockLowlightExtension, CustomBlockMathExtension, CustomInlineMathExtension, DetailsContentExtension, DetailsExtension, DetailsSummaryExtension, EmojiExtension, FileHandlerExtension, ImageExtension, InlineAttachmentExtension, InlineLinkExtension, ListExtension, MentionExtension, TableExtension, TableOfContents, UploadProgressExtension, VerticalAlign, VideoExtension, YoutubeExtension } from "./node";
18
19
  export var getExtensions = function getExtensions(_ref) {
19
20
  var limit = _ref.limit,
@@ -28,6 +29,7 @@ export var getExtensions = function getExtensions(_ref) {
28
29
  onTocUpdate = _ref.onTocUpdate;
29
30
  var defaultExtensions = [StarterKit.configure({
30
31
  link: false,
32
+ code: false,
31
33
  codeBlock: false,
32
34
  listItem: false,
33
35
  orderedList: false,
@@ -45,7 +47,7 @@ export var getExtensions = function getExtensions(_ref) {
45
47
  defaultAlignment: null
46
48
  }), CodeBlockLowlightExtension, CharacterCount.configure({
47
49
  limit: limit !== null && limit !== void 0 ? limit : null
48
- }), Subscript, Superscript, TextStyleKit, AlertExtension, Highlight.configure({
50
+ }), Subscript, Superscript, TextStyleKit, CodeExtension, AlertExtension, Highlight.configure({
49
51
  multicolor: true
50
52
  }), Placeholder.configure({
51
53
  emptyNodeClass: 'custom-placeholder-node',
@@ -0,0 +1,2 @@
1
+ export declare const CodeExtension: import("@tiptap/core").Mark<import("@tiptap/extension-code").CodeOptions, any>;
2
+ export default CodeExtension;
@@ -0,0 +1,9 @@
1
+ import Code from '@tiptap/extension-code';
2
+
3
+ // 允许与 textStyle 等标记共存,以便字号/颜色等样式可应用到 code 文本
4
+ export var CodeExtension = Code.extend({
5
+ // 默认 `@tiptap/extension-code` 的 excludes 为 '_'(排除所有其他 mark)
6
+ // 这里清空以允许共存,从而让 textStyle 的 fontSize 生效
7
+ excludes: ''
8
+ });
9
+ export default CodeExtension;
package/dist/index.css CHANGED
@@ -331,7 +331,6 @@
331
331
  border-bottom: 1px solid var(--mui-palette-divider);
332
332
  border-right: 1px solid transparent;
333
333
  box-sizing: border-box;
334
- min-width: 1rem;
335
334
  padding: 12px 16px;
336
335
  position: relative;
337
336
  vertical-align: top;
@@ -1,2 +1,3 @@
1
+ import { Strategy } from "@floating-ui/dom";
1
2
  import { Editor } from "@tiptap/core";
2
- export declare const updatePosition: (editor: Editor, element: HTMLElement) => void;
3
+ export declare const updatePosition: (editor: Editor, element: HTMLElement, strategy?: Strategy) => void;
@@ -1,6 +1,7 @@
1
1
  import { computePosition, flip, shift } from "@floating-ui/dom";
2
2
  import { posToDOMRect } from "@tiptap/core";
3
3
  export var updatePosition = function updatePosition(editor, element) {
4
+ var strategy = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'absolute';
4
5
  var virtualElement = {
5
6
  getBoundingClientRect: function getBoundingClientRect() {
6
7
  return posToDOMRect(editor.view, editor.state.selection.from, editor.state.selection.to);
@@ -8,7 +9,7 @@ export var updatePosition = function updatePosition(editor, element) {
8
9
  };
9
10
  computePosition(virtualElement, element, {
10
11
  placement: 'bottom-start',
11
- strategy: 'absolute',
12
+ strategy: strategy,
12
13
  middleware: [shift(), flip()]
13
14
  }).then(function (_ref) {
14
15
  var x = _ref.x,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctzhian/tiptap",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "基于 Tiptap 二次开发的编辑器组件",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -83,6 +83,7 @@
83
83
  "@floating-ui/dom": "^1.7.2",
84
84
  "@tiptap/core": "^3.4.2",
85
85
  "@tiptap/extension-bubble-menu": "^3.4.2",
86
+ "@tiptap/extension-code": "^3.4.3",
86
87
  "@tiptap/extension-code-block-lowlight": "^3.4.2",
87
88
  "@tiptap/extension-details": "^3.4.2",
88
89
  "@tiptap/extension-drag-handle-react": "^3.4.2",