rename some methods

This commit is contained in:
Philipp Kühn 2020-11-17 21:10:08 +01:00
parent 99aebcc18b
commit a4ad1572e8
9 changed files with 18 additions and 18 deletions

View File

@ -139,8 +139,8 @@ Dont confuse methods with [commands](/api/commands), which are used to change
| `destroy()` | | Stops the editor instance and unbinds all events. |
| `getHTML()` | | Returns the current content as HTML. |
| `getJSON()` | | Returns the current content as JSON. |
| `getMarkAttrs()` | `state` State of the editor<br>`name` Name of the mark | Get attributes of the currently selected mark. |
| `getNodeAttrs()` | `state` State of the editor`name` Name of the node | Get attributes of the currently selected node. |
| `getMarkAttributes()` | `name` Name of the mark | Get attributes of the currently selected mark. |
| `getNodeAttributes()` | `name` Name of the node | Get attributes of the currently selected node. |
| `isActive()` | `name` Name of the node or mark<br>`attrs` Attributes of the node or mark | Returns if the currently selected node or mark is active. |
| `isEditable()` | - | Returns whether the editor is editable. |
| `isEmpty()` | - | Check if there is no content. |

View File

@ -10,8 +10,8 @@ import magicMethods from './utils/magicMethods'
import elementFromString from './utils/elementFromString'
import nodeIsActive from './utils/nodeIsActive'
import markIsActive from './utils/markIsActive'
import getNodeAttrs from './utils/getNodeAttrs'
import getMarkAttrs from './utils/getMarkAttrs'
import getNodeAttributes from './utils/getNodeAttributes'
import getMarkAttributes from './utils/getMarkAttributes'
import removeElement from './utils/removeElement'
import getSchemaTypeNameByName from './utils/getSchemaTypeNameByName'
import getHTMLFromFragment from './utils/getHTMLFromFragment'
@ -333,8 +333,8 @@ export class Editor extends EventEmitter {
*
* @param name Name of the node
*/
public getNodeAttrs(name: string) {
return getNodeAttrs(this.state, this.schema.nodes[name])
public getNodeAttributes(name: string) {
return getNodeAttributes(this.state, this.schema.nodes[name])
}
/**
@ -342,8 +342,8 @@ export class Editor extends EventEmitter {
*
* @param name Name of the mark
*/
public getMarkAttrs(name: string) {
return getMarkAttrs(this.state, this.schema.marks[name])
public getMarkAttributes(name: string) {
return getMarkAttributes(this.state, this.schema.marks[name])
}
/**

View File

@ -1,13 +1,13 @@
import { MarkType } from 'prosemirror-model'
import { Command } from '../types'
import getMarkType from '../utils/getMarkType'
import getMarkAttrs from '../utils/getMarkAttrs'
import getMarkAttributes from '../utils/getMarkAttributes'
export default (typeOrName: string | MarkType, attributes: {}): Command => ({ tr, state, dispatch }) => {
const { selection } = tr
const { from, to, empty } = selection
const type = getMarkType(typeOrName, state.schema)
const oldAttributes = getMarkAttrs(state, type)
const oldAttributes = getMarkAttributes(state, type)
const newAttributes = {
...oldAttributes,
...attributes,

View File

@ -11,7 +11,7 @@ export { default as markPasteRule } from './pasteRules/markPasteRule'
export { default as getSchema } from './utils/getSchema'
export { default as generateHTML } from './utils/generateHTML'
export { default as getHTMLFromFragment } from './utils/getHTMLFromFragment'
export { default as getMarkAttrs } from './utils/getMarkAttrs'
export { default as getMarkAttributes } from './utils/getMarkAttributes'
export { default as mergeAttributes } from './utils/mergeAttributes'
export interface AllExtensions {}

View File

@ -1,7 +1,7 @@
import { EditorState } from 'prosemirror-state'
import { Mark, MarkType } from 'prosemirror-model'
export default function getMarkAttrs(state: EditorState, type: MarkType) {
export default function getMarkAttributes(state: EditorState, type: MarkType) {
const { from, to, empty } = state.selection
let marks: Mark[] = []

View File

@ -1,7 +1,7 @@
import { EditorState } from 'prosemirror-state'
import { Node, NodeType } from 'prosemirror-model'
export default function getNodeAttrs(state: EditorState, type: NodeType) {
export default function getNodeAttributes(state: EditorState, type: NodeType) {
const { from, to } = state.selection
let nodes: Node[] = []

View File

@ -1,6 +1,6 @@
import { EditorState } from 'prosemirror-state'
import { MarkType } from 'prosemirror-model'
import getMarkAttrs from './getMarkAttrs'
import getMarkAttributes from './getMarkAttributes'
import { AnyObject } from '../types'
import isEmptyObject from './isEmptyObject'
@ -9,7 +9,7 @@ export default function markHasAttributes(state: EditorState, type: MarkType, at
return true
}
const originalAttrs = getMarkAttrs(state, type)
const originalAttrs = getMarkAttributes(state, type)
return !!Object
.keys(attributes)

View File

@ -75,7 +75,7 @@ const Link = Mark.create({
key: new PluginKey('handleClick'),
props: {
handleClick: (view, pos, event) => {
const attrs = this.editor.getMarkAttrs('link')
const attrs = this.editor.getMarkAttributes('link')
if (attrs.href && event.target instanceof HTMLAnchorElement) {
window.open(attrs.href, attrs.target)

View File

@ -1,4 +1,4 @@
import { Command, Mark, getMarkAttrs } from '@tiptap/core'
import { Command, Mark, getMarkAttributes } from '@tiptap/core'
const TextStyle = Mark.create({
name: 'textStyle',
@ -30,7 +30,7 @@ const TextStyle = Mark.create({
* Remove spans without inline style attributes.
*/
removeEmptyTextStyle: (): Command => ({ state, commands }) => {
const attributes = getMarkAttrs(state, this.type)
const attributes = getMarkAttributes(state, this.type)
const hasStyles = Object.entries(attributes).every(([, value]) => !!value)
if (hasStyles) {