@geops/rvf-mobility-web-component 0.1.9 → 0.1.11

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 (80) hide show
  1. package/.github/CODEOWNERS +37 -0
  2. package/.github/workflows/conventional-pr-title.yml +36 -0
  3. package/CHANGELOG.md +55 -0
  4. package/README.md +3 -1
  5. package/doc/package.json +5 -5
  6. package/doc/src/app/components/GeopsMobilityDoc.tsx +19 -0
  7. package/docutils.js +198 -0
  8. package/index.html +48 -217
  9. package/index.js +683 -91
  10. package/input.css +15 -1
  11. package/jest-setup.js +3 -2
  12. package/package.json +9 -8
  13. package/scripts/dev.mjs +1 -1
  14. package/search.html +38 -69
  15. package/src/GeolocationButton/GeolocationButton.tsx +6 -17
  16. package/src/LayerTree/LayerTree.tsx +44 -0
  17. package/src/LayerTree/TreeItem/TreeItem.tsx +145 -0
  18. package/src/LayerTree/TreeItem/index.tsx +1 -0
  19. package/src/LayerTree/TreeItemContainer/TreeItemContainer.tsx +16 -0
  20. package/src/LayerTree/TreeItemContainer/index.tsx +1 -0
  21. package/src/LayerTree/index.tsx +1 -0
  22. package/src/LayerTree/layersTreeContext.ts +4 -0
  23. package/src/LayerTree/layersTreeReducer.ts +156 -0
  24. package/src/Map/Map.tsx +57 -12
  25. package/src/MobilityMap/MobilityMap.tsx +22 -9
  26. package/src/MobilityMap/index.css +0 -13
  27. package/src/RealtimeLayer/RealtimeLayer.tsx +1 -1
  28. package/src/RvfButton/RvfButton.tsx +45 -0
  29. package/src/RvfButton/index.tsx +1 -0
  30. package/src/RvfExportMenu/RvfExportMenu.tsx +95 -0
  31. package/src/RvfExportMenu/index.tsx +1 -0
  32. package/src/RvfExportMenuButton/RvfExportMenuButton.tsx +27 -0
  33. package/src/RvfExportMenuButton/index.tsx +1 -0
  34. package/src/RvfFeatureDetails/RvfFeatureDetails.tsx +29 -0
  35. package/src/RvfFeatureDetails/index.tsx +1 -0
  36. package/src/RvfIconButton/RvfIconButton.tsx +35 -0
  37. package/src/RvfIconButton/index.tsx +1 -0
  38. package/src/RvfMobilityMap/RvfMobilityMap.tsx +132 -52
  39. package/src/RvfMobilityMap/index.css +0 -13
  40. package/src/RvfModal/RvfModal.tsx +52 -0
  41. package/src/RvfModal/index.tsx +1 -0
  42. package/src/RvfPoisLayer/RvfPoisLayer.tsx +39 -0
  43. package/src/RvfPoisLayer/index.tsx +1 -0
  44. package/src/RvfSharedMobilityLayerGroup/RvfSharedMobilityLayerGroup.tsx +88 -0
  45. package/src/RvfSharedMobilityLayerGroup/index.tsx +1 -0
  46. package/src/RvfSingleClickListener/RvfSingleClickListener.tsx +137 -0
  47. package/src/RvfSingleClickListener/index.tsx +1 -0
  48. package/src/RvfZoomButtons/RvfZoomButtons.tsx +73 -0
  49. package/src/RvfZoomButtons/index.tsx +1 -0
  50. package/src/Search/Search.tsx +11 -9
  51. package/src/SingleClickListener/index.tsx +1 -1
  52. package/src/StationsLayer/StationsLayer.tsx +0 -1
  53. package/src/StopsSearch/StopsSearch.tsx +38 -6
  54. package/src/TopicMenu/TopicMenu.tsx +143 -0
  55. package/src/TopicMenu/index.tsx +1 -0
  56. package/src/icons/Cancel/Cancel.tsx +21 -0
  57. package/src/icons/Cancel/cancel.svg +7 -0
  58. package/src/icons/Cancel/index.tsx +1 -0
  59. package/src/icons/Download/Download.tsx +20 -0
  60. package/src/icons/Download/download.svg +15 -0
  61. package/src/icons/Download/index.tsx +1 -0
  62. package/src/icons/Elevator/Elevator.tsx +1 -1
  63. package/src/icons/Geolocation/Geolocation.tsx +21 -0
  64. package/src/icons/Geolocation/index.tsx +1 -0
  65. package/src/icons/Menu/Menu.tsx +32 -0
  66. package/src/icons/Menu/index.tsx +1 -0
  67. package/src/icons/Menu/menu.svg +9 -0
  68. package/src/icons/Minus/Minus.tsx +19 -0
  69. package/src/icons/Minus/index.tsx +1 -0
  70. package/src/icons/Minus/minus.svg +7 -0
  71. package/src/icons/Plus/Plus.tsx +19 -0
  72. package/src/icons/Plus/index.tsx +1 -0
  73. package/src/icons/Plus/plus.svg +7 -0
  74. package/src/index.tsx +2 -0
  75. package/src/utils/constants.ts +9 -0
  76. package/src/utils/createMobiDataBwWfsLayer.ts +120 -0
  77. package/src/utils/exportPdf.ts +677 -0
  78. package/src/utils/hooks/useRvfContext.tsx +37 -0
  79. package/src/utils/hooks/useUpdatePermalink.tsx +2 -9
  80. package/tailwind.config.mjs +60 -8
@@ -0,0 +1,37 @@
1
+ # This is a comment.
2
+ # Each line is a file pattern followed by one or more owners.
3
+
4
+ # These owners will be the default owners for everything in
5
+ # the repo. Unless a later match takes precedence,
6
+ # @global-owner1 and @global-owner2 will be requested for
7
+ # review when someone opens a pull request.
8
+ * @danji90 @friedjoff @oterral
9
+
10
+ # Order is important; the last matching pattern takes the most
11
+ # precedence. When someone opens a pull request that only
12
+ # modifies JS files, only @js-owner and not the global
13
+ # owner(s) will be requested for a review.
14
+ # *.js @js-owner
15
+
16
+ # You can also use email addresses if you prefer. They'll be
17
+ # used to look up users just like we do for commit author
18
+ # emails.
19
+ # *.go docs@example.com
20
+
21
+ # In this example, @doctocat owns any files in the build/logs
22
+ # directory at the root of the repository and any of its
23
+ # subdirectories.
24
+ # /build/logs/ @doctocat
25
+
26
+ # The `docs/*` pattern will match files like
27
+ # `docs/getting-started.md` but not further nested files like
28
+ # `docs/build-app/troubleshooting.md`.
29
+ # docs/* docs@example.com
30
+
31
+ # In this example, @octocat owns any file in an apps directory
32
+ # anywhere in your repository.
33
+ # apps/ @octocat
34
+
35
+ # In this example, @doctocat owns any file in the `/docs`
36
+ # directory in the root of your repository.
37
+ # /docs/ @doctocat
@@ -0,0 +1,36 @@
1
+ name: Check PR title
2
+ on:
3
+ pull_request:
4
+ types:
5
+ - opened
6
+ - reopened
7
+ - edited
8
+ - synchronize
9
+
10
+ # permissions for dependabot PRs
11
+ permissions:
12
+ actions: read
13
+ checks: read
14
+ contents: read
15
+ deployments: read
16
+ id-token: write
17
+ issues: read
18
+ discussions: read
19
+ packages: read
20
+ pages: read
21
+ pull-requests: read
22
+ repository-projects: read
23
+ security-events: read
24
+ statuses: write
25
+
26
+ jobs:
27
+ lint:
28
+ runs-on: ubuntu-latest
29
+ steps:
30
+ - uses: aslafy-z/conventional-pr-title-action@v3
31
+ with:
32
+ success-state: Title follows the specification.
33
+ failure-state: Title does not follow the specification.
34
+ context-name: conventional-pr-title
35
+ env:
36
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/CHANGELOG.md CHANGED
@@ -2,6 +2,61 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.1.11](https://github.com/geops/rvf-mobility-web-component/compare/v0.1.10...v0.1.11) (2024-12-17)
6
+
7
+
8
+ ### Features
9
+
10
+ * add and hide pois layer ([f99d82a](https://github.com/geops/rvf-mobility-web-component/commit/f99d82a944d9daeb0acae9b0c3519cb8bbb608d7))
11
+ * add copyright in export and add feature details on click ([#10](https://github.com/geops/rvf-mobility-web-component/issues/10)) ([3e2ed59](https://github.com/geops/rvf-mobility-web-component/commit/3e2ed597c374e2edfb2d1a8e4b3afe0e4dc80e0a))
12
+ * add custom click listener ([74de9e4](https://github.com/geops/rvf-mobility-web-component/commit/74de9e42125ee068147d67a17324ba06fd1727a1))
13
+ * add export pdf ([#7](https://github.com/geops/rvf-mobility-web-component/issues/7)) ([3409f8b](https://github.com/geops/rvf-mobility-web-component/commit/3409f8baf257dcacc3c823355209e3c44214a31b))
14
+ * add rvf context and rvf print menu button ([37f6ddf](https://github.com/geops/rvf-mobility-web-component/commit/37f6ddfcec4a950539c41178575dc841c5824252))
15
+ * added layers tree component ([#9](https://github.com/geops/rvf-mobility-web-component/issues/9)) ([ceb0220](https://github.com/geops/rvf-mobility-web-component/commit/ceb022025eeb7b4cf25ff9a38afe8950b7d1d651))
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * add better types ([c5ddf70](https://github.com/geops/rvf-mobility-web-component/commit/c5ddf7041036ab1c5e702b6d6c702bf9747df396))
21
+ * add lonlat to singleclick event ([786c79b](https://github.com/geops/rvf-mobility-web-component/commit/786c79bdd2fae619c522f635217684c05347bfe9))
22
+ * add mobidata bw layers as a group ([2aab2a5](https://github.com/geops/rvf-mobility-web-component/commit/2aab2a570c3e6214830895c146a5a95836a75516))
23
+ * add selected state ([ea6e84e](https://github.com/geops/rvf-mobility-web-component/commit/ea6e84ee265d734a502e5e2299571bd977133433))
24
+ * create a correct layer tree ([1d886b5](https://github.com/geops/rvf-mobility-web-component/commit/1d886b588821467db431bddc45821ba21b471946))
25
+ * dispatch event on html element ([e36f61d](https://github.com/geops/rvf-mobility-web-component/commit/e36f61d8295193896aba57694a4de0141aa8d0f8))
26
+ * display the copyright after an export ([cb957b7](https://github.com/geops/rvf-mobility-web-component/commit/cb957b71a528a2ad466e8bc0f0a1ddf8eb844920))
27
+ * hide print menu for now ([43dc47f](https://github.com/geops/rvf-mobility-web-component/commit/43dc47fc3ba17f8af10b057d61cce33268ffdba6))
28
+ * improve demo ([3ca67ea](https://github.com/geops/rvf-mobility-web-component/commit/3ca67eacf74b89cd396a66706b111d0e9d8963a0))
29
+ * improve demo ([1ed0b7e](https://github.com/geops/rvf-mobility-web-component/commit/1ed0b7e078b23c1bc3d1bbe1743d45b318b129b5))
30
+ * make realtime use the map pixel ratio ([dce1004](https://github.com/geops/rvf-mobility-web-component/commit/dce1004f9d945d5cd260e41660a71d49ce684e18))
31
+ * manage boolean attributes ([be816a9](https://github.com/geops/rvf-mobility-web-component/commit/be816a9f005a6979af1b0bf02034e9fe1bb22218))
32
+ * memoize onselect callback ([1d7e739](https://github.com/geops/rvf-mobility-web-component/commit/1d7e739e08da0d8d2ebb6594f83abdf9a655e658))
33
+ * remove useless xyz ([926cca7](https://github.com/geops/rvf-mobility-web-component/commit/926cca7e235265ccc6ab1ffb8241aa65454500e0))
34
+ * use also input.css for components ([1284687](https://github.com/geops/rvf-mobility-web-component/commit/128468703b3e1f50b851050870205364f43e5def))
35
+ * use memo ([0a3f107](https://github.com/geops/rvf-mobility-web-component/commit/0a3f1074bbc75b371c6375f91a9c9975a9627ed4))
36
+ * use proper rendercomplete event ([8cd5136](https://github.com/geops/rvf-mobility-web-component/commit/8cd51362b012bd7ce482355a11a6007ca705a12a))
37
+
38
+ ### [0.1.10](https://github.com/geops/rvf-mobility-web-component/compare/v0.1.9...v0.1.10) (2024-12-05)
39
+
40
+
41
+ ### Features
42
+
43
+ * add conventional pr title workflow ([711af06](https://github.com/geops/rvf-mobility-web-component/commit/711af0666a0882050f5e8aa9b5d8bb09c0e7d1c2))
44
+ * add extent and maxextent attribute ([89675e0](https://github.com/geops/rvf-mobility-web-component/commit/89675e09cbbfd07e1a0c19accdb6eb226b335392))
45
+ * add wfs layer ([#5](https://github.com/geops/rvf-mobility-web-component/issues/5)) ([48aa20c](https://github.com/geops/rvf-mobility-web-component/commit/48aa20cf07f50e3cd1cde977e462d617e824c5b5))
46
+ * add zoom buttons ([#6](https://github.com/geops/rvf-mobility-web-component/issues/6)) ([25c7574](https://github.com/geops/rvf-mobility-web-component/commit/25c75749cce225b5c331191a46e2455f1e3141b7))
47
+
48
+
49
+ ### Bug Fixes
50
+
51
+ * add extent and maxexten in doc and update deps ([aae94c4](https://github.com/geops/rvf-mobility-web-component/commit/aae94c47562b6ae3d797a6d114978c294836cf67))
52
+ * block extent on rvf data ([1d77f73](https://github.com/geops/rvf-mobility-web-component/commit/1d77f736e6177f3999df1750c56e4abd9011649f))
53
+ * constrain only center when maxextent is defined ([47c3ba8](https://github.com/geops/rvf-mobility-web-component/commit/47c3ba8a2c9f48a2fcc3f2d87757ab71aded22a1))
54
+ * constraint to max extent ([a052df1](https://github.com/geops/rvf-mobility-web-component/commit/a052df1378e5478fc48c90908400f58394501baf))
55
+ * constraint to max extent ([8d113e6](https://github.com/geops/rvf-mobility-web-component/commit/8d113e6f139d8b8fe3950e4d894f673b41e750f0))
56
+ * fix default css in code example ([85f5ce9](https://github.com/geops/rvf-mobility-web-component/commit/85f5ce957f74c8a0c5f1939180bbe3dab9c71ff3))
57
+ * remove default value ([0a2e48a](https://github.com/geops/rvf-mobility-web-component/commit/0a2e48ad70e6d93e8281fab5eee92e2540bfc9f3))
58
+ * use maps prod url ([d3bb0d2](https://github.com/geops/rvf-mobility-web-component/commit/d3bb0d22aac819d866c3fe02ab8373f7743197f4))
59
+
5
60
  ### [0.1.9](https://github.com/geops/rvf-mobility-web-component/compare/v0.1.8...v0.1.9) (2024-12-04)
6
61
 
7
62
 
package/README.md CHANGED
@@ -34,8 +34,10 @@ Here an exhaustive list of the `<geops-mobility>` web component attributes avail
34
34
  - [`apikey="YOUR_API_KEY"`](https://mobility-web-component.geops.io/?apikey=YOUR_API_KEY): your [geOps API key](https://developer.geops.io/).
35
35
  - [`baselayer="travic_v2"`](https://mobility-web-component.geops.io/?baselayer=travic_v2): the style's name from the [geOps Maps API](https://developer.geops.io/apis/maps) (base_dark_v2, base_bright_v2, ...). Default to `travic_v2`.
36
36
  - [`center="831634,5933959"`](https://mobility-web-component.geops.io/?center=831634,5933959): the center of the map in EPSG:3857 coordinates. Default to `831634,5933959` (Bern).
37
+ - [`extent="830634,5923959,831634,5933959"`](https://mobility-web-component.geops.io/?extent=830634,5923959,831634,5933959): the extent of the map of the map in EPSG:3857 coordinates. It has the priority over `center` and `zoom` attributes.
37
38
  - [`geolocation="false"`](https://mobility-web-component.geops.io/?geolocation=false): display the geolocation button or not (true or false). Default to true.
38
- - [`mapsurl="https://maps.geops.io"`](https://mobility-web-component.geops.io/?mapsurl=https://maps.geops.io): the [geOps Maps API](https://developer.geops.io/apis/maps) url to use. Default to `https://maps.geops.io`.
39
+ - [`mapsurl="https://maps.geops.io"`](https://mobility-web-component.geops.io/?mapsurl=https://maps.geops.io): the [geOps Maps API](https://developer.geops.io/apis/maps) url to use.Default to `https://maps.geops.io`.
40
+ - [`maxextent="830634,5923959,831634,5933959"`](https://mobility-web-component.geops.io/?extent=830634,5923959,831634,5933959): constraint the map in a specific extent in EPSG:3857 coordinates, the user can not navigate outside this extent.
39
41
  - [`maxzoom="14"`](https://mobility-web-component.geops.io/?maxzoom=14): define the max zoom level of the map.
40
42
  - [`minzoom="2"`](https://mobility-web-component.geops.io/?minzoom=2): define the min zoom level of the map.
41
43
  - [`mots="rail,bus"`](https://mobility-web-component.geops.io/?mots=rail,bus): list of commas separated mots to display on the Realtime layer ( rail, bus, coach, foot, tram, subway, gondola, funicular, ferry, car).
package/doc/package.json CHANGED
@@ -7,10 +7,10 @@
7
7
  "@emotion/react": "^11.13.5",
8
8
  "@emotion/styled": "^11.13.5",
9
9
  "@geops/geops-ui": "^0.3.4",
10
- "@mui/icons-material": "^6.1.9",
11
- "@mui/material": "^6.1.9",
10
+ "@mui/icons-material": "^6.1.10",
11
+ "@mui/material": "^6.1.10",
12
12
  "@mui/material-nextjs": "^6.1.9",
13
- "@mui/styles": "^6.1.9",
13
+ "@mui/styles": "^6.1.10",
14
14
  "next": "15.0.3",
15
15
  "prismjs": "^1.29.0",
16
16
  "react": "^18",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^22.10.1",
23
- "@types/react": "^18.3.12",
23
+ "@types/react": "^18.3.13",
24
24
  "@types/react-dom": "^18",
25
25
  "@types/react-syntax-highlighter": "^15.5.13",
26
26
  "eslint": "^8",
@@ -28,7 +28,7 @@
28
28
  "eslint-config-prettier": "^9.1.0",
29
29
  "generact": "^0.4.0",
30
30
  "postcss": "^8.4.49",
31
- "tailwindcss": "^3.4.15",
31
+ "tailwindcss": "^3.4.16",
32
32
  "typescript": "^5.7.2"
33
33
  },
34
34
  "scripts": {
@@ -36,6 +36,16 @@ const attrsConfig: Record<string, AttrConfig> = {
36
36
  ),
37
37
  type: "textfield",
38
38
  },
39
+ extent: {
40
+ description: (
41
+ <Typography>
42
+ The extent of the map in EPSG:3857 coordinates (ex:
43
+ 830634,5923959,831634,5933959). It has the priority over center and zoom
44
+ attributes.
45
+ </Typography>
46
+ ),
47
+ type: "textfield",
48
+ },
39
49
  geolocation: {
40
50
  defaultValue: "true",
41
51
  description: (
@@ -54,6 +64,15 @@ const attrsConfig: Record<string, AttrConfig> = {
54
64
  ),
55
65
  type: "textfield",
56
66
  },
67
+ maxextent: {
68
+ description: (
69
+ <Typography>
70
+ Constraint the map in a specific extent in EPSG:3857 coordinates, the
71
+ user can not navigate outside this extent.
72
+ </Typography>
73
+ ),
74
+ type: "textfield",
75
+ },
57
76
  maxzoom: {
58
77
  description: <Typography>Define the max zoom level of the map.</Typography>,
59
78
  props: {
package/docutils.js ADDED
@@ -0,0 +1,198 @@
1
+ /* eslint-disable no-undef */
2
+ /* eslint-disable @typescript-eslint/no-unused-vars */
3
+ function applyPermalinkParameters(wc) {
4
+ const params = new URLSearchParams(window.location.search);
5
+
6
+ // Apply fullscreen mode
7
+ if (params.get("fullscreen") === "true") {
8
+ wc.parentElement.removeChild(wc);
9
+ wc.className = "absolute w-full h-full inset-0";
10
+ document.body.appendChild(wc);
11
+ document.body.style = "padding:0;";
12
+ } else {
13
+ const doc = document.querySelectorAll("#doc");
14
+ doc.forEach((d) => {
15
+ return (d.style.display = "block");
16
+ });
17
+ }
18
+ // Apply x,y,z
19
+ if (
20
+ params.get("permalink") === "true" &&
21
+ params.get("x") &&
22
+ params.get("y")
23
+ ) {
24
+ wc.setAttribute("center", `${params.get("x")},${params.get("y")}`);
25
+ params.delete("x");
26
+ params.delete("y");
27
+ }
28
+
29
+ if (params.get("permalink") === "true" && params.get("z")) {
30
+ wc.setAttribute("zoom", params.get("z"));
31
+ params.delete("z");
32
+ }
33
+
34
+ // Apply all url parameters as attribute of the web component and fill the input fields.
35
+ params.forEach((value, key) => {
36
+ wc.setAttribute(key, value);
37
+ const input = document.querySelector(`[name=${key}]`);
38
+ if (input) {
39
+ if (input.type === "checkbox") {
40
+ input.checked = value !== "false";
41
+ } else {
42
+ input.value = value;
43
+ }
44
+ }
45
+ });
46
+
47
+ // Get an apikey if there is none defined
48
+ if (!wc.getAttribute("apikey")) {
49
+ fetch("https://backend.developer.geops.io/publickey")
50
+ .then((response) => {
51
+ return response.json();
52
+ })
53
+ .then((data) => {
54
+ if (data && data.success) {
55
+ wc.setAttribute("apikey", data.key);
56
+ }
57
+ });
58
+ }
59
+ }
60
+
61
+ // Generates a HTML table with all attributes of a web component
62
+ function generateAttributesTable(wc, attrs, booleanAttrs = []) {
63
+ let innerHMTL = `<table class="table-auto w-full" >
64
+ <thead>
65
+ <tr>
66
+ <th class="border px-4 py-2">Name</th>
67
+ <!--th class="border px-4 py-2">Default</th>
68
+ <th class="border px-4 py-2">Description</th-->
69
+ <th class="border px-4 py-2">Value</th>
70
+ </tr>
71
+ </thead>
72
+ <tbody>`;
73
+ innerHMTL += attrs
74
+ .sort()
75
+ .map((key) => {
76
+ const isBoolean = booleanAttrs.includes(key);
77
+ return `
78
+ <tr>
79
+ <td class="border px-4 py-2">${key}</td>
80
+ <!--td class="border px-4 py-2"></td>
81
+ <td class="border px-4 py-2"></td-->
82
+ <td class="border px-4 py-2">
83
+ <div class="flex gap-4">
84
+ ${
85
+ isBoolean
86
+ ? `<input
87
+ type="checkbox"
88
+ class="border"
89
+ name="${key}"
90
+ ${wc.getAttribute(key) === "true" ? "checked" : ""}
91
+ onchange="document.querySelector('${wc.localName}').setAttribute('${key}', this.checked);onAttributeUpdate(document.querySelector('${wc.localName}'),this.name, this.checked);"
92
+ />`
93
+ : `
94
+ <input
95
+ type="text"
96
+ class="border"
97
+ name="${key}"
98
+ value="${wc.getAttribute(key) || ""}"
99
+ />
100
+ <button class="border p-2 bg-black hover:bg-gray-700 text-white" onclick="document.querySelector('${wc.localName}').setAttribute('${key}', this.previousElementSibling.value);onAttributeUpdate(document.querySelector('${wc.localName}'),this.previousElementSibling.name, this.previousElementSibling.value);">Update</button>`
101
+ }
102
+ </div>
103
+ </td>
104
+ </tr>
105
+ `;
106
+ })
107
+ .join("");
108
+
109
+ innerHMTL += `</tbody>
110
+ </table>`;
111
+ return innerHMTL;
112
+ }
113
+
114
+ // Generates a code text for the web component
115
+ function generateCodeText(
116
+ wc,
117
+ attrs,
118
+ pkgSrc = "https://www.unpkg.com/@geops/mobility-web-component",
119
+ ) {
120
+ let codeText = "";
121
+ codeText = `&lt;script\n\ttype="module"\n\tsrc="${pkgSrc}"&gt;
122
+ &lt;/script&gt;
123
+ &lt;${wc.localName} style="display:block;width:100%;height:500px;"`;
124
+
125
+ attrs.forEach((key) => {
126
+ const attributeValue = wc.getAttribute(key);
127
+ const inputValue = document.querySelector(`[name=${key}]`).value;
128
+ if (attributeValue !== null && attributeValue === inputValue) {
129
+ codeText += `\n\t${[key, '"' + wc.getAttribute(key) + '"'].join("=")}`;
130
+ }
131
+ });
132
+
133
+ return codeText + `&gt;\n&lt;/${wc.localName}&gt;`;
134
+ }
135
+
136
+ // Generates a HTML table with all events of a web component
137
+ function generateEventsTable(wc, events) {
138
+ let innerHMTL = `<table class="table-auto w-full" >
139
+ <thead>
140
+ <tr>
141
+ <th class="border px-4 py-2">Name</th>
142
+ <th class="border px-4 py-2">Last data received</th>
143
+ </tr>
144
+ </thead>
145
+ <tbody>`;
146
+ innerHMTL += events
147
+ .sort()
148
+ .map((key) => {
149
+ wc.addEventListener(key, (event) => {
150
+ let stringify;
151
+ try {
152
+ stringify = JSON.stringify(event, undefined, 4);
153
+ } catch (e) {
154
+ stringify =
155
+ "Object not stringifyable, open the console (F12) to see the object received.";
156
+ console.log(key + " event", event);
157
+ }
158
+ if (key === "singleclick") {
159
+ stringify = "event.data.lonlat:\n";
160
+ stringify += JSON.stringify(event.data.lonlat, undefined, 4);
161
+ stringify += "\n";
162
+ stringify += "event.data.features:\n";
163
+ stringify += JSON.stringify(event.data.features, undefined, 4);
164
+ }
165
+
166
+ document.querySelector(`[name='${key}']`).value = stringify.toString();
167
+ });
168
+ return `
169
+ <tr>
170
+ <td class="border px-4 py-2">${key}</td>
171
+ <td class="border px-4 py-2">
172
+ <div class="flex gap-4">
173
+ <textarea
174
+ type="text"
175
+ class="border w-full h-300"
176
+ style="height:300px;"
177
+ name="${key}"
178
+ ></textarea>
179
+ </div>
180
+ </td>
181
+ </tr>
182
+ `;
183
+ })
184
+ .join("");
185
+
186
+ innerHMTL += `</tbody>
187
+ </table>`;
188
+
189
+ return innerHMTL;
190
+ }
191
+
192
+ // Update url on attributes update via inputs
193
+ function onAttributeUpdate(wc, key, value) {
194
+ const params = new URLSearchParams(window.location.search);
195
+ params.set(key, value);
196
+ wc.setAttribute(key, value);
197
+ window.history.replaceState({}, "", `${window.location.pathname}?${params}`);
198
+ }