document-model 1.0.0 → 1.0.1
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-47a38d27.mjs → index-0874c584.mjs} +1 -1
- package/dist/browser/index-71854bcc.mjs +30 -0
- package/dist/browser/{index-71473ecd.js → index-ba0b84c2.js} +1 -1
- package/dist/browser/index-ebc86e7b.js +1 -0
- package/dist/browser/index.cjs +1 -1
- package/dist/browser/index.js +3 -3
- package/dist/browser/{object-38724dbb.js → object-5f0a8dc6.js} +1 -1
- package/dist/browser/src/document/actions/types.d.ts +1 -2
- package/dist/browser/src/document/utils/base.d.ts +2 -1
- package/dist/node/document-model.cjs +1 -1
- package/dist/node/document-model.js +2 -2
- package/dist/node/document.cjs +1 -1
- package/dist/node/document.js +2 -2
- package/dist/node/{index-fbaffded.js → index-027f73ec.js} +1 -1
- package/dist/node/index-718fe9bd.mjs +30 -0
- package/dist/node/index-bb0a856f.js +1 -0
- package/dist/node/{index-78a1221c.mjs → index-ca902418.mjs} +1 -1
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.js +3 -3
- package/dist/node/{object-b1510be8.js → object-2bb87214.js} +1 -1
- package/dist/node/src/document/actions/types.d.ts +1 -2
- package/dist/node/src/document/utils/base.d.ts +2 -1
- package/package.json +1 -1
- package/dist/browser/index-1aa6b70c.js +0 -1
- package/dist/browser/index-ede882c4.mjs +0 -29
- package/dist/node/index-03f82dde.mjs +0 -29
- package/dist/node/index-0b695055.js +0 -1
- package/dist/browser/{object-916a56cd.mjs → object-05addf9f.mjs} +3 -3
- package/dist/node/{object-bdb7f8c6.mjs → object-8edc0f76.mjs} +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./object-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./object-5f0a8dc6.js");require("json-stringify-deterministic");require("immer");require("sha.js/sha1");require("jszip");const e=require("./index-ba0b84c2.js");require("zod");exports.Document=e.Document;exports.DocumentModel=e.DocumentModel$1;exports.actions=e.actions;exports.documentModel=e.documentModel;exports.module=e.module;exports.reducer=e.reducer;exports.utils=e.utils;exports.z=e.zod;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "./object-
|
|
1
|
+
import "./object-05addf9f.mjs";
|
|
2
2
|
import "json-stringify-deterministic";
|
|
3
3
|
import "immer";
|
|
4
4
|
import "sha.js/sha1";
|
|
5
5
|
import "jszip";
|
|
6
|
-
import { b as p, a as u, c, d, m as l, r as n, u as D, z as M } from "./index-
|
|
6
|
+
import { b as p, a as u, c, d, m as l, r as n, u as D, z as M } from "./index-0874c584.mjs";
|
|
7
7
|
import "zod";
|
|
8
8
|
export {
|
|
9
9
|
p as Document,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./object-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./object-5f0a8dc6.js"),r=require("./index-ebc86e7b.js");require("json-stringify-deterministic");require("immer");require("zod");require("sha.js/sha1");require("jszip");exports.BaseDocument=e.BaseDocument;exports.actions=e.BaseActions;exports.applyMixins=e.applyMixins;exports.baseReducer=e.baseReducer;exports.z=e.zod;exports.utils=r.index;
|
package/dist/browser/document.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as m, h as e, g as c, p as n, z as u } from "./object-
|
|
2
|
-
import { i as f } from "./index-
|
|
1
|
+
import { B as m, h as e, g as c, p as n, z as u } from "./object-05addf9f.mjs";
|
|
2
|
+
import { i as f } from "./index-71854bcc.mjs";
|
|
3
3
|
import "json-stringify-deterministic";
|
|
4
4
|
import "immer";
|
|
5
5
|
import "zod";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var pt = Object.defineProperty;
|
|
2
2
|
var lt = (t, e, i) => e in t ? pt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
|
|
3
3
|
var pe = (t, e, i) => (lt(t, typeof e != "symbol" ? e + "" : e, i), i);
|
|
4
|
-
import { c as dt, i as ct, a as ut, b as mt, s as Et, d as ht, l as Ot, e as St, f as s, B as l, g as gt, h as ft } from "./object-
|
|
4
|
+
import { c as dt, i as ct, a as ut, b as mt, s as Et, d as ht, l as Ot, e as St, f as s, B as l, g as gt, h as ft } from "./object-05addf9f.mjs";
|
|
5
5
|
import "json-stringify-deterministic";
|
|
6
6
|
import "immer";
|
|
7
7
|
import "sha.js/sha1";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { f as e, b as a, a as s, c as t, j as o, k as c, m as i, n as l, o as n, i as r, l as d, e as u, s as m, d as p, B as b, h as _, g, p as F, z as f } from "./object-05addf9f.mjs";
|
|
2
|
+
const y = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3
|
+
__proto__: null,
|
|
4
|
+
createAction: e,
|
|
5
|
+
createDocument: a,
|
|
6
|
+
createExtendedState: s,
|
|
7
|
+
createReducer: t,
|
|
8
|
+
createZip: o,
|
|
9
|
+
getLocalFile: c,
|
|
10
|
+
getRemoteFile: i,
|
|
11
|
+
hashDocument: l,
|
|
12
|
+
hashKey: n,
|
|
13
|
+
isBaseAction: r,
|
|
14
|
+
loadFromFile: d,
|
|
15
|
+
loadFromInput: u,
|
|
16
|
+
saveToFile: m,
|
|
17
|
+
saveToFileHandle: p
|
|
18
|
+
}, Symbol.toStringTag, { value: "Module" })), j = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
19
|
+
__proto__: null,
|
|
20
|
+
BaseDocument: b,
|
|
21
|
+
actions: _,
|
|
22
|
+
applyMixins: g,
|
|
23
|
+
baseReducer: F,
|
|
24
|
+
utils: y,
|
|
25
|
+
z: f
|
|
26
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
27
|
+
export {
|
|
28
|
+
j as D,
|
|
29
|
+
y as i
|
|
30
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ct=Object.defineProperty;var lt=(t,e,o)=>e in t?ct(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var de=(t,e,o)=>(lt(t,typeof e!="symbol"?e+"":e,o),o);const s=require("./object-
|
|
1
|
+
"use strict";var ct=Object.defineProperty;var lt=(t,e,o)=>e in t?ct(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var de=(t,e,o)=>(lt(t,typeof e!="symbol"?e+"":e,o),o);const s=require("./object-5f0a8dc6.js");require("json-stringify-deterministic");require("immer");require("sha.js/sha1");require("jszip");const r=require("zod"),dt=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),_={id:"powerhouse/document-model",name:"DocumentModel",extension:"phdm",description:"The Powerhouse Document Model describes the state and operations of a document type.",author:{name:"Powerhouse",website:"https://www.powerhouse.inc/"},specifications:[{version:1,changeLog:[],modules:[{name:"header",operations:[{name:"SetModelName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModelId",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModelExtension",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModelDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetAuthorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetAuthorWebsite",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"versioning",operations:[{name:"AddChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"UpdateChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderChangeLogItems",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReleaseNewVersion",schema:null,id:"",description:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"module",operations:[{name:"AddModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModuleName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModuleDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderModules",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"operation-error",operations:[{name:"AddOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorCode",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderOperationErrors",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"operation-example",operations:[{name:"AddOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"UpdateOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderOperationExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"operation",operations:[{name:"AddOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationReducer",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"MoveOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderModuleOperations",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"state",operations:[{name:"SetStateSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetInitialState",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"AddStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"UpdateStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderStateExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""}],state:{schema:"",initialValue:`{
|
|
2
2
|
"id": "",
|
|
3
3
|
"name": "",
|
|
4
4
|
"extension": "",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./object-5f0a8dc6.js"),t=Object.freeze(Object.defineProperty({__proto__:null,createAction:e.createAction,createDocument:e.createDocument,createExtendedState:e.createExtendedState,createReducer:e.createReducer,createZip:e.createZip,getLocalFile:e.getLocalFile,getRemoteFile:e.getRemoteFile,hashDocument:e.hashDocument,hashKey:e.hashKey,isBaseAction:e.isBaseAction,loadFromFile:e.loadFromFile,loadFromInput:e.loadFromInput,saveToFile:e.saveToFile,saveToFileHandle:e.saveToFileHandle},Symbol.toStringTag,{value:"Module"})),o=Object.freeze(Object.defineProperty({__proto__:null,BaseDocument:e.BaseDocument,actions:e.BaseActions,applyMixins:e.applyMixins,baseReducer:e.baseReducer,utils:t,z:e.zod},Symbol.toStringTag,{value:"Module"}));exports.Document=o;exports.index=t;
|
package/dist/browser/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-ebc86e7b.js"),o=require("./index-ba0b84c2.js");require("./object-5f0a8dc6.js");require("json-stringify-deterministic");require("immer");require("zod");require("sha.js/sha1");require("jszip");const u={"powerhouse/document":e.Document,"powerhouse/document-model":o.DocumentModel},t={Document:e.Document,DocumentModel:o.DocumentModel};exports.Document=e.Document;exports.DocumentModel=o.DocumentModel;exports.DocumentModels=u;exports.default=t;
|
package/dist/browser/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as o } from "./index-
|
|
2
|
-
import { D as t } from "./index-
|
|
3
|
-
import "./object-
|
|
1
|
+
import { D as o } from "./index-71854bcc.mjs";
|
|
2
|
+
import { D as t } from "./index-0874c584.mjs";
|
|
3
|
+
import "./object-05addf9f.mjs";
|
|
4
4
|
import "json-stringify-deterministic";
|
|
5
5
|
import "immer";
|
|
6
6
|
import "zod";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ot=Object.defineProperty;var st=(t,e,i)=>e in t?ot(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var j=(t,e,i)=>(st(t,typeof e!="symbol"?e+"":e,i),i);const pt=require("json-stringify-deterministic"),y=require("immer"),n=require("zod"),lt=require("sha.js/sha1"),T=require("jszip"),F=t=>t!=null,ct=n.z.any().refine(t=>F(t)),q=n.z.enum(["LOAD_STATE"]),M=n.z.enum(["PRUNE"]),R=n.z.enum(["REDO"]),P=n.z.enum(["SET_NAME"]),L=n.z.enum(["UNDO"]);function rt(){return n.z.object({__typename:n.z.literal("Action").optional(),type:n.z.string()})}function I(){return n.z.union([S(),_(),O(),E(),D()])}function mt(){return n.z.object({__typename:n.z.literal("DocumentFile").optional(),data:n.z.string(),extension:n.z.string().nullable(),fileName:n.z.string().nullable(),mimeType:n.z.string()})}function S(){return n.z.object({input:n.z.lazy(()=>U()),type:q})}function U(){return n.z.object({operations:n.z.number(),state:n.z.lazy(()=>C())})}function C(){return n.z.object({data:n.z.unknown().nullish(),name:n.z.string()})}function ut(){return n.z.object({__typename:n.z.literal("Operation").optional(),hash:n.z.string(),index:n.z.number(),timestamp:n.z.string().datetime(),type:n.z.string()})}function _(){return n.z.object({input:n.z.lazy(()=>J()),type:M})}function J(){return n.z.object({end:n.z.number().nullish(),start:n.z.number().nullish()})}function O(){return n.z.object({input:n.z.number(),type:R})}function E(){return n.z.object({input:n.z.string(),type:P})}function dt(){return n.z.object({__typename:n.z.literal("SetNameOperation").optional(),hash:n.z.string(),index:n.z.number(),input:n.z.string(),timestamp:n.z.string().datetime(),type:n.z.string()})}function D(){return n.z.object({input:n.z.number(),type:L})}const xt=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:rt,BaseActionSchema:I,DocumentFileSchema:mt,LoadStateActionInputSchema:U,LoadStateActionSchema:S,LoadStateActionStateInputSchema:C,Load_StateSchema:q,OperationSchema:ut,PruneActionInputSchema:J,PruneActionSchema:_,PruneSchema:M,RedoActionSchema:O,RedoSchema:R,SetNameActionSchema:E,SetNameOperationSchema:dt,Set_NameSchema:P,UndoActionSchema:D,UndoSchema:L,definedNonNullAnySchema:ct,isDefinedNonNullAny:F},Symbol.toStringTag,{value:"Module"}));function gt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function g(){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)}g.prototype.define=function(t,e){for(let i in t){let a=t[i].map(function(o){return o.toLowerCase()});i=i.toLowerCase();for(let o=0;o<a.length;o++){const s=a[o];if(s[0]!=="*"){if(!e&&s in this._types)throw new Error('Attempt to change mapping for "'+s+'" extension from "'+this._types[s]+'" to "'+i+'". Pass `force=true` to allow this, otherwise remove "'+s+'" from the list of extensions for "'+i+'".');this._types[s]=i}}if(e||!this._extensions[i]){const o=a[0];this._extensions[i]=o[0]!=="*"?o:o.substr(1)}}};g.prototype.getType=function(t){t=String(t);let e=t.replace(/^.*[/\\]/,"").toLowerCase(),i=e.replace(/^.*\./,"").toLowerCase(),a=e.length<t.length;return(i.length<e.length-1||!a)&&this._types[i]||null};g.prototype.getExtension=function(t){return t=/^\s*([^;\s]*)/.test(t)&&RegExp.$1,t&&this._extensions[t.toLowerCase()]||null};var ft=g,ht={"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 vt=ft;var bt=new vt(ht);const jt=gt(bt),k=new Error("File system not available.");function yt(t,e,i){throw k}function $(t){throw k}function wt(t){throw k}const zt=async t=>$();function St(t){let e="";for(let i=0;i<t.length;i+=2)e+=String.fromCharCode(parseInt(t.substr(i,2),16));return btoa(e)}const f=(t,e="sha1")=>{if(e!=="sha1")throw new Error("Only sha1 algorithm is available.");const i=new lt;return St(i.update(t).digest("hex"))},A=async t=>{const e=new T,{name:i,revision:a,documentType:o,created:s,lastModified:p}=t,l={name:i,revision:a,documentType:o,created:s,lastModified:p};return e.file("header.json",JSON.stringify(l,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(c=>{const{data:r,...b}=t.attachments[c];e.file(c,r,{base64:!0,createFolders:!0,comment:JSON.stringify(b)})}),e},B=async(t,e,i,a)=>{await(await A(t)).generateAsync({type:"uint8array",streamFiles:!0});const s=a??t.name,p=`.${i}.zip`;return yt(e,s.endsWith(p)?s:`${s}${p}`)},_t=async(t,e)=>{const a=await(await A(t)).generateAsync({type:"blob"}),o=await e.createWritable();await o.write(a),await o.close()},w=async(t,e)=>{const i=$();return Z(i,e)},Z=async(t,e)=>{const i=new T;return await i.loadAsync(t),Ot(i,e)};async function Ot(t,e){const i=t.file("state.json");if(!i)throw new Error("Initial state not found");const a=await i.async("string"),o=JSON.parse(a),s=t.file("header.json");let p=null;s&&(p=JSON.parse(await s.async("string")));const l=t.file("operations.json");if(!l)throw new Error("Operations history not found");const u=JSON.parse(await l.async("string")),c={...o,...p,initialState:o,operations:[],attachments:{...o.attachments}};let r=u.slice(0,p==null?void 0:p.revision).reduce((b,nt)=>e(b,nt),c);return p&&(r={...r,...p,operations:[...r.operations,...u.slice(p.revision)]}),r}function K(t){const e=t.replace(/^.*\./,"")||void 0,i=t.replace(/^.*[/\\]/,"")||void 0;return{extension:e,fileName:i}}async function Et(t){const{buffer:e,mimeType:i="application/octet-stream"}=await wt(),a=K(t),o=e.toString("base64");return{data:o,hash:f(o),mimeType:i,...a}}async function Dt(t){const e=await zt(),i=jt.getType(t)||"application/octet-stream",a=K(t),o=e.toString("base64");return{data:o,hash:f(o),mimeType:i,...a}}function x(t,e,i){const a=X(t),o=Q(i);return e.reduce((s,p)=>o(s,p),a)}function kt(t,e){return{...t,name:e}}function At(t,e,i){const a=Math.min(e,t.revision),o=t.operations.slice(0,t.revision-a);return{...x(t.initialState,o,i),operations:t.operations,revision:t.revision-a}}function Nt(t,e,i){const a=t.operations.length-t.revision;if(!a)throw new Error("There is no UNDO operation to REDO");const o=e<a?e:a,s=t.operations.slice(0,t.revision+o);return{...x(t.initialState,s,i),operations:t.operations,revision:t.revision+o}}function Tt(t,e,i,a){e=e||0,i=i||t.operations.length;const o=t.operations.slice(e,i),s=t.operations.slice(0,e),p=t.operations.slice(i),l=x(t.initialState,s.concat(o),a),{name:u,state:c}=l;return x(t.initialState,[...s,N({name:u,state:c},o.length),...p],a)}function Ft(t,e){return{...t,name:e.name,state:e.state??{}}}const H="SET_NAME",h="UNDO",v="REDO",d="PRUNE",W="LOAD_STATE";function z(t){return[H,h,v,d,W].includes(t.type)}function qt(t,e){return[h,v,d].includes(e.type)?t.revision:t.revision+1}function Mt(t,e){return{...t,revision:qt(t,e),lastModified:new Date().toISOString()}}function Rt(t,e){if([h,v,d,d].includes(e.type))return t;const i=t.operations.slice(0,t.revision);return{...t,operations:[...i,{...e,index:i.length,timestamp:new Date().toISOString(),hash:""}]}}function Pt(t,e){let i=Rt(t,e);return i=Mt(i,e),i}function Lt(t,e,i){switch(I().parse(e),e.type){case H:return kt(t,e.input);case h:return At(t,e.input,i);case v:return Nt(t,e.input,i);case d:return Tt(t,e.input.start,e.input.end,i);case W:return Ft(t,e.input.state);default:return t}}function G(t,e,i){let a=t;return z(e)&&(a=Lt(a,e,i)),a=Pt(a,e),a=y.produce(a,o=>{const s=i(o.state,e);if(s)return y.castDraft({...a,state:s})}),y.produce(a,o=>{o.operations[o.operations.length-1].hash=Y(o),!z(e)&&e.attachments&&e.attachments.forEach(s=>{const{hash:p,...l}=s;o.attachments[p]={...l}})})}function m(t,e,i,a){if(!t)throw new Error("Empty action type");if(typeof t!="string")throw new Error(`Invalid action type: ${t}`);const o=i?{type:t,input:e,attachments:i}:{type:t,input:e};return a==null||a().parse(o),o}function Q(t,e=G){return(i,a)=>e(i,a,t)}const V=(t,e)=>({name:"",documentType:"",revision: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)??{}}),X=(t,e)=>{const i=V(t,e);return{...i,initialState:i,operations:[]}},Y=t=>f(pt(t.state)),It=(t,e=1e3)=>{const i=Math.random()*e;return f(`${(t??new Date).toISOString()}${i}`)},tt=t=>m("SET_NAME",t,void 0,E),et=(t=1)=>m("UNDO",t,void 0,D),it=(t=1)=>m("REDO",t,void 0,O),at=(t,e)=>m("PRUNE",{start:t,end:e},void 0,_),N=(t,e)=>m("LOAD_STATE",{state:t,operations:e},void 0,S),Ut=Object.freeze(Object.defineProperty({__proto__:null,loadState:N,prune:at,redo:it,setName:tt,undo:et},Symbol.toStringTag,{value:"Module"}));class Ct{constructor(e,i){j(this,"_document");j(this,"_reducer");this._reducer=e,this._document=i}dispatch(e){return this._document=this._reducer(this._document,e),this}saveToFile(e,i,a){return B(this._document,e,i,a)}async loadFromFile(e){this._document=await w(e,this._reducer)}static async stateFromFile(e,i){return await w(e,i)}get state(){return this._document.state}get operations(){return 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}get initialState(){return this._document.initialState}getAttachment(e){return this._document.attachments[e]}setName(e){return this.dispatch(tt(e)),this}undo(e){return this.dispatch(et(e)),this}redo(e){return this.dispatch(it(e)),this}prune(e,i){return this.dispatch(at(e,i)),this}loadState(e,i){return this.dispatch(N(e,i)),this}}function Jt(t,e){e.forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(a=>{Object.defineProperty(t.prototype,a,Object.getOwnPropertyDescriptor(i.prototype,a)||Object.create(null))})})}exports.BaseActions=Ut;exports.BaseDocument=Ct;exports.applyMixins=Jt;exports.baseReducer=G;exports.createAction=m;exports.createDocument=X;exports.createExtendedState=V;exports.createReducer=Q;exports.createZip=A;exports.getLocalFile=Dt;exports.getRemoteFile=Et;exports.hashDocument=Y;exports.hashKey=It;exports.isBaseAction=z;exports.loadFromFile=w;exports.loadFromInput=Z;exports.saveToFile=B;exports.saveToFileHandle=_t;exports.zod=xt;
|
|
1
|
+
"use strict";var ot=Object.defineProperty;var st=(t,e,i)=>e in t?ot(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var j=(t,e,i)=>(st(t,typeof e!="symbol"?e+"":e,i),i);const pt=require("json-stringify-deterministic"),y=require("immer"),n=require("zod"),lt=require("sha.js/sha1"),T=require("jszip"),F=t=>t!=null,ct=n.z.any().refine(t=>F(t)),q=n.z.enum(["LOAD_STATE"]),M=n.z.enum(["PRUNE"]),R=n.z.enum(["REDO"]),P=n.z.enum(["SET_NAME"]),L=n.z.enum(["UNDO"]);function rt(){return n.z.object({__typename:n.z.literal("Action").optional(),type:n.z.string()})}function I(){return n.z.union([S(),_(),O(),E(),D()])}function mt(){return n.z.object({__typename:n.z.literal("DocumentFile").optional(),data:n.z.string(),extension:n.z.string().nullable(),fileName:n.z.string().nullable(),mimeType:n.z.string()})}function S(){return n.z.object({input:n.z.lazy(()=>U()),type:q})}function U(){return n.z.object({operations:n.z.number(),state:n.z.lazy(()=>C())})}function C(){return n.z.object({data:n.z.unknown().nullish(),name:n.z.string()})}function ut(){return n.z.object({__typename:n.z.literal("Operation").optional(),hash:n.z.string(),index:n.z.number(),timestamp:n.z.string().datetime(),type:n.z.string()})}function _(){return n.z.object({input:n.z.lazy(()=>J()),type:M})}function J(){return n.z.object({end:n.z.number().nullish(),start:n.z.number().nullish()})}function O(){return n.z.object({input:n.z.number(),type:R})}function E(){return n.z.object({input:n.z.string(),type:P})}function dt(){return n.z.object({__typename:n.z.literal("SetNameOperation").optional(),hash:n.z.string(),index:n.z.number(),input:n.z.string(),timestamp:n.z.string().datetime(),type:n.z.string()})}function D(){return n.z.object({input:n.z.number(),type:L})}const xt=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:rt,BaseActionSchema:I,DocumentFileSchema:mt,LoadStateActionInputSchema:U,LoadStateActionSchema:S,LoadStateActionStateInputSchema:C,Load_StateSchema:q,OperationSchema:ut,PruneActionInputSchema:J,PruneActionSchema:_,PruneSchema:M,RedoActionSchema:O,RedoSchema:R,SetNameActionSchema:E,SetNameOperationSchema:dt,Set_NameSchema:P,UndoActionSchema:D,UndoSchema:L,definedNonNullAnySchema:ct,isDefinedNonNullAny:F},Symbol.toStringTag,{value:"Module"}));function gt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function g(){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)}g.prototype.define=function(t,e){for(let i in t){let a=t[i].map(function(o){return o.toLowerCase()});i=i.toLowerCase();for(let o=0;o<a.length;o++){const s=a[o];if(s[0]!=="*"){if(!e&&s in this._types)throw new Error('Attempt to change mapping for "'+s+'" extension from "'+this._types[s]+'" to "'+i+'". Pass `force=true` to allow this, otherwise remove "'+s+'" from the list of extensions for "'+i+'".');this._types[s]=i}}if(e||!this._extensions[i]){const o=a[0];this._extensions[i]=o[0]!=="*"?o:o.substr(1)}}};g.prototype.getType=function(t){t=String(t);let e=t.replace(/^.*[/\\]/,"").toLowerCase(),i=e.replace(/^.*\./,"").toLowerCase(),a=e.length<t.length;return(i.length<e.length-1||!a)&&this._types[i]||null};g.prototype.getExtension=function(t){return t=/^\s*([^;\s]*)/.test(t)&&RegExp.$1,t&&this._extensions[t.toLowerCase()]||null};var ft=g,ht={"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 vt=ft;var bt=new vt(ht);const jt=gt(bt),k=new Error("File system not available.");function yt(t,e,i){throw k}function $(t){throw k}function wt(t){throw k}const zt=async t=>$();function St(t){let e="";for(let i=0;i<t.length;i+=2)e+=String.fromCharCode(parseInt(t.substr(i,2),16));return btoa(e)}const f=(t,e="sha1")=>{if(e!=="sha1")throw new Error("Only sha1 algorithm is available.");const i=new lt;return St(i.update(t).digest("hex"))},A=async t=>{const e=new T,{name:i,revision:a,documentType:o,created:s,lastModified:p}=t,l={name:i,revision:a,documentType:o,created:s,lastModified:p};return e.file("header.json",JSON.stringify(l,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(c=>{const{data:r,...b}=t.attachments[c];e.file(c,r,{base64:!0,createFolders:!0,comment:JSON.stringify(b)})}),e},B=async(t,e,i,a)=>{await(await A(t)).generateAsync({type:"uint8array",streamFiles:!0});const s=a??t.name,p=`.${i}.zip`;return yt(e,s.endsWith(p)?s:`${s}${p}`)},_t=async(t,e)=>{const a=await(await A(t)).generateAsync({type:"blob"}),o=await e.createWritable();await o.write(a),await o.close()},w=async(t,e)=>{const i=$();return Z(i,e)},Z=async(t,e)=>{const i=new T;return await i.loadAsync(t),Ot(i,e)};async function Ot(t,e){const i=t.file("state.json");if(!i)throw new Error("Initial state not found");const a=await i.async("string"),o=JSON.parse(a),s=t.file("header.json");let p=null;s&&(p=JSON.parse(await s.async("string")));const l=t.file("operations.json");if(!l)throw new Error("Operations history not found");const u=JSON.parse(await l.async("string")),c={...o,...p,initialState:o,operations:[],attachments:{...o.attachments}};let r=u.slice(0,p==null?void 0:p.revision).reduce((b,nt)=>e(b,nt),c);return p&&(r={...r,...p,operations:[...r.operations,...u.slice(p.revision)]}),r}function K(t){const e=t.replace(/^.*\./,"")||void 0,i=t.replace(/^.*[/\\]/,"")||void 0;return{extension:e,fileName:i}}async function Et(t){const{buffer:e,mimeType:i="application/octet-stream"}=await wt(),a=K(t),o=e.toString("base64");return{data:o,hash:f(o),mimeType:i,...a}}async function Dt(t){const e=await zt(),i=jt.getType(t)||"application/octet-stream",a=K(t),o=e.toString("base64");return{data:o,hash:f(o),mimeType:i,...a}}function x(t,e,i){const a=X(t),o=Q(i);return e.reduce((s,p)=>o(s,p),a)}function kt(t,e){return{...t,name:e}}function At(t,e,i){const a=Math.min(e,t.revision),o=t.operations.slice(0,t.revision-a);return{...x(t.initialState,o,i),operations:t.operations,revision:t.revision-a}}function Nt(t,e,i){const a=t.operations.length-t.revision;if(!a)throw new Error("There is no UNDO operation to REDO");const o=e<a?e:a,s=t.operations.slice(0,t.revision+o);return{...x(t.initialState,s,i),operations:t.operations,revision:t.revision+o}}function Tt(t,e,i,a){e=e||0,i=i||t.operations.length;const o=t.operations.slice(e,i),s=t.operations.slice(0,e),p=t.operations.slice(i),l=x(t.initialState,s.concat(o),a),{name:u,state:c}=l;return x(t.initialState,[...s,N({name:u,state:c},o.length),...p],a)}function Ft(t,e){return{...t,name:e.name,state:e.state??{}}}const H="SET_NAME",h="UNDO",v="REDO",d="PRUNE",W="LOAD_STATE";function qt(t,e){return[h,v,d].includes(e.type)?t.revision:t.revision+1}function Mt(t,e){return{...t,revision:qt(t,e),lastModified:new Date().toISOString()}}function Rt(t,e){if([h,v,d,d].includes(e.type))return t;const i=t.operations.slice(0,t.revision);return{...t,operations:[...i,{...e,index:i.length,timestamp:new Date().toISOString(),hash:""}]}}function Pt(t,e){let i=Rt(t,e);return i=Mt(i,e),i}function Lt(t,e,i){switch(I().parse(e),e.type){case H:return kt(t,e.input);case h:return At(t,e.input,i);case v:return Nt(t,e.input,i);case d:return Tt(t,e.input.start,e.input.end,i);case W:return Ft(t,e.input.state);default:return t}}function G(t,e,i){let a=t;return z(e)&&(a=Lt(a,e,i)),a=Pt(a,e),a=y.produce(a,o=>{const s=i(o.state,e);if(s)return y.castDraft({...a,state:s})}),y.produce(a,o=>{o.operations[o.operations.length-1].hash=Y(o),!z(e)&&e.attachments&&e.attachments.forEach(s=>{const{hash:p,...l}=s;o.attachments[p]={...l}})})}function z(t){return[H,h,v,d,W].includes(t.type)}function m(t,e,i,a){if(!t)throw new Error("Empty action type");if(typeof t!="string")throw new Error(`Invalid action type: ${t}`);const o=i?{type:t,input:e,attachments:i}:{type:t,input:e};return a==null||a().parse(o),o}function Q(t,e=G){return(i,a)=>e(i,a,t)}const V=(t,e)=>({name:"",documentType:"",revision: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)??{}}),X=(t,e)=>{const i=V(t,e);return{...i,initialState:i,operations:[]}},Y=t=>f(pt(t.state)),It=(t,e=1e3)=>{const i=Math.random()*e;return f(`${(t??new Date).toISOString()}${i}`)},tt=t=>m("SET_NAME",t,void 0,E),et=(t=1)=>m("UNDO",t,void 0,D),it=(t=1)=>m("REDO",t,void 0,O),at=(t,e)=>m("PRUNE",{start:t,end:e},void 0,_),N=(t,e)=>m("LOAD_STATE",{state:t,operations:e},void 0,S),Ut=Object.freeze(Object.defineProperty({__proto__:null,loadState:N,prune:at,redo:it,setName:tt,undo:et},Symbol.toStringTag,{value:"Module"}));class Ct{constructor(e,i){j(this,"_document");j(this,"_reducer");this._reducer=e,this._document=i}dispatch(e){return this._document=this._reducer(this._document,e),this}saveToFile(e,i,a){return B(this._document,e,i,a)}async loadFromFile(e){this._document=await w(e,this._reducer)}static async stateFromFile(e,i){return await w(e,i)}get state(){return this._document.state}get operations(){return 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}get initialState(){return this._document.initialState}getAttachment(e){return this._document.attachments[e]}setName(e){return this.dispatch(tt(e)),this}undo(e){return this.dispatch(et(e)),this}redo(e){return this.dispatch(it(e)),this}prune(e,i){return this.dispatch(at(e,i)),this}loadState(e,i){return this.dispatch(N(e,i)),this}}function Jt(t,e){e.forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(a=>{Object.defineProperty(t.prototype,a,Object.getOwnPropertyDescriptor(i.prototype,a)||Object.create(null))})})}exports.BaseActions=Ut;exports.BaseDocument=Ct;exports.applyMixins=Jt;exports.baseReducer=G;exports.createAction=m;exports.createDocument=X;exports.createExtendedState=V;exports.createReducer=Q;exports.createZip=A;exports.getLocalFile=Dt;exports.getRemoteFile=Et;exports.hashDocument=Y;exports.hashKey=It;exports.isBaseAction=z;exports.loadFromFile=w;exports.loadFromInput=Z;exports.saveToFile=B;exports.saveToFileHandle=_t;exports.zod=xt;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseAction } from '../types';
|
|
2
2
|
export declare const SET_NAME = "SET_NAME";
|
|
3
3
|
export declare const UNDO = "UNDO";
|
|
4
4
|
export declare const REDO = "REDO";
|
|
@@ -6,4 +6,3 @@ export declare const PRUNE = "PRUNE";
|
|
|
6
6
|
export declare const LOAD_STATE = "LOAD_STATE";
|
|
7
7
|
export { LoadStateAction, PruneAction, RedoAction, SetNameAction, UndoAction, } from '../types';
|
|
8
8
|
export type { BaseAction };
|
|
9
|
-
export declare function isBaseAction(action: Action): action is BaseAction;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { baseReducer } from '../reducer';
|
|
2
|
-
import { Action, Document, ExtendedState, ImmutableStateReducer, Reducer } from '../types';
|
|
2
|
+
import { Action, BaseAction, Document, ExtendedState, ImmutableStateReducer, Reducer } from '../types';
|
|
3
|
+
export declare function isBaseAction(action: Action): action is BaseAction;
|
|
3
4
|
/**
|
|
4
5
|
* Helper function to be used by action creators.
|
|
5
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./object-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./object-2bb87214.js");require("json-stringify-deterministic");require("immer");require("crypto");require("fs");require("https");require("path");require("jszip");const e=require("./index-027f73ec.js");require("zod");exports.Document=e.Document;exports.DocumentModel=e.DocumentModel$1;exports.actions=e.actions;exports.documentModel=e.documentModel;exports.module=e.module;exports.reducer=e.reducer;exports.utils=e.utils;exports.z=e.zod;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./object-
|
|
1
|
+
import "./object-8edc0f76.mjs";
|
|
2
2
|
import "json-stringify-deterministic";
|
|
3
3
|
import "immer";
|
|
4
4
|
import "crypto";
|
|
@@ -6,7 +6,7 @@ import "fs";
|
|
|
6
6
|
import "https";
|
|
7
7
|
import "path";
|
|
8
8
|
import "jszip";
|
|
9
|
-
import { b as d, a as l, c as n, d as D, m as M, r as b, u as f, z as x } from "./index-
|
|
9
|
+
import { b as d, a as l, c as n, d as D, m as M, r as b, u as f, z as x } from "./index-ca902418.mjs";
|
|
10
10
|
import "zod";
|
|
11
11
|
export {
|
|
12
12
|
d as Document,
|
package/dist/node/document.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./object-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./object-2bb87214.js"),r=require("./index-bb0a856f.js");require("json-stringify-deterministic");require("immer");require("zod");require("crypto");require("fs");require("https");require("path");require("jszip");exports.BaseDocument=e.BaseDocument;exports.actions=e.BaseActions;exports.applyMixins=e.applyMixins;exports.baseReducer=e.baseReducer;exports.z=e.zod;exports.utils=r.index;
|
package/dist/node/document.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as n, h as u, g as x, p as f, z as l } from "./object-
|
|
2
|
-
import { i as b } from "./index-
|
|
1
|
+
import { B as n, h as u, g as x, p as f, z as l } from "./object-8edc0f76.mjs";
|
|
2
|
+
import { i as b } from "./index-718fe9bd.mjs";
|
|
3
3
|
import "json-stringify-deterministic";
|
|
4
4
|
import "immer";
|
|
5
5
|
import "zod";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ct=Object.defineProperty;var lt=(t,e,o)=>e in t?ct(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var de=(t,e,o)=>(lt(t,typeof e!="symbol"?e+"":e,o),o);const s=require("./object-
|
|
1
|
+
"use strict";var ct=Object.defineProperty;var lt=(t,e,o)=>e in t?ct(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var de=(t,e,o)=>(lt(t,typeof e!="symbol"?e+"":e,o),o);const s=require("./object-2bb87214.js");require("json-stringify-deterministic");require("immer");require("crypto");require("fs");require("https");require("path");require("jszip");const r=require("zod"),dt=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),_={id:"powerhouse/document-model",name:"DocumentModel",extension:"phdm",description:"The Powerhouse Document Model describes the state and operations of a document type.",author:{name:"Powerhouse",website:"https://www.powerhouse.inc/"},specifications:[{version:1,changeLog:[],modules:[{name:"header",operations:[{name:"SetModelName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModelId",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModelExtension",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModelDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetAuthorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetAuthorWebsite",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"versioning",operations:[{name:"AddChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"UpdateChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderChangeLogItems",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReleaseNewVersion",schema:null,id:"",description:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"module",operations:[{name:"AddModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModuleName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetModuleDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderModules",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"operation-error",operations:[{name:"AddOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorCode",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationErrorTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderOperationErrors",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"operation-example",operations:[{name:"AddOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"UpdateOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderOperationExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"operation",operations:[{name:"AddOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetOperationReducer",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"MoveOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderModuleOperations",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""},{name:"state",operations:[{name:"SetStateSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"SetInitialState",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"AddStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"UpdateStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"DeleteStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]},{name:"ReorderStateExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[]}],id:"",description:""}],state:{schema:"",initialValue:`{
|
|
2
2
|
"id": "",
|
|
3
3
|
"name": "",
|
|
4
4
|
"extension": "",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { f as e, b as a, a as s, c as t, j as o, k as c, m as i, n as l, o as n, i as r, l as d, e as u, s as m, d as p, B as b, h as _, g, p as F, z as f } from "./object-8edc0f76.mjs";
|
|
2
|
+
const y = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3
|
+
__proto__: null,
|
|
4
|
+
createAction: e,
|
|
5
|
+
createDocument: a,
|
|
6
|
+
createExtendedState: s,
|
|
7
|
+
createReducer: t,
|
|
8
|
+
createZip: o,
|
|
9
|
+
getLocalFile: c,
|
|
10
|
+
getRemoteFile: i,
|
|
11
|
+
hashDocument: l,
|
|
12
|
+
hashKey: n,
|
|
13
|
+
isBaseAction: r,
|
|
14
|
+
loadFromFile: d,
|
|
15
|
+
loadFromInput: u,
|
|
16
|
+
saveToFile: m,
|
|
17
|
+
saveToFileHandle: p
|
|
18
|
+
}, Symbol.toStringTag, { value: "Module" })), j = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
19
|
+
__proto__: null,
|
|
20
|
+
BaseDocument: b,
|
|
21
|
+
actions: _,
|
|
22
|
+
applyMixins: g,
|
|
23
|
+
baseReducer: F,
|
|
24
|
+
utils: y,
|
|
25
|
+
z: f
|
|
26
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
27
|
+
export {
|
|
28
|
+
j as D,
|
|
29
|
+
y as i
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./object-2bb87214.js"),t=Object.freeze(Object.defineProperty({__proto__:null,createAction:e.createAction,createDocument:e.createDocument,createExtendedState:e.createExtendedState,createReducer:e.createReducer,createZip:e.createZip,getLocalFile:e.getLocalFile,getRemoteFile:e.getRemoteFile,hashDocument:e.hashDocument,hashKey:e.hashKey,isBaseAction:e.isBaseAction,loadFromFile:e.loadFromFile,loadFromInput:e.loadFromInput,saveToFile:e.saveToFile,saveToFileHandle:e.saveToFileHandle},Symbol.toStringTag,{value:"Module"})),o=Object.freeze(Object.defineProperty({__proto__:null,BaseDocument:e.BaseDocument,actions:e.BaseActions,applyMixins:e.applyMixins,baseReducer:e.baseReducer,utils:t,z:e.zod},Symbol.toStringTag,{value:"Module"}));exports.Document=o;exports.index=t;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var pt = Object.defineProperty;
|
|
2
2
|
var lt = (t, e, i) => e in t ? pt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
|
|
3
3
|
var pe = (t, e, i) => (lt(t, typeof e != "symbol" ? e + "" : e, i), i);
|
|
4
|
-
import { c as dt, i as ct, a as ut, b as mt, s as Et, d as ht, l as Ot, e as St, f as s, B as l, g as gt, h as ft } from "./object-
|
|
4
|
+
import { c as dt, i as ct, a as ut, b as mt, s as Et, d as ht, l as Ot, e as St, f as s, B as l, g as gt, h as ft } from "./object-8edc0f76.mjs";
|
|
5
5
|
import "json-stringify-deterministic";
|
|
6
6
|
import "immer";
|
|
7
7
|
import "crypto";
|
package/dist/node/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./index-bb0a856f.js"),o=require("./index-027f73ec.js");require("./object-2bb87214.js");require("json-stringify-deterministic");require("immer");require("zod");require("crypto");require("fs");require("https");require("path");require("jszip");const u={"powerhouse/document":e.Document,"powerhouse/document-model":o.DocumentModel},r={Document:e.Document,DocumentModel:o.DocumentModel};exports.Document=e.Document;exports.DocumentModel=o.DocumentModel;exports.DocumentModels=u;exports.default=r;
|
package/dist/node/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as o } from "./index-
|
|
2
|
-
import { D as t } from "./index-
|
|
3
|
-
import "./object-
|
|
1
|
+
import { D as o } from "./index-718fe9bd.mjs";
|
|
2
|
+
import { D as t } from "./index-ca902418.mjs";
|
|
3
|
+
import "./object-8edc0f76.mjs";
|
|
4
4
|
import "json-stringify-deterministic";
|
|
5
5
|
import "immer";
|
|
6
6
|
import "zod";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ot=Object.defineProperty;var st=(t,e,i)=>e in t?ot(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var b=(t,e,i)=>(st(t,typeof e!="symbol"?e+"":e,i),i);const pt=require("json-stringify-deterministic"),j=require("immer"),o=require("zod"),ct=require("crypto"),w=require("fs"),lt=require("https"),rt=require("path"),T=require("jszip"),F=t=>t!=null,mt=o.z.any().refine(t=>F(t)),q=o.z.enum(["LOAD_STATE"]),P=o.z.enum(["PRUNE"]),M=o.z.enum(["REDO"]),R=o.z.enum(["SET_NAME"]),L=o.z.enum(["UNDO"]);function ut(){return o.z.object({__typename:o.z.literal("Action").optional(),type:o.z.string()})}function I(){return o.z.union([_(),O(),k(),D(),E()])}function dt(){return o.z.object({__typename:o.z.literal("DocumentFile").optional(),data:o.z.string(),extension:o.z.string().nullable(),fileName:o.z.string().nullable(),mimeType:o.z.string()})}function _(){return o.z.object({input:o.z.lazy(()=>U()),type:q})}function U(){return o.z.object({operations:o.z.number(),state:o.z.lazy(()=>J())})}function J(){return o.z.object({data:o.z.unknown().nullish(),name:o.z.string()})}function xt(){return o.z.object({__typename:o.z.literal("Operation").optional(),hash:o.z.string(),index:o.z.number(),timestamp:o.z.string().datetime(),type:o.z.string()})}function O(){return o.z.object({input:o.z.lazy(()=>B()),type:P})}function B(){return o.z.object({end:o.z.number().nullish(),start:o.z.number().nullish()})}function k(){return o.z.object({input:o.z.number(),type:M})}function D(){return o.z.object({input:o.z.string(),type:R})}function ft(){return o.z.object({__typename:o.z.literal("SetNameOperation").optional(),hash:o.z.string(),index:o.z.number(),input:o.z.string(),timestamp:o.z.string().datetime(),type:o.z.string()})}function E(){return o.z.object({input:o.z.number(),type:L})}const gt=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:ut,BaseActionSchema:I,DocumentFileSchema:dt,LoadStateActionInputSchema:U,LoadStateActionSchema:_,LoadStateActionStateInputSchema:J,Load_StateSchema:q,OperationSchema:xt,PruneActionInputSchema:B,PruneActionSchema:O,PruneSchema:P,RedoActionSchema:k,RedoSchema:M,SetNameActionSchema:D,SetNameOperationSchema:ft,Set_NameSchema:R,UndoActionSchema:E,UndoSchema:L,definedNonNullAnySchema:mt,isDefinedNonNullAny:F},Symbol.toStringTag,{value:"Module"}));function ht(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function f(){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)}f.prototype.define=function(t,e){for(let i in t){let a=t[i].map(function(n){return n.toLowerCase()});i=i.toLowerCase();for(let n=0;n<a.length;n++){const s=a[n];if(s[0]!=="*"){if(!e&&s in this._types)throw new Error('Attempt to change mapping for "'+s+'" extension from "'+this._types[s]+'" to "'+i+'". Pass `force=true` to allow this, otherwise remove "'+s+'" from the list of extensions for "'+i+'".');this._types[s]=i}}if(e||!this._extensions[i]){const n=a[0];this._extensions[i]=n[0]!=="*"?n:n.substr(1)}}};f.prototype.getType=function(t){t=String(t);let e=t.replace(/^.*[/\\]/,"").toLowerCase(),i=e.replace(/^.*\./,"").toLowerCase(),a=e.length<t.length;return(i.length<e.length-1||!a)&&this._types[i]||null};f.prototype.getExtension=function(t){return t=/^\s*([^;\s]*)/.test(t)&&RegExp.$1,t&&this._extensions[t.toLowerCase()]||null};var vt=f,yt={"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 bt=vt;var jt=new bt(yt);const wt=ht(jt);function zt(t,e,i){const a=rt.join(t,e);return w.mkdirSync(t,{recursive:!0}),new Promise((n,s)=>{try{w.writeFile(a,i,{},p=>{p?s(p):n(a)})}catch(p){s(p)}})}function C(t){return w.readFileSync(t)}function St(t){return new Promise((e,i)=>{lt.get(t,a=>{const n=[],s=a.headers["content-type"];a.on("data",p=>{n.push(p)}),a.on("end",()=>{e({buffer:Buffer.concat(n),mimeType:s})})}).on("error",a=>{i(a)})})}const _t=async t=>C(t),g=(t,e="sha1")=>ct.createHash(e).update(t).digest("base64"),A=async t=>{const e=new T,{name:i,revision:a,documentType:n,created:s,lastModified:p}=t,c={name:i,revision:a,documentType:n,created:s,lastModified:p};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(l=>{const{data:r,...y}=t.attachments[l];e.file(l,r,{base64:!0,createFolders:!0,comment:JSON.stringify(y)})}),e},$=async(t,e,i,a)=>{const s=await(await A(t)).generateAsync({type:"uint8array",streamFiles:!0}),p=a??t.name,c=`.${i}.zip`;return zt(e,p.endsWith(c)?p:`${p}${c}`,s)},Ot=async(t,e)=>{const a=await(await A(t)).generateAsync({type:"blob"}),n=await e.createWritable();await n.write(a),await n.close()},z=async(t,e)=>{const i=C(t);return Z(i,e)},Z=async(t,e)=>{const i=new T;return await i.loadAsync(t),kt(i,e)};async function kt(t,e){const i=t.file("state.json");if(!i)throw new Error("Initial state not found");const a=await i.async("string"),n=JSON.parse(a),s=t.file("header.json");let p=null;s&&(p=JSON.parse(await s.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")),l={...n,...p,initialState:n,operations:[],attachments:{...n.attachments}};let r=u.slice(0,p==null?void 0:p.revision).reduce((y,nt)=>e(y,nt),l);return p&&(r={...r,...p,operations:[...r.operations,...u.slice(p.revision)]}),r}function H(t){const e=t.replace(/^.*\./,"")||void 0,i=t.replace(/^.*[/\\]/,"")||void 0;return{extension:e,fileName:i}}async function Dt(t){const{buffer:e,mimeType:i="application/octet-stream"}=await St(t),a=H(t),n=e.toString("base64");return{data:n,hash:g(n),mimeType:i,...a}}async function Et(t){const e=await _t(t),i=wt.getType(t)||"application/octet-stream",a=H(t),n=e.toString("base64");return{data:n,hash:g(n),mimeType:i,...a}}function x(t,e,i){const a=X(t),n=Q(i);return e.reduce((s,p)=>n(s,p),a)}function At(t,e){return{...t,name:e}}function Nt(t,e,i){const a=Math.min(e,t.revision),n=t.operations.slice(0,t.revision-a);return{...x(t.initialState,n,i),operations:t.operations,revision:t.revision-a}}function Tt(t,e,i){const a=t.operations.length-t.revision;if(!a)throw new Error("There is no UNDO operation to REDO");const n=e<a?e:a,s=t.operations.slice(0,t.revision+n);return{...x(t.initialState,s,i),operations:t.operations,revision:t.revision+n}}function Ft(t,e,i,a){e=e||0,i=i||t.operations.length;const n=t.operations.slice(e,i),s=t.operations.slice(0,e),p=t.operations.slice(i),c=x(t.initialState,s.concat(n),a),{name:u,state:l}=c;return x(t.initialState,[...s,N({name:u,state:l},n.length),...p],a)}function qt(t,e){return{...t,name:e.name,state:e.state??{}}}const K="SET_NAME",h="UNDO",v="REDO",d="PRUNE",W="LOAD_STATE";function S(t){return[K,h,v,d,W].includes(t.type)}function Pt(t,e){return[h,v,d].includes(e.type)?t.revision:t.revision+1}function Mt(t,e){return{...t,revision:Pt(t,e),lastModified:new Date().toISOString()}}function Rt(t,e){if([h,v,d,d].includes(e.type))return t;const i=t.operations.slice(0,t.revision);return{...t,operations:[...i,{...e,index:i.length,timestamp:new Date().toISOString(),hash:""}]}}function Lt(t,e){let i=Rt(t,e);return i=Mt(i,e),i}function It(t,e,i){switch(I().parse(e),e.type){case K:return At(t,e.input);case h:return Nt(t,e.input,i);case v:return Tt(t,e.input,i);case d:return Ft(t,e.input.start,e.input.end,i);case W:return qt(t,e.input.state);default:return t}}function G(t,e,i){let a=t;return S(e)&&(a=It(a,e,i)),a=Lt(a,e),a=j.produce(a,n=>{const s=i(n.state,e);if(s)return j.castDraft({...a,state:s})}),j.produce(a,n=>{n.operations[n.operations.length-1].hash=Y(n),!S(e)&&e.attachments&&e.attachments.forEach(s=>{const{hash:p,...c}=s;n.attachments[p]={...c}})})}function m(t,e,i,a){if(!t)throw new Error("Empty action type");if(typeof t!="string")throw new Error(`Invalid action type: ${t}`);const n=i?{type:t,input:e,attachments:i}:{type:t,input:e};return a==null||a().parse(n),n}function Q(t,e=G){return(i,a)=>e(i,a,t)}const V=(t,e)=>({name:"",documentType:"",revision: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)??{}}),X=(t,e)=>{const i=V(t,e);return{...i,initialState:i,operations:[]}},Y=t=>g(pt(t.state)),Ut=(t,e=1e3)=>{const i=Math.random()*e;return g(`${(t??new Date).toISOString()}${i}`)},tt=t=>m("SET_NAME",t,void 0,D),et=(t=1)=>m("UNDO",t,void 0,E),it=(t=1)=>m("REDO",t,void 0,k),at=(t,e)=>m("PRUNE",{start:t,end:e},void 0,O),N=(t,e)=>m("LOAD_STATE",{state:t,operations:e},void 0,_),Jt=Object.freeze(Object.defineProperty({__proto__:null,loadState:N,prune:at,redo:it,setName:tt,undo:et},Symbol.toStringTag,{value:"Module"}));class Bt{constructor(e,i){b(this,"_document");b(this,"_reducer");this._reducer=e,this._document=i}dispatch(e){return this._document=this._reducer(this._document,e),this}saveToFile(e,i,a){return $(this._document,e,i,a)}async loadFromFile(e){this._document=await z(e,this._reducer)}static async stateFromFile(e,i){return await z(e,i)}get state(){return this._document.state}get operations(){return 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}get initialState(){return this._document.initialState}getAttachment(e){return this._document.attachments[e]}setName(e){return this.dispatch(tt(e)),this}undo(e){return this.dispatch(et(e)),this}redo(e){return this.dispatch(it(e)),this}prune(e,i){return this.dispatch(at(e,i)),this}loadState(e,i){return this.dispatch(N(e,i)),this}}function Ct(t,e){e.forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(a=>{Object.defineProperty(t.prototype,a,Object.getOwnPropertyDescriptor(i.prototype,a)||Object.create(null))})})}exports.BaseActions=Jt;exports.BaseDocument=Bt;exports.applyMixins=Ct;exports.baseReducer=G;exports.createAction=m;exports.createDocument=X;exports.createExtendedState=V;exports.createReducer=Q;exports.createZip=A;exports.getLocalFile=Et;exports.getRemoteFile=Dt;exports.hashDocument=Y;exports.hashKey=Ut;exports.isBaseAction=S;exports.loadFromFile=z;exports.loadFromInput=Z;exports.saveToFile=$;exports.saveToFileHandle=Ot;exports.zod=gt;
|
|
1
|
+
"use strict";var ot=Object.defineProperty;var st=(t,e,i)=>e in t?ot(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i;var b=(t,e,i)=>(st(t,typeof e!="symbol"?e+"":e,i),i);const pt=require("json-stringify-deterministic"),j=require("immer"),o=require("zod"),ct=require("crypto"),w=require("fs"),lt=require("https"),rt=require("path"),T=require("jszip"),F=t=>t!=null,mt=o.z.any().refine(t=>F(t)),q=o.z.enum(["LOAD_STATE"]),P=o.z.enum(["PRUNE"]),M=o.z.enum(["REDO"]),R=o.z.enum(["SET_NAME"]),L=o.z.enum(["UNDO"]);function ut(){return o.z.object({__typename:o.z.literal("Action").optional(),type:o.z.string()})}function I(){return o.z.union([_(),O(),k(),D(),E()])}function dt(){return o.z.object({__typename:o.z.literal("DocumentFile").optional(),data:o.z.string(),extension:o.z.string().nullable(),fileName:o.z.string().nullable(),mimeType:o.z.string()})}function _(){return o.z.object({input:o.z.lazy(()=>U()),type:q})}function U(){return o.z.object({operations:o.z.number(),state:o.z.lazy(()=>J())})}function J(){return o.z.object({data:o.z.unknown().nullish(),name:o.z.string()})}function xt(){return o.z.object({__typename:o.z.literal("Operation").optional(),hash:o.z.string(),index:o.z.number(),timestamp:o.z.string().datetime(),type:o.z.string()})}function O(){return o.z.object({input:o.z.lazy(()=>B()),type:P})}function B(){return o.z.object({end:o.z.number().nullish(),start:o.z.number().nullish()})}function k(){return o.z.object({input:o.z.number(),type:M})}function D(){return o.z.object({input:o.z.string(),type:R})}function ft(){return o.z.object({__typename:o.z.literal("SetNameOperation").optional(),hash:o.z.string(),index:o.z.number(),input:o.z.string(),timestamp:o.z.string().datetime(),type:o.z.string()})}function E(){return o.z.object({input:o.z.number(),type:L})}const gt=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:ut,BaseActionSchema:I,DocumentFileSchema:dt,LoadStateActionInputSchema:U,LoadStateActionSchema:_,LoadStateActionStateInputSchema:J,Load_StateSchema:q,OperationSchema:xt,PruneActionInputSchema:B,PruneActionSchema:O,PruneSchema:P,RedoActionSchema:k,RedoSchema:M,SetNameActionSchema:D,SetNameOperationSchema:ft,Set_NameSchema:R,UndoActionSchema:E,UndoSchema:L,definedNonNullAnySchema:mt,isDefinedNonNullAny:F},Symbol.toStringTag,{value:"Module"}));function ht(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function f(){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)}f.prototype.define=function(t,e){for(let i in t){let a=t[i].map(function(n){return n.toLowerCase()});i=i.toLowerCase();for(let n=0;n<a.length;n++){const s=a[n];if(s[0]!=="*"){if(!e&&s in this._types)throw new Error('Attempt to change mapping for "'+s+'" extension from "'+this._types[s]+'" to "'+i+'". Pass `force=true` to allow this, otherwise remove "'+s+'" from the list of extensions for "'+i+'".');this._types[s]=i}}if(e||!this._extensions[i]){const n=a[0];this._extensions[i]=n[0]!=="*"?n:n.substr(1)}}};f.prototype.getType=function(t){t=String(t);let e=t.replace(/^.*[/\\]/,"").toLowerCase(),i=e.replace(/^.*\./,"").toLowerCase(),a=e.length<t.length;return(i.length<e.length-1||!a)&&this._types[i]||null};f.prototype.getExtension=function(t){return t=/^\s*([^;\s]*)/.test(t)&&RegExp.$1,t&&this._extensions[t.toLowerCase()]||null};var vt=f,yt={"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 bt=vt;var jt=new bt(yt);const wt=ht(jt);function zt(t,e,i){const a=rt.join(t,e);return w.mkdirSync(t,{recursive:!0}),new Promise((n,s)=>{try{w.writeFile(a,i,{},p=>{p?s(p):n(a)})}catch(p){s(p)}})}function C(t){return w.readFileSync(t)}function St(t){return new Promise((e,i)=>{lt.get(t,a=>{const n=[],s=a.headers["content-type"];a.on("data",p=>{n.push(p)}),a.on("end",()=>{e({buffer:Buffer.concat(n),mimeType:s})})}).on("error",a=>{i(a)})})}const _t=async t=>C(t),g=(t,e="sha1")=>ct.createHash(e).update(t).digest("base64"),A=async t=>{const e=new T,{name:i,revision:a,documentType:n,created:s,lastModified:p}=t,c={name:i,revision:a,documentType:n,created:s,lastModified:p};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(l=>{const{data:r,...y}=t.attachments[l];e.file(l,r,{base64:!0,createFolders:!0,comment:JSON.stringify(y)})}),e},$=async(t,e,i,a)=>{const s=await(await A(t)).generateAsync({type:"uint8array",streamFiles:!0}),p=a??t.name,c=`.${i}.zip`;return zt(e,p.endsWith(c)?p:`${p}${c}`,s)},Ot=async(t,e)=>{const a=await(await A(t)).generateAsync({type:"blob"}),n=await e.createWritable();await n.write(a),await n.close()},z=async(t,e)=>{const i=C(t);return Z(i,e)},Z=async(t,e)=>{const i=new T;return await i.loadAsync(t),kt(i,e)};async function kt(t,e){const i=t.file("state.json");if(!i)throw new Error("Initial state not found");const a=await i.async("string"),n=JSON.parse(a),s=t.file("header.json");let p=null;s&&(p=JSON.parse(await s.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")),l={...n,...p,initialState:n,operations:[],attachments:{...n.attachments}};let r=u.slice(0,p==null?void 0:p.revision).reduce((y,nt)=>e(y,nt),l);return p&&(r={...r,...p,operations:[...r.operations,...u.slice(p.revision)]}),r}function H(t){const e=t.replace(/^.*\./,"")||void 0,i=t.replace(/^.*[/\\]/,"")||void 0;return{extension:e,fileName:i}}async function Dt(t){const{buffer:e,mimeType:i="application/octet-stream"}=await St(t),a=H(t),n=e.toString("base64");return{data:n,hash:g(n),mimeType:i,...a}}async function Et(t){const e=await _t(t),i=wt.getType(t)||"application/octet-stream",a=H(t),n=e.toString("base64");return{data:n,hash:g(n),mimeType:i,...a}}function x(t,e,i){const a=X(t),n=Q(i);return e.reduce((s,p)=>n(s,p),a)}function At(t,e){return{...t,name:e}}function Nt(t,e,i){const a=Math.min(e,t.revision),n=t.operations.slice(0,t.revision-a);return{...x(t.initialState,n,i),operations:t.operations,revision:t.revision-a}}function Tt(t,e,i){const a=t.operations.length-t.revision;if(!a)throw new Error("There is no UNDO operation to REDO");const n=e<a?e:a,s=t.operations.slice(0,t.revision+n);return{...x(t.initialState,s,i),operations:t.operations,revision:t.revision+n}}function Ft(t,e,i,a){e=e||0,i=i||t.operations.length;const n=t.operations.slice(e,i),s=t.operations.slice(0,e),p=t.operations.slice(i),c=x(t.initialState,s.concat(n),a),{name:u,state:l}=c;return x(t.initialState,[...s,N({name:u,state:l},n.length),...p],a)}function qt(t,e){return{...t,name:e.name,state:e.state??{}}}const K="SET_NAME",h="UNDO",v="REDO",d="PRUNE",W="LOAD_STATE";function Pt(t,e){return[h,v,d].includes(e.type)?t.revision:t.revision+1}function Mt(t,e){return{...t,revision:Pt(t,e),lastModified:new Date().toISOString()}}function Rt(t,e){if([h,v,d,d].includes(e.type))return t;const i=t.operations.slice(0,t.revision);return{...t,operations:[...i,{...e,index:i.length,timestamp:new Date().toISOString(),hash:""}]}}function Lt(t,e){let i=Rt(t,e);return i=Mt(i,e),i}function It(t,e,i){switch(I().parse(e),e.type){case K:return At(t,e.input);case h:return Nt(t,e.input,i);case v:return Tt(t,e.input,i);case d:return Ft(t,e.input.start,e.input.end,i);case W:return qt(t,e.input.state);default:return t}}function G(t,e,i){let a=t;return S(e)&&(a=It(a,e,i)),a=Lt(a,e),a=j.produce(a,n=>{const s=i(n.state,e);if(s)return j.castDraft({...a,state:s})}),j.produce(a,n=>{n.operations[n.operations.length-1].hash=Y(n),!S(e)&&e.attachments&&e.attachments.forEach(s=>{const{hash:p,...c}=s;n.attachments[p]={...c}})})}function S(t){return[K,h,v,d,W].includes(t.type)}function m(t,e,i,a){if(!t)throw new Error("Empty action type");if(typeof t!="string")throw new Error(`Invalid action type: ${t}`);const n=i?{type:t,input:e,attachments:i}:{type:t,input:e};return a==null||a().parse(n),n}function Q(t,e=G){return(i,a)=>e(i,a,t)}const V=(t,e)=>({name:"",documentType:"",revision: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)??{}}),X=(t,e)=>{const i=V(t,e);return{...i,initialState:i,operations:[]}},Y=t=>g(pt(t.state)),Ut=(t,e=1e3)=>{const i=Math.random()*e;return g(`${(t??new Date).toISOString()}${i}`)},tt=t=>m("SET_NAME",t,void 0,D),et=(t=1)=>m("UNDO",t,void 0,E),it=(t=1)=>m("REDO",t,void 0,k),at=(t,e)=>m("PRUNE",{start:t,end:e},void 0,O),N=(t,e)=>m("LOAD_STATE",{state:t,operations:e},void 0,_),Jt=Object.freeze(Object.defineProperty({__proto__:null,loadState:N,prune:at,redo:it,setName:tt,undo:et},Symbol.toStringTag,{value:"Module"}));class Bt{constructor(e,i){b(this,"_document");b(this,"_reducer");this._reducer=e,this._document=i}dispatch(e){return this._document=this._reducer(this._document,e),this}saveToFile(e,i,a){return $(this._document,e,i,a)}async loadFromFile(e){this._document=await z(e,this._reducer)}static async stateFromFile(e,i){return await z(e,i)}get state(){return this._document.state}get operations(){return 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}get initialState(){return this._document.initialState}getAttachment(e){return this._document.attachments[e]}setName(e){return this.dispatch(tt(e)),this}undo(e){return this.dispatch(et(e)),this}redo(e){return this.dispatch(it(e)),this}prune(e,i){return this.dispatch(at(e,i)),this}loadState(e,i){return this.dispatch(N(e,i)),this}}function Ct(t,e){e.forEach(i=>{Object.getOwnPropertyNames(i.prototype).forEach(a=>{Object.defineProperty(t.prototype,a,Object.getOwnPropertyDescriptor(i.prototype,a)||Object.create(null))})})}exports.BaseActions=Jt;exports.BaseDocument=Bt;exports.applyMixins=Ct;exports.baseReducer=G;exports.createAction=m;exports.createDocument=X;exports.createExtendedState=V;exports.createReducer=Q;exports.createZip=A;exports.getLocalFile=Et;exports.getRemoteFile=Dt;exports.hashDocument=Y;exports.hashKey=Ut;exports.isBaseAction=S;exports.loadFromFile=z;exports.loadFromInput=Z;exports.saveToFile=$;exports.saveToFileHandle=Ot;exports.zod=gt;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseAction } from '../types';
|
|
2
2
|
export declare const SET_NAME = "SET_NAME";
|
|
3
3
|
export declare const UNDO = "UNDO";
|
|
4
4
|
export declare const REDO = "REDO";
|
|
@@ -6,4 +6,3 @@ export declare const PRUNE = "PRUNE";
|
|
|
6
6
|
export declare const LOAD_STATE = "LOAD_STATE";
|
|
7
7
|
export { LoadStateAction, PruneAction, RedoAction, SetNameAction, UndoAction, } from '../types';
|
|
8
8
|
export type { BaseAction };
|
|
9
|
-
export declare function isBaseAction(action: Action): action is BaseAction;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { baseReducer } from '../reducer';
|
|
2
|
-
import { Action, Document, ExtendedState, ImmutableStateReducer, Reducer } from '../types';
|
|
2
|
+
import { Action, BaseAction, Document, ExtendedState, ImmutableStateReducer, Reducer } from '../types';
|
|
3
|
+
export declare function isBaseAction(action: Action): action is BaseAction;
|
|
3
4
|
/**
|
|
4
5
|
* Helper function to be used by action creators.
|
|
5
6
|
*
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("./object-38724dbb.js"),t=Object.freeze(Object.defineProperty({__proto__:null,createAction:e.createAction,createDocument:e.createDocument,createExtendedState:e.createExtendedState,createReducer:e.createReducer,createZip:e.createZip,getLocalFile:e.getLocalFile,getRemoteFile:e.getRemoteFile,hashDocument:e.hashDocument,hashKey:e.hashKey,loadFromFile:e.loadFromFile,loadFromInput:e.loadFromInput,saveToFile:e.saveToFile,saveToFileHandle:e.saveToFileHandle},Symbol.toStringTag,{value:"Module"})),o=Object.freeze(Object.defineProperty({__proto__:null,BaseDocument:e.BaseDocument,actions:e.BaseActions,applyMixins:e.applyMixins,baseReducer:e.baseReducer,utils:t,z:e.zod},Symbol.toStringTag,{value:"Module"}));exports.Document=o;exports.index=t;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { f as e, b as a, a as t, c as o, j as s, k as c, m as l, n as r, o as n, l as i, e as d, s as u, d as m, B as p, h as b, g as _, p as g, z as F } from "./object-916a56cd.mjs";
|
|
2
|
-
const f = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3
|
-
__proto__: null,
|
|
4
|
-
createAction: e,
|
|
5
|
-
createDocument: a,
|
|
6
|
-
createExtendedState: t,
|
|
7
|
-
createReducer: o,
|
|
8
|
-
createZip: s,
|
|
9
|
-
getLocalFile: c,
|
|
10
|
-
getRemoteFile: l,
|
|
11
|
-
hashDocument: r,
|
|
12
|
-
hashKey: n,
|
|
13
|
-
loadFromFile: i,
|
|
14
|
-
loadFromInput: d,
|
|
15
|
-
saveToFile: u,
|
|
16
|
-
saveToFileHandle: m
|
|
17
|
-
}, Symbol.toStringTag, { value: "Module" })), h = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
18
|
-
__proto__: null,
|
|
19
|
-
BaseDocument: p,
|
|
20
|
-
actions: b,
|
|
21
|
-
applyMixins: _,
|
|
22
|
-
baseReducer: g,
|
|
23
|
-
utils: f,
|
|
24
|
-
z: F
|
|
25
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
26
|
-
export {
|
|
27
|
-
h as D,
|
|
28
|
-
f as i
|
|
29
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { f as e, b as a, a as t, c as o, j as s, k as c, m as l, n as r, o as n, l as i, e as d, s as u, d as m, B as p, h as b, g as _, p as g, z as F } from "./object-bdb7f8c6.mjs";
|
|
2
|
-
const f = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3
|
-
__proto__: null,
|
|
4
|
-
createAction: e,
|
|
5
|
-
createDocument: a,
|
|
6
|
-
createExtendedState: t,
|
|
7
|
-
createReducer: o,
|
|
8
|
-
createZip: s,
|
|
9
|
-
getLocalFile: c,
|
|
10
|
-
getRemoteFile: l,
|
|
11
|
-
hashDocument: r,
|
|
12
|
-
hashKey: n,
|
|
13
|
-
loadFromFile: i,
|
|
14
|
-
loadFromInput: d,
|
|
15
|
-
saveToFile: u,
|
|
16
|
-
saveToFileHandle: m
|
|
17
|
-
}, Symbol.toStringTag, { value: "Module" })), h = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
18
|
-
__proto__: null,
|
|
19
|
-
BaseDocument: p,
|
|
20
|
-
actions: b,
|
|
21
|
-
applyMixins: _,
|
|
22
|
-
baseReducer: g,
|
|
23
|
-
utils: f,
|
|
24
|
-
z: F
|
|
25
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
26
|
-
export {
|
|
27
|
-
h as D,
|
|
28
|
-
f as i
|
|
29
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("./object-b1510be8.js"),t=Object.freeze(Object.defineProperty({__proto__:null,createAction:e.createAction,createDocument:e.createDocument,createExtendedState:e.createExtendedState,createReducer:e.createReducer,createZip:e.createZip,getLocalFile:e.getLocalFile,getRemoteFile:e.getRemoteFile,hashDocument:e.hashDocument,hashKey:e.hashKey,loadFromFile:e.loadFromFile,loadFromInput:e.loadFromInput,saveToFile:e.saveToFile,saveToFileHandle:e.saveToFileHandle},Symbol.toStringTag,{value:"Module"})),o=Object.freeze(Object.defineProperty({__proto__:null,BaseDocument:e.BaseDocument,actions:e.BaseActions,applyMixins:e.applyMixins,baseReducer:e.baseReducer,utils:t,z:e.zod},Symbol.toStringTag,{value:"Module"}));exports.Document=o;exports.index=t;
|
|
@@ -341,9 +341,6 @@ function Ot(t, i) {
|
|
|
341
341
|
};
|
|
342
342
|
}
|
|
343
343
|
const Z = "SET_NAME", h = "UNDO", v = "REDO", d = "PRUNE", K = "LOAD_STATE";
|
|
344
|
-
function A(t) {
|
|
345
|
-
return [Z, h, v, d, K].includes(t.type);
|
|
346
|
-
}
|
|
347
344
|
function Et(t, i) {
|
|
348
345
|
return [h, v, d].includes(i.type) ? t.revision : t.revision + 1;
|
|
349
346
|
}
|
|
@@ -414,6 +411,9 @@ function Tt(t, i, e) {
|
|
|
414
411
|
});
|
|
415
412
|
});
|
|
416
413
|
}
|
|
414
|
+
function A(t) {
|
|
415
|
+
return [Z, h, v, d, K].includes(t.type);
|
|
416
|
+
}
|
|
417
417
|
function u(t, i, e, a) {
|
|
418
418
|
if (!t)
|
|
419
419
|
throw new Error("Empty action type");
|
|
@@ -354,9 +354,6 @@ function kt(t, i) {
|
|
|
354
354
|
};
|
|
355
355
|
}
|
|
356
356
|
const Z = "SET_NAME", h = "UNDO", v = "REDO", d = "PRUNE", H = "LOAD_STATE";
|
|
357
|
-
function A(t) {
|
|
358
|
-
return [Z, h, v, d, H].includes(t.type);
|
|
359
|
-
}
|
|
360
357
|
function Et(t, i) {
|
|
361
358
|
return [h, v, d].includes(i.type) ? t.revision : t.revision + 1;
|
|
362
359
|
}
|
|
@@ -427,6 +424,9 @@ function zt(t, i, e) {
|
|
|
427
424
|
});
|
|
428
425
|
});
|
|
429
426
|
}
|
|
427
|
+
function A(t) {
|
|
428
|
+
return [Z, h, v, d, H].includes(t.type);
|
|
429
|
+
}
|
|
430
430
|
function u(t, i, e, a) {
|
|
431
431
|
if (!t)
|
|
432
432
|
throw new Error("Empty action type");
|