UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

2 lines (1 loc) 2.71 kB
var o=Object.defineProperty;var h=(s,t)=>o(s,"name",{value:t,configurable:!0});import{html as p}from"./render.js";import{Style as d}from"./style.js";import{INSEPARABLE_TAGS as f}from"jodit/esm/core/constants.js";import{Dom as c}from"jodit/esm/core/dom/dom.js";import{assert as u}from"jodit/esm/core/helpers/utils/assert.js";const m=new Set(f),n=class n{get isText(){return this.type===Node.TEXT_NODE}get isElement(){return this.type===Node.ELEMENT_NODE}get isComment(){return this.type===Node.COMMENT_NODE}get isSingle(){return m.has(this.name)}get length(){return this.children.length}constructor(t,e){this.parent=e,this.name=t.nodeName.toLowerCase(),this.type=t.nodeType,this.attributes=v(t),this.style=new d(this.attributes.style),this.children=[],t.childNodes.forEach(r=>this.children.push(n.make(r,this)))}static make(t,e=null){return new n(t,e)}wrap(t){var e;u(this.parent!=null,"You can't wrap the root element");const r=n.make(document.createElement(t),this.parent),i=(e=this.parent.children.indexOf(this))!==null&&e!==void 0?e:-1;return i===-1?this.parent.append(r):this.parent.children[i]=r,r.append(this),r}append(t){return u(t!==this,"Forbidden to add to yourself"),t.remove(),this.children.push(t),t.parent=this,this}get previousElement(){if(!this.parent)return null;const{children:t}=this.parent,e=t.indexOf(this);if(e!==-1){for(let r=e-1;r>=0;r-=1)if(t[r].isElement)return t[r]}return null}get lastElement(){const{children:t}=this;for(let e=t.length-1;e>=0;e-=1)if(t[e].isElement)return t[e];return null}get previous(){var t,e,r;return(r=(t=this.sibling(!1))!==null&&t!==void 0?t:(e=this.parent)===null||e===void 0?void 0:e.previous)!==null&&r!==void 0?r:null}get next(){var t,e,r;return(r=(t=this.sibling(!0))!==null&&t!==void 0?t:(e=this.parent)===null||e===void 0?void 0:e.next)!==null&&r!==void 0?r:null}sibling(t){if(!this.parent)return null;const{children:e}=this.parent,r=e.indexOf(this);return r!==-1&&e[r+(t?1:-1)]?e[r+(t?1:-1)]:null}forEach(t,e=!1){const r=[...this.children];for(const i of r)if(t(i)===!1||e&&i.forEach(t,!0)===!1)return!1}find(t,e=!0){const r=[];return this.forEach(i=>{t(i)&&r.push(i)},e),r}map(t){return this.children.map(t)}remove(){var t,e;const r=(t=this.parent)===null||t===void 0?void 0:t.children.indexOf(this);return r!=null&&r!==-1&&((e=this.parent)===null||e===void 0||e.children.splice(r,1)),this}textBetween(t,e){let r=!1;const i=[];return this.forEach(l=>{if(!r&&t(l)&&(r=!0),r&&l.isText&&i.push(p(l)),r&&e(l))return!1},!0),i.join("")}};h(n,"JElement");let a=n;function v(s){const t={};if(c.isElement(s))for(let e=0,r=s.attributes;e<r.length;e+=1)t[r[e].name]=r[e].value;else t.nodeValue=s.nodeValue;return t}h(v,"readAttributes");export{a as JElement};