rename package folders

This commit is contained in:
Philipp Kühn
2020-03-30 10:42:59 +02:00
parent 18c5164af9
commit 14421a11fa
35 changed files with 2 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
export default function elementFromString(value: string): HTMLDivElement {
const element = document.createElement('div')
element.innerHTML = value.trim()
return element
}

View File

@@ -0,0 +1,10 @@
export default function getAllMethodNames(obj: Object) {
let methods = new Set()
while (obj = Reflect.getPrototypeOf(obj)) {
let keys = Reflect.ownKeys(obj)
keys.forEach((k) => methods.add(k))
}
return Array.from(methods)
}

View File

@@ -0,0 +1,19 @@
import { EditorState } from 'prosemirror-state'
import { Mark, MarkType } from 'prosemirror-model'
export default function getMarkAttrs(state: EditorState, type: MarkType) {
const { from, to } = state.selection
let marks: Mark[] = []
state.doc.nodesBetween(from, to, node => {
marks = [...marks, ...node.marks]
})
const mark = marks.find(markItem => markItem.type.name === type.name)
if (mark) {
return mark.attrs
}
return {}
}

View File

@@ -0,0 +1,15 @@
export default function injectCSS(css: string) {
if (process.env.NODE_ENV !== 'test') {
const style = document.createElement('style')
style.type = 'text/css'
style.textContent = css
const { head } = document
const { firstChild } = head
if (firstChild) {
head.insertBefore(style, firstChild)
} else {
head.appendChild(style)
}
}
}

View File

@@ -0,0 +1,31 @@
export default function magicMethods(clazz: any) {
const classHandler = Object.create(null)
classHandler.construct = (target: any, args: any) => {
const instance = new clazz(...args)
const instanceHandler = Object.create(null)
const get = Object.getOwnPropertyDescriptor(clazz.prototype, '__get')
if (get) {
instanceHandler.get = (target: any, name: any) => {
if (typeof name !== 'string') {
return
}
const exists = name in target || name.startsWith('_')
if (exists) {
return target[name]
} else {
return get.value.call(target, name)
}
}
}
instance.proxy = new Proxy(instance, instanceHandler)
return instance.proxy
}
return new Proxy(clazz, classHandler)
}

View File

@@ -0,0 +1,17 @@
import { EditorState } from 'prosemirror-state'
import { MarkType } from 'prosemirror-model'
export default function markIsActive(state: EditorState, type: MarkType) {
const {
from,
$from,
to,
empty,
} = state.selection
if (empty) {
return !!type.isInSet(state.storedMarks || $from.marks())
}
return !!state.doc.rangeHasMark(from, to, type)
}

View File

@@ -0,0 +1,3 @@
export default function minMax(value: number = 0, min: number = 0, max: number = 0): number {
return Math.min(Math.max(value, min), max)
}

View File

@@ -0,0 +1,15 @@
import { findParentNode, findSelectedNodeOfType } from 'prosemirror-utils'
import { EditorState } from 'prosemirror-state'
import { Node, NodeType } from 'prosemirror-model'
export default function nodeIsActive(state: EditorState, type: NodeType, attrs = {}) {
const predicate = (node: Node) => node.type === type
const node = findSelectedNodeOfType(type)(state.selection)
|| findParentNode(predicate)(state.selection)
if (!Object.keys(attrs).length || !node) {
return !!node
}
return node.node.hasMarkup(type, attrs)
}

View File

@@ -0,0 +1,3 @@
export default function sleep(milliseconds: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}