@@ -35,6 +35,7 @@ import { useSputlitContext, VisualState } from '../../Hooks/useSputlitContext'
35
35
import { useContentStore } from '../../Stores/useContentStore'
36
36
import useDataStore from '../../Stores/useDataStore'
37
37
import { getDibbaText } from '../../Utils/getDibbaText'
38
+ import { supportedDomains , simulateOnChange , copySnippetToClipboard , getUpcomingData } from '../../Utils/pasteUtils'
38
39
import EditorPreviewRenderer from '../EditorPreviewRenderer'
39
40
import { ComboboxItem , ComboboxRoot , ItemCenterWrapper , ItemDesc , ItemRightIcons , ItemTitle } from './styled'
40
41
@@ -47,85 +48,6 @@ interface PublicNode {
47
48
content : NodeEditorContent
48
49
}
49
50
50
- // TODO: add more domains and their supported types
51
- // Also a better matching for the domains
52
- const supportedDomains : Record < string , 'plain' | 'html' > = {
53
- 'https://mail.google.com' : 'html' ,
54
- 'https://www.figma.com' : 'plain' ,
55
- 'https://keep.google.com' : 'plain'
56
- }
57
-
58
- export const copySnippetToClipboard = async ( item : Snippet ) => {
59
- const text = convertContentToRawText ( item . content , '\n' )
60
-
61
- let html = text
62
-
63
- try {
64
- const filterdContent = convertToCopySnippet ( item . content )
65
- const convertedContent = convertToCopySnippet ( filterdContent , {
66
- filter : defaultCopyFilter ,
67
- converter : defaultCopyConverter
68
- } )
69
-
70
- const tempEditor = createPlateEditor ( {
71
- plugins : getPlugins (
72
- createPlateUI ( {
73
- [ ELEMENT_TAG ] : CopyTag as any
74
- } ) ,
75
- {
76
- exclude : { dnd : true }
77
- }
78
- )
79
- } )
80
-
81
- html = serializeHtml ( tempEditor , {
82
- nodes : convertedContent
83
- } )
84
- } catch ( err ) {
85
- mog ( 'Something went wrong' , { err } )
86
- }
87
-
88
- //Copying both the html and text in clipboard
89
- const textBlob = new Blob ( [ text ] , { type : 'text/plain' } )
90
- const htmlBlob = new Blob ( [ html ] , { type : 'text/html' } )
91
- const data = [ new ClipboardItem ( { [ 'text/plain' ] : textBlob , [ 'text/html' ] : htmlBlob } ) ]
92
-
93
- await navigator . clipboard . write ( data )
94
-
95
- toast . success ( 'Snippet copied to clipboard!' )
96
- }
97
-
98
- // This functions provides the 'to be' range and text content
99
- // Needed because keydown event happens before there is a selection or content change
100
- function getUpcomingData ( selection : Selection ) {
101
- const ogRange = selection . getRangeAt ( 0 )
102
-
103
- // Shifitng both start and end offset to simulate backwards caret movement
104
- const range = ogRange . cloneRange ( )
105
- range . setStart ( ogRange . startContainer , ogRange . startOffset - 1 )
106
- range . setEnd ( ogRange . endContainer , ogRange . endOffset - 1 )
107
-
108
- // delete last character of current content
109
- const text = selection . anchorNode . textContent . slice ( 0 , - 1 )
110
-
111
- return { range, text }
112
- }
113
-
114
- function simulateOnChange ( ) {
115
- const inputEvent = new InputEvent ( 'input' , {
116
- bubbles : true ,
117
- cancelable : false
118
- } )
119
-
120
- const changeEvent = new Event ( 'change' , {
121
- bubbles : true ,
122
- cancelable : false
123
- } )
124
-
125
- document . activeElement . dispatchEvent ( inputEvent )
126
- document . activeElement . dispatchEvent ( changeEvent )
127
- }
128
-
129
51
// TODO: whether or not to enable dibba should be a user's preference
130
52
// we don't users to move away because they have doubts of us forcing a 'keylogger' on them
131
53
export default function Dibba ( ) {
0 commit comments