@wordpress/compose 5.0.6 → 5.1.1
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 +11 -17
- 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-disabled/index.js +114 -0
- package/build/hooks/use-disabled/index.js.map +1 -0
- package/build/hooks/use-ref-effect/index.js +0 -1
- package/build/hooks/use-ref-effect/index.js.map +1 -1
- package/build/index.js +8 -0
- package/build/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-disabled/index.js +104 -0
- package/build-module/hooks/use-disabled/index.js.map +1 -0
- 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/index.js +1 -0
- package/build-module/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-disabled/index.d.ts +23 -0
- package/build-types/hooks/use-disabled/index.d.ts.map +1 -0
- package/build-types/hooks/use-ref-effect/index.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -0
- 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/index.js +113 -0
- package/src/hooks/use-disabled/test/index.js +92 -0
- package/src/hooks/use-ref-effect/index.ts +0 -1
- package/src/index.js +1 -0
- 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/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,IAAwB;AAC1D,UAAMC,OAAN,SAAsBX,SAAtB,CAAgC;AAC/BY,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,KAAKA,SAAL,CAAeD,IAAf,CAAqB,IAArB,CAAjB;AACA;;AAEDE,MAAAA,iBAAiB,GAAG;AACnBlB,QAAAA,OAAO,CAAEQ,oBAAF,EAAwB,CAAEW,CAAF,EAAKC,SAAL,KAAoB;AAClDd,UAAAA,QAAQ,CAACe,GAAT,CAAcD,SAAd,EAAyB,IAAzB;AACA,SAFM,CAAP;AAGA;;AAEDE,MAAAA,oBAAoB,GAAG;AACtBtB,QAAAA,OAAO,CAAEQ,oBAAF,EAAwB,CAAEW,CAAF,EAAKC,SAAL,KAAoB;AAClDd,UAAAA,QAAQ,CAACiB,MAAT,CAAiBH,SAAjB,EAA4B,IAA5B;AACA,SAFM,CAAP;AAGA;;AAEDL,MAAAA,WAAW;AAAE;AAAmBS,MAAAA,KAArB,EAA6B;AACvC,cAAMC,OAAO,GACZjB,oBAAoB;AACnB;AAAmDgB,QAAAA,KAAK,CAACE;AACzD;AAFmB,SADrB;;AAKA,YAAK,OAAO,KAAKC,UAAL,CAAiBF,OAAjB,CAAP,KAAsC,UAA3C,EAAwD;AACvD,eAAKE,UAAL,CAAiBF,OAAjB,EAA4BD,KAA5B;AACA;AACD;;AAEDP,MAAAA,SAAS;AAAE;AAAmBW,MAAAA,EAArB,EAA0B;AAClC,aAAKD,UAAL,GAAkBC,EAAlB,CADkC,CAElC;AACA;AACA;;AACA,YAAK,KAAKd,KAAL,CAAWe,YAAhB,EAA+B;AAC9B,eAAKf,KAAL,CAAWe,YAAX,CAAyBD,EAAzB;AACA;AACD;;AAEDE,MAAAA,MAAM,GAAG;AACR,eACC,cAAC,gBAAD,eACM,KAAKhB,KAAL,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,SAASC,MAAT,EAAiBC,SAAjB,EAA4BC,QAA5B,QAA4C,oBAA5C;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,cAAT,CAAyBC,GAAzB,EAA8BC,IAA9B,EAAqD;AAAA,MAAjBC,OAAiB,uEAAP,IAAO;;AACnE;AACAJ,EAAAA,UAAU,CAAE,2BAAF,EAA+B;AACxCK,IAAAA,KAAK,EAAE,KADiC;AAExCC,IAAAA,WAAW,EAAE;AAF2B,GAA/B,CAAV;AAKA;;AACA,QAAMC,SAAS,GAAGV,MAAM,EAAxB;AACA,QAAM,CAAEW,SAAF,EAAaC,YAAb,IAA8BV,QAAQ,CAAE,KAAF,CAA5C;AAEAD,EAAAA,SAAS,CAAE,MAAM;AAChB;AACA,QAAIY,SAAJ;;AAEA,QAAK,CAAER,GAAG,CAACS,OAAX,EAAqB;AACpB;AACA,KANe,CAQhB;;;AACAJ,IAAAA,SAAS,CAACI,OAAV,GAAoB,IAAIf,SAAJ,CAAeM,GAAG,CAACS,OAAnB,EAA4B;AAC/CR,MAAAA,IAAI,EAAE,MAAQ,OAAOA,IAAP,KAAgB,UAAhB,GAA6BA,IAAI,EAAjC,GAAsCA;AADL,KAA5B,CAApB;AAIAI,IAAAA,SAAS,CAACI,OAAV,CAAkBC,EAAlB,CAAsB,SAAtB,EAAiC,QAAmC;AAAA,UAAjC;AAAEC,QAAAA,cAAF;AAAkBC,QAAAA;AAAlB,OAAiC;AACnE;AACA;AACA;AACAD,MAAAA,cAAc,GAJqD,CAMnE;;AACA,UAAKC,OAAL,EAAe;AACd;AAA6BA,QAAAA,OAAF,CAAYC,KAAZ;AAC3B;;AAED,UAAKX,OAAL,EAAe;AACdK,QAAAA,YAAY,CAAE,IAAF,CAAZ;AACAO,QAAAA,YAAY,CAAEN,SAAF,CAAZ;AACAA,QAAAA,SAAS,GAAGO,UAAU,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"]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { includes, debounce } from 'lodash';
|
|
5
|
+
/**
|
|
6
|
+
* WordPress dependencies
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { useCallback, useLayoutEffect, useRef } from '@wordpress/element';
|
|
10
|
+
import { focus } from '@wordpress/dom';
|
|
11
|
+
/**
|
|
12
|
+
* Names of control nodes which qualify for disabled behavior.
|
|
13
|
+
*
|
|
14
|
+
* See WHATWG HTML Standard: 4.10.18.5: "Enabling and disabling form controls: the disabled attribute".
|
|
15
|
+
*
|
|
16
|
+
* @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#enabling-and-disabling-form-controls:-the-disabled-attribute
|
|
17
|
+
*
|
|
18
|
+
* @type {string[]}
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const DISABLED_ELIGIBLE_NODE_NAMES = ['BUTTON', 'FIELDSET', 'INPUT', 'OPTGROUP', 'OPTION', 'SELECT', 'TEXTAREA'];
|
|
22
|
+
/**
|
|
23
|
+
* In some circumstances, such as block previews, all focusable DOM elements
|
|
24
|
+
* (input fields, links, buttons, etc.) need to be disabled. This hook adds the
|
|
25
|
+
* behavior to disable nested DOM elements to the returned ref.
|
|
26
|
+
*
|
|
27
|
+
* @return {import('react').RefObject<HTMLElement>} Element Ref.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```js
|
|
31
|
+
* import { __experimentalUseDisabled as useDisabled } from '@wordpress/compose';
|
|
32
|
+
* const DisabledExample = () => {
|
|
33
|
+
* const disabledRef = useDisabled();
|
|
34
|
+
* return (
|
|
35
|
+
* <div ref={ disabledRef }>
|
|
36
|
+
* <a href="#">This link will have tabindex set to -1</a>
|
|
37
|
+
* <input placeholder="This input will have the disabled attribute added to it." type="text" />
|
|
38
|
+
* </div>
|
|
39
|
+
* );
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
export default function useDisabled() {
|
|
45
|
+
/** @type {import('react').RefObject<HTMLElement>} */
|
|
46
|
+
const node = useRef(null);
|
|
47
|
+
|
|
48
|
+
const disable = () => {
|
|
49
|
+
if (!node.current) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
focus.focusable.find(node.current).forEach(focusable => {
|
|
54
|
+
if (includes(DISABLED_ELIGIBLE_NODE_NAMES, focusable.nodeName)) {
|
|
55
|
+
focusable.setAttribute('disabled', '');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (focusable.nodeName === 'A') {
|
|
59
|
+
focusable.setAttribute('tabindex', '-1');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const tabIndex = focusable.getAttribute('tabindex');
|
|
63
|
+
|
|
64
|
+
if (tabIndex !== null && tabIndex !== '-1') {
|
|
65
|
+
focusable.removeAttribute('tabindex');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (focusable.hasAttribute('contenteditable')) {
|
|
69
|
+
focusable.setAttribute('contenteditable', 'false');
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}; // Debounce re-disable since disabling process itself will incur
|
|
73
|
+
// additional mutations which should be ignored.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
const debouncedDisable = useCallback(debounce(disable, undefined, {
|
|
77
|
+
leading: true
|
|
78
|
+
}), []);
|
|
79
|
+
useLayoutEffect(() => {
|
|
80
|
+
disable();
|
|
81
|
+
/** @type {MutationObserver | undefined} */
|
|
82
|
+
|
|
83
|
+
let observer;
|
|
84
|
+
|
|
85
|
+
if (node.current) {
|
|
86
|
+
observer = new window.MutationObserver(debouncedDisable);
|
|
87
|
+
observer.observe(node.current, {
|
|
88
|
+
childList: true,
|
|
89
|
+
attributes: true,
|
|
90
|
+
subtree: true
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return () => {
|
|
95
|
+
if (observer) {
|
|
96
|
+
observer.disconnect();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
debouncedDisable.cancel();
|
|
100
|
+
};
|
|
101
|
+
}, []);
|
|
102
|
+
return node;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/hooks/use-disabled/index.js"],"names":["includes","debounce","useCallback","useLayoutEffect","useRef","focus","DISABLED_ELIGIBLE_NODE_NAMES","useDisabled","node","disable","current","focusable","find","forEach","nodeName","setAttribute","tabIndex","getAttribute","removeAttribute","hasAttribute","debouncedDisable","undefined","leading","observer","window","MutationObserver","observe","childList","attributes","subtree","disconnect","cancel"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,QAAnB,QAAmC,QAAnC;AAEA;AACA;AACA;;AACA,SAASC,WAAT,EAAsBC,eAAtB,EAAuCC,MAAvC,QAAqD,oBAArD;AACA,SAASC,KAAT,QAAsB,gBAAtB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,4BAA4B,GAAG,CACpC,QADoC,EAEpC,UAFoC,EAGpC,OAHoC,EAIpC,UAJoC,EAKpC,QALoC,EAMpC,QANoC,EAOpC,UAPoC,CAArC;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,WAAT,GAAuB;AACrC;AACA,QAAMC,IAAI,GAAGJ,MAAM,CAAE,IAAF,CAAnB;;AAEA,QAAMK,OAAO,GAAG,MAAM;AACrB,QAAK,CAAED,IAAI,CAACE,OAAZ,EAAsB;AACrB;AACA;;AAEDL,IAAAA,KAAK,CAACM,SAAN,CAAgBC,IAAhB,CAAsBJ,IAAI,CAACE,OAA3B,EAAqCG,OAArC,CAAgDF,SAAF,IAAiB;AAC9D,UACCX,QAAQ,CAAEM,4BAAF,EAAgCK,SAAS,CAACG,QAA1C,CADT,EAEE;AACDH,QAAAA,SAAS,CAACI,YAAV,CAAwB,UAAxB,EAAoC,EAApC;AACA;;AAED,UAAKJ,SAAS,CAACG,QAAV,KAAuB,GAA5B,EAAkC;AACjCH,QAAAA,SAAS,CAACI,YAAV,CAAwB,UAAxB,EAAoC,IAApC;AACA;;AAED,YAAMC,QAAQ,GAAGL,SAAS,CAACM,YAAV,CAAwB,UAAxB,CAAjB;;AACA,UAAKD,QAAQ,KAAK,IAAb,IAAqBA,QAAQ,KAAK,IAAvC,EAA8C;AAC7CL,QAAAA,SAAS,CAACO,eAAV,CAA2B,UAA3B;AACA;;AAED,UAAKP,SAAS,CAACQ,YAAV,CAAwB,iBAAxB,CAAL,EAAmD;AAClDR,QAAAA,SAAS,CAACI,YAAV,CAAwB,iBAAxB,EAA2C,OAA3C;AACA;AACD,KAnBD;AAoBA,GAzBD,CAJqC,CA+BrC;AACA;;;AACA,QAAMK,gBAAgB,GAAGlB,WAAW,CACnCD,QAAQ,CAAEQ,OAAF,EAAWY,SAAX,EAAsB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GAAtB,CAD2B,EAEnC,EAFmC,CAApC;AAKAnB,EAAAA,eAAe,CAAE,MAAM;AACtBM,IAAAA,OAAO;AAEP;;AACA,QAAIc,QAAJ;;AACA,QAAKf,IAAI,CAACE,OAAV,EAAoB;AACnBa,MAAAA,QAAQ,GAAG,IAAIC,MAAM,CAACC,gBAAX,CAA6BL,gBAA7B,CAAX;AACAG,MAAAA,QAAQ,CAACG,OAAT,CAAkBlB,IAAI,CAACE,OAAvB,EAAgC;AAC/BiB,QAAAA,SAAS,EAAE,IADoB;AAE/BC,QAAAA,UAAU,EAAE,IAFmB;AAG/BC,QAAAA,OAAO,EAAE;AAHsB,OAAhC;AAKA;;AAED,WAAO,MAAM;AACZ,UAAKN,QAAL,EAAgB;AACfA,QAAAA,QAAQ,CAACO,UAAT;AACA;;AACDV,MAAAA,gBAAgB,CAACW,MAAjB;AACA,KALD;AAMA,GApBc,EAoBZ,EApBY,CAAf;AAsBA,SAAOvB,IAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { includes, debounce } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useLayoutEffect, useRef } from '@wordpress/element';\nimport { focus } from '@wordpress/dom';\n\n/**\n * Names of control nodes which qualify for disabled behavior.\n *\n * See WHATWG HTML Standard: 4.10.18.5: \"Enabling and disabling form controls: the disabled attribute\".\n *\n * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#enabling-and-disabling-form-controls:-the-disabled-attribute\n *\n * @type {string[]}\n */\nconst DISABLED_ELIGIBLE_NODE_NAMES = [\n\t'BUTTON',\n\t'FIELDSET',\n\t'INPUT',\n\t'OPTGROUP',\n\t'OPTION',\n\t'SELECT',\n\t'TEXTAREA',\n];\n\n/**\n * In some circumstances, such as block previews, all focusable DOM elements\n * (input fields, links, buttons, etc.) need to be disabled. This hook adds the\n * behavior to disable nested DOM elements to the returned ref.\n *\n * @return {import('react').RefObject<HTMLElement>} Element Ref.\n *\n * @example\n * ```js\n * import { __experimentalUseDisabled as useDisabled } from '@wordpress/compose';\n * const DisabledExample = () => {\n * \tconst disabledRef = useDisabled();\n *\treturn (\n *\t\t<div ref={ disabledRef }>\n *\t\t\t<a href=\"#\">This link will have tabindex set to -1</a>\n *\t\t\t<input placeholder=\"This input will have the disabled attribute added to it.\" type=\"text\" />\n *\t\t</div>\n *\t);\n * };\n * ```\n */\nexport default function useDisabled() {\n\t/** @type {import('react').RefObject<HTMLElement>} */\n\tconst node = useRef( null );\n\n\tconst disable = () => {\n\t\tif ( ! node.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfocus.focusable.find( node.current ).forEach( ( focusable ) => {\n\t\t\tif (\n\t\t\t\tincludes( DISABLED_ELIGIBLE_NODE_NAMES, focusable.nodeName )\n\t\t\t) {\n\t\t\t\tfocusable.setAttribute( 'disabled', '' );\n\t\t\t}\n\n\t\t\tif ( focusable.nodeName === 'A' ) {\n\t\t\t\tfocusable.setAttribute( 'tabindex', '-1' );\n\t\t\t}\n\n\t\t\tconst tabIndex = focusable.getAttribute( 'tabindex' );\n\t\t\tif ( tabIndex !== null && tabIndex !== '-1' ) {\n\t\t\t\tfocusable.removeAttribute( 'tabindex' );\n\t\t\t}\n\n\t\t\tif ( focusable.hasAttribute( 'contenteditable' ) ) {\n\t\t\t\tfocusable.setAttribute( 'contenteditable', 'false' );\n\t\t\t}\n\t\t} );\n\t};\n\n\t// Debounce re-disable since disabling process itself will incur\n\t// additional mutations which should be ignored.\n\tconst debouncedDisable = useCallback(\n\t\tdebounce( disable, undefined, { leading: true } ),\n\t\t[]\n\t);\n\n\tuseLayoutEffect( () => {\n\t\tdisable();\n\n\t\t/** @type {MutationObserver | undefined} */\n\t\tlet observer;\n\t\tif ( node.current ) {\n\t\t\tobserver = new window.MutationObserver( debouncedDisable );\n\t\t\tobserver.observe( node.current, {\n\t\t\t\tchildList: true,\n\t\t\t\tattributes: true,\n\t\t\t\tsubtree: true,\n\t\t\t} );\n\t\t}\n\n\t\treturn () => {\n\t\t\tif ( observer ) {\n\t\t\t\tobserver.disconnect();\n\t\t\t}\n\t\t\tdebouncedDisable.cancel();\n\t\t};\n\t}, [] );\n\n\treturn node;\n}\n"]}
|
|
@@ -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"]}
|
package/build-module/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export { default as useConstrainedTabbing } from './hooks/use-constrained-tabbin
|
|
|
14
14
|
export { default as useCopyOnClick } from './hooks/use-copy-on-click';
|
|
15
15
|
export { default as useCopyToClipboard } from './hooks/use-copy-to-clipboard';
|
|
16
16
|
export { default as __experimentalUseDialog } from './hooks/use-dialog';
|
|
17
|
+
export { default as __experimentalUseDisabled } from './hooks/use-disabled';
|
|
17
18
|
export { default as __experimentalUseDragging } from './hooks/use-dragging';
|
|
18
19
|
export { default as useFocusOnMount } from './hooks/use-focus-on-mount';
|
|
19
20
|
export { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/index.js"],"names":["default","createHigherOrderComponent","compose","ifCondition","pure","withGlobalEvents","withInstanceId","withSafeTimeout","withState","useConstrainedTabbing","useCopyOnClick","useCopyToClipboard","__experimentalUseDialog","__experimentalUseDragging","useFocusOnMount","__experimentalUseFocusOutside","useFocusReturn","useInstanceId","useIsomorphicLayoutEffect","useKeyboardShortcut","useMediaQuery","usePrevious","useReducedMotion","useViewportMatch","useResizeObserver","useAsyncList","useWarnOnChange","useDebounce","useThrottle","useMergeRefs","useRefEffect","__experimentalUseDropZone","useFocusableIframe","__experimentalUseFixedWindowList"],"mappings":"AAAA;AACA,SAASA,OAAO,IAAIC,0BAApB,QAAsD,uCAAtD,C,CAEA;;AACA,SAASD,OAAO,IAAIE,OAApB,QAAmC,wBAAnC,C,CAEA;;AACA,SAASF,OAAO,IAAIG,WAApB,QAAuC,6BAAvC;AACA,SAASH,OAAO,IAAII,IAApB,QAAgC,qBAAhC;AACA,SAASJ,OAAO,IAAIK,gBAApB,QAA4C,mCAA5C;AACA,SAASL,OAAO,IAAIM,cAApB,QAA0C,iCAA1C;AACA,SAASN,OAAO,IAAIO,eAApB,QAA2C,kCAA3C;AACA,SAASP,OAAO,IAAIQ,SAApB,QAAqC,2BAArC,C,CAEA;;AACA,SAASR,OAAO,IAAIS,qBAApB,QAAiD,iCAAjD;AACA,SAAST,OAAO,IAAIU,cAApB,QAA0C,2BAA1C;AACA,SAASV,OAAO,IAAIW,kBAApB,QAA8C,+BAA9C;AACA,SAASX,OAAO,IAAIY,uBAApB,QAAmD,oBAAnD;AACA,SAASZ,OAAO,IAAIa,yBAApB,QAAqD,sBAArD;AACA,SAASb,OAAO,IAAIc,eAApB,QAA2C,4BAA3C;AACA,
|
|
1
|
+
{"version":3,"sources":["@wordpress/compose/src/index.js"],"names":["default","createHigherOrderComponent","compose","ifCondition","pure","withGlobalEvents","withInstanceId","withSafeTimeout","withState","useConstrainedTabbing","useCopyOnClick","useCopyToClipboard","__experimentalUseDialog","__experimentalUseDisabled","__experimentalUseDragging","useFocusOnMount","__experimentalUseFocusOutside","useFocusReturn","useInstanceId","useIsomorphicLayoutEffect","useKeyboardShortcut","useMediaQuery","usePrevious","useReducedMotion","useViewportMatch","useResizeObserver","useAsyncList","useWarnOnChange","useDebounce","useThrottle","useMergeRefs","useRefEffect","__experimentalUseDropZone","useFocusableIframe","__experimentalUseFixedWindowList"],"mappings":"AAAA;AACA,SAASA,OAAO,IAAIC,0BAApB,QAAsD,uCAAtD,C,CAEA;;AACA,SAASD,OAAO,IAAIE,OAApB,QAAmC,wBAAnC,C,CAEA;;AACA,SAASF,OAAO,IAAIG,WAApB,QAAuC,6BAAvC;AACA,SAASH,OAAO,IAAII,IAApB,QAAgC,qBAAhC;AACA,SAASJ,OAAO,IAAIK,gBAApB,QAA4C,mCAA5C;AACA,SAASL,OAAO,IAAIM,cAApB,QAA0C,iCAA1C;AACA,SAASN,OAAO,IAAIO,eAApB,QAA2C,kCAA3C;AACA,SAASP,OAAO,IAAIQ,SAApB,QAAqC,2BAArC,C,CAEA;;AACA,SAASR,OAAO,IAAIS,qBAApB,QAAiD,iCAAjD;AACA,SAAST,OAAO,IAAIU,cAApB,QAA0C,2BAA1C;AACA,SAASV,OAAO,IAAIW,kBAApB,QAA8C,+BAA9C;AACA,SAASX,OAAO,IAAIY,uBAApB,QAAmD,oBAAnD;AACA,SAASZ,OAAO,IAAIa,yBAApB,QAAqD,sBAArD;AACA,SAASb,OAAO,IAAIc,yBAApB,QAAqD,sBAArD;AACA,SAASd,OAAO,IAAIe,eAApB,QAA2C,4BAA3C;AACA,SAASf,OAAO,IAAIgB,6BAApB,QAAyD,2BAAzD;AACA,SAAShB,OAAO,IAAIiB,cAApB,QAA0C,0BAA1C;AACA,SAASjB,OAAO,IAAIkB,aAApB,QAAyC,yBAAzC;AACA,SAASlB,OAAO,IAAImB,yBAApB,QAAqD,sCAArD;AACA,SAASnB,OAAO,IAAIoB,mBAApB,QAA+C,+BAA/C;AACA,SAASpB,OAAO,IAAIqB,aAApB,QAAyC,yBAAzC;AACA,SAASrB,OAAO,IAAIsB,WAApB,QAAuC,sBAAvC;AACA,SAAStB,OAAO,IAAIuB,gBAApB,QAA4C,4BAA5C;AACA,SAASvB,OAAO,IAAIwB,gBAApB,QAA4C,4BAA5C;AACA,SAASxB,OAAO,IAAIyB,iBAApB,QAA6C,6BAA7C;AACA,SAASzB,OAAO,IAAI0B,YAApB,QAAwC,wBAAxC;AACA,SAAS1B,OAAO,IAAI2B,eAApB,QAA2C,4BAA3C;AACA,SAAS3B,OAAO,IAAI4B,WAApB,QAAuC,sBAAvC;AACA,SAAS5B,OAAO,IAAI6B,WAApB,QAAuC,sBAAvC;AACA,SAAS7B,OAAO,IAAI8B,YAApB,QAAwC,wBAAxC;AACA,SAAS9B,OAAO,IAAI+B,YAApB,QAAwC,wBAAxC;AACA,SAAS/B,OAAO,IAAIgC,yBAApB,QAAqD,uBAArD;AACA,SAAShC,OAAO,IAAIiC,kBAApB,QAA8C,8BAA9C;AACA,SAASjC,OAAO,IAAIkC,gCAApB,QAA4D,+BAA5D","sourcesContent":["// Utils\nexport { default as createHigherOrderComponent } from './utils/create-higher-order-component';\n\n// Compose helper (aliased flowRight from Lodash)\nexport { default as compose } from './higher-order/compose';\n\n// Higher-order components\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\n\n// Hooks\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as useCopyOnClick } from './hooks/use-copy-on-click';\nexport { default as useCopyToClipboard } from './hooks/use-copy-to-clipboard';\nexport { default as __experimentalUseDialog } from './hooks/use-dialog';\nexport { default as __experimentalUseDisabled } from './hooks/use-disabled';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as useFocusOnMount } from './hooks/use-focus-on-mount';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useFocusReturn } from './hooks/use-focus-return';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useAsyncList } from './hooks/use-async-list';\nexport { default as useWarnOnChange } from './hooks/use-warn-on-change';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\nexport { default as __experimentalUseDropZone } from './hooks/use-drop-zone';\nexport { default as useFocusableIframe } from './hooks/use-focusable-iframe';\nexport { default as __experimentalUseFixedWindowList } from './hooks/use-fixed-window-list';\n"]}
|
|
@@ -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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In some circumstances, such as block previews, all focusable DOM elements
|
|
3
|
+
* (input fields, links, buttons, etc.) need to be disabled. This hook adds the
|
|
4
|
+
* behavior to disable nested DOM elements to the returned ref.
|
|
5
|
+
*
|
|
6
|
+
* @return {import('react').RefObject<HTMLElement>} Element Ref.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* import { __experimentalUseDisabled as useDisabled } from '@wordpress/compose';
|
|
11
|
+
* const DisabledExample = () => {
|
|
12
|
+
* const disabledRef = useDisabled();
|
|
13
|
+
* return (
|
|
14
|
+
* <div ref={ disabledRef }>
|
|
15
|
+
* <a href="#">This link will have tabindex set to -1</a>
|
|
16
|
+
* <input placeholder="This input will have the disabled attribute added to it." type="text" />
|
|
17
|
+
* </div>
|
|
18
|
+
* );
|
|
19
|
+
* };
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export default function useDisabled(): import('react').RefObject<HTMLElement>;
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-disabled/index.js"],"names":[],"mappings":"AA8BA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,uCAhBY,OAAO,OAAO,EAAE,SAAS,CAAC,WAAW,CAAC,CA6EjD"}
|
|
@@ -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"}
|
package/build-types/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { default as useConstrainedTabbing } from "./hooks/use-constrained-tabbin
|
|
|
10
10
|
export { default as useCopyOnClick } from "./hooks/use-copy-on-click";
|
|
11
11
|
export { default as useCopyToClipboard } from "./hooks/use-copy-to-clipboard";
|
|
12
12
|
export { default as __experimentalUseDialog } from "./hooks/use-dialog";
|
|
13
|
+
export { default as __experimentalUseDisabled } from "./hooks/use-disabled";
|
|
13
14
|
export { default as __experimentalUseDragging } from "./hooks/use-dragging";
|
|
14
15
|
export { default as useFocusOnMount } from "./hooks/use-focus-on-mount";
|
|
15
16
|
export { default as __experimentalUseFocusOutside } from "./hooks/use-focus-outside";
|
|
@@ -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"}
|