mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 11:09:01 +08:00
add getNodeAttrs, fix #622
This commit is contained in:
parent
0228001aa4
commit
0ca798fe23
@ -110,6 +110,7 @@ The `<editor-menu-bar />` component is renderless and will receive some properti
|
|||||||
| `commands` | `Array` | A list of all commands. |
|
| `commands` | `Array` | A list of all commands. |
|
||||||
| `isActive` | `Object` | An object of functions to check if your selected text is a node or mark. `isActive.{node|mark}(attrs)` |
|
| `isActive` | `Object` | An object of functions to check if your selected text is a node or mark. `isActive.{node|mark}(attrs)` |
|
||||||
| `getMarkAttrs` | `Function` | A function to get all mark attributes of your selection. |
|
| `getMarkAttrs` | `Function` | A function to get all mark attributes of your selection. |
|
||||||
|
| `getNodeAttrs` | `Function` | A function to get all node attributes of your selection. |
|
||||||
| `focused` | `Boolean` | Whether the editor is focused. |
|
| `focused` | `Boolean` | Whether the editor is focused. |
|
||||||
| `focus` | `Function` | A function to focus the editor. |
|
| `focus` | `Function` | A function to focus the editor. |
|
||||||
|
|
||||||
@ -139,6 +140,7 @@ The `<editor-menu-bubble />` component is renderless and will receive some prope
|
|||||||
| `commands` | `Array` | A list of all commands. |
|
| `commands` | `Array` | A list of all commands. |
|
||||||
| `isActive` | `Object` | An object of functions to check if your selected text is a node or mark. `isActive.{node|mark}(attrs)` |
|
| `isActive` | `Object` | An object of functions to check if your selected text is a node or mark. `isActive.{node|mark}(attrs)` |
|
||||||
| `getMarkAttrs` | `Function` | A function to get all mark attributes of your selection. |
|
| `getMarkAttrs` | `Function` | A function to get all mark attributes of your selection. |
|
||||||
|
| `getNodeAttrs` | `Function` | A function to get all node attributes of your selection. |
|
||||||
| `focused` | `Boolean` | Whether the editor is focused. |
|
| `focused` | `Boolean` | Whether the editor is focused. |
|
||||||
| `focus` | `Function` | A function to focus the editor. |
|
| `focus` | `Function` | A function to focus the editor. |
|
||||||
| `menu` | `Object` | An object for positioning your menu. |
|
| `menu` | `Object` | An object for positioning your menu. |
|
||||||
@ -172,6 +174,7 @@ The `<editor-floating-menu />` component is renderless and will receive some pro
|
|||||||
| `commands` | `Array` | A list of all commands. |
|
| `commands` | `Array` | A list of all commands. |
|
||||||
| `isActive` | `Object` | An object of functions to check if your selected text is a node or mark. `isActive.{node|mark}(attrs)` |
|
| `isActive` | `Object` | An object of functions to check if your selected text is a node or mark. `isActive.{node|mark}(attrs)` |
|
||||||
| `getMarkAttrs` | `Function` | A function to get all mark attributes of your selection. |
|
| `getMarkAttrs` | `Function` | A function to get all mark attributes of your selection. |
|
||||||
|
| `getNodeAttrs` | `Function` | A function to get all node attributes of your selection. |
|
||||||
| `focused` | `Boolean` | Whether the editor is focused. |
|
| `focused` | `Boolean` | Whether the editor is focused. |
|
||||||
| `focus` | `Function` | A function to focus the editor. |
|
| `focus` | `Function` | A function to focus the editor. |
|
||||||
| `menu` | `Object` | An object for positioning your menu. |
|
| `menu` | `Object` | An object for positioning your menu. |
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
export { default as getMarkAttrs } from './utils/getMarkAttrs'
|
export { default as getMarkAttrs } from './utils/getMarkAttrs'
|
||||||
|
export { default as getNodeAttrs } from './utils/getNodeAttrs'
|
||||||
export { default as getMarkRange } from './utils/getMarkRange'
|
export { default as getMarkRange } from './utils/getMarkRange'
|
||||||
export { default as markIsActive } from './utils/markIsActive'
|
export { default as markIsActive } from './utils/markIsActive'
|
||||||
export { default as nodeEqualsType } from './utils/nodeEqualsType'
|
export { default as nodeEqualsType } from './utils/nodeEqualsType'
|
||||||
|
18
packages/tiptap-utils/src/utils/getNodeAttrs.js
Normal file
18
packages/tiptap-utils/src/utils/getNodeAttrs.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
export default function getNodeAttrs(state, type) {
|
||||||
|
const { from, to } = state.selection
|
||||||
|
let nodes = []
|
||||||
|
|
||||||
|
state.doc.nodesBetween(from, to, node => {
|
||||||
|
nodes = [...nodes, node]
|
||||||
|
})
|
||||||
|
|
||||||
|
const node = nodes
|
||||||
|
.reverse()
|
||||||
|
.find(nodeItem => nodeItem.type.name === type.name)
|
||||||
|
|
||||||
|
if (node) {
|
||||||
|
return node.attrs
|
||||||
|
}
|
||||||
|
|
||||||
|
return {}
|
||||||
|
}
|
@ -55,6 +55,7 @@ export default {
|
|||||||
commands: this.editor.commands,
|
commands: this.editor.commands,
|
||||||
isActive: this.editor.isActive,
|
isActive: this.editor.isActive,
|
||||||
getMarkAttrs: this.editor.getMarkAttrs.bind(this.editor),
|
getMarkAttrs: this.editor.getMarkAttrs.bind(this.editor),
|
||||||
|
getNodeAttrs: this.editor.getNodeAttrs.bind(this.editor),
|
||||||
menu: this.menu,
|
menu: this.menu,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -52,6 +52,7 @@ export default {
|
|||||||
commands: this.editor.commands,
|
commands: this.editor.commands,
|
||||||
isActive: this.editor.isActive,
|
isActive: this.editor.isActive,
|
||||||
getMarkAttrs: this.editor.getMarkAttrs.bind(this.editor),
|
getMarkAttrs: this.editor.getMarkAttrs.bind(this.editor),
|
||||||
|
getNodeAttrs: this.editor.getNodeAttrs.bind(this.editor),
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -60,6 +60,7 @@ export default {
|
|||||||
commands: this.editor.commands,
|
commands: this.editor.commands,
|
||||||
isActive: this.editor.isActive,
|
isActive: this.editor.isActive,
|
||||||
getMarkAttrs: this.editor.getMarkAttrs.bind(this.editor),
|
getMarkAttrs: this.editor.getMarkAttrs.bind(this.editor),
|
||||||
|
getNodeAttrs: this.editor.getNodeAttrs.bind(this.editor),
|
||||||
menu: this.menu,
|
menu: this.menu,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -11,7 +11,12 @@ import { gapCursor } from 'prosemirror-gapcursor'
|
|||||||
import { keymap } from 'prosemirror-keymap'
|
import { keymap } from 'prosemirror-keymap'
|
||||||
import { baseKeymap } from 'prosemirror-commands'
|
import { baseKeymap } from 'prosemirror-commands'
|
||||||
import { inputRules, undoInputRule } from 'prosemirror-inputrules'
|
import { inputRules, undoInputRule } from 'prosemirror-inputrules'
|
||||||
import { markIsActive, nodeIsActive, getMarkAttrs } from 'tiptap-utils'
|
import {
|
||||||
|
markIsActive,
|
||||||
|
nodeIsActive,
|
||||||
|
getMarkAttrs,
|
||||||
|
getNodeAttrs,
|
||||||
|
} from 'tiptap-utils'
|
||||||
import {
|
import {
|
||||||
injectCSS,
|
injectCSS,
|
||||||
camelCase,
|
camelCase,
|
||||||
@ -475,6 +480,12 @@ export default class Editor extends Emitter {
|
|||||||
return this.activeMarkAttrs[type]
|
return this.activeMarkAttrs[type]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getNodeAttrs(type = null) {
|
||||||
|
return {
|
||||||
|
...getNodeAttrs(this.state, this.schema.nodes[type]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get isActive() {
|
get isActive() {
|
||||||
return Object
|
return Object
|
||||||
.entries({
|
.entries({
|
||||||
|
Loading…
Reference in New Issue
Block a user