@automattic/newspack-blocks 4.24.1 → 4.25.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 (102) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/author-profile/view-rtl.css +1 -1
  3. package/dist/author-profile/view.asset.php +1 -1
  4. package/dist/author-profile/view.css +1 -1
  5. package/dist/blocks/author-list/block.json +2 -1
  6. package/dist/blocks/author-profile/block.json +18 -1
  7. package/dist/blocks/carousel/block.json +2 -1
  8. package/dist/blocks/donate/block.json +2 -1
  9. package/dist/blocks/homepage-articles/block.json +2 -1
  10. package/dist/blocks/iframe/block.json +2 -1
  11. package/dist/editor-rtl.css +2 -2
  12. package/dist/editor.asset.php +1 -1
  13. package/dist/editor.css +2 -2
  14. package/dist/editor.js +23 -19
  15. package/dist/placeholder_blocks.asset.php +1 -1
  16. package/dist/placeholder_blocks.js +1 -1
  17. package/includes/class-modal-checkout.php +43 -11
  18. package/includes/class-newspack-blocks-caching.php +13 -1
  19. package/includes/class-newspack-blocks.php +14 -7
  20. package/languages/newspack-blocks-de_DE-2d52b39fdbc5d6c94b3514803f3720b8.json +1 -1
  21. package/languages/newspack-blocks-de_DE-34e5c64f90b1444f3fc735376442eada.json +1 -1
  22. package/languages/newspack-blocks-de_DE-4fdea541976076f02d56139fb35e5b42.json +1 -1
  23. package/languages/newspack-blocks-de_DE-53e2a1d5945b8d2b1c35e81ae1e532f3.json +1 -1
  24. package/languages/newspack-blocks-de_DE-78456b164809d080adecb4d2b3895802.json +1 -1
  25. package/languages/newspack-blocks-de_DE-9ef9b2c60c897ad79f92951e6e9949a1.json +1 -1
  26. package/languages/newspack-blocks-de_DE-eccbc51a43c04f59165364eda71e0be7.json +1 -1
  27. package/languages/newspack-blocks-de_DE-fbe7f8c598cf05d4603ba49fec909ded.json +1 -1
  28. package/languages/newspack-blocks-de_DE.po +594 -493
  29. package/languages/newspack-blocks-es_ES-2d52b39fdbc5d6c94b3514803f3720b8.json +1 -1
  30. package/languages/newspack-blocks-es_ES-34e5c64f90b1444f3fc735376442eada.json +1 -1
  31. package/languages/newspack-blocks-es_ES-4fdea541976076f02d56139fb35e5b42.json +1 -1
  32. package/languages/newspack-blocks-es_ES-53e2a1d5945b8d2b1c35e81ae1e532f3.json +1 -1
  33. package/languages/newspack-blocks-es_ES-78456b164809d080adecb4d2b3895802.json +1 -1
  34. package/languages/newspack-blocks-es_ES-9ef9b2c60c897ad79f92951e6e9949a1.json +1 -1
  35. package/languages/newspack-blocks-es_ES-eccbc51a43c04f59165364eda71e0be7.json +1 -1
  36. package/languages/newspack-blocks-es_ES-fbe7f8c598cf05d4603ba49fec909ded.json +1 -1
  37. package/languages/newspack-blocks-es_ES.po +594 -493
  38. package/languages/newspack-blocks-fr_BE-2d52b39fdbc5d6c94b3514803f3720b8.json +1 -1
  39. package/languages/newspack-blocks-fr_BE-34e5c64f90b1444f3fc735376442eada.json +1 -1
  40. package/languages/newspack-blocks-fr_BE-4fdea541976076f02d56139fb35e5b42.json +1 -1
  41. package/languages/newspack-blocks-fr_BE-53e2a1d5945b8d2b1c35e81ae1e532f3.json +1 -1
  42. package/languages/newspack-blocks-fr_BE-78456b164809d080adecb4d2b3895802.json +1 -1
  43. package/languages/newspack-blocks-fr_BE-9ef9b2c60c897ad79f92951e6e9949a1.json +1 -1
  44. package/languages/newspack-blocks-fr_BE-eccbc51a43c04f59165364eda71e0be7.json +1 -1
  45. package/languages/newspack-blocks-fr_BE-fbe7f8c598cf05d4603ba49fec909ded.json +1 -1
  46. package/languages/newspack-blocks-fr_BE.po +594 -493
  47. package/languages/newspack-blocks-nb_NO-2d52b39fdbc5d6c94b3514803f3720b8.json +1 -1
  48. package/languages/newspack-blocks-nb_NO-34e5c64f90b1444f3fc735376442eada.json +1 -1
  49. package/languages/newspack-blocks-nb_NO-4fdea541976076f02d56139fb35e5b42.json +1 -1
  50. package/languages/newspack-blocks-nb_NO-53e2a1d5945b8d2b1c35e81ae1e532f3.json +1 -1
  51. package/languages/newspack-blocks-nb_NO-78456b164809d080adecb4d2b3895802.json +1 -1
  52. package/languages/newspack-blocks-nb_NO-9ef9b2c60c897ad79f92951e6e9949a1.json +1 -1
  53. package/languages/newspack-blocks-nb_NO-eccbc51a43c04f59165364eda71e0be7.json +1 -1
  54. package/languages/newspack-blocks-nb_NO-fbe7f8c598cf05d4603ba49fec909ded.json +1 -1
  55. package/languages/newspack-blocks-nb_NO.po +594 -493
  56. package/languages/newspack-blocks-pt_PT-2d52b39fdbc5d6c94b3514803f3720b8.json +1 -1
  57. package/languages/newspack-blocks-pt_PT-34e5c64f90b1444f3fc735376442eada.json +1 -1
  58. package/languages/newspack-blocks-pt_PT-4fdea541976076f02d56139fb35e5b42.json +1 -1
  59. package/languages/newspack-blocks-pt_PT-53e2a1d5945b8d2b1c35e81ae1e532f3.json +1 -1
  60. package/languages/newspack-blocks-pt_PT-78456b164809d080adecb4d2b3895802.json +1 -1
  61. package/languages/newspack-blocks-pt_PT-9ef9b2c60c897ad79f92951e6e9949a1.json +1 -1
  62. package/languages/newspack-blocks-pt_PT-eccbc51a43c04f59165364eda71e0be7.json +1 -1
  63. package/languages/newspack-blocks-pt_PT-fbe7f8c598cf05d4603ba49fec909ded.json +1 -1
  64. package/languages/newspack-blocks-pt_PT.po +594 -493
  65. package/languages/newspack-blocks.pot +806 -671
  66. package/newspack-blocks.php +5 -5
  67. package/package.json +1 -1
  68. package/src/blocks/author-list/block.json +3 -2
  69. package/src/blocks/author-list/edit.js +15 -8
  70. package/src/blocks/author-list/index.js +4 -3
  71. package/src/blocks/author-list/view.php +1 -0
  72. package/src/blocks/author-profile/block.json +16 -2
  73. package/src/blocks/author-profile/class-wp-rest-newspack-authors-controller.php +180 -9
  74. package/src/blocks/author-profile/context.js +26 -0
  75. package/src/blocks/author-profile/edit.js +847 -84
  76. package/src/blocks/author-profile/editor.scss +18 -14
  77. package/src/blocks/author-profile/index.js +14 -9
  78. package/src/blocks/author-profile/single-author.js +6 -2
  79. package/src/blocks/author-profile/view.php +386 -15
  80. package/src/blocks/author-profile/view.scss +48 -19
  81. package/src/blocks/carousel/block.json +2 -1
  82. package/src/blocks/carousel/edit.js +120 -117
  83. package/src/blocks/carousel/index.js +2 -1
  84. package/src/blocks/carousel/view.php +1 -0
  85. package/src/blocks/donate/block.json +3 -2
  86. package/src/blocks/donate/edit/FrequencyBasedLayout.tsx +2 -3
  87. package/src/blocks/donate/edit/index.tsx +56 -39
  88. package/src/blocks/donate/index.js +2 -1
  89. package/src/blocks/donate/view.php +1 -0
  90. package/src/blocks/homepage-articles/block.json +2 -1
  91. package/src/blocks/homepage-articles/edit.tsx +42 -37
  92. package/src/blocks/homepage-articles/index.js +2 -1
  93. package/src/blocks/homepage-articles/view.php +13 -1
  94. package/src/blocks/iframe/block.json +3 -2
  95. package/src/blocks/iframe/edit.js +36 -34
  96. package/src/blocks/iframe/index.js +2 -1
  97. package/src/blocks/iframe/view.php +1 -0
  98. package/src/blocks/video-playlist/edit.js +22 -15
  99. package/src/blocks/video-playlist/index.js +1 -0
  100. package/src/blocks/video-playlist/view.php +1 -0
  101. package/src/setup/placeholder-blocks.js +1 -0
  102. package/vendor/composer/installed.php +2 -2
@@ -10,10 +10,10 @@ import classnames from 'classnames';
10
10
  * WordPress dependencies
11
11
  */
12
12
  import { __ } from '@wordpress/i18n';
13
- import { InspectorControls } from '@wordpress/block-editor';
13
+ import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
14
14
  // eslint-disable-next-line @wordpress/no-unsafe-wp-apis
15
15
  import { dateI18n, __experimentalGetSettings } from '@wordpress/date';
16
- import { Component, createRef, Fragment, RawHTML } from '@wordpress/element';
16
+ import { Component, createRef, Fragment, RawHTML, useRef } from '@wordpress/element';
17
17
  import {
18
18
  PanelBody,
19
19
  Placeholder,
@@ -50,7 +50,6 @@ class Edit extends Component {
50
50
  this.btnPauseRef = createRef();
51
51
  this.btnNextRef = createRef();
52
52
  this.btnPrevRef = createRef();
53
- this.carouselRef = createRef();
54
53
  this.paginationRef = createRef();
55
54
 
56
55
  this.state = {
@@ -64,7 +63,7 @@ class Edit extends Component {
64
63
  }
65
64
 
66
65
  componentDidUpdate( prevProps ) {
67
- const isVisible = 0 < this.carouselRef.current.offsetWidth && 0 < this.carouselRef.current.offsetHeight;
66
+ const isVisible = 0 < this.props.carouselRef.current.offsetWidth && 0 < this.props.carouselRef.current.offsetHeight;
68
67
 
69
68
  // Bail early if the component is hidden.
70
69
  if ( ! isVisible ) {
@@ -108,8 +107,8 @@ class Edit extends Component {
108
107
  const { aspectRatio, autoplay, delay, slidesPerView } = this.props.attributes;
109
108
  const swiperInstance = createSwiper(
110
109
  {
111
- block: this.carouselRef.current, // Editor uses the same wrapper for block and swiper container.
112
- container: this.carouselRef.current,
110
+ block: this.props.carouselRef.current, // Editor uses the same wrapper for block and swiper container.
111
+ container: this.props.carouselRef.current,
113
112
  next: this.btnNextRef.current,
114
113
  prev: this.btnPrevRef.current,
115
114
  play: this.btnPlayRef.current,
@@ -134,7 +133,7 @@ class Edit extends Component {
134
133
  }
135
134
 
136
135
  render() {
137
- const { attributes, className, setAttributes, latestPosts, isUIDisabled } = this.props;
136
+ const { attributes, setAttributes, latestPosts, isUIDisabled, blockProps } = this.props;
138
137
  const {
139
138
  aspectRatio,
140
139
  authors,
@@ -161,8 +160,7 @@ class Edit extends Component {
161
160
  tags,
162
161
  } = attributes;
163
162
  const classes = classnames(
164
- className,
165
- 'wp-block-newspack-blocks-carousel', // Default to make styles work for third-party consumers.
163
+ blockProps.className,
166
164
  'wpnbpc', // Shortened version of the default classname.
167
165
  'slides-per-view-' + slidesPerView,
168
166
  'swiper',
@@ -206,113 +204,6 @@ class Edit extends Component {
206
204
 
207
205
  return (
208
206
  <Fragment>
209
- <div className={ classes } ref={ this.carouselRef }>
210
- { hasNoPosts && (
211
- <Placeholder className="component-placeholder__align-center">
212
- <div style={ { margin: 'auto' } }>{ __( 'Sorry, no posts were found.' ) }</div>
213
- </Placeholder>
214
- ) }
215
- { ( ! this.state.swiperInitialized || ! latestPosts ) && (
216
- <Placeholder icon={ <Spinner /> } className="component-placeholder__align-center" />
217
- ) }
218
- { latestPosts && (
219
- <Fragment>
220
- { autoplay && (
221
- <Fragment>
222
- <button className="swiper-button swiper-button-pause" ref={ this.btnPauseRef } />
223
- <button className="swiper-button swiper-button-play" ref={ this.btnPlayRef } />
224
- </Fragment>
225
- ) }
226
- <div className="swiper-wrapper">
227
- { latestPosts.map( post => (
228
- <article
229
- className={ `post-has-image swiper-slide ${ post.post_type } ${ post.newspack_article_classes || '' }` }
230
- key={ post.id }
231
- >
232
- { getPostStatusLabel( post ) }
233
- <figure className="post-thumbnail">
234
- <a href="#" rel="bookmark">
235
- { post.newspack_featured_image_src ? (
236
- <img
237
- className={ `image-fit-${ imageFit }` }
238
- src={ post.newspack_featured_image_src.large }
239
- alt=""
240
- />
241
- ) : (
242
- <div className="wp-block-newspack-blocks-carousel__placeholder" />
243
- ) }
244
- </a>
245
- </figure>
246
- { ( post.newspack_post_sponsors ||
247
- showCategory ||
248
- showTitle ||
249
- showAuthor ||
250
- showDate ||
251
- showCaption ||
252
- showCredit ) && (
253
- <div className="entry-wrapper">
254
- { ( post.newspack_post_sponsors || ( showCategory && 0 < post.newspack_category_info.length ) ) && (
255
- <div className={ 'cat-links' + ( post.newspack_post_sponsors ? ' sponsor-label' : '' ) }>
256
- { post.newspack_post_sponsors && (
257
- <span className="flag">{ post.newspack_post_sponsors[ 0 ].flag }</span>
258
- ) }
259
- { showCategory &&
260
- ( ! post.newspack_post_sponsors || post.newspack_sponsors_show_categories ) && (
261
- <RawHTML>{ decodeEntities( post.newspack_category_info ) }</RawHTML>
262
- ) }
263
- </div>
264
- ) }
265
- { showTitle && (
266
- <h3 className="entry-title">
267
- <a href="#">{ decodeEntities( post.title.rendered.trim() ) }</a>
268
- </h3>
269
- ) }
270
- <div className="entry-meta">
271
- { post.newspack_post_sponsors && (
272
- <span
273
- className={ `entry-sponsors ${
274
- post.newspack_sponsors_show_author ? 'plus-author' : ''
275
- }` }
276
- >
277
- { formatSponsorLogos( post.newspack_post_sponsors ) }
278
- { formatSponsorByline( post.newspack_post_sponsors ) }
279
- </span>
280
- ) }
281
- { showAuthor &&
282
- ! post.newspack_listings_hide_author &&
283
- ( ! post.newspack_post_sponsors || post.newspack_sponsors_show_author ) && (
284
- <RawHTML className="byline-container">{ getBylineHTML( post, showAvatar ) }</RawHTML>
285
- ) }
286
- { showDate && (
287
- <time className="entry-date published" key="pub-date">
288
- { dateI18n( dateFormat, post.date ) }
289
- </time>
290
- ) }
291
- { ( showCaption || showCredit ) && post.newspack_featured_image_caption && (
292
- <div
293
- className="entry-caption"
294
- dangerouslySetInnerHTML={ {
295
- __html: post.newspack_featured_image_caption,
296
- } }
297
- />
298
- ) }
299
- </div>
300
- </div>
301
- ) }
302
- </article>
303
- ) ) }
304
- </div>
305
- { ! hasNoPosts && ! hasOnePost && (
306
- <>
307
- <button className="swiper-button swiper-button-prev" ref={ this.btnPrevRef } />
308
- <button className="swiper-button swiper-button-next" ref={ this.btnNextRef } />
309
- <div className="swiper-pagination swiper-pagination-bullets" ref={ this.paginationRef } />
310
- </>
311
- ) }
312
- </Fragment>
313
- ) }
314
- </div>
315
-
316
207
  <InspectorControls>
317
208
  <PanelBody title={ __( 'Settings', 'newspack-blocks' ) } className="newspack-block__panel is-content">
318
209
  { postsToShow && (
@@ -456,9 +347,121 @@ class Edit extends Component {
456
347
  <PostTypesPanel attributes={ attributes } setAttributes={ setAttributes } />
457
348
  <PostStatusesPanel attributes={ attributes } setAttributes={ setAttributes } />
458
349
  </InspectorControls>
350
+ <div { ...blockProps } className={ classes } ref={ this.props.carouselRef }>
351
+ { hasNoPosts && (
352
+ <Placeholder className="component-placeholder__align-center">
353
+ <div style={ { margin: 'auto' } }>{ __( 'Sorry, no posts were found.' ) }</div>
354
+ </Placeholder>
355
+ ) }
356
+ { ( ! this.state.swiperInitialized || ! latestPosts ) && (
357
+ <Placeholder icon={ <Spinner /> } className="component-placeholder__align-center" />
358
+ ) }
359
+ { latestPosts && (
360
+ <Fragment>
361
+ { autoplay && (
362
+ <Fragment>
363
+ <button className="swiper-button swiper-button-pause" ref={ this.btnPauseRef } />
364
+ <button className="swiper-button swiper-button-play" ref={ this.btnPlayRef } />
365
+ </Fragment>
366
+ ) }
367
+ <div className="swiper-wrapper">
368
+ { latestPosts.map( post => (
369
+ <article
370
+ className={ `post-has-image swiper-slide ${ post.post_type } ${ post.newspack_article_classes || '' }` }
371
+ key={ post.id }
372
+ >
373
+ { getPostStatusLabel( post ) }
374
+ <figure className="post-thumbnail">
375
+ <a href="#" rel="bookmark">
376
+ { post.newspack_featured_image_src ? (
377
+ <img
378
+ className={ `image-fit-${ imageFit }` }
379
+ src={ post.newspack_featured_image_src.large }
380
+ alt=""
381
+ />
382
+ ) : (
383
+ <div className="wp-block-newspack-blocks-carousel__placeholder" />
384
+ ) }
385
+ </a>
386
+ </figure>
387
+ { ( post.newspack_post_sponsors ||
388
+ showCategory ||
389
+ showTitle ||
390
+ showAuthor ||
391
+ showDate ||
392
+ showCaption ||
393
+ showCredit ) && (
394
+ <div className="entry-wrapper">
395
+ { ( post.newspack_post_sponsors || ( showCategory && 0 < post.newspack_category_info.length ) ) && (
396
+ <div className={ 'cat-links' + ( post.newspack_post_sponsors ? ' sponsor-label' : '' ) }>
397
+ { post.newspack_post_sponsors && (
398
+ <span className="flag">{ post.newspack_post_sponsors[ 0 ].flag }</span>
399
+ ) }
400
+ { showCategory &&
401
+ ( ! post.newspack_post_sponsors || post.newspack_sponsors_show_categories ) && (
402
+ <RawHTML>{ decodeEntities( post.newspack_category_info ) }</RawHTML>
403
+ ) }
404
+ </div>
405
+ ) }
406
+ { showTitle && (
407
+ <h3 className="entry-title">
408
+ <a href="#">{ decodeEntities( post.title.rendered.trim() ) }</a>
409
+ </h3>
410
+ ) }
411
+ <div className="entry-meta">
412
+ { post.newspack_post_sponsors && (
413
+ <span
414
+ className={ `entry-sponsors ${
415
+ post.newspack_sponsors_show_author ? 'plus-author' : ''
416
+ }` }
417
+ >
418
+ { formatSponsorLogos( post.newspack_post_sponsors ) }
419
+ { formatSponsorByline( post.newspack_post_sponsors ) }
420
+ </span>
421
+ ) }
422
+ { showAuthor &&
423
+ ! post.newspack_listings_hide_author &&
424
+ ( ! post.newspack_post_sponsors || post.newspack_sponsors_show_author ) && (
425
+ <RawHTML className="byline-container">{ getBylineHTML( post, showAvatar ) }</RawHTML>
426
+ ) }
427
+ { showDate && (
428
+ <time className="entry-date published" key="pub-date">
429
+ { dateI18n( dateFormat, post.date ) }
430
+ </time>
431
+ ) }
432
+ { ( showCaption || showCredit ) && post.newspack_featured_image_caption && (
433
+ <div
434
+ className="entry-caption"
435
+ dangerouslySetInnerHTML={ {
436
+ __html: post.newspack_featured_image_caption,
437
+ } }
438
+ />
439
+ ) }
440
+ </div>
441
+ </div>
442
+ ) }
443
+ </article>
444
+ ) ) }
445
+ </div>
446
+ { ! hasNoPosts && ! hasOnePost && (
447
+ <>
448
+ <button className="swiper-button swiper-button-prev" ref={ this.btnPrevRef } />
449
+ <button className="swiper-button swiper-button-next" ref={ this.btnNextRef } />
450
+ <div className="swiper-pagination swiper-pagination-bullets" ref={ this.paginationRef } />
451
+ </>
452
+ ) }
453
+ </Fragment>
454
+ ) }
455
+ </div>
459
456
  </Fragment>
460
457
  );
461
458
  }
462
459
  }
463
460
 
464
- export default compose( [ withSelect( postsBlockSelector ), withDispatch( postsBlockDispatch ) ] )( Edit );
461
+ const EditWithBlockProps = props => {
462
+ const carouselRef = useRef();
463
+ const blockProps = useBlockProps();
464
+ return <Edit { ...props } blockProps={ blockProps } carouselRef={ carouselRef } />;
465
+ };
466
+
467
+ export default compose( [ withSelect( postsBlockSelector ), withDispatch( postsBlockDispatch ) ] )( EditWithBlockProps );
@@ -20,7 +20,7 @@ import edit from './edit';
20
20
  import './view.scss';
21
21
  import './editor.scss';
22
22
  import metadata from './block.json';
23
- const { name, attributes, category } = metadata;
23
+ const { name, attributes, apiVersion, category } = metadata;
24
24
 
25
25
  // Name must be exported separately.
26
26
  export { name };
@@ -28,6 +28,7 @@ export { name };
28
28
  export const title = __( 'Content Carousel', 'newspack-blocks' );
29
29
 
30
30
  export const settings = {
31
+ apiVersion,
31
32
  title,
32
33
  icon: {
33
34
  src: icon,
@@ -304,6 +304,7 @@ function newspack_blocks_register_carousel() {
304
304
  apply_filters(
305
305
  'newspack_blocks_block_args',
306
306
  array(
307
+ 'api_version' => 3,
307
308
  'attributes' => array(
308
309
  'className' => array(
309
310
  'type' => 'string',
@@ -1,7 +1,8 @@
1
1
  {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 3,
2
4
  "name": "donate",
3
5
  "category": "newspack",
4
- "apiVersion": 3,
5
6
  "attributes": {
6
7
  "className": {
7
8
  "type": "string"
@@ -99,4 +100,4 @@
99
100
  "html": false,
100
101
  "align": false
101
102
  }
102
- }
103
+ }
@@ -19,11 +19,11 @@ import { FREQUENCIES } from '../consts';
19
19
  import type { ComponentProps, DonationFrequencySlug } from '../types';
20
20
  import { updateBlockClassName, getFormData } from '../view';
21
21
 
22
- const FrequencyBasedLayout = ( props: { isTiered: boolean } & ComponentProps ) => {
22
+ const FrequencyBasedLayout = ( props: { canUseNameYourPrice: boolean; isTiered: boolean } & ComponentProps ) => {
23
23
  // Unique identifier to prevent collisions with other Donate blocks' labels.
24
24
  const uid = useMemo( () => Math.random().toString( 16 ).slice( 2 ), [] );
25
25
 
26
- const { attributes, settings, amounts, availableFrequencies, setAttributes } = props;
26
+ const { attributes, settings, amounts, availableFrequencies, setAttributes, canUseNameYourPrice } = props;
27
27
 
28
28
  const formRef = useRef< HTMLFormElement >( null );
29
29
 
@@ -69,7 +69,6 @@ const FrequencyBasedLayout = ( props: { isTiered: boolean } & ComponentProps ) =
69
69
  }, [ attributes.defaultFrequency ] );
70
70
 
71
71
  const [ selectedFrequency, setSelectedFrequency ] = useState( attributes.defaultFrequency );
72
- const canUseNameYourPrice = window.newspack_blocks_data?.can_use_name_your_price;
73
72
  const renderFrequencySelect = ( frequencySlug: DonationFrequencySlug ) => (
74
73
  <>
75
74
  <input
@@ -23,7 +23,7 @@ import {
23
23
  Button,
24
24
  Notice,
25
25
  } from '@wordpress/components';
26
- import { BlockControls, ColorPaletteControl, InspectorControls } from '@wordpress/block-editor';
26
+ import { BlockControls, ColorPaletteControl, InspectorControls, useBlockProps } from '@wordpress/block-editor';
27
27
  import { isEmpty, pick } from 'lodash';
28
28
  import { Icon, formatListBullets, grid } from '@wordpress/icons';
29
29
 
@@ -40,7 +40,7 @@ import RedirectAfterSuccess from '../../../components/redirect-after-success';
40
40
 
41
41
  const TIER_LABELS = [ __( 'Low-tier', 'newspack-blocks' ), __( 'Mid-tier', 'newspack-blocks' ), __( 'High-tier', 'newspack-blocks' ) ];
42
42
 
43
- const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
43
+ const Edit = ( { attributes, setAttributes }: EditProps ) => {
44
44
  const [ isLoading, setIsLoading ] = useState( true );
45
45
  const [ error, setError ] = useState( '' );
46
46
 
@@ -99,39 +99,51 @@ const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
99
99
  .finally( () => setIsLoading( false ) );
100
100
  }, [] );
101
101
 
102
+ const blockProps = useBlockProps();
102
103
  if ( error.length ) {
103
104
  return (
104
- <Placeholder icon="warning" label={ __( 'Error', 'newspack-blocks' ) } instructions={ error }>
105
- <ExternalLink href="/wp-admin/admin.php?page=newspack-audience#/payment">
106
- { __( 'Go to checkout & payment settings to troubleshoot.', 'newspack-blocks' ) }
107
- </ExternalLink>
108
- </Placeholder>
105
+ <div { ...blockProps }>
106
+ <Placeholder icon="warning" label={ __( 'Error', 'newspack-blocks' ) } instructions={ error }>
107
+ <ExternalLink href="/wp-admin/admin.php?page=newspack-audience#/payment">
108
+ { __( 'Go to checkout & payment settings to troubleshoot.', 'newspack-blocks' ) }
109
+ </ExternalLink>
110
+ </Placeholder>
111
+ </div>
109
112
  );
110
113
  }
111
114
 
112
115
  if ( settings.platform === 'other' ) {
113
116
  return (
114
- <Placeholder
115
- icon="warning"
116
- label={ __( 'The Donate block will not be rendered.', 'newspack-blocks' ) }
117
- instructions={ __( 'The Reader Revenue platform is set to "other".', 'newspack-blocks' ) }
118
- >
119
- <ExternalLink href="/wp-admin/admin.php?page=newspack-audience#/payment">
120
- { __( 'Go to checkout & payment settings to update the platform.', 'newspack-blocks' ) }
121
- </ExternalLink>
122
- </Placeholder>
117
+ <div { ...blockProps }>
118
+ <Placeholder
119
+ icon="warning"
120
+ label={ __( 'The Donate block will not be rendered.', 'newspack-blocks' ) }
121
+ instructions={ __( 'The Reader Revenue platform is set to "other".', 'newspack-blocks' ) }
122
+ >
123
+ <ExternalLink href="/wp-admin/admin.php?page=newspack-audience#/payment">
124
+ { __( 'Go to checkout & payment settings to update the platform.', 'newspack-blocks' ) }
125
+ </ExternalLink>
126
+ </Placeholder>
127
+ </div>
123
128
  );
124
129
  }
125
130
 
126
131
  if ( isLoading ) {
127
- return <Placeholder icon={ <Spinner /> } className="component-placeholder__align-center" />;
132
+ return (
133
+ <div { ...blockProps }>
134
+ <Placeholder icon={ <Spinner /> } className="component-placeholder__align-center" />
135
+ </div>
136
+ );
128
137
  }
129
138
 
130
- const canUseNameYourPrice = window.newspack_blocks_data?.can_use_name_your_price;
139
+ const canUseNameYourPrice = window?.newspack_blocks_data?.can_use_name_your_price;
131
140
  const isManual = attributes.manual && canUseNameYourPrice;
132
141
  const isTiered = isManual ? attributes.tiered : settings.tiered;
133
142
  const isTierBasedLayoutEnabled = isTiered && attributes.layoutOption === 'tiers';
134
143
  const tierLayoutStyle = attributes.tierStyle;
144
+ const hasRecaptcha = window?.newspack_blocks_data?.has_recaptcha;
145
+ const supportsRecaptcha = window?.newspack_blocks_data?.supports_recaptcha;
146
+ const recaptchaURL = window?.newspack_blocks_data?.recaptcha_url || '';
135
147
 
136
148
  const amounts = isManual ? attributes.amounts : settings.amounts;
137
149
 
@@ -139,6 +151,7 @@ const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
139
151
  isManual ? ! attributes.disabledFrequencies[ slug ] : ! settings.disabledFrequencies[ slug ]
140
152
  );
141
153
 
154
+ let className = attributes?.className || '';
142
155
  // Editor bug – initially, the default style is selected, but the class not applied.
143
156
  if ( className.indexOf( 'is-style' ) === -1 ) {
144
157
  className += ' is-style-default';
@@ -200,22 +213,7 @@ const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
200
213
  );
201
214
 
202
215
  return (
203
- <>
204
- { isTierBasedLayoutEnabled ? (
205
- <>
206
- <div className={ getWrapperClassNames() }>
207
- <TierBasedLayout { ...componentProps } amounts={ displayedAmounts } />
208
- </div>
209
- <BlockControls>
210
- <Toolbar controls={ tiersLayoutControls } />
211
- </BlockControls>
212
- </>
213
- ) : (
214
- <div className={ getWrapperClassNames( [ isTiered ? 'tiered' : 'untiered' ] ) }>
215
- <FrequencyBasedLayout isTiered={ isTiered } { ...componentProps } amounts={ displayedAmounts } />
216
- </div>
217
- ) }
218
-
216
+ <Fragment>
219
217
  <InspectorControls>
220
218
  <PanelBody title={ __( 'Layout', 'newspack-blocks' ) }>
221
219
  { canUseNameYourPrice && (
@@ -395,16 +393,16 @@ const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
395
393
  />
396
394
  </PanelBody>
397
395
  ) }
398
- { window.newspack_blocks_data.supports_recaptcha && (
396
+ { supportsRecaptcha && (
399
397
  <PanelBody title={ __( 'Spam protection', 'newspack' ) }>
400
398
  <p>
401
399
  { sprintf(
402
400
  // translators: %s is either 'enabled' or 'disabled'.
403
401
  __( 'reCAPTCHA is currently %s.', 'newspack' ),
404
- window.newspack_blocks_data.has_recaptcha ? __( 'enabled', 'newspack' ) : __( 'disabled', 'newspack' )
402
+ hasRecaptcha ? __( 'enabled', 'newspack' ) : __( 'disabled', 'newspack' )
405
403
  ) }
406
404
  </p>
407
- { ! window.newspack_blocks_data.has_recaptcha && (
405
+ { ! hasRecaptcha && (
408
406
  <p>
409
407
  { __(
410
408
  "It's highly recommended that you enable reCAPTCHA protection to prevent spambots from using this form!",
@@ -413,7 +411,7 @@ const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
413
411
  </p>
414
412
  ) }
415
413
  <p>
416
- <a href={ window.newspack_blocks_data.recaptcha_url }>{ __( 'Configure your reCAPTCHA settings.', 'newspack' ) }</a>
414
+ <a href={ recaptchaURL }>{ __( 'Configure your reCAPTCHA settings.', 'newspack' ) }</a>
417
415
  </p>
418
416
  </PanelBody>
419
417
  ) }
@@ -421,7 +419,26 @@ const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
421
419
  <RedirectAfterSuccess setAttributes={ setAttributes } attributes={ attributes } />
422
420
  </PanelBody>
423
421
  </InspectorControls>
424
- </>
422
+ { isTierBasedLayoutEnabled && (
423
+ <BlockControls>
424
+ <Toolbar controls={ tiersLayoutControls } />
425
+ </BlockControls>
426
+ ) }
427
+ { isTierBasedLayoutEnabled ? (
428
+ <div { ...blockProps } className={ classNames( blockProps.className, getWrapperClassNames() ) }>
429
+ <TierBasedLayout { ...componentProps } amounts={ displayedAmounts } />
430
+ </div>
431
+ ) : (
432
+ <div { ...blockProps } className={ classNames( blockProps.className, getWrapperClassNames( [ isTiered ? 'tiered' : 'untiered' ] ) ) }>
433
+ <FrequencyBasedLayout
434
+ isTiered={ isTiered }
435
+ canUseNameYourPrice={ canUseNameYourPrice }
436
+ amounts={ displayedAmounts }
437
+ { ...componentProps }
438
+ />
439
+ </div>
440
+ ) }
441
+ </Fragment>
425
442
  );
426
443
  };
427
444
 
@@ -23,7 +23,7 @@ import metadata from './block.json';
23
23
  import './styles/editor.scss';
24
24
  import './styles/view.scss';
25
25
 
26
- const { name, attributes, category, supports } = metadata;
26
+ const { name, attributes, apiVersion, category, supports } = metadata;
27
27
 
28
28
  // Name must be exported separately.
29
29
  export { name };
@@ -31,6 +31,7 @@ export { name };
31
31
  export const title = __( 'Donate', 'newspack-blocks' );
32
32
 
33
33
  export const settings = {
34
+ apiVersion,
34
35
  title,
35
36
  icon: {
36
37
  src: icon,
@@ -19,6 +19,7 @@ function newspack_blocks_register_donate() {
19
19
  register_block_type(
20
20
  'newspack-blocks/' . $block_json['name'],
21
21
  [
22
+ 'api_version' => $block_json['apiVersion'],
22
23
  'attributes' => $block_json['attributes'],
23
24
  'render_callback' => 'Newspack_Blocks_Donate_Renderer::render',
24
25
  'supports' => $block_json['supports'],
@@ -1,7 +1,8 @@
1
1
  {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 3,
2
4
  "name": "homepage-articles",
3
5
  "category": "newspack",
4
- "apiVersion": 3,
5
6
  "attributes": {
6
7
  "className": {
7
8
  "type": "string",