@wordpress/plugins 7.33.1 → 7.34.1-next.2f1c7c01b.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 +2 -0
- package/build/api/index.js +3 -1
- package/build/api/index.js.map +1 -1
- package/build/components/index.js +2 -0
- package/build/components/index.js.map +1 -1
- package/build/components/plugin-area/index.js +4 -2
- package/build/components/plugin-area/index.js.map +1 -1
- package/build/components/plugin-context/index.js +6 -4
- package/build/components/plugin-context/index.js.map +1 -1
- package/build/components/plugin-error-boundary/index.js +4 -2
- package/build/components/plugin-error-boundary/index.js.map +1 -1
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/build/types.js +2 -0
- package/build/types.js.map +1 -1
- package/build-module/api/index.js +2 -1
- package/build-module/api/index.js.map +1 -1
- package/build-module/components/index.js +1 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/plugin-area/index.js +3 -2
- package/build-module/components/plugin-area/index.js.map +1 -1
- package/build-module/components/plugin-context/index.js +5 -4
- package/build-module/components/plugin-context/index.js.map +1 -1
- package/build-module/components/plugin-error-boundary/index.js +3 -2
- package/build-module/components/plugin-error-boundary/index.js.map +1 -1
- package/build-module/index.js +1 -0
- package/build-module/index.js.map +1 -1
- package/package.json +9 -9
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/build/api/index.js
CHANGED
|
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/plugins/src/api/index.ts
|
|
19
21
|
var api_exports = {};
|
|
20
22
|
__export(api_exports, {
|
|
21
23
|
getPlugin: () => getPlugin,
|
|
@@ -26,7 +28,7 @@ __export(api_exports, {
|
|
|
26
28
|
module.exports = __toCommonJS(api_exports);
|
|
27
29
|
var import_hooks = require("@wordpress/hooks");
|
|
28
30
|
var import_icons = require("@wordpress/icons");
|
|
29
|
-
|
|
31
|
+
var plugins = {};
|
|
30
32
|
function registerPlugin(name, settings) {
|
|
31
33
|
if (typeof settings !== "object") {
|
|
32
34
|
console.error("No settings object provided!");
|
package/build/api/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/api/index.ts"],
|
|
4
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": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,mBAAuC;AACvC,mBAAuC;AAoCvC,IAAM,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
6
|
"names": ["pluginsIcon"]
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/plugins/src/components/index.ts
|
|
29
31
|
var components_exports = {};
|
|
30
32
|
__export(components_exports, {
|
|
31
33
|
PluginArea: () => import_plugin_area.default,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/components/index.ts"],
|
|
4
4
|
"sourcesContent": ["export { default as PluginArea } from './plugin-area';\nexport { usePluginContext, withPluginContext } from './plugin-context';\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAsC;AACtC,4BAAoD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,12 +26,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/plugins/src/components/plugin-area/index.tsx
|
|
29
31
|
var plugin_area_exports = {};
|
|
30
32
|
__export(plugin_area_exports, {
|
|
31
33
|
default: () => plugin_area_default
|
|
32
34
|
});
|
|
33
35
|
module.exports = __toCommonJS(plugin_area_exports);
|
|
34
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
36
|
var import_memize = __toESM(require("memize"));
|
|
36
37
|
var import_element = require("@wordpress/element");
|
|
37
38
|
var import_hooks = require("@wordpress/hooks");
|
|
@@ -39,7 +40,8 @@ var import_is_shallow_equal = __toESM(require("@wordpress/is-shallow-equal"));
|
|
|
39
40
|
var import_plugin_context = require("../plugin-context");
|
|
40
41
|
var import_plugin_error_boundary = require("../plugin-error-boundary");
|
|
41
42
|
var import_api = require("../../api");
|
|
42
|
-
|
|
43
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
44
|
+
var getPluginContext = (0, import_memize.default)(
|
|
43
45
|
(icon, name) => ({
|
|
44
46
|
icon,
|
|
45
47
|
name
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/plugin-area/index.tsx"],
|
|
4
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": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAoB;AAKpB,qBAA8C;AAC9C,mBAAwC;AACxC,8BAA2B;AAK3B,4BAAsC;AACtC,mCAAoC;AACpC,iBAA2B;AAgHrB;AA5GN,IAAM,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
6
|
"names": ["memoize", "isShallowEqual"]
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/plugins/src/components/plugin-context/index.tsx
|
|
29
31
|
var plugin_context_exports = {};
|
|
30
32
|
__export(plugin_context_exports, {
|
|
31
33
|
PluginContextProvider: () => PluginContextProvider,
|
|
@@ -33,20 +35,20 @@ __export(plugin_context_exports, {
|
|
|
33
35
|
withPluginContext: () => withPluginContext
|
|
34
36
|
});
|
|
35
37
|
module.exports = __toCommonJS(plugin_context_exports);
|
|
36
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
37
38
|
var import_element = require("@wordpress/element");
|
|
38
39
|
var import_compose = require("@wordpress/compose");
|
|
39
40
|
var import_deprecated = __toESM(require("@wordpress/deprecated"));
|
|
40
|
-
|
|
41
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
+
var Context = (0, import_element.createContext)({
|
|
41
43
|
name: null,
|
|
42
44
|
icon: null
|
|
43
45
|
});
|
|
44
46
|
Context.displayName = "PluginContext";
|
|
45
|
-
|
|
47
|
+
var PluginContextProvider = Context.Provider;
|
|
46
48
|
function usePluginContext() {
|
|
47
49
|
return (0, import_element.useContext)(Context);
|
|
48
50
|
}
|
|
49
|
-
|
|
51
|
+
var withPluginContext = (mapContextToProps) => (0, import_compose.createHigherOrderComponent)((OriginalComponent) => {
|
|
50
52
|
(0, import_deprecated.default)("wp.plugins.withPluginContext", {
|
|
51
53
|
since: "6.8.0",
|
|
52
54
|
alternative: "wp.plugins.usePluginContext"
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/plugin-context/index.tsx"],
|
|
4
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": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA0C;AAC1C,qBAA2C;AAC3C,wBAAuB;AAuDlB;AA3CL,IAAM,cAAU,8BAAgC;AAAA,EAC/C,MAAM;AAAA,EACN,MAAM;AACP,CAAE;AACF,QAAQ,cAAc;AAEf,IAAM,wBAAwB,QAAQ;AAOtC,SAAS,mBAAmB;AAClC,aAAO,2BAAY,OAAQ;AAC5B;AAcO,IAAM,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
6
|
"names": ["deprecated"]
|
|
7
7
|
}
|
|
@@ -16,13 +16,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/plugins/src/components/plugin-error-boundary/index.tsx
|
|
19
21
|
var plugin_error_boundary_exports = {};
|
|
20
22
|
__export(plugin_error_boundary_exports, {
|
|
21
23
|
PluginErrorBoundary: () => PluginErrorBoundary
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(plugin_error_boundary_exports);
|
|
24
26
|
var import_element = require("@wordpress/element");
|
|
25
|
-
|
|
27
|
+
var PluginErrorBoundary = class extends import_element.Component {
|
|
26
28
|
constructor(props) {
|
|
27
29
|
super(props);
|
|
28
30
|
this.state = {
|
|
@@ -44,7 +46,7 @@ class PluginErrorBoundary extends import_element.Component {
|
|
|
44
46
|
}
|
|
45
47
|
return null;
|
|
46
48
|
}
|
|
47
|
-
}
|
|
49
|
+
};
|
|
48
50
|
// Annotate the CommonJS export names for ESM import in node:
|
|
49
51
|
0 && (module.exports = {
|
|
50
52
|
PluginErrorBoundary
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/plugin-error-boundary/index.tsx"],
|
|
4
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": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA0B;AAUnB,IAAM,sBAAN,cAAkC,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
6
|
"names": []
|
|
7
7
|
}
|
package/build/index.js
CHANGED
|
@@ -13,6 +13,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
13
13
|
};
|
|
14
14
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
|
|
17
|
+
// packages/plugins/src/index.ts
|
|
16
18
|
var index_exports = {};
|
|
17
19
|
module.exports = __toCommonJS(index_exports);
|
|
18
20
|
__reExport(index_exports, require("./components"), module.exports);
|
package/build/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["export * from './components';\nexport * from './api';\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,yBAAd;AACA,0BAAc,kBADd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/types.js
CHANGED
|
@@ -12,6 +12,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
12
12
|
return to;
|
|
13
13
|
};
|
|
14
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// packages/plugins/src/types.ts
|
|
15
17
|
var types_exports = {};
|
|
16
18
|
module.exports = __toCommonJS(types_exports);
|
|
17
19
|
//# sourceMappingURL=types.js.map
|
package/build/types.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/types.ts"],
|
|
4
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": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
// packages/plugins/src/api/index.ts
|
|
1
2
|
import { applyFilters, doAction } from "@wordpress/hooks";
|
|
2
3
|
import { plugins as pluginsIcon } from "@wordpress/icons";
|
|
3
|
-
|
|
4
|
+
var plugins = {};
|
|
4
5
|
function registerPlugin(name, settings) {
|
|
5
6
|
if (typeof settings !== "object") {
|
|
6
7
|
console.error("No settings object provided!");
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/api/index.ts"],
|
|
4
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,
|
|
5
|
+
"mappings": ";AASA,SAAS,cAAc,gBAAgB;AACvC,SAAS,WAAW,mBAAmB;AAoCvC,IAAM,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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/components/index.ts"],
|
|
4
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;",
|
|
5
|
+
"mappings": ";AAAA,SAAoB,WAAXA,gBAA6B;AACtC,SAAS,kBAAkB,yBAAyB;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// packages/plugins/src/components/plugin-area/index.tsx
|
|
2
2
|
import memoize from "memize";
|
|
3
3
|
import { useMemo, useSyncExternalStore } from "@wordpress/element";
|
|
4
4
|
import { addAction, removeAction } from "@wordpress/hooks";
|
|
@@ -6,7 +6,8 @@ import isShallowEqual from "@wordpress/is-shallow-equal";
|
|
|
6
6
|
import { PluginContextProvider } from "../plugin-context";
|
|
7
7
|
import { PluginErrorBoundary } from "../plugin-error-boundary";
|
|
8
8
|
import { getPlugins } from "../../api";
|
|
9
|
-
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
var getPluginContext = memoize(
|
|
10
11
|
(icon, name) => ({
|
|
11
12
|
icon,
|
|
12
13
|
name
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/plugin-area/index.tsx"],
|
|
4
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": "
|
|
5
|
+
"mappings": ";AAGA,OAAO,aAAa;AAKpB,SAAS,SAAS,4BAA4B;AAC9C,SAAS,WAAW,oBAAoB;AACxC,OAAO,oBAAoB;AAK3B,SAAS,6BAA6B;AACtC,SAAS,2BAA2B;AACpC,SAAS,kBAAkB;AAgHrB;AA5GN,IAAM,mBAAmB;AAAA,EACxB,CAAE,MAA+B,UAAqC;AAAA,IACrE;AAAA,IACA;AAAA,EACD;AACD;AAuCA,SAAS,WAAY;AAAA,EACpB;AAAA,EACA;AACD,GAGI;AACH,QAAM,QAAQ,QAAS,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,YAAY,WAAY,KAAM;AAEpC,YAAK,CAAE,eAAgB,WAAW,SAAU,GAAI;AAC/C,sBAAY;AAAA,QACb;AAEA,eAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD,GAAG,CAAE,KAAM,CAAE;AAEb,QAAM,UAAU;AAAA,IACf,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,EACP;AAEA,SACC,oBAAC,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,8BAAC,uBAAoB,MAAc,SAClC,8BAAC,UAAO,GACT;AAAA;AAAA,IALM;AAAA,EAMP,CACC,GACH;AAEF;AAEA,IAAO,sBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
// packages/plugins/src/components/plugin-context/index.tsx
|
|
2
2
|
import { createContext, useContext } from "@wordpress/element";
|
|
3
3
|
import { createHigherOrderComponent } from "@wordpress/compose";
|
|
4
4
|
import deprecated from "@wordpress/deprecated";
|
|
5
|
-
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
var Context = createContext({
|
|
6
7
|
name: null,
|
|
7
8
|
icon: null
|
|
8
9
|
});
|
|
9
10
|
Context.displayName = "PluginContext";
|
|
10
|
-
|
|
11
|
+
var PluginContextProvider = Context.Provider;
|
|
11
12
|
function usePluginContext() {
|
|
12
13
|
return useContext(Context);
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
var withPluginContext = (mapContextToProps) => createHigherOrderComponent((OriginalComponent) => {
|
|
15
16
|
deprecated("wp.plugins.withPluginContext", {
|
|
16
17
|
since: "6.8.0",
|
|
17
18
|
alternative: "wp.plugins.usePluginContext"
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/plugin-context/index.tsx"],
|
|
4
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": "
|
|
5
|
+
"mappings": ";AAGA,SAAS,eAAe,kBAAkB;AAC1C,SAAS,kCAAkC;AAC3C,OAAO,gBAAgB;AAuDlB;AA3CL,IAAM,UAAU,cAAgC;AAAA,EAC/C,MAAM;AAAA,EACN,MAAM;AACP,CAAE;AACF,QAAQ,cAAc;AAEf,IAAM,wBAAwB,QAAQ;AAOtC,SAAS,mBAAmB;AAClC,SAAO,WAAY,OAAQ;AAC5B;AAcO,IAAM,oBAAoB,CAChC,sBAKA,2BAA4B,CAAE,sBAAuB;AACpD,aAAY,gCAAgC;AAAA,IAC3C,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AACF,SAAO,CAAE,UACR,oBAAC,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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
// packages/plugins/src/components/plugin-error-boundary/index.tsx
|
|
1
2
|
import { Component } from "@wordpress/element";
|
|
2
|
-
|
|
3
|
+
var PluginErrorBoundary = class extends Component {
|
|
3
4
|
constructor(props) {
|
|
4
5
|
super(props);
|
|
5
6
|
this.state = {
|
|
@@ -21,7 +22,7 @@ class PluginErrorBoundary extends Component {
|
|
|
21
22
|
}
|
|
22
23
|
return null;
|
|
23
24
|
}
|
|
24
|
-
}
|
|
25
|
+
};
|
|
25
26
|
export {
|
|
26
27
|
PluginErrorBoundary
|
|
27
28
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/plugin-error-boundary/index.tsx"],
|
|
4
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": "AAGA,SAAS,iBAAiB;AAUnB,
|
|
5
|
+
"mappings": ";AAGA,SAAS,iBAAiB;AAUnB,IAAM,sBAAN,cAAkC,UAA0B;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
6
|
"names": []
|
|
7
7
|
}
|
package/build-module/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/plugins",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.34.1-next.2f1c7c01b.0",
|
|
4
4
|
"description": "Plugins module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"wpScript": true,
|
|
37
37
|
"types": "build-types",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@wordpress/components": "^30.
|
|
40
|
-
"@wordpress/compose": "^7.
|
|
41
|
-
"@wordpress/deprecated": "^4.
|
|
42
|
-
"@wordpress/element": "^6.
|
|
43
|
-
"@wordpress/hooks": "^4.
|
|
44
|
-
"@wordpress/icons": "^11.
|
|
45
|
-
"@wordpress/is-shallow-equal": "^5.
|
|
39
|
+
"@wordpress/components": "^30.7.2-next.2f1c7c01b.0",
|
|
40
|
+
"@wordpress/compose": "^7.34.1-next.2f1c7c01b.0",
|
|
41
|
+
"@wordpress/deprecated": "^4.34.1-next.2f1c7c01b.0",
|
|
42
|
+
"@wordpress/element": "^6.34.1-next.2f1c7c01b.0",
|
|
43
|
+
"@wordpress/hooks": "^4.34.1-next.2f1c7c01b.0",
|
|
44
|
+
"@wordpress/icons": "^11.1.1-next.2f1c7c01b.0",
|
|
45
|
+
"@wordpress/is-shallow-equal": "^5.34.1-next.2f1c7c01b.0",
|
|
46
46
|
"memize": "^2.0.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "c6ddcdf455bc02567a2c9e03de6862a2061b85e8"
|
|
56
56
|
}
|