|
|
|
@ -75,8 +75,15 @@ export const ClipboardAndDropHandler = Extension.create<ClipboardAndDropHandlerO |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (item.kind === 'string' && item.type === 'text/plain') { |
|
|
|
} else if (item.kind === 'string' && item.type === 'text/plain') { |
|
|
|
item.getAsString((text) => { |
|
|
|
item.getAsString((text) => { |
|
|
|
const textNode = view.state.schema.text(text) |
|
|
|
const { schema } = view.state |
|
|
|
const tr = view.state.tr.replaceSelectionWith(textNode) |
|
|
|
const parts = text.split('\n') |
|
|
|
|
|
|
|
const nodes = [] |
|
|
|
|
|
|
|
for (let i = 0; i < parts.length; i++) { |
|
|
|
|
|
|
|
if (i > 0) nodes.push(schema.nodes.hardBreak.create()) |
|
|
|
|
|
|
|
if (parts[i]) nodes.push(schema.text(parts[i])) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const fragment = schema.nodes.paragraph.create(null, nodes) |
|
|
|
|
|
|
|
const tr = view.state.tr.replaceSelectionWith(fragment) |
|
|
|
view.dispatch(tr) |
|
|
|
view.dispatch(tr) |
|
|
|
}) |
|
|
|
}) |
|
|
|
handled = true |
|
|
|
handled = true |
|
|
|
@ -99,8 +106,10 @@ async function uploadFile(view: EditorView, file: File, options: ClipboardAndDro |
|
|
|
options.onUploadStart?.(file) |
|
|
|
options.onUploadStart?.(file) |
|
|
|
|
|
|
|
|
|
|
|
const placeholder = `[Uploading "${name}"...]` |
|
|
|
const placeholder = `[Uploading "${name}"...]` |
|
|
|
const uploadingNode = view.state.schema.text(placeholder + '\n') |
|
|
|
const uploadingNode = view.state.schema.text(placeholder) |
|
|
|
const tr = view.state.tr.replaceSelectionWith(uploadingNode) |
|
|
|
const hardBreakNode = view.state.schema.nodes.hardBreak.create() |
|
|
|
|
|
|
|
let tr = view.state.tr.replaceSelectionWith(uploadingNode) |
|
|
|
|
|
|
|
tr = tr.insert(tr.selection.from, hardBreakNode) |
|
|
|
view.dispatch(tr) |
|
|
|
view.dispatch(tr) |
|
|
|
|
|
|
|
|
|
|
|
mediaUpload |
|
|
|
mediaUpload |
|
|
|
|