react-dpd-pickup-map 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ ci:
10
+ name: Lint, Typecheck, Test & Build
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v6
14
+
15
+ - uses: pnpm/action-setup@v4
16
+ with:
17
+ version: latest
18
+
19
+ - uses: actions/setup-node@v6
20
+ with:
21
+ node-version: 24
22
+ cache: pnpm
23
+
24
+ - name: Install dependencies
25
+ run: pnpm install --frozen-lockfile
26
+
27
+ - name: Lint & format check
28
+ run: pnpm biome check
29
+
30
+ - name: Typecheck
31
+ run: pnpm typecheck
32
+
33
+ - name: Test
34
+ run: pnpm test
35
+
36
+ - name: Build
37
+ run: pnpm build
@@ -0,0 +1,41 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ release:
10
+ name: Semantic Release
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: write
14
+ issues: write
15
+ pull-requests: write
16
+ id-token: write
17
+ steps:
18
+ - uses: actions/checkout@v6
19
+ with:
20
+ fetch-depth: 0
21
+
22
+ - uses: pnpm/action-setup@v4
23
+ with:
24
+ version: latest
25
+
26
+ - uses: actions/setup-node@v6
27
+ with:
28
+ node-version: 24
29
+ cache: pnpm
30
+
31
+ - name: Install dependencies
32
+ run: pnpm install --frozen-lockfile
33
+
34
+ - name: Build
35
+ run: pnpm build
36
+
37
+ - name: Release
38
+ run: pnpm exec semantic-release
39
+ env:
40
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,3 @@
1
+ pnpm check
2
+ pnpm typecheck
3
+ pnpm test
@@ -0,0 +1,27 @@
1
+ {
2
+ "branches": ["main"],
3
+ "plugins": [
4
+ "@semantic-release/commit-analyzer",
5
+ "@semantic-release/release-notes-generator",
6
+ "@semantic-release/changelog",
7
+ [
8
+ "@semantic-release/npm",
9
+ {
10
+ "pkgRoot": "."
11
+ }
12
+ ],
13
+ [
14
+ "@semantic-release/github",
15
+ {
16
+ "assets": [{ "path": "dist/**", "label": "Distribution" }]
17
+ }
18
+ ],
19
+ [
20
+ "@semantic-release/git",
21
+ {
22
+ "assets": ["CHANGELOG.md", "package.json"],
23
+ "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
24
+ }
25
+ ]
26
+ ]
27
+ }
package/CHANGELOG.md CHANGED
@@ -1,7 +1,14 @@
1
- # react-dpd-pickup-map
2
-
3
- ## 0.0.2
4
-
5
- ### Patch Changes
6
-
7
- - cef9f5e: Init release
1
+ # 1.0.0 (2026-03-12)
2
+
3
+
4
+ ### Features
5
+
6
+ * Refactored `ReactDPDPickupMap` to use stable refs for callbacks, improving re-render behavior ([7d7988d](https://github.com/Imunal/react-dpd-pickup-map/commit/7d7988d508f483e0a58bf969e311ce926b084072))
7
+
8
+ # react-dpd-pickup-map
9
+
10
+ ## 0.0.2
11
+
12
+ ### Patch Changes
13
+
14
+ - cef9f5e: Init release
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Juliusz Kowalewski
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Juliusz Kowalewski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,56 +1,56 @@
1
- # react-dpd-pickup-map
2
-
3
- React component for implementing a DPD Pickup Map
4
-
5
- ## Installation
6
-
7
- Install react-dpd-pickup-map with npm
8
-
9
- ```bash
10
- npm install react-dpd-pickup-map
11
- ```
12
-
13
- ## Usage/Examples
14
-
15
- ```typescript
16
- import ReactDPDPickupMap from 'react-dpd-pickup-map'
17
-
18
- function App() {
19
- return <ReactDPDPickupMap
20
- authKey='YOUR_AUTH_KEY' //<- Your own auth key for pudofinder.dpd.com.pl
21
- lang='pl' //<- Defaults to: pl
22
- country='PL' //<- Defaults to: PL
23
- services={{
24
- openSaturdays=true
25
- openSundays=true
26
- }}
27
- />
28
- }
29
- ```
30
-
31
- ## Available services
32
-
33
- | Parameter | Type | Default | Description |
34
- | :------------------- | :-------- | :------ | :--------------------------------------------- |
35
- | `openLate` | `boolean` | `false` | Points open Late |
36
- | `openSaturdays` | `boolean` | `false` | Points open in Saturdays |
37
- | `openSundays` | `boolean` | `false` | Points open in Sundays |
38
- | `disabledFriendly` | `boolean` | `false` | Points friendly for disabled people |
39
- | `parking` | `boolean` | `false` | Points with parking |
40
- | `directDelivery` | `boolean` | `false` | Direct delivery |
41
- | `directDeliveryCOD` | `boolean` | `false` | Direct delivery with cash on delivery |
42
- | `dropOffOnline` | `boolean` | `false` | Sending a paid shipment |
43
- | `dropOffOffline` | `boolean` | `false` | Points with on-site shipping + payment and BOD |
44
- | `swapParcel` | `boolean` | `false` | Points with return shipment |
45
- | `dpdFood` | `boolean` | `false` | Points with DPD Food |
46
- | `fittingRoom` | `boolean` | `false` | Points with fitting room |
47
- | `cardPayment` | `boolean` | `false` | Points with card payment |
48
- | `rod` | `boolean` | `false` | Point with return documents |
49
- | `dpdLQ` | `boolean` | `false` | DPD LG |
50
- | `digitalLabel` | `boolean` | `false` | Point with shipping without a label |
51
- | `swipBox` | `boolean` | `false` | Parcela machines |
52
- | `pointsWithServices` | `boolean` | `false` | Points with services |
53
-
54
- ## Authors
55
-
56
- - [@Imunal](https://github.com/Imunal)
1
+ # react-dpd-pickup-map
2
+
3
+ React component for implementing a DPD Pickup Map
4
+
5
+ ## Installation
6
+
7
+ Install react-dpd-pickup-map with npm
8
+
9
+ ```bash
10
+ npm install react-dpd-pickup-map
11
+ ```
12
+
13
+ ## Usage/Examples
14
+
15
+ ```typescript
16
+ import ReactDPDPickupMap from 'react-dpd-pickup-map'
17
+
18
+ function App() {
19
+ return <ReactDPDPickupMap
20
+ authKey='YOUR_AUTH_KEY' //<- Your own auth key for pudofinder.dpd.com.pl
21
+ lang='pl' //<- Defaults to: pl
22
+ country='PL' //<- Defaults to: PL
23
+ services={{
24
+ openSaturdays=true
25
+ openSundays=true
26
+ }}
27
+ />
28
+ }
29
+ ```
30
+
31
+ ## Available services
32
+
33
+ | Parameter | Type | Default | Description |
34
+ | :------------------- | :-------- | :------ | :--------------------------------------------- |
35
+ | `openLate` | `boolean` | `false` | Points open Late |
36
+ | `openSaturdays` | `boolean` | `false` | Points open in Saturdays |
37
+ | `openSundays` | `boolean` | `false` | Points open in Sundays |
38
+ | `disabledFriendly` | `boolean` | `false` | Points friendly for disabled people |
39
+ | `parking` | `boolean` | `false` | Points with parking |
40
+ | `directDelivery` | `boolean` | `false` | Direct delivery |
41
+ | `directDeliveryCOD` | `boolean` | `false` | Direct delivery with cash on delivery |
42
+ | `dropOffOnline` | `boolean` | `false` | Sending a paid shipment |
43
+ | `dropOffOffline` | `boolean` | `false` | Points with on-site shipping + payment and BOD |
44
+ | `swapParcel` | `boolean` | `false` | Points with return shipment |
45
+ | `dpdFood` | `boolean` | `false` | Points with DPD Food |
46
+ | `fittingRoom` | `boolean` | `false` | Points with fitting room |
47
+ | `cardPayment` | `boolean` | `false` | Points with card payment |
48
+ | `rod` | `boolean` | `false` | Point with return documents |
49
+ | `dpdLQ` | `boolean` | `false` | DPD LG |
50
+ | `digitalLabel` | `boolean` | `false` | Point with shipping without a label |
51
+ | `swipBox` | `boolean` | `false` | Parcela machines |
52
+ | `pointsWithServices` | `boolean` | `false` | Points with services |
53
+
54
+ ## Authors
55
+
56
+ - [@Imunal](https://github.com/Imunal)
package/biome.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.4.6/schema.json",
3
+ "vcs": {
4
+ "enabled": true,
5
+ "clientKind": "git",
6
+ "useIgnoreFile": true
7
+ },
8
+ "files": {
9
+ "includes": ["**", "!!**/dist"]
10
+ },
11
+ "formatter": {
12
+ "enabled": true,
13
+ "indentStyle": "tab"
14
+ },
15
+ "linter": {
16
+ "enabled": true,
17
+ "rules": {
18
+ "recommended": true
19
+ }
20
+ },
21
+ "javascript": {
22
+ "formatter": {
23
+ "quoteStyle": "double"
24
+ }
25
+ },
26
+ "assist": {
27
+ "enabled": true,
28
+ "actions": {
29
+ "source": {
30
+ "organizeImports": "on"
31
+ }
32
+ }
33
+ }
34
+ }
package/dist/index.d.mts CHANGED
@@ -1,31 +1,40 @@
1
1
  import React from 'react';
2
2
 
3
- interface IReactDPDPickupMap {
3
+ type DPDLang = "pl" | "de" | "se" | "fr";
4
+ type DPDCountry = "AT" | "BE" | "HR" | "CZ" | "DK" | "EE" | "FI" | "FR" | "ES" | "NL" | "LT" | "LV" | "DE" | "PT" | "SK" | "SE" | "HU" | "IT" | "PL";
5
+ interface DPDServices {
6
+ openLate?: boolean;
7
+ openSaturdays?: boolean;
8
+ openSundays?: boolean;
9
+ disabledFriendly?: boolean;
10
+ parking?: boolean;
11
+ directDelivery?: boolean;
12
+ directDeliveryCOD?: boolean;
13
+ dropOffOnline?: boolean;
14
+ dropOffOffline?: boolean;
15
+ swapParcel?: boolean;
16
+ dpdFood?: boolean;
17
+ fittingRoom?: boolean;
18
+ cardPayment?: boolean;
19
+ rod?: boolean;
20
+ dpdLQ?: boolean;
21
+ digitalLabel?: boolean;
22
+ swipBox?: boolean;
23
+ pointsWithServices?: boolean;
24
+ }
25
+ interface ReactDPDPickupMapProps {
4
26
  authKey: string;
5
27
  onPointSelect: (pointID: string) => void;
6
- lang: "pl" | "de" | "se" | "fr";
7
- country: "AT" | "BE" | "HR" | "CZ" | "DK" | "EE" | "FI" | "FR" | "ES" | "NL" | "LT" | "LV" | "DE" | "PT" | "SK" | "SE" | "HU" | "IT" | "PL";
8
- services?: {
9
- openLate?: boolean;
10
- openSaturdays?: boolean;
11
- openSundays?: boolean;
12
- disabledFriendly?: boolean;
13
- parking?: boolean;
14
- directDelivery?: boolean;
15
- directDeliveryCOD?: boolean;
16
- dropOffOnline?: boolean;
17
- dropOffOffline?: boolean;
18
- swapParcel?: boolean;
19
- dpdFood?: boolean;
20
- fittingRoom?: boolean;
21
- cardPayment?: boolean;
22
- rod?: boolean;
23
- dpdLQ?: boolean;
24
- digitalLabel?: boolean;
25
- swipBox?: boolean;
26
- pointsWithServices?: boolean;
27
- };
28
+ lang?: DPDLang;
29
+ country?: DPDCountry;
30
+ services?: DPDServices;
31
+ }
32
+
33
+ declare global {
34
+ interface Window {
35
+ pointSelected: (pointID: string) => void;
36
+ }
28
37
  }
29
- declare const ReactDPDPickupMap: ({ authKey, onPointSelect, lang, country, services, }: IReactDPDPickupMap) => React.JSX.Element;
38
+ declare const ReactDPDPickupMap: ({ authKey, onPointSelect, lang, country, services, }: ReactDPDPickupMapProps) => React.JSX.Element;
30
39
 
31
- export { ReactDPDPickupMap };
40
+ export { type DPDCountry, type DPDLang, type DPDServices, ReactDPDPickupMap, type ReactDPDPickupMapProps };
package/dist/index.d.ts CHANGED
@@ -1,31 +1,40 @@
1
1
  import React from 'react';
2
2
 
3
- interface IReactDPDPickupMap {
3
+ type DPDLang = "pl" | "de" | "se" | "fr";
4
+ type DPDCountry = "AT" | "BE" | "HR" | "CZ" | "DK" | "EE" | "FI" | "FR" | "ES" | "NL" | "LT" | "LV" | "DE" | "PT" | "SK" | "SE" | "HU" | "IT" | "PL";
5
+ interface DPDServices {
6
+ openLate?: boolean;
7
+ openSaturdays?: boolean;
8
+ openSundays?: boolean;
9
+ disabledFriendly?: boolean;
10
+ parking?: boolean;
11
+ directDelivery?: boolean;
12
+ directDeliveryCOD?: boolean;
13
+ dropOffOnline?: boolean;
14
+ dropOffOffline?: boolean;
15
+ swapParcel?: boolean;
16
+ dpdFood?: boolean;
17
+ fittingRoom?: boolean;
18
+ cardPayment?: boolean;
19
+ rod?: boolean;
20
+ dpdLQ?: boolean;
21
+ digitalLabel?: boolean;
22
+ swipBox?: boolean;
23
+ pointsWithServices?: boolean;
24
+ }
25
+ interface ReactDPDPickupMapProps {
4
26
  authKey: string;
5
27
  onPointSelect: (pointID: string) => void;
6
- lang: "pl" | "de" | "se" | "fr";
7
- country: "AT" | "BE" | "HR" | "CZ" | "DK" | "EE" | "FI" | "FR" | "ES" | "NL" | "LT" | "LV" | "DE" | "PT" | "SK" | "SE" | "HU" | "IT" | "PL";
8
- services?: {
9
- openLate?: boolean;
10
- openSaturdays?: boolean;
11
- openSundays?: boolean;
12
- disabledFriendly?: boolean;
13
- parking?: boolean;
14
- directDelivery?: boolean;
15
- directDeliveryCOD?: boolean;
16
- dropOffOnline?: boolean;
17
- dropOffOffline?: boolean;
18
- swapParcel?: boolean;
19
- dpdFood?: boolean;
20
- fittingRoom?: boolean;
21
- cardPayment?: boolean;
22
- rod?: boolean;
23
- dpdLQ?: boolean;
24
- digitalLabel?: boolean;
25
- swipBox?: boolean;
26
- pointsWithServices?: boolean;
27
- };
28
+ lang?: DPDLang;
29
+ country?: DPDCountry;
30
+ services?: DPDServices;
31
+ }
32
+
33
+ declare global {
34
+ interface Window {
35
+ pointSelected: (pointID: string) => void;
36
+ }
28
37
  }
29
- declare const ReactDPDPickupMap: ({ authKey, onPointSelect, lang, country, services, }: IReactDPDPickupMap) => React.JSX.Element;
38
+ declare const ReactDPDPickupMap: ({ authKey, onPointSelect, lang, country, services, }: ReactDPDPickupMapProps) => React.JSX.Element;
30
39
 
31
- export { ReactDPDPickupMap };
40
+ export { type DPDCountry, type DPDLang, type DPDServices, ReactDPDPickupMap, type ReactDPDPickupMapProps };
package/dist/index.js CHANGED
@@ -29,11 +29,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
30
 
31
31
  // src/index.tsx
32
- var src_exports = {};
33
- __export(src_exports, {
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
34
  ReactDPDPickupMap: () => ReactDPDPickupMap
35
35
  });
36
- module.exports = __toCommonJS(src_exports);
36
+ module.exports = __toCommonJS(index_exports);
37
37
  var import_react = __toESM(require("react"));
38
38
  var boolToInt = (value) => value ? "1" : "0";
39
39
  var ReactDPDPickupMap = ({
@@ -43,46 +43,52 @@ var ReactDPDPickupMap = ({
43
43
  country = "PL",
44
44
  services = {}
45
45
  }) => {
46
+ const onPointSelectRef = (0, import_react.useRef)(onPointSelect);
46
47
  (0, import_react.useEffect)(() => {
48
+ onPointSelectRef.current = onPointSelect;
49
+ }, [onPointSelect]);
50
+ (0, import_react.useEffect)(() => {
51
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
47
52
  const container = document.getElementById("dpd-widget-container");
48
- if (!container)
49
- return;
50
- window.pointSelected = (pointID) => onPointSelect(pointID);
53
+ if (!container) return;
54
+ window.pointSelected = (pointID) => onPointSelectRef.current(pointID);
51
55
  const queryParams = new URLSearchParams({
52
56
  key: authKey,
53
57
  lang,
54
58
  country,
55
- //Map
56
- open_late: boolToInt(services.openLate || false),
57
- open_saturdays: boolToInt(services.openSaturdays || false),
58
- open_sundays: boolToInt(services.openSundays || false),
59
- disabled_friendly: boolToInt(services.disabledFriendly || false),
60
- parking: boolToInt(services.parking || false),
61
- direct_delivery: boolToInt(services.directDelivery || false),
62
- direct_delivery_cod: boolToInt(services.directDeliveryCOD || false),
63
- dropoff_online: boolToInt(services.dropOffOnline || false),
64
- dropoff_offline: boolToInt(services.dropOffOffline || false),
65
- swap_parcel: boolToInt(services.swapParcel || false),
66
- d_fresh: boolToInt(services.dpdFood || false),
67
- fitting_room: boolToInt(services.fittingRoom || false),
68
- card_payment: boolToInt(services.cardPayment || false),
69
- rod: boolToInt(services.rod || false),
70
- dpd_lq: boolToInt(services.dpdLQ || false),
71
- digital_label: boolToInt(services.digitalLabel || false),
72
- swip_box: boolToInt(services.swipBox || false),
73
- points_with_services: boolToInt(services.pointsWithServices || false)
59
+ open_late: boolToInt((_a = services.openLate) != null ? _a : false),
60
+ open_saturdays: boolToInt((_b = services.openSaturdays) != null ? _b : false),
61
+ open_sundays: boolToInt((_c = services.openSundays) != null ? _c : false),
62
+ disabled_friendly: boolToInt((_d = services.disabledFriendly) != null ? _d : false),
63
+ parking: boolToInt((_e = services.parking) != null ? _e : false),
64
+ direct_delivery: boolToInt((_f = services.directDelivery) != null ? _f : false),
65
+ direct_delivery_cod: boolToInt((_g = services.directDeliveryCOD) != null ? _g : false),
66
+ dropoff_online: boolToInt((_h = services.dropOffOnline) != null ? _h : false),
67
+ dropoff_offline: boolToInt((_i = services.dropOffOffline) != null ? _i : false),
68
+ swap_parcel: boolToInt((_j = services.swapParcel) != null ? _j : false),
69
+ d_fresh: boolToInt((_k = services.dpdFood) != null ? _k : false),
70
+ fitting_room: boolToInt((_l = services.fittingRoom) != null ? _l : false),
71
+ card_payment: boolToInt((_m = services.cardPayment) != null ? _m : false),
72
+ rod: boolToInt((_n = services.rod) != null ? _n : false),
73
+ dpd_lq: boolToInt((_o = services.dpdLQ) != null ? _o : false),
74
+ digital_label: boolToInt((_p = services.digitalLabel) != null ? _p : false),
75
+ swip_box: boolToInt((_q = services.swipBox) != null ? _q : false),
76
+ points_with_services: boolToInt((_r = services.pointsWithServices) != null ? _r : false)
74
77
  });
75
78
  const script = document.createElement("script");
76
79
  script.id = "dpd-widget";
77
80
  script.src = `//pudofinder.dpd.com.pl/source/dpd_widget.js?${queryParams}`;
78
81
  script.async = true;
79
- document.body.appendChild(script);
82
+ script.onerror = () => {
83
+ console.error("[react-dpd-pickup-map] Failed to load DPD widget script.");
84
+ };
85
+ container.appendChild(script);
80
86
  return () => {
81
- document.body.removeChild(script);
87
+ container.removeChild(script);
82
88
  delete window.pointSelected;
83
89
  };
84
- }, [authKey, onPointSelect, lang, country, services]);
85
- return /* @__PURE__ */ import_react.default.createElement("div", { id: "dpd-widget-container" }, /* @__PURE__ */ import_react.default.createElement("script", { id: "dpd-widget" }));
90
+ }, [authKey, lang, country, services]);
91
+ return /* @__PURE__ */ import_react.default.createElement("div", { id: "dpd-widget-container" });
86
92
  };
87
93
  // Annotate the CommonJS export names for ESM import in node:
88
94
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  // src/index.tsx
4
- import React, { useEffect } from "react";
4
+ import React, { useEffect, useRef } from "react";
5
5
  var boolToInt = (value) => value ? "1" : "0";
6
6
  var ReactDPDPickupMap = ({
7
7
  authKey,
@@ -10,46 +10,52 @@ var ReactDPDPickupMap = ({
10
10
  country = "PL",
11
11
  services = {}
12
12
  }) => {
13
+ const onPointSelectRef = useRef(onPointSelect);
13
14
  useEffect(() => {
15
+ onPointSelectRef.current = onPointSelect;
16
+ }, [onPointSelect]);
17
+ useEffect(() => {
18
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
14
19
  const container = document.getElementById("dpd-widget-container");
15
- if (!container)
16
- return;
17
- window.pointSelected = (pointID) => onPointSelect(pointID);
20
+ if (!container) return;
21
+ window.pointSelected = (pointID) => onPointSelectRef.current(pointID);
18
22
  const queryParams = new URLSearchParams({
19
23
  key: authKey,
20
24
  lang,
21
25
  country,
22
- //Map
23
- open_late: boolToInt(services.openLate || false),
24
- open_saturdays: boolToInt(services.openSaturdays || false),
25
- open_sundays: boolToInt(services.openSundays || false),
26
- disabled_friendly: boolToInt(services.disabledFriendly || false),
27
- parking: boolToInt(services.parking || false),
28
- direct_delivery: boolToInt(services.directDelivery || false),
29
- direct_delivery_cod: boolToInt(services.directDeliveryCOD || false),
30
- dropoff_online: boolToInt(services.dropOffOnline || false),
31
- dropoff_offline: boolToInt(services.dropOffOffline || false),
32
- swap_parcel: boolToInt(services.swapParcel || false),
33
- d_fresh: boolToInt(services.dpdFood || false),
34
- fitting_room: boolToInt(services.fittingRoom || false),
35
- card_payment: boolToInt(services.cardPayment || false),
36
- rod: boolToInt(services.rod || false),
37
- dpd_lq: boolToInt(services.dpdLQ || false),
38
- digital_label: boolToInt(services.digitalLabel || false),
39
- swip_box: boolToInt(services.swipBox || false),
40
- points_with_services: boolToInt(services.pointsWithServices || false)
26
+ open_late: boolToInt((_a = services.openLate) != null ? _a : false),
27
+ open_saturdays: boolToInt((_b = services.openSaturdays) != null ? _b : false),
28
+ open_sundays: boolToInt((_c = services.openSundays) != null ? _c : false),
29
+ disabled_friendly: boolToInt((_d = services.disabledFriendly) != null ? _d : false),
30
+ parking: boolToInt((_e = services.parking) != null ? _e : false),
31
+ direct_delivery: boolToInt((_f = services.directDelivery) != null ? _f : false),
32
+ direct_delivery_cod: boolToInt((_g = services.directDeliveryCOD) != null ? _g : false),
33
+ dropoff_online: boolToInt((_h = services.dropOffOnline) != null ? _h : false),
34
+ dropoff_offline: boolToInt((_i = services.dropOffOffline) != null ? _i : false),
35
+ swap_parcel: boolToInt((_j = services.swapParcel) != null ? _j : false),
36
+ d_fresh: boolToInt((_k = services.dpdFood) != null ? _k : false),
37
+ fitting_room: boolToInt((_l = services.fittingRoom) != null ? _l : false),
38
+ card_payment: boolToInt((_m = services.cardPayment) != null ? _m : false),
39
+ rod: boolToInt((_n = services.rod) != null ? _n : false),
40
+ dpd_lq: boolToInt((_o = services.dpdLQ) != null ? _o : false),
41
+ digital_label: boolToInt((_p = services.digitalLabel) != null ? _p : false),
42
+ swip_box: boolToInt((_q = services.swipBox) != null ? _q : false),
43
+ points_with_services: boolToInt((_r = services.pointsWithServices) != null ? _r : false)
41
44
  });
42
45
  const script = document.createElement("script");
43
46
  script.id = "dpd-widget";
44
47
  script.src = `//pudofinder.dpd.com.pl/source/dpd_widget.js?${queryParams}`;
45
48
  script.async = true;
46
- document.body.appendChild(script);
49
+ script.onerror = () => {
50
+ console.error("[react-dpd-pickup-map] Failed to load DPD widget script.");
51
+ };
52
+ container.appendChild(script);
47
53
  return () => {
48
- document.body.removeChild(script);
54
+ container.removeChild(script);
49
55
  delete window.pointSelected;
50
56
  };
51
- }, [authKey, onPointSelect, lang, country, services]);
52
- return /* @__PURE__ */ React.createElement("div", { id: "dpd-widget-container" }, /* @__PURE__ */ React.createElement("script", { id: "dpd-widget" }));
57
+ }, [authKey, lang, country, services]);
58
+ return /* @__PURE__ */ React.createElement("div", { id: "dpd-widget-container" });
53
59
  };
54
60
  export {
55
61
  ReactDPDPickupMap
package/package.json CHANGED
@@ -1,40 +1,61 @@
1
1
  {
2
- "name": "react-dpd-pickup-map",
3
- "version": "0.0.1",
4
- "description": "React component for DPD Pickup Map",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
8
- "keywords": [
9
- "dpd",
10
- "react",
11
- "dpd pickup",
12
- "dpd pickup map",
13
- "react dpd"
14
- ],
15
- "author": "Juliusz Kowalewski @Imunal",
16
- "license": "MIT",
17
- "bugs": {
18
- "url": "https://github.com/Imunal/react-dpd-pickup-map/issues"
19
- },
20
- "homepage": "https://github.com/Imunal/react-dpd-pickup-map",
21
- "repository": {
22
- "type": "github",
23
- "url": "https://github.com/Imunal/react-dpd-pickup-map"
24
- },
25
- "devDependencies": {
26
- "@types/react": "^18.2.72",
27
- "@types/react-dom": "^18.2.22",
28
- "tsup": "^8.0.2",
29
- "typescript": "^5.4.3"
30
- },
31
- "dependencies": {
32
- "react": "^18.2.0",
33
- "react-dom": "^18.2.0"
34
- },
35
- "scripts": {
36
- "dev": "tsup src/index.tsx --watch",
37
- "build": "tsup src/index.tsx --format cjs,esm --dts",
38
- "lint": "tsc"
39
- }
40
- }
2
+ "name": "react-dpd-pickup-map",
3
+ "version": "1.0.0",
4
+ "description": "React component for DPD Pickup Map",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "keywords": [
9
+ "dpd",
10
+ "react",
11
+ "dpd pickup",
12
+ "dpd pickup map",
13
+ "react dpd"
14
+ ],
15
+ "author": "Juliusz Kowalewski @Imunal",
16
+ "license": "MIT",
17
+ "bugs": {
18
+ "url": "https://github.com/Imunal/react-dpd-pickup-map/issues"
19
+ },
20
+ "homepage": "https://github.com/Imunal/react-dpd-pickup-map",
21
+ "repository": {
22
+ "type": "github",
23
+ "url": "https://github.com/Imunal/react-dpd-pickup-map"
24
+ },
25
+ "scripts": {
26
+ "dev": "tsup src/index.tsx --watch",
27
+ "build": "tsup src/index.tsx --format cjs,esm --dts",
28
+ "lint": "biome lint --write",
29
+ "format": "biome format --write",
30
+ "check": "biome check --write",
31
+ "typecheck": "tsc --noEmit",
32
+ "test": "vitest run",
33
+ "test:watch": "vitest",
34
+ "prepare": "husky"
35
+ },
36
+ "peerDependencies": {
37
+ "react": "^18.0.0 || ^19.0.0",
38
+ "react-dom": "^18.0.0 || ^19.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "@biomejs/biome": "2.4.6",
42
+ "@semantic-release/changelog": "^6.0.3",
43
+ "@semantic-release/commit-analyzer": "^13.0.1",
44
+ "@semantic-release/git": "^10.0.1",
45
+ "@semantic-release/github": "^12.0.6",
46
+ "@semantic-release/npm": "^13.1.5",
47
+ "@semantic-release/release-notes-generator": "^14.1.0",
48
+ "@testing-library/jest-dom": "^6.9.1",
49
+ "@testing-library/react": "^16.3.2",
50
+ "@types/react": "^19.2.14",
51
+ "@types/react-dom": "^19.2.3",
52
+ "husky": "^9.1.7",
53
+ "jsdom": "^28.1.0",
54
+ "react": "^19",
55
+ "react-dom": "^19",
56
+ "semantic-release": "^25.0.3",
57
+ "tsup": "^8.5.1",
58
+ "typescript": "^5.9.3",
59
+ "vitest": "^4.1.0"
60
+ }
61
+ }
@@ -0,0 +1,2 @@
1
+ onlyBuiltDependencies:
2
+ - esbuild
@@ -0,0 +1,156 @@
1
+ import { cleanup, render } from "@testing-library/react";
2
+ import React from "react";
3
+ import { afterEach, describe, expect, it, vi } from "vitest";
4
+ import { ReactDPDPickupMap } from "../src";
5
+
6
+ afterEach(() => {
7
+ cleanup();
8
+ delete (window as any).pointSelected;
9
+ });
10
+
11
+ describe("ReactDPDPickupMap", () => {
12
+ describe("rendering", () => {
13
+ it("renders the widget container div", () => {
14
+ // given
15
+ // when
16
+ render(<ReactDPDPickupMap authKey="test-key" onPointSelect={() => {}} />);
17
+
18
+ // then
19
+ expect(
20
+ document.getElementById("dpd-widget-container"),
21
+ ).toBeInTheDocument();
22
+ });
23
+ });
24
+
25
+ describe("script injection", () => {
26
+ it("appends a script tag inside the container on mount", () => {
27
+ // given
28
+ // when
29
+ render(<ReactDPDPickupMap authKey="test-key" onPointSelect={() => {}} />);
30
+
31
+ // then
32
+ const widgetContainer = document.getElementById("dpd-widget-container");
33
+ expect(
34
+ widgetContainer?.querySelector("script#dpd-widget"),
35
+ ).toBeInTheDocument();
36
+ });
37
+
38
+ it("builds the correct script src with authKey, lang and country", () => {
39
+ // given
40
+ // when
41
+ render(
42
+ <ReactDPDPickupMap
43
+ authKey="my-auth-key"
44
+ onPointSelect={() => {}}
45
+ lang="de"
46
+ country="DE"
47
+ />,
48
+ );
49
+
50
+ // then
51
+ const script = document
52
+ .getElementById("dpd-widget-container")
53
+ ?.querySelector<HTMLScriptElement>("script#dpd-widget");
54
+
55
+ expect(script?.src).toContain("key=my-auth-key");
56
+ expect(script?.src).toContain("lang=de");
57
+ expect(script?.src).toContain("country=DE");
58
+ });
59
+
60
+ it("encodes enabled service flags as 1 and disabled as 0 in the script src", () => {
61
+ // given
62
+ // when
63
+ render(
64
+ <ReactDPDPickupMap
65
+ authKey="key"
66
+ onPointSelect={() => {}}
67
+ services={{ openLate: true, parking: false }}
68
+ />,
69
+ );
70
+
71
+ // then
72
+ const script = document
73
+ .getElementById("dpd-widget-container")
74
+ ?.querySelector<HTMLScriptElement>("script#dpd-widget");
75
+
76
+ expect(script?.src).toContain("open_late=1");
77
+ expect(script?.src).toContain("parking=0");
78
+ });
79
+
80
+ it("re-injects the script when authKey changes", () => {
81
+ // given
82
+ const { rerender } = render(
83
+ <ReactDPDPickupMap authKey="key-v1" onPointSelect={() => {}} />,
84
+ );
85
+
86
+ // when
87
+ rerender(<ReactDPDPickupMap authKey="key-v2" onPointSelect={() => {}} />);
88
+
89
+ // then
90
+ const script = document
91
+ .getElementById("dpd-widget-container")
92
+ ?.querySelector<HTMLScriptElement>("script#dpd-widget");
93
+
94
+ expect(script?.src).toContain("key=key-v2");
95
+ });
96
+ });
97
+
98
+ describe("callback bridge", () => {
99
+ it("sets window.pointSelected on mount", () => {
100
+ // given
101
+ // when
102
+ render(<ReactDPDPickupMap authKey="key" onPointSelect={() => {}} />);
103
+
104
+ // then
105
+ expect(typeof window.pointSelected).toBe("function");
106
+ });
107
+
108
+ it("calls onPointSelect when the DPD widget invokes window.pointSelected", () => {
109
+ // given
110
+ const onPointSelect = vi.fn();
111
+ render(<ReactDPDPickupMap authKey="key" onPointSelect={onPointSelect} />);
112
+
113
+ // when
114
+ window.pointSelected("POINT123");
115
+
116
+ // then
117
+ expect(onPointSelect).toHaveBeenCalledOnce();
118
+ expect(onPointSelect).toHaveBeenCalledWith("POINT123");
119
+ });
120
+
121
+ it("always calls the latest onPointSelect without re-injecting the script", () => {
122
+ // given
123
+ const first = vi.fn();
124
+ const second = vi.fn();
125
+ const { rerender } = render(
126
+ <ReactDPDPickupMap authKey="key" onPointSelect={first} />,
127
+ );
128
+
129
+ // when
130
+ rerender(<ReactDPDPickupMap authKey="key" onPointSelect={second} />);
131
+ window.pointSelected("POINT456");
132
+
133
+ // then
134
+ expect(first).not.toHaveBeenCalled();
135
+ expect(second).toHaveBeenCalledWith("POINT456");
136
+ });
137
+ });
138
+
139
+ describe("cleanup", () => {
140
+ it("removes the script tag and deletes window.pointSelected on unmount", () => {
141
+ // given
142
+ const { unmount } = render(
143
+ <ReactDPDPickupMap authKey="key" onPointSelect={() => {}} />,
144
+ );
145
+
146
+ // when
147
+ unmount();
148
+
149
+ // then
150
+ expect(
151
+ document.getElementById("dpd-widget-container"),
152
+ ).not.toBeInTheDocument();
153
+ expect(window.pointSelected).toBeUndefined();
154
+ });
155
+ });
156
+ });
@@ -0,0 +1 @@
1
+ import "@testing-library/jest-dom";
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: "jsdom",
7
+ setupFiles: ["./tests/test-setup.ts"],
8
+ },
9
+ });