@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
package/CHANGELOG.md
CHANGED
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -79,12 +79,12 @@ name, returns the enhanced component augmented with a generated displayName.
|
|
|
79
79
|
|
|
80
80
|
_Parameters_
|
|
81
81
|
|
|
82
|
-
-
|
|
82
|
+
- _mapComponent_ `HigherOrderComponent< HOCProps >`: Function mapping component to enhanced component.
|
|
83
83
|
- _modifierName_ `string`: Seed name from which to generated display name.
|
|
84
84
|
|
|
85
85
|
_Returns_
|
|
86
86
|
|
|
87
|
-
-
|
|
87
|
+
- Component class with generated display name assigned.
|
|
88
88
|
|
|
89
89
|
### ifCondition
|
|
90
90
|
|
|
@@ -109,16 +109,12 @@ _Parameters_
|
|
|
109
109
|
|
|
110
110
|
_Returns_
|
|
111
111
|
|
|
112
|
-
-
|
|
112
|
+
- Higher-order component.
|
|
113
113
|
|
|
114
114
|
### pure
|
|
115
115
|
|
|
116
116
|
Given a component returns the enhanced component augmented with a component
|
|
117
|
-
only
|
|
118
|
-
|
|
119
|
-
_Type_
|
|
120
|
-
|
|
121
|
-
- `SimpleHigherOrderComponent`
|
|
117
|
+
only re-rendering when its props/state change
|
|
122
118
|
|
|
123
119
|
### useAsyncList
|
|
124
120
|
|
|
@@ -528,19 +524,11 @@ _Returns_
|
|
|
528
524
|
A Higher Order Component used to be provide a unique instance ID by
|
|
529
525
|
component.
|
|
530
526
|
|
|
531
|
-
_Type_
|
|
532
|
-
|
|
533
|
-
- `PropInjectingHigherOrderComponent< { instanceId: string | number; } >`
|
|
534
|
-
|
|
535
527
|
### withSafeTimeout
|
|
536
528
|
|
|
537
529
|
A higher-order component used to provide and manage delayed function calls
|
|
538
530
|
that ought to be bound to a component's lifecycle.
|
|
539
531
|
|
|
540
|
-
_Type_
|
|
541
|
-
|
|
542
|
-
- `PropInjectingHigherOrderComponent< TimeoutProps >`
|
|
543
|
-
|
|
544
532
|
### withState
|
|
545
533
|
|
|
546
534
|
> **Deprecated** Use `useState` instead.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/if-condition/index.tsx"],"names":["ifCondition","predicate","WrappedComponent","props"],"mappings":";;;;;;;;;;;AAGA;;AAHA;AACA;AACA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/if-condition/index.tsx"],"names":["ifCondition","predicate","WrappedComponent","props"],"mappings":";;;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,WAAW,GAChBC,SADmB,IAGnB,yCACGC,gBAAF,IAA0BC,KAAF,IAAa;AACpC,MAAK,CAAEF,SAAS,CAAEE,KAAF,CAAhB,EAAsC;AACrC,WAAO,IAAP;AACA;;AAED,SAAO,4BAAC,gBAAD,EAAuBA,KAAvB,CAAP;AACA,CAPF,EAQC,aARD,CAHD;;eAceH,W","sourcesContent":["/**\n * Internal dependencies\n */\nimport createHigherOrderComponent from '../../utils/create-higher-order-component';\n\n/**\n * Higher-order component creator, creating a new component which renders if\n * the given condition is satisfied or with the given optional prop name.\n *\n * @example\n * ```ts\n * type Props = { foo: string };\n * const Component = ( props: Props ) => <div>{ props.foo }</div>;\n * const ConditionalComponent = ifCondition( ( props: Props ) => props.foo.length !== 0 )( Component );\n * <ConditionalComponent foo=\"\" />; // => null\n * <ConditionalComponent foo=\"bar\" />; // => <div>bar</div>;\n * ```\n *\n * @param predicate Function to test condition.\n *\n * @return Higher-order component.\n */\nconst ifCondition = < TProps extends Record< string, any > >(\n\tpredicate: ( props: TProps ) => boolean\n) =>\n\tcreateHigherOrderComponent< {} >(\n\t\t( WrappedComponent ) => ( props ) => {\n\t\t\tif ( ! predicate( props as TProps ) ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn <WrappedComponent { ...props } />;\n\t\t},\n\t\t'ifCondition'\n\t);\n\nexport default ifCondition;\n"]}
|
|
@@ -23,7 +23,7 @@ var _createHigherOrderComponent = _interopRequireDefault(require("../../utils/cr
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Given a component returns the enhanced component augmented with a component
|
|
26
|
-
* only
|
|
26
|
+
* only re-rendering when its props/state change
|
|
27
27
|
*/
|
|
28
28
|
const pure = (0, _createHigherOrderComponent.default)(Wrapped => {
|
|
29
29
|
if (Wrapped.prototype instanceof _element.Component) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/pure/index.tsx"],"names":["pure","Wrapped","prototype","Component","shouldComponentUpdate","nextProps","nextState","props","state","render"],"mappings":";;;;;;;;;AAIA;;AADA;;AAMA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/pure/index.tsx"],"names":["pure","Wrapped","prototype","Component","shouldComponentUpdate","nextProps","nextState","props","state","render"],"mappings":";;;;;;;;;AAIA;;AADA;;AAMA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA,MAAMA,IAAI,GAAG,yCAEXC,OADD,IAEK;AACJ,MAAKA,OAAO,CAACC,SAAR,YAA6BC,kBAAlC,EAA8C;AAC7C,WAAO,cAAgBF,OAAhB,CAAsD;AAC5DG,MAAAA,qBAAqB,CAAEC,SAAF,EAAqBC,SAArB,EAAsC;AAC1D,eACC,CAAE,6BAAgBD,SAAhB,EAA2B,KAAKE,KAAhC,CAAF,IACA,CAAE,6BAAgBD,SAAhB,EAA2B,KAAKE,KAAhC,CAFH;AAIA;;AAN2D,KAA7D;AAQA;;AAED,SAAO,cAAcL,kBAAd,CAAkC;AACxCC,IAAAA,qBAAqB,CAAEC,SAAF,EAAsB;AAC1C,aAAO,CAAE,6BAAgBA,SAAhB,EAA2B,KAAKE,KAAhC,CAAT;AACA;;AAEDE,IAAAA,MAAM,GAAG;AACR,aAAO,4BAAC,OAAD,EAAc,KAAKF,KAAnB,CAAP;AACA;;AAPuC,GAAzC;AASA,CAxBW,EAyBZ,MAzBY,CAAb;eA4BeP,I","sourcesContent":["/**\n * WordPress dependencies\n */\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { Component } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport createHigherOrderComponent from '../../utils/create-higher-order-component';\n\n/**\n * External dependencies\n */\nimport type { ComponentType, ComponentClass } from 'react';\n\n/**\n * Given a component returns the enhanced component augmented with a component\n * only re-rendering when its props/state change\n */\nconst pure = createHigherOrderComponent(\n\t< TProps extends Record< string, any > >(\n\t\tWrapped: ComponentType< TProps >\n\t) => {\n\t\tif ( Wrapped.prototype instanceof Component ) {\n\t\t\treturn class extends ( Wrapped as ComponentClass< TProps > ) {\n\t\t\t\tshouldComponentUpdate( nextProps: TProps, nextState: any ) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t! isShallowEqual( nextProps, this.props ) ||\n\t\t\t\t\t\t! isShallowEqual( nextState, this.state )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\treturn class extends Component< TProps > {\n\t\t\tshouldComponentUpdate( nextProps: TProps ) {\n\t\t\t\treturn ! isShallowEqual( nextProps, this.props );\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn <Wrapped { ...this.props } />;\n\t\t\t}\n\t\t};\n\t},\n\t'pure'\n);\n\nexport default pure;\n"]}
|
|
@@ -61,7 +61,8 @@ function withGlobalEvents(eventTypesToHandlers) {
|
|
|
61
61
|
(0, _deprecated.default)('wp.compose.withGlobalEvents', {
|
|
62
62
|
since: '5.7',
|
|
63
63
|
alternative: 'useEffect'
|
|
64
|
-
});
|
|
64
|
+
}); // @ts-ignore We don't need to fix the type-related issues because this is deprecated.
|
|
65
|
+
|
|
65
66
|
return (0, _createHigherOrderComponent.default)(WrappedComponent => {
|
|
66
67
|
class Wrapper extends _element.Component {
|
|
67
68
|
constructor(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-global-events/index.js"],"names":["listener","Listener","withGlobalEvents","eventTypesToHandlers","since","alternative","WrappedComponent","Wrapper","Component","constructor","props","handleEvent","bind","handleRef","componentDidMount","_","eventType","add","componentWillUnmount","remove","event","handler","type","wrappedRef","el","forwardedRef","render","ownProps","ref"],"mappings":";;;;;;;;;AAQA;;;;AALA;;AAMA;;AAKA;;AACA;;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;AACA,MAAMA,QAAQ,GAAG,IAAIC,iBAAJ,EAAjB;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,gBAAT,CAA2BC,oBAA3B,EAAkD;AAChE,2BAAY,6BAAZ,EAA2C;AAC1CC,IAAAA,KAAK,EAAE,KADmC;AAE1CC,IAAAA,WAAW,EAAE;AAF6B,GAA3C
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-global-events/index.js"],"names":["listener","Listener","withGlobalEvents","eventTypesToHandlers","since","alternative","WrappedComponent","Wrapper","Component","constructor","props","handleEvent","bind","handleRef","componentDidMount","_","eventType","add","componentWillUnmount","remove","event","handler","type","wrappedRef","el","forwardedRef","render","ownProps","ref"],"mappings":";;;;;;;;;AAQA;;;;AALA;;AAMA;;AAKA;;AACA;;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;AACA,MAAMA,QAAQ,GAAG,IAAIC,iBAAJ,EAAjB;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,gBAAT,CAA2BC,oBAA3B,EAAkD;AAChE,2BAAY,6BAAZ,EAA2C;AAC1CC,IAAAA,KAAK,EAAE,KADmC;AAE1CC,IAAAA,WAAW,EAAE;AAF6B,GAA3C,EADgE,CAMhE;;AACA,SAAO,yCAA8BC,gBAAF,IAAwB;AAC1D,UAAMC,OAAN,SAAsBC,kBAAtB,CAAgC;AAC/BC,MAAAA,WAAW;AAAE;AAAmBC,MAAAA,KAArB,EAA6B;AACvC,cAAOA,KAAP;AAEA,aAAKC,WAAL,GAAmB,KAAKA,WAAL,CAAiBC,IAAjB,CAAuB,IAAvB,CAAnB;AACA,aAAKC,SAAL,GAAiB,K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uDJ,kBAvDI,CAAP;AAwDA","sourcesContent":["/**\n * External dependencies\n */\nimport { forEach } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { Component, forwardRef } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createHigherOrderComponent from '../../utils/create-higher-order-component';\nimport Listener from './listener';\n\n/**\n * Listener instance responsible for managing document event handling.\n */\nconst listener = new Listener();\n\n/* eslint-disable jsdoc/no-undefined-types */\n/**\n * Higher-order component creator which, given an object of DOM event types and\n * values corresponding to a callback function name on the component, will\n * create or update a window event handler to invoke the callback when an event\n * occurs. On behalf of the consuming developer, the higher-order component\n * manages unbinding when the component unmounts, and binding at most a single\n * event handler for the entire application.\n *\n * @deprecated\n *\n * @param {Record<keyof GlobalEventHandlersEventMap, string>} eventTypesToHandlers Object with keys of DOM\n * event type, the value a\n * name of the function on\n * the original component's\n * instance which handles\n * the event.\n *\n * @return {any} Higher-order component.\n */\nexport default function withGlobalEvents( eventTypesToHandlers ) {\n\tdeprecated( 'wp.compose.withGlobalEvents', {\n\t\tsince: '5.7',\n\t\talternative: 'useEffect',\n\t} );\n\n\t// @ts-ignore We don't need to fix the type-related issues because this is deprecated.\n\treturn createHigherOrderComponent( ( WrappedComponent ) => {\n\t\tclass Wrapper extends Component {\n\t\t\tconstructor( /** @type {any} */ props ) {\n\t\t\t\tsuper( props );\n\n\t\t\t\tthis.handleEvent = this.handleEvent.bind( this );\n\t\t\t\tthis.handleRef = this.handleRef.bind( this );\n\t\t\t}\n\n\t\t\tcomponentDidMount() {\n\t\t\t\tforEach( eventTypesToHandlers, ( _, eventType ) => {\n\t\t\t\t\tlistener.add( eventType, this );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tcomponentWillUnmount() {\n\t\t\t\tforEach( eventTypesToHandlers, ( _, eventType ) => {\n\t\t\t\t\tlistener.remove( eventType, this );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\thandleEvent( /** @type {any} */ event ) {\n\t\t\t\tconst handler =\n\t\t\t\t\teventTypesToHandlers[\n\t\t\t\t\t\t/** @type {keyof GlobalEventHandlersEventMap} */ ( event.type )\n\t\t\t\t\t\t/* eslint-enable jsdoc/no-undefined-types */\n\t\t\t\t\t];\n\t\t\t\tif ( typeof this.wrappedRef[ handler ] === 'function' ) {\n\t\t\t\t\tthis.wrappedRef[ handler ]( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\thandleRef( /** @type {any} */ el ) {\n\t\t\t\tthis.wrappedRef = el;\n\t\t\t\t// Any component using `withGlobalEvents` that is not setting a `ref`\n\t\t\t\t// will cause `this.props.forwardedRef` to be `null`, so we need this\n\t\t\t\t// check.\n\t\t\t\tif ( this.props.forwardedRef ) {\n\t\t\t\t\tthis.props.forwardedRef( el );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t{ ...this.props.ownProps }\n\t\t\t\t\t\tref={ this.handleRef }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn forwardRef( ( props, ref ) => {\n\t\t\treturn <Wrapper ownProps={ props } forwardedRef={ ref } />;\n\t\t} );\n\t}, 'withGlobalEvents' );\n}\n"]}
|
|
@@ -15,11 +15,6 @@ var _createHigherOrderComponent = _interopRequireDefault(require("../../utils/cr
|
|
|
15
15
|
|
|
16
16
|
var _useInstanceId = _interopRequireDefault(require("../../hooks/use-instance-id"));
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* External dependencies
|
|
20
|
-
*/
|
|
21
|
-
// eslint-disable-next-line no-restricted-imports
|
|
22
|
-
|
|
23
18
|
/**
|
|
24
19
|
* Internal dependencies
|
|
25
20
|
*/
|
|
@@ -30,7 +25,8 @@ var _useInstanceId = _interopRequireDefault(require("../../hooks/use-instance-id
|
|
|
30
25
|
*/
|
|
31
26
|
const withInstanceId = (0, _createHigherOrderComponent.default)(WrappedComponent => {
|
|
32
27
|
return props => {
|
|
33
|
-
const instanceId = (0, _useInstanceId.default)(WrappedComponent);
|
|
28
|
+
const instanceId = (0, _useInstanceId.default)(WrappedComponent); // @ts-ignore
|
|
29
|
+
|
|
34
30
|
return (0, _element.createElement)(WrappedComponent, (0, _extends2.default)({}, props, {
|
|
35
31
|
instanceId: instanceId
|
|
36
32
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-instance-id/index.tsx"],"names":["withInstanceId","WrappedComponent","props","instanceId"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-instance-id/index.tsx"],"names":["withInstanceId","WrappedComponent","props","instanceId"],"mappings":";;;;;;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA,MAAMA,cAAc,GAAG,yCAEhBC,gBAAF,IAAwB;AAC5B,SAASC,KAAF,IAAa;AACnB,UAAMC,UAAU,GAAG,4BAAeF,gBAAf,CAAnB,CADmB,CAEnB;;AACA,WAAO,4BAAC,gBAAD,6BAAuBC,KAAvB;AAA+B,MAAA,UAAU,EAAGC;AAA5C,OAAP;AACA,GAJD;AAKA,CARsB,EAQpB,gBARoB,CAAvB;eAUeH,c","sourcesContent":["/**\n * Internal dependencies\n */\nimport createHigherOrderComponent from '../../utils/create-higher-order-component';\nimport useInstanceId from '../../hooks/use-instance-id';\n\n/**\n * A Higher Order Component used to be provide a unique instance ID by\n * component.\n */\nconst withInstanceId = createHigherOrderComponent< {\n\tinstanceId: string | number;\n} >( ( WrappedComponent ) => {\n\treturn ( props ) => {\n\t\tconst instanceId = useInstanceId( WrappedComponent );\n\t\t// @ts-ignore\n\t\treturn <WrappedComponent { ...props } instanceId={ instanceId } />;\n\t};\n}, 'withInstanceId' );\n\nexport default withInstanceId;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-safe-timeout/index.tsx"],"names":["withSafeTimeout","OriginalComponent","WrappedComponent","Component","constructor","props","timeouts","setTimeout","bind","clearTimeout","componentWillUnmount","forEach","fn","delay","id","push","render"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-safe-timeout/index.tsx"],"names":["withSafeTimeout","OriginalComponent","WrappedComponent","Component","constructor","props","timeouts","setTimeout","bind","clearTimeout","componentWillUnmount","forEach","fn","delay","id","push","render"],"mappings":";;;;;;;;;AASA;;AANA;;AAWA;;AAdA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;;AAgBA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAAG,yCAEtBC,iBADD,IAEK;AACJ,SAAO,MAAMC,gBAAN,SAA+BC,kBAA/B,CAEL;AAGDC,IAAAA,WAAW,CAAEC,KAAF,EAA8C;AACxD,YAAOA,KAAP;AACA,WAAKC,QAAL,GAAgB,EAAhB;AACA,WAAKC,UAAL,GAAkB,KAAKA,UAAL,CAAgBC,IAAhB,CAAsB,IAAtB,CAAlB;AACA,WAAKC,YAAL,GAAoB,KAAKA,YAAL,CAAkBD,IAAlB,CAAwB,IAAxB,CAApB;AACA;;AAEDE,IAAAA,oBAAoB,GAAG;AACtB,WAAKJ,QAAL,CAAcK,OAAd,CAAuBF,YAAvB;AACA;;AAEDF,IAAAA,UAAU,CAAEK,EAAF,EAAkCC,KAAlC,EAAkD;AAC3D,YAAMC,EAAE,GAAGP,UAAU,CAAE,MAAM;AAC5BK,QAAAA,EAAE;AACF,aAAKH,YAAL,CAAmBK,EAAnB;AACA,OAHoB,EAGlBD,KAHkB,CAArB;AAIA,WAAKP,QAAL,CAAcS,IAAd,CAAoBD,EAApB;AACA,aAAOA,EAAP;AACA;;AAEDL,IAAAA,YAAY,CAAEK,EAAF,EAAe;AAC1BL,MAAAA,YAAY,CAAEK,EAAF,CAAZ;AACA,WAAKR,QAAL,GAAgB,qBAAS,KAAKA,QAAd,EAAwBQ,EAAxB,CAAhB;AACA;;AAEDE,IAAAA,MAAM,GAAG;AACR,YAAMX,KAAK,GAAG,EACb,GAAG,KAAKA,KADK;AAEbE,QAAAA,UAAU,EAAE,KAAKA,UAFJ;AAGbE,QAAAA,YAAY,EAAE,KAAKA;AAHN,OAAd;AAMA,aAAO,4BAAC,iBAAD,EAAwBJ,KAAxB,CAAP;AACA;;AApCA,GAFF;AAwCA,CA5CsB,EA6CvB,iBA7CuB,CAAxB;eAgDeL,e","sourcesContent":["/**\n * External dependencies\n */\nimport { without } from 'lodash';\nimport type { ComponentType } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport createHigherOrderComponent from '../../utils/create-higher-order-component';\n\n/**\n * We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`\n * types here because those functions include functionality that is not handled\n * by this component, like the ability to pass extra arguments.\n *\n * In the case of this component, we only handle the simplest case where\n * `setTimeout` only accepts a function (not a string) and an optional delay.\n */\ntype TimeoutProps = {\n\tsetTimeout: ( fn: () => void, delay: number ) => number;\n\tclearTimeout: ( id: number ) => void;\n};\n\n/**\n * A higher-order component used to provide and manage delayed function calls\n * that ought to be bound to a component's lifecycle.\n */\nconst withSafeTimeout = createHigherOrderComponent< TimeoutProps >(\n\t< TProps extends TimeoutProps >(\n\t\tOriginalComponent: ComponentType< TProps >\n\t) => {\n\t\treturn class WrappedComponent extends Component<\n\t\t\tOmit< TProps, keyof TimeoutProps >\n\t\t> {\n\t\t\ttimeouts: number[];\n\n\t\t\tconstructor( props: Omit< TProps, keyof TimeoutProps > ) {\n\t\t\t\tsuper( props );\n\t\t\t\tthis.timeouts = [];\n\t\t\t\tthis.setTimeout = this.setTimeout.bind( this );\n\t\t\t\tthis.clearTimeout = this.clearTimeout.bind( this );\n\t\t\t}\n\n\t\t\tcomponentWillUnmount() {\n\t\t\t\tthis.timeouts.forEach( clearTimeout );\n\t\t\t}\n\n\t\t\tsetTimeout( fn: ( ...args: any[] ) => void, delay: number ) {\n\t\t\t\tconst id = setTimeout( () => {\n\t\t\t\t\tfn();\n\t\t\t\t\tthis.clearTimeout( id );\n\t\t\t\t}, delay );\n\t\t\t\tthis.timeouts.push( id );\n\t\t\t\treturn id;\n\t\t\t}\n\n\t\t\tclearTimeout( id: number ) {\n\t\t\t\tclearTimeout( id );\n\t\t\t\tthis.timeouts = without( this.timeouts, id );\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\tconst props = {\n\t\t\t\t\t...this.props,\n\t\t\t\t\tsetTimeout: this.setTimeout,\n\t\t\t\t\tclearTimeout: this.clearTimeout,\n\t\t\t\t} as TProps;\n\n\t\t\t\treturn <OriginalComponent { ...props } />;\n\t\t\t}\n\t\t};\n\t},\n\t'withSafeTimeout'\n);\n\nexport default withSafeTimeout;\n"]}
|
|
@@ -36,6 +36,7 @@ var _createHigherOrderComponent = _interopRequireDefault(require("../../utils/cr
|
|
|
36
36
|
function withState() {
|
|
37
37
|
let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
38
38
|
(0, _deprecated.default)('wp.compose.withState', {
|
|
39
|
+
since: '5.8',
|
|
39
40
|
alternative: 'wp.element.useState'
|
|
40
41
|
});
|
|
41
42
|
return (0, _createHigherOrderComponent.default)(OriginalComponent => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-state/index.js"],"names":["withState","initialState","alternative","OriginalComponent","WrappedComponent","Component","constructor","props","setState","bind","state","render"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,SAAT,GAAwC;AAAA,MAApBC,YAAoB,uEAAL,EAAK;AACtD,2BAAY,sBAAZ,EAAoC;AACnCC,IAAAA,WAAW,EAAE;
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-state/index.js"],"names":["withState","initialState","since","alternative","OriginalComponent","WrappedComponent","Component","constructor","props","setState","bind","state","render"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,SAAT,GAAwC;AAAA,MAApBC,YAAoB,uEAAL,EAAK;AACtD,2BAAY,sBAAZ,EAAoC;AACnCC,IAAAA,KAAK,EAAE,KAD4B;AAEnCC,IAAAA,WAAW,EAAE;AAFsB,GAApC;AAKA,SAAO,yCAA8BC,iBAAF,IAAyB;AAC3D,WAAO,MAAMC,gBAAN,SAA+BC,kBAA/B,CAAyC;AAC/CC,MAAAA,WAAW;AAAE;AAAmBC,MAAAA,KAArB,EAA6B;AACvC,cAAOA,KAAP;AAEA,aAAKC,QAAL,GAAgB,KAAKA,QAAL,CAAcC,IAAd,CAAoB,IAApB,CAAhB;AAEA,aAAKC,KAAL,GAAaV,YAAb;AACA;;AAEDW,MAAAA,MAAM,GAAG;AACR,eACC,4BAAC,iBAAD,6BACM,KAAKJ,KADX,EAEM,KAAKG,KAFX;AAGC,UAAA,QAAQ,EAAG,KAAKF;AAHjB,WADD;AAOA;;AAjB8C,KAAhD;AAmBA,GApBM,EAoBJ,WApBI,CAAP;AAqBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createHigherOrderComponent from '../../utils/create-higher-order-component';\n\n/**\n * A Higher Order Component used to provide and manage internal component state\n * via props.\n *\n * @deprecated Use `useState` instead.\n *\n * @param {any} initialState Optional initial state of the component.\n *\n * @return {any} A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props.\n */\nexport default function withState( initialState = {} ) {\n\tdeprecated( 'wp.compose.withState', {\n\t\tsince: '5.8',\n\t\talternative: 'wp.element.useState',\n\t} );\n\n\treturn createHigherOrderComponent( ( OriginalComponent ) => {\n\t\treturn class WrappedComponent extends Component {\n\t\t\tconstructor( /** @type {any} */ props ) {\n\t\t\t\tsuper( props );\n\n\t\t\t\tthis.setState = this.setState.bind( this );\n\n\t\t\t\tthis.state = initialState;\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t<OriginalComponent\n\t\t\t\t\t\t{ ...this.props }\n\t\t\t\t\t\t{ ...this.state }\n\t\t\t\t\t\tsetState={ this.setState }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t}, 'withState' );\n}\n"]}
|
|
@@ -41,8 +41,7 @@ function useCopyOnClick(ref, text) {
|
|
|
41
41
|
|
|
42
42
|
/* eslint-enable jsdoc/no-undefined-types */
|
|
43
43
|
(0, _deprecated.default)('wp.compose.useCopyOnClick', {
|
|
44
|
-
since: '
|
|
45
|
-
plugin: 'Gutenberg',
|
|
44
|
+
since: '5.8',
|
|
46
45
|
alternative: 'wp.compose.useCopyToClipboard'
|
|
47
46
|
});
|
|
48
47
|
/** @type {import('react').MutableRefObject<Clipboard | undefined>} */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-copy-on-click/index.js"],"names":["useCopyOnClick","ref","text","timeout","since","
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-copy-on-click/index.js"],"names":["useCopyOnClick","ref","text","timeout","since","alternative","clipboard","hasCopied","setHasCopied","timeoutId","current","Clipboard","on","clearSelection","trigger","focus","clearTimeout","setTimeout","destroy"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAyBC,GAAzB,EAA8BC,IAA9B,EAAqD;AAAA,MAAjBC,OAAiB,uEAAP,IAAO;;AACnE;A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CA,SAAOD,SAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport Clipboard from 'clipboard';\n\n/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useState } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/* eslint-disable jsdoc/no-undefined-types */\n/**\n * Copies the text to the clipboard when the element is clicked.\n *\n * @deprecated\n *\n * @param {import('react').RefObject<string | Element | NodeListOf<Element>>} ref Reference with the element.\n * @param {string|Function} text The text to copy.\n * @param {number} [timeout] Optional timeout to reset the returned\n * state. 4 seconds by default.\n *\n * @return {boolean} Whether or not the text has been copied. Resets after the\n * timeout.\n */\nexport default function useCopyOnClick( ref, text, timeout = 4000 ) {\n\t/* eslint-enable jsdoc/no-undefined-types */\n\tdeprecated( 'wp.compose.useCopyOnClick', {\n\t\tsince: '5.8',\n\t\talternative: 'wp.compose.useCopyToClipboard',\n\t} );\n\n\t/** @type {import('react').MutableRefObject<Clipboard | undefined>} */\n\tconst clipboard = useRef();\n\tconst [ hasCopied, setHasCopied ] = useState( false );\n\n\tuseEffect( () => {\n\t\t/** @type {number | undefined} */\n\t\tlet timeoutId;\n\n\t\tif ( ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Clipboard listens to click events.\n\t\tclipboard.current = new Clipboard( ref.current, {\n\t\t\ttext: () => ( typeof text === 'function' ? text() : text ),\n\t\t} );\n\n\t\tclipboard.current.on( 'success', ( { clearSelection, trigger } ) => {\n\t\t\t// Clearing selection will move focus back to the triggering button,\n\t\t\t// ensuring that it is not reset to the body, and further that it is\n\t\t\t// kept within the rendered node.\n\t\t\tclearSelection();\n\n\t\t\t// Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680\n\t\t\tif ( trigger ) {\n\t\t\t\t/** @type {HTMLElement} */ ( trigger ).focus();\n\t\t\t}\n\n\t\t\tif ( timeout ) {\n\t\t\t\tsetHasCopied( true );\n\t\t\t\tclearTimeout( timeoutId );\n\t\t\t\ttimeoutId = setTimeout( () => setHasCopied( false ), timeout );\n\t\t\t}\n\t\t} );\n\n\t\treturn () => {\n\t\t\tif ( clipboard.current ) {\n\t\t\t\tclipboard.current.destroy();\n\t\t\t}\n\t\t\tclearTimeout( timeoutId );\n\t\t};\n\t}, [ text, timeout, setHasCopied ] );\n\n\treturn hasCopied;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-ref-effect/index.ts"],"names":["useRefEffect","callback","dependencies","cleanup","node","current"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-ref-effect/index.ts"],"names":["useRefEffect","callback","dependencies","cleanup","node","current"],"mappings":";;;;;;;AAQA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAT,CACdC,QADc,EAEdC,YAFc,EAGmB;AACjC,QAAMC,OAAO,GAAG,sBAAhB;AACA,SAAO,0BAAeC,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,GANM,EAMJH,YANI,CAAP;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"]}
|
|
@@ -15,8 +15,8 @@ var _lodash = require("lodash");
|
|
|
15
15
|
* Given a function mapping a component to an enhanced component and modifier
|
|
16
16
|
* name, returns the enhanced component augmented with a generated displayName.
|
|
17
17
|
*
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
18
|
+
* @param mapComponent Function mapping component to enhanced component.
|
|
19
|
+
* @param modifierName Seed name from which to generated display name.
|
|
20
20
|
*
|
|
21
21
|
* @return Component class with generated display name assigned.
|
|
22
22
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/utils/create-higher-order-component/index.ts"],"names":["createHigherOrderComponent","mapComponent","modifierName","Inner","Outer","displayName","name"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/utils/create-higher-order-component/index.ts"],"names":["createHigherOrderComponent","mapComponent","modifierName","Inner","Outer","displayName","name"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAqBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,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,GAAG,wBACvB,uBAAWH,YAAX,CADuB,CAErB,IAAIG,WAAa,GAFpB;AAGA,WAAOD,KAAP;AACA,GATD;AAUA;;eAEcJ,0B","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"]}
|
|
@@ -4,7 +4,6 @@ import { createElement } from "@wordpress/element";
|
|
|
4
4
|
* Internal dependencies
|
|
5
5
|
*/
|
|
6
6
|
import createHigherOrderComponent from '../../utils/create-higher-order-component';
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Higher-order component creator, creating a new component which renders if
|
|
10
9
|
* the given condition is satisfied or with the given optional prop name.
|
|
@@ -22,6 +21,7 @@ import createHigherOrderComponent from '../../utils/create-higher-order-componen
|
|
|
22
21
|
*
|
|
23
22
|
* @return Higher-order component.
|
|
24
23
|
*/
|
|
24
|
+
|
|
25
25
|
const ifCondition = predicate => createHigherOrderComponent(WrappedComponent => props => {
|
|
26
26
|
if (!predicate(props)) {
|
|
27
27
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/if-condition/index.tsx"],"names":["createHigherOrderComponent","ifCondition","predicate","WrappedComponent","props"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,0BAAP,MAAuC,2CAAvC
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/if-condition/index.tsx"],"names":["createHigherOrderComponent","ifCondition","predicate","WrappedComponent","props"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,0BAAP,MAAuC,2CAAvC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,WAAW,GAChBC,SADmB,IAGnBF,0BAA0B,CACvBG,gBAAF,IAA0BC,KAAF,IAAa;AACpC,MAAK,CAAEF,SAAS,CAAEE,KAAF,CAAhB,EAAsC;AACrC,WAAO,IAAP;AACA;;AAED,SAAO,cAAC,gBAAD,EAAuBA,KAAvB,CAAP;AACA,CAPwB,EAQzB,aARyB,CAH3B;;AAcA,eAAeH,WAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport createHigherOrderComponent from '../../utils/create-higher-order-component';\n\n/**\n * Higher-order component creator, creating a new component which renders if\n * the given condition is satisfied or with the given optional prop name.\n *\n * @example\n * ```ts\n * type Props = { foo: string };\n * const Component = ( props: Props ) => <div>{ props.foo }</div>;\n * const ConditionalComponent = ifCondition( ( props: Props ) => props.foo.length !== 0 )( Component );\n * <ConditionalComponent foo=\"\" />; // => null\n * <ConditionalComponent foo=\"bar\" />; // => <div>bar</div>;\n * ```\n *\n * @param predicate Function to test condition.\n *\n * @return Higher-order component.\n */\nconst ifCondition = < TProps extends Record< string, any > >(\n\tpredicate: ( props: TProps ) => boolean\n) =>\n\tcreateHigherOrderComponent< {} >(\n\t\t( WrappedComponent ) => ( props ) => {\n\t\t\tif ( ! predicate( props as TProps ) ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn <WrappedComponent { ...props } />;\n\t\t},\n\t\t'ifCondition'\n\t);\n\nexport default ifCondition;\n"]}
|
|
@@ -10,10 +10,13 @@ import { Component } from '@wordpress/element';
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import createHigherOrderComponent from '../../utils/create-higher-order-component';
|
|
13
|
+
/**
|
|
14
|
+
* External dependencies
|
|
15
|
+
*/
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* Given a component returns the enhanced component augmented with a component
|
|
16
|
-
* only
|
|
19
|
+
* only re-rendering when its props/state change
|
|
17
20
|
*/
|
|
18
21
|
const pure = createHigherOrderComponent(Wrapped => {
|
|
19
22
|
if (Wrapped.prototype instanceof Component) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/pure/index.tsx"],"names":["isShallowEqual","Component","createHigherOrderComponent","pure","Wrapped","prototype","shouldComponentUpdate","nextProps","nextState","props","state","render"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,cAAP,MAA2B,6BAA3B;AACA,SAASC,SAAT,QAA0B,oBAA1B;AAEA;AACA;AACA;;AACA,OAAOC,0BAAP,MAAuC,2CAAvC;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/pure/index.tsx"],"names":["isShallowEqual","Component","createHigherOrderComponent","pure","Wrapped","prototype","shouldComponentUpdate","nextProps","nextState","props","state","render"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,cAAP,MAA2B,6BAA3B;AACA,SAASC,SAAT,QAA0B,oBAA1B;AAEA;AACA;AACA;;AACA,OAAOC,0BAAP,MAAuC,2CAAvC;AAEA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA,MAAMC,IAAI,GAAGD,0BAA0B,CAErCE,OADD,IAEK;AACJ,MAAKA,OAAO,CAACC,SAAR,YAA6BJ,SAAlC,EAA8C;AAC7C,WAAO,cAAgBG,OAAhB,CAAsD;AAC5DE,MAAAA,qBAAqB,CAAEC,SAAF,EAAqBC,SAArB,EAAsC;AAC1D,eACC,CAAER,cAAc,CAAEO,SAAF,EAAa,KAAKE,KAAlB,CAAhB,IACA,CAAET,cAAc,CAAEQ,SAAF,EAAa,KAAKE,KAAlB,CAFjB;AAIA;;AAN2D,KAA7D;AAQA;;AAED,SAAO,cAAcT,SAAd,CAAkC;AACxCK,IAAAA,qBAAqB,CAAEC,SAAF,EAAsB;AAC1C,aAAO,CAAEP,cAAc,CAAEO,SAAF,EAAa,KAAKE,KAAlB,CAAvB;AACA;;AAEDE,IAAAA,MAAM,GAAG;AACR,aAAO,cAAC,OAAD,EAAc,KAAKF,KAAnB,CAAP;AACA;;AAPuC,GAAzC;AASA,CAxBqC,EAyBtC,MAzBsC,CAAvC;AA4BA,eAAeN,IAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { Component } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport createHigherOrderComponent from '../../utils/create-higher-order-component';\n\n/**\n * External dependencies\n */\nimport type { ComponentType, ComponentClass } from 'react';\n\n/**\n * Given a component returns the enhanced component augmented with a component\n * only re-rendering when its props/state change\n */\nconst pure = createHigherOrderComponent(\n\t< TProps extends Record< string, any > >(\n\t\tWrapped: ComponentType< TProps >\n\t) => {\n\t\tif ( Wrapped.prototype instanceof Component ) {\n\t\t\treturn class extends ( Wrapped as ComponentClass< TProps > ) {\n\t\t\t\tshouldComponentUpdate( nextProps: TProps, nextState: any ) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t! isShallowEqual( nextProps, this.props ) ||\n\t\t\t\t\t\t! isShallowEqual( nextState, this.state )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\treturn class extends Component< TProps > {\n\t\t\tshouldComponentUpdate( nextProps: TProps ) {\n\t\t\t\treturn ! isShallowEqual( nextProps, this.props );\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn <Wrapped { ...this.props } />;\n\t\t\t}\n\t\t};\n\t},\n\t'pure'\n);\n\nexport default pure;\n"]}
|
|
@@ -48,7 +48,8 @@ export default function withGlobalEvents(eventTypesToHandlers) {
|
|
|
48
48
|
deprecated('wp.compose.withGlobalEvents', {
|
|
49
49
|
since: '5.7',
|
|
50
50
|
alternative: 'useEffect'
|
|
51
|
-
});
|
|
51
|
+
}); // @ts-ignore We don't need to fix the type-related issues because this is deprecated.
|
|
52
|
+
|
|
52
53
|
return createHigherOrderComponent(WrappedComponent => {
|
|
53
54
|
class Wrapper extends Component {
|
|
54
55
|
constructor(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-global-events/index.js"],"names":["forEach","Component","forwardRef","deprecated","createHigherOrderComponent","Listener","listener","withGlobalEvents","eventTypesToHandlers","since","alternative","WrappedComponent","Wrapper","constructor","props","handleEvent","bind","handleRef","componentDidMount","_","eventType","add","componentWillUnmount","remove","event","handler","type","wrappedRef","el","forwardedRef","render","ownProps","ref"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,QAAxB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,EAAoBC,UAApB,QAAsC,oBAAtC;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,0BAAP,MAAuC,2CAAvC;AACA,OAAOC,QAAP,MAAqB,YAArB;AAEA;AACA;AACA;;AACA,MAAMC,QAAQ,GAAG,IAAID,QAAJ,EAAjB;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASE,gBAAT,CAA2BC,oBAA3B,EAAkD;AAChEL,EAAAA,UAAU,CAAE,6BAAF,EAAiC;AAC1CM,IAAAA,KAAK,EAAE,KADmC;AAE1CC,IAAAA,WAAW,EAAE;AAF6B,GAAjC,CAAV
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-global-events/index.js"],"names":["forEach","Component","forwardRef","deprecated","createHigherOrderComponent","Listener","listener","withGlobalEvents","eventTypesToHandlers","since","alternative","WrappedComponent","Wrapper","constructor","props","handleEvent","bind","handleRef","componentDidMount","_","eventType","add","componentWillUnmount","remove","event","handler","type","wrappedRef","el","forwardedRef","render","ownProps","ref"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,QAAxB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,EAAoBC,UAApB,QAAsC,oBAAtC;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,0BAAP,MAAuC,2CAAvC;AACA,OAAOC,QAAP,MAAqB,YAArB;AAEA;AACA;AACA;;AACA,MAAMC,QAAQ,GAAG,IAAID,QAAJ,EAAjB;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASE,gBAAT,CAA2BC,oBAA3B,EAAkD;AAChEL,EAAAA,UAAU,CAAE,6BAAF,EAAiC;AAC1CM,IAAAA,KAAK,EAAE,KADmC;AAE1CC,IAAAA,WAAW,EAAE;AAF6B,GAAjC,CAAV,CADgE,CAMhE;;AACA,SAAON,0BAA0B,CAAIO,gBAAF,IAA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AL,CAAWiB,QADjB;AAEC,UAAA,GAAG,EAAG,KAAKd;AAFZ,WADD;AAMA;;AAhD8B;;AAmDhC,WAAOf,UAAU,CAAE,CAAEY,KAAF,EAASkB,GAAT,KAAkB;AACpC,aAAO,cAAC,OAAD;AAAS,QAAA,QAAQ,EAAGlB,KAApB;AAA4B,QAAA,YAAY,EAAGkB;AAA3C,QAAP;AACA,KAFgB,CAAjB;AAGA,GAvDgC,EAuD9B,kBAvD8B,CAAjC;AAwDA","sourcesContent":["/**\n * External dependencies\n */\nimport { forEach } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { Component, forwardRef } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createHigherOrderComponent from '../../utils/create-higher-order-component';\nimport Listener from './listener';\n\n/**\n * Listener instance responsible for managing document event handling.\n */\nconst listener = new Listener();\n\n/* eslint-disable jsdoc/no-undefined-types */\n/**\n * Higher-order component creator which, given an object of DOM event types and\n * values corresponding to a callback function name on the component, will\n * create or update a window event handler to invoke the callback when an event\n * occurs. On behalf of the consuming developer, the higher-order component\n * manages unbinding when the component unmounts, and binding at most a single\n * event handler for the entire application.\n *\n * @deprecated\n *\n * @param {Record<keyof GlobalEventHandlersEventMap, string>} eventTypesToHandlers Object with keys of DOM\n * event type, the value a\n * name of the function on\n * the original component's\n * instance which handles\n * the event.\n *\n * @return {any} Higher-order component.\n */\nexport default function withGlobalEvents( eventTypesToHandlers ) {\n\tdeprecated( 'wp.compose.withGlobalEvents', {\n\t\tsince: '5.7',\n\t\talternative: 'useEffect',\n\t} );\n\n\t// @ts-ignore We don't need to fix the type-related issues because this is deprecated.\n\treturn createHigherOrderComponent( ( WrappedComponent ) => {\n\t\tclass Wrapper extends Component {\n\t\t\tconstructor( /** @type {any} */ props ) {\n\t\t\t\tsuper( props );\n\n\t\t\t\tthis.handleEvent = this.handleEvent.bind( this );\n\t\t\t\tthis.handleRef = this.handleRef.bind( this );\n\t\t\t}\n\n\t\t\tcomponentDidMount() {\n\t\t\t\tforEach( eventTypesToHandlers, ( _, eventType ) => {\n\t\t\t\t\tlistener.add( eventType, this );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tcomponentWillUnmount() {\n\t\t\t\tforEach( eventTypesToHandlers, ( _, eventType ) => {\n\t\t\t\t\tlistener.remove( eventType, this );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\thandleEvent( /** @type {any} */ event ) {\n\t\t\t\tconst handler =\n\t\t\t\t\teventTypesToHandlers[\n\t\t\t\t\t\t/** @type {keyof GlobalEventHandlersEventMap} */ ( event.type )\n\t\t\t\t\t\t/* eslint-enable jsdoc/no-undefined-types */\n\t\t\t\t\t];\n\t\t\t\tif ( typeof this.wrappedRef[ handler ] === 'function' ) {\n\t\t\t\t\tthis.wrappedRef[ handler ]( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\thandleRef( /** @type {any} */ el ) {\n\t\t\t\tthis.wrappedRef = el;\n\t\t\t\t// Any component using `withGlobalEvents` that is not setting a `ref`\n\t\t\t\t// will cause `this.props.forwardedRef` to be `null`, so we need this\n\t\t\t\t// check.\n\t\t\t\tif ( this.props.forwardedRef ) {\n\t\t\t\t\tthis.props.forwardedRef( el );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t{ ...this.props.ownProps }\n\t\t\t\t\t\tref={ this.handleRef }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn forwardRef( ( props, ref ) => {\n\t\t\treturn <Wrapper ownProps={ props } forwardedRef={ ref } />;\n\t\t} );\n\t}, 'withGlobalEvents' );\n}\n"]}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import { createElement } from "@wordpress/element";
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* External dependencies
|
|
6
|
-
*/
|
|
7
|
-
// eslint-disable-next-line no-restricted-imports
|
|
8
|
-
|
|
9
4
|
/**
|
|
10
5
|
* Internal dependencies
|
|
11
6
|
*/
|
|
@@ -18,7 +13,8 @@ import useInstanceId from '../../hooks/use-instance-id';
|
|
|
18
13
|
|
|
19
14
|
const withInstanceId = createHigherOrderComponent(WrappedComponent => {
|
|
20
15
|
return props => {
|
|
21
|
-
const instanceId = useInstanceId(WrappedComponent);
|
|
16
|
+
const instanceId = useInstanceId(WrappedComponent); // @ts-ignore
|
|
17
|
+
|
|
22
18
|
return createElement(WrappedComponent, _extends({}, props, {
|
|
23
19
|
instanceId: instanceId
|
|
24
20
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-instance-id/index.tsx"],"names":["createHigherOrderComponent","useInstanceId","withInstanceId","WrappedComponent","props","instanceId"],"mappings":";;;AAAA;AACA;AACA;AACA
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-instance-id/index.tsx"],"names":["createHigherOrderComponent","useInstanceId","withInstanceId","WrappedComponent","props","instanceId"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,0BAAP,MAAuC,2CAAvC;AACA,OAAOC,aAAP,MAA0B,6BAA1B;AAEA;AACA;AACA;AACA;;AACA,MAAMC,cAAc,GAAGF,0BAA0B,CAE1CG,gBAAF,IAAwB;AAC5B,SAASC,KAAF,IAAa;AACnB,UAAMC,UAAU,GAAGJ,aAAa,CAAEE,gBAAF,CAAhC,CADmB,CAEnB;;AACA,WAAO,cAAC,gBAAD,eAAuBC,KAAvB;AAA+B,MAAA,UAAU,EAAGC;AAA5C,OAAP;AACA,GAJD;AAKA,CARgD,EAQ9C,gBAR8C,CAAjD;AAUA,eAAeH,cAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport createHigherOrderComponent from '../../utils/create-higher-order-component';\nimport useInstanceId from '../../hooks/use-instance-id';\n\n/**\n * A Higher Order Component used to be provide a unique instance ID by\n * component.\n */\nconst withInstanceId = createHigherOrderComponent< {\n\tinstanceId: string | number;\n} >( ( WrappedComponent ) => {\n\treturn ( props ) => {\n\t\tconst instanceId = useInstanceId( WrappedComponent );\n\t\t// @ts-ignore\n\t\treturn <WrappedComponent { ...props } instanceId={ instanceId } />;\n\t};\n}, 'withInstanceId' );\n\nexport default withInstanceId;\n"]}
|
|
@@ -3,7 +3,7 @@ import { createElement } from "@wordpress/element";
|
|
|
3
3
|
/**
|
|
4
4
|
* External dependencies
|
|
5
5
|
*/
|
|
6
|
-
import { without } from 'lodash';
|
|
6
|
+
import { without } from 'lodash';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* WordPress dependencies
|
|
@@ -14,6 +14,14 @@ import { Component } from '@wordpress/element';
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import createHigherOrderComponent from '../../utils/create-higher-order-component';
|
|
17
|
+
/**
|
|
18
|
+
* We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`
|
|
19
|
+
* types here because those functions include functionality that is not handled
|
|
20
|
+
* by this component, like the ability to pass extra arguments.
|
|
21
|
+
*
|
|
22
|
+
* In the case of this component, we only handle the simplest case where
|
|
23
|
+
* `setTimeout` only accepts a function (not a string) and an optional delay.
|
|
24
|
+
*/
|
|
17
25
|
|
|
18
26
|
/**
|
|
19
27
|
* A higher-order component used to provide and manage delayed function calls
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-safe-timeout/index.tsx"],"names":["without","Component","createHigherOrderComponent","withSafeTimeout","OriginalComponent","WrappedComponent","constructor","props","timeouts","setTimeout","bind","clearTimeout","componentWillUnmount","forEach","fn","delay","id","push","render"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,QAAxB
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-safe-timeout/index.tsx"],"names":["without","Component","createHigherOrderComponent","withSafeTimeout","OriginalComponent","WrappedComponent","constructor","props","timeouts","setTimeout","bind","clearTimeout","componentWillUnmount","forEach","fn","delay","id","push","render"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,QAAxB;;AAGA;AACA;AACA;AACA,SAASC,SAAT,QAA0B,oBAA1B;AAEA;AACA;AACA;;AACA,OAAOC,0BAAP,MAAuC,2CAAvC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA,MAAMC,eAAe,GAAGD,0BAA0B,CAEhDE,iBADD,IAEK;AACJ,SAAO,MAAMC,gBAAN,SAA+BJ,SAA/B,CAEL;AAGDK,IAAAA,WAAW,CAAEC,KAAF,EAA8C;AACxD,YAAOA,KAAP;AACA,WAAKC,QAAL,GAAgB,EAAhB;AACA,WAAKC,UAAL,GAAkB,KAAKA,UAAL,CAAgBC,IAAhB,CAAsB,IAAtB,CAAlB;AACA,WAAKC,YAAL,GAAoB,KAAKA,YAAL,CAAkBD,IAAlB,CAAwB,IAAxB,CAApB;AACA;;AAEDE,IAAAA,oBAAoB,GAAG;AACtB,WAAKJ,QAAL,CAAcK,OAAd,CAAuBF,YAAvB;AACA;;AAEDF,IAAAA,UAAU,CAAEK,EAAF,EAAkCC,KAAlC,EAAkD;AAC3D,YAAMC,EAAE,GAAGP,UAAU,CAAE,MAAM;AAC5BK,QAAAA,EAAE;AACF,aAAKH,YAAL,CAAmBK,EAAnB;AACA,OAHoB,EAGlBD,KAHkB,CAArB;AAIA,WAAKP,QAAL,CAAcS,IAAd,CAAoBD,EAApB;AACA,aAAOA,EAAP;AACA;;AAEDL,IAAAA,YAAY,CAAEK,EAAF,EAAe;AAC1BL,MAAAA,YAAY,CAAEK,EAAF,CAAZ;AACA,WAAKR,QAAL,GAAgBR,OAAO,CAAE,KAAKQ,QAAP,EAAiBQ,EAAjB,CAAvB;AACA;;AAEDE,IAAAA,MAAM,GAAG;AACR,YAAMX,KAAK,GAAG,EACb,GAAG,KAAKA,KADK;AAEbE,QAAAA,UAAU,EAAE,KAAKA,UAFJ;AAGbE,QAAAA,YAAY,EAAE,KAAKA;AAHN,OAAd;AAMA,aAAO,cAAC,iBAAD,EAAwBJ,KAAxB,CAAP;AACA;;AApCA,GAFF;AAwCA,CA5CgD,EA6CjD,iBA7CiD,CAAlD;AAgDA,eAAeJ,eAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { without } from 'lodash';\nimport type { ComponentType } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport createHigherOrderComponent from '../../utils/create-higher-order-component';\n\n/**\n * We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`\n * types here because those functions include functionality that is not handled\n * by this component, like the ability to pass extra arguments.\n *\n * In the case of this component, we only handle the simplest case where\n * `setTimeout` only accepts a function (not a string) and an optional delay.\n */\ntype TimeoutProps = {\n\tsetTimeout: ( fn: () => void, delay: number ) => number;\n\tclearTimeout: ( id: number ) => void;\n};\n\n/**\n * A higher-order component used to provide and manage delayed function calls\n * that ought to be bound to a component's lifecycle.\n */\nconst withSafeTimeout = createHigherOrderComponent< TimeoutProps >(\n\t< TProps extends TimeoutProps >(\n\t\tOriginalComponent: ComponentType< TProps >\n\t) => {\n\t\treturn class WrappedComponent extends Component<\n\t\t\tOmit< TProps, keyof TimeoutProps >\n\t\t> {\n\t\t\ttimeouts: number[];\n\n\t\t\tconstructor( props: Omit< TProps, keyof TimeoutProps > ) {\n\t\t\t\tsuper( props );\n\t\t\t\tthis.timeouts = [];\n\t\t\t\tthis.setTimeout = this.setTimeout.bind( this );\n\t\t\t\tthis.clearTimeout = this.clearTimeout.bind( this );\n\t\t\t}\n\n\t\t\tcomponentWillUnmount() {\n\t\t\t\tthis.timeouts.forEach( clearTimeout );\n\t\t\t}\n\n\t\t\tsetTimeout( fn: ( ...args: any[] ) => void, delay: number ) {\n\t\t\t\tconst id = setTimeout( () => {\n\t\t\t\t\tfn();\n\t\t\t\t\tthis.clearTimeout( id );\n\t\t\t\t}, delay );\n\t\t\t\tthis.timeouts.push( id );\n\t\t\t\treturn id;\n\t\t\t}\n\n\t\t\tclearTimeout( id: number ) {\n\t\t\t\tclearTimeout( id );\n\t\t\t\tthis.timeouts = without( this.timeouts, id );\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\tconst props = {\n\t\t\t\t\t...this.props,\n\t\t\t\t\tsetTimeout: this.setTimeout,\n\t\t\t\t\tclearTimeout: this.clearTimeout,\n\t\t\t\t} as TProps;\n\n\t\t\t\treturn <OriginalComponent { ...props } />;\n\t\t\t}\n\t\t};\n\t},\n\t'withSafeTimeout'\n);\n\nexport default withSafeTimeout;\n"]}
|
|
@@ -25,6 +25,7 @@ import createHigherOrderComponent from '../../utils/create-higher-order-componen
|
|
|
25
25
|
export default function withState() {
|
|
26
26
|
let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
27
27
|
deprecated('wp.compose.withState', {
|
|
28
|
+
since: '5.8',
|
|
28
29
|
alternative: 'wp.element.useState'
|
|
29
30
|
});
|
|
30
31
|
return createHigherOrderComponent(OriginalComponent => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-state/index.js"],"names":["Component","deprecated","createHigherOrderComponent","withState","initialState","alternative","OriginalComponent","WrappedComponent","constructor","props","setState","bind","state","render"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,oBAA1B;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,0BAAP,MAAuC,2CAAvC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,SAAT,GAAwC;AAAA,MAApBC,YAAoB,uEAAL,EAAK;AACtDH,EAAAA,UAAU,CAAE,sBAAF,EAA0B;AACnCI,IAAAA,WAAW,EAAE;
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/higher-order/with-state/index.js"],"names":["Component","deprecated","createHigherOrderComponent","withState","initialState","since","alternative","OriginalComponent","WrappedComponent","constructor","props","setState","bind","state","render"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,oBAA1B;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,0BAAP,MAAuC,2CAAvC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,SAAT,GAAwC;AAAA,MAApBC,YAAoB,uEAAL,EAAK;AACtDH,EAAAA,UAAU,CAAE,sBAAF,EAA0B;AACnCI,IAAAA,KAAK,EAAE,KAD4B;AAEnCC,IAAAA,WAAW,EAAE;AAFsB,GAA1B,CAAV;AAKA,SAAOJ,0BAA0B,CAAIK,iBAAF,IAAyB;AAC3D,WAAO,MAAMC,gBAAN,SAA+BR,SAA/B,CAAyC;AAC/CS,MAAAA,WAAW;AAAE;AAAmBC,MAAAA,KAArB,EAA6B;AACvC,cAAOA,KAAP;AAEA,aAAKC,QAAL,GAAgB,KAAKA,QAAL,CAAcC,IAAd,CAAoB,IAApB,CAAhB;AAEA,aAAKC,KAAL,GAAaT,YAAb;AACA;;AAEDU,MAAAA,MAAM,GAAG;AACR,eACC,cAAC,iBAAD,eACM,KAAKJ,KADX,EAEM,KAAKG,KAFX;AAGC,UAAA,QAAQ,EAAG,KAAKF;AAHjB,WADD;AAOA;;AAjB8C,KAAhD;AAmBA,GApBgC,EAoB9B,WApB8B,CAAjC;AAqBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createHigherOrderComponent from '../../utils/create-higher-order-component';\n\n/**\n * A Higher Order Component used to provide and manage internal component state\n * via props.\n *\n * @deprecated Use `useState` instead.\n *\n * @param {any} initialState Optional initial state of the component.\n *\n * @return {any} A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props.\n */\nexport default function withState( initialState = {} ) {\n\tdeprecated( 'wp.compose.withState', {\n\t\tsince: '5.8',\n\t\talternative: 'wp.element.useState',\n\t} );\n\n\treturn createHigherOrderComponent( ( OriginalComponent ) => {\n\t\treturn class WrappedComponent extends Component {\n\t\t\tconstructor( /** @type {any} */ props ) {\n\t\t\t\tsuper( props );\n\n\t\t\t\tthis.setState = this.setState.bind( this );\n\n\t\t\t\tthis.state = initialState;\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t<OriginalComponent\n\t\t\t\t\t\t{ ...this.props }\n\t\t\t\t\t\t{ ...this.state }\n\t\t\t\t\t\tsetState={ this.setState }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t}, 'withState' );\n}\n"]}
|
|
@@ -29,8 +29,7 @@ export default function useCopyOnClick(ref, text) {
|
|
|
29
29
|
|
|
30
30
|
/* eslint-enable jsdoc/no-undefined-types */
|
|
31
31
|
deprecated('wp.compose.useCopyOnClick', {
|
|
32
|
-
since: '
|
|
33
|
-
plugin: 'Gutenberg',
|
|
32
|
+
since: '5.8',
|
|
34
33
|
alternative: 'wp.compose.useCopyToClipboard'
|
|
35
34
|
});
|
|
36
35
|
/** @type {import('react').MutableRefObject<Clipboard | undefined>} */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/hooks/use-copy-on-click/index.js"],"names":["Clipboard","useRef","useEffect","useState","deprecated","useCopyOnClick","ref","text","timeout","since","
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-copy-on-click/index.js"],"names":["Clipboard","useRef","useEffect","useState","deprecated","useCopyOnClick","ref","text","timeout","since","alternative","clipboard","hasCopied","setHasCopied","timeoutId","current","on","clearSelection","trigger","focus","clearTimeout","setTimeout","destroy"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,WAAtB;AAEA;AACA;AACA;;AACA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CAAE,MAAMR,YAAY,CAAE,KAAF,CAApB,EAA+BL,OAA/B,CAAtB;AACA;AACD,KAhBD;AAkBA,WAAO,MAAM;AACZ,UAAKG,SAAS,CAACI,OAAf,EAAyB;AACxBJ,QAAAA,SAAS,CAACI,OAAV,CAAkBO,OAAlB;AACA;;AACDF,MAAAA,YAAY,CAAEN,SAAF,CAAZ;AACA,KALD;AAMA,GArCQ,EAqCN,CAAEP,IAAF,EAAQC,OAAR,EAAiBK,YAAjB,CArCM,CAAT;AAuCA,SAAOD,SAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport Clipboard from 'clipboard';\n\n/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useState } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/* eslint-disable jsdoc/no-undefined-types */\n/**\n * Copies the text to the clipboard when the element is clicked.\n *\n * @deprecated\n *\n * @param {import('react').RefObject<string | Element | NodeListOf<Element>>} ref Reference with the element.\n * @param {string|Function} text The text to copy.\n * @param {number} [timeout] Optional timeout to reset the returned\n * state. 4 seconds by default.\n *\n * @return {boolean} Whether or not the text has been copied. Resets after the\n * timeout.\n */\nexport default function useCopyOnClick( ref, text, timeout = 4000 ) {\n\t/* eslint-enable jsdoc/no-undefined-types */\n\tdeprecated( 'wp.compose.useCopyOnClick', {\n\t\tsince: '5.8',\n\t\talternative: 'wp.compose.useCopyToClipboard',\n\t} );\n\n\t/** @type {import('react').MutableRefObject<Clipboard | undefined>} */\n\tconst clipboard = useRef();\n\tconst [ hasCopied, setHasCopied ] = useState( false );\n\n\tuseEffect( () => {\n\t\t/** @type {number | undefined} */\n\t\tlet timeoutId;\n\n\t\tif ( ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Clipboard listens to click events.\n\t\tclipboard.current = new Clipboard( ref.current, {\n\t\t\ttext: () => ( typeof text === 'function' ? text() : text ),\n\t\t} );\n\n\t\tclipboard.current.on( 'success', ( { clearSelection, trigger } ) => {\n\t\t\t// Clearing selection will move focus back to the triggering button,\n\t\t\t// ensuring that it is not reset to the body, and further that it is\n\t\t\t// kept within the rendered node.\n\t\t\tclearSelection();\n\n\t\t\t// Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680\n\t\t\tif ( trigger ) {\n\t\t\t\t/** @type {HTMLElement} */ ( trigger ).focus();\n\t\t\t}\n\n\t\t\tif ( timeout ) {\n\t\t\t\tsetHasCopied( true );\n\t\t\t\tclearTimeout( timeoutId );\n\t\t\t\ttimeoutId = setTimeout( () => setHasCopied( false ), timeout );\n\t\t\t}\n\t\t} );\n\n\t\treturn () => {\n\t\t\tif ( clipboard.current ) {\n\t\t\t\tclipboard.current.destroy();\n\t\t\t}\n\t\t\tclearTimeout( timeoutId );\n\t\t};\n\t}, [ text, timeout, setHasCopied ] );\n\n\treturn hasCopied;\n}\n"]}
|