@wordpress/plugins 6.26.0 → 7.0.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 +7 -0
- package/build/components/plugin-area/index.js +16 -14
- package/build/components/plugin-area/index.js.map +1 -1
- package/build/components/plugin-context/index.js +7 -5
- package/build/components/plugin-context/index.js.map +1 -1
- package/build-module/components/plugin-area/index.js +16 -14
- package/build-module/components/plugin-area/index.js.map +1 -1
- package/build-module/components/plugin-context/index.js +7 -6
- package/build-module/components/plugin-context/index.js.map +1 -1
- package/package.json +10 -9
- package/tsconfig.json +1 -2
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 7.0.0 (2024-05-31)
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
- Variables like `process.env.IS_GUTENBERG_PLUGIN` have been replaced by `globalThis.IS_GUTENBERG_PLUGIN`. Build systems using `process.env` should be updated ([#61486](https://github.com/WordPress/gutenberg/pull/61486)).
|
|
10
|
+
- Increase the minimum required Node.js version to v18.12.0 matching long-term support releases ([#31270](https://github.com/WordPress/gutenberg/pull/61930)). Learn more about [Node.js releases](https://nodejs.org/en/about/previous-releases).
|
|
11
|
+
|
|
5
12
|
## 6.26.0 (2024-05-16)
|
|
6
13
|
|
|
7
14
|
## 6.25.0 (2024-05-02)
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var _react = require("react");
|
|
9
8
|
var _memize = _interopRequireDefault(require("memize"));
|
|
10
9
|
var _element = require("@wordpress/element");
|
|
11
10
|
var _hooks = require("@wordpress/hooks");
|
|
@@ -13,6 +12,7 @@ var _isShallowEqual = _interopRequireDefault(require("@wordpress/is-shallow-equa
|
|
|
13
12
|
var _pluginContext = require("../plugin-context");
|
|
14
13
|
var _pluginErrorBoundary = require("../plugin-error-boundary");
|
|
15
14
|
var _api = require("../../api");
|
|
15
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
16
|
/**
|
|
17
17
|
* External dependencies
|
|
18
18
|
*/
|
|
@@ -92,21 +92,23 @@ function PluginArea({
|
|
|
92
92
|
};
|
|
93
93
|
}, [scope]);
|
|
94
94
|
const plugins = (0, _element.useSyncExternalStore)(store.subscribe, store.getValue, store.getValue);
|
|
95
|
-
return (0,
|
|
95
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
96
96
|
style: {
|
|
97
97
|
display: 'none'
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
98
|
+
},
|
|
99
|
+
children: plugins.map(({
|
|
100
|
+
icon,
|
|
101
|
+
name,
|
|
102
|
+
render: Plugin
|
|
103
|
+
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_pluginContext.PluginContextProvider, {
|
|
104
|
+
value: getPluginContext(icon, name),
|
|
105
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_pluginErrorBoundary.PluginErrorBoundary, {
|
|
106
|
+
name: name,
|
|
107
|
+
onError: onError,
|
|
108
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Plugin, {})
|
|
109
|
+
})
|
|
110
|
+
}, name))
|
|
111
|
+
});
|
|
110
112
|
}
|
|
111
113
|
var _default = exports.default = PluginArea;
|
|
112
114
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_memize","_interopRequireDefault","require","_element","_hooks","_isShallowEqual","_pluginContext","_pluginErrorBoundary","_api","getPluginContext","memoize","icon","name","PluginArea","scope","onError","store","useMemo","lastValue","subscribe","listener","addAction","removeAction","getValue","nextValue","getPlugins","isShallowEqual","plugins","useSyncExternalStore","
|
|
1
|
+
{"version":3,"names":["_memize","_interopRequireDefault","require","_element","_hooks","_isShallowEqual","_pluginContext","_pluginErrorBoundary","_api","_jsxRuntime","getPluginContext","memoize","icon","name","PluginArea","scope","onError","store","useMemo","lastValue","subscribe","listener","addAction","removeAction","getValue","nextValue","getPlugins","isShallowEqual","plugins","useSyncExternalStore","jsx","style","display","children","map","render","Plugin","PluginContextProvider","value","PluginErrorBoundary","_default","exports","default"],"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 = React.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 {Component} 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(\n\t\tstore.subscribe,\n\t\tstore.getValue,\n\t\tstore.getValue\n\t);\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":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAKA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,oBAAA,GAAAL,OAAA;AACA,IAAAM,IAAA,GAAAN,OAAA;AAAuC,IAAAO,WAAA,GAAAP,OAAA;AAjBvC;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;;AAOA,MAAMQ,gBAAgB,GAAG,IAAAC,eAAO,EAC/B,CAAEC,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,GAAG,IAAAC,gBAAO,EAAE,MAAM;IAC5B,IAAIC,SAAqB,GAAG,EAAE;IAE9B,OAAO;MACNC,SAASA,CACRC,QAGS,EACR;QACD,IAAAC,gBAAS,EACR,0BAA0B,EAC1B,6CAA6C,EAC7CD,QACD,CAAC;QACD,IAAAC,gBAAS,EACR,4BAA4B,EAC5B,+CAA+C,EAC/CD,QACD,CAAC;QACD,OAAO,MAAM;UACZ,IAAAE,mBAAY,EACX,0BAA0B,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7
7
|
exports.usePluginContext = usePluginContext;
|
|
8
8
|
exports.withPluginContext = void 0;
|
|
9
|
-
var _react = require("react");
|
|
10
9
|
var _element = require("@wordpress/element");
|
|
11
10
|
var _compose = require("@wordpress/compose");
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
12
|
/**
|
|
13
13
|
* WordPress dependencies
|
|
14
14
|
*/
|
|
@@ -43,10 +43,12 @@ function usePluginContext() {
|
|
|
43
43
|
* @return {Component} Enhanced component with injected context as props.
|
|
44
44
|
*/
|
|
45
45
|
const withPluginContext = mapContextToProps => (0, _compose.createHigherOrderComponent)(OriginalComponent => {
|
|
46
|
-
return props => (0,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
return props => /*#__PURE__*/(0, _jsxRuntime.jsx)(Context.Consumer, {
|
|
47
|
+
children: context => /*#__PURE__*/(0, _jsxRuntime.jsx)(OriginalComponent, {
|
|
48
|
+
...props,
|
|
49
|
+
...mapContextToProps(context, props)
|
|
50
|
+
})
|
|
51
|
+
});
|
|
50
52
|
}, 'withPluginContext');
|
|
51
53
|
exports.withPluginContext = withPluginContext;
|
|
52
54
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_compose","Context","createContext","name","icon","PluginContextProvider","exports","Provider","usePluginContext","useContext","withPluginContext","mapContextToProps","createHigherOrderComponent","OriginalComponent","props","
|
|
1
|
+
{"version":3,"names":["_element","require","_compose","_jsxRuntime","Context","createContext","name","icon","PluginContextProvider","exports","Provider","usePluginContext","useContext","withPluginContext","mapContextToProps","createHigherOrderComponent","OriginalComponent","props","jsx","Consumer","children","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 {Component} 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":";;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAAgE,IAAAE,WAAA,GAAAF,OAAA;AAJhE;AACA;AACA;;AAIA;AACA;AACA;;AAQA,MAAMG,OAAO,GAAG,IAAAC,sBAAa,EAAmB;EAC/CC,IAAI,EAAE,IAAI;EACVC,IAAI,EAAE;AACP,CAAE,CAAC;AAEI,MAAMC,qBAAqB,GAAAC,OAAA,CAAAD,qBAAA,GAAGJ,OAAO,CAACM,QAAQ;;AAErD;AACA;AACA;AACA;AACA;AACO,SAASC,gBAAgBA,CAAA,EAAG;EAClC,OAAO,IAAAC,mBAAU,EAAER,OAAQ,CAAC;AAC7B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMS,iBAAiB,GAC7BC,iBAGsB,IAEtB,IAAAC,mCAA0B,EAAIC,iBAAiB,IAAM;EACpD,OAASC,KAAK,iBACb,IAAAd,WAAA,CAAAe,GAAA,EAACd,OAAO,CAACe,QAAQ;IAAAC,QAAA,EACZC,OAAO,iBACV,IAAAlB,WAAA,CAAAe,GAAA,EAACF,iBAAiB;MAAA,GACZC,KAAK;MAAA,GACLH,iBAAiB,CAAEO,OAAO,EAAEJ,KAAM;IAAC,CACxC;EACD,CACgB,CAClB;AACF,CAAC,EAAE,mBAAoB,CAAC;AAACR,OAAA,CAAAI,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createElement } from "react";
|
|
2
1
|
/**
|
|
3
2
|
* External dependencies
|
|
4
3
|
*/
|
|
@@ -17,6 +16,7 @@ import isShallowEqual from '@wordpress/is-shallow-equal';
|
|
|
17
16
|
import { PluginContextProvider } from '../plugin-context';
|
|
18
17
|
import { PluginErrorBoundary } from '../plugin-error-boundary';
|
|
19
18
|
import { getPlugins } from '../../api';
|
|
19
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
20
|
const getPluginContext = memoize((icon, name) => ({
|
|
21
21
|
icon,
|
|
22
22
|
name
|
|
@@ -84,21 +84,23 @@ function PluginArea({
|
|
|
84
84
|
};
|
|
85
85
|
}, [scope]);
|
|
86
86
|
const plugins = useSyncExternalStore(store.subscribe, store.getValue, store.getValue);
|
|
87
|
-
return
|
|
87
|
+
return /*#__PURE__*/_jsx("div", {
|
|
88
88
|
style: {
|
|
89
89
|
display: 'none'
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
},
|
|
91
|
+
children: plugins.map(({
|
|
92
|
+
icon,
|
|
93
|
+
name,
|
|
94
|
+
render: Plugin
|
|
95
|
+
}) => /*#__PURE__*/_jsx(PluginContextProvider, {
|
|
96
|
+
value: getPluginContext(icon, name),
|
|
97
|
+
children: /*#__PURE__*/_jsx(PluginErrorBoundary, {
|
|
98
|
+
name: name,
|
|
99
|
+
onError: onError,
|
|
100
|
+
children: /*#__PURE__*/_jsx(Plugin, {})
|
|
101
|
+
})
|
|
102
|
+
}, name))
|
|
103
|
+
});
|
|
102
104
|
}
|
|
103
105
|
export default PluginArea;
|
|
104
106
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
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","
|
|
1
|
+
{"version":3,"names":["memoize","useMemo","useSyncExternalStore","addAction","removeAction","isShallowEqual","PluginContextProvider","PluginErrorBoundary","getPlugins","jsx","_jsx","getPluginContext","icon","name","PluginArea","scope","onError","store","lastValue","subscribe","listener","getValue","nextValue","plugins","style","display","children","map","render","Plugin","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 = React.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 {Component} 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(\n\t\tstore.subscribe,\n\t\tstore.getValue,\n\t\tstore.getValue\n\t);\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;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAIvC,MAAMC,gBAAgB,GAAGX,OAAO,CAC/B,CAAEY,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;EACL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AAC;AAER;AAEA,eAAeC,UAAU","ignoreList":[]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createElement } from "react";
|
|
2
1
|
/**
|
|
3
2
|
* WordPress dependencies
|
|
4
3
|
*/
|
|
@@ -8,7 +7,7 @@ import { createHigherOrderComponent } from '@wordpress/compose';
|
|
|
8
7
|
/**
|
|
9
8
|
* Internal dependencies
|
|
10
9
|
*/
|
|
11
|
-
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
11
|
const Context = createContext({
|
|
13
12
|
name: null,
|
|
14
13
|
icon: null
|
|
@@ -35,9 +34,11 @@ export function usePluginContext() {
|
|
|
35
34
|
* @return {Component} Enhanced component with injected context as props.
|
|
36
35
|
*/
|
|
37
36
|
export const withPluginContext = mapContextToProps => createHigherOrderComponent(OriginalComponent => {
|
|
38
|
-
return props =>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
return props => /*#__PURE__*/_jsx(Context.Consumer, {
|
|
38
|
+
children: context => /*#__PURE__*/_jsx(OriginalComponent, {
|
|
39
|
+
...props,
|
|
40
|
+
...mapContextToProps(context, props)
|
|
41
|
+
})
|
|
42
|
+
});
|
|
42
43
|
}, 'withPluginContext');
|
|
43
44
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","useContext","createHigherOrderComponent","Context","name","icon","PluginContextProvider","Provider","usePluginContext","withPluginContext","mapContextToProps","OriginalComponent","props","
|
|
1
|
+
{"version":3,"names":["createContext","useContext","createHigherOrderComponent","jsx","_jsx","Context","name","icon","PluginContextProvider","Provider","usePluginContext","withPluginContext","mapContextToProps","OriginalComponent","props","Consumer","children","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 {Component} 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;AAFA,SAAAC,GAAA,IAAAC,IAAA;AAUA,MAAMC,OAAO,GAAGL,aAAa,CAAmB;EAC/CM,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,OAAOT,UAAU,CAAEI,OAAQ,CAAC;AAC7B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMM,iBAAiB,GAC7BC,iBAGsB,IAEtBV,0BAA0B,CAAIW,iBAAiB,IAAM;EACpD,OAASC,KAAK,iBACbV,IAAA,CAACC,OAAO,CAACU,QAAQ;IAAAC,QAAA,EACZC,OAAO,iBACVb,IAAA,CAACS,iBAAiB;MAAA,GACZC,KAAK;MAAA,GACLF,iBAAiB,CAAEK,OAAO,EAAEH,KAAM;IAAC,CACxC;EACD,CACgB,CAClB;AACF,CAAC,EAAE,mBAAoB,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/plugins",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Plugins module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"url": "https://github.com/WordPress/gutenberg/issues"
|
|
20
20
|
},
|
|
21
21
|
"engines": {
|
|
22
|
-
"node": ">=12"
|
|
22
|
+
"node": ">=18.12.0",
|
|
23
|
+
"npm": ">=8.19.2"
|
|
23
24
|
},
|
|
24
25
|
"main": "build/index.js",
|
|
25
26
|
"module": "build-module/index.js",
|
|
@@ -27,12 +28,12 @@
|
|
|
27
28
|
"types": "build-types",
|
|
28
29
|
"dependencies": {
|
|
29
30
|
"@babel/runtime": "^7.16.0",
|
|
30
|
-
"@wordpress/components": "^
|
|
31
|
-
"@wordpress/compose": "^
|
|
32
|
-
"@wordpress/element": "^
|
|
33
|
-
"@wordpress/hooks": "^
|
|
34
|
-
"@wordpress/icons": "^
|
|
35
|
-
"@wordpress/is-shallow-equal": "^
|
|
31
|
+
"@wordpress/components": "^28.0.0",
|
|
32
|
+
"@wordpress/compose": "^7.0.0",
|
|
33
|
+
"@wordpress/element": "^6.0.0",
|
|
34
|
+
"@wordpress/hooks": "^4.0.0",
|
|
35
|
+
"@wordpress/icons": "^10.0.0",
|
|
36
|
+
"@wordpress/is-shallow-equal": "^5.0.0",
|
|
36
37
|
"memize": "^2.0.1"
|
|
37
38
|
},
|
|
38
39
|
"peerDependencies": {
|
|
@@ -42,5 +43,5 @@
|
|
|
42
43
|
"publishConfig": {
|
|
43
44
|
"access": "public"
|
|
44
45
|
},
|
|
45
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "2f30cddff15723ac7017fd009fc5913b7b419400"
|
|
46
47
|
}
|