auto-patch 638-dev-dev01-2024-05-14T20_44_36

This commit is contained in:
root
2024-05-14 20:44:36 +00:00
parent a941559057
commit 5dbb0b284e
1812 changed files with 29671 additions and 14588 deletions

View File

@@ -9658,6 +9658,45 @@ function useSupportedStyles(name, element) {
return supportedPanels;
}
;// CONCATENATED MODULE: ./node_modules/@wordpress/edit-site/build-module/utils/set-nested-value.js
/**
* Sets the value at path of object.
* If a portion of path doesnt exist, its created.
* Arrays are created for missing index properties while objects are created
* for all other missing properties.
*
* This function intentionally mutates the input object.
*
* Inspired by _.set().
*
* @see https://lodash.com/docs/4.17.15#set
*
* @todo Needs to be deduplicated with its copy in `@wordpress/core-data`.
*
* @param {Object} object Object to modify
* @param {Array} path Path of the property to set.
* @param {*} value Value to set.
*/
function setNestedValue(object, path, value) {
if (!object || typeof object !== 'object') {
return object;
}
path.reduce((acc, key, idx) => {
if (acc[key] === undefined) {
if (Number.isInteger(path[idx + 1])) {
acc[key] = [];
} else {
acc[key] = {};
}
}
if (idx === path.length - 1) {
acc[key] = value;
}
return acc[key];
}, object);
return object;
}
;// CONCATENATED MODULE: ./node_modules/@wordpress/edit-site/build-module/hooks/push-changes-to-global-styles/index.js
/**
@@ -9679,6 +9718,7 @@ function useSupportedStyles(name, element) {
*/
const {
cleanEmptyObject,
GlobalStylesContext
@@ -9877,44 +9917,6 @@ function useChangesToPush(name, attributes, userConfig) {
return changes;
}, [supports, attributes, blockUserConfig]);
}
/**
* Sets the value at path of object.
* If a portion of path doesnt exist, its created.
* Arrays are created for missing index properties while objects are created
* for all other missing properties.
*
* This function intentionally mutates the input object.
*
* Inspired by _.set().
*
* @see https://lodash.com/docs/4.17.15#set
*
* @todo Needs to be deduplicated with its copy in `@wordpress/core-data`.
*
* @param {Object} object Object to modify
* @param {Array} path Path of the property to set.
* @param {*} value Value to set.
*/
function setNestedValue(object, path, value) {
if (!object || typeof object !== 'object') {
return object;
}
path.reduce((acc, key, idx) => {
if (acc[key] === undefined) {
if (Number.isInteger(path[idx + 1])) {
acc[key] = [];
} else {
acc[key] = {};
}
}
if (idx === path.length - 1) {
acc[key] = value;
}
return acc[key];
}, object);
return object;
}
function cloneDeep(object) {
return !object ? {} : JSON.parse(JSON.stringify(object));
}
@@ -17917,6 +17919,7 @@ function useResolveEditedEntityAndContext({
const {
hasLoadedAllDependencies,
homepageId,
postsPageId,
url,
frontPageTemplateId
} = (0,external_wp_data_namespaceObject.useSelect)(select => {
@@ -17930,16 +17933,20 @@ function useResolveEditedEntityAndContext({
const templates = getEntityRecords('postType', constants_TEMPLATE_POST_TYPE, {
per_page: -1
});
let _frontPateTemplateId;
const _homepageId = siteData?.show_on_front === 'page' && ['number', 'string'].includes(typeof siteData.page_on_front) && !!+siteData.page_on_front // We also need to check if it's not zero(`0`).
? siteData.page_on_front.toString() : null;
const _postsPageId = siteData?.show_on_front === 'page' && ['number', 'string'].includes(typeof siteData.page_for_posts) ? siteData.page_for_posts.toString() : null;
let _frontPageTemplateId;
if (templates) {
const frontPageTemplate = templates.find(t => t.slug === 'front-page');
_frontPateTemplateId = frontPageTemplate ? frontPageTemplate.id : false;
_frontPageTemplateId = frontPageTemplate ? frontPageTemplate.id : false;
}
return {
hasLoadedAllDependencies: !!base && !!siteData,
homepageId: siteData?.show_on_front === 'page' && ['number', 'string'].includes(typeof siteData.page_on_front) ? siteData.page_on_front.toString() : null,
homepageId: _homepageId,
postsPageId: _postsPageId,
url: base?.home,
frontPageTemplateId: _frontPateTemplateId
frontPageTemplateId: _frontPageTemplateId
};
}, []);
@@ -17977,6 +17984,10 @@ function useResolveEditedEntityAndContext({
if (!editedEntity) {
return undefined;
}
// Check if the current page is the posts page.
if (postTypeToResolve === 'page' && postsPageId === postIdToResolve) {
return __experimentalGetTemplateForLink(editedEntity.link)?.id;
}
// First see if the post/page has an assigned template and fetch it.
const currentTemplateSlug = editedEntity.template;
if (currentTemplateSlug) {
@@ -18028,7 +18039,7 @@ function useResolveEditedEntityAndContext({
const template = __experimentalGetTemplateForLink(url);
return template?.id;
}
}, [homepageId, hasLoadedAllDependencies, url, postId, postType, path, frontPageTemplateId]);
}, [homepageId, postsPageId, hasLoadedAllDependencies, url, postId, postType, path, frontPageTemplateId]);
const context = (0,external_wp_element_namespaceObject.useMemo)(() => {
if (postTypesWithoutParentTemplate.includes(postType)) {
return {};
@@ -26985,12 +26996,13 @@ const {
} = unlock(external_wp_blockEditor_namespaceObject.privateApis);
const FontLibraryContext = (0,external_wp_element_namespaceObject.createContext)({});
function FontLibraryProvider({
children
}) {
const {
__experimentalSaveSpecifiedEntityEdits: saveSpecifiedEntityEdits
saveEntityRecord
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_coreData_namespaceObject.store);
const {
globalStylesId
@@ -27031,9 +27043,25 @@ function FontLibraryProvider({
// theme.json file font families
const [baseFontFamilies] = context_useGlobalSetting('typography.fontFamilies', undefined, 'base');
// Save font families to the global styles post in the database.
const saveFontFamilies = () => {
saveSpecifiedEntityEdits('root', 'globalStyles', globalStylesId, ['settings.typography.fontFamilies']);
/*
* Save the font families to the database.
* This function is called when the user activates or deactivates a font family.
* It only updates the global styles post content in the database for new font families.
* This avoids saving other styles/settings changed by the user using other parts of the editor.
*
* It uses the font families from the param to avoid using the font families from an outdated state.
*
* @param {Array} fonts - The font families that will be saved to the database.
*/
const saveFontFamilies = async fonts => {
// Gets the global styles database post content.
const updatedGlobalStyles = globalStyles.record;
// Updates the database version of global styles with the edited font families in the client.
setNestedValue(updatedGlobalStyles, ['settings', 'typography', 'fontFamilies'], fonts);
// Saves a new version of the global styles in the database.
await saveEntityRecord('root', 'globalStyles', updatedGlobalStyles);
};
// Library Fonts
@@ -27176,10 +27204,9 @@ function FontLibraryProvider({
installationErrors = installationErrors.reduce((unique, item) => unique.includes(item.message) ? unique : [...unique, item.message], []);
if (fontFamiliesToActivate.length > 0) {
// Activate the font family (add the font family to the global styles).
activateCustomFontFamilies(fontFamiliesToActivate);
const activeFonts = activateCustomFontFamilies(fontFamiliesToActivate);
// Save the global styles to the database.
await saveSpecifiedEntityEdits('root', 'globalStyles', globalStylesId, ['settings.typography.fontFamilies']);
await saveFontFamilies(activeFonts);
refreshLibrary();
}
if (installationErrors.length > 0) {
@@ -27200,9 +27227,9 @@ function FontLibraryProvider({
// Deactivate the font family if delete request is successful
// (Removes the font family from the global styles).
if (uninstalledFontFamily.deleted) {
deactivateFontFamily(fontFamilyToUninstall);
const activeFonts = deactivateFontFamily(fontFamilyToUninstall);
// Save the global styles to the database.
await saveSpecifiedEntityEdits('root', 'globalStyles', globalStylesId, ['settings.typography.fontFamilies']);
await saveFontFamilies(activeFonts);
}
// Refresh the library (the library font families from database).
@@ -27220,19 +27247,35 @@ function FontLibraryProvider({
// We want to save as active all the theme fonts at the beginning
const initialCustomFonts = (_fontFamilies$font$so = fontFamilies?.[font.source]) !== null && _fontFamilies$font$so !== void 0 ? _fontFamilies$font$so : [];
const newCustomFonts = initialCustomFonts.filter(f => f.slug !== font.slug);
setFontFamilies({
const activeFonts = {
...fontFamilies,
[font.source]: newCustomFonts
});
};
setFontFamilies(activeFonts);
if (font.fontFace) {
font.fontFace.forEach(face => {
unloadFontFaceInBrowser(face, 'all');
});
}
return activeFonts;
};
const activateCustomFontFamilies = fontsToAdd => {
// Removes the id from the families and faces to avoid saving that to global styles post content.
const fontsToActivate = fontsToAdd.map(({
const fontsToActivate = cleanFontsForSave(fontsToAdd);
const activeFonts = {
...fontFamilies,
// Merge the existing custom fonts with the new fonts.
custom: mergeFontFamilies(fontFamilies?.custom, fontsToActivate)
};
// Activate the fonts by set the new custom fonts array.
setFontFamilies(activeFonts);
loadFontsInBrowser(fontsToActivate);
return activeFonts;
};
// Removes the id from the families and faces to avoid saving that to global styles post content.
const cleanFontsForSave = fonts => {
return fonts.map(({
id: _familyDbId,
fontFace,
...font
@@ -27245,16 +27288,10 @@ function FontLibraryProvider({
}) => face)
} : {})
}));
// Activate the fonts by set the new custom fonts array.
setFontFamilies({
...fontFamilies,
// Merge the existing custom fonts with the new fonts.
custom: mergeFontFamilies(fontFamilies?.custom, fontsToActivate)
});
};
const loadFontsInBrowser = fonts => {
// Add custom fonts to the browser.
fontsToActivate.forEach(font => {
fonts.forEach(font => {
if (font.fontFace) {
font.fontFace.forEach(face => {
// Load font faces just in the iframe because they already are in the document.
@@ -27324,6 +27361,7 @@ function FontLibraryProvider({
value: {
libraryFontSelected,
handleSetLibraryFontSelected,
fontFamilies,
themeFonts,
baseThemeFonts,
customFonts,
@@ -27622,7 +27660,8 @@ function InstalledFonts() {
getFontFacesActivated,
fontFamiliesHasChanges,
notice,
setNotice
setNotice,
fontFamilies
} = (0,external_wp_element_namespaceObject.useContext)(FontLibraryContext);
const [isConfirmDeleteOpen, setIsConfirmDeleteOpen] = (0,external_wp_element_namespaceObject.useState)(false);
const customFontFamilyId = libraryFontSelected?.source === 'custom' && libraryFontSelected?.id;
@@ -27700,9 +27739,7 @@ function InstalledFonts() {
onClick: () => {
handleSetLibraryFontSelected(font);
}
}))), (0,external_React_.createElement)(external_wp_components_namespaceObject.__experimentalSpacer, {
margin: 16
})), (0,external_React_.createElement)(external_wp_components_namespaceObject.__experimentalNavigatorScreen, {
})))), (0,external_React_.createElement)(external_wp_components_namespaceObject.__experimentalNavigatorScreen, {
path: "/fontFamily"
}, (0,external_React_.createElement)(ConfirmDeleteDialog, {
font: libraryFontSelected,
@@ -27752,7 +27789,9 @@ function InstalledFonts() {
onClick: handleUninstallClick
}, (0,external_wp_i18n_namespaceObject.__)('Delete')), (0,external_React_.createElement)(external_wp_components_namespaceObject.Button, {
variant: "primary",
onClick: saveFontFamilies,
onClick: () => {
saveFontFamilies(fontFamilies);
},
disabled: !fontFamiliesHasChanges,
__experimentalIsFocusable: true
}, (0,external_wp_i18n_namespaceObject.__)('Update'))));
@@ -28188,6 +28227,7 @@ function FontCollection({
isSmall: true,
onClick: () => {
setSelectedFont(null);
setNotice(null);
},
"aria-label": (0,external_wp_i18n_namespaceObject.__)('Navigate to the previous view')
}), (0,external_React_.createElement)(external_wp_components_namespaceObject.__experimentalHeading, {
@@ -32375,7 +32415,7 @@ const {
} = unlock(external_wp_components_namespaceObject.privateApis);
const DEFAULT_TAB = {
id: 'installed-fonts',
title: (0,external_wp_i18n_namespaceObject.__)('Library')
title: (0,external_wp_i18n_namespaceObject._x)('Library', 'Font library')
};
const UPLOAD_TAB = {
id: 'upload-fonts',