@wordpress/plugins 7.32.0 → 7.32.1-next.b8c8708f3.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
package/build/api/index.js
CHANGED
|
@@ -1,177 +1,82 @@
|
|
|
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 api_exports = {};
|
|
20
|
+
__export(api_exports, {
|
|
21
|
+
getPlugin: () => getPlugin,
|
|
22
|
+
getPlugins: () => getPlugins,
|
|
23
|
+
registerPlugin: () => registerPlugin,
|
|
24
|
+
unregisterPlugin: () => unregisterPlugin
|
|
5
25
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.unregisterPlugin = unregisterPlugin;
|
|
10
|
-
var _hooks = require("@wordpress/hooks");
|
|
11
|
-
var _icons = require("@wordpress/icons");
|
|
12
|
-
/* eslint no-console: [ 'error', { allow: [ 'error' ] } ] */
|
|
13
|
-
/**
|
|
14
|
-
* External dependencies
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* WordPress dependencies
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Defined behavior of a plugin type.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Plugin definitions keyed by plugin name.
|
|
27
|
-
*/
|
|
26
|
+
module.exports = __toCommonJS(api_exports);
|
|
27
|
+
var import_hooks = require("@wordpress/hooks");
|
|
28
|
+
var import_icons = require("@wordpress/icons");
|
|
28
29
|
const plugins = {};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Registers a plugin to the editor.
|
|
32
|
-
*
|
|
33
|
-
* @param name A string identifying the plugin. Must be
|
|
34
|
-
* unique across all registered plugins.
|
|
35
|
-
* @param settings The settings for this plugin.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```js
|
|
39
|
-
* // Using ES5 syntax
|
|
40
|
-
* var el = React.createElement;
|
|
41
|
-
* var Fragment = wp.element.Fragment;
|
|
42
|
-
* var PluginSidebar = wp.editor.PluginSidebar;
|
|
43
|
-
* var PluginSidebarMoreMenuItem = wp.editor.PluginSidebarMoreMenuItem;
|
|
44
|
-
* var registerPlugin = wp.plugins.registerPlugin;
|
|
45
|
-
* var moreIcon = React.createElement( 'svg' ); //... svg element.
|
|
46
|
-
*
|
|
47
|
-
* function Component() {
|
|
48
|
-
* return el(
|
|
49
|
-
* Fragment,
|
|
50
|
-
* {},
|
|
51
|
-
* el(
|
|
52
|
-
* PluginSidebarMoreMenuItem,
|
|
53
|
-
* {
|
|
54
|
-
* target: 'sidebar-name',
|
|
55
|
-
* },
|
|
56
|
-
* 'My Sidebar'
|
|
57
|
-
* ),
|
|
58
|
-
* el(
|
|
59
|
-
* PluginSidebar,
|
|
60
|
-
* {
|
|
61
|
-
* name: 'sidebar-name',
|
|
62
|
-
* title: 'My Sidebar',
|
|
63
|
-
* },
|
|
64
|
-
* 'Content of the sidebar'
|
|
65
|
-
* )
|
|
66
|
-
* );
|
|
67
|
-
* }
|
|
68
|
-
* registerPlugin( 'plugin-name', {
|
|
69
|
-
* icon: moreIcon,
|
|
70
|
-
* render: Component,
|
|
71
|
-
* scope: 'my-page',
|
|
72
|
-
* } );
|
|
73
|
-
* ```
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```js
|
|
77
|
-
* // Using ESNext syntax
|
|
78
|
-
* import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/editor';
|
|
79
|
-
* import { registerPlugin } from '@wordpress/plugins';
|
|
80
|
-
* import { more } from '@wordpress/icons';
|
|
81
|
-
*
|
|
82
|
-
* const Component = () => (
|
|
83
|
-
* <>
|
|
84
|
-
* <PluginSidebarMoreMenuItem
|
|
85
|
-
* target="sidebar-name"
|
|
86
|
-
* >
|
|
87
|
-
* My Sidebar
|
|
88
|
-
* </PluginSidebarMoreMenuItem>
|
|
89
|
-
* <PluginSidebar
|
|
90
|
-
* name="sidebar-name"
|
|
91
|
-
* title="My Sidebar"
|
|
92
|
-
* >
|
|
93
|
-
* Content of the sidebar
|
|
94
|
-
* </PluginSidebar>
|
|
95
|
-
* </>
|
|
96
|
-
* );
|
|
97
|
-
*
|
|
98
|
-
* registerPlugin( 'plugin-name', {
|
|
99
|
-
* icon: more,
|
|
100
|
-
* render: Component,
|
|
101
|
-
* scope: 'my-page',
|
|
102
|
-
* } );
|
|
103
|
-
* ```
|
|
104
|
-
*
|
|
105
|
-
* @return The final plugin settings object.
|
|
106
|
-
*/
|
|
107
30
|
function registerPlugin(name, settings) {
|
|
108
|
-
if (typeof settings !==
|
|
109
|
-
console.error(
|
|
31
|
+
if (typeof settings !== "object") {
|
|
32
|
+
console.error("No settings object provided!");
|
|
110
33
|
return null;
|
|
111
34
|
}
|
|
112
|
-
if (typeof name !==
|
|
113
|
-
console.error(
|
|
35
|
+
if (typeof name !== "string") {
|
|
36
|
+
console.error("Plugin name must be string.");
|
|
114
37
|
return null;
|
|
115
38
|
}
|
|
116
39
|
if (!/^[a-z][a-z0-9-]*$/.test(name)) {
|
|
117
|
-
console.error(
|
|
40
|
+
console.error(
|
|
41
|
+
'Plugin name must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-plugin".'
|
|
42
|
+
);
|
|
118
43
|
return null;
|
|
119
44
|
}
|
|
120
45
|
if (plugins[name]) {
|
|
121
46
|
console.error(`Plugin "${name}" is already registered.`);
|
|
122
47
|
}
|
|
123
|
-
settings = (0,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
48
|
+
settings = (0, import_hooks.applyFilters)(
|
|
49
|
+
"plugins.registerPlugin",
|
|
50
|
+
settings,
|
|
51
|
+
name
|
|
52
|
+
);
|
|
53
|
+
const { render, scope } = settings;
|
|
54
|
+
if (typeof render !== "function") {
|
|
55
|
+
console.error(
|
|
56
|
+
'The "render" property must be specified and must be a valid function.'
|
|
57
|
+
);
|
|
130
58
|
return null;
|
|
131
59
|
}
|
|
132
60
|
if (scope) {
|
|
133
|
-
if (typeof scope !==
|
|
134
|
-
console.error(
|
|
61
|
+
if (typeof scope !== "string") {
|
|
62
|
+
console.error("Plugin scope must be string.");
|
|
135
63
|
return null;
|
|
136
64
|
}
|
|
137
65
|
if (!/^[a-z][a-z0-9-]*$/.test(scope)) {
|
|
138
|
-
console.error(
|
|
66
|
+
console.error(
|
|
67
|
+
'Plugin scope must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-page".'
|
|
68
|
+
);
|
|
139
69
|
return null;
|
|
140
70
|
}
|
|
141
71
|
}
|
|
142
72
|
plugins[name] = {
|
|
143
73
|
name,
|
|
144
|
-
icon:
|
|
74
|
+
icon: import_icons.plugins,
|
|
145
75
|
...settings
|
|
146
76
|
};
|
|
147
|
-
(0,
|
|
77
|
+
(0, import_hooks.doAction)("plugins.pluginRegistered", settings, name);
|
|
148
78
|
return settings;
|
|
149
79
|
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Unregisters a plugin by name.
|
|
153
|
-
*
|
|
154
|
-
* @param name Plugin name.
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```js
|
|
158
|
-
* // Using ES5 syntax
|
|
159
|
-
* var unregisterPlugin = wp.plugins.unregisterPlugin;
|
|
160
|
-
*
|
|
161
|
-
* unregisterPlugin( 'plugin-name' );
|
|
162
|
-
* ```
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* ```js
|
|
166
|
-
* // Using ESNext syntax
|
|
167
|
-
* import { unregisterPlugin } from '@wordpress/plugins';
|
|
168
|
-
*
|
|
169
|
-
* unregisterPlugin( 'plugin-name' );
|
|
170
|
-
* ```
|
|
171
|
-
*
|
|
172
|
-
* @return The previous plugin settings object, if it has been
|
|
173
|
-
* successfully unregistered; otherwise `undefined`.
|
|
174
|
-
*/
|
|
175
80
|
function unregisterPlugin(name) {
|
|
176
81
|
if (!plugins[name]) {
|
|
177
82
|
console.error('Plugin "' + name + '" is not registered.');
|
|
@@ -179,30 +84,22 @@ function unregisterPlugin(name) {
|
|
|
179
84
|
}
|
|
180
85
|
const oldPlugin = plugins[name];
|
|
181
86
|
delete plugins[name];
|
|
182
|
-
(0,
|
|
87
|
+
(0, import_hooks.doAction)("plugins.pluginUnregistered", oldPlugin, name);
|
|
183
88
|
return oldPlugin;
|
|
184
89
|
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Returns a registered plugin settings.
|
|
188
|
-
*
|
|
189
|
-
* @param name Plugin name.
|
|
190
|
-
*
|
|
191
|
-
* @return Plugin setting.
|
|
192
|
-
*/
|
|
193
90
|
function getPlugin(name) {
|
|
194
91
|
return plugins[name];
|
|
195
92
|
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Returns all registered plugins without a scope or for a given scope.
|
|
199
|
-
*
|
|
200
|
-
* @param scope The scope to be used when rendering inside
|
|
201
|
-
* a plugin area. No scope by default.
|
|
202
|
-
*
|
|
203
|
-
* @return The list of plugins without a scope or for a given scope.
|
|
204
|
-
*/
|
|
205
93
|
function getPlugins(scope) {
|
|
206
|
-
return Object.values(plugins).filter(
|
|
94
|
+
return Object.values(plugins).filter(
|
|
95
|
+
(plugin) => plugin.scope === scope
|
|
96
|
+
);
|
|
207
97
|
}
|
|
208
|
-
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
getPlugin,
|
|
101
|
+
getPlugins,
|
|
102
|
+
registerPlugin,
|
|
103
|
+
unregisterPlugin
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=index.js.map
|
package/build/api/index.js.map
CHANGED
|
@@ -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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,mBAAuC;AACvC,mBAAuC;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,iBAAW;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,aAAAA;AAAA,IACN,GAAG;AAAA,EACJ;AAEA,6BAAU,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,6BAAU,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": ["pluginsIcon"]
|
|
7
|
+
}
|
|
@@ -1,27 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
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 components_exports = {};
|
|
30
|
+
__export(components_exports, {
|
|
31
|
+
PluginArea: () => import_plugin_area.default,
|
|
32
|
+
usePluginContext: () => import_plugin_context.usePluginContext,
|
|
33
|
+
withPluginContext: () => import_plugin_context.withPluginContext
|
|
18
34
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
35
|
+
module.exports = __toCommonJS(components_exports);
|
|
36
|
+
var import_plugin_area = __toESM(require("./plugin-area"));
|
|
37
|
+
var import_plugin_context = require("./plugin-context");
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
PluginArea,
|
|
41
|
+
usePluginContext,
|
|
42
|
+
withPluginContext
|
|
24
43
|
});
|
|
25
|
-
|
|
26
|
-
var _pluginContext = require("./plugin-context");
|
|
27
|
-
//# sourceMappingURL=index.js.map
|
|
44
|
+
//# 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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAsC;AACtC,4BAAoD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,114 +1,101 @@
|
|
|
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_area_exports = {};
|
|
30
|
+
__export(plugin_area_exports, {
|
|
31
|
+
default: () => plugin_area_default
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Internal dependencies
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
const getPluginContext = (0, _memize.default)((icon, name) => ({
|
|
29
|
-
icon,
|
|
30
|
-
name
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* A component that renders all plugin fills in a hidden div.
|
|
35
|
-
*
|
|
36
|
-
* @param props
|
|
37
|
-
* @param props.scope
|
|
38
|
-
* @param props.onError
|
|
39
|
-
* @example
|
|
40
|
-
* ```js
|
|
41
|
-
* // Using ES5 syntax
|
|
42
|
-
* var el = React.createElement;
|
|
43
|
-
* var PluginArea = wp.plugins.PluginArea;
|
|
44
|
-
*
|
|
45
|
-
* function Layout() {
|
|
46
|
-
* return el(
|
|
47
|
-
* 'div',
|
|
48
|
-
* { scope: 'my-page' },
|
|
49
|
-
* 'Content of the page',
|
|
50
|
-
* PluginArea
|
|
51
|
-
* );
|
|
52
|
-
* }
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```js
|
|
57
|
-
* // Using ESNext syntax
|
|
58
|
-
* import { PluginArea } from '@wordpress/plugins';
|
|
59
|
-
*
|
|
60
|
-
* const Layout = () => (
|
|
61
|
-
* <div>
|
|
62
|
-
* Content of the page
|
|
63
|
-
* <PluginArea scope="my-page" />
|
|
64
|
-
* </div>
|
|
65
|
-
* );
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
* @return {Component} The component to be rendered.
|
|
69
|
-
*/
|
|
33
|
+
module.exports = __toCommonJS(plugin_area_exports);
|
|
34
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
+
var import_memize = __toESM(require("memize"));
|
|
36
|
+
var import_element = require("@wordpress/element");
|
|
37
|
+
var import_hooks = require("@wordpress/hooks");
|
|
38
|
+
var import_is_shallow_equal = __toESM(require("@wordpress/is-shallow-equal"));
|
|
39
|
+
var import_plugin_context = require("../plugin-context");
|
|
40
|
+
var import_plugin_error_boundary = require("../plugin-error-boundary");
|
|
41
|
+
var import_api = require("../../api");
|
|
42
|
+
const getPluginContext = (0, import_memize.default)(
|
|
43
|
+
(icon, name) => ({
|
|
44
|
+
icon,
|
|
45
|
+
name
|
|
46
|
+
})
|
|
47
|
+
);
|
|
70
48
|
function PluginArea({
|
|
71
49
|
scope,
|
|
72
50
|
onError
|
|
73
51
|
}) {
|
|
74
|
-
const store = (0,
|
|
52
|
+
const store = (0, import_element.useMemo)(() => {
|
|
75
53
|
let lastValue = [];
|
|
76
54
|
return {
|
|
77
55
|
subscribe(listener) {
|
|
78
|
-
(0,
|
|
79
|
-
|
|
56
|
+
(0, import_hooks.addAction)(
|
|
57
|
+
"plugins.pluginRegistered",
|
|
58
|
+
"core/plugins/plugin-area/plugins-registered",
|
|
59
|
+
listener
|
|
60
|
+
);
|
|
61
|
+
(0, import_hooks.addAction)(
|
|
62
|
+
"plugins.pluginUnregistered",
|
|
63
|
+
"core/plugins/plugin-area/plugins-unregistered",
|
|
64
|
+
listener
|
|
65
|
+
);
|
|
80
66
|
return () => {
|
|
81
|
-
(0,
|
|
82
|
-
|
|
67
|
+
(0, import_hooks.removeAction)(
|
|
68
|
+
"plugins.pluginRegistered",
|
|
69
|
+
"core/plugins/plugin-area/plugins-registered"
|
|
70
|
+
);
|
|
71
|
+
(0, import_hooks.removeAction)(
|
|
72
|
+
"plugins.pluginUnregistered",
|
|
73
|
+
"core/plugins/plugin-area/plugins-unregistered"
|
|
74
|
+
);
|
|
83
75
|
};
|
|
84
76
|
},
|
|
85
77
|
getValue() {
|
|
86
|
-
const nextValue = (0,
|
|
87
|
-
if (!(0,
|
|
78
|
+
const nextValue = (0, import_api.getPlugins)(scope);
|
|
79
|
+
if (!(0, import_is_shallow_equal.default)(lastValue, nextValue)) {
|
|
88
80
|
lastValue = nextValue;
|
|
89
81
|
}
|
|
90
82
|
return lastValue;
|
|
91
83
|
}
|
|
92
84
|
};
|
|
93
85
|
}, [scope]);
|
|
94
|
-
const plugins = (0,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
render: Plugin
|
|
103
|
-
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_pluginContext.PluginContextProvider, {
|
|
86
|
+
const plugins = (0, import_element.useSyncExternalStore)(
|
|
87
|
+
store.subscribe,
|
|
88
|
+
store.getValue,
|
|
89
|
+
store.getValue
|
|
90
|
+
);
|
|
91
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "none" }, children: plugins.map(({ icon, name, render: Plugin }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
92
|
+
import_plugin_context.PluginContextProvider,
|
|
93
|
+
{
|
|
104
94
|
value: getPluginContext(icon, name),
|
|
105
|
-
children:
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
})
|
|
110
|
-
}, name))
|
|
111
|
-
});
|
|
95
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_plugin_error_boundary.PluginErrorBoundary, { name, onError, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Plugin, {}) })
|
|
96
|
+
},
|
|
97
|
+
name
|
|
98
|
+
)) });
|
|
112
99
|
}
|
|
113
|
-
var
|
|
114
|
-
//# sourceMappingURL=index.js.map
|
|
100
|
+
var plugin_area_default = PluginArea;
|
|
101
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/plugin-area/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport memoize from 'memize';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\nimport { addAction, removeAction } from '@wordpress/hooks';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport { PluginContextProvider } from '../plugin-context';\nimport { PluginErrorBoundary } from '../plugin-error-boundary';\nimport { getPlugins } from '../../api';\nimport type { PluginContext } from '../plugin-context';\nimport type { WPPlugin } from '../../api';\n\nconst getPluginContext = memoize(\n\t( icon: PluginContext[ 'icon' ], name: PluginContext[ 'name' ] ) => ( {\n\t\ticon,\n\t\tname,\n\t} )\n);\n\n/**\n * A component that renders all plugin fills in a hidden div.\n *\n * @param props\n * @param props.scope\n * @param props.onError\n * @example\n * ```js\n * // Using ES5 syntax\n * var el = React.createElement;\n * var PluginArea = wp.plugins.PluginArea;\n *\n * function Layout() {\n * \treturn el(\n * \t\t'div',\n * \t\t{ scope: 'my-page' },\n * \t\t'Content of the page',\n * \t\tPluginArea\n * \t);\n * }\n * ```\n *\n * @example\n * ```js\n * // Using ESNext syntax\n * import { PluginArea } from '@wordpress/plugins';\n *\n * const Layout = () => (\n * \t<div>\n * \t\tContent of the page\n * \t\t<PluginArea scope=\"my-page\" />\n * \t</div>\n * );\n * ```\n *\n * @return {Component} The component to be rendered.\n */\nfunction PluginArea( {\n\tscope,\n\tonError,\n}: {\n\tscope?: string;\n\tonError?: ( name: WPPlugin[ 'name' ], error: Error ) => void;\n} ) {\n\tconst store = useMemo( () => {\n\t\tlet lastValue: WPPlugin[] = [];\n\n\t\treturn {\n\t\t\tsubscribe(\n\t\t\t\tlistener: (\n\t\t\t\t\tplugin: Omit< WPPlugin, 'name' >,\n\t\t\t\t\tname: WPPlugin[ 'name' ]\n\t\t\t\t) => void\n\t\t\t) {\n\t\t\t\taddAction(\n\t\t\t\t\t'plugins.pluginRegistered',\n\t\t\t\t\t'core/plugins/plugin-area/plugins-registered',\n\t\t\t\t\tlistener\n\t\t\t\t);\n\t\t\t\taddAction(\n\t\t\t\t\t'plugins.pluginUnregistered',\n\t\t\t\t\t'core/plugins/plugin-area/plugins-unregistered',\n\t\t\t\t\tlistener\n\t\t\t\t);\n\t\t\t\treturn () => {\n\t\t\t\t\tremoveAction(\n\t\t\t\t\t\t'plugins.pluginRegistered',\n\t\t\t\t\t\t'core/plugins/plugin-area/plugins-registered'\n\t\t\t\t\t);\n\t\t\t\t\tremoveAction(\n\t\t\t\t\t\t'plugins.pluginUnregistered',\n\t\t\t\t\t\t'core/plugins/plugin-area/plugins-unregistered'\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetValue() {\n\t\t\t\tconst nextValue = getPlugins( scope );\n\n\t\t\t\tif ( ! isShallowEqual( lastValue, nextValue ) ) {\n\t\t\t\t\tlastValue = nextValue;\n\t\t\t\t}\n\n\t\t\t\treturn lastValue;\n\t\t\t},\n\t\t};\n\t}, [ scope ] );\n\n\tconst plugins = useSyncExternalStore(\n\t\tstore.subscribe,\n\t\tstore.getValue,\n\t\tstore.getValue\n\t);\n\n\treturn (\n\t\t<div style={ { display: 'none' } }>\n\t\t\t{ plugins.map( ( { icon, name, render: Plugin } ) => (\n\t\t\t\t<PluginContextProvider\n\t\t\t\t\tkey={ name }\n\t\t\t\t\tvalue={ getPluginContext( icon, name ) }\n\t\t\t\t>\n\t\t\t\t\t<PluginErrorBoundary name={ name } onError={ onError }>\n\t\t\t\t\t\t<Plugin />\n\t\t\t\t\t</PluginErrorBoundary>\n\t\t\t\t</PluginContextProvider>\n\t\t\t) ) }\n\t\t</div>\n\t);\n}\n\nexport default PluginArea;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiIM;AA9HN,oBAAoB;AAKpB,qBAA8C;AAC9C,mBAAwC;AACxC,8BAA2B;AAK3B,4BAAsC;AACtC,mCAAoC;AACpC,iBAA2B;AAI3B,MAAM,uBAAmB,cAAAA;AAAA,EACxB,CAAE,MAA+B,UAAqC;AAAA,IACrE;AAAA,IACA;AAAA,EACD;AACD;AAuCA,SAAS,WAAY;AAAA,EACpB;AAAA,EACA;AACD,GAGI;AACH,QAAM,YAAQ,wBAAS,MAAM;AAC5B,QAAI,YAAwB,CAAC;AAE7B,WAAO;AAAA,MACN,UACC,UAIC;AACD;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,QACD;AACA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,QACD;AACA,eAAO,MAAM;AACZ;AAAA,YACC;AAAA,YACA;AAAA,UACD;AACA;AAAA,YACC;AAAA,YACA;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MACA,WAAW;AACV,cAAM,gBAAY,uBAAY,KAAM;AAEpC,YAAK,KAAE,wBAAAC,SAAgB,WAAW,SAAU,GAAI;AAC/C,sBAAY;AAAA,QACb;AAEA,eAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD,GAAG,CAAE,KAAM,CAAE;AAEb,QAAM,cAAU;AAAA,IACf,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,EACP;AAEA,SACC,4CAAC,SAAI,OAAQ,EAAE,SAAS,OAAO,GAC5B,kBAAQ,IAAK,CAAE,EAAE,MAAM,MAAM,QAAQ,OAAO,MAC7C;AAAA,IAAC;AAAA;AAAA,MAEA,OAAQ,iBAAkB,MAAM,IAAK;AAAA,MAErC,sDAAC,oDAAoB,MAAc,SAClC,sDAAC,UAAO,GACT;AAAA;AAAA,IALM;AAAA,EAMP,CACC,GACH;AAEF;AAEA,IAAO,sBAAQ;",
|
|
6
|
+
"names": ["memoize", "isShallowEqual"]
|
|
7
|
+
}
|