@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
1 lines • 2.52 kB
Source Map (JSON)
{"version":3,"file":"api.mjs","names":["coreDataStore"],"sources":["../../src/font-library/api.ts"],"sourcesContent":["import apiFetch from '@wordpress/api-fetch';\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport type {\n\tCollectionFontFace,\n\tCollectionFontFamily,\n\tFontFace,\n} from '@wordpress/core-data';\nimport type { DataRegistry } from '@wordpress/data';\n\nconst FONT_FAMILIES_URL = '/wp/v2/font-families';\n\n/**\n * Invalidates the cache for font family queries.\n * This should be called after installing fonts\n * to ensure the UI reflects the latest state.\n *\n * @param registry The data registry to use for dispatching actions.\n */\nfunction invalidateFontFamilyCache( registry: DataRegistry ) {\n\tconst { receiveEntityRecords } = registry.dispatch( coreDataStore );\n\n\t// Invalidate all font family queries\n\t// Ideally there should be a dedicated action to do this\n\t// \"invalid all caches for this entity type\"\n\treceiveEntityRecords(\n\t\t'postType',\n\t\t'wp_font_family',\n\t\t[],\n\t\tundefined,\n\t\ttrue // invalidateCache\n\t);\n}\n\nexport async function fetchInstallFontFamily(\n\tdata: FormData,\n\tregistry: DataRegistry\n) {\n\tconst config = {\n\t\tpath: FONT_FAMILIES_URL,\n\t\tmethod: 'POST',\n\t\tbody: data,\n\t};\n\tconst response: CollectionFontFamily = await apiFetch( config );\n\tinvalidateFontFamilyCache( registry );\n\n\treturn {\n\t\tid: response.id as string,\n\t\t...response.font_family_settings,\n\t\tfontFace: [],\n\t};\n}\n\nexport async function fetchInstallFontFace(\n\tfontFamilyId: string,\n\tdata: FormData,\n\tregistry: DataRegistry\n): Promise< FontFace > {\n\tconst config = {\n\t\tpath: `${ FONT_FAMILIES_URL }/${ fontFamilyId }/font-faces`,\n\t\tmethod: 'POST',\n\t\tbody: data,\n\t};\n\tconst response = ( await apiFetch( config ) ) as CollectionFontFace;\n\tinvalidateFontFamilyCache( registry );\n\treturn {\n\t\tid: response.id,\n\t\t...response.font_face_settings,\n\t};\n}\n"],"mappings":";;;AASA,MAAM,oBAAoB;;;;;;;;AAS1B,SAAS,0BAA2B,UAAyB;CAC5D,MAAM,EAAE,yBAAyB,SAAS,SAAUA,KAAc;CAKlE,qBACC,YACA,kBACA,CAAC,GACD,KAAA,GACA,IACD;AACD;AAEA,eAAsB,uBACrB,MACA,UACC;CAMD,MAAM,WAAiC,MAAM,SAAU;EAJtD,MAAM;EACN,QAAQ;EACR,MAAM;CAEqD,CAAE;CAC9D,0BAA2B,QAAS;CAEpC,OAAO;EACN,IAAI,SAAS;EACb,GAAG,SAAS;EACZ,UAAU,CAAC;CACZ;AACD;AAEA,eAAsB,qBACrB,cACA,MACA,UACsB;CACtB,MAAM,SAAS;EACd,MAAM,GAAI,kBAAmB,GAAI,aAAc;EAC/C,QAAQ;EACR,MAAM;CACP;CACA,MAAM,WAAa,MAAM,SAAU,MAAO;CAC1C,0BAA2B,QAAS;CACpC,OAAO;EACN,IAAI,SAAS;EACb,GAAG,SAAS;CACb;AACD"}