@thebase/ui
Version:
CDN-installable Owl and Bootstrap 5 UI component library.
2 lines (1 loc) • 15.7 kB
JavaScript
import{d as R,n as U,t as q}from"./chunk-R43NMSZO.js";import{G as I,T as P,U as Y,_a as K}from"./chunk-XNCXGIZE.js";import{a as $,d as T}from"./chunk-OQJVATGH.js";function pe(n){let e=n.schema.cached.changeSetIDs||(n.schema.cached.changeSetIDs=Object.create(null)),t=e[n.name];return t==null&&(e[n.name]=t=Object.keys(n.schema.nodes).indexOf(n.name)+1),t}var V={encodeCharacter:n=>n,encodeNodeStart:n=>n.type.name,encodeNodeEnd:n=>-pe(n.type),compareTokens:(n,e)=>n===e};function F(n,e,t,o,r){for(let f=0,i=0;f<n.childCount;f++){let l=n.child(f),s=i+l.nodeSize,a=Math.max(i,t),u=Math.min(s,o);if(a<u)if(l.isText)for(let c=a;c<u;c++)r.push(e.encodeCharacter(l.text.charCodeAt(c-i),l.marks));else l.isLeaf?r.push(e.encodeNodeStart(l)):(a==i&&r.push(e.encodeNodeStart(l)),F(l.content,e,Math.max(i+1,a)-i-1,Math.min(s-1,u)-i-1,r),u==s&&r.push(e.encodeNodeEnd(l)));i=s}return r}var Z=2500;function ge(n,e){return Math.min(15,Math.max(2,Math.floor(Math.max(n,e)/10)))}function Q(n,e,t,o=V){if(Math.max(t.toA-t.fromA,t.toB,t.fromB)>Z)return[t];let r=F(n,o,t.fromA,t.toA,[]),f=F(e,o,t.fromB,t.toB,[]);return Ae(r,f,t,o.compareTokens)}function Ae(n,e,t,o){let r=0,f=n.length,i=e.length;for(;r<n.length&&r<e.length&&o(n[r],e[r]);)r++;if(r==n.length&&r==e.length)return[];for(;f>r&&i>r&&o(n[f-1],e[i-1]);)f--,i--;if(f==r||i==r||f==i&&f==r+1)return[t.slice(r,f,r,i)];let l=f-r,s=i-r,a=Math.min(Z,l+s),u=[],c=new Int16Array((a+1)*2).fill(-1);for(let d=0;d<=a;d++){for(let h=-d;h<=d;h+=2){let m=c[h+1+a],B=c[h-1+a],g=m<B?B:m+1,D=g+h;for(;g<l&&D<s&&o(n[r+g],e[r+D]);)g++,D++;if(c[h+a]=g,g>=l&&D>=s){let x=[],z=ge(f-r,i-r),C=-1,M=-1,S=-1,O=-1,W=(j,k,N,me)=>{C>-1&&C<k+z?(C=j,S=N):(C>-1&&x.push(t.slice(C,M,S,O)),C=j,M=k,S=N,O=me)};for(let j=d-1;j>=0;j--){let k=c[h+1+a],N=c[h-1+a];k<N?(h--,g=N+r,D=g+h,W(g,g,D,D+1)):(h++,g=k+r,D=g+h,W(g,g+1,D,D)),c=u[j>>1]}return C>-1&&x.push(t.slice(C,M,S,O)),x.reverse()}}d%2==0&&u.push(c.slice())}return[t]}var p=class n{constructor(e,t){this.length=e,this.data=t}cut(e){return e==this.length?this:new n(e,this.data)}static slice(e,t,o){if(t==o)return n.none;if(t==0&&o==n.len(e))return e;let r=[];for(let f=0,i=0;i<o;f++){let l=e[f],s=i+l.length,a=Math.min(o,s)-Math.max(t,i);a>0&&r.push(l.cut(a)),i=s}return r}static join(e,t,o){if(e.length==0)return t;if(t.length==0)return e;let r=o(e[e.length-1].data,t[0].data);if(r==null)return e.concat(t);let f=e.slice(0,e.length-1);f.push(new n(e[e.length-1].length+t[0].length,r));for(let i=1;i<t.length;i++)f.push(t[i]);return f}static len(e){let t=0;for(let o=0;o<e.length;o++)t+=e[o].length;return t}};p.none=[];var w=class n{constructor(e,t,o,r,f,i){this.fromA=e,this.toA=t,this.fromB=o,this.toB=r,this.deleted=f,this.inserted=i}get lenA(){return this.toA-this.fromA}get lenB(){return this.toB-this.fromB}slice(e,t,o,r){return e==0&&o==0&&t==this.toA-this.fromA&&r==this.toB-this.fromB?this:new n(this.fromA+e,this.fromA+t,this.fromB+o,this.fromB+r,p.slice(this.deleted,e,t),p.slice(this.inserted,o,r))}static merge(e,t,o){if(e.length==0)return t;if(t.length==0)return e;let r=[];for(let f=0,i=0,l=e[0],s=t[0];;){if(!l&&!s)return r;if(l&&(!s||l.toB<s.fromA)){let a=i?t[i-1].toB-t[i-1].toA:0;r.push(a==0?l:new n(l.fromA,l.toA,l.fromB+a,l.toB+a,l.deleted,l.inserted)),l=f++==e.length?null:e[f]}else if(s&&(!l||s.toA<l.fromB)){let a=f?e[f-1].toB-e[f-1].toA:0;r.push(a==0?s:new n(s.fromA-a,s.toA-a,s.fromB,s.toB,s.deleted,s.inserted)),s=i++==t.length?null:t[i]}else{let a=Math.min(l.fromB,s.fromA),u=Math.min(l.fromA,s.fromA-(f?e[f-1].toB-e[f-1].toA:0)),c=u,d=Math.min(s.fromB,l.fromB+(i?t[i-1].toB-t[i-1].toA:0)),h=d,m=p.none,B=p.none,g=!1,D=!1;for(;;){let x=l?a>=l.fromB?l.toB:l.fromB:2e8,z=s?a>=s.fromA?s.toA:s.fromA:2e8,C=Math.min(x,z),M=l&&a>=l.fromB,S=s&&a>=s.fromA;if(!M&&!S)break;M&&a==l.fromB&&!g&&(m=p.join(m,l.deleted,o),c+=l.lenA,g=!0),M&&!S&&(B=p.join(B,p.slice(l.inserted,a-l.fromB,C-l.fromB),o),h+=C-a),S&&a==s.fromA&&!D&&(B=p.join(B,s.inserted,o),h+=s.lenB,D=!0),S&&!M&&(m=p.join(m,p.slice(s.deleted,a-s.fromA,C-s.fromA),o),c+=C-a),M&&C==l.toB&&(l=f++==e.length?null:e[f],g=!1),S&&C==s.toA&&(s=i++==t.length?null:t[i],D=!1),a=C}(u<c||d<h)&&r.push(new n(u,c,d,h,m,B))}}}static fromJSON(e){return new n(e.fromA,e.toA,e.fromB,e.toB,e.deleted.map(t=>new p(t.length,t.data)),e.inserted.map(t=>new p(t.length,t.data)))}toJSON(){return this}},Be;try{Be=new RegExp("[\\p{Alphabetic}_]","u")}catch{}var v=class n{constructor(e,t){this.config=e,this.changes=t}addSteps(e,t,o){let r=[];for(let s=0;s<t.length;s++){let a=Array.isArray(o)?o[s]:o,u=0;t[s].forEach((c,d,h,m)=>{r.push(new w(c+u,d+u,h,m,c==d?p.none:[new p(d-c,a)],h==m?p.none:[new p(m-h,a)])),u=m-h-(d-c)})}if(r.length==0)return this;let f=L(r,this.config.combine),i=w.merge(this.changes,f,this.config.combine),l=i;for(let s=0;s<l.length;s++){let a=l[s];if(a.fromA==a.toA||a.fromB==a.toB||!f.some(c=>c.toB>a.fromB&&c.fromB<a.toB))continue;let u=Q(this.config.doc.content,e.content,a,this.config.encoder);u.length==1&&u[0].fromB==0&&u[0].toB==a.toB-a.fromB||(l==i&&(l=i.slice()),u.length==1?l[s]=u[0]:(l.splice(s,1,...u),s+=u.length-1))}return new n(this.config,l)}get startDoc(){return this.config.doc}map(e){let t=o=>{let r=e(o);return r===o.data?o:new p(o.length,r)};return new n(this.config,this.changes.map(o=>new w(o.fromA,o.toA,o.fromB,o.toB,o.deleted.map(t),o.inserted.map(t))))}changedRange(e,t){if(e==this)return null;let o=t&&Ce(t),r=o?o.toB-o.fromB-(o.toA-o.fromA):0;function f(c){return!o||c<=o.fromA?c:c+r}let i=o?o.fromB:2e8,l=o?o.toB:-2e8;function s(c,d=c){i=Math.min(c,i),l=Math.max(d,l)}let a=this.changes,u=e.changes;for(let c=0,d=0;c<a.length&&d<u.length;){let h=a[c],m=u[d];h&&m&&De(h,m,f)?(c++,d++):m&&(!h||f(h.fromB)>=m.fromB)?(s(m.fromB,m.toB),d++):(s(f(h.fromB),f(h.toB)),c++)}return i<=l?{from:i,to:l}:null}static create(e,t=(f,i)=>f===i?f:null,o=V,r=[]){return new n({combine:t,doc:e,encoder:o},r)}};v.computeDiff=Q;function L(n,e,t=0,o=n.length){if(o==t+1)return[n[t]];let r=t+o>>1;return w.merge(L(n,e,t,r),L(n,e,r,o),e)}function G(n){let e=2e8,t=-2e8;for(let o=0;o<n.length;o++){let r=n[o];e!=2e8&&(e=r.map(e,-1),t=r.map(t,1)),r.forEach((f,i,l,s)=>{e=Math.min(e,l),t=Math.max(t,s)})}return e==2e8?null:{from:e,to:t}}function Ce(n){let e=G(n);if(!e)return null;let t=G(n.map(o=>o.invert()).reverse());return{fromA:t.from,toA:t.to,fromB:e.from,toB:e.to}}function De(n,e,t){return t(n.fromB)==e.fromB&&t(n.toB)==e.toB&&H(n.deleted,e.deleted)&&H(n.inserted,e.inserted)}function H(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(n[t].length!=e[t].length||n[t].data!==e[t].data)return!1;return!0}function y(n,e){return Object.assign(n,{meta:{package:"@milkdown/plugin-diff",...e}}),n}var _=500;function Se(n={}){let e=new WeakMap,t=new WeakMap;function o(r){let f=e.get(r);if(f!=null)return f;let i=r.attrs,l=i?Object.keys(i).filter(s=>i[s]!=null).sort():[];if(l.length===0)f=r.type.name;else{let s={};for(let a of l)s[a]=i[a];f=`${r.type.name}:${JSON.stringify(s)}`}return e.set(r,f),f}return{encodeCharacter:(r,f)=>{if(f.length===0)return r;let i=t.get(f);return i==null&&(i=f.map(o).join(","),t.set(f,i)),`${r}:${i}`},encodeNodeStart:r=>{let f=r.attrs;if(f&&Object.keys(f).length>0){let i=n[r.type.name]??[],l=Object.keys(f).filter(s=>{if(i.includes(s))return!1;let a=r.type.spec.attrs?.[s]?.default;return f[s]!==a});if(l.length>0){let s={};for(let a of l.sort())s[a]=f[a];return`${r.type.name}:${JSON.stringify(s)}`}}return r.type.name},encodeNodeEnd:r=>{let f=r.type.schema,i=f.cached.changeSetIDs||(f.cached.changeSetIDs=Object.create(null)),l=i[r.type.name];return l==null&&(i[r.type.name]=l=Object.keys(f.nodes).indexOf(r.type.name)+1),-l},compareTokens:(r,f)=>r===f}}function re(n,e,t){let o=t.get(n);if(o!=null)return o;let r=[String(e.encodeNodeStart(n))];if(n.isText){let i=n.text;for(let l=0;l<i.length;l++)r.push(":"+String(e.encodeCharacter(i.charCodeAt(l),n.marks)))}else n.content.forEach(i=>{r.push("/"+re(i,e,t))});r.push("\\"+String(e.encodeNodeEnd(n)));let f=r.join("");return t.set(n,f),f}function ee(n,e,t){let o=[],r=0;return n.content.forEach(f=>{o.push({node:f,offset:r,size:f.nodeSize,signature:re(f,t.encoder,t.sigCache)}),r+=f.nodeSize}),{node:n,contentStart:e,content:o}}function we(n,e){let t=n.length,o=e.length,r=Array.from({length:t+1},()=>Array.from({length:o+1},()=>0));for(let s=t-1;s>=0;s--)for(let a=o-1;a>=0;a--)n[s].signature===e[a].signature?r[s][a]=r[s+1][a+1]+1:r[s][a]=Math.max(r[s+1][a],r[s][a+1]);let f=[],i=0,l=0;for(;i<t&&l<o;)n[i].signature===e[l].signature?(f.push([i,l]),i++,l++):r[i+1][l]>=r[i][l+1]?i++:l++;return f}function ye(n,e){if(n.type!==e.type)return!1;let t=n.type;return!(t.isTextblock||t.isAtom||t.spec.code===!0||!t.isBlock)}function oe(n,e,t){return w.fromJSON({fromA:n.fromA+e,toA:n.toA+e,fromB:n.fromB+t,toB:n.toB+t,deleted:n.deleted.map(o=>({length:o.length,data:o.data})),inserted:n.inserted.map(o=>({length:o.length,data:o.data}))})}function Me(n,e,t){let o=n.parent.copy($.from(n.node)),r=e.parent.copy($.from(e.node)),f=new I(0,o.content.size,new T(r.content,0,0));return v.create(o,void 0,t.encoder).addSteps(r,[f.getMap()],null).changes.map(i=>oe(i,n.abs,e.abs))}function te(n,e){let t=n.content;if(e<t.length)return n.contentStart+t[e].offset;if(e>0){let o=t[e-1];return n.contentStart+o.offset+o.size}return n.contentStart+n.node.content.size}function Re(n,e,t){return w.fromJSON({fromA:e,toA:e+n.size,fromB:t,toB:t,deleted:[{length:n.size,data:null}],inserted:[]})}function je(n,e,t){return w.fromJSON({fromA:e,toA:e,fromB:t,toB:t+n.size,deleted:[],inserted:[{length:n.size,data:null}]})}function ve(n,e,t,o,r){let f=new I(0,n.content.size,new T(e.content,0,0));return v.create(n,void 0,r.encoder).addSteps(e,[f.getMap()],null).changes.map(i=>oe(i,t,o))}function E(n,e,t,o,r){if(n.childCount>_||e.childCount>_)return ve(n,e,t,o,r);let f=ee(n,t,r),i=ee(e,o,r),l=we(f.content,i.content),s=[],a=0,u=0;for(let[c,d]of l)ne(f,i,{oldStart:a,oldEnd:c,newStart:u,newEnd:d},r,s),a=c+1,u=d+1;return ne(f,i,{oldStart:a,oldEnd:f.content.length,newStart:u,newEnd:i.content.length},r,s),s}function ne(n,e,t,o,r){let f=n.content,i=e.content,l=t.oldStart,s=t.newStart;for(;l<t.oldEnd||s<t.newEnd;){let a=l<t.oldEnd?f[l]:null,u=s<t.newEnd?i[s]:null,c=a&&u&&a.node.type===u.node.type;if(a&&u&&c){r.push(...xe(n,e,a,u,o)),l++,s++;continue}if(a&&(!u||!c)){let d=n.contentStart+a.offset;r.push(Re(a,d,te(e,s))),l++;continue}if(u){let d=e.contentStart+u.offset;r.push(je(u,te(n,l),d)),s++}}}function xe(n,e,t,o,r){let f=n.contentStart+t.offset,i=e.contentStart+o.offset;return ye(t.node,o.node)&&ke(t.node,o.node,r.encoder)?E(t.node,o.node,f+1,i+1,r):Me({node:t.node,parent:n.node,abs:f},{node:o.node,parent:e.node,abs:i},r)}function ke(n,e,t){return t.encodeNodeStart(n)===t.encodeNodeStart(e)}function Ne(n,e,t,o,r){let f=n.resolve(t),i=n.resolve(o),l=e.resolve(t),s=e.resolve(o),a=f.sharedDepth(o);if(l.sharedDepth(o)!==a)throw new RangeError(`computeDocDiff: range [${t}, ${o}) resolves to different sharedDepth in old and new docs`);for(let B=0;B<=a;B++){if(r.encodeNodeStart(f.node(B))!==r.encodeNodeStart(l.node(B)))throw new RangeError(`computeDocDiff: ancestor at depth ${B} differs in type or non-ignored attrs along the path to the shared ancestor`);if(f.start(B)!==l.start(B))throw new RangeError(`computeDocDiff: ancestor at depth ${B} starts at different absolute positions in old and new docs (content before the range differs in size)`)}let u=f.node(a);if(u.isTextblock)throw new RangeError(`computeDocDiff: range [${t}, ${o}) lands inside a textblock; widen the range to a block boundary`);if(f.depth!==a||i.depth!==a||l.depth!==a||s.depth!==a)throw new RangeError(`computeDocDiff: range [${t}, ${o}) endpoints must be aligned to child boundaries of the shared ancestor`);let c=l.node(a),d=f.start(a),h=t-d,m=o-d;return{oldCut:u.copy(u.content.cut(h,m)),newCut:c.copy(c.content.cut(h,m)),cutAbsStart:t}}function X(n,e,t){let o=Se(t?.ignoreAttrs),r={encoder:o,sigCache:new WeakMap},f=n.content.size,i=e.content.size,l=t?.range;if(l==null)return E(n,e,0,0,r);let s=Math.min(f,i),a=Math.max(0,Math.min(l.from??0,s)),u=Math.max(a,Math.min(l.to??s,s));if(a===u)return[];if(a===0&&u===s&&f===i)return E(n,e,0,0,r);let c=Ne(n,e,a,u,o);return E(c.oldCut,c.newCut,c.cutAbsStart,c.cutAbsStart,r)}var J=q({ignoreAttrs:{heading:["id"]}},"diffConfig");y(J,{displayName:"Ctx<diffConfig>",group:"Diff"});var A=new Y("MILKDOWN_DIFF");function Ee(n,e,t){let o=X(n,e.newDoc,t);return{...e,changes:o}}function be(n,e){return e.some(t=>n.fromB<t.toB&&n.toB>t.fromB)}function b(n){return n.changes.filter(e=>!be(e,n.rejectedRanges))}var fe=U(n=>{let e=n.get(J.key);return new P({key:A,state:{init:()=>null,apply(t,o,r,f){let i=t.getMeta(A);if(!o){if(i?.type==="start"){let a=X(f.doc,i.newDoc,{ignoreAttrs:e.ignoreAttrs});return{newDoc:i.newDoc,changes:a,rejectedRanges:[],active:!0}}return null}let l=o;if(t.docChanged&&l.active&&(l=Ee(f.doc,l,{ignoreAttrs:e.ignoreAttrs})),!i)return l;let s;switch(i.type){case"start":{let a=X(f.doc,i.newDoc,{ignoreAttrs:e.ignoreAttrs});return{newDoc:i.newDoc,changes:a,rejectedRanges:[],active:!0}}case"accept":case"acceptRange":s=l;break;case"reject":s={...l,rejectedRanges:[...l.rejectedRanges,{fromB:i.fromB,toB:i.toB}]};break;case"rejectRange":s={...l,rejectedRanges:[...l.rejectedRanges,{fromB:i.range.fromB,toB:i.range.toB}]};break;case"acceptAll":case"clear":return null;default:return l}return s.active&&b(s).length===0?null:s}},filterTransaction(t,o){return!A.getState(o)?.active||t.getMeta(A)?!0:!t.docChanged}})});y(fe,{displayName:"Prose<diff>",group:"Diff"});function ze(n,e){let t=b(e);for(let o=t.length-1;o>=0;o--){let r=t[o],f=e.newDoc.slice(r.fromB,r.toB);n=n.replace(r.fromA,r.toA,f)}return n}var ie=R("StartDiffReview",n=>e=>(t,o)=>{if(e==null)return!1;let r=n.get(K)(e);return r?(o&&o(t.tr.setMeta(A,{type:"start",newDoc:r})),!0):!1});y(ie,{displayName:"Command<startDiffReview>",group:"Diff"});var le=R("StartDiffReviewFromDoc",()=>n=>(e,t)=>!n||n.type!==e.doc.type?!1:(t&&t(e.tr.setMeta(A,{type:"start",newDoc:n})),!0));y(le,{displayName:"Command<startDiffReviewFromDoc>",group:"Diff"});var se=R("AcceptDiffChunk",()=>n=>(e,t)=>{if(n==null)return!1;let o=A.getState(e);if(!o)return!1;let r=b(o)[n];if(!r)return!1;if(t){let f=o.newDoc.slice(r.fromB,r.toB),i=e.tr.replace(r.fromA,r.toA,f);i=i.setMeta(A,{type:"accept",changeIndex:n}),t(i)}return!0});y(se,{displayName:"Command<acceptDiffChunk>",group:"Diff"});var ae=R("RejectDiffChunk",()=>n=>(e,t)=>{if(n==null)return!1;let o=A.getState(e);if(!o)return!1;let r=b(o)[n];return r?(t&&t(e.tr.setMeta(A,{type:"reject",fromB:r.fromB,toB:r.toB})),!0):!1});y(ae,{displayName:"Command<rejectDiffChunk>",group:"Diff"});var ce=R("AcceptDiffRange",()=>n=>(e,t)=>{if(!n)return!1;let o=A.getState(e);if(!o)return!1;if(t){let r=o.newDoc.slice(n.fromB,n.toB),f=e.tr.replace(n.fromA,n.toA,r);f=f.setMeta(A,{type:"acceptRange",range:n}),t(f)}return!0});y(ce,{displayName:"Command<acceptDiffRange>",group:"Diff"});var ue=R("RejectDiffRange",()=>n=>(e,t)=>!n||!A.getState(e)?!1:(t&&t(e.tr.setMeta(A,{type:"rejectRange",range:n})),!0));y(ue,{displayName:"Command<rejectDiffRange>",group:"Diff"});var de=R("AcceptAllDiffs",()=>()=>(n,e)=>{let t=A.getState(n);return t?(e&&e((t.rejectedRanges.length===0?n.tr.replaceWith(0,n.doc.content.size,t.newDoc.content):ze(n.tr,t)).setMeta(A,{type:"acceptAll"})),!0):!1});y(de,{displayName:"Command<acceptAllDiffs>",group:"Diff"});var he=R("ClearDiffReview",()=>()=>(n,e)=>A.getState(n)?(e&&e(n.tr.setMeta(A,{type:"clear"})),!0):!1);y(he,{displayName:"Command<clearDiffReview>",group:"Diff"});var Je=[J,fe,ie,le,se,ce,ae,ue,de,he];export{X as a,J as b,A as c,be as d,b as e,fe as f,ie as g,le as h,se as i,ae as j,ce as k,ue as l,de as m,he as n,Je as o};