@wordpress/plugins 6.6.0 → 6.8.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 +4 -0
- package/README.md +8 -0
- package/build/api/index.js +4 -19
- package/build/api/index.js.map +1 -1
- package/build/components/index.js +6 -3
- package/build/components/index.js.map +1 -1
- package/build/components/plugin-area/index.js +2 -15
- package/build/components/plugin-area/index.js.map +1 -1
- package/build/components/plugin-context/index.js +18 -11
- package/build/components/plugin-context/index.js.map +1 -1
- package/build/components/plugin-error-boundary/index.js +2 -10
- package/build/components/plugin-error-boundary/index.js.map +1 -1
- package/build/index.js +0 -4
- package/build/index.js.map +1 -1
- package/build-module/api/index.js +4 -14
- package/build-module/api/index.js.map +1 -1
- package/build-module/components/index.js +1 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/plugin-area/index.js +3 -9
- package/build-module/components/plugin-area/index.js.map +1 -1
- package/build-module/components/plugin-context/index.js +16 -9
- package/build-module/components/plugin-context/index.js.map +1 -1
- package/build-module/components/plugin-error-boundary/index.js +1 -7
- package/build-module/components/plugin-error-boundary/index.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-types/components/index.d.ts +1 -1
- package/build-types/components/plugin-area/index.d.ts +1 -0
- package/build-types/components/plugin-area/index.d.ts.map +1 -1
- package/build-types/components/plugin-context/index.d.ts +8 -2
- package/build-types/components/plugin-context/index.d.ts.map +1 -1
- package/build-types/components/plugin-error-boundary/index.d.ts +1 -1
- package/build-types/components/plugin-error-boundary/index.d.ts.map +1 -1
- package/package.json +10 -9
- package/src/components/index.js +1 -1
- package/src/components/plugin-context/index.tsx +14 -5
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["default","PluginArea","usePluginContext","withPluginContext"],"sources":["@wordpress/plugins/src/components/index.js"],"sourcesContent":["export { default as PluginArea } from './plugin-area';\nexport { usePluginContext, withPluginContext } from './plugin-context';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,UAAU,QAAQ,eAAe;AACrD,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,kBAAkB"}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* External dependencies
|
|
5
4
|
*/
|
|
6
5
|
import memoize from 'memize';
|
|
6
|
+
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
import { useMemo, useSyncExternalStore } from '@wordpress/element';
|
|
12
11
|
import { addAction, removeAction } from '@wordpress/hooks';
|
|
13
12
|
import isShallowEqual from '@wordpress/is-shallow-equal';
|
|
13
|
+
|
|
14
14
|
/**
|
|
15
15
|
* Internal dependencies
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
17
|
import { PluginContextProvider } from '../plugin-context';
|
|
19
18
|
import { PluginErrorBoundary } from '../plugin-error-boundary';
|
|
20
19
|
import { getPlugins } from '../../api';
|
|
@@ -22,6 +21,7 @@ const getPluginContext = memoize((icon, name) => ({
|
|
|
22
21
|
icon,
|
|
23
22
|
name
|
|
24
23
|
}));
|
|
24
|
+
|
|
25
25
|
/**
|
|
26
26
|
* A component that renders all plugin fills in a hidden div.
|
|
27
27
|
*
|
|
@@ -59,7 +59,6 @@ const getPluginContext = memoize((icon, name) => ({
|
|
|
59
59
|
*
|
|
60
60
|
* @return {WPComponent} The component to be rendered.
|
|
61
61
|
*/
|
|
62
|
-
|
|
63
62
|
function PluginArea({
|
|
64
63
|
scope,
|
|
65
64
|
onError
|
|
@@ -75,17 +74,13 @@ function PluginArea({
|
|
|
75
74
|
removeAction('plugins.pluginUnregistered', 'core/plugins/plugin-area/plugins-unregistered');
|
|
76
75
|
};
|
|
77
76
|
},
|
|
78
|
-
|
|
79
77
|
getValue() {
|
|
80
78
|
const nextValue = getPlugins(scope);
|
|
81
|
-
|
|
82
79
|
if (!isShallowEqual(lastValue, nextValue)) {
|
|
83
80
|
lastValue = nextValue;
|
|
84
81
|
}
|
|
85
|
-
|
|
86
82
|
return lastValue;
|
|
87
83
|
}
|
|
88
|
-
|
|
89
84
|
};
|
|
90
85
|
}, [scope]);
|
|
91
86
|
const plugins = useSyncExternalStore(store.subscribe, store.getValue);
|
|
@@ -105,6 +100,5 @@ function PluginArea({
|
|
|
105
100
|
onError: onError
|
|
106
101
|
}, createElement(Plugin, null)))));
|
|
107
102
|
}
|
|
108
|
-
|
|
109
103
|
export default PluginArea;
|
|
110
104
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["memoize","useMemo","useSyncExternalStore","addAction","removeAction","isShallowEqual","PluginContextProvider","PluginErrorBoundary","getPlugins","getPluginContext","icon","name","PluginArea","scope","onError","store","lastValue","subscribe","listener","getValue","nextValue","plugins","createElement","style","display","map","render","Plugin","key","value"],"sources":["@wordpress/plugins/src/components/plugin-area/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport memoize from 'memize';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\nimport { addAction, removeAction } from '@wordpress/hooks';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport { PluginContextProvider } from '../plugin-context';\nimport { PluginErrorBoundary } from '../plugin-error-boundary';\nimport { getPlugins } from '../../api';\nimport type { PluginContext } from '../plugin-context';\nimport type { WPPlugin } from '../../api';\n\nconst getPluginContext = memoize(\n\t( icon: PluginContext[ 'icon' ], name: PluginContext[ 'name' ] ) => ( {\n\t\ticon,\n\t\tname,\n\t} )\n);\n\n/**\n * A component that renders all plugin fills in a hidden div.\n *\n * @param props\n * @param props.scope\n * @param props.onError\n * @example\n * ```js\n * // Using ES5 syntax\n * var el = wp.element.createElement;\n * var PluginArea = wp.plugins.PluginArea;\n *\n * function Layout() {\n * \treturn el(\n * \t\t'div',\n * \t\t{ scope: 'my-page' },\n * \t\t'Content of the page',\n * \t\tPluginArea\n * \t);\n * }\n * ```\n *\n * @example\n * ```js\n * // Using ESNext syntax\n * import { PluginArea } from '@wordpress/plugins';\n *\n * const Layout = () => (\n * \t<div>\n * \t\tContent of the page\n * \t\t<PluginArea scope=\"my-page\" />\n * \t</div>\n * );\n * ```\n *\n * @return {WPComponent} The component to be rendered.\n */\nfunction PluginArea( {\n\tscope,\n\tonError,\n}: {\n\tscope?: string;\n\tonError?: ( name: WPPlugin[ 'name' ], error: Error ) => void;\n} ) {\n\tconst store = useMemo( () => {\n\t\tlet lastValue: WPPlugin[] = [];\n\n\t\treturn {\n\t\t\tsubscribe(\n\t\t\t\tlistener: (\n\t\t\t\t\tplugin: Omit< WPPlugin, 'name' >,\n\t\t\t\t\tname: WPPlugin[ 'name' ]\n\t\t\t\t) => void\n\t\t\t) {\n\t\t\t\taddAction(\n\t\t\t\t\t'plugins.pluginRegistered',\n\t\t\t\t\t'core/plugins/plugin-area/plugins-registered',\n\t\t\t\t\tlistener\n\t\t\t\t);\n\t\t\t\taddAction(\n\t\t\t\t\t'plugins.pluginUnregistered',\n\t\t\t\t\t'core/plugins/plugin-area/plugins-unregistered',\n\t\t\t\t\tlistener\n\t\t\t\t);\n\t\t\t\treturn () => {\n\t\t\t\t\tremoveAction(\n\t\t\t\t\t\t'plugins.pluginRegistered',\n\t\t\t\t\t\t'core/plugins/plugin-area/plugins-registered'\n\t\t\t\t\t);\n\t\t\t\t\tremoveAction(\n\t\t\t\t\t\t'plugins.pluginUnregistered',\n\t\t\t\t\t\t'core/plugins/plugin-area/plugins-unregistered'\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetValue() {\n\t\t\t\tconst nextValue = getPlugins( scope );\n\n\t\t\t\tif ( ! isShallowEqual( lastValue, nextValue ) ) {\n\t\t\t\t\tlastValue = nextValue;\n\t\t\t\t}\n\n\t\t\t\treturn lastValue;\n\t\t\t},\n\t\t};\n\t}, [ scope ] );\n\n\tconst plugins = useSyncExternalStore( store.subscribe, store.getValue );\n\n\treturn (\n\t\t<div style={ { display: 'none' } }>\n\t\t\t{ plugins.map( ( { icon, name, render: Plugin } ) => (\n\t\t\t\t<PluginContextProvider\n\t\t\t\t\tkey={ name }\n\t\t\t\t\tvalue={ getPluginContext( icon, name ) }\n\t\t\t\t>\n\t\t\t\t\t<PluginErrorBoundary name={ name } onError={ onError }>\n\t\t\t\t\t\t<Plugin />\n\t\t\t\t\t</PluginErrorBoundary>\n\t\t\t\t</PluginContextProvider>\n\t\t\t) ) }\n\t\t</div>\n\t);\n}\n\nexport default PluginArea;\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,OAAO,MAAM,QAAQ;;AAE5B;AACA;AACA;AACA,SAASC,OAAO,EAAEC,oBAAoB,QAAQ,oBAAoB;AAClE,SAASC,SAAS,EAAEC,YAAY,QAAQ,kBAAkB;AAC1D,OAAOC,cAAc,MAAM,6BAA6B;;AAExD;AACA;AACA;AACA,SAASC,qBAAqB,QAAQ,mBAAmB;AACzD,SAASC,mBAAmB,QAAQ,0BAA0B;AAC9D,SAASC,UAAU,QAAQ,WAAW;AAItC,MAAMC,gBAAgB,GAAGT,OAAO,CAC/B,CAAEU,IAA6B,EAAEC,IAA6B,MAAQ;EACrED,IAAI;EACJC;AACD,CAAC,CACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,UAAUA,CAAE;EACpBC,KAAK;EACLC;AAID,CAAC,EAAG;EACH,MAAMC,KAAK,GAAGd,OAAO,CAAE,MAAM;IAC5B,IAAIe,SAAqB,GAAG,EAAE;IAE9B,OAAO;MACNC,SAASA,CACRC,QAGS,EACR;QACDf,SAAS,CACR,0BAA0B,EAC1B,6CAA6C,EAC7Ce,QACD,CAAC;QACDf,SAAS,CACR,4BAA4B,EAC5B,+CAA+C,EAC/Ce,QACD,CAAC;QACD,OAAO,MAAM;UACZd,YAAY,CACX,0BAA0B,EAC1B,6CACD,CAAC;UACDA,YAAY,CACX,4BAA4B,EAC5B,+CACD,CAAC;QACF,CAAC;MACF,CAAC;MACDe,QAAQA,CAAA,EAAG;QACV,MAAMC,SAAS,GAAGZ,UAAU,CAAEK,KAAM,CAAC;QAErC,IAAK,CAAER,cAAc,CAAEW,SAAS,EAAEI,SAAU,CAAC,EAAG;UAC/CJ,SAAS,GAAGI,SAAS;QACtB;QAEA,OAAOJ,SAAS;MACjB;IACD,CAAC;EACF,CAAC,EAAE,CAAEH,KAAK,CAAG,CAAC;EAEd,MAAMQ,OAAO,GAAGnB,oBAAoB,CAAEa,KAAK,CAACE,SAAS,EAAEF,KAAK,CAACI,QAAS,CAAC;EAEvE,OACCG,aAAA;IAAKC,KAAK,EAAG;MAAEC,OAAO,EAAE;IAAO;EAAG,GAC/BH,OAAO,CAACI,GAAG,CAAE,CAAE;IAAEf,IAAI;IAAEC,IAAI;IAAEe,MAAM,EAAEC;EAAO,CAAC,KAC9CL,aAAA,CAAChB,qBAAqB;IACrBsB,GAAG,EAAGjB,IAAM;IACZkB,KAAK,EAAGpB,gBAAgB,CAAEC,IAAI,EAAEC,IAAK;EAAG,GAExCW,aAAA,CAACf,mBAAmB;IAACI,IAAI,EAAGA,IAAM;IAACG,OAAO,EAAGA;EAAS,GACrDQ,aAAA,CAACK,MAAM,MAAE,CACW,CACC,CACtB,CACE,CAAC;AAER;AAEA,eAAef,UAAU"}
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* WordPress dependencies
|
|
5
4
|
*/
|
|
6
|
-
import { createContext } from '@wordpress/element';
|
|
5
|
+
import { createContext, useContext } from '@wordpress/element';
|
|
7
6
|
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
7
|
+
|
|
8
8
|
/**
|
|
9
9
|
* Internal dependencies
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
const {
|
|
13
|
-
Consumer,
|
|
14
|
-
Provider
|
|
15
|
-
} = createContext({
|
|
12
|
+
const Context = createContext({
|
|
16
13
|
name: null,
|
|
17
14
|
icon: null
|
|
18
15
|
});
|
|
19
|
-
export
|
|
16
|
+
export const PluginContextProvider = Context.Provider;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A hook that returns the plugin context.
|
|
20
|
+
*
|
|
21
|
+
* @return {PluginContext} Plugin context
|
|
22
|
+
*/
|
|
23
|
+
export function usePluginContext() {
|
|
24
|
+
return useContext(Context);
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
/**
|
|
21
28
|
* A Higher Order Component used to inject Plugin context to the
|
|
22
29
|
* wrapped component.
|
|
@@ -27,9 +34,9 @@ export { Provider as PluginContextProvider };
|
|
|
27
34
|
*
|
|
28
35
|
* @return {WPComponent} Enhanced component with injected context as props.
|
|
29
36
|
*/
|
|
30
|
-
|
|
31
37
|
export const withPluginContext = mapContextToProps => createHigherOrderComponent(OriginalComponent => {
|
|
32
|
-
return props => createElement(Consumer, null, context => createElement(OriginalComponent, {
|
|
38
|
+
return props => createElement(Context.Consumer, null, context => createElement(OriginalComponent, {
|
|
39
|
+
...props,
|
|
33
40
|
...mapContextToProps(context, props)
|
|
34
41
|
}));
|
|
35
42
|
}, 'withPluginContext');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createContext","useContext","createHigherOrderComponent","Context","name","icon","PluginContextProvider","Provider","usePluginContext","withPluginContext","mapContextToProps","OriginalComponent","props","createElement","Consumer","context"],"sources":["@wordpress/plugins/src/components/plugin-context/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport type { WPPlugin } from '../../api';\n\nexport interface PluginContext {\n\tname: null | WPPlugin[ 'name' ];\n\ticon: null | WPPlugin[ 'icon' ];\n}\n\nconst Context = createContext< PluginContext >( {\n\tname: null,\n\ticon: null,\n} );\n\nexport const PluginContextProvider = Context.Provider;\n\n/**\n * A hook that returns the plugin context.\n *\n * @return {PluginContext} Plugin context\n */\nexport function usePluginContext() {\n\treturn useContext( Context );\n}\n\n/**\n * A Higher Order Component used to inject Plugin context to the\n * wrapped component.\n *\n * @param mapContextToProps Function called on every context change,\n * expected to return object of props to\n * merge with the component's own props.\n *\n * @return {WPComponent} Enhanced component with injected context as props.\n */\nexport const withPluginContext = (\n\tmapContextToProps: < T >(\n\t\tcontext: PluginContext,\n\t\tprops: T\n\t) => T & PluginContext\n) =>\n\tcreateHigherOrderComponent( ( OriginalComponent ) => {\n\t\treturn ( props ) => (\n\t\t\t<Context.Consumer>\n\t\t\t\t{ ( context ) => (\n\t\t\t\t\t<OriginalComponent\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t{ ...mapContextToProps( context, props ) }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</Context.Consumer>\n\t\t);\n\t}, 'withPluginContext' );\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,UAAU,QAAQ,oBAAoB;AAC9D,SAASC,0BAA0B,QAAQ,oBAAoB;;AAE/D;AACA;AACA;;AAQA,MAAMC,OAAO,GAAGH,aAAa,CAAmB;EAC/CI,IAAI,EAAE,IAAI;EACVC,IAAI,EAAE;AACP,CAAE,CAAC;AAEH,OAAO,MAAMC,qBAAqB,GAAGH,OAAO,CAACI,QAAQ;;AAErD;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAAA,EAAG;EAClC,OAAOP,UAAU,CAAEE,OAAQ,CAAC;AAC7B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMM,iBAAiB,GAC7BC,iBAGsB,IAEtBR,0BAA0B,CAAIS,iBAAiB,IAAM;EACpD,OAASC,KAAK,IACbC,aAAA,CAACV,OAAO,CAACW,QAAQ,QACZC,OAAO,IACVF,aAAA,CAACF,iBAAiB;IAAA,GACZC,KAAK;IAAA,GACLF,iBAAiB,CAAEK,OAAO,EAAEH,KAAM;EAAC,CACxC,CAEe,CAClB;AACF,CAAC,EAAE,mBAAoB,CAAC"}
|
|
@@ -12,35 +12,29 @@ export class PluginErrorBoundary extends Component {
|
|
|
12
12
|
hasError: false
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
|
|
16
15
|
static getDerivedStateFromError() {
|
|
17
16
|
return {
|
|
18
17
|
hasError: true
|
|
19
18
|
};
|
|
20
19
|
}
|
|
20
|
+
|
|
21
21
|
/**
|
|
22
22
|
* @param {Error} error Error object passed by React.
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
24
|
componentDidCatch(error) {
|
|
27
25
|
const {
|
|
28
26
|
name,
|
|
29
27
|
onError
|
|
30
28
|
} = this.props;
|
|
31
|
-
|
|
32
29
|
if (onError) {
|
|
33
30
|
onError(name, error);
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
|
-
|
|
37
33
|
render() {
|
|
38
34
|
if (!this.state.hasError) {
|
|
39
35
|
return this.props.children;
|
|
40
36
|
}
|
|
41
|
-
|
|
42
37
|
return null;
|
|
43
38
|
}
|
|
44
|
-
|
|
45
39
|
}
|
|
46
40
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["Component","PluginErrorBoundary","constructor","props","state","hasError","getDerivedStateFromError","componentDidCatch","error","name","onError","render","children"],"sources":["@wordpress/plugins/src/components/plugin-error-boundary/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\n\nexport class PluginErrorBoundary extends Component {\n\t/**\n\t * @param {Object} props\n\t */\n\tconstructor( props ) {\n\t\tsuper( props );\n\t\tthis.state = {\n\t\t\thasError: false,\n\t\t};\n\t}\n\n\tstatic getDerivedStateFromError() {\n\t\treturn { hasError: true };\n\t}\n\n\t/**\n\t * @param {Error} error Error object passed by React.\n\t */\n\tcomponentDidCatch( error ) {\n\t\tconst { name, onError } = this.props;\n\t\tif ( onError ) {\n\t\t\tonError( name, error );\n\t\t}\n\t}\n\n\trender() {\n\t\tif ( ! this.state.hasError ) {\n\t\t\treturn this.props.children;\n\t\t}\n\n\t\treturn null;\n\t}\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,oBAAoB;AAE9C,OAAO,MAAMC,mBAAmB,SAASD,SAAS,CAAC;EAClD;AACD;AACA;EACCE,WAAWA,CAAEC,KAAK,EAAG;IACpB,KAAK,CAAEA,KAAM,CAAC;IACd,IAAI,CAACC,KAAK,GAAG;MACZC,QAAQ,EAAE;IACX,CAAC;EACF;EAEA,OAAOC,wBAAwBA,CAAA,EAAG;IACjC,OAAO;MAAED,QAAQ,EAAE;IAAK,CAAC;EAC1B;;EAEA;AACD;AACA;EACCE,iBAAiBA,CAAEC,KAAK,EAAG;IAC1B,MAAM;MAAEC,IAAI;MAAEC;IAAQ,CAAC,GAAG,IAAI,CAACP,KAAK;IACpC,IAAKO,OAAO,EAAG;MACdA,OAAO,CAAED,IAAI,EAAED,KAAM,CAAC;IACvB;EACD;EAEAG,MAAMA,CAAA,EAAG;IACR,IAAK,CAAE,IAAI,CAACP,KAAK,CAACC,QAAQ,EAAG;MAC5B,OAAO,IAAI,CAACF,KAAK,CAACS,QAAQ;IAC3B;IAEA,OAAO,IAAI;EACZ;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/plugins/src/index.js"],"
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/plugins/src/index.js"],"sourcesContent":["export * from './components';\nexport * from './api';\n"],"mappings":"AAAA,cAAc,cAAc;AAC5B,cAAc,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/plugin-area/index.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAS1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,iBAAS,UAAU,CAAE,EACpB,KAAK,EACL,OAAO,GACP,EAAE;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,CAAE,IAAI,EAAE,QAAQ,CAAE,MAAM,CAAE,EAAE,KAAK,EAAE,KAAK,KAAM,IAAI,CAAC;CAC7D,eA4DA;AAED,eAAe,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/plugin-area/index.tsx"],"names":[],"mappings":";AAmBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAS1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,iBAAS,UAAU,CAAE,EACpB,KAAK,EACL,OAAO,GACP,EAAE;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,CAAE,IAAI,EAAE,QAAQ,CAAE,MAAM,CAAE,EAAE,KAAK,EAAE,KAAK,KAAM,IAAI,CAAC;CAC7D,eA4DA;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
/**
|
|
2
3
|
* Internal dependencies
|
|
3
4
|
*/
|
|
@@ -6,8 +7,13 @@ export interface PluginContext {
|
|
|
6
7
|
name: null | WPPlugin['name'];
|
|
7
8
|
icon: null | WPPlugin['icon'];
|
|
8
9
|
}
|
|
9
|
-
declare const
|
|
10
|
-
|
|
10
|
+
export declare const PluginContextProvider: import("react").Provider<PluginContext>;
|
|
11
|
+
/**
|
|
12
|
+
* A hook that returns the plugin context.
|
|
13
|
+
*
|
|
14
|
+
* @return {PluginContext} Plugin context
|
|
15
|
+
*/
|
|
16
|
+
export declare function usePluginContext(): PluginContext;
|
|
11
17
|
/**
|
|
12
18
|
* A Higher Order Component used to inject Plugin context to the
|
|
13
19
|
* wrapped component.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/plugin-context/index.tsx"],"names":[],"mappings":"AAMA;;GAEG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,IAAI,GAAG,QAAQ,CAAE,MAAM,CAAE,CAAC;IAChC,IAAI,EAAE,IAAI,GAAG,QAAQ,CAAE,MAAM,CAAE,CAAC;CAChC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/plugin-context/index.tsx"],"names":[],"mappings":";AAMA;;GAEG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,IAAI,GAAG,QAAQ,CAAE,MAAM,CAAE,CAAC;IAChC,IAAI,EAAE,IAAI,GAAG,QAAQ,CAAE,MAAM,CAAE,CAAC;CAChC;AAOD,eAAO,MAAM,qBAAqB,yCAAmB,CAAC;AAEtD;;;;GAIG;AACH,wBAAgB,gBAAgB,kBAE/B;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,mCAEnB,aAAa,+GAeC,CAAC"}
|
|
@@ -15,5 +15,5 @@ export class PluginErrorBoundary extends Component<any, any, any> {
|
|
|
15
15
|
componentDidCatch(error: Error): void;
|
|
16
16
|
render(): any;
|
|
17
17
|
}
|
|
18
|
-
import { Component } from
|
|
18
|
+
import { Component } from '@wordpress/element';
|
|
19
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/plugin-error-boundary/index.js"],"names":[],"mappings":"AAKA;IAWC;;MAEC;IAZD;;OAEG;IACH,mBAFW,MAAM,EAOhB;IAHA;;MAEC;IAOF;;OAEG;IACH,yBAFW,KAAK,QAOf;IAED,cAMC;CACD"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/plugin-error-boundary/index.js"],"names":[],"mappings":"AAKA;IAWC;;MAEC;IAZD;;OAEG;IACH,mBAFW,MAAM,EAOhB;IAHA;;MAEC;IAOF;;OAEG;IACH,yBAFW,KAAK,QAOf;IAED,cAMC;CACD;0BAlCyB,oBAAoB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/plugins",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.8.0",
|
|
4
4
|
"description": "Plugins module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -27,19 +27,20 @@
|
|
|
27
27
|
"types": "build-types",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/runtime": "^7.16.0",
|
|
30
|
-
"@wordpress/components": "^25.
|
|
31
|
-
"@wordpress/compose": "^6.
|
|
32
|
-
"@wordpress/element": "^5.
|
|
33
|
-
"@wordpress/hooks": "^3.
|
|
34
|
-
"@wordpress/icons": "^9.
|
|
35
|
-
"@wordpress/is-shallow-equal": "^4.
|
|
30
|
+
"@wordpress/components": "^25.6.0",
|
|
31
|
+
"@wordpress/compose": "^6.17.0",
|
|
32
|
+
"@wordpress/element": "^5.17.0",
|
|
33
|
+
"@wordpress/hooks": "^3.40.0",
|
|
34
|
+
"@wordpress/icons": "^9.31.0",
|
|
35
|
+
"@wordpress/is-shallow-equal": "^4.40.0",
|
|
36
36
|
"memize": "^2.0.1"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"react": "^18.0.0"
|
|
39
|
+
"react": "^18.0.0",
|
|
40
|
+
"react-dom": "^18.0.0"
|
|
40
41
|
},
|
|
41
42
|
"publishConfig": {
|
|
42
43
|
"access": "public"
|
|
43
44
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "78a288d55b83a713b2f7d98d5a855c0771a2afc6"
|
|
45
46
|
}
|
package/src/components/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default as PluginArea } from './plugin-area';
|
|
2
|
-
export { withPluginContext } from './plugin-context';
|
|
2
|
+
export { usePluginContext, withPluginContext } from './plugin-context';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { createContext } from '@wordpress/element';
|
|
4
|
+
import { createContext, useContext } from '@wordpress/element';
|
|
5
5
|
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -14,12 +14,21 @@ export interface PluginContext {
|
|
|
14
14
|
icon: null | WPPlugin[ 'icon' ];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const
|
|
17
|
+
const Context = createContext< PluginContext >( {
|
|
18
18
|
name: null,
|
|
19
19
|
icon: null,
|
|
20
20
|
} );
|
|
21
21
|
|
|
22
|
-
export
|
|
22
|
+
export const PluginContextProvider = Context.Provider;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A hook that returns the plugin context.
|
|
26
|
+
*
|
|
27
|
+
* @return {PluginContext} Plugin context
|
|
28
|
+
*/
|
|
29
|
+
export function usePluginContext() {
|
|
30
|
+
return useContext( Context );
|
|
31
|
+
}
|
|
23
32
|
|
|
24
33
|
/**
|
|
25
34
|
* A Higher Order Component used to inject Plugin context to the
|
|
@@ -39,13 +48,13 @@ export const withPluginContext = (
|
|
|
39
48
|
) =>
|
|
40
49
|
createHigherOrderComponent( ( OriginalComponent ) => {
|
|
41
50
|
return ( props ) => (
|
|
42
|
-
<Consumer>
|
|
51
|
+
<Context.Consumer>
|
|
43
52
|
{ ( context ) => (
|
|
44
53
|
<OriginalComponent
|
|
45
54
|
{ ...props }
|
|
46
55
|
{ ...mapContextToProps( context, props ) }
|
|
47
56
|
/>
|
|
48
57
|
) }
|
|
49
|
-
</Consumer>
|
|
58
|
+
</Context.Consumer>
|
|
50
59
|
);
|
|
51
60
|
}, 'withPluginContext' );
|