@wordpress/block-editor 11.3.4 → 11.3.6
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 +11 -1
- package/build/components/block-inspector/index.js +11 -10
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-inspector/useBlockInspectorAnimationSettings.js +46 -0
- package/build/components/block-inspector/useBlockInspectorAnimationSettings.js.map +1 -0
- package/build/components/inserter/media-tab/hooks.js +10 -11
- package/build/components/inserter/media-tab/hooks.js.map +1 -1
- package/build/components/inserter/media-tab/media-list.js +5 -108
- package/build/components/inserter/media-tab/media-list.js.map +1 -1
- package/build/components/inserter/media-tab/media-preview.js +242 -0
- package/build/components/inserter/media-tab/media-preview.js.map +1 -0
- package/build/components/link-control/index.js +17 -44
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/list-view/block.js +14 -2
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +2 -2
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/leaf.js +10 -6
- package/build/components/list-view/leaf.js.map +1 -1
- package/build/components/list-view/use-list-view-scroll-into-view.js +51 -0
- package/build/components/list-view/use-list-view-scroll-into-view.js.map +1 -0
- package/build/components/off-canvas-editor/leaf-more-menu.js +126 -0
- package/build/components/off-canvas-editor/leaf-more-menu.js.map +1 -0
- package/build/private-apis.js +3 -0
- package/build/private-apis.js.map +1 -1
- package/build/store/defaults.js +28 -1
- package/build/store/defaults.js.map +1 -1
- package/build/store/selectors.js +1 -1
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-inspector/index.js +9 -9
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-inspector/useBlockInspectorAnimationSettings.js +37 -0
- package/build-module/components/block-inspector/useBlockInspectorAnimationSettings.js.map +1 -0
- package/build-module/components/inserter/media-tab/hooks.js +10 -11
- package/build-module/components/inserter/media-tab/hooks.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-list.js +6 -105
- package/build-module/components/inserter/media-tab/media-list.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-preview.js +222 -0
- package/build-module/components/inserter/media-tab/media-preview.js.map +1 -0
- package/build-module/components/link-control/index.js +16 -44
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/list-view/block.js +13 -2
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +2 -2
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/leaf.js +8 -4
- package/build-module/components/list-view/leaf.js.map +1 -1
- package/build-module/components/list-view/use-list-view-scroll-into-view.js +42 -0
- package/build-module/components/list-view/use-list-view-scroll-into-view.js.map +1 -0
- package/build-module/components/off-canvas-editor/leaf-more-menu.js +108 -0
- package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +1 -0
- package/build-module/private-apis.js +2 -0
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/defaults.js +28 -1
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/selectors.js +1 -1
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +43 -8
- package/build-style/style.css +43 -8
- package/package.json +12 -12
- package/src/components/block-inspector/index.js +11 -14
- package/src/components/block-inspector/useBlockInspectorAnimationSettings.js +53 -0
- package/src/components/inserter/media-tab/hooks.js +9 -8
- package/src/components/inserter/media-tab/media-list.js +3 -122
- package/src/components/inserter/media-tab/media-preview.js +268 -0
- package/src/components/inserter/style.scss +22 -0
- package/src/components/link-control/index.js +23 -58
- package/src/components/link-control/style.scss +23 -7
- package/src/components/link-control/test/index.js +5 -134
- package/src/components/list-view/block.js +12 -0
- package/src/components/list-view/branch.js +1 -2
- package/src/components/list-view/leaf.js +43 -29
- package/src/components/list-view/use-list-view-scroll-into-view.js +48 -0
- package/src/components/media-replace-flow/test/index.js +1 -1
- package/src/components/off-canvas-editor/leaf-more-menu.js +120 -0
- package/src/components/spacing-sizes-control/style.scss +1 -1
- package/src/private-apis.js +2 -0
- package/src/store/defaults.js +14 -1
- package/src/store/selectors.js +4 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1699,6 +1699,7 @@
|
|
|
1699
1699
|
width: calc(100% - 32px);
|
|
1700
1700
|
display: block;
|
|
1701
1701
|
padding: 11px 16px;
|
|
1702
|
+
padding-left: 36px;
|
|
1702
1703
|
margin: 0;
|
|
1703
1704
|
position: relative;
|
|
1704
1705
|
border: 1px solid #ddd;
|
|
@@ -1738,10 +1739,20 @@
|
|
|
1738
1739
|
}
|
|
1739
1740
|
|
|
1740
1741
|
.block-editor-link-control__search-actions {
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1742
|
+
position: absolute;
|
|
1743
|
+
/*
|
|
1744
|
+
* Actions must be positioned on top of URLInput, since the input will grow
|
|
1745
|
+
* when suggestions are rendered.
|
|
1746
|
+
*
|
|
1747
|
+
* Compensate for:
|
|
1748
|
+
* - Border (1px)
|
|
1749
|
+
* - Vertically, for the difference in height between the input (40px) and
|
|
1750
|
+
* the icon buttons.
|
|
1751
|
+
* - Horizontally, pad to the minimum of: default input padding, or the
|
|
1752
|
+
* equivalent of the vertical padding.
|
|
1753
|
+
*/
|
|
1754
|
+
top: 3px;
|
|
1755
|
+
left: 19px;
|
|
1745
1756
|
}
|
|
1746
1757
|
|
|
1747
1758
|
.components-button .block-editor-link-control__search-submit .has-icon {
|
|
@@ -2026,10 +2037,9 @@
|
|
|
2026
2037
|
padding: 10px;
|
|
2027
2038
|
}
|
|
2028
2039
|
|
|
2029
|
-
.block-editor-link-
|
|
2040
|
+
.block-editor-link-control__tools {
|
|
2030
2041
|
display: flex;
|
|
2031
2042
|
align-items: center;
|
|
2032
|
-
justify-content: space-between;
|
|
2033
2043
|
border-top: 1px solid #ddd;
|
|
2034
2044
|
margin: 0;
|
|
2035
2045
|
padding: 16px;
|
|
@@ -2065,8 +2075,14 @@
|
|
|
2065
2075
|
position: absolute;
|
|
2066
2076
|
right: auto;
|
|
2067
2077
|
bottom: auto;
|
|
2078
|
+
/*
|
|
2079
|
+
* Position spinner to the left of the actions.
|
|
2080
|
+
*
|
|
2081
|
+
* Compensate for:
|
|
2082
|
+
* - Input padding right ($button-size)
|
|
2083
|
+
*/
|
|
2068
2084
|
top: calc(50% - 16px / 2);
|
|
2069
|
-
left:
|
|
2085
|
+
left: 36px;
|
|
2070
2086
|
}
|
|
2071
2087
|
|
|
2072
2088
|
.block-editor-link-control__search-item-action {
|
|
@@ -3841,6 +3857,16 @@
|
|
|
3841
3857
|
margin: 0 auto;
|
|
3842
3858
|
max-width: 100%;
|
|
3843
3859
|
}
|
|
3860
|
+
.block-editor-inserter__media-list .block-editor-inserter__media-list__item .block-editor-inserter__media-list__item-preview .block-editor-inserter__media-list__item-preview-spinner {
|
|
3861
|
+
display: flex;
|
|
3862
|
+
height: 100%;
|
|
3863
|
+
width: 100%;
|
|
3864
|
+
position: absolute;
|
|
3865
|
+
justify-content: center;
|
|
3866
|
+
background: rgba(255, 255, 255, 0.7);
|
|
3867
|
+
align-items: center;
|
|
3868
|
+
pointer-events: none;
|
|
3869
|
+
}
|
|
3844
3870
|
.block-editor-inserter__media-list .block-editor-inserter__media-list__item:focus .block-editor-inserter__media-list__item-preview {
|
|
3845
3871
|
box-shadow: inset 0 0 0 2px #fff, 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
|
|
3846
3872
|
outline: 2px solid transparent;
|
|
@@ -3858,6 +3884,15 @@
|
|
|
3858
3884
|
height: 100%;
|
|
3859
3885
|
}
|
|
3860
3886
|
|
|
3887
|
+
@media (min-width: 600px) {
|
|
3888
|
+
.block-editor-inserter-media-tab-media-preview-inserter-external-image-modal {
|
|
3889
|
+
max-width: 480px;
|
|
3890
|
+
}
|
|
3891
|
+
}
|
|
3892
|
+
.block-editor-inserter-media-tab-media-preview-inserter-external-image-modal p {
|
|
3893
|
+
margin: 0;
|
|
3894
|
+
}
|
|
3895
|
+
|
|
3861
3896
|
.block-editor-post-preview__dropdown {
|
|
3862
3897
|
padding: 0;
|
|
3863
3898
|
}
|
|
@@ -4019,7 +4054,7 @@
|
|
|
4019
4054
|
.component-spacing-sizes-control .components-range-control__marks :first-child {
|
|
4020
4055
|
display: none;
|
|
4021
4056
|
}
|
|
4022
|
-
.component-spacing-sizes-control
|
|
4057
|
+
.component-spacing-sizes-control .components-range-control__thumb-wrapper {
|
|
4023
4058
|
z-index: 3;
|
|
4024
4059
|
}
|
|
4025
4060
|
.component-spacing-sizes-control .components-spacing-sizes-control__custom-select-control {
|
package/build-style/style.css
CHANGED
|
@@ -1699,6 +1699,7 @@
|
|
|
1699
1699
|
width: calc(100% - 32px);
|
|
1700
1700
|
display: block;
|
|
1701
1701
|
padding: 11px 16px;
|
|
1702
|
+
padding-right: 36px;
|
|
1702
1703
|
margin: 0;
|
|
1703
1704
|
position: relative;
|
|
1704
1705
|
border: 1px solid #ddd;
|
|
@@ -1738,10 +1739,20 @@
|
|
|
1738
1739
|
}
|
|
1739
1740
|
|
|
1740
1741
|
.block-editor-link-control__search-actions {
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1742
|
+
position: absolute;
|
|
1743
|
+
/*
|
|
1744
|
+
* Actions must be positioned on top of URLInput, since the input will grow
|
|
1745
|
+
* when suggestions are rendered.
|
|
1746
|
+
*
|
|
1747
|
+
* Compensate for:
|
|
1748
|
+
* - Border (1px)
|
|
1749
|
+
* - Vertically, for the difference in height between the input (40px) and
|
|
1750
|
+
* the icon buttons.
|
|
1751
|
+
* - Horizontally, pad to the minimum of: default input padding, or the
|
|
1752
|
+
* equivalent of the vertical padding.
|
|
1753
|
+
*/
|
|
1754
|
+
top: 3px;
|
|
1755
|
+
right: 19px;
|
|
1745
1756
|
}
|
|
1746
1757
|
|
|
1747
1758
|
.components-button .block-editor-link-control__search-submit .has-icon {
|
|
@@ -2026,10 +2037,9 @@
|
|
|
2026
2037
|
padding: 10px;
|
|
2027
2038
|
}
|
|
2028
2039
|
|
|
2029
|
-
.block-editor-link-
|
|
2040
|
+
.block-editor-link-control__tools {
|
|
2030
2041
|
display: flex;
|
|
2031
2042
|
align-items: center;
|
|
2032
|
-
justify-content: space-between;
|
|
2033
2043
|
border-top: 1px solid #ddd;
|
|
2034
2044
|
margin: 0;
|
|
2035
2045
|
padding: 16px;
|
|
@@ -2065,8 +2075,14 @@
|
|
|
2065
2075
|
position: absolute;
|
|
2066
2076
|
left: auto;
|
|
2067
2077
|
bottom: auto;
|
|
2078
|
+
/*
|
|
2079
|
+
* Position spinner to the left of the actions.
|
|
2080
|
+
*
|
|
2081
|
+
* Compensate for:
|
|
2082
|
+
* - Input padding right ($button-size)
|
|
2083
|
+
*/
|
|
2068
2084
|
top: calc(50% - 16px / 2);
|
|
2069
|
-
right:
|
|
2085
|
+
right: 36px;
|
|
2070
2086
|
}
|
|
2071
2087
|
|
|
2072
2088
|
.block-editor-link-control__search-item-action {
|
|
@@ -3841,6 +3857,16 @@
|
|
|
3841
3857
|
margin: 0 auto;
|
|
3842
3858
|
max-width: 100%;
|
|
3843
3859
|
}
|
|
3860
|
+
.block-editor-inserter__media-list .block-editor-inserter__media-list__item .block-editor-inserter__media-list__item-preview .block-editor-inserter__media-list__item-preview-spinner {
|
|
3861
|
+
display: flex;
|
|
3862
|
+
height: 100%;
|
|
3863
|
+
width: 100%;
|
|
3864
|
+
position: absolute;
|
|
3865
|
+
justify-content: center;
|
|
3866
|
+
background: rgba(255, 255, 255, 0.7);
|
|
3867
|
+
align-items: center;
|
|
3868
|
+
pointer-events: none;
|
|
3869
|
+
}
|
|
3844
3870
|
.block-editor-inserter__media-list .block-editor-inserter__media-list__item:focus .block-editor-inserter__media-list__item-preview {
|
|
3845
3871
|
box-shadow: inset 0 0 0 2px #fff, 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
|
|
3846
3872
|
outline: 2px solid transparent;
|
|
@@ -3858,6 +3884,15 @@
|
|
|
3858
3884
|
height: 100%;
|
|
3859
3885
|
}
|
|
3860
3886
|
|
|
3887
|
+
@media (min-width: 600px) {
|
|
3888
|
+
.block-editor-inserter-media-tab-media-preview-inserter-external-image-modal {
|
|
3889
|
+
max-width: 480px;
|
|
3890
|
+
}
|
|
3891
|
+
}
|
|
3892
|
+
.block-editor-inserter-media-tab-media-preview-inserter-external-image-modal p {
|
|
3893
|
+
margin: 0;
|
|
3894
|
+
}
|
|
3895
|
+
|
|
3861
3896
|
.block-editor-post-preview__dropdown {
|
|
3862
3897
|
padding: 0;
|
|
3863
3898
|
}
|
|
@@ -4019,7 +4054,7 @@
|
|
|
4019
4054
|
.component-spacing-sizes-control .components-range-control__marks :first-child {
|
|
4020
4055
|
display: none;
|
|
4021
4056
|
}
|
|
4022
|
-
.component-spacing-sizes-control
|
|
4057
|
+
.component-spacing-sizes-control .components-range-control__thumb-wrapper {
|
|
4023
4058
|
z-index: 3;
|
|
4024
4059
|
}
|
|
4025
4060
|
.component-spacing-sizes-control .components-spacing-sizes-control__custom-select-control {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/block-editor",
|
|
3
|
-
"version": "11.3.
|
|
3
|
+
"version": "11.3.6",
|
|
4
4
|
"description": "Generic block editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -36,26 +36,26 @@
|
|
|
36
36
|
"@wordpress/a11y": "^3.26.1",
|
|
37
37
|
"@wordpress/api-fetch": "^6.23.1",
|
|
38
38
|
"@wordpress/blob": "^3.26.1",
|
|
39
|
-
"@wordpress/blocks": "^12.3.
|
|
40
|
-
"@wordpress/components": "^23.3.
|
|
41
|
-
"@wordpress/compose": "^6.3.
|
|
42
|
-
"@wordpress/data": "^8.3.
|
|
39
|
+
"@wordpress/blocks": "^12.3.3",
|
|
40
|
+
"@wordpress/components": "^23.3.5",
|
|
41
|
+
"@wordpress/compose": "^6.3.3",
|
|
42
|
+
"@wordpress/data": "^8.3.3",
|
|
43
43
|
"@wordpress/date": "^4.26.2",
|
|
44
44
|
"@wordpress/deprecated": "^3.26.1",
|
|
45
45
|
"@wordpress/dom": "^3.26.1",
|
|
46
|
-
"@wordpress/element": "^5.3.
|
|
46
|
+
"@wordpress/element": "^5.3.2",
|
|
47
47
|
"@wordpress/escape-html": "^2.26.1",
|
|
48
48
|
"@wordpress/hooks": "^3.26.1",
|
|
49
49
|
"@wordpress/html-entities": "^3.26.1",
|
|
50
50
|
"@wordpress/i18n": "^4.26.1",
|
|
51
|
-
"@wordpress/icons": "^9.17.
|
|
51
|
+
"@wordpress/icons": "^9.17.2",
|
|
52
52
|
"@wordpress/is-shallow-equal": "^4.26.1",
|
|
53
|
-
"@wordpress/keyboard-shortcuts": "^4.3.
|
|
53
|
+
"@wordpress/keyboard-shortcuts": "^4.3.3",
|
|
54
54
|
"@wordpress/keycodes": "^3.26.2",
|
|
55
|
-
"@wordpress/notices": "^3.26.
|
|
56
|
-
"@wordpress/preferences": "^3.3.
|
|
55
|
+
"@wordpress/notices": "^3.26.3",
|
|
56
|
+
"@wordpress/preferences": "^3.3.5",
|
|
57
57
|
"@wordpress/private-apis": "^0.8.1",
|
|
58
|
-
"@wordpress/rich-text": "^6.3.
|
|
58
|
+
"@wordpress/rich-text": "^6.3.3",
|
|
59
59
|
"@wordpress/shortcode": "^3.26.1",
|
|
60
60
|
"@wordpress/style-engine": "^1.9.1",
|
|
61
61
|
"@wordpress/token-list": "^2.26.1",
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"publishConfig": {
|
|
84
84
|
"access": "public"
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "35f10c183655e9196d4ea12b8fa499a8ecbb7b6a"
|
|
87
87
|
}
|
|
@@ -36,6 +36,7 @@ import { default as InspectorControlsTabs } from '../inspector-controls-tabs';
|
|
|
36
36
|
import useInspectorControlsTabs from '../inspector-controls-tabs/use-inspector-controls-tabs';
|
|
37
37
|
import AdvancedControls from '../inspector-controls-tabs/advanced-controls-panel';
|
|
38
38
|
import PositionControls from '../inspector-controls-tabs/position-controls-panel';
|
|
39
|
+
import useBlockInspectorAnimationSettings from './useBlockInspectorAnimationSettings';
|
|
39
40
|
|
|
40
41
|
function useContentBlocks( blockTypes, block ) {
|
|
41
42
|
const contentBlocksObjectAux = useMemo( () => {
|
|
@@ -56,7 +57,7 @@ function useContentBlocks( blockTypes, block ) {
|
|
|
56
57
|
( blockName ) => {
|
|
57
58
|
return !! contentBlocksObjectAux[ blockName ];
|
|
58
59
|
},
|
|
59
|
-
[
|
|
60
|
+
[ contentBlocksObjectAux ]
|
|
60
61
|
);
|
|
61
62
|
return useMemo( () => {
|
|
62
63
|
return getContentBlocks( [ block ], isContentBlock );
|
|
@@ -173,19 +174,15 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
|
|
|
173
174
|
const availableTabs = useInspectorControlsTabs( blockType?.name );
|
|
174
175
|
const showTabs = availableTabs?.length > 1;
|
|
175
176
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
return null;
|
|
187
|
-
},
|
|
188
|
-
[ selectedBlockClientId, blockType ]
|
|
177
|
+
// The block inspector animation settings will be completely
|
|
178
|
+
// removed in the future to create an API which allows the block
|
|
179
|
+
// inspector to transition between what it
|
|
180
|
+
// displays based on the relationship between the selected block
|
|
181
|
+
// and its parent, and only enable it if the parent is controlling
|
|
182
|
+
// its children blocks.
|
|
183
|
+
const blockInspectorAnimationSettings = useBlockInspectorAnimationSettings(
|
|
184
|
+
blockType,
|
|
185
|
+
selectedBlockClientId
|
|
189
186
|
);
|
|
190
187
|
|
|
191
188
|
if ( count > 1 ) {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect } from '@wordpress/data';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { store as blockEditorStore } from '../../store';
|
|
10
|
+
|
|
11
|
+
export default function useBlockInspectorAnimationSettings(
|
|
12
|
+
blockType,
|
|
13
|
+
selectedBlockClientId
|
|
14
|
+
) {
|
|
15
|
+
return useSelect(
|
|
16
|
+
( select ) => {
|
|
17
|
+
if ( blockType ) {
|
|
18
|
+
const globalBlockInspectorAnimationSettings =
|
|
19
|
+
select( blockEditorStore ).getSettings()
|
|
20
|
+
.blockInspectorAnimation;
|
|
21
|
+
|
|
22
|
+
// Get the name of the block that will allow it's children to be animated.
|
|
23
|
+
const animationParent =
|
|
24
|
+
globalBlockInspectorAnimationSettings?.animationParent;
|
|
25
|
+
|
|
26
|
+
// Determine whether the animationParent block is a parent of the selected block.
|
|
27
|
+
const { getSelectedBlockClientId, getBlockParentsByBlockName } =
|
|
28
|
+
select( blockEditorStore );
|
|
29
|
+
const _selectedBlockClientId = getSelectedBlockClientId();
|
|
30
|
+
const animationParentBlockClientId = getBlockParentsByBlockName(
|
|
31
|
+
_selectedBlockClientId,
|
|
32
|
+
animationParent,
|
|
33
|
+
true
|
|
34
|
+
)[ 0 ];
|
|
35
|
+
|
|
36
|
+
// If the selected block is not a child of the animationParent block,
|
|
37
|
+
// and not an animationParent block itself, don't animate.
|
|
38
|
+
if (
|
|
39
|
+
! animationParentBlockClientId &&
|
|
40
|
+
blockType.name !== animationParent
|
|
41
|
+
) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return globalBlockInspectorAnimationSettings?.[
|
|
46
|
+
blockType.name
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
},
|
|
51
|
+
[ selectedBlockClientId, blockType ]
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -98,13 +98,6 @@ function useInserterMediaCategories() {
|
|
|
98
98
|
) {
|
|
99
99
|
return false;
|
|
100
100
|
}
|
|
101
|
-
// When a category has set `isExternalResource` to `true`, we
|
|
102
|
-
// don't need to check for allowed mime types, as they are used
|
|
103
|
-
// for restricting uploads for this media type and not for
|
|
104
|
-
// inserting media from external sources.
|
|
105
|
-
if ( category.isExternalResource ) {
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
101
|
return Object.values( allowedMimeTypes ).some( ( mimeType ) =>
|
|
109
102
|
mimeType.startsWith( `${ category.mediaType }/` )
|
|
110
103
|
);
|
|
@@ -156,7 +149,15 @@ export function useMediaCategories( rootClientId ) {
|
|
|
156
149
|
if ( category.isExternalResource ) {
|
|
157
150
|
return [ category.name, true ];
|
|
158
151
|
}
|
|
159
|
-
|
|
152
|
+
let results = [];
|
|
153
|
+
try {
|
|
154
|
+
results = await category.fetch( {
|
|
155
|
+
per_page: 1,
|
|
156
|
+
} );
|
|
157
|
+
} catch ( e ) {
|
|
158
|
+
// If the request fails, we shallow the error and just don't show
|
|
159
|
+
// the category, in order to not break the media tab.
|
|
160
|
+
}
|
|
160
161
|
return [ category.name, !! results.length ];
|
|
161
162
|
} )
|
|
162
163
|
)
|
|
@@ -1,129 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import classnames from 'classnames';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* WordPress dependencies
|
|
8
3
|
*/
|
|
9
4
|
import {
|
|
10
5
|
__unstableComposite as Composite,
|
|
11
6
|
__unstableUseCompositeState as useCompositeState,
|
|
12
|
-
__unstableCompositeItem as CompositeItem,
|
|
13
|
-
Tooltip,
|
|
14
|
-
DropdownMenu,
|
|
15
|
-
MenuGroup,
|
|
16
|
-
MenuItem,
|
|
17
7
|
} from '@wordpress/components';
|
|
18
|
-
import { __
|
|
19
|
-
import { useMemo, useCallback, useState } from '@wordpress/element';
|
|
20
|
-
import { cloneBlock } from '@wordpress/blocks';
|
|
21
|
-
import { moreVertical, external } from '@wordpress/icons';
|
|
8
|
+
import { __ } from '@wordpress/i18n';
|
|
22
9
|
|
|
23
10
|
/**
|
|
24
11
|
* Internal dependencies
|
|
25
12
|
*/
|
|
26
|
-
import
|
|
27
|
-
import { getBlockAndPreviewFromMedia } from './utils';
|
|
28
|
-
|
|
29
|
-
const MAXIMUM_TITLE_LENGTH = 25;
|
|
30
|
-
const MEDIA_OPTIONS_POPOVER_PROPS = {
|
|
31
|
-
position: 'bottom left',
|
|
32
|
-
className:
|
|
33
|
-
'block-editor-inserter__media-list__item-preview-options__popover',
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
function MediaPreviewOptions( { category, media } ) {
|
|
37
|
-
if ( ! category.getReportUrl ) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
const reportUrl = category.getReportUrl( media );
|
|
41
|
-
return (
|
|
42
|
-
<DropdownMenu
|
|
43
|
-
className="block-editor-inserter__media-list__item-preview-options"
|
|
44
|
-
label={ __( 'Options' ) }
|
|
45
|
-
popoverProps={ MEDIA_OPTIONS_POPOVER_PROPS }
|
|
46
|
-
icon={ moreVertical }
|
|
47
|
-
>
|
|
48
|
-
{ () => (
|
|
49
|
-
<MenuGroup>
|
|
50
|
-
<MenuItem
|
|
51
|
-
onClick={ () =>
|
|
52
|
-
window.open( reportUrl, '_blank' ).focus()
|
|
53
|
-
}
|
|
54
|
-
icon={ external }
|
|
55
|
-
>
|
|
56
|
-
{ sprintf(
|
|
57
|
-
/* translators: %s: The media type to report e.g: "image", "video", "audio" */
|
|
58
|
-
__( 'Report %s' ),
|
|
59
|
-
category.mediaType
|
|
60
|
-
) }
|
|
61
|
-
</MenuItem>
|
|
62
|
-
</MenuGroup>
|
|
63
|
-
) }
|
|
64
|
-
</DropdownMenu>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function MediaPreview( { media, onClick, composite, category } ) {
|
|
69
|
-
const [ isHovered, setIsHovered ] = useState( false );
|
|
70
|
-
const [ block, preview ] = useMemo(
|
|
71
|
-
() => getBlockAndPreviewFromMedia( media, category.mediaType ),
|
|
72
|
-
[ media, category.mediaType ]
|
|
73
|
-
);
|
|
74
|
-
const title = media.title?.rendered || media.title;
|
|
75
|
-
let truncatedTitle;
|
|
76
|
-
if ( title.length > MAXIMUM_TITLE_LENGTH ) {
|
|
77
|
-
const omission = '...';
|
|
78
|
-
truncatedTitle =
|
|
79
|
-
title.slice( 0, MAXIMUM_TITLE_LENGTH - omission.length ) + omission;
|
|
80
|
-
}
|
|
81
|
-
const onMouseEnter = useCallback( () => setIsHovered( true ), [] );
|
|
82
|
-
const onMouseLeave = useCallback( () => setIsHovered( false ), [] );
|
|
83
|
-
return (
|
|
84
|
-
<InserterDraggableBlocks isEnabled={ true } blocks={ [ block ] }>
|
|
85
|
-
{ ( { draggable, onDragStart, onDragEnd } ) => (
|
|
86
|
-
<div
|
|
87
|
-
className={ classnames(
|
|
88
|
-
'block-editor-inserter__media-list__list-item',
|
|
89
|
-
{
|
|
90
|
-
'is-hovered': isHovered,
|
|
91
|
-
}
|
|
92
|
-
) }
|
|
93
|
-
draggable={ draggable }
|
|
94
|
-
onDragStart={ onDragStart }
|
|
95
|
-
onDragEnd={ onDragEnd }
|
|
96
|
-
>
|
|
97
|
-
<Tooltip text={ truncatedTitle || title }>
|
|
98
|
-
{ /* Adding `is-hovered` class to the wrapper element is needed
|
|
99
|
-
because the options Popover is rendered outside of this node. */ }
|
|
100
|
-
<div
|
|
101
|
-
onMouseEnter={ onMouseEnter }
|
|
102
|
-
onMouseLeave={ onMouseLeave }
|
|
103
|
-
>
|
|
104
|
-
<CompositeItem
|
|
105
|
-
role="option"
|
|
106
|
-
as="div"
|
|
107
|
-
{ ...composite }
|
|
108
|
-
className="block-editor-inserter__media-list__item"
|
|
109
|
-
onClick={ () => onClick( block ) }
|
|
110
|
-
aria-label={ title }
|
|
111
|
-
>
|
|
112
|
-
<div className="block-editor-inserter__media-list__item-preview">
|
|
113
|
-
{ preview }
|
|
114
|
-
</div>
|
|
115
|
-
</CompositeItem>
|
|
116
|
-
<MediaPreviewOptions
|
|
117
|
-
category={ category }
|
|
118
|
-
media={ media }
|
|
119
|
-
/>
|
|
120
|
-
</div>
|
|
121
|
-
</Tooltip>
|
|
122
|
-
</div>
|
|
123
|
-
) }
|
|
124
|
-
</InserterDraggableBlocks>
|
|
125
|
-
);
|
|
126
|
-
}
|
|
13
|
+
import { MediaPreview } from './media-preview';
|
|
127
14
|
|
|
128
15
|
function MediaList( {
|
|
129
16
|
mediaList,
|
|
@@ -132,12 +19,6 @@ function MediaList( {
|
|
|
132
19
|
label = __( 'Media List' ),
|
|
133
20
|
} ) {
|
|
134
21
|
const composite = useCompositeState();
|
|
135
|
-
const onPreviewClick = useCallback(
|
|
136
|
-
( block ) => {
|
|
137
|
-
onClick( cloneBlock( block ) );
|
|
138
|
-
},
|
|
139
|
-
[ onClick ]
|
|
140
|
-
);
|
|
141
22
|
return (
|
|
142
23
|
<Composite
|
|
143
24
|
{ ...composite }
|
|
@@ -150,7 +31,7 @@ function MediaList( {
|
|
|
150
31
|
key={ media.id || media.sourceId || index }
|
|
151
32
|
media={ media }
|
|
152
33
|
category={ category }
|
|
153
|
-
onClick={
|
|
34
|
+
onClick={ onClick }
|
|
154
35
|
composite={ composite }
|
|
155
36
|
/>
|
|
156
37
|
) ) }
|