{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/plugin-area/index.tsx"],"sourcesContent":["import memoize from 'memize';\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\nimport { addAction, removeAction } from '@wordpress/hooks';\nimport { isShallowEqual } from '@wordpress/is-shallow-equal';\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"],"mappings":";;;;;;;;;AAUA,MAAM,mBAAmB,SACtB,MAA+B,UAAqC;CACrE;CACA;AACD,EACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAS,WAAY,EACpB,OACA,WAIG;CACH,MAAM,QAAQ,cAAe;EAC5B,IAAI,YAAwB,CAAC;EAE7B,OAAO;GACN,UACC,UAIC;IACD,UACC,4BACA,+CACA,QACD;IACA,UACC,8BACA,iDACA,QACD;IACA,aAAa;KACZ,aACC,4BACA,6CACD;KACA,aACC,8BACA,+CACD;IACD;GACD;GACA,WAAW;IACV,MAAM,YAAY,WAAY,KAAM;IAEpC,IAAK,CAAE,eAAgB,WAAW,SAAU,GAC3C,YAAY;IAGb,OAAO;GACR;EACD;CACD,GAAG,CAAE,KAAM,CAAE;CAEb,MAAM,UAAU,qBACf,MAAM,WACN,MAAM,UACN,MAAM,QACP;CAEA,OACC,oBAAC,OAAD;EAAK,OAAQ,EAAE,SAAS,OAAO;EAC5B,UAAA,QAAQ,KAAO,EAAE,MAAM,MAAM,QAAQ,aACtC,oBAAC,uBAAD;GAEC,OAAQ,iBAAkB,MAAM,IAAK;GAErC,UAAA,oBAAC,qBAAD;IAA4B;IAAiB;IAC5C,UAAA,oBAAC,QAAD,CAAS,CAAA;GACW,CAAA;EACC,GANhB,IAMgB,CACtB;CACE,CAAA;AAEP"}