edytor 0.0.5 → 0.0.6

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.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("yjs"),n=require("nanoid"),r=(e=require("is-hotkey"))&&"object"==typeof e&&"default"in e?e.default:e,o=require("y-websocket");function a(){return(a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function i(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function s(e,t){if(null==e)return{};var n,r,o={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||(o[n]=e[n]);return o}var l=["id","text","data"],f=function(e){var n=new t.Map;if(n.set("id",(null==e?void 0:e.id)||M()),n.set("text",new t.Text((null==e?void 0:e.text)||"")),e){var r=e.text,o=e.data,a=s(e,l);n.set("text",new t.Text(r||"")),o&&n.set("data",new t.Map(Object.entries(o))),a&&Object.keys(a).forEach((function(e){n.set(e,a[e])}))}return n},c=function(e,n){var r=new t.Map;return r.set("id",(null==n?void 0:n.id)||M()),r.set("type",e),null!=n&&n.data&&r.set("data",new t.Map(Object.entries(n.data))),r.set("content",(null==n?void 0:n.content)instanceof t.Array?n.content:t.Array.from((null==n?void 0:n.content)||[f()])),r.set("children",(null==n?void 0:n.children)instanceof t.Array?n.children:t.Array.from((null==n?void 0:n.children)||[])),r},d=function(e){function t(){return e.apply(this,arguments)||this}return i(t,e),t}(t.Map),u=["type","content","children"],p=function(e){return f(e)},g=function e(t){var n=t.type,r=t.content,o=void 0===r?[]:r,i=t.children,l=void 0===i?[]:i,f=s(t,u);return c(n,a({},f,{children:l.map(e),content:o.map(p)}))},h=function(e){function t(t){return e.call(this)||this}return i(t,e),t}(t.Doc),v=function(e,t){var n=t.mode,r=t.selection||e.selection,o=r.start,a=r.end,i=r.length,s=r.edges,l=r.setPosition;switch(r.type){case"collapsed":if("backward"===n&&s.startNode){if(console.log(o.nodeIndex,ie(o.leaf),o.path.length),!(o.nodeIndex===o.node.parent.length-1&&o.path.length>1&&0!==o.nodeIndex))return D(e),l(o.leafId,{offset:0});console.log(o.leafId);var c=_(o.node);o.node.parent.delete(o.nodeIndex),o.node.parent.parent.parent.insert(F(o.node.parent.parent)+1,[c]),l(o.leafId,{offset:0})}if("backward"===n&&s.startLeaf){var d=re(o.leaf).get(o.leafIndex-1);return U(d,X(d)-1,i||1),l(d.get("id"),{offset:X(d)})}if("forward"===n&&s.endNode)return I(e);if("forward"===n&&s.endLeaf){var u=re(o.leaf).get(o.leafIndex+1);return U(u,0,i||1)}U(o.leaf,o.offset+("backward"===n?-i||-1:i),i||1),l(o.leaf.get("id"),{offset:o.offset+("backward"===n?-i||-1:i)});break;case"singlenode":U(o.leaf,o.offset,i,!0),C(R(o.leaf))&&re(o.leaf).insert(0,[f()]),l(o.leaf.get("id"),{offset:o.offset});break;case"multileaves":case"multinodes":var p=o.path.join(","),g=a.path.join(",");e.doc.transact((function(){var t=new K,n=t.reap,r=t.burn;return W(e,(function(e,t){if(t){var r=q(e),i=X(e);r.join(",")===p?(U(e,o.offset,i),n(e,!1)):r>o.path&&r<a.path?(U(e,0,i),n(e,!0)):r.join(",")===g&&(U(e,0,a.offset),n(e,a.offset===i))}}),{start:o.path[0],end:a.path[0]+1}),r(e)})),l(o.leaf.get("id"),{offset:o.offset})}},x=function(e,t){Array.from(e.keys(),(function(n){"text"!==n&&t.forEach((function(t){t.set(n,e.get(n))}))}))},m=function(e){var t=e.format,n=e.value,r=e.start,o=e.end,i=o.offset-r.offset,s=r.leaf,l=z(s).toString(),c=F(s),d=s.has(t);if(d&&X(s)===i)return s.delete(t),s;var u,p=l.substring(o.offset,X(s));if(0==p.length&&X(s)===o.offset-r.offset)return s.set(t,n),s;U(s,r.offset,X(s));var g=f(a({},s.toJSON(),((u={id:void 0})[t]=n,u.text=l.substring(r.offset,o.offset),u))),h=[g];return p.length>0&&h.push(f(a({},s.toJSON(),{id:void 0,text:p}))),d&&g.delete(t),h.length&&re(s).insert(c+1,h),g},y=function(e,t){var n=Object.entries(t)[0],r=n[0],o=n[1];console.log(r);var a=0,i=e.selection,s=i.start,l=i.end,c=i.type,d=i.length,u=i.setPosition,p=i.selectedText;return e.doc.transact((function(){switch(c){case"collapsed":var t=s.leaf.has(r);if(t&&Q(s.leaf))s.leaf.delete(r),a=re(s.leaf).toArray().indexOf(s.leaf);else if(Q(s.leaf))t?s.leaf.delete(r):s.leaf.set(r,o);else{var n;k(e,{yText:s.leaf.get("text"),at:s});var i=f(((n={text:""})[r]=o,n));x(s.leaf,[i]),t&&i.delete(r),re(s.leaf).insert(s.path.slice().reverse()[0]+1,[i]),Q(s.leaf)&&re(s.leaf).delete(s.path.slice().reverse()[0]),a=re(s.leaf).toArray().indexOf(i)}w(re(s.leaf));break;case"singlenode":e.doc.transact((function(){var e=m({format:r,value:o,start:s,end:l,length:d});if(w(re(s.leaf)),e._item.deleted){var t=e.parent.get(s.leafIndex-1),n=z(t).toJSON().indexOf(p);setTimeout((function(){u(t.get("id"),{offset:n,end:n+p.length})}))}else u(s.leaf.get("id"),{offset:s.offset}),setTimeout((function(){u(e.get("id"),{offset:0,end:X(e)})}))}));break;case"multileaves":case"multinodes":var g=s.path.join(","),h=l.path.join(","),v=!1,y=!1;W(e,(function(e,t){if(t){var n=q(e),a=n.join(",")===g,i=n.join(",")===q(l.leaf).join(",");console.log({isEnd:i},h,q(l.leaf).join(","),n.join(",")),a&&(v=!0);var f=a?s.offset:0,c=i?l.offset:X(e);v&&!y&&m({format:r,start:{leaf:e,offset:f},end:{offset:c},value:o}),console.log({ended:y}),i&&(y=!0),w(re(e))}}),{start:s.path[0],end:l.path[0]+1})}})),a},b=function(e,t){var n=t.text;if(n&&null!==n&&n.length){var r=e.selection,o=r.start,a=r.end,i=r.type,s=r.length,l=r.setPosition;if("notInDoc"===i)return console.error("Path is not in document space");switch(i){case"collapsed":V(o.leaf,o.offset,n),l(o.leaf.get("id"),{offset:o.offset+n.length});break;case"singlenode":Z(o.leaf,o.offset,s,n),l(o.leaf.get("id"),{offset:o.offset+n.length});break;case"multileaves":case"multinodes":var f=o.path.join(","),c=a.path.join(",");e.doc.transact((function(){var t=new K,r=t.reap,i=t.burn;W(e,(function(e,t){if(t){var i=q(e);i.join(",")===f?(Z(e,o.offset,X(e),n),r(e)):i>o.path&&i<a.path?(U(e,0,X(e)),r(e)):i.join(",")===c&&(U(e,0,a.offset),r(e))}}),{start:o.path[0],end:a.path[0]+1}),i(e)})),l(o.leaf.get("id"),{offset:o.offset+n.length})}}},N=function(e){var t=e.map((function(e){return Array.from(e.keys())})).flat();return e.every((function(e){return t.every((function(t){return e.has(t)}))}))},w=function(e){var t=e.get(0),n=[];e.forEach((function(r,o){var a=e.get(o+1);if(a)if(N([t,a])){var i=t.get("text");t.get("text").insert(i.length,a.get("text").toString()),n.push(a)}else t=a})),n.forEach((function(t){e.delete(F(t))}))},k=function(e,n){var r,o=n.yText,a=n.at,i=o.toString().substring(a.offset,o.length);if(a.offset!==o.length){var s=new t.Text(i),l=new t.Map;l.set("text",s),x(o.parent,[l]);var f=null==o||null==(r=o.parent)?void 0:r.parent;o.delete(a.offset,o.length),f.insert(a.path.slice().reverse()[0]+1,[l])}},O=function(e){var t=e.selection,n=t.start,r=t.type,o=t.setPosition,i=t.edges,s=n.leaf,l=re(n.leaf),d=te(n.leaf),u=F(n.leaf),p=F(d),g=function(){var t=l.toArray().filter((function(e,t){return t>u})),r=G(n.leaf).substring(null==n?void 0:n.offset,X(n.leaf));U(n.leaf,null==n?void 0:n.offset,r.length,!1);var i=C(d)?A(d):d.parent,g=f(a({},s.toJSON(),{id:void 0,text:r}));i.insert(C(d)?0:p+1,[c(e.defaultBlock,{children:[],content:[g].concat(t.map((function(e){return f(e.toJSON())})))})]),l.delete(u+1,oe(n.leaf)-u-1),setTimeout((function(){o(g.get("id"),{offset:0})}),10)},h=!(i.startNode&&i.endNode||"multinodes"===r);if((i.endNode||i.startNode)&&"collapsed"===r){var x=c(e.defaultBlock);return d.parent.insert(p+(i.endNode?1:0),[x]),setTimeout((function(){o(x.get("content").get(0).get("id"),{offset:0})}))}switch(r){case"collapsed":h&&g();break;case"singlenode":v(e,{mode:"backward"}),h&&g(),!h&&o(n.leaf.get("id"),{offset:n.offset});break;case"multileaves":case"multinodes":v(e,{mode:"backward"}),h&&g(),!h&&o(n.leaf.get("id"),{offset:n.offset})}},T=function(e){var t=e.selection,n=t.start,r=t.type,o=t.end,i=t.setPosition,s=R(n.leaf),l=s.toJSON(),f=q(s),d=f.slice().reverse(),u=d[0],h=d.slice(1),v=H(e,[].concat(h,[u-1])),x=S(s);switch(r){case"singlenode":case"collapsed":if(!v)return;var m=n.leaf.get("id"),y=v.get("children");x.delete(u),y.insert(y.length,[c(l.type,a({},l,{children:l.children.map(g),content:l.content.map(p)}))]),i(m,{offset:n.offset});break;case"multileaves":case"multinodes":var b=0,N=[],w=n.leaf.get("id"),k=n.path.slice(0,n.path.length-1).join(""),O=o.path.slice(0,n.path.length-1).join("");if(W(e,(function(e,t){if(!t){var n=q(e).join("");if(n.length===f.length&&n<=O&&n>=k){b++;var r=e.toJSON();N.push(c(r.type,a({},r,{children:r.children.map(g),content:r.content.map(p)})))}}}),{start:n.path[0],end:o.path[0]+1}),!v)return;var T=v.get("children");x.delete(u,b),T.insert(T.length,N),i(w,{offset:n.offset})}},E=function(e){var t=e.from,n=e.to,r=Array.isArray(t.at)?t.at:[t.at],o=t.container.get(r[0]),a=r.map((function(e){var n=t.container.get(e);return _(n)}));return n.container.insert(n.at,a),t.container.delete(F(o),r.length),a[0].get("content").get(0).get("id")},j=["type"],D=function(e){var t,n=e.selection.start,r=!1;W(e,(function(e,o){o&&(e===n.leaf?r=!0:r||(t=e))})),t&&(re(t).insert(oe(t),re(n.leaf).toArray().map((function(e){return f(e.toJSON())}))),w(re(t)),n.leaf.parent.parent.delete(F(R(n.leaf))))},I=function(e){var t,n=e.selection.start,r=!1;e.doc.traverse((function(e,o){o&&(e===n.leaf?r=!0:r&&(t=e,r=!1))})),console.log(re(t).toArray()),re(n.leaf).insert(oe(n.leaf),re(t).toArray().map((function(e){return f(e.toJSON())}))),w(re(n.leaf)),console.log(n.leaf.parent.toJSON());var o=R(t);return C(o)&&(console.log(o.get("children").toJSON()),o.parent.insert(F(o),o.get("children").toJSON().map((function(e){return c(e.type,e)})))),o.parent.delete(F(o)),t},L=function(e,t){if(B(e))e.parent.delete(F(e));else if(J(e)){var n=A(e).toJSON(),r=F(e);e.parent.delete(r),e.parent.insert(r,n.map((function(e){var t=e.type,n=s(e,j);return c(t,n)})))}e.parent===(e.doc.getArray("children")&&0===e.doc.getArray("children").length)&&e.parent.insert(0,[c(t,{content:[f()]})])},S=function(e){return e.parent},A=function(e){return e.get("children")},P=function(e){return e.get("content")},C=function(e){return A(e).length>0},B=function(e){return J(e)&&!C(e)},J=function(e){return 0===P(e).length||0===P(e).toArray().map(G).join("").length},_=function(e){var t=e.toJSON();return c(t.type,a({},t,{children:t.children.map(g),content:t.content.map(p)}))},M=function(){return"y-"+n.customAlphabet("346789ABCDEFGHJKLMNPQRTUV-WXYabcdefghijkmnpqrtwxyz",20)()},R=function(e){var t;return null==e||null==(t=e.parent)?void 0:t.parent},F=function(e){for(var t=0,n=!1,r=e.parent._start;null!==r&&!n;){if(r.countable&&!r.deleted)for(var o=r.content.getContent(),a=0;a<o.length;a++){if(o[a]===e){n=!0;break}t++}r=r.right}return t},q=function(e){for(var t=[],n=e;n;)t.push(F(n)),n=R(n);return t.reverse()},H=function(e,t){for(var n=t[0],r=t.slice(1),o=e.children.get(n),a=0;a<r.length;a++){var i=r[a];o=o.get?o.get("children").get(i):void 0}return o},W=function(e,t,n){for(var r=function e(n,r){if(n.has("text"))t(n,!0,r);else{var o=P(n).toArray().concat(A(n).toArray());t(n,!1,r);for(var a=0;a<o.length;a++)e(o[a],[].concat(r.slice(0,r.length-1),[0,a]))}},o=e.children.toArray().slice((null==n?void 0:n.start)||0,(null==n?void 0:n.end)||e.children.length),a=0;a<o.length;a++)r(o[a],[a+((null==n?void 0:n.start)||0)])},K=function(){var e=this;this.reap=function(t,n){if(void 0===n&&(n=!1),Q(t)){var r=ne(t);e.leaves[r]||(e.leaves[r]={shouldDeleteNode:n,content:re(t),node:te(t),indexes:[]}),e.leaves[r].indexes.push(F(t))}},this.burn=function(t){Object.values(e.leaves).forEach((function(e,n){var r=e.shouldDeleteNode,o=e.content,a=e.node,i=e.indexes;if(o.delete(i[0],i.length),0!==o.length||r){if(r)return L(a,null==t?void 0:t.defaultBlock)}else o.insert(0,[createLeaf()])}))},this.leaves={}},Y=function(e){return e.get("data")},z=function(e){return e.get("text")},X=function(e){return z(e).length},G=function(e){return z(e).toString()},Q=function(e){return void 0===z(e)||0===X(e)},U=function(e,t,n,r){z(e).delete(t,n),r&&ee(e)},V=function(e,t,n){z(e).insert(t,n)},Z=function(e,t,n,r){var o=G(e).split("");return o.splice.apply(o,[t,n].concat(r.split(""))),$(e,o.join(""))},$=function(e,t){var n=z(e);n.delete(0,n.length),n.insert(0,t)},ee=function(e){Q(e)&&re(e).delete(F(e))},te=function(e){return e.parent.parent},ne=function(e){return te(e).get("id")},re=function(e){return e.parent},oe=function(e){return re(e).length},ae=function(e){return te(e).get("children")},ie=function(e){return ae(e).length},se=function(e){return e.dataTransfer.getData("text/plain")};exports.DocFromJson=function(e){var n=new t.Doc;return n.getArray("children").insert(0,e.map(g)),n},exports.Dropper=function(){var e=this;this.init=function(t,n){e.editor=t,e.doc=t.doc,e.container=n,e.editorId=t.editorId,e.selection=t.selection,e.ID_TO_NODE=t.ID_TO_NODE,e.allowNesting=t.allowNesting},this.startDrag=function(t,n){var r;e.node=t,document.getElementById("dndIndicator").style.opacity="1";var o=document.getElementById(t.get("id"));o.style.opacity="0.4",document.body.style.cursor="grabbing",e.from={container:t.parent,at:F(t)},e.startPath=q(t),null==(r=n.dataTransfer)||r.setDragImage(o,n.offsetX,n.offsetY),document.addEventListener("mousemove",e.onDrag),document.addEventListener("mouseup",e.dragEnd)},this.dragEnd=function(){var t=document.getElementById(e.node.get("id"));t&&(t.style.opacity="1"),document.body.style.cursor="auto",document.removeEventListener("mousemove",e.onDrag),document.removeEventListener("mouseup",e.dragEnd);var n=E({from:e.from,to:e.to});document.getElementById("dndIndicator").style.opacity="0",setTimeout((function(){console.log(n),e.selection.setPosition(n,{offset:0})}))},this.getHoveredNode=function(t){for(var n,r=t,o=0;!n&&(null==(a=r)?void 0:a.id)!==e.editorId&&r&&o<100;){var a;if(r.hasAttribute("data-edytor-block")){n=e.ID_TO_NODE.get(r.id);break}r=r.parentElement,o++}return n?{hoveredElement:r,hoveredNode:n}:{}},this.onDrag=function(t){var n=e.getHoveredNode(t.target),r=n.hoveredElement,o=n.hoveredNode,a=document.getElementById("dndIndicator");if(o&&r&&a&&o!==e.node){var i=r.getBoundingClientRect(),s=t.y<i.top+i.height/2,l=i,f=e.allowNesting&&!s&&t.x>l.left+l.width/5,c=s?l.top:l.top+l.height,d=f?30:0,u=q(o),p=u.slice().reverse(),g=p[0],h=p.slice(1);e.startPath.join("")!==h.join("")&&(a.style.width=l.width-d+"px",a.style.top=c+window.pageYOffset+"px",a.style.left=l.left+d+"px",-1===(g+=s?0:1)&&(g=0),e.to={container:f?o.get("children"):1===u.length?e.editor.children:o.parent,at:f?0:g})}}},exports.EdytorDoc=h,exports.EdytorSelection=function(){var e=this;this.init=function(t,n){e.container=n,e.editor=t,document.addEventListener("selectionchange",e.onSelection),e.container.addEventListener("focus",e.onFocus),e.container.addEventListener("blur",e.onBlur)},this.onFocus=function(){e.focused=!0,e.onChange()},this.onBlur=function(){e.focused=!1,e.onChange()},this.destroy=function(){document.removeEventListener("selectionchange",e.onSelection)},this.onSelection=function(t){var n;(null==(n=t.target)?void 0:n.activeElement)===e.container&&e.getRange()},this.observe=function(t){e.observers=e.observers?e.observers.concat(t):[t]},this.unobserve=function(t){e.observers=e.observers?e.observers.filter((function(e){return e!==t})):[]},this.getLeaf=function(t,n){if(e[n]&&e[n].node===t)return e[n].value;for(var r,o=t;!r&&o!==e.container&&o;)(r=e.editor.ID_TO_NODE.get(o.id))||(o=o.parentElement);if(!r)return[void 0,void 0,void 0,void 0];var a=[r,te(r),q(r),o];return e[n]={value:a,node:t},a},this.getNodeBoundingRect=function(t){return{nodeHtml:e.container.querySelector("#"+t.get("id"))}},this.getRange=function(){var t=window.getSelection(),n=t.focusNode,r=t.anchorOffset,o=t.focusOffset,i=t.isCollapsed,s=t.rangeCount;if(null!==n){var l=e.getLeaf(t.anchorNode,"anchorNode"),f=l[0],c=l[1],d=l[2],u=l[3],p=e.getLeaf(n,"focusNode"),g=p[0],h=p[1],v=p[2],x=p[3];if(f){var m=d.join("")===v.join(""),y=m?r<o:d.join()<v.join(),b=s>=1?null==t?void 0:t.getRangeAt(0):void 0;e.start=a({},e.getNodeBoundingRect(y?c:h),{node:y?c:h,leafId:(y?f:g).get("id"),leafIndex:y?d[d.length-1]:v[v.length-1],nodeIndex:y?d[d.length-2]:v[v.length-2],path:y?d:v,leafHtml:y?u:x,offset:y?r:o,leaf:y?f:g}),e.end=i||null===h?e.start:a({},e.getNodeBoundingRect(y?h:c),{node:y?h:c,leafId:(y?g:f).get("id"),leafIndex:y?v[v.length-1]:d[d.length-1],nodeIndex:y?v[v.length-2]:d[d.length-2],path:y?v:d,leafHtml:y?x:u,offset:y?o:r,leaf:y?g:f}),e.selectedText=b?b.toString():"",e.arePathsEquals=m,e.length=e.selectedText.length,e.range=b,e.selection=t,e.edges={startLeaf:0===e.start.offset,startNode:0===e.start.offset&&0===F(e.start.leaf),endLeaf:e.end.offset===X(e.end.leaf),endNode:e.end.offset===X(e.end.leaf)&&F(e.start.leaf)===oe(e.end.leaf)-1},e.type=i?"collapsed":m?"singlenode":e.start.node===e.end.node?"multileaves":"multinodes",e.onChange()}}},this.onChange=function(){e.observers.forEach((function(t){return t(e)}))},this.setPosition=function(t,n){for(var r,o,i,s,l=n.offset,f=n.delta,c=n.end,d=e.container.querySelector("#"+t);d&&3!==d.nodeType&&null!=(u=d)&&u.firstChild;){var u;d=d.firstChild}var p=l||(null==(r=e.start)?void 0:r.offset)+f;e.range||e.selection||(e.range=document.createRange(),e.selection=window.getSelection()),e.range.setStart(d,p),c?e.range.setEnd(d,c):e.range.collapse(!0),null==(o=e.selection)||o.removeAllRanges(),null==(i=e.selection)||i.addRange(e.range),e.start=a({},e.start,{leafHtml:e.container.querySelector("#"+t),offset:l||(null==(s=e.start)?void 0:s.offset)+f})},this.observers=[]},exports.LeavesHarvest=K,exports.YNode=d,exports.applyMarksFromParent=x,exports.areLeafsMergeable=N,exports.copyNode=_,exports.createLeaf=f,exports.createNode=c,exports.createWSProvider=function(e){return new Promise((function(n){var r=new t.Doc;console.log("production");var a=new o.WebsocketProvider("wss://edytor-production.up.railway.app",e||"edytor",r,{connect:!0});a.on("status",(function(e){if("connected"===e.status)return n(a)}))}))},exports.createWebRtcProvider=function(e,t,n){},exports.deleteLeafText=U,exports.deleteNode=L,exports.deleteText=v,exports.formatAtEqualPath=m,exports.formatText=y,exports.getChildren=g,exports.getContainerAtPath=function(e,t){return 1===t.length?e.children:H(e,t.slice(1,t.length)).get("children")},exports.getContent=p,exports.getId=function(e){return e.get("id")},exports.getIndex=F,exports.getLeafAtPath=function(e,t){for(var n=t[0],r=t.slice(1),o=e.children.get(n),a=0;a<r.length-1;){var i=r[a];a++,o=o.get("children").get(i)}return o&&o.get("content").get(r.slice().reverse()[0])},exports.getNode=R,exports.getNodeAtPath=H,exports.getNodeChildren=A,exports.getNodeContainer=S,exports.getNodeContent=P,exports.getPath=q,exports.hasChildren=C,exports.insertText=b,exports.insertTextInLeaf=V,exports.isLeafEmpty=Q,exports.isNodeContentEmpty=J,exports.isNodeEmpty=B,exports.leafData=Y,exports.leafLength=X,exports.leafNode=te,exports.leafNodeChildren=ae,exports.leafNodeChildrenLength=ie,exports.leafNodeContent=re,exports.leafNodeContentLength=oe,exports.leafNodeContentStringLength=function(e){return re(e).toArray().reduce((function(e,t){return e+X(t)}),0)},exports.leafNodeId=ne,exports.leafString=G,exports.leafText=z,exports.mergeContentWithNextLeaf=I,exports.mergeContentWithPrevLeaf=D,exports.mergeLeafs=w,exports.moveNode=E,exports.nanoid=M,exports.nestNode=T,exports.onBeforeInput=function(e,t){var n=e[0],r=e[1],o=e[2];!function(e){e.preventDefault(),e.stopPropagation()}(t);var a=o.selection,i=a.start,s=a.length;switch(t.inputType){case"insertFromPaste":case"insertLineBreak":case"insertText":var l="insertLineBreak"===t.inputType?"\n":"insertFromPaste"===t.inputType?se(t):t.data;b(o,{text:l});break;case"deleteContentBackward":v(o,{mode:"backward"});break;case"deleteByDrag":case"deleteByCut":case"deleteContentForward":v(o,{mode:"forward"});break;case"insertParagraph":O(o);break;case"insertFromDrop":setTimeout((function(){var e=se(t);e&&b(o,{text:e})}),50);break;case"deleteSoftLineBackward":case"deleteWordForward":case"insertFromYank":case"formatSetBlockTextDirection":case"formatSetInlineTextDirection":case"deleteWordBackward":case"insertCompositionText":break;case"formatItalic":case"formatBold":break;case"insertReplacementText":n().doc.transact((function(){Z(i.leaf,i.offset,s,se(t))}))}r&&r(o)},exports.onDragOver=function(e,t){var n,r;t.preventDefault(),(null==(n=t.dataTransfer)?void 0:n.files.length)>0&&(t.preventDefault(),console.log(null==(r=t.dataTransfer)?void 0:r.files))},exports.onDrop=function(e,t){var n,r;(null==(n=t.dataTransfer)?void 0:n.files.length)>0&&(t.preventDefault(),console.log(null==(r=t.dataTransfer)?void 0:r.files))},exports.onKeyDown=function(e,t){if("Tab"===t.key&&(t.preventDefault(),e.allowNesting&&T(e)),t.metaKey){if("z"===t.key&&t.metaKey)return t.preventDefault(),e.undoManager.undo();if("Z"===t.key&&t.metaKey&&t.shiftKey)return t.preventDefault(),e.undoManager.redo();for(var n=0;n<e.hotkeys.length;n++){var o=e.hotkeys[n],a=o.operation,i=o.mark;if(r(o.keys,t)){if(t.preventDefault(),t.stopPropagation(),"function"==typeof a)return a(e);switch(a){case"formatText":return y(e,i)}break}}}},exports.removeEmptyText=function(e){var t,n,r=null==e||null==(t=e.parent)?void 0:t.parent,o=function(e,t){return null==e?void 0:e.toArray().indexOf(t)};for(null==(n=r)||n.delete(o(r,e.parent));r&&0===r.length;){var a=r.parent,i=a.parent;if(i){var s=o(i,a);-1!==s&&i.delete(s),r=i}else r=void 0}},exports.removeIfEmpty=ee,exports.replaceLeafText=Z,exports.setLeafData=function(e,t){e.has("data")?Object.keys(t).forEach((function(n){Y(e).set(n,t[n])})):e.set("data",new Map(Object.entries(t)))},exports.setLeafText=$,exports.splitLeaf=k,exports.splitNode=O,exports.toString=function(e){for(var t="",n=e.children.toArray(),r=0;r<n.length;r++)t+=G(n[r]);return t},exports.traverse=W;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("yjs"),n=require("nanoid"),o=(e=require("is-hotkey"))&&"object"==typeof e&&"default"in e?e.default:e,r=require("y-websocket");function a(){return(a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}function i(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function s(e,t){if(null==e)return{};var n,o,r={},a=Object.keys(e);for(o=0;o<a.length;o++)t.indexOf(n=a[o])>=0||(r[n]=e[n]);return r}var f=["id","text","data"],l=function(e){var n=new t.Map;if(n.set("id",(null==e?void 0:e.id)||R()),n.set("text",new t.Text((null==e?void 0:e.text)||"")),e){var o=e.text,r=e.data,a=s(e,f);n.set("text",new t.Text(o||"")),r&&n.set("data",new t.Map(Object.entries(r))),a&&Object.keys(a).forEach((function(e){n.set(e,a[e])}))}return n},d=function(e,n){var o=new t.Map;return o.set("id",(null==n?void 0:n.id)||R()),o.set("type",e),null!=n&&n.data&&o.set("data",new t.Map(Object.entries(n.data))),o.set("content",(null==n?void 0:n.content)instanceof t.Array?n.content:t.Array.from((null==n?void 0:n.content)||[l()])),o.set("children",(null==n?void 0:n.children)instanceof t.Array?n.children:t.Array.from((null==n?void 0:n.children)||[])),o},c=function(e){function t(){return e.apply(this,arguments)||this}return i(t,e),t}(t.Map),u=["type","content","children"],p=function e(t){var n=t.type,o=t.content,r=void 0===o?[]:o,i=t.children,f=void 0===i?[]:i,c=s(t,u);return d(n,a({},c,{children:f.map(e),content:r.map(l)}))},g=function(e){function t(){return e.apply(this,arguments)||this}return i(t,e),t}(t.Doc),h=function(e,t){var n=t.mode,o=t.selection||e.selection,r=o.start,a=o.end,i=o.length,s=o.edges,f=o.setPosition;switch(o.type){case"collapsed":if("backward"===n&&s.startNode){if(s.startDocument)return;if(r.nodeIndex===r.node.parent.length-1&&r.path.length>2&&(0!==r.nodeIndex||1===r.node.parent.length)){var d=_(r.node),c=r.node.parent.parent,u=F(c);return r.node.parent.delete(r.nodeIndex),c.parent.insert(u+1,[d]),f(r.leafId,{offset:0})}return e.doc.transact((function(){var t=D(e),n=t[0],o=t[1];setTimeout((function(){f(n.get("id"),{offset:o})}))}))}if("backward"===n&&s.startLeaf){var p=oe(r.leaf).get(r.leafIndex-1);return Q(p,z(p)-1,i||1),f(p.get("id"),{offset:z(p)})}if("forward"===n&&s.endNode)return e.doc.transact((function(){j(e),setTimeout((function(){f(r.leafId,{offset:r.offset})}))}));if("forward"===n&&s.endLeaf){var g=oe(r.leaf).get(r.leafIndex+1);return Q(g,0,i||1)}Q(r.leaf,r.offset+("backward"===n?-i||-1:i),i||1),f(r.leaf.get("id"),{offset:r.offset+("backward"===n?-i||-1:i)});break;case"singlenode":Q(r.leaf,r.offset,i,!0),B(r.node)&&oe(r.leaf).insert(0,[l()]),f(r.leafId,{offset:r.offset});break;case"multileaves":case"multinodes":var h=r.path.join(","),v=a.path.join(",");e.doc.transact((function(){var t=new K,n=t.reap,o=t.burn;return W(e,(function(e,t){if(t){var o=q(e),i=z(e);o.join(",")===h?(Q(e,r.offset,i),n(e,!1)):o>r.path&&o<a.path?(Q(e,0,i),n(e,!0)):o.join(",")===v&&(Q(e,0,a.offset),n(e,a.offset===i))}}),{start:r.path[0],end:a.path[0]+1}),o(e)})),f(r.leaf.get("id"),{offset:r.offset})}},v=function(e,t){Array.from(e.keys(),(function(n){"text"!==n&&"id"!==n&&"data"!==n&&t.forEach((function(t){t.set(n,e.get(n))}))}))},m=function(e){var t=e.format,n=e.value,o=e.start,r=e.end,i=r.offset-o.offset,s=o.leaf,f=X(s).toString(),d=F(s),c=s.has(t);if(c&&z(s)===i)return s.delete(t),s;var u,p=f.substring(r.offset,z(s));if(0==p.length&&z(s)===r.offset-o.offset)return s.set(t,n),s;Q(s,o.offset,z(s));var g=l(a({},s.toJSON(),((u={id:void 0})[t]=n,u.text=f.substring(o.offset,r.offset),u))),h=[g];return p.length>0&&h.push(l(a({},s.toJSON(),{id:void 0,text:p}))),c&&g.delete(t),h.length&&oe(s).insert(d+1,h),g},x=function(e,t){var n=Object.entries(t)[0],o=n[0],r=n[1];console.log(o);var a=e.selection,i=a.start,s=a.end,f=a.type,d=a.length,c=a.setPosition,u=a.selectedText;return e.doc.transact((function(){switch(f){case"collapsed":var t=i.leaf.has(o)&&i.leaf.get(o)===r;if(G(i.leaf))t?i.leaf.delete(o):i.leaf.set(o,r);else{var n;N(e);var a=l(((n={text:""})[o]=r,n));v(i.leaf,[a]),t&&a.delete(o),oe(i.leaf).insert(i.leafIndex+1,[a]),G(i.leaf)&&oe(i.leaf).delete(i.leafIndex),setTimeout((function(){c(a.get("id"),{offset:0}),console.log(oe(i.leaf).toJSON())}))}k(oe(i.leaf));break;case"singlenode":var p=m({format:o,value:r,start:i,end:s,length:d});if(k(oe(i.leaf)),p._item.deleted){var g=p.parent.get(i.leafIndex-1),h=X(g).toJSON().indexOf(u);setTimeout((function(){c(g.get("id"),{offset:h,end:h+u.length})}))}else c(i.leaf.get("id"),{offset:i.offset}),setTimeout((function(){c(p.get("id"),{offset:0,end:z(p)})}));break;case"multileaves":case"multinodes":var x=i.path.join(","),y=s.path.join(","),b=!1,w=!1;W(e,(function(e,t){if(t){var n=q(e),a=n.join(",")===x,f=n.join(",")===q(s.leaf).join(",");console.log({isEnd:f},y,q(s.leaf).join(","),n.join(",")),a&&(b=!0);var l=a?i.offset:0,d=f?s.offset:z(e);b&&!w&&m({format:o,start:{leaf:e,offset:l},end:{offset:d},value:r}),console.log({ended:w}),f&&(w=!0),k(oe(e))}}),{start:i.path[0],end:s.path[0]+1})}})),0},y=function(e,t){var n=t.text;if(n&&null!==n&&n.length){var o=e.selection,r=o.start,a=o.end,i=o.type,s=o.length,f=o.setPosition;if("notInDoc"===i)return console.error("Path is not in document space");switch(i){case"collapsed":V(r.leaf,r.offset,n),f(r.leaf.get("id"),{offset:r.offset+n.length});break;case"singlenode":Z(r.leaf,r.offset,s,n),f(r.leaf.get("id"),{offset:r.offset+n.length});break;case"multileaves":case"multinodes":var l=r.path.join(","),d=a.path.join(",");e.doc.transact((function(){var t=new K,o=t.reap,i=t.burn;W(e,(function(e,t){if(t){var i=q(e);i.join(",")===l?(Z(e,r.offset,z(e),n),o(e)):i>r.path&&i<a.path?(Q(e,0,z(e)),o(e)):i.join(",")===d&&(Q(e,0,a.offset),o(e))}}),{start:r.path[0],end:a.path[0]+1}),i(e)})),f(r.leaf.get("id"),{offset:r.offset+n.length})}}},b=function(e){var t=e.map((function(e){return Array.from(e.keys())})).flat();return e.every((function(e){return t.every((function(t){return e.has(t)}))}))},k=function(e){var t=e.get(0),n=[];e.forEach((function(o,r){var a=e.get(r+1);if(a)if(b([t,a])){var i=t.get("text");t.get("text").insert(i.length,a.get("text").toString()),n.push(a)}else t=a})),n.forEach((function(t){e.delete(F(t))}))},N=function(e){var t=e.selection.start,n=t.leaf,o=t.leafIndex,r=t.offset,i=U(n),s=i.substring(r,i.length);r!==i.length&&(Q(n,r,s.length),oe(n).insert(o+1,[l(a({},n.toJSON(),{text:s,id:void 0}))]))},w=function(e){var t=e.selection,n=t.start,o=t.type,r=t.setPosition,i=t.edges,s=n.leaf,f=oe(n.leaf),c=te(n.leaf),u=F(n.leaf),p=F(c),g=function(){var t=f.toArray().filter((function(e,t){return t>u})),o=U(n.leaf).substring(null==n?void 0:n.offset,z(n.leaf));Q(n.leaf,null==n?void 0:n.offset,o.length,!1);var i=P(c)?A(c):c.parent,g=l(a({},s.toJSON(),{id:void 0,text:o}));i.insert(P(c)?0:p+1,[d(e.defaultBlock,{children:[],content:[g].concat(t.map((function(e){return l(e.toJSON())})))})]),r(g.get("id"),{offset:0}),f.delete(u+1,re(n.leaf)-u-1)},v=!(i.startNode&&i.endNode||"multinodes"===o);if((i.endNode||i.startNode)&&"collapsed"===o){var m=d(e.defaultBlock);return c.parent.insert(p+(i.endNode?1:0),[m]),setTimeout((function(){r(m.get("content").get(0).get("id"),{offset:0})}))}switch(o){case"collapsed":v&&g();break;case"singlenode":h(e,{mode:"backward"}),v&&g(),!v&&r(n.leaf.get("id"),{offset:n.offset});break;case"multileaves":case"multinodes":h(e,{mode:"backward"}),v&&g(),!v&&r(n.leaf.get("id"),{offset:n.offset})}},T=function(e){var t=e.selection,n=t.start,o=t.type,r=t.end,a=t.setPosition,i=M(n.leaf),s=_(i),f=q(i),l=f.slice().reverse(),d=l[0],c=l.slice(1),u=H(e,[].concat(c,[d-1])),p=L(i);switch(o){case"singlenode":case"collapsed":if(!u)return;var g=n.leaf.get("id"),h=u.get("children");p.delete(d),h.insert(h.length,[s]),a(g,{offset:n.offset});break;case"multileaves":case"multinodes":var v=0,m=[],x=n.leaf.get("id"),y=n.path.slice(0,n.path.length-1).join(""),b=r.path.slice(0,n.path.length-1).join("");if(W(e,(function(e,t){if(!t){var n=q(e).join("");n.length===f.length&&n<=b&&n>=y&&(v++,m.push(_(e)))}}),{start:n.path[0],end:r.path[0]+1}),!u)return;var k=u.get("children");p.delete(d,v),k.insert(k.length,m),a(x,{offset:n.offset})}},E=function(e){var t=e.from,n=e.to,o=Array.isArray(t.at)?t.at:[t.at],r=t.container.get(o[0]),a=o.map((function(e){var n=t.container.get(e);return _(n)}));return n.container.insert(n.at,a),t.container.delete(F(r),o.length),a[0].get("content").get(0).get("id")},I=["type"],D=function(e){var t,n=e.selection.start,o=!1;if(W(e,(function(e,r){r&&(e===n.leaf?o=!0:o||(t=e))})),t){var r=z(t);oe(t).insert(re(t),oe(n.leaf).toArray().map((function(e){return l(e.toJSON())}))),k(oe(t));var a=n.node.get("children").toArray().map(_);return a.length&&n.node.parent.insert(n.nodeIndex,a),n.node.parent.delete(n.nodeIndex+a.length),[t,r]}},j=function(e){var t,n=e.selection.start,o=!1;if(W(e,(function(e,r){r&&(e===n.leaf?o=!0:o&&(t=e,o=!1))})),t){oe(n.leaf).insert(re(n.leaf),oe(t).toArray().map((function(e){return l(e.toJSON())}))),k(oe(n.leaf));var r=M(t),a=F(r),i=r.parent,s=r.get("children").toArray();return s.length>0&&i.insert(a,s.map(_)),i.delete(a+s.length),t}},O=function(e,t){if(C(e))e.parent.delete(F(e));else if(B(e)){var n=A(e).toJSON(),o=F(e);e.parent.delete(o),e.parent.insert(o,n.map((function(e){var t=e.type,n=s(e,I);return d(t,n)})))}e.parent===(e.doc.getArray("children")&&0===e.doc.getArray("children").length)&&e.parent.insert(0,[d(t,{content:[l()]})])},L=function(e){return e.parent},A=function(e){return e.get("children")},S=function(e){return e.get("content")},P=function(e){return A(e).length>0},C=function(e){return B(e)&&!P(e)},B=function(e){return 0===S(e).length||0===S(e).toArray().map(U).join("").length},_=function(e){var t=e.toJSON();return d(t.type,a({},t,{children:t.children.map(p),content:t.content.map(l)}))},J=function e(t){var n="";return S(t).forEach((function(e){n+=U(e)})),A(t).forEach((function(t){n+=e(t)})),n},R=function(){return"y-"+n.customAlphabet("346789ABCDEFGHJKLMNPQRTUV-WXYabcdefghijkmnpqrtwxyz",20)()},M=function(e){var t;return null==e||null==(t=e.parent)?void 0:t.parent},F=function(e){for(var t=0,n=!1,o=e.parent._start;null!==o&&!n;){if(o.countable&&!o.deleted)for(var r=o.content.getContent(),a=0;a<r.length;a++){if(r[a]===e){n=!0;break}t++}o=o.right}return t},q=function(e){for(var t=[],n=e;n;)t.push(F(n)),n=M(n);return t.reverse()},H=function(e,t){for(var n=t[0],o=t.slice(1),r=e.children.get(n),a=0;a<o.length;a++){var i=o[a];r=r.get?r.get("children").get(i):void 0}return r},W=function(e,t,n){for(var o=function e(n,o){if(n.has("text"))t(n,!0,o);else{var r=S(n).toArray().concat(A(n).toArray());t(n,!1,o);for(var a=0;a<r.length;a++)e(r[a],[].concat(o.slice(0,o.length-1),[0,a]))}},r=e.children.toArray().slice((null==n?void 0:n.start)||0,(null==n?void 0:n.end)||e.children.length),a=0;a<r.length;a++)o(r[a],[a+((null==n?void 0:n.start)||0)])},K=function(){var e=this;this.reap=function(t,n){if(void 0===n&&(n=!1),G(t)){var o=ne(t);e.leaves[o]||(e.leaves[o]={shouldDeleteNode:n,content:oe(t),node:te(t),indexes:[]}),e.leaves[o].indexes.push(F(t))}},this.burn=function(t){Object.values(e.leaves).forEach((function(e,n){var o=e.shouldDeleteNode,r=e.content,a=e.node,i=e.indexes;if(r.delete(i[0],i.length),0!==r.length||o){if(o)return O(a,null==t?void 0:t.defaultBlock)}else r.insert(0,[createLeaf()])}))},this.leaves={}},Y=function(e){return e.get("data")},X=function(e){return e.get("text")},z=function(e){return X(e).length},U=function(e){return X(e).toString()},G=function(e){return void 0===X(e)||0===z(e)},Q=function(e,t,n,o){X(e).delete(t,n),o&&ee(e)},V=function(e,t,n){X(e).insert(t,n)},Z=function(e,t,n,o){var r=U(e).split("");return r.splice.apply(r,[t,n].concat(o.split(""))),$(e,r.join(""))},$=function(e,t){var n=X(e);n.delete(0,n.length),n.insert(0,t)},ee=function(e){G(e)&&(console.log("isEmpty",oe(e).toJSON()),oe(e).delete(F(e)))},te=function(e){return e.parent.parent},ne=function(e){return te(e).get("id")},oe=function(e){return e.parent},re=function(e){return oe(e).length},ae=function(e){return te(e).get("children")},ie=function(e){return e.dataTransfer.getData("text/plain")};exports.DocFromJson=function(e,n){var o=(n||new t.Doc).getArray("children");return o.insert(0,e.map(p)),o.doc},exports.Dropper=function(){var e=this;this.init=function(t,n){e.editor=t,e.doc=t.doc,e.container=n,e.editorId=t.editorId,e.selection=t.selection,e.ID_TO_NODE=t.ID_TO_NODE,e.allowNesting=t.allowNesting},this.startDrag=function(t,n){var o;if(e.editor.dnd.active){e.node=t,document.getElementById("dndIndicator").style.opacity="1";var r=document.getElementById(t.get("id"));r.style.opacity="0.4",document.body.style.cursor="grabbing",e.from={container:t.parent,at:F(t)},e.startPath=q(t),null==(o=n.dataTransfer)||o.setDragImage(r,n.offsetX,n.offsetY),document.addEventListener("mousemove",e.onDrag),document.addEventListener("mouseup",e.dragEnd)}},this.dragEnd=function(){var t=document.getElementById(e.node.get("id"));t&&(t.style.opacity="1"),document.body.style.cursor="auto",document.removeEventListener("mousemove",e.onDrag),document.removeEventListener("mouseup",e.dragEnd);var n=E({from:e.from,to:e.to});document.getElementById("dndIndicator").style.opacity="0",setTimeout((function(){console.log(n),e.selection.setPosition(n,{offset:0})}))},this.getHoveredNode=function(t){for(var n,o=t,r=0;!n&&(null==(a=o)?void 0:a.id)!==e.editorId&&o&&r<100;){var a;if(o.hasAttribute("data-edytor-block")){n=e.ID_TO_NODE.get(o.id);break}o=o.parentElement,r++}return n?{hoveredElement:o,hoveredNode:n}:{}},this.onDrag=function(t){if(e.editor.dnd.active){var n=e.getHoveredNode(t.target),o=n.hoveredElement,r=n.hoveredNode,a=document.getElementById("dndIndicator");if(r&&o&&a&&r!==e.node){var i=o.getBoundingClientRect(),s=t.y<i.top+i.height/2,f=i,l=e.allowNesting&&!s&&t.x>f.left+f.width/5,d=s?f.top:f.top+f.height,c=l?30:0,u=q(r),p=u.slice().reverse(),g=p[0],h=p.slice(1);e.startPath.join("")!==h.join("")&&(a.style.width=f.width-c+"px",a.style.top=d+window.pageYOffset+"px",a.style.left=f.left+c+"px",-1===(g+=s?0:1)&&(g=0),e.to={container:l?r.get("children"):1===u.length?e.editor.children:r.parent,at:l?0:g})}}}},exports.EdytorDoc=g,exports.EdytorSelection=function(){var e=this;this.init=function(t,n){e.container=n,e.editor=t,document.addEventListener("selectionchange",e.onSelection),e.container.addEventListener("focus",e.onFocus),e.container.addEventListener("blur",e.onBlur)},this.onFocus=function(){e.focused=!0,e.onChange()},this.onBlur=function(){e.focused=!1,e.onChange()},this.destroy=function(){document.removeEventListener("selectionchange",e.onSelection)},this.onSelection=function(t){var n;(null==(n=t.target)?void 0:n.activeElement)===e.container&&e.getRange()},this.observe=function(t){e.observers=e.observers?e.observers.concat(t):[t]},this.unobserve=function(t){e.observers=e.observers?e.observers.filter((function(e){return e!==t})):[]},this.getLeaf=function(t,n){if(e[n]&&e[n].node===t)return e[n].value;for(var o,r=t;!o&&r!==e.container&&r;)(o=e.editor.ID_TO_NODE.get(r.id))||(r=r.parentElement);if(!o)return[void 0,void 0,void 0,void 0];var a=[o,te(o),q(o),r];return e[n]={value:a,node:t},a},this.getNodeBoundingRect=function(t){return{nodeHtml:e.container.querySelector("#"+t.get("id"))}},this.getRange=function(){var t=window.getSelection(),n=t.focusNode,o=t.anchorOffset,r=t.focusOffset,i=t.isCollapsed,s=t.rangeCount;if(null!==n){var f=e.getLeaf(t.anchorNode,"anchorNode"),l=f[0],d=f[1],c=f[2],u=f[3],p=e.getLeaf(n,"focusNode"),g=p[0],h=p[1],v=p[2],m=p[3];if(l){var x=c.join("")===v.join(""),y=x?o<r:c.join()<v.join(),b=s>=1?null==t?void 0:t.getRangeAt(0):void 0;e.start=a({},e.getNodeBoundingRect(y?d:h),{node:y?d:h,leafId:(y?l:g).get("id"),leafIndex:y?c[c.length-1]:v[v.length-1],nodeIndex:y?c[c.length-2]:v[v.length-2],path:y?c:v,leafHtml:y?u:m,offset:y?o:r,leaf:y?l:g}),e.end=i||null===h?e.start:a({},e.getNodeBoundingRect(y?h:d),{node:y?h:d,leafId:(y?g:l).get("id"),leafIndex:y?v[v.length-1]:c[c.length-1],nodeIndex:y?v[v.length-2]:c[c.length-2],path:y?v:c,leafHtml:y?m:u,offset:y?r:o,leaf:y?g:l}),e.selectedText=b?b.toString():"",e.arePathsEquals=x,e.length=e.selectedText.length,e.range=b,e.selection=t;var k=0===e.start.offset&&0===F(e.start.leaf),N=e.end.offset===z(e.end.leaf)&&F(e.start.leaf)===re(e.end.leaf)-1;e.edges={startLeaf:0===e.start.offset,endLeaf:e.end.offset===z(e.end.leaf),startNode:k,endNode:N,startDocument:k&&"00"===e.start.path.join(""),endDocument:!1},e.type=i?"collapsed":x?"singlenode":e.start.node===e.end.node?"multileaves":"multinodes",e.onChange()}}},this.onChange=function(){e.observers.forEach((function(t){return t(e)}))},this.setPosition=function(t,n){var o,r,i,s,f=n.offset,l=n.delta,d=n.end,c=e.container.querySelector("#"+t);for(console.log({node:c});c&&3!==c.nodeType&&null!=(u=c)&&u.firstChild;){var u;c=c.firstChild}var p=f||(null==(o=e.start)?void 0:o.offset)+l;e.range||e.selection||(e.range=document.createRange(),e.selection=window.getSelection()),e.range.setStart(c,p),d?e.range.setEnd(c,d):e.range.collapse(!0),null==(r=e.selection)||r.removeAllRanges(),null==(i=e.selection)||i.addRange(e.range),e.start=a({},e.start,{leafHtml:e.container.querySelector("#"+t),offset:f||(null==(s=e.start)?void 0:s.offset)+l})},this.observers=[]},exports.LeavesHarvest=K,exports.YNode=c,exports.applyMarksFromParent=v,exports.areLeafsMergeable=b,exports.copyNode=_,exports.createLeaf=l,exports.createNode=d,exports.createWSProvider=function(e){return new Promise((function(n){var o=new t.Doc;console.log("production");var a=new r.WebsocketProvider("wss://edytor-production.up.railway.app",e||"edytor",o,{connect:!0});a.on("status",(function(e){if("connected"===e.status)return n(a)}))}))},exports.defaultHotkeys=[{operation:"formatText",keys:"mod+b",mark:{bold:!0}},{operation:"formatText",keys:"mod+i",mark:{italic:!0}},{operation:"formatText",keys:"mod+u",mark:{underline:!0}},{operation:"formatText",keys:"mod+shift+c",mark:{code:!0}},{operation:"formatText",keys:"mod+shift+x",mark:{strikethrough:!0}},{operation:"formatText",keys:"mod+shift+h",mark:{highlight:!0}}],exports.deleteLeafText=Q,exports.deleteNode=O,exports.deleteText=h,exports.formatAtEqualPath=m,exports.formatText=x,exports.getChildren=p,exports.getContainerAtPath=function(e,t){return 1===t.length?e.children:H(e,t.slice(1,t.length)).get("children")},exports.getId=function(e){return e.get("id")},exports.getIndex=F,exports.getLeafAtPath=function(e,t){for(var n=t[0],o=t.slice(1),r=e.children.get(n),a=0;a<o.length-1;){var i=o[a];a++,r=r.get("children").get(i)}return r&&r.get("content").get(o.slice().reverse()[0])},exports.getNode=M,exports.getNodeAtPath=H,exports.getNodeChildren=A,exports.getNodeContainer=L,exports.getNodeContent=S,exports.getPath=q,exports.hasChildren=P,exports.insertText=y,exports.insertTextInLeaf=V,exports.isLeafEmpty=G,exports.isNodeContentEmpty=B,exports.isNodeEmpty=C,exports.leafData=Y,exports.leafLength=z,exports.leafNode=te,exports.leafNodeChildren=ae,exports.leafNodeChildrenLength=function(e){return ae(e).length},exports.leafNodeContent=oe,exports.leafNodeContentLength=re,exports.leafNodeContentStringLength=function(e){return oe(e).toArray().reduce((function(e,t){return e+z(t)}),0)},exports.leafNodeId=ne,exports.leafString=U,exports.leafText=X,exports.mergeContentWithNextLeaf=j,exports.mergeContentWithPrevLeaf=D,exports.mergeLeafs=k,exports.moveNode=E,exports.nanoid=R,exports.nestNode=T,exports.nodeString=J,exports.onBeforeInput=function(e,t){var n,o=e[1],r=e[2],a=r.selection,i=a.start,s=a.length,f=a.setPosition,l=null==(n=t.target)?void 0:n.tagName;if("TEXTAREA"!==l&&"INPUT"!==l){switch(function(e){e.preventDefault(),e.stopPropagation()}(t),t.inputType){case"insertFromPaste":case"insertLineBreak":case"insertText":var d="insertLineBreak"===t.inputType?"\n":"insertFromPaste"===t.inputType?ie(t):t.data;y(r,{text:d});break;case"deleteContentBackward":h(r,{mode:"backward"});break;case"deleteByDrag":case"deleteByCut":case"deleteContentForward":h(r,{mode:"forward"});break;case"insertParagraph":w(r);break;case"insertFromDrop":setTimeout((function(){var e=ie(t);e&&y(r,{text:e})}),50);break;case"deleteSoftLineBackward":case"deleteWordForward":case"insertFromYank":case"formatSetBlockTextDirection":case"formatSetInlineTextDirection":case"deleteWordBackward":case"insertCompositionText":break;case"formatItalic":case"formatBold":break;case"insertReplacementText":Z(i.leaf,i.offset,s,ie(t)),f(i.leafId,{offset:i.offset})}o&&o(r)}},exports.onDragOver=function(e,t){var n,o;t.preventDefault(),(null==(n=t.dataTransfer)?void 0:n.files.length)>0&&(t.preventDefault(),console.log(null==(o=t.dataTransfer)?void 0:o.files))},exports.onDrop=function(e,t){var n,o;(null==(n=t.dataTransfer)?void 0:n.files.length)>0&&(t.preventDefault(),console.log(null==(o=t.dataTransfer)?void 0:o.files))},exports.onKeyDown=function(e,t){if("Tab"===t.key&&(t.preventDefault(),e.allowNesting&&T(e)),t.metaKey){if("z"===t.key&&t.metaKey)return t.preventDefault(),e.undoManager.undo();if("Z"===t.key&&t.metaKey&&t.shiftKey)return t.preventDefault(),e.undoManager.redo();if(e.hotkeys)for(var n=0;n<e.hotkeys.length;n++){var r=e.hotkeys[n],a=r.operation,i=r.mark;if(o(r.keys,t)){if(t.preventDefault(),t.stopPropagation(),"function"==typeof a)return a(e);switch(a){case"formatText":return x(e,i)}break}}}},exports.removeEmptyText=function(e){var t,n,o=null==e||null==(t=e.parent)?void 0:t.parent,r=function(e,t){return null==e?void 0:e.toArray().indexOf(t)};for(null==(n=o)||n.delete(r(o,e.parent));o&&0===o.length;){var a=o.parent,i=a.parent;if(i){var s=r(i,a);-1!==s&&i.delete(s),o=i}else o=void 0}},exports.removeIfEmpty=ee,exports.replaceLeafText=Z,exports.setLeafData=function(e,t){e.has("data")?Object.keys(t).forEach((function(n){Y(e).set(n,t[n])})):e.set("data",new Map(Object.entries(t)))},exports.setLeafText=$,exports.splitLeaf=N,exports.splitNode=w,exports.toString=function(e){for(var t="",n=e.children.toArray(),o=0;o<n.length;o++)t+=J(n[o]);return t},exports.traverse=W;
2
2
  //# sourceMappingURL=edytor.cjs.production.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"edytor.cjs.production.min.js","sources":["../src/utils/yClasses/yLeaf.ts","../src/utils/yClasses/yNode.ts","../src/utils/yClasses/EdytorDoc.ts","../src/operations/deleteText.ts","../src/operations/formatText.ts","../src/operations/insertText.ts","../src/operations/merge.ts","../src/operations/splitLeaf.ts","../src/operations/splitNode.ts","../src/operations/nestNode.ts","../src/operations/moveNode.ts","../src/utils/nodes.ts","../src/utils/common.ts","../src/utils/leaves.ts","../src/events/onBeforeInput.ts","../src/utils/dropper.ts","../src/utils/selection.ts","../src/yjs/wsProvider.ts","../src/yjs/webrtcProvider.ts","../src/events/onDrop.ts","../src/events/onKeyDown.ts","../src/operations/removeEmptyText.ts"],"sourcesContent":["import { nanoid } from \"..\";\nimport { Map, Text } from \"yjs\";\n\nexport type YLeafProps = {\n data?: any;\n text?: string;\n id?: string;\n};\n\nexport const createLeaf = (props?: YLeafProps) => {\n const leaf = new Map();\n leaf.set(\"id\", props?.id || nanoid());\n leaf.set(\"text\", new Text(props?.text || \"\"));\n if (props) {\n const { id, text, data, ...marks } = props;\n leaf.set(\"text\", new Text(text || \"\"));\n data && leaf.set(\"data\", new Map(Object.entries(data)));\n marks &&\n Object.keys(marks).forEach((mark) => {\n leaf.set(mark, marks[mark]);\n });\n }\n return leaf;\n};\n","import { nanoid } from \"..\";\nimport { Map, Array } from \"yjs\";\nimport { YArray, YMap } from \"yjs/dist/src/internals\";\nimport { YLeaf } from \"../../\";\nimport { createLeaf } from \"./yLeaf\";\n\nexport type YNodeProps = {\n data?: any;\n content?: YLeaf[] | YArray<YLeaf>;\n children?: YNode[] | YArray<YNode>;\n id?: string;\n};\n\nexport const createNode = (type: string, props?: YNodeProps): YMap<any> => {\n const node = new Map();\n node.set(\"id\", props?.id || nanoid());\n node.set(\"type\", type);\n if (props?.data) {\n node.set(\"data\", new Map(Object.entries(props.data)));\n }\n node.set(\"content\", props?.content instanceof Array ? props.content : Array.from(props?.content || [createLeaf()]));\n node.set(\"children\", props?.children instanceof Array ? props.children : Array.from(props?.children || []));\n return node;\n};\n\nexport class YNode extends Map<any> {}\n","import { Doc } from \"yjs\";\nimport { YLeaf, YNode } from \".\";\nimport { createLeaf } from \"./yLeaf\";\nimport { createNode } from \"./yNode\";\nexport interface jsonLeaf extends Record<string, any> {\n text: string;\n data?: object;\n}\nexport type jsonNode = {\n type: string;\n content?: jsonLeaf[];\n data?: object;\n children?: jsonNode[];\n};\n\nexport const getContent = (leaf: jsonLeaf): YLeaf => {\n return createLeaf(leaf);\n};\nexport const getChildren = ({ type, content = [], children = [], ...props }: jsonNode): YNode => {\n return createNode(type, { ...props, children: children.map(getChildren), content: content.map(getContent) });\n};\nexport class EdytorDoc extends Doc {\n constructor(value?: jsonNode[]) {\n super();\n if (value) {\n }\n }\n}\n\nexport const DocFromJson = (value: jsonNode[]) => {\n const doc = new Doc();\n const array = doc.getArray(\"children\");\n array.insert(0, value.map(getChildren));\n return doc;\n};\n","import { Editor, EdytorSelection } from \"../types\";\nimport {\n copyNode,\n deleteLeafText,\n getIndex,\n getNode,\n getPath,\n hasChildren,\n leafLength,\n leafNodeChildrenLength,\n leafNodeContent,\n leafNodeContentLength,\n leafNodeContentStringLength,\n leafString,\n LeavesHarvest,\n mergeContentWithNextLeaf,\n mergeContentWithPrevLeaf,\n createLeaf,\n traverse,\n YLeaf\n} from \"../utils\";\nimport { nestNode } from \"./nestNode\";\n\ntype deleteTextOpts = {\n mode: \"forward\" | \"backward\" | \"none\";\n selection?: EdytorSelection;\n};\nexport const deleteText = (editor: Editor, { mode, selection }: deleteTextOpts) => {\n const { start, end, type, length, edges, setPosition } = selection || editor.selection;\n\n switch (type) {\n case \"collapsed\": {\n if (mode === \"backward\" && edges.startNode) {\n console.log(start.nodeIndex, leafNodeChildrenLength(start.leaf), start.path.length);\n // unnest node if its the last of its parent and if he is nested\n if (start.nodeIndex === start.node.parent.length - 1 && start.path.length > 1 && start.nodeIndex !== 0) {\n console.log(start.leafId);\n const node = copyNode(start.node);\n start.node.parent.delete(start.nodeIndex);\n start.node.parent.parent.parent.insert(getIndex(start.node.parent.parent) + 1, [node]);\n setPosition(start.leafId, { offset: 0 });\n } else {\n // merge node with the prev one if it's not the last of its parent regardless of its nesting\n mergeContentWithPrevLeaf(editor);\n return setPosition(start.leafId, { offset: 0 });\n }\n }\n if (mode === \"backward\" && edges.startLeaf) {\n // delete content in the prev leaf because we are at its edge start, and escape current leaf\n const prevLeaf = leafNodeContent(start.leaf).get(start.leafIndex - 1);\n deleteLeafText(prevLeaf, leafLength(prevLeaf) - 1, length || 1);\n return setPosition(prevLeaf.get(\"id\"), { offset: leafLength(prevLeaf) });\n }\n\n if (mode === \"forward\" && edges.endNode) {\n // merge node with the next node because we are at edge end of it\n return mergeContentWithNextLeaf(editor);\n }\n if (mode === \"forward\" && edges.endLeaf) {\n // delete content in the next leaf because we are at its edge end\n const nextLeaf = leafNodeContent(start.leaf).get(start.leafIndex + 1);\n return deleteLeafText(nextLeaf, 0, length || 1);\n }\n\n deleteLeafText(start.leaf, start.offset + (mode === \"backward\" ? -length || -1 : length), length || 1);\n setPosition(start.leaf.get(\"id\"), { offset: start.offset + (mode === \"backward\" ? -length || -1 : length) });\n break;\n }\n case \"singlenode\": {\n deleteLeafText(start.leaf, start.offset, length, true);\n if (hasChildren(getNode(start.leaf))) {\n leafNodeContent(start.leaf).insert(0, [createLeaf()]);\n }\n setPosition(start.leaf.get(\"id\"), { offset: start.offset });\n break;\n }\n case \"multileaves\":\n case \"multinodes\":\n {\n const startPathString = start.path.join(\",\");\n const endPathString = end.path.join(\",\");\n editor.doc.transact(() => {\n const { reap, burn } = new LeavesHarvest();\n traverse(\n editor,\n (leaf, isText) => {\n if (isText) {\n const path = getPath(leaf);\n const l = leafLength(leaf);\n if (path.join(\",\") === startPathString) {\n deleteLeafText(leaf, start.offset, l);\n reap(leaf, false);\n } else if (path > start.path && path < end.path) {\n deleteLeafText(leaf, 0, l);\n reap(leaf, true);\n } else if (path.join(\",\") === endPathString) {\n deleteLeafText(leaf, 0, end.offset);\n reap(leaf, end.offset === l);\n }\n }\n },\n { start: start.path[0], end: end.path[0] + 1 }\n );\n return burn(editor);\n });\n }\n setPosition(start.leaf.get(\"id\"), { offset: start.offset });\n break;\n }\n};\n","import { YMap, YText } from \"yjs/dist/src/internals\";\nimport { Editor, Position, EdytorSelection } from \"../types\";\nimport { mergeLeafs, splitLeaf } from \".\";\nimport {\n deleteLeafText,\n getIndex,\n getPath,\n isLeafEmpty,\n leafLength,\n leafNodeContent,\n leafText,\n createLeaf,\n traverse,\n YLeaf\n} from \"../utils\";\n\nexport type formatTextOperation = {\n at?: Position;\n value: any;\n range?: EdytorSelection;\n format: string;\n yText?: YText;\n};\nexport type formatAtEqualPathOperation = {\n format: string;\n value: any;\n start: EdytorSelection[\"start\"];\n end: EdytorSelection[\"end\"];\n length: EdytorSelection[\"length\"];\n data?: object;\n};\n\nexport const applyMarksFromParent = (parent: YMap<any>, leafs: YMap<any>[]) => {\n Array.from(parent.keys(), (key) => {\n if (key !== \"text\") {\n leafs.forEach((leaf) => {\n leaf.set(key, parent.get(key));\n });\n }\n });\n};\n\nexport const formatAtEqualPath = ({ format, value, start, end }: formatAtEqualPathOperation) => {\n const length = end.offset - start.offset;\n const leaf = start.leaf;\n const text = leafText(leaf);\n\n const content = text.toString();\n const index = getIndex(leaf);\n\n const isMarkActive = leaf.has(format);\n\n if (isMarkActive && leafLength(leaf) === length) {\n leaf.delete(format);\n return leaf;\n } else {\n const remainingText = content.substring(end.offset, leafLength(leaf));\n if (remainingText.length == 0 && leafLength(leaf) === end.offset - start.offset) {\n leaf.set(format, value);\n return leaf;\n } else {\n deleteLeafText(leaf, start.offset, leafLength(leaf));\n\n const formatedLeaf = createLeaf({\n ...leaf.toJSON(),\n id: undefined,\n [format]: value,\n text: content.substring(start.offset, end.offset)\n });\n\n let newLeaves = [formatedLeaf];\n\n if (remainingText.length > 0) {\n newLeaves.push(createLeaf({ ...leaf.toJSON(), id: undefined, text: remainingText }));\n }\n\n if (isMarkActive) {\n formatedLeaf.delete(format);\n }\n newLeaves.length && leafNodeContent(leaf).insert(index + 1, newLeaves);\n return formatedLeaf;\n }\n }\n};\n\nexport const formatText = (editor: Editor, mark: Record<string, any>) => {\n const [[format, value]] = Object.entries(mark);\n console.log(format);\n let newPath = 0;\n const { start, end, type, length, setPosition, selectedText } = editor.selection;\n\n editor.doc.transact(() => {\n switch (type) {\n case \"collapsed\": {\n const isMarkActive = start.leaf.has(format);\n\n if (isMarkActive && isLeafEmpty(start.leaf)) {\n start.leaf.delete(format);\n newPath = leafNodeContent(start.leaf)\n .toArray()\n .indexOf(start.leaf);\n } else {\n if (isLeafEmpty(start.leaf)) {\n isMarkActive ? start.leaf.delete(format) : start.leaf.set(format, value);\n } else {\n splitLeaf(editor, { yText: start.leaf.get(\"text\"), at: start });\n const newChild = createLeaf({ text: \"\", [format]: value });\n applyMarksFromParent(start.leaf, [newChild]);\n\n if (isMarkActive) newChild.delete(format);\n\n leafNodeContent(start.leaf).insert(start.path.slice().reverse()[0] + 1, [newChild]);\n\n if (isLeafEmpty(start.leaf)) {\n leafNodeContent(start.leaf).delete(start.path.slice().reverse()[0]);\n }\n newPath = leafNodeContent(start.leaf)\n .toArray()\n .indexOf(newChild);\n }\n }\n mergeLeafs(leafNodeContent(start.leaf));\n break;\n // return newPath;\n }\n case \"singlenode\": {\n editor.doc.transact(() => {\n const formatedLeaf = formatAtEqualPath({ format, value, start, end, length });\n mergeLeafs(leafNodeContent(start.leaf));\n const isRemoved = formatedLeaf._item.deleted;\n\n if (!isRemoved) {\n setPosition(start.leaf.get(\"id\"), { offset: start.offset });\n setTimeout(() => {\n setPosition(formatedLeaf.get(\"id\"), { offset: 0, end: leafLength(formatedLeaf) });\n });\n } else {\n const remainingLeaf = formatedLeaf.parent.get(start.leafIndex - 1);\n const offset = leafText(remainingLeaf)\n .toJSON()\n .indexOf(selectedText);\n setTimeout(() => {\n setPosition(remainingLeaf.get(\"id\"), {\n offset,\n end: offset + selectedText.length\n });\n });\n }\n });\n break;\n }\n case \"multileaves\":\n case \"multinodes\": {\n const startPathString = start.path.join(\",\");\n const endPathString = end.path.join(\",\");\n let started = false;\n let ended = false;\n\n traverse(\n editor,\n (leaf, isText) => {\n if (isText) {\n const path = getPath(leaf);\n const isStart = path.join(\",\") === startPathString;\n const isEnd = path.join(\",\") === getPath(end.leaf).join(\",\");\n console.log({ isEnd }, endPathString, getPath(end.leaf).join(\",\"), path.join(\",\"));\n if (isStart) {\n started = true;\n }\n\n const startOffset = isStart ? start.offset : 0;\n const endOffset = isEnd ? end.offset : leafLength(leaf);\n started &&\n !ended &&\n formatAtEqualPath({\n format,\n start: { leaf, offset: startOffset },\n end: { offset: endOffset },\n value\n });\n console.log({ ended });\n if (isEnd) {\n ended = true;\n }\n\n mergeLeafs(leafNodeContent(leaf));\n }\n },\n { start: start.path[0], end: end.path[0] + 1 }\n );\n break;\n }\n }\n });\n\n return newPath;\n};\n","import { Editor } from \"../types\";\nimport {\n deleteLeafText,\n getPath,\n insertTextInLeaf,\n leafLength,\n LeavesHarvest,\n replaceLeafText,\n traverse,\n YLeaf\n} from \"../utils\";\n\nexport type insertTextOperation = {\n text: string | null;\n};\nexport const insertText = (editor: Editor, { text }: insertTextOperation) => {\n if (!text || text === null || !text.length) return;\n\n const { start, end, type, length, setPosition } = editor.selection;\n if (type === \"notInDoc\") return console.error(\"Path is not in document space\");\n\n switch (type) {\n case \"collapsed\": {\n insertTextInLeaf(start.leaf, start.offset, text);\n setPosition(start.leaf.get(\"id\"), { offset: start.offset + text.length });\n break;\n }\n case \"singlenode\": {\n replaceLeafText(start.leaf, start.offset, length, text);\n setPosition(start.leaf.get(\"id\"), { offset: start.offset + text.length });\n break;\n }\n case \"multileaves\":\n case \"multinodes\": {\n const startPathString = start.path.join(\",\");\n const endPathString = end.path.join(\",\");\n editor.doc.transact(() => {\n const { reap, burn } = new LeavesHarvest();\n traverse(\n editor,\n (leaf, isText) => {\n if (isText) {\n const path = getPath(leaf);\n if (path.join(\",\") === startPathString) {\n replaceLeafText(leaf, start.offset, leafLength(leaf), text);\n reap(leaf);\n } else if (path > start.path && path < end.path) {\n deleteLeafText(leaf, 0, leafLength(leaf));\n reap(leaf);\n } else if (path.join(\",\") === endPathString) {\n deleteLeafText(leaf, 0, end.offset);\n reap(leaf);\n }\n }\n },\n { start: start.path[0], end: end.path[0] + 1 }\n );\n burn(editor);\n });\n setPosition(start.leaf.get(\"id\"), { offset: start.offset + text.length });\n }\n }\n};\n","import { YArray, YMap } from \"yjs/dist/src/internals\";\nimport { getIndex } from \"../utils\";\n\nexport const areLeafsMergeable = (nodes: YMap<any>[]) => {\n let keys = nodes.map((node) => Array.from(node.keys())).flat();\n return nodes.every((node) => {\n return keys.every((key) => node.has(key));\n });\n};\n\nexport const mergeLeafs = (leafs: YArray<YMap<any>>) => {\n let currentLeaf = leafs.get(0);\n let leafsToDelete = [] as YMap<any>[];\n leafs.forEach((_, i) => {\n const leaf = leafs.get(i + 1);\n if (!leaf) return;\n\n if (areLeafsMergeable([currentLeaf, leaf])) {\n const firstText = currentLeaf.get(\"text\");\n currentLeaf.get(\"text\").insert(firstText.length, leaf.get(\"text\").toString());\n leafsToDelete.push(leaf);\n } else {\n currentLeaf = leaf;\n }\n });\n\n leafsToDelete.forEach((leaf) => {\n leafs.delete(getIndex(leaf));\n });\n};\n","import * as Y from \"yjs\";\nimport { YText, YArray, YMap } from \"yjs/dist/src/internals\";\nimport { Editor, Position } from \"../types\";\nimport { applyMarksFromParent } from \".\";\n\ntype splitLeafOperation = {\n yText: YText;\n at: Position;\n};\nexport const splitLeaf = (editor: Editor | Pick<Editor, \"toYJS\">, { yText, at }: splitLeafOperation) => {\n const content = yText.toString();\n\n const rightText = content.substring(at.offset, yText.length);\n if (at.offset === yText.length) return;\n const newText = new Y.Text(rightText);\n const newLeave = new Y.Map();\n newLeave.set(\"text\", newText);\n applyMarksFromParent(yText.parent as YMap<any>, [newLeave]);\n\n const parent = yText?.parent?.parent as YArray<any>;\n yText.delete(at.offset, yText.length);\n parent.insert(at.path.slice().reverse()[0] + 1, [newLeave]);\n};\n","import { YArray, YText } from \"yjs/dist/src/internals\";\nimport { Editor, Position, EdytorSelection } from \"../types\";\nimport { deleteText } from \".\";\nimport { YNode, YLeaf } from \"..\";\nimport {\n leafNodeContent,\n leafString,\n leafLength,\n deleteLeafText,\n leafNode,\n getIndex,\n leafNodeContentLength,\n hasChildren,\n getNodeChildren,\n createLeaf,\n createNode\n} from \"../utils\";\n\nexport type splitNodeOperation = {\n at: Position;\n range?: EdytorSelection;\n yText?: YText;\n};\n\nexport const splitNode = (editor: Editor) => {\n const { start, end, type, length, setPosition, edges } = editor.selection;\n\n const leaf = start.leaf;\n const leafContent = leafNodeContent(start.leaf);\n const node = leafNode(start.leaf);\n\n const indexOfLeaf = getIndex(start.leaf);\n const indexOfNode = getIndex(node);\n\n const split = () => {\n const nextLeaves = leafContent.toArray().filter((_, i) => i > indexOfLeaf);\n\n const rightText = leafString(start.leaf).substring(start?.offset, leafLength(start.leaf));\n deleteLeafText(start.leaf, start?.offset, rightText.length, false);\n\n const newParent = hasChildren(node) ? getNodeChildren(node) : (node.parent as YArray<any>);\n const newLeaf = createLeaf({ ...leaf.toJSON(), id: undefined, text: rightText });\n newParent.insert(hasChildren(node) ? 0 : indexOfNode + 1, [\n createNode(editor.defaultBlock, {\n children: [],\n content: [newLeaf].concat(nextLeaves.map((leaf) => createLeaf(leaf.toJSON())))\n })\n ]);\n leafContent.delete(indexOfLeaf + 1, leafNodeContentLength(start.leaf) - indexOfLeaf - 1);\n setTimeout(() => {\n setPosition(newLeaf.get(\"id\"), { offset: 0 });\n }, 10);\n };\n\n let doSplit = (!edges.startNode || !edges.endNode) && type !== \"multinodes\";\n\n if ((edges.endNode || edges.startNode) && type === \"collapsed\") {\n const newNode = createNode(editor.defaultBlock);\n (node.parent as YArray<any>).insert(indexOfNode + (edges.endNode ? 1 : 0), [newNode]);\n return setTimeout(() => {\n setPosition(\n newNode\n .get(\"content\")\n .get(0)\n .get(\"id\"),\n { offset: 0 }\n );\n });\n }\n\n switch (type) {\n case \"collapsed\": {\n doSplit && split();\n break;\n }\n case \"singlenode\": {\n deleteText(editor, { mode: \"backward\" });\n doSplit && split();\n !doSplit && setPosition(start.leaf.get(\"id\"), { offset: start.offset });\n\n break;\n }\n case \"multileaves\":\n case \"multinodes\": {\n deleteText(editor, { mode: \"backward\" });\n doSplit && split();\n !doSplit && setPosition(start.leaf.get(\"id\"), { offset: start.offset });\n }\n }\n};\n","import { Editor, getNode, getNodeContainer, getPath, YNode, getChildren, getContent } from \"..\";\nimport { createNode, getNodeAtPath, traverse } from \"../utils\";\n\nexport const nestNode = (editor: Editor) => {\n const { start, type, end, setPosition } = editor.selection;\n\n const startNode = getNode(start.leaf);\n const startJsonNode = startNode.toJSON();\n const startPath = getPath(startNode);\n const [index, ...newPath] = startPath.slice().reverse();\n const prevNode = getNodeAtPath(editor, [...newPath, index - 1]);\n const startContainer = getNodeContainer(startNode);\n switch (type) {\n case \"singlenode\":\n case \"collapsed\": {\n if (!prevNode) return;\n const id = start.leaf.get(\"id\");\n const prevChildren = prevNode.get(\"children\");\n startContainer.delete(index);\n\n prevChildren.insert(prevChildren.length, [\n createNode(startJsonNode.type, {\n ...startJsonNode,\n children: startJsonNode.children.map(getChildren),\n content: startJsonNode.content.map(getContent)\n })\n ]);\n\n setPosition(id, { offset: start.offset });\n break;\n }\n case \"multileaves\":\n case \"multinodes\": {\n let length = 0;\n let newNodes = [];\n const id = start.leaf.get(\"id\");\n const startPathString = start.path.slice(0, start.path.length - 1).join(\"\");\n const endPathString = end.path.slice(0, start.path.length - 1).join(\"\");\n traverse(\n editor,\n (node, isText) => {\n if (!isText) {\n const path = getPath(node).join(\"\");\n\n if (path.length === startPath.length) {\n if (path <= endPathString && path >= startPathString) {\n length++;\n const jsonNode = node.toJSON();\n newNodes.push(\n createNode(jsonNode.type, {\n ...jsonNode,\n children: jsonNode.children.map(getChildren),\n content: jsonNode.content.map(getContent)\n })\n );\n }\n }\n }\n },\n { start: start.path[0], end: end.path[0] + 1 }\n );\n if (!prevNode) return;\n\n const prevChildren = prevNode.get(\"children\");\n\n startContainer.delete(index, length);\n prevChildren.insert(prevChildren.length, newNodes);\n setPosition(id, { offset: start.offset });\n break;\n }\n }\n};\n","import { getIndex } from \"..\";\nimport { YArray } from \"../../../../node_modules/yjs/dist/src/internals\";\nimport { copyNode } from \"../utils\";\n\nexport type moveNodeOperation = {\n from: {\n container: YArray<any> | any;\n at: number | number[];\n };\n to: {\n container: YArray<any>;\n at: number;\n };\n};\nexport const moveNode = ({ from, to }: moveNodeOperation) => {\n const indexes = Array.isArray(from.at) ? from.at : [from.at];\n const [firstIndex] = indexes;\n const firstNode = from.container.get(firstIndex);\n\n const nodesCopies = indexes.map((index) => {\n const node = from.container.get(index);\n return copyNode(node);\n });\n\n to.container.insert(to.at, nodesCopies);\n from.container.delete(getIndex(firstNode), indexes.length);\n return nodesCopies[0]\n .get(\"content\")\n .get(0)\n .get(\"id\");\n};\n","import { YArray, YMap } from \"yjs/dist/src/internals\";\nimport { mergeLeafs } from \"../operations\";\nimport { Editor } from \"../types\";\nimport { getIndex, getNode, traverse } from \"./common\";\nimport { leafNodeContent, leafNodeContentLength, leafString } from \"./leaves\";\nimport { createLeaf, createNode, EdytorDoc, getChildren, getContent, YLeaf, YNode } from \"./yClasses\";\n\nexport const mergeContentWithPrevLeaf = (editor: Editor) => {\n const { start } = editor.selection;\n let prevLeaf;\n let stop = false;\n\n traverse(editor, (node, isText) => {\n if (isText) {\n if (node === start.leaf) {\n stop = true;\n } else if (!stop) {\n prevLeaf = node;\n }\n }\n });\n if (!prevLeaf) return;\n\n leafNodeContent(prevLeaf).insert(\n leafNodeContentLength(prevLeaf),\n leafNodeContent(start.leaf)\n .toArray()\n .map((leaf: YLeaf) => {\n return createLeaf(leaf.toJSON());\n })\n );\n mergeLeafs(leafNodeContent(prevLeaf));\n (start.leaf.parent.parent as YArray<YNode>).delete(getIndex(getNode(start.leaf)));\n};\n\nexport const mergeContentWithNextLeaf = (editor: Editor) => {\n const { start } = editor.selection;\n let nextLeaf;\n let stop = false;\n\n editor.doc.traverse((node, isText) => {\n if (isText) {\n if (node === start.leaf) {\n stop = true;\n } else if (stop) {\n nextLeaf = node;\n stop = false;\n }\n }\n });\n\n //TODO the children should be pull to the depth level of the removed parent\n console.log(leafNodeContent(nextLeaf).toArray());\n leafNodeContent(start.leaf).insert(\n leafNodeContentLength(start.leaf),\n leafNodeContent(nextLeaf)\n .toArray()\n .map((leaf: YLeaf) => {\n return createLeaf(leaf.toJSON());\n })\n );\n mergeLeafs(leafNodeContent(start.leaf));\n console.log(start.leaf.parent.toJSON());\n const node = getNode(nextLeaf);\n if (hasChildren(node)) {\n console.log(node.get(\"children\").toJSON());\n node.parent.insert(\n getIndex(node),\n node\n .get(\"children\")\n .toJSON()\n .map((node) => createNode(node.type, node))\n );\n }\n node.parent.delete(getIndex(node));\n return nextLeaf;\n};\n\nexport const deleteNode = (node, defaultBlock: string) => {\n if (isNodeEmpty(node)) {\n (node.parent as YArray<YNode>).delete(getIndex(node));\n } else if (isNodeContentEmpty(node)) {\n const children = getNodeChildren(node).toJSON();\n const index = getIndex(node);\n node.parent.delete(index);\n node.parent.insert(\n index,\n children.map(({ type, ...props }) => createNode(type, props))\n );\n }\n if (node.parent === (node.doc.getArray(\"children\") && node.doc.getArray(\"children\").length === 0)) {\n (node.parent as YArray<YNode>).insert(0, [createNode(defaultBlock, { content: [createLeaf()] })]);\n }\n};\n\nexport const getNodeContainer = (node) => node.parent as YArray<YNode>;\nexport const getNodeChildren = (node) => node.get(\"children\") as YArray<YNode>;\nexport const getNodeContent = (node) => node.get(\"content\") as YArray<YNode>;\nexport const hasChildren = (node) => getNodeChildren(node).length > 0;\nexport const isNodeEmpty = (node) => isNodeContentEmpty(node) && !hasChildren(node);\nexport const isNodeContentEmpty = (node) =>\n getNodeContent(node).length === 0 ||\n getNodeContent(node)\n .toArray()\n .map(leafString)\n .join(\"\").length === 0;\n\nexport const copyNode = (node: YNode) => {\n const jsonNode = node.toJSON();\n return createNode(jsonNode.type, {\n ...jsonNode,\n children: jsonNode.children.map(getChildren),\n content: jsonNode.content.map(getContent)\n });\n};\n","import { customAlphabet } from \"nanoid\";\nimport { YArray, YMap } from \"yjs/dist/src/internals\";\nimport { Editor } from \"../types\";\nimport { leafString } from \"./leaves\";\nimport { getNodeChildren, getNodeContent } from \"./nodes\";\nimport { YLeaf } from \"./yClasses\";\nexport const nanoid = () => \"y-\" + customAlphabet(\"346789ABCDEFGHJKLMNPQRTUV-WXYabcdefghijkmnpqrtwxyz\", 20)();\n\ntype YNode = YMap<any>;\n\nexport const getNode = (node): YNode => node?.parent?.parent as YNode;\n\nexport const getIndex = (node: YNode): number => {\n let index = 0;\n let stop = false;\n let n = node.parent._start;\n while (n !== null && !stop) {\n if (n.countable && !n.deleted) {\n const c = n.content.getContent();\n for (let i = 0; i < c.length; i++) {\n if (c[i] === node) {\n stop = true;\n break;\n }\n index++;\n }\n }\n n = n.right;\n }\n return index;\n};\n\nexport const getPath = (node: YNode): number[] => {\n let p = [] as number[];\n let n = node;\n while (!!n) {\n p.push(getIndex(n));\n n = getNode(n);\n }\n return p.reverse();\n};\n\nexport const getId = (node): string => node.get(\"id\");\n\nexport const getLeafAtPath = (editor: Editor, [start, ...path]: number[]): YLeaf => {\n let node = editor.children.get(start);\n let i = 0;\n while (i < path.length - 1) {\n const index = path[i];\n i++;\n node = node.get(\"children\").get(index);\n }\n\n return node && node.get(\"content\").get(path.slice().reverse()[0]);\n};\nexport const getNodeAtPath = (editor: Editor, [start, ...path]: number[]): YNode => {\n let node = editor.children.get(start);\n for (let i = 0; i < path.length; i++) {\n const index = path[i];\n if (node.get) {\n node = node.get(\"children\").get(index);\n } else {\n node = undefined;\n }\n }\n return node;\n};\nexport const getContainerAtPath = (editor: Editor, path: number[]): YArray<any> => {\n if (path.length === 1) {\n return editor.children;\n } else {\n return getNodeAtPath(editor, path.slice(1, path.length)).get(\"children\");\n }\n};\nexport const traverse = (\n editor: Editor,\n cb: (node: YMap<any>, isText: boolean, path: number[]) => void,\n opts?: {\n start?: number;\n end?: number;\n }\n) => {\n const t = (node: YNode | YLeaf, path: number[]) => {\n if (node.has(\"text\")) {\n cb(node, true, path);\n } else {\n const array = getNodeContent(node)\n .toArray()\n //@ts-ignore\n .concat(getNodeChildren(node).toArray());\n cb(node, false, path);\n\n for (let i = 0; i < array.length; i++) {\n t(array[i], [...path.slice(0, path.length - 1), 0, i]);\n }\n }\n };\n const array = editor.children.toArray().slice(opts?.start || 0, opts?.end || editor.children.length) as YNode[];\n for (let i = 0; i < array.length; i++) {\n t(array[i], [i + (opts?.start || 0)]);\n }\n};\n\nexport const toString = (editor: Editor): string => {\n let t = \"\";\n const array = editor.children.toArray() as YNode[];\n for (let i = 0; i < array.length; i++) {\n t += leafString(array[i]);\n }\n return t;\n};\n","import { YArray, YMap, YText } from \"yjs/dist/src/internals\";\nimport { Editor } from \"../types\";\nimport { getIndex } from \"./common\";\nimport { deleteNode } from \"./nodes\";\nimport { YLeaf, YNode } from \"./yClasses\";\n\nexport class LeavesHarvest {\n leaves: { [id: string]: { shouldDeleteNode: boolean; content: YArray<YLeaf>; node: YMap<any>; indexes: number[] } };\n constructor() {\n this.leaves = {};\n }\n\n reap = (leaf, shouldDeleteNode = false) => {\n if (!isLeafEmpty(leaf)) return;\n const id = leafNodeId(leaf);\n if (!this.leaves[id]) {\n this.leaves[id] = {\n shouldDeleteNode,\n content: leafNodeContent(leaf),\n node: leafNode(leaf),\n indexes: []\n };\n }\n\n this.leaves[id].indexes.push(getIndex(leaf));\n };\n\n burn = (editor: Editor) => {\n Object.values(this.leaves).forEach(({ shouldDeleteNode, content, node, indexes }, i) => {\n content.delete(indexes[0], indexes.length);\n if (content.length === 0 && !shouldDeleteNode) {\n content.insert(0, [createLeaf()]);\n } else if (shouldDeleteNode) return deleteNode(node, editor?.defaultBlock);\n });\n };\n}\n\nexport const leafData = (leaf): YMap<any> => leaf.get(\"data\");\nexport const leafText = (leaf): YText => leaf.get(\"text\");\nexport const leafLength = (leaf): number => leafText(leaf).length;\nexport const leafString = (leaf): string => leafText(leaf).toString();\n\nexport const isLeafEmpty = (leaf) => leafText(leaf) === undefined || leafLength(leaf) === 0;\nexport const deleteLeafText = (leaf, index: number, length: number, shouldRemoveIfEmpty?: boolean) => {\n leafText(leaf).delete(index, length);\n\n shouldRemoveIfEmpty && removeIfEmpty(leaf);\n};\nexport const insertTextInLeaf = (leaf, index: number, text) => {\n leafText(leaf).insert(index, text);\n};\nexport const replaceLeafText = (leaf, start: number, length: number, text: string) => {\n const currentText = leafString(leaf).split(\"\");\n currentText.splice(start, length, ...text.split(\"\"));\n return setLeafText(leaf, currentText.join(\"\"));\n};\nexport const setLeafText = (leaf, text: string) => {\n const t = leafText(leaf);\n t.delete(0, t.length);\n t.insert(0, text);\n};\n\nexport const setLeafData = (leaf, data: object) => {\n if (leaf.has(\"data\")) {\n Object.keys(data).forEach((key) => {\n leafData(leaf).set(key, data[key]);\n });\n } else {\n leaf.set(\"data\", new Map(Object.entries(data)));\n }\n};\n\nexport const removeIfEmpty = (leaf) => {\n if (isLeafEmpty(leaf)) {\n leafNodeContent(leaf).delete(getIndex(leaf));\n // if (leafNodeContentLength(leaf) === 0) {\n // deleteNode(leafNode(leaf));\n // }\n }\n};\n\nexport const leafNode = (leaf): YNode => leaf.parent.parent as YNode;\nexport const leafNodeId = (leaf): string => leafNode(leaf).get(\"id\");\n\nexport const leafNodeContent = (leaf): YArray<YLeaf> => leaf.parent as YArray<YLeaf>;\n\nexport const leafNodeContentLength = (leaf): number => leafNodeContent(leaf).length;\nexport const leafNodeContentStringLength = (leaf): number =>\n leafNodeContent(leaf)\n .toArray()\n .reduce((acc, leaf) => acc + leafLength(leaf), 0);\n\nexport const leafNodeChildren = (leaf): YArray<YNode> => leafNode(leaf).get(\"children\") as YArray<YNode>;\n\nexport const leafNodeChildrenLength = (leaf): number => leafNodeChildren(leaf).length;\n","import { replaceLeafText } from \"../utils\";\nimport { onBeforeInputData } from \"../types\";\nimport { splitNode, insertText, deleteText, formatText } from \"../operations\";\n\nconst prevent = (e: any) => {\n e.preventDefault();\n e.stopPropagation();\n};\n\nconst getDataTransfer = (e: any): string => e.dataTransfer.getData(\"text/plain\");\n\nexport const onBeforeInput = ([doc, onChange, editor]: onBeforeInputData, e: InputEvent) => {\n prevent(e);\n // console.log(e);\n const { start, length } = editor.selection;\n\n switch (e.inputType) {\n case \"insertFromPaste\":\n case \"insertLineBreak\":\n // case \"insertCompositionText\":\n // case \"insertFromDrop\":\n case \"insertText\": {\n const text =\n e.inputType === \"insertLineBreak\"\n ? \"\\n\"\n : e.inputType === \"insertFromPaste\"\n ? getDataTransfer(e)\n : (e.data as string);\n\n insertText(editor, {\n text\n });\n\n break;\n }\n case \"deleteContentBackward\": {\n deleteText(editor, { mode: \"backward\" });\n\n break;\n }\n case \"deleteByDrag\":\n case \"deleteByCut\":\n case \"deleteContentForward\": {\n deleteText(editor, { mode: \"forward\" });\n\n break;\n }\n\n case \"insertParagraph\": {\n splitNode(editor);\n\n break;\n }\n\n case \"insertFromDrop\": {\n setTimeout(() => {\n const text = getDataTransfer(e);\n if (text) {\n insertText(editor, {\n text\n });\n }\n }, 50);\n break;\n }\n case \"deleteSoftLineBackward\": {\n break;\n }\n case \"deleteWordForward\": {\n break;\n }\n case \"insertFromYank\": {\n break;\n }\n case \"formatSetBlockTextDirection\": {\n break;\n }\n case \"formatSetInlineTextDirection\": {\n break;\n }\n case \"deleteWordBackward\": {\n break;\n }\n case \"insertCompositionText\": {\n break;\n }\n case \"formatItalic\":\n case \"formatBold\": {\n break;\n }\n\n case \"insertReplacementText\": {\n doc().doc.transact(() => {\n replaceLeafText(start.leaf, start.offset, length, getDataTransfer(e));\n });\n }\n }\n\n onChange && onChange(editor);\n};\n","import { moveNode } from \"../operations\";\nimport { Editor, EdytorSelection } from \"../types\";\nimport { getIndex, getPath } from \"./common\";\nimport { EdytorDoc } from \"./yClasses\";\n\nexport class Dropper {\n from;\n to;\n node;\n startPath;\n container: HTMLDivElement;\n editor: Editor;\n doc: EdytorDoc;\n editorId: string;\n ID_TO_NODE: Map<any, any>;\n selection: EdytorSelection;\n allowNesting: boolean;\n\n init = (editor, container) => {\n this.editor = editor;\n this.doc = editor.doc;\n this.container = container;\n this.editorId = editor.editorId;\n this.selection = editor.selection;\n this.ID_TO_NODE = editor.ID_TO_NODE;\n this.allowNesting = editor.allowNesting;\n };\n startDrag = (node, e: DragEvent) => {\n this.node = node;\n const dndIndicator = document.getElementById(\"dndIndicator\");\n dndIndicator.style.opacity = \"1\";\n\n const element = document.getElementById(node.get(\"id\")) as HTMLElement;\n element.style.opacity = \"0.4\";\n document.body.style.cursor = \"grabbing\";\n\n this.from = {\n container: node.parent,\n at: getIndex(node)\n };\n this.startPath = getPath(node);\n e.dataTransfer?.setDragImage(element, e.offsetX, e.offsetY);\n document.addEventListener(\"mousemove\", this.onDrag);\n document.addEventListener(\"mouseup\", this.dragEnd);\n };\n dragEnd = () => {\n const element = document.getElementById(this.node.get(\"id\")) as HTMLElement;\n if (element) element.style.opacity = \"1\";\n document.body.style.cursor = \"auto\";\n document.removeEventListener(\"mousemove\", this.onDrag);\n document.removeEventListener(\"mouseup\", this.dragEnd);\n const id = moveNode({ from: this.from, to: this.to });\n const dndIndicator = document.getElementById(\"dndIndicator\");\n dndIndicator.style.opacity = \"0\";\n setTimeout(() => {\n console.log(id);\n this.selection.setPosition(id, { offset: 0 });\n });\n };\n\n getHoveredNode = (target: HTMLElement) => {\n let hoveredNode;\n let element = target;\n let i = 0;\n while (!hoveredNode && element?.id !== this.editorId && element && i < 100) {\n if (element.hasAttribute(\"data-edytor-block\")) {\n hoveredNode = this.ID_TO_NODE.get(element.id);\n break;\n }\n element = element.parentElement;\n i++;\n }\n if (!hoveredNode) return {};\n\n return { hoveredElement: element, hoveredNode };\n };\n onDrag = (e: MouseEvent) => {\n const { hoveredElement, hoveredNode } = this.getHoveredNode(e.target as HTMLElement);\n const dndIndicator = document.getElementById(\"dndIndicator\");\n\n if (!hoveredNode || !hoveredElement || !dndIndicator || hoveredNode === this.node) return;\n const rectHovered = hoveredElement.getBoundingClientRect();\n const isOnTop = e.y < rectHovered.top + rectHovered.height / 2;\n const rect = rectHovered;\n const isNested = this.allowNesting && !isOnTop && e.x > rect.left + rect.width / 5;\n\n const top = isOnTop ? rect.top : rect.top + rect.height;\n const deltaX = isNested ? 30 : 0;\n\n let path = getPath(hoveredNode);\n\n let [index, ...startOfPath] = path.slice().reverse();\n\n if (this.startPath.join(\"\") === startOfPath.join(\"\")) {\n return;\n // this.to= undefined\n }\n\n dndIndicator.style.width = `${rect.width - deltaX}px`;\n dndIndicator.style.top = `${top + window.pageYOffset}px`;\n dndIndicator.style.left = `${rect.left + deltaX}px`;\n\n index = index + (isOnTop ? 0 : 1);\n if (index === -1) index = 0;\n this.to = {\n container: isNested ? hoveredNode.get(\"children\") : path.length === 1 ? this.editor.children : hoveredNode.parent,\n at: isNested ? 0 : index\n };\n };\n}\n","import { Editor, Position } from \"../types\";\nimport { getIndex, getPath, leafLength, leafNode, leafNodeContentLength, YLeaf, YNode } from \".\";\n\nexport class EdytorSelection {\n editor: Editor;\n observers: ((selection: EdytorSelection) => void)[];\n container: HTMLDivElement;\n\n start: Position;\n end: Position;\n selectedText: string;\n arePathsEquals: boolean;\n editorOffset: number;\n length: number;\n range?: Range;\n boundingRect?: DOMRect;\n edges: {\n startLeaf: boolean;\n startNode: boolean;\n endLeaf: boolean;\n endNode: boolean;\n };\n selection?: Selection;\n focused: boolean;\n type?: \"multinodes\" | \"collapsed\" | \"singlenode\" | \"multileaves\" | \"notInDoc\";\n\n constructor() {\n this.observers = [];\n }\n init = (editor: Editor, container) => {\n this.container = container;\n this.editor = editor;\n document.addEventListener(\"selectionchange\", this.onSelection);\n this.container.addEventListener(\"focus\", this.onFocus);\n this.container.addEventListener(\"blur\", this.onBlur);\n };\n onFocus = () => {\n this.focused = true;\n this.onChange();\n };\n\n onBlur = () => {\n this.focused = false;\n this.onChange();\n };\n destroy = () => {\n document.removeEventListener(\"selectionchange\", this.onSelection);\n };\n onSelection = (e: any) => {\n if (e.target?.activeElement === this.container) this.getRange();\n };\n observe = (observer) => {\n this.observers = this.observers ? this.observers.concat(observer) : [observer];\n };\n unobserve = (observer) => {\n this.observers = this.observers ? this.observers.filter((o) => o !== observer) : [];\n };\n\n getLeaf = (\n anchorNode: HTMLElement,\n current: \"anchorNode\" | \"focusNode\"\n ): [YLeaf | undefined, YNode | undefined, number[], HTMLElement | undefined] => {\n if (this[current] && this[current].node === anchorNode) {\n // serve cached result to avoid loops to getPath and node\n return this[current].value;\n }\n\n let leaf;\n let node = anchorNode;\n\n while (!leaf && node !== this.container && node) {\n leaf = this.editor.ID_TO_NODE.get(node.id);\n if (!leaf) {\n node = node.parentElement;\n }\n }\n\n if (!leaf) return [undefined, undefined, undefined, undefined];\n const value = [leaf, leafNode(leaf), getPath(leaf), node];\n this[current] = { value, node: anchorNode };\n return value;\n };\n\n getNodeBoundingRect = (node: YNode): { nodeHtml: HTMLElement } => {\n const nodeHtml = this.container.querySelector(`#${node.get(\"id\")}`) as HTMLElement;\n return { nodeHtml };\n };\n getRange = (): EdytorSelection => {\n const selection = window.getSelection();\n const { anchorNode, focusNode, anchorOffset, focusOffset, isCollapsed, rangeCount } = selection;\n\n if (focusNode === null) return;\n const [leaf1, node1, path1, leafHtml1] = this.getLeaf(anchorNode as HTMLElement, \"anchorNode\");\n const [leaf2, node2, path2, leafHtml2] = this.getLeaf(focusNode as HTMLElement, \"focusNode\");\n\n if (!leaf1) return;\n const equalPaths = path1.join(\"\") === path2.join(\"\");\n const isFollowing = equalPaths ? anchorOffset < focusOffset : path1.join() < path2.join();\n const range = rangeCount >= 1 ? selection?.getRangeAt(0) : undefined;\n\n this.start = {\n ...this.getNodeBoundingRect(isFollowing ? node1 : node2),\n node: isFollowing ? node1 : node2,\n leafId: (isFollowing ? leaf1 : leaf2).get(\"id\"),\n leafIndex: isFollowing ? path1[path1.length - 1] : path2[path2.length - 1],\n nodeIndex: isFollowing ? path1[path1.length - 2] : path2[path2.length - 2],\n path: isFollowing ? path1 : path2,\n leafHtml: isFollowing ? leafHtml1 : leafHtml2,\n offset: isFollowing ? anchorOffset : focusOffset,\n leaf: isFollowing ? leaf1 : leaf2\n } as Position;\n\n this.end =\n isCollapsed || node2 === null\n ? this.start\n : {\n ...this.getNodeBoundingRect(!isFollowing ? node1 : node2),\n node: !isFollowing ? node1 : node2,\n leafId: (!isFollowing ? leaf1 : leaf2).get(\"id\"),\n leafIndex: !isFollowing ? path1[path1.length - 1] : path2[path2.length - 1],\n nodeIndex: !isFollowing ? path1[path1.length - 2] : path2[path2.length - 2],\n path: !isFollowing ? path1 : path2,\n leafHtml: !isFollowing ? leafHtml1 : leafHtml2,\n offset: !isFollowing ? anchorOffset : focusOffset,\n leaf: !isFollowing ? leaf1 : leaf2\n };\n this.selectedText = range ? range.toString() : \"\";\n this.arePathsEquals = equalPaths;\n this.length = this.selectedText.length;\n this.range = range;\n this.selection = selection;\n this.edges = {\n startLeaf: this.start.offset === 0,\n startNode: this.start.offset === 0 && getIndex(this.start.leaf) === 0,\n endLeaf: this.end.offset === leafLength(this.end.leaf),\n endNode:\n this.end.offset === leafLength(this.end.leaf) &&\n getIndex(this.start.leaf) === leafNodeContentLength(this.end.leaf) - 1\n };\n this.type = isCollapsed\n ? \"collapsed\"\n : equalPaths\n ? \"singlenode\"\n : this.start.node === this.end.node\n ? \"multileaves\"\n : \"multinodes\";\n this.onChange();\n };\n\n onChange = () => {\n this.observers.forEach((o) => o(this));\n };\n\n setPosition = (\n id: string,\n { offset, delta, end }: { offset?: number; delta?: number; end?: number; select?: boolean }\n ) => {\n let node = this.container.querySelector(`#${id}`) as ChildNode;\n\n while (node && node.nodeType !== 3 && node?.firstChild) {\n node = node.firstChild;\n }\n\n const pos = offset || this.start?.offset + delta;\n const hasRange = this.range || this.selection;\n if (!hasRange) {\n this.range = document.createRange();\n this.selection = window.getSelection();\n }\n this.range.setStart(node, pos);\n if (end) {\n this.range.setEnd(node, end);\n } else {\n this.range.collapse(true);\n }\n\n this.selection?.removeAllRanges();\n this.selection?.addRange(this.range);\n\n this.start = {\n ...this.start,\n leafHtml: this.container.querySelector(`#${id}`),\n offset: offset || this.start?.offset + delta\n };\n };\n}\n","import { Doc } from \"yjs\";\nimport { WebsocketProvider } from \"y-websocket\";\n\nexport const createWSProvider = (room?) => {\n return new Promise((res) => {\n const doc = new Doc();\n const dev = \"ws://localhost:1234\";\n const prod = \"wss://edytor-production.up.railway.app\";\n console.log(process.env.NODE_ENV);\n const provider = new WebsocketProvider(process.env.NODE_ENV === \"production\" ? prod : dev, room || \"edytor\", doc, {\n connect: true\n });\n provider.on(\"status\", ({ status }) => {\n if (status === \"connected\") {\n return res(provider);\n }\n });\n });\n};\n","// import { WebrtcProvider } from \"y-webrtc\";\nimport { Doc } from \"yjs\";\n\ntype WebrtcProviderOptions = {\n signaling: Array<string>;\n password: string | null;\n awareness: any;\n maxConns: number;\n filterBcConns: boolean;\n peerOpts: any;\n};\nexport const createWebRtcProvider = (doc: Doc, room = \"hello\", opts: WebrtcProviderOptions) => {\n // const fakeDoc = new Doc();\n // const provider = new WebrtcProvider(room, doc, opts);\n // provider.emit(\"ping\", [\"lkeazlk\"]);\n // provider.connect();\n // provider.on(\"ping\", () => {\n // console.log(\"ping\");\n // });\n // provider.on(\"*\", (event) => {\n // console.log(event);\n // });\n // provider.on(\"connect\", (event) => {\n // console.log(event);\n // });\n // return provider;\n};\n","import { Editor } from \"../types\";\n\nexport const onDrop = (editor: Editor, e: DragEvent) => {\n if (e.dataTransfer?.files.length > 0) {\n e.preventDefault();\n console.log(e.dataTransfer?.files);\n }\n};\nexport const onDragOver = (editor: Editor, e: DragEvent) => {\n e.preventDefault();\n\n if (e.dataTransfer?.files.length > 0) {\n e.preventDefault();\n console.log(e.dataTransfer?.files);\n }\n};\n","import { Editor } from \"../types\";\nimport isHotkey from \"is-hotkey\";\nimport { formatText, nestNode } from \"../operations\";\n\nexport const onKeyDown = (editor: Editor, e: KeyboardEvent) => {\n if (e.key === \"Tab\") {\n e.preventDefault();\n editor.allowNesting && nestNode(editor);\n }\n if (e.metaKey) {\n if (e.key === \"z\" && e.metaKey) {\n e.preventDefault();\n return editor.undoManager.undo();\n }\n if (e.key === \"Z\" && e.metaKey && e.shiftKey) {\n e.preventDefault();\n return editor.undoManager.redo();\n }\n\n for (let i = 0; i < editor.hotkeys.length; i++) {\n const { keys, operation, mark } = editor.hotkeys[i];\n if (isHotkey(keys, e)) {\n e.preventDefault();\n e.stopPropagation();\n if (typeof operation === \"function\") {\n return operation(editor);\n }\n switch (operation) {\n case \"formatText\": {\n return formatText(editor, mark);\n }\n }\n break;\n }\n }\n }\n};\n","import { YText, YArray, YMap } from \"yjs/dist/src/internals\";\n\nexport const removeEmptyText = (yText: YText) => {\n let array = yText?.parent?.parent as YArray<YMap<any>> | undefined;\n const index = (array: YArray<any>, node: YMap<any>) => array?.toArray().indexOf(node);\n array?.delete(index(array, yText.parent as YMap<any>)!);\n while (array && array.length === 0) {\n const pop = array.parent as YMap<any>;\n const pop_pop = pop.parent as YArray<YMap<any>>;\n if (pop_pop) {\n const i = index(pop_pop, pop);\n i !== -1 && pop_pop.delete(i);\n array = pop_pop;\n } else {\n array = undefined;\n }\n }\n};\n"],"names":["createLeaf","props","leaf","Map","set","id","nanoid","Text","text","data","marks","Object","entries","keys","forEach","mark","createNode","type","node","content","Array","from","children","YNode","getContent","getChildren","map","EdytorDoc","value","Doc","deleteText","editor","mode","selection","start","end","length","edges","setPosition","startNode","console","log","nodeIndex","leafNodeChildrenLength","path","parent","mergeContentWithPrevLeaf","leafId","offset","copyNode","insert","getIndex","startLeaf","prevLeaf","leafNodeContent","get","leafIndex","deleteLeafText","leafLength","endNode","mergeContentWithNextLeaf","endLeaf","nextLeaf","hasChildren","getNode","startPathString","join","endPathString","doc","transact","LeavesHarvest","reap","burn","traverse","isText","getPath","l","applyMarksFromParent","leafs","key","formatAtEqualPath","format","leafText","toString","index","isMarkActive","has","remainingText","substring","formatedLeaf","toJSON","undefined","newLeaves","push","formatText","newPath","selectedText","isLeafEmpty","toArray","indexOf","splitLeaf","yText","at","newChild","slice","reverse","mergeLeafs","_item","deleted","remainingLeaf","setTimeout","started","ended","isStart","isEnd","startOffset","endOffset","insertText","error","insertTextInLeaf","replaceLeafText","areLeafsMergeable","nodes","flat","every","currentLeaf","leafsToDelete","_","i","firstText","rightText","newText","Y","newLeave","_yText$parent","splitNode","leafContent","leafNode","indexOfLeaf","indexOfNode","split","nextLeaves","filter","leafString","newParent","getNodeChildren","newLeaf","defaultBlock","concat","leafNodeContentLength","doSplit","newNode","nestNode","startJsonNode","startPath","prevNode","getNodeAtPath","startContainer","getNodeContainer","prevChildren","newNodes","jsonNode","moveNode","to","indexes","isArray","firstNode","container","nodesCopies","stop","deleteNode","isNodeEmpty","isNodeContentEmpty","getArray","getNodeContent","customAlphabet","_node$parent","n","_start","countable","c","right","p","cb","opts","t","array","shouldDeleteNode","leafNodeId","_this","leaves","values","leafData","shouldRemoveIfEmpty","removeIfEmpty","currentText","splice","setLeafText","leafNodeChildren","getDataTransfer","e","dataTransfer","getData","editorId","ID_TO_NODE","allowNesting","document","getElementById","style","opacity","element","body","cursor","setDragImage","offsetX","offsetY","addEventListener","onDrag","dragEnd","removeEventListener","target","hoveredNode","hasAttribute","parentElement","hoveredElement","getHoveredNode","dndIndicator","rectHovered","getBoundingClientRect","isOnTop","y","top","height","rect","isNested","x","left","width","deltaX","startOfPath","window","pageYOffset","onSelection","onFocus","onBlur","focused","onChange","activeElement","getRange","observer","observers","o","anchorNode","current","nodeHtml","querySelector","getSelection","focusNode","anchorOffset","focusOffset","isCollapsed","rangeCount","getLeaf","leaf1","node1","path1","leafHtml1","leaf2","node2","path2","leafHtml2","equalPaths","isFollowing","range","getRangeAt","getNodeBoundingRect","leafHtml","arePathsEquals","delta","nodeType","_node","firstChild","pos","createRange","setStart","setEnd","collapse","removeAllRanges","addRange","room","Promise","res","process","provider","WebsocketProvider","connect","on","status","reduce","acc","preventDefault","stopPropagation","prevent","inputType","files","_e$dataTransfer4","_e$dataTransfer2","metaKey","undoManager","undo","shiftKey","redo","hotkeys","operation","isHotkey","pop","pop_pop"],"mappings":"qtBASaA,EAAa,SAACC,OACnBC,EAAO,IAAIC,SACjBD,EAAKE,IAAI,YAAMH,SAAAA,EAAOI,KAAMC,KAC5BJ,EAAKE,IAAI,OAAQ,IAAIG,cAAKN,SAAAA,EAAOO,OAAQ,KACrCP,EAAO,KACGO,EAAyBP,EAAzBO,KAAMC,EAAmBR,EAAnBQ,KAASC,IAAUT,KACrCC,EAAKE,IAAI,OAAQ,IAAIG,OAAKC,GAAQ,KAClCC,GAAQP,EAAKE,IAAI,OAAQ,IAAID,MAAIQ,OAAOC,QAAQH,KAChDC,GACEC,OAAOE,KAAKH,GAAOI,SAAQ,SAACC,GAC1Bb,EAAKE,IAAIW,EAAML,EAAMK,cAGpBb,GCTIc,EAAa,SAACC,EAAchB,OACjCiB,EAAO,IAAIf,aACjBe,EAAKd,IAAI,YAAMH,SAAAA,EAAOI,KAAMC,KAC5BY,EAAKd,IAAI,OAAQa,SACbhB,GAAAA,EAAOQ,MACTS,EAAKd,IAAI,OAAQ,IAAID,MAAIQ,OAAOC,QAAQX,EAAMQ,QAEhDS,EAAKd,IAAI,iBAAWH,SAAAA,EAAOkB,mBAAmBC,QAAQnB,EAAMkB,QAAUC,QAAMC,YAAKpB,SAAAA,EAAOkB,UAAW,CAACnB,OACpGkB,EAAKd,IAAI,kBAAYH,SAAAA,EAAOqB,oBAAoBF,QAAQ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G/B7E,EAAKE,IAAI,OAAQ,IAAID,IAAIQ,OAAOC,QAAQH,qFDmCpB,SAACsB,WACnB0J,EAAI,GACFC,EAAQ3J,EAAOT,SAAS4E,UACrB8B,EAAI,EAAGA,EAAI0D,EAAMtJ,OAAQ4F,IAChCyD,GAAK1C,EAAW2C,EAAM1D,WAEjByD"}
1
+ {"version":3,"file":"edytor.cjs.production.min.js","sources":["../src/utils/yClasses/yLeaf.ts","../src/utils/yClasses/yNode.ts","../src/utils/yClasses/EdytorDoc.ts","../src/operations/deleteText.ts","../src/operations/formatText.ts","../src/operations/insertText.ts","../src/operations/merge.ts","../src/operations/splitLeaf.ts","../src/operations/splitNode.ts","../src/operations/nestNode.ts","../src/operations/moveNode.ts","../src/utils/nodes.ts","../src/utils/common.ts","../src/utils/leaves.ts","../src/events/onBeforeInput.ts","../src/utils/dropper.ts","../src/utils/selection.ts","../src/yjs/wsProvider.ts","../src/events/onKeyDown.ts","../src/events/onDrop.ts","../src/operations/removeEmptyText.ts"],"sourcesContent":["import { nanoid } from \"..\";\nimport { Map, Text } from \"yjs\";\n\nexport type YLeafProps = {\n data?: any;\n text?: string;\n id?: string;\n};\n\nexport const createLeaf = (props?: YLeafProps) => {\n const leaf = new Map();\n leaf.set(\"id\", props?.id || nanoid());\n leaf.set(\"text\", new Text(props?.text || \"\"));\n if (props) {\n const { id, text, data, ...marks } = props;\n leaf.set(\"text\", new Text(text || \"\"));\n data && leaf.set(\"data\", new Map(Object.entries(data)));\n marks &&\n Object.keys(marks).forEach((mark) => {\n leaf.set(mark, marks[mark]);\n });\n }\n return leaf;\n};\n","import { nanoid } from \"..\";\nimport { Map, Array } from \"yjs\";\nimport { YArray, YMap } from \"yjs/dist/src/internals\";\nimport { YLeaf } from \"../../\";\nimport { createLeaf } from \"./yLeaf\";\n\nexport type YNodeProps = {\n data?: any;\n content?: YLeaf[] | YArray<YLeaf>;\n children?: YNode[] | YArray<YNode>;\n id?: string;\n};\n\nexport const createNode = (type: string, props?: YNodeProps): YMap<any> => {\n const node = new Map();\n node.set(\"id\", props?.id || nanoid());\n node.set(\"type\", type);\n if (props?.data) {\n node.set(\"data\", new Map(Object.entries(props.data)));\n }\n node.set(\"content\", props?.content instanceof Array ? props.content : Array.from(props?.content || [createLeaf()]));\n node.set(\"children\", props?.children instanceof Array ? props.children : Array.from(props?.children || []));\n return node;\n};\n\nexport class YNode extends Map<any> {}\n","import { Doc } from \"yjs\";\nimport { YNode } from \".\";\nimport { createLeaf } from \"./yLeaf\";\nimport { createNode } from \"./yNode\";\nexport interface jsonLeaf extends Record<string, any> {\n text: string;\n data?: object;\n}\nexport type jsonNode = {\n type: string;\n content?: jsonLeaf[];\n data?: object;\n children?: jsonNode[];\n};\n\nexport const getChildren = ({ type, content = [], children = [], ...props }: jsonNode): YNode => {\n return createNode(type, { ...props, children: children.map(getChildren), content: content.map(createLeaf) });\n};\nexport class EdytorDoc extends Doc {}\n\nexport const DocFromJson = (value: jsonNode[], initialDoc?: Doc) => {\n const array = (initialDoc || new Doc()).getArray(\"children\");\n array.insert(0, value.map(getChildren));\n return array.doc;\n};\n","import { Editor, EdytorSelection } from \"../types\";\nimport {\n copyNode,\n deleteLeafText,\n getIndex,\n getNode,\n getPath,\n hasChildren,\n leafLength,\n leafNodeChildrenLength,\n leafNodeContent,\n LeavesHarvest,\n mergeContentWithNextLeaf,\n mergeContentWithPrevLeaf,\n createLeaf,\n traverse,\n isNodeContentEmpty\n} from \"../utils\";\n\ntype deleteTextOpts = {\n mode: \"forward\" | \"backward\" | \"none\";\n selection?: EdytorSelection;\n};\nexport const deleteText = (editor: Editor, { mode, selection }: deleteTextOpts) => {\n const { start, end, type, length, edges, setPosition } = selection || editor.selection;\n\n switch (type) {\n case \"collapsed\": {\n if (mode === \"backward\" && edges.startNode) {\n if (edges.startDocument) return;\n\n // unnest node if its the last of its parent and if he is nested or it's the first its the only child of its parent\n if (\n start.nodeIndex === start.node.parent.length - 1 &&\n start.path.length > 2 &&\n (start.nodeIndex !== 0 || start.node.parent.length === 1)\n ) {\n const node = copyNode(start.node);\n const nodeGrandParent = start.node.parent.parent;\n const index = getIndex(nodeGrandParent);\n start.node.parent.delete(start.nodeIndex);\n nodeGrandParent.parent.insert(index + 1, [node]);\n return setPosition(start.leafId, { offset: 0 });\n } else {\n return editor.doc.transact(() => {\n const [prevLeaf, offset] = mergeContentWithPrevLeaf(editor);\n setTimeout(() => {\n setPosition(prevLeaf.get(\"id\"), { offset });\n });\n });\n }\n }\n if (mode === \"backward\" && edges.startLeaf) {\n // delete content in the prev leaf because we are at its edge start, and escape current leaf\n const prevLeaf = leafNodeContent(start.leaf).get(start.leafIndex - 1);\n deleteLeafText(prevLeaf, leafLength(prevLeaf) - 1, length || 1);\n return setPosition(prevLeaf.get(\"id\"), { offset: leafLength(prevLeaf) });\n }\n\n if (mode === \"forward\" && edges.endNode) {\n // merge node with the next node because we are at edge end of it\n return editor.doc.transact(() => {\n mergeContentWithNextLeaf(editor);\n setTimeout(() => {\n setPosition(start.leafId, { offset: start.offset });\n });\n });\n }\n if (mode === \"forward\" && edges.endLeaf) {\n // delete content in the next leaf because we are at its edge end\n const nextLeaf = leafNodeContent(start.leaf).get(start.leafIndex + 1);\n return deleteLeafText(nextLeaf, 0, length || 1);\n }\n\n // just delete text\n deleteLeafText(start.leaf, start.offset + (mode === \"backward\" ? -length || -1 : length), length || 1);\n setPosition(start.leaf.get(\"id\"), { offset: start.offset + (mode === \"backward\" ? -length || -1 : length) });\n break;\n }\n case \"singlenode\": {\n deleteLeafText(start.leaf, start.offset, length, true);\n if (isNodeContentEmpty(start.node)) {\n leafNodeContent(start.leaf).insert(0, [createLeaf()]);\n }\n setPosition(start.leafId, { offset: start.offset });\n break;\n }\n case \"multileaves\":\n case \"multinodes\":\n {\n const startPathString = start.path.join(\",\");\n const endPathString = end.path.join(\",\");\n editor.doc.transact(() => {\n const { reap, burn } = new LeavesHarvest();\n traverse(\n editor,\n (leaf, isText) => {\n if (isText) {\n const path = getPath(leaf);\n const l = leafLength(leaf);\n if (path.join(\",\") === startPathString) {\n deleteLeafText(leaf, start.offset, l);\n reap(leaf, false);\n } else if (path > start.path && path < end.path) {\n deleteLeafText(leaf, 0, l);\n reap(leaf, true);\n } else if (path.join(\",\") === endPathString) {\n deleteLeafText(leaf, 0, end.offset);\n reap(leaf, end.offset === l);\n }\n }\n },\n { start: start.path[0], end: end.path[0] + 1 }\n );\n return burn(editor);\n });\n }\n setPosition(start.leaf.get(\"id\"), { offset: start.offset });\n break;\n }\n};\n","import { YMap, YText } from \"yjs/dist/src/internals\";\nimport { Editor, Position, EdytorSelection } from \"../types\";\nimport { mergeLeafs, splitLeaf } from \".\";\nimport {\n deleteLeafText,\n getIndex,\n getPath,\n isLeafEmpty,\n leafLength,\n leafNodeContent,\n leafText,\n createLeaf,\n traverse\n} from \"../utils\";\n\nexport type formatTextOperation = {\n at?: Position;\n value: any;\n range?: EdytorSelection;\n format: string;\n yText?: YText;\n};\nexport type formatAtEqualPathOperation = {\n format: string;\n value: any;\n start: EdytorSelection[\"start\"];\n end: EdytorSelection[\"end\"];\n length: EdytorSelection[\"length\"];\n data?: object;\n};\n\nexport const applyMarksFromParent = (parent: YMap<any>, leafs: YMap<any>[]) => {\n Array.from(parent.keys(), (key) => {\n if (key !== \"text\" && key !== \"id\" && key !== \"data\") {\n leafs.forEach((leaf) => {\n leaf.set(key, parent.get(key));\n });\n }\n });\n};\n\nexport const formatAtEqualPath = ({ format, value, start, end }: formatAtEqualPathOperation) => {\n const length = end.offset - start.offset;\n const leaf = start.leaf;\n const text = leafText(leaf);\n\n const content = text.toString();\n const index = getIndex(leaf);\n\n const isMarkActive = leaf.has(format);\n\n if (isMarkActive && leafLength(leaf) === length) {\n leaf.delete(format);\n return leaf;\n } else {\n const remainingText = content.substring(end.offset, leafLength(leaf));\n if (remainingText.length == 0 && leafLength(leaf) === end.offset - start.offset) {\n leaf.set(format, value);\n return leaf;\n } else {\n deleteLeafText(leaf, start.offset, leafLength(leaf));\n\n const formatedLeaf = createLeaf({\n ...leaf.toJSON(),\n id: undefined,\n [format]: value,\n text: content.substring(start.offset, end.offset)\n });\n\n let newLeaves = [formatedLeaf];\n\n if (remainingText.length > 0) {\n newLeaves.push(createLeaf({ ...leaf.toJSON(), id: undefined, text: remainingText }));\n }\n\n if (isMarkActive) {\n formatedLeaf.delete(format);\n }\n newLeaves.length && leafNodeContent(leaf).insert(index + 1, newLeaves);\n return formatedLeaf;\n }\n }\n};\n\nexport const formatText = (editor: Editor, mark: Record<string, any>) => {\n const [[format, value]] = Object.entries(mark);\n console.log(format);\n let newPath = 0;\n const { start, end, type, length, setPosition, selectedText } = editor.selection;\n\n editor.doc.transact(() => {\n switch (type) {\n case \"collapsed\": {\n const isMarkActive = start.leaf.has(format) && start.leaf.get(format) === value;\n if (isLeafEmpty(start.leaf)) {\n // if the leaf is empty we only toggle the mark\n isMarkActive ? start.leaf.delete(format) : start.leaf.set(format, value);\n } else {\n // if leaf is not empty we split the current leaf in half to insert an empty fragment with the desired mark\n splitLeaf(editor);\n const fragment = createLeaf({ text: \"\", [format]: value });\n // we are applying the current marks on the fragment\n applyMarksFromParent(start.leaf, [fragment]);\n // we remove the mark if its here\n if (isMarkActive) fragment.delete(format);\n // we insert the fragment after the spitted leaf\n leafNodeContent(start.leaf).insert(start.leafIndex + 1, [fragment]);\n // we remove the spitted leaf if empty\n if (isLeafEmpty(start.leaf)) {\n leafNodeContent(start.leaf).delete(start.leafIndex);\n }\n setTimeout(() => {\n setPosition(fragment.get(\"id\") as string, { offset: 0 });\n console.log(leafNodeContent(start.leaf).toJSON());\n });\n }\n\n // we merge leaves to avoid two subsequent leaves with the same marks\n mergeLeafs(leafNodeContent(start.leaf));\n break;\n }\n case \"singlenode\": {\n const formatedLeaf = formatAtEqualPath({ format, value, start, end, length });\n mergeLeafs(leafNodeContent(start.leaf));\n const isRemoved = formatedLeaf._item.deleted;\n\n if (!isRemoved) {\n setPosition(start.leaf.get(\"id\"), { offset: start.offset });\n setTimeout(() => {\n setPosition(formatedLeaf.get(\"id\"), { offset: 0, end: leafLength(formatedLeaf) });\n });\n } else {\n const remainingLeaf = formatedLeaf.parent.get(start.leafIndex - 1);\n const offset = leafText(remainingLeaf)\n .toJSON()\n .indexOf(selectedText);\n setTimeout(() => {\n setPosition(remainingLeaf.get(\"id\"), {\n offset,\n end: offset + selectedText.length\n });\n });\n }\n\n break;\n }\n case \"multileaves\":\n case \"multinodes\": {\n const startPathString = start.path.join(\",\");\n const endPathString = end.path.join(\",\");\n let started = false;\n let ended = false;\n\n traverse(\n editor,\n (leaf, isText) => {\n if (isText) {\n const path = getPath(leaf);\n const isStart = path.join(\",\") === startPathString;\n const isEnd = path.join(\",\") === getPath(end.leaf).join(\",\");\n console.log({ isEnd }, endPathString, getPath(end.leaf).join(\",\"), path.join(\",\"));\n if (isStart) {\n started = true;\n }\n\n const startOffset = isStart ? start.offset : 0;\n const endOffset = isEnd ? end.offset : leafLength(leaf);\n started &&\n !ended &&\n formatAtEqualPath({\n format,\n start: { leaf, offset: startOffset },\n end: { offset: endOffset },\n value\n });\n console.log({ ended });\n if (isEnd) {\n ended = true;\n }\n\n mergeLeafs(leafNodeContent(leaf));\n }\n },\n { start: start.path[0], end: end.path[0] + 1 }\n );\n break;\n }\n }\n });\n\n return newPath;\n};\n","import { Editor } from \"../types\";\nimport {\n deleteLeafText,\n getPath,\n insertTextInLeaf,\n leafLength,\n LeavesHarvest,\n replaceLeafText,\n traverse,\n YLeaf\n} from \"../utils\";\n\nexport type insertTextOperation = {\n text: string | null;\n};\nexport const insertText = (editor: Editor, { text }: insertTextOperation) => {\n if (!text || text === null || !text.length) return;\n\n const { start, end, type, length, setPosition } = editor.selection;\n if (type === \"notInDoc\") return console.error(\"Path is not in document space\");\n\n switch (type) {\n case \"collapsed\": {\n insertTextInLeaf(start.leaf, start.offset, text);\n setPosition(start.leaf.get(\"id\"), { offset: start.offset + text.length });\n break;\n }\n case \"singlenode\": {\n replaceLeafText(start.leaf, start.offset, length, text);\n setPosition(start.leaf.get(\"id\"), { offset: start.offset + text.length });\n break;\n }\n case \"multileaves\":\n case \"multinodes\": {\n const startPathString = start.path.join(\",\");\n const endPathString = end.path.join(\",\");\n editor.doc.transact(() => {\n const { reap, burn } = new LeavesHarvest();\n traverse(\n editor,\n (leaf, isText) => {\n if (isText) {\n const path = getPath(leaf);\n if (path.join(\",\") === startPathString) {\n replaceLeafText(leaf, start.offset, leafLength(leaf), text);\n reap(leaf);\n } else if (path > start.path && path < end.path) {\n deleteLeafText(leaf, 0, leafLength(leaf));\n reap(leaf);\n } else if (path.join(\",\") === endPathString) {\n deleteLeafText(leaf, 0, end.offset);\n reap(leaf);\n }\n }\n },\n { start: start.path[0], end: end.path[0] + 1 }\n );\n burn(editor);\n });\n setPosition(start.leaf.get(\"id\"), { offset: start.offset + text.length });\n }\n }\n};\n","import { YArray, YMap } from \"yjs/dist/src/internals\";\nimport { getIndex } from \"../utils\";\n\nexport const areLeafsMergeable = (nodes: YMap<any>[]) => {\n let keys = nodes.map((node) => Array.from(node.keys())).flat();\n return nodes.every((node) => {\n return keys.every((key) => node.has(key));\n });\n};\n\nexport const mergeLeafs = (leafs: YArray<YMap<any>>) => {\n let currentLeaf = leafs.get(0);\n let leafsToDelete = [] as YMap<any>[];\n leafs.forEach((_, i) => {\n const leaf = leafs.get(i + 1);\n if (!leaf) return;\n\n if (areLeafsMergeable([currentLeaf, leaf])) {\n const firstText = currentLeaf.get(\"text\");\n currentLeaf.get(\"text\").insert(firstText.length, leaf.get(\"text\").toString());\n leafsToDelete.push(leaf);\n } else {\n currentLeaf = leaf;\n }\n });\n\n leafsToDelete.forEach((leaf) => {\n leafs.delete(getIndex(leaf));\n });\n};\n","import { Editor } from \"../types\";\nimport { createLeaf, deleteLeafText, leafNodeContent, leafString } from \"../utils\";\nexport const splitLeaf = (editor: Editor) => {\n const {\n start: { leaf, leafIndex, offset }\n } = editor.selection;\n const content = leafString(leaf);\n const rightText = content.substring(offset, content.length);\n if (offset === content.length) return;\n deleteLeafText(leaf, offset, rightText.length);\n leafNodeContent(leaf).insert(leafIndex + 1, [createLeaf({ ...leaf.toJSON(), text: rightText, id: undefined })]);\n};\n","import { YArray, YText } from \"yjs/dist/src/internals\";\nimport { Editor, Position, EdytorSelection } from \"../types\";\nimport { deleteText } from \".\";\nimport { YNode, YLeaf } from \"..\";\nimport {\n leafNodeContent,\n leafString,\n leafLength,\n deleteLeafText,\n leafNode,\n getIndex,\n leafNodeContentLength,\n hasChildren,\n getNodeChildren,\n createLeaf,\n createNode\n} from \"../utils\";\n\nexport type splitNodeOperation = {\n at: Position;\n range?: EdytorSelection;\n yText?: YText;\n};\n\nexport const splitNode = (editor: Editor) => {\n const { start, end, type, length, setPosition, edges } = editor.selection;\n\n const leaf = start.leaf;\n const leafContent = leafNodeContent(start.leaf);\n const node = leafNode(start.leaf);\n\n const indexOfLeaf = getIndex(start.leaf);\n const indexOfNode = getIndex(node);\n\n const split = () => {\n const nextLeaves = leafContent.toArray().filter((_, i) => i > indexOfLeaf);\n\n const rightText = leafString(start.leaf).substring(start?.offset, leafLength(start.leaf));\n deleteLeafText(start.leaf, start?.offset, rightText.length, false);\n\n const newParent = hasChildren(node) ? getNodeChildren(node) : (node.parent as YArray<any>);\n const newLeaf = createLeaf({ ...leaf.toJSON(), id: undefined, text: rightText });\n newParent.insert(hasChildren(node) ? 0 : indexOfNode + 1, [\n createNode(editor.defaultBlock, {\n children: [],\n content: [newLeaf].concat(nextLeaves.map((leaf) => createLeaf(leaf.toJSON())))\n })\n ]);\n setPosition(newLeaf.get(\"id\") as string, { offset: 0 });\n leafContent.delete(indexOfLeaf + 1, leafNodeContentLength(start.leaf) - indexOfLeaf - 1);\n };\n\n let doSplit = (!edges.startNode || !edges.endNode) && type !== \"multinodes\";\n\n if ((edges.endNode || edges.startNode) && type === \"collapsed\") {\n // if cursor is at edge node with insert a default block before of after the current node\n const newNode = createNode(editor.defaultBlock);\n (node.parent as YArray<any>).insert(indexOfNode + (edges.endNode ? 1 : 0), [newNode]);\n return setTimeout(() => {\n setPosition(\n newNode\n .get(\"content\")\n .get(0)\n .get(\"id\"),\n { offset: 0 }\n );\n });\n }\n\n switch (type) {\n case \"collapsed\": {\n doSplit && split();\n break;\n }\n case \"singlenode\": {\n deleteText(editor, { mode: \"backward\" });\n doSplit && split();\n !doSplit && setPosition(start.leaf.get(\"id\"), { offset: start.offset });\n\n break;\n }\n case \"multileaves\":\n case \"multinodes\": {\n deleteText(editor, { mode: \"backward\" });\n doSplit && split();\n !doSplit && setPosition(start.leaf.get(\"id\"), { offset: start.offset });\n }\n }\n};\n","import { Editor, getNode, getNodeContainer, getPath } from \"..\";\nimport { copyNode, getNodeAtPath, traverse } from \"../utils\";\n\nexport const nestNode = (editor: Editor) => {\n const { start, type, end, setPosition } = editor.selection;\n\n const startNode = getNode(start.leaf);\n const nodeCopy = copyNode(startNode);\n const startPath = getPath(startNode);\n const [index, ...newPath] = startPath.slice().reverse();\n const prevNode = getNodeAtPath(editor, [...newPath, index - 1]);\n const startContainer = getNodeContainer(startNode);\n switch (type) {\n case \"singlenode\":\n case \"collapsed\": {\n if (!prevNode) return;\n const id = start.leaf.get(\"id\");\n const prevChildren = prevNode.get(\"children\");\n startContainer.delete(index);\n prevChildren.insert(prevChildren.length, [nodeCopy]);\n setPosition(id, { offset: start.offset });\n break;\n }\n case \"multileaves\":\n case \"multinodes\": {\n let length = 0;\n let newNodes = [];\n const id = start.leaf.get(\"id\");\n const startPathString = start.path.slice(0, start.path.length - 1).join(\"\");\n const endPathString = end.path.slice(0, start.path.length - 1).join(\"\");\n traverse(\n editor,\n (node, isText) => {\n if (!isText) {\n const path = getPath(node).join(\"\");\n if (path.length === startPath.length) {\n if (path <= endPathString && path >= startPathString) {\n length++;\n newNodes.push(copyNode(node));\n }\n }\n }\n },\n { start: start.path[0], end: end.path[0] + 1 }\n );\n if (!prevNode) return;\n\n const prevChildren = prevNode.get(\"children\");\n\n startContainer.delete(index, length);\n prevChildren.insert(prevChildren.length, newNodes);\n setPosition(id, { offset: start.offset });\n break;\n }\n }\n};\n","import { getIndex } from \"..\";\nimport { YArray } from \"../../../../node_modules/yjs/dist/src/internals\";\nimport { copyNode } from \"../utils\";\n\nexport type moveNodeOperation = {\n from: {\n container: YArray<any> | any;\n at: number | number[];\n };\n to: {\n container: YArray<any>;\n at: number;\n };\n};\nexport const moveNode = ({ from, to }: moveNodeOperation) => {\n const indexes = Array.isArray(from.at) ? from.at : [from.at];\n const [firstIndex] = indexes;\n const firstNode = from.container.get(firstIndex);\n\n const nodesCopies = indexes.map((index) => {\n const node = from.container.get(index);\n return copyNode(node);\n });\n\n to.container.insert(to.at, nodesCopies);\n from.container.delete(getIndex(firstNode), indexes.length);\n return nodesCopies[0]\n .get(\"content\")\n .get(0)\n .get(\"id\");\n};\n","import { YArray, YMap } from \"yjs/dist/src/internals\";\nimport { mergeLeafs } from \"../operations\";\nimport { Editor } from \"../types\";\nimport { getIndex, getNode, traverse } from \"./common\";\nimport { leafLength, leafNodeContent, leafNodeContentLength, leafString } from \"./leaves\";\nimport { createLeaf, createNode, getChildren, YNode } from \"./yClasses\";\n\nexport const mergeContentWithPrevLeaf = (editor: Editor) => {\n const { start } = editor.selection;\n let prevLeaf;\n let stop = false;\n\n traverse(editor, (node, isText) => {\n if (isText) {\n if (node === start.leaf) {\n stop = true;\n } else if (!stop) {\n prevLeaf = node;\n }\n }\n });\n if (!prevLeaf) return;\n const prevLeafLength = leafLength(prevLeaf);\n leafNodeContent(prevLeaf).insert(\n leafNodeContentLength(prevLeaf),\n leafNodeContent(start.leaf)\n .toArray()\n .map((leaf: YMap<any>) => {\n return createLeaf(leaf.toJSON());\n })\n );\n mergeLeafs(leafNodeContent(prevLeaf));\n\n const children = start.node\n .get(\"children\")\n .toArray()\n .map(copyNode);\n if (children.length) {\n start.node.parent.insert(start.nodeIndex, children);\n }\n start.node.parent.delete(start.nodeIndex + children.length);\n return [prevLeaf, prevLeafLength];\n // (start.leaf.parent.parent as YArray<YNode>).delete(index);\n};\n\nexport const mergeContentWithNextLeaf = (editor: Editor) => {\n const { start } = editor.selection;\n\n // 1 .get the next leaf\n let nextLeaf;\n let stop = false;\n\n traverse(editor, (node, isText) => {\n if (isText) {\n if (node === start.leaf) {\n stop = true;\n } else if (stop) {\n nextLeaf = node;\n stop = false;\n }\n }\n });\n // end of document do nothing\n if (!nextLeaf) return;\n\n // 2 .merge the next leaf with the start leaf\n leafNodeContent(start.leaf).insert(\n leafNodeContentLength(start.leaf),\n leafNodeContent(nextLeaf)\n .toArray()\n .map((leaf: YMap<any>) => {\n return createLeaf(leaf.toJSON());\n })\n );\n mergeLeafs(leafNodeContent(start.leaf));\n\n // 3 get the merged node children if any and place it where the merged node was\n const node = getNode(nextLeaf);\n const index = getIndex(node);\n const parent = node.parent as YArray<any>;\n const children = node.get(\"children\").toArray();\n children.length > 0 && parent.insert(index, children.map(copyNode));\n parent.delete(index + children.length);\n return nextLeaf;\n};\n\nexport const deleteNode = (node, defaultBlock: string) => {\n if (isNodeEmpty(node)) {\n (node.parent as YArray<YNode>).delete(getIndex(node));\n } else if (isNodeContentEmpty(node)) {\n const children = getNodeChildren(node).toJSON();\n const index = getIndex(node);\n node.parent.delete(index);\n node.parent.insert(\n index,\n children.map(({ type, ...props }) => createNode(type, props))\n );\n }\n if (node.parent === (node.doc.getArray(\"children\") && node.doc.getArray(\"children\").length === 0)) {\n (node.parent as YArray<YNode>).insert(0, [createNode(defaultBlock, { content: [createLeaf()] })]);\n }\n};\n\nexport const getNodeContainer = (node) => node.parent as YArray<YNode>;\nexport const getNodeChildren = (node) => node.get(\"children\") as YArray<YNode>;\nexport const getNodeContent = (node) => node.get(\"content\") as YArray<YNode>;\nexport const hasChildren = (node) => getNodeChildren(node).length > 0;\nexport const isNodeEmpty = (node) => isNodeContentEmpty(node) && !hasChildren(node);\nexport const isNodeContentEmpty = (node) =>\n getNodeContent(node).length === 0 ||\n getNodeContent(node)\n .toArray()\n .map(leafString)\n .join(\"\").length === 0;\n\nexport const copyNode = (node: YNode) => {\n const jsonNode = node.toJSON();\n return createNode(jsonNode.type, {\n ...jsonNode,\n children: jsonNode.children.map(getChildren),\n content: jsonNode.content.map(createLeaf)\n });\n};\n\nexport const nodeString = (node: YNode) => {\n let text = \"\";\n getNodeContent(node).forEach((leaf) => {\n text += leafString(leaf);\n });\n getNodeChildren(node).forEach((node) => {\n text += nodeString(node);\n });\n return text;\n};\n","import { customAlphabet } from \"nanoid\";\nimport { YArray, YMap } from \"yjs/dist/src/internals\";\nimport { Editor, EditorWithChildren, YLeaf } from \"../types\";\nimport { leafString } from \"./leaves\";\nimport { getNodeChildren, getNodeContent, nodeString } from \"./nodes\";\n\nexport const nanoid = () => \"y-\" + customAlphabet(\"346789ABCDEFGHJKLMNPQRTUV-WXYabcdefghijkmnpqrtwxyz\", 20)();\n\ntype YNode = YMap<any>;\n\nexport const getNode = (node): YNode => node?.parent?.parent as YNode;\n\nexport const getIndex = (node: YNode): number => {\n let index = 0;\n let stop = false;\n let n = node.parent._start;\n while (n !== null && !stop) {\n if (n.countable && !n.deleted) {\n const c = n.content.getContent();\n for (let i = 0; i < c.length; i++) {\n if (c[i] === node) {\n stop = true;\n break;\n }\n index++;\n }\n }\n n = n.right;\n }\n return index;\n};\n\nexport const getPath = (node: YNode): number[] => {\n let p = [] as number[];\n let n = node;\n while (!!n) {\n p.push(getIndex(n));\n n = getNode(n);\n }\n return p.reverse();\n};\n\nexport const getId = (node): string => node.get(\"id\");\n\nexport const getLeafAtPath = (editor: Editor | EditorWithChildren, [start, ...path]: number[]): YLeaf => {\n let node = editor.children.get(start);\n let i = 0;\n while (i < path.length - 1) {\n const index = path[i];\n i++;\n node = node.get(\"children\").get(index);\n }\n\n return node && node.get(\"content\").get(path.slice().reverse()[0]);\n};\nexport const getNodeAtPath = (editor: Editor, [start, ...path]: number[]): YNode => {\n let node = editor.children.get(start);\n for (let i = 0; i < path.length; i++) {\n const index = path[i];\n if (node.get) {\n node = node.get(\"children\").get(index);\n } else {\n node = undefined;\n }\n }\n return node;\n};\nexport const getContainerAtPath = (editor: Editor, path: number[]): YArray<any> => {\n if (path.length === 1) {\n return editor.children;\n } else {\n return getNodeAtPath(editor, path.slice(1, path.length)).get(\"children\");\n }\n};\nexport const traverse = (\n editor: Editor | EditorWithChildren,\n cb: (node: YMap<any>, isText: boolean, path: number[]) => void,\n opts?: {\n start?: number;\n end?: number;\n }\n) => {\n const t = (node: YNode | YLeaf, path: number[]) => {\n if (node.has(\"text\")) {\n cb(node, true, path);\n } else {\n const array = getNodeContent(node)\n .toArray()\n //@ts-ignore\n .concat(getNodeChildren(node).toArray());\n cb(node, false, path);\n\n for (let i = 0; i < array.length; i++) {\n t(array[i], [...path.slice(0, path.length - 1), 0, i]);\n }\n }\n };\n const array = editor.children.toArray().slice(opts?.start || 0, opts?.end || editor.children.length) as YNode[];\n for (let i = 0; i < array.length; i++) {\n t(array[i], [i + (opts?.start || 0)]);\n }\n};\n\nexport const toString = (editor: Editor | EditorWithChildren): string => {\n let t = \"\";\n const array = editor.children.toArray() as YNode[];\n for (let i = 0; i < array.length; i++) {\n t += nodeString(array[i]);\n }\n return t;\n};\n","import { YArray, YMap, YText } from \"yjs/dist/src/internals\";\nimport { Editor } from \"../types\";\nimport { getIndex } from \"./common\";\nimport { deleteNode } from \"./nodes\";\nimport { YLeaf, YNode } from \"./yClasses\";\n\nexport class LeavesHarvest {\n leaves: { [id: string]: { shouldDeleteNode: boolean; content: YArray<YLeaf>; node: YMap<any>; indexes: number[] } };\n constructor() {\n this.leaves = {};\n }\n\n reap = (leaf, shouldDeleteNode = false) => {\n if (!isLeafEmpty(leaf)) return;\n const id = leafNodeId(leaf);\n if (!this.leaves[id]) {\n this.leaves[id] = {\n shouldDeleteNode,\n content: leafNodeContent(leaf),\n node: leafNode(leaf),\n indexes: []\n };\n }\n\n this.leaves[id].indexes.push(getIndex(leaf));\n };\n\n burn = (editor: Editor) => {\n Object.values(this.leaves).forEach(({ shouldDeleteNode, content, node, indexes }, i) => {\n content.delete(indexes[0], indexes.length);\n if (content.length === 0 && !shouldDeleteNode) {\n content.insert(0, [createLeaf()]);\n } else if (shouldDeleteNode) return deleteNode(node, editor?.defaultBlock);\n });\n };\n}\n\nexport const leafData = (leaf): YMap<any> => leaf.get(\"data\");\nexport const leafText = (leaf): YText => leaf.get(\"text\");\nexport const leafLength = (leaf): number => leafText(leaf).length;\nexport const leafString = (leaf): string => leafText(leaf).toString();\n\nexport const isLeafEmpty = (leaf) => leafText(leaf) === undefined || leafLength(leaf) === 0;\nexport const deleteLeafText = (leaf, index: number, length: number, shouldRemoveIfEmpty?: boolean) => {\n leafText(leaf).delete(index, length);\n\n shouldRemoveIfEmpty && removeIfEmpty(leaf);\n};\nexport const insertTextInLeaf = (leaf, index: number, text) => {\n leafText(leaf).insert(index, text);\n};\nexport const replaceLeafText = (leaf, start: number, length: number, text: string) => {\n const currentText = leafString(leaf).split(\"\");\n currentText.splice(start, length, ...text.split(\"\"));\n return setLeafText(leaf, currentText.join(\"\"));\n};\nexport const setLeafText = (leaf, text: string) => {\n const t = leafText(leaf);\n t.delete(0, t.length);\n t.insert(0, text);\n};\n\nexport const setLeafData = (leaf, data: object) => {\n if (leaf.has(\"data\")) {\n Object.keys(data).forEach((key) => {\n leafData(leaf).set(key, data[key]);\n });\n } else {\n leaf.set(\"data\", new Map(Object.entries(data)));\n }\n};\n\nexport const removeIfEmpty = (leaf) => {\n if (isLeafEmpty(leaf)) {\n console.log(\"isEmpty\", leafNodeContent(leaf).toJSON());\n leafNodeContent(leaf).delete(getIndex(leaf));\n // if (leafNodeContentLength(leaf) === 0) {\n // deleteNode(leafNode(leaf));\n // }\n }\n};\n\nexport const leafNode = (leaf): YNode => leaf.parent.parent as YNode;\nexport const leafNodeId = (leaf): string => leafNode(leaf).get(\"id\");\n\nexport const leafNodeContent = (leaf): YArray<YLeaf> => leaf.parent as YArray<YLeaf>;\n\nexport const leafNodeContentLength = (leaf): number => leafNodeContent(leaf).length;\nexport const leafNodeContentStringLength = (leaf): number =>\n leafNodeContent(leaf)\n .toArray()\n .reduce((acc, leaf) => acc + leafLength(leaf), 0);\n\nexport const leafNodeChildren = (leaf): YArray<YNode> => leafNode(leaf).get(\"children\") as YArray<YNode>;\n\nexport const leafNodeChildrenLength = (leaf): number => leafNodeChildren(leaf).length;\n","import { replaceLeafText } from \"../utils\";\nimport { onBeforeInputData } from \"../types\";\nimport { splitNode, insertText, deleteText, formatText } from \"../operations\";\n\nconst prevent = (e: any) => {\n e.preventDefault();\n e.stopPropagation();\n};\n\nconst getDataTransfer = (e: any): string => e.dataTransfer.getData(\"text/plain\");\n\nexport const onBeforeInput = ([doc, onChange, editor]: onBeforeInputData, e: InputEvent) => {\n // console.log(e);\n const { start, length, setPosition } = editor.selection;\n\n // if (e.composedPath().some((el) => el.getAttribute && el.getAttribute(\"data-edytor-void\") === \"true\")) {\n // return;\n // }\n const tag = e.target?.tagName;\n if (tag === \"TEXTAREA\" || tag === \"INPUT\") return;\n prevent(e);\n switch (e.inputType) {\n case \"insertFromPaste\":\n case \"insertLineBreak\":\n // case \"insertCompositionText\":\n // case \"insertFromDrop\":\n case \"insertText\": {\n const text =\n e.inputType === \"insertLineBreak\"\n ? \"\\n\"\n : e.inputType === \"insertFromPaste\"\n ? getDataTransfer(e)\n : (e.data as string);\n\n insertText(editor, {\n text\n });\n\n break;\n }\n case \"deleteContentBackward\": {\n deleteText(editor, { mode: \"backward\" });\n\n break;\n }\n case \"deleteByDrag\":\n case \"deleteByCut\":\n case \"deleteContentForward\": {\n deleteText(editor, { mode: \"forward\" });\n break;\n }\n\n case \"insertParagraph\": {\n splitNode(editor);\n break;\n }\n\n case \"insertFromDrop\": {\n setTimeout(() => {\n const text = getDataTransfer(e);\n if (text) {\n insertText(editor, {\n text\n });\n }\n }, 50);\n break;\n }\n case \"deleteSoftLineBackward\": {\n break;\n }\n case \"deleteWordForward\": {\n break;\n }\n case \"insertFromYank\": {\n break;\n }\n case \"formatSetBlockTextDirection\": {\n break;\n }\n case \"formatSetInlineTextDirection\": {\n break;\n }\n case \"deleteWordBackward\": {\n break;\n }\n case \"insertCompositionText\": {\n break;\n }\n case \"formatItalic\":\n case \"formatBold\": {\n break;\n }\n\n case \"insertReplacementText\": {\n replaceLeafText(start.leaf, start.offset, length, getDataTransfer(e));\n setPosition(start.leafId, { offset: start.offset });\n }\n }\n\n onChange && onChange(editor);\n};\n","import { moveNode } from \"../operations\";\nimport { Editor, EdytorSelection } from \"../types\";\nimport { getIndex, getPath } from \"./common\";\nimport { EdytorDoc } from \"./yClasses\";\n\nexport class Dropper {\n from;\n to;\n node;\n startPath;\n container: HTMLDivElement;\n editor: Editor;\n doc: EdytorDoc;\n editorId: string;\n ID_TO_NODE: Map<any, any>;\n selection: EdytorSelection;\n allowNesting: boolean;\n\n init = (editor, container) => {\n this.editor = editor;\n this.doc = editor.doc;\n this.container = container;\n this.editorId = editor.editorId;\n this.selection = editor.selection;\n this.ID_TO_NODE = editor.ID_TO_NODE;\n this.allowNesting = editor.allowNesting;\n };\n startDrag = (node, e: DragEvent) => {\n if (!this.editor.dnd.active) return;\n this.node = node;\n const dndIndicator = document.getElementById(\"dndIndicator\");\n dndIndicator.style.opacity = \"1\";\n\n const element = document.getElementById(node.get(\"id\")) as HTMLElement;\n element.style.opacity = \"0.4\";\n document.body.style.cursor = \"grabbing\";\n\n this.from = {\n container: node.parent,\n at: getIndex(node)\n };\n this.startPath = getPath(node);\n e.dataTransfer?.setDragImage(element, e.offsetX, e.offsetY);\n document.addEventListener(\"mousemove\", this.onDrag);\n document.addEventListener(\"mouseup\", this.dragEnd);\n };\n dragEnd = () => {\n const element = document.getElementById(this.node.get(\"id\")) as HTMLElement;\n if (element) element.style.opacity = \"1\";\n document.body.style.cursor = \"auto\";\n document.removeEventListener(\"mousemove\", this.onDrag);\n document.removeEventListener(\"mouseup\", this.dragEnd);\n const id = moveNode({ from: this.from, to: this.to });\n const dndIndicator = document.getElementById(\"dndIndicator\");\n dndIndicator.style.opacity = \"0\";\n setTimeout(() => {\n console.log(id);\n this.selection.setPosition(id, { offset: 0 });\n });\n };\n\n getHoveredNode = (target: HTMLElement) => {\n let hoveredNode;\n let element = target;\n let i = 0;\n while (!hoveredNode && element?.id !== this.editorId && element && i < 100) {\n if (element.hasAttribute(\"data-edytor-block\")) {\n hoveredNode = this.ID_TO_NODE.get(element.id);\n break;\n }\n element = element.parentElement;\n i++;\n }\n if (!hoveredNode) return {};\n\n return { hoveredElement: element, hoveredNode };\n };\n onDrag = (e: MouseEvent) => {\n if (!this.editor.dnd.active) return;\n const { hoveredElement, hoveredNode } = this.getHoveredNode(e.target as HTMLElement);\n const dndIndicator = document.getElementById(\"dndIndicator\");\n\n if (!hoveredNode || !hoveredElement || !dndIndicator || hoveredNode === this.node) return;\n const rectHovered = hoveredElement.getBoundingClientRect();\n const isOnTop = e.y < rectHovered.top + rectHovered.height / 2;\n const rect = rectHovered;\n const isNested = this.allowNesting && !isOnTop && e.x > rect.left + rect.width / 5;\n\n const top = isOnTop ? rect.top : rect.top + rect.height;\n const deltaX = isNested ? 30 : 0;\n\n let path = getPath(hoveredNode);\n\n let [index, ...startOfPath] = path.slice().reverse();\n\n if (this.startPath.join(\"\") === startOfPath.join(\"\")) {\n return;\n // this.to= undefined\n }\n\n dndIndicator.style.width = `${rect.width - deltaX}px`;\n dndIndicator.style.top = `${top + window.pageYOffset}px`;\n dndIndicator.style.left = `${rect.left + deltaX}px`;\n\n index = index + (isOnTop ? 0 : 1);\n if (index === -1) index = 0;\n this.to = {\n container: isNested ? hoveredNode.get(\"children\") : path.length === 1 ? this.editor.children : hoveredNode.parent,\n at: isNested ? 0 : index\n };\n };\n}\n","import { Editor, Position, YLeaf } from \"../types\";\nimport { getIndex, getPath, leafLength, leafNode, leafNodeContentLength, YNode } from \".\";\n\nexport class EdytorSelection {\n editor: Editor;\n observers: ((selection: EdytorSelection) => void)[];\n container: HTMLDivElement;\n collaborationPosition: {\n node: string;\n leaf: string;\n offset: number;\n };\n start: Position;\n end: Position;\n selectedText: string;\n arePathsEquals: boolean;\n editorOffset: number;\n length: number;\n range?: Range;\n boundingRect?: DOMRect;\n edges: {\n startDocument: boolean;\n endDocument: boolean;\n startLeaf: boolean;\n startNode: boolean;\n endLeaf: boolean;\n endNode: boolean;\n };\n selection?: Selection;\n focused: boolean;\n type?: \"multinodes\" | \"collapsed\" | \"singlenode\" | \"multileaves\" | \"notInDoc\";\n\n constructor() {\n this.observers = [];\n }\n init = (editor: Editor, container) => {\n this.container = container;\n this.editor = editor;\n document.addEventListener(\"selectionchange\", this.onSelection);\n this.container.addEventListener(\"focus\", this.onFocus);\n this.container.addEventListener(\"blur\", this.onBlur);\n };\n onFocus = () => {\n this.focused = true;\n this.onChange();\n };\n\n onBlur = () => {\n this.focused = false;\n this.onChange();\n };\n destroy = () => {\n document.removeEventListener(\"selectionchange\", this.onSelection);\n };\n onSelection = (e: any) => {\n if (e.target?.activeElement === this.container) this.getRange();\n };\n observe = (observer) => {\n this.observers = this.observers ? this.observers.concat(observer) : [observer];\n };\n unobserve = (observer) => {\n this.observers = this.observers ? this.observers.filter((o) => o !== observer) : [];\n };\n\n getLeaf = (\n anchorNode: HTMLElement,\n current: \"anchorNode\" | \"focusNode\"\n ): [YLeaf | undefined, YNode | undefined, number[], HTMLElement | undefined] => {\n if (this[current] && this[current].node === anchorNode) {\n // serve cached result to avoid loops to getPath and node\n return this[current].value;\n }\n\n let leaf;\n let node = anchorNode;\n\n while (!leaf && node !== this.container && node) {\n leaf = this.editor.ID_TO_NODE.get(node.id);\n if (!leaf) {\n node = node.parentElement;\n }\n }\n\n if (!leaf) return [undefined, undefined, undefined, undefined];\n const value = [leaf, leafNode(leaf), getPath(leaf), node];\n this[current] = { value, node: anchorNode };\n return value as [YLeaf, YNode, number[], HTMLElement];\n };\n\n getNodeBoundingRect = (node: YNode): { nodeHtml: HTMLElement } => {\n const nodeHtml = this.container.querySelector(`#${node.get(\"id\")}`) as HTMLElement;\n return { nodeHtml };\n };\n getRange = (): EdytorSelection => {\n const selection = window.getSelection();\n const { anchorNode, focusNode, anchorOffset, focusOffset, isCollapsed, rangeCount } = selection;\n\n if (focusNode === null) return;\n const [leaf1, node1, path1, leafHtml1] = this.getLeaf(anchorNode as HTMLElement, \"anchorNode\");\n const [leaf2, node2, path2, leafHtml2] = this.getLeaf(focusNode as HTMLElement, \"focusNode\");\n\n if (!leaf1) return;\n const equalPaths = path1.join(\"\") === path2.join(\"\");\n const isFollowing = equalPaths ? anchorOffset < focusOffset : path1.join() < path2.join();\n const range = rangeCount >= 1 ? selection?.getRangeAt(0) : undefined;\n\n this.start = {\n ...this.getNodeBoundingRect(isFollowing ? node1 : node2),\n node: isFollowing ? node1 : node2,\n leafId: (isFollowing ? leaf1 : leaf2).get(\"id\"),\n leafIndex: isFollowing ? path1[path1.length - 1] : path2[path2.length - 1],\n nodeIndex: isFollowing ? path1[path1.length - 2] : path2[path2.length - 2],\n path: isFollowing ? path1 : path2,\n leafHtml: isFollowing ? leafHtml1 : leafHtml2,\n offset: isFollowing ? anchorOffset : focusOffset,\n leaf: isFollowing ? leaf1 : leaf2\n } as Position;\n\n this.end =\n isCollapsed || node2 === null\n ? this.start\n : {\n ...this.getNodeBoundingRect(!isFollowing ? node1 : node2),\n node: !isFollowing ? node1 : node2,\n leafId: (!isFollowing ? leaf1 : leaf2).get(\"id\"),\n leafIndex: !isFollowing ? path1[path1.length - 1] : path2[path2.length - 1],\n nodeIndex: !isFollowing ? path1[path1.length - 2] : path2[path2.length - 2],\n path: !isFollowing ? path1 : path2,\n leafHtml: !isFollowing ? leafHtml1 : leafHtml2,\n offset: !isFollowing ? anchorOffset : focusOffset,\n leaf: !isFollowing ? leaf1 : leaf2\n };\n this.selectedText = range ? range.toString() : \"\";\n this.arePathsEquals = equalPaths;\n this.length = this.selectedText.length;\n this.range = range;\n this.selection = selection;\n const startNode = this.start.offset === 0 && getIndex(this.start.leaf) === 0;\n const endNode =\n this.end.offset === leafLength(this.end.leaf) &&\n getIndex(this.start.leaf) === leafNodeContentLength(this.end.leaf) - 1;\n this.edges = {\n startLeaf: this.start.offset === 0,\n endLeaf: this.end.offset === leafLength(this.end.leaf),\n startNode,\n endNode,\n startDocument: startNode && this.start.path.join(\"\") === \"00\",\n endDocument: false\n };\n\n this.type = isCollapsed\n ? \"collapsed\"\n : equalPaths\n ? \"singlenode\"\n : this.start.node === this.end.node\n ? \"multileaves\"\n : \"multinodes\";\n this.onChange();\n };\n\n onChange = () => {\n this.observers.forEach((o) => o(this));\n // console.log(this.editor.awareness);\n // if (this.collaborationPosition?.node !== this.start.node.get(\"id\")) {\n // this.collaborationPosition = {\n // node: this.start.node.get(\"id\"),\n // leaf: this.start.leaf.get(\"id\"),\n // offset: this.start.offset\n // };\n // this.editor.awareness.setLocalStateField(\"position\", this.collaborationPosition);\n // }\n };\n\n setPosition = (\n id: string,\n { offset, delta, end }: { offset?: number; delta?: number; end?: number; select?: boolean }\n ) => {\n let node = this.container.querySelector(`#${id}`) as ChildNode;\n console.log({ node });\n while (node && node.nodeType !== 3 && node?.firstChild) {\n node = node.firstChild;\n }\n\n const pos = offset || this.start?.offset + delta;\n const hasRange = this.range || this.selection;\n if (!hasRange) {\n this.range = document.createRange();\n this.selection = window.getSelection();\n }\n this.range.setStart(node, pos);\n if (end) {\n this.range.setEnd(node, end);\n } else {\n this.range.collapse(true);\n }\n\n this.selection?.removeAllRanges();\n this.selection?.addRange(this.range);\n\n this.start = {\n ...this.start,\n leafHtml: this.container.querySelector(`#${id}`),\n offset: offset || this.start?.offset + delta\n };\n };\n}\n","import { Doc } from \"yjs\";\nimport { WebsocketProvider } from \"y-websocket\";\n\nexport const createWSProvider = (room?) => {\n return new Promise((res) => {\n const doc = new Doc();\n const dev = \"ws://localhost:1234\";\n const prod = \"wss://edytor-production.up.railway.app\";\n console.log(process.env.NODE_ENV);\n const provider = new WebsocketProvider(process.env.NODE_ENV === \"production\" ? prod : prod, room || \"edytor\", doc, {\n connect: true\n });\n provider.on(\"status\", ({ status }) => {\n if (status === \"connected\") {\n return res(provider);\n }\n });\n });\n};\n","import { Editor } from \"../types\";\nimport isHotkey from \"is-hotkey\";\nimport { formatText, nestNode } from \"../operations\";\n\nexport const onKeyDown = (editor: Editor, e: KeyboardEvent) => {\n if (e.key === \"Tab\") {\n e.preventDefault();\n editor.allowNesting && nestNode(editor);\n }\n if (e.metaKey) {\n if (e.key === \"z\" && e.metaKey) {\n e.preventDefault();\n return editor.undoManager.undo();\n }\n if (e.key === \"Z\" && e.metaKey && e.shiftKey) {\n e.preventDefault();\n return editor.undoManager.redo();\n }\n\n if (editor.hotkeys) {\n for (let i = 0; i < editor.hotkeys.length; i++) {\n const { keys, operation, mark } = editor.hotkeys[i];\n if (isHotkey(keys, e)) {\n e.preventDefault();\n e.stopPropagation();\n if (typeof operation === \"function\") {\n return operation(editor);\n }\n switch (operation) {\n case \"formatText\": {\n return formatText(editor, mark);\n }\n }\n break;\n }\n }\n }\n }\n};\n\nexport const defaultHotkeys = [\n { operation: \"formatText\", keys: \"mod+b\", mark: { bold: true } },\n { operation: \"formatText\", keys: \"mod+i\", mark: { italic: true } },\n { operation: \"formatText\", keys: \"mod+u\", mark: { underline: true } },\n { operation: \"formatText\", keys: \"mod+shift+c\", mark: { code: true } },\n { operation: \"formatText\", keys: \"mod+shift+x\", mark: { strikethrough: true } },\n { operation: \"formatText\", keys: \"mod+shift+h\", mark: { highlight: true } }\n];\n","import { Editor } from \"../types\";\n\nexport const onDrop = (editor: Editor, e: DragEvent) => {\n if (e.dataTransfer?.files.length > 0) {\n e.preventDefault();\n console.log(e.dataTransfer?.files);\n }\n};\nexport const onDragOver = (editor: Editor, e: DragEvent) => {\n e.preventDefault();\n\n if (e.dataTransfer?.files.length > 0) {\n e.preventDefault();\n console.log(e.dataTransfer?.files);\n }\n};\n","import { YText, YArray, YMap } from \"yjs/dist/src/internals\";\n\nexport const removeEmptyText = (yText: YText) => {\n let array = yText?.parent?.parent as YArray<YMap<any>> | undefined;\n const index = (array: YArray<any>, node: YMap<any>) => array?.toArray().indexOf(node);\n array?.delete(index(array, yText.parent as YMap<any>)!);\n while (array && array.length === 0) {\n const pop = array.parent as YMap<any>;\n const pop_pop = pop.parent as YArray<YMap<any>>;\n if (pop_pop) {\n const i = index(pop_pop, pop);\n i !== -1 && pop_pop.delete(i);\n array = pop_pop;\n } else {\n array = undefined;\n }\n }\n};\n"],"names":["createLeaf","props","leaf","Map","set","id","nanoid","Text","text","data","marks","Object","entries","keys","forEach","mark","createNode","type","node","content","Array","from","children","YNode","getChildren","map","EdytorDoc","Doc","deleteText","editor","mode","selection","start","end","length","edges","setPosition","startNode","startDocument","nodeIndex","parent","path","copyNode","nodeGrandParent","index","getIndex","insert","leafId","offset","doc","transact","mergeContentWithPrevLeaf","prevLeaf","setTimeout","get","startLeaf","leafNodeContent","leafIndex","deleteLeafText","leafLength","endNode","mergeContentWithNextLeaf","endLeaf","nextLeaf","isNodeContentEmpty","startPathString","join","endPathString","LeavesHarvest","reap","burn","traverse","isText","getPath","l","applyMarksFromParent","leafs","key","formatAtEqualPath","format","value","leafText","toString","isMarkActive","has","remainingText","substring","formatedLeaf","toJSON","undefined","newLeaves","push","formatText","console","log","selectedText","isLeafEmpty","splitLeaf","fragment","mergeLeafs","_item","deleted","remainingLeaf","indexOf","started","ended","isStart","isEnd","startOffset","endOffset","insertText","error","insertTextInLeaf","replaceLeafText","areLeafsMergeable","nodes","flat","every","currentLeaf","leafsToDelete","_","i","firstText","leafString","rightText","splitNode","leafContent","leafNode","indexOfLeaf","indexOfNode","split","nextLeaves","toArray","filter","newParent","hasChildren","getNodeChildren","newLeaf","defaultBlock","concat","leafNodeContentLength","doSplit","newNode","nestNode","getNode","nodeCopy","startPath","slice","reverse","newPath","prevNode","getNodeAtPath","startContainer","getNodeContainer","prevChildren","newNodes","moveNode","to","indexes","isArray","at","firstNode","container","nodesCopies","stop","prevLeafLength","deleteNode","isNodeEmpty","getArray","getNodeContent","jsonNode","nodeString","customAlphabet","_node$parent","n","_start","countable","c","getContent","right","p","cb","opts","t","array","shouldDeleteNode","leafNodeId","_this","leaves","values","leafData","shouldRemoveIfEmpty","removeIfEmpty","currentText","splice","setLeafText","leafNodeChildren","getDataTransfer","e","dataTransfer","getData","initialDoc","editorId","ID_TO_NODE","allowNesting","dnd","active","document","getElementById","style","opacity","element","body","cursor","setDragImage","offsetX","offsetY","addEventListener","onDrag","dragEnd","removeEventListener","target","hoveredNode","hasAttribute","parentElement","hoveredElement","getHoveredNode","dndIndicator","rectHovered","getBoundingClientRect","isOnTop","y","top","height","rect","isNested","x","left","width","deltaX","startOfPath","window","pageYOffset","onSelection","onFocus","onBlur","focused","onChange","activeElement","getRange","observer","observers","o","anchorNode","current","nodeHtml","querySelector","getSelection","focusNode","anchorOffset","focusOffset","isCollapsed","rangeCount","getLeaf","leaf1","node1","path1","leafHtml1","leaf2","node2","path2","leafHtml2","equalPaths","isFollowing","range","getRangeAt","getNodeBoundingRect","leafHtml","arePathsEquals","endDocument","delta","nodeType","_node","firstChild","pos","createRange","setStart","setEnd","collapse","removeAllRanges","addRange","room","Promise","res","process","provider","WebsocketProvider","connect","on","status","operation","bold","italic","underline","code","strikethrough","highlight","reduce","acc","tag","_e$target","tagName","preventDefault","stopPropagation","prevent","inputType","files","_e$dataTransfer4","_e$dataTransfer2","metaKey","undoManager","undo","shiftKey","redo","hotkeys","isHotkey","yText","_yText$parent","pop","pop_pop"],"mappings":"qtBASaA,EAAa,SAACC,OACnBC,EAAO,IAAIC,SACjBD,EAAKE,IAAI,YAAMH,SAAAA,EAAOI,KAAMC,KAC5BJ,EAAKE,IAAI,OAAQ,IAAIG,cAAKN,SAAAA,EAAOO,OAAQ,KACrCP,EAAO,KACGO,EAAyBP,EAAzBO,KAAMC,EAAmBR,EAAnBQ,KAASC,IAAUT,KACrCC,EAAKE,IAAI,OAAQ,IAAIG,OAAKC,GAAQ,KAClCC,GAAQP,EAAKE,IAAI,OAAQ,IAAID,MAAIQ,OAAOC,QAAQH,KAChDC,GACEC,OAAOE,KAA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