@antscorp/antsomi-ui 2.0.83-text-editor-beta.10 → 2.0.84
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 +2 -4
- package/es/components/molecules/DisplayFormat/constants.js +2 -2
- package/es/components/molecules/DisplayFormat/utils.js +2 -2
- package/es/components/molecules/EmojiPopover/EmojiPopover.js +1 -5
- package/es/components/molecules/VirtualizedMenu/VirtualizedMenu.d.ts +3 -6
- package/es/components/molecules/VirtualizedMenu/__mocks__/index.js +982 -2594
- package/es/components/molecules/VirtualizedMenu/components/Item/Item.d.ts +3 -13
- package/es/components/molecules/VirtualizedMenu/components/Item/Item.js +25 -53
- package/es/components/molecules/VirtualizedMenu/components/Item/index.d.ts +1 -1
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.d.ts +5 -8
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.js +46 -289
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/index.js +0 -1
- package/es/components/molecules/VirtualizedMenu/styled.d.ts +1 -1
- package/es/components/molecules/VirtualizedMenu/styled.js +4 -23
- package/es/components/molecules/VirtualizedMenu/types.d.ts +9 -6
- package/es/components/molecules/VirtualizedMenu/utils.d.ts +5 -8
- package/es/components/molecules/VirtualizedMenu/utils.js +18 -13
- package/es/components/molecules/index.d.ts +0 -1
- package/es/components/molecules/index.js +0 -1
- package/es/components/organism/index.d.ts +0 -1
- package/es/components/organism/index.js +0 -1
- package/es/hooks/index.d.ts +0 -1
- package/es/hooks/index.js +0 -1
- package/es/utils/common.d.ts +9 -6
- package/es/utils/common.js +23 -44
- package/es/utils/index.d.ts +0 -1
- package/es/utils/index.js +0 -1
- package/es/utils/web.d.ts +0 -4
- package/es/utils/web.js +0 -25
- package/package.json +3 -29
- package/es/components/index.scss +0 -2
- package/es/components/molecules/FontSizeInput/FontSizeInput.d.ts +0 -3
- package/es/components/molecules/FontSizeInput/FontSizeInput.js +0 -128
- package/es/components/molecules/FontSizeInput/components/FontSizeControl.d.ts +0 -8
- package/es/components/molecules/FontSizeInput/components/FontSizeControl.js +0 -14
- package/es/components/molecules/FontSizeInput/components/FontSizeDropdown.d.ts +0 -20
- package/es/components/molecules/FontSizeInput/components/FontSizeDropdown.js +0 -17
- package/es/components/molecules/FontSizeInput/constants.d.ts +0 -2
- package/es/components/molecules/FontSizeInput/constants.js +0 -5
- package/es/components/molecules/FontSizeInput/index.d.ts +0 -2
- package/es/components/molecules/FontSizeInput/index.js +0 -1
- package/es/components/molecules/FontSizeInput/styled.d.ts +0 -3
- package/es/components/molecules/FontSizeInput/styled.js +0 -22
- package/es/components/molecules/FontSizeInput/styles.scss +0 -15
- package/es/components/molecules/FontSizeInput/types.d.ts +0 -24
- package/es/components/molecules/FontSizeInput/types.js +0 -1
- package/es/components/molecules/FontSizeInput/utils.d.ts +0 -7
- package/es/components/molecules/FontSizeInput/utils.js +0 -9
- package/es/components/molecules/index.scss +0 -1
- package/es/components/organism/ActivityTimeline/__mocks__/event_tracking.json +0 -1290
- package/es/components/organism/ActivityTimeline/__mocks__/timeline.json +0 -3059
- package/es/components/organism/TextEditor/TextEditor.d.ts +0 -3
- package/es/components/organism/TextEditor/TextEditor.js +0 -251
- package/es/components/organism/TextEditor/__mocks__/text-block.settings.json +0 -320
- package/es/components/organism/TextEditor/__mocks__/text-contennt.d.ts +0 -1
- package/es/components/organism/TextEditor/__mocks__/text-contennt.js +0 -38
- package/es/components/organism/TextEditor/constants.d.ts +0 -135
- package/es/components/organism/TextEditor/constants.js +0 -280
- package/es/components/organism/TextEditor/extensions/BackgroundColor.d.ts +0 -25
- package/es/components/organism/TextEditor/extensions/BackgroundColor.js +0 -46
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.d.ts +0 -130
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu-plugin.js +0 -247
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.d.ts +0 -15
- package/es/components/organism/TextEditor/extensions/BubbleMenu/bubble-menu.js +0 -31
- package/es/components/organism/TextEditor/extensions/BubbleMenu/index.d.ts +0 -2
- package/es/components/organism/TextEditor/extensions/BubbleMenu/index.js +0 -2
- package/es/components/organism/TextEditor/extensions/Color.d.ts +0 -6
- package/es/components/organism/TextEditor/extensions/Color.js +0 -41
- package/es/components/organism/TextEditor/extensions/Emoji.d.ts +0 -57
- package/es/components/organism/TextEditor/extensions/Emoji.js +0 -184
- package/es/components/organism/TextEditor/extensions/FontFamily.d.ts +0 -6
- package/es/components/organism/TextEditor/extensions/FontFamily.js +0 -43
- package/es/components/organism/TextEditor/extensions/FontSize.d.ts +0 -32
- package/es/components/organism/TextEditor/extensions/FontSize.js +0 -47
- package/es/components/organism/TextEditor/extensions/FontWeight.d.ts +0 -23
- package/es/components/organism/TextEditor/extensions/FontWeight.js +0 -41
- package/es/components/organism/TextEditor/extensions/Highlight.d.ts +0 -1
- package/es/components/organism/TextEditor/extensions/Highlight.js +0 -14
- package/es/components/organism/TextEditor/extensions/Indent.d.ts +0 -28
- package/es/components/organism/TextEditor/extensions/Indent.js +0 -68
- package/es/components/organism/TextEditor/extensions/LineHeight.d.ts +0 -20
- package/es/components/organism/TextEditor/extensions/LineHeight.js +0 -36
- package/es/components/organism/TextEditor/extensions/Link.d.ts +0 -15
- package/es/components/organism/TextEditor/extensions/Link.js +0 -50
- package/es/components/organism/TextEditor/extensions/ListItemMarker.d.ts +0 -13
- package/es/components/organism/TextEditor/extensions/ListItemMarker.js +0 -174
- package/es/components/organism/TextEditor/extensions/Selection.d.ts +0 -6
- package/es/components/organism/TextEditor/extensions/Selection.js +0 -40
- package/es/components/organism/TextEditor/extensions/SmartTag.d.ts +0 -39
- package/es/components/organism/TextEditor/extensions/SmartTag.js +0 -167
- package/es/components/organism/TextEditor/extensions/StyleMemory.d.ts +0 -36
- package/es/components/organism/TextEditor/extensions/StyleMemory.js +0 -163
- package/es/components/organism/TextEditor/extensions/TextTransform.d.ts +0 -31
- package/es/components/organism/TextEditor/extensions/TextTransform.js +0 -37
- package/es/components/organism/TextEditor/hooks/index.d.ts +0 -6
- package/es/components/organism/TextEditor/hooks/index.js +0 -6
- package/es/components/organism/TextEditor/hooks/useDocumentState.d.ts +0 -18
- package/es/components/organism/TextEditor/hooks/useDocumentState.js +0 -42
- package/es/components/organism/TextEditor/hooks/useLinkHandler.d.ts +0 -10
- package/es/components/organism/TextEditor/hooks/useLinkHandler.js +0 -223
- package/es/components/organism/TextEditor/hooks/useMarkTracking.d.ts +0 -26
- package/es/components/organism/TextEditor/hooks/useMarkTracking.js +0 -68
- package/es/components/organism/TextEditor/hooks/usePersistence.d.ts +0 -31
- package/es/components/organism/TextEditor/hooks/usePersistence.js +0 -169
- package/es/components/organism/TextEditor/hooks/useStyleMemory.d.ts +0 -6
- package/es/components/organism/TextEditor/hooks/useStyleMemory.js +0 -42
- package/es/components/organism/TextEditor/hooks/useStylePresets.d.ts +0 -34
- package/es/components/organism/TextEditor/hooks/useStylePresets.js +0 -83
- package/es/components/organism/TextEditor/index.d.ts +0 -14
- package/es/components/organism/TextEditor/index.js +0 -6
- package/es/components/organism/TextEditor/index.scss +0 -61
- package/es/components/organism/TextEditor/provider.d.ts +0 -10
- package/es/components/organism/TextEditor/provider.js +0 -20
- package/es/components/organism/TextEditor/store.d.ts +0 -11
- package/es/components/organism/TextEditor/store.js +0 -12
- package/es/components/organism/TextEditor/styled.d.ts +0 -8
- package/es/components/organism/TextEditor/styled.js +0 -90
- package/es/components/organism/TextEditor/types.d.ts +0 -92
- package/es/components/organism/TextEditor/types.js +0 -1
- package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.d.ts +0 -6
- package/es/components/organism/TextEditor/ui/BubbleMenu/BubbleMenu.js +0 -78
- package/es/components/organism/TextEditor/ui/BubbleMenu/index.d.ts +0 -1
- package/es/components/organism/TextEditor/ui/BubbleMenu/index.js +0 -1
- package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.d.ts +0 -43
- package/es/components/organism/TextEditor/ui/ColorPicker/ColorPicker.js +0 -120
- package/es/components/organism/TextEditor/ui/ColorPicker/index.d.ts +0 -1
- package/es/components/organism/TextEditor/ui/ColorPicker/index.js +0 -1
- package/es/components/organism/TextEditor/ui/Emoji/EmojiList.d.ts +0 -11
- package/es/components/organism/TextEditor/ui/Emoji/EmojiList.js +0 -66
- package/es/components/organism/TextEditor/ui/Emoji/index.d.ts +0 -2
- package/es/components/organism/TextEditor/ui/Emoji/index.js +0 -2
- package/es/components/organism/TextEditor/ui/Emoji/suggestion.d.ts +0 -4
- package/es/components/organism/TextEditor/ui/Emoji/suggestion.js +0 -71
- package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.d.ts +0 -12
- package/es/components/organism/TextEditor/ui/FontPopover/FontPopover.js +0 -69
- package/es/components/organism/TextEditor/ui/FontPopover/styled.d.ts +0 -1
- package/es/components/organism/TextEditor/ui/FontPopover/styled.js +0 -20
- package/es/components/organism/TextEditor/ui/Popover/Popover.d.ts +0 -6
- package/es/components/organism/TextEditor/ui/Popover/Popover.js +0 -7
- package/es/components/organism/TextEditor/ui/Popover/index.d.ts +0 -1
- package/es/components/organism/TextEditor/ui/Popover/index.js +0 -1
- package/es/components/organism/TextEditor/ui/Select/Select.d.ts +0 -4
- package/es/components/organism/TextEditor/ui/Select/Select.js +0 -7
- package/es/components/organism/TextEditor/ui/Select/index.d.ts +0 -1
- package/es/components/organism/TextEditor/ui/Select/index.js +0 -1
- package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.d.ts +0 -30
- package/es/components/organism/TextEditor/ui/TextAlignSelect/TextAlignSelect.js +0 -49
- package/es/components/organism/TextEditor/ui/TextAlignSelect/index.d.ts +0 -1
- package/es/components/organism/TextEditor/ui/TextAlignSelect/index.js +0 -1
- package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.d.ts +0 -14
- package/es/components/organism/TextEditor/ui/Toolbar/Toolbar.js +0 -42
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.d.ts +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BoldAction.js +0 -7
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.d.ts +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/BulletListAction.js +0 -7
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.d.ts +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ClearFormattingAction.js +0 -18
- package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.d.ts +0 -4
- package/es/components/organism/TextEditor/ui/Toolbar/actions/EmojiAction.js +0 -13
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.d.ts +0 -7
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontFamilyAction.js +0 -18
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.d.ts +0 -7
- package/es/components/organism/TextEditor/ui/Toolbar/actions/FontSizeAction.js +0 -37
- package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.d.ts +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/HighlightAction.js +0 -7
- package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.d.ts +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/IndentAction.js +0 -7
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.d.ts +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/ItalicAction.js +0 -7
- package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.d.ts +0 -6
- package/es/components/organism/TextEditor/ui/Toolbar/actions/LinkAction.js +0 -4
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.d.ts +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OrderedListAction.js +0 -7
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.d.ts +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/OutdentAction.js +0 -7
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.d.ts +0 -7
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SmartTagAction.js +0 -9
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.d.ts +0 -9
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SpacingAction.js +0 -22
- package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.d.ts +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/StrikeAction.js +0 -7
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.d.ts +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SubscriptAction.js +0 -13
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.d.ts +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/SuperscriptAction.js +0 -13
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.d.ts +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextAlignAction.js +0 -3
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.d.ts +0 -7
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextBackgroundColorAction.js +0 -19
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.d.ts +0 -15
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextColorAction.js +0 -14
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.d.ts +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/TextTransformAction.js +0 -30
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.d.ts +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnderlineAction.js +0 -5
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.d.ts +0 -6
- package/es/components/organism/TextEditor/ui/Toolbar/actions/UnsetLink.js +0 -10
- package/es/components/organism/TextEditor/ui/Toolbar/actions/index.d.ts +0 -20
- package/es/components/organism/TextEditor/ui/Toolbar/actions/index.js +0 -20
- package/es/components/organism/TextEditor/ui/Toolbar/index.d.ts +0 -1
- package/es/components/organism/TextEditor/ui/Toolbar/index.js +0 -1
- package/es/components/organism/TextEditor/utils/documentState.d.ts +0 -57
- package/es/components/organism/TextEditor/utils/documentState.js +0 -100
- package/es/components/organism/TextEditor/utils/font.d.ts +0 -84
- package/es/components/organism/TextEditor/utils/font.js +0 -175
- package/es/components/organism/TextEditor/utils/htmlProcessing.d.ts +0 -63
- package/es/components/organism/TextEditor/utils/htmlProcessing.js +0 -321
- package/es/components/organism/TextEditor/utils/index.d.ts +0 -8
- package/es/components/organism/TextEditor/utils/index.js +0 -16
- package/es/components/organism/TextEditor/utils/link.d.ts +0 -100
- package/es/components/organism/TextEditor/utils/link.js +0 -149
- package/es/components/organism/TextEditor/utils/menu.d.ts +0 -134
- package/es/components/organism/TextEditor/utils/menu.js +0 -317
- package/es/components/organism/TextEditor/utils/selection.d.ts +0 -25
- package/es/components/organism/TextEditor/utils/selection.js +0 -57
- package/es/components/organism/TextEditor/utils/smartTag.d.ts +0 -49
- package/es/components/organism/TextEditor/utils/smartTag.js +0 -89
- package/es/components/organism/TextEditor/utils/style.d.ts +0 -78
- package/es/components/organism/TextEditor/utils/style.js +0 -193
- package/es/components/organism/index.scss +0 -1
- package/es/hooks/useBroadcastedLocalStorage.d.ts +0 -5
- package/es/hooks/useBroadcastedLocalStorage.js +0 -71
- package/es/hooks/useElementSize.d.ts +0 -7
- package/es/hooks/useElementSize.js +0 -56
- package/es/utils/tree.d.ts +0 -225
- package/es/utils/tree.js +0 -469
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { Node, mergeAttributes } from '@tiptap/core';
|
|
2
|
-
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
3
|
-
import { Decoration, DecorationSet } from '@tiptap/pm/view';
|
|
4
|
-
export const EXTENSION_NAME = 'smartTag';
|
|
5
|
-
/**
|
|
6
|
-
* Creates decorations for all SmartTag nodes in the document
|
|
7
|
-
* @param doc - The ProseMirror document
|
|
8
|
-
* @param highlight - Whether to highlight the SmartTags
|
|
9
|
-
* @returns A DecorationSet containing decorations for all SmartTag nodes
|
|
10
|
-
*/
|
|
11
|
-
function createSmartTagDecorations(doc, highlight) {
|
|
12
|
-
const decorations = [];
|
|
13
|
-
if (!highlight) {
|
|
14
|
-
return DecorationSet.create(doc, decorations);
|
|
15
|
-
}
|
|
16
|
-
// Find all SmartTag nodes and create decorations for them
|
|
17
|
-
doc.descendants((node, pos) => {
|
|
18
|
-
if (node.type.name === EXTENSION_NAME) {
|
|
19
|
-
// Create a node decoration that adds the highlight class
|
|
20
|
-
decorations.push(Decoration.node(pos, pos + node.nodeSize, {
|
|
21
|
-
class: 'highlight',
|
|
22
|
-
}));
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
return DecorationSet.create(doc, decorations);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Represents a dynamic tag node in the editor.
|
|
29
|
-
*/
|
|
30
|
-
export const SmartTag = Node.create({
|
|
31
|
-
name: EXTENSION_NAME,
|
|
32
|
-
group: 'inline',
|
|
33
|
-
atom: true,
|
|
34
|
-
inline: true,
|
|
35
|
-
selectable: true,
|
|
36
|
-
addStorage() {
|
|
37
|
-
return {
|
|
38
|
-
highlight: this.options.highlight,
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
addOptions() {
|
|
42
|
-
return {
|
|
43
|
-
HTMLAttributes: {},
|
|
44
|
-
highlight: true,
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
addAttributes() {
|
|
48
|
-
return {
|
|
49
|
-
id: {
|
|
50
|
-
default: '',
|
|
51
|
-
parseHTML: el => el.getAttribute('data-dynamic-id'),
|
|
52
|
-
},
|
|
53
|
-
content: {
|
|
54
|
-
default: '',
|
|
55
|
-
parseHTML: el => el.innerText,
|
|
56
|
-
},
|
|
57
|
-
tag: {
|
|
58
|
-
default: null,
|
|
59
|
-
parseHTML: el => el.getAttribute('tag'),
|
|
60
|
-
renderHTML: attrs => (attrs.tag ? { tag: attrs.tag } : null),
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
},
|
|
64
|
-
parseHTML() {
|
|
65
|
-
return [
|
|
66
|
-
{
|
|
67
|
-
tag: 'span[data-dynamic="true"]',
|
|
68
|
-
priority: 1000,
|
|
69
|
-
getAttrs: node => node.getAttribute('data-dynamic') === 'true' && null,
|
|
70
|
-
},
|
|
71
|
-
];
|
|
72
|
-
},
|
|
73
|
-
renderHTML({ node }) {
|
|
74
|
-
return [
|
|
75
|
-
'span',
|
|
76
|
-
mergeAttributes(this.options.HTMLAttributes, {
|
|
77
|
-
'data-dynamic': 'true',
|
|
78
|
-
'data-dynamic-id': node.attrs.id,
|
|
79
|
-
class: 'smart-tag',
|
|
80
|
-
}),
|
|
81
|
-
node.attrs.content,
|
|
82
|
-
];
|
|
83
|
-
},
|
|
84
|
-
renderText({ node }) {
|
|
85
|
-
return node.attrs.content;
|
|
86
|
-
},
|
|
87
|
-
addCommands() {
|
|
88
|
-
return {
|
|
89
|
-
setSmartTag: attrs => ({ chain, state }) => {
|
|
90
|
-
const { selection, storedMarks } = state;
|
|
91
|
-
const { $from } = selection;
|
|
92
|
-
const marks = storedMarks || $from.marks();
|
|
93
|
-
const smartTagNode = this.type.create(attrs);
|
|
94
|
-
const nodeWithMarks = marks.length > 0 ? smartTagNode.mark(marks) : smartTagNode;
|
|
95
|
-
return chain()
|
|
96
|
-
.command(({ tr }) => {
|
|
97
|
-
tr.replaceSelectionWith(nodeWithMarks, false);
|
|
98
|
-
return true;
|
|
99
|
-
})
|
|
100
|
-
.run();
|
|
101
|
-
},
|
|
102
|
-
deleteSmartTagGlobally: predicate => ({ tr, state }) => {
|
|
103
|
-
let hasDeleted = false;
|
|
104
|
-
const { doc } = state;
|
|
105
|
-
doc.descendants((node, pos) => {
|
|
106
|
-
if (node.type.name === this.name && predicate(node.attrs)) {
|
|
107
|
-
tr.delete(pos, pos + node.nodeSize);
|
|
108
|
-
hasDeleted = true;
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
return hasDeleted;
|
|
112
|
-
},
|
|
113
|
-
updateSmartTagAttrsGlobally: updateFn => ({ tr, state }) => {
|
|
114
|
-
let hasUpdated = false;
|
|
115
|
-
const { doc } = state;
|
|
116
|
-
doc.descendants((node, pos) => {
|
|
117
|
-
if (node.type.name === this.name) {
|
|
118
|
-
const updatedAttrs = updateFn(node.attrs);
|
|
119
|
-
if (updatedAttrs) {
|
|
120
|
-
tr.setNodeMarkup(pos, undefined, {
|
|
121
|
-
...node.attrs,
|
|
122
|
-
...updatedAttrs,
|
|
123
|
-
});
|
|
124
|
-
hasUpdated = true;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
return hasUpdated;
|
|
129
|
-
},
|
|
130
|
-
updateSmartTagHighlight: (enabled) => ({ tr }) => {
|
|
131
|
-
// Update the storage value
|
|
132
|
-
this.storage.highlight = enabled;
|
|
133
|
-
// Set metadata on the transaction to trigger the plugin to update decorations
|
|
134
|
-
tr.setMeta('updateSmartTagHighlight', { highlight: enabled });
|
|
135
|
-
return true;
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
},
|
|
139
|
-
addProseMirrorPlugins() {
|
|
140
|
-
return [
|
|
141
|
-
new Plugin({
|
|
142
|
-
key: new PluginKey(`${EXTENSION_NAME}_highlight`),
|
|
143
|
-
// Initialize the plugin state with decorations based on the initial highlight value
|
|
144
|
-
state: {
|
|
145
|
-
init: (_, { doc }) => createSmartTagDecorations(doc, this.storage.highlight),
|
|
146
|
-
// Update the decorations when the document changes or when the highlight value changes
|
|
147
|
-
apply: (tr, oldDecorations) => {
|
|
148
|
-
// Check if the highlight value has changed
|
|
149
|
-
const highlightMeta = tr.getMeta('updateSmartTagHighlight');
|
|
150
|
-
// If the document has changed or the highlight value has changed, update the decorations
|
|
151
|
-
if (tr.docChanged || highlightMeta !== undefined) {
|
|
152
|
-
return createSmartTagDecorations(tr.doc, this.storage.highlight);
|
|
153
|
-
}
|
|
154
|
-
// Otherwise, map the old decorations through the transaction
|
|
155
|
-
return oldDecorations.map(tr.mapping, tr.doc);
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
// Provide the decorations to the editor view
|
|
159
|
-
props: {
|
|
160
|
-
decorations(state) {
|
|
161
|
-
return this.getState(state);
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
}),
|
|
165
|
-
];
|
|
166
|
-
},
|
|
167
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Extension } from '@tiptap/core';
|
|
2
|
-
import { Mark } from '@tiptap/pm/model';
|
|
3
|
-
import { DocumentStateConfig } from '../utils/documentState';
|
|
4
|
-
export interface StyleMemoryOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Marks to exclude from being stored
|
|
7
|
-
* @default ['link', 'smartTag']
|
|
8
|
-
*/
|
|
9
|
-
excludeMarks: string[];
|
|
10
|
-
/**
|
|
11
|
-
* Configuration for document emptiness detection
|
|
12
|
-
*/
|
|
13
|
-
documentStateConfig?: DocumentStateConfig;
|
|
14
|
-
}
|
|
15
|
-
export interface StyleMemoryStorage {
|
|
16
|
-
storedMarks: Mark[];
|
|
17
|
-
}
|
|
18
|
-
declare module '@tiptap/core' {
|
|
19
|
-
interface Commands<ReturnType> {
|
|
20
|
-
styleMemory: {
|
|
21
|
-
/**
|
|
22
|
-
* Manually store current marks
|
|
23
|
-
*/
|
|
24
|
-
storeCurrentMarks: () => ReturnType;
|
|
25
|
-
/**
|
|
26
|
-
* Clear stored marks
|
|
27
|
-
*/
|
|
28
|
-
clearStoredMarks: () => ReturnType;
|
|
29
|
-
/**
|
|
30
|
-
* Apply stored marks to current selection
|
|
31
|
-
*/
|
|
32
|
-
applyStoredMarks: () => ReturnType;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
export declare const StyleMemory: Extension<StyleMemoryOptions, StyleMemoryStorage>;
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { Extension } from '@tiptap/core';
|
|
2
|
-
import { Plugin, PluginKey } from '@tiptap/pm/state';
|
|
3
|
-
import { isDocumentEmpty, DocumentStateTracker } from '../utils/documentState';
|
|
4
|
-
export const StyleMemory = Extension.create({
|
|
5
|
-
name: 'styleMemory',
|
|
6
|
-
addOptions() {
|
|
7
|
-
return {
|
|
8
|
-
excludeMarks: ['link', 'smartTag'],
|
|
9
|
-
documentStateConfig: {
|
|
10
|
-
ignoreWhitespace: true,
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
},
|
|
14
|
-
addStorage() {
|
|
15
|
-
return {
|
|
16
|
-
storedMarks: [],
|
|
17
|
-
};
|
|
18
|
-
},
|
|
19
|
-
addCommands() {
|
|
20
|
-
return {
|
|
21
|
-
storeCurrentMarks: () => ({ state }) => {
|
|
22
|
-
const { selection, storedMarks } = state;
|
|
23
|
-
const { $from } = selection;
|
|
24
|
-
// Get marks from current position or stored marks
|
|
25
|
-
const currentMarks = storedMarks || $from.marks();
|
|
26
|
-
// Filter out excluded marks
|
|
27
|
-
const filteredMarks = currentMarks.filter(mark => !this.options.excludeMarks.includes(mark.type.name));
|
|
28
|
-
this.storage.storedMarks = filteredMarks;
|
|
29
|
-
return true;
|
|
30
|
-
},
|
|
31
|
-
clearStoredMarks: () => () => {
|
|
32
|
-
this.storage.storedMarks = [];
|
|
33
|
-
return true;
|
|
34
|
-
},
|
|
35
|
-
applyStoredMarks: () => ({ commands }) => {
|
|
36
|
-
if (this.storage.storedMarks.length === 0) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
// Apply each stored mark
|
|
40
|
-
this.storage.storedMarks.forEach(mark => {
|
|
41
|
-
commands.setMark(mark.type.name, mark.attrs);
|
|
42
|
-
});
|
|
43
|
-
return true;
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
addProseMirrorPlugins() {
|
|
48
|
-
const stateTracker = new DocumentStateTracker();
|
|
49
|
-
return [
|
|
50
|
-
new Plugin({
|
|
51
|
-
key: new PluginKey('styleMemory'),
|
|
52
|
-
state: {
|
|
53
|
-
init: (_, initialState) => {
|
|
54
|
-
const isEmpty = isDocumentEmpty(initialState, this.options.documentStateConfig);
|
|
55
|
-
return {
|
|
56
|
-
lastContentSize: initialState.doc.content.size,
|
|
57
|
-
wasEmpty: isEmpty,
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
apply: (tr, _oldState, _oldEditorState, newEditorState) => {
|
|
61
|
-
const changes = stateTracker.update(newEditorState);
|
|
62
|
-
const isEmpty = isDocumentEmpty(newEditorState, this.options.documentStateConfig);
|
|
63
|
-
const hasContent = !isEmpty;
|
|
64
|
-
// Store marks when content exists and user has selection with marks
|
|
65
|
-
if (hasContent && tr.selection && !tr.selection.empty) {
|
|
66
|
-
const { $from } = tr.selection;
|
|
67
|
-
const marks = tr.storedMarks || $from.marks();
|
|
68
|
-
if (marks.length > 0) {
|
|
69
|
-
const filteredMarks = marks.filter(mark => !this.options.excludeMarks.includes(mark.type.name));
|
|
70
|
-
if (filteredMarks.length > 0) {
|
|
71
|
-
this.storage.storedMarks = filteredMarks;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// Also store marks when selection changes and we have marks
|
|
76
|
-
if (hasContent && tr.selectionSet) {
|
|
77
|
-
const { $from } = tr.selection;
|
|
78
|
-
const marks = tr.storedMarks || $from.marks();
|
|
79
|
-
if (marks.length > 0) {
|
|
80
|
-
const filteredMarks = marks.filter(mark => !this.options.excludeMarks.includes(mark.type.name));
|
|
81
|
-
if (filteredMarks.length > 0) {
|
|
82
|
-
this.storage.storedMarks = filteredMarks;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
// Apply stored marks when transitioning from empty to non-empty
|
|
87
|
-
if (changes.becameNonEmpty && this.storage.storedMarks.length > 0) {
|
|
88
|
-
// Set stored marks for the next input
|
|
89
|
-
tr.setStoredMarks(this.storage.storedMarks);
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
lastContentSize: newEditorState.doc.content.size,
|
|
93
|
-
wasEmpty: isEmpty,
|
|
94
|
-
};
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
appendTransaction: (transactions, oldState, newState) => {
|
|
98
|
-
const wasEmpty = isDocumentEmpty(oldState, this.options.documentStateConfig);
|
|
99
|
-
const hasContent = !isDocumentEmpty(newState, this.options.documentStateConfig);
|
|
100
|
-
// Check if we need to restore marks after content was added to empty editor
|
|
101
|
-
if (wasEmpty && hasContent && this.storage.storedMarks.length > 0) {
|
|
102
|
-
const { tr } = newState;
|
|
103
|
-
let hasChanges = false;
|
|
104
|
-
// Find the newly added content
|
|
105
|
-
let newContentStart = -1;
|
|
106
|
-
let newContentEnd = -1;
|
|
107
|
-
for (const transaction of transactions) {
|
|
108
|
-
if (transaction.docChanged) {
|
|
109
|
-
transaction.steps.forEach(step => {
|
|
110
|
-
if ('from' in step &&
|
|
111
|
-
'to' in step &&
|
|
112
|
-
typeof step.from === 'number' &&
|
|
113
|
-
typeof step.to === 'number') {
|
|
114
|
-
if (newContentStart === -1 || step.from < newContentStart) {
|
|
115
|
-
newContentStart = step.from;
|
|
116
|
-
}
|
|
117
|
-
if (newContentEnd === -1 || step.to > newContentEnd) {
|
|
118
|
-
newContentEnd = step.to;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
// Apply stored marks to the new content if we found the range
|
|
125
|
-
if (newContentStart !== -1 && newContentEnd !== -1) {
|
|
126
|
-
this.storage.storedMarks.forEach(mark => {
|
|
127
|
-
tr.addMark(newContentStart, newContentEnd, mark);
|
|
128
|
-
hasChanges = true;
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
// Also set stored marks for future typing
|
|
132
|
-
if (this.storage.storedMarks.length > 0) {
|
|
133
|
-
tr.setStoredMarks(this.storage.storedMarks);
|
|
134
|
-
hasChanges = true;
|
|
135
|
-
}
|
|
136
|
-
if (hasChanges) {
|
|
137
|
-
return tr;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return null;
|
|
141
|
-
},
|
|
142
|
-
// Handle view updates for better mark application
|
|
143
|
-
view: () => ({
|
|
144
|
-
update: (view, prevState) => {
|
|
145
|
-
const prevEmpty = isDocumentEmpty(prevState, this.options.documentStateConfig);
|
|
146
|
-
const currentEmpty = isDocumentEmpty(view.state, this.options.documentStateConfig);
|
|
147
|
-
// When transitioning from empty to non-empty, ensure stored marks are applied
|
|
148
|
-
if (prevEmpty && !currentEmpty && this.storage.storedMarks.length > 0) {
|
|
149
|
-
// Use setTimeout to ensure this runs after the current transaction
|
|
150
|
-
setTimeout(() => {
|
|
151
|
-
const { state, dispatch } = view;
|
|
152
|
-
const { tr } = state;
|
|
153
|
-
// Set stored marks for the current position
|
|
154
|
-
tr.setStoredMarks(this.storage.storedMarks);
|
|
155
|
-
dispatch(tr);
|
|
156
|
-
}, 0);
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
}),
|
|
160
|
-
}),
|
|
161
|
-
];
|
|
162
|
-
},
|
|
163
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import '@tiptap/extension-text-style';
|
|
2
|
-
import { Extension } from '@tiptap/core';
|
|
3
|
-
export type TextTransformOptions = {
|
|
4
|
-
/**
|
|
5
|
-
* A list of node names where the text transform can be applied.
|
|
6
|
-
* @default ['textStyle']
|
|
7
|
-
* @example ['heading', 'paragraph']
|
|
8
|
-
*/
|
|
9
|
-
types: string[];
|
|
10
|
-
};
|
|
11
|
-
declare module '@tiptap/core' {
|
|
12
|
-
interface Commands<ReturnType> {
|
|
13
|
-
textTransform: {
|
|
14
|
-
/**
|
|
15
|
-
* Set the text transform
|
|
16
|
-
* @param textTransform The text transform
|
|
17
|
-
* @example editor.commands.setTextTransform('uppercase')
|
|
18
|
-
*/
|
|
19
|
-
setTextTransform: (textTransform: string) => ReturnType;
|
|
20
|
-
/**
|
|
21
|
-
* Unset the text transform
|
|
22
|
-
* @example editor.commands.unsetTextTransform()
|
|
23
|
-
*/
|
|
24
|
-
unsetTextTransform: () => ReturnType;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* This extension allows you to set a text transform for text.
|
|
30
|
-
*/
|
|
31
|
-
export declare const TextTransform: Extension<TextTransformOptions, any>;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import '@tiptap/extension-text-style';
|
|
2
|
-
import { Extension } from '@tiptap/core';
|
|
3
|
-
/**
|
|
4
|
-
* This extension allows you to set a text transform for text.
|
|
5
|
-
*/
|
|
6
|
-
export const TextTransform = Extension.create({
|
|
7
|
-
name: 'textTransform',
|
|
8
|
-
addOptions() {
|
|
9
|
-
return {
|
|
10
|
-
types: ['textStyle'],
|
|
11
|
-
};
|
|
12
|
-
},
|
|
13
|
-
addGlobalAttributes() {
|
|
14
|
-
return [
|
|
15
|
-
{
|
|
16
|
-
types: this.options.types,
|
|
17
|
-
attributes: {
|
|
18
|
-
textTransform: {
|
|
19
|
-
default: null,
|
|
20
|
-
renderHTML: attrs => attrs.textTransform && attrs.textTransform !== 'none'
|
|
21
|
-
? {
|
|
22
|
-
style: `text-transform: ${attrs.textTransform}`,
|
|
23
|
-
}
|
|
24
|
-
: {},
|
|
25
|
-
parseHTML: element => element.style.textTransform,
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
];
|
|
30
|
-
},
|
|
31
|
-
addCommands() {
|
|
32
|
-
return {
|
|
33
|
-
setTextTransform: textTransform => ({ chain }) => chain().setMark('textStyle', { textTransform }).run(),
|
|
34
|
-
unsetTextTransform: () => ({ chain }) => chain().setMark('textStyle', { textTransform: 'none' }).removeEmptyTextStyle().run(),
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Editor } from '@tiptap/react';
|
|
2
|
-
import { DocumentStateConfig, getDocumentStats } from '../utils/documentState';
|
|
3
|
-
export interface UseDocumentStateOptions extends DocumentStateConfig {
|
|
4
|
-
/** Callback when document becomes empty */
|
|
5
|
-
onBecomeEmpty?: () => void;
|
|
6
|
-
/** Callback when document becomes non-empty */
|
|
7
|
-
onBecomeNonEmpty?: () => void;
|
|
8
|
-
/** Callback when document state changes */
|
|
9
|
-
onStateChange?: (stats: ReturnType<typeof getDocumentStats>) => void;
|
|
10
|
-
}
|
|
11
|
-
export declare function useDocumentState(editor: Editor | null, options?: UseDocumentStateOptions): {
|
|
12
|
-
nodeSize: number;
|
|
13
|
-
textLength: number;
|
|
14
|
-
trimmedTextLength: number;
|
|
15
|
-
nodeCount: void;
|
|
16
|
-
isEmpty: boolean;
|
|
17
|
-
emptyDocumentSize: number;
|
|
18
|
-
} | null;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { DocumentStateTracker, getDocumentStats, } from '../utils/documentState';
|
|
3
|
-
export function useDocumentState(editor, options = {}) {
|
|
4
|
-
const { onBecomeEmpty, onBecomeNonEmpty, onStateChange } = options;
|
|
5
|
-
const [documentStats, setDocumentStats] = useState(() => editor ? getDocumentStats(editor.state) : null);
|
|
6
|
-
const trackerRef = useRef(new DocumentStateTracker());
|
|
7
|
-
const updateDocumentState = useCallback(() => {
|
|
8
|
-
if (!editor)
|
|
9
|
-
return;
|
|
10
|
-
const stats = getDocumentStats(editor.state);
|
|
11
|
-
const changes = trackerRef.current.update(editor.state);
|
|
12
|
-
setDocumentStats(stats);
|
|
13
|
-
// Trigger callbacks
|
|
14
|
-
if (changes.becameEmpty) {
|
|
15
|
-
onBecomeEmpty?.();
|
|
16
|
-
}
|
|
17
|
-
if (changes.becameNonEmpty) {
|
|
18
|
-
onBecomeNonEmpty?.();
|
|
19
|
-
}
|
|
20
|
-
if (changes.sizeChanged || changes.textLengthChanged) {
|
|
21
|
-
onStateChange?.(stats);
|
|
22
|
-
}
|
|
23
|
-
}, [editor, onBecomeEmpty, onBecomeNonEmpty, onStateChange]);
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
if (!editor)
|
|
26
|
-
return;
|
|
27
|
-
// Initial state
|
|
28
|
-
updateDocumentState();
|
|
29
|
-
// Listen to changes
|
|
30
|
-
editor.on('update', updateDocumentState);
|
|
31
|
-
editor.on('transaction', updateDocumentState);
|
|
32
|
-
return () => {
|
|
33
|
-
editor.off('update', updateDocumentState);
|
|
34
|
-
editor.off('transaction', updateDocumentState);
|
|
35
|
-
};
|
|
36
|
-
}, [editor, updateDocumentState]);
|
|
37
|
-
// Reset tracker when editor changes
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
trackerRef.current.reset();
|
|
40
|
-
}, [editor]);
|
|
41
|
-
return documentStats;
|
|
42
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Editor } from '@tiptap/react';
|
|
2
|
-
import { Attrs } from '@tiptap/pm/model';
|
|
3
|
-
export declare function useLinkHandler(params: {
|
|
4
|
-
editor?: Editor | null;
|
|
5
|
-
}): {
|
|
6
|
-
setLink: (attrs: import("../extensions/Link").LinkAttrs) => void;
|
|
7
|
-
deleteLink: (id: string) => void;
|
|
8
|
-
unsetLink: () => void;
|
|
9
|
-
updateLinkAttrsGlobally: (updateFn: (attrs: Attrs) => Attrs | undefined) => void;
|
|
10
|
-
};
|