@wordpress/block-editor 12.3.4 → 12.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +4 -0
- package/build/components/block-heading-level-dropdown/heading-level-icon.js +10 -2
- package/build/components/block-heading-level-dropdown/heading-level-icon.js.map +1 -1
- package/build/components/block-heading-level-dropdown/index.native.js +4 -3
- package/build/components/block-heading-level-dropdown/index.native.js.map +1 -1
- package/build/components/block-parent-selector/index.js +8 -5
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-removal-warning-modal/index.js +18 -25
- package/build/components/block-removal-warning-modal/index.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +7 -11
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/global-styles/color-panel.js +1 -1
- package/build/components/global-styles/color-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +2 -2
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +34 -2
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/index.js +19 -1
- package/build/components/index.js.map +1 -1
- package/build/components/inserter/media-tab/hooks.js +2 -21
- package/build/components/inserter/media-tab/hooks.js.map +1 -1
- package/build/components/inserter/reusable-block-rename-hint.js +62 -0
- package/build/components/inserter/reusable-block-rename-hint.js.map +1 -0
- package/build/components/inserter/reusable-blocks-tab.js +5 -1
- package/build/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build/components/inserter/reusable-blocks-tab.native.js +2 -2
- package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build/components/inserter/tabs.native.js +1 -1
- package/build/components/inserter/tabs.native.js.map +1 -1
- package/build/components/inserter-draggable-blocks/index.js +9 -1
- package/build/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build/components/link-control/constants.js +1 -1
- package/build/components/link-control/constants.js.map +1 -1
- package/build/components/link-control/search-create-button.js +5 -21
- package/build/components/link-control/search-create-button.js.map +1 -1
- package/build/components/link-control/search-item.js +13 -30
- package/build/components/link-control/search-item.js.map +1 -1
- package/build/components/link-control/search-results.js +2 -2
- package/build/components/link-control/search-results.js.map +1 -1
- package/build/components/list-view/appender.js +2 -6
- package/build/components/list-view/appender.js.map +1 -1
- package/build/components/provider/index.js +5 -2
- package/build/components/provider/index.js.map +1 -1
- package/build/components/writing-flow/use-tab-nav.js +10 -27
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build/components/writing-mode-control/index.js +70 -0
- package/build/components/writing-mode-control/index.js.map +1 -0
- package/build/hooks/behaviors.js +25 -20
- package/build/hooks/behaviors.js.map +1 -1
- package/build/hooks/supports.js +7 -1
- package/build/hooks/supports.js.map +1 -1
- package/build/hooks/typography.js +2 -1
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/utils.js +4 -2
- package/build/hooks/utils.js.map +1 -1
- package/build/private-apis.js +3 -0
- package/build/private-apis.js.map +1 -1
- package/build/private-apis.native.js +3 -0
- package/build/private-apis.native.js.map +1 -1
- package/build/store/actions.js +195 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +10 -1
- package/build/store/index.js.map +1 -1
- package/build/store/private-actions.js +46 -40
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +3 -3
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +22 -8
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +6 -4
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-heading-level-dropdown/heading-level-icon.js +9 -2
- package/build-module/components/block-heading-level-dropdown/heading-level-icon.js.map +1 -1
- package/build-module/components/block-heading-level-dropdown/index.native.js +4 -3
- package/build-module/components/block-heading-level-dropdown/index.native.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +7 -5
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-removal-warning-modal/index.js +19 -23
- package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +8 -11
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/global-styles/color-panel.js +1 -1
- package/build-module/components/global-styles/color-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +2 -2
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +33 -2
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/index.js +6 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inserter/media-tab/hooks.js +2 -21
- package/build-module/components/inserter/media-tab/hooks.js.map +1 -1
- package/build-module/components/inserter/reusable-block-rename-hint.js +48 -0
- package/build-module/components/inserter/reusable-block-rename-hint.js.map +1 -0
- package/build-module/components/inserter/reusable-blocks-tab.js +4 -1
- package/build-module/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build-module/components/inserter/reusable-blocks-tab.native.js +2 -2
- package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build-module/components/inserter/tabs.native.js +1 -1
- package/build-module/components/inserter/tabs.native.js.map +1 -1
- package/build-module/components/inserter-draggable-blocks/index.js +9 -2
- package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
- package/build-module/components/link-control/constants.js +1 -1
- package/build-module/components/link-control/constants.js.map +1 -1
- package/build-module/components/link-control/search-create-button.js +7 -20
- package/build-module/components/link-control/search-create-button.js.map +1 -1
- package/build-module/components/link-control/search-item.js +14 -28
- package/build-module/components/link-control/search-item.js.map +1 -1
- package/build-module/components/link-control/search-results.js +3 -3
- package/build-module/components/link-control/search-results.js.map +1 -1
- package/build-module/components/list-view/appender.js +2 -6
- package/build-module/components/list-view/appender.js.map +1 -1
- package/build-module/components/provider/index.js +5 -2
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/writing-flow/use-tab-nav.js +8 -26
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/components/writing-mode-control/index.js +57 -0
- package/build-module/components/writing-mode-control/index.js.map +1 -0
- package/build-module/hooks/behaviors.js +26 -20
- package/build-module/hooks/behaviors.js.map +1 -1
- package/build-module/hooks/supports.js +7 -1
- package/build-module/hooks/supports.js.map +1 -1
- package/build-module/hooks/typography.js +2 -1
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/utils.js +4 -2
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/private-apis.js +2 -0
- package/build-module/private-apis.js.map +1 -1
- package/build-module/private-apis.native.js +2 -0
- package/build-module/private-apis.native.js.map +1 -1
- package/build-module/store/actions.js +191 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +10 -1
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-actions.js +45 -36
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +2 -2
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +22 -8
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +6 -4
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +88 -81
- package/build-style/style.css +88 -81
- package/package.json +31 -31
- package/src/components/block-draggable/style.scss +1 -0
- package/src/components/block-heading-level-dropdown/heading-level-icon.js +6 -1
- package/src/components/block-heading-level-dropdown/index.native.js +8 -4
- package/src/components/block-inspector/style.scss +2 -1
- package/src/components/block-parent-selector/index.js +13 -8
- package/src/components/block-removal-warning-modal/index.js +16 -27
- package/src/components/block-tools/block-contextual-toolbar.js +5 -11
- package/src/components/block-tools/style.scss +69 -26
- package/src/components/font-family/README.md +71 -0
- package/src/components/global-styles/color-panel.js +1 -1
- package/src/components/global-styles/hooks.js +2 -0
- package/src/components/global-styles/typography-panel.js +40 -0
- package/src/components/index.js +6 -0
- package/src/components/inserter/media-tab/hooks.js +2 -22
- package/src/components/inserter/reusable-block-rename-hint.js +52 -0
- package/src/components/inserter/reusable-blocks-tab.js +4 -0
- package/src/components/inserter/reusable-blocks-tab.native.js +2 -2
- package/src/components/inserter/style.scss +28 -0
- package/src/components/inserter/tabs.native.js +5 -1
- package/src/components/inserter-draggable-blocks/index.js +13 -2
- package/src/components/link-control/constants.js +1 -1
- package/src/components/link-control/search-create-button.js +8 -26
- package/src/components/link-control/search-item.js +21 -43
- package/src/components/link-control/search-results.js +48 -46
- package/src/components/link-control/style.scss +18 -68
- package/src/components/link-control/test/index.js +6 -7
- package/src/components/list-view/appender.js +5 -6
- package/src/components/panel-color-settings/README.md +98 -0
- package/src/components/provider/index.js +9 -2
- package/src/components/recursion-provider/README.md +101 -0
- package/src/components/writing-flow/use-tab-nav.js +10 -33
- package/src/components/writing-mode-control/index.js +68 -0
- package/src/components/writing-mode-control/style.scss +18 -0
- package/src/hooks/behaviors.js +25 -16
- package/src/hooks/supports.js +7 -0
- package/src/hooks/typography.js +2 -0
- package/src/hooks/utils.js +3 -0
- package/src/private-apis.js +2 -0
- package/src/private-apis.native.js +2 -0
- package/src/store/actions.js +194 -1
- package/src/store/index.js +10 -0
- package/src/store/private-actions.js +39 -39
- package/src/store/private-selectors.js +2 -2
- package/src/store/reducer.js +22 -8
- package/src/store/selectors.js +9 -6
- package/src/store/test/actions.js +111 -0
- package/src/store/test/private-actions.js +56 -0
package/src/store/actions.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint no-console: [ 'error', { allow: [ 'error', 'warn' ] } ] */
|
|
1
2
|
/**
|
|
2
3
|
* WordPress dependencies
|
|
3
4
|
*/
|
|
@@ -1389,7 +1390,9 @@ export function updateBlockListSettings( clientId, settings ) {
|
|
|
1389
1390
|
* @return {Object} Action object
|
|
1390
1391
|
*/
|
|
1391
1392
|
export function updateSettings( settings ) {
|
|
1392
|
-
return __experimentalUpdateSettings( settings,
|
|
1393
|
+
return __experimentalUpdateSettings( settings, {
|
|
1394
|
+
stripExperimentalSettings: true,
|
|
1395
|
+
} );
|
|
1393
1396
|
}
|
|
1394
1397
|
|
|
1395
1398
|
/**
|
|
@@ -1692,3 +1695,193 @@ export function __unstableSetTemporarilyEditingAsBlocks(
|
|
|
1692
1695
|
temporarilyEditingAsBlocks,
|
|
1693
1696
|
};
|
|
1694
1697
|
}
|
|
1698
|
+
|
|
1699
|
+
/**
|
|
1700
|
+
* Interface for inserter media requests.
|
|
1701
|
+
*
|
|
1702
|
+
* @typedef {Object} InserterMediaRequest
|
|
1703
|
+
* @property {number} per_page How many items to fetch per page.
|
|
1704
|
+
* @property {string} search The search term to use for filtering the results.
|
|
1705
|
+
*/
|
|
1706
|
+
|
|
1707
|
+
/**
|
|
1708
|
+
* Interface for inserter media responses. Any media resource should
|
|
1709
|
+
* map their response to this interface, in order to create the core
|
|
1710
|
+
* WordPress media blocks (image, video, audio).
|
|
1711
|
+
*
|
|
1712
|
+
* @typedef {Object} InserterMediaItem
|
|
1713
|
+
* @property {string} title The title of the media item.
|
|
1714
|
+
* @property {string} url The source url of the media item.
|
|
1715
|
+
* @property {string} [previewUrl] The preview source url of the media item to display in the media list.
|
|
1716
|
+
* @property {number} [id] The WordPress id of the media item.
|
|
1717
|
+
* @property {number|string} [sourceId] The id of the media item from external source.
|
|
1718
|
+
* @property {string} [alt] The alt text of the media item.
|
|
1719
|
+
* @property {string} [caption] The caption of the media item.
|
|
1720
|
+
*/
|
|
1721
|
+
|
|
1722
|
+
/**
|
|
1723
|
+
* Registers a new inserter media category. Once registered, the media category is
|
|
1724
|
+
* available in the inserter's media tab.
|
|
1725
|
+
*
|
|
1726
|
+
* The following interfaces are used:
|
|
1727
|
+
*
|
|
1728
|
+
* _Type Definition_
|
|
1729
|
+
*
|
|
1730
|
+
* - _InserterMediaRequest_ `Object`: Interface for inserter media requests.
|
|
1731
|
+
*
|
|
1732
|
+
* _Properties_
|
|
1733
|
+
*
|
|
1734
|
+
* - _per_page_ `number`: How many items to fetch per page.
|
|
1735
|
+
* - _search_ `string`: The search term to use for filtering the results.
|
|
1736
|
+
*
|
|
1737
|
+
* _Type Definition_
|
|
1738
|
+
*
|
|
1739
|
+
* - _InserterMediaItem_ `Object`: Interface for inserter media responses. Any media resource should
|
|
1740
|
+
* map their response to this interface, in order to create the core
|
|
1741
|
+
* WordPress media blocks (image, video, audio).
|
|
1742
|
+
*
|
|
1743
|
+
* _Properties_
|
|
1744
|
+
*
|
|
1745
|
+
* - _title_ `string`: The title of the media item.
|
|
1746
|
+
* - _url_ `string: The source url of the media item.
|
|
1747
|
+
* - _previewUrl_ `[string]`: The preview source url of the media item to display in the media list.
|
|
1748
|
+
* - _id_ `[number]`: The WordPress id of the media item.
|
|
1749
|
+
* - _sourceId_ `[number|string]`: The id of the media item from external source.
|
|
1750
|
+
* - _alt_ `[string]`: The alt text of the media item.
|
|
1751
|
+
* - _caption_ `[string]`: The caption of the media item.
|
|
1752
|
+
*
|
|
1753
|
+
* @param {InserterMediaCategory} category The inserter media category to register.
|
|
1754
|
+
*
|
|
1755
|
+
* @example
|
|
1756
|
+
* ```js
|
|
1757
|
+
*
|
|
1758
|
+
* wp.data.dispatch('core/block-editor').registerInserterMediaCategory( {
|
|
1759
|
+
* name: 'openverse',
|
|
1760
|
+
* labels: {
|
|
1761
|
+
* name: 'Openverse',
|
|
1762
|
+
* search_items: 'Search Openverse',
|
|
1763
|
+
* },
|
|
1764
|
+
* mediaType: 'image',
|
|
1765
|
+
* async fetch( query = {} ) {
|
|
1766
|
+
* const defaultArgs = {
|
|
1767
|
+
* mature: false,
|
|
1768
|
+
* excluded_source: 'flickr,inaturalist,wikimedia',
|
|
1769
|
+
* license: 'pdm,cc0',
|
|
1770
|
+
* };
|
|
1771
|
+
* const finalQuery = { ...query, ...defaultArgs };
|
|
1772
|
+
* // Sometimes you might need to map the supported request params according to `InserterMediaRequest`.
|
|
1773
|
+
* // interface. In this example the `search` query param is named `q`.
|
|
1774
|
+
* const mapFromInserterMediaRequest = {
|
|
1775
|
+
* per_page: 'page_size',
|
|
1776
|
+
* search: 'q',
|
|
1777
|
+
* };
|
|
1778
|
+
* const url = new URL( 'https://api.openverse.engineering/v1/images/' );
|
|
1779
|
+
* Object.entries( finalQuery ).forEach( ( [ key, value ] ) => {
|
|
1780
|
+
* const queryKey = mapFromInserterMediaRequest[ key ] || key;
|
|
1781
|
+
* url.searchParams.set( queryKey, value );
|
|
1782
|
+
* } );
|
|
1783
|
+
* const response = await window.fetch( url, {
|
|
1784
|
+
* headers: {
|
|
1785
|
+
* 'User-Agent': 'WordPress/inserter-media-fetch',
|
|
1786
|
+
* },
|
|
1787
|
+
* } );
|
|
1788
|
+
* const jsonResponse = await response.json();
|
|
1789
|
+
* const results = jsonResponse.results;
|
|
1790
|
+
* return results.map( ( result ) => ( {
|
|
1791
|
+
* ...result,
|
|
1792
|
+
* // If your response result includes an `id` prop that you want to access later, it should
|
|
1793
|
+
* // be mapped to `InserterMediaItem`'s `sourceId` prop. This can be useful if you provide
|
|
1794
|
+
* // a report URL getter.
|
|
1795
|
+
* // Additionally you should always clear the `id` value of your response results because
|
|
1796
|
+
* // it is used to identify WordPress media items.
|
|
1797
|
+
* sourceId: result.id,
|
|
1798
|
+
* id: undefined,
|
|
1799
|
+
* caption: result.caption,
|
|
1800
|
+
* previewUrl: result.thumbnail,
|
|
1801
|
+
* } ) );
|
|
1802
|
+
* },
|
|
1803
|
+
* getReportUrl: ( { sourceId } ) =>
|
|
1804
|
+
* `https://wordpress.org/openverse/image/${ sourceId }/report/`,
|
|
1805
|
+
* isExternalResource: true,
|
|
1806
|
+
* } );
|
|
1807
|
+
* ```
|
|
1808
|
+
*
|
|
1809
|
+
* @typedef {Object} InserterMediaCategory Interface for inserter media category.
|
|
1810
|
+
* @property {string} name The name of the media category, that should be unique among all media categories.
|
|
1811
|
+
* @property {Object} labels Labels for the media category.
|
|
1812
|
+
* @property {string} labels.name General name of the media category. It's used in the inserter media items list.
|
|
1813
|
+
* @property {string} [labels.search_items='Search'] Label for searching items. Default is ‘Search Posts’ / ‘Search Pages’.
|
|
1814
|
+
* @property {('image'|'audio'|'video')} mediaType The media type of the media category.
|
|
1815
|
+
* @property {(InserterMediaRequest) => Promise<InserterMediaItem[]>} fetch The function to fetch media items for the category.
|
|
1816
|
+
* @property {(InserterMediaItem) => string} [getReportUrl] If the media category supports reporting media items, this function should return
|
|
1817
|
+
* the report url for the media item. It accepts the `InserterMediaItem` as an argument.
|
|
1818
|
+
* @property {boolean} [isExternalResource] If the media category is an external resource, this should be set to true.
|
|
1819
|
+
* This is used to avoid making a request to the external resource when the user
|
|
1820
|
+
*
|
|
1821
|
+
*/
|
|
1822
|
+
export const registerInserterMediaCategory =
|
|
1823
|
+
( category ) =>
|
|
1824
|
+
( { select, dispatch } ) => {
|
|
1825
|
+
if ( ! category || typeof category !== 'object' ) {
|
|
1826
|
+
console.error(
|
|
1827
|
+
'Category should be an `InserterMediaCategory` object.'
|
|
1828
|
+
);
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1831
|
+
if ( ! category.name ) {
|
|
1832
|
+
console.error(
|
|
1833
|
+
'Category should have a `name` that should be unique among all media categories.'
|
|
1834
|
+
);
|
|
1835
|
+
return;
|
|
1836
|
+
}
|
|
1837
|
+
if ( ! category.labels?.name ) {
|
|
1838
|
+
console.error( 'Category should have a `labels.name`.' );
|
|
1839
|
+
return;
|
|
1840
|
+
}
|
|
1841
|
+
if ( ! [ 'image', 'audio', 'video' ].includes( category.mediaType ) ) {
|
|
1842
|
+
console.error(
|
|
1843
|
+
'Category should have `mediaType` property that is one of `image|audio|video`.'
|
|
1844
|
+
);
|
|
1845
|
+
return;
|
|
1846
|
+
}
|
|
1847
|
+
if ( ! category.fetch || typeof category.fetch !== 'function' ) {
|
|
1848
|
+
console.error(
|
|
1849
|
+
'Category should have a `fetch` function defined with the following signature `(InserterMediaRequest) => Promise<InserterMediaItem[]>`.'
|
|
1850
|
+
);
|
|
1851
|
+
return;
|
|
1852
|
+
}
|
|
1853
|
+
const { inserterMediaCategories = [] } = select.getSettings();
|
|
1854
|
+
if (
|
|
1855
|
+
inserterMediaCategories.some(
|
|
1856
|
+
( { name } ) => name === category.name
|
|
1857
|
+
)
|
|
1858
|
+
) {
|
|
1859
|
+
console.error(
|
|
1860
|
+
`A category is already registered with the same name: "${ category.name }".`
|
|
1861
|
+
);
|
|
1862
|
+
return;
|
|
1863
|
+
}
|
|
1864
|
+
if (
|
|
1865
|
+
inserterMediaCategories.some(
|
|
1866
|
+
( { labels: { name } } ) => name === category.labels?.name
|
|
1867
|
+
)
|
|
1868
|
+
) {
|
|
1869
|
+
console.error(
|
|
1870
|
+
`A category is already registered with the same labels.name: "${ category.labels.name }".`
|
|
1871
|
+
);
|
|
1872
|
+
return;
|
|
1873
|
+
}
|
|
1874
|
+
// `inserterMediaCategories` is a private block editor setting, which means it cannot
|
|
1875
|
+
// be updated through the public `updateSettings` action. We preserve this setting as
|
|
1876
|
+
// private, so extenders can only add new inserter media categories and don't have any
|
|
1877
|
+
// control over the core media categories.
|
|
1878
|
+
dispatch( {
|
|
1879
|
+
type: 'UPDATE_SETTINGS',
|
|
1880
|
+
settings: {
|
|
1881
|
+
inserterMediaCategories: [
|
|
1882
|
+
...inserterMediaCategories,
|
|
1883
|
+
{ ...category, isExternalResource: true },
|
|
1884
|
+
],
|
|
1885
|
+
},
|
|
1886
|
+
} );
|
|
1887
|
+
};
|
package/src/store/index.js
CHANGED
|
@@ -43,3 +43,13 @@ const registeredStore = registerStore( STORE_NAME, {
|
|
|
43
43
|
} );
|
|
44
44
|
unlock( registeredStore ).registerPrivateActions( privateActions );
|
|
45
45
|
unlock( registeredStore ).registerPrivateSelectors( privateSelectors );
|
|
46
|
+
|
|
47
|
+
// TODO: Remove once we switch to the `register` function (see above).
|
|
48
|
+
//
|
|
49
|
+
// Until then, private functions also need to be attached to the original
|
|
50
|
+
// `store` descriptor in order to avoid unit tests failing, which could happen
|
|
51
|
+
// when tests create new registries in which they register stores.
|
|
52
|
+
//
|
|
53
|
+
// @see https://github.com/WordPress/gutenberg/pull/51145#discussion_r1239999590
|
|
54
|
+
unlock( store ).registerPrivateActions( privateActions );
|
|
55
|
+
unlock( store ).registerPrivateSelectors( privateSelectors );
|
|
@@ -3,11 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Platform } from '@wordpress/element';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { blockTypePromptMessages } from '../components/block-removal-warning-modal';
|
|
10
|
-
|
|
11
6
|
const castArray = ( maybeArray ) =>
|
|
12
7
|
Array.isArray( maybeArray ) ? maybeArray : [ maybeArray ];
|
|
13
8
|
|
|
@@ -28,13 +23,15 @@ const privateSettings = [
|
|
|
28
23
|
* Action that updates the block editor settings and
|
|
29
24
|
* conditionally preserves the experimental ones.
|
|
30
25
|
*
|
|
31
|
-
* @param {Object} settings
|
|
32
|
-
* @param {
|
|
26
|
+
* @param {Object} settings Updated settings
|
|
27
|
+
* @param {Object} options Options object.
|
|
28
|
+
* @param {boolean} options.stripExperimentalSettings Whether to strip experimental settings.
|
|
29
|
+
* @param {boolean} options.reset Whether to reset the settings.
|
|
33
30
|
* @return {Object} Action object
|
|
34
31
|
*/
|
|
35
32
|
export function __experimentalUpdateSettings(
|
|
36
33
|
settings,
|
|
37
|
-
stripExperimentalSettings = false
|
|
34
|
+
{ stripExperimentalSettings = false, reset = false } = {}
|
|
38
35
|
) {
|
|
39
36
|
let cleanSettings = settings;
|
|
40
37
|
// There are no plugins in the mobile apps, so there is no
|
|
@@ -50,6 +47,7 @@ export function __experimentalUpdateSettings(
|
|
|
50
47
|
return {
|
|
51
48
|
type: 'UPDATE_SETTINGS',
|
|
52
49
|
settings: cleanSettings,
|
|
50
|
+
reset,
|
|
53
51
|
};
|
|
54
52
|
}
|
|
55
53
|
|
|
@@ -155,35 +153,22 @@ export const privateRemoveBlocks =
|
|
|
155
153
|
// confirmation that they intended to remove such block(s). However,
|
|
156
154
|
// the editor instance is responsible for presenting those confirmation
|
|
157
155
|
// prompts to the user. Any instance opting into removal prompts must
|
|
158
|
-
// register using `
|
|
156
|
+
// register using `setBlockRemovalRules()`.
|
|
159
157
|
//
|
|
160
158
|
// @see https://github.com/WordPress/gutenberg/pull/51145
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// FIXME: Without this existence check, the unit tests for
|
|
164
|
-
// `__experimentalDeleteReusableBlock` in
|
|
165
|
-
// `packages/reusable-blocks/src/store/test/actions.js` fail due to
|
|
166
|
-
// the fact that the `registry` object passed to the thunk actions
|
|
167
|
-
// doesn't include this private action. This needs to be
|
|
168
|
-
// investigated to understand whether it's a real smell or if it's
|
|
169
|
-
// because not all store code has been updated to accommodate
|
|
170
|
-
// private selectors.
|
|
171
|
-
select.isRemovalPromptSupported &&
|
|
172
|
-
select.isRemovalPromptSupported()
|
|
173
|
-
) {
|
|
159
|
+
const rules = ! forceRemove && select.getBlockRemovalRules();
|
|
160
|
+
if ( rules ) {
|
|
174
161
|
const blockNamesForPrompt = new Set();
|
|
175
162
|
|
|
176
163
|
// Given a list of client IDs of blocks that the user intended to
|
|
177
164
|
// remove, perform a tree search (BFS) to find all block names
|
|
178
165
|
// corresponding to "important" blocks, i.e. blocks that require a
|
|
179
166
|
// removal prompt.
|
|
180
|
-
//
|
|
181
|
-
// @see blockTypePromptMessages
|
|
182
167
|
const queue = [ ...clientIds ];
|
|
183
168
|
while ( queue.length ) {
|
|
184
169
|
const clientId = queue.shift();
|
|
185
170
|
const blockName = select.getBlockName( clientId );
|
|
186
|
-
if (
|
|
171
|
+
if ( rules[ blockName ] ) {
|
|
187
172
|
blockNamesForPrompt.add( blockName );
|
|
188
173
|
}
|
|
189
174
|
const innerBlocks = select.getBlockOrder( clientId );
|
|
@@ -194,7 +179,7 @@ export const privateRemoveBlocks =
|
|
|
194
179
|
// skip any other steps (thus postponing actual removal).
|
|
195
180
|
if ( blockNamesForPrompt.size ) {
|
|
196
181
|
dispatch(
|
|
197
|
-
|
|
182
|
+
displayBlockRemovalPrompt(
|
|
198
183
|
clientIds,
|
|
199
184
|
selectPrevious,
|
|
200
185
|
Array.from( blockNamesForPrompt )
|
|
@@ -246,7 +231,7 @@ export const ensureDefaultBlock =
|
|
|
246
231
|
* Returns an action object used in signalling that a block removal prompt must
|
|
247
232
|
* be displayed.
|
|
248
233
|
*
|
|
249
|
-
* Contrast with `
|
|
234
|
+
* Contrast with `setBlockRemovalRules`.
|
|
250
235
|
*
|
|
251
236
|
* @param {string|string[]} clientIds Client IDs of blocks to remove.
|
|
252
237
|
* @param {boolean} selectPrevious True if the previous block
|
|
@@ -254,16 +239,19 @@ export const ensureDefaultBlock =
|
|
|
254
239
|
* (if no previous block exists)
|
|
255
240
|
* should be selected
|
|
256
241
|
* when a block is removed.
|
|
257
|
-
* @param {string[]} blockNamesForPrompt Names of blocks
|
|
242
|
+
* @param {string[]} blockNamesForPrompt Names of the blocks that
|
|
243
|
+
* triggered the need for
|
|
244
|
+
* confirmation before removal.
|
|
245
|
+
*
|
|
258
246
|
* @return {Object} Action object.
|
|
259
247
|
*/
|
|
260
|
-
|
|
248
|
+
function displayBlockRemovalPrompt(
|
|
261
249
|
clientIds,
|
|
262
250
|
selectPrevious,
|
|
263
251
|
blockNamesForPrompt
|
|
264
252
|
) {
|
|
265
253
|
return {
|
|
266
|
-
type: '
|
|
254
|
+
type: 'DISPLAY_BLOCK_REMOVAL_PROMPT',
|
|
267
255
|
clientIds,
|
|
268
256
|
selectPrevious,
|
|
269
257
|
blockNamesForPrompt,
|
|
@@ -277,24 +265,36 @@ export function displayRemovalPrompt(
|
|
|
277
265
|
*
|
|
278
266
|
* @return {Object} Action object.
|
|
279
267
|
*/
|
|
280
|
-
export function
|
|
268
|
+
export function clearBlockRemovalPrompt() {
|
|
281
269
|
return {
|
|
282
|
-
type: '
|
|
270
|
+
type: 'CLEAR_BLOCK_REMOVAL_PROMPT',
|
|
283
271
|
};
|
|
284
272
|
}
|
|
285
273
|
|
|
286
274
|
/**
|
|
287
|
-
* Returns an action object used
|
|
288
|
-
*
|
|
275
|
+
* Returns an action object used to set up any rules that a block editor may
|
|
276
|
+
* provide in order to prevent a user from accidentally removing certain
|
|
277
|
+
* blocks. These rules are then used to display a confirmation prompt to the
|
|
278
|
+
* user. For instance, in the Site Editor, the Query Loop block is important
|
|
279
|
+
* enough to warrant such confirmation.
|
|
280
|
+
*
|
|
281
|
+
* IMPORTANT: Registering rules implicitly signals to the `privateRemoveBlocks`
|
|
282
|
+
* action that the editor will be responsible for displaying block removal
|
|
283
|
+
* prompts and confirming deletions. This action is meant to be used by
|
|
284
|
+
* component `BlockRemovalWarningModal` only.
|
|
285
|
+
*
|
|
286
|
+
* The data is a record whose keys are block types (e.g. 'core/query') and
|
|
287
|
+
* whose values are the explanation to be shown to users (e.g. 'Query Loop
|
|
288
|
+
* displays a list of posts or pages.').
|
|
289
289
|
*
|
|
290
|
-
* Contrast with `
|
|
290
|
+
* Contrast with `displayBlockRemovalPrompt`.
|
|
291
291
|
*
|
|
292
|
-
* @param {
|
|
292
|
+
* @param {Record<string,string>|false} rules Block removal rules.
|
|
293
293
|
* @return {Object} Action object.
|
|
294
294
|
*/
|
|
295
|
-
export function
|
|
295
|
+
export function setBlockRemovalRules( rules = false ) {
|
|
296
296
|
return {
|
|
297
|
-
type: '
|
|
298
|
-
|
|
297
|
+
type: 'SET_BLOCK_REMOVAL_RULES',
|
|
298
|
+
rules,
|
|
299
299
|
};
|
|
300
300
|
}
|
|
@@ -205,6 +205,6 @@ export function getRemovalPromptData( state ) {
|
|
|
205
205
|
*
|
|
206
206
|
* @return {boolean} Whether removal prompt exists.
|
|
207
207
|
*/
|
|
208
|
-
export function
|
|
209
|
-
return state.
|
|
208
|
+
export function getBlockRemovalRules( state ) {
|
|
209
|
+
return state.blockRemovalRules;
|
|
210
210
|
}
|
package/src/store/reducer.js
CHANGED
|
@@ -1480,14 +1480,14 @@ export function isSelectionEnabled( state = true, action ) {
|
|
|
1480
1480
|
*/
|
|
1481
1481
|
function removalPromptData( state = false, action ) {
|
|
1482
1482
|
switch ( action.type ) {
|
|
1483
|
-
case '
|
|
1483
|
+
case 'DISPLAY_BLOCK_REMOVAL_PROMPT':
|
|
1484
1484
|
const { clientIds, selectPrevious, blockNamesForPrompt } = action;
|
|
1485
1485
|
return {
|
|
1486
1486
|
clientIds,
|
|
1487
1487
|
selectPrevious,
|
|
1488
1488
|
blockNamesForPrompt,
|
|
1489
1489
|
};
|
|
1490
|
-
case '
|
|
1490
|
+
case 'CLEAR_BLOCK_REMOVAL_PROMPT':
|
|
1491
1491
|
return false;
|
|
1492
1492
|
}
|
|
1493
1493
|
|
|
@@ -1495,17 +1495,25 @@ function removalPromptData( state = false, action ) {
|
|
|
1495
1495
|
}
|
|
1496
1496
|
|
|
1497
1497
|
/**
|
|
1498
|
-
* Reducer
|
|
1498
|
+
* Reducer returning any rules that a block editor may provide in order to
|
|
1499
|
+
* prevent a user from accidentally removing certain blocks. These rules are
|
|
1500
|
+
* then used to display a confirmation prompt to the user. For instance, in the
|
|
1501
|
+
* Site Editor, the Query Loop block is important enough to warrant such
|
|
1502
|
+
* confirmation.
|
|
1503
|
+
*
|
|
1504
|
+
* The data is a record whose keys are block types (e.g. 'core/query') and
|
|
1505
|
+
* whose values are the explanation to be shown to users (e.g. 'Query Loop
|
|
1506
|
+
* displays a list of posts or pages.').
|
|
1499
1507
|
*
|
|
1500
1508
|
* @param {boolean} state Current state.
|
|
1501
1509
|
* @param {Object} action Dispatched action.
|
|
1502
1510
|
*
|
|
1503
|
-
* @return {
|
|
1511
|
+
* @return {Record<string,string>} Updated state.
|
|
1504
1512
|
*/
|
|
1505
|
-
function
|
|
1513
|
+
function blockRemovalRules( state = false, action ) {
|
|
1506
1514
|
switch ( action.type ) {
|
|
1507
|
-
case '
|
|
1508
|
-
return action.
|
|
1515
|
+
case 'SET_BLOCK_REMOVAL_RULES':
|
|
1516
|
+
return action.rules;
|
|
1509
1517
|
}
|
|
1510
1518
|
|
|
1511
1519
|
return state;
|
|
@@ -1623,6 +1631,12 @@ export function template( state = { isValid: true }, action ) {
|
|
|
1623
1631
|
export function settings( state = SETTINGS_DEFAULTS, action ) {
|
|
1624
1632
|
switch ( action.type ) {
|
|
1625
1633
|
case 'UPDATE_SETTINGS':
|
|
1634
|
+
if ( action.reset ) {
|
|
1635
|
+
return {
|
|
1636
|
+
...SETTINGS_DEFAULTS,
|
|
1637
|
+
...action.settings,
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1626
1640
|
return {
|
|
1627
1641
|
...state,
|
|
1628
1642
|
...action.settings,
|
|
@@ -1924,7 +1938,7 @@ const combinedReducers = combineReducers( {
|
|
|
1924
1938
|
blockVisibility,
|
|
1925
1939
|
blockEditingModes,
|
|
1926
1940
|
removalPromptData,
|
|
1927
|
-
|
|
1941
|
+
blockRemovalRules,
|
|
1928
1942
|
} );
|
|
1929
1943
|
|
|
1930
1944
|
function withAutomaticChangeReset( reducer ) {
|
package/src/store/selectors.js
CHANGED
|
@@ -2034,11 +2034,13 @@ export const getInserterItems = createSelector(
|
|
|
2034
2034
|
? getReusableBlocks( state )
|
|
2035
2035
|
.filter(
|
|
2036
2036
|
( reusableBlock ) =>
|
|
2037
|
-
//
|
|
2038
|
-
//
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2037
|
+
// Reusable blocks that are fully synced should have no sync status set
|
|
2038
|
+
// for backwards compat between patterns and old reusable blocks, but
|
|
2039
|
+
// some in release 16.1 may have had sync status inadvertantly set to
|
|
2040
|
+
// 'fully' if created in the site editor.
|
|
2041
|
+
reusableBlock.wp_pattern_sync_status === 'fully' ||
|
|
2042
|
+
reusableBlock.wp_pattern_sync_status === '' ||
|
|
2043
|
+
! reusableBlock.wp_pattern_sync_status
|
|
2042
2044
|
)
|
|
2043
2045
|
.map( buildReusableBlockInserterItem )
|
|
2044
2046
|
: [];
|
|
@@ -2313,7 +2315,8 @@ function getUnsyncedPatterns( state ) {
|
|
|
2313
2315
|
|
|
2314
2316
|
return reusableBlocks
|
|
2315
2317
|
.filter(
|
|
2316
|
-
( reusableBlock ) =>
|
|
2318
|
+
( reusableBlock ) =>
|
|
2319
|
+
reusableBlock.wp_pattern_sync_status === 'unsynced'
|
|
2317
2320
|
)
|
|
2318
2321
|
.map( ( reusableBlock ) => {
|
|
2319
2322
|
return {
|
|
@@ -53,6 +53,7 @@ const {
|
|
|
53
53
|
updateBlockListSettings,
|
|
54
54
|
updateSettings,
|
|
55
55
|
validateBlocksToTemplate,
|
|
56
|
+
registerInserterMediaCategory,
|
|
56
57
|
} = actions;
|
|
57
58
|
|
|
58
59
|
describe( 'actions', () => {
|
|
@@ -617,6 +618,7 @@ describe( 'actions', () => {
|
|
|
617
618
|
const select = {
|
|
618
619
|
getBlockRootClientId: () => undefined,
|
|
619
620
|
canRemoveBlocks: () => true,
|
|
621
|
+
getBlockRemovalRules: () => false,
|
|
620
622
|
};
|
|
621
623
|
const dispatch = Object.assign( jest.fn(), {
|
|
622
624
|
selectPreviousBlock: jest.fn(),
|
|
@@ -727,6 +729,7 @@ describe( 'actions', () => {
|
|
|
727
729
|
const select = {
|
|
728
730
|
getBlockRootClientId: () => null,
|
|
729
731
|
canRemoveBlocks: () => true,
|
|
732
|
+
getBlockRemovalRules: () => false,
|
|
730
733
|
};
|
|
731
734
|
const dispatch = Object.assign( jest.fn(), {
|
|
732
735
|
selectPreviousBlock: jest.fn(),
|
|
@@ -751,6 +754,7 @@ describe( 'actions', () => {
|
|
|
751
754
|
const select = {
|
|
752
755
|
getBlockRootClientId: () => null,
|
|
753
756
|
canRemoveBlocks: () => true,
|
|
757
|
+
getBlockRemovalRules: () => false,
|
|
754
758
|
};
|
|
755
759
|
const dispatch = Object.assign( jest.fn(), {
|
|
756
760
|
selectPreviousBlock: jest.fn(),
|
|
@@ -1209,4 +1213,111 @@ describe( 'actions', () => {
|
|
|
1209
1213
|
expect( result ).toEqual( false );
|
|
1210
1214
|
} );
|
|
1211
1215
|
} );
|
|
1216
|
+
|
|
1217
|
+
describe( 'registerInserterMediaCategory', () => {
|
|
1218
|
+
describe( 'should log errors when invalid', () => {
|
|
1219
|
+
it( 'valid object', () => {
|
|
1220
|
+
registerInserterMediaCategory()( {} );
|
|
1221
|
+
expect( console ).toHaveErroredWith(
|
|
1222
|
+
'Category should be an `InserterMediaCategory` object.'
|
|
1223
|
+
);
|
|
1224
|
+
} );
|
|
1225
|
+
it( 'has name', () => {
|
|
1226
|
+
registerInserterMediaCategory( {} )( {} );
|
|
1227
|
+
expect( console ).toHaveErroredWith(
|
|
1228
|
+
'Category should have a `name` that should be unique among all media categories.'
|
|
1229
|
+
);
|
|
1230
|
+
} );
|
|
1231
|
+
it( 'has labels.name', () => {
|
|
1232
|
+
registerInserterMediaCategory( { name: 'a' } )( {} );
|
|
1233
|
+
expect( console ).toHaveErroredWith(
|
|
1234
|
+
'Category should have a `labels.name`.'
|
|
1235
|
+
);
|
|
1236
|
+
} );
|
|
1237
|
+
it( 'has proper media type', () => {
|
|
1238
|
+
registerInserterMediaCategory( {
|
|
1239
|
+
name: 'a',
|
|
1240
|
+
labels: { name: 'a' },
|
|
1241
|
+
mediaType: 'b',
|
|
1242
|
+
} )( {} );
|
|
1243
|
+
expect( console ).toHaveErroredWith(
|
|
1244
|
+
'Category should have `mediaType` property that is one of `image|audio|video`.'
|
|
1245
|
+
);
|
|
1246
|
+
} );
|
|
1247
|
+
it( 'has fetch function', () => {
|
|
1248
|
+
registerInserterMediaCategory( {
|
|
1249
|
+
name: 'a',
|
|
1250
|
+
labels: { name: 'a' },
|
|
1251
|
+
mediaType: 'image',
|
|
1252
|
+
fetch: 'c',
|
|
1253
|
+
} )( {} );
|
|
1254
|
+
expect( console ).toHaveErroredWith(
|
|
1255
|
+
'Category should have a `fetch` function defined with the following signature `(InserterMediaRequest) => Promise<InserterMediaItem[]>`.'
|
|
1256
|
+
);
|
|
1257
|
+
} );
|
|
1258
|
+
it( 'has unique name', () => {
|
|
1259
|
+
registerInserterMediaCategory( {
|
|
1260
|
+
name: 'a',
|
|
1261
|
+
labels: { name: 'a' },
|
|
1262
|
+
mediaType: 'image',
|
|
1263
|
+
fetch: () => {},
|
|
1264
|
+
} )( {
|
|
1265
|
+
select: {
|
|
1266
|
+
getSettings: () => ( {
|
|
1267
|
+
inserterMediaCategories: [ { name: 'a' } ],
|
|
1268
|
+
} ),
|
|
1269
|
+
},
|
|
1270
|
+
} );
|
|
1271
|
+
expect( console ).toHaveErroredWith(
|
|
1272
|
+
'A category is already registered with the same name: "a".'
|
|
1273
|
+
);
|
|
1274
|
+
} );
|
|
1275
|
+
it( 'has unique labels.name', () => {
|
|
1276
|
+
registerInserterMediaCategory( {
|
|
1277
|
+
name: 'a',
|
|
1278
|
+
labels: { name: 'a' },
|
|
1279
|
+
mediaType: 'image',
|
|
1280
|
+
fetch: () => {},
|
|
1281
|
+
} )( {
|
|
1282
|
+
select: {
|
|
1283
|
+
getSettings: () => ( {
|
|
1284
|
+
inserterMediaCategories: [
|
|
1285
|
+
{ labels: { name: 'a' } },
|
|
1286
|
+
],
|
|
1287
|
+
} ),
|
|
1288
|
+
},
|
|
1289
|
+
} );
|
|
1290
|
+
expect( console ).toHaveErroredWith(
|
|
1291
|
+
'A category is already registered with the same labels.name: "a".'
|
|
1292
|
+
);
|
|
1293
|
+
} );
|
|
1294
|
+
} );
|
|
1295
|
+
it( 'should register a media category', () => {
|
|
1296
|
+
const category = {
|
|
1297
|
+
name: 'new',
|
|
1298
|
+
labels: { name: 'new' },
|
|
1299
|
+
mediaType: 'image',
|
|
1300
|
+
fetch: () => {},
|
|
1301
|
+
};
|
|
1302
|
+
const inserterMediaCategories = [
|
|
1303
|
+
{ name: 'a', labels: { name: 'a' } },
|
|
1304
|
+
];
|
|
1305
|
+
const dispatch = jest.fn();
|
|
1306
|
+
registerInserterMediaCategory( category )( {
|
|
1307
|
+
select: {
|
|
1308
|
+
getSettings: () => ( { inserterMediaCategories } ),
|
|
1309
|
+
},
|
|
1310
|
+
dispatch,
|
|
1311
|
+
} );
|
|
1312
|
+
expect( dispatch ).toHaveBeenLastCalledWith( {
|
|
1313
|
+
type: 'UPDATE_SETTINGS',
|
|
1314
|
+
settings: {
|
|
1315
|
+
inserterMediaCategories: [
|
|
1316
|
+
...inserterMediaCategories,
|
|
1317
|
+
{ ...category, isExternalResource: true },
|
|
1318
|
+
],
|
|
1319
|
+
},
|
|
1320
|
+
} );
|
|
1321
|
+
} );
|
|
1322
|
+
} );
|
|
1212
1323
|
} );
|