{"version":3,"file":"entity-provider.cjs","names":["useContext","EntityContext","useMemo"],"sources":["../src/entity-provider.tsx"],"sourcesContent":["import { useContext, useMemo } from '@wordpress/element';\nimport { EntityContext } from './entity-context';\nimport type { EntityProviderProps } from './types';\nimport type { PrivateEntityProviderProps } from './private-types';\n\n/**\n * Context provider component for providing\n * an entity for a specific entity.\n *\n * @param props            The component's props.\n * @param props.kind       The entity kind.\n * @param props.type       The entity name.\n * @param props.id         The entity ID.\n * @param props.revisionId Optional revision ID. When set,\n *                         `useEntityProp` reads from the\n *                         revision record instead of the\n *                         current entity. Applies only to this\n *                         entity, not to others rendered within\n *                         it.\n * @param props.children   The children to wrap.\n *\n * @return The provided children, wrapped with\n *         the entity's context provider.\n */\nexport default function EntityProvider( {\n\tkind,\n\ttype,\n\tid,\n\trevisionId,\n\tchildren,\n}: EntityProviderProps ) {\n\treturn (\n\t\t<PrivateEntityProvider\n\t\t\tkind={ kind }\n\t\t\ttype={ type }\n\t\t\tid={ id }\n\t\t\trevisionId={ revisionId }\n\t\t>\n\t\t\t{ children }\n\t\t</PrivateEntityProvider>\n\t);\n}\n\n/**\n * Like `EntityProvider`, but also accepts a record to read from instead of\n * the current entity, for content that isn't stored as a revision. Fields the\n * record doesn't have are read from the current entity.\n *\n * @param props            The component's props.\n * @param props.kind       The entity kind.\n * @param props.type       The entity name.\n * @param props.id         The entity ID.\n * @param props.revisionId Optional revision ID.\n * @param props.revision   Optional record to read from.\n * @param props.children   The children to wrap.\n *\n * @return The provided children, wrapped with\n *         the entity's context provider.\n */\nexport function PrivateEntityProvider( {\n\tkind,\n\ttype: name,\n\tid,\n\trevisionId,\n\trevision,\n\tchildren,\n}: PrivateEntityProviderProps ) {\n\tconst parent = useContext( EntityContext );\n\tconst providedRevision = revision ?? revisionId;\n\tconst childContext = useMemo(\n\t\t() => ( {\n\t\t\t...parent,\n\t\t\t...( kind && {\n\t\t\t\t[ kind ]: {\n\t\t\t\t\t...parent?.[ kind ],\n\t\t\t\t\t[ name ]: id,\n\t\t\t\t},\n\t\t\t} ),\n\t\t\t...( providedRevision !== undefined &&\n\t\t\t\tkind && {\n\t\t\t\t\trevision: {\n\t\t\t\t\t\t...parent?.revision,\n\t\t\t\t\t\t[ kind ]: {\n\t\t\t\t\t\t\t...parent?.revision?.[ kind ],\n\t\t\t\t\t\t\t[ name ]: providedRevision,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ parent, kind, name, id, providedRevision ]\n\t);\n\treturn (\n\t\t<EntityContext.Provider value={ childContext }>\n\t\t\t{ children }\n\t\t</EntityContext.Provider>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAwB,eAAgB,EACvC,MACA,MACA,IACA,YACA,YACwB;CACxB,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,uBAAD;EACQ;EACA;EACF;EACQ;EAEX;CACoB,CAAA;AAEzB;;;;;;;;;;;;;;;;;AAkBA,SAAgB,sBAAuB,EACtC,MACA,MAAM,MACN,IACA,YACA,UACA,YAC+B;CAC/B,MAAM,UAAA,GAASA,mBAAAA,WAAAA,CAAYC,oBAAAA,aAAc;CACzC,MAAM,mBAAmB,YAAY;CACrC,MAAM,gBAAA,GAAeC,mBAAAA,QAAAA,QACZ;EACP,GAAG;EACH,GAAK,QAAQ,GACV,OAAQ;GACT,GAAG,SAAU;IACX,OAAQ;EACX,EACD;EACA,GAAK,qBAAqB,KAAA,KACzB,QAAQ,EACP,UAAU;GACT,GAAG,QAAQ;IACT,OAAQ;IACT,GAAG,QAAQ,WAAY;KACrB,OAAQ;GACX;EACD,EACD;CACF,IACA;EAAE;EAAQ;EAAM;EAAM;EAAI;CAAiB,CAC5C;CACA,OACC,iBAAA,GAAA,kBAAA,IAAA,CAACD,oBAAAA,cAAc,UAAf;EAAwB,OAAQ;EAC7B;CACqB,CAAA;AAE1B"}