diff --git a/projects/plugins/jetpack/changelog/display-map-block-as-preview-if-in-block-preview-mode b/projects/plugins/jetpack/changelog/display-map-block-as-preview-if-in-block-preview-mode
new file mode 100644
index 0000000000000..3ee73641ae113
--- /dev/null
+++ b/projects/plugins/jetpack/changelog/display-map-block-as-preview-if-in-block-preview-mode
@@ -0,0 +1,4 @@
+Significance: patch
+Type: other
+
+Map block: Display a static map image when the block is rendered in a pattern preview
diff --git a/projects/plugins/jetpack/changelog/remove-preview-attribute-from-map-block b/projects/plugins/jetpack/changelog/remove-preview-attribute-from-map-block
new file mode 100644
index 0000000000000..514100b1029fe
--- /dev/null
+++ b/projects/plugins/jetpack/changelog/remove-preview-attribute-from-map-block
@@ -0,0 +1,4 @@
+Significance: patch
+Type: other
+
+Map: remove preview attribute. The mechanism to determine if the block is in preview mode changed internally.
diff --git a/projects/plugins/jetpack/extensions/blocks/map/block.json b/projects/plugins/jetpack/extensions/blocks/map/block.json
index 3b537067858e5..eca12d214a760 100644
--- a/projects/plugins/jetpack/extensions/blocks/map/block.json
+++ b/projects/plugins/jetpack/extensions/blocks/map/block.json
@@ -41,10 +41,6 @@
"type": "string",
"default": "red"
},
- "preview": {
- "type": "boolean",
- "default": false
- },
"scrollToZoom": {
"type": "boolean",
"default": false
@@ -57,9 +53,5 @@
"default": true
}
},
- "example": {
- "attributes": {
- "preview": true
- }
- }
+ "example": {}
}
diff --git a/projects/plugins/jetpack/extensions/blocks/map/deprecated/v1/index.js b/projects/plugins/jetpack/extensions/blocks/map/deprecated/v1/index.js
index f8c69b5889fea..6db6c96f8f530 100644
--- a/projects/plugins/jetpack/extensions/blocks/map/deprecated/v1/index.js
+++ b/projects/plugins/jetpack/extensions/blocks/map/deprecated/v1/index.js
@@ -40,10 +40,6 @@ const attributes = {
type: 'string',
default: 'red',
},
- preview: {
- type: 'boolean',
- default: false,
- },
scrollToZoom: {
type: 'boolean',
default: false,
diff --git a/projects/plugins/jetpack/extensions/blocks/map/deprecated/v2/index.js b/projects/plugins/jetpack/extensions/blocks/map/deprecated/v2/index.js
index 4f10d1c29bf2c..24863901eb331 100644
--- a/projects/plugins/jetpack/extensions/blocks/map/deprecated/v2/index.js
+++ b/projects/plugins/jetpack/extensions/blocks/map/deprecated/v2/index.js
@@ -41,10 +41,6 @@ const attributes = {
type: 'string',
default: 'red',
},
- preview: {
- type: 'boolean',
- default: false,
- },
scrollToZoom: {
type: 'boolean',
default: false,
diff --git a/projects/plugins/jetpack/extensions/blocks/map/edit.js b/projects/plugins/jetpack/extensions/blocks/map/edit.js
index e5758c3475e1f..9d5891bb9e587 100644
--- a/projects/plugins/jetpack/extensions/blocks/map/edit.js
+++ b/projects/plugins/jetpack/extensions/blocks/map/edit.js
@@ -1,6 +1,11 @@
import { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils';
import apiFetch from '@wordpress/api-fetch';
-import { BlockControls, InspectorControls, useBlockProps } from '@wordpress/block-editor';
+import {
+ BlockControls,
+ InspectorControls,
+ useBlockProps,
+ store as blockEditorStore,
+} from '@wordpress/block-editor';
import {
Button,
ExternalLink,
@@ -10,7 +15,7 @@ import {
ResizableBox,
} from '@wordpress/components';
import { compose } from '@wordpress/compose';
-import { withDispatch } from '@wordpress/data';
+import { withDispatch, useSelect } from '@wordpress/data';
import { useEffect, useRef, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { getActiveStyleName } from '../../shared/block-styles';
@@ -62,11 +67,18 @@ const MapEdit = ( {
zoom,
mapCenter,
markerColor,
- preview,
mapHeight,
showFullscreenButton,
} = attributes;
+ const { isPreviewMode } = useSelect( select => {
+ const { getSettings } = select( blockEditorStore );
+ const settings = getSettings();
+ return {
+ isPreviewMode: settings.__unstableIsPreviewMode,
+ };
+ }, [] );
+
const [ addPointVisibility, setAddPointVisibility ] = useState( false );
const [ apiState, setApiState ] = useState( API_STATE_LOADING );
const [ apiKey, setApiKey ] = useState( null );
@@ -223,7 +235,7 @@ const MapEdit = ( {
let content;
- if ( preview ) {
+ if ( isPreviewMode ) {
const mapStyleObject = styles.find( styleObject => styleObject.name === mapStyle );
content = (
@@ -231,6 +243,7 @@ const MapEdit = ( {
);
diff --git a/projects/plugins/jetpack/extensions/blocks/map/test/fixtures/jetpack__map.json b/projects/plugins/jetpack/extensions/blocks/map/test/fixtures/jetpack__map.json
index ae6191ec05e32..ed5cca43347fc 100644
--- a/projects/plugins/jetpack/extensions/blocks/map/test/fixtures/jetpack__map.json
+++ b/projects/plugins/jetpack/extensions/blocks/map/test/fixtures/jetpack__map.json
@@ -24,7 +24,6 @@
"lat": -43.391304
},
"markerColor": "red",
- "preview": false,
"scrollToZoom": false,
"showFullscreenButton": true
},
diff --git a/projects/plugins/jetpack/extensions/blocks/map/test/fixtures/jetpack__map__deprecated-1.json b/projects/plugins/jetpack/extensions/blocks/map/test/fixtures/jetpack__map__deprecated-1.json
index 08808d0ba6d41..e549862eab94d 100644
--- a/projects/plugins/jetpack/extensions/blocks/map/test/fixtures/jetpack__map__deprecated-1.json
+++ b/projects/plugins/jetpack/extensions/blocks/map/test/fixtures/jetpack__map__deprecated-1.json
@@ -1,34 +1,33 @@
[
- {
- "clientId": "_clientId_0",
- "name": "jetpack/map",
- "isValid": true,
- "attributes": {
- "points": [
- {
- "placeTitle": "Williams Street",
- "title": "Williams Street",
- "caption": "15 Williams Street, Kaiapoi, The Pines Beach 7630, New Zealand",
- "id": "address.3454160499802812",
- "coordinates": {
- "longitude": 172.652908,
- "latitude": -43.391304
- }
- }
- ],
- "mapDetails": true,
- "zoom": 11.765903600711997,
- "mapCenter": {
- "lng": 172.652908,
- "lat": -43.391304
- },
- "markerColor": "red",
- "preview": false,
- "scrollToZoom": false,
- "className": "is-style-black-and-white",
- "showFullscreenButton": true
- },
- "innerBlocks": [],
- "originalContent": "