зеркало из https://github.com/nextcloud/text.git
3 строки
12 KiB
JavaScript
3 строки
12 KiB
JavaScript
/*! third party licenses: js/vendor.LICENSE.txt */
|
|
import{C as D,R as _,a as j,M as A,W as H,A as G}from"./Wrapper-CqeHBx_S.chunk.mjs";import{m as $,P as z,ae as W,E as F,$ as U,T as q,_ as K,ac as N}from"./RichText-Cc-yfyjL.chunk.mjs";import{g as V}from"./modulepreload-polyfill-DMTabKmO.chunk.mjs";import{i as J,b as L,j as Q}from"./MediaHandler.provider-CSBQhvYP.chunk.mjs";import{n as X}from"./_plugin-vue2_normalizer-XF5BqDH-.chunk.mjs";import"./vue.runtime.esm-fZsuJKoo.chunk.mjs";import"./index-WINsn-uD.chunk.mjs";import"./emoji-picker-SoWZqoso.chunk.mjs";import"./index-hXSjL27_.chunk.mjs";import"./public-CBtR8U5E.chunk.mjs";import"./index-Ubm2itxG.chunk.mjs";import"./index-CyNrdWBa.chunk.mjs";import"./_plugin-vue2_normalizer-CQ6iBklL-DSXPAugt.chunk.mjs";import"./logger-B4T8Bva5.chunk.mjs";import"./index-DkzhscpN.chunk.mjs";var C=200,u=function(){};u.prototype.append=function(e){return e.length?(e=u.from(e),!this.length&&e||e.length<C&&this.leafAppend(e)||this.length<C&&e.leafPrepend(this)||this.appendInner(e)):this},u.prototype.prepend=function(e){return e.length?u.from(e).append(this):this},u.prototype.appendInner=function(e){return new Y(this,e)},u.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?u.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},u.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},u.prototype.forEach=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length),t<=n?this.forEachInner(e,t,n,0):this.forEachInvertedInner(e,t,n,0)},u.prototype.map=function(e,t,n){t===void 0&&(t=0),n===void 0&&(n=this.length);var r=[];return this.forEach(function(i,o){return r.push(e(i,o))},t,n),r},u.from=function(e){return e instanceof u?e:e&&e.length?new x(e):u.empty};var x=function(e){function t(r){e.call(this),this.values=r}e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t;var n={length:{configurable:!0},depth:{configurable:!0}};return t.prototype.flatten=function(){return this.values},t.prototype.sliceInner=function(r,i){return r==0&&i==this.length?this:new t(this.values.slice(r,i))},t.prototype.getInner=function(r){return this.values[r]},t.prototype.forEachInner=function(r,i,o,s){for(var a=i;a<o;a++)if(r(this.values[a],s+a)===!1)return!1},t.prototype.forEachInvertedInner=function(r,i,o,s){for(var a=i-1;a>=o;a--)if(r(this.values[a],s+a)===!1)return!1},t.prototype.leafAppend=function(r){if(this.length+r.length<=C)return new t(this.values.concat(r.flatten()))},t.prototype.leafPrepend=function(r){if(this.length+r.length<=C)return new t(r.flatten().concat(this.values))},n.length.get=function(){return this.values.length},n.depth.get=function(){return 0},Object.defineProperties(t.prototype,n),t}(u);u.empty=new x([]);var Y=function(e){function t(n,r){e.call(this),this.left=n,this.right=r,this.length=n.length+r.length,this.depth=Math.max(n.depth,r.depth)+1}return e&&(t.__proto__=e),t.prototype=Object.create(e&&e.prototype),t.prototype.constructor=t,t.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},t.prototype.getInner=function(n){return n<this.left.length?this.left.get(n):this.right.get(n-this.left.length)},t.prototype.forEachInner=function(n,r,i,o){var s=this.left.length;if(r<s&&this.left.forEachInner(n,r,Math.min(i,s),o)===!1||i>s&&this.right.forEachInner(n,Math.max(r-s,0),Math.min(this.length,i)-s,o+s)===!1)return!1},t.prototype.forEachInvertedInner=function(n,r,i,o){var s=this.left.length;if(r>s&&this.right.forEachInvertedInner(n,r-s,Math.max(i,s)-s,o+s)===!1||i<s&&this.left.forEachInvertedInner(n,Math.min(r,s),i,o)===!1)return!1},t.prototype.sliceInner=function(n,r){if(n==0&&r==this.length)return this;var i=this.left.length;return r<=i?this.left.slice(n,r):n>=i?this.right.slice(n-i,r-i):this.left.slice(n,i).append(this.right.slice(0,r-i))},t.prototype.leafAppend=function(n){var r=this.right.leafAppend(n);if(r)return new t(this.left,r)},t.prototype.leafPrepend=function(n){var r=this.left.leafPrepend(n);if(r)return new t(r,this.right)},t.prototype.appendInner=function(n){return this.left.depth>=Math.max(this.right.depth,n.depth)+1?new t(this.left,new t(this.right,n)):new t(this,n)},t}(u),k=u;const Z=500;class m{constructor(t,n){this.items=t,this.eventCount=n}popEvent(t,n){if(this.eventCount==0)return null;let r=this.items.length;for(;;r--)if(this.items.get(r-1).selection){--r;break}let i,o;n&&(i=this.remapping(r,this.items.length),o=i.maps.length);let s=t.tr,a,h,d=[],c=[];return this.items.forEach((l,p)=>{if(!l.step){i||(i=this.remapping(r,p+1),o=i.maps.length),o--,c.push(l);return}if(i){c.push(new g(l.map));let f=l.step.map(i.slice(o)),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))),o--,y&&i.appendMap(y,o)}else s.maybeStep(l.step);if(l.selection)return a=i?l.selection.map(i.slice(o)):l.selection,h=new m(this.items.slice(0,r).append(c.reverse().concat(d)),this.eventCount-1),!1},this.items.length,0),{remaining:h,transform:s,selection:a}}addTransform(t,n,r,i){let o=[],s=this.eventCount,a=this.items,h=!i&&a.length?a.get(a.length-1):null;for(let c=0;c<t.steps.length;c++){let l=t.steps[c].invert(t.docs[c]),p=new g(t.mapping.maps[c],l,n),f;(f=h&&h.merge(p))&&(p=f,c?o.pop():a=a.slice(0,a.length-1)),o.push(p),n&&(s++,n=void 0),i||(h=p)}let d=s-r.depth;return d>et&&(a=tt(a,d),s-=d),new m(a.append(o),s)}remapping(t,n){let r=new W;return this.items.forEach((i,o)=>{let s=i.mirrorOffset!=null&&o-i.mirrorOffset>=t?r.maps.length-i.mirrorOffset:void 0;r.appendMap(i.map,s)},t,n),r}addMaps(t){return this.eventCount==0?this:new m(this.items.append(t.map(n=>new g(n))),this.eventCount)}rebased(t,n){if(!this.eventCount)return this;let r=[],i=Math.max(0,this.items.length-n),o=t.mapping,s=t.steps.length,a=this.eventCount;this.items.forEach(p=>{p.selection&&a--},i);let h=n;this.items.forEach(p=>{let f=o.getMirror(--h);if(f==null)return;s=Math.min(s,f);let y=o.maps[f];if(p.step){let R=t.steps[f].invert(t.docs[f]),T=p.selection&&p.selection.map(o.slice(h+1,f));T&&a++,r.push(new g(y,R,T))}else r.push(new g(y))},i);let d=[];for(let p=n;p<s;p++)d.push(new g(o.maps[p]));let c=this.items.slice(0,i).append(d).append(r),l=new m(c,a);return l.emptyItemCount()>Z&&(l=l.compress(this.items.length-r.length)),l}emptyItemCount(){let t=0;return this.items.forEach(n=>{n.step||t++}),t}compress(t=this.items.length){let n=this.remapping(0,t),r=n.maps.length,i=[],o=0;return this.items.forEach((s,a)=>{if(a>=t)i.push(s),s.selection&&o++;else if(s.step){let h=s.step.map(n.slice(r)),d=h&&h.getMap();if(r--,d&&n.appendMap(d,r),h){let c=s.selection&&s.selection.map(n.slice(r));c&&o++;let l=new g(d.invert(),h,c),p,f=i.length-1;(p=i.length&&i[f].merge(l))?i[f]=p:i.push(l)}}else s.map&&r--},this.items.length,0),new m(k.from(i.reverse()),o)}}m.empty=new m(k.empty,0);function tt(e,t){let n;return e.forEach((r,i)=>{if(r.selection&&t--==0)return n=i,!1}),e.slice(n)}class g{constructor(t,n,r,i){this.map=t,this.step=n,this.selection=r,this.mirrorOffset=i}merge(t){if(this.step&&t.step&&!t.selection){let n=t.step.merge(this.step);if(n)return new g(n.getMap().invert(),n,this.selection)}}}class v{constructor(t,n,r,i,o){this.done=t,this.undone=n,this.prevRanges=r,this.prevTime=i,this.prevComposition=o}}const et=20;function nt(e,t,n,r){let i=n.getMeta(w),o;if(i)return i.historyState;n.getMeta(ot)&&(e=new v(e.done,e.undone,null,0,-1));let s=n.getMeta("appendedTransaction");if(n.steps.length==0)return e;if(s&&s.getMeta(w))return s.getMeta(w).redo?new v(e.done.addTransform(n,void 0,r,M(t)),e.undone,b(n.mapping.maps),e.prevTime,e.prevComposition):new v(e.done,e.undone.addTransform(n,void 0,r,M(t)),null,e.prevTime,e.prevComposition);if(n.getMeta("addToHistory")!==!1&&!(s&&s.getMeta("addToHistory")===!1)){let a=n.getMeta("composition"),h=e.prevTime==0||!s&&e.prevComposition!=a&&(e.prevTime<(n.time||0)-r.newGroupDelay||!rt(n,e.prevRanges)),d=s?I(e.prevRanges,n.mapping):b(n.mapping.maps);return new v(e.done.addTransform(n,h?t.selection.getBookmark():void 0,r,M(t)),m.empty,d,n.time,a!=null?a:e.prevComposition)}else return(o=n.getMeta("rebased"))?new v(e.done.rebased(n,o),e.undone.rebased(n,o),I(e.prevRanges,n.mapping),e.prevTime,e.prevComposition):new v(e.done.addMaps(n.mapping.maps),e.undone.addMaps(n.mapping.maps),I(e.prevRanges,n.mapping),e.prevTime,e.prevComposition)}function rt(e,t){if(!t)return!1;if(!e.docChanged)return!0;let n=!1;return e.mapping.maps[0].forEach((r,i)=>{for(let o=0;o<t.length;o+=2)r<=t[o+1]&&i>=t[o]&&(n=!0)}),n}function b(e){let t=[];for(let n=e.length-1;n>=0&&t.length==0;n--)e[n].forEach((r,i,o,s)=>t.push(o,s));return t}function I(e,t){if(!e)return null;let n=[];for(let r=0;r<e.length;r+=2){let i=t.map(e[r],1),o=t.map(e[r+1],-1);i<=o&&n.push(i,o)}return n}function it(e,t,n){let r=M(t),i=w.get(t).spec.config,o=(n?e.undone:e.done).popEvent(t,r);if(!o)return null;let s=o.selection.resolve(o.transform.doc),a=(n?e.done:e.undone).addTransform(o.transform,t.selection.getBookmark(),i,r),h=new v(n?a:o.remaining,n?o.remaining:a,null,0,-1);return o.transform.setSelection(s).setMeta(w,{redo:n,historyState:h})}let E=!1,O=null;function M(e){let t=e.plugins;if(O!=t){E=!1,O=t;for(let n=0;n<t.length;n++)if(t[n].spec.historyPreserveItems){E=!0;break}}return E}const w=new $("history"),ot=new $("closeHistory");function st(e={}){return e={depth:e.depth||100,newGroupDelay:e.newGroupDelay||500},new z({key:w,state:{init(){return new v(m.empty,m.empty,null,0,-1)},apply(t,n,r){return nt(n,r,t,e)}},config:e,props:{handleDOMEvents:{beforeinput(t,n){let r=n.inputType,i=r=="historyUndo"?P:r=="historyRedo"?S:null;return i?(n.preventDefault(),i(t.state,t.dispatch)):!1}}}})}function B(e,t){return(n,r)=>{let i=w.getState(n);if(!i||(e?i.undone:i.done).eventCount==0)return!1;if(r){let o=it(i,n,e);o&&r(t?o.scrollIntoView():o)}return!0}}const P=B(!1,!0),S=B(!0,!0),at=F.create({name:"history",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:e,dispatch:t})=>P(e,t),redo:()=>({state:e,dispatch:t})=>S(e,t)}},addProseMirrorPlugins(){return[st(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()}}}),pt={name:"MarkdownContentEditor",components:{ContentContainer:D,ReadonlyBar:_,MenuBar:j,MainContainer:A,Wrapper:H},provide(){const e={};return Object.defineProperties(e,{[J]:{get:()=>this.$editor},[L]:{get:()=>{var t;return(t=this.$attachmentResolver)!=null?t:null}},[Q]:{get:()=>!0}}),e},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"],computed:{htmlContent(){return this.renderHtml(this.content)}},watch:{content(){this.updateContent()}},created(){var e;this.$editor=this.createEditor(),this.$editor.setEditable(!this.readOnly),this.fileId&&(this.$attachmentResolver=new G({currentDirectory:(e=this.relativePath)==null?void 0:e.match(/.*\//),user:V(),shareToken:this.shareToken,fileId:this.fileId}))},updated(){this.$editor.setEditable(!this.readOnly)},beforeDestroy(){this.$editor.destroy()},methods:{renderHtml(e){return U.render(e)},extensions(){return[q.configure({component:this,extensions:[at]})]},createEditor(){return new K({content:this.htmlContent,extensions:this.extensions(),onUpdate:({editor:e})=>{const t=N(this.$editor.schema).serialize(e.state.doc);this.emit("update:content",{json:e.state.doc,markdown:t})},onCreate:({editor:e})=>{this.$emit("ready"),this.$parent.$emit("ready")}})},updateContent(){this.$editor.commands.setContent(this.htmlContent,!0)},outlineToggled(e){this.emit("outline-toggled",e)},emit(e,t){var n;this.$emit(e,t),(n=this.$parent)==null||n.$emit(e,t)}}};var ht=function(){var e=this,t=e._self._c;return t("Wrapper",{attrs:{"content-loaded":!0,"show-outline-outside":e.showOutlineOutside},on:{"outline-toggled":e.outlineToggled}},[t("MainContainer",[e.showMenuBar?[e.readOnly?e._t("readonlyBar",function(){return[t("ReadonlyBar")]}):t("MenuBar",{attrs:{autohide:!1}})]:e._e(),t("ContentContainer")],2)],1)},lt=[],ut=X(pt,ht,lt,!1,null,null);const $t=ut.exports;export{$t as default};
|