react-bkoi-gl 1.0.7 → 2.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.
Files changed (167) hide show
  1. package/README.md +163 -18
  2. package/dist/components/attribution-control.d.ts +4 -6
  3. package/dist/components/attribution-control.js +6 -5
  4. package/dist/components/attribution-control.js.map +1 -1
  5. package/dist/components/fullscreen-control.d.ts +4 -6
  6. package/dist/components/fullscreen-control.js +4 -4
  7. package/dist/components/fullscreen-control.js.map +1 -1
  8. package/dist/components/geolocate-control.d.ts +10 -26
  9. package/dist/components/geolocate-control.js +11 -11
  10. package/dist/components/geolocate-control.js.map +1 -1
  11. package/dist/components/layer.d.ts +7 -6
  12. package/dist/components/layer.js +8 -9
  13. package/dist/components/layer.js.map +1 -1
  14. package/dist/components/logo-control.d.ts +9 -0
  15. package/dist/components/logo-control.js +28 -0
  16. package/dist/components/logo-control.js.map +1 -0
  17. package/dist/components/map.d.ts +20 -16
  18. package/dist/components/map.js +38 -32
  19. package/dist/components/map.js.map +1 -1
  20. package/dist/components/marker.d.ts +10 -33
  21. package/dist/components/marker.js +22 -15
  22. package/dist/components/marker.js.map +1 -1
  23. package/dist/components/navigation-control.d.ts +4 -6
  24. package/dist/components/navigation-control.js +4 -4
  25. package/dist/components/navigation-control.js.map +1 -1
  26. package/dist/components/popup.d.ts +7 -25
  27. package/dist/components/popup.js +17 -28
  28. package/dist/components/popup.js.map +1 -1
  29. package/dist/components/scale-control.d.ts +4 -6
  30. package/dist/components/scale-control.js +4 -4
  31. package/dist/components/scale-control.js.map +1 -1
  32. package/dist/components/source.d.ts +3 -4
  33. package/dist/components/source.js +20 -22
  34. package/dist/components/source.js.map +1 -1
  35. package/dist/components/terrain-control.d.ts +10 -0
  36. package/dist/components/terrain-control.js +19 -0
  37. package/dist/components/terrain-control.js.map +1 -0
  38. package/dist/components/use-control.d.ts +6 -6
  39. package/dist/components/use-control.js +4 -5
  40. package/dist/components/use-control.js.map +1 -1
  41. package/dist/components/use-map.d.ts +8 -9
  42. package/dist/components/use-map.js +5 -5
  43. package/dist/components/use-map.js.map +1 -1
  44. package/dist/exports-maplibre-gl.d.ts +33 -0
  45. package/dist/exports-maplibre-gl.js +21 -0
  46. package/dist/exports-maplibre-gl.js.map +1 -0
  47. package/dist/index.cjs +590 -681
  48. package/dist/index.d.ts +2 -2
  49. package/dist/index.js +2 -2
  50. package/dist/index.js.map +1 -1
  51. package/dist/{mapbox → maplibre}/create-ref.d.ts +6 -6
  52. package/dist/maplibre/create-ref.js +30 -0
  53. package/dist/maplibre/create-ref.js.map +1 -0
  54. package/dist/maplibre/maplibre.d.ts +81 -0
  55. package/dist/maplibre/maplibre.js +387 -0
  56. package/dist/maplibre/maplibre.js.map +1 -0
  57. package/dist/styles/index.d.ts +4 -0
  58. package/dist/styles/react-bkoi-gl.css +1 -1
  59. package/dist/styles.d.js +2 -0
  60. package/dist/styles.d.js.map +1 -0
  61. package/dist/tsconfig.build.tsbuildinfo +1 -0
  62. package/dist/types/common.d.ts +2 -60
  63. package/dist/types/common.js.map +1 -1
  64. package/dist/types/events.d.ts +64 -23
  65. package/dist/types/events.js.map +1 -1
  66. package/dist/types/internal.d.ts +14 -0
  67. package/dist/types/internal.js +2 -0
  68. package/dist/types/internal.js.map +1 -0
  69. package/dist/types/lib.d.ts +16 -200
  70. package/dist/types/lib.js.map +1 -1
  71. package/dist/types/style-spec.d.ts +1 -0
  72. package/dist/types/style-spec.js +2 -0
  73. package/dist/types/style-spec.js.map +1 -0
  74. package/dist/utils/apply-react-style.d.ts +1 -1
  75. package/dist/utils/apply-react-style.js.map +1 -1
  76. package/dist/utils/compare-class-names.d.ts +2 -0
  77. package/dist/utils/compare-class-names.js +23 -0
  78. package/dist/utils/compare-class-names.js.map +1 -0
  79. package/dist/utils/deep-equal.d.ts +1 -1
  80. package/dist/utils/deep-equal.js +1 -1
  81. package/dist/utils/deep-equal.js.map +1 -1
  82. package/dist/utils/set-globals.d.ts +6 -8
  83. package/dist/utils/set-globals.js +22 -10
  84. package/dist/utils/set-globals.js.map +1 -1
  85. package/dist/utils/style-utils.d.ts +3 -2
  86. package/dist/utils/style-utils.js +4 -4
  87. package/dist/utils/style-utils.js.map +1 -1
  88. package/dist/utils/transform.d.ts +11 -19
  89. package/dist/utils/transform.js +13 -36
  90. package/dist/utils/transform.js.map +1 -1
  91. package/dist/utils/use-isomorphic-layout-effect.d.ts +1 -1
  92. package/dist/utils/use-isomorphic-layout-effect.js +2 -2
  93. package/dist/utils/use-isomorphic-layout-effect.js.map +1 -1
  94. package/package.json +42 -26
  95. package/src/components/attribution-control.ts +40 -16
  96. package/src/components/fullscreen-control.ts +40 -0
  97. package/src/components/geolocate-control.ts +45 -39
  98. package/src/components/layer.ts +37 -29
  99. package/src/components/logo-control.ts +44 -0
  100. package/src/components/map.tsx +86 -75
  101. package/src/components/marker.ts +141 -123
  102. package/src/components/navigation-control.ts +11 -12
  103. package/src/components/popup.ts +94 -97
  104. package/src/components/scale-control.ts +12 -14
  105. package/src/components/source.ts +58 -57
  106. package/src/components/terrain-control.ts +29 -0
  107. package/src/components/use-control.ts +21 -17
  108. package/src/components/use-map.tsx +26 -24
  109. package/src/exports-maplibre-gl.ts +37 -0
  110. package/src/index.ts +3 -2
  111. package/src/maplibre/create-ref.ts +70 -0
  112. package/src/maplibre/maplibre.ts +624 -0
  113. package/src/styles.d.ts +4 -0
  114. package/src/types/common.ts +12 -72
  115. package/src/types/events.ts +102 -42
  116. package/src/types/internal.ts +26 -0
  117. package/src/types/lib.ts +65 -260
  118. package/src/types/style-spec.ts +34 -0
  119. package/src/utils/apply-react-style.ts +7 -3
  120. package/src/utils/compare-class-names.ts +29 -0
  121. package/src/utils/deep-equal.ts +2 -2
  122. package/src/utils/set-globals.ts +22 -28
  123. package/src/utils/style-utils.ts +18 -9
  124. package/src/utils/transform.ts +32 -60
  125. package/src/utils/use-isomorphic-layout-effect.ts +3 -2
  126. package/bkoi-gl/package.json +0 -6
  127. package/dist/exports-bkoi-gl.cjs +0 -1512
  128. package/dist/exports-bkoi-gl.d.ts +0 -89
  129. package/dist/exports-bkoi-gl.js +0 -36
  130. package/dist/exports-bkoi-gl.js.map +0 -1
  131. package/dist/exports-mapbox.d.ts +0 -139
  132. package/dist/exports-mapbox.js +0 -36
  133. package/dist/exports-mapbox.js.map +0 -1
  134. package/dist/mapbox/create-ref.js +0 -64
  135. package/dist/mapbox/create-ref.js.map +0 -1
  136. package/dist/mapbox/mapbox.d.ts +0 -81
  137. package/dist/mapbox/mapbox.js +0 -476
  138. package/dist/mapbox/mapbox.js.map +0 -1
  139. package/dist/types/events-bkoi-gl.d.ts +0 -49
  140. package/dist/types/events-bkoi-gl.js +0 -2
  141. package/dist/types/events-bkoi-gl.js.map +0 -1
  142. package/dist/types/events-mapbox.d.ts +0 -49
  143. package/dist/types/events-mapbox.js +0 -2
  144. package/dist/types/events-mapbox.js.map +0 -1
  145. package/dist/types/index.d.ts +0 -70
  146. package/dist/types/index.js +0 -5
  147. package/dist/types/index.js.map +0 -1
  148. package/dist/types/public.d.ts +0 -2
  149. package/dist/types/public.js +0 -2
  150. package/dist/types/public.js.map +0 -1
  151. package/dist/types/style-spec-bkoi-gl.d.ts +0 -9
  152. package/dist/types/style-spec-bkoi-gl.js +0 -2
  153. package/dist/types/style-spec-bkoi-gl.js.map +0 -1
  154. package/dist/types/style-spec-mapbox.d.ts +0 -7
  155. package/dist/types/style-spec-mapbox.js +0 -2
  156. package/dist/types/style-spec-mapbox.js.map +0 -1
  157. package/src/components/fullscreen-control.tsx +0 -37
  158. package/src/exports-bkoi-gl.ts +0 -156
  159. package/src/exports-mapbox.ts +0 -159
  160. package/src/mapbox/create-ref.ts +0 -118
  161. package/src/mapbox/mapbox.ts +0 -742
  162. package/src/types/events-bkoi-gl.ts +0 -78
  163. package/src/types/events-mapbox.ts +0 -76
  164. package/src/types/index.ts +0 -93
  165. package/src/types/public.ts +0 -9
  166. package/src/types/style-spec-bkoi-gl.ts +0 -81
  167. package/src/types/style-spec-mapbox.ts +0 -80
@@ -1 +1 @@
1
- {"version":3,"file":"transform.js","names":["deepEqual","cloneTransform","tr","newTransform","clone","pixelsToGLUnits","syncProjection","src","dest","getProjection","srcProjection","destProjection","setProjection","transformToViewState","longitude","center","lng","latitude","lat","zoom","pitch","bearing","padding","applyViewStateToTransform","props","v","viewState","changed","isPaddingEqual","constructor"],"sources":["../../src/utils/transform.ts"],"sourcesContent":["import type {MapboxProps} from '../mapbox/mapbox';\nimport type {Transform, ViewState} from '../types';\nimport {deepEqual} from './deep-equal';\n\n/**\n * Make a copy of a transform\n * @param tr\n */\nexport function cloneTransform(tr: Transform): Transform {\n const newTransform = tr.clone();\n // Work around mapbox bug - this value is not assigned in clone(), only in resize()\n newTransform.pixelsToGLUnits = tr.pixelsToGLUnits;\n return newTransform;\n}\n\n/**\n * Copy projection from one transform to another. This only applies to mapbox-gl transforms\n * @param src the transform to copy projection settings from\n * @param dest to transform to copy projection settings to\n */\nexport function syncProjection(src: Transform, dest: Transform): void {\n if (!src.getProjection) {\n return;\n }\n const srcProjection = src.getProjection();\n const destProjection = dest.getProjection();\n\n if (!deepEqual(srcProjection, destProjection)) {\n dest.setProjection(srcProjection);\n }\n}\n\n/**\n * Capture a transform's current state\n * @param transform\n * @returns descriptor of the view state\n */\nexport function transformToViewState(tr: Transform): ViewState {\n return {\n longitude: tr.center.lng,\n latitude: tr.center.lat,\n zoom: tr.zoom,\n pitch: tr.pitch,\n bearing: tr.bearing,\n padding: tr.padding\n };\n}\n\n/* eslint-disable complexity */\n/**\n * Mutate a transform to match the given view state\n * @param transform\n * @param viewState\n * @returns true if the transform has changed\n */\nexport function applyViewStateToTransform(tr: Transform, props: MapboxProps): boolean {\n const v: Partial<ViewState> = props.viewState || props;\n let changed = false;\n\n if ('zoom' in v) {\n const zoom = tr.zoom;\n tr.zoom = v.zoom;\n changed = changed || zoom !== tr.zoom;\n }\n if ('bearing' in v) {\n const bearing = tr.bearing;\n tr.bearing = v.bearing;\n changed = changed || bearing !== tr.bearing;\n }\n if ('pitch' in v) {\n const pitch = tr.pitch;\n tr.pitch = v.pitch;\n changed = changed || pitch !== tr.pitch;\n }\n if (v.padding && !tr.isPaddingEqual(v.padding)) {\n changed = true;\n tr.padding = v.padding;\n }\n if ('longitude' in v && 'latitude' in v) {\n const center = tr.center;\n // @ts-ignore\n tr.center = new center.constructor(v.longitude, v.latitude);\n changed = changed || center !== tr.center;\n }\n return changed;\n}\n"],"mappings":"SAEQA,SAAS;AAMjB,OAAO,SAASC,cAAcA,CAACC,EAAa,EAAa;EACvD,MAAMC,YAAY,GAAGD,EAAE,CAACE,KAAK,CAAC,CAAC;EAE/BD,YAAY,CAACE,eAAe,GAAGH,EAAE,CAACG,eAAe;EACjD,OAAOF,YAAY;AACrB;AAOA,OAAO,SAASG,cAAcA,CAACC,GAAc,EAAEC,IAAe,EAAQ;EACpE,IAAI,CAACD,GAAG,CAACE,aAAa,EAAE;IACtB;EACF;EACA,MAAMC,aAAa,GAAGH,GAAG,CAACE,aAAa,CAAC,CAAC;EACzC,MAAME,cAAc,GAAGH,IAAI,CAACC,aAAa,CAAC,CAAC;EAE3C,IAAI,CAACT,SAAS,CAACU,aAAa,EAAEC,cAAc,CAAC,EAAE;IAC7CH,IAAI,CAACI,aAAa,CAACF,aAAa,CAAC;EACnC;AACF;AAOA,OAAO,SAASG,oBAAoBA,CAACX,EAAa,EAAa;EAC7D,OAAO;IACLY,SAAS,EAAEZ,EAAE,CAACa,MAAM,CAACC,GAAG;IACxBC,QAAQ,EAAEf,EAAE,CAACa,MAAM,CAACG,GAAG;IACvBC,IAAI,EAAEjB,EAAE,CAACiB,IAAI;IACbC,KAAK,EAAElB,EAAE,CAACkB,KAAK;IACfC,OAAO,EAAEnB,EAAE,CAACmB,OAAO;IACnBC,OAAO,EAAEpB,EAAE,CAACoB;EACd,CAAC;AACH;AASA,OAAO,SAASC,yBAAyBA,CAACrB,EAAa,EAAEsB,KAAkB,EAAW;EACpF,MAAMC,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version":3,"file":"transform.js","names":["deepEqual","transformToViewState","tr","longitude","center","lng","latitude","lat","zoom","pitch","bearing","padding","applyViewStateToTransform","props","v","viewState","changes","LngLat","constructor"],"sources":["../../src/utils/transform.ts"],"sourcesContent":["import type { MaplibreProps } from \"../maplibre/maplibre\";\nimport type { ViewState } from \"../types/common\";\nimport type { TransformLike } from \"../types/internal\";\nimport { deepEqual } from \"./deep-equal\";\n\n/**\n * Capture a transform's current state\n * @param transform\n * @returns descriptor of the view state\n */\nexport function transformToViewState(tr: TransformLike): ViewState {\n return {\n longitude: tr.center.lng,\n latitude: tr.center.lat,\n zoom: tr.zoom,\n pitch: tr.pitch,\n bearing: tr.bearing,\n padding: tr.padding,\n };\n}\n\n/* eslint-disable complexity */\n/**\n * Applies requested view state to a transform\n * @returns an object containing detected changes\n */\nexport function applyViewStateToTransform(\n /** An object that describes Maplibre's camera state */\n tr: TransformLike,\n /** Props from Map component */\n props: MaplibreProps,\n): Partial<TransformLike> {\n const v: Partial<ViewState> = props.viewState || props;\n const changes: Partial<TransformLike> = {};\n\n if (\n \"longitude\" in v &&\n \"latitude\" in v &&\n (v.longitude !== tr.center.lng || v.latitude !== tr.center.lat)\n ) {\n const LngLat = tr.center.constructor;\n // @ts-expect-error we should not import LngLat class from maplibre-gl because we don't know the source of mapLib\n changes.center = new LngLat(v.longitude, v.latitude);\n }\n if (\"zoom\" in v && v.zoom !== tr.zoom) {\n changes.zoom = v.zoom;\n }\n if (\"bearing\" in v && v.bearing !== tr.bearing) {\n changes.bearing = v.bearing;\n }\n if (\"pitch\" in v && v.pitch !== tr.pitch) {\n changes.pitch = v.pitch;\n }\n if (v.padding && tr.padding && !deepEqual(v.padding, tr.padding)) {\n changes.padding = v.padding;\n }\n return changes;\n}\n"],"mappings":"SAGSA,SAAS;AAOlB,OAAO,SAASC,oBAAoBA,CAACC,EAAiB,EAAa;EACjE,OAAO;IACLC,SAAS,EAAED,EAAE,CAACE,MAAM,CAACC,GAAG;IACxBC,QAAQ,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AACc,CAAC,CAACH,OAAO,EAAET,EAAE,CAACS,OAAO,CAAC,EAAE;IAChEK,OAAO,CAACL,OAAO,GAAGG,CAAC,CAACH,OAAO;EAC7B;EACA,OAAOK,OAAO;AAChB","ignoreList":[]}
@@ -1,3 +1,3 @@
1
- import { useLayoutEffect } from 'react';
1
+ import { useLayoutEffect } from "react";
2
2
  declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
3
3
  export default useIsomorphicLayoutEffect;
@@ -1,4 +1,4 @@
1
- import { useEffect, useLayoutEffect } from 'react';
2
- const useIsomorphicLayoutEffect = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
1
+ import { useEffect, useLayoutEffect } from "react";
2
+ const useIsomorphicLayoutEffect = typeof document !== "undefined" ? useLayoutEffect : useEffect;
3
3
  export default useIsomorphicLayoutEffect;
4
4
  //# sourceMappingURL=use-isomorphic-layout-effect.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-isomorphic-layout-effect.js","names":["useEffect","useLayoutEffect","useIsomorphicLayoutEffect","document"],"sources":["../../src/utils/use-isomorphic-layout-effect.ts"],"sourcesContent":["// From https://github.com/streamich/react-use/blob/master/src/useIsomorphicLayoutEffect.ts\n// useLayoutEffect but does not trigger warning in server-side rendering\nimport {useEffect, useLayoutEffect} from 'react';\n\nconst useIsomorphicLayoutEffect = typeof document !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport default useIsomorphicLayoutEffect;\n"],"mappings":"AAEA,SAAQA,SAAS,EAAEC,eAAe,QAAO,OAAO;AAEhD,MAAMC,yBAAyB,GAAG,OAAOC,QAAQ,KAAK,WAAW,GAAGF,eAAe,GAAGD,SAAS;AAE/F,eAAeE,yBAAyB","ignoreList":[]}
1
+ {"version":3,"file":"use-isomorphic-layout-effect.js","names":["useEffect","useLayoutEffect","useIsomorphicLayoutEffect","document"],"sources":["../../src/utils/use-isomorphic-layout-effect.ts"],"sourcesContent":["// From https://github.com/streamich/react-use/blob/master/src/useIsomorphicLayoutEffect.ts\n// useLayoutEffect but does not trigger warning in server-side rendering\nimport { useEffect, useLayoutEffect } from \"react\";\n\nconst useIsomorphicLayoutEffect =\n typeof document !== \"undefined\" ? useLayoutEffect : useEffect;\n\nexport default useIsomorphicLayoutEffect;\n"],"mappings":"AAEA,SAASA,SAAS,EAAEC,eAAe,QAAQ,OAAO;AAElD,MAAMC,yBAAyB,GAC7B,OAAOC,QAAQ,KAAK,WAAW,GAAGF,eAAe,GAAGD,SAAS;AAE/D,eAAeE,yBAAyB","ignoreList":[]}
package/package.json CHANGED
@@ -1,51 +1,49 @@
1
1
  {
2
2
  "name": "react-bkoi-gl",
3
- "version": "1.0.7",
3
+ "version": "2.0.0",
4
+ "updatedAt": "12-05-2025 5:19:02 PM",
5
+ "engines": {
6
+ "node": ">=18.13.0"
7
+ },
4
8
  "description": "React components for Barikoi GL JS",
5
9
  "type": "module",
6
10
  "types": "dist/index.d.ts",
7
11
  "main": "dist/index.cjs",
8
12
  "module": "dist/index.js",
9
- "author": "barikoi",
10
- "readme": "README.md",
11
- "license": "MIT",
12
- "homepage": "https://docs.barikoi.com/docs/maps-api",
13
13
  "exports": {
14
14
  ".": {
15
15
  "types": "./dist/index.d.ts",
16
16
  "require": "./dist/index.cjs",
17
- "import": "./dist/index.js"
18
- },
19
- "./bkoi-gl": {
20
- "types": "./dist/exports-bkoi-gl.d.ts",
21
- "require": "./dist/exports-bkoi-gl.cjs",
22
- "import": "./dist/exports-bkoi-gl.js"
17
+ "import": "./dist/index.js",
18
+ "default": "./dist/index.cjs"
23
19
  },
24
20
  "./styles": {
21
+ "types": "./dist/styles/index.d.ts",
25
22
  "import": "./dist/styles/react-bkoi-gl.css",
26
23
  "default": "./dist/styles/react-bkoi-gl.css"
27
24
  }
28
25
  },
26
+ "author": "barikoi",
27
+ "readme": "README.md",
28
+ "license": "MIT",
29
+ "homepage": "https://docs.barikoi.com/docs/maps-api",
29
30
  "files": [
30
31
  "src",
31
32
  "dist",
32
- "bkoi-gl",
33
33
  "README.md"
34
34
  ],
35
35
  "scripts": {
36
- "typecheck": "tsc -p tsconfig.build.json --noEmit",
36
+ "typecheck": "tsc -p tsconfig.build.json",
37
+ "clean": "rm -rf dist && mkdir -p dist",
37
38
  "build": "ocular-clean && ocular-build && node scripts/modify-css.js",
38
- "lint": "ocular-lint",
39
- "cover": "ocular-test cover",
40
- "test": "yarn typecheck && ocular-test",
41
- "test-fast": "yarn typecheck && ocular-test node",
42
- "metrics": "ocular-metrics"
39
+ "lint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
40
+ "test": "npm run typecheck && jest",
41
+ "coverage": "jest --coverage --passWithNoTests",
42
+ "update-version": "node scripts/update-version.cjs"
43
43
  },
44
44
  "dependencies": {
45
- "@maplibre/maplibre-gl-style-spec": "^19.2.1",
46
- "@rollup/plugin-typescript": "^11.1.6",
47
- "bkoi-gl": ">=2.0.0",
48
- "mapbox-gl": "^1.13.0"
45
+ "@maplibre/maplibre-gl-style-spec": "^23.2.1",
46
+ "maplibre-gl": "^5.4.0"
49
47
  },
50
48
  "peerDependencies": {
51
49
  "react": ">=16.3.0",
@@ -54,13 +52,24 @@
54
52
  "devDependencies": {
55
53
  "@commitlint/cli": "^19.4.1",
56
54
  "@commitlint/config-conventional": "^19.4.1",
57
- "@types/mapbox-gl": "^3.4.0",
55
+ "@testing-library/jest-dom": "^6.4.2",
56
+ "@testing-library/react": "^14.2.1",
57
+ "@testing-library/react-hooks": "8.0.1",
58
+ "@types/jest": "^29.5.12",
59
+ "@types/node": "^22.0.0",
58
60
  "@types/react": "^16.0.0",
59
- "bkoi-gl": ">=2.0.0",
61
+ "babel-jest": "^29.7.0",
62
+ "identity-obj-proxy": "^3.0.0",
63
+ "jest": "^29.7.0",
64
+ "jest-environment-jsdom": "^29.7.0",
60
65
  "ocular-dev-tools": "2.0.0-alpha.15",
66
+ "puppeteer": "^22.4.0",
61
67
  "react": "^18.0.0",
62
68
  "react-dom": "^18.0.0",
63
- "typescript": "^4.0.0"
69
+ "react-test-renderer": "^18.0.0",
70
+ "tape-promise": "^4.0.0",
71
+ "ts-jest": "^29.1.2",
72
+ "typescript": "^5.0.0"
64
73
  },
65
74
  "keywords": [
66
75
  "barikoi",
@@ -72,5 +81,12 @@
72
81
  "repository": {
73
82
  "type": "git",
74
83
  "url": "https://github.com/barikoi/react-bkoi-gl.git"
84
+ },
85
+ "overrides": {
86
+ "@testing-library/react-hooks": {
87
+ "react": "$react",
88
+ "react-dom": "$react-dom",
89
+ "react-test-renderer": "$react-test-renderer"
90
+ }
75
91
  }
76
- }
92
+ }
@@ -1,32 +1,56 @@
1
- import * as React from 'react';
2
- import {useEffect, memo} from 'react';
3
- import {applyReactStyle} from '../utils/apply-react-style';
4
- import useControl from './use-control';
1
+ /* eslint-disable max-statements */
2
+ /* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
3
+ import * as React from "react";
4
+ import { useEffect, memo } from "react";
5
+ import { applyReactStyle } from "../utils/apply-react-style";
6
+ import { useControl } from "./use-control";
5
7
 
6
- import type {ControlPosition, AttributionControlInstance} from '../types';
8
+ import type { ControlPosition, AttributionControlOptions } from "../types/lib";
7
9
 
8
- export type AttributionControlProps<OptionsT> = OptionsT & {
10
+ export type AttributionControlProps = AttributionControlOptions & {
9
11
  /** Placement of the control relative to the map. */
10
12
  position?: ControlPosition;
11
13
  /** CSS style override, applied to the control's container */
12
14
  style?: React.CSSProperties;
13
15
  };
14
16
 
15
- function AttributionControl<AttributionControlOptions, ControlT extends AttributionControlInstance>(
16
- props: AttributionControlProps<AttributionControlOptions>
17
- ): null {
18
- const ctrl = useControl<ControlT>(
19
- ({mapLib}) => new mapLib.AttributionControl(props) as ControlT,
20
- {
21
- position: props.position
22
- }
17
+ function _AttributionControl(props: AttributionControlProps) {
18
+ const ctrl = useControl(
19
+ ({ mapLib }) => new mapLib.AttributionControl(props),
20
+ { position: props.position },
23
21
  );
24
22
 
25
23
  useEffect(() => {
26
24
  applyReactStyle(ctrl._container, props.style);
27
- }, [props.style]);
25
+
26
+ // Ensure the container is available
27
+ if (!ctrl._container) return;
28
+
29
+ // Create and append the custom attribution control
30
+ // const customAttribution = document.createElement('details');
31
+ // customAttribution.className = 'maplibregl-ctrl maplibregl-ctrl-attrib maplibregl-compact maplibregl-compact-show';
32
+ // customAttribution.setAttribute('open', '');
33
+
34
+ // const summary = document.createElement('summary');
35
+ // summary.className = 'maplibregl-ctrl-attrib-button';
36
+ // summary.setAttribute('title', 'Toggle attribution');
37
+ // summary.setAttribute('aria-label', 'Toggle attribution');
38
+ // customAttribution.appendChild(summary);
39
+
40
+ // const innerDiv = document.createElement('div');
41
+ // innerDiv.className = 'maplibregl-ctrl-attrib-inner';
42
+ // innerDiv.innerHTML = `
43
+ // <a href="https://barikoi.com/" target="_blank">© Barikoi</a> |
44
+ // <a href="https://www.openmaptiles.org/" target="_blank">© OpenMapTiles</a> |
45
+ // <a href="https://www.openstreetmap.org/copyright" target="_blank">© OpenStreetMap contributors</a>
46
+ // `;
47
+ // customAttribution.appendChild(innerDiv);
48
+
49
+ // ctrl._container.appendChild(customAttribution);
50
+ }, [props.style, ctrl._container]);
28
51
 
29
52
  return null;
30
53
  }
31
54
 
32
- export default memo(AttributionControl);
55
+ export const AttributionControl: React.FC<AttributionControlProps> =
56
+ memo(_AttributionControl);
@@ -0,0 +1,40 @@
1
+ /* global document */
2
+ import * as React from "react";
3
+ import { useEffect, memo } from "react";
4
+ import { applyReactStyle } from "../utils/apply-react-style";
5
+ import { useControl } from "./use-control";
6
+
7
+ import type { ControlPosition, FullscreenControlOptions } from "../types/lib";
8
+
9
+ export type FullscreenControlProps = Omit<
10
+ FullscreenControlOptions,
11
+ "container"
12
+ > & {
13
+ /** Id of the DOM element which should be made full screen. By default, the map container
14
+ * element will be made full screen. */
15
+ containerId?: string;
16
+ /** Placement of the control relative to the map. */
17
+ position?: ControlPosition;
18
+ /** CSS style override, applied to the control's container */
19
+ style?: React.CSSProperties;
20
+ };
21
+
22
+ function _FullscreenControl(props: FullscreenControlProps) {
23
+ const ctrl = useControl(
24
+ ({ mapLib }) =>
25
+ new mapLib.FullscreenControl({
26
+ container:
27
+ props.containerId && document.getElementById(props.containerId),
28
+ }),
29
+ { position: props.position },
30
+ );
31
+
32
+ useEffect(() => {
33
+ applyReactStyle(ctrl._controlContainer, props.style);
34
+ }, [props.style]);
35
+
36
+ return null;
37
+ }
38
+
39
+ export const FullscreenControl: React.FC<FullscreenControlProps> =
40
+ memo(_FullscreenControl);
@@ -1,79 +1,83 @@
1
- import * as React from 'react';
2
- import {useImperativeHandle, useRef, useEffect, forwardRef, memo} from 'react';
3
- import {applyReactStyle} from '../utils/apply-react-style';
4
- import useControl from './use-control';
1
+ import * as React from "react";
2
+ import {
3
+ useImperativeHandle,
4
+ useRef,
5
+ useEffect,
6
+ forwardRef,
7
+ memo,
8
+ } from "react";
9
+ import { applyReactStyle } from "../utils/apply-react-style";
10
+ import { useControl } from "./use-control";
5
11
 
6
12
  import type {
7
13
  ControlPosition,
8
- GeolocateControlInstance,
14
+ GeolocateControl as GeolocateControlInstance,
15
+ GeolocateControlOptions,
16
+ } from "../types/lib";
17
+ import type {
9
18
  GeolocateEvent,
10
19
  GeolocateResultEvent,
11
- GeolocateErrorEvent
12
- } from '../types';
20
+ GeolocateErrorEvent,
21
+ } from "../types/events";
13
22
 
14
- export type GeolocateControlProps<
15
- OptionsT,
16
- ControlT extends GeolocateControlInstance
17
- > = OptionsT & {
23
+ export type GeolocateControlProps = GeolocateControlOptions & {
18
24
  /** Placement of the control relative to the map. */
19
25
  position?: ControlPosition;
20
26
  /** CSS style override, applied to the control's container */
21
27
  style?: React.CSSProperties;
22
28
 
23
29
  /** Called on each Geolocation API position update that returned as success. */
24
- onGeolocate?: (e: GeolocateResultEvent<ControlT>) => void;
30
+ onGeolocate?: (e: GeolocateResultEvent) => void;
25
31
  /** Called on each Geolocation API position update that returned as an error. */
26
- onError?: (e: GeolocateErrorEvent<ControlT>) => void;
32
+ onError?: (e: GeolocateErrorEvent) => void;
27
33
  /** Called on each Geolocation API position update that returned as success but user position
28
34
  * is out of map `maxBounds`. */
29
- onOutOfMaxBounds?: (e: GeolocateResultEvent<ControlT>) => void;
35
+ onOutOfMaxBounds?: (e: GeolocateResultEvent) => void;
30
36
  /** Called when the GeolocateControl changes to the active lock state. */
31
- onTrackUserLocationStart?: (e: GeolocateEvent<ControlT>) => void;
37
+ onTrackUserLocationStart?: (e: GeolocateEvent) => void;
32
38
  /** Called when the GeolocateControl changes to the background state. */
33
- onTrackUserLocationEnd?: (e: GeolocateEvent<ControlT>) => void;
39
+ onTrackUserLocationEnd?: (e: GeolocateEvent) => void;
34
40
  };
35
41
 
36
- function GeolocateControl<GeolocateControlOptions, ControlT extends GeolocateControlInstance>(
37
- props: GeolocateControlProps<GeolocateControlOptions, ControlT>,
38
- ref: React.Ref<ControlT>
42
+ function _GeolocateControl(
43
+ props: GeolocateControlProps,
44
+ ref: React.Ref<GeolocateControlInstance>,
39
45
  ) {
40
- const thisRef = useRef({props});
46
+ const thisRef = useRef({ props });
41
47
 
42
- const ctrl = useControl<ControlT>(
43
- ({mapLib}) => {
44
- const gc = new mapLib.GeolocateControl(props) as ControlT;
48
+ const ctrl = useControl(
49
+ ({ mapLib }) => {
50
+ const gc = new mapLib.GeolocateControl(props);
45
51
 
46
52
  // Hack: fix GeolocateControl reuse
47
53
  // When using React strict mode, the component is mounted twice.
48
54
  // GeolocateControl's UI creation is asynchronous. Removing and adding it back causes the UI to be initialized twice.
49
- // @ts-expect-error private method
50
55
  const setupUI = gc._setupUI;
51
- // @ts-expect-error private method
52
- gc._setupUI = args => {
56
+ gc._setupUI = () => {
53
57
  if (!gc._container.hasChildNodes()) {
54
- setupUI(args);
58
+ setupUI();
55
59
  }
56
60
  };
57
61
 
58
- gc.on('geolocate', e => {
59
- thisRef.current.props.onGeolocate?.(e as GeolocateResultEvent<ControlT>);
62
+ gc.on("geolocate", (e) => {
63
+ thisRef.current.props.onGeolocate?.(e as GeolocateResultEvent);
60
64
  });
61
- gc.on('error', e => {
62
- thisRef.current.props.onError?.(e as GeolocateErrorEvent<ControlT>);
65
+ gc.on("error", (e) => {
66
+ thisRef.current.props.onError?.(e as GeolocateErrorEvent);
63
67
  });
64
- gc.on('outofmaxbounds', e => {
65
- thisRef.current.props.onOutOfMaxBounds?.(e as GeolocateResultEvent<ControlT>);
68
+ gc.on("outofmaxbounds", (e) => {
69
+ thisRef.current.props.onOutOfMaxBounds?.(e as GeolocateResultEvent);
66
70
  });
67
- gc.on('trackuserlocationstart', e => {
68
- thisRef.current.props.onTrackUserLocationStart?.(e as GeolocateEvent<ControlT>);
71
+ gc.on("trackuserlocationstart", (e) => {
72
+ thisRef.current.props.onTrackUserLocationStart?.(e as GeolocateEvent);
69
73
  });
70
- gc.on('trackuserlocationend', e => {
71
- thisRef.current.props.onTrackUserLocationEnd?.(e as GeolocateEvent<ControlT>);
74
+ gc.on("trackuserlocationend", (e) => {
75
+ thisRef.current.props.onTrackUserLocationEnd?.(e as GeolocateEvent);
72
76
  });
73
77
 
74
78
  return gc;
75
79
  },
76
- {position: props.position}
80
+ { position: props.position },
77
81
  );
78
82
 
79
83
  thisRef.current.props = props;
@@ -87,4 +91,6 @@ function GeolocateControl<GeolocateControlOptions, ControlT extends GeolocateCon
87
91
  return null;
88
92
  }
89
93
 
90
- export default memo(forwardRef(GeolocateControl));
94
+ export const GeolocateControl: React.FC<GeolocateControlProps> = memo(
95
+ forwardRef(_GeolocateControl),
96
+ );
@@ -1,35 +1,44 @@
1
- import {useContext, useEffect, useMemo, useState, useRef} from 'react';
2
- import {MapContext} from './map';
3
- import assert from '../utils/assert';
4
- import {deepEqual} from '../utils/deep-equal';
1
+ import { useContext, useEffect, useMemo, useState, useRef } from "react";
2
+ import { MapContext } from "./map";
3
+ import assert from "../utils/assert";
4
+ import { deepEqual } from "../utils/deep-equal";
5
5
 
6
- import type {MapInstance, CustomLayerInterface, ILayer} from '../types';
6
+ import type { Map as MapInstance, CustomLayerInterface } from "../types/lib";
7
+ import type { LayerSpecification } from "../types/style-spec";
7
8
 
8
9
  // Omiting property from a union type, see
9
10
  // https://github.com/microsoft/TypeScript/issues/39556#issuecomment-656925230
10
- type OptionalId<T> = T extends {id: string} ? Omit<T, 'id'> & {id?: string} : T;
11
- type OptionalSource<T> = T extends {source: string} ? Omit<T, 'source'> & {source?: string} : T;
12
-
13
- export type LayerProps<LayerT> = OptionalSource<OptionalId<LayerT>> & {
11
+ type OptionalId<T> = T extends { id: string }
12
+ ? Omit<T, "id"> & { id?: string }
13
+ : T;
14
+ type OptionalSource<T> = T extends { source: string }
15
+ ? Omit<T, "source"> & { source?: string }
16
+ : T;
17
+
18
+ export type LayerProps = (
19
+ | OptionalSource<OptionalId<LayerSpecification>>
20
+ | CustomLayerInterface
21
+ ) & {
14
22
  /** If set, the layer will be inserted before the specified layer */
15
23
  beforeId?: string;
16
24
  };
17
25
 
18
26
  /* eslint-disable complexity, max-statements */
19
- function updateLayer<LayerT extends ILayer>(
27
+ function updateLayer(
20
28
  map: MapInstance,
21
29
  id: string,
22
- props: LayerProps<LayerT>,
23
- prevProps: LayerProps<LayerT>
30
+ props: LayerProps,
31
+ prevProps: LayerProps,
24
32
  ) {
25
- assert(props.id === prevProps.id, 'layer id changed');
26
- assert(props.type === prevProps.type, 'layer type changed');
33
+ assert(props.id === prevProps.id, "layer id changed");
34
+ assert(props.type === prevProps.type, "layer type changed");
27
35
 
28
- if (props.type === 'custom' || prevProps.type === 'custom') {
36
+ if (props.type === "custom" || prevProps.type === "custom") {
29
37
  return;
30
38
  }
31
39
 
32
- const {layout = {}, paint = {}, filter, minzoom, maxzoom, beforeId} = props;
40
+ // @ts-ignore filter does not exist in some Layer types
41
+ const { layout = {}, paint = {}, filter, minzoom, maxzoom, beforeId } = props;
33
42
 
34
43
  if (beforeId !== prevProps.beforeId) {
35
44
  map.moveLayer(id, beforeId);
@@ -61,6 +70,7 @@ function updateLayer<LayerT extends ILayer>(
61
70
  }
62
71
  }
63
72
 
73
+ // @ts-ignore filter does not exist in some Layer types
64
74
  if (!deepEqual(filter, prevProps.filter)) {
65
75
  map.setFilter(id, filter);
66
76
  }
@@ -69,14 +79,14 @@ function updateLayer<LayerT extends ILayer>(
69
79
  }
70
80
  }
71
81
 
72
- function createLayer<LayerT extends ILayer>(
73
- map: MapInstance,
74
- id: string,
75
- props: LayerProps<LayerT>
76
- ) {
82
+ function createLayer(map: MapInstance, id: string, props: LayerProps) {
77
83
  // @ts-ignore
78
- if (map.style && map.style._loaded && (!('source' in props) || map.getSource(props.source))) {
79
- const options: LayerProps<LayerT> = {...props, id};
84
+ if (
85
+ map.style &&
86
+ map.style._loaded &&
87
+ (!("source" in props) || map.getSource(props.source))
88
+ ) {
89
+ const options: LayerProps = { ...props, id };
80
90
  delete options.beforeId;
81
91
 
82
92
  // @ts-ignore
@@ -88,7 +98,7 @@ function createLayer<LayerT extends ILayer>(
88
98
 
89
99
  let layerCounter = 0;
90
100
 
91
- function Layer<LayerT extends ILayer>(props: LayerProps<LayerT | CustomLayerInterface>) {
101
+ export function Layer(props: LayerProps) {
92
102
  const map = useContext(MapContext).map.getMap();
93
103
  const propsRef = useRef(props);
94
104
  const [, setStyleLoaded] = useState(0);
@@ -97,12 +107,12 @@ function Layer<LayerT extends ILayer>(props: LayerProps<LayerT | CustomLayerInte
97
107
 
98
108
  useEffect(() => {
99
109
  if (map) {
100
- const forceUpdate = () => setStyleLoaded(version => version + 1);
101
- map.on('styledata', forceUpdate);
110
+ const forceUpdate = () => setStyleLoaded((version) => version + 1);
111
+ map.on("styledata", forceUpdate);
102
112
  forceUpdate();
103
113
 
104
114
  return () => {
105
- map.off('styledata', forceUpdate);
115
+ map.off("styledata", forceUpdate);
106
116
  // @ts-ignore
107
117
  if (map.style && map.style._loaded && map.getLayer(id)) {
108
118
  map.removeLayer(id);
@@ -129,5 +139,3 @@ function Layer<LayerT extends ILayer>(props: LayerProps<LayerT | CustomLayerInte
129
139
 
130
140
  return null;
131
141
  }
132
-
133
- export default Layer;
@@ -0,0 +1,44 @@
1
+ /* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
2
+ import * as React from "react";
3
+ import { useEffect, memo } from "react";
4
+ import { applyReactStyle } from "../utils/apply-react-style";
5
+ import { useControl } from "./use-control";
6
+
7
+ import type { ControlPosition, LogoControlOptions } from "../types/lib";
8
+
9
+ export type LogoControlProps = LogoControlOptions & {
10
+ /** Placement of the control relative to the map. */
11
+ position?: ControlPosition;
12
+ /** CSS style override, applied to the control's container */
13
+ style?: React.CSSProperties;
14
+ };
15
+
16
+ function _LogoControl(props: LogoControlProps) {
17
+ const ctrl = useControl(({ mapLib }) => new mapLib.LogoControl(props), {
18
+ position: props.position,
19
+ });
20
+
21
+ useEffect(() => {
22
+ applyReactStyle(ctrl._container, props.style);
23
+
24
+ // Update the DOM structure and attributes directly
25
+ const logoElement = ctrl._container?.querySelector(
26
+ ".maplibregl-ctrl-logo",
27
+ ) as HTMLAnchorElement | null;
28
+ if (logoElement) {
29
+ // Update the link attributes
30
+ logoElement.href = "https://barikoi.com/";
31
+ logoElement.setAttribute("aria-label", "Barikoi logo");
32
+ logoElement.target = "_blank";
33
+ logoElement.rel = "noopener nofollow";
34
+ logoElement.style.cursor = "pointer";
35
+
36
+ // Remove any existing click handlers
37
+ logoElement.replaceWith(logoElement.cloneNode(true));
38
+ }
39
+ }, [props.style, ctrl._container]);
40
+
41
+ return null;
42
+ }
43
+
44
+ export const LogoControl: React.FC<LogoControlProps> = memo(_LogoControl);