document-model 1.1.0-experimental.3 → 1.1.0-experimental.5
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/CHANGELOG.md +40 -0
- package/dist/browser/cjs/document-model.js +21 -1
- package/dist/browser/cjs/document-model.js.map +1 -0
- package/dist/browser/cjs/document.js +18 -1
- package/dist/browser/cjs/document.js.map +1 -0
- package/dist/browser/cjs/index.js +18 -1
- package/dist/browser/cjs/index.js.map +1 -0
- package/dist/browser/cjs/internal/index-1o9ymQ-0.js +2339 -0
- package/dist/browser/cjs/internal/index-1o9ymQ-0.js.map +1 -0
- package/dist/browser/cjs/internal/index-BUtd0hAV.js +49 -0
- package/dist/browser/cjs/internal/index-BUtd0hAV.js.map +1 -0
- package/dist/browser/cjs/internal/object-D19DRCyd.js +4351 -0
- package/dist/browser/cjs/internal/object-D19DRCyd.js.map +1 -0
- package/dist/browser/es/document-model.js +16 -15
- package/dist/browser/es/document-model.js.map +1 -0
- package/dist/browser/es/document.js +13 -9
- package/dist/browser/es/document.js.map +1 -0
- package/dist/browser/es/index.js +13 -11
- package/dist/browser/es/index.js.map +1 -0
- package/dist/browser/es/internal/index-Chr1cTqP.js +50 -0
- package/dist/browser/es/internal/index-Chr1cTqP.js.map +1 -0
- package/dist/browser/es/internal/index-D-FR4sw9.js +2340 -0
- package/dist/browser/es/internal/index-D-FR4sw9.js.map +1 -0
- package/dist/browser/es/internal/object-BXimXhmt.js +4352 -0
- package/dist/browser/es/internal/object-BXimXhmt.js.map +1 -0
- package/dist/browser/src/document/actions/index.d.ts +2 -2
- package/dist/browser/src/document/object.d.ts +55 -5
- package/dist/browser/src/document/reducer.d.ts +30 -0
- package/dist/browser/src/document/types.d.ts +4 -0
- package/dist/browser/src/document/utils/base.d.ts +4 -3
- package/dist/browser/src/document/utils/document-helpers.d.ts +9 -0
- package/dist/node/cjs/document-model.js +25 -1
- package/dist/node/cjs/document-model.js.map +1 -0
- package/dist/node/cjs/document.js +22 -1
- package/dist/node/cjs/document.js.map +1 -0
- package/dist/node/cjs/index.js +22 -1
- package/dist/node/cjs/index.js.map +1 -0
- package/dist/node/cjs/internal/index-CPkAfk27.js +49 -0
- package/dist/node/cjs/internal/index-CPkAfk27.js.map +1 -0
- package/dist/node/cjs/internal/index-Vr62psRC.js +2343 -0
- package/dist/node/cjs/internal/index-Vr62psRC.js.map +1 -0
- package/dist/node/cjs/internal/object-Bur9CrCb.js +2353 -0
- package/dist/node/cjs/internal/object-Bur9CrCb.js.map +1 -0
- package/dist/node/es/document-model.js +15 -14
- package/dist/node/es/document-model.js.map +1 -0
- package/dist/node/es/document.js +13 -9
- package/dist/node/es/document.js.map +1 -0
- package/dist/node/es/index.js +13 -11
- package/dist/node/es/index.js.map +1 -0
- package/dist/node/es/internal/index-C1HCcE55.js +2344 -0
- package/dist/node/es/internal/index-C1HCcE55.js.map +1 -0
- package/dist/node/es/internal/index-CWmk_0Sq.js +50 -0
- package/dist/node/es/internal/index-CWmk_0Sq.js.map +1 -0
- package/dist/node/es/internal/object-BqsV7nYl.js +2354 -0
- package/dist/node/es/internal/object-BqsV7nYl.js.map +1 -0
- package/dist/node/src/document/actions/index.d.ts +2 -2
- package/dist/node/src/document/object.d.ts +55 -5
- package/dist/node/src/document/reducer.d.ts +30 -0
- package/dist/node/src/document/types.d.ts +4 -0
- package/dist/node/src/document/utils/base.d.ts +4 -3
- package/dist/node/src/document/utils/document-helpers.d.ts +9 -0
- package/dist/src/document/actions/creators.d.ts +47 -0
- package/dist/src/document/actions/index.d.ts +14 -0
- package/dist/src/document/actions/types.d.ts +15 -0
- package/dist/src/document/index.d.ts +6 -0
- package/dist/src/document/object.d.ts +1260 -0
- package/dist/src/document/reducer.d.ts +73 -0
- package/dist/src/document/schema/index.d.ts +2 -0
- package/dist/src/document/schema/types.d.ts +176 -0
- package/dist/src/document/schema/zod.d.ts +113 -0
- package/dist/src/document/signal.d.ts +29 -0
- package/dist/src/document/types.d.ts +259 -0
- package/dist/src/document/utils/base.d.ts +87 -0
- package/dist/src/document/utils/document-helpers.d.ts +62 -0
- package/dist/src/document/utils/file.d.ts +48 -0
- package/dist/src/document/utils/index.d.ts +5 -0
- package/dist/src/document/utils/node.d.ts +9 -0
- package/dist/src/document/utils/validation.d.ts +2 -0
- package/dist/src/document-model/custom/reducers/header.d.ts +2 -0
- package/dist/src/document-model/custom/reducers/module.d.ts +2 -0
- package/dist/src/document-model/custom/reducers/operation-error.d.ts +2 -0
- package/dist/src/document-model/custom/reducers/operation-example.d.ts +2 -0
- package/dist/src/document-model/custom/reducers/operation.d.ts +2 -0
- package/dist/src/document-model/custom/reducers/state.d.ts +2 -0
- package/dist/src/document-model/custom/reducers/versioning.d.ts +7 -0
- package/dist/src/document-model/custom/utils.d.ts +7 -0
- package/dist/src/document-model/gen/actions.d.ts +15 -0
- package/dist/src/document-model/gen/creators.d.ts +7 -0
- package/dist/src/document-model/gen/document-model.d.ts +2 -0
- package/dist/src/document-model/gen/header/actions.d.ts +9 -0
- package/dist/src/document-model/gen/header/creators.d.ts +8 -0
- package/dist/src/document-model/gen/header/object.d.ts +12 -0
- package/dist/src/document-model/gen/header/operations.d.ts +10 -0
- package/dist/src/document-model/gen/index.d.ts +5 -0
- package/dist/src/document-model/gen/module/actions.d.ts +8 -0
- package/dist/src/document-model/gen/module/creators.d.ts +7 -0
- package/dist/src/document-model/gen/module/object.d.ts +11 -0
- package/dist/src/document-model/gen/module/operations.d.ts +9 -0
- package/dist/src/document-model/gen/object.d.ts +28 -0
- package/dist/src/document-model/gen/operation/actions.d.ts +13 -0
- package/dist/src/document-model/gen/operation/creators.d.ts +12 -0
- package/dist/src/document-model/gen/operation/object.d.ts +16 -0
- package/dist/src/document-model/gen/operation/operations.d.ts +14 -0
- package/dist/src/document-model/gen/operation-error/actions.d.ts +10 -0
- package/dist/src/document-model/gen/operation-error/creators.d.ts +9 -0
- package/dist/src/document-model/gen/operation-error/object.d.ts +13 -0
- package/dist/src/document-model/gen/operation-error/operations.d.ts +11 -0
- package/dist/src/document-model/gen/operation-example/actions.d.ts +7 -0
- package/dist/src/document-model/gen/operation-example/creators.d.ts +6 -0
- package/dist/src/document-model/gen/operation-example/object.d.ts +10 -0
- package/dist/src/document-model/gen/operation-example/operations.d.ts +8 -0
- package/dist/src/document-model/gen/reducer.d.ts +5 -0
- package/dist/src/document-model/gen/schema/index.d.ts +2 -0
- package/dist/src/document-model/gen/schema/types.d.ts +453 -0
- package/dist/src/document-model/gen/schema/zod.d.ts +453 -0
- package/dist/src/document-model/gen/state/actions.d.ts +9 -0
- package/dist/src/document-model/gen/state/creators.d.ts +8 -0
- package/dist/src/document-model/gen/state/object.d.ts +12 -0
- package/dist/src/document-model/gen/state/operations.d.ts +10 -0
- package/dist/src/document-model/gen/types.d.ts +8 -0
- package/dist/src/document-model/gen/utils.d.ts +6 -0
- package/dist/src/document-model/gen/versioning/actions.d.ts +8 -0
- package/dist/src/document-model/gen/versioning/creators.d.ts +7 -0
- package/dist/src/document-model/gen/versioning/object.d.ts +11 -0
- package/dist/src/document-model/gen/versioning/operations.d.ts +9 -0
- package/dist/src/document-model/index.d.ts +80 -0
- package/dist/src/index.d.ts +25 -0
- package/dist/vite.config.d.ts +2 -0
- package/dist/vitest.config.d.ts +2 -0
- package/package.json +3 -1
- package/dist/browser/cjs/internal/index-DMRH7zDy.js +0 -1
- package/dist/browser/cjs/internal/index-dwAOfmBp.js +0 -22
- package/dist/browser/cjs/internal/object-C-PazS9q.js +0 -25
- package/dist/browser/es/internal/index-BVJxzkIs.js +0 -44
- package/dist/browser/es/internal/index-DQztOVJu.js +0 -2104
- package/dist/browser/es/internal/object-iTBekDVP.js +0 -2800
- package/dist/node/cjs/internal/index-BNFVmPew.js +0 -22
- package/dist/node/cjs/internal/index-FvRO8SnG.js +0 -1
- package/dist/node/cjs/internal/object-Xvr4kDQj.js +0 -20
- package/dist/node/es/internal/index-BIrQOTP_.js +0 -44
- package/dist/node/es/internal/index-DOpbr_uw.js +0 -2108
- package/dist/node/es/internal/object-C2s2eZ08.js +0 -1698
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";var Tt=Object.defineProperty;var Rt=(t,e,r)=>e in t?Tt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var be=(t,e,r)=>(Rt(t,typeof e!="symbol"?e+"":e,r),r);const s=require("./object-Xvr4kDQj.js");require("immer");require("jszip");require("crypto");require("fs");require("https");require("path");const o=require("zod"),xt=new RegExp("([\\p{Ll}\\d])(\\p{Lu})","gu"),Mt=new RegExp("(\\p{Lu})([\\p{Lu}][\\p{Ll}])","gu"),Dt=new RegExp("(\\d)\\p{Ll}|(\\p{L})\\d","u"),Nt=/[^\p{L}\d]+/giu,_e="$1\0$2",Ae="";function ze(t){let e=t.trim();e=e.replace(xt,_e).replace(Mt,_e),e=e.replace(Nt,"\0");let r=0,n=e.length;for(;e.charAt(r)==="\0";)r++;if(r===n)return[];for(;e.charAt(n-1)==="\0";)n--;return e.slice(r,n).split(/\0/g)}function Lt(t){const e=ze(t);for(let r=0;r<e.length;r++){const n=e[r],i=Dt.exec(n);if(i){const a=i.index+(i[1]??i[2]).length;e.splice(r,1,n.slice(0,a),n.slice(a))}}return e}function Ie(t,e){const[r,n,i]=wt(t,e),a=Pt(e==null?void 0:e.locale),l=jt(e==null?void 0:e.locale),d=e!=null&&e.mergeAmbiguousCharacters?Ct(a,l):yt(a,l);return r+n.map(d).join((e==null?void 0:e.delimiter)??"")+i}function Pt(t){return t===!1?e=>e.toLowerCase():e=>e.toLocaleLowerCase(t)}function jt(t){return t===!1?e=>e.toUpperCase():e=>e.toLocaleUpperCase(t)}function Ct(t,e){return r=>`${e(r[0])}${t(r.slice(1))}`}function yt(t,e){return(r,n)=>{const i=r[0];return(n>0&&i>="0"&&i<="9"?"_"+i:e(i))+t(r.slice(1))}}function wt(t,e={}){const r=e.split??(e.separateNumbers?Lt:ze),n=e.prefixCharacters??Ae,i=e.suffixCharacters??Ae;let a=0,l=t.length;for(;a<t.length;){const d=t.charAt(a);if(!n.includes(d))break;a++}for(;l>a;){const d=l-1,zt=t.charAt(d);if(!i.includes(zt))break;l=d}return[t.slice(0,a),r(t.slice(a,l)),t.slice(l)]}function T(t,e=!1){const r=[];if(e&&t==="")return r;try{const n=JSON.parse(t);!e&&!Object.keys(n).length&&r.push({message:"Initial state cannot be empty",details:{initialState:t}})}catch{r.push({message:"Invalid initial state",details:{initialState:t}})}return r}function R(t,e,r="",n=!0){const i=[];if(!n&&!t)return i.push({message:"State schema is required",details:{schema:t}}),i;if(n&&!t)return i;const a=`type ${Ie(e)}${Ie(r)}State`;return t.includes(a)||i.push({message:`Invalid state schema name. Expected ${a}`,details:{schema:t}}),i}function x(t){const e=[];t.length||e.push({message:"Modules are required",details:{modules:t}});const r=t.reduce((n,i)=>[...n,...b(i)],[]);return[...e,...r]}function b(t){const e=[];t.name||e.push({message:"Module name is required",details:{module:t}}),t.operations.length||e.push({message:"Module operations are required",details:{module:t}});const r=t.operations.reduce((n,i)=>[...n,..._(i)],[]);return[...e,...r]}function _(t){const e=[];return t.name||e.push({message:"Operation name is required",details:{operation:t}}),t.schema||e.push({message:"Operation schema is required",details:{operation:t}}),e}const kt=Object.freeze(Object.defineProperty({__proto__:null,validateInitialState:T,validateModule:b,validateModuleOperation:_,validateModules:x,validateStateSchemaName:R},Symbol.toStringTag,{value:"Module"})),M={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:[],scope:"global"},{name:"SetModelId",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModelExtension",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModelDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetAuthorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetAuthorWebsite",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"versioning",operations:[{name:"AddChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteChangeLogItem",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderChangeLogItems",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReleaseNewVersion",schema:null,id:"",description:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"module",operations:[{name:"AddModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModuleName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetModuleDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteModule",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderModules",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation-error",operations:[{name:"AddOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorCode",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationErrorTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperationError",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderOperationErrors",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation-example",operations:[{name:"AddOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperationExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderOperationExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"operation",operations:[{name:"AddOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationName",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationDescription",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationTemplate",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetOperationReducer",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"MoveOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteOperation",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderModuleOperations",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""},{name:"state",operations:[{name:"SetStateSchema",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"SetInitialState",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"AddStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"UpdateStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"DeleteStateExample",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"},{name:"ReorderStateExamples",id:"",description:"",schema:"",template:"",reducer:"",examples:[],errors:[],scope:"global"}],id:"",description:""}],state:{global:{schema:"",initialValue:`{
|
|
2
|
-
"id": "",
|
|
3
|
-
"name": "",
|
|
4
|
-
"extension": "",
|
|
5
|
-
"description": "",
|
|
6
|
-
"author": {
|
|
7
|
-
"name": "",
|
|
8
|
-
"website": ""
|
|
9
|
-
},
|
|
10
|
-
"specifications": [
|
|
11
|
-
{
|
|
12
|
-
"version": 1,
|
|
13
|
-
"changeLog": [],
|
|
14
|
-
"state": {
|
|
15
|
-
"schema": "",
|
|
16
|
-
"initialValue": "",
|
|
17
|
-
"examples": []
|
|
18
|
-
},
|
|
19
|
-
"modules": []
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
}`,examples:[]},local:{schema:"",initialValue:"{}",examples:[]}}}]},Te=t=>t!=null,vt=o.z.any().refine(t=>Te(t));function D(){return o.z.object({__typename:o.z.literal("AddChangeLogItemInput").optional(),content:o.z.string(),id:o.z.string(),insertBefore:o.z.string().nullable()})}function N(){return o.z.object({description:o.z.string().nullish(),id:o.z.string(),name:o.z.string()})}function L(){return o.z.object({errorCode:o.z.string().nullish(),errorDescription:o.z.string().nullish(),errorName:o.z.string().nullish(),errorTemplate:o.z.string().nullish(),id:o.z.string(),operationId:o.z.string()})}function P(){return o.z.object({example:o.z.string(),id:o.z.string(),operationId:o.z.string()})}function j(){return o.z.object({description:o.z.string().nullish(),id:o.z.string(),moduleId:o.z.string(),name:o.z.string(),reducer:o.z.string().nullish(),schema:o.z.string().nullish(),template:o.z.string().nullish(),scope:A().nullish()})}function C(){return o.z.object({scope:o.z.string(),example:o.z.string(),id:o.z.string(),insertBefore:o.z.string().nullish()})}function Re(){return o.z.object({__typename:o.z.literal("Author").optional(),name:o.z.string(),website:o.z.string().nullable()})}function y(){return o.z.object({__typename:o.z.literal("CodeExample").optional(),id:o.z.string(),value:o.z.string()})}function w(){return o.z.object({__typename:o.z.literal("DeleteChangeLogItemInput").optional(),id:o.z.string()})}function k(){return o.z.object({id:o.z.string()})}function v(){return o.z.object({id:o.z.string()})}function U(){return o.z.object({id:o.z.string()})}function F(){return o.z.object({id:o.z.string()})}function $(){return o.z.object({scope:o.z.string(),id:o.z.string()})}function A(){return o.z.literal("global").or(o.z.literal("local"))}function Ut(){return o.z.union([D(),N(),L(),P(),j(),C(),w(),k(),v(),U(),F(),$(),V(),X(),H(),G(),B(),q(),W(),J(),K(),Q(),Y(),Z(),ee(),te(),re(),oe(),ne(),ie(),se(),ae(),pe(),le(),ce(),de(),ue(),me(),Ee(),he(),Oe()])}function Ft(){return o.z.object({__typename:o.z.literal("DocumentModelState").optional(),author:Re(),description:o.z.string(),extension:o.z.string(),id:o.z.string(),name:o.z.string(),specifications:o.z.array(xe())})}function xe(){return o.z.object({__typename:o.z.literal("DocumentSpecification").optional(),changeLog:o.z.array(o.z.string()),modules:o.z.array(Me()),state:Pe(),version:o.z.number()})}function Me(){return o.z.object({__typename:o.z.literal("Module").optional(),description:o.z.string().nullable(),id:o.z.string(),name:o.z.string(),operations:o.z.array(De())})}function V(){return o.z.object({newModuleId:o.z.string(),operationId:o.z.string()})}function De(){return o.z.object({__typename:o.z.literal("Operation").optional(),description:o.z.string().nullable(),errors:o.z.array(Ne()),examples:o.z.array(y()),id:o.z.string(),name:o.z.string().nullable(),reducer:o.z.string().nullable(),schema:o.z.string().nullable(),template:o.z.string().nullable(),scope:A()})}function Ne(){return o.z.object({__typename:o.z.literal("OperationError").optional(),code:o.z.string().nullable(),description:o.z.string().nullable(),id:o.z.string(),name:o.z.string().nullable(),template:o.z.string().nullable()})}function X(){return o.z.object({__typename:o.z.literal("ReorderChangeLogItemsInput").optional(),order:o.z.array(o.z.string())})}function H(){return o.z.object({moduleId:o.z.string(),order:o.z.array(o.z.string())})}function G(){return o.z.object({order:o.z.array(o.z.string())})}function B(){return o.z.object({operationId:o.z.string(),order:o.z.array(o.z.string())})}function q(){return o.z.object({operationId:o.z.string(),order:o.z.array(o.z.string())})}function W(){return o.z.object({scope:o.z.string(),order:o.z.array(o.z.string())})}function J(){return o.z.object({authorName:o.z.string()})}function K(){return o.z.object({authorWebsite:o.z.string()})}function Q(){return o.z.object({scope:o.z.string(),initialValue:o.z.string()})}function Y(){return o.z.object({description:o.z.string()})}function Z(){return o.z.object({extension:o.z.string()})}function ee(){return o.z.object({id:o.z.string()})}function te(){return o.z.object({name:o.z.string()})}function re(){return o.z.object({description:o.z.string().nullish(),id:o.z.string()})}function oe(){return o.z.object({id:o.z.string(),name:o.z.string().nullish()})}function ne(){return o.z.object({description:o.z.string().nullish(),id:o.z.string()})}function ie(){return o.z.object({errorCode:o.z.string().nullish(),id:o.z.string()})}function se(){return o.z.object({errorDescription:o.z.string().nullish(),id:o.z.string()})}function ae(){return o.z.object({errorName:o.z.string().nullish(),id:o.z.string()})}function pe(){return o.z.object({errorTemplate:o.z.string().nullish(),id:o.z.string()})}function le(){return o.z.object({id:o.z.string(),name:o.z.string().nullish()})}function Le(){return o.z.object({id:o.z.string(),scope:A()})}function ce(){return o.z.object({id:o.z.string(),reducer:o.z.string().nullish()})}function de(){return o.z.object({id:o.z.string(),schema:o.z.string().nullish()})}function ue(){return o.z.object({id:o.z.string(),template:o.z.string().nullish()})}function me(){return o.z.object({scope:o.z.string(),schema:o.z.string()})}function z(){return o.z.object({__typename:o.z.literal("State").optional(),examples:o.z.array(y()),initialValue:o.z.string(),schema:o.z.string()})}function Pe(){return o.z.object({global:z(),local:z()})}function Ee(){return o.z.object({__typename:o.z.literal("UpdateChangeLogItemInput").optional(),id:o.z.string(),newContent:o.z.string()})}function he(){return o.z.object({example:o.z.string(),id:o.z.string()})}function Oe(){return o.z.object({scope:o.z.string(),id:o.z.string(),newExample:o.z.string()})}const je=Object.freeze(Object.defineProperty({__proto__:null,AddChangeLogItemInputSchema:D,AddModuleInputSchema:N,AddOperationErrorInputSchema:L,AddOperationExampleInputSchema:P,AddOperationInputSchema:j,AddStateExampleInputSchema:C,AuthorSchema:Re,CodeExampleSchema:y,DeleteChangeLogItemInputSchema:w,DeleteModuleInputSchema:k,DeleteOperationErrorInputSchema:v,DeleteOperationExampleInputSchema:U,DeleteOperationInputSchema:F,DeleteStateExampleInputSchema:$,DocumentModelInputSchema:Ut,DocumentModelStateSchema:Ft,DocumentSpecificationSchema:xe,ModuleSchema:Me,MoveOperationInputSchema:V,OperationErrorSchema:Ne,OperationSchema:De,OperationScopeSchema:A,ReorderChangeLogItemsInputSchema:X,ReorderModuleOperationsInputSchema:H,ReorderModulesInputSchema:G,ReorderOperationErrorsInputSchema:B,ReorderOperationExamplesInputSchema:q,ReorderStateExamplesInputSchema:W,ScopeStateSchema:Pe,SetAuthorNameInputSchema:J,SetAuthorWebsiteInputSchema:K,SetInitialStateInputSchema:Q,SetModelDescriptionInputSchema:Y,SetModelExtensionInputSchema:Z,SetModelIdInputSchema:ee,SetModelNameInputSchema:te,SetModuleDescriptionInputSchema:re,SetModuleNameInputSchema:oe,SetOperationDescriptionInputSchema:ne,SetOperationErrorCodeInputSchema:ie,SetOperationErrorDescriptionInputSchema:se,SetOperationErrorNameInputSchema:ae,SetOperationErrorTemplateInputSchema:pe,SetOperationNameInputSchema:le,SetOperationReducerInputSchema:ce,SetOperationSchemaInputSchema:de,SetOperationScopeInputSchema:Le,SetOperationTemplateInputSchema:ue,SetStateSchemaInputSchema:me,StateSchema:z,UpdateChangeLogItemInputSchema:Ee,UpdateOperationExampleInputSchema:he,UpdateStateExampleInputSchema:Oe,definedNonNullAnySchema:vt,isDefinedNonNullAny:Te},Symbol.toStringTag,{value:"Module"})),u={setModelNameOperation(t,e){t.name=e.input.name},setModelIdOperation(t,e){t.id=e.input.id},setModelExtensionOperation(t,e){t.extension=e.input.extension},setModelDescriptionOperation(t,e){t.description=e.input.description},setAuthorNameOperation(t,e){t.author=t.author||{name:"",website:null},t.author.name=e.input.authorName},setAuthorWebsiteOperation(t,e){t.author=t.author||{name:"",website:null},t.author.website=e.input.authorWebsite}},O={addChangeLogItemOperation(t,e){throw new Error('Reducer "addChangeLogItemOperation" not yet implemented')},updateChangeLogItemOperation(t,e){throw new Error('Reducer "updateChangeLogItemOperation" not yet implemented')},deleteChangeLogItemOperation(t,e){throw new Error('Reducer "deleteChangeLogItemOperation" not yet implemented')},reorderChangeLogItemsOperation(t,e){throw new Error('Reducer "reorderChangeLogItemsOperation" not yet implemented')},releaseNewVersionOperation(t,e){throw new Error('Reducer "releaseNewVersionOperation" not yet implemented')}},$t=t=>{const e={};return t.forEach((r,n)=>e[r]=n),(r,n)=>(e[n.id]||999999)-(e[r.id]||999999)},g={addModuleOperation(t,e){t.specifications[t.specifications.length-1].modules.push({id:e.input.id,name:e.input.name,description:e.input.description||"",operations:[]})},setModuleNameOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)r.modules[n].id===e.input.id&&(r.modules[n].name=e.input.name||"")},setModuleDescriptionOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)r.modules[n].id===e.input.id&&(r.modules[n].description=e.input.description||"")},deleteModuleOperation(t,e){const r=t.specifications[t.specifications.length-1];r.modules=r.modules.filter(n=>n.id!=e.input.id)},reorderModulesOperation(t,e){t.specifications[t.specifications.length-1].modules.sort($t(e.input.order))}},Vt=t=>{const e={};return t.forEach((r,n)=>e[r]=n),(r,n)=>(e[n.id]||999999)-(e[r.id]||999999)},c={addOperationErrorOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.operationId&&r.modules[n].operations[i].errors.push({id:e.input.id,name:e.input.errorName||"",code:e.input.errorCode||"",description:e.input.errorDescription||"",template:e.input.errorTemplate||""})},setOperationErrorCodeOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)for(let a=0;a<r.modules[n].operations[i].errors.length;a++)r.modules[n].operations[i].errors[a].id==e.input.id&&(r.modules[n].operations[i].errors[a].code=e.input.errorCode||"")},setOperationErrorNameOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)for(let a=0;a<r.modules[n].operations[i].errors.length;a++)r.modules[n].operations[i].errors[a].id==e.input.id&&(r.modules[n].operations[i].errors[a].name=e.input.errorName||"")},setOperationErrorDescriptionOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)for(let a=0;a<r.modules[n].operations[i].errors.length;a++)r.modules[n].operations[i].errors[a].id==e.input.id&&(r.modules[n].operations[i].errors[a].description=e.input.errorDescription||"")},setOperationErrorTemplateOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)for(let a=0;a<r.modules[n].operations[i].errors.length;a++)r.modules[n].operations[i].errors[a].id==e.input.id&&(r.modules[n].operations[i].errors[a].template=e.input.errorTemplate||"")},deleteOperationErrorOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].errors=r.modules[n].operations[i].errors.filter(a=>a.id!=e.input.id)},reorderOperationErrorsOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.operationId&&r.modules[n].operations[i].errors.sort(Vt(e.input.order))}},Xt=t=>{const e={};return t.forEach((r,n)=>e[r]=n),(r,n)=>(e[n.id]||999999)-(e[r.id]||999999)},f={addOperationExampleOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.operationId&&r.modules[n].operations[i].examples.push({id:e.input.id,value:e.input.example})},updateOperationExampleOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)for(let a=0;a<r.modules[n].operations[i].examples.length;a++)r.modules[n].operations[i].examples[a].id==e.input.id&&(r.modules[n].operations[i].examples[a].value=e.input.example)},deleteOperationExampleOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].examples=r.modules[n].operations[i].examples.filter(a=>a.id!=e.input.id)},reorderOperationExamplesOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.operationId&&r.modules[n].operations[i].examples.sort(Xt(e.input.order))}},Ht=t=>{const e={};return t.forEach((r,n)=>e[r]=n),(r,n)=>(e[n.id]||999999)-(e[r.id]||999999)},p={addOperationOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)r.modules[n].id==e.input.moduleId&&r.modules[n].operations.push({id:e.input.id,name:e.input.name,description:e.input.description||"",schema:e.input.schema||"",template:e.input.template||e.input.description||"",reducer:e.input.reducer||"",errors:[],examples:[],scope:e.input.scope||"global"})},setOperationNameOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.id&&(r.modules[n].operations[i].name=e.input.name||"")},setOperationScopeOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.id&&(r.modules[n].operations[i].scope=e.input.scope||"global")},setOperationSchemaOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.id&&(r.modules[n].operations[i].schema=e.input.schema||"")},setOperationDescriptionOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.id&&(r.modules[n].operations[i].description=e.input.description||"")},setOperationTemplateOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.id&&(r.modules[n].operations[i].template=e.input.template||"")},setOperationReducerOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)for(let i=0;i<r.modules[n].operations.length;i++)r.modules[n].operations[i].id==e.input.id&&(r.modules[n].operations[i].reducer=e.input.reducer||"")},moveOperationOperation(t,e){const r=[],n=t.specifications[t.specifications.length-1];for(let i=0;i<n.modules.length;i++)n.modules[i].operations=n.modules[i].operations.filter(a=>a.id==e.input.operationId?(r.push(a),!1):!0);for(let i=0;i<n.modules.length;i++)n.modules[i].id==e.input.newModuleId&&n.modules[i].operations.push(...r)},deleteOperationOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)r.modules[n].operations=r.modules[n].operations.filter(i=>i.id!=e.input.id)},reorderModuleOperationsOperation(t,e){const r=t.specifications[t.specifications.length-1];for(let n=0;n<r.modules.length;n++)r.modules[n].id==e.input.moduleId&&r.modules[n].operations.sort(Ht(e.input.order))}},Gt=t=>{const e={};return t.forEach((r,n)=>e[r]=n),(r,n)=>(e[n.id]||999999)-(e[r.id]||999999)},m={setStateSchemaOperation(t,e){const r=t.specifications[t.specifications.length-1];if(Object.keys(r.state).includes(e.input.scope))r.state[e.input.scope].schema=e.input.schema;else throw new Error(`Invalid scope: ${e.input.scope}`)},setInitialStateOperation(t,e){const r=t.specifications[t.specifications.length-1];if(Object.keys(r.state).includes(e.input.scope))r.state[e.input.scope].initialValue=e.input.initialValue;else throw new Error(`Invalid scope: ${e.input.scope}`)},addStateExampleOperation(t,e){const r=t.specifications[t.specifications.length-1];if(Object.keys(r.state).includes(e.input.scope))r.state[e.input.scope].examples.push({id:e.input.id,value:e.input.example});else throw new Error(`Invalid scope: ${e.input.scope}`)},updateStateExampleOperation(t,e){const r=t.specifications[t.specifications.length-1];if(!Object.keys(r.state).includes(e.input.scope))throw new Error(`Invalid scope: ${e.input.scope}`);const n=r.state[e.input.scope].examples;for(let i=0;i<n.length;i++)n[i].id==e.input.id&&(n[i].value=e.input.newExample)},deleteStateExampleOperation(t,e){const r=t.specifications[t.specifications.length-1];if(Object.keys(r.state).includes(e.input.scope))r.state[e.input.scope].examples=r.state[e.input.scope].examples.filter(n=>n.id!=e.input.id);else throw new Error(`Invalid scope: ${e.input.scope}`)},reorderStateExamplesOperation(t,e){const r=t.specifications[t.specifications.length-1];if(Object.keys(r.state).includes(e.input.scope))r.state[e.input.scope].examples.sort(Gt(e.input.order));else throw new Error(`Invalid scope: ${e.input.scope}`)}},Bt=(t,e)=>{if(s.isBaseAction(e))return t;switch(e.type){case"SET_MODEL_NAME":te().parse(e.input),u.setModelNameOperation(t.global,e);break;case"SET_MODEL_ID":ee().parse(e.input),u.setModelIdOperation(t.global,e);break;case"SET_MODEL_EXTENSION":Z().parse(e.input),u.setModelExtensionOperation(t.global,e);break;case"SET_MODEL_DESCRIPTION":Y().parse(e.input),u.setModelDescriptionOperation(t.global,e);break;case"SET_AUTHOR_NAME":J().parse(e.input),u.setAuthorNameOperation(t.global,e);break;case"SET_AUTHOR_WEBSITE":K().parse(e.input),u.setAuthorWebsiteOperation(t.global,e);break;case"ADD_CHANGE_LOG_ITEM":D().parse(e.input),O.addChangeLogItemOperation(t.global,e);break;case"UPDATE_CHANGE_LOG_ITEM":Ee().parse(e.input),O.updateChangeLogItemOperation(t.global,e);break;case"DELETE_CHANGE_LOG_ITEM":w().parse(e.input),O.deleteChangeLogItemOperation(t.global,e);break;case"REORDER_CHANGE_LOG_ITEMS":X().parse(e.input),O.reorderChangeLogItemsOperation(t.global,e);break;case"RELEASE_NEW_VERSION":if(Object.keys(e.input).length>0)throw new Error("Expected empty input for action RELEASE_NEW_VERSION");O.releaseNewVersionOperation(t.global,e);break;case"ADD_MODULE":N().parse(e.input),g.addModuleOperation(t.global,e);break;case"SET_MODULE_NAME":oe().parse(e.input),g.setModuleNameOperation(t.global,e);break;case"SET_MODULE_DESCRIPTION":re().parse(e.input),g.setModuleDescriptionOperation(t.global,e);break;case"DELETE_MODULE":k().parse(e.input),g.deleteModuleOperation(t.global,e);break;case"REORDER_MODULES":G().parse(e.input),g.reorderModulesOperation(t.global,e);break;case"ADD_OPERATION_ERROR":L().parse(e.input),c.addOperationErrorOperation(t.global,e);break;case"SET_OPERATION_ERROR_CODE":ie().parse(e.input),c.setOperationErrorCodeOperation(t.global,e);break;case"SET_OPERATION_ERROR_NAME":ae().parse(e.input),c.setOperationErrorNameOperation(t.global,e);break;case"SET_OPERATION_ERROR_DESCRIPTION":se().parse(e.input),c.setOperationErrorDescriptionOperation(t.global,e);break;case"SET_OPERATION_ERROR_TEMPLATE":pe().parse(e.input),c.setOperationErrorTemplateOperation(t.global,e);break;case"DELETE_OPERATION_ERROR":v().parse(e.input),c.deleteOperationErrorOperation(t.global,e);break;case"REORDER_OPERATION_ERRORS":B().parse(e.input),c.reorderOperationErrorsOperation(t.global,e);break;case"ADD_OPERATION_EXAMPLE":P().parse(e.input),f.addOperationExampleOperation(t.global,e);break;case"UPDATE_OPERATION_EXAMPLE":he().parse(e.input),f.updateOperationExampleOperation(t.global,e);break;case"DELETE_OPERATION_EXAMPLE":U().parse(e.input),f.deleteOperationExampleOperation(t.global,e);break;case"REORDER_OPERATION_EXAMPLES":q().parse(e.input),f.reorderOperationExamplesOperation(t.global,e);break;case"ADD_OPERATION":j().parse(e.input),p.addOperationOperation(t.global,e);break;case"SET_OPERATION_NAME":le().parse(e.input),p.setOperationNameOperation(t.global,e);break;case"SET_OPERATION_SCOPE":Le().parse(e.input),p.setOperationScopeOperation(t.global,e);break;case"SET_OPERATION_SCHEMA":de().parse(e.input),p.setOperationSchemaOperation(t.global,e);break;case"SET_OPERATION_DESCRIPTION":ne().parse(e.input),p.setOperationDescriptionOperation(t.global,e);break;case"SET_OPERATION_TEMPLATE":ue().parse(e.input),p.setOperationTemplateOperation(t.global,e);break;case"SET_OPERATION_REDUCER":ce().parse(e.input),p.setOperationReducerOperation(t.global,e);break;case"MOVE_OPERATION":V().parse(e.input),p.moveOperationOperation(t.global,e);break;case"DELETE_OPERATION":F().parse(e.input),p.deleteOperationOperation(t.global,e);break;case"REORDER_MODULE_OPERATIONS":H().parse(e.input),p.reorderModuleOperationsOperation(t.global,e);break;case"SET_STATE_SCHEMA":me().parse(e.input),m.setStateSchemaOperation(t.global,e);break;case"SET_INITIAL_STATE":Q().parse(e.input),m.setInitialStateOperation(t.global,e);break;case"ADD_STATE_EXAMPLE":C().parse(e.input),m.addStateExampleOperation(t.global,e);break;case"UPDATE_STATE_EXAMPLE":Oe().parse(e.input),m.updateStateExampleOperation(t.global,e);break;case"DELETE_STATE_EXAMPLE":$().parse(e.input),m.deleteStateExampleOperation(t.global,e);break;case"REORDER_STATE_EXAMPLES":W().parse(e.input),m.reorderStateExamplesOperation(t.global,e);break;default:return t}},h=s.createReducer(Bt),qt={id:"",name:"",extension:"",description:"",author:{name:"",website:""},specifications:[{version:1,changeLog:[],state:{global:{schema:"",initialValue:"",examples:[]},local:{schema:"",initialValue:"",examples:[]}},modules:[]}]},Wt={},S={fileExtension:"phdm",createState(t){return{global:{...qt,...t==null?void 0:t.global},local:{...Wt,...t==null?void 0:t.local}}},createExtendedState(t){return s.createExtendedState({...t,documentType:"powerhouse/document-model"},S.createState)},createDocument(t){return s.createDocument(S.createExtendedState(t),S.createState)},saveToFile(t,e,r){return s.saveToFile(t,e,"phdm",r)},saveToFileHandle(t,e){return s.saveToFileHandle(t,e)},loadFromFile(t){return s.loadFromFile(t,h)},loadFromInput(t){return s.loadFromInput(t,h)}},Ce=t=>s.createAction("SET_MODEL_NAME",{...t}),ye=t=>s.createAction("SET_MODEL_ID",{...t}),we=t=>s.createAction("SET_MODEL_EXTENSION",{...t}),ke=t=>s.createAction("SET_MODEL_DESCRIPTION",{...t}),ve=t=>s.createAction("SET_AUTHOR_NAME",{...t}),Ue=t=>s.createAction("SET_AUTHOR_WEBSITE",{...t});class Jt extends s.BaseDocument{setModelName(e,r){return this.dispatch(Ce(e),r)}setModelId(e,r){return this.dispatch(ye(e),r)}setModelExtension(e,r){return this.dispatch(we(e),r)}setModelDescription(e,r){return this.dispatch(ke(e),r)}setAuthorName(e,r){return this.dispatch(ve(e),r)}setAuthorWebsite(e,r){return this.dispatch(Ue(e),r)}}const Fe=t=>s.createAction("ADD_CHANGE_LOG_ITEM",{...t}),$e=t=>s.createAction("UPDATE_CHANGE_LOG_ITEM",{...t}),Ve=t=>s.createAction("DELETE_CHANGE_LOG_ITEM",{...t}),Xe=t=>s.createAction("REORDER_CHANGE_LOG_ITEMS",{...t}),He=()=>s.createAction("RELEASE_NEW_VERSION");class Kt extends s.BaseDocument{addChangeLogItem(e,r){return this.dispatch(Fe(e),r)}updateChangeLogItem(e,r){return this.dispatch($e(e),r)}deleteChangeLogItem(e,r){return this.dispatch(Ve(e),r)}reorderChangeLogItems(e,r){return this.dispatch(Xe(e),r)}releaseNewVersion(e){return this.dispatch(He(),e)}}const Ge=t=>s.createAction("ADD_MODULE",{...t}),Be=t=>s.createAction("SET_MODULE_NAME",{...t}),qe=t=>s.createAction("SET_MODULE_DESCRIPTION",{...t}),We=t=>s.createAction("DELETE_MODULE",{...t}),Je=t=>s.createAction("REORDER_MODULES",{...t});class Qt extends s.BaseDocument{addModule(e,r){return this.dispatch(Ge(e),r)}setModuleName(e,r){return this.dispatch(Be(e),r)}setModuleDescription(e,r){return this.dispatch(qe(e),r)}deleteModule(e,r){return this.dispatch(We(e),r)}reorderModules(e,r){return this.dispatch(Je(e),r)}}const Ke=t=>s.createAction("ADD_OPERATION_ERROR",{...t}),Qe=t=>s.createAction("SET_OPERATION_ERROR_CODE",{...t}),Ye=t=>s.createAction("SET_OPERATION_ERROR_NAME",{...t}),Ze=t=>s.createAction("SET_OPERATION_ERROR_DESCRIPTION",{...t}),et=t=>s.createAction("SET_OPERATION_ERROR_TEMPLATE",{...t}),tt=t=>s.createAction("DELETE_OPERATION_ERROR",{...t}),rt=t=>s.createAction("REORDER_OPERATION_ERRORS",{...t});class Yt extends s.BaseDocument{addOperationError(e,r){return this.dispatch(Ke(e),r)}setOperationErrorCode(e,r){return this.dispatch(Qe(e),r)}setOperationErrorName(e,r){return this.dispatch(Ye(e),r)}setOperationErrorDescription(e,r){return this.dispatch(Ze(e),r)}setOperationErrorTemplate(e,r){return this.dispatch(et(e),r)}deleteOperationError(e,r){return this.dispatch(tt(e),r)}reorderOperationErrors(e,r){return this.dispatch(rt(e),r)}}const ot=t=>s.createAction("ADD_OPERATION_EXAMPLE",{...t}),nt=t=>s.createAction("UPDATE_OPERATION_EXAMPLE",{...t}),it=t=>s.createAction("DELETE_OPERATION_EXAMPLE",{...t}),st=t=>s.createAction("REORDER_OPERATION_EXAMPLES",{...t});class Zt extends s.BaseDocument{addOperationExample(e,r){return this.dispatch(ot(e),r)}updateOperationExample(e,r){return this.dispatch(nt(e),r)}deleteOperationExample(e,r){return this.dispatch(it(e),r)}reorderOperationExamples(e,r){return this.dispatch(st(e),r)}}const at=t=>s.createAction("ADD_OPERATION",{...t}),pt=t=>s.createAction("SET_OPERATION_NAME",{...t}),lt=t=>s.createAction("SET_OPERATION_SCOPE",{...t}),ct=t=>s.createAction("SET_OPERATION_SCHEMA",{...t}),dt=t=>s.createAction("SET_OPERATION_DESCRIPTION",{...t}),ut=t=>s.createAction("SET_OPERATION_TEMPLATE",{...t}),mt=t=>s.createAction("SET_OPERATION_REDUCER",{...t}),Et=t=>s.createAction("MOVE_OPERATION",{...t}),ht=t=>s.createAction("DELETE_OPERATION",{...t}),Ot=t=>s.createAction("REORDER_MODULE_OPERATIONS",{...t});class er extends s.BaseDocument{addOperation(e,r){return this.dispatch(at(e),r)}setOperationName(e,r){return this.dispatch(pt(e),r)}setOperationScope(e,r){return this.dispatch(lt(e),r)}setOperationSchema(e,r){return this.dispatch(ct(e),r)}setOperationDescription(e,r){return this.dispatch(dt(e),r)}setOperationTemplate(e,r){return this.dispatch(ut(e),r)}setOperationReducer(e,r){return this.dispatch(mt(e),r)}moveOperation(e,r){return this.dispatch(Et(e),r)}deleteOperation(e,r){return this.dispatch(ht(e),r)}reorderModuleOperations(e,r){return this.dispatch(Ot(e),r)}}const gt=t=>s.createAction("SET_STATE_SCHEMA",{...t}),St=t=>s.createAction("SET_INITIAL_STATE",{...t}),ft=t=>s.createAction("ADD_STATE_EXAMPLE",{...t}),bt=t=>s.createAction("UPDATE_STATE_EXAMPLE",{...t}),_t=t=>s.createAction("DELETE_STATE_EXAMPLE",{...t}),At=t=>s.createAction("REORDER_STATE_EXAMPLES",{...t});class tr extends s.BaseDocument{setStateSchema(e,r){return this.dispatch(gt(e),r)}setInitialState(e,r){return this.dispatch(St(e),r)}addStateExample(e,r){return this.dispatch(ft(e),r)}updateStateExample(e,r){return this.dispatch(bt(e),r)}deleteStateExample(e,r){return this.dispatch(_t(e),r)}reorderStateExamples(e,r){return this.dispatch(At(e),r)}}var E;let I=(E=class extends s.BaseDocument{constructor(e,r){super(h,S.createDocument(e),r)}saveToFile(e,r){return super.saveToFile(e,E.fileExtension,r)}loadFromFile(e){return super.loadFromFile(e)}static async fromFile(e){const r=new this;return await r.loadFromFile(e),r}},be(E,"fileExtension","phdm"),E);s.applyMixins(I,[Jt,Kt,Qt,Yt,Zt,er,tr]);const rr=Object.freeze(Object.defineProperty({__proto__:null,addChangeLogItem:Fe,addModule:Ge,addOperation:at,addOperationError:Ke,addOperationExample:ot,addStateExample:ft,deleteChangeLogItem:Ve,deleteModule:We,deleteOperation:ht,deleteOperationError:tt,deleteOperationExample:it,deleteStateExample:_t,moveOperation:Et,releaseNewVersion:He,reorderChangeLogItems:Xe,reorderModuleOperations:Ot,reorderModules:Je,reorderOperationErrors:rt,reorderOperationExamples:st,reorderStateExamples:At,setAuthorName:ve,setAuthorWebsite:Ue,setInitialState:St,setModelDescription:ke,setModelExtension:we,setModelId:ye,setModelName:Ce,setModuleDescription:qe,setModuleName:Be,setOperationDescription:dt,setOperationErrorCode:Qe,setOperationErrorDescription:Ze,setOperationErrorName:Ye,setOperationErrorTemplate:et,setOperationName:pt,setOperationReducer:mt,setOperationSchema:ct,setOperationScope:lt,setOperationTemplate:ut,setStateSchema:gt,updateChangeLogItem:$e,updateOperationExample:nt,updateStateExample:bt},Symbol.toStringTag,{value:"Module"})),ge=I,Se={...S,...kt},fe={...s.BaseActions,...rr},It={Document:ge,reducer:h,actions:fe,utils:Se,documentModel:M},or=Object.freeze(Object.defineProperty({__proto__:null,Document:ge,DocumentModel:I,actions:fe,documentModel:M,module:It,reducer:h,utils:Se,validateInitialState:T,validateModule:b,validateModuleOperation:_,validateModules:x,validateStateSchemaName:R,z:je},Symbol.toStringTag,{value:"Module"}));exports.Document=ge;exports.DocumentModel=or;exports.DocumentModel$1=I;exports.actions=fe;exports.documentModel=M;exports.module=It;exports.reducer=h;exports.utils=Se;exports.validateInitialState=T;exports.validateModule=b;exports.validateModuleOperation=_;exports.validateModules=x;exports.validateStateSchemaName=R;exports.zod=je;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("./object-Xvr4kDQj.js"),t=Object.freeze(Object.defineProperty({__proto__:null,calculateSkipsLeft:e.calculateSkipsLeft,createAction:e.createAction,createDocument:e.createDocument,createExtendedState:e.createExtendedState,createReducer:e.createReducer,createZip:e.createZip,documentHelpers:e.documentHelpers,getLocalFile:e.getLocalFile,getRemoteFile:e.getRemoteFile,hashDocument:e.hashDocument,hashKey:e.hashKey,isBaseAction:e.isBaseAction,isNoopOperation:e.isNoopOperation,isSameDocument:e.isSameDocument,isUndoRedo:e.isUndoRedo,loadFromFile:e.loadFromFile,loadFromInput:e.loadFromInput,mapSkippedOperations:e.mapSkippedOperations,parseResultingState:e.parseResultingState,readOnly:e.readOnly,replayDocument:e.replayDocument,replayOperations:e.replayOperations,saveToFile:e.saveToFile,saveToFileHandle:e.saveToFileHandle,sortMappedOperations:e.sortMappedOperations,sortOperations:e.sortOperations,validateOperations:e.validateOperations},Symbol.toStringTag,{value:"Module"})),o=Object.freeze(Object.defineProperty({__proto__:null,BaseDocument:e.BaseDocument,actions:e.BaseActions,applyMixins:e.applyMixins,baseReducer:e.baseReducer,processUndoRedo:e.processUndoRedo,utils:t,z:e.zod},Symbol.toStringTag,{value:"Module"}));exports.Document=o;exports.index=t;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";var fe=Object.defineProperty;var de=(t,e,n)=>e in t?fe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var at=(t,e,n)=>(de(t,typeof e!="symbol"?e+"":e,n),n);const H=require("immer"),f=require("zod"),_t=require("jszip"),ge=require("crypto"),ft=require("fs"),he=require("https"),xe=require("path"),vt=t=>t!=null,ye=f.z.any().refine(t=>vt(t)),Nt=f.z.enum(["LOAD_STATE"]),It=f.z.enum(["PRUNE"]),At=f.z.enum(["REDO"]),Pt=f.z.enum(["SET_NAME"]),Mt=f.z.enum(["UNDO"]);function be(){return f.z.object({__typename:f.z.literal("Action").optional(),type:f.z.string()})}function et(){return f.z.literal("global").or(f.z.literal("local"))}function Ft(){return f.z.union([Rt(),qt(),Ct(),Ut(),Jt()])}function we(){return f.z.object({__typename:f.z.literal("DocumentFile").optional(),data:f.z.string(),extension:f.z.string().nullable(),fileName:f.z.string().nullable(),mimeType:f.z.string()})}function Rt(){return f.z.object({input:f.z.lazy(()=>yt()),type:Nt,scope:et()})}function yt(){return f.z.object({operations:f.z.number(),state:f.z.lazy(()=>Lt())})}function Lt(){return f.z.object({data:f.z.unknown().nullish(),name:f.z.string()})}function Oe(){return f.z.object({__typename:f.z.literal("Operation").optional(),hash:f.z.string(),index:f.z.number(),timestamp:f.z.string().datetime(),type:f.z.string()})}function qt(){return f.z.object({input:f.z.lazy(()=>bt()),type:It,scope:et()})}function bt(){return f.z.object({end:f.z.number().nullish(),start:f.z.number().nullish()})}const wt=f.z.number;function Ct(){return f.z.object({input:wt(),type:At,scope:et()})}const Ot=f.z.string;function Ut(){return f.z.object({input:Ot(),type:Pt,scope:f.z.literal("global")})}function Se(){return f.z.object({__typename:f.z.literal("SetNameOperation").optional(),hash:f.z.string(),index:f.z.number(),input:f.z.string(),timestamp:f.z.string().datetime(),type:f.z.string()})}const St=f.z.number;function Jt(){return f.z.object({input:St(),type:Mt,scope:et()})}const je=Object.freeze(Object.defineProperty({__proto__:null,ActionSchema:be,BaseActionSchema:Ft,DocumentFileSchema:we,LoadStateActionInputSchema:yt,LoadStateActionSchema:Rt,LoadStateActionStateInputSchema:Lt,Load_StateSchema:Nt,OperationSchema:Oe,OperationScopeSchema:et,PruneActionInputSchema:bt,PruneActionSchema:qt,PruneSchema:It,RedoActionInputSchema:wt,RedoActionSchema:Ct,RedoSchema:At,SetNameActionInputSchema:Ot,SetNameActionSchema:Ut,SetNameOperationSchema:Se,Set_NameSchema:Pt,UndoActionInputSchema:St,UndoActionSchema:Jt,UndoSchema:Mt,definedNonNullAnySchema:ye,isDefinedNonNullAny:vt},Symbol.toStringTag,{value:"Module"}));function Ee(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var dt={exports:{}};(function(t,e){const{hasOwnProperty:n}=Object.prototype,i=R();i.configure=R,i.stringify=i,i.default=i,e.stringify=i,e.configure=R,t.exports=i;const o=/[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/;function a(c){return c.length<5e3&&!o.test(c)?`"${c}"`:JSON.stringify(c)}function r(c){if(c.length>200)return c.sort();for(let l=1;l<c.length;l++){const u=c[l];let T=l;for(;T!==0&&c[T-1]>u;)c[T]=c[T-1],T--;c[T]=u}return c}const p=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Object.getPrototypeOf(new Int8Array)),Symbol.toStringTag).get;function m(c){return p.call(c)!==void 0&&c.length!==0}function d(c,l,u){c.length<u&&(u=c.length);const T=l===","?"":" ";let L=`"0":${T}${c[0]}`;for(let P=1;P<u;P++)L+=`${l}"${P}":${T}${c[P]}`;return L}function h(c){if(n.call(c,"circularValue")){const l=c.circularValue;if(typeof l=="string")return`"${l}"`;if(l==null)return l;if(l===Error||l===TypeError)return{toString(){throw new TypeError("Converting circular structure to JSON")}};throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined')}return'"[Circular]"'}function b(c,l){let u;if(n.call(c,l)&&(u=c[l],typeof u!="boolean"))throw new TypeError(`The "${l}" argument must be of type boolean`);return u===void 0?!0:u}function O(c,l){let u;if(n.call(c,l)){if(u=c[l],typeof u!="number")throw new TypeError(`The "${l}" argument must be of type number`);if(!Number.isInteger(u))throw new TypeError(`The "${l}" argument must be an integer`);if(u<1)throw new RangeError(`The "${l}" argument must be >= 1`)}return u===void 0?1/0:u}function v(c){return c===1?"1 item":`${c} items`}function z(c){const l=new Set;for(const u of c)(typeof u=="string"||typeof u=="number")&&l.add(String(u));return l}function A(c){if(n.call(c,"strict")){const l=c.strict;if(typeof l!="boolean")throw new TypeError('The "strict" argument must be of type boolean');if(l)return u=>{let T=`Object can not safely be stringified. Received type ${typeof u}`;throw typeof u!="function"&&(T+=` (${u.toString()})`),new Error(T)}}}function R(c){c={...c};const l=A(c);l&&(c.bigint===void 0&&(c.bigint=!1),"circularValue"in c||(c.circularValue=Error));const u=h(c),T=b(c,"bigint"),L=b(c,"deterministic"),P=O(c,"maximumDepth"),D=O(c,"maximumBreadth");function ot(I,s,g,w,y,j){let x=s[I];switch(typeof x=="object"&&x!==null&&typeof x.toJSON=="function"&&(x=x.toJSON(I)),x=w.call(s,I,x),typeof x){case"string":return a(x);case"object":{if(x===null)return"null";if(g.indexOf(x)!==-1)return u;let S="",$=",";const k=j;if(Array.isArray(x)){if(x.length===0)return"[]";if(P<g.length+1)return'"[Array]"';g.push(x),y!==""&&(j+=y,S+=`
|
|
2
|
-
${j}`,$=`,
|
|
3
|
-
${j}`);const F=Math.min(x.length,D);let U=0;for(;U<F-1;U++){const rt=ot(String(U),x,g,w,y,j);S+=rt!==void 0?rt:"null",S+=$}const J=ot(String(U),x,g,w,y,j);if(S+=J!==void 0?J:"null",x.length-1>D){const rt=x.length-D-1;S+=`${$}"... ${v(rt)} not stringified"`}return y!==""&&(S+=`
|
|
4
|
-
${k}`),g.pop(),`[${S}]`}let _=Object.keys(x);const N=_.length;if(N===0)return"{}";if(P<g.length+1)return'"[Object]"';let E="",M="";y!==""&&(j+=y,$=`,
|
|
5
|
-
${j}`,E=" ");const C=Math.min(N,D);L&&!m(x)&&(_=r(_)),g.push(x);for(let F=0;F<C;F++){const U=_[F],J=ot(U,x,g,w,y,j);J!==void 0&&(S+=`${M}${a(U)}:${E}${J}`,M=$)}if(N>D){const F=N-D;S+=`${M}"...":${E}"${v(F)} not stringified"`,M=$}return y!==""&&M.length>1&&(S=`
|
|
6
|
-
${j}${S}
|
|
7
|
-
${k}`),g.pop(),`{${S}}`}case"number":return isFinite(x)?String(x):l?l(x):"null";case"boolean":return x===!0?"true":"false";case"undefined":return;case"bigint":if(T)return String(x);default:return l?l(x):void 0}}function st(I,s,g,w,y,j){switch(typeof s=="object"&&s!==null&&typeof s.toJSON=="function"&&(s=s.toJSON(I)),typeof s){case"string":return a(s);case"object":{if(s===null)return"null";if(g.indexOf(s)!==-1)return u;const x=j;let S="",$=",";if(Array.isArray(s)){if(s.length===0)return"[]";if(P<g.length+1)return'"[Array]"';g.push(s),y!==""&&(j+=y,S+=`
|
|
8
|
-
${j}`,$=`,
|
|
9
|
-
${j}`);const N=Math.min(s.length,D);let E=0;for(;E<N-1;E++){const C=st(String(E),s[E],g,w,y,j);S+=C!==void 0?C:"null",S+=$}const M=st(String(E),s[E],g,w,y,j);if(S+=M!==void 0?M:"null",s.length-1>D){const C=s.length-D-1;S+=`${$}"... ${v(C)} not stringified"`}return y!==""&&(S+=`
|
|
10
|
-
${x}`),g.pop(),`[${S}]`}g.push(s);let k="";y!==""&&(j+=y,$=`,
|
|
11
|
-
${j}`,k=" ");let _="";for(const N of w){const E=st(N,s[N],g,w,y,j);E!==void 0&&(S+=`${_}${a(N)}:${k}${E}`,_=$)}return y!==""&&_.length>1&&(S=`
|
|
12
|
-
${j}${S}
|
|
13
|
-
${x}`),g.pop(),`{${S}}`}case"number":return isFinite(s)?String(s):l?l(s):"null";case"boolean":return s===!0?"true":"false";case"undefined":return;case"bigint":if(T)return String(s);default:return l?l(s):void 0}}function Z(I,s,g,w,y){switch(typeof s){case"string":return a(s);case"object":{if(s===null)return"null";if(typeof s.toJSON=="function"){if(s=s.toJSON(I),typeof s!="object")return Z(I,s,g,w,y);if(s===null)return"null"}if(g.indexOf(s)!==-1)return u;const j=y;if(Array.isArray(s)){if(s.length===0)return"[]";if(P<g.length+1)return'"[Array]"';g.push(s),y+=w;let E=`
|
|
14
|
-
${y}`;const M=`,
|
|
15
|
-
${y}`,C=Math.min(s.length,D);let F=0;for(;F<C-1;F++){const J=Z(String(F),s[F],g,w,y);E+=J!==void 0?J:"null",E+=M}const U=Z(String(F),s[F],g,w,y);if(E+=U!==void 0?U:"null",s.length-1>D){const J=s.length-D-1;E+=`${M}"... ${v(J)} not stringified"`}return E+=`
|
|
16
|
-
${j}`,g.pop(),`[${E}]`}let x=Object.keys(s);const S=x.length;if(S===0)return"{}";if(P<g.length+1)return'"[Object]"';y+=w;const $=`,
|
|
17
|
-
${y}`;let k="",_="",N=Math.min(S,D);m(s)&&(k+=d(s,$,D),x=x.slice(s.length),N-=s.length,_=$),L&&(x=r(x)),g.push(s);for(let E=0;E<N;E++){const M=x[E],C=Z(M,s[M],g,w,y);C!==void 0&&(k+=`${_}${a(M)}: ${C}`,_=$)}if(S>D){const E=S-D;k+=`${_}"...": "${v(E)} not stringified"`,_=$}return _!==""&&(k=`
|
|
18
|
-
${y}${k}
|
|
19
|
-
${j}`),g.pop(),`{${k}}`}case"number":return isFinite(s)?String(s):l?l(s):"null";case"boolean":return s===!0?"true":"false";case"undefined":return;case"bigint":if(T)return String(s);default:return l?l(s):void 0}}function Q(I,s,g){switch(typeof s){case"string":return a(s);case"object":{if(s===null)return"null";if(typeof s.toJSON=="function"){if(s=s.toJSON(I),typeof s!="object")return Q(I,s,g);if(s===null)return"null"}if(g.indexOf(s)!==-1)return u;let w="";if(Array.isArray(s)){if(s.length===0)return"[]";if(P<g.length+1)return'"[Array]"';g.push(s);const $=Math.min(s.length,D);let k=0;for(;k<$-1;k++){const N=Q(String(k),s[k],g);w+=N!==void 0?N:"null",w+=","}const _=Q(String(k),s[k],g);if(w+=_!==void 0?_:"null",s.length-1>D){const N=s.length-D-1;w+=`,"... ${v(N)} not stringified"`}return g.pop(),`[${w}]`}let y=Object.keys(s);const j=y.length;if(j===0)return"{}";if(P<g.length+1)return'"[Object]"';let x="",S=Math.min(j,D);m(s)&&(w+=d(s,",",D),y=y.slice(s.length),S-=s.length,x=","),L&&(y=r(y)),g.push(s);for(let $=0;$<S;$++){const k=y[$],_=Q(k,s[k],g);_!==void 0&&(w+=`${x}${a(k)}:${_}`,x=",")}if(j>D){const $=j-D;w+=`${x}"...":"${v($)} not stringified"`}return g.pop(),`{${w}}`}case"number":return isFinite(s)?String(s):l?l(s):"null";case"boolean":return s===!0?"true":"false";case"undefined":return;case"bigint":if(T)return String(s);default:return l?l(s):void 0}}function ue(I,s,g){if(arguments.length>1){let w="";if(typeof g=="number"?w=" ".repeat(Math.min(g,10)):typeof g=="string"&&(w=g.slice(0,10)),s!=null){if(typeof s=="function")return ot("",{"":I},[],s,w,"");if(Array.isArray(s))return st("",I,[],z(s),w,"")}if(w.length!==0)return Z("",I,[],w,"")}return Q("",I,[])}return ue}})(dt,dt.exports);var $e=dt.exports;const G=Ee($e);G.configure;function De(t,e){return{...t,name:e}}function ke(t,e,n){const{scope:i,input:o}=e,a={document:t,action:e,skip:n};return H.produce(a,r=>{if(r.document.operations[i].length<1)throw new Error(`Cannot undo: no operations in history for scope "${i}"`);if(o<1)throw new Error("Invalid UNDO action: input value must be greater than 0");if(r.skip>0)throw new Error("Cannot undo: skip value from reducer cannot be used with UNDO action");const p=r.document.operations[i].at(-1),m=p&&p.type==="NOOP"&&p.skip>0;if(r.skip+=o,m){r.skip+=p.skip;const O=r.document.operations[i][r.document.operations[i].length-2];O&&p.index-O.index===1&&r.document.operations[i].pop()}if(r.document.operations[i].length<r.skip)throw new Error("Cannot undo: you can't undo more operations than the ones in the scope history");const d=r.document.operations[i].length-1;let h=o,b=m?d-p.skip:d;for(;h>0&&b>=0;){const O=r.document.operations[i][b];if(!O){h--,b--;continue}O.type==="NOOP"&&O.skip>0?(b=b-(O.skip+1),r.skip+=O.skip+1):(r.document.clipboard.push({...O}),h--,b--)}r.action=me(i)})}function ze(t,e,n){const{scope:i,input:o}=e,a={document:t,action:e,skip:n};return H.produce(a,r=>{if(r.skip>0)throw new Error("Cannot redo: skip value from reducer cannot be used with REDO action");if(o>1)throw new Error("Cannot redo: you can only redo one operation at a time");if(o<1)throw new Error("Invalid REDO action: invalid redo input value");if(r.document.clipboard.length<1)throw new Error("Cannot redo: no operations in the clipboard");const p=r.document.clipboard.findLastIndex(d=>d.scope===i);if(p<0)throw new Error(`Cannot redo: no operations in clipboard for scope "${i}"`);const m=r.document.clipboard.splice(p,1)[0];r.action=H.castDraft({type:m.type,scope:m.scope,input:m.input})})}function Te(t,e,n){const{scope:i}=e,o=t.operations[i];let{input:{start:a,end:r}}=e;a=a||0,r=r||o.length;const p=o.slice(a,r),m=o.slice(0,a),d=o.slice(r),h=pt(t.initialState,{...t.operations,[i]:m.concat(p)},n),{name:b,state:O}=h,v=m.length,z=m.length?m[m.length-1].timestamp:d.length?d[0].timestamp:new Date().toISOString();return pt(t.initialState,{...t.operations,[i]:[...m,{...Tt({name:b,state:O},p.length),timestamp:z,index:v,hash:mt({state:O},"global")},...d.map((A,R)=>({...A,index:v+R+1}))]},n)}function _e(t,e){return{...t,name:e.name,state:e.state??{global:{},local:{}}}}const Ht="SET_NAME",nt="UNDO",it="REDO",ct="PRUNE",Vt="LOAD_STATE",ve="NOOP",Bt={"application/andrew-inset":["ez"],"application/appinstaller":["appinstaller"],"application/applixware":["aw"],"application/appx":["appx"],"application/appxbundle":["appxbundle"],"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/automationml-aml+xml":["aml"],"application/automationml-amlx+zip":["amlx"],"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/cpl+xml":["cpl"],"application/cu-seeme":["cu"],"application/cwl":["cwl"],"application/dash+xml":["mpd"],"application/dash-patch+xml":["mpp"],"application/davmount+xml":["davmount"],"application/docbook+xml":["dbk"],"application/dssc+der":["dssc"],"application/dssc+xml":["xdssc"],"application/ecmascript":["ecma"],"application/emma+xml":["emma"],"application/emotionml+xml":["emotionml"],"application/epub+zip":["epub"],"application/exi":["exi"],"application/express":["exp"],"application/fdf":["fdf"],"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"],"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/media-policy-dataset+xml":["mpf"],"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":["*mp4","*mpg4","mp4s","m4p"],"application/msix":["msix"],"application/msixbundle":["msixbundle"],"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-keys":["asc"],"application/pgp-signature":["sig","*asc"],"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/sql":["sql"],"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/watcherinfo+xml":["wif"],"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/xfdf":["xfdf"],"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/aac":["adts","aac"],"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/avci":["avci"],"image/avcs":["avcs"],"image/avif":["avif"],"image/bmp":["bmp","dib"],"image/cgm":["cgm"],"image/dicom-rle":["drle"],"image/dpx":["dpx"],"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","jpgm"],"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/jt":["jt"],"model/mesh":["msh","mesh","silo"],"model/mtl":["mtl"],"model/obj":["obj"],"model/prc":["prc"],"model/step+xml":["stpx"],"model/step+zip":["stpz"],"model/step-xml+zip":["stpxz"],"model/stl":["stl"],"model/u3d":["u3d"],"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/javascript":["js","mjs"],"text/jsx":["jsx"],"text/less":["less"],"text/markdown":["md","markdown"],"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/wgsl":["wgsl"],"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"]};Object.freeze(Bt);var q=function(t,e,n,i){if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return n==="m"?i:n==="a"?i.call(t):i?i.value:e.get(t)},W,Y,X;class Ne{constructor(...e){W.set(this,new Map),Y.set(this,new Map),X.set(this,new Map);for(const n of e)this.define(n)}define(e,n=!1){for(let[i,o]of Object.entries(e)){i=i.toLowerCase(),o=o.map(p=>p.toLowerCase()),q(this,X,"f").has(i)||q(this,X,"f").set(i,new Set);const a=q(this,X,"f").get(i);let r=!0;for(let p of o){const m=p.startsWith("*");if(p=m?p.slice(1):p,a==null||a.add(p),r&&q(this,Y,"f").set(i,p),r=!1,m)continue;const d=q(this,W,"f").get(p);if(d&&d!=i&&!n)throw new Error(`"${i} -> ${p}" conflicts with "${d} -> ${p}". Pass \`force=true\` to override this definition.`);q(this,W,"f").set(p,i)}}return this}getType(e){if(typeof e!="string")return null;const n=e.replace(/^.*[/\\]/,"").toLowerCase(),i=n.replace(/^.*\./,"").toLowerCase(),o=n.length<e.length;return!(i.length<n.length-1)&&o?null:q(this,W,"f").get(i)??null}getExtension(e){var n;return typeof e!="string"?null:(e=(n=e==null?void 0:e.split)==null?void 0:n.call(e,";")[0],(e&&q(this,Y,"f").get(e.trim().toLowerCase()))??null)}getAllExtensions(e){return typeof e!="string"?null:q(this,X,"f").get(e.toLowerCase())??null}_freeze(){this.define=()=>{throw new Error("define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances")},Object.freeze(this);for(const e of q(this,X,"f").values())Object.freeze(e);return this}_getTestState(){return{types:q(this,W,"f"),extensions:q(this,Y,"f")}}}W=new WeakMap,Y=new WeakMap,X=new WeakMap;const Ie=new Ne(Bt)._freeze();function Ae(t,e,n){const i=xe.join(t,e);return ft.mkdirSync(t,{recursive:!0}),new Promise((o,a)=>{try{ft.writeFile(i,n,{},r=>{r?a(r):o(i)})}catch(r){a(r)}})}function Xt(t){return ft.readFileSync(t)}function Pe(t){return new Promise((e,n)=>{he.get(t,i=>{const o=[],a=i.headers["content-type"];i.on("data",r=>{o.push(r)}),i.on("end",()=>{e({buffer:Buffer.concat(o),mimeType:a})})}).on("error",i=>{n(i)})})}const Me=async t=>Xt(t),lt=(t,e="sha1")=>ge.createHash(e).update(t).digest("base64");function Kt(t){const e=[],n=Object.keys(t);for(const i of n){const o=t[i].sort((a,r)=>a.index-r.index);for(let a=0;a<o.length;a++)o[a].index!==a&&e.push({message:`Invalid operation index ${o[a].index} at position ${a}`,details:{position:a,operation:o[a],scope:o[a].scope}})}return e}const jt=async t=>{const e=new _t,{name:n,revision:i,documentType:o,created:a,lastModified:r}=t,p={name:n,revision:i,documentType:o,created:a,lastModified:r};return e.file("header.json",JSON.stringify(p,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(d=>{const{data:h,...b}=t.attachments[d];e.file(d,h,{base64:!0,createFolders:!0,comment:JSON.stringify(b)})}),e},Wt=async(t,e,n,i)=>{const a=await(await jt(t)).generateAsync({type:"uint8array",streamFiles:!0}),r=i??t.name,p=`.${n}.zip`;return Ae(e,r.endsWith(p)?r:`${r}${p}`,a)},Fe=async(t,e)=>{const i=await(await jt(t)).generateAsync({type:"blob"}),o=await e.createWritable();await o.write(i),await o.close()},gt=async(t,e,n)=>{const i=Xt(t);return Gt(i,e,n)},Gt=async(t,e,n)=>{const i=new _t;return await i.loadAsync(t),Re(i,e,n)};async function Re(t,e,n){const i=t.file("state.json");if(!i)throw new Error("Initial state not found");const o=await i.async("string"),a=JSON.parse(o),r=t.file("header.json");let p;r&&(p=JSON.parse(await r.async("string")));const m=t.file("operations.json");if(!m)throw new Error("Operations history not found");const d=JSON.parse(await m.async("string")),h=Kt(d);if(h.length){const O=h.map(v=>v.message);throw new Error(O.join(`
|
|
20
|
-
`))}let b=kt(a,d,e,void 0,p,{},n);return p&&(b={...b,...p}),b}function Zt(t){const e=t.replace(/^.*\./,"")||void 0,n=t.replace(/^.*[/\\]/,"")||void 0;return{extension:e,fileName:n}}async function Le(t){const{buffer:e,mimeType:n="application/octet-stream"}=await Pe(t),i=Zt(t),o=e.toString("base64");return{data:o,hash:lt(o),mimeType:n,...i}}async function qe(t){const e=await Me(t),n=Ie.getType(t)||"application/octet-stream",i=Zt(t),o=e.toString("base64");return{data:o,hash:lt(o),mimeType:n,...i}}var Qt=(t=>(t.UNEXPECTED_INDEX="UNEXPECTED_INDEX",t))(Qt||{}),Yt=(t=>(t.DUPLICATED_INDEX="DUPLICATED_INDEX",t.MISSING_INDEX="MISSING_INDEX",t))(Yt||{});function Et(t){const e=[];let n=-1;for(const i of t){const o=i.index-i.skip;o!==n+1&&e.push({operation:{index:i.index,skip:i.skip},issue:"UNEXPECTED_INDEX",category:o>n+1?"MISSING_INDEX":"DUPLICATED_INDEX",message:`Expected index ${n+1} with skip 0 or equivalent, got index ${i.index} with skip ${i.skip}`}),n=i.index}return e}function V(t){var i,o,a;const e=[];let n=t.length-1;for(;n>-1;){e.unshift(t[n]);const r=(((i=t[n])==null?void 0:i.index)||0)-(((o=t[n])==null?void 0:o.skip)||0)-1;let p=n-1;for(;p>-1&&(((a=t[p])==null?void 0:a.index)||0)>r;)p--;n=p}return e}function Ce(t){const e=[...t],n=e[e.length-1];return n&&(n.type==="NOOP"?e.push({...n,index:n.index,type:"NOOP",skip:ne(t)}):e.push({type:"NOOP",index:n.index+1,timestamp:new Date().toISOString(),input:{},skip:1,scope:n.scope,hash:n.hash})),e}function B(t){return t.slice().sort((e,n)=>e.skip-n.skip).sort((e,n)=>e.index-n.index)}const Ue=(t,e,n)=>[...e,...n].sort((i,o)=>new Date(i.timestamp).getTime()-new Date(o.timestamp).getTime()).map((i,o)=>({...i,index:t.index+o,skip:o===0?t.skip:0})),Je=(t,e,n)=>[...e,...n].sort((i,o)=>new Date(i.timestamp).getTime()-new Date(o.timestamp).getTime()).sort((i,o)=>i.index-o.index).map((i,o)=>({...i,index:t.index+o,skip:o===0?t.skip:0}));function $t(t,e){return G(t)===G(e)}function He(t,e){const n=V(B(t.slice())),i=V(B(e.slice()));if(n.length<1)return[i,[]];const o=[];let a=!1;for(;i.length>0;){const r=i[0];let p=n.shift();for(;p&&te(p,r);)o.push(p),p=n.shift();if(p?a||($t(p,r)?(i.shift(),o.push(p)):(n.unshift(p),a=!0)):a=!0,a){let m=i.shift();for(;m;)o.push(m),m=i.shift()}}if(!a){let r=n.shift();for(;r;)o.push(r),r=n.shift()}return[V(o),n]}function te(t,e){return t.index<e.index||t.index===e.index&&t.skip<e.skip}function ee(t,e){const n=[],i=[],o=[],a=Math.max(t.length,e.length);let r=!1;for(let p=0;p<a;p++){const m=t[p],d=e[p];m&&d?!r&&$t(m,d)?n.push(m):(r=!0,i.push(m),o.push(d)):m?i.push(m):d&&o.push(d)}return[n,i,o]}function Ve(t,e,n){const[i,o,a]=ee(V(t),V(e)),r=ut(i),p=1+Math.max(r,ut(o),ut(a)),m=n({index:p,skip:p-(r+1)},o,a);return i.concat(m)}function ut(t){const e=t[t.length-1];return e?e.index:-1}function ne(t){var i,o,a;if(t.length<1)return-1;const e=V(t);let n=(((i=e[e.length-1])==null?void 0:i.skip)||0)+1;return e.length>1&&(n+=((o=e[e.length-2])==null?void 0:o.skip)||0),(((a=e[e.length-1])==null?void 0:a.index)||-1)<n?-1:n}const Be=t=>Et(V(B(t))),Xe=t=>t.reduce((n,i)=>{var o;return n[i.scope]||(n[i.scope]=[]),(o=n[i.scope])==null||o.push(i),n},{}),Ke=(t,e)=>{var m;const n={integrityIssues:[],validOperations:[],invalidOperations:[],duplicatedOperations:[]},i=B(t),o=B(e),a=Et([...i,...o]),p=(m=[...a.filter(d=>d.category==="MISSING_INDEX")].sort((d,h)=>h.operation.index-d.operation.index).pop())==null?void 0:m.operation;for(const d of o){if(p&&d.index>=p.index){n.invalidOperations.push(d);continue}if(a.some(b=>b.operation.index===d.index&&b.operation.skip===d.skip&&b.category==="DUPLICATED_INDEX")){n.duplicatedOperations.push(d);continue}n.validOperations.push(d)}return n.integrityIssues.push(...a),n};function We(t,e){return t.filter(n=>!e.some(i=>n.type==="NOOP"&&n.skip===0&&n.index===i.index||n.index===i.index&&n.skip===i.skip&&n.scope===i.scope&&n.hash===i.hash&&n.type===i.type))}function ie(t,e){const[n]=B(t).slice(-1),i=(n==null?void 0:n.index)??-1,o=i+1,a={...e,index:e.index??o};if(a.index<i)throw new Error(`The skip header operation index must be greater than or equal to ${i}`);return(V(B([...t,a]))||[]).slice(0,-1)}function ht(t){return{...Object.entries(t).reduce((n,i)=>{const[o,a]=i;return{...n,[o]:V(B(a))}},{})}}const Ge=Object.freeze(Object.defineProperty({__proto__:null,IntegrityIssueSubType:Yt,IntegrityIssueType:Qt,addUndo:Ce,attachBranch:He,checkCleanedOperationsIntegrity:Et,checkOperationsIntegrity:Be,garbageCollect:V,garbageCollectDocumentOperations:ht,groupOperationsByScope:Xe,merge:Ve,nextSkipNumber:ne,operationsAreEqual:$t,precedes:te,prepareOperations:Ke,removeExistingOperations:We,reshuffleByTimestamp:Ue,reshuffleByTimestampAndIndex:Je,skipHeaderOperations:ie,sortOperations:B,split:ee},Symbol.toStringTag,{value:"Module"}));function Ze(t,e){let n;return"index"in e?n={...e}:n=t.operations[e.scope].at(-1),((n==null?void 0:n.index)??-1)+1}function Qe(t,e){return{...t,revision:{...t.revision,[e.scope]:Ze(t,e)},lastModified:new Date().toISOString()}}function Ye(t,e,n=0,i=!1){if([nt,it,ct].includes(e.type))return t;const{scope:o}=e,a=t.operations[o].slice(),r=a.at(-1);let p=((r==null?void 0:r.index)??-1)+1;if("index"in e){if(e.index-n>p)throw new Error(`Missing operations: expected ${p} with skip 0 or equivalent, got index ${e.index} with skip ${n}`);p=e.index}const m={...e,index:p,timestamp:new Date().toISOString(),hash:"",scope:o,skip:n,error:void 0};return i&&(m.resultingState=t.state[o]),a.push(m),{...t,operations:{...t.operations,[o]:a}}}function tn(t,e,n=0,i=!1){let o=Ye(t,e,n,i);return o=Qe(o,e),o}function en(t,e,n){switch(Ft().parse(e),e.type){case Ht:return De(t,e.input);case ct:return Te(t,e,n);case Vt:return _e(t,e.input.state);default:return t}}function nn(t,e,n){switch(e.type){case nt:return ke(t,e,n);case it:return ze(t,e,n);default:return{document:t,action:e,skip:n}}}function on(t,e,n,i,o=!1,a=zt){const r=e.scope,p=t.operations[r].at(-1);if(!p)return t;const m=ht({...t.operations,[r]:ie(t.operations[r],p)});let d;const h=m[r].at(-1);if(o&&(h!=null&&h.resultingState))d=a(h.resultingState);else{const{state:b}=pt(t.initialState,m,n,void 0,void 0,void 0,void 0,{reuseHash:!0,reuseOperationResultingState:o,operationResultingStateParser:a});d=b[r]}return{...t,state:{...t.state,[r]:d},operations:ht({...t.operations})}}function Dt(t,e,n,i,o={}){const{skip:a,ignoreSkipOperations:r=!1,reuseHash:p=!1,reuseOperationResultingState:m=!1,operationResultingStateParser:d}=o,h={...e},b=a||0;let O={...t};const v=!r&&(b>0||"index"in h&&h.skip>0);return xt(h)&&(O=en(O,h,n)),O=tn(O,h,b,m),v&&(O=on(O,h,n,b,m,d)),O=H.produce(O,z=>{try{const A=n(z.state,h,i);if(A)return H.castDraft({...O,state:A})}catch(A){const R=O.operations[h.scope].length-1;z.operations[h.scope][R].error=A.message,z.operations[h.scope][R].skip=0,v&&(z.state=H.castDraft({...t.state}),z.operations=H.castDraft({...t.operations,[h.scope]:[...t.operations[h.scope],{...z.operations[h.scope][R]}]}))}}),H.produce(O,z=>{if([nt,it,ct].includes(h.type))return z;const A=h.scope||"global",R=p&&Object.prototype.hasOwnProperty.call(h,"hash")?h.hash:mt(z,A);z.operations[A][z.operations[A].length-1].hash=R,!xt(h)&&h.attachments&&h.attachments.forEach(c=>{const{hash:l,...u}=c;z.attachments[l]={...u}})})}function sn(t){return t.type===ve&&t.skip!==void 0&&t.skip>0&&t.hash!==void 0}function rn(t){return[nt,it].includes(t.type)}function xt(t){return[Ht,nt,it,ct,Vt].includes(t.type)}function K(t,e,n,i,o="global"){if(!t)throw new Error("Empty action type");if(typeof t!="string")throw new Error(`Invalid action type: ${JSON.stringify(t)}`);const a={type:t,input:e,scope:o};n&&(a.attachments=n);try{i==null||i().parse(a.input)}catch(r){throw new Error(`Invalid action input: ${r}`)}return a}function oe(t,e=Dt){return(n,i,o,a)=>e(n,i,t,o,a)}const se=(t,e)=>({name:"",documentType:"",revision:{global:0,local:0},created:new Date().toISOString(),lastModified:new Date().toISOString(),attachments:{},...t,state:(e==null?void 0:e(t==null?void 0:t.state))??(t==null?void 0:t.state)??{global:{},local:{}}}),re=(t,e)=>{const n=se(t,e);return{...n,initialState:n,operations:{global:[],local:[]},clipboard:[]}},mt=(t,e="global")=>lt(G(t.state[e]||"")),an=(t,e=1e3)=>{const n=Math.random()*e;return lt(`${(t??new Date).toISOString()}${n}`)};function tt(t){return H.castImmutable(H.freeze(t,!0))}function pn(t,e){const n=[...t];let i=e||0,o=n.length>0?n[n.length-1].index:0;const a=[];for(const r of n.reverse()){if(i>0){const d=o-r.index;i-=d}if(i<0)throw new Error("Invalid operation index, missing operations");const p={ignore:i>0,operation:r},m=r.skip>0?r.skip+1:0;if(m>0&&m>i){const d=m-i;i=i+d}o=r.index,a.push(p)}return a.reverse()}function cn(t,e,n){const i=t.slice().sort((p,m)=>p.skip-m.skip).sort((p,m)=>p.index-m.index);let o=n,a=0,r=e;for(const p of i.reverse()){const m=r-p.index;if(o=o-m,o>-1)a++,r=p.index;else break}return a}function ln(t){return Object.values(t).flatMap(e=>e).sort((e,n)=>new Date(e.timestamp).getTime()-new Date(n.timestamp).getTime())}function mn(t){return Object.values(t).flatMap(e=>e).sort((e,n)=>new Date(e.operation.timestamp).getTime()-new Date(n.operation.timestamp).getTime())}function pt(t,e,n,i,o,a=Dt,r={},p){const m=oe(n,a);return kt(t,e,m,i,o,r,p)}function kt(t,e,n,i,o,a={},r){const{checkHashes:p=!0,reuseOperationResultingState:m,operationResultingStateParser:d=zt}=r||{};let h=t;const b=[],O={global:[],local:[]};if(m)for(const[c,l]of Object.entries(e)){const u=l.findLastIndex(L=>!!L.resultingState);if(u<0){b.push(...l);continue}const T=l[u];try{const L=d(T.resultingState);h={...h,state:{...h.state,[c]:L}},O[c].push(...l.slice(0,u+1)),b.push(...l.slice(u+1))}catch{b.push(...l)}}else b.push(...Object.values(e).flat());const v=re(h);v.initialState=t,v.operations=O;const z=b.reduce((c,l)=>n(c,l,i,{skip:l.skip,ignoreSkipOperations:!0,reuseHash:!p}),v);if(!p)for(const c of Object.keys(z.state))for(let l=b.length-1;l>=0;l--){const u=b[l];if(u.scope===c){if(u.hash!==mt(z,c))throw new Error(`Hash mismatch for scope ${c}`);break}}const A=Object.keys(z.operations).reduce((c,l)=>{const u=l;return{...c,[u]:[...z.operations[u].map((T,L)=>{var P;return{...T,timestamp:((P=e[u][L])==null?void 0:P.timestamp)??T.timestamp}})]}},{global:[],local:[]}),R=Object.values(A).reduce((c,l)=>{const u=l[l.length-1];return(u==null?void 0:u.timestamp)>c&&(c=u.timestamp),c},t.lastModified);return{...z,operations:A,lastModified:R}}function un(t,e){return G(t)===G(e)}function zt(t){const e=typeof t;if(e==="string")return JSON.parse(t);if(e==="object")return t;throw new Error(`Providing resulting state is of type: ${e}`)}const ae=t=>K("SET_NAME",t,void 0,Ot,void 0),pe=(t=1,e="global")=>K("UNDO",t,void 0,St,e),ce=(t=1,e="global")=>K("REDO",t,void 0,wt,e),le=(t,e,n="global")=>K("PRUNE",{start:t,end:e},void 0,bt,n),Tt=(t,e)=>K("LOAD_STATE",{state:t,operations:e},void 0,yt),me=(t="global")=>K("NOOP",{},void 0,void 0,t),fn=Object.freeze(Object.defineProperty({__proto__:null,loadState:Tt,noop:me,prune:le,redo:ce,setName:ae,undo:pe},Symbol.toStringTag,{value:"Module"}));class dn{constructor(e,n,i){at(this,"_document");at(this,"_reducer");at(this,"_signalDispatch");this._reducer=e,this._document=n,this._signalDispatch=i}dispatch(e,n){return this._document=this._reducer(this._document,e,this._signalDispatch,n),this}saveToFile(e,n,i){return Wt(this._document,e,n,i)}async loadFromFile(e){this._document=await gt(e,this._reducer)}static async stateFromFile(e,n){return await gt(e,n)}get state(){return tt(this._document.state)}get operations(){return tt(this._document.operations)}get name(){return this._document.name}get documentType(){return this._document.documentType}get created(){return this._document.created}get lastModified(){return this._document.lastModified}get revision(){return this._document.revision.global}getRevision(e){return this._document.revision[e]}get initialState(){return tt(this._document.initialState)}toDocument(){return tt(this._document)}getAttachment(e){return this._document.attachments[e]}setName(e){return this.dispatch(ae(e)),this}undo(e){return this.dispatch(pe(e)),this}redo(e){return this.dispatch(ce(e)),this}prune(e,n){return this.dispatch(le(e,n)),this}loadState(e,n){return this.dispatch(Tt(e,n)),this}}function gn(t,e){e.forEach(n=>{Object.getOwnPropertyNames(n.prototype).forEach(i=>{Object.defineProperty(t.prototype,i,Object.getOwnPropertyDescriptor(n.prototype,i)||Object.create(null))})})}exports.BaseActions=fn;exports.BaseDocument=dn;exports.applyMixins=gn;exports.baseReducer=Dt;exports.calculateSkipsLeft=cn;exports.createAction=K;exports.createDocument=re;exports.createExtendedState=se;exports.createReducer=oe;exports.createZip=jt;exports.documentHelpers=Ge;exports.getLocalFile=qe;exports.getRemoteFile=Le;exports.hashDocument=mt;exports.hashKey=an;exports.isBaseAction=xt;exports.isNoopOperation=sn;exports.isSameDocument=un;exports.isUndoRedo=rn;exports.loadFromFile=gt;exports.loadFromInput=Gt;exports.mapSkippedOperations=pn;exports.parseResultingState=zt;exports.processUndoRedo=nn;exports.readOnly=tt;exports.replayDocument=kt;exports.replayOperations=pt;exports.saveToFile=Wt;exports.saveToFileHandle=Fe;exports.sortMappedOperations=mn;exports.sortOperations=ln;exports.validateOperations=Kt;exports.zod=je;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { j as e, f as a, b as s, a as t, c as o, k as r, m as i, n, o as l, p as c, q as p, i as d, r as u, t as m, u as O, l as y, e as S, v as b, w as g, x as D, y as F, z as _, s as f, d as v, A as R, C as h, D as j, B as x, h as z, g as A, E as B, F as M, G as T } from "./object-C2s2eZ08.js";
|
|
2
|
-
const k = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3
|
-
__proto__: null,
|
|
4
|
-
calculateSkipsLeft: e,
|
|
5
|
-
createAction: a,
|
|
6
|
-
createDocument: s,
|
|
7
|
-
createExtendedState: t,
|
|
8
|
-
createReducer: o,
|
|
9
|
-
createZip: r,
|
|
10
|
-
documentHelpers: i,
|
|
11
|
-
getLocalFile: n,
|
|
12
|
-
getRemoteFile: l,
|
|
13
|
-
hashDocument: c,
|
|
14
|
-
hashKey: p,
|
|
15
|
-
isBaseAction: d,
|
|
16
|
-
isNoopOperation: u,
|
|
17
|
-
isSameDocument: m,
|
|
18
|
-
isUndoRedo: O,
|
|
19
|
-
loadFromFile: y,
|
|
20
|
-
loadFromInput: S,
|
|
21
|
-
mapSkippedOperations: b,
|
|
22
|
-
parseResultingState: g,
|
|
23
|
-
readOnly: D,
|
|
24
|
-
replayDocument: F,
|
|
25
|
-
replayOperations: _,
|
|
26
|
-
saveToFile: f,
|
|
27
|
-
saveToFileHandle: v,
|
|
28
|
-
sortMappedOperations: R,
|
|
29
|
-
sortOperations: h,
|
|
30
|
-
validateOperations: j
|
|
31
|
-
}, Symbol.toStringTag, { value: "Module" })), H = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
32
|
-
__proto__: null,
|
|
33
|
-
BaseDocument: x,
|
|
34
|
-
actions: z,
|
|
35
|
-
applyMixins: A,
|
|
36
|
-
baseReducer: B,
|
|
37
|
-
processUndoRedo: M,
|
|
38
|
-
utils: k,
|
|
39
|
-
z: T
|
|
40
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
41
|
-
export {
|
|
42
|
-
H as D,
|
|
43
|
-
k as i
|
|
44
|
-
};
|