fix more linting errors

This commit is contained in:
Philipp Kühn 2020-09-24 00:29:05 +02:00
parent aefb4ca8e6
commit ac33eb483e
106 changed files with 310 additions and 274 deletions

View File

@ -34,6 +34,7 @@ module.exports = {
'global-require': 'off',
'func-names': ['error', 'never'],
'arrow-body-style': 'off',
'max-len': 'off',
'vue/this-in-template': ['error', 'never'],
'vue/max-attributes-per-line': ['error', {
singleline: 3,
@ -42,6 +43,9 @@ module.exports = {
allowFirstLine: false,
},
}],
'no-param-reassign': 'off',
'import/prefer-default-export': 'off',
'consistent-return': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error'],
},

View File

@ -23,7 +23,7 @@
</div>
<div class="demo__meta">
<div class="demo__name">
Demo/{{ this.name }}
Demo/{{ name }}
</div>
<a class="demo__link" :href="githubUrl" target="_blank">
Edit on GitHub
@ -31,7 +31,7 @@
</div>
</template>
<div v-else class="demo__error">
Could not find a demo called {{ this.name }}.
Could not find a demo called {{ name }}.
</div>
</div>
</template>
@ -66,7 +66,7 @@ export default {
hideSourceCode: {
type: Boolean,
default: false,
}
},
},
data() {
@ -106,7 +106,7 @@ export default {
},
mounted() {
this.files = collect(require.context(`~/demos/`, true, /.+\..+$/).keys())
this.files = collect(require.context('~/demos/', true, /.+\..+$/).keys())
.filter(path => path.startsWith(`./${this.name}`))
.map(path => path.replace('./', ''))
.map(path => {
@ -120,13 +120,13 @@ export default {
highlight: this.syntax[extension] || extension,
}
})
.filter((item) => {
.filter(item => {
return ['vue', 'jsx', 'scss'].includes(item.extension)
})
.sortBy(item => item.path.split('/').length)
.toArray()
}
},
}
</script>
<style lang="scss" src="./style.scss" scoped />
<style lang="scss" src="./style.scss" scoped />

View File

@ -51,8 +51,8 @@ export default {
previousPage() {
return this.items[this.currentIndex - 1]
},
}
},
}
</script>
<style lang="scss" src="./style.scss" scoped></style>
<style lang="scss" src="./style.scss" scoped></style>

View File

@ -34,11 +34,11 @@ export default {
methods: {
highlightCode() {
Prism.highlightAllUnder(this.$el)
}
},
},
mounted() {
this.highlightCode()
},
}
</script>
</script>

View File

@ -10,7 +10,7 @@ export default {
props: {
component: {
required: true,
}
},
},
mounted() {
@ -21,4 +21,4 @@ export default {
ReactDOM.unmountComponentAtNode(this.$el)
},
}
</script>
</script>

View File

@ -8,18 +8,18 @@ import { outdent } from '@mvasilkov/outdent'
export default {
data() {
return {
formattedCode: null
formattedCode: null,
}
},
methods: {
updateCode() {
const text = this.$slots.default[0].text
const { text } = this.$slots.default[0]
if (text) {
this.formattedCode = outdent(text)
}
}
},
},
beforeUpdate() {
@ -30,4 +30,4 @@ export default {
this.updateCode()
},
}
</script>
</script>

View File

@ -1,5 +1,5 @@
<template>
<pre>{{ this.html }}</pre>
<pre>{{ html }}</pre>
</template>
<script>
@ -9,22 +9,21 @@ import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
export default {
data() {
return {
doc: {
'type': 'document',
'content': [{
'type': 'paragraph',
'attrs': {
'align': 'left'
type: 'document',
content: [{
type: 'paragraph',
attrs: {
align: 'left',
},
'content': [{
'type': 'text',
'text': 'Example Text'
}]
}]
}
content: [{
type: 'text',
text: 'Example Text',
}],
}],
},
}
},
@ -35,8 +34,7 @@ export default {
Paragraph(),
Text(),
])
}
}
},
},
}
</script>
</script>

View File

@ -83,7 +83,7 @@ export default {
mounted() {
this.editor = new Editor({
extensions: defaultExtensions(),
content: `
content: `
<h2>
Hi there,
</h2>
@ -112,4 +112,4 @@ export default {
this.editor.destroy()
},
}
</script>
</script>

View File

@ -88,4 +88,4 @@ export default {
}
</script>
<style lang="scss" src="./style.scss">
<style lang="scss" src="./style.scss">

View File

@ -55,4 +55,4 @@ export default {
}
</script>
<style lang="scss" src="./style.scss">
<style lang="scss" src="./style.scss">

View File

@ -28,7 +28,7 @@ export default {
mounted() {
this.editor = new Editor({
content: `
content: `
<h2>
History
</h2>
@ -44,4 +44,4 @@ export default {
this.editor.destroy()
},
}
</script>
</script>

View File

@ -20,7 +20,7 @@ export default {
mounted() {
this.editor = new Editor({
content: `
content: `
<p>
Start a new line and type <code>#</code> followed by a space to get a headline. Try <code>#</code>, <code>##</code>, <code>###</code>, <code>####</code>, <code>#####</code>, <code>######</code> for different levels.
</p>
@ -39,4 +39,4 @@ export default {
this.editor.destroy()
},
}
</script>
</script>

View File

@ -49,4 +49,4 @@ export default {
}
</script>
<style lang="scss" src="./style.scss">
<style lang="scss" src="./style.scss">

View File

@ -41,4 +41,4 @@ export default {
this.editor.destroy()
},
}
</script>
</script>

View File

@ -38,4 +38,4 @@ export default {
this.editor.destroy()
},
}
</script>
</script>

View File

@ -46,6 +46,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -49,6 +49,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -48,6 +48,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -44,6 +44,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -59,6 +59,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -37,6 +37,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -52,6 +52,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -54,6 +54,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -46,6 +46,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -47,6 +47,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -46,6 +46,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -41,6 +41,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -68,6 +68,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -48,6 +48,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -37,6 +37,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -47,6 +47,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -37,6 +37,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -45,6 +45,6 @@ export default {
beforeDestroy() {
this.editor.destroy()
}
},
}
</script>
</script>

View File

@ -27,4 +27,4 @@ export default {
this.editor.destroy()
},
}
</script>
</script>

View File

@ -72,4 +72,4 @@ export default {
this.editor.destroy()
},
}
</script>
</script>

View File

@ -27,4 +27,4 @@ export default {
this.editor.destroy()
},
}
</script>
</script>

View File

@ -1,11 +1,15 @@
import React, { useState, useRef, useEffect, createContext, useContext } from 'react'
import {
useState, useRef, useEffect, createContext, useContext,
} from 'react'
import { Editor as Tiptap } from '@tiptap/core'
export const EditorContext = createContext({})
export const useEditor = () => useContext(EditorContext)
export const Editor = ({ value, onChange, children, ...props }) => {
export const Editor = ({
value, onChange, children, ...props
}) => {
const [editor, setEditor] = useState(null)
const editorRef = useRef(null)

View File

@ -1,6 +1,6 @@
import React, { useState } from 'react'
import { useEditor, Editor } from './components/Editor'
import { useState } from 'react'
import extensions from '@tiptap/starter-kit'
import { useEditor, Editor } from './components/Editor'
// Menu bar example component
// useEditor only works for child components of <Editor />
@ -24,39 +24,39 @@ const MenuBar = () => {
export default () => {
const [value, setValue] = useState({
'type': 'document',
'content': [
{
'type': 'paragraph',
'content': [
{
'type': 'text',
'text': 'rendered in '
},
{
'type': 'text',
'marks': [
{
'type': 'bold'
}
],
'text': 'react'
},
{
'type': 'text',
'text': '!'
}
]
}
]
})
type: 'document',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'rendered in ',
},
{
type: 'text',
marks: [
{
type: 'bold',
},
],
text: 'react',
},
{
type: 'text',
text: '!',
},
],
},
],
})
return (
<>
<p>
<button onClick={() => alert(JSON.stringify(value))}>Alert state</button>
</p>
<hr style={{ margin: '0.85rem 0'}} />
<hr style={{ margin: '0.85rem 0' }} />
<Editor
value={value}
onChange={setValue}

View File

@ -41,4 +41,4 @@ export default {
this.editor.destroy()
},
}
</script>
</script>

View File

@ -6,7 +6,7 @@
{{ $static.metadata.siteName }}
</g-link>
<div>
<input class="search" type="search" placeholder="Search" />
<input class="search" type="search" placeholder="Search">
<a href="https://github.com/sponsors/ueberdosis">
Sponsor
</a>
@ -58,9 +58,9 @@
</nav>
</div>
<main class="app__main">
<slot/>
<slot />
<p>
<br />
<br>
<a :href="editLink" target="_blank">
<span>Edit this page on GitHub</span>
</a>
@ -103,11 +103,11 @@ export default {
},
computed: {
currentPath () {
currentPath() {
return this.$route.matched[0].path
},
editLink () {
const currentPath = this.currentPath
editLink() {
const { currentPath } = this
const filePath = currentPath === '' ? '/introduction' : currentPath
return `https://github.com/ueberdosis/tiptap-next/blob/main/docs/src/docPages${filePath}.md`
@ -116,13 +116,14 @@ export default {
methods: {
initSearch() {
// eslint-disable-next-line
docsearch({
apiKey: '1abe7fb0f0dac150d0e963d2eda930fe',
indexName: 'ueberdosis_tiptap',
inputSelector: '.search',
debug: false,
})
}
},
},
mounted() {
@ -134,4 +135,4 @@ export default {
<style lang="scss" src="./fonts.scss"></style>
<style lang="scss" src="./base.scss"></style>
<style lang="scss" src="./prism.scss"></style>
<style lang="scss" src="./style.scss" scoped></style>
<style lang="scss" src="./style.scss" scoped></style>

View File

@ -35,4 +35,4 @@ export default {
}
</script>
<style lang="scss" src="./style.scss" scoped></style>
<style lang="scss" src="./style.scss" scoped></style>

View File

@ -6,4 +6,4 @@
</Layout>
</template>
<style lang="scss" src="./style.scss" scoped></style>
<style lang="scss" src="./style.scss" scoped></style>

View File

@ -1,10 +1,11 @@
import { EditorState, Transaction } from "prosemirror-state"
import { ChainedCommands, Editor, CommandSpec } from "./Editor"
import { EditorState, Transaction } from 'prosemirror-state'
import { ChainedCommands, Editor, CommandSpec } from './Editor'
import getAllMethodNames from './utils/getAllMethodNames'
export default class CommandManager {
editor: Editor
commands: { [key: string]: any } = {}
constructor(editor: Editor) {
@ -35,13 +36,13 @@ export default class CommandManager {
const { commands, editor } = this
const { state, view } = editor
const command = commands[name]
if (!command) {
// TODO: prevent vue devtools to throw error
// throw new Error(`tiptap: command '${name}' not found.`)
return
}
return (...args: any) => {
const { tr } = state
const props = this.buildProps(tr)
@ -87,7 +88,7 @@ export default class CommandManager {
return proxy
}
}
},
}) as ChainedCommands
}
@ -108,16 +109,16 @@ export default class CommandManager {
.map(([name, command]) => {
return [name, (...args: any[]) => command(...args)(props)]
}))
}
},
}
return props
}
public chainableState(tr: Transaction, state: EditorState): EditorState {
let selection = tr.selection
let doc = tr.doc
let storedMarks = tr.storedMarks
let { selection } = tr
let { doc } = tr
let { storedMarks } = tr
return {
...state,
@ -143,7 +144,7 @@ export default class CommandManager {
return tr
},
};
}
}
}
}

View File

@ -2,4 +2,4 @@ export default abstract class ComponentRenderer {
static type: string
}
}

View File

@ -1,5 +1,5 @@
import { EditorState, Plugin, Transaction } from 'prosemirror-state'
import { EditorView} from 'prosemirror-view'
import { EditorView } from 'prosemirror-view'
import { Schema, DOMParser, DOMSerializer } from 'prosemirror-model'
import magicMethods from './utils/magicMethods'
import elementFromString from './utils/elementFromString'
@ -18,7 +18,7 @@ import Node from './Node'
import Mark from './Mark'
import ComponentRenderer from './ComponentRenderer'
import defaultPlugins from './plugins'
import * as commands from './commands'
import * as coreCommands from './commands'
export type Command = (props: {
editor: Editor,
@ -77,14 +77,23 @@ declare module './Editor' {
export class Editor extends EventEmitter {
public renderer!: any
private proxy!: Editor
private commandManager!: CommandManager
private extensionManager!: ExtensionManager
private css!: HTMLStyleElement
public schema!: Schema
public view!: EditorView
public selection = { from: 0, to: 0 }
public isFocused = false
public options: EditorOptions = {
element: document.createElement('div'),
content: '',
@ -109,7 +118,7 @@ export class Editor extends EventEmitter {
this.createSchema()
this.extensionManager.resolveConfigs()
this.createView()
this.registerCommands(commands)
this.registerCommands(coreCommands)
if (this.options.injectCSS) {
require('./style.css')
@ -190,7 +199,7 @@ export class Editor extends EventEmitter {
* @param plugin A ProseMirror plugin
* @param handlePlugins Control how to merge the plugin into the existing plugins.
*/
public registerPlugin(plugin: Plugin, handlePlugins?: (plugin: Plugin, plugins: Plugin[]) => Plugin[]) {
public registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]) {
const plugins = typeof handlePlugins === 'function'
? handlePlugins(plugin, this.state.plugins)
: [plugin, ...this.state.plugins]
@ -333,7 +342,7 @@ export class Editor extends EventEmitter {
if (schemaType === 'node') {
return nodeIsActive(this.state, this.schema.nodes[name], attrs)
} else if (schemaType === 'mark') {
} if (schemaType === 'mark') {
return markIsActive(this.state, this.schema.marks[name])
}
@ -381,5 +390,5 @@ export class Editor extends EventEmitter {
this.removeAllListeners()
removeElement(this.css)
}
}

View File

@ -8,7 +8,7 @@ export default class EventEmitter {
}
this._callbacks[event].push(fn)
return this
}

View File

@ -41,8 +41,11 @@ export default class Extension<
Methods extends ExtensionMethods<Props, Options> = ExtensionMethods<Props, Options>
> {
type = 'extension'
config: AnyObject = {}
configs: Configs = {}
configs: Configs = {}
options: Partial<Options> = {}
protected storeConfig(key: string, value: any, stategy: MergeStrategy) {
@ -102,12 +105,10 @@ export default class Extension<
this.storeConfig(key, value, 'extend')
return this
}
public create() {
type ParentOptions = Options
return <Options = ParentOptions>(options?: Partial<NoInfer<Options>>) => {
return cloneDeep(this, true).configure(options as Options)
public create() {
return <NewOptions = Options>(options?: Partial<NoInfer<NewOptions>>) => {
return cloneDeep(this, true).configure(options as NewOptions)
}
}
}

View File

@ -2,10 +2,10 @@ import deepmerge from 'deepmerge'
import collect from 'collect.js'
import { Plugin } from 'prosemirror-state'
import { keymap } from 'prosemirror-keymap'
import { Schema } from 'prosemirror-model'
import { Schema, Node as ProsemirrorNode } from 'prosemirror-model'
import { inputRules } from 'prosemirror-inputrules'
import { EditorView, Decoration } from 'prosemirror-view'
import { Node as ProsemirrorNode } from 'prosemirror-model'
import { Editor } from './Editor'
import capitalize from './utils/capitalize'
import { Extensions } from './types'
@ -18,6 +18,7 @@ import getSchema from './utils/getSchema'
export default class ExtensionManager {
editor: Editor
extensions: Extensions
constructor(extensions: Extensions, editor: Editor) {
@ -28,17 +29,27 @@ export default class ExtensionManager {
resolveConfigs() {
this.extensions.forEach(extension => {
const { editor } = this
const name = extension.config.name
const { name } = extension.config
const options = deepmerge(extension.config.defaults, extension.options)
const type = extension.type === 'node'
? editor.schema.nodes[name]
: editor.schema.marks[name]
resolveExtensionConfig(extension, 'commands', { name, options, editor, type })
resolveExtensionConfig(extension, 'inputRules', { name, options, editor, type })
resolveExtensionConfig(extension, 'pasteRules', { name, options, editor, type })
resolveExtensionConfig(extension, 'keys', { name, options, editor, type })
resolveExtensionConfig(extension, 'plugins', { name, options, editor, type })
resolveExtensionConfig(extension, 'commands', {
name, options, editor, type,
})
resolveExtensionConfig(extension, 'inputRules', {
name, options, editor, type,
})
resolveExtensionConfig(extension, 'pasteRules', {
name, options, editor, type,
})
resolveExtensionConfig(extension, 'keys', {
name, options, editor, type,
})
resolveExtensionConfig(extension, 'plugins', {
name, options, editor, type,
})
if (extension.config.commands) {
editor.registerCommands(extension.config.commands)
@ -57,7 +68,7 @@ export default class ExtensionManager {
get nodes(): any {
return getNodesFromExtensions(this.extensions)
}
get marks(): any {
return getMarksFromExtensions(this.extensions)
}

View File

@ -25,4 +25,4 @@ export default class Mark<
this.storeConfig('schema', value, 'overwrite')
return this
}
}
}

View File

@ -1,5 +1,5 @@
import { Command } from '../Editor'
import { deleteSelection as originalDeleteSelection } from 'prosemirror-commands'
import { Command } from '../Editor'
type DeleteSelectionCommand = () => Command

View File

@ -1,7 +1,8 @@
import { Editor, Command } from '../Editor'
import { TextSelection } from 'prosemirror-state'
import { Editor, Command } from '../Editor'
import minMax from '../utils/minMax'
type Position = 'start' | 'end' | number | boolean | null
type FocusCommand = (position?: Position) => Command
declare module '../Editor' {
@ -15,8 +16,6 @@ interface ResolvedSelection {
to: number,
}
type Position = 'start' | 'end' | number | boolean | null
function resolveSelection(editor: Editor, position: Position = null): ResolvedSelection {
if (position === null) {
return editor.selection
@ -31,7 +30,7 @@ function resolveSelection(editor: Editor, position: Position = null): ResolvedSe
if (position === 'end') {
const { size } = editor.state.doc.content
return {
from: size,
to: size - 1, // TODO: -1 only for nodes with content
@ -54,9 +53,9 @@ export const focus: FocusCommand = (position = null) => ({ editor, view, tr }) =
const resolvedFrom = minMax(from, 0, doc.content.size)
const resolvedEnd = minMax(to, 0, doc.content.size)
const selection = TextSelection.create(doc, resolvedFrom, resolvedEnd)
tr.setSelection(selection)
view.focus()
return true
}
}

View File

@ -1,8 +1,8 @@
import { DOMParser } from 'prosemirror-model'
import { Selection, Transaction } from 'prosemirror-state'
import { ReplaceStep, ReplaceAroundStep } from 'prosemirror-transform'
import { Command } from '../Editor'
import elementFromString from '../utils/elementFromString'
import {ReplaceStep, ReplaceAroundStep} from "prosemirror-transform"
type InsertHTMLCommand = (value: string) => Command
@ -15,13 +15,13 @@ declare module '../Editor' {
// TODO: move to utils
// https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.js#L466
function selectionToInsertionEnd(tr: Transaction, startLen: number, bias: number) {
let last = tr.steps.length - 1
const last = tr.steps.length - 1
if (last < startLen) return
let step = tr.steps[last]
const step = tr.steps[last]
if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) return
let map = tr.mapping.maps[last]
const map = tr.mapping.maps[last]
let end = 0
map.forEach((_from, _to, _newFrom, newTo) => { if (end == 0) end = newTo })
map.forEach((_from, _to, _newFrom, newTo) => { if (end === 0) end = newTo })
tr.setSelection(Selection.near(tr.doc.resolve(end as unknown as number), bias))
}
@ -34,4 +34,4 @@ export const insertHTML: InsertHTMLCommand = value => ({ tr, state }) => {
selectionToInsertionEnd(tr, tr.steps.length - 1, -1)
return true
}
}

View File

@ -1,6 +1,6 @@
import { Command } from '../Editor'
import { liftListItem as originalLiftListItem } from 'prosemirror-schema-list'
import { NodeType } from 'prosemirror-model'
import { Command } from '../Editor'
import getNodeType from '../utils/getNodeType'
type LiftListItem = (typeOrName: string | NodeType) => Command
@ -11,7 +11,7 @@ declare module '../Editor' {
}
}
export const liftListItem: LiftListItem = (typeOrName) => ({ state, dispatch }) => {
export const liftListItem: LiftListItem = typeOrName => ({ state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)
return originalLiftListItem(type)(state, dispatch)

View File

@ -1,5 +1,5 @@
import { Command } from '../Editor'
import { MarkType } from 'prosemirror-model'
import { Command } from '../Editor'
import getMarkType from '../utils/getMarkType'
import getMarkRange from '../utils/getMarkRange'
@ -11,10 +11,12 @@ declare module '../Editor' {
}
}
export const removeMark: RemoveMarkCommand = (typeOrName) => ({ tr, state }) => {
export const removeMark: RemoveMarkCommand = typeOrName => ({ tr, state }) => {
const { selection } = tr
const type = getMarkType(typeOrName, state.schema)
let { from, to, $from, empty } = selection
let {
from, to, $from, empty,
} = selection
if (empty) {
const range = getMarkRange($from, type)

View File

@ -8,7 +8,7 @@ declare module '../Editor' {
}
}
export const removeMarks: RemoveMarksCommand = () => ({ tr, state, view }) => {
export const removeMarks: RemoveMarksCommand = () => ({ tr, state }) => {
const { selection } = tr
const { from, to, empty } = selection
@ -18,7 +18,7 @@ export const removeMarks: RemoveMarksCommand = () => ({ tr, state, view }) => {
Object
.entries(state.schema.marks)
.forEach(([name, mark]) => {
.forEach(([, mark]) => {
tr.removeMark(from, to, mark as any)
})

View File

@ -1,5 +1,5 @@
import { Command } from '../Editor'
import { NodeType } from 'prosemirror-model'
import { Command } from '../Editor'
import getNodeType from '../utils/getNodeType'
interface Range {
@ -29,7 +29,7 @@ export const replaceWithNode: ReplaceWithNodeCommand = (typeOrName, attrs = {},
if (!$from.parent.canReplaceWith(index, index, type)) {
return false
}
view.dispatch(tr.replaceWith(from, to, type.create(attrs)))
return true

View File

@ -1,5 +1,5 @@
import { Command } from '../Editor'
import { selectAll as originalSelectAll } from 'prosemirror-commands'
import { Command } from '../Editor'
type SelectAllCommand = () => Command

View File

@ -1,5 +1,5 @@
import { Command } from '../Editor'
import { selectParentNode as originalSelectParentNode } from 'prosemirror-commands'
import { Command } from '../Editor'
type SelectParentNodeCommand = () => Command

View File

@ -1,5 +1,5 @@
import { Command } from '../Editor'
import { TextSelection } from 'prosemirror-state'
import { Command } from '../Editor'
type SetContentCommand = (
content: string,
@ -18,7 +18,7 @@ export const setContent: SetContentCommand = (content = '', emitUpdate = false,
const { doc } = tr
const document = createDocument(content, parseOptions)
const selection = TextSelection.create(doc, 0, doc.content.size)
tr.setSelection(selection)
.replaceSelectionWith(document, false)
.setMeta('preventUpdate', !emitUpdate)

View File

@ -1,6 +1,6 @@
import { Command } from '../Editor'
import { sinkListItem as originalSinkListItem } from 'prosemirror-schema-list'
import { NodeType } from 'prosemirror-model'
import { Command } from '../Editor'
import getNodeType from '../utils/getNodeType'
type SinkListItem = (typeOrName: string | NodeType) => Command
@ -11,7 +11,7 @@ declare module '../Editor' {
}
}
export const sinkListItem: SinkListItem = (typeOrName) => ({ state, dispatch }) => {
export const sinkListItem: SinkListItem = typeOrName => ({ state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)
return originalSinkListItem(type)(state, dispatch)

View File

@ -1,6 +1,6 @@
import { Command } from '../Editor'
import { splitListItem as originalSplitListItem } from 'prosemirror-schema-list'
import { NodeType } from 'prosemirror-model'
import { Command } from '../Editor'
import getNodeType from '../utils/getNodeType'
type SplitListItem = (typeOrName: string | NodeType) => Command
@ -11,7 +11,7 @@ declare module '../Editor' {
}
}
export const splitListItem: SplitListItem = (typeOrName) => ({ state, dispatch }) => {
export const splitListItem: SplitListItem = typeOrName => ({ state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)
return originalSplitListItem(type)(state, dispatch)

View File

@ -1,7 +1,7 @@
import { Command } from '../Editor'
import { wrapInList, liftListItem } from 'prosemirror-schema-list'
import { findParentNode } from 'prosemirror-utils'
import { Node, NodeType, Schema } from 'prosemirror-model'
import { Command } from '../Editor'
import getNodeType from '../utils/getNodeType'
type ToggleListCommand = (

View File

@ -1,6 +1,6 @@
import { Command } from '../Editor'
import { toggleMark as originalToggleMark } from 'prosemirror-commands'
import { MarkType } from 'prosemirror-model'
import { Command } from '../Editor'
import getMarkType from '../utils/getMarkType'
type ToggleMarkCommand = (typeOrName: string | MarkType) => Command
@ -11,7 +11,7 @@ declare module '../Editor' {
}
}
export const toggleMark: ToggleMarkCommand = (typeOrName) => ({ state, dispatch }) => {
export const toggleMark: ToggleMarkCommand = typeOrName => ({ state, dispatch }) => {
const type = getMarkType(typeOrName, state.schema)
return originalToggleMark(type)(state, dispatch)

View File

@ -23,7 +23,7 @@ export const toggleNode: ToggleNodeCommand = (typeOrName, toggleTypeOrName, attr
if (isActive) {
return setBlockType(toggleType)(state, dispatch)
} else {
return setBlockType(type, attrs)(state, dispatch)
}
return setBlockType(type, attrs)(state, dispatch)
}

View File

@ -1,5 +1,5 @@
import { Command } from '../Editor'
import { MarkType } from 'prosemirror-model'
import { Command } from '../Editor'
import getMarkType from '../utils/getMarkType'
import getMarkRange from '../utils/getMarkRange'
@ -16,7 +16,8 @@ declare module '../Editor' {
export const updateMark: UpdateMarkCommand = (typeOrName, attrs = {}) => ({ tr, state }) => {
const { selection, doc } = tr
let { from, to, $from, empty } = selection
let { from, to } = selection
const { $from, empty } = selection
const type = getMarkType(typeOrName, state.schema)
if (empty) {

View File

@ -12,4 +12,4 @@ export default function (regexp: RegExp, type: NodeType, getAttrs?: Function) {
return tr
})
}
}

View File

@ -5,13 +5,13 @@ export default function (regexp: RegExp, type: MarkType, getAttrs?: Function) {
const handler = (fragment: Fragment, parent?: any) => {
const nodes: any[] = []
fragment.forEach(child => {
if (child.isText && child.text) {
const { text } = child
let pos = 0
let match
// eslint-disable-next-line
while ((match = regexp.exec(text)) !== null) {
const m = match.length - 1

View File

@ -6,4 +6,4 @@ export default (editor: Editor) => new Plugin({
props: {
editable: () => editor.options.editable,
},
})
})

View File

@ -25,4 +25,4 @@ export default (editor: Editor) => new Plugin({
},
},
},
})
})

View File

@ -2,9 +2,9 @@ import { keymap } from 'prosemirror-keymap'
import { baseKeymap } from 'prosemirror-commands'
import { dropCursor } from 'prosemirror-dropcursor'
import { gapCursor } from 'prosemirror-gapcursor'
import { undoInputRule } from 'prosemirror-inputrules'
import editable from './editable'
import focus from './focus'
import { undoInputRule } from 'prosemirror-inputrules'
export default [
() => dropCursor(),
@ -13,4 +13,4 @@ export default [
() => keymap(baseKeymap),
editable,
focus,
]
]

View File

@ -2,4 +2,4 @@ import Extension from './Extension'
import Node from './Node'
import Mark from './Mark'
export type Extensions = (Extension | Node | Mark)[]
export type Extensions = (Extension | Node | Mark)[]

View File

@ -1,3 +1,3 @@
export default function capitalize(value: string = ''): string {
return value.charAt(0).toUpperCase() + value.slice(1)
}
}

View File

@ -1,7 +1,7 @@
export default function elementFromString(value: string): HTMLElement {
const htmlString = `<div>${value}</div>`
const parser = new window.DOMParser
const parser = new window.DOMParser()
const element = parser.parseFromString(htmlString, 'text/html').body
return element
}
}

View File

@ -1,6 +1,6 @@
import { Node } from 'prosemirror-model'
import getSchema from './getSchema'
import getHtmlFromFragment from './getHtmlFromFragment'
import { Node } from 'prosemirror-model'
import { Extensions } from '../types'
export default function generateHtml(doc: object, extensions: Extensions): string {

View File

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

View File

@ -1,5 +1,4 @@
import { Node, DOMSerializer } from 'prosemirror-model'
import { Schema } from 'prosemirror-model'
import { Node, DOMSerializer, Schema } from 'prosemirror-model'
export default function getHtmlFromFragment(doc: Node, schema: Schema): string {
const fragment = DOMSerializer

View File

@ -1,5 +1,5 @@
import Mark from '../Mark'
import collect from 'collect.js'
import Mark from '../Mark'
import { Extensions } from '../types'
export default function getMarksFromExtensions(extensions: Extensions): any {
@ -7,4 +7,4 @@ export default function getMarksFromExtensions(extensions: Extensions): any {
.where('type', 'mark')
.mapWithKeys((extension: Mark) => [extension.config.name, extension.config.schema])
.all()
}
}

View File

@ -1,5 +1,5 @@
import Node from '../Node'
import collect from 'collect.js'
import Node from '../Node'
import { Extensions } from '../types'
export default function getNodesFromExtensions(extensions: Extensions): any {
@ -7,4 +7,4 @@ export default function getNodesFromExtensions(extensions: Extensions): any {
.where('type', 'node')
.mapWithKeys((extension: Node) => [extension.config.name, extension.config.schema])
.all()
}
}

View File

@ -12,7 +12,7 @@ export default function getSchema(extensions: Extensions): Schema {
resolveExtensionConfig(extension, 'defaults')
resolveExtensionConfig(extension, 'topNode')
const name = extension.config.name
const { name } = extension.config
const options = deepmerge(extension.config.defaults, extension.options)
resolveExtensionConfig(extension, 'schema', { name, options })

View File

@ -10,4 +10,4 @@ export default function getSchemaTypeByName(name: string, schema: Schema) {
}
return null
}
}

View File

@ -7,4 +7,4 @@ export default function getTopNodeFromExtensions(extensions: Extensions): any {
if (topNode) {
return topNode.config.name
}
}
}

View File

@ -1,10 +1,10 @@
export default function magicMethods(clazz: any) {
export default function magicMethods(Clazz: any) {
const classHandler = Object.create(null)
classHandler.construct = (target: any, args: any) => {
const instance = new clazz(...args)
classHandler.construct = (_, args: any) => {
const instance = new Clazz(...args)
const instanceHandler = Object.create(null)
const get = Object.getOwnPropertyDescriptor(clazz.prototype, '__get')
const get = Object.getOwnPropertyDescriptor(Clazz.prototype, '__get')
if (get) {
instanceHandler.get = (target: any, name: any) => {
@ -18,9 +18,9 @@ export default function magicMethods(clazz: any) {
if (exists) {
return target[name]
} else {
return get.value.call(target, name)
}
return get.value.call(target, name)
}
}
@ -30,5 +30,5 @@ export default function magicMethods(clazz: any) {
return instance.proxy
}
return new Proxy(clazz, classHandler)
}
return new Proxy(Clazz, classHandler)
}

View File

@ -1,3 +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

@ -2,4 +2,4 @@ export default function removeElement(element: HTMLElement) {
if (element && element.parentNode) {
element.parentNode.removeChild(element)
}
}
}

View File

@ -32,4 +32,4 @@ export default function resolveExtensionConfig(
return accumulator
}, undefined)
}
}

View File

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

View File

@ -35,5 +35,3 @@ export default new Node()
textblockTypeInputRule(inputRegex, type),
])
.create()

View File

@ -1,4 +1,6 @@
import { Command, Mark, markInputRule, markPasteRule } from '@tiptap/core'
import {
Command, Mark, markInputRule, markPasteRule,
} from '@tiptap/core'
export type BoldCommand = () => Command
@ -37,7 +39,7 @@ export default new Mark()
},
}))
.keys(({ editor }) => ({
'Mod-b': () => editor.bold()
'Mod-b': () => editor.bold(),
}))
.inputRules(({ type }) => [
markInputRule(starInputRegex, type),

View File

@ -29,7 +29,7 @@ export default new Node()
},
}))
.keys(({ editor }) => ({
'Shift-Ctrl-\\': () => editor.codeBlock()
'Shift-Ctrl-\\': () => editor.codeBlock(),
}))
.inputRules(({ type }) => [
textblockTypeInputRule(/^```$/, type),

View File

@ -1,4 +1,6 @@
import { Command, Mark, markInputRule, markPasteRule } from '@tiptap/core'
import {
Command, Mark, markInputRule, markPasteRule,
} from '@tiptap/core'
export type CodeCommand = () => Command
@ -26,12 +28,12 @@ export default new Mark()
},
}))
.keys(({ editor }) => ({
'Mod-`': () => editor.code()
'Mod-`': () => editor.code(),
}))
.inputRules(({ type }) => [
markInputRule(inputRegex, type)
markInputRule(inputRegex, type),
])
.pasteRules(({ type }) => [
markPasteRule(inputRegex, type)
markPasteRule(inputRegex, type),
])
.create()

View File

@ -6,4 +6,4 @@ export default new Node()
.schema(() => ({
content: 'block+',
}))
.create()
.create()

View File

@ -22,7 +22,7 @@ export default new Extension<FocusOptions>()
const decorations: Decoration[] = []
if (!isEditable || !isFocused) {
return
return DecorationSet.create(doc, [])
}
doc.descendants((node, pos) => {

View File

@ -20,8 +20,10 @@ export default new Node()
],
toDOM: () => ['br'],
}))
.commands(({ editor, type }) => ({
hardBreak: () => ({ tr, state, dispatch, view }) => {
.commands(({ type }) => ({
hardBreak: () => ({
tr, state, dispatch, view,
}) => {
return chainCommands(exitCode, () => {
dispatch(tr.replaceSelectionWith(type.create()).scrollIntoView())
return true

View File

@ -3,8 +3,6 @@ import {
history,
undo,
redo,
undoDepth,
redoDepth,
} from 'prosemirror-history'
declare module '@tiptap/core/src/Editor' {
@ -37,6 +35,6 @@ export default new Extension<HistoryOptions>()
'Shift-Mod-z': () => editor.redo(),
}))
.plugins(({ options }) => [
history(options.historyPluginOptions)
history(options.historyPluginOptions),
])
.create()

View File

@ -1,4 +1,6 @@
import { Command, Mark, markInputRule, markPasteRule } from '@tiptap/core'
import {
Command, Mark, markInputRule, markPasteRule,
} from '@tiptap/core'
export type ItalicCommand = () => Command
@ -29,7 +31,7 @@ export default new Mark()
},
}))
.keys(({ editor }) => ({
'Mod-i': () => editor.italic()
'Mod-i': () => editor.italic(),
}))
.inputRules(({ type }) => [
markInputRule(starInputRegex, type),

View File

@ -23,7 +23,7 @@ export default new Node()
tag: 'ol',
getAttrs: node => ({
order: (node as HTMLElement).hasAttribute('start')
? parseInt((node as HTMLElement).getAttribute('start') || '')
? parseInt((node as HTMLElement).getAttribute('start') || '', 10)
: 1,
}),
}],

View File

@ -10,4 +10,4 @@ export default new Node()
toDOM: () => ['p', 0],
// toVue: ParagraphComponent,
}))
.create()
.create()

View File

@ -6,4 +6,4 @@
export default {
}
</script>
</script>

View File

@ -1,4 +1,6 @@
import { Command, Mark, markInputRule, markPasteRule } from '@tiptap/core'
import {
Command, Mark, markInputRule, markPasteRule,
} from '@tiptap/core'
type StrikeCommand = () => Command
@ -26,7 +28,7 @@ export default new Mark()
},
{
style: 'text-decoration',
getAttrs: node => node === 'line-through' ? {} : false,
getAttrs: node => (node === 'line-through' ? {} : false),
},
],
toDOM: () => ['s', 0],
@ -37,12 +39,12 @@ export default new Mark()
},
}))
.keys(({ editor }) => ({
'Mod-d': () => editor.strike()
'Mod-d': () => editor.strike(),
}))
.inputRules(({ type }) => [
markInputRule(inputRegex, type)
markInputRule(inputRegex, type),
])
.pasteRules(({ type }) => [
markPasteRule(inputRegex, type)
markPasteRule(inputRegex, type),
])
.create()

View File

@ -5,4 +5,4 @@ export default new Node()
.schema(() => ({
group: 'inline',
}))
.create()
.create()

Some files were not shown because too many files have changed in this diff Show More