Skip to content

Commit

Permalink
fix: rename key to pluginKey for menus
Browse files Browse the repository at this point in the history
  • Loading branch information
philippkuehn committed Aug 13, 2021
1 parent 8fd75bc commit 89d26f7
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 40 deletions.
12 changes: 6 additions & 6 deletions docs/src/docPages/api/extensions/bubble-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ yarn add @tiptap/extension-bubble-menu
| ------------ | -------------------- | -------------- | ----------------------------------------------------------------------- |
| element | `HTMLElement` | `null` | The DOM element that contains your menu. |
| tippyOptions | `Object` | `{}` | [Options for tippy.js](https://atomiks.github.io/tippyjs/v6/all-props/) |
| key | `string | PluginKey` | `'bubbleMenu'` | The key for the underlying ProseMirror plugin. |
| pluginKey | `string | PluginKey` | `'bubbleMenu'` | The key for the underlying ProseMirror plugin. |
| shouldShow | `(props) => boolean` | | Controls whether the menu should be shown or not. |

## Source code
Expand Down Expand Up @@ -60,7 +60,7 @@ BubbleMenu.configure({
```

### Multiple menus
Use multiple menus by setting an unique `key`.
Use multiple menus by setting an unique `pluginKey`.

```js
import { Editor } from '@tiptap/core'
Expand All @@ -69,11 +69,11 @@ import BubbleMenu from '@tiptap/extension-bubble-menu'
new Editor({
extensions: [
BubbleMenu.configure({
key: 'bubbleMenuOne',
pluginKey: 'bubbleMenuOne',
element: document.querySelector('.menu-one'),
}),
BubbleMenu.configure({
key: 'bubbleMenuTwo',
pluginKey: 'bubbleMenuTwo',
element: document.querySelector('.menu-two'),
}),
],
Expand All @@ -90,11 +90,11 @@ import { PluginKey } from 'prosemirror-state'
new Editor({
extensions: [
BubbleMenu.configure({
key: new PluginKey('bubbleMenuOne'),
pluginKey: new PluginKey('bubbleMenuOne'),
element: document.querySelector('.menu-one'),
}),
BubbleMenu.configure({
key: new PluginKey('bubbleMenuTwo'),
pluginKey: new PluginKey('bubbleMenuTwo'),
element: document.querySelector('.menu-two'),
}),
],
Expand Down
12 changes: 6 additions & 6 deletions docs/src/docPages/api/extensions/floating-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ yarn add @tiptap/extension-floating-menu
| ------------ | -------------------- | ---------------- | ----------------------------------------------------------------------- |
| element | `HTMLElement` | `null` | The DOM element of your menu. |
| tippyOptions | `Object` | `{}` | [Options for tippy.js](https://atomiks.github.io/tippyjs/v6/all-props/) |
| key | `string | PluginKey` | `'floatingMenu'` | The key for the underlying ProseMirror plugin. |
| pluginKey | `string | PluginKey` | `'floatingMenu'` | The key for the underlying ProseMirror plugin. |
| shouldShow | `(props) => boolean` | | Controls whether the menu should be shown or not. |

## Source code
Expand Down Expand Up @@ -56,7 +56,7 @@ FloatingMenu.configure({
```

### Multiple menus
Use multiple menus by setting an unique `key`.
Use multiple menus by setting an unique `pluginKey`.

```js
import { Editor } from '@tiptap/core'
Expand All @@ -65,11 +65,11 @@ import FloatingMenu from '@tiptap/extension-floating-menu'
new Editor({
extensions: [
FloatingMenu.configure({
key: 'floatingMenuOne',
pluginKey: 'floatingMenuOne',
element: document.querySelector('.menu-one'),
}),
FloatingMenu.configure({
key: 'floatingMenuTwo',
pluginKey: 'floatingMenuTwo',
element: document.querySelector('.menu-two'),
}),
],
Expand All @@ -86,11 +86,11 @@ import { PluginKey } from 'prosemirror-state'
new Editor({
extensions: [
FloatingMenu.configure({
key: new PluginKey('floatingMenuOne'),
pluginKey: new PluginKey('floatingMenuOne'),
element: document.querySelector('.menu-one'),
}),
FloatingMenu.configure({
key: new PluginKey('floatingMenuOne'),
pluginKey: new PluginKey('floatingMenuOne'),
element: document.querySelector('.menu-two'),
}),
],
Expand Down
8 changes: 4 additions & 4 deletions packages/extension-bubble-menu/src/bubble-menu-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EditorView } from 'prosemirror-view'
import tippy, { Instance, Props } from 'tippy.js'

export interface BubbleMenuPluginProps {
key: PluginKey | string,
pluginKey: PluginKey | string,
editor: Editor,
element: HTMLElement,
tippyOptions?: Partial<Props>,
Expand Down Expand Up @@ -191,9 +191,9 @@ export class BubbleMenuView {

export const BubbleMenuPlugin = (options: BubbleMenuPluginProps) => {
return new Plugin({
key: typeof options.key === 'string'
? new PluginKey(options.key)
: options.key,
key: typeof options.pluginKey === 'string'
? new PluginKey(options.pluginKey)
: options.pluginKey,
view: view => new BubbleMenuView({ view, ...options }),
})
}
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 @@ -11,7 +11,7 @@ export const BubbleMenu = Extension.create<BubbleMenuOptions>({
defaultOptions: {
element: null,
tippyOptions: {},
key: 'bubbleMenu',
pluginKey: 'bubbleMenu',
shouldShow: null,
},

Expand All @@ -22,7 +22,7 @@ export const BubbleMenu = Extension.create<BubbleMenuOptions>({

return [
BubbleMenuPlugin({
key: this.options.key,
pluginKey: this.options.pluginKey,
editor: this.editor,
element: this.options.element,
tippyOptions: this.options.tippyOptions,
Expand Down
8 changes: 4 additions & 4 deletions packages/extension-floating-menu/src/floating-menu-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EditorView } from 'prosemirror-view'
import tippy, { Instance, Props } from 'tippy.js'

export interface FloatingMenuPluginProps {
key: PluginKey | string,
pluginKey: PluginKey | string,
editor: Editor,
element: HTMLElement,
tippyOptions?: Partial<Props>,
Expand Down Expand Up @@ -160,9 +160,9 @@ export class FloatingMenuView {

export const FloatingMenuPlugin = (options: FloatingMenuPluginProps) => {
return new Plugin({
key: typeof options.key === 'string'
? new PluginKey(options.key)
: options.key,
key: typeof options.pluginKey === 'string'
? new PluginKey(options.pluginKey)
: options.pluginKey,
view: view => new FloatingMenuView({ view, ...options }),
})
}
4 changes: 2 additions & 2 deletions packages/extension-floating-menu/src/floating-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const FloatingMenu = Extension.create<FloatingMenuOptions>({
defaultOptions: {
element: null,
tippyOptions: {},
key: 'floatingMenu',
pluginKey: 'floatingMenu',
shouldShow: null,
},

Expand All @@ -22,7 +22,7 @@ export const FloatingMenu = Extension.create<FloatingMenuOptions>({

return [
FloatingMenuPlugin({
key: this.options.key,
pluginKey: this.options.pluginKey,
editor: this.editor,
element: this.options.element,
tippyOptions: this.options.tippyOptions,
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 @@ -10,22 +10,22 @@ export const BubbleMenu: React.FC<BubbleMenuProps> = props => {

useEffect(() => {
const {
key,
pluginKey,
editor,
tippyOptions,
shouldShow,
} = props

editor.registerPlugin(BubbleMenuPlugin({
key,
pluginKey,
editor,
element: element.current as HTMLElement,
tippyOptions,
shouldShow,
}))

return () => {
editor.unregisterPlugin(key)
editor.unregisterPlugin(pluginKey)
}
}, [])

Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/FloatingMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ export const FloatingMenu: React.FC<FloatingMenuProps> = props => {

useEffect(() => {
const {
key,
pluginKey,
editor,
tippyOptions,
shouldShow,
} = props

editor.registerPlugin(FloatingMenuPlugin({
key,
pluginKey,
editor,
element: element.current as HTMLElement,
tippyOptions,
shouldShow,
}))

return () => {
editor.unregisterPlugin(key)
editor.unregisterPlugin(pluginKey)
}
}, [])

Expand Down
6 changes: 3 additions & 3 deletions packages/vue-2/src/BubbleMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Vue, { Component, PropType } from 'vue'
import { BubbleMenuPlugin, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'

export interface BubbleMenuInterface extends Vue {
pluginKey: BubbleMenuPluginProps['key'],
pluginKey: BubbleMenuPluginProps['pluginKey'],
editor: BubbleMenuPluginProps['editor'],
tippyOptions: BubbleMenuPluginProps['tippyOptions'],
shouldShow: BubbleMenuPluginProps['shouldShow'],
Expand All @@ -13,7 +13,7 @@ export const BubbleMenu: Component = {

props: {
pluginKey: {
type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['key'], string>>],
type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['pluginKey'], string>>],
default: 'bubbleMenu',
},

Expand Down Expand Up @@ -43,7 +43,7 @@ export const BubbleMenu: Component = {

this.$nextTick(() => {
editor.registerPlugin(BubbleMenuPlugin({
key: this.pluginKey,
pluginKey: this.pluginKey,
editor,
element: this.$el as HTMLElement,
tippyOptions: this.tippyOptions,
Expand Down
6 changes: 3 additions & 3 deletions packages/vue-2/src/FloatingMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Vue, { Component, PropType } from 'vue'
import { FloatingMenuPlugin, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'

export interface FloatingMenuInterface extends Vue {
pluginKey: FloatingMenuPluginProps['key'],
pluginKey: FloatingMenuPluginProps['pluginKey'],
tippyOptions: FloatingMenuPluginProps['tippyOptions'],
editor: FloatingMenuPluginProps['editor'],
shouldShow: FloatingMenuPluginProps['shouldShow'],
Expand All @@ -13,7 +13,7 @@ export const FloatingMenu: Component = {

props: {
pluginKey: {
type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['key'], string>>],
type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
default: 'floatingMenu',
},

Expand Down Expand Up @@ -43,7 +43,7 @@ export const FloatingMenu: Component = {

this.$nextTick(() => {
editor.registerPlugin(FloatingMenuPlugin({
key: this.pluginKey,
pluginKey: this.pluginKey,
editor,
element: this.$el as HTMLElement,
tippyOptions: this.tippyOptions,
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-3/src/BubbleMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const BubbleMenu = defineComponent({
props: {
pluginKey: {
// TODO: TypeScript breaks :(
// type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['key'], string>>],
// type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['pluginKey'], string>>],
type: [String, Object],
default: 'bubbleMenu',
},
Expand Down Expand Up @@ -47,7 +47,7 @@ export const BubbleMenu = defineComponent({
} = props

editor.registerPlugin(BubbleMenuPlugin({
key: pluginKey,
pluginKey,
editor,
element: root.value as HTMLElement,
tippyOptions,
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-3/src/FloatingMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const FloatingMenu = defineComponent({
props: {
pluginKey: {
// TODO: TypeScript breaks :(
// type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['key'], string>>],
// type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
type: [String, Object],
default: 'floatingMenu',
},
Expand Down Expand Up @@ -47,7 +47,7 @@ export const FloatingMenu = defineComponent({
} = props

editor.registerPlugin(FloatingMenuPlugin({
key: pluginKey,
pluginKey,
editor,
element: root.value as HTMLElement,
tippyOptions,
Expand Down

0 comments on commit 89d26f7

Please sign in to comment.