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