From 2c62df14ce189d86fe0a5d250cd5fa21501f0cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Fri, 8 Mar 2019 09:08:27 +0100 Subject: [PATCH] Add ES5 examples back --- packages/plugins/README.md | 54 +++++++++++++++++++ packages/plugins/src/api/index.js | 46 +++++++++++++++- .../src/components/plugin-area/index.js | 17 +++++- 3 files changed, 114 insertions(+), 3 deletions(-) diff --git a/packages/plugins/README.md b/packages/plugins/README.md index 39f0e1d164cb7..ff07b3fb660af 100644 --- a/packages/plugins/README.md +++ b/packages/plugins/README.md @@ -48,6 +48,20 @@ A component that renders all plugin fills in a hidden div. **Usage** +```js +var el = wp.element.createElement; +var PluginArea = wp.plugins.PluginArea; + +function Layout() { + return el( + 'div', + {}, + 'Content of the page', + PluginArea + ); +} +``` + ```js const { PluginArea } = wp.plugins; @@ -71,6 +85,40 @@ Registers a plugin to the editor. **Usage** +```js +var el = wp.element.createElement; +var Fragment = wp.element.Fragment; +var PluginSidebar = wp.editPost.PluginSidebar; +var PluginSidebarMoreMenuItem = wp.editPost.PluginSidebarMoreMenuItem; +var registerPlugin = wp.plugins.registerPlugin; + +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: 'smiley', + render: Component, +} ); +``` + ```js const { Fragment } = wp.element; const { PluginSidebar, PluginSidebarMoreMenuItem } = wp.editPost; @@ -117,6 +165,12 @@ Unregisters a plugin by name. **Usage** +```js +var unregisterPlugin = wp.plugins.unregisterPlugin; + +unregisterPlugin( 'plugin-name' ); +``` + ```js const { unregisterPlugin } = wp.plugins; unregisterPlugin( 'plugin-name' ); diff --git a/packages/plugins/src/api/index.js b/packages/plugins/src/api/index.js index ce5ef7820a34d..48637159180f7 100644 --- a/packages/plugins/src/api/index.js +++ b/packages/plugins/src/api/index.js @@ -26,7 +26,42 @@ const plugins = {}; * or an element (or function returning an element) if you choose to render your own SVG. * @param {Function} settings.render A component containing the UI elements to be rendered. * - * @example + * @example ES5 + * ```js + * var el = wp.element.createElement; + * var Fragment = wp.element.Fragment; + * var PluginSidebar = wp.editPost.PluginSidebar; + * var PluginSidebarMoreMenuItem = wp.editPost.PluginSidebarMoreMenuItem; + * var registerPlugin = wp.plugins.registerPlugin; + * + * 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: 'smiley', + * render: Component, + * } ); + * ``` + * + * @example ESNext * ```js * const { Fragment } = wp.element; * const { PluginSidebar, PluginSidebarMoreMenuItem } = wp.editPost; @@ -106,7 +141,14 @@ export function registerPlugin( name, settings ) { * * @param {string} name Plugin name. * - * @example + * @example ES5 + * ```js + * var unregisterPlugin = wp.plugins.unregisterPlugin; + * + * unregisterPlugin( 'plugin-name' ); + * ``` + * + * @example ESNext * ```js * const { unregisterPlugin } = wp.plugins; * unregisterPlugin( 'plugin-name' ); diff --git a/packages/plugins/src/components/plugin-area/index.js b/packages/plugins/src/components/plugin-area/index.js index 294d4fe0c6677..4bd1ad9e55548 100644 --- a/packages/plugins/src/components/plugin-area/index.js +++ b/packages/plugins/src/components/plugin-area/index.js @@ -18,7 +18,22 @@ import { getPlugins } from '../../api'; /** * A component that renders all plugin fills in a hidden div. * - * @example + * @example ES5 + * ```js + * var el = wp.element.createElement; + * var PluginArea = wp.plugins.PluginArea; + * + * function Layout() { + * return el( + * 'div', + * {}, + * 'Content of the page', + * PluginArea + * ); + * } + * ``` + * + * @example ESNext * ```js * const { PluginArea } = wp.plugins; *