@pucp-gidis-hiisc/esm-fua-app 1.0.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.
Files changed (95) hide show
  1. package/.turbo/turbo-extract-translations.log +11 -0
  2. package/.turbo/turbo-lint.log +0 -0
  3. package/.turbo/turbo-test.log +1 -0
  4. package/.turbo/turbo-typescript.log +0 -0
  5. package/README.md +9 -0
  6. package/dist/@pucp-gidis-hiisc/esm-dyaku-app.3156ff9f6a47f657.hot-update.js +11 -0
  7. package/dist/@pucp-gidis-hiisc/esm-dyaku-app.3156ff9f6a47f657.hot-update.js.map +1 -0
  8. package/dist/@pucp-gidis-hiisc/esm-dyaku-app.52df2f9ab9342568.hot-update.js +11 -0
  9. package/dist/@pucp-gidis-hiisc/esm-dyaku-app.52df2f9ab9342568.hot-update.js.map +1 -0
  10. package/dist/@pucp-gidis-hiisc/esm-dyaku-app.670ae221c7eb0597.hot-update.js +11 -0
  11. package/dist/@pucp-gidis-hiisc/esm-dyaku-app.670ae221c7eb0597.hot-update.js.map +1 -0
  12. package/dist/_pucp-gidis-hiisc_esm-dyaku-app.3156ff9f6a47f657.hot-update.json +1 -0
  13. package/dist/_pucp-gidis-hiisc_esm-dyaku-app.52df2f9ab9342568.hot-update.json +1 -0
  14. package/dist/_pucp-gidis-hiisc_esm-dyaku-app.670ae221c7eb0597.hot-update.json +1 -0
  15. package/dist/main.3156ff9f6a47f657.hot-update.js +11 -0
  16. package/dist/main.3156ff9f6a47f657.hot-update.js.map +1 -0
  17. package/dist/main.3156ff9f6a47f657.hot-update.json +1 -0
  18. package/dist/main.52df2f9ab9342568.hot-update.js +11 -0
  19. package/dist/main.52df2f9ab9342568.hot-update.js.map +1 -0
  20. package/dist/main.52df2f9ab9342568.hot-update.json +1 -0
  21. package/dist/main.670ae221c7eb0597.hot-update.js +11 -0
  22. package/dist/main.670ae221c7eb0597.hot-update.js.map +1 -0
  23. package/dist/main.670ae221c7eb0597.hot-update.json +1 -0
  24. package/dist/main.js +5012 -0
  25. package/dist/main.js.map +1 -0
  26. package/dist/node_modules_babel_runtime_helpers_esm_objectWithoutPropertiesLoose_js.js +28 -0
  27. package/dist/node_modules_babel_runtime_helpers_esm_objectWithoutPropertiesLoose_js.js.map +1 -0
  28. package/dist/node_modules_client-only_index_js-node_modules_use-sync-external-store_shim_index_js-_e121-_afc40.js +137 -0
  29. package/dist/node_modules_client-only_index_js-node_modules_use-sync-external-store_shim_index_js-_e121-_afc40.js.map +1 -0
  30. package/dist/node_modules_client-only_index_js-node_modules_use-sync-external-store_shim_index_js-_e121-_afc41.js +137 -0
  31. package/dist/node_modules_client-only_index_js-node_modules_use-sync-external-store_shim_index_js-_e121-_afc41.js.map +1 -0
  32. package/dist/node_modules_dayjs_dayjs_min_js.js +14 -0
  33. package/dist/node_modules_dayjs_dayjs_min_js.js.map +1 -0
  34. package/dist/pucp-gidis-hiisc-esm-dyaku-app.js +4902 -0
  35. package/dist/pucp-gidis-hiisc-esm-dyaku-app.js.buildmanifest.json +705 -0
  36. package/dist/pucp-gidis-hiisc-esm-dyaku-app.js.map +1 -0
  37. package/dist/routes.json +1 -0
  38. package/dist/src_dyaku-patients_dyaku-patients-link_component_tsx.js +46 -0
  39. package/dist/src_dyaku-patients_dyaku-patients-link_component_tsx.js.map +1 -0
  40. package/dist/src_dyaku-patients_dyaku_main_component_tsx.3156ff9f6a47f657.hot-update.js +309 -0
  41. package/dist/src_dyaku-patients_dyaku_main_component_tsx.3156ff9f6a47f657.hot-update.js.map +1 -0
  42. package/dist/src_dyaku-patients_dyaku_main_component_tsx.52df2f9ab9342568.hot-update.js +309 -0
  43. package/dist/src_dyaku-patients_dyaku_main_component_tsx.52df2f9ab9342568.hot-update.js.map +1 -0
  44. package/dist/src_dyaku-patients_dyaku_main_component_tsx.670ae221c7eb0597.hot-update.js +309 -0
  45. package/dist/src_dyaku-patients_dyaku_main_component_tsx.670ae221c7eb0597.hot-update.js.map +1 -0
  46. package/dist/src_dyaku-patients_dyaku_main_component_tsx.js +2520 -0
  47. package/dist/src_dyaku-patients_dyaku_main_component_tsx.js.map +1 -0
  48. package/dist/src_index_ts.js +146 -0
  49. package/dist/src_index_ts.js.map +1 -0
  50. package/dist/translations_en_json.js +14 -0
  51. package/dist/translations_es_json.js +14 -0
  52. package/dist/vendors-node_modules_carbon_react_es_index_js.js +121758 -0
  53. package/dist/vendors-node_modules_carbon_react_es_index_js.js.map +1 -0
  54. package/dist/vendors-node_modules_openmrs_esm-framework_src_internal_ts.js +4256 -0
  55. package/dist/vendors-node_modules_openmrs_esm-framework_src_internal_ts.js.map +1 -0
  56. package/dist/vendors-node_modules_openmrs_esm-patient-common-lib_src_index_ts.js +4200 -0
  57. package/dist/vendors-node_modules_openmrs_esm-patient-common-lib_src_index_ts.js.map +1 -0
  58. package/dist/vendors-node_modules_openmrs_esm-styleguide_src_internal_ts.js +119007 -0
  59. package/dist/vendors-node_modules_openmrs_esm-styleguide_src_internal_ts.js.map +1 -0
  60. package/dist/vendors-node_modules_react-dom_index_js.js +30632 -0
  61. package/dist/vendors-node_modules_react-dom_index_js.js.map +1 -0
  62. package/dist/vendors-node_modules_react-i18next_dist_es_index_js.js +1392 -0
  63. package/dist/vendors-node_modules_react-i18next_dist_es_index_js.js.map +1 -0
  64. package/dist/vendors-node_modules_react-router-dom_dist_index_js.js +8221 -0
  65. package/dist/vendors-node_modules_react-router-dom_dist_index_js.js.map +1 -0
  66. package/dist/vendors-node_modules_react_index_js.js +2772 -0
  67. package/dist/vendors-node_modules_react_index_js.js.map +1 -0
  68. package/dist/vendors-node_modules_rxjs__esm5_index_js.js +6245 -0
  69. package/dist/vendors-node_modules_rxjs__esm5_index_js.js.map +1 -0
  70. package/dist/vendors-node_modules_swr_dist__internal_index_mjs.js +732 -0
  71. package/dist/vendors-node_modules_swr_dist__internal_index_mjs.js.map +1 -0
  72. package/dist/vendors-node_modules_swr_dist_immutable_index_mjs.js +572 -0
  73. package/dist/vendors-node_modules_swr_dist_immutable_index_mjs.js.map +1 -0
  74. package/dist/vendors-node_modules_swr_dist_infinite_index_mjs.js +815 -0
  75. package/dist/vendors-node_modules_swr_dist_infinite_index_mjs.js.map +1 -0
  76. package/jest.config.js +3 -0
  77. package/package.json +68 -0
  78. package/src/config-schema.ts +61 -0
  79. package/src/constant.ts +1 -0
  80. package/src/dashboard.meta.tsx +8 -0
  81. package/src/declarations.d.ts +6 -0
  82. package/src/fua/case-management-header.tsx +37 -0
  83. package/src/fua/case-management-illustration.tsx +13 -0
  84. package/src/fua/fua-request-table.scss +173 -0
  85. package/src/fua/fuaRequestTable.tsx +147 -0
  86. package/src/fua/solicitudes/.gitkeep +0 -0
  87. package/src/hooks/useFuaRequests.ts +48 -0
  88. package/src/index.ts +27 -0
  89. package/src/left-panel-link.component.tsx +42 -0
  90. package/src/root.scss +102 -0
  91. package/src/routes.json +28 -0
  92. package/translations/en.json +0 -0
  93. package/translations/es.json +0 -0
  94. package/tsconfig.json +5 -0
  95. package/webpack.config.js +1 -0
@@ -0,0 +1,732 @@
1
+ "use strict";
2
+ (globalThis["webpackChunk_pucp_gidis_hiisc_esm_dyaku_app"] = globalThis["webpackChunk_pucp_gidis_hiisc_esm_dyaku_app"] || []).push([["vendors-node_modules_swr_dist__internal_index_mjs"],{
3
+
4
+ /***/ "../../node_modules/swr/dist/_internal/index.mjs":
5
+ /*!*******************************************************!*\
6
+ !*** ../../node_modules/swr/dist/_internal/index.mjs ***!
7
+ \*******************************************************/
8
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
9
+
10
+ __webpack_require__.r(__webpack_exports__);
11
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
12
+ /* harmony export */ INFINITE_PREFIX: () => (/* binding */ INFINITE_PREFIX),
13
+ /* harmony export */ IS_REACT_LEGACY: () => (/* binding */ IS_REACT_LEGACY),
14
+ /* harmony export */ IS_SERVER: () => (/* binding */ IS_SERVER),
15
+ /* harmony export */ OBJECT: () => (/* binding */ OBJECT),
16
+ /* harmony export */ SWRConfig: () => (/* binding */ SWRConfig),
17
+ /* harmony export */ SWRGlobalState: () => (/* binding */ SWRGlobalState),
18
+ /* harmony export */ UNDEFINED: () => (/* binding */ UNDEFINED),
19
+ /* harmony export */ cache: () => (/* binding */ cache),
20
+ /* harmony export */ compare: () => (/* binding */ compare),
21
+ /* harmony export */ createCacheHelper: () => (/* binding */ createCacheHelper),
22
+ /* harmony export */ defaultConfig: () => (/* binding */ defaultConfig),
23
+ /* harmony export */ defaultConfigOptions: () => (/* binding */ defaultConfigOptions),
24
+ /* harmony export */ getTimestamp: () => (/* binding */ getTimestamp),
25
+ /* harmony export */ hasRequestAnimationFrame: () => (/* binding */ hasRequestAnimationFrame),
26
+ /* harmony export */ initCache: () => (/* binding */ initCache),
27
+ /* harmony export */ internalMutate: () => (/* binding */ internalMutate),
28
+ /* harmony export */ isDocumentDefined: () => (/* binding */ isDocumentDefined),
29
+ /* harmony export */ isFunction: () => (/* binding */ isFunction),
30
+ /* harmony export */ isPromiseLike: () => (/* binding */ isPromiseLike),
31
+ /* harmony export */ isUndefined: () => (/* binding */ isUndefined),
32
+ /* harmony export */ isWindowDefined: () => (/* binding */ isWindowDefined),
33
+ /* harmony export */ mergeConfigs: () => (/* binding */ mergeConfigs),
34
+ /* harmony export */ mergeObjects: () => (/* binding */ mergeObjects),
35
+ /* harmony export */ mutate: () => (/* binding */ mutate),
36
+ /* harmony export */ noop: () => (/* binding */ noop),
37
+ /* harmony export */ normalize: () => (/* binding */ normalize),
38
+ /* harmony export */ preload: () => (/* binding */ preload),
39
+ /* harmony export */ preset: () => (/* binding */ preset),
40
+ /* harmony export */ rAF: () => (/* binding */ rAF),
41
+ /* harmony export */ revalidateEvents: () => (/* binding */ events),
42
+ /* harmony export */ serialize: () => (/* binding */ serialize),
43
+ /* harmony export */ slowConnection: () => (/* binding */ slowConnection),
44
+ /* harmony export */ stableHash: () => (/* binding */ stableHash),
45
+ /* harmony export */ subscribeCallback: () => (/* binding */ subscribeCallback),
46
+ /* harmony export */ useIsomorphicLayoutEffect: () => (/* binding */ useIsomorphicLayoutEffect),
47
+ /* harmony export */ useSWRConfig: () => (/* binding */ useSWRConfig),
48
+ /* harmony export */ withArgs: () => (/* binding */ withArgs),
49
+ /* harmony export */ withMiddleware: () => (/* binding */ withMiddleware)
50
+ /* harmony export */ });
51
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "webpack/sharing/consume/default/react/react");
52
+
53
+
54
+ // Shared state between server components and client components
55
+ const noop = ()=>{};
56
+ // Using noop() as the undefined value as undefined can be replaced
57
+ // by something else. Prettier ignore and extra parentheses are necessary here
58
+ // to ensure that tsc doesn't remove the __NOINLINE__ comment.
59
+ // prettier-ignore
60
+ const UNDEFINED = /*#__NOINLINE__*/ noop();
61
+ const OBJECT = Object;
62
+ const isUndefined = (v)=>v === UNDEFINED;
63
+ const isFunction = (v)=>typeof v == 'function';
64
+ const mergeObjects = (a, b)=>({
65
+ ...a,
66
+ ...b
67
+ });
68
+ const isPromiseLike = (x)=>isFunction(x.then);
69
+
70
+ // use WeakMap to store the object->key mapping
71
+ // so the objects can be garbage collected.
72
+ // WeakMap uses a hashtable under the hood, so the lookup
73
+ // complexity is almost O(1).
74
+ const table = new WeakMap();
75
+ // counter of the key
76
+ let counter = 0;
77
+ // A stable hash implementation that supports:
78
+ // - Fast and ensures unique hash properties
79
+ // - Handles unserializable values
80
+ // - Handles object key ordering
81
+ // - Generates short results
82
+ //
83
+ // This is not a serialization function, and the result is not guaranteed to be
84
+ // parsable.
85
+ const stableHash = (arg)=>{
86
+ const type = typeof arg;
87
+ const constructor = arg && arg.constructor;
88
+ const isDate = constructor == Date;
89
+ let result;
90
+ let index;
91
+ if (OBJECT(arg) === arg && !isDate && constructor != RegExp) {
92
+ // Object/function, not null/date/regexp. Use WeakMap to store the id first.
93
+ // If it's already hashed, directly return the result.
94
+ result = table.get(arg);
95
+ if (result) return result;
96
+ // Store the hash first for circular reference detection before entering the
97
+ // recursive `stableHash` calls.
98
+ // For other objects like set and map, we use this id directly as the hash.
99
+ result = ++counter + '~';
100
+ table.set(arg, result);
101
+ if (constructor == Array) {
102
+ // Array.
103
+ result = '@';
104
+ for(index = 0; index < arg.length; index++){
105
+ result += stableHash(arg[index]) + ',';
106
+ }
107
+ table.set(arg, result);
108
+ }
109
+ if (constructor == OBJECT) {
110
+ // Object, sort keys.
111
+ result = '#';
112
+ const keys = OBJECT.keys(arg).sort();
113
+ while(!isUndefined(index = keys.pop())){
114
+ if (!isUndefined(arg[index])) {
115
+ result += index + ':' + stableHash(arg[index]) + ',';
116
+ }
117
+ }
118
+ table.set(arg, result);
119
+ }
120
+ } else {
121
+ result = isDate ? arg.toJSON() : type == 'symbol' ? arg.toString() : type == 'string' ? JSON.stringify(arg) : '' + arg;
122
+ }
123
+ return result;
124
+ };
125
+
126
+ // Global state used to deduplicate requests and store listeners
127
+ const SWRGlobalState = new WeakMap();
128
+
129
+ const EMPTY_CACHE = {};
130
+ const INITIAL_CACHE = {};
131
+ const STR_UNDEFINED = 'undefined';
132
+ // NOTE: Use the function to guarantee it's re-evaluated between jsdom and node runtime for tests.
133
+ const isWindowDefined = typeof window != STR_UNDEFINED;
134
+ const isDocumentDefined = typeof document != STR_UNDEFINED;
135
+ const hasRequestAnimationFrame = ()=>isWindowDefined && typeof window['requestAnimationFrame'] != STR_UNDEFINED;
136
+ const createCacheHelper = (cache, key)=>{
137
+ const state = SWRGlobalState.get(cache);
138
+ return [
139
+ // Getter
140
+ ()=>!isUndefined(key) && cache.get(key) || EMPTY_CACHE,
141
+ // Setter
142
+ (info)=>{
143
+ if (!isUndefined(key)) {
144
+ const prev = cache.get(key);
145
+ // Before writing to the store, we keep the value in the initial cache
146
+ // if it's not there yet.
147
+ if (!(key in INITIAL_CACHE)) {
148
+ INITIAL_CACHE[key] = prev;
149
+ }
150
+ state[5](key, mergeObjects(prev, info), prev || EMPTY_CACHE);
151
+ }
152
+ },
153
+ // Subscriber
154
+ state[6],
155
+ // Get server cache snapshot
156
+ ()=>{
157
+ if (!isUndefined(key)) {
158
+ // If the cache was updated on the client, we return the stored initial value.
159
+ if (key in INITIAL_CACHE) return INITIAL_CACHE[key];
160
+ }
161
+ // If we haven't done any client-side updates, we return the current value.
162
+ return !isUndefined(key) && cache.get(key) || EMPTY_CACHE;
163
+ }
164
+ ];
165
+ } // export { UNDEFINED, OBJECT, isUndefined, isFunction, mergeObjects, isPromiseLike }
166
+ ;
167
+
168
+ /**
169
+ * Due to the bug https://bugs.chromium.org/p/chromium/issues/detail?id=678075,
170
+ * it's not reliable to detect if the browser is currently online or offline
171
+ * based on `navigator.onLine`.
172
+ * As a workaround, we always assume it's online on the first load, and change
173
+ * the status upon `online` or `offline` events.
174
+ */ let online = true;
175
+ const isOnline = ()=>online;
176
+ // For node and React Native, `add/removeEventListener` doesn't exist on window.
177
+ const [onWindowEvent, offWindowEvent] = isWindowDefined && window.addEventListener ? [
178
+ window.addEventListener.bind(window),
179
+ window.removeEventListener.bind(window)
180
+ ] : [
181
+ noop,
182
+ noop
183
+ ];
184
+ const isVisible = ()=>{
185
+ const visibilityState = isDocumentDefined && document.visibilityState;
186
+ return isUndefined(visibilityState) || visibilityState !== 'hidden';
187
+ };
188
+ const initFocus = (callback)=>{
189
+ // focus revalidate
190
+ if (isDocumentDefined) {
191
+ document.addEventListener('visibilitychange', callback);
192
+ }
193
+ onWindowEvent('focus', callback);
194
+ return ()=>{
195
+ if (isDocumentDefined) {
196
+ document.removeEventListener('visibilitychange', callback);
197
+ }
198
+ offWindowEvent('focus', callback);
199
+ };
200
+ };
201
+ const initReconnect = (callback)=>{
202
+ // revalidate on reconnected
203
+ const onOnline = ()=>{
204
+ online = true;
205
+ callback();
206
+ };
207
+ // nothing to revalidate, just update the status
208
+ const onOffline = ()=>{
209
+ online = false;
210
+ };
211
+ onWindowEvent('online', onOnline);
212
+ onWindowEvent('offline', onOffline);
213
+ return ()=>{
214
+ offWindowEvent('online', onOnline);
215
+ offWindowEvent('offline', onOffline);
216
+ };
217
+ };
218
+ const preset = {
219
+ isOnline,
220
+ isVisible
221
+ };
222
+ const defaultConfigOptions = {
223
+ initFocus,
224
+ initReconnect
225
+ };
226
+
227
+ const IS_REACT_LEGACY = !react__WEBPACK_IMPORTED_MODULE_0__.useId;
228
+ const IS_SERVER = !isWindowDefined || 'Deno' in window;
229
+ // Polyfill requestAnimationFrame
230
+ const rAF = (f)=>hasRequestAnimationFrame() ? window['requestAnimationFrame'](f) : setTimeout(f, 1);
231
+ // React currently throws a warning when using useLayoutEffect on the server.
232
+ // To get around it, we can conditionally useEffect on the server (no-op) and
233
+ // useLayoutEffect in the browser.
234
+ const useIsomorphicLayoutEffect = IS_SERVER ? react__WEBPACK_IMPORTED_MODULE_0__.useEffect : react__WEBPACK_IMPORTED_MODULE_0__.useLayoutEffect;
235
+ // This assignment is to extend the Navigator type to use effectiveType.
236
+ const navigatorConnection = typeof navigator !== 'undefined' && navigator.connection;
237
+ // Adjust the config based on slow connection status (<= 70Kbps).
238
+ const slowConnection = !IS_SERVER && navigatorConnection && ([
239
+ 'slow-2g',
240
+ '2g'
241
+ ].includes(navigatorConnection.effectiveType) || navigatorConnection.saveData);
242
+
243
+ const serialize = (key)=>{
244
+ if (isFunction(key)) {
245
+ try {
246
+ key = key();
247
+ } catch (err) {
248
+ // dependencies not ready
249
+ key = '';
250
+ }
251
+ }
252
+ // Use the original key as the argument of fetcher. This can be a string or an
253
+ // array of values.
254
+ const args = key;
255
+ // If key is not falsy, or not an empty array, hash it.
256
+ key = typeof key == 'string' ? key : (Array.isArray(key) ? key.length : key) ? stableHash(key) : '';
257
+ return [
258
+ key,
259
+ args
260
+ ];
261
+ };
262
+
263
+ // Global timestamp.
264
+ let __timestamp = 0;
265
+ const getTimestamp = ()=>++__timestamp;
266
+
267
+ const FOCUS_EVENT = 0;
268
+ const RECONNECT_EVENT = 1;
269
+ const MUTATE_EVENT = 2;
270
+ const ERROR_REVALIDATE_EVENT = 3;
271
+
272
+ var events = {
273
+ __proto__: null,
274
+ ERROR_REVALIDATE_EVENT: ERROR_REVALIDATE_EVENT,
275
+ FOCUS_EVENT: FOCUS_EVENT,
276
+ MUTATE_EVENT: MUTATE_EVENT,
277
+ RECONNECT_EVENT: RECONNECT_EVENT
278
+ };
279
+
280
+ async function internalMutate(...args) {
281
+ const [cache, _key, _data, _opts] = args;
282
+ // When passing as a boolean, it's explicitly used to disable/enable
283
+ // revalidation.
284
+ const options = mergeObjects({
285
+ populateCache: true,
286
+ throwOnError: true
287
+ }, typeof _opts === 'boolean' ? {
288
+ revalidate: _opts
289
+ } : _opts || {});
290
+ let populateCache = options.populateCache;
291
+ const rollbackOnErrorOption = options.rollbackOnError;
292
+ let optimisticData = options.optimisticData;
293
+ const rollbackOnError = (error)=>{
294
+ return typeof rollbackOnErrorOption === 'function' ? rollbackOnErrorOption(error) : rollbackOnErrorOption !== false;
295
+ };
296
+ const throwOnError = options.throwOnError;
297
+ // If the second argument is a key filter, return the mutation results for all
298
+ // filtered keys.
299
+ if (isFunction(_key)) {
300
+ const keyFilter = _key;
301
+ const matchedKeys = [];
302
+ const it = cache.keys();
303
+ for (const key of it){
304
+ if (// Skip the special useSWRInfinite and useSWRSubscription keys.
305
+ !/^\$(inf|sub)\$/.test(key) && keyFilter(cache.get(key)._k)) {
306
+ matchedKeys.push(key);
307
+ }
308
+ }
309
+ return Promise.all(matchedKeys.map(mutateByKey));
310
+ }
311
+ return mutateByKey(_key);
312
+ async function mutateByKey(_k) {
313
+ // Serialize key
314
+ const [key] = serialize(_k);
315
+ if (!key) return;
316
+ const [get, set] = createCacheHelper(cache, key);
317
+ const [EVENT_REVALIDATORS, MUTATION, FETCH, PRELOAD] = SWRGlobalState.get(cache);
318
+ const startRevalidate = ()=>{
319
+ const revalidators = EVENT_REVALIDATORS[key];
320
+ const revalidate = isFunction(options.revalidate) ? options.revalidate(get().data, _k) : options.revalidate !== false;
321
+ if (revalidate) {
322
+ // Invalidate the key by deleting the concurrent request markers so new
323
+ // requests will not be deduped.
324
+ delete FETCH[key];
325
+ delete PRELOAD[key];
326
+ if (revalidators && revalidators[0]) {
327
+ return revalidators[0](MUTATE_EVENT).then(()=>get().data);
328
+ }
329
+ }
330
+ return get().data;
331
+ };
332
+ // If there is no new data provided, revalidate the key with current state.
333
+ if (args.length < 3) {
334
+ // Revalidate and broadcast state.
335
+ return startRevalidate();
336
+ }
337
+ let data = _data;
338
+ let error;
339
+ // Update global timestamps.
340
+ const beforeMutationTs = getTimestamp();
341
+ MUTATION[key] = [
342
+ beforeMutationTs,
343
+ 0
344
+ ];
345
+ const hasOptimisticData = !isUndefined(optimisticData);
346
+ const state = get();
347
+ // `displayedData` is the current value on screen. It could be the optimistic value
348
+ // that is going to be overridden by a `committedData`, or get reverted back.
349
+ // `committedData` is the validated value that comes from a fetch or mutation.
350
+ const displayedData = state.data;
351
+ const currentData = state._c;
352
+ const committedData = isUndefined(currentData) ? displayedData : currentData;
353
+ // Do optimistic data update.
354
+ if (hasOptimisticData) {
355
+ optimisticData = isFunction(optimisticData) ? optimisticData(committedData, displayedData) : optimisticData;
356
+ // When we set optimistic data, backup the current committedData data in `_c`.
357
+ set({
358
+ data: optimisticData,
359
+ _c: committedData
360
+ });
361
+ }
362
+ if (isFunction(data)) {
363
+ // `data` is a function, call it passing current cache value.
364
+ try {
365
+ data = data(committedData);
366
+ } catch (err) {
367
+ // If it throws an error synchronously, we shouldn't update the cache.
368
+ error = err;
369
+ }
370
+ }
371
+ // `data` is a promise/thenable, resolve the final data first.
372
+ if (data && isPromiseLike(data)) {
373
+ // This means that the mutation is async, we need to check timestamps to
374
+ // avoid race conditions.
375
+ data = await data.catch((err)=>{
376
+ error = err;
377
+ });
378
+ // Check if other mutations have occurred since we've started this mutation.
379
+ // If there's a race we don't update cache or broadcast the change,
380
+ // just return the data.
381
+ if (beforeMutationTs !== MUTATION[key][0]) {
382
+ if (error) throw error;
383
+ return data;
384
+ } else if (error && hasOptimisticData && rollbackOnError(error)) {
385
+ // Rollback. Always populate the cache in this case but without
386
+ // transforming the data.
387
+ populateCache = true;
388
+ // Reset data to be the latest committed data, and clear the `_c` value.
389
+ set({
390
+ data: committedData,
391
+ _c: UNDEFINED
392
+ });
393
+ }
394
+ }
395
+ // If we should write back the cache after request.
396
+ if (populateCache) {
397
+ if (!error) {
398
+ // Transform the result into data.
399
+ if (isFunction(populateCache)) {
400
+ const populateCachedData = populateCache(data, committedData);
401
+ set({
402
+ data: populateCachedData,
403
+ error: UNDEFINED,
404
+ _c: UNDEFINED
405
+ });
406
+ } else {
407
+ // Only update cached data and reset the error if there's no error. Data can be `undefined` here.
408
+ set({
409
+ data,
410
+ error: UNDEFINED,
411
+ _c: UNDEFINED
412
+ });
413
+ }
414
+ }
415
+ }
416
+ // Reset the timestamp to mark the mutation has ended.
417
+ MUTATION[key][1] = getTimestamp();
418
+ // Update existing SWR Hooks' internal states:
419
+ Promise.resolve(startRevalidate()).then(()=>{
420
+ // The mutation and revalidation are ended, we can clear it since the data is
421
+ // not an optimistic value anymore.
422
+ set({
423
+ _c: UNDEFINED
424
+ });
425
+ });
426
+ // Throw error or return data
427
+ if (error) {
428
+ if (throwOnError) throw error;
429
+ return;
430
+ }
431
+ return data;
432
+ }
433
+ }
434
+
435
+ const revalidateAllKeys = (revalidators, type)=>{
436
+ for(const key in revalidators){
437
+ if (revalidators[key][0]) revalidators[key][0](type);
438
+ }
439
+ };
440
+ const initCache = (provider, options)=>{
441
+ // The global state for a specific provider will be used to deduplicate
442
+ // requests and store listeners. As well as a mutate function that is bound to
443
+ // the cache.
444
+ // The provider's global state might be already initialized. Let's try to get the
445
+ // global state associated with the provider first.
446
+ if (!SWRGlobalState.has(provider)) {
447
+ const opts = mergeObjects(defaultConfigOptions, options);
448
+ // If there's no global state bound to the provider, create a new one with the
449
+ // new mutate function.
450
+ const EVENT_REVALIDATORS = {};
451
+ const mutate = internalMutate.bind(UNDEFINED, provider);
452
+ let unmount = noop;
453
+ const subscriptions = {};
454
+ const subscribe = (key, callback)=>{
455
+ const subs = subscriptions[key] || [];
456
+ subscriptions[key] = subs;
457
+ subs.push(callback);
458
+ return ()=>subs.splice(subs.indexOf(callback), 1);
459
+ };
460
+ const setter = (key, value, prev)=>{
461
+ provider.set(key, value);
462
+ const subs = subscriptions[key];
463
+ if (subs) {
464
+ for (const fn of subs){
465
+ fn(value, prev);
466
+ }
467
+ }
468
+ };
469
+ const initProvider = ()=>{
470
+ if (!SWRGlobalState.has(provider)) {
471
+ // Update the state if it's new, or if the provider has been extended.
472
+ SWRGlobalState.set(provider, [
473
+ EVENT_REVALIDATORS,
474
+ {},
475
+ {},
476
+ {},
477
+ mutate,
478
+ setter,
479
+ subscribe
480
+ ]);
481
+ if (!IS_SERVER) {
482
+ // When listening to the native events for auto revalidations,
483
+ // we intentionally put a delay (setTimeout) here to make sure they are
484
+ // fired after immediate JavaScript executions, which can be
485
+ // React's state updates.
486
+ // This avoids some unnecessary revalidations such as
487
+ // https://github.com/vercel/swr/issues/1680.
488
+ const releaseFocus = opts.initFocus(setTimeout.bind(UNDEFINED, revalidateAllKeys.bind(UNDEFINED, EVENT_REVALIDATORS, FOCUS_EVENT)));
489
+ const releaseReconnect = opts.initReconnect(setTimeout.bind(UNDEFINED, revalidateAllKeys.bind(UNDEFINED, EVENT_REVALIDATORS, RECONNECT_EVENT)));
490
+ unmount = ()=>{
491
+ releaseFocus && releaseFocus();
492
+ releaseReconnect && releaseReconnect();
493
+ // When un-mounting, we need to remove the cache provider from the state
494
+ // storage too because it's a side-effect. Otherwise, when re-mounting we
495
+ // will not re-register those event listeners.
496
+ SWRGlobalState.delete(provider);
497
+ };
498
+ }
499
+ }
500
+ };
501
+ initProvider();
502
+ // This is a new provider, we need to initialize it and setup DOM events
503
+ // listeners for `focus` and `reconnect` actions.
504
+ // We might want to inject an extra layer on top of `provider` in the future,
505
+ // such as key serialization, auto GC, etc.
506
+ // For now, it's just a `Map` interface without any modifications.
507
+ return [
508
+ provider,
509
+ mutate,
510
+ initProvider,
511
+ unmount
512
+ ];
513
+ }
514
+ return [
515
+ provider,
516
+ SWRGlobalState.get(provider)[4]
517
+ ];
518
+ };
519
+
520
+ // error retry
521
+ const onErrorRetry = (_, __, config, revalidate, opts)=>{
522
+ const maxRetryCount = config.errorRetryCount;
523
+ const currentRetryCount = opts.retryCount;
524
+ // Exponential backoff
525
+ const timeout = ~~((Math.random() + 0.5) * (1 << (currentRetryCount < 8 ? currentRetryCount : 8))) * config.errorRetryInterval;
526
+ if (!isUndefined(maxRetryCount) && currentRetryCount > maxRetryCount) {
527
+ return;
528
+ }
529
+ setTimeout(revalidate, timeout, opts);
530
+ };
531
+ const compare = (currentData, newData)=>stableHash(currentData) == stableHash(newData);
532
+ // Default cache provider
533
+ const [cache, mutate] = initCache(new Map());
534
+ // Default config
535
+ const defaultConfig = mergeObjects({
536
+ // events
537
+ onLoadingSlow: noop,
538
+ onSuccess: noop,
539
+ onError: noop,
540
+ onErrorRetry,
541
+ onDiscarded: noop,
542
+ // switches
543
+ revalidateOnFocus: true,
544
+ revalidateOnReconnect: true,
545
+ revalidateIfStale: true,
546
+ shouldRetryOnError: true,
547
+ // timeouts
548
+ errorRetryInterval: slowConnection ? 10000 : 5000,
549
+ focusThrottleInterval: 5 * 1000,
550
+ dedupingInterval: 2 * 1000,
551
+ loadingTimeout: slowConnection ? 5000 : 3000,
552
+ // providers
553
+ compare,
554
+ isPaused: ()=>false,
555
+ cache,
556
+ mutate,
557
+ fallback: {}
558
+ }, // use web preset by default
559
+ preset);
560
+
561
+ const mergeConfigs = (a, b)=>{
562
+ // Need to create a new object to avoid mutating the original here.
563
+ const v = mergeObjects(a, b);
564
+ // If two configs are provided, merge their `use` and `fallback` options.
565
+ if (b) {
566
+ const { use: u1, fallback: f1 } = a;
567
+ const { use: u2, fallback: f2 } = b;
568
+ if (u1 && u2) {
569
+ v.use = u1.concat(u2);
570
+ }
571
+ if (f1 && f2) {
572
+ v.fallback = mergeObjects(f1, f2);
573
+ }
574
+ }
575
+ return v;
576
+ };
577
+
578
+ const SWRConfigContext = (0,react__WEBPACK_IMPORTED_MODULE_0__.createContext)({});
579
+ const SWRConfig = (props)=>{
580
+ const { value } = props;
581
+ const parentConfig = (0,react__WEBPACK_IMPORTED_MODULE_0__.useContext)(SWRConfigContext);
582
+ const isFunctionalConfig = isFunction(value);
583
+ const config = (0,react__WEBPACK_IMPORTED_MODULE_0__.useMemo)(()=>isFunctionalConfig ? value(parentConfig) : value, [
584
+ isFunctionalConfig,
585
+ parentConfig,
586
+ value
587
+ ]);
588
+ // Extend parent context values and middleware.
589
+ const extendedConfig = (0,react__WEBPACK_IMPORTED_MODULE_0__.useMemo)(()=>isFunctionalConfig ? config : mergeConfigs(parentConfig, config), [
590
+ isFunctionalConfig,
591
+ parentConfig,
592
+ config
593
+ ]);
594
+ // Should not use the inherited provider.
595
+ const provider = config && config.provider;
596
+ // initialize the cache only on first access.
597
+ const cacheContextRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(UNDEFINED);
598
+ if (provider && !cacheContextRef.current) {
599
+ cacheContextRef.current = initCache(provider(extendedConfig.cache || cache), config);
600
+ }
601
+ const cacheContext = cacheContextRef.current;
602
+ // Override the cache if a new provider is given.
603
+ if (cacheContext) {
604
+ extendedConfig.cache = cacheContext[0];
605
+ extendedConfig.mutate = cacheContext[1];
606
+ }
607
+ // Unsubscribe events.
608
+ useIsomorphicLayoutEffect(()=>{
609
+ if (cacheContext) {
610
+ cacheContext[2] && cacheContext[2]();
611
+ return cacheContext[3];
612
+ }
613
+ }, []);
614
+ return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(SWRConfigContext.Provider, mergeObjects(props, {
615
+ value: extendedConfig
616
+ }));
617
+ };
618
+
619
+ const INFINITE_PREFIX = '$inf$';
620
+
621
+ // @ts-expect-error
622
+ const enableDevtools = isWindowDefined && window.__SWR_DEVTOOLS_USE__;
623
+ const use = enableDevtools ? window.__SWR_DEVTOOLS_USE__ : [];
624
+ const setupDevTools = ()=>{
625
+ if (enableDevtools) {
626
+ // @ts-expect-error
627
+ window.__SWR_DEVTOOLS_REACT__ = react__WEBPACK_IMPORTED_MODULE_0__;
628
+ }
629
+ };
630
+
631
+ const normalize = (args)=>{
632
+ return isFunction(args[1]) ? [
633
+ args[0],
634
+ args[1],
635
+ args[2] || {}
636
+ ] : [
637
+ args[0],
638
+ null,
639
+ (args[1] === null ? args[2] : args[1]) || {}
640
+ ];
641
+ };
642
+
643
+ const useSWRConfig = ()=>{
644
+ return mergeObjects(defaultConfig, (0,react__WEBPACK_IMPORTED_MODULE_0__.useContext)(SWRConfigContext));
645
+ };
646
+
647
+ const preload = (key_, fetcher)=>{
648
+ const [key, fnArg] = serialize(key_);
649
+ const [, , , PRELOAD] = SWRGlobalState.get(cache);
650
+ // Prevent preload to be called multiple times before used.
651
+ if (PRELOAD[key]) return PRELOAD[key];
652
+ const req = fetcher(fnArg);
653
+ PRELOAD[key] = req;
654
+ return req;
655
+ };
656
+ const middleware = (useSWRNext)=>(key_, fetcher_, config)=>{
657
+ // fetcher might be a sync function, so this should not be an async function
658
+ const fetcher = fetcher_ && ((...args)=>{
659
+ const [key] = serialize(key_);
660
+ const [, , , PRELOAD] = SWRGlobalState.get(cache);
661
+ if (key.startsWith(INFINITE_PREFIX)) {
662
+ // we want the infinite fetcher to be called.
663
+ // handling of the PRELOAD cache happens there.
664
+ return fetcher_(...args);
665
+ }
666
+ const req = PRELOAD[key];
667
+ if (isUndefined(req)) return fetcher_(...args);
668
+ delete PRELOAD[key];
669
+ return req;
670
+ });
671
+ return useSWRNext(key_, fetcher, config);
672
+ };
673
+
674
+ const BUILT_IN_MIDDLEWARE = use.concat(middleware);
675
+
676
+ // It's tricky to pass generic types as parameters, so we just directly override
677
+ // the types here.
678
+ const withArgs = (hook)=>{
679
+ return function useSWRArgs(...args) {
680
+ // Get the default and inherited configuration.
681
+ const fallbackConfig = useSWRConfig();
682
+ // Normalize arguments.
683
+ const [key, fn, _config] = normalize(args);
684
+ // Merge configurations.
685
+ const config = mergeConfigs(fallbackConfig, _config);
686
+ // Apply middleware
687
+ let next = hook;
688
+ const { use } = config;
689
+ const middleware = (use || []).concat(BUILT_IN_MIDDLEWARE);
690
+ for(let i = middleware.length; i--;){
691
+ next = middleware[i](next);
692
+ }
693
+ return next(key, fn || config.fetcher || null, config);
694
+ };
695
+ };
696
+
697
+ // Add a callback function to a list of keyed callback functions and return
698
+ // the unsubscribe function.
699
+ const subscribeCallback = (key, callbacks, callback)=>{
700
+ const keyedRevalidators = callbacks[key] || (callbacks[key] = []);
701
+ keyedRevalidators.push(callback);
702
+ return ()=>{
703
+ const index = keyedRevalidators.indexOf(callback);
704
+ if (index >= 0) {
705
+ // O(1): faster than splice
706
+ keyedRevalidators[index] = keyedRevalidators[keyedRevalidators.length - 1];
707
+ keyedRevalidators.pop();
708
+ }
709
+ };
710
+ };
711
+
712
+ // Create a custom hook with a middleware
713
+ const withMiddleware = (useSWR, middleware)=>{
714
+ return (...args)=>{
715
+ const [key, fn, config] = normalize(args);
716
+ const uses = (config.use || []).concat(middleware);
717
+ return useSWR(key, fn, {
718
+ ...config,
719
+ use: uses
720
+ });
721
+ };
722
+ };
723
+
724
+ setupDevTools();
725
+
726
+
727
+
728
+
729
+ /***/ })
730
+
731
+ }]);
732
+ //# sourceMappingURL=vendors-node_modules_swr_dist__internal_index_mjs.js.map