{"version":3,"file":"index.cjs","names":["createContext","useContext","createHigherOrderComponent"],"sources":["../../../src/components/plugin-context/index.tsx"],"sourcesContent":["import { createContext, useContext } from '@wordpress/element';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport deprecated from '@wordpress/deprecated';\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAM,WAAA,GAAUA,mBAAAA,cAAAA,CAAgC;CAC/C,MAAM;CACN,MAAM;AACP,CAAE;AACF,QAAQ,cAAc;AAEtB,MAAa,wBAAwB,QAAQ;;;;;;AAO7C,SAAgB,mBAAmB;CAClC,QAAA,GAAOC,mBAAAA,WAAAA,CAAY,OAAQ;AAC5B;;;;;;;;;;;;;AAcA,MAAa,qBACZ,uBAAA,GAKAC,mBAAAA,2BAAAA,EAA8B,sBAAuB;CACpD,CAAA,GAAA,sBAAA,QAAA,CAAY,gCAAgC;EAC3C,OAAO;EACP,aAAa;CACd,CAAE;CACF,QAAS,UACR,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAQ,UAAT,EAAA,WACK,YACH,iBAAA,GAAA,kBAAA,IAAA,CAAC,mBAAD;EACC,GAAK;EACL,GAAK,kBAAmB,SAAS,KAAM;CACvC,CAAA,EAEe,CAAA;AAEpB,GAAG,mBAAoB"}