fix: rename key to pluginKey for menus

This commit is contained in:
Philipp Kühn
2021-08-13 12:33:06 +02:00
parent 8fd75bc4b6
commit 89d26f7cba
12 changed files with 40 additions and 40 deletions

View File

@@ -19,7 +19,7 @@ yarn add @tiptap/extension-bubble-menu
| ------------ | -------------------- | -------------- | ----------------------------------------------------------------------- | | ------------ | -------------------- | -------------- | ----------------------------------------------------------------------- |
| element | `HTMLElement` | `null` | The DOM element that contains your 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/) | | 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. | | shouldShow | `(props) => boolean` | | Controls whether the menu should be shown or not. |
## Source code ## Source code
@@ -60,7 +60,7 @@ BubbleMenu.configure({
``` ```
### Multiple menus ### Multiple menus
Use multiple menus by setting an unique `key`. Use multiple menus by setting an unique `pluginKey`.
```js ```js
import { Editor } from '@tiptap/core' import { Editor } from '@tiptap/core'
@@ -69,11 +69,11 @@ import BubbleMenu from '@tiptap/extension-bubble-menu'
new Editor({ new Editor({
extensions: [ extensions: [
BubbleMenu.configure({ BubbleMenu.configure({
key: 'bubbleMenuOne', pluginKey: 'bubbleMenuOne',
element: document.querySelector('.menu-one'), element: document.querySelector('.menu-one'),
}), }),
BubbleMenu.configure({ BubbleMenu.configure({
key: 'bubbleMenuTwo', pluginKey: 'bubbleMenuTwo',
element: document.querySelector('.menu-two'), element: document.querySelector('.menu-two'),
}), }),
], ],
@@ -90,11 +90,11 @@ import { PluginKey } from 'prosemirror-state'
new Editor({ new Editor({
extensions: [ extensions: [
BubbleMenu.configure({ BubbleMenu.configure({
key: new PluginKey('bubbleMenuOne'), pluginKey: new PluginKey('bubbleMenuOne'),
element: document.querySelector('.menu-one'), element: document.querySelector('.menu-one'),
}), }),
BubbleMenu.configure({ BubbleMenu.configure({
key: new PluginKey('bubbleMenuTwo'), pluginKey: new PluginKey('bubbleMenuTwo'),
element: document.querySelector('.menu-two'), element: document.querySelector('.menu-two'),
}), }),
], ],

View File

@@ -17,7 +17,7 @@ yarn add @tiptap/extension-floating-menu
| ------------ | -------------------- | ---------------- | ----------------------------------------------------------------------- | | ------------ | -------------------- | ---------------- | ----------------------------------------------------------------------- |
| element | `HTMLElement` | `null` | The DOM element of your menu. | | element | `HTMLElement` | `null` | The DOM element of your menu. |
| tippyOptions | `Object` | `{}` | [Options for tippy.js](https://atomiks.github.io/tippyjs/v6/all-props/) | | 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. | | shouldShow | `(props) => boolean` | | Controls whether the menu should be shown or not. |
## Source code ## Source code
@@ -56,7 +56,7 @@ FloatingMenu.configure({
``` ```
### Multiple menus ### Multiple menus
Use multiple menus by setting an unique `key`. Use multiple menus by setting an unique `pluginKey`.
```js ```js
import { Editor } from '@tiptap/core' import { Editor } from '@tiptap/core'
@@ -65,11 +65,11 @@ import FloatingMenu from '@tiptap/extension-floating-menu'
new Editor({ new Editor({
extensions: [ extensions: [
FloatingMenu.configure({ FloatingMenu.configure({
key: 'floatingMenuOne', pluginKey: 'floatingMenuOne',
element: document.querySelector('.menu-one'), element: document.querySelector('.menu-one'),
}), }),
FloatingMenu.configure({ FloatingMenu.configure({
key: 'floatingMenuTwo', pluginKey: 'floatingMenuTwo',
element: document.querySelector('.menu-two'), element: document.querySelector('.menu-two'),
}), }),
], ],
@@ -86,11 +86,11 @@ import { PluginKey } from 'prosemirror-state'
new Editor({ new Editor({
extensions: [ extensions: [
FloatingMenu.configure({ FloatingMenu.configure({
key: new PluginKey('floatingMenuOne'), pluginKey: new PluginKey('floatingMenuOne'),
element: document.querySelector('.menu-one'), element: document.querySelector('.menu-one'),
}), }),
FloatingMenu.configure({ FloatingMenu.configure({
key: new PluginKey('floatingMenuOne'), pluginKey: new PluginKey('floatingMenuOne'),
element: document.querySelector('.menu-two'), element: document.querySelector('.menu-two'),
}), }),
], ],

View File

@@ -9,7 +9,7 @@ import { EditorView } from 'prosemirror-view'
import tippy, { Instance, Props } from 'tippy.js' import tippy, { Instance, Props } from 'tippy.js'
export interface BubbleMenuPluginProps { export interface BubbleMenuPluginProps {
key: PluginKey | string, pluginKey: PluginKey | string,
editor: Editor, editor: Editor,
element: HTMLElement, element: HTMLElement,
tippyOptions?: Partial<Props>, tippyOptions?: Partial<Props>,
@@ -191,9 +191,9 @@ export class BubbleMenuView {
export const BubbleMenuPlugin = (options: BubbleMenuPluginProps) => { export const BubbleMenuPlugin = (options: BubbleMenuPluginProps) => {
return new Plugin({ return new Plugin({
key: typeof options.key === 'string' key: typeof options.pluginKey === 'string'
? new PluginKey(options.key) ? new PluginKey(options.pluginKey)
: options.key, : options.pluginKey,
view: view => new BubbleMenuView({ view, ...options }), view: view => new BubbleMenuView({ view, ...options }),
}) })
} }

View File

@@ -11,7 +11,7 @@ export const BubbleMenu = Extension.create<BubbleMenuOptions>({
defaultOptions: { defaultOptions: {
element: null, element: null,
tippyOptions: {}, tippyOptions: {},
key: 'bubbleMenu', pluginKey: 'bubbleMenu',
shouldShow: null, shouldShow: null,
}, },
@@ -22,7 +22,7 @@ export const BubbleMenu = Extension.create<BubbleMenuOptions>({
return [ return [
BubbleMenuPlugin({ BubbleMenuPlugin({
key: this.options.key, pluginKey: this.options.pluginKey,
editor: this.editor, editor: this.editor,
element: this.options.element, element: this.options.element,
tippyOptions: this.options.tippyOptions, tippyOptions: this.options.tippyOptions,

View File

@@ -4,7 +4,7 @@ import { EditorView } from 'prosemirror-view'
import tippy, { Instance, Props } from 'tippy.js' import tippy, { Instance, Props } from 'tippy.js'
export interface FloatingMenuPluginProps { export interface FloatingMenuPluginProps {
key: PluginKey | string, pluginKey: PluginKey | string,
editor: Editor, editor: Editor,
element: HTMLElement, element: HTMLElement,
tippyOptions?: Partial<Props>, tippyOptions?: Partial<Props>,
@@ -160,9 +160,9 @@ export class FloatingMenuView {
export const FloatingMenuPlugin = (options: FloatingMenuPluginProps) => { export const FloatingMenuPlugin = (options: FloatingMenuPluginProps) => {
return new Plugin({ return new Plugin({
key: typeof options.key === 'string' key: typeof options.pluginKey === 'string'
? new PluginKey(options.key) ? new PluginKey(options.pluginKey)
: options.key, : options.pluginKey,
view: view => new FloatingMenuView({ view, ...options }), view: view => new FloatingMenuView({ view, ...options }),
}) })
} }

View File

@@ -11,7 +11,7 @@ export const FloatingMenu = Extension.create<FloatingMenuOptions>({
defaultOptions: { defaultOptions: {
element: null, element: null,
tippyOptions: {}, tippyOptions: {},
key: 'floatingMenu', pluginKey: 'floatingMenu',
shouldShow: null, shouldShow: null,
}, },
@@ -22,7 +22,7 @@ export const FloatingMenu = Extension.create<FloatingMenuOptions>({
return [ return [
FloatingMenuPlugin({ FloatingMenuPlugin({
key: this.options.key, pluginKey: this.options.pluginKey,
editor: this.editor, editor: this.editor,
element: this.options.element, element: this.options.element,
tippyOptions: this.options.tippyOptions, tippyOptions: this.options.tippyOptions,

View File

@@ -10,14 +10,14 @@ export const BubbleMenu: React.FC<BubbleMenuProps> = props => {
useEffect(() => { useEffect(() => {
const { const {
key, pluginKey,
editor, editor,
tippyOptions, tippyOptions,
shouldShow, shouldShow,
} = props } = props
editor.registerPlugin(BubbleMenuPlugin({ editor.registerPlugin(BubbleMenuPlugin({
key, pluginKey,
editor, editor,
element: element.current as HTMLElement, element: element.current as HTMLElement,
tippyOptions, tippyOptions,
@@ -25,7 +25,7 @@ export const BubbleMenu: React.FC<BubbleMenuProps> = props => {
})) }))
return () => { return () => {
editor.unregisterPlugin(key) editor.unregisterPlugin(pluginKey)
} }
}, []) }, [])

View File

@@ -10,14 +10,14 @@ export const FloatingMenu: React.FC<FloatingMenuProps> = props => {
useEffect(() => { useEffect(() => {
const { const {
key, pluginKey,
editor, editor,
tippyOptions, tippyOptions,
shouldShow, shouldShow,
} = props } = props
editor.registerPlugin(FloatingMenuPlugin({ editor.registerPlugin(FloatingMenuPlugin({
key, pluginKey,
editor, editor,
element: element.current as HTMLElement, element: element.current as HTMLElement,
tippyOptions, tippyOptions,
@@ -25,7 +25,7 @@ export const FloatingMenu: React.FC<FloatingMenuProps> = props => {
})) }))
return () => { return () => {
editor.unregisterPlugin(key) editor.unregisterPlugin(pluginKey)
} }
}, []) }, [])

View File

@@ -2,7 +2,7 @@ import Vue, { Component, PropType } from 'vue'
import { BubbleMenuPlugin, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu' import { BubbleMenuPlugin, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'
export interface BubbleMenuInterface extends Vue { export interface BubbleMenuInterface extends Vue {
pluginKey: BubbleMenuPluginProps['key'], pluginKey: BubbleMenuPluginProps['pluginKey'],
editor: BubbleMenuPluginProps['editor'], editor: BubbleMenuPluginProps['editor'],
tippyOptions: BubbleMenuPluginProps['tippyOptions'], tippyOptions: BubbleMenuPluginProps['tippyOptions'],
shouldShow: BubbleMenuPluginProps['shouldShow'], shouldShow: BubbleMenuPluginProps['shouldShow'],
@@ -13,7 +13,7 @@ export const BubbleMenu: Component = {
props: { props: {
pluginKey: { pluginKey: {
type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['key'], string>>], type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['pluginKey'], string>>],
default: 'bubbleMenu', default: 'bubbleMenu',
}, },
@@ -43,7 +43,7 @@ export const BubbleMenu: Component = {
this.$nextTick(() => { this.$nextTick(() => {
editor.registerPlugin(BubbleMenuPlugin({ editor.registerPlugin(BubbleMenuPlugin({
key: this.pluginKey, pluginKey: this.pluginKey,
editor, editor,
element: this.$el as HTMLElement, element: this.$el as HTMLElement,
tippyOptions: this.tippyOptions, tippyOptions: this.tippyOptions,

View File

@@ -2,7 +2,7 @@ import Vue, { Component, PropType } from 'vue'
import { FloatingMenuPlugin, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu' import { FloatingMenuPlugin, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'
export interface FloatingMenuInterface extends Vue { export interface FloatingMenuInterface extends Vue {
pluginKey: FloatingMenuPluginProps['key'], pluginKey: FloatingMenuPluginProps['pluginKey'],
tippyOptions: FloatingMenuPluginProps['tippyOptions'], tippyOptions: FloatingMenuPluginProps['tippyOptions'],
editor: FloatingMenuPluginProps['editor'], editor: FloatingMenuPluginProps['editor'],
shouldShow: FloatingMenuPluginProps['shouldShow'], shouldShow: FloatingMenuPluginProps['shouldShow'],
@@ -13,7 +13,7 @@ export const FloatingMenu: Component = {
props: { props: {
pluginKey: { pluginKey: {
type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['key'], string>>], type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
default: 'floatingMenu', default: 'floatingMenu',
}, },
@@ -43,7 +43,7 @@ export const FloatingMenu: Component = {
this.$nextTick(() => { this.$nextTick(() => {
editor.registerPlugin(FloatingMenuPlugin({ editor.registerPlugin(FloatingMenuPlugin({
key: this.pluginKey, pluginKey: this.pluginKey,
editor, editor,
element: this.$el as HTMLElement, element: this.$el as HTMLElement,
tippyOptions: this.tippyOptions, tippyOptions: this.tippyOptions,

View File

@@ -14,7 +14,7 @@ export const BubbleMenu = defineComponent({
props: { props: {
pluginKey: { pluginKey: {
// TODO: TypeScript breaks :( // TODO: TypeScript breaks :(
// type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['key'], string>>], // type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['pluginKey'], string>>],
type: [String, Object], type: [String, Object],
default: 'bubbleMenu', default: 'bubbleMenu',
}, },
@@ -47,7 +47,7 @@ export const BubbleMenu = defineComponent({
} = props } = props
editor.registerPlugin(BubbleMenuPlugin({ editor.registerPlugin(BubbleMenuPlugin({
key: pluginKey, pluginKey,
editor, editor,
element: root.value as HTMLElement, element: root.value as HTMLElement,
tippyOptions, tippyOptions,

View File

@@ -14,7 +14,7 @@ export const FloatingMenu = defineComponent({
props: { props: {
pluginKey: { pluginKey: {
// TODO: TypeScript breaks :( // TODO: TypeScript breaks :(
// type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['key'], string>>], // type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
type: [String, Object], type: [String, Object],
default: 'floatingMenu', default: 'floatingMenu',
}, },
@@ -47,7 +47,7 @@ export const FloatingMenu = defineComponent({
} = props } = props
editor.registerPlugin(FloatingMenuPlugin({ editor.registerPlugin(FloatingMenuPlugin({
key: pluginKey, pluginKey,
editor, editor,
element: root.value as HTMLElement, element: root.value as HTMLElement,
tippyOptions, tippyOptions,