MCPcopy Create free account
hub / github.com/editablejs/editable / uploadImage

Function uploadImage

packages/plugins/image/src/utils.ts:110–142  ·  view source on GitHub ↗
(editor: Editor, path: Path, file: File | string)

Source from the content-addressed store, hash-verified

108}
109
110export 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
144export function rotateImgWithCanvas(image: HTMLImageElement, degrees: number): Promise<Blob> {
145 return new Promise((resolve, reject) => {

Callers 3

insertImagesFunction · 0.90
withImageFunction · 0.90
image.tsxFile · 0.90

Calls 2

getOptionsFunction · 0.90
setPercentageFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…