@antscorp/antsomi-ui 2.0.84 → 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.
Files changed (231) hide show
  1. package/es/assets/css/main.scss +4 -2
  2. package/es/components/index.scss +2 -0
  3. package/es/components/molecules/EmojiPopover/EmojiPopover.js +5 -1
  4. package/es/components/molecules/FontSizeInput/FontSizeInput.d.ts +3 -0
  5. package/es/components/molecules/FontSizeInput/FontSizeInput.js +128 -0
  6. package/es/components/molecules/FontSizeInput/components/FontSizeControl.d.ts +8 -0
  7. package/es/components/molecules/FontSizeInput/components/FontSizeControl.js +14 -0
  8. package/es/components/molecules/FontSizeInput/components/FontSizeDropdown.d.ts +20 -0
  9. package/es/components/molecules/FontSizeInput/components/FontSizeDropdown.js +17 -0
  10. package/es/components/molecules/FontSizeInput/constants.d.ts +2 -0
  11. package/es/components/molecules/FontSizeInput/constants.js +5 -0
  12. package/es/components/molecules/FontSizeInput/index.d.ts +2 -0
  13. package/es/components/molecules/FontSizeInput/index.js +1 -0
  14. package/es/components/molecules/FontSizeInput/styled.d.ts +3 -0
  15. package/es/components/molecules/FontSizeInput/styled.js +22 -0
  16. package/es/components/molecules/FontSizeInput/styles.scss +15 -0
  17. package/es/components/molecules/FontSizeInput/types.d.ts +24 -0
  18. package/es/components/molecules/FontSizeInput/types.js +1 -0
  19. package/es/components/molecules/FontSizeInput/utils.d.ts +7 -0
  20. package/es/components/molecules/FontSizeInput/utils.js +9 -0
  21. package/es/components/molecules/TagifyInput/TagifyInput.js +20 -14
  22. package/es/components/molecules/TagifyInput/utils.d.ts +10 -1
  23. package/es/components/molecules/TagifyInput/utils.js +64 -6
  24. package/es/components/molecules/VirtualizedMenu/VirtualizedMenu.d.ts +6 -3
  25. package/es/components/molecules/VirtualizedMenu/__mocks__/index.js +2550 -938
  26. package/es/components/molecules/VirtualizedMenu/components/Item/Item.d.ts +13 -3
  27. package/es/components/molecules/VirtualizedMenu/components/Item/Item.js +53 -25
  28. package/es/components/molecules/VirtualizedMenu/components/Item/index.d.ts +1 -1
  29. package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.d.ts +8 -5
  30. package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.js +289 -46
  31. package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.js +1 -0
  32. package/es/components/molecules/VirtualizedMenu/styled.d.ts +1 -1
  33. package/es/components/molecules/VirtualizedMenu/styled.js +23 -4
  34. package/es/components/molecules/VirtualizedMenu/types.d.ts +6 -9
  35. package/es/components/molecules/VirtualizedMenu/utils.d.ts +8 -5
  36. package/es/components/molecules/VirtualizedMenu/utils.js +13 -18
  37. package/es/components/molecules/index.d.ts +1 -0
  38. package/es/components/molecules/index.js +1 -0
  39. package/es/components/molecules/index.scss +1 -0
  40. package/es/components/organism/ActivityTimeline/__mocks__/event_tracking.json +1290 -0
  41. package/es/components/organism/ActivityTimeline/__mocks__/timeline.json +3059 -0
  42. package/es/components/organism/TextEditor/TextEditor.d.ts +3 -0
  43. package/es/components/organism/TextEditor/TextEditor.js +251 -0
  44. package/es/components/organism/TextEditor/__mocks__/text-block.settings.json +320 -0
  45. package/es/components/organism/TextEditor/__mocks__/text-contennt.d.ts +1 -0
  46. package/es/components/organism/TextEditor/__mocks__/text-contennt.js +38 -0
  47. package/es/components/organism/TextEditor/constants.d.ts +135 -0
  48. package/es/components/organism/TextEditor/constants.js +280 -0
  49. package/es/components/organism/TextEditor/extensions/BackgroundColor.d.ts +25 -0
  50. package/es/components/organism/TextEditor/extensions/BackgroundColor.js +46 -0
  51. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.d.ts +130 -0
  52. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.js +247 -0
  53. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.d.ts +15 -0
  54. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.js +31 -0
  55. package/es/components/organism/TextEditor/extensions/BubbleMenu/index.d.ts +2 -0
  56. package/es/components/organism/TextEditor/extensions/BubbleMenu/index.js +2 -0
  57. package/es/components/organism/TextEditor/extensions/Color.d.ts +6 -0
  58. package/es/components/organism/TextEditor/extensions/Color.js +41 -0
  59. package/es/components/organism/TextEditor/extensions/Emoji.d.ts +57 -0
  60. package/es/components/organism/TextEditor/extensions/Emoji.js +184 -0
  61. package/es/components/organism/TextEditor/extensions/FontFamily.d.ts +6 -0
  62. package/es/components/organism/TextEditor/extensions/FontFamily.js +43 -0
  63. package/es/components/organism/TextEditor/extensions/FontSize.d.ts +32 -0
  64. package/es/components/organism/TextEditor/extensions/FontSize.js +47 -0
  65. package/es/components/organism/TextEditor/extensions/FontWeight.d.ts +23 -0
  66. package/es/components/organism/TextEditor/extensions/FontWeight.js +41 -0
  67. package/es/components/organism/TextEditor/extensions/Highlight.d.ts +1 -0
  68. package/es/components/organism/TextEditor/extensions/Highlight.js +14 -0
  69. package/es/components/organism/TextEditor/extensions/Indent.d.ts +28 -0
  70. package/es/components/organism/TextEditor/extensions/Indent.js +68 -0
  71. package/es/components/organism/TextEditor/extensions/LineHeight.d.ts +20 -0
  72. package/es/components/organism/TextEditor/extensions/LineHeight.js +36 -0
  73. package/es/components/organism/TextEditor/extensions/Link.d.ts +15 -0
  74. package/es/components/organism/TextEditor/extensions/Link.js +50 -0
  75. package/es/components/organism/TextEditor/extensions/ListItemMarker.d.ts +13 -0
  76. package/es/components/organism/TextEditor/extensions/ListItemMarker.js +174 -0
  77. package/es/components/organism/TextEditor/extensions/Selection.d.ts +6 -0
  78. package/es/components/organism/TextEditor/extensions/Selection.js +40 -0
  79. package/es/components/organism/TextEditor/extensions/SmartTag.d.ts +39 -0
  80. package/es/components/organism/TextEditor/extensions/SmartTag.js +167 -0
  81. package/es/components/organism/TextEditor/extensions/StyleMemory.d.ts +36 -0
  82. package/es/components/organism/TextEditor/extensions/StyleMemory.js +163 -0
  83. package/es/components/organism/TextEditor/extensions/TextTransform.d.ts +31 -0
  84. package/es/components/organism/TextEditor/extensions/TextTransform.js +37 -0
  85. package/es/components/organism/TextEditor/hooks/index.d.ts +6 -0
  86. package/es/components/organism/TextEditor/hooks/index.js +6 -0
  87. package/es/components/organism/TextEditor/hooks/useDocumentState.d.ts +18 -0
  88. package/es/components/organism/TextEditor/hooks/useDocumentState.js +42 -0
  89. package/es/components/organism/TextEditor/hooks/useLinkHandler.d.ts +10 -0
  90. package/es/components/organism/TextEditor/hooks/useLinkHandler.js +223 -0
  91. package/es/components/organism/TextEditor/hooks/useMarkTracking.d.ts +26 -0
  92. package/es/components/organism/TextEditor/hooks/useMarkTracking.js +68 -0
  93. package/es/components/organism/TextEditor/hooks/usePersistence.d.ts +31 -0
  94. package/es/components/organism/TextEditor/hooks/usePersistence.js +169 -0
  95. package/es/components/organism/TextEditor/hooks/useStyleMemory.d.ts +6 -0
  96. package/es/components/organism/TextEditor/hooks/useStyleMemory.js +42 -0
  97. package/es/components/organism/TextEditor/hooks/useStylePresets.d.ts +34 -0
  98. package/es/components/organism/TextEditor/hooks/useStylePresets.js +83 -0
  99. package/es/components/organism/TextEditor/index.d.ts +14 -0
  100. package/es/components/organism/TextEditor/index.js +6 -0
  101. package/es/components/organism/TextEditor/index.scss +61 -0
  102. package/es/components/organism/TextEditor/provider.d.ts +10 -0
  103. package/es/components/organism/TextEditor/provider.js +20 -0
  104. package/es/components/organism/TextEditor/store.d.ts +11 -0
  105. package/es/components/organism/TextEditor/store.js +12 -0
  106. package/es/components/organism/TextEditor/styled.d.ts +8 -0
  107. package/es/components/organism/TextEditor/styled.js +90 -0
  108. package/es/components/organism/TextEditor/types.d.ts +92 -0
  109. package/es/components/organism/TextEditor/types.js +1 -0
  110. package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.d.ts +6 -0
  111. package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.js +78 -0
  112. package/es/components/organism/TextEditor/ui/BubbleMenu/index.d.ts +1 -0
  113. package/es/components/organism/TextEditor/ui/BubbleMenu/index.js +1 -0
  114. package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.d.ts +43 -0
  115. package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.js +120 -0
  116. package/es/components/organism/TextEditor/ui/ColorPicker/index.d.ts +1 -0
  117. package/es/components/organism/TextEditor/ui/ColorPicker/index.js +1 -0
  118. package/es/components/organism/TextEditor/ui/Emoji/EmojiList.d.ts +11 -0
  119. package/es/components/organism/TextEditor/ui/Emoji/EmojiList.js +66 -0
  120. package/es/components/organism/TextEditor/ui/Emoji/index.d.ts +2 -0
  121. package/es/components/organism/TextEditor/ui/Emoji/index.js +2 -0
  122. package/es/components/organism/TextEditor/ui/Emoji/suggestion.d.ts +4 -0
  123. package/es/components/organism/TextEditor/ui/Emoji/suggestion.js +71 -0
  124. package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.d.ts +12 -0
  125. package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.js +69 -0
  126. package/es/components/organism/TextEditor/ui/FontPopover/styled.d.ts +1 -0
  127. package/es/components/organism/TextEditor/ui/FontPopover/styled.js +20 -0
  128. package/es/components/organism/TextEditor/ui/Popover/Popover.d.ts +6 -0
  129. package/es/components/organism/TextEditor/ui/Popover/Popover.js +7 -0
  130. package/es/components/organism/TextEditor/ui/Popover/index.d.ts +1 -0
  131. package/es/components/organism/TextEditor/ui/Popover/index.js +1 -0
  132. package/es/components/organism/TextEditor/ui/Select/Select.d.ts +4 -0
  133. package/es/components/organism/TextEditor/ui/Select/Select.js +7 -0
  134. package/es/components/organism/TextEditor/ui/Select/index.d.ts +1 -0
  135. package/es/components/organism/TextEditor/ui/Select/index.js +1 -0
  136. package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.d.ts +30 -0
  137. package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.js +49 -0
  138. package/es/components/organism/TextEditor/ui/TextAlignSelect/index.d.ts +1 -0
  139. package/es/components/organism/TextEditor/ui/TextAlignSelect/index.js +1 -0
  140. package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.d.ts +14 -0
  141. package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.js +42 -0
  142. package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.d.ts +5 -0
  143. package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.js +7 -0
  144. package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.d.ts +5 -0
  145. package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.js +7 -0
  146. package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.d.ts +5 -0
  147. package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.js +18 -0
  148. package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.d.ts +4 -0
  149. package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.js +13 -0
  150. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.d.ts +7 -0
  151. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.js +18 -0
  152. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.d.ts +7 -0
  153. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.js +37 -0
  154. package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.d.ts +5 -0
  155. package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.js +7 -0
  156. package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.d.ts +5 -0
  157. package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.js +7 -0
  158. package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.d.ts +5 -0
  159. package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.js +7 -0
  160. package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.d.ts +6 -0
  161. package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.js +4 -0
  162. package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.d.ts +5 -0
  163. package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.js +7 -0
  164. package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.d.ts +5 -0
  165. package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.js +7 -0
  166. package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.d.ts +7 -0
  167. package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.js +9 -0
  168. package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.d.ts +9 -0
  169. package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.js +22 -0
  170. package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.d.ts +5 -0
  171. package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.js +7 -0
  172. package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.d.ts +5 -0
  173. package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.js +13 -0
  174. package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.d.ts +5 -0
  175. package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.js +13 -0
  176. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.d.ts +5 -0
  177. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.js +3 -0
  178. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.d.ts +7 -0
  179. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.js +19 -0
  180. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.d.ts +15 -0
  181. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.js +14 -0
  182. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.d.ts +5 -0
  183. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.js +30 -0
  184. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.d.ts +5 -0
  185. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.js +5 -0
  186. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.d.ts +6 -0
  187. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.js +10 -0
  188. package/es/components/organism/TextEditor/ui/Toolbar/actions/index.d.ts +20 -0
  189. package/es/components/organism/TextEditor/ui/Toolbar/actions/index.js +20 -0
  190. package/es/components/organism/TextEditor/ui/Toolbar/index.d.ts +1 -0
  191. package/es/components/organism/TextEditor/ui/Toolbar/index.js +1 -0
  192. package/es/components/organism/TextEditor/utils/documentState.d.ts +57 -0
  193. package/es/components/organism/TextEditor/utils/documentState.js +100 -0
  194. package/es/components/organism/TextEditor/utils/font.d.ts +84 -0
  195. package/es/components/organism/TextEditor/utils/font.js +175 -0
  196. package/es/components/organism/TextEditor/utils/htmlProcessing.d.ts +63 -0
  197. package/es/components/organism/TextEditor/utils/htmlProcessing.js +321 -0
  198. package/es/components/organism/TextEditor/utils/index.d.ts +8 -0
  199. package/es/components/organism/TextEditor/utils/index.js +16 -0
  200. package/es/components/organism/TextEditor/utils/link.d.ts +100 -0
  201. package/es/components/organism/TextEditor/utils/link.js +149 -0
  202. package/es/components/organism/TextEditor/utils/menu.d.ts +134 -0
  203. package/es/components/organism/TextEditor/utils/menu.js +317 -0
  204. package/es/components/organism/TextEditor/utils/selection.d.ts +25 -0
  205. package/es/components/organism/TextEditor/utils/selection.js +57 -0
  206. package/es/components/organism/TextEditor/utils/smartTag.d.ts +49 -0
  207. package/es/components/organism/TextEditor/utils/smartTag.js +89 -0
  208. package/es/components/organism/TextEditor/utils/style.d.ts +78 -0
  209. package/es/components/organism/TextEditor/utils/style.js +193 -0
  210. package/es/components/organism/index.d.ts +1 -0
  211. package/es/components/organism/index.js +1 -0
  212. package/es/components/organism/index.scss +1 -0
  213. package/es/config/index.d.ts +1 -0
  214. package/es/config/index.js +1 -0
  215. package/es/constants/api.d.ts +10 -0
  216. package/es/constants/api.js +10 -0
  217. package/es/hooks/index.d.ts +1 -0
  218. package/es/hooks/index.js +1 -0
  219. package/es/hooks/useBroadcastedLocalStorage.d.ts +5 -0
  220. package/es/hooks/useBroadcastedLocalStorage.js +71 -0
  221. package/es/hooks/useElementSize.d.ts +7 -0
  222. package/es/hooks/useElementSize.js +56 -0
  223. package/es/utils/common.d.ts +6 -9
  224. package/es/utils/common.js +44 -23
  225. package/es/utils/index.d.ts +1 -0
  226. package/es/utils/index.js +1 -0
  227. package/es/utils/tree.d.ts +225 -0
  228. package/es/utils/tree.js +469 -0
  229. package/es/utils/web.d.ts +4 -0
  230. package/es/utils/web.js +25 -0
  231. package/package.json +29 -3
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { JSONContent } from '@tiptap/core';
3
+ export type { TextEditorProps, TextEditorRef } from './types';
4
+ export type { JSONContent as TextEditorJSONContent };
5
+ export { TextEditorProvider } from './provider';
6
+ export declare const TextEditor: import("react").NamedExoticComponent<Omit<import("./types").TextEditorProps & import("react").RefAttributes<import("./types").TextEditorRef>, "ref"> & {
7
+ ref?: ((instance: import("./types").TextEditorRef | null) => void) | import("react").RefObject<import("./types").TextEditorRef> | null | undefined;
8
+ }> & {
9
+ readonly type: import("react").ForwardRefExoticComponent<import("./types").TextEditorProps & import("react").RefAttributes<import("./types").TextEditorRef>>;
10
+ } & {
11
+ Utils: {
12
+ htmlMinifyForEmail: (htmlEditorContent: string) => string;
13
+ };
14
+ };
@@ -0,0 +1,6 @@
1
+ import { TextEditor as TextEditorComponent } from './TextEditor';
2
+ import { htmlMinifyForEmail } from './utils';
3
+ export { TextEditorProvider } from './provider';
4
+ export const TextEditor = Object.assign(TextEditorComponent, {
5
+ Utils: { htmlMinifyForEmail },
6
+ });
@@ -0,0 +1,61 @@
1
+ .antsomi-text-editor-bubble-menu {
2
+ visibility: hidden;
3
+ position: absolute;
4
+ pointer-events: auto;
5
+ z-index: 999;
6
+ }
7
+
8
+ .antsomi-text-editor-emoji-popover {
9
+ position: absolute;
10
+ width: 180px;
11
+ z-index: 1000;
12
+
13
+ .antsomi-text-editor-emoji-list {
14
+ .antsomi-virtualize-menu-menu-inline {
15
+ background-color: white;
16
+ box-shadow: var(--antsomi-box-shadow-secondary);
17
+ border-radius: 10px;
18
+
19
+ .antsomi-virtualize-menu-item-label {
20
+ display: flex;
21
+ align-items: center;
22
+ gap: 10px;
23
+ }
24
+ }
25
+ }
26
+ }
27
+
28
+ .font-popover-overlay {
29
+ padding: 0;
30
+
31
+ .font-popover-item {
32
+ width: 100%;
33
+ height: 100%;
34
+ cursor: pointer;
35
+ padding-left: 10px;
36
+ padding-right: 8px;
37
+
38
+ &:hover,
39
+ &.active {
40
+ background-color: #f2f9ff;
41
+ }
42
+ }
43
+ }
44
+
45
+ .font-weight-popover {
46
+ &.antsomi-popover {
47
+ .antsomi-popover-inner {
48
+ padding: 10px 0px;
49
+
50
+ .font-weight-item {
51
+ padding: 4px 10px;
52
+ cursor: pointer;
53
+
54
+ &:hover,
55
+ &.active {
56
+ background-color: #f2f9ff;
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { StoreApi } from 'zustand';
3
+ import type { TextEditorStore } from './store';
4
+ export type TextEditorStoreApi = StoreApi<TextEditorStore>;
5
+ export declare const TextEditorStoreContext: import("react").Context<TextEditorStoreApi | null>;
6
+ export interface TextEditorProviderProps {
7
+ children: React.ReactNode | ((props: TextEditorStoreApi) => React.ReactNode);
8
+ }
9
+ export declare const TextEditorProvider: React.FC<React.PropsWithChildren<TextEditorProviderProps>>;
10
+ export declare const useTextEditorStore: <T>(selector: (state: TextEditorStore) => T) => T;
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // Libraries
3
+ import { createContext, useContext, useRef } from 'react';
4
+ import { useStore } from 'zustand';
5
+ // Store
6
+ import { createTextEditorStore } from './store';
7
+ export const TextEditorStoreContext = createContext(null);
8
+ export const TextEditorProvider = ({ children, }) => {
9
+ const storeRef = useRef();
10
+ if (!storeRef.current) {
11
+ storeRef.current = createTextEditorStore();
12
+ }
13
+ return (_jsx(TextEditorStoreContext.Provider, { value: storeRef.current, children: typeof children === 'function' ? children(storeRef.current) : children }));
14
+ };
15
+ export const useTextEditorStore = (selector) => {
16
+ const store = useContext(TextEditorStoreContext);
17
+ if (!store)
18
+ throw new Error('Missing TextEditorStoreContext.Provider in the tree');
19
+ return useStore(store, selector);
20
+ };
@@ -0,0 +1,11 @@
1
+ export type TextEditorState = {
2
+ bubbleMenuContainer: HTMLDivElement | null;
3
+ isShowBubbleMenu: boolean;
4
+ };
5
+ export type TextEditorActions = {
6
+ setBubbleMenuContainer: (container: HTMLDivElement | null) => void;
7
+ setIsShowBubbleMenu: (isShow: boolean) => void;
8
+ };
9
+ export type TextEditorStore = TextEditorState & TextEditorActions;
10
+ export declare const defaultTextEditorState: TextEditorState;
11
+ export declare const createTextEditorStore: (initState?: Partial<TextEditorState>) => import("zustand").StoreApi<TextEditorStore>;
@@ -0,0 +1,12 @@
1
+ // Libraries
2
+ import { createStore } from 'zustand';
3
+ export const defaultTextEditorState = {
4
+ bubbleMenuContainer: null,
5
+ isShowBubbleMenu: false,
6
+ };
7
+ export const createTextEditorStore = (initState = {}) => createStore()(set => ({
8
+ ...defaultTextEditorState,
9
+ ...initState,
10
+ setBubbleMenuContainer: container => set(() => ({ bubbleMenuContainer: container })),
11
+ setIsShowBubbleMenu: isShow => set(() => ({ isShowBubbleMenu: isShow })),
12
+ }));
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { TextStyle } from './types';
3
+ export declare const StyledBubbleMenu: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<Pick<Partial<Omit<Pick<Partial<import("./extensions/BubbleMenu").BubbleMenuPluginProps>, "pluginKey"> & Omit<import("./extensions/BubbleMenu").BubbleMenuPluginProps, "pluginKey">, "element">>, "editor"> & Omit<Omit<Pick<Partial<import("./extensions/BubbleMenu").BubbleMenuPluginProps>, "pluginKey"> & Omit<import("./extensions/BubbleMenu").BubbleMenuPluginProps, "pluginKey">, "element">, "editor"> & import("react").HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>, any, {}, never>;
4
+ export declare const StyledEditorContent: import("styled-components").StyledComponent<import("react").NamedExoticComponent<Omit<import("@tiptap/react").EditorContentProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>, any, {
5
+ $textStyle: TextStyle;
6
+ }, never>;
7
+ export declare const ColorBox: import("styled-components").StyledComponent<"div", any, {}, never>;
8
+ export declare const ToolbarWrapper: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("antd").FlexProps<import("antd/es/_util/type").AnyObject> & import("react").RefAttributes<HTMLElement>>, any, {}, never>;
@@ -0,0 +1,90 @@
1
+ import { EditorContent } from '@tiptap/react';
2
+ import styled, { css } from 'styled-components';
3
+ import { BubbleMenu } from './ui/BubbleMenu';
4
+ import { SMART_TAG_HIGHLIGHT_BG } from './constants';
5
+ import { THEME } from '@antscorp/antsomi-ui/es/constants';
6
+ import { Flex } from 'antd';
7
+ export const StyledBubbleMenu = styled(BubbleMenu) `
8
+ background-color: white;
9
+ border: 1px solid ${THEME.token?.blue1};
10
+ border-radius: 5px;
11
+ padding: 8px;
12
+ `;
13
+ const dynContentStyles = css `
14
+ background-color: ${SMART_TAG_HIGHLIGHT_BG};
15
+ background-color: color-mix(
16
+ in lab,
17
+ var(--text-style-bg-color, transparent),
18
+ ${SMART_TAG_HIGHLIGHT_BG}
19
+ );
20
+
21
+ &:hover {
22
+ background-color: ${SMART_TAG_HIGHLIGHT_BG};
23
+ background-color: color-mix(
24
+ in lab,
25
+ var(--text-style-bg-color, transparent),
26
+ ${SMART_TAG_HIGHLIGHT_BG} 80%
27
+ );
28
+ }
29
+ `;
30
+ export const StyledEditorContent = styled(EditorContent) `
31
+ .tiptap {
32
+ outline: none;
33
+
34
+ p {
35
+ margin: 0;
36
+ padding: 0;
37
+
38
+ line-height: ${p => p.$textStyle.lineHeight};
39
+ font-family: ${p => p.$textStyle.fontFamily};
40
+ font-size: ${p => p.$textStyle.fontSize};
41
+ color: ${p => p.$textStyle.color};
42
+ }
43
+
44
+ &:not([contenteditable='false']) {
45
+ p {
46
+ cursor: text;
47
+ }
48
+
49
+ .selection {
50
+ background-color: #d7cac9;
51
+ background-color: color-mix(in lab, var(--text-style-bg-color, transparent), #d7cac9);
52
+ }
53
+
54
+ .smart-tag {
55
+ cursor: pointer;
56
+
57
+ &.highlight {
58
+ ${dynContentStyles}
59
+ }
60
+ }
61
+
62
+ .link {
63
+ &.highlight > span {
64
+ ${dynContentStyles}
65
+ }
66
+ }
67
+ }
68
+ }
69
+ `;
70
+ export const ColorBox = styled.div `
71
+ cursor: pointer;
72
+ width: 20px;
73
+ height: 20px;
74
+ border-radius: 50%;
75
+ border: 1px solid #d9d9d9;
76
+
77
+ &:hover {
78
+ box-shadow: rgba(0, 0, 0, 0.35) 0px 0px 3px;
79
+ }
80
+
81
+ &.active {
82
+ box-shadow: blue 0px 0px 3px;
83
+ }
84
+ `;
85
+ export const ToolbarWrapper = styled(Flex) `
86
+ .antsomi-divider.toolbar-separator {
87
+ height: 20px;
88
+ margin: 2px;
89
+ }
90
+ `;
@@ -0,0 +1,92 @@
1
+ import React from 'react';
2
+ import { JSONContent, Editor } from '@tiptap/core';
3
+ import { LinkAttrs } from './extensions/Link';
4
+ import { SmartTagAttrs } from './extensions/SmartTag';
5
+ export type HandleSmartTagRef = {
6
+ setSmartTag: (attrs: SmartTagAttrs) => void;
7
+ deleteSmartTag: (id: string) => void;
8
+ updateSmartTagAttrs: (id: string, updatedAttrs: Omit<SmartTagAttrs, 'id'>) => void;
9
+ };
10
+ export type HandleLinkRef = {
11
+ setLink: (attrs: LinkAttrs) => void;
12
+ deleteLink: (id: string) => void;
13
+ updateLinkAttrs: (id: string, updatedAttrs: Omit<LinkAttrs, 'id'>) => void;
14
+ };
15
+ export type TextEditorRef = HandleSmartTagRef & HandleLinkRef & {
16
+ blur: (perserveSelection?: boolean) => void;
17
+ style?: CSSStyleDeclaration;
18
+ readonly editor: Editor | null;
19
+ };
20
+ export type SmartTagHandler = Partial<{
21
+ edit: (id: string, event: React.MouseEvent) => void;
22
+ setNew: (args: {
23
+ selectionText: string;
24
+ }) => void;
25
+ }>;
26
+ export type LinkHandler = Partial<{
27
+ setNew: (args: {
28
+ selectionText: string;
29
+ }) => void;
30
+ edit: (args: {
31
+ id: string;
32
+ selectionText: string;
33
+ }) => void;
34
+ }>;
35
+ export type FontConfig = {
36
+ fontFamily: {
37
+ name: string;
38
+ fallback?: string[];
39
+ };
40
+ fontWeight: number[];
41
+ };
42
+ export type Config = Partial<{
43
+ SmartTag: Partial<{
44
+ highlight: boolean;
45
+ }>;
46
+ Link: Partial<{
47
+ highlightDynamic: boolean;
48
+ }>;
49
+ Color: {
50
+ colorPickerStorageKey: string;
51
+ };
52
+ BackgroundColor: {
53
+ colorPickerStorageKey: string;
54
+ };
55
+ FontFamily: {
56
+ fonts: FontConfig[];
57
+ };
58
+ }>;
59
+ export type TextStyle = {
60
+ fontFamily: string;
61
+ fontSize: string;
62
+ color: string;
63
+ backgroundColor: string;
64
+ lineHeight: string;
65
+ fontWeight: string;
66
+ };
67
+ export type TextEditorProps = {
68
+ id?: string;
69
+ className?: string;
70
+ style?: React.CSSProperties;
71
+ initialContent?: string;
72
+ config?: Config;
73
+ smartTagHandler?: SmartTagHandler;
74
+ linkHandler?: LinkHandler;
75
+ editable?: boolean;
76
+ bubbleMenuProps?: {
77
+ container?: HTMLElement | null;
78
+ };
79
+ defaultTextStyle?: Partial<TextStyle>;
80
+ dataAttributes?: Record<`data-${string}`, unknown>;
81
+ onFocus?: (event: FocusEvent) => void;
82
+ onUpdate?: (args: {
83
+ html: string;
84
+ text: string;
85
+ json: JSONContent;
86
+ }) => void;
87
+ onCreate?: (args: {
88
+ html: string;
89
+ text: string;
90
+ json: JSONContent;
91
+ }) => void;
92
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { BubbleMenuPluginProps } from '../../extensions/BubbleMenu';
3
+ type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
4
+ export type BubbleMenuProps = Optional<Omit<Optional<BubbleMenuPluginProps, 'pluginKey'>, 'element'>, 'editor'> & React.HTMLAttributes<HTMLDivElement>;
5
+ export declare const BubbleMenu: React.ForwardRefExoticComponent<Pick<Partial<Omit<Optional<BubbleMenuPluginProps, "pluginKey">, "element">>, "editor"> & Omit<Omit<Optional<BubbleMenuPluginProps, "pluginKey">, "element">, "editor"> & React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
6
+ export {};
@@ -0,0 +1,78 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /* eslint-disable no-console */
3
+ import { useCurrentEditor } from '@tiptap/react';
4
+ import { forwardRef, useRef } from 'react';
5
+ import { createPortal } from 'react-dom';
6
+ import { BubbleMenuPlugin } from '../../extensions/BubbleMenu';
7
+ import { useDeepCompareEffect } from '@antscorp/antsomi-ui/es/hooks';
8
+ import { useTextEditorStore } from '../../provider';
9
+ import clsx from 'clsx';
10
+ import { ANTSOMI_COMPONENT_PREFIX_CLS } from '@antscorp/antsomi-ui/es/constants';
11
+ export const BubbleMenu = forwardRef(({ pluginKey = 'bubbleMenu', editor, updateDelay, resizeDelay, shouldShow = null, options, children, container, className, ...restProps }, ref) => {
12
+ const menuEl = useRef(document.createElement('div'));
13
+ const setIsShowBubbleMenu = useTextEditorStore(state => state.setIsShowBubbleMenu);
14
+ if (typeof ref === 'function') {
15
+ ref(menuEl.current);
16
+ }
17
+ else if (ref) {
18
+ ref.current = menuEl.current;
19
+ }
20
+ const { editor: currentEditor } = useCurrentEditor();
21
+ useDeepCompareEffect(() => {
22
+ const bubbleMenuElement = menuEl.current;
23
+ bubbleMenuElement.className = clsx(className, `${ANTSOMI_COMPONENT_PREFIX_CLS}-text-editor-bubble-menu`);
24
+ if (editor?.isDestroyed || currentEditor?.isDestroyed) {
25
+ return;
26
+ }
27
+ const attachToEditor = editor || currentEditor;
28
+ if (!attachToEditor) {
29
+ console.warn('BubbleMenu component is not rendered inside of an editor component or does not have editor prop.');
30
+ return;
31
+ }
32
+ const plugin = BubbleMenuPlugin({
33
+ updateDelay,
34
+ resizeDelay,
35
+ editor: attachToEditor,
36
+ element: bubbleMenuElement,
37
+ container,
38
+ pluginKey,
39
+ shouldShow,
40
+ onShow: () => {
41
+ setIsShowBubbleMenu(true);
42
+ },
43
+ onHide: () => {
44
+ setIsShowBubbleMenu(false);
45
+ },
46
+ options: {
47
+ ...options,
48
+ strategy: options?.strategy || 'absolute',
49
+ placement: options?.placement || 'top-start',
50
+ offset: options?.offset || {
51
+ alignmentAxis: -20,
52
+ mainAxis: 10,
53
+ },
54
+ },
55
+ });
56
+ attachToEditor.registerPlugin(plugin);
57
+ return () => {
58
+ attachToEditor.unregisterPlugin(pluginKey);
59
+ window.requestAnimationFrame(() => {
60
+ if (bubbleMenuElement.parentNode) {
61
+ bubbleMenuElement.parentNode.removeChild(bubbleMenuElement);
62
+ }
63
+ });
64
+ };
65
+ }, [
66
+ editor,
67
+ container,
68
+ updateDelay,
69
+ resizeDelay,
70
+ pluginKey,
71
+ options,
72
+ className,
73
+ currentEditor,
74
+ shouldShow,
75
+ setIsShowBubbleMenu,
76
+ ]);
77
+ return createPortal(_jsx("div", { ...restProps, children: children }), menuEl.current);
78
+ });
@@ -0,0 +1 @@
1
+ export { BubbleMenu, type BubbleMenuProps } from './BubbleMenu';
@@ -0,0 +1 @@
1
+ export { BubbleMenu } from './BubbleMenu';
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import { PopoverProps } from 'antd/lib';
3
+ export interface ColorPickerProps {
4
+ value?: string;
5
+ children?: React.ReactNode;
6
+ usedColorsStorageKey?: string;
7
+ onChange?: (value: string) => void;
8
+ popoverProps?: Omit<PopoverProps, 'content'> & {
9
+ content?: ((args: {
10
+ colorGrid: React.ReactNode;
11
+ usedColors: React.ReactNode;
12
+ customColorPicker: React.ReactNode;
13
+ }) => React.ReactNode) | React.ReactNode;
14
+ };
15
+ }
16
+ export interface ColorPickerRef {
17
+ setOpen: (open: boolean) => void;
18
+ }
19
+ export interface UsedColorsProps {
20
+ value?: string;
21
+ usedColorsStorageKey?: string;
22
+ onChange?: (value: string) => void;
23
+ }
24
+ export interface GridColorProps {
25
+ value?: string;
26
+ usedColorsStorageKey?: string;
27
+ colorGrid?: string[][];
28
+ onChange?: (value: string) => void;
29
+ }
30
+ export interface UseUsedColorsParams {
31
+ key?: string;
32
+ numberOfColors?: number;
33
+ }
34
+ export interface BoxColorProps {
35
+ color?: string;
36
+ isActive?: boolean;
37
+ onClick?: (e: React.MouseEvent) => void;
38
+ }
39
+ export interface CustomColorPickerProps {
40
+ currentColor: string;
41
+ onApply?: (value: string) => void;
42
+ }
43
+ export declare const ColorPicker: React.ForwardRefExoticComponent<ColorPickerProps & React.RefAttributes<ColorPickerRef>>;
@@ -0,0 +1,120 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /* eslint-disable react/no-array-index-key */
3
+ import { ColorPicker as AntdColorPicker, Button, Col, Flex, Row, Typography } from 'antd';
4
+ import { chunk } from 'lodash';
5
+ import { TEXT_EDITOR_CONSTANTS } from '../../constants';
6
+ import clsx from 'clsx';
7
+ import { forwardRef, useEffect, useState, useImperativeHandle } from 'react';
8
+ import { useDebouncedCallback } from 'use-debounce';
9
+ import { useBroadcastedLocalStorage } from '@antscorp/antsomi-ui/es/hooks/useBroadcastedLocalStorage';
10
+ import { useTextEditorStore } from '../../provider';
11
+ import { ColorBox } from '../../styled';
12
+ import { TextEditorPopover } from '../Popover';
13
+ const { COLOR_GIRD } = TEXT_EDITOR_CONSTANTS;
14
+ const CustomColorPicker = (props) => {
15
+ const { onApply, currentColor } = props;
16
+ const [isOpen, setIsOpen] = useState(false);
17
+ const [color, setColor] = useState(currentColor);
18
+ const bubbleMenuContainer = useTextEditorStore(state => state.bubbleMenuContainer);
19
+ useEffect(() => {
20
+ setColor(currentColor);
21
+ }, [currentColor]);
22
+ const handleChangeColor = useDebouncedCallback((newColor) => {
23
+ setColor(newColor);
24
+ }, 50);
25
+ const handleClose = () => {
26
+ setIsOpen(false);
27
+ handleChangeColor(currentColor);
28
+ };
29
+ const handleApply = () => {
30
+ handleClose();
31
+ onApply?.(color);
32
+ };
33
+ return (_jsx(AntdColorPicker, { getPopupContainer: () => bubbleMenuContainer || document.body, open: isOpen, value: color, onOpenChange: setOpen => setIsOpen(setOpen), onChange: newColor => handleChangeColor(newColor.toRgbString()), placement: "bottomRight", destroyTooltipOnHide: true, panelRender: panel => (_jsxs(_Fragment, { children: [panel, _jsxs(Flex, { justify: "end", gap: 8, style: { marginTop: 10 }, children: [_jsx(Button, { size: "small", type: "default", onClick: handleClose, children: "Cancel" }), _jsx(Button, { size: "small", type: "primary", onClick: handleApply, children: "Apply" })] })] })), children: _jsx(Button, { children: "Custom" }) }));
34
+ };
35
+ const BoxColor = (props) => {
36
+ const { color, isActive, onClick } = props;
37
+ const handleClick = (e) => {
38
+ e.stopPropagation();
39
+ onClick?.(e);
40
+ };
41
+ return (_jsx(ColorBox, { style: { backgroundColor: color }, className: clsx({
42
+ active: isActive,
43
+ }), onClick: handleClick }));
44
+ };
45
+ const useUsedColors = (params) => {
46
+ const { key = 'used-colors', numberOfColors = 10 } = params || {};
47
+ const { value: usedColors, setValue: setUsedColors } = useBroadcastedLocalStorage(key, []);
48
+ const addColor = (color) => {
49
+ const updatedColors = [...usedColors];
50
+ if (!usedColors.includes(color)) {
51
+ updatedColors.push(color);
52
+ if (usedColors.length >= numberOfColors) {
53
+ updatedColors.shift();
54
+ }
55
+ }
56
+ setUsedColors(updatedColors);
57
+ };
58
+ return { usedColors, addColor };
59
+ };
60
+ const UsedColors = (props) => {
61
+ const { onChange, value, usedColorsStorageKey } = props;
62
+ const { usedColors, addColor: addUsedColor } = useUsedColors({
63
+ key: usedColorsStorageKey,
64
+ });
65
+ const rowColorSize = COLOR_GIRD[0].length;
66
+ const handleClick = (color) => {
67
+ addUsedColor(color);
68
+ onChange?.(color);
69
+ };
70
+ if (usedColors.length === 0) {
71
+ return null;
72
+ }
73
+ return (_jsxs(Flex, { vertical: true, gap: 2, children: [_jsx(Typography.Text, { children: "Recently used" }), chunk(usedColors, rowColorSize).map((row, rowIndex) => (_jsx(Row, { gutter: [2, 2], children: row.map((color, colIndex) => (_jsx(Col, { span: 24 / rowColorSize, children: _jsx(BoxColor, { color: color, isActive: color === value, onClick: () => handleClick(color) }) }, `${rowIndex}-${colIndex}`))) }, rowIndex)))] }));
74
+ };
75
+ const GridColor = (props) => {
76
+ const { onChange, value, usedColorsStorageKey, colorGrid = COLOR_GIRD } = props;
77
+ const rowColorSize = colorGrid[0].length;
78
+ const { addColor: addUsedColor } = useUsedColors({
79
+ key: usedColorsStorageKey,
80
+ });
81
+ const handleClick = (color) => {
82
+ addUsedColor(color);
83
+ onChange?.(color);
84
+ };
85
+ return (_jsx(Flex, { vertical: true, gap: 2, children: colorGrid.map((row, rowIndex) => (_jsx(Row, { gutter: [2, 2], children: row.map((color, colIndex) => (_jsx(Col, { span: 24 / rowColorSize, children: _jsx(BoxColor, { color: color, isActive: color === value, onClick: () => handleClick(color) }) }, `${rowIndex}-${colIndex}`))) }, rowIndex))) }));
86
+ };
87
+ export const ColorPicker = forwardRef((props, ref) => {
88
+ const { value = '', onChange, children, usedColorsStorageKey = 'used-colors', popoverProps, } = props;
89
+ const [isOpen, setIsOpen] = useState(false);
90
+ useEffect(() => {
91
+ if (popoverProps?.open !== undefined) {
92
+ setIsOpen(popoverProps.open);
93
+ }
94
+ }, [popoverProps?.open]);
95
+ const handleChangeOpen = (open) => {
96
+ setIsOpen(open);
97
+ if (popoverProps?.onOpenChange) {
98
+ popoverProps.onOpenChange(open);
99
+ }
100
+ };
101
+ const handleOnChange = (color) => {
102
+ onChange?.(color);
103
+ handleChangeOpen(false);
104
+ };
105
+ useImperativeHandle(ref, () => ({
106
+ setOpen: handleChangeOpen,
107
+ }));
108
+ const colorGrid = (_jsx(GridColor, { onChange: handleOnChange, value: value, usedColorsStorageKey: usedColorsStorageKey }));
109
+ const usedColors = (_jsx(UsedColors, { onChange: handleOnChange, value: value, usedColorsStorageKey: usedColorsStorageKey }));
110
+ const customColorPicker = _jsx(CustomColorPicker, { currentColor: value, onApply: handleOnChange });
111
+ let content = (_jsxs(Flex, { vertical: true, gap: 8, children: [colorGrid, usedColors, customColorPicker] }));
112
+ if (typeof popoverProps?.content === 'function') {
113
+ content = popoverProps.content({
114
+ colorGrid,
115
+ usedColors,
116
+ customColorPicker,
117
+ });
118
+ }
119
+ return (_jsx(TextEditorPopover, { trigger: ['click'], placement: "bottomLeft", ...popoverProps, open: isOpen, onOpenChange: handleChangeOpen, content: content, children: children }));
120
+ });
@@ -0,0 +1 @@
1
+ export { ColorPicker } from './ColorPicker';
@@ -0,0 +1 @@
1
+ export { ColorPicker } from './ColorPicker';
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { EmojiNodeAttrs, SuggestionItem } from '../../extensions/Emoji';
3
+ import { SuggestionProps } from '@tiptap/suggestion';
4
+ export declare const ITEM_SIZE = 28;
5
+ export type EmojiListRef = {
6
+ onKeyDown: (args: {
7
+ event: KeyboardEvent;
8
+ }) => boolean;
9
+ };
10
+ export type EmojiListProps = SuggestionProps<SuggestionItem, EmojiNodeAttrs>;
11
+ export declare const EmojiList: import("react").ForwardRefExoticComponent<EmojiListProps & import("react").RefAttributes<EmojiListRef>>;