@wangeditor-next/core 6.5.0 → 6.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
`));let n=e[0].textContent||``;n=w(n),n=Tt(n);let r={text:n};return kt.forEach(n=>{r=n(e[0],r,t)}),r}function Bt(e,t){let n={text:``};return kt.forEach(r=>{n=r(e[0],n,t)}),n}var Vt=zt;function Ht(e,t){let n=t.parentElement;return n==null?e:(n.closest(`pre`)==null&&(e=e.replace(/[\r\n\t]+/g,``)),e=w(e),e=Tt(e),e)}function Ut(e,t){let n=A(A({},e),t);return Object.keys(t).forEach(e=>{t[e]===!1&&delete n[e]}),n}function Wt(e,t,n){let r=e[0];if(R(r)){let r=Gt(e,n),i=A({},t);return delete i.text,Array.isArray(r)?r.map(e=>Ut(i,e)):[Ut(i,r)]}return ft(r)?null:[Ut(t,z(r)?{text:Ht(r.textContent||``,r)}:Vt(e,n))]}function Gt(e,t){Dt.forEach(t=>{let{selector:n,preParseHtml:r}=t;e[0].matches(n)&&(e=(0,s.default)(r(e[0])))});let n=Ct(e);if(n===`span`){if(e.attr(`data-w-e-type`))return Rt(e,t);let n=Array.from(e[0].childNodes);if(n.some(e=>!z(e)&&!ft(e))){let r=Bt((0,s.default)(e[0]),t);return n.flatMap(e=>Wt((0,s.default)(e),r,t)||[])}return Vt(e,t)}if(n===`code`)return Ct(e.parent())===`pre`?Rt(e,t):Vt(e,t);if(Et.includes(n)){let n=Array.from(e[0].childNodes);if(n.some(e=>!z(e)&&!ft(e))){let r=Bt((0,s.default)(e[0]),t);return n.flatMap(e=>Wt((0,s.default)(e),r,t)||[])}return Vt(e,t)}return Rt(e,t)}var Kt=Gt;function qt(e,t,n){let r=F(n);return r.attr(t)?!0:(r.attr(t,`true`),e.on(M.DESTROYED,()=>{r.removeAttr(t)}),!1)}function Jt(e,t){return qt(e,`data-w-e-textarea`,t)}function Yt(e,t){return qt(e,`data-w-e-toolbar`,t)}function Xt(){return[{type:`paragraph`,children:[{text:``}]}]}function Zt(e,t=``){let n=[],{sanitizeHtml:r}=e.getConfig();t===``&&(t=`<p><br></p>`),t.indexOf(`<`)!==0&&(t=t.split(/\n/).map(e=>`<p>${e}</p>`).join(``)),t=r?r(t):t;let i=F(`<div>${t}</div>`);return Array.from(i.children()).forEach(t=>{let r=Kt(F(t),e);Array.isArray(r)?r.forEach(e=>n.push(e)):n.push(r)}),n}function Qt(e,t){let{html:n,content:r}=t,i;n==null?r&&r.length&&(i=r):i=Zt(e,n),i&&(e.children=e.transformInitialContent?e.transformInitialContent(i):i),e.children.length===0&&(e.children=Xt())}function $t(e,t){return`w-e-element-${e}-${t}`}function en(e){return`w-e-text-${e}`}let tn=[];function nn(e){tn.push(e)}let rn=[];function an(e){rn.push(e)}function on(e,t,n,r={}){return rn.reduce((e,i)=>i(e,t,n,r),e)}let sn={};function cn(e){let{type:t,elemToHtml:n}=e,r=t||``;sn[r]=n}let ln=0;var un=class{constructor(){this.id=`${ln}`,ln+=1}};globalThis.navigator!==void 0&&globalThis.window!==void 0&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&globalThis.window.MSStream;let dn=typeof navigator<`u`&&/Mac OS X/.test(navigator.userAgent),fn=typeof navigator<`u`&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);typeof navigator<`u`&&/^(?!.*Seamonkey)(?=.*Firefox\/(?:[0-7][0-9]|[0-8][0-6])(?:\.)).*/i.test(navigator.userAgent);let B=typeof navigator<`u`&&/^((?!chrome|android).)*safari/i.test(navigator.userAgent),pn=typeof navigator<`u`&&/Edge?\/(?:[0-6][0-9]|[0-7][0-8])(?:\.)/i.test(navigator.userAgent),mn=typeof navigator<`u`&&/Chrome?\/(?:[0-7][0-5]|[0-6][0-9])(?:\.)/i.test(navigator.userAgent),hn=typeof navigator<`u`&&/Chrome/i.test(navigator.userAgent);typeof navigator<`u`&&/.*QQBrowser/.test(navigator.userAgent);let gn=!mn&&!pn&&typeof globalThis<`u`&&globalThis.InputEvent&&typeof globalThis.InputEvent.prototype.getTargetRanges==`function`,_n=(e,t)=>!!(e.compareDocumentPosition(t)&Qe.DOCUMENT_POSITION_PRECEDING),vn=(e,t)=>!!(e.compareDocumentPosition(t)&Qe.DOCUMENT_POSITION_FOLLOWING),V={getWindow(e){let t=Ue.get(e);if(!t)throw Error(`Unable to find a host window element for this editor`);return t},findKey(e,t){let n=He.get(t);return n||(n=new un,He.set(t,n)),n},setNewKey(e){let t=new un;He.set(e,t)},findPath(e,t){let n=[],r=t;for(;;){let e=Re.get(r);if(e==null){if(a.Editor.isEditor(r))return n;break}let t=Le.get(r);if(t==null)break;n.unshift(t),r=e}throw Error(`Unable to find the path for Slate node: ${JSON.stringify(t)}`)},findDocumentOrShadowRoot(e){if(e.isDestroyed)return window.document;let t=V.toDOMNode(e,e),n=t.getRootNode();return(at(n)||ot(n))&&Reflect.get(n,`getSelection`)!=null?n:t.ownerDocument},getParentNode(e,t){return Re.get(t)||null},getParentsNodes(e,t){let n=[],r=t;for(;r!==e&&r!=null;){let t=V.getParentNode(e,r);if(t==null)break;n.push(t),r=t}return n},getTopNode(e,t){let n=[V.findPath(e,t)[0]];return a.Node.get(e,n)},toDOMNode(e,t){let n;if(a.Editor.isEditor(t))n=N.get(e);else{let r=V.findKey(e,t);n=Be.get(r)}if(!n)throw Error(`Cannot resolve a DOM node from Slate node: ${JSON.stringify(t)}`);return n},hasDOMNodeBySlateNode(e,t){if(a.Editor.isEditor(t))return!!N.get(e);let n=V.findKey(e,t);return!!Be.get(n)},canResolveDOMRange(e,t){try{let[n]=a.Editor.node(e,t.anchor.path),[r]=a.Range.isCollapsed(t)?[n]:a.Editor.node(e,t.focus.path);return V.hasDOMNodeBySlateNode(e,n)&&V.hasDOMNodeBySlateNode(e,r)}catch(e){return!1}},hasDOMNode(e,t,n={}){let{editable:r=!1}=n,i=V.toDOMNode(e,e),a;try{a=R(t)?t:t.parentElement}catch(e){if(e instanceof Error&&!e.message.includes(`Permission denied to access property "nodeType"`))throw e}return a?a.closest(`[data-slate-editor]`)===i&&(!r||a.isContentEditable||a.closest(`[contenteditable="false"]`)===i||!!a.getAttribute(`data-slate-zero-width`))||!!a.getAttribute(`data-slate-string`):!1},toDOMRange(e,t){let{anchor:n,focus:r}=t,i=a.Range.isBackward(t),o=V.toDOMPoint(e,n),s=a.Range.isCollapsed(t)?o:V.toDOMPoint(e,r),c=V.getWindow(e).document.createRange(),[l,u]=i?s:o,[d,f]=i?o:s,p=!!(R(l)?l:l.parentElement).getAttribute(`data-slate-zero-width`),m=!!(R(d)?d:d.parentElement).getAttribute(`data-slate-zero-width`);return c.setStart(l,p?1:u),c.setEnd(d,m?1:f),c},toDOMPoint(e,t){let[n]=a.Editor.node(e,t.path),r=V.toDOMNode(e,n),i;a.Editor.void(e,{at:t})&&(t={path:t.path,offset:0});let o=Array.from(r.querySelectorAll(`[data-slate-string], [data-slate-zero-width]`)),s=0;for(let e of o){let n=e.childNodes[0];if(n==null||n.textContent==null)continue;let{length:r}=n.textContent,a=e.getAttribute(`data-slate-length`),o=s+(a==null?r:parseInt(a,10));if(t.offset<=o){i=[n,Math.min(r,Math.max(0,t.offset-s))];break}s=o}if(!i)throw Error(`Cannot resolve a DOM point from Slate point: ${JSON.stringify(t)}`);return i},toSlateNode(e,t){let n=R(t)?t:t.parentElement;n&&!n.hasAttribute(`data-slate-node`)&&(n=n.closest(`[data-slate-node]`));let r=n?ze.get(n):null;if(!r)throw Error(`Cannot resolve a Slate node from DOM node: ${n}`);return r},findEventRange(e,t){`nativeEvent`in t&&(t=t.nativeEvent);let{clientX:n,clientY:r,target:i}=t;if(n==null||r==null)throw Error(`Cannot resolve a Slate range from a DOM event: ${t}`);let o=V.toSlateNode(e,t.target),s=V.findPath(e,o);if(a.Element.isElement(o)&&a.Editor.isVoid(e,o)){let t=i.getBoundingClientRect(),c=e.isInline(o)?n-t.left<t.left+t.width-n:r-t.top<t.top+t.height-r,l=a.Editor.point(e,s,{edge:c?`start`:`end`}),u=c?a.Editor.before(e,l):a.Editor.after(e,l);if(u)return a.Editor.range(e,u)}let c,{document:l}=this.getWindow(e);if(l.caretRangeFromPoint)c=l.caretRangeFromPoint(n,r);else{let e=l.caretPositionFromPoint(n,r);e&&(c=l.createRange(),c.setStart(e.offsetNode,e.offset),c.setEnd(e.offsetNode,e.offset))}if(!c)throw Error(`Cannot resolve a Slate range from a DOM event: ${t}`);return V.toSlateRange(e,c,{exactMatch:!1,suppressThrow:!1})},toSlateRange(e,t,n){let{exactMatch:r,suppressThrow:i}=n,o=pt(t)?t.anchorNode:t.startContainer,s,c,l,u,d;if(o&&(pt(t)?(s=t.anchorNode,c=t.anchorOffset,l=t.focusNode,u=t.focusOffset,d=hn&>()?t.anchorNode===t.focusNode&&t.anchorOffset===t.focusOffset:t.isCollapsed):(s=t.startContainer,c=t.startOffset,l=t.endContainer,u=t.endOffset,d=t.collapsed)),s==null||l==null||c==null||u==null){if(i)return null;throw Error(`Cannot resolve a Slate range from DOM range: ${t}`)}let f=V.toSlatePoint(e,[s,c],{exactMatch:r,suppressThrow:i});if(!f)return null;let p=d?f:V.toSlatePoint(e,[l,u],{exactMatch:r,suppressThrow:i,searchDirection:_n(s,l)||s===l&&u<c?`forward`:`backward`});if(!p)return null;let m={anchor:f,focus:p};return a.Range.isExpanded(m)&&a.Range.isForward(m)&&R(l)&&a.Editor.void(e,{at:m.focus,mode:`highest`})&&(m=a.Editor.unhangRange(e,m,{voids:!0})),m},toSlatePoint(e,t,n){let{exactMatch:r,suppressThrow:i}=n,[a,o]=r?t:ht(t),s=a.parentNode,l=n.searchDirection,u=null,d=0;if(s){var f;let t=V.toDOMNode(e,e),n=s.closest(`[data-slate-void="true"]`),r=n&&t.contains(n)?n:null,i=s.closest(`[contenteditable="false"]`),p=i&&t.contains(i)?i:null,m=s.closest(`[data-slate-leaf]`),h=null,g=V.getWindow(e);if(m&&g.document.createRange){u=m.closest(`[data-slate-node="text"]`);let e=g.document.createRange();e.setStart(u,0),e.setEnd(a,o);let t=e.cloneContents();[...(0,c.default)(t.querySelectorAll(`[data-slate-zero-width]`)),...(0,c.default)(t.querySelectorAll(`[contenteditable=false]`))].forEach(e=>{e.parentNode.removeChild(e)}),d=t.textContent.length,h=u}else if(r)m=Array.from(r.querySelectorAll(`[data-slate-leaf]`)).find(t=>V.hasDOMNode(e,t))||null,m?(u=m.closest(`[data-slate-node="text"]`),h=m,d=h.textContent.length,h.querySelectorAll(`[data-slate-zero-width]`).forEach(e=>{d-=e.textContent.length})):d=1;else if(p){let t=!!p.closest(`[data-w-e-reserve]`);!l&&t&&(l=`forward`);let n=l,r=t=>t?Array.from(t.querySelectorAll(`[data-slate-leaf]`)).filter(t=>V.hasDOMNode(e,t)):[],i=p.closest(`[data-slate-node="element"]`);if(l===`backward`||!l){let e=[...r(i==null?void 0:i.previousElementSibling),...r(i)];for(let t=e.length-1;t>=0;--t){let n=e[t];if(_n(p,n)){m=n,l=`backward`;break}}}if(!m&&(l===`forward`||!l||t)){let e=[...r(i),...r(i==null?void 0:i.nextElementSibling)];for(let r of e)if(vn(p,r)){m=r,n=l===`backward`&&t?`backward`:`forward`;break}}m&&(u=m.closest(`[data-slate-node="text"]`),h=m,n===`forward`?d=0:(d=h.textContent.length,h.querySelectorAll(`[data-slate-zero-width]`).forEach(e=>{d-=e.textContent.length})))}h&&d===h.textContent.length&&(s.hasAttribute(`data-slate-zero-width`)||fn&&(f=h.textContent)!=null&&f.endsWith(`
|
|
9
9
|
`))&&--d}if(!u){if(i)return null;throw Error(`Cannot resolve a Slate point from DOM point: ${t}`)}let p;try{let t=V.toSlateNode(e,u);p=V.findPath(e,t)}catch(e){if(i)return null;throw e}return{path:p,offset:d}},hasRange(e,t){let{anchor:n,focus:r}=t;return a.Editor.hasPath(e,n.path)&&a.Editor.hasPath(e,r.path)},getNodeType(e){return a.Element.isElement(e)?e.type:``},checkNodeType(e,t){return this.getNodeType(e)===t},getNodesStr(e){return e.map(e=>a.Node.string(e)).join(``)},getSelectedVoidNode(e){let{selection:t}=e;if(!t)return null;let n=a.Editor.void(e,{at:t});if(!n)return null;let[r]=n;return a.Element.isElement(r)?r:null},getSelectedElems(e){let t=[],n=V.getSelectedVoidNode(e);n&&t.push(n);let r=a.Editor.nodes(e,{universal:!0});for(let e of r){let[r]=e;a.Element.isElement(r)&&r!==n&&t.push(r)}return t},getSelectedNodeByType(e,t){let n=V.getSelectedVoidNode(e);if(n&&this.checkNodeType(n,t))return n;let[r]=a.Editor.nodes(e,{match:e=>this.checkNodeType(e,t),universal:!0});return r==null?null:r[0]},getSelectedTextNode(e){let[t]=a.Editor.nodes(e,{match:e=>a.Text.isText(e),universal:!0});return t==null?null:t[0]},isNodeSelected(e,t){if(V.getSelectedVoidNode(e)===t)return!0;let[n]=a.Editor.nodes(e,{match:e=>e===t,universal:!0});if(n==null)return!1;let[r]=n;return r===t},isSelectionAtLineEnd(e,t){let{selection:n}=e;return n?a.Editor.isEnd(e,n.anchor,t)||a.Editor.isEnd(e,n.focus,t):!1},getTextarea(e){let t=Se.get(e);if(t==null)throw Error(`Cannot find textarea instance by editor`);return t},getToolbar(e){return Te.get(e)||null},getHoverbar(e){return De.get(e)||null},normalizeContent(e){e.children.forEach((t,n)=>{e.normalizeNode([t,[n]])})},getLeftLengthOfMaxLength(e){let{maxLength:t,onMaxLength:n}=e.getConfig();if(typeof t!=`number`||t<=0)return 1/0;let r=t-e.getText().replace(/\r|\n|(\r\n)|(\n\r)/g,``).length;return r<=0&&n&&n(e),r},cleanExposedTexNodeInSelectionBlock(e){let{$textArea:t}=V.getTextarea(e),n=t==null?void 0:t[0].childNodes;if(n)for(let e of Array.from(n))if(z(e))e.remove();else break;let r=a.Editor.nodes(e,{match:t=>!!(a.Element.isElement(t)&&!e.isInline(t)),universal:!0});for(let t of r)if(t!=null){let n=t[0];if(!V.hasDOMNodeBySlateNode(e,n))continue;St(V.toDOMNode(e,n),(e,t)=>{let n=F(t);n.attr(`data-slate-string`)||n.attr(`data-slate-zero-width`)||n.attr(`data-w-e-reserve`)||t.removeChild(e)})}},isLastNode(e,t){let n=e.children||[];return n[n.length-1]===t},genEmptyParagraph(){return{type:`paragraph`,children:[{text:``}]}},isSelectedVoidNode(e){return V.getSelectedVoidNode(e)!=null},isSelectedEmptyParagraph(e){let{selection:t}=e;if(t==null||a.Range.isExpanded(t))return!1;let n=[t.focus.path[0]];if(!a.Editor.hasPath(e,n))return!1;let[r]=a.Editor.node(e,n);if(!a.Element.isElement(r)||r.type!==`paragraph`)return!1;let{children:i}=r;if(i.length!==1)return!1;let{text:o}=i[0];if(o===``)return!0},isEmptyPath(e,t){let n=a.Editor.node(e,t);if(n==null)return!1;let[r]=n,{children:i}=r;if(i.length===1){let{text:e}=i[0];if(e===``)return!0}return!1}};function yn(e,t,n){let r=n.isInline(e)?`span`:`div`;return`<${r}>${t}</${r}>`}function bn(e){return sn[e]||yn}let xn=/^[A-Za-z_:-][A-Za-z0-9_:.-]*$/;function Sn(e){return!e||!xn.test(e)?`data-w-e-id`:e}function Cn(e,t,n){if(!e)return e;let r=e.match(/^<([A-Za-z][A-Za-z0-9-]*)([^>]*)>/);if(!r)return e;let[i,a,o=``]=r;if(RegExp(`\\s${t}=`).test(o))return e;let s=/\/\s*$/.test(o),c=o.replace(/\s*\/\s*$/,``);return`<${a}${c.trim()?` ${c.trim()}`:``} ${t}="${n}"${s?` /`:``}>`+e.slice(i.length)}function wn(e,t,n,r){if(!r.includeId)return e;let i=Sn(r.idKey),a=V.findKey(n,t);return Cn(e,i,$t(V.getNodeType(t),a.id))}function Tn(e,t,n={}){let{type:r=``,children:i=[]}=e,o=a.Editor.isVoid(t,e),s=``;o||(s=i.map(e=>An(e,t,n)).join(``));let c=bn(r)(e,s,t),l=``;if(l=typeof c==`string`?c:c.html||``,o||tn.forEach(n=>l=n(e,l,t)),l=wn(l,e,t,n),typeof c==`string`)return l;let{prefix:u=``,suffix:d=``}=c;return u&&(l=u+l),d&&(l+=d),l}var En=Tn;function Dn(e,t,n={}){let{text:r}=e;if(r==null)throw Error(`Current node is not slate Text ${JSON.stringify(e)}`);let i=r;i=C(i);let a=V.getParentsNodes(t,e).some(e=>V.getNodeType(e)===`pre`);if(a||(i=i.replace(/\n\r|\r\n|\r|\n/g,`<br>`)),a&&(i=i.replace(/ /g,` `)),i===``){let t=V.getParentNode(null,e);if(t&&t.children.length===0)i=`<br>`;else return i}return tn.forEach(n=>i=n(e,i,t)),i}var On=Dn;function kn(e,t,n={}){return a.Element.isElement(e)?En(e,t,n):On(e,t,n)}var An=kn;let jn=(e,t)=>{let n=(t.top+t.bottom)/2;return e.top<=n&&e.bottom>=n},Mn=(e,t,n)=>{let r=V.toDOMRange(e,t).getBoundingClientRect(),i=V.toDOMRange(e,n).getBoundingClientRect();return jn(r,i)&&jn(i,r)},Nn=(e,t)=>{let n=a.Editor.range(e,a.Range.end(t)),r=Array.from(a.Editor.positions(e,{at:t})),i=0,o=r.length,s=Math.floor(o/2);if(Mn(e,a.Editor.range(e,r[i]),n))return a.Editor.range(e,r[i],n);if(r.length<2)return a.Editor.range(e,r[r.length-1],n);for(;s!==r.length&&s!==i;)Mn(e,a.Editor.range(e,r[s]),n)?o=s:i=s,s=Math.floor((i+o)/2);return a.Editor.range(e,r[o],n)},Pn=(e,t)=>{let n=[];for(let[r,i]of a.Editor.levels(e,{at:t})){let t=V.findKey(e,r);n.push([i,t])}return n};function Fn(e,t){if(a.Text.isText(t)){e.insertNode(t);return}if(a.Element.isElement(t))if(e.isInline(t))e.insertNode(t),t.type===`link`&&e.insertFragment([{text:``}]);else{let{selection:n}=e;if(!n)return;let r=[n.focus.path[0]];if(V.isSelectedEmptyParagraph(e)){a.Transforms.removeNodes(e,{at:r}),a.Transforms.insertNodes(e,t,{at:r}),a.Transforms.select(e,a.Editor.end(e,r));return}let i=a.Path.next(r);a.Transforms.insertNodes(e,t,{at:i}),a.Transforms.select(e,a.Editor.end(e,i))}}function In(e){let{selection:t}=e;if(t==null||a.Range.isCollapsed(t))return!1;let[n,r]=a.Range.edges(t),[i,o]=a.Editor.edges(e,[]);return a.Point.equals(n,i)&&a.Point.equals(r,o)}function Ln(e){let t=e.children[0];if(e.children.length!==1||!a.Element.isElement(t)||t.type===`paragraph`&&a.Node.string(t)===``||a.Node.string(t)!==``)return;let n=[{type:`paragraph`,children:[{text:``}]}];a.Editor.withoutNormalizing(e,()=>{a.Transforms.removeNodes(e,{at:[0]}),a.Transforms.insertNodes(e,n,{at:[0]})})}function Rn(e){let t=[{type:`paragraph`,children:[{text:``}]}];a.Editor.withoutNormalizing(e,()=>{for(let t=e.children.length-1;t>=0;--t)a.Transforms.removeNodes(e,{at:[t]});a.Transforms.insertNodes(e,t,{at:[0]})})}let zn=e=>{let t=e,{onChange:n,insertText:r,apply:i,deleteBackward:o,deleteFragment:s}=t;return t.insertText=e=>{let{readOnly:n}=t.getConfig();n||r(e)},t.apply=e=>{let n=[];switch(e.type){case`insert_text`:case`remove_text`:case`set_node`:case`split_node`:n.push(...Pn(t,e.path));break;case`insert_node`:case`remove_node`:n.push(...Pn(t,a.Path.parent(e.path)));break;case`merge_node`:{let r=a.Path.previous(e.path);n.push(...Pn(t,r));break}case`move_node`:{let r=a.Path.common(a.Path.parent(e.path),a.Path.parent(e.newPath));n.push(...Pn(t,r));break}case`set_selection`:var r;if(!((r=e.newProperties)==null||(r=r.focus)==null)&&r.path){var o,s;n.push(...Pn(t,(o=e.newProperties)==null||(o=o.focus)==null?void 0:o.path)),n.push(...Pn(t,(s=e.properties)==null||(s=s.focus)==null?void 0:s.path))}break;default:}i(e);for(let[e,r]of n){let[n]=a.Editor.node(t,e);He.set(n,r),`type`in n&&(Fe.has(n)&&Fe.delete(n),Ie.has(n)&&Ie.delete(n))}},t.deleteBackward=n=>{if(n!==`line`)return o(n);if(e.selection&&a.Range.isCollapsed(e.selection)){let n=a.Editor.above(e,{match:t=>a.Element.isElement(t)&&a.Editor.isBlock(e,t),at:e.selection});if(n){let[,r]=n,i=Nn(t,a.Editor.range(e,r,e.selection.anchor));a.Range.isCollapsed(i)||a.Transforms.delete(e,{at:i})}}},t.deleteFragment=e=>{let n=In(t);s(e),n&&(Rn(t),t.children.length>0&&a.Transforms.select(t,a.Editor.start(t,[])))},t.onChange=()=>{let{selection:e}=t;e!=null&&We.set(t,e),t.emit(M.CHANGE),n()},t.handleTab=()=>{t.insertText(` `)},t.getHtml=()=>{let{children:e=[]}=t,{skipCacheTypes:n=[`list-item`]}=t.getConfig();return on(e.map(e=>{let r=V.getNodeType(e);if(n.includes(r))return An(e,t);let i=Ie.get(e);if(i)return i.toString();let a=An(e,t);return Ie.set(e,a),a}),e,t).join(``)},t.getHtmlWithId=(e=`data-w-e-id`)=>{let{children:n=[]}=t;return on(n.map(n=>An(n,t,{includeId:!0,idKey:e})),n,t,{includeId:!0,idKey:e}).join(``)},t.getText=()=>{let{children:e=[]}=t;return e.map(e=>a.Node.string(e)).join(`
|
|
10
10
|
`)},t.getSelectionText=()=>{let{selection:n}=t;return n==null?``:a.Editor.string(e,n)},t.getElemsByType=(e,n=!1)=>{let r=[],i=a.Editor.nodes(t,{at:[],universal:!0});for(let o of i){let[i]=o;if(a.Element.isElement(i)&&(n?i.type.indexOf(e)>=0:i.type===e)){let e=V.findKey(t,i),n=$t(i.type,e.id);r.push(A(A({},i),{},{id:n}))}}return r},t.getElemsByTypePrefix=e=>t.getElemsByType(e,!0),t.isEmpty=()=>{let{children:e=[]}=t;if(e.length>1)return!1;let n=e[0];if(n==null)return!0;if(!a.Element.isElement(n)||n.type!==`paragraph`)return!1;let{children:r=[]}=n;if(r.length>1)return!1;let i=r[0];return i==null||a.Text.isText(i)&&i.text===``},t.clear=()=>{let e=[{type:`paragraph`,children:[{text:``}]}];for(let e=t.children.length-1;e>=0;--e)a.Transforms.removeNodes(t,{at:[e]});if(t.children.length===0){a.Transforms.insertNodes(t,e);return}Ln(t)},t.getParentNode=e=>V.getParentNode(t,e),t.dangerouslyInsertHtml=(e=``,n=!1)=>{if(!e)return;let r=document.createElement(`div`);r.innerHTML=e;let i=Array.from(r.childNodes);if(i=i.filter(e=>{let{nodeName:t}=e;return z(e)?!0:R(e)?!Xe.has(t.toLowerCase()):!1}),i.length===0)return;let{selection:o}=t;if(o==null)return;let s=null;if(V.isSelectedEmptyParagraph(t)&&!n){let{focus:e}=o;s=[e.path[0]]}r.setAttribute(`hidden`,`true`),document.body.appendChild(r);let c=0;i.forEach((e,n)=>{let{nodeName:r,textContent:o=``}=e;if(z(e)){if(!o||!o.trim())return;t.insertNode({text:o});return}if(r===`BR`){t.insertText(`
|
|
11
|
-
`);return}let s=e,l=!1;if(Et.includes(r.toLowerCase()))l=!0;else for(let e in jt)if(s.matches(e)){l=!0;break}if(l){let e=Kt(F(s),t),n=Array.isArray(e)?e:[e];if(n.forEach(e=>Fn(t,e)),c+=n.length,V.isSelectedVoidNode(t)&&t.move(1),n.some(e=>a.Element.isElement(e)?t.isInline(e)?!0:e.children.some(e=>a.Element.isElement(e)&&t.isInline(e)):!1)&&t.selection){let e=a.Editor.nodes(t,{at:t.selection,match:e=>a.Element.isElement(e)&&t.isInline(e),universal:!0}).next().value;if(e){let[,n]=e,r=a.Path.next(n);a.Editor.hasPath(t,r)?a.Transforms.select(t,{anchor:{path:r,offset:0},focus:{path:r,offset:0}}):t.move(1)}}return}let u=window.getComputedStyle(s).display;if(!V.isSelectedEmptyParagraph(t)&&u.indexOf(`inline`)<0){if(n>=1){let e=i[n-1];lt(e)&&t.insertBreak()}t.insertBreak()}t.dangerouslyInsertHtml(s.innerHTML,!0)}),c&&s&&V.isEmptyPath(t,s)&&a.Transforms.removeNodes(t,{at:s}),r.remove()},t.setHtml=(e=``)=>{let n=t.isDisabled(),r=t.isFocused(),i=JSON.stringify(t.selection);t.enable(),We.delete(t),t.
|
|
11
|
+
`);return}let s=e,l=!1;if(Et.includes(r.toLowerCase()))l=!0;else for(let e in jt)if(s.matches(e)){l=!0;break}if(l){let e=Kt(F(s),t),n=Array.isArray(e)?e:[e];if(n.forEach(e=>Fn(t,e)),c+=n.length,V.isSelectedVoidNode(t)&&t.move(1),n.some(e=>a.Element.isElement(e)?t.isInline(e)?!0:e.children.some(e=>a.Element.isElement(e)&&t.isInline(e)):!1)&&t.selection){let e=a.Editor.nodes(t,{at:t.selection,match:e=>a.Element.isElement(e)&&t.isInline(e),universal:!0}).next().value;if(e){let[,n]=e,r=a.Path.next(n);a.Editor.hasPath(t,r)?a.Transforms.select(t,{anchor:{path:r,offset:0},focus:{path:r,offset:0}}):t.move(1)}}return}let u=window.getComputedStyle(s).display;if(!V.isSelectedEmptyParagraph(t)&&u.indexOf(`inline`)<0){if(n>=1){let e=i[n-1];lt(e)&&t.insertBreak()}t.insertBreak()}t.dangerouslyInsertHtml(s.innerHTML,!0)}),c&&s&&V.isEmptyPath(t,s)&&a.Transforms.removeNodes(t,{at:s}),r.remove()},t.setHtml=(e=``)=>{let n=t.isDisabled(),r=t.isFocused(),i=JSON.stringify(t.selection);t.enable(),We.delete(t),t.clear(),r?t.focus():a.Transforms.select(t,a.Editor.start(t,[]));let o=Zt(t,e==null?``:e);a.Transforms.insertFragment(t,o);let s=o[o.length-1],c=t.children[t.children.length-1];if(a.Element.isElement(s)&&s.type===`table`&&a.Element.isElement(c)&&c.type===`paragraph`&&a.Node.string(c)===``&&a.Transforms.removeNodes(t,{at:[t.children.length-1]}),r||(t.deselect(),t.blur()),n&&(t.deselect(),t.disable()),t.isFocused())try{let e=JSON.parse(i);a.Range.isRange(e)&&V.hasRange(t,e)?t.select(e):t.select(a.Editor.start(t,[]))}catch(e){t.select(a.Editor.start(t,[]))}},t},Bn=1,Vn=e=>{let t=e;return t.id=`wangEditor-${Bn}`,Bn+=1,t.isDestroyed=!1,t.isFullScreen=!1,t.focus=e=>{if(V.toDOMNode(t,t).focus({preventScroll:!0}),P.set(t,!0),e){let e=a.Editor.end(t,[]);a.Transforms.select(t,e)}else{let e=We.get(t);e?a.Transforms.select(t,e):a.Transforms.select(t,a.Editor.start(t,[]))}},t.isFocused=()=>!!P.get(t),t.blur=()=>{V.toDOMNode(t,t).blur(),a.Transforms.deselect(t),P.set(t,!1)},t.updateView=()=>{V.getTextarea(t).changeViewState();let e=V.getToolbar(t);e&&e.changeToolbarState();let n=V.getHoverbar(t);n&&n.changeHoverbarState()},t.destroy=()=>{if(t.isDestroyed)return;let e=V.getTextarea(t);e.destroy(),Se.delete(t),Ce.delete(e);let n=V.getToolbar(t);n&&(n.destroy(),Te.delete(t),we.delete(n));let r=V.getHoverbar(t);r&&(r.destroy(),De.delete(t),Ee.delete(r)),t.isDestroyed=!0,t.emit(M.DESTROYED)},t.scrollToElem=e=>{let{scroll:n}=t.getConfig();if(!n){let e=`编辑器禁用了 scroll ,编辑器内容无法滚动,请自行实现该功能`;e+=`
|
|
12
12
|
You has disabled editor scroll, please do this yourself`,console.warn(e);return}let r=F(`#${e}`);if(r.length===0)return;let i=r[0];if(!V.hasDOMNode(t,i)){let t=`Element (found by id is '${e}') is not in editor DOM`;t+=`\n 通过 id '${e}' 找到的 element 不在 editor DOM 之内`,console.error(t,i);return}let{$textAreaContainer:a,$scroll:o}=V.getTextarea(t),{top:s}=r.offset(),{top:c}=a.offset();o[0].scrollBy({top:s-c,behavior:`smooth`})},t.showProgressBar=e=>{e<1||V.getTextarea(t).changeProgress(e)},t.hidePanelOrModal=()=>{let e=ke.get(t);e!=null&&e.forEach(e=>e.hide())},t.enable=()=>{let e=t.getConfig();e.readOnly=!1,t.updateView()},t.disable=()=>{let e=t.getConfig();e.readOnly=!0,t.updateView()},t.isDisabled=()=>t.getConfig().readOnly,t.toDOMNode=e=>V.toDOMNode(t,e),t.fullScreen=()=>{if(t.isFullScreen)return;let e=null,n=V.getToolbar(t);n&&(e=n.$box);let r=V.getTextarea(t).$box.parent();if(e&&e.parent()[0]!==r[0]){let e=`Can not set full screen, cause toolbar DOM parent is not equal to textarea DOM parent`;throw e+=`
|
|
13
13
|
不能设置全屏,因为 toolbar DOM 父节点和 textarea DOM 父节点不一致`,Error(e)}r.addClass(`w-e-full-screen-container`);let i=r.css(`z-index`);r.attr(`data-z-index`,i.toString()),t.isFullScreen=!0,t.emit(M.FULLSCREEN)},t.unFullScreen=()=>{if(!t.isFullScreen)return;let e=V.getTextarea(t).$box.parent();setTimeout(()=>{e.removeClass(`w-e-full-screen-container`),t.isFullScreen=!1,t.emit(M.UNFULLSCREEN)},200)},t.getEditableContainer=()=>V.getTextarea(t).$textAreaContainer[0],t};var Hn=b(((e,t)=>{var n=void 0;t.exports=function(e){return e!==n&&e!==null}})),Un=b(((e,t)=>{var n=Hn(),r={object:!0,function:!0,undefined:!0};t.exports=function(e){return n(e)?hasOwnProperty.call(r,typeof e):!1}})),Wn=b(((e,t)=>{var n=Un();t.exports=function(e){if(!n(e))return!1;try{return e.constructor?e.constructor.prototype===e:!1}catch(e){return!1}}})),Gn=b(((e,t)=>{var n=Wn();t.exports=function(e){if(typeof e!=`function`||!hasOwnProperty.call(e,`length`))return!1;try{if(typeof e.length!=`number`||typeof e.call!=`function`||typeof e.apply!=`function`)return!1}catch(e){return!1}return!n(e)}})),Kn=b(((e,t)=>{var n=Gn(),r=/^\s*class[\s{/}]/,i=Function.prototype.toString;t.exports=function(e){return!(!n(e)||r.test(i.call(e)))}})),qn=b(((e,t)=>{t.exports=function(){var e=Object.assign,t;return typeof e==`function`?(t={foo:`raz`},e(t,{bar:`dwa`},{trzy:`trzy`}),t.foo+t.bar+t.trzy===`razdwatrzy`):!1}})),Jn=b(((e,t)=>{t.exports=function(){try{return!0}catch(e){return!1}}})),Yn=b(((e,t)=>{t.exports=function(){}})),Xn=b(((e,t)=>{var n=Yn()();t.exports=function(e){return e!==n&&e!==null}})),Zn=b(((e,t)=>{var n=Xn(),r=Object.keys;t.exports=function(e){return r(n(e)?Object(e):e)}})),Qn=b(((e,t)=>{t.exports=Jn()()?Object.keys:Zn()})),$n=b(((e,t)=>{var n=Xn();t.exports=function(e){if(!n(e))throw TypeError(`Cannot use null or undefined`);return e}})),er=b(((e,t)=>{var n=Qn(),r=$n(),i=Math.max;t.exports=function(e,t){var a,o,s=i(arguments.length,2),c;for(e=Object(r(e)),c=function(n){try{e[n]=t[n]}catch(e){a||(a=e)}},o=1;o<s;++o)t=arguments[o],n(t).forEach(c);if(a!==void 0)throw a;return e}})),tr=b(((e,t)=>{t.exports=qn()()?Object.assign:er()})),nr=b(((e,t)=>{var n=Xn(),r=Array.prototype.forEach,i=Object.create,a=function(e,t){for(var n in e)t[n]=e[n]};t.exports=function(e){var t=i(null);return r.call(arguments,function(e){n(e)&&a(Object(e),t)}),t}})),rr=b(((e,t)=>{var n=`razdwatrzy`;t.exports=function(){return typeof n.contains==`function`?n.contains(`dwa`)===!0&&n.contains(`foo`)===!1:!1}})),ir=b(((e,t)=>{var n=String.prototype.indexOf;t.exports=function(e){return n.call(this,e,arguments[1])>-1}})),ar=b(((e,t)=>{t.exports=rr()()?String.prototype.contains:ir()})),or=b(((e,t)=>{var n=Hn(),r=Kn(),i=tr(),a=nr(),o=ar(),s=t.exports=function(e,t){var r,s,c,l,u;return arguments.length<2||typeof e!=`string`?(l=t,t=e,e=null):l=arguments[2],n(e)?(r=o.call(e,`c`),s=o.call(e,`e`),c=o.call(e,`w`)):(r=c=!0,s=!1),u={value:t,configurable:r,enumerable:s,writable:c},l?i(a(l),u):u};s.gs=function(e,t,s){var c,l,u,d;return typeof e==`string`?u=arguments[3]:(u=s,s=t,t=e,e=null),n(t)?r(t)?n(s)?r(s)||(u=s,s=void 0):s=void 0:(u=t,t=s=void 0):t=void 0,n(e)?(c=o.call(e,`c`),l=o.call(e,`e`)):(c=!0,l=!1),d={get:t,set:s,configurable:c,enumerable:l},u?i(a(u),d):d}})),sr=b(((e,t)=>{t.exports=function(e){if(typeof e!=`function`)throw TypeError(e+` is not a function`);return e}})),cr=x(b(((e,t)=>{var n=or(),r=sr(),i=Function.prototype.apply,a=Function.prototype.call,o=Object.create,s=Object.defineProperty,c=Object.defineProperties,l=Object.prototype.hasOwnProperty,u={configurable:!0,enumerable:!1,writable:!0},d=function(e,t){var n;return r(t),l.call(this,`__ee__`)?n=this.__ee__:(n=u.value=o(null),s(this,`__ee__`,u),u.value=null),n[e]?typeof n[e]==`object`?n[e].push(t):n[e]=[n[e],t]:n[e]=t,this},f=function(e,t){var n,a;return r(t),a=this,d.call(this,e,n=function(){p.call(a,e,n),i.call(t,this,arguments)}),n.__eeOnceListener__=t,this},p=function(e,t){var n,i,a,o;if(r(t),!l.call(this,`__ee__`)||(n=this.__ee__,!n[e]))return this;if(i=n[e],typeof i==`object`)for(o=0;a=i[o];++o)(a===t||a.__eeOnceListener__===t)&&(i.length===2?n[e]=i[o?0:1]:i.splice(o,1));else (i===t||i.__eeOnceListener__===t)&&delete n[e];return this},m=function(e){var t,n,r,o,s;if(l.call(this,`__ee__`)&&(o=this.__ee__[e],o))if(typeof o==`object`){for(n=arguments.length,s=Array(n-1),t=1;t<n;++t)s[t-1]=arguments[t];for(o=o.slice(),t=0;r=o[t];++t)i.call(r,this,s)}else switch(arguments.length){case 1:a.call(o,this);break;case 2:a.call(o,this,arguments[1]);break;case 3:a.call(o,this,arguments[1],arguments[2]);break;default:for(n=arguments.length,s=Array(n-1),t=1;t<n;++t)s[t-1]=arguments[t];i.call(o,this,s)}},h={on:d,once:f,off:p,emit:m},g={on:n(d),once:n(f),off:n(p),emit:n(m)},_=c({},g);t.exports=e=function(e){return e==null?o(_):c(Object(e),g)},e.methods=h}))(),1);function lr(e){let t=Ge.get(e);return t==null&&(t=(0,cr.default)(),Ge.set(e,t)),t}let ur=new WeakMap;function dr(e,t){let n=ur.get(e);n==null&&(n=new Set,ur.set(e,n)),n.add(t)}function fr(e){return ur.get(e)||new Set}function pr(e){ur.set(e,new Set)}let mr=e=>{let t=e;return t.on=(e,n)=>{let r=lr(t);if(r.on(e,n),e===`destroyed`&&dr(t,n),e!==`destroyed`){let i=()=>r.off(e,n);r.on(`destroyed`,i),dr(t,i)}},t.once=(e,n)=>{lr(t).once(e,n)},t.off=(e,n)=>{lr(t).off(e,n)},t.emit=(e,...n)=>{let r=lr(t);r.emit(e,...n),e===`destroyed`&&(fr(t).forEach(e=>r.off(`destroyed`,e)),pr(t))},t};function hr(e){return e.replace(/\n\r|\r\n|\r/g,`
|
|
14
14
|
`).split(`
|