utopia-ui 3.0.107 → 3.0.109

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