1 | var __extends = (this && this.__extends) || (function () {
|
2 | var extendStatics = function (d, b) {
|
3 | extendStatics = Object.setPrototypeOf ||
|
4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
6 | return extendStatics(d, b);
|
7 | };
|
8 | return function (d, b) {
|
9 | if (typeof b !== "function" && b !== null)
|
10 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
11 | extendStatics(d, b);
|
12 | function __() { this.constructor = d; }
|
13 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
14 | };
|
15 | })();
|
16 | var __generator = (this && this.__generator) || function (thisArg, body) {
|
17 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
18 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
19 | function verb(n) { return function (v) { return step([n, v]); }; }
|
20 | function step(op) {
|
21 | if (f) throw new TypeError("Generator is already executing.");
|
22 | while (_) try {
|
23 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
24 | if (y = 0, t) op = [op[0] & 2, t.value];
|
25 | switch (op[0]) {
|
26 | case 0: case 1: t = op; break;
|
27 | case 4: _.label++; return { value: op[1], done: false };
|
28 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
29 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
30 | default:
|
31 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
32 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
33 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
34 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
35 | if (t[2]) _.ops.pop();
|
36 | _.trys.pop(); continue;
|
37 | }
|
38 | op = body.call(thisArg, _);
|
39 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
40 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
41 | }
|
42 | };
|
43 | var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
44 | for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
45 | to[j] = from[i];
|
46 | return to;
|
47 | };
|
48 | var __create = Object.create;
|
49 | var __defProp = Object.defineProperty;
|
50 | var __defProps = Object.defineProperties;
|
51 | var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
52 | var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
53 | var __getOwnPropNames = Object.getOwnPropertyNames;
|
54 | var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
55 | var __getProtoOf = Object.getPrototypeOf;
|
56 | var __hasOwnProp = Object.prototype.hasOwnProperty;
|
57 | var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
58 | var __defNormalProp = function (obj, key, value) { return key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value: value }) : obj[key] = value; };
|
59 | var __spreadValues = function (a, b) {
|
60 | for (var prop in b || (b = {}))
|
61 | if (__hasOwnProp.call(b, prop))
|
62 | __defNormalProp(a, prop, b[prop]);
|
63 | if (__getOwnPropSymbols)
|
64 | for (var _i = 0, _c = __getOwnPropSymbols(b); _i < _c.length; _i++) {
|
65 | var prop = _c[_i];
|
66 | if (__propIsEnum.call(b, prop))
|
67 | __defNormalProp(a, prop, b[prop]);
|
68 | }
|
69 | return a;
|
70 | };
|
71 | var __spreadProps = function (a, b) { return __defProps(a, __getOwnPropDescs(b)); };
|
72 | var __markAsModule = function (target) { return __defProp(target, "__esModule", { value: true }); };
|
73 | var __export = function (target, all) {
|
74 | for (var name in all)
|
75 | __defProp(target, name, { get: all[name], enumerable: true });
|
76 | };
|
77 | var __reExport = function (target, module2, desc) {
|
78 | if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
79 | var _loop_1 = function (key) {
|
80 | if (!__hasOwnProp.call(target, key) && key !== "default")
|
81 | __defProp(target, key, { get: function () { return module2[key]; }, enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
82 | };
|
83 | for (var _i = 0, _c = __getOwnPropNames(module2); _i < _c.length; _i++) {
|
84 | var key = _c[_i];
|
85 | _loop_1(key);
|
86 | }
|
87 | }
|
88 | return target;
|
89 | };
|
90 | var __toModule = function (module2) {
|
91 | return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: function () { return module2.default; }, enumerable: true } : { value: module2, enumerable: true })), module2);
|
92 | };
|
93 | var __async = function (__this, __arguments, generator) {
|
94 | return new Promise(function (resolve, reject) {
|
95 | var fulfilled = function (value) {
|
96 | try {
|
97 | step(generator.next(value));
|
98 | }
|
99 | catch (e) {
|
100 | reject(e);
|
101 | }
|
102 | };
|
103 | var rejected = function (value) {
|
104 | try {
|
105 | step(generator.throw(value));
|
106 | }
|
107 | catch (e) {
|
108 | reject(e);
|
109 | }
|
110 | };
|
111 | var step = function (x) { return x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); };
|
112 | step((generator = generator.apply(__this, __arguments)).next());
|
113 | });
|
114 | };
|
115 |
|
116 | __markAsModule(exports);
|
117 | __export(exports, {
|
118 | MiddlewareArray: function () { return MiddlewareArray; },
|
119 | SHOULD_AUTOBATCH: function () { return SHOULD_AUTOBATCH; },
|
120 | TaskAbortError: function () { return TaskAbortError; },
|
121 | addListener: function () { return addListener; },
|
122 | autoBatchEnhancer: function () { return autoBatchEnhancer; },
|
123 | clearAllListeners: function () { return clearAllListeners; },
|
124 | configureStore: function () { return configureStore; },
|
125 | createAction: function () { return createAction; },
|
126 | createAsyncThunk: function () { return createAsyncThunk; },
|
127 | createDraftSafeSelector: function () { return createDraftSafeSelector; },
|
128 | createEntityAdapter: function () { return createEntityAdapter; },
|
129 | createImmutableStateInvariantMiddleware: function () { return createImmutableStateInvariantMiddleware; },
|
130 | createListenerMiddleware: function () { return createListenerMiddleware; },
|
131 | createNextState: function () { return import_immer6.default; },
|
132 | createReducer: function () { return createReducer; },
|
133 | createSelector: function () { return import_reselect2.createSelector; },
|
134 | createSerializableStateInvariantMiddleware: function () { return createSerializableStateInvariantMiddleware; },
|
135 | createSlice: function () { return createSlice; },
|
136 | current: function () { return import_immer6.current; },
|
137 | findNonSerializableValue: function () { return findNonSerializableValue; },
|
138 | freeze: function () { return import_immer6.freeze; },
|
139 | getDefaultMiddleware: function () { return getDefaultMiddleware; },
|
140 | getType: function () { return getType; },
|
141 | isAllOf: function () { return isAllOf; },
|
142 | isAnyOf: function () { return isAnyOf; },
|
143 | isAsyncThunkAction: function () { return isAsyncThunkAction; },
|
144 | isDraft: function () { return import_immer6.isDraft; },
|
145 | isFulfilled: function () { return isFulfilled; },
|
146 | isImmutableDefault: function () { return isImmutableDefault; },
|
147 | isPending: function () { return isPending; },
|
148 | isPlain: function () { return isPlain; },
|
149 | isPlainObject: function () { return isPlainObject; },
|
150 | isRejected: function () { return isRejected; },
|
151 | isRejectedWithValue: function () { return isRejectedWithValue; },
|
152 | miniSerializeError: function () { return miniSerializeError; },
|
153 | nanoid: function () { return nanoid; },
|
154 | original: function () { return import_immer6.original; },
|
155 | prepareAutoBatched: function () { return prepareAutoBatched; },
|
156 | removeListener: function () { return removeListener; },
|
157 | unwrapResult: function () { return unwrapResult; }
|
158 | });
|
159 | var import_immer5 = __toModule(require("immer"));
|
160 | __reExport(exports, __toModule(require("redux")));
|
161 | var import_immer6 = __toModule(require("immer"));
|
162 | var import_reselect2 = __toModule(require("reselect"));
|
163 |
|
164 | var import_immer = __toModule(require("immer"));
|
165 | var import_reselect = __toModule(require("reselect"));
|
166 | var createDraftSafeSelector = function () {
|
167 | var args = [];
|
168 | for (var _i = 0; _i < arguments.length; _i++) {
|
169 | args[_i] = arguments[_i];
|
170 | }
|
171 | var selector = (0, import_reselect.createSelector).apply(void 0, args);
|
172 | var wrappedSelector = function (value) {
|
173 | var rest = [];
|
174 | for (var _i = 1; _i < arguments.length; _i++) {
|
175 | rest[_i - 1] = arguments[_i];
|
176 | }
|
177 | return selector.apply(void 0, __spreadArray([(0, import_immer.isDraft)(value) ? (0, import_immer.current)(value) : value], rest));
|
178 | };
|
179 | return wrappedSelector;
|
180 | };
|
181 |
|
182 | var import_redux2 = __toModule(require("redux"));
|
183 |
|
184 | var import_redux = __toModule(require("redux"));
|
185 | var composeWithDevTools = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : function () {
|
186 | if (arguments.length === 0)
|
187 | return void 0;
|
188 | if (typeof arguments[0] === "object")
|
189 | return import_redux.compose;
|
190 | return import_redux.compose.apply(null, arguments);
|
191 | };
|
192 | var devToolsEnhancer = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ : function () {
|
193 | return function (noop2) {
|
194 | return noop2;
|
195 | };
|
196 | };
|
197 |
|
198 | function isPlainObject(value) {
|
199 | if (typeof value !== "object" || value === null)
|
200 | return false;
|
201 | var proto = Object.getPrototypeOf(value);
|
202 | if (proto === null)
|
203 | return true;
|
204 | var baseProto = proto;
|
205 | while (Object.getPrototypeOf(baseProto) !== null) {
|
206 | baseProto = Object.getPrototypeOf(baseProto);
|
207 | }
|
208 | return proto === baseProto;
|
209 | }
|
210 |
|
211 | var import_redux_thunk = __toModule(require("redux-thunk"));
|
212 |
|
213 | var import_immer2 = __toModule(require("immer"));
|
214 | function getTimeMeasureUtils(maxDelay, fnName) {
|
215 | var elapsed = 0;
|
216 | return {
|
217 | measureTime: function (fn) {
|
218 | var started = Date.now();
|
219 | try {
|
220 | return fn();
|
221 | }
|
222 | finally {
|
223 | var finished = Date.now();
|
224 | elapsed += finished - started;
|
225 | }
|
226 | },
|
227 | warnIfExceeded: function () {
|
228 | if (elapsed > maxDelay) {
|
229 | console.warn(fnName + " took " + elapsed + "ms, which is more than the warning threshold of " + maxDelay + "ms. \nIf 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.\nIt is disabled in production builds, so you don't need to worry about that.");
|
230 | }
|
231 | }
|
232 | };
|
233 | }
|
234 | var MiddlewareArray = (function (_super) {
|
235 | __extends(MiddlewareArray, _super);
|
236 | function MiddlewareArray() {
|
237 | var args = [];
|
238 | for (var _i = 0; _i < arguments.length; _i++) {
|
239 | args[_i] = arguments[_i];
|
240 | }
|
241 | var _this = _super.apply(this, args) || this;
|
242 | Object.setPrototypeOf(_this, MiddlewareArray.prototype);
|
243 | return _this;
|
244 | }
|
245 | Object.defineProperty(MiddlewareArray, Symbol.species, {
|
246 | get: function () {
|
247 | return MiddlewareArray;
|
248 | },
|
249 | enumerable: false,
|
250 | configurable: true
|
251 | });
|
252 | MiddlewareArray.prototype.concat = function () {
|
253 | var arr = [];
|
254 | for (var _i = 0; _i < arguments.length; _i++) {
|
255 | arr[_i] = arguments[_i];
|
256 | }
|
257 | return _super.prototype.concat.apply(this, arr);
|
258 | };
|
259 | MiddlewareArray.prototype.prepend = function () {
|
260 | var arr = [];
|
261 | for (var _i = 0; _i < arguments.length; _i++) {
|
262 | arr[_i] = arguments[_i];
|
263 | }
|
264 | if (arr.length === 1 && Array.isArray(arr[0])) {
|
265 | return new (MiddlewareArray.bind.apply(MiddlewareArray, __spreadArray([void 0], arr[0].concat(this))))();
|
266 | }
|
267 | return new (MiddlewareArray.bind.apply(MiddlewareArray, __spreadArray([void 0], arr.concat(this))))();
|
268 | };
|
269 | return MiddlewareArray;
|
270 | }(Array));
|
271 | function freezeDraftable(val) {
|
272 | return (0, import_immer2.isDraftable)(val) ? (0, import_immer2.default)(val, function () {
|
273 | }) : val;
|
274 | }
|
275 |
|
276 | var isProduction = false;
|
277 | var prefix = "Invariant failed";
|
278 | function invariant(condition, message) {
|
279 | if (condition) {
|
280 | return;
|
281 | }
|
282 | if (isProduction) {
|
283 | throw new Error(prefix);
|
284 | }
|
285 | throw new Error(prefix + ": " + (message || ""));
|
286 | }
|
287 | function stringify(obj, serializer, indent, decycler) {
|
288 | return JSON.stringify(obj, getSerialize(serializer, decycler), indent);
|
289 | }
|
290 | function getSerialize(serializer, decycler) {
|
291 | var stack = [], keys = [];
|
292 | if (!decycler)
|
293 | decycler = function (_, value) {
|
294 | if (stack[0] === value)
|
295 | return "[Circular ~]";
|
296 | return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
|
297 | };
|
298 | return function (key, value) {
|
299 | if (stack.length > 0) {
|
300 | var thisPos = stack.indexOf(this);
|
301 | ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
|
302 | ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
|
303 | if (~stack.indexOf(value))
|
304 | value = decycler.call(this, key, value);
|
305 | }
|
306 | else
|
307 | stack.push(value);
|
308 | return serializer == null ? value : serializer.call(this, key, value);
|
309 | };
|
310 | }
|
311 | function isImmutableDefault(value) {
|
312 | return typeof value !== "object" || value == null || Object.isFrozen(value);
|
313 | }
|
314 | function trackForMutations(isImmutable, ignorePaths, obj) {
|
315 | var trackedProperties = trackProperties(isImmutable, ignorePaths, obj);
|
316 | return {
|
317 | detectMutations: function () {
|
318 | return detectMutations(isImmutable, ignorePaths, trackedProperties, obj);
|
319 | }
|
320 | };
|
321 | }
|
322 | function trackProperties(isImmutable, ignorePaths, obj, path) {
|
323 | if (ignorePaths === void 0) { ignorePaths = []; }
|
324 | if (path === void 0) { path = ""; }
|
325 | var tracked = { value: obj };
|
326 | if (!isImmutable(obj)) {
|
327 | tracked.children = {};
|
328 | for (var key in obj) {
|
329 | var childPath = path ? path + "." + key : key;
|
330 | if (ignorePaths.length && ignorePaths.indexOf(childPath) !== -1) {
|
331 | continue;
|
332 | }
|
333 | tracked.children[key] = trackProperties(isImmutable, ignorePaths, obj[key], childPath);
|
334 | }
|
335 | }
|
336 | return tracked;
|
337 | }
|
338 | function detectMutations(isImmutable, ignoredPaths, trackedProperty, obj, sameParentRef, path) {
|
339 | if (ignoredPaths === void 0) { ignoredPaths = []; }
|
340 | if (sameParentRef === void 0) { sameParentRef = false; }
|
341 | if (path === void 0) { path = ""; }
|
342 | var prevObj = trackedProperty ? trackedProperty.value : void 0;
|
343 | var sameRef = prevObj === obj;
|
344 | if (sameParentRef && !sameRef && !Number.isNaN(obj)) {
|
345 | return { wasMutated: true, path: path };
|
346 | }
|
347 | if (isImmutable(prevObj) || isImmutable(obj)) {
|
348 | return { wasMutated: false };
|
349 | }
|
350 | var keysToDetect = {};
|
351 | for (var key in trackedProperty.children) {
|
352 | keysToDetect[key] = true;
|
353 | }
|
354 | for (var key in obj) {
|
355 | keysToDetect[key] = true;
|
356 | }
|
357 | var hasIgnoredPaths = ignoredPaths.length > 0;
|
358 | var _loop_2 = function (key) {
|
359 | var nestedPath = path ? path + "." + key : key;
|
360 | if (hasIgnoredPaths) {
|
361 | var hasMatches = ignoredPaths.some(function (ignored) {
|
362 | if (ignored instanceof RegExp) {
|
363 | return ignored.test(nestedPath);
|
364 | }
|
365 | return nestedPath === ignored;
|
366 | });
|
367 | if (hasMatches) {
|
368 | return "continue";
|
369 | }
|
370 | }
|
371 | var result = detectMutations(isImmutable, ignoredPaths, trackedProperty.children[key], obj[key], sameRef, nestedPath);
|
372 | if (result.wasMutated) {
|
373 | return { value: result };
|
374 | }
|
375 | };
|
376 | for (var key in keysToDetect) {
|
377 | var state_1 = _loop_2(key);
|
378 | if (typeof state_1 === "object")
|
379 | return state_1.value;
|
380 | }
|
381 | return { wasMutated: false };
|
382 | }
|
383 | function createImmutableStateInvariantMiddleware(options) {
|
384 | if (options === void 0) { options = {}; }
|
385 | if (false) {
|
386 | return function () { return function (next) { return function (action) { return next(action); }; }; };
|
387 | }
|
388 | var _c = options.isImmutable, isImmutable = _c === void 0 ? isImmutableDefault : _c, ignoredPaths = options.ignoredPaths, _d = options.warnAfter, warnAfter = _d === void 0 ? 32 : _d, ignore = options.ignore;
|
389 | ignoredPaths = ignoredPaths || ignore;
|
390 | var track = trackForMutations.bind(null, isImmutable, ignoredPaths);
|
391 | return function (_c) {
|
392 | var getState = _c.getState;
|
393 | var state = getState();
|
394 | var tracker = track(state);
|
395 | var result;
|
396 | return function (next) { return function (action) {
|
397 | var measureUtils = getTimeMeasureUtils(warnAfter, "ImmutableStateInvariantMiddleware");
|
398 | measureUtils.measureTime(function () {
|
399 | state = getState();
|
400 | result = tracker.detectMutations();
|
401 | tracker = track(state);
|
402 | invariant(!result.wasMutated, "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)");
|
403 | });
|
404 | var dispatchedAction = next(action);
|
405 | measureUtils.measureTime(function () {
|
406 | state = getState();
|
407 | result = tracker.detectMutations();
|
408 | tracker = track(state);
|
409 | result.wasMutated && invariant(!result.wasMutated, "A state mutation was detected inside a dispatch, in the path: " + (result.path || "") + ". Take a look at the reducer(s) handling the action " + stringify(action) + ". (https://redux.js.org/style-guide/style-guide#do-not-mutate-state)");
|
410 | });
|
411 | measureUtils.warnIfExceeded();
|
412 | return dispatchedAction;
|
413 | }; };
|
414 | };
|
415 | }
|
416 |
|
417 | function isPlain(val) {
|
418 | var type = typeof val;
|
419 | return val == null || type === "string" || type === "boolean" || type === "number" || Array.isArray(val) || isPlainObject(val);
|
420 | }
|
421 | function findNonSerializableValue(value, path, isSerializable, getEntries, ignoredPaths, cache) {
|
422 | if (path === void 0) { path = ""; }
|
423 | if (isSerializable === void 0) { isSerializable = isPlain; }
|
424 | if (ignoredPaths === void 0) { ignoredPaths = []; }
|
425 | var foundNestedSerializable;
|
426 | if (!isSerializable(value)) {
|
427 | return {
|
428 | keyPath: path || "<root>",
|
429 | value: value
|
430 | };
|
431 | }
|
432 | if (typeof value !== "object" || value === null) {
|
433 | return false;
|
434 | }
|
435 | if (cache == null ? void 0 : cache.has(value))
|
436 | return false;
|
437 | var entries = getEntries != null ? getEntries(value) : Object.entries(value);
|
438 | var hasIgnoredPaths = ignoredPaths.length > 0;
|
439 | var _loop_3 = function (key, nestedValue) {
|
440 | var nestedPath = path ? path + "." + key : key;
|
441 | if (hasIgnoredPaths) {
|
442 | var hasMatches = ignoredPaths.some(function (ignored) {
|
443 | if (ignored instanceof RegExp) {
|
444 | return ignored.test(nestedPath);
|
445 | }
|
446 | return nestedPath === ignored;
|
447 | });
|
448 | if (hasMatches) {
|
449 | return "continue";
|
450 | }
|
451 | }
|
452 | if (!isSerializable(nestedValue)) {
|
453 | return { value: {
|
454 | keyPath: nestedPath,
|
455 | value: nestedValue
|
456 | } };
|
457 | }
|
458 | if (typeof nestedValue === "object") {
|
459 | foundNestedSerializable = findNonSerializableValue(nestedValue, nestedPath, isSerializable, getEntries, ignoredPaths, cache);
|
460 | if (foundNestedSerializable) {
|
461 | return { value: foundNestedSerializable };
|
462 | }
|
463 | }
|
464 | };
|
465 | for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
|
466 | var _c = entries_1[_i], key = _c[0], nestedValue = _c[1];
|
467 | var state_2 = _loop_3(key, nestedValue);
|
468 | if (typeof state_2 === "object")
|
469 | return state_2.value;
|
470 | }
|
471 | if (cache && isNestedFrozen(value))
|
472 | cache.add(value);
|
473 | return false;
|
474 | }
|
475 | function isNestedFrozen(value) {
|
476 | if (!Object.isFrozen(value))
|
477 | return false;
|
478 | for (var _i = 0, _c = Object.values(value); _i < _c.length; _i++) {
|
479 | var nestedValue = _c[_i];
|
480 | if (typeof nestedValue !== "object" || nestedValue === null)
|
481 | continue;
|
482 | if (!isNestedFrozen(nestedValue))
|
483 | return false;
|
484 | }
|
485 | return true;
|
486 | }
|
487 | function createSerializableStateInvariantMiddleware(options) {
|
488 | if (options === void 0) { options = {}; }
|
489 | if (false) {
|
490 | return function () { return function (next) { return function (action) { return next(action); }; }; };
|
491 | }
|
492 | var _c = options.isSerializable, isSerializable = _c === void 0 ? isPlain : _c, getEntries = options.getEntries, _d = options.ignoredActions, ignoredActions = _d === void 0 ? [] : _d, _e = options.ignoredActionPaths, ignoredActionPaths = _e === void 0 ? ["meta.arg", "meta.baseQueryMeta"] : _e, _f = options.ignoredPaths, ignoredPaths = _f === void 0 ? [] : _f, _g = options.warnAfter, warnAfter = _g === void 0 ? 32 : _g, _h = options.ignoreState, ignoreState = _h === void 0 ? false : _h, _j = options.ignoreActions, ignoreActions = _j === void 0 ? false : _j, _k = options.disableCache, disableCache = _k === void 0 ? false : _k;
|
493 | var cache = !disableCache && WeakSet ? new WeakSet() : void 0;
|
494 | return function (storeAPI) { return function (next) { return function (action) {
|
495 | var result = next(action);
|
496 | var measureUtils = getTimeMeasureUtils(warnAfter, "SerializableStateInvariantMiddleware");
|
497 | if (!ignoreActions && !(ignoredActions.length && ignoredActions.indexOf(action.type) !== -1)) {
|
498 | measureUtils.measureTime(function () {
|
499 | var foundActionNonSerializableValue = findNonSerializableValue(action, "", isSerializable, getEntries, ignoredActionPaths, cache);
|
500 | if (foundActionNonSerializableValue) {
|
501 | var keyPath = foundActionNonSerializableValue.keyPath, value = foundActionNonSerializableValue.value;
|
502 | 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)");
|
503 | }
|
504 | });
|
505 | }
|
506 | if (!ignoreState) {
|
507 | measureUtils.measureTime(function () {
|
508 | var state = storeAPI.getState();
|
509 | var foundStateNonSerializableValue = findNonSerializableValue(state, "", isSerializable, getEntries, ignoredPaths, cache);
|
510 | if (foundStateNonSerializableValue) {
|
511 | var keyPath = foundStateNonSerializableValue.keyPath, value = foundStateNonSerializableValue.value;
|
512 | console.error("A non-serializable value was detected in the state, in the path: `" + keyPath + "`. Value:", value, "\nTake a look at the reducer(s) handling this action type: " + action.type + ".\n(See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)");
|
513 | }
|
514 | });
|
515 | measureUtils.warnIfExceeded();
|
516 | }
|
517 | return result;
|
518 | }; }; };
|
519 | }
|
520 |
|
521 | function isBoolean(x) {
|
522 | return typeof x === "boolean";
|
523 | }
|
524 | function curryGetDefaultMiddleware() {
|
525 | return function curriedGetDefaultMiddleware(options) {
|
526 | return getDefaultMiddleware(options);
|
527 | };
|
528 | }
|
529 | function getDefaultMiddleware(options) {
|
530 | if (options === void 0) { options = {}; }
|
531 | var _c = options.thunk, thunk = _c === void 0 ? true : _c, _d = options.immutableCheck, immutableCheck = _d === void 0 ? true : _d, _e = options.serializableCheck, serializableCheck = _e === void 0 ? true : _e;
|
532 | var middlewareArray = new MiddlewareArray();
|
533 | if (thunk) {
|
534 | if (isBoolean(thunk)) {
|
535 | middlewareArray.push(import_redux_thunk.default);
|
536 | }
|
537 | else {
|
538 | middlewareArray.push(import_redux_thunk.default.withExtraArgument(thunk.extraArgument));
|
539 | }
|
540 | }
|
541 | if (true) {
|
542 | if (immutableCheck) {
|
543 | var immutableOptions = {};
|
544 | if (!isBoolean(immutableCheck)) {
|
545 | immutableOptions = immutableCheck;
|
546 | }
|
547 | middlewareArray.unshift(createImmutableStateInvariantMiddleware(immutableOptions));
|
548 | }
|
549 | if (serializableCheck) {
|
550 | var serializableOptions = {};
|
551 | if (!isBoolean(serializableCheck)) {
|
552 | serializableOptions = serializableCheck;
|
553 | }
|
554 | middlewareArray.push(createSerializableStateInvariantMiddleware(serializableOptions));
|
555 | }
|
556 | }
|
557 | return middlewareArray;
|
558 | }
|
559 |
|
560 | var IS_PRODUCTION = false;
|
561 | function configureStore(options) {
|
562 | var curriedGetDefaultMiddleware = curryGetDefaultMiddleware();
|
563 | var _c = options || {}, _d = _c.reducer, reducer = _d === void 0 ? void 0 : _d, _e = _c.middleware, middleware = _e === void 0 ? curriedGetDefaultMiddleware() : _e, _f = _c.devTools, devTools = _f === void 0 ? true : _f, _g = _c.preloadedState, preloadedState = _g === void 0 ? void 0 : _g, _h = _c.enhancers, enhancers = _h === void 0 ? void 0 : _h;
|
564 | var rootReducer;
|
565 | if (typeof reducer === "function") {
|
566 | rootReducer = reducer;
|
567 | }
|
568 | else if (isPlainObject(reducer)) {
|
569 | rootReducer = (0, import_redux2.combineReducers)(reducer);
|
570 | }
|
571 | else {
|
572 | throw new Error('"reducer" is a required argument, and must be a function or an object of functions that can be passed to combineReducers');
|
573 | }
|
574 | var finalMiddleware = middleware;
|
575 | if (typeof finalMiddleware === "function") {
|
576 | finalMiddleware = finalMiddleware(curriedGetDefaultMiddleware);
|
577 | if (!IS_PRODUCTION && !Array.isArray(finalMiddleware)) {
|
578 | throw new Error("when using a middleware builder function, an array of middleware must be returned");
|
579 | }
|
580 | }
|
581 | if (!IS_PRODUCTION && finalMiddleware.some(function (item) { return typeof item !== "function"; })) {
|
582 | throw new Error("each middleware provided to configureStore must be a function");
|
583 | }
|
584 | var middlewareEnhancer = (0, import_redux2.applyMiddleware).apply(void 0, finalMiddleware);
|
585 | var finalCompose = import_redux2.compose;
|
586 | if (devTools) {
|
587 | finalCompose = composeWithDevTools(__spreadValues({
|
588 | trace: !IS_PRODUCTION
|
589 | }, typeof devTools === "object" && devTools));
|
590 | }
|
591 | var storeEnhancers = [middlewareEnhancer];
|
592 | if (Array.isArray(enhancers)) {
|
593 | storeEnhancers = __spreadArray([middlewareEnhancer], enhancers);
|
594 | }
|
595 | else if (typeof enhancers === "function") {
|
596 | storeEnhancers = enhancers(storeEnhancers);
|
597 | }
|
598 | var composedEnhancer = finalCompose.apply(void 0, storeEnhancers);
|
599 | return (0, import_redux2.createStore)(rootReducer, preloadedState, composedEnhancer);
|
600 | }
|
601 |
|
602 | function createAction(type, prepareAction) {
|
603 | function actionCreator() {
|
604 | var args = [];
|
605 | for (var _i = 0; _i < arguments.length; _i++) {
|
606 | args[_i] = arguments[_i];
|
607 | }
|
608 | if (prepareAction) {
|
609 | var prepared = prepareAction.apply(void 0, args);
|
610 | if (!prepared) {
|
611 | throw new Error("prepareAction did not return an object");
|
612 | }
|
613 | return __spreadValues(__spreadValues({
|
614 | type: type,
|
615 | payload: prepared.payload
|
616 | }, "meta" in prepared && { meta: prepared.meta }), "error" in prepared && { error: prepared.error });
|
617 | }
|
618 | return { type: type, payload: args[0] };
|
619 | }
|
620 | actionCreator.toString = function () { return "" + type; };
|
621 | actionCreator.type = type;
|
622 | actionCreator.match = function (action) { return action.type === type; };
|
623 | return actionCreator;
|
624 | }
|
625 | function isFSA(action) {
|
626 | return isPlainObject(action) && typeof action.type === "string" && Object.keys(action).every(isValidKey);
|
627 | }
|
628 | function isValidKey(key) {
|
629 | return ["type", "payload", "error", "meta"].indexOf(key) > -1;
|
630 | }
|
631 | function getType(actionCreator) {
|
632 | return "" + actionCreator;
|
633 | }
|
634 |
|
635 | var import_immer3 = __toModule(require("immer"));
|
636 |
|
637 | function executeReducerBuilderCallback(builderCallback) {
|
638 | var actionsMap = {};
|
639 | var actionMatchers = [];
|
640 | var defaultCaseReducer;
|
641 | var builder = {
|
642 | addCase: function (typeOrActionCreator, reducer) {
|
643 | if (true) {
|
644 | if (actionMatchers.length > 0) {
|
645 | throw new Error("`builder.addCase` should only be called before calling `builder.addMatcher`");
|
646 | }
|
647 | if (defaultCaseReducer) {
|
648 | throw new Error("`builder.addCase` should only be called before calling `builder.addDefaultCase`");
|
649 | }
|
650 | }
|
651 | var type = typeof typeOrActionCreator === "string" ? typeOrActionCreator : typeOrActionCreator.type;
|
652 | if (type in actionsMap) {
|
653 | throw new Error("addCase cannot be called with two reducers for the same action type");
|
654 | }
|
655 | actionsMap[type] = reducer;
|
656 | return builder;
|
657 | },
|
658 | addMatcher: function (matcher, reducer) {
|
659 | if (true) {
|
660 | if (defaultCaseReducer) {
|
661 | throw new Error("`builder.addMatcher` should only be called before calling `builder.addDefaultCase`");
|
662 | }
|
663 | }
|
664 | actionMatchers.push({ matcher: matcher, reducer: reducer });
|
665 | return builder;
|
666 | },
|
667 | addDefaultCase: function (reducer) {
|
668 | if (true) {
|
669 | if (defaultCaseReducer) {
|
670 | throw new Error("`builder.addDefaultCase` can only be called once");
|
671 | }
|
672 | }
|
673 | defaultCaseReducer = reducer;
|
674 | return builder;
|
675 | }
|
676 | };
|
677 | builderCallback(builder);
|
678 | return [actionsMap, actionMatchers, defaultCaseReducer];
|
679 | }
|
680 |
|
681 | function isStateFunction(x) {
|
682 | return typeof x === "function";
|
683 | }
|
684 | var hasWarnedAboutObjectNotation = false;
|
685 | function createReducer(initialState, mapOrBuilderCallback, actionMatchers, defaultCaseReducer) {
|
686 | if (actionMatchers === void 0) { actionMatchers = []; }
|
687 | if (true) {
|
688 | if (typeof mapOrBuilderCallback === "object") {
|
689 | if (!hasWarnedAboutObjectNotation) {
|
690 | hasWarnedAboutObjectNotation = true;
|
691 | console.warn("The object notation for `createReducer` is deprecated, and will be removed in RTK 2.0. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createReducer");
|
692 | }
|
693 | }
|
694 | }
|
695 | var _c = typeof mapOrBuilderCallback === "function" ? executeReducerBuilderCallback(mapOrBuilderCallback) : [mapOrBuilderCallback, actionMatchers, defaultCaseReducer], actionsMap = _c[0], finalActionMatchers = _c[1], finalDefaultCaseReducer = _c[2];
|
696 | var getInitialState;
|
697 | if (isStateFunction(initialState)) {
|
698 | getInitialState = function () { return freezeDraftable(initialState()); };
|
699 | }
|
700 | else {
|
701 | var frozenInitialState_1 = freezeDraftable(initialState);
|
702 | getInitialState = function () { return frozenInitialState_1; };
|
703 | }
|
704 | function reducer(state, action) {
|
705 | if (state === void 0) { state = getInitialState(); }
|
706 | var caseReducers = __spreadArray([
|
707 | actionsMap[action.type]
|
708 | ], finalActionMatchers.filter(function (_c) {
|
709 | var matcher = _c.matcher;
|
710 | return matcher(action);
|
711 | }).map(function (_c) {
|
712 | var reducer2 = _c.reducer;
|
713 | return reducer2;
|
714 | }));
|
715 | if (caseReducers.filter(function (cr) { return !!cr; }).length === 0) {
|
716 | caseReducers = [finalDefaultCaseReducer];
|
717 | }
|
718 | return caseReducers.reduce(function (previousState, caseReducer) {
|
719 | if (caseReducer) {
|
720 | if ((0, import_immer3.isDraft)(previousState)) {
|
721 | var draft = previousState;
|
722 | var result = caseReducer(draft, action);
|
723 | if (result === void 0) {
|
724 | return previousState;
|
725 | }
|
726 | return result;
|
727 | }
|
728 | else if (!(0, import_immer3.isDraftable)(previousState)) {
|
729 | var result = caseReducer(previousState, action);
|
730 | if (result === void 0) {
|
731 | if (previousState === null) {
|
732 | return previousState;
|
733 | }
|
734 | throw Error("A case reducer on a non-draftable value must not return undefined");
|
735 | }
|
736 | return result;
|
737 | }
|
738 | else {
|
739 | return (0, import_immer3.default)(previousState, function (draft) {
|
740 | return caseReducer(draft, action);
|
741 | });
|
742 | }
|
743 | }
|
744 | return previousState;
|
745 | }, state);
|
746 | }
|
747 | reducer.getInitialState = getInitialState;
|
748 | return reducer;
|
749 | }
|
750 |
|
751 | var hasWarnedAboutObjectNotation2 = false;
|
752 | function getType2(slice, actionKey) {
|
753 | return slice + "/" + actionKey;
|
754 | }
|
755 | function createSlice(options) {
|
756 | var name = options.name;
|
757 | if (!name) {
|
758 | throw new Error("`name` is a required option for createSlice");
|
759 | }
|
760 | if (typeof process !== "undefined" && true) {
|
761 | if (options.initialState === void 0) {
|
762 | console.error("You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`");
|
763 | }
|
764 | }
|
765 | var initialState = typeof options.initialState == "function" ? options.initialState : freezeDraftable(options.initialState);
|
766 | var reducers = options.reducers || {};
|
767 | var reducerNames = Object.keys(reducers);
|
768 | var sliceCaseReducersByName = {};
|
769 | var sliceCaseReducersByType = {};
|
770 | var actionCreators = {};
|
771 | reducerNames.forEach(function (reducerName) {
|
772 | var maybeReducerWithPrepare = reducers[reducerName];
|
773 | var type = getType2(name, reducerName);
|
774 | var caseReducer;
|
775 | var prepareCallback;
|
776 | if ("reducer" in maybeReducerWithPrepare) {
|
777 | caseReducer = maybeReducerWithPrepare.reducer;
|
778 | prepareCallback = maybeReducerWithPrepare.prepare;
|
779 | }
|
780 | else {
|
781 | caseReducer = maybeReducerWithPrepare;
|
782 | }
|
783 | sliceCaseReducersByName[reducerName] = caseReducer;
|
784 | sliceCaseReducersByType[type] = caseReducer;
|
785 | actionCreators[reducerName] = prepareCallback ? createAction(type, prepareCallback) : createAction(type);
|
786 | });
|
787 | function buildReducer() {
|
788 | if (true) {
|
789 | if (typeof options.extraReducers === "object") {
|
790 | if (!hasWarnedAboutObjectNotation2) {
|
791 | hasWarnedAboutObjectNotation2 = true;
|
792 | console.warn("The object notation for `createSlice.extraReducers` is deprecated, and will be removed in RTK 2.0. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createSlice");
|
793 | }
|
794 | }
|
795 | }
|
796 | var _c = typeof options.extraReducers === "function" ? executeReducerBuilderCallback(options.extraReducers) : [options.extraReducers], _d = _c[0], extraReducers = _d === void 0 ? {} : _d, _e = _c[1], actionMatchers = _e === void 0 ? [] : _e, _f = _c[2], defaultCaseReducer = _f === void 0 ? void 0 : _f;
|
797 | var finalCaseReducers = __spreadValues(__spreadValues({}, extraReducers), sliceCaseReducersByType);
|
798 | return createReducer(initialState, function (builder) {
|
799 | for (var key in finalCaseReducers) {
|
800 | builder.addCase(key, finalCaseReducers[key]);
|
801 | }
|
802 | for (var _i = 0, actionMatchers_1 = actionMatchers; _i < actionMatchers_1.length; _i++) {
|
803 | var m = actionMatchers_1[_i];
|
804 | builder.addMatcher(m.matcher, m.reducer);
|
805 | }
|
806 | if (defaultCaseReducer) {
|
807 | builder.addDefaultCase(defaultCaseReducer);
|
808 | }
|
809 | });
|
810 | }
|
811 | var _reducer;
|
812 | return {
|
813 | name: name,
|
814 | reducer: function (state, action) {
|
815 | if (!_reducer)
|
816 | _reducer = buildReducer();
|
817 | return _reducer(state, action);
|
818 | },
|
819 | actions: actionCreators,
|
820 | caseReducers: sliceCaseReducersByName,
|
821 | getInitialState: function () {
|
822 | if (!_reducer)
|
823 | _reducer = buildReducer();
|
824 | return _reducer.getInitialState();
|
825 | }
|
826 | };
|
827 | }
|
828 |
|
829 | function getInitialEntityState() {
|
830 | return {
|
831 | ids: [],
|
832 | entities: {}
|
833 | };
|
834 | }
|
835 | function createInitialStateFactory() {
|
836 | function getInitialState(additionalState) {
|
837 | if (additionalState === void 0) { additionalState = {}; }
|
838 | return Object.assign(getInitialEntityState(), additionalState);
|
839 | }
|
840 | return { getInitialState: getInitialState };
|
841 | }
|
842 |
|
843 | function createSelectorsFactory() {
|
844 | function getSelectors(selectState) {
|
845 | var selectIds = function (state) { return state.ids; };
|
846 | var selectEntities = function (state) { return state.entities; };
|
847 | var selectAll = createDraftSafeSelector(selectIds, selectEntities, function (ids, entities) { return ids.map(function (id) { return entities[id]; }); });
|
848 | var selectId = function (_, id) { return id; };
|
849 | var selectById = function (entities, id) { return entities[id]; };
|
850 | var selectTotal = createDraftSafeSelector(selectIds, function (ids) { return ids.length; });
|
851 | if (!selectState) {
|
852 | return {
|
853 | selectIds: selectIds,
|
854 | selectEntities: selectEntities,
|
855 | selectAll: selectAll,
|
856 | selectTotal: selectTotal,
|
857 | selectById: createDraftSafeSelector(selectEntities, selectId, selectById)
|
858 | };
|
859 | }
|
860 | var selectGlobalizedEntities = createDraftSafeSelector(selectState, selectEntities);
|
861 | return {
|
862 | selectIds: createDraftSafeSelector(selectState, selectIds),
|
863 | selectEntities: selectGlobalizedEntities,
|
864 | selectAll: createDraftSafeSelector(selectState, selectAll),
|
865 | selectTotal: createDraftSafeSelector(selectState, selectTotal),
|
866 | selectById: createDraftSafeSelector(selectGlobalizedEntities, selectId, selectById)
|
867 | };
|
868 | }
|
869 | return { getSelectors: getSelectors };
|
870 | }
|
871 |
|
872 | var import_immer4 = __toModule(require("immer"));
|
873 | function createSingleArgumentStateOperator(mutator) {
|
874 | var operator = createStateOperator(function (_, state) { return mutator(state); });
|
875 | return function operation(state) {
|
876 | return operator(state, void 0);
|
877 | };
|
878 | }
|
879 | function createStateOperator(mutator) {
|
880 | return function operation(state, arg) {
|
881 | function isPayloadActionArgument(arg2) {
|
882 | return isFSA(arg2);
|
883 | }
|
884 | var runMutator = function (draft) {
|
885 | if (isPayloadActionArgument(arg)) {
|
886 | mutator(arg.payload, draft);
|
887 | }
|
888 | else {
|
889 | mutator(arg, draft);
|
890 | }
|
891 | };
|
892 | if ((0, import_immer4.isDraft)(state)) {
|
893 | runMutator(state);
|
894 | return state;
|
895 | }
|
896 | else {
|
897 | return (0, import_immer4.default)(state, runMutator);
|
898 | }
|
899 | };
|
900 | }
|
901 |
|
902 | function selectIdValue(entity, selectId) {
|
903 | var key = selectId(entity);
|
904 | if (key === void 0) {
|
905 | 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());
|
906 | }
|
907 | return key;
|
908 | }
|
909 | function ensureEntitiesArray(entities) {
|
910 | if (!Array.isArray(entities)) {
|
911 | entities = Object.values(entities);
|
912 | }
|
913 | return entities;
|
914 | }
|
915 | function splitAddedUpdatedEntities(newEntities, selectId, state) {
|
916 | newEntities = ensureEntitiesArray(newEntities);
|
917 | var added = [];
|
918 | var updated = [];
|
919 | for (var _i = 0, newEntities_1 = newEntities; _i < newEntities_1.length; _i++) {
|
920 | var entity = newEntities_1[_i];
|
921 | var id = selectIdValue(entity, selectId);
|
922 | if (id in state.entities) {
|
923 | updated.push({ id: id, changes: entity });
|
924 | }
|
925 | else {
|
926 | added.push(entity);
|
927 | }
|
928 | }
|
929 | return [added, updated];
|
930 | }
|
931 |
|
932 | function createUnsortedStateAdapter(selectId) {
|
933 | function addOneMutably(entity, state) {
|
934 | var key = selectIdValue(entity, selectId);
|
935 | if (key in state.entities) {
|
936 | return;
|
937 | }
|
938 | state.ids.push(key);
|
939 | state.entities[key] = entity;
|
940 | }
|
941 | function addManyMutably(newEntities, state) {
|
942 | newEntities = ensureEntitiesArray(newEntities);
|
943 | for (var _i = 0, newEntities_2 = newEntities; _i < newEntities_2.length; _i++) {
|
944 | var entity = newEntities_2[_i];
|
945 | addOneMutably(entity, state);
|
946 | }
|
947 | }
|
948 | function setOneMutably(entity, state) {
|
949 | var key = selectIdValue(entity, selectId);
|
950 | if (!(key in state.entities)) {
|
951 | state.ids.push(key);
|
952 | }
|
953 | state.entities[key] = entity;
|
954 | }
|
955 | function setManyMutably(newEntities, state) {
|
956 | newEntities = ensureEntitiesArray(newEntities);
|
957 | for (var _i = 0, newEntities_3 = newEntities; _i < newEntities_3.length; _i++) {
|
958 | var entity = newEntities_3[_i];
|
959 | setOneMutably(entity, state);
|
960 | }
|
961 | }
|
962 | function setAllMutably(newEntities, state) {
|
963 | newEntities = ensureEntitiesArray(newEntities);
|
964 | state.ids = [];
|
965 | state.entities = {};
|
966 | addManyMutably(newEntities, state);
|
967 | }
|
968 | function removeOneMutably(key, state) {
|
969 | return removeManyMutably([key], state);
|
970 | }
|
971 | function removeManyMutably(keys, state) {
|
972 | var didMutate = false;
|
973 | keys.forEach(function (key) {
|
974 | if (key in state.entities) {
|
975 | delete state.entities[key];
|
976 | didMutate = true;
|
977 | }
|
978 | });
|
979 | if (didMutate) {
|
980 | state.ids = state.ids.filter(function (id) { return id in state.entities; });
|
981 | }
|
982 | }
|
983 | function removeAllMutably(state) {
|
984 | Object.assign(state, {
|
985 | ids: [],
|
986 | entities: {}
|
987 | });
|
988 | }
|
989 | function takeNewKey(keys, update, state) {
|
990 | var original2 = state.entities[update.id];
|
991 | var updated = Object.assign({}, original2, update.changes);
|
992 | var newKey = selectIdValue(updated, selectId);
|
993 | var hasNewKey = newKey !== update.id;
|
994 | if (hasNewKey) {
|
995 | keys[update.id] = newKey;
|
996 | delete state.entities[update.id];
|
997 | }
|
998 | state.entities[newKey] = updated;
|
999 | return hasNewKey;
|
1000 | }
|
1001 | function updateOneMutably(update, state) {
|
1002 | return updateManyMutably([update], state);
|
1003 | }
|
1004 | function updateManyMutably(updates, state) {
|
1005 | var newKeys = {};
|
1006 | var updatesPerEntity = {};
|
1007 | updates.forEach(function (update) {
|
1008 | if (update.id in state.entities) {
|
1009 | updatesPerEntity[update.id] = {
|
1010 | id: update.id,
|
1011 | changes: __spreadValues(__spreadValues({}, updatesPerEntity[update.id] ? updatesPerEntity[update.id].changes : null), update.changes)
|
1012 | };
|
1013 | }
|
1014 | });
|
1015 | updates = Object.values(updatesPerEntity);
|
1016 | var didMutateEntities = updates.length > 0;
|
1017 | if (didMutateEntities) {
|
1018 | var didMutateIds = updates.filter(function (update) { return takeNewKey(newKeys, update, state); }).length > 0;
|
1019 | if (didMutateIds) {
|
1020 | state.ids = Object.keys(state.entities);
|
1021 | }
|
1022 | }
|
1023 | }
|
1024 | function upsertOneMutably(entity, state) {
|
1025 | return upsertManyMutably([entity], state);
|
1026 | }
|
1027 | function upsertManyMutably(newEntities, state) {
|
1028 | var _c = splitAddedUpdatedEntities(newEntities, selectId, state), added = _c[0], updated = _c[1];
|
1029 | updateManyMutably(updated, state);
|
1030 | addManyMutably(added, state);
|
1031 | }
|
1032 | return {
|
1033 | removeAll: createSingleArgumentStateOperator(removeAllMutably),
|
1034 | addOne: createStateOperator(addOneMutably),
|
1035 | addMany: createStateOperator(addManyMutably),
|
1036 | setOne: createStateOperator(setOneMutably),
|
1037 | setMany: createStateOperator(setManyMutably),
|
1038 | setAll: createStateOperator(setAllMutably),
|
1039 | updateOne: createStateOperator(updateOneMutably),
|
1040 | updateMany: createStateOperator(updateManyMutably),
|
1041 | upsertOne: createStateOperator(upsertOneMutably),
|
1042 | upsertMany: createStateOperator(upsertManyMutably),
|
1043 | removeOne: createStateOperator(removeOneMutably),
|
1044 | removeMany: createStateOperator(removeManyMutably)
|
1045 | };
|
1046 | }
|
1047 |
|
1048 | function createSortedStateAdapter(selectId, sort) {
|
1049 | var _c = createUnsortedStateAdapter(selectId), removeOne = _c.removeOne, removeMany = _c.removeMany, removeAll = _c.removeAll;
|
1050 | function addOneMutably(entity, state) {
|
1051 | return addManyMutably([entity], state);
|
1052 | }
|
1053 | function addManyMutably(newEntities, state) {
|
1054 | newEntities = ensureEntitiesArray(newEntities);
|
1055 | var models = newEntities.filter(function (model) { return !(selectIdValue(model, selectId) in state.entities); });
|
1056 | if (models.length !== 0) {
|
1057 | merge(models, state);
|
1058 | }
|
1059 | }
|
1060 | function setOneMutably(entity, state) {
|
1061 | return setManyMutably([entity], state);
|
1062 | }
|
1063 | function setManyMutably(newEntities, state) {
|
1064 | newEntities = ensureEntitiesArray(newEntities);
|
1065 | if (newEntities.length !== 0) {
|
1066 | merge(newEntities, state);
|
1067 | }
|
1068 | }
|
1069 | function setAllMutably(newEntities, state) {
|
1070 | newEntities = ensureEntitiesArray(newEntities);
|
1071 | state.entities = {};
|
1072 | state.ids = [];
|
1073 | addManyMutably(newEntities, state);
|
1074 | }
|
1075 | function updateOneMutably(update, state) {
|
1076 | return updateManyMutably([update], state);
|
1077 | }
|
1078 | function updateManyMutably(updates, state) {
|
1079 | var appliedUpdates = false;
|
1080 | for (var _i = 0, updates_1 = updates; _i < updates_1.length; _i++) {
|
1081 | var update = updates_1[_i];
|
1082 | var entity = state.entities[update.id];
|
1083 | if (!entity) {
|
1084 | continue;
|
1085 | }
|
1086 | appliedUpdates = true;
|
1087 | Object.assign(entity, update.changes);
|
1088 | var newId = selectId(entity);
|
1089 | if (update.id !== newId) {
|
1090 | delete state.entities[update.id];
|
1091 | state.entities[newId] = entity;
|
1092 | }
|
1093 | }
|
1094 | if (appliedUpdates) {
|
1095 | resortEntities(state);
|
1096 | }
|
1097 | }
|
1098 | function upsertOneMutably(entity, state) {
|
1099 | return upsertManyMutably([entity], state);
|
1100 | }
|
1101 | function upsertManyMutably(newEntities, state) {
|
1102 | var _c = splitAddedUpdatedEntities(newEntities, selectId, state), added = _c[0], updated = _c[1];
|
1103 | updateManyMutably(updated, state);
|
1104 | addManyMutably(added, state);
|
1105 | }
|
1106 | function areArraysEqual(a, b) {
|
1107 | if (a.length !== b.length) {
|
1108 | return false;
|
1109 | }
|
1110 | for (var i = 0; i < a.length && i < b.length; i++) {
|
1111 | if (a[i] === b[i]) {
|
1112 | continue;
|
1113 | }
|
1114 | return false;
|
1115 | }
|
1116 | return true;
|
1117 | }
|
1118 | function merge(models, state) {
|
1119 | models.forEach(function (model) {
|
1120 | state.entities[selectId(model)] = model;
|
1121 | });
|
1122 | resortEntities(state);
|
1123 | }
|
1124 | function resortEntities(state) {
|
1125 | var allEntities = Object.values(state.entities);
|
1126 | allEntities.sort(sort);
|
1127 | var newSortedIds = allEntities.map(selectId);
|
1128 | var ids = state.ids;
|
1129 | if (!areArraysEqual(ids, newSortedIds)) {
|
1130 | state.ids = newSortedIds;
|
1131 | }
|
1132 | }
|
1133 | return {
|
1134 | removeOne: removeOne,
|
1135 | removeMany: removeMany,
|
1136 | removeAll: removeAll,
|
1137 | addOne: createStateOperator(addOneMutably),
|
1138 | updateOne: createStateOperator(updateOneMutably),
|
1139 | upsertOne: createStateOperator(upsertOneMutably),
|
1140 | setOne: createStateOperator(setOneMutably),
|
1141 | setMany: createStateOperator(setManyMutably),
|
1142 | setAll: createStateOperator(setAllMutably),
|
1143 | addMany: createStateOperator(addManyMutably),
|
1144 | updateMany: createStateOperator(updateManyMutably),
|
1145 | upsertMany: createStateOperator(upsertManyMutably)
|
1146 | };
|
1147 | }
|
1148 |
|
1149 | function createEntityAdapter(options) {
|
1150 | if (options === void 0) { options = {}; }
|
1151 | var _c = __spreadValues({
|
1152 | sortComparer: false,
|
1153 | selectId: function (instance) { return instance.id; }
|
1154 | }, options), selectId = _c.selectId, sortComparer = _c.sortComparer;
|
1155 | var stateFactory = createInitialStateFactory();
|
1156 | var selectorsFactory = createSelectorsFactory();
|
1157 | var stateAdapter = sortComparer ? createSortedStateAdapter(selectId, sortComparer) : createUnsortedStateAdapter(selectId);
|
1158 | return __spreadValues(__spreadValues(__spreadValues({
|
1159 | selectId: selectId,
|
1160 | sortComparer: sortComparer
|
1161 | }, stateFactory), selectorsFactory), stateAdapter);
|
1162 | }
|
1163 |
|
1164 | var urlAlphabet = "ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW";
|
1165 | var nanoid = function (size) {
|
1166 | if (size === void 0) { size = 21; }
|
1167 | var id = "";
|
1168 | var i = size;
|
1169 | while (i--) {
|
1170 | id += urlAlphabet[Math.random() * 64 | 0];
|
1171 | }
|
1172 | return id;
|
1173 | };
|
1174 |
|
1175 | var commonProperties = [
|
1176 | "name",
|
1177 | "message",
|
1178 | "stack",
|
1179 | "code"
|
1180 | ];
|
1181 | var RejectWithValue = (function () {
|
1182 | function RejectWithValue(payload, meta) {
|
1183 | this.payload = payload;
|
1184 | this.meta = meta;
|
1185 | }
|
1186 | return RejectWithValue;
|
1187 | }());
|
1188 | var FulfillWithMeta = (function () {
|
1189 | function FulfillWithMeta(payload, meta) {
|
1190 | this.payload = payload;
|
1191 | this.meta = meta;
|
1192 | }
|
1193 | return FulfillWithMeta;
|
1194 | }());
|
1195 | var miniSerializeError = function (value) {
|
1196 | if (typeof value === "object" && value !== null) {
|
1197 | var simpleError = {};
|
1198 | for (var _i = 0, commonProperties_1 = commonProperties; _i < commonProperties_1.length; _i++) {
|
1199 | var property = commonProperties_1[_i];
|
1200 | if (typeof value[property] === "string") {
|
1201 | simpleError[property] = value[property];
|
1202 | }
|
1203 | }
|
1204 | return simpleError;
|
1205 | }
|
1206 | return { message: String(value) };
|
1207 | };
|
1208 | var createAsyncThunk = (function () {
|
1209 | function createAsyncThunk2(typePrefix, payloadCreator, options) {
|
1210 | var fulfilled = createAction(typePrefix + "/fulfilled", function (payload, requestId, arg, meta) { return ({
|
1211 | payload: payload,
|
1212 | meta: __spreadProps(__spreadValues({}, meta || {}), {
|
1213 | arg: arg,
|
1214 | requestId: requestId,
|
1215 | requestStatus: "fulfilled"
|
1216 | })
|
1217 | }); });
|
1218 | var pending = createAction(typePrefix + "/pending", function (requestId, arg, meta) { return ({
|
1219 | payload: void 0,
|
1220 | meta: __spreadProps(__spreadValues({}, meta || {}), {
|
1221 | arg: arg,
|
1222 | requestId: requestId,
|
1223 | requestStatus: "pending"
|
1224 | })
|
1225 | }); });
|
1226 | var rejected = createAction(typePrefix + "/rejected", function (error, requestId, arg, payload, meta) { return ({
|
1227 | payload: payload,
|
1228 | error: (options && options.serializeError || miniSerializeError)(error || "Rejected"),
|
1229 | meta: __spreadProps(__spreadValues({}, meta || {}), {
|
1230 | arg: arg,
|
1231 | requestId: requestId,
|
1232 | rejectedWithValue: !!payload,
|
1233 | requestStatus: "rejected",
|
1234 | aborted: (error == null ? void 0 : error.name) === "AbortError",
|
1235 | condition: (error == null ? void 0 : error.name) === "ConditionError"
|
1236 | })
|
1237 | }); });
|
1238 | var displayedWarning = false;
|
1239 | var AC = typeof AbortController !== "undefined" ? AbortController : (function () {
|
1240 | function class_1() {
|
1241 | this.signal = {
|
1242 | aborted: false,
|
1243 | addEventListener: function () {
|
1244 | },
|
1245 | dispatchEvent: function () {
|
1246 | return false;
|
1247 | },
|
1248 | onabort: function () {
|
1249 | },
|
1250 | removeEventListener: function () {
|
1251 | },
|
1252 | reason: void 0,
|
1253 | throwIfAborted: function () {
|
1254 | }
|
1255 | };
|
1256 | }
|
1257 | class_1.prototype.abort = function () {
|
1258 | if (true) {
|
1259 | if (!displayedWarning) {
|
1260 | displayedWarning = true;
|
1261 | console.info("This platform does not implement AbortController. \nIf you want to use the AbortController to react to `abort` events, please consider importing a polyfill like 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'.");
|
1262 | }
|
1263 | }
|
1264 | };
|
1265 | return class_1;
|
1266 | }());
|
1267 | function actionCreator(arg) {
|
1268 | return function (dispatch, getState, extra) {
|
1269 | var requestId = (options == null ? void 0 : options.idGenerator) ? options.idGenerator(arg) : nanoid();
|
1270 | var abortController = new AC();
|
1271 | var abortReason;
|
1272 | var started = false;
|
1273 | function abort(reason) {
|
1274 | abortReason = reason;
|
1275 | abortController.abort();
|
1276 | }
|
1277 | var promise2 = function () {
|
1278 | return __async(this, null, function () {
|
1279 | var _a, _b, finalAction, conditionResult, abortedPromise, err_1, skipDispatch;
|
1280 | return __generator(this, function (_c) {
|
1281 | switch (_c.label) {
|
1282 | case 0:
|
1283 | _c.trys.push([0, 4, , 5]);
|
1284 | conditionResult = (_a = options == null ? void 0 : options.condition) == null ? void 0 : _a.call(options, arg, { getState: getState, extra: extra });
|
1285 | if (!isThenable(conditionResult)) return [3 , 2];
|
1286 | return [4 , conditionResult];
|
1287 | case 1:
|
1288 | conditionResult = _c.sent();
|
1289 | _c.label = 2;
|
1290 | case 2:
|
1291 | if (conditionResult === false || abortController.signal.aborted) {
|
1292 | throw {
|
1293 | name: "ConditionError",
|
1294 | message: "Aborted due to condition callback returning false."
|
1295 | };
|
1296 | }
|
1297 | started = true;
|
1298 | abortedPromise = new Promise(function (_, reject) { return abortController.signal.addEventListener("abort", function () { return reject({
|
1299 | name: "AbortError",
|
1300 | message: abortReason || "Aborted"
|
1301 | }); }); });
|
1302 | dispatch(pending(requestId, arg, (_b = options == null ? void 0 : options.getPendingMeta) == null ? void 0 : _b.call(options, { requestId: requestId, arg: arg }, { getState: getState, extra: extra })));
|
1303 | return [4 , Promise.race([
|
1304 | abortedPromise,
|
1305 | Promise.resolve(payloadCreator(arg, {
|
1306 | dispatch: dispatch,
|
1307 | getState: getState,
|
1308 | extra: extra,
|
1309 | requestId: requestId,
|
1310 | signal: abortController.signal,
|
1311 | abort: abort,
|
1312 | rejectWithValue: function (value, meta) {
|
1313 | return new RejectWithValue(value, meta);
|
1314 | },
|
1315 | fulfillWithValue: function (value, meta) {
|
1316 | return new FulfillWithMeta(value, meta);
|
1317 | }
|
1318 | })).then(function (result) {
|
1319 | if (result instanceof RejectWithValue) {
|
1320 | throw result;
|
1321 | }
|
1322 | if (result instanceof FulfillWithMeta) {
|
1323 | return fulfilled(result.payload, requestId, arg, result.meta);
|
1324 | }
|
1325 | return fulfilled(result, requestId, arg);
|
1326 | })
|
1327 | ])];
|
1328 | case 3:
|
1329 | finalAction = _c.sent();
|
1330 | return [3 , 5];
|
1331 | case 4:
|
1332 | err_1 = _c.sent();
|
1333 | finalAction = err_1 instanceof RejectWithValue ? rejected(null, requestId, arg, err_1.payload, err_1.meta) : rejected(err_1, requestId, arg);
|
1334 | return [3 , 5];
|
1335 | case 5:
|
1336 | skipDispatch = options && !options.dispatchConditionRejection && rejected.match(finalAction) && finalAction.meta.condition;
|
1337 | if (!skipDispatch) {
|
1338 | dispatch(finalAction);
|
1339 | }
|
1340 | return [2 , finalAction];
|
1341 | }
|
1342 | });
|
1343 | });
|
1344 | }();
|
1345 | return Object.assign(promise2, {
|
1346 | abort: abort,
|
1347 | requestId: requestId,
|
1348 | arg: arg,
|
1349 | unwrap: function () {
|
1350 | return promise2.then(unwrapResult);
|
1351 | }
|
1352 | });
|
1353 | };
|
1354 | }
|
1355 | return Object.assign(actionCreator, {
|
1356 | pending: pending,
|
1357 | rejected: rejected,
|
1358 | fulfilled: fulfilled,
|
1359 | typePrefix: typePrefix
|
1360 | });
|
1361 | }
|
1362 | createAsyncThunk2.withTypes = function () { return createAsyncThunk2; };
|
1363 | return createAsyncThunk2;
|
1364 | })();
|
1365 | function unwrapResult(action) {
|
1366 | if (action.meta && action.meta.rejectedWithValue) {
|
1367 | throw action.payload;
|
1368 | }
|
1369 | if (action.error) {
|
1370 | throw action.error;
|
1371 | }
|
1372 | return action.payload;
|
1373 | }
|
1374 | function isThenable(value) {
|
1375 | return value !== null && typeof value === "object" && typeof value.then === "function";
|
1376 | }
|
1377 |
|
1378 | var hasMatchFunction = function (v) {
|
1379 | return v && typeof v.match === "function";
|
1380 | };
|
1381 |
|
1382 | var matches = function (matcher, action) {
|
1383 | if (hasMatchFunction(matcher)) {
|
1384 | return matcher.match(action);
|
1385 | }
|
1386 | else {
|
1387 | return matcher(action);
|
1388 | }
|
1389 | };
|
1390 | function isAnyOf() {
|
1391 | var matchers = [];
|
1392 | for (var _i = 0; _i < arguments.length; _i++) {
|
1393 | matchers[_i] = arguments[_i];
|
1394 | }
|
1395 | return function (action) {
|
1396 | return matchers.some(function (matcher) { return matches(matcher, action); });
|
1397 | };
|
1398 | }
|
1399 | function isAllOf() {
|
1400 | var matchers = [];
|
1401 | for (var _i = 0; _i < arguments.length; _i++) {
|
1402 | matchers[_i] = arguments[_i];
|
1403 | }
|
1404 | return function (action) {
|
1405 | return matchers.every(function (matcher) { return matches(matcher, action); });
|
1406 | };
|
1407 | }
|
1408 | function hasExpectedRequestMetadata(action, validStatus) {
|
1409 | if (!action || !action.meta)
|
1410 | return false;
|
1411 | var hasValidRequestId = typeof action.meta.requestId === "string";
|
1412 | var hasValidRequestStatus = validStatus.indexOf(action.meta.requestStatus) > -1;
|
1413 | return hasValidRequestId && hasValidRequestStatus;
|
1414 | }
|
1415 | function isAsyncThunkArray(a) {
|
1416 | return typeof a[0] === "function" && "pending" in a[0] && "fulfilled" in a[0] && "rejected" in a[0];
|
1417 | }
|
1418 | function isPending() {
|
1419 | var asyncThunks = [];
|
1420 | for (var _i = 0; _i < arguments.length; _i++) {
|
1421 | asyncThunks[_i] = arguments[_i];
|
1422 | }
|
1423 | if (asyncThunks.length === 0) {
|
1424 | return function (action) { return hasExpectedRequestMetadata(action, ["pending"]); };
|
1425 | }
|
1426 | if (!isAsyncThunkArray(asyncThunks)) {
|
1427 | return isPending()(asyncThunks[0]);
|
1428 | }
|
1429 | return function (action) {
|
1430 | var matchers = asyncThunks.map(function (asyncThunk) { return asyncThunk.pending; });
|
1431 | var combinedMatcher = isAnyOf.apply(void 0, matchers);
|
1432 | return combinedMatcher(action);
|
1433 | };
|
1434 | }
|
1435 | function isRejected() {
|
1436 | var asyncThunks = [];
|
1437 | for (var _i = 0; _i < arguments.length; _i++) {
|
1438 | asyncThunks[_i] = arguments[_i];
|
1439 | }
|
1440 | if (asyncThunks.length === 0) {
|
1441 | return function (action) { return hasExpectedRequestMetadata(action, ["rejected"]); };
|
1442 | }
|
1443 | if (!isAsyncThunkArray(asyncThunks)) {
|
1444 | return isRejected()(asyncThunks[0]);
|
1445 | }
|
1446 | return function (action) {
|
1447 | var matchers = asyncThunks.map(function (asyncThunk) { return asyncThunk.rejected; });
|
1448 | var combinedMatcher = isAnyOf.apply(void 0, matchers);
|
1449 | return combinedMatcher(action);
|
1450 | };
|
1451 | }
|
1452 | function isRejectedWithValue() {
|
1453 | var asyncThunks = [];
|
1454 | for (var _i = 0; _i < arguments.length; _i++) {
|
1455 | asyncThunks[_i] = arguments[_i];
|
1456 | }
|
1457 | var hasFlag = function (action) {
|
1458 | return action && action.meta && action.meta.rejectedWithValue;
|
1459 | };
|
1460 | if (asyncThunks.length === 0) {
|
1461 | return function (action) {
|
1462 | var combinedMatcher = isAllOf(isRejected.apply(void 0, asyncThunks), hasFlag);
|
1463 | return combinedMatcher(action);
|
1464 | };
|
1465 | }
|
1466 | if (!isAsyncThunkArray(asyncThunks)) {
|
1467 | return isRejectedWithValue()(asyncThunks[0]);
|
1468 | }
|
1469 | return function (action) {
|
1470 | var combinedMatcher = isAllOf(isRejected.apply(void 0, asyncThunks), hasFlag);
|
1471 | return combinedMatcher(action);
|
1472 | };
|
1473 | }
|
1474 | function isFulfilled() {
|
1475 | var asyncThunks = [];
|
1476 | for (var _i = 0; _i < arguments.length; _i++) {
|
1477 | asyncThunks[_i] = arguments[_i];
|
1478 | }
|
1479 | if (asyncThunks.length === 0) {
|
1480 | return function (action) { return hasExpectedRequestMetadata(action, ["fulfilled"]); };
|
1481 | }
|
1482 | if (!isAsyncThunkArray(asyncThunks)) {
|
1483 | return isFulfilled()(asyncThunks[0]);
|
1484 | }
|
1485 | return function (action) {
|
1486 | var matchers = asyncThunks.map(function (asyncThunk) { return asyncThunk.fulfilled; });
|
1487 | var combinedMatcher = isAnyOf.apply(void 0, matchers);
|
1488 | return combinedMatcher(action);
|
1489 | };
|
1490 | }
|
1491 | function isAsyncThunkAction() {
|
1492 | var asyncThunks = [];
|
1493 | for (var _i = 0; _i < arguments.length; _i++) {
|
1494 | asyncThunks[_i] = arguments[_i];
|
1495 | }
|
1496 | if (asyncThunks.length === 0) {
|
1497 | return function (action) { return hasExpectedRequestMetadata(action, ["pending", "fulfilled", "rejected"]); };
|
1498 | }
|
1499 | if (!isAsyncThunkArray(asyncThunks)) {
|
1500 | return isAsyncThunkAction()(asyncThunks[0]);
|
1501 | }
|
1502 | return function (action) {
|
1503 | var matchers = [];
|
1504 | for (var _i = 0, asyncThunks_1 = asyncThunks; _i < asyncThunks_1.length; _i++) {
|
1505 | var asyncThunk = asyncThunks_1[_i];
|
1506 | matchers.push(asyncThunk.pending, asyncThunk.rejected, asyncThunk.fulfilled);
|
1507 | }
|
1508 | var combinedMatcher = isAnyOf.apply(void 0, matchers);
|
1509 | return combinedMatcher(action);
|
1510 | };
|
1511 | }
|
1512 |
|
1513 | var assertFunction = function (func, expected) {
|
1514 | if (typeof func !== "function") {
|
1515 | throw new TypeError(expected + " is not a function");
|
1516 | }
|
1517 | };
|
1518 | var noop = function () {
|
1519 | };
|
1520 | var catchRejection = function (promise2, onError) {
|
1521 | if (onError === void 0) { onError = noop; }
|
1522 | promise2.catch(onError);
|
1523 | return promise2;
|
1524 | };
|
1525 | var addAbortSignalListener = function (abortSignal, callback) {
|
1526 | abortSignal.addEventListener("abort", callback, { once: true });
|
1527 | return function () { return abortSignal.removeEventListener("abort", callback); };
|
1528 | };
|
1529 | var abortControllerWithReason = function (abortController, reason) {
|
1530 | var signal = abortController.signal;
|
1531 | if (signal.aborted) {
|
1532 | return;
|
1533 | }
|
1534 | if (!("reason" in signal)) {
|
1535 | Object.defineProperty(signal, "reason", {
|
1536 | enumerable: true,
|
1537 | value: reason,
|
1538 | configurable: true,
|
1539 | writable: true
|
1540 | });
|
1541 | }
|
1542 | ;
|
1543 | abortController.abort(reason);
|
1544 | };
|
1545 |
|
1546 | var task = "task";
|
1547 | var listener = "listener";
|
1548 | var completed = "completed";
|
1549 | var cancelled = "cancelled";
|
1550 | var taskCancelled = "task-" + cancelled;
|
1551 | var taskCompleted = "task-" + completed;
|
1552 | var listenerCancelled = listener + "-" + cancelled;
|
1553 | var listenerCompleted = listener + "-" + completed;
|
1554 | var TaskAbortError = (function () {
|
1555 | function TaskAbortError(code) {
|
1556 | this.code = code;
|
1557 | this.name = "TaskAbortError";
|
1558 | this.message = task + " " + cancelled + " (reason: " + code + ")";
|
1559 | }
|
1560 | return TaskAbortError;
|
1561 | }());
|
1562 |
|
1563 | var validateActive = function (signal) {
|
1564 | if (signal.aborted) {
|
1565 | throw new TaskAbortError(signal.reason);
|
1566 | }
|
1567 | };
|
1568 | function raceWithSignal(signal, promise2) {
|
1569 | var cleanup = noop;
|
1570 | return new Promise(function (resolve, reject) {
|
1571 | var notifyRejection = function () { return reject(new TaskAbortError(signal.reason)); };
|
1572 | if (signal.aborted) {
|
1573 | notifyRejection();
|
1574 | return;
|
1575 | }
|
1576 | cleanup = addAbortSignalListener(signal, notifyRejection);
|
1577 | promise2.finally(function () { return cleanup(); }).then(resolve, reject);
|
1578 | }).finally(function () {
|
1579 | cleanup = noop;
|
1580 | });
|
1581 | }
|
1582 | var runTask = function (task2, cleanUp) { return __async(void 0, null, function () {
|
1583 | var value, error_1;
|
1584 | return __generator(this, function (_c) {
|
1585 | switch (_c.label) {
|
1586 | case 0:
|
1587 | _c.trys.push([0, 3, 4, 5]);
|
1588 | return [4 , Promise.resolve()];
|
1589 | case 1:
|
1590 | _c.sent();
|
1591 | return [4 , task2()];
|
1592 | case 2:
|
1593 | value = _c.sent();
|
1594 | return [2 , {
|
1595 | status: "ok",
|
1596 | value: value
|
1597 | }];
|
1598 | case 3:
|
1599 | error_1 = _c.sent();
|
1600 | return [2 , {
|
1601 | status: error_1 instanceof TaskAbortError ? "cancelled" : "rejected",
|
1602 | error: error_1
|
1603 | }];
|
1604 | case 4:
|
1605 | cleanUp == null ? void 0 : cleanUp();
|
1606 | return [7 ];
|
1607 | case 5: return [2 ];
|
1608 | }
|
1609 | });
|
1610 | }); };
|
1611 | var createPause = function (signal) {
|
1612 | return function (promise2) {
|
1613 | return catchRejection(raceWithSignal(signal, promise2).then(function (output) {
|
1614 | validateActive(signal);
|
1615 | return output;
|
1616 | }));
|
1617 | };
|
1618 | };
|
1619 | var createDelay = function (signal) {
|
1620 | var pause = createPause(signal);
|
1621 | return function (timeoutMs) {
|
1622 | return pause(new Promise(function (resolve) { return setTimeout(resolve, timeoutMs); }));
|
1623 | };
|
1624 | };
|
1625 |
|
1626 | var assign = Object.assign;
|
1627 | var INTERNAL_NIL_TOKEN = {};
|
1628 | var alm = "listenerMiddleware";
|
1629 | var createFork = function (parentAbortSignal) {
|
1630 | var linkControllers = function (controller) { return addAbortSignalListener(parentAbortSignal, function () { return abortControllerWithReason(controller, parentAbortSignal.reason); }); };
|
1631 | return function (taskExecutor) {
|
1632 | assertFunction(taskExecutor, "taskExecutor");
|
1633 | var childAbortController = new AbortController();
|
1634 | linkControllers(childAbortController);
|
1635 | var result = runTask(function () { return __async(void 0, null, function () {
|
1636 | var result2;
|
1637 | return __generator(this, function (_c) {
|
1638 | switch (_c.label) {
|
1639 | case 0:
|
1640 | validateActive(parentAbortSignal);
|
1641 | validateActive(childAbortController.signal);
|
1642 | return [4 , taskExecutor({
|
1643 | pause: createPause(childAbortController.signal),
|
1644 | delay: createDelay(childAbortController.signal),
|
1645 | signal: childAbortController.signal
|
1646 | })];
|
1647 | case 1:
|
1648 | result2 = _c.sent();
|
1649 | validateActive(childAbortController.signal);
|
1650 | return [2 , result2];
|
1651 | }
|
1652 | });
|
1653 | }); }, function () { return abortControllerWithReason(childAbortController, taskCompleted); });
|
1654 | return {
|
1655 | result: createPause(parentAbortSignal)(result),
|
1656 | cancel: function () {
|
1657 | abortControllerWithReason(childAbortController, taskCancelled);
|
1658 | }
|
1659 | };
|
1660 | };
|
1661 | };
|
1662 | var createTakePattern = function (startListening, signal) {
|
1663 | var take = function (predicate, timeout) { return __async(void 0, null, function () {
|
1664 | var unsubscribe, tuplePromise, promises, output;
|
1665 | return __generator(this, function (_c) {
|
1666 | switch (_c.label) {
|
1667 | case 0:
|
1668 | validateActive(signal);
|
1669 | unsubscribe = function () {
|
1670 | };
|
1671 | tuplePromise = new Promise(function (resolve, reject) {
|
1672 | var stopListening = startListening({
|
1673 | predicate: predicate,
|
1674 | effect: function (action, listenerApi) {
|
1675 | listenerApi.unsubscribe();
|
1676 | resolve([
|
1677 | action,
|
1678 | listenerApi.getState(),
|
1679 | listenerApi.getOriginalState()
|
1680 | ]);
|
1681 | }
|
1682 | });
|
1683 | unsubscribe = function () {
|
1684 | stopListening();
|
1685 | reject();
|
1686 | };
|
1687 | });
|
1688 | promises = [
|
1689 | tuplePromise
|
1690 | ];
|
1691 | if (timeout != null) {
|
1692 | promises.push(new Promise(function (resolve) { return setTimeout(resolve, timeout, null); }));
|
1693 | }
|
1694 | _c.label = 1;
|
1695 | case 1:
|
1696 | _c.trys.push([1, , 3, 4]);
|
1697 | return [4 , raceWithSignal(signal, Promise.race(promises))];
|
1698 | case 2:
|
1699 | output = _c.sent();
|
1700 | validateActive(signal);
|
1701 | return [2 , output];
|
1702 | case 3:
|
1703 | unsubscribe();
|
1704 | return [7 ];
|
1705 | case 4: return [2 ];
|
1706 | }
|
1707 | });
|
1708 | }); };
|
1709 | return function (predicate, timeout) { return catchRejection(take(predicate, timeout)); };
|
1710 | };
|
1711 | var getListenerEntryPropsFrom = function (options) {
|
1712 | var type = options.type, actionCreator = options.actionCreator, matcher = options.matcher, predicate = options.predicate, effect = options.effect;
|
1713 | if (type) {
|
1714 | predicate = createAction(type).match;
|
1715 | }
|
1716 | else if (actionCreator) {
|
1717 | type = actionCreator.type;
|
1718 | predicate = actionCreator.match;
|
1719 | }
|
1720 | else if (matcher) {
|
1721 | predicate = matcher;
|
1722 | }
|
1723 | else if (predicate) {
|
1724 | }
|
1725 | else {
|
1726 | throw new Error("Creating or removing a listener requires one of the known fields for matching an action");
|
1727 | }
|
1728 | assertFunction(effect, "options.listener");
|
1729 | return { predicate: predicate, type: type, effect: effect };
|
1730 | };
|
1731 | var createListenerEntry = function (options) {
|
1732 | var _c = getListenerEntryPropsFrom(options), type = _c.type, predicate = _c.predicate, effect = _c.effect;
|
1733 | var id = nanoid();
|
1734 | var entry = {
|
1735 | id: id,
|
1736 | effect: effect,
|
1737 | type: type,
|
1738 | predicate: predicate,
|
1739 | pending: new Set(),
|
1740 | unsubscribe: function () {
|
1741 | throw new Error("Unsubscribe not initialized");
|
1742 | }
|
1743 | };
|
1744 | return entry;
|
1745 | };
|
1746 | var cancelActiveListeners = function (entry) {
|
1747 | entry.pending.forEach(function (controller) {
|
1748 | abortControllerWithReason(controller, listenerCancelled);
|
1749 | });
|
1750 | };
|
1751 | var createClearListenerMiddleware = function (listenerMap) {
|
1752 | return function () {
|
1753 | listenerMap.forEach(cancelActiveListeners);
|
1754 | listenerMap.clear();
|
1755 | };
|
1756 | };
|
1757 | var safelyNotifyError = function (errorHandler, errorToNotify, errorInfo) {
|
1758 | try {
|
1759 | errorHandler(errorToNotify, errorInfo);
|
1760 | }
|
1761 | catch (errorHandlerError) {
|
1762 | setTimeout(function () {
|
1763 | throw errorHandlerError;
|
1764 | }, 0);
|
1765 | }
|
1766 | };
|
1767 | var addListener = createAction(alm + "/add");
|
1768 | var clearAllListeners = createAction(alm + "/removeAll");
|
1769 | var removeListener = createAction(alm + "/remove");
|
1770 | var defaultErrorHandler = function () {
|
1771 | var args = [];
|
1772 | for (var _i = 0; _i < arguments.length; _i++) {
|
1773 | args[_i] = arguments[_i];
|
1774 | }
|
1775 | console.error.apply(console, __spreadArray([alm + "/error"], args));
|
1776 | };
|
1777 | function createListenerMiddleware(middlewareOptions) {
|
1778 | var _this = this;
|
1779 | if (middlewareOptions === void 0) { middlewareOptions = {}; }
|
1780 | var listenerMap = new Map();
|
1781 | var extra = middlewareOptions.extra, _c = middlewareOptions.onError, onError = _c === void 0 ? defaultErrorHandler : _c;
|
1782 | assertFunction(onError, "onError");
|
1783 | var insertEntry = function (entry) {
|
1784 | entry.unsubscribe = function () { return listenerMap.delete(entry.id); };
|
1785 | listenerMap.set(entry.id, entry);
|
1786 | return function (cancelOptions) {
|
1787 | entry.unsubscribe();
|
1788 | if (cancelOptions == null ? void 0 : cancelOptions.cancelActive) {
|
1789 | cancelActiveListeners(entry);
|
1790 | }
|
1791 | };
|
1792 | };
|
1793 | var findListenerEntry = function (comparator) {
|
1794 | for (var _i = 0, _c = Array.from(listenerMap.values()); _i < _c.length; _i++) {
|
1795 | var entry = _c[_i];
|
1796 | if (comparator(entry)) {
|
1797 | return entry;
|
1798 | }
|
1799 | }
|
1800 | return void 0;
|
1801 | };
|
1802 | var startListening = function (options) {
|
1803 | var entry = findListenerEntry(function (existingEntry) { return existingEntry.effect === options.effect; });
|
1804 | if (!entry) {
|
1805 | entry = createListenerEntry(options);
|
1806 | }
|
1807 | return insertEntry(entry);
|
1808 | };
|
1809 | var stopListening = function (options) {
|
1810 | var _c = getListenerEntryPropsFrom(options), type = _c.type, effect = _c.effect, predicate = _c.predicate;
|
1811 | var entry = findListenerEntry(function (entry2) {
|
1812 | var matchPredicateOrType = typeof type === "string" ? entry2.type === type : entry2.predicate === predicate;
|
1813 | return matchPredicateOrType && entry2.effect === effect;
|
1814 | });
|
1815 | if (entry) {
|
1816 | entry.unsubscribe();
|
1817 | if (options.cancelActive) {
|
1818 | cancelActiveListeners(entry);
|
1819 | }
|
1820 | }
|
1821 | return !!entry;
|
1822 | };
|
1823 | var notifyListener = function (entry, action, api, getOriginalState) { return __async(_this, null, function () {
|
1824 | var internalTaskController, take, listenerError_1;
|
1825 | return __generator(this, function (_c) {
|
1826 | switch (_c.label) {
|
1827 | case 0:
|
1828 | internalTaskController = new AbortController();
|
1829 | take = createTakePattern(startListening, internalTaskController.signal);
|
1830 | _c.label = 1;
|
1831 | case 1:
|
1832 | _c.trys.push([1, 3, 4, 5]);
|
1833 | entry.pending.add(internalTaskController);
|
1834 | return [4 , Promise.resolve(entry.effect(action, assign({}, api, {
|
1835 | getOriginalState: getOriginalState,
|
1836 | condition: function (predicate, timeout) { return take(predicate, timeout).then(Boolean); },
|
1837 | take: take,
|
1838 | delay: createDelay(internalTaskController.signal),
|
1839 | pause: createPause(internalTaskController.signal),
|
1840 | extra: extra,
|
1841 | signal: internalTaskController.signal,
|
1842 | fork: createFork(internalTaskController.signal),
|
1843 | unsubscribe: entry.unsubscribe,
|
1844 | subscribe: function () {
|
1845 | listenerMap.set(entry.id, entry);
|
1846 | },
|
1847 | cancelActiveListeners: function () {
|
1848 | entry.pending.forEach(function (controller, _, set) {
|
1849 | if (controller !== internalTaskController) {
|
1850 | abortControllerWithReason(controller, listenerCancelled);
|
1851 | set.delete(controller);
|
1852 | }
|
1853 | });
|
1854 | }
|
1855 | })))];
|
1856 | case 2:
|
1857 | _c.sent();
|
1858 | return [3 /*break*/, 5];
|
1859 | case 3:
|
1860 | listenerError_1 = _c.sent();
|
1861 | if (!(listenerError_1 instanceof TaskAbortError)) {
|
1862 | safelyNotifyError(onError, listenerError_1, {
|
1863 | raisedBy: "effect"
|
1864 | });
|
1865 | }
|
1866 | return [3 , 5];
|
1867 | case 4:
|
1868 | abortControllerWithReason(internalTaskController, listenerCompleted);
|
1869 | entry.pending.delete(internalTaskController);
|
1870 | return [7 ];
|
1871 | case 5: return [2 ];
|
1872 | }
|
1873 | });
|
1874 | }); };
|
1875 | var clearListenerMiddleware = createClearListenerMiddleware(listenerMap);
|
1876 | var middleware = function (api) { return function (next) { return function (action) {
|
1877 | if (addListener.match(action)) {
|
1878 | return startListening(action.payload);
|
1879 | }
|
1880 | if (clearAllListeners.match(action)) {
|
1881 | clearListenerMiddleware();
|
1882 | return;
|
1883 | }
|
1884 | if (removeListener.match(action)) {
|
1885 | return stopListening(action.payload);
|
1886 | }
|
1887 | var originalState = api.getState();
|
1888 | var getOriginalState = function () {
|
1889 | if (originalState === INTERNAL_NIL_TOKEN) {
|
1890 | throw new Error(alm + ": getOriginalState can only be called synchronously");
|
1891 | }
|
1892 | return originalState;
|
1893 | };
|
1894 | var result;
|
1895 | try {
|
1896 | result = next(action);
|
1897 | if (listenerMap.size > 0) {
|
1898 | var currentState = api.getState();
|
1899 | var listenerEntries = Array.from(listenerMap.values());
|
1900 | for (var _i = 0, listenerEntries_1 = listenerEntries; _i < listenerEntries_1.length; _i++) {
|
1901 | var entry = listenerEntries_1[_i];
|
1902 | var runListener = false;
|
1903 | try {
|
1904 | runListener = entry.predicate(action, currentState, originalState);
|
1905 | }
|
1906 | catch (predicateError) {
|
1907 | runListener = false;
|
1908 | safelyNotifyError(onError, predicateError, {
|
1909 | raisedBy: "predicate"
|
1910 | });
|
1911 | }
|
1912 | if (!runListener) {
|
1913 | continue;
|
1914 | }
|
1915 | notifyListener(entry, action, api, getOriginalState);
|
1916 | }
|
1917 | }
|
1918 | }
|
1919 | finally {
|
1920 | originalState = INTERNAL_NIL_TOKEN;
|
1921 | }
|
1922 | return result;
|
1923 | }; }; };
|
1924 | return {
|
1925 | middleware: middleware,
|
1926 | startListening: startListening,
|
1927 | stopListening: stopListening,
|
1928 | clearListeners: clearListenerMiddleware
|
1929 | };
|
1930 | }
|
1931 |
|
1932 | var SHOULD_AUTOBATCH = "RTK_autoBatch";
|
1933 | var prepareAutoBatched = function () { return function (payload) {
|
1934 | var _c;
|
1935 | return ({
|
1936 | payload: payload,
|
1937 | meta: (_c = {}, _c[SHOULD_AUTOBATCH] = true, _c)
|
1938 | });
|
1939 | }; };
|
1940 | var promise;
|
1941 | var queueMicrotaskShim = typeof queueMicrotask === "function" ? queueMicrotask.bind(typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : globalThis) : function (cb) { return (promise || (promise = Promise.resolve())).then(cb).catch(function (err) { return setTimeout(function () {
|
1942 | throw err;
|
1943 | }, 0); }); };
|
1944 | var createQueueWithTimer = function (timeout) {
|
1945 | return function (notify) {
|
1946 | setTimeout(notify, timeout);
|
1947 | };
|
1948 | };
|
1949 | var rAF = typeof window !== "undefined" && window.requestAnimationFrame ? window.requestAnimationFrame : createQueueWithTimer(10);
|
1950 | var autoBatchEnhancer = function (options) {
|
1951 | if (options === void 0) { options = { type: "raf" }; }
|
1952 | return function (next) { return function () {
|
1953 | var args = [];
|
1954 | for (var _i = 0; _i < arguments.length; _i++) {
|
1955 | args[_i] = arguments[_i];
|
1956 | }
|
1957 | var store = next.apply(void 0, args);
|
1958 | var notifying = true;
|
1959 | var shouldNotifyAtEndOfTick = false;
|
1960 | var notificationQueued = false;
|
1961 | var listeners = new Set();
|
1962 | var queueCallback = options.type === "tick" ? queueMicrotaskShim : options.type === "raf" ? rAF : options.type === "callback" ? options.queueNotification : createQueueWithTimer(options.timeout);
|
1963 | var notifyListeners = function () {
|
1964 | notificationQueued = false;
|
1965 | if (shouldNotifyAtEndOfTick) {
|
1966 | shouldNotifyAtEndOfTick = false;
|
1967 | listeners.forEach(function (l) { return l(); });
|
1968 | }
|
1969 | };
|
1970 | return Object.assign({}, store, {
|
1971 | subscribe: function (listener2) {
|
1972 | var wrappedListener = function () { return notifying && listener2(); };
|
1973 | var unsubscribe = store.subscribe(wrappedListener);
|
1974 | listeners.add(listener2);
|
1975 | return function () {
|
1976 | unsubscribe();
|
1977 | listeners.delete(listener2);
|
1978 | };
|
1979 | },
|
1980 | dispatch: function (action) {
|
1981 | var _a;
|
1982 | try {
|
1983 | notifying = !((_a = action == null ? void 0 : action.meta) == null ? void 0 : _a[SHOULD_AUTOBATCH]);
|
1984 | shouldNotifyAtEndOfTick = !notifying;
|
1985 | if (shouldNotifyAtEndOfTick) {
|
1986 | if (!notificationQueued) {
|
1987 | notificationQueued = true;
|
1988 | queueCallback(notifyListeners);
|
1989 | }
|
1990 | }
|
1991 | return store.dispatch(action);
|
1992 | }
|
1993 | finally {
|
1994 | notifying = true;
|
1995 | }
|
1996 | }
|
1997 | });
|
1998 | }; };
|
1999 | };
|
2000 |
|
2001 | (0, import_immer5.enableES5)();
|
2002 |
|
\ | No newline at end of file |