Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.0.1 #25

Merged
merged 3 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .eslintrc.js

This file was deleted.

3 changes: 0 additions & 3 deletions .prettierrc.js

This file was deleted.

3 changes: 0 additions & 3 deletions .stylelintrc

This file was deleted.

10 changes: 0 additions & 10 deletions babel.config.js

This file was deleted.

32 changes: 24 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"scripts": {
"packages-update": "wp-scripts packages-update",
"build": "npm run build:scripts && npm run build:makepot",
"build:scripts": "wp-scripts build ./src/index ./src/frontend",
"build:scripts": "wp-scripts build",
"build:makepot": "npx @wp-blocks/make-pot",
"start": "wp-scripts start ./src/index ./src/frontend",
"start": "wp-scripts start",
"format": "wp-scripts format /src",
"lint:css": "wp-scripts lint-style /src/style",
"lint:js": "wp-scripts lint-js ./src",
Expand Down Expand Up @@ -60,20 +60,36 @@
"babel-jest": "^29.5.0",
"jest-puppeteer": "^8.0.6",
"react-beautiful-dnd": "^13.1.1",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"classnames": "^2.5.1"
},
"dependencies": {
"@mapbox/maki": "^8.0.1",
"@mapbox/mapbox-gl-geocoder": "^5.0.2",
"@mapbox/mapbox-gl-language": "^1.0.1",
"@turf/turf": "^6.5.0",
"classnames": "^2.5.1",
"mapbox-gl": "^3.4.0"
},
"engines": {
"node": ">=16.0.0"
},
"browserslist": [
"extends @wordpress/browserslist-config"
]
],
"engines": {
"node": ">=18.0.0",
"npm": ">=7.0.0"
},
"eslintConfig": {
"extends": [
"plugin:@wordpress/eslint-plugin/recommended"
],
"env": {
"browser": true,
"node": true
},
"globals": {
"window": true,
"document": true,
"localStorage": true
}
},
"prettier": "@wordpress/prettier-config"
}
8 changes: 4 additions & 4 deletions src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@
}
}
},
"viewScript": ["file:./vendors.js", "file:./frontend.js"],
"editorScript": ["file:./vendors.js", "file:./index.js"],
"editorStyle": ["file:./vendors.css","file:./index.css"],
"viewStyle": ["file:./vendors.css","file:./frontend.css"],
"viewScript": ["file:./vendor.js", "file:./frontend.js"],
"editorScript": ["file:./vendor.js", "file:./editor.js"],
"editorStyle": ["file:./vendor.css","file:./style-frontend.css", "file:./style-editor.css", "file:./editor.css"],
"viewStyle": ["file:./vendor.css","file:./style-frontend.css", "file:./frontend.css"],
"render": "file:./render.php"
}
3 changes: 2 additions & 1 deletion src/components/Mapbox/MapboxContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
MapBoxListing,
MountedMapsContextValue,
} from '../../types';
import mapboxgl, { LngLat } from 'mapbox-gl';
import type mapboxgl from 'mapbox-gl';
import type { LngLat } from 'mapbox-gl';
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
import type { MutableRefObject } from 'react';
import { __ } from '@wordpress/i18n';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Mapbox/init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function initMap(
if ( map.getLayer( 'country-label' ) ) {
map.setLayoutProperty( 'country-label', 'text-field', [
'get',
'name_' + defaults?.language?.substring( 0, 2 ) || 'en',
'name_' + defaults.language || 'en',
] );
}

Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const DEFAULT_COLOR_ALT = '#004a83';
export const ICON_SIZE: number = 36;
// https://docs.mapbox.com/api/search/geocoding/#data-types
export const DEFAULT_GEOCODER_TYPE_SEARCH: string =
'country,region,postcode,place,locality,poi';
'country,region,district,postcode,place,locality,poi';

/**
* Markers
Expand Down
29 changes: 15 additions & 14 deletions src/frontend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ export async function createMapRoot(
attributes: MapAttributes
) {
// initialize the map with React
await import( 'mapbox-gl' ).then( ( mapboxgl ) => {
const componentRoot = createRoot( el );
componentRoot.render(
<Suspense fallback={ <Loader wrapperHeight={ '50vh' } /> }>
<MapProvider attributes={ attributes }>
<MapBox
mapboxgl={ mapboxgl.default }
attributes={ attributes }
mapDefaults={ getMapDefaults() }
/>
</MapProvider>
</Suspense>
);
} );
const mapboxgl = await import(
/* webpackChunkName: "mapbox" */ 'mapbox-gl'
);
const componentRoot = createRoot( el );
componentRoot.render(
<Suspense fallback={ <Loader wrapperHeight={ '50vh' } /> }>
<MapProvider attributes={ attributes }>
<MapBox
mapboxgl={ mapboxgl.default }
attributes={ attributes }
mapDefaults={ getMapDefaults() }
/>
</MapProvider>
</Suspense>
);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { Feature, Geometry } from '@turf/turf';
import mapboxgl, { LngLat } from 'mapbox-gl';
import type mapboxgl from 'mapbox-gl';
import type { LngLat } from 'mapbox-gl';
import type {
Dispatch,
MutableRefObject,
RefObject,
SetStateAction,
} from 'react';
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
import type MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';

export type CoordinatesDef = [ number, number ];

Expand Down
56 changes: 15 additions & 41 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,23 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"target": "ES2022",
"module": "ES2022",
"jsx": "react-jsx",
"lib": [ "esnext", "dom", "dom.iterable", "es2022" ],
// Search under node_modules for non-relative imports.
"moduleResolution": "node",
"sourceMap": true,

// Enable the strictest settings like strictNullChecks & noImplicitAny.
"strict": true,

"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"strictNullChecks": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true,
// Import non-ES modules as default imports."esModuleInterop": true,

// Tells TypeScript to read JS files, as
// normally they are ignored as source files
// Search under node_modules for non-relative imports.
"allowJs": true,
// Generate d.ts files
"declaration": true,
"declarationMap": true,
"declarationDir": "build/types",
"emitDeclarationOnly": true,
"pretty": true,

// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
// Process & infer types from .js files.
"noEmit": true,
// Don't emit; allow Babel to transform files.
"outDir": "build",
"typeRoots": [
"node_modules/@types",
"@types"
],
"types": [
"mapbox-gl",
"mapbox__mapbox-gl-geocoder",
"puppeteer",
"jest-environment-puppeteer",
"expect-puppeteer"
]
"baseUrl": "src",
"allowSyntheticDefaultImports": true
},
"include": ["src/**/*", "block.json"],
"exclude": ["build","coverage"]
"include": [
"./src/**/*"
],
"exclude": [
"coverage",
"docs"
]
}
10 changes: 0 additions & 10 deletions tsconfig.types.json

This file was deleted.

9 changes: 6 additions & 3 deletions vsge-mapbox-block.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Plugin Name: vsge-mapbox-block
* Version: 1.0.0
* Version: 1.0.1
* Description: VSGE - mapbox block
* Author: codekraft
* Text Domain: vsge-mapbox-block
Expand All @@ -21,7 +21,8 @@
*
* @return string
*/
function vsge_get_token(): string {
function vsge_get_token(): string
{
if (defined('MAPBOX_TOKEN')) {
return apply_filters('vsge_mapbox_block_key', MAPBOX_TOKEN);
}
Expand All @@ -33,8 +34,10 @@ function vsge_get_token(): string {
*
* @return void
*/
function vsge_mapbox_block_scripts(): void {
function vsge_mapbox_block_scripts(): void
{
echo '<script id="vsge-mapbox-block-data">var mapboxBlockData = ' . json_encode(array('siteurl' => get_option('siteurl'), 'accessToken' => vsge_get_token(), 'language' => get_locale())) . ' </script>';
}

add_action('wp_footer', 'vsge_mapbox_block_scripts');
add_action('admin_footer', 'vsge_mapbox_block_scripts');
24 changes: 21 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,34 @@ const path = require( 'path' );

module.exports = {
...defaultConfig,
entry: {
frontend: './src/frontend.tsx',
editor: './src/index.tsx',
},
module: {
...defaultConfig.module,
rules: [
...defaultConfig.module.rules,
{ test: /\.geojson$/, type: 'json' },
],
},
optimization: {
...defaultConfig.optimization,
splitChunks: {
...defaultConfig.optimization.splitChunks,
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
...defaultConfig.optimization.splitChunks.cacheGroups,
vendor: {
test: /[\\/]node_modules[\\/](mapbox-gl|@mapbox|@turf)[\\/]/,
name: 'vendor',
chunks: 'all',
},
},
},
},
externals: {
react: 'react',
'react-dom': 'reactDOM',
'@wordpress/element': 'element',
},
};
Loading