resolve all configs
This commit is contained in:
@@ -23,35 +23,56 @@ export default class ExtensionManager {
|
|||||||
this.extensions = extensions
|
this.extensions = extensions
|
||||||
|
|
||||||
this.extensions.forEach(extension => {
|
this.extensions.forEach(extension => {
|
||||||
const simpleConfigs = ['name', 'defaults']
|
this.resolveConfig(extension, 'name')
|
||||||
|
this.resolveConfig(extension, 'defaults')
|
||||||
|
this.resolveConfig(extension, 'topNode')
|
||||||
|
this.resolveConfig(extension, 'schema', ['name', 'options'])
|
||||||
|
|
||||||
Object
|
editor.on('schemaCreated', () => {
|
||||||
.entries(extension.configs)
|
this.resolveConfig(extension, 'commands', ['name', 'options', 'editor', 'type'])
|
||||||
.sort(([name]) => simpleConfigs.includes(name) ? -1 : 1)
|
this.resolveConfig(extension, 'inputRules', ['name', 'options', 'editor', 'type'])
|
||||||
.forEach(([name, configs]) => {
|
this.resolveConfig(extension, 'pasteRules', ['name', 'options', 'editor', 'type'])
|
||||||
extension.config[name] = configs.reduce((accumulator, { stategy, value: rawValue }) => {
|
this.resolveConfig(extension, 'keys', ['name', 'options', 'editor', 'type'])
|
||||||
const isSimpleConfig = simpleConfigs.includes(name)
|
this.resolveConfig(extension, 'plugins', ['name', 'options', 'editor', 'type'])
|
||||||
const props = isSimpleConfig
|
|
||||||
? undefined
|
|
||||||
: {
|
|
||||||
editor,
|
|
||||||
options: deepmerge(extension.config.defaults, extension.options),
|
|
||||||
// TODO: type is not available here
|
|
||||||
// get type() {
|
|
||||||
// console.log('called', editor.schema)
|
|
||||||
|
|
||||||
// if (!editor.schema) {
|
if (extension.config.commands) {
|
||||||
// return
|
this.editor.registerCommands(extension.config.commands)
|
||||||
// }
|
|
||||||
|
|
||||||
// if (extension.type === 'node') {
|
|
||||||
// return editor.schema.nodes[extension.config.name]
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return editor.schema.marks[extension.config.name]
|
|
||||||
// },
|
|
||||||
name: extension.config.name,
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
resolveConfig(
|
||||||
|
extension: Extension | Node | Mark,
|
||||||
|
name: string,
|
||||||
|
propValues: ('name' | 'options' | 'editor' | 'type')[] = []
|
||||||
|
) {
|
||||||
|
if (!extension.configs[name]) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
extension.config[name] = extension.configs[name]
|
||||||
|
.reduce((accumulator, { stategy, value: rawValue }) => {
|
||||||
|
const props: any = {}
|
||||||
|
|
||||||
|
if (propValues.includes('name')) {
|
||||||
|
props.name = extension.config.name
|
||||||
|
}
|
||||||
|
|
||||||
|
if (propValues.includes('options')) {
|
||||||
|
props.options = deepmerge(extension.config.defaults, extension.options)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (propValues.includes('editor')) {
|
||||||
|
props.editor = this.editor
|
||||||
|
}
|
||||||
|
|
||||||
|
if (propValues.includes('type')) {
|
||||||
|
props.type = extension.type === 'node'
|
||||||
|
? this.editor.schema.nodes[extension.config.name]
|
||||||
|
: this.editor.schema.marks[extension.config.name]
|
||||||
|
}
|
||||||
|
|
||||||
const value = typeof rawValue === 'function'
|
const value = typeof rawValue === 'function'
|
||||||
? rawValue(props)
|
? rawValue(props)
|
||||||
: rawValue
|
: rawValue
|
||||||
@@ -70,14 +91,6 @@ export default class ExtensionManager {
|
|||||||
|
|
||||||
return accumulator
|
return accumulator
|
||||||
}, undefined)
|
}, undefined)
|
||||||
})
|
|
||||||
|
|
||||||
editor.on('schemaCreated', () => {
|
|
||||||
if (extension.config.commands) {
|
|
||||||
this.editor.registerCommands(extension.config.commands)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get topNode() {
|
get topNode() {
|
||||||
|
|||||||
@@ -50,19 +50,19 @@ export default new Mark()
|
|||||||
return markInputRule(regex, type)
|
return markInputRule(regex, type)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
// .pasteRules(({ type }) => {
|
.pasteRules(({ type }) => {
|
||||||
// return ['**', '__'].map(character => {
|
return ['**', '__'].map(character => {
|
||||||
// const regex = VerEx()
|
const regex = VerEx()
|
||||||
// .add('(?:^|\\s)')
|
.add('(?:^|\\s)')
|
||||||
// .beginCapture()
|
.beginCapture()
|
||||||
// .find(character)
|
.find(character)
|
||||||
// .beginCapture()
|
.beginCapture()
|
||||||
// .somethingBut(character)
|
.somethingBut(character)
|
||||||
// .endCapture()
|
.endCapture()
|
||||||
// .find(character)
|
.find(character)
|
||||||
// .endCapture()
|
.endCapture()
|
||||||
|
|
||||||
// return markPasteRule(regex, type)
|
return markPasteRule(regex, type)
|
||||||
// })
|
})
|
||||||
// })
|
})
|
||||||
.create()
|
.create()
|
||||||
|
|||||||
@@ -25,31 +25,31 @@ export default new Mark()
|
|||||||
.keys(({ editor }) => ({
|
.keys(({ editor }) => ({
|
||||||
'Mod-`': () => editor.code()
|
'Mod-`': () => editor.code()
|
||||||
}))
|
}))
|
||||||
// .inputRules(({ type }) => {
|
.inputRules(({ type }) => {
|
||||||
// const regex = VerEx()
|
const regex = VerEx()
|
||||||
// .add('(?:^|\\s)')
|
.add('(?:^|\\s)')
|
||||||
// .beginCapture()
|
.beginCapture()
|
||||||
// .find('`')
|
.find('`')
|
||||||
// .beginCapture()
|
.beginCapture()
|
||||||
// .somethingBut('`')
|
.somethingBut('`')
|
||||||
// .endCapture()
|
.endCapture()
|
||||||
// .find('`')
|
.find('`')
|
||||||
// .endCapture()
|
.endCapture()
|
||||||
// .endOfLine()
|
.endOfLine()
|
||||||
|
|
||||||
// return [markInputRule(regex, type)]
|
return [markInputRule(regex, type)]
|
||||||
// })
|
})
|
||||||
// .pasteRules(({ type }) => {
|
.pasteRules(({ type }) => {
|
||||||
// const regex = VerEx()
|
const regex = VerEx()
|
||||||
// .add('(?:^|\\s)')
|
.add('(?:^|\\s)')
|
||||||
// .beginCapture()
|
.beginCapture()
|
||||||
// .find('`')
|
.find('`')
|
||||||
// .beginCapture()
|
.beginCapture()
|
||||||
// .somethingBut('`')
|
.somethingBut('`')
|
||||||
// .endCapture()
|
.endCapture()
|
||||||
// .find('`')
|
.find('`')
|
||||||
// .endCapture()
|
.endCapture()
|
||||||
|
|
||||||
// return [markPasteRule(regex, type)]
|
return [markPasteRule(regex, type)]
|
||||||
// })
|
})
|
||||||
.create()
|
.create()
|
||||||
|
|||||||
@@ -43,16 +43,16 @@ export default new Node<HeadingOptions>()
|
|||||||
next()
|
next()
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
// .inputRules(({ options, type }) => {
|
.inputRules(({ options, type }) => {
|
||||||
// return options.levels.map((level: Level) => {
|
return options.levels.map((level: Level) => {
|
||||||
// const regex = VerEx()
|
const regex = VerEx()
|
||||||
// .startOfLine()
|
.startOfLine()
|
||||||
// .find('#')
|
.find('#')
|
||||||
// .repeatPrevious(level)
|
.repeatPrevious(level)
|
||||||
// .whitespace()
|
.whitespace()
|
||||||
// .endOfLine()
|
.endOfLine()
|
||||||
|
|
||||||
// return textblockTypeInputRule(regex, type, { level })
|
return textblockTypeInputRule(regex, type, { level })
|
||||||
// })
|
})
|
||||||
// })
|
})
|
||||||
.create()
|
.create()
|
||||||
|
|||||||
@@ -26,35 +26,35 @@ export default new Mark()
|
|||||||
.keys(({ editor }) => ({
|
.keys(({ editor }) => ({
|
||||||
'Mod-i': () => editor.italic()
|
'Mod-i': () => editor.italic()
|
||||||
}))
|
}))
|
||||||
// .inputRules(({ type }) => {
|
.inputRules(({ type }) => {
|
||||||
// return ['*', '_'].map(character => {
|
return ['*', '_'].map(character => {
|
||||||
// const regex = VerEx()
|
const regex = VerEx()
|
||||||
// .add('(?:^|\\s)')
|
.add('(?:^|\\s)')
|
||||||
// .beginCapture()
|
.beginCapture()
|
||||||
// .find(character)
|
.find(character)
|
||||||
// .beginCapture()
|
.beginCapture()
|
||||||
// .somethingBut(character)
|
.somethingBut(character)
|
||||||
// .endCapture()
|
.endCapture()
|
||||||
// .find(character)
|
.find(character)
|
||||||
// .endCapture()
|
.endCapture()
|
||||||
// .endOfLine()
|
.endOfLine()
|
||||||
|
|
||||||
// return markInputRule(regex, type)
|
return markInputRule(regex, type)
|
||||||
// })
|
})
|
||||||
// })
|
})
|
||||||
// .pasteRules(({ type }) => {
|
.pasteRules(({ type }) => {
|
||||||
// return ['*', '_'].map(character => {
|
return ['*', '_'].map(character => {
|
||||||
// const regex = VerEx()
|
const regex = VerEx()
|
||||||
// .add('(?:^|\\s)')
|
.add('(?:^|\\s)')
|
||||||
// .beginCapture()
|
.beginCapture()
|
||||||
// .find(character)
|
.find(character)
|
||||||
// .beginCapture()
|
.beginCapture()
|
||||||
// .somethingBut(character)
|
.somethingBut(character)
|
||||||
// .endCapture()
|
.endCapture()
|
||||||
// .find(character)
|
.find(character)
|
||||||
// .endCapture()
|
.endCapture()
|
||||||
|
|
||||||
// return markPasteRule(regex, type)
|
return markPasteRule(regex, type)
|
||||||
// })
|
})
|
||||||
// })
|
})
|
||||||
.create()
|
.create()
|
||||||
|
|||||||
Reference in New Issue
Block a user