UNPKG

@plebjs/editorjs-nowrap-tool

Version:
3 lines (2 loc) 1.87 kB
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".cdx-nowrap{display:inline;white-space:nowrap}")),document.head.appendChild(e)}}catch(n){console.error("vite-plugin-css-injected-by-js",n)}})(); (function(s,n){typeof exports=="object"&&typeof module<"u"?module.exports=n():typeof define=="function"&&define.amd?define(n):(s=typeof globalThis<"u"?globalThis:s||self,s.NowrapTool=n())})(this,function(){"use strict";const s="";class n{static get CSS(){return"cdx-nowrap"}constructor({api:t}){this.api=t,this.button=null,this.tag="SPAN",this.iconClasses={base:this.api.styles.inlineToolButton,active:this.api.styles.inlineToolButtonActive}}static get isInline(){return!0}render(){return this.button=document.createElement("button"),this.button.type="button",this.button.classList.add(this.iconClasses.base),this.button.innerHTML=this.toolboxIcon,this.button}surround(t){if(!t)return;let e=this.api.selection.findParentTag(this.tag,n.CSS);e?this.unwrap(e):this.wrap(t)}wrap(t){let e=document.createElement(this.tag);e.classList.add(n.CSS),e.appendChild(t.extractContents()),t.insertNode(e),this.api.selection.expandToTag(e)}unwrap(t){this.api.selection.expandToTag(t);let e=window.getSelection(),i=e.getRangeAt(0),o=i.extractContents();t.parentNode.removeChild(t),i.insertNode(o),e.removeAllRanges(),e.addRange(i)}checkState(){const t=this.api.selection.findParentTag(this.tag,n.CSS);this.button.classList.toggle(this.iconClasses.active,!!t)}get toolboxIcon(){return'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M4 6l10 0"></path> <path d="M4 18l10 0"></path><path d="M4 12h17l-3 -3m0 6l3 -3"></path></svg>'}static get sanitize(){return{span:{class:n.CSS}}}}return n});