From aa96afab872df1d291912b427dcc4e895932116e Mon Sep 17 00:00:00 2001 From: Roni Laukkarinen Date: Fri, 28 Feb 2025 14:25:29 +0200 Subject: [PATCH] Serve block server side instead of separate view.js, T-25856 --- blocks/latest-articles/build/block.json | 12 +++-- blocks/latest-articles/build/index-rtl.css | 2 +- blocks/latest-articles/build/index.asset.php | 2 +- blocks/latest-articles/build/index.css | 2 +- blocks/latest-articles/build/index.js | 2 +- blocks/latest-articles/build/render.php | 42 +++++++++-------- .../latest-articles/build/style-index-rtl.css | 2 +- blocks/latest-articles/build/style-index.css | 2 +- blocks/latest-articles/src/block.json | 12 +++-- blocks/latest-articles/src/edit.js | 46 ++----------------- blocks/latest-articles/src/editor.scss | 4 -- blocks/latest-articles/src/render.php | 42 +++++++++-------- blocks/latest-articles/src/style.scss | 44 ++++++------------ blocks/latest-articles/src/view.js | 2 +- gulp/tasks/blocks.js | 3 +- 15 files changed, 94 insertions(+), 125 deletions(-) diff --git a/blocks/latest-articles/build/block.json b/blocks/latest-articles/build/block.json index d1c13813..da883187 100644 --- a/blocks/latest-articles/build/block.json +++ b/blocks/latest-articles/build/block.json @@ -3,13 +3,13 @@ "apiVersion": 3, "name": "air-light/latest-articles", "version": "1.0.0", - "title": "Uusimmat ohjeet", + "title": "Latest articles", "category": "air-light", "icon": "grid-view", "description": "Show latest articles in a grid.", "example": {}, "supports": { - "html": false, + "html": true, "align": false }, "textdomain": "air-light", @@ -17,5 +17,11 @@ "editorStyle": "file:./index.css", "style": "file:./style-index.css", "render": "file:./render.php", - "viewScript": "file:./view.js" + "viewScript": "file:./view.js", + "attributes": { + "preview": { + "type": "boolean", + "default": false + } + } } \ No newline at end of file diff --git a/blocks/latest-articles/build/index-rtl.css b/blocks/latest-articles/build/index-rtl.css index 90ef3a94..8b137891 100644 --- a/blocks/latest-articles/build/index-rtl.css +++ b/blocks/latest-articles/build/index-rtl.css @@ -1 +1 @@ -.wp-block-create-block-latest-articles{border:1px dotted red} + diff --git a/blocks/latest-articles/build/index.asset.php b/blocks/latest-articles/build/index.asset.php index 2c39807f..fdc88f5d 100644 --- a/blocks/latest-articles/build/index.asset.php +++ b/blocks/latest-articles/build/index.asset.php @@ -1 +1 @@ - array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-i18n'), 'version' => '76cefaef40ac70803a1a'); + array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-i18n', 'wp-server-side-render'), 'version' => '6c4ddfadd3c18d2fb2e5'); diff --git a/blocks/latest-articles/build/index.css b/blocks/latest-articles/build/index.css index 90ef3a94..8b137891 100644 --- a/blocks/latest-articles/build/index.css +++ b/blocks/latest-articles/build/index.css @@ -1 +1 @@ -.wp-block-create-block-latest-articles{border:1px dotted red} + diff --git a/blocks/latest-articles/build/index.js b/blocks/latest-articles/build/index.js index 0c784056..ff45bbe5 100644 --- a/blocks/latest-articles/build/index.js +++ b/blocks/latest-articles/build/index.js @@ -1 +1 @@ -(()=>{"use strict";var e,r={580:()=>{const e=window.wp.blocks,r=window.wp.i18n,t=window.wp.blockEditor,i=window.wp.data,a=window.ReactJSXRuntime,s=JSON.parse('{"UU":"air-light/latest-articles"}');(0,e.registerBlockType)(s.UU,{edit:function(){const e=(0,i.useSelect)((e=>e("core").getEntityRecords("postType","post",{per_page:3,_embed:!0})),[]),s=(0,t.useBlockProps)();return e?0===e.length?(0,a.jsx)("p",{...s,children:(0,r.__)("No posts found.","air-light")}):(0,a.jsx)("div",{...s,children:(0,a.jsx)("div",{className:"latest-articles",children:e.map((e=>(0,a.jsxs)("article",{className:"latest-article",children:[(0,a.jsx)("h3",{children:(0,a.jsx)("a",{href:e.link,children:e.title.rendered})}),(0,a.jsx)("time",{dateTime:e.date,children:new Date(e.date).toLocaleDateString()}),(0,a.jsx)("div",{className:"excerpt",dangerouslySetInnerHTML:{__html:e.excerpt.rendered}})]},e.id)))})}):(0,a.jsx)("p",{...s,children:(0,r.__)("Loading...","air-light")})},save:()=>null})}},t={};function i(e){var a=t[e];if(void 0!==a)return a.exports;var s=t[e]={exports:{}};return r[e](s,s.exports,i),s.exports}i.m=r,e=[],i.O=(r,t,a,s)=>{if(!t){var l=1/0;for(d=0;d=s)&&Object.keys(i.O).every((e=>i.O[e](t[o])))?t.splice(o--,1):(n=!1,s0&&e[d-1][2]>s;d--)e[d]=e[d-1];e[d]=[t,a,s]},i.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),(()=>{var e={57:0,350:0};i.O.j=r=>0===e[r];var r=(r,t)=>{var a,s,[l,n,o]=t,c=0;if(l.some((r=>0!==e[r]))){for(a in n)i.o(n,a)&&(i.m[a]=n[a]);if(o)var d=o(i)}for(r&&r(t);ci(580)));a=i.O(a)})(); \ No newline at end of file +(()=>{"use strict";var e,r={262:(e,r,t)=>{const i=window.wp.blocks,o=(window.wp.i18n,window.wp.blockEditor),n=(window.wp.data,window.wp.serverSideRender);var a=t.n(n);const l=window.ReactJSXRuntime,s=JSON.parse('{"UU":"air-light/latest-articles"}');(0,i.registerBlockType)(s.UU,{edit:function(){const e=(0,o.useBlockProps)();return(0,l.jsx)("div",{...e,children:(0,l.jsx)(a(),{block:"air-light/latest-articles",attributes:{preview:!0}})})},save:()=>null})}},t={};function i(e){var o=t[e];if(void 0!==o)return o.exports;var n=t[e]={exports:{}};return r[e](n,n.exports,i),n.exports}i.m=r,e=[],i.O=(r,t,o,n)=>{if(!t){var a=1/0;for(d=0;d=n)&&Object.keys(i.O).every((e=>i.O[e](t[s])))?t.splice(s--,1):(l=!1,n0&&e[d-1][2]>n;d--)e[d]=e[d-1];e[d]=[t,o,n]},i.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return i.d(r,{a:r}),r},i.d=(e,r)=>{for(var t in r)i.o(r,t)&&!i.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},i.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),(()=>{var e={57:0,350:0};i.O.j=r=>0===e[r];var r=(r,t)=>{var o,n,[a,l,s]=t,c=0;if(a.some((r=>0!==e[r]))){for(o in l)i.o(l,o)&&(i.m[o]=l[o]);if(s)var d=s(i)}for(r&&r(t);ci(262)));o=i.O(o)})(); \ No newline at end of file diff --git a/blocks/latest-articles/build/render.php b/blocks/latest-articles/build/render.php index 65b1defb..2cd0c8e4 100644 --- a/blocks/latest-articles/build/render.php +++ b/blocks/latest-articles/build/render.php @@ -16,26 +16,32 @@ $latest_posts = new WP_Query( $args ); if ( $latest_posts->have_posts() ) : ?> -
'latest-articles'] ); // phpcs:ignore ?>> - have_posts() ) : - $latest_posts->the_post(); ?> -
-

- - - -

+
'latest-articles'] ); // phpcs:ignore ?>> +
+
+ have_posts() ) : + $latest_posts->the_post(); ?> +
+

+ + + +

- +

+ +

-
- -
-
- -
+
+ +
+
+ +
+ + { - return select('core').getEntityRecords('postType', 'post', { - per_page: 3, - _embed: true - }); - }, []); - const blockProps = useBlockProps(); - if (!posts) { - return ( -

- {__('Loading...', 'air-light')} -

- ); - } - - if (posts.length === 0) { - return ( -

- {__('No posts found.', 'air-light')} -

- ); - } - return (
-
- {posts.map((post) => ( - - ))} -
+
); } diff --git a/blocks/latest-articles/src/editor.scss b/blocks/latest-articles/src/editor.scss index 94be0141..84a459c7 100644 --- a/blocks/latest-articles/src/editor.scss +++ b/blocks/latest-articles/src/editor.scss @@ -3,7 +3,3 @@ * * Replace them with your own styles or remove the file completely. */ - - .wp-block-create-block-latest-articles { - border: 1px dotted #f00; -} diff --git a/blocks/latest-articles/src/render.php b/blocks/latest-articles/src/render.php index 65b1defb..2cd0c8e4 100644 --- a/blocks/latest-articles/src/render.php +++ b/blocks/latest-articles/src/render.php @@ -16,26 +16,32 @@ $latest_posts = new WP_Query( $args ); if ( $latest_posts->have_posts() ) : ?> -
'latest-articles'] ); // phpcs:ignore ?>> - have_posts() ) : - $latest_posts->the_post(); ?> -
-

- - - -

+
'latest-articles'] ); // phpcs:ignore ?>> +
+
+ have_posts() ) : + $latest_posts->the_post(); ?> +
+

+ + + +

- +

+ +

-
- -
-
- -
+
+ +
+
+ +
+ +