document-model 1.0.25 → 1.0.27
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.
- package/dist/browser/document-model.cjs +1 -1
- package/dist/browser/document-model.js +2 -2
- package/dist/browser/document.cjs +1 -1
- package/dist/browser/document.js +2 -2
- package/dist/browser/index.cjs +1 -1
- package/dist/browser/index.js +3 -3
- package/dist/browser/internal/{index-TAPWNyA9.js → index-99f8b333.js} +16 -6
- package/dist/{node/internal/index-FmPDtpIY.js → browser/internal/index-df4df518.js} +1 -1
- package/dist/{node/internal/index-lh4jt_0f.js → browser/internal/index-e019b5aa.js} +1 -1
- package/dist/browser/internal/{index-3haD_DrE.js → index-ff67644b.js} +1 -1
- package/dist/browser/internal/{object-jGU_rY7z.js → object-4b5800c0.js} +348 -352
- package/dist/browser/internal/{object-1BuggAcr.js → object-be1b0c52.js} +2 -2
- package/dist/browser/src/document/schema/index.d.ts +2 -2
- package/dist/browser/src/document/schema/types.d.ts +8 -12
- package/dist/browser/src/document/signal.d.ts +1 -0
- package/dist/browser/src/document/utils/index.d.ts +1 -0
- package/dist/browser/src/document-model/custom/reducers/versioning.d.ts +4 -4
- package/dist/browser/vitest.config.d.ts +2 -0
- package/dist/node/document-model.cjs +1 -1
- package/dist/node/document-model.js +3 -3
- package/dist/node/document.cjs +1 -1
- package/dist/node/document.js +3 -3
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.js +4 -4
- package/dist/{browser/internal/index-7bSWIChK.js → node/internal/index-2d55ed8c.js} +1 -1
- package/dist/node/internal/{index-pZl431ni.js → index-433d6a9b.js} +1 -1
- package/dist/{browser/internal/index-DQNkZhvL.js → node/internal/index-78c035e1.js} +1 -1
- package/dist/node/internal/{index-GpOpKG2W.js → index-a46dcf07.js} +17 -7
- package/dist/node/internal/{object-evJm9vYN.js → object-305e4c59.js} +244 -248
- package/dist/node/internal/object-ff6617a2.js +1 -0
- package/dist/node/src/document/schema/index.d.ts +2 -2
- package/dist/node/src/document/schema/types.d.ts +8 -12
- package/dist/node/src/document/signal.d.ts +1 -0
- package/dist/node/src/document/utils/index.d.ts +1 -0
- package/dist/node/src/document-model/custom/reducers/versioning.d.ts +4 -4
- package/dist/node/vitest.config.d.ts +2 -0
- package/package.json +23 -17
- package/dist/browser/jest.config.d.ts +0 -8
- package/dist/node/internal/object-pZF_UDWv.js +0 -1
- package/dist/node/jest.config.d.ts +0 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var wt=Object.defineProperty;var jt=(t,e,i)=>e in t?wt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var S=(t,e,i)=>(jt(t,typeof e!="symbol"?e+"":e,i),i);const g=require("immer"),Ot=require("json-stringify-deterministic"),s=require("zod"),St=require("crypto"),E=require("fs"),zt=require("https"),kt=require("path"),Z=require("jszip"),H=t=>t!=null,_t=s.z.any().refine(t=>H(t)),K=s.z.enum(["LOAD_STATE"]),W=s.z.enum(["PRUNE"]),V=s.z.enum(["REDO"]),G=s.z.enum(["SET_NAME"]),Q=s.z.enum(["UNDO"]);function Dt(){return s.z.object({__typename:s.z.literal("Action").optional(),type:s.z.string()})}function j(){return s.z.literal("global").or(s.z.literal("local"))}function X(){return s.z.union([Y(),et(),it(),nt(),at()])}function Et(){return s.z.object({__typename:s.z.literal("DocumentFile").optional(),data:s.z.string(),extension:s.z.string().nullable(),fileName:s.z.string().nullable(),mimeType:s.z.string()})}function Y(){return s.z.object({input:s.z.lazy(()=>F()),type:K,scope:j()})}function F(){return s.z.object({operations:s.z.number(),state:s.z.lazy(()=>tt())})}function tt(){return s.z.object({data:s.z.unknown().nullish(),name:s.z.string()})}function Nt(){return s.z.object({__typename:s.z.literal("Operation").optional(),hash:s.z.string(),index:s.z.number(),timestamp:s.z.string().datetime(),type:s.z.string()})}function et(){return s.z.object({input:s.z.lazy(()=>R()),type:W,scope:j()})}function R(){return s.z.object({end:s.z.number().nullish(),start:s.z.number().nullish()})}const I=s.z.number;function it(){return s.z.object({input:I(),type:V,scope:j()})}const q=s.z.string;function nt(){return s.z.object({input:q(),type:G,scope:s.z.literal("global")})}function At(){return s.z.object({__typename:s.z.literal("SetNameOperation").optional(),hash:s.z.string(),index:s.z.number(),input:s.z.string(),timestamp:s.z.string().datetime(),type:s.z.string()})}const P=s.z.number;function at(){return s.z.object({input:P(),type:Q,scope:j()})}const Tt=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:Dt,BaseActionSchema:X,DocumentFileSchema:Et,LoadStateActionInputSchema:F,LoadStateActionSchema:Y,LoadStateActionStateInputSchema:tt,Load_StateSchema:K,OperationSchema:Nt,OperationScopeSchema:j,PruneActionInputSchema:R,PruneActionSchema:et,PruneSchema:W,RedoActionInputSchema:I,RedoActionSchema:it,RedoSchema:V,SetNameActionInputSchema:q,SetNameActionSchema:nt,SetNameOperationSchema:At,Set_NameSchema:G,UndoActionInputSchema:P,UndoActionSchema:at,UndoSchema:Q,definedNonNullAnySchema:_t,isDefinedNonNullAny:H},Symbol.toStringTag,{value:"Module"}));function Ft(t,e){return{...t,name:e}}function Rt(t,e,i){const{scope:n,input:a}=e,p={document:t,action:e,skip:i};return g.produce(p,o=>{if(o.document.operations[n].length<1)throw new Error(`Cannot undo: no operations in history for scope "${n}"`);if(a<1)throw new Error("Invalid UNDO action: input value must be greater than 0");if(o.skip>0)throw new Error("Cannot undo: skip value from reducer cannot be used with UNDO action");const[c]=o.document.operations[n].slice(-1),u=c.type==="NOOP"&&c.skip>0;if(o.skip+=a,u&&(o.skip+=c.skip,o.document.operations[n].pop()),o.document.operations[n].length<o.skip)throw new Error("Cannot undo: you can't undo more operations than the ones in the scope history");const r=o.document.operations[n].length-1;let x=a,m=u?r-c.skip:r;for(;x>0&&m>=0;){const d=o.document.operations[n][m];d.type==="NOOP"&&d.skip>0?(m=m-(d.skip+1),o.skip+=d.skip+1):(o.document.clipboard.push({...d}),x--,m--)}o.action=$(n)})}function It(t,e,i){const{scope:n,input:a}=e,p={document:t,action:e,skip:i};return g.produce(p,o=>{if(o.skip>0)throw new Error("Cannot redo: skip value from reducer cannot be used with REDO action");if(a>1)throw new Error("Cannot redo: you can only redo one operation at a time");if(a<1)throw new Error("Invalid REDO action: invalid redo input value");if(o.document.clipboard.length<1)throw new Error("Cannot redo: no operations in the clipboard");const c=o.document.clipboard.findLastIndex(r=>r.scope===n);if(c<0)throw new Error(`Cannot redo: no operations in clipboard for scope "${n}"`);const u=o.document.clipboard.splice(c,1)[0];o.action=g.castDraft({type:u.type,scope:u.scope,input:u.input})})}function qt(t,e,i){const{scope:n}=e,a=t.operations[n];let{input:{start:p,end:o}}=e;p=p||0,o=o||a.length;const c=a.slice(p,o),u=a.slice(0,p),r=a.slice(o),x=z(t.initialState,{...t.operations,[n]:u.concat(c)},i),{name:m,state:d}=x,l=u.length,y=u.length?u[u.length-1].timestamp:r.length?r[0].timestamp:new Date().toISOString();return z(t.initialState,{...t.operations,[n]:[...u,{...C({name:m,state:d},c.length),timestamp:y,index:l,hash:L({state:d},"global")},...r.map((h,D)=>({...h,index:l+D+1}))]},i)}function Pt(t,e){return{...t,name:e.name,state:e.state??{global:{},local:{}}}}const ot="SET_NAME",b="UNDO",v="REDO",O="PRUNE",st="LOAD_STATE";function Mt(t,e){const i=t.revision[e.scope];return[b,v,O].includes(e.type)?i:i+1}function Lt(t,e){return{...t,revision:{...t.revision,[e.scope]:Mt(t,e)},lastModified:new Date().toISOString()}}function Ut(t,e,i=0){if([b,v,O].includes(e.type))return t;const{scope:n}=e,a=t.operations[n].slice(0,t.revision[n]);return a.push({...e,index:a.length,timestamp:new Date().toISOString(),hash:"",scope:n,skip:i}),{...t,operations:{...t.operations,[n]:a}}}function Ct(t,e,i=0){let n=Ut(t,e,i);return n=Lt(n,e),n}function $t(t,e,i){switch(X().parse(e),e.type){case ot:return Ft(t,e.input);case O:return qt(t,e,i);case st:return Pt(t,e.input.state);default:return t}}function pt(t,e,i){switch(e.type){case b:return Rt(t,e,i);case v:return It(t,e,i);default:return{document:t,action:e,skip:i}}}function M(t,e,i,n,a={}){const{skip:p,ignoreSkipOperations:o=!1}=a;let c={...e},u=p||0,r=t,x=[...t.clipboard];if(N(c)){const{skip:m,action:d,document:l}=pt(t,c,u);c=d,u=m,r=l,x=[...r.clipboard]}return A(c)&&(r=$t(r,c,i)),u>0&&!o&&(r=z(r.initialState,r.operations,i,void 0,void 0,void 0,{[c.scope]:u})),r=Ct(r,c,u),r=g.produce(r,m=>{const d=i(m.state,c,n),l=N(e)?[...x]:[];if(d)return g.castDraft({...r,clipboard:[...l],state:d});m.clipboard=g.castDraft([...l])}),g.produce(r,m=>{if([b,v,O].includes(c.type))return m;const d=c.scope||"global";m.operations[d][m.operations[d].length-1].hash=L(m,d),!A(c)&&c.attachments&&c.attachments.forEach(l=>{const{hash:y,...h}=l;m.attachments[y]={...h}})})}function Jt(t,e,i){const n=kt.join(t,e);return E.mkdirSync(t,{recursive:!0}),new Promise((a,p)=>{try{E.writeFile(n,i,{},o=>{o?p(o):a(n)})}catch(o){p(o)}})}function ct(t){return E.readFileSync(t)}function Bt(t){return new Promise((e,i)=>{zt.get(t,n=>{const a=[],p=n.headers["content-type"];n.on("data",o=>{a.push(o)}),n.on("end",()=>{e({buffer:Buffer.concat(a),mimeType:p})})}).on("error",n=>{i(n)})})}const Zt=async t=>ct(t),k=(t,e="sha1")=>St.createHash(e).update(t).digest("base64");function N(t){return[b,v].includes(t.type)}function A(t){return[ot,b,v,O,st].includes(t.type)}function f(t,e,i,n,a="global"){if(!t)throw new Error("Empty action type");if(typeof t!="string")throw new Error(`Invalid action type: ${t}`);const p={type:t,input:e,scope:a};i&&(p.attachments=i);try{n==null||n().parse(p.input)}catch(o){throw new Error(`Invalid action input: ${o}`)}return p}function rt(t,e=M){return(i,n,a,p)=>e(i,n,t,a,p)}const lt=(t,e)=>({name:"",documentType:"",revision:{global:0,local:0},created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...t,state:(e==null?void 0:e(t==null?void 0:t.state))??(t==null?void 0:t.state)??{global:{},local:{}}}),mt=(t,e)=>{const i=lt(t,e);return{...i,initialState:i,operations:{global:[],local:[]},clipboard:[]}},L=(t,e="global")=>k(Ot(t.state[e])),Ht=(t,e=1e3)=>{const i=Math.random()*e;return k(`${(t??new Date).toISOString()}${i}`)};function w(t){return g.castImmutable(g.freeze(t,!0))}function ut(t,e){const i=[...t];let n=e||0,a=i.length>0?i[i.length-1].index:0;const p=[];for(const o of i.reverse()){if(n>0){const r=a-o.index;n-=r}if(n<0)throw new Error("Invalid operation index, missing operations");const c={ignore:n>0,operation:o},u=o.skip>0?o.skip+1:0;if(u>0&&u>n){const r=u-n;n=n+r}a=o.index,p.push(c)}return p.reverse()}function Kt(t){return Object.values(t).flatMap(e=>e).sort((e,i)=>new Date(e.timestamp).getTime()-new Date(i.timestamp).getTime())}function dt(t){return Object.values(t).flatMap(e=>e).sort((e,i)=>new Date(e.operation.timestamp).getTime()-new Date(i.operation.timestamp).getTime())}function z(t,e,i,n,a,p=M,o={}){const c=rt(i,p);return U(t,e,c,n,a,o)}function U(t,e,i,n,a,p={}){const o=mt(t),c=Object.keys(e).reduce((m,d)=>{const l=d;return{...m,[l]:e[l].slice(0,a==null?void 0:a.revision[l])}},{}),u=Object.keys(c).reduce((m,d)=>{const l=d;return{...m,[l]:ut(c[l],p[l])}},{}),r=dt(u).reduce((m,{ignore:d,operation:l})=>d?i(m,$(l.scope),n,{skip:l.skip,ignoreSkipOperations:!0}):i(m,l,n,{skip:l.skip,ignoreSkipOperations:!0}),o),x=Object.keys(r.operations).reduce((m,d)=>{const l=d,y=a&&a.revision[l]<e[l].length?e[l].slice(a.revision[l]):[];return{...m,[l]:[...r.operations[l].map((h,D)=>{var B;return{...h,timestamp:((B=e[l][D])==null?void 0:B.timestamp)??h.timestamp}}),...y]}},{global:[],local:[]});return{...r,operations:x}}const xt=t=>f("SET_NAME",t,void 0,q,void 0),gt=(t=1,e="global")=>f("UNDO",t,void 0,P,e),ft=(t=1,e="global")=>f("REDO",t,void 0,I,e),ht=(t,e,i="global")=>f("PRUNE",{start:t,end:e},void 0,R,i),C=(t,e)=>f("LOAD_STATE",{state:t,operations:e},void 0,F),$=(t="global")=>f("NOOP",{},void 0,void 0,t),Wt=Object.freeze(Object.defineProperty({__proto__:null,loadState:C,noop:$,prune:ht,redo:ft,setName:xt,undo:gt},Symbol.toStringTag,{value:"Module"}));function Vt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function _(){this._types=Object.create(null),this._extensions=Object.create(null);for(let t=0;t<arguments.length;t++)this.define(arguments[t]);this.define=this.define.bind(this),this.getType=this.getType.bind(this),this.getExtension=this.getExtension.bind(this)}_.prototype.define=function(t,e){for(let i in t){let n=t[i].map(function(a){return a.toLowerCase()});i=i.toLowerCase();for(let a=0;a<n.length;a++){const p=n[a];if(p[0]!=="*"){if(!e&&p in this._types)throw new Error('Attempt to change mapping for "'+p+'" extension from "'+this._types[p]+'" to "'+i+'". Pass `force=true` to allow this, otherwise remove "'+p+'" from the list of extensions for "'+i+'".');this._types[p]=i}}if(e||!this._extensions[i]){const a=n[0];this._extensions[i]=a[0]!=="*"?a:a.substr(1)}}};_.prototype.getType=function(t){t=String(t);let e=t.replace(/^.*[/\\]/,"").toLowerCase(),i=e.replace(/^.*\./,"").toLowerCase(),n=e.length<t.length;return(i.length<e.length-1||!n)&&this._types[i]||null};_.prototype.getExtension=function(t){return t=/^\s*([^;\s]*)/.test(t)&&RegExp.$1,t&&this._extensions[t.toLowerCase()]||null};var Gt=_,Qt={"application/andrew-inset":["ez"],"application/applixware":["aw"],"application/atom+xml":["atom"],"application/atomcat+xml":["atomcat"],"application/atomdeleted+xml":["atomdeleted"],"application/atomsvc+xml":["atomsvc"],"application/atsc-dwd+xml":["dwd"],"application/atsc-held+xml":["held"],"application/atsc-rsat+xml":["rsat"],"application/bdoc":["bdoc"],"application/calendar+xml":["xcs"],"application/ccxml+xml":["ccxml"],"application/cdfx+xml":["cdfx"],"application/cdmi-capability":["cdmia"],"application/cdmi-container":["cdmic"],"application/cdmi-domain":["cdmid"],"application/cdmi-object":["cdmio"],"application/cdmi-queue":["cdmiq"],"application/cu-seeme":["cu"],"application/dash+xml":["mpd"],"application/davmount+xml":["davmount"],"application/docbook+xml":["dbk"],"application/dssc+der":["dssc"],"application/dssc+xml":["xdssc"],"application/ecmascript":["es","ecma"],"application/emma+xml":["emma"],"application/emotionml+xml":["emotionml"],"application/epub+zip":["epub"],"application/exi":["exi"],"application/express":["exp"],"application/fdt+xml":["fdt"],"application/font-tdpfr":["pfr"],"application/geo+json":["geojson"],"application/gml+xml":["gml"],"application/gpx+xml":["gpx"],"application/gxf":["gxf"],"application/gzip":["gz"],"application/hjson":["hjson"],"application/hyperstudio":["stk"],"application/inkml+xml":["ink","inkml"],"application/ipfix":["ipfix"],"application/its+xml":["its"],"application/java-archive":["jar","war","ear"],"application/java-serialized-object":["ser"],"application/java-vm":["class"],"application/javascript":["js","mjs"],"application/json":["json","map"],"application/json5":["json5"],"application/jsonml+json":["jsonml"],"application/ld+json":["jsonld"],"application/lgr+xml":["lgr"],"application/lost+xml":["lostxml"],"application/mac-binhex40":["hqx"],"application/mac-compactpro":["cpt"],"application/mads+xml":["mads"],"application/manifest+json":["webmanifest"],"application/marc":["mrc"],"application/marcxml+xml":["mrcx"],"application/mathematica":["ma","nb","mb"],"application/mathml+xml":["mathml"],"application/mbox":["mbox"],"application/mediaservercontrol+xml":["mscml"],"application/metalink+xml":["metalink"],"application/metalink4+xml":["meta4"],"application/mets+xml":["mets"],"application/mmt-aei+xml":["maei"],"application/mmt-usd+xml":["musd"],"application/mods+xml":["mods"],"application/mp21":["m21","mp21"],"application/mp4":["mp4s","m4p"],"application/msword":["doc","dot"],"application/mxf":["mxf"],"application/n-quads":["nq"],"application/n-triples":["nt"],"application/node":["cjs"],"application/octet-stream":["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","exe","dll","deb","dmg","iso","img","msi","msp","msm","buffer"],"application/oda":["oda"],"application/oebps-package+xml":["opf"],"application/ogg":["ogx"],"application/omdoc+xml":["omdoc"],"application/onenote":["onetoc","onetoc2","onetmp","onepkg"],"application/oxps":["oxps"],"application/p2p-overlay+xml":["relo"],"application/patch-ops-error+xml":["xer"],"application/pdf":["pdf"],"application/pgp-encrypted":["pgp"],"application/pgp-signature":["asc","sig"],"application/pics-rules":["prf"],"application/pkcs10":["p10"],"application/pkcs7-mime":["p7m","p7c"],"application/pkcs7-signature":["p7s"],"application/pkcs8":["p8"],"application/pkix-attr-cert":["ac"],"application/pkix-cert":["cer"],"application/pkix-crl":["crl"],"application/pkix-pkipath":["pkipath"],"application/pkixcmp":["pki"],"application/pls+xml":["pls"],"application/postscript":["ai","eps","ps"],"application/provenance+xml":["provx"],"application/pskc+xml":["pskcxml"],"application/raml+yaml":["raml"],"application/rdf+xml":["rdf","owl"],"application/reginfo+xml":["rif"],"application/relax-ng-compact-syntax":["rnc"],"application/resource-lists+xml":["rl"],"application/resource-lists-diff+xml":["rld"],"application/rls-services+xml":["rs"],"application/route-apd+xml":["rapd"],"application/route-s-tsid+xml":["sls"],"application/route-usd+xml":["rusd"],"application/rpki-ghostbusters":["gbr"],"application/rpki-manifest":["mft"],"application/rpki-roa":["roa"],"application/rsd+xml":["rsd"],"application/rss+xml":["rss"],"application/rtf":["rtf"],"application/sbml+xml":["sbml"],"application/scvp-cv-request":["scq"],"application/scvp-cv-response":["scs"],"application/scvp-vp-request":["spq"],"application/scvp-vp-response":["spp"],"application/sdp":["sdp"],"application/senml+xml":["senmlx"],"application/sensml+xml":["sensmlx"],"application/set-payment-initiation":["setpay"],"application/set-registration-initiation":["setreg"],"application/shf+xml":["shf"],"application/sieve":["siv","sieve"],"application/smil+xml":["smi","smil"],"application/sparql-query":["rq"],"application/sparql-results+xml":["srx"],"application/srgs":["gram"],"application/srgs+xml":["grxml"],"application/sru+xml":["sru"],"application/ssdl+xml":["ssdl"],"application/ssml+xml":["ssml"],"application/swid+xml":["swidtag"],"application/tei+xml":["tei","teicorpus"],"application/thraud+xml":["tfi"],"application/timestamped-data":["tsd"],"application/toml":["toml"],"application/trig":["trig"],"application/ttml+xml":["ttml"],"application/ubjson":["ubj"],"application/urc-ressheet+xml":["rsheet"],"application/urc-targetdesc+xml":["td"],"application/voicexml+xml":["vxml"],"application/wasm":["wasm"],"application/widget":["wgt"],"application/winhlp":["hlp"],"application/wsdl+xml":["wsdl"],"application/wspolicy+xml":["wspolicy"],"application/xaml+xml":["xaml"],"application/xcap-att+xml":["xav"],"application/xcap-caps+xml":["xca"],"application/xcap-diff+xml":["xdf"],"application/xcap-el+xml":["xel"],"application/xcap-ns+xml":["xns"],"application/xenc+xml":["xenc"],"application/xhtml+xml":["xhtml","xht"],"application/xliff+xml":["xlf"],"application/xml":["xml","xsl","xsd","rng"],"application/xml-dtd":["dtd"],"application/xop+xml":["xop"],"application/xproc+xml":["xpl"],"application/xslt+xml":["*xsl","xslt"],"application/xspf+xml":["xspf"],"application/xv+xml":["mxml","xhvml","xvml","xvm"],"application/yang":["yang"],"application/yin+xml":["yin"],"application/zip":["zip"],"audio/3gpp":["*3gpp"],"audio/adpcm":["adp"],"audio/amr":["amr"],"audio/basic":["au","snd"],"audio/midi":["mid","midi","kar","rmi"],"audio/mobile-xmf":["mxmf"],"audio/mp3":["*mp3"],"audio/mp4":["m4a","mp4a"],"audio/mpeg":["mpga","mp2","mp2a","mp3","m2a","m3a"],"audio/ogg":["oga","ogg","spx","opus"],"audio/s3m":["s3m"],"audio/silk":["sil"],"audio/wav":["wav"],"audio/wave":["*wav"],"audio/webm":["weba"],"audio/xm":["xm"],"font/collection":["ttc"],"font/otf":["otf"],"font/ttf":["ttf"],"font/woff":["woff"],"font/woff2":["woff2"],"image/aces":["exr"],"image/apng":["apng"],"image/avif":["avif"],"image/bmp":["bmp"],"image/cgm":["cgm"],"image/dicom-rle":["drle"],"image/emf":["emf"],"image/fits":["fits"],"image/g3fax":["g3"],"image/gif":["gif"],"image/heic":["heic"],"image/heic-sequence":["heics"],"image/heif":["heif"],"image/heif-sequence":["heifs"],"image/hej2k":["hej2"],"image/hsj2":["hsj2"],"image/ief":["ief"],"image/jls":["jls"],"image/jp2":["jp2","jpg2"],"image/jpeg":["jpeg","jpg","jpe"],"image/jph":["jph"],"image/jphc":["jhc"],"image/jpm":["jpm"],"image/jpx":["jpx","jpf"],"image/jxr":["jxr"],"image/jxra":["jxra"],"image/jxrs":["jxrs"],"image/jxs":["jxs"],"image/jxsc":["jxsc"],"image/jxsi":["jxsi"],"image/jxss":["jxss"],"image/ktx":["ktx"],"image/ktx2":["ktx2"],"image/png":["png"],"image/sgi":["sgi"],"image/svg+xml":["svg","svgz"],"image/t38":["t38"],"image/tiff":["tif","tiff"],"image/tiff-fx":["tfx"],"image/webp":["webp"],"image/wmf":["wmf"],"message/disposition-notification":["disposition-notification"],"message/global":["u8msg"],"message/global-delivery-status":["u8dsn"],"message/global-disposition-notification":["u8mdn"],"message/global-headers":["u8hdr"],"message/rfc822":["eml","mime"],"model/3mf":["3mf"],"model/gltf+json":["gltf"],"model/gltf-binary":["glb"],"model/iges":["igs","iges"],"model/mesh":["msh","mesh","silo"],"model/mtl":["mtl"],"model/obj":["obj"],"model/step+xml":["stpx"],"model/step+zip":["stpz"],"model/step-xml+zip":["stpxz"],"model/stl":["stl"],"model/vrml":["wrl","vrml"],"model/x3d+binary":["*x3db","x3dbz"],"model/x3d+fastinfoset":["x3db"],"model/x3d+vrml":["*x3dv","x3dvz"],"model/x3d+xml":["x3d","x3dz"],"model/x3d-vrml":["x3dv"],"text/cache-manifest":["appcache","manifest"],"text/calendar":["ics","ifb"],"text/coffeescript":["coffee","litcoffee"],"text/css":["css"],"text/csv":["csv"],"text/html":["html","htm","shtml"],"text/jade":["jade"],"text/jsx":["jsx"],"text/less":["less"],"text/markdown":["markdown","md"],"text/mathml":["mml"],"text/mdx":["mdx"],"text/n3":["n3"],"text/plain":["txt","text","conf","def","list","log","in","ini"],"text/richtext":["rtx"],"text/rtf":["*rtf"],"text/sgml":["sgml","sgm"],"text/shex":["shex"],"text/slim":["slim","slm"],"text/spdx":["spdx"],"text/stylus":["stylus","styl"],"text/tab-separated-values":["tsv"],"text/troff":["t","tr","roff","man","me","ms"],"text/turtle":["ttl"],"text/uri-list":["uri","uris","urls"],"text/vcard":["vcard"],"text/vtt":["vtt"],"text/xml":["*xml"],"text/yaml":["yaml","yml"],"video/3gpp":["3gp","3gpp"],"video/3gpp2":["3g2"],"video/h261":["h261"],"video/h263":["h263"],"video/h264":["h264"],"video/iso.segment":["m4s"],"video/jpeg":["jpgv"],"video/jpm":["*jpm","jpgm"],"video/mj2":["mj2","mjp2"],"video/mp2t":["ts"],"video/mp4":["mp4","mp4v","mpg4"],"video/mpeg":["mpeg","mpg","mpe","m1v","m2v"],"video/ogg":["ogv"],"video/quicktime":["qt","mov"],"video/webm":["webm"]};let Xt=Gt;var Yt=new Xt(Qt);const te=Vt(Yt),J=async t=>{const e=new Z,{name:i,revision:n,documentType:a,created:p,lastModified:o}=t,c={name:i,revision:n,documentType:a,created:p,lastModified:o};return e.file("header.json",JSON.stringify(c,null,2)),e.file("state.json",JSON.stringify(t.initialState||{},null,2)),e.file("operations.json",JSON.stringify(t.operations,null,2)),Object.keys(t.attachments).forEach(r=>{const{data:x,...m}=t.attachments[r];e.file(r,x,{base64:!0,createFolders:!0,comment:JSON.stringify(m)})}),e},bt=async(t,e,i,n)=>{const p=await(await J(t)).generateAsync({type:"uint8array",streamFiles:!0}),o=n??t.name,c=`.${i}.zip`;return Jt(e,o.endsWith(c)?o:`${o}${c}`,p)},ee=async(t,e)=>{const n=await(await J(t)).generateAsync({type:"blob"}),a=await e.createWritable();await a.write(n),await a.close()},T=async(t,e)=>{const i=ct(t);return vt(i,e)},vt=async(t,e)=>{const i=new Z;return await i.loadAsync(t),ie(i,e)};async function ie(t,e){const i=t.file("state.json");if(!i)throw new Error("Initial state not found");const n=await i.async("string"),a=JSON.parse(n),p=t.file("header.json");let o;p&&(o=JSON.parse(await p.async("string")));const c=t.file("operations.json");if(!c)throw new Error("Operations history not found");const u=JSON.parse(await c.async("string"));let r=U(a,u,e,void 0,o);return o&&(r={...r,...o}),r}function yt(t){const e=t.replace(/^.*\./,"")||void 0,i=t.replace(/^.*[/\\]/,"")||void 0;return{extension:e,fileName:i}}async function ne(t){const{buffer:e,mimeType:i="application/octet-stream"}=await Bt(t),n=yt(t),a=e.toString("base64");return{data:a,hash:k(a),mimeType:i,...n}}async function ae(t){const e=await Zt(t),i=te.getType(t)||"application/octet-stream",n=yt(t),a=e.toString("base64");return{data:a,hash:k(a),mimeType:i,...n}}class oe{constructor(e,i,n){S(this,"_document");S(this,"_reducer");S(this,"_signalDispatch");this._reducer=e,this._document=i,this._signalDispatch=n}dispatch(e,i){return this._document=this._reducer(this._document,e,this._signalDispatch,i),this}saveToFile(e,i,n){return bt(this._document,e,i,n)}async loadFromFile(e){this._document=await T(e,this._reducer)}static async stateFromFile(e,i){return await T(e,i)}get state(){return w(this._document.state)}get operations(){return w(this._document.operations)}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision.global}getRevision(e){return this._document.revision[e]}get initialState(){return w(this._document.initialState)}toDocument(){return w(this._document)}getAttachment(e){return this._document.attachments[e]}setName(e){return this.dispatch(xt(e)),this}undo(e){return this.dispatch(gt(e)),this}redo(e){return this.dispatch(ft(e)),this}prune(e,i){return this.dispatch(ht(e,i)),this}loadState(e,i){return this.dispatch(C(e,i)),this}}function se(t,e){e.forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(n=>{Object.defineProperty(t.prototype,n,Object.getOwnPropertyDescriptor(i.prototype,n)||Object.create(null))})})}exports.BaseActions=Wt;exports.BaseDocument=oe;exports.applyMixins=se;exports.baseReducer=M;exports.createAction=f;exports.createDocument=mt;exports.createExtendedState=lt;exports.createReducer=rt;exports.createZip=J;exports.getLocalFile=ae;exports.getRemoteFile=ne;exports.hashDocument=L;exports.hashKey=Ht;exports.isBaseAction=A;exports.isUndoRedo=N;exports.loadFromFile=T;exports.loadFromInput=vt;exports.mapSkippedOperations=ut;exports.processUndoRedo=pt;exports.readOnly=w;exports.replayDocument=U;exports.replayOperations=z;exports.saveToFile=bt;exports.saveToFileHandle=ee;exports.sortMappedOperations=dt;exports.sortOperations=Kt;exports.zod=Tt;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * as z from
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * as z from './zod';
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { OperationScope } from '..';
|
|
2
2
|
export type Maybe<T> = T | null;
|
|
3
3
|
export type InputMaybe<T> = T | null | undefined;
|
|
4
|
-
export type Exact<T extends {
|
|
5
|
-
[key: string]: unknown;
|
|
6
|
-
}> = {
|
|
4
|
+
export type Exact<T extends Record<string, unknown>> = {
|
|
7
5
|
[K in keyof T]: T[K];
|
|
8
6
|
};
|
|
9
7
|
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
|
|
@@ -12,9 +10,7 @@ export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
|
|
|
12
10
|
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
|
|
13
11
|
[SubKey in K]: Maybe<T[SubKey]>;
|
|
14
12
|
};
|
|
15
|
-
export type MakeEmpty<T extends {
|
|
16
|
-
[key: string]: unknown;
|
|
17
|
-
}, K extends keyof T> = {
|
|
13
|
+
export type MakeEmpty<T extends Record<string, unknown>, K extends keyof T> = {
|
|
18
14
|
[_ in K]?: never;
|
|
19
15
|
};
|
|
20
16
|
export type Incremental<T> = T | {
|
|
@@ -92,7 +88,7 @@ export type IOperation = {
|
|
|
92
88
|
export type Load_State = 'LOAD_STATE';
|
|
93
89
|
export type LoadStateAction = {
|
|
94
90
|
input: LoadStateActionInput;
|
|
95
|
-
type: Load_State
|
|
91
|
+
type: Load_State;
|
|
96
92
|
scope: OperationScope;
|
|
97
93
|
};
|
|
98
94
|
export type LoadStateActionInput = {
|
|
@@ -136,7 +132,7 @@ export type Operation = IOperation & {
|
|
|
136
132
|
export type Prune = 'PRUNE';
|
|
137
133
|
export type PruneAction = {
|
|
138
134
|
input: PruneActionInput;
|
|
139
|
-
type: Prune
|
|
135
|
+
type: Prune;
|
|
140
136
|
scope: OperationScope;
|
|
141
137
|
};
|
|
142
138
|
export type PruneActionInput = {
|
|
@@ -150,13 +146,13 @@ export type Query = {
|
|
|
150
146
|
export type Redo = 'REDO';
|
|
151
147
|
export type RedoAction = {
|
|
152
148
|
input: Scalars['Int']['input'];
|
|
153
|
-
type: Redo
|
|
149
|
+
type: Redo;
|
|
154
150
|
scope: OperationScope;
|
|
155
151
|
};
|
|
156
152
|
export type Set_Name = 'SET_NAME';
|
|
157
153
|
export type SetNameAction = {
|
|
158
154
|
input: Scalars['String']['input'];
|
|
159
|
-
type: Set_Name
|
|
155
|
+
type: Set_Name;
|
|
160
156
|
scope: 'global';
|
|
161
157
|
};
|
|
162
158
|
export type SetNameOperation = IOperation & {
|
|
@@ -170,12 +166,12 @@ export type SetNameOperation = IOperation & {
|
|
|
170
166
|
export type Undo = 'UNDO';
|
|
171
167
|
export type UndoAction = {
|
|
172
168
|
input: Scalars['Int']['input'];
|
|
173
|
-
type: Undo
|
|
169
|
+
type: Undo;
|
|
174
170
|
scope: OperationScope;
|
|
175
171
|
};
|
|
176
172
|
export type NOOP = 'NOOP';
|
|
177
173
|
export type NOOPAction = {
|
|
178
174
|
input: Scalars['Unknown']['input'];
|
|
179
|
-
type: NOOP
|
|
175
|
+
type: NOOP;
|
|
180
176
|
scope: OperationScope;
|
|
181
177
|
};
|
|
@@ -22,6 +22,7 @@ export type DeleteChildDocumentSignal = ISignal<'DELETE_CHILD_DOCUMENT', DeleteC
|
|
|
22
22
|
export type CopyChildDocumentInput = {
|
|
23
23
|
id: string;
|
|
24
24
|
newId: string;
|
|
25
|
+
synchronizationUnits: SynchronizationUnit[];
|
|
25
26
|
};
|
|
26
27
|
export type CopyChildDocumentSignal = ISignal<'COPY_CHILD_DOCUMENT', CopyChildDocumentInput>;
|
|
27
28
|
export type Signal = CreateChildDocumentSignal | DeleteChildDocumentSignal | CopyChildDocumentSignal;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export * from './base';
|
|
2
|
+
export { createAction, createDocument, createExtendedState, createReducer, hashDocument, hashKey, isBaseAction, mapSkippedOperations, readOnly, replayDocument, replayOperations, sortMappedOperations, sortOperations, } from './base';
|
|
2
3
|
export * from './file';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This is a scaffold file meant for customization:
|
|
3
|
-
* - modify it by implementing the reducer functions
|
|
4
|
-
* - delete the file and run the code generator again to have it reset
|
|
5
|
-
*/
|
|
2
|
+
* This is a scaffold file meant for customization:
|
|
3
|
+
* - modify it by implementing the reducer functions
|
|
4
|
+
* - delete the file and run the code generator again to have it reset
|
|
5
|
+
*/
|
|
6
6
|
import { DocumentModelVersioningOperations } from '../../gen/versioning/operations';
|
|
7
7
|
export declare const reducer: DocumentModelVersioningOperations;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-model",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"private": false,
|
|
6
6
|
"files": [
|
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
"module": "dist/node/index.js",
|
|
12
12
|
"browser": "dist/browser/index.js",
|
|
13
13
|
"scripts": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"check-types": "tsc",
|
|
15
|
+
"lint": "eslint . && yarn check-types",
|
|
16
|
+
"lint:fix": "eslint --fix . && yarn check-types",
|
|
16
17
|
"build": "yarn build:browser && yarn build:node",
|
|
17
18
|
"build:browser": "vite build --mode browser",
|
|
18
19
|
"build:node": "vite build --mode node",
|
|
19
|
-
"test": "
|
|
20
|
+
"test": "vitest run"
|
|
20
21
|
},
|
|
21
22
|
"exports": {
|
|
22
23
|
".": {
|
|
@@ -51,33 +52,38 @@
|
|
|
51
52
|
}
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@
|
|
55
|
+
"@commitlint/cli": "^18.4.4",
|
|
56
|
+
"@commitlint/config-conventional": "^18.4.4",
|
|
57
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
55
58
|
"@total-typescript/ts-reset": "^0.5.1",
|
|
56
59
|
"@types/jest": "^29.5.11",
|
|
57
60
|
"@types/mime": "^3.0.4",
|
|
58
|
-
"@types/react": "^18.2.
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
60
|
-
"@typescript-eslint/parser": "^6.
|
|
61
|
+
"@types/react": "^18.2.48",
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
|
63
|
+
"@typescript-eslint/parser": "^6.19.0",
|
|
61
64
|
"eslint": "^8.56.0",
|
|
62
65
|
"eslint-config-prettier": "^9.1.0",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
66
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
67
|
+
"husky": "^8.0.3",
|
|
68
|
+
"lint-staged": "^15.2.0",
|
|
69
|
+
"prettier": "^3.2.4",
|
|
65
70
|
"prettier-plugin-organize-imports": "^3.2.4",
|
|
66
71
|
"react": "^18.2.0",
|
|
67
|
-
"rollup-plugin-polyfill-node": "^0.
|
|
72
|
+
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
68
73
|
"sha.js": "^2.4.11",
|
|
69
74
|
"ts-jest": "^29.1.1",
|
|
70
75
|
"ts-node": "^10.9.2",
|
|
71
76
|
"typescript": "^5.3.3",
|
|
72
77
|
"vite": "^5.0.11",
|
|
73
|
-
"vite-plugin-dts": "^3.7.
|
|
74
|
-
"vite-plugin-node-polyfills": "^0.19.0"
|
|
78
|
+
"vite-plugin-dts": "^3.7.1",
|
|
79
|
+
"vite-plugin-node-polyfills": "^0.19.0",
|
|
80
|
+
"vitest": "^1.2.1"
|
|
75
81
|
},
|
|
76
82
|
"dependencies": {
|
|
77
|
-
"immer": "^10.0.
|
|
78
|
-
"json-stringify-deterministic": "^1.0.
|
|
83
|
+
"immer": "^10.0.3",
|
|
84
|
+
"json-stringify-deterministic": "^1.0.12",
|
|
79
85
|
"jszip": "^3.10.1",
|
|
80
|
-
"mime": "^
|
|
81
|
-
"zod": "^3.22.
|
|
86
|
+
"mime": "^4.0.1",
|
|
87
|
+
"zod": "^3.22.4"
|
|
82
88
|
}
|
|
83
89
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var wt=Object.defineProperty;var jt=(t,e,i)=>e in t?wt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var S=(t,e,i)=>(jt(t,typeof e!="symbol"?e+"":e,i),i);const g=require("immer"),Ot=require("json-stringify-deterministic"),s=require("zod"),Z=require("jszip"),St=require("crypto"),E=require("fs"),zt=require("https"),kt=require("path"),H=t=>t!=null,_t=s.z.any().refine(t=>H(t)),K=s.z.enum(["LOAD_STATE"]),W=s.z.enum(["PRUNE"]),V=s.z.enum(["REDO"]),G=s.z.enum(["SET_NAME"]),Q=s.z.enum(["UNDO"]);function Dt(){return s.z.object({__typename:s.z.literal("Action").optional(),type:s.z.string()})}function j(){return s.z.literal("global").or(s.z.literal("local"))}function X(){return s.z.union([Y(),et(),it(),nt(),at()])}function Et(){return s.z.object({__typename:s.z.literal("DocumentFile").optional(),data:s.z.string(),extension:s.z.string().nullable(),fileName:s.z.string().nullable(),mimeType:s.z.string()})}function Y(){return s.z.object({input:s.z.lazy(()=>F()),type:K,scope:j()})}function F(){return s.z.object({operations:s.z.number(),state:s.z.lazy(()=>tt())})}function tt(){return s.z.object({data:s.z.unknown().nullish(),name:s.z.string()})}function Nt(){return s.z.object({__typename:s.z.literal("Operation").optional(),hash:s.z.string(),index:s.z.number(),timestamp:s.z.string().datetime(),type:s.z.string()})}function et(){return s.z.object({input:s.z.lazy(()=>R()),type:W,scope:j()})}function R(){return s.z.object({end:s.z.number().nullish(),start:s.z.number().nullish()})}const I=s.z.number;function it(){return s.z.object({input:I(),type:V,scope:j()})}const q=s.z.string;function nt(){return s.z.object({input:q(),type:G,scope:s.z.literal("global")})}function At(){return s.z.object({__typename:s.z.literal("SetNameOperation").optional(),hash:s.z.string(),index:s.z.number(),input:s.z.string(),timestamp:s.z.string().datetime(),type:s.z.string()})}const P=s.z.number;function at(){return s.z.object({input:P(),type:Q,scope:j()})}const Tt=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:Dt,BaseActionSchema:X,DocumentFileSchema:Et,LoadStateActionInputSchema:F,LoadStateActionSchema:Y,LoadStateActionStateInputSchema:tt,Load_StateSchema:K,OperationSchema:Nt,OperationScopeSchema:j,PruneActionInputSchema:R,PruneActionSchema:et,PruneSchema:W,RedoActionInputSchema:I,RedoActionSchema:it,RedoSchema:V,SetNameActionInputSchema:q,SetNameActionSchema:nt,SetNameOperationSchema:At,Set_NameSchema:G,UndoActionInputSchema:P,UndoActionSchema:at,UndoSchema:Q,definedNonNullAnySchema:_t,isDefinedNonNullAny:H},Symbol.toStringTag,{value:"Module"}));function Ft(t,e){return{...t,name:e}}function Rt(t,e,i){const{scope:n,input:a}=e,p={document:t,action:e,skip:i};return g.produce(p,o=>{if(o.document.operations[n].length<1)throw new Error(`Cannot undo: no operations in history for scope "${n}"`);if(a<1)throw new Error("Invalid UNDO action: input value must be greater than 0");if(o.skip>0)throw new Error("Cannot undo: skip value from reducer cannot be used with UNDO action");const[c]=o.document.operations[n].slice(-1),u=c.type==="NOOP"&&c.skip>0;if(o.skip+=a,u&&(o.skip+=c.skip,o.document.operations[n].pop()),o.document.operations[n].length<o.skip)throw new Error("Cannot undo: you can't undo more operations than the ones in the scope history");const r=o.document.operations[n].length-1;let x=a,m=u?r-c.skip:r;for(;x>0&&m>=0;){const d=o.document.operations[n][m];d.type==="NOOP"&&d.skip>0?(m=m-(d.skip+1),o.skip+=d.skip+1):(o.document.clipboard.push({...d}),x--,m--)}o.action=J(n)})}function It(t,e,i){const{scope:n,input:a}=e,p={document:t,action:e,skip:i};return g.produce(p,o=>{if(o.skip>0)throw new Error("Cannot redo: skip value from reducer cannot be used with REDO action");if(a>1)throw new Error("Cannot redo: you can only redo one operation at a time");if(a<1)throw new Error("Invalid REDO action: invalid redo input value");if(o.document.clipboard.length<1)throw new Error("Cannot redo: no operations in the clipboard");const c=o.document.clipboard.findLastIndex(r=>r.scope===n);if(c<0)throw new Error(`Cannot redo: no operations in clipboard for scope "${n}"`);const u=o.document.clipboard.splice(c,1)[0];o.action=g.castDraft({type:u.type,scope:u.scope,input:u.input})})}function qt(t,e,i){const{scope:n}=e,a=t.operations[n];let{input:{start:p,end:o}}=e;p=p||0,o=o||a.length;const c=a.slice(p,o),u=a.slice(0,p),r=a.slice(o),x=z(t.initialState,{...t.operations,[n]:u.concat(c)},i),{name:m,state:d}=x,l=u.length,y=u.length?u[u.length-1].timestamp:r.length?r[0].timestamp:new Date().toISOString();return z(t.initialState,{...t.operations,[n]:[...u,{...$({name:m,state:d},c.length),timestamp:y,index:l,hash:U({state:d},"global")},...r.map((h,D)=>({...h,index:l+D+1}))]},i)}function Pt(t,e){return{...t,name:e.name,state:e.state??{global:{},local:{}}}}const ot="SET_NAME",b="UNDO",v="REDO",O="PRUNE",st="LOAD_STATE";function Mt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function k(){this._types=Object.create(null),this._extensions=Object.create(null);for(let t=0;t<arguments.length;t++)this.define(arguments[t]);this.define=this.define.bind(this),this.getType=this.getType.bind(this),this.getExtension=this.getExtension.bind(this)}k.prototype.define=function(t,e){for(let i in t){let n=t[i].map(function(a){return a.toLowerCase()});i=i.toLowerCase();for(let a=0;a<n.length;a++){const p=n[a];if(p[0]!=="*"){if(!e&&p in this._types)throw new Error('Attempt to change mapping for "'+p+'" extension from "'+this._types[p]+'" to "'+i+'". Pass `force=true` to allow this, otherwise remove "'+p+'" from the list of extensions for "'+i+'".');this._types[p]=i}}if(e||!this._extensions[i]){const a=n[0];this._extensions[i]=a[0]!=="*"?a:a.substr(1)}}};k.prototype.getType=function(t){t=String(t);let e=t.replace(/^.*[/\\]/,"").toLowerCase(),i=e.replace(/^.*\./,"").toLowerCase(),n=e.length<t.length;return(i.length<e.length-1||!n)&&this._types[i]||null};k.prototype.getExtension=function(t){return t=/^\s*([^;\s]*)/.test(t)&&RegExp.$1,t&&this._extensions[t.toLowerCase()]||null};var Lt=k,Ut={"application/andrew-inset":["ez"],"application/applixware":["aw"],"application/atom+xml":["atom"],"application/atomcat+xml":["atomcat"],"application/atomdeleted+xml":["atomdeleted"],"application/atomsvc+xml":["atomsvc"],"application/atsc-dwd+xml":["dwd"],"application/atsc-held+xml":["held"],"application/atsc-rsat+xml":["rsat"],"application/bdoc":["bdoc"],"application/calendar+xml":["xcs"],"application/ccxml+xml":["ccxml"],"application/cdfx+xml":["cdfx"],"application/cdmi-capability":["cdmia"],"application/cdmi-container":["cdmic"],"application/cdmi-domain":["cdmid"],"application/cdmi-object":["cdmio"],"application/cdmi-queue":["cdmiq"],"application/cu-seeme":["cu"],"application/dash+xml":["mpd"],"application/davmount+xml":["davmount"],"application/docbook+xml":["dbk"],"application/dssc+der":["dssc"],"application/dssc+xml":["xdssc"],"application/ecmascript":["es","ecma"],"application/emma+xml":["emma"],"application/emotionml+xml":["emotionml"],"application/epub+zip":["epub"],"application/exi":["exi"],"application/express":["exp"],"application/fdt+xml":["fdt"],"application/font-tdpfr":["pfr"],"application/geo+json":["geojson"],"application/gml+xml":["gml"],"application/gpx+xml":["gpx"],"application/gxf":["gxf"],"application/gzip":["gz"],"application/hjson":["hjson"],"application/hyperstudio":["stk"],"application/inkml+xml":["ink","inkml"],"application/ipfix":["ipfix"],"application/its+xml":["its"],"application/java-archive":["jar","war","ear"],"application/java-serialized-object":["ser"],"application/java-vm":["class"],"application/javascript":["js","mjs"],"application/json":["json","map"],"application/json5":["json5"],"application/jsonml+json":["jsonml"],"application/ld+json":["jsonld"],"application/lgr+xml":["lgr"],"application/lost+xml":["lostxml"],"application/mac-binhex40":["hqx"],"application/mac-compactpro":["cpt"],"application/mads+xml":["mads"],"application/manifest+json":["webmanifest"],"application/marc":["mrc"],"application/marcxml+xml":["mrcx"],"application/mathematica":["ma","nb","mb"],"application/mathml+xml":["mathml"],"application/mbox":["mbox"],"application/mediaservercontrol+xml":["mscml"],"application/metalink+xml":["metalink"],"application/metalink4+xml":["meta4"],"application/mets+xml":["mets"],"application/mmt-aei+xml":["maei"],"application/mmt-usd+xml":["musd"],"application/mods+xml":["mods"],"application/mp21":["m21","mp21"],"application/mp4":["mp4s","m4p"],"application/msword":["doc","dot"],"application/mxf":["mxf"],"application/n-quads":["nq"],"application/n-triples":["nt"],"application/node":["cjs"],"application/octet-stream":["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","exe","dll","deb","dmg","iso","img","msi","msp","msm","buffer"],"application/oda":["oda"],"application/oebps-package+xml":["opf"],"application/ogg":["ogx"],"application/omdoc+xml":["omdoc"],"application/onenote":["onetoc","onetoc2","onetmp","onepkg"],"application/oxps":["oxps"],"application/p2p-overlay+xml":["relo"],"application/patch-ops-error+xml":["xer"],"application/pdf":["pdf"],"application/pgp-encrypted":["pgp"],"application/pgp-signature":["asc","sig"],"application/pics-rules":["prf"],"application/pkcs10":["p10"],"application/pkcs7-mime":["p7m","p7c"],"application/pkcs7-signature":["p7s"],"application/pkcs8":["p8"],"application/pkix-attr-cert":["ac"],"application/pkix-cert":["cer"],"application/pkix-crl":["crl"],"application/pkix-pkipath":["pkipath"],"application/pkixcmp":["pki"],"application/pls+xml":["pls"],"application/postscript":["ai","eps","ps"],"application/provenance+xml":["provx"],"application/pskc+xml":["pskcxml"],"application/raml+yaml":["raml"],"application/rdf+xml":["rdf","owl"],"application/reginfo+xml":["rif"],"application/relax-ng-compact-syntax":["rnc"],"application/resource-lists+xml":["rl"],"application/resource-lists-diff+xml":["rld"],"application/rls-services+xml":["rs"],"application/route-apd+xml":["rapd"],"application/route-s-tsid+xml":["sls"],"application/route-usd+xml":["rusd"],"application/rpki-ghostbusters":["gbr"],"application/rpki-manifest":["mft"],"application/rpki-roa":["roa"],"application/rsd+xml":["rsd"],"application/rss+xml":["rss"],"application/rtf":["rtf"],"application/sbml+xml":["sbml"],"application/scvp-cv-request":["scq"],"application/scvp-cv-response":["scs"],"application/scvp-vp-request":["spq"],"application/scvp-vp-response":["spp"],"application/sdp":["sdp"],"application/senml+xml":["senmlx"],"application/sensml+xml":["sensmlx"],"application/set-payment-initiation":["setpay"],"application/set-registration-initiation":["setreg"],"application/shf+xml":["shf"],"application/sieve":["siv","sieve"],"application/smil+xml":["smi","smil"],"application/sparql-query":["rq"],"application/sparql-results+xml":["srx"],"application/srgs":["gram"],"application/srgs+xml":["grxml"],"application/sru+xml":["sru"],"application/ssdl+xml":["ssdl"],"application/ssml+xml":["ssml"],"application/swid+xml":["swidtag"],"application/tei+xml":["tei","teicorpus"],"application/thraud+xml":["tfi"],"application/timestamped-data":["tsd"],"application/toml":["toml"],"application/trig":["trig"],"application/ttml+xml":["ttml"],"application/ubjson":["ubj"],"application/urc-ressheet+xml":["rsheet"],"application/urc-targetdesc+xml":["td"],"application/voicexml+xml":["vxml"],"application/wasm":["wasm"],"application/widget":["wgt"],"application/winhlp":["hlp"],"application/wsdl+xml":["wsdl"],"application/wspolicy+xml":["wspolicy"],"application/xaml+xml":["xaml"],"application/xcap-att+xml":["xav"],"application/xcap-caps+xml":["xca"],"application/xcap-diff+xml":["xdf"],"application/xcap-el+xml":["xel"],"application/xcap-ns+xml":["xns"],"application/xenc+xml":["xenc"],"application/xhtml+xml":["xhtml","xht"],"application/xliff+xml":["xlf"],"application/xml":["xml","xsl","xsd","rng"],"application/xml-dtd":["dtd"],"application/xop+xml":["xop"],"application/xproc+xml":["xpl"],"application/xslt+xml":["*xsl","xslt"],"application/xspf+xml":["xspf"],"application/xv+xml":["mxml","xhvml","xvml","xvm"],"application/yang":["yang"],"application/yin+xml":["yin"],"application/zip":["zip"],"audio/3gpp":["*3gpp"],"audio/adpcm":["adp"],"audio/amr":["amr"],"audio/basic":["au","snd"],"audio/midi":["mid","midi","kar","rmi"],"audio/mobile-xmf":["mxmf"],"audio/mp3":["*mp3"],"audio/mp4":["m4a","mp4a"],"audio/mpeg":["mpga","mp2","mp2a","mp3","m2a","m3a"],"audio/ogg":["oga","ogg","spx","opus"],"audio/s3m":["s3m"],"audio/silk":["sil"],"audio/wav":["wav"],"audio/wave":["*wav"],"audio/webm":["weba"],"audio/xm":["xm"],"font/collection":["ttc"],"font/otf":["otf"],"font/ttf":["ttf"],"font/woff":["woff"],"font/woff2":["woff2"],"image/aces":["exr"],"image/apng":["apng"],"image/avif":["avif"],"image/bmp":["bmp"],"image/cgm":["cgm"],"image/dicom-rle":["drle"],"image/emf":["emf"],"image/fits":["fits"],"image/g3fax":["g3"],"image/gif":["gif"],"image/heic":["heic"],"image/heic-sequence":["heics"],"image/heif":["heif"],"image/heif-sequence":["heifs"],"image/hej2k":["hej2"],"image/hsj2":["hsj2"],"image/ief":["ief"],"image/jls":["jls"],"image/jp2":["jp2","jpg2"],"image/jpeg":["jpeg","jpg","jpe"],"image/jph":["jph"],"image/jphc":["jhc"],"image/jpm":["jpm"],"image/jpx":["jpx","jpf"],"image/jxr":["jxr"],"image/jxra":["jxra"],"image/jxrs":["jxrs"],"image/jxs":["jxs"],"image/jxsc":["jxsc"],"image/jxsi":["jxsi"],"image/jxss":["jxss"],"image/ktx":["ktx"],"image/ktx2":["ktx2"],"image/png":["png"],"image/sgi":["sgi"],"image/svg+xml":["svg","svgz"],"image/t38":["t38"],"image/tiff":["tif","tiff"],"image/tiff-fx":["tfx"],"image/webp":["webp"],"image/wmf":["wmf"],"message/disposition-notification":["disposition-notification"],"message/global":["u8msg"],"message/global-delivery-status":["u8dsn"],"message/global-disposition-notification":["u8mdn"],"message/global-headers":["u8hdr"],"message/rfc822":["eml","mime"],"model/3mf":["3mf"],"model/gltf+json":["gltf"],"model/gltf-binary":["glb"],"model/iges":["igs","iges"],"model/mesh":["msh","mesh","silo"],"model/mtl":["mtl"],"model/obj":["obj"],"model/step+xml":["stpx"],"model/step+zip":["stpz"],"model/step-xml+zip":["stpxz"],"model/stl":["stl"],"model/vrml":["wrl","vrml"],"model/x3d+binary":["*x3db","x3dbz"],"model/x3d+fastinfoset":["x3db"],"model/x3d+vrml":["*x3dv","x3dvz"],"model/x3d+xml":["x3d","x3dz"],"model/x3d-vrml":["x3dv"],"text/cache-manifest":["appcache","manifest"],"text/calendar":["ics","ifb"],"text/coffeescript":["coffee","litcoffee"],"text/css":["css"],"text/csv":["csv"],"text/html":["html","htm","shtml"],"text/jade":["jade"],"text/jsx":["jsx"],"text/less":["less"],"text/markdown":["markdown","md"],"text/mathml":["mml"],"text/mdx":["mdx"],"text/n3":["n3"],"text/plain":["txt","text","conf","def","list","log","in","ini"],"text/richtext":["rtx"],"text/rtf":["*rtf"],"text/sgml":["sgml","sgm"],"text/shex":["shex"],"text/slim":["slim","slm"],"text/spdx":["spdx"],"text/stylus":["stylus","styl"],"text/tab-separated-values":["tsv"],"text/troff":["t","tr","roff","man","me","ms"],"text/turtle":["ttl"],"text/uri-list":["uri","uris","urls"],"text/vcard":["vcard"],"text/vtt":["vtt"],"text/xml":["*xml"],"text/yaml":["yaml","yml"],"video/3gpp":["3gp","3gpp"],"video/3gpp2":["3g2"],"video/h261":["h261"],"video/h263":["h263"],"video/h264":["h264"],"video/iso.segment":["m4s"],"video/jpeg":["jpgv"],"video/jpm":["*jpm","jpgm"],"video/mj2":["mj2","mjp2"],"video/mp2t":["ts"],"video/mp4":["mp4","mp4v","mpg4"],"video/mpeg":["mpeg","mpg","mpe","m1v","m2v"],"video/ogg":["ogv"],"video/quicktime":["qt","mov"],"video/webm":["webm"]};let Ct=Lt;var $t=new Ct(Ut);const Jt=Mt($t);function Bt(t,e,i){const n=kt.join(t,e);return E.mkdirSync(t,{recursive:!0}),new Promise((a,p)=>{try{E.writeFile(n,i,{},o=>{o?p(o):a(n)})}catch(o){p(o)}})}function pt(t){return E.readFileSync(t)}function Zt(t){return new Promise((e,i)=>{zt.get(t,n=>{const a=[],p=n.headers["content-type"];n.on("data",o=>{a.push(o)}),n.on("end",()=>{e({buffer:Buffer.concat(a),mimeType:p})})}).on("error",n=>{i(n)})})}const Ht=async t=>pt(t),_=(t,e="sha1")=>St.createHash(e).update(t).digest("base64"),M=async t=>{const e=new Z,{name:i,revision:n,documentType:a,created:p,lastModified:o}=t,c={name:i,revision:n,documentType:a,created:p,lastModified:o};return e.file("header.json",JSON.stringify(c,null,2)),e.file("state.json",JSON.stringify(t.initialState||{},null,2)),e.file("operations.json",JSON.stringify(t.operations,null,2)),Object.keys(t.attachments).forEach(r=>{const{data:x,...m}=t.attachments[r];e.file(r,x,{base64:!0,createFolders:!0,comment:JSON.stringify(m)})}),e},ct=async(t,e,i,n)=>{const p=await(await M(t)).generateAsync({type:"uint8array",streamFiles:!0}),o=n??t.name,c=`.${i}.zip`;return Bt(e,o.endsWith(c)?o:`${o}${c}`,p)},Kt=async(t,e)=>{const n=await(await M(t)).generateAsync({type:"blob"}),a=await e.createWritable();await a.write(n),await a.close()},N=async(t,e)=>{const i=pt(t);return rt(i,e)},rt=async(t,e)=>{const i=new Z;return await i.loadAsync(t),Wt(i,e)};async function Wt(t,e){const i=t.file("state.json");if(!i)throw new Error("Initial state not found");const n=await i.async("string"),a=JSON.parse(n),p=t.file("header.json");let o;p&&(o=JSON.parse(await p.async("string")));const c=t.file("operations.json");if(!c)throw new Error("Operations history not found");const u=JSON.parse(await c.async("string"));let r=C(a,u,e,void 0,o);return o&&(r={...r,...o}),r}function lt(t){const e=t.replace(/^.*\./,"")||void 0,i=t.replace(/^.*[/\\]/,"")||void 0;return{extension:e,fileName:i}}async function Vt(t){const{buffer:e,mimeType:i="application/octet-stream"}=await Zt(t),n=lt(t),a=e.toString("base64");return{data:a,hash:_(a),mimeType:i,...n}}async function Gt(t){const e=await Ht(t),i=Jt.getType(t)||"application/octet-stream",n=lt(t),a=e.toString("base64");return{data:a,hash:_(a),mimeType:i,...n}}function Qt(t,e){const i=t.revision[e.scope];return[b,v,O].includes(e.type)?i:i+1}function Xt(t,e){return{...t,revision:{...t.revision,[e.scope]:Qt(t,e)},lastModified:new Date().toISOString()}}function Yt(t,e,i=0){if([b,v,O].includes(e.type))return t;const{scope:n}=e,a=t.operations[n].slice(0,t.revision[n]);return a.push({...e,index:a.length,timestamp:new Date().toISOString(),hash:"",scope:n,skip:i}),{...t,operations:{...t.operations,[n]:a}}}function te(t,e,i=0){let n=Yt(t,e,i);return n=Xt(n,e),n}function ee(t,e,i){switch(X().parse(e),e.type){case ot:return Ft(t,e.input);case O:return qt(t,e,i);case st:return Pt(t,e.input.state);default:return t}}function mt(t,e,i){switch(e.type){case b:return Rt(t,e,i);case v:return It(t,e,i);default:return{document:t,action:e,skip:i}}}function L(t,e,i,n,a={}){const{skip:p,ignoreSkipOperations:o=!1}=a;let c={...e},u=p||0,r=t,x=[...t.clipboard];if(A(c)){const{skip:m,action:d,document:l}=mt(t,c,u);c=d,u=m,r=l,x=[...r.clipboard]}return T(c)&&(r=ee(r,c,i)),u>0&&!o&&(r=z(r.initialState,r.operations,i,void 0,void 0,void 0,{[c.scope]:u})),r=te(r,c,u),r=g.produce(r,m=>{const d=i(m.state,c,n),l=A(e)?[...x]:[];if(d)return g.castDraft({...r,clipboard:[...l],state:d});m.clipboard=g.castDraft([...l])}),g.produce(r,m=>{if([b,v,O].includes(c.type))return m;const d=c.scope||"global";m.operations[d][m.operations[d].length-1].hash=U(m,d),!T(c)&&c.attachments&&c.attachments.forEach(l=>{const{hash:y,...h}=l;m.attachments[y]={...h}})})}function A(t){return[b,v].includes(t.type)}function T(t){return[ot,b,v,O,st].includes(t.type)}function f(t,e,i,n,a="global"){if(!t)throw new Error("Empty action type");if(typeof t!="string")throw new Error(`Invalid action type: ${t}`);const p={type:t,input:e,scope:a};i&&(p.attachments=i);try{n==null||n().parse(p.input)}catch(o){throw new Error(`Invalid action input: ${o}`)}return p}function ut(t,e=L){return(i,n,a,p)=>e(i,n,t,a,p)}const dt=(t,e)=>({name:"",documentType:"",revision:{global:0,local:0},created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...t,state:(e==null?void 0:e(t==null?void 0:t.state))??(t==null?void 0:t.state)??{global:{},local:{}}}),xt=(t,e)=>{const i=dt(t,e);return{...i,initialState:i,operations:{global:[],local:[]},clipboard:[]}},U=(t,e="global")=>_(Ot(t.state[e])),ie=(t,e=1e3)=>{const i=Math.random()*e;return _(`${(t??new Date).toISOString()}${i}`)};function w(t){return g.castImmutable(g.freeze(t,!0))}function gt(t,e){const i=[...t];let n=e||0,a=i.length>0?i[i.length-1].index:0;const p=[];for(const o of i.reverse()){if(n>0){const r=a-o.index;n-=r}if(n<0)throw new Error("Invalid operation index, missing operations");const c={ignore:n>0,operation:o},u=o.skip>0?o.skip+1:0;if(u>0&&u>n){const r=u-n;n=n+r}a=o.index,p.push(c)}return p.reverse()}function ne(t){return Object.values(t).flatMap(e=>e).sort((e,i)=>new Date(e.timestamp).getTime()-new Date(i.timestamp).getTime())}function ft(t){return Object.values(t).flatMap(e=>e).sort((e,i)=>new Date(e.operation.timestamp).getTime()-new Date(i.operation.timestamp).getTime())}function z(t,e,i,n,a,p=L,o={}){const c=ut(i,p);return C(t,e,c,n,a,o)}function C(t,e,i,n,a,p={}){const o=xt(t),c=Object.keys(e).reduce((m,d)=>{const l=d;return{...m,[l]:e[l].slice(0,a==null?void 0:a.revision[l])}},{}),u=Object.keys(c).reduce((m,d)=>{const l=d;return{...m,[l]:gt(c[l],p[l])}},{}),r=ft(u).reduce((m,{ignore:d,operation:l})=>d?i(m,J(l.scope),n,{skip:l.skip,ignoreSkipOperations:!0}):i(m,l,n,{skip:l.skip,ignoreSkipOperations:!0}),o),x=Object.keys(r.operations).reduce((m,d)=>{const l=d,y=a&&a.revision[l]<e[l].length?e[l].slice(a.revision[l]):[];return{...m,[l]:[...r.operations[l].map((h,D)=>{var B;return{...h,timestamp:((B=e[l][D])==null?void 0:B.timestamp)??h.timestamp}}),...y]}},{global:[],local:[]});return{...r,operations:x}}const ht=t=>f("SET_NAME",t,void 0,q,void 0),bt=(t=1,e="global")=>f("UNDO",t,void 0,P,e),vt=(t=1,e="global")=>f("REDO",t,void 0,I,e),yt=(t,e,i="global")=>f("PRUNE",{start:t,end:e},void 0,R,i),$=(t,e)=>f("LOAD_STATE",{state:t,operations:e},void 0,F),J=(t="global")=>f("NOOP",{},void 0,void 0,t),ae=Object.freeze(Object.defineProperty({__proto__:null,loadState:$,noop:J,prune:yt,redo:vt,setName:ht,undo:bt},Symbol.toStringTag,{value:"Module"}));class oe{constructor(e,i,n){S(this,"_document");S(this,"_reducer");S(this,"_signalDispatch");this._reducer=e,this._document=i,this._signalDispatch=n}dispatch(e,i){return this._document=this._reducer(this._document,e,this._signalDispatch,i),this}saveToFile(e,i,n){return ct(this._document,e,i,n)}async loadFromFile(e){this._document=await N(e,this._reducer)}static async stateFromFile(e,i){return await N(e,i)}get state(){return w(this._document.state)}get operations(){return w(this._document.operations)}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision.global}getRevision(e){return this._document.revision[e]}get initialState(){return w(this._document.initialState)}toDocument(){return w(this._document)}getAttachment(e){return this._document.attachments[e]}setName(e){return this.dispatch(ht(e)),this}undo(e){return this.dispatch(bt(e)),this}redo(e){return this.dispatch(vt(e)),this}prune(e,i){return this.dispatch(yt(e,i)),this}loadState(e,i){return this.dispatch($(e,i)),this}}function se(t,e){e.forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(n=>{Object.defineProperty(t.prototype,n,Object.getOwnPropertyDescriptor(i.prototype,n)||Object.create(null))})})}exports.BaseActions=ae;exports.BaseDocument=oe;exports.applyMixins=se;exports.baseReducer=L;exports.createAction=f;exports.createDocument=xt;exports.createExtendedState=dt;exports.createReducer=ut;exports.createZip=M;exports.getLocalFile=Gt;exports.getRemoteFile=Vt;exports.hashDocument=U;exports.hashKey=ie;exports.isBaseAction=T;exports.isUndoRedo=A;exports.loadFromFile=N;exports.loadFromInput=rt;exports.mapSkippedOperations=gt;exports.processUndoRedo=mt;exports.readOnly=w;exports.replayDocument=C;exports.replayOperations=z;exports.saveToFile=ct;exports.saveToFileHandle=Kt;exports.sortMappedOperations=ft;exports.sortOperations=ne;exports.zod=Tt;
|