Skip to content

Commit 49f073f

Browse files
committed
use maps graphic
1 parent 012ce7c commit 49f073f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
214 KB
Loading

src/components/design-library-list/use-preview-renderer.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Internal dependencies.
44
*/
55
import DEFAULT from './default.json'
6+
import mapsGraphic from './images/maps.png'
67
import {
78
addBackgroundScheme, addContainerScheme,
89
addPlaceholderForPostsBlock, cleanParse,
@@ -13,7 +14,9 @@ import {
1314
/**
1415
* External dependencies.
1516
*/
16-
import { isPro, devMode } from 'stackable'
17+
import {
18+
isPro, devMode, srcUrl,
19+
} from 'stackable'
1720
import { fetchDesign } from '~stackable/design-library'
1821
import { cloneDeep } from 'lodash'
1922

@@ -138,6 +141,22 @@ export const usePreviewRenderer = (
138141
preview = addPlaceholderForPostsBlock( preview, defaultValues.posts_placeholder, defaultValues )
139142
}
140143

144+
// For designs with maps block, replace the iframe with an img of the maps
145+
if ( preview.includes( 'stk-block-map' ) ) {
146+
// Regex to match <div ... class="...stk-block-map...">...</div>
147+
preview = preview.replace(
148+
/(<div[^>]*class="[^"]*stk-block-map[^"]*"[^>]*>)([\s\S]*?)(<\/div>)/g,
149+
( match, divStart, divContent, divEnd ) => {
150+
// Replace <iframe ...></iframe> or <iframe .../> with <img ... />
151+
const replacedContent = divContent.replace(
152+
/<iframe[\s\S]*?<\/iframe>|<iframe[\s\S]*?\/>/g,
153+
'<img src="' + srcUrl + '/' + mapsGraphic + '" />'
154+
)
155+
return divStart + replacedContent + divEnd
156+
}
157+
)
158+
}
159+
141160
const cleanedBlock = preview.replace( /<!--[\s\S]*?-->/g, '' ) // removes comment
142161

143162
setBlocks( {

0 commit comments

Comments
 (0)