reactjs-tiptap-editor-pro 0.2.31 → 0.2.33
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/lib/ColorPicker-MEAh4MhG.js +28181 -0
- package/lib/ColorPicker-ZncOwjAP.cjs +142 -0
- package/lib/extension-bundle.cjs +133 -0
- package/lib/extension-bundle.d.cts +947 -0
- package/lib/extension-bundle.d.ts +947 -0
- package/lib/extension-bundle.js +23921 -0
- package/lib/index.cjs +140 -0
- package/lib/index.d.cts +513 -0
- package/lib/index.d.ts +513 -0
- package/lib/index.js +3700 -0
- package/lib/locale-bundle-DiqW5jwb.cjs +1 -0
- package/lib/locale-bundle-DxCAtRDI.js +1487 -0
- package/lib/locale-bundle.cjs +1 -0
- package/lib/locale-bundle.d.cts +1140 -0
- package/lib/locale-bundle.d.ts +1140 -0
- package/lib/locale-bundle.js +9 -0
- package/lib/lucide-react-BFZtMawV.js +30462 -0
- package/lib/lucide-react-CMPhLW1m.cjs +7851 -0
- package/lib/style.css +1 -0
- package/package.json +58 -5
- package/src/components/ActionButton.tsx +0 -103
- package/src/components/ActionMenuButton.tsx +0 -76
- package/src/components/BubbleMenu.tsx +0 -93
- package/src/components/CharactorCount.tsx +0 -50
- package/src/components/ColorPicker.tsx +0 -272
- package/src/components/RichTextEditor.tsx +0 -212
- package/src/components/SizeSetter/SizeSetter.tsx +0 -102
- package/src/components/Toolbar.tsx +0 -108
- package/src/components/icons/Activity.tsx +0 -19
- package/src/components/icons/Animas.tsx +0 -24
- package/src/components/icons/AspectRatio.tsx +0 -13
- package/src/components/icons/Blockquote.tsx +0 -17
- package/src/components/icons/ColumnAddLeft.tsx +0 -7
- package/src/components/icons/ColumnAddRight.tsx +0 -7
- package/src/components/icons/DeleteColumn.tsx +0 -26
- package/src/components/icons/DeleteRow.tsx +0 -26
- package/src/components/icons/Direction.tsx +0 -7
- package/src/components/icons/Excalidraw.tsx +0 -7
- package/src/components/icons/ExportPdf.tsx +0 -8
- package/src/components/icons/ExportWord.tsx +0 -24
- package/src/components/icons/FileWordOutline.tsx +0 -13
- package/src/components/icons/Flag.tsx +0 -19
- package/src/components/icons/Food.tsx +0 -20
- package/src/components/icons/GIfIcon.tsx +0 -10
- package/src/components/icons/Icon.tsx +0 -30
- package/src/components/icons/ImportWord.tsx +0 -23
- package/src/components/icons/LeftToRight.tsx +0 -7
- package/src/components/icons/LineHeight.tsx +0 -13
- package/src/components/icons/MenuDown.tsx +0 -24
- package/src/components/icons/Mermaid.tsx +0 -13
- package/src/components/icons/NoFill.tsx +0 -7
- package/src/components/icons/Object.tsx +0 -24
- package/src/components/icons/RightToLeft.tsx +0 -7
- package/src/components/icons/SizeL.tsx +0 -9
- package/src/components/icons/SizeM.tsx +0 -13
- package/src/components/icons/SizeS.tsx +0 -13
- package/src/components/icons/Symbol.tsx +0 -19
- package/src/components/icons/Travel.tsx +0 -24
- package/src/components/icons/Twitter.tsx +0 -7
- package/src/components/icons/icons.ts +0 -212
- package/src/components/icons/index.ts +0 -12
- package/src/components/index.ts +0 -9
- package/src/components/menus/bubble.ts +0 -395
- package/src/components/menus/components/BubbleMenuContent.tsx +0 -15
- package/src/components/menus/components/BubbleMenuDrawer.tsx +0 -128
- package/src/components/menus/components/BubbleMenuExcalidraw.tsx +0 -91
- package/src/components/menus/components/BubbleMenuIframe.tsx +0 -143
- package/src/components/menus/components/BubbleMenuKatex.tsx +0 -136
- package/src/components/menus/components/BubbleMenuLink.tsx +0 -99
- package/src/components/menus/components/BubbleMenuMedia.tsx +0 -235
- package/src/components/menus/components/BubbleMenuMermaid.tsx +0 -128
- package/src/components/menus/components/BubbleMenuText.tsx +0 -102
- package/src/components/menus/components/BubbleMenuTwitter.tsx +0 -91
- package/src/components/menus/components/ColumnsBubbleMenu.tsx +0 -59
- package/src/components/menus/components/ContentMenu.tsx +0 -396
- package/src/components/menus/components/TableBubbleMenu.tsx +0 -362
- package/src/components/menus/index.ts +0 -7
- package/src/components/ui/button.tsx +0 -56
- package/src/components/ui/checkbox.tsx +0 -30
- package/src/components/ui/dialog.tsx +0 -128
- package/src/components/ui/dropdown-menu.tsx +0 -203
- package/src/components/ui/emoji-picker.tsx +0 -166
- package/src/components/ui/index.ts +0 -14
- package/src/components/ui/input.tsx +0 -25
- package/src/components/ui/label.tsx +0 -26
- package/src/components/ui/popover.tsx +0 -31
- package/src/components/ui/select.tsx +0 -162
- package/src/components/ui/separator.tsx +0 -31
- package/src/components/ui/switch.tsx +0 -29
- package/src/components/ui/tabs.tsx +0 -55
- package/src/components/ui/textarea.tsx +0 -24
- package/src/components/ui/toast.tsx +0 -129
- package/src/components/ui/toaster.tsx +0 -44
- package/src/components/ui/toggle.tsx +0 -45
- package/src/components/ui/tooltip.tsx +0 -30
- package/src/components/ui/use-toast.ts +0 -197
- package/src/constants/index.ts +0 -223
- package/src/constants/resetCSS.ts +0 -139
- package/src/extension-bundle.ts +0 -2
- package/src/extensions/Attachment/Attachment.ts +0 -144
- package/src/extensions/Attachment/components/NodeViewAttachment/FileIcon.tsx +0 -69
- package/src/extensions/Attachment/components/NodeViewAttachment/FileIconString.ts +0 -28
- package/src/extensions/Attachment/components/NodeViewAttachment/NodeViewAttachment.tsx +0 -155
- package/src/extensions/Attachment/components/NodeViewAttachment/index.module.scss +0 -23
- package/src/extensions/Attachment/index.ts +0 -1
- package/src/extensions/BaseKit.ts +0 -253
- package/src/extensions/Blockquote/Blockquote.ts +0 -31
- package/src/extensions/Blockquote/index.ts +0 -1
- package/src/extensions/Bold/Bold.ts +0 -26
- package/src/extensions/Bold/index.ts +0 -1
- package/src/extensions/BulletList/BulletList.ts +0 -28
- package/src/extensions/BulletList/index.ts +0 -1
- package/src/extensions/Clear/Clear.ts +0 -24
- package/src/extensions/Clear/index.ts +0 -1
- package/src/extensions/Code/Code.ts +0 -26
- package/src/extensions/Code/index.ts +0 -1
- package/src/extensions/CodeBlock/CodeBlock.ts +0 -54
- package/src/extensions/CodeBlock/components/CodeBlockActiveButton.tsx +0 -66
- package/src/extensions/CodeBlock/components/NodeViewCodeBlock/NodeViewCodeBlock.tsx +0 -89
- package/src/extensions/CodeBlock/components/NodeViewCodeBlock/index.module.scss +0 -81
- package/src/extensions/CodeBlock/highlighter.ts +0 -132
- package/src/extensions/CodeBlock/index.ts +0 -1
- package/src/extensions/CodeBlock/shiki-plugin.ts +0 -213
- package/src/extensions/Color/Color.ts +0 -52
- package/src/extensions/Color/components/ColorActionButton.tsx +0 -104
- package/src/extensions/Color/index.ts +0 -1
- package/src/extensions/Document/Document.ts +0 -8
- package/src/extensions/Document/index.ts +0 -1
- package/src/extensions/Drawer/Drawer.ts +0 -177
- package/src/extensions/Drawer/components/ControlDrawer/ControlDrawer.module.scss +0 -85
- package/src/extensions/Drawer/components/ControlDrawer/ControlDrawer.tsx +0 -598
- package/src/extensions/Drawer/components/ControlDrawer/icon.tsx +0 -500
- package/src/extensions/Drawer/components/DrawerActiveButton.tsx +0 -239
- package/src/extensions/Drawer/components/EditDrawerBlock.tsx +0 -238
- package/src/extensions/Drawer/components/NodeViewDrawer/NodeViewDrawer.tsx +0 -260
- package/src/extensions/Drawer/index.ts +0 -1
- package/src/extensions/Emoji/Emoji.ts +0 -146
- package/src/extensions/Emoji/components/EmojiList/EmojiList.tsx +0 -103
- package/src/extensions/Emoji/components/EmojiList/emojis.ts +0 -1858
- package/src/extensions/Emoji/components/EmojiPicker/EmojiPicker.tsx +0 -61
- package/src/extensions/Emoji/index.ts +0 -1
- package/src/extensions/Excalidraw/Excalidraw.ts +0 -123
- package/src/extensions/Excalidraw/components/ExcalidrawActiveButton.tsx +0 -138
- package/src/extensions/Excalidraw/components/NodeViewExcalidraw/NodeViewExcalidraw.tsx +0 -178
- package/src/extensions/Excalidraw/components/NodeViewExcalidraw/index.module.scss +0 -43
- package/src/extensions/Excalidraw/index.ts +0 -1
- package/src/extensions/ExportPdf/ExportPdf.ts +0 -25
- package/src/extensions/ExportPdf/index.ts +0 -1
- package/src/extensions/ExportWord/ExportWord.ts +0 -87
- package/src/extensions/ExportWord/index.ts +0 -1
- package/src/extensions/FontFamily/FontFamily.ts +0 -64
- package/src/extensions/FontFamily/components/FontFamilyButton.tsx +0 -97
- package/src/extensions/FontFamily/index.ts +0 -1
- package/src/extensions/FontSize/FontSize.ts +0 -119
- package/src/extensions/FontSize/components/FontSizeMenuButton.tsx +0 -84
- package/src/extensions/FontSize/index.ts +0 -1
- package/src/extensions/FormatPainter/FormatPainter.ts +0 -121
- package/src/extensions/FormatPainter/index.ts +0 -1
- package/src/extensions/Heading/Heading.ts +0 -57
- package/src/extensions/Heading/components/HeadingButton.tsx +0 -96
- package/src/extensions/Heading/index.ts +0 -1
- package/src/extensions/Highlight/Highlight.ts +0 -36
- package/src/extensions/Highlight/components/HighlightActionButton.tsx +0 -108
- package/src/extensions/Highlight/index.ts +0 -1
- package/src/extensions/History/History.ts +0 -39
- package/src/extensions/History/components/HistoryActionButton.tsx +0 -74
- package/src/extensions/History/index.ts +0 -1
- package/src/extensions/HorizontalRule/HorizontalRule.ts +0 -42
- package/src/extensions/HorizontalRule/index.ts +0 -1
- package/src/extensions/Iframe/Iframe.ts +0 -140
- package/src/extensions/Iframe/components/IframeNodeView.tsx +0 -92
- package/src/extensions/Iframe/components/index.module.scss +0 -40
- package/src/extensions/Iframe/embed.ts +0 -487
- package/src/extensions/Iframe/index.ts +0 -1
- package/src/extensions/Image/Image.ts +0 -303
- package/src/extensions/Image/components/ActionImageButton.tsx +0 -186
- package/src/extensions/Image/components/ImageCropper.tsx +0 -198
- package/src/extensions/Image/components/ImageView.tsx +0 -271
- package/src/extensions/Image/index.ts +0 -1
- package/src/extensions/Image/store.ts +0 -15
- package/src/extensions/ImageGif/ImageGif.ts +0 -176
- package/src/extensions/ImageGif/components/ImageGifActionButton.tsx +0 -138
- package/src/extensions/ImageGif/components/ImageGifView.tsx +0 -260
- package/src/extensions/ImageGif/index.ts +0 -1
- package/src/extensions/ImportWord/ImportWord.ts +0 -52
- package/src/extensions/ImportWord/components/ImportWordButton.tsx +0 -151
- package/src/extensions/ImportWord/index.ts +0 -1
- package/src/extensions/Indent/Indent.ts +0 -110
- package/src/extensions/Indent/index.ts +0 -1
- package/src/extensions/Italic/Italic.ts +0 -29
- package/src/extensions/Italic/index.ts +0 -1
- package/src/extensions/Katex/Katex.ts +0 -109
- package/src/extensions/Katex/components/KatexActiveButton.tsx +0 -117
- package/src/extensions/Katex/components/KatexWrapper.tsx +0 -53
- package/src/extensions/Katex/index.ts +0 -1
- package/src/extensions/LineHeight/LineHeight.ts +0 -76
- package/src/extensions/LineHeight/components/LineHeightDropdown.tsx +0 -93
- package/src/extensions/LineHeight/index.ts +0 -1
- package/src/extensions/Link/Link.ts +0 -92
- package/src/extensions/Link/components/LinkEditBlock.tsx +0 -110
- package/src/extensions/Link/components/LinkEditPopover.tsx +0 -46
- package/src/extensions/Link/components/LinkViewBlock.tsx +0 -54
- package/src/extensions/Link/index.ts +0 -1
- package/src/extensions/ListItem/ListItem.ts +0 -1
- package/src/extensions/ListItem/index.ts +0 -1
- package/src/extensions/Mention/Mention.ts +0 -100
- package/src/extensions/Mention/components/NodeViewMentionList/NodeViewMentionList.tsx +0 -94
- package/src/extensions/Mention/components/NodeViewMentionList/index.module.scss +0 -38
- package/src/extensions/Mention/index.ts +0 -1
- package/src/extensions/Mermaid/Mermaid.ts +0 -177
- package/src/extensions/Mermaid/components/EditMermaidBlock.tsx +0 -155
- package/src/extensions/Mermaid/components/MermaidActiveButton.tsx +0 -151
- package/src/extensions/Mermaid/components/NodeViewMermaid/NodeViewMermaid.tsx +0 -260
- package/src/extensions/Mermaid/index.ts +0 -1
- package/src/extensions/MoreMark/MoreMark.ts +0 -102
- package/src/extensions/MoreMark/components/ActionMoreButton.tsx +0 -97
- package/src/extensions/MoreMark/index.ts +0 -1
- package/src/extensions/MultiColumn/Column.ts +0 -36
- package/src/extensions/MultiColumn/MultiColumn.ts +0 -111
- package/src/extensions/MultiColumn/components/ColumnActionButton.ts +0 -22
- package/src/extensions/MultiColumn/index.ts +0 -3
- package/src/extensions/OrderedList/OrderedList.ts +0 -28
- package/src/extensions/OrderedList/index.ts +0 -1
- package/src/extensions/SearchAndReplace/SearchAndReplace.ts +0 -395
- package/src/extensions/SearchAndReplace/components/SearchAndReplaceButton.tsx +0 -190
- package/src/extensions/SearchAndReplace/index.ts +0 -1
- package/src/extensions/Selection/Selection.ts +0 -32
- package/src/extensions/Selection/index.ts +0 -1
- package/src/extensions/SlashCommand/SlashCommand.ts +0 -255
- package/src/extensions/SlashCommand/components/CommandsList.tsx +0 -180
- package/src/extensions/SlashCommand/groups.ts +0 -183
- package/src/extensions/SlashCommand/index.ts +0 -1
- package/src/extensions/SlashCommand/types.ts +0 -24
- package/src/extensions/Strike/Strike.ts +0 -26
- package/src/extensions/Strike/index.ts +0 -1
- package/src/extensions/Subscript/Subscript.ts +0 -88
- package/src/extensions/Subscript/index.ts +0 -1
- package/src/extensions/Table/Cell.ts +0 -131
- package/src/extensions/Table/Header.ts +0 -93
- package/src/extensions/Table/Row.ts +0 -8
- package/src/extensions/Table/Table.ts +0 -60
- package/src/extensions/Table/cell-background.ts +0 -112
- package/src/extensions/Table/components/CreateTablePopover.tsx +0 -132
- package/src/extensions/Table/components/TableActionButton.tsx +0 -42
- package/src/extensions/Table/index.ts +0 -6
- package/src/extensions/Table/utils.ts +0 -352
- package/src/extensions/TableOfContent/TableOfContent.ts +0 -124
- package/src/extensions/TableOfContent/components/NodeViewTableOfContent.tsx +0 -116
- package/src/extensions/TableOfContent/components/TableOfContentActionButton.tsx +0 -27
- package/src/extensions/TableOfContent/components/index.module.scss +0 -40
- package/src/extensions/TableOfContent/index.ts +0 -1
- package/src/extensions/TaskList/TaskList.ts +0 -46
- package/src/extensions/TaskList/index.ts +0 -1
- package/src/extensions/TextAlign/TextAlign.ts +0 -68
- package/src/extensions/TextAlign/components/TextAlignMenuButton.tsx +0 -103
- package/src/extensions/TextAlign/index.ts +0 -1
- package/src/extensions/TextBubble/TextBubble.ts +0 -22
- package/src/extensions/TextBubble/components/TextDropdown.tsx +0 -146
- package/src/extensions/TextBubble/index.ts +0 -1
- package/src/extensions/TextDirection/TextDirection.ts +0 -97
- package/src/extensions/TextDirection/components/TextDirectionButton.tsx +0 -103
- package/src/extensions/TextDirection/index.ts +0 -1
- package/src/extensions/TrailingNode/TrailingNode.ts +0 -71
- package/src/extensions/TrailingNode/index.ts +0 -1
- package/src/extensions/Twitter/Twitter.ts +0 -161
- package/src/extensions/Twitter/components/FormEditLinkTwitter.tsx +0 -68
- package/src/extensions/Twitter/components/NodeViewTweet.tsx +0 -30
- package/src/extensions/Twitter/components/TwitterActiveButton.tsx +0 -41
- package/src/extensions/Twitter/index.ts +0 -1
- package/src/extensions/UnderLine/Underline.ts +0 -30
- package/src/extensions/UnderLine/index.ts +0 -1
- package/src/extensions/Video/Video.ts +0 -204
- package/src/extensions/Video/components/ActiveVideoButton.tsx +0 -191
- package/src/extensions/Video/index.ts +0 -1
- package/src/extensions/Video/store.ts +0 -15
- package/src/extensions/index.ts +0 -122
- package/src/hooks/useActive.tsx +0 -24
- package/src/hooks/useAttributes.tsx +0 -45
- package/src/hooks/useCopy.tsx +0 -20
- package/src/hooks/useEditorState.tsx +0 -23
- package/src/hooks/useExtension.tsx +0 -29
- package/src/index.ts +0 -8
- package/src/lib/utils.ts +0 -7
- package/src/locale-bundle.ts +0 -3
- package/src/locales/en.ts +0 -173
- package/src/locales/hu.ts +0 -173
- package/src/locales/index.tsx +0 -163
- package/src/locales/pt-br.ts +0 -173
- package/src/locales/vi.ts +0 -173
- package/src/locales/zh-cn.ts +0 -173
- package/src/plugins/DragHandle/index.ts +0 -375
- package/src/plugins/DragHandle/range.ts +0 -114
- package/src/plugins/DragHandle/utils.ts +0 -80
- package/src/plugins/image-upload.ts +0 -160
- package/src/store/ProviderRichText.tsx +0 -53
- package/src/store/editableEditor.ts +0 -15
- package/src/store/fast-context.tsx +0 -70
- package/src/store/store.ts +0 -35
- package/src/styles/ProseMirror.scss +0 -176
- package/src/styles/columns.scss +0 -23
- package/src/styles/editor.scss +0 -411
- package/src/styles/global.scss +0 -87
- package/src/styles/index.scss +0 -5
- package/src/styles/mention.scss +0 -6
- package/src/theme/theme.ts +0 -15
- package/src/types.ts +0 -271
- package/src/utils/_event.ts +0 -55
- package/src/utils/color.ts +0 -67
- package/src/utils/columns.ts +0 -142
- package/src/utils/customEvents/customEvents.ts +0 -18
- package/src/utils/customEvents/events.constant.ts +0 -11
- package/src/utils/delete-node.ts +0 -46
- package/src/utils/dom-dataset.ts +0 -121
- package/src/utils/download.ts +0 -17
- package/src/utils/dynamicCSS.ts +0 -192
- package/src/utils/editor-container-size.ts +0 -28
- package/src/utils/file.ts +0 -112
- package/src/utils/getRenderContainer.ts +0 -41
- package/src/utils/indent.ts +0 -99
- package/src/utils/is-mobile.ts +0 -57
- package/src/utils/json.ts +0 -18
- package/src/utils/line-height.ts +0 -109
- package/src/utils/lru-cache.ts +0 -145
- package/src/utils/mitt.ts +0 -114
- package/src/utils/node.ts +0 -92
- package/src/utils/pdf.ts +0 -72
- package/src/utils/plateform.ts +0 -49
- package/src/utils/shortId.ts +0 -5
- package/src/utils/storage.ts +0 -18
- package/src/utils/utils.ts +0 -71
- package/src/vite-env.d.ts +0 -3
package/src/utils/dom-dataset.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
-
|
|
3
|
-
import { safeJSONParse } from 'reactjs-tiptap-editor-pro/utils/json';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param json
|
|
7
|
-
*/
|
|
8
|
-
export function jsonToStr(json: Record<string, unknown>) {
|
|
9
|
-
try {
|
|
10
|
-
return JSON.stringify(json);
|
|
11
|
-
} catch {
|
|
12
|
-
return JSON.stringify({});
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param str
|
|
18
|
-
*/
|
|
19
|
-
export function strToJSON(str: string) {
|
|
20
|
-
return safeJSONParse(str);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @param element
|
|
25
|
-
* @param json
|
|
26
|
-
*/
|
|
27
|
-
export function jsonToDOMDataset(json: Record<string, unknown>) {
|
|
28
|
-
return Object.keys(json).map((key) => {
|
|
29
|
-
let value = json[key];
|
|
30
|
-
|
|
31
|
-
if (typeof value === 'object') {
|
|
32
|
-
value = JSON.stringify(value);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
key: `data-${key}`,
|
|
37
|
-
value: encodeURIComponent(value as string),
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @param element
|
|
44
|
-
* @param attribute
|
|
45
|
-
* @param transformToJSON
|
|
46
|
-
*/
|
|
47
|
-
export function getDatasetAttribute(attribute: string, transformToJSON = false) {
|
|
48
|
-
return (element: HTMLElement) => {
|
|
49
|
-
const dataKey = attribute.startsWith('data-') ? attribute : `data-${attribute}`;
|
|
50
|
-
// @ts-ignore
|
|
51
|
-
let value = decodeURIComponent(element.getAttribute(dataKey));
|
|
52
|
-
|
|
53
|
-
if (value == null || (typeof value === 'string' && value === 'null')) {
|
|
54
|
-
try {
|
|
55
|
-
const html = element.outerHTML;
|
|
56
|
-
|
|
57
|
-
const texts = html.match(/([\S\s])+?="([\S\s])+?"/g);
|
|
58
|
-
if (texts && texts.length > 0) {
|
|
59
|
-
const params = texts
|
|
60
|
-
.map(str => str.trim())
|
|
61
|
-
.reduce((accu, item) => {
|
|
62
|
-
const i = item.indexOf('=');
|
|
63
|
-
const arr = [item.slice(0, i), item.slice(i + 1).slice(1, -1)];
|
|
64
|
-
// @ts-expect-error
|
|
65
|
-
accu[arr[0]] = arr[1];
|
|
66
|
-
return accu;
|
|
67
|
-
}, {});
|
|
68
|
-
|
|
69
|
-
// @ts-expect-error
|
|
70
|
-
value = (params[attribute.toLowerCase()] || '').replaceAll('"', '"');
|
|
71
|
-
}
|
|
72
|
-
} catch (e: any) {
|
|
73
|
-
console.error('Error getDatasetAttribute ', e.message, element);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (transformToJSON) {
|
|
78
|
-
try {
|
|
79
|
-
return JSON.parse(value);
|
|
80
|
-
} catch {
|
|
81
|
-
return {};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (value.includes('%') || value.includes('auto')) {
|
|
86
|
-
return value;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const toNumber = Number.parseInt(value);
|
|
90
|
-
return toNumber !== toNumber ? value : toNumber;
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 将节点属性转换为 dataset
|
|
96
|
-
* @param node
|
|
97
|
-
* @returns
|
|
98
|
-
*/
|
|
99
|
-
export function nodeAttrsToDataset(node: Node) {
|
|
100
|
-
const { attrs } = node as any;
|
|
101
|
-
|
|
102
|
-
return Object.keys(attrs).reduce((accu, key) => {
|
|
103
|
-
const value = attrs[key];
|
|
104
|
-
|
|
105
|
-
if (value == null) {
|
|
106
|
-
return accu;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
let encodeValue = '';
|
|
110
|
-
|
|
111
|
-
if (typeof value === 'object') {
|
|
112
|
-
encodeValue = jsonToStr(value);
|
|
113
|
-
} else {
|
|
114
|
-
encodeValue = value;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
accu[key] = encodeValue;
|
|
118
|
-
|
|
119
|
-
return accu;
|
|
120
|
-
}, Object.create(null));
|
|
121
|
-
}
|
package/src/utils/download.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const isBrowser = typeof window !== 'undefined';
|
|
2
|
-
|
|
3
|
-
export function downloadFromBlob(blob: Blob, filename: string) {
|
|
4
|
-
if (isBrowser) {
|
|
5
|
-
const url = window.URL.createObjectURL(blob);
|
|
6
|
-
const a = document.createElement('a');
|
|
7
|
-
a.href = url;
|
|
8
|
-
a.download = filename;
|
|
9
|
-
a.click();
|
|
10
|
-
window.URL.revokeObjectURL(url);
|
|
11
|
-
return Promise.resolve();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
console.error('Download is not supported in Node.js');
|
|
15
|
-
|
|
16
|
-
return Promise.resolve();
|
|
17
|
-
}
|
package/src/utils/dynamicCSS.ts
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
-
const APPEND_ORDER = 'data-rc-order';
|
|
3
|
-
const APPEND_PRIORITY = 'data-rc-priority';
|
|
4
|
-
const MARK_KEY = 'rc-util-key';
|
|
5
|
-
|
|
6
|
-
const containerCache = new Map<ContainerType, Node & ParentNode>();
|
|
7
|
-
|
|
8
|
-
export type ContainerType = Element | ShadowRoot;
|
|
9
|
-
export type Prepend = boolean | 'queue';
|
|
10
|
-
export type AppendType = 'prependQueue' | 'append' | 'prepend';
|
|
11
|
-
|
|
12
|
-
export default function contains(root: Node | null | undefined, n?: Node) {
|
|
13
|
-
if (!root) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Use native if support
|
|
18
|
-
if (root.contains) {
|
|
19
|
-
return root.contains(n as any);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// `document.contains` not support with IE11
|
|
23
|
-
let node = n;
|
|
24
|
-
while (node) {
|
|
25
|
-
if (node === root) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
node = node.parentNode;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface Options {
|
|
36
|
-
attachTo?: ContainerType
|
|
37
|
-
csp?: { nonce?: string }
|
|
38
|
-
prepend?: Prepend
|
|
39
|
-
/**
|
|
40
|
-
* Config the `priority` of `prependQueue`. Default is `0`.
|
|
41
|
-
* It's useful if you need to insert style before other style.
|
|
42
|
-
*/
|
|
43
|
-
priority?: number
|
|
44
|
-
mark?: string
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function getMark({ mark }: Options = {}) {
|
|
48
|
-
if (mark) {
|
|
49
|
-
return mark.startsWith('data-') ? mark : `data-${mark}`;
|
|
50
|
-
}
|
|
51
|
-
return MARK_KEY;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function getContainer(option: Options) {
|
|
55
|
-
if (option.attachTo) {
|
|
56
|
-
return option.attachTo;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const head = document.querySelector('head');
|
|
60
|
-
return head || document.body;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function getOrder(prepend?: Prepend): AppendType {
|
|
64
|
-
if (prepend === 'queue') {
|
|
65
|
-
return 'prependQueue';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return prepend ? 'prepend' : 'append';
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Find style which inject by rc-util
|
|
73
|
-
*/
|
|
74
|
-
function findStyles(container: ContainerType) {
|
|
75
|
-
return [...(containerCache.get(container) || container).children].filter(
|
|
76
|
-
node => node.tagName === 'STYLE',
|
|
77
|
-
) as HTMLStyleElement[];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function injectCSS(css: string, option: Options = {}) {
|
|
81
|
-
const { csp, prepend, priority = 0 } = option;
|
|
82
|
-
const mergedOrder = getOrder(prepend);
|
|
83
|
-
const isPrependQueue = mergedOrder === 'prependQueue';
|
|
84
|
-
|
|
85
|
-
const styleNode = document.createElement('style');
|
|
86
|
-
styleNode.setAttribute(APPEND_ORDER, mergedOrder);
|
|
87
|
-
|
|
88
|
-
if (isPrependQueue && priority) {
|
|
89
|
-
styleNode.setAttribute(APPEND_PRIORITY, `${priority}`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (csp?.nonce) {
|
|
93
|
-
styleNode.nonce = csp?.nonce;
|
|
94
|
-
}
|
|
95
|
-
styleNode.innerHTML = css;
|
|
96
|
-
|
|
97
|
-
const container = getContainer(option);
|
|
98
|
-
const { firstChild } = container as any;
|
|
99
|
-
|
|
100
|
-
if (prepend) {
|
|
101
|
-
// If is queue `prepend`, it will prepend first style and then append rest style
|
|
102
|
-
if (isPrependQueue) {
|
|
103
|
-
const existStyle = findStyles(container).filter((node) => {
|
|
104
|
-
// Ignore style which not injected by rc-util with prepend
|
|
105
|
-
// @ts-ignore
|
|
106
|
-
if (!['prepend', 'prependQueue'].includes(node.getAttribute(APPEND_ORDER))) {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Ignore style which priority less then new style
|
|
111
|
-
const nodePriority = Number(node.getAttribute(APPEND_PRIORITY) || 0);
|
|
112
|
-
return priority >= nodePriority;
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
if (existStyle.length > 0) {
|
|
116
|
-
// @ts-ignore
|
|
117
|
-
container.insertBefore(styleNode, existStyle.at(-1).nextSibling);
|
|
118
|
-
|
|
119
|
-
return styleNode;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Use `insertBefore` as `prepend`
|
|
124
|
-
firstChild.before(styleNode);
|
|
125
|
-
} else {
|
|
126
|
-
container.append(styleNode);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return styleNode;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function findExistNode(key: string, option: Options = {}) {
|
|
133
|
-
const container = getContainer(option);
|
|
134
|
-
|
|
135
|
-
return findStyles(container).find(node => node.getAttribute(getMark(option)) === key);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function removeCSS(key: string, option: Options = {}) {
|
|
139
|
-
const existNode = findExistNode(key, option);
|
|
140
|
-
if (existNode) {
|
|
141
|
-
// const container = getContainer(option);
|
|
142
|
-
existNode.remove();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* qiankun will inject `appendChild` to insert into other
|
|
148
|
-
*/
|
|
149
|
-
function syncRealContainer(container: ContainerType, option: Options) {
|
|
150
|
-
const cachedRealContainer = containerCache.get(container);
|
|
151
|
-
|
|
152
|
-
// Find real container when not cached or cached container removed
|
|
153
|
-
if (!cachedRealContainer || !contains(document, cachedRealContainer)) {
|
|
154
|
-
const placeholderStyle = injectCSS('', option);
|
|
155
|
-
const { parentNode } = placeholderStyle;
|
|
156
|
-
// @ts-ignore
|
|
157
|
-
containerCache.set(container, parentNode);
|
|
158
|
-
placeholderStyle.remove();
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* manually clear container cache to avoid global cache in unit testes
|
|
164
|
-
*/
|
|
165
|
-
export function clearContainerCache() {
|
|
166
|
-
containerCache.clear();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function updateCSS(css: string, key: string, option: Options = {}) {
|
|
170
|
-
const container = getContainer(option);
|
|
171
|
-
|
|
172
|
-
// Sync real parent
|
|
173
|
-
syncRealContainer(container, option);
|
|
174
|
-
|
|
175
|
-
const existNode = findExistNode(key, option);
|
|
176
|
-
|
|
177
|
-
if (existNode) {
|
|
178
|
-
if (option.csp?.nonce && existNode.nonce !== option.csp?.nonce) {
|
|
179
|
-
existNode.nonce = option.csp?.nonce;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (existNode.innerHTML !== css) {
|
|
183
|
-
existNode.innerHTML = css;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return existNode;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const newNode = injectCSS(css, option);
|
|
190
|
-
newNode.setAttribute(getMark(option), key);
|
|
191
|
-
return newNode;
|
|
192
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Editor } from '@tiptap/core';
|
|
2
|
-
|
|
3
|
-
const cache = new Map();
|
|
4
|
-
|
|
5
|
-
export function getEditorContainerDOMSize(editor: Editor): { width: number } {
|
|
6
|
-
const targetNode = editor.options.element as HTMLElement;
|
|
7
|
-
|
|
8
|
-
if (!cache.has('width')) {
|
|
9
|
-
cache.set('width', targetNode.clientWidth);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (cache.has('width') && cache.get('width') <= 0) {
|
|
13
|
-
cache.set('width', targetNode.clientWidth);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const config = { attributes: true, childList: true, subtree: true };
|
|
17
|
-
const callback = function () {
|
|
18
|
-
cache.set('width', targetNode.clientWidth);
|
|
19
|
-
};
|
|
20
|
-
const observer = new MutationObserver(callback);
|
|
21
|
-
observer.observe(targetNode, config);
|
|
22
|
-
|
|
23
|
-
editor.on('destroy', () => {
|
|
24
|
-
observer.disconnect();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
return { width: cache.get('width') };
|
|
28
|
-
}
|
package/src/utils/file.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/* eslint-disable unicorn/prefer-add-event-listener */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
/**
|
|
4
|
-
* 获取文件名
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* > extractFilename('https://gitlab.com/images/logo-full.png')
|
|
8
|
-
* < 'logo-full'
|
|
9
|
-
*
|
|
10
|
-
* @param {string} src The URL to extract filename from
|
|
11
|
-
* @returns {string}
|
|
12
|
-
*/
|
|
13
|
-
export function extractFilename(src: any) {
|
|
14
|
-
return src.replace(/^.*\/|\..+$/g, '');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* extractFileExtension
|
|
19
|
-
* @param {string} fileName The file name to extract extension from
|
|
20
|
-
* @returns {string}
|
|
21
|
-
*/
|
|
22
|
-
export function extractFileExtension(fileName: any) {
|
|
23
|
-
return fileName.split('.').pop();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function normalizeFileSize(size: any) {
|
|
27
|
-
if (size < 1024) {
|
|
28
|
-
return `${size} Byte`;
|
|
29
|
-
}
|
|
30
|
-
if (size < 1024 * 1024) {
|
|
31
|
-
return `${(size / 1024).toFixed(2)} KB`;
|
|
32
|
-
}
|
|
33
|
-
return `${(size / 1024 / 1024).toFixed(2)} MB`;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type FileType = 'image' | 'audio' | 'video' | 'pdf' | 'word' | 'excel' | 'ppt' | 'file';
|
|
37
|
-
|
|
38
|
-
export function normalizeFileType(fileType: any): FileType {
|
|
39
|
-
if (!fileType)
|
|
40
|
-
return 'file';
|
|
41
|
-
|
|
42
|
-
if (fileType === 'application/pdf')
|
|
43
|
-
return 'pdf';
|
|
44
|
-
|
|
45
|
-
if (fileType.startsWith('application/') && ['.document', 'word'].some(type => fileType.includes(type)))
|
|
46
|
-
return 'word';
|
|
47
|
-
|
|
48
|
-
if (fileType.startsWith('application/') && ['presentation'].some(type => fileType.includes(type)))
|
|
49
|
-
return 'excel';
|
|
50
|
-
|
|
51
|
-
if (fileType.startsWith('application/') && ['sheet'].some(type => fileType.includes(type)))
|
|
52
|
-
return 'ppt';
|
|
53
|
-
|
|
54
|
-
if (fileType.startsWith('image')) {
|
|
55
|
-
return 'image';
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (fileType.startsWith('audio')) {
|
|
59
|
-
return 'audio';
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (fileType.startsWith('video')) {
|
|
63
|
-
return 'video';
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return 'file';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function readImageAsBase64(file: File): Promise<{ alt: string, src: string }> {
|
|
70
|
-
return new Promise((resolve) => {
|
|
71
|
-
const reader = new FileReader();
|
|
72
|
-
reader.addEventListener(
|
|
73
|
-
'load',
|
|
74
|
-
() => {
|
|
75
|
-
resolve({
|
|
76
|
-
alt: file.name,
|
|
77
|
-
src: reader.result as string,
|
|
78
|
-
});
|
|
79
|
-
},
|
|
80
|
-
false,
|
|
81
|
-
);
|
|
82
|
-
reader.readAsDataURL(file);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function getImageWidthHeight(url: string): Promise<{ width: number | string, height: number | string }> {
|
|
87
|
-
return new Promise((resolve) => {
|
|
88
|
-
const img = document.createElement('img');
|
|
89
|
-
img.addEventListener('load', () => {
|
|
90
|
-
resolve({ width: img.width, height: img.height });
|
|
91
|
-
});
|
|
92
|
-
img.onerror = () => {
|
|
93
|
-
resolve({ width: 'auto', height: 'auto' });
|
|
94
|
-
};
|
|
95
|
-
img.src = url;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export const FILE_CHUNK_SIZE = 2 * 1024 * 1024;
|
|
100
|
-
|
|
101
|
-
export function dataURLtoFile(dataurl: string, filename: string) {
|
|
102
|
-
const arr = dataurl.split(',');
|
|
103
|
-
// @ts-expect-error
|
|
104
|
-
const mime = arr[0].match(/:(.*?);/)[1];
|
|
105
|
-
const bstr = atob(arr[arr.length - 1]);
|
|
106
|
-
let n = bstr.length;
|
|
107
|
-
const u8arr = new Uint8Array(n);
|
|
108
|
-
while (n--) {
|
|
109
|
-
u8arr[n] = bstr.charCodeAt(n);
|
|
110
|
-
}
|
|
111
|
-
return new File([u8arr], filename, { type: mime });
|
|
112
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Editor } from '@tiptap/react';
|
|
2
|
-
|
|
3
|
-
export function getRenderContainer(editor: Editor, nodeType: string) {
|
|
4
|
-
const {
|
|
5
|
-
view,
|
|
6
|
-
state: {
|
|
7
|
-
selection: { from },
|
|
8
|
-
},
|
|
9
|
-
} = editor;
|
|
10
|
-
|
|
11
|
-
const elements = document.querySelectorAll('.has-focus');
|
|
12
|
-
const elementCount = elements.length;
|
|
13
|
-
const innermostNode = elements[elementCount - 1];
|
|
14
|
-
const element = innermostNode as any;
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
(element && element.dataset.type && element.dataset.type === nodeType)
|
|
18
|
-
|| (element && element.classList && element.classList.contains(nodeType))
|
|
19
|
-
) {
|
|
20
|
-
return element;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const node = view.domAtPos(from).node as HTMLElement;
|
|
24
|
-
let container: any = node;
|
|
25
|
-
|
|
26
|
-
if (!container.tagName) {
|
|
27
|
-
container = node.parentElement;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
while (
|
|
31
|
-
container
|
|
32
|
-
&& !(container.dataset.type && container.dataset.type === nodeType)
|
|
33
|
-
&& !container.classList.contains(nodeType)
|
|
34
|
-
) {
|
|
35
|
-
container = container.parentElement;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return container;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default getRenderContainer;
|
package/src/utils/indent.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-restricted-syntax */
|
|
2
|
-
import type { Command, Editor } from '@tiptap/core';
|
|
3
|
-
import { isList } from '@tiptap/core';
|
|
4
|
-
import type { Transaction } from '@tiptap/pm/state';
|
|
5
|
-
import { AllSelection, TextSelection } from '@tiptap/pm/state';
|
|
6
|
-
|
|
7
|
-
export const enum IndentProps {
|
|
8
|
-
max = 7,
|
|
9
|
-
min = 0,
|
|
10
|
-
|
|
11
|
-
more = 1,
|
|
12
|
-
less = -1,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function clamp(val: number, min: number, max: number): number {
|
|
16
|
-
if (val < min) {
|
|
17
|
-
return min;
|
|
18
|
-
}
|
|
19
|
-
if (val > max) {
|
|
20
|
-
return max;
|
|
21
|
-
}
|
|
22
|
-
return val;
|
|
23
|
-
}
|
|
24
|
-
function updateIndentLevel(
|
|
25
|
-
tr: Transaction,
|
|
26
|
-
delta: number,
|
|
27
|
-
types: string[],
|
|
28
|
-
editor: Editor,
|
|
29
|
-
): Transaction {
|
|
30
|
-
const { doc, selection } = tr;
|
|
31
|
-
|
|
32
|
-
if (!doc || !selection) {
|
|
33
|
-
return tr;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (!(selection instanceof TextSelection || selection instanceof AllSelection)) {
|
|
37
|
-
return tr;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const { from, to } = selection;
|
|
41
|
-
|
|
42
|
-
doc.nodesBetween(from, to, (node, pos) => {
|
|
43
|
-
const nodeType = node.type;
|
|
44
|
-
|
|
45
|
-
if (types.includes(nodeType.name)) {
|
|
46
|
-
tr = setNodeIndentMarkup(tr, pos, delta);
|
|
47
|
-
return false;
|
|
48
|
-
} else if (isList(node.type.name, editor.extensionManager.extensions)) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
return true;
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
return tr;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function setNodeIndentMarkup(tr: Transaction, pos: number, delta: number): Transaction {
|
|
58
|
-
if (!tr.doc) {
|
|
59
|
-
return tr;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const node = tr.doc.nodeAt(pos);
|
|
63
|
-
if (!node) {
|
|
64
|
-
return tr;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const minIndent = IndentProps.min;
|
|
68
|
-
const maxIndent = IndentProps.max;
|
|
69
|
-
|
|
70
|
-
const indent = clamp((node.attrs.indent || 0) + delta, minIndent, maxIndent);
|
|
71
|
-
|
|
72
|
-
if (indent === node.attrs.indent) {
|
|
73
|
-
return tr;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const nodeAttrs = {
|
|
77
|
-
...node.attrs,
|
|
78
|
-
indent,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
return tr.setNodeMarkup(pos, node.type, nodeAttrs, node.marks);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function createIndentCommand({ delta, types }: { delta: number, types: string[] }): Command {
|
|
85
|
-
return ({ state, dispatch, editor }) => {
|
|
86
|
-
const { selection } = state;
|
|
87
|
-
let { tr } = state;
|
|
88
|
-
tr = tr.setSelection(selection);
|
|
89
|
-
tr = updateIndentLevel(tr, delta, types, editor);
|
|
90
|
-
|
|
91
|
-
if (tr.docChanged) {
|
|
92
|
-
if (dispatch)
|
|
93
|
-
dispatch(tr);
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return false;
|
|
98
|
-
};
|
|
99
|
-
}
|
package/src/utils/is-mobile.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
interface HttpRequestHeadersInterfaceMock {
|
|
2
|
-
[id: string]: string | string[] | undefined
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
interface HttpRequestInterfaceMock {
|
|
6
|
-
headers: HttpRequestHeadersInterfaceMock
|
|
7
|
-
[id: string]: any
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface IsMobileOptions {
|
|
11
|
-
ua?: string | HttpRequestInterfaceMock
|
|
12
|
-
tablet?: boolean
|
|
13
|
-
featureDetect?: boolean
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const mobileRE
|
|
17
|
-
= /(android|bb\d+|meego).+mobile|armv7l|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series[46]0|samsungbrowser.*mobile|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i;
|
|
18
|
-
const notMobileRE = /CrOS/;
|
|
19
|
-
const tabletRE = /android|ipad|playbook|silk/i;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Determines if the current device is a mobile or tablet device.
|
|
23
|
-
* @param opts - Options for the detection.
|
|
24
|
-
* @returns `true` if the device is mobile or tablet, `false` otherwise.
|
|
25
|
-
*/
|
|
26
|
-
export function isMobile(opts: IsMobileOptions = {}): boolean {
|
|
27
|
-
let ua = opts.ua || (typeof navigator !== 'undefined' && navigator.userAgent);
|
|
28
|
-
|
|
29
|
-
if (ua && typeof ua === 'object' && ua.headers && typeof ua.headers['user-agent'] === 'string') {
|
|
30
|
-
ua = ua.headers['user-agent'];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (typeof ua !== 'string') {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (mobileRE.test(ua) && !notMobileRE.test(ua)) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (opts.tablet && tabletRE.test(ua)) {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
opts.tablet
|
|
47
|
-
&& opts.featureDetect
|
|
48
|
-
&& navigator
|
|
49
|
-
&& navigator.maxTouchPoints > 1
|
|
50
|
-
&& ua.includes('Macintosh')
|
|
51
|
-
&& ua.includes('Safari')
|
|
52
|
-
) {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return false;
|
|
57
|
-
}
|
package/src/utils/json.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export function safeJSONParse(str: any, defaultValue = {}) {
|
|
2
|
-
if (typeof str === 'object')
|
|
3
|
-
return str;
|
|
4
|
-
|
|
5
|
-
try {
|
|
6
|
-
return JSON.parse(str);
|
|
7
|
-
} catch {
|
|
8
|
-
return defaultValue;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function safeJSONStringify(obj: any, defaultValue = '{}') {
|
|
13
|
-
try {
|
|
14
|
-
return JSON.stringify(obj);
|
|
15
|
-
} catch {
|
|
16
|
-
return defaultValue;
|
|
17
|
-
}
|
|
18
|
-
}
|