1 |
|
2 | export * from "redux";
|
3 | import { produce, current as current2, freeze, original as original2, isDraft as isDraft4 } from "immer";
|
4 | import { createSelector, createSelectorCreator as createSelectorCreator2, lruMemoize, weakMapMemoize as weakMapMemoize2 } from "reselect";
|
5 |
|
6 |
|
7 | import { current, isDraft } from "immer";
|
8 | import { createSelectorCreator, weakMapMemoize } from "reselect";
|
9 | var createDraftSafeSelectorCreator = (...args) => {
|
10 | const createSelector2 = createSelectorCreator(...args);
|
11 | const createDraftSafeSelector2 = Object.assign((...args2) => {
|
12 | const selector = createSelector2(...args2);
|
13 | const wrappedSelector = (value, ...rest) => selector(isDraft(value) ? current(value) : value, ...rest);
|
14 | Object.assign(wrappedSelector, selector);
|
15 | return wrappedSelector;
|
16 | }, {
|
17 | withTypes: () => createDraftSafeSelector2
|
18 | });
|
19 | return createDraftSafeSelector2;
|
20 | };
|
21 | var createDraftSafeSelector = createDraftSafeSelectorCreator(weakMapMemoize);
|
22 |
|
23 |
|
24 | import { applyMiddleware, createStore, compose as compose2, combineReducers, isPlainObject as isPlainObject2 } from "redux";
|
25 |
|
26 |
|
27 | import { compose } from "redux";
|
28 | var composeWithDevTools = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : function() {
|
29 | if (arguments.length === 0)
|
30 | return void 0;
|
31 | if (typeof arguments[0] === "object")
|
32 | return compose;
|
33 | return compose.apply(null, arguments);
|
34 | };
|
35 | var devToolsEnhancer = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ : function() {
|
36 | return function(noop3) {
|
37 | return noop3;
|
38 | };
|
39 | };
|
40 |
|
41 |
|
42 | import { thunk as thunkMiddleware, withExtraArgument } from "redux-thunk";
|
43 |
|
44 |
|
45 | import { isAction } from "redux";
|
46 |
|
47 |
|
48 | var hasMatchFunction = (v) => {
|
49 | return v && typeof v.match === "function";
|
50 | };
|
51 |
|
52 |
|
53 | function createAction(type, prepareAction) {
|
54 | function actionCreator(...args) {
|
55 | if (prepareAction) {
|
56 | let prepared = prepareAction(...args);
|
57 | if (!prepared) {
|
58 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(0) : "prepareAction did not return an object");
|
59 | }
|
60 | return {
|
61 | type,
|
62 | payload: prepared.payload,
|
63 | ..."meta" in prepared && {
|
64 | meta: prepared.meta
|
65 | },
|
66 | ..."error" in prepared && {
|
67 | error: prepared.error
|
68 | }
|
69 | };
|
70 | }
|
71 | return {
|
72 | type,
|
73 | payload: args[0]
|
74 | };
|
75 | }
|
76 | actionCreator.toString = () => `${type}`;
|
77 | actionCreator.type = type;
|
78 | actionCreator.match = (action) => isAction(action) && action.type === type;
|
79 | return actionCreator;
|
80 | }
|
81 | function isActionCreator(action) {
|
82 | return typeof action === "function" && "type" in action &&
|
83 | hasMatchFunction(action);
|
84 | }
|
85 | function isFSA(action) {
|
86 | return isAction(action) && Object.keys(action).every(isValidKey);
|
87 | }
|
88 | function isValidKey(key) {
|
89 | return ["type", "payload", "error", "meta"].indexOf(key) > -1;
|
90 | }
|
91 |
|
92 |
|
93 | function getMessage(type) {
|
94 | const splitType = type ? `${type}`.split("/") : [];
|
95 | const actionName = splitType[splitType.length - 1] || "actionCreator";
|
96 | return `Detected an action creator with type "${type || "unknown"}" being dispatched.
|
97 | Make sure you're calling the action creator before dispatching, i.e. \`dispatch(${actionName}())\` instead of \`dispatch(${actionName})\`. This is necessary even if the action has no payload.`;
|
98 | }
|
99 | function createActionCreatorInvariantMiddleware(options = {}) {
|
100 | if (process.env.NODE_ENV === "production") {
|
101 | return () => (next) => (action) => next(action);
|
102 | }
|
103 | const {
|
104 | isActionCreator: isActionCreator2 = isActionCreator
|
105 | } = options;
|
106 | return () => (next) => (action) => {
|
107 | if (isActionCreator2(action)) {
|
108 | console.warn(getMessage(action.type));
|
109 | }
|
110 | return next(action);
|
111 | };
|
112 | }
|
113 |
|
114 |
|
115 | import { produce as createNextState, isDraftable } from "immer";
|
116 | function getTimeMeasureUtils(maxDelay, fnName) {
|
117 | let elapsed = 0;
|
118 | return {
|
119 | measureTime(fn) {
|
120 | const started = Date.now();
|
121 | try {
|
122 | return fn();
|
123 | } finally {
|
124 | const finished = Date.now();
|
125 | elapsed += finished - started;
|
126 | }
|
127 | },
|
128 | warnIfExceeded() {
|
129 | if (elapsed > maxDelay) {
|
130 | console.warn(`${fnName} took ${elapsed}ms, which is more than the warning threshold of ${maxDelay}ms.
|
131 | If your state or actions are very large, you may want to disable the middleware as it might cause too much of a slowdown in development mode. See https://redux-toolkit.js.org/api/getDefaultMiddleware for instructions.
|
132 | It is disabled in production builds, so you don't need to worry about that.`);
|
133 | }
|
134 | }
|
135 | };
|
136 | }
|
137 | function find(iterable, comparator) {
|
138 | for (const entry of iterable) {
|
139 | if (comparator(entry)) {
|
140 | return entry;
|
141 | }
|
142 | }
|
143 | return void 0;
|
144 | }
|
145 | var Tuple = class _Tuple extends Array {
|
146 | constructor(...items) {
|
147 | super(...items);
|
148 | Object.setPrototypeOf(this, _Tuple.prototype);
|
149 | }
|
150 | static get [Symbol.species]() {
|
151 | return _Tuple;
|
152 | }
|
153 | concat(...arr) {
|
154 | return super.concat.apply(this, arr);
|
155 | }
|
156 | prepend(...arr) {
|
157 | if (arr.length === 1 && Array.isArray(arr[0])) {
|
158 | return new _Tuple(...arr[0].concat(this));
|
159 | }
|
160 | return new _Tuple(...arr.concat(this));
|
161 | }
|
162 | };
|
163 | function freezeDraftable(val) {
|
164 | return isDraftable(val) ? createNextState(val, () => {
|
165 | }) : val;
|
166 | }
|
167 | function emplace(map, key, handler) {
|
168 | if (map.has(key)) {
|
169 | let value = map.get(key);
|
170 | if (handler.update) {
|
171 | value = handler.update(value, key, map);
|
172 | map.set(key, value);
|
173 | }
|
174 | return value;
|
175 | }
|
176 | if (!handler.insert)
|
177 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(10) : "No insert provided for key not already in map");
|
178 | const inserted = handler.insert(key, map);
|
179 | map.set(key, inserted);
|
180 | return inserted;
|
181 | }
|
182 |
|
183 |
|
184 | function isImmutableDefault(value) {
|
185 | return typeof value !== "object" || value == null || Object.isFrozen(value);
|
186 | }
|
187 | function trackForMutations(isImmutable, ignorePaths, obj) {
|
188 | const trackedProperties = trackProperties(isImmutable, ignorePaths, obj);
|
189 | return {
|
190 | detectMutations() {
|
191 | return detectMutations(isImmutable, ignorePaths, trackedProperties, obj);
|
192 | }
|
193 | };
|
194 | }
|
195 | function trackProperties(isImmutable, ignorePaths = [], obj, path = "", checkedObjects = /* @__PURE__ */ new Set()) {
|
196 | const tracked = {
|
197 | value: obj
|
198 | };
|
199 | if (!isImmutable(obj) && !checkedObjects.has(obj)) {
|
200 | checkedObjects.add(obj);
|
201 | tracked.children = {};
|
202 | for (const key in obj) {
|
203 | const childPath = path ? path + "." + key : key;
|
204 | if (ignorePaths.length && ignorePaths.indexOf(childPath) !== -1) {
|
205 | continue;
|
206 | }
|
207 | tracked.children[key] = trackProperties(isImmutable, ignorePaths, obj[key], childPath);
|
208 | }
|
209 | }
|
210 | return tracked;
|
211 | }
|
212 | function detectMutations(isImmutable, ignoredPaths = [], trackedProperty, obj, sameParentRef = false, path = "") {
|
213 | const prevObj = trackedProperty ? trackedProperty.value : void 0;
|
214 | const sameRef = prevObj === obj;
|
215 | if (sameParentRef && !sameRef && !Number.isNaN(obj)) {
|
216 | return {
|
217 | wasMutated: true,
|
218 | path
|
219 | };
|
220 | }
|
221 | if (isImmutable(prevObj) || isImmutable(obj)) {
|
222 | return {
|
223 | wasMutated: false
|
224 | };
|
225 | }
|
226 | const keysToDetect = {};
|
227 | for (let key in trackedProperty.children) {
|
228 | keysToDetect[key] = true;
|
229 | }
|
230 | for (let key in obj) {
|
231 | keysToDetect[key] = true;
|
232 | }
|
233 | const hasIgnoredPaths = ignoredPaths.length > 0;
|
234 | for (let key in keysToDetect) {
|
235 | const nestedPath = path ? path + "." + key : key;
|
236 | if (hasIgnoredPaths) {
|
237 | const hasMatches = ignoredPaths.some((ignored) => {
|
238 | if (ignored instanceof RegExp) {
|
239 | return ignored.test(nestedPath);
|
240 | }
|
241 | return nestedPath === ignored;
|
242 | });
|
243 | if (hasMatches) {
|
244 | continue;
|
245 | }
|
246 | }
|
247 | const result = detectMutations(isImmutable, ignoredPaths, trackedProperty.children[key], obj[key], sameRef, nestedPath);
|
248 | if (result.wasMutated) {
|
249 | return result;
|
250 | }
|
251 | }
|
252 | return {
|
253 | wasMutated: false
|
254 | };
|
255 | }
|
256 | function createImmutableStateInvariantMiddleware(options = {}) {
|
257 | if (process.env.NODE_ENV === "production") {
|
258 | return () => (next) => (action) => next(action);
|
259 | } else {
|
260 | let stringify2 = function(obj, serializer, indent, decycler) {
|
261 | return JSON.stringify(obj, getSerialize2(serializer, decycler), indent);
|
262 | }, getSerialize2 = function(serializer, decycler) {
|
263 | let stack = [], keys = [];
|
264 | if (!decycler)
|
265 | decycler = function(_, value) {
|
266 | if (stack[0] === value)
|
267 | return "[Circular ~]";
|
268 | return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
|
269 | };
|
270 | return function(key, value) {
|
271 | if (stack.length > 0) {
|
272 | var thisPos = stack.indexOf(this);
|
273 | ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
|
274 | ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
|
275 | if (~stack.indexOf(value))
|
276 | value = decycler.call(this, key, value);
|
277 | } else
|
278 | stack.push(value);
|
279 | return serializer == null ? value : serializer.call(this, key, value);
|
280 | };
|
281 | };
|
282 | var stringify = stringify2, getSerialize = getSerialize2;
|
283 | let {
|
284 | isImmutable = isImmutableDefault,
|
285 | ignoredPaths,
|
286 | warnAfter = 32
|
287 | } = options;
|
288 | const track = trackForMutations.bind(null, isImmutable, ignoredPaths);
|
289 | return ({
|
290 | getState
|
291 | }) => {
|
292 | let state = getState();
|
293 | let tracker = track(state);
|
294 | let result;
|
295 | return (next) => (action) => {
|
296 | const measureUtils = getTimeMeasureUtils(warnAfter, "ImmutableStateInvariantMiddleware");
|
297 | measureUtils.measureTime(() => {
|
298 | state = getState();
|
299 | result = tracker.detectMutations();
|
300 | tracker = track(state);
|
301 | if (result.wasMutated) {
|
302 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(19) : `A state mutation was detected between dispatches, in the path '${result.path || ""}'. This may cause incorrect behavior. (https://redux.js.org/style-guide/style-guide#do-not-mutate-state)`);
|
303 | }
|
304 | });
|
305 | const dispatchedAction = next(action);
|
306 | measureUtils.measureTime(() => {
|
307 | state = getState();
|
308 | result = tracker.detectMutations();
|
309 | tracker = track(state);
|
310 | if (result.wasMutated) {
|
311 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(20) : `A state mutation was detected inside a dispatch, in the path: ${result.path || ""}. Take a look at the reducer(s) handling the action ${stringify2(action)}. (https://redux.js.org/style-guide/style-guide#do-not-mutate-state)`);
|
312 | }
|
313 | });
|
314 | measureUtils.warnIfExceeded();
|
315 | return dispatchedAction;
|
316 | };
|
317 | };
|
318 | }
|
319 | }
|
320 |
|
321 |
|
322 | import { isAction as isAction2, isPlainObject } from "redux";
|
323 | function isPlain(val) {
|
324 | const type = typeof val;
|
325 | return val == null || type === "string" || type === "boolean" || type === "number" || Array.isArray(val) || isPlainObject(val);
|
326 | }
|
327 | function findNonSerializableValue(value, path = "", isSerializable = isPlain, getEntries, ignoredPaths = [], cache) {
|
328 | let foundNestedSerializable;
|
329 | if (!isSerializable(value)) {
|
330 | return {
|
331 | keyPath: path || "<root>",
|
332 | value
|
333 | };
|
334 | }
|
335 | if (typeof value !== "object" || value === null) {
|
336 | return false;
|
337 | }
|
338 | if (cache?.has(value))
|
339 | return false;
|
340 | const entries = getEntries != null ? getEntries(value) : Object.entries(value);
|
341 | const hasIgnoredPaths = ignoredPaths.length > 0;
|
342 | for (const [key, nestedValue] of entries) {
|
343 | const nestedPath = path ? path + "." + key : key;
|
344 | if (hasIgnoredPaths) {
|
345 | const hasMatches = ignoredPaths.some((ignored) => {
|
346 | if (ignored instanceof RegExp) {
|
347 | return ignored.test(nestedPath);
|
348 | }
|
349 | return nestedPath === ignored;
|
350 | });
|
351 | if (hasMatches) {
|
352 | continue;
|
353 | }
|
354 | }
|
355 | if (!isSerializable(nestedValue)) {
|
356 | return {
|
357 | keyPath: nestedPath,
|
358 | value: nestedValue
|
359 | };
|
360 | }
|
361 | if (typeof nestedValue === "object") {
|
362 | foundNestedSerializable = findNonSerializableValue(nestedValue, nestedPath, isSerializable, getEntries, ignoredPaths, cache);
|
363 | if (foundNestedSerializable) {
|
364 | return foundNestedSerializable;
|
365 | }
|
366 | }
|
367 | }
|
368 | if (cache && isNestedFrozen(value))
|
369 | cache.add(value);
|
370 | return false;
|
371 | }
|
372 | function isNestedFrozen(value) {
|
373 | if (!Object.isFrozen(value))
|
374 | return false;
|
375 | for (const nestedValue of Object.values(value)) {
|
376 | if (typeof nestedValue !== "object" || nestedValue === null)
|
377 | continue;
|
378 | if (!isNestedFrozen(nestedValue))
|
379 | return false;
|
380 | }
|
381 | return true;
|
382 | }
|
383 | function createSerializableStateInvariantMiddleware(options = {}) {
|
384 | if (process.env.NODE_ENV === "production") {
|
385 | return () => (next) => (action) => next(action);
|
386 | } else {
|
387 | const {
|
388 | isSerializable = isPlain,
|
389 | getEntries,
|
390 | ignoredActions = [],
|
391 | ignoredActionPaths = ["meta.arg", "meta.baseQueryMeta"],
|
392 | ignoredPaths = [],
|
393 | warnAfter = 32,
|
394 | ignoreState = false,
|
395 | ignoreActions = false,
|
396 | disableCache = false
|
397 | } = options;
|
398 | const cache = !disableCache && WeakSet ? new WeakSet() : void 0;
|
399 | return (storeAPI) => (next) => (action) => {
|
400 | if (!isAction2(action)) {
|
401 | return next(action);
|
402 | }
|
403 | const result = next(action);
|
404 | const measureUtils = getTimeMeasureUtils(warnAfter, "SerializableStateInvariantMiddleware");
|
405 | if (!ignoreActions && !(ignoredActions.length && ignoredActions.indexOf(action.type) !== -1)) {
|
406 | measureUtils.measureTime(() => {
|
407 | const foundActionNonSerializableValue = findNonSerializableValue(action, "", isSerializable, getEntries, ignoredActionPaths, cache);
|
408 | if (foundActionNonSerializableValue) {
|
409 | const {
|
410 | keyPath,
|
411 | value
|
412 | } = foundActionNonSerializableValue;
|
413 | console.error(`A non-serializable value was detected in an action, in the path: \`${keyPath}\`. Value:`, value, "\nTake a look at the logic that dispatched this action: ", action, "\n(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)", "\n(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)");
|
414 | }
|
415 | });
|
416 | }
|
417 | if (!ignoreState) {
|
418 | measureUtils.measureTime(() => {
|
419 | const state = storeAPI.getState();
|
420 | const foundStateNonSerializableValue = findNonSerializableValue(state, "", isSerializable, getEntries, ignoredPaths, cache);
|
421 | if (foundStateNonSerializableValue) {
|
422 | const {
|
423 | keyPath,
|
424 | value
|
425 | } = foundStateNonSerializableValue;
|
426 | console.error(`A non-serializable value was detected in the state, in the path: \`${keyPath}\`. Value:`, value, `
|
427 | Take a look at the reducer(s) handling this action type: ${action.type}.
|
428 | (See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)`);
|
429 | }
|
430 | });
|
431 | measureUtils.warnIfExceeded();
|
432 | }
|
433 | return result;
|
434 | };
|
435 | }
|
436 | }
|
437 |
|
438 |
|
439 | function isBoolean(x) {
|
440 | return typeof x === "boolean";
|
441 | }
|
442 | var buildGetDefaultMiddleware = () => function getDefaultMiddleware(options) {
|
443 | const {
|
444 | thunk = true,
|
445 | immutableCheck = true,
|
446 | serializableCheck = true,
|
447 | actionCreatorCheck = true
|
448 | } = options ?? {};
|
449 | let middlewareArray = new Tuple();
|
450 | if (thunk) {
|
451 | if (isBoolean(thunk)) {
|
452 | middlewareArray.push(thunkMiddleware);
|
453 | } else {
|
454 | middlewareArray.push(withExtraArgument(thunk.extraArgument));
|
455 | }
|
456 | }
|
457 | if (process.env.NODE_ENV !== "production") {
|
458 | if (immutableCheck) {
|
459 | let immutableOptions = {};
|
460 | if (!isBoolean(immutableCheck)) {
|
461 | immutableOptions = immutableCheck;
|
462 | }
|
463 | middlewareArray.unshift(createImmutableStateInvariantMiddleware(immutableOptions));
|
464 | }
|
465 | if (serializableCheck) {
|
466 | let serializableOptions = {};
|
467 | if (!isBoolean(serializableCheck)) {
|
468 | serializableOptions = serializableCheck;
|
469 | }
|
470 | middlewareArray.push(createSerializableStateInvariantMiddleware(serializableOptions));
|
471 | }
|
472 | if (actionCreatorCheck) {
|
473 | let actionCreatorOptions = {};
|
474 | if (!isBoolean(actionCreatorCheck)) {
|
475 | actionCreatorOptions = actionCreatorCheck;
|
476 | }
|
477 | middlewareArray.unshift(createActionCreatorInvariantMiddleware(actionCreatorOptions));
|
478 | }
|
479 | }
|
480 | return middlewareArray;
|
481 | };
|
482 |
|
483 |
|
484 | var SHOULD_AUTOBATCH = "RTK_autoBatch";
|
485 | var prepareAutoBatched = () => (payload) => ({
|
486 | payload,
|
487 | meta: {
|
488 | [SHOULD_AUTOBATCH]: true
|
489 | }
|
490 | });
|
491 | var createQueueWithTimer = (timeout) => {
|
492 | return (notify) => {
|
493 | setTimeout(notify, timeout);
|
494 | };
|
495 | };
|
496 | var rAF = typeof window !== "undefined" && window.requestAnimationFrame ? window.requestAnimationFrame : createQueueWithTimer(10);
|
497 | var autoBatchEnhancer = (options = {
|
498 | type: "raf"
|
499 | }) => (next) => (...args) => {
|
500 | const store = next(...args);
|
501 | let notifying = true;
|
502 | let shouldNotifyAtEndOfTick = false;
|
503 | let notificationQueued = false;
|
504 | const listeners = new Set();
|
505 | const queueCallback = options.type === "tick" ? queueMicrotask : options.type === "raf" ? rAF : options.type === "callback" ? options.queueNotification : createQueueWithTimer(options.timeout);
|
506 | const notifyListeners = () => {
|
507 | notificationQueued = false;
|
508 | if (shouldNotifyAtEndOfTick) {
|
509 | shouldNotifyAtEndOfTick = false;
|
510 | listeners.forEach((l) => l());
|
511 | }
|
512 | };
|
513 | return Object.assign({}, store, {
|
514 |
|
515 |
|
516 | subscribe(listener2) {
|
517 | const wrappedListener = () => notifying && listener2();
|
518 | const unsubscribe = store.subscribe(wrappedListener);
|
519 | listeners.add(listener2);
|
520 | return () => {
|
521 | unsubscribe();
|
522 | listeners.delete(listener2);
|
523 | };
|
524 | },
|
525 |
|
526 |
|
527 | dispatch(action) {
|
528 | try {
|
529 | notifying = !action?.meta?.[SHOULD_AUTOBATCH];
|
530 | shouldNotifyAtEndOfTick = !notifying;
|
531 | if (shouldNotifyAtEndOfTick) {
|
532 | if (!notificationQueued) {
|
533 | notificationQueued = true;
|
534 | queueCallback(notifyListeners);
|
535 | }
|
536 | }
|
537 | return store.dispatch(action);
|
538 | } finally {
|
539 | notifying = true;
|
540 | }
|
541 | }
|
542 | });
|
543 | };
|
544 |
|
545 |
|
546 | var buildGetDefaultEnhancers = (middlewareEnhancer) => function getDefaultEnhancers(options) {
|
547 | const {
|
548 | autoBatch = true
|
549 | } = options ?? {};
|
550 | let enhancerArray = new Tuple(middlewareEnhancer);
|
551 | if (autoBatch) {
|
552 | enhancerArray.push(autoBatchEnhancer(typeof autoBatch === "object" ? autoBatch : void 0));
|
553 | }
|
554 | return enhancerArray;
|
555 | };
|
556 |
|
557 |
|
558 | var IS_PRODUCTION = process.env.NODE_ENV === "production";
|
559 | function configureStore(options) {
|
560 | const getDefaultMiddleware = buildGetDefaultMiddleware();
|
561 | const {
|
562 | reducer = void 0,
|
563 | middleware,
|
564 | devTools = true,
|
565 | preloadedState = void 0,
|
566 | enhancers = void 0
|
567 | } = options || {};
|
568 | let rootReducer;
|
569 | if (typeof reducer === "function") {
|
570 | rootReducer = reducer;
|
571 | } else if (isPlainObject2(reducer)) {
|
572 | rootReducer = combineReducers(reducer);
|
573 | } else {
|
574 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(1) : "`reducer` is a required argument, and must be a function or an object of functions that can be passed to combineReducers");
|
575 | }
|
576 | if (!IS_PRODUCTION && middleware && typeof middleware !== "function") {
|
577 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(2) : "`middleware` field must be a callback");
|
578 | }
|
579 | let finalMiddleware;
|
580 | if (typeof middleware === "function") {
|
581 | finalMiddleware = middleware(getDefaultMiddleware);
|
582 | if (!IS_PRODUCTION && !Array.isArray(finalMiddleware)) {
|
583 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(3) : "when using a middleware builder function, an array of middleware must be returned");
|
584 | }
|
585 | } else {
|
586 | finalMiddleware = getDefaultMiddleware();
|
587 | }
|
588 | if (!IS_PRODUCTION && finalMiddleware.some((item) => typeof item !== "function")) {
|
589 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(4) : "each middleware provided to configureStore must be a function");
|
590 | }
|
591 | let finalCompose = compose2;
|
592 | if (devTools) {
|
593 | finalCompose = composeWithDevTools({
|
594 |
|
595 | trace: !IS_PRODUCTION,
|
596 | ...typeof devTools === "object" && devTools
|
597 | });
|
598 | }
|
599 | const middlewareEnhancer = applyMiddleware(...finalMiddleware);
|
600 | const getDefaultEnhancers = buildGetDefaultEnhancers(middlewareEnhancer);
|
601 | if (!IS_PRODUCTION && enhancers && typeof enhancers !== "function") {
|
602 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(5) : "`enhancers` field must be a callback");
|
603 | }
|
604 | let storeEnhancers = typeof enhancers === "function" ? enhancers(getDefaultEnhancers) : getDefaultEnhancers();
|
605 | if (!IS_PRODUCTION && !Array.isArray(storeEnhancers)) {
|
606 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(6) : "`enhancers` callback must return an array");
|
607 | }
|
608 | if (!IS_PRODUCTION && storeEnhancers.some((item) => typeof item !== "function")) {
|
609 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(7) : "each enhancer provided to configureStore must be a function");
|
610 | }
|
611 | if (!IS_PRODUCTION && finalMiddleware.length && !storeEnhancers.includes(middlewareEnhancer)) {
|
612 | console.error("middlewares were provided, but middleware enhancer was not included in final enhancers - make sure to call `getDefaultEnhancers`");
|
613 | }
|
614 | const composedEnhancer = finalCompose(...storeEnhancers);
|
615 | return createStore(rootReducer, preloadedState, composedEnhancer);
|
616 | }
|
617 |
|
618 |
|
619 | import { produce as createNextState2, isDraft as isDraft2, isDraftable as isDraftable2 } from "immer";
|
620 |
|
621 |
|
622 | function executeReducerBuilderCallback(builderCallback) {
|
623 | const actionsMap = {};
|
624 | const actionMatchers = [];
|
625 | let defaultCaseReducer;
|
626 | const builder = {
|
627 | addCase(typeOrActionCreator, reducer) {
|
628 | if (process.env.NODE_ENV !== "production") {
|
629 | if (actionMatchers.length > 0) {
|
630 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(26) : "`builder.addCase` should only be called before calling `builder.addMatcher`");
|
631 | }
|
632 | if (defaultCaseReducer) {
|
633 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(27) : "`builder.addCase` should only be called before calling `builder.addDefaultCase`");
|
634 | }
|
635 | }
|
636 | const type = typeof typeOrActionCreator === "string" ? typeOrActionCreator : typeOrActionCreator.type;
|
637 | if (!type) {
|
638 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(28) : "`builder.addCase` cannot be called with an empty action type");
|
639 | }
|
640 | if (type in actionsMap) {
|
641 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(29) : `\`builder.addCase\` cannot be called with two reducers for the same action type '${type}'`);
|
642 | }
|
643 | actionsMap[type] = reducer;
|
644 | return builder;
|
645 | },
|
646 | addMatcher(matcher, reducer) {
|
647 | if (process.env.NODE_ENV !== "production") {
|
648 | if (defaultCaseReducer) {
|
649 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(30) : "`builder.addMatcher` should only be called before calling `builder.addDefaultCase`");
|
650 | }
|
651 | }
|
652 | actionMatchers.push({
|
653 | matcher,
|
654 | reducer
|
655 | });
|
656 | return builder;
|
657 | },
|
658 | addDefaultCase(reducer) {
|
659 | if (process.env.NODE_ENV !== "production") {
|
660 | if (defaultCaseReducer) {
|
661 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(31) : "`builder.addDefaultCase` can only be called once");
|
662 | }
|
663 | }
|
664 | defaultCaseReducer = reducer;
|
665 | return builder;
|
666 | }
|
667 | };
|
668 | builderCallback(builder);
|
669 | return [actionsMap, actionMatchers, defaultCaseReducer];
|
670 | }
|
671 |
|
672 |
|
673 | function isStateFunction(x) {
|
674 | return typeof x === "function";
|
675 | }
|
676 | function createReducer(initialState, mapOrBuilderCallback) {
|
677 | if (process.env.NODE_ENV !== "production") {
|
678 | if (typeof mapOrBuilderCallback === "object") {
|
679 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(8) : "The object notation for `createReducer` has been removed. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createReducer");
|
680 | }
|
681 | }
|
682 | let [actionsMap, finalActionMatchers, finalDefaultCaseReducer] = executeReducerBuilderCallback(mapOrBuilderCallback);
|
683 | let getInitialState;
|
684 | if (isStateFunction(initialState)) {
|
685 | getInitialState = () => freezeDraftable(initialState());
|
686 | } else {
|
687 | const frozenInitialState = freezeDraftable(initialState);
|
688 | getInitialState = () => frozenInitialState;
|
689 | }
|
690 | function reducer(state = getInitialState(), action) {
|
691 | let caseReducers = [actionsMap[action.type], ...finalActionMatchers.filter(({
|
692 | matcher
|
693 | }) => matcher(action)).map(({
|
694 | reducer: reducer2
|
695 | }) => reducer2)];
|
696 | if (caseReducers.filter((cr) => !!cr).length === 0) {
|
697 | caseReducers = [finalDefaultCaseReducer];
|
698 | }
|
699 | return caseReducers.reduce((previousState, caseReducer) => {
|
700 | if (caseReducer) {
|
701 | if (isDraft2(previousState)) {
|
702 | const draft = previousState;
|
703 | const result = caseReducer(draft, action);
|
704 | if (result === void 0) {
|
705 | return previousState;
|
706 | }
|
707 | return result;
|
708 | } else if (!isDraftable2(previousState)) {
|
709 | const result = caseReducer(previousState, action);
|
710 | if (result === void 0) {
|
711 | if (previousState === null) {
|
712 | return previousState;
|
713 | }
|
714 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(9) : "A case reducer on a non-draftable value must not return undefined");
|
715 | }
|
716 | return result;
|
717 | } else {
|
718 | return createNextState2(previousState, (draft) => {
|
719 | return caseReducer(draft, action);
|
720 | });
|
721 | }
|
722 | }
|
723 | return previousState;
|
724 | }, state);
|
725 | }
|
726 | reducer.getInitialState = getInitialState;
|
727 | return reducer;
|
728 | }
|
729 |
|
730 |
|
731 | var urlAlphabet = "ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW";
|
732 | var nanoid = (size = 21) => {
|
733 | let id = "";
|
734 | let i = size;
|
735 | while (i--) {
|
736 | id += urlAlphabet[Math.random() * 64 | 0];
|
737 | }
|
738 | return id;
|
739 | };
|
740 |
|
741 |
|
742 | var matches = (matcher, action) => {
|
743 | if (hasMatchFunction(matcher)) {
|
744 | return matcher.match(action);
|
745 | } else {
|
746 | return matcher(action);
|
747 | }
|
748 | };
|
749 | function isAnyOf(...matchers) {
|
750 | return (action) => {
|
751 | return matchers.some((matcher) => matches(matcher, action));
|
752 | };
|
753 | }
|
754 | function isAllOf(...matchers) {
|
755 | return (action) => {
|
756 | return matchers.every((matcher) => matches(matcher, action));
|
757 | };
|
758 | }
|
759 | function hasExpectedRequestMetadata(action, validStatus) {
|
760 | if (!action || !action.meta)
|
761 | return false;
|
762 | const hasValidRequestId = typeof action.meta.requestId === "string";
|
763 | const hasValidRequestStatus = validStatus.indexOf(action.meta.requestStatus) > -1;
|
764 | return hasValidRequestId && hasValidRequestStatus;
|
765 | }
|
766 | function isAsyncThunkArray(a) {
|
767 | return typeof a[0] === "function" && "pending" in a[0] && "fulfilled" in a[0] && "rejected" in a[0];
|
768 | }
|
769 | function isPending(...asyncThunks) {
|
770 | if (asyncThunks.length === 0) {
|
771 | return (action) => hasExpectedRequestMetadata(action, ["pending"]);
|
772 | }
|
773 | if (!isAsyncThunkArray(asyncThunks)) {
|
774 | return isPending()(asyncThunks[0]);
|
775 | }
|
776 | return (action) => {
|
777 | const matchers = asyncThunks.map((asyncThunk) => asyncThunk.pending);
|
778 | const combinedMatcher = isAnyOf(...matchers);
|
779 | return combinedMatcher(action);
|
780 | };
|
781 | }
|
782 | function isRejected(...asyncThunks) {
|
783 | if (asyncThunks.length === 0) {
|
784 | return (action) => hasExpectedRequestMetadata(action, ["rejected"]);
|
785 | }
|
786 | if (!isAsyncThunkArray(asyncThunks)) {
|
787 | return isRejected()(asyncThunks[0]);
|
788 | }
|
789 | return (action) => {
|
790 | const matchers = asyncThunks.map((asyncThunk) => asyncThunk.rejected);
|
791 | const combinedMatcher = isAnyOf(...matchers);
|
792 | return combinedMatcher(action);
|
793 | };
|
794 | }
|
795 | function isRejectedWithValue(...asyncThunks) {
|
796 | const hasFlag = (action) => {
|
797 | return action && action.meta && action.meta.rejectedWithValue;
|
798 | };
|
799 | if (asyncThunks.length === 0) {
|
800 | return (action) => {
|
801 | const combinedMatcher = isAllOf(isRejected(...asyncThunks), hasFlag);
|
802 | return combinedMatcher(action);
|
803 | };
|
804 | }
|
805 | if (!isAsyncThunkArray(asyncThunks)) {
|
806 | return isRejectedWithValue()(asyncThunks[0]);
|
807 | }
|
808 | return (action) => {
|
809 | const combinedMatcher = isAllOf(isRejected(...asyncThunks), hasFlag);
|
810 | return combinedMatcher(action);
|
811 | };
|
812 | }
|
813 | function isFulfilled(...asyncThunks) {
|
814 | if (asyncThunks.length === 0) {
|
815 | return (action) => hasExpectedRequestMetadata(action, ["fulfilled"]);
|
816 | }
|
817 | if (!isAsyncThunkArray(asyncThunks)) {
|
818 | return isFulfilled()(asyncThunks[0]);
|
819 | }
|
820 | return (action) => {
|
821 | const matchers = asyncThunks.map((asyncThunk) => asyncThunk.fulfilled);
|
822 | const combinedMatcher = isAnyOf(...matchers);
|
823 | return combinedMatcher(action);
|
824 | };
|
825 | }
|
826 | function isAsyncThunkAction(...asyncThunks) {
|
827 | if (asyncThunks.length === 0) {
|
828 | return (action) => hasExpectedRequestMetadata(action, ["pending", "fulfilled", "rejected"]);
|
829 | }
|
830 | if (!isAsyncThunkArray(asyncThunks)) {
|
831 | return isAsyncThunkAction()(asyncThunks[0]);
|
832 | }
|
833 | return (action) => {
|
834 | const matchers = [];
|
835 | for (const asyncThunk of asyncThunks) {
|
836 | matchers.push(asyncThunk.pending, asyncThunk.rejected, asyncThunk.fulfilled);
|
837 | }
|
838 | const combinedMatcher = isAnyOf(...matchers);
|
839 | return combinedMatcher(action);
|
840 | };
|
841 | }
|
842 |
|
843 |
|
844 | var commonProperties = ["name", "message", "stack", "code"];
|
845 | var RejectWithValue = class {
|
846 | constructor(payload, meta) {
|
847 | this.payload = payload;
|
848 | this.meta = meta;
|
849 | }
|
850 | |
851 |
|
852 |
|
853 |
|
854 | _type;
|
855 | };
|
856 | var FulfillWithMeta = class {
|
857 | constructor(payload, meta) {
|
858 | this.payload = payload;
|
859 | this.meta = meta;
|
860 | }
|
861 | |
862 |
|
863 |
|
864 |
|
865 | _type;
|
866 | };
|
867 | var miniSerializeError = (value) => {
|
868 | if (typeof value === "object" && value !== null) {
|
869 | const simpleError = {};
|
870 | for (const property of commonProperties) {
|
871 | if (typeof value[property] === "string") {
|
872 | simpleError[property] = value[property];
|
873 | }
|
874 | }
|
875 | return simpleError;
|
876 | }
|
877 | return {
|
878 | message: String(value)
|
879 | };
|
880 | };
|
881 | var createAsyncThunk = (() => {
|
882 | function createAsyncThunk2(typePrefix, payloadCreator, options) {
|
883 | const fulfilled = createAction(typePrefix + "/fulfilled", (payload, requestId, arg, meta) => ({
|
884 | payload,
|
885 | meta: {
|
886 | ...meta || {},
|
887 | arg,
|
888 | requestId,
|
889 | requestStatus: "fulfilled"
|
890 | }
|
891 | }));
|
892 | const pending = createAction(typePrefix + "/pending", (requestId, arg, meta) => ({
|
893 | payload: void 0,
|
894 | meta: {
|
895 | ...meta || {},
|
896 | arg,
|
897 | requestId,
|
898 | requestStatus: "pending"
|
899 | }
|
900 | }));
|
901 | const rejected = createAction(typePrefix + "/rejected", (error, requestId, arg, payload, meta) => ({
|
902 | payload,
|
903 | error: (options && options.serializeError || miniSerializeError)(error || "Rejected"),
|
904 | meta: {
|
905 | ...meta || {},
|
906 | arg,
|
907 | requestId,
|
908 | rejectedWithValue: !!payload,
|
909 | requestStatus: "rejected",
|
910 | aborted: error?.name === "AbortError",
|
911 | condition: error?.name === "ConditionError"
|
912 | }
|
913 | }));
|
914 | function actionCreator(arg) {
|
915 | return (dispatch, getState, extra) => {
|
916 | const requestId = options?.idGenerator ? options.idGenerator(arg) : nanoid();
|
917 | const abortController = new AbortController();
|
918 | let abortHandler;
|
919 | let abortReason;
|
920 | function abort(reason) {
|
921 | abortReason = reason;
|
922 | abortController.abort();
|
923 | }
|
924 | const promise = async function() {
|
925 | let finalAction;
|
926 | try {
|
927 | let conditionResult = options?.condition?.(arg, {
|
928 | getState,
|
929 | extra
|
930 | });
|
931 | if (isThenable(conditionResult)) {
|
932 | conditionResult = await conditionResult;
|
933 | }
|
934 | if (conditionResult === false || abortController.signal.aborted) {
|
935 | throw {
|
936 | name: "ConditionError",
|
937 | message: "Aborted due to condition callback returning false."
|
938 | };
|
939 | }
|
940 | const abortedPromise = new Promise((_, reject) => {
|
941 | abortHandler = () => {
|
942 | reject({
|
943 | name: "AbortError",
|
944 | message: abortReason || "Aborted"
|
945 | });
|
946 | };
|
947 | abortController.signal.addEventListener("abort", abortHandler);
|
948 | });
|
949 | dispatch(pending(requestId, arg, options?.getPendingMeta?.({
|
950 | requestId,
|
951 | arg
|
952 | }, {
|
953 | getState,
|
954 | extra
|
955 | })));
|
956 | finalAction = await Promise.race([abortedPromise, Promise.resolve(payloadCreator(arg, {
|
957 | dispatch,
|
958 | getState,
|
959 | extra,
|
960 | requestId,
|
961 | signal: abortController.signal,
|
962 | abort,
|
963 | rejectWithValue: (value, meta) => {
|
964 | return new RejectWithValue(value, meta);
|
965 | },
|
966 | fulfillWithValue: (value, meta) => {
|
967 | return new FulfillWithMeta(value, meta);
|
968 | }
|
969 | })).then((result) => {
|
970 | if (result instanceof RejectWithValue) {
|
971 | throw result;
|
972 | }
|
973 | if (result instanceof FulfillWithMeta) {
|
974 | return fulfilled(result.payload, requestId, arg, result.meta);
|
975 | }
|
976 | return fulfilled(result, requestId, arg);
|
977 | })]);
|
978 | } catch (err) {
|
979 | finalAction = err instanceof RejectWithValue ? rejected(null, requestId, arg, err.payload, err.meta) : rejected(err, requestId, arg);
|
980 | } finally {
|
981 | if (abortHandler) {
|
982 | abortController.signal.removeEventListener("abort", abortHandler);
|
983 | }
|
984 | }
|
985 | const skipDispatch = options && !options.dispatchConditionRejection && rejected.match(finalAction) && finalAction.meta.condition;
|
986 | if (!skipDispatch) {
|
987 | dispatch(finalAction);
|
988 | }
|
989 | return finalAction;
|
990 | }();
|
991 | return Object.assign(promise, {
|
992 | abort,
|
993 | requestId,
|
994 | arg,
|
995 | unwrap() {
|
996 | return promise.then(unwrapResult);
|
997 | }
|
998 | });
|
999 | };
|
1000 | }
|
1001 | return Object.assign(actionCreator, {
|
1002 | pending,
|
1003 | rejected,
|
1004 | fulfilled,
|
1005 | settled: isAnyOf(rejected, fulfilled),
|
1006 | typePrefix
|
1007 | });
|
1008 | }
|
1009 | createAsyncThunk2.withTypes = () => createAsyncThunk2;
|
1010 | return createAsyncThunk2;
|
1011 | })();
|
1012 | function unwrapResult(action) {
|
1013 | if (action.meta && action.meta.rejectedWithValue) {
|
1014 | throw action.payload;
|
1015 | }
|
1016 | if (action.error) {
|
1017 | throw action.error;
|
1018 | }
|
1019 | return action.payload;
|
1020 | }
|
1021 | function isThenable(value) {
|
1022 | return value !== null && typeof value === "object" && typeof value.then === "function";
|
1023 | }
|
1024 |
|
1025 |
|
1026 | var asyncThunkSymbol = Symbol.for("rtk-slice-createasyncthunk");
|
1027 | var asyncThunkCreator = {
|
1028 | [asyncThunkSymbol]: createAsyncThunk
|
1029 | };
|
1030 | var ReducerType = ((ReducerType2) => {
|
1031 | ReducerType2["reducer"] = "reducer";
|
1032 | ReducerType2["reducerWithPrepare"] = "reducerWithPrepare";
|
1033 | ReducerType2["asyncThunk"] = "asyncThunk";
|
1034 | return ReducerType2;
|
1035 | })(ReducerType || {});
|
1036 | function getType(slice, actionKey) {
|
1037 | return `${slice}/${actionKey}`;
|
1038 | }
|
1039 | function buildCreateSlice({
|
1040 | creators
|
1041 | } = {}) {
|
1042 | const cAT = creators?.asyncThunk?.[asyncThunkSymbol];
|
1043 | return function createSlice2(options) {
|
1044 | const {
|
1045 | name,
|
1046 | reducerPath = name
|
1047 | } = options;
|
1048 | if (!name) {
|
1049 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(11) : "`name` is a required option for createSlice");
|
1050 | }
|
1051 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
1052 | if (options.initialState === void 0) {
|
1053 | console.error("You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`");
|
1054 | }
|
1055 | }
|
1056 | const reducers = (typeof options.reducers === "function" ? options.reducers(buildReducerCreators()) : options.reducers) || {};
|
1057 | const reducerNames = Object.keys(reducers);
|
1058 | const context = {
|
1059 | sliceCaseReducersByName: {},
|
1060 | sliceCaseReducersByType: {},
|
1061 | actionCreators: {},
|
1062 | sliceMatchers: []
|
1063 | };
|
1064 | const contextMethods = {
|
1065 | addCase(typeOrActionCreator, reducer2) {
|
1066 | const type = typeof typeOrActionCreator === "string" ? typeOrActionCreator : typeOrActionCreator.type;
|
1067 | if (!type) {
|
1068 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(12) : "`context.addCase` cannot be called with an empty action type");
|
1069 | }
|
1070 | if (type in context.sliceCaseReducersByType) {
|
1071 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(13) : "`context.addCase` cannot be called with two reducers for the same action type: " + type);
|
1072 | }
|
1073 | context.sliceCaseReducersByType[type] = reducer2;
|
1074 | return contextMethods;
|
1075 | },
|
1076 | addMatcher(matcher, reducer2) {
|
1077 | context.sliceMatchers.push({
|
1078 | matcher,
|
1079 | reducer: reducer2
|
1080 | });
|
1081 | return contextMethods;
|
1082 | },
|
1083 | exposeAction(name2, actionCreator) {
|
1084 | context.actionCreators[name2] = actionCreator;
|
1085 | return contextMethods;
|
1086 | },
|
1087 | exposeCaseReducer(name2, reducer2) {
|
1088 | context.sliceCaseReducersByName[name2] = reducer2;
|
1089 | return contextMethods;
|
1090 | }
|
1091 | };
|
1092 | reducerNames.forEach((reducerName) => {
|
1093 | const reducerDefinition = reducers[reducerName];
|
1094 | const reducerDetails = {
|
1095 | reducerName,
|
1096 | type: getType(name, reducerName),
|
1097 | createNotation: typeof options.reducers === "function"
|
1098 | };
|
1099 | if (isAsyncThunkSliceReducerDefinition(reducerDefinition)) {
|
1100 | handleThunkCaseReducerDefinition(reducerDetails, reducerDefinition, contextMethods, cAT);
|
1101 | } else {
|
1102 | handleNormalReducerDefinition(reducerDetails, reducerDefinition, contextMethods);
|
1103 | }
|
1104 | });
|
1105 | function buildReducer() {
|
1106 | if (process.env.NODE_ENV !== "production") {
|
1107 | if (typeof options.extraReducers === "object") {
|
1108 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(14) : "The object notation for `createSlice.extraReducers` has been removed. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createSlice");
|
1109 | }
|
1110 | }
|
1111 | const [extraReducers = {}, actionMatchers = [], defaultCaseReducer = void 0] = typeof options.extraReducers === "function" ? executeReducerBuilderCallback(options.extraReducers) : [options.extraReducers];
|
1112 | const finalCaseReducers = {
|
1113 | ...extraReducers,
|
1114 | ...context.sliceCaseReducersByType
|
1115 | };
|
1116 | return createReducer(options.initialState, (builder) => {
|
1117 | for (let key in finalCaseReducers) {
|
1118 | builder.addCase(key, finalCaseReducers[key]);
|
1119 | }
|
1120 | for (let sM of context.sliceMatchers) {
|
1121 | builder.addMatcher(sM.matcher, sM.reducer);
|
1122 | }
|
1123 | for (let m of actionMatchers) {
|
1124 | builder.addMatcher(m.matcher, m.reducer);
|
1125 | }
|
1126 | if (defaultCaseReducer) {
|
1127 | builder.addDefaultCase(defaultCaseReducer);
|
1128 | }
|
1129 | });
|
1130 | }
|
1131 | const selectSelf = (state) => state;
|
1132 | const injectedSelectorCache = new Map();
|
1133 | let _reducer;
|
1134 | function reducer(state, action) {
|
1135 | if (!_reducer)
|
1136 | _reducer = buildReducer();
|
1137 | return _reducer(state, action);
|
1138 | }
|
1139 | function getInitialState() {
|
1140 | if (!_reducer)
|
1141 | _reducer = buildReducer();
|
1142 | return _reducer.getInitialState();
|
1143 | }
|
1144 | function makeSelectorProps(reducerPath2, injected = false) {
|
1145 | function selectSlice(state) {
|
1146 | let sliceState = state[reducerPath2];
|
1147 | if (typeof sliceState === "undefined") {
|
1148 | if (injected) {
|
1149 | sliceState = getInitialState();
|
1150 | } else if (process.env.NODE_ENV !== "production") {
|
1151 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(15) : "selectSlice returned undefined for an uninjected slice reducer");
|
1152 | }
|
1153 | }
|
1154 | return sliceState;
|
1155 | }
|
1156 | function getSelectors(selectState = selectSelf) {
|
1157 | const selectorCache = emplace(injectedSelectorCache, injected, {
|
1158 | insert: () => new WeakMap()
|
1159 | });
|
1160 | return emplace(selectorCache, selectState, {
|
1161 | insert: () => {
|
1162 | const map = {};
|
1163 | for (const [name2, selector] of Object.entries(options.selectors ?? {})) {
|
1164 | map[name2] = wrapSelector(selector, selectState, getInitialState, injected);
|
1165 | }
|
1166 | return map;
|
1167 | }
|
1168 | });
|
1169 | }
|
1170 | return {
|
1171 | reducerPath: reducerPath2,
|
1172 | getSelectors,
|
1173 | get selectors() {
|
1174 | return getSelectors(selectSlice);
|
1175 | },
|
1176 | selectSlice
|
1177 | };
|
1178 | }
|
1179 | const slice = {
|
1180 | name,
|
1181 | reducer,
|
1182 | actions: context.actionCreators,
|
1183 | caseReducers: context.sliceCaseReducersByName,
|
1184 | getInitialState,
|
1185 | ...makeSelectorProps(reducerPath),
|
1186 | injectInto(injectable, {
|
1187 | reducerPath: pathOpt,
|
1188 | ...config
|
1189 | } = {}) {
|
1190 | const newReducerPath = pathOpt ?? reducerPath;
|
1191 | injectable.inject({
|
1192 | reducerPath: newReducerPath,
|
1193 | reducer
|
1194 | }, config);
|
1195 | return {
|
1196 | ...slice,
|
1197 | ...makeSelectorProps(newReducerPath, true)
|
1198 | };
|
1199 | }
|
1200 | };
|
1201 | return slice;
|
1202 | };
|
1203 | }
|
1204 | function wrapSelector(selector, selectState, getInitialState, injected) {
|
1205 | function wrapper(rootState, ...args) {
|
1206 | let sliceState = selectState(rootState);
|
1207 | if (typeof sliceState === "undefined") {
|
1208 | if (injected) {
|
1209 | sliceState = getInitialState();
|
1210 | } else if (process.env.NODE_ENV !== "production") {
|
1211 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(16) : "selectState returned undefined for an uninjected slice reducer");
|
1212 | }
|
1213 | }
|
1214 | return selector(sliceState, ...args);
|
1215 | }
|
1216 | wrapper.unwrapped = selector;
|
1217 | return wrapper;
|
1218 | }
|
1219 | var createSlice = buildCreateSlice();
|
1220 | function buildReducerCreators() {
|
1221 | function asyncThunk(payloadCreator, config) {
|
1222 | return {
|
1223 | _reducerDefinitionType: "asyncThunk" ,
|
1224 | payloadCreator,
|
1225 | ...config
|
1226 | };
|
1227 | }
|
1228 | asyncThunk.withTypes = () => asyncThunk;
|
1229 | return {
|
1230 | reducer(caseReducer) {
|
1231 | return Object.assign({
|
1232 |
|
1233 |
|
1234 | [caseReducer.name](...args) {
|
1235 | return caseReducer(...args);
|
1236 | }
|
1237 | }[caseReducer.name], {
|
1238 | _reducerDefinitionType: "reducer"
|
1239 | });
|
1240 | },
|
1241 | preparedReducer(prepare, reducer) {
|
1242 | return {
|
1243 | _reducerDefinitionType: "reducerWithPrepare" ,
|
1244 | prepare,
|
1245 | reducer
|
1246 | };
|
1247 | },
|
1248 | asyncThunk
|
1249 | };
|
1250 | }
|
1251 | function handleNormalReducerDefinition({
|
1252 | type,
|
1253 | reducerName,
|
1254 | createNotation
|
1255 | }, maybeReducerWithPrepare, context) {
|
1256 | let caseReducer;
|
1257 | let prepareCallback;
|
1258 | if ("reducer" in maybeReducerWithPrepare) {
|
1259 | if (createNotation && !isCaseReducerWithPrepareDefinition(maybeReducerWithPrepare)) {
|
1260 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(17) : "Please use the `create.preparedReducer` notation for prepared action creators with the `create` notation.");
|
1261 | }
|
1262 | caseReducer = maybeReducerWithPrepare.reducer;
|
1263 | prepareCallback = maybeReducerWithPrepare.prepare;
|
1264 | } else {
|
1265 | caseReducer = maybeReducerWithPrepare;
|
1266 | }
|
1267 | context.addCase(type, caseReducer).exposeCaseReducer(reducerName, caseReducer).exposeAction(reducerName, prepareCallback ? createAction(type, prepareCallback) : createAction(type));
|
1268 | }
|
1269 | function isAsyncThunkSliceReducerDefinition(reducerDefinition) {
|
1270 | return reducerDefinition._reducerDefinitionType === "asyncThunk" ;
|
1271 | }
|
1272 | function isCaseReducerWithPrepareDefinition(reducerDefinition) {
|
1273 | return reducerDefinition._reducerDefinitionType === "reducerWithPrepare" ;
|
1274 | }
|
1275 | function handleThunkCaseReducerDefinition({
|
1276 | type,
|
1277 | reducerName
|
1278 | }, reducerDefinition, context, cAT) {
|
1279 | if (!cAT) {
|
1280 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(18) : "Cannot use `create.asyncThunk` in the built-in `createSlice`. Use `buildCreateSlice({ creators: { asyncThunk: asyncThunkCreator } })` to create a customised version of `createSlice`.");
|
1281 | }
|
1282 | const {
|
1283 | payloadCreator,
|
1284 | fulfilled,
|
1285 | pending,
|
1286 | rejected,
|
1287 | settled,
|
1288 | options
|
1289 | } = reducerDefinition;
|
1290 | const thunk = cAT(type, payloadCreator, options);
|
1291 | context.exposeAction(reducerName, thunk);
|
1292 | if (fulfilled) {
|
1293 | context.addCase(thunk.fulfilled, fulfilled);
|
1294 | }
|
1295 | if (pending) {
|
1296 | context.addCase(thunk.pending, pending);
|
1297 | }
|
1298 | if (rejected) {
|
1299 | context.addCase(thunk.rejected, rejected);
|
1300 | }
|
1301 | if (settled) {
|
1302 | context.addMatcher(thunk.settled, settled);
|
1303 | }
|
1304 | context.exposeCaseReducer(reducerName, {
|
1305 | fulfilled: fulfilled || noop,
|
1306 | pending: pending || noop,
|
1307 | rejected: rejected || noop,
|
1308 | settled: settled || noop
|
1309 | });
|
1310 | }
|
1311 | function noop() {
|
1312 | }
|
1313 |
|
1314 |
|
1315 | function getInitialEntityState() {
|
1316 | return {
|
1317 | ids: [],
|
1318 | entities: {}
|
1319 | };
|
1320 | }
|
1321 | function createInitialStateFactory(stateAdapter) {
|
1322 | function getInitialState(additionalState = {}, entities) {
|
1323 | const state = Object.assign(getInitialEntityState(), additionalState);
|
1324 | return entities ? stateAdapter.setAll(state, entities) : state;
|
1325 | }
|
1326 | return {
|
1327 | getInitialState
|
1328 | };
|
1329 | }
|
1330 |
|
1331 |
|
1332 | function createSelectorsFactory() {
|
1333 | function getSelectors(selectState, options = {}) {
|
1334 | const {
|
1335 | createSelector: createSelector2 = createDraftSafeSelector
|
1336 | } = options;
|
1337 | const selectIds = (state) => state.ids;
|
1338 | const selectEntities = (state) => state.entities;
|
1339 | const selectAll = createSelector2(selectIds, selectEntities, (ids, entities) => ids.map((id) => entities[id]));
|
1340 | const selectId = (_, id) => id;
|
1341 | const selectById = (entities, id) => entities[id];
|
1342 | const selectTotal = createSelector2(selectIds, (ids) => ids.length);
|
1343 | if (!selectState) {
|
1344 | return {
|
1345 | selectIds,
|
1346 | selectEntities,
|
1347 | selectAll,
|
1348 | selectTotal,
|
1349 | selectById: createSelector2(selectEntities, selectId, selectById)
|
1350 | };
|
1351 | }
|
1352 | const selectGlobalizedEntities = createSelector2(selectState, selectEntities);
|
1353 | return {
|
1354 | selectIds: createSelector2(selectState, selectIds),
|
1355 | selectEntities: selectGlobalizedEntities,
|
1356 | selectAll: createSelector2(selectState, selectAll),
|
1357 | selectTotal: createSelector2(selectState, selectTotal),
|
1358 | selectById: createSelector2(selectGlobalizedEntities, selectId, selectById)
|
1359 | };
|
1360 | }
|
1361 | return {
|
1362 | getSelectors
|
1363 | };
|
1364 | }
|
1365 |
|
1366 |
|
1367 | import { produce as createNextState3, isDraft as isDraft3 } from "immer";
|
1368 | var isDraftTyped = isDraft3;
|
1369 | function createSingleArgumentStateOperator(mutator) {
|
1370 | const operator = createStateOperator((_, state) => mutator(state));
|
1371 | return function operation(state) {
|
1372 | return operator(state, void 0);
|
1373 | };
|
1374 | }
|
1375 | function createStateOperator(mutator) {
|
1376 | return function operation(state, arg) {
|
1377 | function isPayloadActionArgument(arg2) {
|
1378 | return isFSA(arg2);
|
1379 | }
|
1380 | const runMutator = (draft) => {
|
1381 | if (isPayloadActionArgument(arg)) {
|
1382 | mutator(arg.payload, draft);
|
1383 | } else {
|
1384 | mutator(arg, draft);
|
1385 | }
|
1386 | };
|
1387 | if (isDraftTyped(state)) {
|
1388 | runMutator(state);
|
1389 | return state;
|
1390 | }
|
1391 | return createNextState3(state, runMutator);
|
1392 | };
|
1393 | }
|
1394 |
|
1395 |
|
1396 | function selectIdValue(entity, selectId) {
|
1397 | const key = selectId(entity);
|
1398 | if (process.env.NODE_ENV !== "production" && key === void 0) {
|
1399 | console.warn("The entity passed to the `selectId` implementation returned undefined.", "You should probably provide your own `selectId` implementation.", "The entity that was passed:", entity, "The `selectId` implementation:", selectId.toString());
|
1400 | }
|
1401 | return key;
|
1402 | }
|
1403 | function ensureEntitiesArray(entities) {
|
1404 | if (!Array.isArray(entities)) {
|
1405 | entities = Object.values(entities);
|
1406 | }
|
1407 | return entities;
|
1408 | }
|
1409 | function splitAddedUpdatedEntities(newEntities, selectId, state) {
|
1410 | newEntities = ensureEntitiesArray(newEntities);
|
1411 | const added = [];
|
1412 | const updated = [];
|
1413 | for (const entity of newEntities) {
|
1414 | const id = selectIdValue(entity, selectId);
|
1415 | if (id in state.entities) {
|
1416 | updated.push({
|
1417 | id,
|
1418 | changes: entity
|
1419 | });
|
1420 | } else {
|
1421 | added.push(entity);
|
1422 | }
|
1423 | }
|
1424 | return [added, updated];
|
1425 | }
|
1426 |
|
1427 |
|
1428 | function createUnsortedStateAdapter(selectId) {
|
1429 | function addOneMutably(entity, state) {
|
1430 | const key = selectIdValue(entity, selectId);
|
1431 | if (key in state.entities) {
|
1432 | return;
|
1433 | }
|
1434 | state.ids.push(key);
|
1435 | state.entities[key] = entity;
|
1436 | }
|
1437 | function addManyMutably(newEntities, state) {
|
1438 | newEntities = ensureEntitiesArray(newEntities);
|
1439 | for (const entity of newEntities) {
|
1440 | addOneMutably(entity, state);
|
1441 | }
|
1442 | }
|
1443 | function setOneMutably(entity, state) {
|
1444 | const key = selectIdValue(entity, selectId);
|
1445 | if (!(key in state.entities)) {
|
1446 | state.ids.push(key);
|
1447 | }
|
1448 | ;
|
1449 | state.entities[key] = entity;
|
1450 | }
|
1451 | function setManyMutably(newEntities, state) {
|
1452 | newEntities = ensureEntitiesArray(newEntities);
|
1453 | for (const entity of newEntities) {
|
1454 | setOneMutably(entity, state);
|
1455 | }
|
1456 | }
|
1457 | function setAllMutably(newEntities, state) {
|
1458 | newEntities = ensureEntitiesArray(newEntities);
|
1459 | state.ids = [];
|
1460 | state.entities = {};
|
1461 | addManyMutably(newEntities, state);
|
1462 | }
|
1463 | function removeOneMutably(key, state) {
|
1464 | return removeManyMutably([key], state);
|
1465 | }
|
1466 | function removeManyMutably(keys, state) {
|
1467 | let didMutate = false;
|
1468 | keys.forEach((key) => {
|
1469 | if (key in state.entities) {
|
1470 | delete state.entities[key];
|
1471 | didMutate = true;
|
1472 | }
|
1473 | });
|
1474 | if (didMutate) {
|
1475 | state.ids = state.ids.filter((id) => id in state.entities);
|
1476 | }
|
1477 | }
|
1478 | function removeAllMutably(state) {
|
1479 | Object.assign(state, {
|
1480 | ids: [],
|
1481 | entities: {}
|
1482 | });
|
1483 | }
|
1484 | function takeNewKey(keys, update, state) {
|
1485 | const original3 = state.entities[update.id];
|
1486 | if (original3 === void 0) {
|
1487 | return false;
|
1488 | }
|
1489 | const updated = Object.assign({}, original3, update.changes);
|
1490 | const newKey = selectIdValue(updated, selectId);
|
1491 | const hasNewKey = newKey !== update.id;
|
1492 | if (hasNewKey) {
|
1493 | keys[update.id] = newKey;
|
1494 | delete state.entities[update.id];
|
1495 | }
|
1496 | ;
|
1497 | state.entities[newKey] = updated;
|
1498 | return hasNewKey;
|
1499 | }
|
1500 | function updateOneMutably(update, state) {
|
1501 | return updateManyMutably([update], state);
|
1502 | }
|
1503 | function updateManyMutably(updates, state) {
|
1504 | const newKeys = {};
|
1505 | const updatesPerEntity = {};
|
1506 | updates.forEach((update) => {
|
1507 | if (update.id in state.entities) {
|
1508 | updatesPerEntity[update.id] = {
|
1509 | id: update.id,
|
1510 |
|
1511 |
|
1512 | changes: {
|
1513 | ...updatesPerEntity[update.id] ? updatesPerEntity[update.id].changes : null,
|
1514 | ...update.changes
|
1515 | }
|
1516 | };
|
1517 | }
|
1518 | });
|
1519 | updates = Object.values(updatesPerEntity);
|
1520 | const didMutateEntities = updates.length > 0;
|
1521 | if (didMutateEntities) {
|
1522 | const didMutateIds = updates.filter((update) => takeNewKey(newKeys, update, state)).length > 0;
|
1523 | if (didMutateIds) {
|
1524 | state.ids = Object.values(state.entities).map((e) => selectIdValue(e, selectId));
|
1525 | }
|
1526 | }
|
1527 | }
|
1528 | function upsertOneMutably(entity, state) {
|
1529 | return upsertManyMutably([entity], state);
|
1530 | }
|
1531 | function upsertManyMutably(newEntities, state) {
|
1532 | const [added, updated] = splitAddedUpdatedEntities(newEntities, selectId, state);
|
1533 | updateManyMutably(updated, state);
|
1534 | addManyMutably(added, state);
|
1535 | }
|
1536 | return {
|
1537 | removeAll: createSingleArgumentStateOperator(removeAllMutably),
|
1538 | addOne: createStateOperator(addOneMutably),
|
1539 | addMany: createStateOperator(addManyMutably),
|
1540 | setOne: createStateOperator(setOneMutably),
|
1541 | setMany: createStateOperator(setManyMutably),
|
1542 | setAll: createStateOperator(setAllMutably),
|
1543 | updateOne: createStateOperator(updateOneMutably),
|
1544 | updateMany: createStateOperator(updateManyMutably),
|
1545 | upsertOne: createStateOperator(upsertOneMutably),
|
1546 | upsertMany: createStateOperator(upsertManyMutably),
|
1547 | removeOne: createStateOperator(removeOneMutably),
|
1548 | removeMany: createStateOperator(removeManyMutably)
|
1549 | };
|
1550 | }
|
1551 |
|
1552 |
|
1553 | function createSortedStateAdapter(selectId, sort) {
|
1554 | const {
|
1555 | removeOne,
|
1556 | removeMany,
|
1557 | removeAll
|
1558 | } = createUnsortedStateAdapter(selectId);
|
1559 | function addOneMutably(entity, state) {
|
1560 | return addManyMutably([entity], state);
|
1561 | }
|
1562 | function addManyMutably(newEntities, state) {
|
1563 | newEntities = ensureEntitiesArray(newEntities);
|
1564 | const models = newEntities.filter((model) => !(selectIdValue(model, selectId) in state.entities));
|
1565 | if (models.length !== 0) {
|
1566 | merge(models, state);
|
1567 | }
|
1568 | }
|
1569 | function setOneMutably(entity, state) {
|
1570 | return setManyMutably([entity], state);
|
1571 | }
|
1572 | function setManyMutably(newEntities, state) {
|
1573 | newEntities = ensureEntitiesArray(newEntities);
|
1574 | if (newEntities.length !== 0) {
|
1575 | merge(newEntities, state);
|
1576 | }
|
1577 | }
|
1578 | function setAllMutably(newEntities, state) {
|
1579 | newEntities = ensureEntitiesArray(newEntities);
|
1580 | state.entities = {};
|
1581 | state.ids = [];
|
1582 | addManyMutably(newEntities, state);
|
1583 | }
|
1584 | function updateOneMutably(update, state) {
|
1585 | return updateManyMutably([update], state);
|
1586 | }
|
1587 | function updateManyMutably(updates, state) {
|
1588 | let appliedUpdates = false;
|
1589 | for (let update of updates) {
|
1590 | const entity = state.entities[update.id];
|
1591 | if (!entity) {
|
1592 | continue;
|
1593 | }
|
1594 | appliedUpdates = true;
|
1595 | Object.assign(entity, update.changes);
|
1596 | const newId = selectId(entity);
|
1597 | if (update.id !== newId) {
|
1598 | delete state.entities[update.id];
|
1599 | state.entities[newId] = entity;
|
1600 | }
|
1601 | }
|
1602 | if (appliedUpdates) {
|
1603 | resortEntities(state);
|
1604 | }
|
1605 | }
|
1606 | function upsertOneMutably(entity, state) {
|
1607 | return upsertManyMutably([entity], state);
|
1608 | }
|
1609 | function upsertManyMutably(newEntities, state) {
|
1610 | const [added, updated] = splitAddedUpdatedEntities(newEntities, selectId, state);
|
1611 | updateManyMutably(updated, state);
|
1612 | addManyMutably(added, state);
|
1613 | }
|
1614 | function areArraysEqual(a, b) {
|
1615 | if (a.length !== b.length) {
|
1616 | return false;
|
1617 | }
|
1618 | for (let i = 0; i < a.length && i < b.length; i++) {
|
1619 | if (a[i] === b[i]) {
|
1620 | continue;
|
1621 | }
|
1622 | return false;
|
1623 | }
|
1624 | return true;
|
1625 | }
|
1626 | function merge(models, state) {
|
1627 | models.forEach((model) => {
|
1628 | ;
|
1629 | state.entities[selectId(model)] = model;
|
1630 | });
|
1631 | resortEntities(state);
|
1632 | }
|
1633 | function resortEntities(state) {
|
1634 | const allEntities = Object.values(state.entities);
|
1635 | allEntities.sort(sort);
|
1636 | const newSortedIds = allEntities.map(selectId);
|
1637 | const {
|
1638 | ids
|
1639 | } = state;
|
1640 | if (!areArraysEqual(ids, newSortedIds)) {
|
1641 | state.ids = newSortedIds;
|
1642 | }
|
1643 | }
|
1644 | return {
|
1645 | removeOne,
|
1646 | removeMany,
|
1647 | removeAll,
|
1648 | addOne: createStateOperator(addOneMutably),
|
1649 | updateOne: createStateOperator(updateOneMutably),
|
1650 | upsertOne: createStateOperator(upsertOneMutably),
|
1651 | setOne: createStateOperator(setOneMutably),
|
1652 | setMany: createStateOperator(setManyMutably),
|
1653 | setAll: createStateOperator(setAllMutably),
|
1654 | addMany: createStateOperator(addManyMutably),
|
1655 | updateMany: createStateOperator(updateManyMutably),
|
1656 | upsertMany: createStateOperator(upsertManyMutably)
|
1657 | };
|
1658 | }
|
1659 |
|
1660 |
|
1661 | function createEntityAdapter(options = {}) {
|
1662 | const {
|
1663 | selectId,
|
1664 | sortComparer
|
1665 | } = {
|
1666 | sortComparer: false,
|
1667 | selectId: (instance) => instance.id,
|
1668 | ...options
|
1669 | };
|
1670 | const stateAdapter = sortComparer ? createSortedStateAdapter(selectId, sortComparer) : createUnsortedStateAdapter(selectId);
|
1671 | const stateFactory = createInitialStateFactory(stateAdapter);
|
1672 | const selectorsFactory = createSelectorsFactory();
|
1673 | return {
|
1674 | selectId,
|
1675 | sortComparer,
|
1676 | ...stateFactory,
|
1677 | ...selectorsFactory,
|
1678 | ...stateAdapter
|
1679 | };
|
1680 | }
|
1681 |
|
1682 |
|
1683 | import { isAction as isAction3 } from "redux";
|
1684 |
|
1685 |
|
1686 | var task = "task";
|
1687 | var listener = "listener";
|
1688 | var completed = "completed";
|
1689 | var cancelled = "cancelled";
|
1690 | var taskCancelled = `task-${cancelled}`;
|
1691 | var taskCompleted = `task-${completed}`;
|
1692 | var listenerCancelled = `${listener}-${cancelled}`;
|
1693 | var listenerCompleted = `${listener}-${completed}`;
|
1694 | var TaskAbortError = class {
|
1695 | constructor(code) {
|
1696 | this.code = code;
|
1697 | this.message = `${task} ${cancelled} (reason: ${code})`;
|
1698 | }
|
1699 | name = "TaskAbortError";
|
1700 | message;
|
1701 | };
|
1702 |
|
1703 |
|
1704 | var assertFunction = (func, expected) => {
|
1705 | if (typeof func !== "function") {
|
1706 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(32) : `${expected} is not a function`);
|
1707 | }
|
1708 | };
|
1709 | var noop2 = () => {
|
1710 | };
|
1711 | var catchRejection = (promise, onError = noop2) => {
|
1712 | promise.catch(onError);
|
1713 | return promise;
|
1714 | };
|
1715 | var addAbortSignalListener = (abortSignal, callback) => {
|
1716 | abortSignal.addEventListener("abort", callback, {
|
1717 | once: true
|
1718 | });
|
1719 | return () => abortSignal.removeEventListener("abort", callback);
|
1720 | };
|
1721 | var abortControllerWithReason = (abortController, reason) => {
|
1722 | const signal = abortController.signal;
|
1723 | if (signal.aborted) {
|
1724 | return;
|
1725 | }
|
1726 | if (!("reason" in signal)) {
|
1727 | Object.defineProperty(signal, "reason", {
|
1728 | enumerable: true,
|
1729 | value: reason,
|
1730 | configurable: true,
|
1731 | writable: true
|
1732 | });
|
1733 | }
|
1734 | ;
|
1735 | abortController.abort(reason);
|
1736 | };
|
1737 |
|
1738 |
|
1739 | var validateActive = (signal) => {
|
1740 | if (signal.aborted) {
|
1741 | const {
|
1742 | reason
|
1743 | } = signal;
|
1744 | throw new TaskAbortError(reason);
|
1745 | }
|
1746 | };
|
1747 | function raceWithSignal(signal, promise) {
|
1748 | let cleanup = noop2;
|
1749 | return new Promise((resolve, reject) => {
|
1750 | const notifyRejection = () => reject(new TaskAbortError(signal.reason));
|
1751 | if (signal.aborted) {
|
1752 | notifyRejection();
|
1753 | return;
|
1754 | }
|
1755 | cleanup = addAbortSignalListener(signal, notifyRejection);
|
1756 | promise.finally(() => cleanup()).then(resolve, reject);
|
1757 | }).finally(() => {
|
1758 | cleanup = noop2;
|
1759 | });
|
1760 | }
|
1761 | var runTask = async (task2, cleanUp) => {
|
1762 | try {
|
1763 | await Promise.resolve();
|
1764 | const value = await task2();
|
1765 | return {
|
1766 | status: "ok",
|
1767 | value
|
1768 | };
|
1769 | } catch (error) {
|
1770 | return {
|
1771 | status: error instanceof TaskAbortError ? "cancelled" : "rejected",
|
1772 | error
|
1773 | };
|
1774 | } finally {
|
1775 | cleanUp?.();
|
1776 | }
|
1777 | };
|
1778 | var createPause = (signal) => {
|
1779 | return (promise) => {
|
1780 | return catchRejection(raceWithSignal(signal, promise).then((output) => {
|
1781 | validateActive(signal);
|
1782 | return output;
|
1783 | }));
|
1784 | };
|
1785 | };
|
1786 | var createDelay = (signal) => {
|
1787 | const pause = createPause(signal);
|
1788 | return (timeoutMs) => {
|
1789 | return pause(new Promise((resolve) => setTimeout(resolve, timeoutMs)));
|
1790 | };
|
1791 | };
|
1792 |
|
1793 |
|
1794 | var {
|
1795 | assign
|
1796 | } = Object;
|
1797 | var INTERNAL_NIL_TOKEN = {};
|
1798 | var alm = "listenerMiddleware";
|
1799 | var createFork = (parentAbortSignal, parentBlockingPromises) => {
|
1800 | const linkControllers = (controller) => addAbortSignalListener(parentAbortSignal, () => abortControllerWithReason(controller, parentAbortSignal.reason));
|
1801 | return (taskExecutor, opts) => {
|
1802 | assertFunction(taskExecutor, "taskExecutor");
|
1803 | const childAbortController = new AbortController();
|
1804 | linkControllers(childAbortController);
|
1805 | const result = runTask(async () => {
|
1806 | validateActive(parentAbortSignal);
|
1807 | validateActive(childAbortController.signal);
|
1808 | const result2 = await taskExecutor({
|
1809 | pause: createPause(childAbortController.signal),
|
1810 | delay: createDelay(childAbortController.signal),
|
1811 | signal: childAbortController.signal
|
1812 | });
|
1813 | validateActive(childAbortController.signal);
|
1814 | return result2;
|
1815 | }, () => abortControllerWithReason(childAbortController, taskCompleted));
|
1816 | if (opts?.autoJoin) {
|
1817 | parentBlockingPromises.push(result.catch(noop2));
|
1818 | }
|
1819 | return {
|
1820 | result: createPause(parentAbortSignal)(result),
|
1821 | cancel() {
|
1822 | abortControllerWithReason(childAbortController, taskCancelled);
|
1823 | }
|
1824 | };
|
1825 | };
|
1826 | };
|
1827 | var createTakePattern = (startListening, signal) => {
|
1828 | const take = async (predicate, timeout) => {
|
1829 | validateActive(signal);
|
1830 | let unsubscribe = () => {
|
1831 | };
|
1832 | const tuplePromise = new Promise((resolve, reject) => {
|
1833 | let stopListening = startListening({
|
1834 | predicate,
|
1835 | effect: (action, listenerApi) => {
|
1836 | listenerApi.unsubscribe();
|
1837 | resolve([action, listenerApi.getState(), listenerApi.getOriginalState()]);
|
1838 | }
|
1839 | });
|
1840 | unsubscribe = () => {
|
1841 | stopListening();
|
1842 | reject();
|
1843 | };
|
1844 | });
|
1845 | const promises = [tuplePromise];
|
1846 | if (timeout != null) {
|
1847 | promises.push(new Promise((resolve) => setTimeout(resolve, timeout, null)));
|
1848 | }
|
1849 | try {
|
1850 | const output = await raceWithSignal(signal, Promise.race(promises));
|
1851 | validateActive(signal);
|
1852 | return output;
|
1853 | } finally {
|
1854 | unsubscribe();
|
1855 | }
|
1856 | };
|
1857 | return (predicate, timeout) => catchRejection(take(predicate, timeout));
|
1858 | };
|
1859 | var getListenerEntryPropsFrom = (options) => {
|
1860 | let {
|
1861 | type,
|
1862 | actionCreator,
|
1863 | matcher,
|
1864 | predicate,
|
1865 | effect
|
1866 | } = options;
|
1867 | if (type) {
|
1868 | predicate = createAction(type).match;
|
1869 | } else if (actionCreator) {
|
1870 | type = actionCreator.type;
|
1871 | predicate = actionCreator.match;
|
1872 | } else if (matcher) {
|
1873 | predicate = matcher;
|
1874 | } else if (predicate) {
|
1875 | } else {
|
1876 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(21) : "Creating or removing a listener requires one of the known fields for matching an action");
|
1877 | }
|
1878 | assertFunction(effect, "options.listener");
|
1879 | return {
|
1880 | predicate,
|
1881 | type,
|
1882 | effect
|
1883 | };
|
1884 | };
|
1885 | var createListenerEntry = Object.assign((options) => {
|
1886 | const {
|
1887 | type,
|
1888 | predicate,
|
1889 | effect
|
1890 | } = getListenerEntryPropsFrom(options);
|
1891 | const id = nanoid();
|
1892 | const entry = {
|
1893 | id,
|
1894 | effect,
|
1895 | type,
|
1896 | predicate,
|
1897 | pending: new Set(),
|
1898 | unsubscribe: () => {
|
1899 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(22) : "Unsubscribe not initialized");
|
1900 | }
|
1901 | };
|
1902 | return entry;
|
1903 | }, {
|
1904 | withTypes: () => createListenerEntry
|
1905 | });
|
1906 | var cancelActiveListeners = (entry) => {
|
1907 | entry.pending.forEach((controller) => {
|
1908 | abortControllerWithReason(controller, listenerCancelled);
|
1909 | });
|
1910 | };
|
1911 | var createClearListenerMiddleware = (listenerMap) => {
|
1912 | return () => {
|
1913 | listenerMap.forEach(cancelActiveListeners);
|
1914 | listenerMap.clear();
|
1915 | };
|
1916 | };
|
1917 | var safelyNotifyError = (errorHandler, errorToNotify, errorInfo) => {
|
1918 | try {
|
1919 | errorHandler(errorToNotify, errorInfo);
|
1920 | } catch (errorHandlerError) {
|
1921 | setTimeout(() => {
|
1922 | throw errorHandlerError;
|
1923 | }, 0);
|
1924 | }
|
1925 | };
|
1926 | var addListener = Object.assign(createAction(`${alm}/add`), {
|
1927 | withTypes: () => addListener
|
1928 | });
|
1929 | var clearAllListeners = createAction(`${alm}/removeAll`);
|
1930 | var removeListener = Object.assign(createAction(`${alm}/remove`), {
|
1931 | withTypes: () => removeListener
|
1932 | });
|
1933 | var defaultErrorHandler = (...args) => {
|
1934 | console.error(`${alm}/error`, ...args);
|
1935 | };
|
1936 | var createListenerMiddleware = (middlewareOptions = {}) => {
|
1937 | const listenerMap = new Map();
|
1938 | const {
|
1939 | extra,
|
1940 | onError = defaultErrorHandler
|
1941 | } = middlewareOptions;
|
1942 | assertFunction(onError, "onError");
|
1943 | const insertEntry = (entry) => {
|
1944 | entry.unsubscribe = () => listenerMap.delete(entry.id);
|
1945 | listenerMap.set(entry.id, entry);
|
1946 | return (cancelOptions) => {
|
1947 | entry.unsubscribe();
|
1948 | if (cancelOptions?.cancelActive) {
|
1949 | cancelActiveListeners(entry);
|
1950 | }
|
1951 | };
|
1952 | };
|
1953 | const startListening = (options) => {
|
1954 | let entry = find(Array.from(listenerMap.values()), (existingEntry) => existingEntry.effect === options.effect);
|
1955 | if (!entry) {
|
1956 | entry = createListenerEntry(options);
|
1957 | }
|
1958 | return insertEntry(entry);
|
1959 | };
|
1960 | Object.assign(startListening, {
|
1961 | withTypes: () => startListening
|
1962 | });
|
1963 | const stopListening = (options) => {
|
1964 | const {
|
1965 | type,
|
1966 | effect,
|
1967 | predicate
|
1968 | } = getListenerEntryPropsFrom(options);
|
1969 | const entry = find(Array.from(listenerMap.values()), (entry2) => {
|
1970 | const matchPredicateOrType = typeof type === "string" ? entry2.type === type : entry2.predicate === predicate;
|
1971 | return matchPredicateOrType && entry2.effect === effect;
|
1972 | });
|
1973 | if (entry) {
|
1974 | entry.unsubscribe();
|
1975 | if (options.cancelActive) {
|
1976 | cancelActiveListeners(entry);
|
1977 | }
|
1978 | }
|
1979 | return !!entry;
|
1980 | };
|
1981 | Object.assign(stopListening, {
|
1982 | withTypes: () => stopListening
|
1983 | });
|
1984 | const notifyListener = async (entry, action, api, getOriginalState) => {
|
1985 | const internalTaskController = new AbortController();
|
1986 | const take = createTakePattern(startListening, internalTaskController.signal);
|
1987 | const autoJoinPromises = [];
|
1988 | try {
|
1989 | entry.pending.add(internalTaskController);
|
1990 | await Promise.resolve(entry.effect(
|
1991 | action,
|
1992 |
|
1993 | assign({}, api, {
|
1994 | getOriginalState,
|
1995 | condition: (predicate, timeout) => take(predicate, timeout).then(Boolean),
|
1996 | take,
|
1997 | delay: createDelay(internalTaskController.signal),
|
1998 | pause: createPause(internalTaskController.signal),
|
1999 | extra,
|
2000 | signal: internalTaskController.signal,
|
2001 | fork: createFork(internalTaskController.signal, autoJoinPromises),
|
2002 | unsubscribe: entry.unsubscribe,
|
2003 | subscribe: () => {
|
2004 | listenerMap.set(entry.id, entry);
|
2005 | },
|
2006 | cancelActiveListeners: () => {
|
2007 | entry.pending.forEach((controller, _, set) => {
|
2008 | if (controller !== internalTaskController) {
|
2009 | abortControllerWithReason(controller, listenerCancelled);
|
2010 | set.delete(controller);
|
2011 | }
|
2012 | });
|
2013 | },
|
2014 | cancel: () => {
|
2015 | abortControllerWithReason(internalTaskController, listenerCancelled);
|
2016 | entry.pending.delete(internalTaskController);
|
2017 | },
|
2018 | throwIfCancelled: () => {
|
2019 | validateActive(internalTaskController.signal);
|
2020 | }
|
2021 | })
|
2022 | ));
|
2023 | } catch (listenerError) {
|
2024 | if (!(listenerError instanceof TaskAbortError)) {
|
2025 | safelyNotifyError(onError, listenerError, {
|
2026 | raisedBy: "effect"
|
2027 | });
|
2028 | }
|
2029 | } finally {
|
2030 | await Promise.all(autoJoinPromises);
|
2031 | abortControllerWithReason(internalTaskController, listenerCompleted);
|
2032 | entry.pending.delete(internalTaskController);
|
2033 | }
|
2034 | };
|
2035 | const clearListenerMiddleware = createClearListenerMiddleware(listenerMap);
|
2036 | const middleware = (api) => (next) => (action) => {
|
2037 | if (!isAction3(action)) {
|
2038 | return next(action);
|
2039 | }
|
2040 | if (addListener.match(action)) {
|
2041 | return startListening(action.payload);
|
2042 | }
|
2043 | if (clearAllListeners.match(action)) {
|
2044 | clearListenerMiddleware();
|
2045 | return;
|
2046 | }
|
2047 | if (removeListener.match(action)) {
|
2048 | return stopListening(action.payload);
|
2049 | }
|
2050 | let originalState = api.getState();
|
2051 | const getOriginalState = () => {
|
2052 | if (originalState === INTERNAL_NIL_TOKEN) {
|
2053 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(23) : `${alm}: getOriginalState can only be called synchronously`);
|
2054 | }
|
2055 | return originalState;
|
2056 | };
|
2057 | let result;
|
2058 | try {
|
2059 | result = next(action);
|
2060 | if (listenerMap.size > 0) {
|
2061 | const currentState = api.getState();
|
2062 | const listenerEntries = Array.from(listenerMap.values());
|
2063 | for (const entry of listenerEntries) {
|
2064 | let runListener = false;
|
2065 | try {
|
2066 | runListener = entry.predicate(action, currentState, originalState);
|
2067 | } catch (predicateError) {
|
2068 | runListener = false;
|
2069 | safelyNotifyError(onError, predicateError, {
|
2070 | raisedBy: "predicate"
|
2071 | });
|
2072 | }
|
2073 | if (!runListener) {
|
2074 | continue;
|
2075 | }
|
2076 | notifyListener(entry, action, api, getOriginalState);
|
2077 | }
|
2078 | }
|
2079 | } finally {
|
2080 | originalState = INTERNAL_NIL_TOKEN;
|
2081 | }
|
2082 | return result;
|
2083 | };
|
2084 | return {
|
2085 | middleware,
|
2086 | startListening,
|
2087 | stopListening,
|
2088 | clearListeners: clearListenerMiddleware
|
2089 | };
|
2090 | };
|
2091 |
|
2092 |
|
2093 | import { compose as compose3 } from "redux";
|
2094 | var createMiddlewareEntry = (middleware) => ({
|
2095 | id: nanoid(),
|
2096 | middleware,
|
2097 | applied: new Map()
|
2098 | });
|
2099 | var matchInstance = (instanceId) => (action) => action?.meta?.instanceId === instanceId;
|
2100 | var createDynamicMiddleware = () => {
|
2101 | const instanceId = nanoid();
|
2102 | const middlewareMap = new Map();
|
2103 | const withMiddleware = Object.assign(createAction("dynamicMiddleware/add", (...middlewares) => ({
|
2104 | payload: middlewares,
|
2105 | meta: {
|
2106 | instanceId
|
2107 | }
|
2108 | })), {
|
2109 | withTypes: () => withMiddleware
|
2110 | });
|
2111 | const addMiddleware = Object.assign(function addMiddleware2(...middlewares) {
|
2112 | middlewares.forEach((middleware2) => {
|
2113 | let entry = find(Array.from(middlewareMap.values()), (entry2) => entry2.middleware === middleware2);
|
2114 | if (!entry) {
|
2115 | entry = createMiddlewareEntry(middleware2);
|
2116 | }
|
2117 | middlewareMap.set(entry.id, entry);
|
2118 | });
|
2119 | }, {
|
2120 | withTypes: () => addMiddleware
|
2121 | });
|
2122 | const getFinalMiddleware = (api) => {
|
2123 | const appliedMiddleware = Array.from(middlewareMap.values()).map((entry) => emplace(entry.applied, api, {
|
2124 | insert: () => entry.middleware(api)
|
2125 | }));
|
2126 | return compose3(...appliedMiddleware);
|
2127 | };
|
2128 | const isWithMiddleware = isAllOf(withMiddleware, matchInstance(instanceId));
|
2129 | const middleware = (api) => (next) => (action) => {
|
2130 | if (isWithMiddleware(action)) {
|
2131 | addMiddleware(...action.payload);
|
2132 | return api.dispatch;
|
2133 | }
|
2134 | return getFinalMiddleware(api)(next)(action);
|
2135 | };
|
2136 | return {
|
2137 | middleware,
|
2138 | addMiddleware,
|
2139 | withMiddleware,
|
2140 | instanceId
|
2141 | };
|
2142 | };
|
2143 |
|
2144 |
|
2145 | import { combineReducers as combineReducers2 } from "redux";
|
2146 | var isSliceLike = (maybeSliceLike) => "reducerPath" in maybeSliceLike && typeof maybeSliceLike.reducerPath === "string";
|
2147 | var getReducers = (slices) => slices.flatMap((sliceOrMap) => isSliceLike(sliceOrMap) ? [[sliceOrMap.reducerPath, sliceOrMap.reducer]] : Object.entries(sliceOrMap));
|
2148 | var ORIGINAL_STATE = Symbol.for("rtk-state-proxy-original");
|
2149 | var isStateProxy = (value) => !!value && !!value[ORIGINAL_STATE];
|
2150 | var stateProxyMap = new WeakMap();
|
2151 | var createStateProxy = (state, reducerMap) => emplace(stateProxyMap, state, {
|
2152 | insert: () => new Proxy(state, {
|
2153 | get: (target, prop, receiver) => {
|
2154 | if (prop === ORIGINAL_STATE)
|
2155 | return target;
|
2156 | const result = Reflect.get(target, prop, receiver);
|
2157 | if (typeof result === "undefined") {
|
2158 | const reducer = reducerMap[prop.toString()];
|
2159 | if (reducer) {
|
2160 | const reducerResult = reducer(void 0, {
|
2161 | type: nanoid()
|
2162 | });
|
2163 | if (typeof reducerResult === "undefined") {
|
2164 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(24) : `The slice reducer for key "${prop.toString()}" returned undefined when called for selector(). If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.`);
|
2165 | }
|
2166 | return reducerResult;
|
2167 | }
|
2168 | }
|
2169 | return result;
|
2170 | }
|
2171 | })
|
2172 | });
|
2173 | var original = (state) => {
|
2174 | if (!isStateProxy(state)) {
|
2175 | throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(25) : "original must be used on state Proxy");
|
2176 | }
|
2177 | return state[ORIGINAL_STATE];
|
2178 | };
|
2179 | var noopReducer = (state = {}) => state;
|
2180 | function combineSlices(...slices) {
|
2181 | const reducerMap = Object.fromEntries(getReducers(slices));
|
2182 | const getReducer = () => Object.keys(reducerMap).length ? combineReducers2(reducerMap) : noopReducer;
|
2183 | let reducer = getReducer();
|
2184 | function combinedReducer(state, action) {
|
2185 | return reducer(state, action);
|
2186 | }
|
2187 | combinedReducer.withLazyLoadedSlices = () => combinedReducer;
|
2188 | const inject = (slice, config = {}) => {
|
2189 | const {
|
2190 | reducerPath,
|
2191 | reducer: reducerToInject
|
2192 | } = slice;
|
2193 | const currentReducer = reducerMap[reducerPath];
|
2194 | if (!config.overrideExisting && currentReducer && currentReducer !== reducerToInject) {
|
2195 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
2196 | console.error(`called \`inject\` to override already-existing reducer ${reducerPath} without specifying \`overrideExisting: true\``);
|
2197 | }
|
2198 | return combinedReducer;
|
2199 | }
|
2200 | reducerMap[reducerPath] = reducerToInject;
|
2201 | reducer = getReducer();
|
2202 | return combinedReducer;
|
2203 | };
|
2204 | const selector = Object.assign(function makeSelector(selectorFn, selectState) {
|
2205 | return function selector2(state, ...args) {
|
2206 | return selectorFn(createStateProxy(selectState ? selectState(state, ...args) : state, reducerMap), ...args);
|
2207 | };
|
2208 | }, {
|
2209 | original
|
2210 | });
|
2211 | return Object.assign(combinedReducer, {
|
2212 | inject,
|
2213 | selector
|
2214 | });
|
2215 | }
|
2216 |
|
2217 |
|
2218 | function formatProdErrorMessage(code) {
|
2219 | return `Minified Redux Toolkit error #${code}; visit https://redux-toolkit.js.org/Errors?code=${code} for the full message or use the non-minified dev environment for full errors. `;
|
2220 | }
|
2221 | export {
|
2222 | ReducerType,
|
2223 | SHOULD_AUTOBATCH,
|
2224 | TaskAbortError,
|
2225 | Tuple,
|
2226 | addListener,
|
2227 | asyncThunkCreator,
|
2228 | autoBatchEnhancer,
|
2229 | buildCreateSlice,
|
2230 | clearAllListeners,
|
2231 | combineSlices,
|
2232 | configureStore,
|
2233 | createAction,
|
2234 | createActionCreatorInvariantMiddleware,
|
2235 | createAsyncThunk,
|
2236 | createDraftSafeSelector,
|
2237 | createDraftSafeSelectorCreator,
|
2238 | createDynamicMiddleware,
|
2239 | createEntityAdapter,
|
2240 | createImmutableStateInvariantMiddleware,
|
2241 | createListenerMiddleware,
|
2242 | produce as createNextState,
|
2243 | createReducer,
|
2244 | createSelector,
|
2245 | createSelectorCreator2 as createSelectorCreator,
|
2246 | createSerializableStateInvariantMiddleware,
|
2247 | createSlice,
|
2248 | current2 as current,
|
2249 | findNonSerializableValue,
|
2250 | formatProdErrorMessage,
|
2251 | freeze,
|
2252 | isActionCreator,
|
2253 | isAllOf,
|
2254 | isAnyOf,
|
2255 | isAsyncThunkAction,
|
2256 | isDraft4 as isDraft,
|
2257 | isFSA as isFluxStandardAction,
|
2258 | isFulfilled,
|
2259 | isImmutableDefault,
|
2260 | isPending,
|
2261 | isPlain,
|
2262 | isRejected,
|
2263 | isRejectedWithValue,
|
2264 | lruMemoize,
|
2265 | miniSerializeError,
|
2266 | nanoid,
|
2267 | original2 as original,
|
2268 | prepareAutoBatched,
|
2269 | removeListener,
|
2270 | unwrapResult,
|
2271 | weakMapMemoize2 as weakMapMemoize
|
2272 | };
|
2273 |
|
\ | No newline at end of file |