Full Site Editing - Version 0.17

Version Description

  • Introduces Blog Posts block, a better version of Posts List.
Download this release

Release Info

Developer obenland
Plugin Icon wp plugin Full Site Editing
Version 0.17
Comparing to
See all releases

Code changes from version 0.16.2 to 0.17

Files changed (52) hide show
  1. blog-posts-block/README.md +30 -0
  2. blog-posts-block/dist/editor.asset.php +1 -0
  3. blog-posts-block/dist/editor.css +1 -0
  4. blog-posts-block/dist/editor.js +2 -0
  5. blog-posts-block/dist/editor.js.LICENSE +5 -0
  6. blog-posts-block/dist/editor.rtl.css +1 -0
  7. blog-posts-block/dist/view.asset.php +1 -0
  8. blog-posts-block/dist/view.css +1 -0
  9. blog-posts-block/dist/view.js +1 -0
  10. blog-posts-block/dist/view.rtl.css +1 -0
  11. blog-posts-block/editor.js +34 -0
  12. blog-posts-block/index.php +92 -0
  13. blog-posts-block/newspack-homepage-articles/README.md +5 -0
  14. blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/block.json +118 -0
  15. blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/class-wp-rest-newspack-articles-controller.php +123 -0
  16. blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/edit.js +641 -0
  17. blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/editor.js +7 -0
  18. blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/editor.scss +39 -0
  19. blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/index.js +106 -0
  20. blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/templates/article.php +143 -0
  21. blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/templates/articles-list.php +21 -0
  22. blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/templates/articles-loop.php +29 -0
  23. blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/view.js +211 -0
  24. blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/view.php +221 -0
  25. blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/view.scss +554 -0
  26. blog-posts-block/newspack-homepage-articles/class-newspack-blocks-api.php +220 -0
  27. blog-posts-block/newspack-homepage-articles/class-newspack-blocks.php +393 -0
  28. blog-posts-block/newspack-homepage-articles/components/autocomplete-tokenfield.js +175 -0
  29. blog-posts-block/newspack-homepage-articles/components/autocomplete-tokenfield.scss +9 -0
  30. blog-posts-block/newspack-homepage-articles/components/query-controls.js +214 -0
  31. blog-posts-block/newspack-homepage-articles/shared/sass/_colors.scss +8 -0
  32. blog-posts-block/newspack-homepage-articles/shared/sass/_legacy_colors.scss +13 -0
  33. blog-posts-block/newspack-homepage-articles/shared/sass/_mixins.scss +26 -0
  34. blog-posts-block/newspack-homepage-articles/shared/sass/_variables.scss +27 -0
  35. blog-posts-block/view.js +1 -0
  36. full-site-editing-plugin.php +44 -171
  37. full-site-editing/dist/full-site-editing.asset.php +1 -1
  38. full-site-editing/dist/full-site-editing.js +1 -1
  39. full-site-editing/helpers.php +181 -0
  40. global-styles/class-global-styles.php +12 -8
  41. global-styles/dist/global-styles.asset.php +1 -1
  42. posts-list-block/blocks/posts-list/editor.scss +9 -0
  43. posts-list-block/blocks/posts-list/index.js +75 -49
  44. posts-list-block/blocks/posts-list/transforms.js +34 -0
  45. posts-list-block/dist/posts-list-block.asset.php +1 -1
  46. posts-list-block/dist/posts-list-block.css +1 -1
  47. posts-list-block/dist/posts-list-block.js +1 -1
  48. posts-list-block/dist/posts-list-block.rtl.css +1 -1
  49. readme.txt +5 -9
  50. starter-page-templates/dist/starter-page-templates.asset.php +1 -1
  51. starter-page-templates/dist/starter-page-templates.js +1 -1
  52. starter-page-templates/page-template-modal/index.js +56 -29
blog-posts-block/README.md ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Blog Posts Block
2
+
3
+ This block allows you to list your posts in various layouts and filter them by criteria like category, tag or author.
4
+
5
+ It originally comes from the [Newspack Blocks collection](https://github.com/automattic/newspack-blocks) and the block is still being developed there.
6
+
7
+ It was added to this repository in order to make it available to other parts of the FSE plugin, such as Starter Page Templates where this block will be used.
8
+
9
+ ## Structure
10
+
11
+ ```
12
+ index.php — main entry file, registers the block on backend
13
+ editor.js — assets for the block editor
14
+ view.js — assets for the block rendered on frontend
15
+ newspack-homepage-articles/** — source code synced from the Newspack Blocks repository
16
+ ```
17
+
18
+ ### Synchronizing the code
19
+
20
+ You can see that `newspack-homepage-articles` is being synced with the Newspack Blocks repository. Please make all improvements and additions on the Newspack side. Please don't make any direct changes to files in this directory as the next synchronization will overwrite them.
21
+
22
+ Once your changes land on the Newspack side, coordinate with the team (over issues/PRs) to [make a new release](https://github.com/Automattic/newspack-blocks/releases) and once you have the release ID, you can pull the code into here.
23
+
24
+ While being in `apps/full-site-editing/` directory, you can run:
25
+
26
+ ```
27
+ npm run sync:blog-posts-block --release=1.0.0-alpha.17
28
+ ```
29
+
30
+ This will pull the code from the release and integrate it into this repository. Please review changes, make sure to update `NEWSPACK_BLOCKS__VERSION` in [index.php](./index.php) and commit.
blog-posts-block/dist/editor.asset.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php return array('dependencies' => array('lodash', 'moment', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-polyfill', 'wp-url'), 'version' => 'd1a7b1582367286500f855e68a4228d0');
blog-posts-block/dist/editor.css ADDED
@@ -0,0 +1 @@
 
1
+ .autocomplete-tokenfield{position:relative}.autocomplete-tokenfield .components-spinner{position:absolute;top:2em;right:0}.type-scale-slider .dashicon{height:16px;width:16px}.type-scale-slider input+.dashicon{height:24px;margin-left:10px;margin-right:0;width:24px}.wpnbha .editor-rich-text{width:100%}.wpnbha .cat-links{font-size:.7em}.wpnbha span.avatar{display:inline-block;margin-right:.5em}.wpnbha span.avatar div{display:inline}.wpnbha .excerpt-contain p{margin:.5em 0}.wpnbha{margin-bottom:1em}.wpnbha article{margin-bottom:1.5em;word-break:break-word;overflow-wrap:break-word;position:relative}.wpnbha article:last-of-type{margin-bottom:0}.wpnbha .article-section-title{font-size:.8em;margin-bottom:.5em;width:100%}.wpnbha.is-grid{display:flex;flex-wrap:wrap;justify-content:space-between;padding:0;list-style:none}.wpnbha.is-grid article{flex-basis:100%}@media only screen and (min-width:782px){.wpnbha.is-grid article,.wpnbha.is-grid article:last-child{margin-bottom:1em}}@media only screen and (min-width:600px){.wpnbha.columns-3 article,.wpnbha.columns-6 article{flex-basis:calc(33.333% - 16px)}.wpnbha.columns-2 article,.wpnbha.columns-4 article,.wpnbha.columns-5 article{flex-basis:calc(50% - 16px)}.wpnbha.columns-5 article:last-of-type:nth-child(odd){flex-grow:1}}@media only screen and (min-width:782px){.wpnbha.columns-2 article{flex-basis:calc(50% - 16px)}.wpnbha.columns-3 article{flex-basis:calc(33.33333% - 16px)}.wpnbha.columns-4 article{flex-basis:calc(25% - 16px)}.wpnbha.columns-5 article{flex-basis:calc(20% - 16px)}.wpnbha.columns-6 article{flex-basis:calc(16.66667% - 16px)}}.wpnbha .post-thumbnail{margin:0}.wpnbha .post-thumbnail img{height:auto;width:100%}.wpnbha figcaption{font-size:.6em}.wpnbha.image-aligntop .post-thumbnail{margin-bottom:.25em}.wpnbha.image-aligntop .post-thumbnail figcaption{margin-bottom:.5em}.wpnbha.image-alignleft .post-has-image,.wpnbha.image-alignright .post-has-image{display:flex}.wpnbha.image-alignleft .post-has-image .post-thumbnail,.wpnbha.image-alignright .post-has-image .post-thumbnail{flex-basis:33%}.wpnbha.image-alignleft .post-has-image .entry-wrapper,.wpnbha.image-alignright .post-has-image .entry-wrapper{flex-basis:67%}.wpnbha.image-alignleft.mobile-stack .post-has-image,.wpnbha.image-alignright.mobile-stack .post-has-image{display:block}@media only screen and (min-width:600px){.wpnbha.image-alignleft.mobile-stack .post-has-image,.wpnbha.image-alignright.mobile-stack .post-has-image{display:flex}.wpnbha.image-alignleft.is-4 .post-thumbnail,.wpnbha.image-alignright.is-4 .post-thumbnail{flex-basis:75%}.wpnbha.image-alignleft.is-4 .entry-wrapper,.wpnbha.image-alignright.is-4 .entry-wrapper{flex-basis:25%}.wpnbha.image-alignleft.is-3 .entry-wrapper,.wpnbha.image-alignleft.is-3 .post-thumbnail,.wpnbha.image-alignright.is-3 .entry-wrapper,.wpnbha.image-alignright.is-3 .post-thumbnail{flex-basis:50%}}.wpnbha.image-alignleft.is-1 .post-thumbnail,.wpnbha.image-alignright.is-1 .post-thumbnail{flex-basis:25%}.wpnbha.image-alignleft.is-1 .entry-wrapper,.wpnbha.image-alignright.is-1 .entry-wrapper{flex-basis:75%}.wpnbha.image-alignleft .post-thumbnail{margin-right:1em}.wpnbha.image-alignright .post-thumbnail{margin-left:1em}.wpnbha.image-alignright .entry-wrapper{order:-1}.wpnbha .entry-title{margin:0 0 .25em}.wpnbha .entry-title a{color:inherit;text-decoration:none}.wpnbha .cat-links{font-size:.6em;font-weight:700;margin:0 0 .5em}.wpnbha .cat-links a{text-decoration:none}.wpnbha .cat-links a:hover{text-decoration:underline}.wpnbha .entry-meta{display:flex;flex-wrap:wrap;align-items:center;margin-top:.5em}.wpnbha .entry-meta .byline:not(:last-child){margin-right:1.5em}.wpnbha .avatar{border-radius:100%;display:block;margin-right:.5em}.wpnbha p{margin:.5em 0}.wpnbha.has-text-color .article-section-title,.wpnbha.has-text-color .cat-links,.wpnbha.has-text-color .cat-links a,.wpnbha.has-text-color .cat-links a:visited,.wpnbha.has-text-color .entry-meta,.wpnbha.has-text-color .entry-meta .byline a,.wpnbha.has-text-color .entry-meta .byline a:visited,.wpnbha.has-text-color .entry-meta a,.wpnbha.has-text-color .entry-title,.wpnbha.has-text-color .entry-title a,.wpnbha.has-text-color .entry-title a:visited,.wpnbha.has-text-color figcaption{color:inherit}.wpnbha.has-text-color .entry-meta span:not(.avatar){opacity:.8}.wpnbha.image-alignbehind .post-has-image{display:flex;align-items:flex-end;position:relative}.wpnbha.image-alignbehind .post-has-image .post-thumbnail{bottom:0;left:0;overflow:hidden;position:absolute;right:0;top:0}.wpnbha.image-alignbehind .post-has-image .post-thumbnail img{height:100%;-o-object-fit:cover;object-fit:cover;max-width:1000%;width:100%}.wpnbha.image-alignbehind .post-has-image .post-thumbnail figcaption{bottom:1em;-webkit-box-orient:vertical;color:hsla(0,0%,100%,.9);display:-webkit-box;font-style:italic;left:0;-webkit-line-clamp:1;margin:0;max-height:1.6em;overflow:hidden;padding:0 1em;position:absolute;right:0;text-align:right;text-overflow:ellipsis;z-index:2}.wpnbha.image-alignbehind .post-has-image .post-thumbnail:after{background:rgba(0,0,0,.5);bottom:0;content:"";left:0;position:absolute;right:0;top:0;z-index:1}.wpnbha.image-alignbehind .post-has-image .entry-wrapper{padding:2em;position:relative;z-index:2}.wpnbha.image-alignbehind .post-has-image .cat-links a,.wpnbha.image-alignbehind .post-has-image .entry-meta,.wpnbha.image-alignbehind .post-has-image .entry-meta .byline a,.wpnbha.image-alignbehind .post-has-image .entry-title a,.wpnbha.image-alignbehind .post-has-image .entry-wrapper{color:#fff}.wpnbha article .entry-title{font-size:1.2em}.wpnbha article .entry-meta{font-size:.8em}.wpnbha article .avatar{height:25px;width:25px}@media only screen and (min-width:782px){.wpnbha article .entry-title{font-size:1.6em}.wpnbha article .avatar{height:40px;width:40px}}.wpnbha.ts-8 .entry-title,.wpnbha.ts-9 .entry-title,.wpnbha.ts-10 .entry-title{line-height:1.1em}@media only screen and (min-width:782px){.wpnbha.ts-8 article .avatar,.wpnbha.ts-9 article .avatar,.wpnbha.ts-10 article .avatar{height:2.4em;width:2.4em}}.wpnbha.ts-10 article .entry-title{font-size:2.6em}@media only screen and (min-width:782px){.wpnbha.ts-10 article .entry-title{font-size:3.6em}}@media only screen and (min-width:1168px){.wpnbha.ts-10 article .entry-title{font-size:4.8em}}.wpnbha.ts-9 article .entry-title{font-size:2.4em}@media only screen and (min-width:782px){.wpnbha.ts-9 article .entry-title{font-size:3.4em}}@media only screen and (min-width:1168px){.wpnbha.ts-9 article .entry-title{font-size:4.2em}}.wpnbha.ts-8 article .entry-title{font-size:2.2em}@media only screen and (min-width:782px){.wpnbha.ts-8 article .entry-title{font-size:3em}}@media only screen and (min-width:1168px){.wpnbha.ts-8 article .entry-title{font-size:3.6em}}.wpnbha.ts-7 article .entry-title{font-size:2em}@media only screen and (min-width:782px){.wpnbha.ts-7 article .entry-title{font-size:2.4em}.wpnbha.ts-7 article .avatar{height:48px;width:48px}}@media only screen and (min-width:1168px){.wpnbha.ts-7 article .entry-title{font-size:3em}}.wpnbha.ts-6 article .entry-title{font-size:1.7em}@media only screen and (min-width:782px){.wpnbha.ts-6 article .entry-title{font-size:2em}.wpnbha.ts-6 article .avatar{height:44px;width:44px}}@media only screen and (min-width:1168px){.wpnbha.ts-6 article .entry-title{font-size:2.4em}}.wpnbha.ts-5 article .entry-title{font-size:1.4em}@media only screen and (min-width:782px){.wpnbha.ts-5 article .entry-title{font-size:1.8em}.wpnbha.ts-5 article .avatar{height:40px;width:40px}}@media only screen and (min-width:1168px){.wpnbha.ts-5 article .entry-title{font-size:2em}}.wpnbha.ts-3 article .entry-title{font-size:1em}.wpnbha.ts-3 article .entry-wrapper p{font-size:.8em}.wpnbha.ts-3 article .entry-meta{font-size:.7em}@media only screen and (min-width:782px){.wpnbha.ts-3 article .entry-title{font-size:1.2em}.wpnbha.ts-3 article .avatar{height:32px;width:32px}}.wpnbha.ts-2 article .entry-title{font-size:.8em}.wpnbha.ts-2 article .entry-meta,.wpnbha.ts-2 article .entry-wrapper p{font-size:.7em}@media only screen and (min-width:782px){.wpnbha.ts-2 article .entry-title{font-size:.9em}.wpnbha.ts-2 article .avatar{height:28px;width:28px}}.wpnbha.ts-1 article .entry-title,.wpnbha.ts-1 article .entry-wrapper p{font-size:.7em}.wpnbha.ts-1 article .entry-meta{font-size:.6em}@media only screen and (min-width:782px){.wpnbha.ts-1 article .avatar{height:24px;width:24px}}.wpnbha.is-style-borders article{border:solid rgba(0,0,0,.2);border-width:0 0 1px;margin-bottom:1em;padding-bottom:1em}.wpnbha.is-style-borders article:last-of-type{margin-bottom:0}.wpnbha.is-style-borders article:last-of-type:not(:first-of-type){border-bottom:0}@media only screen and (min-width:782px){.wpnbha.is-style-borders.columns-2 article{padding-right:32px}.wpnbha.is-style-borders.columns-3 article{padding-right:24px}.wpnbha.is-style-borders.columns-4 article{padding-right:21.33333px}.wpnbha.is-style-borders.columns-5 article{padding-right:20px}.wpnbha.is-style-borders.columns-6 article{padding-right:19.2px}.wpnbha.is-style-borders.is-grid article{border-width:0 1px 0 0}.wpnbha.is-style-borders.columns-1 article,.wpnbha.is-style-borders.columns-2 article:nth-of-type(2n),.wpnbha.is-style-borders.columns-3 article:nth-of-type(3n),.wpnbha.is-style-borders.columns-4 article:nth-of-type(4n),.wpnbha.is-style-borders.columns-5 article:nth-of-type(5n),.wpnbha.is-style-borders.columns-6 article:nth-of-type(6n),.wpnbha.is-style-borders.is-grid article:last-of-type{border:0}}
blog-posts-block/dist/editor.js ADDED
@@ -0,0 +1,2 @@
 
 
1
+ /*! For license information please see editor.js.LICENSE */
2
+ !function(e,t){for(var n in t)e[n]=t[n]}(window,function(e){var t={};function n(o){if(t[o])return t[o].exports;var c=t[o]={i:o,l:!1,exports:{}};return e[o].call(c.exports,c,c.exports,n),c.l=!0,c.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var c in e)n.d(o,c,function(t){return e[t]}.bind(null,c));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=33)}([function(e,t){!function(){e.exports=this.wp.element}()},function(e,t){!function(){e.exports=this.wp.i18n}()},function(e,t){!function(){e.exports=this.wp.components}()},function(e,t){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},function(e,t){e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}},function(e,t){!function(){e.exports=this.wp.htmlEntities}()},function(e,t){!function(){e.exports=this.wp.url}()},function(e,t){!function(){e.exports=this.wp.apiFetch}()},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},function(e,t,n){var o=n(28),c=n(4);e.exports=function(e,t){return!t||"object"!==o(t)&&"function"!=typeof t?c(e):t}},function(e,t){function n(t){return e.exports=n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},n(t)}e.exports=n},function(e,t,n){var o=n(29);e.exports=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}},function(e,t){!function(){e.exports=this.wp.editor}()},function(e,t){!function(){e.exports=this.wp.blocks}()},function(e,t){!function(){e.exports=this.lodash}()},function(e,t){!function(){e.exports=this.wp.hooks}()},function(e,t,n){var o=n(25),c=n(26),a=n(27);e.exports=function(e){return o(e)||c(e)||a()}},function(e,t){function n(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}e.exports=function(e,t,o){return t&&n(e.prototype,t),o&&n(e,o),e}},function(e){e.exports=JSON.parse('{"name":"homepage-articles","category":"newspack","attributes":{"className":{"type":"string","default":""},"showExcerpt":{"type":"boolean","default":true},"showDate":{"type":"boolean","default":true},"showImage":{"type":"boolean","default":true},"showCaption":{"type":"boolean","default":false},"imageShape":{"type":"string","default":"landscape"},"minHeight":{"type":"integer","default":0},"moreButton":{"type":"boolean","default":false},"showAuthor":{"type":"boolean","default":true},"showAvatar":{"type":"boolean","default":true},"showCategory":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"integer","default":3},"postsToShow":{"type":"integer","default":3},"mediaPosition":{"type":"string","default":"top"},"authors":{"type":"array","default":[],"items":{"type":"integer"}},"categories":{"type":"array","default":[],"items":{"type":"integer"}},"tags":{"type":"array","default":[],"items":{"type":"integer"}},"specificPosts":{"type":"array","default":[],"items":{"type":"integer"}},"typeScale":{"type":"integer","default":4},"imageScale":{"type":"integer","default":3},"mobileStack":{"type":"boolean","default":false},"sectionHeader":{"type":"string","default":""},"specificMode":{"type":"boolean","default":false},"textColor":{"type":"string","default":""},"customTextColor":{"type":"string","default":""},"singleMode":{"type":"boolean","default":false}}}')},function(e,t){!function(){e.exports=this.wp.blockEditor}()},function(e,t,n){var o=n(3);function c(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}e.exports=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?c(Object(n),!0).forEach((function(t){o(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}},function(e,t,n){var o;!function(){"use strict";var n={}.hasOwnProperty;function c(){for(var e=[],t=0;t<arguments.length;t++){var o=arguments[t];if(o){var a=typeof o;if("string"===a||"number"===a)e.push(o);else if(Array.isArray(o)&&o.length){var r=c.apply(null,o);r&&e.push(r)}else if("object"===a)for(var s in o)n.call(o,s)&&o[s]&&e.push(s)}}return e.join(" ")}e.exports?(c.default=c,e.exports=c):void 0===(o=function(){return c}.apply(t,[]))||(e.exports=o)}()},function(e,t){!function(){e.exports=this.moment}()},function(e,t){!function(){e.exports=this.wp.data}()},function(e,t){!function(){e.exports=this.wp.compose}()},function(e,t){e.exports=function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}},function(e,t){e.exports=function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}},function(e,t){function n(t){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?e.exports=n=function(e){return typeof e}:e.exports=n=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(t)}e.exports=n},function(e,t){function n(t,o){return e.exports=n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(t,o)}e.exports=n},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){"use strict";n.r(t);var o=n(20),c=n.n(o),a=n(13),r=n(1),s=n(15),i=n(0),l=n(2),u=n(16),p=n.n(u),b=n(8),h=n.n(b),f=n(17),g=n.n(f),m=n(9),d=n.n(m),w=n(10),O=n.n(w),k=n(4),j=n.n(k),_=n(11),y=n.n(_),v=n(3),S=n.n(v),E=n(7),C=n.n(E),P=n(6),x=n(5),A=n(14),T=(n(30),function(e){function t(e){var n;return h()(this,t),(n=d()(this,O()(t).call(this,e))).state={suggestions:[],validValues:{},loading:!1},n.debouncedUpdateSuggestions=Object(A.debounce)(n.updateSuggestions,500),n}return y()(t,e),g()(t,[{key:"componentDidMount",value:function(){var e=this,t=this.props,n=t.tokens,o=t.fetchSavedInfo;n.length&&o&&this.setState({loading:!0},(function(){o(n).then((function(t){var n=e.state.validValues;t.forEach((function(e){n[e.value]=e.label})),e.setState({validValues:n,loading:!1})}))}))}},{key:"componentWillUnmount",value:function(){delete this.suggestionsRequest,this.debouncedUpdateSuggestions.cancel()}},{key:"getLabelsForValues",value:function(e){var t=this.state.validValues;return e.reduce((function(e,n){return t[n]?[].concat(p()(e),[t[n]]):e}),[])}},{key:"getValuesForLabels",value:function(e){var t=this.state.validValues;return e.map((function(e){return Object.keys(t).find((function(n){return t[n]===e}))}))}},{key:"updateSuggestions",value:function(e){var t=this,n=this.props.fetchSuggestions;n&&this.setState({loading:!0},(function(){var o=n(e);o.then((function(e){if(t.suggestionsRequest===o){var n=t.state.validValues,c=[];e.forEach((function(e){c.push(e.label),n[e.value]=e.label})),t.setState({suggestions:c,validValues:n,loading:!1})}})).catch((function(){t.suggestionsRequest===o&&t.setState({loading:!1})})),t.suggestionsRequest=o}))}},{key:"handleOnChange",value:function(e){(0,this.props.onChange)(this.getValuesForLabels(e))}},{key:"getTokens",value:function(){var e=this.props.tokens;return this.getLabelsForValues(e)}},{key:"render",value:function(){var e=this,t=this.props.label,n=void 0===t?"":t,o=this.state,c=o.suggestions,a=o.loading;return Object(i.createElement)("div",{className:"autocomplete-tokenfield"},Object(i.createElement)(l.FormTokenField,{value:this.getTokens(),suggestions:c,onChange:function(t){return e.handleOnChange(t)},onInputChange:function(t){return e.debouncedUpdateSuggestions(t)},label:n}),a&&Object(i.createElement)(l.Spinner,null))}}]),t}(i.Component)),M=function(e){function t(){var e,n;h()(this,t);for(var o=arguments.length,c=new Array(o),a=0;a<o;a++)c[a]=arguments[a];return n=d()(this,(e=O()(t)).call.apply(e,[this].concat(c))),S()(j()(n),"fetchPostSuggestions",(function(e){return C()({path:Object(P.addQueryArgs)("/wp/v2/search",{search:e,per_page:20,_fields:"id,title",type:"post"})}).then((function(e){return e.map((function(e){return{value:e.id,label:Object(x.decodeEntities)(e.title)||Object(r.__)("(no title)","newspack-blocks")}}))}))})),S()(j()(n),"fetchSavedPosts",(function(e){return C()({path:Object(P.addQueryArgs)("/wp/v2/posts",{per_page:100,include:e.join(","),_fields:"id,title"})}).then((function(e){return e.map((function(e){return{value:e.id,label:Object(x.decodeEntities)(e.title.rendered)||Object(r.__)("(no title)","newspack-blocks")}}))}))})),S()(j()(n),"fetchAuthorSuggestions",(function(e){return C()({path:Object(P.addQueryArgs)("/wp/v2/users",{search:e,per_page:20,_fields:"id,name"})}).then((function(e){return e.map((function(e){return{value:e.id,label:Object(x.decodeEntities)(e.name)||Object(r.__)("(no name)","newspack-blocks")}}))}))})),S()(j()(n),"fetchSavedAuthors",(function(e){return C()({path:Object(P.addQueryArgs)("/wp/v2/users",{per_page:100,include:e.join(","),_fields:"id,name"})}).then((function(e){return e.map((function(e){return{value:e.id,label:Object(x.decodeEntities)(e.name)||Object(r.__)("(no name)","newspack-blocks")}}))}))})),S()(j()(n),"fetchCategorySuggestions",(function(e){return C()({path:Object(P.addQueryArgs)("/wp/v2/categories",{search:e,per_page:20,_fields:"id,name",orderby:"count",order:"desc"})}).then((function(e){return e.map((function(e){return{value:e.id,label:Object(x.decodeEntities)(e.name)||Object(r.__)("(no title)","newspack-blocks")}}))}))})),S()(j()(n),"fetchSavedCategories",(function(e){return C()({path:Object(P.addQueryArgs)("/wp/v2/categories",{per_page:100,_fields:"id,name",include:e.join(",")})}).then((function(e){return e.map((function(e){return{value:e.id,label:Object(x.decodeEntities)(e.name)||Object(r.__)("(no title)","newspack-blocks")}}))}))})),S()(j()(n),"fetchTagSuggestions",(function(e){return C()({path:Object(P.addQueryArgs)("/wp/v2/tags",{search:e,per_page:20,_fields:"id,name",orderby:"count",order:"desc"})}).then((function(e){return e.map((function(e){return{value:e.id,label:Object(x.decodeEntities)(e.name)||Object(r.__)("(no title)","newspack-blocks")}}))}))})),S()(j()(n),"fetchSavedTags",(function(e){return C()({path:Object(P.addQueryArgs)("/wp/v2/tags",{per_page:100,_fields:"id,name",include:e.join(",")})}).then((function(e){return e.map((function(e){return{value:e.id,label:Object(x.decodeEntities)(e.name)||Object(r.__)("(no title)","newspack-blocks")}}))}))})),S()(j()(n),"render",(function(){var e=n.props,t=(e.numberOfItems,e.onNumberOfItemsChange,e.specificMode),o=e.onSpecificModeChange,c=e.specificPosts,a=e.onSpecificPostsChange,s=e.authors,u=e.onAuthorsChange,p=e.categories,b=e.onCategoriesChange,h=e.tags,f=e.onTagsChange;return[e.enableSpecific&&Object(i.createElement)(l.ToggleControl,{checked:t,onChange:o,label:Object(r.__)("Choose specific stories","newspack-blocks")}),t&&Object(i.createElement)(T,{tokens:c||[],onChange:a,fetchSuggestions:n.fetchPostSuggestions,fetchSavedInfo:n.fetchSavedPosts,label:Object(r.__)("Posts","newspack-blocks")}),!t&&Object(i.createElement)(l.QueryControls,n.props),!t&&u&&Object(i.createElement)(T,{tokens:s||[],onChange:u,fetchSuggestions:n.fetchAuthorSuggestions,fetchSavedInfo:n.fetchSavedAuthors,label:Object(r.__)("Authors","newspack-blocks")}),!t&&b&&Object(i.createElement)(T,{tokens:p||[],onChange:b,fetchSuggestions:n.fetchCategorySuggestions,fetchSavedInfo:n.fetchSavedCategories,label:Object(r.__)("Categories","newspack-blocks")}),!t&&f&&Object(i.createElement)(T,{tokens:h||[],onChange:f,fetchSuggestions:n.fetchTagSuggestions,fetchSavedInfo:n.fetchSavedTags,label:Object(r.__)("Tags","newspack-blocks")})]})),n}return y()(t,e),t}(i.Component);M.defaultProps={enableSpecific:!0,specificPosts:[],authors:[],categories:[],tags:[]};var H=M,V=n(21),z=n.n(V),N=n(22),I=n.n(N),B=n(12),L=n(23),R=n(24),D=n(19),F=6,q=Object(i.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"},Object(i.createElement)(l.Path,{d:"M0 0h24v24H0z",fill:"none"}),Object(i.createElement)(l.Path,{d:"M19 5H5c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 12H5V7h14v10z"})),Q=Object(i.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"},Object(i.createElement)(l.Path,{d:"M0 0h24v24H0z",fill:"none"}),Object(i.createElement)(l.Path,{d:"M17 3H7c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h10c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H7V5h10v14z"})),G=Object(i.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"},Object(i.createElement)(l.Path,{d:"M0 0h24v24H0z",fill:"none"}),Object(i.createElement)(l.Path,{d:"M18 4H6c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 14H6V6h12v12z"})),U=Object(i.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"},Object(i.createElement)(l.Path,{d:"M0 0h24v24H0z",fill:"none"}),Object(i.createElement)(l.Path,{d:"M3 5v4h2V5h4V3H5c-1.1 0-2 .9-2 2zm2 10H3v4c0 1.1.9 2 2 2h4v-2H5v-4zm14 4h-4v2h4c1.1 0 2-.9 2-2v-4h-2v4zm0-16h-4v2h4v4h2V5c0-1.1-.9-2-2-2z"})),W=Object(i.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"},Object(i.createElement)(l.Path,{d:"M0 0h24v24H0z",fill:"none"}),Object(i.createElement)(l.Path,{d:"M4 4h7V2H4c-1.1 0-2 .9-2 2v7h2V4zm6 9l-4 5h12l-3-4-2.03 2.71L10 13zm7-4.5c0-.83-.67-1.5-1.5-1.5S14 7.67 14 8.5s.67 1.5 1.5 1.5S17 9.33 17 8.5zM20 2h-7v2h7v7h2V4c0-1.1-.9-2-2-2zm0 18h-7v2h7c1.1 0 2-.9 2-2v-7h-2v7zM4 13H2v7c0 1.1.9 2 2 2h7v-2H4v-7z"})),J=function(e){function t(){var e,n;h()(this,t);for(var o=arguments.length,c=new Array(o),a=0;a<o;a++)c[a]=arguments[a];return n=d()(this,(e=O()(t)).call.apply(e,[this].concat(c))),S()(j()(n),"renderPost",(function(e){var t=n.props.attributes,o=t.showImage,c=t.imageShape,a=t.mediaPosition,r=t.minHeight,s=t.showCaption,l=t.showExcerpt,u=t.showAuthor,p=t.showAvatar,b=t.showDate,h=t.showCategory,f=t.sectionHeader,g={minHeight:"behind"===a&&o&&e.newspack_featured_image_src&&r+"vh",paddingTop:"behind"===a&&o&&e.newspack_featured_image_src&&r/5+"vh"};e.newspack_author_info.length;return Object(i.createElement)("article",{className:e.newspack_featured_image_src?"post-has-image":null,key:e.id,style:g},o&&e.newspack_featured_image_src&&Object(i.createElement)("figure",{className:"post-thumbnail",key:"thumbnail"},Object(i.createElement)("a",{href:"#"},"landscape"===c&&Object(i.createElement)("img",{src:e.newspack_featured_image_src.landscape}),"portrait"===c&&Object(i.createElement)("img",{src:e.newspack_featured_image_src.portrait}),"square"===c&&Object(i.createElement)("img",{src:e.newspack_featured_image_src.square}),"uncropped"===c&&Object(i.createElement)("img",{src:e.newspack_featured_image_src.uncropped})),s&&""!==e.newspack_featured_image_caption&&Object(i.createElement)("figcaption",null,e.newspack_featured_image_caption)),Object(i.createElement)("div",{className:"entry-wrapper"},h&&e.newspack_category_info.length&&Object(i.createElement)("div",{className:"cat-links"},Object(i.createElement)("a",{href:"#"},e.newspack_category_info)),B.RichText.isEmpty(f)?Object(i.createElement)("h2",{className:"entry-title",key:"title"},Object(i.createElement)("a",{href:"#"},Object(x.decodeEntities)(e.title.rendered.trim()))):Object(i.createElement)("h3",{className:"entry-title",key:"title"},Object(i.createElement)("a",{href:"#"},Object(x.decodeEntities)(e.title.rendered.trim()))),l&&Object(i.createElement)(i.RawHTML,{key:"excerpt",className:"excerpt-contain"},e.excerpt.rendered),Object(i.createElement)("div",{className:"entry-meta"},u&&p&&n.formatAvatars(e.newspack_author_info),u&&n.formatByline(e.newspack_author_info),b&&Object(i.createElement)("time",{className:"entry-date published",key:"pub-date"},I()(e.date_gmt).local().format("MMMM DD, Y")))))})),S()(j()(n),"formatAvatars",(function(e){return e.map((function(e){return Object(i.createElement)("span",{className:"avatar author-avatar"},Object(i.createElement)("a",{className:"url fn n",href:"#"},Object(i.createElement)(i.RawHTML,{key:e.id},e.avatar)))}))})),S()(j()(n),"formatByline",(function(e){return Object(i.createElement)("span",{className:"byline"},Object(r.__)("by","newspack-blocks")," ",e.reduce((function(t,n,o){return[].concat(p()(t),[Object(i.createElement)("span",{className:"author vcard",key:n.id},Object(i.createElement)("a",{className:"url fn n",href:"#"},n.display_name)),o<e.length-2&&", ",e.length>1&&o===e.length-2&&Object(r.__)(" and ","newspack-blocks")])}),[]))})),S()(j()(n),"renderInspectorControls",(function(){var e=n.props,t=e.attributes,o=e.setAttributes,c=e.latestPosts,a=(e.isSelected,e.textColor),s=e.setTextColor,u=Array.isArray(c)&&c.length,p=t.authors,b=t.specificPosts,h=t.postsToShow,f=t.categories,g=(t.sectionHeader,t.columns),m=t.showImage,d=t.showCaption,w=t.imageScale,O=t.mobileStack,k=t.minHeight,j=t.moreButton,_=t.showExcerpt,y=t.typeScale,v=t.showDate,S=t.showAuthor,E=t.showAvatar,C=t.showCategory,P=t.postLayout,x=t.mediaPosition,A=t.specificMode,T=t.tags,M=(t.url,[{value:1,label:Object(r.__)("Small","newspack-blocks"),shortName:Object(r.__)("S","newspack-blocks")},{value:2,label:Object(r.__)("Medium","newspack-blocks"),shortName:Object(r.__)("M","newspack-blocks")},{value:3,label:Object(r.__)("Large","newspack-blocks"),shortName:Object(r.__)("L","newspack-blocks")},{value:4,label:Object(r.__)("Extra Large","newspack-blocks"),shortName:Object(r.__)("XL","newspack-blocks")}]);return Object(i.createElement)(i.Fragment,null,Object(i.createElement)(l.PanelBody,{title:Object(r.__)("Display Settings","newspack-blocks"),initialOpen:!0},h&&Object(i.createElement)(H,{numberOfItems:h,onNumberOfItemsChange:function(e){return o({postsToShow:e})},specificMode:A,onSpecificModeChange:function(e){return o({specificMode:e})},specificPosts:b,onSpecificPostsChange:function(e){return o({specificPosts:e})},authors:p,onAuthorsChange:function(e){return o({authors:e})},categories:f,onCategoriesChange:function(e){return o({categories:e})},tags:T,onTagsChange:function(e){return o({tags:e})}}),"grid"===P&&Object(i.createElement)(l.RangeControl,{label:Object(r.__)("Columns","newspack-blocks"),value:g,onChange:function(e){return o({columns:e})},min:2,max:u?Math.min(F,c.length):F,required:!0}),!A&&Object(i.createElement)(l.ToggleControl,{label:Object(r.__)('Show "More" Button',"newspack-blocks"),checked:j,onChange:function(){return o({moreButton:!j})},help:Object(r.__)("Only available for non-AMP requests.","newspack-blocks")})),Object(i.createElement)(l.PanelBody,{title:Object(r.__)("Featured Image Settings","newspack-blocks")},Object(i.createElement)(l.PanelRow,null,Object(i.createElement)(l.ToggleControl,{label:Object(r.__)("Show Featured Image","newspack-blocks"),checked:m,onChange:function(){return o({showImage:!m})}})),m&&Object(i.createElement)(l.PanelRow,null,Object(i.createElement)(l.ToggleControl,{label:Object(r.__)("Show Featured Image Caption","newspack-blocks"),checked:d,onChange:function(){return o({showCaption:!d})}})),m&&"top"!==x&&"behind"!==x&&Object(i.createElement)(i.Fragment,null,Object(i.createElement)(l.PanelRow,null,Object(i.createElement)(l.ToggleControl,{label:Object(r.__)("Stack on mobile","newspack-blocks"),checked:O,onChange:function(){return o({mobileStack:!O})}})),Object(i.createElement)(l.BaseControl,{label:Object(r.__)("Featured Image Size","newspack-blocks")},Object(i.createElement)(l.PanelRow,null,Object(i.createElement)(l.ButtonGroup,{"aria-label":Object(r.__)("Featured Image Size","newspack-blocks")},M.map((function(e){var t=w===e.value;return Object(i.createElement)(l.Button,{isLarge:!0,isPrimary:t,"aria-pressed":t,"aria-label":e.label,onClick:function(){return o({imageScale:e.value})}},e.shortName)})))))),m&&"behind"===x&&Object(i.createElement)(l.RangeControl,{label:Object(r.__)("Minimum height","newspack-blocks"),help:Object(r.__)("Sets a minimum height for the block, using a percentage of the screen's current height.","newspack-blocks"),value:k,onChange:function(e){return o({minHeight:e})},min:0,max:100,required:!0})),Object(i.createElement)(l.PanelBody,{title:Object(r.__)("Post Control Settings","newspack-blocks")},Object(i.createElement)(l.PanelRow,null,Object(i.createElement)(l.ToggleControl,{label:Object(r.__)("Show Excerpt","newspack-blocks"),checked:_,onChange:function(){return o({showExcerpt:!_})}})),Object(i.createElement)(l.RangeControl,{className:"type-scale-slider",label:Object(r.__)("Type Scale","newspack-blocks"),value:y,onChange:function(e){return o({typeScale:e})},min:1,max:10,beforeIcon:"editor-textcolor",afterIcon:"editor-textcolor",required:!0})),Object(i.createElement)(D.PanelColorSettings,{title:Object(r.__)("Color Settings","newspack-blocks"),initialOpen:!0,colorSettings:[{value:a.color,onChange:s,label:Object(r.__)("Text Color","newspack-blocks")}]}),Object(i.createElement)(l.PanelBody,{title:Object(r.__)("Post Meta Settings","newspack-blocks")},Object(i.createElement)(l.PanelRow,null,Object(i.createElement)(l.ToggleControl,{label:Object(r.__)("Show Date","newspack-blocks"),checked:v,onChange:function(){return o({showDate:!v})}})),Object(i.createElement)(l.PanelRow,null,Object(i.createElement)(l.ToggleControl,{label:Object(r.__)("Show Category","newspack-blocks"),checked:C,onChange:function(){return o({showCategory:!C})}})),Object(i.createElement)(l.PanelRow,null,Object(i.createElement)(l.ToggleControl,{label:Object(r.__)("Show Author","newspack-blocks"),checked:S,onChange:function(){return o({showAuthor:!S})}})),S&&Object(i.createElement)(l.PanelRow,null,Object(i.createElement)(l.ToggleControl,{label:Object(r.__)("Show Author Avatar","newspack-blocks"),checked:E,onChange:function(){return o({showAvatar:!E})}}))))})),n}return y()(t,e),g()(t,[{key:"render",value:function(){var e,t=this,n=this.props,o=n.attributes,c=n.className,a=n.setAttributes,s=n.isSelected,u=n.latestPosts,p=(n.hasPosts,n.textColor),b=(o.showExcerpt,o.showDate,o.showImage),h=o.imageShape,f=(o.showAuthor,o.showAvatar,o.postsToShow,o.postLayout),g=o.mediaPosition,m=o.moreButton,d=o.columns,w=(o.categories,o.typeScale),O=o.imageScale,k=o.mobileStack,j=o.sectionHeader,_=o.showCaption,y=o.showCategory,v=o.specificMode,E=z()(c,(e={"is-grid":"grid"===f,"show-image":b},S()(e,"columns-".concat(d),"grid"===f),S()(e,"ts-".concat(w),"5"!==w),S()(e,"image-align".concat(g),b),S()(e,"is-".concat(O),"1"!==O&&b),S()(e,"mobile-stack",k),S()(e,"image-shape".concat(h),"landscape"!==h),S()(e,"has-text-color",""!==p.color),S()(e,"show-caption",_),S()(e,"show-category",y),S()(e,"wpnbha",!0),e)),C=[{icon:"list-view",title:Object(r.__)("List View","newspack-blocks"),onClick:function(){return a({postLayout:"list"})},isActive:"list"===f},{icon:"grid-view",title:Object(r.__)("Grid View","newspack-blocks"),onClick:function(){return a({postLayout:"grid"})},isActive:"grid"===f}],P=[{icon:"align-none",title:Object(r.__)("Show media on top","newspack-blocks"),isActive:"top"===g,onClick:function(){return a({mediaPosition:"top"})}},{icon:"align-pull-left",title:Object(r.__)("Show media on left","newspack-blocks"),isActive:"left"===g,onClick:function(){return a({mediaPosition:"left"})}},{icon:"align-pull-right",title:Object(r.__)("Show media on right","newspack-blocks"),isActive:"right"===g,onClick:function(){return a({mediaPosition:"right"})}},{icon:W,title:Object(r.__)("Show media behind","newspack-blocks"),isActive:"behind"===g,onClick:function(){return a({mediaPosition:"behind"})}}],x=[{icon:q,title:Object(r.__)("Landscape Image Shape","newspack-blocks"),isActive:"landscape"===h,onClick:function(){return a({imageShape:"landscape"})}},{icon:Q,title:Object(r.__)("portrait Image Shape","newspack-blocks"),isActive:"portrait"===h,onClick:function(){return a({imageShape:"portrait"})}},{icon:G,title:Object(r.__)("Square Image Shape","newspack-blocks"),isActive:"square"===h,onClick:function(){return a({imageShape:"square"})}},{icon:U,title:Object(r.__)("Uncropped","newspack-blocks"),isActive:"uncropped"===h,onClick:function(){return a({imageShape:"uncropped"})}}];return Object(i.createElement)(i.Fragment,null,Object(i.createElement)("div",{className:E,style:{color:p.color}},u&&(!B.RichText.isEmpty(j)||s)&&Object(i.createElement)(B.RichText,{onChange:function(e){return a({sectionHeader:e})},placeholder:Object(r.__)("Write header…","newspack-blocks"),value:j,tagName:"h2",className:"article-section-title"}),u&&!u.length&&Object(i.createElement)(l.Placeholder,null,Object(r.__)("Sorry, no posts were found.","newspack-blocks")),!u&&Object(i.createElement)(l.Placeholder,null,Object(i.createElement)(l.Spinner,null)),u&&u.map((function(e){return t.renderPost(e)}))),!v&&u&&m&&Object(i.createElement)("button",{className:"button",type:"button"},Object(r.__)("More…","newspack-blocks")),Object(i.createElement)(B.BlockControls,null,Object(i.createElement)(l.Toolbar,{controls:C}),b&&Object(i.createElement)(l.Toolbar,{controls:P}),b&&Object(i.createElement)(l.Toolbar,{controls:x})),Object(i.createElement)(B.InspectorControls,null,this.renderInspectorControls()))}}]),t}(i.Component),X=Object(R.compose)([Object(D.withColors)({textColor:"color"}),Object(L.withSelect)((function(e,t){var n=t.attributes,o=n.postsToShow,c=n.authors,a=n.categories,r=n.tags,s=n.specificPosts,i=n.specificMode,l=e("core");l.getAuthors;return{latestPosts:(0,l.getEntityRecords)("postType","post",Object(A.pickBy)(i&&s&&s.length?{include:s,orderby:"include"}:{per_page:o,categories:a,author:c,tags:r},(function(e){return!Object(A.isUndefined)(e)})))}}))])(J),Y=(n(31),n(32),n(18)),K=(Y.name,Y.attributes),Z=Y.category,$={title:Object(r.__)("Homepage Posts","newspack-blocks"),icon:Object(i.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"},Object(i.createElement)(l.Path,{d:"M0 0h24v24H0z",fill:"none"}),Object(i.createElement)(l.Path,{d:"M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H8V4h12v12zM10 9h8v2h-8zm0 3h4v2h-4zm0-6h8v2h-8z"})),attributes:K,category:Z,keywords:[Object(r.__)("posts","newspack-blocks"),Object(r.__)("articles","newspack-blocks"),Object(r.__)("latest","newspack-blocks")],description:Object(r.__)("A block for displaying homepage posts.","newspack-blocks"),styles:[{name:"default",label:Object(r._x)("Default","block style","newspack-blocks"),isDefault:!0},{name:"borders",label:Object(r._x)("Borders","block style","newspack-blocks")}],supports:{html:!1,align:["wide","full"],default:""},edit:X,save:function(){return null},transforms:{from:[{type:"block",blocks:["core/latest-posts"],transform:function(e){var t=e.displayPostContent,n=e.displayPostDate,o=e.postLayout,c=e.columns,r=e.postsToShow,i=e.categories;return Object(a.createBlock)(Object(s.applyFilters)("blocks.transforms_from_name","newspack-blocks/homepage-articles"),{showExcerpt:t,showDate:n,postLayout:o,columns:c,postsToShow:r,showAuthor:!1,categories:i?[i]:[]})}}],to:[{type:"block",blocks:["core/latest-posts"],transform:function(e){var t=e.showExcerpt,n=e.showDate,o=e.postLayout,c=e.columns,r=e.postsToShow,s=e.categories;return Object(a.createBlock)("core/latest-posts",{displayPostContent:t,displayPostDate:n,postLayout:o,columns:c,postsToShow:r,categories:s[0]||""})}}]}},ee="a8c/blog-posts";Object(s.addFilter)("blocks.transforms_from_name","set-transformed-block-name",(function(e){return"newspack-blocks/homepage-articles"!==e?e:ee})),Object(a.registerBlockType)(ee,c()({},$,{title:Object(r.__)("Blog Posts","full-site-editing"),category:"layout"}))}]));
blog-posts-block/dist/editor.js.LICENSE ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ /*!
2
+ Copyright (c) 2017 Jed Watson.
3
+ Licensed under the MIT License (MIT), see
4
+ http://jedwatson.github.io/classnames
5
+ */
blog-posts-block/dist/editor.rtl.css ADDED
@@ -0,0 +1 @@
 
1
+ .autocomplete-tokenfield{position:relative}.autocomplete-tokenfield .components-spinner{position:absolute;top:2em;left:0}.type-scale-slider .dashicon{height:16px;width:16px}.type-scale-slider input+.dashicon{height:24px;margin-right:10px;margin-left:0;width:24px}.wpnbha .editor-rich-text{width:100%}.wpnbha .cat-links{font-size:.7em}.wpnbha span.avatar{display:inline-block;margin-left:.5em}.wpnbha span.avatar div{display:inline}.wpnbha .excerpt-contain p{margin:.5em 0}.wpnbha{margin-bottom:1em}.wpnbha article{margin-bottom:1.5em;word-break:break-word;overflow-wrap:break-word;position:relative}.wpnbha article:last-of-type{margin-bottom:0}.wpnbha .article-section-title{font-size:.8em;margin-bottom:.5em;width:100%}.wpnbha.is-grid{display:flex;flex-wrap:wrap;justify-content:space-between;padding:0;list-style:none}.wpnbha.is-grid article{flex-basis:100%}@media only screen and (min-width:782px){.wpnbha.is-grid article,.wpnbha.is-grid article:last-child{margin-bottom:1em}}@media only screen and (min-width:600px){.wpnbha.columns-3 article,.wpnbha.columns-6 article{flex-basis:calc(33.333% - 16px)}.wpnbha.columns-2 article,.wpnbha.columns-4 article,.wpnbha.columns-5 article{flex-basis:calc(50% - 16px)}.wpnbha.columns-5 article:last-of-type:nth-child(odd){flex-grow:1}}@media only screen and (min-width:782px){.wpnbha.columns-2 article{flex-basis:calc(50% - 16px)}.wpnbha.columns-3 article{flex-basis:calc(33.33333% - 16px)}.wpnbha.columns-4 article{flex-basis:calc(25% - 16px)}.wpnbha.columns-5 article{flex-basis:calc(20% - 16px)}.wpnbha.columns-6 article{flex-basis:calc(16.66667% - 16px)}}.wpnbha .post-thumbnail{margin:0}.wpnbha .post-thumbnail img{height:auto;width:100%}.wpnbha figcaption{font-size:.6em}.wpnbha.image-aligntop .post-thumbnail{margin-bottom:.25em}.wpnbha.image-aligntop .post-thumbnail figcaption{margin-bottom:.5em}.wpnbha.image-alignleft .post-has-image,.wpnbha.image-alignright .post-has-image{display:flex}.wpnbha.image-alignleft .post-has-image .post-thumbnail,.wpnbha.image-alignright .post-has-image .post-thumbnail{flex-basis:33%}.wpnbha.image-alignleft .post-has-image .entry-wrapper,.wpnbha.image-alignright .post-has-image .entry-wrapper{flex-basis:67%}.wpnbha.image-alignleft.mobile-stack .post-has-image,.wpnbha.image-alignright.mobile-stack .post-has-image{display:block}@media only screen and (min-width:600px){.wpnbha.image-alignleft.mobile-stack .post-has-image,.wpnbha.image-alignright.mobile-stack .post-has-image{display:flex}.wpnbha.image-alignleft.is-4 .post-thumbnail,.wpnbha.image-alignright.is-4 .post-thumbnail{flex-basis:75%}.wpnbha.image-alignleft.is-4 .entry-wrapper,.wpnbha.image-alignright.is-4 .entry-wrapper{flex-basis:25%}.wpnbha.image-alignleft.is-3 .entry-wrapper,.wpnbha.image-alignleft.is-3 .post-thumbnail,.wpnbha.image-alignright.is-3 .entry-wrapper,.wpnbha.image-alignright.is-3 .post-thumbnail{flex-basis:50%}}.wpnbha.image-alignleft.is-1 .post-thumbnail,.wpnbha.image-alignright.is-1 .post-thumbnail{flex-basis:25%}.wpnbha.image-alignleft.is-1 .entry-wrapper,.wpnbha.image-alignright.is-1 .entry-wrapper{flex-basis:75%}.wpnbha.image-alignleft .post-thumbnail{margin-left:1em}.wpnbha.image-alignright .post-thumbnail{margin-right:1em}.wpnbha.image-alignright .entry-wrapper{order:-1}.wpnbha .entry-title{margin:0 0 .25em}.wpnbha .entry-title a{color:inherit;text-decoration:none}.wpnbha .cat-links{font-size:.6em;font-weight:700;margin:0 0 .5em}.wpnbha .cat-links a{text-decoration:none}.wpnbha .cat-links a:hover{text-decoration:underline}.wpnbha .entry-meta{display:flex;flex-wrap:wrap;align-items:center;margin-top:.5em}.wpnbha .entry-meta .byline:not(:last-child){margin-left:1.5em}.wpnbha .avatar{border-radius:100%;display:block;margin-left:.5em}.wpnbha p{margin:.5em 0}.wpnbha.has-text-color .article-section-title,.wpnbha.has-text-color .cat-links,.wpnbha.has-text-color .cat-links a,.wpnbha.has-text-color .cat-links a:visited,.wpnbha.has-text-color .entry-meta,.wpnbha.has-text-color .entry-meta .byline a,.wpnbha.has-text-color .entry-meta .byline a:visited,.wpnbha.has-text-color .entry-meta a,.wpnbha.has-text-color .entry-title,.wpnbha.has-text-color .entry-title a,.wpnbha.has-text-color .entry-title a:visited,.wpnbha.has-text-color figcaption{color:inherit}.wpnbha.has-text-color .entry-meta span:not(.avatar){opacity:.8}.wpnbha.image-alignbehind .post-has-image{display:flex;align-items:flex-end;position:relative}.wpnbha.image-alignbehind .post-has-image .post-thumbnail{bottom:0;right:0;overflow:hidden;position:absolute;left:0;top:0}.wpnbha.image-alignbehind .post-has-image .post-thumbnail img{height:100%;-o-object-fit:cover;object-fit:cover;max-width:1000%;width:100%}.wpnbha.image-alignbehind .post-has-image .post-thumbnail figcaption{bottom:1em;-webkit-box-orient:vertical;color:hsla(0,0%,100%,.9);display:-webkit-box;font-style:italic;right:0;-webkit-line-clamp:1;margin:0;max-height:1.6em;overflow:hidden;padding:0 1em;position:absolute;left:0;text-align:left;text-overflow:ellipsis;z-index:2}.wpnbha.image-alignbehind .post-has-image .post-thumbnail:after{background:rgba(0,0,0,.5);bottom:0;content:"";right:0;position:absolute;left:0;top:0;z-index:1}.wpnbha.image-alignbehind .post-has-image .entry-wrapper{padding:2em;position:relative;z-index:2}.wpnbha.image-alignbehind .post-has-image .cat-links a,.wpnbha.image-alignbehind .post-has-image .entry-meta,.wpnbha.image-alignbehind .post-has-image .entry-meta .byline a,.wpnbha.image-alignbehind .post-has-image .entry-title a,.wpnbha.image-alignbehind .post-has-image .entry-wrapper{color:#fff}.wpnbha article .entry-title{font-size:1.2em}.wpnbha article .entry-meta{font-size:.8em}.wpnbha article .avatar{height:25px;width:25px}@media only screen and (min-width:782px){.wpnbha article .entry-title{font-size:1.6em}.wpnbha article .avatar{height:40px;width:40px}}.wpnbha.ts-8 .entry-title,.wpnbha.ts-9 .entry-title,.wpnbha.ts-10 .entry-title{line-height:1.1em}@media only screen and (min-width:782px){.wpnbha.ts-8 article .avatar,.wpnbha.ts-9 article .avatar,.wpnbha.ts-10 article .avatar{height:2.4em;width:2.4em}}.wpnbha.ts-10 article .entry-title{font-size:2.6em}@media only screen and (min-width:782px){.wpnbha.ts-10 article .entry-title{font-size:3.6em}}@media only screen and (min-width:1168px){.wpnbha.ts-10 article .entry-title{font-size:4.8em}}.wpnbha.ts-9 article .entry-title{font-size:2.4em}@media only screen and (min-width:782px){.wpnbha.ts-9 article .entry-title{font-size:3.4em}}@media only screen and (min-width:1168px){.wpnbha.ts-9 article .entry-title{font-size:4.2em}}.wpnbha.ts-8 article .entry-title{font-size:2.2em}@media only screen and (min-width:782px){.wpnbha.ts-8 article .entry-title{font-size:3em}}@media only screen and (min-width:1168px){.wpnbha.ts-8 article .entry-title{font-size:3.6em}}.wpnbha.ts-7 article .entry-title{font-size:2em}@media only screen and (min-width:782px){.wpnbha.ts-7 article .entry-title{font-size:2.4em}.wpnbha.ts-7 article .avatar{height:48px;width:48px}}@media only screen and (min-width:1168px){.wpnbha.ts-7 article .entry-title{font-size:3em}}.wpnbha.ts-6 article .entry-title{font-size:1.7em}@media only screen and (min-width:782px){.wpnbha.ts-6 article .entry-title{font-size:2em}.wpnbha.ts-6 article .avatar{height:44px;width:44px}}@media only screen and (min-width:1168px){.wpnbha.ts-6 article .entry-title{font-size:2.4em}}.wpnbha.ts-5 article .entry-title{font-size:1.4em}@media only screen and (min-width:782px){.wpnbha.ts-5 article .entry-title{font-size:1.8em}.wpnbha.ts-5 article .avatar{height:40px;width:40px}}@media only screen and (min-width:1168px){.wpnbha.ts-5 article .entry-title{font-size:2em}}.wpnbha.ts-3 article .entry-title{font-size:1em}.wpnbha.ts-3 article .entry-wrapper p{font-size:.8em}.wpnbha.ts-3 article .entry-meta{font-size:.7em}@media only screen and (min-width:782px){.wpnbha.ts-3 article .entry-title{font-size:1.2em}.wpnbha.ts-3 article .avatar{height:32px;width:32px}}.wpnbha.ts-2 article .entry-title{font-size:.8em}.wpnbha.ts-2 article .entry-meta,.wpnbha.ts-2 article .entry-wrapper p{font-size:.7em}@media only screen and (min-width:782px){.wpnbha.ts-2 article .entry-title{font-size:.9em}.wpnbha.ts-2 article .avatar{height:28px;width:28px}}.wpnbha.ts-1 article .entry-title,.wpnbha.ts-1 article .entry-wrapper p{font-size:.7em}.wpnbha.ts-1 article .entry-meta{font-size:.6em}@media only screen and (min-width:782px){.wpnbha.ts-1 article .avatar{height:24px;width:24px}}.wpnbha.is-style-borders article{border:solid rgba(0,0,0,.2);border-width:0 0 1px;margin-bottom:1em;padding-bottom:1em}.wpnbha.is-style-borders article:last-of-type{margin-bottom:0}.wpnbha.is-style-borders article:last-of-type:not(:first-of-type){border-bottom:0}@media only screen and (min-width:782px){.wpnbha.is-style-borders.columns-2 article{padding-left:32px}.wpnbha.is-style-borders.columns-3 article{padding-left:24px}.wpnbha.is-style-borders.columns-4 article{padding-left:21.33333px}.wpnbha.is-style-borders.columns-5 article{padding-left:20px}.wpnbha.is-style-borders.columns-6 article{padding-left:19.2px}.wpnbha.is-style-borders.is-grid article{border-width:0 0 0 1px}.wpnbha.is-style-borders.columns-1 article,.wpnbha.is-style-borders.columns-2 article:nth-of-type(2n),.wpnbha.is-style-borders.columns-3 article:nth-of-type(3n),.wpnbha.is-style-borders.columns-4 article:nth-of-type(4n),.wpnbha.is-style-borders.columns-5 article:nth-of-type(5n),.wpnbha.is-style-borders.columns-6 article:nth-of-type(6n),.wpnbha.is-style-borders.is-grid article:last-of-type{border:0}}
blog-posts-block/dist/view.asset.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php return array('dependencies' => array('wp-polyfill'), 'version' => 'dcb5e643cfdcb1de98dea3b5275c9687');
blog-posts-block/dist/view.css ADDED
@@ -0,0 +1 @@
 
1
+ .wpnbha{margin-bottom:1em}.wpnbha article{margin-bottom:1.5em;word-break:break-word;overflow-wrap:break-word;position:relative}.wpnbha article:last-of-type{margin-bottom:0}.wpnbha .article-section-title{font-size:.8em;margin-bottom:.5em;width:100%}.wpnbha.is-grid{display:flex;flex-wrap:wrap;justify-content:space-between;padding:0;list-style:none}.wpnbha.is-grid article{flex-basis:100%}@media only screen and (min-width:782px){.wpnbha.is-grid article,.wpnbha.is-grid article:last-child{margin-bottom:1em}}@media only screen and (min-width:600px){.wpnbha.columns-3 article,.wpnbha.columns-6 article{flex-basis:calc(33.333% - 16px)}.wpnbha.columns-2 article,.wpnbha.columns-4 article,.wpnbha.columns-5 article{flex-basis:calc(50% - 16px)}.wpnbha.columns-5 article:last-of-type:nth-child(odd){flex-grow:1}}@media only screen and (min-width:782px){.wpnbha.columns-2 article{flex-basis:calc(50% - 16px)}.wpnbha.columns-3 article{flex-basis:calc(33.33333% - 16px)}.wpnbha.columns-4 article{flex-basis:calc(25% - 16px)}.wpnbha.columns-5 article{flex-basis:calc(20% - 16px)}.wpnbha.columns-6 article{flex-basis:calc(16.66667% - 16px)}}.wpnbha .post-thumbnail{margin:0}.wpnbha .post-thumbnail img{height:auto;width:100%}.wpnbha figcaption{font-size:.6em}.wpnbha.image-aligntop .post-thumbnail{margin-bottom:.25em}.wpnbha.image-aligntop .post-thumbnail figcaption{margin-bottom:.5em}.wpnbha.image-alignleft .post-has-image,.wpnbha.image-alignright .post-has-image{display:flex}.wpnbha.image-alignleft .post-has-image .post-thumbnail,.wpnbha.image-alignright .post-has-image .post-thumbnail{flex-basis:33%}.wpnbha.image-alignleft .post-has-image .entry-wrapper,.wpnbha.image-alignright .post-has-image .entry-wrapper{flex-basis:67%}.wpnbha.image-alignleft.mobile-stack .post-has-image,.wpnbha.image-alignright.mobile-stack .post-has-image{display:block}@media only screen and (min-width:600px){.wpnbha.image-alignleft.mobile-stack .post-has-image,.wpnbha.image-alignright.mobile-stack .post-has-image{display:flex}.wpnbha.image-alignleft.is-4 .post-thumbnail,.wpnbha.image-alignright.is-4 .post-thumbnail{flex-basis:75%}.wpnbha.image-alignleft.is-4 .entry-wrapper,.wpnbha.image-alignright.is-4 .entry-wrapper{flex-basis:25%}.wpnbha.image-alignleft.is-3 .entry-wrapper,.wpnbha.image-alignleft.is-3 .post-thumbnail,.wpnbha.image-alignright.is-3 .entry-wrapper,.wpnbha.image-alignright.is-3 .post-thumbnail{flex-basis:50%}}.wpnbha.image-alignleft.is-1 .post-thumbnail,.wpnbha.image-alignright.is-1 .post-thumbnail{flex-basis:25%}.wpnbha.image-alignleft.is-1 .entry-wrapper,.wpnbha.image-alignright.is-1 .entry-wrapper{flex-basis:75%}.wpnbha.image-alignleft .post-thumbnail{margin-right:1em}.wpnbha.image-alignright .post-thumbnail{margin-left:1em}.wpnbha.image-alignright .entry-wrapper{order:-1}.wpnbha .entry-title{margin:0 0 .25em}.wpnbha .entry-title a{color:inherit;text-decoration:none}.wpnbha .cat-links{font-size:.6em;font-weight:700;margin:0 0 .5em}.wpnbha .cat-links a{text-decoration:none}.wpnbha .cat-links a:hover{text-decoration:underline}.wpnbha .entry-meta{display:flex;flex-wrap:wrap;align-items:center;margin-top:.5em}.wpnbha .entry-meta .byline:not(:last-child){margin-right:1.5em}.wpnbha .avatar{border-radius:100%;display:block;margin-right:.5em}.wpnbha p{margin:.5em 0}.wpnbha.has-text-color .article-section-title,.wpnbha.has-text-color .cat-links,.wpnbha.has-text-color .cat-links a,.wpnbha.has-text-color .cat-links a:visited,.wpnbha.has-text-color .entry-meta,.wpnbha.has-text-color .entry-meta .byline a,.wpnbha.has-text-color .entry-meta .byline a:visited,.wpnbha.has-text-color .entry-meta a,.wpnbha.has-text-color .entry-title,.wpnbha.has-text-color .entry-title a,.wpnbha.has-text-color .entry-title a:visited,.wpnbha.has-text-color figcaption{color:inherit}.wpnbha.has-text-color .entry-meta span:not(.avatar){opacity:.8}.wpnbha.image-alignbehind .post-has-image{display:flex;align-items:flex-end;position:relative}.wpnbha.image-alignbehind .post-has-image .post-thumbnail{bottom:0;left:0;overflow:hidden;position:absolute;right:0;top:0}.wpnbha.image-alignbehind .post-has-image .post-thumbnail img{height:100%;-o-object-fit:cover;object-fit:cover;max-width:1000%;width:100%}.wpnbha.image-alignbehind .post-has-image .post-thumbnail figcaption{bottom:1em;-webkit-box-orient:vertical;color:hsla(0,0%,100%,.9);display:-webkit-box;font-style:italic;left:0;-webkit-line-clamp:1;margin:0;max-height:1.6em;overflow:hidden;padding:0 1em;position:absolute;right:0;text-align:right;text-overflow:ellipsis;z-index:2}.wpnbha.image-alignbehind .post-has-image .post-thumbnail:after{background:rgba(0,0,0,.5);bottom:0;content:"";left:0;position:absolute;right:0;top:0;z-index:1}.wpnbha.image-alignbehind .post-has-image .entry-wrapper{padding:2em;position:relative;z-index:2}.wpnbha.image-alignbehind .post-has-image .cat-links a,.wpnbha.image-alignbehind .post-has-image .entry-meta,.wpnbha.image-alignbehind .post-has-image .entry-meta .byline a,.wpnbha.image-alignbehind .post-has-image .entry-title a,.wpnbha.image-alignbehind .post-has-image .entry-wrapper{color:#fff}.wpnbha article .entry-title{font-size:1.2em}.wpnbha article .entry-meta{font-size:.8em}.wpnbha article .avatar{height:25px;width:25px}@media only screen and (min-width:782px){.wpnbha article .entry-title{font-size:1.6em}.wpnbha article .avatar{height:40px;width:40px}}.wpnbha.ts-8 .entry-title,.wpnbha.ts-9 .entry-title,.wpnbha.ts-10 .entry-title{line-height:1.1em}@media only screen and (min-width:782px){.wpnbha.ts-8 article .avatar,.wpnbha.ts-9 article .avatar,.wpnbha.ts-10 article .avatar{height:2.4em;width:2.4em}}.wpnbha.ts-10 article .entry-title{font-size:2.6em}@media only screen and (min-width:782px){.wpnbha.ts-10 article .entry-title{font-size:3.6em}}@media only screen and (min-width:1168px){.wpnbha.ts-10 article .entry-title{font-size:4.8em}}.wpnbha.ts-9 article .entry-title{font-size:2.4em}@media only screen and (min-width:782px){.wpnbha.ts-9 article .entry-title{font-size:3.4em}}@media only screen and (min-width:1168px){.wpnbha.ts-9 article .entry-title{font-size:4.2em}}.wpnbha.ts-8 article .entry-title{font-size:2.2em}@media only screen and (min-width:782px){.wpnbha.ts-8 article .entry-title{font-size:3em}}@media only screen and (min-width:1168px){.wpnbha.ts-8 article .entry-title{font-size:3.6em}}.wpnbha.ts-7 article .entry-title{font-size:2em}@media only screen and (min-width:782px){.wpnbha.ts-7 article .entry-title{font-size:2.4em}.wpnbha.ts-7 article .avatar{height:48px;width:48px}}@media only screen and (min-width:1168px){.wpnbha.ts-7 article .entry-title{font-size:3em}}.wpnbha.ts-6 article .entry-title{font-size:1.7em}@media only screen and (min-width:782px){.wpnbha.ts-6 article .entry-title{font-size:2em}.wpnbha.ts-6 article .avatar{height:44px;width:44px}}@media only screen and (min-width:1168px){.wpnbha.ts-6 article .entry-title{font-size:2.4em}}.wpnbha.ts-5 article .entry-title{font-size:1.4em}@media only screen and (min-width:782px){.wpnbha.ts-5 article .entry-title{font-size:1.8em}.wpnbha.ts-5 article .avatar{height:40px;width:40px}}@media only screen and (min-width:1168px){.wpnbha.ts-5 article .entry-title{font-size:2em}}.wpnbha.ts-3 article .entry-title{font-size:1em}.wpnbha.ts-3 article .entry-wrapper p{font-size:.8em}.wpnbha.ts-3 article .entry-meta{font-size:.7em}@media only screen and (min-width:782px){.wpnbha.ts-3 article .entry-title{font-size:1.2em}.wpnbha.ts-3 article .avatar{height:32px;width:32px}}.wpnbha.ts-2 article .entry-title{font-size:.8em}.wpnbha.ts-2 article .entry-meta,.wpnbha.ts-2 article .entry-wrapper p{font-size:.7em}@media only screen and (min-width:782px){.wpnbha.ts-2 article .entry-title{font-size:.9em}.wpnbha.ts-2 article .avatar{height:28px;width:28px}}.wpnbha.ts-1 article .entry-title,.wpnbha.ts-1 article .entry-wrapper p{font-size:.7em}.wpnbha.ts-1 article .entry-meta{font-size:.6em}@media only screen and (min-width:782px){.wpnbha.ts-1 article .avatar{height:24px;width:24px}}.wpnbha.is-style-borders article{border:solid rgba(0,0,0,.2);border-width:0 0 1px;margin-bottom:1em;padding-bottom:1em}.wpnbha.is-style-borders article:last-of-type{margin-bottom:0}.wpnbha.is-style-borders article:last-of-type:not(:first-of-type){border-bottom:0}@media only screen and (min-width:782px){.wpnbha.is-style-borders.columns-2 article{padding-right:32px}.wpnbha.is-style-borders.columns-3 article{padding-right:24px}.wpnbha.is-style-borders.columns-4 article{padding-right:21.33333px}.wpnbha.is-style-borders.columns-5 article{padding-right:20px}.wpnbha.is-style-borders.columns-6 article{padding-right:19.2px}.wpnbha.is-style-borders.is-grid article{border-width:0 1px 0 0}.wpnbha.is-style-borders.columns-1 article,.wpnbha.is-style-borders.columns-2 article:nth-of-type(2n),.wpnbha.is-style-borders.columns-3 article:nth-of-type(3n),.wpnbha.is-style-borders.columns-4 article:nth-of-type(4n),.wpnbha.is-style-borders.columns-5 article:nth-of-type(5n),.wpnbha.is-style-borders.columns-6 article:nth-of-type(6n),.wpnbha.is-style-borders.is-grid article:last-of-type{border:0}}
blog-posts-block/dist/view.js ADDED
@@ -0,0 +1 @@
 
1
+ !function(t,e){for(var r in e)t[r]=e[r]}(window,function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(t,e,r){},function(t,e,r){"use strict";r.r(e);r(0);var n="data-load-more-url",o=3;function u(t){t.style.display="none",t.setAttribute("hidden","")}function i(t){t.style.display="",t.removeAttribute("hidden")}function a(t,e){return Object.prototype.hasOwnProperty.call(t,e)}document.querySelectorAll("[data-load-more-btn]").forEach((function(t){if(!t)return null;var e=function(t){var e=t.parentElement,r=e.querySelector("[data-posts-container]"),c=e.querySelector("[data-load-more-loading-text]"),l=e.querySelector("[data-load-more-error-text]"),f=!1,s=!1;return function(){if(f||s)return!1;f=!0,u(t),u(l),i(c);!function t(e,r){var n=new XMLHttpRequest;n.onreadystatechange=function(){if(4===n.readyState){if(n.status>=200&&n.status<300){var o=JSON.parse(n.responseText);return e.onSuccess(o)}return r?t(e,r-1):e.onError()}},n.open("GET",e.url),n.send()}({url:t.getAttribute(n),onSuccess:function(e){if(function(t){if(t&&a(t,"items")&&a(t,"next")&&Array.isArray(t.items)&&t.items.length&&a(t.items[0],"html")&&"string"==typeof t.items[0].html)return!0;return!1}(e)){var o=e.items.map((function(t){return t.html})).join("");r.insertAdjacentHTML("beforeend",o),e.next?(t.setAttribute(n,e.next),i(t)):s=!0,f=!1,u(c)}},onError:function(){f=!1,u(c),i(l),i(t)}},o)}}(t);t.addEventListener("click",e)}))}]));
blog-posts-block/dist/view.rtl.css ADDED
@@ -0,0 +1 @@
 
1
+ .wpnbha{margin-bottom:1em}.wpnbha article{margin-bottom:1.5em;word-break:break-word;overflow-wrap:break-word;position:relative}.wpnbha article:last-of-type{margin-bottom:0}.wpnbha .article-section-title{font-size:.8em;margin-bottom:.5em;width:100%}.wpnbha.is-grid{display:flex;flex-wrap:wrap;justify-content:space-between;padding:0;list-style:none}.wpnbha.is-grid article{flex-basis:100%}@media only screen and (min-width:782px){.wpnbha.is-grid article,.wpnbha.is-grid article:last-child{margin-bottom:1em}}@media only screen and (min-width:600px){.wpnbha.columns-3 article,.wpnbha.columns-6 article{flex-basis:calc(33.333% - 16px)}.wpnbha.columns-2 article,.wpnbha.columns-4 article,.wpnbha.columns-5 article{flex-basis:calc(50% - 16px)}.wpnbha.columns-5 article:last-of-type:nth-child(odd){flex-grow:1}}@media only screen and (min-width:782px){.wpnbha.columns-2 article{flex-basis:calc(50% - 16px)}.wpnbha.columns-3 article{flex-basis:calc(33.33333% - 16px)}.wpnbha.columns-4 article{flex-basis:calc(25% - 16px)}.wpnbha.columns-5 article{flex-basis:calc(20% - 16px)}.wpnbha.columns-6 article{flex-basis:calc(16.66667% - 16px)}}.wpnbha .post-thumbnail{margin:0}.wpnbha .post-thumbnail img{height:auto;width:100%}.wpnbha figcaption{font-size:.6em}.wpnbha.image-aligntop .post-thumbnail{margin-bottom:.25em}.wpnbha.image-aligntop .post-thumbnail figcaption{margin-bottom:.5em}.wpnbha.image-alignleft .post-has-image,.wpnbha.image-alignright .post-has-image{display:flex}.wpnbha.image-alignleft .post-has-image .post-thumbnail,.wpnbha.image-alignright .post-has-image .post-thumbnail{flex-basis:33%}.wpnbha.image-alignleft .post-has-image .entry-wrapper,.wpnbha.image-alignright .post-has-image .entry-wrapper{flex-basis:67%}.wpnbha.image-alignleft.mobile-stack .post-has-image,.wpnbha.image-alignright.mobile-stack .post-has-image{display:block}@media only screen and (min-width:600px){.wpnbha.image-alignleft.mobile-stack .post-has-image,.wpnbha.image-alignright.mobile-stack .post-has-image{display:flex}.wpnbha.image-alignleft.is-4 .post-thumbnail,.wpnbha.image-alignright.is-4 .post-thumbnail{flex-basis:75%}.wpnbha.image-alignleft.is-4 .entry-wrapper,.wpnbha.image-alignright.is-4 .entry-wrapper{flex-basis:25%}.wpnbha.image-alignleft.is-3 .entry-wrapper,.wpnbha.image-alignleft.is-3 .post-thumbnail,.wpnbha.image-alignright.is-3 .entry-wrapper,.wpnbha.image-alignright.is-3 .post-thumbnail{flex-basis:50%}}.wpnbha.image-alignleft.is-1 .post-thumbnail,.wpnbha.image-alignright.is-1 .post-thumbnail{flex-basis:25%}.wpnbha.image-alignleft.is-1 .entry-wrapper,.wpnbha.image-alignright.is-1 .entry-wrapper{flex-basis:75%}.wpnbha.image-alignleft .post-thumbnail{margin-left:1em}.wpnbha.image-alignright .post-thumbnail{margin-right:1em}.wpnbha.image-alignright .entry-wrapper{order:-1}.wpnbha .entry-title{margin:0 0 .25em}.wpnbha .entry-title a{color:inherit;text-decoration:none}.wpnbha .cat-links{font-size:.6em;font-weight:700;margin:0 0 .5em}.wpnbha .cat-links a{text-decoration:none}.wpnbha .cat-links a:hover{text-decoration:underline}.wpnbha .entry-meta{display:flex;flex-wrap:wrap;align-items:center;margin-top:.5em}.wpnbha .entry-meta .byline:not(:last-child){margin-left:1.5em}.wpnbha .avatar{border-radius:100%;display:block;margin-left:.5em}.wpnbha p{margin:.5em 0}.wpnbha.has-text-color .article-section-title,.wpnbha.has-text-color .cat-links,.wpnbha.has-text-color .cat-links a,.wpnbha.has-text-color .cat-links a:visited,.wpnbha.has-text-color .entry-meta,.wpnbha.has-text-color .entry-meta .byline a,.wpnbha.has-text-color .entry-meta .byline a:visited,.wpnbha.has-text-color .entry-meta a,.wpnbha.has-text-color .entry-title,.wpnbha.has-text-color .entry-title a,.wpnbha.has-text-color .entry-title a:visited,.wpnbha.has-text-color figcaption{color:inherit}.wpnbha.has-text-color .entry-meta span:not(.avatar){opacity:.8}.wpnbha.image-alignbehind .post-has-image{display:flex;align-items:flex-end;position:relative}.wpnbha.image-alignbehind .post-has-image .post-thumbnail{bottom:0;right:0;overflow:hidden;position:absolute;left:0;top:0}.wpnbha.image-alignbehind .post-has-image .post-thumbnail img{height:100%;-o-object-fit:cover;object-fit:cover;max-width:1000%;width:100%}.wpnbha.image-alignbehind .post-has-image .post-thumbnail figcaption{bottom:1em;-webkit-box-orient:vertical;color:hsla(0,0%,100%,.9);display:-webkit-box;font-style:italic;right:0;-webkit-line-clamp:1;margin:0;max-height:1.6em;overflow:hidden;padding:0 1em;position:absolute;left:0;text-align:left;text-overflow:ellipsis;z-index:2}.wpnbha.image-alignbehind .post-has-image .post-thumbnail:after{background:rgba(0,0,0,.5);bottom:0;content:"";right:0;position:absolute;left:0;top:0;z-index:1}.wpnbha.image-alignbehind .post-has-image .entry-wrapper{padding:2em;position:relative;z-index:2}.wpnbha.image-alignbehind .post-has-image .cat-links a,.wpnbha.image-alignbehind .post-has-image .entry-meta,.wpnbha.image-alignbehind .post-has-image .entry-meta .byline a,.wpnbha.image-alignbehind .post-has-image .entry-title a,.wpnbha.image-alignbehind .post-has-image .entry-wrapper{color:#fff}.wpnbha article .entry-title{font-size:1.2em}.wpnbha article .entry-meta{font-size:.8em}.wpnbha article .avatar{height:25px;width:25px}@media only screen and (min-width:782px){.wpnbha article .entry-title{font-size:1.6em}.wpnbha article .avatar{height:40px;width:40px}}.wpnbha.ts-8 .entry-title,.wpnbha.ts-9 .entry-title,.wpnbha.ts-10 .entry-title{line-height:1.1em}@media only screen and (min-width:782px){.wpnbha.ts-8 article .avatar,.wpnbha.ts-9 article .avatar,.wpnbha.ts-10 article .avatar{height:2.4em;width:2.4em}}.wpnbha.ts-10 article .entry-title{font-size:2.6em}@media only screen and (min-width:782px){.wpnbha.ts-10 article .entry-title{font-size:3.6em}}@media only screen and (min-width:1168px){.wpnbha.ts-10 article .entry-title{font-size:4.8em}}.wpnbha.ts-9 article .entry-title{font-size:2.4em}@media only screen and (min-width:782px){.wpnbha.ts-9 article .entry-title{font-size:3.4em}}@media only screen and (min-width:1168px){.wpnbha.ts-9 article .entry-title{font-size:4.2em}}.wpnbha.ts-8 article .entry-title{font-size:2.2em}@media only screen and (min-width:782px){.wpnbha.ts-8 article .entry-title{font-size:3em}}@media only screen and (min-width:1168px){.wpnbha.ts-8 article .entry-title{font-size:3.6em}}.wpnbha.ts-7 article .entry-title{font-size:2em}@media only screen and (min-width:782px){.wpnbha.ts-7 article .entry-title{font-size:2.4em}.wpnbha.ts-7 article .avatar{height:48px;width:48px}}@media only screen and (min-width:1168px){.wpnbha.ts-7 article .entry-title{font-size:3em}}.wpnbha.ts-6 article .entry-title{font-size:1.7em}@media only screen and (min-width:782px){.wpnbha.ts-6 article .entry-title{font-size:2em}.wpnbha.ts-6 article .avatar{height:44px;width:44px}}@media only screen and (min-width:1168px){.wpnbha.ts-6 article .entry-title{font-size:2.4em}}.wpnbha.ts-5 article .entry-title{font-size:1.4em}@media only screen and (min-width:782px){.wpnbha.ts-5 article .entry-title{font-size:1.8em}.wpnbha.ts-5 article .avatar{height:40px;width:40px}}@media only screen and (min-width:1168px){.wpnbha.ts-5 article .entry-title{font-size:2em}}.wpnbha.ts-3 article .entry-title{font-size:1em}.wpnbha.ts-3 article .entry-wrapper p{font-size:.8em}.wpnbha.ts-3 article .entry-meta{font-size:.7em}@media only screen and (min-width:782px){.wpnbha.ts-3 article .entry-title{font-size:1.2em}.wpnbha.ts-3 article .avatar{height:32px;width:32px}}.wpnbha.ts-2 article .entry-title{font-size:.8em}.wpnbha.ts-2 article .entry-meta,.wpnbha.ts-2 article .entry-wrapper p{font-size:.7em}@media only screen and (min-width:782px){.wpnbha.ts-2 article .entry-title{font-size:.9em}.wpnbha.ts-2 article .avatar{height:28px;width:28px}}.wpnbha.ts-1 article .entry-title,.wpnbha.ts-1 article .entry-wrapper p{font-size:.7em}.wpnbha.ts-1 article .entry-meta{font-size:.6em}@media only screen and (min-width:782px){.wpnbha.ts-1 article .avatar{height:24px;width:24px}}.wpnbha.is-style-borders article{border:solid rgba(0,0,0,.2);border-width:0 0 1px;margin-bottom:1em;padding-bottom:1em}.wpnbha.is-style-borders article:last-of-type{margin-bottom:0}.wpnbha.is-style-borders article:last-of-type:not(:first-of-type){border-bottom:0}@media only screen and (min-width:782px){.wpnbha.is-style-borders.columns-2 article{padding-left:32px}.wpnbha.is-style-borders.columns-3 article{padding-left:24px}.wpnbha.is-style-borders.columns-4 article{padding-left:21.33333px}.wpnbha.is-style-borders.columns-5 article{padding-left:20px}.wpnbha.is-style-borders.columns-6 article{padding-left:19.2px}.wpnbha.is-style-borders.is-grid article{border-width:0 0 0 1px}.wpnbha.is-style-borders.columns-1 article,.wpnbha.is-style-borders.columns-2 article:nth-of-type(2n),.wpnbha.is-style-borders.columns-3 article:nth-of-type(3n),.wpnbha.is-style-borders.columns-4 article:nth-of-type(4n),.wpnbha.is-style-borders.columns-5 article:nth-of-type(5n),.wpnbha.is-style-borders.columns-6 article:nth-of-type(6n),.wpnbha.is-style-borders.is-grid article:last-of-type{border:0}}
blog-posts-block/editor.js ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* eslint-disable import/no-extraneous-dependencies */
2
+ /**
3
+ * Internal dependencies
4
+ */
5
+ import { registerBlockType } from '@wordpress/blocks';
6
+ import { __ } from '@wordpress/i18n';
7
+ import { addFilter } from '@wordpress/hooks';
8
+ /* eslint-enable import/no-extraneous-dependencies */
9
+
10
+ /**
11
+ * NHA dependencies
12
+ */
13
+ import { settings } from './newspack-homepage-articles/blocks/homepage-articles/index';
14
+
15
+ /**
16
+ * Block name in the A8C\FSE context.
17
+ */
18
+ const blockName = 'a8c/blog-posts';
19
+
20
+ function setBlockTransformationName( name ) {
21
+ return name !== 'newspack-blocks/homepage-articles' ? name : blockName;
22
+ }
23
+
24
+ addFilter(
25
+ 'blocks.transforms_from_name',
26
+ 'set-transformed-block-name',
27
+ setBlockTransformationName
28
+ );
29
+
30
+ registerBlockType( blockName, {
31
+ ...settings,
32
+ title: __( 'Blog Posts', 'full-site-editing' ),
33
+ category: 'layout',
34
+ } );
blog-posts-block/index.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Blog posts file.
4
+ *
5
+ * @package A8C\FSE
6
+ */
7
+
8
+ namespace A8C\FSE;
9
+
10
+ define( 'NEWSPACK_BLOCKS__BLOCKS_DIRECTORY', 'dist/' );
11
+ define( 'NEWSPACK_BLOCKS__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
12
+ define( 'NEWSPACK_BLOCKS__VERSION', '1.0.0-alpha.18' );
13
+
14
+ /**
15
+ * Filters block name.
16
+ *
17
+ * @param string $name Block name.
18
+ * @return string
19
+ */
20
+ function blog_posts_block_name( $name ) {
21
+ if ( 'newspack-blocks/homepage-articles' === $name ) {
22
+ return 'a8c/blog-posts';
23
+ }
24
+ return $name;
25
+ }
26
+ add_filter( 'newspack_blocks_block_name', __NAMESPACE__ . '\blog_posts_block_name' );
27
+
28
+ /**
29
+ * Filters block arguments for `register_block_type()`.
30
+ *
31
+ * @param array $args Arguments to `register_block_type()`.
32
+ * @param string $name Block name.
33
+ * @return array
34
+ */
35
+ function blog_posts_block_args( $args, $name ) {
36
+ if ( 'homepage-articles' !== $name ) {
37
+ return $args;
38
+ }
39
+
40
+ // Editor script.
41
+ $script_data = require NEWSPACK_BLOCKS__BLOCKS_DIRECTORY . 'editor.asset.php';
42
+ wp_register_script(
43
+ 'blog-posts-block-editor',
44
+ plugins_url( NEWSPACK_BLOCKS__BLOCKS_DIRECTORY . 'editor.js', __FILE__ ),
45
+ $script_data['dependencies'],
46
+ $script_data['version'],
47
+ true
48
+ );
49
+
50
+ // Editor style.
51
+ $editor_style = plugins_url( NEWSPACK_BLOCKS__BLOCKS_DIRECTORY . 'editor.css', __FILE__ );
52
+ wp_register_style( 'blog-posts-block-editor', $editor_style, array(), NEWSPACK_BLOCKS__VERSION );
53
+
54
+ // View script.
55
+ $script_data = require NEWSPACK_BLOCKS__BLOCKS_DIRECTORY . 'view.asset.php';
56
+ wp_register_script(
57
+ 'blog-posts-block-view',
58
+ plugins_url( NEWSPACK_BLOCKS__BLOCKS_DIRECTORY . 'view.js', __FILE__ ),
59
+ $script_data['dependencies'],
60
+ $script_data['version'],
61
+ true
62
+ );
63
+
64
+ // View style.
65
+ $editor_style = plugins_url( NEWSPACK_BLOCKS__BLOCKS_DIRECTORY . 'view.css', __FILE__ );
66
+ wp_register_style( 'blog-posts-block-view', $editor_style, array(), NEWSPACK_BLOCKS__VERSION );
67
+
68
+ $args['editor_script'] = 'blog-posts-block-editor';
69
+ $args['editor_style'] = 'blog-posts-block-editor';
70
+ $args['script'] = 'blog-posts-block-view';
71
+ $args['style'] = 'blog-posts-block-view';
72
+
73
+ return $args;
74
+ }
75
+ add_filter( 'newspack_blocks_block_args', __NAMESPACE__ . '\blog_posts_block_args', 10, 2 );
76
+
77
+ require_once __DIR__ . '/newspack-homepage-articles/class-newspack-blocks.php';
78
+ require_once __DIR__ . '/newspack-homepage-articles/class-newspack-blocks-api.php';
79
+
80
+ require_once __DIR__ . '/newspack-homepage-articles/blocks/homepage-articles/view.php';
81
+
82
+ // REST Controller for Articles Block.
83
+ require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'newspack-homepage-articles/blocks/homepage-articles/class-wp-rest-newspack-articles-controller.php';
84
+
85
+ /**
86
+ * Registers Articles block routes.
87
+ */
88
+ function register_rest_routes() {
89
+ $articles_controller = new \WP_REST_Newspack_Articles_Controller();
90
+ $articles_controller->register_routes();
91
+ }
92
+ add_action( 'rest_api_init', __NAMESPACE__ . '\register_rest_routes' );
blog-posts-block/newspack-homepage-articles/README.md ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ # Newspack Homepage Articles
2
+
3
+ This folder is synchronized from [Newspack Blocks repository](https://github.com/automattic/newspack-blocks) where the original code lives.
4
+
5
+ Please don't make any changes to these files directly but rather open a PR in the original repository and once landed there, use the sync script.
blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/block.json ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "homepage-articles",
3
+ "category": "newspack",
4
+ "attributes": {
5
+ "className": {
6
+ "type": "string",
7
+ "default": ""
8
+ },
9
+ "showExcerpt": {
10
+ "type": "boolean",
11
+ "default": true
12
+ },
13
+ "showDate": {
14
+ "type": "boolean",
15
+ "default": true
16
+ },
17
+ "showImage": {
18
+ "type": "boolean",
19
+ "default": true
20
+ },
21
+ "showCaption": {
22
+ "type": "boolean",
23
+ "default": false
24
+ },
25
+ "imageShape": {
26
+ "type": "string",
27
+ "default": "landscape"
28
+ },
29
+ "minHeight": {
30
+ "type": "integer",
31
+ "default": 0
32
+ },
33
+ "moreButton": {
34
+ "type": "boolean",
35
+ "default": false
36
+ },
37
+ "showAuthor": {
38
+ "type": "boolean",
39
+ "default": true
40
+ },
41
+ "showAvatar": {
42
+ "type": "boolean",
43
+ "default": true
44
+ },
45
+ "showCategory": {
46
+ "type": "boolean",
47
+ "default": false
48
+ },
49
+ "postLayout": {
50
+ "type": "string",
51
+ "default": "list"
52
+ },
53
+ "columns": {
54
+ "type": "integer",
55
+ "default": 3
56
+ },
57
+ "postsToShow": {
58
+ "type": "integer",
59
+ "default": 3
60
+ },
61
+ "mediaPosition": {
62
+ "type": "string",
63
+ "default": "top"
64
+ },
65
+ "authors": {
66
+ "type": "array",
67
+ "default": [],
68
+ "items": { "type": "integer" }
69
+ },
70
+ "categories": {
71
+ "type": "array",
72
+ "default": [],
73
+ "items": { "type": "integer" }
74
+ },
75
+ "tags": {
76
+ "type": "array",
77
+ "default": [],
78
+ "items": { "type": "integer" }
79
+ },
80
+ "specificPosts": {
81
+ "type": "array",
82
+ "default": [],
83
+ "items": { "type": "integer" }
84
+ },
85
+ "typeScale": {
86
+ "type": "integer",
87
+ "default": 4
88
+ },
89
+ "imageScale": {
90
+ "type": "integer",
91
+ "default": 3
92
+ },
93
+ "mobileStack": {
94
+ "type": "boolean",
95
+ "default": false
96
+ },
97
+ "sectionHeader": {
98
+ "type": "string",
99
+ "default": ""
100
+ },
101
+ "specificMode": {
102
+ "type": "boolean",
103
+ "default": false
104
+ },
105
+ "textColor": {
106
+ "type": "string",
107
+ "default": ""
108
+ },
109
+ "customTextColor": {
110
+ "type": "string",
111
+ "default": ""
112
+ },
113
+ "singleMode": {
114
+ "type": "boolean",
115
+ "default": false
116
+ }
117
+ }
118
+ }
blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/class-wp-rest-newspack-articles-controller.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WP_REST_Newspack_Articles_Controller file.
4
+ */
5
+
6
+ /**
7
+ * Class WP_REST_Newspack_Articles_Controller.
8
+ */
9
+ class WP_REST_Newspack_Articles_Controller extends WP_REST_Controller {
10
+
11
+ /**
12
+ * Attribute schema.
13
+ *
14
+ * @var array
15
+ */
16
+ public $attribute_schema;
17
+
18
+ /**
19
+ * Constructs the controller.
20
+ *
21
+ * @access public
22
+ */
23
+ public function __construct() {
24
+ $this->namespace = 'newspack-blocks/v1';
25
+ $this->rest_base = 'articles';
26
+ }
27
+
28
+ /**
29
+ * Registers the necessary REST API routes.
30
+ *
31
+ * @access public
32
+ */
33
+ public function register_routes() {
34
+ register_rest_route(
35
+ $this->namespace,
36
+ '/' . $this->rest_base,
37
+ [
38
+ [
39
+ 'methods' => WP_REST_Server::READABLE,
40
+ 'callback' => [ $this, 'get_items' ],
41
+ 'args' => $this->get_attribute_schema(),
42
+ 'permission_callback' => '__return_true',
43
+ ],
44
+ ]
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Returns a list of rendered posts.
50
+ *
51
+ * @param WP_REST_Request $request Request object.
52
+ * @return WP_REST_Response
53
+ */
54
+ public function get_items( $request ) {
55
+ $page = $request->get_param( 'page' ) ?? 1;
56
+ $next_page = $page + 1;
57
+ $attributes = wp_parse_args(
58
+ $request->get_params() ?? [],
59
+ wp_list_pluck( $this->get_attribute_schema(), 'default' )
60
+ );
61
+ $article_query_args = Newspack_Blocks::build_articles_query( $attributes );
62
+
63
+ // Append custom pagination arg for REST API endpoint.
64
+ $article_query_args['paged'] = $page;
65
+
66
+ // Run Query.
67
+ $article_query = new WP_Query( $article_query_args );
68
+
69
+ // Defaults.
70
+ $items = [];
71
+ $next_url = '';
72
+
73
+ // The Loop.
74
+ while ( $article_query->have_posts() ) {
75
+ $article_query->the_post();
76
+ $items[]['html'] = Newspack_Blocks::template_inc(
77
+ __DIR__ . '/templates/article.php',
78
+ [
79
+ 'attributes' => $attributes,
80
+ ]
81
+ );
82
+ }
83
+
84
+ // Provide next URL if there are more pages.
85
+ if ( $next_page <= $article_query->max_num_pages ) {
86
+ $next_url = add_query_arg(
87
+ array_merge(
88
+ array_map(
89
+ function( $attribute ) {
90
+ return $attribute === false ? '0' : $attribute; },
91
+ $attributes
92
+ ),
93
+ [ 'page' => $next_page ] // phpcs:ignore PHPCompatibility.Syntax.NewShortArray.Found
94
+ ),
95
+ rest_url( '/newspack-blocks/v1/articles' )
96
+ );
97
+ }
98
+
99
+ return rest_ensure_response(
100
+ [
101
+ 'items' => $items,
102
+ 'next' => $next_url,
103
+ ]
104
+ );
105
+ }
106
+
107
+ /**
108
+ * Sets up and returns attribute schema.
109
+ *
110
+ * @return array
111
+ */
112
+ public function get_attribute_schema() {
113
+ if ( empty( $this->attribute_schema ) ) {
114
+ $block_json = json_decode(
115
+ file_get_contents( __DIR__ . '/block.json' ),
116
+ true
117
+ );
118
+ $this->attribute_schema = $block_json['attributes'];
119
+ }
120
+
121
+ return $this->attribute_schema;
122
+ }
123
+ }
blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/edit.js ADDED
@@ -0,0 +1,641 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import QueryControls from '../../components/query-controls';
5
+
6
+ /**
7
+ * External dependencies
8
+ */
9
+ import classNames from 'classnames';
10
+ import { isUndefined, pickBy } from 'lodash';
11
+ import moment from 'moment';
12
+
13
+ /**
14
+ * WordPress dependencies
15
+ */
16
+ import { __ } from '@wordpress/i18n';
17
+ import { Component, Fragment, RawHTML } from '@wordpress/element';
18
+ import { InspectorControls, RichText, BlockControls } from '@wordpress/editor';
19
+ import {
20
+ Button,
21
+ ButtonGroup,
22
+ PanelBody,
23
+ PanelRow,
24
+ RangeControl,
25
+ Toolbar,
26
+ ToggleControl,
27
+ Dashicon,
28
+ Placeholder,
29
+ Spinner,
30
+ BaseControl,
31
+ Path,
32
+ SVG,
33
+ } from '@wordpress/components';
34
+ import { withSelect } from '@wordpress/data';
35
+ import { compose } from '@wordpress/compose';
36
+ import { addQueryArgs } from '@wordpress/url';
37
+ import { decodeEntities } from '@wordpress/html-entities';
38
+ import { PanelColorSettings, withColors } from '@wordpress/block-editor';
39
+
40
+ /**
41
+ * Module Constants
42
+ */
43
+ const MAX_POSTS_COLUMNS = 6;
44
+
45
+ /* From https://material.io/tools/icons */
46
+ const landscapeIcon = (
47
+ <SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
48
+ <Path d="M0 0h24v24H0z" fill="none" />
49
+ <Path d="M19 5H5c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 12H5V7h14v10z" />
50
+ </SVG>
51
+ );
52
+
53
+ const portraitIcon = (
54
+ <SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
55
+ <Path d="M0 0h24v24H0z" fill="none" />
56
+ <Path d="M17 3H7c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h10c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H7V5h10v14z" />
57
+ </SVG>
58
+ );
59
+
60
+ const squareIcon = (
61
+ <SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
62
+ <Path d="M0 0h24v24H0z" fill="none" />
63
+ <Path d="M18 4H6c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 14H6V6h12v12z" />
64
+ </SVG>
65
+ );
66
+
67
+ const uncroppedIcon = (
68
+ <SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
69
+ <Path d="M0 0h24v24H0z" fill="none" />
70
+ <Path d="M3 5v4h2V5h4V3H5c-1.1 0-2 .9-2 2zm2 10H3v4c0 1.1.9 2 2 2h4v-2H5v-4zm14 4h-4v2h4c1.1 0 2-.9 2-2v-4h-2v4zm0-16h-4v2h4v4h2V5c0-1.1-.9-2-2-2z" />
71
+ </SVG>
72
+ );
73
+
74
+ const coverIcon = (
75
+ <SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
76
+ <Path d="M0 0h24v24H0z" fill="none" />
77
+ <Path d="M4 4h7V2H4c-1.1 0-2 .9-2 2v7h2V4zm6 9l-4 5h12l-3-4-2.03 2.71L10 13zm7-4.5c0-.83-.67-1.5-1.5-1.5S14 7.67 14 8.5s.67 1.5 1.5 1.5S17 9.33 17 8.5zM20 2h-7v2h7v7h2V4c0-1.1-.9-2-2-2zm0 18h-7v2h7c1.1 0 2-.9 2-2v-7h-2v7zM4 13H2v7c0 1.1.9 2 2 2h7v-2H4v-7z" />
78
+ </SVG>
79
+ );
80
+
81
+ class Edit extends Component {
82
+ renderPost = post => {
83
+ const { attributes } = this.props;
84
+ const {
85
+ showImage,
86
+ imageShape,
87
+ mediaPosition,
88
+ minHeight,
89
+ showCaption,
90
+ showExcerpt,
91
+ showAuthor,
92
+ showAvatar,
93
+ showDate,
94
+ showCategory,
95
+ sectionHeader,
96
+ } = attributes;
97
+
98
+ const styles = {
99
+ minHeight:
100
+ mediaPosition === 'behind' &&
101
+ showImage &&
102
+ post.newspack_featured_image_src &&
103
+ minHeight + 'vh',
104
+ paddingTop:
105
+ mediaPosition === 'behind' &&
106
+ showImage &&
107
+ post.newspack_featured_image_src &&
108
+ minHeight / 5 + 'vh',
109
+ };
110
+
111
+ const authorNumber = post.newspack_author_info.length;
112
+
113
+ return (
114
+ <article
115
+ className={ post.newspack_featured_image_src ? 'post-has-image' : null }
116
+ key={ post.id }
117
+ style={ styles }
118
+ >
119
+ { showImage && post.newspack_featured_image_src && (
120
+ <figure className="post-thumbnail" key="thumbnail">
121
+ <a href="#">
122
+ { imageShape === 'landscape' && (
123
+ <img src={ post.newspack_featured_image_src.landscape } />
124
+ ) }
125
+ { imageShape === 'portrait' && (
126
+ <img src={ post.newspack_featured_image_src.portrait } />
127
+ ) }
128
+ { imageShape === 'square' && <img src={ post.newspack_featured_image_src.square } /> }
129
+
130
+ { imageShape === 'uncropped' && (
131
+ <img src={ post.newspack_featured_image_src.uncropped } />
132
+ ) }
133
+ </a>
134
+ { showCaption && '' !== post.newspack_featured_image_caption && (
135
+ <figcaption>{ post.newspack_featured_image_caption }</figcaption>
136
+ ) }
137
+ </figure>
138
+ ) }
139
+
140
+ <div className="entry-wrapper">
141
+ { showCategory && post.newspack_category_info.length && (
142
+ <div className="cat-links">
143
+ <a href="#">{ post.newspack_category_info }</a>
144
+ </div>
145
+ ) }
146
+ { RichText.isEmpty( sectionHeader ) ? (
147
+ <h2 className="entry-title" key="title">
148
+ <a href="#">{ decodeEntities( post.title.rendered.trim() ) }</a>
149
+ </h2>
150
+ ) : (
151
+ <h3 className="entry-title" key="title">
152
+ <a href="#">{ decodeEntities( post.title.rendered.trim() ) }</a>
153
+ </h3>
154
+ ) }
155
+ { showExcerpt && (
156
+ <RawHTML key="excerpt" className="excerpt-contain">
157
+ { post.excerpt.rendered }
158
+ </RawHTML>
159
+ ) }
160
+ <div className="entry-meta">
161
+ { showAuthor && showAvatar && this.formatAvatars( post.newspack_author_info ) }
162
+ { showAuthor && this.formatByline( post.newspack_author_info ) }
163
+ { showDate && (
164
+ <time className="entry-date published" key="pub-date">
165
+ { moment( post.date_gmt )
166
+ .local()
167
+ .format( 'MMMM DD, Y' ) }
168
+ </time>
169
+ ) }
170
+ </div>
171
+ </div>
172
+ </article>
173
+ );
174
+ };
175
+
176
+ formatAvatars = authorInfo =>
177
+ authorInfo.map( author => (
178
+ <span className="avatar author-avatar">
179
+ <a className="url fn n" href="#">
180
+ <RawHTML key={ author.id }>{ author.avatar }</RawHTML>
181
+ </a>
182
+ </span>
183
+ ) );
184
+
185
+ formatByline = authorInfo => (
186
+ <span className="byline">
187
+ { __( 'by', 'newspack-blocks' ) }{ ' ' }
188
+ { authorInfo.reduce( ( accumulator, author, index ) => {
189
+ return [
190
+ ...accumulator,
191
+ <span className="author vcard" key={ author.id }>
192
+ <a className="url fn n" href="#">
193
+ { author.display_name }
194
+ </a>
195
+ </span>,
196
+ index < authorInfo.length - 2 && ', ',
197
+ authorInfo.length > 1 &&
198
+ index === authorInfo.length - 2 &&
199
+ __( ' and ', 'newspack-blocks' ),
200
+ ];
201
+ }, [] ) }
202
+ </span>
203
+ );
204
+
205
+ renderInspectorControls = () => {
206
+ const {
207
+ attributes,
208
+ setAttributes,
209
+ latestPosts,
210
+ isSelected,
211
+ textColor,
212
+ setTextColor,
213
+ } = this.props;
214
+ const hasPosts = Array.isArray( latestPosts ) && latestPosts.length;
215
+
216
+ const {
217
+ authors,
218
+ specificPosts,
219
+ postsToShow,
220
+ categories,
221
+ sectionHeader,
222
+ columns,
223
+ showImage,
224
+ showCaption,
225
+ imageScale,
226
+ mobileStack,
227
+ minHeight,
228
+ moreButton,
229
+ showExcerpt,
230
+ typeScale,
231
+ showDate,
232
+ showAuthor,
233
+ showAvatar,
234
+ showCategory,
235
+ postLayout,
236
+ mediaPosition,
237
+ specificMode,
238
+ tags,
239
+ url,
240
+ } = attributes;
241
+
242
+ const imageSizeOptions = [
243
+ {
244
+ value: 1,
245
+ label: /* translators: label for small size option */ __( 'Small', 'newspack-blocks' ),
246
+ shortName: /* translators: abbreviation for small size */ __( 'S', 'newspack-blocks' ),
247
+ },
248
+ {
249
+ value: 2,
250
+ label: /* translators: label for medium size option */ __( 'Medium', 'newspack-blocks' ),
251
+ shortName: /* translators: abbreviation for medium size */ __( 'M', 'newspack-blocks' ),
252
+ },
253
+ {
254
+ value: 3,
255
+ label: /* translators: label for large size option */ __( 'Large', 'newspack-blocks' ),
256
+ shortName: /* translators: abbreviation for large size */ __( 'L', 'newspack-blocks' ),
257
+ },
258
+ {
259
+ value: 4,
260
+ label: /* translators: label for extra large size option */ __(
261
+ 'Extra Large',
262
+ 'newspack-blocks'
263
+ ),
264
+ shortName: /* translators: abbreviation for extra large size */ __(
265
+ 'XL',
266
+ 'newspack-blocks'
267
+ ),
268
+ },
269
+ ];
270
+
271
+ return (
272
+ <Fragment>
273
+ <PanelBody title={ __( 'Display Settings', 'newspack-blocks' ) } initialOpen={ true }>
274
+ { postsToShow && (
275
+ <QueryControls
276
+ numberOfItems={ postsToShow }
277
+ onNumberOfItemsChange={ value => setAttributes( { postsToShow: value } ) }
278
+ specificMode={ specificMode }
279
+ onSpecificModeChange={ value => setAttributes( { specificMode: value } ) }
280
+ specificPosts={ specificPosts }
281
+ onSpecificPostsChange={ value => setAttributes( { specificPosts: value } ) }
282
+ authors={ authors }
283
+ onAuthorsChange={ value => setAttributes( { authors: value } ) }
284
+ categories={ categories }
285
+ onCategoriesChange={ value => setAttributes( { categories: value } ) }
286
+ tags={ tags }
287
+ onTagsChange={ value => setAttributes( { tags: value } ) }
288
+ />
289
+ ) }
290
+ { postLayout === 'grid' && (
291
+ <RangeControl
292
+ label={ __( 'Columns', 'newspack-blocks' ) }
293
+ value={ columns }
294
+ onChange={ value => setAttributes( { columns: value } ) }
295
+ min={ 2 }
296
+ max={
297
+ ! hasPosts ? MAX_POSTS_COLUMNS : Math.min( MAX_POSTS_COLUMNS, latestPosts.length )
298
+ }
299
+ required
300
+ />
301
+ ) }
302
+ { ! specificMode && (
303
+ <ToggleControl
304
+ label={ __( 'Show "More" Button', 'newspack-blocks' ) }
305
+ checked={ moreButton }
306
+ onChange={ () => setAttributes( { moreButton: ! moreButton } ) }
307
+ help={ __( 'Only available for non-AMP requests.', 'newspack-blocks' ) }
308
+ />
309
+ ) }
310
+ </PanelBody>
311
+ <PanelBody title={ __( 'Featured Image Settings', 'newspack-blocks' ) }>
312
+ <PanelRow>
313
+ <ToggleControl
314
+ label={ __( 'Show Featured Image', 'newspack-blocks' ) }
315
+ checked={ showImage }
316
+ onChange={ () => setAttributes( { showImage: ! showImage } ) }
317
+ />
318
+ </PanelRow>
319
+
320
+ { showImage && (
321
+ <PanelRow>
322
+ <ToggleControl
323
+ label={ __( 'Show Featured Image Caption', 'newspack-blocks' ) }
324
+ checked={ showCaption }
325
+ onChange={ () => setAttributes( { showCaption: ! showCaption } ) }
326
+ />
327
+ </PanelRow>
328
+ ) }
329
+
330
+ { showImage && mediaPosition !== 'top' && mediaPosition !== 'behind' && (
331
+ <Fragment>
332
+ <PanelRow>
333
+ <ToggleControl
334
+ label={ __( 'Stack on mobile', 'newspack-blocks' ) }
335
+ checked={ mobileStack }
336
+ onChange={ () => setAttributes( { mobileStack: ! mobileStack } ) }
337
+ />
338
+ </PanelRow>
339
+ <BaseControl label={ __( 'Featured Image Size', 'newspack-blocks' ) }>
340
+ <PanelRow>
341
+ <ButtonGroup aria-label={ __( 'Featured Image Size', 'newspack-blocks' ) }>
342
+ { imageSizeOptions.map( option => {
343
+ const isCurrent = imageScale === option.value;
344
+ return (
345
+ <Button
346
+ isLarge
347
+ isPrimary={ isCurrent }
348
+ aria-pressed={ isCurrent }
349
+ aria-label={ option.label }
350
+ onClick={ () => setAttributes( { imageScale: option.value } ) }
351
+ >
352
+ { option.shortName }
353
+ </Button>
354
+ );
355
+ } ) }
356
+ </ButtonGroup>
357
+ </PanelRow>
358
+ </BaseControl>
359
+ </Fragment>
360
+ ) }
361
+
362
+ { showImage && mediaPosition === 'behind' && (
363
+ <RangeControl
364
+ label={ __( 'Minimum height', 'newspack-blocks' ) }
365
+ help={ __(
366
+ "Sets a minimum height for the block, using a percentage of the screen's current height.",
367
+ 'newspack-blocks'
368
+ ) }
369
+ value={ minHeight }
370
+ onChange={ value => setAttributes( { minHeight: value } ) }
371
+ min={ 0 }
372
+ max={ 100 }
373
+ required
374
+ />
375
+ ) }
376
+ </PanelBody>
377
+ <PanelBody title={ __( 'Post Control Settings', 'newspack-blocks' ) }>
378
+ <PanelRow>
379
+ <ToggleControl
380
+ label={ __( 'Show Excerpt', 'newspack-blocks' ) }
381
+ checked={ showExcerpt }
382
+ onChange={ () => setAttributes( { showExcerpt: ! showExcerpt } ) }
383
+ />
384
+ </PanelRow>
385
+ <RangeControl
386
+ className="type-scale-slider"
387
+ label={ __( 'Type Scale', 'newspack-blocks' ) }
388
+ value={ typeScale }
389
+ onChange={ value => setAttributes( { typeScale: value } ) }
390
+ min={ 1 }
391
+ max={ 10 }
392
+ beforeIcon="editor-textcolor"
393
+ afterIcon="editor-textcolor"
394
+ required
395
+ />
396
+ </PanelBody>
397
+ <PanelColorSettings
398
+ title={ __( 'Color Settings', 'newspack-blocks' ) }
399
+ initialOpen={ true }
400
+ colorSettings={ [
401
+ {
402
+ value: textColor.color,
403
+ onChange: setTextColor,
404
+ label: __( 'Text Color', 'newspack-blocks' ),
405
+ },
406
+ ] }
407
+ />
408
+ <PanelBody title={ __( 'Post Meta Settings', 'newspack-blocks' ) }>
409
+ <PanelRow>
410
+ <ToggleControl
411
+ label={ __( 'Show Date', 'newspack-blocks' ) }
412
+ checked={ showDate }
413
+ onChange={ () => setAttributes( { showDate: ! showDate } ) }
414
+ />
415
+ </PanelRow>
416
+ <PanelRow>
417
+ <ToggleControl
418
+ label={ __( 'Show Category', 'newspack-blocks' ) }
419
+ checked={ showCategory }
420
+ onChange={ () => setAttributes( { showCategory: ! showCategory } ) }
421
+ />
422
+ </PanelRow>
423
+ <PanelRow>
424
+ <ToggleControl
425
+ label={ __( 'Show Author', 'newspack-blocks' ) }
426
+ checked={ showAuthor }
427
+ onChange={ () => setAttributes( { showAuthor: ! showAuthor } ) }
428
+ />
429
+ </PanelRow>
430
+ { showAuthor && (
431
+ <PanelRow>
432
+ <ToggleControl
433
+ label={ __( 'Show Author Avatar', 'newspack-blocks' ) }
434
+ checked={ showAvatar }
435
+ onChange={ () => setAttributes( { showAvatar: ! showAvatar } ) }
436
+ />
437
+ </PanelRow>
438
+ ) }
439
+ </PanelBody>
440
+ </Fragment>
441
+ );
442
+ };
443
+
444
+ render() {
445
+ /**
446
+ * Constants
447
+ */
448
+ const {
449
+ attributes,
450
+ className,
451
+ setAttributes,
452
+ isSelected,
453
+ latestPosts,
454
+ hasPosts,
455
+ textColor,
456
+ } = this.props; // variables getting pulled out of props
457
+ const {
458
+ showExcerpt,
459
+ showDate,
460
+ showImage,
461
+ imageShape,
462
+ showAuthor,
463
+ showAvatar,
464
+ postsToShow,
465
+ postLayout,
466
+ mediaPosition,
467
+ moreButton,
468
+ columns,
469
+ categories,
470
+ typeScale,
471
+ imageScale,
472
+ mobileStack,
473
+ sectionHeader,
474
+ showCaption,
475
+ showCategory,
476
+ specificMode,
477
+ } = attributes;
478
+
479
+ const classes = classNames( className, {
480
+ 'is-grid': postLayout === 'grid',
481
+ 'show-image': showImage,
482
+ [ `columns-${ columns }` ]: postLayout === 'grid',
483
+ [ `ts-${ typeScale }` ]: typeScale !== '5',
484
+ [ `image-align${ mediaPosition }` ]: showImage,
485
+ [ `is-${ imageScale }` ]: imageScale !== '1' && showImage,
486
+ 'mobile-stack': mobileStack,
487
+ [ `image-shape${ imageShape }` ]: imageShape !== 'landscape',
488
+ 'has-text-color': textColor.color !== '',
489
+ 'show-caption': showCaption,
490
+ 'show-category': showCategory,
491
+ wpnbha: true,
492
+ } );
493
+
494
+ const blockControls = [
495
+ {
496
+ icon: 'list-view',
497
+ title: __( 'List View', 'newspack-blocks' ),
498
+ onClick: () => setAttributes( { postLayout: 'list' } ),
499
+ isActive: postLayout === 'list',
500
+ },
501
+ {
502
+ icon: 'grid-view',
503
+ title: __( 'Grid View', 'newspack-blocks' ),
504
+ onClick: () => setAttributes( { postLayout: 'grid' } ),
505
+ isActive: postLayout === 'grid',
506
+ },
507
+ ];
508
+
509
+ const blockControlsImages = [
510
+ {
511
+ icon: 'align-none',
512
+ title: __( 'Show media on top', 'newspack-blocks' ),
513
+ isActive: mediaPosition === 'top',
514
+ onClick: () => setAttributes( { mediaPosition: 'top' } ),
515
+ },
516
+ {
517
+ icon: 'align-pull-left',
518
+ title: __( 'Show media on left', 'newspack-blocks' ),
519
+ isActive: mediaPosition === 'left',
520
+ onClick: () => setAttributes( { mediaPosition: 'left' } ),
521
+ },
522
+ {
523
+ icon: 'align-pull-right',
524
+ title: __( 'Show media on right', 'newspack-blocks' ),
525
+ isActive: mediaPosition === 'right',
526
+ onClick: () => setAttributes( { mediaPosition: 'right' } ),
527
+ },
528
+ {
529
+ icon: coverIcon,
530
+ title: __( 'Show media behind', 'newspack-blocks' ),
531
+ isActive: mediaPosition === 'behind',
532
+ onClick: () => setAttributes( { mediaPosition: 'behind' } ),
533
+ },
534
+ ];
535
+
536
+ const blockControlsImageShape = [
537
+ {
538
+ icon: landscapeIcon,
539
+ title: __( 'Landscape Image Shape', 'newspack-blocks' ),
540
+ isActive: imageShape === 'landscape',
541
+ onClick: () => setAttributes( { imageShape: 'landscape' } ),
542
+ },
543
+ {
544
+ icon: portraitIcon,
545
+ title: __( 'portrait Image Shape', 'newspack-blocks' ),
546
+ isActive: imageShape === 'portrait',
547
+ onClick: () => setAttributes( { imageShape: 'portrait' } ),
548
+ },
549
+ {
550
+ icon: squareIcon,
551
+ title: __( 'Square Image Shape', 'newspack-blocks' ),
552
+ isActive: imageShape === 'square',
553
+ onClick: () => setAttributes( { imageShape: 'square' } ),
554
+ },
555
+ {
556
+ icon: uncroppedIcon,
557
+ title: __( 'Uncropped', 'newspack-blocks' ),
558
+ isActive: imageShape === 'uncropped',
559
+ onClick: () => setAttributes( { imageShape: 'uncropped' } ),
560
+ },
561
+ ];
562
+
563
+ return (
564
+ <Fragment>
565
+ <div
566
+ className={ classes }
567
+ style={ {
568
+ color: textColor.color,
569
+ } }
570
+ >
571
+ { latestPosts && ( ! RichText.isEmpty( sectionHeader ) || isSelected ) && (
572
+ <RichText
573
+ onChange={ value => setAttributes( { sectionHeader: value } ) }
574
+ placeholder={ __( 'Write header…', 'newspack-blocks' ) }
575
+ value={ sectionHeader }
576
+ tagName="h2"
577
+ className="article-section-title"
578
+ />
579
+ ) }
580
+ { latestPosts && ! latestPosts.length && (
581
+ <Placeholder>{ __( 'Sorry, no posts were found.', 'newspack-blocks' ) }</Placeholder>
582
+ ) }
583
+ { ! latestPosts && (
584
+ <Placeholder>
585
+ <Spinner />
586
+ </Placeholder>
587
+ ) }
588
+ { latestPosts && latestPosts.map( post => this.renderPost( post ) ) }
589
+ </div>
590
+
591
+ { ! specificMode && latestPosts && moreButton && (
592
+ <button className="button" type="button">
593
+ { __( 'More…', 'newspack-blocks' ) }
594
+ </button>
595
+ ) }
596
+
597
+ <BlockControls>
598
+ <Toolbar controls={ blockControls } />
599
+ { showImage && <Toolbar controls={ blockControlsImages } /> }
600
+ { showImage && <Toolbar controls={ blockControlsImageShape } /> }
601
+ </BlockControls>
602
+ <InspectorControls>{ this.renderInspectorControls() }</InspectorControls>
603
+ </Fragment>
604
+ );
605
+ }
606
+ }
607
+
608
+ export default compose( [
609
+ withColors( { textColor: 'color' } ),
610
+ withSelect( ( select, props ) => {
611
+ const {
612
+ postsToShow,
613
+ authors,
614
+ categories,
615
+ tags,
616
+ specificPosts,
617
+ specificMode,
618
+ } = props.attributes;
619
+ const { getAuthors, getEntityRecords } = select( 'core' );
620
+ const latestPostsQuery = pickBy(
621
+ specificMode && specificPosts && specificPosts.length
622
+ ? {
623
+ include: specificPosts,
624
+ orderby: 'include',
625
+ }
626
+ : {
627
+ per_page: postsToShow,
628
+ categories,
629
+ author: authors,
630
+ tags,
631
+ },
632
+ value => ! isUndefined( value )
633
+ );
634
+ const postsListQuery = {
635
+ per_page: 50,
636
+ };
637
+ return {
638
+ latestPosts: getEntityRecords( 'postType', 'post', latestPostsQuery ),
639
+ };
640
+ } ),
641
+ ] )( Edit );
blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/editor.js ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { registerBlockType } from '@wordpress/blocks';
5
+ import { name, settings } from '.';
6
+
7
+ registerBlockType( `newspack-blocks/${ name }`, settings );
blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/editor.scss ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../../shared/sass/variables";
2
+
3
+ .type-scale-slider {
4
+ .dashicon {
5
+ height: 16px;
6
+ width: 16px;
7
+ }
8
+
9
+ input + .dashicon {
10
+ height: 24px;
11
+ margin-left: 10px;
12
+ margin-right: 0;
13
+ width: 24px;
14
+ }
15
+ }
16
+
17
+ .wpnbha {
18
+ .editor-rich-text {
19
+ width: 100%;
20
+ }
21
+
22
+ /* Article meta */
23
+ .cat-links {
24
+ font-size: $font__size-xs;
25
+ }
26
+
27
+ span.avatar {
28
+ display: inline-block;
29
+ margin-right: 0.5em;
30
+ div {
31
+ display: inline;
32
+ }
33
+ }
34
+
35
+ /* Article excerpt */
36
+ .excerpt-contain p {
37
+ margin: 0.5em 0;
38
+ }
39
+ }
blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/index.js ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { Path, SVG } from '@wordpress/components';
5
+ import { createBlock } from '@wordpress/blocks';
6
+
7
+ /**
8
+ * WordPress dependencies
9
+ */
10
+ import { applyFilters } from '@wordpress/hooks';
11
+ import { __, _x } from '@wordpress/i18n';
12
+
13
+ /**
14
+ * Internal dependencies
15
+ */
16
+ import edit from './edit';
17
+
18
+ /**
19
+ * Style dependencies - will load in editor
20
+ */
21
+ import './editor.scss';
22
+ import './view.scss';
23
+ import metadata from './block.json';
24
+ const { name, attributes, category } = metadata;
25
+
26
+ // Name must be exported separately.
27
+ export { name };
28
+
29
+ export const title = __( 'Homepage Posts', 'newspack-blocks' );
30
+
31
+ /* From https://material.io/tools/icons */
32
+ export const icon = (
33
+ <SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
34
+ <Path d="M0 0h24v24H0z" fill="none" />
35
+ <Path d="M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H8V4h12v12zM10 9h8v2h-8zm0 3h4v2h-4zm0-6h8v2h-8z" />
36
+ </SVG>
37
+ );
38
+
39
+ export const settings = {
40
+ title,
41
+ icon,
42
+ attributes,
43
+ category,
44
+ keywords: [
45
+ __( 'posts', 'newspack-blocks' ),
46
+ __( 'articles', 'newspack-blocks' ),
47
+ __( 'latest', 'newspack-blocks' ),
48
+ ],
49
+ description: __( 'A block for displaying homepage posts.', 'newspack-blocks' ),
50
+ styles: [
51
+ { name: 'default', label: _x( 'Default', 'block style', 'newspack-blocks' ), isDefault: true },
52
+ { name: 'borders', label: _x( 'Borders', 'block style', 'newspack-blocks' ) },
53
+ ],
54
+ supports: {
55
+ html: false,
56
+ align: [ 'wide', 'full' ],
57
+ default: '',
58
+ },
59
+ edit,
60
+ save: () => null, // to use view.php
61
+ transforms: {
62
+ from: [
63
+ {
64
+ type: 'block',
65
+ blocks: [ 'core/latest-posts' ],
66
+ transform: ( {
67
+ displayPostContent,
68
+ displayPostDate,
69
+ postLayout,
70
+ columns,
71
+ postsToShow,
72
+ categories,
73
+ } ) => {
74
+ return createBlock(
75
+ applyFilters( 'blocks.transforms_from_name', 'newspack-blocks/homepage-articles' ),
76
+ {
77
+ showExcerpt: displayPostContent,
78
+ showDate: displayPostDate,
79
+ postLayout,
80
+ columns,
81
+ postsToShow,
82
+ showAuthor: false,
83
+ categories: categories ? [ categories ] : [],
84
+ }
85
+ );
86
+ },
87
+ },
88
+ ],
89
+ to: [
90
+ {
91
+ type: 'block',
92
+ blocks: [ 'core/latest-posts' ],
93
+ transform: ( { showExcerpt, showDate, postLayout, columns, postsToShow, categories } ) => {
94
+ return createBlock( 'core/latest-posts', {
95
+ displayPostContent: showExcerpt,
96
+ displayPostDate: showDate,
97
+ postLayout,
98
+ columns,
99
+ postsToShow,
100
+ categories: categories[ 0 ] || '',
101
+ } );
102
+ },
103
+ },
104
+ ],
105
+ },
106
+ };
blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/templates/article.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Article template.
4
+ *
5
+ * @global array $attributes Block attributes.
6
+ * @package WordPress
7
+ */
8
+
9
+ call_user_func(
10
+ function( $data ) {
11
+ $attributes = $data['attributes'];
12
+
13
+ $authors = Newspack_Blocks::prepare_authors();
14
+
15
+ $styles = '';
16
+
17
+ if ( 'behind' === $attributes['mediaPosition'] && $attributes['showImage'] && has_post_thumbnail() ) {
18
+ $styles = 'min-height: ' . $attributes['minHeight'] . 'vh; padding-top: ' . ( $attributes['minHeight'] / 5 ) . 'vh;';
19
+ }
20
+ $image_size = 'newspack-article-block-uncropped';
21
+ if ( 'uncropped' !== $attributes['imageShape'] ) {
22
+ $image_size = Newspack_Blocks::image_size_for_orientation( $attributes['imageShape'] );
23
+ }
24
+ $thumbnail_args = '';
25
+ // If the image position is behind, pass the object-fit setting to maintain styles with AMP.
26
+ if ( 'behind' === $attributes['mediaPosition'] ) {
27
+ $thumbnail_args = array( 'object-fit' => 'cover' );
28
+ }
29
+ $category = false;
30
+ // Use Yoast primary category if set.
31
+ if ( class_exists( 'WPSEO_Primary_Term' ) ) {
32
+ $primary_term = new WPSEO_Primary_Term( 'category', get_the_ID() );
33
+ $category_id = $primary_term->get_primary_term();
34
+ if ( $category_id ) {
35
+ $category = get_term( $category_id );
36
+ }
37
+ }
38
+ if ( ! $category ) {
39
+ $categories_list = get_the_category();
40
+ if ( ! empty( $categories_list ) ) {
41
+ $category = $categories_list[0];
42
+ }
43
+ }
44
+ ?>
45
+ <article
46
+ <?php if ( has_post_thumbnail() ) : ?>
47
+ class="post-has-image"
48
+ <?php endif; ?>
49
+ <?php if ( $styles ) : ?>
50
+ style="<?php echo esc_attr( $styles ); ?>"
51
+ <?php endif; ?>
52
+ >
53
+ <?php if ( has_post_thumbnail() && $attributes['showImage'] && $attributes['imageShape'] ) : ?>
54
+ <figure class="post-thumbnail">
55
+ <a href="<?php the_permalink(); ?>" rel="bookmark">
56
+ <?php the_post_thumbnail( $image_size, $thumbnail_args ); ?>
57
+ </a>
58
+
59
+ <?php if ( $attributes['showCaption'] && '' !== get_the_post_thumbnail_caption() ) : ?>
60
+ <figcaption><?php the_post_thumbnail_caption(); ?></figcaption>
61
+ <?php endif; ?>
62
+ </figure><!-- .featured-image -->
63
+ <?php endif; ?>
64
+
65
+ <div class="entry-wrapper">
66
+ <?php if ( $attributes['showCategory'] && $category ) : ?>
67
+ <div class="cat-links">
68
+ <a href="<?php echo esc_url( get_category_link( $category->term_id ) ); ?>">
69
+ <?php echo esc_html( $category->name ); ?>
70
+ </a>
71
+ </div>
72
+ <?php
73
+ endif;
74
+ if ( '' === $attributes['sectionHeader'] ) :
75
+ the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
76
+ else :
77
+ the_title( '<h3 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h3>' );
78
+ endif;
79
+ if ( $attributes['showExcerpt'] ) :
80
+ the_excerpt();
81
+ endif;
82
+ if ( $attributes['showAuthor'] || $attributes['showDate'] ) :
83
+ ?>
84
+ <div class="entry-meta">
85
+ <?php
86
+ if ( $attributes['showAuthor'] ) :
87
+ if ( $attributes['showAvatar'] ) :
88
+ echo wp_kses(
89
+ newspack_blocks_format_avatars( $authors ),
90
+ array(
91
+ 'img' => array(
92
+ 'class' => true,
93
+ 'src' => true,
94
+ 'alt' => true,
95
+ 'width' => true,
96
+ 'height' => true,
97
+ 'data-*' => true,
98
+ 'srcset' => true,
99
+ ),
100
+ 'noscript' => array(),
101
+ 'a' => array(
102
+ 'href' => true,
103
+ ),
104
+ )
105
+ );
106
+ endif;
107
+ ?>
108
+ <span class="byline">
109
+ <?php echo wp_kses_post( newspack_blocks_format_byline( $authors ) ); ?>
110
+ </span><!-- .author-name -->
111
+ <?php
112
+ endif;
113
+ if ( $attributes['showDate'] ) :
114
+ $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
115
+ if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) :
116
+ $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
117
+ endif;
118
+ printf(
119
+ wp_kses(
120
+ $time_string,
121
+ array(
122
+ 'time' => array(
123
+ 'class' => true,
124
+ 'datetime' => true,
125
+ ),
126
+ )
127
+ ),
128
+ esc_attr( get_the_date( DATE_W3C ) ),
129
+ esc_html( get_the_date() ),
130
+ esc_attr( get_the_modified_date( DATE_W3C ) ),
131
+ esc_html( get_the_modified_date() )
132
+ );
133
+ endif;
134
+ ?>
135
+ </div><!-- .entry-meta -->
136
+ <?php endif; ?>
137
+ </div><!-- .entry-wrapper -->
138
+ </article>
139
+
140
+ <?php
141
+ },
142
+ $data // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
143
+ );
blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/templates/articles-list.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Article list template.
4
+ *
5
+ * @global WP_Query $article_query Article query.
6
+ * @global array $attributes
7
+ * @package WordPress
8
+ */
9
+
10
+ call_user_func(
11
+ function( $data ) {
12
+ echo Newspack_Blocks::template_inc( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
13
+ __DIR__ . '/articles-loop.php',
14
+ array(
15
+ 'attributes' => $data['attributes'],
16
+ 'article_query' => $data['article_query'],
17
+ )
18
+ );
19
+ },
20
+ $data // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
21
+ );
blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/templates/articles-loop.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Articles loop template.
4
+ *
5
+ * @package WordPress
6
+ * @global \WP_Query $article_query Article query.
7
+ * @global array $attributes
8
+ * @global array $newspack_blocks_post_id
9
+ */
10
+
11
+ call_user_func(
12
+ function( $data ) {
13
+ $attributes = $data['attributes'];
14
+ $article_query = $data['article_query'];
15
+ global $newspack_blocks_post_id;
16
+ $post_counter = 0;
17
+ while ( $article_query->have_posts() ) {
18
+ $article_query->the_post();
19
+ if ( ! $attributes['specificMode'] && ( isset( $newspack_blocks_post_id[ get_the_ID() ] ) || $post_counter >= $attributes['postsToShow'] ) ) {
20
+ continue;
21
+ }
22
+ $newspack_blocks_post_id[ get_the_ID() ] = true;
23
+ $post_counter++;
24
+ echo Newspack_Blocks::template_inc( __DIR__ . '/article.php', array( 'attributes' => $attributes ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
25
+ }
26
+ wp_reset_postdata();
27
+ },
28
+ $data // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
29
+ );
blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/view.js ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * VIEW
3
+ * JavaScript used on front of site.
4
+ */
5
+
6
+ /**
7
+ * Style dependencies
8
+ */
9
+ import './view.scss';
10
+
11
+ const btnURLAttr = 'data-load-more-url';
12
+ const fetchRetryCount = 3;
13
+
14
+ /**
15
+ * Load More Button Handling
16
+ */
17
+
18
+ document.querySelectorAll( '[data-load-more-btn]' ).forEach( attachLoadMoreHandler );
19
+
20
+ /**
21
+ * Attaches an event handler to the Load more button.
22
+ * @param {DOMElement} btnEl the button that was clicked
23
+ */
24
+ function attachLoadMoreHandler( btnEl ) {
25
+ if ( ! btnEl ) {
26
+ return null;
27
+ }
28
+
29
+ const handler = buildLoadMoreHandler( btnEl );
30
+
31
+ btnEl.addEventListener( 'click', handler );
32
+ }
33
+
34
+ /**
35
+ * Builds a function to handle clicks on the load more button.
36
+ * Creates internal state via closure to ensure all state is
37
+ * isolated to a single Block + button instance.
38
+ *
39
+ * @param {DOMElement} btnEl the button that was clicked
40
+ */
41
+ function buildLoadMoreHandler( btnEl ) {
42
+ // Set elements from scope determined by the clicked "Load more" button.
43
+ const blockWrapperEl = btnEl.parentElement; // scope root element
44
+ const postsContainerEl = blockWrapperEl.querySelector( '[data-posts-container]' );
45
+ const loadingEl = blockWrapperEl.querySelector( '[data-load-more-loading-text]' );
46
+ const errorEl = blockWrapperEl.querySelector( '[data-load-more-error-text]' );
47
+
48
+ // Set initial state flags.
49
+ let isFetching = false;
50
+ let isEndOfData = false;
51
+
52
+ return () => {
53
+ // Early return if still fetching or no more posts to render.
54
+ if ( isFetching || isEndOfData ) {
55
+ return false;
56
+ }
57
+
58
+ isFetching = true;
59
+
60
+ // Set elements visibility for fetching state.
61
+ hideEl( btnEl );
62
+ hideEl( errorEl );
63
+ showEl( loadingEl );
64
+
65
+ const onSuccess = data => {
66
+ // Validate received data.
67
+ if ( isPostsDataValid( data ) ) {
68
+ // Render posts' HTML from string.
69
+ const postsHTML = data.items.map( item => item.html ).join( '' );
70
+ postsContainerEl.insertAdjacentHTML( 'beforeend', postsHTML );
71
+
72
+ if ( data.next ) {
73
+ // Save next URL as button's attribute.
74
+ btnEl.setAttribute( btnURLAttr, data.next );
75
+
76
+ // Unhide button since there are more posts available.
77
+ showEl( btnEl );
78
+ } else {
79
+ isEndOfData = true;
80
+ }
81
+
82
+ isFetching = false;
83
+
84
+ hideEl( loadingEl );
85
+ }
86
+ };
87
+
88
+ const onError = () => {
89
+ isFetching = false;
90
+
91
+ // Display error message and keep the button visible to enable retrying.
92
+ hideEl( loadingEl );
93
+ showEl( errorEl );
94
+ showEl( btnEl );
95
+ };
96
+
97
+ fetchWithRetry(
98
+ { url: btnEl.getAttribute( btnURLAttr ), onSuccess, onError },
99
+ fetchRetryCount
100
+ );
101
+ };
102
+ }
103
+
104
+ /**
105
+ * Wrapper for XMLHttpRequest that performs given number of retries when error
106
+ * occurs.
107
+ *
108
+ * @param {Object} options XMLHttpRequest options
109
+ * @param {Number} n retry count before throwing
110
+ */
111
+ function fetchWithRetry( options, n ) {
112
+ const xhr = new XMLHttpRequest();
113
+
114
+ xhr.onreadystatechange = () => {
115
+ // Return if the request is completed.
116
+ if ( xhr.readyState !== 4 ) {
117
+ return;
118
+ }
119
+
120
+ // Call onSuccess with parsed JSON if the request is successful.
121
+ if ( xhr.status >= 200 && xhr.status < 300 ) {
122
+ const data = JSON.parse( xhr.responseText );
123
+
124
+ return options.onSuccess( data );
125
+ }
126
+
127
+ // Call onError if the request has failed n + 1 times (or if n is undefined).
128
+ if ( ! n ) {
129
+ return options.onError();
130
+ }
131
+
132
+ // Retry fetching if request has failed and n > 0.
133
+ return fetchWithRetry( options, n - 1 );
134
+ };
135
+
136
+ xhr.open( 'GET', options.url );
137
+ xhr.send();
138
+ }
139
+
140
+ /**
141
+ * Validates the "Load more" posts endpoint schema:
142
+ * {
143
+ * "type": "object",
144
+ * "properties": {
145
+ * "items": {
146
+ * "type": "array",
147
+ * "items": {
148
+ * "type": "object",
149
+ * "properties": {
150
+ * "html": {
151
+ * "type": "string"
152
+ * }
153
+ * },
154
+ * "required": ["html"]
155
+ * },
156
+ * "required": ["items"]
157
+ * },
158
+ * "next": {
159
+ * "type": ["string", "null"]
160
+ * }
161
+ * },
162
+ * "required": ["items", "next"]
163
+ * }
164
+ *
165
+ * @param {Object} data posts endpoint payload
166
+ */
167
+ function isPostsDataValid( data ) {
168
+ if (
169
+ data &&
170
+ hasOwnProp( data, 'items' ) &&
171
+ hasOwnProp( data, 'next' ) &&
172
+ Array.isArray( data.items ) &&
173
+ data.items.length &&
174
+ hasOwnProp( data.items[ 0 ], 'html' ) &&
175
+ typeof data.items[ 0 ].html === 'string'
176
+ ) {
177
+ return true;
178
+ }
179
+
180
+ return false;
181
+ }
182
+
183
+ /**
184
+ * Hides given DOM element.
185
+ *
186
+ * @param {DOMElement} el
187
+ */
188
+ function hideEl( el ) {
189
+ el.style.display = 'none';
190
+ el.setAttribute( 'hidden', '' );
191
+ }
192
+
193
+ /**
194
+ * Unhides given DOM element.
195
+ *
196
+ * @param {DOMElement} el
197
+ */
198
+ function showEl( el ) {
199
+ el.style.display = '';
200
+ el.removeAttribute( 'hidden' );
201
+ }
202
+
203
+ /**
204
+ * Checks if object has own property.
205
+ *
206
+ * @param {Object} obj
207
+ * @param {String} prop
208
+ */
209
+ function hasOwnProp( obj, prop ) {
210
+ return Object.prototype.hasOwnProperty.call( obj, prop );
211
+ }
blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/view.php ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Server-side rendering of the `newspack-blocks/homepage-posts` block.
4
+ *
5
+ * @package WordPress
6
+ */
7
+
8
+ /**
9
+ * Renders the `newspack-blocks/homepage-posts` block on server.
10
+ *
11
+ * @param array $attributes The block attributes.
12
+ *
13
+ * @return string Returns the post content with latest posts added.
14
+ */
15
+ function newspack_blocks_render_block_homepage_articles( $attributes ) {
16
+ $article_query = new WP_Query( Newspack_Blocks::build_articles_query( $attributes ) );
17
+
18
+ $classes = Newspack_Blocks::block_classes( 'homepage-articles', $attributes, [ 'wpnbha' ] );
19
+
20
+ if ( isset( $attributes['postLayout'] ) && 'grid' === $attributes['postLayout'] ) {
21
+ $classes .= ' is-grid';
22
+ }
23
+ if ( isset( $attributes['columns'] ) && 'grid' === $attributes['postLayout'] ) {
24
+ $classes .= ' columns-' . $attributes['columns'];
25
+ }
26
+ if ( $attributes['showImage'] ) {
27
+ $classes .= ' show-image';
28
+ }
29
+ if ( $attributes['showImage'] && isset( $attributes['mediaPosition'] ) ) {
30
+ $classes .= ' image-align' . $attributes['mediaPosition'];
31
+ }
32
+ if ( isset( $attributes['typeScale'] ) ) {
33
+ $classes .= ' ts-' . $attributes['typeScale'];
34
+ }
35
+ if ( $attributes['showImage'] && isset( $attributes['imageScale'] ) ) {
36
+ $classes .= ' is-' . $attributes['imageScale'];
37
+ }
38
+ if ( $attributes['showImage'] && $attributes['mobileStack'] ) {
39
+ $classes .= ' mobile-stack';
40
+ }
41
+ if ( $attributes['showCaption'] ) {
42
+ $classes .= ' show-caption';
43
+ }
44
+ if ( $attributes['showCategory'] ) {
45
+ $classes .= ' show-category';
46
+ }
47
+ if ( isset( $attributes['className'] ) ) {
48
+ $classes .= ' ' . $attributes['className'];
49
+ }
50
+
51
+ if ( '' !== $attributes['textColor'] || '' !== $attributes['customTextColor'] ) {
52
+ $classes .= ' has-text-color';
53
+ }
54
+ if ( '' !== $attributes['textColor'] ) {
55
+ $classes .= ' has-' . $attributes['textColor'] . '-color';
56
+ }
57
+
58
+ $styles = '';
59
+
60
+ if ( '' !== $attributes['customTextColor'] ) {
61
+ $styles = 'color: ' . $attributes['customTextColor'] . ';';
62
+ }
63
+
64
+ $articles_rest_url = add_query_arg(
65
+ array_merge(
66
+ array_map(
67
+ function( $attribute ) {
68
+ return false === $attribute ? '0' : $attribute;
69
+ },
70
+ $attributes
71
+ ),
72
+ [ 'page' => 2 ]
73
+ ),
74
+ rest_url( '/newspack-blocks/v1/articles' )
75
+ );
76
+
77
+ ob_start();
78
+
79
+ if ( $article_query->have_posts() ) : ?>
80
+ <div>
81
+ <div data-posts-container class="<?php echo esc_attr( $classes ); ?>" style="<?php echo esc_attr( $styles ); ?>">
82
+ <?php if ( '' !== $attributes['sectionHeader'] ) : ?>
83
+ <h2 class="article-section-title">
84
+ <span><?php echo wp_kses_post( $attributes['sectionHeader'] ); ?></span>
85
+ </h2>
86
+ <?php endif; ?>
87
+ <?php
88
+
89
+ /*
90
+ * We are not using an AMP-based renderer on AMP requests because it has limitations
91
+ * around dynamically calculating the height of the the article list on load.
92
+ * As a result we render the same standards-based markup for all requests.
93
+ */
94
+
95
+ echo Newspack_Blocks::template_inc(
96
+ __DIR__ . '/templates/articles-list.php',
97
+ [
98
+ 'articles_rest_url' => $articles_rest_url,
99
+ 'article_query' => $article_query,
100
+ 'attributes' => $attributes,
101
+ ]
102
+ );
103
+ ?>
104
+ </div>
105
+ <?php
106
+
107
+ /*
108
+ * AMP-requests cannot contain client-side scripting (eg: JavaScript). As a result
109
+ * we do not display the "More" button on AMP-requests. This feature is deliberately
110
+ * disabled.
111
+ *
112
+ * @see https://github.com/Automattic/newspack-blocks/pull/226#issuecomment-558695909
113
+ * @see https://wp.me/paYJgx-jW
114
+ */
115
+ $page = $article_query->paged ?? 1;
116
+
117
+ $has_more_pages = ( ++$page ) <= $article_query->max_num_pages;
118
+
119
+ if ( ! Newspack_Blocks::is_amp() && $has_more_pages && boolval( $attributes['moreButton'] ) ) :
120
+ ?>
121
+ <button type="button" data-load-more-btn data-load-more-url="<?php echo esc_url( $articles_rest_url ); ?>">
122
+ <?php _e( 'Load more articles', 'newspack-blocks' ); ?>
123
+ </button>
124
+ <p data-load-more-loading-text hidden>
125
+ <?php _e( 'Loading...', 'newspack-blocks' ); ?>
126
+ </p>
127
+ <p data-load-more-error-text hidden>
128
+ <?php _e( 'Something went wrong. Please refresh the page and/or try again.', 'newspack-blocks' ); ?>
129
+ </p>
130
+ <?php endif; ?>
131
+
132
+ </div>
133
+ <?php
134
+ endif;
135
+
136
+ $content = ob_get_clean();
137
+ Newspack_Blocks::enqueue_view_assets( 'homepage-articles' );
138
+
139
+ return $content;
140
+ }
141
+
142
+ /**
143
+ * Registers the `newspack-blocks/homepage-articles` block on server.
144
+ */
145
+ function newspack_blocks_register_homepage_articles() {
146
+ $block = json_decode(
147
+ file_get_contents( __DIR__ . '/block.json' ), // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
148
+ true
149
+ );
150
+ register_block_type(
151
+ apply_filters( 'newspack_blocks_block_name', 'newspack-blocks/' . $block['name'] ),
152
+ apply_filters(
153
+ 'newspack_blocks_block_args',
154
+ array(
155
+ 'attributes' => $block['attributes'],
156
+ 'render_callback' => 'newspack_blocks_render_block_homepage_articles',
157
+ ),
158
+ $block['name']
159
+ )
160
+ );
161
+ }
162
+ add_action( 'init', 'newspack_blocks_register_homepage_articles' );
163
+
164
+
165
+ /**
166
+ * Renders author avatar markup.
167
+ *
168
+ * @param array $author_info Author info array.
169
+ *
170
+ * @return string Returns formatted Avatar markup
171
+ */
172
+ function newspack_blocks_format_avatars( $author_info ) {
173
+ $elements = array_map(
174
+ function ( $author ) {
175
+ return sprintf( '<a href="%s">%s</a>', $author->url, $author->avatar );
176
+ },
177
+ $author_info
178
+ );
179
+
180
+ return implode( '', $elements );
181
+ }
182
+
183
+ /**
184
+ * Renders byline markup.
185
+ *
186
+ * @param array $author_info Author info array.
187
+ *
188
+ * @return string Returns byline markup.
189
+ */
190
+ function newspack_blocks_format_byline( $author_info ) {
191
+ $index = -1;
192
+ $elements = array_merge(
193
+ [
194
+ esc_html_x( 'by', 'post author', 'newspack-blocks' ) . ' ',
195
+ ],
196
+ array_reduce(
197
+ $author_info,
198
+ function ( $accumulator, $author ) use ( $author_info, &$index ) {
199
+ $index ++;
200
+ $penultimate = count( $author_info ) - 2;
201
+
202
+ return array_merge(
203
+ $accumulator,
204
+ [
205
+ sprintf(
206
+ /* translators: 1: author link. 2: author name. 3. variable seperator (comma, 'and', or empty) */
207
+ '<span class="author vcard"><a class="url fn n" href="%1$s">%2$s</a></span>',
208
+ esc_url( get_author_posts_url( $author->ID ) ),
209
+ esc_html( $author->display_name )
210
+ ),
211
+ ( $index < $penultimate ) ? ', ' : '',
212
+ ( count( $author_info ) > 1 && $penultimate === $index ) ? esc_html_x( ' and ', 'post author', 'newspack-blocks' ) : '',
213
+ ]
214
+ );
215
+ },
216
+ []
217
+ )
218
+ );
219
+
220
+ return implode( '', $elements );
221
+ }
blog-posts-block/newspack-homepage-articles/blocks/homepage-articles/view.scss ADDED
@@ -0,0 +1,554 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @import "../../shared/sass/variables";
2
+ @import "../../shared/sass/mixins";
3
+
4
+ .wpnbha {
5
+ margin-bottom: 1em;
6
+
7
+ article {
8
+ margin-bottom: 1.5em;
9
+ word-break: break-word;
10
+ overflow-wrap: break-word;
11
+ position: relative;
12
+
13
+ &:last-of-type {
14
+ margin-bottom: 0;
15
+ }
16
+ }
17
+
18
+ /* Section header */
19
+ .article-section-title {
20
+ font-size: $font__size-sm;
21
+ margin-bottom: 0.5em;
22
+ width: 100%; // make sure this isn't caught up in the flex styles.
23
+ }
24
+
25
+ /* Column styles */
26
+ &.is-grid {
27
+ display: flex;
28
+ flex-wrap: wrap;
29
+ justify-content: space-between;
30
+ padding: 0;
31
+ list-style: none;
32
+
33
+ article {
34
+ flex-basis: 100%;
35
+
36
+ @include media(tablet) {
37
+ &:last-child,
38
+ & {
39
+ margin-bottom: 1em;
40
+ }
41
+ }
42
+ }
43
+ }
44
+
45
+ @include media(mobile) {
46
+ &.columns-3 article,
47
+ &.columns-6 article {
48
+ flex-basis: calc( 33.333% - 16px );
49
+ }
50
+
51
+ &.columns-2 article,
52
+ &.columns-4 article,
53
+ &.columns-5 article {
54
+ flex-basis: calc( 50% - 16px);
55
+ }
56
+
57
+ &.columns-5 article:last-of-type:nth-child(odd) {
58
+ flex-grow: 1;
59
+ }
60
+ }
61
+
62
+ @include media(tablet) {
63
+ @for $i from 2 through 6 {
64
+ &.columns-#{ $i } article {
65
+ flex-basis: calc( ( 100% / #{$i} ) - 16px );
66
+ }
67
+ }
68
+ }
69
+
70
+ /* Image styles */
71
+
72
+ .post-thumbnail {
73
+ margin: 0;
74
+
75
+ img {
76
+ height: auto;
77
+ width: 100%;
78
+ }
79
+ }
80
+
81
+ figcaption {
82
+ font-size: $font__size-xxs;
83
+ }
84
+
85
+ &.image-aligntop .post-thumbnail {
86
+ margin-bottom: 0.25em;
87
+
88
+ figcaption {
89
+ margin-bottom: 0.5em;
90
+ }
91
+ }
92
+
93
+ &.image-alignleft,
94
+ &.image-alignright {
95
+ .post-has-image {
96
+ display: flex;
97
+
98
+ .post-thumbnail {
99
+ flex-basis: 33%;
100
+ }
101
+ .entry-wrapper {
102
+ flex-basis: 67%;
103
+ }
104
+ }
105
+
106
+ &.mobile-stack .post-has-image {
107
+ display: block;
108
+ }
109
+
110
+ // Image scale
111
+ @include media(mobile) {
112
+ &.mobile-stack .post-has-image {
113
+ display: flex;
114
+ }
115
+
116
+ &.is-4 {
117
+ .post-thumbnail {
118
+ flex-basis: 75%;
119
+ }
120
+ .entry-wrapper {
121
+ flex-basis: 25%;
122
+ }
123
+ }
124
+
125
+ &.is-3 {
126
+ .post-thumbnail,
127
+ .entry-wrapper {
128
+ flex-basis: 50%;
129
+ }
130
+ }
131
+
132
+ // is-2 matches the mobile default above
133
+ }
134
+
135
+ &.is-1 {
136
+ .post-thumbnail {
137
+ flex-basis: 25%;
138
+ }
139
+ .entry-wrapper {
140
+ flex-basis: 75%;
141
+ }
142
+ }
143
+ }
144
+
145
+ &.image-alignleft {
146
+ .post-thumbnail {
147
+ margin-right: 1em;
148
+ }
149
+ }
150
+
151
+ &.image-alignright {
152
+ .post-thumbnail {
153
+ margin-left: 1em;
154
+ }
155
+ .entry-wrapper {
156
+ order: -1;
157
+ }
158
+ }
159
+
160
+ /* Headings */
161
+ .entry-title {
162
+ margin: 0 0 0.25em;
163
+ a {
164
+ color: inherit;
165
+ text-decoration: none;
166
+ }
167
+ }
168
+
169
+ /* Article meta */
170
+ .cat-links {
171
+ font-size: $font__size-xxs;
172
+ font-weight: bold;
173
+ margin: 0 0 0.5em;
174
+
175
+ a {
176
+ text-decoration: none;
177
+
178
+ &:hover {
179
+ text-decoration: underline;
180
+ }
181
+ }
182
+ }
183
+
184
+ .entry-meta {
185
+ display: flex;
186
+ flex-wrap: wrap;
187
+ align-items: center;
188
+ margin-top: 0.5em;
189
+
190
+ .byline:not(:last-child) {
191
+ margin-right: 1.5em;
192
+ }
193
+ }
194
+
195
+ .avatar {
196
+ border-radius: 100%;
197
+ display: block;
198
+ margin-right: 0.5em;
199
+ }
200
+
201
+ p {
202
+ margin: 0.5em 0;
203
+ }
204
+
205
+ &.has-text-color {
206
+ .article-section-title,
207
+ .entry-title,
208
+ .entry-title a,
209
+ .entry-title a:visited,
210
+ .entry-meta,
211
+ .entry-meta a,
212
+ .entry-meta .byline a,
213
+ .entry-meta .byline a:visited,
214
+ .cat-links,
215
+ .cat-links a,
216
+ .cat-links a:visited,
217
+ figcaption {
218
+ color: inherit;
219
+ }
220
+ }
221
+
222
+ &.has-text-color {
223
+ .entry-meta span:not(.avatar) {
224
+ opacity: 0.8;
225
+ }
226
+ }
227
+
228
+ &.image-alignbehind {
229
+ .post-has-image {
230
+ display: flex;
231
+ align-items: flex-end;
232
+ position: relative;
233
+
234
+ .post-thumbnail {
235
+ bottom: 0;
236
+ left: 0;
237
+ overflow: hidden;
238
+ position: absolute;
239
+ right: 0;
240
+ top: 0;
241
+
242
+ img {
243
+ height: 100%;
244
+ object-fit: cover;
245
+ max-width: 1000%;
246
+ width: 100%;
247
+ }
248
+
249
+ figcaption {
250
+ bottom: 1em;
251
+ /* autoprefixer: ignore next */
252
+ -webkit-box-orient: vertical;
253
+ color: rgba(white, 0.9);
254
+ display: -webkit-box;
255
+ font-style: italic;
256
+ left: 0;
257
+ -webkit-line-clamp: 1;
258
+ margin: 0;
259
+ max-height: 1.6em;
260
+ overflow: hidden;
261
+ padding: 0 1em;
262
+ position: absolute;
263
+ right: 0;
264
+ text-align: right;
265
+ text-overflow: ellipsis;
266
+ z-index: 2;
267
+ }
268
+
269
+ &:after {
270
+ background: rgba( 0, 0, 0, 0.5 );
271
+ bottom: 0;
272
+ content: '';
273
+ left: 0;
274
+ position: absolute;
275
+ right: 0;
276
+ top: 0;
277
+ z-index: 1;
278
+ }
279
+ }
280
+
281
+ .entry-wrapper {
282
+ padding: 2em;
283
+ position: relative;
284
+ z-index: 2;
285
+ }
286
+
287
+ .entry-wrapper,
288
+ .entry-title a,
289
+ .entry-meta,
290
+ .entry-meta .byline a,
291
+ .cat-links a {
292
+ color: #fff;
293
+ }
294
+
295
+ }
296
+ }
297
+ }
298
+
299
+ /* Some really rough font sizing */
300
+ .wpnbha {
301
+ /* 'Normal' size */
302
+ article {
303
+ .entry-title {
304
+ font-size: 1.2em;
305
+ }
306
+ .entry-meta {
307
+ font-size: 0.8em;
308
+ }
309
+
310
+ .avatar {
311
+ height: 25px;
312
+ width: 25px;
313
+ }
314
+
315
+ @include media(tablet) {
316
+ .entry-title {
317
+ font-size: 1.6em;
318
+ }
319
+
320
+ .avatar {
321
+ height: 40px;
322
+ width: 40px;
323
+ }
324
+ }
325
+ }
326
+
327
+ &.ts-10,
328
+ &.ts-9,
329
+ &.ts-8 {
330
+ .entry-title {
331
+ line-height: 1.1em;
332
+ }
333
+ @include media(tablet) {
334
+ article .avatar {
335
+ height: 2.4em;
336
+ width: 2.4em;
337
+ }
338
+ }
339
+
340
+ }
341
+
342
+ &.ts-10 article {
343
+ .entry-title {
344
+ font-size: 2.6em;
345
+ }
346
+ @include media(tablet) {
347
+ .entry-title {
348
+ font-size: 3.6em;
349
+ }
350
+ }
351
+ @include media(desktop) {
352
+ .entry-title {
353
+ font-size: 4.8em;
354
+ }
355
+ }
356
+ }
357
+
358
+ &.ts-9 article {
359
+ .entry-title {
360
+ font-size: 2.4em;
361
+ }
362
+ @include media(tablet) {
363
+ .entry-title {
364
+ font-size: 3.4em;
365
+ }
366
+ }
367
+ @include media(desktop) {
368
+ .entry-title {
369
+ font-size: 4.2em;
370
+ }
371
+ }
372
+ }
373
+
374
+ &.ts-8 article {
375
+ .entry-title {
376
+ font-size: 2.2em;
377
+ }
378
+ @include media(tablet) {
379
+ .entry-title {
380
+ font-size: 3.0em;
381
+ }
382
+ }
383
+ @include media(desktop) {
384
+ .entry-title {
385
+ font-size: 3.6em;
386
+ }
387
+ }
388
+ }
389
+
390
+ &.ts-7 article {
391
+ .entry-title {
392
+ font-size: 2em;
393
+ }
394
+ @include media( tablet) {
395
+ .entry-title {
396
+ font-size: 2.4em;
397
+ }
398
+ .avatar {
399
+ height: 48px;
400
+ width: 48px;
401
+ }
402
+ }
403
+ @include media(desktop) {
404
+ .entry-title {
405
+ font-size: 3em;
406
+ }
407
+ }
408
+ }
409
+
410
+ &.ts-6 article {
411
+ .entry-title {
412
+ font-size: 1.7em;
413
+ }
414
+ @include media(tablet) {
415
+ .entry-title {
416
+ font-size: 2.0em;
417
+ }
418
+ .avatar {
419
+ height: 44px;
420
+ width: 44px;
421
+ }
422
+ }
423
+ @include media(desktop) {
424
+ .entry-title {
425
+ font-size: 2.4em;
426
+ }
427
+ }
428
+ }
429
+
430
+ &.ts-5 article {
431
+ .entry-title {
432
+ font-size: 1.4em;
433
+ }
434
+ @include media(tablet) {
435
+ .entry-title {
436
+ font-size: 1.8em;
437
+ }
438
+ .avatar {
439
+ height: 40px;
440
+ width: 40px;
441
+ }
442
+ }
443
+ @include media(desktop) {
444
+ .entry-title {
445
+ font-size: 2.0em;
446
+ }
447
+ }
448
+ }
449
+
450
+ /* Type Scale 4: default */
451
+
452
+ &.ts-3 article {
453
+ .entry-title {
454
+ font-size: 1.0em;
455
+ }
456
+ .entry-wrapper p {
457
+ font-size: 0.8em;
458
+ }
459
+ .entry-meta {
460
+ font-size: 0.7em;
461
+ }
462
+ @include media( tablet ) {
463
+ .entry-title {
464
+ font-size: 1.2em
465
+ }
466
+
467
+ .avatar {
468
+ height: 32px;
469
+ width: 32px;
470
+ }
471
+ }
472
+ }
473
+
474
+ &.ts-2 article {
475
+ .entry-title {
476
+ font-size: 0.8em;
477
+ }
478
+ .entry-wrapper p,
479
+ .entry-meta {
480
+ font-size: 0.7em;
481
+ }
482
+
483
+ @include media( tablet ) {
484
+ .entry-title {
485
+ font-size: 0.9em;
486
+ }
487
+
488
+ .avatar {
489
+ height: 28px;
490
+ width: 28px;
491
+ }
492
+ }
493
+ }
494
+
495
+ &.ts-1 article {
496
+ .entry-title,
497
+ .entry-wrapper p {
498
+ font-size: 0.7em;
499
+ }
500
+ .entry-meta {
501
+ font-size: 0.6em;
502
+ }
503
+ @include media( tablet ) {
504
+ .avatar {
505
+ height: 24px;
506
+ width: 24px;
507
+ }
508
+ }
509
+ }
510
+ }
511
+
512
+ /* Block styles */
513
+
514
+ .wpnbha.is-style-borders {
515
+ article {
516
+ border: solid rgba(0, 0, 0, 0.2);
517
+ border-width: 0 0 1px;
518
+ margin-bottom: 1em;
519
+ padding-bottom: 1em;
520
+
521
+ &:last-of-type {
522
+ margin-bottom: 0;
523
+
524
+ &:not(:first-of-type) {
525
+ border-bottom: 0;
526
+ }
527
+ }
528
+ }
529
+
530
+ @include media(tablet) {
531
+
532
+ @for $i from 2 through 6 {
533
+ &.columns-#{ $i } article {
534
+ padding-right: calc( ( 16px * #{$i} ) / ( #{$i} - 1 ) );
535
+ }
536
+ }
537
+
538
+ &.is-grid {
539
+ article {
540
+ border-width: 0 1px 0 0;
541
+ }
542
+ }
543
+
544
+ &.is-grid article:last-of-type,
545
+ &.columns-1 article,
546
+ &.columns-2 article:nth-of-type(2n),
547
+ &.columns-3 article:nth-of-type(3n),
548
+ &.columns-4 article:nth-of-type(4n),
549
+ &.columns-5 article:nth-of-type(5n),
550
+ &.columns-6 article:nth-of-type(6n) {
551
+ border: 0;
552
+ }
553
+ }
554
+ }
blog-posts-block/newspack-homepage-articles/class-newspack-blocks-api.php ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Register Newspack Blocks rest fields
4
+ *
5
+ * @package Newspack_Blocks
6
+ */
7
+
8
+ /**
9
+ * `Newspack_Blocks_API` is a wrapper for `register_rest_fields()`
10
+ */
11
+ class Newspack_Blocks_API {
12
+
13
+ /**
14
+ * Register Newspack REST fields.
15
+ */
16
+ public static function register_rest_fields() {
17
+ register_rest_field(
18
+ [ 'post', 'page' ],
19
+ 'newspack_featured_image_src',
20
+ [
21
+ 'get_callback' => [ 'Newspack_Blocks_API', 'newspack_blocks_get_image_src' ],
22
+ 'schema' => [
23
+ 'context' => [
24
+ 'edit',
25
+ ],
26
+ 'type' => 'array',
27
+ ],
28
+ ]
29
+ );
30
+
31
+ register_rest_field(
32
+ [ 'post', 'page' ],
33
+ 'newspack_featured_image_caption',
34
+ [
35
+ 'get_callback' => [ 'Newspack_Blocks_API', 'newspack_blocks_get_image_caption' ],
36
+ 'schema' => [
37
+ 'context' => [
38
+ 'edit',
39
+ ],
40
+ 'type' => 'string',
41
+ ],
42
+ ]
43
+ );
44
+
45
+ /* Add author info source */
46
+ register_rest_field(
47
+ 'post',
48
+ 'newspack_author_info',
49
+ [
50
+ 'get_callback' => [ 'Newspack_Blocks_API', 'newspack_blocks_get_author_info' ],
51
+ 'schema' => [
52
+ 'context' => [
53
+ 'edit',
54
+ ],
55
+ 'type' => 'array',
56
+ ],
57
+ ]
58
+ );
59
+
60
+ /* Add first category source */
61
+ register_rest_field(
62
+ 'post',
63
+ 'newspack_category_info',
64
+ [
65
+ 'get_callback' => [ 'Newspack_Blocks_API', 'newspack_blocks_get_primary_category' ],
66
+ 'schema' => [
67
+ 'context' => [
68
+ 'edit',
69
+ ],
70
+ 'type' => 'string',
71
+ ],
72
+ ]
73
+ );
74
+ }
75
+
76
+ /**
77
+ * Get thumbnail featured image source for the rest field.
78
+ *
79
+ * @param array $object The object info.
80
+ * @return array | bool Featured image if available, false if not.
81
+ */
82
+ public static function newspack_blocks_get_image_src( $object ) {
83
+ $featured_image_set = [];
84
+
85
+ if ( 0 === $object['featured_media'] ) {
86
+ return false;
87
+ }
88
+
89
+ // Landscape image.
90
+ $landscape_size = Newspack_Blocks::image_size_for_orientation( 'landscape' );
91
+
92
+ $feat_img_array_landscape = wp_get_attachment_image_src(
93
+ $object['featured_media'],
94
+ $landscape_size,
95
+ false
96
+ );
97
+ $featured_image_set['landscape'] = $feat_img_array_landscape[0];
98
+
99
+ // Portrait image.
100
+ $portrait_size = Newspack_Blocks::image_size_for_orientation( 'portrait' );
101
+
102
+ $feat_img_array_portrait = wp_get_attachment_image_src(
103
+ $object['featured_media'],
104
+ $portrait_size,
105
+ false
106
+ );
107
+ $featured_image_set['portrait'] = $feat_img_array_portrait[0];
108
+
109
+ // Square image.
110
+ $square_size = Newspack_Blocks::image_size_for_orientation( 'square' );
111
+
112
+ $feat_img_array_square = wp_get_attachment_image_src(
113
+ $object['featured_media'],
114
+ $square_size,
115
+ false
116
+ );
117
+ $featured_image_set['square'] = $feat_img_array_square[0];
118
+
119
+ // Uncropped image.
120
+ $uncropped_size = 'newspack-article-block-uncropped';
121
+
122
+ $feat_img_array_uncropped = wp_get_attachment_image_src(
123
+ $object['featured_media'],
124
+ $uncropped_size,
125
+ false
126
+ );
127
+ $featured_image_set['uncropped'] = $feat_img_array_uncropped[0];
128
+
129
+ return $featured_image_set;
130
+ }
131
+
132
+ /**
133
+ * Get thumbnail featured image captions for the rest field.
134
+ *
135
+ * @param array $object The object info.
136
+ * @return string|null Image caption on success, null on failure.
137
+ */
138
+ public static function newspack_blocks_get_image_caption( $object ) {
139
+ return (int) $object['featured_media'] > 0 ? trim( wp_get_attachment_caption( $object['featured_media'] ) ) : null;
140
+ }
141
+
142
+ /**
143
+ * Get author info for the rest field.
144
+ *
145
+ * @param array $object The object info.
146
+ * @return array Author data.
147
+ */
148
+ public static function newspack_blocks_get_author_info( $object ) {
149
+ $author_data = [];
150
+
151
+ if ( function_exists( 'coauthors_posts_links' ) ) :
152
+ $authors = get_coauthors();
153
+
154
+ foreach ( $authors as $author ) {
155
+ // Check if this is a guest author post type.
156
+ if ( 'guest-author' === get_post_type( $author->ID ) ) {
157
+ // If yes, make sure the author actually has an avatar set; otherwise, coauthors_get_avatar returns a featured image.
158
+ if ( get_post_thumbnail_id( $author->ID ) ) {
159
+ $author_avatar = coauthors_get_avatar( $author, 48 );
160
+ } else {
161
+ // If there is no avatar, force it to return the current fallback image.
162
+ $author_avatar = get_avatar( ' ' );
163
+ }
164
+ } else {
165
+ $author_avatar = coauthors_get_avatar( $author, 48 );
166
+ }
167
+ $author_data[] = array(
168
+ /* Get the author name */
169
+ 'display_name' => esc_html( $author->display_name ),
170
+ /* Get the author avatar */
171
+ 'avatar' => wp_kses_post( $author_avatar ),
172
+ );
173
+ }
174
+ else :
175
+ $author_data[] = array(
176
+ /* Get the author name */
177
+ 'display_name' => get_the_author_meta( 'display_name', $object['author'] ),
178
+ /* Get the author avatar */
179
+ 'avatar' => get_avatar( $object['author'], 48 ),
180
+ );
181
+ endif;
182
+
183
+ /* Return the author data */
184
+ return $author_data;
185
+ }
186
+
187
+ /**
188
+ * Get primary category for the rest field.
189
+ *
190
+ * @param array $object The object info.
191
+ * @return string Category name.
192
+ */
193
+ public static function newspack_blocks_get_primary_category( $object ) {
194
+ $category = false;
195
+
196
+ // Use Yoast primary category if set.
197
+ if ( class_exists( 'WPSEO_Primary_Term' ) ) {
198
+ $primary_term = new WPSEO_Primary_Term( 'category', $object['id'] );
199
+ $category_id = $primary_term->get_primary_term();
200
+ if ( $category_id ) {
201
+ $category = get_term( $category_id );
202
+ }
203
+ }
204
+
205
+ if ( ! $category ) {
206
+ $categories_list = get_the_category( $object['id'] );
207
+ if ( ! empty( $categories_list ) ) {
208
+ $category = $categories_list[0];
209
+ }
210
+ }
211
+
212
+ if ( ! $category ) {
213
+ return '';
214
+ }
215
+
216
+ return $category->name;
217
+ }
218
+ }
219
+
220
+ add_action( 'rest_api_init', array( 'Newspack_Blocks_API', 'register_rest_fields' ) );
blog-posts-block/newspack-homepage-articles/class-newspack-blocks.php ADDED
@@ -0,0 +1,393 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Newspack blocks functionality
4
+ *
5
+ * @package Newspack_Blocks
6
+ */
7
+
8
+ /**
9
+ * Newspack blocks functionality
10
+ */
11
+ class Newspack_Blocks {
12
+
13
+ /**
14
+ * Gather dependencies and paths needed for script enqueuing.
15
+ *
16
+ * @param string $script_path Path to the script relative to plugin root.
17
+ *
18
+ * @return array Associative array including dependency array, version, and web path to the script. Returns false if script doesn't exist.
19
+ */
20
+ public static function script_enqueue_helper( $script_path ) {
21
+ $local_path = NEWSPACK_BLOCKS__PLUGIN_DIR . $script_path;
22
+ if ( ! file_exists( $local_path ) ) {
23
+ return false;
24
+ }
25
+
26
+ $path_info = pathinfo( $local_path );
27
+ $asset_path = $path_info['dirname'] . '/' . $path_info['filename'] . '.asset.php';
28
+ $script_data = file_exists( $asset_path )
29
+ ? require $asset_path
30
+ : array(
31
+ 'dependencies' => array(),
32
+ 'version' => filemtime( $local_path ),
33
+ );
34
+
35
+ $script_data['script_path'] = plugins_url( $script_path, __FILE__ );
36
+ return $script_data;
37
+ }
38
+
39
+ /**
40
+ * Enqueue block scripts and styles for editor.
41
+ */
42
+ public static function enqueue_block_editor_assets() {
43
+ $script_data = static::script_enqueue_helper( NEWSPACK_BLOCKS__BLOCKS_DIRECTORY . 'editor.js' );
44
+
45
+ if ( $script_data ) {
46
+ wp_enqueue_script(
47
+ 'newspack-blocks-editor',
48
+ $script_data['script_path'],
49
+ $script_data['dependencies'],
50
+ $script_data['version'],
51
+ true
52
+ );
53
+ }
54
+
55
+ $editor_style = plugins_url( NEWSPACK_BLOCKS__BLOCKS_DIRECTORY . 'editor.css', __FILE__ );
56
+
57
+ wp_enqueue_style(
58
+ 'newspack-blocks-editor',
59
+ $editor_style,
60
+ array(),
61
+ NEWSPACK_BLOCKS__VERSION
62
+ );
63
+
64
+ wp_set_script_translations(
65
+ 'newspack-blocks-editor',
66
+ 'newspack-blocks',
67
+ plugin_dir_path( __FILE__ ) . 'languages'
68
+ );
69
+ }
70
+
71
+ /**
72
+ * Enqueue block scripts and styles for view.
73
+ */
74
+ public static function manage_view_scripts() {
75
+ if ( is_admin() ) {
76
+ // In editor environment, do nothing.
77
+ return;
78
+ }
79
+ $src_directory = NEWSPACK_BLOCKS__PLUGIN_DIR . 'src/blocks/';
80
+ $dist_directory = NEWSPACK_BLOCKS__PLUGIN_DIR . 'dist/';
81
+ $iterator = new DirectoryIterator( $src_directory );
82
+ foreach ( $iterator as $block_directory ) {
83
+ if ( ! $block_directory->isDir() || $block_directory->isDot() ) {
84
+ continue;
85
+ }
86
+ $type = $block_directory->getFilename();
87
+
88
+ /* If view.php is found, include it and use for block rendering. */
89
+ $view_php_path = $src_directory . $type . '/view.php';
90
+ if ( file_exists( $view_php_path ) ) {
91
+ include_once $view_php_path;
92
+ continue;
93
+ }
94
+
95
+ /* If view.php is missing but view Javascript file is found, do generic view asset loading. */
96
+ $view_js_path = $dist_directory . $type . '/view.js';
97
+ if ( file_exists( $view_js_path ) ) {
98
+ register_block_type(
99
+ "newspack-blocks/{$type}",
100
+ array(
101
+ 'render_callback' => function( $attributes, $content ) use ( $type ) {
102
+ Newspack_Blocks::enqueue_view_assets( $type );
103
+ return $content;
104
+ },
105
+ )
106
+ );
107
+ }
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Enqueue block styles stylesheet.
113
+ */
114
+ public static function enqueue_block_styles_assets() {
115
+ $style_path = NEWSPACK_BLOCKS__BLOCKS_DIRECTORY . 'block_styles' . ( is_rtl() ? '.rtl' : '' ) . '.css';
116
+ if ( file_exists( NEWSPACK_BLOCKS__PLUGIN_DIR . $style_path ) ) {
117
+ wp_enqueue_style(
118
+ 'newspack-blocks-block-styles-stylesheet',
119
+ plugins_url( $style_path, __FILE__ ),
120
+ array(),
121
+ NEWSPACK_BLOCKS__VERSION
122
+ );
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Enqueue view scripts and styles for a single block.
128
+ *
129
+ * @param string $type The block's type.
130
+ */
131
+ public static function enqueue_view_assets( $type ) {
132
+ $style_path = apply_filters(
133
+ 'newspack_blocks_enqueue_view_assets',
134
+ NEWSPACK_BLOCKS__BLOCKS_DIRECTORY . $type . '/view' . ( is_rtl() ? '.rtl' : '' ) . '.css',
135
+ $type,
136
+ is_rtl()
137
+ );
138
+
139
+ if ( file_exists( NEWSPACK_BLOCKS__PLUGIN_DIR . $style_path ) ) {
140
+ wp_enqueue_style(
141
+ "newspack-blocks-{$type}",
142
+ plugins_url( $style_path, __FILE__ ),
143
+ array(),
144
+ NEWSPACK_BLOCKS__VERSION
145
+ );
146
+ }
147
+ if ( static::is_amp() ) {
148
+ return;
149
+ }
150
+ $script_data = static::script_enqueue_helper( NEWSPACK_BLOCKS__BLOCKS_DIRECTORY . $type . '/view.js' );
151
+ if ( $script_data ) {
152
+ wp_enqueue_script(
153
+ "newspack-blocks-{$type}",
154
+ $script_data['script_path'],
155
+ $script_data['dependencies'],
156
+ $script_data['version'],
157
+ true
158
+ );
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Utility to assemble the class for a server-side rendered block.
164
+ *
165
+ * @param string $type The block type.
166
+ * @param array $attributes Block attributes.
167
+ * @param array $extra Additional classes to be added to the class list.
168
+ *
169
+ * @return string Class list separated by spaces.
170
+ */
171
+ public static function block_classes( $type, $attributes = array(), $extra = array() ) {
172
+ $classes = [ "wp-block-newspack-blocks-{$type}" ];
173
+
174
+ if ( ! empty( $attributes['align'] ) ) {
175
+ $classes[] = 'align' . $attributes['align'];
176
+ }
177
+ if ( isset( $attributes['className'] ) ) {
178
+ array_push( $classes, $attributes['className'] );
179
+ }
180
+ if ( is_array( $extra ) && ! empty( $extra ) ) {
181
+ $classes = array_merge( $classes, $extra );
182
+ }
183
+
184
+ return implode( $classes, ' ' );
185
+ }
186
+
187
+ /**
188
+ * Checks whether the current view is served in AMP context.
189
+ *
190
+ * @return bool True if AMP, false otherwise.
191
+ */
192
+ public static function is_amp() {
193
+ return ! is_admin() && function_exists( 'is_amp_endpoint' ) && is_amp_endpoint();
194
+ }
195
+
196
+ /**
197
+ * Return the most appropriate thumbnail size to display.
198
+ *
199
+ * @param string $orientation The block's orientation settings: landscape|portrait|square.
200
+ *
201
+ * @return string Returns the thumbnail key to use.
202
+ */
203
+ public static function image_size_for_orientation( $orientation = 'landscape' ) {
204
+ $sizes = array(
205
+ 'landscape' => array(
206
+ 'large' => array(
207
+ 1200,
208
+ 900,
209
+ ),
210
+ 'medium' => array(
211
+ 800,
212
+ 600,
213
+ ),
214
+ 'small' => array(
215
+ 400,
216
+ 300,
217
+ ),
218
+ 'tiny' => array(
219
+ 200,
220
+ 150,
221
+ ),
222
+ ),
223
+ 'portrait' => array(
224
+ 'large' => array(
225
+ 900,
226
+ 1200,
227
+ ),
228
+ 'medium' => array(
229
+ 600,
230
+ 800,
231
+ ),
232
+ 'small' => array(
233
+ 300,
234
+ 400,
235
+ ),
236
+ 'tiny' => array(
237
+ 150,
238
+ 200,
239
+ ),
240
+ ),
241
+ 'square' => array(
242
+ 'large' => array(
243
+ 1200,
244
+ 1200,
245
+ ),
246
+ 'medium' => array(
247
+ 800,
248
+ 800,
249
+ ),
250
+ 'small' => array(
251
+ 400,
252
+ 400,
253
+ ),
254
+ 'tiny' => array(
255
+ 200,
256
+ 200,
257
+ ),
258
+ ),
259
+ );
260
+
261
+ foreach ( $sizes[ $orientation ] as $key => $dimensions ) {
262
+ $attachment = wp_get_attachment_image_src(
263
+ get_post_thumbnail_id( get_the_ID() ),
264
+ 'newspack-article-block-' . $orientation . '-' . $key
265
+ );
266
+ if ( $dimensions[0] === $attachment[1] && $dimensions[1] === $attachment[2] ) {
267
+ return 'newspack-article-block-' . $orientation . '-' . $key;
268
+ }
269
+ }
270
+ }
271
+
272
+ /**
273
+ * Registers image sizes required for Newspack Blocks.
274
+ */
275
+ public static function add_image_sizes() {
276
+ add_image_size( 'newspack-article-block-landscape-large', 1200, 900, true );
277
+ add_image_size( 'newspack-article-block-portrait-large', 900, 1200, true );
278
+ add_image_size( 'newspack-article-block-square-large', 1200, 1200, true );
279
+
280
+ add_image_size( 'newspack-article-block-landscape-medium', 800, 600, true );
281
+ add_image_size( 'newspack-article-block-portrait-medium', 600, 800, true );
282
+ add_image_size( 'newspack-article-block-square-medium', 800, 800, true );
283
+
284
+ add_image_size( 'newspack-article-block-landscape-small', 400, 300, true );
285
+ add_image_size( 'newspack-article-block-portrait-small', 300, 400, true );
286
+ add_image_size( 'newspack-article-block-square-small', 400, 400, true );
287
+
288
+ add_image_size( 'newspack-article-block-landscape-tiny', 200, 150, true );
289
+ add_image_size( 'newspack-article-block-portrait-tiny', 150, 200, true );
290
+ add_image_size( 'newspack-article-block-square-tiny', 200, 200, true );
291
+
292
+ add_image_size( 'newspack-article-block-uncropped', 1200, 9999, false );
293
+ }
294
+
295
+ /**
296
+ * Builds and returns query args based on block attributes.
297
+ *
298
+ * @param array $attributes An array of block attributes.
299
+ *
300
+ * @return array
301
+ */
302
+ public static function build_articles_query( $attributes ) {
303
+ global $newspack_blocks_post_id;
304
+ if ( ! $newspack_blocks_post_id ) {
305
+ $newspack_blocks_post_id = array();
306
+ }
307
+ $authors = isset( $attributes['authors'] ) ? $attributes['authors'] : array();
308
+ $categories = isset( $attributes['categories'] ) ? $attributes['categories'] : array();
309
+ $tags = isset( $attributes['tags'] ) ? $attributes['tags'] : array();
310
+ $specific_posts = isset( $attributes['specificPosts'] ) ? $attributes['specificPosts'] : array();
311
+ $posts_to_show = intval( $attributes['postsToShow'] );
312
+ $specific_mode = intval( $attributes['specificMode'] );
313
+ $args = array(
314
+ 'post_status' => 'publish',
315
+ 'suppress_filters' => false,
316
+ 'ignore_sticky_posts' => true,
317
+ );
318
+ if ( $specific_mode && $specific_posts ) {
319
+ $args['post__in'] = $specific_posts;
320
+ $args['orderby'] = 'post__in';
321
+ } else {
322
+ $args['posts_per_page'] = $posts_to_show + count( $newspack_blocks_post_id );
323
+ if ( $authors ) {
324
+ $args['author__in'] = $authors;
325
+ }
326
+ if ( $categories ) {
327
+ $args['category__in'] = $categories;
328
+ }
329
+ if ( $tags ) {
330
+ $args['tag__in'] = $tags;
331
+ }
332
+ }
333
+ return $args;
334
+ }
335
+
336
+ /**
337
+ * Loads a template with given data in scope.
338
+ *
339
+ * @param string $template full Path to the template to be included.
340
+ * @param array $data Data to be passed into the template to be included.
341
+ * @return string
342
+ */
343
+ public static function template_inc( $template, $data = array() ) {
344
+ if ( ! strpos( $template, '.php' ) ) {
345
+ $template = $template . '.php';
346
+ }
347
+ if ( ! is_file( $template ) ) {
348
+ return '';
349
+ }
350
+ ob_start();
351
+ include $template;
352
+ $contents = ob_get_contents();
353
+ ob_end_clean();
354
+ return $contents;
355
+ }
356
+
357
+ /**
358
+ * Prepare an array of authors, taking presence of CoAuthors Plus into account.
359
+ *
360
+ * @return array Array of WP_User objects.
361
+ */
362
+ public static function prepare_authors() {
363
+ if ( function_exists( 'coauthors_posts_links' ) ) {
364
+ $authors = get_coauthors();
365
+ foreach ( $authors as $author ) {
366
+ // Check if this is a guest author post type.
367
+ if ( 'guest-author' === get_post_type( $author->ID ) ) {
368
+ // If yes, make sure the author actually has an avatar set; otherwise, coauthors_get_avatar returns a featured image.
369
+ if ( get_post_thumbnail_id( $author->ID ) ) {
370
+ $author->avatar = coauthors_get_avatar( $author, 48 );
371
+ } else {
372
+ // If there is no avatar, force it to return the current fallback image.
373
+ $author->avatar = get_avatar( ' ' );
374
+ }
375
+ } else {
376
+ $author->avatar = coauthors_get_avatar( $author, 48 );
377
+ }
378
+ $author->url = get_author_posts_url( $author->ID, $author->user_nicename );
379
+ }
380
+ return $authors;
381
+ }
382
+ $id = get_the_author_meta( 'ID' );
383
+ return array(
384
+ (object) array(
385
+ 'ID' => $id,
386
+ 'avatar' => get_avatar( $id, 48 ),
387
+ 'url' => get_author_posts_url( $id ),
388
+ 'user_nicename' => get_the_author(),
389
+ 'display_name' => get_the_author_meta( 'display_name' ),
390
+ ),
391
+ );
392
+ }
393
+ }
blog-posts-block/newspack-homepage-articles/components/autocomplete-tokenfield.js ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { debounce } from 'lodash';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { Component } from '@wordpress/element';
10
+ import { FormTokenField, Spinner } from '@wordpress/components';
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ import './autocomplete-tokenfield.scss';
16
+
17
+ /**
18
+ * An multi-selecting, api-driven autocomplete input suitable for use in block attributes.
19
+ */
20
+ class AutocompleteTokenField extends Component {
21
+ constructor( props ) {
22
+ super( props );
23
+ this.state = {
24
+ suggestions: [],
25
+ validValues: {},
26
+ loading: false,
27
+ };
28
+
29
+ this.debouncedUpdateSuggestions = debounce( this.updateSuggestions, 500 )
30
+ }
31
+
32
+ /**
33
+ * When the component loads, fetch information about the tokens so we can populate
34
+ * the tokens with the correct labels.
35
+ */
36
+ componentDidMount() {
37
+ const { tokens, fetchSavedInfo } = this.props;
38
+
39
+ if ( ! tokens.length || ! fetchSavedInfo ) {
40
+ return;
41
+ }
42
+
43
+ this.setState( { loading: true }, () => {
44
+ fetchSavedInfo( tokens )
45
+ .then( results => {
46
+ const { validValues } = this.state;
47
+
48
+ results.forEach( suggestion => {
49
+ validValues[ suggestion.value ] = suggestion.label;
50
+ } );
51
+
52
+ this.setState( { validValues, loading: false } );
53
+ } );
54
+ } );
55
+ }
56
+
57
+ /**
58
+ * Clean up any unfinished autocomplete api call requests.
59
+ */
60
+ componentWillUnmount() {
61
+ delete this.suggestionsRequest;
62
+ this.debouncedUpdateSuggestions.cancel();
63
+ }
64
+
65
+ /**
66
+ * Get a list of labels for input values.
67
+ *
68
+ * @param array values Array of values (ids, etc.).
69
+ * @return array Array of valid labels corresponding to the values.
70
+ */
71
+ getLabelsForValues( values ) {
72
+ const { validValues } = this.state;
73
+ return values.reduce(
74
+ ( accumulator, value ) =>
75
+ validValues[ value ] ? [ ...accumulator, validValues[ value ] ] : accumulator,
76
+ []
77
+ );
78
+ }
79
+
80
+ /**
81
+ * Get a list of values for input labels.
82
+ *
83
+ * @param array labels Array of labels from the tokens.
84
+ * @return array Array of valid values corresponding to the labels.
85
+ */
86
+ getValuesForLabels( labels ) {
87
+ const { validValues } = this.state;
88
+ return labels.map( label =>
89
+ Object.keys( validValues ).find( key => validValues[ key ] === label )
90
+ );
91
+ }
92
+
93
+ /**
94
+ * Refresh the autocomplete dropdown.
95
+ */
96
+ updateSuggestions( input ) {
97
+ const { fetchSuggestions } = this.props;
98
+ if ( ! fetchSuggestions ) {
99
+ return;
100
+ }
101
+
102
+ this.setState( { loading: true }, () => {
103
+ const request = fetchSuggestions( input );
104
+ request.then( suggestions => {
105
+ // A fetch Promise doesn't have an abort option. It's mimicked by
106
+ // comparing the request reference in on the instance, which is
107
+ // reset or deleted on subsequent requests or unmounting.
108
+ if ( this.suggestionsRequest !== request ) {
109
+ return;
110
+ }
111
+
112
+ const { validValues } = this.state;
113
+ const currentSuggestions = []
114
+
115
+ suggestions.forEach( suggestion => {
116
+ currentSuggestions.push( suggestion.label );
117
+ validValues[ suggestion.value ] = suggestion.label;
118
+ } );
119
+
120
+ this.setState( { suggestions: currentSuggestions, validValues, loading: false } );
121
+ } ).catch( () => {
122
+ if ( this.suggestionsRequest === request ) {
123
+ this.setState( {
124
+ loading: false,
125
+ } );
126
+ }
127
+ } );
128
+
129
+ this.suggestionsRequest = request;
130
+ } );
131
+ }
132
+
133
+ /**
134
+ * When a token is selected, we need to convert the string label into a recognized value suitable for saving as an attribute.
135
+ *
136
+ * @param array tokenStrings An array of token label strings.
137
+ */
138
+ handleOnChange( tokenStrings ) {
139
+ const { onChange } = this.props;
140
+ onChange( this.getValuesForLabels( tokenStrings ) );
141
+ }
142
+
143
+ /**
144
+ * To populate the tokens, we need to convert the values into a human-readable label.
145
+ *
146
+ * @return array An array of token label strings.
147
+ */
148
+ getTokens() {
149
+ const { tokens } = this.props;
150
+ return this.getLabelsForValues( tokens );
151
+ }
152
+
153
+ /**
154
+ * Render.
155
+ */
156
+ render() {
157
+ const { label = '' } = this.props;
158
+ const { suggestions, loading } = this.state;
159
+
160
+ return (
161
+ <div className='autocomplete-tokenfield'>
162
+ <FormTokenField
163
+ value={ this.getTokens() }
164
+ suggestions={ suggestions }
165
+ onChange={ tokens => this.handleOnChange( tokens ) }
166
+ onInputChange={ input => this.debouncedUpdateSuggestions( input ) }
167
+ label={ label }
168
+ />
169
+ { loading && <Spinner /> }
170
+ </div>
171
+ );
172
+ }
173
+ }
174
+
175
+ export default AutocompleteTokenField;
blog-posts-block/newspack-homepage-articles/components/autocomplete-tokenfield.scss ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ .autocomplete-tokenfield {
2
+ position: relative;
3
+
4
+ .components-spinner {
5
+ position: absolute;
6
+ top: 2em;
7
+ right: 0;
8
+ }
9
+ }
blog-posts-block/newspack-homepage-articles/components/query-controls.js ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import { Component, Fragment } from '@wordpress/element';
6
+ import { QueryControls as BaseControl, SelectControl, ToggleControl } from '@wordpress/components';
7
+ import apiFetch from '@wordpress/api-fetch';
8
+ import { addQueryArgs } from '@wordpress/url';
9
+ import { decodeEntities } from '@wordpress/html-entities';
10
+
11
+ /**
12
+ * Internal dependencies.
13
+ */
14
+ import AutocompleteTokenField from './autocomplete-tokenfield';
15
+
16
+ class QueryControls extends Component {
17
+
18
+ fetchPostSuggestions = search => {
19
+ return apiFetch( {
20
+ path: addQueryArgs( '/wp/v2/search', {
21
+ search,
22
+ per_page: 20,
23
+ _fields: 'id,title',
24
+ type: 'post',
25
+ } ),
26
+ } ).then( function( posts ) {
27
+ const result = posts.map( post => ( {
28
+ value: post.id,
29
+ label: decodeEntities( post.title ) || __( '(no title)', 'newspack-blocks' ),
30
+ } ) );
31
+ return result;
32
+ } );
33
+ };
34
+ fetchSavedPosts = postIDs => {
35
+ return apiFetch( {
36
+ path: addQueryArgs( '/wp/v2/posts', {
37
+ per_page: 100,
38
+ include: postIDs.join( ',' ),
39
+ _fields: 'id,title',
40
+ } ),
41
+ } ).then( function( posts ) {
42
+ return posts.map( post => ( {
43
+ value: post.id,
44
+ label: decodeEntities( post.title.rendered ) || __( '(no title)', 'newspack-blocks' ),
45
+ } ) );
46
+ } );
47
+ };
48
+
49
+ fetchAuthorSuggestions = search => {
50
+ return apiFetch( {
51
+ path: addQueryArgs( '/wp/v2/users', {
52
+ search,
53
+ per_page: 20,
54
+ _fields: 'id,name',
55
+ } ),
56
+ } ).then( function( users ) {
57
+ return users.map( user => ( {
58
+ value: user.id,
59
+ label: decodeEntities( user.name ) || __( '(no name)', 'newspack-blocks' ),
60
+ } ) );
61
+ } );
62
+ };
63
+ fetchSavedAuthors = userIDs => {
64
+ return apiFetch( {
65
+ path: addQueryArgs( '/wp/v2/users', {
66
+ per_page: 100,
67
+ include: userIDs.join( ',' ),
68
+ _fields: 'id,name',
69
+ } ),
70
+ } ).then( function( users ) {
71
+ return users.map( user => ( {
72
+ value: user.id,
73
+ label: decodeEntities( user.name ) || __( '(no name)', 'newspack-blocks' ),
74
+ } ) );
75
+ } );
76
+ };
77
+
78
+ fetchCategorySuggestions = search => {
79
+ return apiFetch( {
80
+ path: addQueryArgs( '/wp/v2/categories', {
81
+ search,
82
+ per_page: 20,
83
+ _fields: 'id,name',
84
+ orderby: 'count',
85
+ order: 'desc',
86
+ } ),
87
+ } ).then( function( categories ) {
88
+ return categories.map( category => ( {
89
+ value: category.id,
90
+ label: decodeEntities( category.name ) || __( '(no title)', 'newspack-blocks' ),
91
+ } ) );
92
+ } );
93
+ };
94
+ fetchSavedCategories = categoryIDs => {
95
+ return apiFetch( {
96
+ path: addQueryArgs( '/wp/v2/categories', {
97
+ per_page: 100,
98
+ _fields: 'id,name',
99
+ include: categoryIDs.join( ',' ),
100
+ } ),
101
+ } ).then( function( categories ) {
102
+ return categories.map( category => ( {
103
+ value: category.id,
104
+ label: decodeEntities( category.name ) || __( '(no title)', 'newspack-blocks' ),
105
+ } ) );
106
+ } );
107
+ };
108
+
109
+ fetchTagSuggestions = search => {
110
+ return apiFetch( {
111
+ path: addQueryArgs( '/wp/v2/tags', {
112
+ search,
113
+ per_page: 20,
114
+ _fields: 'id,name',
115
+ orderby: 'count',
116
+ order: 'desc',
117
+ } ),
118
+ } ).then( function( tags ) {
119
+ return tags.map( tag => ( {
120
+ value: tag.id,
121
+ label: decodeEntities( tag.name ) || __( '(no title)', 'newspack-blocks' ),
122
+ } ) );
123
+ } );
124
+ };
125
+ fetchSavedTags = tagIDs => {
126
+ return apiFetch( {
127
+ path: addQueryArgs( '/wp/v2/tags', {
128
+ per_page: 100,
129
+ _fields: 'id,name',
130
+ include: tagIDs.join( ',' ),
131
+ } ),
132
+ } ).then( function( tags ) {
133
+ return tags.map( tag => ( {
134
+ value: tag.id,
135
+ label: decodeEntities( tag.name ) || __( '(no title)', 'newspack-blocks' ),
136
+ } ) );
137
+ } );
138
+ };
139
+
140
+ render = () => {
141
+ const {
142
+ numberOfItems,
143
+ onNumberOfItemsChange,
144
+ specificMode,
145
+ onSpecificModeChange,
146
+ specificPosts,
147
+ onSpecificPostsChange,
148
+ authors,
149
+ onAuthorsChange,
150
+ categories,
151
+ onCategoriesChange,
152
+ tags,
153
+ onTagsChange,
154
+ enableSpecific,
155
+ } = this.props;
156
+
157
+ return [
158
+ enableSpecific && (
159
+ <ToggleControl
160
+ checked={ specificMode }
161
+ onChange={ onSpecificModeChange }
162
+ label={ __( 'Choose specific stories', 'newspack-blocks' ) }
163
+ />
164
+ ),
165
+ specificMode && (
166
+ <AutocompleteTokenField
167
+ tokens={ specificPosts || [] }
168
+ onChange={ onSpecificPostsChange }
169
+ fetchSuggestions={ this.fetchPostSuggestions }
170
+ fetchSavedInfo={ this.fetchSavedPosts }
171
+ label={ __( 'Posts', 'newspack-blocks' ) }
172
+ />
173
+ ),
174
+ ! specificMode && <BaseControl { ...this.props } />,
175
+ ! specificMode && onAuthorsChange && (
176
+ <AutocompleteTokenField
177
+ tokens={ authors || [] }
178
+ onChange={ onAuthorsChange }
179
+ fetchSuggestions={ this.fetchAuthorSuggestions }
180
+ fetchSavedInfo={ this.fetchSavedAuthors }
181
+ label={ __( 'Authors', 'newspack-blocks' ) }
182
+ />
183
+ ),
184
+ ! specificMode && onCategoriesChange && (
185
+ <AutocompleteTokenField
186
+ tokens={ categories || [] }
187
+ onChange={ onCategoriesChange }
188
+ fetchSuggestions={ this.fetchCategorySuggestions }
189
+ fetchSavedInfo={ this.fetchSavedCategories }
190
+ label={ __( 'Categories', 'newspack-blocks' ) }
191
+ />
192
+ ),
193
+ ! specificMode && onTagsChange && (
194
+ <AutocompleteTokenField
195
+ tokens={ tags || [] }
196
+ onChange={ onTagsChange }
197
+ fetchSuggestions={ this.fetchTagSuggestions }
198
+ fetchSavedInfo={ this.fetchSavedTags }
199
+ label={ __( 'Tags', 'newspack-blocks' ) }
200
+ />
201
+ ),
202
+ ];
203
+ };
204
+ }
205
+
206
+ QueryControls.defaultProps = {
207
+ enableSpecific: true,
208
+ specificPosts: [],
209
+ authors: [],
210
+ categories: [],
211
+ tags: [],
212
+ };
213
+
214
+ export default QueryControls;
blog-posts-block/newspack-homepage-articles/shared/sass/_colors.scss ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ $color__primary: #36f;
2
+ $color__background-body: #fff;
3
+ $color__background-input: #fff;
4
+ $color__background-screen: #f1f1f1;
5
+ $color__text-main: #111;
6
+ $color__text-light: #767676;
7
+ $color__text-input-focus: #111;
8
+ $color__border: #ccc;
blog-posts-block/newspack-homepage-articles/shared/sass/_legacy_colors.scss ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $muriel-white: #fff;
2
+
3
+ $muriel-gray-0: #f6f6f6;
4
+ $muriel-gray-50: #e1e2e2;
5
+ $muriel-gray-100: #ccced0;
6
+ $muriel-gray-200: #b0b5b8;
7
+ $muriel-gray-300: #969ca1;
8
+ $muriel-gray-400: #7c848b;
9
+ $muriel-gray-500: #636d75;
10
+ $muriel-gray-600: #50575d;
11
+ $muriel-gray-700: #3d4145;
12
+ $muriel-gray-800: #2b2d2f;
13
+ $muriel-gray-900: #1a1a1a;
blog-posts-block/newspack-homepage-articles/shared/sass/_mixins.scss ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ @mixin media( $res ) {
3
+ @if mobile == $res {
4
+ @media only screen and (min-width: $mobile_width) {
5
+ @content;
6
+ }
7
+ }
8
+
9
+ @if tablet == $res {
10
+ @media only screen and (min-width: $tablet_width) {
11
+ @content;
12
+ }
13
+ }
14
+
15
+ @if desktop == $res {
16
+ @media only screen and (min-width: $desktop_width) {
17
+ @content;
18
+ }
19
+ }
20
+
21
+ @if wide == $res {
22
+ @media only screen and (min-width: $wide_width) {
23
+ @content;
24
+ }
25
+ }
26
+ }
blog-posts-block/newspack-homepage-articles/shared/sass/_variables.scss ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ $mobile_width: 600px;
2
+ $tablet_width: 782px;
3
+ $desktop_width: 1168px;
4
+ $wide_width: 1379px;
5
+
6
+ $font__size_base: 20px;
7
+ $font__size-ratio: 1.125;
8
+
9
+ $font__size-xxxs: 1em * 0.5; // 10px
10
+ $font__size-xxs: 1em * 0.6; // 12px
11
+ $font__size-xs: 1em * 0.7; // 14px
12
+ $font__size-sm: 1em * 0.8; // 16px
13
+ // $font__size_base: 1em * 1; // 20px
14
+ $font__size-md: 1em * 1.2; // 24px
15
+ $font__size-lg: 1em * 1.4; // 28px
16
+ $font__size-xl: 1em * 1.8; // 36px
17
+ $font__size-xxl: 1em * 2.2; // 44px
18
+ $font__size-xxxl: 1em * 2.8; // 56px
19
+ $font__size-xxxxl: 1em * 3.2; // 64px
20
+
21
+
22
+ $font__line-height-body: 1.6;
23
+ $font__line-height-pre: 1.6;
24
+ $font__line-height-heading: 1.2;
25
+ $font__line-height-double: 2 * $font__line-height-heading;
26
+
27
+ $color__border: #ccc;
blog-posts-block/view.js ADDED
@@ -0,0 +1 @@
 
1
+ import './newspack-homepage-articles/blocks/homepage-articles/view';
full-site-editing-plugin.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: Full Site Editing
4
  * Description: Enhances your page creation workflow within the Block Editor.
5
- * Version: 0.16.2
6
  * Author: Automattic
7
  * Author URI: https://automattic.com/wordpress-plugins/
8
  * License: GPLv2 or later
@@ -13,6 +13,21 @@
13
 
14
  namespace A8C\FSE;
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  /**
17
  * Plugin version.
18
  *
@@ -20,7 +35,10 @@ namespace A8C\FSE;
20
  *
21
  * @var string
22
  */
23
- define( 'PLUGIN_VERSION', '0.16.2' );
 
 
 
24
 
25
  /**
26
  * Load Full Site Editing.
@@ -37,147 +55,6 @@ function load_full_site_editing() {
37
  }
38
  add_action( 'plugins_loaded', __NAMESPACE__ . '\load_full_site_editing' );
39
 
40
- /**
41
- * NOTE: In most cases, you should NOT use this function. Please use
42
- * load_full_site_editing instead. This function should only be used if you need
43
- * to include the FSE files somewhere like a script. I.e. if you want to access
44
- * a class defined here without needing full FSE functionality.
45
- */
46
- function dangerously_load_full_site_editing_files() {
47
- require_once __DIR__ . '/full-site-editing/blocks/navigation-menu/index.php';
48
- require_once __DIR__ . '/full-site-editing/blocks/post-content/index.php';
49
- require_once __DIR__ . '/full-site-editing/blocks/site-description/index.php';
50
- require_once __DIR__ . '/full-site-editing/blocks/site-title/index.php';
51
- require_once __DIR__ . '/full-site-editing/blocks/template/index.php';
52
- require_once __DIR__ . '/full-site-editing/class-full-site-editing.php';
53
- require_once __DIR__ . '/full-site-editing/templates/class-rest-templates-controller.php';
54
- require_once __DIR__ . '/full-site-editing/templates/class-wp-template.php';
55
- require_once __DIR__ . '/full-site-editing/templates/class-wp-template-inserter.php';
56
- require_once __DIR__ . '/full-site-editing/templates/class-template-image-inserter.php';
57
- require_once __DIR__ . '/full-site-editing/serialize-block-fallback.php';
58
- }
59
-
60
- /**
61
- * Whether or not FSE is active.
62
- * If false, FSE functionality should be disabled.
63
- *
64
- * @returns bool True if FSE is active, false otherwise.
65
- */
66
- function is_full_site_editing_active() {
67
- /**
68
- * There are times when this function is called from the WordPress.com public
69
- * API context. In this case, we need to switch to the correct blog so that
70
- * the functions reference the correct blog context.
71
- */
72
- $multisite_id = apply_filters( 'a8c_fse_get_multisite_id', false );
73
- $should_switch = is_multisite() && $multisite_id;
74
- if ( $should_switch ) {
75
- switch_to_blog( $multisite_id );
76
- }
77
-
78
- $is_active = is_site_eligible_for_full_site_editing() && is_theme_supported() && did_insert_template_parts();
79
-
80
- if ( $should_switch ) {
81
- restore_current_blog();
82
- }
83
- return $is_active;
84
- }
85
-
86
- /**
87
- * Returns the slug for the current theme.
88
- *
89
- * This even works for the WordPress.com API context where the current theme is
90
- * not correct. The filter correctly switches to the correct blog context if
91
- * that is the case.
92
- *
93
- * @return string Theme slug.
94
- */
95
- function get_theme_slug() {
96
- /**
97
- * Used to get the correct theme in certain contexts.
98
- *
99
- * For example, in the wpcom API context, the theme slug is a8c/public-api,
100
- * so we need to grab the correct one with the filter.
101
- *
102
- * @since 0.7
103
- *
104
- * @param string current theme slug is the default if nothing overrides it.
105
- */
106
- return apply_filters( 'a8c_fse_get_theme_slug', get_stylesheet() );
107
- }
108
-
109
- /**
110
- * Returns a normalized slug for the current theme.
111
- *
112
- * In some cases, the theme is located in a subfolder like `pub/maywood`. Use
113
- * this function to get the slug without the prefix.
114
- *
115
- * @param string $theme_slug The raw theme_slug to normalize.
116
- * @return string Theme slug.
117
- */
118
- function normalize_theme_slug( $theme_slug ) {
119
- // Normalize the theme slug.
120
- if ( 'pub/' === substr( $theme_slug, 0, 4 ) ) {
121
- $theme_slug = substr( $theme_slug, 4 );
122
- }
123
-
124
- if ( '-wpcom' === substr( $theme_slug, -6, 6 ) ) {
125
- $theme_slug = substr( $theme_slug, 0, -6 );
126
- }
127
-
128
- return $theme_slug;
129
- }
130
-
131
- /**
132
- * Whether or not the site is eligible for FSE. This is essentially a feature
133
- * gate to disable FSE on some sites which could theoretically otherwise use it.
134
- *
135
- * @return bool True if current site is eligible for FSE, false otherwise.
136
- */
137
- function is_site_eligible_for_full_site_editing() {
138
- /**
139
- * Can be used to disable Full Site Editing functionality.
140
- *
141
- * @since 0.2
142
- *
143
- * @param bool true if Full Site Editing should be disabled, false otherwise.
144
- */
145
- return ! apply_filters( 'a8c_disable_full_site_editing', false );
146
- }
147
-
148
- /**
149
- * Whether or not current theme is enabled for FSE.
150
- *
151
- * @return bool True if current theme supports FSE, false otherwise.
152
- */
153
- function is_theme_supported() {
154
- // Use un-normalized theme slug because get_theme requires the full string.
155
- $theme = wp_get_theme( get_theme_slug() );
156
- return ! $theme->errors() && in_array( 'full-site-editing', $theme->tags, true );
157
- }
158
-
159
- /**
160
- * Determines if the template parts have been inserted for the current theme.
161
- *
162
- * We want to gate on this check in is_full_site_editing_active so that we don't
163
- * load FSE for sites which did not get template parts for some reason or another.
164
- *
165
- * For example, if a user activates theme A on their site and gets FSE, but then
166
- * activates theme B which does not have FSE, they will not get FSE flows. If we
167
- * retroactively add FSE support to theme B, the user should not get FSE flows
168
- * because their site would be modified. Instead, FSE flows would become active
169
- * when they specifically take action to re-activate the theme.
170
- *
171
- * @return bool True if the template parts have been inserted. False otherwise.
172
- */
173
- function did_insert_template_parts() {
174
- require_once __DIR__ . '/full-site-editing/templates/class-wp-template-inserter.php';
175
-
176
- $theme_slug = normalize_theme_slug( get_theme_slug() );
177
- $inserter = new WP_Template_Inserter( $theme_slug );
178
- return $inserter->is_template_data_inserted();
179
- }
180
-
181
  /**
182
  * Load Posts List Block.
183
  */
@@ -239,34 +116,6 @@ function load_global_styles() {
239
  }
240
  add_action( 'plugins_loaded', __NAMESPACE__ . '\load_global_styles' );
241
 
242
- /**
243
- * Inserts default full site editing data for current theme on plugin/theme activation.
244
- *
245
- * We put this here outside of the normal FSE class because FSE is not active
246
- * until the template parts are inserted. This makes sure we insert the template
247
- * parts when switching to a theme which supports FSE.
248
- *
249
- * This will populate the default header and footer for current theme, and create
250
- * About and Contact pages. Nothing will populate if the data already exists, or
251
- * if the theme is unsupported.
252
- */
253
- function populate_wp_template_data() {
254
- if ( ! is_theme_supported() ) {
255
- return;
256
- }
257
-
258
- require_once __DIR__ . '/full-site-editing/templates/class-template-image-inserter.php';
259
- require_once __DIR__ . '/full-site-editing/templates/class-wp-template-inserter.php';
260
-
261
- $theme_slug = normalize_theme_slug( get_theme_slug() );
262
-
263
- $template_inserter = new WP_Template_Inserter( $theme_slug );
264
- $template_inserter->insert_default_template_data();
265
- $template_inserter->insert_default_pages();
266
- }
267
- register_activation_hook( __FILE__, __NAMESPACE__ . '\populate_wp_template_data' );
268
- add_action( 'after_switch_theme', __NAMESPACE__ . '\populate_wp_template_data' );
269
-
270
  /**
271
  * Add front-end CoBlocks gallery block scripts.
272
  *
@@ -318,3 +167,27 @@ function enqueue_coblocks_gallery_scripts() {
318
  }
319
  }
320
  add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_coblocks_gallery_scripts' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  /**
3
  * Plugin Name: Full Site Editing
4
  * Description: Enhances your page creation workflow within the Block Editor.
5
+ * Version: 0.17
6
  * Author: Automattic
7
  * Author URI: https://automattic.com/wordpress-plugins/
8
  * License: GPLv2 or later
13
 
14
  namespace A8C\FSE;
15
 
16
+ /**
17
+ * This file should only be used to load files needed for each subfeature.
18
+ *
19
+ * For example, if you are adding a new feature to this plugin called "Foo",
20
+ * you would create a directory `./foo` to contain all code needed by your
21
+ * feature. Then, in this file, you would add a `load_foo()` function which
22
+ * includes your feature's files via the 'plugins_loaded' action.
23
+ *
24
+ * Please take care to _not_ load your feature's files if there are situations
25
+ * which could cause bugs. For example, FSE files are only loaded if FSE is
26
+ * active on the site.
27
+ *
28
+ * Finally, don't forget to use the A8C\FSE namespace for your code. :)
29
+ */
30
+
31
  /**
32
  * Plugin version.
33
  *
35
  *
36
  * @var string
37
  */
38
+ define( 'PLUGIN_VERSION', '0.17' );
39
+
40
+ // Always include these helper files for FSE.
41
+ require_once __DIR__ . '/full-site-editing/helpers.php';
42
 
43
  /**
44
  * Load Full Site Editing.
55
  }
56
  add_action( 'plugins_loaded', __NAMESPACE__ . '\load_full_site_editing' );
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  /**
59
  * Load Posts List Block.
60
  */
116
  }
117
  add_action( 'plugins_loaded', __NAMESPACE__ . '\load_global_styles' );
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  /**
120
  * Add front-end CoBlocks gallery block scripts.
121
  *
167
  }
168
  }
169
  add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_coblocks_gallery_scripts' );
170
+
171
+ /**
172
+ * Load Blog Posts block.
173
+ */
174
+ function load_blog_posts_block() {
175
+ $disable_block = (
176
+ in_array( 'newspack-blocks/newspack-blocks.php', (array) get_option( 'active_plugins', array() ), true ) ||
177
+ in_array( 'newspack-blocks/newspack-blocks.php', (array) get_site_option( 'active_sitewide_plugins', array() ), true )
178
+ );
179
+
180
+ /**
181
+ * Can be used to disable the Blog Posts block.
182
+ *
183
+ * @since 0.15.1
184
+ *
185
+ * @param bool $disable_block True if Blog Posts block should be enabled, false otherwise.
186
+ */
187
+ if ( apply_filters( 'a8c_disable_blog_posts_block', $disable_block ) ) {
188
+ return;
189
+ }
190
+
191
+ require_once __DIR__ . '/blog-posts-block/index.php';
192
+ }
193
+ add_action( 'plugins_loaded', __NAMESPACE__ . '\load_blog_posts_block' );
full-site-editing/dist/full-site-editing.asset.php CHANGED
@@ -1 +1 @@
1
- <?php return array('dependencies' => array('lodash', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-plugins', 'wp-polyfill', 'wp-server-side-render', 'wp-url'), 'version' => '6fa56a71ac083a87653ef10a76e9c126');
1
+ <?php return array('dependencies' => array('lodash', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-plugins', 'wp-polyfill', 'wp-server-side-render', 'wp-url'), 'version' => 'c633ece41359a0d7a9b1b379fd0a9c8f');
full-site-editing/dist/full-site-editing.js CHANGED
@@ -1,2 +1,2 @@
1
  /*! For license information please see full-site-editing.js.LICENSE */
2
- !function(e,t){for(var n in t)e[n]=t[n]}(window,function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=45)}([function(e,t){!function(){e.exports=this.wp.element}()},function(e,t){!function(){e.exports=this.wp.i18n}()},function(e,t){!function(){e.exports=this.wp.blockEditor}()},function(e,t){!function(){e.exports=this.wp.data}()},function(e,t){!function(){e.exports=this.wp.compose}()},function(e,t){!function(){e.exports=this.wp.components}()},function(e,t){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},function(e,t){!function(){e.exports=this.wp.blocks}()},function(e,t){!function(){e.exports=this.lodash}()},function(e,t,n){var o=n(6);function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}e.exports=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){o(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}},function(e,t){function n(){return e.exports=n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},n.apply(this,arguments)}e.exports=n},function(e,t,n){var o;!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t<arguments.length;t++){var o=arguments[t];if(o){var i=typeof o;if("string"===i||"number"===i)e.push(o);else if(Array.isArray(o)&&o.length){var c=r.apply(null,o);c&&e.push(c)}else if("object"===i)for(var l in o)n.call(o,l)&&o[l]&&e.push(l)}}return e.join(" ")}e.exports?(r.default=r,e.exports=r):void 0===(o=function(){return r}.apply(t,[]))||(e.exports=o)}()},function(e,t){!function(){e.exports=this.wp.hooks}()},function(e,t,n){var o=n(34),r=n(35),i=n(36);e.exports=function(e,t){return o(e)||r(e,t)||i()}},function(e,t){!function(){e.exports=this.wp.domReady}()},function(e,t){!function(){e.exports=this.wp.apiFetch}()},function(e,t){!function(){e.exports=this.wp.htmlEntities}()},function(e,t,n){},function(e,t){!function(){e.exports=this.wp.serverSideRender}()},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},function(e,t){function n(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}e.exports=function(e,t,o){return t&&n(e.prototype,t),o&&n(e,o),e}},function(e,t,n){var o=n(30),r=n(31);e.exports=function(e,t){return!t||"object"!==o(t)&&"function"!=typeof t?r(e):t}},function(e,t){function n(t){return e.exports=n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},n(t)}e.exports=n},function(e,t,n){var o=n(32);e.exports=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}},function(e,t){!function(){e.exports=this.wp.editor}()},function(e,t){!function(){e.exports=this.wp.url}()},function(e,t){!function(){e.exports=this.ReactDOM}()},function(e,t,n){var o=n(41),r=n(42),i=n(43);e.exports=function(e){return o(e)||r(e)||i()}},function(e,t){!function(){e.exports=this.wp.plugins}()},function(e,t,n){},function(e,t){function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(t){return"function"==typeof Symbol&&"symbol"===n(Symbol.iterator)?e.exports=o=function(e){return n(e)}:e.exports=o=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":n(e)},o(t)}e.exports=o},function(e,t){e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}},function(e,t){function n(t,o){return e.exports=n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(t,o)}e.exports=n},function(e,t,n){},function(e,t){e.exports=function(e){if(Array.isArray(e))return e}},function(e,t){e.exports=function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],o=!0,r=!1,i=void 0;try{for(var c,l=e[Symbol.iterator]();!(o=(c=l.next()).done)&&(n.push(c.value),!t||n.length!==t);o=!0);}catch(a){r=!0,i=a}finally{try{o||null==l.return||l.return()}finally{if(r)throw i}}return n}}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t){e.exports=function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}},function(e,t){e.exports=function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}},function(e,t,n){},function(e,t,n){"use strict";n.r(t);var o=n(0),r=n(7),i=n(1),c=n(10),l=n.n(c),a=n(18),s=n.n(a),u=n(4),p=n(2),d=n(5),b=n(3),f=Object(u.compose)([Object(p.withColors)("backgroundColor",{textColor:"color"}),Object(p.withFontSizes)("fontSize"),Object(b.withSelect)((function(e){return{isPublished:e("core/editor").isCurrentPostPublished()}}))])((function(e){var t=e.attributes,n=e.backgroundColor,r=e.fontSize,c=e.setAttributes,a=e.setBackgroundColor,u=e.setFontSize,b=e.setTextColor,f=e.textColor,m=e.isPublished,O=t.customFontSize,g=t.textAlign,j=O||r.size;return Object(o.createElement)(o.Fragment,null,Object(o.createElement)(p.BlockControls,null,Object(o.createElement)(p.AlignmentToolbar,{value:g,onChange:function(e){c({textAlign:e})}})),Object(o.createElement)(p.InspectorControls,null,Object(o.createElement)(d.PanelBody,{className:"blocks-font-size",title:Object(i.__)("Text Settings")},Object(o.createElement)(p.FontSizePicker,{onChange:u,value:j})),Object(o.createElement)(p.PanelColorSettings,{title:Object(i.__)("Color Settings"),initialOpen:!1,colorSettings:[{value:n.color,onChange:a,label:Object(i.__)("Background Color")},{value:f.color,onChange:b,label:Object(i.__)("Text Color")}]},Object(o.createElement)(p.ContrastChecker,l()({textColor:f.color,backgroundColor:n.color},{fontSize:j})))),Object(o.createElement)(s.a,{isPublished:m,block:"a8c/navigation-menu",attributes:t}))})),m=(n(29),Object(o.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"},Object(o.createElement)("path",{fill:"none",d:"M0 0h24v24H0V0z"}),Object(o.createElement)("path",{d:"M12 7.27l4.28 10.43-3.47-1.53-.81-.36-.81.36-3.47 1.53L12 7.27M12 2L4.5 20.29l.71.71L12 18l6.79 3 .71-.71L12 2z"})));Object(r.registerBlockType)("a8c/navigation-menu",{title:Object(i.__)("Navigation Menu"),description:Object(i.__)("Visual placeholder for site-wide navigation and menus."),icon:m,category:"layout",supports:{align:["wide","full","right","left"],html:!1,reusable:!1},edit:f,save:function(){return null}});var O=n(12),g=n(6),j=n.n(g),v=n(19),h=n.n(v),y=n(20),_=n.n(y),S=n(21),E=n.n(S),k=n(22),w=n.n(k),C=n(23),x=n.n(C),P=n(11),T=n.n(P),B=n(24),I=function(e){function t(){return h()(this,t),E()(this,w()(t).apply(this,arguments))}return x()(t,e),_()(t,[{key:"toggleEditing",value:function(){var e=this.props,t=e.isEditing;(0,e.setState)({isEditing:!t})}},{key:"onSelectPost",value:function(e){var t=e.id,n=e.type;this.props.setState({isEditing:!1,selectedPostId:t,selectedPostType:n})}},{key:"render",value:function(){var e=this.props.attributes.align;return Object(o.createElement)(o.Fragment,null,Object(o.createElement)("div",{className:T()("post-content-block",j()({},"align".concat(e),e))},Object(o.createElement)(B.PostTitle,null),Object(o.createElement)(p.InnerBlocks,{templateLock:!1})))}}]),t}(o.Component),N=Object(u.compose)([Object(u.withState)({isEditing:!1,selectedPostId:void 0,selectedPostType:void 0}),Object(b.withSelect)((function(e,t){var n=t.selectedPostId,o=t.selectedPostType;return{selectedPost:(0,e("core").getEntityRecord)("postType",o,n)}}))])(I);n(33);Object(r.registerBlockType)("a8c/post-content",{title:Object(i.__)("Content"),description:Object(i.__)("The page content."),icon:"layout",category:"layout",supports:{align:["full"],anchor:!1,customClassName:!1,html:!1,inserter:!1,multiple:!1,reusable:!1},attributes:{align:{type:"string",default:"full"}},edit:N,save:function(){return Object(o.createElement)(p.InnerBlocks.Content,null)}});var A=Object(u.createHigherOrderComponent)((function(e){return function(t){return"a8c/post-content"!==t.name?Object(o.createElement)(e,t):Object(o.createElement)(e,l()({},t,{className:"post-content__block"}))}}),"addContentSlotClassname");Object(O.addFilter)("editor.BlockListBlock","full-site-editing/blocks/post-content",A,9);var z=n(9),D=n.n(z),F=n(13),L=n.n(F),R=n(15),V=n.n(R),M=n(16);function U(e){var t=Object(o.useRef)();return Object(o.useEffect)((function(){t.current=e}),[e]),t.current}function H(e,t,n,r,c,l){var a=Object(o.useState)({option:t,previousOption:"",loaded:!1,error:!1}),s=L()(a,2),u=s[0],p=s[1],d=U(r),b=U(c);function f(){p(D()({},u,{option:u.previousOption,isSaving:!1}))}return Object(o.useEffect)((function(){u.loaded||u.error?function(){var t=u.option,o=u.previousOption,l=!o&&!t||t&&o&&t.trim()===o.trim(),a=!t||0===t.trim().length;!r&&d&&a&&f();if(!c||l)return;!b&&c&&function(t){p(D()({},u,{isSaving:!0})),V()({path:"/wp/v2/settings",method:"POST",data:j()({},e,t)}).then((function(){return function(e){p(D()({},u,{previousOption:e,isDirty:!1,isSaving:!1}))}(t)})).catch((function(){n(Object(i.sprintf)(Object(i.__)("Unable to save site %s"),e)),f()}))}(t)}():V()({path:"/wp/v2/settings"}).then((function(t){return p(D()({},u,{option:Object(M.decodeEntities)(t[e]),previousOption:Object(M.decodeEntities)(t[e]),loaded:!0,error:!1}))})).catch((function(){n(Object(i.sprintf)(Object(i.__)("Unable to load site %s"),e)),p(D()({},u,{option:Object(i.sprintf)(Object(i.__)("Error loading site %s"),e),error:!0}))}))})),{siteOptions:u,handleChange:function(e){l({updated:Date.now()}),p(D()({},u,{option:e}))}}}var W=function(e){return Object(u.createHigherOrderComponent)((function(t){return Object(u.pure)((function(n){var r=Object(b.useSelect)((function(e){var t=e("core/editor"),n=t.isSavingPost,o=t.isPublishingPost,r=t.isAutosavingPost,i=t.isCurrentPostPublished;return(n()&&i()||o())&&!r()})),i=Object(b.useDispatch)((function(e){return e("core/notices").createErrorNotice})),c=n.isSelected,a=n.setAttributes,s=Object.keys(e).reduce((function(t,n){var o=e[n],l=H(o.optionName,o.defaultValue,i,c,r,a),s=l.siteOptions,u=l.handleChange;return t[n]={value:s.option,updateValue:u,loaded:s.loaded},t}),{});return Object(o.createElement)(t,l()({},n,s))}))}),"withSiteOptions")},q=fullSiteEditing.footerCreditOptions,G=function(e){var t=e.choice,n=q.find((function(e){return e.value===t}));if(!n)return null;var r=n.renderType,i=n.renderProps,c=n.label,l=D()({label:c},i);return"icon"===r?Object(o.createElement)(d.Icon,l):Object(o.createElement)("span",null," ",l.label," ")},Q=fullSiteEditing,Y=Q.footerCreditOptions,J=Q.defaultCreditOption;var K=Object(u.compose)([W({siteTitleOption:{optionName:"title",defaultValue:Object(i.__)("Site title loading…")},footerCreditOption:{optionName:"footer_credit",defaultValue:Object(i.__)("Footer credit loading…")}})])((function(e){var t=e.attributes.textAlign,n=void 0===t?"center":t,r=e.isSelected,i=e.setAttributes,c=e.footerCreditOption,l=c.value,a=c.updateValue,s=e.siteTitleOption.value,u=l||J;return Object(o.createElement)(o.Fragment,null,Object(o.createElement)(p.BlockControls,null,Object(o.createElement)(p.AlignmentToolbar,{value:n,onChange:function(e){i({textAlign:e})}})),Object(o.createElement)("div",{className:T()("site-info","site-credit__block",j()({},"has-text-align-".concat(n),n))},Object(o.createElement)("span",{className:"site-name"},s),Object(o.createElement)("span",{className:"comma"},","),Object(o.createElement)("span",{className:"site-credit__selection"},r?Object(o.createElement)(d.SelectControl,{onChange:a,value:u,options:Y}):Object(o.createElement)(G,{choice:u}))))}));n(37);Object(r.registerBlockType)("a8c/site-credit",{title:Object(i.__)("WordPress.com Credit"),description:Object(i.__)("This block tells the wolrd that you're using WordPress.com."),icon:"wordpress-alt",category:"layout",supports:{align:["wide","full"],html:!1,multiple:!1,reusable:!1,removal:!1},attributes:{align:{type:"string",default:"wide"},textAlign:{type:"string",default:"center"}},edit:K,save:function(){return null}});var X=n(8);var Z=Object(u.compose)([Object(p.withColors)("backgroundColor",{textColor:"color"}),Object(p.withFontSizes)("fontSize"),Object(b.withSelect)((function(e,t){var n=t.clientId,o=e("core/block-editor"),r=o.getBlockIndex,i=o.getBlockRootClientId,c=o.getTemplateLock,l=i(n);return{blockIndex:r(n,l),isLocked:!!c(l),rootClientId:l}})),Object(b.withDispatch)((function(e,t){var n=t.blockIndex,o=t.rootClientId;return{insertDefaultBlock:function(){return e("core/block-editor").insertDefaultBlock({},o,n+1)}}})),W({siteDescription:{optionName:"description",defaultValue:Object(i.__)("Site description loading…")}})])((function(e){var t,n=e.attributes,r=e.backgroundColor,c=e.className,a=e.fontSize,s=e.insertDefaultBlock,u=e.setAttributes,b=e.setBackgroundColor,f=e.setFontSize,m=e.setTextColor,O=e.siteDescription,g=e.textColor,v=n.customFontSize,h=n.textAlign,y=v||a.size,_=O.value,S=O.updateValue;return Object(o.createElement)(o.Fragment,null,Object(o.createElement)(p.BlockControls,null,Object(o.createElement)(p.AlignmentToolbar,{value:h,onChange:function(e){u({textAlign:e})}})),Object(o.createElement)(p.InspectorControls,null,Object(o.createElement)(d.PanelBody,{className:"blocks-font-size",title:Object(i.__)("Text Settings")},Object(o.createElement)(p.FontSizePicker,{onChange:f,value:y})),Object(o.createElement)(p.PanelColorSettings,{title:Object(i.__)("Color Settings"),initialOpen:!1,colorSettings:[{value:r.color,onChange:b,label:Object(i.__)("Background Color")},{value:g.color,onChange:m,label:Object(i.__)("Text Color")}]},Object(o.createElement)(p.ContrastChecker,l()({textColor:g.color,backgroundColor:r.color},{fontSize:y})))),Object(o.createElement)(p.RichText,{allowedFormats:[],"aria-label":Object(i.__)("Site Description"),className:T()("site-description",c,(t={"has-text-color":g.color,"has-background":r.color},j()(t,"has-text-align-".concat(h),h),j()(t,r.class,r.class),j()(t,g.class,g.class),j()(t,a.class,!v&&a.class),t)),identifier:"content",onChange:S,onReplace:s,onSplit:X.noop,placeholder:Object(i.__)("Add a Site Description"),style:{backgroundColor:r.color,color:g.color,fontSize:y?y+"px":void 0},tagName:"p",value:_}))}));n(38);Object(r.registerBlockType)("a8c/site-description",{title:Object(i.__)("Site Description"),description:Object(i.__)("Site description, also known as the tagline."),icon:Object(o.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24"},Object(o.createElement)("path",{fill:"none",d:"M0 0h24v24H0z"}),Object(o.createElement)("path",{d:"M4 9h16v2H4V9zm0 4h10v2H4v-2z"})),category:"layout",supports:{align:["wide","full"],html:!1,multiple:!1,reusable:!1},attributes:{align:{type:"string",default:"wide"},textAlign:{type:"string",default:"center"},textColor:{type:"string"},customTextColor:{type:"string"},backgroundColor:{type:"string"},customBackgroundColor:{type:"string"},fontSize:{type:"string",default:"small"},customFontSize:{type:"number"}},edit:Z,save:function(){return null}});var $=Object(u.compose)([Object(p.withColors)({textColor:"color"}),Object(p.withFontSizes)("fontSize"),Object(b.withSelect)((function(e,t){var n=t.clientId,o=e("core/block-editor"),r=o.getBlockIndex,i=o.getBlockRootClientId,c=o.getTemplateLock,l=i(n);return{blockIndex:r(n,l),isLocked:!!c(l),rootClientId:l}})),Object(b.withDispatch)((function(e,t){var n=t.blockIndex,o=t.rootClientId;return{insertDefaultBlock:function(){return e("core/block-editor").insertDefaultBlock({},o,n+1)}}})),W({siteTitle:{optionName:"title",defaultValue:Object(i.__)("Site title loading…")}})])((function(e){var t,n=e.attributes,r=e.className,c=e.fontSize,l=e.insertDefaultBlock,a=e.setAttributes,s=e.setFontSize,u=e.setTextColor,b=e.siteTitle,f=e.textColor,m=n.customFontSize,O=n.textAlign,g=m||c.size,v=b.value,h=b.updateValue;return Object(o.createElement)(o.Fragment,null,Object(o.createElement)(p.BlockControls,null,Object(o.createElement)(p.AlignmentToolbar,{value:O,onChange:function(e){a({textAlign:e})}})),Object(o.createElement)(p.InspectorControls,null,Object(o.createElement)(d.PanelBody,{className:"blocks-font-size",title:Object(i.__)("Text Settings")},Object(o.createElement)(p.FontSizePicker,{onChange:s,value:g})),Object(o.createElement)(p.PanelColorSettings,{title:Object(i.__)("Color Settings"),initialOpen:!1,colorSettings:[{value:f.color,onChange:u,label:Object(i.__)("Text Color")}]})),Object(o.createElement)(p.RichText,{allowedFormats:[],"aria-label":Object(i.__)("Site Title"),className:T()("site-title",r,(t={"has-text-color":f.color},j()(t,"has-text-align-".concat(O),O),j()(t,f.class,f.class),j()(t,c.class,!m&&c.class),t)),identifier:"content",onChange:h,onReplace:l,onSplit:X.noop,placeholder:Object(i.__)("Add a Site Title"),style:{color:f.color,fontSize:g?g+"px":void 0},tagName:"h1",value:v}))}));n(39);Object(r.registerBlockType)("a8c/site-title",{title:Object(i.__)("Site Title"),description:Object(i.__)("Your site title."),icon:"layout",category:"layout",supports:{align:["wide","full"],html:!1,multiple:!1,reusable:!1},attributes:{align:{type:"string",default:"wide"},textAlign:{type:"string",default:"center"},textColor:{type:"string"},customTextColor:{type:"string"},fontSize:{type:"string",default:"normal"},customFontSize:{type:"number"}},edit:$,save:function(){return null}});var ee=n(25),te=(n(17),Object(u.compose)(Object(u.withState)({templateClientId:null}),Object(b.withSelect)((function(e,t){var n=t.attributes,o=t.templateClientId,r=e("core").getEntityRecord,i=e("core/editor"),c=i.getCurrentPostId,l=i.isEditedPostDirty,a=e("core/block-editor"),s=a.getBlock,u=a.getSelectedBlock,p=e("core/edit-post").isEditorSidebarOpened,d=n.templateId,b=c(),f=d&&r("postType","wp_template_part",d),m=Object(ee.addQueryArgs)(fullSiteEditing.editTemplateBaseUrl,{post:d,fse_parent_post:b}),O=u();return{currentPostId:b,editTemplateUrl:m,template:f,templateBlock:s(o),templateTitle:Object(X.get)(f,["title","rendered"],""),isDirty:l(),isEditorSidebarOpened:!!p(),isAnyTemplateBlockSelected:O&&"a8c/template"===O.name}})),Object(b.withDispatch)((function(e,t){var n=e("core/block-editor").receiveBlocks,o=e("core/edit-post").openGeneralSidebar,i=t.template,c=t.templateClientId,l=t.setState;return{savePost:e("core/editor").savePost,receiveTemplateBlocks:function(){if(i&&!c){var e=Object(r.parse)(Object(X.get)(i,["content","raw"],"")),t=Object(r.createBlock)("core/group",{},e);n([t]),l({templateClientId:t.clientId})}},openGeneralSidebar:o}})))((function(e){var t,n=e.attributes,r=e.editTemplateUrl,c=e.receiveTemplateBlocks,l=e.template,a=e.templateBlock,s=e.templateTitle,u=e.isDirty,b=e.savePost,f=e.isEditorSidebarOpened,m=e.openGeneralSidebar,O=e.isAnyTemplateBlockSelected;if(!l)return Object(o.createElement)(d.Placeholder,null,Object(o.createElement)(d.Spinner,null));var g=Object(o.createRef)(),v=Object(o.useState)(!1),h=L()(v,2),y=h[0],_=h[1];Object(o.useEffect)((function(){y&&!u&&g.current.click(),c()})),Object(o.useEffect)((function(){var e=document.querySelector(".edit-post-sidebar__panel-tabs ul li:last-child");if(f&&e){if(O)return m("edit-post/document"),void e.classList.add("hidden");e.classList.remove("hidden")}}),[O,f,m]);var S=n.align,E=n.className,k=function(e){e.stopPropagation(),_(!0),u&&(e.preventDefault(),b())};return Object(o.createElement)("div",{className:T()("template-block",(t={},j()(t,"align".concat(S),S),j()(t,"is-navigating-to-template",y),t))},a&&Object(o.createElement)(o.Fragment,null,Object(o.createElement)(d.Disabled,null,Object(o.createElement)("div",{className:E},Object(o.createElement)(p.BlockEdit,{attributes:a.attributes,block:a,clientId:a.clientId,isSelected:!1,name:a.name,setAttributes:X.noop}))),Object(o.createElement)(d.Placeholder,{className:"template-block__overlay",onClick:k},y&&Object(o.createElement)("div",{className:"template-block__loading"},Object(o.createElement)(d.Spinner,null)," ",Object(i.sprintf)(Object(i.__)("Loading editor for: %s"),s)),Object(o.createElement)(d.Button,{className:y?"hidden":null,href:r,onClick:k,isDefault:!0,isLarge:!0,ref:g},Object(i.sprintf)(Object(i.__)("Edit %s"),s)))))}))),ne=Object(u.createHigherOrderComponent)((function(e){return function(t){return"fse-site-logo"!==t.attributes.className?Object(o.createElement)(e,t):Object(o.createElement)(e,l()({},t,{className:"template__site-logo"}))}}),"addFSESiteLogoClassname");Object(O.addFilter)("editor.BlockListBlock","full-site-editing/blocks/template",ne),"wp_template_part"!==fullSiteEditing.editorPostType&&Object(r.registerBlockType)("a8c/template",{title:Object(i.__)("Template Part"),__experimentalDisplayName:"label",description:Object(i.__)("Display a Template Part."),icon:"layout",category:"layout",attributes:{templateId:{type:"number"},className:{type:"string"},label:{type:"string"}},supports:{anchor:!1,customClassName:!1,html:!1,inserter:!1,reusable:!1},edit:te,save:function(){return null},getEditWrapperProps:function(){return{"data-align":"full"}}});var oe=Object(u.createHigherOrderComponent)((function(e){return function(t){return"a8c/template"!==t.name?Object(o.createElement)(e,t):Object(o.createElement)(e,l()({},t,{className:"template__block-container"}))}}),"addFSETemplateClassname");Object(O.addFilter)("editor.BlockListBlock","full-site-editing/blocks/template",oe,9);var re=n(14),ie=n.n(re),ce=n(26),le=n.n(ce);n(40);function ae(e){var t=e.defaultLabel,n=e.defaultUrl,r=Object(o.useState)(t),i=L()(r,2),c=i[0],l=i[1],a=Object(o.useState)(n),s=L()(a,2),u=s[0],p=s[1];return window.wp.hooks.addAction("updateCloseButtonOverrides","a8c-fse",(function(e){l(e.label),p(e.closeUrl)})),Object(o.createElement)("a",{href:u,"aria-label":c},Object(o.createElement)(d.Button,{className:"components-button components-icon-button"},Object(o.createElement)(d.Dashicon,{icon:"arrow-left-alt2"}),Object(o.createElement)("div",{className:"close-button-override__label"},c)))}ie()((function(){var e=fullSiteEditing.editorPostType;if("wp_template_part"===e||"page"===e||"post"===e)var t=setInterval((function(){var n=document.querySelector(".edit-post-header__toolbar");if(n){clearInterval(t);var r=document.createElement("div");r.className="components-toolbar edit-post-fullscreen-mode-close__toolbar edit-post-fullscreen-mode-close__toolbar__override",n.prepend(r);var c=fullSiteEditing,l=c.closeButtonLabel,a=c.closeButtonUrl,s=window.calypsoifyGutenberg;s&&s.closeUrl&&(a=s.closeUrl),s&&s.closeButtonLabel&&(l=s.closeButtonLabel);var u=a||"edit.php?post_type=".concat(e),p=l||"Back";"page"!==e||l?"post"!==e||l?"wp_template_part"!==e||l||(p=Object(i.__)("Template Parts")):p=Object(i.__)("Posts"):p=Object(i.__)("Pages"),le.a.render(Object(o.createElement)(ae,{defaultLabel:p,defaultUrl:u}),r)}}))}));var se=n(27),ue=n.n(se),pe=n(28),de=Object(b.withSelect)((function(e){var t=e("core").getEntityRecord,n=e("core/editor").getEditedPostAttribute;return{templateClasses:Object(X.map)(n("template_part_types"),(function(e){var n=Object(X.get)(t("taxonomy","wp_template_part_type",e),"name","");return Object(X.endsWith)(n,"-header")?"fse-header":Object(X.endsWith)(n,"-footer")?"fse-footer":void 0}))}}))((function(e){var t=e.templateClasses,n=setInterval((function(){var e=document.querySelector(".block-editor-writing-flow.editor-writing-flow > div");e&&(clearInterval(n),e.className=T.a.apply(void 0,["a8c-template-editor fse-template-part"].concat(ue()(t))))}));return null}));"wp_template_part"===fullSiteEditing.editorPostType&&Object(pe.registerPlugin)("fse-editor-template-classes",{render:de}),ie()((function(){"wp_template_part"===fullSiteEditing.editorPostType&&Object(b.dispatch)("core/notices").createNotice("info",Object(i.__)("Updates to this template will affect all pages on your site."),{isDismissible:!1})}));var be=Object(u.compose)(Object(b.withSelect)((function(e){var t=e("core/editor").getEditorSettings,n=e("core/block-editor").getBlocks,o=e("core/edit-post").getEditorMode,r=n().find((function(e){return"a8c/post-content"===e.name}));return{rootClientId:r?r.clientId:"",showInserter:"visual"===o()&&t().richEditingEnabled}})))((function(e){var t=e.rootClientId,n=e.showInserter;return Object(o.createElement)(p.Inserter,{rootClientId:t,disabled:!n,position:"bottom right"})}));ie()((function(){return function(){if("page"===fullSiteEditing.editorPostType)var e=setInterval((function(){var t=document.querySelector(".edit-post-header-toolbar");if(t){clearInterval(e);var n=document.createElement("div");n.classList.add("fse-post-content-block-inserter"),t.insertBefore(n,t.firstChild),Object(o.render)(Object(o.createElement)(be,null),n)}}))}()}));var fe=Object(b.subscribe)((function(){if("page"!==fullSiteEditing.editorPostType)return fe();!1===Object(b.select)("core/block-editor").isValidTemplate()&&Object(b.dispatch)("core/block-editor").setTemplateValidity(!0)})),me=["logo","brand","emblem","hallmark"];Object(O.addFilter)("blocks.registerBlockType","full-site-editing/editor/image-block-keywords",(function(e,t){return"core/image"!==t?e:e=Object(X.assign)({},e,{keywords:e.keywords.concat(me)})}));n(44);Object(b.use)((function(e){return{dispatch:function(t){var n=D()({},e.dispatch(t)),o=fullSiteEditing.editorPostType;return"core/editor"===t&&n.trashPost&&"wp_template_part"===o&&(n.trashPost=function(){}),n}}})),Object(b.use)((function(e){return{dispatch:function(t){var n=D()({},e.dispatch(t)),o=fullSiteEditing.editorPostType;if("core/editor"===t&&n.editPost&&"wp_template_part"===o){var r=n.editPost;n.editPost=function(e){"draft"!==e.status&&r(e)}}return n}}}));var Oe=Object(b.subscribe)((function(){var e=Object(b.dispatch)("core/edit-post").removeEditorPanel;return"page"===fullSiteEditing.editorPostType&&e("featured-image"),"wp_template_part"===fullSiteEditing.editorPostType&&e("post-status"),Oe()}))}]));
1
  /*! For license information please see full-site-editing.js.LICENSE */
2
+ !function(e,t){for(var n in t)e[n]=t[n]}(window,function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=45)}([function(e,t){!function(){e.exports=this.wp.element}()},function(e,t){!function(){e.exports=this.wp.i18n}()},function(e,t){!function(){e.exports=this.wp.blockEditor}()},function(e,t){!function(){e.exports=this.wp.data}()},function(e,t){!function(){e.exports=this.wp.compose}()},function(e,t){!function(){e.exports=this.wp.components}()},function(e,t){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},function(e,t){!function(){e.exports=this.wp.blocks}()},function(e,t){!function(){e.exports=this.lodash}()},function(e,t,n){var o=n(6);function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}e.exports=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){o(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}},function(e,t){function n(){return e.exports=n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},n.apply(this,arguments)}e.exports=n},function(e,t,n){var o;!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t<arguments.length;t++){var o=arguments[t];if(o){var i=typeof o;if("string"===i||"number"===i)e.push(o);else if(Array.isArray(o)&&o.length){var c=r.apply(null,o);c&&e.push(c)}else if("object"===i)for(var l in o)n.call(o,l)&&o[l]&&e.push(l)}}return e.join(" ")}e.exports?(r.default=r,e.exports=r):void 0===(o=function(){return r}.apply(t,[]))||(e.exports=o)}()},function(e,t){!function(){e.exports=this.wp.hooks}()},function(e,t,n){var o=n(34),r=n(35),i=n(36);e.exports=function(e,t){return o(e)||r(e,t)||i()}},function(e,t){!function(){e.exports=this.wp.domReady}()},function(e,t){!function(){e.exports=this.wp.apiFetch}()},function(e,t){!function(){e.exports=this.wp.htmlEntities}()},function(e,t,n){},function(e,t){!function(){e.exports=this.wp.serverSideRender}()},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},function(e,t){function n(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}e.exports=function(e,t,o){return t&&n(e.prototype,t),o&&n(e,o),e}},function(e,t,n){var o=n(30),r=n(31);e.exports=function(e,t){return!t||"object"!==o(t)&&"function"!=typeof t?r(e):t}},function(e,t){function n(t){return e.exports=n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},n(t)}e.exports=n},function(e,t,n){var o=n(32);e.exports=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}},function(e,t){!function(){e.exports=this.wp.editor}()},function(e,t){!function(){e.exports=this.wp.url}()},function(e,t){!function(){e.exports=this.ReactDOM}()},function(e,t,n){var o=n(41),r=n(42),i=n(43);e.exports=function(e){return o(e)||r(e)||i()}},function(e,t){!function(){e.exports=this.wp.plugins}()},function(e,t,n){},function(e,t){function n(t){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?e.exports=n=function(e){return typeof e}:e.exports=n=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(t)}e.exports=n},function(e,t){e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}},function(e,t){function n(t,o){return e.exports=n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(t,o)}e.exports=n},function(e,t,n){},function(e,t){e.exports=function(e){if(Array.isArray(e))return e}},function(e,t){e.exports=function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],o=!0,r=!1,i=void 0;try{for(var c,l=e[Symbol.iterator]();!(o=(c=l.next()).done)&&(n.push(c.value),!t||n.length!==t);o=!0);}catch(a){r=!0,i=a}finally{try{o||null==l.return||l.return()}finally{if(r)throw i}}return n}}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t,n){},function(e,t){e.exports=function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}},function(e,t){e.exports=function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}},function(e,t,n){},function(e,t,n){"use strict";n.r(t);var o=n(0),r=n(7),i=n(1),c=n(10),l=n.n(c),a=n(18),s=n.n(a),u=n(4),p=n(2),d=n(5),b=n(3),f=Object(u.compose)([Object(p.withColors)("backgroundColor",{textColor:"color"}),Object(p.withFontSizes)("fontSize"),Object(b.withSelect)((function(e){return{isPublished:e("core/editor").isCurrentPostPublished()}}))])((function(e){var t=e.attributes,n=e.backgroundColor,r=e.fontSize,c=e.setAttributes,a=e.setBackgroundColor,u=e.setFontSize,b=e.setTextColor,f=e.textColor,m=e.isPublished,O=t.customFontSize,g=t.textAlign,j=O||r.size;return Object(o.createElement)(o.Fragment,null,Object(o.createElement)(p.BlockControls,null,Object(o.createElement)(p.AlignmentToolbar,{value:g,onChange:function(e){c({textAlign:e})}})),Object(o.createElement)(p.InspectorControls,null,Object(o.createElement)(d.PanelBody,{className:"blocks-font-size",title:Object(i.__)("Text Settings")},Object(o.createElement)(p.FontSizePicker,{onChange:u,value:j})),Object(o.createElement)(p.PanelColorSettings,{title:Object(i.__)("Color Settings"),initialOpen:!1,colorSettings:[{value:n.color,onChange:a,label:Object(i.__)("Background Color")},{value:f.color,onChange:b,label:Object(i.__)("Text Color")}]},Object(o.createElement)(p.ContrastChecker,l()({textColor:f.color,backgroundColor:n.color},{fontSize:j})))),Object(o.createElement)(s.a,{isPublished:m,block:"a8c/navigation-menu",attributes:t}))})),m=(n(29),Object(o.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"},Object(o.createElement)("path",{fill:"none",d:"M0 0h24v24H0V0z"}),Object(o.createElement)("path",{d:"M12 7.27l4.28 10.43-3.47-1.53-.81-.36-.81.36-3.47 1.53L12 7.27M12 2L4.5 20.29l.71.71L12 18l6.79 3 .71-.71L12 2z"})));Object(r.registerBlockType)("a8c/navigation-menu",{title:Object(i.__)("Navigation Menu"),description:Object(i.__)("Visual placeholder for site-wide navigation and menus."),icon:m,category:"layout",supports:{align:["wide","full","right","left"],html:!1,reusable:!1},edit:f,save:function(){return null}});var O=n(12),g=n(6),j=n.n(g),v=n(19),h=n.n(v),y=n(20),_=n.n(y),S=n(21),E=n.n(S),k=n(22),w=n.n(k),C=n(23),x=n.n(C),P=n(11),T=n.n(P),B=n(24),I=function(e){function t(){return h()(this,t),E()(this,w()(t).apply(this,arguments))}return x()(t,e),_()(t,[{key:"toggleEditing",value:function(){var e=this.props,t=e.isEditing;(0,e.setState)({isEditing:!t})}},{key:"onSelectPost",value:function(e){var t=e.id,n=e.type;this.props.setState({isEditing:!1,selectedPostId:t,selectedPostType:n})}},{key:"render",value:function(){var e=this.props.attributes.align;return Object(o.createElement)(o.Fragment,null,Object(o.createElement)("div",{className:T()("post-content-block",j()({},"align".concat(e),e))},Object(o.createElement)(B.PostTitle,null),Object(o.createElement)(p.InnerBlocks,{templateLock:!1})))}}]),t}(o.Component),N=Object(u.compose)([Object(u.withState)({isEditing:!1,selectedPostId:void 0,selectedPostType:void 0}),Object(b.withSelect)((function(e,t){var n=t.selectedPostId,o=t.selectedPostType;return{selectedPost:(0,e("core").getEntityRecord)("postType",o,n)}}))])(I);n(33);Object(r.registerBlockType)("a8c/post-content",{title:Object(i.__)("Content"),description:Object(i.__)("The page content."),icon:"layout",category:"layout",supports:{align:["full"],anchor:!1,customClassName:!1,html:!1,inserter:!1,multiple:!1,reusable:!1},attributes:{align:{type:"string",default:"full"}},edit:N,save:function(){return Object(o.createElement)(p.InnerBlocks.Content,null)}});var A=Object(u.createHigherOrderComponent)((function(e){return function(t){return"a8c/post-content"!==t.name?Object(o.createElement)(e,t):Object(o.createElement)(e,l()({},t,{className:"post-content__block"}))}}),"addContentSlotClassname");Object(O.addFilter)("editor.BlockListBlock","full-site-editing/blocks/post-content",A,9);var z=n(9),D=n.n(z),F=n(13),L=n.n(F),R=n(15),V=n.n(R),M=n(16);function U(e){var t=Object(o.useRef)();return Object(o.useEffect)((function(){t.current=e}),[e]),t.current}function H(e,t,n,r,c,l){var a=Object(o.useState)({option:t,previousOption:"",loaded:!1,error:!1}),s=L()(a,2),u=s[0],p=s[1],d=U(r),b=U(c);function f(){p(D()({},u,{option:u.previousOption,isSaving:!1}))}return Object(o.useEffect)((function(){u.loaded||u.error?function(){var t=u.option,o=u.previousOption,l=!o&&!t||t&&o&&t.trim()===o.trim(),a=!t||0===t.trim().length;!r&&d&&a&&f();if(!c||l)return;!b&&c&&function(t){p(D()({},u,{isSaving:!0})),V()({path:"/wp/v2/settings",method:"POST",data:j()({},e,t)}).then((function(){return function(e){p(D()({},u,{previousOption:e,isDirty:!1,isSaving:!1}))}(t)})).catch((function(){n(Object(i.sprintf)(Object(i.__)("Unable to save site %s"),e)),f()}))}(t)}():V()({path:"/wp/v2/settings"}).then((function(t){return p(D()({},u,{option:Object(M.decodeEntities)(t[e]),previousOption:Object(M.decodeEntities)(t[e]),loaded:!0,error:!1}))})).catch((function(){n(Object(i.sprintf)(Object(i.__)("Unable to load site %s"),e)),p(D()({},u,{option:Object(i.sprintf)(Object(i.__)("Error loading site %s"),e),error:!0}))}))})),{siteOptions:u,handleChange:function(e){l({updated:Date.now()}),p(D()({},u,{option:e}))}}}var W=function(e){return Object(u.createHigherOrderComponent)((function(t){return Object(u.pure)((function(n){var r=Object(b.useSelect)((function(e){var t=e("core/editor"),n=t.isSavingPost,o=t.isPublishingPost,r=t.isAutosavingPost,i=t.isCurrentPostPublished;return(n()&&i()||o())&&!r()})),i=Object(b.useDispatch)((function(e){return e("core/notices").createErrorNotice})),c=n.isSelected,a=n.setAttributes,s=Object.keys(e).reduce((function(t,n){var o=e[n],l=H(o.optionName,o.defaultValue,i,c,r,a),s=l.siteOptions,u=l.handleChange;return t[n]={value:s.option,updateValue:u,loaded:s.loaded},t}),{});return Object(o.createElement)(t,l()({},n,s))}))}),"withSiteOptions")},q=fullSiteEditing.footerCreditOptions,G=function(e){var t=e.choice,n=q.find((function(e){return e.value===t}));if(!n)return null;var r=n.renderType,i=n.renderProps,c=n.label,l=D()({label:c},i);return"icon"===r?Object(o.createElement)(d.Icon,l):Object(o.createElement)("span",null," ",l.label," ")},Q=fullSiteEditing,Y=Q.footerCreditOptions,J=Q.defaultCreditOption;var K=Object(u.compose)([W({siteTitleOption:{optionName:"title",defaultValue:Object(i.__)("Site title loading…")},footerCreditOption:{optionName:"footer_credit",defaultValue:Object(i.__)("Footer credit loading…")}})])((function(e){var t=e.attributes.textAlign,n=void 0===t?"center":t,r=e.isSelected,i=e.setAttributes,c=e.footerCreditOption,l=c.value,a=c.updateValue,s=e.siteTitleOption.value,u=l||J;return Object(o.createElement)(o.Fragment,null,Object(o.createElement)(p.BlockControls,null,Object(o.createElement)(p.AlignmentToolbar,{value:n,onChange:function(e){i({textAlign:e})}})),Object(o.createElement)("div",{className:T()("site-info","site-credit__block",j()({},"has-text-align-".concat(n),n))},Object(o.createElement)("span",{className:"site-name"},s),Object(o.createElement)("span",{className:"comma"},","),Object(o.createElement)("span",{className:"site-credit__selection"},r?Object(o.createElement)(d.SelectControl,{onChange:a,value:u,options:Y}):Object(o.createElement)(G,{choice:u}))))}));n(37);Object(r.registerBlockType)("a8c/site-credit",{title:Object(i.__)("WordPress.com Credit"),description:Object(i.__)("This block tells the wolrd that you're using WordPress.com."),icon:"wordpress-alt",category:"layout",supports:{align:["wide","full"],html:!1,multiple:!1,reusable:!1,removal:!1},attributes:{align:{type:"string",default:"wide"},textAlign:{type:"string",default:"center"}},edit:K,save:function(){return null}});var X=n(8);var Z=Object(u.compose)([Object(p.withColors)("backgroundColor",{textColor:"color"}),Object(p.withFontSizes)("fontSize"),Object(b.withSelect)((function(e,t){var n=t.clientId,o=e("core/block-editor"),r=o.getBlockIndex,i=o.getBlockRootClientId,c=o.getTemplateLock,l=i(n);return{blockIndex:r(n,l),isLocked:!!c(l),rootClientId:l}})),Object(b.withDispatch)((function(e,t){var n=t.blockIndex,o=t.rootClientId;return{insertDefaultBlock:function(){return e("core/block-editor").insertDefaultBlock({},o,n+1)}}})),W({siteDescription:{optionName:"description",defaultValue:Object(i.__)("Site description loading…")}})])((function(e){var t,n=e.attributes,r=e.backgroundColor,c=e.className,a=e.fontSize,s=e.insertDefaultBlock,u=e.setAttributes,b=e.setBackgroundColor,f=e.setFontSize,m=e.setTextColor,O=e.siteDescription,g=e.textColor,v=n.customFontSize,h=n.textAlign,y=v||a.size,_=O.value,S=O.updateValue;return Object(o.createElement)(o.Fragment,null,Object(o.createElement)(p.BlockControls,null,Object(o.createElement)(p.AlignmentToolbar,{value:h,onChange:function(e){u({textAlign:e})}})),Object(o.createElement)(p.InspectorControls,null,Object(o.createElement)(d.PanelBody,{className:"blocks-font-size",title:Object(i.__)("Text Settings")},Object(o.createElement)(p.FontSizePicker,{onChange:f,value:y})),Object(o.createElement)(p.PanelColorSettings,{title:Object(i.__)("Color Settings"),initialOpen:!1,colorSettings:[{value:r.color,onChange:b,label:Object(i.__)("Background Color")},{value:g.color,onChange:m,label:Object(i.__)("Text Color")}]},Object(o.createElement)(p.ContrastChecker,l()({textColor:g.color,backgroundColor:r.color},{fontSize:y})))),Object(o.createElement)(p.RichText,{allowedFormats:[],"aria-label":Object(i.__)("Site Description"),className:T()("site-description",c,(t={"has-text-color":g.color,"has-background":r.color},j()(t,"has-text-align-".concat(h),h),j()(t,r.class,r.class),j()(t,g.class,g.class),j()(t,a.class,!v&&a.class),t)),identifier:"content",onChange:S,onReplace:s,onSplit:X.noop,placeholder:Object(i.__)("Add a Site Description"),style:{backgroundColor:r.color,color:g.color,fontSize:y?y+"px":void 0},tagName:"p",value:_}))}));n(38);Object(r.registerBlockType)("a8c/site-description",{title:Object(i.__)("Site Description"),description:Object(i.__)("Site description, also known as the tagline."),icon:Object(o.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24"},Object(o.createElement)("path",{fill:"none",d:"M0 0h24v24H0z"}),Object(o.createElement)("path",{d:"M4 9h16v2H4V9zm0 4h10v2H4v-2z"})),category:"layout",supports:{align:["wide","full"],html:!1,multiple:!1,reusable:!1},attributes:{align:{type:"string",default:"wide"},textAlign:{type:"string",default:"center"},textColor:{type:"string"},customTextColor:{type:"string"},backgroundColor:{type:"string"},customBackgroundColor:{type:"string"},fontSize:{type:"string",default:"small"},customFontSize:{type:"number"}},edit:Z,save:function(){return null}});var $=Object(u.compose)([Object(p.withColors)({textColor:"color"}),Object(p.withFontSizes)("fontSize"),Object(b.withSelect)((function(e,t){var n=t.clientId,o=e("core/block-editor"),r=o.getBlockIndex,i=o.getBlockRootClientId,c=o.getTemplateLock,l=i(n);return{blockIndex:r(n,l),isLocked:!!c(l),rootClientId:l}})),Object(b.withDispatch)((function(e,t){var n=t.blockIndex,o=t.rootClientId;return{insertDefaultBlock:function(){return e("core/block-editor").insertDefaultBlock({},o,n+1)}}})),W({siteTitle:{optionName:"title",defaultValue:Object(i.__)("Site title loading…")}})])((function(e){var t,n=e.attributes,r=e.className,c=e.fontSize,l=e.insertDefaultBlock,a=e.setAttributes,s=e.setFontSize,u=e.setTextColor,b=e.siteTitle,f=e.textColor,m=n.customFontSize,O=n.textAlign,g=m||c.size,v=b.value,h=b.updateValue;return Object(o.createElement)(o.Fragment,null,Object(o.createElement)(p.BlockControls,null,Object(o.createElement)(p.AlignmentToolbar,{value:O,onChange:function(e){a({textAlign:e})}})),Object(o.createElement)(p.InspectorControls,null,Object(o.createElement)(d.PanelBody,{className:"blocks-font-size",title:Object(i.__)("Text Settings")},Object(o.createElement)(p.FontSizePicker,{onChange:s,value:g})),Object(o.createElement)(p.PanelColorSettings,{title:Object(i.__)("Color Settings"),initialOpen:!1,colorSettings:[{value:f.color,onChange:u,label:Object(i.__)("Text Color")}]})),Object(o.createElement)(p.RichText,{allowedFormats:[],"aria-label":Object(i.__)("Site Title"),className:T()("site-title",r,(t={"has-text-color":f.color},j()(t,"has-text-align-".concat(O),O),j()(t,f.class,f.class),j()(t,c.class,!m&&c.class),t)),identifier:"content",onChange:h,onReplace:l,onSplit:X.noop,placeholder:Object(i.__)("Add a Site Title"),style:{color:f.color,fontSize:g?g+"px":void 0},tagName:"h1",value:v}))}));n(39);Object(r.registerBlockType)("a8c/site-title",{title:Object(i.__)("Site Title"),description:Object(i.__)("Your site title."),icon:"layout",category:"layout",supports:{align:["wide","full"],html:!1,multiple:!1,reusable:!1},attributes:{align:{type:"string",default:"wide"},textAlign:{type:"string",default:"center"},textColor:{type:"string"},customTextColor:{type:"string"},fontSize:{type:"string",default:"normal"},customFontSize:{type:"number"}},edit:$,save:function(){return null}});var ee=n(25),te=(n(17),Object(u.compose)(Object(u.withState)({templateClientId:null}),Object(b.withSelect)((function(e,t){var n=t.attributes,o=t.templateClientId,r=e("core").getEntityRecord,i=e("core/editor"),c=i.getCurrentPostId,l=i.isEditedPostDirty,a=e("core/block-editor"),s=a.getBlock,u=a.getSelectedBlock,p=e("core/edit-post").isEditorSidebarOpened,d=n.templateId,b=c(),f=d&&r("postType","wp_template_part",d),m=Object(ee.addQueryArgs)(fullSiteEditing.editTemplateBaseUrl,{post:d,fse_parent_post:b}),O=u();return{currentPostId:b,editTemplateUrl:m,template:f,templateBlock:s(o),templateTitle:Object(X.get)(f,["title","rendered"],""),isDirty:l(),isEditorSidebarOpened:!!p(),isAnyTemplateBlockSelected:O&&"a8c/template"===O.name}})),Object(b.withDispatch)((function(e,t){var n=e("core/block-editor").receiveBlocks,o=e("core/edit-post").openGeneralSidebar,i=t.template,c=t.templateClientId,l=t.setState;return{savePost:e("core/editor").savePost,receiveTemplateBlocks:function(){if(i&&!c){var e=Object(r.parse)(Object(X.get)(i,["content","raw"],"")),t=Object(r.createBlock)("core/group",{},e);n([t]),l({templateClientId:t.clientId})}},openGeneralSidebar:o}})))((function(e){var t,n=e.attributes,r=e.editTemplateUrl,c=e.receiveTemplateBlocks,l=e.template,a=e.templateBlock,s=e.templateTitle,u=e.isDirty,b=e.savePost,f=e.isEditorSidebarOpened,m=e.openGeneralSidebar,O=e.isAnyTemplateBlockSelected;if(!l)return Object(o.createElement)(d.Placeholder,null,Object(o.createElement)(d.Spinner,null));var g=Object(o.createRef)(),v=Object(o.useState)(!1),h=L()(v,2),y=h[0],_=h[1];Object(o.useEffect)((function(){y&&!u&&g.current.click(),c()})),Object(o.useEffect)((function(){var e=document.querySelector(".edit-post-sidebar__panel-tabs ul li:last-child");if(f&&e){if(O)return m("edit-post/document"),void e.classList.add("hidden");e.classList.remove("hidden")}}),[O,f,m]);var S=n.align,E=n.className,k=function(e){e.stopPropagation(),_(!0),u&&(e.preventDefault(),b())};return Object(o.createElement)("div",{className:T()("template-block",(t={},j()(t,"align".concat(S),S),j()(t,"is-navigating-to-template",y),t))},a&&Object(o.createElement)(o.Fragment,null,Object(o.createElement)(d.Disabled,null,Object(o.createElement)("div",{className:E},Object(o.createElement)(p.BlockEdit,{attributes:a.attributes,block:a,clientId:a.clientId,isSelected:!1,name:a.name,setAttributes:X.noop}))),Object(o.createElement)(d.Placeholder,{className:"template-block__overlay",onClick:k},y&&Object(o.createElement)("div",{className:"template-block__loading"},Object(o.createElement)(d.Spinner,null)," ",Object(i.sprintf)(Object(i.__)("Loading editor for: %s"),s)),Object(o.createElement)(d.Button,{className:y?"hidden":null,href:r,onClick:k,isDefault:!0,isLarge:!0,ref:g},Object(i.sprintf)(Object(i.__)("Edit %s"),s)))))}))),ne=Object(u.createHigherOrderComponent)((function(e){return function(t){return"fse-site-logo"!==t.attributes.className?Object(o.createElement)(e,t):Object(o.createElement)(e,l()({},t,{className:"template__site-logo"}))}}),"addFSESiteLogoClassname");Object(O.addFilter)("editor.BlockListBlock","full-site-editing/blocks/template",ne),"wp_template_part"!==fullSiteEditing.editorPostType&&Object(r.registerBlockType)("a8c/template",{title:Object(i.__)("Template Part"),__experimentalDisplayName:"label",description:Object(i.__)("Display a Template Part."),icon:"layout",category:"layout",attributes:{templateId:{type:"number"},className:{type:"string"},label:{type:"string"}},supports:{anchor:!1,customClassName:!1,html:!1,inserter:!1,reusable:!1},edit:te,save:function(){return null},getEditWrapperProps:function(){return{"data-align":"full"}}});var oe=Object(u.createHigherOrderComponent)((function(e){return function(t){return"a8c/template"!==t.name?Object(o.createElement)(e,t):Object(o.createElement)(e,l()({},t,{className:"template__block-container"}))}}),"addFSETemplateClassname");Object(O.addFilter)("editor.BlockListBlock","full-site-editing/blocks/template",oe,9);var re=n(14),ie=n.n(re),ce=n(26),le=n.n(ce);n(40);function ae(e){var t=e.defaultLabel,n=e.defaultUrl,r=Object(o.useState)(t),i=L()(r,2),c=i[0],l=i[1],a=Object(o.useState)(n),s=L()(a,2),u=s[0],p=s[1];return window.wp.hooks.addAction("updateCloseButtonOverrides","a8c-fse",(function(e){l(e.label),p(e.closeUrl)})),Object(o.createElement)("a",{href:u,"aria-label":c},Object(o.createElement)(d.Button,{className:"components-button components-icon-button"},Object(o.createElement)(d.Dashicon,{icon:"arrow-left-alt2"}),Object(o.createElement)("div",{className:"close-button-override__label"},c)))}ie()((function(){var e=fullSiteEditing.editorPostType;if("wp_template_part"===e||"page"===e||"post"===e)var t=setInterval((function(){var n=document.querySelector(".edit-post-header__toolbar");if(n){clearInterval(t);var r=document.createElement("div");r.className="components-toolbar edit-post-fullscreen-mode-close__toolbar edit-post-fullscreen-mode-close__toolbar__override",n.prepend(r);var c=fullSiteEditing,l=c.closeButtonLabel,a=c.closeButtonUrl,s=window.calypsoifyGutenberg;s&&s.closeUrl&&(a=s.closeUrl),s&&s.closeButtonLabel&&(l=s.closeButtonLabel);var u=a||"edit.php?post_type=".concat(e),p=l||"Back";"page"!==e||l?"post"!==e||l?"wp_template_part"!==e||l||(p=Object(i.__)("Template Parts")):p=Object(i.__)("Posts"):p=Object(i.__)("Pages"),le.a.render(Object(o.createElement)(ae,{defaultLabel:p,defaultUrl:u}),r)}}))}));var se=n(27),ue=n.n(se),pe=n(28),de=Object(b.withSelect)((function(e){var t=e("core").getEntityRecord,n=e("core/editor").getEditedPostAttribute;return{templateClasses:Object(X.map)(n("template_part_types"),(function(e){var n=Object(X.get)(t("taxonomy","wp_template_part_type",e),"name","");return Object(X.endsWith)(n,"-header")?"fse-header":Object(X.endsWith)(n,"-footer")?"fse-footer":void 0}))}}))((function(e){var t=e.templateClasses,n=setInterval((function(){var e=document.querySelector(".block-editor-writing-flow.editor-writing-flow > div");e&&(clearInterval(n),e.className=T.a.apply(void 0,["a8c-template-editor fse-template-part"].concat(ue()(t))))}));return null}));"wp_template_part"===fullSiteEditing.editorPostType&&Object(pe.registerPlugin)("fse-editor-template-classes",{render:de}),ie()((function(){"wp_template_part"===fullSiteEditing.editorPostType&&Object(b.dispatch)("core/notices").createNotice("info",Object(i.__)("Updates to this template will affect all pages on your site."),{isDismissible:!1})}));var be=Object(u.compose)(Object(b.withSelect)((function(e){var t=e("core/editor").getEditorSettings,n=e("core/block-editor").getBlocks,o=e("core/edit-post").getEditorMode,r=n().find((function(e){return"a8c/post-content"===e.name}));return{rootClientId:r?r.clientId:"",showInserter:"visual"===o()&&t().richEditingEnabled}})))((function(e){var t=e.rootClientId,n=e.showInserter;return Object(o.createElement)(p.Inserter,{rootClientId:t,disabled:!n,position:"bottom right"})}));ie()((function(){return function(){if("page"===fullSiteEditing.editorPostType)var e=setInterval((function(){var t=document.querySelector(".edit-post-header-toolbar");if(t){clearInterval(e);var n=document.createElement("div");n.classList.add("fse-post-content-block-inserter"),t.insertBefore(n,t.firstChild),Object(o.render)(Object(o.createElement)(be,null),n)}}))}()}));var fe=Object(b.subscribe)((function(){if("page"!==fullSiteEditing.editorPostType)return fe();!1===Object(b.select)("core/block-editor").isValidTemplate()&&Object(b.dispatch)("core/block-editor").setTemplateValidity(!0)})),me=["logo","brand","emblem","hallmark"];Object(O.addFilter)("blocks.registerBlockType","full-site-editing/editor/image-block-keywords",(function(e,t){return"core/image"!==t?e:e=Object(X.assign)({},e,{keywords:e.keywords.concat(me)})}));n(44);Object(b.use)((function(e){return{dispatch:function(t){var n=D()({},e.dispatch(t)),o=fullSiteEditing.editorPostType;return"core/editor"===t&&n.trashPost&&"wp_template_part"===o&&(n.trashPost=function(){}),n}}})),Object(b.use)((function(e){return{dispatch:function(t){var n=D()({},e.dispatch(t)),o=fullSiteEditing.editorPostType;if("core/editor"===t&&n.editPost&&"wp_template_part"===o){var r=n.editPost;n.editPost=function(e){"draft"!==e.status&&r(e)}}return n}}}));var Oe=Object(b.subscribe)((function(){var e=Object(b.dispatch)("core/edit-post").removeEditorPanel;return"page"===fullSiteEditing.editorPostType&&e("featured-image"),"wp_template_part"===fullSiteEditing.editorPostType&&e("post-status"),Oe()}))}]));
full-site-editing/helpers.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Helpers for Full Site Editing.
4
+ *
5
+ * This file is always loaded, so these functions should always exist if the
6
+ * plugin is activated on the site. (Not to be confused with whether FSE is
7
+ * active on the site!)
8
+ *
9
+ * @package A8C\FSE
10
+ */
11
+
12
+ namespace A8C\FSE;
13
+
14
+ /**
15
+ * NOTE: In most cases, you should NOT use this function. Please use
16
+ * load_full_site_editing instead. This function should only be used if you need
17
+ * to include the FSE files somewhere like a script. I.e. if you want to access
18
+ * a class defined here without needing full FSE functionality.
19
+ */
20
+ function dangerously_load_full_site_editing_files() {
21
+ require_once __DIR__ . '/blocks/navigation-menu/index.php';
22
+ require_once __DIR__ . '/blocks/post-content/index.php';
23
+ require_once __DIR__ . '/blocks/site-description/index.php';
24
+ require_once __DIR__ . '/blocks/site-title/index.php';
25
+ require_once __DIR__ . '/blocks/template/index.php';
26
+ require_once __DIR__ . '/class-full-site-editing.php';
27
+ require_once __DIR__ . '/templates/class-rest-templates-controller.php';
28
+ require_once __DIR__ . '/templates/class-wp-template.php';
29
+ require_once __DIR__ . '/templates/class-wp-template-inserter.php';
30
+ require_once __DIR__ . '/templates/class-template-image-inserter.php';
31
+ require_once __DIR__ . '/serialize-block-fallback.php';
32
+ }
33
+
34
+ /**
35
+ * Whether or not FSE is active.
36
+ * If false, FSE functionality should be disabled.
37
+ *
38
+ * @returns bool True if FSE is active, false otherwise.
39
+ */
40
+ function is_full_site_editing_active() {
41
+ /**
42
+ * There are times when this function is called from the WordPress.com public
43
+ * API context. In this case, we need to switch to the correct blog so that
44
+ * the functions reference the correct blog context.
45
+ */
46
+ $multisite_id = apply_filters( 'a8c_fse_get_multisite_id', false );
47
+ $should_switch = is_multisite() && $multisite_id;
48
+ if ( $should_switch ) {
49
+ switch_to_blog( $multisite_id );
50
+ }
51
+
52
+ $is_active = is_site_eligible_for_full_site_editing() && is_theme_supported() && did_insert_template_parts();
53
+
54
+ if ( $should_switch ) {
55
+ restore_current_blog();
56
+ }
57
+ return $is_active;
58
+ }
59
+
60
+ /**
61
+ * Returns the slug for the current theme.
62
+ *
63
+ * This even works for the WordPress.com API context where the current theme is
64
+ * not correct. The filter correctly switches to the correct blog context if
65
+ * that is the case.
66
+ *
67
+ * @return string Theme slug.
68
+ */
69
+ function get_theme_slug() {
70
+ /**
71
+ * Used to get the correct theme in certain contexts.
72
+ *
73
+ * For example, in the wpcom API context, the theme slug is a8c/public-api,
74
+ * so we need to grab the correct one with the filter.
75
+ *
76
+ * @since 0.7
77
+ *
78
+ * @param string current theme slug is the default if nothing overrides it.
79
+ */
80
+ return apply_filters( 'a8c_fse_get_theme_slug', get_stylesheet() );
81
+ }
82
+
83
+ /**
84
+ * Returns a normalized slug for the current theme.
85
+ *
86
+ * In some cases, the theme is located in a subfolder like `pub/maywood`. Use
87
+ * this function to get the slug without the prefix.
88
+ *
89
+ * @param string $theme_slug The raw theme_slug to normalize.
90
+ * @return string Theme slug.
91
+ */
92
+ function normalize_theme_slug( $theme_slug ) {
93
+ // Normalize the theme slug.
94
+ if ( 'pub/' === substr( $theme_slug, 0, 4 ) ) {
95
+ $theme_slug = substr( $theme_slug, 4 );
96
+ }
97
+
98
+ if ( '-wpcom' === substr( $theme_slug, -6, 6 ) ) {
99
+ $theme_slug = substr( $theme_slug, 0, -6 );
100
+ }
101
+
102
+ return $theme_slug;
103
+ }
104
+
105
+ /**
106
+ * Whether or not the site is eligible for FSE. This is essentially a feature
107
+ * gate to disable FSE on some sites which could theoretically otherwise use it.
108
+ *
109
+ * @return bool True if current site is eligible for FSE, false otherwise.
110
+ */
111
+ function is_site_eligible_for_full_site_editing() {
112
+ /**
113
+ * Can be used to disable Full Site Editing functionality.
114
+ *
115
+ * @since 0.2
116
+ *
117
+ * @param bool true if Full Site Editing should be disabled, false otherwise.
118
+ */
119
+ return ! apply_filters( 'a8c_disable_full_site_editing', false );
120
+ }
121
+
122
+ /**
123
+ * Whether or not current theme is enabled for FSE.
124
+ *
125
+ * @return bool True if current theme supports FSE, false otherwise.
126
+ */
127
+ function is_theme_supported() {
128
+ // Use un-normalized theme slug because get_theme requires the full string.
129
+ $theme = wp_get_theme( get_theme_slug() );
130
+ return ! $theme->errors() && in_array( 'full-site-editing', $theme->tags, true );
131
+ }
132
+
133
+ /**
134
+ * Determines if the template parts have been inserted for the current theme.
135
+ *
136
+ * We want to gate on this check in is_full_site_editing_active so that we don't
137
+ * load FSE for sites which did not get template parts for some reason or another.
138
+ *
139
+ * For example, if a user activates theme A on their site and gets FSE, but then
140
+ * activates theme B which does not have FSE, they will not get FSE flows. If we
141
+ * retroactively add FSE support to theme B, the user should not get FSE flows
142
+ * because their site would be modified. Instead, FSE flows would become active
143
+ * when they specifically take action to re-activate the theme.
144
+ *
145
+ * @return bool True if the template parts have been inserted. False otherwise.
146
+ */
147
+ function did_insert_template_parts() {
148
+ require_once __DIR__ . '/templates/class-wp-template-inserter.php';
149
+
150
+ $theme_slug = normalize_theme_slug( get_theme_slug() );
151
+ $inserter = new WP_Template_Inserter( $theme_slug );
152
+ return $inserter->is_template_data_inserted();
153
+ }
154
+
155
+ /**
156
+ * Inserts default full site editing data for current theme on plugin/theme activation.
157
+ *
158
+ * We put this here outside of the normal FSE class because FSE is not active
159
+ * until the template parts are inserted. This makes sure we insert the template
160
+ * parts when switching to a theme which supports FSE.
161
+ *
162
+ * This will populate the default header and footer for current theme, and create
163
+ * About and Contact pages. Nothing will populate if the data already exists, or
164
+ * if the theme is unsupported.
165
+ */
166
+ function populate_wp_template_data() {
167
+ if ( ! is_theme_supported() ) {
168
+ return;
169
+ }
170
+
171
+ require_once __DIR__ . '/templates/class-template-image-inserter.php';
172
+ require_once __DIR__ . '/templates/class-wp-template-inserter.php';
173
+
174
+ $theme_slug = normalize_theme_slug( get_theme_slug() );
175
+
176
+ $template_inserter = new WP_Template_Inserter( $theme_slug );
177
+ $template_inserter->insert_default_template_data();
178
+ $template_inserter->insert_default_pages();
179
+ }
180
+ register_activation_hook( __FILE__, __NAMESPACE__ . '\populate_wp_template_data' );
181
+ add_action( 'switch_theme', __NAMESPACE__ . '\populate_wp_template_data' );
global-styles/class-global-styles.php CHANGED
@@ -385,8 +385,9 @@ class Global_Styles {
385
  * - only the selected ones for the frontend
386
  */
387
  $font_list = [];
388
- // We want $font_list to only contain valid Google Font values, not things like 'unset'.
389
- $font_values = array_diff( $this->get_font_values( $data['font_options'] ), [ 'unset' ] );
 
390
  if ( true === $only_selected_fonts ) {
391
  foreach ( [ 'font_base', 'font_base_default', 'font_headings', 'font_headings_default' ] as $key ) {
392
  if ( in_array( $data[ $key ], $font_values, true ) ) {
@@ -396,13 +397,16 @@ class Global_Styles {
396
  } else {
397
  $font_list = $font_values;
398
  }
399
- $font_list_str = '';
400
- foreach ( $font_list as $font ) {
401
- // Some fonts lack italic variants,
402
- // the API will return only the regular and bold CSS for those.
403
- $font_list_str = $font_list_str . $font . ':regular,bold,italic,bolditalic|';
 
 
 
 
404
  }
405
- $result = $result . "@import url('https://fonts.googleapis.com/css?family=" . $font_list_str . "');";
406
 
407
  /*
408
  * Add the CSS custom properties.
385
  * - only the selected ones for the frontend
386
  */
387
  $font_list = [];
388
+ // We want $font_list to only contain valid Google Font values,
389
+ // so we filter out things like 'unset' on the system font.
390
+ $font_values = array_diff( $this->get_font_values( $data['font_options'] ), [ 'unset', self::SYSTEM_FONT ] );
391
  if ( true === $only_selected_fonts ) {
392
  foreach ( [ 'font_base', 'font_base_default', 'font_headings', 'font_headings_default' ] as $key ) {
393
  if ( in_array( $data[ $key ], $font_values, true ) ) {
397
  } else {
398
  $font_list = $font_values;
399
  }
400
+
401
+ if ( count( $font_list ) > 0 ) {
402
+ $font_list_str = '';
403
+ foreach ( $font_list as $font ) {
404
+ // Some fonts lack italic variants,
405
+ // the API will return only the regular and bold CSS for those.
406
+ $font_list_str = $font_list_str . $font . ':regular,bold,italic,bolditalic|';
407
+ }
408
+ $result = $result . "@import url('https://fonts.googleapis.com/css?family=" . $font_list_str . "');";
409
  }
 
410
 
411
  /*
412
  * Add the CSS custom properties.
global-styles/dist/global-styles.asset.php CHANGED
@@ -1 +1 @@
1
- <?php return array('dependencies' => array('wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-dom-ready', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-keycodes', 'wp-plugins', 'wp-polyfill'), 'version' => '071739fc55cdb3d4abceff3f3c674850');
1
+ <?php return array('dependencies' => array('wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-dom-ready', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-keycodes', 'wp-plugins', 'wp-polyfill'), 'version' => '7b46002aa46c09a594ea1279b226c825');
posts-list-block/blocks/posts-list/editor.scss ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ div.posts-list__notice {
2
+ margin: 0 0 5px;
3
+
4
+ .components-notice__content {
5
+ display: flex;
6
+ align-items: center;
7
+ justify-content: space-between;
8
+ }
9
+ }
posts-list-block/blocks/posts-list/index.js CHANGED
@@ -2,18 +2,25 @@
2
  /**
3
  * WordPress dependencies
4
  */
5
- import { registerBlockType, createBlock } from '@wordpress/blocks';
 
 
 
 
6
  import { __ } from '@wordpress/i18n';
7
- import { Placeholder, RangeControl, PanelBody } from '@wordpress/components';
8
  import { Fragment } from '@wordpress/element';
9
  import { InspectorControls } from '@wordpress/block-editor';
 
10
  /* eslint-enable import/no-extraneous-dependencies */
11
 
12
  /**
13
  * Internal dependencies
14
  */
15
  import * as metadata from './block.json';
 
16
  import './style.scss';
 
17
 
18
  const icon = (
19
  <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
@@ -31,54 +38,73 @@ registerBlockType( metadata.name, {
31
  html: false,
32
  multiple: false,
33
  reusable: false,
 
34
  },
35
  attributes: metadata.attributes,
36
- edit: ( { attributes, setAttributes, isSelected } ) => (
37
- <Fragment>
38
- <Placeholder
39
- icon={ icon }
40
- label={ __( 'Your recent blog posts will be displayed here.', 'full-site-editing' ) }
41
- >
42
- { isSelected ? (
43
- <RangeControl
44
- label={ __( 'Number of posts to show', 'full-site-editing' ) }
45
- value={ attributes.postsPerPage }
46
- onChange={ val => setAttributes( { postsPerPage: val } ) }
47
- min={ 1 }
48
- max={ 50 }
49
- />
50
- ) : null }
51
- </Placeholder>
52
- <InspectorControls>
53
- <PanelBody>
54
- <RangeControl
55
- label={ __( 'Number of posts', 'full-site-editing' ) }
56
- value={ attributes.postsPerPage }
57
- onChange={ val => setAttributes( { postsPerPage: val } ) }
58
- min={ 1 }
59
- max={ 50 }
60
- />
61
- </PanelBody>
62
- </InspectorControls>
63
- </Fragment>
64
- ),
65
- save: () => null,
66
- transforms: {
67
- to: [
68
- {
69
- type: 'block',
70
- blocks: [ 'newspack-blocks/homepage-articles' ],
71
- transform: ( { postsPerPage } ) => {
72
- // Configure the Newspack block to look as close as possible
73
- // to the output of this one.
74
- return createBlock( 'newspack-blocks/homepage-articles', {
75
- postsToShow: postsPerPage,
76
- showAvatar: false,
77
- displayPostDate: true,
78
- displayPostContent: true,
79
- } );
80
- },
81
- },
82
- ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  },
 
 
84
  } );
2
  /**
3
  * WordPress dependencies
4
  */
5
+ import {
6
+ registerBlockType,
7
+ switchToBlockType,
8
+ getPossibleBlockTransformations,
9
+ } from '@wordpress/blocks';
10
  import { __ } from '@wordpress/i18n';
11
+ import { Placeholder, RangeControl, PanelBody, Notice } from '@wordpress/components';
12
  import { Fragment } from '@wordpress/element';
13
  import { InspectorControls } from '@wordpress/block-editor';
14
+ import { select, dispatch } from '@wordpress/data';
15
  /* eslint-enable import/no-extraneous-dependencies */
16
 
17
  /**
18
  * Internal dependencies
19
  */
20
  import * as metadata from './block.json';
21
+ import './editor.scss';
22
  import './style.scss';
23
+ import { transforms, isValidHomepagePostsBlockType } from './transforms';
24
 
25
  const icon = (
26
  <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
38
  html: false,
39
  multiple: false,
40
  reusable: false,
41
+ inserter: false,
42
  },
43
  attributes: metadata.attributes,
44
+ edit: ( { attributes, setAttributes, clientId, isSelected } ) => {
45
+ const block = select( 'core/block-editor' ).getBlock( clientId );
46
+
47
+ // Find if any of possible transformations is into the Homepage Posts block.
48
+ const possibleTransforms = getPossibleBlockTransformations( [ block ] );
49
+ const homepagePostsTransform = possibleTransforms.find(
50
+ transform => transform && isValidHomepagePostsBlockType( transform.name )
51
+ );
52
+ const canBeUpgraded = !! homepagePostsTransform;
53
+
54
+ const upgradeBlock = () => {
55
+ dispatch( 'core/block-editor' ).replaceBlocks(
56
+ block.clientId,
57
+ switchToBlockType( block, homepagePostsTransform.name )
58
+ );
59
+ };
60
+
61
+ return (
62
+ <Fragment>
63
+ { canBeUpgraded && (
64
+ <Notice
65
+ actions={ [
66
+ {
67
+ label: __( 'Update Block', 'full-site-editing' ),
68
+ onClick: upgradeBlock,
69
+ },
70
+ ] }
71
+ className="posts-list__notice"
72
+ isDismissible={ false }
73
+ >
74
+ { __(
75
+ 'An improved version of this block is available. Update for a better, more natural way to manage your blog post listings. There may be small visual changes.',
76
+ 'full-site-editing'
77
+ ) }
78
+ </Notice>
79
+ ) }
80
+ <Placeholder
81
+ icon={ icon }
82
+ label={ __( 'Your recent blog posts will be displayed here.', 'full-site-editing' ) }
83
+ >
84
+ { isSelected ? (
85
+ <RangeControl
86
+ label={ __( 'Number of posts to show', 'full-site-editing' ) }
87
+ value={ attributes.postsPerPage }
88
+ onChange={ val => setAttributes( { postsPerPage: val } ) }
89
+ min={ 1 }
90
+ max={ 50 }
91
+ />
92
+ ) : null }
93
+ </Placeholder>
94
+ <InspectorControls>
95
+ <PanelBody>
96
+ <RangeControl
97
+ label={ __( 'Number of posts', 'full-site-editing' ) }
98
+ value={ attributes.postsPerPage }
99
+ onChange={ val => setAttributes( { postsPerPage: val } ) }
100
+ min={ 1 }
101
+ max={ 50 }
102
+ />
103
+ </PanelBody>
104
+ </InspectorControls>
105
+ </Fragment>
106
+ );
107
  },
108
+ save: () => null,
109
+ transforms,
110
  } );
posts-list-block/blocks/posts-list/transforms.js ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * External dependencies
3
+ */
4
+
5
+ /* eslint-disable import/no-extraneous-dependencies */
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { createBlock } from '@wordpress/blocks';
10
+ /* eslint-enable import/no-extraneous-dependencies */
11
+
12
+ const HOMEPAGE_POSTS_BLOCK_TYPES = [ 'a8c/blog-posts', 'newspack-blocks/homepage-articles' ];
13
+
14
+ const getTransformFunction = type => ( { postsPerPage } ) => {
15
+ // Configure the Newspack block to look as close as possible
16
+ // to the output of this one.
17
+ return createBlock( type, {
18
+ postsToShow: postsPerPage,
19
+ showAvatar: false,
20
+ displayPostDate: true,
21
+ displayPostContent: true,
22
+ } );
23
+ };
24
+
25
+ export const isValidHomepagePostsBlockType = type =>
26
+ HOMEPAGE_POSTS_BLOCK_TYPES.indexOf( type ) > -1;
27
+
28
+ export const transforms = {
29
+ to: HOMEPAGE_POSTS_BLOCK_TYPES.map( type => ( {
30
+ type: 'block',
31
+ blocks: [ type ],
32
+ transform: getTransformFunction( type ),
33
+ } ) ),
34
+ };
posts-list-block/dist/posts-list-block.asset.php CHANGED
@@ -1 +1 @@
1
- <?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => '3db81c8fa659ba0ed7934e180184706e');
1
+ <?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => 'f0483730afc14121e3c57f1d14a2b90b');
posts-list-block/dist/posts-list-block.css CHANGED
@@ -1 +1 @@
1
- .a8c-posts-list__listing{list-style:none;margin:0;padding:0}.a8c-posts-list__item{display:block}
1
+ div.posts-list__notice{margin:0 0 5px}div.posts-list__notice .components-notice__content{display:flex;align-items:center;justify-content:space-between}.a8c-posts-list__listing{list-style:none;margin:0;padding:0}.a8c-posts-list__item{display:block}
posts-list-block/dist/posts-list-block.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){for(var n in t)e[n]=t[n]}(window,function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=7)}([function(e,t){!function(){e.exports=this.wp.element}()},function(e,t){!function(){e.exports=this.wp.i18n}()},function(e,t){!function(){e.exports=this.wp.components}()},function(e,t){!function(){e.exports=this.wp.blocks}()},function(e){e.exports=JSON.parse('{"b":"a8c/posts-list","a":{"postsPerPage":{"type":"number","default":10}}}')},function(e,t){!function(){e.exports=this.wp.blockEditor}()},function(e,t,n){},function(e,t,n){"use strict";n.r(t);var o=n(0),r=n(3),l=n(1),i=n(2),s=n(5),c=n(4),u=(n(6),Object(o.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"},Object(o.createElement)("path",{opacity:".87",fill:"none",d:"M0 0h24v24H0V0z"}),Object(o.createElement)("path",{d:"M3 5v14h17V5H3zm4 2v2H5V7h2zm-2 6v-2h2v2H5zm0 2h2v2H5v-2zm13 2H9v-2h9v2zm0-4H9v-2h9v2zm0-4H9V7h9v2z"})));Object(r.registerBlockType)(c.b,{title:Object(l.__)("Blog Posts Listing","full-site-editing"),description:Object(l.__)("Displays your latest Blog Posts.","full-site-editing"),icon:u,category:"layout",supports:{html:!1,multiple:!1,reusable:!1},attributes:c.a,edit:function(e){var t=e.attributes,n=e.setAttributes,r=e.isSelected;return Object(o.createElement)(o.Fragment,null,Object(o.createElement)(i.Placeholder,{icon:u,label:Object(l.__)("Your recent blog posts will be displayed here.","full-site-editing")},r?Object(o.createElement)(i.RangeControl,{label:Object(l.__)("Number of posts to show","full-site-editing"),value:t.postsPerPage,onChange:function(e){return n({postsPerPage:e})},min:1,max:50}):null),Object(o.createElement)(s.InspectorControls,null,Object(o.createElement)(i.PanelBody,null,Object(o.createElement)(i.RangeControl,{label:Object(l.__)("Number of posts","full-site-editing"),value:t.postsPerPage,onChange:function(e){return n({postsPerPage:e})},min:1,max:50}))))},save:function(){return null},transforms:{to:[{type:"block",blocks:["newspack-blocks/homepage-articles"],transform:function(e){var t=e.postsPerPage;return Object(r.createBlock)("newspack-blocks/homepage-articles",{postsToShow:t,showAvatar:!1,displayPostDate:!0,displayPostContent:!0})}}]}})}]));
1
+ !function(e,t){for(var n in t)e[n]=t[n]}(window,function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=9)}([function(e,t){!function(){e.exports=this.wp.element}()},function(e,t){!function(){e.exports=this.wp.i18n}()},function(e,t){!function(){e.exports=this.wp.blocks}()},function(e,t){!function(){e.exports=this.wp.components}()},function(e,t){!function(){e.exports=this.wp.data}()},function(e){e.exports=JSON.parse('{"b":"a8c/posts-list","a":{"postsPerPage":{"type":"number","default":10}}}')},function(e,t){!function(){e.exports=this.wp.blockEditor}()},function(e,t,n){},function(e,t,n){},function(e,t,n){"use strict";n.r(t);var o=n(0),r=n(2),i=n(1),l=n(3),s=n(6),c=n(4),a=n(5),u=(n(7),n(8),["a8c/blog-posts","newspack-blocks/homepage-articles"]),f=function(e){return function(t){var n=t.postsPerPage;return Object(r.createBlock)(e,{postsToShow:n,showAvatar:!1,displayPostDate:!0,displayPostContent:!0})}},p={to:u.map((function(e){return{type:"block",blocks:[e],transform:f(e)}}))},b=Object(o.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"},Object(o.createElement)("path",{opacity:".87",fill:"none",d:"M0 0h24v24H0V0z"}),Object(o.createElement)("path",{d:"M3 5v14h17V5H3zm4 2v2H5V7h2zm-2 6v-2h2v2H5zm0 2h2v2H5v-2zm13 2H9v-2h9v2zm0-4H9v-2h9v2zm0-4H9V7h9v2z"}));Object(r.registerBlockType)(a.b,{title:Object(i.__)("Blog Posts Listing","full-site-editing"),description:Object(i.__)("Displays your latest Blog Posts.","full-site-editing"),icon:b,category:"layout",supports:{html:!1,multiple:!1,reusable:!1,inserter:!1},attributes:a.a,edit:function(e){var t=e.attributes,n=e.setAttributes,a=e.clientId,f=e.isSelected,p=Object(c.select)("core/block-editor").getBlock(a),d=Object(r.getPossibleBlockTransformations)([p]).find((function(e){return e&&(t=e.name,u.indexOf(t)>-1);var t})),m=!!d;return Object(o.createElement)(o.Fragment,null,m&&Object(o.createElement)(l.Notice,{actions:[{label:Object(i.__)("Update Block","full-site-editing"),onClick:function(){Object(c.dispatch)("core/block-editor").replaceBlocks(p.clientId,Object(r.switchToBlockType)(p,d.name))}}],className:"posts-list__notice",isDismissible:!1},Object(i.__)("An improved version of this block is available. Update for a better, more natural way to manage your blog post listings. There may be small visual changes.","full-site-editing")),Object(o.createElement)(l.Placeholder,{icon:b,label:Object(i.__)("Your recent blog posts will be displayed here.","full-site-editing")},f?Object(o.createElement)(l.RangeControl,{label:Object(i.__)("Number of posts to show","full-site-editing"),value:t.postsPerPage,onChange:function(e){return n({postsPerPage:e})},min:1,max:50}):null),Object(o.createElement)(s.InspectorControls,null,Object(o.createElement)(l.PanelBody,null,Object(o.createElement)(l.RangeControl,{label:Object(i.__)("Number of posts","full-site-editing"),value:t.postsPerPage,onChange:function(e){return n({postsPerPage:e})},min:1,max:50}))))},save:function(){return null},transforms:p})}]));
posts-list-block/dist/posts-list-block.rtl.css CHANGED
@@ -1 +1 @@
1
- .a8c-posts-list__listing{list-style:none;margin:0;padding:0}.a8c-posts-list__item{display:block}
1
+ div.posts-list__notice{margin:0 0 5px}div.posts-list__notice .components-notice__content{display:flex;align-items:center;justify-content:space-between}.a8c-posts-list__listing{list-style:none;margin:0;padding:0}.a8c-posts-list__item{display:block}
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: alexislloyd, allancole, automattic, codebykat, copons, dmsnell, ge
3
  Tags: block, blocks, editor, gutenberg, page
4
  Requires at least: 5.0
5
  Tested up to: 5.3
6
- Stable tag: 0.16.2
7
  Requires PHP: 5.6.20
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -42,8 +42,10 @@ This plugin is experimental, so we don't provide any support for it outside of w
42
 
43
  == Changelog ==
44
 
45
- = 0.16.2 =
 
46
 
 
47
  * Fix for Global Styles. Logged out users weren't getting the fonts properly.
48
 
49
  = 0.16.1 =
@@ -51,35 +53,29 @@ This plugin is experimental, so we don't provide any support for it outside of w
51
  * Consistent back button styles.
52
 
53
  = 0.16 =
54
-
55
  * Delegate FSE support detection to themes by leveraging the theme tags.
56
  * Enable Global Styles for all template-first themes.
57
  * Fix back button navigation issues.
58
  * Keep the sidebar layout selector open by default.
59
  * Fix editor styles with new Gutenberg version.
60
- * Clyck anywhere on header/footer block to Navigate to editor.
61
 
62
  = 0.15.1 =
63
-
64
  * Always open the layout selector if the `?new-homepage` query argument exists.
65
 
66
  = 0.15 =
67
-
68
  * Add ability to change page layout for existing pages.
69
  * Expose Homepage layouts from other themes in page layout picker.
70
 
71
  = 0.14 =
72
-
73
  * Stop using theme classes for template parts to improve support for FSE blocks' style attributes.
74
 
75
  = 0.13 =
76
-
77
  * Incorporate Global Styles plugin functionality.
78
  * Side-load images on template insertion.
79
  * Remove widgets menu from wp-admin.
80
 
81
  = 0.12 =
82
-
83
  * Change menu order of default pages that FSE creates to 1.
84
 
85
  = 0.11 =
3
  Tags: block, blocks, editor, gutenberg, page
4
  Requires at least: 5.0
5
  Tested up to: 5.3
6
+ Stable tag: 0.17
7
  Requires PHP: 5.6.20
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
42
 
43
  == Changelog ==
44
 
45
+ = 0.17 =
46
+ * Introduces Blog Posts block, a better version of Posts List.
47
 
48
+ = 0.16.2 =
49
  * Fix for Global Styles. Logged out users weren't getting the fonts properly.
50
 
51
  = 0.16.1 =
53
  * Consistent back button styles.
54
 
55
  = 0.16 =
 
56
  * Delegate FSE support detection to themes by leveraging the theme tags.
57
  * Enable Global Styles for all template-first themes.
58
  * Fix back button navigation issues.
59
  * Keep the sidebar layout selector open by default.
60
  * Fix editor styles with new Gutenberg version.
61
+ * Click anywhere on header/footer block to Navigate to editor.
62
 
63
  = 0.15.1 =
 
64
  * Always open the layout selector if the `?new-homepage` query argument exists.
65
 
66
  = 0.15 =
 
67
  * Add ability to change page layout for existing pages.
68
  * Expose Homepage layouts from other themes in page layout picker.
69
 
70
  = 0.14 =
 
71
  * Stop using theme classes for template parts to improve support for FSE blocks' style attributes.
72
 
73
  = 0.13 =
 
74
  * Incorporate Global Styles plugin functionality.
75
  * Side-load images on template insertion.
76
  * Remove widgets menu from wp-admin.
77
 
78
  = 0.12 =
 
79
  * Change menu order of default pages that FSE creates to 1.
80
 
81
  = 0.11 =
starter-page-templates/dist/starter-page-templates.asset.php CHANGED
@@ -1 +1 @@
1
- <?php return array('dependencies' => array('lodash', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-nux', 'wp-plugins', 'wp-polyfill', 'wp-url'), 'version' => '59d1f6914b28d26c8ce5943919338b6f');
1
+ <?php return array('dependencies' => array('lodash', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-nux', 'wp-plugins', 'wp-polyfill', 'wp-url'), 'version' => '307c64109b16cd6016d3ee77cd1a492a');
starter-page-templates/dist/starter-page-templates.js CHANGED
@@ -1,2 +1,2 @@
1
  /*! For license information please see starter-page-templates.js.LICENSE */
2
- !function(e,t){for(var n in t)e[n]=t[n]}(window,function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=33)}([function(e,t){!function(){e.exports=this.wp.element}()},function(e,t){!function(){e.exports=this.lodash}()},function(e,t){!function(){e.exports=this.wp.i18n}()},function(e,t){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},function(e,t){!function(){e.exports=this.wp.components}()},function(e,t){e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}},function(e,t){!function(){e.exports=this.wp.data}()},function(e,t,n){var r;!function(){"use strict";var n={}.hasOwnProperty;function i(){for(var e=[],t=0;t<arguments.length;t++){var r=arguments[t];if(r){var a=typeof r;if("string"===a||"number"===a)e.push(r);else if(Array.isArray(r)&&r.length){var o=i.apply(null,r);o&&e.push(o)}else if("object"===a)for(var l in r)n.call(r,l)&&r[l]&&e.push(l)}}return e.join(" ")}e.exports?(i.default=i,e.exports=i):void 0===(r=function(){return i}.apply(t,[]))||(e.exports=r)}()},function(e,t){!function(){e.exports=this.wp.compose}()},function(e,t,n){var r=n(3);function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}e.exports=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}},function(e,t,n){var r=n(23),i=n(24),a=n(25);e.exports=function(e){return r(e)||i(e)||a()}},function(e,t,n){var r=n(26),i=n(27),a=n(28);e.exports=function(e,t){return r(e)||i(e,t)||a()}},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},function(e,t){function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}e.exports=function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}},function(e,t,n){var r=n(29),i=n(5);e.exports=function(e,t){return!t||"object"!==r(t)&&"function"!=typeof t?i(e):t}},function(e,t){function n(t){return e.exports=n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},n(t)}e.exports=n},function(e,t,n){var r=n(30);e.exports=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&r(e,t)}},function(e,t){!function(){e.exports=this.wp.blockEditor}()},function(e,t){!function(){e.exports=this.wp.plugins}()},function(e,t){!function(){e.exports=this.wp.editPost}()},function(e,t){!function(){e.exports=this.wp.blocks}()},function(e,t){!function(){e.exports=this.wp.apiFetch}()},function(e,t){!function(){e.exports=this.wp.url}()},function(e,t){e.exports=function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}},function(e,t){e.exports=function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}},function(e,t){e.exports=function(e){if(Array.isArray(e))return e}},function(e,t){e.exports=function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],r=!0,i=!1,a=void 0;try{for(var o,l=e[Symbol.iterator]();!(r=(o=l.next()).done)&&(n.push(o.value),!t||n.length!==t);r=!0);}catch(s){i=!0,a=s}finally{try{r||null==l.return||l.return()}finally{if(i)throw a}}return n}}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}},function(e,t){function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(t){return"function"==typeof Symbol&&"symbol"===n(Symbol.iterator)?e.exports=r=function(e){return n(e)}:e.exports=r=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":n(e)},r(t)}e.exports=r},function(e,t){function n(t,r){return e.exports=n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(t,r)}e.exports=n},function(e,t){!function(){e.exports=this.wp.nux}()},function(e,t,n){},function(e,t,n){"use strict";n.r(t);var r=n(0),i=n(2),a=n(18),o=n(6),l=n(19),s=n(9),c=n.n(s),u=n(10),p=n.n(u),m=n(11),d=n.n(m),f=n(12),b=n.n(f),g=n(13),v=n.n(g),O=n(14),y=n.n(O),h=n(15),j=n.n(h),_=n(5),w=n.n(_),E=n(16),T=n.n(E),P=n(3),S=n.n(P),k=n(1),x=n(7),N=n.n(x),B=(n(31),n(8)),C=n(4),I=n(20),M=(n(32),n(17)),A=function(e){var t=e.blocks,n=void 0===t?[]:t,i=e.viewportWidth;return n&&n.length?Object(r.createElement)("div",{className:"edit-post-visual-editor"},Object(r.createElement)("div",{className:"editor-styles-wrapper"},Object(r.createElement)("div",{className:"editor-writing-flow"},Object(r.createElement)(M.BlockPreview,{blocks:n,viewportWidth:i})))):null},L=function(e){var t=e.id,n=e.value,i=e.onSelect,a=e.label,o=e.useDynamicPreview,l=void 0!==o&&o,s=e.staticPreviewImg,c=e.staticPreviewImgAlt,u=void 0===c?"":c,p=e.blocks,m=void 0===p?[]:p,d=e.isSelected,f=e.handleTemplateConfirmation;if(Object(k.isNil)(t)||Object(k.isNil)(a)||Object(k.isNil)(n))return null;if(l&&(Object(k.isNil)(m)||Object(k.isEmpty)(m)))return null;var b=l?Object(r.createElement)(C.Disabled,null,Object(r.createElement)(A,{blocks:m,viewportWidth:960})):Object(r.createElement)("img",{className:"template-selector-item__media",src:s,alt:u}),g="label-".concat(t,"-").concat(n);return Object(r.createElement)("button",{type:"button",className:N()("template-selector-item__label",{"is-selected":d}),value:n,onClick:function(){var e=window.matchMedia("(min-width: 660px)").matches;i(n),e||f(n)},"aria-labelledby":"".concat(t," ").concat(g)},Object(r.createElement)("div",{className:"template-selector-item__preview-wrap"},b),Object(r.createElement)("span",{className:"template-selector-item__template-title",id:g},a))},D={Address:Object(i._x)("123 Main St","default address","full-site-editing"),Phone:Object(i._x)("555-555-5555","default phone number","full-site-editing"),CompanyName:Object(i._x)("Your Company Name","default company name","full-site-editing"),Vertical:Object(i._x)("Business","default vertical name","full-site-editing")},F={CompanyName:"title",Address:"address",Phone:"phone",Vertical:"vertical"},W=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e?e.replace(/{{(\w+)}}/g,(function(e,n){var r=D[n];return t[F[n]]||r||n})):""},U=Object(B.compose)(r.memo,B.withInstanceId)((function(e){var t=e.label,n=e.className,i=e.help,a=e.instanceId,o=e.templates,l=void 0===o?[]:o,s=e.blocksByTemplates,c=void 0===s?{}:s,u=e.useDynamicPreview,p=void 0!==u&&u,m=e.onTemplateSelect,d=void 0===m?k.noop:m,f=e.siteInformation,b=void 0===f?{}:f,g=e.selectedTemplate,v=e.handleTemplateConfirmation,O=void 0===v?k.noop:v;if(Object(k.isEmpty)(l)||!Object(k.isArray)(l))return null;if(!0===p&&Object(k.isEmpty)(c))return null;var y="template-selector-control-".concat(a);return Object(r.createElement)(C.BaseControl,{label:t,id:y,help:i,className:N()(n,"template-selector-control")},Object(r.createElement)("ul",{className:"template-selector-control__options","data-testid":"template-selector-control-options"},Object(k.map)(l,(function(e){var t=e.slug,n=e.title,a=e.preview,o=e.previewAlt;return Object(r.createElement)("li",{key:"".concat(y,"-").concat(t),className:"template-selector-control__template"},Object(r.createElement)(L,{id:y,value:t,label:W(n,b),help:i,onSelect:d,staticPreviewImg:a,staticPreviewImgAlt:o,blocks:c.hasOwnProperty(t)?c[t]:[],useDynamicPreview:p,isSelected:t===g,handleTemplateConfirmation:O}))}))))})),q=function(e){var t=e.title,n=e.transform;return(Object(r.createElement)("div",{className:"editor-post-title",style:{transform:n}},Object(r.createElement)("div",{className:"wp-block editor-post-title__block"},Object(r.createElement)("textarea",{className:"editor-post-title__input",value:t,onChange:function(){}}))))},R=function(e){return Object(r.createElement)(M.BlockPreview,e)},G=function(e){var t=e.blocks,n=e.viewportWidth,a=e.title,o=Object(r.useState)("hidden"),l=d()(o,2),s=l[0],c=l[1],u=Object(r.useRef)(null),p=Object(r.useReducer)((function(e){return e+1}),0),m=d()(p,2),f=m[0],b=m[1],g=function(){setTimeout((function(){if(u&&u.current){var e=u.current.querySelector(".block-editor-block-preview__content");if(e){var t=window.getComputedStyle(e);if(t&&t.transform){var n=u.current.querySelector(".editor-post-title");n&&(n.style.transform=t.transform);var r=t.transform.replace(/matrix\((.+)\)$/i,"$1").split(",");r=r&&r.length?Number(r[0]):null,r=isNaN(r)?null:r;var i=e.closest(".template-selector-preview__offset-correction");if(i&&r){var a=n?n.offsetHeight:null;i.style.top="".concat(a*r,"px")}}c("visible")}}}),300)};return Object(r.useLayoutEffect)((function(){c("hidden"),g()}),[t]),Object(r.useEffect)((function(){if(t&&t.length){var e=Object(k.debounce)((function(){g(),b()}),300);return window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}}),[t]),Object(k.isEmpty)(t)||!Object(k.isArray)(t)?Object(r.createElement)("div",{className:N()("template-selector-preview","is-blank-preview")},Object(r.createElement)("div",{className:"template-selector-preview__placeholder"},Object(i.__)("Select a layout to preview.","full-site-editing"))):Object(r.createElement)("div",{className:"template-selector-preview"},Object(r.createElement)(C.Disabled,null,Object(r.createElement)("div",{ref:u,className:"edit-post-visual-editor"},Object(r.createElement)("div",{className:"editor-styles-wrapper",style:{visibility:s}},Object(r.createElement)("div",{className:"editor-writing-flow"},Object(r.createElement)(q,{title:a}),Object(r.createElement)("div",{className:"template-selector-preview__offset-correction"},Object(r.createElement)(R,{key:f,blocks:t,viewportWidth:n})))))))};window._tkq=window._tkq||[];var z,V=null,H=function(e,t){V&&window._tkq.push(["recordEvent","a8c_full_site_editing_template_selector_dismiss",{blog_id:V.blogid,segment_id:e,vertical_id:t}])},$=function(e,t,n){V&&window._tkq.push(["recordEvent","a8c_full_site_editing_template_selector_template_selected",{blog_id:V.blogid,segment_id:e,vertical_id:t,template:n}])},Q=n(21),Y=n.n(Q),J=n(22),K=function(e,t,n){var r=e[t=Object(J.removeQueryArgs)(t,"w","s")]||{url:t,usages:[]};return c()({},e,S()({},t,c()({},r,{usages:[].concat(p()(r.usages),p()(n))})))},X=function e(t,n){switch(t.blocksByClientId[n.clientId]=n,n.name){case"core/cover":case"core/image":var r=n.attributes.url;r&&(t.assets=K(t.assets,r,[{prop:"url",path:[n.clientId,"attributes","url"]},{prop:"id",path:[n.clientId,"attributes","id"]}]));case"core/media-text":var i=n.attributes.mediaUrl;i&&"image"===n.attributes.mediaType&&(t.assets=K(t.assets,i,[{prop:"url",path:[n.clientId,"attributes","mediaUrl"]},{prop:"id",path:[n.clientId,"attributes","mediaId"]}]));case"core/gallery":Object(k.forEach)(n.attributes.images,(function(e,r){t.assets=K(t.assets,e.url,[{prop:"url",path:[n.clientId,"attributes","images",r,"url"]},{prop:"url",path:[n.clientId,"attributes","images",r,"link"]},{prop:"id",path:[n.clientId,"attributes","images",r,"id"]},{prop:"id",path:[n.clientId,"attributes","ids",r]}])}))}return Object(k.isEmpty)(n.innerBlocks)?t:Object(k.reduce)(n.innerBlocks,e,t)},Z=function(e){return regeneratorRuntime.async((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,regeneratorRuntime.awrap(Y()({method:"POST",path:"/fse/v1/sideload/image/batch",data:{resources:Object(k.map)(e)}}).then((function(t){return Object(k.reduce)(e,(function(e,n){var r=t.shift(),i=r.id,a=r.source_url;return c()({},e,S()({},n.url,{id:i,url:a}))}),{})})));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}))},ee=function(e,t){return Object(k.forEach)(e.assets,(function(n){var r=t[n.url];r&&Object(k.forEach)(n.usages,(function(t){Object(k.set)(e.blocksByClientId,t.path,r[t.prop])}))})),e.blocks},te=function(e){var t;return regeneratorRuntime.async((function(n){for(;;)switch(n.prev=n.next){case 0:if(t=Object(k.reduce)(e,X,{assets:{},blocksByClientId:{},blocks:e}),!Object(k.isEmpty)(t.assets)){n.next=3;break}return n.abrupt("return",e);case 3:return n.abrupt("return",Z(t.assets).then((function(e){return ee(t,e)})));case 4:case"end":return n.stop()}}))},ne="maywood",re=function(e){function t(e){var n;b()(this,t),n=y()(this,j()(t).call(this)),S()(w()(n),"state",{isLoading:!1,previewedTemplate:null,blocksByTemplateSlug:{},titlesByTemplateSlug:{},error:null,isOpen:!1}),S()(w()(n),"getDefaultSelectedTemplate",(function(e){var t=Object(k.get)(e.templates,[0,"slug"]),n=e._starter_page_template;if(!e.isFrontPage&&!n)return t;"home"===n&&(n=e.theme);var r=n||e.theme;return Object(k.find)(e.templates,{slug:r})?r:Object(k.find)(e.templates,{slug:ne})?ne:t})),S()(w()(n),"setTemplate",(function(e){$(n.props.segment.id,n.props.vertical.id,e),n.props.saveTemplateChoice(e);var t=Object(k.find)(n.props.templates,{slug:e,category:"home"}),r=n.getBlocksByTemplateSlug(e),i=t?null:n.getTitleByTemplateSlug(e);r&&r.length?(n.setState({error:null,isLoading:!0}),n.maybePrefetchAssets(r).then((function(e){n.state.isOpen&&(n.props.insertTemplate(i,e),n.setState({isOpen:!1}))})).catch((function(e){n.setState({isLoading:!1,error:e})}))):n.setState({isOpen:!1})})),S()(w()(n),"maybePrefetchAssets",(function(e){return n.props.shouldPrefetchAssets?te(e):Promise.resolve(e)})),S()(w()(n),"handleConfirmation",(function(e){"string"!=typeof e&&(e=n.state.previewedTemplate),n.setTemplate(e),n.props.isPromptedFromSidebar&&n.props.toggleTemplateModal()})),S()(w()(n),"previewTemplate",(function(e){return n.setState({previewedTemplate:e})})),S()(w()(n),"closeModal",(function(e){if(e.target.matches("button.template-selector-item__label"))return!1;H(n.props.segment.id,n.props.vertical.id);var t=Object(k.get)(window,["calypsoifyGutenberg","closeUrl"]);window.top.location=t||"edit.php?post_type=page"})),S()(w()(n),"getTemplateGroups",(function(){var e=Object(k.partition)(n.props.templates,{category:"home"}),t=d()(e,2),r=t[0],i=t[1],a=Object(k.find)(n.props.templates,{slug:n.props.theme})||Object(k.find)(n.props.templates,{slug:ne});if(!n.props.isFrontPage||!a)return{homepageTemplates:Object(k.sortBy)(r,"title"),defaultTemplates:i};var o=Object(k.reject)(r,{slug:a.slug});return{homepageTemplates:[a].concat(p()(Object(k.sortBy)(o,"title"))),defaultTemplates:i}})),S()(w()(n),"renderTemplatesList",(function(e,t){return Object(r.createElement)("fieldset",{className:"page-template-modal__list"},Object(r.createElement)("legend",{className:"page-template-modal__form-title"},t),Object(r.createElement)(U,{label:Object(i.__)("Layout","full-site-editing"),templates:e,blocksByTemplates:n.state.blocksByTemplateSlug,onTemplateSelect:n.previewTemplate,useDynamicPreview:!1,siteInformation:n.props.siteInformation,selectedTemplate:n.state.previewedTemplate,handleTemplateConfirmation:n.handleConfirmation}))}));var a=!Object(k.isEmpty)(e.templates);return n.state.isOpen=a,a&&(n.state.previewedTemplate=n.getDefaultSelectedTemplate(e),n.state.titlesByTemplateSlug=Object(k.mapValues)(Object(k.keyBy)(e.templates,"slug"),"title")),n}return T()(t,e),v()(t,[{key:"componentDidMount",value:function(){var e,t,n=this;this.state.isOpen&&(e=this.props.segment.id,t=this.props.vertical.id,V&&window._tkq.push(["recordEvent","a8c_full_site_editing_template_selector_view",{blog_id:V.blogid,segment_id:e,vertical_id:t}]));var r=Object(k.reduce)(this.props.templates,(function(e,t){var r=t.slug,i=t.content;return e[r]=i?Object(I.parse)(W(i,n.props.siteInformation)):[],e}),{});this.setState({blocksByTemplateSlug:r})}},{key:"getBlocksByTemplateSlug",value:function(e){return Object(k.get)(this.state.blocksByTemplateSlug,[e],[])}},{key:"getTitleByTemplateSlug",value:function(e){return Object(k.get)(this.state.titlesByTemplateSlug,[e],"")}},{key:"render",value:function(){var e=this.state,t=e.previewedTemplate,n=e.isOpen,a=e.isLoading,o=this.props.isPromptedFromSidebar;if(!n)return null;var l=this.getTemplateGroups(),s=l.homepageTemplates,c=l.defaultTemplates;return Object(r.createElement)(C.Modal,{title:Object(i.__)("Select Page Layout","full-site-editing"),className:"page-template-modal",overlayClassName:"page-template-modal-screen-overlay",shouldCloseOnClickOutside:!1,isDismissable:!1,isDismissible:!1},o?Object(r.createElement)(C.IconButton,{className:"page-template-modal__close-button components-icon-button",onClick:this.props.toggleTemplateModal,icon:"no-alt",label:Object(i.__)("Close Layout Selector")}):Object(r.createElement)(C.IconButton,{className:"page-template-modal__close-button components-icon-button",onClick:this.closeModal,icon:"arrow-left-alt2",label:Object(i.__)("Go back")}),Object(r.createElement)("div",{className:"page-template-modal__inner"},a?Object(r.createElement)("div",{className:"page-template-modal__loading"},Object(r.createElement)(C.Spinner,null),Object(i.__)("Adding layout…","full-site-editing")):Object(r.createElement)(r.Fragment,null,Object(r.createElement)("form",{className:"page-template-modal__form"},this.props.isFrontPage?Object(r.createElement)(r.Fragment,null,this.renderTemplatesList(s,Object(i.__)("Recommended Layouts","full-site-editing")),this.renderTemplatesList(c,Object(i.__)("Other Page Layouts","full-site-editing"))):Object(r.createElement)(r.Fragment,null,this.renderTemplatesList(c,Object(i.__)("Recommended Layouts","full-site-editing")),this.renderTemplatesList(s,Object(i.__)("Homepage Layouts","full-site-editing")))),Object(r.createElement)(G,{blocks:this.getBlocksByTemplateSlug(t),viewportWidth:960,title:this.getTitleByTemplateSlug(t)}))),Object(r.createElement)("div",{className:N()("page-template-modal__buttons",{"is-visually-hidden":Object(k.isEmpty)(t)||a})},Object(r.createElement)(C.Button,{isPrimary:!0,isLarge:!0,disabled:Object(k.isEmpty)(t)||a,onClick:this.handleConfirmation},Object(i.sprintf)(Object(i.__)("Use %s layout","full-site-editing"),this.getTitleByTemplateSlug(t)))))}}]),t}(r.Component),ie=Object(B.compose)(Object(o.withSelect)((function(e){var t=function(){return e("core/editor").getEditedPostAttribute("meta")},n=t();return{getMeta:t,_starter_page_template:n._starter_page_template,postContentBlock:e("core/editor").getBlocks().find((function(e){return"a8c/post-content"===e.name}))}})),Object(o.withDispatch)((function(e,t){e("core/nux").disableTips();var n=e("core/editor");return{saveTemplateChoice:function(e){var r=t.getMeta();n.editPost({meta:c()({},r,{_starter_page_template:e})})},insertTemplate:function(r,i){r&&n.editPost({title:r});var a=t.postContentBlock;e("core/block-editor").replaceInnerBlocks(a?a.clientId:"",i,!1)}}})))(re),ae=function(e){function t(){var e,n;b()(this,t);for(var r=arguments.length,i=new Array(r),a=0;a<r;a++)i[a]=arguments[a];return n=y()(this,(e=j()(t)).call.apply(e,[this].concat(i))),S()(w()(n),"state",{isTemplateModalOpen:!1,isWarningOpen:!1}),S()(w()(n),"toggleTemplateModal",(function(){n.setState({isTemplateModalOpen:!n.state.isTemplateModalOpen})})),S()(w()(n),"toggleWarningModal",(function(){n.setState({isWarningOpen:!n.state.isWarningOpen})})),S()(w()(n),"getLastTemplateUsed",(function(){var e=n.props,t=e.isFrontPage,r=e.templates,i=e.theme,a=n.props.lastTemplateUsedSlug;if(!a&&t&&(a=i),!a||"blank"===a)return r[0];var o=r.find((function(e){return e.slug===a}));return o||r[0]})),n}return T()(t,e),v()(t,[{key:"render",value:function(){var e=this.getLastTemplateUsed(),t=e.slug,n=e.title,a=e.preview,o=e.previewAlt,l=this.props,s=l.isFrontPage,c=l.templates,u=l.theme,p=l.vertical,m=l.segment,d=l.siteInformation;return Object(r.createElement)("div",{className:"sidebar-modal-opener"},Object(r.createElement)(L,{id:"sidebar-modal-opener__last-template-used-preview",value:t,label:W(n,d),staticPreviewImg:a,staticPreviewImgAlt:o,onSelect:this.toggleWarningModal}),Object(r.createElement)(C.Button,{isPrimary:!0,onClick:this.toggleWarningModal,className:"sidebar-modal-opener__button"},Object(i.__)("Change Layout")),this.state.isTemplateModalOpen&&Object(r.createElement)(ie,{shouldPrefetchAssets:!1,templates:c,theme:u,vertical:p,segment:m,toggleTemplateModal:this.toggleTemplateModal,isFrontPage:s,isPromptedFromSidebar:!0}),this.state.isWarningOpen&&Object(r.createElement)(C.Modal,{title:Object(i.__)("Overwrite Page Content?"),isDismissible:!1,onRequestClose:this.toggleWarningModal,className:"sidebar-modal-opener__warning-modal"},Object(r.createElement)("div",{className:"sidebar-modal-opener__warning-text"},Object(i.__)("Changing the page's layout will remove any customizations or edits you have already made.")),Object(r.createElement)("div",{className:"sidebar-modal-opener__warning-options"},Object(r.createElement)(C.Button,{isDefault:!0,onClick:this.toggleWarningModal},Object(i.__)("Cancel")),Object(r.createElement)(C.Button,{isPrimary:!0,onClick:this.toggleTemplateModal},Object(i.__)("Change Layout")))))}}]),t}(r.Component),oe=Object(B.compose)(Object(o.withSelect)((function(e){return{lastTemplateUsedSlug:e("core/editor").getEditedPostAttribute("meta")._starter_page_template}})))(ae),le=window.starterPageTemplatesConfig,se=le.templates,ce=void 0===se?[]:se,ue=le.vertical,pe=le.segment,me=le.tracksUserData,de=le.siteInformation,fe=void 0===de?{}:de,be=le.screenAction,ge=le.theme,ve=le.isFrontPage;me&&(V=z=me,window._tkq.push(["identifyUser",z.userid,z.username])),"add"===be&&Object(a.registerPlugin)("page-templates",{render:function(){return Object(r.createElement)(ie,{isFrontPage:ve,segment:pe,shouldPrefetchAssets:!1,templates:ce,theme:ge,vertical:ue})}}),Object(a.registerPlugin)("page-templates-sidebar",{render:function(){return Object(r.createElement)(l.PluginDocumentSettingPanel,{name:"Template Modal Opener",title:Object(i.__)("Page Layout"),className:"page-template-modal__sidebar",icon:"admin-page"},Object(r.createElement)(oe,{isFrontPage:ve,segment:pe,siteInformation:fe,templates:ce,theme:ge,vertical:ue}))}});var Oe=Object(o.subscribe)((function(){Object(o.select)("core/edit-post").isEditorPanelOpened("page-templates-sidebar/Template Modal Opener")||Object(o.dispatch)("core/edit-post").toggleEditorPanelOpened("page-templates-sidebar/Template Modal Opener"),Oe()}))}]));
1
  /*! For license information please see starter-page-templates.js.LICENSE */
2
+ !function(e,t){for(var n in t)e[n]=t[n]}(window,function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=33)}([function(e,t){!function(){e.exports=this.wp.element}()},function(e,t){!function(){e.exports=this.lodash}()},function(e,t){!function(){e.exports=this.wp.i18n}()},function(e,t){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},function(e,t){!function(){e.exports=this.wp.components}()},function(e,t){e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}},function(e,t){!function(){e.exports=this.wp.data}()},function(e,t,n){var r;!function(){"use strict";var n={}.hasOwnProperty;function i(){for(var e=[],t=0;t<arguments.length;t++){var r=arguments[t];if(r){var a=typeof r;if("string"===a||"number"===a)e.push(r);else if(Array.isArray(r)&&r.length){var o=i.apply(null,r);o&&e.push(o)}else if("object"===a)for(var l in r)n.call(r,l)&&r[l]&&e.push(l)}}return e.join(" ")}e.exports?(i.default=i,e.exports=i):void 0===(r=function(){return i}.apply(t,[]))||(e.exports=r)}()},function(e,t){!function(){e.exports=this.wp.compose}()},function(e,t,n){var r=n(3);function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}e.exports=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}},function(e,t,n){var r=n(23),i=n(24),a=n(25);e.exports=function(e){return r(e)||i(e)||a()}},function(e,t,n){var r=n(26),i=n(27),a=n(28);e.exports=function(e,t){return r(e)||i(e,t)||a()}},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},function(e,t){function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}e.exports=function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}},function(e,t,n){var r=n(29),i=n(5);e.exports=function(e,t){return!t||"object"!==r(t)&&"function"!=typeof t?i(e):t}},function(e,t){function n(t){return e.exports=n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},n(t)}e.exports=n},function(e,t,n){var r=n(30);e.exports=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&r(e,t)}},function(e,t){!function(){e.exports=this.wp.blockEditor}()},function(e,t){!function(){e.exports=this.wp.plugins}()},function(e,t){!function(){e.exports=this.wp.editPost}()},function(e,t){!function(){e.exports=this.wp.blocks}()},function(e,t){!function(){e.exports=this.wp.apiFetch}()},function(e,t){!function(){e.exports=this.wp.url}()},function(e,t){e.exports=function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}},function(e,t){e.exports=function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}},function(e,t){e.exports=function(e){if(Array.isArray(e))return e}},function(e,t){e.exports=function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],r=!0,i=!1,a=void 0;try{for(var o,l=e[Symbol.iterator]();!(r=(o=l.next()).done)&&(n.push(o.value),!t||n.length!==t);r=!0);}catch(s){i=!0,a=s}finally{try{r||null==l.return||l.return()}finally{if(i)throw a}}return n}}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}},function(e,t){function n(t){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?e.exports=n=function(e){return typeof e}:e.exports=n=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(t)}e.exports=n},function(e,t){function n(t,r){return e.exports=n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},n(t,r)}e.exports=n},function(e,t){!function(){e.exports=this.wp.nux}()},function(e,t,n){},function(e,t,n){"use strict";n.r(t);var r=n(0),i=n(2),a=n(18),o=n(6),l=n(19),s=n(9),c=n.n(s),p=n(10),u=n.n(p),m=n(11),d=n.n(m),f=n(12),b=n.n(f),g=n(13),v=n.n(g),O=n(14),h=n.n(O),y=n(15),j=n.n(y),_=n(5),w=n.n(_),E=n(16),T=n.n(E),P=n(3),k=n.n(P),S=n(1),x=n(7),N=n.n(x),B=(n(31),n(8)),C=n(4),I=n(20),A=(n(32),n(17)),M=function(e){var t=e.blocks,n=void 0===t?[]:t,i=e.viewportWidth;return n&&n.length?Object(r.createElement)("div",{className:"edit-post-visual-editor"},Object(r.createElement)("div",{className:"editor-styles-wrapper"},Object(r.createElement)("div",{className:"editor-writing-flow"},Object(r.createElement)(A.BlockPreview,{blocks:n,viewportWidth:i})))):null},L=function(e){var t=e.id,n=e.value,i=e.onSelect,a=e.label,o=e.useDynamicPreview,l=void 0!==o&&o,s=e.staticPreviewImg,c=e.staticPreviewImgAlt,p=void 0===c?"":c,u=e.blocks,m=void 0===u?[]:u,d=e.isSelected,f=e.handleTemplateConfirmation;if(Object(S.isNil)(t)||Object(S.isNil)(a)||Object(S.isNil)(n))return null;if(l&&(Object(S.isNil)(m)||Object(S.isEmpty)(m)))return null;var b=l?Object(r.createElement)(C.Disabled,null,Object(r.createElement)(M,{blocks:m,viewportWidth:960})):Object(r.createElement)("img",{className:"template-selector-item__media",src:s,alt:p}),g="label-".concat(t,"-").concat(n);return Object(r.createElement)("button",{type:"button",className:N()("template-selector-item__label",{"is-selected":d}),value:n,onClick:function(){var e=window.matchMedia("(min-width: 660px)").matches;i(n),e||f(n)},"aria-labelledby":"".concat(t," ").concat(g)},Object(r.createElement)("div",{className:"template-selector-item__preview-wrap"},b),Object(r.createElement)("span",{className:"template-selector-item__template-title",id:g},a))},D={Address:Object(i._x)("123 Main St","default address","full-site-editing"),Phone:Object(i._x)("555-555-5555","default phone number","full-site-editing"),CompanyName:Object(i._x)("Your Company Name","default company name","full-site-editing"),Vertical:Object(i._x)("Business","default vertical name","full-site-editing")},F={CompanyName:"title",Address:"address",Phone:"phone",Vertical:"vertical"},W=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e?e.replace(/{{(\w+)}}/g,(function(e,n){var r=D[n];return t[F[n]]||r||n})):""},U=Object(B.compose)(r.memo,B.withInstanceId)((function(e){var t=e.label,n=e.className,i=e.help,a=e.instanceId,o=e.templates,l=void 0===o?[]:o,s=e.blocksByTemplates,c=void 0===s?{}:s,p=e.useDynamicPreview,u=void 0!==p&&p,m=e.onTemplateSelect,d=void 0===m?S.noop:m,f=e.siteInformation,b=void 0===f?{}:f,g=e.selectedTemplate,v=e.handleTemplateConfirmation,O=void 0===v?S.noop:v;if(Object(S.isEmpty)(l)||!Object(S.isArray)(l))return null;if(!0===u&&Object(S.isEmpty)(c))return null;var h="template-selector-control-".concat(a);return Object(r.createElement)(C.BaseControl,{label:t,id:h,help:i,className:N()(n,"template-selector-control")},Object(r.createElement)("ul",{className:"template-selector-control__options","data-testid":"template-selector-control-options"},Object(S.map)(l,(function(e){var t=e.slug,n=e.title,a=e.preview,o=e.previewAlt;return Object(r.createElement)("li",{key:"".concat(h,"-").concat(t),className:"template-selector-control__template"},Object(r.createElement)(L,{id:h,value:t,label:W(n,b),help:i,onSelect:d,staticPreviewImg:a,staticPreviewImgAlt:o,blocks:c.hasOwnProperty(t)?c[t]:[],useDynamicPreview:u,isSelected:t===g,handleTemplateConfirmation:O}))}))))})),q=function(e){var t=e.title,n=e.transform;return(Object(r.createElement)("div",{className:"editor-post-title",style:{transform:n}},Object(r.createElement)("div",{className:"wp-block editor-post-title__block"},Object(r.createElement)("textarea",{className:"editor-post-title__input",value:t,onChange:function(){}}))))},R=function(e){return Object(r.createElement)(A.BlockPreview,e)},z=function(e){var t=e.blocks,n=e.viewportWidth,a=e.title,o=Object(r.useState)("hidden"),l=d()(o,2),s=l[0],c=l[1],p=Object(r.useRef)(null),u=Object(r.useReducer)((function(e){return e+1}),0),m=d()(u,2),f=m[0],b=m[1],g=function(){setTimeout((function(){if(p&&p.current){var e=p.current.querySelector(".block-editor-block-preview__content");if(e){var t=window.getComputedStyle(e);if(t&&t.transform){var n=p.current.querySelector(".editor-post-title");n&&(n.style.transform=t.transform);var r=t.transform.replace(/matrix\((.+)\)$/i,"$1").split(",");r=r&&r.length?Number(r[0]):null,r=isNaN(r)?null:r;var i=e.closest(".template-selector-preview__offset-correction");if(i&&r){var a=n?n.offsetHeight:null;i.style.top="".concat(a*r,"px")}}c("visible")}}}),300)};return Object(r.useLayoutEffect)((function(){c("hidden"),g()}),[t]),Object(r.useEffect)((function(){if(t&&t.length){var e=Object(S.debounce)((function(){g(),b()}),300);return window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}}}),[t]),Object(S.isEmpty)(t)||!Object(S.isArray)(t)?Object(r.createElement)("div",{className:N()("template-selector-preview","is-blank-preview")},Object(r.createElement)("div",{className:"template-selector-preview__placeholder"},Object(i.__)("Select a layout to preview.","full-site-editing"))):Object(r.createElement)("div",{className:"template-selector-preview"},Object(r.createElement)(C.Disabled,null,Object(r.createElement)("div",{ref:p,className:"edit-post-visual-editor"},Object(r.createElement)("div",{className:"editor-styles-wrapper",style:{visibility:s}},Object(r.createElement)("div",{className:"editor-writing-flow"},Object(r.createElement)(q,{title:a}),Object(r.createElement)("div",{className:"template-selector-preview__offset-correction"},Object(r.createElement)(R,{key:f,blocks:t,viewportWidth:n})))))))};window._tkq=window._tkq||[];var G=null,V=function(e,t){G&&window._tkq.push(["recordEvent","a8c_full_site_editing_template_selector_view",{blog_id:G.blogid,segment_id:e,vertical_id:t}])},H=function(e,t){G&&window._tkq.push(["recordEvent","a8c_full_site_editing_template_selector_dismiss",{blog_id:G.blogid,segment_id:e,vertical_id:t}])},$=function(e,t,n){G&&window._tkq.push(["recordEvent","a8c_full_site_editing_template_selector_template_selected",{blog_id:G.blogid,segment_id:e,vertical_id:t,template:n}])},Q=n(21),Y=n.n(Q),J=n(22),K=function(e,t,n){var r=e[t=Object(J.removeQueryArgs)(t,"w","s")]||{url:t,usages:[]};return c()({},e,k()({},t,c()({},r,{usages:[].concat(u()(r.usages),u()(n))})))},X=function e(t,n){switch(t.blocksByClientId[n.clientId]=n,n.name){case"core/cover":case"core/image":var r=n.attributes.url;r&&(t.assets=K(t.assets,r,[{prop:"url",path:[n.clientId,"attributes","url"]},{prop:"id",path:[n.clientId,"attributes","id"]}]));case"core/media-text":var i=n.attributes.mediaUrl;i&&"image"===n.attributes.mediaType&&(t.assets=K(t.assets,i,[{prop:"url",path:[n.clientId,"attributes","mediaUrl"]},{prop:"id",path:[n.clientId,"attributes","mediaId"]}]));case"core/gallery":Object(S.forEach)(n.attributes.images,(function(e,r){t.assets=K(t.assets,e.url,[{prop:"url",path:[n.clientId,"attributes","images",r,"url"]},{prop:"url",path:[n.clientId,"attributes","images",r,"link"]},{prop:"id",path:[n.clientId,"attributes","images",r,"id"]},{prop:"id",path:[n.clientId,"attributes","ids",r]}])}))}return Object(S.isEmpty)(n.innerBlocks)?t:Object(S.reduce)(n.innerBlocks,e,t)},Z=function(e){return regeneratorRuntime.async((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,regeneratorRuntime.awrap(Y()({method:"POST",path:"/fse/v1/sideload/image/batch",data:{resources:Object(S.map)(e)}}).then((function(t){return Object(S.reduce)(e,(function(e,n){var r=t.shift(),i=r.id,a=r.source_url;return c()({},e,k()({},n.url,{id:i,url:a}))}),{})})));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}))},ee=function(e,t){return Object(S.forEach)(e.assets,(function(n){var r=t[n.url];r&&Object(S.forEach)(n.usages,(function(t){Object(S.set)(e.blocksByClientId,t.path,r[t.prop])}))})),e.blocks},te=function(e){var t;return regeneratorRuntime.async((function(n){for(;;)switch(n.prev=n.next){case 0:if(t=Object(S.reduce)(e,X,{assets:{},blocksByClientId:{},blocks:e}),!Object(S.isEmpty)(t.assets)){n.next=3;break}return n.abrupt("return",e);case 3:return n.abrupt("return",Z(t.assets).then((function(e){return ee(t,e)})));case 4:case"end":return n.stop()}}))},ne="maywood",re=function(e){function t(){var e,n;b()(this,t);for(var a=arguments.length,o=new Array(a),l=0;l<a;l++)o[l]=arguments[l];return n=h()(this,(e=j()(t)).call.apply(e,[this].concat(o))),k()(w()(n),"state",{isLoading:!1,previewedTemplate:null,error:null,isOpen:!1}),k()(w()(n),"getTitlesByTemplateSlugs",Object(S.memoize)((function(e){return Object(S.mapValues)(Object(S.keyBy)(e,"slug"),"title")}))),k()(w()(n),"getBlocksByTemplateSlugs",Object(S.memoize)((function(e){return Object(S.reduce)(e,(function(e,t){var r=t.slug,i=t.content;return e[r]=i?Object(I.parse)(W(i,n.props.siteInformation)):[],e}),{})}))),k()(w()(n),"setTemplate",(function(e){$(n.props.segment.id,n.props.vertical.id,e),n.props.saveTemplateChoice(e);var t=Object(S.find)(n.props.templates,{slug:e,category:"home"}),r=n.getBlocksByTemplateSlug(e),i=t?null:n.getTitleByTemplateSlug(e);r&&r.length?(n.setState({error:null,isLoading:!0}),n.maybePrefetchAssets(r).then((function(e){n.state.isOpen&&(n.props.insertTemplate(i,e),n.setState({isOpen:!1}))})).catch((function(e){n.setState({isLoading:!1,error:e})}))):n.setState({isOpen:!1})})),k()(w()(n),"maybePrefetchAssets",(function(e){return n.props.shouldPrefetchAssets?te(e):Promise.resolve(e)})),k()(w()(n),"handleConfirmation",(function(e){"string"!=typeof e&&(e=n.state.previewedTemplate),n.setTemplate(e),n.props.isPromptedFromSidebar&&n.props.toggleTemplateModal()})),k()(w()(n),"previewTemplate",(function(e){return n.setState({previewedTemplate:e})})),k()(w()(n),"closeModal",(function(e){if(e.target.matches("button.template-selector-item__label"))return!1;H(n.props.segment.id,n.props.vertical.id);var t=Object(S.get)(window,["calypsoifyGutenberg","closeUrl"]);window.top.location=t||"edit.php?post_type=page"})),k()(w()(n),"getTemplateGroups",(function(){var e=Object(S.partition)(n.props.templates,{category:"home"}),t=d()(e,2),r=t[0],i=t[1],a=Object(S.find)(n.props.templates,{slug:n.props.theme})||Object(S.find)(n.props.templates,{slug:ne});if(!n.props.isFrontPage||!a)return{homepageTemplates:Object(S.sortBy)(r,"title"),defaultTemplates:i};var o=Object(S.reject)(r,{slug:a.slug});return{homepageTemplates:[a].concat(u()(Object(S.sortBy)(o,"title"))),defaultTemplates:i}})),k()(w()(n),"renderTemplatesList",(function(e,t){return Object(r.createElement)("fieldset",{className:"page-template-modal__list"},Object(r.createElement)("legend",{className:"page-template-modal__form-title"},t),Object(r.createElement)(U,{label:Object(i.__)("Layout","full-site-editing"),templates:e,blocksByTemplates:n.getBlocksByTemplateSlugs(n.props.templates),onTemplateSelect:n.previewTemplate,useDynamicPreview:!1,siteInformation:n.props.siteInformation,selectedTemplate:n.state.previewedTemplate,handleTemplateConfirmation:n.handleConfirmation}))})),n}return T()(t,e),v()(t,[{key:"componentDidMount",value:function(){this.state.isOpen&&V(this.props.segment.id,this.props.vertical.id)}},{key:"componentDidUpdate",value:function(e,t){!t.isOpen&&this.state.isOpen&&V(this.props.segment.id,this.props.vertical.id)}},{key:"getBlocksByTemplateSlug",value:function(e){return Object(S.get)(this.getBlocksByTemplateSlugs(this.props.templates),[e],[])}},{key:"getTitleByTemplateSlug",value:function(e){return Object(S.get)(this.getTitlesByTemplateSlugs(this.props.templates),[e],"")}},{key:"render",value:function(){var e=this.state,t=e.previewedTemplate,n=e.isOpen,a=e.isLoading,o=this.props.isPromptedFromSidebar;if(!n)return null;var l=this.getTemplateGroups(),s=l.homepageTemplates,c=l.defaultTemplates;return Object(r.createElement)(C.Modal,{title:Object(i.__)("Select Page Layout","full-site-editing"),className:"page-template-modal",overlayClassName:"page-template-modal-screen-overlay",shouldCloseOnClickOutside:!1,isDismissable:!1,isDismissible:!1},o?Object(r.createElement)(C.IconButton,{className:"page-template-modal__close-button components-icon-button",onClick:this.props.toggleTemplateModal,icon:"no-alt",label:Object(i.__)("Close Layout Selector")}):Object(r.createElement)(C.IconButton,{className:"page-template-modal__close-button components-icon-button",onClick:this.closeModal,icon:"arrow-left-alt2",label:Object(i.__)("Go back")}),Object(r.createElement)("div",{className:"page-template-modal__inner"},a?Object(r.createElement)("div",{className:"page-template-modal__loading"},Object(r.createElement)(C.Spinner,null),Object(i.__)("Adding layout…","full-site-editing")):Object(r.createElement)(r.Fragment,null,Object(r.createElement)("form",{className:"page-template-modal__form"},this.props.isFrontPage?Object(r.createElement)(r.Fragment,null,this.renderTemplatesList(s,Object(i.__)("Recommended Layouts","full-site-editing")),this.renderTemplatesList(c,Object(i.__)("Other Page Layouts","full-site-editing"))):Object(r.createElement)(r.Fragment,null,this.renderTemplatesList(c,Object(i.__)("Recommended Layouts","full-site-editing")),this.renderTemplatesList(s,Object(i.__)("Homepage Layouts","full-site-editing")))),Object(r.createElement)(z,{blocks:this.getBlocksByTemplateSlug(t),viewportWidth:960,title:this.getTitleByTemplateSlug(t)}))),Object(r.createElement)("div",{className:N()("page-template-modal__buttons",{"is-visually-hidden":Object(S.isEmpty)(t)||a})},Object(r.createElement)(C.Button,{isPrimary:!0,isLarge:!0,disabled:Object(S.isEmpty)(t)||a,onClick:this.handleConfirmation},Object(i.sprintf)(Object(i.__)("Use %s layout","full-site-editing"),this.getTitleByTemplateSlug(t)))))}}],[{key:"getDerivedStateFromProps",value:function(e,n){return n.previewedTemplate||Object(S.isEmpty)(e.templates)?null:{isOpen:!0,previewedTemplate:t.getDefaultSelectedTemplate(e)}}}]),t}(r.Component);k()(re,"getDefaultSelectedTemplate",(function(e){var t=Object(S.get)(e.templates,[0,"slug"]),n=e._starter_page_template;if(!e.isFrontPage&&!n)return t;"home"===n&&(n=e.theme);var r=n||e.theme;return Object(S.find)(e.templates,{slug:r})?r:Object(S.find)(e.templates,{slug:ne})?ne:t}));var ie,ae=Object(B.compose)(Object(o.withSelect)((function(e){var t=function(){return e("core/editor").getEditedPostAttribute("meta")},n=t();return{getMeta:t,_starter_page_template:n._starter_page_template,postContentBlock:e("core/editor").getBlocks().find((function(e){return"a8c/post-content"===e.name}))}})),Object(o.withDispatch)((function(e,t){e("core/nux").disableTips();var n=e("core/editor");return{saveTemplateChoice:function(e){var r=t.getMeta();n.editPost({meta:c()({},r,{_starter_page_template:e})})},insertTemplate:function(r,i){r&&n.editPost({title:r});var a=t.postContentBlock;e("core/block-editor").replaceInnerBlocks(a?a.clientId:"",i,!1)}}})))(re),oe=function(e){function t(){var e,n;b()(this,t);for(var r=arguments.length,i=new Array(r),a=0;a<r;a++)i[a]=arguments[a];return n=h()(this,(e=j()(t)).call.apply(e,[this].concat(i))),k()(w()(n),"state",{isTemplateModalOpen:!1,isWarningOpen:!1}),k()(w()(n),"toggleTemplateModal",(function(){n.setState({isTemplateModalOpen:!n.state.isTemplateModalOpen})})),k()(w()(n),"toggleWarningModal",(function(){n.setState({isWarningOpen:!n.state.isWarningOpen})})),k()(w()(n),"getLastTemplateUsed",(function(){var e=n.props,t=e.isFrontPage,r=e.templates,i=e.theme,a=n.props.lastTemplateUsedSlug;if(!a&&t&&(a=i),!a||"blank"===a)return r[0];var o=r.find((function(e){return e.slug===a}));return o||r[0]})),n}return T()(t,e),v()(t,[{key:"render",value:function(){var e=this.getLastTemplateUsed(),t=e.slug,n=e.title,a=e.preview,o=e.previewAlt,l=this.props,s=l.isFrontPage,c=l.templates,p=l.theme,u=l.vertical,m=l.segment,d=l.siteInformation;return Object(r.createElement)("div",{className:"sidebar-modal-opener"},Object(r.createElement)(L,{id:"sidebar-modal-opener__last-template-used-preview",value:t,label:W(n,d),staticPreviewImg:a,staticPreviewImgAlt:o,onSelect:this.toggleWarningModal}),Object(r.createElement)(C.Button,{isPrimary:!0,onClick:this.toggleWarningModal,className:"sidebar-modal-opener__button"},Object(i.__)("Change Layout")),this.state.isTemplateModalOpen&&Object(r.createElement)(ae,{shouldPrefetchAssets:!1,templates:c,theme:p,vertical:u,segment:m,toggleTemplateModal:this.toggleTemplateModal,isFrontPage:s,isPromptedFromSidebar:!0}),this.state.isWarningOpen&&Object(r.createElement)(C.Modal,{title:Object(i.__)("Overwrite Page Content?"),isDismissible:!1,onRequestClose:this.toggleWarningModal,className:"sidebar-modal-opener__warning-modal"},Object(r.createElement)("div",{className:"sidebar-modal-opener__warning-text"},Object(i.__)("Changing the page's layout will remove any customizations or edits you have already made.")),Object(r.createElement)("div",{className:"sidebar-modal-opener__warning-options"},Object(r.createElement)(C.Button,{isDefault:!0,onClick:this.toggleWarningModal},Object(i.__)("Cancel")),Object(r.createElement)(C.Button,{isPrimary:!0,onClick:this.toggleTemplateModal},Object(i.__)("Change Layout")))))}}]),t}(r.Component),le=Object(B.compose)(Object(o.withSelect)((function(e){return{lastTemplateUsedSlug:e("core/editor").getEditedPostAttribute("meta")._starter_page_template}})))(oe),se=window.starterPageTemplatesConfig,ce=se.templates,pe=void 0===ce?[]:ce,ue=se.vertical,me=se.segment,de=se.tracksUserData,fe=se.siteInformation,be=void 0===fe?{}:fe,ge=se.screenAction,ve=se.theme,Oe=se.isFrontPage;de&&(G=ie=de,window._tkq.push(["identifyUser",ie.userid,ie.username])),"add"===ge&&Object(a.registerPlugin)("page-templates",{render:function(){return Object(r.createElement)(ae,{isFrontPage:Oe,segment:me,shouldPrefetchAssets:!1,templates:pe,theme:ve,vertical:ue})}}),Object(a.registerPlugin)("page-templates-sidebar",{render:function(){return Object(r.createElement)(l.PluginDocumentSettingPanel,{name:"Template Modal Opener",title:Object(i.__)("Page Layout"),className:"page-template-modal__sidebar",icon:"admin-page"},Object(r.createElement)(le,{isFrontPage:Oe,segment:me,siteInformation:be,templates:pe,theme:ve,vertical:ue}))}});var he=Object(o.subscribe)((function(){Object(o.select)("core/edit-post").isEditorPanelOpened("page-templates-sidebar/Template Modal Opener")||Object(o.dispatch)("core/edit-post").toggleEditorPanelOpened("page-templates-sidebar/Template Modal Opener"),he()}))}]));
starter-page-templates/page-template-modal/index.js CHANGED
@@ -2,7 +2,18 @@
2
  /**
3
  * External dependencies
4
  */
5
- import { find, isEmpty, reduce, get, keyBy, mapValues, partition, reject, sortBy } from 'lodash';
 
 
 
 
 
 
 
 
 
 
 
6
  import classnames from 'classnames';
7
  import '@wordpress/nux';
8
  import { __, sprintf } from '@wordpress/i18n';
@@ -29,32 +40,19 @@ class PageTemplateModal extends Component {
29
  state = {
30
  isLoading: false,
31
  previewedTemplate: null,
32
- blocksByTemplateSlug: {},
33
- titlesByTemplateSlug: {},
34
  error: null,
35
  isOpen: false,
36
  };
37
 
38
- constructor( props ) {
39
- super();
40
- const hasTemplates = ! isEmpty( props.templates );
41
- this.state.isOpen = hasTemplates;
42
- if ( hasTemplates ) {
43
- // Select the first template automatically.
44
- this.state.previewedTemplate = this.getDefaultSelectedTemplate( props );
45
- // Extract titles for faster lookup.
46
- this.state.titlesByTemplateSlug = mapValues( keyBy( props.templates, 'slug' ), 'title' );
47
- }
48
- }
49
-
50
- componentDidMount() {
51
- if ( this.state.isOpen ) {
52
- trackView( this.props.segment.id, this.props.vertical.id );
53
- }
54
 
55
- // Parse templates blocks and store them into the state.
56
- const blocksByTemplateSlug = reduce(
57
- this.props.templates,
 
58
  ( prev, { slug, content } ) => {
59
  prev[ slug ] = content
60
  ? parseBlocks( replacePlaceholders( content, this.props.siteInformation ) )
@@ -62,13 +60,42 @@ class PageTemplateModal extends Component {
62
  return prev;
63
  },
64
  {}
65
- );
 
66
 
67
- // eslint-disable-next-line react/no-did-mount-set-state
68
- this.setState( { blocksByTemplateSlug } );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
70
 
71
- getDefaultSelectedTemplate = props => {
72
  const blankTemplate = get( props.templates, [ 0, 'slug' ] );
73
  let previouslyChosenTemplate = props._starter_page_template;
74
 
@@ -170,11 +197,11 @@ class PageTemplateModal extends Component {
170
  };
171
 
172
  getBlocksByTemplateSlug( slug ) {
173
- return get( this.state.blocksByTemplateSlug, [ slug ], [] );
174
  }
175
 
176
  getTitleByTemplateSlug( slug ) {
177
- return get( this.state.titlesByTemplateSlug, [ slug ], '' );
178
  }
179
 
180
  getTemplateGroups = () => {
@@ -206,7 +233,7 @@ class PageTemplateModal extends Component {
206
  <TemplateSelectorControl
207
  label={ __( 'Layout', 'full-site-editing' ) }
208
  templates={ templatesList }
209
- blocksByTemplates={ this.state.blocksByTemplateSlug }
210
  onTemplateSelect={ this.previewTemplate }
211
  useDynamicPreview={ false }
212
  siteInformation={ this.props.siteInformation }
2
  /**
3
  * External dependencies
4
  */
5
+ import {
6
+ find,
7
+ isEmpty,
8
+ reduce,
9
+ get,
10
+ keyBy,
11
+ mapValues,
12
+ memoize,
13
+ partition,
14
+ reject,
15
+ sortBy,
16
+ } from 'lodash';
17
  import classnames from 'classnames';
18
  import '@wordpress/nux';
19
  import { __, sprintf } from '@wordpress/i18n';
40
  state = {
41
  isLoading: false,
42
  previewedTemplate: null,
 
 
43
  error: null,
44
  isOpen: false,
45
  };
46
 
47
+ // Extract titles for faster lookup.
48
+ getTitlesByTemplateSlugs = memoize( templates =>
49
+ mapValues( keyBy( templates, 'slug' ), 'title' )
50
+ );
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
+ // Parse templates blocks and memoize them.
53
+ getBlocksByTemplateSlugs = memoize( templates =>
54
+ reduce(
55
+ templates,
56
  ( prev, { slug, content } ) => {
57
  prev[ slug ] = content
58
  ? parseBlocks( replacePlaceholders( content, this.props.siteInformation ) )
60
  return prev;
61
  },
62
  {}
63
+ )
64
+ );
65
 
66
+ static getDerivedStateFromProps( props, state ) {
67
+ // The only time `state.previewedTemplate` isn't set is before `templates`
68
+ // are loaded. As soon as we have our `templates`, we set it using
69
+ // `this.getDefaultSelectedTemplate`. Afterwards, the user can select a
70
+ // different template, but can never un-select it.
71
+ // This makes it a reliable indicator for whether the modal has just been launched.
72
+ // It's also possible that `templates` are present during initial mount, in which
73
+ // case this will be called before `componentDidMount`, which is also fine.
74
+ if ( ! state.previewedTemplate && ! isEmpty( props.templates ) ) {
75
+ // Show the modal, and select the first template automatically.
76
+ return {
77
+ isOpen: true,
78
+ previewedTemplate: PageTemplateModal.getDefaultSelectedTemplate( props ),
79
+ };
80
+ }
81
+ return null;
82
+ }
83
+
84
+ componentDidMount() {
85
+ if ( this.state.isOpen ) {
86
+ trackView( this.props.segment.id, this.props.vertical.id );
87
+ }
88
+ }
89
+
90
+ componentDidUpdate( prevProps, prevState ) {
91
+ // Only track when the modal is first displayed
92
+ // and if it didn't already happen during componentDidMount.
93
+ if ( ! prevState.isOpen && this.state.isOpen ) {
94
+ trackView( this.props.segment.id, this.props.vertical.id );
95
+ }
96
  }
97
 
98
+ static getDefaultSelectedTemplate = props => {
99
  const blankTemplate = get( props.templates, [ 0, 'slug' ] );
100
  let previouslyChosenTemplate = props._starter_page_template;
101
 
197
  };
198
 
199
  getBlocksByTemplateSlug( slug ) {
200
+ return get( this.getBlocksByTemplateSlugs( this.props.templates ), [ slug ], [] );
201
  }
202
 
203
  getTitleByTemplateSlug( slug ) {
204
+ return get( this.getTitlesByTemplateSlugs( this.props.templates ), [ slug ], '' );
205
  }
206
 
207
  getTemplateGroups = () => {
233
  <TemplateSelectorControl
234
  label={ __( 'Layout', 'full-site-editing' ) }
235
  templates={ templatesList }
236
+ blocksByTemplates={ this.getBlocksByTemplateSlugs( this.props.templates ) }
237
  onTemplateSelect={ this.previewTemplate }
238
  useDynamicPreview={ false }
239
  siteInformation={ this.props.siteInformation }