refactor style loading for the Editor
This commit is contained in:
@@ -10,6 +10,7 @@ import getMarkAttrs from './utils/getMarkAttrs'
|
|||||||
import removeElement from './utils/removeElement'
|
import removeElement from './utils/removeElement'
|
||||||
import getSchemaTypeByName from './utils/getSchemaTypeByName'
|
import getSchemaTypeByName from './utils/getSchemaTypeByName'
|
||||||
import getHtmlFromFragment from './utils/getHtmlFromFragment'
|
import getHtmlFromFragment from './utils/getHtmlFromFragment'
|
||||||
|
import createStyleTag from './utils/createStyleTag'
|
||||||
import CommandManager from './CommandManager'
|
import CommandManager from './CommandManager'
|
||||||
import ExtensionManager from './ExtensionManager'
|
import ExtensionManager from './ExtensionManager'
|
||||||
import EventEmitter from './EventEmitter'
|
import EventEmitter from './EventEmitter'
|
||||||
@@ -18,6 +19,7 @@ import Node from './Node'
|
|||||||
import Mark from './Mark'
|
import Mark from './Mark'
|
||||||
import defaultPlugins from './plugins'
|
import defaultPlugins from './plugins'
|
||||||
import * as coreCommands from './commands'
|
import * as coreCommands from './commands'
|
||||||
|
import style from './style'
|
||||||
|
|
||||||
export type Command = (props: {
|
export type Command = (props: {
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
@@ -118,10 +120,7 @@ export class Editor extends EventEmitter {
|
|||||||
this.extensionManager.resolveConfigs()
|
this.extensionManager.resolveConfigs()
|
||||||
this.createView()
|
this.createView()
|
||||||
this.registerCommands(coreCommands)
|
this.registerCommands(coreCommands)
|
||||||
|
this.injectCSS()
|
||||||
if (this.options.injectCSS) {
|
|
||||||
require('./style.css')
|
|
||||||
}
|
|
||||||
|
|
||||||
this.proxy.focus(this.options.autoFocus)
|
this.proxy.focus(this.options.autoFocus)
|
||||||
}
|
}
|
||||||
@@ -143,6 +142,15 @@ export class Editor extends EventEmitter {
|
|||||||
return this.commandManager.createChain()
|
return this.commandManager.createChain()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject CSS styles.
|
||||||
|
*/
|
||||||
|
private injectCSS() {
|
||||||
|
if (this.options.injectCSS && document) {
|
||||||
|
this.css = createStyleTag(style)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update editor options.
|
* Update editor options.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.ProseMirror {
|
const style = `.ProseMirror {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,4 +49,6 @@
|
|||||||
|
|
||||||
.ProseMirror-focused .ProseMirror-gapcursor {
|
.ProseMirror-focused .ProseMirror-gapcursor {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}`
|
||||||
|
|
||||||
|
export default style
|
||||||
8
packages/core/src/utils/createStyleTag.ts
Normal file
8
packages/core/src/utils/createStyleTag.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
export default function createStyleTag(style: string): HTMLStyleElement {
|
||||||
|
const styleNode = document.createElement('style')
|
||||||
|
|
||||||
|
styleNode.innerHTML = style
|
||||||
|
document.getElementsByTagName('head')[0].appendChild(styleNode)
|
||||||
|
|
||||||
|
return styleNode
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user