-
Notifications
You must be signed in to change notification settings - Fork 111
fix(FloatingButtons): group smartpicker button and drag handle together #7818
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
Merged
Merged
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 hidden or 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 hidden or 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,112 @@ | ||
| <!-- | ||
| - SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| - SPDX-License-Identifier: AGPL-3.0-or-later | ||
| --> | ||
|
|
||
| <template> | ||
| <DragHandle | ||
| :editor="editor" | ||
| class="floating-buttons" | ||
| :class="{ heading: isHeadingNode }" | ||
| :on-node-change="onNodeChange"> | ||
| <NcButton | ||
| type="tertiary-no-background" | ||
| size="small" | ||
| :title="t('text', 'Insert below')" | ||
| @click="onOpenSmartPicker"> | ||
| <template #icon> | ||
| <PlusIcon :size="16" /> | ||
| </template> | ||
| </NcButton> | ||
| <NcButton | ||
| type="tertiary-no-background" | ||
| size="small" | ||
| class="drag-button" | ||
| :title="t('text', 'Click for options, hold to drag')"> | ||
| <template #icon> | ||
| <DragVerticalIcon :size="16" /> | ||
| </template> | ||
| </NcButton> | ||
| </DragHandle> | ||
| </template> | ||
|
|
||
| <script> | ||
| import { t } from '@nextcloud/l10n' | ||
| import NcButton from '@nextcloud/vue/components/NcButton' | ||
| import { DragHandle } from '@tiptap/extension-drag-handle-vue-2' | ||
| import DragVerticalIcon from 'vue-material-design-icons/DragVertical.vue' | ||
| import PlusIcon from 'vue-material-design-icons/Plus.vue' | ||
| import { useEditor } from '../../composables/useEditor.ts' | ||
|
|
||
| export default { | ||
| name: 'FloatingButtons', | ||
|
|
||
| components: { | ||
| DragHandle, | ||
| DragVerticalIcon, | ||
| NcButton, | ||
| PlusIcon, | ||
| }, | ||
|
|
||
| setup() { | ||
| const { editor } = useEditor() | ||
| return { editor } | ||
| }, | ||
|
|
||
| data() { | ||
| return { | ||
| node: null, | ||
| pos: -1, | ||
| } | ||
| }, | ||
|
|
||
| computed: { | ||
| isHeadingNode() { | ||
| return this.node?.type === this.editor.schema.nodes.heading | ||
| }, | ||
| }, | ||
|
|
||
| methods: { | ||
| onNodeChange({ node, pos }) { | ||
| this.node = node | ||
| this.pos = pos | ||
| }, | ||
| onOpenSmartPicker() { | ||
| if (!this.node || this.pos === -1) { | ||
| return | ||
| } | ||
|
|
||
| // Node has no children or just text children and no text content | ||
| const { schema } = this.editor | ||
| const emptyNode = | ||
| this.node.textContent.trim() === '' | ||
| && (this.node.children.length === 0 | ||
| || this.node.children.every((n) => n.type === schema.nodes.text)) | ||
|
|
||
| // Insert at the end of the node | ||
| const pos = emptyNode ? this.pos + 1 : this.pos + this.node.nodeSize | ||
| this.editor.chain().insertContentAt(pos, '/').focus().run() | ||
| }, | ||
| t, | ||
| }, | ||
| } | ||
| </script> | ||
|
|
||
| <style scoped lang="scss"> | ||
| .floating-buttons { | ||
| display: flex; | ||
|
|
||
| &.heading { | ||
| margin-right: 16px; | ||
| } | ||
| } | ||
|
|
||
| .drag-button { | ||
| cursor: grab; | ||
|
|
||
| :deep(span), | ||
| :deep(svg) { | ||
| cursor: grab !important; | ||
| } | ||
| } | ||
| </style> | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Seems a bit weird to have the plus button wrapped in the drag handle itself. I guess that is a bit of a shortcut to have a more straight forward implementation. Only "issue" i could see is that you can use the plus button as a drag handle as well. Not a blocker for me though
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.
Hehe, first I thought the same. Then I realized that it's exactly what the "notion style" Tiptap example does it as well 🤪
I didn't see a good reason to not do it and actually it results in cleaner code, as I can reuse the
nodeandposreturned by the drag handler callback for the plus button action.