@wordpress/compose 5.6.0 → 5.9.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 +18 -0
- package/README.md +37 -11
- package/build/higher-order/if-condition/index.js +14 -10
- package/build/higher-order/if-condition/index.js.map +1 -1
- package/build/higher-order/pure/index.js +9 -5
- package/build/higher-order/pure/index.js.map +1 -1
- package/build/higher-order/with-global-events/index.js +2 -2
- package/build/higher-order/with-global-events/index.js.map +1 -1
- package/build/higher-order/with-instance-id/index.js +3 -3
- package/build/higher-order/with-instance-id/index.js.map +1 -1
- package/build/higher-order/with-preferred-color-scheme/index.native.js +2 -2
- package/build/higher-order/with-preferred-color-scheme/index.native.js.map +1 -1
- package/build/higher-order/with-safe-timeout/index.js +10 -7
- package/build/higher-order/with-safe-timeout/index.js.map +1 -1
- package/build/higher-order/with-state/index.js +2 -2
- package/build/higher-order/with-state/index.js.map +1 -1
- package/build/hooks/use-copy-to-clipboard/index.js +1 -1
- package/build/hooks/use-copy-to-clipboard/index.js.map +1 -1
- package/build/hooks/use-debounce/index.js.map +1 -1
- package/build/hooks/use-dialog/index.js.map +1 -1
- package/build/hooks/use-disabled/index.js +77 -7
- package/build/hooks/use-disabled/index.js.map +1 -1
- package/build/hooks/use-focus-on-mount/index.js +6 -1
- package/build/hooks/use-focus-on-mount/index.js.map +1 -1
- package/build/hooks/use-focus-return/index.js.map +1 -1
- package/build/hooks/use-keyboard-shortcut/index.js.map +1 -1
- package/build/hooks/use-merge-refs/index.js.map +1 -1
- package/build/hooks/use-ref-effect/index.js.map +1 -1
- package/build/hooks/use-resize-observer/index.js +224 -13
- package/build/hooks/use-resize-observer/index.js.map +1 -1
- package/build/hooks/use-resize-observer/index.native.js +0 -2
- package/build/hooks/use-resize-observer/index.native.js.map +1 -1
- package/build/hooks/use-throttle/index.js.map +1 -1
- package/build/index.js +54 -13
- package/build/index.js.map +1 -1
- package/build/index.native.js +48 -7
- package/build/index.native.js.map +1 -1
- package/build/utils/create-higher-order-component/index.js +19 -5
- package/build/utils/create-higher-order-component/index.js.map +1 -1
- package/build-module/higher-order/if-condition/index.js +13 -7
- package/build-module/higher-order/if-condition/index.js.map +1 -1
- package/build-module/higher-order/pure/index.js +10 -9
- package/build-module/higher-order/pure/index.js.map +1 -1
- package/build-module/higher-order/with-global-events/index.js +1 -1
- package/build-module/higher-order/with-global-events/index.js.map +1 -1
- package/build-module/higher-order/with-instance-id/index.js +3 -3
- package/build-module/higher-order/with-instance-id/index.js.map +1 -1
- package/build-module/higher-order/with-preferred-color-scheme/index.native.js +1 -1
- package/build-module/higher-order/with-preferred-color-scheme/index.native.js.map +1 -1
- package/build-module/higher-order/with-safe-timeout/index.js +9 -7
- package/build-module/higher-order/with-safe-timeout/index.js.map +1 -1
- package/build-module/higher-order/with-state/index.js +1 -1
- package/build-module/higher-order/with-state/index.js.map +1 -1
- package/build-module/hooks/use-copy-to-clipboard/index.js +1 -1
- package/build-module/hooks/use-copy-to-clipboard/index.js.map +1 -1
- package/build-module/hooks/use-debounce/index.js.map +1 -1
- package/build-module/hooks/use-dialog/index.js.map +1 -1
- package/build-module/hooks/use-disabled/index.js +78 -7
- package/build-module/hooks/use-disabled/index.js.map +1 -1
- package/build-module/hooks/use-focus-on-mount/index.js +6 -1
- package/build-module/hooks/use-focus-on-mount/index.js.map +1 -1
- package/build-module/hooks/use-focus-return/index.js.map +1 -1
- package/build-module/hooks/use-keyboard-shortcut/index.js.map +1 -1
- package/build-module/hooks/use-merge-refs/index.js.map +1 -1
- package/build-module/hooks/use-ref-effect/index.js.map +1 -1
- package/build-module/hooks/use-resize-observer/index.js +226 -9
- package/build-module/hooks/use-resize-observer/index.js.map +1 -1
- package/build-module/hooks/use-resize-observer/index.native.js +0 -2
- package/build-module/hooks/use-resize-observer/index.native.js.map +1 -1
- package/build-module/hooks/use-throttle/index.js.map +1 -1
- package/build-module/index.js +3 -3
- package/build-module/index.js.map +1 -1
- package/build-module/index.native.js +3 -2
- package/build-module/index.native.js.map +1 -1
- package/build-module/utils/create-higher-order-component/index.js +18 -4
- package/build-module/utils/create-higher-order-component/index.js.map +1 -1
- package/build-types/higher-order/if-condition/index.d.ts +5 -2
- package/build-types/higher-order/if-condition/index.d.ts.map +1 -1
- package/build-types/higher-order/pure/index.d.ts +1 -1
- package/build-types/higher-order/pure/index.d.ts.map +1 -1
- package/build-types/higher-order/with-global-events/index.d.ts.map +1 -1
- package/build-types/higher-order/with-instance-id/index.d.ts +8 -4
- package/build-types/higher-order/with-instance-id/index.d.ts.map +1 -1
- package/build-types/higher-order/with-safe-timeout/index.d.ts +37 -4
- package/build-types/higher-order/with-safe-timeout/index.d.ts.map +1 -1
- package/build-types/hooks/use-debounce/index.d.ts.map +1 -1
- package/build-types/hooks/use-dialog/index.d.ts.map +1 -1
- package/build-types/hooks/use-disabled/index.d.ts +6 -2
- package/build-types/hooks/use-disabled/index.d.ts.map +1 -1
- package/build-types/hooks/use-focus-on-mount/index.d.ts.map +1 -1
- package/build-types/hooks/use-focus-return/index.d.ts.map +1 -1
- package/build-types/hooks/use-merge-refs/index.d.ts.map +1 -1
- package/build-types/hooks/use-ref-effect/index.d.ts +1 -1
- package/build-types/hooks/use-ref-effect/index.d.ts.map +1 -1
- package/build-types/hooks/use-resize-observer/index.d.ts +32 -2
- package/build-types/hooks/use-resize-observer/index.d.ts.map +1 -1
- package/build-types/hooks/use-throttle/index.d.ts.map +1 -1
- package/build-types/index.d.ts +2 -2
- package/build-types/utils/create-higher-order-component/index.d.ts +5 -12
- package/build-types/utils/create-higher-order-component/index.d.ts.map +1 -1
- package/package.json +8 -9
- package/src/higher-order/if-condition/index.tsx +11 -7
- package/src/higher-order/pure/index.tsx +29 -31
- package/src/higher-order/with-global-events/index.js +4 -2
- package/src/higher-order/with-global-events/test/index.js +2 -2
- package/src/higher-order/with-instance-id/index.tsx +19 -10
- package/src/higher-order/with-preferred-color-scheme/index.native.js +1 -1
- package/src/higher-order/with-safe-timeout/index.tsx +22 -19
- package/src/higher-order/with-state/index.js +1 -1
- package/src/hooks/use-copy-to-clipboard/index.js +1 -1
- package/src/hooks/use-debounce/index.js +4 -5
- package/src/hooks/use-dialog/index.js +13 -12
- package/src/hooks/use-disabled/index.js +139 -50
- package/src/hooks/use-focus-on-mount/index.js +6 -1
- package/src/hooks/use-focus-return/index.js +3 -1
- package/src/hooks/use-keyboard-shortcut/index.js +1 -1
- package/src/hooks/use-merge-refs/index.js +2 -1
- package/src/hooks/use-ref-effect/index.ts +2 -2
- package/src/hooks/use-resize-observer/index.native.js +0 -2
- package/src/hooks/use-resize-observer/index.tsx +362 -0
- package/src/hooks/use-throttle/index.js +4 -5
- package/src/index.js +3 -3
- package/src/index.native.js +3 -2
- package/src/utils/create-higher-order-component/index.ts +30 -27
- package/src/utils/create-higher-order-component/test/index.js +1 -1
- package/tsconfig.json +2 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/src/hooks/use-resize-observer/index.js +0 -31
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-debounce/index.js"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;GAcG;AACH,4DAPwB,GAAG,EAAE,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-debounce/index.js"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;GAcG;AACH,4DAPwB,GAAG,EAAE,KAAK,IAAI,wIAerC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-dialog/index.js"],"names":[],"mappings":";;;;;kBAkBc,kCAA2B,CAAC,CAAC,CAAC;;;;aAC9B,MAAM,IAAI;;AAHxB;;;;GAIG;AAGH;;;;;;;;GAQG;AACH,oCAFW,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-dialog/index.js"],"names":[],"mappings":";;;;;kBAkBc,kCAA2B,CAAC,CAAC,CAAC;;;;aAC9B,MAAM,IAAI;;AAHxB;;;;GAIG;AAGH;;;;;;;;GAQG;AACH,oCAFW,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;KAyDvB"}
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
* (input fields, links, buttons, etc.) need to be disabled. This hook adds the
|
|
4
4
|
* behavior to disable nested DOM elements to the returned ref.
|
|
5
5
|
*
|
|
6
|
+
* @param {Object} config Configuration object.
|
|
7
|
+
* @param {boolean=} config.isDisabled Whether the element should be disabled.
|
|
6
8
|
* @return {import('react').RefCallback<HTMLElement>} Element Ref.
|
|
7
9
|
*
|
|
8
10
|
* @example
|
|
9
11
|
* ```js
|
|
10
|
-
* import {
|
|
12
|
+
* import { useDisabled } from '@wordpress/compose';
|
|
11
13
|
* const DisabledExample = () => {
|
|
12
14
|
* const disabledRef = useDisabled();
|
|
13
15
|
* return (
|
|
@@ -19,5 +21,7 @@
|
|
|
19
21
|
* };
|
|
20
22
|
* ```
|
|
21
23
|
*/
|
|
22
|
-
export default function useDisabled(
|
|
24
|
+
export default function useDisabled({ isDisabled: isDisabledProp, }?: {
|
|
25
|
+
isDisabled?: boolean | undefined;
|
|
26
|
+
}): import('react').RefCallback<HTMLElement>;
|
|
23
27
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-disabled/index.js"],"names":[],"mappings":"AAkCA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-disabled/index.js"],"names":[],"mappings":"AAkCA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH;IAjB4B,UAAU,GAA3B,OAAO;IACN,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAgKnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-focus-on-mount/index.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,uDAlBW,OAAO,GAAG,cAAc,GACvB,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-focus-on-mount/index.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,uDAlBW,OAAO,GAAG,cAAc,GACvB,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAiDnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-focus-return/index.js"],"names":[],"mappings":";AAKA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,uDAlBiB,IAAI,gBACT,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-focus-return/index.js"],"names":[],"mappings":";AAKA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,uDAlBiB,IAAI,gBACT,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CA4DnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-merge-refs/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-merge-refs/index.js"],"names":[],"mappings":"AA4BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wIAsDC"}
|
|
@@ -21,5 +21,5 @@ import type { DependencyList, RefCallback } from 'react';
|
|
|
21
21
|
*
|
|
22
22
|
* @return Ref callback.
|
|
23
23
|
*/
|
|
24
|
-
export default function useRefEffect<TElement = Node>(callback: (node: TElement) => (() => void) |
|
|
24
|
+
export default function useRefEffect<TElement = Node>(callback: (node: TElement) => (() => void) | void, dependencies: DependencyList): RefCallback<TElement | null>;
|
|
25
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-ref-effect/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAOzD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAE,QAAQ,GAAG,IAAI,EACpD,QAAQ,EAAE,CAAE,IAAI,EAAE,QAAQ,KAAM,CAAE,MAAM,IAAI,CAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-ref-effect/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAOzD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAE,QAAQ,GAAG,IAAI,EACpD,QAAQ,EAAE,CAAE,IAAI,EAAE,QAAQ,KAAM,CAAE,MAAM,IAAI,CAAE,GAAG,IAAI,EACrD,YAAY,EAAE,cAAc,GAC1B,WAAW,CAAE,QAAQ,GAAG,IAAI,CAAE,CAShC"}
|
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { WPElement } from '@wordpress/element';
|
|
2
|
+
declare global {
|
|
3
|
+
interface ResizeObserverEntry {
|
|
4
|
+
readonly devicePixelContentBoxSize: ReadonlyArray<ResizeObserverSize>;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Hook which allows to listen the resize event of any target element when it changes sizes.
|
|
9
|
+
* _Note: `useResizeObserver` will report `null` until after first render.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* ```js
|
|
14
|
+
* const App = () => {
|
|
15
|
+
* const [ resizeListener, sizes ] = useResizeObserver();
|
|
16
|
+
*
|
|
17
|
+
* return (
|
|
18
|
+
* <div>
|
|
19
|
+
* { resizeListener }
|
|
20
|
+
* Your content here
|
|
21
|
+
* </div>
|
|
22
|
+
* );
|
|
23
|
+
* };
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export default function useResizeAware(): [
|
|
27
|
+
WPElement,
|
|
28
|
+
{
|
|
29
|
+
width: number | null;
|
|
30
|
+
height: number | null;
|
|
31
|
+
}
|
|
32
|
+
];
|
|
3
33
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-resize-observer/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-resize-observer/index.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AA6FpD,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,mBAAmB;QAC5B,QAAQ,CAAC,yBAAyB,EAAE,aAAa,CAAE,kBAAkB,CAAE,CAAC;KACxE;CACD;AA4MD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,IAAI;IACzC,SAAS;IACT;QAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE;CAC/C,CAuBA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-throttle/index.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;GAcG;AACH,4DAPwB,GAAG,EAAE,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-throttle/index.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;GAcG;AACH,4DAPwB,GAAG,EAAE,KAAK,IAAI,wIAcrC"}
|
package/build-types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./utils/create-higher-order-component";
|
|
2
2
|
export { default as compose } from "./higher-order/compose";
|
|
3
3
|
export { default as ifCondition } from "./higher-order/if-condition";
|
|
4
4
|
export { default as pure } from "./higher-order/pure";
|
|
@@ -10,7 +10,7 @@ export { default as useConstrainedTabbing } from "./hooks/use-constrained-tabbin
|
|
|
10
10
|
export { default as useCopyOnClick } from "./hooks/use-copy-on-click";
|
|
11
11
|
export { default as useCopyToClipboard } from "./hooks/use-copy-to-clipboard";
|
|
12
12
|
export { default as __experimentalUseDialog } from "./hooks/use-dialog";
|
|
13
|
-
export { default as
|
|
13
|
+
export { default as useDisabled } from "./hooks/use-disabled";
|
|
14
14
|
export { default as __experimentalUseDragging } from "./hooks/use-dragging";
|
|
15
15
|
export { default as useFocusOnMount } from "./hooks/use-focus-on-mount";
|
|
16
16
|
export { default as __experimentalUseFocusOutside } from "./hooks/use-focus-outside";
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import type { ComponentType } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* If a HOC does not obviate the need for any specific props then we default to `{}` which
|
|
7
|
-
* essentially subtracts 0 from the original props of the passed in component. An example
|
|
8
|
-
* of this is the `pure` HOC which does not change the API surface of the component but
|
|
9
|
-
* simply modifies the internals.
|
|
10
|
-
*/
|
|
11
|
-
export declare type HigherOrderComponent<HOCProps extends Record<string, any>> = <InnerProps extends HOCProps>(Inner: ComponentType<InnerProps>) => {} extends HOCProps ? ComponentType<InnerProps> : ComponentType<Omit<InnerProps, keyof HOCProps>>;
|
|
2
|
+
declare type GetProps<C> = C extends ComponentType<infer P> ? P : never;
|
|
3
|
+
export declare type WithoutInjectedProps<C, I> = Omit<GetProps<C>, keyof I>;
|
|
4
|
+
export declare type WithInjectedProps<C, I> = ComponentType<WithoutInjectedProps<C, I> & I>;
|
|
12
5
|
/**
|
|
13
6
|
* Given a function mapping a component to an enhanced component and modifier
|
|
14
7
|
* name, returns the enhanced component augmented with a generated displayName.
|
|
@@ -18,6 +11,6 @@ export declare type HigherOrderComponent<HOCProps extends Record<string, any>> =
|
|
|
18
11
|
*
|
|
19
12
|
* @return Component class with generated display name assigned.
|
|
20
13
|
*/
|
|
21
|
-
declare function createHigherOrderComponent<
|
|
22
|
-
export
|
|
14
|
+
export declare function createHigherOrderComponent<TInner extends ComponentType<any>, TOuter extends ComponentType<any>>(mapComponent: (Inner: TInner) => TOuter, modifierName: string): (Inner: TInner) => TOuter;
|
|
15
|
+
export {};
|
|
23
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/create-higher-order-component/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/create-higher-order-component/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,aAAK,QAAQ,CAAE,CAAC,IAAK,CAAC,SAAS,aAAa,CAAE,MAAM,CAAC,CAAE,GAAG,CAAC,GAAG,KAAK,CAAC;AAEpE,oBAAY,oBAAoB,CAAE,CAAC,EAAE,CAAC,IAAK,IAAI,CAAE,QAAQ,CAAE,CAAC,CAAE,EAAE,MAAM,CAAC,CAAE,CAAC;AAE1E,oBAAY,iBAAiB,CAAE,CAAC,EAAE,CAAC,IAAK,aAAa,CACpD,oBAAoB,CAAE,CAAC,EAAE,CAAC,CAAE,GAAG,CAAC,CAChC,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACzC,MAAM,SAAS,aAAa,CAAE,GAAG,CAAE,EACnC,MAAM,SAAS,aAAa,CAAE,GAAG,CAAE,EACjC,YAAY,EAAE,CAAE,KAAK,EAAE,MAAM,KAAM,MAAM,EAAE,YAAY,EAAE,MAAM,WACjD,MAAM,YAKtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/compose",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.9.0",
|
|
4
4
|
"description": "WordPress higher-order components (HOCs).",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -32,16 +32,15 @@
|
|
|
32
32
|
"@babel/runtime": "^7.16.0",
|
|
33
33
|
"@types/lodash": "^4.14.172",
|
|
34
34
|
"@types/mousetrap": "^1.6.8",
|
|
35
|
-
"@wordpress/deprecated": "^3.
|
|
36
|
-
"@wordpress/dom": "^3.
|
|
37
|
-
"@wordpress/element": "^4.
|
|
38
|
-
"@wordpress/is-shallow-equal": "^4.
|
|
39
|
-
"@wordpress/keycodes": "^3.
|
|
40
|
-
"@wordpress/priority-queue": "^2.
|
|
35
|
+
"@wordpress/deprecated": "^3.11.0",
|
|
36
|
+
"@wordpress/dom": "^3.11.0",
|
|
37
|
+
"@wordpress/element": "^4.9.0",
|
|
38
|
+
"@wordpress/is-shallow-equal": "^4.11.0",
|
|
39
|
+
"@wordpress/keycodes": "^3.11.0",
|
|
40
|
+
"@wordpress/priority-queue": "^2.11.0",
|
|
41
41
|
"clipboard": "^2.0.8",
|
|
42
42
|
"lodash": "^4.17.21",
|
|
43
43
|
"mousetrap": "^1.6.5",
|
|
44
|
-
"react-resize-aware": "^3.1.0",
|
|
45
44
|
"use-memo-one": "^1.1.1"
|
|
46
45
|
},
|
|
47
46
|
"peerDependencies": {
|
|
@@ -50,5 +49,5 @@
|
|
|
50
49
|
"publishConfig": {
|
|
51
50
|
"access": "public"
|
|
52
51
|
},
|
|
53
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "48d5f37dfb52d2e77c8eeb662f9874cf141b8c6b"
|
|
54
53
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ComponentType } from 'react';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* Internal dependencies
|
|
3
8
|
*/
|
|
4
|
-
import createHigherOrderComponent from '../../utils/create-higher-order-component';
|
|
9
|
+
import { createHigherOrderComponent } from '../../utils/create-higher-order-component';
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* Higher-order component creator, creating a new component which renders if
|
|
@@ -20,12 +25,10 @@ import createHigherOrderComponent from '../../utils/create-higher-order-componen
|
|
|
20
25
|
*
|
|
21
26
|
* @return Higher-order component.
|
|
22
27
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
) =>
|
|
26
|
-
|
|
27
|
-
( WrappedComponent ) => ( props ) => {
|
|
28
|
-
if ( ! predicate( props as TProps ) ) {
|
|
28
|
+
function ifCondition< Props >( predicate: ( props: Props ) => boolean ) {
|
|
29
|
+
return createHigherOrderComponent(
|
|
30
|
+
( WrappedComponent: ComponentType< Props > ) => ( props: Props ) => {
|
|
31
|
+
if ( ! predicate( props ) ) {
|
|
29
32
|
return null;
|
|
30
33
|
}
|
|
31
34
|
|
|
@@ -33,5 +36,6 @@ const ifCondition = < TProps extends Record< string, any > >(
|
|
|
33
36
|
},
|
|
34
37
|
'ifCondition'
|
|
35
38
|
);
|
|
39
|
+
}
|
|
36
40
|
|
|
37
41
|
export default ifCondition;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ComponentType, ComponentClass } from 'react';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* WordPress dependencies
|
|
3
8
|
*/
|
|
@@ -7,43 +12,36 @@ import { Component } from '@wordpress/element';
|
|
|
7
12
|
/**
|
|
8
13
|
* Internal dependencies
|
|
9
14
|
*/
|
|
10
|
-
import createHigherOrderComponent from '../../utils/create-higher-order-component';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* External dependencies
|
|
14
|
-
*/
|
|
15
|
-
import type { ComponentType, ComponentClass } from 'react';
|
|
15
|
+
import { createHigherOrderComponent } from '../../utils/create-higher-order-component';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Given a component returns the enhanced component augmented with a component
|
|
19
19
|
* only re-rendering when its props/state change
|
|
20
20
|
*/
|
|
21
|
-
const pure = createHigherOrderComponent(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return class extends Component< TProps > {
|
|
37
|
-
shouldComponentUpdate( nextProps: TProps ) {
|
|
38
|
-
return ! isShallowEqual( nextProps, this.props );
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
render() {
|
|
42
|
-
return <Wrapped { ...this.props } />;
|
|
21
|
+
const pure = createHigherOrderComponent( function < Props >(
|
|
22
|
+
WrappedComponent: ComponentType< Props >
|
|
23
|
+
): ComponentType< Props > {
|
|
24
|
+
if ( WrappedComponent.prototype instanceof Component ) {
|
|
25
|
+
return class extends ( WrappedComponent as ComponentClass< Props > ) {
|
|
26
|
+
shouldComponentUpdate( nextProps: Props, nextState: any ) {
|
|
27
|
+
return (
|
|
28
|
+
! isShallowEqual( nextProps, this.props ) ||
|
|
29
|
+
! isShallowEqual( nextState, this.state )
|
|
30
|
+
);
|
|
43
31
|
}
|
|
44
32
|
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return class extends Component< Props > {
|
|
36
|
+
shouldComponentUpdate( nextProps: Props ) {
|
|
37
|
+
return ! isShallowEqual( nextProps, this.props );
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
render() {
|
|
41
|
+
return <WrappedComponent { ...this.props } />;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
'pure' );
|
|
48
46
|
|
|
49
47
|
export default pure;
|
|
@@ -12,7 +12,7 @@ import deprecated from '@wordpress/deprecated';
|
|
|
12
12
|
/**
|
|
13
13
|
* Internal dependencies
|
|
14
14
|
*/
|
|
15
|
-
import createHigherOrderComponent from '../../utils/create-higher-order-component';
|
|
15
|
+
import { createHigherOrderComponent } from '../../utils/create-higher-order-component';
|
|
16
16
|
import Listener from './listener';
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -71,7 +71,9 @@ export default function withGlobalEvents( eventTypesToHandlers ) {
|
|
|
71
71
|
handleEvent( /** @type {any} */ event ) {
|
|
72
72
|
const handler =
|
|
73
73
|
eventTypesToHandlers[
|
|
74
|
-
/** @type {keyof GlobalEventHandlersEventMap} */ (
|
|
74
|
+
/** @type {keyof GlobalEventHandlersEventMap} */ (
|
|
75
|
+
event.type
|
|
76
|
+
)
|
|
75
77
|
/* eslint-enable jsdoc/no-undefined-types */
|
|
76
78
|
];
|
|
77
79
|
if ( typeof this.wrappedRef[ handler ] === 'function' ) {
|
|
@@ -82,8 +82,8 @@ describe( 'withGlobalEvents', () => {
|
|
|
82
82
|
mountEnhancedComponent();
|
|
83
83
|
|
|
84
84
|
// Get the HOC wrapper instance.
|
|
85
|
-
const hocInstance =
|
|
86
|
-
.instance;
|
|
85
|
+
const hocInstance =
|
|
86
|
+
wrapper.root.findByType( OriginalComponent ).parent.instance;
|
|
87
87
|
|
|
88
88
|
expect( Listener._instance.add ).toHaveBeenCalledWith(
|
|
89
89
|
'resize',
|
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import {
|
|
5
|
+
createHigherOrderComponent,
|
|
6
|
+
WithInjectedProps,
|
|
7
|
+
WithoutInjectedProps,
|
|
8
|
+
} from '../../utils/create-higher-order-component';
|
|
5
9
|
import useInstanceId from '../../hooks/use-instance-id';
|
|
6
10
|
|
|
11
|
+
type InstanceIdProps = { instanceId: string | number };
|
|
12
|
+
|
|
7
13
|
/**
|
|
8
14
|
* A Higher Order Component used to be provide a unique instance ID by
|
|
9
15
|
* component.
|
|
10
16
|
*/
|
|
11
|
-
const withInstanceId = createHigherOrderComponent
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
const withInstanceId = createHigherOrderComponent(
|
|
18
|
+
< C extends WithInjectedProps< C, InstanceIdProps > >(
|
|
19
|
+
WrappedComponent: C
|
|
20
|
+
) => {
|
|
21
|
+
return ( props: WithoutInjectedProps< C, InstanceIdProps > ) => {
|
|
22
|
+
const instanceId = useInstanceId( WrappedComponent );
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
return <WrappedComponent { ...props } instanceId={ instanceId } />;
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
'instanceId'
|
|
28
|
+
);
|
|
20
29
|
|
|
21
30
|
export default withInstanceId;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
|
-
import createHigherOrderComponent from '../../utils/create-higher-order-component';
|
|
4
|
+
import { createHigherOrderComponent } from '../../utils/create-higher-order-component';
|
|
5
5
|
import usePreferredColorScheme from '../../hooks/use-preferred-color-scheme';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { without } from 'lodash';
|
|
5
|
-
import type { ComponentType } from 'react';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* WordPress dependencies
|
|
@@ -12,7 +11,11 @@ import { Component } from '@wordpress/element';
|
|
|
12
11
|
/**
|
|
13
12
|
* Internal dependencies
|
|
14
13
|
*/
|
|
15
|
-
import
|
|
14
|
+
import {
|
|
15
|
+
createHigherOrderComponent,
|
|
16
|
+
WithInjectedProps,
|
|
17
|
+
WithoutInjectedProps,
|
|
18
|
+
} from '../../utils/create-higher-order-component';
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
21
|
* We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`
|
|
@@ -22,25 +25,24 @@ import createHigherOrderComponent from '../../utils/create-higher-order-componen
|
|
|
22
25
|
* In the case of this component, we only handle the simplest case where
|
|
23
26
|
* `setTimeout` only accepts a function (not a string) and an optional delay.
|
|
24
27
|
*/
|
|
25
|
-
|
|
28
|
+
interface TimeoutProps {
|
|
26
29
|
setTimeout: ( fn: () => void, delay: number ) => number;
|
|
27
30
|
clearTimeout: ( id: number ) => void;
|
|
28
|
-
}
|
|
31
|
+
}
|
|
29
32
|
|
|
30
33
|
/**
|
|
31
34
|
* A higher-order component used to provide and manage delayed function calls
|
|
32
35
|
* that ought to be bound to a component's lifecycle.
|
|
33
36
|
*/
|
|
34
|
-
const withSafeTimeout = createHigherOrderComponent
|
|
35
|
-
<
|
|
36
|
-
OriginalComponent:
|
|
37
|
+
const withSafeTimeout = createHigherOrderComponent(
|
|
38
|
+
< C extends WithInjectedProps< C, TimeoutProps > >(
|
|
39
|
+
OriginalComponent: C
|
|
37
40
|
) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
> {
|
|
41
|
+
type WrappedProps = WithoutInjectedProps< C, TimeoutProps >;
|
|
42
|
+
return class WrappedComponent extends Component< WrappedProps > {
|
|
41
43
|
timeouts: number[];
|
|
42
44
|
|
|
43
|
-
constructor( props:
|
|
45
|
+
constructor( props: WrappedProps ) {
|
|
44
46
|
super( props );
|
|
45
47
|
this.timeouts = [];
|
|
46
48
|
this.setTimeout = this.setTimeout.bind( this );
|
|
@@ -51,7 +53,7 @@ const withSafeTimeout = createHigherOrderComponent< TimeoutProps >(
|
|
|
51
53
|
this.timeouts.forEach( clearTimeout );
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
setTimeout( fn: (
|
|
56
|
+
setTimeout( fn: () => void, delay: number ) {
|
|
55
57
|
const id = setTimeout( () => {
|
|
56
58
|
fn();
|
|
57
59
|
this.clearTimeout( id );
|
|
@@ -66,13 +68,14 @@ const withSafeTimeout = createHigherOrderComponent< TimeoutProps >(
|
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
render() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
return (
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
<OriginalComponent
|
|
74
|
+
{ ...this.props }
|
|
75
|
+
setTimeout={ this.setTimeout }
|
|
76
|
+
clearTimeout={ this.clearTimeout }
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
76
79
|
}
|
|
77
80
|
};
|
|
78
81
|
},
|
|
@@ -7,7 +7,7 @@ import deprecated from '@wordpress/deprecated';
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
import createHigherOrderComponent from '../../utils/create-higher-order-component';
|
|
10
|
+
import { createHigherOrderComponent } from '../../utils/create-higher-order-component';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* A Higher Order Component used to provide and manage internal component state
|
|
@@ -35,7 +35,7 @@ function useUpdatedRef( value ) {
|
|
|
35
35
|
* @return {import('react').Ref<TElementType>} A ref to assign to the target element.
|
|
36
36
|
*/
|
|
37
37
|
export default function useCopyToClipboard( text, onSuccess ) {
|
|
38
|
-
// Store the dependencies as refs and
|
|
38
|
+
// Store the dependencies as refs and continuously update them so they're
|
|
39
39
|
// fresh when the callback is called.
|
|
40
40
|
const textRef = useUpdatedRef( text );
|
|
41
41
|
const onSuccessRef = useUpdatedRef( onSuccess );
|
|
@@ -27,11 +27,10 @@ import { useEffect } from '@wordpress/element';
|
|
|
27
27
|
*/
|
|
28
28
|
export default function useDebounce( fn, wait, options ) {
|
|
29
29
|
/* eslint-enable jsdoc/valid-types */
|
|
30
|
-
const debounced = useMemoOne(
|
|
31
|
-
fn,
|
|
32
|
-
wait,
|
|
33
|
-
|
|
34
|
-
] );
|
|
30
|
+
const debounced = useMemoOne(
|
|
31
|
+
() => debounce( fn, wait, options ),
|
|
32
|
+
[ fn, wait, options ]
|
|
33
|
+
);
|
|
35
34
|
useEffect( () => () => debounced.cancel(), [ debounced ] );
|
|
36
35
|
return debounced;
|
|
37
36
|
}
|
|
@@ -57,19 +57,20 @@ function useDialog( options ) {
|
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
node.addEventListener(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
node.addEventListener(
|
|
61
|
+
'keydown',
|
|
62
|
+
( /** @type {KeyboardEvent} */ event ) => {
|
|
63
|
+
// Close on escape.
|
|
64
|
+
if (
|
|
65
|
+
event.keyCode === ESCAPE &&
|
|
66
|
+
! event.defaultPrevented &&
|
|
67
|
+
currentOptions.current?.onClose
|
|
68
|
+
) {
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
currentOptions.current.onClose();
|
|
71
|
+
}
|
|
71
72
|
}
|
|
72
|
-
|
|
73
|
+
);
|
|
73
74
|
}, [] );
|
|
74
75
|
|
|
75
76
|
return [
|