@antscorp/antsomi-ui 2.0.86-text-editor-beta.5 → 2.0.86

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.
Files changed (228) hide show
  1. package/es/assets/css/main.scss +2 -4
  2. package/es/components/molecules/EmojiPopover/EmojiPopover.js +1 -5
  3. package/es/components/molecules/VirtualizedMenu/VirtualizedMenu.d.ts +3 -6
  4. package/es/components/molecules/VirtualizedMenu/__mocks__/index.js +982 -2594
  5. package/es/components/molecules/VirtualizedMenu/components/Item/Item.d.ts +3 -13
  6. package/es/components/molecules/VirtualizedMenu/components/Item/Item.js +25 -53
  7. package/es/components/molecules/VirtualizedMenu/components/Item/index.d.ts +1 -1
  8. package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.d.ts +5 -8
  9. package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.js +46 -289
  10. package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.js +0 -1
  11. package/es/components/molecules/VirtualizedMenu/styled.d.ts +1 -1
  12. package/es/components/molecules/VirtualizedMenu/styled.js +4 -23
  13. package/es/components/molecules/VirtualizedMenu/types.d.ts +9 -6
  14. package/es/components/molecules/VirtualizedMenu/utils.d.ts +5 -8
  15. package/es/components/molecules/VirtualizedMenu/utils.js +18 -13
  16. package/es/components/molecules/index.d.ts +0 -1
  17. package/es/components/molecules/index.js +0 -1
  18. package/es/components/organism/index.d.ts +0 -1
  19. package/es/components/organism/index.js +0 -1
  20. package/es/components/template/Layout/constants/permission.d.ts +1 -0
  21. package/es/components/template/Layout/constants/permission.js +1 -1
  22. package/es/hooks/index.d.ts +0 -1
  23. package/es/hooks/index.js +0 -1
  24. package/es/utils/common.d.ts +9 -6
  25. package/es/utils/common.js +23 -44
  26. package/es/utils/index.d.ts +0 -1
  27. package/es/utils/index.js +0 -1
  28. package/es/utils/web.d.ts +0 -4
  29. package/es/utils/web.js +0 -25
  30. package/package.json +3 -29
  31. package/es/components/index.scss +0 -2
  32. package/es/components/molecules/FontSizeInput/FontSizeInput.d.ts +0 -3
  33. package/es/components/molecules/FontSizeInput/FontSizeInput.js +0 -128
  34. package/es/components/molecules/FontSizeInput/components/FontSizeControl.d.ts +0 -8
  35. package/es/components/molecules/FontSizeInput/components/FontSizeControl.js +0 -14
  36. package/es/components/molecules/FontSizeInput/components/FontSizeDropdown.d.ts +0 -20
  37. package/es/components/molecules/FontSizeInput/components/FontSizeDropdown.js +0 -17
  38. package/es/components/molecules/FontSizeInput/constants.d.ts +0 -2
  39. package/es/components/molecules/FontSizeInput/constants.js +0 -5
  40. package/es/components/molecules/FontSizeInput/index.d.ts +0 -2
  41. package/es/components/molecules/FontSizeInput/index.js +0 -1
  42. package/es/components/molecules/FontSizeInput/styled.d.ts +0 -3
  43. package/es/components/molecules/FontSizeInput/styled.js +0 -22
  44. package/es/components/molecules/FontSizeInput/styles.scss +0 -15
  45. package/es/components/molecules/FontSizeInput/types.d.ts +0 -24
  46. package/es/components/molecules/FontSizeInput/types.js +0 -1
  47. package/es/components/molecules/FontSizeInput/utils.d.ts +0 -7
  48. package/es/components/molecules/FontSizeInput/utils.js +0 -9
  49. package/es/components/molecules/index.scss +0 -1
  50. package/es/components/organism/ActivityTimeline/__mocks__/event_tracking.json +0 -1290
  51. package/es/components/organism/ActivityTimeline/__mocks__/timeline.json +0 -3059
  52. package/es/components/organism/TextEditor/TextEditor.d.ts +0 -3
  53. package/es/components/organism/TextEditor/TextEditor.js +0 -251
  54. package/es/components/organism/TextEditor/__mocks__/text-block.settings.json +0 -320
  55. package/es/components/organism/TextEditor/__mocks__/text-contennt.d.ts +0 -1
  56. package/es/components/organism/TextEditor/__mocks__/text-contennt.js +0 -38
  57. package/es/components/organism/TextEditor/constants.d.ts +0 -135
  58. package/es/components/organism/TextEditor/constants.js +0 -280
  59. package/es/components/organism/TextEditor/extensions/BackgroundColor.d.ts +0 -25
  60. package/es/components/organism/TextEditor/extensions/BackgroundColor.js +0 -46
  61. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.d.ts +0 -130
  62. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.js +0 -247
  63. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.d.ts +0 -15
  64. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.js +0 -31
  65. package/es/components/organism/TextEditor/extensions/BubbleMenu/index.d.ts +0 -2
  66. package/es/components/organism/TextEditor/extensions/BubbleMenu/index.js +0 -2
  67. package/es/components/organism/TextEditor/extensions/Color.d.ts +0 -6
  68. package/es/components/organism/TextEditor/extensions/Color.js +0 -41
  69. package/es/components/organism/TextEditor/extensions/Emoji.d.ts +0 -57
  70. package/es/components/organism/TextEditor/extensions/Emoji.js +0 -184
  71. package/es/components/organism/TextEditor/extensions/FontFamily.d.ts +0 -6
  72. package/es/components/organism/TextEditor/extensions/FontFamily.js +0 -43
  73. package/es/components/organism/TextEditor/extensions/FontSize.d.ts +0 -32
  74. package/es/components/organism/TextEditor/extensions/FontSize.js +0 -47
  75. package/es/components/organism/TextEditor/extensions/FontWeight.d.ts +0 -23
  76. package/es/components/organism/TextEditor/extensions/FontWeight.js +0 -41
  77. package/es/components/organism/TextEditor/extensions/Highlight.d.ts +0 -1
  78. package/es/components/organism/TextEditor/extensions/Highlight.js +0 -14
  79. package/es/components/organism/TextEditor/extensions/Indent.d.ts +0 -28
  80. package/es/components/organism/TextEditor/extensions/Indent.js +0 -68
  81. package/es/components/organism/TextEditor/extensions/LineHeight.d.ts +0 -20
  82. package/es/components/organism/TextEditor/extensions/LineHeight.js +0 -36
  83. package/es/components/organism/TextEditor/extensions/Link.d.ts +0 -15
  84. package/es/components/organism/TextEditor/extensions/Link.js +0 -50
  85. package/es/components/organism/TextEditor/extensions/ListItemMarker.d.ts +0 -13
  86. package/es/components/organism/TextEditor/extensions/ListItemMarker.js +0 -174
  87. package/es/components/organism/TextEditor/extensions/Selection.d.ts +0 -6
  88. package/es/components/organism/TextEditor/extensions/Selection.js +0 -40
  89. package/es/components/organism/TextEditor/extensions/SmartTag.d.ts +0 -39
  90. package/es/components/organism/TextEditor/extensions/SmartTag.js +0 -167
  91. package/es/components/organism/TextEditor/extensions/StyleMemory.d.ts +0 -36
  92. package/es/components/organism/TextEditor/extensions/StyleMemory.js +0 -163
  93. package/es/components/organism/TextEditor/extensions/TextTransform.d.ts +0 -31
  94. package/es/components/organism/TextEditor/extensions/TextTransform.js +0 -37
  95. package/es/components/organism/TextEditor/hooks/index.d.ts +0 -7
  96. package/es/components/organism/TextEditor/hooks/index.js +0 -7
  97. package/es/components/organism/TextEditor/hooks/useColorSet.d.ts +0 -4
  98. package/es/components/organism/TextEditor/hooks/useColorSet.js +0 -6
  99. package/es/components/organism/TextEditor/hooks/useDocumentState.d.ts +0 -18
  100. package/es/components/organism/TextEditor/hooks/useDocumentState.js +0 -42
  101. package/es/components/organism/TextEditor/hooks/useLinkHandler.d.ts +0 -10
  102. package/es/components/organism/TextEditor/hooks/useLinkHandler.js +0 -223
  103. package/es/components/organism/TextEditor/hooks/useMarkTracking.d.ts +0 -26
  104. package/es/components/organism/TextEditor/hooks/useMarkTracking.js +0 -68
  105. package/es/components/organism/TextEditor/hooks/usePersistence.d.ts +0 -31
  106. package/es/components/organism/TextEditor/hooks/usePersistence.js +0 -169
  107. package/es/components/organism/TextEditor/hooks/useStyleMemory.d.ts +0 -6
  108. package/es/components/organism/TextEditor/hooks/useStyleMemory.js +0 -42
  109. package/es/components/organism/TextEditor/hooks/useStylePresets.d.ts +0 -34
  110. package/es/components/organism/TextEditor/hooks/useStylePresets.js +0 -83
  111. package/es/components/organism/TextEditor/index.d.ts +0 -14
  112. package/es/components/organism/TextEditor/index.js +0 -6
  113. package/es/components/organism/TextEditor/index.scss +0 -61
  114. package/es/components/organism/TextEditor/provider.d.ts +0 -12
  115. package/es/components/organism/TextEditor/provider.js +0 -34
  116. package/es/components/organism/TextEditor/store.d.ts +0 -13
  117. package/es/components/organism/TextEditor/store.js +0 -20
  118. package/es/components/organism/TextEditor/styled.d.ts +0 -8
  119. package/es/components/organism/TextEditor/styled.js +0 -90
  120. package/es/components/organism/TextEditor/types.d.ts +0 -92
  121. package/es/components/organism/TextEditor/types.js +0 -1
  122. package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.d.ts +0 -6
  123. package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.js +0 -78
  124. package/es/components/organism/TextEditor/ui/BubbleMenu/index.d.ts +0 -1
  125. package/es/components/organism/TextEditor/ui/BubbleMenu/index.js +0 -1
  126. package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.d.ts +0 -43
  127. package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.js +0 -132
  128. package/es/components/organism/TextEditor/ui/ColorPicker/index.d.ts +0 -1
  129. package/es/components/organism/TextEditor/ui/ColorPicker/index.js +0 -1
  130. package/es/components/organism/TextEditor/ui/Emoji/EmojiList.d.ts +0 -11
  131. package/es/components/organism/TextEditor/ui/Emoji/EmojiList.js +0 -66
  132. package/es/components/organism/TextEditor/ui/Emoji/index.d.ts +0 -2
  133. package/es/components/organism/TextEditor/ui/Emoji/index.js +0 -2
  134. package/es/components/organism/TextEditor/ui/Emoji/suggestion.d.ts +0 -4
  135. package/es/components/organism/TextEditor/ui/Emoji/suggestion.js +0 -71
  136. package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.d.ts +0 -12
  137. package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.js +0 -69
  138. package/es/components/organism/TextEditor/ui/FontPopover/styled.d.ts +0 -1
  139. package/es/components/organism/TextEditor/ui/FontPopover/styled.js +0 -20
  140. package/es/components/organism/TextEditor/ui/Popover/Popover.d.ts +0 -6
  141. package/es/components/organism/TextEditor/ui/Popover/Popover.js +0 -7
  142. package/es/components/organism/TextEditor/ui/Popover/index.d.ts +0 -1
  143. package/es/components/organism/TextEditor/ui/Popover/index.js +0 -1
  144. package/es/components/organism/TextEditor/ui/Select/Select.d.ts +0 -4
  145. package/es/components/organism/TextEditor/ui/Select/Select.js +0 -7
  146. package/es/components/organism/TextEditor/ui/Select/index.d.ts +0 -1
  147. package/es/components/organism/TextEditor/ui/Select/index.js +0 -1
  148. package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.d.ts +0 -30
  149. package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.js +0 -49
  150. package/es/components/organism/TextEditor/ui/TextAlignSelect/index.d.ts +0 -1
  151. package/es/components/organism/TextEditor/ui/TextAlignSelect/index.js +0 -1
  152. package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.d.ts +0 -14
  153. package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.js +0 -42
  154. package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.d.ts +0 -5
  155. package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.js +0 -7
  156. package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.d.ts +0 -5
  157. package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.js +0 -7
  158. package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.d.ts +0 -5
  159. package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.js +0 -18
  160. package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.d.ts +0 -4
  161. package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.js +0 -13
  162. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.d.ts +0 -7
  163. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.js +0 -18
  164. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.d.ts +0 -7
  165. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.js +0 -37
  166. package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.d.ts +0 -5
  167. package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.js +0 -7
  168. package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.d.ts +0 -5
  169. package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.js +0 -7
  170. package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.d.ts +0 -5
  171. package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.js +0 -7
  172. package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.d.ts +0 -6
  173. package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.js +0 -4
  174. package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.d.ts +0 -5
  175. package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.js +0 -7
  176. package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.d.ts +0 -5
  177. package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.js +0 -7
  178. package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.d.ts +0 -7
  179. package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.js +0 -9
  180. package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.d.ts +0 -9
  181. package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.js +0 -22
  182. package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.d.ts +0 -5
  183. package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.js +0 -7
  184. package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.d.ts +0 -5
  185. package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.js +0 -13
  186. package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.d.ts +0 -5
  187. package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.js +0 -13
  188. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.d.ts +0 -5
  189. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.js +0 -3
  190. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.d.ts +0 -7
  191. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.js +0 -19
  192. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.d.ts +0 -15
  193. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.js +0 -14
  194. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.d.ts +0 -5
  195. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.js +0 -30
  196. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.d.ts +0 -5
  197. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.js +0 -5
  198. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.d.ts +0 -6
  199. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.js +0 -10
  200. package/es/components/organism/TextEditor/ui/Toolbar/actions/index.d.ts +0 -20
  201. package/es/components/organism/TextEditor/ui/Toolbar/actions/index.js +0 -20
  202. package/es/components/organism/TextEditor/ui/Toolbar/index.d.ts +0 -1
  203. package/es/components/organism/TextEditor/ui/Toolbar/index.js +0 -1
  204. package/es/components/organism/TextEditor/utils/documentState.d.ts +0 -57
  205. package/es/components/organism/TextEditor/utils/documentState.js +0 -100
  206. package/es/components/organism/TextEditor/utils/font.d.ts +0 -84
  207. package/es/components/organism/TextEditor/utils/font.js +0 -175
  208. package/es/components/organism/TextEditor/utils/htmlProcessing.d.ts +0 -63
  209. package/es/components/organism/TextEditor/utils/htmlProcessing.js +0 -319
  210. package/es/components/organism/TextEditor/utils/index.d.ts +0 -8
  211. package/es/components/organism/TextEditor/utils/index.js +0 -16
  212. package/es/components/organism/TextEditor/utils/link.d.ts +0 -100
  213. package/es/components/organism/TextEditor/utils/link.js +0 -149
  214. package/es/components/organism/TextEditor/utils/menu.d.ts +0 -134
  215. package/es/components/organism/TextEditor/utils/menu.js +0 -317
  216. package/es/components/organism/TextEditor/utils/selection.d.ts +0 -25
  217. package/es/components/organism/TextEditor/utils/selection.js +0 -57
  218. package/es/components/organism/TextEditor/utils/smartTag.d.ts +0 -49
  219. package/es/components/organism/TextEditor/utils/smartTag.js +0 -89
  220. package/es/components/organism/TextEditor/utils/style.d.ts +0 -78
  221. package/es/components/organism/TextEditor/utils/style.js +0 -193
  222. package/es/components/organism/index.scss +0 -1
  223. package/es/hooks/useBroadcastedLocalStorage.d.ts +0 -5
  224. package/es/hooks/useBroadcastedLocalStorage.js +0 -71
  225. package/es/hooks/useElementSize.d.ts +0 -7
  226. package/es/hooks/useElementSize.js +0 -56
  227. package/es/utils/tree.d.ts +0 -225
  228. package/es/utils/tree.js +0 -469
@@ -1,247 +0,0 @@
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
- });
@@ -1,15 +0,0 @@
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>;
@@ -1,31 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- export * from './bubble-menu-plugin';
2
- export * from './bubble-menu';
@@ -1,2 +0,0 @@
1
- export * from './bubble-menu-plugin';
2
- export * from './bubble-menu';
@@ -1,6 +0,0 @@
1
- import { ColorOptions as TiptapColorOptions } from '@tiptap/extension-color';
2
- interface ColorOptions extends TiptapColorOptions {
3
- defaultColor: string;
4
- }
5
- export declare const Color: import("@tiptap/core").Extension<ColorOptions, any>;
6
- export {};
@@ -1,41 +0,0 @@
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
- });
@@ -1,57 +0,0 @@
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>;
@@ -1,184 +0,0 @@
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
- });
@@ -1,6 +0,0 @@
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 {};
@@ -1,43 +0,0 @@
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
- });
@@ -1,32 +0,0 @@
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>;