mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-22 00:10:37 +00:00
UBERF-5743 Show editor toolbars on selection only (#4802)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
parent
5d54728777
commit
cfd20dee35
@ -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',
|
||||||
|
@ -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) => {
|
||||||
|
@ -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',
|
||||||
|
@ -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
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -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'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user