Skip to content

Commit c0eb2f5

Browse files
committed
update placeholders, fix design render
1 parent fc74efa commit c0eb2f5

File tree

4 files changed

+101
-33
lines changed

4 files changed

+101
-33
lines changed

src/block/design-library/edit.js

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const Edit = props => {
102102
const spacingSize = ! presetMarks || ! Array.isArray( presetMarks ) ? 120 : presetMarks[ presetMarks.length - 2 ].value
103103

104104
// Replaces the current block with a block made out of attributes.
105-
const createBlockWithAttributes = async ( blockName, attributes, innerBlocks, substituteBlocks, parentClientId ) => {
105+
const createBlockWithAttributes = async ( category, blockName, attributes, innerBlocks, substituteBlocks, parentClientId ) => {
106106
const disabledBlocks = settings.stackable_block_states || {} // eslint-disable-line camelcase
107107

108108
// Recursively substitute core blocks to disabled Stackable blocks
@@ -189,29 +189,31 @@ const Edit = props => {
189189
attributes = block[ 0 ].attributes
190190
innerBlocks = block[ 0 ].innerBlocks
191191

192-
if ( ! parentClientId && attributes.hasBackground ) {
193-
attributes.blockMargin = {
194-
top: '',
195-
right: '',
196-
bottom: '0',
197-
left: '',
198-
}
199-
} else if ( ! parentClientId ) {
200-
attributes.blockMargin = {
201-
top: spacingSize,
202-
right: '',
203-
bottom: spacingSize,
204-
left: '',
192+
if ( category !== 'Header' ) {
193+
if ( ! parentClientId && attributes.hasBackground ) {
194+
attributes.blockMargin = {
195+
top: '',
196+
right: '',
197+
bottom: '0',
198+
left: '',
199+
}
200+
} else if ( ! parentClientId ) {
201+
attributes.blockMargin = {
202+
top: spacingSize,
203+
right: '',
204+
bottom: spacingSize,
205+
left: '',
206+
}
205207
}
206-
}
207208

208-
const blockLayouts = select( 'stackable/global-spacing-and-borders' ).getBlockLayouts()
209-
if ( attributes.hasBackground && typeof blockLayouts === 'object' && ! blockLayouts[ 'block-background-padding' ] ) {
210-
attributes.blockPadding = {
211-
top: spacingSize,
212-
right: spacingSize,
213-
bottom: spacingSize,
214-
left: spacingSize,
209+
const blockLayouts = select( 'stackable/global-spacing-and-borders' ).getBlockLayouts()
210+
if ( attributes.hasBackground && typeof blockLayouts === 'object' && ! blockLayouts[ 'block-background-padding' ] ) {
211+
attributes.blockPadding = {
212+
top: spacingSize,
213+
right: spacingSize,
214+
bottom: spacingSize,
215+
left: spacingSize,
216+
}
215217
}
216218
}
217219

@@ -229,12 +231,13 @@ const Edit = props => {
229231
const designs = designsRef.current
230232
const blocks = []
231233

232-
for ( const designData of designs ) {
234+
for ( const blockDesign of designs ) {
235+
const { designData, category } = blockDesign
233236
const {
234237
name, attributes, innerBlocks,
235238
} = designData
236239
if ( name && attributes ) {
237-
const block = await createBlockWithAttributes( name, applyFilters( 'stackable.design-library.attributes', attributes ), innerBlocks || [], substituteBlocks, parentClientId )
240+
const block = await createBlockWithAttributes( category, name, applyFilters( 'stackable.design-library.attributes', attributes ), innerBlocks || [], substituteBlocks, parentClientId )
238241
blocks.push( block )
239242
} else {
240243
console.error( 'Design library selection failed: No block data found' ) // eslint-disable-line no-console
@@ -319,13 +322,15 @@ const Edit = props => {
319322
let disabledBlocks = new Set()
320323

321324
_designs.forEach( design => {
322-
const { designData, blocksForSubstitution } = design
325+
const {
326+
designData, blocksForSubstitution, category,
327+
} = design
323328

324329
if ( blocksForSubstitution.size ) {
325330
disabledBlocks = disabledBlocks.union( blocksForSubstitution )
326331
}
327332

328-
designs.push( designData )
333+
designs.push( { designData, category } )
329334
} )
330335

331336
designsRef.current = designs

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,47 @@
277277
"title-7_placeholder": "Storytelling in Brand Building",
278278
"text-7_placeholder": "Learn how compelling narratives can elevate your brand."
279279
},
280+
"Pricing Table": {
281+
"heading_placeholder": "Our Pricing Plans",
282+
"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.",
283+
"btn-1_placeholder": "Get Started",
284+
"btn-2_placeholder": "Buy Now",
285+
"title-1_placeholder": "Flexible Scaling",
286+
"text-1_placeholder": "Easily upgrade or downgrade as your needs evolve.",
287+
"title-2_placeholder": "24/7 Customer Support",
288+
"text-2_placeholder": "Our team is always ready to assist you.",
289+
"title-3_placeholder": "Secure and Reliable Platform",
290+
"text-3_placeholder": "We prioritize your data's security and stability.",
291+
"title-4_placeholder": "Regular Feature Updates",
292+
"text-4_placeholder": "Benefit from continuous improvements and new functionalities.",
293+
"plan-1_placeholder": "Free",
294+
"plan-description-1_placeholder": "Perfect for individuals.",
295+
"plan-1-item-1_placeholder": "Limited Storage (e.g., 500MB)",
296+
"plan-1-item-2_placeholder": "Basic Analytics",
297+
"plan-1-item-3_placeholder": "Email Support",
298+
"plan-1-item-4_placeholder": "1 User Account",
299+
"plan-2_placeholder": "Basic",
300+
"plan-description-2_placeholder": "Ideal for small teams.",
301+
"plan-2-item-1_placeholder": "2GB Storage",
302+
"plan-2-item-2_placeholder": "Standard Analytics",
303+
"plan-2-item-3_placeholder": "Priority Email Support",
304+
"plan-2-item-4_placeholder": "Up to 3 User Accounts",
305+
"plan-3_placeholder": "Pro",
306+
"plan-description-3_placeholder": "Great for growing businesses.",
307+
"plan-3-item-1_placeholder": "10GB Storage",
308+
"plan-3-item-2_placeholder": "Advanced Analytics",
309+
"plan-3-item-3_placeholder": "Chat & Phone Support",
310+
"plan-3-item-4_placeholder": "Up to 10 User Accounts",
311+
"plan-4_placeholder": "Premium",
312+
"plan-description-4_placeholder": "Designed for established businesses.",
313+
"plan-4-item-1_placeholder": "Unlimited Storage",
314+
"plan-4-item-2_placeholder": "Real-time Advanced Analytics",
315+
"plan-4-item-3_placeholder": "Dedicated Account Manager",
316+
"plan-4-item-4_placeholder": "Unlimited User Accounts",
317+
"plan-5_placeholder": "Enterprise",
318+
"plan-description-5_placeholder": "Tailored for large organizations with unique demands.",
319+
"plan-5-details_placeholder": "For customized solutions including specialized features, dedicated infrastructure, and personalized support, please contact us to discuss an Enterprise plan."
320+
},
280321
"Quote": {
281322
"text-1_placeholder": "The journey of a thousand miles begins with a single step.",
282323
"name-1_placeholder": "A. B. Johnson",
@@ -336,7 +377,11 @@
336377
"tab-2_placeholder": "News",
337378
"tab-3_placeholder": "Trending",
338379
"tab-4_placeholder": "For You",
339-
"tab-5_placeholder": "Favorites"
380+
"tab-5_placeholder": "Favorites",
381+
"title-1_placeholder": "Our Vision for the Future",
382+
"text-1_placeholder": "We envision a world where innovation drives progress, and technology empowers individuals. Our commitment lies in fostering solutions that are not only groundbreaking but also accessible and sustainable, contributing to a brighter tomorrow for everyone.",
383+
"title-2_placeholder": "Unlocking Your Potential",
384+
"text-2_placeholder": "Discover the tools and resources designed to help you achieve your goals. We believe in providing comprehensive support and personalized guidance, enabling you to navigate challenges and seize opportunities with confidence."
340385
},
341386
"Team Members": {
342387
"heading_placeholder": "Meet Our Team",

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
6363
const { getEditorDom } = useSelect( 'stackable/editor-dom' )
6464
const editorDom = getEditorDom()
6565

66+
const siteTitle = useSelect( select => select( 'core' ).getEntityRecord( 'root', 'site' )?.title || 'InnovateCo', [] )
67+
6668
const mainClasses = classnames( [
6769
'ugb-design-library-item',
6870
'ugb-design-library-item--toggle',
@@ -131,7 +133,16 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
131133

132134
setParsedBlocks( blocks )
133135

134-
const preview = serialize( blocks )
136+
let preview = serialize( blocks )
137+
138+
// The block `wp/site-title` is a dynamic block, so we need to manually replace it for the preview
139+
if ( category === 'Header' ) {
140+
preview = preview.replace( /<!--\s*wp:site-title(?:\s+[^\/]*?)?\/-->/g, siteTitle )
141+
} else if ( category === 'Tabs' ) {
142+
// Add a class for the first tab to be the active tab in the preview
143+
preview = preview.replace( '"stk-block-tabs__tab"', '"stk-block-tabs__tab stk-block-tabs__tab--active"' )
144+
}
145+
135146
const cleanedBlock = preview.replace( /<!--[\s\S]*?-->/g, '' ) // removes comment
136147

137148
previewRef.current.render( <DesignPreview
@@ -167,9 +178,11 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
167178
// Get all styles needed and make a copy for the shadow DOM
168179
const styleNodes = STYLE_IDS.map( id => {
169180
let style = null
170-
let node = document.getElementById( id )
181+
let node = document?.head?.querySelector( `#${ id }` )
171182
if ( ! node && editorDom ) {
172-
node = editorDom.querySelector( `#${ id }` )
183+
const editorBody = editorDom?.closest( 'body' )
184+
const editorHead = editorBody?.ownerDocument?.head
185+
node = editorHead.querySelector( `#${ id }` )
173186
}
174187

175188
if ( node ) {
@@ -199,7 +212,12 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
199212
: ` [stk-design-library__bg-target="true"].stk-block-background:not(.stk--no-padding) { padding: calc(26px + var(--stk-block-background-padding)); }`
200213
}
201214

215+
// Additional styles for blocks to render properly in the preview
202216
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); }`
220+
203221
styleNodes.push( hostStyles )
204222

205223
styleNodes.forEach( node => {
@@ -262,7 +280,7 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
262280
scale: previewSize.scale,
263281
}
264282

265-
onClick( designId, parsedBlocks, blocksForSubstitutionRef.current, selectedPreviewSize )
283+
onClick( designId, category, parsedBlocks, blocksForSubstitutionRef.current, selectedPreviewSize )
266284
} }
267285
>
268286
{ ! isPro && plan !== 'free' && <span className="stk-pulsating-circle" role="presentation" /> }

src/components/modal-design-library/modal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export const ModalDesignLibrary = props => {
366366
designs={ displayDesigns }
367367
selectedDesigns={ selectedDesignIds }
368368
selectedDesignData={ selectedDesignData }
369-
onSelectMulti={ ( designId, parsedBlocks, blocksForSubstitution, selectedPreviewSize ) => {
369+
onSelectMulti={ ( designId, category, parsedBlocks, blocksForSubstitution, selectedPreviewSize ) => {
370370
const newSelectedDesigns = [ ...selectedDesignIds ]
371371
// We also get the design data from displayDesigns
372372
// already instead of after clicking the "Add
@@ -385,7 +385,7 @@ export const ModalDesignLibrary = props => {
385385
newSelectedDesigns.push( designId )
386386
setSelectedDesignIds( newSelectedDesigns )
387387
newSelectedDesignData.push( {
388-
designData: parsedBlocks, blocksForSubstitution, selectedPreviewSize,
388+
designId, category, designData: parsedBlocks, blocksForSubstitution, selectedPreviewSize,
389389
} )
390390
setSelectedDesignData( newSelectedDesignData )
391391
}

0 commit comments

Comments
 (0)