@khanacademy/wonder-blocks-timing 2.0.0 → 2.1.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/dist/index.js CHANGED
@@ -82,71 +82,441 @@ module.exports =
82
82
  /******/
83
83
  /******/
84
84
  /******/ // Load entry module and return exports
85
- /******/ return __webpack_require__(__webpack_require__.s = 2);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 13);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ([
89
89
  /* 0 */
90
- /***/ (function(module, exports) {
90
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
91
91
 
92
- module.exports = require("react");
92
+ "use strict";
93
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return SchedulePolicy; });
94
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ClearPolicy; });
95
+ const SchedulePolicy = {
96
+ Immediately: "schedule-immediately",
97
+ OnDemand: "schedule-on-demand"
98
+ };
99
+ const ClearPolicy = {
100
+ Resolve: "resolve-on-clear",
101
+ Cancel: "cancel-on-clear"
102
+ };
93
103
 
94
104
  /***/ }),
95
105
  /* 1 */
96
106
  /***/ (function(module, exports) {
97
107
 
98
- function _extends() {
99
- module.exports = _extends = Object.assign || function (target) {
100
- for (var i = 1; i < arguments.length; i++) {
101
- var source = arguments[i];
108
+ module.exports = require("react");
102
109
 
103
- for (var key in source) {
104
- if (Object.prototype.hasOwnProperty.call(source, key)) {
105
- target[key] = source[key];
106
- }
107
- }
110
+ /***/ }),
111
+ /* 2 */
112
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
113
+
114
+ "use strict";
115
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useUpdatingRef; });
116
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
117
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
118
+
119
+ /**
120
+ * Returns a ref whose .current value is updated whenever
121
+ * the `value` passed to this hook changes.
122
+ *
123
+ * this is great for values that you want to reference from
124
+ * within a useCallback or useEffect event listener, without
125
+ * re-triggering the effect when the value changes
126
+ *
127
+ * @returns {{current: T}}
128
+ */
129
+
130
+ const useUpdatingRef = value => {
131
+ const ref = Object(react__WEBPACK_IMPORTED_MODULE_0__["useRef"])(value);
132
+ Object(react__WEBPACK_IMPORTED_MODULE_0__["useEffect"])(() => {
133
+ ref.current = value;
134
+ }, [value]);
135
+ return ref;
136
+ };
137
+
138
+ /***/ }),
139
+ /* 3 */
140
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
141
+
142
+ "use strict";
143
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useInterval; });
144
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
145
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
146
+ /* harmony import */ var _internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
147
+
148
+
149
+ /**
150
+ * A simple hook for using `setInterval`.
151
+ *
152
+ * @param action called every `intervalMs` when `active` is true
153
+ * @param intervalMs the duration between calls to `action`
154
+ * @param active whether or not the interval is active
155
+ */
156
+
157
+ function useInterval(action, intervalMs, active) {
158
+ // We using a ref instead of a callback for `action` to avoid resetting
159
+ // the interval whenever the `action` changes.
160
+ const actionRef = Object(_internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_1__[/* useUpdatingRef */ "a"])(action);
161
+ Object(react__WEBPACK_IMPORTED_MODULE_0__["useEffect"])(() => {
162
+ if (active) {
163
+ const intervalId = setInterval(() => {
164
+ actionRef.current();
165
+ }, intervalMs);
166
+ return () => {
167
+ clearInterval(intervalId);
168
+ };
169
+ } // actionRef isn't actually required, but react-hooks/exhaustive-deps
170
+ // doesn't recognize it as a ref and thus complains if it isn't in the
171
+ // deps list. It isn't a big deal though since the value ofactionRef
172
+ // never changes (only its contents do).
173
+
174
+ }, [intervalMs, active, actionRef]);
175
+ }
176
+
177
+ /***/ }),
178
+ /* 4 */
179
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
180
+
181
+ "use strict";
182
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useTimeout; });
183
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
184
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
185
+ /* harmony import */ var _internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
186
+
187
+
188
+ /**
189
+ * A simple hook for using `setTimeout`.
190
+ *
191
+ * @param action called after `timeoutMs` when `active` is true
192
+ * @param timeoutMs the duration after which `action` is called
193
+ * @param active whether or not the interval is active
194
+ */
195
+
196
+ function useTimeout(action, timeoutMs, active) {
197
+ // We using a ref instead of a callback for `action` to avoid resetting
198
+ // the interval whenever the `action` changes.
199
+ const actionRef = Object(_internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_1__[/* useUpdatingRef */ "a"])(action);
200
+ Object(react__WEBPACK_IMPORTED_MODULE_0__["useEffect"])(() => {
201
+ if (active) {
202
+ const timeoutId = setTimeout(() => {
203
+ actionRef.current();
204
+ }, timeoutMs);
205
+ return () => {
206
+ clearTimeout(timeoutId);
207
+ };
208
+ } // actionRef isn't actually required, but react-hooks/exhaustive-deps
209
+ // doesn't recognize it as a ref and thus complains if it isn't in the
210
+ // deps list. It isn't a big deal though since the value ofactionRef
211
+ // never changes (only its contents do).
212
+
213
+ }, [timeoutMs, active, actionRef]);
214
+ }
215
+
216
+ /***/ }),
217
+ /* 5 */
218
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
219
+
220
+ "use strict";
221
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return withActionScheduler; });
222
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
223
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
224
+ /* harmony import */ var _action_scheduler_provider_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8);
225
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
226
+
227
+
228
+
229
+
230
+ /**
231
+ * A higher order component that attaches the given component to an
232
+ * `IScheduleActions` instance. Any actions scheduled will automatically be
233
+ * cleared on unmount.
234
+ *
235
+ * @template TOwnProps The own props of the component being rendered, without
236
+ * the additional action scheduler prop. To attach the additional prop to
237
+ * these props use the `WithActionScheduler` type.
238
+ */
239
+ function withActionScheduler(WrappedComponent) {
240
+ return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["forwardRef"]((props, ref) => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_action_scheduler_provider_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"], null, schedule => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](WrappedComponent, _extends({}, props, {
241
+ ref: ref,
242
+ schedule: schedule
243
+ }))));
244
+ }
245
+
246
+ /***/ }),
247
+ /* 6 */
248
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
249
+
250
+ "use strict";
251
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useScheduledInterval; });
252
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
253
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
254
+ /* harmony import */ var _util_policies_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
255
+ /* harmony import */ var _internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2);
256
+ /* harmony import */ var _use_interval_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(3);
257
+
258
+
259
+
260
+
261
+ function useScheduledInterval(action, intervalMs, options) {
262
+ var _options$schedulePoli;
263
+
264
+ if (typeof action !== "function") {
265
+ throw new Error("Action must be a function");
266
+ }
267
+
268
+ if (intervalMs < 1) {
269
+ throw new Error("Interval period must be >= 1");
270
+ }
271
+
272
+ const schedulePolicy = (_options$schedulePoli = options == null ? void 0 : options.schedulePolicy) != null ? _options$schedulePoli : _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* SchedulePolicy */ "b"].Immediately;
273
+ const [isSet, setIsSet] = Object(react__WEBPACK_IMPORTED_MODULE_0__["useState"])(schedulePolicy === _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* SchedulePolicy */ "b"].Immediately);
274
+ const set = Object(react__WEBPACK_IMPORTED_MODULE_0__["useCallback"])(() => setIsSet(true), []);
275
+ const actionRef = Object(_internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_2__[/* useUpdatingRef */ "a"])(action);
276
+ const clear = Object(react__WEBPACK_IMPORTED_MODULE_0__["useCallback"])(policy => {
277
+ var _policy;
278
+
279
+ policy = (_policy = policy) != null ? _policy : options == null ? void 0 : options.clearPolicy;
280
+
281
+ if (isSet && policy === _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* ClearPolicy */ "a"].Resolve) {
282
+ actionRef.current();
108
283
  }
109
284
 
110
- return target;
285
+ setIsSet(false);
286
+ }, // react-hooks/exhaustive-deps doesn't require refs to be
287
+ // listed in the deps array. Unfortunately, in this situation
288
+ // it doesn't recognized actionRef as a ref.
289
+ [actionRef, isSet, options == null ? void 0 : options.clearPolicy]);
290
+ const runOnUnmountRef = Object(_internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_2__[/* useUpdatingRef */ "a"])(isSet && (options == null ? void 0 : options.clearPolicy) === _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* ClearPolicy */ "a"].Resolve);
291
+ Object(react__WEBPACK_IMPORTED_MODULE_0__["useEffect"])(() => {
292
+ return () => {
293
+ // This code will only run with the component using this
294
+ // hook is unmounted.
295
+ // eslint-disable-next-line react-hooks/exhaustive-deps
296
+ if (runOnUnmountRef.current) {
297
+ // eslint-disable-next-line react-hooks/exhaustive-deps
298
+ actionRef.current();
299
+ }
300
+ }; // This eslint rule doesn't realize actionRef and runOnUnmountRef
301
+ // a both refs and thus do not have to be listed as deps.
302
+ // eslint-disable-next-line react-hooks/exhaustive-deps
303
+ }, []);
304
+ Object(_use_interval_js__WEBPACK_IMPORTED_MODULE_3__[/* useInterval */ "a"])(action, intervalMs, isSet);
305
+ return {
306
+ isSet,
307
+ set,
308
+ clear
111
309
  };
310
+ }
311
+
312
+ /***/ }),
313
+ /* 7 */
314
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
315
+
316
+ "use strict";
317
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useScheduledTimeout; });
318
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
319
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
320
+ /* harmony import */ var _util_policies_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
321
+ /* harmony import */ var _internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2);
322
+ /* harmony import */ var _use_timeout_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4);
323
+
112
324
 
113
- module.exports["default"] = module.exports, module.exports.__esModule = true;
114
- return _extends.apply(this, arguments);
325
+
326
+
327
+ function useScheduledTimeout(action, timeoutMs, options) {
328
+ var _options$schedulePoli;
329
+
330
+ if (typeof action !== "function") {
331
+ throw new Error("Action must be a function");
332
+ }
333
+
334
+ if (timeoutMs < 0) {
335
+ throw new Error("Timeout period must be >= 0");
336
+ }
337
+
338
+ const schedulePolicy = (_options$schedulePoli = options == null ? void 0 : options.schedulePolicy) != null ? _options$schedulePoli : _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* SchedulePolicy */ "b"].Immediately;
339
+ const [isSet, setIsSet] = Object(react__WEBPACK_IMPORTED_MODULE_0__["useState"])(schedulePolicy === _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* SchedulePolicy */ "b"].Immediately);
340
+ const set = Object(react__WEBPACK_IMPORTED_MODULE_0__["useCallback"])(() => setIsSet(true), []); // This wrapper isn't present in useScheduledInterval because we
341
+ // don't need to update `isSet` in that situations.
342
+
343
+ const wrappedAction = Object(react__WEBPACK_IMPORTED_MODULE_0__["useCallback"])(() => {
344
+ setIsSet(false);
345
+ action();
346
+ }, [action]);
347
+ const actionRef = Object(_internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_2__[/* useUpdatingRef */ "a"])(wrappedAction);
348
+ const clear = Object(react__WEBPACK_IMPORTED_MODULE_0__["useCallback"])(policy => {
349
+ var _policy;
350
+
351
+ policy = (_policy = policy) != null ? _policy : options == null ? void 0 : options.clearPolicy;
352
+
353
+ if (isSet && policy === _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* ClearPolicy */ "a"].Resolve) {
354
+ actionRef.current();
355
+ }
356
+
357
+ setIsSet(false);
358
+ }, // react-hooks/exhaustive-deps doesn't require refs to be
359
+ // listed in the deps array. Unfortunately, in this situation
360
+ // it doesn't recognized actionRef as a ref.
361
+ [actionRef, isSet, options == null ? void 0 : options.clearPolicy]);
362
+ const runOnUnmountRef = Object(_internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_2__[/* useUpdatingRef */ "a"])(isSet && (options == null ? void 0 : options.clearPolicy) === _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* ClearPolicy */ "a"].Resolve);
363
+ Object(react__WEBPACK_IMPORTED_MODULE_0__["useEffect"])(() => {
364
+ return () => {
365
+ // This code will only run with the component using this
366
+ // hook is unmounted.
367
+ // eslint-disable-next-line react-hooks/exhaustive-deps
368
+ if (runOnUnmountRef.current) {
369
+ // eslint-disable-next-line react-hooks/exhaustive-deps
370
+ actionRef.current();
371
+ }
372
+ }; // This eslint rule doesn't realize actionRef and runOnUnmountRef
373
+ // a both refs and thus do not have to be listed as deps.
374
+ // eslint-disable-next-line react-hooks/exhaustive-deps
375
+ }, []);
376
+ Object(_use_timeout_js__WEBPACK_IMPORTED_MODULE_3__[/* useTimeout */ "a"])(wrappedAction, timeoutMs, isSet);
377
+ return {
378
+ isSet,
379
+ set,
380
+ clear
381
+ };
115
382
  }
116
383
 
117
- module.exports = _extends;
118
- module.exports["default"] = module.exports, module.exports.__esModule = true;
384
+ /***/ }),
385
+ /* 8 */
386
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
387
+
388
+ "use strict";
389
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ActionSchedulerProvider; });
390
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
391
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
392
+ /* harmony import */ var _util_action_scheduler_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9);
393
+
394
+
395
+
396
+ /**
397
+ * A provider component that passes our action scheduling API to its children
398
+ * and ensures that all scheduled actions are cleared on unmount.
399
+ *
400
+ * ```jsx
401
+ * <ActionSchedulerProvider>
402
+ * {schedule => this.renderThingThatNeedsTimers(schedule)}
403
+ * </ActionSchedulerProvider>
404
+ * ```
405
+ */
406
+ class ActionSchedulerProvider extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
407
+ constructor(...args) {
408
+ super(...args);
409
+ this._actionScheduler = new _util_action_scheduler_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"]();
410
+ }
411
+
412
+ componentWillUnmount() {
413
+ this._actionScheduler.disable();
414
+ }
415
+
416
+ render() {
417
+ const {
418
+ children
419
+ } = this.props;
420
+ return children(this._actionScheduler);
421
+ }
422
+
423
+ }
119
424
 
120
425
  /***/ }),
121
- /* 2 */
426
+ /* 9 */
122
427
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
123
428
 
124
429
  "use strict";
125
- // ESM COMPAT FLAG
126
- __webpack_require__.r(__webpack_exports__);
430
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ActionScheduler; });
431
+ /* harmony import */ var _timeout_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(10);
432
+ /* harmony import */ var _interval_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(11);
433
+ /* harmony import */ var _animation_frame_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(12);
127
434
 
128
- // EXPORTS
129
- __webpack_require__.d(__webpack_exports__, "SchedulePolicy", function() { return /* reexport */ SchedulePolicy; });
130
- __webpack_require__.d(__webpack_exports__, "ClearPolicy", function() { return /* reexport */ ClearPolicy; });
131
- __webpack_require__.d(__webpack_exports__, "withActionScheduler", function() { return /* reexport */ withActionScheduler; });
132
435
 
133
- // CONCATENATED MODULE: ./packages/wonder-blocks-timing/src/util/policies.js
134
- const SchedulePolicy = {
135
- Immediately: "schedule-immediately",
136
- OnDemand: "schedule-on-demand"
137
- };
138
- const ClearPolicy = {
139
- Resolve: "resolve-on-clear",
140
- Cancel: "cancel-on-clear"
436
+
437
+
438
+ /**
439
+ * Implements the `IScheduleActions` API to provide timeout, interval, and
440
+ * animation frame support. This is not intended for direct use, but instead
441
+ * is to be used solely by the `ActionSchedulerProvider` to provide an
442
+ * `IScheduleActions` instance.
443
+ */
444
+ class ActionScheduler {
445
+ constructor() {
446
+ this._disabled = false;
447
+ this._registeredActions = [];
448
+ }
449
+
450
+ timeout(action, period, options) {
451
+ if (this._disabled) {
452
+ return ActionScheduler.NoopAction;
453
+ }
454
+
455
+ const timeout = new _timeout_js__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"](action, period, options == null ? void 0 : options.schedulePolicy);
456
+
457
+ this._registeredActions.push(() => timeout.clear(options == null ? void 0 : options.clearPolicy));
458
+
459
+ return timeout;
460
+ }
461
+
462
+ interval(action, period, options) {
463
+ if (this._disabled) {
464
+ return ActionScheduler.NoopAction;
465
+ }
466
+
467
+ const interval = new _interval_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"](action, period, options == null ? void 0 : options.schedulePolicy);
468
+
469
+ this._registeredActions.push(() => interval.clear(options == null ? void 0 : options.clearPolicy));
470
+
471
+ return interval;
472
+ }
473
+
474
+ animationFrame(action, options) {
475
+ if (this._disabled) {
476
+ return ActionScheduler.NoopAction;
477
+ }
478
+
479
+ const animationFrame = new _animation_frame_js__WEBPACK_IMPORTED_MODULE_2__[/* default */ "a"](action, options == null ? void 0 : options.schedulePolicy);
480
+
481
+ this._registeredActions.push(() => animationFrame.clear(options == null ? void 0 : options.clearPolicy));
482
+
483
+ return animationFrame;
484
+ }
485
+
486
+ clearAll() {
487
+ const registered = [].concat(this._registeredActions);
488
+ this._registeredActions = [];
489
+ registered.forEach(clearFn => clearFn());
490
+ }
491
+ /**
492
+ * Prevents this scheduler from creating any additional actions.
493
+ * This also clears any pending actions.
494
+ */
495
+
496
+
497
+ disable() {
498
+ this._disabled = true;
499
+ this.clearAll();
500
+ }
501
+
502
+ }
503
+ ActionScheduler.NoopAction = {
504
+ set: () => {},
505
+
506
+ get isSet() {
507
+ return false;
508
+ },
509
+
510
+ clear: () => {}
141
511
  };
142
- // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/extends.js
143
- var helpers_extends = __webpack_require__(1);
144
- var extends_default = /*#__PURE__*/__webpack_require__.n(helpers_extends);
145
512
 
146
- // EXTERNAL MODULE: external "react"
147
- var external_react_ = __webpack_require__(0);
513
+ /***/ }),
514
+ /* 10 */
515
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
148
516
 
149
- // CONCATENATED MODULE: ./packages/wonder-blocks-timing/src/util/timeout.js
517
+ "use strict";
518
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Timeout; });
519
+ /* harmony import */ var _policies_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
150
520
 
151
521
 
152
522
  /**
@@ -158,7 +528,7 @@ var external_react_ = __webpack_require__(0);
158
528
  * @class Timeout
159
529
  * @implements {ITimeout}
160
530
  */
161
- class timeout_Timeout {
531
+ class Timeout {
162
532
  /**
163
533
  * Creates a timeout that will invoke the given action after
164
534
  * the given period. The timeout does not start until set is called.
@@ -172,7 +542,7 @@ class timeout_Timeout {
172
542
  * Defaults to `SchedulePolicy.Immediately`.
173
543
  * @memberof Timeout
174
544
  */
175
- constructor(action, timeoutMs, schedulePolicy = SchedulePolicy.Immediately) {
545
+ constructor(action, timeoutMs, schedulePolicy = _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* SchedulePolicy */ "b"].Immediately) {
176
546
  if (typeof action !== "function") {
177
547
  throw new Error("Action must be a function");
178
548
  }
@@ -184,7 +554,7 @@ class timeout_Timeout {
184
554
  this._action = action;
185
555
  this._timeoutMs = timeoutMs;
186
556
 
187
- if (schedulePolicy === SchedulePolicy.Immediately) {
557
+ if (schedulePolicy === _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* SchedulePolicy */ "b"].Immediately) {
188
558
  this.set();
189
559
  }
190
560
  }
@@ -213,10 +583,10 @@ class timeout_Timeout {
213
583
 
214
584
  set() {
215
585
  if (this.isSet) {
216
- this.clear(ClearPolicy.Cancel);
586
+ this.clear(_policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Cancel);
217
587
  }
218
588
 
219
- this._timeoutId = setTimeout(() => this.clear(ClearPolicy.Resolve), this._timeoutMs);
589
+ this._timeoutId = setTimeout(() => this.clear(_policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Resolve), this._timeoutMs);
220
590
  }
221
591
  /**
222
592
  * Clear the set timeout.
@@ -234,7 +604,7 @@ class timeout_Timeout {
234
604
  */
235
605
 
236
606
 
237
- clear(policy = ClearPolicy.Cancel) {
607
+ clear(policy = _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Cancel) {
238
608
  const timeoutId = this._timeoutId;
239
609
  this._timeoutId = null;
240
610
 
@@ -244,13 +614,20 @@ class timeout_Timeout {
244
614
 
245
615
  clearTimeout(timeoutId);
246
616
 
247
- if (policy === ClearPolicy.Resolve) {
617
+ if (policy === _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Resolve) {
248
618
  this._action();
249
619
  }
250
620
  }
251
621
 
252
622
  }
253
- // CONCATENATED MODULE: ./packages/wonder-blocks-timing/src/util/interval.js
623
+
624
+ /***/ }),
625
+ /* 11 */
626
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
627
+
628
+ "use strict";
629
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Interval; });
630
+ /* harmony import */ var _policies_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
254
631
 
255
632
 
256
633
  /**
@@ -262,7 +639,7 @@ class timeout_Timeout {
262
639
  * @class Interval
263
640
  * @implements {IInterval}
264
641
  */
265
- class interval_Interval {
642
+ class Interval {
266
643
  /**
267
644
  * Creates an interval that will invoke the given action after
268
645
  * the given period. The interval does not start until set is called.
@@ -276,7 +653,7 @@ class interval_Interval {
276
653
  * Defaults to `SchedulePolicy.Immediately`.
277
654
  * @memberof Interval
278
655
  */
279
- constructor(action, intervalMs, schedulePolicy = SchedulePolicy.Immediately) {
656
+ constructor(action, intervalMs, schedulePolicy = _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* SchedulePolicy */ "b"].Immediately) {
280
657
  if (typeof action !== "function") {
281
658
  throw new Error("Action must be a function");
282
659
  }
@@ -288,7 +665,7 @@ class interval_Interval {
288
665
  this._action = action;
289
666
  this._intervalMs = intervalMs;
290
667
 
291
- if (schedulePolicy === SchedulePolicy.Immediately) {
668
+ if (schedulePolicy === _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* SchedulePolicy */ "b"].Immediately) {
292
669
  this.set();
293
670
  }
294
671
  }
@@ -315,7 +692,7 @@ class interval_Interval {
315
692
 
316
693
  set() {
317
694
  if (this.isSet) {
318
- this.clear(ClearPolicy.Cancel);
695
+ this.clear(_policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Cancel);
319
696
  }
320
697
 
321
698
  this._intervalId = setInterval(() => this._action(), this._intervalMs);
@@ -336,7 +713,7 @@ class interval_Interval {
336
713
  */
337
714
 
338
715
 
339
- clear(policy = ClearPolicy.Cancel) {
716
+ clear(policy = _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Cancel) {
340
717
  const intervalId = this._intervalId;
341
718
  this._intervalId = null;
342
719
 
@@ -346,13 +723,20 @@ class interval_Interval {
346
723
 
347
724
  clearInterval(intervalId);
348
725
 
349
- if (policy === ClearPolicy.Resolve) {
726
+ if (policy === _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Resolve) {
350
727
  this._action();
351
728
  }
352
729
  }
353
730
 
354
731
  }
355
- // CONCATENATED MODULE: ./packages/wonder-blocks-timing/src/util/animation-frame.js
732
+
733
+ /***/ }),
734
+ /* 12 */
735
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
736
+
737
+ "use strict";
738
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return AnimationFrame; });
739
+ /* harmony import */ var _policies_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
356
740
 
357
741
 
358
742
  /**
@@ -364,7 +748,7 @@ class interval_Interval {
364
748
  * @class AnimationFrame
365
749
  * @implements {IAnimationFrame}
366
750
  */
367
- class animation_frame_AnimationFrame {
751
+ class AnimationFrame {
368
752
  /**
369
753
  * Creates an animation frame request that will invoke the given action.
370
754
  * The request is not made until set is called.
@@ -376,14 +760,14 @@ class animation_frame_AnimationFrame {
376
760
  * Defaults to `SchedulePolicy.Immediately`.
377
761
  * @memberof AnimationFrame
378
762
  */
379
- constructor(action, schedulePolicy = SchedulePolicy.Immediately) {
763
+ constructor(action, schedulePolicy = _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* SchedulePolicy */ "b"].Immediately) {
380
764
  if (typeof action !== "function") {
381
765
  throw new Error("Action must be a function");
382
766
  }
383
767
 
384
768
  this._action = action;
385
769
 
386
- if (schedulePolicy === SchedulePolicy.Immediately) {
770
+ if (schedulePolicy === _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* SchedulePolicy */ "b"].Immediately) {
387
771
  this.set();
388
772
  }
389
773
  }
@@ -412,10 +796,10 @@ class animation_frame_AnimationFrame {
412
796
 
413
797
  set() {
414
798
  if (this.isSet) {
415
- this.clear(ClearPolicy.Cancel);
799
+ this.clear(_policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Cancel);
416
800
  }
417
801
 
418
- this._animationFrameId = requestAnimationFrame(time => this.clear(ClearPolicy.Resolve, time));
802
+ this._animationFrameId = requestAnimationFrame(time => this.clear(_policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Resolve, time));
419
803
  }
420
804
  /**
421
805
  * Clear the pending request.
@@ -436,7 +820,7 @@ class animation_frame_AnimationFrame {
436
820
  */
437
821
 
438
822
 
439
- clear(policy = ClearPolicy.Cancel, time) {
823
+ clear(policy = _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Cancel, time) {
440
824
  const animationFrameId = this._animationFrameId;
441
825
  this._animationFrameId = null;
442
826
 
@@ -446,144 +830,43 @@ class animation_frame_AnimationFrame {
446
830
 
447
831
  cancelAnimationFrame(animationFrameId);
448
832
 
449
- if (policy === ClearPolicy.Resolve) {
833
+ if (policy === _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Resolve) {
450
834
  this._action(time || performance.now());
451
835
  }
452
836
  }
453
837
 
454
838
  }
455
- // CONCATENATED MODULE: ./packages/wonder-blocks-timing/src/util/action-scheduler.js
456
-
457
-
458
-
459
-
460
- /**
461
- * Implements the `IScheduleActions` API to provide timeout, interval, and
462
- * animation frame support. This is not intended for direct use, but instead
463
- * is to be used solely by the `ActionSchedulerProvider` to provide an
464
- * `IScheduleActions` instance.
465
- */
466
- class action_scheduler_ActionScheduler {
467
- constructor() {
468
- this._disabled = false;
469
- this._registeredActions = [];
470
- }
471
-
472
- timeout(action, period, options) {
473
- if (this._disabled) {
474
- return action_scheduler_ActionScheduler.NoopAction;
475
- }
476
-
477
- const timeout = new timeout_Timeout(action, period, options == null ? void 0 : options.schedulePolicy);
478
-
479
- this._registeredActions.push(() => timeout.clear(options == null ? void 0 : options.clearPolicy));
480
-
481
- return timeout;
482
- }
483
-
484
- interval(action, period, options) {
485
- if (this._disabled) {
486
- return action_scheduler_ActionScheduler.NoopAction;
487
- }
488
-
489
- const interval = new interval_Interval(action, period, options == null ? void 0 : options.schedulePolicy);
490
-
491
- this._registeredActions.push(() => interval.clear(options == null ? void 0 : options.clearPolicy));
492
-
493
- return interval;
494
- }
495
839
 
496
- animationFrame(action, options) {
497
- if (this._disabled) {
498
- return action_scheduler_ActionScheduler.NoopAction;
499
- }
500
-
501
- const animationFrame = new animation_frame_AnimationFrame(action, options == null ? void 0 : options.schedulePolicy);
502
-
503
- this._registeredActions.push(() => animationFrame.clear(options == null ? void 0 : options.clearPolicy));
504
-
505
- return animationFrame;
506
- }
507
-
508
- clearAll() {
509
- const registered = [].concat(this._registeredActions);
510
- this._registeredActions = [];
511
- registered.forEach(clearFn => clearFn());
512
- }
513
- /**
514
- * Prevents this scheduler from creating any additional actions.
515
- * This also clears any pending actions.
516
- */
517
-
518
-
519
- disable() {
520
- this._disabled = true;
521
- this.clearAll();
522
- }
523
-
524
- }
525
- action_scheduler_ActionScheduler.NoopAction = {
526
- set: () => {},
840
+ /***/ }),
841
+ /* 13 */
842
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
527
843
 
528
- get isSet() {
529
- return false;
530
- },
844
+ "use strict";
845
+ __webpack_require__.r(__webpack_exports__);
846
+ /* harmony import */ var _util_policies_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
847
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "SchedulePolicy", function() { return _util_policies_js__WEBPACK_IMPORTED_MODULE_0__["b"]; });
531
848
 
532
- clear: () => {}
533
- };
534
- // CONCATENATED MODULE: ./packages/wonder-blocks-timing/src/components/action-scheduler-provider.js
849
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ClearPolicy", function() { return _util_policies_js__WEBPACK_IMPORTED_MODULE_0__["a"]; });
535
850
 
851
+ /* harmony import */ var _components_with_action_scheduler_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
852
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "withActionScheduler", function() { return _components_with_action_scheduler_js__WEBPACK_IMPORTED_MODULE_1__["a"]; });
536
853
 
854
+ /* harmony import */ var _hooks_use_interval_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3);
855
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useInterval", function() { return _hooks_use_interval_js__WEBPACK_IMPORTED_MODULE_2__["a"]; });
537
856
 
538
- /**
539
- * A provider component that passes our action scheduling API to its children
540
- * and ensures that all scheduled actions are cleared on unmount.
541
- *
542
- * ```jsx
543
- * <ActionSchedulerProvider>
544
- * {schedule => this.renderThingThatNeedsTimers(schedule)}
545
- * </ActionSchedulerProvider>
546
- * ```
547
- */
548
- class action_scheduler_provider_ActionSchedulerProvider extends external_react_["Component"] {
549
- constructor(...args) {
550
- super(...args);
551
- this._actionScheduler = new action_scheduler_ActionScheduler();
552
- }
857
+ /* harmony import */ var _hooks_use_timeout_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4);
858
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useTimeout", function() { return _hooks_use_timeout_js__WEBPACK_IMPORTED_MODULE_3__["a"]; });
553
859
 
554
- componentWillUnmount() {
555
- this._actionScheduler.disable();
556
- }
860
+ /* harmony import */ var _hooks_use_scheduled_interval_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6);
861
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useScheduledInterval", function() { return _hooks_use_scheduled_interval_js__WEBPACK_IMPORTED_MODULE_4__["a"]; });
557
862
 
558
- render() {
559
- const {
560
- children
561
- } = this.props;
562
- return children(this._actionScheduler);
563
- }
863
+ /* harmony import */ var _hooks_use_scheduled_timeout_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(7);
864
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useScheduledTimeout", function() { return _hooks_use_scheduled_timeout_js__WEBPACK_IMPORTED_MODULE_5__["a"]; });
564
865
 
565
- }
566
- // CONCATENATED MODULE: ./packages/wonder-blocks-timing/src/components/with-action-scheduler.js
567
866
 
568
867
 
569
868
 
570
869
 
571
- /**
572
- * A higher order component that attaches the given component to an
573
- * `IScheduleActions` instance. Any actions scheduled will automatically be
574
- * cleared on unmount.
575
- *
576
- * @template TOwnProps The own props of the component being rendered, without
577
- * the additional action scheduler prop. To attach the additional prop to
578
- * these props use the `WithActionScheduler` type.
579
- */
580
- function withActionScheduler(WrappedComponent) {
581
- return /*#__PURE__*/external_react_["forwardRef"]((props, ref) => /*#__PURE__*/external_react_["createElement"](action_scheduler_provider_ActionSchedulerProvider, null, schedule => /*#__PURE__*/external_react_["createElement"](WrappedComponent, extends_default()({}, props, {
582
- ref: ref,
583
- schedule: schedule
584
- }))));
585
- }
586
- // CONCATENATED MODULE: ./packages/wonder-blocks-timing/src/index.js
587
870
 
588
871
 
589
872