@antscorp/antsomi-ui 2.0.85 → 2.0.86-text-editor-beta.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/es/assets/css/main.scss +4 -2
- package/es/components/index.scss +2 -0
- package/es/components/molecules/EmojiPopover/EmojiPopover.js +5 -1
- package/es/components/molecules/FontSizeInput/FontSizeInput.d.ts +3 -0
- package/es/components/molecules/FontSizeInput/FontSizeInput.js +128 -0
- package/es/components/molecules/FontSizeInput/components/FontSizeControl.d.ts +8 -0
- package/es/components/molecules/FontSizeInput/components/FontSizeControl.js +14 -0
- package/es/components/molecules/FontSizeInput/components/FontSizeDropdown.d.ts +20 -0
- package/es/components/molecules/FontSizeInput/components/FontSizeDropdown.js +17 -0
- package/es/components/molecules/FontSizeInput/constants.d.ts +2 -0
- package/es/components/molecules/FontSizeInput/constants.js +5 -0
- package/es/components/molecules/FontSizeInput/index.d.ts +2 -0
- package/es/components/molecules/FontSizeInput/index.js +1 -0
- package/es/components/molecules/FontSizeInput/styled.d.ts +3 -0
- package/es/components/molecules/FontSizeInput/styled.js +22 -0
- package/es/components/molecules/FontSizeInput/styles.scss +15 -0
- package/es/components/molecules/FontSizeInput/types.d.ts +24 -0
- package/es/components/molecules/FontSizeInput/types.js +1 -0
- package/es/components/molecules/FontSizeInput/utils.d.ts +7 -0
- package/es/components/molecules/FontSizeInput/utils.js +9 -0
- package/es/components/molecules/VirtualizedMenu/VirtualizedMenu.d.ts +6 -3
- package/es/components/molecules/VirtualizedMenu/__mocks__/index.js +2550 -938
- package/es/components/molecules/VirtualizedMenu/components/Item/Item.d.ts +13 -3
- package/es/components/molecules/VirtualizedMenu/components/Item/Item.js +53 -25
- package/es/components/molecules/VirtualizedMenu/components/Item/index.d.ts +1 -1
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.d.ts +8 -5
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.js +289 -46
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.js +1 -0
- package/es/components/molecules/VirtualizedMenu/styled.d.ts +1 -1
- package/es/components/molecules/VirtualizedMenu/styled.js +23 -4
- package/es/components/molecules/VirtualizedMenu/types.d.ts +6 -9
- package/es/components/molecules/VirtualizedMenu/utils.d.ts +8 -5
- package/es/components/molecules/VirtualizedMenu/utils.js +13 -18
- package/es/components/molecules/index.d.ts +1 -0
- package/es/components/molecules/index.js +1 -0
- package/es/components/molecules/index.scss +1 -0
- package/es/components/organism/ActivityTimeline/__mocks__/event_tracking.json +1290 -0
- package/es/components/organism/ActivityTimeline/__mocks__/timeline.json +3059 -0
- package/es/components/organism/TextEditor/TextEditor.d.ts +3 -0
- package/es/components/organism/TextEditor/TextEditor.js +251 -0
- package/es/components/organism/TextEditor/__mocks__/text-block.settings.json +320 -0
- package/es/components/organism/TextEditor/__mocks__/text-contennt.d.ts +1 -0
- package/es/components/organism/TextEditor/__mocks__/text-contennt.js +38 -0
- package/es/components/organism/TextEditor/constants.d.ts +135 -0
- package/es/components/organism/TextEditor/constants.js +280 -0
- package/es/components/organism/TextEditor/extensions/BackgroundColor.d.ts +25 -0
- package/es/components/organism/TextEditor/extensions/BackgroundColor.js +46 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.d.ts +130 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.js +247 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.d.ts +15 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.js +31 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/index.d.ts +2 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/index.js +2 -0
- package/es/components/organism/TextEditor/extensions/Color.d.ts +6 -0
- package/es/components/organism/TextEditor/extensions/Color.js +41 -0
- package/es/components/organism/TextEditor/extensions/Emoji.d.ts +57 -0
- package/es/components/organism/TextEditor/extensions/Emoji.js +184 -0
- package/es/components/organism/TextEditor/extensions/FontFamily.d.ts +6 -0
- package/es/components/organism/TextEditor/extensions/FontFamily.js +43 -0
- package/es/components/organism/TextEditor/extensions/FontSize.d.ts +32 -0
- package/es/components/organism/TextEditor/extensions/FontSize.js +47 -0
- package/es/components/organism/TextEditor/extensions/FontWeight.d.ts +23 -0
- package/es/components/organism/TextEditor/extensions/FontWeight.js +41 -0
- package/es/components/organism/TextEditor/extensions/Highlight.d.ts +1 -0
- package/es/components/organism/TextEditor/extensions/Highlight.js +14 -0
- package/es/components/organism/TextEditor/extensions/Indent.d.ts +28 -0
- package/es/components/organism/TextEditor/extensions/Indent.js +68 -0
- package/es/components/organism/TextEditor/extensions/LineHeight.d.ts +20 -0
- package/es/components/organism/TextEditor/extensions/LineHeight.js +36 -0
- package/es/components/organism/TextEditor/extensions/Link.d.ts +15 -0
- package/es/components/organism/TextEditor/extensions/Link.js +50 -0
- package/es/components/organism/TextEditor/extensions/ListItemMarker.d.ts +13 -0
- package/es/components/organism/TextEditor/extensions/ListItemMarker.js +174 -0
- package/es/components/organism/TextEditor/extensions/Selection.d.ts +6 -0
- package/es/components/organism/TextEditor/extensions/Selection.js +40 -0
- package/es/components/organism/TextEditor/extensions/SmartTag.d.ts +39 -0
- package/es/components/organism/TextEditor/extensions/SmartTag.js +167 -0
- package/es/components/organism/TextEditor/extensions/StyleMemory.d.ts +36 -0
- package/es/components/organism/TextEditor/extensions/StyleMemory.js +163 -0
- package/es/components/organism/TextEditor/extensions/TextTransform.d.ts +31 -0
- package/es/components/organism/TextEditor/extensions/TextTransform.js +37 -0
- package/es/components/organism/TextEditor/hooks/index.d.ts +6 -0
- package/es/components/organism/TextEditor/hooks/index.js +6 -0
- package/es/components/organism/TextEditor/hooks/useDocumentState.d.ts +18 -0
- package/es/components/organism/TextEditor/hooks/useDocumentState.js +42 -0
- package/es/components/organism/TextEditor/hooks/useLinkHandler.d.ts +10 -0
- package/es/components/organism/TextEditor/hooks/useLinkHandler.js +223 -0
- package/es/components/organism/TextEditor/hooks/useMarkTracking.d.ts +26 -0
- package/es/components/organism/TextEditor/hooks/useMarkTracking.js +68 -0
- package/es/components/organism/TextEditor/hooks/usePersistence.d.ts +31 -0
- package/es/components/organism/TextEditor/hooks/usePersistence.js +169 -0
- package/es/components/organism/TextEditor/hooks/useStyleMemory.d.ts +6 -0
- package/es/components/organism/TextEditor/hooks/useStyleMemory.js +42 -0
- package/es/components/organism/TextEditor/hooks/useStylePresets.d.ts +34 -0
- package/es/components/organism/TextEditor/hooks/useStylePresets.js +83 -0
- package/es/components/organism/TextEditor/index.d.ts +14 -0
- package/es/components/organism/TextEditor/index.js +6 -0
- package/es/components/organism/TextEditor/index.scss +61 -0
- package/es/components/organism/TextEditor/provider.d.ts +10 -0
- package/es/components/organism/TextEditor/provider.js +20 -0
- package/es/components/organism/TextEditor/store.d.ts +11 -0
- package/es/components/organism/TextEditor/store.js +12 -0
- package/es/components/organism/TextEditor/styled.d.ts +8 -0
- package/es/components/organism/TextEditor/styled.js +90 -0
- package/es/components/organism/TextEditor/types.d.ts +92 -0
- package/es/components/organism/TextEditor/types.js +1 -0
- package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.d.ts +6 -0
- package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.js +78 -0
- package/es/components/organism/TextEditor/ui/BubbleMenu/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/BubbleMenu/index.js +1 -0
- package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.d.ts +43 -0
- package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.js +120 -0
- package/es/components/organism/TextEditor/ui/ColorPicker/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/ColorPicker/index.js +1 -0
- package/es/components/organism/TextEditor/ui/Emoji/EmojiList.d.ts +11 -0
- package/es/components/organism/TextEditor/ui/Emoji/EmojiList.js +66 -0
- package/es/components/organism/TextEditor/ui/Emoji/index.d.ts +2 -0
- package/es/components/organism/TextEditor/ui/Emoji/index.js +2 -0
- package/es/components/organism/TextEditor/ui/Emoji/suggestion.d.ts +4 -0
- package/es/components/organism/TextEditor/ui/Emoji/suggestion.js +71 -0
- package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.d.ts +12 -0
- package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.js +69 -0
- package/es/components/organism/TextEditor/ui/FontPopover/styled.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/FontPopover/styled.js +20 -0
- package/es/components/organism/TextEditor/ui/Popover/Popover.d.ts +6 -0
- package/es/components/organism/TextEditor/ui/Popover/Popover.js +7 -0
- package/es/components/organism/TextEditor/ui/Popover/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/Popover/index.js +1 -0
- package/es/components/organism/TextEditor/ui/Select/Select.d.ts +4 -0
- package/es/components/organism/TextEditor/ui/Select/Select.js +7 -0
- package/es/components/organism/TextEditor/ui/Select/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/Select/index.js +1 -0
- package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.d.ts +30 -0
- package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.js +49 -0
- package/es/components/organism/TextEditor/ui/TextAlignSelect/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/TextAlignSelect/index.js +1 -0
- package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.d.ts +14 -0
- package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.js +42 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.js +18 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.d.ts +4 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.js +13 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.d.ts +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.js +18 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.d.ts +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.js +37 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.d.ts +6 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.js +4 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.d.ts +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.js +9 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.d.ts +9 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.js +22 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.js +13 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.js +13 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.js +3 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.d.ts +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.js +19 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.d.ts +15 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.js +14 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.js +30 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.js +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.d.ts +6 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.js +10 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/index.d.ts +20 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/index.js +20 -0
- package/es/components/organism/TextEditor/ui/Toolbar/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/Toolbar/index.js +1 -0
- package/es/components/organism/TextEditor/utils/documentState.d.ts +57 -0
- package/es/components/organism/TextEditor/utils/documentState.js +100 -0
- package/es/components/organism/TextEditor/utils/font.d.ts +84 -0
- package/es/components/organism/TextEditor/utils/font.js +175 -0
- package/es/components/organism/TextEditor/utils/htmlProcessing.d.ts +63 -0
- package/es/components/organism/TextEditor/utils/htmlProcessing.js +321 -0
- package/es/components/organism/TextEditor/utils/index.d.ts +8 -0
- package/es/components/organism/TextEditor/utils/index.js +16 -0
- package/es/components/organism/TextEditor/utils/link.d.ts +100 -0
- package/es/components/organism/TextEditor/utils/link.js +149 -0
- package/es/components/organism/TextEditor/utils/menu.d.ts +134 -0
- package/es/components/organism/TextEditor/utils/menu.js +317 -0
- package/es/components/organism/TextEditor/utils/selection.d.ts +25 -0
- package/es/components/organism/TextEditor/utils/selection.js +57 -0
- package/es/components/organism/TextEditor/utils/smartTag.d.ts +49 -0
- package/es/components/organism/TextEditor/utils/smartTag.js +89 -0
- package/es/components/organism/TextEditor/utils/style.d.ts +78 -0
- package/es/components/organism/TextEditor/utils/style.js +193 -0
- package/es/components/organism/index.d.ts +1 -0
- package/es/components/organism/index.js +1 -0
- package/es/components/organism/index.scss +1 -0
- package/es/config/index.d.ts +1 -0
- package/es/config/index.js +1 -0
- package/es/constants/api.d.ts +10 -0
- package/es/constants/api.js +10 -0
- package/es/hooks/index.d.ts +1 -0
- package/es/hooks/index.js +1 -0
- package/es/hooks/useBroadcastedLocalStorage.d.ts +5 -0
- package/es/hooks/useBroadcastedLocalStorage.js +71 -0
- package/es/hooks/useElementSize.d.ts +7 -0
- package/es/hooks/useElementSize.js +56 -0
- package/es/utils/common.d.ts +6 -9
- package/es/utils/common.js +44 -23
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +1 -0
- package/es/utils/tree.d.ts +225 -0
- package/es/utils/tree.js +469 -0
- package/es/utils/web.d.ts +4 -0
- package/es/utils/web.js +25 -0
- package/package.json +29 -3
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { arrow, autoPlacement, computePosition, flip, hide, inline, offset, shift, size, } from '@floating-ui/dom';
|
|
2
|
+
import { isTextSelection, posToDOMRect } from '@tiptap/core';
|
|
3
|
+
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
4
|
+
export class BubbleMenuView {
|
|
5
|
+
get middlewares() {
|
|
6
|
+
const middlewares = [];
|
|
7
|
+
if (this.floatingUIOptions.flip) {
|
|
8
|
+
middlewares.push(flip(typeof this.floatingUIOptions.flip !== 'boolean'
|
|
9
|
+
? this.floatingUIOptions.flip
|
|
10
|
+
: undefined));
|
|
11
|
+
}
|
|
12
|
+
if (this.floatingUIOptions.shift) {
|
|
13
|
+
middlewares.push(shift(typeof this.floatingUIOptions.shift !== 'boolean'
|
|
14
|
+
? this.floatingUIOptions.shift
|
|
15
|
+
: undefined));
|
|
16
|
+
}
|
|
17
|
+
if (this.floatingUIOptions.offset) {
|
|
18
|
+
middlewares.push(offset(typeof this.floatingUIOptions.offset !== 'boolean'
|
|
19
|
+
? this.floatingUIOptions.offset
|
|
20
|
+
: undefined));
|
|
21
|
+
}
|
|
22
|
+
if (this.floatingUIOptions.arrow) {
|
|
23
|
+
middlewares.push(arrow(this.floatingUIOptions.arrow));
|
|
24
|
+
}
|
|
25
|
+
if (this.floatingUIOptions.size) {
|
|
26
|
+
middlewares.push(size(typeof this.floatingUIOptions.size !== 'boolean'
|
|
27
|
+
? this.floatingUIOptions.size
|
|
28
|
+
: undefined));
|
|
29
|
+
}
|
|
30
|
+
if (this.floatingUIOptions.autoPlacement) {
|
|
31
|
+
middlewares.push(autoPlacement(typeof this.floatingUIOptions.autoPlacement !== 'boolean'
|
|
32
|
+
? this.floatingUIOptions.autoPlacement
|
|
33
|
+
: undefined));
|
|
34
|
+
}
|
|
35
|
+
if (this.floatingUIOptions.hide) {
|
|
36
|
+
middlewares.push(hide(typeof this.floatingUIOptions.hide !== 'boolean'
|
|
37
|
+
? this.floatingUIOptions.hide
|
|
38
|
+
: undefined));
|
|
39
|
+
}
|
|
40
|
+
if (this.floatingUIOptions.inline) {
|
|
41
|
+
middlewares.push(inline(typeof this.floatingUIOptions.inline !== 'boolean'
|
|
42
|
+
? this.floatingUIOptions.inline
|
|
43
|
+
: undefined));
|
|
44
|
+
}
|
|
45
|
+
return middlewares;
|
|
46
|
+
}
|
|
47
|
+
constructor({ editor, element, view, updateDelay = 250, resizeDelay = 60, container, shouldShow, options, onShow, onHide, }) {
|
|
48
|
+
this.preventHide = false;
|
|
49
|
+
this.floatingUIOptions = {
|
|
50
|
+
strategy: 'absolute',
|
|
51
|
+
placement: 'top',
|
|
52
|
+
offset: 8,
|
|
53
|
+
flip: {},
|
|
54
|
+
shift: {},
|
|
55
|
+
arrow: false,
|
|
56
|
+
size: false,
|
|
57
|
+
autoPlacement: false,
|
|
58
|
+
hide: false,
|
|
59
|
+
inline: false,
|
|
60
|
+
};
|
|
61
|
+
this.shouldShow = ({ view, state, from, to, }) => {
|
|
62
|
+
const { doc, selection } = state;
|
|
63
|
+
const { empty } = selection;
|
|
64
|
+
// Sometime check for `empty` is not enough.
|
|
65
|
+
// Doubleclick an empty paragraph returns a node size of 2.
|
|
66
|
+
// So we check also for an empty text size.
|
|
67
|
+
const isEmptyTextBlock = !doc.textBetween(from, to).length && isTextSelection(state.selection);
|
|
68
|
+
// When clicking on a element inside the bubble menu the editor "blur" event
|
|
69
|
+
// is called and the bubble menu item is focussed. In this case we should
|
|
70
|
+
// consider the menu as part of the editor and keep showing the menu
|
|
71
|
+
const isChildOfMenu = this.element.contains(document.activeElement);
|
|
72
|
+
const hasEditorFocus = view.hasFocus() || isChildOfMenu;
|
|
73
|
+
if (!hasEditorFocus || empty || isEmptyTextBlock || !this.editor.isEditable) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
};
|
|
78
|
+
this.mousedownHandler = () => {
|
|
79
|
+
this.preventHide = true;
|
|
80
|
+
};
|
|
81
|
+
this.dragstartHandler = () => {
|
|
82
|
+
this.hide();
|
|
83
|
+
};
|
|
84
|
+
this.focusHandler = () => {
|
|
85
|
+
// we use `setTimeout` to make sure `selection` is already updated
|
|
86
|
+
setTimeout(() => this.update(this.editor.view));
|
|
87
|
+
};
|
|
88
|
+
this.blurHandler = ({ event }) => {
|
|
89
|
+
if (this.preventHide) {
|
|
90
|
+
this.preventHide = false;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (event?.relatedTarget && this.element.parentNode?.contains(event.relatedTarget)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (event?.relatedTarget === this.editor.view.dom) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
this.hide();
|
|
100
|
+
};
|
|
101
|
+
this.handleDebouncedUpdate = (view, oldState) => {
|
|
102
|
+
const selectionChanged = !oldState?.selection.eq(view.state.selection);
|
|
103
|
+
const docChanged = !oldState?.doc.eq(view.state.doc);
|
|
104
|
+
if (!selectionChanged && !docChanged) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (this.updateDebounceTimer) {
|
|
108
|
+
clearTimeout(this.updateDebounceTimer);
|
|
109
|
+
}
|
|
110
|
+
this.updateDebounceTimer = window.setTimeout(() => {
|
|
111
|
+
this.updateHandler(view, selectionChanged, docChanged, oldState);
|
|
112
|
+
}, this.updateDelay);
|
|
113
|
+
};
|
|
114
|
+
this.updateHandler = (view, selectionChanged, docChanged, oldState) => {
|
|
115
|
+
const { composing } = view;
|
|
116
|
+
const isSame = !selectionChanged && !docChanged;
|
|
117
|
+
if (composing || isSame) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const shouldShow = this.getShouldShow(oldState);
|
|
121
|
+
if (!shouldShow) {
|
|
122
|
+
this.hide();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.show();
|
|
126
|
+
this.updatePosition();
|
|
127
|
+
};
|
|
128
|
+
this.editor = editor;
|
|
129
|
+
this.element = element;
|
|
130
|
+
this.view = view;
|
|
131
|
+
this.updateDelay = updateDelay;
|
|
132
|
+
this.resizeDelay = resizeDelay;
|
|
133
|
+
this.container = container;
|
|
134
|
+
this.onShow = onShow;
|
|
135
|
+
this.onHide = onHide;
|
|
136
|
+
this.floatingUIOptions = {
|
|
137
|
+
...this.floatingUIOptions,
|
|
138
|
+
...options,
|
|
139
|
+
};
|
|
140
|
+
if (shouldShow) {
|
|
141
|
+
this.shouldShow = shouldShow;
|
|
142
|
+
}
|
|
143
|
+
const containerElement = this.getContainer();
|
|
144
|
+
if (containerElement === document.body) {
|
|
145
|
+
this.element.style.zIndex = '9999';
|
|
146
|
+
}
|
|
147
|
+
this.element.addEventListener('mousedown', this.mousedownHandler, { capture: true });
|
|
148
|
+
this.view.dom.addEventListener('dragstart', this.dragstartHandler);
|
|
149
|
+
this.editor.on('focus', this.focusHandler);
|
|
150
|
+
this.editor.on('blur', this.blurHandler);
|
|
151
|
+
window.addEventListener('resize', () => {
|
|
152
|
+
if (this.resizeDebounceTimer) {
|
|
153
|
+
clearTimeout(this.resizeDebounceTimer);
|
|
154
|
+
}
|
|
155
|
+
this.resizeDebounceTimer = window.setTimeout(() => {
|
|
156
|
+
this.updatePosition();
|
|
157
|
+
}, this.resizeDelay);
|
|
158
|
+
});
|
|
159
|
+
this.update(view, view.state);
|
|
160
|
+
if (this.getShouldShow()) {
|
|
161
|
+
this.show();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
updatePosition() {
|
|
165
|
+
const { selection } = this.editor.state;
|
|
166
|
+
const virtualElement = {
|
|
167
|
+
getBoundingClientRect: () => posToDOMRect(this.view, selection.from, selection.to),
|
|
168
|
+
};
|
|
169
|
+
const strategy = this.container === document.body ? 'fixed' : this.floatingUIOptions.strategy;
|
|
170
|
+
computePosition(virtualElement, this.element, {
|
|
171
|
+
placement: this.floatingUIOptions.placement,
|
|
172
|
+
strategy,
|
|
173
|
+
middleware: this.middlewares,
|
|
174
|
+
}).then(({ x, y, strategy }) => {
|
|
175
|
+
this.element.style.width = 'max-content';
|
|
176
|
+
this.element.style.position = strategy;
|
|
177
|
+
this.element.style.left = `${x}px`;
|
|
178
|
+
this.element.style.top = `${y}px`;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
update(view, oldState) {
|
|
182
|
+
const { state } = view;
|
|
183
|
+
const hasValidSelection = state.selection.from !== state.selection.to;
|
|
184
|
+
if (this.updateDelay > 0 && hasValidSelection) {
|
|
185
|
+
this.handleDebouncedUpdate(view, oldState);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const selectionChanged = !oldState?.selection.eq(view.state.selection);
|
|
189
|
+
const docChanged = !oldState?.doc.eq(view.state.doc);
|
|
190
|
+
this.updateHandler(view, selectionChanged, docChanged, oldState);
|
|
191
|
+
}
|
|
192
|
+
getShouldShow(oldState) {
|
|
193
|
+
const { state } = this.view;
|
|
194
|
+
const { selection } = state;
|
|
195
|
+
// support for CellSelections
|
|
196
|
+
const { ranges } = selection;
|
|
197
|
+
const from = Math.min(...ranges.map(range => range.$from.pos));
|
|
198
|
+
const to = Math.max(...ranges.map(range => range.$to.pos));
|
|
199
|
+
const shouldShow = this.shouldShow?.({
|
|
200
|
+
editor: this.editor,
|
|
201
|
+
element: this.element,
|
|
202
|
+
view: this.view,
|
|
203
|
+
state,
|
|
204
|
+
oldState,
|
|
205
|
+
from,
|
|
206
|
+
to,
|
|
207
|
+
});
|
|
208
|
+
return shouldShow;
|
|
209
|
+
}
|
|
210
|
+
getContainer() {
|
|
211
|
+
if (!this.container) {
|
|
212
|
+
return this.view.dom.parentElement;
|
|
213
|
+
}
|
|
214
|
+
if (typeof this.container === 'function') {
|
|
215
|
+
return this.container();
|
|
216
|
+
}
|
|
217
|
+
return this.container;
|
|
218
|
+
}
|
|
219
|
+
show() {
|
|
220
|
+
this.element.style.visibility = 'visible';
|
|
221
|
+
this.element.style.opacity = '1';
|
|
222
|
+
// attach to editor's parent element
|
|
223
|
+
const container = this.getContainer();
|
|
224
|
+
if (container) {
|
|
225
|
+
container.appendChild(this.element);
|
|
226
|
+
this.onShow?.();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
hide() {
|
|
230
|
+
this.element.style.visibility = 'hidden';
|
|
231
|
+
this.element.style.opacity = '0';
|
|
232
|
+
// remove from the parent element
|
|
233
|
+
this.element.remove();
|
|
234
|
+
this.onHide?.();
|
|
235
|
+
}
|
|
236
|
+
destroy() {
|
|
237
|
+
this.hide();
|
|
238
|
+
this.element.removeEventListener('mousedown', this.mousedownHandler, { capture: true });
|
|
239
|
+
this.view.dom.removeEventListener('dragstart', this.dragstartHandler);
|
|
240
|
+
this.editor.off('focus', this.focusHandler);
|
|
241
|
+
this.editor.off('blur', this.blurHandler);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
export const BubbleMenuPlugin = (options) => new Plugin({
|
|
245
|
+
key: typeof options.pluginKey === 'string' ? new PluginKey(options.pluginKey) : options.pluginKey,
|
|
246
|
+
view: view => new BubbleMenuView({ view, ...options }),
|
|
247
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import type { BubbleMenuPluginProps } from './bubble-menu-plugin';
|
|
3
|
+
export type BubbleMenuOptions = Omit<BubbleMenuPluginProps, 'editor' | 'element'> & {
|
|
4
|
+
/**
|
|
5
|
+
* The DOM element that contains your menu.
|
|
6
|
+
* @type {HTMLElement}
|
|
7
|
+
* @default null
|
|
8
|
+
*/
|
|
9
|
+
element: HTMLElement | null;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* This extension allows you to create a bubble menu.
|
|
13
|
+
* @see https://tiptap.dev/api/extensions/bubble-menu
|
|
14
|
+
*/
|
|
15
|
+
export declare const BubbleMenu: Extension<BubbleMenuOptions, any>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import { BubbleMenuPlugin } from './bubble-menu-plugin';
|
|
3
|
+
/**
|
|
4
|
+
* This extension allows you to create a bubble menu.
|
|
5
|
+
* @see https://tiptap.dev/api/extensions/bubble-menu
|
|
6
|
+
*/
|
|
7
|
+
export const BubbleMenu = Extension.create({
|
|
8
|
+
name: 'bubbleMenu',
|
|
9
|
+
addOptions() {
|
|
10
|
+
return {
|
|
11
|
+
element: null,
|
|
12
|
+
pluginKey: 'bubbleMenu',
|
|
13
|
+
updateDelay: undefined,
|
|
14
|
+
shouldShow: null,
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
addProseMirrorPlugins() {
|
|
18
|
+
if (!this.options.element) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
return [
|
|
22
|
+
BubbleMenuPlugin({
|
|
23
|
+
pluginKey: this.options.pluginKey,
|
|
24
|
+
editor: this.editor,
|
|
25
|
+
element: this.options.element,
|
|
26
|
+
updateDelay: this.options.updateDelay,
|
|
27
|
+
shouldShow: this.options.shouldShow,
|
|
28
|
+
}),
|
|
29
|
+
];
|
|
30
|
+
},
|
|
31
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Color as TiptapColorExtension, } from '@tiptap/extension-color';
|
|
2
|
+
import { DEFAULT_TEXT_STYLE } from '../constants';
|
|
3
|
+
import tinycolor from 'tinycolor2';
|
|
4
|
+
export const Color = TiptapColorExtension.extend({
|
|
5
|
+
addOptions() {
|
|
6
|
+
return {
|
|
7
|
+
...this.parent?.(),
|
|
8
|
+
defaultColor: DEFAULT_TEXT_STYLE.color,
|
|
9
|
+
};
|
|
10
|
+
},
|
|
11
|
+
addGlobalAttributes() {
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
types: this.options.types,
|
|
15
|
+
attributes: {
|
|
16
|
+
color: {
|
|
17
|
+
default: null,
|
|
18
|
+
parseHTML: element => element.style.color?.replace(/['"]+/g, ''),
|
|
19
|
+
renderHTML: attrs => {
|
|
20
|
+
if (!attrs.color || tinycolor.equals(attrs.color, this.options.defaultColor)) {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
style: `color: ${attrs.color}`,
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
},
|
|
32
|
+
addCommands() {
|
|
33
|
+
return {
|
|
34
|
+
...this.parent?.(),
|
|
35
|
+
unsetColor: () => ({ chain }) => chain()
|
|
36
|
+
.setMark('textStyle', { color: this.options.defaultColor || null })
|
|
37
|
+
.removeEmptyTextStyle()
|
|
38
|
+
.run(),
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
import { DOMOutputSpec, Node as ProseMirrorNode } from '@tiptap/pm/model';
|
|
3
|
+
import { SuggestionOptions } from '@tiptap/suggestion';
|
|
4
|
+
export declare const LIST_EMOJI: ({
|
|
5
|
+
emoji: string;
|
|
6
|
+
skin_tone_support: boolean;
|
|
7
|
+
name: string;
|
|
8
|
+
slug: string;
|
|
9
|
+
unicode_version: string;
|
|
10
|
+
emoji_version: string;
|
|
11
|
+
skin_tone_support_unicode_version?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
emoji: string;
|
|
14
|
+
skin_tone_support: boolean;
|
|
15
|
+
skin_tone_support_unicode_version: string;
|
|
16
|
+
name: string;
|
|
17
|
+
slug: string;
|
|
18
|
+
unicode_version: string;
|
|
19
|
+
emoji_version: string;
|
|
20
|
+
})[];
|
|
21
|
+
declare module '@tiptap/core' {
|
|
22
|
+
interface Commands<ReturnType> {
|
|
23
|
+
emoji: {
|
|
24
|
+
insertEmoji: (emojiName: string) => ReturnType;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export interface SuggestionItem {
|
|
29
|
+
emoji: string;
|
|
30
|
+
skin_tone_support: boolean;
|
|
31
|
+
name: string;
|
|
32
|
+
slug: string;
|
|
33
|
+
unicode_version: string;
|
|
34
|
+
emoji_version: string;
|
|
35
|
+
}
|
|
36
|
+
export interface EmojiNodeAttrs {
|
|
37
|
+
name?: string | null;
|
|
38
|
+
}
|
|
39
|
+
export type EmojiOptions<Attrs extends Record<string, any> = EmojiNodeAttrs> = {
|
|
40
|
+
HTMLAttributes: Record<string, any>;
|
|
41
|
+
renderLabel?: (props: {
|
|
42
|
+
options: EmojiOptions<Attrs>;
|
|
43
|
+
node: ProseMirrorNode;
|
|
44
|
+
}) => string;
|
|
45
|
+
renderText: (props: {
|
|
46
|
+
options: EmojiOptions<Attrs>;
|
|
47
|
+
node: ProseMirrorNode;
|
|
48
|
+
}) => string;
|
|
49
|
+
renderHTML: (props: {
|
|
50
|
+
options: EmojiOptions<Attrs>;
|
|
51
|
+
node: ProseMirrorNode;
|
|
52
|
+
}) => DOMOutputSpec;
|
|
53
|
+
deleteTriggerWithBackspace: boolean;
|
|
54
|
+
suggestion: Omit<SuggestionOptions<SuggestionItem, Attrs>, 'editor'>;
|
|
55
|
+
};
|
|
56
|
+
export declare const EXTENSION_NAME = "emoji";
|
|
57
|
+
export declare const Emoji: Node<EmojiOptions<EmojiNodeAttrs>, any>;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { Node, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
import { PluginKey } from '@tiptap/pm/state';
|
|
3
|
+
import Suggestion from '@tiptap/suggestion';
|
|
4
|
+
import { ICON_EMOJI_COMMON } from '@antscorp/antsomi-ui/es/components/molecules';
|
|
5
|
+
import { memoize } from 'lodash';
|
|
6
|
+
export const LIST_EMOJI = ICON_EMOJI_COMMON.flatMap(group => group.emojis);
|
|
7
|
+
const findEmojiByName = memoize((name) => LIST_EMOJI.find(i => i.name === name)?.emoji);
|
|
8
|
+
export const EXTENSION_NAME = 'emoji';
|
|
9
|
+
export const Emoji = Node.create({
|
|
10
|
+
name: EXTENSION_NAME,
|
|
11
|
+
priority: 102,
|
|
12
|
+
group: 'inline',
|
|
13
|
+
inline: true,
|
|
14
|
+
atom: true,
|
|
15
|
+
selectable: true,
|
|
16
|
+
addOptions() {
|
|
17
|
+
return {
|
|
18
|
+
HTMLAttributes: {},
|
|
19
|
+
deleteTriggerWithBackspace: false,
|
|
20
|
+
renderText({ node }) {
|
|
21
|
+
return findEmojiByName(node.attrs.name) || node.attrs.name;
|
|
22
|
+
},
|
|
23
|
+
renderHTML({ options, node }) {
|
|
24
|
+
const emoji = findEmojiByName(node.attrs.name);
|
|
25
|
+
return [
|
|
26
|
+
'span',
|
|
27
|
+
mergeAttributes(this.HTMLAttributes, options.HTMLAttributes),
|
|
28
|
+
emoji || node.attrs.name,
|
|
29
|
+
];
|
|
30
|
+
},
|
|
31
|
+
suggestion: {
|
|
32
|
+
char: ':',
|
|
33
|
+
pluginKey: new PluginKey('emoji'),
|
|
34
|
+
command: ({ editor, range, props }) => {
|
|
35
|
+
const { name } = props;
|
|
36
|
+
// increase range.to by one when the next node is of type "text"
|
|
37
|
+
// and starts with a space character
|
|
38
|
+
const { nodeAfter } = editor.view.state.selection.$to;
|
|
39
|
+
const overrideSpace = nodeAfter?.text?.startsWith(' ');
|
|
40
|
+
if (overrideSpace) {
|
|
41
|
+
range.to++;
|
|
42
|
+
}
|
|
43
|
+
const nodeBeforeMarks = editor.state.doc
|
|
44
|
+
.resolve(range.from)
|
|
45
|
+
.marks()
|
|
46
|
+
.map(i => ({
|
|
47
|
+
type: i.type.name,
|
|
48
|
+
attrs: i.attrs,
|
|
49
|
+
}));
|
|
50
|
+
editor
|
|
51
|
+
.chain()
|
|
52
|
+
.focus()
|
|
53
|
+
.insertContentAt(range, [
|
|
54
|
+
{
|
|
55
|
+
type: this.name,
|
|
56
|
+
attrs: { name },
|
|
57
|
+
marks: nodeBeforeMarks,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: 'text',
|
|
61
|
+
text: ' ',
|
|
62
|
+
marks: nodeBeforeMarks,
|
|
63
|
+
},
|
|
64
|
+
])
|
|
65
|
+
.run();
|
|
66
|
+
// get reference to `window` object from editor element, to support cross-frame JS usage
|
|
67
|
+
editor.view.dom.ownerDocument.defaultView?.getSelection()?.collapseToEnd();
|
|
68
|
+
},
|
|
69
|
+
allow: ({ state, range }) => {
|
|
70
|
+
const $from = state.doc.resolve(range.from);
|
|
71
|
+
const type = state.schema.nodes[this.name];
|
|
72
|
+
const allow = !!$from.parent.type.contentMatch.matchType(type);
|
|
73
|
+
return allow;
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
addAttributes() {
|
|
79
|
+
return {
|
|
80
|
+
name: {
|
|
81
|
+
default: null,
|
|
82
|
+
parseHTML: element => element.getAttribute('data-name'),
|
|
83
|
+
renderHTML: attributes => {
|
|
84
|
+
if (!attributes.name) {
|
|
85
|
+
return {};
|
|
86
|
+
}
|
|
87
|
+
return { 'data-name': attributes.name };
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
parseHTML() {
|
|
93
|
+
return [
|
|
94
|
+
{
|
|
95
|
+
tag: `span[data-type="${this.name}"]`,
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
},
|
|
99
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
100
|
+
const mergedOptions = { ...this.options };
|
|
101
|
+
mergedOptions.HTMLAttributes = mergeAttributes({
|
|
102
|
+
'data-type': this.name,
|
|
103
|
+
}, this.options.HTMLAttributes, HTMLAttributes);
|
|
104
|
+
const html = this.options.renderHTML({
|
|
105
|
+
options: mergedOptions,
|
|
106
|
+
node,
|
|
107
|
+
});
|
|
108
|
+
if (typeof html === 'string') {
|
|
109
|
+
return [
|
|
110
|
+
'span',
|
|
111
|
+
mergeAttributes({
|
|
112
|
+
'data-type': this.name,
|
|
113
|
+
}, this.options.HTMLAttributes, HTMLAttributes),
|
|
114
|
+
html,
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
return html;
|
|
118
|
+
},
|
|
119
|
+
renderText({ node }) {
|
|
120
|
+
return this.options.renderText({
|
|
121
|
+
options: this.options,
|
|
122
|
+
node,
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
addKeyboardShortcuts() {
|
|
126
|
+
return {
|
|
127
|
+
Backspace: () => this.editor.commands.command(({ tr, state }) => {
|
|
128
|
+
let isEmoji = false;
|
|
129
|
+
const { selection } = state;
|
|
130
|
+
const { empty, anchor } = selection;
|
|
131
|
+
if (!empty) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
|
|
135
|
+
if (node.type.name === this.name) {
|
|
136
|
+
isEmoji = true;
|
|
137
|
+
tr.insertText(this.options.deleteTriggerWithBackspace ? '' : this.options.suggestion.char || '', pos, pos + node.nodeSize);
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
return isEmoji;
|
|
142
|
+
}),
|
|
143
|
+
};
|
|
144
|
+
},
|
|
145
|
+
addCommands() {
|
|
146
|
+
return {
|
|
147
|
+
insertEmoji: emojiName => ({ editor, state }) => {
|
|
148
|
+
const { selection } = state;
|
|
149
|
+
const nodeBeforeMarks = selection.$from.marks().map(i => ({
|
|
150
|
+
type: i.type.name,
|
|
151
|
+
attrs: i.attrs,
|
|
152
|
+
}));
|
|
153
|
+
// Chèn emoji node
|
|
154
|
+
editor
|
|
155
|
+
.chain()
|
|
156
|
+
.focus()
|
|
157
|
+
.insertContent([
|
|
158
|
+
{
|
|
159
|
+
type: this.name,
|
|
160
|
+
attrs: { name: emojiName },
|
|
161
|
+
marks: nodeBeforeMarks,
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
type: 'text',
|
|
165
|
+
text: ' ',
|
|
166
|
+
marks: nodeBeforeMarks,
|
|
167
|
+
},
|
|
168
|
+
])
|
|
169
|
+
.run();
|
|
170
|
+
// Đưa con trỏ về cuối emoji
|
|
171
|
+
editor.view.dom.ownerDocument.defaultView?.getSelection()?.collapseToEnd();
|
|
172
|
+
return true;
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
addProseMirrorPlugins() {
|
|
177
|
+
return [
|
|
178
|
+
Suggestion({
|
|
179
|
+
editor: this.editor,
|
|
180
|
+
...this.options.suggestion,
|
|
181
|
+
}),
|
|
182
|
+
];
|
|
183
|
+
},
|
|
184
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FontFamilyOptions as TiptapFontFamilyOptions } from '@tiptap/extension-font-family';
|
|
2
|
+
interface FontFamilyOptions extends TiptapFontFamilyOptions {
|
|
3
|
+
defaultFontFamily: string;
|
|
4
|
+
}
|
|
5
|
+
export declare const FontFamily: import("@tiptap/core").Extension<FontFamilyOptions, any>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FontFamily as TiptapFontFamilyExtension, } from '@tiptap/extension-font-family';
|
|
2
|
+
import { DEFAULT_TEXT_STYLE } from '../constants';
|
|
3
|
+
export const FontFamily = TiptapFontFamilyExtension.extend({
|
|
4
|
+
addOptions() {
|
|
5
|
+
return {
|
|
6
|
+
...this.parent?.(),
|
|
7
|
+
defaultFontFamily: DEFAULT_TEXT_STYLE.fontFamily,
|
|
8
|
+
};
|
|
9
|
+
},
|
|
10
|
+
addCommands() {
|
|
11
|
+
return {
|
|
12
|
+
...this.parent?.(),
|
|
13
|
+
unsetFontFamily: () => ({ chain }) => chain()
|
|
14
|
+
.setMark('textStyle', {
|
|
15
|
+
fontFamily: this.options.defaultFontFamily || null,
|
|
16
|
+
})
|
|
17
|
+
.removeEmptyTextStyle()
|
|
18
|
+
.run(),
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
addGlobalAttributes() {
|
|
22
|
+
return [
|
|
23
|
+
...(this.parent?.() || []),
|
|
24
|
+
{
|
|
25
|
+
types: this.options.types,
|
|
26
|
+
attributes: {
|
|
27
|
+
fontFamily: {
|
|
28
|
+
default: this.options.defaultFontFamily,
|
|
29
|
+
renderHTML: attrs => {
|
|
30
|
+
if (!attrs.fontFamily || attrs.fontFamily === this.options.defaultFontFamily) {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
style: `font-family: ${attrs.fontFamily}`,
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
parseHTML: element => element.style.fontFamily || this.options.defaultFontFamily,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
},
|
|
43
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import '@tiptap/extension-text-style';
|
|
2
|
+
import { Extension } from '@tiptap/core';
|
|
3
|
+
export type FontSizeOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* A list of node names where the font size can be applied.
|
|
6
|
+
* @default ['textStyle']
|
|
7
|
+
* @example ['heading', 'paragraph']
|
|
8
|
+
*/
|
|
9
|
+
types: string[];
|
|
10
|
+
defaultFontSize: string;
|
|
11
|
+
};
|
|
12
|
+
declare module '@tiptap/core' {
|
|
13
|
+
interface Commands<ReturnType> {
|
|
14
|
+
fontSize: {
|
|
15
|
+
/**
|
|
16
|
+
* Set the font size
|
|
17
|
+
* @param fontSize The font size
|
|
18
|
+
* @example editor.commands.setFontSize('16px')
|
|
19
|
+
*/
|
|
20
|
+
setFontSize: (fontSize: string) => ReturnType;
|
|
21
|
+
/**
|
|
22
|
+
* Unset the font size
|
|
23
|
+
* @example editor.commands.unsetFontSize()
|
|
24
|
+
*/
|
|
25
|
+
unsetFontSize: () => ReturnType;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* This extension allows you to set a font size for text.
|
|
31
|
+
*/
|
|
32
|
+
export declare const FontSize: Extension<FontSizeOptions, any>;
|