@wordpress/plugins 5.8.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +9 -9
- package/build/api/index.js +12 -31
- package/build/api/index.js.map +1 -1
- package/build/components/plugin-area/index.js +4 -4
- package/build/components/plugin-area/index.js.map +1 -1
- package/build/components/plugin-context/index.js +3 -3
- package/build/components/plugin-context/index.js.map +1 -1
- package/build/components/plugin-error-boundary/index.js +7 -0
- package/build/components/plugin-error-boundary/index.js.map +1 -1
- package/build-module/api/index.js +12 -31
- package/build-module/api/index.js.map +1 -1
- package/build-module/components/plugin-area/index.js +4 -4
- package/build-module/components/plugin-area/index.js.map +1 -1
- package/build-module/components/plugin-context/index.js +7 -3
- package/build-module/components/plugin-context/index.js.map +1 -1
- package/build-module/components/plugin-error-boundary/index.js +7 -0
- package/build-module/components/plugin-error-boundary/index.js.map +1 -1
- package/build-types/api/index.d.ts +149 -0
- package/build-types/api/index.d.ts.map +1 -0
- package/build-types/components/index.d.ts +3 -0
- package/build-types/components/index.d.ts.map +1 -0
- package/build-types/components/plugin-area/index.d.ts +44 -0
- package/build-types/components/plugin-area/index.d.ts.map +1 -0
- package/build-types/components/plugin-context/index.d.ts +22 -0
- package/build-types/components/plugin-context/index.d.ts.map +1 -0
- package/build-types/components/plugin-error-boundary/index.d.ts +19 -0
- package/build-types/components/plugin-error-boundary/index.d.ts.map +1 -0
- package/build-types/index.d.ts +3 -0
- package/build-types/index.d.ts.map +1 -0
- package/package.json +9 -7
- package/src/api/{index.js → index.ts} +53 -33
- package/src/components/plugin-area/{index.js → index.tsx} +25 -7
- package/src/components/plugin-context/{index.js → index.tsx} +20 -5
- package/src/components/plugin-error-boundary/index.js +6 -0
- package/tsconfig.json +18 -0
- package/tsconfig.tsbuildinfo +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 6.1.0 (2023-05-10)
|
|
6
|
+
|
|
7
|
+
## 6.0.0 (2023-04-26)
|
|
8
|
+
|
|
9
|
+
### Breaking Changes
|
|
10
|
+
|
|
11
|
+
- Publish types for `@wordpress/plugins` ([#49649](https://github.com/WordPress/gutenberg/pull/49649))
|
|
12
|
+
|
|
5
13
|
## 5.8.0 (2023-04-12)
|
|
6
14
|
|
|
7
15
|
## 5.7.0 (2023-03-29)
|
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ _Parameters_
|
|
|
26
26
|
|
|
27
27
|
_Returns_
|
|
28
28
|
|
|
29
|
-
-
|
|
29
|
+
- `WPPlugin | undefined`: Plugin setting.
|
|
30
30
|
|
|
31
31
|
#### getPlugins
|
|
32
32
|
|
|
@@ -34,7 +34,7 @@ Returns all registered plugins without a scope or for a given scope.
|
|
|
34
34
|
|
|
35
35
|
_Parameters_
|
|
36
36
|
|
|
37
|
-
- _scope_ `
|
|
37
|
+
- _scope_ `string`: The scope to be used when rendering inside a plugin area. No scope by default.
|
|
38
38
|
|
|
39
39
|
_Returns_
|
|
40
40
|
|
|
@@ -70,9 +70,9 @@ const Layout = () => (
|
|
|
70
70
|
|
|
71
71
|
_Parameters_
|
|
72
72
|
|
|
73
|
-
- _props_ `
|
|
74
|
-
- _props.scope_ `string
|
|
75
|
-
- _props.onError_ `
|
|
73
|
+
- _props_ `{ scope?: string; onError?: ( name: WPPlugin[ 'name' ], error: Error ) => void; }`:
|
|
74
|
+
- _props.scope_ `string`:
|
|
75
|
+
- _props.onError_ `( name: WPPlugin[ 'name' ], error: Error ) => void`:
|
|
76
76
|
|
|
77
77
|
_Returns_
|
|
78
78
|
|
|
@@ -147,12 +147,12 @@ registerPlugin( 'plugin-name', {
|
|
|
147
147
|
|
|
148
148
|
_Parameters_
|
|
149
149
|
|
|
150
|
-
- _name_ `string`: A string identifying the plugin.Must be unique across all registered plugins.
|
|
151
|
-
- _settings_ `
|
|
150
|
+
- _name_ `string`: A string identifying the plugin. Must be unique across all registered plugins.
|
|
151
|
+
- _settings_ `PluginSettings`: The settings for this plugin.
|
|
152
152
|
|
|
153
153
|
_Returns_
|
|
154
154
|
|
|
155
|
-
- `
|
|
155
|
+
- `PluginSettings | null`: The final plugin settings object.
|
|
156
156
|
|
|
157
157
|
#### unregisterPlugin
|
|
158
158
|
|
|
@@ -188,7 +188,7 @@ A Higher Order Component used to inject Plugin context to the wrapped component.
|
|
|
188
188
|
|
|
189
189
|
_Parameters_
|
|
190
190
|
|
|
191
|
-
- _mapContextToProps_ `
|
|
191
|
+
- _mapContextToProps_ `( context: PluginContext, props: T ) => T & PluginContext`: Function called on every context change, expected to return object of props to merge with the component's own props.
|
|
192
192
|
|
|
193
193
|
_Returns_
|
|
194
194
|
|
package/build/api/index.js
CHANGED
|
@@ -18,35 +18,16 @@ var _icons = require("@wordpress/icons");
|
|
|
18
18
|
* WordPress dependencies
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
/**
|
|
22
|
-
* Defined behavior of a plugin type.
|
|
23
|
-
*
|
|
24
|
-
* @typedef {Object} WPPlugin
|
|
25
|
-
*
|
|
26
|
-
* @property {string} name A string identifying the plugin. Must be
|
|
27
|
-
* unique across all registered plugins.
|
|
28
|
-
* @property {string|WPElement|Function} [icon] An icon to be shown in the UI. It can
|
|
29
|
-
* be a slug of the Dashicon, or an element
|
|
30
|
-
* (or function returning an element) if you
|
|
31
|
-
* choose to render your own SVG.
|
|
32
|
-
* @property {Function} render A component containing the UI elements
|
|
33
|
-
* to be rendered.
|
|
34
|
-
* @property {string} [scope] The optional scope to be used when rendering inside
|
|
35
|
-
* a plugin area. No scope by default.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
21
|
/**
|
|
39
22
|
* Plugin definitions keyed by plugin name.
|
|
40
|
-
*
|
|
41
|
-
* @type {Object.<string,WPPlugin>}
|
|
42
23
|
*/
|
|
43
24
|
const plugins = {};
|
|
44
25
|
/**
|
|
45
26
|
* Registers a plugin to the editor.
|
|
46
27
|
*
|
|
47
|
-
* @param
|
|
48
|
-
*
|
|
49
|
-
* @param
|
|
28
|
+
* @param name A string identifying the plugin. Must be
|
|
29
|
+
* unique across all registered plugins.
|
|
30
|
+
* @param settings The settings for this plugin.
|
|
50
31
|
*
|
|
51
32
|
* @example
|
|
52
33
|
* ```js
|
|
@@ -116,7 +97,7 @@ const plugins = {};
|
|
|
116
97
|
* } );
|
|
117
98
|
* ```
|
|
118
99
|
*
|
|
119
|
-
* @return
|
|
100
|
+
* @return The final plugin settings object.
|
|
120
101
|
*/
|
|
121
102
|
|
|
122
103
|
function registerPlugin(name, settings) {
|
|
@@ -173,7 +154,7 @@ function registerPlugin(name, settings) {
|
|
|
173
154
|
/**
|
|
174
155
|
* Unregisters a plugin by name.
|
|
175
156
|
*
|
|
176
|
-
* @param
|
|
157
|
+
* @param name Plugin name.
|
|
177
158
|
*
|
|
178
159
|
* @example
|
|
179
160
|
* ```js
|
|
@@ -191,8 +172,8 @@ function registerPlugin(name, settings) {
|
|
|
191
172
|
* unregisterPlugin( 'plugin-name' );
|
|
192
173
|
* ```
|
|
193
174
|
*
|
|
194
|
-
* @return
|
|
195
|
-
*
|
|
175
|
+
* @return The previous plugin settings object, if it has been
|
|
176
|
+
* successfully unregistered; otherwise `undefined`.
|
|
196
177
|
*/
|
|
197
178
|
|
|
198
179
|
|
|
@@ -210,9 +191,9 @@ function unregisterPlugin(name) {
|
|
|
210
191
|
/**
|
|
211
192
|
* Returns a registered plugin settings.
|
|
212
193
|
*
|
|
213
|
-
* @param
|
|
194
|
+
* @param name Plugin name.
|
|
214
195
|
*
|
|
215
|
-
* @return
|
|
196
|
+
* @return Plugin setting.
|
|
216
197
|
*/
|
|
217
198
|
|
|
218
199
|
|
|
@@ -222,10 +203,10 @@ function getPlugin(name) {
|
|
|
222
203
|
/**
|
|
223
204
|
* Returns all registered plugins without a scope or for a given scope.
|
|
224
205
|
*
|
|
225
|
-
* @param
|
|
226
|
-
*
|
|
206
|
+
* @param scope The scope to be used when rendering inside
|
|
207
|
+
* a plugin area. No scope by default.
|
|
227
208
|
*
|
|
228
|
-
* @return
|
|
209
|
+
* @return The list of plugins without a scope or for a given scope.
|
|
229
210
|
*/
|
|
230
211
|
|
|
231
212
|
|
package/build/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/plugins/src/api/index.
|
|
1
|
+
{"version":3,"sources":["@wordpress/plugins/src/api/index.ts"],"names":["plugins","registerPlugin","name","settings","console","error","test","render","scope","icon","pluginsIcon","unregisterPlugin","oldPlugin","getPlugin","getPlugins","Object","values","filter","plugin"],"mappings":";;;;;;;;;;AAKA;;AACA;;AANA;;AAEA;AACA;AACA;;AAoCA;AACA;AACA;AACA,MAAMA,OAAO,GAAG,EAAhB;AAEA;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;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;AACA;AACA;;AACO,SAASC,cAAT,CACNC,IADM,EAENC,QAFM,EAGkB;AACxB,MAAK,OAAOA,QAAP,KAAoB,QAAzB,EAAoC;AACnCC,IAAAA,OAAO,CAACC,KAAR,CAAe,8BAAf;AACA,WAAO,IAAP;AACA;;AACD,MAAK,OAAOH,IAAP,KAAgB,QAArB,EAAgC;AAC/BE,IAAAA,OAAO,CAACC,KAAR,CAAe,6BAAf;AACA,WAAO,IAAP;AACA;;AACD,MAAK,CAAE,oBAAoBC,IAApB,CAA0BJ,IAA1B,CAAP,EAA0C;AACzCE,IAAAA,OAAO,CAACC,KAAR,CACC,2HADD;AAGA,WAAO,IAAP;AACA;;AACD,MAAKL,OAAO,CAAEE,IAAF,CAAZ,EAAuB;AACtBE,IAAAA,OAAO,CAACC,KAAR,CAAgB,WAAWH,IAAM,0BAAjC;AACA;;AAEDC,EAAAA,QAAQ,GAAG,yBACV,wBADU,EAEVA,QAFU,EAGVD,IAHU,CAAX;AAMA,QAAM;AAAEK,IAAAA,MAAF;AAAUC,IAAAA;AAAV,MAAoBL,QAA1B;;AAEA,MAAK,OAAOI,MAAP,KAAkB,UAAvB,EAAoC;AACnCH,IAAAA,OAAO,CAACC,KAAR,CACC,uEADD;AAGA,WAAO,IAAP;AACA;;AAED,MAAKG,KAAL,EAAa;AACZ,QAAK,OAAOA,KAAP,KAAiB,QAAtB,EAAiC;AAChCJ,MAAAA,OAAO,CAACC,KAAR,CAAe,8BAAf;AACA,aAAO,IAAP;AACA;;AAED,QAAK,CAAE,oBAAoBC,IAApB,CAA0BE,KAA1B,CAAP,EAA2C;AAC1CJ,MAAAA,OAAO,CAACC,KAAR,CACC,0HADD;AAGA,aAAO,IAAP;AACA;AACD;;AAEDL,EAAAA,OAAO,CAAEE,IAAF,CAAP,GAAkB;AACjBA,IAAAA,IADiB;AAEjBO,IAAAA,IAAI,EAAEC,cAFW;AAGjB,OAAGP;AAHc,GAAlB;AAMA,uBAAU,0BAAV,EAAsCA,QAAtC,EAAgDD,IAAhD;AAEA,SAAOC,QAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASQ,gBAAT,CAA2BT,IAA3B,EAAgE;AACtE,MAAK,CAAEF,OAAO,CAAEE,IAAF,CAAd,EAAyB;AACxBE,IAAAA,OAAO,CAACC,KAAR,CAAe,aAAaH,IAAb,GAAoB,sBAAnC;AACA;AACA;;AACD,QAAMU,SAAS,GAAGZ,OAAO,CAAEE,IAAF,CAAzB;AACA,SAAOF,OAAO,CAAEE,IAAF,CAAd;AAEA,uBAAU,4BAAV,EAAwCU,SAAxC,EAAmDV,IAAnD;AAEA,SAAOU,SAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,SAAT,CAAoBX,IAApB,EAAyD;AAC/D,SAAOF,OAAO,CAAEE,IAAF,CAAd;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASY,UAAT,CAAqBN,KAArB,EAAkD;AACxD,SAAOO,MAAM,CAACC,MAAP,CAAehB,OAAf,EAAyBiB,MAAzB,CACJC,MAAF,IAAcA,MAAM,CAACV,KAAP,KAAiBA,KADzB,CAAP;AAGA","sourcesContent":["/* eslint no-console: [ 'error', { allow: [ 'error' ] } ] */\n\n/**\n * WordPress dependencies\n */\nimport { applyFilters, doAction } from '@wordpress/hooks';\nimport { plugins as pluginsIcon } from '@wordpress/icons';\nimport type { IconType } from '@wordpress/components';\nimport type { WPComponent } from '@wordpress/element';\n\n/**\n * Defined behavior of a plugin type.\n */\nexport interface WPPlugin {\n\t/**\n\t * A string identifying the plugin. Must be unique across all registered plugins.\n\t */\n\tname: string;\n\n\t/**\n\t * An icon to be shown in the UI. It can be a slug of the Dashicon, or an\n\t * element (or function returning an element) if you choose to render your\n\t * own SVG.\n\t */\n\ticon?: IconType;\n\n\t/**\n\t * A component containing the UI elements to be rendered.\n\t */\n\trender: WPComponent;\n\n\t/**\n\t * The optional scope to be used when rendering inside a plugin area.\n\t * No scope by default.\n\t */\n\tscope?: string;\n}\n\ntype PluginSettings = Omit< WPPlugin, 'name' >;\n\n/**\n * Plugin definitions keyed by plugin name.\n */\nconst plugins = {} as Record< string, WPPlugin >;\n\n/**\n * Registers a plugin to the editor.\n *\n * @param name A string identifying the plugin. Must be\n * unique across all registered plugins.\n * @param settings The settings for this plugin.\n *\n * @example\n * ```js\n * // Using ES5 syntax\n * var el = wp.element.createElement;\n * var Fragment = wp.element.Fragment;\n * var PluginSidebar = wp.editPost.PluginSidebar;\n * var PluginSidebarMoreMenuItem = wp.editPost.PluginSidebarMoreMenuItem;\n * var registerPlugin = wp.plugins.registerPlugin;\n * var moreIcon = wp.element.createElement( 'svg' ); //... svg element.\n *\n * function Component() {\n * \treturn el(\n * \t\tFragment,\n * \t\t{},\n * \t\tel(\n * \t\t\tPluginSidebarMoreMenuItem,\n * \t\t\t{\n * \t\t\t\ttarget: 'sidebar-name',\n * \t\t\t},\n * \t\t\t'My Sidebar'\n * \t\t),\n * \t\tel(\n * \t\t\tPluginSidebar,\n * \t\t\t{\n * \t\t\t\tname: 'sidebar-name',\n * \t\t\t\ttitle: 'My Sidebar',\n * \t\t\t},\n * \t\t\t'Content of the sidebar'\n * \t\t)\n * \t);\n * }\n * registerPlugin( 'plugin-name', {\n * \ticon: moreIcon,\n * \trender: Component,\n * \tscope: 'my-page',\n * } );\n * ```\n *\n * @example\n * ```js\n * // Using ESNext syntax\n * import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/edit-post';\n * import { registerPlugin } from '@wordpress/plugins';\n * import { more } from '@wordpress/icons';\n *\n * const Component = () => (\n * \t<>\n * \t\t<PluginSidebarMoreMenuItem\n * \t\t\ttarget=\"sidebar-name\"\n * \t\t>\n * \t\t\tMy Sidebar\n * \t\t</PluginSidebarMoreMenuItem>\n * \t\t<PluginSidebar\n * \t\t\tname=\"sidebar-name\"\n * \t\t\ttitle=\"My Sidebar\"\n * \t\t>\n * \t\t\tContent of the sidebar\n * \t\t</PluginSidebar>\n * \t</>\n * );\n *\n * registerPlugin( 'plugin-name', {\n * \ticon: more,\n * \trender: Component,\n * \tscope: 'my-page',\n * } );\n * ```\n *\n * @return The final plugin settings object.\n */\nexport function registerPlugin(\n\tname: string,\n\tsettings: PluginSettings\n): PluginSettings | null {\n\tif ( typeof settings !== 'object' ) {\n\t\tconsole.error( 'No settings object provided!' );\n\t\treturn null;\n\t}\n\tif ( typeof name !== 'string' ) {\n\t\tconsole.error( 'Plugin name must be string.' );\n\t\treturn null;\n\t}\n\tif ( ! /^[a-z][a-z0-9-]*$/.test( name ) ) {\n\t\tconsole.error(\n\t\t\t'Plugin name must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: \"my-plugin\".'\n\t\t);\n\t\treturn null;\n\t}\n\tif ( plugins[ name ] ) {\n\t\tconsole.error( `Plugin \"${ name }\" is already registered.` );\n\t}\n\n\tsettings = applyFilters(\n\t\t'plugins.registerPlugin',\n\t\tsettings,\n\t\tname\n\t) as PluginSettings;\n\n\tconst { render, scope } = settings;\n\n\tif ( typeof render !== 'function' ) {\n\t\tconsole.error(\n\t\t\t'The \"render\" property must be specified and must be a valid function.'\n\t\t);\n\t\treturn null;\n\t}\n\n\tif ( scope ) {\n\t\tif ( typeof scope !== 'string' ) {\n\t\t\tconsole.error( 'Plugin scope must be string.' );\n\t\t\treturn null;\n\t\t}\n\n\t\tif ( ! /^[a-z][a-z0-9-]*$/.test( scope ) ) {\n\t\t\tconsole.error(\n\t\t\t\t'Plugin scope must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: \"my-page\".'\n\t\t\t);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tplugins[ name ] = {\n\t\tname,\n\t\ticon: pluginsIcon,\n\t\t...settings,\n\t};\n\n\tdoAction( 'plugins.pluginRegistered', settings, name );\n\n\treturn settings;\n}\n\n/**\n * Unregisters a plugin by name.\n *\n * @param name Plugin name.\n *\n * @example\n * ```js\n * // Using ES5 syntax\n * var unregisterPlugin = wp.plugins.unregisterPlugin;\n *\n * unregisterPlugin( 'plugin-name' );\n * ```\n *\n * @example\n * ```js\n * // Using ESNext syntax\n * import { unregisterPlugin } from '@wordpress/plugins';\n *\n * unregisterPlugin( 'plugin-name' );\n * ```\n *\n * @return The previous plugin settings object, if it has been\n * successfully unregistered; otherwise `undefined`.\n */\nexport function unregisterPlugin( name: string ): WPPlugin | undefined {\n\tif ( ! plugins[ name ] ) {\n\t\tconsole.error( 'Plugin \"' + name + '\" is not registered.' );\n\t\treturn;\n\t}\n\tconst oldPlugin = plugins[ name ];\n\tdelete plugins[ name ];\n\n\tdoAction( 'plugins.pluginUnregistered', oldPlugin, name );\n\n\treturn oldPlugin;\n}\n\n/**\n * Returns a registered plugin settings.\n *\n * @param name Plugin name.\n *\n * @return Plugin setting.\n */\nexport function getPlugin( name: string ): WPPlugin | undefined {\n\treturn plugins[ name ];\n}\n\n/**\n * Returns all registered plugins without a scope or for a given scope.\n *\n * @param scope The scope to be used when rendering inside\n * a plugin area. No scope by default.\n *\n * @return The list of plugins without a scope or for a given scope.\n */\nexport function getPlugins( scope?: string ): WPPlugin[] {\n\treturn Object.values( plugins ).filter(\n\t\t( plugin ) => plugin.scope === scope\n\t);\n}\n"]}
|
|
@@ -39,9 +39,9 @@ const getPluginContext = (0, _memize.default)((icon, name) => ({
|
|
|
39
39
|
/**
|
|
40
40
|
* A component that renders all plugin fills in a hidden div.
|
|
41
41
|
*
|
|
42
|
-
* @param
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
42
|
+
* @param props
|
|
43
|
+
* @param props.scope
|
|
44
|
+
* @param props.onError
|
|
45
45
|
* @example
|
|
46
46
|
* ```js
|
|
47
47
|
* // Using ES5 syntax
|
|
@@ -80,7 +80,7 @@ function PluginArea(_ref) {
|
|
|
80
80
|
onError
|
|
81
81
|
} = _ref;
|
|
82
82
|
const store = (0, _element.useMemo)(() => {
|
|
83
|
-
let lastValue;
|
|
83
|
+
let lastValue = [];
|
|
84
84
|
return {
|
|
85
85
|
subscribe(listener) {
|
|
86
86
|
(0, _hooks.addAction)('plugins.pluginRegistered', 'core/plugins/plugin-area/plugins-registered', listener);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-area/index.
|
|
1
|
+
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-area/index.tsx"],"names":["getPluginContext","icon","name","PluginArea","scope","onError","store","lastValue","subscribe","listener","getValue","nextValue","plugins","display","map","render","Plugin"],"mappings":";;;;;;;;;AAQA;;AALA;;AAMA;;AACA;;AAKA;;AACA;;AACA;;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;AAOA,MAAMA,gBAAgB,GAAG,qBACxB,CAAEC,IAAF,EAAiCC,IAAjC,MAAsE;AACrED,EAAAA,IADqE;AAErEC,EAAAA;AAFqE,CAAtE,CADwB,CAAzB;AAOA;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,UAAT,OAMI;AAAA,MANiB;AACpBC,IAAAA,KADoB;AAEpBC,IAAAA;AAFoB,GAMjB;AACH,QAAMC,KAAK,GAAG,sBAAS,MAAM;AAC5B,QAAIC,SAAqB,GAAG,EAA5B;AAEA,WAAO;AACNC,MAAAA,SAAS,CACRC,QADQ,EAKP;AACD,8BACC,0BADD,EAEC,6CAFD,EAGCA,QAHD;AAKA,8BACC,4BADD,EAEC,+CAFD,EAGCA,QAHD;AAKA,eAAO,MAAM;AACZ,mCACC,0BADD,EAEC,6CAFD;AAIA,mCACC,4BADD,EAEC,+CAFD;AAIA,SATD;AAUA,OA3BK;;AA4BNC,MAAAA,QAAQ,GAAG;AACV,cAAMC,SAAS,GAAG,qBAAYP,KAAZ,CAAlB;;AAEA,YAAK,CAAE,6BAAgBG,SAAhB,EAA2BI,SAA3B,CAAP,EAAgD;AAC/CJ,UAAAA,SAAS,GAAGI,SAAZ;AACA;;AAED,eAAOJ,SAAP;AACA;;AApCK,KAAP;AAsCA,GAzCa,EAyCX,CAAEH,KAAF,CAzCW,CAAd;AA2CA,QAAMQ,OAAO,GAAG,mCAAsBN,KAAK,CAACE,SAA5B,EAAuCF,KAAK,CAACI,QAA7C,CAAhB;AAEA,SACC;AAAK,IAAA,KAAK,EAAG;AAAEG,MAAAA,OAAO,EAAE;AAAX;AAAb,KACGD,OAAO,CAACE,GAAR,CAAa;AAAA,QAAE;AAAEb,MAAAA,IAAF;AAAQC,MAAAA,IAAR;AAAca,MAAAA,MAAM,EAAEC;AAAtB,KAAF;AAAA,WACd,4BAAC,oCAAD;AACC,MAAA,GAAG,EAAGd,IADP;AAEC,MAAA,KAAK,EAAGF,gBAAgB,CAAEC,IAAF,EAAQC,IAAR;AAFzB,OAIC,4BAAC,wCAAD;AAAqB,MAAA,IAAI,EAAGA,IAA5B;AAAmC,MAAA,OAAO,EAAGG;AAA7C,OACC,4BAAC,MAAD,OADD,CAJD,CADc;AAAA,GAAb,CADH,CADD;AAcA;;eAEcF,U","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"]}
|
|
@@ -29,9 +29,9 @@ exports.PluginContextProvider = Provider;
|
|
|
29
29
|
* A Higher Order Component used to inject Plugin context to the
|
|
30
30
|
* wrapped component.
|
|
31
31
|
*
|
|
32
|
-
* @param
|
|
33
|
-
*
|
|
34
|
-
*
|
|
32
|
+
* @param mapContextToProps Function called on every context change,
|
|
33
|
+
* expected to return object of props to
|
|
34
|
+
* merge with the component's own props.
|
|
35
35
|
*
|
|
36
36
|
* @return {WPComponent} Enhanced component with injected context as props.
|
|
37
37
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-context/index.
|
|
1
|
+
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-context/index.tsx"],"names":["Consumer","Provider","name","icon","withPluginContext","mapContextToProps","OriginalComponent","props","context"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AAJA;AACA;AACA;AAcA,MAAM;AAAEA,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,IAAyB,4BAAgC;AAC9DC,EAAAA,IAAI,EAAE,IADwD;AAE9DC,EAAAA,IAAI,EAAE;AAFwD,CAAhC,CAA/B;;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,iBAAiB,GAC7BC,iBADgC,IAMhC,yCAA8BC,iBAAF,IAAyB;AACpD,SAASC,KAAF,IACN,4BAAC,QAAD,QACKC,OAAF,IACD,4BAAC,iBAAD,6BACMD,KADN,EAEMF,iBAAiB,CAAEG,OAAF,EAAWD,KAAX,CAFvB,EAFF,CADD;AAUA,CAXD,EAWG,mBAXH,CANM","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext } 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 { Consumer, Provider } = createContext< PluginContext >( {\n\tname: null,\n\ticon: null,\n} );\n\nexport { Provider as PluginContextProvider };\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<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</Consumer>\n\t\t);\n\t}, 'withPluginContext' );\n"]}
|
|
@@ -11,6 +11,9 @@ var _element = require("@wordpress/element");
|
|
|
11
11
|
* WordPress dependencies
|
|
12
12
|
*/
|
|
13
13
|
class PluginErrorBoundary extends _element.Component {
|
|
14
|
+
/**
|
|
15
|
+
* @param {Object} props
|
|
16
|
+
*/
|
|
14
17
|
constructor(props) {
|
|
15
18
|
super(props);
|
|
16
19
|
this.state = {
|
|
@@ -23,6 +26,10 @@ class PluginErrorBoundary extends _element.Component {
|
|
|
23
26
|
hasError: true
|
|
24
27
|
};
|
|
25
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* @param {Error} error Error object passed by React.
|
|
31
|
+
*/
|
|
32
|
+
|
|
26
33
|
|
|
27
34
|
componentDidCatch(error) {
|
|
28
35
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-error-boundary/index.js"],"names":["PluginErrorBoundary","Component","constructor","props","state","hasError","getDerivedStateFromError","componentDidCatch","error","name","onError","render","children"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;AAGO,MAAMA,mBAAN,SAAkCC,kBAAlC,CAA4C;
|
|
1
|
+
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-error-boundary/index.js"],"names":["PluginErrorBoundary","Component","constructor","props","state","hasError","getDerivedStateFromError","componentDidCatch","error","name","onError","render","children"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;AAGO,MAAMA,mBAAN,SAAkCC,kBAAlC,CAA4C;AAClD;AACD;AACA;AACCC,EAAAA,WAAW,CAAEC,KAAF,EAAU;AACpB,UAAOA,KAAP;AACA,SAAKC,KAAL,GAAa;AACZC,MAAAA,QAAQ,EAAE;AADE,KAAb;AAGA;;AAE8B,SAAxBC,wBAAwB,GAAG;AACjC,WAAO;AAAED,MAAAA,QAAQ,EAAE;AAAZ,KAAP;AACA;AAED;AACD;AACA;;;AACCE,EAAAA,iBAAiB,CAAEC,KAAF,EAAU;AAC1B,UAAM;AAAEC,MAAAA,IAAF;AAAQC,MAAAA;AAAR,QAAoB,KAAKP,KAA/B;;AACA,QAAKO,OAAL,EAAe;AACdA,MAAAA,OAAO,CAAED,IAAF,EAAQD,KAAR,CAAP;AACA;AACD;;AAEDG,EAAAA,MAAM,GAAG;AACR,QAAK,CAAE,KAAKP,KAAL,CAAWC,QAAlB,EAA6B;AAC5B,aAAO,KAAKF,KAAL,CAAWS,QAAlB;AACA;;AAED,WAAO,IAAP;AACA;;AA/BiD","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"]}
|
|
@@ -5,36 +5,17 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { applyFilters, doAction } from '@wordpress/hooks';
|
|
7
7
|
import { plugins as pluginsIcon } from '@wordpress/icons';
|
|
8
|
-
/**
|
|
9
|
-
* Defined behavior of a plugin type.
|
|
10
|
-
*
|
|
11
|
-
* @typedef {Object} WPPlugin
|
|
12
|
-
*
|
|
13
|
-
* @property {string} name A string identifying the plugin. Must be
|
|
14
|
-
* unique across all registered plugins.
|
|
15
|
-
* @property {string|WPElement|Function} [icon] An icon to be shown in the UI. It can
|
|
16
|
-
* be a slug of the Dashicon, or an element
|
|
17
|
-
* (or function returning an element) if you
|
|
18
|
-
* choose to render your own SVG.
|
|
19
|
-
* @property {Function} render A component containing the UI elements
|
|
20
|
-
* to be rendered.
|
|
21
|
-
* @property {string} [scope] The optional scope to be used when rendering inside
|
|
22
|
-
* a plugin area. No scope by default.
|
|
23
|
-
*/
|
|
24
8
|
|
|
25
9
|
/**
|
|
26
10
|
* Plugin definitions keyed by plugin name.
|
|
27
|
-
*
|
|
28
|
-
* @type {Object.<string,WPPlugin>}
|
|
29
11
|
*/
|
|
30
|
-
|
|
31
12
|
const plugins = {};
|
|
32
13
|
/**
|
|
33
14
|
* Registers a plugin to the editor.
|
|
34
15
|
*
|
|
35
|
-
* @param
|
|
36
|
-
*
|
|
37
|
-
* @param
|
|
16
|
+
* @param name A string identifying the plugin. Must be
|
|
17
|
+
* unique across all registered plugins.
|
|
18
|
+
* @param settings The settings for this plugin.
|
|
38
19
|
*
|
|
39
20
|
* @example
|
|
40
21
|
* ```js
|
|
@@ -104,7 +85,7 @@ const plugins = {};
|
|
|
104
85
|
* } );
|
|
105
86
|
* ```
|
|
106
87
|
*
|
|
107
|
-
* @return
|
|
88
|
+
* @return The final plugin settings object.
|
|
108
89
|
*/
|
|
109
90
|
|
|
110
91
|
export function registerPlugin(name, settings) {
|
|
@@ -161,7 +142,7 @@ export function registerPlugin(name, settings) {
|
|
|
161
142
|
/**
|
|
162
143
|
* Unregisters a plugin by name.
|
|
163
144
|
*
|
|
164
|
-
* @param
|
|
145
|
+
* @param name Plugin name.
|
|
165
146
|
*
|
|
166
147
|
* @example
|
|
167
148
|
* ```js
|
|
@@ -179,8 +160,8 @@ export function registerPlugin(name, settings) {
|
|
|
179
160
|
* unregisterPlugin( 'plugin-name' );
|
|
180
161
|
* ```
|
|
181
162
|
*
|
|
182
|
-
* @return
|
|
183
|
-
*
|
|
163
|
+
* @return The previous plugin settings object, if it has been
|
|
164
|
+
* successfully unregistered; otherwise `undefined`.
|
|
184
165
|
*/
|
|
185
166
|
|
|
186
167
|
export function unregisterPlugin(name) {
|
|
@@ -197,9 +178,9 @@ export function unregisterPlugin(name) {
|
|
|
197
178
|
/**
|
|
198
179
|
* Returns a registered plugin settings.
|
|
199
180
|
*
|
|
200
|
-
* @param
|
|
181
|
+
* @param name Plugin name.
|
|
201
182
|
*
|
|
202
|
-
* @return
|
|
183
|
+
* @return Plugin setting.
|
|
203
184
|
*/
|
|
204
185
|
|
|
205
186
|
export function getPlugin(name) {
|
|
@@ -208,10 +189,10 @@ export function getPlugin(name) {
|
|
|
208
189
|
/**
|
|
209
190
|
* Returns all registered plugins without a scope or for a given scope.
|
|
210
191
|
*
|
|
211
|
-
* @param
|
|
212
|
-
*
|
|
192
|
+
* @param scope The scope to be used when rendering inside
|
|
193
|
+
* a plugin area. No scope by default.
|
|
213
194
|
*
|
|
214
|
-
* @return
|
|
195
|
+
* @return The list of plugins without a scope or for a given scope.
|
|
215
196
|
*/
|
|
216
197
|
|
|
217
198
|
export function getPlugins(scope) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/plugins/src/api/index.
|
|
1
|
+
{"version":3,"sources":["@wordpress/plugins/src/api/index.ts"],"names":["applyFilters","doAction","plugins","pluginsIcon","registerPlugin","name","settings","console","error","test","render","scope","icon","unregisterPlugin","oldPlugin","getPlugin","getPlugins","Object","values","filter","plugin"],"mappings":"AAAA;;AAEA;AACA;AACA;AACA,SAASA,YAAT,EAAuBC,QAAvB,QAAuC,kBAAvC;AACA,SAASC,OAAO,IAAIC,WAApB,QAAuC,kBAAvC;;AAkCA;AACA;AACA;AACA,MAAMD,OAAO,GAAG,EAAhB;AAEA;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;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;AACA;AACA;;AACA,OAAO,SAASE,cAAT,CACNC,IADM,EAENC,QAFM,EAGkB;AACxB,MAAK,OAAOA,QAAP,KAAoB,QAAzB,EAAoC;AACnCC,IAAAA,OAAO,CAACC,KAAR,CAAe,8BAAf;AACA,WAAO,IAAP;AACA;;AACD,MAAK,OAAOH,IAAP,KAAgB,QAArB,EAAgC;AAC/BE,IAAAA,OAAO,CAACC,KAAR,CAAe,6BAAf;AACA,WAAO,IAAP;AACA;;AACD,MAAK,CAAE,oBAAoBC,IAApB,CAA0BJ,IAA1B,CAAP,EAA0C;AACzCE,IAAAA,OAAO,CAACC,KAAR,CACC,2HADD;AAGA,WAAO,IAAP;AACA;;AACD,MAAKN,OAAO,CAAEG,IAAF,CAAZ,EAAuB;AACtBE,IAAAA,OAAO,CAACC,KAAR,CAAgB,WAAWH,IAAM,0BAAjC;AACA;;AAEDC,EAAAA,QAAQ,GAAGN,YAAY,CACtB,wBADsB,EAEtBM,QAFsB,EAGtBD,IAHsB,CAAvB;AAMA,QAAM;AAAEK,IAAAA,MAAF;AAAUC,IAAAA;AAAV,MAAoBL,QAA1B;;AAEA,MAAK,OAAOI,MAAP,KAAkB,UAAvB,EAAoC;AACnCH,IAAAA,OAAO,CAACC,KAAR,CACC,uEADD;AAGA,WAAO,IAAP;AACA;;AAED,MAAKG,KAAL,EAAa;AACZ,QAAK,OAAOA,KAAP,KAAiB,QAAtB,EAAiC;AAChCJ,MAAAA,OAAO,CAACC,KAAR,CAAe,8BAAf;AACA,aAAO,IAAP;AACA;;AAED,QAAK,CAAE,oBAAoBC,IAApB,CAA0BE,KAA1B,CAAP,EAA2C;AAC1CJ,MAAAA,OAAO,CAACC,KAAR,CACC,0HADD;AAGA,aAAO,IAAP;AACA;AACD;;AAEDN,EAAAA,OAAO,CAAEG,IAAF,CAAP,GAAkB;AACjBA,IAAAA,IADiB;AAEjBO,IAAAA,IAAI,EAAET,WAFW;AAGjB,OAAGG;AAHc,GAAlB;AAMAL,EAAAA,QAAQ,CAAE,0BAAF,EAA8BK,QAA9B,EAAwCD,IAAxC,CAAR;AAEA,SAAOC,QAAP;AACA;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,OAAO,SAASO,gBAAT,CAA2BR,IAA3B,EAAgE;AACtE,MAAK,CAAEH,OAAO,CAAEG,IAAF,CAAd,EAAyB;AACxBE,IAAAA,OAAO,CAACC,KAAR,CAAe,aAAaH,IAAb,GAAoB,sBAAnC;AACA;AACA;;AACD,QAAMS,SAAS,GAAGZ,OAAO,CAAEG,IAAF,CAAzB;AACA,SAAOH,OAAO,CAAEG,IAAF,CAAd;AAEAJ,EAAAA,QAAQ,CAAE,4BAAF,EAAgCa,SAAhC,EAA2CT,IAA3C,CAAR;AAEA,SAAOS,SAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,SAAT,CAAoBV,IAApB,EAAyD;AAC/D,SAAOH,OAAO,CAAEG,IAAF,CAAd;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASW,UAAT,CAAqBL,KAArB,EAAkD;AACxD,SAAOM,MAAM,CAACC,MAAP,CAAehB,OAAf,EAAyBiB,MAAzB,CACJC,MAAF,IAAcA,MAAM,CAACT,KAAP,KAAiBA,KADzB,CAAP;AAGA","sourcesContent":["/* eslint no-console: [ 'error', { allow: [ 'error' ] } ] */\n\n/**\n * WordPress dependencies\n */\nimport { applyFilters, doAction } from '@wordpress/hooks';\nimport { plugins as pluginsIcon } from '@wordpress/icons';\nimport type { IconType } from '@wordpress/components';\nimport type { WPComponent } from '@wordpress/element';\n\n/**\n * Defined behavior of a plugin type.\n */\nexport interface WPPlugin {\n\t/**\n\t * A string identifying the plugin. Must be unique across all registered plugins.\n\t */\n\tname: string;\n\n\t/**\n\t * An icon to be shown in the UI. It can be a slug of the Dashicon, or an\n\t * element (or function returning an element) if you choose to render your\n\t * own SVG.\n\t */\n\ticon?: IconType;\n\n\t/**\n\t * A component containing the UI elements to be rendered.\n\t */\n\trender: WPComponent;\n\n\t/**\n\t * The optional scope to be used when rendering inside a plugin area.\n\t * No scope by default.\n\t */\n\tscope?: string;\n}\n\ntype PluginSettings = Omit< WPPlugin, 'name' >;\n\n/**\n * Plugin definitions keyed by plugin name.\n */\nconst plugins = {} as Record< string, WPPlugin >;\n\n/**\n * Registers a plugin to the editor.\n *\n * @param name A string identifying the plugin. Must be\n * unique across all registered plugins.\n * @param settings The settings for this plugin.\n *\n * @example\n * ```js\n * // Using ES5 syntax\n * var el = wp.element.createElement;\n * var Fragment = wp.element.Fragment;\n * var PluginSidebar = wp.editPost.PluginSidebar;\n * var PluginSidebarMoreMenuItem = wp.editPost.PluginSidebarMoreMenuItem;\n * var registerPlugin = wp.plugins.registerPlugin;\n * var moreIcon = wp.element.createElement( 'svg' ); //... svg element.\n *\n * function Component() {\n * \treturn el(\n * \t\tFragment,\n * \t\t{},\n * \t\tel(\n * \t\t\tPluginSidebarMoreMenuItem,\n * \t\t\t{\n * \t\t\t\ttarget: 'sidebar-name',\n * \t\t\t},\n * \t\t\t'My Sidebar'\n * \t\t),\n * \t\tel(\n * \t\t\tPluginSidebar,\n * \t\t\t{\n * \t\t\t\tname: 'sidebar-name',\n * \t\t\t\ttitle: 'My Sidebar',\n * \t\t\t},\n * \t\t\t'Content of the sidebar'\n * \t\t)\n * \t);\n * }\n * registerPlugin( 'plugin-name', {\n * \ticon: moreIcon,\n * \trender: Component,\n * \tscope: 'my-page',\n * } );\n * ```\n *\n * @example\n * ```js\n * // Using ESNext syntax\n * import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/edit-post';\n * import { registerPlugin } from '@wordpress/plugins';\n * import { more } from '@wordpress/icons';\n *\n * const Component = () => (\n * \t<>\n * \t\t<PluginSidebarMoreMenuItem\n * \t\t\ttarget=\"sidebar-name\"\n * \t\t>\n * \t\t\tMy Sidebar\n * \t\t</PluginSidebarMoreMenuItem>\n * \t\t<PluginSidebar\n * \t\t\tname=\"sidebar-name\"\n * \t\t\ttitle=\"My Sidebar\"\n * \t\t>\n * \t\t\tContent of the sidebar\n * \t\t</PluginSidebar>\n * \t</>\n * );\n *\n * registerPlugin( 'plugin-name', {\n * \ticon: more,\n * \trender: Component,\n * \tscope: 'my-page',\n * } );\n * ```\n *\n * @return The final plugin settings object.\n */\nexport function registerPlugin(\n\tname: string,\n\tsettings: PluginSettings\n): PluginSettings | null {\n\tif ( typeof settings !== 'object' ) {\n\t\tconsole.error( 'No settings object provided!' );\n\t\treturn null;\n\t}\n\tif ( typeof name !== 'string' ) {\n\t\tconsole.error( 'Plugin name must be string.' );\n\t\treturn null;\n\t}\n\tif ( ! /^[a-z][a-z0-9-]*$/.test( name ) ) {\n\t\tconsole.error(\n\t\t\t'Plugin name must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: \"my-plugin\".'\n\t\t);\n\t\treturn null;\n\t}\n\tif ( plugins[ name ] ) {\n\t\tconsole.error( `Plugin \"${ name }\" is already registered.` );\n\t}\n\n\tsettings = applyFilters(\n\t\t'plugins.registerPlugin',\n\t\tsettings,\n\t\tname\n\t) as PluginSettings;\n\n\tconst { render, scope } = settings;\n\n\tif ( typeof render !== 'function' ) {\n\t\tconsole.error(\n\t\t\t'The \"render\" property must be specified and must be a valid function.'\n\t\t);\n\t\treturn null;\n\t}\n\n\tif ( scope ) {\n\t\tif ( typeof scope !== 'string' ) {\n\t\t\tconsole.error( 'Plugin scope must be string.' );\n\t\t\treturn null;\n\t\t}\n\n\t\tif ( ! /^[a-z][a-z0-9-]*$/.test( scope ) ) {\n\t\t\tconsole.error(\n\t\t\t\t'Plugin scope must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: \"my-page\".'\n\t\t\t);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tplugins[ name ] = {\n\t\tname,\n\t\ticon: pluginsIcon,\n\t\t...settings,\n\t};\n\n\tdoAction( 'plugins.pluginRegistered', settings, name );\n\n\treturn settings;\n}\n\n/**\n * Unregisters a plugin by name.\n *\n * @param name Plugin name.\n *\n * @example\n * ```js\n * // Using ES5 syntax\n * var unregisterPlugin = wp.plugins.unregisterPlugin;\n *\n * unregisterPlugin( 'plugin-name' );\n * ```\n *\n * @example\n * ```js\n * // Using ESNext syntax\n * import { unregisterPlugin } from '@wordpress/plugins';\n *\n * unregisterPlugin( 'plugin-name' );\n * ```\n *\n * @return The previous plugin settings object, if it has been\n * successfully unregistered; otherwise `undefined`.\n */\nexport function unregisterPlugin( name: string ): WPPlugin | undefined {\n\tif ( ! plugins[ name ] ) {\n\t\tconsole.error( 'Plugin \"' + name + '\" is not registered.' );\n\t\treturn;\n\t}\n\tconst oldPlugin = plugins[ name ];\n\tdelete plugins[ name ];\n\n\tdoAction( 'plugins.pluginUnregistered', oldPlugin, name );\n\n\treturn oldPlugin;\n}\n\n/**\n * Returns a registered plugin settings.\n *\n * @param name Plugin name.\n *\n * @return Plugin setting.\n */\nexport function getPlugin( name: string ): WPPlugin | undefined {\n\treturn plugins[ name ];\n}\n\n/**\n * Returns all registered plugins without a scope or for a given scope.\n *\n * @param scope The scope to be used when rendering inside\n * a plugin area. No scope by default.\n *\n * @return The list of plugins without a scope or for a given scope.\n */\nexport function getPlugins( scope?: string ): WPPlugin[] {\n\treturn Object.values( plugins ).filter(\n\t\t( plugin ) => plugin.scope === scope\n\t);\n}\n"]}
|
|
@@ -25,9 +25,9 @@ const getPluginContext = memoize((icon, name) => ({
|
|
|
25
25
|
/**
|
|
26
26
|
* A component that renders all plugin fills in a hidden div.
|
|
27
27
|
*
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
28
|
+
* @param props
|
|
29
|
+
* @param props.scope
|
|
30
|
+
* @param props.onError
|
|
31
31
|
* @example
|
|
32
32
|
* ```js
|
|
33
33
|
* // Using ES5 syntax
|
|
@@ -66,7 +66,7 @@ function PluginArea(_ref) {
|
|
|
66
66
|
onError
|
|
67
67
|
} = _ref;
|
|
68
68
|
const store = useMemo(() => {
|
|
69
|
-
let lastValue;
|
|
69
|
+
let lastValue = [];
|
|
70
70
|
return {
|
|
71
71
|
subscribe(listener) {
|
|
72
72
|
addAction('plugins.pluginRegistered', 'core/plugins/plugin-area/plugins-registered', listener);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-area/index.
|
|
1
|
+
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-area/index.tsx"],"names":["memoize","useMemo","useSyncExternalStore","addAction","removeAction","isShallowEqual","PluginContextProvider","PluginErrorBoundary","getPlugins","getPluginContext","icon","name","PluginArea","scope","onError","store","lastValue","subscribe","listener","getValue","nextValue","plugins","display","map","render","Plugin"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,OAAT,EAAkBC,oBAAlB,QAA8C,oBAA9C;AACA,SAASC,SAAT,EAAoBC,YAApB,QAAwC,kBAAxC;AACA,OAAOC,cAAP,MAA2B,6BAA3B;AAEA;AACA;AACA;;AACA,SAASC,qBAAT,QAAsC,mBAAtC;AACA,SAASC,mBAAT,QAAoC,0BAApC;AACA,SAASC,UAAT,QAA2B,WAA3B;AAIA,MAAMC,gBAAgB,GAAGT,OAAO,CAC/B,CAAEU,IAAF,EAAiCC,IAAjC,MAAsE;AACrED,EAAAA,IADqE;AAErEC,EAAAA;AAFqE,CAAtE,CAD+B,CAAhC;AAOA;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,UAAT,OAMI;AAAA,MANiB;AACpBC,IAAAA,KADoB;AAEpBC,IAAAA;AAFoB,GAMjB;AACH,QAAMC,KAAK,GAAGd,OAAO,CAAE,MAAM;AAC5B,QAAIe,SAAqB,GAAG,EAA5B;AAEA,WAAO;AACNC,MAAAA,SAAS,CACRC,QADQ,EAKP;AACDf,QAAAA,SAAS,CACR,0BADQ,EAER,6CAFQ,EAGRe,QAHQ,CAAT;AAKAf,QAAAA,SAAS,CACR,4BADQ,EAER,+CAFQ,EAGRe,QAHQ,CAAT;AAKA,eAAO,MAAM;AACZd,UAAAA,YAAY,CACX,0BADW,EAEX,6CAFW,CAAZ;AAIAA,UAAAA,YAAY,CACX,4BADW,EAEX,+CAFW,CAAZ;AAIA,SATD;AAUA,OA3BK;;AA4BNe,MAAAA,QAAQ,GAAG;AACV,cAAMC,SAAS,GAAGZ,UAAU,CAAEK,KAAF,CAA5B;;AAEA,YAAK,CAAER,cAAc,CAAEW,SAAF,EAAaI,SAAb,CAArB,EAAgD;AAC/CJ,UAAAA,SAAS,GAAGI,SAAZ;AACA;;AAED,eAAOJ,SAAP;AACA;;AApCK,KAAP;AAsCA,GAzCoB,EAyClB,CAAEH,KAAF,CAzCkB,CAArB;AA2CA,QAAMQ,OAAO,GAAGnB,oBAAoB,CAAEa,KAAK,CAACE,SAAR,EAAmBF,KAAK,CAACI,QAAzB,CAApC;AAEA,SACC;AAAK,IAAA,KAAK,EAAG;AAAEG,MAAAA,OAAO,EAAE;AAAX;AAAb,KACGD,OAAO,CAACE,GAAR,CAAa;AAAA,QAAE;AAAEb,MAAAA,IAAF;AAAQC,MAAAA,IAAR;AAAca,MAAAA,MAAM,EAAEC;AAAtB,KAAF;AAAA,WACd,cAAC,qBAAD;AACC,MAAA,GAAG,EAAGd,IADP;AAEC,MAAA,KAAK,EAAGF,gBAAgB,CAAEC,IAAF,EAAQC,IAAR;AAFzB,OAIC,cAAC,mBAAD;AAAqB,MAAA,IAAI,EAAGA,IAA5B;AAAmC,MAAA,OAAO,EAAGG;AAA7C,OACC,cAAC,MAAD,OADD,CAJD,CADc;AAAA,GAAb,CADH,CADD;AAcA;;AAED,eAAeF,UAAf","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"]}
|
|
@@ -6,6 +6,10 @@ import { createElement } from "@wordpress/element";
|
|
|
6
6
|
*/
|
|
7
7
|
import { createContext } from '@wordpress/element';
|
|
8
8
|
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
|
|
9
13
|
const {
|
|
10
14
|
Consumer,
|
|
11
15
|
Provider
|
|
@@ -18,9 +22,9 @@ export { Provider as PluginContextProvider };
|
|
|
18
22
|
* A Higher Order Component used to inject Plugin context to the
|
|
19
23
|
* wrapped component.
|
|
20
24
|
*
|
|
21
|
-
* @param
|
|
22
|
-
*
|
|
23
|
-
*
|
|
25
|
+
* @param mapContextToProps Function called on every context change,
|
|
26
|
+
* expected to return object of props to
|
|
27
|
+
* merge with the component's own props.
|
|
24
28
|
*
|
|
25
29
|
* @return {WPComponent} Enhanced component with injected context as props.
|
|
26
30
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-context/index.
|
|
1
|
+
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-context/index.tsx"],"names":["createContext","createHigherOrderComponent","Consumer","Provider","name","icon","PluginContextProvider","withPluginContext","mapContextToProps","OriginalComponent","props","context"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,aAAT,QAA8B,oBAA9B;AACA,SAASC,0BAAT,QAA2C,oBAA3C;AAEA;AACA;AACA;;AAQA,MAAM;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,IAAyBH,aAAa,CAAmB;AAC9DI,EAAAA,IAAI,EAAE,IADwD;AAE9DC,EAAAA,IAAI,EAAE;AAFwD,CAAnB,CAA5C;AAKA,SAASF,QAAQ,IAAIG,qBAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,iBAAiB,GAC7BC,iBADgC,IAMhCP,0BAA0B,CAAIQ,iBAAF,IAAyB;AACpD,SAASC,KAAF,IACN,cAAC,QAAD,QACKC,OAAF,IACD,cAAC,iBAAD,eACMD,KADN,EAEMF,iBAAiB,CAAEG,OAAF,EAAWD,KAAX,CAFvB,EAFF,CADD;AAUA,CAXyB,EAWvB,mBAXuB,CANpB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext } 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 { Consumer, Provider } = createContext< PluginContext >( {\n\tname: null,\n\ticon: null,\n} );\n\nexport { Provider as PluginContextProvider };\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<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</Consumer>\n\t\t);\n\t}, 'withPluginContext' );\n"]}
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Component } from '@wordpress/element';
|
|
5
5
|
export class PluginErrorBoundary extends Component {
|
|
6
|
+
/**
|
|
7
|
+
* @param {Object} props
|
|
8
|
+
*/
|
|
6
9
|
constructor(props) {
|
|
7
10
|
super(props);
|
|
8
11
|
this.state = {
|
|
@@ -15,6 +18,10 @@ export class PluginErrorBoundary extends Component {
|
|
|
15
18
|
hasError: true
|
|
16
19
|
};
|
|
17
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @param {Error} error Error object passed by React.
|
|
23
|
+
*/
|
|
24
|
+
|
|
18
25
|
|
|
19
26
|
componentDidCatch(error) {
|
|
20
27
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-error-boundary/index.js"],"names":["Component","PluginErrorBoundary","constructor","props","state","hasError","getDerivedStateFromError","componentDidCatch","error","name","onError","render","children"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,oBAA1B;AAEA,OAAO,MAAMC,mBAAN,SAAkCD,SAAlC,CAA4C;
|
|
1
|
+
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-error-boundary/index.js"],"names":["Component","PluginErrorBoundary","constructor","props","state","hasError","getDerivedStateFromError","componentDidCatch","error","name","onError","render","children"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,oBAA1B;AAEA,OAAO,MAAMC,mBAAN,SAAkCD,SAAlC,CAA4C;AAClD;AACD;AACA;AACCE,EAAAA,WAAW,CAAEC,KAAF,EAAU;AACpB,UAAOA,KAAP;AACA,SAAKC,KAAL,GAAa;AACZC,MAAAA,QAAQ,EAAE;AADE,KAAb;AAGA;;AAE8B,SAAxBC,wBAAwB,GAAG;AACjC,WAAO;AAAED,MAAAA,QAAQ,EAAE;AAAZ,KAAP;AACA;AAED;AACD;AACA;;;AACCE,EAAAA,iBAAiB,CAAEC,KAAF,EAAU;AAC1B,UAAM;AAAEC,MAAAA,IAAF;AAAQC,MAAAA;AAAR,QAAoB,KAAKP,KAA/B;;AACA,QAAKO,OAAL,EAAe;AACdA,MAAAA,OAAO,CAAED,IAAF,EAAQD,KAAR,CAAP;AACA;AACD;;AAEDG,EAAAA,MAAM,GAAG;AACR,QAAK,CAAE,KAAKP,KAAL,CAAWC,QAAlB,EAA6B;AAC5B,aAAO,KAAKF,KAAL,CAAWS,QAAlB;AACA;;AAED,WAAO,IAAP;AACA;;AA/BiD","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"]}
|