CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
middleware.development.js593 linesDownload Raw Back to system
1System.register([], (function (exports) {2  'use strict';3  return {4    execute: (function () {5 6      exports("createJSONStorage", createJSONStorage);7 8      const reduxImpl = (reducer, initial) => (set, _get, api) => {9        api.dispatch = (action) => {10          set((state) => reducer(state, action), false, action);11          return action;12        };13        api.dispatchFromDevtools = true;14        return { dispatch: (...a) => api.dispatch(...a), ...initial };15      };16      const redux = exports("redux", reduxImpl);17 18      const trackedConnections = /* @__PURE__ */ new Map();19      const getTrackedConnectionState = (name) => {20        const api = trackedConnections.get(name);21        if (!api) return {};22        return Object.fromEntries(23          Object.entries(api.stores).map(([key, api2]) => [key, api2.getState()])24        );25      };26      const extractConnectionInformation = (store, extensionConnector, options) => {27        if (store === void 0) {28          return {29            type: "untracked",30            connection: extensionConnector.connect(options)31          };32        }33        const existingConnection = trackedConnections.get(options.name);34        if (existingConnection) {35          return { type: "tracked", store, ...existingConnection };36        }37        const newConnection = {38          connection: extensionConnector.connect(options),39          stores: {}40        };41        trackedConnections.set(options.name, newConnection);42        return { type: "tracked", store, ...newConnection };43      };44      const devtoolsImpl = (fn, devtoolsOptions = {}) => (set, get, api) => {45        const { enabled, anonymousActionType, store, ...options } = devtoolsOptions;46        let extensionConnector;47        try {48          extensionConnector = (enabled != null ? enabled : true) && window.__REDUX_DEVTOOLS_EXTENSION__;49        } catch (_e) {50        }51        if (!extensionConnector) {52          if (enabled) {53            console.warn(54              "[zustand devtools middleware] Please install/enable Redux devtools extension"55            );56          }57          return fn(set, get, api);58        }59        const { connection, ...connectionInformation } = extractConnectionInformation(store, extensionConnector, options);60        let isRecording = true;61        api.setState = (state, replace, nameOrAction) => {62          const r = set(state, replace);63          if (!isRecording) return r;64          const action = nameOrAction === void 0 ? { type: anonymousActionType || "anonymous" } : typeof nameOrAction === "string" ? { type: nameOrAction } : nameOrAction;65          if (store === void 0) {66            connection == null ? void 0 : connection.send(action, get());67            return r;68          }69          connection == null ? void 0 : connection.send(70            {71              ...action,72              type: `${store}/${action.type}`73            },74            {75              ...getTrackedConnectionState(options.name),76              [store]: api.getState()77            }78          );79          return r;80        };81        const setStateFromDevtools = (...a) => {82          const originalIsRecording = isRecording;83          isRecording = false;84          set(...a);85          isRecording = originalIsRecording;86        };87        const initialState = fn(api.setState, get, api);88        if (connectionInformation.type === "untracked") {89          connection == null ? void 0 : connection.init(initialState);90        } else {91          connectionInformation.stores[connectionInformation.store] = api;92          connection == null ? void 0 : connection.init(93            Object.fromEntries(94              Object.entries(connectionInformation.stores).map(([key, store2]) => [95                key,96                key === connectionInformation.store ? initialState : store2.getState()97              ])98            )99          );100        }101        if (api.dispatchFromDevtools && typeof api.dispatch === "function") {102          let didWarnAboutReservedActionType = false;103          const originalDispatch = api.dispatch;104          api.dispatch = (...a) => {105            if (a[0].type === "__setState" && !didWarnAboutReservedActionType) {106              console.warn(107                '[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'108              );109              didWarnAboutReservedActionType = true;110            }111            originalDispatch(...a);112          };113        }114        connection.subscribe((message) => {115          var _a;116          switch (message.type) {117            case "ACTION":118              if (typeof message.payload !== "string") {119                console.error(120                  "[zustand devtools middleware] Unsupported action format"121                );122                return;123              }124              return parseJsonThen(125                message.payload,126                (action) => {127                  if (action.type === "__setState") {128                    if (store === void 0) {129                      setStateFromDevtools(action.state);130                      return;131                    }132                    if (Object.keys(action.state).length !== 1) {133                      console.error(134                        `135                    [zustand devtools middleware] Unsupported __setState action format. 136                    When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),137                    and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }138                    `139                      );140                    }141                    const stateFromDevtools = action.state[store];142                    if (stateFromDevtools === void 0 || stateFromDevtools === null) {143                      return;144                    }145                    if (JSON.stringify(api.getState()) !== JSON.stringify(stateFromDevtools)) {146                      setStateFromDevtools(stateFromDevtools);147                    }148                    return;149                  }150                  if (!api.dispatchFromDevtools) return;151                  if (typeof api.dispatch !== "function") return;152                  api.dispatch(action);153                }154              );155            case "DISPATCH":156              switch (message.payload.type) {157                case "RESET":158                  setStateFromDevtools(initialState);159                  if (store === void 0) {160                    return connection == null ? void 0 : connection.init(api.getState());161                  }162                  return connection == null ? void 0 : connection.init(getTrackedConnectionState(options.name));163                case "COMMIT":164                  if (store === void 0) {165                    connection == null ? void 0 : connection.init(api.getState());166                    return;167                  }168                  return connection == null ? void 0 : connection.init(getTrackedConnectionState(options.name));169                case "ROLLBACK":170                  return parseJsonThen(message.state, (state) => {171                    if (store === void 0) {172                      setStateFromDevtools(state);173                      connection == null ? void 0 : connection.init(api.getState());174                      return;175                    }176                    setStateFromDevtools(state[store]);177                    connection == null ? void 0 : connection.init(getTrackedConnectionState(options.name));178                  });179                case "JUMP_TO_STATE":180                case "JUMP_TO_ACTION":181                  return parseJsonThen(message.state, (state) => {182                    if (store === void 0) {183                      setStateFromDevtools(state);184                      return;185                    }186                    if (JSON.stringify(api.getState()) !== JSON.stringify(state[store])) {187                      setStateFromDevtools(state[store]);188                    }189                  });190                case "IMPORT_STATE": {191                  const { nextLiftedState } = message.payload;192                  const lastComputedState = (_a = nextLiftedState.computedStates.slice(-1)[0]) == null ? void 0 : _a.state;193                  if (!lastComputedState) return;194                  if (store === void 0) {195                    setStateFromDevtools(lastComputedState);196                  } else {197                    setStateFromDevtools(lastComputedState[store]);198                  }199                  connection == null ? void 0 : connection.send(200                    null,201                    // FIXME no-any202                    nextLiftedState203                  );204                  return;205                }206                case "PAUSE_RECORDING":207                  return isRecording = !isRecording;208              }209              return;210          }211        });212        return initialState;213      };214      const devtools = exports("devtools", devtoolsImpl);215      const parseJsonThen = (stringified, f) => {216        let parsed;217        try {218          parsed = JSON.parse(stringified);219        } catch (e) {220          console.error(221            "[zustand devtools middleware] Could not parse the received json",222            e223          );224        }225        if (parsed !== void 0) f(parsed);226      };227 228      const subscribeWithSelectorImpl = (fn) => (set, get, api) => {229        const origSubscribe = api.subscribe;230        api.subscribe = (selector, optListener, options) => {231          let listener = selector;232          if (optListener) {233            const equalityFn = (options == null ? void 0 : options.equalityFn) || Object.is;234            let currentSlice = selector(api.getState());235            listener = (state) => {236              const nextSlice = selector(state);237              if (!equalityFn(currentSlice, nextSlice)) {238                const previousSlice = currentSlice;239                optListener(currentSlice = nextSlice, previousSlice);240              }241            };242            if (options == null ? void 0 : options.fireImmediately) {243              optListener(currentSlice, currentSlice);244            }245          }246          return origSubscribe(listener);247        };248        const initialState = fn(set, get, api);249        return initialState;250      };251      const subscribeWithSelector = exports("subscribeWithSelector", subscribeWithSelectorImpl);252 253      const combine = exports("combine", (initialState, create) => (...a) => Object.assign({}, initialState, create(...a)));254 255      function createJSONStorage(getStorage, options) {256        let storage;257        try {258          storage = getStorage();259        } catch (_e) {260          return;261        }262        const persistStorage = {263          getItem: (name) => {264            var _a;265            const parse = (str2) => {266              if (str2 === null) {267                return null;268              }269              return JSON.parse(str2, options == null ? void 0 : options.reviver);270            };271            const str = (_a = storage.getItem(name)) != null ? _a : null;272            if (str instanceof Promise) {273              return str.then(parse);274            }275            return parse(str);276          },277          setItem: (name, newValue) => storage.setItem(278            name,279            JSON.stringify(newValue, options == null ? void 0 : options.replacer)280          ),281          removeItem: (name) => storage.removeItem(name)282        };283        return persistStorage;284      }285      const toThenable = (fn) => (input) => {286        try {287          const result = fn(input);288          if (result instanceof Promise) {289            return result;290          }291          return {292            then(onFulfilled) {293              return toThenable(onFulfilled)(result);294            },295            catch(_onRejected) {296              return this;297            }298          };299        } catch (e) {300          return {301            then(_onFulfilled) {302              return this;303            },304            catch(onRejected) {305              return toThenable(onRejected)(e);306            }307          };308        }309      };310      const oldImpl = (config, baseOptions) => (set, get, api) => {311        let options = {312          getStorage: () => localStorage,313          serialize: JSON.stringify,314          deserialize: JSON.parse,315          partialize: (state) => state,316          version: 0,317          merge: (persistedState, currentState) => ({318            ...currentState,319            ...persistedState320          }),321          ...baseOptions322        };323        let hasHydrated = false;324        const hydrationListeners = /* @__PURE__ */ new Set();325        const finishHydrationListeners = /* @__PURE__ */ new Set();326        let storage;327        try {328          storage = options.getStorage();329        } catch (_e) {330        }331        if (!storage) {332          return config(333            (...args) => {334              console.warn(335                `[zustand persist middleware] Unable to update item '${options.name}', the given storage is currently unavailable.`336              );337              set(...args);338            },339            get,340            api341          );342        }343        const thenableSerialize = toThenable(options.serialize);344        const setItem = () => {345          const state = options.partialize({ ...get() });346          let errorInSync;347          const thenable = thenableSerialize({ state, version: options.version }).then(348            (serializedValue) => storage.setItem(options.name, serializedValue)349          ).catch((e) => {350            errorInSync = e;351          });352          if (errorInSync) {353            throw errorInSync;354          }355          return thenable;356        };357        const savedSetState = api.setState;358        api.setState = (state, replace) => {359          savedSetState(state, replace);360          void setItem();361        };362        const configResult = config(363          (...args) => {364            set(...args);365            void setItem();366          },367          get,368          api369        );370        let stateFromStorage;371        const hydrate = () => {372          var _a;373          if (!storage) return;374          hasHydrated = false;375          hydrationListeners.forEach((cb) => cb(get()));376          const postRehydrationCallback = ((_a = options.onRehydrateStorage) == null ? void 0 : _a.call(options, get())) || void 0;377          return toThenable(storage.getItem.bind(storage))(options.name).then((storageValue) => {378            if (storageValue) {379              return options.deserialize(storageValue);380            }381          }).then((deserializedStorageValue) => {382            if (deserializedStorageValue) {383              if (typeof deserializedStorageValue.version === "number" && deserializedStorageValue.version !== options.version) {384                if (options.migrate) {385                  return options.migrate(386                    deserializedStorageValue.state,387                    deserializedStorageValue.version388                  );389                }390                console.error(391                  `State loaded from storage couldn't be migrated since no migrate function was provided`392                );393              } else {394                return deserializedStorageValue.state;395              }396            }397          }).then((migratedState) => {398            var _a2;399            stateFromStorage = options.merge(400              migratedState,401              (_a2 = get()) != null ? _a2 : configResult402            );403            set(stateFromStorage, true);404            return setItem();405          }).then(() => {406            postRehydrationCallback == null ? void 0 : postRehydrationCallback(stateFromStorage, void 0);407            hasHydrated = true;408            finishHydrationListeners.forEach((cb) => cb(stateFromStorage));409          }).catch((e) => {410            postRehydrationCallback == null ? void 0 : postRehydrationCallback(void 0, e);411          });412        };413        api.persist = {414          setOptions: (newOptions) => {415            options = {416              ...options,417              ...newOptions418            };419            if (newOptions.getStorage) {420              storage = newOptions.getStorage();421            }422          },423          clearStorage: () => {424            storage == null ? void 0 : storage.removeItem(options.name);425          },426          getOptions: () => options,427          rehydrate: () => hydrate(),428          hasHydrated: () => hasHydrated,429          onHydrate: (cb) => {430            hydrationListeners.add(cb);431            return () => {432              hydrationListeners.delete(cb);433            };434          },435          onFinishHydration: (cb) => {436            finishHydrationListeners.add(cb);437            return () => {438              finishHydrationListeners.delete(cb);439            };440          }441        };442        hydrate();443        return stateFromStorage || configResult;444      };445      const newImpl = (config, baseOptions) => (set, get, api) => {446        let options = {447          storage: createJSONStorage(() => localStorage),448          partialize: (state) => state,449          version: 0,450          merge: (persistedState, currentState) => ({451            ...currentState,452            ...persistedState453          }),454          ...baseOptions455        };456        let hasHydrated = false;457        const hydrationListeners = /* @__PURE__ */ new Set();458        const finishHydrationListeners = /* @__PURE__ */ new Set();459        let storage = options.storage;460        if (!storage) {461          return config(462            (...args) => {463              console.warn(464                `[zustand persist middleware] Unable to update item '${options.name}', the given storage is currently unavailable.`465              );466              set(...args);467            },468            get,469            api470          );471        }472        const setItem = () => {473          const state = options.partialize({ ...get() });474          return storage.setItem(options.name, {475            state,476            version: options.version477          });478        };479        const savedSetState = api.setState;480        api.setState = (state, replace) => {481          savedSetState(state, replace);482          void setItem();483        };484        const configResult = config(485          (...args) => {486            set(...args);487            void setItem();488          },489          get,490          api491        );492        api.getInitialState = () => configResult;493        let stateFromStorage;494        const hydrate = () => {495          var _a, _b;496          if (!storage) return;497          hasHydrated = false;498          hydrationListeners.forEach((cb) => {499            var _a2;500            return cb((_a2 = get()) != null ? _a2 : configResult);501          });502          const postRehydrationCallback = ((_b = options.onRehydrateStorage) == null ? void 0 : _b.call(options, (_a = get()) != null ? _a : configResult)) || void 0;503          return toThenable(storage.getItem.bind(storage))(options.name).then((deserializedStorageValue) => {504            if (deserializedStorageValue) {505              if (typeof deserializedStorageValue.version === "number" && deserializedStorageValue.version !== options.version) {506                if (options.migrate) {507                  return [508                    true,509                    options.migrate(510                      deserializedStorageValue.state,511                      deserializedStorageValue.version512                    )513                  ];514                }515                console.error(516                  `State loaded from storage couldn't be migrated since no migrate function was provided`517                );518              } else {519                return [false, deserializedStorageValue.state];520              }521            }522            return [false, void 0];523          }).then((migrationResult) => {524            var _a2;525            const [migrated, migratedState] = migrationResult;526            stateFromStorage = options.merge(527              migratedState,528              (_a2 = get()) != null ? _a2 : configResult529            );530            set(stateFromStorage, true);531            if (migrated) {532              return setItem();533            }534          }).then(() => {535            postRehydrationCallback == null ? void 0 : postRehydrationCallback(stateFromStorage, void 0);536            stateFromStorage = get();537            hasHydrated = true;538            finishHydrationListeners.forEach((cb) => cb(stateFromStorage));539          }).catch((e) => {540            postRehydrationCallback == null ? void 0 : postRehydrationCallback(void 0, e);541          });542        };543        api.persist = {544          setOptions: (newOptions) => {545            options = {546              ...options,547              ...newOptions548            };549            if (newOptions.storage) {550              storage = newOptions.storage;551            }552          },553          clearStorage: () => {554            storage == null ? void 0 : storage.removeItem(options.name);555          },556          getOptions: () => options,557          rehydrate: () => hydrate(),558          hasHydrated: () => hasHydrated,559          onHydrate: (cb) => {560            hydrationListeners.add(cb);561            return () => {562              hydrationListeners.delete(cb);563            };564          },565          onFinishHydration: (cb) => {566            finishHydrationListeners.add(cb);567            return () => {568              finishHydrationListeners.delete(cb);569            };570          }571        };572        if (!options.skipHydration) {573          hydrate();574        }575        return stateFromStorage || configResult;576      };577      const persistImpl = (config, baseOptions) => {578        if ("getStorage" in baseOptions || "serialize" in baseOptions || "deserialize" in baseOptions) {579          {580            console.warn(581              "[DEPRECATED] `getStorage`, `serialize` and `deserialize` options are deprecated. Use `storage` option instead."582            );583          }584          return oldImpl(config, baseOptions);585        }586        return newImpl(config, baseOptions);587      };588      const persist = exports("persist", persistImpl);589 590    })591  };592}));593