import{f as j,g as k,M as A,h as _,i as G,R as H,F as W,c as z,d as F,p as q,j as K}from"./EditorOutline-DrybdBHq.chunk.mjs";import{W as N,M as U,a as V,R as J,C as L,A as Q}from"./MenuBar-aZwqxDEv.chunk.mjs";import{a as X}from"./index-CRQM6PVi.chunk.mjs";import{w as b,p as Y}from"./vue.runtime.esm-CLeelJur.chunk.mjs";import{A as Z}from"./MediaHandler.provider-CTjO6aKX.chunk.mjs";import{n as ee}from"./_plugin-vue2_normalizer-wd1ZAbRr.chunk.mjs";import"./NcLoadingIcon-ZJnsd-es.chunk.mjs";import"./emoji-picker-MDCGxHB0.chunk.mjs";import"./index-DxwFe63_.chunk.mjs";import"./logger-CoS2pszN.chunk.mjs";import"./index-Dl858C8_.chunk.mjs";import"./NcNoteCard-Dz5-u2BY-S2qe9Sjm.chunk.mjs";import"./NcCheckboxRadioSwitch-DAPHFb0L-BMVa4UgQ.chunk.mjs";var I=200,u=function(){};u.prototype.append=function(t){return t.length?(t=u.from(t),!this.length&&t||t.length=e?u.empty:this.sliceInner(Math.max(0,t),Math.min(this.length,e))},u.prototype.get=function(t){if(!(t<0||t>=this.length))return this.getInner(t)},u.prototype.forEach=function(t,e,n){e===void 0&&(e=0),n===void 0&&(n=this.length),e<=n?this.forEachInner(t,e,n,0):this.forEachInvertedInner(t,e,n,0)},u.prototype.map=function(t,e,n){e===void 0&&(e=0),n===void 0&&(n=this.length);var i=[];return this.forEach(function(o,r){return i.push(t(o,r))},e,n),i},u.from=function(t){return t instanceof u?t:t&&t.length?new B(t):u.empty};var B=function(t){function e(i){t.call(this),this.values=i}t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e;var n={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,o){return i==0&&o==this.length?this:new e(this.values.slice(i,o))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,o,r,s){for(var a=o;a=r;a--)if(i(this.values[a],s+a)===!1)return!1},e.prototype.leafAppend=function(i){if(this.length+i.length<=I)return new e(this.values.concat(i.flatten()))},e.prototype.leafPrepend=function(i){if(this.length+i.length<=I)return new e(i.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(e.prototype,n),e}(u);u.empty=new B([]);var te=function(t){function e(n,i){t.call(this),this.left=n,this.right=i,this.length=n.length+i.length,this.depth=Math.max(n.depth,i.depth)+1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(n){return ns&&this.right.forEachInner(n,Math.max(i-s,0),Math.min(this.length,o)-s,r+s)===!1)return!1},e.prototype.forEachInvertedInner=function(n,i,o,r){var s=this.left.length;if(i>s&&this.right.forEachInvertedInner(n,i-s,Math.max(o,s)-s,r+s)===!1||o=o?this.right.slice(n-o,i-o):this.left.slice(n,o).append(this.right.slice(0,i-o))},e.prototype.leafAppend=function(n){var i=this.right.leafAppend(n);if(i)return new e(this.left,i)},e.prototype.leafPrepend=function(n){var i=this.left.leafPrepend(n);if(i)return new e(i,this.right)},e.prototype.appendInner=function(n){return this.left.depth>=Math.max(this.right.depth,n.depth)+1?new e(this.left,new e(this.right,n)):new e(this,n)},e}(u),P=u;const ne=500;class m{constructor(e,n){this.items=e,this.eventCount=n}popEvent(e,n){if(this.eventCount==0)return null;let i=this.items.length;for(;;i--)if(this.items.get(i-1).selection){--i;break}let o,r;n&&(o=this.remapping(i,this.items.length),r=o.maps.length);let s=e.tr,a,h,d=[],c=[];return this.items.forEach((l,p)=>{if(!l.step){o||(o=this.remapping(i,p+1),r=o.maps.length),r--,c.push(l);return}if(o){c.push(new g(l.map));let f=l.step.map(o.slice(r)),y;f&&s.maybeStep(f).doc&&(y=s.mapping.maps[s.mapping.maps.length-1],d.push(new g(y,void 0,void 0,d.length+c.length))),r--,y&&o.appendMap(y,r)}else s.maybeStep(l.step);if(l.selection)return a=o?l.selection.map(o.slice(r)):l.selection,h=new m(this.items.slice(0,i).append(c.reverse().concat(d)),this.eventCount-1),!1},this.items.length,0),{remaining:h,transform:s,selection:a}}addTransform(e,n,i,o){let r=[],s=this.eventCount,a=this.items,h=!o&&a.length?a.get(a.length-1):null;for(let c=0;coe&&(a=ie(a,d),s-=d),new m(a.append(r),s)}remapping(e,n){let i=new A;return this.items.forEach((o,r)=>{let s=o.mirrorOffset!=null&&r-o.mirrorOffset>=e?i.maps.length-o.mirrorOffset:void 0;i.appendMap(o.map,s)},e,n),i}addMaps(e){return this.eventCount==0?this:new m(this.items.append(e.map(n=>new g(n))),this.eventCount)}rebased(e,n){if(!this.eventCount)return this;let i=[],o=Math.max(0,this.items.length-n),r=e.mapping,s=e.steps.length,a=this.eventCount;this.items.forEach(p=>{p.selection&&a--},o);let h=n;this.items.forEach(p=>{let f=r.getMirror(--h);if(f==null)return;s=Math.min(s,f);let y=r.maps[f];if(p.step){let $=e.steps[f].invert(e.docs[f]),T=p.selection&&p.selection.map(r.slice(h+1,f));T&&a++,i.push(new g(y,$,T))}else i.push(new g(y))},o);let d=[];for(let p=n;pne&&(l=l.compress(this.items.length-i.length)),l}emptyItemCount(){let e=0;return this.items.forEach(n=>{n.step||e++}),e}compress(e=this.items.length){let n=this.remapping(0,e),i=n.maps.length,o=[],r=0;return this.items.forEach((s,a)=>{if(a>=e)o.push(s),s.selection&&r++;else if(s.step){let h=s.step.map(n.slice(i)),d=h&&h.getMap();if(i--,d&&n.appendMap(d,i),h){let c=s.selection&&s.selection.map(n.slice(i));c&&r++;let l=new g(d.invert(),h,c),p,f=o.length-1;(p=o.length&&o[f].merge(l))?o[f]=p:o.push(l)}}else s.map&&i--},this.items.length,0),new m(P.from(o.reverse()),r)}}m.empty=new m(P.empty,0);function ie(t,e){let n;return t.forEach((i,o)=>{if(i.selection&&e--==0)return n=o,!1}),t.slice(n)}class g{constructor(e,n,i,o){this.map=e,this.step=n,this.selection=i,this.mirrorOffset=o}merge(e){if(this.step&&e.step&&!e.selection){let n=e.step.merge(this.step);if(n)return new g(n.getMap().invert(),n,this.selection)}}}class v{constructor(e,n,i,o,r){this.done=e,this.undone=n,this.prevRanges=i,this.prevTime=o,this.prevComposition=r}}const oe=20;function re(t,e,n,i){let o=n.getMeta(w),r;if(o)return o.historyState;n.getMeta(pe)&&(t=new v(t.done,t.undone,null,0,-1));let s=n.getMeta("appendedTransaction");if(n.steps.length==0)return t;if(s&&s.getMeta(w))return s.getMeta(w).redo?new v(t.done.addTransform(n,void 0,i,M(e)),t.undone,O(n.mapping.maps),t.prevTime,t.prevComposition):new v(t.done,t.undone.addTransform(n,void 0,i,M(e)),null,t.prevTime,t.prevComposition);if(n.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let a=n.getMeta("composition"),h=t.prevTime==0||!s&&t.prevComposition!=a&&(t.prevTime<(n.time||0)-i.newGroupDelay||!se(n,t.prevRanges)),d=s?C(t.prevRanges,n.mapping):O(n.mapping.maps);return new v(t.done.addTransform(n,h?e.selection.getBookmark():void 0,i,M(e)),m.empty,d,n.time,a??t.prevComposition)}else return(r=n.getMeta("rebased"))?new v(t.done.rebased(n,r),t.undone.rebased(n,r),C(t.prevRanges,n.mapping),t.prevTime,t.prevComposition):new v(t.done.addMaps(n.mapping.maps),t.undone.addMaps(n.mapping.maps),C(t.prevRanges,n.mapping),t.prevTime,t.prevComposition)}function se(t,e){if(!e)return!1;if(!t.docChanged)return!0;let n=!1;return t.mapping.maps[0].forEach((i,o)=>{for(let r=0;r=e[r]&&(n=!0)}),n}function O(t){let e=[];for(let n=t.length-1;n>=0&&e.length==0;n--)t[n].forEach((i,o,r,s)=>e.push(r,s));return e}function C(t,e){if(!t)return null;let n=[];for(let i=0;i{let o=w.getState(n);if(!o||(t?o.undone:o.done).eventCount==0)return!1;if(i){let r=ae(o,n,t);r&&i(e?r.scrollIntoView():r)}return!0}}const x=S(!1,!0),D=S(!0,!0),le=_.create({name:"history",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:t,dispatch:e})=>x(t,e),redo:()=>({state:t,dispatch:e})=>D(t,e)}},addProseMirrorPlugins(){return[he(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),ue={name:"MarkdownContentEditor",components:{ContentContainer:L,ReadonlyBar:J,MenuBar:V,MainContainer:U,Wrapper:N},provide(){const t={};return Object.defineProperties(t,{[Z]:{get:()=>this.$attachmentResolver??null}}),t},props:{fileId:{type:Number,default:null},content:{type:String,required:!0},readOnly:{type:Boolean,default:!1},relativePath:{type:String,default:""},shareToken:{type:String,default:null},showMenuBar:{type:Boolean,default:!0},showOutlineOutside:{type:Boolean,default:!1}},emits:["update:content"],setup(t){const e=[H.configure({extensions:[le]}),W],n=new z({extensions:e}),{setEditable:i,setContent:o}=F(n);return b(()=>t.content,r=>{o(r)}),i(!t.readOnly),b(()=>t.readOnly,r=>{i(!r)}),q(n),Y(K,{isPublic:!1,isRichEditor:!0,isRichWorkspace:!1}),{editor:n,setContent:o}},created(){this.setContent(this.content,{addToHistory:!1}),this.editor.on("create",()=>{this.$emit("ready"),this.$parent.$emit("ready")}),this.editor.on("update",({editor:t})=>{const e=G(t.schema).serialize(t.state.doc);this.emit("update:content",{json:t.state.doc,markdown:e})}),this.fileId&&(this.$attachmentResolver=new Q({currentDirectory:this.relativePath?.match(/.*\//),user:X(),shareToken:this.shareToken,fileId:this.fileId}))},beforeDestroy(){this.editor.destroy()},methods:{outlineToggled(t){this.emit("outline-toggled",t)},emit(t,e){this.$emit(t,e),this.$parent?.$emit(t,e)}}};var de=function(){var t=this,e=t._self._c;return e("Wrapper",{attrs:{"content-loaded":!0,"show-outline-outside":t.showOutlineOutside},on:{"outline-toggled":t.outlineToggled}},[e("MainContainer",[t.showMenuBar?[t.readOnly?t._t("readonlyBar",function(){return[e("ReadonlyBar")]}):e("MenuBar",{attrs:{autohide:!1}})]:t._e(),e("ContentContainer",{attrs:{"read-only":t.readOnly}})],2)],1)},ce=[],fe=ee(ue,de,ce,!1,null,null);const ke=fe.exports;export{ke as default}; //# sourceMappingURL=MarkdownContentEditor-DmNwqD-y.chunk.mjs.map