UNPKG

@wordpress/plugins

Version:
152 lines 3.79 kB
/** * External dependencies */ import type { ComponentType } from 'react'; import type { IconType } from '@wordpress/components'; /** * Defined behavior of a plugin type. */ export interface WPPlugin { /** * A string identifying the plugin. Must be unique across all registered plugins. */ name: string; /** * An icon to be shown in the UI. It can be a slug of the Dashicon, or an * element (or function returning an element) if you choose to render your * own SVG. */ icon?: IconType; /** * A component containing the UI elements to be rendered. */ render: ComponentType; /** * The optional scope to be used when rendering inside a plugin area. * No scope by default. */ scope?: string; } type PluginSettings = Omit<WPPlugin, 'name'>; /** * Registers a plugin to the editor. * * @param name A string identifying the plugin. Must be * unique across all registered plugins. * @param settings The settings for this plugin. * * @example * ```js * // Using ES5 syntax * var el = React.createElement; * var Fragment = wp.element.Fragment; * var PluginSidebar = wp.editor.PluginSidebar; * var PluginSidebarMoreMenuItem = wp.editor.PluginSidebarMoreMenuItem; * var registerPlugin = wp.plugins.registerPlugin; * var moreIcon = React.createElement( 'svg' ); //... svg element. * * function Component() { * return el( * Fragment, * {}, * el( * PluginSidebarMoreMenuItem, * { * target: 'sidebar-name', * }, * 'My Sidebar' * ), * el( * PluginSidebar, * { * name: 'sidebar-name', * title: 'My Sidebar', * }, * 'Content of the sidebar' * ) * ); * } * registerPlugin( 'plugin-name', { * icon: moreIcon, * render: Component, * scope: 'my-page', * } ); * ``` * * @example * ```js * // Using ESNext syntax * import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/editor'; * import { registerPlugin } from '@wordpress/plugins'; * import { more } from '@wordpress/icons'; * * const Component = () => ( * <> * <PluginSidebarMoreMenuItem * target="sidebar-name" * > * My Sidebar * </PluginSidebarMoreMenuItem> * <PluginSidebar * name="sidebar-name" * title="My Sidebar" * > * Content of the sidebar * </PluginSidebar> * </> * ); * * registerPlugin( 'plugin-name', { * icon: more, * render: Component, * scope: 'my-page', * } ); * ``` * * @return The final plugin settings object. */ export declare function registerPlugin(name: string, settings: PluginSettings): PluginSettings | null; /** * Unregisters a plugin by name. * * @param name Plugin name. * * @example * ```js * // Using ES5 syntax * var unregisterPlugin = wp.plugins.unregisterPlugin; * * unregisterPlugin( 'plugin-name' ); * ``` * * @example * ```js * // Using ESNext syntax * import { unregisterPlugin } from '@wordpress/plugins'; * * unregisterPlugin( 'plugin-name' ); * ``` * * @return The previous plugin settings object, if it has been * successfully unregistered; otherwise `undefined`. */ export declare function unregisterPlugin(name: string): WPPlugin | undefined; /** * Returns a registered plugin settings. * * @param name Plugin name. * * @return Plugin setting. */ export declare function getPlugin(name: string): WPPlugin | undefined; /** * Returns all registered plugins without a scope or for a given scope. * * @param scope The scope to be used when rendering inside * a plugin area. No scope by default. * * @return The list of plugins without a scope or for a given scope. */ export declare function getPlugins(scope?: string): WPPlugin[]; export {}; //# sourceMappingURL=index.d.ts.map