@yoopta/editor
Version:
<h2 align="center">Yoopta-Editor v1 🎉</h2> <p align="center">Yoopta-Editor - is an open source notion-like editor 💥</p> <div align="center"> <img width="574" alt="Screen Shot 2023-01-25 at 16 04 29" src="https://user-images.githubusercontent.com/2909311
1 lines • 198 kB
JavaScript
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import*as r from"react";import o,{createContext as i,useContext as l,useRef as a,useMemo as s,useLayoutEffect as c,useEffect as u,useCallback as d,useState as f,memo as p,useReducer as h,forwardRef as g,createElement as v}from"react";import{Editor as m,Element as y,Text as b,Transforms as w,Point as x,Path as k,Node as O,Range as E,createEditor as _,Operation as S}from"slate";import{ReactEditor as C,withReact as j,useSelected as D,Slate as A,Editable as P,DefaultElement as R}from"slate-react";import*as B from"react-dom";import{unstable_batchedUpdates as T,createPortal as M}from"react-dom";class N{constructor(e){this.plugin=e}get getPlugin(){return this.plugin}extend(e){const{renders:t,options:n,elementProps:r,events:o}=e,i=Object.assign(Object.assign({},this.plugin.options),n),l=Object.assign({},this.plugin.elements);return t&&Object.keys(t).forEach((e=>{const n=l[e];if(n&&n.render){const r=t[e];let o=n.render;n.render=e=>o(Object.assign(Object.assign({},e),{extendRender:r}))}})),r&&Object.keys(r).forEach((e=>{const t=l[e];if(t){const n=r[e],o=t.props;n&&o&&(t.props=n(o))}})),o&&Object.keys(o).forEach((e=>{const t=o[e];t&&(this.plugin.events||(this.plugin.events={}),this.plugin.events[e]=t)})),new N(Object.assign(Object.assign({},this.plugin),{elements:l,options:i}))}}function L(){let e=function(){return(65536*(1+Math.random())|0).toString(16).substring(1)};return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()}const I=()=>{var e,t;return"undefined"==typeof window||"function"!=typeof(null===(e=window.crypto)||void 0===e?void 0:e.randomUUID)?L():null===(t=window.crypto)||void 0===t?void 0:t.randomUUID()},F=e=>({id:I(),type:(null==e?void 0:e.type)||"paragraph",children:(null==e?void 0:e.children)||[{text:""}],props:Object.assign({nodeType:"block"},null==e?void 0:e.props)}),z=e=>({id:(null==e?void 0:e.id)||I(),value:(null==e?void 0:e.value)||[F()],type:(null==e?void 0:e.type)||"Paragraph",meta:Object.assign({order:0,depth:0},null==e?void 0:e.meta)});function $(e){if(!e)return;const t=Object.keys(e);return 1===t.length?t[0]:t.find((t=>e[t].asRoot))}function H(e){if(!e)return;const t=$(e);return t?e[t]:void 0}function V(e,t={nodeType:"block"}){return{id:I(),type:e,children:[{text:""}],props:t}}function U(e,t,n){var r;return(null===(r=e.children)||void 0===r?void 0:r.map((e=>{const r=t[e];if(!r)throw new Error(`Element definition for ${e} not found`);return F({id:I(),type:e,props:r.props,children:r.children&&r.children.length>0?U(r,t,n):[{text:(null==n?void 0:n[e])||""}]})})))||[]}function K(e,t,n){const r=e.blocks[t].elements,o=$(r);if(!o)throw new Error(`Root element type not found for block type ${t}`);const i=r[o];return{id:I(),type:o,props:i.props,children:i.children&&i.children.length>0?U(i,r,n):[{text:""}]}}function W(e,t,n={}){var r,o;const{at:i=e.path.current,focus:l=!1,blockData:a}=n,s=e.plugins[t],{onBeforeCreate:c,onCreate:u}=s.events||{};let d;d=a&&Array.isArray(null==a?void 0:a.value)?a.value[0]:(null==c?void 0:c(e))||K(e,t);const f={id:(null==a?void 0:a.id)||I(),type:t,value:[d],meta:{align:(null===(r=null==a?void 0:a.meta)||void 0===r?void 0:r.align)||"left",depth:(null===(o=null==a?void 0:a.meta)||void 0===o?void 0:o.depth)||0,order:"number"==typeof i?i:Object.keys(e.children).length}},p=[];return p.push({type:"insert_block",path:{current:f.meta.order},block:f}),e.applyTransforms(p),null==u||u(e,f.id),l&&e.focusBlock(f.id),f.id}function q(e){const t=e.path.current;return"number"==typeof t&&0!==t?t-1:null}function Y(e,t){e.applyTransforms([{type:"set_block_path",path:t}],{validatePaths:!1})}function X(e){try{let t;const[n,r]=m.last(e,[]);if(y.isElement(n)&&!m.isEditor(n)){const[n,o]=m.last(e,r);b.isText(n)&&(t={path:o,offset:n.text.length})}else b.isText(n)&&(t={path:r,offset:n.text.length});return t}catch(e){return{path:[0,0],offset:0}}}const Z={getPath:function(e){return e.path.current},getNextPath:function(e){const t=e.path.current;return"number"==typeof t?t+1:null},getPreviousPath:q,isBlockSelected:function(e,t){const n=e.path.selected;return!!Array.isArray(n)&&n.includes(t.meta.order)},getSelectedPaths:function(e){return e.path.selected},isPathEmpty:function(e){return null===e.path.current},setPath:Y,getLastNodePoint:X};function J(e,t){if(!(null==t?void 0:t.id)&&"number"!=typeof(null==t?void 0:t.at))throw new Error("getBlockSlate requires either an id or at");const n=(null==t?void 0:t.id)||Object.keys(e.children).find((n=>e.children[n].meta.order===(null==t?void 0:t.at))),r=e.blockEditorsMap[n||""],o=e.children[n||""],i=e.blocks[(null==o?void 0:o.type)||""];if(!(null==i?void 0:i.hasCustomEditor)&&!r)throw new Error(`Slate not found with params: ${JSON.stringify(t)}`);return r}function G(e,t){const{focus:n,blockId:r,at:o}=t;if(!r&&"number"!=typeof o)throw new Error("blockId or path should be provided");const i=e.getBlock({id:r,at:o});if(!i)throw new Error("Block not found");const l=Z.getPreviousPath(e),a=null!==l?e.getBlock({at:l}):void 0,s=a?J(e,{id:null==a?void 0:a.id}):void 0,c=e.children[i.id],u=[],d=e.plugins[c.type],{onDestroy:f}=d.events||{};if(null==f||f(e,c.id),u.push({type:"delete_block",block:c,path:e.path}),e.applyTransforms(u,{validatePaths:!1}),n&&s&&a){const t=Z.getLastNodePoint(s);e.focusBlock(a.id,{focusAt:t})}}function Q(e,t,n){const r=n,o=e.children[t],i=Object.values(e.children).find((e=>e.meta.order===r));if(!o||!i)return void console.warn("Invalid block ids for move operation");const l=[],a={type:"move_block",prevProperties:{id:t,order:o.meta.order},properties:{id:t,order:r}};l.push(a),e.applyTransforms(l),e.setPath({current:r})}const ee=new WeakMap;function te(e,t,n={}){const{focusAt:r,waitExecution:o=!0,waitExecutionMs:i=0,shouldUpdateBlockPath:l=!0}=n,a=()=>{const o=n.slate||e.blockEditorsMap[t],i=e.children[t];if(!o||!i)return;if(!e.blocks[i.type].hasCustomEditor)try{const e=function(e,t){if(x.isPoint(t))return t;if(k.isPath(t))return{path:t,offset:0};const[,n]=m.first(e,[0]);return{path:n||[0,0],offset:0}}(o,r);w.select(o,e),C.focus(o)}catch(e){}l&&setTimeout((()=>{e.setPath({current:i.meta.order})}),0)};o?setTimeout((()=>a()),i):a(),ee.set(e,!0)}function ne(e,t){const n=Object.keys(e.children),{at:r=e.path.current}=t||{},o=n.find((t=>e.children[t].meta.order===r));return o?e.children[o]:null}function re(e,t){const n=Object.keys(e.children),{at:r=e.path.current}=t||{},o=n.find((t=>e.children[t].meta.order===r));if(o)return e.blockEditorsMap[o]}var oe="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ie(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var le={};!function(e,t){var n="__lodash_hash_undefined__",r=9007199254740991,o="[object Arguments]",i="[object Boolean]",l="[object Date]",a="[object Function]",s="[object GeneratorFunction]",c="[object Map]",u="[object Number]",d="[object Object]",f="[object Promise]",p="[object RegExp]",h="[object Set]",g="[object String]",v="[object Symbol]",m="[object WeakMap]",y="[object ArrayBuffer]",b="[object DataView]",w="[object Float32Array]",x="[object Float64Array]",k="[object Int8Array]",O="[object Int16Array]",E="[object Int32Array]",_="[object Uint8Array]",S="[object Uint8ClampedArray]",C="[object Uint16Array]",j="[object Uint32Array]",D=/\w*$/,A=/^\[object .+?Constructor\]$/,P=/^(?:0|[1-9]\d*)$/,R={};R[o]=R["[object Array]"]=R[y]=R[b]=R[i]=R[l]=R[w]=R[x]=R[k]=R[O]=R[E]=R[c]=R[u]=R[d]=R[p]=R[h]=R[g]=R[v]=R[_]=R[S]=R[C]=R[j]=!0,R["[object Error]"]=R[a]=R[m]=!1;var B="object"==typeof oe&&oe&&oe.Object===Object&&oe,T="object"==typeof self&&self&&self.Object===Object&&self,M=B||T||Function("return this")(),N=t&&!t.nodeType&&t,L=N&&e&&!e.nodeType&&e,I=L&&L.exports===N;function F(e,t){return e.set(t[0],t[1]),e}function z(e,t){return e.add(t),e}function $(e,t,n,r){var o=-1,i=e?e.length:0;for(r&&i&&(n=e[++o]);++o<i;)n=t(n,e[o],o,e);return n}function H(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}function V(e){var t=-1,n=Array(e.size);return e.forEach((function(e,r){n[++t]=[r,e]})),n}function U(e,t){return function(n){return e(t(n))}}function K(e){var t=-1,n=Array(e.size);return e.forEach((function(e){n[++t]=e})),n}var W,q=Array.prototype,Y=Function.prototype,X=Object.prototype,Z=M["__core-js_shared__"],J=(W=/[^.]+$/.exec(Z&&Z.keys&&Z.keys.IE_PROTO||""))?"Symbol(src)_1."+W:"",G=Y.toString,Q=X.hasOwnProperty,ee=X.toString,te=RegExp("^"+G.call(Q).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ne=I?M.Buffer:void 0,re=M.Symbol,ie=M.Uint8Array,le=U(Object.getPrototypeOf,Object),ae=Object.create,se=X.propertyIsEnumerable,ce=q.splice,ue=Object.getOwnPropertySymbols,de=ne?ne.isBuffer:void 0,fe=U(Object.keys,Object),pe=Ie(M,"DataView"),he=Ie(M,"Map"),ge=Ie(M,"Promise"),ve=Ie(M,"Set"),me=Ie(M,"WeakMap"),ye=Ie(Object,"create"),be=Ve(pe),we=Ve(he),xe=Ve(ge),ke=Ve(ve),Oe=Ve(me),Ee=re?re.prototype:void 0,_e=Ee?Ee.valueOf:void 0;function Se(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function Ce(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function je(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function De(e){this.__data__=new Ce(e)}function Ae(e,t){var n=Ke(e)||function(e){return function(e){return function(e){return!!e&&"object"==typeof e}(e)&&We(e)}(e)&&Q.call(e,"callee")&&(!se.call(e,"callee")||ee.call(e)==o)}(e)?function(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}(e.length,String):[],r=n.length,i=!!r;for(var l in e)!t&&!Q.call(e,l)||i&&("length"==l||$e(l,r))||n.push(l);return n}function Pe(e,t,n){var r=e[t];Q.call(e,t)&&Ue(r,n)&&(void 0!==n||t in e)||(e[t]=n)}function Re(e,t){for(var n=e.length;n--;)if(Ue(e[n][0],t))return n;return-1}function Be(e,t,n,r,f,m,A){var P;if(r&&(P=m?r(e,f,m,A):r(e)),void 0!==P)return P;if(!Xe(e))return e;var B=Ke(e);if(B){if(P=function(e){var t=e.length,n=e.constructor(t);t&&"string"==typeof e[0]&&Q.call(e,"index")&&(n.index=e.index,n.input=e.input);return n}(e),!t)return function(e,t){var n=-1,r=e.length;t||(t=Array(r));for(;++n<r;)t[n]=e[n];return t}(e,P)}else{var T=ze(e),M=T==a||T==s;if(qe(e))return function(e,t){if(t)return e.slice();var n=new e.constructor(e.length);return e.copy(n),n}(e,t);if(T==d||T==o||M&&!m){if(H(e))return m?e:{};if(P=function(e){return"function"!=typeof e.constructor||He(e)?{}:(t=le(e),Xe(t)?ae(t):{});var t}(M?{}:e),!t)return function(e,t){return Ne(e,Fe(e),t)}(e,function(e,t){return e&&Ne(t,Ze(t),e)}(P,e))}else{if(!R[T])return m?e:{};P=function(e,t,n,r){var o=e.constructor;switch(t){case y:return Me(e);case i:case l:return new o(+e);case b:return function(e,t){var n=t?Me(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.byteLength)}(e,r);case w:case x:case k:case O:case E:case _:case S:case C:case j:return function(e,t){var n=t?Me(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}(e,r);case c:return function(e,t,n){var r=t?n(V(e),!0):V(e);return $(r,F,new e.constructor)}(e,r,n);case u:case g:return new o(e);case p:return function(e){var t=new e.constructor(e.source,D.exec(e));return t.lastIndex=e.lastIndex,t}(e);case h:return function(e,t,n){var r=t?n(K(e),!0):K(e);return $(r,z,new e.constructor)}(e,r,n);case v:return a=e,_e?Object(_e.call(a)):{}}var a}(e,T,Be,t)}}A||(A=new De);var N=A.get(e);if(N)return N;if(A.set(e,P),!B)var L=n?function(e){return function(e,t,n){var r=t(e);return Ke(e)?r:function(e,t){for(var n=-1,r=t.length,o=e.length;++n<r;)e[o+n]=t[n];return e}(r,n(e))}(e,Ze,Fe)}(e):Ze(e);return function(e,t){for(var n=-1,r=e?e.length:0;++n<r&&!1!==t(e[n],n,e););}(L||e,(function(o,i){L&&(o=e[i=o]),Pe(P,i,Be(o,t,n,r,i,e,A))})),P}function Te(e){return!(!Xe(e)||(t=e,J&&J in t))&&(Ye(e)||H(e)?te:A).test(Ve(e));var t}function Me(e){var t=new e.constructor(e.byteLength);return new ie(t).set(new ie(e)),t}function Ne(e,t,n,r){n||(n={});for(var o=-1,i=t.length;++o<i;){var l=t[o],a=r?r(n[l],e[l],l,n,e):void 0;Pe(n,l,void 0===a?e[l]:a)}return n}function Le(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function Ie(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return Te(n)?n:void 0}Se.prototype.clear=function(){this.__data__=ye?ye(null):{}},Se.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},Se.prototype.get=function(e){var t=this.__data__;if(ye){var r=t[e];return r===n?void 0:r}return Q.call(t,e)?t[e]:void 0},Se.prototype.has=function(e){var t=this.__data__;return ye?void 0!==t[e]:Q.call(t,e)},Se.prototype.set=function(e,t){return this.__data__[e]=ye&&void 0===t?n:t,this},Ce.prototype.clear=function(){this.__data__=[]},Ce.prototype.delete=function(e){var t=this.__data__,n=Re(t,e);return!(n<0)&&(n==t.length-1?t.pop():ce.call(t,n,1),!0)},Ce.prototype.get=function(e){var t=this.__data__,n=Re(t,e);return n<0?void 0:t[n][1]},Ce.prototype.has=function(e){return Re(this.__data__,e)>-1},Ce.prototype.set=function(e,t){var n=this.__data__,r=Re(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},je.prototype.clear=function(){this.__data__={hash:new Se,map:new(he||Ce),string:new Se}},je.prototype.delete=function(e){return Le(this,e).delete(e)},je.prototype.get=function(e){return Le(this,e).get(e)},je.prototype.has=function(e){return Le(this,e).has(e)},je.prototype.set=function(e,t){return Le(this,e).set(e,t),this},De.prototype.clear=function(){this.__data__=new Ce},De.prototype.delete=function(e){return this.__data__.delete(e)},De.prototype.get=function(e){return this.__data__.get(e)},De.prototype.has=function(e){return this.__data__.has(e)},De.prototype.set=function(e,t){var n=this.__data__;if(n instanceof Ce){var r=n.__data__;if(!he||r.length<199)return r.push([e,t]),this;n=this.__data__=new je(r)}return n.set(e,t),this};var Fe=ue?U(ue,Object):function(){return[]},ze=function(e){return ee.call(e)};function $e(e,t){return!!(t=null==t?r:t)&&("number"==typeof e||P.test(e))&&e>-1&&e%1==0&&e<t}function He(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||X)}function Ve(e){if(null!=e){try{return G.call(e)}catch(e){}try{return e+""}catch(e){}}return""}function Ue(e,t){return e===t||e!=e&&t!=t}(pe&&ze(new pe(new ArrayBuffer(1)))!=b||he&&ze(new he)!=c||ge&&ze(ge.resolve())!=f||ve&&ze(new ve)!=h||me&&ze(new me)!=m)&&(ze=function(e){var t=ee.call(e),n=t==d?e.constructor:void 0,r=n?Ve(n):void 0;if(r)switch(r){case be:return b;case we:return c;case xe:return f;case ke:return h;case Oe:return m}return t});var Ke=Array.isArray;function We(e){return null!=e&&function(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=r}(e.length)&&!Ye(e)}var qe=de||function(){return!1};function Ye(e){var t=Xe(e)?ee.call(e):"";return t==a||t==s}function Xe(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function Ze(e){return We(e)?Ae(e):function(e){if(!He(e))return fe(e);var t=[];for(var n in Object(e))Q.call(e,n)&&"constructor"!=n&&t.push(n);return t}(e)}e.exports=function(e){return Be(e,!0,!0)}}({get exports(){return le},set exports(e){le=e}},le);var ae=le;function se(e){return ae(e)}function ce(e,t={}){const{focus:n=!0}=t,r=ne(e),o=t.slate||re(e);o&&r&&m.withoutNormalizing(o,(()=>{if(!o.selection)return;const t=se(o.children),i=[],[l,a]=function(e,t){const{path:n,offset:r}=t.focus,[,...o]=n,i=JSON.parse(JSON.stringify(e[0]));function l(e,t,n){if(0!==t.length){const[r,...o]=t,[i,a]=l(e.children[r],o,n),s=e.children.slice(0,r).concat(i?[i]:[]),c=(a?[a]:[]).concat(e.children.slice(r+1));return[Object.assign(Object.assign({},e),{children:s}),Object.assign(Object.assign({},e),{children:c})]}if(O.string(e).length<=n)return[e,null];if("text"in e)return[Object.assign(Object.assign({},e),{text:e.text.slice(0,n)}),Object.assign(Object.assign({},e),{text:e.text.slice(n)})];if("link"===e.type){const[t,r]=l(e.children[0],[],n);return[Object.assign(Object.assign({},e),{children:[t]}),Object.assign(Object.assign({},e),{children:[r]})]}}const[a,s]=l(i,o,r);function c(e){return"children"in e&&(e.children=e.children.filter((e=>""!==e.text&&void 0!==e.text||e.children&&e.children.length>0)),e.children.forEach(c)),e}return[c(a),c(s)].map((e=>[e])).filter((e=>e[0].children.length>0))}(o.children,o.selection),s={id:I(),type:r.type,meta:{order:r.meta.order+1,depth:r.meta.depth,align:r.meta.align},value:[]};i.push({type:"split_block",prevProperties:{originalBlock:r,originalValue:t},properties:{nextBlock:s,nextSlateValue:a||[V("paragraph")],splitSlateValue:l},path:e.path}),e.applyTransforms(i),n&&e.focusBlock(s.id)}))}function ue(e,t={}){const{at:n=e.path.current,blockId:r}=t,o=r?e.children[r]:ne(e,{at:n});if(!o)return;const i=o.meta.depth+1,l={type:"set_block_meta",id:o.id,properties:{depth:i},prevProperties:{depth:o.meta.depth}};e.applyTransforms([l])}function de(e,t={}){const{at:n=e.path.current,blockId:r}=t,o=r?e.children[r]:ne(e,{at:n});if(!o)return;const i=Math.max(0,o.meta.depth-1),l={type:"set_block_meta",id:o.id,properties:{depth:i},prevProperties:{depth:o.meta.depth}};e.applyTransforms([l])}function fe(e){return!!e&&("object"==typeof e&&!Array.isArray(e))}function pe(e,t){const{original:n,focus:r,at:o}=t;if(!n)throw new Error("`original` should be provided");if(!n.blockId&&"number"!=typeof n.path)throw new Error("blockId or path should be provided");const{blockId:i,path:l}=n;let a=i?e.children[i]:ne(e,{at:l});if(!a)throw new Error("Block not found");const s=[],c=se(a);return c.id=I(),c.meta.order=Array.isArray(o)&&"number"==typeof o?o:a.meta.order+1,s.push({type:"insert_block",path:{current:c.meta.order},block:c}),e.applyTransforms(s),r&&e.focusBlock(c.id,{waitExecution:!0}),c.id}function he(e,t,n){const r=e.children[t];if(!r)return void console.warn(`Block with id ${t} does not exist.`);const o={type:"set_block_meta",id:t,properties:{},prevProperties:{}},i={type:"set_block_value",id:t,value:[]};n.meta&&(o.prevProperties=r.meta,o.properties=Object.assign(Object.assign({},r.meta),n.meta)),n.value&&(i.value=n.value);const l=[];Object.keys(o.properties).length&&l.push(o),i.value.length&&l.push(i),l.length>0&&e.applyTransforms(l,{validatePaths:!1})}const ge=(e,t)=>{const{insertText:n}=t;return t.insertText=r=>{var o;const{selection:i}=t;if(" "===r&&i&&E.isCollapsed(i)){const{anchor:l}=i,a=m.above(t,{match:e=>y.isElement(e)&&m.isBlock(t,e),mode:"lowest"});if(!a)return;const[,s]=a,c=m.parent(t,s),[u]=c;if(y.isElement(u)&&!b.isText(u.children[0]))return n(r);const d=a?s:[],f={anchor:l,focus:m.start(t,d)},p=m.string(t,f),h=null===(o=e.shortcuts)||void 0===o?void 0:o[p];if(!!h&&!h.isActive())return w.select(t,f),w.delete(t),void e.toggleBlock(h.type,{deleteText:!0,focus:!0})}n(r)},t};function ve(e){return ge(e,j(_()))}const me="Paragraph";function ye(e,t,n,r){const o=r.plugins[n.type];return(null==o?void 0:o.customEditor)?n.value[0].children:m.isEditor(t)?t.children.flatMap((t=>ye(e,t,n,r))):y.isElement(t)?m.isInline(e,t)?[t]:t.children.flatMap((t=>ye(e,t,n,r))):[t]}function be(e){return y.isElement(e)?0===e.children.length||b.isText(e.children[0])?e:be(e.children[0]):null}function we(e,t,n={}){const r=ne(e,{at:n.at||e.path.current});if(!r)throw new Error("Block not found at current selection");let o=r.type===t?me:t;const i=e.plugins[o],{onBeforeCreate:l}=i.events||{},a=re(e,{at:r.meta.order});if(!a)throw new Error(`Slate not found for block in position ${r.meta.order}`);const s=(null==l?void 0:l(e))||K(e,o),c=ye(a,a.children[0],r,e),u=be(s);u&&(u.children=c);const d={id:I(),type:o,meta:Object.assign(Object.assign({},r.meta),{align:void 0}),value:[s]},f=ve(e);f.children=[s];const p=[{type:"delete_block",block:r,path:{current:r.meta.order}},{type:"insert_block",path:{current:r.meta.order},block:d}];return e.applyTransforms(p),n.deleteText&&w.delete(f,{at:[0,0]}),n.focus&&e.focusBlock(d.id),d.id}function xe(e,t){if(!(null==t?void 0:t.id)&&"number"!=typeof(null==t?void 0:t.at))throw new Error("getBlock requires either an id or at");if(null==t?void 0:t.id)return e.children[null==t?void 0:t.id];const n=Object.keys(e.children).find((n=>e.children[n].meta.order===(null==t?void 0:t.at)));return n?e.children[n]:null}function ke(e,t,n){const r=e.children[t];if(!r)throw new Error(`Block with id ${t} not found`);const o=re(e,{at:r.meta.order});if(!o)return void console.warn("No slate found");let i=e=>y.isElement(e);(null==n?void 0:n.type)&&(i=e=>y.isElement(e)&&e.type===(null==n?void 0:n.type));try{const[e]=m.nodes(o,{at:(null==n?void 0:n.path)||o.selection||[0],match:i,mode:"lowest"});return e}catch(e){}}function Oe(e,t,n){const r=ke(e,t,n);if(r)return r[0]}const Ee={createElement:function(e,t,n,r){const o=e.children[t];if(!o)throw new Error(`Block with id ${t} not found`);const i=re(e,{at:o.meta.order});i?m.withoutNormalizing(i,(()=>{const l=e.blocks[o.type],a=l.elements[n.type],s=F({type:n.type,props:Object.assign(Object.assign({},a.props),n.props)}),c=Object.keys(l.elements);let u=[];c.forEach((e=>{const t=l.elements[e];e===n.type&&Array.isArray(t.children)&&t.children.length>0&&t.children.forEach((e=>{const t=l.elements[e];u.push(F({type:e,props:t.props}))}))})),u.length>0&&(s.children=u);const{path:d,focus:f=!0}=r||{};let p;const h=ke(e,t,{type:n.type});if(h){const[,e]=h;k.isPath(d)?p=d:"prev"===d?p=k.previous(e):"next"===d&&(p=k.next(e))}if(w.insertNodes(i,s,{at:p,select:f}),f&&u.length>0){const n=u[0],r=ke(e,t,{path:p,type:n.type});if(r){const[,e]=r;w.select(i,e)}}})):console.warn("No slate found")},deleteElement:function(e,t,n){const r=e.children[t];if(!r)throw new Error(`Block with id ${t} not found`);const o=re(e,{at:r.meta.order});o?m.withoutNormalizing(o,(()=>{w.removeNodes(o,{at:n.path,match:e=>y.isElement(e)&&e.type===n.type})})):console.warn("No slate found")},updateElement:function(e,t,n,r){const o=e.children[t];if(!o)throw new Error(`Block with id ${t} not found`);const i=re(e,{at:o.meta.order});i?m.withoutNormalizing(i,(()=>{const[e]=m.nodes(i,{at:(null==r?void 0:r.path)||[0],match:e=>y.isElement(e)&&e.type===n.type}),t=null==e?void 0:e[0],o=null==e?void 0:e[1],l=(null==t?void 0:t.props)||{},a={props:Object.assign(Object.assign({},l),n.props)};w.setNodes(i,a,{at:(null==r?void 0:r.path)||o||[0],match:e=>y.isElement(e)&&e.type===n.type,mode:"lowest"})})):console.warn("No slate found")},insertElementText:function(e,t,n){const{blockId:r,focus:o}=n||{},i=r?e.children[r]:ne(e);if(!i)return void console.warn(`To set text programmatically, you must provide a valid blockId. Got: ${r}`);const l=re(e,{at:i.meta.order});if(!l)return void console.warn("No slate found");const a=e.blocks[i.type],s=Array.from({length:Object.keys(a.elements).length},(e=>0));let c=l.selection||s;c?m.withoutNormalizing(l,(()=>{E.isRange(c)&&!E.isCollapsed(c)&&w.collapse(l,{edge:"end"}),w.insertText(l,t,{at:c}),o&&e.focusBlock(i.id,{waitExecution:!0,shouldUpdateBlockPath:!0})})):console.warn("No valid path or selection found for text insertion")},getElement:Oe,getElementChildren:function(e,t,n){const r=Oe(e,t,n);if(r)return r.children},getElementEntry:ke,isElementEmpty:function(e,t,n){const r=e.children[t];if(!r)throw new Error(`Block with id ${t} not found`);const o=re(e,{at:r.meta.order});if(!o)return void console.warn("No slate found");const[i]=m.nodes(o,{at:n.path||o.selection,match:e=>y.isElement(e)&&e.type===n.type});if(i){const[e,t]=i;return 0===m.string(o,t).trim().length}return!1},getElementPath:function(e,t,n){const r=e.children[t];if(!r)throw new Error(`Block with id ${t} not found`);const o=re(e,{at:r.meta.order});if(o)try{return C.findPath(o,n)}catch(e){}else console.warn("No slate found")},getParentElementPath:function(e,t,n){const r=e.children[t];if(!r)throw new Error(`Block with id ${t} not found`);const o=re(e,{at:r.meta.order});if(!o)return console.warn("No slate found"),[];try{const e=C.findPath(o,n);return k.parent(e)}catch(e){}}};function _e(e){var t;const n=ne(e),r=re(e,{at:e.path.current}),o=Z.getPreviousPath(e),i=re(e,{at:o}),l=ne(e,{at:o}),a=e.blocks[(null==l?void 0:l.type)||""];if(!(r&&n&&i&&l))return;const s=Ee.getElement(e,l.id);if(a&&!a.hasCustomEditor&&"void"!==(null===(t=null==s?void 0:s.props)||void 0===t?void 0:t.nodeType)){try{const e=X(i);w.select(i,e)}catch(e){w.select(i,m.start(i,[]))}m.withoutNormalizing(i,(()=>{const t=[],o=function(e,t){const n=JSON.parse(JSON.stringify(e.children)),r=JSON.parse(JSON.stringify(t.children)),o=n[n.length-1],i=r[0];return b.isText(o)&&b.isText(i)?(o.text+=i.text,[...n.slice(0,-1),o,...r.slice(1)]):[...n,...r]}(i.children[0],r.children[0]),a=[Object.assign(Object.assign({},i.children[0]),{children:o})],s=Object.assign(Object.assign({},l),{value:a});t.push({type:"merge_block",prevProperties:{sourceBlock:n,sourceSlateValue:r.children,targetBlock:l,targetSlateValue:i.children},properties:{mergedBlock:s,mergedSlateValue:a},path:e.path}),e.applyTransforms(t),e.setPath({current:l.meta.order});try{setTimeout((()=>{C.focus(i)}),0)}catch(e){console.error("Error setting focus:",e)}}))}}const Se={insertBlock:W,deleteBlock:G,moveBlock:Q,focusBlock:te,splitBlock:ce,increaseBlockDepth:ue,decreaseBlockDepth:de,duplicateBlock:pe,updateBlock:he,toggleBlock:we,getBlock:xe,getBlockSlate:J,buildBlockData:function(e){var t,n,r;return{id:(null==e?void 0:e.id)||I(),value:(null==e?void 0:e.value)||[{id:I(),type:(null==r?void 0:r.type)||"paragraph",children:(null==r?void 0:r.children)||[{text:""}],props:Object.assign({nodeType:"block"},null==r?void 0:r.props)}],type:(null==e?void 0:e.type)||"Paragraph",meta:Object.assign({order:(null===(t=null==e?void 0:e.meta)||void 0===t?void 0:t.order)||0,depth:(null===(n=null==e?void 0:e.meta)||void 0===n?void 0:n.depth)||0},null==e?void 0:e.meta)}},mergeBlock:_e};function Ce(e,t){try{C.blur(t),C.deselect(t),w.deselect(t)}catch(e){}e.setPath({current:null})}const je={underline:{type:"underline",tag:"u"},strike:{type:"strike",tag:"s"},code:{type:"code",tag:"code"},italic:{type:"italic",tag:"i"},bold:{type:"bold",tag:"strong"},strong:{type:"bold",tag:"strong"}};function De(e,t,n){return e.map((e=>{var n,r;let o="";if(e.text)return o=Object.keys(je).reduce(((t,n)=>e[n]?`<${je[n].tag}>${t}</${je[n].tag}>`:t),e.text),o;if(e.type){const i=function(e,t){return Object.values(e).find((e=>{var n,r;return e.type===(null===(r=null===(n=e.elements)||void 0===n?void 0:n[t])||void 0===r?void 0:r.rootPlugin)}))}(t,e.type);if(i&&(null===(r=null===(n=i.parsers)||void 0===n?void 0:n.html)||void 0===r?void 0:r.serialize))return o=i.parsers.html.serialize(e,De(e.children,t)),o}return o})).join("")}function Ae(e,t){const n=Object.values(t).filter((t=>{const n=Z.getSelectedPaths(e);return!(Array.isArray(n)&&n.length>0)||(null==n?void 0:n.includes(t.meta.order))})).sort(((e,t)=>e.meta.order-t.meta.order)).map((t=>{var n,r;const o=e.plugins[t.type];if(o&&(null===(r=null===(n=o.parsers)||void 0===n?void 0:n.html)||void 0===r?void 0:r.serialize)){const n=De(t.value[0].children,e.plugins);return o.parsers.html.serialize(t.value[0],n,t.meta)}return""}));return`<body id="yoopta-clipboard" data-editor-id="${e.id}">${n.join("")}</body>`}var Pe=Symbol.for("immer-nothing"),Re=Symbol.for("immer-draftable"),Be=Symbol.for("immer-state");function Te(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var Me=Object.getPrototypeOf;function Ne(e){return!!e&&!!e[Be]}function Le(e){return!!e&&(Fe(e)||Array.isArray(e)||!!e[Re]||!!e.constructor?.[Re]||Ue(e)||Ke(e))}var Ie=Object.prototype.constructor.toString();function Fe(e){if(!e||"object"!=typeof e)return!1;const t=Me(e);if(null===t)return!0;const n=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return n===Object||"function"==typeof n&&Function.toString.call(n)===Ie}function ze(e,t){0===$e(e)?Reflect.ownKeys(e).forEach((n=>{t(n,e[n],e)})):e.forEach(((n,r)=>t(r,n,e)))}function $e(e){const t=e[Be];return t?t.type_:Array.isArray(e)?1:Ue(e)?2:Ke(e)?3:0}function He(e,t){return 2===$e(e)?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Ve(e,t,n){const r=$e(e);2===r?e.set(t,n):3===r?e.add(n):e[t]=n}function Ue(e){return e instanceof Map}function Ke(e){return e instanceof Set}function We(e){return e.copy_||e.base_}function qe(e,t){if(Ue(e))return new Map(e);if(Ke(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);if(!t&&Fe(e)){if(!Me(e)){const t=Object.create(null);return Object.assign(t,e)}return{...e}}const n=Object.getOwnPropertyDescriptors(e);delete n[Be];let r=Reflect.ownKeys(n);for(let t=0;t<r.length;t++){const o=r[t],i=n[o];!1===i.writable&&(i.writable=!0,i.configurable=!0),(i.get||i.set)&&(n[o]={configurable:!0,writable:!0,enumerable:i.enumerable,value:e[o]})}return Object.create(Me(e),n)}function Ye(e,t=!1){return Ze(e)||Ne(e)||!Le(e)||($e(e)>1&&(e.set=e.add=e.clear=e.delete=Xe),Object.freeze(e),t&&Object.entries(e).forEach((([e,t])=>Ye(t,!0)))),e}function Xe(){Te(2)}function Ze(e){return Object.isFrozen(e)}var Je,Ge={};function Qe(e){const t=Ge[e];return t||Te(0),t}function et(){return Je}function tt(e,t){t&&(Qe("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function nt(e){rt(e),e.drafts_.forEach(it),e.drafts_=null}function rt(e){e===Je&&(Je=e.parent_)}function ot(e){return Je={drafts_:[],parent_:Je,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function it(e){const t=e[Be];0===t.type_||1===t.type_?t.revoke_():t.revoked_=!0}function lt(e,t){t.unfinalizedDrafts_=t.drafts_.length;const n=t.drafts_[0];return void 0!==e&&e!==n?(n[Be].modified_&&(nt(t),Te(4)),Le(e)&&(e=at(t,e),t.parent_||ct(t,e)),t.patches_&&Qe("Patches").generateReplacementPatches_(n[Be].base_,e,t.patches_,t.inversePatches_)):e=at(t,n,[]),nt(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==Pe?e:void 0}function at(e,t,n){if(Ze(t))return t;const r=t[Be];if(!r)return ze(t,((o,i)=>st(e,r,t,o,i,n))),t;if(r.scope_!==e)return t;if(!r.modified_)return ct(e,r.base_,!0),r.base_;if(!r.finalized_){r.finalized_=!0,r.scope_.unfinalizedDrafts_--;const t=r.copy_;let o=t,i=!1;3===r.type_&&(o=new Set(t),t.clear(),i=!0),ze(o,((o,l)=>st(e,r,t,o,l,n,i))),ct(e,t,!1),n&&e.patches_&&Qe("Patches").generatePatches_(r,n,e.patches_,e.inversePatches_)}return r.copy_}function st(e,t,n,r,o,i,l){if(Ne(o)){const l=at(e,o,i&&t&&3!==t.type_&&!He(t.assigned_,r)?i.concat(r):void 0);if(Ve(n,r,l),!Ne(l))return;e.canAutoFreeze_=!1}else l&&n.add(o);if(Le(o)&&!Ze(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;at(e,o),t&&t.scope_.parent_||"symbol"==typeof r||!Object.prototype.propertyIsEnumerable.call(n,r)||ct(e,o)}}function ct(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&Ye(t,n)}var ut={get(e,t){if(t===Be)return e;const n=We(e);if(!He(n,t))return function(e,t,n){const r=pt(t,n);return r?"value"in r?r.value:r.get?.call(e.draft_):void 0}(e,n,t);const r=n[t];return e.finalized_||!Le(r)?r:r===ft(e.base_,t)?(gt(e),e.copy_[t]=vt(r,e)):r},has:(e,t)=>t in We(e),ownKeys:e=>Reflect.ownKeys(We(e)),set(e,t,n){const r=pt(We(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){const r=ft(We(e),t),l=r?.[Be];if(l&&l.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(((o=n)===(i=r)?0!==o||1/o==1/i:o!=o&&i!=i)&&(void 0!==n||He(e.base_,t)))return!0;gt(e),ht(e)}var o,i;return e.copy_[t]===n&&(void 0!==n||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_[t]=!0),!0},deleteProperty:(e,t)=>(void 0!==ft(e.base_,t)||t in e.base_?(e.assigned_[t]=!1,gt(e),ht(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0),getOwnPropertyDescriptor(e,t){const n=We(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r?{writable:!0,configurable:1!==e.type_||"length"!==t,enumerable:r.enumerable,value:n[t]}:r},defineProperty(){Te(11)},getPrototypeOf:e=>Me(e.base_),setPrototypeOf(){Te(12)}},dt={};function ft(e,t){const n=e[Be];return(n?We(n):e)[t]}function pt(e,t){if(!(t in e))return;let n=Me(e);for(;n;){const e=Object.getOwnPropertyDescriptor(n,t);if(e)return e;n=Me(n)}}function ht(e){e.modified_||(e.modified_=!0,e.parent_&&ht(e.parent_))}function gt(e){e.copy_||(e.copy_=qe(e.base_,e.scope_.immer_.useStrictShallowCopy_))}ze(ut,((e,t)=>{dt[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}})),dt.deleteProperty=function(e,t){return dt.set.call(this,e,t,void 0)},dt.set=function(e,t,n){return ut.set.call(this,e[0],t,n,e[0])};function vt(e,t){const n=Ue(e)?Qe("MapSet").proxyMap_(e,t):Ke(e)?Qe("MapSet").proxySet_(e,t):function(e,t){const n=Array.isArray(e),r={type_:n?1:0,scope_:t?t.scope_:et(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let o=r,i=ut;n&&(o=[r],i=dt);const{revoke:l,proxy:a}=Proxy.revocable(o,i);return r.draft_=a,r.revoke_=l,a}(e,t);return(t?t.scope_:et()).drafts_.push(n),n}function mt(e){if(!Le(e)||Ze(e))return e;const t=e[Be];let n;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=qe(e,t.scope_.immer_.useStrictShallowCopy_)}else n=qe(e,!0);return ze(n,((e,t)=>{Ve(n,e,mt(t))})),t&&(t.finalized_=!1),n}var yt=new class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(e,t,n)=>{if("function"==typeof e&&"function"!=typeof t){const n=t;t=e;const r=this;return function(e=n,...o){return r.produce(e,(e=>t.call(this,e,...o)))}}let r;if("function"!=typeof t&&Te(6),void 0!==n&&"function"!=typeof n&&Te(7),Le(e)){const o=ot(this),i=vt(e,void 0);let l=!0;try{r=t(i),l=!1}finally{l?nt(o):rt(o)}return tt(o,n),lt(r,o)}if(!e||"object"!=typeof e){if(r=t(e),void 0===r&&(r=e),r===Pe&&(r=void 0),this.autoFreeze_&&Ye(r,!0),n){const t=[],o=[];Qe("Patches").generateReplacementPatches_(e,r,t,o),n(t,o)}return r}Te(1)},this.produceWithPatches=(e,t)=>{if("function"==typeof e)return(t,...n)=>this.produceWithPatches(t,(t=>e(t,...n)));let n,r;return[this.produce(e,t,((e,t)=>{n=e,r=t})),n,r]},"boolean"==typeof e?.autoFreeze&&this.setAutoFreeze(e.autoFreeze),"boolean"==typeof e?.useStrictShallowCopy&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){Le(e)||Te(8),Ne(e)&&(e=function(e){Ne(e)||Te(10);return mt(e)}(e));const t=ot(this),n=vt(e,void 0);return n[Be].isManual_=!0,rt(t),n}finishDraft(e,t){const n=e&&e[Be];n&&n.isManual_||Te(9);const{scope_:r}=n;return tt(r,t),lt(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){const r=t[n];if(0===r.path.length&&"replace"===r.op){e=r.value;break}}n>-1&&(t=t.slice(n+1));const r=Qe("Patches").applyPatches_;return Ne(e)?r(e,t):this.produce(e,(e=>r(e,t)))}},bt=yt.produce;yt.produceWithPatches.bind(yt),yt.setAutoFreeze.bind(yt),yt.setUseStrictShallowCopy.bind(yt),yt.applyPatches.bind(yt);var wt=yt.createDraft.bind(yt),xt=yt.finishDraft.bind(yt);function kt(e,t){switch(t.type){case"set_slate":{const{properties:n,blockId:r}=t,o=e.blockEditorsMap[r];if(o){const{slateOps:e,selectionBefore:t}=n;m.withoutNormalizing(o,(()=>{for(const t of e)o.apply(t);if(t)try{w.select(o,t),C.focus(o)}catch(e){}}))}break}case"insert_block":e.blockEditorsMap[t.block.id]=ve(e),e.children[t.block.id]=t.block,e.blockEditorsMap[t.block.id].children=t.block.value,Object.keys(e.children).forEach((n=>{const r=e.children[n];r.meta.order>=t.block.meta.order&&r.id!==t.block.id&&Ne(e.children[r.id])&&(r.meta.order=r.meta.order+1)}));break;case"delete_block":{delete e.blockEditorsMap[t.block.id],delete e.children[t.block.id];const n=Object.values(e.children);n.forEach((e=>{e.meta.order>t.block.meta.order&&(Ne(e)?e.meta.order--:bt(e,(e=>{e.meta.order--})))})),n.sort(((e,t)=>e.meta.order-t.meta.order)),n.forEach(((e,t)=>{Ne(e.meta)?e.meta.order=t:bt(e,(e=>{e.meta=Object.assign(Object.assign({},e.meta),{order:t})}))}));break}case"set_block_value":{const{id:n,value:r,forceSlate:o}=t,i=e.blockEditorsMap[n];o&&i&&(i.children=r),Array.isArray(r)&&(Ne(e.children[n])?e.children[n].value=r:bt(e.children[n],(e=>{e.value=r})));break}case"set_block_meta":{const{id:n,properties:r}=t,o=e.children[n];if(!o)break;Ne(o)?Object.keys(r).forEach((e=>{o.meta[e]=r[e]})):bt(o,(e=>{e.meta=Object.assign(Object.assign({},e.meta),r)}));break}case"split_block":{const{properties:n}=t,r=ve(e);r.children=n.nextSlateValue,e.children[n.nextBlock.id]=Object.assign(Object.assign({},n.nextBlock),{value:r.children}),e.blockEditorsMap[n.nextBlock.id]=r;const o=e.blockEditorsMap[t.prevProperties.originalBlock.id];o.children=n.splitSlateValue,e.children[t.prevProperties.originalBlock.id].value=o.children,Object.values(e.children).forEach((e=>{e.meta.order>=n.nextBlock.meta.order&&e.id!==n.nextBlock.id&&(Ne(e)?e.meta.order++:bt(e,(e=>{e.meta.order++})))}));break}case"merge_block":{const{prevProperties:n,properties:r}=t;delete e.blockEditorsMap[n.sourceBlock.id],delete e.children[n.sourceBlock.id],e.children[r.mergedBlock.id]=r.mergedBlock,e.blockEditorsMap[r.mergedBlock.id].children=r.mergedSlateValue,Object.values(e.children).forEach((e=>{e.meta.order>r.mergedBlock.meta.order&&(Ne(e)?e.meta.order--:bt(e,(e=>{e.meta.order--})))}));break}case"move_block":{const{prevProperties:n,properties:r}=t,o=e.children[n.id];o&&(o.meta.order=r.order,Object.values(e.children).forEach((e=>{e.id!==n.id&&(n.order<r.order?e.meta.order>n.order&&e.meta.order<=r.order&&e.meta.order--:e.meta.order<n.order&&e.meta.order>=r.order&&e.meta.order++)})));break}case"set_block_path":e.path=t.path;break;case"set_editor_value":{e.children=t.properties.value;const n={};Object.keys(e.children).forEach((t=>{const r=e.children[t],o=ve(e);o.children=r.value,n[t]=o})),e.blockEditorsMap=n;break}case"validate_block_paths":{const t=Object.values(e.children);t.sort(((e,t)=>e.meta.order-t.meta.order)),t.forEach(((e,t)=>{Ne(e.meta)?e.meta.order=t:bt(e,(e=>{e.meta=Object.assign(Object.assign({},e.meta),{order:t})}))}));break}}}const Ot=100;const Et=new WeakMap,_t=new WeakMap,St={isMergingHistory:e=>_t.get(e),isSavingHistory:e=>Et.get(e),withMergingHistory(e,t){const n=St.isMergingHistory(e);_t.set(e,!0),t(),_t.set(e,n)},withSavingHistory(e,t){const n=St.isSavingHistory(e);Et.set(e,!0),t(),Et.set(e,n)},withoutMergingHistory(e,t){const n=St.isMergingHistory(e);_t.set(e,!1),t(),_t.set(e,n)},withoutSavingHistory(e,t){const n=St.isSavingHistory(e);Et.set(e,!1),t(),Et.set(e,n)},redo:(e,t)=>{const{redos:n}=e.historyStack;if(n.length>0){const r=n[n.length-1];St.withoutSavingHistory(e,(()=>{e.applyTransforms(r.operations,{source:"history"}),e.setPath(r.path);const{scroll:n=!0}=t||{};if(n&&"number"==typeof r.path.current){const t=Se.getBlock(e,{at:r.path.current}),n=document.querySelector(`[data-yoopta-block-id="${null==t?void 0:t.id}"]`);n&&!Ct(n)&&n.scrollIntoView({block:"center",behavior:"auto"})}})),e.historyStack.redos.pop(),e.historyStack.undos.push(r)}},undo:(e,t)=>{const{undos:n}=e.historyStack;if(n.length>0){const n=e.historyStack.undos[e.historyStack.undos.length-1];St.withoutSavingHistory(e,(()=>{const r=n.operations.flatMap((e=>function(e,t){switch(t.type){case"insert_block":return{type:"delete_block",path:t.path,block:t.block};case"delete_block":return{type:"insert_block",path:t.path,block:t.block};case"set_block_meta":return{type:"set_block_meta",id:t.id,properties:t.prevProperties,prevProperties:t.properties};case"split_block":return[{type:"delete_block",block:t.properties.nextBlock,path:t.path},{type:"set_block_value",id:t.prevProperties.originalBlock.id,value:t.prevProperties.originalValue,forceSlate:!0}];case"merge_block":return[{type:"split_block",properties:{nextBlock:t.prevProperties.sourceBlock,nextSlateValue:t.prevProperties.sourceSlateValue,splitSlateValue:t.prevProperties.targetSlateValue},prevProperties:{originalBlock:t.properties.mergedBlock,originalValue:t.properties.mergedSlateValue},path:t.path}];case"move_block":return{type:"move_block",properties:t.prevProperties,prevProperties:t.properties};case"set_slate":return{type:"set_slate",properties:{slateOps:t.properties.slateOps.map(S.inverse).reverse(),selectionBefore:t.properties.selectionBefore},slate:t.slate,blockId:t.blockId};case"set_editor_value":return{type:"set_editor_value",properties:t.prevProperties,prevProperties:t.properties};default:return t}}(0,e))).reverse();e.applyTransforms(r,{source:"history"}),e.setPath(n.path);const{scroll:o=!0}=t||{};if(o&&"number"==typeof n.path.current){const t=Se.getBlock(e,{at:n.path.current}),r=document.querySelector(`[data-yoopta-block-id="${null==t?void 0:t.id}"]`);r&&!Ct(r)&&r.scrollIntoView({block:"center",behavior:"auto"})}})),e.historyStack.redos.push(n),e.historyStack.undos.pop()}}};function Ct(e){var t=e.getBoundingClientRect(),n=document.documentElement;return t.top>=0&&t.left>=0&&t.bottom<=(window.innerHeight||n.clientHeight)&&t.right<=(window.innerWidth||n.clientWidth)}var jt={};function Dt(e){return e.map((e=>{var t,n;if("text"in e){let r=e.text;return e.bold&&(r=`<strong style="font-weight: bolder;">${r}</strong>`),e.italic&&(r=`<i>${r}</i>`),e.strike&&(r=`<s>${r}</s>`),e.underline&&(r=`<u>${r}</u>`),e.code&&(r=`<code style="background-color: rgb(242 242 242); border-radius: .25rem; font-size: 75%; padding: 3px 6px;">${r}</code>`),e.highlight&&(r=`<mark style="color: ${null===(t=e.highlight)||void 0===t?void 0:t.color}; background-color: ${(null===(n=e.highlight)||void 0===n?void 0:n.backgroundColor)||"transparent"};">${r}</mark>`),r}if("link"===e.type){const{url:t,target:n,rel:r}=e.props;return`<a href="${t}" target="${n}" rel="${r}" style="color: rgb(0 122 255);\n cursor: pointer;\n position: relative;\n text-decoration-line: underline;\n text-underline-offset: 4px;">${Dt(e.children)}</a>`}return""})).join("")}function At(e){return e.map((e=>{if("text"in e){let t=e.text;return e.bold&&(t=`**${t}**`),e.italic&&(t=`*${t}*`),e.strike&&(t=`~~${t}~~`),e.underline&&(t=`<u>${t}</u>`),e.code&&(t=`\`${t}\``),t}if("link"===e.type){const{url:t,target:n,rel:r}=e.props;return`[${At(e.children)}](${t})`}return""})).join("")}!function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function i(e,t,r,i,l){if("function"!=typeof r)throw new TypeError("The listener must be a function");var a=new o(r,i||e,l),s=n?n+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],a]:e._events[s].push(a):(e._events[s]=a,e._eventsCount++),e}function l(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t]}function a(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),a.prototype.eventNames=function(){var e,r,o=[];if(0===this._eventsCount)return o;for(r in e=this._events)t.call(e,r)&&o.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},a.prototype.listeners=function(e){var t=n?n+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,i=r.length,l=new Array(i);o<i;o++)l[o]=r[o].fn;return l},a.prototype.listenerCount=function(e){var t=n?n+e:e,r=this._events[t];return r?r.fn?1:r.length:0},a.prototype.emit=function(e,t,r,o,i,l){var a=n?n+e:e;if(!this._events[a])return!1;var s,c,u=this._events[a],d=arguments.length;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),d){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,r),!0;case 4:return u.fn.call(u.context,t,r,o),!0;case 5:return u.fn.call(u.context,t,r,o,i),!0;case 6:return u.fn.call(u.context,t,r,o,i,l),!0}for(c=1,s=new Array(d-1);c<d;c++)s[c-1]=arguments[c];u.fn.apply(u.context,s)}else{var f,p=u.length;for(c=0;c<p;c++)switch(u[c].once&&this.removeListener(e,u[c].fn,void 0,!0),d){case 1:u[c].fn.call(u[c].context);break;case 2:u[c].fn.call(u[c].context,t);break;case 3:u[c].fn.call(u[c].context,t,r);break;case 4:u[c].fn.call(u[c].context,t,r,o);break;default:if(!s)for(f=1,s=new Array(d-1);f<d;f++)s[f-1]=arguments[f];u[c].fn.apply(u[c].context,s)}}return!0},a.prototype.on=function(e,t,n){return i(this,e,t,n,!1)},a.prototype.once=function(e,t,n){return i(this,e,t,n,!0)},a.prototype.removeListener=function(e,t,r,o){var i=n?n+e:e;if(!this._events[i])return this;if(!t)return l(this,i),this;var a=this._events[i];if(a.fn)a.fn!==t||o&&!a.once||r&&a.context!==r||l(this,i);else{for(var s=0,c=[],u=a.length;s<u;s++)(a[s].fn!==t||o&&!a[s].once||r&&a[s].context!==r)&&c.push(a[s]);c.length?this._events[i]=1===c.length?c[0]:c:l(this,i)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&l(this,t)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a}({get exports(){return jt},set exports(e){jt=e}});const Pt={head:{meta:[{content:"width=device-width",name:"viewport"},{charset:"UTF-8"},{content:"IE=edge","http-equiv":"X-UA-Compatible"}]},body:{attrs:{style:{margin:"0 auto",padding:0,width:"900px"}}},container:{attrs:{style:{margin:"0 auto",width:"600px"}}}};function Rt(e,t,n){var r,o,i,l,a;const s=Tt(Pt,n||{}),c=Object.values(t).filter((t=>{const n=Z.getSelectedPaths(e);return!(Array.isArray(n)&&n.length>0)||(null==n?void 0:n.includes(t.meta.order))})).sort(((e,t)=>e.meta.order-t.meta.order)).map((t=>{var n,r;const o=e.plugins[t.type];if(o&&(null===(r=null===(n=o.parsers)||void 0===n?void 0:n.email)||void 0===r?void 0:r.serialize)){const e=Dt(t.value[0].children);return o.parsers.email.serialize(t.value[0],e,t.meta)}return""})),u=c.join("");if(s.customTemplate)return s.customTemplate(u);const d=Bt(null===(r=s.body)||void 0===r?void 0:r.attrs),f=Bt(null===(o=s.container)||void 0===o?void 0:o.attrs);return`\n <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n <html lang="en">\n <head>\n <title>${(null===(i=null==s?void 0:s.head)||void 0===i?void 0:i.title)||"Email-Builder"}</title>\n <meta http-equiv="Content-Type" content="text/html charset=UTF-8" />\n ${function(e=[]){return e.map((e=>`<meta ${Object.entries(e).filter((([e,t])=>void 0!==t)).map((([e,t])=>""===t?e:`${e}="${t}"`)).join(" ")}>`)).join("\n")}(null===(l=s.head)||void 0===l?void 0:l.meta)}\n ${function(e=[]){return e.map((e=>`<style${e.id?` id="${e.id}"`:""}>${e.content}</style>`)).join("\n")}(null===(a=s.head)||void 0===a?void 0:a.styles)}\n </head>\n <body id="yoopta-email" ${d}>\n <table ${f}>\n <tbody>\n <tr>\n <td>\n ${u}\n </td>\n </tr>\n </tbody>\n </table>\n </body>\n </html>\n `}function Bt(e){return e?Object.entries(e).map((([e,t])=>{if("style"===e){const e=(n=t)?Object.entries(n).map((([e,t])=>`${e.replace(/[A-Z]/g,(e=>`-${e.toLowerCase()}`))}: ${t}${"number"==typeof t?"px":""};`)).join(" "):"";return`style="${e}"`}var n;return`${e}="${t}"`})).join(" "):""}function Tt(e,t){return Array.isArray(e)&&Array.isArray(t)?e.concat(t):"object"==typeof e&&"object"==typeof t?Object.keys(Object.assign(Object.assign({},e),t)).reduce(((n,r)=>(n[r]=Tt(e[r],t[r]),n)),{}):t}const Mt=new jt,Nt=(e,t)=>Mt.on(e,t),Lt=(e,t)=>Mt.once(e,t),It=(e,t)=>Mt.off(e,t),Ft=(e,t)=>Mt.emit(e,t);function zt(){const e={id:"",children:{},blockEditorsMap:{},path:{current:null},readOnly:!1,isEmpty:()=>function(e){const t=Object.values(e.children);if(t.length>1)return!1;const n=t[0];if(!n)return!0;if("Paragraph"!==n.type)return!1;const r=re(e,{at:n.meta.order});if(!r)return!0;try{return!(m.string(r,[0]).length>0)}catch(e){return!0}}(e),getEditorValue:()=>function(e){return e.children}(e),setEditorValue:(...t)=>function(e,t){let n;if(null!==t&&fe(t))n=t;else{const e=Se.buildBlockData();n={[e.id]:e}}const r={type:"set_editor_value",properties:{value:n},prevProperties:{value:e.children}};e.applyTransforms([r],{validatePaths:!0})}(e,...t),insertBlock:(...t)=>W(e,...t),deleteBlock:(...t)=>G(e,...t),duplicateBlock:(...t)=>pe(e,...t),toggleBlock:(...t)=>we(e,...t),increaseBlockDepth:(...t)=>ue(e,...t),decreaseBlockDepth:(...t)=>de(e,...t),moveBlock:(...t)=>Q(e,...t),focusBlock:(...t)=>te(e,...t),getBlock:(...t)=>xe(e,...t),updateBlock:(...t)=>he(e,...t),splitBlock:(...t)=>ce(e,...t),mergeBlock:(...t)=>_e(e,...t),setPath:(...t)=>Y(e,...t),blocks:{},formats:{},shortcuts:{},plugins:{},commands:{},applyTransforms:(t,...n)=>function(e,t,n){e.children=wt(e.children),e.path=wt(e.path);const{validatePaths:r=!0,source:o}=n||{},i=[...t];r&&i.push({type:"validate_block_paths"}),i.length>1&&i.sort(((e,t)=>"insert_block"===e.type&&"insert_block"===t.type?e.block.meta.order-t.block.meta.order:0));for(const t of i)"set_slate"===t.type&&"api"===o||kt(e,t);if(Ne(e.children)||(e.children=wt(e.children)),e.children=xt(e.children),Ne(e.path)&&(e.path=xt(e.path)),!1!==e.isSavingHistory()){const t={operations:i.filter((e=>"set_block_path"!==e.type&&"set_block_value"!==e.type&&"validate_block_paths"!==e.type)),path:e.path};t.operations.length>0&&"history"!==o&&(e.historyStack.undos.push(t),e.historyStack.redos=[]),e.historyStack.undos.length>Ot&&e.historyStack.undos.shift()}const l={value:e.children,operations:i};e.emit("change",l),e.emit("path-change",e.path)}(e,t,...n),batchOperations:t=>function(e,t){const n=[];let r={};const o=e.applyTransforms;e.applyTransforms=(e,t)=>{t&&(r=t),n.push(...e)},t(),e.applyTransforms=o,n.length>0&&e.applyTransforms(n,r)}(e,t),on:(e,t)=>Nt(e,t),off:(e,t)=>It(e,t),emit:(e,...t)=>Ft(e,...t),once:(e,t)=>Lt(e,t),isFocused:()=>function(e){return!!ee.get(e)}(e),focus:()=>function(e){if(e.readOnly)return;const t=ne(e,{at:0});t&&(ee.set(e,!0),e.focusBlock(t.id,{waitExecution:!0}),e.emit("focus",!0))}(e),blur:(...t)=>function(e,t={}){var n;const r=null!==(n=t.slate)&&void 0!==n?n:re(e);if(!r)return;const{waitExecution:o,waitExecutionMs:i}=t;o?setTimeout((()=>Ce(e,r)),i):(ee.set(e,!1),Ce(e,r),e.emit("blur",!1))}(e,...t),getHTML:t=>Ae(e,t),getMarkdown:t=>function(e,t){re