@antscorp/antsomi-ui 2.0.82 → 2.0.83-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 (213) hide show
  1. package/es/assets/css/main.scss +4 -2
  2. package/es/components/index.scss +1 -0
  3. package/es/components/molecules/AccountSelection/AccountListing.js +14 -3
  4. package/es/components/molecules/EmojiPopover/EmojiPopover.js +5 -1
  5. package/es/components/molecules/FontSizeInput/FontSizeInput.d.ts +3 -0
  6. package/es/components/molecules/FontSizeInput/FontSizeInput.js +77 -0
  7. package/es/components/molecules/FontSizeInput/constants.d.ts +2 -0
  8. package/es/components/molecules/FontSizeInput/constants.js +5 -0
  9. package/es/components/molecules/FontSizeInput/index.d.ts +2 -0
  10. package/es/components/molecules/FontSizeInput/index.js +1 -0
  11. package/es/components/molecules/FontSizeInput/types.d.ts +21 -0
  12. package/es/components/molecules/FontSizeInput/types.js +1 -0
  13. package/es/components/molecules/VirtualizedMenu/VirtualizedMenu.d.ts +1 -2
  14. package/es/components/molecules/VirtualizedMenu/__mocks__/index.js +2550 -938
  15. package/es/components/molecules/VirtualizedMenu/components/Item/Item.d.ts +4 -3
  16. package/es/components/molecules/VirtualizedMenu/components/Item/Item.js +24 -22
  17. package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.d.ts +1 -2
  18. package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.js +59 -31
  19. package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.optimized.d.ts +19 -0
  20. package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.optimized.js +233 -0
  21. package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.d.ts +1 -1
  22. package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.js +2 -1
  23. package/es/components/molecules/VirtualizedMenu/styled.d.ts +1 -1
  24. package/es/components/molecules/VirtualizedMenu/styled.js +11 -3
  25. package/es/components/molecules/VirtualizedMenu/types.d.ts +1 -8
  26. package/es/components/molecules/VirtualizedMenu/utils.d.ts +7 -5
  27. package/es/components/molecules/VirtualizedMenu/utils.js +12 -18
  28. package/es/components/molecules/index.d.ts +1 -0
  29. package/es/components/molecules/index.js +1 -0
  30. package/es/components/organism/ActivityTimeline/__mocks__/event_tracking.json +1290 -0
  31. package/es/components/organism/ActivityTimeline/__mocks__/timeline.json +3059 -0
  32. package/es/components/organism/TextEditor/TextEditor.d.ts +3 -0
  33. package/es/components/organism/TextEditor/TextEditor.js +239 -0
  34. package/es/components/organism/TextEditor/__mocks__/text-block.settings.json +320 -0
  35. package/es/components/organism/TextEditor/__mocks__/text-contennt.d.ts +1 -0
  36. package/es/components/organism/TextEditor/__mocks__/text-contennt.js +38 -0
  37. package/es/components/organism/TextEditor/constants.d.ts +135 -0
  38. package/es/components/organism/TextEditor/constants.js +280 -0
  39. package/es/components/organism/TextEditor/extensions/BackgroundColor.d.ts +25 -0
  40. package/es/components/organism/TextEditor/extensions/BackgroundColor.js +41 -0
  41. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.d.ts +130 -0
  42. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.js +247 -0
  43. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.d.ts +15 -0
  44. package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.js +31 -0
  45. package/es/components/organism/TextEditor/extensions/BubbleMenu/index.d.ts +2 -0
  46. package/es/components/organism/TextEditor/extensions/BubbleMenu/index.js +2 -0
  47. package/es/components/organism/TextEditor/extensions/Color.d.ts +6 -0
  48. package/es/components/organism/TextEditor/extensions/Color.js +19 -0
  49. package/es/components/organism/TextEditor/extensions/Emoji.d.ts +57 -0
  50. package/es/components/organism/TextEditor/extensions/Emoji.js +184 -0
  51. package/es/components/organism/TextEditor/extensions/FontFamily.d.ts +6 -0
  52. package/es/components/organism/TextEditor/extensions/FontFamily.js +43 -0
  53. package/es/components/organism/TextEditor/extensions/FontSize.d.ts +32 -0
  54. package/es/components/organism/TextEditor/extensions/FontSize.js +47 -0
  55. package/es/components/organism/TextEditor/extensions/FontWeight.d.ts +23 -0
  56. package/es/components/organism/TextEditor/extensions/FontWeight.js +41 -0
  57. package/es/components/organism/TextEditor/extensions/Highlight.d.ts +1 -0
  58. package/es/components/organism/TextEditor/extensions/Highlight.js +14 -0
  59. package/es/components/organism/TextEditor/extensions/Indent.d.ts +28 -0
  60. package/es/components/organism/TextEditor/extensions/Indent.js +66 -0
  61. package/es/components/organism/TextEditor/extensions/LineHeight.d.ts +20 -0
  62. package/es/components/organism/TextEditor/extensions/LineHeight.js +36 -0
  63. package/es/components/organism/TextEditor/extensions/Link.d.ts +3 -0
  64. package/es/components/organism/TextEditor/extensions/Link.js +47 -0
  65. package/es/components/organism/TextEditor/extensions/ListItemMarker.d.ts +13 -0
  66. package/es/components/organism/TextEditor/extensions/ListItemMarker.js +174 -0
  67. package/es/components/organism/TextEditor/extensions/Selection.d.ts +6 -0
  68. package/es/components/organism/TextEditor/extensions/Selection.js +40 -0
  69. package/es/components/organism/TextEditor/extensions/SmartTag.d.ts +33 -0
  70. package/es/components/organism/TextEditor/extensions/SmartTag.js +162 -0
  71. package/es/components/organism/TextEditor/extensions/StyleMemory.d.ts +36 -0
  72. package/es/components/organism/TextEditor/extensions/StyleMemory.js +163 -0
  73. package/es/components/organism/TextEditor/extensions/TextTransform.d.ts +31 -0
  74. package/es/components/organism/TextEditor/extensions/TextTransform.js +35 -0
  75. package/es/components/organism/TextEditor/hooks/index.d.ts +6 -0
  76. package/es/components/organism/TextEditor/hooks/index.js +6 -0
  77. package/es/components/organism/TextEditor/hooks/useDocumentState.d.ts +18 -0
  78. package/es/components/organism/TextEditor/hooks/useDocumentState.js +42 -0
  79. package/es/components/organism/TextEditor/hooks/useLinkHandler.d.ts +27 -0
  80. package/es/components/organism/TextEditor/hooks/useLinkHandler.js +279 -0
  81. package/es/components/organism/TextEditor/hooks/useMarkTracking.d.ts +26 -0
  82. package/es/components/organism/TextEditor/hooks/useMarkTracking.js +68 -0
  83. package/es/components/organism/TextEditor/hooks/usePersistence.d.ts +31 -0
  84. package/es/components/organism/TextEditor/hooks/usePersistence.js +169 -0
  85. package/es/components/organism/TextEditor/hooks/useStyleMemory.d.ts +6 -0
  86. package/es/components/organism/TextEditor/hooks/useStyleMemory.js +42 -0
  87. package/es/components/organism/TextEditor/hooks/useStylePresets.d.ts +34 -0
  88. package/es/components/organism/TextEditor/hooks/useStylePresets.js +83 -0
  89. package/es/components/organism/TextEditor/index.d.ts +5 -0
  90. package/es/components/organism/TextEditor/index.js +2 -0
  91. package/es/components/organism/TextEditor/index.scss +26 -0
  92. package/es/components/organism/TextEditor/provider.d.ts +10 -0
  93. package/es/components/organism/TextEditor/provider.js +20 -0
  94. package/es/components/organism/TextEditor/store.d.ts +11 -0
  95. package/es/components/organism/TextEditor/store.js +12 -0
  96. package/es/components/organism/TextEditor/styled.d.ts +5 -0
  97. package/es/components/organism/TextEditor/styled.js +69 -0
  98. package/es/components/organism/TextEditor/types.d.ts +95 -0
  99. package/es/components/organism/TextEditor/types.js +1 -0
  100. package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.d.ts +6 -0
  101. package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.js +78 -0
  102. package/es/components/organism/TextEditor/ui/BubbleMenu/index.d.ts +1 -0
  103. package/es/components/organism/TextEditor/ui/BubbleMenu/index.js +1 -0
  104. package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.d.ts +43 -0
  105. package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.js +120 -0
  106. package/es/components/organism/TextEditor/ui/ColorPicker/index.d.ts +1 -0
  107. package/es/components/organism/TextEditor/ui/ColorPicker/index.js +1 -0
  108. package/es/components/organism/TextEditor/ui/Emoji/EmojiList.d.ts +11 -0
  109. package/es/components/organism/TextEditor/ui/Emoji/EmojiList.js +66 -0
  110. package/es/components/organism/TextEditor/ui/Emoji/index.d.ts +2 -0
  111. package/es/components/organism/TextEditor/ui/Emoji/index.js +2 -0
  112. package/es/components/organism/TextEditor/ui/Emoji/suggestion.d.ts +4 -0
  113. package/es/components/organism/TextEditor/ui/Emoji/suggestion.js +71 -0
  114. package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.d.ts +11 -0
  115. package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.js +72 -0
  116. package/es/components/organism/TextEditor/ui/FontPopover/styled.d.ts +1 -0
  117. package/es/components/organism/TextEditor/ui/FontPopover/styled.js +51 -0
  118. package/es/components/organism/TextEditor/ui/Popover/Popover.d.ts +6 -0
  119. package/es/components/organism/TextEditor/ui/Popover/Popover.js +7 -0
  120. package/es/components/organism/TextEditor/ui/Popover/index.d.ts +1 -0
  121. package/es/components/organism/TextEditor/ui/Popover/index.js +1 -0
  122. package/es/components/organism/TextEditor/ui/Select/Select.d.ts +4 -0
  123. package/es/components/organism/TextEditor/ui/Select/Select.js +7 -0
  124. package/es/components/organism/TextEditor/ui/Select/index.d.ts +1 -0
  125. package/es/components/organism/TextEditor/ui/Select/index.js +1 -0
  126. package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.d.ts +30 -0
  127. package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.js +49 -0
  128. package/es/components/organism/TextEditor/ui/TextAlignSelect/index.d.ts +1 -0
  129. package/es/components/organism/TextEditor/ui/TextAlignSelect/index.js +1 -0
  130. package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.d.ts +14 -0
  131. package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.js +42 -0
  132. package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.d.ts +5 -0
  133. package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.js +7 -0
  134. package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.d.ts +5 -0
  135. package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.js +7 -0
  136. package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.d.ts +5 -0
  137. package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.js +18 -0
  138. package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.d.ts +4 -0
  139. package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.js +13 -0
  140. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.d.ts +7 -0
  141. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.js +18 -0
  142. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.d.ts +6 -0
  143. package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.js +42 -0
  144. package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.d.ts +5 -0
  145. package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.js +7 -0
  146. package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.d.ts +5 -0
  147. package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.js +7 -0
  148. package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.d.ts +5 -0
  149. package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.js +7 -0
  150. package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.d.ts +6 -0
  151. package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.js +4 -0
  152. package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.d.ts +5 -0
  153. package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.js +7 -0
  154. package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.d.ts +5 -0
  155. package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.js +7 -0
  156. package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.d.ts +7 -0
  157. package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.js +9 -0
  158. package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.d.ts +9 -0
  159. package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.js +22 -0
  160. package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.d.ts +5 -0
  161. package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.js +7 -0
  162. package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.d.ts +5 -0
  163. package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.js +13 -0
  164. package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.d.ts +5 -0
  165. package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.js +13 -0
  166. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.d.ts +5 -0
  167. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.js +3 -0
  168. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.d.ts +7 -0
  169. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.js +19 -0
  170. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.d.ts +15 -0
  171. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.js +14 -0
  172. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.d.ts +5 -0
  173. package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.js +28 -0
  174. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.d.ts +5 -0
  175. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.js +5 -0
  176. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.d.ts +6 -0
  177. package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.js +10 -0
  178. package/es/components/organism/TextEditor/ui/Toolbar/actions/index.d.ts +20 -0
  179. package/es/components/organism/TextEditor/ui/Toolbar/actions/index.js +20 -0
  180. package/es/components/organism/TextEditor/ui/Toolbar/index.d.ts +1 -0
  181. package/es/components/organism/TextEditor/ui/Toolbar/index.js +1 -0
  182. package/es/components/organism/TextEditor/utils/documentState.d.ts +57 -0
  183. package/es/components/organism/TextEditor/utils/documentState.js +100 -0
  184. package/es/components/organism/TextEditor/utils/font.d.ts +84 -0
  185. package/es/components/organism/TextEditor/utils/font.js +175 -0
  186. package/es/components/organism/TextEditor/utils/htmlProcessing.d.ts +62 -0
  187. package/es/components/organism/TextEditor/utils/htmlProcessing.js +304 -0
  188. package/es/components/organism/TextEditor/utils/index.d.ts +8 -0
  189. package/es/components/organism/TextEditor/utils/index.js +16 -0
  190. package/es/components/organism/TextEditor/utils/link.d.ts +100 -0
  191. package/es/components/organism/TextEditor/utils/link.js +149 -0
  192. package/es/components/organism/TextEditor/utils/menu.d.ts +134 -0
  193. package/es/components/organism/TextEditor/utils/menu.js +317 -0
  194. package/es/components/organism/TextEditor/utils/selection.d.ts +25 -0
  195. package/es/components/organism/TextEditor/utils/selection.js +57 -0
  196. package/es/components/organism/TextEditor/utils/smartTag.d.ts +49 -0
  197. package/es/components/organism/TextEditor/utils/smartTag.js +89 -0
  198. package/es/components/organism/TextEditor/utils/style.d.ts +78 -0
  199. package/es/components/organism/TextEditor/utils/style.js +193 -0
  200. package/es/components/organism/index.d.ts +1 -0
  201. package/es/components/organism/index.js +1 -0
  202. package/es/components/organism/index.scss +1 -0
  203. package/es/hooks/useBroadcastedLocalStorage.d.ts +5 -0
  204. package/es/hooks/useBroadcastedLocalStorage.js +71 -0
  205. package/es/utils/common.d.ts +6 -9
  206. package/es/utils/common.js +44 -23
  207. package/es/utils/index.d.ts +1 -0
  208. package/es/utils/index.js +1 -0
  209. package/es/utils/tree.d.ts +225 -0
  210. package/es/utils/tree.js +469 -0
  211. package/es/utils/web.d.ts +4 -0
  212. package/es/utils/web.js +25 -0
  213. package/package.json +29 -3
@@ -0,0 +1,42 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useTextEditorStore } from '../../../provider';
3
+ import { FontSizeInput, } from '@antscorp/antsomi-ui/es/components/molecules';
4
+ import styled from 'styled-components';
5
+ import { useCallback, useMemo, useRef, useState } from 'react';
6
+ import { useDebouncedCallback } from 'use-debounce';
7
+ import { DEFAULT_TEXT_STYLE } from '../../../constants';
8
+ const StyledFontSizeInput = styled(FontSizeInput) `
9
+ &.antsomi-input-number {
10
+ height: 22.5px;
11
+
12
+ input.antsomi-input-number-input {
13
+ font-size: 12px;
14
+ padding: 0 0 0 7px;
15
+ }
16
+ }
17
+ `;
18
+ export const FontSizeAction = ({ editor, debounceUpdateSize = 500 }) => {
19
+ const inputRef = useRef(null);
20
+ const bubbleMenuContainer = useTextEditorStore(state => state.bubbleMenuContainer);
21
+ const numberFontSize = (editor.getAttributes('textStyle').fontSize || DEFAULT_TEXT_STYLE.fontSize).replace('px', '');
22
+ const [currentFontSize, setCurrentFontSize] = useState(numberFontSize);
23
+ const updateEditorFontSize = useDebouncedCallback((v) => {
24
+ if (v === numberFontSize)
25
+ return;
26
+ editor.chain().focus().setFontSize(`${v}px`).run();
27
+ }, debounceUpdateSize);
28
+ const handleUpdateSize = useCallback((value) => {
29
+ setCurrentFontSize(+value);
30
+ updateEditorFontSize(+value);
31
+ }, [updateEditorFontSize]);
32
+ const handleFontSizeChange = useCallback((value, info) => {
33
+ if (info.type === 'dropdown') {
34
+ handleUpdateSize(value);
35
+ }
36
+ inputRef.current?.closeDropdown();
37
+ }, [handleUpdateSize]);
38
+ const dropdownProps = useMemo(() => ({
39
+ getPopupContainer: () => bubbleMenuContainer,
40
+ }), [bubbleMenuContainer]);
41
+ return (_jsx(StyledFontSizeInput, { ref: inputRef, placeholder: "Font Size", value: currentFontSize, onChange: handleFontSizeChange, dropdownProps: dropdownProps, onBlur: handleUpdateSize }));
42
+ };
@@ -0,0 +1,5 @@
1
+ import { Editor } from '@tiptap/core';
2
+ export interface HighlightActionProps {
3
+ editor: Editor;
4
+ }
5
+ export declare const HighlightAction: ({ editor }: HighlightActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button, Tooltip } from 'antd';
3
+ import { HighlighterIcon } from 'lucide-react';
4
+ import { ColorPicker } from '../../ColorPicker';
5
+ import { TEXT_EDITOR_CONSTANTS } from '../../../constants';
6
+ const { TOOLTIPS } = TEXT_EDITOR_CONSTANTS;
7
+ export const HighlightAction = ({ editor }) => (_jsx(ColorPicker, { value: editor.getAttributes('highlight').color, onChange: v => editor.chain().focus().setHighlight({ color: v }).run(), usedColorsStorageKey: "text-backgrounds", children: _jsx(Tooltip, { title: TOOLTIPS.HIGHLIGHT.TITLE, placement: "top", children: _jsx(Button, { size: "small", icon: _jsx(HighlighterIcon, { color: editor.getAttributes('highlight').color, size: 16 }) }) }) }));
@@ -0,0 +1,5 @@
1
+ import { Editor } from '@tiptap/core';
2
+ export interface IndentActionProps {
3
+ editor: Editor;
4
+ }
5
+ export declare const IndentAction: ({ editor }: IndentActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button, Tooltip } from 'antd';
3
+ import { IndentIcon } from 'lucide-react';
4
+ export const IndentAction = ({ editor }) => {
5
+ const disabled = !editor.can().chain().focus().indent().run();
6
+ return (_jsx(Tooltip, { open: disabled ? false : undefined, title: "Indent (Tab)", placement: "top", children: _jsx(Button, { size: "small", disabled: disabled, onClick: () => editor.chain().focus().indent().run(), icon: _jsx(IndentIcon, { size: 16 }) }) }));
7
+ };
@@ -0,0 +1,5 @@
1
+ import { Editor } from '@tiptap/core';
2
+ export interface ItalicActionProps {
3
+ editor: Editor;
4
+ }
5
+ export declare const ItalicAction: ({ editor }: ItalicActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button, Tooltip } from 'antd';
3
+ import { ItalicIcon } from 'lucide-react';
4
+ import { formatHotkey } from '../../../utils';
5
+ import { TEXT_EDITOR_CONSTANTS } from '../../../constants';
6
+ const { TOOLTIPS } = TEXT_EDITOR_CONSTANTS;
7
+ export const ItalicAction = ({ editor }) => (_jsx(Tooltip, { title: `${TOOLTIPS.ITALIC.TITLE} (${formatHotkey(TOOLTIPS.ITALIC.SHORTCUT)})`, placement: "top", children: _jsx(Button, { size: "small", onClick: () => editor.chain().focus().toggleItalic().run(), disabled: !editor.can().chain().focus().toggleItalic().run(), type: editor.isActive('italic') ? 'primary' : 'default', icon: _jsx(ItalicIcon, { size: 16 }) }) }));
@@ -0,0 +1,6 @@
1
+ import { Editor } from '@tiptap/core';
2
+ export interface LinkActionProps {
3
+ editor: Editor;
4
+ onClick?: () => void;
5
+ }
6
+ export declare const LinkAction: ({ editor, onClick }: LinkActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button, Tooltip } from 'antd';
3
+ import { Link2Icon } from 'lucide-react';
4
+ export const LinkAction = ({ editor, onClick }) => (_jsx(Tooltip, { title: "Link Tag", placement: "top", children: _jsx(Button, { size: "small", type: editor.isActive('link') ? 'primary' : 'default', icon: _jsx(Link2Icon, { size: 16 }), onClick: () => onClick?.() }) }));
@@ -0,0 +1,5 @@
1
+ import { Editor } from '@tiptap/core';
2
+ export interface OrderedListActionProps {
3
+ editor: Editor;
4
+ }
5
+ export declare const OrderedListAction: ({ editor }: OrderedListActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button, Tooltip } from 'antd';
3
+ import { ListOrderedIcon } from 'lucide-react';
4
+ import { formatHotkey } from '../../../utils';
5
+ import { TEXT_EDITOR_CONSTANTS } from '../../../constants';
6
+ const { TOOLTIPS } = TEXT_EDITOR_CONSTANTS;
7
+ export const OrderedListAction = ({ editor }) => (_jsx(Tooltip, { title: `${TOOLTIPS.ORDERED_LIST.TITLE} (${formatHotkey(TOOLTIPS.ORDERED_LIST.SHORTCUT)})`, placement: "top", children: _jsx(Button, { size: "small", onClick: () => editor.chain().focus().toggleOrderedList().run(), type: editor.isActive('orderedList') ? 'primary' : 'default', icon: _jsx(ListOrderedIcon, { size: 16 }) }) }));
@@ -0,0 +1,5 @@
1
+ import { Editor } from '@tiptap/core';
2
+ export interface OutdentActionProps {
3
+ editor: Editor;
4
+ }
5
+ export declare const OutdentAction: ({ editor }: OutdentActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button, Tooltip } from 'antd';
3
+ import { OutdentIcon } from 'lucide-react';
4
+ export const OutdentAction = ({ editor }) => {
5
+ const disabled = !editor.can().chain().focus().outdent().run();
6
+ return (_jsx(Tooltip, { open: disabled ? false : undefined, title: "Outdent (Shift + Tab)", placement: "top", children: _jsx(Button, { size: "small", disabled: disabled, onClick: () => editor.chain().focus().outdent().run(), icon: _jsx(OutdentIcon, { size: 16 }) }) }));
7
+ };
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { Editor } from '@tiptap/core';
3
+ export interface SmartTagActionProps {
4
+ editor: Editor;
5
+ onClick?: (event: React.MouseEvent) => void;
6
+ }
7
+ export declare const SmartTagAction: (props: SmartTagActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button, Tooltip } from 'antd';
3
+ import { BracesIcon } from 'lucide-react';
4
+ import { TEXT_EDITOR_CONSTANTS } from '../../../constants';
5
+ const { TOOLTIPS } = TEXT_EDITOR_CONSTANTS;
6
+ export const SmartTagAction = (props) => {
7
+ const { editor, onClick } = props;
8
+ return (_jsx(Tooltip, { title: TOOLTIPS.SMART_TAG.TITLE, placement: "top", children: _jsx(Button, { size: "small", onClick: onClick, type: editor.isActive('smartTag') ? 'primary' : 'default', icon: _jsx(BracesIcon, { size: 16 }) }) }));
9
+ };
@@ -0,0 +1,9 @@
1
+ import { Editor } from '@tiptap/core';
2
+ interface SpacingActionProps {
3
+ editor: Editor;
4
+ }
5
+ export declare const SpacingIcon: (props: React.SVGProps<SVGSVGElement> & {
6
+ size?: number;
7
+ }) => import("react/jsx-runtime").JSX.Element;
8
+ export declare const SpacingAction: (props: SpacingActionProps) => import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button, Menu, Tooltip } from 'antd';
3
+ import { useState } from 'react';
4
+ import { TextEditorPopover } from '../../Popover';
5
+ export const SpacingIcon = (props) => {
6
+ const { size = 24, ...restProps } = props;
7
+ return (_jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...restProps, children: _jsx("path", { d: "M21 10H13M21 6H13M21 14H13M21 18H13M6 20L6 4M6 20L3 17M6 20L9 17M6 4L3 7M6 4L9 7", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }));
8
+ };
9
+ export const SpacingAction = (props) => {
10
+ const { editor } = props;
11
+ const [isOpen, setIsOpen] = useState(false);
12
+ return (_jsx(TextEditorPopover, { open: isOpen, onOpenChange: setIsOpen, trigger: ['click'], arrow: false, overlayInnerStyle: {
13
+ padding: 0,
14
+ }, content: _jsx(Menu, { items: [
15
+ { key: '1', label: 'Single' },
16
+ { key: '1.15', label: '1.15' },
17
+ { key: '1.5', label: '1.5' },
18
+ { key: '2', label: 'Double' },
19
+ ], onClick: ({ key }) => {
20
+ editor.chain().focus().setLineHeight(key).run();
21
+ } }), children: _jsx(Tooltip, { open: isOpen ? false : undefined, title: "Line Spacing", placement: "top", destroyTooltipOnHide: true, children: _jsx(Button, { size: "small", icon: _jsx(SpacingIcon, { size: 16 }) }) }) }));
22
+ };
@@ -0,0 +1,5 @@
1
+ import { Editor } from '@tiptap/core';
2
+ export interface StrikeActionProps {
3
+ editor: Editor;
4
+ }
5
+ export declare const StrikeAction: ({ editor }: StrikeActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button, Tooltip } from 'antd';
3
+ import { StrikethroughIcon } from 'lucide-react';
4
+ import { formatHotkey } from '../../../utils';
5
+ import { TEXT_EDITOR_CONSTANTS } from '../../../constants';
6
+ const { TOOLTIPS } = TEXT_EDITOR_CONSTANTS;
7
+ export const StrikeAction = ({ editor }) => (_jsx(Tooltip, { title: `${TOOLTIPS.STRIKE.TITLE} (${formatHotkey(TOOLTIPS.STRIKE.SHORTCUT)})`, placement: "top", children: _jsx(Button, { size: "small", onClick: () => editor.chain().focus().toggleStrike().run(), disabled: !editor.can().chain().focus().toggleStrike().run(), type: editor.isActive('strike') ? 'primary' : 'default', children: _jsx(StrikethroughIcon, { size: 16 }) }) }));
@@ -0,0 +1,5 @@
1
+ import { Editor } from '@tiptap/core';
2
+ export interface SubscriptActionProps {
3
+ editor: Editor;
4
+ }
5
+ export declare const SubscriptAction: ({ editor }: SubscriptActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button, Tooltip } from 'antd';
3
+ import { SubscriptIcon } from 'lucide-react';
4
+ import { TEXT_EDITOR_CONSTANTS } from '../../../constants';
5
+ const { TOOLTIPS } = TEXT_EDITOR_CONSTANTS;
6
+ export const SubscriptAction = ({ editor }) => (_jsx(Tooltip, { title: TOOLTIPS.SUBSCRIPT.TITLE, placement: "top", children: _jsx(Button, { size: "small", onClick: () => {
7
+ if (editor.isActive('superscript')) {
8
+ editor.chain().focus().toggleSuperscript().toggleSubscript().run();
9
+ }
10
+ else {
11
+ editor.chain().focus().toggleSubscript().run();
12
+ }
13
+ }, disabled: !editor.can().chain().focus().toggleSubscript().run(), type: editor.isActive('subscript') ? 'primary' : 'default', children: _jsx(SubscriptIcon, { size: 16 }) }) }));
@@ -0,0 +1,5 @@
1
+ import { Editor } from '@tiptap/core';
2
+ export interface SuperscriptActionProps {
3
+ editor: Editor;
4
+ }
5
+ export declare const SuperscriptAction: ({ editor }: SuperscriptActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button, Tooltip } from 'antd';
3
+ import { SuperscriptIcon } from 'lucide-react';
4
+ import { TEXT_EDITOR_CONSTANTS } from '../../../constants';
5
+ const { TOOLTIPS } = TEXT_EDITOR_CONSTANTS;
6
+ export const SuperscriptAction = ({ editor }) => (_jsx(Tooltip, { title: TOOLTIPS.SUPERSCRIPT.TITLE, placement: "top", children: _jsx(Button, { size: "small", onClick: () => {
7
+ if (editor.isActive('subscript')) {
8
+ editor.chain().focus().toggleSubscript().toggleSuperscript().run();
9
+ }
10
+ else {
11
+ editor.chain().focus().toggleSuperscript().run();
12
+ }
13
+ }, disabled: !editor.can().chain().focus().toggleSuperscript().run(), type: editor.isActive('superscript') ? 'primary' : 'default', children: _jsx(SuperscriptIcon, { size: 16 }) }) }));
@@ -0,0 +1,5 @@
1
+ import { Editor } from '@tiptap/core';
2
+ export interface TextAlignActionProps {
3
+ editor: Editor;
4
+ }
5
+ export declare const TextAlignAction: ({ editor }: TextAlignActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,3 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { TextAlignSelect } from '../../TextAlignSelect';
3
+ export const TextAlignAction = ({ editor }) => (_jsx(TextAlignSelect, { editor: editor, onChange: v => editor.chain().focus().setTextAlign(v).run() }));
@@ -0,0 +1,7 @@
1
+ import { Editor } from '@tiptap/core';
2
+ import { ColorPickerProps } from '../../ColorPicker/ColorPicker';
3
+ export interface HighlightActionProps {
4
+ editor: Editor;
5
+ colorPickerProps?: ColorPickerProps;
6
+ }
7
+ export declare const TextBackColorAction: ({ editor, colorPickerProps }: HighlightActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button, Flex, Tooltip } from 'antd';
3
+ import { HighlighterIcon, BrushCleaningIcon } from 'lucide-react';
4
+ import { ColorPicker } from '../../ColorPicker';
5
+ import { TEXT_EDITOR_CONSTANTS } from '../../../constants';
6
+ import { useRef } from 'react';
7
+ import tinycolor from 'tinycolor2';
8
+ const { TOOLTIPS } = TEXT_EDITOR_CONSTANTS;
9
+ export const TextBackColorAction = ({ editor, colorPickerProps }) => {
10
+ const ref = useRef(null);
11
+ const handleClearBackgroundColor = () => {
12
+ editor.chain().focus().unsetBackgroundColor().run();
13
+ ref.current?.setOpen(false);
14
+ };
15
+ const activeColor = editor.getAttributes('textStyle').backgroundColor;
16
+ return (_jsx(ColorPicker, { ...colorPickerProps, ref: ref, value: editor.getAttributes('textStyle').backgroundColor, onChange: v => editor.chain().focus().setBackgroundColor(v).run(), usedColorsStorageKey: "text-backgrounds", popoverProps: {
17
+ content: ({ colorGrid, usedColors, customColorPicker }) => (_jsxs(Flex, { vertical: true, gap: 8, children: [colorGrid, usedColors, customColorPicker, _jsx(Button, { icon: _jsx(BrushCleaningIcon, { size: 16 }), onClick: handleClearBackgroundColor, type: "text", children: "Clear" })] })),
18
+ }, children: _jsx(Tooltip, { title: TOOLTIPS.HIGHLIGHT.TITLE, placement: "top", children: _jsx(Button, { size: "small", icon: _jsx(HighlighterIcon, { color: tinycolor(activeColor).isValid() ? activeColor : undefined, size: 16 }) }) }) }));
19
+ };
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ import { Editor } from '@tiptap/core';
3
+ import { ColorPickerProps } from '../../ColorPicker/ColorPicker';
4
+ interface IconProps extends React.SVGProps<SVGSVGElement> {
5
+ color?: string;
6
+ textColor?: string;
7
+ size?: number;
8
+ }
9
+ export declare const TextColorIcon: (props: IconProps) => import("react/jsx-runtime").JSX.Element;
10
+ export interface TextColorActionProps {
11
+ editor: Editor;
12
+ colorPickerProps?: ColorPickerProps;
13
+ }
14
+ export declare const TextColorAction: ({ editor, colorPickerProps }: TextColorActionProps) => import("react/jsx-runtime").JSX.Element;
15
+ export {};
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button, Tooltip } from 'antd';
3
+ import { ColorPicker } from '../../ColorPicker';
4
+ import { TEXT_EDITOR_CONSTANTS } from '../../../constants';
5
+ import tinycolor from 'tinycolor2';
6
+ const { TOOLTIPS } = TEXT_EDITOR_CONSTANTS;
7
+ export const TextColorIcon = (props) => {
8
+ const { color, textColor, size, ...rest } = props;
9
+ return (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", width: size || 24, height: size || 24, viewBox: "0 0 24 24", fill: "none", stroke: color || 'currentColor', strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", ...rest, children: [_jsx("path", { stroke: textColor, d: "M4 20h16" }), _jsx("path", { d: "m6 16 6-12 6 12" }), _jsx("path", { d: "M8 12h8" })] }));
10
+ };
11
+ export const TextColorAction = ({ editor, colorPickerProps }) => {
12
+ const activeColor = editor.getAttributes('textStyle').color;
13
+ return (_jsx(ColorPicker, { ...colorPickerProps, value: editor.getAttributes('textStyle').color, onChange: v => editor.chain().focus().setColor(v).run(), usedColorsStorageKey: "text-colors", children: _jsx(Tooltip, { title: TOOLTIPS.TEXT_COLOR.TITLE, placement: "top", children: _jsx(Button, { size: "small", icon: _jsx(TextColorIcon, { size: 16, textColor: tinycolor(activeColor) ? activeColor : undefined }) }) }) }));
14
+ };
@@ -0,0 +1,5 @@
1
+ import { Editor } from '@tiptap/core';
2
+ export interface TextTransformActionProps {
3
+ editor: Editor;
4
+ }
5
+ export declare const TextTransformAction: ({ editor }: TextTransformActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { TEXT_EDITOR_CONSTANTS } from '../../../constants';
3
+ import { TextEditorSelect } from '../../Select';
4
+ const { TEXT_TRANSFORM } = TEXT_EDITOR_CONSTANTS;
5
+ export const TextTransformAction = ({ editor }) => (_jsx(TextEditorSelect, { value: editor.getAttributes('textStyle').textTransform, style: { width: 120 }, size: "small", options: [
6
+ {
7
+ label: TEXT_TRANSFORM.OPTIONS.UPPERCASE.LABEL,
8
+ value: TEXT_TRANSFORM.OPTIONS.UPPERCASE.VALUE,
9
+ disabled: editor.getAttributes('textTransform').textTransform ===
10
+ TEXT_TRANSFORM.OPTIONS.UPPERCASE.VALUE,
11
+ },
12
+ {
13
+ label: TEXT_TRANSFORM.OPTIONS.LOWERCASE.LABEL,
14
+ value: TEXT_TRANSFORM.OPTIONS.LOWERCASE.VALUE,
15
+ disabled: editor.getAttributes('textTransform').textTransform ===
16
+ TEXT_TRANSFORM.OPTIONS.LOWERCASE.VALUE,
17
+ },
18
+ {
19
+ label: TEXT_TRANSFORM.OPTIONS.CAPITALIZE.LABEL,
20
+ value: TEXT_TRANSFORM.OPTIONS.CAPITALIZE.VALUE,
21
+ disabled: editor.getAttributes('textTransform').textTransform ===
22
+ TEXT_TRANSFORM.OPTIONS.CAPITALIZE.VALUE,
23
+ },
24
+ {
25
+ label: TEXT_TRANSFORM.OPTIONS.NONE.LABEL,
26
+ value: TEXT_TRANSFORM.OPTIONS.NONE.VALUE,
27
+ },
28
+ ], onChange: v => editor.chain().focus().setTextTransform(v).run(), placeholder: TEXT_TRANSFORM.PLACEHOLDER }));
@@ -0,0 +1,5 @@
1
+ import { Editor } from '@tiptap/core';
2
+ export interface UnderlineActionProps {
3
+ editor: Editor;
4
+ }
5
+ export declare const UnderlineAction: ({ editor }: UnderlineActionProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button, Tooltip } from 'antd';
3
+ import { UnderlineIcon } from 'lucide-react';
4
+ import { formatHotkey } from '../../../utils';
5
+ export const UnderlineAction = ({ editor }) => (_jsx(Tooltip, { title: `Underline (${formatHotkey('U')})`, placement: "top", children: _jsx(Button, { size: "small", onClick: () => editor.chain().focus().toggleUnderline().run(), disabled: !editor.can().chain().focus().toggleUnderline().run(), type: editor.isActive('underline') ? 'primary' : 'default', icon: _jsx(UnderlineIcon, { size: 16 }) }) }));
@@ -0,0 +1,6 @@
1
+ import { Editor } from '@tiptap/core';
2
+ interface UnsetLinkActionProps {
3
+ editor: Editor;
4
+ }
5
+ export declare const UnsetLinkAction: (props: UnsetLinkActionProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button, Tooltip } from 'antd';
3
+ import { Link2OffIcon } from 'lucide-react';
4
+ // Hooks
5
+ import { useLinkHandler } from '../../../hooks/useLinkHandler';
6
+ export const UnsetLinkAction = (props) => {
7
+ const { editor } = props;
8
+ const { unsetLink } = useLinkHandler({ editor });
9
+ return (_jsx(Tooltip, { title: "Remove link", children: _jsx(Button, { size: "small", icon: _jsx(Link2OffIcon, { size: 16 }), onClick: () => unsetLink() }) }));
10
+ };
@@ -0,0 +1,20 @@
1
+ export * from './BoldAction';
2
+ export * from './BulletListAction';
3
+ export * from './ClearFormattingAction';
4
+ export * from './FontFamilyAction';
5
+ export * from './FontSizeAction';
6
+ export * from './ItalicAction';
7
+ export * from './StrikeAction';
8
+ export * from './SuperscriptAction';
9
+ export * from './SubscriptAction';
10
+ export * from './TextTransformAction';
11
+ export * from './LinkAction';
12
+ export * from './SmartTagAction';
13
+ export * from './TextColorAction';
14
+ export * from './HighlightAction';
15
+ export * from './OrderedListAction';
16
+ export * from './TextAlignAction';
17
+ export * from './IndentAction';
18
+ export * from './OutdentAction';
19
+ export * from './UnderlineAction';
20
+ export * from './EmojiAction';
@@ -0,0 +1,20 @@
1
+ export * from './BoldAction';
2
+ export * from './BulletListAction';
3
+ export * from './ClearFormattingAction';
4
+ export * from './FontFamilyAction';
5
+ export * from './FontSizeAction';
6
+ export * from './ItalicAction';
7
+ export * from './StrikeAction';
8
+ export * from './SuperscriptAction';
9
+ export * from './SubscriptAction';
10
+ export * from './TextTransformAction';
11
+ export * from './LinkAction';
12
+ export * from './SmartTagAction';
13
+ export * from './TextColorAction';
14
+ export * from './HighlightAction';
15
+ export * from './OrderedListAction';
16
+ export * from './TextAlignAction';
17
+ export * from './IndentAction';
18
+ export * from './OutdentAction';
19
+ export * from './UnderlineAction';
20
+ export * from './EmojiAction';
@@ -0,0 +1 @@
1
+ export { Toolbar, type ToolbarProps } from './Toolbar';
@@ -0,0 +1 @@
1
+ export { Toolbar } from './Toolbar';
@@ -0,0 +1,57 @@
1
+ import { EditorState } from '@tiptap/pm/state';
2
+ import { Node as ProseMirrorNode } from '@tiptap/pm/model';
3
+ /**
4
+ * Configuration for document emptiness detection
5
+ */
6
+ export interface DocumentStateConfig {
7
+ /** Minimum size to consider document as having content */
8
+ minContentSize?: number;
9
+ /** Whether to consider whitespace-only content as empty */
10
+ ignoreWhitespace?: boolean;
11
+ /** Custom validation function */
12
+ customValidator?: (doc: ProseMirrorNode) => boolean;
13
+ }
14
+ /**
15
+ * Calculates the minimum size of an empty document based on schema
16
+ */
17
+ export declare function calculateEmptyDocumentSize(state: EditorState): number;
18
+ /**
19
+ * Checks if document is effectively empty
20
+ */
21
+ export declare function isDocumentEmpty(state: EditorState, config?: DocumentStateConfig): boolean;
22
+ /**
23
+ * Checks if document has meaningful content
24
+ */
25
+ export declare function hasDocumentContent(state: EditorState, config?: DocumentStateConfig): boolean;
26
+ /**
27
+ * Gets document content statistics
28
+ */
29
+ export declare function getDocumentStats(state: EditorState): {
30
+ nodeSize: number;
31
+ textLength: number;
32
+ trimmedTextLength: number;
33
+ nodeCount: void;
34
+ isEmpty: boolean;
35
+ emptyDocumentSize: number;
36
+ };
37
+ /**
38
+ * Document state change detector
39
+ */
40
+ export declare class DocumentStateTracker {
41
+ private previousState;
42
+ /**
43
+ * Updates tracker with new state and returns changes
44
+ */
45
+ update(state: EditorState): {
46
+ isEmpty: boolean;
47
+ wasEmpty: boolean;
48
+ becameEmpty: boolean;
49
+ becameNonEmpty: boolean;
50
+ sizeChanged: boolean;
51
+ textLengthChanged: boolean;
52
+ };
53
+ /**
54
+ * Resets the tracker
55
+ */
56
+ reset(): void;
57
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Default configuration for document state detection
3
+ */
4
+ const DEFAULT_CONFIG = {
5
+ minContentSize: 4, // Standard ProseMirror empty doc size
6
+ ignoreWhitespace: true,
7
+ customValidator: () => false,
8
+ };
9
+ /**
10
+ * Calculates the minimum size of an empty document based on schema
11
+ */
12
+ export function calculateEmptyDocumentSize(state) {
13
+ // Create a minimal document with the same schema
14
+ const emptyDoc = state.schema.topNodeType.createAndFill();
15
+ return emptyDoc?.nodeSize ?? 4;
16
+ }
17
+ /**
18
+ * Checks if document is effectively empty
19
+ */
20
+ export function isDocumentEmpty(state, config = {}) {
21
+ const { minContentSize, ignoreWhitespace, customValidator } = {
22
+ ...DEFAULT_CONFIG,
23
+ ...config,
24
+ };
25
+ const { doc } = state;
26
+ // Use custom validator if provided
27
+ if (customValidator(doc)) {
28
+ return true;
29
+ }
30
+ // Check document size
31
+ const calculatedMinSize = calculateEmptyDocumentSize(state);
32
+ const effectiveMinSize = minContentSize === 4 ? calculatedMinSize : minContentSize;
33
+ if (doc.nodeSize <= effectiveMinSize) {
34
+ return true;
35
+ }
36
+ // Check if content is only whitespace
37
+ if (ignoreWhitespace) {
38
+ const textContent = doc.textContent.trim();
39
+ return textContent.length === 0;
40
+ }
41
+ return false;
42
+ }
43
+ /**
44
+ * Checks if document has meaningful content
45
+ */
46
+ export function hasDocumentContent(state, config = {}) {
47
+ return !isDocumentEmpty(state, config);
48
+ }
49
+ /**
50
+ * Gets document content statistics
51
+ */
52
+ export function getDocumentStats(state) {
53
+ const { doc } = state;
54
+ return {
55
+ nodeSize: doc.nodeSize,
56
+ textLength: doc.textContent.length,
57
+ trimmedTextLength: doc.textContent.trim().length,
58
+ nodeCount: doc.nodesBetween(0, doc.nodeSize, () => true),
59
+ isEmpty: isDocumentEmpty(state),
60
+ emptyDocumentSize: calculateEmptyDocumentSize(state),
61
+ };
62
+ }
63
+ /**
64
+ * Document state change detector
65
+ */
66
+ export class DocumentStateTracker {
67
+ constructor() {
68
+ this.previousState = null;
69
+ }
70
+ /**
71
+ * Updates tracker with new state and returns changes
72
+ */
73
+ update(state) {
74
+ const isEmpty = isDocumentEmpty(state);
75
+ const { nodeSize } = state.doc;
76
+ const textLength = state.doc.textContent.length;
77
+ const result = {
78
+ isEmpty,
79
+ wasEmpty: this.previousState?.isEmpty ?? true,
80
+ becameEmpty: false,
81
+ becameNonEmpty: false,
82
+ sizeChanged: false,
83
+ textLengthChanged: false,
84
+ };
85
+ if (this.previousState) {
86
+ result.becameEmpty = !this.previousState.isEmpty && isEmpty;
87
+ result.becameNonEmpty = this.previousState.isEmpty && !isEmpty;
88
+ result.sizeChanged = this.previousState.nodeSize !== nodeSize;
89
+ result.textLengthChanged = this.previousState.textLength !== textLength;
90
+ }
91
+ this.previousState = { isEmpty, nodeSize, textLength };
92
+ return result;
93
+ }
94
+ /**
95
+ * Resets the tracker
96
+ */
97
+ reset() {
98
+ this.previousState = null;
99
+ }
100
+ }