@wordpress/block-library 9.25.0 → 9.26.1-next.719a03cbe.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 (179) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/avatar/edit.js +84 -39
  3. package/build/avatar/edit.js.map +1 -1
  4. package/build/avatar/user-control.js +32 -17
  5. package/build/avatar/user-control.js.map +1 -1
  6. package/build/button/edit.js +1 -1
  7. package/build/button/edit.js.map +1 -1
  8. package/build/cover/edit/inspector-controls.js +2 -2
  9. package/build/cover/edit/inspector-controls.js.map +1 -1
  10. package/build/details/index.js +1 -1
  11. package/build/details/index.js.map +1 -1
  12. package/build/embed/variations.js +0 -10
  13. package/build/embed/variations.js.map +1 -1
  14. package/build/form/edit.js +0 -1
  15. package/build/form/edit.js.map +1 -1
  16. package/build/form/index.js +3 -3
  17. package/build/form/index.js.map +1 -1
  18. package/build/form-input/index.js +2 -1
  19. package/build/form-input/index.js.map +1 -1
  20. package/build/form-submission-notification/index.js +2 -1
  21. package/build/form-submission-notification/index.js.map +1 -1
  22. package/build/form-submit-button/index.js +2 -1
  23. package/build/form-submit-button/index.js.map +1 -1
  24. package/build/gallery/constants.js +2 -1
  25. package/build/gallery/constants.js.map +1 -1
  26. package/build/gallery/edit.js +93 -15
  27. package/build/gallery/edit.js.map +1 -1
  28. package/build/image/edit.js +6 -0
  29. package/build/image/edit.js.map +1 -1
  30. package/build/image/image.js +1 -0
  31. package/build/image/image.js.map +1 -1
  32. package/build/image/view.js +0 -3
  33. package/build/image/view.js.map +1 -1
  34. package/build/list/index.js +0 -1
  35. package/build/list/index.js.map +1 -1
  36. package/build/more/edit.native.js +17 -32
  37. package/build/more/edit.native.js.map +1 -1
  38. package/build/navigation-link/edit.js +28 -1
  39. package/build/navigation-link/edit.js.map +1 -1
  40. package/build/post-author/edit.js +152 -52
  41. package/build/post-author/edit.js.map +1 -1
  42. package/build/post-comments-form/form.js +1 -1
  43. package/build/post-comments-form/form.js.map +1 -1
  44. package/build/post-featured-image/edit.js +2 -1
  45. package/build/post-featured-image/edit.js.map +1 -1
  46. package/build/post-navigation-link/edit.js +72 -33
  47. package/build/post-navigation-link/edit.js.map +1 -1
  48. package/build/search/edit.js +1 -1
  49. package/build/search/edit.js.map +1 -1
  50. package/build/site-logo/edit.js +69 -24
  51. package/build/site-logo/edit.js.map +1 -1
  52. package/build/social-link/edit.js +21 -5
  53. package/build/social-link/edit.js.map +1 -1
  54. package/build/social-link/edit.native.js +13 -5
  55. package/build/social-link/edit.native.js.map +1 -1
  56. package/build/social-link/social-list.js +17 -25
  57. package/build/social-link/social-list.js.map +1 -1
  58. package/build/social-links/edit.js +8 -5
  59. package/build/social-links/edit.js.map +1 -1
  60. package/build/video/tracks-editor.js +23 -9
  61. package/build/video/tracks-editor.js.map +1 -1
  62. package/build-module/avatar/edit.js +83 -38
  63. package/build-module/avatar/edit.js.map +1 -1
  64. package/build-module/avatar/user-control.js +33 -18
  65. package/build-module/avatar/user-control.js.map +1 -1
  66. package/build-module/button/edit.js +1 -1
  67. package/build-module/button/edit.js.map +1 -1
  68. package/build-module/cover/edit/inspector-controls.js +2 -2
  69. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  70. package/build-module/details/index.js +1 -1
  71. package/build-module/details/index.js.map +1 -1
  72. package/build-module/embed/variations.js +0 -10
  73. package/build-module/embed/variations.js.map +1 -1
  74. package/build-module/form/edit.js +0 -1
  75. package/build-module/form/edit.js.map +1 -1
  76. package/build-module/form/index.js +3 -3
  77. package/build-module/form/index.js.map +1 -1
  78. package/build-module/form-input/index.js +2 -1
  79. package/build-module/form-input/index.js.map +1 -1
  80. package/build-module/form-submission-notification/index.js +2 -1
  81. package/build-module/form-submission-notification/index.js.map +1 -1
  82. package/build-module/form-submit-button/index.js +2 -1
  83. package/build-module/form-submit-button/index.js.map +1 -1
  84. package/build-module/gallery/constants.js +1 -0
  85. package/build-module/gallery/constants.js.map +1 -1
  86. package/build-module/gallery/edit.js +95 -17
  87. package/build-module/gallery/edit.js.map +1 -1
  88. package/build-module/image/edit.js +6 -0
  89. package/build-module/image/edit.js.map +1 -1
  90. package/build-module/image/image.js +1 -0
  91. package/build-module/image/image.js.map +1 -1
  92. package/build-module/image/view.js +0 -3
  93. package/build-module/image/view.js.map +1 -1
  94. package/build-module/list/index.js +0 -1
  95. package/build-module/list/index.js.map +1 -1
  96. package/build-module/more/edit.native.js +16 -30
  97. package/build-module/more/edit.native.js.map +1 -1
  98. package/build-module/navigation-link/edit.js +29 -2
  99. package/build-module/navigation-link/edit.js.map +1 -1
  100. package/build-module/post-author/edit.js +153 -53
  101. package/build-module/post-author/edit.js.map +1 -1
  102. package/build-module/post-comments-form/form.js +1 -1
  103. package/build-module/post-comments-form/form.js.map +1 -1
  104. package/build-module/post-featured-image/edit.js +2 -1
  105. package/build-module/post-featured-image/edit.js.map +1 -1
  106. package/build-module/post-navigation-link/edit.js +73 -34
  107. package/build-module/post-navigation-link/edit.js.map +1 -1
  108. package/build-module/search/edit.js +1 -1
  109. package/build-module/search/edit.js.map +1 -1
  110. package/build-module/site-logo/edit.js +70 -25
  111. package/build-module/site-logo/edit.js.map +1 -1
  112. package/build-module/social-link/edit.js +24 -8
  113. package/build-module/social-link/edit.js.map +1 -1
  114. package/build-module/social-link/edit.native.js +15 -6
  115. package/build-module/social-link/edit.native.js.map +1 -1
  116. package/build-module/social-link/social-list.js +16 -21
  117. package/build-module/social-link/social-list.js.map +1 -1
  118. package/build-module/social-links/edit.js +8 -5
  119. package/build-module/social-links/edit.js.map +1 -1
  120. package/build-module/video/tracks-editor.js +24 -10
  121. package/build-module/video/tracks-editor.js.map +1 -1
  122. package/build-style/calendar/style-rtl.css +7 -7
  123. package/build-style/calendar/style.css +7 -7
  124. package/build-style/comments-pagination/editor-rtl.css +0 -12
  125. package/build-style/comments-pagination/editor.css +0 -14
  126. package/build-style/comments-pagination/style-rtl.css +0 -7
  127. package/build-style/comments-pagination/style.css +0 -9
  128. package/build-style/editor-rtl.css +0 -30
  129. package/build-style/editor.css +0 -32
  130. package/build-style/gallery/editor-rtl.css +0 -13
  131. package/build-style/gallery/editor.css +0 -13
  132. package/build-style/navigation/style-rtl.css +5 -0
  133. package/build-style/navigation/style.css +5 -0
  134. package/build-style/style-rtl.css +12 -14
  135. package/build-style/style.css +12 -16
  136. package/package.json +35 -35
  137. package/src/avatar/edit.js +99 -51
  138. package/src/avatar/user-control.js +34 -29
  139. package/src/button/edit.js +1 -1
  140. package/src/calendar/style.scss +10 -10
  141. package/src/comments-pagination/editor.scss +0 -15
  142. package/src/comments-pagination/style.scss +0 -8
  143. package/src/cover/edit/inspector-controls.js +1 -1
  144. package/src/details/index.js +1 -1
  145. package/src/editor.scss +0 -1
  146. package/src/embed/variations.js +0 -8
  147. package/src/form/block.json +1 -2
  148. package/src/form/edit.js +0 -1
  149. package/src/form/index.js +1 -0
  150. package/src/form-input/index.js +1 -0
  151. package/src/form-submission-notification/index.js +1 -0
  152. package/src/form-submit-button/index.js +1 -0
  153. package/src/gallery/constants.js +1 -0
  154. package/src/gallery/edit.js +182 -68
  155. package/src/gallery/editor.scss +0 -17
  156. package/src/image/edit.js +12 -0
  157. package/src/image/image.js +1 -0
  158. package/src/image/index.php +4 -1
  159. package/src/image/view.js +0 -3
  160. package/src/list/block.json +0 -1
  161. package/src/more/edit.native.js +19 -33
  162. package/src/navigation/style.scss +9 -0
  163. package/src/navigation-link/edit.js +32 -2
  164. package/src/post-author/edit.js +178 -63
  165. package/src/post-comments-form/form.js +1 -1
  166. package/src/post-featured-image/edit.js +1 -0
  167. package/src/post-navigation-link/edit.js +96 -51
  168. package/src/rss/index.php +2 -1
  169. package/src/search/edit.js +1 -1
  170. package/src/site-logo/edit.js +90 -35
  171. package/src/social-link/edit.js +18 -7
  172. package/src/social-link/edit.native.js +10 -4
  173. package/src/social-link/index.php +13 -0
  174. package/src/social-link/social-list.js +15 -20
  175. package/src/social-links/edit.js +6 -7
  176. package/src/video/tracks-editor.js +18 -6
  177. package/build-style/post-author/editor-rtl.css +0 -140
  178. package/build-style/post-author/editor.css +0 -140
  179. package/src/post-author/editor.scss +0 -7
@@ -14,7 +14,6 @@ import {
14
14
  } from '@wordpress/element';
15
15
  import { __, isRTL } from '@wordpress/i18n';
16
16
  import {
17
- PanelBody,
18
17
  RangeControl,
19
18
  ResizableBox,
20
19
  Spinner,
@@ -24,6 +23,8 @@ import {
24
23
  Button,
25
24
  DropZone,
26
25
  FlexItem,
26
+ __experimentalToolsPanel as ToolsPanel,
27
+ __experimentalToolsPanelItem as ToolsPanelItem,
27
28
  __experimentalItemGroup as ItemGroup,
28
29
  __experimentalHStack as HStack,
29
30
  __experimentalTruncate as Truncate,
@@ -47,6 +48,7 @@ import { store as noticesStore } from '@wordpress/notices';
47
48
  * Internal dependencies
48
49
  */
49
50
  import { MIN_SIZE } from '../image/constants';
51
+ import { useToolsPanelDropdownMenuProps } from '../utils/hooks';
50
52
 
51
53
  const ALLOWED_MEDIA_TYPES = [ 'image' ];
52
54
  const ACCEPT_MEDIA_STRING = 'image/*';
@@ -70,6 +72,7 @@ const SiteLogo = ( {
70
72
  const [ { naturalWidth, naturalHeight }, setNaturalSize ] = useState( {} );
71
73
  const [ isEditingImage, setIsEditingImage ] = useState( false );
72
74
  const { toggleSelection } = useDispatch( blockEditorStore );
75
+ const dropdownMenuProps = useToolsPanelDropdownMenuProps();
73
76
  const { imageEditing, maxWidth, title } = useSelect( ( select ) => {
74
77
  const settings = select( blockEditorStore ).getSettings();
75
78
  const siteEntities = select( coreStore ).getEntityRecord(
@@ -276,31 +279,61 @@ const SiteLogo = ( {
276
279
  return (
277
280
  <>
278
281
  <InspectorControls>
279
- <PanelBody title={ __( 'Settings' ) }>
280
- <RangeControl
281
- __nextHasNoMarginBottom
282
- __next40pxDefaultSize
282
+ <ToolsPanel
283
+ label={ __( 'Settings' ) }
284
+ dropdownMenuProps={ dropdownMenuProps }
285
+ >
286
+ <ToolsPanelItem
287
+ isShownByDefault
288
+ hasValue={ () => !! width }
283
289
  label={ __( 'Image width' ) }
284
- onChange={ ( newWidth ) =>
285
- setAttributes( { width: newWidth } )
290
+ onDeselect={ () =>
291
+ setAttributes( { width: undefined } )
286
292
  }
287
- min={ minWidth }
288
- max={ maxWidthBuffer }
289
- initialPosition={ Math.min(
290
- defaultWidth,
291
- maxWidthBuffer
292
- ) }
293
- value={ width || '' }
294
- disabled={ ! isResizable }
295
- />
296
- <ToggleControl
297
- __nextHasNoMarginBottom
293
+ >
294
+ <RangeControl
295
+ __nextHasNoMarginBottom
296
+ __next40pxDefaultSize
297
+ label={ __( 'Image width' ) }
298
+ onChange={ ( newWidth ) =>
299
+ setAttributes( { width: newWidth } )
300
+ }
301
+ min={ minWidth }
302
+ max={ maxWidthBuffer }
303
+ initialPosition={ Math.min(
304
+ defaultWidth,
305
+ maxWidthBuffer
306
+ ) }
307
+ value={ width || '' }
308
+ disabled={ ! isResizable }
309
+ />
310
+ </ToolsPanelItem>
311
+
312
+ <ToolsPanelItem
313
+ isShownByDefault
314
+ hasValue={ () => ! isLink }
298
315
  label={ __( 'Link image to home' ) }
299
- onChange={ () => setAttributes( { isLink: ! isLink } ) }
300
- checked={ isLink }
301
- />
316
+ onDeselect={ () => setAttributes( { isLink: true } ) }
317
+ >
318
+ <ToggleControl
319
+ __nextHasNoMarginBottom
320
+ label={ __( 'Link image to home' ) }
321
+ onChange={ () =>
322
+ setAttributes( { isLink: ! isLink } )
323
+ }
324
+ checked={ isLink }
325
+ />
326
+ </ToolsPanelItem>
327
+
302
328
  { isLink && (
303
- <>
329
+ <ToolsPanelItem
330
+ isShownByDefault
331
+ hasValue={ () => linkTarget === '_blank' }
332
+ label={ __( 'Open in new tab' ) }
333
+ onDeselect={ () =>
334
+ setAttributes( { linkTarget: '_self' } )
335
+ }
336
+ >
304
337
  <ToggleControl
305
338
  __nextHasNoMarginBottom
306
339
  label={ __( 'Open in new tab' ) }
@@ -311,10 +344,19 @@ const SiteLogo = ( {
311
344
  }
312
345
  checked={ linkTarget === '_blank' }
313
346
  />
314
- </>
347
+ </ToolsPanelItem>
315
348
  ) }
349
+
316
350
  { canUserEdit && (
317
- <>
351
+ <ToolsPanelItem
352
+ isShownByDefault
353
+ hasValue={ () => !! shouldSyncIcon }
354
+ label={ __( 'Use as Site Icon' ) }
355
+ onDeselect={ () => {
356
+ setAttributes( { shouldSyncIcon: false } );
357
+ setIcon( undefined );
358
+ } }
359
+ >
318
360
  <ToggleControl
319
361
  __nextHasNoMarginBottom
320
362
  label={ __( 'Use as Site Icon' ) }
@@ -325,9 +367,9 @@ const SiteLogo = ( {
325
367
  checked={ !! shouldSyncIcon }
326
368
  help={ syncSiteIconHelpText }
327
369
  />
328
- </>
370
+ </ToolsPanelItem>
329
371
  ) }
330
- </PanelBody>
372
+ </ToolsPanel>
331
373
  </InspectorControls>
332
374
  <BlockControls group="block">
333
375
  { canEditImage && ! isEditingImage && (
@@ -433,6 +475,7 @@ export default function LogoEdit( {
433
475
  }, [] );
434
476
  const { getSettings } = useSelect( blockEditorStore );
435
477
  const [ temporaryURL, setTemporaryURL ] = useState();
478
+ const dropdownMenuProps = useToolsPanelDropdownMenuProps();
436
479
 
437
480
  const { editEntityRecord } = useDispatch( coreStore );
438
481
 
@@ -590,9 +633,15 @@ export default function LogoEdit( {
590
633
 
591
634
  const mediaInspectorPanel = ( canUserEdit || logoUrl ) && (
592
635
  <InspectorControls>
593
- <PanelBody title={ __( 'Media' ) }>
594
- <div className="block-library-site-logo__inspector-media-replace-container">
595
- { ! canUserEdit ? (
636
+ <ToolsPanel
637
+ label={ __( 'Media' ) }
638
+ dropdownMenuProps={ dropdownMenuProps }
639
+ >
640
+ { ! canUserEdit ? (
641
+ <div
642
+ className="block-library-site-logo__inspector-media-replace-container"
643
+ style={ { gridColumn: '1 / -1' } }
644
+ >
596
645
  <InspectorLogoPreview
597
646
  media={ mediaItemData }
598
647
  itemGroupProps={ {
@@ -601,8 +650,14 @@ export default function LogoEdit( {
601
650
  'block-library-site-logo__inspector-readonly-logo-preview',
602
651
  } }
603
652
  />
604
- ) : (
605
- <>
653
+ </div>
654
+ ) : (
655
+ <ToolsPanelItem
656
+ hasValue={ () => !! logoUrl }
657
+ label={ __( 'Logo' ) }
658
+ isShownByDefault
659
+ >
660
+ <div className="block-library-site-logo__inspector-media-replace-container">
606
661
  <SiteLogoReplaceFlow
607
662
  { ...mediaReplaceFlowProps }
608
663
  name={
@@ -625,10 +680,10 @@ export default function LogoEdit( {
625
680
  ) }
626
681
  />
627
682
  <DropZone onFilesDrop={ onFilesDrop } />
628
- </>
629
- ) }
630
- </div>
631
- </PanelBody>
683
+ </div>
684
+ </ToolsPanelItem>
685
+ ) }
686
+ </ToolsPanel>
632
687
  </InspectorControls>
633
688
  );
634
689
 
@@ -7,8 +7,7 @@ import clsx from 'clsx';
7
7
  * WordPress dependencies
8
8
  */
9
9
  import { DELETE, BACKSPACE, ENTER } from '@wordpress/keycodes';
10
- import { useDispatch } from '@wordpress/data';
11
-
10
+ import { useDispatch, useSelect } from '@wordpress/data';
12
11
  import {
13
12
  BlockControls,
14
13
  InspectorControls,
@@ -20,6 +19,7 @@ import {
20
19
  } from '@wordpress/block-editor';
21
20
  import { useState, useRef } from '@wordpress/element';
22
21
  import {
22
+ Icon,
23
23
  Button,
24
24
  Dropdown,
25
25
  TextControl,
@@ -31,11 +31,12 @@ import {
31
31
  import { useMergeRefs } from '@wordpress/compose';
32
32
  import { __ } from '@wordpress/i18n';
33
33
  import { keyboardReturn } from '@wordpress/icons';
34
+ import { store as blocksStore } from '@wordpress/blocks';
34
35
 
35
36
  /**
36
37
  * Internal dependencies
37
38
  */
38
- import { getIconBySite, getNameBySite } from './social-list';
39
+ import { getSocialService } from './social-list';
39
40
  import { useToolsPanelDropdownMenuProps } from '../utils/hooks';
40
41
 
41
42
  const SocialLinkURLPopover = ( {
@@ -108,6 +109,7 @@ const SocialLinkEdit = ( {
108
109
  isSelected,
109
110
  setAttributes,
110
111
  clientId,
112
+ name,
111
113
  } ) => {
112
114
  const { url, service, label = '', rel } = attributes;
113
115
  const dropdownMenuProps = useToolsPanelDropdownMenuProps();
@@ -138,8 +140,17 @@ const SocialLinkEdit = ( {
138
140
  const [ popoverAnchor, setPopoverAnchor ] = useState( null );
139
141
  const isContentOnlyMode = useBlockEditingMode() === 'contentOnly';
140
142
 
141
- const IconComponent = getIconBySite( service );
142
- const socialLinkName = getNameBySite( service );
143
+ const { activeVariation } = useSelect(
144
+ ( select ) => {
145
+ const { getActiveBlockVariation } = select( blocksStore );
146
+ return {
147
+ activeVariation: getActiveBlockVariation( name, attributes ),
148
+ };
149
+ },
150
+ [ name, attributes ]
151
+ );
152
+
153
+ const { icon, label: socialLinkName } = getSocialService( activeVariation );
143
154
  // The initial label (ie. the link text) is an empty string.
144
155
  // We want to prevent empty links so that the link text always fallbacks to
145
156
  // the social name, even when users enter and save an empty string or only
@@ -167,7 +178,7 @@ const SocialLinkEdit = ( {
167
178
  // to edit this attribute.
168
179
  <BlockControls group="other">
169
180
  <Dropdown
170
- popoverProps={ { position: 'bottom right' } }
181
+ popoverProps={ { placement: 'bottom-start' } }
171
182
  renderToggle={ ( { isOpen, onToggle } ) => (
172
183
  <ToolbarButton
173
184
  onClick={ onToggle }
@@ -258,7 +269,7 @@ const SocialLinkEdit = ( {
258
269
  */
259
270
  /* eslint-disable jsx-a11y/no-redundant-roles */ }
260
271
  <button aria-haspopup="dialog" { ...blockProps } role="button">
261
- <IconComponent />
272
+ <Icon icon={ icon } />
262
273
  <span
263
274
  className={ clsx( 'wp-block-social-link-label', {
264
275
  'screen-reader-text': ! showLabels,
@@ -20,10 +20,12 @@ import { compose } from '@wordpress/compose';
20
20
  import { __, sprintf } from '@wordpress/i18n';
21
21
  import { link, Icon } from '@wordpress/icons';
22
22
  import { withSelect } from '@wordpress/data';
23
+ import { store as blocksStore } from '@wordpress/blocks';
24
+
23
25
  /**
24
26
  * Internal dependencies
25
27
  */
26
- import { getIconBySite, getNameBySite } from './social-list';
28
+ import { getSocialService } from './social-list';
27
29
  import styles from './editor.scss';
28
30
 
29
31
  const DEFAULT_ACTIVE_ICON_STYLES = {
@@ -54,6 +56,7 @@ const SocialLinkEdit = ( {
54
56
  isSelected,
55
57
  onFocus,
56
58
  name,
59
+ activeVariation,
57
60
  } ) => {
58
61
  const { url, service = name } = attributes;
59
62
  const [ isLinkSheetVisible, setIsLinkSheetVisible ] = useState( false );
@@ -64,8 +67,7 @@ const SocialLinkEdit = ( {
64
67
  DEFAULT_ACTIVE_ICON_STYLES;
65
68
  const animatedValue = useRef( new Animated.Value( 0 ) ).current;
66
69
 
67
- const IconComponent = getIconBySite( service )();
68
- const socialLinkName = getNameBySite( service );
70
+ const { icon, label: socialLinkName } = getSocialService( activeVariation );
69
71
 
70
72
  // When new social icon is added link sheet is opened automatically.
71
73
  useEffect( () => {
@@ -190,7 +192,7 @@ const SocialLinkEdit = ( {
190
192
  >
191
193
  <Icon
192
194
  animated
193
- icon={ IconComponent }
195
+ icon={ icon() }
194
196
  style={ { color: activeIcon.color } }
195
197
  />
196
198
  </Animated.View>
@@ -202,12 +204,16 @@ const SocialLinkEdit = ( {
202
204
  export default compose( [
203
205
  withSelect( ( select, { clientId } ) => {
204
206
  const { getBlock } = select( blockEditorStore );
207
+ const { getActiveBlockVariation } = select( blocksStore );
205
208
 
206
209
  const block = getBlock( clientId );
207
210
  const name = block?.name.substring( 17 );
208
211
 
209
212
  return {
210
213
  name,
214
+ activeVariation: block
215
+ ? getActiveBlockVariation( block.name, block.attributes )
216
+ : undefined,
211
217
  };
212
218
  } ),
213
219
  ] )( SocialLinkEdit );
@@ -335,6 +335,19 @@ function block_core_social_link_services( $service = '', $field = '' ) {
335
335
  ),
336
336
  );
337
337
 
338
+ /**
339
+ * Filter the list of available social service.
340
+ *
341
+ * This can be used to change icons or add custom icons (additionally to variations in the editor).
342
+ * Icons should be directly renderable - therefore SVGs work best.
343
+ *
344
+ * @since 6.9.0
345
+ *
346
+ * @param array $services_data The list of services. Each item is an array containing a 'name' and 'icon' key.
347
+ * @return array The list of social services.
348
+ */
349
+ $services_data = apply_filters( 'block_core_social_link_get_services', $services_data );
350
+
338
351
  if ( ! empty( $service )
339
352
  && ! empty( $field )
340
353
  && isset( $services_data[ $service ] )
@@ -6,29 +6,24 @@ import { __ } from '@wordpress/i18n';
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
- import variations from './variations';
10
9
  import { ChainIcon } from './icons';
11
10
 
12
11
  /**
13
- * Retrieves the social service's icon component.
12
+ * Retrieves the social service's icon component and label.
14
13
  *
15
- * @param {string} name key for a social service (lowercase slug)
16
- *
17
- * @return {Component} Icon component for social service.
14
+ * @param {Object} variation The object of the social service variation.
15
+ * @return {Object} An object containing the Icon component for social service and label.
18
16
  */
19
- export const getIconBySite = ( name ) => {
20
- const variation = variations.find( ( v ) => v.name === name );
21
- return variation ? variation.icon : ChainIcon;
22
- };
17
+ export function getSocialService( variation ) {
18
+ if ( ! variation?.name ) {
19
+ return {
20
+ icon: ChainIcon,
21
+ label: __( 'Social Icon' ),
22
+ };
23
+ }
23
24
 
24
- /**
25
- * Retrieves the display name for the social service.
26
- *
27
- * @param {string} name key for a social service (lowercase slug)
28
- *
29
- * @return {string} Display name for social service
30
- */
31
- export const getNameBySite = ( name ) => {
32
- const variation = variations.find( ( v ) => v.name === name );
33
- return variation ? variation.title : __( 'Social Icon' );
34
- };
25
+ return {
26
+ icon: variation?.icon ?? ChainIcon,
27
+ label: variation?.title ?? __( 'Social Icon' ),
28
+ };
29
+ }
@@ -33,6 +33,7 @@ import { useSelect } from '@wordpress/data';
33
33
  import { useToolsPanelDropdownMenuProps } from '../utils/hooks';
34
34
 
35
35
  const sizeOptions = [
36
+ { label: __( 'Default' ), value: '' },
36
37
  { label: __( 'Small' ), value: 'has-small-icon-size' },
37
38
  { label: __( 'Normal' ), value: 'has-normal-icon-size' },
38
39
  { label: __( 'Large' ), value: 'has-large-icon-size' },
@@ -166,19 +167,17 @@ export function SocialLinksEdit( props ) {
166
167
  setAttributes( {
167
168
  openInNewTab: false,
168
169
  showLabels: false,
169
- size: 'has-normal-icon-size',
170
+ size: undefined,
170
171
  } );
171
172
  } }
172
173
  dropdownMenuProps={ dropdownMenuProps }
173
174
  >
174
175
  <ToolsPanelItem
175
176
  isShownByDefault
176
- hasValue={ () =>
177
- !! size && size !== 'has-normal-icon-size'
178
- }
177
+ hasValue={ () => !! size }
179
178
  label={ __( 'Icon size' ) }
180
179
  onDeselect={ () =>
181
- setAttributes( { size: 'has-normal-icon-size' } )
180
+ setAttributes( { size: undefined } )
182
181
  }
183
182
  >
184
183
  <SelectControl
@@ -187,10 +186,10 @@ export function SocialLinksEdit( props ) {
187
186
  label={ __( 'Icon Size' ) }
188
187
  onChange={ ( newSize ) => {
189
188
  setAttributes( {
190
- size: newSize,
189
+ size: newSize === '' ? undefined : newSize,
191
190
  } );
192
191
  } }
193
- value={ size ?? 'has-normal-icon-size' }
192
+ value={ size ?? '' }
194
193
  options={ sizeOptions }
195
194
  />
196
195
  </ToolsPanelItem>
@@ -24,8 +24,9 @@ import {
24
24
  MediaUploadCheck,
25
25
  store as blockEditorStore,
26
26
  } from '@wordpress/block-editor';
27
+ import { store as noticesStore } from '@wordpress/notices';
27
28
  import { upload, media } from '@wordpress/icons';
28
- import { useSelect } from '@wordpress/data';
29
+ import { useSelect, useDispatch } from '@wordpress/data';
29
30
  import { useState, useRef, useEffect } from '@wordpress/element';
30
31
  import { getFilename } from '@wordpress/url';
31
32
 
@@ -212,12 +213,27 @@ function SingleTrackEditor( {
212
213
  }
213
214
 
214
215
  export default function TracksEditor( { tracks = [], onChange } ) {
216
+ const { createNotice } = useDispatch( noticesStore );
215
217
  const mediaUpload = useSelect( ( select ) => {
216
218
  return select( blockEditorStore ).getSettings().mediaUpload;
217
219
  }, [] );
218
220
  const [ trackBeingEdited, setTrackBeingEdited ] = useState( null );
219
221
  const dropdownPopoverRef = useRef();
220
222
 
223
+ const handleTrackSelect = ( { title, url } ) => {
224
+ if ( tracks.some( ( track ) => track.src === url ) ) {
225
+ createNotice( 'error', __( 'This track already exists.' ), {
226
+ isDismissible: true,
227
+ type: 'snackbar',
228
+ } );
229
+ return;
230
+ }
231
+
232
+ const trackIndex = tracks.length;
233
+ onChange( [ ...tracks, { label: title || '', src: url } ] );
234
+ setTrackBeingEdited( trackIndex );
235
+ };
236
+
221
237
  useEffect( () => {
222
238
  dropdownPopoverRef.current?.focus();
223
239
  }, [ trackBeingEdited ] );
@@ -306,11 +322,7 @@ export default function TracksEditor( { tracks = [], onChange } ) {
306
322
  label={ __( 'Add tracks' ) }
307
323
  >
308
324
  <MediaUpload
309
- onSelect={ ( { url } ) => {
310
- const trackIndex = tracks.length;
311
- onChange( [ ...tracks, { src: url } ] );
312
- setTrackBeingEdited( trackIndex );
313
- } }
325
+ onSelect={ handleTrackSelect }
314
326
  allowedTypes={ ALLOWED_TYPES }
315
327
  render={ ( { open } ) => (
316
328
  <MenuItem
@@ -1,140 +0,0 @@
1
- /**
2
- * Colors
3
- */
4
- /**
5
- * Breakpoints & Media Queries
6
- */
7
- /**
8
- * Colors
9
- */
10
- /**
11
- * SCSS Variables.
12
- *
13
- * Please use variables from this sheet to ensure consistency across the UI.
14
- * Don't add to this sheet unless you're pretty sure the value will be reused in many places.
15
- * For example, don't add rules to this sheet that affect block visuals. It's purely for UI.
16
- */
17
- /**
18
- * Fonts & basic variables.
19
- */
20
- /**
21
- * Typography
22
- */
23
- /**
24
- * Grid System.
25
- * https://make.wordpress.org/design/2019/10/31/proposal-a-consistent-spacing-system-for-wordpress/
26
- */
27
- /**
28
- * Radius scale.
29
- */
30
- /**
31
- * Elevation scale.
32
- */
33
- /**
34
- * Dimensions.
35
- */
36
- /**
37
- * Mobile specific styles
38
- */
39
- /**
40
- * Editor styles.
41
- */
42
- /**
43
- * Block & Editor UI.
44
- */
45
- /**
46
- * Block paddings.
47
- */
48
- /**
49
- * React Native specific.
50
- * These variables do not appear to be used anywhere else.
51
- */
52
- /**
53
- * Colors
54
- */
55
- /**
56
- * SCSS Variables.
57
- *
58
- * Please use variables from this sheet to ensure consistency across the UI.
59
- * Don't add to this sheet unless you're pretty sure the value will be reused in many places.
60
- * For example, don't add rules to this sheet that affect block visuals. It's purely for UI.
61
- */
62
- /**
63
- * Fonts & basic variables.
64
- */
65
- /**
66
- * Typography
67
- */
68
- /**
69
- * Grid System.
70
- * https://make.wordpress.org/design/2019/10/31/proposal-a-consistent-spacing-system-for-wordpress/
71
- */
72
- /**
73
- * Radius scale.
74
- */
75
- /**
76
- * Elevation scale.
77
- */
78
- /**
79
- * Dimensions.
80
- */
81
- /**
82
- * Mobile specific styles
83
- */
84
- /**
85
- * Editor styles.
86
- */
87
- /**
88
- * Block & Editor UI.
89
- */
90
- /**
91
- * Block paddings.
92
- */
93
- /**
94
- * React Native specific.
95
- * These variables do not appear to be used anywhere else.
96
- */
97
- /**
98
- * Breakpoints & Media Queries
99
- */
100
- /**
101
- * Converts a hex value into the rgb equivalent.
102
- *
103
- * @param {string} hex - the hexadecimal value to convert
104
- * @return {string} comma separated rgb values
105
- */
106
- /**
107
- * Long content fade mixin
108
- *
109
- * Creates a fading overlay to signify that the content is longer
110
- * than the space allows.
111
- */
112
- /**
113
- * Typography
114
- */
115
- /**
116
- * Breakpoint mixins
117
- */
118
- /**
119
- * Focus styles.
120
- */
121
- /**
122
- * Applies editor left position to the selector passed as argument
123
- */
124
- /**
125
- * Styles that are reused verbatim in a few places
126
- */
127
- /**
128
- * Allows users to opt-out of animations via OS-level preferences.
129
- */
130
- /**
131
- * Reset default styles for JavaScript UI based pages.
132
- * This is a WP-admin agnostic reset
133
- */
134
- /**
135
- * Reset the WP Admin page styles for Gutenberg-like pages.
136
- */
137
- .wp-block-post-author__inspector-settings .components-base-control,
138
- .wp-block-post-author__inspector-settings .components-base-control:last-child {
139
- margin-bottom: 0;
140
- }