Skip to content

Commit

Permalink
style(extension/bubble-menu): change delay option to updateDelay
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbch committed Nov 4, 2022
1 parent e889e10 commit 3d04941
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/api/extensions/bubble-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Type: `HTMLElement`

Default: `null`

### delay
### updateDelay
The `BubbleMenu` debounces the `update` method to allow the bubble menu to not be updated on every selection update. This can be controlled in milliseconds.
The BubbleMenuPlugin will come with a default delay of 250ms. This can be deactivated, by setting the delay to `0` which deactivates the debounce.

Expand Down
12 changes: 6 additions & 6 deletions packages/extension-bubble-menu/src/bubble-menu-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface BubbleMenuPluginProps {
editor: Editor,
element: HTMLElement,
tippyOptions?: Partial<Props>,
delay?: number,
updateDelay?: number,
shouldShow?: ((props: {
editor: Editor,
view: EditorView,
Expand Down Expand Up @@ -42,7 +42,7 @@ export class BubbleMenuView {

public tippyOptions?: Partial<Props>

public delay: number
public updateDelay: number

public shouldShow: Exclude<BubbleMenuPluginProps['shouldShow'], null> = ({
view,
Expand Down Expand Up @@ -83,13 +83,13 @@ export class BubbleMenuView {
element,
view,
tippyOptions = {},
delay = 250,
updateDelay = 250,
shouldShow,
}: BubbleMenuViewProps) {
this.editor = editor
this.element = element
this.view = view
this.delay = delay
this.updateDelay = updateDelay

if (shouldShow) {
this.shouldShow = shouldShow
Expand Down Expand Up @@ -169,8 +169,8 @@ export class BubbleMenuView {
const hasValidSelection = state.selection.$from.pos !== state.selection.$to.pos

if (hasValidSelection) {
if (this.delay > 0) {
debounce(this.updateHandler, this.delay)(view, oldState)
if (this.updateDelay > 0) {
debounce(this.updateHandler, this.updateDelay)(view, oldState)
} else {
this.updateHandler(view, oldState)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-bubble-menu/src/bubble-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const BubbleMenu = Extension.create<BubbleMenuOptions>({
element: null,
tippyOptions: {},
pluginKey: 'bubbleMenu',
delay: undefined,
updateDelay: undefined,
shouldShow: null,
}
},
Expand All @@ -30,7 +30,7 @@ export const BubbleMenu = Extension.create<BubbleMenuOptions>({
editor: this.editor,
element: this.options.element,
tippyOptions: this.options.tippyOptions,
delay: this.options.delay,
updateDelay: this.options.updateDelay,
shouldShow: this.options.shouldShow,
}),
]
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/BubbleMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
export type BubbleMenuProps = Omit<Optional<BubbleMenuPluginProps, 'pluginKey'>, 'element'> & {
className?: string;
children: React.ReactNode;
delay?: number;
updateDelay?: number;
};

export const BubbleMenu = (props: BubbleMenuProps) => {
Expand All @@ -22,11 +22,11 @@ export const BubbleMenu = (props: BubbleMenuProps) => {
}

const {
pluginKey = 'bubbleMenu', editor, tippyOptions = {}, delay, shouldShow = null,
pluginKey = 'bubbleMenu', editor, tippyOptions = {}, updateDelay, shouldShow = null,
} = props

const plugin = BubbleMenuPlugin({
delay,
updateDelay,
editor,
element,
pluginKey,
Expand Down
8 changes: 4 additions & 4 deletions packages/vue-2/src/BubbleMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface BubbleMenuInterface extends Vue {
pluginKey: BubbleMenuPluginProps['pluginKey'],
editor: BubbleMenuPluginProps['editor'],
tippyOptions: BubbleMenuPluginProps['tippyOptions'],
delay: BubbleMenuPluginProps['delay'],
updateDelay: BubbleMenuPluginProps['updateDelay'],
shouldShow: BubbleMenuPluginProps['shouldShow'],
}

Expand All @@ -23,8 +23,8 @@ export const BubbleMenu: Component = {
required: true,
},

delay: {
type: Number as PropType<BubbleMenuPluginProps['delay']>,
updateDelay: {
type: Number as PropType<BubbleMenuPluginProps['updateDelay']>,
},

tippyOptions: {
Expand All @@ -48,7 +48,7 @@ export const BubbleMenu: Component = {

this.$nextTick(() => {
editor.registerPlugin(BubbleMenuPlugin({
delay: this.delay,
updateDelay: this.updateDelay,
editor,
element: this.$el as HTMLElement,
pluginKey: this.pluginKey,
Expand Down
8 changes: 4 additions & 4 deletions packages/vue-3/src/BubbleMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export const BubbleMenu = defineComponent({
required: true,
},

delay: {
type: Number as PropType<BubbleMenuPluginProps['delay']>,
updateDelay: {
type: Number as PropType<BubbleMenuPluginProps['updateDelay']>,
default: undefined,
},

Expand All @@ -45,15 +45,15 @@ export const BubbleMenu = defineComponent({

onMounted(() => {
const {
delay,
updateDelay,
editor,
pluginKey,
shouldShow,
tippyOptions,
} = props

editor.registerPlugin(BubbleMenuPlugin({
delay,
updateDelay,
editor,
element: root.value as HTMLElement,
pluginKey,
Expand Down

0 comments on commit 3d04941

Please sign in to comment.