edytor 0.0.1 → 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("nanoid"),n=require("yjs"),o=(e=require("is-hotkey"))&&"object"==typeof e&&"default"in e?e.default:e,r=require("y-webrtc"),a=require("y-websocket"),i=function(){return"y-"+t.customAlphabet("346789ABCDEFGHJKLMNPQRTUV-WXYabcdefghijkmnpqrtwxyz",20)()},s=function(e){var t;return null==e||null==(t=e.parent)?void 0:t.parent},l=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},f=function(e){for(var t=[],n=e;n;)t.push(l(n)),n=s(n);return t.reverse()};function c(){return(c=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 d(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 u(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 g=function(e,t){var n=t.mode,o=t.selection||e.selection,r=o.start,a=o.end,i=o.length,c=o.edges,d=o.setPosition;switch(o.type){case"collapsed":if("backward"===n&&c.startNode){if(console.log(r.nodeIndex,re(r.leaf),r.path.length),!(r.nodeIndex===r.node.parent.length-1&&r.path.length>1&&0!==r.nodeIndex))return I(e),d(r.leafId,{offset:0});console.log(r.leafId);var u=F(r.node);r.node.parent.delete(r.nodeIndex),r.node.parent.parent.parent.insert(l(r.node.parent.parent)+1,[u]),d(r.leafId,{offset:0})}if("backward"===n&&c.startLeaf){var g=te(r.leaf).get(r.leafIndex-1);return X(g,Y(g)-1,i||1),d(g.get("id"),{offset:Y(g)})}if("forward"===n&&c.endNode)return L(e);if("forward"===n&&c.endLeaf){var h=te(r.leaf).get(r.leafIndex+1);return X(h,0,i||1)}X(r.leaf,r.offset+("backward"===n?-i||-1:i),i||1),d(r.leaf.get("id"),{offset:r.offset+("backward"===n?-i||-1:i)});break;case"singlenode":X(r.leaf,r.offset,i,!0),J(s(r.leaf))&&te(r.leaf).insert(0,[new A]),d(r.leaf.get("id"),{offset:r.offset});break;case"multileaves":case"multinodes":var p=r.path.join(","),v=a.path.join(",");e.doc.transact((function(){var t=new W,n=t.reap,o=t.burn;return e.doc.traverse((function(e,t){if(t){var o=f(e),i=Y(e);o.join(",")===p?(X(e,r.offset,i),n(e,!1)):o>r.path&&o<a.path?(X(e,0,i),n(e,!0)):o.join(",")===v&&(X(e,0,a.offset),n(e,a.offset===i))}}),{start:r.path[0],end:a.path[0]+1}),o(e)})),d(r.leaf.get("id"),{offset:r.offset})}},h=function(e,t){Array.from(e.keys(),(function(n){"text"!==n&&t.forEach((function(t){t.set(n,e.get(n))}))}))},p=function(e){var t=e.format,n=e.value,o=e.start,r=e.end,a=r.offset-o.offset,i=o.leaf,s=K(i).toString(),f=l(i),d=i.has(t);if(d&&Y(i)===a)return i.delete(t),i;var u,g=s.substring(r.offset,Y(i));if(0==g.length&&Y(i)===r.offset-o.offset)return i.set(t,n),i;X(i,o.offset,Y(i));var h=new A(c({},i.toJSON(),((u={id:void 0})[t]=n,u.text=s.substring(o.offset,r.offset),u))),p=[h];return g.length>0&&p.push(new A(c({},i.toJSON(),{id:void 0,text:g}))),d&&h.delete(t),p.length&&te(i).insert(f+1,p),h},v=function(e,t){var n=Object.entries(t)[0],o=n[0],r=n[1];console.log(o);var a=0,i=e.selection,s=i.start,l=i.end,c=i.type,d=i.length,u=i.setPosition,g=i.selectedText;return e.doc.transact((function(){switch(c){case"collapsed":var t=s.leaf.has(o);if(t&&V(s.leaf))s.leaf.delete(o),a=te(s.leaf).toArray().indexOf(s.leaf);else if(V(s.leaf))t?s.leaf.delete(o):s.leaf.set(o,r);else{var n;N(e,{yText:s.leaf.get("text"),at:s});var i=new A(((n={text:""})[o]=r,n));h(s.leaf,[i]),t&&i.delete(o),te(s.leaf).insert(s.path.slice().reverse()[0]+1,[i]),V(s.leaf)&&te(s.leaf).delete(s.path.slice().reverse()[0]),a=te(s.leaf).toArray().indexOf(i)}y(te(s.leaf));break;case"singlenode":e.doc.transact((function(){var e=p({format:o,value:r,start:s,end:l,length:d});y(te(s.leaf)),setTimeout((function(){if(e._item.deleted){var t=e.parent.get(s.leafIndex-1),n=K(t).toJSON().indexOf(g);u(t.get("id"),{offset:n,end:n+g.length})}else u(e.get("id"),{offset:0,end:Y(e)})}))}));break;case"multileaves":case"multinodes":var v=s.path.join(","),x=l.path.join(","),m=!1,w=!1;e.doc.traverse((function(e,t){if(t){var n=f(e),a=n.join(",")===v,i=n.join(",")===f(l.leaf).join(",");console.log({isEnd:i},x,f(l.leaf).join(","),n.join(",")),a&&(m=!0);var c=a?s.offset:0,d=i?l.offset:Y(e);m&&!w&&p({format:o,start:{leaf:e,offset:c},end:{offset:d},value:r}),console.log({ended:w}),i&&(w=!0),y(te(e))}}))}})),a},x=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,l=o.setPosition;if("notInDoc"===i)return console.error("Path is not in document space");switch(i){case"collapsed":z(r.leaf,r.offset,n),l(r.leaf.get("id"),{offset:r.offset+n.length});break;case"singlenode":G(r.leaf,r.offset,s,n),l(r.leaf.get("id"),{offset:r.offset+n.length});break;case"multileaves":case"multinodes":var c=r.path.join(","),d=a.path.join(",");e.doc.transact((function(){var t=new W,o=t.reap,i=t.burn;e.doc.traverse((function(e,t){if(t){var i=f(e);i.join(",")===c?(G(e,r.offset,Y(e),n),o(e)):i>r.path&&i<a.path?(X(e,0,Y(e)),o(e)):i.join(",")===d&&(X(e,0,a.offset),o(e))}}),{start:r.path[0],end:a.path[0]+1}),i(e)})),l(r.leaf.get("id"),{offset:r.offset+n.length})}}},m=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)}))}))},y=function(e){var t=e.get(0),n=[];e.forEach((function(o,r){var a=e.get(r+1);if(a)if(m([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(l(t))}))},N=function(e,t){var o,r=t.yText,a=t.at,i=r.toString().substring(a.offset,r.length);if(a.offset!==r.length){var s=new n.Text(i),l=new n.Map;l.set("text",s),h(r.parent,[l]);var f=null==r||null==(o=r.parent)?void 0:o.parent;r.delete(a.offset,r.length),f.insert(a.path.slice().reverse()[0]+1,[l])}},w=function(e){var t=e.selection,n=t.start,o=t.type,r=t.setPosition,a=t.edges,i=n.leaf,s=te(n.leaf),f=$(n.leaf),d=l(n.leaf),u=l(f),h=function(){var t=s.toArray().filter((function(e,t){return t>d})),o=U(n.leaf).substring(null==n?void 0:n.offset,Y(n.leaf));X(n.leaf,null==n?void 0:n.offset,o.length,!1);var a=J(f)?B(f):f.parent,l=new A(c({},i.toJSON(),{id:void 0,text:o}));a.insert(J(f)?0:u+1,[new T(e.defaultBlock,{children:[],content:[l].concat(t.map((function(e){return new A(e.toJSON())})))})]),s.delete(d+1,ne(n.leaf)-d-1),setTimeout((function(){r(l.get("id"),{offset:0})}),10)},p=!(a.startNode&&a.endNode||"multinodes"===o);if((a.endNode||a.startNode)&&"collapsed"===o){var v=new T(e.defaultBlock);return f.parent.insert(u+(a.endNode?1:0),[v]),setTimeout((function(){r(v.get("content").get(0).get("id"),{offset:0})}))}switch(o){case"collapsed":p&&h();break;case"singlenode":g(e,{mode:"backward"}),p&&h(),!p&&r(n.leaf.get("id"),{offset:n.offset});break;case"multileaves":case"multinodes":g(e,{mode:"backward"}),p&&h(),!p&&r(n.leaf.get("id"),{offset:n.offset})}},b=function(e){var t=e.selection,n=t.start,o=t.type,r=t.end,a=t.setPosition,i=s(n.leaf),l=i.toJSON(),d=f(i),u=d.slice().reverse(),g=u[0],h=u.slice(1),p=e.doc.getNodeAtPath([].concat(h,[g-1])),v=R(i);switch(o){case"singlenode":case"collapsed":if(!p)return;var x=n.leaf.get("id"),m=p.get("children");v.delete(g),m.insert(m.length,[new T(l.type,c({},l,{children:l.children.map(k),content:l.content.map(E)}))]),a(x,{offset:n.offset});break;case"multileaves":case"multinodes":var y=0,N=[],w=n.leaf.get("id"),b=n.path.slice(0,n.path.length-1).join(""),O=r.path.slice(0,n.path.length-1).join("");if(e.doc.traverse((function(e,t){if(!t){var n=f(e).join("");if(n.length===d.length&&n<=O&&n>=b){y++;var o=e.toJSON();N.push(new T(o.type,c({},o,{children:o.children.map(k),content:o.content.map(E)})))}}}),{start:n.path[0],end:r.path[0]+1}),!p)return;var S=p.get("children");v.delete(g,y),S.insert(S.length,N),a(w,{offset:n.offset})}},O=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 F(n)}));return n.container.insert(n.at,a),t.container.delete(l(r),o.length),a[0].get("content").get(0).get("id")},S=["type","content","children"],E=function(e){return new A(e)},k=function e(t){var n=t.type,o=t.content,r=void 0===o?[]:o,a=t.children,i=void 0===a?[]:a,s=u(t,S);return new T(n,c({},s,{children:i.map(e),content:r.map(E)}))},C=function(e){function t(t){var o;return(o=e.call(this)||this).getLeafAtPath=function(e){for(var t=e[0],n=e.slice(1),r=o.children.get(t),a=0;a<n.length-1;){var i=n[a];a++,r=r.get("children").get(i)}return r&&r.get("content").get(n.slice().reverse()[0])},o.getNodeAtPath=function(e){for(var t=e[0],n=e.slice(1),r=o.children.get(t),a=0;a<n.length;a++){var i=n[a];r=r.get?r.get("children").get(i):void 0}return r},o.getContainerAtPath=function(e){return 1===e.length?o.children:o.getNodeAtPath(e.slice(1,e.length)).get("children")},o.traverse=function(e,t){for(var n=function t(n,o){if(n.has("text"))e(n,!0,o);else{var r=_(n).toArray().concat(B(n).toArray());e(n,!1,o);for(var a=0;a<r.length;a++)t(r[a],[].concat(o.slice(0,o.length-1),[0,a]))}},r=o.children.toArray().slice((null==t?void 0:t.start)||0,(null==t?void 0:t.end)||o.children.length),a=0;a<r.length;a++)n(r[a],[a+((null==t?void 0:t.start)||0)])},o.toJSON=function(){return{children:o.children.toJSON(),config:o.config.toJSON()}},o.toUpdate=function(){return n.encodeStateAsUpdateV2(function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(o))},o.string=function(){for(var e="",t=o.children.toArray(),n=0;n<t.length;n++)e+=t[n].string();return e},t&&o.getArray("children").insert(0,t.map(k)),o.config=o.getMap("config"),o.children=o.getArray("children"),o}return d(t,e),t}(n.Doc),T=function(e){function t(t,o){var r;return(r=e.call(this)||this).set("id",(null==o?void 0:o.id)||i()),r.set("type",t),null!=o&&o.data&&r.set("data",new n.Map(Object.entries(o.data))),r.set("content",(null==o?void 0:o.content)instanceof n.Array?o.content:n.Array.from((null==o?void 0:o.content)||[new A])),r.set("children",(null==o?void 0:o.children)instanceof n.Array?o.children:n.Array.from((null==o?void 0:o.children)||[])),r}return d(t,e),t}(n.Map),j=["id","text","data"],A=function(e){function t(t){var o;if((o=e.call(this)||this).set("id",(null==t?void 0:t.id)||i()),o.set("text",new n.Text((null==t?void 0:t.text)||"")),t){var r=t.text,a=t.data,s=u(t,j);o.set("text",new n.Text(r||"")),a&&o.set("data",new n.Map(Object.entries(a))),s&&Object.keys(s).forEach((function(e){o.set(e,s[e])}))}return o}return d(t,e),t}(n.Map),D=["type"],I=function(e){var t,n=e.selection.start,o=!1;e.doc.traverse((function(e,r){r&&(e===n.leaf?o=!0:o||(t=e))})),t&&(te(t).insert(ne(t),te(n.leaf).toArray().map((function(e){return new A(e.toJSON())}))),y(te(t)),n.leaf.parent.parent.delete(l(s(n.leaf))))},L=function(e){var t,n=e.selection.start,o=!1;e.doc.traverse((function(e,r){r&&(e===n.leaf?o=!0:o&&(t=e,o=!1))})),console.log(te(t).toArray()),te(n.leaf).insert(ne(n.leaf),te(t).toArray().map((function(e){return new A(e.toJSON())}))),y(te(n.leaf)),console.log(n.leaf.parent.toJSON());var r=s(t);return J(r)&&(console.log(r.get("children").toJSON()),r.parent.insert(l(r),r.get("children").toJSON().map((function(e){return new T(e.type,e)})))),r.parent.delete(l(r)),t},P=function(e,t){if(q(e))e.parent.delete(l(e));else if(M(e)){var n=B(e).toJSON(),o=l(e);e.parent.delete(o),e.parent.insert(o,n.map((function(e){var t=e.type,n=u(e,D);return new T(t,n)})))}e.parent===e.doc.children&&0===e.doc.children.length&&e.parent.insert(0,[new T(t,{content:[new A]})])},R=function(e){return e.parent},B=function(e){return e.get("children")},_=function(e){return e.get("content")},J=function(e){return B(e).length>0},q=function(e){return M(e)&&!J(e)},M=function(e){return 0===_(e).length||0===_(e).toArray().map(U).join("").length},F=function(e){var t=e.toJSON();return new T(t.type,c({},t,{children:t.children.map(k),content:t.content.map(E)}))},W=function(){var e=this;this.reap=function(t,n){if(void 0===n&&(n=!1),V(t)){var o=ee(t);e.leaves[o]||(e.leaves[o]={shouldDeleteNode:n,content:te(t),node:$(t),indexes:[]}),e.leaves[o].indexes.push(l(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 P(a,null==t?void 0:t.defaultBlock)}else r.insert(0,[new A])}))},this.leaves={}},H=function(e){return e.get("data")},K=function(e){return e.get("text")},Y=function(e){return K(e).length},U=function(e){return K(e).toString()},V=function(e){return void 0===K(e)||0===Y(e)},X=function(e,t,n,o){K(e).delete(t,n),o&&Z(e)},z=function(e,t,n){K(e).insert(t,n)},G=function(e,t,n,o){var r=U(e).split("");return r.splice.apply(r,[t,n].concat(o.split(""))),Q(e,r.join(""))},Q=function(e,t){var n=K(e);n.delete(0,n.length),n.insert(0,t)},Z=function(e){V(e)&&te(e).delete(l(e))},$=function(e){return e.parent.parent},ee=function(e){return $(e).get("id")},te=function(e){return e.parent},ne=function(e){return te(e).length},oe=function(e){return $(e).get("children")},re=function(e){return oe(e).length},ae=function(e,t){for(var n,o=t,r=0;!n&&(null==(a=o)?void 0:a.id)!==e.editorId&&o&&r<100;){var a;n=e.ID_TO_NODE.get(o.id),o=o.parentElement,r++}if(n)return[n,f(n)]},ie=function(e){return e.dataTransfer.getData("text/plain")};exports.Cursor=function(){function e(t){var n=this,o=t.container,r=t.selection;this.getEditorOffset=function(t){var o,r=t.focusNode,a=t.focusOffset,i=-1;if(!r){var s=window.getSelection();r=s.focusNode,a=null==s?void 0:s.focusOffset}if(r&&e._isChildOf(r,n.container))for(o=r,i=a;o&&o!==n.container;)if(o.previousSibling)i+=(o=o.previousSibling).textContent.length;else if(null===(o=o.parentNode))break;return i},this.set=function(t){e.setCurrentCursorPosition(t,n.container,n.selection.selection)},this.setRange=function(e,t){var o=n.selection.selection,r=n.getRangeBoundaries(e,t),a=r.startNode,i=r.startOffset,s=r.endNode,l=r.endOffset;o.removeAllRanges();var f=document.createRange();f.selectNode(n.container),f.setStart(a,i),f.setEnd(s,l),o.addRange(f)},this.getRangeBoundaries=function(e,t){var o,r,a,i=n.getRangeBoundary(n.container,{count:e-t},!0),s=i[0],l=i[1],f=n.getRangeBoundary(n.container,{count:e},!1),c=f[0],d=f[1];return s.length===l&&(o=s,a=(r=Array.from(o.parentElement.childNodes)).indexOf(o),console.log({index:a,childNodes:r,next:r[a+1]})),{startNode:s,startOffset:l,endNode:c,endOffset:d}},this.getRangeBoundary=function(e,t,o){var r;if(0===t.count)r=[e,t.count];else if(e&&t.count>0)if(e.nodeType===Node.TEXT_NODE)e.textContent.length<t.count?t.count-=e.textContent.length:(r=[e,t.count],t.count=0);else for(var a=0;a<e.childNodes.length&&(r=n.getRangeBoundary(e.childNodes[a],t,o),0!==t.count);a++);return r},this.container=o,this.selection=r}return e.getCurrentCursorPosition=function(t,n,o){var r,a=-1;if(!n){var i=window.getSelection();n=i.focusNode,o=null==i?void 0:i.focusOffset}if(n&&e._isChildOf(n,t))for(r=n,a=o;r&&r!==t;)if(r.previousSibling)a+=(r=r.previousSibling).textContent.length;else if(null===(r=r.parentNode))break;return a},e.setCurrentCursorPosition=function(t,n,o){if(t>=0){var r=o||window.getSelection(),a=e._createRange(n,{count:t});a&&(a.collapse(!1),r.removeAllRanges(),r.addRange(a))}},e.selectNode=function(e,t,n,o){o||(o=window.getSelection());for(var r=e;3!==(null==(a=r)?void 0:a.nodeType)&&null!=(i=r)&&i.firstChild;){var a,i,s;r=null==(s=r)?void 0:s.firstChild}o.removeAllRanges();var l=document.createRange();l.setStart(r,t),l.setEnd(r,n),o.addRange(l)},e._createRange=function(t,n,o){if(o||((o=document.createRange()).selectNode(t),o.setStart(t,0)),0===n.count)o.setEnd(t,n.count);else if(t&&n.count>0)if(t.nodeType===Node.TEXT_NODE)t.textContent.length<n.count?n.count-=t.textContent.length:(o.setEnd(t,n.count),n.count=0);else for(var r=0;r<t.childNodes.length&&(o=e._createRange(t.childNodes[r],n,o),0!==n.count);r++);return o},e._isChildOf=function(e,t){for(;null!==e;){if(e===t)return!0;e=e.parentNode}return!1},e}(),exports.Dropper=function(e,t,n,o,r){var a=this;this.startDrag=function(e,t){var n;a.node=e,document.getElementById("dndIndicator").style.opacity="1";var o=document.getElementById(e.get("id"));o.style.opacity="0.4",document.body.style.cursor="grabbing",a.from={container:e.parent,at:l(e)},a.startPath=f(e),null==(n=t.dataTransfer)||n.setDragImage(o,t.offsetX,t.offsetY),document.addEventListener("mousemove",a.onDrag),document.addEventListener("mouseup",a.dragEnd)},this.dragEnd=function(){var e=document.getElementById(a.node.get("id"));e&&(e.style.opacity="1"),document.body.style.cursor="auto",document.removeEventListener("mousemove",a.onDrag),document.removeEventListener("mouseup",a.dragEnd);var t=O({from:a.from,to:a.to});document.getElementById("dndIndicator").style.opacity="0",setTimeout((function(){console.log(t),a.selection.setPosition(t,{offset:0})}))},this.getHoveredNode=function(e){for(var t,n=e,o=0;!t&&(null==(r=n)?void 0:r.id)!==a.editorId&&n&&o<100;){var r;if(n.hasAttribute("data-edytor-block")){t=a.ID_TO_NODE.get(n.id);break}n=n.parentElement,o++}return t?{hoveredElement:n,hoveredNode:t}:{}},this.onDrag=function(e){var t=a.getHoveredNode(e.target),n=t.hoveredElement,o=t.hoveredNode,r=document.getElementById("dndIndicator");if(o&&n&&r&&o!==a.node){var i=n.getBoundingClientRect(),s=e.y<i.top+i.height/2,l=i,c=a.allowNesting&&!s&&e.x>l.left+l.width/5,d=s?l.top:l.top+l.height,u=c?30:0,g=f(o),h=g.slice().reverse(),p=h[0],v=h.slice(1);a.startPath.join("")!==v.join("")&&(r.style.width=l.width-u+"px",r.style.top=d+window.pageYOffset+"px",r.style.left=l.left+u+"px",-1===(p+=s?0:1)&&(p=0),a.to={container:c?o.get("children"):1===g.length?a.doc.children:o.parent,at:c?0:p})}},this.doc=e,this.editorId=t,this.selection=o,this.ID_TO_NODE=n,this.allowNesting=r},exports.EdytorDoc=C,exports.EdytorSelection=function(e,t){var n=this;this.init=function(e){n.container=e,document.addEventListener("selectionchange",n.onSelection),n.container.addEventListener("focus",n.onFocus),n.container.addEventListener("blur",n.onBlur)},this.onFocus=function(){n.focused=!0,n.onChange()},this.onBlur=function(){n.focused=!1,n.onChange()},this.destroy=function(){document.removeEventListener("selectionchange",n.onSelection)},this.onSelection=function(e){var t;(null==(t=e.target)?void 0:t.activeElement)===n.container&&n.getRange()},this.observe=function(e){n.observers=n.observers?n.observers.concat(e):[e]},this.unobserve=function(e){n.observers=n.observers?n.observers.filter((function(t){return t!==e})):[]},this.getLeaf=function(e,t){if(n[t]&&n[t].node===e)return n[t].value;for(var o,r=e;!o&&r!==n.container&&r;)(o=n.ID_TO_NODE.get(r.id))||(r=r.parentElement);if(!o)return[void 0,void 0,void 0,void 0];var a=[o,$(o),f(o),r];return n[t]={value:a,node:e},a},this.getNodeBoundingRect=function(e){return{nodeHtml:n.container.querySelector("#"+e.get("id"))}},this.getRange=function(){var e=window.getSelection(),t=e.focusNode,o=e.anchorOffset,r=e.focusOffset,a=e.isCollapsed,i=e.rangeCount;if(null!==t){var s=n.getLeaf(e.anchorNode,"anchorNode"),f=s[0],d=s[1],u=s[2],g=s[3],h=n.getLeaf(t,"focusNode"),p=h[0],v=h[1],x=h[2],m=h[3];if(f){var y=u.join("")===x.join(""),N=y?o<r:u.join()<x.join(),w=i>=1?null==e?void 0:e.getRangeAt(0):void 0;n.start=c({},n.getNodeBoundingRect(N?d:v),{node:N?d:v,leafId:(N?f:p).get("id"),leafIndex:N?u[u.length-1]:x[x.length-1],nodeIndex:N?u[u.length-2]:x[x.length-2],path:N?u:x,leafHtml:N?g:m,offset:N?o:r,leaf:N?f:p}),n.end=a?n.start:c({},n.getNodeBoundingRect(N?v:d),{node:N?v:d,leafId:(N?p:f).get("id"),leafIndex:N?x[x.length-1]:u[u.length-1],nodeIndex:N?x[x.length-2]:u[u.length-2],path:N?x:u,leafHtml:N?m:g,offset:N?r:o,leaf:N?p:f}),n.selectedText=w?w.toString():"",n.arePathsEquals=y,n.length=n.selectedText.length,n.range=w,n.selection=e,n.edges={startLeaf:0===n.start.offset,startNode:0===n.start.offset&&0===l(n.start.leaf),endLeaf:n.end.offset===Y(n.end.leaf),endNode:n.end.offset===Y(n.end.leaf)&&l(n.start.leaf)===ne(n.end.leaf)-1},n.type=a?"collapsed":y?"singlenode":n.start.node===n.end.node?"multileaves":"multinodes",n.onChange()}}},this.onChange=function(){n.onSelectionChange&&n.onSelectionChange(n),n.observers&&n.observers.forEach((function(e){return e(n)}))},this.setPosition=function(e,t){for(var o,r,a,i,s=t.offset,l=t.delta,f=t.end,d=n.container.querySelector("#"+e);d&&3!==d.nodeType&&null!=(u=d)&&u.firstChild;){var u;d=d.firstChild}var g=s||(null==(o=n.start)?void 0:o.offset)+l;n.range||n.selection||(n.range=document.createRange(),n.selection=window.getSelection()),n.range.setStart(d,g),f?n.range.setEnd(d,f):n.range.collapse(!0),null==(r=n.selection)||r.removeAllRanges(),null==(a=n.selection)||a.addRange(n.range),n.start=c({},n.start,{leafHtml:n.container.querySelector("#"+e),offset:s||(null==(i=n.start)?void 0:i.offset)+l})},this.onSelectionChange=t,this.ID_TO_NODE=e},exports.LeavesHarvest=W,exports.YLeaf=A,exports.YNode=T,exports.applyMarksFromParent=h,exports.areLeafsMergeable=m,exports.copyNode=F,exports.createWSProvider=function(e,t,o){void 0===t&&(t="hello");var r=new C,i=new a.WebsocketProvider("ws://localhost:1234",t,r);return i.on("status",(function(t){if("connected"===t.status){var o=1===Array.from(i.awareness.getStates().values()).length;console.log(o,Array.from(i.awareness.getStates().values()).length),i.awareness.setLocalStateField("connected",!0),o&&n.applyUpdateV2(r,n.encodeStateAsUpdateV2(e))}})),i.doc},exports.createWebRtcProvider=function(e,t,o){void 0===t&&(t="hello"),new n.Doc;var a=new r.WebrtcProvider(t,e,o);return a.emit("ping",["lkeazlk"]),a.connect(),a.on("ping",(function(){console.log("ping")})),a.on("*",(function(e){console.log(e)})),a.on("connect",(function(e){console.log(e)})),a},exports.deleteLeafText=X,exports.deleteNode=P,exports.deleteText=g,exports.formatAtEqualPath=p,exports.formatText=v,exports.getChildren=k,exports.getContent=E,exports.getId=function(e){return e.get("id")},exports.getIndex=l,exports.getNode=s,exports.getNodeChildren=B,exports.getNodeContainer=R,exports.getNodeContent=_,exports.getPath=f,exports.getRange=function(e,t){var n,o=t.anchorNode,r=t.focusNode,a=t.anchorOffset,i=t.focusOffset,s=t.isCollapsed,l=t.rangeCount;if(null!==r){var f=ae(e,o),c=f[0],d=f[1],u=ae(e,r),g=u[0],h=u[1];if(c){var p=d.join("")===h.join(""),v=p?a<i:d.join()<h.join(),x={node:v?o:r,path:v?d:h,ancestor:document.querySelector('[data-edytor-path="'+(v?d:h).slice(0,1)+'"]'),offset:v?a:i,leaf:v?c:g},m=s?x:{node:v?r:o,path:v?h:d,offset:v?i:a,leaf:v?g:c},y=l>=1?null==t?void 0:t.getRangeAt(0):void 0,N={start:x,end:m,arePathsEquals:p,length:y&&(null==(n=y.toString())?void 0:n.length),range:y,boundingRect:y&&y.getBoundingClientRect(),selection:t,edges:{start:0===x.offset,end:m.offset===Y(m.leaf)},type:s?"collapsed":p?"singlenode":"multinodes",editorOffset:e.cursor().getEditorOffset(t)};return console.log({edytorSelection:N}),N}}},exports.hasChildren=J,exports.insertText=x,exports.insertTextInLeaf=z,exports.isLeafEmpty=V,exports.isNodeContentEmpty=M,exports.isNodeEmpty=q,exports.leafData=H,exports.leafLength=Y,exports.leafNode=$,exports.leafNodeChildren=oe,exports.leafNodeChildrenLength=re,exports.leafNodeContent=te,exports.leafNodeContentLength=ne,exports.leafNodeContentStringLength=function(e){return te(e).toArray().reduce((function(e,t){return e+Y(t)}),0)},exports.leafNodeId=ee,exports.leafString=U,exports.leafText=K,exports.mergeContentWithNextLeaf=L,exports.mergeContentWithPrevLeaf=I,exports.mergeLeafs=y,exports.moveNode=O,exports.nanoid=i,exports.nestNode=b,exports.onBeforeInput=function(e,t){var n=e[0],o=e[1],r=e[2];!function(e){e.preventDefault(),e.stopPropagation()}(t);var a=r.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?ie(t):t.data;x(r,{text:l});break;case"deleteContentBackward":g(r,{mode:"backward"});break;case"deleteByDrag":case"deleteByCut":case"deleteContentForward":g(r,{mode:"forward"});break;case"insertParagraph":w(r);break;case"insertFromDrop":setTimeout((function(){var e=ie(t);e&&x(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":n().doc.transact((function(){G(i.leaf,i.offset,s,ie(t))}))}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&&b(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 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 v(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=Z,exports.replaceLeafText=G,exports.setLeafData=function(e,t){e.has("data")?Object.keys(t).forEach((function(n){H(e).set(n,t[n])})):e.set("data",new Map(Object.entries(t)))},exports.setLeafText=Q,exports.splitLeaf=N,exports.splitNode=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/common.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/yClasses/EdytorDoc.ts","../src/utils/yClasses/yNode.ts","../src/utils/yClasses/yLeaf.ts","../src/utils/nodes.ts","../src/utils/leaves.ts","../src/utils/getSelection.ts","../src/events/onBeforeInput.ts","../src/utils/cursor.ts","../src/utils/dropper.ts","../src/utils/Selection/EdytorSelection.ts","../src/yjs/wsProvider.ts","../src/yjs/webrtcProvider.ts","../src/events/onDrop.ts","../src/events/onKeyDown.ts","../src/operations/removeEmptyText.ts"],"sourcesContent":["import { customAlphabet } from \"nanoid\";\nimport { YMap } from \"yjs/dist/src/internals\";\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","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 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, [new YLeaf()]);\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 editor.doc.traverse(\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 leafString,\n leafText,\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 = new YLeaf({\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(new YLeaf({ ...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 = new YLeaf({ 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\n setTimeout(() => {\n if (!formatedLeaf._item.deleted) {\n setPosition(formatedLeaf.get(\"id\"), { offset: 0, end: leafLength(formatedLeaf) });\n } else {\n const remainingLeaf = formatedLeaf.parent.get(start.leafIndex - 1);\n const offset = leafText(remainingLeaf)\n .toJSON()\n .indexOf(selectedText);\n setPosition(remainingLeaf.get(\"id\"), {\n offset,\n end: offset + selectedText.length\n });\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 editor.doc.traverse(\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 { deleteLeafText, getPath, insertTextInLeaf, leafLength, LeavesHarvest, replaceLeafText, YLeaf } 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 editor.doc.traverse(\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} 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 = new YLeaf({ ...leaf.toJSON(), id: undefined, text: rightText });\n newParent.insert(hasChildren(node) ? 0 : indexOfNode + 1, [\n new YNode(editor.defaultBlock, {\n children: [],\n content: [newLeaf].concat(nextLeaves.map((leaf) => new YLeaf(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 = new YNode(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 \"..\";\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 = editor.doc.getNodeAtPath([...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 new YNode(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 editor.doc.traverse(\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 new YNode(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 { Editor, getIndex, getNodeContainer, getPath, YNode, getChildren, getContent } 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 { Doc, encodeStateAsUpdateV2 } from \"yjs\";\nimport { YArray, YMap } from \"yjs/dist/src/internals\";\nimport { YLeaf, YNode } from \".\";\nimport { getNodeContent, getNodeChildren } from \"../nodes\";\n\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 new YLeaf(leaf);\n};\nexport const getChildren = ({ type, content = [], children = [], ...props }: jsonNode): YNode => {\n return new YNode(type, { ...props, children: children.map(getChildren), content: content.map(getContent) });\n};\nexport class EdytorDoc extends Doc {\n children: YArray<YNode>;\n config: YMap<any>;\n constructor(value?: jsonNode[]) {\n super();\n if (value) {\n const array = this.getArray(\"children\");\n array.insert(0, value.map(getChildren));\n }\n this.config = this.getMap(\"config\");\n this.children = this.getArray(\"children\");\n }\n getLeafAtPath = ([start, ...path]: number[]): YLeaf => {\n let node = this.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 };\n getNodeAtPath = ([start, ...path]: number[]): YNode => {\n let node = this.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 };\n getContainerAtPath = (path: number[]): YArray<any> => {\n if (path.length === 1) {\n return this.children;\n } else {\n return this.getNodeAtPath(path.slice(1, path.length)).get(\"children\");\n }\n };\n traverse = (\n cb: (node: YMap<any>, isText: boolean, path: number[]) => void,\n opts?: {\n start?: number;\n end?: number;\n }\n ) => {\n const traverse = (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 traverse(array[i], [...path.slice(0, path.length - 1), 0, i]);\n }\n }\n };\n const array = this.children.toArray().slice(opts?.start || 0, opts?.end || this.children.length) as YNode[];\n for (let i = 0; i < array.length; i++) {\n traverse(array[i], [i + (opts?.start || 0)]);\n }\n };\n toJSON = () => {\n return {\n children: this.children.toJSON(),\n config: this.config.toJSON()\n };\n };\n toUpdate = () => {\n return encodeStateAsUpdateV2(this);\n };\n string = (): string => {\n let t = \"\";\n const array = this.children.toArray() as YNode[];\n for (let i = 0; i < array.length; i++) {\n t += array[i].string();\n }\n return t;\n };\n}\n","import { nanoid } from \"..\";\nimport { Map, Array } from \"yjs\";\nimport { YArray, YMap } from \"yjs/dist/src/internals\";\nimport { YLeaf } from \".\";\n\nexport type YNodeProps = {\n data?: any;\n content?: YLeaf[] | YArray<YLeaf>;\n children?: YNode[] | YArray<YNode>;\n id?: string;\n};\n\nexport class YNode extends Map<any> {\n constructor(type: string, props?: YNodeProps) {\n super();\n\n this.set(\"id\", props?.id || nanoid());\n this.set(\"type\", type);\n if (props?.data) {\n this.set(\"data\", new Map(Object.entries(props.data)));\n }\n this.set(\"content\", props?.content instanceof Array ? props.content : Array.from(props?.content || [new YLeaf()]));\n this.set(\"children\", props?.children instanceof Array ? props.children : Array.from(props?.children || []));\n }\n}\n","import { nanoid } from \"..\";\nimport { Map, Text } from \"yjs\";\n\nexport type YLeafProps = {\n data?: any;\n text?: string;\n id?: string;\n};\nexport class YLeaf extends Map<any> {\n id: string;\n\n constructor(props?: YLeafProps) {\n super();\n this.set(\"id\", props?.id || nanoid());\n this.set(\"text\", new Text(props?.text || \"\"));\n if (props) {\n const { id, text, data, ...marks } = props;\n\n this.set(\"text\", new Text(text || \"\"));\n data && this.set(\"data\", new Map(Object.entries(data)));\n\n marks &&\n Object.keys(marks).forEach((mark) => {\n this.set(mark, marks[mark]);\n });\n }\n }\n}\n","import { YArray, YMap } from \"yjs/dist/src/internals\";\nimport { mergeLeafs } from \"../operations\";\nimport { Editor } from \"../types\";\nimport { getIndex, getNode } from \"./common\";\nimport { leafNodeContent, leafNodeContentLength, leafString } from \"./leaves\";\nimport { 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 editor.doc.traverse((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 new YLeaf(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 new YLeaf(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) => new YNode(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 }) => new YNode(type, props))\n );\n }\n if (node.parent === (node.doc as EdytorDoc).children && (node.doc as EdytorDoc).children.length === 0) {\n (node.parent as YArray<YNode>).insert(0, [new YNode(defaultBlock, { content: [new YLeaf()] })]);\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 new YNode(jsonNode.type, {\n ...jsonNode,\n children: jsonNode.children.map(getChildren),\n content: jsonNode.content.map(getContent)\n });\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, [new YLeaf()]);\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 { Editor, EdytorSelection } from \"../types\";\nimport { getPath } from \"./common\";\nimport { leafLength } from \"./leaves\";\n\nimport { YLeaf } from \"./yClasses\";\n\nconst getLeaf = (editor: Editor, anchorNode: HTMLElement): [YLeaf, number[]] => {\n let leaf;\n let node = anchorNode;\n let i = 0;\n while (!leaf && node?.id !== editor.editorId && node && i < 100) {\n leaf = editor.ID_TO_NODE.get(node.id);\n node = node.parentElement;\n i++;\n }\n if (!leaf) return undefined;\n\n return [leaf, getPath(leaf)];\n};\n\nexport const getRange = (editor: Editor, selection: Selection): EdytorSelection => {\n const { anchorNode, focusNode, anchorOffset, focusOffset, isCollapsed, rangeCount } = selection;\n\n if (focusNode === null) return;\n const [leaf1, path1] = getLeaf(editor, anchorNode as HTMLElement);\n const [leaf2, path2] = getLeaf(editor, focusNode as HTMLElement);\n if (!leaf1) return;\n const equalPaths = path1.join(\"\") === path2.join(\"\");\n const isFollowing = equalPaths ? anchorOffset < focusOffset : path1.join() < path2.join();\n\n // console.log(isFollowing, equalPaths, { path1, path2 });\n const start = {\n node: isFollowing ? anchorNode : focusNode,\n path: isFollowing ? path1 : path2,\n ancestor: document.querySelector(`[data-edytor-path=\"${(isFollowing ? path1 : path2).slice(0, 1)}\"]`),\n offset: isFollowing ? anchorOffset : focusOffset,\n leaf: isFollowing ? leaf1 : leaf2\n };\n\n const end = isCollapsed\n ? start\n : {\n node: !isFollowing ? anchorNode : focusNode,\n path: !isFollowing ? path1 : path2,\n offset: !isFollowing ? anchorOffset : focusOffset,\n leaf: !isFollowing ? leaf1 : leaf2\n };\n\n const range = rangeCount >= 1 ? selection?.getRangeAt(0) : undefined;\n\n //@ts-ignore\n let edytorSelection = {\n start,\n end,\n arePathsEquals: equalPaths,\n length: range && range.toString()?.length,\n range,\n boundingRect: range && range.getBoundingClientRect(),\n selection,\n edges: {\n start: start.offset === 0,\n end: end.offset === leafLength(end.leaf)\n },\n type: isCollapsed ? \"collapsed\" : equalPaths ? \"singlenode\" : \"multinodes\",\n editorOffset: editor.cursor().getEditorOffset(selection)\n } as EdytorSelection;\n\n console.log({ edytorSelection });\n return edytorSelection;\n};\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\n const editorDiv = e.target as HTMLDivElement;\n\n const { selection, 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 { EdytorSelection } from \"../types\";\n\nexport class Cursor {\n container: HTMLDivElement;\n selection: EdytorSelection;\n constructor({ container, selection }) {\n this.container = container;\n this.selection = selection;\n }\n getEditorOffset = (selection: Selection): number => {\n let { focusNode, focusOffset } = selection;\n var charCount = -1,\n node;\n if (!focusNode) {\n const selection = window.getSelection();\n focusNode = selection.focusNode;\n focusOffset = selection?.focusOffset;\n }\n\n if (focusNode) {\n if (Cursor._isChildOf(focusNode, this.container)) {\n node = focusNode;\n charCount = focusOffset;\n\n while (node) {\n if (node === this.container) {\n break;\n }\n\n if (node.previousSibling) {\n node = node.previousSibling;\n charCount += node.textContent.length;\n } else {\n node = node.parentNode;\n if (node === null) {\n break;\n }\n }\n }\n }\n }\n\n return charCount;\n };\n\n static getCurrentCursorPosition(parentElement: HTMLElement | Node, focusNode?: Node, focusOffset?: number) {\n var charCount = -1,\n node;\n if (!focusNode) {\n const selection = window.getSelection();\n focusNode = selection.focusNode;\n focusOffset = selection?.focusOffset;\n }\n\n if (focusNode) {\n if (Cursor._isChildOf(focusNode, parentElement)) {\n node = focusNode;\n charCount = focusOffset;\n\n while (node) {\n if (node === parentElement) {\n break;\n }\n\n if (node.previousSibling) {\n node = node.previousSibling;\n charCount += node.textContent.length;\n } else {\n node = node.parentNode;\n if (node === null) {\n break;\n }\n }\n }\n }\n }\n\n return charCount;\n }\n\n set = (offset: number) => {\n Cursor.setCurrentCursorPosition(offset, this.container, this.selection.selection);\n };\n setRange = (offset: number, length) => {\n const { range, selection } = this.selection;\n const { startNode, startOffset, endNode, endOffset } = this.getRangeBoundaries(offset, length);\n selection.removeAllRanges();\n\n const R = document.createRange();\n R.selectNode(this.container);\n R.setStart(startNode, startOffset);\n R.setEnd(endNode, endOffset);\n selection.addRange(R);\n };\n\n getRangeBoundaries = (offset: number, length) => {\n const [startNode, startOffset] = this.getRangeBoundary(this.container, { count: offset - length }, true);\n const [endNode, endOffset] = this.getRangeBoundary(this.container, { count: offset }, false);\n\n if (startNode.length === startOffset) {\n const getNextNode = (node: ChildNode) => {\n const childNodes = Array.from(node.parentElement.childNodes);\n const index = childNodes.indexOf(node);\n console.log({ index, childNodes, next: childNodes[index + 1] });\n };\n getNextNode(startNode);\n }\n return {\n startNode,\n startOffset,\n endNode,\n endOffset\n };\n };\n getRangeBoundary = (node, chars, isStart): [ChildNode, number] => {\n let result;\n if (chars.count === 0) {\n result = [node, chars.count];\n } else if (node && chars.count > 0) {\n if (node.nodeType === Node.TEXT_NODE) {\n if (node.textContent.length < chars.count) {\n chars.count -= node.textContent.length;\n } else {\n result = [node, chars.count];\n chars.count = 0;\n }\n } else {\n for (var lp = 0; lp < node.childNodes.length; lp++) {\n result = this.getRangeBoundary(node.childNodes[lp], chars, isStart);\n if (chars.count === 0) {\n break;\n }\n }\n }\n }\n\n return result;\n };\n\n static setCurrentCursorPosition(chars, element, s?: Selection) {\n if (chars >= 0) {\n var selection = s || window.getSelection();\n\n let range = Cursor._createRange(element, { count: chars });\n\n if (range) {\n range.collapse(false);\n selection.removeAllRanges();\n selection.addRange(range);\n }\n }\n }\n\n static selectNode(node, startOffset, endOffset, selection) {\n if (!selection) selection = window.getSelection();\n\n let textNode = node;\n while (textNode?.nodeType !== 3 && textNode?.firstChild) {\n textNode = textNode?.firstChild;\n }\n\n selection.removeAllRanges();\n const R = document.createRange();\n\n R.setStart(textNode, startOffset);\n R.setEnd(textNode, endOffset);\n selection.addRange(R);\n }\n\n static _createRange(node, chars, range) {\n if (!range) {\n range = document.createRange();\n range.selectNode(node);\n range.setStart(node, 0);\n }\n\n if (chars.count === 0) {\n range.setEnd(node, chars.count);\n } else if (node && chars.count > 0) {\n if (node.nodeType === Node.TEXT_NODE) {\n if (node.textContent.length < chars.count) {\n chars.count -= node.textContent.length;\n } else {\n range.setEnd(node, chars.count);\n chars.count = 0;\n }\n } else {\n for (var lp = 0; lp < node.childNodes.length; lp++) {\n range = Cursor._createRange(node.childNodes[lp], chars, range);\n\n if (chars.count === 0) {\n break;\n }\n }\n }\n }\n\n return range;\n }\n\n static _isChildOf(node, parentElement) {\n while (node !== null) {\n if (node === parentElement) return true;\n node = node.parentNode;\n }\n\n return false;\n }\n}\n","import { moveNode } from \"../operations\";\nimport { 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\n doc: EdytorDoc;\n editorId: string;\n ID_TO_NODE: Map<any, any>;\n selection: EdytorSelection;\n allowNesting: boolean;\n\n constructor(\n doc: EdytorDoc,\n editorId: string,\n ID_TO_NODE: Map<any, any>,\n selection: EdytorSelection,\n allowNesting: boolean\n ) {\n this.doc = doc;\n this.editorId = editorId;\n this.selection = selection;\n this.ID_TO_NODE = ID_TO_NODE;\n this.allowNesting = 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.doc.children : hoveredNode.parent,\n at: isNested ? 0 : index\n };\n };\n}\n","import { Position } from \"../..\";\nimport { createAbsolutePositionFromRelativePosition } from \"../../../../../node_modules/yjs/dist/src\";\nimport { getIndex, getPath } from \"../common\";\nimport { leafLength, leafNode, leafNodeContentLength } from \"../leaves\";\nimport { YLeaf, YNode } from \"../yClasses\";\n\nexport class EdytorSelection {\n onSelectionChange?: (selection: EdytorSelection) => void;\n observers: ((selection: EdytorSelection) => void)[];\n container: HTMLDivElement;\n ID_TO_NODE: Map<any, any>;\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 constructor(ID_TO_NODE: Map<any, any>, onSelectionChange?: (selection: EdytorSelection) => void) {\n this.onSelectionChange = onSelectionChange;\n this.ID_TO_NODE = ID_TO_NODE;\n }\n init = (container) => {\n this.container = container;\n\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.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 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 = isCollapsed\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.onSelectionChange && this.onSelectionChange(this);\n if (this.observers) {\n this.observers.forEach((o) => o(this));\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\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 { applyUpdateV2, Doc, encodeStateAsUpdateV2 } from \"yjs\";\nimport { WebsocketProvider } from \"y-websocket\";\nimport { EdytorDoc } from \"../utils\";\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 createWSProvider = (doc: Doc, room = \"hello\", opts: WebrtcProviderOptions) => {\n const fakeDoc = new EdytorDoc();\n const provider = new WebsocketProvider(\"ws://localhost:1234\", room, fakeDoc);\n provider.on(\"status\", ({ status }) => {\n if (status === \"connected\") {\n const isEmpty = Array.from(provider.awareness.getStates().values()).length === 1;\n console.log(isEmpty, Array.from(provider.awareness.getStates().values()).length);\n provider.awareness.setLocalStateField(\"connected\", true);\n if (isEmpty) {\n applyUpdateV2(fakeDoc, encodeStateAsUpdateV2(doc));\n }\n }\n });\n\n return provider.doc;\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":["nanoid","customAlphabet","getNode","node","parent","_node$parent","getIndex","index","stop","n","_start","countable","deleted","c","content","getContent","i","length","right","getPath","p","push","reverse","deleteText","editor","mode","selection","start","end","edges","setPosition","type","startNode","console","log","nodeIndex","leafNodeChildrenLength","leaf","path","mergeContentWithPrevLeaf","leafId","offset","copyNode","insert","startLeaf","prevLeaf","leafNodeContent","get","leafIndex","deleteLeafText","leafLength","endNode","mergeContentWithNextLeaf","endLeaf","nextLeaf","hasChildren","YLeaf","startPathString","join","endPathString","doc","transact","LeavesHarvest","reap","burn","traverse","isText","l","applyMarksFromParent","leafs","Array","from","keys","key","forEach","set","formatAtEqualPath","format","value","leafText","toString","isMarkActive","has","remainingText","substring","formatedLeaf","toJSON","id","undefined","text","newLeaves","formatText","mark","Object","entries","newPath","selectedText","isLeafEmpty","toArray","indexOf","splitLeaf","yText","at","newChild","slice","mergeLeafs","setTimeout","_item","remainingLeaf","started","ended","isStart","isEnd","startOffset","endOffset","insertText","error","insertTextInLeaf","replaceLeafText","areLeafsMergeable","nodes","map","flat","every","currentLeaf","leafsToDelete","_","firstText","rightText","newText","Y","newLeave","_yText$parent","splitNode","leafContent","leafNode","indexOfLeaf","indexOfNode","split","nextLeaves","filter","leafString","newParent","getNodeChildren","newLeaf","YNode","defaultBlock","children","concat","leafNodeContentLength","doSplit","newNode","nestNode","startJsonNode","startPath","prevNode","getNodeAtPath","startContainer","getNodeContainer","prevChildren","getChildren","newNodes","jsonNode","moveNode","to","indexes","isArray","firstNode","container","nodesCopies","props","EdytorDoc","_this","cb","opts","array","getNodeContent","config","encodeStateAsUpdateV2","t","string","getArray","getMap","Doc","data","Map","Text","marks","deleteNode","isNodeEmpty","isNodeContentEmpty","shouldDeleteNode","leafNodeId","leaves","values","leafData","shouldRemoveIfEmpty","removeIfEmpty","currentText","splice","setLeafText","leafNodeChildren","getLeaf","anchorNode","editorId","ID_TO_NODE","parentElement","getDataTransfer","e","dataTransfer","getData","focusNode","focusOffset","charCount","window","getSelection","Cursor","_isChildOf","previousSibling","textContent","parentNode","setCurrentCursorPosition","range","getRangeBoundaries","removeAllRanges","R","document","createRange","selectNode","setStart","setEnd","addRange","childNodes","getRangeBoundary","count","next","chars","result","nodeType","Node","TEXT_NODE","lp","getCurrentCursorPosition","element","s","_createRange","collapse","textNode","_textNode2","firstChild","_textNode3","allowNesting","getElementById","style","opacity","body","cursor","setDragImage","offsetX","offsetY","addEventListener","onDrag","dragEnd","removeEventListener","target","hoveredNode","hasAttribute","hoveredElement","getHoveredNode","dndIndicator","rectHovered","getBoundingClientRect","isOnTop","y","top","height","rect","isNested","x","left","width","deltaX","startOfPath","pageYOffset","onSelectionChange","onSelection","onFocus","onBlur","focused","onChange","activeElement","getRange","observer","observers","o","current","nodeHtml","querySelector","anchorOffset","isCollapsed","rangeCount","leaf1","node1","path1","leafHtml1","leaf2","node2","path2","leafHtml2","equalPaths","isFollowing","getRangeAt","getNodeBoundingRect","leafHtml","arePathsEquals","delta","_node","pos","room","fakeDoc","provider","WebsocketProvider","on","status","isEmpty","awareness","getStates","setLocalStateField","applyUpdateV2","WebrtcProvider","emit","connect","event","ancestor","edytorSelection","_range$toString","boundingRect","editorOffset","getEditorOffset","reduce","acc","preventDefault","stopPropagation","prevent","inputType","files","_e$dataTransfer4","_e$dataTransfer2","metaKey","undoManager","undo","shiftKey","redo","hotkeys","operation","isHotkey","pop","pop_pop"],"mappings":"wOAEaA,EAAS,iBAAM,KAAOC,iBAAe,qDAAsD,GAArEA,IAItBC,EAAU,SAACC,sBAAgBA,YAAAA,EAAMC,eAANC,EAAcD,QAEzCE,EAAW,SAACH,WACnBI,EAAQ,EACRC,GAAO,EACPC,EAAIN,EAAKC,OAAOM,OACP,OAAND,IAAeD,GAAM,IACtBC,EAAEE,YAAcF,EAAEG,gBACdC,EAAIJ,EAAEK,QAAQC,aACXC,EAAI,EAAGA,EAAIH,EAAEI,OAAQD,IAAK,IAC7BH,EAAEG,KAAOb,EAAM,CACjBK,GAAO,QAGTD,IAGJE,EAAIA,EAAES,aAEDX,GAGIY,EAAU,SAAChB,WAClBiB,EAAI,GACJX,EAAIN,EACCM,GACPW,EAAEC,KAAKf,EAASG,IAChBA,EAAIP,EAAQO,UAEPW,EAAEE,ufCVEC,EAAa,SAACC,SAAkBC,IAAAA,SAAMC,WACqBF,EAAOE,UAArEC,IAAAA,MAAOC,IAAAA,IAAWX,IAAAA,OAAQY,IAAAA,MAAOC,IAAAA,qBAArBC,UAGb,eACU,aAATN,GAAuBI,EAAMG,UAAW,IAC1CC,QAAQC,IAAIP,EAAMQ,UAAWC,GAAuBT,EAAMU,MAAOV,EAAMW,KAAKrB,UAExEU,EAAMQ,YAAcR,EAAMxB,KAAKC,OAAOa,OAAS,GAAKU,EAAMW,KAAKrB,OAAS,GAAyB,IAApBU,EAAMQ,kBAQrFI,EAAyBf,GAClBM,EAAYH,EAAMa,OAAQ,CAAEC,OAAQ,IAR3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IhW,UAChBiW,EAAS,KACLrV,EAAIT,EAAM8V,EAASD,IAClB,IAAPpV,GAAYqV,SAAerV,GAC3B+J,EAAQsL,OAERtL,OAAQvF,0EVgDa,SAACnD,EAAMmJ,GAC5BnJ,EAAK6C,IAAI,QACXW,OAAOrB,KAAKgH,GAAM9G,SAAQ,SAACD,GACzB0H,EAAS9J,GAAMsC,IAAIF,EAAK+G,EAAK/G,OAG/BpC,EAAKsC,IAAI,OAAQ,IAAI8G,IAAI5F,OAAOC,QAAQ0F"}
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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