useFileDrop.ts 566 B

12345678910111213
  1. import { fileToBase64, getSizeFromSrc, TLAsset, uniqueId } from '@tldraw/core'
  2. import type { TLReactCallbacks } from '@tldraw/react'
  3. import * as React from 'react'
  4. import type { Shape } from '~lib'
  5. import type { LogseqContextValue } from '~lib/logseq-context'
  6. import { usePaste } from './usePaste'
  7. export function useFileDrop(context: LogseqContextValue) {
  8. const handlePaste = usePaste(context)
  9. return React.useCallback<TLReactCallbacks<Shape>['onFileDrop']>(async (app, { files, point }) => {
  10. handlePaste(app, { point, shiftKey: false, files })
  11. }, [])
  12. }