This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 589
feat: Attachment of Files to Documents using S3. #603
Open
FeralMib
wants to merge
3
commits into
outline:main
Choose a base branch
from
FeralMib:file-upload
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { ToastType } from "../types"; | ||
|
||
|
||
// function findPlaceholderLink(doc, href) { | ||
// let result; | ||
|
||
// function findLinks(node, pos = 0) { | ||
// // get text nodes | ||
// if (node.type.name === "text") { | ||
// // get marks for text nodes | ||
// node.marks.forEach(mark => { | ||
// // any of the marks links? | ||
// if (mark.type.name === "link") { | ||
// // any of the links to other docs? | ||
// if (mark.attrs.href === href) { | ||
// result = { node, pos }; | ||
// if (result) return false; | ||
// } | ||
// } | ||
// }); | ||
// } | ||
|
||
// if (!node.content.size) { | ||
// return; | ||
// } | ||
|
||
// node.descendants(findLinks); | ||
// } | ||
|
||
// findLinks(doc); | ||
// return result; | ||
// } | ||
|
||
const insertAllFiles = function(view, event, pos, files, options) { | ||
if (files.length === 0) return; | ||
|
||
const { | ||
dictionary, | ||
uploadFile, | ||
onFileUploadStart, | ||
onFileUploadStop, | ||
onShowToast, | ||
} = options; | ||
|
||
if (!uploadFile) { | ||
console.warn("uploadFile callback must be defined to handle file uploads."); | ||
return; | ||
} | ||
|
||
// okay, we have some dropped files and a handler – lets stop this | ||
// event going any further up the stack | ||
event.preventDefault(); | ||
|
||
// let the user know we're starting to process the files | ||
if (onFileUploadStart) onFileUploadStart(); | ||
|
||
// we'll use this to track of how many files have succeeded or failed | ||
let complete = 0; | ||
|
||
const { state } = view; | ||
const { from, to } = state.selection; | ||
|
||
console.log("state.selection: " + state.selection + "," + from + "," + to); | ||
|
||
// the user might have dropped multiple files at once, we need to loop | ||
for (const file of files) { | ||
|
||
// Insert a placeholder link | ||
var placeholder = `[${file.name} uploading...]` | ||
// const phref = `#uploading_${file.name}`; | ||
view.dispatch( | ||
view.state.tr | ||
.insertText(placeholder, from, to-1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1 is a bit strange here |
||
); | ||
// start uploading the file file to the server. Using "then" syntax | ||
// to allow all placeholders to be entered at once with the uploads | ||
// happening in the background in parallel. | ||
uploadFile(file) | ||
.then(src => { | ||
const title = file.name; | ||
const href = src; | ||
|
||
// const result = findPlaceholderLink(view.state.doc, phref); | ||
// console.log("placeholder: " + result + "," + result.pos + "," + result.node.nodeSize); | ||
// if (result) { | ||
// view.dispatch( | ||
// view.state.tr | ||
// .removeMark( | ||
// result.pos, | ||
// result.pos + result.node.nodeSize, | ||
// state.schema.marks.link | ||
// ) | ||
// ); | ||
// } | ||
|
||
view.dispatch( | ||
view.state.tr | ||
.delete(from, to + placeholder.length) | ||
.insertText(title, from, to) | ||
.addMark( | ||
from, | ||
to + title.length, | ||
state.schema.marks.link.create({ href }) | ||
) | ||
); | ||
}) | ||
.catch(error => { | ||
console.error(error); | ||
if (onShowToast) { | ||
onShowToast(dictionary.fileUploadError, ToastType.Error); | ||
} | ||
}) | ||
// eslint-disable-next-line no-loop-func | ||
.finally(() => { | ||
complete++; | ||
|
||
// once everything is done, let the user know | ||
if (complete === files.length) { | ||
if (onFileUploadStop) onFileUploadStop(); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
export default insertAllFiles; |
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ import { | |
TableIcon, | ||
TodoListIcon, | ||
ImageIcon, | ||
NotepadIcon, | ||
StarredIcon, | ||
WarningIcon, | ||
InfoIcon, | ||
|
@@ -115,6 +116,12 @@ export default function blockMenuItems( | |
icon: ImageIcon, | ||
keywords: "picture photo", | ||
}, | ||
{ | ||
name: "file", | ||
title: dictionary.file, | ||
icon: NotepadIcon, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd use the |
||
keywords: "doc pdf", | ||
}, | ||
{ | ||
name: "link", | ||
title: dictionary.link, | ||
|
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 |
---|---|---|
|
@@ -29,4 +29,4 @@ | |
"dist", | ||
"node_modules" | ||
] | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type of placeholder isn't sufficient as the text document can change while the file is uploading – in that case the text will be replaced incorrectly. Instead it should work like the image placeholder with a widget decoration that is then searched for again to find it's current position once the file upload is complete