@wordpress/block-editor 12.4.0 → 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 +2 -0
- package/README.md +5 -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-lock/toolbar.js +25 -6
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js +3 -6
- package/build/components/block-mobile-toolbar/block-actions-menu.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-toolbar/index.js +8 -5
- package/build/components/block-toolbar/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/dimensions-tool/aspect-ratio-tool.js +99 -0
- package/build/components/dimensions-tool/aspect-ratio-tool.js.map +1 -0
- package/build/components/dimensions-tool/index.js +207 -0
- package/build/components/dimensions-tool/index.js.map +1 -0
- package/build/components/dimensions-tool/scale-tool.js +111 -0
- package/build/components/dimensions-tool/scale-tool.js.map +1 -0
- package/build/components/dimensions-tool/width-height-tool.js +125 -0
- package/build/components/dimensions-tool/width-height-tool.js.map +1 -0
- 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/filters-panel.js +1 -1
- package/build/components/global-styles/filters-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/image-editor/aspect-ratio-dropdown.js +1 -1
- package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build/components/image-editor/use-save-image.js +1 -2
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/image-size-control/index.js +6 -0
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/index.js +19 -1
- package/build/components/index.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/patterns-list.js +2 -2
- package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +7 -35
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/hooks/use-block-types-state.js +3 -4
- package/build/components/inserter/hooks/use-block-types-state.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-state.js +9 -3
- package/build/components/inserter/hooks/use-patterns-state.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 +6 -2
- 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/index.js +17 -15
- package/build/components/link-control/index.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-input.js +4 -4
- package/build/components/link-control/search-input.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/link-control/settings-drawer.js +2 -3
- package/build/components/link-control/settings-drawer.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/provider/use-block-sync.js +21 -0
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/components/resolution-tool/index.js +55 -0
- package/build/components/resolution-tool/index.js.map +1 -0
- package/build/components/url-input/index.js +4 -2
- package/build/components/url-input/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 +10 -1
- 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/defaults.js +1 -0
- package/build/store/defaults.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 +33 -15
- 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-lock/toolbar.js +25 -7
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +4 -6
- package/build-module/components/block-mobile-toolbar/block-actions-menu.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 +20 -24
- package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +8 -5
- package/build-module/components/block-toolbar/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/dimensions-tool/aspect-ratio-tool.js +87 -0
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js.map +1 -0
- package/build-module/components/dimensions-tool/index.js +195 -0
- package/build-module/components/dimensions-tool/index.js.map +1 -0
- package/build-module/components/dimensions-tool/scale-tool.js +103 -0
- package/build-module/components/dimensions-tool/scale-tool.js.map +1 -0
- package/build-module/components/dimensions-tool/width-height-tool.js +122 -0
- package/build-module/components/dimensions-tool/width-height-tool.js.map +1 -0
- 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/filters-panel.js +2 -2
- package/build-module/components/global-styles/filters-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/image-editor/aspect-ratio-dropdown.js +1 -1
- package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build-module/components/image-editor/use-save-image.js +1 -2
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/image-size-control/index.js +5 -0
- package/build-module/components/image-size-control/index.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/block-patterns-explorer/patterns-list.js +2 -2
- package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +7 -33
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/hooks/use-block-types-state.js +3 -4
- package/build-module/components/inserter/hooks/use-block-types-state.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js +9 -3
- package/build-module/components/inserter/hooks/use-patterns-state.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 +5 -2
- 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/index.js +17 -15
- package/build-module/components/link-control/index.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-input.js +4 -4
- package/build-module/components/link-control/search-input.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/link-control/settings-drawer.js +4 -5
- package/build-module/components/link-control/settings-drawer.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/provider/use-block-sync.js +21 -0
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/components/resolution-tool/index.js +45 -0
- package/build-module/components/resolution-tool/index.js.map +1 -0
- package/build-module/components/url-input/index.js +4 -2
- package/build-module/components/url-input/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 +7 -1
- 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/defaults.js +1 -0
- package/build-module/store/defaults.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 +33 -15
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/content-rtl.css +3 -0
- package/build-style/content.css +3 -0
- package/build-style/style-rtl.css +131 -129
- package/build-style/style.css +131 -129
- package/package.json +32 -31
- package/src/components/alignment-control/test/__snapshots__/index.js.snap +6 -6
- package/src/components/block-alignment-control/test/__snapshots__/index.js.snap +5 -5
- 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-lock/toolbar.js +34 -6
- package/src/components/block-mobile-toolbar/block-actions-menu.native.js +4 -8
- package/src/components/block-parent-selector/index.js +13 -8
- package/src/components/block-removal-warning-modal/index.js +20 -33
- package/src/components/block-toolbar/index.js +9 -6
- package/src/components/block-tools/block-contextual-toolbar.js +5 -11
- package/src/components/block-tools/style.scss +73 -26
- package/src/components/default-block-appender/content.scss +11 -0
- package/src/components/dimensions-tool/aspect-ratio-tool.js +124 -0
- package/src/components/dimensions-tool/index.js +212 -0
- package/src/components/dimensions-tool/scale-tool.js +124 -0
- package/src/components/dimensions-tool/stories/aspect-ratio-tool.js +52 -0
- package/src/components/dimensions-tool/stories/index.js +54 -0
- package/src/components/dimensions-tool/stories/scale-tool.js +48 -0
- package/src/components/dimensions-tool/stories/width-height-tool.js +54 -0
- package/src/components/dimensions-tool/test/index.js +641 -0
- package/src/components/dimensions-tool/width-height-tool.js +113 -0
- package/src/components/font-family/README.md +71 -0
- package/src/components/global-styles/color-panel.js +1 -1
- package/src/components/global-styles/filters-panel.js +2 -2
- package/src/components/global-styles/hooks.js +2 -0
- package/src/components/global-styles/typography-panel.js +40 -0
- package/src/components/image-editor/aspect-ratio-dropdown.js +1 -1
- package/src/components/image-editor/use-save-image.js +0 -1
- package/src/components/image-size-control/index.js +6 -0
- package/src/components/index.js +6 -0
- package/src/components/inserter/block-patterns-explorer/patterns-list.js +8 -2
- package/src/components/inserter/block-patterns-tab.js +8 -56
- package/src/components/inserter/hooks/use-block-types-state.js +3 -4
- package/src/components/inserter/hooks/use-patterns-state.js +35 -19
- 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 +5 -1
- 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/index.js +32 -28
- package/src/components/link-control/search-create-button.js +8 -26
- package/src/components/link-control/search-input.js +4 -3
- 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/settings-drawer.js +6 -5
- package/src/components/link-control/style.scss +51 -123
- package/src/components/link-control/test/index.js +135 -123
- package/src/components/list-view/appender.js +5 -6
- package/src/components/list-view/style.scss +1 -2
- package/src/components/media-replace-flow/test/index.js +1 -1
- package/src/components/panel-color-settings/README.md +98 -0
- package/src/components/provider/index.js +9 -2
- package/src/components/provider/test/use-block-sync.js +21 -6
- package/src/components/provider/use-block-sync.js +19 -0
- package/src/components/recursion-provider/README.md +101 -0
- package/src/components/resolution-tool/index.js +56 -0
- package/src/components/resolution-tool/stories/index.js +48 -0
- package/src/components/url-input/index.js +2 -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 +6 -0
- package/src/private-apis.native.js +2 -0
- package/src/store/actions.js +194 -1
- package/src/store/defaults.js +1 -0
- 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 +54 -20
- package/src/store/test/actions.js +111 -0
- package/src/store/test/private-actions.js +56 -0
package/build/store/actions.js
CHANGED
|
@@ -22,6 +22,7 @@ exports.mergeBlocks = exports.insertDefaultBlock = exports.insertBlocks = void 0
|
|
|
22
22
|
exports.moveBlockToPosition = moveBlockToPosition;
|
|
23
23
|
exports.multiSelect = exports.moveBlocksUp = exports.moveBlocksToPosition = exports.moveBlocksDown = void 0;
|
|
24
24
|
exports.receiveBlocks = receiveBlocks;
|
|
25
|
+
exports.registerInserterMediaCategory = void 0;
|
|
25
26
|
exports.removeBlock = removeBlock;
|
|
26
27
|
exports.removeBlocks = void 0;
|
|
27
28
|
exports.replaceBlock = replaceBlock;
|
|
@@ -70,6 +71,8 @@ var _selection = require("../utils/selection");
|
|
|
70
71
|
|
|
71
72
|
var _privateActions = require("./private-actions");
|
|
72
73
|
|
|
74
|
+
/* eslint no-console: [ 'error', { allow: [ 'error', 'warn' ] } ] */
|
|
75
|
+
|
|
73
76
|
/**
|
|
74
77
|
* WordPress dependencies
|
|
75
78
|
*/
|
|
@@ -1322,7 +1325,9 @@ function updateBlockListSettings(clientId, settings) {
|
|
|
1322
1325
|
|
|
1323
1326
|
|
|
1324
1327
|
function updateSettings(settings) {
|
|
1325
|
-
return (0, _privateActions.__experimentalUpdateSettings)(settings,
|
|
1328
|
+
return (0, _privateActions.__experimentalUpdateSettings)(settings, {
|
|
1329
|
+
stripExperimentalSettings: true
|
|
1330
|
+
});
|
|
1326
1331
|
}
|
|
1327
1332
|
/**
|
|
1328
1333
|
* Action that signals that a temporary reusable block has been saved
|
|
@@ -1636,4 +1641,193 @@ function __unstableSetTemporarilyEditingAsBlocks(temporarilyEditingAsBlocks) {
|
|
|
1636
1641
|
temporarilyEditingAsBlocks
|
|
1637
1642
|
};
|
|
1638
1643
|
}
|
|
1644
|
+
/**
|
|
1645
|
+
* Interface for inserter media requests.
|
|
1646
|
+
*
|
|
1647
|
+
* @typedef {Object} InserterMediaRequest
|
|
1648
|
+
* @property {number} per_page How many items to fetch per page.
|
|
1649
|
+
* @property {string} search The search term to use for filtering the results.
|
|
1650
|
+
*/
|
|
1651
|
+
|
|
1652
|
+
/**
|
|
1653
|
+
* Interface for inserter media responses. Any media resource should
|
|
1654
|
+
* map their response to this interface, in order to create the core
|
|
1655
|
+
* WordPress media blocks (image, video, audio).
|
|
1656
|
+
*
|
|
1657
|
+
* @typedef {Object} InserterMediaItem
|
|
1658
|
+
* @property {string} title The title of the media item.
|
|
1659
|
+
* @property {string} url The source url of the media item.
|
|
1660
|
+
* @property {string} [previewUrl] The preview source url of the media item to display in the media list.
|
|
1661
|
+
* @property {number} [id] The WordPress id of the media item.
|
|
1662
|
+
* @property {number|string} [sourceId] The id of the media item from external source.
|
|
1663
|
+
* @property {string} [alt] The alt text of the media item.
|
|
1664
|
+
* @property {string} [caption] The caption of the media item.
|
|
1665
|
+
*/
|
|
1666
|
+
|
|
1667
|
+
/**
|
|
1668
|
+
* Registers a new inserter media category. Once registered, the media category is
|
|
1669
|
+
* available in the inserter's media tab.
|
|
1670
|
+
*
|
|
1671
|
+
* The following interfaces are used:
|
|
1672
|
+
*
|
|
1673
|
+
* _Type Definition_
|
|
1674
|
+
*
|
|
1675
|
+
* - _InserterMediaRequest_ `Object`: Interface for inserter media requests.
|
|
1676
|
+
*
|
|
1677
|
+
* _Properties_
|
|
1678
|
+
*
|
|
1679
|
+
* - _per_page_ `number`: How many items to fetch per page.
|
|
1680
|
+
* - _search_ `string`: The search term to use for filtering the results.
|
|
1681
|
+
*
|
|
1682
|
+
* _Type Definition_
|
|
1683
|
+
*
|
|
1684
|
+
* - _InserterMediaItem_ `Object`: Interface for inserter media responses. Any media resource should
|
|
1685
|
+
* map their response to this interface, in order to create the core
|
|
1686
|
+
* WordPress media blocks (image, video, audio).
|
|
1687
|
+
*
|
|
1688
|
+
* _Properties_
|
|
1689
|
+
*
|
|
1690
|
+
* - _title_ `string`: The title of the media item.
|
|
1691
|
+
* - _url_ `string: The source url of the media item.
|
|
1692
|
+
* - _previewUrl_ `[string]`: The preview source url of the media item to display in the media list.
|
|
1693
|
+
* - _id_ `[number]`: The WordPress id of the media item.
|
|
1694
|
+
* - _sourceId_ `[number|string]`: The id of the media item from external source.
|
|
1695
|
+
* - _alt_ `[string]`: The alt text of the media item.
|
|
1696
|
+
* - _caption_ `[string]`: The caption of the media item.
|
|
1697
|
+
*
|
|
1698
|
+
* @param {InserterMediaCategory} category The inserter media category to register.
|
|
1699
|
+
*
|
|
1700
|
+
* @example
|
|
1701
|
+
* ```js
|
|
1702
|
+
*
|
|
1703
|
+
* wp.data.dispatch('core/block-editor').registerInserterMediaCategory( {
|
|
1704
|
+
* name: 'openverse',
|
|
1705
|
+
* labels: {
|
|
1706
|
+
* name: 'Openverse',
|
|
1707
|
+
* search_items: 'Search Openverse',
|
|
1708
|
+
* },
|
|
1709
|
+
* mediaType: 'image',
|
|
1710
|
+
* async fetch( query = {} ) {
|
|
1711
|
+
* const defaultArgs = {
|
|
1712
|
+
* mature: false,
|
|
1713
|
+
* excluded_source: 'flickr,inaturalist,wikimedia',
|
|
1714
|
+
* license: 'pdm,cc0',
|
|
1715
|
+
* };
|
|
1716
|
+
* const finalQuery = { ...query, ...defaultArgs };
|
|
1717
|
+
* // Sometimes you might need to map the supported request params according to `InserterMediaRequest`.
|
|
1718
|
+
* // interface. In this example the `search` query param is named `q`.
|
|
1719
|
+
* const mapFromInserterMediaRequest = {
|
|
1720
|
+
* per_page: 'page_size',
|
|
1721
|
+
* search: 'q',
|
|
1722
|
+
* };
|
|
1723
|
+
* const url = new URL( 'https://api.openverse.engineering/v1/images/' );
|
|
1724
|
+
* Object.entries( finalQuery ).forEach( ( [ key, value ] ) => {
|
|
1725
|
+
* const queryKey = mapFromInserterMediaRequest[ key ] || key;
|
|
1726
|
+
* url.searchParams.set( queryKey, value );
|
|
1727
|
+
* } );
|
|
1728
|
+
* const response = await window.fetch( url, {
|
|
1729
|
+
* headers: {
|
|
1730
|
+
* 'User-Agent': 'WordPress/inserter-media-fetch',
|
|
1731
|
+
* },
|
|
1732
|
+
* } );
|
|
1733
|
+
* const jsonResponse = await response.json();
|
|
1734
|
+
* const results = jsonResponse.results;
|
|
1735
|
+
* return results.map( ( result ) => ( {
|
|
1736
|
+
* ...result,
|
|
1737
|
+
* // If your response result includes an `id` prop that you want to access later, it should
|
|
1738
|
+
* // be mapped to `InserterMediaItem`'s `sourceId` prop. This can be useful if you provide
|
|
1739
|
+
* // a report URL getter.
|
|
1740
|
+
* // Additionally you should always clear the `id` value of your response results because
|
|
1741
|
+
* // it is used to identify WordPress media items.
|
|
1742
|
+
* sourceId: result.id,
|
|
1743
|
+
* id: undefined,
|
|
1744
|
+
* caption: result.caption,
|
|
1745
|
+
* previewUrl: result.thumbnail,
|
|
1746
|
+
* } ) );
|
|
1747
|
+
* },
|
|
1748
|
+
* getReportUrl: ( { sourceId } ) =>
|
|
1749
|
+
* `https://wordpress.org/openverse/image/${ sourceId }/report/`,
|
|
1750
|
+
* isExternalResource: true,
|
|
1751
|
+
* } );
|
|
1752
|
+
* ```
|
|
1753
|
+
*
|
|
1754
|
+
* @typedef {Object} InserterMediaCategory Interface for inserter media category.
|
|
1755
|
+
* @property {string} name The name of the media category, that should be unique among all media categories.
|
|
1756
|
+
* @property {Object} labels Labels for the media category.
|
|
1757
|
+
* @property {string} labels.name General name of the media category. It's used in the inserter media items list.
|
|
1758
|
+
* @property {string} [labels.search_items='Search'] Label for searching items. Default is ‘Search Posts’ / ‘Search Pages’.
|
|
1759
|
+
* @property {('image'|'audio'|'video')} mediaType The media type of the media category.
|
|
1760
|
+
* @property {(InserterMediaRequest) => Promise<InserterMediaItem[]>} fetch The function to fetch media items for the category.
|
|
1761
|
+
* @property {(InserterMediaItem) => string} [getReportUrl] If the media category supports reporting media items, this function should return
|
|
1762
|
+
* the report url for the media item. It accepts the `InserterMediaItem` as an argument.
|
|
1763
|
+
* @property {boolean} [isExternalResource] If the media category is an external resource, this should be set to true.
|
|
1764
|
+
* This is used to avoid making a request to the external resource when the user
|
|
1765
|
+
*
|
|
1766
|
+
*/
|
|
1767
|
+
|
|
1768
|
+
|
|
1769
|
+
const registerInserterMediaCategory = category => ({
|
|
1770
|
+
select,
|
|
1771
|
+
dispatch
|
|
1772
|
+
}) => {
|
|
1773
|
+
if (!category || typeof category !== 'object') {
|
|
1774
|
+
console.error('Category should be an `InserterMediaCategory` object.');
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
if (!category.name) {
|
|
1779
|
+
console.error('Category should have a `name` that should be unique among all media categories.');
|
|
1780
|
+
return;
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
if (!category.labels?.name) {
|
|
1784
|
+
console.error('Category should have a `labels.name`.');
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
if (!['image', 'audio', 'video'].includes(category.mediaType)) {
|
|
1789
|
+
console.error('Category should have `mediaType` property that is one of `image|audio|video`.');
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
if (!category.fetch || typeof category.fetch !== 'function') {
|
|
1794
|
+
console.error('Category should have a `fetch` function defined with the following signature `(InserterMediaRequest) => Promise<InserterMediaItem[]>`.');
|
|
1795
|
+
return;
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
const {
|
|
1799
|
+
inserterMediaCategories = []
|
|
1800
|
+
} = select.getSettings();
|
|
1801
|
+
|
|
1802
|
+
if (inserterMediaCategories.some(({
|
|
1803
|
+
name
|
|
1804
|
+
}) => name === category.name)) {
|
|
1805
|
+
console.error(`A category is already registered with the same name: "${category.name}".`);
|
|
1806
|
+
return;
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
if (inserterMediaCategories.some(({
|
|
1810
|
+
labels: {
|
|
1811
|
+
name
|
|
1812
|
+
}
|
|
1813
|
+
}) => name === category.labels?.name)) {
|
|
1814
|
+
console.error(`A category is already registered with the same labels.name: "${category.labels.name}".`);
|
|
1815
|
+
return;
|
|
1816
|
+
} // `inserterMediaCategories` is a private block editor setting, which means it cannot
|
|
1817
|
+
// be updated through the public `updateSettings` action. We preserve this setting as
|
|
1818
|
+
// private, so extenders can only add new inserter media categories and don't have any
|
|
1819
|
+
// control over the core media categories.
|
|
1820
|
+
|
|
1821
|
+
|
|
1822
|
+
dispatch({
|
|
1823
|
+
type: 'UPDATE_SETTINGS',
|
|
1824
|
+
settings: {
|
|
1825
|
+
inserterMediaCategories: [...inserterMediaCategories, { ...category,
|
|
1826
|
+
isExternalResource: true
|
|
1827
|
+
}]
|
|
1828
|
+
}
|
|
1829
|
+
});
|
|
1830
|
+
};
|
|
1831
|
+
|
|
1832
|
+
exports.registerInserterMediaCategory = registerInserterMediaCategory;
|
|
1639
1833
|
//# sourceMappingURL=actions.js.map
|