@me1a/ui 1.2.12 → 1.2.13

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.
@@ -1,3 +1,6 @@
1
+ import * as ReactOriginal from 'react';
2
+ import ReactOriginal__default, { useContext, useEffect, useCallback, useMemo, useDebugValue, useState, useRef, useLayoutEffect } from 'react';
3
+
1
4
  // src/utils/formatProdErrorMessage.ts
2
5
  function formatProdErrorMessage$1(code) {
3
6
  return `Minified Redux error #${code}; visit https://redux.js.org/Errors?code=${code} for the full message or use the non-minified dev environment for full errors. `;
@@ -488,7 +491,7 @@ function set(thing, propOrOldValue, value) {
488
491
  } else
489
492
  thing[propOrOldValue] = value;
490
493
  }
491
- function is(x, y) {
494
+ function is$1(x, y) {
492
495
  if (x === y) {
493
496
  return x !== 0 || 1 / x === 1 / y;
494
497
  } else {
@@ -802,7 +805,7 @@ var objectTraps = {
802
805
  state.assigned_[prop] = false;
803
806
  return true;
804
807
  }
805
- if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
808
+ if (is$1(value, current2) && (value !== void 0 || has(state.base_, prop)))
806
809
  return true;
807
810
  prepareCopy(state);
808
811
  markChanged(state);
@@ -3993,7 +3996,7 @@ function copyWithStructuralSharing(oldObj, newObj) {
3993
3996
  }
3994
3997
 
3995
3998
  // src/query/utils/countObjectKeys.ts
3996
- function countObjectKeys(obj) {
3999
+ function countObjectKeys$1(obj) {
3997
4000
  let count = 0;
3998
4001
  for (const _key in obj) {
3999
4002
  count++;
@@ -4321,10 +4324,10 @@ function setupListeners(dispatch, customHandler) {
4321
4324
  }
4322
4325
 
4323
4326
  // src/query/endpointDefinitions.ts
4324
- function isQueryDefinition(e) {
4327
+ function isQueryDefinition$1(e) {
4325
4328
  return e.type === "query" /* query */;
4326
4329
  }
4327
- function isMutationDefinition(e) {
4330
+ function isMutationDefinition$1(e) {
4328
4331
  return e.type === "mutation" /* mutation */;
4329
4332
  }
4330
4333
  function calculateProvidedBy(description, result, error, queryArg, meta, assertTagTypes) {
@@ -4494,7 +4497,7 @@ You must add the middleware for RTK-Query to function correctly!`);
4494
4497
  runningQueries.set(dispatch, running);
4495
4498
  statePromise.then(() => {
4496
4499
  delete running[queryCacheKey];
4497
- if (!countObjectKeys(running)) {
4500
+ if (!countObjectKeys$1(running)) {
4498
4501
  runningQueries.delete(dispatch);
4499
4502
  }
4500
4503
  });
@@ -4545,7 +4548,7 @@ You must add the middleware for RTK-Query to function correctly!`);
4545
4548
  running[requestId] = ret;
4546
4549
  ret.then(() => {
4547
4550
  delete running[requestId];
4548
- if (!countObjectKeys(running)) {
4551
+ if (!countObjectKeys$1(running)) {
4549
4552
  runningMutations.delete(dispatch);
4550
4553
  }
4551
4554
  });
@@ -4554,7 +4557,7 @@ You must add the middleware for RTK-Query to function correctly!`);
4554
4557
  ret.then(() => {
4555
4558
  if (running[fixedCacheKey] === ret) {
4556
4559
  delete running[fixedCacheKey];
4557
- if (!countObjectKeys(running)) {
4560
+ if (!countObjectKeys$1(running)) {
4558
4561
  runningMutations.delete(dispatch);
4559
4562
  }
4560
4563
  }
@@ -4780,7 +4783,7 @@ In the case of an unhandled error, no tags will be "provided" or "invalidated".`
4780
4783
  if (isForcedQuery(queryThunkArgs, state)) {
4781
4784
  return true;
4782
4785
  }
4783
- if (isQueryDefinition(endpointDefinition) && endpointDefinition?.forceRefetch?.({
4786
+ if (isQueryDefinition$1(endpointDefinition) && endpointDefinition?.forceRefetch?.({
4784
4787
  currentArg,
4785
4788
  previousArg,
4786
4789
  endpointState: requestState,
@@ -5384,13 +5387,13 @@ function buildSelectors({
5384
5387
  }
5385
5388
 
5386
5389
  // src/query/defaultSerializeQueryArgs.ts
5387
- var cache = WeakMap ? /* @__PURE__ */ new WeakMap() : void 0;
5388
- var defaultSerializeQueryArgs = ({
5390
+ var cache$1 = WeakMap ? /* @__PURE__ */ new WeakMap() : void 0;
5391
+ var defaultSerializeQueryArgs$1 = ({
5389
5392
  endpointName,
5390
5393
  queryArgs
5391
5394
  }) => {
5392
5395
  let serialized = "";
5393
- const cached = cache?.get(queryArgs);
5396
+ const cached = cache$1?.get(queryArgs);
5394
5397
  if (typeof cached === "string") {
5395
5398
  serialized = cached;
5396
5399
  } else {
@@ -5405,7 +5408,7 @@ var defaultSerializeQueryArgs = ({
5405
5408
  return value;
5406
5409
  });
5407
5410
  if (isPlainObject$1(queryArgs)) {
5408
- cache?.set(queryArgs, stringified);
5411
+ cache$1?.set(queryArgs, stringified);
5409
5412
  }
5410
5413
  serialized = stringified;
5411
5414
  }
@@ -5426,7 +5429,7 @@ function buildCreateApi(...modules) {
5426
5429
  ...options,
5427
5430
  extractRehydrationInfo,
5428
5431
  serializeQueryArgs(queryArgsApi) {
5429
- let finalSerializeQueryArgs = defaultSerializeQueryArgs;
5432
+ let finalSerializeQueryArgs = defaultSerializeQueryArgs$1;
5430
5433
  if ("serializeQueryArgs" in queryArgsApi.endpointDefinition) {
5431
5434
  const endpointSQA = queryArgsApi.endpointDefinition.serializeQueryArgs;
5432
5435
  finalSerializeQueryArgs = (queryArgsApi2) => {
@@ -5434,7 +5437,7 @@ function buildCreateApi(...modules) {
5434
5437
  if (typeof initialResult === "string") {
5435
5438
  return initialResult;
5436
5439
  } else {
5437
- return defaultSerializeQueryArgs({
5440
+ return defaultSerializeQueryArgs$1({
5438
5441
  ...queryArgsApi2,
5439
5442
  queryArgs: initialResult
5440
5443
  });
@@ -5520,7 +5523,7 @@ function fakeBaseQuery() {
5520
5523
  throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(33) : "When using `fakeBaseQuery`, all queries & mutations must use the `queryFn` definition syntax.");
5521
5524
  };
5522
5525
  }
5523
- function safeAssign(target, ...args) {
5526
+ function safeAssign$1(target, ...args) {
5524
5527
  return Object.assign(target, ...args);
5525
5528
  }
5526
5529
  var buildBatchedActionsHandler = ({
@@ -5602,7 +5605,7 @@ var buildBatchedActionsHandler = ({
5602
5605
  const getSubscriptionCount = (queryCacheKey) => {
5603
5606
  const subscriptions = getSubscriptions();
5604
5607
  const subscriptionsForQueryArg = subscriptions[queryCacheKey] ?? {};
5605
- return countObjectKeys(subscriptionsForQueryArg);
5608
+ return countObjectKeys$1(subscriptionsForQueryArg);
5606
5609
  };
5607
5610
  const isRequestSubscribed = (queryCacheKey, requestId) => {
5608
5611
  const subscriptions = getSubscriptions();
@@ -5922,7 +5925,7 @@ var buildInvalidationByTagsHandler = ({
5922
5925
  const querySubState = state.queries[queryCacheKey];
5923
5926
  const subscriptionSubState = internalState.currentSubscriptions[queryCacheKey] ?? {};
5924
5927
  if (querySubState) {
5925
- if (countObjectKeys(subscriptionSubState) === 0) {
5928
+ if (countObjectKeys$1(subscriptionSubState) === 0) {
5926
5929
  mwApi.dispatch(removeQueryResult({
5927
5930
  queryCacheKey
5928
5931
  }));
@@ -6143,7 +6146,7 @@ var buildWindowEventHandler = ({
6143
6146
  if (!subscriptionSubState || !querySubState) continue;
6144
6147
  const shouldRefetch = Object.values(subscriptionSubState).some((sub) => sub[type] === true) || Object.values(subscriptionSubState).every((sub) => sub[type] === void 0) && state.config[type];
6145
6148
  if (shouldRefetch) {
6146
- if (countObjectKeys(subscriptionSubState) === 0) {
6149
+ if (countObjectKeys$1(subscriptionSubState) === 0) {
6147
6150
  api2.dispatch(removeQueryResult({
6148
6151
  queryCacheKey
6149
6152
  }));
@@ -6304,7 +6307,7 @@ var coreModule = ({
6304
6307
  invalidationBehavior
6305
6308
  }
6306
6309
  });
6307
- safeAssign(api.util, {
6310
+ safeAssign$1(api.util, {
6308
6311
  patchQueryData,
6309
6312
  updateQueryData,
6310
6313
  upsertQueryData,
@@ -6312,7 +6315,7 @@ var coreModule = ({
6312
6315
  resetApiState: sliceActions.resetApiState,
6313
6316
  upsertQueryEntries: sliceActions.cacheEntriesUpserted
6314
6317
  });
6315
- safeAssign(api.internalActions, sliceActions);
6318
+ safeAssign$1(api.internalActions, sliceActions);
6316
6319
  const {
6317
6320
  middleware,
6318
6321
  actions: middlewareActions
@@ -6324,8 +6327,8 @@ var coreModule = ({
6324
6327
  api,
6325
6328
  assertTagType
6326
6329
  });
6327
- safeAssign(api.util, middlewareActions);
6328
- safeAssign(api, {
6330
+ safeAssign$1(api.util, middlewareActions);
6331
+ safeAssign$1(api, {
6329
6332
  reducer,
6330
6333
  middleware
6331
6334
  });
@@ -6339,7 +6342,7 @@ var coreModule = ({
6339
6342
  reducerPath,
6340
6343
  createSelector: createSelector2
6341
6344
  });
6342
- safeAssign(api.util, {
6345
+ safeAssign$1(api.util, {
6343
6346
  selectInvalidatedBy,
6344
6347
  selectCachedArgsForQuery
6345
6348
  });
@@ -6357,7 +6360,7 @@ var coreModule = ({
6357
6360
  serializeQueryArgs,
6358
6361
  context
6359
6362
  });
6360
- safeAssign(api.util, {
6363
+ safeAssign$1(api.util, {
6361
6364
  getRunningMutationThunk,
6362
6365
  getRunningMutationsThunk,
6363
6366
  getRunningQueryThunk,
@@ -6368,14 +6371,14 @@ var coreModule = ({
6368
6371
  injectEndpoint(endpointName, definition) {
6369
6372
  const anyApi = api;
6370
6373
  anyApi.endpoints[endpointName] ??= {};
6371
- if (isQueryDefinition(definition)) {
6372
- safeAssign(anyApi.endpoints[endpointName], {
6374
+ if (isQueryDefinition$1(definition)) {
6375
+ safeAssign$1(anyApi.endpoints[endpointName], {
6373
6376
  name: endpointName,
6374
6377
  select: buildQuerySelector(endpointName, definition),
6375
6378
  initiate: buildInitiateQuery(endpointName, definition)
6376
6379
  }, buildMatchThunkActions(queryThunk, endpointName));
6377
- } else if (isMutationDefinition(definition)) {
6378
- safeAssign(anyApi.endpoints[endpointName], {
6380
+ } else if (isMutationDefinition$1(definition)) {
6381
+ safeAssign$1(anyApi.endpoints[endpointName], {
6379
6382
  name: endpointName,
6380
6383
  select: buildMutationSelector(),
6381
6384
  initiate: buildInitiateMutation(endpointName)
@@ -6386,25 +6389,1201 @@ var coreModule = ({
6386
6389
  }
6387
6390
  });
6388
6391
 
6389
- // src/query/core/index.ts
6390
- var createApi = /* @__PURE__ */ buildCreateApi(coreModule());
6392
+ var withSelector = {exports: {}};
6393
+
6394
+ var useSyncExternalStoreWithSelector_production_min = {};
6395
+
6396
+ /**
6397
+ * @license React
6398
+ * use-sync-external-store-with-selector.production.min.js
6399
+ *
6400
+ * Copyright (c) Facebook, Inc. and its affiliates.
6401
+ *
6402
+ * This source code is licensed under the MIT license found in the
6403
+ * LICENSE file in the root directory of this source tree.
6404
+ */
6405
+
6406
+ var hasRequiredUseSyncExternalStoreWithSelector_production_min;
6407
+
6408
+ function requireUseSyncExternalStoreWithSelector_production_min () {
6409
+ if (hasRequiredUseSyncExternalStoreWithSelector_production_min) return useSyncExternalStoreWithSelector_production_min;
6410
+ hasRequiredUseSyncExternalStoreWithSelector_production_min = 1;
6411
+ var g=ReactOriginal__default;function n(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var p="function"===typeof Object.is?Object.is:n,q=g.useSyncExternalStore,r=g.useRef,t=g.useEffect,u=g.useMemo,v=g.useDebugValue;
6412
+ useSyncExternalStoreWithSelector_production_min.useSyncExternalStoreWithSelector=function(a,b,e,l,h){var c=r(null);if(null===c.current){var f={hasValue:!1,value:null};c.current=f;}else f=c.current;c=u(function(){function a(a){if(!c){c=!0;d=a;a=l(a);if(void 0!==h&&f.hasValue){var b=f.value;if(h(b,a))return k=b}return k=a}b=k;if(p(d,a))return b;var e=l(a);if(void 0!==h&&h(b,e))return b;d=a;return k=e}var c=!1,d,k,m=void 0===e?null:e;return [function(){return a(b())},null===m?void 0:function(){return a(m())}]},[b,e,l,h]);var d=q(a,c[0],c[1]);
6413
+ t(function(){f.hasValue=!0;f.value=d;},[d]);v(d);return d};
6414
+ return useSyncExternalStoreWithSelector_production_min;
6415
+ }
6416
+
6417
+ var useSyncExternalStoreWithSelector_development = {};
6418
+
6419
+ /**
6420
+ * @license React
6421
+ * use-sync-external-store-with-selector.development.js
6422
+ *
6423
+ * Copyright (c) Facebook, Inc. and its affiliates.
6424
+ *
6425
+ * This source code is licensed under the MIT license found in the
6426
+ * LICENSE file in the root directory of this source tree.
6427
+ */
6428
+
6429
+ var hasRequiredUseSyncExternalStoreWithSelector_development;
6430
+
6431
+ function requireUseSyncExternalStoreWithSelector_development () {
6432
+ if (hasRequiredUseSyncExternalStoreWithSelector_development) return useSyncExternalStoreWithSelector_development;
6433
+ hasRequiredUseSyncExternalStoreWithSelector_development = 1;
6434
+
6435
+ if (process.env.NODE_ENV !== "production") {
6436
+ (function() {
6437
+
6438
+ /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
6439
+ if (
6440
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
6441
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
6442
+ 'function'
6443
+ ) {
6444
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
6445
+ }
6446
+ var React = ReactOriginal__default;
6447
+
6448
+ /**
6449
+ * inlined Object.is polyfill to avoid requiring consumers ship their own
6450
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
6451
+ */
6452
+ function is(x, y) {
6453
+ return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
6454
+ ;
6455
+ }
6456
+
6457
+ var objectIs = typeof Object.is === 'function' ? Object.is : is;
6458
+
6459
+ var useSyncExternalStore = React.useSyncExternalStore;
6460
+
6461
+ // for CommonJS interop.
6462
+
6463
+ var useRef = React.useRef,
6464
+ useEffect = React.useEffect,
6465
+ useMemo = React.useMemo,
6466
+ useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments.
6467
+
6468
+ function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
6469
+ // Use this to track the rendered snapshot.
6470
+ var instRef = useRef(null);
6471
+ var inst;
6472
+
6473
+ if (instRef.current === null) {
6474
+ inst = {
6475
+ hasValue: false,
6476
+ value: null
6477
+ };
6478
+ instRef.current = inst;
6479
+ } else {
6480
+ inst = instRef.current;
6481
+ }
6482
+
6483
+ var _useMemo = useMemo(function () {
6484
+ // Track the memoized state using closure variables that are local to this
6485
+ // memoized instance of a getSnapshot function. Intentionally not using a
6486
+ // useRef hook, because that state would be shared across all concurrent
6487
+ // copies of the hook/component.
6488
+ var hasMemo = false;
6489
+ var memoizedSnapshot;
6490
+ var memoizedSelection;
6491
+
6492
+ var memoizedSelector = function (nextSnapshot) {
6493
+ if (!hasMemo) {
6494
+ // The first time the hook is called, there is no memoized result.
6495
+ hasMemo = true;
6496
+ memoizedSnapshot = nextSnapshot;
6497
+
6498
+ var _nextSelection = selector(nextSnapshot);
6499
+
6500
+ if (isEqual !== undefined) {
6501
+ // Even if the selector has changed, the currently rendered selection
6502
+ // may be equal to the new selection. We should attempt to reuse the
6503
+ // current value if possible, to preserve downstream memoizations.
6504
+ if (inst.hasValue) {
6505
+ var currentSelection = inst.value;
6506
+
6507
+ if (isEqual(currentSelection, _nextSelection)) {
6508
+ memoizedSelection = currentSelection;
6509
+ return currentSelection;
6510
+ }
6511
+ }
6512
+ }
6513
+
6514
+ memoizedSelection = _nextSelection;
6515
+ return _nextSelection;
6516
+ } // We may be able to reuse the previous invocation's result.
6517
+
6518
+
6519
+ // We may be able to reuse the previous invocation's result.
6520
+ var prevSnapshot = memoizedSnapshot;
6521
+ var prevSelection = memoizedSelection;
6522
+
6523
+ if (objectIs(prevSnapshot, nextSnapshot)) {
6524
+ // The snapshot is the same as last time. Reuse the previous selection.
6525
+ return prevSelection;
6526
+ } // The snapshot has changed, so we need to compute a new selection.
6527
+
6528
+
6529
+ // The snapshot has changed, so we need to compute a new selection.
6530
+ var nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data
6531
+ // has changed. If it hasn't, return the previous selection. That signals
6532
+ // to React that the selections are conceptually equal, and we can bail
6533
+ // out of rendering.
6534
+
6535
+ // If a custom isEqual function is provided, use that to check if the data
6536
+ // has changed. If it hasn't, return the previous selection. That signals
6537
+ // to React that the selections are conceptually equal, and we can bail
6538
+ // out of rendering.
6539
+ if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) {
6540
+ return prevSelection;
6541
+ }
6542
+
6543
+ memoizedSnapshot = nextSnapshot;
6544
+ memoizedSelection = nextSelection;
6545
+ return nextSelection;
6546
+ }; // Assigning this to a constant so that Flow knows it can't change.
6547
+
6548
+
6549
+ // Assigning this to a constant so that Flow knows it can't change.
6550
+ var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;
6551
+
6552
+ var getSnapshotWithSelector = function () {
6553
+ return memoizedSelector(getSnapshot());
6554
+ };
6555
+
6556
+ var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () {
6557
+ return memoizedSelector(maybeGetServerSnapshot());
6558
+ };
6559
+ return [getSnapshotWithSelector, getServerSnapshotWithSelector];
6560
+ }, [getSnapshot, getServerSnapshot, selector, isEqual]),
6561
+ getSelection = _useMemo[0],
6562
+ getServerSelection = _useMemo[1];
6563
+
6564
+ var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
6565
+ useEffect(function () {
6566
+ inst.hasValue = true;
6567
+ inst.value = value;
6568
+ }, [value]);
6569
+ useDebugValue(value);
6570
+ return value;
6571
+ }
6572
+
6573
+ useSyncExternalStoreWithSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
6574
+ /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
6575
+ if (
6576
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
6577
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
6578
+ 'function'
6579
+ ) {
6580
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
6581
+ }
6582
+
6583
+ })();
6584
+ }
6585
+ return useSyncExternalStoreWithSelector_development;
6586
+ }
6587
+
6588
+ var hasRequiredWithSelector;
6589
+
6590
+ function requireWithSelector () {
6591
+ if (hasRequiredWithSelector) return withSelector.exports;
6592
+ hasRequiredWithSelector = 1;
6593
+
6594
+ if (process.env.NODE_ENV === 'production') {
6595
+ withSelector.exports = requireUseSyncExternalStoreWithSelector_production_min();
6596
+ } else {
6597
+ withSelector.exports = requireUseSyncExternalStoreWithSelector_development();
6598
+ }
6599
+ return withSelector.exports;
6600
+ }
6601
+
6602
+ var withSelectorExports = requireWithSelector();
6603
+
6604
+ // src/index.ts
6605
+ var React = (
6606
+ // prettier-ignore
6607
+ // @ts-ignore
6608
+ "default" in ReactOriginal ? ReactOriginal["default"] : ReactOriginal
6609
+ );
6610
+
6611
+ // src/components/Context.ts
6612
+ var ContextKey = Symbol.for(`react-redux-context`);
6613
+ var gT = typeof globalThis !== "undefined" ? globalThis : (
6614
+ /* fall back to a per-module scope (pre-8.1 behaviour) if `globalThis` is not available */
6615
+ {}
6616
+ );
6617
+ function getContext() {
6618
+ if (!React.createContext)
6619
+ return {};
6620
+ const contextMap = gT[ContextKey] ?? (gT[ContextKey] = /* @__PURE__ */ new Map());
6621
+ let realContext = contextMap.get(React.createContext);
6622
+ if (!realContext) {
6623
+ realContext = React.createContext(
6624
+ null
6625
+ );
6626
+ if (process.env.NODE_ENV !== "production") {
6627
+ realContext.displayName = "ReactRedux";
6628
+ }
6629
+ contextMap.set(React.createContext, realContext);
6630
+ }
6631
+ return realContext;
6632
+ }
6633
+ var ReactReduxContext = /* @__PURE__ */ getContext();
6634
+
6635
+ // src/utils/useSyncExternalStore.ts
6636
+ var notInitialized = () => {
6637
+ throw new Error("uSES not initialized!");
6638
+ };
6639
+
6640
+ // src/hooks/useReduxContext.ts
6641
+ function createReduxContextHook(context = ReactReduxContext) {
6642
+ return function useReduxContext2() {
6643
+ const contextValue = React.useContext(context);
6644
+ if (process.env.NODE_ENV !== "production" && !contextValue) {
6645
+ throw new Error(
6646
+ "could not find react-redux context value; please ensure the component is wrapped in a <Provider>"
6647
+ );
6648
+ }
6649
+ return contextValue;
6650
+ };
6651
+ }
6652
+ var useReduxContext = /* @__PURE__ */ createReduxContextHook();
6653
+
6654
+ // src/hooks/useSelector.ts
6655
+ var useSyncExternalStoreWithSelector = notInitialized;
6656
+ var initializeUseSelector = (fn) => {
6657
+ useSyncExternalStoreWithSelector = fn;
6658
+ };
6659
+ var refEquality = (a, b) => a === b;
6660
+ function createSelectorHook(context = ReactReduxContext) {
6661
+ const useReduxContext2 = context === ReactReduxContext ? useReduxContext : createReduxContextHook(context);
6662
+ const useSelector2 = (selector, equalityFnOrOptions = {}) => {
6663
+ const { equalityFn = refEquality, devModeChecks = {} } = typeof equalityFnOrOptions === "function" ? { equalityFn: equalityFnOrOptions } : equalityFnOrOptions;
6664
+ if (process.env.NODE_ENV !== "production") {
6665
+ if (!selector) {
6666
+ throw new Error(`You must pass a selector to useSelector`);
6667
+ }
6668
+ if (typeof selector !== "function") {
6669
+ throw new Error(`You must pass a function as a selector to useSelector`);
6670
+ }
6671
+ if (typeof equalityFn !== "function") {
6672
+ throw new Error(
6673
+ `You must pass a function as an equality function to useSelector`
6674
+ );
6675
+ }
6676
+ }
6677
+ const {
6678
+ store,
6679
+ subscription,
6680
+ getServerState,
6681
+ stabilityCheck,
6682
+ identityFunctionCheck
6683
+ } = useReduxContext2();
6684
+ const firstRun = React.useRef(true);
6685
+ const wrappedSelector = React.useCallback(
6686
+ {
6687
+ [selector.name](state) {
6688
+ const selected = selector(state);
6689
+ if (process.env.NODE_ENV !== "production") {
6690
+ const {
6691
+ identityFunctionCheck: finalIdentityFunctionCheck,
6692
+ stabilityCheck: finalStabilityCheck
6693
+ } = {
6694
+ stabilityCheck,
6695
+ identityFunctionCheck,
6696
+ ...devModeChecks
6697
+ };
6698
+ if (finalStabilityCheck === "always" || finalStabilityCheck === "once" && firstRun.current) {
6699
+ const toCompare = selector(state);
6700
+ if (!equalityFn(selected, toCompare)) {
6701
+ let stack = void 0;
6702
+ try {
6703
+ throw new Error();
6704
+ } catch (e) {
6705
+ ({ stack } = e);
6706
+ }
6707
+ console.warn(
6708
+ "Selector " + (selector.name || "unknown") + " returned a different result when called with the same parameters. This can lead to unnecessary rerenders.\nSelectors that return a new reference (such as an object or an array) should be memoized: https://redux.js.org/usage/deriving-data-selectors#optimizing-selectors-with-memoization",
6709
+ {
6710
+ state,
6711
+ selected,
6712
+ selected2: toCompare,
6713
+ stack
6714
+ }
6715
+ );
6716
+ }
6717
+ }
6718
+ if (finalIdentityFunctionCheck === "always" || finalIdentityFunctionCheck === "once" && firstRun.current) {
6719
+ if (selected === state) {
6720
+ let stack = void 0;
6721
+ try {
6722
+ throw new Error();
6723
+ } catch (e) {
6724
+ ({ stack } = e);
6725
+ }
6726
+ console.warn(
6727
+ "Selector " + (selector.name || "unknown") + " returned the root state when called. This can lead to unnecessary rerenders.\nSelectors that return the entire state are almost certainly a mistake, as they will cause a rerender whenever *anything* in state changes.",
6728
+ { stack }
6729
+ );
6730
+ }
6731
+ }
6732
+ if (firstRun.current)
6733
+ firstRun.current = false;
6734
+ }
6735
+ return selected;
6736
+ }
6737
+ }[selector.name],
6738
+ [selector, stabilityCheck, devModeChecks.stabilityCheck]
6739
+ );
6740
+ const selectedState = useSyncExternalStoreWithSelector(
6741
+ subscription.addNestedSub,
6742
+ store.getState,
6743
+ getServerState || store.getState,
6744
+ wrappedSelector,
6745
+ equalityFn
6746
+ );
6747
+ React.useDebugValue(selectedState);
6748
+ return selectedState;
6749
+ };
6750
+ Object.assign(useSelector2, {
6751
+ withTypes: () => useSelector2
6752
+ });
6753
+ return useSelector2;
6754
+ }
6755
+ var useSelector = /* @__PURE__ */ createSelectorHook();
6756
+
6757
+ // src/utils/batch.ts
6758
+ function defaultNoopBatch(callback) {
6759
+ callback();
6760
+ }
6761
+
6762
+ // src/utils/Subscription.ts
6763
+ function createListenerCollection() {
6764
+ let first = null;
6765
+ let last = null;
6766
+ return {
6767
+ clear() {
6768
+ first = null;
6769
+ last = null;
6770
+ },
6771
+ notify() {
6772
+ defaultNoopBatch(() => {
6773
+ let listener = first;
6774
+ while (listener) {
6775
+ listener.callback();
6776
+ listener = listener.next;
6777
+ }
6778
+ });
6779
+ },
6780
+ get() {
6781
+ const listeners = [];
6782
+ let listener = first;
6783
+ while (listener) {
6784
+ listeners.push(listener);
6785
+ listener = listener.next;
6786
+ }
6787
+ return listeners;
6788
+ },
6789
+ subscribe(callback) {
6790
+ let isSubscribed = true;
6791
+ const listener = last = {
6792
+ callback,
6793
+ next: null,
6794
+ prev: last
6795
+ };
6796
+ if (listener.prev) {
6797
+ listener.prev.next = listener;
6798
+ } else {
6799
+ first = listener;
6800
+ }
6801
+ return function unsubscribe() {
6802
+ if (!isSubscribed || first === null)
6803
+ return;
6804
+ isSubscribed = false;
6805
+ if (listener.next) {
6806
+ listener.next.prev = listener.prev;
6807
+ } else {
6808
+ last = listener.prev;
6809
+ }
6810
+ if (listener.prev) {
6811
+ listener.prev.next = listener.next;
6812
+ } else {
6813
+ first = listener.next;
6814
+ }
6815
+ };
6816
+ }
6817
+ };
6818
+ }
6819
+ var nullListeners = {
6820
+ notify() {
6821
+ },
6822
+ get: () => []
6823
+ };
6824
+ function createSubscription(store, parentSub) {
6825
+ let unsubscribe;
6826
+ let listeners = nullListeners;
6827
+ let subscriptionsAmount = 0;
6828
+ let selfSubscribed = false;
6829
+ function addNestedSub(listener) {
6830
+ trySubscribe();
6831
+ const cleanupListener = listeners.subscribe(listener);
6832
+ let removed = false;
6833
+ return () => {
6834
+ if (!removed) {
6835
+ removed = true;
6836
+ cleanupListener();
6837
+ tryUnsubscribe();
6838
+ }
6839
+ };
6840
+ }
6841
+ function notifyNestedSubs() {
6842
+ listeners.notify();
6843
+ }
6844
+ function handleChangeWrapper() {
6845
+ if (subscription.onStateChange) {
6846
+ subscription.onStateChange();
6847
+ }
6848
+ }
6849
+ function isSubscribed() {
6850
+ return selfSubscribed;
6851
+ }
6852
+ function trySubscribe() {
6853
+ subscriptionsAmount++;
6854
+ if (!unsubscribe) {
6855
+ unsubscribe = store.subscribe(handleChangeWrapper);
6856
+ listeners = createListenerCollection();
6857
+ }
6858
+ }
6859
+ function tryUnsubscribe() {
6860
+ subscriptionsAmount--;
6861
+ if (unsubscribe && subscriptionsAmount === 0) {
6862
+ unsubscribe();
6863
+ unsubscribe = void 0;
6864
+ listeners.clear();
6865
+ listeners = nullListeners;
6866
+ }
6867
+ }
6868
+ function trySubscribeSelf() {
6869
+ if (!selfSubscribed) {
6870
+ selfSubscribed = true;
6871
+ trySubscribe();
6872
+ }
6873
+ }
6874
+ function tryUnsubscribeSelf() {
6875
+ if (selfSubscribed) {
6876
+ selfSubscribed = false;
6877
+ tryUnsubscribe();
6878
+ }
6879
+ }
6880
+ const subscription = {
6881
+ addNestedSub,
6882
+ notifyNestedSubs,
6883
+ handleChangeWrapper,
6884
+ isSubscribed,
6885
+ trySubscribe: trySubscribeSelf,
6886
+ tryUnsubscribe: tryUnsubscribeSelf,
6887
+ getListeners: () => listeners
6888
+ };
6889
+ return subscription;
6890
+ }
6891
+
6892
+ // src/utils/useIsomorphicLayoutEffect.ts
6893
+ var canUseDOM$1 = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
6894
+ var isReactNative$1 = typeof navigator !== "undefined" && navigator.product === "ReactNative";
6895
+ var useIsomorphicLayoutEffect$1 = canUseDOM$1 || isReactNative$1 ? React.useLayoutEffect : React.useEffect;
6896
+
6897
+ // src/utils/shallowEqual.ts
6898
+ function is(x, y) {
6899
+ if (x === y) {
6900
+ return x !== 0 || y !== 0 || 1 / x === 1 / y;
6901
+ } else {
6902
+ return x !== x && y !== y;
6903
+ }
6904
+ }
6905
+ function shallowEqual(objA, objB) {
6906
+ if (is(objA, objB))
6907
+ return true;
6908
+ if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
6909
+ return false;
6910
+ }
6911
+ const keysA = Object.keys(objA);
6912
+ const keysB = Object.keys(objB);
6913
+ if (keysA.length !== keysB.length)
6914
+ return false;
6915
+ for (let i = 0; i < keysA.length; i++) {
6916
+ if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
6917
+ return false;
6918
+ }
6919
+ }
6920
+ return true;
6921
+ }
6922
+
6923
+ // src/components/Provider.tsx
6924
+ function Provider({
6925
+ store,
6926
+ context,
6927
+ children,
6928
+ serverState,
6929
+ stabilityCheck = "once",
6930
+ identityFunctionCheck = "once"
6931
+ }) {
6932
+ const contextValue = React.useMemo(() => {
6933
+ const subscription = createSubscription(store);
6934
+ return {
6935
+ store,
6936
+ subscription,
6937
+ getServerState: serverState ? () => serverState : void 0,
6938
+ stabilityCheck,
6939
+ identityFunctionCheck
6940
+ };
6941
+ }, [store, serverState, stabilityCheck, identityFunctionCheck]);
6942
+ const previousState = React.useMemo(() => store.getState(), [store]);
6943
+ useIsomorphicLayoutEffect$1(() => {
6944
+ const { subscription } = contextValue;
6945
+ subscription.onStateChange = subscription.notifyNestedSubs;
6946
+ subscription.trySubscribe();
6947
+ if (previousState !== store.getState()) {
6948
+ subscription.notifyNestedSubs();
6949
+ }
6950
+ return () => {
6951
+ subscription.tryUnsubscribe();
6952
+ subscription.onStateChange = void 0;
6953
+ };
6954
+ }, [contextValue, previousState]);
6955
+ const Context = context || ReactReduxContext;
6956
+ return /* @__PURE__ */ React.createElement(Context.Provider, { value: contextValue }, children);
6957
+ }
6958
+ var Provider_default = Provider;
6959
+
6960
+ // src/hooks/useStore.ts
6961
+ function createStoreHook(context = ReactReduxContext) {
6962
+ const useReduxContext2 = context === ReactReduxContext ? useReduxContext : (
6963
+ // @ts-ignore
6964
+ createReduxContextHook(context)
6965
+ );
6966
+ const useStore2 = () => {
6967
+ const { store } = useReduxContext2();
6968
+ return store;
6969
+ };
6970
+ Object.assign(useStore2, {
6971
+ withTypes: () => useStore2
6972
+ });
6973
+ return useStore2;
6974
+ }
6975
+ var useStore = /* @__PURE__ */ createStoreHook();
6976
+
6977
+ // src/hooks/useDispatch.ts
6978
+ function createDispatchHook(context = ReactReduxContext) {
6979
+ const useStore2 = context === ReactReduxContext ? useStore : createStoreHook(context);
6980
+ const useDispatch2 = () => {
6981
+ const store = useStore2();
6982
+ return store.dispatch;
6983
+ };
6984
+ Object.assign(useDispatch2, {
6985
+ withTypes: () => useDispatch2
6986
+ });
6987
+ return useDispatch2;
6988
+ }
6989
+ var useDispatch = /* @__PURE__ */ createDispatchHook();
6990
+
6991
+ // src/exports.ts
6992
+ var batch = defaultNoopBatch;
6993
+
6994
+ // src/index.ts
6995
+ initializeUseSelector(withSelectorExports.useSyncExternalStoreWithSelector);
6996
+
6997
+ // src/query/react/index.ts
6998
+
6999
+ // src/query/endpointDefinitions.ts
7000
+ function isQueryDefinition(e) {
7001
+ return e.type === "query" /* query */;
7002
+ }
7003
+ function isMutationDefinition(e) {
7004
+ return e.type === "mutation" /* mutation */;
7005
+ }
7006
+
7007
+ // src/query/tsHelpers.ts
7008
+ function safeAssign(target, ...args) {
7009
+ return Object.assign(target, ...args);
7010
+ }
7011
+
7012
+ // src/query/utils/capitalize.ts
7013
+ function capitalize(str) {
7014
+ return str.replace(str[0], str[0].toUpperCase());
7015
+ }
7016
+
7017
+ // src/query/utils/countObjectKeys.ts
7018
+ function countObjectKeys(obj) {
7019
+ let count = 0;
7020
+ for (const _key in obj) {
7021
+ count++;
7022
+ }
7023
+ return count;
7024
+ }
7025
+
7026
+ // src/query/defaultSerializeQueryArgs.ts
7027
+ var cache = WeakMap ? /* @__PURE__ */ new WeakMap() : void 0;
7028
+ var defaultSerializeQueryArgs = ({
7029
+ endpointName,
7030
+ queryArgs
7031
+ }) => {
7032
+ let serialized = "";
7033
+ const cached = cache?.get(queryArgs);
7034
+ if (typeof cached === "string") {
7035
+ serialized = cached;
7036
+ } else {
7037
+ const stringified = JSON.stringify(queryArgs, (key, value) => {
7038
+ value = typeof value === "bigint" ? {
7039
+ $bigint: value.toString()
7040
+ } : value;
7041
+ value = isPlainObject$1(value) ? Object.keys(value).sort().reduce((acc, key2) => {
7042
+ acc[key2] = value[key2];
7043
+ return acc;
7044
+ }, {}) : value;
7045
+ return value;
7046
+ });
7047
+ if (isPlainObject$1(queryArgs)) {
7048
+ cache?.set(queryArgs, stringified);
7049
+ }
7050
+ serialized = stringified;
7051
+ }
7052
+ return `${endpointName}(${serialized})`;
7053
+ };
7054
+
7055
+ // src/query/react/constants.ts
7056
+ var UNINITIALIZED_VALUE = Symbol();
7057
+ function useStableQueryArgs(queryArgs, serialize, endpointDefinition, endpointName) {
7058
+ const incoming = useMemo(() => ({
7059
+ queryArgs,
7060
+ serialized: typeof queryArgs == "object" ? serialize({
7061
+ queryArgs,
7062
+ endpointDefinition,
7063
+ endpointName
7064
+ }) : queryArgs
7065
+ }), [queryArgs, serialize, endpointDefinition, endpointName]);
7066
+ const cache2 = useRef(incoming);
7067
+ useEffect(() => {
7068
+ if (cache2.current.serialized !== incoming.serialized) {
7069
+ cache2.current = incoming;
7070
+ }
7071
+ }, [incoming]);
7072
+ return cache2.current.serialized === incoming.serialized ? cache2.current.queryArgs : queryArgs;
7073
+ }
7074
+ function useShallowStableValue(value) {
7075
+ const cache2 = useRef(value);
7076
+ useEffect(() => {
7077
+ if (!shallowEqual(cache2.current, value)) {
7078
+ cache2.current = value;
7079
+ }
7080
+ }, [value]);
7081
+ return shallowEqual(cache2.current, value) ? cache2.current : value;
7082
+ }
7083
+
7084
+ // src/query/react/buildHooks.ts
7085
+ var canUseDOM = () => !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
7086
+ var isDOM = /* @__PURE__ */ canUseDOM();
7087
+ var isRunningInReactNative = () => typeof navigator !== "undefined" && navigator.product === "ReactNative";
7088
+ var isReactNative = /* @__PURE__ */ isRunningInReactNative();
7089
+ var getUseIsomorphicLayoutEffect = () => isDOM || isReactNative ? useLayoutEffect : useEffect;
7090
+ var useIsomorphicLayoutEffect = /* @__PURE__ */ getUseIsomorphicLayoutEffect();
7091
+ var noPendingQueryStateSelector = (selected) => {
7092
+ if (selected.isUninitialized) {
7093
+ return {
7094
+ ...selected,
7095
+ isUninitialized: false,
7096
+ isFetching: true,
7097
+ isLoading: selected.data !== void 0 ? false : true,
7098
+ status: QueryStatus.pending
7099
+ };
7100
+ }
7101
+ return selected;
7102
+ };
7103
+ function buildHooks({
7104
+ api,
7105
+ moduleOptions: {
7106
+ batch,
7107
+ hooks: {
7108
+ useDispatch,
7109
+ useSelector,
7110
+ useStore
7111
+ },
7112
+ unstable__sideEffectsInRender,
7113
+ createSelector: createSelector2
7114
+ },
7115
+ serializeQueryArgs,
7116
+ context
7117
+ }) {
7118
+ const usePossiblyImmediateEffect = unstable__sideEffectsInRender ? (cb) => cb() : useEffect;
7119
+ return {
7120
+ buildQueryHooks,
7121
+ buildMutationHook,
7122
+ usePrefetch
7123
+ };
7124
+ function queryStatePreSelector(currentState, lastResult, queryArgs) {
7125
+ if (lastResult?.endpointName && currentState.isUninitialized) {
7126
+ const {
7127
+ endpointName
7128
+ } = lastResult;
7129
+ const endpointDefinition = context.endpointDefinitions[endpointName];
7130
+ if (serializeQueryArgs({
7131
+ queryArgs: lastResult.originalArgs,
7132
+ endpointDefinition,
7133
+ endpointName
7134
+ }) === serializeQueryArgs({
7135
+ queryArgs,
7136
+ endpointDefinition,
7137
+ endpointName
7138
+ })) lastResult = void 0;
7139
+ }
7140
+ let data = currentState.isSuccess ? currentState.data : lastResult?.data;
7141
+ if (data === void 0) data = currentState.data;
7142
+ const hasData = data !== void 0;
7143
+ const isFetching = currentState.isLoading;
7144
+ const isLoading = (!lastResult || lastResult.isLoading || lastResult.isUninitialized) && !hasData && isFetching;
7145
+ const isSuccess = currentState.isSuccess || isFetching && hasData;
7146
+ return {
7147
+ ...currentState,
7148
+ data,
7149
+ currentData: currentState.data,
7150
+ isFetching,
7151
+ isLoading,
7152
+ isSuccess
7153
+ };
7154
+ }
7155
+ function usePrefetch(endpointName, defaultOptions) {
7156
+ const dispatch = useDispatch();
7157
+ const stableDefaultOptions = useShallowStableValue(defaultOptions);
7158
+ return useCallback((arg, options) => dispatch(api.util.prefetch(endpointName, arg, {
7159
+ ...stableDefaultOptions,
7160
+ ...options
7161
+ })), [endpointName, dispatch, stableDefaultOptions]);
7162
+ }
7163
+ function buildQueryHooks(name) {
7164
+ const useQuerySubscription = (arg, {
7165
+ refetchOnReconnect,
7166
+ refetchOnFocus,
7167
+ refetchOnMountOrArgChange,
7168
+ skip = false,
7169
+ pollingInterval = 0,
7170
+ skipPollingIfUnfocused = false
7171
+ } = {}) => {
7172
+ const {
7173
+ initiate
7174
+ } = api.endpoints[name];
7175
+ const dispatch = useDispatch();
7176
+ const subscriptionSelectorsRef = useRef(void 0);
7177
+ if (!subscriptionSelectorsRef.current) {
7178
+ const returnedValue = dispatch(api.internalActions.internal_getRTKQSubscriptions());
7179
+ if (process.env.NODE_ENV !== "production") {
7180
+ if (typeof returnedValue !== "object" || typeof returnedValue?.type === "string") {
7181
+ throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(37) : `Warning: Middleware for RTK-Query API at reducerPath "${api.reducerPath}" has not been added to the store.
7182
+ You must add the middleware for RTK-Query to function correctly!`);
7183
+ }
7184
+ }
7185
+ subscriptionSelectorsRef.current = returnedValue;
7186
+ }
7187
+ const stableArg = useStableQueryArgs(
7188
+ skip ? skipToken : arg,
7189
+ // Even if the user provided a per-endpoint `serializeQueryArgs` with
7190
+ // a consistent return value, _here_ we want to use the default behavior
7191
+ // so we can tell if _anything_ actually changed. Otherwise, we can end up
7192
+ // with a case where the query args did change but the serialization doesn't,
7193
+ // and then we never try to initiate a refetch.
7194
+ defaultSerializeQueryArgs,
7195
+ context.endpointDefinitions[name],
7196
+ name
7197
+ );
7198
+ const stableSubscriptionOptions = useShallowStableValue({
7199
+ refetchOnReconnect,
7200
+ refetchOnFocus,
7201
+ pollingInterval,
7202
+ skipPollingIfUnfocused
7203
+ });
7204
+ const lastRenderHadSubscription = useRef(false);
7205
+ const promiseRef = useRef(void 0);
7206
+ let {
7207
+ queryCacheKey,
7208
+ requestId
7209
+ } = promiseRef.current || {};
7210
+ let currentRenderHasSubscription = false;
7211
+ if (queryCacheKey && requestId) {
7212
+ currentRenderHasSubscription = subscriptionSelectorsRef.current.isRequestSubscribed(queryCacheKey, requestId);
7213
+ }
7214
+ const subscriptionRemoved = !currentRenderHasSubscription && lastRenderHadSubscription.current;
7215
+ usePossiblyImmediateEffect(() => {
7216
+ lastRenderHadSubscription.current = currentRenderHasSubscription;
7217
+ });
7218
+ usePossiblyImmediateEffect(() => {
7219
+ if (subscriptionRemoved) {
7220
+ promiseRef.current = void 0;
7221
+ }
7222
+ }, [subscriptionRemoved]);
7223
+ usePossiblyImmediateEffect(() => {
7224
+ const lastPromise = promiseRef.current;
7225
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "removeMeOnCompilation") {
7226
+ console.log(subscriptionRemoved);
7227
+ }
7228
+ if (stableArg === skipToken) {
7229
+ lastPromise?.unsubscribe();
7230
+ promiseRef.current = void 0;
7231
+ return;
7232
+ }
7233
+ const lastSubscriptionOptions = promiseRef.current?.subscriptionOptions;
7234
+ if (!lastPromise || lastPromise.arg !== stableArg) {
7235
+ lastPromise?.unsubscribe();
7236
+ const promise = dispatch(initiate(stableArg, {
7237
+ subscriptionOptions: stableSubscriptionOptions,
7238
+ forceRefetch: refetchOnMountOrArgChange
7239
+ }));
7240
+ promiseRef.current = promise;
7241
+ } else if (stableSubscriptionOptions !== lastSubscriptionOptions) {
7242
+ lastPromise.updateSubscriptionOptions(stableSubscriptionOptions);
7243
+ }
7244
+ }, [dispatch, initiate, refetchOnMountOrArgChange, stableArg, stableSubscriptionOptions, subscriptionRemoved]);
7245
+ useEffect(() => {
7246
+ return () => {
7247
+ promiseRef.current?.unsubscribe();
7248
+ promiseRef.current = void 0;
7249
+ };
7250
+ }, []);
7251
+ return useMemo(() => ({
7252
+ /**
7253
+ * A method to manually refetch data for the query
7254
+ */
7255
+ refetch: () => {
7256
+ if (!promiseRef.current) throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(38) : "Cannot refetch a query that has not been started yet.");
7257
+ return promiseRef.current?.refetch();
7258
+ }
7259
+ }), []);
7260
+ };
7261
+ const useLazyQuerySubscription = ({
7262
+ refetchOnReconnect,
7263
+ refetchOnFocus,
7264
+ pollingInterval = 0,
7265
+ skipPollingIfUnfocused = false
7266
+ } = {}) => {
7267
+ const {
7268
+ initiate
7269
+ } = api.endpoints[name];
7270
+ const dispatch = useDispatch();
7271
+ const [arg, setArg] = useState(UNINITIALIZED_VALUE);
7272
+ const promiseRef = useRef(void 0);
7273
+ const stableSubscriptionOptions = useShallowStableValue({
7274
+ refetchOnReconnect,
7275
+ refetchOnFocus,
7276
+ pollingInterval,
7277
+ skipPollingIfUnfocused
7278
+ });
7279
+ usePossiblyImmediateEffect(() => {
7280
+ const lastSubscriptionOptions = promiseRef.current?.subscriptionOptions;
7281
+ if (stableSubscriptionOptions !== lastSubscriptionOptions) {
7282
+ promiseRef.current?.updateSubscriptionOptions(stableSubscriptionOptions);
7283
+ }
7284
+ }, [stableSubscriptionOptions]);
7285
+ const subscriptionOptionsRef = useRef(stableSubscriptionOptions);
7286
+ usePossiblyImmediateEffect(() => {
7287
+ subscriptionOptionsRef.current = stableSubscriptionOptions;
7288
+ }, [stableSubscriptionOptions]);
7289
+ const trigger = useCallback(function(arg2, preferCacheValue = false) {
7290
+ let promise;
7291
+ batch(() => {
7292
+ promiseRef.current?.unsubscribe();
7293
+ promiseRef.current = promise = dispatch(initiate(arg2, {
7294
+ subscriptionOptions: subscriptionOptionsRef.current,
7295
+ forceRefetch: !preferCacheValue
7296
+ }));
7297
+ setArg(arg2);
7298
+ });
7299
+ return promise;
7300
+ }, [dispatch, initiate]);
7301
+ useEffect(() => {
7302
+ return () => {
7303
+ promiseRef?.current?.unsubscribe();
7304
+ };
7305
+ }, []);
7306
+ useEffect(() => {
7307
+ if (arg !== UNINITIALIZED_VALUE && !promiseRef.current) {
7308
+ trigger(arg, true);
7309
+ }
7310
+ }, [arg, trigger]);
7311
+ return useMemo(() => [trigger, arg], [trigger, arg]);
7312
+ };
7313
+ const useQueryState = (arg, {
7314
+ skip = false,
7315
+ selectFromResult
7316
+ } = {}) => {
7317
+ const {
7318
+ select
7319
+ } = api.endpoints[name];
7320
+ const stableArg = useStableQueryArgs(skip ? skipToken : arg, serializeQueryArgs, context.endpointDefinitions[name], name);
7321
+ const lastValue = useRef(void 0);
7322
+ const selectDefaultResult = useMemo(() => createSelector2([select(stableArg), (_, lastResult) => lastResult, (_) => stableArg], queryStatePreSelector, {
7323
+ memoizeOptions: {
7324
+ resultEqualityCheck: shallowEqual
7325
+ }
7326
+ }), [select, stableArg]);
7327
+ const querySelector = useMemo(() => selectFromResult ? createSelector2([selectDefaultResult], selectFromResult, {
7328
+ devModeChecks: {
7329
+ identityFunctionCheck: "never"
7330
+ }
7331
+ }) : selectDefaultResult, [selectDefaultResult, selectFromResult]);
7332
+ const currentState = useSelector((state) => querySelector(state, lastValue.current), shallowEqual);
7333
+ const store = useStore();
7334
+ const newLastValue = selectDefaultResult(store.getState(), lastValue.current);
7335
+ useIsomorphicLayoutEffect(() => {
7336
+ lastValue.current = newLastValue;
7337
+ }, [newLastValue]);
7338
+ return currentState;
7339
+ };
7340
+ return {
7341
+ useQueryState,
7342
+ useQuerySubscription,
7343
+ useLazyQuerySubscription,
7344
+ useLazyQuery(options) {
7345
+ const [trigger, arg] = useLazyQuerySubscription(options);
7346
+ const queryStateResults = useQueryState(arg, {
7347
+ ...options,
7348
+ skip: arg === UNINITIALIZED_VALUE
7349
+ });
7350
+ const info = useMemo(() => ({
7351
+ lastArg: arg
7352
+ }), [arg]);
7353
+ return useMemo(() => [trigger, queryStateResults, info], [trigger, queryStateResults, info]);
7354
+ },
7355
+ useQuery(arg, options) {
7356
+ const querySubscriptionResults = useQuerySubscription(arg, options);
7357
+ const queryStateResults = useQueryState(arg, {
7358
+ selectFromResult: arg === skipToken || options?.skip ? void 0 : noPendingQueryStateSelector,
7359
+ ...options
7360
+ });
7361
+ const {
7362
+ data,
7363
+ status,
7364
+ isLoading,
7365
+ isSuccess,
7366
+ isError,
7367
+ error
7368
+ } = queryStateResults;
7369
+ useDebugValue({
7370
+ data,
7371
+ status,
7372
+ isLoading,
7373
+ isSuccess,
7374
+ isError,
7375
+ error
7376
+ });
7377
+ return useMemo(() => ({
7378
+ ...queryStateResults,
7379
+ ...querySubscriptionResults
7380
+ }), [queryStateResults, querySubscriptionResults]);
7381
+ }
7382
+ };
7383
+ }
7384
+ function buildMutationHook(name) {
7385
+ return ({
7386
+ selectFromResult,
7387
+ fixedCacheKey
7388
+ } = {}) => {
7389
+ const {
7390
+ select,
7391
+ initiate
7392
+ } = api.endpoints[name];
7393
+ const dispatch = useDispatch();
7394
+ const [promise, setPromise] = useState();
7395
+ useEffect(() => () => {
7396
+ if (!promise?.arg.fixedCacheKey) {
7397
+ promise?.reset();
7398
+ }
7399
+ }, [promise]);
7400
+ const triggerMutation = useCallback(function(arg) {
7401
+ const promise2 = dispatch(initiate(arg, {
7402
+ fixedCacheKey
7403
+ }));
7404
+ setPromise(promise2);
7405
+ return promise2;
7406
+ }, [dispatch, initiate, fixedCacheKey]);
7407
+ const {
7408
+ requestId
7409
+ } = promise || {};
7410
+ const selectDefaultResult = useMemo(() => select({
7411
+ fixedCacheKey,
7412
+ requestId: promise?.requestId
7413
+ }), [fixedCacheKey, promise, select]);
7414
+ const mutationSelector = useMemo(() => selectFromResult ? createSelector2([selectDefaultResult], selectFromResult) : selectDefaultResult, [selectFromResult, selectDefaultResult]);
7415
+ const currentState = useSelector(mutationSelector, shallowEqual);
7416
+ const originalArgs = fixedCacheKey == null ? promise?.arg.originalArgs : void 0;
7417
+ const reset = useCallback(() => {
7418
+ batch(() => {
7419
+ if (promise) {
7420
+ setPromise(void 0);
7421
+ }
7422
+ if (fixedCacheKey) {
7423
+ dispatch(api.internalActions.removeMutationResult({
7424
+ requestId,
7425
+ fixedCacheKey
7426
+ }));
7427
+ }
7428
+ });
7429
+ }, [dispatch, fixedCacheKey, promise, requestId]);
7430
+ const {
7431
+ endpointName,
7432
+ data,
7433
+ status,
7434
+ isLoading,
7435
+ isSuccess,
7436
+ isError,
7437
+ error
7438
+ } = currentState;
7439
+ useDebugValue({
7440
+ endpointName,
7441
+ data,
7442
+ status,
7443
+ isLoading,
7444
+ isSuccess,
7445
+ isError,
7446
+ error
7447
+ });
7448
+ const finalState = useMemo(() => ({
7449
+ ...currentState,
7450
+ originalArgs,
7451
+ reset
7452
+ }), [currentState, originalArgs, reset]);
7453
+ return useMemo(() => [triggerMutation, finalState], [triggerMutation, finalState]);
7454
+ };
7455
+ }
7456
+ }
7457
+
7458
+ // src/query/react/module.ts
7459
+ var reactHooksModuleName = /* @__PURE__ */ Symbol();
7460
+ var reactHooksModule = ({
7461
+ batch: batch$1 = batch,
7462
+ hooks = {
7463
+ useDispatch: useDispatch,
7464
+ useSelector: useSelector,
7465
+ useStore: useStore
7466
+ },
7467
+ createSelector: createSelector2 = createSelector,
7468
+ unstable__sideEffectsInRender = false,
7469
+ ...rest
7470
+ } = {}) => {
7471
+ if (process.env.NODE_ENV !== "production") {
7472
+ const hookNames = ["useDispatch", "useSelector", "useStore"];
7473
+ let warned = false;
7474
+ for (const hookName of hookNames) {
7475
+ if (countObjectKeys(rest) > 0) {
7476
+ if (rest[hookName]) {
7477
+ if (!warned) {
7478
+ console.warn("As of RTK 2.0, the hooks now need to be specified as one object, provided under a `hooks` key:\n`reactHooksModule({ hooks: { useDispatch, useSelector, useStore } })`");
7479
+ warned = true;
7480
+ }
7481
+ }
7482
+ hooks[hookName] = rest[hookName];
7483
+ }
7484
+ if (typeof hooks[hookName] !== "function") {
7485
+ throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(36) : `When using custom hooks for context, all ${hookNames.length} hooks need to be provided: ${hookNames.join(", ")}.
7486
+ Hook ${hookName} was either not provided or not a function.`);
7487
+ }
7488
+ }
7489
+ }
7490
+ return {
7491
+ name: reactHooksModuleName,
7492
+ init(api, {
7493
+ serializeQueryArgs
7494
+ }, context) {
7495
+ const anyApi = api;
7496
+ const {
7497
+ buildQueryHooks,
7498
+ buildMutationHook,
7499
+ usePrefetch
7500
+ } = buildHooks({
7501
+ api,
7502
+ moduleOptions: {
7503
+ batch: batch$1,
7504
+ hooks,
7505
+ unstable__sideEffectsInRender,
7506
+ createSelector: createSelector2
7507
+ },
7508
+ serializeQueryArgs,
7509
+ context
7510
+ });
7511
+ safeAssign(anyApi, {
7512
+ usePrefetch
7513
+ });
7514
+ safeAssign(context, {
7515
+ batch: batch$1
7516
+ });
7517
+ return {
7518
+ injectEndpoint(endpointName, definition) {
7519
+ if (isQueryDefinition(definition)) {
7520
+ const {
7521
+ useQuery,
7522
+ useLazyQuery,
7523
+ useLazyQuerySubscription,
7524
+ useQueryState,
7525
+ useQuerySubscription
7526
+ } = buildQueryHooks(endpointName);
7527
+ safeAssign(anyApi.endpoints[endpointName], {
7528
+ useQuery,
7529
+ useLazyQuery,
7530
+ useLazyQuerySubscription,
7531
+ useQueryState,
7532
+ useQuerySubscription
7533
+ });
7534
+ api[`use${capitalize(endpointName)}Query`] = useQuery;
7535
+ api[`useLazy${capitalize(endpointName)}Query`] = useLazyQuery;
7536
+ } else if (isMutationDefinition(definition)) {
7537
+ const useMutation = buildMutationHook(endpointName);
7538
+ safeAssign(anyApi.endpoints[endpointName], {
7539
+ useMutation
7540
+ });
7541
+ api[`use${capitalize(endpointName)}Mutation`] = useMutation;
7542
+ }
7543
+ }
7544
+ };
7545
+ }
7546
+ };
7547
+ };
7548
+ function ApiProvider(props) {
7549
+ const context = props.context || ReactReduxContext;
7550
+ const existingContext = useContext(context);
7551
+ if (existingContext) {
7552
+ throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(35) : "Existing Redux context detected. If you already have a store set up, please use the traditional Redux setup.");
7553
+ }
7554
+ const [store] = ReactOriginal.useState(() => configureStore({
7555
+ reducer: {
7556
+ [props.api.reducerPath]: props.api.reducer
7557
+ },
7558
+ middleware: (gDM) => gDM().concat(props.api.middleware)
7559
+ }));
7560
+ useEffect(() => props.setupListeners === false ? void 0 : setupListeners(store.dispatch, props.setupListeners), [props.setupListeners, store.dispatch]);
7561
+ return /* @__PURE__ */ ReactOriginal.createElement(Provider_default, { store, context }, props.children);
7562
+ }
7563
+
7564
+ // src/query/react/index.ts
7565
+ var createApi = /* @__PURE__ */ buildCreateApi(coreModule(), reactHooksModule());
6391
7566
 
6392
- var rtkQuery_modern = /*#__PURE__*/Object.freeze({
7567
+ var rtkQueryReact_modern = /*#__PURE__*/Object.freeze({
6393
7568
  __proto__: null,
7569
+ ApiProvider: ApiProvider,
6394
7570
  QueryStatus: QueryStatus,
7571
+ UNINITIALIZED_VALUE: UNINITIALIZED_VALUE,
6395
7572
  _NEVER: _NEVER,
6396
7573
  buildCreateApi: buildCreateApi,
6397
7574
  copyWithStructuralSharing: copyWithStructuralSharing,
6398
7575
  coreModule: coreModule,
6399
7576
  coreModuleName: coreModuleName,
6400
7577
  createApi: createApi,
6401
- defaultSerializeQueryArgs: defaultSerializeQueryArgs,
7578
+ defaultSerializeQueryArgs: defaultSerializeQueryArgs$1,
6402
7579
  fakeBaseQuery: fakeBaseQuery,
6403
7580
  fetchBaseQuery: fetchBaseQuery,
7581
+ reactHooksModule: reactHooksModule,
7582
+ reactHooksModuleName: reactHooksModuleName,
6404
7583
  retry: retry,
6405
7584
  setupListeners: setupListeners,
6406
7585
  skipToken: skipToken
6407
7586
  });
6408
7587
 
6409
- export { ReducerType, SHOULD_AUTOBATCH, TaskAbortError, Tuple, actionTypes_default as __DO_NOT_USE__ActionTypes, addListener, applyMiddleware, asyncThunkCreator, autoBatchEnhancer, bindActionCreators, buildCreateSlice, clearAllListeners, combineReducers, combineSlices, compose, configureStore, createAction, createActionCreatorInvariantMiddleware, createAsyncThunk, createDraftSafeSelector, createDraftSafeSelectorCreator, createDynamicMiddleware, createEntityAdapter, createImmutableStateInvariantMiddleware, createListenerMiddleware, produce as createNextState, createReducer, createSelector, createSelectorCreator, createSerializableStateInvariantMiddleware, createSlice, createStore, current, findNonSerializableValue, formatProdErrorMessage, freeze, isAction, isActionCreator, isAllOf, isAnyOf, isAsyncThunkAction, isDraft, isFSA as isFluxStandardAction, isFulfilled, isImmutableDefault, isPending, isPlain, isPlainObject$1 as isPlainObject, isRejected, isRejectedWithValue, legacy_createStore, lruMemoize, miniSerializeError, nanoid, original$1 as original, prepareAutoBatched, rtkQuery_modern as reactQuery, removeListener, unwrapResult, weakMapMemoize };
7588
+ export { ReducerType, SHOULD_AUTOBATCH, TaskAbortError, Tuple, actionTypes_default as __DO_NOT_USE__ActionTypes, addListener, applyMiddleware, asyncThunkCreator, autoBatchEnhancer, bindActionCreators, buildCreateSlice, clearAllListeners, combineReducers, combineSlices, compose, configureStore, createAction, createActionCreatorInvariantMiddleware, createAsyncThunk, createDraftSafeSelector, createDraftSafeSelectorCreator, createDynamicMiddleware, createEntityAdapter, createImmutableStateInvariantMiddleware, createListenerMiddleware, produce as createNextState, createReducer, createSelector, createSelectorCreator, createSerializableStateInvariantMiddleware, createSlice, createStore, current, findNonSerializableValue, formatProdErrorMessage, freeze, isAction, isActionCreator, isAllOf, isAnyOf, isAsyncThunkAction, isDraft, isFSA as isFluxStandardAction, isFulfilled, isImmutableDefault, isPending, isPlain, isPlainObject$1 as isPlainObject, isRejected, isRejectedWithValue, legacy_createStore, lruMemoize, miniSerializeError, nanoid, original$1 as original, prepareAutoBatched, rtkQueryReact_modern as reactQuery, removeListener, unwrapResult, weakMapMemoize };
6410
7589
  //# sourceMappingURL=index.es.js.map