@availity/mui-file-selector 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,11 +1,7 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __defProps = Object.defineProperties;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
3
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __getProtoOf = Object.getPrototypeOf;
9
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -21,12 +17,6 @@ var __spreadValues = (a, b) => {
21
17
  return a;
22
18
  };
23
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
25
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
26
- }) : x)(function(x) {
27
- if (typeof require !== "undefined") return require.apply(this, arguments);
28
- throw Error('Dynamic require of "' + x + '" is not supported');
29
- });
30
20
  var __objRest = (source, exclude) => {
31
21
  var target = {};
32
22
  for (var prop in source)
@@ -39,25 +29,6 @@ var __objRest = (source, exclude) => {
39
29
  }
40
30
  return target;
41
31
  };
42
- var __commonJS = (cb, mod) => function __require2() {
43
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
44
- };
45
- var __copyProps = (to, from, except, desc) => {
46
- if (from && typeof from === "object" || typeof from === "function") {
47
- for (let key of __getOwnPropNames(from))
48
- if (!__hasOwnProp.call(to, key) && key !== except)
49
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
50
- }
51
- return to;
52
- };
53
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
54
- // If the importer is in node compatibility mode or this is not an ESM
55
- // file that has been converted to a CommonJS file using a Babel-
56
- // compatible transform (i.e. "__esModule" has not been set), then set
57
- // "default" to the CommonJS "module.exports" for node compatibility.
58
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
59
- mod
60
- ));
61
32
  var __async = (__this, __arguments, generator) => {
62
33
  return new Promise((resolve, reject) => {
63
34
  var fulfilled = (value) => {
@@ -79,135 +50,6 @@ var __async = (__this, __arguments, generator) => {
79
50
  });
80
51
  };
81
52
 
82
- // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js
83
- var require_use_sync_external_store_shim_production = __commonJS({
84
- "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js"(exports) {
85
- "use strict";
86
- var React6 = __require("react");
87
- function is(x, y) {
88
- return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
89
- }
90
- var objectIs = "function" === typeof Object.is ? Object.is : is;
91
- var useState7 = React6.useState;
92
- var useEffect4 = React6.useEffect;
93
- var useLayoutEffect = React6.useLayoutEffect;
94
- var useDebugValue = React6.useDebugValue;
95
- function useSyncExternalStore$2(subscribe, getSnapshot) {
96
- var value = getSnapshot(), _useState = useState7({ inst: { value, getSnapshot } }), inst = _useState[0].inst, forceUpdate = _useState[1];
97
- useLayoutEffect(
98
- function() {
99
- inst.value = value;
100
- inst.getSnapshot = getSnapshot;
101
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
102
- },
103
- [subscribe, value, getSnapshot]
104
- );
105
- useEffect4(
106
- function() {
107
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
108
- return subscribe(function() {
109
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
110
- });
111
- },
112
- [subscribe]
113
- );
114
- useDebugValue(value);
115
- return value;
116
- }
117
- function checkIfSnapshotChanged(inst) {
118
- var latestGetSnapshot = inst.getSnapshot;
119
- inst = inst.value;
120
- try {
121
- var nextValue = latestGetSnapshot();
122
- return !objectIs(inst, nextValue);
123
- } catch (error) {
124
- return true;
125
- }
126
- }
127
- function useSyncExternalStore$12(subscribe, getSnapshot) {
128
- return getSnapshot();
129
- }
130
- var shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$12 : useSyncExternalStore$2;
131
- exports.useSyncExternalStore = void 0 !== React6.useSyncExternalStore ? React6.useSyncExternalStore : shim;
132
- }
133
- });
134
-
135
- // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js
136
- var require_use_sync_external_store_shim_development = __commonJS({
137
- "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js"(exports) {
138
- "use strict";
139
- "production" !== process.env.NODE_ENV && function() {
140
- function is(x, y) {
141
- return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
142
- }
143
- function useSyncExternalStore$2(subscribe, getSnapshot) {
144
- didWarnOld18Alpha || void 0 === React6.startTransition || (didWarnOld18Alpha = true, console.error(
145
- "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
146
- ));
147
- var value = getSnapshot();
148
- if (!didWarnUncachedGetSnapshot) {
149
- var cachedValue = getSnapshot();
150
- objectIs(value, cachedValue) || (console.error(
151
- "The result of getSnapshot should be cached to avoid an infinite loop"
152
- ), didWarnUncachedGetSnapshot = true);
153
- }
154
- cachedValue = useState7({
155
- inst: { value, getSnapshot }
156
- });
157
- var inst = cachedValue[0].inst, forceUpdate = cachedValue[1];
158
- useLayoutEffect(
159
- function() {
160
- inst.value = value;
161
- inst.getSnapshot = getSnapshot;
162
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
163
- },
164
- [subscribe, value, getSnapshot]
165
- );
166
- useEffect4(
167
- function() {
168
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
169
- return subscribe(function() {
170
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
171
- });
172
- },
173
- [subscribe]
174
- );
175
- useDebugValue(value);
176
- return value;
177
- }
178
- function checkIfSnapshotChanged(inst) {
179
- var latestGetSnapshot = inst.getSnapshot;
180
- inst = inst.value;
181
- try {
182
- var nextValue = latestGetSnapshot();
183
- return !objectIs(inst, nextValue);
184
- } catch (error) {
185
- return true;
186
- }
187
- }
188
- function useSyncExternalStore$12(subscribe, getSnapshot) {
189
- return getSnapshot();
190
- }
191
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
192
- var React6 = __require("react"), objectIs = "function" === typeof Object.is ? Object.is : is, useState7 = React6.useState, useEffect4 = React6.useEffect, useLayoutEffect = React6.useLayoutEffect, useDebugValue = React6.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$12 : useSyncExternalStore$2;
193
- exports.useSyncExternalStore = void 0 !== React6.useSyncExternalStore ? React6.useSyncExternalStore : shim;
194
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
195
- }();
196
- }
197
- });
198
-
199
- // ../../node_modules/use-sync-external-store/shim/index.js
200
- var require_shim = __commonJS({
201
- "../../node_modules/use-sync-external-store/shim/index.js"(exports, module) {
202
- "use strict";
203
- if (process.env.NODE_ENV === "production") {
204
- module.exports = require_use_sync_external_store_shim_production();
205
- } else {
206
- module.exports = require_use_sync_external_store_shim_development();
207
- }
208
- }
209
- });
210
-
211
53
  // src/lib/Dropzone.tsx
212
54
  import { useCallback } from "react";
213
55
  import { styled } from "@mui/material/styles";
@@ -272,6 +114,66 @@ var FilePickerBtn = (_a) => {
272
114
  ] });
273
115
  };
274
116
 
117
+ // src/lib/util.ts
118
+ import {
119
+ FileArchiveIcon,
120
+ FileCodeIcon,
121
+ FileCsvIcon,
122
+ FileExcelIcon,
123
+ FileIcon,
124
+ FileImageIcon,
125
+ FileLinesIcon,
126
+ FilePdfIcon,
127
+ FilePowerpointIcon,
128
+ FileWordIcon
129
+ } from "@availity/mui-icon";
130
+ function formatBytes(bytes, decimals = 2) {
131
+ if (!+bytes) return "0 Bytes";
132
+ const k = 1024;
133
+ const dm = decimals < 0 ? 0 : decimals;
134
+ const sizes = ["Bytes", "KB", "MB", "GB"];
135
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
136
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
137
+ }
138
+ var FILE_EXT_ICONS = {
139
+ png: FileImageIcon,
140
+ jpg: FileImageIcon,
141
+ jpeg: FileImageIcon,
142
+ gif: FileImageIcon,
143
+ csv: FileCsvIcon,
144
+ ppt: FilePowerpointIcon,
145
+ pptx: FilePowerpointIcon,
146
+ xls: FileExcelIcon,
147
+ xlsx: FileExcelIcon,
148
+ doc: FileWordIcon,
149
+ docx: FileWordIcon,
150
+ txt: FileLinesIcon,
151
+ text: FileLinesIcon,
152
+ zip: FileArchiveIcon,
153
+ "7zip": FileArchiveIcon,
154
+ xml: FileCodeIcon,
155
+ html: FileCodeIcon,
156
+ pdf: FilePdfIcon
157
+ };
158
+ var isValidKey = (key) => key ? key in FILE_EXT_ICONS : false;
159
+ var getFileExtension = (fileName) => {
160
+ var _a;
161
+ return ((_a = fileName.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
162
+ };
163
+ var getFileExtIcon = (fileName) => {
164
+ const ext = getFileExtension(fileName);
165
+ return isValidKey(ext) ? FILE_EXT_ICONS[ext] : FileIcon;
166
+ };
167
+ var dedupeErrors = (errors) => {
168
+ const dedupedErrors = errors.reduce((acc, error) => {
169
+ if (!acc.find((err) => err.code === error.code)) {
170
+ acc.push(error);
171
+ }
172
+ return acc;
173
+ }, []);
174
+ return dedupedErrors;
175
+ };
176
+
275
177
  // src/lib/Dropzone.tsx
276
178
  import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
277
179
  var outerBoxStyles = {
@@ -311,6 +213,7 @@ var Dropzone = ({
311
213
  enableDropArea = true,
312
214
  maxFiles,
313
215
  maxSize,
216
+ maxTotalSize,
314
217
  multiple,
315
218
  name,
316
219
  onChange,
@@ -363,7 +266,48 @@ var Dropzone = ({
363
266
  }
364
267
  setTotalSize((prev) => prev + newSize);
365
268
  const previous = (_a2 = watch(name)) != null ? _a2 : [];
366
- setValue(name, previous.concat(acceptedFiles));
269
+ if (maxTotalSize) {
270
+ const currentTotalSize = previous.reduce((sum, file) => sum + file.size, 0);
271
+ let newSize2 = 0;
272
+ const availableSize = Math.max(0, maxTotalSize - currentTotalSize);
273
+ let sizeCounter = 0;
274
+ const cutoffIndex = acceptedFiles.findIndex((file) => {
275
+ sizeCounter += file.size;
276
+ return sizeCounter > availableSize;
277
+ });
278
+ if (cutoffIndex !== -1) {
279
+ const filesToAdd2 = acceptedFiles.slice(0, cutoffIndex === 0 ? 0 : cutoffIndex);
280
+ fileRejections.push({
281
+ file: acceptedFiles[cutoffIndex],
282
+ errors: [
283
+ {
284
+ code: "upload-too-large",
285
+ message: `Total upload size exceeds the limit of ${formatBytes(maxTotalSize)}.`
286
+ }
287
+ ],
288
+ id: counter.increment()
289
+ });
290
+ acceptedFiles = filesToAdd2;
291
+ }
292
+ newSize2 = acceptedFiles.reduce((sum, file) => sum + file.size, 0);
293
+ setTotalSize((prev) => prev + newSize2);
294
+ }
295
+ const remainingSlots = maxFiles ? Math.max(0, maxFiles - previous.length) : acceptedFiles.length;
296
+ const filesToAdd = acceptedFiles.slice(0, remainingSlots);
297
+ setValue(name, previous.concat(filesToAdd));
298
+ if (maxFiles && acceptedFiles.length > remainingSlots) {
299
+ fileRejections.push({
300
+ file: acceptedFiles[remainingSlots],
301
+ // Use the first excess file
302
+ errors: [
303
+ {
304
+ code: "too-many-files",
305
+ message: `Too many files. You may only upload ${maxFiles} file(s).`
306
+ }
307
+ ],
308
+ id: counter.increment()
309
+ });
310
+ }
367
311
  if (fileRejections.length > 0) {
368
312
  const TOO_MANY_FILES_CODE = "too-many-files";
369
313
  let hasTooManyFiles = false;
@@ -464,68 +408,6 @@ import { CloudUploadIcon as CloudUploadIcon2, PlusIcon as PlusIcon2 } from "@ava
464
408
  import { Box as Box2, Stack as Stack2 } from "@availity/mui-layout";
465
409
  import { Typography as Typography2 } from "@availity/mui-typography";
466
410
  import Upload from "@availity/upload-core";
467
-
468
- // src/lib/util.ts
469
- import {
470
- FileArchiveIcon,
471
- FileCodeIcon,
472
- FileCsvIcon,
473
- FileExcelIcon,
474
- FileIcon,
475
- FileImageIcon,
476
- FileLinesIcon,
477
- FilePdfIcon,
478
- FilePowerpointIcon,
479
- FileWordIcon
480
- } from "@availity/mui-icon";
481
- function formatBytes(bytes, decimals = 2) {
482
- if (!+bytes) return "0 Bytes";
483
- const k = 1024;
484
- const dm = decimals < 0 ? 0 : decimals;
485
- const sizes = ["Bytes", "KB", "MB", "GB"];
486
- const i = Math.floor(Math.log(bytes) / Math.log(k));
487
- return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
488
- }
489
- var FILE_EXT_ICONS = {
490
- png: FileImageIcon,
491
- jpg: FileImageIcon,
492
- jpeg: FileImageIcon,
493
- gif: FileImageIcon,
494
- csv: FileCsvIcon,
495
- ppt: FilePowerpointIcon,
496
- pptx: FilePowerpointIcon,
497
- xls: FileExcelIcon,
498
- xlsx: FileExcelIcon,
499
- doc: FileWordIcon,
500
- docx: FileWordIcon,
501
- txt: FileLinesIcon,
502
- text: FileLinesIcon,
503
- zip: FileArchiveIcon,
504
- "7zip": FileArchiveIcon,
505
- xml: FileCodeIcon,
506
- html: FileCodeIcon,
507
- pdf: FilePdfIcon
508
- };
509
- var isValidKey = (key) => key ? key in FILE_EXT_ICONS : false;
510
- var getFileExtension = (fileName) => {
511
- var _a;
512
- return ((_a = fileName.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
513
- };
514
- var getFileExtIcon = (fileName) => {
515
- const ext = getFileExtension(fileName);
516
- return isValidKey(ext) ? FILE_EXT_ICONS[ext] : FileIcon;
517
- };
518
- var dedupeErrors = (errors) => {
519
- const dedupedErrors = errors.reduce((acc, error) => {
520
- if (!acc.find((err) => err.code === error.code)) {
521
- acc.push(error);
522
- }
523
- return acc;
524
- }, []);
525
- return dedupedErrors;
526
- };
527
-
528
- // src/lib/Dropzone2.tsx
529
411
  import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
530
412
  var counter2 = createCounter();
531
413
  function startUpload(file, options) {
@@ -547,6 +429,7 @@ var Dropzone2 = ({
547
429
  enableDropArea = true,
548
430
  maxFiles,
549
431
  maxSize,
432
+ maxTotalSize,
550
433
  multiple,
551
434
  name,
552
435
  onChange,
@@ -601,8 +484,50 @@ var Dropzone2 = ({
601
484
  }
602
485
  setTotalSize((prev) => prev + newSize);
603
486
  const previous = (_a2 = watch(name)) != null ? _a2 : [];
604
- const uploads = acceptedFiles.map((file) => startUpload(file, uploadOptions));
487
+ if (maxTotalSize) {
488
+ const currentTotalSize = previous.reduce((sum, upload) => sum + upload.file.size, 0);
489
+ console.log({ previous });
490
+ let newSize2 = 0;
491
+ const availableSize = Math.max(0, maxTotalSize - currentTotalSize);
492
+ let sizeCounter = 0;
493
+ const cutoffIndex = acceptedFiles.findIndex((file) => {
494
+ sizeCounter += file.size;
495
+ return sizeCounter > availableSize;
496
+ });
497
+ if (cutoffIndex !== -1) {
498
+ const filesToAdd2 = acceptedFiles.slice(0, cutoffIndex === 0 ? 0 : cutoffIndex);
499
+ fileRejections.push({
500
+ file: acceptedFiles[cutoffIndex],
501
+ errors: [
502
+ {
503
+ code: "upload-too-large",
504
+ message: `Total upload size exceeds the limit of ${formatBytes(maxTotalSize)}.`
505
+ }
506
+ ],
507
+ id: counter2.increment()
508
+ });
509
+ acceptedFiles = filesToAdd2;
510
+ }
511
+ newSize2 = acceptedFiles.reduce((sum, file) => sum + file.size, 0);
512
+ setTotalSize((prev) => prev + newSize2);
513
+ }
514
+ const remainingSlots = maxFiles ? Math.max(0, maxFiles - previous.length) : acceptedFiles.length;
515
+ const filesToAdd = acceptedFiles.slice(0, remainingSlots);
516
+ const uploads = filesToAdd.map((file) => startUpload(file, uploadOptions));
605
517
  setValue(name, previous.concat(yield Promise.all(uploads)));
518
+ if (maxFiles && acceptedFiles.length > remainingSlots) {
519
+ fileRejections.push({
520
+ file: acceptedFiles[remainingSlots],
521
+ // Use the first excess file
522
+ errors: [
523
+ {
524
+ code: "too-many-files",
525
+ message: `Too many files. You may only upload ${maxFiles} file(s).`
526
+ }
527
+ ],
528
+ id: counter2.increment()
529
+ });
530
+ }
606
531
  if (fileRejections.length > 0) {
607
532
  const TOO_MANY_FILES_CODE = "too-many-files";
608
533
  let hasTooManyFiles = false;
@@ -699,6 +624,7 @@ import { List, ListItem } from "@availity/mui-list";
699
624
  import { Fragment as Fragment4, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
700
625
  var codes = {
701
626
  "file-too-large": "File exceeds maximum size",
627
+ "upload-too-large": "File causes maximum total upload size to be exceeded",
702
628
  "file-invalid-type": "File has an invalid type",
703
629
  "file-too-small": "File is smaller than minimum size",
704
630
  "too-many-file": "Too many files",
@@ -1036,952 +962,8 @@ var UploadProgressBar = ({ upload, onProgress, onError, onSuccess }) => {
1036
962
  ] }) : /* @__PURE__ */ jsx11(LinearProgress, { value: statePercentage, "aria-label": `${upload.file.name}-progress` });
1037
963
  };
1038
964
 
1039
- // ../../node_modules/@tanstack/query-core/build/lib/subscribable.mjs
1040
- var Subscribable = class {
1041
- constructor() {
1042
- this.listeners = /* @__PURE__ */ new Set();
1043
- this.subscribe = this.subscribe.bind(this);
1044
- }
1045
- subscribe(listener) {
1046
- const identity = {
1047
- listener
1048
- };
1049
- this.listeners.add(identity);
1050
- this.onSubscribe();
1051
- return () => {
1052
- this.listeners.delete(identity);
1053
- this.onUnsubscribe();
1054
- };
1055
- }
1056
- hasListeners() {
1057
- return this.listeners.size > 0;
1058
- }
1059
- onSubscribe() {
1060
- }
1061
- onUnsubscribe() {
1062
- }
1063
- };
1064
-
1065
- // ../../node_modules/@tanstack/query-core/build/lib/utils.mjs
1066
- var isServer = typeof window === "undefined" || "Deno" in window;
1067
- function noop() {
1068
- return void 0;
1069
- }
1070
- function isValidTimeout(value) {
1071
- return typeof value === "number" && value >= 0 && value !== Infinity;
1072
- }
1073
- function timeUntilStale(updatedAt, staleTime) {
1074
- return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
1075
- }
1076
- function parseQueryArgs(arg1, arg2, arg3) {
1077
- if (!isQueryKey(arg1)) {
1078
- return arg1;
1079
- }
1080
- if (typeof arg2 === "function") {
1081
- return __spreadProps(__spreadValues({}, arg3), {
1082
- queryKey: arg1,
1083
- queryFn: arg2
1084
- });
1085
- }
1086
- return __spreadProps(__spreadValues({}, arg2), {
1087
- queryKey: arg1
1088
- });
1089
- }
1090
- function replaceEqualDeep(a, b) {
1091
- if (a === b) {
1092
- return a;
1093
- }
1094
- const array = isPlainArray(a) && isPlainArray(b);
1095
- if (array || isPlainObject(a) && isPlainObject(b)) {
1096
- const aSize = array ? a.length : Object.keys(a).length;
1097
- const bItems = array ? b : Object.keys(b);
1098
- const bSize = bItems.length;
1099
- const copy = array ? [] : {};
1100
- let equalItems = 0;
1101
- for (let i = 0; i < bSize; i++) {
1102
- const key = array ? i : bItems[i];
1103
- copy[key] = replaceEqualDeep(a[key], b[key]);
1104
- if (copy[key] === a[key]) {
1105
- equalItems++;
1106
- }
1107
- }
1108
- return aSize === bSize && equalItems === aSize ? a : copy;
1109
- }
1110
- return b;
1111
- }
1112
- function shallowEqualObjects(a, b) {
1113
- if (a && !b || b && !a) {
1114
- return false;
1115
- }
1116
- for (const key in a) {
1117
- if (a[key] !== b[key]) {
1118
- return false;
1119
- }
1120
- }
1121
- return true;
1122
- }
1123
- function isPlainArray(value) {
1124
- return Array.isArray(value) && value.length === Object.keys(value).length;
1125
- }
1126
- function isPlainObject(o) {
1127
- if (!hasObjectPrototype(o)) {
1128
- return false;
1129
- }
1130
- const ctor = o.constructor;
1131
- if (typeof ctor === "undefined") {
1132
- return true;
1133
- }
1134
- const prot = ctor.prototype;
1135
- if (!hasObjectPrototype(prot)) {
1136
- return false;
1137
- }
1138
- if (!prot.hasOwnProperty("isPrototypeOf")) {
1139
- return false;
1140
- }
1141
- return true;
1142
- }
1143
- function hasObjectPrototype(o) {
1144
- return Object.prototype.toString.call(o) === "[object Object]";
1145
- }
1146
- function isQueryKey(value) {
1147
- return Array.isArray(value);
1148
- }
1149
- function sleep(timeout) {
1150
- return new Promise((resolve) => {
1151
- setTimeout(resolve, timeout);
1152
- });
1153
- }
1154
- function scheduleMicrotask(callback) {
1155
- sleep(0).then(callback);
1156
- }
1157
- function replaceData(prevData, data, options) {
1158
- if (options.isDataEqual != null && options.isDataEqual(prevData, data)) {
1159
- return prevData;
1160
- } else if (typeof options.structuralSharing === "function") {
1161
- return options.structuralSharing(prevData, data);
1162
- } else if (options.structuralSharing !== false) {
1163
- return replaceEqualDeep(prevData, data);
1164
- }
1165
- return data;
1166
- }
1167
-
1168
- // ../../node_modules/@tanstack/query-core/build/lib/focusManager.mjs
1169
- var FocusManager = class extends Subscribable {
1170
- constructor() {
1171
- super();
1172
- this.setup = (onFocus) => {
1173
- if (!isServer && window.addEventListener) {
1174
- const listener = () => onFocus();
1175
- window.addEventListener("visibilitychange", listener, false);
1176
- window.addEventListener("focus", listener, false);
1177
- return () => {
1178
- window.removeEventListener("visibilitychange", listener);
1179
- window.removeEventListener("focus", listener);
1180
- };
1181
- }
1182
- return;
1183
- };
1184
- }
1185
- onSubscribe() {
1186
- if (!this.cleanup) {
1187
- this.setEventListener(this.setup);
1188
- }
1189
- }
1190
- onUnsubscribe() {
1191
- if (!this.hasListeners()) {
1192
- var _this$cleanup;
1193
- (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
1194
- this.cleanup = void 0;
1195
- }
1196
- }
1197
- setEventListener(setup) {
1198
- var _this$cleanup2;
1199
- this.setup = setup;
1200
- (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
1201
- this.cleanup = setup((focused) => {
1202
- if (typeof focused === "boolean") {
1203
- this.setFocused(focused);
1204
- } else {
1205
- this.onFocus();
1206
- }
1207
- });
1208
- }
1209
- setFocused(focused) {
1210
- const changed = this.focused !== focused;
1211
- if (changed) {
1212
- this.focused = focused;
1213
- this.onFocus();
1214
- }
1215
- }
1216
- onFocus() {
1217
- this.listeners.forEach(({
1218
- listener
1219
- }) => {
1220
- listener();
1221
- });
1222
- }
1223
- isFocused() {
1224
- if (typeof this.focused === "boolean") {
1225
- return this.focused;
1226
- }
1227
- if (typeof document === "undefined") {
1228
- return true;
1229
- }
1230
- return [void 0, "visible", "prerender"].includes(document.visibilityState);
1231
- }
1232
- };
1233
- var focusManager = new FocusManager();
1234
-
1235
- // ../../node_modules/@tanstack/query-core/build/lib/onlineManager.mjs
1236
- var onlineEvents = ["online", "offline"];
1237
- var OnlineManager = class extends Subscribable {
1238
- constructor() {
1239
- super();
1240
- this.setup = (onOnline) => {
1241
- if (!isServer && window.addEventListener) {
1242
- const listener = () => onOnline();
1243
- onlineEvents.forEach((event) => {
1244
- window.addEventListener(event, listener, false);
1245
- });
1246
- return () => {
1247
- onlineEvents.forEach((event) => {
1248
- window.removeEventListener(event, listener);
1249
- });
1250
- };
1251
- }
1252
- return;
1253
- };
1254
- }
1255
- onSubscribe() {
1256
- if (!this.cleanup) {
1257
- this.setEventListener(this.setup);
1258
- }
1259
- }
1260
- onUnsubscribe() {
1261
- if (!this.hasListeners()) {
1262
- var _this$cleanup;
1263
- (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
1264
- this.cleanup = void 0;
1265
- }
1266
- }
1267
- setEventListener(setup) {
1268
- var _this$cleanup2;
1269
- this.setup = setup;
1270
- (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
1271
- this.cleanup = setup((online) => {
1272
- if (typeof online === "boolean") {
1273
- this.setOnline(online);
1274
- } else {
1275
- this.onOnline();
1276
- }
1277
- });
1278
- }
1279
- setOnline(online) {
1280
- const changed = this.online !== online;
1281
- if (changed) {
1282
- this.online = online;
1283
- this.onOnline();
1284
- }
1285
- }
1286
- onOnline() {
1287
- this.listeners.forEach(({
1288
- listener
1289
- }) => {
1290
- listener();
1291
- });
1292
- }
1293
- isOnline() {
1294
- if (typeof this.online === "boolean") {
1295
- return this.online;
1296
- }
1297
- if (typeof navigator === "undefined" || typeof navigator.onLine === "undefined") {
1298
- return true;
1299
- }
1300
- return navigator.onLine;
1301
- }
1302
- };
1303
- var onlineManager = new OnlineManager();
1304
-
1305
- // ../../node_modules/@tanstack/query-core/build/lib/retryer.mjs
1306
- function canFetch(networkMode) {
1307
- return (networkMode != null ? networkMode : "online") === "online" ? onlineManager.isOnline() : true;
1308
- }
1309
- var CancelledError = class {
1310
- constructor(options) {
1311
- this.revert = options == null ? void 0 : options.revert;
1312
- this.silent = options == null ? void 0 : options.silent;
1313
- }
1314
- };
1315
- function isCancelledError(value) {
1316
- return value instanceof CancelledError;
1317
- }
1318
-
1319
- // ../../node_modules/@tanstack/query-core/build/lib/notifyManager.mjs
1320
- function createNotifyManager() {
1321
- let queue = [];
1322
- let transactions = 0;
1323
- let notifyFn = (callback) => {
1324
- callback();
1325
- };
1326
- let batchNotifyFn = (callback) => {
1327
- callback();
1328
- };
1329
- const batch = (callback) => {
1330
- let result;
1331
- transactions++;
1332
- try {
1333
- result = callback();
1334
- } finally {
1335
- transactions--;
1336
- if (!transactions) {
1337
- flush();
1338
- }
1339
- }
1340
- return result;
1341
- };
1342
- const schedule = (callback) => {
1343
- if (transactions) {
1344
- queue.push(callback);
1345
- } else {
1346
- scheduleMicrotask(() => {
1347
- notifyFn(callback);
1348
- });
1349
- }
1350
- };
1351
- const batchCalls = (callback) => {
1352
- return (...args) => {
1353
- schedule(() => {
1354
- callback(...args);
1355
- });
1356
- };
1357
- };
1358
- const flush = () => {
1359
- const originalQueue = queue;
1360
- queue = [];
1361
- if (originalQueue.length) {
1362
- scheduleMicrotask(() => {
1363
- batchNotifyFn(() => {
1364
- originalQueue.forEach((callback) => {
1365
- notifyFn(callback);
1366
- });
1367
- });
1368
- });
1369
- }
1370
- };
1371
- const setNotifyFunction = (fn) => {
1372
- notifyFn = fn;
1373
- };
1374
- const setBatchNotifyFunction = (fn) => {
1375
- batchNotifyFn = fn;
1376
- };
1377
- return {
1378
- batch,
1379
- batchCalls,
1380
- schedule,
1381
- setNotifyFunction,
1382
- setBatchNotifyFunction
1383
- };
1384
- }
1385
- var notifyManager = createNotifyManager();
1386
-
1387
- // ../../node_modules/@tanstack/query-core/build/lib/queryObserver.mjs
1388
- var QueryObserver = class extends Subscribable {
1389
- constructor(client, options) {
1390
- super();
1391
- this.client = client;
1392
- this.options = options;
1393
- this.trackedProps = /* @__PURE__ */ new Set();
1394
- this.selectError = null;
1395
- this.bindMethods();
1396
- this.setOptions(options);
1397
- }
1398
- bindMethods() {
1399
- this.remove = this.remove.bind(this);
1400
- this.refetch = this.refetch.bind(this);
1401
- }
1402
- onSubscribe() {
1403
- if (this.listeners.size === 1) {
1404
- this.currentQuery.addObserver(this);
1405
- if (shouldFetchOnMount(this.currentQuery, this.options)) {
1406
- this.executeFetch();
1407
- }
1408
- this.updateTimers();
1409
- }
1410
- }
1411
- onUnsubscribe() {
1412
- if (!this.hasListeners()) {
1413
- this.destroy();
1414
- }
1415
- }
1416
- shouldFetchOnReconnect() {
1417
- return shouldFetchOn(this.currentQuery, this.options, this.options.refetchOnReconnect);
1418
- }
1419
- shouldFetchOnWindowFocus() {
1420
- return shouldFetchOn(this.currentQuery, this.options, this.options.refetchOnWindowFocus);
1421
- }
1422
- destroy() {
1423
- this.listeners = /* @__PURE__ */ new Set();
1424
- this.clearStaleTimeout();
1425
- this.clearRefetchInterval();
1426
- this.currentQuery.removeObserver(this);
1427
- }
1428
- setOptions(options, notifyOptions) {
1429
- const prevOptions = this.options;
1430
- const prevQuery = this.currentQuery;
1431
- this.options = this.client.defaultQueryOptions(options);
1432
- if (process.env.NODE_ENV !== "production" && typeof (options == null ? void 0 : options.isDataEqual) !== "undefined") {
1433
- this.client.getLogger().error("The isDataEqual option has been deprecated and will be removed in the next major version. You can achieve the same functionality by passing a function as the structuralSharing option");
1434
- }
1435
- if (!shallowEqualObjects(prevOptions, this.options)) {
1436
- this.client.getQueryCache().notify({
1437
- type: "observerOptionsUpdated",
1438
- query: this.currentQuery,
1439
- observer: this
1440
- });
1441
- }
1442
- if (typeof this.options.enabled !== "undefined" && typeof this.options.enabled !== "boolean") {
1443
- throw new Error("Expected enabled to be a boolean");
1444
- }
1445
- if (!this.options.queryKey) {
1446
- this.options.queryKey = prevOptions.queryKey;
1447
- }
1448
- this.updateQuery();
1449
- const mounted = this.hasListeners();
1450
- if (mounted && shouldFetchOptionally(this.currentQuery, prevQuery, this.options, prevOptions)) {
1451
- this.executeFetch();
1452
- }
1453
- this.updateResult(notifyOptions);
1454
- if (mounted && (this.currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
1455
- this.updateStaleTimeout();
1456
- }
1457
- const nextRefetchInterval = this.computeRefetchInterval();
1458
- if (mounted && (this.currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== this.currentRefetchInterval)) {
1459
- this.updateRefetchInterval(nextRefetchInterval);
1460
- }
1461
- }
1462
- getOptimisticResult(options) {
1463
- const query = this.client.getQueryCache().build(this.client, options);
1464
- const result = this.createResult(query, options);
1465
- if (shouldAssignObserverCurrentProperties(this, result, options)) {
1466
- this.currentResult = result;
1467
- this.currentResultOptions = this.options;
1468
- this.currentResultState = this.currentQuery.state;
1469
- }
1470
- return result;
1471
- }
1472
- getCurrentResult() {
1473
- return this.currentResult;
1474
- }
1475
- trackResult(result) {
1476
- const trackedResult = {};
1477
- Object.keys(result).forEach((key) => {
1478
- Object.defineProperty(trackedResult, key, {
1479
- configurable: false,
1480
- enumerable: true,
1481
- get: () => {
1482
- this.trackedProps.add(key);
1483
- return result[key];
1484
- }
1485
- });
1486
- });
1487
- return trackedResult;
1488
- }
1489
- getCurrentQuery() {
1490
- return this.currentQuery;
1491
- }
1492
- remove() {
1493
- this.client.getQueryCache().remove(this.currentQuery);
1494
- }
1495
- refetch(_a = {}) {
1496
- var _b = _a, {
1497
- refetchPage
1498
- } = _b, options = __objRest(_b, [
1499
- "refetchPage"
1500
- ]);
1501
- return this.fetch(__spreadProps(__spreadValues({}, options), {
1502
- meta: {
1503
- refetchPage
1504
- }
1505
- }));
1506
- }
1507
- fetchOptimistic(options) {
1508
- const defaultedOptions = this.client.defaultQueryOptions(options);
1509
- const query = this.client.getQueryCache().build(this.client, defaultedOptions);
1510
- query.isFetchingOptimistic = true;
1511
- return query.fetch().then(() => this.createResult(query, defaultedOptions));
1512
- }
1513
- fetch(fetchOptions) {
1514
- var _fetchOptions$cancelR;
1515
- return this.executeFetch(__spreadProps(__spreadValues({}, fetchOptions), {
1516
- cancelRefetch: (_fetchOptions$cancelR = fetchOptions.cancelRefetch) != null ? _fetchOptions$cancelR : true
1517
- })).then(() => {
1518
- this.updateResult();
1519
- return this.currentResult;
1520
- });
1521
- }
1522
- executeFetch(fetchOptions) {
1523
- this.updateQuery();
1524
- let promise = this.currentQuery.fetch(this.options, fetchOptions);
1525
- if (!(fetchOptions != null && fetchOptions.throwOnError)) {
1526
- promise = promise.catch(noop);
1527
- }
1528
- return promise;
1529
- }
1530
- updateStaleTimeout() {
1531
- this.clearStaleTimeout();
1532
- if (isServer || this.currentResult.isStale || !isValidTimeout(this.options.staleTime)) {
1533
- return;
1534
- }
1535
- const time = timeUntilStale(this.currentResult.dataUpdatedAt, this.options.staleTime);
1536
- const timeout = time + 1;
1537
- this.staleTimeoutId = setTimeout(() => {
1538
- if (!this.currentResult.isStale) {
1539
- this.updateResult();
1540
- }
1541
- }, timeout);
1542
- }
1543
- computeRefetchInterval() {
1544
- var _this$options$refetch;
1545
- return typeof this.options.refetchInterval === "function" ? this.options.refetchInterval(this.currentResult.data, this.currentQuery) : (_this$options$refetch = this.options.refetchInterval) != null ? _this$options$refetch : false;
1546
- }
1547
- updateRefetchInterval(nextInterval) {
1548
- this.clearRefetchInterval();
1549
- this.currentRefetchInterval = nextInterval;
1550
- if (isServer || this.options.enabled === false || !isValidTimeout(this.currentRefetchInterval) || this.currentRefetchInterval === 0) {
1551
- return;
1552
- }
1553
- this.refetchIntervalId = setInterval(() => {
1554
- if (this.options.refetchIntervalInBackground || focusManager.isFocused()) {
1555
- this.executeFetch();
1556
- }
1557
- }, this.currentRefetchInterval);
1558
- }
1559
- updateTimers() {
1560
- this.updateStaleTimeout();
1561
- this.updateRefetchInterval(this.computeRefetchInterval());
1562
- }
1563
- clearStaleTimeout() {
1564
- if (this.staleTimeoutId) {
1565
- clearTimeout(this.staleTimeoutId);
1566
- this.staleTimeoutId = void 0;
1567
- }
1568
- }
1569
- clearRefetchInterval() {
1570
- if (this.refetchIntervalId) {
1571
- clearInterval(this.refetchIntervalId);
1572
- this.refetchIntervalId = void 0;
1573
- }
1574
- }
1575
- createResult(query, options) {
1576
- const prevQuery = this.currentQuery;
1577
- const prevOptions = this.options;
1578
- const prevResult = this.currentResult;
1579
- const prevResultState = this.currentResultState;
1580
- const prevResultOptions = this.currentResultOptions;
1581
- const queryChange = query !== prevQuery;
1582
- const queryInitialState = queryChange ? query.state : this.currentQueryInitialState;
1583
- const prevQueryResult = queryChange ? this.currentResult : this.previousQueryResult;
1584
- const {
1585
- state
1586
- } = query;
1587
- let {
1588
- dataUpdatedAt,
1589
- error,
1590
- errorUpdatedAt,
1591
- fetchStatus,
1592
- status
1593
- } = state;
1594
- let isPreviousData = false;
1595
- let isPlaceholderData = false;
1596
- let data;
1597
- if (options._optimisticResults) {
1598
- const mounted = this.hasListeners();
1599
- const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
1600
- const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
1601
- if (fetchOnMount || fetchOptionally) {
1602
- fetchStatus = canFetch(query.options.networkMode) ? "fetching" : "paused";
1603
- if (!dataUpdatedAt) {
1604
- status = "loading";
1605
- }
1606
- }
1607
- if (options._optimisticResults === "isRestoring") {
1608
- fetchStatus = "idle";
1609
- }
1610
- }
1611
- if (options.keepPreviousData && !state.dataUpdatedAt && prevQueryResult != null && prevQueryResult.isSuccess && status !== "error") {
1612
- data = prevQueryResult.data;
1613
- dataUpdatedAt = prevQueryResult.dataUpdatedAt;
1614
- status = prevQueryResult.status;
1615
- isPreviousData = true;
1616
- } else if (options.select && typeof state.data !== "undefined") {
1617
- if (prevResult && state.data === (prevResultState == null ? void 0 : prevResultState.data) && options.select === this.selectFn) {
1618
- data = this.selectResult;
1619
- } else {
1620
- try {
1621
- this.selectFn = options.select;
1622
- data = options.select(state.data);
1623
- data = replaceData(prevResult == null ? void 0 : prevResult.data, data, options);
1624
- this.selectResult = data;
1625
- this.selectError = null;
1626
- } catch (selectError) {
1627
- if (process.env.NODE_ENV !== "production") {
1628
- this.client.getLogger().error(selectError);
1629
- }
1630
- this.selectError = selectError;
1631
- }
1632
- }
1633
- } else {
1634
- data = state.data;
1635
- }
1636
- if (typeof options.placeholderData !== "undefined" && typeof data === "undefined" && status === "loading") {
1637
- let placeholderData;
1638
- if (prevResult != null && prevResult.isPlaceholderData && options.placeholderData === (prevResultOptions == null ? void 0 : prevResultOptions.placeholderData)) {
1639
- placeholderData = prevResult.data;
1640
- } else {
1641
- placeholderData = typeof options.placeholderData === "function" ? options.placeholderData() : options.placeholderData;
1642
- if (options.select && typeof placeholderData !== "undefined") {
1643
- try {
1644
- placeholderData = options.select(placeholderData);
1645
- this.selectError = null;
1646
- } catch (selectError) {
1647
- if (process.env.NODE_ENV !== "production") {
1648
- this.client.getLogger().error(selectError);
1649
- }
1650
- this.selectError = selectError;
1651
- }
1652
- }
1653
- }
1654
- if (typeof placeholderData !== "undefined") {
1655
- status = "success";
1656
- data = replaceData(prevResult == null ? void 0 : prevResult.data, placeholderData, options);
1657
- isPlaceholderData = true;
1658
- }
1659
- }
1660
- if (this.selectError) {
1661
- error = this.selectError;
1662
- data = this.selectResult;
1663
- errorUpdatedAt = Date.now();
1664
- status = "error";
1665
- }
1666
- const isFetching = fetchStatus === "fetching";
1667
- const isLoading = status === "loading";
1668
- const isError2 = status === "error";
1669
- const result = {
1670
- status,
1671
- fetchStatus,
1672
- isLoading,
1673
- isSuccess: status === "success",
1674
- isError: isError2,
1675
- isInitialLoading: isLoading && isFetching,
1676
- data,
1677
- dataUpdatedAt,
1678
- error,
1679
- errorUpdatedAt,
1680
- failureCount: state.fetchFailureCount,
1681
- failureReason: state.fetchFailureReason,
1682
- errorUpdateCount: state.errorUpdateCount,
1683
- isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,
1684
- isFetchedAfterMount: state.dataUpdateCount > queryInitialState.dataUpdateCount || state.errorUpdateCount > queryInitialState.errorUpdateCount,
1685
- isFetching,
1686
- isRefetching: isFetching && !isLoading,
1687
- isLoadingError: isError2 && state.dataUpdatedAt === 0,
1688
- isPaused: fetchStatus === "paused",
1689
- isPlaceholderData,
1690
- isPreviousData,
1691
- isRefetchError: isError2 && state.dataUpdatedAt !== 0,
1692
- isStale: isStale(query, options),
1693
- refetch: this.refetch,
1694
- remove: this.remove
1695
- };
1696
- return result;
1697
- }
1698
- updateResult(notifyOptions) {
1699
- const prevResult = this.currentResult;
1700
- const nextResult = this.createResult(this.currentQuery, this.options);
1701
- this.currentResultState = this.currentQuery.state;
1702
- this.currentResultOptions = this.options;
1703
- if (shallowEqualObjects(nextResult, prevResult)) {
1704
- return;
1705
- }
1706
- this.currentResult = nextResult;
1707
- const defaultNotifyOptions = {
1708
- cache: true
1709
- };
1710
- const shouldNotifyListeners = () => {
1711
- if (!prevResult) {
1712
- return true;
1713
- }
1714
- const {
1715
- notifyOnChangeProps
1716
- } = this.options;
1717
- const notifyOnChangePropsValue = typeof notifyOnChangeProps === "function" ? notifyOnChangeProps() : notifyOnChangeProps;
1718
- if (notifyOnChangePropsValue === "all" || !notifyOnChangePropsValue && !this.trackedProps.size) {
1719
- return true;
1720
- }
1721
- const includedProps = new Set(notifyOnChangePropsValue != null ? notifyOnChangePropsValue : this.trackedProps);
1722
- if (this.options.useErrorBoundary) {
1723
- includedProps.add("error");
1724
- }
1725
- return Object.keys(this.currentResult).some((key) => {
1726
- const typedKey = key;
1727
- const changed = this.currentResult[typedKey] !== prevResult[typedKey];
1728
- return changed && includedProps.has(typedKey);
1729
- });
1730
- };
1731
- if ((notifyOptions == null ? void 0 : notifyOptions.listeners) !== false && shouldNotifyListeners()) {
1732
- defaultNotifyOptions.listeners = true;
1733
- }
1734
- this.notify(__spreadValues(__spreadValues({}, defaultNotifyOptions), notifyOptions));
1735
- }
1736
- updateQuery() {
1737
- const query = this.client.getQueryCache().build(this.client, this.options);
1738
- if (query === this.currentQuery) {
1739
- return;
1740
- }
1741
- const prevQuery = this.currentQuery;
1742
- this.currentQuery = query;
1743
- this.currentQueryInitialState = query.state;
1744
- this.previousQueryResult = this.currentResult;
1745
- if (this.hasListeners()) {
1746
- prevQuery == null ? void 0 : prevQuery.removeObserver(this);
1747
- query.addObserver(this);
1748
- }
1749
- }
1750
- onQueryUpdate(action) {
1751
- const notifyOptions = {};
1752
- if (action.type === "success") {
1753
- notifyOptions.onSuccess = !action.manual;
1754
- } else if (action.type === "error" && !isCancelledError(action.error)) {
1755
- notifyOptions.onError = true;
1756
- }
1757
- this.updateResult(notifyOptions);
1758
- if (this.hasListeners()) {
1759
- this.updateTimers();
1760
- }
1761
- }
1762
- notify(notifyOptions) {
1763
- notifyManager.batch(() => {
1764
- if (notifyOptions.onSuccess) {
1765
- var _this$options$onSucce, _this$options, _this$options$onSettl, _this$options2;
1766
- (_this$options$onSucce = (_this$options = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options, this.currentResult.data);
1767
- (_this$options$onSettl = (_this$options2 = this.options).onSettled) == null ? void 0 : _this$options$onSettl.call(_this$options2, this.currentResult.data, null);
1768
- } else if (notifyOptions.onError) {
1769
- var _this$options$onError, _this$options3, _this$options$onSettl2, _this$options4;
1770
- (_this$options$onError = (_this$options3 = this.options).onError) == null ? void 0 : _this$options$onError.call(_this$options3, this.currentResult.error);
1771
- (_this$options$onSettl2 = (_this$options4 = this.options).onSettled) == null ? void 0 : _this$options$onSettl2.call(_this$options4, void 0, this.currentResult.error);
1772
- }
1773
- if (notifyOptions.listeners) {
1774
- this.listeners.forEach(({
1775
- listener
1776
- }) => {
1777
- listener(this.currentResult);
1778
- });
1779
- }
1780
- if (notifyOptions.cache) {
1781
- this.client.getQueryCache().notify({
1782
- query: this.currentQuery,
1783
- type: "observerResultsUpdated"
1784
- });
1785
- }
1786
- });
1787
- }
1788
- };
1789
- function shouldLoadOnMount(query, options) {
1790
- return options.enabled !== false && !query.state.dataUpdatedAt && !(query.state.status === "error" && options.retryOnMount === false);
1791
- }
1792
- function shouldFetchOnMount(query, options) {
1793
- return shouldLoadOnMount(query, options) || query.state.dataUpdatedAt > 0 && shouldFetchOn(query, options, options.refetchOnMount);
1794
- }
1795
- function shouldFetchOn(query, options, field) {
1796
- if (options.enabled !== false) {
1797
- const value = typeof field === "function" ? field(query) : field;
1798
- return value === "always" || value !== false && isStale(query, options);
1799
- }
1800
- return false;
1801
- }
1802
- function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
1803
- return options.enabled !== false && (query !== prevQuery || prevOptions.enabled === false) && (!options.suspense || query.state.status !== "error") && isStale(query, options);
1804
- }
1805
- function isStale(query, options) {
1806
- return query.isStaleByTime(options.staleTime);
1807
- }
1808
- function shouldAssignObserverCurrentProperties(observer, optimisticResult, options) {
1809
- if (options.keepPreviousData) {
1810
- return false;
1811
- }
1812
- if (options.placeholderData !== void 0) {
1813
- return optimisticResult.isPlaceholderData;
1814
- }
1815
- if (!shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) {
1816
- return true;
1817
- }
1818
- return false;
1819
- }
1820
-
1821
- // ../../node_modules/@tanstack/react-query/build/lib/useSyncExternalStore.mjs
1822
- var import_shim = __toESM(require_shim(), 1);
1823
- var useSyncExternalStore = import_shim.useSyncExternalStore;
1824
-
1825
- // ../../node_modules/@tanstack/react-query/build/lib/QueryClientProvider.mjs
1826
- import * as React from "react";
1827
- var defaultContext = /* @__PURE__ */ React.createContext(void 0);
1828
- var QueryClientSharingContext = /* @__PURE__ */ React.createContext(false);
1829
- function getQueryClientContext(context, contextSharing) {
1830
- if (context) {
1831
- return context;
1832
- }
1833
- if (contextSharing && typeof window !== "undefined") {
1834
- if (!window.ReactQueryClientContext) {
1835
- window.ReactQueryClientContext = defaultContext;
1836
- }
1837
- return window.ReactQueryClientContext;
1838
- }
1839
- return defaultContext;
1840
- }
1841
- var useQueryClient = ({
1842
- context
1843
- } = {}) => {
1844
- const queryClient = React.useContext(getQueryClientContext(context, React.useContext(QueryClientSharingContext)));
1845
- if (!queryClient) {
1846
- throw new Error("No QueryClient set, use QueryClientProvider to set one");
1847
- }
1848
- return queryClient;
1849
- };
1850
-
1851
- // ../../node_modules/@tanstack/react-query/build/lib/isRestoring.mjs
1852
- import * as React2 from "react";
1853
- var IsRestoringContext = /* @__PURE__ */ React2.createContext(false);
1854
- var useIsRestoring = () => React2.useContext(IsRestoringContext);
1855
- var IsRestoringProvider = IsRestoringContext.Provider;
1856
-
1857
- // ../../node_modules/@tanstack/react-query/build/lib/QueryErrorResetBoundary.mjs
1858
- import * as React3 from "react";
1859
- function createValue() {
1860
- let isReset = false;
1861
- return {
1862
- clearReset: () => {
1863
- isReset = false;
1864
- },
1865
- reset: () => {
1866
- isReset = true;
1867
- },
1868
- isReset: () => {
1869
- return isReset;
1870
- }
1871
- };
1872
- }
1873
- var QueryErrorResetBoundaryContext = /* @__PURE__ */ React3.createContext(createValue());
1874
- var useQueryErrorResetBoundary = () => React3.useContext(QueryErrorResetBoundaryContext);
1875
-
1876
- // ../../node_modules/@tanstack/react-query/build/lib/errorBoundaryUtils.mjs
1877
- import * as React4 from "react";
1878
-
1879
- // ../../node_modules/@tanstack/react-query/build/lib/utils.mjs
1880
- function shouldThrowError(_useErrorBoundary, params) {
1881
- if (typeof _useErrorBoundary === "function") {
1882
- return _useErrorBoundary(...params);
1883
- }
1884
- return !!_useErrorBoundary;
1885
- }
1886
-
1887
- // ../../node_modules/@tanstack/react-query/build/lib/errorBoundaryUtils.mjs
1888
- var ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
1889
- if (options.suspense || options.useErrorBoundary) {
1890
- if (!errorResetBoundary.isReset()) {
1891
- options.retryOnMount = false;
1892
- }
1893
- }
1894
- };
1895
- var useClearResetErrorBoundary = (errorResetBoundary) => {
1896
- React4.useEffect(() => {
1897
- errorResetBoundary.clearReset();
1898
- }, [errorResetBoundary]);
1899
- };
1900
- var getHasError = ({
1901
- result,
1902
- errorResetBoundary,
1903
- useErrorBoundary,
1904
- query
1905
- }) => {
1906
- return result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(useErrorBoundary, [result.error, query]);
1907
- };
1908
-
1909
- // ../../node_modules/@tanstack/react-query/build/lib/suspense.mjs
1910
- var ensureStaleTime = (defaultedOptions) => {
1911
- if (defaultedOptions.suspense) {
1912
- if (typeof defaultedOptions.staleTime !== "number") {
1913
- defaultedOptions.staleTime = 1e3;
1914
- }
1915
- }
1916
- };
1917
- var willFetch = (result, isRestoring) => result.isLoading && result.isFetching && !isRestoring;
1918
- var shouldSuspend = (defaultedOptions, result, isRestoring) => (defaultedOptions == null ? void 0 : defaultedOptions.suspense) && willFetch(result, isRestoring);
1919
- var fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).then(({
1920
- data
1921
- }) => {
1922
- defaultedOptions.onSuccess == null ? void 0 : defaultedOptions.onSuccess(data);
1923
- defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(data, null);
1924
- }).catch((error) => {
1925
- errorResetBoundary.clearReset();
1926
- defaultedOptions.onError == null ? void 0 : defaultedOptions.onError(error);
1927
- defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(void 0, error);
1928
- });
1929
-
1930
- // ../../node_modules/@tanstack/react-query/build/lib/useBaseQuery.mjs
1931
- import * as React5 from "react";
1932
- function useBaseQuery(options, Observer) {
1933
- const queryClient = useQueryClient({
1934
- context: options.context
1935
- });
1936
- const isRestoring = useIsRestoring();
1937
- const errorResetBoundary = useQueryErrorResetBoundary();
1938
- const defaultedOptions = queryClient.defaultQueryOptions(options);
1939
- defaultedOptions._optimisticResults = isRestoring ? "isRestoring" : "optimistic";
1940
- if (defaultedOptions.onError) {
1941
- defaultedOptions.onError = notifyManager.batchCalls(defaultedOptions.onError);
1942
- }
1943
- if (defaultedOptions.onSuccess) {
1944
- defaultedOptions.onSuccess = notifyManager.batchCalls(defaultedOptions.onSuccess);
1945
- }
1946
- if (defaultedOptions.onSettled) {
1947
- defaultedOptions.onSettled = notifyManager.batchCalls(defaultedOptions.onSettled);
1948
- }
1949
- ensureStaleTime(defaultedOptions);
1950
- ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary);
1951
- useClearResetErrorBoundary(errorResetBoundary);
1952
- const [observer] = React5.useState(() => new Observer(queryClient, defaultedOptions));
1953
- const result = observer.getOptimisticResult(defaultedOptions);
1954
- useSyncExternalStore(React5.useCallback((onStoreChange) => {
1955
- const unsubscribe = isRestoring ? () => void 0 : observer.subscribe(notifyManager.batchCalls(onStoreChange));
1956
- observer.updateResult();
1957
- return unsubscribe;
1958
- }, [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
1959
- React5.useEffect(() => {
1960
- observer.setOptions(defaultedOptions, {
1961
- listeners: false
1962
- });
1963
- }, [defaultedOptions, observer]);
1964
- if (shouldSuspend(defaultedOptions, result, isRestoring)) {
1965
- throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);
1966
- }
1967
- if (getHasError({
1968
- result,
1969
- errorResetBoundary,
1970
- useErrorBoundary: defaultedOptions.useErrorBoundary,
1971
- query: observer.getCurrentQuery()
1972
- })) {
1973
- throw result.error;
1974
- }
1975
- return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
1976
- }
1977
-
1978
- // ../../node_modules/@tanstack/react-query/build/lib/useQuery.mjs
1979
- function useQuery(arg1, arg2, arg3) {
1980
- const parsedOptions = parseQueryArgs(arg1, arg2, arg3);
1981
- return useBaseQuery(parsedOptions, QueryObserver);
1982
- }
1983
-
1984
965
  // src/lib/useUploadCore.tsx
966
+ import { useQuery } from "@tanstack/react-query";
1985
967
  import Upload2 from "@availity/upload-core";
1986
968
  function startUpload2(file, options) {
1987
969
  return __async(this, null, function* () {
@@ -2141,8 +1123,9 @@ var FileList2 = ({
2141
1123
  };
2142
1124
 
2143
1125
  // src/lib/FileSelector.tsx
2144
- import { useState as useState5 } from "react";
1126
+ import { useState as useState3 } from "react";
2145
1127
  import { useFormContext as useFormContext3 } from "react-hook-form";
1128
+ import { useQueryClient } from "@tanstack/react-query";
2146
1129
  import { Grid as Grid4 } from "@availity/mui-layout";
2147
1130
  import { Typography as Typography6 } from "@availity/mui-typography";
2148
1131
  import { Alert as Alert2, AlertTitle as AlertTitle2 } from "@availity/mui-alert";
@@ -2153,14 +1136,18 @@ import { jsxs as jsxs11 } from "react/jsx-runtime";
2153
1136
  var FileTypesMessage = ({
2154
1137
  allowedFileTypes = [],
2155
1138
  customSizeMessage,
1139
+ customTotalSizeMessage,
2156
1140
  customTypesMessage,
2157
1141
  maxFileSize,
1142
+ maxTotalSize,
2158
1143
  variant = "caption"
2159
1144
  }) => {
2160
1145
  const fileSizeMsg = customSizeMessage || (typeof maxFileSize === "number" ? `Maximum file size is ${formatBytes(maxFileSize)}. ` : null);
1146
+ const totalFileSizeMsg = customTotalSizeMessage || (typeof maxTotalSize === "number" ? `Maximum total upload size is ${formatBytes(maxTotalSize)}. ` : null);
2161
1147
  const fileTypesMsg = customTypesMessage || (allowedFileTypes.length > 0 ? `Supported file types include: ${allowedFileTypes.join(", ")}` : "All file types allowed.");
2162
1148
  return /* @__PURE__ */ jsxs11(Typography4, { variant, children: [
2163
1149
  fileSizeMsg,
1150
+ totalFileSizeMsg,
2164
1151
  fileTypesMsg
2165
1152
  ] });
2166
1153
  };
@@ -2168,12 +1155,14 @@ var FileTypesMessage = ({
2168
1155
  // src/lib/HeaderMessage.tsx
2169
1156
  import { Typography as Typography5 } from "@availity/mui-typography";
2170
1157
  import { jsxs as jsxs12 } from "react/jsx-runtime";
2171
- var HeaderMessage = ({ maxFiles, maxSize }) => {
1158
+ var HeaderMessage = ({ maxFiles, maxSize, maxTotalSize }) => {
2172
1159
  return /* @__PURE__ */ jsxs12(Typography5, { variant: "h6", children: [
2173
1160
  "Attach up to ",
2174
1161
  maxFiles,
2175
1162
  " file(s), with a maximum individual size of ",
2176
- formatBytes(maxSize)
1163
+ formatBytes(maxSize),
1164
+ " ",
1165
+ maxTotalSize && `and a maximum total size of ${formatBytes(maxTotalSize)}`
2177
1166
  ] });
2178
1167
  };
2179
1168
 
@@ -2188,6 +1177,7 @@ var FileSelector = ({
2188
1177
  clientId,
2189
1178
  children,
2190
1179
  customSizeMessage,
1180
+ customTotalSizeMessage,
2191
1181
  customTypesMessage,
2192
1182
  customerId,
2193
1183
  customFileRow,
@@ -2198,6 +1188,7 @@ var FileSelector = ({
2198
1188
  label = "Upload file",
2199
1189
  maxFiles,
2200
1190
  maxSize,
1191
+ maxTotalSize,
2201
1192
  multiple = true,
2202
1193
  onChange,
2203
1194
  onDrop,
@@ -2207,8 +1198,8 @@ var FileSelector = ({
2207
1198
  validator,
2208
1199
  disableRemove
2209
1200
  }) => {
2210
- const [totalSize, setTotalSize] = useState5(0);
2211
- const [fileRejections, setFileRejections] = useState5([]);
1201
+ const [totalSize, setTotalSize] = useState3(0);
1202
+ const [fileRejections, setFileRejections] = useState3([]);
2212
1203
  const client = useQueryClient();
2213
1204
  const formMethods = useFormContext3();
2214
1205
  const options = __spreadProps(__spreadValues({}, uploadOptions), {
@@ -2261,6 +1252,7 @@ var FileSelector = ({
2261
1252
  enableDropArea,
2262
1253
  maxFiles,
2263
1254
  maxSize,
1255
+ maxTotalSize,
2264
1256
  multiple,
2265
1257
  onChange,
2266
1258
  onDrop,
@@ -2274,7 +1266,9 @@ var FileSelector = ({
2274
1266
  {
2275
1267
  allowedFileTypes,
2276
1268
  maxFileSize: maxSize,
1269
+ maxTotalSize,
2277
1270
  customSizeMessage,
1271
+ customTotalSizeMessage,
2278
1272
  customTypesMessage,
2279
1273
  variant: "caption"
2280
1274
  }
@@ -2282,11 +1276,12 @@ var FileSelector = ({
2282
1276
  children
2283
1277
  ] }) : /* @__PURE__ */ jsxs13(Grid4, { container: true, rowSpacing: 3, flexDirection: "column", children: [
2284
1278
  /* @__PURE__ */ jsxs13(Grid4, { children: [
2285
- /* @__PURE__ */ jsx14(HeaderMessage, { maxFiles, maxSize }),
1279
+ /* @__PURE__ */ jsx14(HeaderMessage, { maxFiles, maxSize, maxTotalSize }),
2286
1280
  /* @__PURE__ */ jsx14(
2287
1281
  FileTypesMessage,
2288
1282
  {
2289
1283
  allowedFileTypes,
1284
+ customTotalSizeMessage,
2290
1285
  customSizeMessage,
2291
1286
  customTypesMessage,
2292
1287
  variant: "body2"
@@ -2303,6 +1298,7 @@ var FileSelector = ({
2303
1298
  enableDropArea,
2304
1299
  maxFiles,
2305
1300
  maxSize,
1301
+ maxTotalSize,
2306
1302
  multiple,
2307
1303
  onChange,
2308
1304
  onDrop,
@@ -2350,7 +1346,7 @@ var FileSelector = ({
2350
1346
  };
2351
1347
 
2352
1348
  // src/lib/FileSelector2.tsx
2353
- import { useState as useState6 } from "react";
1349
+ import { useState as useState4 } from "react";
2354
1350
  import { useFormContext as useFormContext4 } from "react-hook-form";
2355
1351
  import { Grid as Grid5 } from "@availity/mui-layout";
2356
1352
  import { Typography as Typography7 } from "@availity/mui-typography";
@@ -2364,6 +1360,7 @@ var FileSelector2 = ({
2364
1360
  clientId,
2365
1361
  children,
2366
1362
  customSizeMessage,
1363
+ customTotalSizeMessage,
2367
1364
  customTypesMessage,
2368
1365
  customerId,
2369
1366
  customFileRow,
@@ -2374,6 +1371,7 @@ var FileSelector2 = ({
2374
1371
  label = "Upload file",
2375
1372
  maxFiles,
2376
1373
  maxSize,
1374
+ maxTotalSize,
2377
1375
  multiple = true,
2378
1376
  onChange,
2379
1377
  onDrop,
@@ -2382,8 +1380,8 @@ var FileSelector2 = ({
2382
1380
  validator,
2383
1381
  disableRemove
2384
1382
  }) => {
2385
- const [totalSize, setTotalSize] = useState6(0);
2386
- const [fileRejections, setFileRejections] = useState6([]);
1383
+ const [totalSize, setTotalSize] = useState4(0);
1384
+ const [fileRejections, setFileRejections] = useState4([]);
2387
1385
  const formMethods = useFormContext4();
2388
1386
  const options = __spreadProps(__spreadValues({}, uploadOptions), {
2389
1387
  bucketId,
@@ -2434,6 +1432,7 @@ var FileSelector2 = ({
2434
1432
  enableDropArea,
2435
1433
  maxFiles,
2436
1434
  maxSize,
1435
+ maxTotalSize,
2437
1436
  multiple,
2438
1437
  onChange,
2439
1438
  onDrop,
@@ -2448,7 +1447,9 @@ var FileSelector2 = ({
2448
1447
  {
2449
1448
  allowedFileTypes,
2450
1449
  maxFileSize: maxSize,
1450
+ maxTotalSize,
2451
1451
  customSizeMessage,
1452
+ customTotalSizeMessage,
2452
1453
  customTypesMessage,
2453
1454
  variant: "caption"
2454
1455
  }
@@ -2456,12 +1457,13 @@ var FileSelector2 = ({
2456
1457
  children
2457
1458
  ] }) : /* @__PURE__ */ jsxs14(Grid5, { container: true, rowSpacing: 3, flexDirection: "column", children: [
2458
1459
  /* @__PURE__ */ jsxs14(Grid5, { children: [
2459
- /* @__PURE__ */ jsx15(HeaderMessage, { maxFiles, maxSize }),
1460
+ /* @__PURE__ */ jsx15(HeaderMessage, { maxFiles, maxSize, maxTotalSize }),
2460
1461
  /* @__PURE__ */ jsx15(
2461
1462
  FileTypesMessage,
2462
1463
  {
2463
1464
  allowedFileTypes,
2464
1465
  customSizeMessage,
1466
+ customTotalSizeMessage,
2465
1467
  customTypesMessage,
2466
1468
  variant: "body2"
2467
1469
  }
@@ -2477,6 +1479,7 @@ var FileSelector2 = ({
2477
1479
  enableDropArea,
2478
1480
  maxFiles,
2479
1481
  maxSize,
1482
+ maxTotalSize,
2480
1483
  multiple,
2481
1484
  onChange,
2482
1485
  onDrop,
@@ -2544,27 +1547,3 @@ export {
2544
1547
  outerBoxStyles,
2545
1548
  useUploadCore
2546
1549
  };
2547
- /*! Bundled license information:
2548
-
2549
- use-sync-external-store/cjs/use-sync-external-store-shim.production.js:
2550
- (**
2551
- * @license React
2552
- * use-sync-external-store-shim.production.js
2553
- *
2554
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2555
- *
2556
- * This source code is licensed under the MIT license found in the
2557
- * LICENSE file in the root directory of this source tree.
2558
- *)
2559
-
2560
- use-sync-external-store/cjs/use-sync-external-store-shim.development.js:
2561
- (**
2562
- * @license React
2563
- * use-sync-external-store-shim.development.js
2564
- *
2565
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2566
- *
2567
- * This source code is licensed under the MIT license found in the
2568
- * LICENSE file in the root directory of this source tree.
2569
- *)
2570
- */