From 1c52b94501773a1835e9912e2215ab52c7640e5f Mon Sep 17 00:00:00 2001 From: charlieforward9 Date: Fri, 1 Nov 2024 15:08:43 -0700 Subject: [PATCH 1/4] feat: support esm --- babel.config.js | 22 +-- dist/cjs/index.js | 234 ++++++++++++++++++++++++++++ dist/{index.js => cjs/index.min.js} | 0 dist/esm/index.js | 225 ++++++++++++++++++++++++++ dist/esm/index.min.js | 225 ++++++++++++++++++++++++++ package-lock.json | 19 +++ package.json | 16 +- 7 files changed, 730 insertions(+), 11 deletions(-) create mode 100644 dist/cjs/index.js rename dist/{index.js => cjs/index.min.js} (100%) create mode 100644 dist/esm/index.js create mode 100644 dist/esm/index.min.js diff --git a/babel.config.js b/babel.config.js index 8ff461e..c0e3504 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,20 +1,24 @@ +// eslint-disable-next-line no-undef +const isESM = process.env.BABEL_ENV === "esm"; + const babelConfig = { presets: [ [ - '@babel/preset-env', + "@babel/preset-env", { + modules: isESM ? false : "commonjs", targets: { - node: 'current', - chrome: '60', - firefox: '60', - safari: '11.1', - edge: '17', - ie: '11', + node: "current", + chrome: "60", + firefox: "60", + safari: "11.1", + edge: "17", + ie: "11", }, }, ], - '@babel/preset-react', + "@babel/preset-react", ], }; -module.exports = babelConfig; +export default babelConfig; diff --git a/dist/cjs/index.js b/dist/cjs/index.js new file mode 100644 index 0000000..c5bbe22 --- /dev/null +++ b/dist/cjs/index.js @@ -0,0 +1,234 @@ +"use strict"; + +function _typeof(o) { + "@babel/helpers - typeof"; + return ( + (_typeof = + "function" == typeof Symbol && "symbol" == typeof Symbol.iterator + ? function (o) { + return typeof o; + } + : function (o) { + return o && + "function" == typeof Symbol && + o.constructor === Symbol && + o !== Symbol.prototype + ? "symbol" + : typeof o; + }), + _typeof(o) + ); +} +Object.defineProperty(exports, "__esModule", { + value: true, +}); +exports.default = void 0; +var _core = require("@react-leaflet/core"); +var _leaflet = _interopRequireDefault(require("leaflet")); +require("leaflet.markercluster"); +var _excluded = ["children"]; +function _interopRequireDefault(e) { + return e && e.__esModule ? e : { default: e }; +} +function ownKeys(e, r) { + var t = Object.keys(e); + if (Object.getOwnPropertySymbols) { + var o = Object.getOwnPropertySymbols(e); + r && + (o = o.filter(function (r) { + return Object.getOwnPropertyDescriptor(e, r).enumerable; + })), + t.push.apply(t, o); + } + return t; +} +function _objectSpread(e) { + for (var r = 1; r < arguments.length; r++) { + var t = null != arguments[r] ? arguments[r] : {}; + r % 2 + ? ownKeys(Object(t), !0).forEach(function (r) { + _defineProperty(e, r, t[r]); + }) + : Object.getOwnPropertyDescriptors + ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) + : ownKeys(Object(t)).forEach(function (r) { + Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); + }); + } + return e; +} +function _defineProperty(e, r, t) { + return ( + (r = _toPropertyKey(r)) in e + ? Object.defineProperty(e, r, { + value: t, + enumerable: !0, + configurable: !0, + writable: !0, + }) + : (e[r] = t), + e + ); +} +function _toPropertyKey(t) { + var i = _toPrimitive(t, "string"); + return "symbol" == _typeof(i) ? i : i + ""; +} +function _toPrimitive(t, r) { + if ("object" != _typeof(t) || !t) return t; + var e = t[Symbol.toPrimitive]; + if (void 0 !== e) { + var i = e.call(t, r || "default"); + if ("object" != _typeof(i)) return i; + throw new TypeError("@@toPrimitive must return a primitive value."); + } + return ("string" === r ? String : Number)(t); +} +function _slicedToArray(r, e) { + return ( + _arrayWithHoles(r) || + _iterableToArrayLimit(r, e) || + _unsupportedIterableToArray(r, e) || + _nonIterableRest() + ); +} +function _nonIterableRest() { + throw new TypeError( + "Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.", + ); +} +function _unsupportedIterableToArray(r, a) { + if (r) { + if ("string" == typeof r) return _arrayLikeToArray(r, a); + var t = {}.toString.call(r).slice(8, -1); + return ( + "Object" === t && r.constructor && (t = r.constructor.name), + "Map" === t || "Set" === t + ? Array.from(r) + : "Arguments" === t || + /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) + ? _arrayLikeToArray(r, a) + : void 0 + ); + } +} +function _arrayLikeToArray(r, a) { + (null == a || a > r.length) && (a = r.length); + for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; + return n; +} +function _iterableToArrayLimit(r, l) { + var t = + null == r + ? null + : ("undefined" != typeof Symbol && r[Symbol.iterator]) || r["@@iterator"]; + if (null != t) { + var e, + n, + i, + u, + a = [], + f = !0, + o = !1; + try { + if (((i = (t = t.call(r)).next), 0 === l)) { + if (Object(t) !== t) return; + f = !1; + } else + for ( + ; + !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); + f = !0 + ); + } catch (r) { + (o = !0), (n = r); + } finally { + try { + if (!f && null != t.return && ((u = t.return()), Object(u) !== u)) + return; + } finally { + if (o) throw n; + } + } + return a; + } +} +function _arrayWithHoles(r) { + if (Array.isArray(r)) return r; +} +function _objectWithoutProperties(e, t) { + if (null == e) return {}; + var o, + r, + i = _objectWithoutPropertiesLoose(e, t); + if (Object.getOwnPropertySymbols) { + var s = Object.getOwnPropertySymbols(e); + for (r = 0; r < s.length; r++) + (o = s[r]), + t.includes(o) || ({}.propertyIsEnumerable.call(e, o) && (i[o] = e[o])); + } + return i; +} +function _objectWithoutPropertiesLoose(r, e) { + if (null == r) return {}; + var t = {}; + for (var n in r) + if ({}.hasOwnProperty.call(r, n)) { + if (e.includes(n)) continue; + t[n] = r[n]; + } + return t; +} +_leaflet.default.MarkerClusterGroup.include({ + _flushLayerBuffer: function _flushLayerBuffer() { + this.addLayers(this._layerBuffer); + this._layerBuffer = []; + }, + addLayer: function addLayer(layer) { + if (this._layerBuffer.length === 0) { + setTimeout(this._flushLayerBuffer.bind(this), 50); + } + this._layerBuffer.push(layer); + }, +}); +_leaflet.default.MarkerClusterGroup.addInitHook(function () { + this._layerBuffer = []; +}); +function createMarkerCluster(_ref, context) { + var _c = _ref.children, + props = _objectWithoutProperties(_ref, _excluded); + var clusterProps = {}; + var clusterEvents = {}; + + // Splitting props and events to different objects + Object.entries(props).forEach(function (_ref2) { + var _ref3 = _slicedToArray(_ref2, 2), + propName = _ref3[0], + prop = _ref3[1]; + return propName.startsWith("on") + ? (clusterEvents[propName] = prop) + : (clusterProps[propName] = prop); + }); + var instance = new _leaflet.default.MarkerClusterGroup(clusterProps); + + // Initializing event listeners + Object.entries(clusterEvents).forEach(function (_ref4) { + var _ref5 = _slicedToArray(_ref4, 2), + eventAsProp = _ref5[0], + callback = _ref5[1]; + var clusterEvent = "cluster".concat(eventAsProp.substring(2).toLowerCase()); + instance.on(clusterEvent, callback); + }); + return { + instance: instance, + context: _objectSpread( + _objectSpread({}, context), + {}, + { + layerContainer: instance, + }, + ), + }; +} +var MarkerCluster = (0, _core.createPathComponent)(createMarkerCluster); +var _default = (exports.default = MarkerCluster); diff --git a/dist/index.js b/dist/cjs/index.min.js similarity index 100% rename from dist/index.js rename to dist/cjs/index.min.js diff --git a/dist/esm/index.js b/dist/esm/index.js new file mode 100644 index 0000000..3398eba --- /dev/null +++ b/dist/esm/index.js @@ -0,0 +1,225 @@ +function _typeof(o) { + "@babel/helpers - typeof"; + return ( + (_typeof = + "function" == typeof Symbol && "symbol" == typeof Symbol.iterator + ? function (o) { + return typeof o; + } + : function (o) { + return o && + "function" == typeof Symbol && + o.constructor === Symbol && + o !== Symbol.prototype + ? "symbol" + : typeof o; + }), + _typeof(o) + ); +} +var _excluded = ["children"]; +function ownKeys(e, r) { + var t = Object.keys(e); + if (Object.getOwnPropertySymbols) { + var o = Object.getOwnPropertySymbols(e); + r && + (o = o.filter(function (r) { + return Object.getOwnPropertyDescriptor(e, r).enumerable; + })), + t.push.apply(t, o); + } + return t; +} +function _objectSpread(e) { + for (var r = 1; r < arguments.length; r++) { + var t = null != arguments[r] ? arguments[r] : {}; + r % 2 + ? ownKeys(Object(t), !0).forEach(function (r) { + _defineProperty(e, r, t[r]); + }) + : Object.getOwnPropertyDescriptors + ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) + : ownKeys(Object(t)).forEach(function (r) { + Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); + }); + } + return e; +} +function _defineProperty(e, r, t) { + return ( + (r = _toPropertyKey(r)) in e + ? Object.defineProperty(e, r, { + value: t, + enumerable: !0, + configurable: !0, + writable: !0, + }) + : (e[r] = t), + e + ); +} +function _toPropertyKey(t) { + var i = _toPrimitive(t, "string"); + return "symbol" == _typeof(i) ? i : i + ""; +} +function _toPrimitive(t, r) { + if ("object" != _typeof(t) || !t) return t; + var e = t[Symbol.toPrimitive]; + if (void 0 !== e) { + var i = e.call(t, r || "default"); + if ("object" != _typeof(i)) return i; + throw new TypeError("@@toPrimitive must return a primitive value."); + } + return ("string" === r ? String : Number)(t); +} +function _slicedToArray(r, e) { + return ( + _arrayWithHoles(r) || + _iterableToArrayLimit(r, e) || + _unsupportedIterableToArray(r, e) || + _nonIterableRest() + ); +} +function _nonIterableRest() { + throw new TypeError( + "Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.", + ); +} +function _unsupportedIterableToArray(r, a) { + if (r) { + if ("string" == typeof r) return _arrayLikeToArray(r, a); + var t = {}.toString.call(r).slice(8, -1); + return ( + "Object" === t && r.constructor && (t = r.constructor.name), + "Map" === t || "Set" === t + ? Array.from(r) + : "Arguments" === t || + /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) + ? _arrayLikeToArray(r, a) + : void 0 + ); + } +} +function _arrayLikeToArray(r, a) { + (null == a || a > r.length) && (a = r.length); + for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; + return n; +} +function _iterableToArrayLimit(r, l) { + var t = + null == r + ? null + : ("undefined" != typeof Symbol && r[Symbol.iterator]) || r["@@iterator"]; + if (null != t) { + var e, + n, + i, + u, + a = [], + f = !0, + o = !1; + try { + if (((i = (t = t.call(r)).next), 0 === l)) { + if (Object(t) !== t) return; + f = !1; + } else + for ( + ; + !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); + f = !0 + ); + } catch (r) { + (o = !0), (n = r); + } finally { + try { + if (!f && null != t.return && ((u = t.return()), Object(u) !== u)) + return; + } finally { + if (o) throw n; + } + } + return a; + } +} +function _arrayWithHoles(r) { + if (Array.isArray(r)) return r; +} +function _objectWithoutProperties(e, t) { + if (null == e) return {}; + var o, + r, + i = _objectWithoutPropertiesLoose(e, t); + if (Object.getOwnPropertySymbols) { + var s = Object.getOwnPropertySymbols(e); + for (r = 0; r < s.length; r++) + (o = s[r]), + t.includes(o) || ({}.propertyIsEnumerable.call(e, o) && (i[o] = e[o])); + } + return i; +} +function _objectWithoutPropertiesLoose(r, e) { + if (null == r) return {}; + var t = {}; + for (var n in r) + if ({}.hasOwnProperty.call(r, n)) { + if (e.includes(n)) continue; + t[n] = r[n]; + } + return t; +} +import { createPathComponent } from "@react-leaflet/core"; +import L from "leaflet"; +import "leaflet.markercluster"; +L.MarkerClusterGroup.include({ + _flushLayerBuffer: function _flushLayerBuffer() { + this.addLayers(this._layerBuffer); + this._layerBuffer = []; + }, + addLayer: function addLayer(layer) { + if (this._layerBuffer.length === 0) { + setTimeout(this._flushLayerBuffer.bind(this), 50); + } + this._layerBuffer.push(layer); + }, +}); +L.MarkerClusterGroup.addInitHook(function () { + this._layerBuffer = []; +}); +function createMarkerCluster(_ref, context) { + var _c = _ref.children, + props = _objectWithoutProperties(_ref, _excluded); + var clusterProps = {}; + var clusterEvents = {}; + + // Splitting props and events to different objects + Object.entries(props).forEach(function (_ref2) { + var _ref3 = _slicedToArray(_ref2, 2), + propName = _ref3[0], + prop = _ref3[1]; + return propName.startsWith("on") + ? (clusterEvents[propName] = prop) + : (clusterProps[propName] = prop); + }); + var instance = new L.MarkerClusterGroup(clusterProps); + + // Initializing event listeners + Object.entries(clusterEvents).forEach(function (_ref4) { + var _ref5 = _slicedToArray(_ref4, 2), + eventAsProp = _ref5[0], + callback = _ref5[1]; + var clusterEvent = "cluster".concat(eventAsProp.substring(2).toLowerCase()); + instance.on(clusterEvent, callback); + }); + return { + instance: instance, + context: _objectSpread( + _objectSpread({}, context), + {}, + { + layerContainer: instance, + }, + ), + }; +} +var MarkerCluster = createPathComponent(createMarkerCluster); +export default MarkerCluster; diff --git a/dist/esm/index.min.js b/dist/esm/index.min.js new file mode 100644 index 0000000..f998080 --- /dev/null +++ b/dist/esm/index.min.js @@ -0,0 +1,225 @@ +"use strict"; +function _typeof(o) { + "@babel/helpers - typeof"; + return ( + (_typeof = + "function" == typeof Symbol && "symbol" == typeof Symbol.iterator + ? function (o) { + return typeof o; + } + : function (o) { + return o && + "function" == typeof Symbol && + o.constructor === Symbol && + o !== Symbol.prototype + ? "symbol" + : typeof o; + }), + _typeof(o) + ); +} +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = void 0; +var _core = require("@react-leaflet/core"); +var _leaflet = _interopRequireDefault(require("leaflet")); +require("leaflet.markercluster"); +var _excluded = ["children"]; +function _interopRequireDefault(e) { + return e && e.__esModule ? e : { default: e }; +} +function ownKeys(e, r) { + var t = Object.keys(e); + if (Object.getOwnPropertySymbols) { + var o = Object.getOwnPropertySymbols(e); + r && + (o = o.filter(function (r) { + return Object.getOwnPropertyDescriptor(e, r).enumerable; + })), + t.push.apply(t, o); + } + return t; +} +function _objectSpread(e) { + for (var r = 1; r < arguments.length; r++) { + var t = null != arguments[r] ? arguments[r] : {}; + r % 2 + ? ownKeys(Object(t), !0).forEach(function (r) { + _defineProperty(e, r, t[r]); + }) + : Object.getOwnPropertyDescriptors + ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) + : ownKeys(Object(t)).forEach(function (r) { + Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); + }); + } + return e; +} +function _defineProperty(e, r, t) { + return ( + (r = _toPropertyKey(r)) in e + ? Object.defineProperty(e, r, { + value: t, + enumerable: !0, + configurable: !0, + writable: !0, + }) + : (e[r] = t), + e + ); +} +function _toPropertyKey(t) { + var i = _toPrimitive(t, "string"); + return "symbol" == _typeof(i) ? i : i + ""; +} +function _toPrimitive(t, r) { + if ("object" != _typeof(t) || !t) return t; + var e = t[Symbol.toPrimitive]; + if (void 0 !== e) { + var i = e.call(t, r || "default"); + if ("object" != _typeof(i)) return i; + throw new TypeError("@@toPrimitive must return a primitive value."); + } + return ("string" === r ? String : Number)(t); +} +function _slicedToArray(r, e) { + return ( + _arrayWithHoles(r) || + _iterableToArrayLimit(r, e) || + _unsupportedIterableToArray(r, e) || + _nonIterableRest() + ); +} +function _nonIterableRest() { + throw new TypeError( + "Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.", + ); +} +function _unsupportedIterableToArray(r, a) { + if (r) { + if ("string" == typeof r) return _arrayLikeToArray(r, a); + var t = {}.toString.call(r).slice(8, -1); + return ( + "Object" === t && r.constructor && (t = r.constructor.name), + "Map" === t || "Set" === t + ? Array.from(r) + : "Arguments" === t || + /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) + ? _arrayLikeToArray(r, a) + : void 0 + ); + } +} +function _arrayLikeToArray(r, a) { + (null == a || a > r.length) && (a = r.length); + for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; + return n; +} +function _iterableToArrayLimit(r, l) { + var t = + null == r + ? null + : ("undefined" != typeof Symbol && r[Symbol.iterator]) || r["@@iterator"]; + if (null != t) { + var e, + n, + i, + u, + a = [], + f = !0, + o = !1; + try { + if (((i = (t = t.call(r)).next), 0 === l)) { + if (Object(t) !== t) return; + f = !1; + } else + for ( + ; + !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); + f = !0 + ); + } catch (r) { + (o = !0), (n = r); + } finally { + try { + if (!f && null != t.return && ((u = t.return()), Object(u) !== u)) + return; + } finally { + if (o) throw n; + } + } + return a; + } +} +function _arrayWithHoles(r) { + if (Array.isArray(r)) return r; +} +function _objectWithoutProperties(e, t) { + if (null == e) return {}; + var o, + r, + i = _objectWithoutPropertiesLoose(e, t); + if (Object.getOwnPropertySymbols) { + var s = Object.getOwnPropertySymbols(e); + for (r = 0; r < s.length; r++) + (o = s[r]), + t.includes(o) || ({}.propertyIsEnumerable.call(e, o) && (i[o] = e[o])); + } + return i; +} +function _objectWithoutPropertiesLoose(r, e) { + if (null == r) return {}; + var t = {}; + for (var n in r) + if ({}.hasOwnProperty.call(r, n)) { + if (e.includes(n)) continue; + t[n] = r[n]; + } + return t; +} +_leaflet.default.MarkerClusterGroup.include({ + _flushLayerBuffer: function _flushLayerBuffer() { + this.addLayers(this._layerBuffer); + this._layerBuffer = []; + }, + addLayer: function addLayer(layer) { + if (this._layerBuffer.length === 0) { + setTimeout(this._flushLayerBuffer.bind(this), 50); + } + this._layerBuffer.push(layer); + }, +}); +_leaflet.default.MarkerClusterGroup.addInitHook(function () { + this._layerBuffer = []; +}); +function createMarkerCluster(_ref, context) { + var _c = _ref.children, + props = _objectWithoutProperties(_ref, _excluded); + var clusterProps = {}; + var clusterEvents = {}; + Object.entries(props).forEach(function (_ref2) { + var _ref3 = _slicedToArray(_ref2, 2), + propName = _ref3[0], + prop = _ref3[1]; + return propName.startsWith("on") + ? (clusterEvents[propName] = prop) + : (clusterProps[propName] = prop); + }); + var instance = new _leaflet.default.MarkerClusterGroup(clusterProps); + Object.entries(clusterEvents).forEach(function (_ref4) { + var _ref5 = _slicedToArray(_ref4, 2), + eventAsProp = _ref5[0], + callback = _ref5[1]; + var clusterEvent = "cluster".concat(eventAsProp.substring(2).toLowerCase()); + instance.on(clusterEvent, callback); + }); + return { + instance: instance, + context: _objectSpread( + _objectSpread({}, context), + {}, + { layerContainer: instance }, + ), + }; +} +var MarkerCluster = (0, _core.createPathComponent)(createMarkerCluster); +var _default = (exports.default = MarkerCluster); diff --git a/package-lock.json b/package-lock.json index 15b63bd..7d483e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,6 +33,7 @@ "@storybook/react": "^8.4.0", "@storybook/react-webpack5": "^8.4.0", "@storybook/test": "^8.4.0", + "cross-env": "^7.0.3", "css-loader": "^7.1.2", "eslint": "^9.13.0", "eslint-config-prettier": "^9.1.0", @@ -5546,6 +5547,24 @@ "typescript": ">=4" } }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", diff --git a/package.json b/package.json index b16a868..a23cdfd 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,17 @@ "name": "react-leaflet-markercluster", "version": "4.1.1", "description": "React wrapper of Leaflet.markercluster for react-leaflet", - "main": "dist/index.js", "repository": "git@github.com:YUzhva/react-leaflet-markercluster.git", + "type": "module", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "exports": { + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + }, + "./styles": "./dist/styles.min.css" + }, "keywords": [ "react", "leaflet", @@ -35,7 +44,9 @@ "scripts": { "dev": "storybook dev -p 6006", "lint": "eslint --ext .js ./ --ignore-pattern '/dist/'", - "build:code": "babel ./src -d ./dist && terser ./dist/react-leaflet-markercluster.js -o ./dist/index.js && rm ./dist/react-leaflet-markercluster.js", + "build:cjs": "cross-env BABEL_ENV=cjs babel ./src -o ./dist/cjs/index.js && terser ./dist/cjs/index.js -o ./dist/cjs/index.min.js", + "build:esm": "cross-env BABEL_ENV=esm babel ./src -o ./dist/esm/index.js && terser ./dist/esm/index.js -o ./dist/esm/index.min.js", + "build:code": "npm run build:cjs && npm run build:esm", "build:styles": "sass ./src/styles.scss ./dist/styles.min.css --style=compressed --no-source-map --load-path=node_modules", "build:source": "npm run build:code && npm run build:styles", "build:gh-pages": "storybook build", @@ -61,6 +72,7 @@ "@storybook/react": "^8.4.0", "@storybook/react-webpack5": "^8.4.0", "@storybook/test": "^8.4.0", + "cross-env": "^7.0.3", "css-loader": "^7.1.2", "eslint": "^9.13.0", "eslint-config-prettier": "^9.1.0", From f021cf2a344fcbf1ac1377af0eb48e50558c3286 Mon Sep 17 00:00:00 2001 From: charlieforward9 Date: Thu, 7 Nov 2024 11:46:24 -0500 Subject: [PATCH 2/4] chore: remove minified dist code / scripts --- dist/cjs/index.min.js | 225 ------------------------------------------ dist/esm/index.min.js | 225 ------------------------------------------ package.json | 4 +- 3 files changed, 2 insertions(+), 452 deletions(-) delete mode 100644 dist/cjs/index.min.js delete mode 100644 dist/esm/index.min.js diff --git a/dist/cjs/index.min.js b/dist/cjs/index.min.js deleted file mode 100644 index f998080..0000000 --- a/dist/cjs/index.min.js +++ /dev/null @@ -1,225 +0,0 @@ -"use strict"; -function _typeof(o) { - "@babel/helpers - typeof"; - return ( - (_typeof = - "function" == typeof Symbol && "symbol" == typeof Symbol.iterator - ? function (o) { - return typeof o; - } - : function (o) { - return o && - "function" == typeof Symbol && - o.constructor === Symbol && - o !== Symbol.prototype - ? "symbol" - : typeof o; - }), - _typeof(o) - ); -} -Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; -var _core = require("@react-leaflet/core"); -var _leaflet = _interopRequireDefault(require("leaflet")); -require("leaflet.markercluster"); -var _excluded = ["children"]; -function _interopRequireDefault(e) { - return e && e.__esModule ? e : { default: e }; -} -function ownKeys(e, r) { - var t = Object.keys(e); - if (Object.getOwnPropertySymbols) { - var o = Object.getOwnPropertySymbols(e); - r && - (o = o.filter(function (r) { - return Object.getOwnPropertyDescriptor(e, r).enumerable; - })), - t.push.apply(t, o); - } - return t; -} -function _objectSpread(e) { - for (var r = 1; r < arguments.length; r++) { - var t = null != arguments[r] ? arguments[r] : {}; - r % 2 - ? ownKeys(Object(t), !0).forEach(function (r) { - _defineProperty(e, r, t[r]); - }) - : Object.getOwnPropertyDescriptors - ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) - : ownKeys(Object(t)).forEach(function (r) { - Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); - }); - } - return e; -} -function _defineProperty(e, r, t) { - return ( - (r = _toPropertyKey(r)) in e - ? Object.defineProperty(e, r, { - value: t, - enumerable: !0, - configurable: !0, - writable: !0, - }) - : (e[r] = t), - e - ); -} -function _toPropertyKey(t) { - var i = _toPrimitive(t, "string"); - return "symbol" == _typeof(i) ? i : i + ""; -} -function _toPrimitive(t, r) { - if ("object" != _typeof(t) || !t) return t; - var e = t[Symbol.toPrimitive]; - if (void 0 !== e) { - var i = e.call(t, r || "default"); - if ("object" != _typeof(i)) return i; - throw new TypeError("@@toPrimitive must return a primitive value."); - } - return ("string" === r ? String : Number)(t); -} -function _slicedToArray(r, e) { - return ( - _arrayWithHoles(r) || - _iterableToArrayLimit(r, e) || - _unsupportedIterableToArray(r, e) || - _nonIterableRest() - ); -} -function _nonIterableRest() { - throw new TypeError( - "Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.", - ); -} -function _unsupportedIterableToArray(r, a) { - if (r) { - if ("string" == typeof r) return _arrayLikeToArray(r, a); - var t = {}.toString.call(r).slice(8, -1); - return ( - "Object" === t && r.constructor && (t = r.constructor.name), - "Map" === t || "Set" === t - ? Array.from(r) - : "Arguments" === t || - /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) - ? _arrayLikeToArray(r, a) - : void 0 - ); - } -} -function _arrayLikeToArray(r, a) { - (null == a || a > r.length) && (a = r.length); - for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; - return n; -} -function _iterableToArrayLimit(r, l) { - var t = - null == r - ? null - : ("undefined" != typeof Symbol && r[Symbol.iterator]) || r["@@iterator"]; - if (null != t) { - var e, - n, - i, - u, - a = [], - f = !0, - o = !1; - try { - if (((i = (t = t.call(r)).next), 0 === l)) { - if (Object(t) !== t) return; - f = !1; - } else - for ( - ; - !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); - f = !0 - ); - } catch (r) { - (o = !0), (n = r); - } finally { - try { - if (!f && null != t.return && ((u = t.return()), Object(u) !== u)) - return; - } finally { - if (o) throw n; - } - } - return a; - } -} -function _arrayWithHoles(r) { - if (Array.isArray(r)) return r; -} -function _objectWithoutProperties(e, t) { - if (null == e) return {}; - var o, - r, - i = _objectWithoutPropertiesLoose(e, t); - if (Object.getOwnPropertySymbols) { - var s = Object.getOwnPropertySymbols(e); - for (r = 0; r < s.length; r++) - (o = s[r]), - t.includes(o) || ({}.propertyIsEnumerable.call(e, o) && (i[o] = e[o])); - } - return i; -} -function _objectWithoutPropertiesLoose(r, e) { - if (null == r) return {}; - var t = {}; - for (var n in r) - if ({}.hasOwnProperty.call(r, n)) { - if (e.includes(n)) continue; - t[n] = r[n]; - } - return t; -} -_leaflet.default.MarkerClusterGroup.include({ - _flushLayerBuffer: function _flushLayerBuffer() { - this.addLayers(this._layerBuffer); - this._layerBuffer = []; - }, - addLayer: function addLayer(layer) { - if (this._layerBuffer.length === 0) { - setTimeout(this._flushLayerBuffer.bind(this), 50); - } - this._layerBuffer.push(layer); - }, -}); -_leaflet.default.MarkerClusterGroup.addInitHook(function () { - this._layerBuffer = []; -}); -function createMarkerCluster(_ref, context) { - var _c = _ref.children, - props = _objectWithoutProperties(_ref, _excluded); - var clusterProps = {}; - var clusterEvents = {}; - Object.entries(props).forEach(function (_ref2) { - var _ref3 = _slicedToArray(_ref2, 2), - propName = _ref3[0], - prop = _ref3[1]; - return propName.startsWith("on") - ? (clusterEvents[propName] = prop) - : (clusterProps[propName] = prop); - }); - var instance = new _leaflet.default.MarkerClusterGroup(clusterProps); - Object.entries(clusterEvents).forEach(function (_ref4) { - var _ref5 = _slicedToArray(_ref4, 2), - eventAsProp = _ref5[0], - callback = _ref5[1]; - var clusterEvent = "cluster".concat(eventAsProp.substring(2).toLowerCase()); - instance.on(clusterEvent, callback); - }); - return { - instance: instance, - context: _objectSpread( - _objectSpread({}, context), - {}, - { layerContainer: instance }, - ), - }; -} -var MarkerCluster = (0, _core.createPathComponent)(createMarkerCluster); -var _default = (exports.default = MarkerCluster); diff --git a/dist/esm/index.min.js b/dist/esm/index.min.js deleted file mode 100644 index f998080..0000000 --- a/dist/esm/index.min.js +++ /dev/null @@ -1,225 +0,0 @@ -"use strict"; -function _typeof(o) { - "@babel/helpers - typeof"; - return ( - (_typeof = - "function" == typeof Symbol && "symbol" == typeof Symbol.iterator - ? function (o) { - return typeof o; - } - : function (o) { - return o && - "function" == typeof Symbol && - o.constructor === Symbol && - o !== Symbol.prototype - ? "symbol" - : typeof o; - }), - _typeof(o) - ); -} -Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; -var _core = require("@react-leaflet/core"); -var _leaflet = _interopRequireDefault(require("leaflet")); -require("leaflet.markercluster"); -var _excluded = ["children"]; -function _interopRequireDefault(e) { - return e && e.__esModule ? e : { default: e }; -} -function ownKeys(e, r) { - var t = Object.keys(e); - if (Object.getOwnPropertySymbols) { - var o = Object.getOwnPropertySymbols(e); - r && - (o = o.filter(function (r) { - return Object.getOwnPropertyDescriptor(e, r).enumerable; - })), - t.push.apply(t, o); - } - return t; -} -function _objectSpread(e) { - for (var r = 1; r < arguments.length; r++) { - var t = null != arguments[r] ? arguments[r] : {}; - r % 2 - ? ownKeys(Object(t), !0).forEach(function (r) { - _defineProperty(e, r, t[r]); - }) - : Object.getOwnPropertyDescriptors - ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) - : ownKeys(Object(t)).forEach(function (r) { - Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); - }); - } - return e; -} -function _defineProperty(e, r, t) { - return ( - (r = _toPropertyKey(r)) in e - ? Object.defineProperty(e, r, { - value: t, - enumerable: !0, - configurable: !0, - writable: !0, - }) - : (e[r] = t), - e - ); -} -function _toPropertyKey(t) { - var i = _toPrimitive(t, "string"); - return "symbol" == _typeof(i) ? i : i + ""; -} -function _toPrimitive(t, r) { - if ("object" != _typeof(t) || !t) return t; - var e = t[Symbol.toPrimitive]; - if (void 0 !== e) { - var i = e.call(t, r || "default"); - if ("object" != _typeof(i)) return i; - throw new TypeError("@@toPrimitive must return a primitive value."); - } - return ("string" === r ? String : Number)(t); -} -function _slicedToArray(r, e) { - return ( - _arrayWithHoles(r) || - _iterableToArrayLimit(r, e) || - _unsupportedIterableToArray(r, e) || - _nonIterableRest() - ); -} -function _nonIterableRest() { - throw new TypeError( - "Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.", - ); -} -function _unsupportedIterableToArray(r, a) { - if (r) { - if ("string" == typeof r) return _arrayLikeToArray(r, a); - var t = {}.toString.call(r).slice(8, -1); - return ( - "Object" === t && r.constructor && (t = r.constructor.name), - "Map" === t || "Set" === t - ? Array.from(r) - : "Arguments" === t || - /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) - ? _arrayLikeToArray(r, a) - : void 0 - ); - } -} -function _arrayLikeToArray(r, a) { - (null == a || a > r.length) && (a = r.length); - for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; - return n; -} -function _iterableToArrayLimit(r, l) { - var t = - null == r - ? null - : ("undefined" != typeof Symbol && r[Symbol.iterator]) || r["@@iterator"]; - if (null != t) { - var e, - n, - i, - u, - a = [], - f = !0, - o = !1; - try { - if (((i = (t = t.call(r)).next), 0 === l)) { - if (Object(t) !== t) return; - f = !1; - } else - for ( - ; - !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); - f = !0 - ); - } catch (r) { - (o = !0), (n = r); - } finally { - try { - if (!f && null != t.return && ((u = t.return()), Object(u) !== u)) - return; - } finally { - if (o) throw n; - } - } - return a; - } -} -function _arrayWithHoles(r) { - if (Array.isArray(r)) return r; -} -function _objectWithoutProperties(e, t) { - if (null == e) return {}; - var o, - r, - i = _objectWithoutPropertiesLoose(e, t); - if (Object.getOwnPropertySymbols) { - var s = Object.getOwnPropertySymbols(e); - for (r = 0; r < s.length; r++) - (o = s[r]), - t.includes(o) || ({}.propertyIsEnumerable.call(e, o) && (i[o] = e[o])); - } - return i; -} -function _objectWithoutPropertiesLoose(r, e) { - if (null == r) return {}; - var t = {}; - for (var n in r) - if ({}.hasOwnProperty.call(r, n)) { - if (e.includes(n)) continue; - t[n] = r[n]; - } - return t; -} -_leaflet.default.MarkerClusterGroup.include({ - _flushLayerBuffer: function _flushLayerBuffer() { - this.addLayers(this._layerBuffer); - this._layerBuffer = []; - }, - addLayer: function addLayer(layer) { - if (this._layerBuffer.length === 0) { - setTimeout(this._flushLayerBuffer.bind(this), 50); - } - this._layerBuffer.push(layer); - }, -}); -_leaflet.default.MarkerClusterGroup.addInitHook(function () { - this._layerBuffer = []; -}); -function createMarkerCluster(_ref, context) { - var _c = _ref.children, - props = _objectWithoutProperties(_ref, _excluded); - var clusterProps = {}; - var clusterEvents = {}; - Object.entries(props).forEach(function (_ref2) { - var _ref3 = _slicedToArray(_ref2, 2), - propName = _ref3[0], - prop = _ref3[1]; - return propName.startsWith("on") - ? (clusterEvents[propName] = prop) - : (clusterProps[propName] = prop); - }); - var instance = new _leaflet.default.MarkerClusterGroup(clusterProps); - Object.entries(clusterEvents).forEach(function (_ref4) { - var _ref5 = _slicedToArray(_ref4, 2), - eventAsProp = _ref5[0], - callback = _ref5[1]; - var clusterEvent = "cluster".concat(eventAsProp.substring(2).toLowerCase()); - instance.on(clusterEvent, callback); - }); - return { - instance: instance, - context: _objectSpread( - _objectSpread({}, context), - {}, - { layerContainer: instance }, - ), - }; -} -var MarkerCluster = (0, _core.createPathComponent)(createMarkerCluster); -var _default = (exports.default = MarkerCluster); diff --git a/package.json b/package.json index a23cdfd..198aa27 100644 --- a/package.json +++ b/package.json @@ -44,8 +44,8 @@ "scripts": { "dev": "storybook dev -p 6006", "lint": "eslint --ext .js ./ --ignore-pattern '/dist/'", - "build:cjs": "cross-env BABEL_ENV=cjs babel ./src -o ./dist/cjs/index.js && terser ./dist/cjs/index.js -o ./dist/cjs/index.min.js", - "build:esm": "cross-env BABEL_ENV=esm babel ./src -o ./dist/esm/index.js && terser ./dist/esm/index.js -o ./dist/esm/index.min.js", + "build:cjs": "cross-env BABEL_ENV=cjs babel ./src -o ./dist/cjs/index.js", + "build:esm": "cross-env BABEL_ENV=esm babel ./src -o ./dist/esm/index.js", "build:code": "npm run build:cjs && npm run build:esm", "build:styles": "sass ./src/styles.scss ./dist/styles.min.css --style=compressed --no-source-map --load-path=node_modules", "build:source": "npm run build:code && npm run build:styles", From 304726a2656213407a2f0ec141a749ac56a4a581 Mon Sep 17 00:00:00 2001 From: charlieforward9 Date: Thu, 5 Dec 2024 23:27:18 -0500 Subject: [PATCH 3/4] docs: update region example --- .storybook/examples/region.jsx | 35 ++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/.storybook/examples/region.jsx b/.storybook/examples/region.jsx index c438be6..5961647 100644 --- a/.storybook/examples/region.jsx +++ b/.storybook/examples/region.jsx @@ -1,7 +1,7 @@ import React from "react"; import { Polygon } from "leaflet"; import { createPathComponent } from "@react-leaflet/core"; -import { MapContainer, TileLayer } from "react-leaflet"; +import { MapContainer, TileLayer, Popup } from "react-leaflet"; import MarkerClusterGroup from "../../src/react-leaflet-markercluster"; import { MAP_ZOOM, MAP_MAX_ZOOM, MAP_CENTER_COORDINATES } from "./constants"; import "./styles.scss"; @@ -11,7 +11,7 @@ function randomCoords() { } const ClusterableRegion = createPathComponent(function createClusterableRegion( - { coordinates, color = "blue", fillOpacity = 0.3, onClick }, + { latlngs, color = "blue", fillOpacity = 0.3, ...props }, ctx, ) { // Define a clusterable region with a getLatLng method for clustering compatibility @@ -28,10 +28,10 @@ const ClusterableRegion = createPathComponent(function createClusterableRegion( }); // Instantiate the ClusterablePolygon with provided positions and options - const region = new ClusterableRegion(coordinates, { + const region = new ClusterableRegion(latlngs, { color, fillOpacity, - onclick: onClick, + ...props, }); return { @@ -61,7 +61,7 @@ const RegionExample = () => ( return ( ( centerCoords[1] + Math.random(), ], ]} - /> + eventHandlers={{ + click: () => { + console.log(`Region ${i} clicked`); + }, + mouseover: (event) => { + event.target.openPopup(); + }, + mouseout: (event) => { + const target = event.target; + if ( + target._popup && + target._popup._container.contains( + //@ts-expect-error - toElement not recognized by TS + event.originalEvent.toElement, + ) + ) { + return; + } + target.closePopup(); + }, + }} + > + Region {i} + ); })} From e78ae0726089161fcfb3167b057f191e853dca4a Mon Sep 17 00:00:00 2001 From: charlieforward9 Date: Thu, 5 Dec 2024 23:28:47 -0500 Subject: [PATCH 4/4] chore: bump 4.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 198aa27..bb8f3ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-leaflet-markercluster", - "version": "4.1.1", + "version": "4.1.2", "description": "React wrapper of Leaflet.markercluster for react-leaflet", "repository": "git@github.com:YUzhva/react-leaflet-markercluster.git", "type": "module",