UBERF-5743 Show editor toolbars on selection only (#4802)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2024-02-28 15:16:48 +07:00 committed by GitHub
parent 5d54728777
commit cfd20dee35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 8 additions and 47 deletions

View File

@ -229,8 +229,7 @@
InlineStyleToolbarExtension.configure({ InlineStyleToolbarExtension.configure({
tippyOptions, tippyOptions,
element: textToolbarElement, element: textToolbarElement,
isSupported: () => showTextStyleToolbar, isSupported: () => showTextStyleToolbar
isSelectionOnly: () => false
}), }),
InlinePopupExtension.configure({ InlinePopupExtension.configure({
pluginKey: 'show-image-actions-popup', pluginKey: 'show-image-actions-popup',

View File

@ -95,6 +95,7 @@
textEditor?.focus() textEditor?.focus()
} }
} }
let actions: RefAction[] = defaultRefActions.concat(...extraActions).sort((a, b) => a.order - b.order) let actions: RefAction[] = defaultRefActions.concat(...extraActions).sort((a, b) => a.order - b.order)
void getModelRefActions().then((modelActions) => { void getModelRefActions().then((modelActions) => {

View File

@ -137,8 +137,7 @@
// you're trying to use TextEditor in long-living components that // you're trying to use TextEditor in long-living components that
// get updated, e.g. in QuestionCollectionItemEditor in Surveys // get updated, e.g. in QuestionCollectionItemEditor in Surveys
element: textToolbarElement, element: textToolbarElement,
isSupported: () => true, isSupported: () => true
isSelectionOnly: () => false
}), }),
InlinePopupExtension.configure({ InlinePopupExtension.configure({
pluginKey: 'show-image-actions-popup', pluginKey: 'show-image-actions-popup',

View File

@ -1,43 +1,15 @@
import { Extension, isTextSelection } from '@tiptap/core' import { Extension, isTextSelection } from '@tiptap/core'
import { type BubbleMenuOptions } from '@tiptap/extension-bubble-menu' import { type BubbleMenuOptions } from '@tiptap/extension-bubble-menu'
import { Plugin, PluginKey } from '@tiptap/pm/state' import { PluginKey } from '@tiptap/pm/state'
import { InlinePopupExtension } from './inlinePopup' import { InlinePopupExtension } from './inlinePopup'
export type InlineStyleToolbarOptions = BubbleMenuOptions & { export type InlineStyleToolbarOptions = BubbleMenuOptions & {
isSupported: () => boolean isSupported: () => boolean
isSelectionOnly?: () => boolean canShowWithoutSelection?: boolean
} }
export interface InlineStyleToolbarStorage { export const InlineStyleToolbarExtension = Extension.create<InlineStyleToolbarOptions>({
canShowWithoutSelection: boolean
}
export const InlineStyleToolbarExtension = Extension.create<InlineStyleToolbarOptions, InlineStyleToolbarStorage>({
pluginKey: new PluginKey('inline-style-toolbar'), pluginKey: new PluginKey('inline-style-toolbar'),
addProseMirrorPlugins () {
const storage = this.storage
const plugins = [
...(this.parent?.() ?? []),
new Plugin({
key: new PluginKey('inline-style-toolbar-click-plugin'),
props: {
handleClickOn (view, pos, node, nodePos, event, direct) {
if (direct) {
storage.canShowWithoutSelection = node.type.name !== 'image'
}
}
}
})
]
return plugins
},
addStorage () {
return {
canShowWithoutSelection: false
}
},
addExtensions () { addExtensions () {
const options: InlineStyleToolbarOptions = this.options const options: InlineStyleToolbarOptions = this.options
@ -80,18 +52,12 @@ export const InlineStyleToolbarExtension = Extension.create<InlineStyleToolbarOp
// So we check also for an empty text size. // So we check also for an empty text size.
const isEmptyTextBlock = doc.textBetween(from, to).length === 0 && textSelection const isEmptyTextBlock = doc.textBetween(from, to).length === 0 && textSelection
if (empty || isEmptyTextBlock) { if (empty || isEmptyTextBlock) {
return this.storage.canShowWithoutSelection return this.options.canShowWithoutSelection ?? false
} }
return textSelection return textSelection
} }
}) })
] ]
},
onSelectionUpdate () {
this.storage.canShowWithoutSelection = false
},
onUpdate () {
this.storage.canShowWithoutSelection = false
} }
}) })

View File

@ -60,11 +60,7 @@ export {
type NodeUuidStorage type NodeUuidStorage
} from './components/extension/nodeUuid' } from './components/extension/nodeUuid'
export { InlinePopupExtension } from './components/extension/inlinePopup' export { InlinePopupExtension } from './components/extension/inlinePopup'
export { export { InlineStyleToolbarExtension, type InlineStyleToolbarOptions } from './components/extension/inlineStyleToolbar'
InlineStyleToolbarExtension,
type InlineStyleToolbarOptions,
type InlineStyleToolbarStorage
} from './components/extension/inlineStyleToolbar'
export { ImageExtension, type ImageOptions } from './components/extension/imageExt' export { ImageExtension, type ImageOptions } from './components/extension/imageExt'
export { TodoItemExtension, TodoListExtension } from './components/extension/todo' export { TodoItemExtension, TodoListExtension } from './components/extension/todo'