@wordpress/block-library 9.2.0 → 9.3.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.
Files changed (302) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/audio/edit.js +20 -8
  3. package/build/audio/edit.js.map +1 -1
  4. package/build/audio/index.js +4 -0
  5. package/build/audio/index.js.map +1 -1
  6. package/build/audio/transforms.js +1 -1
  7. package/build/audio/transforms.js.map +1 -1
  8. package/build/block/edit.js +0 -1
  9. package/build/block/edit.js.map +1 -1
  10. package/build/block/index.js +5 -1
  11. package/build/block/index.js.map +1 -1
  12. package/build/embed/embed-preview.js +4 -4
  13. package/build/embed/embed-preview.js.map +1 -1
  14. package/build/file/edit.js +14 -6
  15. package/build/file/edit.js.map +1 -1
  16. package/build/file/index.js +4 -0
  17. package/build/file/index.js.map +1 -1
  18. package/build/file/transforms.js +2 -3
  19. package/build/file/transforms.js.map +1 -1
  20. package/build/gallery/deprecated.js +6 -54
  21. package/build/gallery/deprecated.js.map +1 -1
  22. package/build/gallery/edit.js +9 -8
  23. package/build/gallery/edit.js.map +1 -1
  24. package/build/gallery/index.js +2 -2
  25. package/build/gallery/index.js.map +1 -1
  26. package/build/gallery/save.js +0 -11
  27. package/build/gallery/save.js.map +1 -1
  28. package/build/gallery/shared.js +0 -27
  29. package/build/gallery/shared.js.map +1 -1
  30. package/build/gallery/transforms.js +29 -80
  31. package/build/gallery/transforms.js.map +1 -1
  32. package/build/group/index.js +1 -0
  33. package/build/group/index.js.map +1 -1
  34. package/build/group/placeholder.js +5 -0
  35. package/build/group/placeholder.js.map +1 -1
  36. package/build/image/edit.js +13 -21
  37. package/build/image/edit.js.map +1 -1
  38. package/build/image/image.js +30 -17
  39. package/build/image/image.js.map +1 -1
  40. package/build/image/index.js +4 -0
  41. package/build/image/index.js.map +1 -1
  42. package/build/image/transforms.js +1 -1
  43. package/build/image/transforms.js.map +1 -1
  44. package/build/list-item/edit.js +1 -1
  45. package/build/list-item/edit.js.map +1 -1
  46. package/build/list-item/hooks/use-merge.js +8 -1
  47. package/build/list-item/hooks/use-merge.js.map +1 -1
  48. package/build/list-item/index.js +11 -1
  49. package/build/list-item/index.js.map +1 -1
  50. package/build/loginout/index.js +3 -0
  51. package/build/loginout/index.js.map +1 -1
  52. package/build/media-text/edit.js +3 -2
  53. package/build/media-text/edit.js.map +1 -1
  54. package/build/navigation-submenu/edit.js +1 -1
  55. package/build/navigation-submenu/edit.js.map +1 -1
  56. package/build/page-list/convert-to-links-modal.js +1 -1
  57. package/build/page-list/convert-to-links-modal.js.map +1 -1
  58. package/build/page-list/edit.js +1 -1
  59. package/build/page-list/edit.js.map +1 -1
  60. package/build/post-content/index.js +3 -0
  61. package/build/post-content/index.js.map +1 -1
  62. package/build/post-date/edit.js +3 -1
  63. package/build/post-date/edit.js.map +1 -1
  64. package/build/post-excerpt/index.js +3 -0
  65. package/build/post-excerpt/index.js.map +1 -1
  66. package/build/post-title/index.js +3 -0
  67. package/build/post-title/index.js.map +1 -1
  68. package/build/query/edit/inspector-controls/index.js +3 -2
  69. package/build/query/edit/inspector-controls/index.js.map +1 -1
  70. package/build/query/edit/query-toolbar.js +54 -61
  71. package/build/query/edit/query-toolbar.js.map +1 -1
  72. package/build/query/index.js +34 -0
  73. package/build/query/index.js.map +1 -1
  74. package/build/social-link/edit.js +27 -7
  75. package/build/social-link/edit.js.map +1 -1
  76. package/build/table/edit.js +8 -17
  77. package/build/table/edit.js.map +1 -1
  78. package/build/template-part/edit/title-modal.js +1 -1
  79. package/build/template-part/edit/title-modal.js.map +1 -1
  80. package/build/utils/hooks.js +12 -0
  81. package/build/utils/hooks.js.map +1 -1
  82. package/build/video/deprecated.js +4 -0
  83. package/build/video/deprecated.js.map +1 -1
  84. package/build/video/edit.js +17 -7
  85. package/build/video/edit.js.map +1 -1
  86. package/build/video/index.js +4 -0
  87. package/build/video/index.js.map +1 -1
  88. package/build/video/transforms.js +1 -1
  89. package/build/video/transforms.js.map +1 -1
  90. package/build-module/audio/edit.js +20 -8
  91. package/build-module/audio/edit.js.map +1 -1
  92. package/build-module/audio/index.js +4 -0
  93. package/build-module/audio/index.js.map +1 -1
  94. package/build-module/audio/transforms.js +1 -1
  95. package/build-module/audio/transforms.js.map +1 -1
  96. package/build-module/block/edit.js +0 -1
  97. package/build-module/block/edit.js.map +1 -1
  98. package/build-module/block/index.js +5 -1
  99. package/build-module/block/index.js.map +1 -1
  100. package/build-module/embed/embed-preview.js +4 -4
  101. package/build-module/embed/embed-preview.js.map +1 -1
  102. package/build-module/file/edit.js +15 -7
  103. package/build-module/file/edit.js.map +1 -1
  104. package/build-module/file/index.js +4 -0
  105. package/build-module/file/index.js.map +1 -1
  106. package/build-module/file/transforms.js +2 -3
  107. package/build-module/file/transforms.js.map +1 -1
  108. package/build-module/gallery/deprecated.js +6 -54
  109. package/build-module/gallery/deprecated.js.map +1 -1
  110. package/build-module/gallery/edit.js +10 -9
  111. package/build-module/gallery/edit.js.map +1 -1
  112. package/build-module/gallery/index.js +1 -1
  113. package/build-module/gallery/index.js.map +1 -1
  114. package/build-module/gallery/save.js +0 -11
  115. package/build-module/gallery/save.js.map +1 -1
  116. package/build-module/gallery/shared.js +0 -25
  117. package/build-module/gallery/shared.js.map +1 -1
  118. package/build-module/gallery/transforms.js +29 -80
  119. package/build-module/gallery/transforms.js.map +1 -1
  120. package/build-module/group/index.js +1 -0
  121. package/build-module/group/index.js.map +1 -1
  122. package/build-module/group/placeholder.js +5 -0
  123. package/build-module/group/placeholder.js.map +1 -1
  124. package/build-module/image/edit.js +12 -20
  125. package/build-module/image/edit.js.map +1 -1
  126. package/build-module/image/image.js +25 -12
  127. package/build-module/image/image.js.map +1 -1
  128. package/build-module/image/index.js +4 -0
  129. package/build-module/image/index.js.map +1 -1
  130. package/build-module/image/transforms.js +1 -1
  131. package/build-module/image/transforms.js.map +1 -1
  132. package/build-module/list-item/edit.js +1 -1
  133. package/build-module/list-item/edit.js.map +1 -1
  134. package/build-module/list-item/hooks/use-merge.js +8 -1
  135. package/build-module/list-item/hooks/use-merge.js.map +1 -1
  136. package/build-module/list-item/index.js +11 -1
  137. package/build-module/list-item/index.js.map +1 -1
  138. package/build-module/loginout/index.js +3 -0
  139. package/build-module/loginout/index.js.map +1 -1
  140. package/build-module/media-text/edit.js +3 -2
  141. package/build-module/media-text/edit.js.map +1 -1
  142. package/build-module/navigation-submenu/edit.js +1 -1
  143. package/build-module/navigation-submenu/edit.js.map +1 -1
  144. package/build-module/page-list/convert-to-links-modal.js +1 -1
  145. package/build-module/page-list/convert-to-links-modal.js.map +1 -1
  146. package/build-module/page-list/edit.js +1 -1
  147. package/build-module/page-list/edit.js.map +1 -1
  148. package/build-module/post-content/index.js +3 -0
  149. package/build-module/post-content/index.js.map +1 -1
  150. package/build-module/post-date/edit.js +4 -2
  151. package/build-module/post-date/edit.js.map +1 -1
  152. package/build-module/post-excerpt/index.js +3 -0
  153. package/build-module/post-excerpt/index.js.map +1 -1
  154. package/build-module/post-title/index.js +3 -0
  155. package/build-module/post-title/index.js.map +1 -1
  156. package/build-module/query/edit/inspector-controls/index.js +3 -2
  157. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  158. package/build-module/query/edit/query-toolbar.js +55 -62
  159. package/build-module/query/edit/query-toolbar.js.map +1 -1
  160. package/build-module/query/index.js +34 -0
  161. package/build-module/query/index.js.map +1 -1
  162. package/build-module/social-link/edit.js +28 -8
  163. package/build-module/social-link/edit.js.map +1 -1
  164. package/build-module/table/edit.js +9 -18
  165. package/build-module/table/edit.js.map +1 -1
  166. package/build-module/template-part/edit/title-modal.js +1 -1
  167. package/build-module/template-part/edit/title-modal.js.map +1 -1
  168. package/build-module/utils/hooks.js +11 -0
  169. package/build-module/utils/hooks.js.map +1 -1
  170. package/build-module/video/deprecated.js +4 -0
  171. package/build-module/video/deprecated.js.map +1 -1
  172. package/build-module/video/edit.js +18 -8
  173. package/build-module/video/edit.js.map +1 -1
  174. package/build-module/video/index.js +4 -0
  175. package/build-module/video/index.js.map +1 -1
  176. package/build-module/video/transforms.js +1 -1
  177. package/build-module/video/transforms.js.map +1 -1
  178. package/build-style/editor-rtl.css +3 -0
  179. package/build-style/editor.css +3 -0
  180. package/build-style/post-comments-form/style-rtl.css +11 -10
  181. package/build-style/post-comments-form/style.css +11 -10
  182. package/build-style/query/editor-rtl.css +3 -0
  183. package/build-style/query/editor.css +3 -0
  184. package/build-style/social-links/style-rtl.css +91 -91
  185. package/build-style/social-links/style.css +91 -91
  186. package/build-style/style-rtl.css +102 -101
  187. package/build-style/style.css +102 -101
  188. package/package.json +35 -35
  189. package/src/audio/block.json +4 -0
  190. package/src/audio/edit.js +19 -7
  191. package/src/audio/transforms.js +1 -1
  192. package/src/block/block.json +5 -1
  193. package/src/block/edit.js +0 -1
  194. package/src/button/index.php +14 -1
  195. package/src/embed/embed-preview.js +4 -6
  196. package/src/file/block.json +4 -0
  197. package/src/file/edit.js +19 -6
  198. package/src/file/transforms.js +1 -2
  199. package/src/gallery/deprecated.js +6 -55
  200. package/src/gallery/edit.js +13 -10
  201. package/src/gallery/gallery-styles.native.scss +0 -2
  202. package/src/gallery/index.js +1 -1
  203. package/src/gallery/save.js +0 -10
  204. package/src/gallery/shared.js +0 -28
  205. package/src/gallery/transforms.js +56 -99
  206. package/src/group/block.json +1 -0
  207. package/src/group/placeholder.js +7 -0
  208. package/src/image/block.json +4 -0
  209. package/src/image/edit.js +10 -19
  210. package/src/image/image.js +36 -14
  211. package/src/image/index.php +26 -5
  212. package/src/image/transforms.js +1 -1
  213. package/src/list-item/block.json +11 -1
  214. package/src/list-item/edit.js +1 -1
  215. package/src/list-item/hooks/use-merge.js +19 -5
  216. package/src/loginout/block.json +3 -0
  217. package/src/media-text/edit.js +3 -2
  218. package/src/navigation-submenu/edit.js +1 -1
  219. package/src/page-list/convert-to-links-modal.js +1 -1
  220. package/src/page-list/edit.js +1 -1
  221. package/src/post-comments-form/style.scss +15 -12
  222. package/src/post-content/block.json +3 -0
  223. package/src/post-date/edit.js +5 -1
  224. package/src/post-date/index.php +8 -2
  225. package/src/post-excerpt/block.json +3 -0
  226. package/src/post-title/block.json +3 -0
  227. package/src/query/edit/inspector-controls/index.js +3 -2
  228. package/src/query/edit/query-toolbar.js +60 -72
  229. package/src/query/editor.scss +4 -0
  230. package/src/query/index.js +40 -0
  231. package/src/social-link/edit.js +29 -3
  232. package/src/social-links/style.scss +2 -2
  233. package/src/table/edit.js +11 -24
  234. package/src/template-part/edit/title-modal.js +1 -1
  235. package/src/utils/hooks.js +14 -1
  236. package/src/video/block.json +4 -0
  237. package/src/video/edit.js +23 -8
  238. package/src/video/transforms.js +1 -1
  239. package/tsconfig.tsbuildinfo +1 -1
  240. package/build/gallery/edit-wrapper.js +0 -37
  241. package/build/gallery/edit-wrapper.js.map +0 -1
  242. package/build/gallery/v1/constants.js +0 -10
  243. package/build/gallery/v1/constants.js.map +0 -1
  244. package/build/gallery/v1/edit.js +0 -399
  245. package/build/gallery/v1/edit.js.map +0 -1
  246. package/build/gallery/v1/gallery-button.native.js +0 -55
  247. package/build/gallery/v1/gallery-button.native.js.map +0 -1
  248. package/build/gallery/v1/gallery-image.js +0 -285
  249. package/build/gallery/v1/gallery-image.js.map +0 -1
  250. package/build/gallery/v1/gallery-image.native.js +0 -297
  251. package/build/gallery/v1/gallery-image.native.js.map +0 -1
  252. package/build/gallery/v1/gallery.js +0 -112
  253. package/build/gallery/v1/gallery.js.map +0 -1
  254. package/build/gallery/v1/gallery.native.js +0 -139
  255. package/build/gallery/v1/gallery.native.js.map +0 -1
  256. package/build/gallery/v1/save.js +0 -81
  257. package/build/gallery/v1/save.js.map +0 -1
  258. package/build/gallery/v1/shared.js +0 -17
  259. package/build/gallery/v1/shared.js.map +0 -1
  260. package/build/gallery/v1/tiles.native.js +0 -83
  261. package/build/gallery/v1/tiles.native.js.map +0 -1
  262. package/build/utils/constants.js +0 -15
  263. package/build/utils/constants.js.map +0 -1
  264. package/build-module/gallery/edit-wrapper.js +0 -31
  265. package/build-module/gallery/edit-wrapper.js.map +0 -1
  266. package/build-module/gallery/v1/constants.js +0 -4
  267. package/build-module/gallery/v1/constants.js.map +0 -1
  268. package/build-module/gallery/v1/edit.js +0 -393
  269. package/build-module/gallery/v1/edit.js.map +0 -1
  270. package/build-module/gallery/v1/gallery-button.native.js +0 -46
  271. package/build-module/gallery/v1/gallery-button.native.js.map +0 -1
  272. package/build-module/gallery/v1/gallery-image.js +0 -279
  273. package/build-module/gallery/v1/gallery-image.js.map +0 -1
  274. package/build-module/gallery/v1/gallery-image.native.js +0 -291
  275. package/build-module/gallery/v1/gallery-image.native.js.map +0 -1
  276. package/build-module/gallery/v1/gallery.js +0 -104
  277. package/build-module/gallery/v1/gallery.js.map +0 -1
  278. package/build-module/gallery/v1/gallery.native.js +0 -131
  279. package/build-module/gallery/v1/gallery.native.js.map +0 -1
  280. package/build-module/gallery/v1/save.js +0 -74
  281. package/build-module/gallery/v1/save.js.map +0 -1
  282. package/build-module/gallery/v1/shared.js +0 -10
  283. package/build-module/gallery/v1/shared.js.map +0 -1
  284. package/build-module/gallery/v1/tiles.native.js +0 -75
  285. package/build-module/gallery/v1/tiles.native.js.map +0 -1
  286. package/build-module/utils/constants.js +0 -9
  287. package/build-module/utils/constants.js.map +0 -1
  288. package/src/gallery/edit-wrapper.js +0 -27
  289. package/src/gallery/v1/constants.js +0 -3
  290. package/src/gallery/v1/edit.js +0 -450
  291. package/src/gallery/v1/gallery-button.native.js +0 -47
  292. package/src/gallery/v1/gallery-image-style.native.scss +0 -109
  293. package/src/gallery/v1/gallery-image.js +0 -293
  294. package/src/gallery/v1/gallery-image.native.js +0 -348
  295. package/src/gallery/v1/gallery-styles.native.scss +0 -8
  296. package/src/gallery/v1/gallery.js +0 -125
  297. package/src/gallery/v1/gallery.native.js +0 -162
  298. package/src/gallery/v1/save.js +0 -98
  299. package/src/gallery/v1/shared.js +0 -19
  300. package/src/gallery/v1/tiles-styles.native.scss +0 -11
  301. package/src/gallery/v1/tiles.native.js +0 -79
  302. package/src/utils/constants.js +0 -8
@@ -1,450 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { compose } from '@wordpress/compose';
5
- import {
6
- PanelBody,
7
- SelectControl,
8
- ToggleControl,
9
- withNotices,
10
- RangeControl,
11
- } from '@wordpress/components';
12
- import {
13
- MediaPlaceholder,
14
- InspectorControls,
15
- useBlockProps,
16
- store as blockEditorStore,
17
- } from '@wordpress/block-editor';
18
- import { Platform, useEffect, useState, useMemo } from '@wordpress/element';
19
- import { __ } from '@wordpress/i18n';
20
- import { getBlobByURL, isBlobURL, revokeBlobURL } from '@wordpress/blob';
21
- import { useDispatch, useSelect } from '@wordpress/data';
22
- import { withViewportMatch } from '@wordpress/viewport';
23
- import { View } from '@wordpress/primitives';
24
- import { store as coreStore } from '@wordpress/core-data';
25
-
26
- /**
27
- * Internal dependencies
28
- */
29
- import { sharedIcon } from '../shared-icon';
30
- import { pickRelevantMediaFiles } from './shared';
31
- import { defaultColumnsNumberV1 } from '../deprecated';
32
- import Gallery from './gallery';
33
- import {
34
- LINK_DESTINATION_ATTACHMENT,
35
- LINK_DESTINATION_MEDIA,
36
- LINK_DESTINATION_NONE,
37
- } from './constants';
38
-
39
- const MAX_COLUMNS = 8;
40
- const linkOptions = [
41
- { value: LINK_DESTINATION_ATTACHMENT, label: __( 'Attachment Page' ) },
42
- { value: LINK_DESTINATION_MEDIA, label: __( 'Media File' ) },
43
- { value: LINK_DESTINATION_NONE, label: __( 'None' ) },
44
- ];
45
- const ALLOWED_MEDIA_TYPES = [ 'image' ];
46
-
47
- const PLACEHOLDER_TEXT = Platform.select( {
48
- web: __(
49
- 'Drag images, upload new ones or select files from your library.'
50
- ),
51
- native: __( 'ADD MEDIA' ),
52
- } );
53
-
54
- const MOBILE_CONTROL_PROPS_RANGE_CONTROL = Platform.select( {
55
- web: {},
56
- native: { type: 'stepper' },
57
- } );
58
-
59
- function GalleryEdit( props ) {
60
- const {
61
- attributes,
62
- clientId,
63
- isSelected,
64
- noticeUI,
65
- noticeOperations,
66
- onFocus,
67
- } = props;
68
- const {
69
- columns = defaultColumnsNumberV1( attributes ),
70
- imageCrop,
71
- images,
72
- linkTo,
73
- sizeSlug,
74
- } = attributes;
75
- const [ selectedImage, setSelectedImage ] = useState();
76
- const [ attachmentCaptions, setAttachmentCaptions ] = useState();
77
- const { __unstableMarkNextChangeAsNotPersistent } =
78
- useDispatch( blockEditorStore );
79
-
80
- const { imageSizes, mediaUpload, getMedia, wasBlockJustInserted } =
81
- useSelect( ( select ) => {
82
- const settings = select( blockEditorStore ).getSettings();
83
-
84
- return {
85
- imageSizes: settings.imageSizes,
86
- mediaUpload: settings.mediaUpload,
87
- getMedia: select( coreStore ).getMedia,
88
- wasBlockJustInserted: select(
89
- blockEditorStore
90
- ).wasBlockJustInserted( clientId, 'inserter_menu' ),
91
- };
92
- } );
93
-
94
- const resizedImages = useMemo( () => {
95
- if ( isSelected ) {
96
- return ( attributes.ids ?? [] ).reduce(
97
- ( currentResizedImages, id ) => {
98
- if ( ! id ) {
99
- return currentResizedImages;
100
- }
101
- const image = getMedia( id );
102
- const sizes = imageSizes.reduce( ( currentSizes, size ) => {
103
- const defaultUrl = image?.sizes?.[ size.slug ]?.url;
104
- const mediaDetailsUrl =
105
- image?.media_details?.sizes?.[ size.slug ]
106
- ?.source_url;
107
- return {
108
- ...currentSizes,
109
- [ size.slug ]: defaultUrl || mediaDetailsUrl,
110
- };
111
- }, {} );
112
- return {
113
- ...currentResizedImages,
114
- [ parseInt( id, 10 ) ]: sizes,
115
- };
116
- },
117
- {}
118
- );
119
- }
120
- return {};
121
- }, [ isSelected, attributes.ids, imageSizes ] );
122
-
123
- function onFocusGalleryCaption() {
124
- setSelectedImage();
125
- }
126
-
127
- function setAttributes( newAttrs ) {
128
- if ( newAttrs.ids ) {
129
- throw new Error(
130
- 'The "ids" attribute should not be changed directly. It is managed automatically when "images" attribute changes'
131
- );
132
- }
133
-
134
- if ( newAttrs.images ) {
135
- newAttrs = {
136
- ...newAttrs,
137
- // Unlike images[ n ].id which is a string, always ensure the
138
- // ids array contains numbers as per its attribute type.
139
- ids: newAttrs.images.map( ( { id } ) => parseInt( id, 10 ) ),
140
- };
141
- }
142
-
143
- props.setAttributes( newAttrs );
144
- }
145
-
146
- function onSelectImage( index ) {
147
- return () => {
148
- setSelectedImage( index );
149
- };
150
- }
151
-
152
- function onDeselectImage() {
153
- return () => {
154
- setSelectedImage();
155
- };
156
- }
157
-
158
- function onMove( oldIndex, newIndex ) {
159
- const newImages = [ ...images ];
160
- newImages.splice( newIndex, 1, images[ oldIndex ] );
161
- newImages.splice( oldIndex, 1, images[ newIndex ] );
162
- setSelectedImage( newIndex );
163
- setAttributes( { images: newImages } );
164
- }
165
-
166
- function onMoveForward( oldIndex ) {
167
- return () => {
168
- if ( oldIndex === images.length - 1 ) {
169
- return;
170
- }
171
- onMove( oldIndex, oldIndex + 1 );
172
- };
173
- }
174
-
175
- function onMoveBackward( oldIndex ) {
176
- return () => {
177
- if ( oldIndex === 0 ) {
178
- return;
179
- }
180
- onMove( oldIndex, oldIndex - 1 );
181
- };
182
- }
183
-
184
- function onRemoveImage( index ) {
185
- return () => {
186
- const newImages = images.filter( ( img, i ) => index !== i );
187
- setSelectedImage();
188
- setAttributes( {
189
- images: newImages,
190
- columns: attributes.columns
191
- ? Math.min( newImages.length, attributes.columns )
192
- : attributes.columns,
193
- } );
194
- };
195
- }
196
-
197
- function selectCaption( newImage ) {
198
- // The image id in both the images and attachmentCaptions arrays is a
199
- // string, so ensure comparison works correctly by converting the
200
- // newImage.id to a string.
201
- const newImageId = newImage.id.toString();
202
- const currentImage = images.find( ( { id } ) => id === newImageId );
203
- const currentImageCaption = currentImage
204
- ? currentImage.caption
205
- : newImage.caption;
206
-
207
- if ( ! attachmentCaptions ) {
208
- return currentImageCaption;
209
- }
210
-
211
- const attachment = attachmentCaptions.find(
212
- ( { id } ) => id === newImageId
213
- );
214
-
215
- // If the attachment caption is updated.
216
- if ( attachment && attachment.caption !== newImage.caption ) {
217
- return newImage.caption;
218
- }
219
-
220
- return currentImageCaption;
221
- }
222
-
223
- function onSelectImages( newImages ) {
224
- setAttachmentCaptions(
225
- newImages.map( ( newImage ) => ( {
226
- // Store the attachmentCaption id as a string for consistency
227
- // with the type of the id in the images attribute.
228
- id: newImage.id.toString(),
229
- caption: newImage.caption,
230
- } ) )
231
- );
232
- setAttributes( {
233
- images: newImages.map( ( newImage ) => ( {
234
- ...pickRelevantMediaFiles( newImage, sizeSlug ),
235
- caption: selectCaption( newImage, images, attachmentCaptions ),
236
- // The id value is stored in a data attribute, so when the
237
- // block is parsed it's converted to a string. Converting
238
- // to a string here ensures it's type is consistent.
239
- id: newImage.id.toString(),
240
- } ) ),
241
- columns: attributes.columns
242
- ? Math.min( newImages.length, attributes.columns )
243
- : attributes.columns,
244
- } );
245
- }
246
-
247
- function onUploadError( message ) {
248
- noticeOperations.removeAllNotices();
249
- noticeOperations.createErrorNotice( message );
250
- }
251
-
252
- function setLinkTo( value ) {
253
- setAttributes( { linkTo: value } );
254
- }
255
-
256
- function setColumnsNumber( value ) {
257
- setAttributes( { columns: value } );
258
- }
259
-
260
- function toggleImageCrop() {
261
- setAttributes( { imageCrop: ! imageCrop } );
262
- }
263
-
264
- function getImageCropHelp( checked ) {
265
- return checked
266
- ? __( 'Thumbnails are cropped to align.' )
267
- : __( 'Thumbnails are not cropped.' );
268
- }
269
-
270
- function setImageAttributes( index, newAttributes ) {
271
- if ( ! images[ index ] ) {
272
- return;
273
- }
274
-
275
- setAttributes( {
276
- images: [
277
- ...images.slice( 0, index ),
278
- {
279
- ...images[ index ],
280
- ...newAttributes,
281
- },
282
- ...images.slice( index + 1 ),
283
- ],
284
- } );
285
- }
286
-
287
- function getImagesSizeOptions() {
288
- const resizedImageSizes = Object.values( resizedImages );
289
- return imageSizes
290
- .filter( ( { slug } ) =>
291
- resizedImageSizes.some( ( sizes ) => sizes[ slug ] )
292
- )
293
- .map( ( { name, slug } ) => ( { value: slug, label: name } ) );
294
- }
295
-
296
- function updateImagesSize( newSizeSlug ) {
297
- const updatedImages = ( images ?? [] ).map( ( image ) => {
298
- if ( ! image.id ) {
299
- return image;
300
- }
301
- const url =
302
- resizedImages[ parseInt( image.id, 10 ) ]?.[ newSizeSlug ];
303
- return {
304
- ...image,
305
- ...( url && { url } ),
306
- };
307
- } );
308
-
309
- setAttributes( { images: updatedImages, sizeSlug: newSizeSlug } );
310
- }
311
-
312
- useEffect( () => {
313
- if (
314
- Platform.OS === 'web' &&
315
- images &&
316
- images.length > 0 &&
317
- images.every( ( { url } ) => isBlobURL( url ) )
318
- ) {
319
- const filesList = images.map( ( { url } ) => getBlobByURL( url ) );
320
- images.forEach( ( { url } ) => revokeBlobURL( url ) );
321
- mediaUpload( {
322
- filesList,
323
- onFileChange: onSelectImages,
324
- allowedTypes: [ 'image' ],
325
- } );
326
- }
327
- }, [] );
328
-
329
- useEffect( () => {
330
- // Deselect images when deselecting the block.
331
- if ( ! isSelected ) {
332
- setSelectedImage();
333
- }
334
- }, [ isSelected ] );
335
-
336
- useEffect( () => {
337
- // linkTo attribute must be saved so blocks don't break when changing
338
- // image_default_link_type in options.php.
339
- if ( ! linkTo ) {
340
- __unstableMarkNextChangeAsNotPersistent();
341
- setAttributes( {
342
- linkTo:
343
- window?.wp?.media?.view?.settings?.defaultProps?.link ||
344
- LINK_DESTINATION_NONE,
345
- } );
346
- }
347
- }, [ linkTo ] );
348
-
349
- const hasImages = !! images.length;
350
- const hasImageIds = hasImages && images.some( ( image ) => !! image.id );
351
-
352
- const mediaPlaceholder = (
353
- <MediaPlaceholder
354
- addToGallery={ hasImageIds }
355
- isAppender={ hasImages }
356
- disableMediaButtons={ hasImages && ! isSelected }
357
- icon={ ! hasImages && sharedIcon }
358
- labels={ {
359
- title: ! hasImages && __( 'Gallery' ),
360
- instructions: ! hasImages && PLACEHOLDER_TEXT,
361
- } }
362
- onSelect={ onSelectImages }
363
- accept="image/*"
364
- allowedTypes={ ALLOWED_MEDIA_TYPES }
365
- multiple
366
- value={ hasImageIds ? images : {} }
367
- onError={ onUploadError }
368
- notices={ hasImages ? undefined : noticeUI }
369
- onFocus={ onFocus }
370
- autoOpenMediaUpload={
371
- ! hasImages && isSelected && wasBlockJustInserted
372
- }
373
- />
374
- );
375
-
376
- const blockProps = useBlockProps();
377
-
378
- if ( ! hasImages ) {
379
- return <View { ...blockProps }>{ mediaPlaceholder }</View>;
380
- }
381
-
382
- const imageSizeOptions = getImagesSizeOptions();
383
- const shouldShowSizeOptions = hasImages && imageSizeOptions.length > 0;
384
-
385
- return (
386
- <>
387
- <InspectorControls>
388
- <PanelBody title={ __( 'Settings' ) }>
389
- { images.length > 1 && (
390
- <RangeControl
391
- __nextHasNoMarginBottom
392
- label={ __( 'Columns' ) }
393
- value={ columns }
394
- onChange={ setColumnsNumber }
395
- min={ 1 }
396
- max={ Math.min( MAX_COLUMNS, images.length ) }
397
- { ...MOBILE_CONTROL_PROPS_RANGE_CONTROL }
398
- required
399
- />
400
- ) }
401
- <ToggleControl
402
- __nextHasNoMarginBottom
403
- label={ __( 'Crop images' ) }
404
- checked={ !! imageCrop }
405
- onChange={ toggleImageCrop }
406
- help={ getImageCropHelp }
407
- />
408
- <SelectControl
409
- __nextHasNoMarginBottom
410
- label={ __( 'Link to' ) }
411
- value={ linkTo }
412
- onChange={ setLinkTo }
413
- options={ linkOptions }
414
- hideCancelButton
415
- />
416
- { shouldShowSizeOptions && (
417
- <SelectControl
418
- __nextHasNoMarginBottom
419
- label={ __( 'Image size' ) }
420
- value={ sizeSlug }
421
- options={ imageSizeOptions }
422
- onChange={ updateImagesSize }
423
- hideCancelButton
424
- />
425
- ) }
426
- </PanelBody>
427
- </InspectorControls>
428
- { noticeUI }
429
- <Gallery
430
- { ...props }
431
- selectedImage={ selectedImage }
432
- mediaPlaceholder={ mediaPlaceholder }
433
- onMoveBackward={ onMoveBackward }
434
- onMoveForward={ onMoveForward }
435
- onRemoveImage={ onRemoveImage }
436
- onSelectImage={ onSelectImage }
437
- onDeselectImage={ onDeselectImage }
438
- onSetImageAttributes={ setImageAttributes }
439
- blockProps={ blockProps }
440
- // This prop is used by gallery.native.js.
441
- onFocusGalleryCaption={ onFocusGalleryCaption }
442
- />
443
- </>
444
- );
445
- }
446
-
447
- export default compose( [
448
- withNotices,
449
- withViewportMatch( { isNarrow: '< small' } ),
450
- ] )( GalleryEdit );
@@ -1,47 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { StyleSheet, TouchableOpacity } from 'react-native';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { Icon } from '@wordpress/components';
10
-
11
- /**
12
- * Internal dependencies
13
- */
14
- import style from './gallery-image-style.scss';
15
-
16
- export function Button( props ) {
17
- const {
18
- icon,
19
- iconSize = 24,
20
- onClick,
21
- disabled,
22
- 'aria-disabled': ariaDisabled,
23
- accessibilityLabel = 'button',
24
- style: customStyle,
25
- } = props;
26
-
27
- const buttonStyle = StyleSheet.compose( style.buttonActive, customStyle );
28
-
29
- const isDisabled = disabled || ariaDisabled;
30
-
31
- const { fill } = isDisabled ? style.buttonDisabled : style.button;
32
-
33
- return (
34
- <TouchableOpacity
35
- style={ buttonStyle }
36
- activeOpacity={ 0.7 }
37
- accessibilityLabel={ accessibilityLabel }
38
- accessibilityRole="button"
39
- onPress={ onClick }
40
- disabled={ isDisabled }
41
- >
42
- <Icon icon={ icon } fill={ fill } size={ iconSize } />
43
- </TouchableOpacity>
44
- );
45
- }
46
-
47
- export default Button;
@@ -1,109 +0,0 @@
1
- $gallery-image-container-height: 150px;
2
- $overlay-border-width: 2px;
3
- $caption-background-color: rgba(0, 0, 0, 0.4);
4
-
5
- .galleryImageContainer {
6
- flex: 1;
7
- height: $gallery-image-container-height;
8
- overflow: hidden;
9
- background-color: $gray-lighten-30;
10
- }
11
-
12
- .galleryImageContainerDark {
13
- background-color: $gray-90;
14
- }
15
-
16
- .image {
17
- height: 100%;
18
- }
19
-
20
- .button {
21
- fill: $gray-0;
22
- width: 30px;
23
- }
24
-
25
- .buttonDisabled {
26
- fill: $gray-30;
27
- }
28
-
29
- .buttonActive {
30
- flex-direction: row;
31
- justify-content: center;
32
- align-items: center;
33
- border-radius: 6px;
34
- border-color: $gray-70;
35
- background-color: $gray-70;
36
- }
37
-
38
- .moverButtonContainer {
39
- flex-direction: row;
40
- align-items: center;
41
- border-radius: 3px;
42
- background-color: $gray-70;
43
- }
44
-
45
- .separator {
46
- border-right-color: $gray-30;
47
- border-right-width: 1px;
48
- height: 20px;
49
- }
50
-
51
- .toolbarContainer {
52
- position: absolute;
53
- }
54
-
55
- .toolbar {
56
- padding: 5px;
57
- flex-direction: row;
58
- justify-content: space-between;
59
- }
60
-
61
- .captionContainer {
62
- flex: 1;
63
- flex-direction: row;
64
- align-items: flex-end;
65
- position: absolute;
66
- bottom: $overlay-border-width;
67
- left: $overlay-border-width;
68
- right: $overlay-border-width;
69
- top: 45;
70
- }
71
-
72
- @mixin caption-shared {
73
- font-size: 12px;
74
- background-color: #0000;
75
- color: #fff;
76
- font-family: $default-regular-font;
77
- text-align: center;
78
- }
79
-
80
- .caption {
81
- @include caption-shared;
82
- background-color: $caption-background-color;
83
- padding-top: $grid-unit;
84
- padding-bottom: $grid-unit;
85
- }
86
-
87
- .captionPlaceholder {
88
- color: #ccc;
89
- }
90
-
91
- // expand caption container to compensate for overlay border
92
- .captionExpandedContainer {
93
- // constrain height to gallery image height for caption scroll
94
- max-height: $gallery-image-container-height;
95
- position: absolute;
96
- bottom: 0;
97
- left: 0;
98
- right: 0;
99
- padding-top: $grid-unit;
100
- padding-bottom: $overlay-border-width + $grid-unit;
101
- padding-left: $overlay-border-width;
102
- padding-right: $overlay-border-width;
103
- // use caption background color on container when expanded
104
- background-color: $caption-background-color;
105
- }
106
-
107
- .captionExpanded {
108
- @include caption-shared;
109
- }