@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
44 lines (43 loc) • 1.29 kB
JavaScript
import apiFetch from "@wordpress/api-fetch";
import { store } from "@wordpress/core-data";
// packages/global-styles-ui/src/font-library/api.ts
const FONT_FAMILIES_URL = "/wp/v2/font-families";
/**
* Invalidates the cache for font family queries.
* This should be called after installing fonts
* to ensure the UI reflects the latest state.
*
* @param registry The data registry to use for dispatching actions.
*/
function invalidateFontFamilyCache(registry) {
const { receiveEntityRecords } = registry.dispatch(store);
receiveEntityRecords("postType", "wp_font_family", [], void 0, true);
}
async function fetchInstallFontFamily(data, registry) {
const response = await apiFetch({
path: FONT_FAMILIES_URL,
method: "POST",
body: data
});
invalidateFontFamilyCache(registry);
return {
id: response.id,
...response.font_family_settings,
fontFace: []
};
}
async function fetchInstallFontFace(fontFamilyId, data, registry) {
const config = {
path: `${FONT_FAMILIES_URL}/${fontFamilyId}/font-faces`,
method: "POST",
body: data
};
const response = await apiFetch(config);
invalidateFontFamilyCache(registry);
return {
id: response.id,
...response.font_face_settings
};
}
export { fetchInstallFontFace, fetchInstallFontFamily };
//# sourceMappingURL=api.mjs.map