File tree Expand file tree Collapse file tree 5 files changed +30
-17
lines changed
apps/builder/app/shared/copy-paste Expand file tree Collapse file tree 5 files changed +30
-17
lines changed Original file line number Diff line number Diff line change 5
5
} from "../nano-states" ;
6
6
import { instanceText , instanceJson } from "./plugin-instance" ;
7
7
import { html } from "./plugin-html" ;
8
- import * as markdown from "./plugin-markdown" ;
9
- import * as webflow from "./plugin-webflow/plugin-webflow" ;
8
+ import { markdown } from "./plugin-markdown" ;
9
+ import { webflow } from "./plugin-webflow/plugin-webflow" ;
10
10
import { builderApi } from "../builder-api" ;
11
11
12
12
const isTextEditing = ( event : ClipboardEvent ) => {
@@ -64,6 +64,7 @@ const validateClipboardEvent = (event: ClipboardEvent) => {
64
64
} ;
65
65
66
66
export type Plugin = {
67
+ name : string ;
67
68
mimeType : string ;
68
69
onCopy ?: ( ) => undefined | string ;
69
70
onCut ?: ( ) => undefined | string ;
@@ -109,7 +110,7 @@ const initPlugins = ({
109
110
}
110
111
} ;
111
112
112
- const handlePaste = ( event : ClipboardEvent ) => {
113
+ const handlePaste = async ( event : ClipboardEvent ) => {
113
114
if ( validateClipboardEvent ( event ) === false ) {
114
115
return ;
115
116
}
@@ -118,7 +119,7 @@ const initPlugins = ({
118
119
// this shouldn't matter, but just in case
119
120
event . preventDefault ( ) ;
120
121
const data = event . clipboardData ?. getData ( mimeType ) . trim ( ) ;
121
- if ( data && onPaste ?.( data ) ) {
122
+ if ( data && ( await onPaste ?.( data ) ) ) {
122
123
break ;
123
124
}
124
125
}
Original file line number Diff line number Diff line change @@ -4,10 +4,12 @@ import { denormalizeSrcProps } from "./asset-upload";
4
4
import type { Plugin } from "./init-copy-paste" ;
5
5
6
6
export const html : Plugin = {
7
+ name : "html" ,
7
8
mimeType : "text/plain" ,
8
9
onPaste : async ( html : string ) => {
9
10
let fragment = generateFragmentFromHtml ( html ) ;
10
11
fragment = await denormalizeSrcProps ( fragment ) ;
11
- return insertWebstudioFragmentAt ( fragment ) ;
12
+ const result = insertWebstudioFragmentAt ( fragment ) ;
13
+ return result ;
12
14
} ,
13
15
} ;
Original file line number Diff line number Diff line change @@ -225,13 +225,15 @@ const onCut = () => {
225
225
} ;
226
226
227
227
export const instanceText : Plugin = {
228
+ name : "instance-text" ,
228
229
mimeType : "text/plain" ,
229
230
onCopy,
230
231
onCut,
231
232
onPaste,
232
233
} ;
233
234
234
235
export const instanceJson : Plugin = {
236
+ name : "instance-json" ,
235
237
mimeType : "application/json" ,
236
238
onPaste,
237
239
} ;
Original file line number Diff line number Diff line change @@ -3,8 +3,7 @@ import { micromark } from "micromark";
3
3
import { insertWebstudioFragmentAt } from "../instance-utils" ;
4
4
import { denormalizeSrcProps } from "./asset-upload" ;
5
5
import { generateFragmentFromHtml } from "../html" ;
6
-
7
- export const mimeType = "text/plain" ;
6
+ import type { Plugin } from "./init-copy-paste" ;
8
7
9
8
const parse = ( clipboardData : string ) => {
10
9
const html = micromark ( clipboardData , "utf-8" , {
@@ -23,13 +22,17 @@ const parse = (clipboardData: string) => {
23
22
return fragment ;
24
23
} ;
25
24
26
- export const onPaste = async ( clipboardData : string ) => {
27
- let fragment = parse ( clipboardData ) ;
28
- if ( fragment === undefined ) {
29
- return false ;
30
- }
31
- fragment = await denormalizeSrcProps ( fragment ) ;
32
- return insertWebstudioFragmentAt ( fragment ) ;
25
+ export const markdown : Plugin = {
26
+ name : "markdown" ,
27
+ mimeType : "text/plain" ,
28
+ onPaste : async ( clipboardData : string ) => {
29
+ let fragment = parse ( clipboardData ) ;
30
+ if ( fragment === undefined ) {
31
+ return false ;
32
+ }
33
+ fragment = await denormalizeSrcProps ( fragment ) ;
34
+ return insertWebstudioFragmentAt ( fragment ) ;
35
+ } ,
33
36
} ;
34
37
35
38
export const __testing__ = {
Original file line number Diff line number Diff line change @@ -19,11 +19,10 @@ import { builderApi } from "~/shared/builder-api";
19
19
import { denormalizeSrcProps } from "../asset-upload" ;
20
20
import { nanoHash } from "~/shared/nano-hash" ;
21
21
import { findAvailableVariables } from "~/shared/data-variables" ;
22
+ import type { Plugin } from "../init-copy-paste" ;
22
23
23
24
const { toast } = builderApi ;
24
25
25
- export const mimeType = "application/json" ;
26
-
27
26
const toWebstudioFragment = async ( wfData : WfData ) => {
28
27
const fragment : WebstudioFragment = {
29
28
children : [ ] ,
@@ -165,7 +164,7 @@ const parse = (clipboardData: string) => {
165
164
console . error ( result . error . message ) ;
166
165
} ;
167
166
168
- export const onPaste = async ( clipboardData : string ) => {
167
+ const onPaste = async ( clipboardData : string ) => {
169
168
const project = $project . get ( ) ;
170
169
const wfData = parse ( clipboardData ) ;
171
170
if ( wfData === undefined || project === undefined ) {
@@ -211,6 +210,12 @@ export const onPaste = async (clipboardData: string) => {
211
210
return true ;
212
211
} ;
213
212
213
+ export const webflow : Plugin = {
214
+ name : "webflow" ,
215
+ mimeType : "application/json" ,
216
+ onPaste,
217
+ } ;
218
+
214
219
export const __testing__ = {
215
220
toWebstudioFragment,
216
221
} ;
You can’t perform that action at this time.
0 commit comments