@wordpress/plugins 7.9.0 → 7.11.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 +4 -0
- package/README.md +2 -0
- package/build/api/index.js.map +1 -1
- package/build/components/plugin-context/index.js +8 -0
- package/build/components/plugin-context/index.js.map +1 -1
- package/build-module/api/index.js.map +1 -1
- package/build-module/components/plugin-context/index.js +7 -0
- package/build-module/components/plugin-context/index.js.map +1 -1
- package/build-types/components/plugin-context/index.d.ts +2 -0
- package/build-types/components/plugin-context/index.d.ts.map +1 -1
- package/package.json +11 -9
- package/src/components/plugin-context/index.tsx +7 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/build/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_hooks","require","_icons","plugins","registerPlugin","name","settings","console","error","test","applyFilters","render","scope","icon","pluginsIcon","doAction","unregisterPlugin","oldPlugin","getPlugin","getPlugins","Object","values","filter","plugin"],"sources":["@wordpress/plugins/src/api/index.ts"],"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"],"mappings":";;;;;;;;;AASA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAVA;AACA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;;AA4BA;AACA;AACA;AACA,MAAME,OAAO,GAAG,CAAC,CAA+B;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,cAAcA,CAC7BC,IAAY,EACZC,QAAwB,EACA;EACxB,IAAK,OAAOA,QAAQ,KAAK,QAAQ,EAAG;IACnCC,OAAO,CAACC,KAAK,CAAE,8BAA+B,CAAC;IAC/C,OAAO,IAAI;EACZ;EACA,IAAK,OAAOH,IAAI,KAAK,QAAQ,EAAG;IAC/BE,OAAO,CAACC,KAAK,CAAE,6BAA8B,CAAC;IAC9C,OAAO,IAAI;EACZ;EACA,IAAK,CAAE,mBAAmB,CAACC,IAAI,CAAEJ,IAAK,CAAC,EAAG;IACzCE,OAAO,CAACC,KAAK,CACZ,2HACD,CAAC;IACD,OAAO,IAAI;EACZ;EACA,IAAKL,OAAO,CAAEE,IAAI,CAAE,EAAG;IACtBE,OAAO,CAACC,KAAK,
|
|
1
|
+
{"version":3,"names":["_hooks","require","_icons","plugins","registerPlugin","name","settings","console","error","test","applyFilters","render","scope","icon","pluginsIcon","doAction","unregisterPlugin","oldPlugin","getPlugin","getPlugins","Object","values","filter","plugin"],"sources":["@wordpress/plugins/src/api/index.ts"],"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"],"mappings":"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","ignoreList":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
@@ -8,6 +9,7 @@ exports.usePluginContext = usePluginContext;
|
|
|
8
9
|
exports.withPluginContext = void 0;
|
|
9
10
|
var _element = require("@wordpress/element");
|
|
10
11
|
var _compose = require("@wordpress/compose");
|
|
12
|
+
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
11
13
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
14
|
/**
|
|
13
15
|
* WordPress dependencies
|
|
@@ -36,6 +38,8 @@ function usePluginContext() {
|
|
|
36
38
|
* A Higher Order Component used to inject Plugin context to the
|
|
37
39
|
* wrapped component.
|
|
38
40
|
*
|
|
41
|
+
* @deprecated 6.8.0 Use `usePluginContext` hook instead.
|
|
42
|
+
*
|
|
39
43
|
* @param mapContextToProps Function called on every context change,
|
|
40
44
|
* expected to return object of props to
|
|
41
45
|
* merge with the component's own props.
|
|
@@ -43,6 +47,10 @@ function usePluginContext() {
|
|
|
43
47
|
* @return {Component} Enhanced component with injected context as props.
|
|
44
48
|
*/
|
|
45
49
|
const withPluginContext = mapContextToProps => (0, _compose.createHigherOrderComponent)(OriginalComponent => {
|
|
50
|
+
(0, _deprecated.default)('wp.plugins.withPluginContext', {
|
|
51
|
+
since: '6.8.0',
|
|
52
|
+
alternative: 'wp.plugins.usePluginContext'
|
|
53
|
+
});
|
|
46
54
|
return props => /*#__PURE__*/(0, _jsxRuntime.jsx)(Context.Consumer, {
|
|
47
55
|
children: context => /*#__PURE__*/(0, _jsxRuntime.jsx)(OriginalComponent, {
|
|
48
56
|
...props,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_compose","_jsxRuntime","Context","createContext","name","icon","PluginContextProvider","exports","Provider","usePluginContext","useContext","withPluginContext","mapContextToProps","createHigherOrderComponent","OriginalComponent","props","jsx","Consumer","children","context"],"sources":["@wordpress/plugins/src/components/plugin-context/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport type { WPPlugin } from '../../api';\n\nexport interface PluginContext {\n\tname: null | WPPlugin[ 'name' ];\n\ticon: null | WPPlugin[ 'icon' ];\n}\n\nconst Context = createContext< PluginContext >( {\n\tname: null,\n\ticon: null,\n} );\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 * @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\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"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_element","require","_compose","_deprecated","_interopRequireDefault","_jsxRuntime","Context","createContext","name","icon","PluginContextProvider","exports","Provider","usePluginContext","useContext","withPluginContext","mapContextToProps","createHigherOrderComponent","OriginalComponent","deprecated","since","alternative","props","jsx","Consumer","children","context"],"sources":["@wordpress/plugins/src/components/plugin-context/index.tsx"],"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} );\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"],"mappings":";;;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAC,sBAAA,CAAAH,OAAA;AAA+C,IAAAI,WAAA,GAAAJ,OAAA;AAL/C;AACA;AACA;;AAKA;AACA;AACA;;AAQA,MAAMK,OAAO,GAAG,IAAAC,sBAAa,EAAmB;EAC/CC,IAAI,EAAE,IAAI;EACVC,IAAI,EAAE;AACP,CAAE,CAAC;AAEI,MAAMC,qBAAqB,GAAAC,OAAA,CAAAD,qBAAA,GAAGJ,OAAO,CAACM,QAAQ;;AAErD;AACA;AACA;AACA;AACA;AACO,SAASC,gBAAgBA,CAAA,EAAG;EAClC,OAAO,IAAAC,mBAAU,EAAER,OAAQ,CAAC;AAC7B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMS,iBAAiB,GAC7BC,iBAGsB,IAEtB,IAAAC,mCAA0B,EAAIC,iBAAiB,IAAM;EACpD,IAAAC,mBAAU,EAAE,8BAA8B,EAAE;IAC3CC,KAAK,EAAE,OAAO;IACdC,WAAW,EAAE;EACd,CAAE,CAAC;EACH,OAASC,KAAK,iBACb,IAAAjB,WAAA,CAAAkB,GAAA,EAACjB,OAAO,CAACkB,QAAQ;IAAAC,QAAA,EACZC,OAAO,iBACV,IAAArB,WAAA,CAAAkB,GAAA,EAACL,iBAAiB;MAAA,GACZI,KAAK;MAAA,GACLN,iBAAiB,CAAEU,OAAO,EAAEJ,KAAM;IAAC,CACxC;EACD,CACgB,CAClB;AACF,CAAC,EAAE,mBAAoB,CAAC;AAACX,OAAA,CAAAI,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["applyFilters","doAction","plugins","pluginsIcon","registerPlugin","name","settings","console","error","test","render","scope","icon","unregisterPlugin","oldPlugin","getPlugin","getPlugins","Object","values","filter","plugin"],"sources":["@wordpress/plugins/src/api/index.ts"],"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"],"mappings":"AAAA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,YAAY,EAAEC,QAAQ,QAAQ,kBAAkB;AACzD,SAASC,OAAO,IAAIC,WAAW,QAAQ,kBAAkB;;AAGzD;AACA;AACA;;AA4BA;AACA;AACA;AACA,MAAMD,OAAO,GAAG,CAAC,CAA+B;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,cAAcA,CAC7BC,IAAY,EACZC,QAAwB,EACA;EACxB,IAAK,OAAOA,QAAQ,KAAK,QAAQ,EAAG;IACnCC,OAAO,CAACC,KAAK,CAAE,8BAA+B,CAAC;IAC/C,OAAO,IAAI;EACZ;EACA,IAAK,OAAOH,IAAI,KAAK,QAAQ,EAAG;IAC/BE,OAAO,CAACC,KAAK,CAAE,6BAA8B,CAAC;IAC9C,OAAO,IAAI;EACZ;EACA,IAAK,CAAE,mBAAmB,CAACC,IAAI,CAAEJ,IAAK,CAAC,EAAG;IACzCE,OAAO,CAACC,KAAK,CACZ,2HACD,CAAC;IACD,OAAO,IAAI;EACZ;EACA,IAAKN,OAAO,CAAEG,IAAI,CAAE,EAAG;IACtBE,OAAO,CAACC,KAAK,
|
|
1
|
+
{"version":3,"names":["applyFilters","doAction","plugins","pluginsIcon","registerPlugin","name","settings","console","error","test","render","scope","icon","unregisterPlugin","oldPlugin","getPlugin","getPlugins","Object","values","filter","plugin"],"sources":["@wordpress/plugins/src/api/index.ts"],"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"],"mappings":"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","ignoreList":[]}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { createContext, useContext } from '@wordpress/element';
|
|
5
5
|
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
6
|
+
import deprecated from '@wordpress/deprecated';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Internal dependencies
|
|
@@ -27,6 +28,8 @@ export function usePluginContext() {
|
|
|
27
28
|
* A Higher Order Component used to inject Plugin context to the
|
|
28
29
|
* wrapped component.
|
|
29
30
|
*
|
|
31
|
+
* @deprecated 6.8.0 Use `usePluginContext` hook instead.
|
|
32
|
+
*
|
|
30
33
|
* @param mapContextToProps Function called on every context change,
|
|
31
34
|
* expected to return object of props to
|
|
32
35
|
* merge with the component's own props.
|
|
@@ -34,6 +37,10 @@ export function usePluginContext() {
|
|
|
34
37
|
* @return {Component} Enhanced component with injected context as props.
|
|
35
38
|
*/
|
|
36
39
|
export const withPluginContext = mapContextToProps => createHigherOrderComponent(OriginalComponent => {
|
|
40
|
+
deprecated('wp.plugins.withPluginContext', {
|
|
41
|
+
since: '6.8.0',
|
|
42
|
+
alternative: 'wp.plugins.usePluginContext'
|
|
43
|
+
});
|
|
37
44
|
return props => /*#__PURE__*/_jsx(Context.Consumer, {
|
|
38
45
|
children: context => /*#__PURE__*/_jsx(OriginalComponent, {
|
|
39
46
|
...props,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","useContext","createHigherOrderComponent","jsx","_jsx","Context","name","icon","PluginContextProvider","Provider","usePluginContext","withPluginContext","mapContextToProps","OriginalComponent","props","Consumer","children","context"],"sources":["@wordpress/plugins/src/components/plugin-context/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport type { WPPlugin } from '../../api';\n\nexport interface PluginContext {\n\tname: null | WPPlugin[ 'name' ];\n\ticon: null | WPPlugin[ 'icon' ];\n}\n\nconst Context = createContext< PluginContext >( {\n\tname: null,\n\ticon: null,\n} );\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 * @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\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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,UAAU,QAAQ,oBAAoB;AAC9D,SAASC,0BAA0B,QAAQ,oBAAoB
|
|
1
|
+
{"version":3,"names":["createContext","useContext","createHigherOrderComponent","deprecated","jsx","_jsx","Context","name","icon","PluginContextProvider","Provider","usePluginContext","withPluginContext","mapContextToProps","OriginalComponent","since","alternative","props","Consumer","children","context"],"sources":["@wordpress/plugins/src/components/plugin-context/index.tsx"],"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} );\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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,UAAU,QAAQ,oBAAoB;AAC9D,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,OAAOC,UAAU,MAAM,uBAAuB;;AAE9C;AACA;AACA;AAFA,SAAAC,GAAA,IAAAC,IAAA;AAUA,MAAMC,OAAO,GAAGN,aAAa,CAAmB;EAC/CO,IAAI,EAAE,IAAI;EACVC,IAAI,EAAE;AACP,CAAE,CAAC;AAEH,OAAO,MAAMC,qBAAqB,GAAGH,OAAO,CAACI,QAAQ;;AAErD;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAAA,EAAG;EAClC,OAAOV,UAAU,CAAEK,OAAQ,CAAC;AAC7B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMM,iBAAiB,GAC7BC,iBAGsB,IAEtBX,0BAA0B,CAAIY,iBAAiB,IAAM;EACpDX,UAAU,CAAE,8BAA8B,EAAE;IAC3CY,KAAK,EAAE,OAAO;IACdC,WAAW,EAAE;EACd,CAAE,CAAC;EACH,OAASC,KAAK,iBACbZ,IAAA,CAACC,OAAO,CAACY,QAAQ;IAAAC,QAAA,EACZC,OAAO,iBACVf,IAAA,CAACS,iBAAiB;MAAA,GACZG,KAAK;MAAA,GACLJ,iBAAiB,CAAEO,OAAO,EAAEH,KAAM;IAAC,CACxC;EACD,CACgB,CAClB;AACF,CAAC,EAAE,mBAAoB,CAAC","ignoreList":[]}
|
|
@@ -17,6 +17,8 @@ export declare function usePluginContext(): PluginContext;
|
|
|
17
17
|
* A Higher Order Component used to inject Plugin context to the
|
|
18
18
|
* wrapped component.
|
|
19
19
|
*
|
|
20
|
+
* @deprecated 6.8.0 Use `usePluginContext` hook instead.
|
|
21
|
+
*
|
|
20
22
|
* @param mapContextToProps Function called on every context change,
|
|
21
23
|
* expected to return object of props to
|
|
22
24
|
* merge with the component's own props.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/plugin-context/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/plugin-context/index.tsx"],"names":[],"mappings":"AAOA;;GAEG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,IAAI,GAAG,QAAQ,CAAE,MAAM,CAAE,CAAC;IAChC,IAAI,EAAE,IAAI,GAAG,QAAQ,CAAE,MAAM,CAAE,CAAC;CAChC;AAOD,eAAO,MAAM,qBAAqB,yCAAmB,CAAC;AAEtD;;;;GAIG;AACH,wBAAgB,gBAAgB,kBAE/B;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,sBACV,CAAE,CAAC,EACrB,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,CAAC,KACJ,CAAC,GAAG,aAAa,+FAiBE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/plugins",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.11.0",
|
|
4
4
|
"description": "Plugins module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -27,13 +27,14 @@
|
|
|
27
27
|
"react-native": "src/index",
|
|
28
28
|
"types": "build-types",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@babel/runtime": "
|
|
31
|
-
"@wordpress/components": "
|
|
32
|
-
"@wordpress/compose": "
|
|
33
|
-
"@wordpress/
|
|
34
|
-
"@wordpress/
|
|
35
|
-
"@wordpress/
|
|
36
|
-
"@wordpress/
|
|
30
|
+
"@babel/runtime": "7.25.7",
|
|
31
|
+
"@wordpress/components": "*",
|
|
32
|
+
"@wordpress/compose": "*",
|
|
33
|
+
"@wordpress/deprecated": "*",
|
|
34
|
+
"@wordpress/element": "*",
|
|
35
|
+
"@wordpress/hooks": "*",
|
|
36
|
+
"@wordpress/icons": "*",
|
|
37
|
+
"@wordpress/is-shallow-equal": "*",
|
|
37
38
|
"memize": "^2.0.1"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
@@ -43,5 +44,6 @@
|
|
|
43
44
|
"publishConfig": {
|
|
44
45
|
"access": "public"
|
|
45
46
|
},
|
|
46
|
-
"
|
|
47
|
+
"wpScript": true,
|
|
48
|
+
"gitHead": "dcf4613b33b0eda14e203ac30f700ed0db70347f"
|
|
47
49
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { createContext, useContext } from '@wordpress/element';
|
|
5
5
|
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
6
|
+
import deprecated from '@wordpress/deprecated';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Internal dependencies
|
|
@@ -34,6 +35,8 @@ export function usePluginContext() {
|
|
|
34
35
|
* A Higher Order Component used to inject Plugin context to the
|
|
35
36
|
* wrapped component.
|
|
36
37
|
*
|
|
38
|
+
* @deprecated 6.8.0 Use `usePluginContext` hook instead.
|
|
39
|
+
*
|
|
37
40
|
* @param mapContextToProps Function called on every context change,
|
|
38
41
|
* expected to return object of props to
|
|
39
42
|
* merge with the component's own props.
|
|
@@ -47,6 +50,10 @@ export const withPluginContext = (
|
|
|
47
50
|
) => T & PluginContext
|
|
48
51
|
) =>
|
|
49
52
|
createHigherOrderComponent( ( OriginalComponent ) => {
|
|
53
|
+
deprecated( 'wp.plugins.withPluginContext', {
|
|
54
|
+
since: '6.8.0',
|
|
55
|
+
alternative: 'wp.plugins.usePluginContext',
|
|
56
|
+
} );
|
|
50
57
|
return ( props ) => (
|
|
51
58
|
<Context.Consumer>
|
|
52
59
|
{ ( context ) => (
|