| 1 |
import apiFetch from '@wordpress/api-fetch'; |
| 2 |
import { dispatch, select } from '@wordpress/data'; |
| 3 |
import { __ } from '@wordpress/i18n'; |
| 4 |
|
| 5 |
const { globalStylesPostID } = window.extSharedData; |
| 6 |
|
| 7 |
export const updateVariation = (variation) => |
| 8 |
updateThemeVariation(globalStylesPostID, variation); |
| 9 |
|
| 10 |
export const updateThemeVariation = (id, variation = {}) => { |
| 11 |
const { settings, styles } = variation; |
| 12 |
if (!settings || !styles) return; |
| 13 |
return apiFetch({ |
| 14 |
path: `wp/v2/global-styles/${id}`, |
| 15 |
method: 'POST', |
| 16 |
data: { id, settings, styles }, |
| 17 |
}); |
| 18 |
}; |
| 19 |
|
| 20 |
export const updateGlobalStyles = (stylesData) => |
| 21 |
apiFetch({ |
| 22 |
path: `wp/v2/global-styles/${globalStylesPostID}`, |
| 23 |
method: 'POST', |
| 24 |
data: stylesData, |
| 25 |
}); |
| 26 |
|
| 27 |
export const getGlobalStyles = () => |
| 28 |
apiFetch({ path: `wp/v2/global-styles/themes/extendable?context=edit` }); |
| 29 |
|
| 30 |
export const updateTemplatePart = (slug, content) => |
| 31 |
apiFetch({ |
| 32 |
path: `wp/v2/template-parts/${slug}`, |
| 33 |
method: 'POST', |
| 34 |
data: { |
| 35 |
slug, |
| 36 |
theme: 'extendable', |
| 37 |
type: 'wp_template_part', |
| 38 |
status: 'publish', |
| 39 |
// See: https://github.com/extendify/company-product/issues/833#issuecomment-1804179527 |
| 40 |
// translators: Launch is the product name. Unless otherwise specified by the glossary, do not translate this name. |
| 41 |
description: __('Added by Launch', 'extendify-local'), |
| 42 |
content, |
| 43 |
}, |
| 44 |
}); |
| 45 |
|
| 46 |
// We set this to 'template-locked' to remove template from editor ui |
| 47 |
export const setThemeRenderingMode = (mode) => { |
| 48 |
const renderingModes = |
| 49 |
select('core/preferences').get('core', 'renderingModes') || {}; |
| 50 |
|
| 51 |
if (renderingModes?.extendable?.page === mode) return; |
| 52 |
dispatch('core/preferences').set('core', 'renderingModes', { |
| 53 |
...renderingModes, |
| 54 |
extendable: { |
| 55 |
...(renderingModes.extendable || {}), |
| 56 |
page: mode, |
| 57 |
}, |
| 58 |
}); |
| 59 |
}; |
| 60 |
|