reactjs-tiptap-editor-pro 0.2.29 → 0.2.31
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/package.json +5 -58
- package/src/components/ActionButton.tsx +103 -0
- package/src/components/ActionMenuButton.tsx +76 -0
- package/src/components/BubbleMenu.tsx +93 -0
- package/src/components/CharactorCount.tsx +50 -0
- package/src/components/ColorPicker.tsx +272 -0
- package/src/components/RichTextEditor.tsx +212 -0
- package/src/components/SizeSetter/SizeSetter.tsx +102 -0
- package/src/components/Toolbar.tsx +108 -0
- package/src/components/icons/Activity.tsx +19 -0
- package/src/components/icons/Animas.tsx +24 -0
- package/src/components/icons/AspectRatio.tsx +13 -0
- package/src/components/icons/Blockquote.tsx +17 -0
- package/src/components/icons/ColumnAddLeft.tsx +7 -0
- package/src/components/icons/ColumnAddRight.tsx +7 -0
- package/src/components/icons/DeleteColumn.tsx +26 -0
- package/src/components/icons/DeleteRow.tsx +26 -0
- package/src/components/icons/Direction.tsx +7 -0
- package/src/components/icons/Excalidraw.tsx +7 -0
- package/src/components/icons/ExportPdf.tsx +8 -0
- package/src/components/icons/ExportWord.tsx +24 -0
- package/src/components/icons/FileWordOutline.tsx +13 -0
- package/src/components/icons/Flag.tsx +19 -0
- package/src/components/icons/Food.tsx +20 -0
- package/src/components/icons/GIfIcon.tsx +10 -0
- package/src/components/icons/Icon.tsx +30 -0
- package/src/components/icons/ImportWord.tsx +23 -0
- package/src/components/icons/LeftToRight.tsx +7 -0
- package/src/components/icons/LineHeight.tsx +13 -0
- package/src/components/icons/MenuDown.tsx +24 -0
- package/src/components/icons/Mermaid.tsx +13 -0
- package/src/components/icons/NoFill.tsx +7 -0
- package/src/components/icons/Object.tsx +24 -0
- package/src/components/icons/RightToLeft.tsx +7 -0
- package/src/components/icons/SizeL.tsx +9 -0
- package/src/components/icons/SizeM.tsx +13 -0
- package/src/components/icons/SizeS.tsx +13 -0
- package/src/components/icons/Symbol.tsx +19 -0
- package/src/components/icons/Travel.tsx +24 -0
- package/src/components/icons/Twitter.tsx +7 -0
- package/src/components/icons/icons.ts +212 -0
- package/src/components/icons/index.ts +12 -0
- package/src/components/index.ts +9 -0
- package/src/components/menus/bubble.ts +395 -0
- package/src/components/menus/components/BubbleMenuContent.tsx +15 -0
- package/src/components/menus/components/BubbleMenuDrawer.tsx +128 -0
- package/src/components/menus/components/BubbleMenuExcalidraw.tsx +91 -0
- package/src/components/menus/components/BubbleMenuIframe.tsx +143 -0
- package/src/components/menus/components/BubbleMenuKatex.tsx +136 -0
- package/src/components/menus/components/BubbleMenuLink.tsx +99 -0
- package/src/components/menus/components/BubbleMenuMedia.tsx +235 -0
- package/src/components/menus/components/BubbleMenuMermaid.tsx +128 -0
- package/src/components/menus/components/BubbleMenuText.tsx +102 -0
- package/src/components/menus/components/BubbleMenuTwitter.tsx +91 -0
- package/src/components/menus/components/ColumnsBubbleMenu.tsx +59 -0
- package/src/components/menus/components/ContentMenu.tsx +396 -0
- package/src/components/menus/components/TableBubbleMenu.tsx +362 -0
- package/src/components/menus/index.ts +7 -0
- package/src/components/ui/button.tsx +56 -0
- package/src/components/ui/checkbox.tsx +30 -0
- package/src/components/ui/dialog.tsx +128 -0
- package/src/components/ui/dropdown-menu.tsx +203 -0
- package/src/components/ui/emoji-picker.tsx +166 -0
- package/src/components/ui/index.ts +14 -0
- package/src/components/ui/input.tsx +25 -0
- package/src/components/ui/label.tsx +26 -0
- package/src/components/ui/popover.tsx +31 -0
- package/src/components/ui/select.tsx +162 -0
- package/src/components/ui/separator.tsx +31 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/tabs.tsx +55 -0
- package/src/components/ui/textarea.tsx +24 -0
- package/src/components/ui/toast.tsx +129 -0
- package/src/components/ui/toaster.tsx +44 -0
- package/src/components/ui/toggle.tsx +45 -0
- package/src/components/ui/tooltip.tsx +30 -0
- package/src/components/ui/use-toast.ts +197 -0
- package/src/constants/index.ts +223 -0
- package/src/constants/resetCSS.ts +139 -0
- package/src/extension-bundle.ts +2 -0
- package/src/extensions/Attachment/Attachment.ts +144 -0
- package/src/extensions/Attachment/components/NodeViewAttachment/FileIcon.tsx +69 -0
- package/src/extensions/Attachment/components/NodeViewAttachment/FileIconString.ts +28 -0
- package/src/extensions/Attachment/components/NodeViewAttachment/NodeViewAttachment.tsx +155 -0
- package/src/extensions/Attachment/components/NodeViewAttachment/index.module.scss +23 -0
- package/src/extensions/Attachment/index.ts +1 -0
- package/src/extensions/BaseKit.ts +253 -0
- package/src/extensions/Blockquote/Blockquote.ts +31 -0
- package/src/extensions/Blockquote/index.ts +1 -0
- package/src/extensions/Bold/Bold.ts +26 -0
- package/src/extensions/Bold/index.ts +1 -0
- package/src/extensions/BulletList/BulletList.ts +28 -0
- package/src/extensions/BulletList/index.ts +1 -0
- package/src/extensions/Clear/Clear.ts +24 -0
- package/src/extensions/Clear/index.ts +1 -0
- package/src/extensions/Code/Code.ts +26 -0
- package/src/extensions/Code/index.ts +1 -0
- package/src/extensions/CodeBlock/CodeBlock.ts +54 -0
- package/src/extensions/CodeBlock/components/CodeBlockActiveButton.tsx +66 -0
- package/src/extensions/CodeBlock/components/NodeViewCodeBlock/NodeViewCodeBlock.tsx +89 -0
- package/src/extensions/CodeBlock/components/NodeViewCodeBlock/index.module.scss +81 -0
- package/src/extensions/CodeBlock/highlighter.ts +132 -0
- package/src/extensions/CodeBlock/index.ts +1 -0
- package/src/extensions/CodeBlock/shiki-plugin.ts +213 -0
- package/src/extensions/Color/Color.ts +52 -0
- package/src/extensions/Color/components/ColorActionButton.tsx +104 -0
- package/src/extensions/Color/index.ts +1 -0
- package/src/extensions/Document/Document.ts +8 -0
- package/src/extensions/Document/index.ts +1 -0
- package/src/extensions/Drawer/Drawer.ts +177 -0
- package/src/extensions/Drawer/components/ControlDrawer/ControlDrawer.module.scss +85 -0
- package/src/extensions/Drawer/components/ControlDrawer/ControlDrawer.tsx +598 -0
- package/src/extensions/Drawer/components/ControlDrawer/icon.tsx +500 -0
- package/src/extensions/Drawer/components/DrawerActiveButton.tsx +239 -0
- package/src/extensions/Drawer/components/EditDrawerBlock.tsx +238 -0
- package/src/extensions/Drawer/components/NodeViewDrawer/NodeViewDrawer.tsx +260 -0
- package/src/extensions/Drawer/index.ts +1 -0
- package/src/extensions/Emoji/Emoji.ts +146 -0
- package/src/extensions/Emoji/components/EmojiList/EmojiList.tsx +103 -0
- package/src/extensions/Emoji/components/EmojiList/emojis.ts +1858 -0
- package/src/extensions/Emoji/components/EmojiPicker/EmojiPicker.tsx +61 -0
- package/src/extensions/Emoji/index.ts +1 -0
- package/src/extensions/Excalidraw/Excalidraw.ts +123 -0
- package/src/extensions/Excalidraw/components/ExcalidrawActiveButton.tsx +138 -0
- package/src/extensions/Excalidraw/components/NodeViewExcalidraw/NodeViewExcalidraw.tsx +178 -0
- package/src/extensions/Excalidraw/components/NodeViewExcalidraw/index.module.scss +43 -0
- package/src/extensions/Excalidraw/index.ts +1 -0
- package/src/extensions/ExportPdf/ExportPdf.ts +25 -0
- package/src/extensions/ExportPdf/index.ts +1 -0
- package/src/extensions/ExportWord/ExportWord.ts +87 -0
- package/src/extensions/ExportWord/index.ts +1 -0
- package/src/extensions/FontFamily/FontFamily.ts +64 -0
- package/src/extensions/FontFamily/components/FontFamilyButton.tsx +97 -0
- package/src/extensions/FontFamily/index.ts +1 -0
- package/src/extensions/FontSize/FontSize.ts +119 -0
- package/src/extensions/FontSize/components/FontSizeMenuButton.tsx +84 -0
- package/src/extensions/FontSize/index.ts +1 -0
- package/src/extensions/FormatPainter/FormatPainter.ts +121 -0
- package/src/extensions/FormatPainter/index.ts +1 -0
- package/src/extensions/Heading/Heading.ts +57 -0
- package/src/extensions/Heading/components/HeadingButton.tsx +96 -0
- package/src/extensions/Heading/index.ts +1 -0
- package/src/extensions/Highlight/Highlight.ts +36 -0
- package/src/extensions/Highlight/components/HighlightActionButton.tsx +108 -0
- package/src/extensions/Highlight/index.ts +1 -0
- package/src/extensions/History/History.ts +39 -0
- package/src/extensions/History/components/HistoryActionButton.tsx +74 -0
- package/src/extensions/History/index.ts +1 -0
- package/src/extensions/HorizontalRule/HorizontalRule.ts +42 -0
- package/src/extensions/HorizontalRule/index.ts +1 -0
- package/src/extensions/Iframe/Iframe.ts +140 -0
- package/src/extensions/Iframe/components/IframeNodeView.tsx +92 -0
- package/src/extensions/Iframe/components/index.module.scss +40 -0
- package/src/extensions/Iframe/embed.ts +487 -0
- package/src/extensions/Iframe/index.ts +1 -0
- package/src/extensions/Image/Image.ts +303 -0
- package/src/extensions/Image/components/ActionImageButton.tsx +186 -0
- package/src/extensions/Image/components/ImageCropper.tsx +198 -0
- package/src/extensions/Image/components/ImageView.tsx +271 -0
- package/src/extensions/Image/index.ts +1 -0
- package/src/extensions/Image/store.ts +15 -0
- package/src/extensions/ImageGif/ImageGif.ts +176 -0
- package/src/extensions/ImageGif/components/ImageGifActionButton.tsx +138 -0
- package/src/extensions/ImageGif/components/ImageGifView.tsx +260 -0
- package/src/extensions/ImageGif/index.ts +1 -0
- package/src/extensions/ImportWord/ImportWord.ts +52 -0
- package/src/extensions/ImportWord/components/ImportWordButton.tsx +151 -0
- package/src/extensions/ImportWord/index.ts +1 -0
- package/src/extensions/Indent/Indent.ts +110 -0
- package/src/extensions/Indent/index.ts +1 -0
- package/src/extensions/Italic/Italic.ts +29 -0
- package/src/extensions/Italic/index.ts +1 -0
- package/src/extensions/Katex/Katex.ts +109 -0
- package/src/extensions/Katex/components/KatexActiveButton.tsx +117 -0
- package/src/extensions/Katex/components/KatexWrapper.tsx +53 -0
- package/src/extensions/Katex/index.ts +1 -0
- package/src/extensions/LineHeight/LineHeight.ts +76 -0
- package/src/extensions/LineHeight/components/LineHeightDropdown.tsx +93 -0
- package/src/extensions/LineHeight/index.ts +1 -0
- package/src/extensions/Link/Link.ts +92 -0
- package/src/extensions/Link/components/LinkEditBlock.tsx +110 -0
- package/src/extensions/Link/components/LinkEditPopover.tsx +46 -0
- package/src/extensions/Link/components/LinkViewBlock.tsx +54 -0
- package/src/extensions/Link/index.ts +1 -0
- package/src/extensions/ListItem/ListItem.ts +1 -0
- package/src/extensions/ListItem/index.ts +1 -0
- package/src/extensions/Mention/Mention.ts +100 -0
- package/src/extensions/Mention/components/NodeViewMentionList/NodeViewMentionList.tsx +94 -0
- package/src/extensions/Mention/components/NodeViewMentionList/index.module.scss +38 -0
- package/src/extensions/Mention/index.ts +1 -0
- package/src/extensions/Mermaid/Mermaid.ts +177 -0
- package/src/extensions/Mermaid/components/EditMermaidBlock.tsx +155 -0
- package/src/extensions/Mermaid/components/MermaidActiveButton.tsx +151 -0
- package/src/extensions/Mermaid/components/NodeViewMermaid/NodeViewMermaid.tsx +260 -0
- package/src/extensions/Mermaid/index.ts +1 -0
- package/src/extensions/MoreMark/MoreMark.ts +102 -0
- package/src/extensions/MoreMark/components/ActionMoreButton.tsx +97 -0
- package/src/extensions/MoreMark/index.ts +1 -0
- package/src/extensions/MultiColumn/Column.ts +36 -0
- package/src/extensions/MultiColumn/MultiColumn.ts +111 -0
- package/src/extensions/MultiColumn/components/ColumnActionButton.ts +22 -0
- package/src/extensions/MultiColumn/index.ts +3 -0
- package/src/extensions/OrderedList/OrderedList.ts +28 -0
- package/src/extensions/OrderedList/index.ts +1 -0
- package/src/extensions/SearchAndReplace/SearchAndReplace.ts +395 -0
- package/src/extensions/SearchAndReplace/components/SearchAndReplaceButton.tsx +190 -0
- package/src/extensions/SearchAndReplace/index.ts +1 -0
- package/src/extensions/Selection/Selection.ts +32 -0
- package/src/extensions/Selection/index.ts +1 -0
- package/src/extensions/SlashCommand/SlashCommand.ts +255 -0
- package/src/extensions/SlashCommand/components/CommandsList.tsx +180 -0
- package/src/extensions/SlashCommand/groups.ts +183 -0
- package/src/extensions/SlashCommand/index.ts +1 -0
- package/src/extensions/SlashCommand/types.ts +24 -0
- package/src/extensions/Strike/Strike.ts +26 -0
- package/src/extensions/Strike/index.ts +1 -0
- package/src/extensions/Subscript/Subscript.ts +88 -0
- package/src/extensions/Subscript/index.ts +1 -0
- package/src/extensions/Table/Cell.ts +131 -0
- package/src/extensions/Table/Header.ts +93 -0
- package/src/extensions/Table/Row.ts +8 -0
- package/src/extensions/Table/Table.ts +60 -0
- package/src/extensions/Table/cell-background.ts +112 -0
- package/src/extensions/Table/components/CreateTablePopover.tsx +132 -0
- package/src/extensions/Table/components/TableActionButton.tsx +42 -0
- package/src/extensions/Table/index.ts +6 -0
- package/src/extensions/Table/utils.ts +352 -0
- package/src/extensions/TableOfContent/TableOfContent.ts +124 -0
- package/src/extensions/TableOfContent/components/NodeViewTableOfContent.tsx +116 -0
- package/src/extensions/TableOfContent/components/TableOfContentActionButton.tsx +27 -0
- package/src/extensions/TableOfContent/components/index.module.scss +40 -0
- package/src/extensions/TableOfContent/index.ts +1 -0
- package/src/extensions/TaskList/TaskList.ts +46 -0
- package/src/extensions/TaskList/index.ts +1 -0
- package/src/extensions/TextAlign/TextAlign.ts +68 -0
- package/src/extensions/TextAlign/components/TextAlignMenuButton.tsx +103 -0
- package/src/extensions/TextAlign/index.ts +1 -0
- package/src/extensions/TextBubble/TextBubble.ts +22 -0
- package/src/extensions/TextBubble/components/TextDropdown.tsx +146 -0
- package/src/extensions/TextBubble/index.ts +1 -0
- package/src/extensions/TextDirection/TextDirection.ts +97 -0
- package/src/extensions/TextDirection/components/TextDirectionButton.tsx +103 -0
- package/src/extensions/TextDirection/index.ts +1 -0
- package/src/extensions/TrailingNode/TrailingNode.ts +71 -0
- package/src/extensions/TrailingNode/index.ts +1 -0
- package/src/extensions/Twitter/Twitter.ts +161 -0
- package/src/extensions/Twitter/components/FormEditLinkTwitter.tsx +68 -0
- package/src/extensions/Twitter/components/NodeViewTweet.tsx +30 -0
- package/src/extensions/Twitter/components/TwitterActiveButton.tsx +41 -0
- package/src/extensions/Twitter/index.ts +1 -0
- package/src/extensions/UnderLine/Underline.ts +30 -0
- package/src/extensions/UnderLine/index.ts +1 -0
- package/src/extensions/Video/Video.ts +204 -0
- package/src/extensions/Video/components/ActiveVideoButton.tsx +191 -0
- package/src/extensions/Video/index.ts +1 -0
- package/src/extensions/Video/store.ts +15 -0
- package/src/extensions/index.ts +122 -0
- package/src/hooks/useActive.tsx +24 -0
- package/src/hooks/useAttributes.tsx +45 -0
- package/src/hooks/useCopy.tsx +20 -0
- package/src/hooks/useEditorState.tsx +23 -0
- package/src/hooks/useExtension.tsx +29 -0
- package/src/index.ts +8 -0
- package/src/lib/utils.ts +7 -0
- package/src/locale-bundle.ts +3 -0
- package/src/locales/en.ts +173 -0
- package/src/locales/hu.ts +173 -0
- package/src/locales/index.tsx +163 -0
- package/src/locales/pt-br.ts +173 -0
- package/src/locales/vi.ts +173 -0
- package/src/locales/zh-cn.ts +173 -0
- package/src/plugins/DragHandle/index.ts +375 -0
- package/src/plugins/DragHandle/range.ts +114 -0
- package/src/plugins/DragHandle/utils.ts +80 -0
- package/src/plugins/image-upload.ts +160 -0
- package/src/store/ProviderRichText.tsx +53 -0
- package/src/store/editableEditor.ts +15 -0
- package/src/store/fast-context.tsx +70 -0
- package/src/store/store.ts +35 -0
- package/src/styles/ProseMirror.scss +176 -0
- package/src/styles/columns.scss +23 -0
- package/src/styles/editor.scss +411 -0
- package/src/styles/global.scss +87 -0
- package/src/styles/index.scss +5 -0
- package/src/styles/mention.scss +6 -0
- package/src/theme/theme.ts +15 -0
- package/src/types.ts +271 -0
- package/src/utils/_event.ts +55 -0
- package/src/utils/color.ts +67 -0
- package/src/utils/columns.ts +142 -0
- package/src/utils/customEvents/customEvents.ts +18 -0
- package/src/utils/customEvents/events.constant.ts +11 -0
- package/src/utils/delete-node.ts +46 -0
- package/src/utils/dom-dataset.ts +121 -0
- package/src/utils/download.ts +17 -0
- package/src/utils/dynamicCSS.ts +192 -0
- package/src/utils/editor-container-size.ts +28 -0
- package/src/utils/file.ts +112 -0
- package/src/utils/getRenderContainer.ts +41 -0
- package/src/utils/indent.ts +99 -0
- package/src/utils/is-mobile.ts +57 -0
- package/src/utils/json.ts +18 -0
- package/src/utils/line-height.ts +109 -0
- package/src/utils/lru-cache.ts +145 -0
- package/src/utils/mitt.ts +114 -0
- package/src/utils/node.ts +92 -0
- package/src/utils/pdf.ts +72 -0
- package/src/utils/plateform.ts +49 -0
- package/src/utils/shortId.ts +5 -0
- package/src/utils/storage.ts +18 -0
- package/src/utils/utils.ts +71 -0
- package/src/vite-env.d.ts +3 -0
- package/lib/RichTextEditor-BwbqJLnA.cjs +0 -141
- package/lib/RichTextEditor-iGJ6-rbq.js +0 -8833
- package/lib/extension-bundle.cjs +0 -33
- package/lib/extension-bundle.d.cts +0 -947
- package/lib/extension-bundle.d.ts +0 -947
- package/lib/extension-bundle.js +0 -5755
- package/lib/index-DV-nXpU1.cjs +0 -1
- package/lib/index-M6H3FoBi.js +0 -1147
- package/lib/index.cjs +0 -1
- package/lib/index.d.cts +0 -513
- package/lib/index.d.ts +0 -513
- package/lib/index.js +0 -16
- package/lib/locale-bundle.cjs +0 -1
- package/lib/locale-bundle.d.cts +0 -1140
- package/lib/locale-bundle.d.ts +0 -1140
- package/lib/locale-bundle.js +0 -9
- package/lib/style.css +0 -1
- package/lib/tiptap-DkWHMWDt.js +0 -6061
- package/lib/tiptap-gBG-1T-V.cjs +0 -116
- package/lib/vendor-BJ0Yf78E.cjs +0 -8114
- package/lib/vendor-Cpa6z-M0.js +0 -67575
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Node, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
import { TextSelection } from '@tiptap/pm/state';
|
|
4
|
+
import { addOrDeleteCol, createColumns, gotoCol } from 'reactjs-tiptap-editor-pro/utils/columns';
|
|
5
|
+
|
|
6
|
+
export const EXTENSION_PRIORITY_HIGHEST = 200;
|
|
7
|
+
|
|
8
|
+
declare module '@tiptap/core' {
|
|
9
|
+
interface Commands<ReturnType> {
|
|
10
|
+
columns: {
|
|
11
|
+
insertColumns: (attrs?: { cols: number }) => ReturnType
|
|
12
|
+
addColBefore: () => ReturnType
|
|
13
|
+
addColAfter: () => ReturnType
|
|
14
|
+
deleteCol: () => ReturnType
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const MultiColumn = Node.create({
|
|
20
|
+
name: 'columns',
|
|
21
|
+
group: 'block',
|
|
22
|
+
defining: true,
|
|
23
|
+
isolating: true,
|
|
24
|
+
allowGapCursor: false,
|
|
25
|
+
content: 'column{1,}',
|
|
26
|
+
priority: EXTENSION_PRIORITY_HIGHEST,
|
|
27
|
+
|
|
28
|
+
addOptions() {
|
|
29
|
+
return {
|
|
30
|
+
HTMLAttributes: {
|
|
31
|
+
class: 'columns',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
addAttributes() {
|
|
37
|
+
return {
|
|
38
|
+
cols: {
|
|
39
|
+
default: 2,
|
|
40
|
+
parseHTML: element => element.getAttribute('cols'),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
parseHTML() {
|
|
46
|
+
return [
|
|
47
|
+
{
|
|
48
|
+
tag: 'div[class=grid]',
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
renderHTML({ HTMLAttributes }) {
|
|
54
|
+
return ['div', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
addCommands() {
|
|
58
|
+
return {
|
|
59
|
+
insertColumns:
|
|
60
|
+
attrs =>
|
|
61
|
+
({ tr, dispatch, editor }) => {
|
|
62
|
+
const node = createColumns(editor.schema, (attrs && attrs.cols) || 3);
|
|
63
|
+
|
|
64
|
+
if (dispatch) {
|
|
65
|
+
const offset = tr.selection.anchor + 1;
|
|
66
|
+
|
|
67
|
+
tr.replaceSelectionWith(node)
|
|
68
|
+
.scrollIntoView()
|
|
69
|
+
.setSelection(TextSelection.near(tr.doc.resolve(offset)));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return true;
|
|
73
|
+
},
|
|
74
|
+
addColBefore:
|
|
75
|
+
() =>
|
|
76
|
+
({ dispatch, state }) => {
|
|
77
|
+
return addOrDeleteCol({ dispatch, state, type: 'addBefore' });
|
|
78
|
+
},
|
|
79
|
+
addColAfter:
|
|
80
|
+
() =>
|
|
81
|
+
({ dispatch, state }) => {
|
|
82
|
+
return addOrDeleteCol({ dispatch, state, type: 'addAfter' });
|
|
83
|
+
},
|
|
84
|
+
deleteCol:
|
|
85
|
+
() =>
|
|
86
|
+
({ dispatch, state }) => {
|
|
87
|
+
return addOrDeleteCol({ dispatch, state, type: 'delete' });
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
addKeyboardShortcuts() {
|
|
93
|
+
return {
|
|
94
|
+
'Mod-Alt-G': () => this.editor.commands.insertColumns(),
|
|
95
|
+
'Tab': () => {
|
|
96
|
+
return gotoCol({
|
|
97
|
+
state: this.editor.state,
|
|
98
|
+
dispatch: this.editor.view.dispatch,
|
|
99
|
+
type: 'after',
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
'Shift-Tab': () => {
|
|
103
|
+
return gotoCol({
|
|
104
|
+
state: this.editor.state,
|
|
105
|
+
dispatch: this.editor.view.dispatch,
|
|
106
|
+
type: 'before',
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
import { ActionButton } from 'reactjs-tiptap-editor-pro/components';
|
|
4
|
+
|
|
5
|
+
export const ColumnActionButton = Extension.create<any>({
|
|
6
|
+
name: 'columnActionButton',
|
|
7
|
+
addOptions() {
|
|
8
|
+
return {
|
|
9
|
+
...this.parent?.(),
|
|
10
|
+
button: ({ editor, t }: any) => ({
|
|
11
|
+
component: ActionButton,
|
|
12
|
+
componentProps: {
|
|
13
|
+
action: () => {
|
|
14
|
+
editor.chain().focus().insertColumns({ cols: 2 }).run();
|
|
15
|
+
},
|
|
16
|
+
icon: 'Columns',
|
|
17
|
+
tooltip: t('editor.columns.tooltip'),
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { OrderedListOptions as TiptapOrderedListOptions } from '@tiptap/extension-ordered-list';
|
|
2
|
+
import { OrderedList as TiptapOrderedList } from '@tiptap/extension-ordered-list';
|
|
3
|
+
|
|
4
|
+
import { ActionButton } from 'reactjs-tiptap-editor-pro/components';
|
|
5
|
+
import type { GeneralOptions } from 'reactjs-tiptap-editor-pro/types';
|
|
6
|
+
|
|
7
|
+
export interface OrderedListOptions
|
|
8
|
+
extends TiptapOrderedListOptions,
|
|
9
|
+
GeneralOptions<OrderedListOptions> {}
|
|
10
|
+
|
|
11
|
+
export const OrderedList = TiptapOrderedList.extend<OrderedListOptions>({
|
|
12
|
+
addOptions() {
|
|
13
|
+
return {
|
|
14
|
+
...this.parent?.(),
|
|
15
|
+
button: ({ editor, t }) => ({
|
|
16
|
+
component: ActionButton,
|
|
17
|
+
componentProps: {
|
|
18
|
+
action: () => editor.commands.toggleOrderedList(),
|
|
19
|
+
isActive: () => editor.isActive('orderedList') || false,
|
|
20
|
+
disabled: false,
|
|
21
|
+
icon: 'ListOrdered',
|
|
22
|
+
shortcutKeys: ['mod', 'shift', '7'],
|
|
23
|
+
tooltip: t('editor.orderedlist.tooltip'),
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './OrderedList';
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
3
|
+
import { Extension } from '@tiptap/core';
|
|
4
|
+
import type { EditorState } from '@tiptap/pm/state';
|
|
5
|
+
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
6
|
+
import { Decoration, DecorationSet } from '@tiptap/pm/view';
|
|
7
|
+
import scrollIntoView from 'scroll-into-view-if-needed';
|
|
8
|
+
|
|
9
|
+
import SearchAndReplaceButton from 'reactjs-tiptap-editor-pro/extensions/SearchAndReplace/components/SearchAndReplaceButton';
|
|
10
|
+
import type { GeneralOptions } from 'reactjs-tiptap-editor-pro/types';
|
|
11
|
+
import { dispatchEvent } from 'reactjs-tiptap-editor-pro/utils/customEvents/customEvents';
|
|
12
|
+
import { EVENTS } from 'reactjs-tiptap-editor-pro/utils/customEvents/events.constant';
|
|
13
|
+
|
|
14
|
+
declare module '@tiptap/core' {
|
|
15
|
+
interface Commands<ReturnType> {
|
|
16
|
+
search: {
|
|
17
|
+
setSearchTerm: (searchTerm: string) => ReturnType
|
|
18
|
+
setReplaceTerm: (replaceTerm: string) => ReturnType
|
|
19
|
+
replace: () => ReturnType
|
|
20
|
+
replaceAll: () => ReturnType
|
|
21
|
+
goToPrevSearchResult: () => void
|
|
22
|
+
goToNextSearchResult: () => void
|
|
23
|
+
setCaseSensitive: (caseSensitive: boolean) => ReturnType
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface Result {
|
|
29
|
+
from: number
|
|
30
|
+
to: number
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface TextNodesWithPosition {
|
|
34
|
+
text: string
|
|
35
|
+
pos: number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const updateView = (state: EditorState, dispatch: any) => dispatch(state.tr);
|
|
39
|
+
|
|
40
|
+
function regex(s: string, disableRegex: boolean, caseSensitive: boolean): RegExp {
|
|
41
|
+
return RegExp(disableRegex ? s.replace(/[$()*+./?[\\\]^{|}-]/g, String.raw`\$&`) : s, caseSensitive ? 'gu' : 'gui');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function processSearches(
|
|
45
|
+
doc: any,
|
|
46
|
+
searchTerm: RegExp,
|
|
47
|
+
searchResultClass: string,
|
|
48
|
+
): { decorationsToReturn: any[], results: Result[] } {
|
|
49
|
+
const decorations: Decoration[] = [];
|
|
50
|
+
let textNodesWithPosition: TextNodesWithPosition[] = [];
|
|
51
|
+
const results: Result[] = [];
|
|
52
|
+
|
|
53
|
+
let index = 0;
|
|
54
|
+
|
|
55
|
+
if (!searchTerm)
|
|
56
|
+
return { decorationsToReturn: [], results: [] };
|
|
57
|
+
|
|
58
|
+
doc?.descendants((node: any, pos: any) => {
|
|
59
|
+
if (node.isText) {
|
|
60
|
+
if (textNodesWithPosition[index]) {
|
|
61
|
+
textNodesWithPosition[index] = {
|
|
62
|
+
text: textNodesWithPosition[index].text + node.text,
|
|
63
|
+
pos: textNodesWithPosition[index].pos,
|
|
64
|
+
};
|
|
65
|
+
} else {
|
|
66
|
+
textNodesWithPosition[index] = {
|
|
67
|
+
text: `${node.text}`,
|
|
68
|
+
pos,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
index += 1;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
textNodesWithPosition = textNodesWithPosition.filter(Boolean);
|
|
77
|
+
|
|
78
|
+
for (const { text, pos } of textNodesWithPosition) {
|
|
79
|
+
|
|
80
|
+
const matches = [...text.matchAll(searchTerm)];
|
|
81
|
+
|
|
82
|
+
for (const m of matches) {
|
|
83
|
+
|
|
84
|
+
if (m[0] === '')
|
|
85
|
+
break;
|
|
86
|
+
|
|
87
|
+
if (m.index !== undefined) {
|
|
88
|
+
results.push({
|
|
89
|
+
from: pos + m.index,
|
|
90
|
+
to: pos + m.index + m[0].length,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
for (const r of results) {
|
|
97
|
+
decorations.push(Decoration.inline(r.from, r.to, { class: searchResultClass }));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
decorationsToReturn: decorations,
|
|
102
|
+
results,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function replace(replaceTerm: string, results: Result[], { state, dispatch }: any) {
|
|
107
|
+
const firstResult = results[0];
|
|
108
|
+
|
|
109
|
+
if (!firstResult)
|
|
110
|
+
return;
|
|
111
|
+
|
|
112
|
+
const { from, to } = results[0];
|
|
113
|
+
|
|
114
|
+
if (dispatch)
|
|
115
|
+
dispatch(state.tr.insertText(replaceTerm, from, to));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function rebaseNextResult(replaceTerm: string, index: number, lastOffset: number, results: Result[]): [number, Result[]] | null {
|
|
119
|
+
const nextIndex = index + 1;
|
|
120
|
+
|
|
121
|
+
if (!results[nextIndex])
|
|
122
|
+
return null;
|
|
123
|
+
|
|
124
|
+
const { from: currentFrom, to: currentTo } = results[index];
|
|
125
|
+
|
|
126
|
+
const offset = currentTo - currentFrom - replaceTerm.length + lastOffset;
|
|
127
|
+
|
|
128
|
+
const { from, to } = results[nextIndex];
|
|
129
|
+
|
|
130
|
+
results[nextIndex] = {
|
|
131
|
+
to: to - offset,
|
|
132
|
+
from: from - offset,
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
return [offset, results];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function replaceAll(replaceTerm: string, results: Result[], { tr, dispatch }: any) {
|
|
139
|
+
let offset = 0;
|
|
140
|
+
|
|
141
|
+
let ourResults = results.slice();
|
|
142
|
+
|
|
143
|
+
if (ourResults.length === 0)
|
|
144
|
+
return false;
|
|
145
|
+
|
|
146
|
+
for (let i = 0; i < ourResults.length; i += 1) {
|
|
147
|
+
const { from, to } = ourResults[i];
|
|
148
|
+
|
|
149
|
+
tr.insertText(replaceTerm, from, to);
|
|
150
|
+
|
|
151
|
+
const rebaseNextResultResponse = rebaseNextResult(replaceTerm, i, offset, ourResults);
|
|
152
|
+
|
|
153
|
+
if (rebaseNextResultResponse) {
|
|
154
|
+
offset = rebaseNextResultResponse[0];
|
|
155
|
+
ourResults = rebaseNextResultResponse[1];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
dispatch(tr);
|
|
160
|
+
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function gotoSearchResult({ view, tr, searchResults, searchResultCurrentClass, gotoIndex }: any) {
|
|
165
|
+
const result = searchResults[gotoIndex];
|
|
166
|
+
|
|
167
|
+
if (result) {
|
|
168
|
+
const transaction = tr.setMeta('directDecoration', {
|
|
169
|
+
fromPos: result.from,
|
|
170
|
+
toPos: result.to,
|
|
171
|
+
attrs: { class: searchResultCurrentClass },
|
|
172
|
+
});
|
|
173
|
+
view?.dispatch(transaction);
|
|
174
|
+
|
|
175
|
+
setTimeout(() => {
|
|
176
|
+
const el = window.document.querySelector(`.${searchResultCurrentClass}`);
|
|
177
|
+
if (el) {
|
|
178
|
+
scrollIntoView(el, { behavior: 'smooth', scrollMode: 'if-needed' });
|
|
179
|
+
}
|
|
180
|
+
}, 0);
|
|
181
|
+
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
interface SearchOptions extends GeneralOptions<SearchOptions> {
|
|
189
|
+
searchTerm: string
|
|
190
|
+
replaceTerm: string
|
|
191
|
+
searchResultClass: string
|
|
192
|
+
searchResultCurrentClass: string
|
|
193
|
+
caseSensitive: boolean
|
|
194
|
+
disableRegex: boolean
|
|
195
|
+
onChange?: () => void
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
interface SearchStorage {
|
|
199
|
+
results: Result[]
|
|
200
|
+
currentIndex: number
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export const SearchAndReplace = Extension.create<SearchOptions, SearchStorage>({
|
|
204
|
+
name: 'search',
|
|
205
|
+
|
|
206
|
+
addOptions() {
|
|
207
|
+
return {
|
|
208
|
+
...this.parent?.(),
|
|
209
|
+
searchTerm: '',
|
|
210
|
+
replaceTerm: '',
|
|
211
|
+
results: [],
|
|
212
|
+
currentIndex: 0,
|
|
213
|
+
searchResultClass: 'search-result',
|
|
214
|
+
searchResultCurrentClass: 'search-result-current',
|
|
215
|
+
caseSensitive: false,
|
|
216
|
+
disableRegex: false,
|
|
217
|
+
onChange: () => {
|
|
218
|
+
return;
|
|
219
|
+
},
|
|
220
|
+
button: ({ editor, t }: any) => ({
|
|
221
|
+
component: SearchAndReplaceButton,
|
|
222
|
+
componentProps: {
|
|
223
|
+
action: () => {
|
|
224
|
+
return;
|
|
225
|
+
},
|
|
226
|
+
icon: 'SearchAndReplace',
|
|
227
|
+
tooltip: t('editor.searchAndReplace.tooltip'),
|
|
228
|
+
isActive: () => false,
|
|
229
|
+
disabled: false,
|
|
230
|
+
editor,
|
|
231
|
+
},
|
|
232
|
+
}),
|
|
233
|
+
};
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
addStorage() {
|
|
237
|
+
return {
|
|
238
|
+
results: [],
|
|
239
|
+
currentIndex: -1,
|
|
240
|
+
};
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
addCommands() {
|
|
244
|
+
return {
|
|
245
|
+
setSearchTerm:
|
|
246
|
+
(searchTerm: string) =>
|
|
247
|
+
({ state, dispatch }) => {
|
|
248
|
+
this.options.searchTerm = searchTerm;
|
|
249
|
+
this.storage.results = [];
|
|
250
|
+
this.storage.currentIndex = 0;
|
|
251
|
+
dispatchEvent(EVENTS.SEARCH_REPLCE);
|
|
252
|
+
updateView(state, dispatch);
|
|
253
|
+
return false;
|
|
254
|
+
},
|
|
255
|
+
setReplaceTerm:
|
|
256
|
+
(replaceTerm: string) =>
|
|
257
|
+
({ state, dispatch }) => {
|
|
258
|
+
this.options.replaceTerm = replaceTerm;
|
|
259
|
+
|
|
260
|
+
updateView(state, dispatch);
|
|
261
|
+
|
|
262
|
+
return false;
|
|
263
|
+
},
|
|
264
|
+
setCaseSensitive: (caseSensitive: boolean) => ({ state, dispatch }) => {
|
|
265
|
+
this.options.caseSensitive = caseSensitive;
|
|
266
|
+
updateView(state, dispatch);
|
|
267
|
+
return false;
|
|
268
|
+
},
|
|
269
|
+
replace:
|
|
270
|
+
() =>
|
|
271
|
+
({ state, dispatch }) => {
|
|
272
|
+
const { replaceTerm } = this.options;
|
|
273
|
+
const { currentIndex, results } = this.storage;
|
|
274
|
+
const currentResult = results[currentIndex];
|
|
275
|
+
|
|
276
|
+
if (currentResult) {
|
|
277
|
+
replace(replaceTerm, [currentResult], { state, dispatch });
|
|
278
|
+
this.storage.results.splice(currentIndex, 1);
|
|
279
|
+
} else {
|
|
280
|
+
replace(replaceTerm, results, { state, dispatch });
|
|
281
|
+
this.storage.results.shift();
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
dispatchEvent(EVENTS.SEARCH_REPLCE);
|
|
285
|
+
|
|
286
|
+
updateView(state, dispatch);
|
|
287
|
+
|
|
288
|
+
return false;
|
|
289
|
+
},
|
|
290
|
+
replaceAll:
|
|
291
|
+
() =>
|
|
292
|
+
({ state, tr, dispatch }) => {
|
|
293
|
+
const { replaceTerm } = this.options;
|
|
294
|
+
const { results } = this.storage;
|
|
295
|
+
|
|
296
|
+
replaceAll(replaceTerm, results, { tr, dispatch });
|
|
297
|
+
|
|
298
|
+
this.storage.currentIndex = -1;
|
|
299
|
+
this.storage.results = [];
|
|
300
|
+
dispatchEvent(EVENTS.SEARCH_REPLCE);
|
|
301
|
+
|
|
302
|
+
updateView(state, dispatch);
|
|
303
|
+
|
|
304
|
+
return false;
|
|
305
|
+
},
|
|
306
|
+
goToPrevSearchResult:
|
|
307
|
+
() =>
|
|
308
|
+
({ view, tr }: any) => {
|
|
309
|
+
const { searchResultCurrentClass } = this.options;
|
|
310
|
+
const { currentIndex, results } = this.storage;
|
|
311
|
+
const nextIndex = (currentIndex + results.length - 1) % results.length;
|
|
312
|
+
this.storage.currentIndex = nextIndex;
|
|
313
|
+
dispatchEvent(EVENTS.SEARCH_REPLCE);
|
|
314
|
+
|
|
315
|
+
return gotoSearchResult({
|
|
316
|
+
view,
|
|
317
|
+
tr,
|
|
318
|
+
searchResults: results,
|
|
319
|
+
searchResultCurrentClass,
|
|
320
|
+
gotoIndex: nextIndex,
|
|
321
|
+
});
|
|
322
|
+
},
|
|
323
|
+
goToNextSearchResult:
|
|
324
|
+
() =>
|
|
325
|
+
({ view, tr }: any) => {
|
|
326
|
+
const { searchResultCurrentClass } = this.options;
|
|
327
|
+
const { currentIndex, results } = this.storage;
|
|
328
|
+
const nextIndex = (currentIndex + 1) % results.length;
|
|
329
|
+
this.storage.currentIndex = nextIndex;
|
|
330
|
+
this.options.onChange && this.options.onChange();
|
|
331
|
+
dispatchEvent(EVENTS.SEARCH_REPLCE);
|
|
332
|
+
|
|
333
|
+
return gotoSearchResult({
|
|
334
|
+
view,
|
|
335
|
+
tr,
|
|
336
|
+
searchResults: results,
|
|
337
|
+
searchResultCurrentClass,
|
|
338
|
+
gotoIndex: nextIndex,
|
|
339
|
+
});
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
},
|
|
343
|
+
|
|
344
|
+
addProseMirrorPlugins() {
|
|
345
|
+
const extensionThis = this;
|
|
346
|
+
|
|
347
|
+
return [
|
|
348
|
+
new Plugin({
|
|
349
|
+
key: new PluginKey('search'),
|
|
350
|
+
state: {
|
|
351
|
+
init() {
|
|
352
|
+
return DecorationSet.empty;
|
|
353
|
+
},
|
|
354
|
+
apply(ctx) {
|
|
355
|
+
const { doc, docChanged } = ctx;
|
|
356
|
+
|
|
357
|
+
const { searchTerm, searchResultClass, searchResultCurrentClass, disableRegex, caseSensitive }
|
|
358
|
+
= extensionThis.options;
|
|
359
|
+
|
|
360
|
+
if (docChanged || searchTerm) {
|
|
361
|
+
const { decorationsToReturn, results } = processSearches(
|
|
362
|
+
doc,
|
|
363
|
+
regex(searchTerm, disableRegex, caseSensitive),
|
|
364
|
+
searchResultClass,
|
|
365
|
+
);
|
|
366
|
+
extensionThis.storage.results = results;
|
|
367
|
+
if (extensionThis.storage.currentIndex > results.length - 1) {
|
|
368
|
+
extensionThis.storage.currentIndex = 0;
|
|
369
|
+
}
|
|
370
|
+
dispatchEvent(EVENTS.SEARCH_REPLCE);
|
|
371
|
+
if (ctx.getMeta('directDecoration')) {
|
|
372
|
+
const { fromPos, toPos, attrs } = ctx.getMeta('directDecoration');
|
|
373
|
+
decorationsToReturn.push(Decoration.inline(fromPos, toPos, attrs));
|
|
374
|
+
} else {
|
|
375
|
+
if (results.length > 0) {
|
|
376
|
+
decorationsToReturn[0] = Decoration.inline(results[0].from, results[0].to, {
|
|
377
|
+
class: searchResultCurrentClass,
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return DecorationSet.create(doc, decorationsToReturn);
|
|
383
|
+
}
|
|
384
|
+
return DecorationSet.empty;
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
props: {
|
|
388
|
+
decorations(state) {
|
|
389
|
+
return this.getState(state);
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
}),
|
|
393
|
+
];
|
|
394
|
+
},
|
|
395
|
+
});
|