utopia-ui 3.0.99 → 3.0.100

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/dist/Profile.cjs.js +1 -1
  2. package/dist/Profile.esm.js +1 -1
  3. package/dist/TagView-2jiLvob4.js +2536 -0
  4. package/dist/TagView-2jiLvob4.js.map +1 -0
  5. package/dist/TagView-BNJqfuzN.js +2475 -0
  6. package/dist/TagView-BNJqfuzN.js.map +1 -0
  7. package/dist/TagView-Blad8hua.js +2537 -0
  8. package/dist/TagView-Blad8hua.js.map +1 -0
  9. package/dist/TagView-C30AIcCd.js +2447 -0
  10. package/dist/TagView-C30AIcCd.js.map +1 -0
  11. package/dist/TagView-C39h3s-k.js +2446 -0
  12. package/dist/TagView-C39h3s-k.js.map +1 -0
  13. package/dist/TagView-C6Dx0Dh8.js +2421 -0
  14. package/dist/TagView-C6Dx0Dh8.js.map +1 -0
  15. package/dist/TagView-C6MBSYla.js +2458 -0
  16. package/dist/TagView-C6MBSYla.js.map +1 -0
  17. package/dist/TagView-CKy_mUeP.js +2452 -0
  18. package/dist/TagView-CKy_mUeP.js.map +1 -0
  19. package/dist/TagView-Cc1KiOit.js +2448 -0
  20. package/dist/TagView-Cc1KiOit.js.map +1 -0
  21. package/dist/TagView-Cmyr_keb.js +2534 -0
  22. package/dist/TagView-Cmyr_keb.js.map +1 -0
  23. package/dist/TagView-CnC-jC7a.js +2446 -0
  24. package/dist/TagView-CnC-jC7a.js.map +1 -0
  25. package/dist/TagView-Cwbv3fc4.js +2537 -0
  26. package/dist/TagView-Cwbv3fc4.js.map +1 -0
  27. package/dist/TagView-CyuG8PpX.js +2534 -0
  28. package/dist/TagView-CyuG8PpX.js.map +1 -0
  29. package/dist/TagView-D1LJxPBD.js +2536 -0
  30. package/dist/TagView-D1LJxPBD.js.map +1 -0
  31. package/dist/TagView-D6Fb7Bnn.js +2448 -0
  32. package/dist/TagView-D6Fb7Bnn.js.map +1 -0
  33. package/dist/TagView-D7I5i9Id.js +2447 -0
  34. package/dist/TagView-D7I5i9Id.js.map +1 -0
  35. package/dist/TagView-DAccEvdL.js +2449 -0
  36. package/dist/TagView-DAccEvdL.js.map +1 -0
  37. package/dist/TagView-DBnaw5Z_.js +2534 -0
  38. package/dist/TagView-DBnaw5Z_.js.map +1 -0
  39. package/dist/TagView-DOpvHy3K.js +2546 -0
  40. package/dist/TagView-DOpvHy3K.js.map +1 -0
  41. package/dist/TagView-DVEva51q.js +2447 -0
  42. package/dist/TagView-DVEva51q.js.map +1 -0
  43. package/dist/TagView-Dj1DIwd9.js +2563 -0
  44. package/dist/TagView-Dj1DIwd9.js.map +1 -0
  45. package/dist/TagView-DkD9R8Ks.js +2555 -0
  46. package/dist/TagView-DkD9R8Ks.js.map +1 -0
  47. package/dist/TagView-Dlo9w6sj.js +2555 -0
  48. package/dist/TagView-Dlo9w6sj.js.map +1 -0
  49. package/dist/TagView-FIrKNfyW.js +2546 -0
  50. package/dist/TagView-FIrKNfyW.js.map +1 -0
  51. package/dist/TagView-OejXbaY0.js +2449 -0
  52. package/dist/TagView-OejXbaY0.js.map +1 -0
  53. package/dist/TagView-PIFUvlwR.js +2447 -0
  54. package/dist/TagView-PIFUvlwR.js.map +1 -0
  55. package/dist/TagView-VEMo7xsv.js +2535 -0
  56. package/dist/TagView-VEMo7xsv.js.map +1 -0
  57. package/dist/TagView-bKNASls5.js +2535 -0
  58. package/dist/TagView-bKNASls5.js.map +1 -0
  59. package/dist/TagView-cU-_Gn3Y.js +2446 -0
  60. package/dist/TagView-cU-_Gn3Y.js.map +1 -0
  61. package/dist/TagView-dDwQhjw4.js +2467 -0
  62. package/dist/TagView-dDwQhjw4.js.map +1 -0
  63. package/dist/TagView-fKUf2qY8.js +2540 -0
  64. package/dist/TagView-fKUf2qY8.js.map +1 -0
  65. package/dist/TagView-fh0Ok5SJ.js +2535 -0
  66. package/dist/TagView-fh0Ok5SJ.js.map +1 -0
  67. package/dist/TagView-m_oIhU7B.js +2458 -0
  68. package/dist/TagView-m_oIhU7B.js.map +1 -0
  69. package/dist/TagView-owB0HoNH.js +2535 -0
  70. package/dist/TagView-owB0HoNH.js.map +1 -0
  71. package/dist/TagView-rCv-3rVA.js +2467 -0
  72. package/dist/TagView-rCv-3rVA.js.map +1 -0
  73. package/dist/TagView-sqUMjBmG.js +2508 -0
  74. package/dist/TagView-sqUMjBmG.js.map +1 -0
  75. package/dist/index.cjs.js +12 -7
  76. package/dist/index.cjs.js.map +1 -1
  77. package/dist/index.esm.js +13 -8
  78. package/dist/index.esm.js.map +1 -1
  79. package/dist/types/src/Components/Map/Subcomponents/SelectPosition.d.ts +5 -2
  80. package/package.json +1 -1
@@ -0,0 +1,2421 @@
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+ import { createContext, useContext, useState, useReducer, useCallback, useEffect, createRef, useRef } from 'react';
4
+ import { toast } from 'react-toastify';
5
+ import require$$0, { DomEvent } from 'leaflet';
6
+ import Markdown from 'react-markdown';
7
+ import remarkBreaks from 'remark-breaks';
8
+ import { useNavigate } from 'react-router-dom';
9
+ import SVG from 'react-inlinesvg';
10
+
11
+ const ClusterRefContext = createContext({
12
+ clusterRef: {},
13
+ setClusterRef: () => { },
14
+ });
15
+ function useClusterRefManager() {
16
+ const [clusterRef, setClusterRef] = useState({});
17
+ return { clusterRef, setClusterRef };
18
+ }
19
+ const ClusterRefProvider = ({ children }) => (jsx(ClusterRefContext.Provider, { value: useClusterRefManager(), children: children }));
20
+ const useClusterRef = () => {
21
+ const { clusterRef } = useContext(ClusterRefContext);
22
+ return clusterRef;
23
+ };
24
+ const useSetClusterRef = () => {
25
+ const { setClusterRef } = useContext(ClusterRefContext);
26
+ return setClusterRef;
27
+ };
28
+
29
+ const LayerContext = createContext({
30
+ layers: [],
31
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
32
+ addLayer: () => { },
33
+ });
34
+ function useLayerManager(initialLayers) {
35
+ const [layers, dispatch] = useReducer((state, action) => {
36
+ switch (action.type) {
37
+ case 'ADD LAYER':
38
+ // eslint-disable-next-line no-case-declarations
39
+ const exist = state.find((layer) => layer.name === action.layer.name);
40
+ if (!exist) {
41
+ return [...state, action.layer];
42
+ }
43
+ else
44
+ return state;
45
+ default:
46
+ throw new Error();
47
+ }
48
+ }, initialLayers);
49
+ const addLayer = useCallback((layer) => {
50
+ dispatch({
51
+ type: 'ADD LAYER',
52
+ layer,
53
+ });
54
+ }, []);
55
+ return { layers, addLayer };
56
+ }
57
+ const LayersProvider = ({ initialLayers, children }) => (jsx(LayerContext.Provider, { value: useLayerManager(initialLayers), children: children }));
58
+ const useLayers = () => {
59
+ const { layers } = useContext(LayerContext);
60
+ return layers;
61
+ };
62
+ const useAddLayer = () => {
63
+ const { addLayer } = useContext(LayerContext);
64
+ return addLayer;
65
+ };
66
+
67
+ function getWindowDimensions() {
68
+ const { innerWidth: width, innerHeight: height } = window;
69
+ return {
70
+ width,
71
+ height,
72
+ };
73
+ }
74
+ function useWindowDimensions() {
75
+ const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());
76
+ useEffect(() => {
77
+ function handleResize() {
78
+ setWindowDimensions(getWindowDimensions());
79
+ }
80
+ window.addEventListener('resize', handleResize);
81
+ return () => window.removeEventListener('resize', handleResize);
82
+ }, []);
83
+ return windowDimensions;
84
+ }
85
+
86
+ const FilterContext = createContext({
87
+ filterTags: [],
88
+ searchPhrase: '',
89
+ visibleLayers: [],
90
+ visibleGroupTypes: [],
91
+ addFilterTag: () => { },
92
+ removeFilterTag: () => { },
93
+ resetFilterTags: () => { },
94
+ setSearchPhrase: () => { },
95
+ addVisibleLayer: () => { },
96
+ toggleVisibleLayer: () => { },
97
+ resetVisibleLayers: () => { },
98
+ isLayerVisible: () => true,
99
+ addVisibleGroupType: () => { },
100
+ toggleVisibleGroupType: () => { },
101
+ isGroupTypeVisible: () => true,
102
+ });
103
+ function useFilterManager(initialTags) {
104
+ const [filterTags, dispatchTags] = useReducer((state, action) => {
105
+ switch (action.type) {
106
+ case 'ADD_TAG':
107
+ const exist = state.find((tag) => tag.id === action.tag.id);
108
+ if (!exist) {
109
+ return [...state, action.tag];
110
+ }
111
+ else
112
+ return state;
113
+ case 'REMOVE_TAG':
114
+ return state.filter(({ name }) => name !== action.name);
115
+ case 'RESET_TAGS':
116
+ return initialTags;
117
+ default:
118
+ throw new Error();
119
+ }
120
+ }, initialTags);
121
+ const initialLayers = useLayers();
122
+ const navigate = useNavigate();
123
+ const windowDimensions = useWindowDimensions();
124
+ const [visibleLayers, dispatchLayers] = useReducer((state, action) => {
125
+ switch (action.type) {
126
+ case 'ADD_LAYER':
127
+ const exist1 = state.find((layer) => layer.name === action.layer.name);
128
+ if (!exist1) {
129
+ return [...state, action.layer];
130
+ }
131
+ else
132
+ return state;
133
+ case 'TOGGLE_LAYER':
134
+ const exist2 = state.some((layer) => layer.name === action.layer.name);
135
+ if (exist2)
136
+ return state.filter(({ name }) => name !== action.layer.name);
137
+ else
138
+ return [...state, action.layer];
139
+ case 'RESET_LAYERS':
140
+ return initialLayers;
141
+ default:
142
+ throw new Error();
143
+ }
144
+ }, initialLayers);
145
+ const allLayers = useLayers();
146
+ useEffect(() => {
147
+ if (allLayers.length === 0)
148
+ return;
149
+ const visibleNames = visibleLayers.map((l) => l.name);
150
+ const allNames = allLayers.map((l) => l.name);
151
+ const params = new URLSearchParams(location.search);
152
+ const allVisible = visibleNames.length === allNames.length &&
153
+ visibleNames.every((name) => allNames.includes(name));
154
+ if (allVisible) {
155
+ params.delete('layers');
156
+ }
157
+ else {
158
+ params.set('layers', visibleNames.join(','));
159
+ }
160
+ navigate(`${location.pathname}?${params.toString()}`, { replace: true });
161
+ }, [visibleLayers, allLayers, navigate]);
162
+ const [visibleGroupTypes, dispatchGroupTypes] = useReducer((state, action) => {
163
+ switch (action.type) {
164
+ case 'ADD_GROUP_TYPE':
165
+ const exist1 = state.find((groupType) => groupType === action.groupType);
166
+ if (!exist1) {
167
+ return [...state, action.groupType];
168
+ }
169
+ else
170
+ return state;
171
+ case 'TOGGLE_GROUP_TYPE':
172
+ const exist2 = state.some((groupType) => groupType === action.groupType);
173
+ if (exist2)
174
+ return state.filter((groupType) => groupType !== action.groupType);
175
+ else
176
+ return [...state, action.groupType];
177
+ case 'RESET_GROUP_TYPE':
178
+ return [];
179
+ default:
180
+ throw new Error();
181
+ }
182
+ }, []);
183
+ const [searchPhrase, searchPhraseSet] = useState('');
184
+ const addFilterTag = useCallback((tag) => {
185
+ const params = new URLSearchParams(location.search);
186
+ const urlTags = params.get('tags');
187
+ const decodedTags = urlTags ? decodeURIComponent(urlTags) : '';
188
+ if (!decodedTags.includes(tag.name)) {
189
+ params.set('tags', `${urlTags || ''}${urlTags ? ';' : ''}${tag.name}`);
190
+ }
191
+ if (windowDimensions.width < 786 && location.pathname.split('/').length > 2)
192
+ navigate('/' + `${params ? `?${params}` : ''}`);
193
+ else
194
+ navigate(location.pathname + `${params ? `?${params}` : ''}`);
195
+ dispatchTags({
196
+ type: 'ADD_TAG',
197
+ tag,
198
+ });
199
+ // eslint-disable-next-line react-hooks/exhaustive-deps
200
+ }, []);
201
+ const removeFilterTag = useCallback((name) => {
202
+ const params = new URLSearchParams(window.location.search);
203
+ const urlTags = params.get('tags');
204
+ let newUrlTags = '';
205
+ const tags = urlTags?.split(';');
206
+ if (tags?.length === 0 && urlTags?.length && urlTags.length > 0)
207
+ tags[0] = urlTags;
208
+ tags?.map((urlTag) => {
209
+ if (!(urlTag.toLocaleLowerCase() === name.toLocaleLowerCase())) {
210
+ newUrlTags = newUrlTags + `${newUrlTags === '' ? urlTag : `;${urlTag}`}`;
211
+ }
212
+ return null;
213
+ });
214
+ if (newUrlTags !== '') {
215
+ params.set('tags', `${newUrlTags}`);
216
+ navigate(location.pathname + `${params ? `?${params}` : ''}`);
217
+ }
218
+ else {
219
+ params.delete('tags');
220
+ navigate(location.pathname + `${params ? `?${params}` : ''}`);
221
+ }
222
+ dispatchTags({
223
+ type: 'REMOVE_TAG',
224
+ name,
225
+ });
226
+ // eslint-disable-next-line react-hooks/exhaustive-deps
227
+ }, []);
228
+ const resetFilterTags = useCallback(() => {
229
+ dispatchTags({
230
+ type: 'RESET_TAGS',
231
+ });
232
+ }, []);
233
+ const addVisibleLayer = (layer) => {
234
+ dispatchLayers({
235
+ type: 'ADD_LAYER',
236
+ layer,
237
+ });
238
+ };
239
+ const toggleVisibleLayer = (layer) => {
240
+ dispatchLayers({
241
+ type: 'TOGGLE_LAYER',
242
+ layer,
243
+ });
244
+ };
245
+ const resetVisibleLayers = useCallback(() => {
246
+ dispatchLayers({
247
+ type: 'RESET_LAYERS',
248
+ });
249
+ }, []);
250
+ const isLayerVisible = useCallback((layer) => {
251
+ return visibleLayers.some((l) => l.name === layer.name);
252
+ }, [visibleLayers]);
253
+ const addVisibleGroupType = (groupType) => {
254
+ dispatchGroupTypes({
255
+ type: 'ADD_GROUP_TYPE',
256
+ groupType,
257
+ });
258
+ };
259
+ const toggleVisibleGroupType = (groupType) => {
260
+ dispatchGroupTypes({
261
+ type: 'TOGGLE_GROUP_TYPE',
262
+ groupType,
263
+ });
264
+ };
265
+ const isGroupTypeVisible = useCallback((groupType) => {
266
+ return visibleGroupTypes.some((gt) => gt === groupType);
267
+ }, [visibleGroupTypes]);
268
+ const setSearchPhrase = useCallback((phrase) => {
269
+ searchPhraseSet(phrase);
270
+ }, []);
271
+ return {
272
+ filterTags,
273
+ addFilterTag,
274
+ removeFilterTag,
275
+ resetFilterTags,
276
+ setSearchPhrase,
277
+ searchPhrase,
278
+ visibleLayers,
279
+ toggleVisibleLayer,
280
+ resetVisibleLayers,
281
+ isLayerVisible,
282
+ addVisibleLayer,
283
+ visibleGroupTypes,
284
+ addVisibleGroupType,
285
+ toggleVisibleGroupType,
286
+ isGroupTypeVisible,
287
+ };
288
+ }
289
+ const FilterProvider = ({ initialTags, children }) => (jsx(FilterContext.Provider, { value: useFilterManager(initialTags), children: children }));
290
+ const useFilterTags = () => {
291
+ const { filterTags } = useContext(FilterContext);
292
+ return filterTags;
293
+ };
294
+ const useAddFilterTag = () => {
295
+ const { addFilterTag } = useContext(FilterContext);
296
+ return addFilterTag;
297
+ };
298
+ const useRemoveFilterTag = () => {
299
+ const { removeFilterTag } = useContext(FilterContext);
300
+ return removeFilterTag;
301
+ };
302
+ const useResetFilterTags = () => {
303
+ const { resetFilterTags } = useContext(FilterContext);
304
+ return resetFilterTags;
305
+ };
306
+ const useAddVisibleLayer = () => {
307
+ const { addVisibleLayer } = useContext(FilterContext);
308
+ return addVisibleLayer;
309
+ };
310
+ const useToggleVisibleLayer = () => {
311
+ const { toggleVisibleLayer } = useContext(FilterContext);
312
+ return toggleVisibleLayer;
313
+ };
314
+ const useIsLayerVisible = () => {
315
+ const { isLayerVisible } = useContext(FilterContext);
316
+ return isLayerVisible;
317
+ };
318
+ const useAddVisibleGroupType = () => {
319
+ const { addVisibleGroupType } = useContext(FilterContext);
320
+ return addVisibleGroupType;
321
+ };
322
+ const useToggleVisibleGroupType = () => {
323
+ const { toggleVisibleGroupType } = useContext(FilterContext);
324
+ return toggleVisibleGroupType;
325
+ };
326
+ const useIsGroupTypeVisible = () => {
327
+ const { isGroupTypeVisible } = useContext(FilterContext);
328
+ return isGroupTypeVisible;
329
+ };
330
+ const useVisibleGroupType = () => {
331
+ const { visibleGroupTypes } = useContext(FilterContext);
332
+ return visibleGroupTypes;
333
+ };
334
+
335
+ const ItemContext = createContext({
336
+ items: [],
337
+ addItem: () => { },
338
+ updateItem: () => { },
339
+ removeItem: () => { },
340
+ resetItems: () => { },
341
+ setItemsApi: () => { },
342
+ setItemsData: () => { },
343
+ allItemsLoaded: false,
344
+ });
345
+ function useItemsManager(initialItems) {
346
+ const addLayer = useAddLayer();
347
+ const [allItemsLoaded, setallItemsLoaded] = useState(false);
348
+ const [items, dispatch] = useReducer((state, action) => {
349
+ switch (action.type) {
350
+ case 'ADD':
351
+ // eslint-disable-next-line no-case-declarations
352
+ const exist = state.find((item) => item.id === action.item.id);
353
+ if (!exist) {
354
+ return [...state, action.item];
355
+ }
356
+ else
357
+ return state;
358
+ case 'UPDATE':
359
+ return state.map((item) => {
360
+ if (item.id === action.item.id) {
361
+ return action.item;
362
+ }
363
+ return item;
364
+ });
365
+ case 'REMOVE':
366
+ return state.filter((item) => item !== action.item);
367
+ case 'RESET':
368
+ return state.filter((item) => item.layer?.name !== action.layer.name);
369
+ default:
370
+ throw new Error();
371
+ }
372
+ }, initialItems);
373
+ const setItemsApi = useCallback(async (layer) => {
374
+ addLayer(layer);
375
+ const result = await toast.promise(layer.api.getItems(), {
376
+ pending: `loading ${layer.name} ...`,
377
+ success: `${layer.name} loaded`,
378
+ error: {
379
+ render({ data }) {
380
+ return `${data}`;
381
+ },
382
+ },
383
+ });
384
+ result.map((item) => {
385
+ dispatch({ type: 'ADD', item: { ...item, layer } });
386
+ return null;
387
+ });
388
+ setallItemsLoaded(true);
389
+ // eslint-disable-next-line react-hooks/exhaustive-deps
390
+ }, []);
391
+ const setItemsData = useCallback((layer) => {
392
+ addLayer(layer);
393
+ layer.data?.map((item) => {
394
+ dispatch({ type: 'ADD', item: { ...item, layer } });
395
+ return null;
396
+ });
397
+ setallItemsLoaded(true);
398
+ // eslint-disable-next-line react-hooks/exhaustive-deps
399
+ }, []);
400
+ const addItem = useCallback(async (item) => {
401
+ dispatch({
402
+ type: 'ADD',
403
+ item,
404
+ });
405
+ }, []);
406
+ const updateItem = useCallback(async (item) => {
407
+ dispatch({
408
+ type: 'UPDATE',
409
+ item,
410
+ });
411
+ }, []);
412
+ const removeItem = useCallback((item) => {
413
+ dispatch({
414
+ type: 'REMOVE',
415
+ item,
416
+ });
417
+ }, []);
418
+ const resetItems = useCallback((layer) => {
419
+ dispatch({
420
+ type: 'RESET',
421
+ layer,
422
+ });
423
+ }, []);
424
+ return {
425
+ items,
426
+ updateItem,
427
+ addItem,
428
+ removeItem,
429
+ resetItems,
430
+ setItemsApi,
431
+ setItemsData,
432
+ allItemsLoaded,
433
+ };
434
+ }
435
+ const ItemsProvider = ({ initialItems, children }) => (jsx(ItemContext.Provider, { value: useItemsManager(initialItems), children: children }));
436
+ const useItems = () => {
437
+ const { items } = useContext(ItemContext);
438
+ return items;
439
+ };
440
+ const useAddItem = () => {
441
+ const { addItem } = useContext(ItemContext);
442
+ return addItem;
443
+ };
444
+ const useUpdateItem = () => {
445
+ const { updateItem } = useContext(ItemContext);
446
+ return updateItem;
447
+ };
448
+ const useRemoveItem = () => {
449
+ const { removeItem } = useContext(ItemContext);
450
+ return removeItem;
451
+ };
452
+ const useSetItemsApi = () => {
453
+ const { setItemsApi } = useContext(ItemContext);
454
+ return setItemsApi;
455
+ };
456
+ const useSetItemsData = () => {
457
+ const { setItemsData } = useContext(ItemContext);
458
+ return setItemsData;
459
+ };
460
+ const useAllItemsLoaded = () => {
461
+ const { allItemsLoaded } = useContext(ItemContext);
462
+ return allItemsLoaded;
463
+ };
464
+
465
+ const LeafletRefsContext = createContext({
466
+ leafletRefs: {},
467
+ addMarker: () => { },
468
+ addPopup: () => { },
469
+ });
470
+ function useLeafletRefsManager(initialLeafletRefs) {
471
+ const [leafletRefs, dispatch] = useReducer((state, action) => {
472
+ switch (action.type) {
473
+ case 'ADD_MARKER':
474
+ return {
475
+ ...state,
476
+ [action.item.id]: {
477
+ ...state[action.item.id],
478
+ marker: action.marker,
479
+ item: action.item,
480
+ },
481
+ };
482
+ case 'ADD_POPUP':
483
+ return {
484
+ ...state,
485
+ [action.item.id]: { ...state[action.item.id], popup: action.popup, item: action.item },
486
+ };
487
+ default:
488
+ throw new Error();
489
+ }
490
+ }, initialLeafletRefs);
491
+ const addMarker = useCallback((item, marker) => {
492
+ dispatch({
493
+ type: 'ADD_MARKER',
494
+ item,
495
+ marker,
496
+ });
497
+ }, []);
498
+ const addPopup = useCallback((item, popup) => {
499
+ dispatch({
500
+ type: 'ADD_POPUP',
501
+ item,
502
+ popup,
503
+ });
504
+ }, []);
505
+ return { leafletRefs, addMarker, addPopup };
506
+ }
507
+ const LeafletRefsProvider = ({ initialLeafletRefs, children }) => (jsx(LeafletRefsContext.Provider, { value: useLeafletRefsManager(initialLeafletRefs), children: children }));
508
+ const useLeafletRefs = () => {
509
+ const { leafletRefs } = useContext(LeafletRefsContext);
510
+ return leafletRefs;
511
+ };
512
+ const useAddMarker = () => {
513
+ const { addMarker } = useContext(LeafletRefsContext);
514
+ return addMarker;
515
+ };
516
+ const useAddPopup = () => {
517
+ const { addPopup } = useContext(LeafletRefsContext);
518
+ return addPopup;
519
+ };
520
+
521
+ const AuthContext = createContext({
522
+ isAuthenticated: false,
523
+ user: null,
524
+ login: () => Promise.reject(Error('Unimplemented')),
525
+ register: () => Promise.reject(Error('Unimplemented')),
526
+ loading: false,
527
+ logout: () => Promise.reject(Error('Unimplemented')),
528
+ updateUser: () => Promise.reject(Error('Unimplemented')),
529
+ token: '',
530
+ requestPasswordReset: () => Promise.reject(Error('Unimplemented')),
531
+ passwordReset: () => Promise.reject(Error('Unimplemented')),
532
+ });
533
+ /**
534
+ * @category Auth
535
+ */
536
+ const AuthProvider = ({ userApi, children }) => {
537
+ const [user, setUser] = useState(null);
538
+ const [token, setToken] = useState();
539
+ const [loading, setLoading] = useState(false);
540
+ const isAuthenticated = !!user;
541
+ useEffect(() => {
542
+ setLoading(true);
543
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
544
+ loadUser();
545
+ setLoading(false);
546
+ // eslint-disable-next-line react-hooks/exhaustive-deps
547
+ }, []);
548
+ async function loadUser() {
549
+ try {
550
+ const token = await userApi.getToken();
551
+ setToken(token);
552
+ if (token) {
553
+ const me = await userApi.getUser();
554
+ setUser(me);
555
+ setLoading(false);
556
+ return me;
557
+ }
558
+ else
559
+ return undefined;
560
+ // eslint-disable-next-line no-catch-all/no-catch-all
561
+ }
562
+ catch (error) {
563
+ setLoading(false);
564
+ return undefined;
565
+ }
566
+ }
567
+ const login = async (credentials) => {
568
+ setLoading(true);
569
+ try {
570
+ const user = await userApi.login(credentials.email, credentials.password);
571
+ setToken(user?.access_token);
572
+ return await loadUser();
573
+ }
574
+ catch (error) {
575
+ setLoading(false);
576
+ throw error;
577
+ }
578
+ };
579
+ const register = async (credentials, userName) => {
580
+ setLoading(true);
581
+ try {
582
+ /* const res = */ await userApi.register(credentials.email, credentials.password, userName);
583
+ return await login(credentials);
584
+ }
585
+ catch (error) {
586
+ setLoading(false);
587
+ throw error;
588
+ }
589
+ };
590
+ const logout = async () => {
591
+ try {
592
+ await userApi.logout();
593
+ setUser(null);
594
+ }
595
+ catch (error) {
596
+ setLoading(false);
597
+ throw error;
598
+ }
599
+ };
600
+ const updateUser = async (user) => {
601
+ setLoading(true);
602
+ try {
603
+ const updatedUser = await userApi.updateUser(user);
604
+ setUser(updatedUser);
605
+ await loadUser();
606
+ setLoading(false);
607
+ return updatedUser;
608
+ }
609
+ catch (error) {
610
+ setLoading(false);
611
+ throw error;
612
+ }
613
+ };
614
+ const requestPasswordReset = async (email, resetUrl) => {
615
+ setLoading(true);
616
+ try {
617
+ await userApi.requestPasswordReset(email, resetUrl);
618
+ return setLoading(false);
619
+ }
620
+ catch (error) {
621
+ setLoading(false);
622
+ throw error;
623
+ }
624
+ };
625
+ const passwordReset = async (token, newPassword) => {
626
+ setLoading(true);
627
+ try {
628
+ await userApi.passwordReset(token, newPassword);
629
+ return setLoading(false);
630
+ }
631
+ catch (error) {
632
+ setLoading(false);
633
+ throw error;
634
+ }
635
+ };
636
+ return (jsx(AuthContext.Provider, { value: {
637
+ isAuthenticated,
638
+ user,
639
+ login,
640
+ register,
641
+ loading,
642
+ logout,
643
+ updateUser,
644
+ token,
645
+ requestPasswordReset,
646
+ passwordReset,
647
+ }, children: children }));
648
+ };
649
+ const useAuth = () => useContext(AuthContext);
650
+
651
+ const PermissionContext = createContext({
652
+ permissions: [],
653
+ setPermissionApi: () => { },
654
+ setPermissionData: () => { },
655
+ setAdminRole: () => { },
656
+ hasUserPermission: () => true,
657
+ });
658
+ function usePermissionsManager(initialPermissions) {
659
+ const [permissions, dispatch] = useReducer((state, action) => {
660
+ switch (action.type) {
661
+ case 'ADD':
662
+ // eslint-disable-next-line no-case-declarations
663
+ const exist = state.find((permission) => permission.id === action.permission.id);
664
+ if (!exist) {
665
+ return [...state, action.permission];
666
+ }
667
+ else
668
+ return state;
669
+ case 'REMOVE':
670
+ return state.filter(({ id }) => id !== action.id);
671
+ default:
672
+ throw new Error();
673
+ }
674
+ }, initialPermissions);
675
+ const [adminRole, setAdminRole] = useState(null);
676
+ const { user } = useAuth();
677
+ const setPermissionApi = useCallback(async (api) => {
678
+ const result = await api.getItems();
679
+ result.map((permission) => {
680
+ dispatch({ type: 'ADD', permission });
681
+ return null;
682
+ });
683
+ }, []);
684
+ const setPermissionData = useCallback((data) => {
685
+ data.map((permission) => {
686
+ dispatch({ type: 'ADD', permission });
687
+ return null;
688
+ });
689
+ }, []);
690
+ const hasUserPermission = useCallback((collectionName, action, item, layer) => {
691
+ const evaluateCondition = (condition) => {
692
+ if (condition.user_created?._eq === '$CURRENT_USER') {
693
+ return item?.user_created?.id === user?.id;
694
+ }
695
+ if (condition.public_edit?._eq === true) {
696
+ return item?.public_edit === true;
697
+ }
698
+ return false;
699
+ };
700
+ const evaluatePermissions = (permissionConditions) => {
701
+ if (!permissionConditions?._and) {
702
+ return true;
703
+ }
704
+ return permissionConditions._and.every((andCondition) => andCondition._or
705
+ ? andCondition._or.some((orCondition) => evaluateCondition(orCondition))
706
+ : evaluateCondition(andCondition));
707
+ };
708
+ if (collectionName === 'items' && action === 'create' && layer?.public_edit_items)
709
+ return true;
710
+ // Bedingung für leere Berechtigungen nur, wenn NICHT item und create
711
+ if (permissions.length === 0)
712
+ return true;
713
+ else if (user && user.role?.id === adminRole)
714
+ return true;
715
+ else {
716
+ return permissions.some((p) => p.action === action &&
717
+ p.collection === collectionName &&
718
+ ((p.policy?.name === user?.role?.name &&
719
+ (!item || evaluatePermissions(p.permissions))) ||
720
+ (p.policy?.name === '$t:public_label' &&
721
+ (layer?.public_edit_items || item?.layer?.public_edit_items) &&
722
+ (!item || evaluatePermissions(p.permissions)))));
723
+ }
724
+ }, [permissions, user, adminRole]);
725
+ return { permissions, setPermissionApi, setPermissionData, setAdminRole, hasUserPermission };
726
+ }
727
+ const PermissionsProvider = ({ initialPermissions, children, }) => (jsx(PermissionContext.Provider, { value: usePermissionsManager(initialPermissions), children: children }));
728
+ const useSetPermissionApi = () => {
729
+ const { setPermissionApi } = useContext(PermissionContext);
730
+ return setPermissionApi;
731
+ };
732
+ const useSetPermissionData = () => {
733
+ const { setPermissionData } = useContext(PermissionContext);
734
+ return setPermissionData;
735
+ };
736
+ const useHasUserPermission = () => {
737
+ const { hasUserPermission } = useContext(PermissionContext);
738
+ return hasUserPermission;
739
+ };
740
+ const useSetAdminRole = () => {
741
+ const { setAdminRole } = useContext(PermissionContext);
742
+ return setAdminRole;
743
+ };
744
+
745
+ const SelectPositionContext = createContext({
746
+ selectPosition: null,
747
+ setSelectPosition: () => { },
748
+ setMarkerClicked: () => { },
749
+ setMapClicked: () => { },
750
+ });
751
+ function useSelectPositionManager() {
752
+ const [selectPosition, setSelectPosition] = useState(null);
753
+ const [markerClicked, setMarkerClicked] = useState();
754
+ const [mapClicked, setMapClicked] = useState();
755
+ const updateItem = useUpdateItem();
756
+ const hasUserPermission = useHasUserPermission();
757
+ useEffect(() => {
758
+ if (selectPosition &&
759
+ markerClicked &&
760
+ 'text' in selectPosition &&
761
+ markerClicked.id !== selectPosition.id) {
762
+ itemUpdateParent({ ...selectPosition, parent: markerClicked.id });
763
+ }
764
+ // eslint-disable-next-line react-hooks/exhaustive-deps
765
+ }, [markerClicked]);
766
+ useEffect(() => {
767
+ if (selectPosition != null) {
768
+ // selectPosition can be null, Layer or Item
769
+ if ('menuIcon' in selectPosition) {
770
+ // if selectPosition is a Layer
771
+ mapClicked &&
772
+ mapClicked.setItemFormPopup({
773
+ layer: selectPosition,
774
+ position: mapClicked.position,
775
+ });
776
+ setSelectPosition(null);
777
+ }
778
+ if ('text' in selectPosition) {
779
+ // if selectPosition is an Item
780
+ const position = mapClicked?.position.lng &&
781
+ {
782
+ type: 'Point',
783
+ coordinates: [mapClicked.position.lng, mapClicked.position.lat],
784
+ };
785
+ position && itemUpdatePosition({ ...selectPosition, position });
786
+ setSelectPosition(null);
787
+ }
788
+ }
789
+ // eslint-disable-next-line react-hooks/exhaustive-deps
790
+ }, [mapClicked]);
791
+ const itemUpdateParent = async (updatedItem) => {
792
+ if (markerClicked?.layer?.api?.collectionName &&
793
+ hasUserPermission(markerClicked.layer.api.collectionName, 'update', markerClicked)) {
794
+ let success = false;
795
+ try {
796
+ await updatedItem.layer?.api?.updateItem({
797
+ id: updatedItem.id,
798
+ parent: updatedItem.parent,
799
+ position: null,
800
+ });
801
+ success = true;
802
+ // eslint-disable-next-line no-catch-all/no-catch-all
803
+ }
804
+ catch (error) {
805
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
806
+ toast.error(error.toString());
807
+ }
808
+ if (success) {
809
+ await updateItem({ ...updatedItem, parent: updatedItem.parent, position: undefined });
810
+ await linkItem(updatedItem.id);
811
+ toast.success('Item position updated');
812
+ setSelectPosition(null);
813
+ setMarkerClicked(null);
814
+ }
815
+ }
816
+ else {
817
+ setSelectPosition(null);
818
+ toast.error("you don't have permission to add items to " + markerClicked?.name);
819
+ }
820
+ };
821
+ const itemUpdatePosition = async (updatedItem) => {
822
+ let success = false;
823
+ try {
824
+ await updatedItem.layer?.api?.updateItem({
825
+ id: updatedItem.id,
826
+ position: updatedItem.position,
827
+ });
828
+ success = true;
829
+ // eslint-disable-next-line no-catch-all/no-catch-all
830
+ }
831
+ catch (error) {
832
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
833
+ toast.error(error.toString());
834
+ }
835
+ if (success) {
836
+ updateItem(updatedItem);
837
+ toast.success('Item position updated');
838
+ }
839
+ };
840
+ const linkItem = async (id) => {
841
+ if (markerClicked) {
842
+ const newRelations = markerClicked.relations || [];
843
+ if (!newRelations.some((r) => r.related_items_id === id)) {
844
+ newRelations.push({ items_id: markerClicked.id, related_items_id: id });
845
+ const updatedItem = { id: markerClicked.id, relations: newRelations };
846
+ let success = false;
847
+ try {
848
+ await markerClicked.layer?.api?.updateItem(updatedItem);
849
+ success = true;
850
+ // eslint-disable-next-line no-catch-all/no-catch-all
851
+ }
852
+ catch (error) {
853
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
854
+ toast.error(error.toString());
855
+ }
856
+ if (success) {
857
+ updateItem({ ...markerClicked, relations: newRelations });
858
+ toast.success('Item linked');
859
+ }
860
+ }
861
+ }
862
+ };
863
+ return { selectPosition, setSelectPosition, setMarkerClicked, setMapClicked };
864
+ }
865
+ const SelectPositionProvider = ({ children }) => (jsx(SelectPositionContext.Provider, { value: useSelectPositionManager(), children: children }));
866
+ const useSelectPosition = () => {
867
+ const { selectPosition } = useContext(SelectPositionContext);
868
+ return selectPosition;
869
+ };
870
+ const useSetSelectPosition = () => {
871
+ const { setSelectPosition } = useContext(SelectPositionContext);
872
+ return setSelectPosition;
873
+ };
874
+ const useSetMarkerClicked = () => {
875
+ const { setMarkerClicked } = useContext(SelectPositionContext);
876
+ return setMarkerClicked;
877
+ };
878
+ const useSetMapClicked = () => {
879
+ const { setMapClicked } = useContext(SelectPositionContext);
880
+ return setMapClicked;
881
+ };
882
+
883
+ const hashTagRegex = /(#+[a-zA-Z0-9À-ÖØ-öø-ʸ_-]{1,})/g;
884
+
885
+ const TagContext = createContext({
886
+ tags: [],
887
+ addTag: () => { },
888
+ setTagApi: () => { },
889
+ setTagData: () => { },
890
+ getItemTags: () => [],
891
+ allTagsLoaded: false,
892
+ });
893
+ function useTagsManager(initialTags) {
894
+ const [allTagsLoaded, setallTagsLoaded] = useState(false);
895
+ const [tagCount, setTagCount] = useState(0);
896
+ const [tags, dispatch] = useReducer((state, action) => {
897
+ switch (action.type) {
898
+ case 'ADD':
899
+ // eslint-disable-next-line no-case-declarations
900
+ const exist = state.find((tag) => tag.name.toLocaleLowerCase() === action.tag.name.toLocaleLowerCase());
901
+ if (!exist) {
902
+ const newState = [...state, { ...action.tag }];
903
+ if (tagCount === newState.length)
904
+ setallTagsLoaded(true);
905
+ return newState;
906
+ }
907
+ else
908
+ return state;
909
+ default:
910
+ throw new Error();
911
+ }
912
+ }, initialTags);
913
+ const [api, setApi] = useState({});
914
+ const setTagApi = useCallback(async (api) => {
915
+ setApi(api);
916
+ const result = await api.getItems();
917
+ setTagCount(result.length);
918
+ if (tagCount === 0)
919
+ setallTagsLoaded(true);
920
+ if (result) {
921
+ result.map((tag) => {
922
+ // tag.name = tag.name.toLocaleLowerCase();
923
+ dispatch({ type: 'ADD', tag });
924
+ return null;
925
+ });
926
+ }
927
+ // eslint-disable-next-line react-hooks/exhaustive-deps
928
+ }, []);
929
+ const setTagData = useCallback((data) => {
930
+ data.map((tag) => {
931
+ // tag.name = tag.name.toLocaleLowerCase();
932
+ dispatch({ type: 'ADD', tag });
933
+ return null;
934
+ });
935
+ }, []);
936
+ const addTag = (tag) => {
937
+ dispatch({
938
+ type: 'ADD',
939
+ tag,
940
+ });
941
+ if (!tags.some((t) => t.name.toLocaleLowerCase() === tag.name.toLocaleLowerCase())) {
942
+ api.createItem && api.createItem(tag);
943
+ }
944
+ };
945
+ const getItemTags = useCallback((item) => {
946
+ const text = item.text;
947
+ const itemTagStrings = text?.match(hashTagRegex);
948
+ const itemTags = [];
949
+ itemTagStrings?.map((tag) => {
950
+ if (tags.find((t) => t.name.toLocaleLowerCase() === tag.slice(1).toLocaleLowerCase())) {
951
+ itemTags.push(tags.find((t) => t.name.toLocaleLowerCase() === tag.slice(1).toLocaleLowerCase()));
952
+ }
953
+ return null;
954
+ });
955
+ // Could be refactored as it occurs in multiple places
956
+ item.offers?.forEach((o) => {
957
+ const offer = tags.find((t) => t.id === o.tags_id);
958
+ offer && itemTags.push(offer);
959
+ });
960
+ item.needs?.forEach((n) => {
961
+ const need = tags.find((t) => t.id === n.tags_id);
962
+ need && itemTags.push(need);
963
+ });
964
+ return itemTags;
965
+ }, [tags]);
966
+ return { tags, addTag, setTagApi, setTagData, getItemTags, allTagsLoaded };
967
+ }
968
+ const TagsProvider = ({ initialTags, children }) => (jsx(TagContext.Provider, { value: useTagsManager(initialTags), children: children }));
969
+ const useTags = () => {
970
+ const { tags } = useContext(TagContext);
971
+ return tags;
972
+ };
973
+ const useAddTag = () => {
974
+ const { addTag } = useContext(TagContext);
975
+ return addTag;
976
+ };
977
+ const useSetTagApi = () => {
978
+ const { setTagApi } = useContext(TagContext);
979
+ return setTagApi;
980
+ };
981
+ const useSetTagData = () => {
982
+ const { setTagData } = useContext(TagContext);
983
+ return setTagData;
984
+ };
985
+ const useGetItemTags = () => {
986
+ const { getItemTags } = useContext(TagContext);
987
+ return getItemTags;
988
+ };
989
+ const useAllTagsLoaded = () => {
990
+ const { allTagsLoaded } = useContext(TagContext);
991
+ return allTagsLoaded;
992
+ };
993
+
994
+ const initialAppState = {
995
+ assetsApi: {},
996
+ sideBarOpen: false,
997
+ sideBarSlim: false,
998
+ showThemeControl: false,
999
+ embedded: false,
1000
+ openCollectiveApiKey: '',
1001
+ };
1002
+ const AppContext = createContext({
1003
+ state: initialAppState,
1004
+ setAppState: () => { },
1005
+ });
1006
+ function useAppManager() {
1007
+ const [state, setState] = useState(initialAppState);
1008
+ const setAppState = useCallback((newState) => {
1009
+ setState((prevState) => ({
1010
+ ...prevState,
1011
+ ...newState,
1012
+ }));
1013
+ }, []);
1014
+ return { state, setAppState };
1015
+ }
1016
+ const AppStateProvider = ({ children }) => jsx(AppContext.Provider, { value: useAppManager(), children: children });
1017
+ const useAppState = () => {
1018
+ const { state } = useContext(AppContext);
1019
+ return state;
1020
+ };
1021
+ const useSetAppState = () => {
1022
+ const { setAppState } = useContext(AppContext);
1023
+ return setAppState;
1024
+ };
1025
+
1026
+ function decodeTag(string) {
1027
+ const formatedTag = string.replace(/_/g, '\u00A0');
1028
+ return formatedTag.charAt(0).toUpperCase() + formatedTag.slice(1);
1029
+ }
1030
+ function encodeTag(string) {
1031
+ return string.replace(/\s+/g, '_');
1032
+ }
1033
+
1034
+ var L_Control_Locate = {exports: {}};
1035
+
1036
+ /*!
1037
+ Copyright (c) 2016 Dominik Moritz
1038
+
1039
+ This file is part of the leaflet locate control. It is licensed under the MIT license.
1040
+ You can find the project at: https://github.com/domoritz/leaflet-locatecontrol
1041
+ */
1042
+
1043
+ var hasRequiredL_Control_Locate;
1044
+
1045
+ function requireL_Control_Locate () {
1046
+ if (hasRequiredL_Control_Locate) return L_Control_Locate.exports;
1047
+ hasRequiredL_Control_Locate = 1;
1048
+ (function (module, exports) {
1049
+ (function (factory, window) {
1050
+ // see https://github.com/Leaflet/Leaflet/blob/master/PLUGIN-GUIDE.md#module-loaders
1051
+ // for details on how to structure a leaflet plugin.
1052
+
1053
+ // define an AMD module that relies on 'leaflet'
1054
+ {
1055
+ if (typeof window !== "undefined" && window.L) {
1056
+ module.exports = factory(L);
1057
+ } else {
1058
+ module.exports = factory(require$$0);
1059
+ }
1060
+ }
1061
+
1062
+ // attach your plugin to the global 'L' variable
1063
+ if (typeof window !== "undefined" && window.L) {
1064
+ window.L.Control.Locate = factory(L);
1065
+ }
1066
+ })(function (L) {
1067
+ const LDomUtilApplyClassesMethod = (method, element, classNames) => {
1068
+ classNames = classNames.split(" ");
1069
+ classNames.forEach(function (className) {
1070
+ L.DomUtil[method].call(this, element, className);
1071
+ });
1072
+ };
1073
+
1074
+ const addClasses = (el, names) => LDomUtilApplyClassesMethod("addClass", el, names);
1075
+ const removeClasses = (el, names) => LDomUtilApplyClassesMethod("removeClass", el, names);
1076
+
1077
+ /**
1078
+ * Compatible with L.Circle but a true marker instead of a path
1079
+ */
1080
+ const LocationMarker = L.Marker.extend({
1081
+ initialize(latlng, options) {
1082
+ L.Util.setOptions(this, options);
1083
+ this._latlng = latlng;
1084
+ this.createIcon();
1085
+ },
1086
+
1087
+ /**
1088
+ * Create a styled circle location marker
1089
+ */
1090
+ createIcon() {
1091
+ const opt = this.options;
1092
+
1093
+ let style = "";
1094
+
1095
+ if (opt.color !== undefined) {
1096
+ style += `stroke:${opt.color};`;
1097
+ }
1098
+ if (opt.weight !== undefined) {
1099
+ style += `stroke-width:${opt.weight};`;
1100
+ }
1101
+ if (opt.fillColor !== undefined) {
1102
+ style += `fill:${opt.fillColor};`;
1103
+ }
1104
+ if (opt.fillOpacity !== undefined) {
1105
+ style += `fill-opacity:${opt.fillOpacity};`;
1106
+ }
1107
+ if (opt.opacity !== undefined) {
1108
+ style += `opacity:${opt.opacity};`;
1109
+ }
1110
+
1111
+ const icon = this._getIconSVG(opt, style);
1112
+
1113
+ this._locationIcon = L.divIcon({
1114
+ className: icon.className,
1115
+ html: icon.svg,
1116
+ iconSize: [icon.w, icon.h]
1117
+ });
1118
+
1119
+ this.setIcon(this._locationIcon);
1120
+ },
1121
+
1122
+ /**
1123
+ * Return the raw svg for the shape
1124
+ *
1125
+ * Split so can be easily overridden
1126
+ */
1127
+ _getIconSVG(options, style) {
1128
+ const r = options.radius;
1129
+ const w = options.weight;
1130
+ const s = r + w;
1131
+ const s2 = s * 2;
1132
+ const svg =
1133
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${s2}" height="${s2}" version="1.1" viewBox="-${s} -${s} ${s2} ${s2}">` +
1134
+ '<circle r="' +
1135
+ r +
1136
+ '" style="' +
1137
+ style +
1138
+ '" />' +
1139
+ "</svg>";
1140
+ return {
1141
+ className: "leaflet-control-locate-location",
1142
+ svg,
1143
+ w: s2,
1144
+ h: s2
1145
+ };
1146
+ },
1147
+
1148
+ setStyle(style) {
1149
+ L.Util.setOptions(this, style);
1150
+ this.createIcon();
1151
+ }
1152
+ });
1153
+
1154
+ const CompassMarker = LocationMarker.extend({
1155
+ initialize(latlng, heading, options) {
1156
+ L.Util.setOptions(this, options);
1157
+ this._latlng = latlng;
1158
+ this._heading = heading;
1159
+ this.createIcon();
1160
+ },
1161
+
1162
+ setHeading(heading) {
1163
+ this._heading = heading;
1164
+ },
1165
+
1166
+ /**
1167
+ * Create a styled arrow compass marker
1168
+ */
1169
+ _getIconSVG(options, style) {
1170
+ const r = options.radius;
1171
+ const w = options.width + options.weight;
1172
+ const h = (r + options.depth + options.weight) * 2;
1173
+ const path = `M0,0 l${options.width / 2},${options.depth} l-${w},0 z`;
1174
+ const svgstyle = `transform: rotate(${this._heading}deg)`;
1175
+ const svg =
1176
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" version="1.1" viewBox="-${w / 2} 0 ${w} ${h}" style="${svgstyle}">` +
1177
+ '<path d="' +
1178
+ path +
1179
+ '" style="' +
1180
+ style +
1181
+ '" />' +
1182
+ "</svg>";
1183
+ return {
1184
+ className: "leaflet-control-locate-heading",
1185
+ svg,
1186
+ w,
1187
+ h
1188
+ };
1189
+ }
1190
+ });
1191
+
1192
+ const LocateControl = L.Control.extend({
1193
+ options: {
1194
+ /** Position of the control */
1195
+ position: "topleft",
1196
+ /** The layer that the user's location should be drawn on. By default creates a new layer. */
1197
+ layer: undefined,
1198
+ /**
1199
+ * Automatically sets the map view (zoom and pan) to the user's location as it updates.
1200
+ * While the map is following the user's location, the control is in the `following` state,
1201
+ * which changes the style of the control and the circle marker.
1202
+ *
1203
+ * Possible values:
1204
+ * - false: never updates the map view when location changes.
1205
+ * - 'once': set the view when the location is first determined
1206
+ * - 'always': always updates the map view when location changes.
1207
+ * The map view follows the user's location.
1208
+ * - 'untilPan': like 'always', except stops updating the
1209
+ * view if the user has manually panned the map.
1210
+ * The map view follows the user's location until she pans.
1211
+ * - 'untilPanOrZoom': (default) like 'always', except stops updating the
1212
+ * view if the user has manually panned the map.
1213
+ * The map view follows the user's location until she pans.
1214
+ */
1215
+ setView: "untilPanOrZoom",
1216
+ /** Keep the current map zoom level when setting the view and only pan. */
1217
+ keepCurrentZoomLevel: false,
1218
+ /** After activating the plugin by clicking on the icon, zoom to the selected zoom level, even when keepCurrentZoomLevel is true. Set to 'false' to disable this feature. */
1219
+ initialZoomLevel: false,
1220
+ /**
1221
+ * This callback can be used to override the viewport tracking
1222
+ * This function should return a LatLngBounds object.
1223
+ *
1224
+ * For example to extend the viewport to ensure that a particular LatLng is visible:
1225
+ *
1226
+ * getLocationBounds: function(locationEvent) {
1227
+ * return locationEvent.bounds.extend([-33.873085, 151.219273]);
1228
+ * },
1229
+ */
1230
+ getLocationBounds(locationEvent) {
1231
+ return locationEvent.bounds;
1232
+ },
1233
+ /** Smooth pan and zoom to the location of the marker. Only works in Leaflet 1.0+. */
1234
+ flyTo: false,
1235
+ /**
1236
+ * The user location can be inside and outside the current view when the user clicks on the
1237
+ * control that is already active. Both cases can be configures separately.
1238
+ * Possible values are:
1239
+ * - 'setView': zoom and pan to the current location
1240
+ * - 'stop': stop locating and remove the location marker
1241
+ */
1242
+ clickBehavior: {
1243
+ /** What should happen if the user clicks on the control while the location is within the current view. */
1244
+ inView: "stop",
1245
+ /** What should happen if the user clicks on the control while the location is outside the current view. */
1246
+ outOfView: "setView",
1247
+ /**
1248
+ * What should happen if the user clicks on the control while the location is within the current view
1249
+ * and we could be following but are not. Defaults to a special value which inherits from 'inView';
1250
+ */
1251
+ inViewNotFollowing: "inView"
1252
+ },
1253
+ /**
1254
+ * If set, save the map bounds just before centering to the user's
1255
+ * location. When control is disabled, set the view back to the
1256
+ * bounds that were saved.
1257
+ */
1258
+ returnToPrevBounds: false,
1259
+ /**
1260
+ * Keep a cache of the location after the user deactivates the control. If set to false, the user has to wait
1261
+ * until the locate API returns a new location before they see where they are again.
1262
+ */
1263
+ cacheLocation: true,
1264
+ /** If set, a circle that shows the location accuracy is drawn. */
1265
+ drawCircle: true,
1266
+ /** If set, the marker at the users' location is drawn. */
1267
+ drawMarker: true,
1268
+ /** If set and supported then show the compass heading */
1269
+ showCompass: true,
1270
+ /** The class to be used to create the marker. For example L.CircleMarker or L.Marker */
1271
+ markerClass: LocationMarker,
1272
+ /** The class us be used to create the compass bearing arrow */
1273
+ compassClass: CompassMarker,
1274
+ /** Accuracy circle style properties. NOTE these styles should match the css animations styles */
1275
+ circleStyle: {
1276
+ className: "leaflet-control-locate-circle",
1277
+ color: "#136AEC",
1278
+ fillColor: "#136AEC",
1279
+ fillOpacity: 0.15,
1280
+ weight: 0
1281
+ },
1282
+ /** Inner marker style properties. Only works if your marker class supports `setStyle`. */
1283
+ markerStyle: {
1284
+ className: "leaflet-control-locate-marker",
1285
+ color: "#fff",
1286
+ fillColor: "#2A93EE",
1287
+ fillOpacity: 1,
1288
+ weight: 3,
1289
+ opacity: 1,
1290
+ radius: 9
1291
+ },
1292
+ /** Compass */
1293
+ compassStyle: {
1294
+ fillColor: "#2A93EE",
1295
+ fillOpacity: 1,
1296
+ weight: 0,
1297
+ color: "#fff",
1298
+ opacity: 1,
1299
+ radius: 9, // How far is the arrow is from the center of of the marker
1300
+ width: 9, // Width of the arrow
1301
+ depth: 6 // Length of the arrow
1302
+ },
1303
+ /**
1304
+ * Changes to accuracy circle and inner marker while following.
1305
+ * It is only necessary to provide the properties that should change.
1306
+ */
1307
+ followCircleStyle: {},
1308
+ followMarkerStyle: {
1309
+ // color: '#FFA500',
1310
+ // fillColor: '#FFB000'
1311
+ },
1312
+ followCompassStyle: {},
1313
+ /** The CSS class for the icon. For example fa-location-arrow or fa-map-marker */
1314
+ icon: "leaflet-control-locate-location-arrow",
1315
+ iconLoading: "leaflet-control-locate-spinner",
1316
+ /** The element to be created for icons. For example span or i */
1317
+ iconElementTag: "span",
1318
+ /** The element to be created for the text. For example small or span */
1319
+ textElementTag: "small",
1320
+ /** Padding around the accuracy circle. */
1321
+ circlePadding: [0, 0],
1322
+ /** Use metric units. */
1323
+ metric: true,
1324
+ /**
1325
+ * This callback can be used in case you would like to override button creation behavior.
1326
+ * This is useful for DOM manipulation frameworks such as angular etc.
1327
+ * This function should return an object with HtmlElement for the button (link property) and the icon (icon property).
1328
+ */
1329
+ createButtonCallback(container, options) {
1330
+ const link = L.DomUtil.create("a", "leaflet-bar-part leaflet-bar-part-single", container);
1331
+ link.title = options.strings.title;
1332
+ link.href = "#";
1333
+ link.setAttribute("role", "button");
1334
+ const icon = L.DomUtil.create(options.iconElementTag, options.icon, link);
1335
+
1336
+ if (options.strings.text !== undefined) {
1337
+ const text = L.DomUtil.create(options.textElementTag, "leaflet-locate-text", link);
1338
+ text.textContent = options.strings.text;
1339
+ link.classList.add("leaflet-locate-text-active");
1340
+ link.parentNode.style.display = "flex";
1341
+ if (options.icon.length > 0) {
1342
+ icon.classList.add("leaflet-locate-icon");
1343
+ }
1344
+ }
1345
+
1346
+ return { link, icon };
1347
+ },
1348
+ /** This event is called in case of any location error that is not a time out error. */
1349
+ onLocationError(err, control) {
1350
+ alert(err.message);
1351
+ },
1352
+ /**
1353
+ * This event is called when the user's location is outside the bounds set on the map.
1354
+ * The event is called repeatedly when the location changes.
1355
+ */
1356
+ onLocationOutsideMapBounds(control) {
1357
+ control.stop();
1358
+ alert(control.options.strings.outsideMapBoundsMsg);
1359
+ },
1360
+ /** Display a pop-up when the user click on the inner marker. */
1361
+ showPopup: true,
1362
+ strings: {
1363
+ title: "Show me where I am",
1364
+ metersUnit: "meters",
1365
+ feetUnit: "feet",
1366
+ popup: "You are within {distance} {unit} from this point",
1367
+ outsideMapBoundsMsg: "You seem located outside the boundaries of the map"
1368
+ },
1369
+ /** The default options passed to leaflets locate method. */
1370
+ locateOptions: {
1371
+ maxZoom: Infinity,
1372
+ watch: true, // if you overwrite this, visualization cannot be updated
1373
+ setView: false // have to set this to false because we have to
1374
+ // do setView manually
1375
+ }
1376
+ },
1377
+
1378
+ initialize(options) {
1379
+ // set default options if nothing is set (merge one step deep)
1380
+ for (const i in options) {
1381
+ if (typeof this.options[i] === "object") {
1382
+ L.extend(this.options[i], options[i]);
1383
+ } else {
1384
+ this.options[i] = options[i];
1385
+ }
1386
+ }
1387
+
1388
+ // extend the follow marker style and circle from the normal style
1389
+ this.options.followMarkerStyle = L.extend({}, this.options.markerStyle, this.options.followMarkerStyle);
1390
+ this.options.followCircleStyle = L.extend({}, this.options.circleStyle, this.options.followCircleStyle);
1391
+ this.options.followCompassStyle = L.extend({}, this.options.compassStyle, this.options.followCompassStyle);
1392
+ },
1393
+
1394
+ /**
1395
+ * Add control to map. Returns the container for the control.
1396
+ */
1397
+ onAdd(map) {
1398
+ const container = L.DomUtil.create("div", "leaflet-control-locate leaflet-bar leaflet-control");
1399
+ this._container = container;
1400
+ this._map = map;
1401
+ this._layer = this.options.layer || new L.LayerGroup();
1402
+ this._layer.addTo(map);
1403
+ this._event = undefined;
1404
+ this._compassHeading = null;
1405
+ this._prevBounds = null;
1406
+
1407
+ const linkAndIcon = this.options.createButtonCallback(container, this.options);
1408
+ this._link = linkAndIcon.link;
1409
+ this._icon = linkAndIcon.icon;
1410
+
1411
+ L.DomEvent.on(
1412
+ this._link,
1413
+ "click",
1414
+ function (ev) {
1415
+ L.DomEvent.stopPropagation(ev);
1416
+ L.DomEvent.preventDefault(ev);
1417
+ this._onClick();
1418
+ },
1419
+ this
1420
+ ).on(this._link, "dblclick", L.DomEvent.stopPropagation);
1421
+
1422
+ this._resetVariables();
1423
+
1424
+ this._map.on("unload", this._unload, this);
1425
+
1426
+ return container;
1427
+ },
1428
+
1429
+ /**
1430
+ * This method is called when the user clicks on the control.
1431
+ */
1432
+ _onClick() {
1433
+ this._justClicked = true;
1434
+ const wasFollowing = this._isFollowing();
1435
+ this._userPanned = false;
1436
+ this._userZoomed = false;
1437
+
1438
+ if (this._active && !this._event) {
1439
+ // click while requesting
1440
+ this.stop();
1441
+ } else if (this._active) {
1442
+ const behaviors = this.options.clickBehavior;
1443
+ let behavior = behaviors.outOfView;
1444
+ if (this._map.getBounds().contains(this._event.latlng)) {
1445
+ behavior = wasFollowing ? behaviors.inView : behaviors.inViewNotFollowing;
1446
+ }
1447
+
1448
+ // Allow inheriting from another behavior
1449
+ if (behaviors[behavior]) {
1450
+ behavior = behaviors[behavior];
1451
+ }
1452
+
1453
+ switch (behavior) {
1454
+ case "setView":
1455
+ this.setView();
1456
+ break;
1457
+ case "stop":
1458
+ this.stop();
1459
+ if (this.options.returnToPrevBounds) {
1460
+ const f = this.options.flyTo ? this._map.flyToBounds : this._map.fitBounds;
1461
+ f.bind(this._map)(this._prevBounds);
1462
+ }
1463
+ break;
1464
+ }
1465
+ } else {
1466
+ if (this.options.returnToPrevBounds) {
1467
+ this._prevBounds = this._map.getBounds();
1468
+ }
1469
+ this.start();
1470
+ }
1471
+
1472
+ this._updateContainerStyle();
1473
+ },
1474
+
1475
+ /**
1476
+ * Starts the plugin:
1477
+ * - activates the engine
1478
+ * - draws the marker (if coordinates available)
1479
+ */
1480
+ start() {
1481
+ this._activate();
1482
+
1483
+ if (this._event) {
1484
+ this._drawMarker(this._map);
1485
+
1486
+ // if we already have a location but the user clicked on the control
1487
+ if (this.options.setView) {
1488
+ this.setView();
1489
+ }
1490
+ }
1491
+ this._updateContainerStyle();
1492
+ },
1493
+
1494
+ /**
1495
+ * Stops the plugin:
1496
+ * - deactivates the engine
1497
+ * - reinitializes the button
1498
+ * - removes the marker
1499
+ */
1500
+ stop() {
1501
+ this._deactivate();
1502
+
1503
+ this._cleanClasses();
1504
+ this._resetVariables();
1505
+
1506
+ this._removeMarker();
1507
+ },
1508
+
1509
+ /**
1510
+ * Keep the control active but stop following the location
1511
+ */
1512
+ stopFollowing() {
1513
+ this._userPanned = true;
1514
+ this._updateContainerStyle();
1515
+ this._drawMarker();
1516
+ },
1517
+
1518
+ /**
1519
+ * This method launches the location engine.
1520
+ * It is called before the marker is updated,
1521
+ * event if it does not mean that the event will be ready.
1522
+ *
1523
+ * Override it if you want to add more functionalities.
1524
+ * It should set the this._active to true and do nothing if
1525
+ * this._active is true.
1526
+ */
1527
+ _activate() {
1528
+ if (this._active || !this._map) {
1529
+ return;
1530
+ }
1531
+
1532
+ this._map.locate(this.options.locateOptions);
1533
+ this._map.fire("locateactivate", this);
1534
+ this._active = true;
1535
+
1536
+ // bind event listeners
1537
+ this._map.on("locationfound", this._onLocationFound, this);
1538
+ this._map.on("locationerror", this._onLocationError, this);
1539
+ this._map.on("dragstart", this._onDrag, this);
1540
+ this._map.on("zoomstart", this._onZoom, this);
1541
+ this._map.on("zoomend", this._onZoomEnd, this);
1542
+ if (this.options.showCompass) {
1543
+ const oriAbs = "ondeviceorientationabsolute" in window;
1544
+ if (oriAbs || "ondeviceorientation" in window) {
1545
+ const _this = this;
1546
+ const deviceorientation = function () {
1547
+ L.DomEvent.on(window, oriAbs ? "deviceorientationabsolute" : "deviceorientation", _this._onDeviceOrientation, _this);
1548
+ };
1549
+ if (DeviceOrientationEvent && typeof DeviceOrientationEvent.requestPermission === "function") {
1550
+ DeviceOrientationEvent.requestPermission().then(function (permissionState) {
1551
+ if (permissionState === "granted") {
1552
+ deviceorientation();
1553
+ }
1554
+ });
1555
+ } else {
1556
+ deviceorientation();
1557
+ }
1558
+ }
1559
+ }
1560
+ },
1561
+
1562
+ /**
1563
+ * Called to stop the location engine.
1564
+ *
1565
+ * Override it to shutdown any functionalities you added on start.
1566
+ */
1567
+ _deactivate() {
1568
+ if (!this._active || !this._map) {
1569
+ return;
1570
+ }
1571
+
1572
+ this._map.stopLocate();
1573
+ this._map.fire("locatedeactivate", this);
1574
+ this._active = false;
1575
+
1576
+ if (!this.options.cacheLocation) {
1577
+ this._event = undefined;
1578
+ }
1579
+
1580
+ // unbind event listeners
1581
+ this._map.off("locationfound", this._onLocationFound, this);
1582
+ this._map.off("locationerror", this._onLocationError, this);
1583
+ this._map.off("dragstart", this._onDrag, this);
1584
+ this._map.off("zoomstart", this._onZoom, this);
1585
+ this._map.off("zoomend", this._onZoomEnd, this);
1586
+ if (this.options.showCompass) {
1587
+ this._compassHeading = null;
1588
+ if ("ondeviceorientationabsolute" in window) {
1589
+ L.DomEvent.off(window, "deviceorientationabsolute", this._onDeviceOrientation, this);
1590
+ } else if ("ondeviceorientation" in window) {
1591
+ L.DomEvent.off(window, "deviceorientation", this._onDeviceOrientation, this);
1592
+ }
1593
+ }
1594
+ },
1595
+
1596
+ /**
1597
+ * Zoom (unless we should keep the zoom level) and an to the current view.
1598
+ */
1599
+ setView() {
1600
+ this._drawMarker();
1601
+ if (this._isOutsideMapBounds()) {
1602
+ this._event = undefined; // clear the current location so we can get back into the bounds
1603
+ this.options.onLocationOutsideMapBounds(this);
1604
+ } else {
1605
+ if (this._justClicked && this.options.initialZoomLevel !== false) {
1606
+ var f = this.options.flyTo ? this._map.flyTo : this._map.setView;
1607
+ f.bind(this._map)([this._event.latitude, this._event.longitude], this.options.initialZoomLevel);
1608
+ } else if (this.options.keepCurrentZoomLevel) {
1609
+ var f = this.options.flyTo ? this._map.flyTo : this._map.panTo;
1610
+ f.bind(this._map)([this._event.latitude, this._event.longitude]);
1611
+ } else {
1612
+ var f = this.options.flyTo ? this._map.flyToBounds : this._map.fitBounds;
1613
+ // Ignore zoom events while setting the viewport as these would stop following
1614
+ this._ignoreEvent = true;
1615
+ f.bind(this._map)(this.options.getLocationBounds(this._event), {
1616
+ padding: this.options.circlePadding,
1617
+ maxZoom: this.options.initialZoomLevel || this.options.locateOptions.maxZoom
1618
+ });
1619
+ L.Util.requestAnimFrame(function () {
1620
+ // Wait until after the next animFrame because the flyTo can be async
1621
+ this._ignoreEvent = false;
1622
+ }, this);
1623
+ }
1624
+ }
1625
+ },
1626
+
1627
+ /**
1628
+ *
1629
+ */
1630
+ _drawCompass() {
1631
+ if (!this._event) {
1632
+ return;
1633
+ }
1634
+
1635
+ const latlng = this._event.latlng;
1636
+
1637
+ if (this.options.showCompass && latlng && this._compassHeading !== null) {
1638
+ const cStyle = this._isFollowing() ? this.options.followCompassStyle : this.options.compassStyle;
1639
+ if (!this._compass) {
1640
+ this._compass = new this.options.compassClass(latlng, this._compassHeading, cStyle).addTo(this._layer);
1641
+ } else {
1642
+ this._compass.setLatLng(latlng);
1643
+ this._compass.setHeading(this._compassHeading);
1644
+ // If the compassClass can be updated with setStyle, update it.
1645
+ if (this._compass.setStyle) {
1646
+ this._compass.setStyle(cStyle);
1647
+ }
1648
+ }
1649
+ //
1650
+ }
1651
+ if (this._compass && (!this.options.showCompass || this._compassHeading === null)) {
1652
+ this._compass.removeFrom(this._layer);
1653
+ this._compass = null;
1654
+ }
1655
+ },
1656
+
1657
+ /**
1658
+ * Draw the marker and accuracy circle on the map.
1659
+ *
1660
+ * Uses the event retrieved from onLocationFound from the map.
1661
+ */
1662
+ _drawMarker() {
1663
+ if (this._event.accuracy === undefined) {
1664
+ this._event.accuracy = 0;
1665
+ }
1666
+
1667
+ const radius = this._event.accuracy;
1668
+ const latlng = this._event.latlng;
1669
+
1670
+ // circle with the radius of the location's accuracy
1671
+ if (this.options.drawCircle) {
1672
+ const style = this._isFollowing() ? this.options.followCircleStyle : this.options.circleStyle;
1673
+
1674
+ if (!this._circle) {
1675
+ this._circle = L.circle(latlng, radius, style).addTo(this._layer);
1676
+ } else {
1677
+ this._circle.setLatLng(latlng).setRadius(radius).setStyle(style);
1678
+ }
1679
+ }
1680
+
1681
+ let distance;
1682
+ let unit;
1683
+ if (this.options.metric) {
1684
+ distance = radius.toFixed(0);
1685
+ unit = this.options.strings.metersUnit;
1686
+ } else {
1687
+ distance = (radius * 3.2808399).toFixed(0);
1688
+ unit = this.options.strings.feetUnit;
1689
+ }
1690
+
1691
+ // small inner marker
1692
+ if (this.options.drawMarker) {
1693
+ const mStyle = this._isFollowing() ? this.options.followMarkerStyle : this.options.markerStyle;
1694
+ if (!this._marker) {
1695
+ this._marker = new this.options.markerClass(latlng, mStyle).addTo(this._layer);
1696
+ } else {
1697
+ this._marker.setLatLng(latlng);
1698
+ // If the markerClass can be updated with setStyle, update it.
1699
+ if (this._marker.setStyle) {
1700
+ this._marker.setStyle(mStyle);
1701
+ }
1702
+ }
1703
+ }
1704
+
1705
+ this._drawCompass();
1706
+
1707
+ const t = this.options.strings.popup;
1708
+ function getPopupText() {
1709
+ if (typeof t === "string") {
1710
+ return L.Util.template(t, { distance, unit });
1711
+ } else if (typeof t === "function") {
1712
+ return t({ distance, unit });
1713
+ } else {
1714
+ return t;
1715
+ }
1716
+ }
1717
+ if (this.options.showPopup && t && this._marker) {
1718
+ this._marker.bindPopup(getPopupText())._popup.setLatLng(latlng);
1719
+ }
1720
+ if (this.options.showPopup && t && this._compass) {
1721
+ this._compass.bindPopup(getPopupText())._popup.setLatLng(latlng);
1722
+ }
1723
+ },
1724
+
1725
+ /**
1726
+ * Remove the marker from map.
1727
+ */
1728
+ _removeMarker() {
1729
+ this._layer.clearLayers();
1730
+ this._marker = undefined;
1731
+ this._circle = undefined;
1732
+ },
1733
+
1734
+ /**
1735
+ * Unload the plugin and all event listeners.
1736
+ * Kind of the opposite of onAdd.
1737
+ */
1738
+ _unload() {
1739
+ this.stop();
1740
+ this._map.off("unload", this._unload, this);
1741
+ },
1742
+
1743
+ /**
1744
+ * Sets the compass heading
1745
+ */
1746
+ _setCompassHeading(angle) {
1747
+ if (!isNaN(parseFloat(angle)) && isFinite(angle)) {
1748
+ angle = Math.round(angle);
1749
+
1750
+ this._compassHeading = angle;
1751
+ L.Util.requestAnimFrame(this._drawCompass, this);
1752
+ } else {
1753
+ this._compassHeading = null;
1754
+ }
1755
+ },
1756
+
1757
+ /**
1758
+ * If the compass fails calibration just fail safely and remove the compass
1759
+ */
1760
+ _onCompassNeedsCalibration() {
1761
+ this._setCompassHeading();
1762
+ },
1763
+
1764
+ /**
1765
+ * Process and normalise compass events
1766
+ */
1767
+ _onDeviceOrientation(e) {
1768
+ if (!this._active) {
1769
+ return;
1770
+ }
1771
+
1772
+ if (e.webkitCompassHeading) {
1773
+ // iOS
1774
+ this._setCompassHeading(e.webkitCompassHeading);
1775
+ } else if (e.absolute && e.alpha) {
1776
+ // Android
1777
+ this._setCompassHeading(360 - e.alpha);
1778
+ }
1779
+ },
1780
+
1781
+ /**
1782
+ * Calls deactivate and dispatches an error.
1783
+ */
1784
+ _onLocationError(err) {
1785
+ // ignore time out error if the location is watched
1786
+ if (err.code == 3 && this.options.locateOptions.watch) {
1787
+ return;
1788
+ }
1789
+
1790
+ this.stop();
1791
+ this.options.onLocationError(err, this);
1792
+ },
1793
+
1794
+ /**
1795
+ * Stores the received event and updates the marker.
1796
+ */
1797
+ _onLocationFound(e) {
1798
+ // no need to do anything if the location has not changed
1799
+ if (this._event && this._event.latlng.lat === e.latlng.lat && this._event.latlng.lng === e.latlng.lng && this._event.accuracy === e.accuracy) {
1800
+ return;
1801
+ }
1802
+
1803
+ if (!this._active) {
1804
+ // we may have a stray event
1805
+ return;
1806
+ }
1807
+
1808
+ this._event = e;
1809
+
1810
+ this._drawMarker();
1811
+ this._updateContainerStyle();
1812
+
1813
+ switch (this.options.setView) {
1814
+ case "once":
1815
+ if (this._justClicked) {
1816
+ this.setView();
1817
+ }
1818
+ break;
1819
+ case "untilPan":
1820
+ if (!this._userPanned) {
1821
+ this.setView();
1822
+ }
1823
+ break;
1824
+ case "untilPanOrZoom":
1825
+ if (!this._userPanned && !this._userZoomed) {
1826
+ this.setView();
1827
+ }
1828
+ break;
1829
+ case "always":
1830
+ this.setView();
1831
+ break;
1832
+ }
1833
+
1834
+ this._justClicked = false;
1835
+ },
1836
+
1837
+ /**
1838
+ * When the user drags. Need a separate event so we can bind and unbind event listeners.
1839
+ */
1840
+ _onDrag() {
1841
+ // only react to drags once we have a location
1842
+ if (this._event && !this._ignoreEvent) {
1843
+ this._userPanned = true;
1844
+ this._updateContainerStyle();
1845
+ this._drawMarker();
1846
+ }
1847
+ },
1848
+
1849
+ /**
1850
+ * When the user zooms. Need a separate event so we can bind and unbind event listeners.
1851
+ */
1852
+ _onZoom() {
1853
+ // only react to drags once we have a location
1854
+ if (this._event && !this._ignoreEvent) {
1855
+ this._userZoomed = true;
1856
+ this._updateContainerStyle();
1857
+ this._drawMarker();
1858
+ }
1859
+ },
1860
+
1861
+ /**
1862
+ * After a zoom ends update the compass and handle sideways zooms
1863
+ */
1864
+ _onZoomEnd() {
1865
+ if (this._event) {
1866
+ this._drawCompass();
1867
+ }
1868
+
1869
+ if (this._event && !this._ignoreEvent) {
1870
+ // If we have zoomed in and out and ended up sideways treat it as a pan
1871
+ if (this._marker && !this._map.getBounds().pad(-0.3).contains(this._marker.getLatLng())) {
1872
+ this._userPanned = true;
1873
+ this._updateContainerStyle();
1874
+ this._drawMarker();
1875
+ }
1876
+ }
1877
+ },
1878
+
1879
+ /**
1880
+ * Compute whether the map is following the user location with pan and zoom.
1881
+ */
1882
+ _isFollowing() {
1883
+ if (!this._active) {
1884
+ return false;
1885
+ }
1886
+
1887
+ if (this.options.setView === "always") {
1888
+ return true;
1889
+ } else if (this.options.setView === "untilPan") {
1890
+ return !this._userPanned;
1891
+ } else if (this.options.setView === "untilPanOrZoom") {
1892
+ return !this._userPanned && !this._userZoomed;
1893
+ }
1894
+ },
1895
+
1896
+ /**
1897
+ * Check if location is in map bounds
1898
+ */
1899
+ _isOutsideMapBounds() {
1900
+ if (this._event === undefined) {
1901
+ return false;
1902
+ }
1903
+ return this._map.options.maxBounds && !this._map.options.maxBounds.contains(this._event.latlng);
1904
+ },
1905
+
1906
+ /**
1907
+ * Toggles button class between following and active.
1908
+ */
1909
+ _updateContainerStyle() {
1910
+ if (!this._container) {
1911
+ return;
1912
+ }
1913
+
1914
+ if (this._active && !this._event) {
1915
+ // active but don't have a location yet
1916
+ this._setClasses("requesting");
1917
+ } else if (this._isFollowing()) {
1918
+ this._setClasses("following");
1919
+ } else if (this._active) {
1920
+ this._setClasses("active");
1921
+ } else {
1922
+ this._cleanClasses();
1923
+ }
1924
+ },
1925
+
1926
+ /**
1927
+ * Sets the CSS classes for the state.
1928
+ */
1929
+ _setClasses(state) {
1930
+ if (state == "requesting") {
1931
+ removeClasses(this._container, "active following");
1932
+ addClasses(this._container, "requesting");
1933
+
1934
+ removeClasses(this._icon, this.options.icon);
1935
+ addClasses(this._icon, this.options.iconLoading);
1936
+ } else if (state == "active") {
1937
+ removeClasses(this._container, "requesting following");
1938
+ addClasses(this._container, "active");
1939
+
1940
+ removeClasses(this._icon, this.options.iconLoading);
1941
+ addClasses(this._icon, this.options.icon);
1942
+ } else if (state == "following") {
1943
+ removeClasses(this._container, "requesting");
1944
+ addClasses(this._container, "active following");
1945
+
1946
+ removeClasses(this._icon, this.options.iconLoading);
1947
+ addClasses(this._icon, this.options.icon);
1948
+ }
1949
+ },
1950
+
1951
+ /**
1952
+ * Removes all classes from button.
1953
+ */
1954
+ _cleanClasses() {
1955
+ L.DomUtil.removeClass(this._container, "requesting");
1956
+ L.DomUtil.removeClass(this._container, "active");
1957
+ L.DomUtil.removeClass(this._container, "following");
1958
+
1959
+ removeClasses(this._icon, this.options.iconLoading);
1960
+ addClasses(this._icon, this.options.icon);
1961
+ },
1962
+
1963
+ /**
1964
+ * Reinitializes state variables.
1965
+ */
1966
+ _resetVariables() {
1967
+ // whether locate is active or not
1968
+ this._active = false;
1969
+
1970
+ // true if the control was clicked for the first time
1971
+ // we need this so we can pan and zoom once we have the location
1972
+ this._justClicked = false;
1973
+
1974
+ // true if the user has panned the map after clicking the control
1975
+ this._userPanned = false;
1976
+
1977
+ // true if the user has zoomed the map after clicking the control
1978
+ this._userZoomed = false;
1979
+ }
1980
+ });
1981
+
1982
+ L.control.locate = (options) => new L.Control.Locate(options);
1983
+
1984
+ return LocateControl;
1985
+ }, window);
1986
+ } (L_Control_Locate));
1987
+ return L_Control_Locate.exports;
1988
+ }
1989
+
1990
+ requireL_Control_Locate();
1991
+
1992
+ const urlRegex =
1993
+ // eslint-disable-next-line no-useless-escape, security/detect-unsafe-regex
1994
+ /(^| )(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,10}(:[0-9]{1,10})?(\/.*)?$/gm;
1995
+ const mailRegex = /(?<![[(])([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})(?![\])])/gi;
1996
+ function fixUrls(message) {
1997
+ message = message.replace(urlRegex, function (url) {
1998
+ let hyperlink = url.replace(' ', '');
1999
+ if (!hyperlink.match('^https?://')) {
2000
+ hyperlink = 'https://' + hyperlink;
2001
+ }
2002
+ return hyperlink;
2003
+ });
2004
+ return message;
2005
+ }
2006
+
2007
+ /**
2008
+ * @category Map
2009
+ */
2010
+ const TextView = ({ item, itemId, text, truncate = false, rawText, }) => {
2011
+ if (item) {
2012
+ text = item.text;
2013
+ itemId = item.id;
2014
+ }
2015
+ const tags = useTags();
2016
+ const addFilterTag = useAddFilterTag();
2017
+ let innerText = '';
2018
+ let replacedText = '';
2019
+ if (rawText) {
2020
+ innerText = replacedText = rawText;
2021
+ }
2022
+ else if (text) {
2023
+ innerText = text;
2024
+ }
2025
+ if (innerText && truncate)
2026
+ innerText = truncateText(removeMarkdownKeepLinksAndParagraphs(innerText), 100);
2027
+ if (innerText)
2028
+ replacedText = fixUrls(innerText);
2029
+ if (replacedText) {
2030
+ replacedText = replacedText.replace(mailRegex, (url) => {
2031
+ return `[${url}](mailto:${url})`;
2032
+ });
2033
+ }
2034
+ if (replacedText) {
2035
+ replacedText = replacedText.replace(hashTagRegex, (match) => {
2036
+ return `[${match}](${match})`;
2037
+ });
2038
+ }
2039
+ const HashTag = ({ children, tag, itemId }) => {
2040
+ return (jsx("a", { className: 'hashtag', style: tag && {
2041
+ color: tag.color,
2042
+ }, onClick: (e) => {
2043
+ e.stopPropagation();
2044
+ addFilterTag(tag);
2045
+ }, children: decodeTag(children) }, tag ? tag.name + itemId : itemId));
2046
+ };
2047
+ const Link = ({ href, children }) => {
2048
+ // Youtube
2049
+ if (href.startsWith('https://www.youtube.com/watch?v=')) {
2050
+ const videoId = href?.split('v=')[1].split('&')[0];
2051
+ const youtubeEmbedUrl = `https://www.youtube-nocookie.com/embed/${videoId}`;
2052
+ return (jsx("iframe", { src: youtubeEmbedUrl, allow: 'fullscreen; picture-in-picture', allowFullScreen: true }));
2053
+ }
2054
+ // Rumble
2055
+ if (href.startsWith('https://rumble.com/embed/')) {
2056
+ return jsx("iframe", { src: href, allow: 'fullscreen; picture-in-picture', allowFullScreen: true });
2057
+ }
2058
+ // HashTag
2059
+ if (href.startsWith('#')) {
2060
+ const tag = tags.find((t) => t.name.toLowerCase() === decodeURI(href).slice(1).toLowerCase());
2061
+ if (tag)
2062
+ return (jsx(HashTag, { tag: tag, itemId: itemId, children: children }));
2063
+ else
2064
+ return children;
2065
+ }
2066
+ // Default: Link
2067
+ return (jsx("a", { href: href, target: '_blank', rel: 'noreferrer', children: children }));
2068
+ };
2069
+ return (jsx(Markdown, { className: 'markdown tw:text-map tw:leading-map tw:text-sm', remarkPlugins: [remarkBreaks], components: {
2070
+ a: Link,
2071
+ }, children: replacedText }));
2072
+ };
2073
+ function removeMarkdownKeepLinksAndParagraphs(text) {
2074
+ // Remove Markdown syntax using regular expressions but keep links and paragraphs
2075
+ return text
2076
+ .replace(/!\[.*?\]\(.*?\)/g, '') // Remove images
2077
+ .replace(/(`{1,3})(.*?)\1/g, '$2') // Remove inline code
2078
+ .replace(/(\*{1,2}|_{1,2})(.*?)\1/g, '$2') // Remove bold and italic
2079
+ .replace(/(#+)\s+(.*)/g, '$2') // Remove headers
2080
+ .replace(/>\s+(.*)/g, '$1') // Remove blockquotes
2081
+ .replace(/^\s*\n/gm, '\n') // Preserve empty lines
2082
+ .replace(/(\r\n|\n|\r)/gm, '\n'); // Preserve line breaks
2083
+ }
2084
+ function truncateText(text, limit) {
2085
+ if (text.length <= limit) {
2086
+ return text;
2087
+ }
2088
+ let truncated = '';
2089
+ let length = 0;
2090
+ // Split the text by paragraphs
2091
+ const paragraphs = text.split('\n');
2092
+ for (const paragraph of paragraphs) {
2093
+ if (length + paragraph.length > limit) {
2094
+ truncated += paragraph.slice(0, limit - length) + '...';
2095
+ break;
2096
+ }
2097
+ else {
2098
+ truncated += paragraph + '\n';
2099
+ length += paragraph.length;
2100
+ }
2101
+ }
2102
+ return truncated.trim();
2103
+ }
2104
+
2105
+ function EllipsisVerticalIcon({
2106
+ title,
2107
+ titleId,
2108
+ ...props
2109
+ }, svgRef) {
2110
+ return /*#__PURE__*/React.createElement("svg", Object.assign({
2111
+ xmlns: "http://www.w3.org/2000/svg",
2112
+ viewBox: "0 0 16 16",
2113
+ fill: "currentColor",
2114
+ "aria-hidden": "true",
2115
+ "data-slot": "icon",
2116
+ ref: svgRef,
2117
+ "aria-labelledby": titleId
2118
+ }, props), title ? /*#__PURE__*/React.createElement("title", {
2119
+ id: titleId
2120
+ }, title) : null, /*#__PURE__*/React.createElement("path", {
2121
+ d: "M8 2a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM8 6.5a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM9.5 12.5a1.5 1.5 0 1 0-3 0 1.5 1.5 0 0 0 3 0Z"
2122
+ }));
2123
+ }
2124
+ const ForwardRef$3 = /*#__PURE__*/ React.forwardRef(EllipsisVerticalIcon);
2125
+
2126
+ /**
2127
+ * @category Templates
2128
+ */
2129
+ function MapOverlayPage({ children, className, backdrop, card = true, }) {
2130
+ const closeScreen = () => {
2131
+ navigate(`/${window.location.search ? window.location.search : ''}`);
2132
+ };
2133
+ const navigate = useNavigate();
2134
+ const overlayRef = createRef();
2135
+ const backdropRef = createRef();
2136
+ useEffect(() => {
2137
+ if (overlayRef.current !== null) {
2138
+ DomEvent.disableClickPropagation(overlayRef.current);
2139
+ DomEvent.disableScrollPropagation(overlayRef.current);
2140
+ }
2141
+ if (backdropRef.current !== null && backdrop) {
2142
+ DomEvent.disableClickPropagation(backdropRef.current);
2143
+ DomEvent.disableScrollPropagation(backdropRef.current);
2144
+ }
2145
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2146
+ }, [overlayRef, backdropRef]);
2147
+ return (jsx("div", { className: `tw:absolute tw:h-full tw:w-full tw:m-auto ${backdrop ? 'tw:z-2000' : ''}`, children: jsx("div", { ref: backdropRef, className: `${backdrop ? 'tw:backdrop-brightness-75' : ''} tw:h-full tw:w-full tw:grid tw:place-items-center tw:m-auto`, children: jsxs("div", { ref: overlayRef, className: `${card ? 'tw:card tw:card-body tw:shadow-xl' : ''} tw:bg-base-100 tw:p-6 ${className ?? ''} ${backdrop ? '' : 'tw:z-2000'} tw:absolute tw:top-0 tw:bottom-0 tw:right-0 tw:left-0 tw:m-auto`, children: [children, jsx("button", { className: 'tw:btn tw:btn-sm tw:btn-circle tw:btn-ghost tw:absolute tw:right-2 tw:top-2', onClick: () => closeScreen(), children: "\u2715" })] }) }) }));
2148
+ }
2149
+
2150
+ /**
2151
+ * @category Input
2152
+ */
2153
+ function TextAreaInput({ labelTitle, dataField, labelStyle, containerStyle, inputStyle, defaultValue, placeholder, required = true, updateFormValue, }) {
2154
+ const ref = useRef(null);
2155
+ const [inputValue, setInputValue] = useState(defaultValue);
2156
+ useEffect(() => {
2157
+ setInputValue(defaultValue);
2158
+ }, [defaultValue]);
2159
+ const handleChange = (e) => {
2160
+ const newValue = e.target.value;
2161
+ setInputValue(newValue);
2162
+ if (updateFormValue) {
2163
+ updateFormValue(newValue);
2164
+ }
2165
+ };
2166
+ return (jsxs("div", { className: `tw:form-control tw:w-full ${containerStyle ?? ''}`, children: [labelTitle ? (jsx("label", { className: 'tw:label', children: jsx("span", { className: `tw:label-text tw:text-base-content ${labelStyle ?? ''}`, children: labelTitle }) })) : null, jsx("textarea", { required: required, ref: ref, value: inputValue, name: dataField, className: `tw:textarea tw:textarea-bordered tw:w-full tw:leading-5 ${inputStyle ?? ''}`, placeholder: placeholder ?? '', onChange: handleChange })] }));
2167
+ }
2168
+
2169
+ /**
2170
+ * @category Input
2171
+ */
2172
+ function TextInput({ labelTitle, labelStyle, type, dataField, containerStyle, inputStyle, defaultValue, placeholder, autocomplete, pattern, required = true, updateFormValue, }) {
2173
+ const [inputValue, setInputValue] = useState(defaultValue ?? '');
2174
+ useEffect(() => {
2175
+ setInputValue(defaultValue ?? '');
2176
+ }, [defaultValue]);
2177
+ const handleChange = (e) => {
2178
+ const newValue = e.target.value;
2179
+ setInputValue(newValue);
2180
+ if (updateFormValue) {
2181
+ updateFormValue(newValue);
2182
+ }
2183
+ };
2184
+ return (jsxs("div", { className: `tw:form-control ${containerStyle ?? ''}`, children: [labelTitle ? (jsx("label", { className: 'tw:label', children: jsx("span", { className: `tw:label-text tw:text-base-content ${labelStyle ?? ''}`, children: labelTitle }) })) : null, jsx("input", { required: required, pattern: pattern, type: type ?? 'text', name: dataField, value: inputValue, placeholder: placeholder ?? '', autoComplete: autocomplete, onChange: handleChange, className: `tw:input tw:input-bordered tw:w-full ${inputStyle ?? ''}` })] }));
2185
+ }
2186
+
2187
+ /**
2188
+ * @category Map
2189
+ */
2190
+ const PopupStartEndInput = ({ item, showLabels = true, labelStyle, updateStartValue, updateEndValue, }) => {
2191
+ return (jsxs("div", { className: 'tw:grid tw:grid-cols-2 tw:gap-2', children: [jsx(TextInput, { type: 'date', placeholder: 'start', dataField: 'start', inputStyle: 'tw:text-sm tw:px-2', labelTitle: showLabels ? 'Start' : '', labelStyle: labelStyle, defaultValue: item && item.start ? item.start.substring(0, 10) : '', autocomplete: 'one-time-code', updateFormValue: updateStartValue }), jsx(TextInput, { type: 'date', placeholder: 'end', dataField: 'end', inputStyle: 'tw:text-sm tw:px-2', labelTitle: showLabels ? 'End' : '', labelStyle: labelStyle, defaultValue: item && item.end ? item.end.substring(0, 10) : '', autocomplete: 'one-time-code', updateFormValue: updateEndValue })] }));
2192
+ };
2193
+
2194
+ function CalendarDaysIcon({
2195
+ title,
2196
+ titleId,
2197
+ ...props
2198
+ }, svgRef) {
2199
+ return /*#__PURE__*/React.createElement("svg", Object.assign({
2200
+ xmlns: "http://www.w3.org/2000/svg",
2201
+ viewBox: "0 0 24 24",
2202
+ fill: "currentColor",
2203
+ "aria-hidden": "true",
2204
+ "data-slot": "icon",
2205
+ ref: svgRef,
2206
+ "aria-labelledby": titleId
2207
+ }, props), title ? /*#__PURE__*/React.createElement("title", {
2208
+ id: titleId
2209
+ }, title) : null, /*#__PURE__*/React.createElement("path", {
2210
+ d: "M12.75 12.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM7.5 15.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5ZM8.25 17.25a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM9.75 15.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5ZM10.5 17.25a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM12 15.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5ZM12.75 17.25a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM14.25 15.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5ZM15 17.25a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM16.5 15.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5ZM15 12.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0ZM16.5 13.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Z"
2211
+ }), /*#__PURE__*/React.createElement("path", {
2212
+ fillRule: "evenodd",
2213
+ d: "M6.75 2.25A.75.75 0 0 1 7.5 3v1.5h9V3A.75.75 0 0 1 18 3v1.5h.75a3 3 0 0 1 3 3v11.25a3 3 0 0 1-3 3H5.25a3 3 0 0 1-3-3V7.5a3 3 0 0 1 3-3H6V3a.75.75 0 0 1 .75-.75Zm13.5 9a1.5 1.5 0 0 0-1.5-1.5H5.25a1.5 1.5 0 0 0-1.5 1.5v7.5a1.5 1.5 0 0 0 1.5 1.5h13.5a1.5 1.5 0 0 0 1.5-1.5v-7.5Z",
2214
+ clipRule: "evenodd"
2215
+ }));
2216
+ }
2217
+ const ForwardRef$2 = /*#__PURE__*/ React.forwardRef(CalendarDaysIcon);
2218
+
2219
+ /**
2220
+ * @category Map
2221
+ */
2222
+ const StartEndView = ({ item }) => {
2223
+ return (jsxs("div", { className: 'tw:flex tw:flex-row tw:mb-4 tw:mt-1', children: [jsxs("div", { className: 'tw:basis-2/5 tw:flex tw:flex-row', children: [jsx(ForwardRef$2, { className: 'tw:h-4 tw:w-4 tw:mr-2' }), jsx("time", { className: 'tw:align-middle', dateTime: item && item.start ? item.start.substring(0, 10) : '', children: item && item.start ? new Date(item.start).toLocaleDateString() : '' })] }), jsx("div", { className: 'tw:basis-1/5 tw:place-content-center', children: jsx("span", { children: "-" }) }), jsxs("div", { className: 'tw:basis-2/5 tw:flex tw:flex-row', children: [jsx(ForwardRef$2, { className: 'tw:h-4 tw:w-4 tw:mr-2' }), jsx("time", { className: 'tw:align-middle', dateTime: item && item.end ? item.end.substring(0, 10) : '', children: item && item.end ? new Date(item.end).toLocaleDateString() : '' })] })] }));
2224
+ };
2225
+
2226
+ const goldenRatioConjugate = 0.618033988749895;
2227
+ const randomColor = () => {
2228
+ return hsvToHex((Math.random() + goldenRatioConjugate) % 1, 0.8, 0.7);
2229
+ };
2230
+ function hsvToHex(h, s, v) {
2231
+ let r, g, b;
2232
+ const i = Math.floor(h * 6);
2233
+ const f = h * 6 - i;
2234
+ const p = v * (1 - s);
2235
+ const q = v * (1 - f * s);
2236
+ const t = v * (1 - (1 - f) * s);
2237
+ switch (i % 6) {
2238
+ case 0:
2239
+ r = v;
2240
+ g = t;
2241
+ b = p;
2242
+ break;
2243
+ case 1:
2244
+ r = q;
2245
+ g = v;
2246
+ b = p;
2247
+ break;
2248
+ case 2:
2249
+ r = p;
2250
+ g = v;
2251
+ b = t;
2252
+ break;
2253
+ case 3:
2254
+ r = p;
2255
+ g = q;
2256
+ b = v;
2257
+ break;
2258
+ case 4:
2259
+ r = t;
2260
+ g = p;
2261
+ b = v;
2262
+ break;
2263
+ case 5:
2264
+ r = v;
2265
+ g = p;
2266
+ b = q;
2267
+ break;
2268
+ }
2269
+ return rgbToHex(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255));
2270
+ }
2271
+ const rgbToHex = (r, g, b) => '#' +
2272
+ [r, g, b]
2273
+ .map((x) => {
2274
+ const hex = x.toString(16);
2275
+ return hex.length === 1 ? `0${hex}` : hex;
2276
+ })
2277
+ .join('');
2278
+
2279
+ function PencilIcon({
2280
+ title,
2281
+ titleId,
2282
+ ...props
2283
+ }, svgRef) {
2284
+ return /*#__PURE__*/React.createElement("svg", Object.assign({
2285
+ xmlns: "http://www.w3.org/2000/svg",
2286
+ viewBox: "0 0 24 24",
2287
+ fill: "currentColor",
2288
+ "aria-hidden": "true",
2289
+ "data-slot": "icon",
2290
+ ref: svgRef,
2291
+ "aria-labelledby": titleId
2292
+ }, props), title ? /*#__PURE__*/React.createElement("title", {
2293
+ id: titleId
2294
+ }, title) : null, /*#__PURE__*/React.createElement("path", {
2295
+ d: "M21.731 2.269a2.625 2.625 0 0 0-3.712 0l-1.157 1.157 3.712 3.712 1.157-1.157a2.625 2.625 0 0 0 0-3.712ZM19.513 8.199l-3.712-3.712-12.15 12.15a5.25 5.25 0 0 0-1.32 2.214l-.8 2.685a.75.75 0 0 0 .933.933l2.685-.8a5.25 5.25 0 0 0 2.214-1.32L19.513 8.2Z"
2296
+ }));
2297
+ }
2298
+ const ForwardRef$1 = /*#__PURE__*/ React.forwardRef(PencilIcon);
2299
+
2300
+ function TrashIcon({
2301
+ title,
2302
+ titleId,
2303
+ ...props
2304
+ }, svgRef) {
2305
+ return /*#__PURE__*/React.createElement("svg", Object.assign({
2306
+ xmlns: "http://www.w3.org/2000/svg",
2307
+ viewBox: "0 0 24 24",
2308
+ fill: "currentColor",
2309
+ "aria-hidden": "true",
2310
+ "data-slot": "icon",
2311
+ ref: svgRef,
2312
+ "aria-labelledby": titleId
2313
+ }, props), title ? /*#__PURE__*/React.createElement("title", {
2314
+ id: titleId
2315
+ }, title) : null, /*#__PURE__*/React.createElement("path", {
2316
+ fillRule: "evenodd",
2317
+ d: "M16.5 4.478v.227a48.816 48.816 0 0 1 3.878.512.75.75 0 1 1-.256 1.478l-.209-.035-1.005 13.07a3 3 0 0 1-2.991 2.77H8.084a3 3 0 0 1-2.991-2.77L4.087 6.66l-.209.035a.75.75 0 0 1-.256-1.478A48.567 48.567 0 0 1 7.5 4.705v-.227c0-1.564 1.213-2.9 2.816-2.951a52.662 52.662 0 0 1 3.369 0c1.603.051 2.815 1.387 2.815 2.951Zm-6.136-1.452a51.196 51.196 0 0 1 3.273 0C14.39 3.05 15 3.684 15 4.478v.113a49.488 49.488 0 0 0-6 0v-.113c0-.794.609-1.428 1.364-1.452Zm-.355 5.945a.75.75 0 1 0-1.5.058l.347 9a.75.75 0 1 0 1.499-.058l-.346-9Zm5.48.058a.75.75 0 1 0-1.498-.058l-.347 9a.75.75 0 0 0 1.5.058l.345-9Z",
2318
+ clipRule: "evenodd"
2319
+ }));
2320
+ }
2321
+ const ForwardRef = /*#__PURE__*/ React.forwardRef(TrashIcon);
2322
+
2323
+ var TargetDotSVG = 'data:image/svg+xml;base64,PHN2ZwogICAgICAgICAgICAgICAgICAgICAgICAgICAgc3Ryb2tlPSdjdXJyZW50Q29sb3InCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmaWxsPSdjdXJyZW50Q29sb3InCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJva2VXaWR0aD0nMCcKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHZpZXdCb3g9JzAgMCA1MTIgNTEyJwogICAgICAgICAgICAgICAgICAgICAgICAgICAgY2xhc3NOYW1lPSd3LTUgaC01JwogICAgICAgICAgICAgICAgICAgICAgICAgICAgeG1sbnM9J2h0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnJwogICAgICAgICAgICAgICAgICAgICAgICAgID4KICAgICAgICAgICAgICAgICAgICAgICAgICAgIDxwYXRoIGQ9J00yNTYgMGMxNy43IDAgMzIgMTQuMyAzMiAzMlY0Mi40YzkzLjcgMTMuOSAxNjcuNyA4OCAxODEuNiAxODEuNkg0ODBjMTcuNyAwIDMyIDE0LjMgMzIgMzJzLTE0LjMgMzItMzIgMzJINDY5LjZjLTEzLjkgOTMuNy04OCAxNjcuNy0xODEuNiAxODEuNlY0ODBjMCAxNy43LTE0LjMgMzItMzIgMzJzLTMyLTE0LjMtMzItMzJWNDY5LjZDMTMwLjMgNDU1LjcgNTYuMyAzODEuNyA0Mi40IDI4OEgzMmMtMTcuNyAwLTMyLTE0LjMtMzItMzJzMTQuMy0zMiAzMi0zMkg0Mi40QzU2LjMgMTMwLjMgMTMwLjMgNTYuMyAyMjQgNDIuNFYzMmMwLTE3LjcgMTQuMy0zMiAzMi0zMnpNMTA3LjQgMjg4YzEyLjUgNTguMyA1OC40IDEwNC4xIDExNi42IDExNi42VjM4NGMwLTE3LjcgMTQuMy0zMiAzMi0zMnMzMiAxNC4zIDMyIDMydjIwLjZjNTguMy0xMi41IDEwNC4xLTU4LjQgMTE2LjYtMTE2LjZIMzg0Yy0xNy43IDAtMzItMTQuMy0zMi0zMnMxNC4zLTMyIDMyLTMyaDIwLjZDMzkyLjEgMTY1LjcgMzQ2LjMgMTE5LjkgMjg4IDEwNy40VjEyOGMwIDE3LjctMTQuMyAzMi0zMiAzMnMtMzItMTQuMy0zMi0zMlYxMDcuNEMxNjUuNyAxMTkuOSAxMTkuOSAxNjUuNyAxMDcuNCAyMjRIMTI4YzE3LjcgMCAzMiAxNC4zIDMyIDMycy0xNC4zIDMyLTMyIDMySDEwNy40ek0yNTYgMjI0YTMyIDMyIDAgMSAxIDAgNjQgMzIgMzIgMCAxIDEgMC02NHonPjwvcGF0aD4KICAgICAgICAgICAgICAgICAgICAgICAgICA8L3N2Zz4=';
2324
+
2325
+ const isClickInsideRectangle = (e, element) => {
2326
+ const r = element.getBoundingClientRect();
2327
+ return e.clientX > r.left && e.clientX < r.right && e.clientY > r.top && e.clientY < r.bottom;
2328
+ };
2329
+ const DialogModal = ({ title, isOpened, onClose, children, showCloseButton = true, closeOnClickOutside = true, className, }) => {
2330
+ const ref = useRef(null);
2331
+ useEffect(() => {
2332
+ if (isOpened) {
2333
+ ref.current?.showModal();
2334
+ ref.current?.classList.remove('tw:hidden');
2335
+ document.body.classList.add('modal-open'); // prevent bg scroll
2336
+ }
2337
+ else {
2338
+ ref.current?.close();
2339
+ ref.current?.classList.add('tw:hidden');
2340
+ document.body.classList.remove('modal-open');
2341
+ }
2342
+ }, [isOpened]);
2343
+ if (isOpened) {
2344
+ return (jsx("dialog", { className: `${className ?? ''} card tw:shadow-xl tw:absolute tw:right-0 tw:top-0 tw:bottom-0 tw:left-0 tw:m-auto tw:transition-opacity tw:duration-300 tw:p-4 tw:max-w-xl tw:bg-base-100`, ref: ref, onCancel: onClose, onClick: (e) => ref.current && !isClickInsideRectangle(e, ref.current) && closeOnClickOutside && onClose(), children: jsxs("div", { className: 'card-body tw:p-2', children: [jsx("h2", { className: 'tw:text-2xl tw:font-semibold tw:mb-2 tw:text-center', children: title }), children, showCloseButton && (jsx("button", { className: 'btn btn-sm btn-circle btn-ghost tw:absolute tw:right-2 tw:top-2', onClick: onClose, children: "\u2715" }))] }) }));
2345
+ }
2346
+ else
2347
+ return jsx(Fragment, {});
2348
+ };
2349
+
2350
+ function HeaderView({ item, api, editCallback, deleteCallback, setPositionCallback, loading, hideMenu = false, big = false, truncateSubname = true, hideSubname = false, showAddress = false, }) {
2351
+ const [modalOpen, setModalOpen] = useState(false);
2352
+ const hasUserPermission = useHasUserPermission();
2353
+ const navigate = useNavigate();
2354
+ const appState = useAppState();
2355
+ const [imageLoaded, setImageLoaded] = useState(false);
2356
+ const avatar = item.image && appState.assetsApi.url + item.image + '?width=160&heigth=160';
2357
+ const title = item.name;
2358
+ const subtitle = item.subname;
2359
+ const [address] = useState('');
2360
+ const params = new URLSearchParams(window.location.search);
2361
+ const openDeleteModal = async (event) => {
2362
+ setModalOpen(true);
2363
+ event.stopPropagation();
2364
+ };
2365
+ return (jsxs(Fragment, { children: [jsxs("div", { className: 'tw:flex tw:flex-row', children: [jsx("div", { className: 'tw:grow tw:max-w-[calc(100%-60px)] }', children: jsxs("div", { className: 'flex items-center', children: [avatar && (jsx("div", { className: 'tw:avatar', children: jsxs("div", { className: `${big ? 'tw:w-20' : 'tw:w-10'} tw:inline tw:items-center tw:justify-center overflow-hidden`, children: [jsx("img", { className: 'tw:w-full tw:h-full tw:object-cover tw:rounded-full', src: avatar, alt: item.name + ' logo', onLoad: () => setImageLoaded(true), onError: () => setImageLoaded(false), style: { display: imageLoaded ? 'block' : 'none' } }), !imageLoaded && (jsx("div", { className: 'tw:w-full tw:h-full tw:bg-gray-200 tw:rounded-full' }))] }) })), jsxs("div", { className: `${avatar ? 'tw:ml-2' : ''} tw:overflow-hidden`, children: [jsx("div", { className: `${big ? 'tw:xl:text-3xl tw:text-2xl' : 'tw:text-xl'} tw:font-semibold tw:truncate`, title: title, children: title }), showAddress && address && !hideSubname && (jsx("div", { className: `tw:text-xs tw:text-gray-500 ${truncateSubname && 'tw:truncate'}`, children: address })), subtitle && !hideSubname && (jsx("div", { className: `tw:text-xs tw:opacity-50 ${truncateSubname && 'tw:truncate'}`, children: subtitle }))] })] }) }), jsx("div", { onClick: (e) => e.stopPropagation(), className: `${big ? 'tw:mt-5' : 'tw:mt-1'}`, children: (api?.deleteItem || item.layer?.api?.updateItem) &&
2366
+ (hasUserPermission(api?.collectionName, 'delete', item) ||
2367
+ hasUserPermission(api?.collectionName, 'update', item)) &&
2368
+ !hideMenu && (jsxs("div", { className: 'tw:dropdown tw:dropdown-bottom', children: [jsx("label", { tabIndex: 0, className: 'tw:bg-base-100 tw:btn tw:m-1 tw:leading-3 tw:border-none tw:min-h-0 tw:h-6', children: jsx(ForwardRef$3, { className: 'tw:h-5 tw:w-5' }) }), jsxs("ul", { tabIndex: 0, className: 'tw:dropdown-content tw:menu tw:p-2 tw:shadow tw:bg-base-100 tw:rounded-box tw:z-1000', children: [api?.updateItem &&
2369
+ hasUserPermission(api.collectionName, 'update', item) &&
2370
+ editCallback && (jsx("li", { children: jsx("a", { className: 'tw:text-base-content! tw:cursor-pointer', onClick: (e) => item.layer?.customEditLink
2371
+ ? navigate(`${item.layer.customEditLink}${item.layer.customEditParameter ? `/${item.id}${params && '?' + params}` : ''} `)
2372
+ : editCallback(e), children: jsx(ForwardRef$1, { className: 'tw:h-5 tw:w-5' }) }) })), api?.updateItem &&
2373
+ hasUserPermission(api.collectionName, 'update', item) &&
2374
+ setPositionCallback && (jsx("li", { children: jsx("a", { className: 'tw:text-base-content! tw:cursor-pointer', onClick: setPositionCallback, children: jsx(SVG, { src: TargetDotSVG, className: 'tw:w-5 tw:h-5' }) }) })), api?.deleteItem &&
2375
+ hasUserPermission(api.collectionName, 'delete', item) &&
2376
+ deleteCallback && (jsx("li", { children: jsx("a", { className: 'tw:cursor-pointer tw:text-error!', onClick: openDeleteModal, children: loading ? (jsx("span", { className: 'tw:loading tw:loading-spinner tw:loading-sm' })) : (jsx(ForwardRef, { className: 'tw:h-5 tw:w-5' })) }) }))] })] })) })] }), jsx(DialogModal, { isOpened: modalOpen, title: 'Are you sure?', showCloseButton: false, onClose: () => setModalOpen(false), children: jsxs("div", { onClick: (e) => e.stopPropagation(), children: [jsxs("span", { children: ["Do you want to delete ", jsx("b", { children: item.name }), "?"] }), jsx("div", { className: 'tw:grid', children: jsxs("div", { className: 'tw:flex tw:justify-between', children: [jsx("label", { className: 'tw:btn tw:mt-4 tw:btn-error', onClick: (e) => {
2377
+ deleteCallback(e);
2378
+ setModalOpen(false);
2379
+ }, children: "Yes" }), jsx("label", { className: 'tw:btn tw:mt-4', onClick: () => setModalOpen(false), children: "No" })] }) })] }) })] }));
2380
+ }
2381
+
2382
+ // in miliseconds
2383
+ const units = [
2384
+ { label: 'year', seconds: 31536000 },
2385
+ { label: 'month', seconds: 2592000 },
2386
+ { label: 'week', seconds: 604800 },
2387
+ { label: 'day', seconds: 86400 },
2388
+ { label: 'hour', seconds: 3600 },
2389
+ { label: 'minute', seconds: 60 },
2390
+ { label: 'second', seconds: 1 },
2391
+ ];
2392
+ const timeAgo = (date) => {
2393
+ const time = Math.floor((new Date().valueOf() - new Date(date).valueOf()) / 1000);
2394
+ const { interval, unit } = calculateTimeDifference(time);
2395
+ const suffix = interval === 1 ? '' : 's';
2396
+ return `${interval} ${unit}${suffix} ago`;
2397
+ };
2398
+ const calculateTimeDifference = (time) => {
2399
+ for (const { label, seconds } of units) {
2400
+ const interval = Math.floor(time / seconds);
2401
+ if (interval >= 1) {
2402
+ return {
2403
+ interval,
2404
+ unit: label,
2405
+ };
2406
+ }
2407
+ }
2408
+ return {
2409
+ interval: 0,
2410
+ unit: '',
2411
+ };
2412
+ };
2413
+
2414
+ const TagView = ({ tag, heighlight, onClick, count, }) => {
2415
+ return (
2416
+ // Use your imagination to render suggestions.
2417
+ jsxs("div", { onClick: onClick, className: `tw:flex tw:items-center tw:flex-row tw:rounded-2xl tw:text-white tw:p-2 tw:px-4 tw:shadow-xl card tw:mt-3 tw:mr-4 tw:cursor-pointer tw:w-fit ${heighlight ? 'tw:border-4 tw:border-base-200 tw:shadow-lg' : ''}`, style: { backgroundColor: tag.color ? tag.color : '#666' }, children: [jsx("b", { children: decodeTag(tag.name) }), count && jsxs("span", { className: 'tw:ml-2', children: ["(", count, ")"] })] }, tag.name));
2418
+ };
2419
+
2420
+ export { useRemoveItem as $, AppStateProvider as A, TextView as B, ClusterRefProvider as C, useResetFilterTags as D, useSetItemsApi as E, FilterProvider as F, useSetItemsData as G, useAddTag as H, ItemsProvider as I, useSetTagData as J, useSetTagApi as K, LayersProvider as L, useSetPermissionData as M, useSetPermissionApi as N, useSetAdminRole as O, PermissionsProvider as P, ForwardRef$3 as Q, MapOverlayPage as R, SelectPositionProvider as S, TagsProvider as T, TextAreaInput as U, TextInput as V, useGetItemTags as W, timeAgo as X, HeaderView as Y, StartEndView as Z, useAddItem as _, LeafletRefsProvider as a, PopupStartEndInput as a0, hashTagRegex as a1, randomColor as a2, TagView as a3, useUpdateItem as a4, useAddMarker as a5, useAddPopup as a6, useAllTagsLoaded as a7, useAllItemsLoaded as a8, useSetMarkerClicked as a9, encodeTag as aa, AuthProvider as ab, DialogModal as ac, ForwardRef as ad, useHasUserPermission as b, useAddVisibleGroupType as c, useIsGroupTypeVisible as d, useToggleVisibleGroupType as e, useVisibleGroupType as f, useAuth as g, useIsLayerVisible as h, useToggleVisibleLayer as i, useAppState as j, useSetAppState as k, useWindowDimensions as l, useTags as m, useItems as n, useLeafletRefs as o, useAddFilterTag as p, decodeTag as q, useFilterTags as r, useRemoveFilterTag as s, useSelectPosition as t, useLayers as u, useSetSelectPosition as v, useSetClusterRef as w, useClusterRef as x, useSetMapClicked as y, useAddVisibleLayer as z };
2421
+ //# sourceMappingURL=TagView-C6Dx0Dh8.js.map