@elice/material-shared-utils 1.261104.0-lxplicense.0 → 1.261108.0-customhtmlmaterial.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.
@@ -8,6 +8,10 @@ function _arrayLikeToArray(r, a) {
8
8
  function _arrayWithHoles(r) {
9
9
  if (Array.isArray(r)) return r;
10
10
  }
11
+ function _assertThisInitialized(e) {
12
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
13
+ return e;
14
+ }
11
15
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
12
16
  try {
13
17
  var i = n[a](c),
@@ -33,6 +37,24 @@ function _asyncToGenerator(n) {
33
37
  });
34
38
  };
35
39
  }
40
+ function _callSuper(t, o, e) {
41
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
42
+ }
43
+ function _classCallCheck(a, n) {
44
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
45
+ }
46
+ function _construct(t, e, r) {
47
+ if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
48
+ var o = [null];
49
+ o.push.apply(o, e);
50
+ var p = new (t.bind.apply(t, o))();
51
+ return r && _setPrototypeOf(p, r.prototype), p;
52
+ }
53
+ function _createClass(e, r, t) {
54
+ return Object.defineProperty(e, "prototype", {
55
+ writable: false
56
+ }), e;
57
+ }
36
58
  function _defineProperty(e, r, t) {
37
59
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
38
60
  value: t,
@@ -41,6 +63,38 @@ function _defineProperty(e, r, t) {
41
63
  writable: true
42
64
  }) : e[r] = t, e;
43
65
  }
66
+ function _getPrototypeOf(t) {
67
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
68
+ return t.__proto__ || Object.getPrototypeOf(t);
69
+ }, _getPrototypeOf(t);
70
+ }
71
+ function _inherits(t, e) {
72
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
73
+ t.prototype = Object.create(e && e.prototype, {
74
+ constructor: {
75
+ value: t,
76
+ writable: true,
77
+ configurable: true
78
+ }
79
+ }), Object.defineProperty(t, "prototype", {
80
+ writable: false
81
+ }), e && _setPrototypeOf(t, e);
82
+ }
83
+ function _isNativeFunction(t) {
84
+ try {
85
+ return -1 !== Function.toString.call(t).indexOf("[native code]");
86
+ } catch (n) {
87
+ return "function" == typeof t;
88
+ }
89
+ }
90
+ function _isNativeReflectConstruct() {
91
+ try {
92
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
93
+ } catch (t) {}
94
+ return (_isNativeReflectConstruct = function () {
95
+ return !!t;
96
+ })();
97
+ }
44
98
  function _iterableToArrayLimit(r, l) {
45
99
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
46
100
  if (null != t) {
@@ -68,6 +122,11 @@ function _iterableToArrayLimit(r, l) {
68
122
  function _nonIterableRest() {
69
123
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
70
124
  }
125
+ function _possibleConstructorReturn(t, e) {
126
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
127
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
128
+ return _assertThisInitialized(t);
129
+ }
71
130
  function _regenerator() {
72
131
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
73
132
  var e,
@@ -176,6 +235,11 @@ function _regeneratorDefine(e, r, n, t) {
176
235
  }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
177
236
  }, _regeneratorDefine(e, r, n, t);
178
237
  }
238
+ function _setPrototypeOf(t, e) {
239
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
240
+ return t.__proto__ = e, t;
241
+ }, _setPrototypeOf(t, e);
242
+ }
179
243
  function _slicedToArray(r, e) {
180
244
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
181
245
  }
@@ -200,16 +264,50 @@ function _unsupportedIterableToArray(r, a) {
200
264
  return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
201
265
  }
202
266
  }
267
+ function _wrapNativeSuper(t) {
268
+ var r = "function" == typeof Map ? new Map() : void 0;
269
+ return _wrapNativeSuper = function (t) {
270
+ if (null === t || !_isNativeFunction(t)) return t;
271
+ if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
272
+ if (void 0 !== r) {
273
+ if (r.has(t)) return r.get(t);
274
+ r.set(t, Wrapper);
275
+ }
276
+ function Wrapper() {
277
+ return _construct(t, arguments, _getPrototypeOf(this).constructor);
278
+ }
279
+ return Wrapper.prototype = Object.create(t.prototype, {
280
+ constructor: {
281
+ value: Wrapper,
282
+ enumerable: false,
283
+ writable: true,
284
+ configurable: true
285
+ }
286
+ }), _setPrototypeOf(Wrapper, t);
287
+ }, _wrapNativeSuper(t);
288
+ }
203
289
 
204
290
  exports.arrayLikeToArray = _arrayLikeToArray;
205
291
  exports.arrayWithHoles = _arrayWithHoles;
292
+ exports.assertThisInitialized = _assertThisInitialized;
206
293
  exports.asyncToGenerator = _asyncToGenerator;
294
+ exports.callSuper = _callSuper;
295
+ exports.classCallCheck = _classCallCheck;
296
+ exports.construct = _construct;
297
+ exports.createClass = _createClass;
207
298
  exports.defineProperty = _defineProperty;
299
+ exports.getPrototypeOf = _getPrototypeOf;
300
+ exports.inherits = _inherits;
301
+ exports.isNativeFunction = _isNativeFunction;
302
+ exports.isNativeReflectConstruct = _isNativeReflectConstruct;
208
303
  exports.iterableToArrayLimit = _iterableToArrayLimit;
209
304
  exports.nonIterableRest = _nonIterableRest;
305
+ exports.possibleConstructorReturn = _possibleConstructorReturn;
210
306
  exports.regenerator = _regenerator;
211
307
  exports.regeneratorDefine = _regeneratorDefine;
308
+ exports.setPrototypeOf = _setPrototypeOf;
212
309
  exports.slicedToArray = _slicedToArray;
213
310
  exports.toPrimitive = _toPrimitive;
214
311
  exports.toPropertyKey = _toPropertyKey;
215
312
  exports.unsupportedIterableToArray = _unsupportedIterableToArray;
313
+ exports.wrapNativeSuper = _wrapNativeSuper;
package/cjs/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './hooks';
2
2
  export * from './material-config';
3
3
  export * from './material-fetch';
4
4
  export * from './material-hoc';
5
+ export * from './utils';
package/cjs/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var MaterialConfigProvider = require('./material-config/MaterialConfigProvider.js');
4
+ var polling = require('./utils/polling.js');
4
5
  var utils = require('./material-config/utils.js');
5
6
  var useCallbackProp = require('./hooks/useCallbackProp.js');
6
7
  var useCallbackRef = require('./hooks/useCallbackRef.js');
@@ -15,6 +16,8 @@ var withMaterial = require('./material-hoc/withMaterial.js');
15
16
 
16
17
 
17
18
  exports.MaterialConfigProvider = MaterialConfigProvider.default;
19
+ exports.PollingAbortError = polling.PollingAbortError;
20
+ exports.polling = polling.polling;
18
21
  exports.updateMaterialConfigSessionKey = utils.updateMaterialConfigSessionKey;
19
22
  exports.useCallbackProp = useCallbackProp.useCallbackProp;
20
23
  exports.useCallbackRef = useCallbackRef.useCallbackRef;
@@ -19,6 +19,7 @@ export interface FetchKeyMap {
19
19
  [enums.LectureMaterialType.Runbox]: 'materialRunbox';
20
20
  [enums.LectureMaterialType.Cloud]: 'materialCloud';
21
21
  [enums.LectureMaterialType.VideoAssessment]: 'materialVideoAssessment';
22
+ [enums.LectureMaterialType.HelpyChat]: 'materialHelpyChat';
22
23
  }
23
24
  /**
24
25
  * Init api client and fetch material for contaner.
@@ -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(_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(_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'), types.enums.LectureMaterialType.VideoAssessment, 'materialVideoAssessment')));
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(_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'), types.enums.LectureMaterialType.VideoAssessment, 'materialVideoAssessment'), types.enums.LectureMaterialType.HelpyChat, 'materialHelpyChat')));
10
10
  //
11
11
  //
12
12
  //
@@ -0,0 +1 @@
1
+ export * from './polling';
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ var polling = require('./polling.js');
4
+
5
+
6
+
7
+ exports.PollingAbortError = polling.PollingAbortError;
8
+ exports.polling = polling.polling;
@@ -0,0 +1,58 @@
1
+ interface PollingFnParams {
2
+ signal: AbortSignal;
3
+ }
4
+ interface PollingTimers {
5
+ setTimeout: typeof globalThis.setTimeout;
6
+ clearTimeout: typeof globalThis.clearTimeout;
7
+ }
8
+ interface PollingOptions<R> {
9
+ /**
10
+ * Function to polling request.
11
+ */
12
+ pollingFn: (params: PollingFnParams) => Promise<R>;
13
+ /**
14
+ * Function to check if the polling request is successful.
15
+ */
16
+ until: (res: R) => boolean;
17
+ /**
18
+ * Interval of polling.
19
+ */
20
+ interval?: number;
21
+ /**
22
+ * Maximum number of attempts.
23
+ */
24
+ maxAttempts?: number;
25
+ /**
26
+ * Abort signal.
27
+ */
28
+ signal?: AbortSignal;
29
+ /**
30
+ * Function on each poll.
31
+ */
32
+ onPoll?: (res: R) => void;
33
+ /**
34
+ * Custom timer implementation for the sleep between attempts.
35
+
36
+ * ```ts
37
+ * polling({
38
+ * pollingFn,
39
+ * until,
40
+ * timers: {
41
+ * setTimeout: window.setTimeout,
42
+ * clearTimeout: window.clearTimeout,
43
+ * },
44
+ * });
45
+ * ```
46
+ */
47
+ timers?: PollingTimers;
48
+ }
49
+ export declare class PollingAbortError extends Error {
50
+ constructor(message?: string);
51
+ }
52
+ /**
53
+ * Call `pollingFn` until `until` returns true, waiting `interval` between attempts. The wait uses
54
+ * worker timers so a background tab does not slow it down. Rejects with `PollingAbortError` when
55
+ * `signal` aborts, and with an `Error` after `maxAttempts`.
56
+ */
57
+ export declare function polling<R>(options: PollingOptions<R>): Promise<R>;
58
+ export {};
@@ -0,0 +1,110 @@
1
+ 'use strict';
2
+
3
+ var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
4
+ var workerTimers = require('worker-timers');
5
+
6
+ //
7
+ //
8
+ //
9
+ var DEFAULT_MAX_ATTEMPTS = 10;
10
+ var DEFAULT_INTERVAL = 1000;
11
+ //
12
+ //
13
+ //
14
+ var PollingAbortError = /*#__PURE__*/function (_Error) {
15
+ function PollingAbortError(message) {
16
+ var _this;
17
+ _rollupPluginBabelHelpers.classCallCheck(this, PollingAbortError);
18
+ _this = _rollupPluginBabelHelpers.callSuper(this, PollingAbortError, [message || 'Polling aborted']);
19
+ _this.name = 'AbortError';
20
+ return _this;
21
+ }
22
+ _rollupPluginBabelHelpers.inherits(PollingAbortError, _Error);
23
+ return _rollupPluginBabelHelpers.createClass(PollingAbortError);
24
+ }(/*#__PURE__*/_rollupPluginBabelHelpers.wrapNativeSuper(Error));
25
+ /**
26
+ * Call `pollingFn` until `until` returns true, waiting `interval` between attempts. The wait uses
27
+ * worker timers so a background tab does not slow it down. Rejects with `PollingAbortError` when
28
+ * `signal` aborts, and with an `Error` after `maxAttempts`.
29
+ */
30
+ function polling(_x) {
31
+ return _polling.apply(this, arguments);
32
+ }
33
+ function _polling() {
34
+ _polling = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee2(options) {
35
+ var _a, _b, _c, _d, _e, _f, _g, period, maxAttempts, signal, setTimeoutFn, clearTimeoutFn, __sleep, attempt, result;
36
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context2) {
37
+ while (1) switch (_context2.n) {
38
+ case 0:
39
+ period = (_a = options === null || options === void 0 ? void 0 : options.interval) !== null && _a !== void 0 ? _a : DEFAULT_INTERVAL;
40
+ maxAttempts = (_b = options === null || options === void 0 ? void 0 : options.maxAttempts) !== null && _b !== void 0 ? _b : DEFAULT_MAX_ATTEMPTS;
41
+ signal = (_c = options === null || options === void 0 ? void 0 : options.signal) !== null && _c !== void 0 ? _c : new AbortController().signal;
42
+ setTimeoutFn = (_e = (_d = options === null || options === void 0 ? void 0 : options.timers) === null || _d === void 0 ? void 0 : _d.setTimeout) !== null && _e !== void 0 ? _e : workerTimers.setTimeout;
43
+ clearTimeoutFn = (_g = (_f = options === null || options === void 0 ? void 0 : options.timers) === null || _f === void 0 ? void 0 : _f.clearTimeout) !== null && _g !== void 0 ? _g : workerTimers.clearTimeout;
44
+ __sleep = /*#__PURE__*/function () {
45
+ var _ref = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee() {
46
+ return _rollupPluginBabelHelpers.regenerator().w(function (_context) {
47
+ while (1) switch (_context.n) {
48
+ case 0:
49
+ return _context.a(2, new Promise(function (resolve, reject) {
50
+ if (signal.aborted) {
51
+ return reject(new PollingAbortError());
52
+ }
53
+ var id = setTimeoutFn(resolve, period);
54
+ signal.addEventListener('abort', function () {
55
+ clearTimeoutFn(id);
56
+ reject(new PollingAbortError());
57
+ }, {
58
+ once: true
59
+ });
60
+ }));
61
+ }
62
+ }, _callee);
63
+ }));
64
+ return function __sleep() {
65
+ return _ref.apply(this, arguments);
66
+ };
67
+ }();
68
+ attempt = 1;
69
+ case 1:
70
+ if (!(attempt <= maxAttempts)) {
71
+ _context2.n = 5;
72
+ break;
73
+ }
74
+ _context2.n = 2;
75
+ return options.pollingFn({
76
+ signal: signal
77
+ });
78
+ case 2:
79
+ result = _context2.v;
80
+ if (typeof options.onPoll === 'function') {
81
+ options.onPoll(result);
82
+ }
83
+ if (!options.until(result)) {
84
+ _context2.n = 3;
85
+ break;
86
+ }
87
+ return _context2.a(2, result);
88
+ case 3:
89
+ if (!(attempt < maxAttempts)) {
90
+ _context2.n = 4;
91
+ break;
92
+ }
93
+ _context2.n = 4;
94
+ return __sleep();
95
+ case 4:
96
+ attempt++;
97
+ _context2.n = 1;
98
+ break;
99
+ case 5:
100
+ throw new Error("Polling failed after ".concat(maxAttempts, " attempts"));
101
+ case 6:
102
+ return _context2.a(2);
103
+ }
104
+ }, _callee2);
105
+ }));
106
+ return _polling.apply(this, arguments);
107
+ }
108
+
109
+ exports.PollingAbortError = PollingAbortError;
110
+ exports.polling = polling;
@@ -6,6 +6,10 @@ function _arrayLikeToArray(r, a) {
6
6
  function _arrayWithHoles(r) {
7
7
  if (Array.isArray(r)) return r;
8
8
  }
9
+ function _assertThisInitialized(e) {
10
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
11
+ return e;
12
+ }
9
13
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
10
14
  try {
11
15
  var i = n[a](c),
@@ -31,6 +35,24 @@ function _asyncToGenerator(n) {
31
35
  });
32
36
  };
33
37
  }
38
+ function _callSuper(t, o, e) {
39
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
40
+ }
41
+ function _classCallCheck(a, n) {
42
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
43
+ }
44
+ function _construct(t, e, r) {
45
+ if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
46
+ var o = [null];
47
+ o.push.apply(o, e);
48
+ var p = new (t.bind.apply(t, o))();
49
+ return r && _setPrototypeOf(p, r.prototype), p;
50
+ }
51
+ function _createClass(e, r, t) {
52
+ return Object.defineProperty(e, "prototype", {
53
+ writable: false
54
+ }), e;
55
+ }
34
56
  function _defineProperty(e, r, t) {
35
57
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
36
58
  value: t,
@@ -39,6 +61,38 @@ function _defineProperty(e, r, t) {
39
61
  writable: true
40
62
  }) : e[r] = t, e;
41
63
  }
64
+ function _getPrototypeOf(t) {
65
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
66
+ return t.__proto__ || Object.getPrototypeOf(t);
67
+ }, _getPrototypeOf(t);
68
+ }
69
+ function _inherits(t, e) {
70
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
71
+ t.prototype = Object.create(e && e.prototype, {
72
+ constructor: {
73
+ value: t,
74
+ writable: true,
75
+ configurable: true
76
+ }
77
+ }), Object.defineProperty(t, "prototype", {
78
+ writable: false
79
+ }), e && _setPrototypeOf(t, e);
80
+ }
81
+ function _isNativeFunction(t) {
82
+ try {
83
+ return -1 !== Function.toString.call(t).indexOf("[native code]");
84
+ } catch (n) {
85
+ return "function" == typeof t;
86
+ }
87
+ }
88
+ function _isNativeReflectConstruct() {
89
+ try {
90
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
91
+ } catch (t) {}
92
+ return (_isNativeReflectConstruct = function () {
93
+ return !!t;
94
+ })();
95
+ }
42
96
  function _iterableToArrayLimit(r, l) {
43
97
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
44
98
  if (null != t) {
@@ -66,6 +120,11 @@ function _iterableToArrayLimit(r, l) {
66
120
  function _nonIterableRest() {
67
121
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
68
122
  }
123
+ function _possibleConstructorReturn(t, e) {
124
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
125
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
126
+ return _assertThisInitialized(t);
127
+ }
69
128
  function _regenerator() {
70
129
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
71
130
  var e,
@@ -174,6 +233,11 @@ function _regeneratorDefine(e, r, n, t) {
174
233
  }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
175
234
  }, _regeneratorDefine(e, r, n, t);
176
235
  }
236
+ function _setPrototypeOf(t, e) {
237
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
238
+ return t.__proto__ = e, t;
239
+ }, _setPrototypeOf(t, e);
240
+ }
177
241
  function _slicedToArray(r, e) {
178
242
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
179
243
  }
@@ -198,5 +262,27 @@ function _unsupportedIterableToArray(r, a) {
198
262
  return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
199
263
  }
200
264
  }
265
+ function _wrapNativeSuper(t) {
266
+ var r = "function" == typeof Map ? new Map() : void 0;
267
+ return _wrapNativeSuper = function (t) {
268
+ if (null === t || !_isNativeFunction(t)) return t;
269
+ if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
270
+ if (void 0 !== r) {
271
+ if (r.has(t)) return r.get(t);
272
+ r.set(t, Wrapper);
273
+ }
274
+ function Wrapper() {
275
+ return _construct(t, arguments, _getPrototypeOf(this).constructor);
276
+ }
277
+ return Wrapper.prototype = Object.create(t.prototype, {
278
+ constructor: {
279
+ value: Wrapper,
280
+ enumerable: false,
281
+ writable: true,
282
+ configurable: true
283
+ }
284
+ }), _setPrototypeOf(Wrapper, t);
285
+ }, _wrapNativeSuper(t);
286
+ }
201
287
 
202
- export { _arrayLikeToArray as arrayLikeToArray, _arrayWithHoles as arrayWithHoles, _asyncToGenerator as asyncToGenerator, _defineProperty as defineProperty, _iterableToArrayLimit as iterableToArrayLimit, _nonIterableRest as nonIterableRest, _regenerator as regenerator, _regeneratorDefine as regeneratorDefine, _slicedToArray as slicedToArray, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey, _unsupportedIterableToArray as unsupportedIterableToArray };
288
+ export { _arrayLikeToArray as arrayLikeToArray, _arrayWithHoles as arrayWithHoles, _assertThisInitialized as assertThisInitialized, _asyncToGenerator as asyncToGenerator, _callSuper as callSuper, _classCallCheck as classCallCheck, _construct as construct, _createClass as createClass, _defineProperty as defineProperty, _getPrototypeOf as getPrototypeOf, _inherits as inherits, _isNativeFunction as isNativeFunction, _isNativeReflectConstruct as isNativeReflectConstruct, _iterableToArrayLimit as iterableToArrayLimit, _nonIterableRest as nonIterableRest, _possibleConstructorReturn as possibleConstructorReturn, _regenerator as regenerator, _regeneratorDefine as regeneratorDefine, _setPrototypeOf as setPrototypeOf, _slicedToArray as slicedToArray, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey, _unsupportedIterableToArray as unsupportedIterableToArray, _wrapNativeSuper as wrapNativeSuper };
package/es/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './hooks';
2
2
  export * from './material-config';
3
3
  export * from './material-fetch';
4
4
  export * from './material-hoc';
5
+ export * from './utils';
package/es/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as MaterialConfigProvider } from './material-config/MaterialConfigProvider.js';
2
+ export { PollingAbortError, polling } from './utils/polling.js';
2
3
  export { updateMaterialConfigSessionKey } from './material-config/utils.js';
3
4
  export { useCallbackProp } from './hooks/useCallbackProp.js';
4
5
  export { useCallbackRef } from './hooks/useCallbackRef.js';
@@ -19,6 +19,7 @@ export interface FetchKeyMap {
19
19
  [enums.LectureMaterialType.Runbox]: 'materialRunbox';
20
20
  [enums.LectureMaterialType.Cloud]: 'materialCloud';
21
21
  [enums.LectureMaterialType.VideoAssessment]: 'materialVideoAssessment';
22
+ [enums.LectureMaterialType.HelpyChat]: 'materialHelpyChat';
22
23
  }
23
24
  /**
24
25
  * Init api client and fetch material for contaner.
@@ -4,7 +4,7 @@ import { getOrgLecturePageResolve, getOrgLecturePageGet } from '@elice/api-clien
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(_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(_defineProperty(_Object$freeze, enums.LectureMaterialType.LMSPublicContent, 'materialLmsPublicContent'), enums.LectureMaterialType.External, 'materialExternal'), enums.LectureMaterialType.Survey, 'materialSurvey'), enums.LectureMaterialType.Runbox, 'materialRunbox'), enums.LectureMaterialType.Cloud, 'materialCloud'), enums.LectureMaterialType.VideoAssessment, 'materialVideoAssessment')));
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(_defineProperty(_defineProperty(_Object$freeze, enums.LectureMaterialType.LMSPublicContent, 'materialLmsPublicContent'), enums.LectureMaterialType.External, 'materialExternal'), enums.LectureMaterialType.Survey, 'materialSurvey'), enums.LectureMaterialType.Runbox, 'materialRunbox'), enums.LectureMaterialType.Cloud, 'materialCloud'), enums.LectureMaterialType.VideoAssessment, 'materialVideoAssessment'), enums.LectureMaterialType.HelpyChat, 'materialHelpyChat')));
8
8
  //
9
9
  //
10
10
  //
@@ -0,0 +1 @@
1
+ export * from './polling';
@@ -0,0 +1 @@
1
+ export { PollingAbortError, polling } from './polling.js';
@@ -0,0 +1,58 @@
1
+ interface PollingFnParams {
2
+ signal: AbortSignal;
3
+ }
4
+ interface PollingTimers {
5
+ setTimeout: typeof globalThis.setTimeout;
6
+ clearTimeout: typeof globalThis.clearTimeout;
7
+ }
8
+ interface PollingOptions<R> {
9
+ /**
10
+ * Function to polling request.
11
+ */
12
+ pollingFn: (params: PollingFnParams) => Promise<R>;
13
+ /**
14
+ * Function to check if the polling request is successful.
15
+ */
16
+ until: (res: R) => boolean;
17
+ /**
18
+ * Interval of polling.
19
+ */
20
+ interval?: number;
21
+ /**
22
+ * Maximum number of attempts.
23
+ */
24
+ maxAttempts?: number;
25
+ /**
26
+ * Abort signal.
27
+ */
28
+ signal?: AbortSignal;
29
+ /**
30
+ * Function on each poll.
31
+ */
32
+ onPoll?: (res: R) => void;
33
+ /**
34
+ * Custom timer implementation for the sleep between attempts.
35
+
36
+ * ```ts
37
+ * polling({
38
+ * pollingFn,
39
+ * until,
40
+ * timers: {
41
+ * setTimeout: window.setTimeout,
42
+ * clearTimeout: window.clearTimeout,
43
+ * },
44
+ * });
45
+ * ```
46
+ */
47
+ timers?: PollingTimers;
48
+ }
49
+ export declare class PollingAbortError extends Error {
50
+ constructor(message?: string);
51
+ }
52
+ /**
53
+ * Call `pollingFn` until `until` returns true, waiting `interval` between attempts. The wait uses
54
+ * worker timers so a background tab does not slow it down. Rejects with `PollingAbortError` when
55
+ * `signal` aborts, and with an `Error` after `maxAttempts`.
56
+ */
57
+ export declare function polling<R>(options: PollingOptions<R>): Promise<R>;
58
+ export {};
@@ -0,0 +1,107 @@
1
+ import { inherits as _inherits, createClass as _createClass, asyncToGenerator as _asyncToGenerator, wrapNativeSuper as _wrapNativeSuper, regenerator as _regenerator, classCallCheck as _classCallCheck, callSuper as _callSuper } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { setTimeout, clearTimeout } from 'worker-timers';
3
+
4
+ //
5
+ //
6
+ //
7
+ var DEFAULT_MAX_ATTEMPTS = 10;
8
+ var DEFAULT_INTERVAL = 1000;
9
+ //
10
+ //
11
+ //
12
+ var PollingAbortError = /*#__PURE__*/function (_Error) {
13
+ function PollingAbortError(message) {
14
+ var _this;
15
+ _classCallCheck(this, PollingAbortError);
16
+ _this = _callSuper(this, PollingAbortError, [message || 'Polling aborted']);
17
+ _this.name = 'AbortError';
18
+ return _this;
19
+ }
20
+ _inherits(PollingAbortError, _Error);
21
+ return _createClass(PollingAbortError);
22
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
23
+ /**
24
+ * Call `pollingFn` until `until` returns true, waiting `interval` between attempts. The wait uses
25
+ * worker timers so a background tab does not slow it down. Rejects with `PollingAbortError` when
26
+ * `signal` aborts, and with an `Error` after `maxAttempts`.
27
+ */
28
+ function polling(_x) {
29
+ return _polling.apply(this, arguments);
30
+ }
31
+ function _polling() {
32
+ _polling = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(options) {
33
+ var _a, _b, _c, _d, _e, _f, _g, period, maxAttempts, signal, setTimeoutFn, clearTimeoutFn, __sleep, attempt, result;
34
+ return _regenerator().w(function (_context2) {
35
+ while (1) switch (_context2.n) {
36
+ case 0:
37
+ period = (_a = options === null || options === void 0 ? void 0 : options.interval) !== null && _a !== void 0 ? _a : DEFAULT_INTERVAL;
38
+ maxAttempts = (_b = options === null || options === void 0 ? void 0 : options.maxAttempts) !== null && _b !== void 0 ? _b : DEFAULT_MAX_ATTEMPTS;
39
+ signal = (_c = options === null || options === void 0 ? void 0 : options.signal) !== null && _c !== void 0 ? _c : new AbortController().signal;
40
+ setTimeoutFn = (_e = (_d = options === null || options === void 0 ? void 0 : options.timers) === null || _d === void 0 ? void 0 : _d.setTimeout) !== null && _e !== void 0 ? _e : setTimeout;
41
+ clearTimeoutFn = (_g = (_f = options === null || options === void 0 ? void 0 : options.timers) === null || _f === void 0 ? void 0 : _f.clearTimeout) !== null && _g !== void 0 ? _g : clearTimeout;
42
+ __sleep = /*#__PURE__*/function () {
43
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
44
+ return _regenerator().w(function (_context) {
45
+ while (1) switch (_context.n) {
46
+ case 0:
47
+ return _context.a(2, new Promise(function (resolve, reject) {
48
+ if (signal.aborted) {
49
+ return reject(new PollingAbortError());
50
+ }
51
+ var id = setTimeoutFn(resolve, period);
52
+ signal.addEventListener('abort', function () {
53
+ clearTimeoutFn(id);
54
+ reject(new PollingAbortError());
55
+ }, {
56
+ once: true
57
+ });
58
+ }));
59
+ }
60
+ }, _callee);
61
+ }));
62
+ return function __sleep() {
63
+ return _ref.apply(this, arguments);
64
+ };
65
+ }();
66
+ attempt = 1;
67
+ case 1:
68
+ if (!(attempt <= maxAttempts)) {
69
+ _context2.n = 5;
70
+ break;
71
+ }
72
+ _context2.n = 2;
73
+ return options.pollingFn({
74
+ signal: signal
75
+ });
76
+ case 2:
77
+ result = _context2.v;
78
+ if (typeof options.onPoll === 'function') {
79
+ options.onPoll(result);
80
+ }
81
+ if (!options.until(result)) {
82
+ _context2.n = 3;
83
+ break;
84
+ }
85
+ return _context2.a(2, result);
86
+ case 3:
87
+ if (!(attempt < maxAttempts)) {
88
+ _context2.n = 4;
89
+ break;
90
+ }
91
+ _context2.n = 4;
92
+ return __sleep();
93
+ case 4:
94
+ attempt++;
95
+ _context2.n = 1;
96
+ break;
97
+ case 5:
98
+ throw new Error("Polling failed after ".concat(maxAttempts, " attempts"));
99
+ case 6:
100
+ return _context2.a(2);
101
+ }
102
+ }, _callee2);
103
+ }));
104
+ return _polling.apply(this, arguments);
105
+ }
106
+
107
+ export { PollingAbortError, polling };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elice/material-shared-utils",
3
- "version": "1.261104.0-lxplicense.0",
3
+ "version": "1.261108.0-customhtmlmaterial.0",
4
4
  "description": "Shared typings for elice material projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,19 +24,20 @@
24
24
  "@tanstack/react-query": "^4",
25
25
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
26
26
  "react-use": "^17.0.0",
27
- "@elice/material-shared-types": "1.261104.0-lxplicense.0"
27
+ "@elice/material-shared-types": "1.261108.0-customhtmlmaterial.0"
28
28
  },
29
29
  "dependencies": {
30
30
  "lodash-es": "^4.17.21",
31
31
  "recoil": "0.7.7",
32
32
  "rxjs": "^7.8.2",
33
- "tslib": "^2.6.1"
33
+ "tslib": "^2.6.1",
34
+ "worker-timers": "^8.0.4"
34
35
  },
35
36
  "devDependencies": {
36
- "@elice/api-client": "1.260529.0",
37
+ "@elice/api-client": "1.261022.0",
37
38
  "@elice/blocks": "1.260723.0",
38
39
  "@elice/rollup-config": "^1.260406.0",
39
- "@elice/types": "1.260608.0",
40
+ "@elice/types": "1.261022.0",
40
41
  "@tanstack/react-query": "^4.29.3",
41
42
  "@types/lodash-es": "^4.17.6",
42
43
  "@types/react": "^18.2.0",
@@ -47,7 +48,7 @@
47
48
  "react-use": "^17.2.4",
48
49
  "rollup": "^4.0.0",
49
50
  "typescript": "~5.9.3",
50
- "@elice/material-shared-types": "1.261104.0-lxplicense.0"
51
+ "@elice/material-shared-types": "1.261108.0-customhtmlmaterial.0"
51
52
  },
52
53
  "scripts": {
53
54
  "start": "run-s watch",