@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.
- package/CHANGELOG.md +2 -0
- package/LICENSE.md +1 -1
- package/README.md +4 -16
- package/build/higher-order/if-condition/index.js.map +1 -1
- package/build/higher-order/pure/index.js +1 -1
- package/build/higher-order/pure/index.js.map +1 -1
- package/build/higher-order/with-global-events/index.js +2 -1
- package/build/higher-order/with-global-events/index.js.map +1 -1
- package/build/higher-order/with-instance-id/index.js +2 -6
- package/build/higher-order/with-instance-id/index.js.map +1 -1
- package/build/higher-order/with-safe-timeout/index.js.map +1 -1
- package/build/higher-order/with-state/index.js +1 -0
- package/build/higher-order/with-state/index.js.map +1 -1
- package/build/hooks/use-copy-on-click/index.js +1 -2
- package/build/hooks/use-copy-on-click/index.js.map +1 -1
- package/build/hooks/use-ref-effect/index.js +0 -1
- package/build/hooks/use-ref-effect/index.js.map +1 -1
- package/build/utils/create-higher-order-component/index.js +2 -2
- package/build/utils/create-higher-order-component/index.js.map +1 -1
- package/build-module/higher-order/if-condition/index.js +1 -1
- package/build-module/higher-order/if-condition/index.js.map +1 -1
- package/build-module/higher-order/pure/index.js +4 -1
- package/build-module/higher-order/pure/index.js.map +1 -1
- package/build-module/higher-order/with-global-events/index.js +2 -1
- package/build-module/higher-order/with-global-events/index.js.map +1 -1
- package/build-module/higher-order/with-instance-id/index.js +2 -6
- package/build-module/higher-order/with-instance-id/index.js.map +1 -1
- package/build-module/higher-order/with-safe-timeout/index.js +9 -1
- package/build-module/higher-order/with-safe-timeout/index.js.map +1 -1
- package/build-module/higher-order/with-state/index.js +1 -0
- package/build-module/higher-order/with-state/index.js.map +1 -1
- package/build-module/hooks/use-copy-on-click/index.js +1 -2
- package/build-module/hooks/use-copy-on-click/index.js.map +1 -1
- package/build-module/hooks/use-ref-effect/index.js +0 -1
- package/build-module/hooks/use-ref-effect/index.js.map +1 -1
- package/build-module/utils/create-higher-order-component/index.js +3 -3
- package/build-module/utils/create-higher-order-component/index.js.map +1 -1
- package/build-types/higher-order/if-condition/index.d.ts +2 -2
- package/build-types/higher-order/if-condition/index.d.ts.map +1 -1
- package/build-types/higher-order/pure/index.d.ts +6 -3
- 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 +3 -3
- 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 +2 -2
- package/build-types/higher-order/with-safe-timeout/index.d.ts.map +1 -1
- package/build-types/higher-order/with-state/index.d.ts.map +1 -1
- package/build-types/hooks/use-copy-on-click/index.d.ts.map +1 -1
- package/build-types/hooks/use-ref-effect/index.d.ts.map +1 -1
- package/build-types/utils/create-higher-order-component/index.d.ts +4 -6
- package/build-types/utils/create-higher-order-component/index.d.ts.map +1 -1
- package/package.json +11 -8
- package/src/higher-order/if-condition/index.tsx +5 -6
- package/src/higher-order/pure/index.tsx +5 -5
- package/src/higher-order/with-global-events/index.js +1 -0
- package/src/higher-order/with-instance-id/index.tsx +8 -24
- package/src/higher-order/with-safe-timeout/index.tsx +5 -6
- package/src/higher-order/with-state/index.js +1 -0
- package/src/hooks/use-copy-on-click/index.js +1 -2
- package/src/hooks/use-disabled/test/index.js +2 -0
- package/src/hooks/use-ref-effect/index.ts +0 -1
- package/src/utils/create-higher-order-component/index.ts +15 -21
- 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
|
|
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';
|
|
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
|
|
11
|
-
* @param
|
|
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
|
|
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
|
-
|
|
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
|
|
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":"
|
|
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
|
-
|
|
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
|
|
7
|
+
* only re-rendering when its props/state change
|
|
5
8
|
*/
|
|
6
|
-
declare const pure:
|
|
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":"
|
|
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,
|
|
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
|
-
|
|
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:
|
|
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":"
|
|
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 {
|
|
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:
|
|
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":"
|
|
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,
|
|
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,
|
|
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;
|
|
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<
|
|
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
|
|
19
|
-
* @param
|
|
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<
|
|
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":"
|
|
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
|
|
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.
|
|
36
|
-
"@wordpress/dom": "^3.
|
|
37
|
-
"@wordpress/element": "^4.0
|
|
38
|
-
"@wordpress/is-shallow-equal": "^4.
|
|
39
|
-
"@wordpress/keycodes": "^3.
|
|
40
|
-
"@wordpress/priority-queue": "^2.
|
|
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": "
|
|
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
|
-
)
|
|
27
|
-
createHigherOrderComponent(
|
|
28
|
-
( WrappedComponent ) => ( props
|
|
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
|
|
19
|
+
* only re-rendering when its props/state change
|
|
22
20
|
*/
|
|
23
|
-
const pure
|
|
24
|
-
< 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
|
|
11
|
+
const withInstanceId = createHigherOrderComponent< {
|
|
19
12
|
instanceId: string | number;
|
|
20
|
-
} >
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
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:
|
|
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
|
-
|
|
73
|
+
} as TProps;
|
|
74
|
+
|
|
75
|
+
return <OriginalComponent { ...props } />;
|
|
77
76
|
}
|
|
78
77
|
};
|
|
79
78
|
},
|
|
@@ -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: '
|
|
30
|
-
plugin: 'Gutenberg',
|
|
29
|
+
since: '5.8',
|
|
31
30
|
alternative: 'wp.compose.useCopyToClipboard',
|
|
32
31
|
} );
|
|
33
32
|
|
|
@@ -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<
|
|
18
|
-
|
|
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<
|
|
29
|
-
) =>
|
|
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
|
|
36
|
-
* @param
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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;
|