@wordpress/plugins 4.1.0 → 4.1.2
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/README.md +7 -1
- package/build/components/plugin-area/index.js +6 -1
- package/build/components/plugin-area/index.js.map +1 -1
- package/build/components/plugin-error-boundary/index.js +49 -0
- package/build/components/plugin-error-boundary/index.js.map +1 -0
- package/build-module/components/plugin-area/index.js +5 -1
- package/build-module/components/plugin-area/index.js.map +1 -1
- package/build-module/components/plugin-error-boundary/index.js +39 -0
- package/build-module/components/plugin-error-boundary/index.js.map +1 -0
- package/package.json +6 -6
- package/src/components/plugin-area/index.js +7 -1
- package/src/components/plugin-error-boundary/index.js +32 -0
package/README.md
CHANGED
|
@@ -191,4 +191,10 @@ _Returns_
|
|
|
191
191
|
|
|
192
192
|
<!-- END TOKEN(Autogenerated API docs) -->
|
|
193
193
|
|
|
194
|
-
|
|
194
|
+
## Contributing to this package
|
|
195
|
+
|
|
196
|
+
This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.
|
|
197
|
+
|
|
198
|
+
To find out more about contributing to this package or Gutenberg as a whole, please read the project's main [contributor guide](https://github.com/WordPress/gutenberg/tree/HEAD/CONTRIBUTING.md).
|
|
199
|
+
|
|
200
|
+
<br /><br /><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
|
|
@@ -17,6 +17,8 @@ var _hooks = require("@wordpress/hooks");
|
|
|
17
17
|
|
|
18
18
|
var _pluginContext = require("../plugin-context");
|
|
19
19
|
|
|
20
|
+
var _pluginErrorBoundary = require("../plugin-error-boundary");
|
|
21
|
+
|
|
20
22
|
var _api = require("../../api");
|
|
21
23
|
|
|
22
24
|
/**
|
|
@@ -121,7 +123,10 @@ class PluginArea extends _element.Component {
|
|
|
121
123
|
return (0, _element.createElement)(_pluginContext.PluginContextProvider, {
|
|
122
124
|
key: context.name,
|
|
123
125
|
value: context
|
|
124
|
-
}, (0, _element.createElement)(
|
|
126
|
+
}, (0, _element.createElement)(_pluginErrorBoundary.PluginErrorBoundary, {
|
|
127
|
+
name: context.name,
|
|
128
|
+
onError: this.props.onError
|
|
129
|
+
}, (0, _element.createElement)(Plugin, null)));
|
|
125
130
|
}));
|
|
126
131
|
}
|
|
127
132
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-area/index.js"],"names":["PluginArea","Component","constructor","arguments","setPlugins","bind","memoizedContext","name","icon","state","getCurrentPluginsState","plugins","props","scope","render","Plugin","context","componentDidMount","componentWillUnmount","setState","display"],"mappings":";;;;;;;;;AASA;;AANA;;AACA;;AAMA;;AAKA;;AACA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-area/index.js"],"names":["PluginArea","Component","constructor","arguments","setPlugins","bind","memoizedContext","name","icon","state","getCurrentPluginsState","plugins","props","scope","render","Plugin","context","componentDidMount","componentWillUnmount","setState","display","onError"],"mappings":";;;;;;;;;AASA;;AANA;;AACA;;AAMA;;AAKA;;AACA;;AACA;;AAjBA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;;AAKA;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,MAAMA,UAAN,SAAyBC,kBAAzB,CAAmC;AAClCC,EAAAA,WAAW,GAAG;AACb,UAAO,GAAGC,SAAV;AAEA,SAAKC,UAAL,GAAkB,KAAKA,UAAL,CAAgBC,IAAhB,CAAsB,IAAtB,CAAlB;AACA,SAAKC,eAAL,GAAuB,qBAAS,CAAEC,IAAF,EAAQC,IAAR,KAAkB;AACjD,aAA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JD,CAD0B;AAAA,KAAzB,CADH,CADD;AAiBA;;AA1EiC;;eA6EpBrB,U","sourcesContent":["/**\n * External dependencies\n */\nimport { map } from 'lodash';\nimport memoize from 'memize';\n\n/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport { addAction, removeAction } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport { PluginContextProvider } from '../plugin-context';\nimport { PluginErrorBoundary } from '../plugin-error-boundary';\nimport { getPlugins } from '../../api';\n\n/**\n * A component that renders all plugin fills in a hidden div.\n *\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 */\nclass PluginArea extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\n\t\tthis.setPlugins = this.setPlugins.bind( this );\n\t\tthis.memoizedContext = memoize( ( name, icon ) => {\n\t\t\treturn {\n\t\t\t\tname,\n\t\t\t\ticon,\n\t\t\t};\n\t\t} );\n\t\tthis.state = this.getCurrentPluginsState();\n\t}\n\n\tgetCurrentPluginsState() {\n\t\treturn {\n\t\t\tplugins: map(\n\t\t\t\tgetPlugins( this.props.scope ),\n\t\t\t\t( { icon, name, render } ) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tPlugin: render,\n\t\t\t\t\t\tcontext: this.memoizedContext( name, icon ),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t),\n\t\t};\n\t}\n\n\tcomponentDidMount() {\n\t\taddAction(\n\t\t\t'plugins.pluginRegistered',\n\t\t\t'core/plugins/plugin-area/plugins-registered',\n\t\t\tthis.setPlugins\n\t\t);\n\t\taddAction(\n\t\t\t'plugins.pluginUnregistered',\n\t\t\t'core/plugins/plugin-area/plugins-unregistered',\n\t\t\tthis.setPlugins\n\t\t);\n\t}\n\n\tcomponentWillUnmount() {\n\t\tremoveAction(\n\t\t\t'plugins.pluginRegistered',\n\t\t\t'core/plugins/plugin-area/plugins-registered'\n\t\t);\n\t\tremoveAction(\n\t\t\t'plugins.pluginUnregistered',\n\t\t\t'core/plugins/plugin-area/plugins-unregistered'\n\t\t);\n\t}\n\n\tsetPlugins() {\n\t\tthis.setState( this.getCurrentPluginsState );\n\t}\n\n\trender() {\n\t\treturn (\n\t\t\t<div style={ { display: 'none' } }>\n\t\t\t\t{ map( this.state.plugins, ( { context, Plugin } ) => (\n\t\t\t\t\t<PluginContextProvider\n\t\t\t\t\t\tkey={ context.name }\n\t\t\t\t\t\tvalue={ context }\n\t\t\t\t\t>\n\t\t\t\t\t\t<PluginErrorBoundary\n\t\t\t\t\t\t\tname={ context.name }\n\t\t\t\t\t\t\tonError={ this.props.onError }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Plugin />\n\t\t\t\t\t\t</PluginErrorBoundary>\n\t\t\t\t\t</PluginContextProvider>\n\t\t\t\t) ) }\n\t\t\t</div>\n\t\t);\n\t}\n}\n\nexport default PluginArea;\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PluginErrorBoundary = void 0;
|
|
7
|
+
|
|
8
|
+
var _element = require("@wordpress/element");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* WordPress dependencies
|
|
12
|
+
*/
|
|
13
|
+
class PluginErrorBoundary extends _element.Component {
|
|
14
|
+
constructor(props) {
|
|
15
|
+
super(props);
|
|
16
|
+
this.state = {
|
|
17
|
+
hasError: false
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static getDerivedStateFromError() {
|
|
22
|
+
return {
|
|
23
|
+
hasError: true
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
componentDidCatch(error) {
|
|
28
|
+
const {
|
|
29
|
+
name,
|
|
30
|
+
onError
|
|
31
|
+
} = this.props;
|
|
32
|
+
|
|
33
|
+
if (onError) {
|
|
34
|
+
onError(name, error);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
render() {
|
|
39
|
+
if (!this.state.hasError) {
|
|
40
|
+
return this.props.children;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.PluginErrorBoundary = PluginErrorBoundary;
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;AAClDC,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;;AAEDE,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;;AAzBiD","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\n\nexport class PluginErrorBoundary extends Component {\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\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"]}
|
|
@@ -16,6 +16,7 @@ import { addAction, removeAction } from '@wordpress/hooks';
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import { PluginContextProvider } from '../plugin-context';
|
|
19
|
+
import { PluginErrorBoundary } from '../plugin-error-boundary';
|
|
19
20
|
import { getPlugins } from '../../api';
|
|
20
21
|
/**
|
|
21
22
|
* A component that renders all plugin fills in a hidden div.
|
|
@@ -108,7 +109,10 @@ class PluginArea extends Component {
|
|
|
108
109
|
return createElement(PluginContextProvider, {
|
|
109
110
|
key: context.name,
|
|
110
111
|
value: context
|
|
111
|
-
}, createElement(
|
|
112
|
+
}, createElement(PluginErrorBoundary, {
|
|
113
|
+
name: context.name,
|
|
114
|
+
onError: this.props.onError
|
|
115
|
+
}, createElement(Plugin, null)));
|
|
112
116
|
}));
|
|
113
117
|
}
|
|
114
118
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-area/index.js"],"names":["map","memoize","Component","addAction","removeAction","PluginContextProvider","getPlugins","PluginArea","constructor","arguments","setPlugins","bind","memoizedContext","name","icon","state","getCurrentPluginsState","plugins","props","scope","render","Plugin","context","componentDidMount","componentWillUnmount","setState","display"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AACA,OAAOC,OAAP,MAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,oBAA1B;AACA,SAASC,SAAT,EAAoBC,YAApB,QAAwC,kBAAxC;AAEA;AACA;AACA;;AACA,SAASC,qBAAT,QAAsC,mBAAtC;AACA,SAASC,UAAT,QAA2B,WAA3B;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,MAAMC,UAAN,
|
|
1
|
+
{"version":3,"sources":["@wordpress/plugins/src/components/plugin-area/index.js"],"names":["map","memoize","Component","addAction","removeAction","PluginContextProvider","PluginErrorBoundary","getPlugins","PluginArea","constructor","arguments","setPlugins","bind","memoizedContext","name","icon","state","getCurrentPluginsState","plugins","props","scope","render","Plugin","context","componentDidMount","componentWillUnmount","setState","display","onError"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AACA,OAAOC,OAAP,MAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,oBAA1B;AACA,SAASC,SAAT,EAAoBC,YAApB,QAAwC,kBAAxC;AAEA;AACA;AACA;;AACA,SAASC,qBAAT,QAAsC,mBAAtC;AACA,SAASC,mBAAT,QAAoC,0BAApC;AACA,SAASC,UAAT,QAA2B,WAA3B;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,MAAMC,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AG,CAAE,KAAKgB,KAAL,CAAWE,OAAb,EAAsB;AAAA,UAAE;AAAEK,QAAAA,OAAF;AAAWD,QAAAA;AAAX,OAAF;AAAA,aAC1B,cAAC,qBAAD;AACC,QAAA,GAAG,EAAGC,OAAO,CAACT,IADf;AAEC,QAAA,KAAK,EAAGS;AAFT,SAIC,cAAC,mBAAD;AACC,QAAA,IAAI,EAAGA,OAAO,CAACT,IADhB;AAEC,QAAA,OAAO,EAAG,KAAKK,KAAL,CAAWS;AAFtB,SAIC,cAAC,MAAD,OAJD,CAJD,CAD0B;AAAA,KAAtB,CADN,CADD;AAiBA;;AA1EiC;;AA6EnC,eAAepB,UAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { map } from 'lodash';\nimport memoize from 'memize';\n\n/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport { addAction, removeAction } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport { PluginContextProvider } from '../plugin-context';\nimport { PluginErrorBoundary } from '../plugin-error-boundary';\nimport { getPlugins } from '../../api';\n\n/**\n * A component that renders all plugin fills in a hidden div.\n *\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 */\nclass PluginArea extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\n\t\tthis.setPlugins = this.setPlugins.bind( this );\n\t\tthis.memoizedContext = memoize( ( name, icon ) => {\n\t\t\treturn {\n\t\t\t\tname,\n\t\t\t\ticon,\n\t\t\t};\n\t\t} );\n\t\tthis.state = this.getCurrentPluginsState();\n\t}\n\n\tgetCurrentPluginsState() {\n\t\treturn {\n\t\t\tplugins: map(\n\t\t\t\tgetPlugins( this.props.scope ),\n\t\t\t\t( { icon, name, render } ) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tPlugin: render,\n\t\t\t\t\t\tcontext: this.memoizedContext( name, icon ),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t),\n\t\t};\n\t}\n\n\tcomponentDidMount() {\n\t\taddAction(\n\t\t\t'plugins.pluginRegistered',\n\t\t\t'core/plugins/plugin-area/plugins-registered',\n\t\t\tthis.setPlugins\n\t\t);\n\t\taddAction(\n\t\t\t'plugins.pluginUnregistered',\n\t\t\t'core/plugins/plugin-area/plugins-unregistered',\n\t\t\tthis.setPlugins\n\t\t);\n\t}\n\n\tcomponentWillUnmount() {\n\t\tremoveAction(\n\t\t\t'plugins.pluginRegistered',\n\t\t\t'core/plugins/plugin-area/plugins-registered'\n\t\t);\n\t\tremoveAction(\n\t\t\t'plugins.pluginUnregistered',\n\t\t\t'core/plugins/plugin-area/plugins-unregistered'\n\t\t);\n\t}\n\n\tsetPlugins() {\n\t\tthis.setState( this.getCurrentPluginsState );\n\t}\n\n\trender() {\n\t\treturn (\n\t\t\t<div style={ { display: 'none' } }>\n\t\t\t\t{ map( this.state.plugins, ( { context, Plugin } ) => (\n\t\t\t\t\t<PluginContextProvider\n\t\t\t\t\t\tkey={ context.name }\n\t\t\t\t\t\tvalue={ context }\n\t\t\t\t\t>\n\t\t\t\t\t\t<PluginErrorBoundary\n\t\t\t\t\t\t\tname={ context.name }\n\t\t\t\t\t\t\tonError={ this.props.onError }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Plugin />\n\t\t\t\t\t\t</PluginErrorBoundary>\n\t\t\t\t\t</PluginContextProvider>\n\t\t\t\t) ) }\n\t\t\t</div>\n\t\t);\n\t}\n}\n\nexport default PluginArea;\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Component } from '@wordpress/element';
|
|
5
|
+
export class PluginErrorBoundary extends Component {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super(props);
|
|
8
|
+
this.state = {
|
|
9
|
+
hasError: false
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static getDerivedStateFromError() {
|
|
14
|
+
return {
|
|
15
|
+
hasError: true
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
componentDidCatch(error) {
|
|
20
|
+
const {
|
|
21
|
+
name,
|
|
22
|
+
onError
|
|
23
|
+
} = this.props;
|
|
24
|
+
|
|
25
|
+
if (onError) {
|
|
26
|
+
onError(name, error);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
render() {
|
|
31
|
+
if (!this.state.hasError) {
|
|
32
|
+
return this.props.children;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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;AAClDE,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;;AAEDE,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;;AAzBiD","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\n\nexport class PluginErrorBoundary extends Component {\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\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/plugins",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"description": "Plugins module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
"react-native": "src/index",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@babel/runtime": "^7.16.0",
|
|
29
|
-
"@wordpress/compose": "^5.1.
|
|
30
|
-
"@wordpress/element": "^4.1.
|
|
31
|
-
"@wordpress/hooks": "^3.3.
|
|
32
|
-
"@wordpress/icons": "^
|
|
29
|
+
"@wordpress/compose": "^5.1.1",
|
|
30
|
+
"@wordpress/element": "^4.1.1",
|
|
31
|
+
"@wordpress/hooks": "^3.3.1",
|
|
32
|
+
"@wordpress/icons": "^7.0.0",
|
|
33
33
|
"lodash": "^4.17.21",
|
|
34
34
|
"memize": "^1.1.0"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "0f838547f37472e46e6d5a9d2e84b6c61f4bd3f0"
|
|
40
40
|
}
|
|
@@ -14,6 +14,7 @@ import { addAction, removeAction } from '@wordpress/hooks';
|
|
|
14
14
|
* Internal dependencies
|
|
15
15
|
*/
|
|
16
16
|
import { PluginContextProvider } from '../plugin-context';
|
|
17
|
+
import { PluginErrorBoundary } from '../plugin-error-boundary';
|
|
17
18
|
import { getPlugins } from '../../api';
|
|
18
19
|
|
|
19
20
|
/**
|
|
@@ -114,7 +115,12 @@ class PluginArea extends Component {
|
|
|
114
115
|
key={ context.name }
|
|
115
116
|
value={ context }
|
|
116
117
|
>
|
|
117
|
-
<
|
|
118
|
+
<PluginErrorBoundary
|
|
119
|
+
name={ context.name }
|
|
120
|
+
onError={ this.props.onError }
|
|
121
|
+
>
|
|
122
|
+
<Plugin />
|
|
123
|
+
</PluginErrorBoundary>
|
|
118
124
|
</PluginContextProvider>
|
|
119
125
|
) ) }
|
|
120
126
|
</div>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Component } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
export class PluginErrorBoundary extends Component {
|
|
7
|
+
constructor( props ) {
|
|
8
|
+
super( props );
|
|
9
|
+
this.state = {
|
|
10
|
+
hasError: false,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static getDerivedStateFromError() {
|
|
15
|
+
return { hasError: true };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
componentDidCatch( error ) {
|
|
19
|
+
const { name, onError } = this.props;
|
|
20
|
+
if ( onError ) {
|
|
21
|
+
onError( name, error );
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
render() {
|
|
26
|
+
if ( ! this.state.hasError ) {
|
|
27
|
+
return this.props.children;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|