mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-19 06:43:02 +08:00
add placeholder extension
This commit is contained in:
parent
80ec395c3a
commit
db61d67156
36
examples/Components/Routes/Placeholder/index.vue
Normal file
36
examples/Components/Routes/Placeholder/index.vue
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<editor class="editor" :extensions="extensions">
|
||||||
|
<div class="editor__content" slot="content" slot-scope="props"></div>
|
||||||
|
</editor>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { Editor } from 'tiptap'
|
||||||
|
import { PlaceholderExtension } from 'tiptap-extensions'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
Editor,
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
extensions: [
|
||||||
|
new PlaceholderExtension(),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.editor p.is-empty:first-child::before {
|
||||||
|
content: 'Start typing…';
|
||||||
|
float: left;
|
||||||
|
color: #aaa;
|
||||||
|
pointer-events: none;
|
||||||
|
height: 0;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
</style>
|
@ -30,6 +30,9 @@
|
|||||||
<router-link class="subnavigation__link" to="/embeds">
|
<router-link class="subnavigation__link" to="/embeds">
|
||||||
Embeds
|
Embeds
|
||||||
</router-link>
|
</router-link>
|
||||||
|
<router-link class="subnavigation__link" to="/placeholder">
|
||||||
|
Placeholder
|
||||||
|
</router-link>
|
||||||
<router-link class="subnavigation__link" to="/export">
|
<router-link class="subnavigation__link" to="/export">
|
||||||
Export HTML or JSON
|
Export HTML or JSON
|
||||||
</router-link>
|
</router-link>
|
||||||
|
@ -13,6 +13,7 @@ import RouteMarkdownShortcuts from 'Components/Routes/MarkdownShortcuts'
|
|||||||
import RouteCodeHighlighting from 'Components/Routes/CodeHighlighting'
|
import RouteCodeHighlighting from 'Components/Routes/CodeHighlighting'
|
||||||
import RouteReadOnly from 'Components/Routes/ReadOnly'
|
import RouteReadOnly from 'Components/Routes/ReadOnly'
|
||||||
import RouteEmbeds from 'Components/Routes/Embeds'
|
import RouteEmbeds from 'Components/Routes/Embeds'
|
||||||
|
import RoutePlaceholder from 'Components/Routes/Placeholder'
|
||||||
import RouteExport from 'Components/Routes/Export'
|
import RouteExport from 'Components/Routes/Export'
|
||||||
|
|
||||||
const __svg__ = { path: './assets/images/icons/*.svg', name: 'assets/images/[hash].sprite.svg' }
|
const __svg__ = { path: './assets/images/icons/*.svg', name: 'assets/images/[hash].sprite.svg' }
|
||||||
@ -93,6 +94,13 @@ const routes = [
|
|||||||
githubUrl: 'https://github.com/heyscrumpy/tiptap/tree/master/examples/Components/Routes/Embeds',
|
githubUrl: 'https://github.com/heyscrumpy/tiptap/tree/master/examples/Components/Routes/Embeds',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/placeholder',
|
||||||
|
component: RoutePlaceholder,
|
||||||
|
meta: {
|
||||||
|
githubUrl: 'https://github.com/heyscrumpy/tiptap/tree/master/examples/Components/Routes/Placeholder',
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/export',
|
path: '/export',
|
||||||
component: RouteExport,
|
component: RouteExport,
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lowlight": "^1.10.0",
|
"lowlight": "^1.10.0",
|
||||||
"prosemirror-history": "^1.0.2",
|
"prosemirror-history": "^1.0.2",
|
||||||
|
"prosemirror-view": "^1.5.1",
|
||||||
"tiptap": "^0.10.0",
|
"tiptap": "^0.10.0",
|
||||||
"tiptap-commands": "^0.3.0"
|
"tiptap-commands": "^0.3.0"
|
||||||
}
|
}
|
||||||
|
39
packages/tiptap-extensions/src/extensions/Placeholder.js
Normal file
39
packages/tiptap-extensions/src/extensions/Placeholder.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { Extension, Plugin } from 'tiptap'
|
||||||
|
import { Decoration, DecorationSet } from 'prosemirror-view'
|
||||||
|
|
||||||
|
export default class PlaceholderExtension extends Extension {
|
||||||
|
|
||||||
|
get name() {
|
||||||
|
return 'placeholder'
|
||||||
|
}
|
||||||
|
|
||||||
|
get defaultOptions() {
|
||||||
|
return {
|
||||||
|
emptyNodeClass: 'is-empty',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get plugins() {
|
||||||
|
return [
|
||||||
|
new Plugin({
|
||||||
|
props: {
|
||||||
|
decorations: state => {
|
||||||
|
const decorations = []
|
||||||
|
|
||||||
|
state.doc.descendants((node, pos) => {
|
||||||
|
if (node.type.isBlock && node.childCount === 0) {
|
||||||
|
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
||||||
|
class: this.options.emptyNodeClass,
|
||||||
|
})
|
||||||
|
decorations.push(decoration)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return DecorationSet.create(state.doc, decorations)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -17,3 +17,4 @@ export { default as LinkMark } from './marks/Link'
|
|||||||
export { default as StrikeMark } from './marks/Strike'
|
export { default as StrikeMark } from './marks/Strike'
|
||||||
|
|
||||||
export { default as HistoryExtension } from './extensions/History'
|
export { default as HistoryExtension } from './extensions/History'
|
||||||
|
export { default as PlaceholderExtension } from './extensions/Placeholder'
|
||||||
|
@ -7791,7 +7791,7 @@ prosemirror-utils@^0.6.5:
|
|||||||
version "0.6.5"
|
version "0.6.5"
|
||||||
resolved "https://registry.yarnpkg.com/prosemirror-utils/-/prosemirror-utils-0.6.5.tgz#df18e39178d510917838a7337a8b64561324a70b"
|
resolved "https://registry.yarnpkg.com/prosemirror-utils/-/prosemirror-utils-0.6.5.tgz#df18e39178d510917838a7337a8b64561324a70b"
|
||||||
|
|
||||||
prosemirror-view@^1.0.0, prosemirror-view@^1.4.3:
|
prosemirror-view@^1.0.0, prosemirror-view@^1.4.3, prosemirror-view@^1.5.1:
|
||||||
version "1.5.1"
|
version "1.5.1"
|
||||||
resolved "https://registry.yarnpkg.com/prosemirror-view/-/prosemirror-view-1.5.1.tgz#545176a65124a89c9d16571797a9ef54853628c4"
|
resolved "https://registry.yarnpkg.com/prosemirror-view/-/prosemirror-view-1.5.1.tgz#545176a65124a89c9d16571797a9ef54853628c4"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
Loading…
Reference in New Issue
Block a user