(editor: Editor, path: Path, file: File | string)
| 108 | } |
| 109 | |
| 110 | export const uploadImage = (editor: Editor, path: Path, file: File | string) => { |
| 111 | const options = getOptions(editor) |
| 112 | const promise = new Promise<void>(resolve => { |
| 113 | const pathRef = Editor.pathRef(editor, path) |
| 114 | |
| 115 | const { onUpload = defaultUpload } = options |
| 116 | onUpload(file, ({ percentage }) => { |
| 117 | const path = pathRef.current |
| 118 | if (path) setPercentage(editor, path, percentage) |
| 119 | }) |
| 120 | .then(url => { |
| 121 | const path = pathRef.current |
| 122 | if (path) Transforms.setNodes<Image>(editor, { url, state: 'done' }, { at: path }) |
| 123 | }) |
| 124 | .catch(err => { |
| 125 | const path = pathRef.current |
| 126 | if (path) |
| 127 | Transforms.setNodes<Image>( |
| 128 | editor, |
| 129 | { state: 'error', errorMessage: typeof err === 'string' ? err : err.message }, |
| 130 | { at: path }, |
| 131 | ) |
| 132 | }) |
| 133 | .finally(() => { |
| 134 | const path = pathRef.unref() |
| 135 | |
| 136 | if (path) setPercentage(editor, path, 100) |
| 137 | |
| 138 | resolve() |
| 139 | }) |
| 140 | }) |
| 141 | return promise |
| 142 | } |
| 143 | |
| 144 | export function rotateImgWithCanvas(image: HTMLImageElement, degrees: number): Promise<Blob> { |
| 145 | return new Promise((resolve, reject) => { |
no test coverage detected
searching dependent graphs…