@ctzhian/tiptap 2.11.2 → 2.11.4
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.
|
@@ -7,13 +7,36 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
7
7
|
import { EditLineIcon } from "../../../component/Icons";
|
|
8
8
|
import { Box, Stack, Tooltip } from "@mui/material";
|
|
9
9
|
import { MarkViewContent } from "@tiptap/react";
|
|
10
|
-
import
|
|
11
|
-
import
|
|
10
|
+
import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
11
|
+
import sanitizeHtml from 'sanitize-html';
|
|
12
12
|
import EditPopover from "./EditPopover";
|
|
13
|
+
var SANITIZE_CONFIG = {
|
|
14
|
+
allowedTags: ['p', 'br', 'strong', 'em', 'b', 'i', 'u', 's', 'strike', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ul', 'ol', 'li', 'a', 'span', 'div', 'blockquote', 'code', 'pre'],
|
|
15
|
+
allowedAttributes: {
|
|
16
|
+
a: ['href', 'title', 'target'],
|
|
17
|
+
span: ['style', 'class'],
|
|
18
|
+
div: ['style', 'class'],
|
|
19
|
+
p: ['style', 'class'],
|
|
20
|
+
'*': ['class']
|
|
21
|
+
},
|
|
22
|
+
allowedStyles: {
|
|
23
|
+
'*': {
|
|
24
|
+
color: [/^#[0-9A-Fa-f]{3,6}$/, /^rgb/, /^rgba/],
|
|
25
|
+
'text-align': [/^left$/, /^right$/, /^center$/, /^justify$/],
|
|
26
|
+
'font-size': [/^\d+(?:px|em|rem|%)$/],
|
|
27
|
+
'font-weight': [/^\d+$/, /^normal$/, /^bold$/]
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
disallowedTagsMode: 'discard',
|
|
31
|
+
allowedSchemes: ['http', 'https', 'mailto'],
|
|
32
|
+
allowedSchemesByTag: {
|
|
33
|
+
a: ['http', 'https', 'mailto']
|
|
34
|
+
}
|
|
35
|
+
};
|
|
13
36
|
var TooltipView = function TooltipView(_ref) {
|
|
14
37
|
var mark = _ref.mark,
|
|
15
38
|
editor = _ref.editor;
|
|
16
|
-
var
|
|
39
|
+
var rawTooltip = mark.attrs.tooltip || '';
|
|
17
40
|
var isEditable = editor.isEditable;
|
|
18
41
|
var _useState = useState(false),
|
|
19
42
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -28,6 +51,9 @@ var TooltipView = function TooltipView(_ref) {
|
|
|
28
51
|
isMobile = _useState6[0],
|
|
29
52
|
setIsMobile = _useState6[1];
|
|
30
53
|
var anchorRef = useRef(null);
|
|
54
|
+
var tooltip = useMemo(function () {
|
|
55
|
+
return sanitizeHtml(rawTooltip, SANITIZE_CONFIG).trim();
|
|
56
|
+
}, [rawTooltip]);
|
|
31
57
|
var handleEditClick = function handleEditClick(e) {
|
|
32
58
|
e.stopPropagation();
|
|
33
59
|
setOpen(true);
|
|
@@ -63,7 +89,7 @@ var TooltipView = function TooltipView(_ref) {
|
|
|
63
89
|
if (isEditable && tooltip === '' && !isSelectionEmpty && anchorRef.current) {
|
|
64
90
|
setOpen(true);
|
|
65
91
|
}
|
|
66
|
-
}, [tooltip, isEditable
|
|
92
|
+
}, [tooltip, isEditable]);
|
|
67
93
|
var isMobileReadonly = !isEditable && isMobile;
|
|
68
94
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Tooltip, {
|
|
69
95
|
arrow: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ctzhian/tiptap",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.4",
|
|
4
4
|
"description": "基于 Tiptap 二次开发的编辑器组件",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"@types/diff-match-patch": "^1.0.36",
|
|
67
67
|
"@types/react": "^18.0.0",
|
|
68
68
|
"@types/react-dom": "^18.0.0",
|
|
69
|
+
"@types/sanitize-html": "^2.16.0",
|
|
69
70
|
"@umijs/lint": "^4.0.0",
|
|
70
71
|
"dumi": "^2.4.21",
|
|
71
72
|
"eslint": "^8.23.0",
|
|
@@ -118,7 +119,6 @@
|
|
|
118
119
|
"core-js": "^3.46.0",
|
|
119
120
|
"diff-match-patch": "^1.0.5",
|
|
120
121
|
"highlight.js": "^11.11.1",
|
|
121
|
-
"isomorphic-dompurify": "^2.34.0",
|
|
122
122
|
"jszip": "^3.10.1",
|
|
123
123
|
"katex": "^0.16.22",
|
|
124
124
|
"linkifyjs": "^4.3.2",
|
|
@@ -128,6 +128,7 @@
|
|
|
128
128
|
"react-colorful": "^5.6.1",
|
|
129
129
|
"react-image-crop": "^11.0.10",
|
|
130
130
|
"react-photo-view": "^1.2.7",
|
|
131
|
+
"sanitize-html": "^2.17.0",
|
|
131
132
|
"uuid": "^11.1.0"
|
|
132
133
|
},
|
|
133
134
|
"scripts": {
|