UNPKG

@wordpress/editor

Version:
8 lines (7 loc) 1.69 kB
{ "version": 3, "sources": ["../../../src/components/post-fields/index.ts"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport type { Field } from '@wordpress/dataviews';\nimport type { BasePostWithEmbeddedAuthor } from '@wordpress/fields';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport { store as editorStore } from '../../store';\n\nfunction usePostFields( {\n\tpostType,\n}: {\n\tpostType: string;\n} ): Field< BasePostWithEmbeddedAuthor >[] {\n\tconst { registerPostTypeSchema } = unlock( useDispatch( editorStore ) );\n\tuseEffect( () => {\n\t\tregisterPostTypeSchema( postType );\n\t}, [ registerPostTypeSchema, postType ] );\n\n\tconst { fields } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityFields } = unlock( select( editorStore ) );\n\t\t\treturn {\n\t\t\t\tfields: getEntityFields( 'postType', postType ),\n\t\t\t};\n\t\t},\n\t\t[ postType ]\n\t);\n\n\treturn fields;\n}\n\n/**\n * Hook to get the fields for a post (BasePost or BasePostWithEmbeddedAuthor).\n */\nexport default usePostFields;\n"], "mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,aAAa,iBAAiB;AAOvC,SAAS,cAAc;AACvB,SAAS,SAAS,mBAAmB;AAErC,SAAS,cAAe;AAAA,EACvB;AACD,GAE2C;AAC1C,QAAM,EAAE,uBAAuB,IAAI,OAAQ,YAAa,WAAY,CAAE;AACtE,YAAW,MAAM;AAChB,2BAAwB,QAAS;AAAA,EAClC,GAAG,CAAE,wBAAwB,QAAS,CAAE;AAExC,QAAM,EAAE,OAAO,IAAI;AAAA,IAClB,CAAE,WAAY;AACb,YAAM,EAAE,gBAAgB,IAAI,OAAQ,OAAQ,WAAY,CAAE;AAC1D,aAAO;AAAA,QACN,QAAQ,gBAAiB,YAAY,QAAS;AAAA,MAC/C;AAAA,IACD;AAAA,IACA,CAAE,QAAS;AAAA,EACZ;AAEA,SAAO;AACR;AAKA,IAAO,sBAAQ;", "names": [] }