-
-
Notifications
You must be signed in to change notification settings - Fork 711
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a5b009
commit 0cd4eeb
Showing
10 changed files
with
188 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
export interface DragItemNode { | ||
export type DragItemNode = ElementDragItemNode | FileDragItemNode; | ||
|
||
export interface ElementDragItemNode { | ||
/** Required to identify the node. */ | ||
id: string; | ||
[key: string]: unknown; | ||
} | ||
|
||
export interface FileDragItemNode { | ||
dataTransfer: DataTransfer[]; | ||
files: FileList; | ||
items: DataTransferItemList; | ||
} | ||
|
||
export type DropLineDirection = '' | 'bottom' | 'top'; | ||
|
||
export type DropDirection = 'bottom' | 'top' | undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/media/src/lib/image/transforms/insertImageFromFiles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { InsertNodesOptions, SlateEditor } from '@udecode/plate-common'; | ||
|
||
import { ImagePlugin } from '../../../react'; | ||
import { insertImage } from './insertImage'; | ||
|
||
export const insertImageFromFiles = ( | ||
editor: SlateEditor, | ||
files: FileList, | ||
options: InsertNodesOptions = {} | ||
) => { | ||
for (const file of files) { | ||
const reader = new FileReader(); | ||
const [mime] = file.type.split('/'); | ||
|
||
if (mime === 'image') { | ||
reader.addEventListener('load', async () => { | ||
if (!reader.result) { | ||
return; | ||
} | ||
|
||
const uploadImage = editor.getOptions(ImagePlugin).uploadImage; | ||
|
||
const uploadedUrl = uploadImage | ||
? await uploadImage(reader.result) | ||
: reader.result; | ||
|
||
insertImage(editor, uploadedUrl, options); | ||
}); | ||
|
||
reader.readAsDataURL(file); | ||
} | ||
} | ||
}; |
Oops, something went wrong.