mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
split helpers and utilities
This commit is contained in:
parent
8d38459289
commit
f486ddf80a
@ -6,7 +6,7 @@ import {
|
||||
CanCommands,
|
||||
CommandSpec,
|
||||
} from './types'
|
||||
import getAllMethodNames from './utils/getAllMethodNames'
|
||||
import getAllMethodNames from './utilities/getAllMethodNames'
|
||||
|
||||
export default class CommandManager {
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
import { EditorState, Plugin, Transaction } from 'prosemirror-state'
|
||||
import { EditorView } from 'prosemirror-view'
|
||||
import { Schema, DOMParser, Node } from 'prosemirror-model'
|
||||
import magicMethods from './utils/magicMethods'
|
||||
import elementFromString from './utils/elementFromString'
|
||||
import getNodeAttributes from './utils/getNodeAttributes'
|
||||
import getMarkAttributes from './utils/getMarkAttributes'
|
||||
import isActive from './utils/isActive'
|
||||
import removeElement from './utils/removeElement'
|
||||
import getHTMLFromFragment from './utils/getHTMLFromFragment'
|
||||
import createStyleTag from './utils/createStyleTag'
|
||||
import magicMethods from './utilities/magicMethods'
|
||||
import elementFromString from './utilities/elementFromString'
|
||||
import getNodeAttributes from './helpers/getNodeAttributes'
|
||||
import getMarkAttributes from './helpers/getMarkAttributes'
|
||||
import isActive from './helpers/isActive'
|
||||
import removeElement from './utilities/removeElement'
|
||||
import getHTMLFromFragment from './helpers/getHTMLFromFragment'
|
||||
import createStyleTag from './utilities/createStyleTag'
|
||||
import CommandManager from './CommandManager'
|
||||
import ExtensionManager from './ExtensionManager'
|
||||
import EventEmitter from './EventEmitter'
|
||||
|
@ -4,11 +4,11 @@ import { inputRules } from 'prosemirror-inputrules'
|
||||
import { EditorView, Decoration } from 'prosemirror-view'
|
||||
import { Editor } from './Editor'
|
||||
import { Extensions, NodeViewRenderer } from './types'
|
||||
import getSchema from './utils/getSchema'
|
||||
import getSchemaTypeByName from './utils/getSchemaTypeByName'
|
||||
import splitExtensions from './utils/splitExtensions'
|
||||
import getAttributesFromExtensions from './utils/getAttributesFromExtensions'
|
||||
import getRenderedAttributes from './utils/getRenderedAttributes'
|
||||
import getSchema from './helpers/getSchema'
|
||||
import getSchemaTypeByName from './helpers/getSchemaTypeByName'
|
||||
import splitExtensions from './helpers/splitExtensions'
|
||||
import getAttributesFromExtensions from './helpers/getAttributesFromExtensions'
|
||||
import getRenderedAttributes from './helpers/getRenderedAttributes'
|
||||
|
||||
export default class ExtensionManager {
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { TextSelection } from 'prosemirror-state'
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import getMarkType from '../utils/getMarkType'
|
||||
import getMarkRange from '../utils/getMarkRange'
|
||||
import getMarkType from '../helpers/getMarkType'
|
||||
import getMarkRange from '../helpers/getMarkRange'
|
||||
|
||||
/**
|
||||
* Extends the text selection to the current mark.
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { EditorState, TextSelection } from 'prosemirror-state'
|
||||
import { Command, FocusPosition } from '../types'
|
||||
import minMax from '../utils/minMax'
|
||||
import minMax from '../utilities/minMax'
|
||||
|
||||
function resolveSelection(state: EditorState, position: FocusPosition = null) {
|
||||
if (!position) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { DOMParser } from 'prosemirror-model'
|
||||
import { Selection, Transaction } from 'prosemirror-state'
|
||||
import { ReplaceStep, ReplaceAroundStep } from 'prosemirror-transform'
|
||||
import elementFromString from '../utils/elementFromString'
|
||||
import elementFromString from '../utilities/elementFromString'
|
||||
import { Command } from '../types'
|
||||
|
||||
// TODO: move to utils
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { lift as originalLift } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import nodeIsActive from '../utils/nodeIsActive'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
import nodeIsActive from '../helpers/nodeIsActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Removes an existing wrap.
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { liftListItem as originalLiftListItem } from 'prosemirror-schema-list'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Lift the list item into a wrapping list.
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
import deleteProps from '../utils/deleteProps'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
import deleteProps from '../utilities/deleteProps'
|
||||
import { Command } from '../types'
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import getMarkType from '../utils/getMarkType'
|
||||
import getMarkAttributes from '../utils/getMarkAttributes'
|
||||
import getMarkType from '../helpers/getMarkType'
|
||||
import getMarkAttributes from '../helpers/getMarkAttributes'
|
||||
|
||||
/**
|
||||
* Add a mark with new attributes.
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { setBlockType } from 'prosemirror-commands'
|
||||
import { Command } from '../types'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Replace a given range with a node.
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { sinkListItem as originalSinkListItem } from 'prosemirror-schema-list'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Sink the list item down into an inner list.
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { splitListItem as originalSplitListItem } from 'prosemirror-schema-list'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Splits one list item into two list items.
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { findParentNode } from 'prosemirror-utils'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
import isList from '../utils/isList'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
import isList from '../helpers/isList'
|
||||
|
||||
/**
|
||||
* Toggle between different list types.
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { toggleMark as originalToggleMark } from 'prosemirror-commands'
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import getMarkType from '../utils/getMarkType'
|
||||
import markIsActive from '../utils/markIsActive'
|
||||
import getMarkType from '../helpers/getMarkType'
|
||||
import markIsActive from '../helpers/markIsActive'
|
||||
|
||||
/**
|
||||
* Toggle a mark on and off.
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import nodeIsActive from '../utils/nodeIsActive'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
import nodeIsActive from '../helpers/nodeIsActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Toggle a node with another node.
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { wrapIn, lift } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import nodeIsActive from '../utils/nodeIsActive'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
import nodeIsActive from '../helpers/nodeIsActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Wraps nodes in another node, or removes an existing wrap.
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import getMarkType from '../utils/getMarkType'
|
||||
import getMarkRange from '../utils/getMarkRange'
|
||||
import getMarkType from '../helpers/getMarkType'
|
||||
import getMarkRange from '../helpers/getMarkRange'
|
||||
|
||||
/**
|
||||
* Remove all marks in the current selection.
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
import { Command } from '../types'
|
||||
|
||||
/**
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { wrapIn as originalWrapIn } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import nodeIsActive from '../utils/nodeIsActive'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
import nodeIsActive from '../helpers/nodeIsActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Wraps nodes in another node.
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { wrapInList as originalWrapInList } from 'prosemirror-schema-list'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../types'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
/**
|
||||
* Wrap a node in a list.
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Node, Mark } from 'prosemirror-model'
|
||||
import { ExtensionAttribute, AnyObject } from '../types'
|
||||
import mergeAttributes from './mergeAttributes'
|
||||
import mergeAttributes from '../utilities/mergeAttributes'
|
||||
|
||||
export default function getRenderedAttributes(nodeOrMark: Node | Mark, extensionAttributes: ExtensionAttribute[]): AnyObject {
|
||||
return extensionAttributes
|
@ -3,9 +3,9 @@ import { Extensions } from '../types'
|
||||
import splitExtensions from './splitExtensions'
|
||||
import getAttributesFromExtensions from './getAttributesFromExtensions'
|
||||
import getRenderedAttributes from './getRenderedAttributes'
|
||||
import isEmptyObject from './isEmptyObject'
|
||||
import isEmptyObject from '../utilities/isEmptyObject'
|
||||
import injectExtensionAttributesToParseRule from './injectExtensionAttributesToParseRule'
|
||||
import callOrReturn from './callOrReturn'
|
||||
import callOrReturn from '../utilities/callOrReturn'
|
||||
|
||||
function cleanUpSchemaItem<T>(data: T) {
|
||||
return Object.fromEntries(Object.entries(data).filter(([key, value]) => {
|
@ -1,6 +1,6 @@
|
||||
import { ParseRule } from 'prosemirror-model'
|
||||
import { ExtensionAttribute } from '../types'
|
||||
import fromString from './fromString'
|
||||
import fromString from '../utilities/fromString'
|
||||
|
||||
/**
|
||||
* This function merges extension attributes into parserule attributes (`attrs` or `getAttrs`).
|
@ -2,7 +2,7 @@ import { EditorState } from 'prosemirror-state'
|
||||
import { Node, Mark } from 'prosemirror-model'
|
||||
import nodeIsActive from './nodeIsActive'
|
||||
import markIsActive from './markIsActive'
|
||||
import objectIncludes from './objectIncludes'
|
||||
import objectIncludes from '../utilities/objectIncludes'
|
||||
import getSchemaTypeNameByName from './getSchemaTypeNameByName'
|
||||
|
||||
export default function isActive(state: EditorState, name: string | null, attributes: { [key: string ]: any } = {}): boolean {
|
@ -1,6 +1,6 @@
|
||||
import { Extensions } from '../types'
|
||||
import splitExtensions from './splitExtensions'
|
||||
import callOrReturn from './callOrReturn'
|
||||
import callOrReturn from '../utilities/callOrReturn'
|
||||
|
||||
export default function isList(name: string, extensions: Extensions) {
|
||||
const { nodeExtensions } = splitExtensions(extensions)
|
@ -1,8 +1,8 @@
|
||||
import { EditorState } from 'prosemirror-state'
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import getMarkAttributes from './getMarkAttributes'
|
||||
import isEmptyObject from './isEmptyObject'
|
||||
import objectIncludes from './objectIncludes'
|
||||
import isEmptyObject from '../utilities/isEmptyObject'
|
||||
import objectIncludes from '../utilities/objectIncludes'
|
||||
|
||||
export default function markHasAttributes(state: EditorState, type: MarkType, attributes: {}) {
|
||||
if (isEmptyObject(attributes)) {
|
@ -8,10 +8,10 @@ export { default as nodeInputRule } from './inputRules/nodeInputRule'
|
||||
export { default as markInputRule } from './inputRules/markInputRule'
|
||||
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 getMarkAttributes } from './utils/getMarkAttributes'
|
||||
export { default as mergeAttributes } from './utils/mergeAttributes'
|
||||
export { default as getSchema } from './helpers/getSchema'
|
||||
export { default as generateHTML } from './helpers/generateHTML'
|
||||
export { default as getHTMLFromFragment } from './helpers/getHTMLFromFragment'
|
||||
export { default as getMarkAttributes } from './helpers/getMarkAttributes'
|
||||
export { default as mergeAttributes } from './utilities/mergeAttributes'
|
||||
|
||||
export interface AllExtensions {}
|
||||
|
@ -1,3 +0,0 @@
|
||||
export default function sleep(milliseconds: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, milliseconds))
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
import fromString from '@tiptap/core/src/utils/fromString'
|
||||
import fromString from '@tiptap/core/src/utilities/fromString'
|
||||
|
||||
describe('fromString', () => {
|
||||
it('should return a string', () => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/// <reference types="cypress" />
|
||||
|
||||
import mergeAttributes from '@tiptap/core/src/utils/mergeAttributes'
|
||||
import mergeAttributes from '@tiptap/core/src/utilities/mergeAttributes'
|
||||
|
||||
describe('mergeAttributes', () => {
|
||||
it('should merge two objects', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user