-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(files): create suggestions bar #6856
Open
JuliaKirschenheuter
wants to merge
1
commit into
main
Choose a base branch
from
enh/6817-Suggestions-on-smart-picking
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
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 |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<template> | ||
<div class="container-suggestions"> | ||
<NcButton ref="linkFileOrFolder" | ||
type="tertiary" | ||
size="normal" | ||
@click="linkFile"> | ||
<template #icon> | ||
<Document :size="20" /> | ||
</template> | ||
{{ t('text', 'Link to file or folder') }} | ||
</NcButton> | ||
|
||
<NcButton type="tertiary" | ||
size="normal" | ||
@click="$callChooseLocalAttachment"> | ||
<template #icon> | ||
<Document :size="20" /> | ||
</template> | ||
{{ t('text', 'Upload') }} | ||
</NcButton> | ||
|
||
<NcButton type="tertiary" | ||
size="normal" | ||
@click="insertTable"> | ||
<template #icon> | ||
<Table :size="20" /> | ||
</template> | ||
{{ t('text', 'Insert Table') }} | ||
</NcButton> | ||
|
||
<NcButton type="tertiary" | ||
size="normal" | ||
@click="linkPicker"> | ||
<template #icon> | ||
<Shape :size="20" /> | ||
</template> | ||
{{ t('text', 'Smart Picker') }} | ||
</NcButton> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { NcButton } from '@nextcloud/vue' | ||
import { Document, Table, Shape } from './icons.js' | ||
import { useActionChooseLocalAttachmentMixin } from './Editor/MediaHandler.provider.js' | ||
import { getLinkWithPicker } from '@nextcloud/vue/dist/Components/NcRichText.js' | ||
import { useEditorMixin, useFileMixin } from './Editor.provider.js' | ||
import { generateUrl } from '@nextcloud/router' | ||
import { buildFilePicker } from '../helpers/filePicker.js' | ||
|
||
export default { | ||
name: 'SuggestionsBar', | ||
components: { | ||
Table, | ||
Document, | ||
NcButton, | ||
Shape, | ||
}, | ||
mixins: [ | ||
useActionChooseLocalAttachmentMixin, | ||
useEditorMixin, | ||
useFileMixin, | ||
], | ||
|
||
data: () => { | ||
return { | ||
startPath: null, | ||
} | ||
}, | ||
|
||
computed: { | ||
relativePath() { | ||
return this.$file?.relativePath ?? '/' | ||
}, | ||
}, | ||
|
||
methods: { | ||
/** | ||
* Open smart picker dialog | ||
* Triggered by the "Smart Picker" button | ||
*/ | ||
linkPicker() { | ||
getLinkWithPicker(null, true) | ||
.then(link => { | ||
const chain = this.$editor.chain() | ||
if (this.$editor.view.state?.selection.empty) { | ||
chain.focus().insertPreview(link).run() | ||
} else { | ||
chain.setLink({ href: link }).focus().run() | ||
} | ||
}) | ||
.catch(error => { | ||
console.error('Smart picker promise rejected', error) | ||
}) | ||
}, | ||
|
||
/** | ||
* Insert table | ||
* Triggered by the "Insert table" button | ||
*/ | ||
insertTable() { | ||
this.$editor.chain().focus().insertTable()?.run() | ||
}, | ||
|
||
/** | ||
* Open dialog and ask user which file to link to | ||
* Triggered by the "link to file or folder" button | ||
*/ | ||
linkFile() { | ||
if (this.startPath === null) { | ||
this.startPath = this.relativePath.split('/').slice(0, -1).join('/') | ||
} | ||
|
||
const filePicker = buildFilePicker(this.startPath) | ||
|
||
filePicker.pick() | ||
.then((file) => { | ||
const client = OC.Files.getClient() | ||
client.getFileInfo(file).then((_status, fileInfo) => { | ||
const url = new URL(generateUrl(`/f/${fileInfo.id}`), window.origin) | ||
this.setLink(url.href, fileInfo.name) | ||
this.startPath = fileInfo.path + (fileInfo.type === 'dir' ? `/${fileInfo.name}/` : '') | ||
}) | ||
}) | ||
.catch(() => { | ||
// do not close menu but keep focus | ||
this.$refs.linkFileOrFolder.$el.focus() | ||
}) | ||
}, | ||
|
||
/** | ||
* Save user entered URL as a link markup | ||
* Triggered when the user submits the ActionInput | ||
* | ||
* @param {string} url href attribute of the link | ||
* @param {string} text Text part of the link | ||
*/ | ||
setLink(url, text) { | ||
this.$editor.chain().setOrInsertLink(url, text).focus().run() | ||
}, | ||
}, | ||
|
||
} | ||
|
||
</script> | ||
|
||
<style scoped lang="scss"> | ||
|
||
.container-suggestions { | ||
display: flex; | ||
justify-content: center; | ||
align-items: flex-end; | ||
align-content: flex-end; | ||
position: sticky; | ||
} | ||
</style> |
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,15 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import { FilePickerType, getFilePickerBuilder } from '@nextcloud/dialogs' | ||
|
||
export const buildFilePicker = (startPath) => { | ||
return getFilePickerBuilder(t('text', 'Select file or folder to link to')) | ||
.startAt(startPath) | ||
.allowDirectories(true) | ||
.setMultiSelect(false) | ||
.setType(FilePickerType.Choose) | ||
.build() | ||
} | ||
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
Oops, something went wrong.
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.
What is the background for that fixed number of 4? I'd assume we can also check the text content length directly? Or the resulting markdown length?
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.
text content length is checked by the count of
nodeSize
fromeditor.state.doc
, checked with MaxThere 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.
Yes, that is what the code does. I would still be curious about the reasoning, this is not obvious. I assume there is one ...