@@ -51,6 +51,7 @@ export const usePreviewRenderer = (
5151
5252 const [ blocks , setBlocks ] = useState ( { parsed : null , serialized : '' } )
5353 const [ content , setContent ] = useState ( '' )
54+ const [ contentForInsertion , setContentForInsertion ] = useState ( null )
5455
5556 const categoriesRef = useRef ( [ ] )
5657 const blocksForSubstitutionRef = useRef ( false )
@@ -125,7 +126,7 @@ export const usePreviewRenderer = (
125126 }
126127
127128 if ( selectedTab === 'patterns' ) {
128- adjustPatternSpacing ( parsedBlocks [ 0 ] . attributes , category , spacingSize , isDesignLibraryDevMode )
129+ adjustPatternSpacing ( parsedBlocks [ 0 ] . attributes , category , spacingSize , false )
129130 }
130131
131132 let preview = serialize ( parsedBlocks )
@@ -168,44 +169,65 @@ export const usePreviewRenderer = (
168169 // Replace the placeholders with the default content
169170 useEffect ( ( ) => {
170171 let _parsedBlocks = [ ]
172+ let _parsedBlocksForInsertion = null
171173 const initialize = async ( ) => {
172- let _content = template
174+ const _content = template
173175 if ( selectedTab === 'patterns' ) {
174- _content = replacePlaceholders ( _content , category , isDesignLibraryDevMode )
176+ // For preview: always replace placeholders (ignore dev mode)
177+ const _contentForPreview = replacePlaceholders ( _content , category , false )
178+ // For insertion: only create separate content if dev mode is enabled
179+ const _contentForInsertion = isDesignLibraryDevMode ? replacePlaceholders ( _content , category , true ) : _contentForPreview
175180
176181 categoriesRef . current . push ( category )
177182
178- if ( _content . includes ( 'stk-design-library__bg-target="true"' ) ) {
183+ if ( _contentForPreview . includes ( 'stk-design-library__bg-target="true"' ) ) {
179184 hasBackgroundTargetRef . current = true
180185 }
181186
182- _parsedBlocks = cleanParse ( _content )
187+ _parsedBlocks = cleanParse ( _contentForPreview )
188+ _parsedBlocksForInsertion = isDesignLibraryDevMode ? cleanParse ( _contentForInsertion ) : null
183189 } else {
184190 for ( let i = 0 ; i < _content . length ; i ++ ) {
185191 const section = _content [ i ]
186192 const design = await fetchDesign ( section . id )
187- const designContent = replacePlaceholders ( design . template || design . content , design . category )
193+ // For preview: always replace placeholders (ignore dev mode)
194+ const designContentForPreview = replacePlaceholders ( design . template || design . content , design . category , false )
195+ // For insertion: only create separate content if dev mode is enabled
196+ const designContentForInsertion = isDesignLibraryDevMode ? replacePlaceholders ( design . template || design . content , design . category , true ) : designContentForPreview
188197
189198 categoriesRef . current . push ( design . category )
190199
191- let _block = cleanParse ( designContent ) [ 0 ]
200+ let _block = cleanParse ( designContentForPreview ) [ 0 ]
201+ let _blockForInsertion = isDesignLibraryDevMode ? cleanParse ( designContentForInsertion ) [ 0 ] : null
192202
193203 if ( section . bg ) {
194204 _block = addBackgroundScheme ( [ _block ] , true , '' ) [ 0 ]
205+ if ( _blockForInsertion ) {
206+ _blockForInsertion = addBackgroundScheme ( [ _blockForInsertion ] , true , '' ) [ 0 ]
207+ }
195208 }
196209
197- adjustPatternSpacing ( _block . attributes , design . category , spacingSize , isDesignLibraryDevMode )
210+ adjustPatternSpacing ( _block . attributes , design . category , spacingSize , false )
211+ if ( _blockForInsertion ) {
212+ adjustPatternSpacing ( _blockForInsertion . attributes , design . category , spacingSize , true )
213+ }
198214 _parsedBlocks . push ( _block )
215+ if ( _blockForInsertion ) {
216+ _parsedBlocksForInsertion = _parsedBlocksForInsertion || [ ]
217+ _parsedBlocksForInsertion . push ( _blockForInsertion )
218+ }
199219 }
200220 }
201221 }
202222
203223 initialize ( ) . then ( ( ) => {
204224 // We need to parse the content because this is what we use to insert the blocks in the Editor
205225 const [ parsedBlocks , blocksForSubstitution ] = parseDisabledBlocks ( _parsedBlocks )
226+ const parsedBlocksForInsertion = _parsedBlocksForInsertion ? parseDisabledBlocks ( _parsedBlocksForInsertion ) [ 0 ] : null
206227 blocksForSubstitutionRef . current = blocksForSubstitution
207228
208229 setContent ( parsedBlocks )
230+ setContentForInsertion ( parsedBlocksForInsertion )
209231 setIsLoading ( false )
210232 } )
211233 } , [ template ] )
@@ -265,7 +287,8 @@ export const usePreviewRenderer = (
265287 scale : previewSize . scale ,
266288 }
267289
268- onClick ( designId , category , blocks . parsed , blocksForSubstitutionRef . current , selectedPreviewSize )
290+ // Use contentForInsertion if dev mode is enabled, otherwise use regular content
291+ onClick ( designId , category , contentForInsertion || content , blocksForSubstitutionRef . current , selectedPreviewSize )
269292 }
270293
271294 return {
0 commit comments