UNPKG

@wordpress/global-styles-ui

Version:
72 lines (71 loc) • 2.58 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); // \0rolldown/runtime.js var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { key = keys[i]; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: ((k) => from[k]).bind(null, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); let _wordpress_api_fetch = require("@wordpress/api-fetch"); _wordpress_api_fetch = __toESM(_wordpress_api_fetch); let _wordpress_core_data = require("@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(_wordpress_core_data.store); receiveEntityRecords("postType", "wp_font_family", [], void 0, true); } async function fetchInstallFontFamily(data, registry) { const response = await (0, _wordpress_api_fetch.default)({ 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 (0, _wordpress_api_fetch.default)(config); invalidateFontFamilyCache(registry); return { id: response.id, ...response.font_face_settings }; } exports.fetchInstallFontFace = fetchInstallFontFace; exports.fetchInstallFontFamily = fetchInstallFontFamily; //# sourceMappingURL=api.cjs.map