@wordpress/plugins 7.32.0 → 7.32.1-next.47f435fc9.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/build/api/index.js +62 -165
- package/build/api/index.js.map +7 -1
- package/build/components/index.js +40 -23
- package/build/components/index.js.map +7 -1
- package/build/components/plugin-area/index.js +80 -93
- package/build/components/plugin-area/index.js.map +7 -1
- package/build/components/plugin-context/index.js +58 -53
- package/build/components/plugin-context/index.js.map +7 -1
- package/build/components/plugin-error-boundary/index.js +30 -23
- package/build/components/plugin-error-boundary/index.js.map +7 -1
- package/build/index.js +23 -26
- package/build/index.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build-module/api/index.js +40 -161
- package/build-module/api/index.js.map +7 -1
- package/build-module/components/index.js +8 -3
- package/build-module/components/index.js.map +7 -1
- package/build-module/components/plugin-area/index.js +49 -84
- package/build-module/components/plugin-area/index.js.map +7 -1
- package/build-module/components/plugin-context/index.js +23 -43
- package/build-module/components/plugin-context/index.js.map +7 -1
- package/build-module/components/plugin-error-boundary/index.js +8 -18
- package/build-module/components/plugin-error-boundary/index.js.map +7 -1
- package/build-module/index.js +3 -3
- package/build-module/index.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/package.json +17 -10
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,63 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var plugin_context_exports = {};
|
|
30
|
+
__export(plugin_context_exports, {
|
|
31
|
+
PluginContextProvider: () => PluginContextProvider,
|
|
32
|
+
usePluginContext: () => usePluginContext,
|
|
33
|
+
withPluginContext: () => withPluginContext
|
|
6
34
|
});
|
|
7
|
-
exports
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
-
/**
|
|
15
|
-
* WordPress dependencies
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Internal dependencies
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
const Context = (0, _element.createContext)({
|
|
35
|
+
module.exports = __toCommonJS(plugin_context_exports);
|
|
36
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
37
|
+
var import_element = require("@wordpress/element");
|
|
38
|
+
var import_compose = require("@wordpress/compose");
|
|
39
|
+
var import_deprecated = __toESM(require("@wordpress/deprecated"));
|
|
40
|
+
const Context = (0, import_element.createContext)({
|
|
23
41
|
name: null,
|
|
24
42
|
icon: null
|
|
25
43
|
});
|
|
26
|
-
Context.displayName =
|
|
27
|
-
const PluginContextProvider =
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* A hook that returns the plugin context.
|
|
31
|
-
*
|
|
32
|
-
* @return {PluginContext} Plugin context
|
|
33
|
-
*/
|
|
44
|
+
Context.displayName = "PluginContext";
|
|
45
|
+
const PluginContextProvider = Context.Provider;
|
|
34
46
|
function usePluginContext() {
|
|
35
|
-
return (0,
|
|
47
|
+
return (0, import_element.useContext)(Context);
|
|
36
48
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*
|
|
42
|
-
* @deprecated 6.8.0 Use `usePluginContext` hook instead.
|
|
43
|
-
*
|
|
44
|
-
* @param mapContextToProps Function called on every context change,
|
|
45
|
-
* expected to return object of props to
|
|
46
|
-
* merge with the component's own props.
|
|
47
|
-
*
|
|
48
|
-
* @return {Component} Enhanced component with injected context as props.
|
|
49
|
-
*/
|
|
50
|
-
const withPluginContext = mapContextToProps => (0, _compose.createHigherOrderComponent)(OriginalComponent => {
|
|
51
|
-
(0, _deprecated.default)('wp.plugins.withPluginContext', {
|
|
52
|
-
since: '6.8.0',
|
|
53
|
-
alternative: 'wp.plugins.usePluginContext'
|
|
49
|
+
const withPluginContext = (mapContextToProps) => (0, import_compose.createHigherOrderComponent)((OriginalComponent) => {
|
|
50
|
+
(0, import_deprecated.default)("wp.plugins.withPluginContext", {
|
|
51
|
+
since: "6.8.0",
|
|
52
|
+
alternative: "wp.plugins.usePluginContext"
|
|
54
53
|
});
|
|
55
|
-
return props =>
|
|
56
|
-
|
|
54
|
+
return (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Consumer, { children: (context) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
55
|
+
OriginalComponent,
|
|
56
|
+
{
|
|
57
57
|
...props,
|
|
58
58
|
...mapContextToProps(context, props)
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
}
|
|
60
|
+
) });
|
|
61
|
+
}, "withPluginContext");
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
PluginContextProvider,
|
|
65
|
+
usePluginContext,
|
|
66
|
+
withPluginContext
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/plugin-context/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport deprecated from '@wordpress/deprecated';\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} );\nContext.displayName = 'PluginContext';\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 * @deprecated 6.8.0 Use `usePluginContext` hook instead.\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\tdeprecated( 'wp.plugins.withPluginContext', {\n\t\t\tsince: '6.8.0',\n\t\t\talternative: 'wp.plugins.usePluginContext',\n\t\t} );\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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4DK;AAzDL,qBAA0C;AAC1C,qBAA2C;AAC3C,wBAAuB;AAYvB,MAAM,cAAU,8BAAgC;AAAA,EAC/C,MAAM;AAAA,EACN,MAAM;AACP,CAAE;AACF,QAAQ,cAAc;AAEf,MAAM,wBAAwB,QAAQ;AAOtC,SAAS,mBAAmB;AAClC,aAAO,2BAAY,OAAQ;AAC5B;AAcO,MAAM,oBAAoB,CAChC,0BAKA,2CAA4B,CAAE,sBAAuB;AACpD,wBAAAA,SAAY,gCAAgC;AAAA,IAC3C,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AACF,SAAO,CAAE,UACR,4CAAC,QAAQ,UAAR,EACE,WAAE,YACH;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACH,GAAG,kBAAmB,SAAS,KAAM;AAAA;AAAA,EACxC,GAEF;AAEF,GAAG,mBAAoB;",
|
|
6
|
+
"names": ["deprecated"]
|
|
7
|
+
}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var plugin_error_boundary_exports = {};
|
|
20
|
+
__export(plugin_error_boundary_exports, {
|
|
21
|
+
PluginErrorBoundary: () => PluginErrorBoundary
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
* WordPress dependencies
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Internal dependencies
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
class PluginErrorBoundary extends _element.Component {
|
|
23
|
+
module.exports = __toCommonJS(plugin_error_boundary_exports);
|
|
24
|
+
var import_element = require("@wordpress/element");
|
|
25
|
+
class PluginErrorBoundary extends import_element.Component {
|
|
17
26
|
constructor(props) {
|
|
18
27
|
super(props);
|
|
19
28
|
this.state = {
|
|
@@ -21,15 +30,10 @@ class PluginErrorBoundary extends _element.Component {
|
|
|
21
30
|
};
|
|
22
31
|
}
|
|
23
32
|
static getDerivedStateFromError() {
|
|
24
|
-
return {
|
|
25
|
-
hasError: true
|
|
26
|
-
};
|
|
33
|
+
return { hasError: true };
|
|
27
34
|
}
|
|
28
35
|
componentDidCatch(error) {
|
|
29
|
-
const {
|
|
30
|
-
name,
|
|
31
|
-
onError
|
|
32
|
-
} = this.props;
|
|
36
|
+
const { name, onError } = this.props;
|
|
33
37
|
if (onError) {
|
|
34
38
|
onError(name, error);
|
|
35
39
|
}
|
|
@@ -41,5 +45,8 @@ class PluginErrorBoundary extends _element.Component {
|
|
|
41
45
|
return null;
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
PluginErrorBoundary
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/plugin-error-boundary/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tPluginErrorBoundaryProps as Props,\n\tPluginErrorBoundaryState as State,\n} from '../../types';\n\nexport class PluginErrorBoundary extends Component< Props, State > {\n\tconstructor( props: Props ) {\n\t\tsuper( props );\n\t\tthis.state = {\n\t\t\thasError: false,\n\t\t};\n\t}\n\n\tstatic getDerivedStateFromError(): State {\n\t\treturn { hasError: true };\n\t}\n\n\tcomponentDidCatch( error: Error ): void {\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(): React.ReactNode {\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
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA0B;AAUnB,MAAM,4BAA4B,yBAA0B;AAAA,EAClE,YAAa,OAAe;AAC3B,UAAO,KAAM;AACb,SAAK,QAAQ;AAAA,MACZ,UAAU;AAAA,IACX;AAAA,EACD;AAAA,EAEA,OAAO,2BAAkC;AACxC,WAAO,EAAE,UAAU,KAAK;AAAA,EACzB;AAAA,EAEA,kBAAmB,OAAqB;AACvC,UAAM,EAAE,MAAM,QAAQ,IAAI,KAAK;AAC/B,QAAK,SAAU;AACd,cAAS,MAAM,KAAM;AAAA,IACtB;AAAA,EACD;AAAA,EAEA,SAA0B;AACzB,QAAK,CAAE,KAAK,MAAM,UAAW;AAC5B,aAAO,KAAK,MAAM;AAAA,IACnB;AAEA,WAAO;AAAA,EACR;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/index.js
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require("./components"), module.exports);
|
|
19
|
+
__reExport(index_exports, require("./api"), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./components"),
|
|
23
|
+
...require("./api")
|
|
5
24
|
});
|
|
6
|
-
|
|
7
|
-
Object.keys(_components).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _components[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _components[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _api = require("./api");
|
|
18
|
-
Object.keys(_api).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _api[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _api[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
//# sourceMappingURL=index.js.map
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './components';\nexport * from './api';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,yBAAd;AACA,0BAAc,kBADd;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/types.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
package/build/types.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Props for the PluginErrorBoundary component.\n */\nexport interface PluginErrorBoundaryProps {\n\t/**\n\t * The name of the plugin that may encounter an error.\n\t */\n\tname: string;\n\t/**\n\t * The child components to render.\n\t */\n\tchildren: React.ReactNode;\n\t/**\n\t * Callback function called when an error occurs.\n\t */\n\tonError?: ( name: string, error: Error ) => void;\n}\n\n/**\n * State for the PluginErrorBoundary component.\n */\nexport interface PluginErrorBoundaryState {\n\thasError: boolean;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,132 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* External dependencies
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { applyFilters, doAction } from '@wordpress/hooks';
|
|
10
|
-
import { plugins as pluginsIcon } from '@wordpress/icons';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Defined behavior of a plugin type.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Plugin definitions keyed by plugin name.
|
|
18
|
-
*/
|
|
1
|
+
import { applyFilters, doAction } from "@wordpress/hooks";
|
|
2
|
+
import { plugins as pluginsIcon } from "@wordpress/icons";
|
|
19
3
|
const plugins = {};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
* @param name A string identifying the plugin. Must be
|
|
25
|
-
* unique across all registered plugins.
|
|
26
|
-
* @param settings The settings for this plugin.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```js
|
|
30
|
-
* // Using ES5 syntax
|
|
31
|
-
* var el = React.createElement;
|
|
32
|
-
* var Fragment = wp.element.Fragment;
|
|
33
|
-
* var PluginSidebar = wp.editor.PluginSidebar;
|
|
34
|
-
* var PluginSidebarMoreMenuItem = wp.editor.PluginSidebarMoreMenuItem;
|
|
35
|
-
* var registerPlugin = wp.plugins.registerPlugin;
|
|
36
|
-
* var moreIcon = React.createElement( 'svg' ); //... svg element.
|
|
37
|
-
*
|
|
38
|
-
* function Component() {
|
|
39
|
-
* return el(
|
|
40
|
-
* Fragment,
|
|
41
|
-
* {},
|
|
42
|
-
* el(
|
|
43
|
-
* PluginSidebarMoreMenuItem,
|
|
44
|
-
* {
|
|
45
|
-
* target: 'sidebar-name',
|
|
46
|
-
* },
|
|
47
|
-
* 'My Sidebar'
|
|
48
|
-
* ),
|
|
49
|
-
* el(
|
|
50
|
-
* PluginSidebar,
|
|
51
|
-
* {
|
|
52
|
-
* name: 'sidebar-name',
|
|
53
|
-
* title: 'My Sidebar',
|
|
54
|
-
* },
|
|
55
|
-
* 'Content of the sidebar'
|
|
56
|
-
* )
|
|
57
|
-
* );
|
|
58
|
-
* }
|
|
59
|
-
* registerPlugin( 'plugin-name', {
|
|
60
|
-
* icon: moreIcon,
|
|
61
|
-
* render: Component,
|
|
62
|
-
* scope: 'my-page',
|
|
63
|
-
* } );
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```js
|
|
68
|
-
* // Using ESNext syntax
|
|
69
|
-
* import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/editor';
|
|
70
|
-
* import { registerPlugin } from '@wordpress/plugins';
|
|
71
|
-
* import { more } from '@wordpress/icons';
|
|
72
|
-
*
|
|
73
|
-
* const Component = () => (
|
|
74
|
-
* <>
|
|
75
|
-
* <PluginSidebarMoreMenuItem
|
|
76
|
-
* target="sidebar-name"
|
|
77
|
-
* >
|
|
78
|
-
* My Sidebar
|
|
79
|
-
* </PluginSidebarMoreMenuItem>
|
|
80
|
-
* <PluginSidebar
|
|
81
|
-
* name="sidebar-name"
|
|
82
|
-
* title="My Sidebar"
|
|
83
|
-
* >
|
|
84
|
-
* Content of the sidebar
|
|
85
|
-
* </PluginSidebar>
|
|
86
|
-
* </>
|
|
87
|
-
* );
|
|
88
|
-
*
|
|
89
|
-
* registerPlugin( 'plugin-name', {
|
|
90
|
-
* icon: more,
|
|
91
|
-
* render: Component,
|
|
92
|
-
* scope: 'my-page',
|
|
93
|
-
* } );
|
|
94
|
-
* ```
|
|
95
|
-
*
|
|
96
|
-
* @return The final plugin settings object.
|
|
97
|
-
*/
|
|
98
|
-
export function registerPlugin(name, settings) {
|
|
99
|
-
if (typeof settings !== 'object') {
|
|
100
|
-
console.error('No settings object provided!');
|
|
4
|
+
function registerPlugin(name, settings) {
|
|
5
|
+
if (typeof settings !== "object") {
|
|
6
|
+
console.error("No settings object provided!");
|
|
101
7
|
return null;
|
|
102
8
|
}
|
|
103
|
-
if (typeof name !==
|
|
104
|
-
console.error(
|
|
9
|
+
if (typeof name !== "string") {
|
|
10
|
+
console.error("Plugin name must be string.");
|
|
105
11
|
return null;
|
|
106
12
|
}
|
|
107
13
|
if (!/^[a-z][a-z0-9-]*$/.test(name)) {
|
|
108
|
-
console.error(
|
|
14
|
+
console.error(
|
|
15
|
+
'Plugin name must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-plugin".'
|
|
16
|
+
);
|
|
109
17
|
return null;
|
|
110
18
|
}
|
|
111
19
|
if (plugins[name]) {
|
|
112
20
|
console.error(`Plugin "${name}" is already registered.`);
|
|
113
21
|
}
|
|
114
|
-
settings = applyFilters(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
22
|
+
settings = applyFilters(
|
|
23
|
+
"plugins.registerPlugin",
|
|
24
|
+
settings,
|
|
25
|
+
name
|
|
26
|
+
);
|
|
27
|
+
const { render, scope } = settings;
|
|
28
|
+
if (typeof render !== "function") {
|
|
29
|
+
console.error(
|
|
30
|
+
'The "render" property must be specified and must be a valid function.'
|
|
31
|
+
);
|
|
121
32
|
return null;
|
|
122
33
|
}
|
|
123
34
|
if (scope) {
|
|
124
|
-
if (typeof scope !==
|
|
125
|
-
console.error(
|
|
35
|
+
if (typeof scope !== "string") {
|
|
36
|
+
console.error("Plugin scope must be string.");
|
|
126
37
|
return null;
|
|
127
38
|
}
|
|
128
39
|
if (!/^[a-z][a-z0-9-]*$/.test(scope)) {
|
|
129
|
-
console.error(
|
|
40
|
+
console.error(
|
|
41
|
+
'Plugin scope must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-page".'
|
|
42
|
+
);
|
|
130
43
|
return null;
|
|
131
44
|
}
|
|
132
45
|
}
|
|
@@ -135,65 +48,31 @@ export function registerPlugin(name, settings) {
|
|
|
135
48
|
icon: pluginsIcon,
|
|
136
49
|
...settings
|
|
137
50
|
};
|
|
138
|
-
doAction(
|
|
51
|
+
doAction("plugins.pluginRegistered", settings, name);
|
|
139
52
|
return settings;
|
|
140
53
|
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Unregisters a plugin by name.
|
|
144
|
-
*
|
|
145
|
-
* @param name Plugin name.
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```js
|
|
149
|
-
* // Using ES5 syntax
|
|
150
|
-
* var unregisterPlugin = wp.plugins.unregisterPlugin;
|
|
151
|
-
*
|
|
152
|
-
* unregisterPlugin( 'plugin-name' );
|
|
153
|
-
* ```
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```js
|
|
157
|
-
* // Using ESNext syntax
|
|
158
|
-
* import { unregisterPlugin } from '@wordpress/plugins';
|
|
159
|
-
*
|
|
160
|
-
* unregisterPlugin( 'plugin-name' );
|
|
161
|
-
* ```
|
|
162
|
-
*
|
|
163
|
-
* @return The previous plugin settings object, if it has been
|
|
164
|
-
* successfully unregistered; otherwise `undefined`.
|
|
165
|
-
*/
|
|
166
|
-
export function unregisterPlugin(name) {
|
|
54
|
+
function unregisterPlugin(name) {
|
|
167
55
|
if (!plugins[name]) {
|
|
168
56
|
console.error('Plugin "' + name + '" is not registered.');
|
|
169
57
|
return;
|
|
170
58
|
}
|
|
171
59
|
const oldPlugin = plugins[name];
|
|
172
60
|
delete plugins[name];
|
|
173
|
-
doAction(
|
|
61
|
+
doAction("plugins.pluginUnregistered", oldPlugin, name);
|
|
174
62
|
return oldPlugin;
|
|
175
63
|
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Returns a registered plugin settings.
|
|
179
|
-
*
|
|
180
|
-
* @param name Plugin name.
|
|
181
|
-
*
|
|
182
|
-
* @return Plugin setting.
|
|
183
|
-
*/
|
|
184
|
-
export function getPlugin(name) {
|
|
64
|
+
function getPlugin(name) {
|
|
185
65
|
return plugins[name];
|
|
186
66
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
* @param scope The scope to be used when rendering inside
|
|
192
|
-
* a plugin area. No scope by default.
|
|
193
|
-
*
|
|
194
|
-
* @return The list of plugins without a scope or for a given scope.
|
|
195
|
-
*/
|
|
196
|
-
export function getPlugins(scope) {
|
|
197
|
-
return Object.values(plugins).filter(plugin => plugin.scope === scope);
|
|
67
|
+
function getPlugins(scope) {
|
|
68
|
+
return Object.values(plugins).filter(
|
|
69
|
+
(plugin) => plugin.scope === scope
|
|
70
|
+
);
|
|
198
71
|
}
|
|
199
|
-
|
|
72
|
+
export {
|
|
73
|
+
getPlugin,
|
|
74
|
+
getPlugins,
|
|
75
|
+
registerPlugin,
|
|
76
|
+
unregisterPlugin
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/api/index.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint no-console: [ 'error', { allow: [ 'error' ] } ] */\n/**\n * External dependencies\n */\nimport type { ComponentType } from 'react';\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';\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: ComponentType;\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 = React.createElement;\n * var Fragment = wp.element.Fragment;\n * var PluginSidebar = wp.editor.PluginSidebar;\n * var PluginSidebarMoreMenuItem = wp.editor.PluginSidebarMoreMenuItem;\n * var registerPlugin = wp.plugins.registerPlugin;\n * var moreIcon = React.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/editor';\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"],
|
|
5
|
+
"mappings": "AASA,SAAS,cAAc,gBAAgB;AACvC,SAAS,WAAW,mBAAmB;AAoCvC,MAAM,UAAU,CAAC;AA+EV,SAAS,eACf,MACA,UACwB;AACxB,MAAK,OAAO,aAAa,UAAW;AACnC,YAAQ,MAAO,8BAA+B;AAC9C,WAAO;AAAA,EACR;AACA,MAAK,OAAO,SAAS,UAAW;AAC/B,YAAQ,MAAO,6BAA8B;AAC7C,WAAO;AAAA,EACR;AACA,MAAK,CAAE,oBAAoB,KAAM,IAAK,GAAI;AACzC,YAAQ;AAAA,MACP;AAAA,IACD;AACA,WAAO;AAAA,EACR;AACA,MAAK,QAAS,IAAK,GAAI;AACtB,YAAQ,MAAO,WAAY,IAAK,0BAA2B;AAAA,EAC5D;AAEA,aAAW;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,QAAM,EAAE,QAAQ,MAAM,IAAI;AAE1B,MAAK,OAAO,WAAW,YAAa;AACnC,YAAQ;AAAA,MACP;AAAA,IACD;AACA,WAAO;AAAA,EACR;AAEA,MAAK,OAAQ;AACZ,QAAK,OAAO,UAAU,UAAW;AAChC,cAAQ,MAAO,8BAA+B;AAC9C,aAAO;AAAA,IACR;AAEA,QAAK,CAAE,oBAAoB,KAAM,KAAM,GAAI;AAC1C,cAAQ;AAAA,QACP;AAAA,MACD;AACA,aAAO;AAAA,IACR;AAAA,EACD;AAEA,UAAS,IAAK,IAAI;AAAA,IACjB;AAAA,IACA,MAAM;AAAA,IACN,GAAG;AAAA,EACJ;AAEA,WAAU,4BAA4B,UAAU,IAAK;AAErD,SAAO;AACR;AA0BO,SAAS,iBAAkB,MAAqC;AACtE,MAAK,CAAE,QAAS,IAAK,GAAI;AACxB,YAAQ,MAAO,aAAa,OAAO,sBAAuB;AAC1D;AAAA,EACD;AACA,QAAM,YAAY,QAAS,IAAK;AAChC,SAAO,QAAS,IAAK;AAErB,WAAU,8BAA8B,WAAW,IAAK;AAExD,SAAO;AACR;AASO,SAAS,UAAW,MAAqC;AAC/D,SAAO,QAAS,IAAK;AACtB;AAUO,SAAS,WAAY,OAA6B;AACxD,SAAO,OAAO,OAAQ,OAAQ,EAAE;AAAA,IAC/B,CAAE,WAAY,OAAO,UAAU;AAAA,EAChC;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { default as default2 } from "./plugin-area";
|
|
2
|
+
import { usePluginContext, withPluginContext } from "./plugin-context";
|
|
3
|
+
export {
|
|
4
|
+
default2 as PluginArea,
|
|
5
|
+
usePluginContext,
|
|
6
|
+
withPluginContext
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/components/index.ts"],
|
|
4
|
+
"sourcesContent": ["export { default as PluginArea } from './plugin-area';\nexport { usePluginContext, withPluginContext } from './plugin-context';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,WAAXA,gBAA6B;AACtC,SAAS,kBAAkB,yBAAyB;",
|
|
6
|
+
"names": ["default"]
|
|
7
|
+
}
|