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