Skip to content

Commit

Permalink
Merge branch 'release/2.8.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
gsarig committed Nov 17, 2024
2 parents 01e8954 + 95f3121 commit a95b810
Show file tree
Hide file tree
Showing 24 changed files with 188 additions and 139 deletions.
32 changes: 30 additions & 2 deletions build/block/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"full"
]
},
"usesContext": [
"postId",
"postType"
],
"keywords": [
"Map block",
"Open Street Maps",
Expand Down Expand Up @@ -137,8 +141,32 @@
"default": false
}
},
"variations": [
{
"name": "custom-fields",
"title": "OpenStreetMap from custom fields",
"icon": "location",
"attributes": {
"queryCustomFields": true,
"showMapData": false,
"showSearchBox": false,
"serverSideRender": true
}
}
],
"textdomain": "ootb-openstreetmap",
"editorScript": "file:../index.js",
"editorStyle": "file:../index.css",
"style": "file:./style-index.css"
"style": "file:../index.css",
"script": [
"leaflet",
"leaflet-gesture-handling"
],
"viewScript": [
"file:./view.js",
"ootb-openstreetmap"
],
"viewStyle": [
"file:./view.css",
"ootb-openstreetmap"
]
}
1 change: 1 addition & 0 deletions build/block/view.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array(), 'version' => '7dd9752838ac72cc2a7d');
1 change: 1 addition & 0 deletions build/block/view.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion build/index-rtl.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '231a97783f847daa82f0');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => 'fa8efa31d5326e923715');
3 changes: 2 additions & 1 deletion build/index.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/index.js

Large diffs are not rendered by default.

96 changes: 42 additions & 54 deletions includes/classes/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,87 +10,75 @@
namespace OOTB;

class Assets {
public string $handle_ootb_script = 'ootb-openstreetmap-view-script';
public string $handle_leaflet = 'leaflet';

public function __construct() {
global $ootb_inline_scripts_tracking;
$ootb_inline_scripts_tracking = [];
add_action( 'enqueue_block_assets', [ $this, 'frontend' ] );
}

public function frontend() {
if ( Helper::has_block_in_frontend( OOTB_BLOCK_NAME ) ) {
$this->frontend_assets();
}
$this->frontend_assets();
$this->script_variables();
}

public function shortcode_assets() {
wp_enqueue_style( 'ootb-openstreetmap-style', '', $this->handle_leaflet );
wp_enqueue_script( $this->handle_leaflet );
wp_enqueue_script( $this->handle_ootb_script );
}

public function frontend_assets() {
$options = Helper::get_option();
$handle_leaflet = 'leaflet';
$dependencies = [ $handle_leaflet ];
$params = [
'providers' => Helper::providers(),
'options' => $options,
];
wp_enqueue_style(
$handle_leaflet,
OOTB_PLUGIN_URL . 'assets/vendor/leaflet/leaflet.css',
[],
OOTB_SCRIPT_VERSION[ $handle_leaflet ]
);
wp_enqueue_script(
$handle_leaflet,
wp_register_script(
$this->handle_leaflet,
OOTB_PLUGIN_URL . 'assets/vendor/leaflet/leaflet.js',
[],
OOTB_SCRIPT_VERSION[ $handle_leaflet ],
OOTB_SCRIPT_VERSION[ $this->handle_leaflet ],
true
);

if ( ! empty( Helper::get_option( 'prevent_default_gestures' ) ) ) {
$handle_gesture_handling = 'leaflet-gesture-handling';
wp_register_script(
$handle_gesture_handling,
OOTB_PLUGIN_URL . 'assets/vendor/leaflet-gesture-handling/leaflet-gesture-handling.js',
[ $this->handle_leaflet ],
OOTB_SCRIPT_VERSION[ $handle_gesture_handling ],
true
);
}
}

public function script_variables() {
global $ootb_inline_scripts_tracking;
// Do not proceed if the script is already present.
if ( in_array( $this->handle_ootb_script, $ootb_inline_scripts_tracking, true ) ) {
return;
}
$options = Helper::get_option();
$params = [
'providers' => Helper::providers(),
'options' => $options,
];

if ( ! empty( $options[ 'prevent_default_gestures' ] ) ) {
$handle_gesture_handling = 'leaflet-gesture-handling';
$dependencies[] = $handle_gesture_handling;
$params[ 'gestureHandlingOptions' ] = apply_filters(
'ootb_gesture_handling_options',
[
'locale' => Helper::get_gesture_handling_locale(),
]
);
wp_enqueue_style(
$handle_gesture_handling,
OOTB_PLUGIN_URL . 'assets/vendor/leaflet-gesture-handling/leaflet-gesture-handling.css',
[],
OOTB_SCRIPT_VERSION[ $handle_gesture_handling ]
);
wp_enqueue_script(
$handle_gesture_handling,
OOTB_PLUGIN_URL . 'assets/vendor/leaflet-gesture-handling/leaflet-gesture-handling.js',
[ $handle_leaflet ],
OOTB_SCRIPT_VERSION[ $handle_gesture_handling ],
true
);
}

wp_enqueue_script(
'ootb-openstreetmap',
OOTB_PLUGIN_URL . 'assets/js/frontend/ootb-openstreetmap.js',
$dependencies,
OOTB_VERSION,
true
);
wp_add_inline_script( 'ootb-openstreetmap',
$ootb_inline_scripts_tracking[] = $this->handle_ootb_script;
wp_add_inline_script( $this->handle_ootb_script,
sprintf(
'const ootb = %s',
wp_json_encode( $params )
),
'before'
);

add_filter( 'wp_script_attributes', [ $this, 'add_type_attribute' ], 10, 1 );

}

function add_type_attribute( $attributes ) {
// Only do this for a specific script.
if ( isset( $attributes[ 'id' ] ) && $attributes[ 'id' ] === 'ootb-openstreetmap-js' ) {
$attributes[ 'type' ] = 'module';
}

return $attributes;
}
}
2 changes: 1 addition & 1 deletion includes/classes/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function shortcode( $attrs ) {
}
if ( ! Helper::has_block_in_frontend( OOTB_BLOCK_NAME ) ) {
$assets = new Assets();
$assets->frontend_assets();
$assets->shortcode_assets();
}
// Only allow specific attributes.
$attrs = shortcode_atts(
Expand Down
6 changes: 3 additions & 3 deletions ootb-openstreetmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Plugin Name: Out of the Block: OpenStreetMap
* Plugin URI: https://wordpress.org/plugins/ootb-openstreetmap/
* Description: A map block for the Gutenberg Editor using OpenStreetMaps and Leaflet that needs no API keys and works out of the box.
* Requires at least: 5.8.6
* Requires at least: 6.5
* Requires PHP: 7.4
* Version: 2.8.2
* Version: 2.8.3
* Author: Giorgos Sarigiannidis
* Author URI: https://www.gsarigiannidis.gr
* License: GPL-2.0-or-later
Expand All @@ -21,7 +21,7 @@
define( 'OOTB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );

const OOTB_BLOCK_NAME = 'ootb/openstreetmap';
const OOTB_VERSION = '2.8.2';
const OOTB_VERSION = '2.8.3';
const OOTB_SCRIPT_VERSION = [
'leaflet' => '1.9.4',
'leaflet-gesture-handling' => '1.4.4',
Expand Down
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Contributors: gsarig
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MZR4JSRUMH5EA&source=url
Tags: Map, OpenStreetMap, Leaflet, Google Maps, block
Requires at least: 5.8.6
Tested up to: 6.5
Requires at least: 6.5
Tested up to: 6.7
Requires PHP: 7.4
Stable tag: 2.8.2
Stable tag: 2.8.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -109,6 +109,9 @@ Glad you asked! There are a few hooks that you can use to further customize the
12. Demonstrating the OpenAI integration

== Upgrade Notice ==
= 2.8.3 =
Version 2.8.3 makes changes to the way the scripts are loaded, and bumps the minimum WordPress version to 6.5. If you are using an older WordPress version, please update WordPress first, before trying to update the plugin.

= 2.8.0 =
Version 2.8.0 adds support for the "Location" custom field, which allows you to store a post's or a post type's location. Read more in the [v.2.8.0 release notes](https://github.com/gsarig/ootb-openstreetmap/releases/tag/2.8.0).

Expand Down Expand Up @@ -136,6 +139,13 @@ Version 2.0.0 is a major, almost full, refactoring, both for the build scripts a
= 1.0 =

== Changelog ==
= 2.8.3 =
* Bumps support to WordPress 6.7.
* Bumps minimum supported WordPress version to 6.5.
* Fixes a tagging issue in the wordpress.org repo.
* Partially fixes a bug where the block wouldn't display on the Full Site Editor's template parts. There is still a bug where dragging doesn't work well when the block is used in a template part, and was disabled as a temporary workaround.
* Improves the way the frontend scripts are loaded (requires at least WordPress v.6.5 amd above).

= 2.8.2 =
* [NEW] Adds the `ootb_cf_modal_content` and `ootb_cf_marker_icon` hooks, which allow you to change the content of the modal that appears when you query posts based on their "Location" custom fields, as well as the marker icon. For more info, check the plugin's FAQ section.

Expand Down
3 changes: 2 additions & 1 deletion src/block/Elements/LeafletMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {MapContainer} from 'react-leaflet';
import MapEvents from './MapEvents';
import MapUpdate from './MapUpdate';

export default function LeafletMap({addingMarker, setAddingMarker, ...props}) {
export default function LeafletMap({inBlockEditor, addingMarker, setAddingMarker, ...props}) {
const {
attributes: {
zoom,
Expand All @@ -20,6 +20,7 @@ export default function LeafletMap({addingMarker, setAddingMarker, ...props}) {
<MapContainer
center={centerMap(props)}
zoom={zoom}
dragging={inBlockEditor} // Dragging doesn't work well when the block is used in a template part. Disabling it as a temporary workaround.
bounds={bounds}
style={
{
Expand Down
2 changes: 1 addition & 1 deletion src/block/Elements/TileProvider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {TileLayer} from 'react-leaflet';
// noinspection NpmUsedModulesInstalled
import {useEffect, useRef} from '@wordpress/element';
import createMapboxStyleUrl from '../../../assets/js/shared/createMapboxStyleUrl';
import createMapboxStyleUrl from '../../common/createMapboxStyleUrl';

export default function TileProvider({props}) {
const {
Expand Down
23 changes: 21 additions & 2 deletions src/block/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"full"
]
},
"usesContext": [ "postId", "postType" ],
"keywords": [
"Map block",
"Open Street Maps",
Expand Down Expand Up @@ -137,8 +138,26 @@
"default": false
}
},
"variations": [
{
"name": "custom-fields",
"title": "OpenStreetMap from custom fields",
"icon": "location",
"attributes": {
"queryCustomFields": true,
"showMapData": false,
"showSearchBox": false,
"serverSideRender": true
}
}
],
"textdomain": "ootb-openstreetmap",
"editorScript": "file:../index.js",
"editorStyle": "file:../index.css",
"style": "file:./style-index.css"
"style": "file:../index.css",
"script": [
"leaflet",
"leaflet-gesture-handling"
],
"viewScript": [ "file:./view.js", "ootb-openstreetmap" ],
"viewStyle": [ "file:./view.css", "ootb-openstreetmap" ]
}
Loading

0 comments on commit a95b810

Please sign in to comment.