@wordpress/compose 5.15.2 → 5.16.1-next.4d3b314fd5.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/CHANGELOG.md +11 -0
- package/README.md +86 -8
- package/build/higher-order/compose.js +5 -4
- package/build/higher-order/compose.js.map +1 -1
- package/build/higher-order/pipe.js +93 -0
- package/build/higher-order/pipe.js.map +1 -0
- package/build/hooks/use-debounce/index.js +11 -10
- package/build/hooks/use-debounce/index.js.map +1 -1
- package/build/hooks/use-disabled/index.js +3 -1
- package/build/hooks/use-disabled/index.js.map +1 -1
- package/build/hooks/use-drop-zone/index.js +4 -10
- package/build/hooks/use-drop-zone/index.js.map +1 -1
- package/build/hooks/use-fixed-window-list/index.js +5 -5
- package/build/hooks/use-fixed-window-list/index.js.map +1 -1
- package/build/hooks/use-instance-id/index.js +22 -20
- package/build/hooks/use-instance-id/index.js.map +1 -1
- package/build/hooks/use-throttle/index.js +12 -8
- package/build/hooks/use-throttle/index.js.map +1 -1
- package/build/index.js +37 -0
- package/build/index.js.map +1 -1
- package/build/index.native.js +37 -0
- package/build/index.native.js.map +1 -1
- package/build/utils/debounce/index.js +230 -0
- package/build/utils/debounce/index.js.map +1 -0
- package/build/utils/throttle/index.js +98 -0
- package/build/utils/throttle/index.js.map +1 -0
- package/build-module/higher-order/compose.js +4 -3
- package/build-module/higher-order/compose.js.map +1 -1
- package/build-module/higher-order/pipe.js +85 -0
- package/build-module/higher-order/pipe.js.map +1 -0
- package/build-module/hooks/use-debounce/index.js +10 -9
- package/build-module/hooks/use-debounce/index.js.map +1 -1
- package/build-module/hooks/use-disabled/index.js +3 -2
- package/build-module/hooks/use-disabled/index.js.map +1 -1
- package/build-module/hooks/use-drop-zone/index.js +4 -10
- package/build-module/hooks/use-drop-zone/index.js.map +1 -1
- package/build-module/hooks/use-fixed-window-list/index.js +5 -5
- package/build-module/hooks/use-fixed-window-list/index.js.map +1 -1
- package/build-module/hooks/use-instance-id/index.js +20 -19
- package/build-module/hooks/use-instance-id/index.js.map +1 -1
- package/build-module/hooks/use-throttle/index.js +11 -7
- package/build-module/hooks/use-throttle/index.js.map +1 -1
- package/build-module/index.js +7 -2
- package/build-module/index.js.map +1 -1
- package/build-module/index.native.js +7 -2
- package/build-module/index.native.js.map +1 -1
- package/build-module/utils/debounce/index.js +221 -0
- package/build-module/utils/debounce/index.js.map +1 -0
- package/build-module/utils/throttle/index.js +88 -0
- package/build-module/utils/throttle/index.js.map +1 -0
- package/build-types/higher-order/compose.d.ts +2 -5
- package/build-types/higher-order/compose.d.ts.map +1 -1
- package/build-types/higher-order/pipe.d.ts +61 -0
- package/build-types/higher-order/pipe.d.ts.map +1 -0
- package/build-types/hooks/use-debounce/index.d.ts +6 -6
- package/build-types/hooks/use-debounce/index.d.ts.map +1 -1
- package/build-types/hooks/use-disabled/index.d.ts.map +1 -1
- package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
- package/build-types/hooks/use-instance-id/index.d.ts +11 -6
- package/build-types/hooks/use-instance-id/index.d.ts.map +1 -1
- package/build-types/hooks/use-throttle/index.d.ts +6 -6
- package/build-types/hooks/use-throttle/index.d.ts.map +1 -1
- package/build-types/index.d.ts +3 -0
- package/build-types/utils/debounce/index.d.ts +104 -0
- package/build-types/utils/debounce/index.d.ts.map +1 -0
- package/build-types/utils/throttle/index.d.ts +77 -0
- package/build-types/utils/throttle/index.d.ts.map +1 -0
- package/package.json +8 -8
- package/src/higher-order/compose.ts +5 -3
- package/src/higher-order/pipe.ts +76 -0
- package/src/higher-order/test/compose.ts +39 -0
- package/src/higher-order/test/pipe.ts +37 -0
- package/src/hooks/use-debounce/index.js +11 -9
- package/src/hooks/use-disabled/index.js +3 -2
- package/src/hooks/use-drop-zone/index.js +6 -13
- package/src/hooks/use-fixed-window-list/index.js +5 -5
- package/src/hooks/use-instance-id/index.ts +59 -0
- package/src/hooks/use-throttle/index.js +11 -7
- package/src/index.js +6 -1
- package/src/index.native.js +6 -1
- package/src/utils/debounce/index.ts +260 -0
- package/src/utils/debounce/test/index.ts +367 -0
- package/src/utils/throttle/index.ts +95 -0
- package/src/utils/throttle/test/index.ts +256 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/hooks/use-instance-id/index.js +0 -42
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-fixed-window-list/index.js"],"names":["DEFAULT_INIT_WINDOW_SIZE","useFixedWindowList","elementRef","itemHeight","totalItems","options","initWindowSize","useWindowing","fixedListWindow","setFixedListWindow","visibleItems","start","end","itemInView","index","scrollContainer","current","measureWindow","initRender","Math","ceil","clientHeight","windowOverscan","firstViewableIndex","floor","scrollTop","max","min","lastWindow","nextWindow","debounceMeasureList","addEventListener","ownerDocument","defaultView","removeEventListener","handleKeyDown","event","keyCode","HOME","scrollTo","top","END","PAGEUP","PAGEDOWN"],"mappings":";;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAVA;AACA;AACA;;AAGA;AACA;AACA;AAKA,MAAMA,wBAAwB,GAAG,EAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,kBAAT,CACdC,UADc,EAEdC,UAFc,EAGdC,UAHc,EAIdC,OAJc,EAKb;AAAA;;AACD,QAAMC,cAAc,4BAAGD,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEC,cAAZ,yEAA8BN,wBAAlD;AACA,QAAMO,YAAY,4BAAGF,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEE,YAAZ,yEAA4B,IAA9C;AAEA,QAAM,CAAEC,eAAF,EAAmBC,kBAAnB,IAA0C,uBAAU;AACzDC,IAAAA,YAAY,EAAEJ,cAD2C;AAEzDK,IAAAA,KAAK,EAAE,CAFkD;AAGzDC,IAAAA,GAAG,EAAEN,cAHoD;AAIzDO,IAAAA,UAAU,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CAAEF,eAAF,EAAmBC,kBAAnB,CAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { debounce } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useLayoutEffect } from '@wordpress/element';\nimport { getScrollContainer } from '@wordpress/dom';\nimport { PAGEUP, PAGEDOWN, HOME, END } from '@wordpress/keycodes';\n\nconst DEFAULT_INIT_WINDOW_SIZE = 30;\n\n/**\n * @typedef {Object} WPFixedWindowList\n *\n * @property {number} visibleItems Items visible in the current viewport\n * @property {number} start Start index of the window\n * @property {number} end End index of the window\n * @property {(index:number)=>boolean} itemInView Returns true if item is in the window\n */\n\n/**\n * @typedef {Object} WPFixedWindowListOptions\n *\n * @property {number} [windowOverscan] Renders windowOverscan number of items before and after the calculated visible window.\n * @property {boolean} [useWindowing] When false avoids calculating the window size\n * @property {number} [initWindowSize] Initial window size to use on first render before we can calculate the window size.\n */\n\n/**\n *\n * @param {import('react').RefObject<HTMLElement>} elementRef Used to find the closest scroll container that contains element.\n * @param { number } itemHeight Fixed item height in pixels\n * @param { number } totalItems Total items in list\n * @param { WPFixedWindowListOptions } [options] Options object\n * @return {[ WPFixedWindowList, setFixedListWindow:(nextWindow:WPFixedWindowList)=>void]} Array with the fixed window list and setter\n */\nexport default function useFixedWindowList(\n\telementRef,\n\titemHeight,\n\ttotalItems,\n\toptions\n) {\n\tconst initWindowSize = options?.initWindowSize ?? DEFAULT_INIT_WINDOW_SIZE;\n\tconst useWindowing = options?.useWindowing ?? true;\n\n\tconst [ fixedListWindow, setFixedListWindow ] = useState( {\n\t\tvisibleItems: initWindowSize,\n\t\tstart: 0,\n\t\tend: initWindowSize,\n\t\titemInView: ( /** @type {number} */ index ) => {\n\t\t\treturn index >= 0 && index <= initWindowSize;\n\t\t},\n\t} );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! useWindowing ) {\n\t\t\treturn;\n\t\t}\n\t\tconst scrollContainer = getScrollContainer( elementRef.current );\n\t\tconst measureWindow = (\n\t\t\t/** @type {boolean | undefined} */ initRender\n\t\t) => {\n\t\t\tif ( ! scrollContainer ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst visibleItems = Math.ceil(\n\t\t\t\tscrollContainer.clientHeight / itemHeight\n\t\t\t);\n\t\t\t// Aim to keep opening list view fast, afterward we can optimize for scrolling.\n\t\t\tconst windowOverscan = initRender\n\t\t\t\t? visibleItems\n\t\t\t\t: options?.windowOverscan ?? visibleItems;\n\t\t\tconst firstViewableIndex = Math.floor(\n\t\t\t\tscrollContainer.scrollTop / itemHeight\n\t\t\t);\n\t\t\tconst start = Math.max( 0, firstViewableIndex - windowOverscan );\n\t\t\tconst end = Math.min(\n\t\t\t\ttotalItems - 1,\n\t\t\t\tfirstViewableIndex + visibleItems + windowOverscan\n\t\t\t);\n\t\t\tsetFixedListWindow( ( lastWindow ) => {\n\t\t\t\tconst nextWindow = {\n\t\t\t\t\tvisibleItems,\n\t\t\t\t\tstart,\n\t\t\t\t\tend,\n\t\t\t\t\titemInView: ( /** @type {number} */ index ) => {\n\t\t\t\t\t\treturn start <= index && index <= end;\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\tif (\n\t\t\t\t\tlastWindow.start !== nextWindow.start ||\n\t\t\t\t\tlastWindow.end !== nextWindow.end ||\n\t\t\t\t\tlastWindow.visibleItems !== nextWindow.visibleItems\n\t\t\t\t) {\n\t\t\t\t\treturn nextWindow;\n\t\t\t\t}\n\t\t\t\treturn lastWindow;\n\t\t\t} );\n\t\t};\n\n\t\tmeasureWindow( true );\n\t\tconst debounceMeasureList = debounce( () => {\n\t\t\tmeasureWindow();\n\t\t}, 16 );\n\t\tscrollContainer?.addEventListener( 'scroll', debounceMeasureList );\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'resize',\n\t\t\tdebounceMeasureList\n\t\t);\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'resize',\n\t\t\tdebounceMeasureList\n\t\t);\n\n\t\treturn () => {\n\t\t\tscrollContainer?.removeEventListener(\n\t\t\t\t'scroll',\n\t\t\t\tdebounceMeasureList\n\t\t\t);\n\t\t\tscrollContainer?.ownerDocument?.defaultView?.removeEventListener(\n\t\t\t\t'resize',\n\t\t\t\tdebounceMeasureList\n\t\t\t);\n\t\t};\n\t}, [ itemHeight, elementRef, totalItems ] );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! useWindowing ) {\n\t\t\treturn;\n\t\t}\n\t\tconst scrollContainer = getScrollContainer( elementRef.current );\n\t\tconst handleKeyDown = ( /** @type {KeyboardEvent} */ event ) => {\n\t\t\tswitch ( event.keyCode ) {\n\t\t\t\tcase HOME: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( { top: 0 } );\n\t\t\t\t}\n\t\t\t\tcase END: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop: totalItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\tcase PAGEUP: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop:\n\t\t\t\t\t\t\tscrollContainer.scrollTop -\n\t\t\t\t\t\t\tfixedListWindow.visibleItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\tcase PAGEDOWN: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop:\n\t\t\t\t\t\t\tscrollContainer.scrollTop +\n\t\t\t\t\t\t\tfixedListWindow.visibleItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'keydown',\n\t\t\thandleKeyDown\n\t\t);\n\t\treturn () => {\n\t\t\tscrollContainer?.ownerDocument?.defaultView?.removeEventListener(\n\t\t\t\t'keydown',\n\t\t\t\thandleKeyDown\n\t\t\t);\n\t\t};\n\t}, [ totalItems, itemHeight, elementRef, fixedListWindow.visibleItems ] );\n\n\treturn [ fixedListWindow, setFixedListWindow ];\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-fixed-window-list/index.js"],"names":["DEFAULT_INIT_WINDOW_SIZE","useFixedWindowList","elementRef","itemHeight","totalItems","options","initWindowSize","useWindowing","fixedListWindow","setFixedListWindow","visibleItems","start","end","itemInView","index","scrollContainer","current","measureWindow","initRender","Math","ceil","clientHeight","windowOverscan","firstViewableIndex","floor","scrollTop","max","min","lastWindow","nextWindow","debounceMeasureList","addEventListener","ownerDocument","defaultView","removeEventListener","handleKeyDown","event","keyCode","HOME","scrollTo","top","END","PAGEUP","PAGEDOWN"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;AAGA,MAAMA,wBAAwB,GAAG,EAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,kBAAT,CACdC,UADc,EAEdC,UAFc,EAGdC,UAHc,EAIdC,OAJc,EAKb;AAAA;;AACD,QAAMC,cAAc,4BAAGD,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEC,cAAZ,yEAA8BN,wBAAlD;AACA,QAAMO,YAAY,4BAAGF,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEE,YAAZ,yEAA4B,IAA9C;AAEA,QAAM,CAAEC,eAAF,EAAmBC,kBAAnB,IAA0C,uBAAU;AACzDC,IAAAA,YAAY,EAAEJ,cAD2C;AAEzDK,IAAAA,KAAK,EAAE,CAFkD;AAGzDC,IAAAA,GAAG,EAAEN,cAHoD;AAIzDO,IAAAA,UAAU,EAAE;AAAE;AAAsBC,IAAAA,KAAxB,KAAmC;AAC9C,aAAOA,KAAK,IAAI,CAAT,IAAcA,KAAK,IAAIR,cAA9B;AACA;AANwD,GAAV,CAAhD;AASA,gCAAiB,M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eAAe,CAAEwB,QAAjB,CAA2B;AAAEC,cAAAA,GAAG,EAAE;AAAP,aAA3B,CAAP;AACA;;AACD,aAAKC,aAAL;AAAU;AACT,mBAAO1B,eAAP,aAAOA,eAAP,uBAAOA,eAAe,CAAEwB,QAAjB,CAA2B;AACjCC,cAAAA,GAAG,EAAEpC,UAAU,GAAGD;AADe,aAA3B,CAAP;AAGA;;AACD,aAAKuC,gBAAL;AAAa;AACZ,mBAAO3B,eAAP,aAAOA,eAAP,uBAAOA,eAAe,CAAEwB,QAAjB,CAA2B;AACjCC,cAAAA,GAAG,EACFzB,eAAe,CAACU,SAAhB,GACAjB,eAAe,CAACE,YAAhB,GAA+BP;AAHC,aAA3B,CAAP;AAKA;;AACD,aAAKwC,kBAAL;AAAe;AACd,mBAAO5B,eAAP,aAAOA,eAAP,uBAAOA,eAAe,CAAEwB,QAAjB,CAA2B;AACjCC,cAAAA,GAAG,EACFzB,eAAe,CAACU,SAAhB,GACAjB,eAAe,CAACE,YAAhB,GAA+BP;AAHC,aAA3B,CAAP;AAKA;AAtBF;AAwBA,KAzBD;;AA0BAY,IAAAA,eAAe,SAAf,IAAAA,eAAe,WAAf,sCAAAA,eAAe,CAAEiB,aAAjB,4GAAgCC,WAAhC,kFAA6CF,gBAA7C,CACC,SADD,EAECI,aAFD;AAIA,WAAO,MAAM;AAAA;;AACZpB,MAAAA,eAAe,SAAf,IAAAA,eAAe,WAAf,sCAAAA,eAAe,CAAEiB,aAAjB,6GAAgCC,WAAhC,oFAA6CC,mBAA7C,CACC,SADD,EAECC,aAFD;AAIA,KALD;AAMA,GAzCD,EAyCG,CAAE/B,UAAF,EAAcD,UAAd,EAA0BD,UAA1B,EAAsCM,eAAe,CAACE,YAAtD,CAzCH;AA2CA,SAAO,CAAEF,eAAF,EAAmBC,kBAAnB,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useLayoutEffect } from '@wordpress/element';\nimport { getScrollContainer } from '@wordpress/dom';\nimport { PAGEUP, PAGEDOWN, HOME, END } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\n\nconst DEFAULT_INIT_WINDOW_SIZE = 30;\n\n/**\n * @typedef {Object} WPFixedWindowList\n *\n * @property {number} visibleItems Items visible in the current viewport\n * @property {number} start Start index of the window\n * @property {number} end End index of the window\n * @property {(index:number)=>boolean} itemInView Returns true if item is in the window\n */\n\n/**\n * @typedef {Object} WPFixedWindowListOptions\n *\n * @property {number} [windowOverscan] Renders windowOverscan number of items before and after the calculated visible window.\n * @property {boolean} [useWindowing] When false avoids calculating the window size\n * @property {number} [initWindowSize] Initial window size to use on first render before we can calculate the window size.\n */\n\n/**\n *\n * @param {import('react').RefObject<HTMLElement>} elementRef Used to find the closest scroll container that contains element.\n * @param { number } itemHeight Fixed item height in pixels\n * @param { number } totalItems Total items in list\n * @param { WPFixedWindowListOptions } [options] Options object\n * @return {[ WPFixedWindowList, setFixedListWindow:(nextWindow:WPFixedWindowList)=>void]} Array with the fixed window list and setter\n */\nexport default function useFixedWindowList(\n\telementRef,\n\titemHeight,\n\ttotalItems,\n\toptions\n) {\n\tconst initWindowSize = options?.initWindowSize ?? DEFAULT_INIT_WINDOW_SIZE;\n\tconst useWindowing = options?.useWindowing ?? true;\n\n\tconst [ fixedListWindow, setFixedListWindow ] = useState( {\n\t\tvisibleItems: initWindowSize,\n\t\tstart: 0,\n\t\tend: initWindowSize,\n\t\titemInView: ( /** @type {number} */ index ) => {\n\t\t\treturn index >= 0 && index <= initWindowSize;\n\t\t},\n\t} );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! useWindowing ) {\n\t\t\treturn;\n\t\t}\n\t\tconst scrollContainer = getScrollContainer( elementRef.current );\n\t\tconst measureWindow = (\n\t\t\t/** @type {boolean | undefined} */ initRender\n\t\t) => {\n\t\t\tif ( ! scrollContainer ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst visibleItems = Math.ceil(\n\t\t\t\tscrollContainer.clientHeight / itemHeight\n\t\t\t);\n\t\t\t// Aim to keep opening list view fast, afterward we can optimize for scrolling.\n\t\t\tconst windowOverscan = initRender\n\t\t\t\t? visibleItems\n\t\t\t\t: options?.windowOverscan ?? visibleItems;\n\t\t\tconst firstViewableIndex = Math.floor(\n\t\t\t\tscrollContainer.scrollTop / itemHeight\n\t\t\t);\n\t\t\tconst start = Math.max( 0, firstViewableIndex - windowOverscan );\n\t\t\tconst end = Math.min(\n\t\t\t\ttotalItems - 1,\n\t\t\t\tfirstViewableIndex + visibleItems + windowOverscan\n\t\t\t);\n\t\t\tsetFixedListWindow( ( lastWindow ) => {\n\t\t\t\tconst nextWindow = {\n\t\t\t\t\tvisibleItems,\n\t\t\t\t\tstart,\n\t\t\t\t\tend,\n\t\t\t\t\titemInView: ( /** @type {number} */ index ) => {\n\t\t\t\t\t\treturn start <= index && index <= end;\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\tif (\n\t\t\t\t\tlastWindow.start !== nextWindow.start ||\n\t\t\t\t\tlastWindow.end !== nextWindow.end ||\n\t\t\t\t\tlastWindow.visibleItems !== nextWindow.visibleItems\n\t\t\t\t) {\n\t\t\t\t\treturn nextWindow;\n\t\t\t\t}\n\t\t\t\treturn lastWindow;\n\t\t\t} );\n\t\t};\n\n\t\tmeasureWindow( true );\n\t\tconst debounceMeasureList = debounce( () => {\n\t\t\tmeasureWindow();\n\t\t}, 16 );\n\t\tscrollContainer?.addEventListener( 'scroll', debounceMeasureList );\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'resize',\n\t\t\tdebounceMeasureList\n\t\t);\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'resize',\n\t\t\tdebounceMeasureList\n\t\t);\n\n\t\treturn () => {\n\t\t\tscrollContainer?.removeEventListener(\n\t\t\t\t'scroll',\n\t\t\t\tdebounceMeasureList\n\t\t\t);\n\t\t\tscrollContainer?.ownerDocument?.defaultView?.removeEventListener(\n\t\t\t\t'resize',\n\t\t\t\tdebounceMeasureList\n\t\t\t);\n\t\t};\n\t}, [ itemHeight, elementRef, totalItems ] );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! useWindowing ) {\n\t\t\treturn;\n\t\t}\n\t\tconst scrollContainer = getScrollContainer( elementRef.current );\n\t\tconst handleKeyDown = ( /** @type {KeyboardEvent} */ event ) => {\n\t\t\tswitch ( event.keyCode ) {\n\t\t\t\tcase HOME: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( { top: 0 } );\n\t\t\t\t}\n\t\t\t\tcase END: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop: totalItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\tcase PAGEUP: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop:\n\t\t\t\t\t\t\tscrollContainer.scrollTop -\n\t\t\t\t\t\t\tfixedListWindow.visibleItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\tcase PAGEDOWN: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop:\n\t\t\t\t\t\t\tscrollContainer.scrollTop +\n\t\t\t\t\t\t\tfixedListWindow.visibleItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'keydown',\n\t\t\thandleKeyDown\n\t\t);\n\t\treturn () => {\n\t\t\tscrollContainer?.ownerDocument?.defaultView?.removeEventListener(\n\t\t\t\t'keydown',\n\t\t\t\thandleKeyDown\n\t\t\t);\n\t\t};\n\t}, [ totalItems, itemHeight, elementRef, fixedListWindow.visibleItems ] );\n\n\treturn [ fixedListWindow, setFixedListWindow ];\n}\n"]}
|
|
@@ -3,28 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
var _element = require("@wordpress/element");
|
|
9
9
|
|
|
10
|
-
// Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case
|
|
11
|
-
// but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript
|
|
12
|
-
|
|
13
|
-
/* eslint-disable jsdoc/check-types */
|
|
14
|
-
|
|
15
10
|
/**
|
|
16
11
|
* WordPress dependencies
|
|
17
12
|
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @type {WeakMap<object, number>}
|
|
21
|
-
*/
|
|
22
13
|
const instanceMap = new WeakMap();
|
|
23
14
|
/**
|
|
24
15
|
* Creates a new id for a given object.
|
|
25
16
|
*
|
|
26
|
-
* @param
|
|
27
|
-
* @return
|
|
17
|
+
* @param object Object reference to create an id for.
|
|
18
|
+
* @return The instance id (index).
|
|
28
19
|
*/
|
|
29
20
|
|
|
30
21
|
function createId(object) {
|
|
@@ -33,22 +24,33 @@ function createId(object) {
|
|
|
33
24
|
return instances;
|
|
34
25
|
}
|
|
35
26
|
/**
|
|
36
|
-
*
|
|
27
|
+
* Specify the useInstanceId *function* signatures.
|
|
37
28
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
29
|
+
* More accurately, useInstanceId distinguishes between three different
|
|
30
|
+
* signatures:
|
|
31
|
+
*
|
|
32
|
+
* 1. When only object is given, the returned value is a number
|
|
33
|
+
* 2. When object and prefix is given, the returned value is a string
|
|
34
|
+
* 3. When preferredId is given, the returned value is the type of preferredId
|
|
42
35
|
*/
|
|
43
36
|
|
|
44
37
|
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Provides a unique instance ID.
|
|
40
|
+
*
|
|
41
|
+
* @param object Object reference to create an id for.
|
|
42
|
+
* @param [prefix] Prefix for the unique id.
|
|
43
|
+
* @param [preferredId] Default ID to use.
|
|
44
|
+
* @return The unique instance id.
|
|
45
|
+
*/
|
|
46
|
+
function useInstanceId(object, prefix, preferredId) {
|
|
47
47
|
return (0, _element.useMemo)(() => {
|
|
48
48
|
if (preferredId) return preferredId;
|
|
49
49
|
const id = createId(object);
|
|
50
50
|
return prefix ? `${prefix}-${id}` : id;
|
|
51
51
|
}, [object]);
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
|
|
54
|
+
var _default = useInstanceId;
|
|
55
|
+
exports.default = _default;
|
|
54
56
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-instance-id/index.
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-instance-id/index.ts"],"names":["instanceMap","WeakMap","createId","object","instances","get","set","useInstanceId","prefix","preferredId","id"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;AAGA,MAAMA,WAAW,GAAG,IAAIC,OAAJ,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,QAAT,CAAmBC,MAAnB,EAA4C;AAC3C,QAAMC,SAAS,GAAGJ,WAAW,CAACK,GAAZ,CAAiBF,MAAjB,KAA6B,CAA/C;AACAH,EAAAA,WAAW,CAACM,GAAZ,CAAiBH,MAAjB,EAAyBC,SAAS,GAAG,CAArC;AACA,SAAOA,SAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASG,aAAT,CACCJ,MADD,EAECK,MAFD,EAGCC,WAHD,EAImB;AAClB,SAAO,sBAAS,MAAM;AACrB,QAAKA,WAAL,EAAmB,OAAOA,WAAP;AACnB,UAAMC,EAAE,GAAGR,QAAQ,CAAEC,MAAF,CAAnB;AAEA,WAAOK,MAAM,GAAI,GAAGA,MAAQ,IAAIE,EAAI,EAAvB,GAA2BA,EAAxC;AACA,GALM,EAKJ,CAAEP,MAAF,CALI,CAAP;AAMA;;eAEcI,a","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\nconst instanceMap = new WeakMap< object, number >();\n\n/**\n * Creates a new id for a given object.\n *\n * @param object Object reference to create an id for.\n * @return The instance id (index).\n */\nfunction createId( object: object ): number {\n\tconst instances = instanceMap.get( object ) || 0;\n\tinstanceMap.set( object, instances + 1 );\n\treturn instances;\n}\n\n/**\n * Specify the useInstanceId *function* signatures.\n *\n * More accurately, useInstanceId distinguishes between three different\n * signatures:\n *\n * 1. When only object is given, the returned value is a number\n * 2. When object and prefix is given, the returned value is a string\n * 3. When preferredId is given, the returned value is the type of preferredId\n */\nfunction useInstanceId( object: object ): number;\nfunction useInstanceId( object: object, prefix: string ): string;\nfunction useInstanceId< T extends string | number >(\n\tobject: object,\n\tprefix: string,\n\tpreferredId?: T\n): T;\n\n/**\n * Provides a unique instance ID.\n *\n * @param object Object reference to create an id for.\n * @param [prefix] Prefix for the unique id.\n * @param [preferredId] Default ID to use.\n * @return The unique instance id.\n */\nfunction useInstanceId(\n\tobject: object,\n\tprefix?: string,\n\tpreferredId?: string | number\n): string | number {\n\treturn useMemo( () => {\n\t\tif ( preferredId ) return preferredId;\n\t\tconst id = createId( object );\n\n\t\treturn prefix ? `${ prefix }-${ id }` : id;\n\t}, [ object ] );\n}\n\nexport default useInstanceId;\n"]}
|
|
@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = useThrottle;
|
|
7
7
|
|
|
8
|
-
var _lodash = require("lodash");
|
|
9
|
-
|
|
10
8
|
var _useMemoOne = require("use-memo-one");
|
|
11
9
|
|
|
12
10
|
var _element = require("@wordpress/element");
|
|
13
11
|
|
|
12
|
+
var _throttle = require("../../utils/throttle");
|
|
13
|
+
|
|
14
14
|
/**
|
|
15
15
|
* External dependencies
|
|
16
16
|
*/
|
|
@@ -20,7 +20,11 @@ var _element = require("@wordpress/element");
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Internal dependencies
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Throttles a function similar to Lodash's `throttle`. A new throttled function will
|
|
24
28
|
* be returned and any scheduled calls cancelled if any of the arguments change,
|
|
25
29
|
* including the function to throttle, so please wrap functions created on
|
|
26
30
|
* render in components in `useCallback`.
|
|
@@ -29,13 +33,13 @@ var _element = require("@wordpress/element");
|
|
|
29
33
|
*
|
|
30
34
|
* @template {(...args: any[]) => void} TFunc
|
|
31
35
|
*
|
|
32
|
-
* @param {TFunc}
|
|
33
|
-
* @param {number}
|
|
34
|
-
* @param {import('
|
|
35
|
-
* @return {import('
|
|
36
|
+
* @param {TFunc} fn The function to throttle.
|
|
37
|
+
* @param {number} [wait] The number of milliseconds to throttle invocations to.
|
|
38
|
+
* @param {import('../../utils/throttle').ThrottleOptions} [options] The options object. See linked documentation for details.
|
|
39
|
+
* @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Throttled function.
|
|
36
40
|
*/
|
|
37
41
|
function useThrottle(fn, wait, options) {
|
|
38
|
-
const throttled = (0, _useMemoOne.useMemoOne)(() => (0,
|
|
42
|
+
const throttled = (0, _useMemoOne.useMemoOne)(() => (0, _throttle.throttle)(fn, wait !== null && wait !== void 0 ? wait : 0, options), [fn, wait, options]);
|
|
39
43
|
(0, _element.useEffect)(() => () => throttled.cancel(), [throttled]);
|
|
40
44
|
return throttled;
|
|
41
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-throttle/index.js"],"names":["useThrottle","fn","wait","options","throttled","cancel"],"mappings":";;;;;;;AAGA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-throttle/index.js"],"names":["useThrottle","fn","wait","options","throttled","cancel"],"mappings":";;;;;;;AAGA;;AAKA;;AAKA;;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,WAAT,CAAsBC,EAAtB,EAA0BC,IAA1B,EAAgCC,OAAhC,EAA0C;AACxD,QAAMC,SAAS,GAAG,4BACjB,MAAM,wBAAUH,EAAV,EAAcC,IAAd,aAAcA,IAAd,cAAcA,IAAd,GAAsB,CAAtB,EAAyBC,OAAzB,CADW,EAEjB,CAAEF,EAAF,EAAMC,IAAN,EAAYC,OAAZ,CAFiB,CAAlB;AAIA,0BAAW,MAAM,MAAMC,SAAS,CAACC,MAAV,EAAvB,EAA2C,CAAED,SAAF,CAA3C;AACA,SAAOA,SAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { throttle } from '../../utils/throttle';\n\n/**\n * Throttles a function similar to Lodash's `throttle`. A new throttled function will\n * be returned and any scheduled calls cancelled if any of the arguments change,\n * including the function to throttle, so please wrap functions created on\n * render in components in `useCallback`.\n *\n * @see https://docs-lodash.com/v4/throttle/\n *\n * @template {(...args: any[]) => void} TFunc\n *\n * @param {TFunc} fn The function to throttle.\n * @param {number} [wait] The number of milliseconds to throttle invocations to.\n * @param {import('../../utils/throttle').ThrottleOptions} [options] The options object. See linked documentation for details.\n * @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Throttled function.\n */\nexport default function useThrottle( fn, wait, options ) {\n\tconst throttled = useMemoOne(\n\t\t() => throttle( fn, wait ?? 0, options ),\n\t\t[ fn, wait, options ]\n\t);\n\tuseEffect( () => () => throttled.cancel(), [ throttled ] );\n\treturn throttled;\n}\n"]}
|
package/build/index.js
CHANGED
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
var _exportNames = {
|
|
9
9
|
compose: true,
|
|
10
|
+
pipe: true,
|
|
10
11
|
ifCondition: true,
|
|
11
12
|
pure: true,
|
|
12
13
|
withGlobalEvents: true,
|
|
@@ -82,6 +83,12 @@ Object.defineProperty(exports, "ifCondition", {
|
|
|
82
83
|
return _ifCondition.default;
|
|
83
84
|
}
|
|
84
85
|
});
|
|
86
|
+
Object.defineProperty(exports, "pipe", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
get: function () {
|
|
89
|
+
return _pipe.default;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
85
92
|
Object.defineProperty(exports, "pure", {
|
|
86
93
|
enumerable: true,
|
|
87
94
|
get: function () {
|
|
@@ -253,8 +260,38 @@ Object.keys(_createHigherOrderComponent).forEach(function (key) {
|
|
|
253
260
|
});
|
|
254
261
|
});
|
|
255
262
|
|
|
263
|
+
var _debounce = require("./utils/debounce");
|
|
264
|
+
|
|
265
|
+
Object.keys(_debounce).forEach(function (key) {
|
|
266
|
+
if (key === "default" || key === "__esModule") return;
|
|
267
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
268
|
+
if (key in exports && exports[key] === _debounce[key]) return;
|
|
269
|
+
Object.defineProperty(exports, key, {
|
|
270
|
+
enumerable: true,
|
|
271
|
+
get: function () {
|
|
272
|
+
return _debounce[key];
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
var _throttle = require("./utils/throttle");
|
|
278
|
+
|
|
279
|
+
Object.keys(_throttle).forEach(function (key) {
|
|
280
|
+
if (key === "default" || key === "__esModule") return;
|
|
281
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
282
|
+
if (key in exports && exports[key] === _throttle[key]) return;
|
|
283
|
+
Object.defineProperty(exports, key, {
|
|
284
|
+
enumerable: true,
|
|
285
|
+
get: function () {
|
|
286
|
+
return _throttle[key];
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
256
291
|
var _compose = _interopRequireDefault(require("./higher-order/compose"));
|
|
257
292
|
|
|
293
|
+
var _pipe = _interopRequireDefault(require("./higher-order/pipe"));
|
|
294
|
+
|
|
258
295
|
var _ifCondition = _interopRequireDefault(require("./higher-order/if-condition"));
|
|
259
296
|
|
|
260
297
|
var _pure = _interopRequireDefault(require("./higher-order/pure"));
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA","sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as useCopyOnClick } from './hooks/use-copy-on-click';\nexport { default as useCopyToClipboard } from './hooks/use-copy-to-clipboard';\nexport { default as __experimentalUseDialog } from './hooks/use-dialog';\nexport { default as useDisabled } from './hooks/use-disabled';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as useFocusOnMount } from './hooks/use-focus-on-mount';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useFocusReturn } from './hooks/use-focus-return';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useAsyncList } from './hooks/use-async-list';\nexport { default as useWarnOnChange } from './hooks/use-warn-on-change';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\nexport { default as __experimentalUseDropZone } from './hooks/use-drop-zone';\nexport { default as useFocusableIframe } from './hooks/use-focusable-iframe';\nexport { default as __experimentalUseFixedWindowList } from './hooks/use-fixed-window-list';\n"]}
|
package/build/index.native.js
CHANGED
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
var _exportNames = {
|
|
9
9
|
compose: true,
|
|
10
|
+
pipe: true,
|
|
10
11
|
ifCondition: true,
|
|
11
12
|
pure: true,
|
|
12
13
|
withGlobalEvents: true,
|
|
@@ -57,6 +58,12 @@ Object.defineProperty(exports, "ifCondition", {
|
|
|
57
58
|
return _ifCondition.default;
|
|
58
59
|
}
|
|
59
60
|
});
|
|
61
|
+
Object.defineProperty(exports, "pipe", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () {
|
|
64
|
+
return _pipe.default;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
60
67
|
Object.defineProperty(exports, "pure", {
|
|
61
68
|
enumerable: true,
|
|
62
69
|
get: function () {
|
|
@@ -204,8 +211,38 @@ Object.keys(_createHigherOrderComponent).forEach(function (key) {
|
|
|
204
211
|
});
|
|
205
212
|
});
|
|
206
213
|
|
|
214
|
+
var _debounce = require("./utils/debounce");
|
|
215
|
+
|
|
216
|
+
Object.keys(_debounce).forEach(function (key) {
|
|
217
|
+
if (key === "default" || key === "__esModule") return;
|
|
218
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
219
|
+
if (key in exports && exports[key] === _debounce[key]) return;
|
|
220
|
+
Object.defineProperty(exports, key, {
|
|
221
|
+
enumerable: true,
|
|
222
|
+
get: function () {
|
|
223
|
+
return _debounce[key];
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
var _throttle = require("./utils/throttle");
|
|
229
|
+
|
|
230
|
+
Object.keys(_throttle).forEach(function (key) {
|
|
231
|
+
if (key === "default" || key === "__esModule") return;
|
|
232
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
233
|
+
if (key in exports && exports[key] === _throttle[key]) return;
|
|
234
|
+
Object.defineProperty(exports, key, {
|
|
235
|
+
enumerable: true,
|
|
236
|
+
get: function () {
|
|
237
|
+
return _throttle[key];
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
207
242
|
var _compose = _interopRequireDefault(require("./higher-order/compose"));
|
|
208
243
|
|
|
244
|
+
var _pipe = _interopRequireDefault(require("./higher-order/pipe"));
|
|
245
|
+
|
|
209
246
|
var _ifCondition = _interopRequireDefault(require("./higher-order/if-condition"));
|
|
210
247
|
|
|
211
248
|
var _pure = _interopRequireDefault(require("./higher-order/pure"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/index.native.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/index.native.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAGA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA","sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\nexport { default as withPreferredColorScheme } from './higher-order/with-preferred-color-scheme';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as useAsyncList } from './hooks/use-async-list';\nexport { default as usePreferredColorScheme } from './hooks/use-preferred-color-scheme';\nexport { default as usePreferredColorSchemeStyle } from './hooks/use-preferred-color-scheme-style';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\n"]}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.debounce = void 0;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Parts of this source were derived and modified from lodash,
|
|
10
|
+
* released under the MIT license.
|
|
11
|
+
*
|
|
12
|
+
* https://github.com/lodash/lodash
|
|
13
|
+
*
|
|
14
|
+
* Copyright JS Foundation and other contributors <https://js.foundation/>
|
|
15
|
+
*
|
|
16
|
+
* Based on Underscore.js, copyright Jeremy Ashkenas,
|
|
17
|
+
* DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
|
|
18
|
+
*
|
|
19
|
+
* This software consists of voluntary contributions made by many
|
|
20
|
+
* individuals. For exact contribution history, see the revision history
|
|
21
|
+
* available at https://github.com/lodash/lodash
|
|
22
|
+
*
|
|
23
|
+
* The following license applies to all parts of this software except as
|
|
24
|
+
* documented below:
|
|
25
|
+
*
|
|
26
|
+
* ====
|
|
27
|
+
*
|
|
28
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
29
|
+
* a copy of this software and associated documentation files (the
|
|
30
|
+
* "Software"), to deal in the Software without restriction, including
|
|
31
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
32
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
33
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
34
|
+
* the following conditions:
|
|
35
|
+
*
|
|
36
|
+
* The above copyright notice and this permission notice shall be
|
|
37
|
+
* included in all copies or substantial portions of the Software.
|
|
38
|
+
*
|
|
39
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
40
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
41
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
42
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
43
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
44
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
45
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A simplified and properly typed version of lodash's `debounce`, that
|
|
50
|
+
* always uses timers instead of sometimes using rAF.
|
|
51
|
+
*
|
|
52
|
+
* Creates a debounced function that delays invoking `func` until after `wait`
|
|
53
|
+
* milliseconds have elapsed since the last time the debounced function was
|
|
54
|
+
* invoked. The debounced function comes with a `cancel` method to cancel delayed
|
|
55
|
+
* `func` invocations and a `flush` method to immediately invoke them. Provide
|
|
56
|
+
* `options` to indicate whether `func` should be invoked on the leading and/or
|
|
57
|
+
* trailing edge of the `wait` timeout. The `func` is invoked with the last
|
|
58
|
+
* arguments provided to the debounced function. Subsequent calls to the debounced
|
|
59
|
+
* function return the result of the last `func` invocation.
|
|
60
|
+
*
|
|
61
|
+
* **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|
62
|
+
* invoked on the trailing edge of the timeout only if the debounced function
|
|
63
|
+
* is invoked more than once during the `wait` timeout.
|
|
64
|
+
*
|
|
65
|
+
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|
66
|
+
* until the next tick, similar to `setTimeout` with a timeout of `0`.
|
|
67
|
+
*
|
|
68
|
+
* @param {Function} func The function to debounce.
|
|
69
|
+
* @param {number} wait The number of milliseconds to delay.
|
|
70
|
+
* @param {Partial< DebounceOptions >} options The options object.
|
|
71
|
+
* @param {boolean} options.leading Specify invoking on the leading edge of the timeout.
|
|
72
|
+
* @param {number} options.maxWait The maximum time `func` is allowed to be delayed before it's invoked.
|
|
73
|
+
* @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.
|
|
74
|
+
*
|
|
75
|
+
* @return Returns the new debounced function.
|
|
76
|
+
*/
|
|
77
|
+
const debounce = (func, wait, options) => {
|
|
78
|
+
let lastArgs;
|
|
79
|
+
let lastThis;
|
|
80
|
+
let maxWait = 0;
|
|
81
|
+
let result;
|
|
82
|
+
let timerId;
|
|
83
|
+
let lastCallTime;
|
|
84
|
+
let lastInvokeTime = 0;
|
|
85
|
+
let leading = false;
|
|
86
|
+
let maxing = false;
|
|
87
|
+
let trailing = true;
|
|
88
|
+
|
|
89
|
+
if (options) {
|
|
90
|
+
leading = !!options.leading;
|
|
91
|
+
maxing = 'maxWait' in options;
|
|
92
|
+
|
|
93
|
+
if (options.maxWait !== undefined) {
|
|
94
|
+
maxWait = Math.max(options.maxWait, wait);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function invokeFunc(time) {
|
|
101
|
+
const args = lastArgs;
|
|
102
|
+
const thisArg = lastThis;
|
|
103
|
+
lastArgs = undefined;
|
|
104
|
+
lastThis = undefined;
|
|
105
|
+
lastInvokeTime = time;
|
|
106
|
+
result = func.apply(thisArg, args);
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function startTimer(pendingFunc, waitTime) {
|
|
111
|
+
timerId = setTimeout(pendingFunc, waitTime);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function cancelTimer() {
|
|
115
|
+
if (timerId !== undefined) {
|
|
116
|
+
clearTimeout(timerId);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function leadingEdge(time) {
|
|
121
|
+
// Reset any `maxWait` timer.
|
|
122
|
+
lastInvokeTime = time; // Start the timer for the trailing edge.
|
|
123
|
+
|
|
124
|
+
startTimer(timerExpired, wait); // Invoke the leading edge.
|
|
125
|
+
|
|
126
|
+
return leading ? invokeFunc(time) : result;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getTimeSinceLastCall(time) {
|
|
130
|
+
return time - (lastCallTime || 0);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function remainingWait(time) {
|
|
134
|
+
const timeSinceLastCall = getTimeSinceLastCall(time);
|
|
135
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
136
|
+
const timeWaiting = wait - timeSinceLastCall;
|
|
137
|
+
return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function shouldInvoke(time) {
|
|
141
|
+
const timeSinceLastCall = getTimeSinceLastCall(time);
|
|
142
|
+
const timeSinceLastInvoke = time - lastInvokeTime; // Either this is the first call, activity has stopped and we're at the
|
|
143
|
+
// trailing edge, the system time has gone backwards and we're treating
|
|
144
|
+
// it as the trailing edge, or we've hit the `maxWait` limit.
|
|
145
|
+
|
|
146
|
+
return lastCallTime === undefined || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function timerExpired() {
|
|
150
|
+
const time = Date.now();
|
|
151
|
+
|
|
152
|
+
if (shouldInvoke(time)) {
|
|
153
|
+
return trailingEdge(time);
|
|
154
|
+
} // Restart the timer.
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
startTimer(timerExpired, remainingWait(time));
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function clearTimer() {
|
|
162
|
+
timerId = undefined;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function trailingEdge(time) {
|
|
166
|
+
clearTimer(); // Only invoke if we have `lastArgs` which means `func` has been
|
|
167
|
+
// debounced at least once.
|
|
168
|
+
|
|
169
|
+
if (trailing && lastArgs) {
|
|
170
|
+
return invokeFunc(time);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
lastArgs = lastThis = undefined;
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function cancel() {
|
|
178
|
+
cancelTimer();
|
|
179
|
+
lastInvokeTime = 0;
|
|
180
|
+
clearTimer();
|
|
181
|
+
lastArgs = lastCallTime = lastThis = undefined;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function flush() {
|
|
185
|
+
return pending() ? trailingEdge(Date.now()) : result;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function pending() {
|
|
189
|
+
return timerId !== undefined;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function debounced() {
|
|
193
|
+
const time = Date.now();
|
|
194
|
+
const isInvoking = shouldInvoke(time);
|
|
195
|
+
|
|
196
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
197
|
+
args[_key] = arguments[_key];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
lastArgs = args;
|
|
201
|
+
lastThis = this;
|
|
202
|
+
lastCallTime = time;
|
|
203
|
+
|
|
204
|
+
if (isInvoking) {
|
|
205
|
+
if (!pending()) {
|
|
206
|
+
return leadingEdge(lastCallTime);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (maxing) {
|
|
210
|
+
// Handle invocations in a tight loop.
|
|
211
|
+
startTimer(timerExpired, wait);
|
|
212
|
+
return invokeFunc(lastCallTime);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (!pending()) {
|
|
217
|
+
startTimer(timerExpired, wait);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
debounced.cancel = cancel;
|
|
224
|
+
debounced.flush = flush;
|
|
225
|
+
debounced.pending = pending;
|
|
226
|
+
return debounced;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
exports.debounce = debounce;
|
|
230
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/utils/debounce/index.ts"],"names":["debounce","func","wait","options","lastArgs","lastThis","maxWait","result","timerId","lastCallTime","lastInvokeTime","leading","maxing","trailing","undefined","Math","max","invokeFunc","time","args","thisArg","apply","startTimer","pendingFunc","waitTime","setTimeout","cancelTimer","clearTimeout","leadingEdge","timerExpired","getTimeSinceLastCall","remainingWait","timeSinceLastCall","timeSinceLastInvoke","timeWaiting","min","shouldInvoke","Date","now","trailingEdge","clearTimer","cancel","flush","pending","debounced","isInvoking"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,GAAG,CACvBC,IADuB,EAEvBC,IAFuB,EAGvBC,OAHuB,KAInB;AACJ,MAAIC,QAAJ;AACA,MAAIC,QAAJ;AACA,MAAIC,OAAO,GAAG,CAAd;AACA,MAAIC,MAAJ;AACA,MAAIC,OAAJ;AACA,MAAIC,YAAJ;AAEA,MAAIC,cAAc,GAAG,CAArB;AACA,MAAIC,OAAO,GAAG,KAAd;AACA,MAAIC,MAAM,GAAG,KAAb;AACA,MAAIC,QAAQ,GAAG,IAAf;;AAEA,MAAKV,OAAL,EAAe;AACdQ,IAAAA,OAAO,GAAG,CAAC,CAAER,OAAO,CAACQ,OAArB;AACAC,IAAAA,MAAM,GAAG,aAAaT,OAAtB;;AACA,QAAKA,OAAO,CAACG,OAAR,KAAoBQ,SAAzB,EAAqC;AACpCR,MAAAA,OAAO,GAAGS,IAAI,CAACC,GAAL,CAAUb,OAAO,CAACG,OAAlB,EAA2BJ,IAA3B,CAAV;AACA;;AACDW,IAAAA,QAAQ,GAAG,cAAcV,O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jB,GAAkC/B,MAAhD;AACA;;AAED,WAASoC,OAAT,GAAmB;AAClB,WAAOnC,OAAO,KAAKM,SAAnB;AACA;;AAED,WAAS8B,SAAT,GAAsE;AACrE,UAAM1B,IAAI,GAAGmB,IAAI,CAACC,GAAL,EAAb;AACA,UAAMO,UAAU,GAAGT,YAAY,CAAElB,IAAF,CAA/B;;AAFqE,sCAAhCC,IAAgC;AAAhCA,MAAAA,IAAgC;AAAA;;AAIrEf,IAAAA,QAAQ,GAAGe,IAAX;AACAd,IAAAA,QAAQ,GAAG,IAAX;AACAI,IAAAA,YAAY,GAAGS,IAAf;;AAEA,QAAK2B,UAAL,EAAkB;AACjB,UAAK,CAAEF,OAAO,EAAd,EAAmB;AAClB,eAAOf,WAAW,CAAEnB,YAAF,CAAlB;AACA;;AACD,UAAKG,MAAL,EAAc;AACb;AACAU,QAAAA,UAAU,CAAEO,YAAF,EAAgB3B,IAAhB,CAAV;AACA,eAAOe,UAAU,CAAER,YAAF,CAAjB;AACA;AACD;;AACD,QAAK,CAAEkC,OAAO,EAAd,EAAmB;AAClBrB,MAAAA,UAAU,CAAEO,YAAF,EAAgB3B,IAAhB,CAAV;AACA;;AACD,WAAOK,MAAP;AACA;;AACDqC,EAAAA,SAAS,CAACH,MAAV,GAAmBA,MAAnB;AACAG,EAAAA,SAAS,CAACF,KAAV,GAAkBA,KAAlB;AACAE,EAAAA,SAAS,CAACD,OAAV,GAAoBA,OAApB;AACA,SAAOC,SAAP;AACA,CA7JM","sourcesContent":["/**\n * Parts of this source were derived and modified from lodash,\n * released under the MIT license.\n *\n * https://github.com/lodash/lodash\n *\n * Copyright JS Foundation and other contributors <https://js.foundation/>\n *\n * Based on Underscore.js, copyright Jeremy Ashkenas,\n * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>\n *\n * This software consists of voluntary contributions made by many\n * individuals. For exact contribution history, see the revision history\n * available at https://github.com/lodash/lodash\n *\n * The following license applies to all parts of this software except as\n * documented below:\n *\n * ====\n *\n * Permission is hereby granted, free of charge, to any person obtaining\n * a copy of this software and associated documentation files (the\n * \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish,\n * distribute, sublicense, and/or sell copies of the Software, and to\n * permit persons to whom the Software is furnished to do so, subject to\n * the following conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\nexport interface DebounceOptions {\n\tleading: boolean;\n\tmaxWait: number;\n\ttrailing: boolean;\n}\n\nexport interface DebouncedFunc< T extends ( ...args: any[] ) => any > {\n\t/**\n\t * Call the original function, but applying the debounce rules.\n\t *\n\t * If the debounced function can be run immediately, this calls it and returns its return\n\t * value.\n\t *\n\t * Otherwise, it returns the return value of the last invocation, or undefined if the debounced\n\t * function was not invoked yet.\n\t */\n\t( ...args: Parameters< T > ): ReturnType< T > | undefined;\n\n\t/**\n\t * Throw away any pending invocation of the debounced function.\n\t */\n\tcancel(): void;\n\n\t/**\n\t * If there is a pending invocation of the debounced function, invoke it immediately and return\n\t * its return value.\n\t *\n\t * Otherwise, return the value from the last invocation, or undefined if the debounced function\n\t * was never invoked.\n\t */\n\tflush(): ReturnType< T > | undefined;\n}\n\n/**\n * A simplified and properly typed version of lodash's `debounce`, that\n * always uses timers instead of sometimes using rAF.\n *\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked. The debounced function comes with a `cancel` method to cancel delayed\n * `func` invocations and a `flush` method to immediately invoke them. Provide\n * `options` to indicate whether `func` should be invoked on the leading and/or\n * trailing edge of the `wait` timeout. The `func` is invoked with the last\n * arguments provided to the debounced function. Subsequent calls to the debounced\n * function return the result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * @param {Function} func The function to debounce.\n * @param {number} wait The number of milliseconds to delay.\n * @param {Partial< DebounceOptions >} options The options object.\n * @param {boolean} options.leading Specify invoking on the leading edge of the timeout.\n * @param {number} options.maxWait The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.\n *\n * @return Returns the new debounced function.\n */\nexport const debounce = < FunctionT extends ( ...args: unknown[] ) => unknown >(\n\tfunc: FunctionT,\n\twait: number,\n\toptions?: Partial< DebounceOptions >\n) => {\n\tlet lastArgs: Parameters< FunctionT > | undefined;\n\tlet lastThis: unknown | undefined;\n\tlet maxWait = 0;\n\tlet result: ReturnType< FunctionT >;\n\tlet timerId: ReturnType< typeof setTimeout > | undefined;\n\tlet lastCallTime: number | undefined;\n\n\tlet lastInvokeTime = 0;\n\tlet leading = false;\n\tlet maxing = false;\n\tlet trailing = true;\n\n\tif ( options ) {\n\t\tleading = !! options.leading;\n\t\tmaxing = 'maxWait' in options;\n\t\tif ( options.maxWait !== undefined ) {\n\t\t\tmaxWait = Math.max( options.maxWait, wait );\n\t\t}\n\t\ttrailing = 'trailing' in options ? !! options.trailing : trailing;\n\t}\n\n\tfunction invokeFunc( time: number ) {\n\t\tconst args = lastArgs;\n\t\tconst thisArg = lastThis;\n\n\t\tlastArgs = undefined;\n\t\tlastThis = undefined;\n\t\tlastInvokeTime = time;\n\n\t\tresult = func.apply( thisArg, args! ) as ReturnType< FunctionT >;\n\t\treturn result;\n\t}\n\n\tfunction startTimer(\n\t\tpendingFunc: () => void,\n\t\twaitTime: number | undefined\n\t) {\n\t\ttimerId = setTimeout( pendingFunc, waitTime );\n\t}\n\n\tfunction cancelTimer() {\n\t\tif ( timerId !== undefined ) {\n\t\t\tclearTimeout( timerId );\n\t\t}\n\t}\n\n\tfunction leadingEdge( time: number ) {\n\t\t// Reset any `maxWait` timer.\n\t\tlastInvokeTime = time;\n\t\t// Start the timer for the trailing edge.\n\t\tstartTimer( timerExpired, wait );\n\t\t// Invoke the leading edge.\n\t\treturn leading ? invokeFunc( time ) : result;\n\t}\n\n\tfunction getTimeSinceLastCall( time: number ) {\n\t\treturn time - ( lastCallTime || 0 );\n\t}\n\n\tfunction remainingWait( time: number ) {\n\t\tconst timeSinceLastCall = getTimeSinceLastCall( time );\n\t\tconst timeSinceLastInvoke = time - lastInvokeTime;\n\t\tconst timeWaiting = wait - timeSinceLastCall;\n\n\t\treturn maxing\n\t\t\t? Math.min( timeWaiting, maxWait - timeSinceLastInvoke )\n\t\t\t: timeWaiting;\n\t}\n\n\tfunction shouldInvoke( time: number ) {\n\t\tconst timeSinceLastCall = getTimeSinceLastCall( time );\n\t\tconst timeSinceLastInvoke = time - lastInvokeTime;\n\n\t\t// Either this is the first call, activity has stopped and we're at the\n\t\t// trailing edge, the system time has gone backwards and we're treating\n\t\t// it as the trailing edge, or we've hit the `maxWait` limit.\n\t\treturn (\n\t\t\tlastCallTime === undefined ||\n\t\t\ttimeSinceLastCall >= wait ||\n\t\t\ttimeSinceLastCall < 0 ||\n\t\t\t( maxing && timeSinceLastInvoke >= maxWait )\n\t\t);\n\t}\n\n\tfunction timerExpired() {\n\t\tconst time = Date.now();\n\t\tif ( shouldInvoke( time ) ) {\n\t\t\treturn trailingEdge( time );\n\t\t}\n\t\t// Restart the timer.\n\t\tstartTimer( timerExpired, remainingWait( time ) );\n\t\treturn undefined;\n\t}\n\n\tfunction clearTimer() {\n\t\ttimerId = undefined;\n\t}\n\n\tfunction trailingEdge( time: number ) {\n\t\tclearTimer();\n\n\t\t// Only invoke if we have `lastArgs` which means `func` has been\n\t\t// debounced at least once.\n\t\tif ( trailing && lastArgs ) {\n\t\t\treturn invokeFunc( time );\n\t\t}\n\t\tlastArgs = lastThis = undefined;\n\t\treturn result;\n\t}\n\n\tfunction cancel() {\n\t\tcancelTimer();\n\t\tlastInvokeTime = 0;\n\t\tclearTimer();\n\t\tlastArgs = lastCallTime = lastThis = undefined;\n\t}\n\n\tfunction flush() {\n\t\treturn pending() ? trailingEdge( Date.now() ) : result;\n\t}\n\n\tfunction pending() {\n\t\treturn timerId !== undefined;\n\t}\n\n\tfunction debounced( this: unknown, ...args: Parameters< FunctionT > ) {\n\t\tconst time = Date.now();\n\t\tconst isInvoking = shouldInvoke( time );\n\n\t\tlastArgs = args;\n\t\tlastThis = this;\n\t\tlastCallTime = time;\n\n\t\tif ( isInvoking ) {\n\t\t\tif ( ! pending() ) {\n\t\t\t\treturn leadingEdge( lastCallTime );\n\t\t\t}\n\t\t\tif ( maxing ) {\n\t\t\t\t// Handle invocations in a tight loop.\n\t\t\t\tstartTimer( timerExpired, wait );\n\t\t\t\treturn invokeFunc( lastCallTime );\n\t\t\t}\n\t\t}\n\t\tif ( ! pending() ) {\n\t\t\tstartTimer( timerExpired, wait );\n\t\t}\n\t\treturn result;\n\t}\n\tdebounced.cancel = cancel;\n\tdebounced.flush = flush;\n\tdebounced.pending = pending;\n\treturn debounced;\n};\n"]}
|