Skip to content

Commit ba92632

Browse files
authored
Merge pull request #89 from editor-js/placeholder
feat(placeholder): update placeholder behavior
2 parents bdeab6d + ee9a685 commit ba92632

File tree

5 files changed

+15
-21
lines changed

5 files changed

+15
-21
lines changed

dist/paragraph.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".ce-paragraph{line-height:1.6em;outline:none}.ce-paragraph[data-placeholder]:empty:before{content:attr(data-placeholder);color:#707684;font-weight:400;opacity:0}.codex-editor--empty .ce-block:first-child .ce-paragraph[data-placeholder]:empty:before{opacity:1}.codex-editor--toolbox-opened .ce-block:first-child .ce-paragraph[data-placeholder]:empty:before,.codex-editor--empty .ce-block:first-child .ce-paragraph[data-placeholder]:empty:focus:before{opacity:0}.ce-paragraph p:first-of-type{margin-top:0}.ce-paragraph p:last-of-type{margin-bottom:0}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
1+
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".ce-paragraph{line-height:1.6em;outline:none}.ce-block:only-of-type .ce-paragraph[data-placeholder-active]:empty:before,.ce-block:only-of-type .ce-paragraph[data-placeholder-active][data-empty=true]:before{content:attr(data-placeholder-active)}.ce-paragraph p:first-of-type{margin-top:0}.ce-paragraph p:last-of-type{margin-bottom:0}")),document.head.appendChild(e)}}catch(a){console.error("vite-plugin-css-injected-by-js",a)}})();
22
const a = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M8 9V7.2C8 7.08954 8.08954 7 8.2 7L12 7M16 9V7.2C16 7.08954 15.9105 7 15.8 7L12 7M12 7L12 17M12 17H10M12 17H14"/></svg>';
33
function l(r) {
44
const t = document.createElement("div");
@@ -59,7 +59,7 @@ class n {
5959
*/
6060
drawView() {
6161
const t = document.createElement("DIV");
62-
return t.classList.add(this._CSS.wrapper, this._CSS.block), t.contentEditable = "false", t.dataset.placeholder = this.api.i18n.t(this._placeholder), this._data.text && (t.innerHTML = this._data.text), this.readOnly || (t.contentEditable = "true", t.addEventListener("keyup", this.onKeyUp)), t;
62+
return t.classList.add(this._CSS.wrapper, this._CSS.block), t.contentEditable = "false", t.dataset.placeholderActive = this.api.i18n.t(this._placeholder), this._data.text && (t.innerHTML = this._data.text), this.readOnly || (t.contentEditable = "true", t.addEventListener("keyup", this.onKeyUp)), t;
6363
}
6464
/**
6565
* Return Tool's view

dist/paragraph.umd.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@editorjs/paragraph",
3-
"version": "2.11.5",
3+
"version": "2.11.6",
44
"keywords": [
55
"codex editor",
66
"paragraph",

src/index.css

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@
33
outline: none;
44
}
55

6-
.ce-paragraph[data-placeholder]:empty::before{
7-
content: attr(data-placeholder);
8-
color: #707684;
9-
font-weight: normal;
10-
opacity: 0;
11-
}
12-
13-
/** Show placeholder at the first paragraph if Editor is empty */
14-
.codex-editor--empty .ce-block:first-child .ce-paragraph[data-placeholder]:empty::before {
15-
opacity: 1;
16-
}
17-
18-
.codex-editor--toolbox-opened .ce-block:first-child .ce-paragraph[data-placeholder]:empty::before,
19-
.codex-editor--empty .ce-block:first-child .ce-paragraph[data-placeholder]:empty:focus::before {
20-
opacity: 0;
6+
/**
7+
* Normally paragraph placeholder is shown only for the focused block (thanks to "data-placeholder-active").
8+
*
9+
* But there is a special case when the paragraph is the only block in the empty editor.
10+
* When editor autofocus=false, there will be no focus. We need to show the placeholder anyway.
11+
*/
12+
.ce-block:only-of-type .ce-paragraph[data-placeholder-active]:empty::before,
13+
.ce-block:only-of-type .ce-paragraph[data-placeholder-active][data-empty="true"]::before {
14+
content: attr(data-placeholder-active);
2115
}
2216

2317
.ce-paragraph p:first-of-type{

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export default class Paragraph {
212212

213213
div.classList.add(this._CSS.wrapper, this._CSS.block);
214214
div.contentEditable = 'false';
215-
div.dataset.placeholder = this.api.i18n.t(this._placeholder);
215+
div.dataset.placeholderActive = this.api.i18n.t(this._placeholder);
216216

217217
if (this._data.text) {
218218
div.innerHTML = this._data.text;

0 commit comments

Comments
 (0)