fix broken input rules

This commit is contained in:
Philipp Kühn
2020-10-23 09:20:26 +02:00
parent e360d010c6
commit 73285aadce
3 changed files with 22 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ import { keymap } from 'prosemirror-keymap'
// import { Schema, Node as ProsemirrorNode } from 'prosemirror-model'
import { inputRules } from 'prosemirror-inputrules'
// import { EditorView, Decoration } from 'prosemirror-view'
import { Schema } from 'prosemirror-model'
import { Editor } from './Editor'
// import capitalize from './utils/capitalize'
import { Extensions } from './types'
@@ -13,11 +14,14 @@ export default class ExtensionManager {
editor: Editor
schema: Schema
extensions: Extensions
constructor(extensions: Extensions, editor: Editor) {
this.editor = editor
this.extensions = extensions
this.schema = getSchema(this.extensions)
this.extensions.forEach(extension => {
const context = {
@@ -32,10 +36,6 @@ export default class ExtensionManager {
})
}
get schema() {
return getSchema(this.extensions)
}
get plugins(): Plugin[] {
const plugins = this.extensions
.map(extension => {

View File

@@ -3,6 +3,17 @@ import { Extensions } from '../types'
import splitExtensions from './splitExtensions'
import getAttributesFromExtensions from './getAttributesFromExtensions'
import getRenderedAttributes from './getRenderedAttributes'
import isEmptyObject from './isEmptyObject'
function cleanUpSchemaItem(data: any) {
return Object.fromEntries(Object.entries(data).filter(([key, value]) => {
if (key === 'attrs' && isEmptyObject(value)) {
return false
}
return value !== null && value !== undefined
}))
}
export default function getSchema(extensions: Extensions): Schema {
const allAttributes = getAttributesFromExtensions(extensions)
@@ -16,7 +27,7 @@ export default function getSchema(extensions: Extensions): Schema {
const attributes = allAttributes.filter(attribute => attribute.type === extension.name)
const schema: NodeSpec = {
const schema: NodeSpec = cleanUpSchemaItem({
content: extension.content,
marks: extension.marks,
group: extension.group,
@@ -37,7 +48,7 @@ export default function getSchema(extensions: Extensions): Schema {
attrs: Object.fromEntries(attributes.map(attribute => {
return [attribute.name, { default: attribute?.attribute?.default }]
})),
}
})
return [extension.name, schema]
}))
@@ -49,7 +60,7 @@ export default function getSchema(extensions: Extensions): Schema {
const attributes = allAttributes.filter(attribute => attribute.type === extension.name)
const schema: MarkSpec = {
const schema: MarkSpec = cleanUpSchemaItem({
inclusive: extension.inclusive,
excludes: extension.excludes,
group: extension.group,
@@ -64,7 +75,7 @@ export default function getSchema(extensions: Extensions): Schema {
attrs: Object.fromEntries(attributes.map(attribute => {
return [attribute.name, { default: attribute?.attribute?.default }]
})),
}
})
return [extension.name, schema]
}))

View File

@@ -0,0 +1,3 @@
export default function isEmptyObject(object = {}) {
return Object.keys(object).length === 0 && object.constructor === Object
}