44
55import { v4 as uuidv4 } from "uuid" ;
66import {
7- WeaveCopyPastePasteMode ,
8- WEAVE_COPY_PASTE_PASTE_MODES ,
97 WeaveContextMenuPlugin ,
108 WeaveCopyPasteNodesPlugin ,
119 WeaveExportNodesActionParams ,
1210 WeaveStageContextMenuPluginOnNodeContextMenuEvent ,
1311} from "@inditextech/weave-sdk" ;
12+ import { Vector2d } from "konva/lib/types" ;
1413import { WeaveSelection } from "@inditextech/weave-types" ;
1514import { useCollaborationRoom } from "@/store/store" ;
1615import React from "react" ;
@@ -38,21 +37,6 @@ import { useMutation } from "@tanstack/react-query";
3837import { postRemoveBackground } from "@/api/post-remove-background" ;
3938import { useIACapabilities } from "@/store/ia" ;
4039
41- const EXTERNAL_PASTE_TYPES = [ "image/png" , "image/jpeg" ] ;
42-
43- const canHandleExternalPaste = async ( items : ClipboardItems ) => {
44- let canHandleExternal = false ;
45- for ( const type of EXTERNAL_PASTE_TYPES ) {
46- for ( const item of items ) {
47- if ( item . types . includes ( type ) ) {
48- canHandleExternal = true ;
49- break ;
50- }
51- }
52- }
53- return Promise . resolve ( canHandleExternal ) ;
54- } ;
55-
5640function useContextMenu ( ) {
5741 const instance = useWeave ( ( state ) => state . instance ) ;
5842
@@ -110,17 +94,16 @@ function useContextMenu() {
11094 canUnGroup,
11195 nodes,
11296 canGroup,
97+ clickPoint,
11398 } : {
11499 actActionActive : string | undefined ;
115100 canUnGroup : boolean ;
116101 canGroup : boolean ;
117102 nodes : WeaveSelection [ ] ;
103+ clickPoint : Vector2d ;
118104 } ) : Promise < ContextMenuOption [ ] > => {
119105 if ( ! instance ) return [ ] ;
120106
121- const copyPasteNodesPlugin =
122- instance . getPlugin < WeaveCopyPasteNodesPlugin > ( "copyPasteNodes" ) ;
123-
124107 const options : ContextMenuOption [ ] = [ ] ;
125108
126109 const singleLocked =
@@ -291,45 +274,45 @@ function useContextMenu() {
291274 }
292275 }
293276
294- const pastMode = await copyPasteNodesPlugin ?. getAvailablePasteMode (
295- canHandleExternalPaste
296- ) ;
277+ // const pastMode = await copyPasteNodesPlugin?.getAvailablePasteMode(
278+ // canHandleExternalPaste
279+ // );
297280
298281 // PASTE
299- if (
300- pastMode &&
301- (
302- [
303- WEAVE_COPY_PASTE_PASTE_MODES . INTERNAL ,
304- WEAVE_COPY_PASTE_PASTE_MODES . EXTERNAL ,
305- ] as WeaveCopyPastePasteMode [ ]
306- ) . includes ( pastMode )
307- )
308- options . push ( {
309- id : "paste" ,
310- type : "button" ,
311- label : (
312- < div className = "w-full flex justify-between items-center" >
313- < div > Paste</ div >
314- < ShortcutElement
315- shortcuts = { {
316- [ SYSTEM_OS . MAC ] : "⌘ P" ,
317- [ SYSTEM_OS . OTHER ] : "Ctrl P" ,
318- } }
319- />
320- </ div >
321- ) ,
322- icon : < ClipboardPaste size = { 16 } /> ,
323- disabled : ! [ "selectionTool" ] . includes ( actActionActive ?? "" ) ,
324- onClick : async ( ) => {
325- const weaveCopyPasteNodesPlugin =
326- instance . getPlugin < WeaveCopyPasteNodesPlugin > ( "copyPasteNodes" ) ;
327- if ( weaveCopyPasteNodesPlugin ) {
328- await weaveCopyPasteNodesPlugin . paste ( ) ;
329- setContextMenuShow ( false ) ;
330- }
331- } ,
332- } ) ;
282+ // if (
283+ // pastMode &&
284+ // (
285+ // [
286+ // WEAVE_COPY_PASTE_PASTE_MODES.INTERNAL,
287+ // WEAVE_COPY_PASTE_PASTE_MODES.EXTERNAL,
288+ // ] as WeaveCopyPastePasteMode[]
289+ // ).includes(pastMode)
290+ // )
291+ options . push ( {
292+ id : "paste" ,
293+ type : "button" ,
294+ label : (
295+ < div className = "w-full flex justify-between items-center" >
296+ < div > Paste here </ div >
297+ < ShortcutElement
298+ shortcuts = { {
299+ [ SYSTEM_OS . MAC ] : "⌘ P" ,
300+ [ SYSTEM_OS . OTHER ] : "Ctrl P" ,
301+ } }
302+ />
303+ </ div >
304+ ) ,
305+ icon : < ClipboardPaste size = { 16 } /> ,
306+ disabled : ! [ "selectionTool" ] . includes ( actActionActive ?? "" ) ,
307+ onClick : async ( ) => {
308+ const weaveCopyPasteNodesPlugin =
309+ instance . getPlugin < WeaveCopyPasteNodesPlugin > ( "copyPasteNodes" ) ;
310+ if ( weaveCopyPasteNodesPlugin ) {
311+ await weaveCopyPasteNodesPlugin . paste ( clickPoint ) ;
312+ setContextMenuShow ( false ) ;
313+ }
314+ } ,
315+ } ) ;
333316 if ( ! singleLocked && nodes . length > 0 ) {
334317 // SEPARATOR
335318 options . push ( {
@@ -598,7 +581,8 @@ function useContextMenu() {
598581 const onNodeContextMenuHandler = React . useCallback (
599582 async ( {
600583 selection,
601- point,
584+ contextMenuPoint,
585+ clickPoint,
602586 visible,
603587 } : WeaveStageContextMenuPluginOnNodeContextMenuEvent ) => {
604588 if ( ! instance ) return ;
@@ -616,11 +600,12 @@ function useContextMenu() {
616600 canUnGroup,
617601 nodes : selection ,
618602 canGroup,
603+ clickPoint,
619604 } ) ;
620605
621606 if ( contextMenu . length > 0 ) {
622607 setContextMenuShow ( visible ) ;
623- setContextMenuPosition ( point ) ;
608+ setContextMenuPosition ( contextMenuPoint ) ;
624609 setContextMenuOptions ( contextMenu ) ;
625610 } else {
626611 const contextMenuPlugin =
0 commit comments