@elice/material-shared-utils 1.240718.0-trasncript.1 → 1.240718.0-trasncript.2
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 +414 -0
- package/cjs/hooks/index.js +9 -0
- package/cjs/hooks/useCallbackProp.js +7 -3
- package/cjs/hooks/useDeepClonedCompareEffect.js +8 -4
- package/cjs/index.d.ts +0 -1
- package/cjs/index.js +0 -2
- package/cjs/material-config/MaterialConfigContext.js +2 -2
- package/cjs/material-config/MaterialConfigProvider.js +31 -17
- package/cjs/material-config/index.js +13 -0
- package/cjs/material-config/useMaterialConfig.js +2 -2
- package/cjs/material-config/useMaterialConfigApiClientUpdate.js +8 -4
- package/cjs/material-fetch/index.js +9 -0
- package/cjs/material-fetch/useMaterialFetch.d.ts +1 -1
- package/cjs/material-fetch/useMaterialFetch.js +3 -2
- package/cjs/material-fetch/useMaterialFetchRaw.js +71 -54
- package/cjs/material-hoc/index.js +8 -0
- package/cjs/material-hoc/withMaterial.d.ts +2 -13
- package/cjs/material-hoc/withMaterial.js +31 -31
- package/es/_virtual/_rollupPluginBabelHelpers.js +402 -0
- package/es/hooks/index.js +2 -0
- package/es/hooks/useCallbackProp.js +3 -3
- package/es/hooks/useDeepClonedCompareEffect.js +4 -4
- package/es/index.d.ts +0 -1
- package/es/index.js +0 -1
- package/es/material-config/MaterialConfigContext.js +2 -2
- package/es/material-config/MaterialConfigProvider.js +27 -17
- package/es/material-config/index.js +4 -0
- package/es/material-config/useMaterialConfig.js +2 -2
- package/es/material-config/useMaterialConfigApiClientUpdate.js +8 -4
- package/es/material-fetch/index.js +2 -0
- package/es/material-fetch/useMaterialFetch.d.ts +1 -1
- package/es/material-fetch/useMaterialFetch.js +3 -2
- package/es/material-fetch/useMaterialFetchRaw.js +71 -54
- package/es/material-hoc/index.js +1 -0
- package/es/material-hoc/withMaterial.d.ts +2 -13
- package/es/material-hoc/withMaterial.js +32 -32
- package/package.json +8 -11
- package/cjs/components/MaterialIntlProvider.d.ts +0 -14
- package/cjs/components/MaterialIntlProvider.js +0 -27
- package/cjs/components/index.d.ts +0 -2
- package/es/components/MaterialIntlProvider.d.ts +0 -14
- package/es/components/MaterialIntlProvider.js +0 -23
- package/es/components/index.d.ts +0 -2
|
@@ -1,26 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
|
|
3
4
|
var React = require('react');
|
|
4
5
|
var apiClient = require('@elice/api-client');
|
|
5
6
|
var types = require('@elice/types');
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
[types.enums.LectureMaterialType.Note]: 'materialNote',
|
|
10
|
-
[types.enums.LectureMaterialType.Video]: 'materialVideo',
|
|
11
|
-
[types.enums.LectureMaterialType.PDF]: 'materialPdf',
|
|
12
|
-
[types.enums.LectureMaterialType.Exercise]: 'materialExercise',
|
|
13
|
-
[types.enums.LectureMaterialType.Quiz]: 'materialQuiz',
|
|
14
|
-
[types.enums.LectureMaterialType.LegacyRunbox]: 'materialLegacyRunbox',
|
|
15
|
-
[types.enums.LectureMaterialType.VideoFile]: 'materialVideoFile',
|
|
16
|
-
[types.enums.LectureMaterialType.Live]: 'materialLive',
|
|
17
|
-
[types.enums.LectureMaterialType.Assignment]: 'materialAssignment',
|
|
18
|
-
[types.enums.LectureMaterialType.LMSPublicContent]: 'materialLmsPublicContent',
|
|
19
|
-
[types.enums.LectureMaterialType.External]: 'materialExternal',
|
|
20
|
-
[types.enums.LectureMaterialType.Survey]: 'materialSurvey',
|
|
21
|
-
[types.enums.LectureMaterialType.Runbox]: 'materialRunbox',
|
|
22
|
-
[types.enums.LectureMaterialType.Cloud]: 'materialCloud'
|
|
23
|
-
});
|
|
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));
|
|
24
10
|
//
|
|
25
11
|
//
|
|
26
12
|
//
|
|
@@ -42,54 +28,85 @@ const MATERIAL_FETCH_KEY_MAP = Object.freeze({
|
|
|
42
28
|
* isReady // boolean
|
|
43
29
|
* );
|
|
44
30
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
31
|
+
var useMaterialFetchRaw = function useMaterialFetchRaw(materialType, materialFetchFn) {
|
|
32
|
+
var isReady = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
33
|
+
var _return = React.useRef({});
|
|
34
|
+
var materialKey = MATERIAL_FETCH_KEY_MAP[materialType];
|
|
35
|
+
var _createEmptyFetchRes = function _createEmptyFetchRes() {
|
|
36
|
+
var _ref;
|
|
37
|
+
return _ref = {}, _rollupPluginBabelHelpers.defineProperty(_ref, materialKey, null), _rollupPluginBabelHelpers.defineProperty(_ref, "materialLecturePage", null), _ref;
|
|
38
|
+
};
|
|
39
|
+
var _useState = React.useState(_createEmptyFetchRes),
|
|
40
|
+
_useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
|
|
41
|
+
matFetchRes = _useState2[0],
|
|
42
|
+
setMatFetchRes = _useState2[1];
|
|
43
|
+
var _useState3 = React.useState('idle'),
|
|
44
|
+
_useState4 = _rollupPluginBabelHelpers.slicedToArray(_useState3, 2),
|
|
45
|
+
matFetchStatus = _useState4[0],
|
|
46
|
+
setMatFetchStatus = _useState4[1];
|
|
54
47
|
/**
|
|
55
48
|
* fetch material and lecture page
|
|
56
49
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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) {
|
|
54
|
+
case 0:
|
|
55
|
+
setMatFetchStatus('pending');
|
|
56
|
+
return _context.abrupt("return", materialFetchFn(signal).then(function (resMaterialGet) {
|
|
57
|
+
return resMaterialGet[materialKey];
|
|
58
|
+
}).then(function (material) {
|
|
59
|
+
return Promise.all([material, apiClient.getOrgLecturePageResolve({
|
|
60
|
+
materialId: material.id,
|
|
61
|
+
materialType: materialType
|
|
62
|
+
}, {
|
|
63
|
+
signal: signal
|
|
64
|
+
}).then(function (resLecturePageResolve) {
|
|
65
|
+
return apiClient.getOrgLecturePageGet({
|
|
66
|
+
lecturePageId: resLecturePageResolve.lecturePageId
|
|
67
|
+
}, {
|
|
68
|
+
signal: signal
|
|
69
|
+
});
|
|
70
|
+
}).then(function (resLecturePageGet) {
|
|
71
|
+
return resLecturePageGet.lecturePage;
|
|
72
|
+
})]);
|
|
73
|
+
}).then(function (_ref3) {
|
|
74
|
+
var _setMatFetchRes;
|
|
75
|
+
var _ref4 = _rollupPluginBabelHelpers.slicedToArray(_ref3, 2),
|
|
76
|
+
material = _ref4[0],
|
|
77
|
+
materialLecturePage = _ref4[1];
|
|
78
|
+
setMatFetchRes((_setMatFetchRes = {}, _rollupPluginBabelHelpers.defineProperty(_setMatFetchRes, materialKey, material), _rollupPluginBabelHelpers.defineProperty(_setMatFetchRes, "materialLecturePage", materialLecturePage), _setMatFetchRes));
|
|
79
|
+
setMatFetchStatus('resolved');
|
|
80
|
+
}).catch(function (err) {
|
|
81
|
+
if (err.name !== 'AbortError') {
|
|
82
|
+
setMatFetchRes(_createEmptyFetchRes);
|
|
83
|
+
setMatFetchStatus('rejected');
|
|
84
|
+
}
|
|
85
|
+
}));
|
|
86
|
+
case 2:
|
|
87
|
+
case "end":
|
|
88
|
+
return _context.stop();
|
|
89
|
+
}
|
|
90
|
+
}, _callee);
|
|
91
|
+
}));
|
|
92
|
+
return function (_x) {
|
|
93
|
+
return _ref2.apply(this, arguments);
|
|
94
|
+
};
|
|
95
|
+
}(),
|
|
81
96
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
82
97
|
[materialKey, materialFetchFn]);
|
|
83
98
|
//
|
|
84
99
|
// emit `fetch` when `isReady` is changed
|
|
85
100
|
//
|
|
86
|
-
React.useEffect(()
|
|
101
|
+
React.useEffect(function () {
|
|
87
102
|
if (!isReady) {
|
|
88
103
|
return;
|
|
89
104
|
}
|
|
90
|
-
|
|
91
|
-
fetch(abortCtrl.signal).catch(()
|
|
92
|
-
|
|
105
|
+
var abortCtrl = new AbortController();
|
|
106
|
+
fetch(abortCtrl.signal).catch(function () {
|
|
107
|
+
return void 0;
|
|
108
|
+
});
|
|
109
|
+
return function () {
|
|
93
110
|
abortCtrl.abort();
|
|
94
111
|
};
|
|
95
112
|
},
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { MaterialIntlProviderPhrases } from '../components/MaterialIntlProvider';
|
|
3
2
|
import type { MaterialConfigApiClientUpdateCallback } from '../material-config';
|
|
4
3
|
type AnyObject = Record<string, any>;
|
|
5
4
|
/**
|
|
@@ -11,16 +10,6 @@ export interface WithMaterialOptions {
|
|
|
11
10
|
* - ref: https://recoiljs.org/docs/api-reference/core/RecoilRoot/#props -> `override`
|
|
12
11
|
*/
|
|
13
12
|
overrideRecoilScope?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Phrases for `IntlProvider`.
|
|
16
|
-
*/
|
|
17
|
-
phrases?: MaterialIntlProviderPhrases;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Common props for material components.
|
|
21
|
-
*/
|
|
22
|
-
export interface MaterialCommponentCommonProps {
|
|
23
|
-
locale?: string;
|
|
24
13
|
}
|
|
25
14
|
/**
|
|
26
15
|
* HOC for material components.
|
|
@@ -29,7 +18,7 @@ export interface MaterialCommponentCommonProps {
|
|
|
29
18
|
* - `<RecoilRoot />`
|
|
30
19
|
* - `<IntlProvider />`
|
|
31
20
|
*/
|
|
32
|
-
export declare const withMaterial: <P extends AnyObject>(Component: React.VFC<P
|
|
21
|
+
export declare const withMaterial: <P extends AnyObject>(Component: React.VFC<P>, eliceApiClientConfigInit: MaterialConfigApiClientUpdateCallback, options?: WithMaterialOptions) => React.VFC<P>;
|
|
33
22
|
/**
|
|
34
23
|
* HOC for material forward ref exotic components.
|
|
35
24
|
*
|
|
@@ -37,5 +26,5 @@ export declare const withMaterial: <P extends AnyObject>(Component: React.VFC<P
|
|
|
37
26
|
* - `<RecoilRoot />`
|
|
38
27
|
* - `<IntlProvider />`
|
|
39
28
|
*/
|
|
40
|
-
export declare const withForwardRefMaterial: <T, P extends AnyObject>(Component: React.ForwardRefExoticComponent<P &
|
|
29
|
+
export declare const withForwardRefMaterial: <T, P extends AnyObject>(Component: React.ForwardRefExoticComponent<P & React.RefAttributes<T>>, eliceApiClientConfigInit: MaterialConfigApiClientUpdateCallback, options?: WithMaterialOptions) => React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>>;
|
|
41
30
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
3
4
|
var React = require('react');
|
|
4
5
|
var blocks = require('@elice/blocks');
|
|
5
6
|
var recoil = require('recoil');
|
|
6
|
-
var MaterialIntlProvider = require('../components/MaterialIntlProvider.js');
|
|
7
7
|
require('../material-config/MaterialConfigContext.js');
|
|
8
8
|
var useMaterialConfigApiClientUpdate = require('../material-config/useMaterialConfigApiClientUpdate.js');
|
|
9
9
|
|
|
@@ -17,27 +17,27 @@ var useMaterialConfigApiClientUpdate = require('../material-config/useMaterialCo
|
|
|
17
17
|
* - `<RecoilRoot />`
|
|
18
18
|
* - `<IntlProvider />`
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
var withMaterial = function withMaterial(Component, eliceApiClientConfigInit) {
|
|
21
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
22
|
+
return function (props) {
|
|
22
23
|
var _a;
|
|
23
|
-
|
|
24
|
+
var isReady = useMaterialConfigApiClientUpdate.useMaterialConfigApiClientUpdate(eliceApiClientConfigInit);
|
|
24
25
|
// do not render component, if material config is not ready
|
|
25
26
|
if (!isReady) {
|
|
26
|
-
return
|
|
27
|
+
return jsxRuntime.jsx(blocks.Flex, {
|
|
27
28
|
justify: "center",
|
|
28
29
|
align: "center",
|
|
29
30
|
width: "100%",
|
|
30
|
-
height: "100%"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
height: "100%",
|
|
32
|
+
children: jsxRuntime.jsx(blocks.Spinner, {
|
|
33
|
+
size: "small"
|
|
34
|
+
})
|
|
35
|
+
});
|
|
34
36
|
}
|
|
35
|
-
return
|
|
36
|
-
override: (_a = options.overrideRecoilScope) !== null && _a !== void 0 ? _a : false
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
phrases: options.phrases
|
|
40
|
-
}, React.createElement(Component, Object.assign({}, props))));
|
|
37
|
+
return jsxRuntime.jsx(recoil.RecoilRoot, {
|
|
38
|
+
override: (_a = options.overrideRecoilScope) !== null && _a !== void 0 ? _a : false,
|
|
39
|
+
children: jsxRuntime.jsx(Component, Object.assign({}, props))
|
|
40
|
+
});
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
43
|
/**
|
|
@@ -47,29 +47,29 @@ const withMaterial = (Component, eliceApiClientConfigInit, options = {}) => {
|
|
|
47
47
|
* - `<RecoilRoot />`
|
|
48
48
|
* - `<IntlProvider />`
|
|
49
49
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
var withForwardRefMaterial = function withForwardRefMaterial(Component, eliceApiClientConfigInit) {
|
|
51
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
52
|
+
return React.forwardRef(function (props, ref) {
|
|
52
53
|
var _a;
|
|
53
|
-
|
|
54
|
+
var isReady = useMaterialConfigApiClientUpdate.useMaterialConfigApiClientUpdate(eliceApiClientConfigInit);
|
|
54
55
|
// do not render component, if material config is not ready
|
|
55
56
|
if (!isReady) {
|
|
56
|
-
return
|
|
57
|
+
return jsxRuntime.jsx(blocks.Flex, {
|
|
57
58
|
justify: "center",
|
|
58
59
|
align: "center",
|
|
59
60
|
width: "100%",
|
|
60
|
-
height: "100%"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
height: "100%",
|
|
62
|
+
children: jsxRuntime.jsx(blocks.Spinner, {
|
|
63
|
+
size: "small"
|
|
64
|
+
})
|
|
65
|
+
});
|
|
64
66
|
}
|
|
65
|
-
return
|
|
66
|
-
override: (_a = options.overrideRecoilScope) !== null && _a !== void 0 ? _a : false
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
ref: ref
|
|
72
|
-
}))));
|
|
67
|
+
return jsxRuntime.jsx(recoil.RecoilRoot, {
|
|
68
|
+
override: (_a = options.overrideRecoilScope) !== null && _a !== void 0 ? _a : false,
|
|
69
|
+
children: jsxRuntime.jsx(Component, Object.assign({}, props, {
|
|
70
|
+
ref: ref
|
|
71
|
+
}))
|
|
72
|
+
});
|
|
73
73
|
});
|
|
74
74
|
};
|
|
75
75
|
|