@wordpress/compose 5.0.7 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/LICENSE.md +1 -1
  3. package/README.md +4 -16
  4. package/build/higher-order/if-condition/index.js.map +1 -1
  5. package/build/higher-order/pure/index.js +1 -1
  6. package/build/higher-order/pure/index.js.map +1 -1
  7. package/build/higher-order/with-global-events/index.js +2 -1
  8. package/build/higher-order/with-global-events/index.js.map +1 -1
  9. package/build/higher-order/with-instance-id/index.js +2 -6
  10. package/build/higher-order/with-instance-id/index.js.map +1 -1
  11. package/build/higher-order/with-safe-timeout/index.js.map +1 -1
  12. package/build/higher-order/with-state/index.js +1 -0
  13. package/build/higher-order/with-state/index.js.map +1 -1
  14. package/build/hooks/use-copy-on-click/index.js +1 -2
  15. package/build/hooks/use-copy-on-click/index.js.map +1 -1
  16. package/build/hooks/use-ref-effect/index.js +0 -1
  17. package/build/hooks/use-ref-effect/index.js.map +1 -1
  18. package/build/utils/create-higher-order-component/index.js +2 -2
  19. package/build/utils/create-higher-order-component/index.js.map +1 -1
  20. package/build-module/higher-order/if-condition/index.js +1 -1
  21. package/build-module/higher-order/if-condition/index.js.map +1 -1
  22. package/build-module/higher-order/pure/index.js +4 -1
  23. package/build-module/higher-order/pure/index.js.map +1 -1
  24. package/build-module/higher-order/with-global-events/index.js +2 -1
  25. package/build-module/higher-order/with-global-events/index.js.map +1 -1
  26. package/build-module/higher-order/with-instance-id/index.js +2 -6
  27. package/build-module/higher-order/with-instance-id/index.js.map +1 -1
  28. package/build-module/higher-order/with-safe-timeout/index.js +9 -1
  29. package/build-module/higher-order/with-safe-timeout/index.js.map +1 -1
  30. package/build-module/higher-order/with-state/index.js +1 -0
  31. package/build-module/higher-order/with-state/index.js.map +1 -1
  32. package/build-module/hooks/use-copy-on-click/index.js +1 -2
  33. package/build-module/hooks/use-copy-on-click/index.js.map +1 -1
  34. package/build-module/hooks/use-ref-effect/index.js +0 -1
  35. package/build-module/hooks/use-ref-effect/index.js.map +1 -1
  36. package/build-module/utils/create-higher-order-component/index.js +3 -3
  37. package/build-module/utils/create-higher-order-component/index.js.map +1 -1
  38. package/build-types/higher-order/if-condition/index.d.ts +2 -2
  39. package/build-types/higher-order/if-condition/index.d.ts.map +1 -1
  40. package/build-types/higher-order/pure/index.d.ts +6 -3
  41. package/build-types/higher-order/pure/index.d.ts.map +1 -1
  42. package/build-types/higher-order/with-global-events/index.d.ts.map +1 -1
  43. package/build-types/higher-order/with-instance-id/index.d.ts +3 -3
  44. package/build-types/higher-order/with-instance-id/index.d.ts.map +1 -1
  45. package/build-types/higher-order/with-safe-timeout/index.d.ts +2 -2
  46. package/build-types/higher-order/with-safe-timeout/index.d.ts.map +1 -1
  47. package/build-types/higher-order/with-state/index.d.ts.map +1 -1
  48. package/build-types/hooks/use-copy-on-click/index.d.ts.map +1 -1
  49. package/build-types/hooks/use-ref-effect/index.d.ts.map +1 -1
  50. package/build-types/utils/create-higher-order-component/index.d.ts +4 -6
  51. package/build-types/utils/create-higher-order-component/index.d.ts.map +1 -1
  52. package/package.json +11 -8
  53. package/src/higher-order/if-condition/index.tsx +5 -6
  54. package/src/higher-order/pure/index.tsx +5 -5
  55. package/src/higher-order/with-global-events/index.js +1 -0
  56. package/src/higher-order/with-instance-id/index.tsx +8 -24
  57. package/src/higher-order/with-safe-timeout/index.tsx +5 -6
  58. package/src/higher-order/with-state/index.js +1 -0
  59. package/src/hooks/use-copy-on-click/index.js +1 -2
  60. package/src/hooks/use-disabled/test/index.js +2 -0
  61. package/src/hooks/use-ref-effect/index.ts +0 -1
  62. package/src/utils/create-higher-order-component/index.ts +15 -21
  63. package/tsconfig.tsbuildinfo +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-ref-effect/index.ts"],"names":["useCallback","useRef","useRefEffect","callback","dependencies","cleanup","node","current"],"mappings":"AAAA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,MAAtB,QAAoC,oBAApC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,YAAT,CACdC,QADc,EAEdC,YAFc,EAGmB;AACjC,QAAMC,OAAO,GAAGJ,MAAM,EAAtB;AACA,SAAOD,WAAW,CAAIM,IAAF,IAA6B;AAChD,QAAKA,IAAL,EAAY;AACXD,MAAAA,OAAO,CAACE,OAAR,GAAkBJ,QAAQ,CAAEG,IAAF,CAA1B;AACA,KAFD,MAEO,IAAKD,OAAO,CAACE,OAAb,EAAuB;AAC7BF,MAAAA,OAAO,CAACE,OAAR;AACA;AACD,GANiB,EAMfH,YANe,CAAlB;AAOA","sourcesContent":["/**\n * External dependencies\n */\n// eslint-disable-next-line no-restricted-imports\nimport type { DependencyList, RefCallback } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useRef } from '@wordpress/element';\n\n/**\n * Effect-like ref callback. Just like with `useEffect`, this allows you to\n * return a cleanup function to be run if the ref changes or one of the\n * dependencies changes. The ref is provided as an argument to the callback\n * functions. The main difference between this and `useEffect` is that\n * the `useEffect` callback is not called when the ref changes, but this is.\n * Pass the returned ref callback as the component's ref and merge multiple refs\n * with `useMergeRefs`.\n *\n * It's worth noting that if the dependencies array is empty, there's not\n * strictly a need to clean up event handlers for example, because the node is\n * to be removed. It *is* necessary if you add dependencies because the ref\n * callback will be called multiple times for the same node.\n *\n * @param callback Callback with ref as argument.\n * @param dependencies Dependencies of the callback.\n *\n * @return Ref callback.\n */\nexport default function useRefEffect< TElement = Node >(\n\tcallback: ( node: TElement ) => ( () => void ) | undefined,\n\tdependencies: DependencyList\n): RefCallback< TElement | null > {\n\tconst cleanup = useRef< ( () => void ) | undefined >();\n\treturn useCallback( ( node: TElement | null ) => {\n\t\tif ( node ) {\n\t\t\tcleanup.current = callback( node );\n\t\t} else if ( cleanup.current ) {\n\t\t\tcleanup.current();\n\t\t}\n\t}, dependencies );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/compose/src/hooks/use-ref-effect/index.ts"],"names":["useCallback","useRef","useRefEffect","callback","dependencies","cleanup","node","current"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,MAAtB,QAAoC,oBAApC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,YAAT,CACdC,QADc,EAEdC,YAFc,EAGmB;AACjC,QAAMC,OAAO,GAAGJ,MAAM,EAAtB;AACA,SAAOD,WAAW,CAAIM,IAAF,IAA6B;AAChD,QAAKA,IAAL,EAAY;AACXD,MAAAA,OAAO,CAACE,OAAR,GAAkBJ,QAAQ,CAAEG,IAAF,CAA1B;AACA,KAFD,MAEO,IAAKD,OAAO,CAACE,OAAb,EAAuB;AAC7BF,MAAAA,OAAO,CAACE,OAAR;AACA;AACD,GANiB,EAMfH,YANe,CAAlB;AAOA","sourcesContent":["/**\n * External dependencies\n */\nimport type { DependencyList, RefCallback } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useRef } from '@wordpress/element';\n\n/**\n * Effect-like ref callback. Just like with `useEffect`, this allows you to\n * return a cleanup function to be run if the ref changes or one of the\n * dependencies changes. The ref is provided as an argument to the callback\n * functions. The main difference between this and `useEffect` is that\n * the `useEffect` callback is not called when the ref changes, but this is.\n * Pass the returned ref callback as the component's ref and merge multiple refs\n * with `useMergeRefs`.\n *\n * It's worth noting that if the dependencies array is empty, there's not\n * strictly a need to clean up event handlers for example, because the node is\n * to be removed. It *is* necessary if you add dependencies because the ref\n * callback will be called multiple times for the same node.\n *\n * @param callback Callback with ref as argument.\n * @param dependencies Dependencies of the callback.\n *\n * @return Ref callback.\n */\nexport default function useRefEffect< TElement = Node >(\n\tcallback: ( node: TElement ) => ( () => void ) | undefined,\n\tdependencies: DependencyList\n): RefCallback< TElement | null > {\n\tconst cleanup = useRef< ( () => void ) | undefined >();\n\treturn useCallback( ( node: TElement | null ) => {\n\t\tif ( node ) {\n\t\t\tcleanup.current = callback( node );\n\t\t} else if ( cleanup.current ) {\n\t\t\tcleanup.current();\n\t\t}\n\t}, dependencies );\n}\n"]}
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { camelCase, upperFirst } from 'lodash'; // eslint-disable-next-line no-restricted-imports
4
+ import { camelCase, upperFirst } from 'lodash';
5
5
 
6
6
  /**
7
7
  * Given a function mapping a component to an enhanced component and modifier
8
8
  * name, returns the enhanced component augmented with a generated displayName.
9
9
  *
10
- * @param mapComponentToEnhancedComponent Function mapping component to enhanced component.
11
- * @param modifierName Seed name from which to generated display name.
10
+ * @param mapComponent Function mapping component to enhanced component.
11
+ * @param modifierName Seed name from which to generated display name.
12
12
  *
13
13
  * @return Component class with generated display name assigned.
14
14
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/utils/create-higher-order-component/index.ts"],"names":["camelCase","upperFirst","createHigherOrderComponent","mapComponent","modifierName","Inner","Outer","displayName","name"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,UAApB,QAAsC,QAAtC,C,CACA;;AA0BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,SAASC,0BAAT,CACCC,YADD,EAECC,YAFD,EAGoD;AACnD,SAASC,KAAF,IAAa;AACnB,UAAMC,KAAK,GAAGH,YAAY,CAAEE,KAAF,CAA1B;AACA,UAAME,WAAW,GAAGF,KAAK,CAACE,WAAN,IAAqBF,KAAK,CAACG,IAA3B,IAAmC,WAAvD;AACAF,IAAAA,KAAK,CAACC,WAAN,GAAqB,GAAGN,UAAU,CACjCD,SAAS,CAAEI,YAAF,CADwB,CAE/B,IAAIG,WAAa,GAFpB;AAGA,WAAOD,KAAP;AACA,GAPD;AAQA;;AACD,eAAeJ,0BAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { camelCase, upperFirst } from 'lodash';\n// eslint-disable-next-line no-restricted-imports\nimport type { ComponentType } from 'react';\n\n/**\n * Higher order components can cause props to be obviated. For example a HOC that\n * injects i18n props will obviate the need for the i18n props to be passed to the component.\n *\n * If a HOC does not obviate the need for any specific props then we default to `{}` which\n * essentially subtracts 0 from the original props of the passed in component. An example\n * of this is the `pure` HOC which does not change the API surface of the component but\n * simply modifies the internals.\n */\nexport type HigherOrderComponent< TInnerProps, TOuterProps > = (\n\tInner: ComponentType< TInnerProps >\n) => ComponentType< TOuterProps >;\n\nexport type SimpleHigherOrderComponent = < TProps >(\n\tInner: ComponentType< TProps >\n) => ComponentType< TProps >;\n\nexport type PropInjectingHigherOrderComponent< TRemovedProps > = <\n\tTProps extends TRemovedProps\n>(\n\tInner: ComponentType< TProps >\n) => ComponentType< Omit< TProps, keyof TRemovedProps > >;\n\n/**\n * Given a function mapping a component to an enhanced component and modifier\n * name, returns the enhanced component augmented with a generated displayName.\n *\n * @param mapComponentToEnhancedComponent Function mapping component to enhanced component.\n * @param modifierName Seed name from which to generated display name.\n *\n * @return Component class with generated display name assigned.\n */\n\nfunction createHigherOrderComponent< TInnerProps, TOuterProps >(\n\tmapComponent: HigherOrderComponent< TInnerProps, TOuterProps >,\n\tmodifierName: string\n): HigherOrderComponent< TInnerProps, TOuterProps > {\n\treturn ( Inner ) => {\n\t\tconst Outer = mapComponent( Inner );\n\t\tconst displayName = Inner.displayName || Inner.name || 'Component';\n\t\tOuter.displayName = `${ upperFirst(\n\t\t\tcamelCase( modifierName )\n\t\t) }(${ displayName })`;\n\t\treturn Outer;\n\t};\n}\nexport default createHigherOrderComponent;\n"]}
1
+ {"version":3,"sources":["@wordpress/compose/src/utils/create-higher-order-component/index.ts"],"names":["camelCase","upperFirst","createHigherOrderComponent","mapComponent","modifierName","Inner","Outer","displayName","name"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,UAApB,QAAsC,QAAtC;;AAoBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,0BAAT,CAEGC,YAFH,EAEmDC,YAFnD,EAE0E;AACzE,SACCC,KADM,IAEF;AACJ,UAAMC,KAAK,GAAGH,YAAY,CAAEE,KAAF,CAA1B;AACA,UAAME,WAAW,GAAGF,KAAK,CAACE,WAAN,IAAqBF,KAAK,CAACG,IAA3B,IAAmC,WAAvD;AACAF,IAAAA,KAAK,CAACC,WAAN,GAAqB,GAAGN,UAAU,CACjCD,SAAS,CAAEI,YAAF,CADwB,CAE/B,IAAIG,WAAa,GAFpB;AAGA,WAAOD,KAAP;AACA,GATD;AAUA;;AAED,eAAeJ,0BAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { camelCase, upperFirst } from 'lodash';\nimport type { ComponentType } from 'react';\n\n/**\n * Higher order components can cause props to be obviated. For example a HOC that\n * injects i18n props will obviate the need for the i18n props to be passed to the component.\n *\n * If a HOC does not obviate the need for any specific props then we default to `{}` which\n * essentially subtracts 0 from the original props of the passed in component. An example\n * of this is the `pure` HOC which does not change the API surface of the component but\n * simply modifies the internals.\n */\nexport type HigherOrderComponent< HOCProps extends Record< string, any > > = <\n\tInnerProps extends HOCProps\n>(\n\tInner: ComponentType< InnerProps >\n) => {} extends HOCProps\n\t? ComponentType< InnerProps >\n\t: ComponentType< Omit< InnerProps, keyof HOCProps > >;\n\n/**\n * Given a function mapping a component to an enhanced component and modifier\n * name, returns the enhanced component augmented with a generated displayName.\n *\n * @param mapComponent Function mapping component to enhanced component.\n * @param modifierName Seed name from which to generated display name.\n *\n * @return Component class with generated display name assigned.\n */\nfunction createHigherOrderComponent<\n\tHOCProps extends Record< string, any > = {}\n>( mapComponent: HigherOrderComponent< HOCProps >, modifierName: string ) {\n\treturn < InnerProps extends HOCProps >(\n\t\tInner: ComponentType< InnerProps >\n\t) => {\n\t\tconst Outer = mapComponent( Inner );\n\t\tconst displayName = Inner.displayName || Inner.name || 'Component';\n\t\tOuter.displayName = `${ upperFirst(\n\t\t\tcamelCase( modifierName )\n\t\t) }(${ displayName })`;\n\t\treturn Outer;\n\t};\n}\n\nexport default createHigherOrderComponent;\n"]}
@@ -1,4 +1,4 @@
1
- import type { HigherOrderComponent } from '../../utils/create-higher-order-component';
1
+ /// <reference types="react" />
2
2
  /**
3
3
  * Higher-order component creator, creating a new component which renders if
4
4
  * the given condition is satisfied or with the given optional prop name.
@@ -16,6 +16,6 @@ import type { HigherOrderComponent } from '../../utils/create-higher-order-compo
16
16
  *
17
17
  * @return Higher-order component.
18
18
  */
19
- declare const ifCondition: <TProps>(predicate: (props: TProps) => boolean) => HigherOrderComponent<TProps, TProps>;
19
+ declare const ifCondition: <TProps extends Record<string, any>>(predicate: (props: TProps) => boolean) => <InnerProps extends {}>(Inner: import("react").ComponentType<InnerProps>) => import("react").ComponentType<InnerProps>;
20
20
  export default ifCondition;
21
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/if-condition/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEtF;;;;;;;;;;;;;;;;GAgBG;AACH,QAAA,MAAM,WAAW,yCACgB,OAAO,yCAWtC,CAAC;AAEH,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/if-condition/index.tsx"],"names":[],"mappings":";AAKA;;;;;;;;;;;;;;;;GAgBG;AACH,QAAA,MAAM,WAAW,qEACgB,OAAO,2HAWtC,CAAC;AAEH,eAAe,WAAW,CAAC"}
@@ -1,8 +1,11 @@
1
- import type { SimpleHigherOrderComponent } from '../../utils/create-higher-order-component';
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import type { ComponentType } from 'react';
2
5
  /**
3
6
  * Given a component returns the enhanced component augmented with a component
4
- * only rerendering when its props/state change
7
+ * only re-rendering when its props/state change
5
8
  */
6
- declare const pure: SimpleHigherOrderComponent;
9
+ declare const pure: <InnerProps extends {}>(Inner: ComponentType<InnerProps>) => ComponentType<InnerProps>;
7
10
  export default pure;
8
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/pure/index.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AAQ5F;;;GAGG;AACH,QAAA,MAAM,IAAI,EAAE,0BAwBX,CAAC;AAEF,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/pure/index.tsx"],"names":[],"mappings":"AAWA;;GAEG;AACH,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,OAAO,CAAC;AAE3D;;;GAGG;AACH,QAAA,MAAM,IAAI,wFA0BT,CAAC;AAEF,eAAe,IAAI,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-global-events/index.js"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;;;GAkBG;AACH,+DATW,OAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,GAOhD,GAAG,CAgEd"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-global-events/index.js"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;;;GAkBG;AACH,+DATW,OAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,GAOhD,GAAG,CAiEd"}
@@ -1,10 +1,10 @@
1
- import type { PropInjectingHigherOrderComponent } from '../../utils/create-higher-order-component';
1
+ /// <reference types="react" />
2
2
  /**
3
3
  * A Higher Order Component used to be provide a unique instance ID by
4
4
  * component.
5
5
  */
6
- declare const withInstanceId: PropInjectingHigherOrderComponent<{
6
+ declare const withInstanceId: <InnerProps extends {
7
7
  instanceId: string | number;
8
- }>;
8
+ }>(Inner: import("react").ComponentType<InnerProps>) => import("react").ComponentType<Omit<InnerProps, "instanceId">>;
9
9
  export default withInstanceId;
10
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-instance-id/index.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,2CAA2C,CAAC;AAGnG;;;GAGG;AACH,QAAA,MAAM,cAAc,EAAE,iCAAiC,CAAE;IACxD,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B,CAeA,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-instance-id/index.tsx"],"names":[],"mappings":";AAMA;;;GAGG;AACH,QAAA,MAAM,cAAc;gBACP,MAAM,GAAG,MAAM;qHAOP,CAAC;AAEtB,eAAe,cAAc,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { PropInjectingHigherOrderComponent } from '../../utils/create-higher-order-component';
1
+ import type { ComponentType } from 'react';
2
2
  /**
3
3
  * We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`
4
4
  * types here because those functions include functionality that is not handled
@@ -15,6 +15,6 @@ declare type TimeoutProps = {
15
15
  * A higher-order component used to provide and manage delayed function calls
16
16
  * that ought to be bound to a component's lifecycle.
17
17
  */
18
- declare const withSafeTimeout: PropInjectingHigherOrderComponent<TimeoutProps>;
18
+ declare const withSafeTimeout: <InnerProps extends TimeoutProps>(Inner: ComponentType<InnerProps>) => ComponentType<Omit<InnerProps, keyof TimeoutProps>>;
19
19
  export default withSafeTimeout;
20
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-safe-timeout/index.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,2CAA2C,CAAC;AAEnG;;;;;;;GAOG;AACH,aAAK,YAAY,GAAG;IACnB,UAAU,EAAE,CAAE,EAAE,EAAE,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,KAAM,MAAM,CAAC;IACxD,YAAY,EAAE,CAAE,EAAE,EAAE,MAAM,KAAM,IAAI,CAAC;CACrC,CAAC;AAEF;;;GAGG;AACH,QAAA,MAAM,eAAe,EAAE,iCAAiC,CAAE,YAAY,CA6CrE,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-safe-timeout/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAY3C;;;;;;;GAOG;AACH,aAAK,YAAY,GAAG;IACnB,UAAU,EAAE,CAAE,EAAE,EAAE,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,KAAM,MAAM,CAAC;IACxD,YAAY,EAAE,CAAE,EAAE,EAAE,MAAM,KAAM,IAAI,CAAC;CACrC,CAAC;AAEF;;;GAGG;AACH,QAAA,MAAM,eAAe,4HA8CpB,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-state/index.js"],"names":[],"mappings":"AAWA;;;;;;;;;GASG;AACH,iDAJW,GAAG,GAEF,GAAG,CA4Bd"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-state/index.js"],"names":[],"mappings":"AAWA;;;;;;;;;GASG;AACH,iDAJW,GAAG,GAEF,GAAG,CA6Bd"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-copy-on-click/index.js"],"names":[],"mappings":"AAYA;;;;;;;;;;;;GAYG;AACH,4CARW,OAAO,OAAO,EAAE,SAAS,CAAC,MAAM,GAAG,OAAO,GAAG,WAAW,OAAO,CAAC,CAAC,QACjE,MAAM,WAAS,iCAId,OAAO,CAuDlB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-copy-on-click/index.js"],"names":[],"mappings":"AAYA;;;;;;;;;;;;GAYG;AACH,4CARW,OAAO,OAAO,EAAE,SAAS,CAAC,MAAM,GAAG,OAAO,GAAG,WAAW,OAAO,CAAC,CAAC,QACjE,MAAM,WAAS,iCAId,OAAO,CAsDlB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-ref-effect/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,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,SAAS,EAC1D,YAAY,EAAE,cAAc,GAC1B,WAAW,CAAE,QAAQ,GAAG,IAAI,CAAE,CAShC"}
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,SAAS,EAC1D,YAAY,EAAE,cAAc,GAC1B,WAAW,CAAE,QAAQ,GAAG,IAAI,CAAE,CAShC"}
@@ -8,18 +8,16 @@ import type { ComponentType } from 'react';
8
8
  * of this is the `pure` HOC which does not change the API surface of the component but
9
9
  * simply modifies the internals.
10
10
  */
11
- export declare type HigherOrderComponent<TInnerProps, TOuterProps> = (Inner: ComponentType<TInnerProps>) => ComponentType<TOuterProps>;
12
- export declare type SimpleHigherOrderComponent = <TProps>(Inner: ComponentType<TProps>) => ComponentType<TProps>;
13
- export declare type PropInjectingHigherOrderComponent<TRemovedProps> = <TProps extends TRemovedProps>(Inner: ComponentType<TProps>) => ComponentType<Omit<TProps, keyof TRemovedProps>>;
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>>;
14
12
  /**
15
13
  * Given a function mapping a component to an enhanced component and modifier
16
14
  * name, returns the enhanced component augmented with a generated displayName.
17
15
  *
18
- * @param mapComponentToEnhancedComponent Function mapping component to enhanced component.
19
- * @param modifierName Seed name from which to generated display name.
16
+ * @param mapComponent Function mapping component to enhanced component.
17
+ * @param modifierName Seed name from which to generated display name.
20
18
  *
21
19
  * @return Component class with generated display name assigned.
22
20
  */
23
- declare function createHigherOrderComponent<TInnerProps, TOuterProps>(mapComponent: HigherOrderComponent<TInnerProps, TOuterProps>, modifierName: string): HigherOrderComponent<TInnerProps, TOuterProps>;
21
+ declare function createHigherOrderComponent<HOCProps extends Record<string, any> = {}>(mapComponent: HigherOrderComponent<HOCProps>, modifierName: string): <InnerProps extends HOCProps>(Inner: ComponentType<InnerProps>) => {} extends HOCProps ? ComponentType<InnerProps> : ComponentType<Omit<InnerProps, keyof HOCProps>>;
24
22
  export default createHigherOrderComponent;
25
23
  //# 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":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C;;;;;;;;GAQG;AACH,oBAAY,oBAAoB,CAAE,WAAW,EAAE,WAAW,IAAK,CAC9D,KAAK,EAAE,aAAa,CAAE,WAAW,CAAE,KAC/B,aAAa,CAAE,WAAW,CAAE,CAAC;AAElC,oBAAY,0BAA0B,GAAG,CAAE,MAAM,EAChD,KAAK,EAAE,aAAa,CAAE,MAAM,CAAE,KAC1B,aAAa,CAAE,MAAM,CAAE,CAAC;AAE7B,oBAAY,iCAAiC,CAAE,aAAa,IAAK,CAChE,MAAM,SAAS,aAAa,EAE5B,KAAK,EAAE,aAAa,CAAE,MAAM,CAAE,KAC1B,aAAa,CAAE,IAAI,CAAE,MAAM,EAAE,MAAM,aAAa,CAAE,CAAE,CAAC;AAE1D;;;;;;;;GAQG;AAEH,iBAAS,0BAA0B,CAAE,WAAW,EAAE,WAAW,EAC5D,YAAY,EAAE,oBAAoB,CAAE,WAAW,EAAE,WAAW,CAAE,EAC9D,YAAY,EAAE,MAAM,GAClB,oBAAoB,CAAE,WAAW,EAAE,WAAW,CAAE,CASlD;AACD,eAAe,0BAA0B,CAAC"}
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;;;;;;;;GAQG;AACH,oBAAY,oBAAoB,CAAE,QAAQ,SAAS,MAAM,CAAE,MAAM,EAAE,GAAG,CAAE,IAAK,CAC5E,UAAU,SAAS,QAAQ,EAE3B,KAAK,EAAE,aAAa,CAAE,UAAU,CAAE,KAC9B,EAAE,SAAS,QAAQ,GACrB,aAAa,CAAE,UAAU,CAAE,GAC3B,aAAa,CAAE,IAAI,CAAE,UAAU,EAAE,MAAM,QAAQ,CAAE,CAAE,CAAC;AAEvD;;;;;;;;GAQG;AACH,iBAAS,0BAA0B,CAClC,QAAQ,SAAS,MAAM,CAAE,MAAM,EAAE,GAAG,CAAE,GAAG,EAAE,EACzC,YAAY,EAAE,oBAAoB,CAAE,QAAQ,CAAE,EAAE,YAAY,EAAE,MAAM,wKAWtE;AAED,eAAe,0BAA0B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/compose",
3
- "version": "5.0.7",
3
+ "version": "5.1.0",
4
4
  "description": "WordPress higher-order components (HOCs).",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -32,20 +32,23 @@
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.2.3",
36
- "@wordpress/dom": "^3.2.7",
37
- "@wordpress/element": "^4.0.4",
38
- "@wordpress/is-shallow-equal": "^4.2.1",
39
- "@wordpress/keycodes": "^3.2.4",
40
- "@wordpress/priority-queue": "^2.2.3",
35
+ "@wordpress/deprecated": "^3.3.0",
36
+ "@wordpress/dom": "^3.3.0",
37
+ "@wordpress/element": "^4.1.0",
38
+ "@wordpress/is-shallow-equal": "^4.3.0",
39
+ "@wordpress/keycodes": "^3.3.0",
40
+ "@wordpress/priority-queue": "^2.3.0",
41
41
  "clipboard": "^2.0.8",
42
42
  "lodash": "^4.17.21",
43
43
  "mousetrap": "^1.6.5",
44
44
  "react-resize-aware": "^3.1.0",
45
45
  "use-memo-one": "^1.1.1"
46
46
  },
47
+ "peerDependencies": {
48
+ "react": "^17.0.0"
49
+ },
47
50
  "publishConfig": {
48
51
  "access": "public"
49
52
  },
50
- "gitHead": "1081a28b2368fcebd9a14554fbd0e25eb33fbcb6"
53
+ "gitHead": "d95ccb9366e249133cdb1d7b25c382446b9ee502"
51
54
  }
@@ -2,7 +2,6 @@
2
2
  * Internal dependencies
3
3
  */
4
4
  import createHigherOrderComponent from '../../utils/create-higher-order-component';
5
- import type { HigherOrderComponent } from '../../utils/create-higher-order-component';
6
5
 
7
6
  /**
8
7
  * Higher-order component creator, creating a new component which renders if
@@ -21,12 +20,12 @@ import type { HigherOrderComponent } from '../../utils/create-higher-order-compo
21
20
  *
22
21
  * @return Higher-order component.
23
22
  */
24
- const ifCondition = < TProps, >(
23
+ const ifCondition = < TProps extends Record< string, any > >(
25
24
  predicate: ( props: TProps ) => boolean
26
- ): HigherOrderComponent< TProps, TProps > =>
27
- createHigherOrderComponent(
28
- ( WrappedComponent ) => ( props: TProps ) => {
29
- if ( ! predicate( props ) ) {
25
+ ) =>
26
+ createHigherOrderComponent< {} >(
27
+ ( WrappedComponent ) => ( props ) => {
28
+ if ( ! predicate( props as TProps ) ) {
30
29
  return null;
31
30
  }
32
31
 
@@ -8,20 +8,20 @@ import { Component } from '@wordpress/element';
8
8
  * Internal dependencies
9
9
  */
10
10
  import createHigherOrderComponent from '../../utils/create-higher-order-component';
11
- import type { SimpleHigherOrderComponent } from '../../utils/create-higher-order-component';
12
11
 
13
12
  /**
14
13
  * External dependencies
15
14
  */
16
- // eslint-disable-next-line no-restricted-imports
17
15
  import type { ComponentType, ComponentClass } from 'react';
18
16
 
19
17
  /**
20
18
  * Given a component returns the enhanced component augmented with a component
21
- * only rerendering when its props/state change
19
+ * only re-rendering when its props/state change
22
20
  */
23
- const pure: SimpleHigherOrderComponent = createHigherOrderComponent(
24
- < TProps, >( Wrapped: ComponentType< TProps > ) => {
21
+ const pure = createHigherOrderComponent(
22
+ < TProps extends Record< string, any > >(
23
+ Wrapped: ComponentType< TProps >
24
+ ) => {
25
25
  if ( Wrapped.prototype instanceof Component ) {
26
26
  return class extends ( Wrapped as ComponentClass< TProps > ) {
27
27
  shouldComponentUpdate( nextProps: TProps, nextState: any ) {
@@ -46,6 +46,7 @@ export default function withGlobalEvents( eventTypesToHandlers ) {
46
46
  alternative: 'useEffect',
47
47
  } );
48
48
 
49
+ // @ts-ignore We don't need to fix the type-related issues because this is deprecated.
49
50
  return createHigherOrderComponent( ( WrappedComponent ) => {
50
51
  class Wrapper extends Component {
51
52
  constructor( /** @type {any} */ props ) {
@@ -1,37 +1,21 @@
1
- /**
2
- * External dependencies
3
- */
4
- // eslint-disable-next-line no-restricted-imports
5
- import type { ComponentType } from 'react';
6
-
7
1
  /**
8
2
  * Internal dependencies
9
3
  */
10
4
  import createHigherOrderComponent from '../../utils/create-higher-order-component';
11
- import type { PropInjectingHigherOrderComponent } from '../../utils/create-higher-order-component';
12
5
  import useInstanceId from '../../hooks/use-instance-id';
13
6
 
14
7
  /**
15
8
  * A Higher Order Component used to be provide a unique instance ID by
16
9
  * component.
17
10
  */
18
- const withInstanceId: PropInjectingHigherOrderComponent< {
11
+ const withInstanceId = createHigherOrderComponent< {
19
12
  instanceId: string | number;
20
- } > = createHigherOrderComponent(
21
- < TProps extends { instanceId: string | number } >(
22
- WrappedComponent: ComponentType< TProps >
23
- ) => {
24
- return ( props: Omit< TProps, 'instanceId' > ) => {
25
- const instanceId = useInstanceId( WrappedComponent );
26
- return (
27
- <WrappedComponent
28
- { ...( props as TProps ) }
29
- instanceId={ instanceId }
30
- />
31
- );
32
- };
33
- },
34
- 'withInstanceId'
35
- );
13
+ } >( ( WrappedComponent ) => {
14
+ return ( props ) => {
15
+ const instanceId = useInstanceId( WrappedComponent );
16
+ // @ts-ignore
17
+ return <WrappedComponent { ...props } instanceId={ instanceId } />;
18
+ };
19
+ }, 'withInstanceId' );
36
20
 
37
21
  export default withInstanceId;
@@ -2,7 +2,6 @@
2
2
  * External dependencies
3
3
  */
4
4
  import { without } from 'lodash';
5
- // eslint-disable-next-line no-restricted-imports
6
5
  import type { ComponentType } from 'react';
7
6
 
8
7
  /**
@@ -14,7 +13,6 @@ import { Component } from '@wordpress/element';
14
13
  * Internal dependencies
15
14
  */
16
15
  import createHigherOrderComponent from '../../utils/create-higher-order-component';
17
- import type { PropInjectingHigherOrderComponent } from '../../utils/create-higher-order-component';
18
16
 
19
17
  /**
20
18
  * We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`
@@ -33,7 +31,7 @@ type TimeoutProps = {
33
31
  * A higher-order component used to provide and manage delayed function calls
34
32
  * that ought to be bound to a component's lifecycle.
35
33
  */
36
- const withSafeTimeout: PropInjectingHigherOrderComponent< TimeoutProps > = createHigherOrderComponent(
34
+ const withSafeTimeout = createHigherOrderComponent< TimeoutProps >(
37
35
  < TProps extends TimeoutProps >(
38
36
  OriginalComponent: ComponentType< TProps >
39
37
  ) => {
@@ -42,7 +40,7 @@ const withSafeTimeout: PropInjectingHigherOrderComponent< TimeoutProps > = creat
42
40
  > {
43
41
  timeouts: number[];
44
42
 
45
- constructor( props: any ) {
43
+ constructor( props: Omit< TProps, keyof TimeoutProps > ) {
46
44
  super( props );
47
45
  this.timeouts = [];
48
46
  this.setTimeout = this.setTimeout.bind( this );
@@ -72,8 +70,9 @@ const withSafeTimeout: PropInjectingHigherOrderComponent< TimeoutProps > = creat
72
70
  ...this.props,
73
71
  setTimeout: this.setTimeout,
74
72
  clearTimeout: this.clearTimeout,
75
- };
76
- return <OriginalComponent { ...( props as TProps ) } />;
73
+ } as TProps;
74
+
75
+ return <OriginalComponent { ...props } />;
77
76
  }
78
77
  };
79
78
  },
@@ -21,6 +21,7 @@ import createHigherOrderComponent from '../../utils/create-higher-order-componen
21
21
  */
22
22
  export default function withState( initialState = {} ) {
23
23
  deprecated( 'wp.compose.withState', {
24
+ since: '5.8',
24
25
  alternative: 'wp.element.useState',
25
26
  } );
26
27
 
@@ -26,8 +26,7 @@ import deprecated from '@wordpress/deprecated';
26
26
  export default function useCopyOnClick( ref, text, timeout = 4000 ) {
27
27
  /* eslint-enable jsdoc/no-undefined-types */
28
28
  deprecated( 'wp.compose.useCopyOnClick', {
29
- since: '10.3',
30
- plugin: 'Gutenberg',
29
+ since: '5.8',
31
30
  alternative: 'wp.compose.useCopyToClipboard',
32
31
  } );
33
32
 
@@ -43,6 +43,8 @@ jest.mock( '@wordpress/dom', () => {
43
43
  };
44
44
  } );
45
45
 
46
+ jest.useRealTimers();
47
+
46
48
  describe( 'useDisabled', () => {
47
49
  const Form = forwardRef( ( { showButton }, ref ) => {
48
50
  return (
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- // eslint-disable-next-line no-restricted-imports
5
4
  import type { DependencyList, RefCallback } from 'react';
6
5
 
7
6
  /**
@@ -2,7 +2,6 @@
2
2
  * External dependencies
3
3
  */
4
4
  import { camelCase, upperFirst } from 'lodash';
5
- // eslint-disable-next-line no-restricted-imports
6
5
  import type { ComponentType } from 'react';
7
6
 
8
7
  /**
@@ -14,35 +13,29 @@ import type { ComponentType } from 'react';
14
13
  * of this is the `pure` HOC which does not change the API surface of the component but
15
14
  * simply modifies the internals.
16
15
  */
17
- export type HigherOrderComponent< TInnerProps, TOuterProps > = (
18
- Inner: ComponentType< TInnerProps >
19
- ) => ComponentType< TOuterProps >;
20
-
21
- export type SimpleHigherOrderComponent = < TProps >(
22
- Inner: ComponentType< TProps >
23
- ) => ComponentType< TProps >;
24
-
25
- export type PropInjectingHigherOrderComponent< TRemovedProps > = <
26
- TProps extends TRemovedProps
16
+ export type HigherOrderComponent< HOCProps extends Record< string, any > > = <
17
+ InnerProps extends HOCProps
27
18
  >(
28
- Inner: ComponentType< TProps >
29
- ) => ComponentType< Omit< TProps, keyof TRemovedProps > >;
19
+ Inner: ComponentType< InnerProps >
20
+ ) => {} extends HOCProps
21
+ ? ComponentType< InnerProps >
22
+ : ComponentType< Omit< InnerProps, keyof HOCProps > >;
30
23
 
31
24
  /**
32
25
  * Given a function mapping a component to an enhanced component and modifier
33
26
  * name, returns the enhanced component augmented with a generated displayName.
34
27
  *
35
- * @param mapComponentToEnhancedComponent Function mapping component to enhanced component.
36
- * @param modifierName Seed name from which to generated display name.
28
+ * @param mapComponent Function mapping component to enhanced component.
29
+ * @param modifierName Seed name from which to generated display name.
37
30
  *
38
31
  * @return Component class with generated display name assigned.
39
32
  */
40
-
41
- function createHigherOrderComponent< TInnerProps, TOuterProps >(
42
- mapComponent: HigherOrderComponent< TInnerProps, TOuterProps >,
43
- modifierName: string
44
- ): HigherOrderComponent< TInnerProps, TOuterProps > {
45
- return ( Inner ) => {
33
+ function createHigherOrderComponent<
34
+ HOCProps extends Record< string, any > = {}
35
+ >( mapComponent: HigherOrderComponent< HOCProps >, modifierName: string ) {
36
+ return < InnerProps extends HOCProps >(
37
+ Inner: ComponentType< InnerProps >
38
+ ) => {
46
39
  const Outer = mapComponent( Inner );
47
40
  const displayName = Inner.displayName || Inner.name || 'Component';
48
41
  Outer.displayName = `${ upperFirst(
@@ -51,4 +44,5 @@ function createHigherOrderComponent< TInnerProps, TOuterProps >(
51
44
  return Outer;
52
45
  };
53
46
  }
47
+
54
48
  export default createHigherOrderComponent;