mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-14 18:49:02 +08:00
add basic styling
This commit is contained in:
parent
0048040b68
commit
b3246f3ef4
@ -5,6 +5,7 @@ import flow from 'rollup-plugin-flow-no-whitespace'
|
|||||||
import cjs from 'rollup-plugin-commonjs'
|
import cjs from 'rollup-plugin-commonjs'
|
||||||
import node from 'rollup-plugin-node-resolve'
|
import node from 'rollup-plugin-node-resolve'
|
||||||
import replace from 'rollup-plugin-replace'
|
import replace from 'rollup-plugin-replace'
|
||||||
|
import cssOnly from 'rollup-plugin-css-only'
|
||||||
|
|
||||||
const resolve = _path => path.resolve(__dirname, '../../', _path)
|
const resolve = _path => path.resolve(__dirname, '../../', _path)
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ function genConfig(opts) {
|
|||||||
input: {
|
input: {
|
||||||
input: opts.input,
|
input: opts.input,
|
||||||
plugins: [
|
plugins: [
|
||||||
|
cssOnly({ output: false }),
|
||||||
flow(),
|
flow(),
|
||||||
node(),
|
node(),
|
||||||
cjs(),
|
cjs(),
|
||||||
|
@ -68,6 +68,7 @@
|
|||||||
"rollup": "^1.13.1",
|
"rollup": "^1.13.1",
|
||||||
"rollup-plugin-babel": "^4.3.2",
|
"rollup-plugin-babel": "^4.3.2",
|
||||||
"rollup-plugin-commonjs": "^10.0.0",
|
"rollup-plugin-commonjs": "^10.0.0",
|
||||||
|
"rollup-plugin-css-only": "^1.0.0",
|
||||||
"rollup-plugin-flow-no-whitespace": "^1.0.0",
|
"rollup-plugin-flow-no-whitespace": "^1.0.0",
|
||||||
"rollup-plugin-node-resolve": "^5.0.1",
|
"rollup-plugin-node-resolve": "^5.0.1",
|
||||||
"rollup-plugin-replace": "^2.2.0",
|
"rollup-plugin-replace": "^2.2.0",
|
||||||
|
@ -13,9 +13,14 @@ import { baseKeymap } from 'prosemirror-commands'
|
|||||||
import { inputRules, undoInputRule } from 'prosemirror-inputrules'
|
import { inputRules, undoInputRule } from 'prosemirror-inputrules'
|
||||||
import { markIsActive, nodeIsActive, getMarkAttrs } from 'tiptap-utils'
|
import { markIsActive, nodeIsActive, getMarkAttrs } from 'tiptap-utils'
|
||||||
import {
|
import {
|
||||||
camelCase, Emitter, ExtensionManager, ComponentView,
|
injectCSS,
|
||||||
|
camelCase,
|
||||||
|
Emitter,
|
||||||
|
ExtensionManager,
|
||||||
|
ComponentView,
|
||||||
} from './Utils'
|
} from './Utils'
|
||||||
import { Doc, Paragraph, Text } from './Nodes'
|
import { Doc, Paragraph, Text } from './Nodes'
|
||||||
|
import css from './style.css'
|
||||||
|
|
||||||
export default class Editor extends Emitter {
|
export default class Editor extends Emitter {
|
||||||
|
|
||||||
@ -39,6 +44,7 @@ export default class Editor extends Emitter {
|
|||||||
disablePasteRules: false,
|
disablePasteRules: false,
|
||||||
dropCursor: {},
|
dropCursor: {},
|
||||||
parseOptions: {},
|
parseOptions: {},
|
||||||
|
injectCSS: true,
|
||||||
onInit: () => {},
|
onInit: () => {},
|
||||||
onTransaction: () => {},
|
onTransaction: () => {},
|
||||||
onUpdate: () => {},
|
onUpdate: () => {},
|
||||||
@ -79,6 +85,10 @@ export default class Editor extends Emitter {
|
|||||||
this.commands = this.createCommands()
|
this.commands = this.createCommands()
|
||||||
this.setActiveNodesAndMarks()
|
this.setActiveNodesAndMarks()
|
||||||
|
|
||||||
|
if (this.options.injectCSS) {
|
||||||
|
injectCSS(css)
|
||||||
|
}
|
||||||
|
|
||||||
if (this.options.autoFocus !== null) {
|
if (this.options.autoFocus !== null) {
|
||||||
this.focus(this.options.autoFocus)
|
this.focus(this.options.autoFocus)
|
||||||
}
|
}
|
||||||
@ -254,16 +264,12 @@ export default class Editor extends Emitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createView() {
|
createView() {
|
||||||
const view = new EditorView(this.element, {
|
return new EditorView(this.element, {
|
||||||
state: this.createState(),
|
state: this.createState(),
|
||||||
handlePaste: (...args) => { this.emit('paste', ...args) },
|
handlePaste: (...args) => { this.emit('paste', ...args) },
|
||||||
handleDrop: (...args) => { this.emit('drop', ...args) },
|
handleDrop: (...args) => { this.emit('drop', ...args) },
|
||||||
dispatchTransaction: this.dispatchTransaction.bind(this),
|
dispatchTransaction: this.dispatchTransaction.bind(this),
|
||||||
})
|
})
|
||||||
|
|
||||||
view.dom.style.whiteSpace = 'pre-wrap'
|
|
||||||
|
|
||||||
return view
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setParentComponent(component = null) {
|
setParentComponent(component = null) {
|
||||||
|
@ -3,5 +3,6 @@ export { default as ComponentView } from './ComponentView'
|
|||||||
export { default as Emitter } from './Emitter'
|
export { default as Emitter } from './Emitter'
|
||||||
export { default as Extension } from './Extension'
|
export { default as Extension } from './Extension'
|
||||||
export { default as ExtensionManager } from './ExtensionManager'
|
export { default as ExtensionManager } from './ExtensionManager'
|
||||||
|
export { default as injectCSS } from './injectCSS'
|
||||||
export { default as Mark } from './Mark'
|
export { default as Mark } from './Mark'
|
||||||
export { default as Node } from './Node'
|
export { default as Node } from './Node'
|
||||||
|
13
packages/tiptap/src/Utils/injectCSS.js
Normal file
13
packages/tiptap/src/Utils/injectCSS.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
export default function (css) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
40
packages/tiptap/src/style.css
Normal file
40
packages/tiptap/src/style.css
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
.ProseMirror {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ProseMirror {
|
||||||
|
word-wrap: break-word;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
-webkit-font-variant-ligatures: none;
|
||||||
|
font-variant-ligatures: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ProseMirror pre {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ProseMirror-gapcursor {
|
||||||
|
display: none;
|
||||||
|
pointer-events: none;
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ProseMirror-gapcursor:after {
|
||||||
|
content: "";
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: -2px;
|
||||||
|
width: 20px;
|
||||||
|
border-top: 1px solid black;
|
||||||
|
animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes ProseMirror-cursor-blink {
|
||||||
|
to {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.ProseMirror-focused .ProseMirror-gapcursor {
|
||||||
|
display: block;
|
||||||
|
}
|
10
yarn.lock
10
yarn.lock
@ -10531,6 +10531,14 @@ rollup-plugin-commonjs@^10.0.0:
|
|||||||
resolve "^1.10.1"
|
resolve "^1.10.1"
|
||||||
rollup-pluginutils "^2.7.0"
|
rollup-pluginutils "^2.7.0"
|
||||||
|
|
||||||
|
rollup-plugin-css-only@^1.0.0:
|
||||||
|
version "1.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/rollup-plugin-css-only/-/rollup-plugin-css-only-1.0.0.tgz#dc027d657d02e7706b855d856dcb0fdd49935135"
|
||||||
|
integrity sha512-WY8bISLKzWCnUmHMOhsgbQ/bZz1J1eigwMROixTWZb4yPrMCA4vbfQog6n3bsOQMfq39Kih6jWY9Xn9rYjiqXw==
|
||||||
|
dependencies:
|
||||||
|
mkdirp "^0.5.1"
|
||||||
|
rollup-pluginutils "^2.3.3"
|
||||||
|
|
||||||
rollup-plugin-flow-no-whitespace@^1.0.0:
|
rollup-plugin-flow-no-whitespace@^1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/rollup-plugin-flow-no-whitespace/-/rollup-plugin-flow-no-whitespace-1.0.0.tgz#bd4ba1bcd99ad5b88234d72e6e2dacea9aa02d16"
|
resolved "https://registry.yarnpkg.com/rollup-plugin-flow-no-whitespace/-/rollup-plugin-flow-no-whitespace-1.0.0.tgz#bd4ba1bcd99ad5b88234d72e6e2dacea9aa02d16"
|
||||||
@ -10581,7 +10589,7 @@ rollup-pluginutils@^1.5.2:
|
|||||||
estree-walker "^0.2.1"
|
estree-walker "^0.2.1"
|
||||||
minimatch "^3.0.2"
|
minimatch "^3.0.2"
|
||||||
|
|
||||||
rollup-pluginutils@^2.3.0, rollup-pluginutils@^2.4.1, rollup-pluginutils@^2.6.0, rollup-pluginutils@^2.7.0, rollup-pluginutils@^2.8.0:
|
rollup-pluginutils@^2.3.0, rollup-pluginutils@^2.3.3, rollup-pluginutils@^2.4.1, rollup-pluginutils@^2.6.0, rollup-pluginutils@^2.7.0, rollup-pluginutils@^2.8.0:
|
||||||
version "2.8.1"
|
version "2.8.1"
|
||||||
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.8.1.tgz#8fa6dd0697344938ef26c2c09d2488ce9e33ce97"
|
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.8.1.tgz#8fa6dd0697344938ef26c2c09d2488ce9e33ce97"
|
||||||
integrity sha512-J5oAoysWar6GuZo0s+3bZ6sVZAC0pfqKz68De7ZgDi5z63jOVZn1uJL/+z1jeKHNbGII8kAyHF5q8LnxSX5lQg==
|
integrity sha512-J5oAoysWar6GuZo0s+3bZ6sVZAC0pfqKz68De7ZgDi5z63jOVZn1uJL/+z1jeKHNbGII8kAyHF5q8LnxSX5lQg==
|
||||||
|
Loading…
Reference in New Issue
Block a user