editorjs-style
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -5,3 +5,7 @@ import type { InlineTool, InlineToolConstructorOptions } from '@editorjs/editorjs'; | ||
static get sanitize(): { | ||
'editorjs-style': boolean; | ||
'editorjs-style': { | ||
class: boolean; | ||
id: boolean; | ||
style: boolean; | ||
}; | ||
}; | ||
@@ -8,0 +12,0 @@ static get title(): string; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.EditorJSStyle=t():e.EditorJSStyle=t()}(window,(function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var s=t[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(i,s,function(t){return e[t]}.bind(null,s));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);class i extends HTMLElement{constructor(){super(),this.addEventListener("keydown",e=>e.stopPropagation());new MutationObserver(()=>{var e,t,n,i,s,o;"#text"===(null===(e=this.firstChild)||void 0===e?void 0:e.nodeName)&&""===(null===(n=null===(t=this.firstChild)||void 0===t?void 0:t.textContent)||void 0===n?void 0:n.slice(0,1))||this.prepend(""),"#text"===(null===(i=this.lastChild)||void 0===i?void 0:i.nodeName)&&""===(null===(o=null===(s=this.lastChild)||void 0===s?void 0:s.textContent)||void 0===o?void 0:o.slice(-1))||this.append("")}).observe(this,{characterData:!0,childList:!0,subtree:!0})}}var s=i;var o=class{constructor({api:e}){this.actions=document.createElement("div"),this.api=e,customElements.get("editorjs-style")||customElements.define("editorjs-style",s)}static get isInline(){return!0}static get sanitize(){return{"editorjs-style":!0}}static get title(){return"Style"}get shortcut(){return"CMD+S"}checkState(){var e;this.actions.innerHTML="";const t=this.api.selection.findParentTag("EDITORJS-STYLE");if(!t)return!1;this.actions.innerHTML=`\n <div style="margin-left: 0.5rem; ">\n <div style="display: flex; align-items: center; justify-content: space-between; ">\n <div>Style settings</div>\n\n <button class="delete-button ${this.api.styles.settingsButton}" type="button">\n <svg class="icon" height="24" viewBox="0 0 24 24" width="24">\n <path d="M0 0h24v24H0z" fill="none"/>\n <path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/>\n </svg>\n </button>\n </div>\n\n <label style="display: flex; align-items: center; justify-content: space-between; ">\n <span>ID</span>\n\n <input class="id-input ${this.api.styles.input}" placeholder="exciting" style="width: 80%; ">\n </label>\n\n <label style="display: flex; align-items: center; justify-content: space-between; ">\n <span>Class</span>\n\n <input class="class-input ${this.api.styles.input}" placeholder="note editorial" style="width: 80%; ">\n </label>\n\n <label style="display: flex; align-items: center; justify-content: space-between; ">\n <span>Style</span>\n\n <textarea\n class="style-textarea ${this.api.styles.input}"\n placeholder="background: #ffe7e8;"\n style="resize: none; width: 80%; ">\n </textarea>\n </label>\n </div>\n `;const n=this.actions.querySelector(".delete-button"),i=this.actions.querySelector(".class-input"),s=this.actions.querySelector(".id-input"),o=this.actions.querySelector(".style-textarea");if(!(n&&i&&s&&o))throw new Error("Couldn't render actions for editorjs-style. ");return n.addEventListener("click",()=>{const e=Array.from(t.childNodes).map(e=>e.cloneNode(!0));if(e.forEach(e=>{var n;return null===(n=t.parentNode)||void 0===n?void 0:n.insertBefore(e,t)}),t.remove(),0===e.length)return;const n=window.getSelection();if(!n)throw new Error("Couldn't select unwrapped editorjs-style contents. ");n.removeAllRanges();const i=new Range;i.setStartBefore(e[0]),i.setEndAfter(e[e.length-1]),n.addRange(i)}),this.api.tooltip.onHover(n,"Delete style",{placement:"top"}),i.value=t.className,i.addEventListener("input",()=>t.setAttribute("class",i.value)),s.value=t.id,s.addEventListener("input",()=>t.id=s.value),o.value=null!==(e=t.getAttribute("style"))&&void 0!==e?e:"",o.addEventListener("keydown",e=>e.stopPropagation()),o.addEventListener("input",()=>t.setAttribute("style",o.value)),!0}clear(){this.actions.innerHTML=""}render(){const e=document.createElement("button");return e.classList.add(this.api.styles.inlineToolButton),e.type="button",e.innerHTML='\n <svg class="icon" height="24" viewBox="0 0 24 24" width="24">\n <path d="M0 0h24v24H0z" fill="none"/>\n <path d="M2.53 19.65l1.34.56v-9.03l-2.43 5.86c-.41 1.02.08 2.19 1.09 2.61zm19.5-3.7L17.07 3.98c-.31-.75-1.04-1.21-1.81-1.23-.26 0-.53.04-.79.15L7.1 5.95c-.75.31-1.21 1.03-1.23 1.8-.01.27.04.54.15.8l4.96 11.97c.31.76 1.05 1.22 1.83 1.23.26 0 .52-.05.77-.15l7.36-3.05c1.02-.42 1.51-1.59 1.09-2.6zM7.88 8.75c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1zm-2 11c0 1.1.9 2 2 2h1.45l-3.45-8.34v6.34z"/>\n </svg>\n ',e}renderActions(){return this.actions}surround(e){const t=new s;t.append(e.collapsed?"new style":e.extractContents()),setTimeout(()=>{e.insertNode(t),this.api.selection.expandToTag(t)})}};t.default=o}]).default})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.EditorJSStyle=t():e.EditorJSStyle=t()}(window,(function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var s=t[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(i,s,function(t){return e[t]}.bind(null,s));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);class i extends HTMLElement{constructor(){super(),this.addEventListener("keydown",e=>e.stopPropagation());new MutationObserver(()=>{var e,t,n,i,s,o;"#text"===(null===(e=this.firstChild)||void 0===e?void 0:e.nodeName)&&""===(null===(n=null===(t=this.firstChild)||void 0===t?void 0:t.textContent)||void 0===n?void 0:n.slice(0,1))||this.prepend(""),"#text"===(null===(i=this.lastChild)||void 0===i?void 0:i.nodeName)&&""===(null===(o=null===(s=this.lastChild)||void 0===s?void 0:s.textContent)||void 0===o?void 0:o.slice(-1))||this.append("")}).observe(this,{characterData:!0,childList:!0,subtree:!0})}}var s=i;var o=class{constructor({api:e}){this.actions=document.createElement("div"),this.api=e,customElements.get("editorjs-style")||customElements.define("editorjs-style",s)}static get isInline(){return!0}static get sanitize(){return{"editorjs-style":{class:!0,id:!0,style:!0}}}static get title(){return"Style"}get shortcut(){return"CMD+S"}checkState(){var e;this.actions.innerHTML="";const t=this.api.selection.findParentTag("EDITORJS-STYLE");if(!t)return!1;this.actions.innerHTML=`\n <div style="margin-left: 0.5rem; ">\n <div style="display: flex; align-items: center; justify-content: space-between; ">\n <div>Style settings</div>\n\n <button class="delete-button ${this.api.styles.settingsButton}" type="button">\n <svg class="icon" height="24" viewBox="0 0 24 24" width="24">\n <path d="M0 0h24v24H0z" fill="none"/>\n <path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"/>\n </svg>\n </button>\n </div>\n\n <label style="display: flex; align-items: center; justify-content: space-between; ">\n <span>ID</span>\n\n <input class="id-input ${this.api.styles.input}" placeholder="exciting" style="width: 80%; ">\n </label>\n\n <label style="display: flex; align-items: center; justify-content: space-between; ">\n <span>Class</span>\n\n <input class="class-input ${this.api.styles.input}" placeholder="note editorial" style="width: 80%; ">\n </label>\n\n <label style="display: flex; align-items: center; justify-content: space-between; ">\n <span>Style</span>\n\n <textarea\n class="style-textarea ${this.api.styles.input}"\n placeholder="background: #ffe7e8;"\n style="resize: none; width: 80%; ">\n </textarea>\n </label>\n </div>\n `;const n=this.actions.querySelector(".delete-button"),i=this.actions.querySelector(".class-input"),s=this.actions.querySelector(".id-input"),o=this.actions.querySelector(".style-textarea");if(!(n&&i&&s&&o))throw new Error("Couldn't render actions for editorjs-style. ");return n.addEventListener("click",()=>{const e=Array.from(t.childNodes).map(e=>e.cloneNode(!0));if(e.forEach(e=>{var n;return null===(n=t.parentNode)||void 0===n?void 0:n.insertBefore(e,t)}),t.remove(),0===e.length)return;const n=window.getSelection();if(!n)throw new Error("Couldn't select unwrapped editorjs-style contents. ");n.removeAllRanges();const i=new Range;i.setStartBefore(e[0]),i.setEndAfter(e[e.length-1]),n.addRange(i)}),this.api.tooltip.onHover(n,"Delete style",{placement:"top"}),i.value=t.className,i.addEventListener("input",()=>t.setAttribute("class",i.value)),s.value=t.id,s.addEventListener("input",()=>t.id=s.value),o.value=null!==(e=t.getAttribute("style"))&&void 0!==e?e:"",o.addEventListener("keydown",e=>e.stopPropagation()),o.addEventListener("input",()=>t.setAttribute("style",o.value)),!0}clear(){this.actions.innerHTML=""}render(){const e=document.createElement("button");return e.classList.add(this.api.styles.inlineToolButton),e.type="button",e.innerHTML='\n <svg class="icon" height="24" viewBox="0 0 24 24" width="24">\n <path d="M0 0h24v24H0z" fill="none"/>\n <path d="M2.53 19.65l1.34.56v-9.03l-2.43 5.86c-.41 1.02.08 2.19 1.09 2.61zm19.5-3.7L17.07 3.98c-.31-.75-1.04-1.21-1.81-1.23-.26 0-.53.04-.79.15L7.1 5.95c-.75.31-1.21 1.03-1.23 1.8-.01.27.04.54.15.8l4.96 11.97c.31.76 1.05 1.22 1.83 1.23.26 0 .52-.05.77-.15l7.36-3.05c1.02-.42 1.51-1.59 1.09-2.6zM7.88 8.75c-.55 0-1-.45-1-1s.45-1 1-1 1 .45 1 1-.45 1-1 1zm-2 11c0 1.1.9 2 2 2h1.45l-3.45-8.34v6.34z"/>\n </svg>\n ',e}renderActions(){return this.actions}surround(e){const t=new s;t.append(e.collapsed?"new style":e.extractContents()),setTimeout(()=>{e.insertNode(t),this.api.selection.expandToTag(t)})}};t.default=o}]).default})); |
{ | ||
"name": "editorjs-style", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Inline-style Tool for Editor.js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -33,2 +33,4 @@ Work in progress | ||
### Install via yarn | ||
```sh | ||
@@ -38,2 +40,26 @@ yarn add editorjs-style | ||
### Load from CDN | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/editorjs-style@latest"></script> | ||
``` | ||
## Usage | ||
Please see [Demo HTML](https://github.com/hata6502/editorjs-style/blob/master/docs/index.html). | ||
## Config params | ||
This tool has no config params. | ||
## Output data | ||
Please see [Demo](https://hata6502.github.io/editorjs-style/). | ||
## Build | ||
```sh | ||
yarn webpack | ||
``` | ||
## Run tests | ||
@@ -40,0 +66,0 @@ |
@@ -15,3 +15,7 @@ import type { | ||
return { | ||
'editorjs-style': true, | ||
'editorjs-style': { | ||
class: true, | ||
id: true, | ||
style: true, | ||
}, | ||
}; | ||
@@ -18,0 +22,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
720730
251
100