Browse Source

feat: dnd multiple shapes

Peng Xiao 3 years ago
parent
commit
c0620a7aa2

+ 15 - 1
tldraw/apps/tldraw-logseq/src/hooks/usePaste.ts

@@ -218,7 +218,21 @@ export function usePaste() {
         const rawText = dataTransfer.getData('block-uuid')
         if (rawText) {
           const text = rawText.trim()
-          return tryCreateShapeHelper(tryCreateLogseqPortalShapesFromString)(`((${text}))`)
+          const allSelectedBlocks = window.logseq?.api?.get_selected_blocks?.()
+          const blockUUIDs =
+            allSelectedBlocks && allSelectedBlocks?.length > 1
+              ? allSelectedBlocks.map(b => b.uuid)
+              : [text]
+          const tasks = blockUUIDs.map(uuid => tryCreateLogseqPortalShapesFromString(`((${uuid}))`))
+          const newShapes = (await Promise.all(tasks)).flat().filter(isNonNullable)
+          return newShapes.map((s, idx) => {
+            // if there are multiple shapes, shift them to the right
+            return {
+              ...s,
+              // TODO: use better alignment?
+              point: [point[0] + (LogseqPortalShape.defaultProps.size[0] + 16) * idx, point[1]],
+            }
+          })
         }
         return null
       }

+ 1 - 0
tldraw/apps/tldraw-logseq/src/index.ts

@@ -10,6 +10,7 @@ declare global {
         edit_block?: (uuid: string) => void
         set_blocks_id?: (uuids: string[]) => void
         open_external_link?: (url: string) => void
+        get_selected_blocks?: () => { uuid: string }[]
       }
     }
   }