@elice/material-shared-utils 1.251120.1 → 1.260128.0-rc.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 (102) hide show
  1. package/cjs/_virtual/_rollupPluginBabelHelpers.js +177 -376
  2. package/cjs/_virtual/index.js +5 -0
  3. package/cjs/_virtual/use-sync-external-store-shim.production.js +5 -0
  4. package/cjs/hooks/useHelpyLogo.js +3 -7
  5. package/cjs/index.js +4 -4
  6. package/cjs/material-config/MaterialConfigContext.d.ts +0 -1
  7. package/cjs/material-config/MaterialConfigContext.js +2 -2
  8. package/cjs/material-fetch/useMaterialFetch.d.ts +2 -47
  9. package/cjs/material-fetch/useMaterialFetch.js +1 -4
  10. package/cjs/material-fetch/useMaterialFetchRaw.d.ts +1 -1
  11. package/cjs/material-fetch/useMaterialFetchRaw.js +12 -19
  12. package/cjs/material-hoc/withMaterial.d.ts +1 -1
  13. package/cjs/material-hoc/withMaterial.js +0 -1
  14. package/cjs/node_modules/@tanstack/query-core/build/lib/focusManager.js +93 -0
  15. package/cjs/node_modules/@tanstack/query-core/build/lib/notifyManager.js +101 -0
  16. package/cjs/node_modules/@tanstack/query-core/build/lib/onlineManager.js +95 -0
  17. package/cjs/node_modules/@tanstack/query-core/build/lib/queryObserver.js +571 -0
  18. package/cjs/node_modules/@tanstack/query-core/build/lib/retryer.js +21 -0
  19. package/cjs/node_modules/@tanstack/query-core/build/lib/subscribable.js +33 -0
  20. package/cjs/node_modules/@tanstack/query-core/build/lib/utils.js +154 -0
  21. package/cjs/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.js +65 -0
  22. package/cjs/node_modules/@tanstack/react-query/build/lib/QueryErrorResetBoundary.js +46 -0
  23. package/cjs/node_modules/@tanstack/react-query/build/lib/errorBoundaryUtils.js +52 -0
  24. package/cjs/node_modules/@tanstack/react-query/build/lib/isRestoring.js +31 -0
  25. package/cjs/node_modules/@tanstack/react-query/build/lib/suspense.js +39 -0
  26. package/cjs/node_modules/@tanstack/react-query/build/lib/useBaseQuery.js +94 -0
  27. package/cjs/node_modules/@tanstack/react-query/build/lib/useQuery.js +14 -0
  28. package/cjs/node_modules/@tanstack/react-query/build/lib/useSyncExternalStore.js +9 -0
  29. package/cjs/node_modules/@tanstack/react-query/build/lib/utils.js +12 -0
  30. package/cjs/node_modules/rxjs/dist/esm5/internal/BehaviorSubject.js +39 -0
  31. package/cjs/node_modules/rxjs/dist/esm5/internal/Observable.js +105 -0
  32. package/cjs/node_modules/rxjs/dist/esm5/internal/Subject.js +165 -0
  33. package/cjs/node_modules/rxjs/dist/esm5/internal/Subscriber.js +157 -0
  34. package/cjs/node_modules/rxjs/dist/esm5/internal/Subscription.js +148 -0
  35. package/cjs/node_modules/rxjs/dist/esm5/internal/config.js +6 -0
  36. package/cjs/node_modules/rxjs/dist/esm5/internal/scheduler/timeoutProvider.js +19 -0
  37. package/cjs/node_modules/rxjs/dist/esm5/internal/symbol/observable.js +5 -0
  38. package/cjs/node_modules/rxjs/dist/esm5/internal/util/ObjectUnsubscribedError.js +13 -0
  39. package/cjs/node_modules/rxjs/dist/esm5/internal/util/UnsubscriptionError.js +16 -0
  40. package/cjs/node_modules/rxjs/dist/esm5/internal/util/arrRemove.js +10 -0
  41. package/cjs/node_modules/rxjs/dist/esm5/internal/util/createErrorClass.js +14 -0
  42. package/cjs/node_modules/rxjs/dist/esm5/internal/util/errorContext.js +9 -0
  43. package/cjs/node_modules/rxjs/dist/esm5/internal/util/identity.js +7 -0
  44. package/cjs/node_modules/rxjs/dist/esm5/internal/util/isFunction.js +7 -0
  45. package/cjs/node_modules/rxjs/dist/esm5/internal/util/noop.js +5 -0
  46. package/cjs/node_modules/rxjs/dist/esm5/internal/util/pipe.js +17 -0
  47. package/cjs/node_modules/rxjs/dist/esm5/internal/util/reportUnhandledError.js +13 -0
  48. package/cjs/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +77 -0
  49. package/cjs/node_modules/use-sync-external-store/shim/index.js +13 -0
  50. package/es/_virtual/_rollupPluginBabelHelpers.js +176 -376
  51. package/es/_virtual/index.js +3 -0
  52. package/es/_virtual/use-sync-external-store-shim.production.js +3 -0
  53. package/es/hooks/useCallbackProp.js +3 -3
  54. package/es/hooks/useDeepClonedCompareEffect.js +2 -2
  55. package/es/hooks/useHelpyLogo.js +2 -6
  56. package/es/index.js +2 -2
  57. package/es/material-config/MaterialConfigContext.d.ts +0 -1
  58. package/es/material-config/MaterialConfigContext.js +1 -1
  59. package/es/material-config/MaterialConfigProvider.js +5 -5
  60. package/es/material-fetch/useMaterialFetch.d.ts +2 -47
  61. package/es/material-fetch/useMaterialFetch.js +1 -4
  62. package/es/material-fetch/useMaterialFetchRaw.d.ts +1 -1
  63. package/es/material-fetch/useMaterialFetchRaw.js +13 -20
  64. package/es/material-hoc/withMaterial.d.ts +1 -1
  65. package/es/material-hoc/withMaterial.js +0 -1
  66. package/es/node_modules/@tanstack/query-core/build/lib/focusManager.js +90 -0
  67. package/es/node_modules/@tanstack/query-core/build/lib/notifyManager.js +98 -0
  68. package/es/node_modules/@tanstack/query-core/build/lib/onlineManager.js +92 -0
  69. package/es/node_modules/@tanstack/query-core/build/lib/queryObserver.js +569 -0
  70. package/es/node_modules/@tanstack/query-core/build/lib/retryer.js +17 -0
  71. package/es/node_modules/@tanstack/query-core/build/lib/subscribable.js +31 -0
  72. package/es/node_modules/@tanstack/query-core/build/lib/utils.js +140 -0
  73. package/es/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.js +42 -0
  74. package/es/node_modules/@tanstack/react-query/build/lib/QueryErrorResetBoundary.js +24 -0
  75. package/es/node_modules/@tanstack/react-query/build/lib/errorBoundaryUtils.js +28 -0
  76. package/es/node_modules/@tanstack/react-query/build/lib/isRestoring.js +9 -0
  77. package/es/node_modules/@tanstack/react-query/build/lib/suspense.js +34 -0
  78. package/es/node_modules/@tanstack/react-query/build/lib/useBaseQuery.js +72 -0
  79. package/es/node_modules/@tanstack/react-query/build/lib/useQuery.js +12 -0
  80. package/es/node_modules/@tanstack/react-query/build/lib/useSyncExternalStore.js +7 -0
  81. package/es/node_modules/@tanstack/react-query/build/lib/utils.js +10 -0
  82. package/es/node_modules/rxjs/dist/esm5/internal/BehaviorSubject.js +37 -0
  83. package/es/node_modules/rxjs/dist/esm5/internal/Observable.js +103 -0
  84. package/es/node_modules/rxjs/dist/esm5/internal/Subject.js +162 -0
  85. package/es/node_modules/rxjs/dist/esm5/internal/Subscriber.js +153 -0
  86. package/es/node_modules/rxjs/dist/esm5/internal/Subscription.js +144 -0
  87. package/es/node_modules/rxjs/dist/esm5/internal/config.js +4 -0
  88. package/es/node_modules/rxjs/dist/esm5/internal/scheduler/timeoutProvider.js +17 -0
  89. package/es/node_modules/rxjs/dist/esm5/internal/symbol/observable.js +3 -0
  90. package/es/node_modules/rxjs/dist/esm5/internal/util/ObjectUnsubscribedError.js +11 -0
  91. package/es/node_modules/rxjs/dist/esm5/internal/util/UnsubscriptionError.js +14 -0
  92. package/es/node_modules/rxjs/dist/esm5/internal/util/arrRemove.js +8 -0
  93. package/es/node_modules/rxjs/dist/esm5/internal/util/createErrorClass.js +12 -0
  94. package/es/node_modules/rxjs/dist/esm5/internal/util/errorContext.js +7 -0
  95. package/es/node_modules/rxjs/dist/esm5/internal/util/identity.js +5 -0
  96. package/es/node_modules/rxjs/dist/esm5/internal/util/isFunction.js +5 -0
  97. package/es/node_modules/rxjs/dist/esm5/internal/util/noop.js +3 -0
  98. package/es/node_modules/rxjs/dist/esm5/internal/util/pipe.js +15 -0
  99. package/es/node_modules/rxjs/dist/esm5/internal/util/reportUnhandledError.js +11 -0
  100. package/es/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +69 -0
  101. package/es/node_modules/use-sync-external-store/shim/index.js +11 -0
  102. package/package.json +6 -4
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { BehaviorSubject } from 'rxjs';
3
2
  export type MaterialConfigSessionKey = null | string;
4
3
  export interface MaterialConfig {
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var React = require('react');
4
- var rxjs = require('rxjs');
4
+ var BehaviorSubject = require('../node_modules/rxjs/dist/esm5/internal/BehaviorSubject.js');
5
5
 
6
6
  var MaterialConfigContext = React.createContext(null);
7
- var sessionKeySubject$ = new rxjs.BehaviorSubject(null);
7
+ var sessionKeySubject$ = new BehaviorSubject.BehaviorSubject(null);
8
8
 
9
9
  exports.MaterialConfigContext = MaterialConfigContext;
10
10
  exports.sessionKeySubject$ = sessionKeySubject$;
@@ -21,54 +21,9 @@ type FetchClientInitializer = (config: EliceApiClientConfigs) => void;
21
21
  * );
22
22
  */
23
23
  export declare const useMaterialFetch: <MT extends enums.LectureMaterialType, R extends Record<FetchKeyMap[MT], Record<string, any>> = Record<FetchKeyMap[MT], Record<string, any>>>(materialType: MT, materialFetchFn: (signal?: AbortSignal) => Promise<EliceApiResponse<R>>, init: FetchClientInitializer) => Record<FetchKeyMap[MT], R[FetchKeyMap[MT]] | null> & {
24
- materialLecturePage: {
25
- isDisplayScore: boolean | null;
26
- certificateDescription: string | null;
27
- certificateFileUrl: string | null;
28
- certificateTitle: string | null;
29
- closeDatetime: number | null;
30
- closeScheduleDatetime: number | null;
31
- courseId: number;
32
- createdDatetime: number;
33
- completionType: enums.LecturePageCompletionType | null;
34
- id: number;
35
- isCertificateEnabled: boolean;
36
- isCompleted: boolean;
37
- isEnrolledStudentResponded: boolean;
38
- isForStats: boolean;
39
- isGraded: boolean;
40
- isLibraryInstance: boolean;
41
- isOpened: boolean;
42
- isResponded: boolean;
43
- lectureGroupType: enums.LectureGroupType | null;
44
- lectureId: number;
45
- libraryInfo: any;
46
- mainOrderNo: number;
47
- materialId: number;
48
- materialKey: string;
49
- materialType: enums.LectureMaterialType;
50
- materialErn: string | null;
51
- modifiedDatetime: number;
52
- openScheduleDatetime: number | null;
53
- originCourse: {
54
- id: number;
55
- title: string;
56
- organization: {
57
- id: number;
58
- name: string;
59
- nameShort: string;
60
- };
61
- } | null;
62
- originLecturePageId: number | null;
63
- point: number;
64
- score: number;
65
- subLecturePageIds: number[];
66
- subOrderNo: number | null;
67
- taglist: string[];
68
- title: string;
69
- } | null;
24
+ materialLecturePage: import("@elice/types").GetOrgLecturePageGetResponses["lecturePage"] | null;
70
25
  } & {
71
26
  status: import("@elice/material-shared-types").APIStatus;
72
- refetch: (signal?: AbortSignal | undefined) => Promise<void>;
27
+ refetch: (signal?: AbortSignal) => Promise<void>;
73
28
  };
74
29
  export {};
@@ -1,10 +1,7 @@
1
1
  'use strict';
2
2
 
3
- require('react/jsx-runtime');
4
- require('react');
5
- require('../material-config/MaterialConfigContext.js');
6
- var useMaterialConfigApiClientUpdate = require('../material-config/useMaterialConfigApiClientUpdate.js');
7
3
  var useMaterialFetchRaw = require('./useMaterialFetchRaw.js');
4
+ var useMaterialConfigApiClientUpdate = require('../material-config/useMaterialConfigApiClientUpdate.js');
8
5
 
9
6
  //
10
7
  //
@@ -38,7 +38,7 @@ export interface FetchKeyMap {
38
38
  * );
39
39
  */
40
40
  export declare const useMaterialFetchRaw: <MT extends enums.LectureMaterialType, R extends Record<FetchKeyMap[MT], Record<string, any>> = Record<FetchKeyMap[MT], Record<string, any>>>(materialType: MT, materialFetchFn: (signal?: AbortSignal) => Promise<EliceApiResponse<R>>, isReady?: boolean) => Record<FetchKeyMap[MT], R[FetchKeyMap[MT]] | null> & {
41
- materialLecturePage: GetOrgLecturePageGetResponses['lecturePage'] | null;
41
+ materialLecturePage: GetOrgLecturePageGetResponses["lecturePage"] | null;
42
42
  } & {
43
43
  status: APIStatus;
44
44
  refetch: (signal?: AbortSignal) => Promise<void>;
@@ -6,7 +6,7 @@ var apiClient = require('@elice/api-client');
6
6
  var types = require('@elice/types');
7
7
 
8
8
  var _Object$freeze;
9
- var MATERIAL_FETCH_KEY_MAP = Object.freeze((_Object$freeze = {}, _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.Nothing, 'materialNothing'), _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.Note, 'materialNote'), _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.Video, 'materialVideo'), _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.PDF, 'materialPdf'), _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.Exercise, 'materialExercise'), _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.Quiz, 'materialQuiz'), _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.LegacyRunbox, 'materialLegacyRunbox'), _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.VideoFile, 'materialVideoFile'), _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.Live, 'materialLive'), _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.Assignment, 'materialAssignment'), _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.LMSPublicContent, 'materialLmsPublicContent'), _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.External, 'materialExternal'), _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.Survey, 'materialSurvey'), _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.Runbox, 'materialRunbox'), _rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.Cloud, 'materialCloud'), _Object$freeze));
9
+ var MATERIAL_FETCH_KEY_MAP = Object.freeze((_Object$freeze = {}, _rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.Nothing, 'materialNothing'), types.enums.LectureMaterialType.Note, 'materialNote'), types.enums.LectureMaterialType.Video, 'materialVideo'), types.enums.LectureMaterialType.PDF, 'materialPdf'), types.enums.LectureMaterialType.Exercise, 'materialExercise'), types.enums.LectureMaterialType.Quiz, 'materialQuiz'), types.enums.LectureMaterialType.LegacyRunbox, 'materialLegacyRunbox'), types.enums.LectureMaterialType.VideoFile, 'materialVideoFile'), types.enums.LectureMaterialType.Live, 'materialLive'), types.enums.LectureMaterialType.Assignment, 'materialAssignment'), _rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty(_Object$freeze, types.enums.LectureMaterialType.LMSPublicContent, 'materialLmsPublicContent'), types.enums.LectureMaterialType.External, 'materialExternal'), types.enums.LectureMaterialType.Survey, 'materialSurvey'), types.enums.LectureMaterialType.Runbox, 'materialRunbox'), types.enums.LectureMaterialType.Cloud, 'materialCloud')));
10
10
  //
11
11
  //
12
12
  //
@@ -33,8 +33,7 @@ var useMaterialFetchRaw = function useMaterialFetchRaw(materialType, materialFet
33
33
  var _return = React.useRef({});
34
34
  var materialKey = MATERIAL_FETCH_KEY_MAP[materialType];
35
35
  var _createEmptyFetchRes = function _createEmptyFetchRes() {
36
- var _ref;
37
- return _ref = {}, _rollupPluginBabelHelpers.defineProperty(_ref, materialKey, null), _rollupPluginBabelHelpers.defineProperty(_ref, "materialLecturePage", null), _ref;
36
+ return _rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty({}, materialKey, null), "materialLecturePage", null);
38
37
  };
39
38
  var _useState = React.useState(_createEmptyFetchRes),
40
39
  _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
@@ -47,16 +46,16 @@ var useMaterialFetchRaw = function useMaterialFetchRaw(materialType, materialFet
47
46
  /**
48
47
  * fetch material and lecture page
49
48
  */
50
- var fetch = React.useCallback( /*#__PURE__*/function () {
51
- var _ref2 = _rollupPluginBabelHelpers.asyncToGenerator( /*#__PURE__*/_rollupPluginBabelHelpers.regeneratorRuntime().mark(function _callee(signal) {
52
- return _rollupPluginBabelHelpers.regeneratorRuntime().wrap(function _callee$(_context) {
53
- while (1) switch (_context.prev = _context.next) {
49
+ var fetch = React.useCallback(/*#__PURE__*/function () {
50
+ var _ref2 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee(signal) {
51
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context) {
52
+ while (1) switch (_context.n) {
54
53
  case 0:
55
54
  setMatFetchStatus('pending');
56
- return _context.abrupt("return", materialFetchFn(signal).then(function (resMaterialGet) {
55
+ return _context.a(2, materialFetchFn(signal).then(function (resMaterialGet) {
57
56
  return resMaterialGet[materialKey];
58
57
  }).then(function (material) {
59
- return Promise.all([material, apiClient.getOrgLecturePageResolve({
58
+ return Promise.all([Promise.resolve(material), apiClient.getOrgLecturePageResolve({
60
59
  materialId: material.id,
61
60
  materialType: materialType
62
61
  }, {
@@ -71,21 +70,17 @@ var useMaterialFetchRaw = function useMaterialFetchRaw(materialType, materialFet
71
70
  return resLecturePageGet.lecturePage;
72
71
  })]);
73
72
  }).then(function (_ref3) {
74
- var _setMatFetchRes;
75
73
  var _ref4 = _rollupPluginBabelHelpers.slicedToArray(_ref3, 2),
76
74
  material = _ref4[0],
77
75
  materialLecturePage = _ref4[1];
78
- setMatFetchRes((_setMatFetchRes = {}, _rollupPluginBabelHelpers.defineProperty(_setMatFetchRes, materialKey, material), _rollupPluginBabelHelpers.defineProperty(_setMatFetchRes, "materialLecturePage", materialLecturePage), _setMatFetchRes));
76
+ setMatFetchRes(_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty({}, materialKey, material), "materialLecturePage", materialLecturePage));
79
77
  setMatFetchStatus('resolved');
80
- }).catch(function (err) {
78
+ })["catch"](function (err) {
81
79
  if (err.name !== 'AbortError') {
82
80
  setMatFetchRes(_createEmptyFetchRes);
83
81
  setMatFetchStatus('rejected');
84
82
  }
85
83
  }));
86
- case 2:
87
- case "end":
88
- return _context.stop();
89
84
  }
90
85
  }, _callee);
91
86
  }));
@@ -103,15 +98,13 @@ var useMaterialFetchRaw = function useMaterialFetchRaw(materialType, materialFet
103
98
  return;
104
99
  }
105
100
  var abortCtrl = new AbortController();
106
- fetch(abortCtrl.signal).catch(function () {
101
+ fetch(abortCtrl.signal)["catch"](function () {
107
102
  return void 0;
108
103
  });
109
104
  return function () {
110
105
  abortCtrl.abort();
111
106
  };
112
- },
113
- // eslint-disable-next-line react-hooks/exhaustive-deps
114
- [isReady, fetch]);
107
+ }, [isReady, fetch]);
115
108
  //
116
109
  //
117
110
  //
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import type React from 'react';
2
2
  import type { MaterialConfigApiClientUpdateCallback } from '../material-config';
3
3
  type AnyObject = Record<string, any>;
4
4
  /**
@@ -4,7 +4,6 @@ var jsxRuntime = require('react/jsx-runtime');
4
4
  var React = require('react');
5
5
  var blocks = require('@elice/blocks');
6
6
  var recoil = require('recoil');
7
- require('../material-config/MaterialConfigContext.js');
8
7
  var useMaterialConfigApiClientUpdate = require('../material-config/useMaterialConfigApiClientUpdate.js');
9
8
 
10
9
  //
@@ -0,0 +1,93 @@
1
+ 'use strict';
2
+
3
+ var subscribable = require('./subscribable.js');
4
+ var utils = require('./utils.js');
5
+
6
+ class FocusManager extends subscribable.Subscribable {
7
+ constructor() {
8
+ super();
9
+
10
+ this.setup = onFocus => {
11
+ // addEventListener does not exist in React Native, but window does
12
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
13
+ if (!utils.isServer && window.addEventListener) {
14
+ const listener = () => onFocus(); // Listen to visibillitychange and focus
15
+
16
+
17
+ window.addEventListener('visibilitychange', listener, false);
18
+ window.addEventListener('focus', listener, false);
19
+ return () => {
20
+ // Be sure to unsubscribe if a new handler is set
21
+ window.removeEventListener('visibilitychange', listener);
22
+ window.removeEventListener('focus', listener);
23
+ };
24
+ }
25
+
26
+ return;
27
+ };
28
+ }
29
+
30
+ onSubscribe() {
31
+ if (!this.cleanup) {
32
+ this.setEventListener(this.setup);
33
+ }
34
+ }
35
+
36
+ onUnsubscribe() {
37
+ if (!this.hasListeners()) {
38
+ var _this$cleanup;
39
+
40
+ (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
41
+ this.cleanup = undefined;
42
+ }
43
+ }
44
+
45
+ setEventListener(setup) {
46
+ var _this$cleanup2;
47
+
48
+ this.setup = setup;
49
+ (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
50
+ this.cleanup = setup(focused => {
51
+ if (typeof focused === 'boolean') {
52
+ this.setFocused(focused);
53
+ } else {
54
+ this.onFocus();
55
+ }
56
+ });
57
+ }
58
+
59
+ setFocused(focused) {
60
+ const changed = this.focused !== focused;
61
+
62
+ if (changed) {
63
+ this.focused = focused;
64
+ this.onFocus();
65
+ }
66
+ }
67
+
68
+ onFocus() {
69
+ this.listeners.forEach(({
70
+ listener
71
+ }) => {
72
+ listener();
73
+ });
74
+ }
75
+
76
+ isFocused() {
77
+ if (typeof this.focused === 'boolean') {
78
+ return this.focused;
79
+ } // document global can be unavailable in react native
80
+
81
+
82
+ if (typeof document === 'undefined') {
83
+ return true;
84
+ }
85
+
86
+ return [undefined, 'visible', 'prerender'].includes(document.visibilityState);
87
+ }
88
+
89
+ }
90
+ const focusManager = new FocusManager();
91
+
92
+ exports.FocusManager = FocusManager;
93
+ exports.focusManager = focusManager;
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ var utils = require('./utils.js');
4
+
5
+ function createNotifyManager() {
6
+ let queue = [];
7
+ let transactions = 0;
8
+
9
+ let notifyFn = callback => {
10
+ callback();
11
+ };
12
+
13
+ let batchNotifyFn = callback => {
14
+ callback();
15
+ };
16
+
17
+ const batch = callback => {
18
+ let result;
19
+ transactions++;
20
+
21
+ try {
22
+ result = callback();
23
+ } finally {
24
+ transactions--;
25
+
26
+ if (!transactions) {
27
+ flush();
28
+ }
29
+ }
30
+
31
+ return result;
32
+ };
33
+
34
+ const schedule = callback => {
35
+ if (transactions) {
36
+ queue.push(callback);
37
+ } else {
38
+ utils.scheduleMicrotask(() => {
39
+ notifyFn(callback);
40
+ });
41
+ }
42
+ };
43
+ /**
44
+ * All calls to the wrapped function will be batched.
45
+ */
46
+
47
+
48
+ const batchCalls = callback => {
49
+ return (...args) => {
50
+ schedule(() => {
51
+ callback(...args);
52
+ });
53
+ };
54
+ };
55
+
56
+ const flush = () => {
57
+ const originalQueue = queue;
58
+ queue = [];
59
+
60
+ if (originalQueue.length) {
61
+ utils.scheduleMicrotask(() => {
62
+ batchNotifyFn(() => {
63
+ originalQueue.forEach(callback => {
64
+ notifyFn(callback);
65
+ });
66
+ });
67
+ });
68
+ }
69
+ };
70
+ /**
71
+ * Use this method to set a custom notify function.
72
+ * This can be used to for example wrap notifications with `React.act` while running tests.
73
+ */
74
+
75
+
76
+ const setNotifyFunction = fn => {
77
+ notifyFn = fn;
78
+ };
79
+ /**
80
+ * Use this method to set a custom function to batch notifications together into a single tick.
81
+ * By default React Query will use the batch function provided by ReactDOM or React Native.
82
+ */
83
+
84
+
85
+ const setBatchNotifyFunction = fn => {
86
+ batchNotifyFn = fn;
87
+ };
88
+
89
+ return {
90
+ batch,
91
+ batchCalls,
92
+ schedule,
93
+ setNotifyFunction,
94
+ setBatchNotifyFunction
95
+ };
96
+ } // SINGLETON
97
+
98
+ const notifyManager = createNotifyManager();
99
+
100
+ exports.createNotifyManager = createNotifyManager;
101
+ exports.notifyManager = notifyManager;
@@ -0,0 +1,95 @@
1
+ 'use strict';
2
+
3
+ var subscribable = require('./subscribable.js');
4
+ var utils = require('./utils.js');
5
+
6
+ const onlineEvents = ['online', 'offline'];
7
+ class OnlineManager extends subscribable.Subscribable {
8
+ constructor() {
9
+ super();
10
+
11
+ this.setup = onOnline => {
12
+ // addEventListener does not exist in React Native, but window does
13
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
14
+ if (!utils.isServer && window.addEventListener) {
15
+ const listener = () => onOnline(); // Listen to online
16
+
17
+
18
+ onlineEvents.forEach(event => {
19
+ window.addEventListener(event, listener, false);
20
+ });
21
+ return () => {
22
+ // Be sure to unsubscribe if a new handler is set
23
+ onlineEvents.forEach(event => {
24
+ window.removeEventListener(event, listener);
25
+ });
26
+ };
27
+ }
28
+
29
+ return;
30
+ };
31
+ }
32
+
33
+ onSubscribe() {
34
+ if (!this.cleanup) {
35
+ this.setEventListener(this.setup);
36
+ }
37
+ }
38
+
39
+ onUnsubscribe() {
40
+ if (!this.hasListeners()) {
41
+ var _this$cleanup;
42
+
43
+ (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
44
+ this.cleanup = undefined;
45
+ }
46
+ }
47
+
48
+ setEventListener(setup) {
49
+ var _this$cleanup2;
50
+
51
+ this.setup = setup;
52
+ (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
53
+ this.cleanup = setup(online => {
54
+ if (typeof online === 'boolean') {
55
+ this.setOnline(online);
56
+ } else {
57
+ this.onOnline();
58
+ }
59
+ });
60
+ }
61
+
62
+ setOnline(online) {
63
+ const changed = this.online !== online;
64
+
65
+ if (changed) {
66
+ this.online = online;
67
+ this.onOnline();
68
+ }
69
+ }
70
+
71
+ onOnline() {
72
+ this.listeners.forEach(({
73
+ listener
74
+ }) => {
75
+ listener();
76
+ });
77
+ }
78
+
79
+ isOnline() {
80
+ if (typeof this.online === 'boolean') {
81
+ return this.online;
82
+ }
83
+
84
+ if (typeof navigator === 'undefined' || typeof navigator.onLine === 'undefined') {
85
+ return true;
86
+ }
87
+
88
+ return navigator.onLine;
89
+ }
90
+
91
+ }
92
+ const onlineManager = new OnlineManager();
93
+
94
+ exports.OnlineManager = OnlineManager;
95
+ exports.onlineManager = onlineManager;