@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.
- package/es/assets/css/main.scss +4 -2
- package/es/components/index.scss +1 -0
- package/es/components/molecules/AccountSelection/AccountListing.js +14 -3
- package/es/components/molecules/EmojiPopover/EmojiPopover.js +5 -1
- package/es/components/molecules/FontSizeInput/FontSizeInput.d.ts +3 -0
- package/es/components/molecules/FontSizeInput/FontSizeInput.js +77 -0
- package/es/components/molecules/FontSizeInput/constants.d.ts +2 -0
- package/es/components/molecules/FontSizeInput/constants.js +5 -0
- package/es/components/molecules/FontSizeInput/index.d.ts +2 -0
- package/es/components/molecules/FontSizeInput/index.js +1 -0
- package/es/components/molecules/FontSizeInput/types.d.ts +21 -0
- package/es/components/molecules/FontSizeInput/types.js +1 -0
- package/es/components/molecules/VirtualizedMenu/VirtualizedMenu.d.ts +1 -2
- package/es/components/molecules/VirtualizedMenu/__mocks__/index.js +2550 -938
- package/es/components/molecules/VirtualizedMenu/components/Item/Item.d.ts +4 -3
- package/es/components/molecules/VirtualizedMenu/components/Item/Item.js +24 -22
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.d.ts +1 -2
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.js +59 -31
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.optimized.d.ts +19 -0
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.optimized.js +233 -0
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.d.ts +1 -1
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.js +2 -1
- package/es/components/molecules/VirtualizedMenu/styled.d.ts +1 -1
- package/es/components/molecules/VirtualizedMenu/styled.js +11 -3
- package/es/components/molecules/VirtualizedMenu/types.d.ts +1 -8
- package/es/components/molecules/VirtualizedMenu/utils.d.ts +7 -5
- package/es/components/molecules/VirtualizedMenu/utils.js +12 -18
- package/es/components/molecules/index.d.ts +1 -0
- package/es/components/molecules/index.js +1 -0
- package/es/components/organism/ActivityTimeline/__mocks__/event_tracking.json +1290 -0
- package/es/components/organism/ActivityTimeline/__mocks__/timeline.json +3059 -0
- package/es/components/organism/TextEditor/TextEditor.d.ts +3 -0
- package/es/components/organism/TextEditor/TextEditor.js +239 -0
- package/es/components/organism/TextEditor/__mocks__/text-block.settings.json +320 -0
- package/es/components/organism/TextEditor/__mocks__/text-contennt.d.ts +1 -0
- package/es/components/organism/TextEditor/__mocks__/text-contennt.js +38 -0
- package/es/components/organism/TextEditor/constants.d.ts +135 -0
- package/es/components/organism/TextEditor/constants.js +280 -0
- package/es/components/organism/TextEditor/extensions/BackgroundColor.d.ts +25 -0
- package/es/components/organism/TextEditor/extensions/BackgroundColor.js +41 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.d.ts +130 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.js +247 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.d.ts +15 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.js +31 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/index.d.ts +2 -0
- package/es/components/organism/TextEditor/extensions/BubbleMenu/index.js +2 -0
- package/es/components/organism/TextEditor/extensions/Color.d.ts +6 -0
- package/es/components/organism/TextEditor/extensions/Color.js +19 -0
- package/es/components/organism/TextEditor/extensions/Emoji.d.ts +57 -0
- package/es/components/organism/TextEditor/extensions/Emoji.js +184 -0
- package/es/components/organism/TextEditor/extensions/FontFamily.d.ts +6 -0
- package/es/components/organism/TextEditor/extensions/FontFamily.js +43 -0
- package/es/components/organism/TextEditor/extensions/FontSize.d.ts +32 -0
- package/es/components/organism/TextEditor/extensions/FontSize.js +47 -0
- package/es/components/organism/TextEditor/extensions/FontWeight.d.ts +23 -0
- package/es/components/organism/TextEditor/extensions/FontWeight.js +41 -0
- package/es/components/organism/TextEditor/extensions/Highlight.d.ts +1 -0
- package/es/components/organism/TextEditor/extensions/Highlight.js +14 -0
- package/es/components/organism/TextEditor/extensions/Indent.d.ts +28 -0
- package/es/components/organism/TextEditor/extensions/Indent.js +66 -0
- package/es/components/organism/TextEditor/extensions/LineHeight.d.ts +20 -0
- package/es/components/organism/TextEditor/extensions/LineHeight.js +36 -0
- package/es/components/organism/TextEditor/extensions/Link.d.ts +3 -0
- package/es/components/organism/TextEditor/extensions/Link.js +47 -0
- package/es/components/organism/TextEditor/extensions/ListItemMarker.d.ts +13 -0
- package/es/components/organism/TextEditor/extensions/ListItemMarker.js +174 -0
- package/es/components/organism/TextEditor/extensions/Selection.d.ts +6 -0
- package/es/components/organism/TextEditor/extensions/Selection.js +40 -0
- package/es/components/organism/TextEditor/extensions/SmartTag.d.ts +33 -0
- package/es/components/organism/TextEditor/extensions/SmartTag.js +162 -0
- package/es/components/organism/TextEditor/extensions/StyleMemory.d.ts +36 -0
- package/es/components/organism/TextEditor/extensions/StyleMemory.js +163 -0
- package/es/components/organism/TextEditor/extensions/TextTransform.d.ts +31 -0
- package/es/components/organism/TextEditor/extensions/TextTransform.js +35 -0
- package/es/components/organism/TextEditor/hooks/index.d.ts +6 -0
- package/es/components/organism/TextEditor/hooks/index.js +6 -0
- package/es/components/organism/TextEditor/hooks/useDocumentState.d.ts +18 -0
- package/es/components/organism/TextEditor/hooks/useDocumentState.js +42 -0
- package/es/components/organism/TextEditor/hooks/useLinkHandler.d.ts +27 -0
- package/es/components/organism/TextEditor/hooks/useLinkHandler.js +279 -0
- package/es/components/organism/TextEditor/hooks/useMarkTracking.d.ts +26 -0
- package/es/components/organism/TextEditor/hooks/useMarkTracking.js +68 -0
- package/es/components/organism/TextEditor/hooks/usePersistence.d.ts +31 -0
- package/es/components/organism/TextEditor/hooks/usePersistence.js +169 -0
- package/es/components/organism/TextEditor/hooks/useStyleMemory.d.ts +6 -0
- package/es/components/organism/TextEditor/hooks/useStyleMemory.js +42 -0
- package/es/components/organism/TextEditor/hooks/useStylePresets.d.ts +34 -0
- package/es/components/organism/TextEditor/hooks/useStylePresets.js +83 -0
- package/es/components/organism/TextEditor/index.d.ts +5 -0
- package/es/components/organism/TextEditor/index.js +2 -0
- package/es/components/organism/TextEditor/index.scss +26 -0
- package/es/components/organism/TextEditor/provider.d.ts +10 -0
- package/es/components/organism/TextEditor/provider.js +20 -0
- package/es/components/organism/TextEditor/store.d.ts +11 -0
- package/es/components/organism/TextEditor/store.js +12 -0
- package/es/components/organism/TextEditor/styled.d.ts +5 -0
- package/es/components/organism/TextEditor/styled.js +69 -0
- package/es/components/organism/TextEditor/types.d.ts +95 -0
- package/es/components/organism/TextEditor/types.js +1 -0
- package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.d.ts +6 -0
- package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.js +78 -0
- package/es/components/organism/TextEditor/ui/BubbleMenu/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/BubbleMenu/index.js +1 -0
- package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.d.ts +43 -0
- package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.js +120 -0
- package/es/components/organism/TextEditor/ui/ColorPicker/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/ColorPicker/index.js +1 -0
- package/es/components/organism/TextEditor/ui/Emoji/EmojiList.d.ts +11 -0
- package/es/components/organism/TextEditor/ui/Emoji/EmojiList.js +66 -0
- package/es/components/organism/TextEditor/ui/Emoji/index.d.ts +2 -0
- package/es/components/organism/TextEditor/ui/Emoji/index.js +2 -0
- package/es/components/organism/TextEditor/ui/Emoji/suggestion.d.ts +4 -0
- package/es/components/organism/TextEditor/ui/Emoji/suggestion.js +71 -0
- package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.d.ts +11 -0
- package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.js +72 -0
- package/es/components/organism/TextEditor/ui/FontPopover/styled.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/FontPopover/styled.js +51 -0
- package/es/components/organism/TextEditor/ui/Popover/Popover.d.ts +6 -0
- package/es/components/organism/TextEditor/ui/Popover/Popover.js +7 -0
- package/es/components/organism/TextEditor/ui/Popover/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/Popover/index.js +1 -0
- package/es/components/organism/TextEditor/ui/Select/Select.d.ts +4 -0
- package/es/components/organism/TextEditor/ui/Select/Select.js +7 -0
- package/es/components/organism/TextEditor/ui/Select/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/Select/index.js +1 -0
- package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.d.ts +30 -0
- package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.js +49 -0
- package/es/components/organism/TextEditor/ui/TextAlignSelect/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/TextAlignSelect/index.js +1 -0
- package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.d.ts +14 -0
- package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.js +42 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.js +18 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.d.ts +4 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.js +13 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.d.ts +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.js +18 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.d.ts +6 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.js +42 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.d.ts +6 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.js +4 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.d.ts +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.js +9 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.d.ts +9 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.js +22 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.js +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.js +13 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.js +13 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.js +3 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.d.ts +7 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.js +19 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.d.ts +15 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.js +14 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.js +28 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.d.ts +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.js +5 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.d.ts +6 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.js +10 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/index.d.ts +20 -0
- package/es/components/organism/TextEditor/ui/Toolbar/actions/index.js +20 -0
- package/es/components/organism/TextEditor/ui/Toolbar/index.d.ts +1 -0
- package/es/components/organism/TextEditor/ui/Toolbar/index.js +1 -0
- package/es/components/organism/TextEditor/utils/documentState.d.ts +57 -0
- package/es/components/organism/TextEditor/utils/documentState.js +100 -0
- package/es/components/organism/TextEditor/utils/font.d.ts +84 -0
- package/es/components/organism/TextEditor/utils/font.js +175 -0
- package/es/components/organism/TextEditor/utils/htmlProcessing.d.ts +62 -0
- package/es/components/organism/TextEditor/utils/htmlProcessing.js +304 -0
- package/es/components/organism/TextEditor/utils/index.d.ts +8 -0
- package/es/components/organism/TextEditor/utils/index.js +16 -0
- package/es/components/organism/TextEditor/utils/link.d.ts +100 -0
- package/es/components/organism/TextEditor/utils/link.js +149 -0
- package/es/components/organism/TextEditor/utils/menu.d.ts +134 -0
- package/es/components/organism/TextEditor/utils/menu.js +317 -0
- package/es/components/organism/TextEditor/utils/selection.d.ts +25 -0
- package/es/components/organism/TextEditor/utils/selection.js +57 -0
- package/es/components/organism/TextEditor/utils/smartTag.d.ts +49 -0
- package/es/components/organism/TextEditor/utils/smartTag.js +89 -0
- package/es/components/organism/TextEditor/utils/style.d.ts +78 -0
- package/es/components/organism/TextEditor/utils/style.js +193 -0
- package/es/components/organism/index.d.ts +1 -0
- package/es/components/organism/index.js +1 -0
- package/es/components/organism/index.scss +1 -0
- package/es/hooks/useBroadcastedLocalStorage.d.ts +5 -0
- package/es/hooks/useBroadcastedLocalStorage.js +71 -0
- package/es/utils/common.d.ts +6 -9
- package/es/utils/common.js +44 -23
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +1 -0
- package/es/utils/tree.d.ts +225 -0
- package/es/utils/tree.js +469 -0
- package/es/utils/web.d.ts +4 -0
- package/es/utils/web.js +25 -0
- package/package.json +29 -3
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Use case**: Template systems, corporate branding, user productivity
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { useBroadcastedLocalStorage } from '@antscorp/antsomi-ui/es/hooks/useBroadcastedLocalStorage';
|
|
4
|
+
export function useStylePresets(editor, options = {}) {
|
|
5
|
+
const { storageKey = 'text-editor-style-presets', maxPresets = 20, defaultPresets = [], } = options;
|
|
6
|
+
const { value: presets, setValue: setPresets } = useBroadcastedLocalStorage(storageKey, defaultPresets.map((preset, index) => ({
|
|
7
|
+
...preset,
|
|
8
|
+
id: `default-${index}`,
|
|
9
|
+
createdAt: Date.now(),
|
|
10
|
+
usageCount: 0,
|
|
11
|
+
})));
|
|
12
|
+
// Create preset from current style
|
|
13
|
+
const createPreset = useCallback((name, description) => {
|
|
14
|
+
if (!editor)
|
|
15
|
+
return;
|
|
16
|
+
const { selection, storedMarks } = editor.state;
|
|
17
|
+
const { $from } = selection;
|
|
18
|
+
const marks = (storedMarks || $from.marks()).map(mark => ({
|
|
19
|
+
type: mark.type.name,
|
|
20
|
+
attrs: mark.attrs,
|
|
21
|
+
}));
|
|
22
|
+
const textStyle = editor.getAttributes('textStyle');
|
|
23
|
+
const preset = {
|
|
24
|
+
id: `preset-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
25
|
+
name,
|
|
26
|
+
description,
|
|
27
|
+
marks,
|
|
28
|
+
textStyle,
|
|
29
|
+
createdAt: Date.now(),
|
|
30
|
+
usageCount: 0,
|
|
31
|
+
};
|
|
32
|
+
setPresets(prev => {
|
|
33
|
+
const updated = [preset, ...prev];
|
|
34
|
+
return updated.slice(0, maxPresets);
|
|
35
|
+
});
|
|
36
|
+
return preset;
|
|
37
|
+
}, [editor, maxPresets, setPresets]);
|
|
38
|
+
// Apply preset
|
|
39
|
+
const applyPreset = useCallback((presetId) => {
|
|
40
|
+
if (!editor)
|
|
41
|
+
return;
|
|
42
|
+
const preset = presets.find(p => p.id === presetId);
|
|
43
|
+
if (!preset)
|
|
44
|
+
return;
|
|
45
|
+
// Clear current formatting
|
|
46
|
+
editor.chain().focus().unsetAllMarks().run();
|
|
47
|
+
// Apply text style attributes
|
|
48
|
+
if (preset.textStyle.fontSize) {
|
|
49
|
+
editor.chain().setFontSize(preset.textStyle.fontSize).run();
|
|
50
|
+
}
|
|
51
|
+
if (preset.textStyle.fontFamily) {
|
|
52
|
+
editor.chain().setFontFamily(preset.textStyle.fontFamily).run();
|
|
53
|
+
}
|
|
54
|
+
if (preset.textStyle.color) {
|
|
55
|
+
editor.chain().setColor(preset.textStyle.color).run();
|
|
56
|
+
}
|
|
57
|
+
if (preset.textStyle.backgroundColor) {
|
|
58
|
+
editor.chain().setBackgroundColor(preset.textStyle.backgroundColor).run();
|
|
59
|
+
}
|
|
60
|
+
if (preset.textStyle.fontWeight) {
|
|
61
|
+
editor.chain().setFontWeight(preset.textStyle.fontWeight).run();
|
|
62
|
+
}
|
|
63
|
+
// Apply marks
|
|
64
|
+
preset.marks.forEach(({ type, attrs }) => {
|
|
65
|
+
editor.chain().setMark(type, attrs).run();
|
|
66
|
+
});
|
|
67
|
+
// Update usage count
|
|
68
|
+
setPresets(prev => prev.map(p => (p.id === presetId ? { ...p, usageCount: p.usageCount + 1 } : p)));
|
|
69
|
+
}, [editor, presets, setPresets]);
|
|
70
|
+
// Delete preset
|
|
71
|
+
const deletePreset = useCallback((presetId) => {
|
|
72
|
+
setPresets(prev => prev.filter(p => p.id !== presetId));
|
|
73
|
+
}, [setPresets]);
|
|
74
|
+
// Get popular presets
|
|
75
|
+
const getPopularPresets = useCallback((limit = 5) => [...presets].sort((a, b) => b.usageCount - a.usageCount).slice(0, limit), [presets]);
|
|
76
|
+
return {
|
|
77
|
+
presets,
|
|
78
|
+
createPreset,
|
|
79
|
+
applyPreset,
|
|
80
|
+
deletePreset,
|
|
81
|
+
getPopularPresets,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
}
|
|
@@ -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,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
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>;
|
|
3
|
+
export declare const StyledEditorContent: import("styled-components").StyledComponent<import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Omit<import("@tiptap/react").EditorContentProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>>, any, {}, never>;
|
|
4
|
+
export declare const ColorBox: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
|
+
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,69 @@
|
|
|
1
|
+
import { EditorContent } from '@tiptap/react';
|
|
2
|
+
import styled 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
|
+
export const StyledEditorContent = styled(EditorContent) `
|
|
14
|
+
.tiptap {
|
|
15
|
+
outline: none;
|
|
16
|
+
|
|
17
|
+
p {
|
|
18
|
+
cursor: text;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.selection {
|
|
22
|
+
background-color: #d7cac9;
|
|
23
|
+
background-color: color-mix(in lab, var(--text-style-bg-color, transparent), #d7cac9);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.smart-tag {
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
|
|
29
|
+
&.highlight {
|
|
30
|
+
background-color: ${SMART_TAG_HIGHLIGHT_BG};
|
|
31
|
+
background-color: color-mix(
|
|
32
|
+
in lab,
|
|
33
|
+
var(--text-style-bg-color, transparent),
|
|
34
|
+
${SMART_TAG_HIGHLIGHT_BG}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
&:hover {
|
|
38
|
+
background-color: ${SMART_TAG_HIGHLIGHT_BG};
|
|
39
|
+
background-color: color-mix(
|
|
40
|
+
in lab,
|
|
41
|
+
var(--text-style-bg-color, transparent),
|
|
42
|
+
${SMART_TAG_HIGHLIGHT_BG} 80%
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
export const ColorBox = styled.div `
|
|
50
|
+
cursor: pointer;
|
|
51
|
+
width: 20px;
|
|
52
|
+
height: 20px;
|
|
53
|
+
border-radius: 50%;
|
|
54
|
+
border: 1px solid #d9d9d9;
|
|
55
|
+
|
|
56
|
+
&:hover {
|
|
57
|
+
box-shadow: rgba(0, 0, 0, 0.35) 0px 0px 3px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
&.active {
|
|
61
|
+
box-shadow: blue 0px 0px 3px;
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
export const ToolbarWrapper = styled(Flex) `
|
|
65
|
+
.antsomi-divider.toolbar-separator {
|
|
66
|
+
height: 20px;
|
|
67
|
+
margin: 2px;
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { JSONContent, Editor } from '@tiptap/core';
|
|
3
|
+
import { Attrs } from '@tiptap/pm/model';
|
|
4
|
+
export type HandleSmartTagRef = {
|
|
5
|
+
setSmartTag: (id: string, content: string) => void;
|
|
6
|
+
deleteSmartTag: (id: string) => void;
|
|
7
|
+
updateSmartTagAttrs: (id: string, updatedAttrs: Attrs) => void;
|
|
8
|
+
};
|
|
9
|
+
export type HandleLinkRef = {
|
|
10
|
+
setLink: (args: {
|
|
11
|
+
id: string;
|
|
12
|
+
link: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
text?: string;
|
|
15
|
+
dynamic?: boolean;
|
|
16
|
+
}) => void;
|
|
17
|
+
deleteLink: (id: string) => void;
|
|
18
|
+
updateLinkAttrs: (id: string, updatedAttrs: Attrs) => void;
|
|
19
|
+
updateLinkText: (id: string, newText: string) => void;
|
|
20
|
+
};
|
|
21
|
+
export type TextEditorRef = HandleSmartTagRef & HandleLinkRef & {
|
|
22
|
+
blur: (perserveSelection?: boolean) => void;
|
|
23
|
+
style?: CSSStyleDeclaration;
|
|
24
|
+
readonly editor: Editor | null;
|
|
25
|
+
};
|
|
26
|
+
export type SmartTagHandler = Partial<{
|
|
27
|
+
edit: (id: string, event: React.MouseEvent) => void;
|
|
28
|
+
setNew: (args: {
|
|
29
|
+
selectionText: string;
|
|
30
|
+
}) => void;
|
|
31
|
+
}>;
|
|
32
|
+
export type LinkHandler = Partial<{
|
|
33
|
+
setNew: (args: {
|
|
34
|
+
selectionText: string;
|
|
35
|
+
}) => void;
|
|
36
|
+
edit: (args: {
|
|
37
|
+
id: string;
|
|
38
|
+
selectionText: string;
|
|
39
|
+
}) => void;
|
|
40
|
+
}>;
|
|
41
|
+
export type FontConfig = {
|
|
42
|
+
fontFamily: {
|
|
43
|
+
name: string;
|
|
44
|
+
fallback?: string[];
|
|
45
|
+
};
|
|
46
|
+
fontWeight: number[];
|
|
47
|
+
};
|
|
48
|
+
export type Config = Partial<{
|
|
49
|
+
SmartTag: Partial<{
|
|
50
|
+
highlight: boolean;
|
|
51
|
+
}>;
|
|
52
|
+
Color: {
|
|
53
|
+
colorPickerStorageKey: string;
|
|
54
|
+
};
|
|
55
|
+
BackgroundColor: {
|
|
56
|
+
colorPickerStorageKey: string;
|
|
57
|
+
};
|
|
58
|
+
FontFamily: {
|
|
59
|
+
fonts: FontConfig[];
|
|
60
|
+
};
|
|
61
|
+
}>;
|
|
62
|
+
export type TextStyle = {
|
|
63
|
+
fontFamily: string;
|
|
64
|
+
fontSize: string;
|
|
65
|
+
color: string;
|
|
66
|
+
backgroundColor: string;
|
|
67
|
+
lineHeight: string;
|
|
68
|
+
fontWeight: string;
|
|
69
|
+
};
|
|
70
|
+
export type TextEditorProps = {
|
|
71
|
+
id?: string;
|
|
72
|
+
className?: string;
|
|
73
|
+
style?: React.CSSProperties;
|
|
74
|
+
initialContent?: string;
|
|
75
|
+
config?: Config;
|
|
76
|
+
smartTagHandler?: SmartTagHandler;
|
|
77
|
+
linkHandler?: LinkHandler;
|
|
78
|
+
editable?: boolean;
|
|
79
|
+
bubbleMenuProps?: {
|
|
80
|
+
container?: HTMLElement | null;
|
|
81
|
+
};
|
|
82
|
+
defaultTextStyle?: Partial<TextStyle>;
|
|
83
|
+
dataAttributes?: Record<`data-${string}`, unknown>;
|
|
84
|
+
onFocus?: (event: FocusEvent) => void;
|
|
85
|
+
onUpdate?: (args: {
|
|
86
|
+
html: string;
|
|
87
|
+
text: string;
|
|
88
|
+
json: JSONContent;
|
|
89
|
+
}) => void;
|
|
90
|
+
onCreate?: (args: {
|
|
91
|
+
html: string;
|
|
92
|
+
text: string;
|
|
93
|
+
json: JSONContent;
|
|
94
|
+
}) => void;
|
|
95
|
+
};
|
|
@@ -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>>;
|