-
-
Save JSoon/bcbffb68c8666cb4e23e226600664795 to your computer and use it in GitHub Desktop.
Revisions
-
Andrew Kirwin revised this gist
Sep 16, 2021 . No changes.There are no files selected for viewing
-
Andrew Kirwin revised this gist
Sep 16, 2021 . 2 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes. -
Andrew Kirwin revised this gist
Sep 16, 2021 . 4 changed files with 16 additions and 61 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ .ProseMirror[data-placeholder]::before { color: global.$placeholder-colour; position: absolute; content: attr(data-placeholder); pointer-events: none; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,19 @@ import { Plugin } from 'prosemirror-state'; export default function placeholder(text) { const update = (view) => { if (view.state.doc.textContent) { view.dom.removeAttribute('data-placeholder'); } else { view.dom.setAttribute('data-placeholder', text); } }; return new Plugin({ view(view) { update(view); return { update }; } }); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,34 +0,0 @@ -
Andrew Kirwin revised this gist
Apr 19, 2021 . 2 changed files with 2 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,5 @@ .ProseMirror__placeholder::after { color: grey; position: absolute; content: attr(data-placeholder); pointer-events: none This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ .ProseMirror[data-placeholder]::before { color: grey; position: absolute; content: attr(data-placeholder); pointer-events: none; -
Andrew Kirwin renamed this gist
Apr 19, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Andrew Kirwin revised this gist
Apr 19, 2021 . 5 changed files with 49 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ import { Plugin } from 'prosemirror-state'; class PlaceholderPluginView { constructor(editor, text) { this.editor = editor; this.text = text; this._updatePlaceholder(); } update() { this._updatePlaceholder(); } _updatePlaceholder() { const doc = this.editor.state.doc; const hasNoChildren = doc.childCount === 0; const isEmptyTextBlock = doc.childCount === 1 && doc.firstChild.isTextblock && doc.firstChild.content.size === 0; if (hasNoChildren || isEmptyTextBlock) { this.editor.dom.setAttribute('data-placeholder', this.text); } else { this.editor.dom.removeAttribute('data-placeholder'); } } } export default function placeholder(text) { return new Plugin({ view(editor) { return new PlaceholderPluginView(editor, text); } }); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ .ProseMirror__placeholder { color: grey; } .ProseMirror__placeholder::after { position: absolute; content: attr(data-placeholder); pointer-events: none } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,6 @@ import { Plugin } from 'prosemirror-state'; import { Decoration, DecorationSet } from 'prosemirror-view'; export default function placeholderPlugin(text) { return new Plugin({ props: { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ .ProseMirror[data-placeholder]::before { color: global.$placeholder-colour; position: absolute; content: attr(data-placeholder); pointer-events: none; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +0,0 @@ -
Andrew Kirwin revised this gist
Apr 19, 2021 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,4 +11,5 @@ .ProseMirror__placeholder::after { position: absolute; content: attr(data-placeholder); pointer-events: none } -
Andrew Kirwin revised this gist
Apr 16, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { Plugin } from 'prosemirror-state'; import { Decoration, DecorationSet } from 'prosemirror-view'; /** * Placeholder plugin for prosemirror that supports documents with an inline, or a block schema. */ export default function placeholderPlugin(text) { -
Andrew Kirwin revised this gist
Apr 16, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ /** * Pseudo content is used, positioned absolutely. Because otherwise, when clicking into the editor, * the cursor would be placed at the _end_ of the placeholder text, and then flicker to the beginning * as prosemirror moves the decoration to the correct side. */ -
Andrew Kirwin created this gist
Apr 16, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ /** * Pseudo content is used, positioned absolutely. Because otherwise, when clicking in to the editor, * the cursor would be placed at the _end_ of the placeholder text, and then flicker to the beginning * as prosemirror moves the decoration to the correct side. */ .ProseMirror__placeholder { color: grey; } .ProseMirror__placeholder::after { position: absolute; content: attr(data-placeholder); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ import { Plugin } from 'prosemirror-state'; import { Decoration, DecorationSet } from 'prosemirror-view'; /** * Placeholder plugin for prosemirror that supports documents with an inline only schema, or a block schema. */ export default function placeholderPlugin(text) { return new Plugin({ props: { decorations(state) { const doc = state.doc; const hasNoChildren = doc.childCount === 0; const isEmptyTextBlock = doc.childCount === 1 && doc.firstChild.isTextblock && doc.firstChild.content.size === 0; if (hasNoChildren || isEmptyTextBlock) { const position = doc.inlineContent ? 0 : 1; const placeholder = document.createElement('span'); placeholder.classList.add('ProseMirror__placeholder'); placeholder.setAttribute('data-placeholder', text); return DecorationSet.create(doc, [Decoration.widget(position, placeholder)]); } } } }); }