@ctzhian/tiptap 1.4.2 → 1.5.1
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.
- package/dist/component/CustomDragHandle/index.js +380 -264
- package/dist/component/FloatingPopover/index.d.ts +2 -2
- package/dist/component/FloatingPopover/index.js +7 -2
- package/dist/component/Icons/add-line-icon.d.ts +6 -0
- package/dist/component/Icons/add-line-icon.js +13 -0
- package/dist/component/Icons/indent-decrease-icon.d.ts +6 -0
- package/dist/component/Icons/indent-decrease-icon.js +13 -0
- package/dist/component/Icons/indent-increase-icon.d.ts +6 -0
- package/dist/component/Icons/indent-increase-icon.js +13 -0
- package/dist/component/Icons/index.d.ts +3 -0
- package/dist/component/Icons/index.js +3 -0
- package/dist/extension/component/Alert/index.js +2 -0
- package/dist/extension/component/Link/index.js +1 -1
- package/dist/extension/component/SlashCommandsList/Overlay.d.ts +10 -0
- package/dist/extension/component/SlashCommandsList/Overlay.js +26 -0
- package/dist/extension/component/SlashCommandsList/index.js +2 -4
- package/dist/extension/index.js +12 -2
- package/dist/extension/node/Indent.d.ts +17 -0
- package/dist/extension/node/Indent.js +103 -0
- package/dist/extension/node/Table.d.ts +1 -1
- package/dist/extension/node/index.d.ts +1 -0
- package/dist/extension/node/index.js +1 -0
- package/dist/extension/suggestion/slash.d.ts +8 -4
- package/dist/extension/suggestion/slash.js +46 -16
- package/dist/index.css +47 -0
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Strategy } from '@floating-ui/dom';
|
|
1
|
+
import { Strategy, VirtualElement } from '@floating-ui/dom';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
export interface FloatingPopoverProps {
|
|
4
4
|
open: boolean;
|
|
5
|
-
anchorEl: HTMLElement | null;
|
|
5
|
+
anchorEl: HTMLElement | VirtualElement | null;
|
|
6
6
|
onClose: () => void;
|
|
7
7
|
children: React.ReactNode;
|
|
8
8
|
strategy?: Strategy;
|
|
@@ -70,8 +70,12 @@ export var FloatingPopover = function FloatingPopover(_ref) {
|
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
var handleClickOutside = function handleClickOutside(event) {
|
|
73
|
-
if (popoverRef.current && !popoverRef.current.contains(event.target)
|
|
74
|
-
|
|
73
|
+
if (popoverRef.current && !popoverRef.current.contains(event.target)) {
|
|
74
|
+
// 仅当锚点为真实元素时,才检测是否点击在锚点上
|
|
75
|
+
var isHitAnchor = anchorEl instanceof HTMLElement && anchorEl.contains(event.target);
|
|
76
|
+
if (!isHitAnchor) {
|
|
77
|
+
onClose();
|
|
78
|
+
}
|
|
75
79
|
}
|
|
76
80
|
};
|
|
77
81
|
document.addEventListener('keydown', handleEscape);
|
|
@@ -100,6 +104,7 @@ export var FloatingPopover = function FloatingPopover(_ref) {
|
|
|
100
104
|
left: position.x,
|
|
101
105
|
top: position.y,
|
|
102
106
|
zIndex: 1300,
|
|
107
|
+
boxShadow: 'var(--mui-shadows-1)',
|
|
103
108
|
borderRadius: 'var(--mui-shape-borderRadius)'
|
|
104
109
|
}, style),
|
|
105
110
|
elevation: 8
|
|
@@ -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 AddLineIcon = function AddLineIcon(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: "M11 11V5H13V11H19V13H13V19H11V13H5V11H11Z"
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
AddLineIcon.displayName = 'icon-add-line';
|
|
@@ -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 IndentDecreaseIcon = function IndentDecreaseIcon(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: "M3 4H21V6H3V4ZM3 19H21V21H3V19ZM11 14H21V16H11V14ZM11 9H21V11H11V9ZM3 12.5L7 9V16L3 12.5Z"
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
IndentDecreaseIcon.displayName = 'icon-indent-decrease';
|
|
@@ -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 IndentIncreaseIcon = function IndentIncreaseIcon(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: "M3 4H21V6H3V4ZM3 19H21V21H3V19ZM11 14H21V16H11V14ZM11 9H21V11H11V9ZM7 12.5L3 16V9L7 12.5Z"
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
IndentIncreaseIcon.displayName = 'icon-indent-increase';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { AddLineIcon } from './add-line-icon';
|
|
1
2
|
export { AiGenerate2Icon } from './ai-generate-2-icon';
|
|
2
3
|
export { AiGenerateTextIcon } from './ai-generate-text-icon';
|
|
3
4
|
export { AlignBottomIcon } from './align-bottom-icon';
|
|
@@ -59,6 +60,8 @@ export { HeadingIcon } from './heading-icon';
|
|
|
59
60
|
export { ImageAddLineIcon } from './image-add-line-icon';
|
|
60
61
|
export { ImageLineIcon } from './image-line-icon';
|
|
61
62
|
export { ImportLineIcon } from './import-line-icon';
|
|
63
|
+
export { IndentDecreaseIcon } from './indent-decrease-icon';
|
|
64
|
+
export { IndentIncreaseIcon } from './indent-increase-icon';
|
|
62
65
|
export { Information2FillIcon } from './information-2-fill-icon';
|
|
63
66
|
export { Information2LineIcon } from './information-2-line-icon';
|
|
64
67
|
export { InsertColumnLeftIcon } from './insert-column-left-icon';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// 此文件由脚本自动生成
|
|
2
2
|
// 导出所有图标组件
|
|
3
3
|
|
|
4
|
+
export { AddLineIcon } from "./add-line-icon";
|
|
4
5
|
export { AiGenerate2Icon } from "./ai-generate-2-icon";
|
|
5
6
|
export { AiGenerateTextIcon } from "./ai-generate-text-icon";
|
|
6
7
|
export { AlignBottomIcon } from "./align-bottom-icon";
|
|
@@ -62,6 +63,8 @@ export { HeadingIcon } from "./heading-icon";
|
|
|
62
63
|
export { ImageAddLineIcon } from "./image-add-line-icon";
|
|
63
64
|
export { ImageLineIcon } from "./image-line-icon";
|
|
64
65
|
export { ImportLineIcon } from "./import-line-icon";
|
|
66
|
+
export { IndentDecreaseIcon } from "./indent-decrease-icon";
|
|
67
|
+
export { IndentIncreaseIcon } from "./indent-increase-icon";
|
|
65
68
|
export { Information2FillIcon } from "./information-2-fill-icon";
|
|
66
69
|
export { Information2LineIcon } from "./information-2-line-icon";
|
|
67
70
|
export { InsertColumnLeftIcon } from "./insert-column-left-icon";
|
|
@@ -45,6 +45,7 @@ var VARIANT_DATA = {
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
var AlertView = function AlertView(_ref) {
|
|
48
|
+
var _node$attrs;
|
|
48
49
|
var editor = _ref.editor,
|
|
49
50
|
node = _ref.node,
|
|
50
51
|
updateAttributes = _ref.updateAttributes,
|
|
@@ -71,6 +72,7 @@ var AlertView = function AlertView(_ref) {
|
|
|
71
72
|
"data-drag-handle": true,
|
|
72
73
|
as: 'div',
|
|
73
74
|
style: {
|
|
75
|
+
marginLeft: (_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.indent ? node.attrs.indent * 32 : undefined,
|
|
74
76
|
border: '1px solid',
|
|
75
77
|
borderColor: variantData.color,
|
|
76
78
|
color: variantData.color,
|
|
@@ -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(attrs.title ||
|
|
97
|
+
editor.commands.insertContent(attrs.title || attrs.href);
|
|
98
98
|
};
|
|
99
99
|
var handleCopyLink = useCallback( /*#__PURE__*/function () {
|
|
100
100
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SlashCommandsListRef } from "../../../type";
|
|
2
|
+
import { SuggestionProps } from '@tiptap/suggestion';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
export type SlashCommandsOverlayProps = SuggestionProps<any> & {
|
|
5
|
+
open: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare const SlashCommandsOverlay: React.ForwardRefExoticComponent<SuggestionProps<any, any> & {
|
|
8
|
+
open: boolean;
|
|
9
|
+
} & React.RefAttributes<SlashCommandsListRef>>;
|
|
10
|
+
export default SlashCommandsOverlay;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FloatingPopover } from "../../../component";
|
|
2
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
3
|
+
import SlashCommandsList from "./index";
|
|
4
|
+
var SlashCommandsOverlay = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
5
|
+
var anchorEl = useMemo(function () {
|
|
6
|
+
if (!props.clientRect) return null;
|
|
7
|
+
return {
|
|
8
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
9
|
+
return props.clientRect();
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}, [props.clientRect]);
|
|
13
|
+
return /*#__PURE__*/React.createElement(FloatingPopover, {
|
|
14
|
+
open: Boolean(props.open && anchorEl),
|
|
15
|
+
anchorEl: anchorEl,
|
|
16
|
+
onClose: function onClose() {/* 由外部生命周期控制关闭 */},
|
|
17
|
+
placement: "bottom"
|
|
18
|
+
}, /*#__PURE__*/React.createElement(SlashCommandsList, {
|
|
19
|
+
ref: ref,
|
|
20
|
+
items: props.items,
|
|
21
|
+
command: props.command,
|
|
22
|
+
editor: props.editor
|
|
23
|
+
}));
|
|
24
|
+
});
|
|
25
|
+
SlashCommandsOverlay.displayName = 'SlashCommandsOverlay';
|
|
26
|
+
export default SlashCommandsOverlay;
|
|
@@ -8,7 +8,7 @@ import { NestedList } from "../../../component";
|
|
|
8
8
|
import { ArrowDownSLineIcon, AttachmentLineIcon, CheckboxCircleFillIcon, CloseCircleFillIcon, ErrorWarningFillIcon, FormulaIcon, FunctionsIcon, ImageLineIcon, Information2FillIcon, Information2LineIcon, MovieLineIcon, Music2LineIcon, SquareRootIcon, Table2Icon, UploadIcon } from "../../../component/Icons";
|
|
9
9
|
import { ToolbarItem } from "../../../component/Toolbar";
|
|
10
10
|
import TableSizePicker from "../../../component/Toolbar/TableSizePicker";
|
|
11
|
-
import {
|
|
11
|
+
import { Box, Divider, Stack } from '@mui/material';
|
|
12
12
|
import React, { forwardRef } from 'react';
|
|
13
13
|
var SlashCommandsList = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
14
14
|
var items = _ref.items,
|
|
@@ -16,10 +16,8 @@ var SlashCommandsList = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
16
16
|
if (items.length === 0) {
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
|
-
return /*#__PURE__*/React.createElement(
|
|
20
|
-
elevation: 8,
|
|
19
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
21
20
|
sx: {
|
|
22
|
-
borderRadius: 'var(--mui-shape-borderRadius)',
|
|
23
21
|
width: '224px',
|
|
24
22
|
p: 0.5
|
|
25
23
|
}
|
package/dist/extension/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import StarterKit from '@tiptap/starter-kit';
|
|
|
15
15
|
import { PLACEHOLDER } from "../contants/placeholder";
|
|
16
16
|
import { SlashCommands, StructuredDiffExtension } from "./extension";
|
|
17
17
|
import { CodeExtension } from "./mark/Code";
|
|
18
|
-
import { AlertExtension, AudioExtension, BlockAttachmentExtension, BlockLinkExtension, CodeBlockLowlightExtension, CustomBlockMathExtension, CustomInlineMathExtension, DetailsContentExtension, DetailsExtension, DetailsSummaryExtension, EmojiExtension, FileHandlerExtension, IframeExtension, ImageExtension, InlineAttachmentExtension, InlineLinkExtension, ListExtension, MentionExtension, TableExtension, TableOfContents, UploadProgressExtension, VerticalAlign, VideoExtension, YoutubeExtension } from "./node";
|
|
18
|
+
import { AlertExtension, AudioExtension, BlockAttachmentExtension, BlockLinkExtension, CodeBlockLowlightExtension, CustomBlockMathExtension, CustomInlineMathExtension, DetailsContentExtension, DetailsExtension, DetailsSummaryExtension, EmojiExtension, FileHandlerExtension, IframeExtension, ImageExtension, Indent, InlineAttachmentExtension, InlineLinkExtension, ListExtension, MentionExtension, TableExtension, TableOfContents, UploadProgressExtension, VerticalAlign, VideoExtension, YoutubeExtension } from "./node";
|
|
19
19
|
export var getExtensions = function getExtensions(_ref) {
|
|
20
20
|
var limit = _ref.limit,
|
|
21
21
|
exclude = _ref.exclude,
|
|
@@ -47,7 +47,17 @@ export var getExtensions = function getExtensions(_ref) {
|
|
|
47
47
|
defaultAlignment: null
|
|
48
48
|
}), CodeBlockLowlightExtension, CharacterCount.configure({
|
|
49
49
|
limit: limit !== null && limit !== void 0 ? limit : null
|
|
50
|
-
}), Subscript, Superscript, TextStyleKit,
|
|
50
|
+
}), Subscript, Superscript, TextStyleKit, Indent.configure({
|
|
51
|
+
types: [
|
|
52
|
+
// 常见块级与项目中定义的节点
|
|
53
|
+
'paragraph', 'heading', 'blockquote', 'alert', 'codeBlock', 'horizontalRule', 'orderedList', 'bulletList', 'taskList', 'taskItem', 'listItem', 'details', 'detailsContent', 'detailsSummary', 'table', 'image', 'video', 'audio', 'iframe', 'blockAttachment', 'inlineAttachment', 'blockLink',
|
|
54
|
+
// 公式
|
|
55
|
+
'blockMath', 'inlineMath'
|
|
56
|
+
// 扩展里还有:youtube 等,如需也可开启
|
|
57
|
+
],
|
|
58
|
+
maxLevel: 8,
|
|
59
|
+
indentPx: 32
|
|
60
|
+
}), CodeExtension, AlertExtension, Highlight.configure({
|
|
51
61
|
multicolor: true
|
|
52
62
|
}), Placeholder.configure({
|
|
53
63
|
emptyNodeClass: 'custom-placeholder-node',
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
export interface IndentOptions {
|
|
3
|
+
types: string[];
|
|
4
|
+
maxLevel: number;
|
|
5
|
+
indentPx: number;
|
|
6
|
+
}
|
|
7
|
+
declare module '@tiptap/core' {
|
|
8
|
+
interface Commands<ReturnType> {
|
|
9
|
+
indent: {
|
|
10
|
+
setIndent: (level: number) => ReturnType;
|
|
11
|
+
increaseIndent: () => ReturnType;
|
|
12
|
+
decreaseIndent: () => ReturnType;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export declare const Indent: Extension<IndentOptions, any>;
|
|
17
|
+
export default Indent;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
export var Indent = Extension.create({
|
|
3
|
+
name: 'indent',
|
|
4
|
+
addOptions: function addOptions() {
|
|
5
|
+
return {
|
|
6
|
+
// 若为 [], 则对所有节点类型生效
|
|
7
|
+
types: [],
|
|
8
|
+
maxLevel: 8,
|
|
9
|
+
indentPx: 24
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
addGlobalAttributes: function addGlobalAttributes() {
|
|
13
|
+
var _this = this,
|
|
14
|
+
_editorInstance$schem;
|
|
15
|
+
var descriptor = {
|
|
16
|
+
attributes: {
|
|
17
|
+
indent: {
|
|
18
|
+
default: 0,
|
|
19
|
+
parseHTML: function parseHTML(element) {
|
|
20
|
+
var data = element.getAttribute('data-indent');
|
|
21
|
+
if (data) return parseInt(data, 10) || 0;
|
|
22
|
+
var style = element.style.marginLeft;
|
|
23
|
+
if (!style) return 0;
|
|
24
|
+
var match = style.match(/(\d+)(px|em|rem)/);
|
|
25
|
+
if (!match) return 0;
|
|
26
|
+
var val = parseInt(match[1], 10);
|
|
27
|
+
return isNaN(val) ? 0 : Math.round(val / _this.options.indentPx);
|
|
28
|
+
},
|
|
29
|
+
renderHTML: function renderHTML(attributes) {
|
|
30
|
+
var level = Number(attributes.indent) || 0;
|
|
31
|
+
if (!level) return {};
|
|
32
|
+
var px = level * _this.options.indentPx;
|
|
33
|
+
return {
|
|
34
|
+
'data-indent': String(level),
|
|
35
|
+
style: "margin-left: ".concat(px, "px;")
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var editorInstance = this.editor;
|
|
42
|
+
var typesList = this.options.types && this.options.types.length > 0 ? this.options.types : Object.keys((editorInstance === null || editorInstance === void 0 || (_editorInstance$schem = editorInstance.schema) === null || _editorInstance$schem === void 0 ? void 0 : _editorInstance$schem.nodes) || {});
|
|
43
|
+
descriptor.types = typesList;
|
|
44
|
+
return [descriptor];
|
|
45
|
+
},
|
|
46
|
+
addCommands: function addCommands() {
|
|
47
|
+
var _this2 = this;
|
|
48
|
+
return {
|
|
49
|
+
setIndent: function setIndent(level) {
|
|
50
|
+
return function (_ref) {
|
|
51
|
+
var _selection$node, _selection$$from;
|
|
52
|
+
var commands = _ref.commands,
|
|
53
|
+
editor = _ref.editor;
|
|
54
|
+
var _ref2 = editor.state,
|
|
55
|
+
selection = _ref2.selection;
|
|
56
|
+
var nodeTypeName = (selection === null || selection === void 0 || (_selection$node = selection.node) === null || _selection$node === void 0 || (_selection$node = _selection$node.type) === null || _selection$node === void 0 ? void 0 : _selection$node.name) || (selection === null || selection === void 0 || (_selection$$from = selection.$from) === null || _selection$$from === void 0 || (_selection$$from = _selection$$from.parent) === null || _selection$$from === void 0 || (_selection$$from = _selection$$from.type) === null || _selection$$from === void 0 ? void 0 : _selection$$from.name);
|
|
57
|
+
if (!nodeTypeName) return false;
|
|
58
|
+
var next = Math.max(0, Math.min(level, _this2.options.maxLevel));
|
|
59
|
+
return commands.updateAttributes(nodeTypeName, {
|
|
60
|
+
indent: next
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
increaseIndent: function increaseIndent() {
|
|
65
|
+
return function (_ref3) {
|
|
66
|
+
var _selection$node2, _selection$$from2;
|
|
67
|
+
var commands = _ref3.commands,
|
|
68
|
+
editor = _ref3.editor;
|
|
69
|
+
var _ref4 = editor.state,
|
|
70
|
+
selection = _ref4.selection;
|
|
71
|
+
var nodeTypeName = (selection === null || selection === void 0 || (_selection$node2 = selection.node) === null || _selection$node2 === void 0 || (_selection$node2 = _selection$node2.type) === null || _selection$node2 === void 0 ? void 0 : _selection$node2.name) || (selection === null || selection === void 0 || (_selection$$from2 = selection.$from) === null || _selection$$from2 === void 0 || (_selection$$from2 = _selection$$from2.parent) === null || _selection$$from2 === void 0 || (_selection$$from2 = _selection$$from2.type) === null || _selection$$from2 === void 0 ? void 0 : _selection$$from2.name);
|
|
72
|
+
if (!nodeTypeName) return false;
|
|
73
|
+
var attrs = editor.getAttributes(nodeTypeName);
|
|
74
|
+
var current = Number(attrs.indent) || 0;
|
|
75
|
+
var next = Math.max(0, Math.min(current + 1, _this2.options.maxLevel));
|
|
76
|
+
if (next === current) return false;
|
|
77
|
+
return commands.updateAttributes(nodeTypeName, {
|
|
78
|
+
indent: next
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
decreaseIndent: function decreaseIndent() {
|
|
83
|
+
return function (_ref5) {
|
|
84
|
+
var _selection$node3, _selection$$from3;
|
|
85
|
+
var commands = _ref5.commands,
|
|
86
|
+
editor = _ref5.editor;
|
|
87
|
+
var _ref6 = editor.state,
|
|
88
|
+
selection = _ref6.selection;
|
|
89
|
+
var nodeTypeName = (selection === null || selection === void 0 || (_selection$node3 = selection.node) === null || _selection$node3 === void 0 || (_selection$node3 = _selection$node3.type) === null || _selection$node3 === void 0 ? void 0 : _selection$node3.name) || (selection === null || selection === void 0 || (_selection$$from3 = selection.$from) === null || _selection$$from3 === void 0 || (_selection$$from3 = _selection$$from3.parent) === null || _selection$$from3 === void 0 || (_selection$$from3 = _selection$$from3.type) === null || _selection$$from3 === void 0 ? void 0 : _selection$$from3.name);
|
|
90
|
+
if (!nodeTypeName) return false;
|
|
91
|
+
var attrs = editor.getAttributes(nodeTypeName);
|
|
92
|
+
var current = Number(attrs.indent) || 0;
|
|
93
|
+
var next = Math.max(0, Math.min(current - 1, _this2.options.maxLevel));
|
|
94
|
+
if (next === current) return false;
|
|
95
|
+
return commands.updateAttributes(nodeTypeName, {
|
|
96
|
+
indent: next
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
export default Indent;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/core';
|
|
2
2
|
export declare const TableExtension: ({ editable }: {
|
|
3
3
|
editable: boolean;
|
|
4
|
-
}) => (import("@tiptap/core").Node<import("@tiptap/extension-table").TableOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableHeaderOptions, any>
|
|
4
|
+
}) => (Extension<any, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableHeaderOptions, any>)[];
|
|
5
5
|
export default TableExtension;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import type { Editor } from "../../type";
|
|
2
3
|
import { SuggestionProps } from '@tiptap/suggestion';
|
|
3
4
|
export declare const slashSuggestion: () => {
|
|
4
5
|
items: ({ query }: {
|
|
@@ -7,7 +8,7 @@ export declare const slashSuggestion: () => {
|
|
|
7
8
|
title: string;
|
|
8
9
|
icon: import("react").JSX.Element;
|
|
9
10
|
command: ({ editor, range, attrs }: {
|
|
10
|
-
editor:
|
|
11
|
+
editor: Editor;
|
|
11
12
|
range: {
|
|
12
13
|
from: number;
|
|
13
14
|
to: number;
|
|
@@ -15,8 +16,11 @@ export declare const slashSuggestion: () => {
|
|
|
15
16
|
attrs: any;
|
|
16
17
|
}) => void;
|
|
17
18
|
}[];
|
|
19
|
+
decorationTag: string;
|
|
20
|
+
decorationClass: string;
|
|
21
|
+
decorationContent: string;
|
|
18
22
|
command: ({ editor, range, props }: {
|
|
19
|
-
editor:
|
|
23
|
+
editor: Editor;
|
|
20
24
|
range: {
|
|
21
25
|
from: number;
|
|
22
26
|
to: number;
|
|
@@ -25,11 +29,11 @@ export declare const slashSuggestion: () => {
|
|
|
25
29
|
}) => void;
|
|
26
30
|
render: () => {
|
|
27
31
|
onStart: (props: SuggestionProps<any>) => void;
|
|
28
|
-
onUpdate(props: SuggestionProps<any>):
|
|
32
|
+
onUpdate(props: SuggestionProps<any>): false | undefined;
|
|
29
33
|
onKeyDown(props: {
|
|
30
34
|
event: KeyboardEvent;
|
|
31
35
|
}): boolean;
|
|
32
|
-
onExit():
|
|
36
|
+
onExit(): false | undefined;
|
|
33
37
|
};
|
|
34
38
|
};
|
|
35
39
|
export default slashSuggestion;
|
|
@@ -1,17 +1,24 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
1
7
|
import { slashCommands } from "../../contants/slash-commands";
|
|
2
|
-
import { updatePosition } from "../../util";
|
|
3
8
|
import { ReactRenderer } from '@tiptap/react';
|
|
4
|
-
import
|
|
9
|
+
import SlashCommandsOverlay from "../component/SlashCommandsList/Overlay";
|
|
5
10
|
export var slashSuggestion = function slashSuggestion() {
|
|
6
11
|
return {
|
|
7
12
|
items: function items(_ref) {
|
|
8
13
|
var query = _ref.query;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
});
|
|
14
|
+
return slashCommands;
|
|
15
|
+
// const commands = slashCommands
|
|
16
|
+
// if (!query) return commands
|
|
17
|
+
// return commands.filter(item => item.title.toLowerCase().includes(query.toLowerCase()))
|
|
14
18
|
},
|
|
19
|
+
decorationTag: 'span',
|
|
20
|
+
decorationClass: 'slash-decoration',
|
|
21
|
+
decorationContent: '插入',
|
|
15
22
|
command: function command(_ref2) {
|
|
16
23
|
var editor = _ref2.editor,
|
|
17
24
|
range = _ref2.range,
|
|
@@ -24,23 +31,38 @@ export var slashSuggestion = function slashSuggestion() {
|
|
|
24
31
|
},
|
|
25
32
|
render: function render() {
|
|
26
33
|
var component = null;
|
|
34
|
+
var lastProps = null;
|
|
35
|
+
var isCaretAfterSlash = function isCaretAfterSlash(editor) {
|
|
36
|
+
try {
|
|
37
|
+
var pos = editor.state.selection.from;
|
|
38
|
+
if (pos <= 1) return false;
|
|
39
|
+
var char = editor.state.doc.textBetween(pos - 1, pos, '\n', '\n');
|
|
40
|
+
return char === '/';
|
|
41
|
+
} catch (_unused) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
27
45
|
return {
|
|
28
46
|
onStart: function onStart(props) {
|
|
29
|
-
|
|
30
|
-
|
|
47
|
+
lastProps = props;
|
|
48
|
+
var shouldOpen = !props.query || props.query.length === 0;
|
|
49
|
+
component = new ReactRenderer(SlashCommandsOverlay, {
|
|
50
|
+
props: _objectSpread(_objectSpread({}, props), {}, {
|
|
51
|
+
open: shouldOpen
|
|
52
|
+
}),
|
|
31
53
|
editor: props.editor
|
|
32
54
|
});
|
|
33
55
|
if (!props.clientRect) return;
|
|
34
56
|
var element = component.element;
|
|
35
|
-
element.style.position = 'absolute';
|
|
36
57
|
document.body.appendChild(element);
|
|
37
|
-
updatePosition(props.editor, element);
|
|
38
58
|
},
|
|
39
59
|
onUpdate: function onUpdate(props) {
|
|
40
|
-
if (!component) return;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
60
|
+
if (!component) return false;
|
|
61
|
+
lastProps = props;
|
|
62
|
+
var shouldOpen = !props.query || props.query.length === 0;
|
|
63
|
+
component.updateProps(_objectSpread(_objectSpread({}, props), {}, {
|
|
64
|
+
open: shouldOpen
|
|
65
|
+
}));
|
|
44
66
|
},
|
|
45
67
|
onKeyDown: function onKeyDown(props) {
|
|
46
68
|
var _component$ref;
|
|
@@ -53,7 +75,15 @@ export var slashSuggestion = function slashSuggestion() {
|
|
|
53
75
|
return ((_component$ref = component.ref) === null || _component$ref === void 0 ? void 0 : _component$ref.onKeyDown(props)) || false;
|
|
54
76
|
},
|
|
55
77
|
onExit: function onExit() {
|
|
56
|
-
|
|
78
|
+
var _lastProps;
|
|
79
|
+
if (!component) return false;
|
|
80
|
+
var editor = (_lastProps = lastProps) === null || _lastProps === void 0 ? void 0 : _lastProps.editor;
|
|
81
|
+
if (editor && isCaretAfterSlash(editor)) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
component.updateProps({
|
|
85
|
+
open: false
|
|
86
|
+
});
|
|
57
87
|
component.destroy();
|
|
58
88
|
component.element.remove();
|
|
59
89
|
}
|
package/dist/index.css
CHANGED
|
@@ -6,6 +6,39 @@
|
|
|
6
6
|
color: var(--mui-palette-text-secondary);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
/* 节点缩进(依赖 data-indent 属性) */
|
|
10
|
+
.tiptap.ProseMirror [data-indent="1"] {
|
|
11
|
+
margin-left: 32px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.tiptap.ProseMirror [data-indent="2"] {
|
|
15
|
+
margin-left: 64px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.tiptap.ProseMirror [data-indent="3"] {
|
|
19
|
+
margin-left: 96px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.tiptap.ProseMirror [data-indent="4"] {
|
|
23
|
+
margin-left: 128px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.tiptap.ProseMirror [data-indent="5"] {
|
|
27
|
+
margin-left: 160px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.tiptap.ProseMirror [data-indent="6"] {
|
|
31
|
+
margin-left: 192px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.tiptap.ProseMirror [data-indent="7"] {
|
|
35
|
+
margin-left: 224px;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.tiptap.ProseMirror [data-indent="8"] {
|
|
39
|
+
margin-left: 256px;
|
|
40
|
+
}
|
|
41
|
+
|
|
9
42
|
.tiptap.ProseMirror[contenteditable="false"] {
|
|
10
43
|
padding: 0;
|
|
11
44
|
}
|
|
@@ -505,4 +538,18 @@
|
|
|
505
538
|
|
|
506
539
|
.PhotoView-Slider__BannerWrap {
|
|
507
540
|
background-color: rgba(33, 34, 45, 0.2) !important;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
.slash-decoration[data-decoration-content].is-empty {
|
|
544
|
+
padding: 4px 8px;
|
|
545
|
+
background-color: var(--mui-palette-background-paper2);
|
|
546
|
+
border-radius: var(--mui-shape-borderRadius);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
.slash-decoration[data-decoration-content].is-empty::after {
|
|
550
|
+
content: attr(data-decoration-content);
|
|
551
|
+
color: var(--mui-palette-text-disabled);
|
|
552
|
+
padding-left: 0.25rem;
|
|
553
|
+
font-size: 14px;
|
|
554
|
+
line-height: 24px;
|
|
508
555
|
}
|