{"version":3,"file":"dashboard-policy.cjs","names":["createContext","useContext","useMemo"],"sources":["../../../src/components/dashboard-policy/dashboard-policy.tsx"],"sourcesContent":["import { createContext, useContext, useMemo } from '@wordpress/element';\nimport type { ReactNode } from 'react';\nimport type { CanPerformDashboardOperation } from '../../types';\n\nconst PolicyContext = createContext< CanPerformDashboardOperation | null >(\n\tnull\n);\n\ninterface WidgetDashboardPolicyProps {\n\t/**\n\t * Answers whether the dashboards below may perform an operation.\n\t */\n\tcanPerform: CanPerformDashboardOperation;\n\n\t/**\n\t * Subtree the policy governs.\n\t */\n\tchildren: ReactNode;\n}\n\n/**\n * Governs the dashboards below it. Mount it around one dashboard, a group,\n * or the whole application. Nested policies compose restrictively: an\n * operation is allowed only when every enclosing policy allows it. Without\n * a policy, every operation is allowed.\n *\n * @param {WidgetDashboardPolicyProps} props Component props.\n */\nexport function WidgetDashboardPolicy( {\n\tcanPerform,\n\tchildren,\n}: WidgetDashboardPolicyProps ) {\n\tconst parent = useContext( PolicyContext );\n\n\tconst value = useMemo< CanPerformDashboardOperation >(\n\t\t() =>\n\t\t\tparent\n\t\t\t\t? ( request ) => parent( request ) && canPerform( request )\n\t\t\t\t: canPerform,\n\t\t[ parent, canPerform ]\n\t);\n\n\treturn (\n\t\t<PolicyContext.Provider value={ value }>\n\t\t\t{ children }\n\t\t</PolicyContext.Provider>\n\t);\n}\n\n/**\n * Reads the policy in effect; `null` when none is mounted.\n */\nexport function useDashboardPolicy(): CanPerformDashboardOperation | null {\n\treturn useContext( PolicyContext );\n}\n"],"mappings":";;;;;;;;AAIA,MAAM,iBAAA,GAAgBA,mBAAAA,cAAAA,CACrB,IACD;;;;;;;;;AAsBA,SAAgB,sBAAuB,EACtC,YACA,YAC+B;CAC/B,MAAM,UAAA,GAASC,mBAAAA,WAAAA,CAAY,aAAc;CAEzC,MAAM,SAAA,GAAQC,mBAAAA,QAAAA,OAEZ,UACK,YAAa,OAAQ,OAAQ,KAAK,WAAY,OAAQ,IACxD,YACJ,CAAE,QAAQ,UAAW,CACtB;CAEA,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,cAAc,UAAf;EAAgC;EAC7B;CACqB,CAAA;AAE1B;;;;AAKA,SAAgB,qBAA0D;CACzE,QAAA,GAAOD,mBAAAA,WAAAA,CAAY,aAAc;AAClC"}