@stoplight/elements-dev-portal 1.4.8 → 1.5.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/index.esm.js CHANGED
@@ -1,15 +1,13 @@
1
1
  import { Menu, FieldButton, Modal, Input, Box, Icon, ListBox, ListBoxItem, Flex, VStack, Heading } from '@stoplight/mosaic';
2
2
  import * as React from 'react';
3
- import React__default from 'react';
3
+ import React__default, { useRef, useEffect, useMemo, useCallback, useState } from 'react';
4
4
  import { withQueryClientProvider, withMosaicProvider, PersistenceContextProvider, MarkdownComponentsProvider, MockingProvider, Docs, withStyles, withPersistenceBoundary, NodeTypeIconDefs, NodeTypeColors, TableOfContents as TableOfContents$1, PoweredByLink, useRouter, findFirstNode, ReactRouterMarkdownLink, SidebarLayout } from '@stoplight/elements-core';
5
5
  import { resolve, dirname } from '@stoplight/path';
6
6
  import { NodeType } from '@stoplight/types';
7
- import { faSearch } from '@fortawesome/free-solid-svg-icons/faSearch';
8
- import { flow } from 'lodash';
7
+ import { faSearch, faCircleNotch, faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
8
+ import flow from 'lodash/flow.js';
9
9
  import { Route, useParams, useHistory, Redirect, Link } from 'react-router-dom';
10
- import { faCircleNotch, faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
11
10
  import { useQuery } from 'react-query';
12
- import { useDebounce } from 'use-debounce';
13
11
 
14
12
  const BranchSelector = ({ branchSlug, branches, onChange }) => {
15
13
  const currentBranch = branches.find(branch => (!branchSlug ? branch.is_default : branch.slug === branchSlug));
@@ -182,7 +180,7 @@ const UpgradeToStarter = () => (React__default.createElement(Flex, { as: "a", hr
182
180
  React__default.createElement(Icon, { icon: faExclamationTriangle, size: "4x" }),
183
181
  React__default.createElement(Box, { pt: 3 }, "Please upgrade your Stoplight Workspace to the Starter Plan to use Elements Dev Portal in production.")));
184
182
 
185
- const appVersion = '1.4.8';
183
+ const appVersion = '1.5.0';
186
184
 
187
185
  class ResponseError extends Error {
188
186
  constructor(message, responseCode) {
@@ -362,6 +360,233 @@ const getWorkspace = ({ projectIds, platformUrl = 'https://stoplight.io', platfo
362
360
  return data;
363
361
  });
364
362
 
363
+ /**
364
+ * Creates a debounced function that delays invoking `func` until after `wait`
365
+ * milliseconds have elapsed since the last time the debounced function was
366
+ * invoked, or until the next browser frame is drawn. The debounced function
367
+ * comes with a `cancel` method to cancel delayed `func` invocations and a
368
+ * `flush` method to immediately invoke them. Provide `options` to indicate
369
+ * whether `func` should be invoked on the leading and/or trailing edge of the
370
+ * `wait` timeout. The `func` is invoked with the last arguments provided to the
371
+ * debounced function. Subsequent calls to the debounced function return the
372
+ * result of the last `func` invocation.
373
+ *
374
+ * **Note:** If `leading` and `trailing` options are `true`, `func` is
375
+ * invoked on the trailing edge of the timeout only if the debounced function
376
+ * is invoked more than once during the `wait` timeout.
377
+ *
378
+ * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
379
+ * until the next tick, similar to `setTimeout` with a timeout of `0`.
380
+ *
381
+ * If `wait` is omitted in an environment with `requestAnimationFrame`, `func`
382
+ * invocation will be deferred until the next frame is drawn (typically about
383
+ * 16ms).
384
+ *
385
+ * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
386
+ * for details over the differences between `debounce` and `throttle`.
387
+ *
388
+ * @category Function
389
+ * @param {Function} func The function to debounce.
390
+ * @param {number} [wait=0]
391
+ * The number of milliseconds to delay; if omitted, `requestAnimationFrame` is
392
+ * used (if available, otherwise it will be setTimeout(...,0)).
393
+ * @param {Object} [options={}] The options object.
394
+ * Specify invoking on the leading edge of the timeout.
395
+ * @param {boolean} [options.leading=false]
396
+ * The maximum time `func` is allowed to be delayed before it's invoked.
397
+ * @param {number} [options.maxWait]
398
+ * Specify invoking on the trailing edge of the timeout.
399
+ * @param {boolean} [options.trailing=true]
400
+ * @returns {Function} Returns the new debounced function.
401
+ * @example
402
+ *
403
+ * // Avoid costly calculations while the window size is in flux.
404
+ * const resizeHandler = useDebouncedCallback(calculateLayout, 150);
405
+ * window.addEventListener('resize', resizeHandler)
406
+ *
407
+ * // Invoke `sendMail` when clicked, debouncing subsequent calls.
408
+ * const clickHandler = useDebouncedCallback(sendMail, 300, {
409
+ * leading: true,
410
+ * trailing: false,
411
+ * })
412
+ * <button onClick={clickHandler}>click me</button>
413
+ *
414
+ * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
415
+ * const debounced = useDebouncedCallback(batchLog, 250, { 'maxWait': 1000 })
416
+ * const source = new EventSource('/stream')
417
+ * source.addEventListener('message', debounced)
418
+ *
419
+ * // Cancel the trailing debounced invocation.
420
+ * window.addEventListener('popstate', debounced.cancel)
421
+ *
422
+ * // Check for pending invocations.
423
+ * const status = debounced.pending() ? "Pending..." : "Ready"
424
+ */
425
+ function useDebouncedCallback(func, wait, options) {
426
+ var _this = this;
427
+ var lastCallTime = useRef(null);
428
+ var lastInvokeTime = useRef(0);
429
+ var timerId = useRef(null);
430
+ var lastArgs = useRef([]);
431
+ var lastThis = useRef();
432
+ var result = useRef();
433
+ var funcRef = useRef(func);
434
+ var mounted = useRef(true);
435
+ funcRef.current = func;
436
+ // Bypass `requestAnimationFrame` by explicitly setting `wait=0`.
437
+ var useRAF = !wait && wait !== 0 && typeof window !== 'undefined';
438
+ if (typeof func !== 'function') {
439
+ throw new TypeError('Expected a function');
440
+ }
441
+ wait = +wait || 0;
442
+ options = options || {};
443
+ var leading = !!options.leading;
444
+ var trailing = 'trailing' in options ? !!options.trailing : true; // `true` by default
445
+ var maxing = 'maxWait' in options;
446
+ var maxWait = maxing ? Math.max(+options.maxWait || 0, wait) : null;
447
+ useEffect(function () {
448
+ mounted.current = true;
449
+ return function () {
450
+ mounted.current = false;
451
+ };
452
+ }, []);
453
+ // You may have a question, why we have so many code under the useMemo definition.
454
+ //
455
+ // This was made as we want to escape from useCallback hell and
456
+ // not to initialize a number of functions each time useDebouncedCallback is called.
457
+ //
458
+ // It means that we have less garbage for our GC calls which improves performance.
459
+ // Also, it makes this library smaller.
460
+ //
461
+ // And the last reason, that the code without lots of useCallback with deps is easier to read.
462
+ // You have only one place for that.
463
+ var debounced = useMemo(function () {
464
+ var invokeFunc = function (time) {
465
+ var args = lastArgs.current;
466
+ var thisArg = lastThis.current;
467
+ lastArgs.current = lastThis.current = null;
468
+ lastInvokeTime.current = time;
469
+ return (result.current = funcRef.current.apply(thisArg, args));
470
+ };
471
+ var startTimer = function (pendingFunc, wait) {
472
+ if (useRAF)
473
+ cancelAnimationFrame(timerId.current);
474
+ timerId.current = useRAF ? requestAnimationFrame(pendingFunc) : setTimeout(pendingFunc, wait);
475
+ };
476
+ var shouldInvoke = function (time) {
477
+ if (!mounted.current)
478
+ return false;
479
+ var timeSinceLastCall = time - lastCallTime.current;
480
+ var timeSinceLastInvoke = time - lastInvokeTime.current;
481
+ // Either this is the first call, activity has stopped and we're at the
482
+ // trailing edge, the system time has gone backwards and we're treating
483
+ // it as the trailing edge, or we've hit the `maxWait` limit.
484
+ return (!lastCallTime.current ||
485
+ timeSinceLastCall >= wait ||
486
+ timeSinceLastCall < 0 ||
487
+ (maxing && timeSinceLastInvoke >= maxWait));
488
+ };
489
+ var trailingEdge = function (time) {
490
+ timerId.current = null;
491
+ // Only invoke if we have `lastArgs` which means `func` has been
492
+ // debounced at least once.
493
+ if (trailing && lastArgs.current) {
494
+ return invokeFunc(time);
495
+ }
496
+ lastArgs.current = lastThis.current = null;
497
+ return result.current;
498
+ };
499
+ var timerExpired = function () {
500
+ var time = Date.now();
501
+ if (shouldInvoke(time)) {
502
+ return trailingEdge(time);
503
+ }
504
+ // https://github.com/xnimorz/use-debounce/issues/97
505
+ if (!mounted.current) {
506
+ return;
507
+ }
508
+ // Remaining wait calculation
509
+ var timeSinceLastCall = time - lastCallTime.current;
510
+ var timeSinceLastInvoke = time - lastInvokeTime.current;
511
+ var timeWaiting = wait - timeSinceLastCall;
512
+ var remainingWait = maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
513
+ // Restart the timer
514
+ startTimer(timerExpired, remainingWait);
515
+ };
516
+ var func = function () {
517
+ var args = [];
518
+ for (var _i = 0; _i < arguments.length; _i++) {
519
+ args[_i] = arguments[_i];
520
+ }
521
+ var time = Date.now();
522
+ var isInvoking = shouldInvoke(time);
523
+ lastArgs.current = args;
524
+ lastThis.current = _this;
525
+ lastCallTime.current = time;
526
+ if (isInvoking) {
527
+ if (!timerId.current && mounted.current) {
528
+ // Reset any `maxWait` timer.
529
+ lastInvokeTime.current = lastCallTime.current;
530
+ // Start the timer for the trailing edge.
531
+ startTimer(timerExpired, wait);
532
+ // Invoke the leading edge.
533
+ return leading ? invokeFunc(lastCallTime.current) : result.current;
534
+ }
535
+ if (maxing) {
536
+ // Handle invocations in a tight loop.
537
+ startTimer(timerExpired, wait);
538
+ return invokeFunc(lastCallTime.current);
539
+ }
540
+ }
541
+ if (!timerId.current) {
542
+ startTimer(timerExpired, wait);
543
+ }
544
+ return result.current;
545
+ };
546
+ func.cancel = function () {
547
+ if (timerId.current) {
548
+ useRAF ? cancelAnimationFrame(timerId.current) : clearTimeout(timerId.current);
549
+ }
550
+ lastInvokeTime.current = 0;
551
+ lastArgs.current = lastCallTime.current = lastThis.current = timerId.current = null;
552
+ };
553
+ func.isPending = function () {
554
+ return !!timerId.current;
555
+ };
556
+ func.flush = function () {
557
+ return !timerId.current ? result.current : trailingEdge(Date.now());
558
+ };
559
+ return func;
560
+ }, [leading, maxing, wait, maxWait, trailing, useRAF]);
561
+ return debounced;
562
+ }
563
+
564
+ function valueEquality(left, right) {
565
+ return left === right;
566
+ }
567
+ function adjustFunctionValueOfSetState(value) {
568
+ return typeof value === 'function' ? function () { return value; } : value;
569
+ }
570
+ function useStateIgnoreCallback(initialState) {
571
+ var _a = useState(adjustFunctionValueOfSetState(initialState)), state = _a[0], setState = _a[1];
572
+ var setStateIgnoreCallback = useCallback(function (value) { return setState(adjustFunctionValueOfSetState(value)); }, []);
573
+ return [state, setStateIgnoreCallback];
574
+ }
575
+ function useDebounce(value, delay, options) {
576
+ var eq = (options && options.equalityFn) || valueEquality;
577
+ var _a = useStateIgnoreCallback(value), state = _a[0], dispatch = _a[1];
578
+ var debounced = useDebouncedCallback(useCallback(function (value) { return dispatch(value); }, [dispatch]), delay, options);
579
+ var previousValue = useRef(value);
580
+ useEffect(function () {
581
+ // We need to use this condition otherwise we will run debounce timer for the first render (including maxWait option)
582
+ if (!eq(previousValue.current, value)) {
583
+ debounced(value);
584
+ previousValue.current = value;
585
+ }
586
+ }, [value, debounced, eq]);
587
+ return [state, { cancel: debounced.cancel, isPending: debounced.isPending, flush: debounced.flush }];
588
+ }
589
+
365
590
  function useGetNodes({ search, workspaceId, branchSlug, projectIds, pause, }) {
366
591
  const { platformUrl, platformAuthToken } = React.useContext(PlatformContext);
367
592
  const [debounceSearch] = useDebounce(search, 500);
package/index.js CHANGED
@@ -7,12 +7,10 @@ var React = require('react');
7
7
  var elementsCore = require('@stoplight/elements-core');
8
8
  var path = require('@stoplight/path');
9
9
  var types = require('@stoplight/types');
10
- var faSearch = require('@fortawesome/free-solid-svg-icons/faSearch');
11
- var lodash = require('lodash');
12
- var reactRouterDom = require('react-router-dom');
13
10
  var freeSolidSvgIcons = require('@fortawesome/free-solid-svg-icons');
11
+ var flow = require('lodash/flow.js');
12
+ var reactRouterDom = require('react-router-dom');
14
13
  var reactQuery = require('react-query');
15
- var useDebounce = require('use-debounce');
16
14
 
17
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
16
 
@@ -36,6 +34,7 @@ function _interopNamespace(e) {
36
34
 
37
35
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
38
36
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
37
+ var flow__default = /*#__PURE__*/_interopDefaultLegacy(flow);
39
38
 
40
39
  const BranchSelector = ({ branchSlug, branches, onChange }) => {
41
40
  const currentBranch = branches.find(branch => (!branchSlug ? branch.is_default : branch.slug === branchSlug));
@@ -133,7 +132,7 @@ const SearchImpl = ({ search, searchResults, isOpen, onClose, onClick, onSearch
133
132
  onClick(selectedResult);
134
133
  }
135
134
  }, [searchResults, onClick]);
136
- return (React__namespace.createElement(mosaic.Modal, { renderHeader: () => (React__namespace.createElement(mosaic.Input, { appearance: "minimal", borderB: true, size: "lg", icon: React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, ml: 1, icon: faSearch.faSearch }), autoFocus: true, placeholder: "Search...", value: search, onChange: onChange, onKeyDown: onKeyDown })), isOpen: !!isOpen, onClose: onClose }, searchResults && searchResults.length > 0 ? (React__namespace.createElement(mosaic.ListBox, { ref: listBoxRef, "aria-label": "Search", overflowY: "auto", h: 80, m: -5, items: searchResults, selectionMode: "single", onSelectionChange: onSelectionChange }, (searchResult) => {
135
+ return (React__namespace.createElement(mosaic.Modal, { renderHeader: () => (React__namespace.createElement(mosaic.Input, { appearance: "minimal", borderB: true, size: "lg", icon: React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, ml: 1, icon: freeSolidSvgIcons.faSearch }), autoFocus: true, placeholder: "Search...", value: search, onChange: onChange, onKeyDown: onKeyDown })), isOpen: !!isOpen, onClose: onClose }, searchResults && searchResults.length > 0 ? (React__namespace.createElement(mosaic.ListBox, { ref: listBoxRef, "aria-label": "Search", overflowY: "auto", h: 80, m: -5, items: searchResults, selectionMode: "single", onSelectionChange: onSelectionChange }, (searchResult) => {
137
136
  var _a, _b;
138
137
  return (React__namespace.createElement(mosaic.ListBoxItem, { key: `${searchResult.id}-${searchResult.project_id}`, textValue: searchResult.title },
139
138
  React__namespace.createElement(mosaic.Box, { p: 3, borderB: true },
@@ -144,7 +143,7 @@ const SearchImpl = ({ search, searchResults, isOpen, onClose, onClick, onSearch
144
143
  React__namespace.createElement(mosaic.Box, { dangerouslySetInnerHTML: { __html: (_b = searchResult.highlighted.summary) !== null && _b !== void 0 ? _b : '' }, color: "muted", fontSize: "sm", mt: 1, ml: 6 }))));
145
144
  })) : (React__namespace.createElement(mosaic.Flex, { w: "full", h: 80, align: "center", justify: "center", m: -5 }, "No search results"))));
146
145
  };
147
- const Search = lodash.flow(elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(SearchImpl);
146
+ const Search = flow__default["default"](elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(SearchImpl);
148
147
 
149
148
  /*! *****************************************************************************
150
149
  Copyright (c) Microsoft Corporation.
@@ -208,7 +207,7 @@ const UpgradeToStarter = () => (React__default["default"].createElement(mosaic.F
208
207
  React__default["default"].createElement(mosaic.Icon, { icon: freeSolidSvgIcons.faExclamationTriangle, size: "4x" }),
209
208
  React__default["default"].createElement(mosaic.Box, { pt: 3 }, "Please upgrade your Stoplight Workspace to the Starter Plan to use Elements Dev Portal in production.")));
210
209
 
211
- const appVersion = '1.4.8';
210
+ const appVersion = '1.5.0';
212
211
 
213
212
  class ResponseError extends Error {
214
213
  constructor(message, responseCode) {
@@ -345,7 +344,7 @@ const StoplightProjectRouter = (_a) => {
345
344
  React__namespace.createElement(reactRouterDom.Route, { path: "/", exact: true },
346
345
  React__namespace.createElement(StoplightProjectImpl, Object.assign({}, props))))));
347
346
  };
348
- const StoplightProject = lodash.flow(elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(StoplightProjectRouter);
347
+ const StoplightProject = flow__default["default"](elementsCore.withStyles, elementsCore.withPersistenceBoundary, elementsCore.withMosaicProvider, elementsCore.withQueryClientProvider)(StoplightProjectRouter);
349
348
 
350
349
  const getNodes = ({ workspaceId, branchSlug, projectIds, search, platformUrl = 'https://stoplight.io', platformAuthToken, }) => __awaiter(void 0, void 0, void 0, function* () {
351
350
  const queryParams = [];
@@ -388,9 +387,236 @@ const getWorkspace = ({ projectIds, platformUrl = 'https://stoplight.io', platfo
388
387
  return data;
389
388
  });
390
389
 
390
+ /**
391
+ * Creates a debounced function that delays invoking `func` until after `wait`
392
+ * milliseconds have elapsed since the last time the debounced function was
393
+ * invoked, or until the next browser frame is drawn. The debounced function
394
+ * comes with a `cancel` method to cancel delayed `func` invocations and a
395
+ * `flush` method to immediately invoke them. Provide `options` to indicate
396
+ * whether `func` should be invoked on the leading and/or trailing edge of the
397
+ * `wait` timeout. The `func` is invoked with the last arguments provided to the
398
+ * debounced function. Subsequent calls to the debounced function return the
399
+ * result of the last `func` invocation.
400
+ *
401
+ * **Note:** If `leading` and `trailing` options are `true`, `func` is
402
+ * invoked on the trailing edge of the timeout only if the debounced function
403
+ * is invoked more than once during the `wait` timeout.
404
+ *
405
+ * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
406
+ * until the next tick, similar to `setTimeout` with a timeout of `0`.
407
+ *
408
+ * If `wait` is omitted in an environment with `requestAnimationFrame`, `func`
409
+ * invocation will be deferred until the next frame is drawn (typically about
410
+ * 16ms).
411
+ *
412
+ * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
413
+ * for details over the differences between `debounce` and `throttle`.
414
+ *
415
+ * @category Function
416
+ * @param {Function} func The function to debounce.
417
+ * @param {number} [wait=0]
418
+ * The number of milliseconds to delay; if omitted, `requestAnimationFrame` is
419
+ * used (if available, otherwise it will be setTimeout(...,0)).
420
+ * @param {Object} [options={}] The options object.
421
+ * Specify invoking on the leading edge of the timeout.
422
+ * @param {boolean} [options.leading=false]
423
+ * The maximum time `func` is allowed to be delayed before it's invoked.
424
+ * @param {number} [options.maxWait]
425
+ * Specify invoking on the trailing edge of the timeout.
426
+ * @param {boolean} [options.trailing=true]
427
+ * @returns {Function} Returns the new debounced function.
428
+ * @example
429
+ *
430
+ * // Avoid costly calculations while the window size is in flux.
431
+ * const resizeHandler = useDebouncedCallback(calculateLayout, 150);
432
+ * window.addEventListener('resize', resizeHandler)
433
+ *
434
+ * // Invoke `sendMail` when clicked, debouncing subsequent calls.
435
+ * const clickHandler = useDebouncedCallback(sendMail, 300, {
436
+ * leading: true,
437
+ * trailing: false,
438
+ * })
439
+ * <button onClick={clickHandler}>click me</button>
440
+ *
441
+ * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
442
+ * const debounced = useDebouncedCallback(batchLog, 250, { 'maxWait': 1000 })
443
+ * const source = new EventSource('/stream')
444
+ * source.addEventListener('message', debounced)
445
+ *
446
+ * // Cancel the trailing debounced invocation.
447
+ * window.addEventListener('popstate', debounced.cancel)
448
+ *
449
+ * // Check for pending invocations.
450
+ * const status = debounced.pending() ? "Pending..." : "Ready"
451
+ */
452
+ function useDebouncedCallback(func, wait, options) {
453
+ var _this = this;
454
+ var lastCallTime = React.useRef(null);
455
+ var lastInvokeTime = React.useRef(0);
456
+ var timerId = React.useRef(null);
457
+ var lastArgs = React.useRef([]);
458
+ var lastThis = React.useRef();
459
+ var result = React.useRef();
460
+ var funcRef = React.useRef(func);
461
+ var mounted = React.useRef(true);
462
+ funcRef.current = func;
463
+ // Bypass `requestAnimationFrame` by explicitly setting `wait=0`.
464
+ var useRAF = !wait && wait !== 0 && typeof window !== 'undefined';
465
+ if (typeof func !== 'function') {
466
+ throw new TypeError('Expected a function');
467
+ }
468
+ wait = +wait || 0;
469
+ options = options || {};
470
+ var leading = !!options.leading;
471
+ var trailing = 'trailing' in options ? !!options.trailing : true; // `true` by default
472
+ var maxing = 'maxWait' in options;
473
+ var maxWait = maxing ? Math.max(+options.maxWait || 0, wait) : null;
474
+ React.useEffect(function () {
475
+ mounted.current = true;
476
+ return function () {
477
+ mounted.current = false;
478
+ };
479
+ }, []);
480
+ // You may have a question, why we have so many code under the useMemo definition.
481
+ //
482
+ // This was made as we want to escape from useCallback hell and
483
+ // not to initialize a number of functions each time useDebouncedCallback is called.
484
+ //
485
+ // It means that we have less garbage for our GC calls which improves performance.
486
+ // Also, it makes this library smaller.
487
+ //
488
+ // And the last reason, that the code without lots of useCallback with deps is easier to read.
489
+ // You have only one place for that.
490
+ var debounced = React.useMemo(function () {
491
+ var invokeFunc = function (time) {
492
+ var args = lastArgs.current;
493
+ var thisArg = lastThis.current;
494
+ lastArgs.current = lastThis.current = null;
495
+ lastInvokeTime.current = time;
496
+ return (result.current = funcRef.current.apply(thisArg, args));
497
+ };
498
+ var startTimer = function (pendingFunc, wait) {
499
+ if (useRAF)
500
+ cancelAnimationFrame(timerId.current);
501
+ timerId.current = useRAF ? requestAnimationFrame(pendingFunc) : setTimeout(pendingFunc, wait);
502
+ };
503
+ var shouldInvoke = function (time) {
504
+ if (!mounted.current)
505
+ return false;
506
+ var timeSinceLastCall = time - lastCallTime.current;
507
+ var timeSinceLastInvoke = time - lastInvokeTime.current;
508
+ // Either this is the first call, activity has stopped and we're at the
509
+ // trailing edge, the system time has gone backwards and we're treating
510
+ // it as the trailing edge, or we've hit the `maxWait` limit.
511
+ return (!lastCallTime.current ||
512
+ timeSinceLastCall >= wait ||
513
+ timeSinceLastCall < 0 ||
514
+ (maxing && timeSinceLastInvoke >= maxWait));
515
+ };
516
+ var trailingEdge = function (time) {
517
+ timerId.current = null;
518
+ // Only invoke if we have `lastArgs` which means `func` has been
519
+ // debounced at least once.
520
+ if (trailing && lastArgs.current) {
521
+ return invokeFunc(time);
522
+ }
523
+ lastArgs.current = lastThis.current = null;
524
+ return result.current;
525
+ };
526
+ var timerExpired = function () {
527
+ var time = Date.now();
528
+ if (shouldInvoke(time)) {
529
+ return trailingEdge(time);
530
+ }
531
+ // https://github.com/xnimorz/use-debounce/issues/97
532
+ if (!mounted.current) {
533
+ return;
534
+ }
535
+ // Remaining wait calculation
536
+ var timeSinceLastCall = time - lastCallTime.current;
537
+ var timeSinceLastInvoke = time - lastInvokeTime.current;
538
+ var timeWaiting = wait - timeSinceLastCall;
539
+ var remainingWait = maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
540
+ // Restart the timer
541
+ startTimer(timerExpired, remainingWait);
542
+ };
543
+ var func = function () {
544
+ var args = [];
545
+ for (var _i = 0; _i < arguments.length; _i++) {
546
+ args[_i] = arguments[_i];
547
+ }
548
+ var time = Date.now();
549
+ var isInvoking = shouldInvoke(time);
550
+ lastArgs.current = args;
551
+ lastThis.current = _this;
552
+ lastCallTime.current = time;
553
+ if (isInvoking) {
554
+ if (!timerId.current && mounted.current) {
555
+ // Reset any `maxWait` timer.
556
+ lastInvokeTime.current = lastCallTime.current;
557
+ // Start the timer for the trailing edge.
558
+ startTimer(timerExpired, wait);
559
+ // Invoke the leading edge.
560
+ return leading ? invokeFunc(lastCallTime.current) : result.current;
561
+ }
562
+ if (maxing) {
563
+ // Handle invocations in a tight loop.
564
+ startTimer(timerExpired, wait);
565
+ return invokeFunc(lastCallTime.current);
566
+ }
567
+ }
568
+ if (!timerId.current) {
569
+ startTimer(timerExpired, wait);
570
+ }
571
+ return result.current;
572
+ };
573
+ func.cancel = function () {
574
+ if (timerId.current) {
575
+ useRAF ? cancelAnimationFrame(timerId.current) : clearTimeout(timerId.current);
576
+ }
577
+ lastInvokeTime.current = 0;
578
+ lastArgs.current = lastCallTime.current = lastThis.current = timerId.current = null;
579
+ };
580
+ func.isPending = function () {
581
+ return !!timerId.current;
582
+ };
583
+ func.flush = function () {
584
+ return !timerId.current ? result.current : trailingEdge(Date.now());
585
+ };
586
+ return func;
587
+ }, [leading, maxing, wait, maxWait, trailing, useRAF]);
588
+ return debounced;
589
+ }
590
+
591
+ function valueEquality(left, right) {
592
+ return left === right;
593
+ }
594
+ function adjustFunctionValueOfSetState(value) {
595
+ return typeof value === 'function' ? function () { return value; } : value;
596
+ }
597
+ function useStateIgnoreCallback(initialState) {
598
+ var _a = React.useState(adjustFunctionValueOfSetState(initialState)), state = _a[0], setState = _a[1];
599
+ var setStateIgnoreCallback = React.useCallback(function (value) { return setState(adjustFunctionValueOfSetState(value)); }, []);
600
+ return [state, setStateIgnoreCallback];
601
+ }
602
+ function useDebounce(value, delay, options) {
603
+ var eq = (options && options.equalityFn) || valueEquality;
604
+ var _a = useStateIgnoreCallback(value), state = _a[0], dispatch = _a[1];
605
+ var debounced = useDebouncedCallback(React.useCallback(function (value) { return dispatch(value); }, [dispatch]), delay, options);
606
+ var previousValue = React.useRef(value);
607
+ React.useEffect(function () {
608
+ // We need to use this condition otherwise we will run debounce timer for the first render (including maxWait option)
609
+ if (!eq(previousValue.current, value)) {
610
+ debounced(value);
611
+ previousValue.current = value;
612
+ }
613
+ }, [value, debounced, eq]);
614
+ return [state, { cancel: debounced.cancel, isPending: debounced.isPending, flush: debounced.flush }];
615
+ }
616
+
391
617
  function useGetNodes({ search, workspaceId, branchSlug, projectIds, pause, }) {
392
618
  const { platformUrl, platformAuthToken } = React__namespace.useContext(PlatformContext);
393
- const [debounceSearch] = useDebounce.useDebounce(search, 500);
619
+ const [debounceSearch] = useDebounce(search, 500);
394
620
  return reactQuery.useQuery(['workspaceNodes', workspaceId, branchSlug, projectIds, debounceSearch, platformUrl, platformAuthToken], () => getNodes({ workspaceId, branchSlug, projectIds, search: debounceSearch, platformUrl, platformAuthToken }), { enabled: !pause });
395
621
  }
396
622