Skip to content

Commit a593090

Browse files
committed
update designs
1 parent 22b308c commit a593090

File tree

4 files changed

+139
-21
lines changed

4 files changed

+139
-21
lines changed

src/components/design-library-list/default.json

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -262,26 +262,43 @@
262262
"post-btn_placeholder": "Read more",
263263
"btn_placeholder": "View all",
264264
"tag_placeholder": "Editor's Picks",
265-
"title-1_placeholder": "Future of AI in Everyday Life",
266-
"text-1_placeholder": "Explore how AI is transforming daily routines and what's next.",
267-
"title-2_placeholder": "Sustainable Living",
268-
"text-2_placeholder": "Discover easy ways to adopt eco-friendly habits.",
269-
"title-3_placeholder": "Mastering Remote Work: Tips for Productivity",
270-
"text-3_placeholder": "Boost your efficiency with these essential remote work strategies.",
271-
"title-4_placeholder": "Rise of Wearable Technology",
272-
"text-4_placeholder": "Learn about the latest advancements in wearable devices.",
273-
"title-5_placeholder": "Cybersecurity Essentials",
274-
"text-5_placeholder": "Protect your digital life with these crucial security tips.",
275-
"title-6_placeholder": "Mindful Photography",
276-
"text-6_placeholder": "Enhance your photography skills through a mindful approach.",
277-
"title-7_placeholder": "Storytelling in Brand Building",
278-
"text-7_placeholder": "Learn how compelling narratives can elevate your brand."
265+
"posts_placeholder": [
266+
{
267+
"title_placeholder": "Future of AI in Everyday Life",
268+
"text_placeholder": "Explore how AI is transforming daily routines and what's next."
269+
},
270+
{
271+
"title_placeholder": "Sustainable Living",
272+
"text_placeholder": "Discover easy ways to adopt eco-friendly habits."
273+
},
274+
{
275+
"title_placeholder": "Mastering Remote Work: Tips for Productivity",
276+
"text_placeholder": "Boost your efficiency with these essential remote work strategies."
277+
},
278+
{
279+
"title_placeholder": "Rise of Wearable Technology",
280+
"text_placeholder": "Learn about the latest advancements in wearable devices."
281+
},
282+
{
283+
"title_placeholder": "Cybersecurity Essentials",
284+
"text_placeholder": "Protect your digital life with these crucial security tips."
285+
},
286+
{
287+
"title_placeholder": "Mindful Photography",
288+
"text_placeholder": "Enhance your photography skills through a mindful approach."
289+
},
290+
{
291+
"title_placeholder": "Storytelling in Brand Building",
292+
"text_placeholder": "Learn how compelling narratives can elevate your brand."
293+
}
294+
]
279295
},
280296
"Pricing Table": {
281297
"heading_placeholder": "Our Pricing Plans",
282298
"description_placeholder": "Choose the perfect plan to fit your needs, from individuals to large organizations. All plans include dedicated support and a commitment to your success.",
283299
"btn-1_placeholder": "Get Started",
284300
"btn-2_placeholder": "Buy Now",
301+
"tag_placeholder": "Best Value",
285302
"title-1_placeholder": "Flexible Scaling",
286303
"text-1_placeholder": "Easily upgrade or downgrade as your needs evolve.",
287304
"title-2_placeholder": "24/7 Customer Support",

src/components/design-library-list/design-library-list-item.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import ProControl from '../pro-control'
55
import DEFAULT from './default.json'
66
import {
7-
addBackgroundScheme, addContainerScheme, cleanParse, parseDisabledBlocks,
7+
addBackgroundScheme, addContainerScheme,
8+
addPlaceholderForPostsBlock, cleanParse,
9+
getAdditionalStylesForPreview,
10+
parseDisabledBlocks,
811
} from './util'
912

1013
/**
@@ -141,6 +144,9 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
141144
} else if ( category === 'Tabs' ) {
142145
// Add a class for the first tab to be the active tab in the preview
143146
preview = preview.replace( '"stk-block-tabs__tab"', '"stk-block-tabs__tab stk-block-tabs__tab--active"' )
147+
} else if ( category === 'Post Loop' ) {
148+
const defaultValues = DEFAULT_CONTENT[ category ]
149+
preview = addPlaceholderForPostsBlock( preview, defaultValues[ 'posts_placeholder' ], defaultValues )
144150
}
145151

146152
const cleanedBlock = preview.replace( /<!--[\s\S]*?-->/g, '' ) // removes comment
@@ -213,10 +219,7 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
213219
}
214220

215221
// Additional styles for blocks to render properly in the preview
216-
hostStyles.innerHTML += `.stk-block-count-up__text:not(.stk--count-up-active) { opacity: 1; }`
217-
hostStyles.innerHTML += `.stk-block-timeline { --line-bg-color: var(--line-accent-bg-color, #000); }`
218-
hostStyles.innerHTML += `.stk-progress-bar .stk-progress-bar__bar { width: var(--progress-percent, 0px); }`
219-
hostStyles.innerHTML += `.stk-progress-circle .stk-progress-circle__bar { stroke-dashoffset: var(--progress-dash-offset); }`
222+
hostStyles.innerHTML += getAdditionalStylesForPreview()
220223

221224
styleNodes.push( hostStyles )
222225

src/components/design-library-list/util.js

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-console */
22
import DEFAULT from './default.json'
3-
import { settings } from 'stackable'
3+
import { settings, isPro } from 'stackable'
44
import { parse, serialize } from '@wordpress/blocks'
55

66
const DEFAULT_CONTENT = { ...DEFAULT }
@@ -198,3 +198,100 @@ export const parseDisabledBlocks = parsedBlock => {
198198
const block = addOriginalAttributes( [ parsedBlock ] )[ 0 ]
199199
return { block, blocksForSubstitution }
200200
}
201+
202+
const IMAGE_STORAGE = 'https://storage.googleapis.com/stackable-plugin-assets/library-v4/images/'
203+
204+
export const addPlaceholderForPostsBlock = ( content, postsPlaceholder, defaultValues ) => {
205+
const remainingPosts = [ ...postsPlaceholder ]
206+
207+
// Normalize special characters
208+
const normalized = content
209+
.replace( /&lt;/g, '<' )
210+
.replace( /&gt;/g, '>' )
211+
.replace( //g, '-' )
212+
.replace( /\u2013|\u2014/g, '-' )
213+
214+
// Regex to match all stackable/posts blocks
215+
const postBlockRegex = /<!--\s*wp:stackable\/posts\s+(\{[\s\S]*?\})\s*-->([\s\S]*?)<!--\s*\/wp:stackable\/posts\s*-->/g
216+
217+
return normalized.replace( postBlockRegex, ( match, jsonStr, innerHtml ) => {
218+
let attrs
219+
try {
220+
attrs = JSON.parse( jsonStr )
221+
} catch {
222+
return match // Skip if JSON is invalid
223+
}
224+
225+
const numItems = attrs.numberOfItems ?? 6
226+
const width = attrs.imageWidth ? attrs.imageWidth + ( attrs.imageWidthUnit ?? 'px' ) : 'auto'
227+
228+
// Get the post template inside the block
229+
const templateMatch = innerHtml.match( /<!--\s*\/stk-start:posts\/template\s*-->([\s\S]*?)<!--\s*\/stk-end:post\/template\s*-->/ )
230+
if ( ! templateMatch ) {
231+
return match // Skip if template is missing
232+
}
233+
234+
const template = templateMatch[ 1 ].trim()
235+
const currentPosts = remainingPosts.splice( 0, numItems ) // Slice the posts for this block
236+
237+
const renderedPosts = currentPosts.map( ( post, index ) =>
238+
template
239+
.replace( /!#title!#/g, post.title_placeholder )
240+
.replace( /!#excerpt!#/g, post.text_placeholder )
241+
.replace( /!#date!#/g, 'March 1, 2025' )
242+
.replace( /!#readmoreText!#/g, defaultValues[ 'post-btn_placeholder' ] )
243+
.replace( /!#category!#/g, defaultValues.tag_placeholder )
244+
.replace( /img class="stk-img"/g, `img class="stk-img" src="${ IMAGE_STORAGE }stk-design-library-image-${ index + 1 }.jpeg" width="${ width }" style="width: ${ width } !important;"` )
245+
).join( '\n' )
246+
247+
// Replace just the template portion, keep rest of the block
248+
const updatedInnerHtml = innerHtml.replace(
249+
/<!--\s*\/stk-start:posts\/template\s*-->([\s\S]*?)<!--\s*\/stk-end:post\/template\s*-->/,
250+
renderedPosts
251+
)
252+
253+
return `<!-- wp:stackable/posts ${ jsonStr } -->${ updatedInnerHtml }<!-- /wp:stackable/posts -->`
254+
} )
255+
}
256+
257+
// Additional styles for blocks to render properly in the preview
258+
export const getAdditionalStylesForPreview = () => {
259+
let styles = ''
260+
261+
// Make sure count up block numbers are visible
262+
styles += `.stk-block-count-up__text:not(.stk--count-up-active) { opacity: 1; }`
263+
264+
// Fill the vertical line in timeline blocks
265+
styles += `.stk-block-timeline { --line-bg-color: var(--line-accent-bg-color, #000); }`
266+
267+
// Display correctly the progress in progress bar and progress circle blocks
268+
styles += `.stk-progress-bar .stk-progress-bar__bar { width: var(--progress-percent, 0px); }`
269+
styles += `.stk-progress-circle .stk-progress-circle__bar { stroke-dashoffset: var(--progress-dash-offset); }`
270+
271+
// Display correctly the styles for posts block.
272+
// Do this only if in Free version, since we will be able to load the correct CSS for Premium.
273+
if ( ! isPro ) {
274+
styles += `.stk-block-posts.is-style-horizontal-2 {
275+
.stk-block-posts__item > .stk-container {
276+
padding: 0;
277+
display: flex;
278+
flex-direction: row;
279+
280+
> .stk-block-posts__image-link:empty ~ .stk-container-padding,
281+
.stk-container-padding:only-child {
282+
width: 100%;
283+
}
284+
}
285+
.stk-img-wrapper {
286+
height: 100%;
287+
margin-top: 0;
288+
margin-bottom: 0;
289+
}
290+
.stk-block-posts__image-link {
291+
margin-bottom: 0;
292+
}
293+
}`
294+
}
295+
296+
return styles
297+
}

src/design-library/init.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ public function get_design_library_from_cloud() {
252252
$designs = array();
253253
$content = null;
254254

255-
$response = wp_remote_get( self::get_cdn_url() . 'library-v4/library.json' );
255+
// Add ignoreCache to retrieve the updated file
256+
$response = wp_remote_get( self::get_cdn_url() . 'library-v4/library.json?ignoreCache=1' );
256257

257258
if ( is_wp_error( $response ) ) {
258259
// Add our error message so we can see it in the network tab.

0 commit comments

Comments
 (0)