Skip to content

Commit e78ca82

Browse files
committed
Update the placeholder plugin and move + import styles
1 parent adaae33 commit e78ca82

File tree

8 files changed

+33
-29
lines changed

8 files changed

+33
-29
lines changed

prosemirror-footnotes/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"main": "dist",
88
"files": [
99
"dist",
10-
"src"
10+
"src",
11+
"style"
1112
],
1213
"publishConfig": {
1314
"access": "public"

prosemirror-footnotes/src/footnotes.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { Plugin } from 'prosemirror-state'
22
import FootnoteView from './FootnoteView'
33

4-
import './footnotes.css'
5-
64
export default options => {
75
return new Plugin({
86
props: {

prosemirror-placeholder/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"main": "dist",
88
"files": [
99
"dist",
10-
"src"
10+
"src",
11+
"style"
1112
],
1213
"publishConfig": {
1314
"access": "public"

prosemirror-placeholder/src/placeholder.css

Lines changed: 0 additions & 5 deletions
This file was deleted.

prosemirror-placeholder/src/placeholder.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
import { Plugin } from 'prosemirror-state'
2-
import { DecorationSet, Decoration } from 'prosemirror-view'
2+
import { Decoration, DecorationSet } from 'prosemirror-view'
33

4-
import './placeholder.css'
5-
6-
const isEmpty = doc => (
7-
doc.childCount === 1 &&
8-
doc.firstChild.isTextblock &&
9-
doc.firstChild.content.size === 0
10-
)
11-
12-
export default options => {
4+
export default () => {
135
return new Plugin({
146
props: {
157
decorations: state => {
16-
if (!isEmpty(state.doc)) return null
8+
const decorations = []
9+
10+
const decorate = (node, pos) => {
11+
if (node.type.isBlock && node.childCount === 0) {
12+
decorations.push(
13+
Decoration.node(pos, pos + node.nodeSize, {
14+
class: 'empty-node'
15+
})
16+
)
17+
}
18+
}
1719

18-
const node = document.createElement('div')
19-
node.textContent = options.content
20-
node.className = 'placeholder'
20+
state.doc.descendants(decorate)
2121

22-
return DecorationSet.create(state.doc, [
23-
Decoration.widget(1, node)
24-
])
22+
return DecorationSet.create(state.doc, decorations)
2523
}
2624
}
2725
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.ProseMirror .empty-node::before {
2+
float: left;
3+
color: #aaa;
4+
pointer-events: none;
5+
height: 0;
6+
font-style: italic;
7+
}
8+
9+
.ProseMirror p.empty-node:first-child::before {
10+
content: 'Start typing…';
11+
}

react-prosemirror-config-default/src/plugins.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import { footnotes } from '@aeaton/prosemirror-footnotes'
77

88
import 'prosemirror-tables/style/tables.css'
99
import 'prosemirror-gapcursor/style/gapcursor.css'
10+
import '@aeaton/prosemirror-footnotes/style/footnotes.css'
11+
import '@aeaton/prosemirror-placeholder/style/placeholder.css'
1012

1113
import keys from './keys'
1214
import rules from './rules'
1315

1416
export default [
1517
rules,
1618
keys,
17-
placeholder({
18-
content: 'Start typing…'
19-
}),
19+
placeholder(),
2020
footnotes(),
2121
dropCursor(),
2222
gapCursor(),

0 commit comments

Comments
 (0)