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. | | `destroy()` | | Stops the editor instance and unbinds all events. |
| `getHTML()` | | Returns the current content as HTML. | | `getHTML()` | | Returns the current content as HTML. |
| `getJSON()` | | Returns the current content as JSON. | | `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. | | `getMarkAttributes()` | `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. | | `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. | | `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. | | `isEditable()` | - | Returns whether the editor is editable. |
| `isEmpty()` | - | Check if there is no content. | | `isEmpty()` | - | Check if there is no content. |

View File

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

View File

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

View File

@@ -11,7 +11,7 @@ export { default as markPasteRule } from './pasteRules/markPasteRule'
export { default as getSchema } from './utils/getSchema' export { default as getSchema } from './utils/getSchema'
export { default as generateHTML } from './utils/generateHTML' export { default as generateHTML } from './utils/generateHTML'
export { default as getHTMLFromFragment } from './utils/getHTMLFromFragment' 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 { default as mergeAttributes } from './utils/mergeAttributes'
export interface AllExtensions {} export interface AllExtensions {}

View File

@@ -1,7 +1,7 @@
import { EditorState } from 'prosemirror-state' import { EditorState } from 'prosemirror-state'
import { Mark, MarkType } from 'prosemirror-model' 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 const { from, to, empty } = state.selection
let marks: Mark[] = [] let marks: Mark[] = []

View File

@@ -1,7 +1,7 @@
import { EditorState } from 'prosemirror-state' import { EditorState } from 'prosemirror-state'
import { Node, NodeType } from 'prosemirror-model' 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 const { from, to } = state.selection
let nodes: Node[] = [] let nodes: Node[] = []

View File

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

View File

@@ -75,7 +75,7 @@ const Link = Mark.create({
key: new PluginKey('handleClick'), key: new PluginKey('handleClick'),
props: { props: {
handleClick: (view, pos, event) => { handleClick: (view, pos, event) => {
const attrs = this.editor.getMarkAttrs('link') const attrs = this.editor.getMarkAttributes('link')
if (attrs.href && event.target instanceof HTMLAnchorElement) { if (attrs.href && event.target instanceof HTMLAnchorElement) {
window.open(attrs.href, attrs.target) 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({ const TextStyle = Mark.create({
name: 'textStyle', name: 'textStyle',
@@ -30,7 +30,7 @@ const TextStyle = Mark.create({
* Remove spans without inline style attributes. * Remove spans without inline style attributes.
*/ */
removeEmptyTextStyle: (): Command => ({ state, commands }) => { removeEmptyTextStyle: (): Command => ({ state, commands }) => {
const attributes = getMarkAttrs(state, this.type) const attributes = getMarkAttributes(state, this.type)
const hasStyles = Object.entries(attributes).every(([, value]) => !!value) const hasStyles = Object.entries(attributes).every(([, value]) => !!value)
if (hasStyles) { if (hasStyles) {