cogsbox-state 0.5.3
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/README.md +386 -0
- package/dist/CogsState.d.ts +279 -0
- package/dist/CogsState.jsx +608 -0
- package/dist/CogsState.jsx.map +1 -0
- package/dist/CogsStateClient.d.ts +12 -0
- package/dist/CogsStateClient.jsx +11 -0
- package/dist/CogsStateClient.jsx.map +1 -0
- package/dist/TRPCValidationLink.d.ts +4 -0
- package/dist/_virtual/_commonjsHelpers.js +7 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/index.js +5 -0
- package/dist/_virtual/index.js.map +1 -0
- package/dist/_virtual/jsx-runtime.jsx +5 -0
- package/dist/_virtual/jsx-runtime.jsx.map +1 -0
- package/dist/_virtual/react-jsx-runtime.jsx +5 -0
- package/dist/_virtual/react-jsx-runtime.jsx.map +1 -0
- package/dist/_virtual/react-jsx-runtime.production.jsx +5 -0
- package/dist/_virtual/react-jsx-runtime.production.jsx.map +1 -0
- package/dist/_virtual/react.js +5 -0
- package/dist/_virtual/react.js.map +1 -0
- package/dist/_virtual/react.production.js +5 -0
- package/dist/_virtual/react.production.js.map +1 -0
- package/dist/examples/index.d.ts +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/node_modules/react/cjs/react-jsx-runtime.jsx +605 -0
- package/dist/node_modules/react/cjs/react-jsx-runtime.jsx.map +1 -0
- package/dist/node_modules/react/cjs/react-jsx-runtime.production.jsx +29 -0
- package/dist/node_modules/react/cjs/react-jsx-runtime.production.jsx.map +1 -0
- package/dist/node_modules/react/cjs/react.js +1274 -0
- package/dist/node_modules/react/cjs/react.js.map +1 -0
- package/dist/node_modules/react/cjs/react.production.js +209 -0
- package/dist/node_modules/react/cjs/react.production.js.map +1 -0
- package/dist/node_modules/react/index.js +12 -0
- package/dist/node_modules/react/index.js.map +1 -0
- package/dist/node_modules/react/jsx-runtime.jsx +9 -0
- package/dist/node_modules/react/jsx-runtime.jsx.map +1 -0
- package/dist/node_modules/uuid/dist/esm-browser/native.js +7 -0
- package/dist/node_modules/uuid/dist/esm-browser/native.js.map +1 -0
- package/dist/node_modules/uuid/dist/esm-browser/rng.js +11 -0
- package/dist/node_modules/uuid/dist/esm-browser/rng.js.map +1 -0
- package/dist/node_modules/uuid/dist/esm-browser/stringify.js +10 -0
- package/dist/node_modules/uuid/dist/esm-browser/stringify.js.map +1 -0
- package/dist/node_modules/uuid/dist/esm-browser/v4.js +14 -0
- package/dist/node_modules/uuid/dist/esm-browser/v4.js.map +1 -0
- package/dist/node_modules/zustand/esm/react.js +20 -0
- package/dist/node_modules/zustand/esm/react.js.map +1 -0
- package/dist/node_modules/zustand/esm/vanilla.js +15 -0
- package/dist/node_modules/zustand/esm/vanilla.js.map +1 -0
- package/dist/store.d.ts +103 -0
- package/dist/store.js +225 -0
- package/dist/store.js.map +1 -0
- package/dist/updaterFunctions.d.ts +29 -0
- package/dist/updaterFunctions.jsx +177 -0
- package/dist/updaterFunctions.jsx.map +1 -0
- package/dist/utility.d.ts +19 -0
- package/dist/utility.js +189 -0
- package/dist/utility.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
let t;
|
|
2
|
+
const e = new Uint8Array(16);
|
|
3
|
+
function o() {
|
|
4
|
+
if (!t && (t = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !t))
|
|
5
|
+
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
6
|
+
return t(e);
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
o as default
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=rng.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rng.js","sources":["../../../../../node_modules/uuid/dist/esm-browser/rng.js"],"sourcesContent":["// Unique ID creation requires a high quality random # generator. In the browser we therefore\n// require the crypto API and do not support built-in fallback to lower quality random number\n// generators (like Math.random()).\nlet getRandomValues;\nconst rnds8 = new Uint8Array(16);\nexport default function rng() {\n // lazy load so that environments that need to polyfill have a chance to do so\n if (!getRandomValues) {\n // getRandomValues needs to be invoked in a context where \"this\" is a Crypto implementation.\n getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);\n\n if (!getRandomValues) {\n throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');\n }\n }\n\n return getRandomValues(rnds8);\n}"],"names":["getRandomValues","rnds8","rng"],"mappings":"AAGA,IAAIA;AACJ,MAAMC,IAAQ,IAAI,WAAW,EAAE;AAChB,SAASC,IAAM;AAE5B,MAAI,CAACF,MAEHA,IAAkB,OAAO,SAAW,OAAe,OAAO,mBAAmB,OAAO,gBAAgB,KAAK,MAAM,GAE3G,CAACA;AACH,UAAM,IAAI,MAAM,0GAA0G;AAI9H,SAAOA,EAAgBC,CAAK;AAC9B;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const i = [];
|
|
2
|
+
for (let n = 0; n < 256; ++n)
|
|
3
|
+
i.push((n + 256).toString(16).slice(1));
|
|
4
|
+
function c(n, u = 0) {
|
|
5
|
+
return i[n[u + 0]] + i[n[u + 1]] + i[n[u + 2]] + i[n[u + 3]] + "-" + i[n[u + 4]] + i[n[u + 5]] + "-" + i[n[u + 6]] + i[n[u + 7]] + "-" + i[n[u + 8]] + i[n[u + 9]] + "-" + i[n[u + 10]] + i[n[u + 11]] + i[n[u + 12]] + i[n[u + 13]] + i[n[u + 14]] + i[n[u + 15]];
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
c as unsafeStringify
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=stringify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringify.js","sources":["../../../../../node_modules/uuid/dist/esm-browser/stringify.js"],"sourcesContent":["import validate from './validate.js';\n/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\n\nconst byteToHex = [];\n\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\n\nexport function unsafeStringify(arr, offset = 0) {\n // Note: Be careful editing this code! It's been tuned for performance\n // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434\n return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];\n}\n\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset); // Consistency check for valid UUID. If this throws, it's likely due to one\n // of the following:\n // - One or more input array values don't map to a hex octet (leading to\n // \"undefined\" in the uuid)\n // - Invalid input values for the RFC `version` or `variant` fields\n\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n\n return uuid;\n}\n\nexport default stringify;"],"names":["byteToHex","i","unsafeStringify","arr","offset"],"mappings":"AAMA,MAAMA,IAAY,CAAE;AAEpB,SAASC,IAAI,GAAGA,IAAI,KAAK,EAAEA;AACzB,EAAAD,EAAU,MAAMC,IAAI,KAAO,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;AAG3C,SAASC,EAAgBC,GAAKC,IAAS,GAAG;AAG/C,SAAOJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IAAIJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IAAIJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IAAIJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IAAI,MAAMJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IAAIJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IAAI,MAAMJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IAAIJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IAAI,MAAMJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IAAIJ,EAAUG,EAAIC,IAAS,CAAC,CAAC,IAAI,MAAMJ,EAAUG,EAAIC,IAAS,EAAE,CAAC,IAAIJ,EAAUG,EAAIC,IAAS,EAAE,CAAC,IAAIJ,EAAUG,EAAIC,IAAS,EAAE,CAAC,IAAIJ,EAAUG,EAAIC,IAAS,EAAE,CAAC,IAAIJ,EAAUG,EAAIC,IAAS,EAAE,CAAC,IAAIJ,EAAUG,EAAIC,IAAS,EAAE,CAAC;AACnf;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import n from "./native.js";
|
|
2
|
+
import m from "./rng.js";
|
|
3
|
+
import { unsafeStringify as t } from "./stringify.js";
|
|
4
|
+
function x(r, e, a) {
|
|
5
|
+
if (n.randomUUID && !r)
|
|
6
|
+
return n.randomUUID();
|
|
7
|
+
r = r || {};
|
|
8
|
+
const f = r.random || (r.rng || m)();
|
|
9
|
+
return f[6] = f[6] & 15 | 64, f[8] = f[8] & 63 | 128, t(f);
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
x as default
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=v4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v4.js","sources":["../../../../../node_modules/uuid/dist/esm-browser/v4.js"],"sourcesContent":["import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\n\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n\n options = options || {};\n const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n\n rnds[6] = rnds[6] & 0x0f | 0x40;\n rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided\n\n if (buf) {\n offset = offset || 0;\n\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n\n return buf;\n }\n\n return unsafeStringify(rnds);\n}\n\nexport default v4;"],"names":["v4","options","buf","offset","native","rnds","rng","unsafeStringify"],"mappings":";;;AAIA,SAASA,EAAGC,GAASC,GAAKC,GAAQ;AAChC,MAAIC,EAAO,cAAsB,CAACH;AAChC,WAAOG,EAAO,WAAY;AAG5B,EAAAH,IAAUA,KAAW,CAAE;AACvB,QAAMI,IAAOJ,EAAQ,WAAWA,EAAQ,OAAOK;AAE/C,SAAAD,EAAK,CAAC,IAAIA,EAAK,CAAC,IAAI,KAAO,IAC3BA,EAAK,CAAC,IAAIA,EAAK,CAAC,IAAI,KAAO,KAYpBE,EAAgBF,CAAI;AAC7B;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import o from "../../react/index.js";
|
|
2
|
+
import { createStore as c } from "./vanilla.js";
|
|
3
|
+
const u = (t) => t;
|
|
4
|
+
function i(t, e = u) {
|
|
5
|
+
const n = o.useSyncExternalStore(
|
|
6
|
+
t.subscribe,
|
|
7
|
+
() => e(t.getState()),
|
|
8
|
+
() => e(t.getInitialState())
|
|
9
|
+
);
|
|
10
|
+
return o.useDebugValue(n), n;
|
|
11
|
+
}
|
|
12
|
+
const r = (t) => {
|
|
13
|
+
const e = c(t), n = (s) => i(e, s);
|
|
14
|
+
return Object.assign(n, e), n;
|
|
15
|
+
}, m = (t) => t ? r(t) : r;
|
|
16
|
+
export {
|
|
17
|
+
m as create,
|
|
18
|
+
i as useStore
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sources":["../../../../node_modules/zustand/esm/react.mjs"],"sourcesContent":["import React from 'react';\nimport { createStore } from 'zustand/vanilla';\n\nconst identity = (arg) => arg;\nfunction useStore(api, selector = identity) {\n const slice = React.useSyncExternalStore(\n api.subscribe,\n () => selector(api.getState()),\n () => selector(api.getInitialState())\n );\n React.useDebugValue(slice);\n return slice;\n}\nconst createImpl = (createState) => {\n const api = createStore(createState);\n const useBoundStore = (selector) => useStore(api, selector);\n Object.assign(useBoundStore, api);\n return useBoundStore;\n};\nconst create = (createState) => createState ? createImpl(createState) : createImpl;\n\nexport { create, useStore };\n"],"names":["identity","arg","useStore","api","selector","slice","React","createImpl","createState","createStore","useBoundStore","create"],"mappings":";;AAGA,MAAMA,IAAW,CAACC,MAAQA;AAC1B,SAASC,EAASC,GAAKC,IAAWJ,GAAU;AAC1C,QAAMK,IAAQC,EAAM;AAAA,IAClBH,EAAI;AAAA,IACJ,MAAMC,EAASD,EAAI,UAAU;AAAA,IAC7B,MAAMC,EAASD,EAAI,gBAAiB,CAAA;AAAA,EACrC;AACD,SAAAG,EAAM,cAAcD,CAAK,GAClBA;AACT;AACA,MAAME,IAAa,CAACC,MAAgB;AAClC,QAAML,IAAMM,EAAYD,CAAW,GAC7BE,IAAgB,CAACN,MAAaF,EAASC,GAAKC,CAAQ;AAC1D,gBAAO,OAAOM,GAAeP,CAAG,GACzBO;AACT,GACMC,IAAS,CAACH,MAAgBA,IAAcD,EAAWC,CAAW,IAAID;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const S = (s) => {
|
|
2
|
+
let t;
|
|
3
|
+
const o = /* @__PURE__ */ new Set(), c = (e, r) => {
|
|
4
|
+
const n = typeof e == "function" ? e(t) : e;
|
|
5
|
+
if (!Object.is(n, t)) {
|
|
6
|
+
const b = t;
|
|
7
|
+
t = r ?? (typeof n != "object" || n === null) ? n : Object.assign({}, t, n), o.forEach((l) => l(t, b));
|
|
8
|
+
}
|
|
9
|
+
}, i = () => t, a = { setState: c, getState: i, getInitialState: () => u, subscribe: (e) => (o.add(e), () => o.delete(e)) }, u = t = s(c, i, a);
|
|
10
|
+
return a;
|
|
11
|
+
}, d = (s) => s ? S(s) : S;
|
|
12
|
+
export {
|
|
13
|
+
d as createStore
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=vanilla.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vanilla.js","sources":["../../../../node_modules/zustand/esm/vanilla.mjs"],"sourcesContent":["const createStoreImpl = (createState) => {\n let state;\n const listeners = /* @__PURE__ */ new Set();\n const setState = (partial, replace) => {\n const nextState = typeof partial === \"function\" ? partial(state) : partial;\n if (!Object.is(nextState, state)) {\n const previousState = state;\n state = (replace != null ? replace : typeof nextState !== \"object\" || nextState === null) ? nextState : Object.assign({}, state, nextState);\n listeners.forEach((listener) => listener(state, previousState));\n }\n };\n const getState = () => state;\n const getInitialState = () => initialState;\n const subscribe = (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n };\n const api = { setState, getState, getInitialState, subscribe };\n const initialState = state = createState(setState, getState, api);\n return api;\n};\nconst createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;\n\nexport { createStore };\n"],"names":["createStoreImpl","createState","state","listeners","setState","partial","replace","nextState","previousState","listener","getState","api","initialState","createStore"],"mappings":"AAAA,MAAMA,IAAkB,CAACC,MAAgB;AACvC,MAAIC;AACJ,QAAMC,IAA4B,oBAAI,IAAK,GACrCC,IAAW,CAACC,GAASC,MAAY;AACrC,UAAMC,IAAY,OAAOF,KAAY,aAAaA,EAAQH,CAAK,IAAIG;AACnE,QAAI,CAAC,OAAO,GAAGE,GAAWL,CAAK,GAAG;AAChC,YAAMM,IAAgBN;AACtB,MAAAA,IAASI,MAA4B,OAAOC,KAAc,YAAYA,MAAc,QAAQA,IAAY,OAAO,OAAO,CAAE,GAAEL,GAAOK,CAAS,GAC1IJ,EAAU,QAAQ,CAACM,MAAaA,EAASP,GAAOM,CAAa,CAAC;AAAA,IACpE;AAAA,EACG,GACKE,IAAW,MAAMR,GAMjBS,IAAM,EAAE,UAAAP,GAAU,UAAAM,GAAU,iBALV,MAAME,GAKqB,WAJjC,CAACH,OACjBN,EAAU,IAAIM,CAAQ,GACf,MAAMN,EAAU,OAAOM,CAAQ,GAEsB,GACxDG,IAAeV,IAAQD,EAAYG,GAAUM,GAAUC,CAAG;AAChE,SAAOA;AACT,GACME,IAAc,CAACZ,MAAgBA,IAAcD,EAAgBC,CAAW,IAAID;","x_google_ignoreList":[0]}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { OptionsType, StateKeys, SyncActionsType, SyncInfo, UpdateTypeDetail } from './CogsState.js';
|
|
2
|
+
|
|
3
|
+
type StateUpdater<StateValue> = StateValue | ((prevValue: StateValue) => StateValue);
|
|
4
|
+
export type FreshValuesObject = {
|
|
5
|
+
pathsToValues?: string[];
|
|
6
|
+
prevValue?: any;
|
|
7
|
+
newValue?: any;
|
|
8
|
+
timeStamp: number;
|
|
9
|
+
};
|
|
10
|
+
type SyncLogType = {
|
|
11
|
+
timeStamp: number;
|
|
12
|
+
};
|
|
13
|
+
type StateValue = any;
|
|
14
|
+
export type CogsGlobalState = {
|
|
15
|
+
updaterState: {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
};
|
|
18
|
+
initialStateOptions: {
|
|
19
|
+
[key: string]: OptionsType;
|
|
20
|
+
};
|
|
21
|
+
cogsStateStore: {
|
|
22
|
+
[key: string]: StateValue;
|
|
23
|
+
};
|
|
24
|
+
isLoadingGlobal: {
|
|
25
|
+
[key: string]: boolean;
|
|
26
|
+
};
|
|
27
|
+
initialStateGlobal: {
|
|
28
|
+
[key: string]: StateValue;
|
|
29
|
+
};
|
|
30
|
+
validationErrors: Map<string, string[]>;
|
|
31
|
+
serverState: {
|
|
32
|
+
[key: string]: StateValue;
|
|
33
|
+
};
|
|
34
|
+
serverSyncActions: {
|
|
35
|
+
[key: string]: SyncActionsType<any>;
|
|
36
|
+
};
|
|
37
|
+
serverSyncLog: {
|
|
38
|
+
[key: string]: SyncLogType[];
|
|
39
|
+
};
|
|
40
|
+
serverSideOrNot: {
|
|
41
|
+
[key: string]: boolean;
|
|
42
|
+
};
|
|
43
|
+
setServerSyncLog: (key: string, newValue: SyncLogType) => void;
|
|
44
|
+
setServerSideOrNot: (key: string, value: boolean) => void;
|
|
45
|
+
getServerSideOrNot: (key: string) => boolean | undefined;
|
|
46
|
+
setServerState: <StateKey extends StateKeys>(key: StateKey, value: StateValue) => void;
|
|
47
|
+
getThisLocalUpdate: (key: string) => UpdateTypeDetail[] | undefined;
|
|
48
|
+
setServerSyncActions: (key: string, value: SyncActionsType<any>) => void;
|
|
49
|
+
addValidationError: (path: string, message: string) => void;
|
|
50
|
+
getValidationErrors: (path: string) => string[];
|
|
51
|
+
updateInitialStateGlobal: (key: string, newState: StateValue) => void;
|
|
52
|
+
getInitialOptions: (key: string) => OptionsType | undefined;
|
|
53
|
+
getUpdaterState: (key: string) => StateUpdater<StateValue>;
|
|
54
|
+
setUpdaterState: (key: string, newUpdater: any) => void;
|
|
55
|
+
getKeyState: <StateKey extends StateKeys>(key: StateKey) => StateValue;
|
|
56
|
+
getNestedState: <StateKey extends StateKeys>(key: StateKey, path: string[]) => StateValue;
|
|
57
|
+
setState: <StateKey extends StateKeys>(key: StateKey, value: StateUpdater<StateValue>) => void;
|
|
58
|
+
setInitialStates: (initialState: StateValue) => void;
|
|
59
|
+
stateLog: {
|
|
60
|
+
[key: string]: UpdateTypeDetail[];
|
|
61
|
+
};
|
|
62
|
+
setStateLog: (key: string, updater: (prevUpdates: UpdateTypeDetail[]) => UpdateTypeDetail[]) => void;
|
|
63
|
+
setIsLoadingGlobal: (key: string, value: boolean) => void;
|
|
64
|
+
setInitialStateOptions: (key: string, value: OptionsType) => void;
|
|
65
|
+
removeValidationError: (path: string) => void;
|
|
66
|
+
signalDomElements: Map<string, Set<{
|
|
67
|
+
instanceId: string;
|
|
68
|
+
parentId: string;
|
|
69
|
+
position: number;
|
|
70
|
+
}>>;
|
|
71
|
+
addSignalElement: (signalId: string, elementInfo: {
|
|
72
|
+
instanceId: string;
|
|
73
|
+
parentId: string;
|
|
74
|
+
position: number;
|
|
75
|
+
}) => void;
|
|
76
|
+
removeSignalElement: (signalId: string, instanceId: string) => void;
|
|
77
|
+
reRenderTriggerPrevValue: Record<string, any>;
|
|
78
|
+
reactiveDeps: Record<string, {
|
|
79
|
+
deps: any[];
|
|
80
|
+
updaters: Set<() => void>;
|
|
81
|
+
depsFunction: ((state: any) => any[] | true) | null;
|
|
82
|
+
}>;
|
|
83
|
+
setReactiveDeps: (key: string, record: {
|
|
84
|
+
deps: any[];
|
|
85
|
+
updaters: Set<() => void>;
|
|
86
|
+
depsFunction: ((state: any) => any[] | true) | null;
|
|
87
|
+
}) => void;
|
|
88
|
+
deleteReactiveDeps: (key: string) => void;
|
|
89
|
+
subscribe: (listener: () => void) => () => void;
|
|
90
|
+
stateComponents: Map<string, {
|
|
91
|
+
components: Map<string, {
|
|
92
|
+
forceUpdate: () => void;
|
|
93
|
+
paths: Set<string>;
|
|
94
|
+
deps?: any[];
|
|
95
|
+
depsFunction?: (state: any) => any[] | true;
|
|
96
|
+
}>;
|
|
97
|
+
}>;
|
|
98
|
+
syncInfoStore: Map<string, SyncInfo>;
|
|
99
|
+
setSyncInfo: (key: string, syncInfo: SyncInfo) => void;
|
|
100
|
+
getSyncInfo: (key: string) => SyncInfo | null;
|
|
101
|
+
};
|
|
102
|
+
export declare const getGlobalStore: import('zustand').UseBoundStore<import('zustand').StoreApi<CogsGlobalState>>;
|
|
103
|
+
export {};
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { create as f } from "./node_modules/zustand/esm/react.js";
|
|
2
|
+
const v = f((o, l) => ({
|
|
3
|
+
stateComponents: /* @__PURE__ */ new Map(),
|
|
4
|
+
subscribe: (e) => l().subscribe(e),
|
|
5
|
+
reactiveDeps: {},
|
|
6
|
+
setReactiveDeps: (e, r) => o((t) => ({
|
|
7
|
+
...t,
|
|
8
|
+
reactiveDeps: {
|
|
9
|
+
...t.reactiveDeps,
|
|
10
|
+
[e]: r
|
|
11
|
+
}
|
|
12
|
+
})),
|
|
13
|
+
deleteReactiveDeps: (e) => o((r) => {
|
|
14
|
+
const { [e]: t, ...n } = r.reactiveDeps;
|
|
15
|
+
return {
|
|
16
|
+
...r,
|
|
17
|
+
reactiveDeps: n
|
|
18
|
+
};
|
|
19
|
+
}),
|
|
20
|
+
reRenderTriggerPrevValue: {},
|
|
21
|
+
signalDomElements: /* @__PURE__ */ new Map(),
|
|
22
|
+
addSignalElement: (e, r) => {
|
|
23
|
+
console.log("Adding signal element", e, r);
|
|
24
|
+
const t = l().signalDomElements;
|
|
25
|
+
t.has(e) || t.set(e, /* @__PURE__ */ new Set()), t.get(e).add(r), console.log("After adding", t.get(e)), o({ signalDomElements: new Map(t) });
|
|
26
|
+
},
|
|
27
|
+
removeSignalElement: (e, r) => {
|
|
28
|
+
console.log("Removing signal element", e, r);
|
|
29
|
+
const t = l().signalDomElements, n = t.get(e);
|
|
30
|
+
n && n.forEach((a) => {
|
|
31
|
+
a.instanceId === r && n.delete(a);
|
|
32
|
+
}), o({ signalDomElements: new Map(t) });
|
|
33
|
+
},
|
|
34
|
+
initialStateOptions: {},
|
|
35
|
+
updaterState: {},
|
|
36
|
+
stateTimeline: {},
|
|
37
|
+
cogsStateStore: {},
|
|
38
|
+
stateLog: {},
|
|
39
|
+
isLoadingGlobal: {},
|
|
40
|
+
initialStateGlobal: {},
|
|
41
|
+
validationErrors: /* @__PURE__ */ new Map(),
|
|
42
|
+
serverState: {},
|
|
43
|
+
serverSyncActions: {},
|
|
44
|
+
serverSyncLog: {},
|
|
45
|
+
serverSideOrNot: {},
|
|
46
|
+
setServerSyncLog: (e, r) => {
|
|
47
|
+
o((t) => ({
|
|
48
|
+
serverSyncLog: {
|
|
49
|
+
...t.serverSyncLog,
|
|
50
|
+
[e]: [...t.serverSyncLog[e] ?? [], r]
|
|
51
|
+
}
|
|
52
|
+
}));
|
|
53
|
+
},
|
|
54
|
+
setServerSideOrNot: (e, r) => {
|
|
55
|
+
o((t) => ({
|
|
56
|
+
serverSideOrNot: {
|
|
57
|
+
...t.serverSideOrNot,
|
|
58
|
+
[e]: r
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
},
|
|
62
|
+
getServerSideOrNot: (e) => l().serverSideOrNot[e],
|
|
63
|
+
getThisLocalUpdate: (e) => l().stateLog[e],
|
|
64
|
+
setServerState: (e, r) => {
|
|
65
|
+
o((t) => ({
|
|
66
|
+
serverState: {
|
|
67
|
+
...t.serverState,
|
|
68
|
+
[e]: r
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
},
|
|
72
|
+
setStateLog: (e, r) => {
|
|
73
|
+
o((t) => {
|
|
74
|
+
const n = t.stateLog[e] ?? [], a = r(n);
|
|
75
|
+
return {
|
|
76
|
+
stateLog: {
|
|
77
|
+
...t.stateLog,
|
|
78
|
+
[e]: a
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
setIsLoadingGlobal: (e, r) => {
|
|
84
|
+
o((t) => ({
|
|
85
|
+
isLoadingGlobal: {
|
|
86
|
+
...t.isLoadingGlobal,
|
|
87
|
+
[e]: r
|
|
88
|
+
}
|
|
89
|
+
}));
|
|
90
|
+
},
|
|
91
|
+
setServerSyncActions: (e, r) => {
|
|
92
|
+
o((t) => ({
|
|
93
|
+
serverSyncActions: {
|
|
94
|
+
...t.serverSyncActions,
|
|
95
|
+
[e]: r
|
|
96
|
+
}
|
|
97
|
+
}));
|
|
98
|
+
},
|
|
99
|
+
addValidationError: (e, r) => {
|
|
100
|
+
o((t) => {
|
|
101
|
+
const n = new Map(t.validationErrors), a = n.get(e) || [];
|
|
102
|
+
return n.set(e, [...a, r]), { validationErrors: n };
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
removeValidationError: (e) => {
|
|
106
|
+
o((r) => {
|
|
107
|
+
const t = new Map(r.validationErrors);
|
|
108
|
+
console.log("updatedErrors", t);
|
|
109
|
+
let n = !1;
|
|
110
|
+
const a = e.split(".");
|
|
111
|
+
return Array.from(t.keys()).forEach((i) => {
|
|
112
|
+
const c = i.split(".");
|
|
113
|
+
if (c.length >= a.length) {
|
|
114
|
+
let S = !0;
|
|
115
|
+
for (let s = 0; s < a.length; s++)
|
|
116
|
+
if (c[s] !== a[s]) {
|
|
117
|
+
S = !1;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
S && (n = !0, t.delete(i));
|
|
121
|
+
}
|
|
122
|
+
}), n ? { validationErrors: t } : r;
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
getValidationErrors: (e) => {
|
|
126
|
+
const r = [], t = l().validationErrors, n = e.split("."), a = (i, c) => i === "[*]" ? !0 : Array.isArray(i) ? i.includes(parseInt(c)) : i === c;
|
|
127
|
+
return Array.from(t.keys()).forEach((i) => {
|
|
128
|
+
const c = i.split(".");
|
|
129
|
+
if (c.length >= n.length) {
|
|
130
|
+
let S = !0;
|
|
131
|
+
for (let s = 0; s < n.length; s++) {
|
|
132
|
+
const d = n[s], g = c[s];
|
|
133
|
+
if (d === "[*]" || Array.isArray(d)) {
|
|
134
|
+
const u = parseInt(g);
|
|
135
|
+
if (isNaN(u)) {
|
|
136
|
+
S = !1;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
if (!a(d, g)) {
|
|
140
|
+
S = !1;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
} else if (d !== g) {
|
|
144
|
+
S = !1;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (S) {
|
|
149
|
+
const s = t.get(i);
|
|
150
|
+
s && r.push(...s);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}), r;
|
|
154
|
+
},
|
|
155
|
+
getInitialOptions: (e) => l().initialStateOptions[e],
|
|
156
|
+
getNestedState: (e, r) => {
|
|
157
|
+
const t = l().cogsStateStore[e], n = (a, i) => {
|
|
158
|
+
if (i.length === 0) return a;
|
|
159
|
+
const c = i[0], S = i.slice(1);
|
|
160
|
+
if (c === "[*]") {
|
|
161
|
+
if (!Array.isArray(a)) {
|
|
162
|
+
console.warn("Asterisk notation used on non-array value");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (S.length === 0) return a;
|
|
166
|
+
const d = a.map(
|
|
167
|
+
(g) => n(g, S)
|
|
168
|
+
);
|
|
169
|
+
return Array.isArray(d[0]) ? d.flat() : d;
|
|
170
|
+
}
|
|
171
|
+
const s = a[c];
|
|
172
|
+
if (s !== void 0)
|
|
173
|
+
return n(s, S);
|
|
174
|
+
};
|
|
175
|
+
return n(t, r);
|
|
176
|
+
},
|
|
177
|
+
setInitialStateOptions: (e, r) => {
|
|
178
|
+
o((t) => ({
|
|
179
|
+
initialStateOptions: {
|
|
180
|
+
...t.initialStateOptions,
|
|
181
|
+
[e]: r
|
|
182
|
+
}
|
|
183
|
+
}));
|
|
184
|
+
},
|
|
185
|
+
updateInitialStateGlobal: (e, r) => {
|
|
186
|
+
o((t) => ({
|
|
187
|
+
initialStateGlobal: {
|
|
188
|
+
...t.initialStateGlobal,
|
|
189
|
+
[e]: r
|
|
190
|
+
}
|
|
191
|
+
}));
|
|
192
|
+
},
|
|
193
|
+
getUpdaterState: (e) => l().updaterState[e],
|
|
194
|
+
setUpdaterState: (e, r) => {
|
|
195
|
+
const t = l().updaterState;
|
|
196
|
+
!e || !r || o({ updaterState: { ...t ?? {}, [e]: r } });
|
|
197
|
+
},
|
|
198
|
+
getKeyState: (e) => l().cogsStateStore[e],
|
|
199
|
+
setState: (e, r) => {
|
|
200
|
+
o((t) => ({
|
|
201
|
+
cogsStateStore: {
|
|
202
|
+
...t.cogsStateStore,
|
|
203
|
+
[e]: typeof r == "function" ? r(t.cogsStateStore[e]) : r
|
|
204
|
+
}
|
|
205
|
+
}));
|
|
206
|
+
},
|
|
207
|
+
setInitialStates: (e) => {
|
|
208
|
+
o((r) => ({
|
|
209
|
+
cogsStateStore: {
|
|
210
|
+
...r.cogsStateStore,
|
|
211
|
+
...e
|
|
212
|
+
}
|
|
213
|
+
}));
|
|
214
|
+
},
|
|
215
|
+
syncInfoStore: /* @__PURE__ */ new Map(),
|
|
216
|
+
setSyncInfo: (e, r) => o((t) => {
|
|
217
|
+
const n = new Map(t.syncInfoStore);
|
|
218
|
+
return n.set(e, r), { ...t, syncInfoStore: n };
|
|
219
|
+
}),
|
|
220
|
+
getSyncInfo: (e) => l().syncInfoStore.get(e) || null
|
|
221
|
+
}));
|
|
222
|
+
export {
|
|
223
|
+
v as getGlobalStore
|
|
224
|
+
};
|
|
225
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sources":["../src/store.ts"],"sourcesContent":["import { create } from \"zustand\";\r\nimport type {\r\n OptionsType,\r\n StateKeys,\r\n SyncActionsType,\r\n SyncInfo,\r\n UpdateTypeDetail,\r\n} from \"./CogsState.js\";\r\n\r\ntype StateUpdater<StateValue> =\r\n | StateValue\r\n | ((prevValue: StateValue) => StateValue);\r\n\r\nexport type FreshValuesObject = {\r\n pathsToValues?: string[];\r\n prevValue?: any;\r\n newValue?: any;\r\n timeStamp: number;\r\n};\r\n\r\ntype SyncLogType = {\r\n timeStamp: number;\r\n};\r\ntype StateValue = any;\r\n\r\nexport type CogsGlobalState = {\r\n updaterState: { [key: string]: any };\r\n initialStateOptions: { [key: string]: OptionsType };\r\n cogsStateStore: { [key: string]: StateValue };\r\n isLoadingGlobal: { [key: string]: boolean };\r\n\r\n initialStateGlobal: { [key: string]: StateValue };\r\n validationErrors: Map<string, string[]>;\r\n\r\n serverState: { [key: string]: StateValue };\r\n serverSyncActions: { [key: string]: SyncActionsType<any> };\r\n\r\n serverSyncLog: { [key: string]: SyncLogType[] };\r\n serverSideOrNot: { [key: string]: boolean };\r\n setServerSyncLog: (key: string, newValue: SyncLogType) => void;\r\n\r\n setServerSideOrNot: (key: string, value: boolean) => void;\r\n getServerSideOrNot: (key: string) => boolean | undefined;\r\n setServerState: <StateKey extends StateKeys>(\r\n key: StateKey,\r\n value: StateValue,\r\n ) => void;\r\n\r\n getThisLocalUpdate: (key: string) => UpdateTypeDetail[] | undefined;\r\n setServerSyncActions: (key: string, value: SyncActionsType<any>) => void;\r\n addValidationError: (path: string, message: string) => void;\r\n getValidationErrors: (path: string) => string[];\r\n updateInitialStateGlobal: (key: string, newState: StateValue) => void;\r\n getInitialOptions: (key: string) => OptionsType | undefined;\r\n getUpdaterState: (key: string) => StateUpdater<StateValue>;\r\n setUpdaterState: (key: string, newUpdater: any) => void;\r\n getKeyState: <StateKey extends StateKeys>(key: StateKey) => StateValue;\r\n getNestedState: <StateKey extends StateKeys>(\r\n key: StateKey,\r\n path: string[],\r\n ) => StateValue;\r\n setState: <StateKey extends StateKeys>(\r\n key: StateKey,\r\n value: StateUpdater<StateValue>,\r\n ) => void;\r\n setInitialStates: (initialState: StateValue) => void;\r\n stateLog: { [key: string]: UpdateTypeDetail[] };\r\n setStateLog: (\r\n key: string,\r\n updater: (prevUpdates: UpdateTypeDetail[]) => UpdateTypeDetail[],\r\n ) => void;\r\n setIsLoadingGlobal: (key: string, value: boolean) => void;\r\n\r\n setInitialStateOptions: (key: string, value: OptionsType) => void;\r\n removeValidationError: (path: string) => void;\r\n signalDomElements: Map<\r\n string,\r\n Set<{ instanceId: string; parentId: string; position: number }>\r\n >;\r\n addSignalElement: (\r\n signalId: string,\r\n elementInfo: { instanceId: string; parentId: string; position: number },\r\n ) => void;\r\n removeSignalElement: (signalId: string, instanceId: string) => void;\r\n reRenderTriggerPrevValue: Record<string, any>;\r\n\r\n reactiveDeps: Record<\r\n string,\r\n {\r\n deps: any[];\r\n updaters: Set<() => void>;\r\n depsFunction: ((state: any) => any[] | true) | null;\r\n }\r\n >;\r\n setReactiveDeps: (\r\n key: string,\r\n record: {\r\n deps: any[];\r\n updaters: Set<() => void>;\r\n depsFunction: ((state: any) => any[] | true) | null;\r\n },\r\n ) => void;\r\n deleteReactiveDeps: (key: string) => void;\r\n subscribe: (listener: () => void) => () => void;\r\n\r\n stateComponents: Map<\r\n string,\r\n {\r\n components: Map<\r\n string,\r\n {\r\n forceUpdate: () => void;\r\n paths: Set<string>;\r\n deps?: any[];\r\n depsFunction?: (state: any) => any[] | true;\r\n }\r\n >;\r\n }\r\n >;\r\n syncInfoStore: Map<string, SyncInfo>;\r\n setSyncInfo: (key: string, syncInfo: SyncInfo) => void;\r\n getSyncInfo: (key: string) => SyncInfo | null;\r\n};\r\n\r\nexport const getGlobalStore = create<CogsGlobalState>((set, get) => ({\r\n stateComponents: new Map(),\r\n subscribe: (listener: () => void) => {\r\n // zustand's subscribe returns an unsubscribe function\r\n return get().subscribe(listener);\r\n },\r\n\r\n reactiveDeps: {},\r\n setReactiveDeps: (key, record) =>\r\n set((state) => ({\r\n ...state,\r\n reactiveDeps: {\r\n ...state.reactiveDeps,\r\n [key]: record,\r\n },\r\n })),\r\n deleteReactiveDeps: (key) =>\r\n set((state) => {\r\n const { [key]: _, ...rest } = state.reactiveDeps;\r\n return {\r\n ...state,\r\n reactiveDeps: rest,\r\n };\r\n }),\r\n\r\n reRenderTriggerPrevValue: {},\r\n signalDomElements: new Map(),\r\n addSignalElement: (\r\n signalId: string,\r\n elementInfo: { instanceId: string; parentId: string; position: number },\r\n ) => {\r\n console.log(\"Adding signal element\", signalId, elementInfo);\r\n const current = get().signalDomElements;\r\n if (!current.has(signalId)) {\r\n current.set(signalId, new Set());\r\n }\r\n current.get(signalId)!.add(elementInfo);\r\n console.log(\"After adding\", current.get(signalId));\r\n set({ signalDomElements: new Map(current) }); // Create new reference to trigger update\r\n },\r\n removeSignalElement: (signalId: string, instanceId: string) => {\r\n console.log(\"Removing signal element\", signalId, instanceId);\r\n const current = get().signalDomElements;\r\n const elements = current.get(signalId);\r\n if (elements) {\r\n elements.forEach((el) => {\r\n if (el.instanceId === instanceId) {\r\n elements.delete(el);\r\n }\r\n });\r\n }\r\n set({ signalDomElements: new Map(current) });\r\n },\r\n initialStateOptions: {},\r\n updaterState: {},\r\n stateTimeline: {},\r\n cogsStateStore: {},\r\n stateLog: {},\r\n isLoadingGlobal: {},\r\n\r\n initialStateGlobal: {},\r\n validationErrors: new Map(),\r\n\r\n serverState: {},\r\n\r\n serverSyncActions: {},\r\n\r\n serverSyncLog: {},\r\n serverSideOrNot: {},\r\n setServerSyncLog: (key, newValue) => {\r\n set((state) => ({\r\n serverSyncLog: {\r\n ...state.serverSyncLog,\r\n [key]: [...(state.serverSyncLog[key] ?? []), newValue],\r\n },\r\n }));\r\n },\r\n setServerSideOrNot: (key, value) => {\r\n set((state) => ({\r\n serverSideOrNot: {\r\n ...state.serverSideOrNot,\r\n [key]: value,\r\n },\r\n }));\r\n },\r\n getServerSideOrNot: (key) => {\r\n return get().serverSideOrNot[key];\r\n },\r\n\r\n getThisLocalUpdate: (key: string) => {\r\n return get().stateLog[key];\r\n },\r\n setServerState: <StateKey extends StateKeys>(\r\n key: StateKey,\r\n value: StateValue,\r\n ) => {\r\n set((prev) => ({\r\n serverState: {\r\n ...prev.serverState,\r\n [key]: value,\r\n },\r\n }));\r\n },\r\n\r\n setStateLog: (\r\n key: string,\r\n updater: (prevUpdates: UpdateTypeDetail[]) => UpdateTypeDetail[],\r\n ) => {\r\n set((prev) => {\r\n const currentUpdates = prev.stateLog[key] ?? [];\r\n const newUpdates = updater(currentUpdates);\r\n return {\r\n stateLog: {\r\n ...prev.stateLog,\r\n [key]: newUpdates,\r\n },\r\n };\r\n });\r\n },\r\n setIsLoadingGlobal: (key: string, value: boolean) => {\r\n set((prev) => ({\r\n isLoadingGlobal: {\r\n ...prev.isLoadingGlobal,\r\n [key]: value,\r\n },\r\n }));\r\n },\r\n setServerSyncActions: (key: string, value: SyncActionsType<any>) => {\r\n set((prev) => ({\r\n serverSyncActions: {\r\n ...prev.serverSyncActions,\r\n [key]: value,\r\n },\r\n }));\r\n },\r\n addValidationError: (path, message) => {\r\n set((prev) => {\r\n const updatedErrors = new Map(prev.validationErrors);\r\n\r\n const existingMessages = updatedErrors.get(path) || [];\r\n updatedErrors.set(path, [...existingMessages, message]);\r\n return { validationErrors: updatedErrors };\r\n });\r\n },\r\n removeValidationError: (path) => {\r\n set((prev) => {\r\n const updatedErrors = new Map(prev.validationErrors);\r\n console.log(\"updatedErrors\", updatedErrors);\r\n let doSomething = false;\r\n const pathArray = path.split(\".\");\r\n Array.from(updatedErrors.keys()).forEach((key) => {\r\n const keyArray = key.split(\".\");\r\n if (keyArray.length >= pathArray.length) {\r\n let match = true;\r\n for (let i = 0; i < pathArray.length; i++) {\r\n if (keyArray[i] !== pathArray[i]) {\r\n match = false;\r\n break;\r\n }\r\n }\r\n\r\n if (match) {\r\n doSomething = true;\r\n updatedErrors.delete(key);\r\n }\r\n }\r\n });\r\n\r\n return doSomething ? { validationErrors: updatedErrors } : prev;\r\n });\r\n },\r\n getValidationErrors: (path: string) => {\r\n const errors: string[] = [];\r\n const valErrors = get().validationErrors;\r\n const pathArray = path.split(\".\");\r\n\r\n // Helper to check if an index matches either a wildcard or is in an array of indices\r\n const isIndexMatch = (pathSegment: string, keySegment: string) => {\r\n if (pathSegment === \"[*]\") return true;\r\n if (Array.isArray(pathSegment)) {\r\n return pathSegment.includes(parseInt(keySegment));\r\n }\r\n return pathSegment === keySegment;\r\n };\r\n\r\n Array.from(valErrors.keys()).forEach((key) => {\r\n const keyArray = key.split(\".\");\r\n if (keyArray.length >= pathArray.length) {\r\n let match = true;\r\n for (let i = 0; i < pathArray.length; i++) {\r\n const pathSegment = pathArray[i];\r\n const keySegment = keyArray[i]!;\r\n\r\n // If current path segment is a number or [*], we need special handling\r\n if (pathSegment === \"[*]\" || Array.isArray(pathSegment)) {\r\n // Key segment should be a number if we're using [*] or array indices\r\n const keyIndex = parseInt(keySegment);\r\n if (isNaN(keyIndex)) {\r\n match = false;\r\n break;\r\n }\r\n\r\n if (!isIndexMatch(pathSegment, keySegment)) {\r\n match = false;\r\n break;\r\n }\r\n } else if (pathSegment !== keySegment) {\r\n match = false;\r\n break;\r\n }\r\n }\r\n\r\n if (match) {\r\n const errorMessages = valErrors.get(key);\r\n if (errorMessages) {\r\n errors.push(...errorMessages);\r\n }\r\n }\r\n }\r\n });\r\n\r\n return errors;\r\n },\r\n getInitialOptions: (key) => {\r\n return get().initialStateOptions[key];\r\n },\r\n getNestedState: (key: string, path: string[]) => {\r\n const rootState = get().cogsStateStore[key];\r\n\r\n const getValueWithAsterisk = (obj: any, pathArray: string[]): any => {\r\n if (pathArray.length === 0) return obj;\r\n\r\n const currentPath = pathArray[0];\r\n const remainingPath = pathArray.slice(1);\r\n\r\n if (currentPath === \"[*]\") {\r\n if (!Array.isArray(obj)) {\r\n console.warn(\"Asterisk notation used on non-array value\");\r\n return undefined;\r\n }\r\n\r\n if (remainingPath.length === 0) return obj;\r\n\r\n // Get result for each array item\r\n const results = obj.map((item) =>\r\n getValueWithAsterisk(item, remainingPath),\r\n );\r\n\r\n // If the next path segment exists and returns arrays, flatten them\r\n if (Array.isArray(results[0])) {\r\n return results.flat();\r\n }\r\n\r\n return results;\r\n }\r\n\r\n const value = obj[currentPath as keyof typeof obj];\r\n if (value === undefined) return undefined;\r\n\r\n return getValueWithAsterisk(value, remainingPath);\r\n };\r\n\r\n // This will still get the value but we need to make it reactive only to specific paths\r\n return getValueWithAsterisk(rootState, path);\r\n },\r\n setInitialStateOptions: (key, value) => {\r\n set((prev) => ({\r\n initialStateOptions: {\r\n ...prev.initialStateOptions,\r\n [key]: value,\r\n },\r\n }));\r\n },\r\n updateInitialStateGlobal: (key, newState) => {\r\n set((prev) => ({\r\n initialStateGlobal: {\r\n ...prev.initialStateGlobal,\r\n [key]: newState,\r\n },\r\n }));\r\n },\r\n getUpdaterState: (key) => {\r\n return get().updaterState[key];\r\n },\r\n setUpdaterState: (key, newUpdater) => {\r\n const current = get().updaterState;\r\n\r\n if (!key || !newUpdater) return;\r\n\r\n set({ updaterState: { ...(current ?? {}), [key]: newUpdater } });\r\n },\r\n getKeyState: <StateKey extends StateKeys>(key: StateKey) => {\r\n return get().cogsStateStore[key];\r\n },\r\n\r\n setState: <StateKey extends StateKeys>(\r\n key: StateKey,\r\n value: StateValue,\r\n ) => {\r\n set((prev) => {\r\n return {\r\n cogsStateStore: {\r\n ...prev.cogsStateStore,\r\n [key]:\r\n typeof value === \"function\"\r\n ? value(prev.cogsStateStore[key])\r\n : value,\r\n },\r\n };\r\n });\r\n },\r\n setInitialStates: <StateKey extends StateKeys>(\r\n initialState: StateValue,\r\n ) => {\r\n set((prev) => ({\r\n cogsStateStore: {\r\n ...prev.cogsStateStore,\r\n ...initialState,\r\n },\r\n }));\r\n },\r\n syncInfoStore: new Map<string, SyncInfo>(),\r\n setSyncInfo: (key: string, syncInfo: SyncInfo) =>\r\n set((state) => {\r\n const newMap = new Map(state.syncInfoStore);\r\n newMap.set(key, syncInfo);\r\n return { ...state, syncInfoStore: newMap };\r\n }),\r\n getSyncInfo: (key: string) => get().syncInfoStore.get(key) || null,\r\n}));\r\n"],"names":["getGlobalStore","create","set","get","listener","key","record","state","_","rest","signalId","elementInfo","current","instanceId","elements","el","newValue","value","prev","updater","currentUpdates","newUpdates","path","message","updatedErrors","existingMessages","doSomething","pathArray","keyArray","match","i","errors","valErrors","isIndexMatch","pathSegment","keySegment","keyIndex","errorMessages","rootState","getValueWithAsterisk","obj","currentPath","remainingPath","results","item","newState","newUpdater","initialState","syncInfo","newMap"],"mappings":";AA4HO,MAAMA,IAAiBC,EAAwB,CAACC,GAAKC,OAAS;AAAA,EACjE,qCAAqB,IAAI;AAAA,EACzB,WAAW,CAACC,MAEDD,EAAA,EAAM,UAAUC,CAAQ;AAAA,EAGnC,cAAc,CAAC;AAAA,EACf,iBAAiB,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;AAAA,EACA,aAAa,CAA6BzC,MAC/BF,EAAA,EAAM,eAAeE,CAAG;AAAA,EAGnC,UAAU,CACNA,GACAY,MACC;AACD,IAAAf,EAAI,CAACgB,OACM;AAAA,MACH,gBAAgB;AAAA,QACZ,GAAGA,EAAK;AAAA,QACR,CAACb,CAAG,GACA,OAAOY,KAAU,aACXA,EAAMC,EAAK,eAAeb,CAAG,CAAC,IAC9BY;AAAA,MAAA;AAAA,IAElB,EACH;AAAA,EACL;AAAA,EACA,kBAAkB,CACd8B,MACC;AACD,IAAA7C,EAAI,CAACgB,OAAU;AAAA,MACX,gBAAgB;AAAA,QACZ,GAAGA,EAAK;AAAA,QACR,GAAG6B;AAAA,MAAA;AAAA,IACP,EACF;AAAA,EACN;AAAA,EACA,mCAAmB,IAAsB;AAAA,EACzC,aAAa,CAAC1C,GAAa2C,MACvB9C,EAAI,CAACK,MAAU;AACX,UAAM0C,IAAS,IAAI,IAAI1C,EAAM,aAAa;AACnC,WAAA0C,EAAA,IAAI5C,GAAK2C,CAAQ,GACjB,EAAE,GAAGzC,GAAO,eAAe0C,EAAO;AAAA,EAAA,CAC5C;AAAA,EACL,aAAa,CAAC5C,MAAgBF,EAAA,EAAM,cAAc,IAAIE,CAAG,KAAK;AAClE,EAAE;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { EffectiveSetState, FormElementParmas, FormOptsType, UpdateArg } from './CogsState';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
import { getGlobalStore } from './store';
|
|
4
|
+
|
|
5
|
+
export declare function updateFn<U>(setState: EffectiveSetState<U>, payload: UpdateArg<U>, path: string[], validationKey?: string): void;
|
|
6
|
+
export declare function pushFunc<U>(setState: EffectiveSetState<U>, payload: UpdateArg<U>, path: string[], stateKey: string, index?: number): void;
|
|
7
|
+
export declare function cutFunc<U>(setState: EffectiveSetState<U>, path: string[], stateKey: string, index: number): void;
|
|
8
|
+
export declare const useStoreSubscription: <T>(fullPath: string, selector: (store: ReturnType<typeof getGlobalStore.getState>, path: string) => T, compare?: (a: T, b: T) => boolean) => T;
|
|
9
|
+
export declare const useGetValidationErrors: (validationKey: string, path: string[], validIndices?: number[]) => string[];
|
|
10
|
+
export declare const useGetSyncInfo: (key: string, path: string[]) => import('./CogsState').SyncInfo | null;
|
|
11
|
+
export declare const useGetKeyState: (key: string, path: string[]) => any;
|
|
12
|
+
interface FormControlComponentProps<TStateObject> {
|
|
13
|
+
setState: EffectiveSetState<TStateObject>;
|
|
14
|
+
validationKey: string;
|
|
15
|
+
path: string[];
|
|
16
|
+
child: (obj: FormElementParmas<TStateObject>) => JSX.Element;
|
|
17
|
+
formOpts?: FormOptsType;
|
|
18
|
+
stateKey: string;
|
|
19
|
+
}
|
|
20
|
+
export declare const FormControlComponent: <TStateObject>({ setState, validationKey, path, child, formOpts, stateKey, }: FormControlComponentProps<TStateObject>) => import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export declare function ValidationWrapper({ formOpts, path, validationKey, stateKey, children, validIndices, }: {
|
|
22
|
+
formOpts?: FormOptsType;
|
|
23
|
+
path: string[];
|
|
24
|
+
validationKey: string;
|
|
25
|
+
stateKey?: string;
|
|
26
|
+
children: React.ReactNode;
|
|
27
|
+
validIndices?: number[];
|
|
28
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
export {};
|