{
  "version": 3,
  "sources": ["../../src/hooks/use-entity-prop.js"],
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useContext } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../name';\nimport { DEFAULT_ENTITY_KEY } from '../entities';\nimport { EntityContext } from '../entity-context';\nimport useEntityId from './use-entity-id';\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string}        kind  The entity kind.\n * @param {string}        name  The entity name.\n * @param {string}        prop  The property name.\n * @param {number|string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n *                            property value, the second is the\n *                            setter and the third is the full value\n * \t\t\t\t\t\t\t  object from REST API containing more\n * \t\t\t\t\t\t\t  information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t  `protected` props.\n */\nexport default function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst context = useContext( EntityContext );\n\tconst revisionId = context?.revisionId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( revisionId ) {\n\t\t\t\t// Use getRevisions (not getRevision) to read from the\n\t\t\t\t// already-cached collection. Using getRevision would\n\t\t\t\t// trigger a redundant single-revision API fetch that\n\t\t\t\t// can wipe the collection due to a race condition.\n\t\t\t\t// See https://github.com/WordPress/gutenberg/pull/76043.\n\t\t\t\tconst revisions = select( STORE_NAME ).getRevisions(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t\t{\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t\tcontext: 'edit',\n\t\t\t\t\t\t_fields:\n\t\t\t\t\t\t\t'id,date,author,meta,title.raw,excerpt.raw,content.raw',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\tconst entityConfig = select( STORE_NAME ).getEntityConfig(\n\t\t\t\t\tkind,\n\t\t\t\t\tname\n\t\t\t\t);\n\t\t\t\tconst revKey = entityConfig?.revisionKey || DEFAULT_ENTITY_KEY;\n\t\t\t\tconst revision = revisions?.find(\n\t\t\t\t\t( r ) => r[ revKey ] === revisionId\n\t\t\t\t);\n\t\t\t\treturn revision\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tvalue: revision[ prop ]?.raw ?? revision[ prop ],\n\t\t\t\t\t\t\tfullValue: revision[ prop ],\n\t\t\t\t\t  }\n\t\t\t\t\t: {};\n\t\t\t}\n\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t  }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop, revisionId ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\tif ( revisionId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ editEntityRecord, kind, name, id, prop, revisionId ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAwC;AACxC,kBAAuC;AAKvC,kBAA2B;AAC3B,sBAAmC;AACnC,4BAA8B;AAC9B,2BAAwB;AAmBT,SAAR,cAAgC,MAAM,MAAM,MAAM,KAAM;AAC9D,QAAM,iBAAa,qBAAAA,SAAa,MAAM,IAAK;AAC3C,QAAM,KAAK,OA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