utopia-ui 3.0.94 → 3.0.96
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.
- package/dist/ItemsApi.d-D5bfsxpo.d.ts +13 -0
- package/dist/Profile.cjs.js +21090 -0
- package/dist/Profile.cjs.js.map +1 -0
- package/dist/Profile.d.ts +21 -0
- package/dist/Profile.esm.js +21068 -0
- package/dist/Profile.esm.js.map +1 -0
- package/dist/TagView-D8MzLpNR.js +2481 -0
- package/dist/TagView-D8MzLpNR.js.map +1 -0
- package/dist/TagView-nJhkFKCX.js +2568 -0
- package/dist/TagView-nJhkFKCX.js.map +1 -0
- package/dist/index.cjs.js +5103 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +11 -30
- package/dist/index.esm.js +3890 -4785
- package/dist/index.esm.js.map +1 -1
- package/dist/types/src/Components/Input/RichTextEditor.d.ts +17 -0
- package/dist/types/src/Components/Templates/LoadingMapOverlay.d.ts +1 -0
- package/dist/types/src/Components/Templates/index.d.ts +2 -0
- package/dist/types/src/css.d.ts +1 -0
- package/dist/types/src/index.d.ts +0 -1
- package/package.json +12 -1
- package/dist/index.cjs +0 -6000
- package/dist/index.cjs.map +0 -1
- package/dist/types/src/Components/AppShell/hooks/useAssets.d.ts +0 -12
- package/dist/types/src/Components/Input/TextInput.cy.d.ts +0 -1
- package/dist/types/src/Components/Map/ItemForm.d.ts +0 -13
- package/dist/types/src/Components/Map/ItemView.d.ts +0 -11
- package/dist/types/src/Components/Map/UrlState.d.ts +0 -1
- package/dist/types/src/Components/Map/setItemLocation.d.ts +0 -1
@@ -0,0 +1,2568 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
4
|
+
var React = require('react');
|
5
|
+
var reactToastify = require('react-toastify');
|
6
|
+
var require$$0 = require('leaflet');
|
7
|
+
var Markdown = require('react-markdown');
|
8
|
+
var remarkBreaks = require('remark-breaks');
|
9
|
+
var reactRouterDom = require('react-router-dom');
|
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
|
+
if (markerClicked?.layer?.api?.collectionName &&
|
813
|
+
hasUserPermission(markerClicked.layer.api.collectionName, 'update', markerClicked)) {
|
814
|
+
let success = false;
|
815
|
+
try {
|
816
|
+
await updatedItem.layer?.api?.updateItem({
|
817
|
+
id: updatedItem.id,
|
818
|
+
parent: updatedItem.parent,
|
819
|
+
position: null,
|
820
|
+
});
|
821
|
+
success = true;
|
822
|
+
// eslint-disable-next-line no-catch-all/no-catch-all
|
823
|
+
}
|
824
|
+
catch (error) {
|
825
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
826
|
+
reactToastify.toast.error(error.toString());
|
827
|
+
}
|
828
|
+
if (success) {
|
829
|
+
await updateItem({ ...updatedItem, parent: updatedItem.parent, position: undefined });
|
830
|
+
await linkItem(updatedItem.id);
|
831
|
+
reactToastify.toast.success('Item position updated');
|
832
|
+
setSelectPosition(null);
|
833
|
+
setMarkerClicked(null);
|
834
|
+
}
|
835
|
+
}
|
836
|
+
else {
|
837
|
+
setSelectPosition(null);
|
838
|
+
reactToastify.toast.error("you don't have permission to add items to " + markerClicked?.name);
|
839
|
+
}
|
840
|
+
};
|
841
|
+
const itemUpdatePosition = async (updatedItem) => {
|
842
|
+
let success = false;
|
843
|
+
try {
|
844
|
+
await updatedItem.layer?.api?.updateItem({
|
845
|
+
id: updatedItem.id,
|
846
|
+
position: updatedItem.position,
|
847
|
+
});
|
848
|
+
success = true;
|
849
|
+
// eslint-disable-next-line no-catch-all/no-catch-all
|
850
|
+
}
|
851
|
+
catch (error) {
|
852
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
853
|
+
reactToastify.toast.error(error.toString());
|
854
|
+
}
|
855
|
+
if (success) {
|
856
|
+
updateItem(updatedItem);
|
857
|
+
reactToastify.toast.success('Item position updated');
|
858
|
+
}
|
859
|
+
};
|
860
|
+
const linkItem = async (id) => {
|
861
|
+
if (markerClicked) {
|
862
|
+
const newRelations = markerClicked.relations || [];
|
863
|
+
if (!newRelations.some((r) => r.related_items_id === id)) {
|
864
|
+
newRelations.push({ items_id: markerClicked.id, related_items_id: id });
|
865
|
+
const updatedItem = { id: markerClicked.id, relations: newRelations };
|
866
|
+
let success = false;
|
867
|
+
try {
|
868
|
+
await markerClicked.layer?.api?.updateItem(updatedItem);
|
869
|
+
success = true;
|
870
|
+
// eslint-disable-next-line no-catch-all/no-catch-all
|
871
|
+
}
|
872
|
+
catch (error) {
|
873
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
874
|
+
reactToastify.toast.error(error.toString());
|
875
|
+
}
|
876
|
+
if (success) {
|
877
|
+
updateItem({ ...markerClicked, relations: newRelations });
|
878
|
+
reactToastify.toast.success('Item linked');
|
879
|
+
}
|
880
|
+
}
|
881
|
+
}
|
882
|
+
};
|
883
|
+
return { selectPosition, setSelectPosition, setMarkerClicked, setMapClicked };
|
884
|
+
}
|
885
|
+
const SelectPositionProvider = ({ children }) => (jsxRuntime.jsx(SelectPositionContext.Provider, { value: useSelectPositionManager(), children: children }));
|
886
|
+
const useSelectPosition = () => {
|
887
|
+
const { selectPosition } = React.useContext(SelectPositionContext);
|
888
|
+
return selectPosition;
|
889
|
+
};
|
890
|
+
const useSetSelectPosition = () => {
|
891
|
+
const { setSelectPosition } = React.useContext(SelectPositionContext);
|
892
|
+
return setSelectPosition;
|
893
|
+
};
|
894
|
+
const useSetMarkerClicked = () => {
|
895
|
+
const { setMarkerClicked } = React.useContext(SelectPositionContext);
|
896
|
+
return setMarkerClicked;
|
897
|
+
};
|
898
|
+
const useSetMapClicked = () => {
|
899
|
+
const { setMapClicked } = React.useContext(SelectPositionContext);
|
900
|
+
return setMapClicked;
|
901
|
+
};
|
902
|
+
|
903
|
+
const hashTagRegex = /(#+[a-zA-Z0-9À-ÖØ-öø-ʸ_-]{1,})/g;
|
904
|
+
|
905
|
+
const TagContext = React.createContext({
|
906
|
+
tags: [],
|
907
|
+
addTag: () => { },
|
908
|
+
setTagApi: () => { },
|
909
|
+
setTagData: () => { },
|
910
|
+
getItemTags: () => [],
|
911
|
+
allTagsLoaded: false,
|
912
|
+
});
|
913
|
+
function useTagsManager(initialTags) {
|
914
|
+
const [allTagsLoaded, setallTagsLoaded] = React.useState(false);
|
915
|
+
const [tagCount, setTagCount] = React.useState(0);
|
916
|
+
const [tags, dispatch] = React.useReducer((state, action) => {
|
917
|
+
switch (action.type) {
|
918
|
+
case 'ADD':
|
919
|
+
// eslint-disable-next-line no-case-declarations
|
920
|
+
const exist = state.find((tag) => tag.name.toLocaleLowerCase() === action.tag.name.toLocaleLowerCase());
|
921
|
+
if (!exist) {
|
922
|
+
const newState = [...state, { ...action.tag }];
|
923
|
+
if (tagCount === newState.length)
|
924
|
+
setallTagsLoaded(true);
|
925
|
+
return newState;
|
926
|
+
}
|
927
|
+
else
|
928
|
+
return state;
|
929
|
+
default:
|
930
|
+
throw new Error();
|
931
|
+
}
|
932
|
+
}, initialTags);
|
933
|
+
const [api, setApi] = React.useState({});
|
934
|
+
const setTagApi = React.useCallback(async (api) => {
|
935
|
+
setApi(api);
|
936
|
+
const result = await api.getItems();
|
937
|
+
setTagCount(result.length);
|
938
|
+
if (tagCount === 0)
|
939
|
+
setallTagsLoaded(true);
|
940
|
+
if (result) {
|
941
|
+
result.map((tag) => {
|
942
|
+
// tag.name = tag.name.toLocaleLowerCase();
|
943
|
+
dispatch({ type: 'ADD', tag });
|
944
|
+
return null;
|
945
|
+
});
|
946
|
+
}
|
947
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
948
|
+
}, []);
|
949
|
+
const setTagData = React.useCallback((data) => {
|
950
|
+
data.map((tag) => {
|
951
|
+
// tag.name = tag.name.toLocaleLowerCase();
|
952
|
+
dispatch({ type: 'ADD', tag });
|
953
|
+
return null;
|
954
|
+
});
|
955
|
+
}, []);
|
956
|
+
const addTag = (tag) => {
|
957
|
+
dispatch({
|
958
|
+
type: 'ADD',
|
959
|
+
tag,
|
960
|
+
});
|
961
|
+
if (!tags.some((t) => t.name.toLocaleLowerCase() === tag.name.toLocaleLowerCase())) {
|
962
|
+
api.createItem && api.createItem(tag);
|
963
|
+
}
|
964
|
+
};
|
965
|
+
const getItemTags = React.useCallback((item) => {
|
966
|
+
const text = item.text;
|
967
|
+
const itemTagStrings = text?.match(hashTagRegex);
|
968
|
+
const itemTags = [];
|
969
|
+
itemTagStrings?.map((tag) => {
|
970
|
+
if (tags.find((t) => t.name.toLocaleLowerCase() === tag.slice(1).toLocaleLowerCase())) {
|
971
|
+
itemTags.push(tags.find((t) => t.name.toLocaleLowerCase() === tag.slice(1).toLocaleLowerCase()));
|
972
|
+
}
|
973
|
+
return null;
|
974
|
+
});
|
975
|
+
// Could be refactored as it occurs in multiple places
|
976
|
+
item.offers?.forEach((o) => {
|
977
|
+
const offer = tags.find((t) => t.id === o.tags_id);
|
978
|
+
offer && itemTags.push(offer);
|
979
|
+
});
|
980
|
+
item.needs?.forEach((n) => {
|
981
|
+
const need = tags.find((t) => t.id === n.tags_id);
|
982
|
+
need && itemTags.push(need);
|
983
|
+
});
|
984
|
+
return itemTags;
|
985
|
+
}, [tags]);
|
986
|
+
return { tags, addTag, setTagApi, setTagData, getItemTags, allTagsLoaded };
|
987
|
+
}
|
988
|
+
const TagsProvider = ({ initialTags, children }) => (jsxRuntime.jsx(TagContext.Provider, { value: useTagsManager(initialTags), children: children }));
|
989
|
+
const useTags = () => {
|
990
|
+
const { tags } = React.useContext(TagContext);
|
991
|
+
return tags;
|
992
|
+
};
|
993
|
+
const useAddTag = () => {
|
994
|
+
const { addTag } = React.useContext(TagContext);
|
995
|
+
return addTag;
|
996
|
+
};
|
997
|
+
const useSetTagApi = () => {
|
998
|
+
const { setTagApi } = React.useContext(TagContext);
|
999
|
+
return setTagApi;
|
1000
|
+
};
|
1001
|
+
const useSetTagData = () => {
|
1002
|
+
const { setTagData } = React.useContext(TagContext);
|
1003
|
+
return setTagData;
|
1004
|
+
};
|
1005
|
+
const useGetItemTags = () => {
|
1006
|
+
const { getItemTags } = React.useContext(TagContext);
|
1007
|
+
return getItemTags;
|
1008
|
+
};
|
1009
|
+
const useAllTagsLoaded = () => {
|
1010
|
+
const { allTagsLoaded } = React.useContext(TagContext);
|
1011
|
+
return allTagsLoaded;
|
1012
|
+
};
|
1013
|
+
|
1014
|
+
const initialAppState = {
|
1015
|
+
assetsApi: {},
|
1016
|
+
sideBarOpen: false,
|
1017
|
+
sideBarSlim: false,
|
1018
|
+
showThemeControl: false,
|
1019
|
+
embedded: false,
|
1020
|
+
openCollectiveApiKey: '',
|
1021
|
+
};
|
1022
|
+
const AppContext = React.createContext({
|
1023
|
+
state: initialAppState,
|
1024
|
+
setAppState: () => { },
|
1025
|
+
});
|
1026
|
+
function useAppManager() {
|
1027
|
+
const [state, setState] = React.useState(initialAppState);
|
1028
|
+
const setAppState = React.useCallback((newState) => {
|
1029
|
+
setState((prevState) => ({
|
1030
|
+
...prevState,
|
1031
|
+
...newState,
|
1032
|
+
}));
|
1033
|
+
}, []);
|
1034
|
+
return { state, setAppState };
|
1035
|
+
}
|
1036
|
+
const AppStateProvider = ({ children }) => jsxRuntime.jsx(AppContext.Provider, { value: useAppManager(), children: children });
|
1037
|
+
const useAppState = () => {
|
1038
|
+
const { state } = React.useContext(AppContext);
|
1039
|
+
return state;
|
1040
|
+
};
|
1041
|
+
const useSetAppState = () => {
|
1042
|
+
const { setAppState } = React.useContext(AppContext);
|
1043
|
+
return setAppState;
|
1044
|
+
};
|
1045
|
+
|
1046
|
+
function decodeTag(string) {
|
1047
|
+
const formatedTag = string.replace(/_/g, '\u00A0');
|
1048
|
+
return formatedTag.charAt(0).toUpperCase() + formatedTag.slice(1);
|
1049
|
+
}
|
1050
|
+
function encodeTag(string) {
|
1051
|
+
return string.replace(/\s+/g, '_');
|
1052
|
+
}
|
1053
|
+
|
1054
|
+
var L_Control_Locate = {exports: {}};
|
1055
|
+
|
1056
|
+
/*!
|
1057
|
+
Copyright (c) 2016 Dominik Moritz
|
1058
|
+
|
1059
|
+
This file is part of the leaflet locate control. It is licensed under the MIT license.
|
1060
|
+
You can find the project at: https://github.com/domoritz/leaflet-locatecontrol
|
1061
|
+
*/
|
1062
|
+
|
1063
|
+
var hasRequiredL_Control_Locate;
|
1064
|
+
|
1065
|
+
function requireL_Control_Locate () {
|
1066
|
+
if (hasRequiredL_Control_Locate) return L_Control_Locate.exports;
|
1067
|
+
hasRequiredL_Control_Locate = 1;
|
1068
|
+
(function (module, exports) {
|
1069
|
+
(function (factory, window) {
|
1070
|
+
// see https://github.com/Leaflet/Leaflet/blob/master/PLUGIN-GUIDE.md#module-loaders
|
1071
|
+
// for details on how to structure a leaflet plugin.
|
1072
|
+
|
1073
|
+
// define an AMD module that relies on 'leaflet'
|
1074
|
+
{
|
1075
|
+
if (typeof window !== "undefined" && window.L) {
|
1076
|
+
module.exports = factory(L);
|
1077
|
+
} else {
|
1078
|
+
module.exports = factory(require$$0);
|
1079
|
+
}
|
1080
|
+
}
|
1081
|
+
|
1082
|
+
// attach your plugin to the global 'L' variable
|
1083
|
+
if (typeof window !== "undefined" && window.L) {
|
1084
|
+
window.L.Control.Locate = factory(L);
|
1085
|
+
}
|
1086
|
+
})(function (L) {
|
1087
|
+
const LDomUtilApplyClassesMethod = (method, element, classNames) => {
|
1088
|
+
classNames = classNames.split(" ");
|
1089
|
+
classNames.forEach(function (className) {
|
1090
|
+
L.DomUtil[method].call(this, element, className);
|
1091
|
+
});
|
1092
|
+
};
|
1093
|
+
|
1094
|
+
const addClasses = (el, names) => LDomUtilApplyClassesMethod("addClass", el, names);
|
1095
|
+
const removeClasses = (el, names) => LDomUtilApplyClassesMethod("removeClass", el, names);
|
1096
|
+
|
1097
|
+
/**
|
1098
|
+
* Compatible with L.Circle but a true marker instead of a path
|
1099
|
+
*/
|
1100
|
+
const LocationMarker = L.Marker.extend({
|
1101
|
+
initialize(latlng, options) {
|
1102
|
+
L.Util.setOptions(this, options);
|
1103
|
+
this._latlng = latlng;
|
1104
|
+
this.createIcon();
|
1105
|
+
},
|
1106
|
+
|
1107
|
+
/**
|
1108
|
+
* Create a styled circle location marker
|
1109
|
+
*/
|
1110
|
+
createIcon() {
|
1111
|
+
const opt = this.options;
|
1112
|
+
|
1113
|
+
let style = "";
|
1114
|
+
|
1115
|
+
if (opt.color !== undefined) {
|
1116
|
+
style += `stroke:${opt.color};`;
|
1117
|
+
}
|
1118
|
+
if (opt.weight !== undefined) {
|
1119
|
+
style += `stroke-width:${opt.weight};`;
|
1120
|
+
}
|
1121
|
+
if (opt.fillColor !== undefined) {
|
1122
|
+
style += `fill:${opt.fillColor};`;
|
1123
|
+
}
|
1124
|
+
if (opt.fillOpacity !== undefined) {
|
1125
|
+
style += `fill-opacity:${opt.fillOpacity};`;
|
1126
|
+
}
|
1127
|
+
if (opt.opacity !== undefined) {
|
1128
|
+
style += `opacity:${opt.opacity};`;
|
1129
|
+
}
|
1130
|
+
|
1131
|
+
const icon = this._getIconSVG(opt, style);
|
1132
|
+
|
1133
|
+
this._locationIcon = L.divIcon({
|
1134
|
+
className: icon.className,
|
1135
|
+
html: icon.svg,
|
1136
|
+
iconSize: [icon.w, icon.h]
|
1137
|
+
});
|
1138
|
+
|
1139
|
+
this.setIcon(this._locationIcon);
|
1140
|
+
},
|
1141
|
+
|
1142
|
+
/**
|
1143
|
+
* Return the raw svg for the shape
|
1144
|
+
*
|
1145
|
+
* Split so can be easily overridden
|
1146
|
+
*/
|
1147
|
+
_getIconSVG(options, style) {
|
1148
|
+
const r = options.radius;
|
1149
|
+
const w = options.weight;
|
1150
|
+
const s = r + w;
|
1151
|
+
const s2 = s * 2;
|
1152
|
+
const svg =
|
1153
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${s2}" height="${s2}" version="1.1" viewBox="-${s} -${s} ${s2} ${s2}">` +
|
1154
|
+
'<circle r="' +
|
1155
|
+
r +
|
1156
|
+
'" style="' +
|
1157
|
+
style +
|
1158
|
+
'" />' +
|
1159
|
+
"</svg>";
|
1160
|
+
return {
|
1161
|
+
className: "leaflet-control-locate-location",
|
1162
|
+
svg,
|
1163
|
+
w: s2,
|
1164
|
+
h: s2
|
1165
|
+
};
|
1166
|
+
},
|
1167
|
+
|
1168
|
+
setStyle(style) {
|
1169
|
+
L.Util.setOptions(this, style);
|
1170
|
+
this.createIcon();
|
1171
|
+
}
|
1172
|
+
});
|
1173
|
+
|
1174
|
+
const CompassMarker = LocationMarker.extend({
|
1175
|
+
initialize(latlng, heading, options) {
|
1176
|
+
L.Util.setOptions(this, options);
|
1177
|
+
this._latlng = latlng;
|
1178
|
+
this._heading = heading;
|
1179
|
+
this.createIcon();
|
1180
|
+
},
|
1181
|
+
|
1182
|
+
setHeading(heading) {
|
1183
|
+
this._heading = heading;
|
1184
|
+
},
|
1185
|
+
|
1186
|
+
/**
|
1187
|
+
* Create a styled arrow compass marker
|
1188
|
+
*/
|
1189
|
+
_getIconSVG(options, style) {
|
1190
|
+
const r = options.radius;
|
1191
|
+
const w = options.width + options.weight;
|
1192
|
+
const h = (r + options.depth + options.weight) * 2;
|
1193
|
+
const path = `M0,0 l${options.width / 2},${options.depth} l-${w},0 z`;
|
1194
|
+
const svgstyle = `transform: rotate(${this._heading}deg)`;
|
1195
|
+
const svg =
|
1196
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" version="1.1" viewBox="-${w / 2} 0 ${w} ${h}" style="${svgstyle}">` +
|
1197
|
+
'<path d="' +
|
1198
|
+
path +
|
1199
|
+
'" style="' +
|
1200
|
+
style +
|
1201
|
+
'" />' +
|
1202
|
+
"</svg>";
|
1203
|
+
return {
|
1204
|
+
className: "leaflet-control-locate-heading",
|
1205
|
+
svg,
|
1206
|
+
w,
|
1207
|
+
h
|
1208
|
+
};
|
1209
|
+
}
|
1210
|
+
});
|
1211
|
+
|
1212
|
+
const LocateControl = L.Control.extend({
|
1213
|
+
options: {
|
1214
|
+
/** Position of the control */
|
1215
|
+
position: "topleft",
|
1216
|
+
/** The layer that the user's location should be drawn on. By default creates a new layer. */
|
1217
|
+
layer: undefined,
|
1218
|
+
/**
|
1219
|
+
* Automatically sets the map view (zoom and pan) to the user's location as it updates.
|
1220
|
+
* While the map is following the user's location, the control is in the `following` state,
|
1221
|
+
* which changes the style of the control and the circle marker.
|
1222
|
+
*
|
1223
|
+
* Possible values:
|
1224
|
+
* - false: never updates the map view when location changes.
|
1225
|
+
* - 'once': set the view when the location is first determined
|
1226
|
+
* - 'always': always updates the map view when location changes.
|
1227
|
+
* The map view follows the user's location.
|
1228
|
+
* - 'untilPan': like 'always', except stops updating the
|
1229
|
+
* view if the user has manually panned the map.
|
1230
|
+
* The map view follows the user's location until she pans.
|
1231
|
+
* - 'untilPanOrZoom': (default) like 'always', except stops updating the
|
1232
|
+
* view if the user has manually panned the map.
|
1233
|
+
* The map view follows the user's location until she pans.
|
1234
|
+
*/
|
1235
|
+
setView: "untilPanOrZoom",
|
1236
|
+
/** Keep the current map zoom level when setting the view and only pan. */
|
1237
|
+
keepCurrentZoomLevel: false,
|
1238
|
+
/** 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. */
|
1239
|
+
initialZoomLevel: false,
|
1240
|
+
/**
|
1241
|
+
* This callback can be used to override the viewport tracking
|
1242
|
+
* This function should return a LatLngBounds object.
|
1243
|
+
*
|
1244
|
+
* For example to extend the viewport to ensure that a particular LatLng is visible:
|
1245
|
+
*
|
1246
|
+
* getLocationBounds: function(locationEvent) {
|
1247
|
+
* return locationEvent.bounds.extend([-33.873085, 151.219273]);
|
1248
|
+
* },
|
1249
|
+
*/
|
1250
|
+
getLocationBounds(locationEvent) {
|
1251
|
+
return locationEvent.bounds;
|
1252
|
+
},
|
1253
|
+
/** Smooth pan and zoom to the location of the marker. Only works in Leaflet 1.0+. */
|
1254
|
+
flyTo: false,
|
1255
|
+
/**
|
1256
|
+
* The user location can be inside and outside the current view when the user clicks on the
|
1257
|
+
* control that is already active. Both cases can be configures separately.
|
1258
|
+
* Possible values are:
|
1259
|
+
* - 'setView': zoom and pan to the current location
|
1260
|
+
* - 'stop': stop locating and remove the location marker
|
1261
|
+
*/
|
1262
|
+
clickBehavior: {
|
1263
|
+
/** What should happen if the user clicks on the control while the location is within the current view. */
|
1264
|
+
inView: "stop",
|
1265
|
+
/** What should happen if the user clicks on the control while the location is outside the current view. */
|
1266
|
+
outOfView: "setView",
|
1267
|
+
/**
|
1268
|
+
* What should happen if the user clicks on the control while the location is within the current view
|
1269
|
+
* and we could be following but are not. Defaults to a special value which inherits from 'inView';
|
1270
|
+
*/
|
1271
|
+
inViewNotFollowing: "inView"
|
1272
|
+
},
|
1273
|
+
/**
|
1274
|
+
* If set, save the map bounds just before centering to the user's
|
1275
|
+
* location. When control is disabled, set the view back to the
|
1276
|
+
* bounds that were saved.
|
1277
|
+
*/
|
1278
|
+
returnToPrevBounds: false,
|
1279
|
+
/**
|
1280
|
+
* Keep a cache of the location after the user deactivates the control. If set to false, the user has to wait
|
1281
|
+
* until the locate API returns a new location before they see where they are again.
|
1282
|
+
*/
|
1283
|
+
cacheLocation: true,
|
1284
|
+
/** If set, a circle that shows the location accuracy is drawn. */
|
1285
|
+
drawCircle: true,
|
1286
|
+
/** If set, the marker at the users' location is drawn. */
|
1287
|
+
drawMarker: true,
|
1288
|
+
/** If set and supported then show the compass heading */
|
1289
|
+
showCompass: true,
|
1290
|
+
/** The class to be used to create the marker. For example L.CircleMarker or L.Marker */
|
1291
|
+
markerClass: LocationMarker,
|
1292
|
+
/** The class us be used to create the compass bearing arrow */
|
1293
|
+
compassClass: CompassMarker,
|
1294
|
+
/** Accuracy circle style properties. NOTE these styles should match the css animations styles */
|
1295
|
+
circleStyle: {
|
1296
|
+
className: "leaflet-control-locate-circle",
|
1297
|
+
color: "#136AEC",
|
1298
|
+
fillColor: "#136AEC",
|
1299
|
+
fillOpacity: 0.15,
|
1300
|
+
weight: 0
|
1301
|
+
},
|
1302
|
+
/** Inner marker style properties. Only works if your marker class supports `setStyle`. */
|
1303
|
+
markerStyle: {
|
1304
|
+
className: "leaflet-control-locate-marker",
|
1305
|
+
color: "#fff",
|
1306
|
+
fillColor: "#2A93EE",
|
1307
|
+
fillOpacity: 1,
|
1308
|
+
weight: 3,
|
1309
|
+
opacity: 1,
|
1310
|
+
radius: 9
|
1311
|
+
},
|
1312
|
+
/** Compass */
|
1313
|
+
compassStyle: {
|
1314
|
+
fillColor: "#2A93EE",
|
1315
|
+
fillOpacity: 1,
|
1316
|
+
weight: 0,
|
1317
|
+
color: "#fff",
|
1318
|
+
opacity: 1,
|
1319
|
+
radius: 9, // How far is the arrow is from the center of of the marker
|
1320
|
+
width: 9, // Width of the arrow
|
1321
|
+
depth: 6 // Length of the arrow
|
1322
|
+
},
|
1323
|
+
/**
|
1324
|
+
* Changes to accuracy circle and inner marker while following.
|
1325
|
+
* It is only necessary to provide the properties that should change.
|
1326
|
+
*/
|
1327
|
+
followCircleStyle: {},
|
1328
|
+
followMarkerStyle: {
|
1329
|
+
// color: '#FFA500',
|
1330
|
+
// fillColor: '#FFB000'
|
1331
|
+
},
|
1332
|
+
followCompassStyle: {},
|
1333
|
+
/** The CSS class for the icon. For example fa-location-arrow or fa-map-marker */
|
1334
|
+
icon: "leaflet-control-locate-location-arrow",
|
1335
|
+
iconLoading: "leaflet-control-locate-spinner",
|
1336
|
+
/** The element to be created for icons. For example span or i */
|
1337
|
+
iconElementTag: "span",
|
1338
|
+
/** The element to be created for the text. For example small or span */
|
1339
|
+
textElementTag: "small",
|
1340
|
+
/** Padding around the accuracy circle. */
|
1341
|
+
circlePadding: [0, 0],
|
1342
|
+
/** Use metric units. */
|
1343
|
+
metric: true,
|
1344
|
+
/**
|
1345
|
+
* This callback can be used in case you would like to override button creation behavior.
|
1346
|
+
* This is useful for DOM manipulation frameworks such as angular etc.
|
1347
|
+
* This function should return an object with HtmlElement for the button (link property) and the icon (icon property).
|
1348
|
+
*/
|
1349
|
+
createButtonCallback(container, options) {
|
1350
|
+
const link = L.DomUtil.create("a", "leaflet-bar-part leaflet-bar-part-single", container);
|
1351
|
+
link.title = options.strings.title;
|
1352
|
+
link.href = "#";
|
1353
|
+
link.setAttribute("role", "button");
|
1354
|
+
const icon = L.DomUtil.create(options.iconElementTag, options.icon, link);
|
1355
|
+
|
1356
|
+
if (options.strings.text !== undefined) {
|
1357
|
+
const text = L.DomUtil.create(options.textElementTag, "leaflet-locate-text", link);
|
1358
|
+
text.textContent = options.strings.text;
|
1359
|
+
link.classList.add("leaflet-locate-text-active");
|
1360
|
+
link.parentNode.style.display = "flex";
|
1361
|
+
if (options.icon.length > 0) {
|
1362
|
+
icon.classList.add("leaflet-locate-icon");
|
1363
|
+
}
|
1364
|
+
}
|
1365
|
+
|
1366
|
+
return { link, icon };
|
1367
|
+
},
|
1368
|
+
/** This event is called in case of any location error that is not a time out error. */
|
1369
|
+
onLocationError(err, control) {
|
1370
|
+
alert(err.message);
|
1371
|
+
},
|
1372
|
+
/**
|
1373
|
+
* This event is called when the user's location is outside the bounds set on the map.
|
1374
|
+
* The event is called repeatedly when the location changes.
|
1375
|
+
*/
|
1376
|
+
onLocationOutsideMapBounds(control) {
|
1377
|
+
control.stop();
|
1378
|
+
alert(control.options.strings.outsideMapBoundsMsg);
|
1379
|
+
},
|
1380
|
+
/** Display a pop-up when the user click on the inner marker. */
|
1381
|
+
showPopup: true,
|
1382
|
+
strings: {
|
1383
|
+
title: "Show me where I am",
|
1384
|
+
metersUnit: "meters",
|
1385
|
+
feetUnit: "feet",
|
1386
|
+
popup: "You are within {distance} {unit} from this point",
|
1387
|
+
outsideMapBoundsMsg: "You seem located outside the boundaries of the map"
|
1388
|
+
},
|
1389
|
+
/** The default options passed to leaflets locate method. */
|
1390
|
+
locateOptions: {
|
1391
|
+
maxZoom: Infinity,
|
1392
|
+
watch: true, // if you overwrite this, visualization cannot be updated
|
1393
|
+
setView: false // have to set this to false because we have to
|
1394
|
+
// do setView manually
|
1395
|
+
}
|
1396
|
+
},
|
1397
|
+
|
1398
|
+
initialize(options) {
|
1399
|
+
// set default options if nothing is set (merge one step deep)
|
1400
|
+
for (const i in options) {
|
1401
|
+
if (typeof this.options[i] === "object") {
|
1402
|
+
L.extend(this.options[i], options[i]);
|
1403
|
+
} else {
|
1404
|
+
this.options[i] = options[i];
|
1405
|
+
}
|
1406
|
+
}
|
1407
|
+
|
1408
|
+
// extend the follow marker style and circle from the normal style
|
1409
|
+
this.options.followMarkerStyle = L.extend({}, this.options.markerStyle, this.options.followMarkerStyle);
|
1410
|
+
this.options.followCircleStyle = L.extend({}, this.options.circleStyle, this.options.followCircleStyle);
|
1411
|
+
this.options.followCompassStyle = L.extend({}, this.options.compassStyle, this.options.followCompassStyle);
|
1412
|
+
},
|
1413
|
+
|
1414
|
+
/**
|
1415
|
+
* Add control to map. Returns the container for the control.
|
1416
|
+
*/
|
1417
|
+
onAdd(map) {
|
1418
|
+
const container = L.DomUtil.create("div", "leaflet-control-locate leaflet-bar leaflet-control");
|
1419
|
+
this._container = container;
|
1420
|
+
this._map = map;
|
1421
|
+
this._layer = this.options.layer || new L.LayerGroup();
|
1422
|
+
this._layer.addTo(map);
|
1423
|
+
this._event = undefined;
|
1424
|
+
this._compassHeading = null;
|
1425
|
+
this._prevBounds = null;
|
1426
|
+
|
1427
|
+
const linkAndIcon = this.options.createButtonCallback(container, this.options);
|
1428
|
+
this._link = linkAndIcon.link;
|
1429
|
+
this._icon = linkAndIcon.icon;
|
1430
|
+
|
1431
|
+
L.DomEvent.on(
|
1432
|
+
this._link,
|
1433
|
+
"click",
|
1434
|
+
function (ev) {
|
1435
|
+
L.DomEvent.stopPropagation(ev);
|
1436
|
+
L.DomEvent.preventDefault(ev);
|
1437
|
+
this._onClick();
|
1438
|
+
},
|
1439
|
+
this
|
1440
|
+
).on(this._link, "dblclick", L.DomEvent.stopPropagation);
|
1441
|
+
|
1442
|
+
this._resetVariables();
|
1443
|
+
|
1444
|
+
this._map.on("unload", this._unload, this);
|
1445
|
+
|
1446
|
+
return container;
|
1447
|
+
},
|
1448
|
+
|
1449
|
+
/**
|
1450
|
+
* This method is called when the user clicks on the control.
|
1451
|
+
*/
|
1452
|
+
_onClick() {
|
1453
|
+
this._justClicked = true;
|
1454
|
+
const wasFollowing = this._isFollowing();
|
1455
|
+
this._userPanned = false;
|
1456
|
+
this._userZoomed = false;
|
1457
|
+
|
1458
|
+
if (this._active && !this._event) {
|
1459
|
+
// click while requesting
|
1460
|
+
this.stop();
|
1461
|
+
} else if (this._active) {
|
1462
|
+
const behaviors = this.options.clickBehavior;
|
1463
|
+
let behavior = behaviors.outOfView;
|
1464
|
+
if (this._map.getBounds().contains(this._event.latlng)) {
|
1465
|
+
behavior = wasFollowing ? behaviors.inView : behaviors.inViewNotFollowing;
|
1466
|
+
}
|
1467
|
+
|
1468
|
+
// Allow inheriting from another behavior
|
1469
|
+
if (behaviors[behavior]) {
|
1470
|
+
behavior = behaviors[behavior];
|
1471
|
+
}
|
1472
|
+
|
1473
|
+
switch (behavior) {
|
1474
|
+
case "setView":
|
1475
|
+
this.setView();
|
1476
|
+
break;
|
1477
|
+
case "stop":
|
1478
|
+
this.stop();
|
1479
|
+
if (this.options.returnToPrevBounds) {
|
1480
|
+
const f = this.options.flyTo ? this._map.flyToBounds : this._map.fitBounds;
|
1481
|
+
f.bind(this._map)(this._prevBounds);
|
1482
|
+
}
|
1483
|
+
break;
|
1484
|
+
}
|
1485
|
+
} else {
|
1486
|
+
if (this.options.returnToPrevBounds) {
|
1487
|
+
this._prevBounds = this._map.getBounds();
|
1488
|
+
}
|
1489
|
+
this.start();
|
1490
|
+
}
|
1491
|
+
|
1492
|
+
this._updateContainerStyle();
|
1493
|
+
},
|
1494
|
+
|
1495
|
+
/**
|
1496
|
+
* Starts the plugin:
|
1497
|
+
* - activates the engine
|
1498
|
+
* - draws the marker (if coordinates available)
|
1499
|
+
*/
|
1500
|
+
start() {
|
1501
|
+
this._activate();
|
1502
|
+
|
1503
|
+
if (this._event) {
|
1504
|
+
this._drawMarker(this._map);
|
1505
|
+
|
1506
|
+
// if we already have a location but the user clicked on the control
|
1507
|
+
if (this.options.setView) {
|
1508
|
+
this.setView();
|
1509
|
+
}
|
1510
|
+
}
|
1511
|
+
this._updateContainerStyle();
|
1512
|
+
},
|
1513
|
+
|
1514
|
+
/**
|
1515
|
+
* Stops the plugin:
|
1516
|
+
* - deactivates the engine
|
1517
|
+
* - reinitializes the button
|
1518
|
+
* - removes the marker
|
1519
|
+
*/
|
1520
|
+
stop() {
|
1521
|
+
this._deactivate();
|
1522
|
+
|
1523
|
+
this._cleanClasses();
|
1524
|
+
this._resetVariables();
|
1525
|
+
|
1526
|
+
this._removeMarker();
|
1527
|
+
},
|
1528
|
+
|
1529
|
+
/**
|
1530
|
+
* Keep the control active but stop following the location
|
1531
|
+
*/
|
1532
|
+
stopFollowing() {
|
1533
|
+
this._userPanned = true;
|
1534
|
+
this._updateContainerStyle();
|
1535
|
+
this._drawMarker();
|
1536
|
+
},
|
1537
|
+
|
1538
|
+
/**
|
1539
|
+
* This method launches the location engine.
|
1540
|
+
* It is called before the marker is updated,
|
1541
|
+
* event if it does not mean that the event will be ready.
|
1542
|
+
*
|
1543
|
+
* Override it if you want to add more functionalities.
|
1544
|
+
* It should set the this._active to true and do nothing if
|
1545
|
+
* this._active is true.
|
1546
|
+
*/
|
1547
|
+
_activate() {
|
1548
|
+
if (this._active || !this._map) {
|
1549
|
+
return;
|
1550
|
+
}
|
1551
|
+
|
1552
|
+
this._map.locate(this.options.locateOptions);
|
1553
|
+
this._map.fire("locateactivate", this);
|
1554
|
+
this._active = true;
|
1555
|
+
|
1556
|
+
// bind event listeners
|
1557
|
+
this._map.on("locationfound", this._onLocationFound, this);
|
1558
|
+
this._map.on("locationerror", this._onLocationError, this);
|
1559
|
+
this._map.on("dragstart", this._onDrag, this);
|
1560
|
+
this._map.on("zoomstart", this._onZoom, this);
|
1561
|
+
this._map.on("zoomend", this._onZoomEnd, this);
|
1562
|
+
if (this.options.showCompass) {
|
1563
|
+
const oriAbs = "ondeviceorientationabsolute" in window;
|
1564
|
+
if (oriAbs || "ondeviceorientation" in window) {
|
1565
|
+
const _this = this;
|
1566
|
+
const deviceorientation = function () {
|
1567
|
+
L.DomEvent.on(window, oriAbs ? "deviceorientationabsolute" : "deviceorientation", _this._onDeviceOrientation, _this);
|
1568
|
+
};
|
1569
|
+
if (DeviceOrientationEvent && typeof DeviceOrientationEvent.requestPermission === "function") {
|
1570
|
+
DeviceOrientationEvent.requestPermission().then(function (permissionState) {
|
1571
|
+
if (permissionState === "granted") {
|
1572
|
+
deviceorientation();
|
1573
|
+
}
|
1574
|
+
});
|
1575
|
+
} else {
|
1576
|
+
deviceorientation();
|
1577
|
+
}
|
1578
|
+
}
|
1579
|
+
}
|
1580
|
+
},
|
1581
|
+
|
1582
|
+
/**
|
1583
|
+
* Called to stop the location engine.
|
1584
|
+
*
|
1585
|
+
* Override it to shutdown any functionalities you added on start.
|
1586
|
+
*/
|
1587
|
+
_deactivate() {
|
1588
|
+
if (!this._active || !this._map) {
|
1589
|
+
return;
|
1590
|
+
}
|
1591
|
+
|
1592
|
+
this._map.stopLocate();
|
1593
|
+
this._map.fire("locatedeactivate", this);
|
1594
|
+
this._active = false;
|
1595
|
+
|
1596
|
+
if (!this.options.cacheLocation) {
|
1597
|
+
this._event = undefined;
|
1598
|
+
}
|
1599
|
+
|
1600
|
+
// unbind event listeners
|
1601
|
+
this._map.off("locationfound", this._onLocationFound, this);
|
1602
|
+
this._map.off("locationerror", this._onLocationError, this);
|
1603
|
+
this._map.off("dragstart", this._onDrag, this);
|
1604
|
+
this._map.off("zoomstart", this._onZoom, this);
|
1605
|
+
this._map.off("zoomend", this._onZoomEnd, this);
|
1606
|
+
if (this.options.showCompass) {
|
1607
|
+
this._compassHeading = null;
|
1608
|
+
if ("ondeviceorientationabsolute" in window) {
|
1609
|
+
L.DomEvent.off(window, "deviceorientationabsolute", this._onDeviceOrientation, this);
|
1610
|
+
} else if ("ondeviceorientation" in window) {
|
1611
|
+
L.DomEvent.off(window, "deviceorientation", this._onDeviceOrientation, this);
|
1612
|
+
}
|
1613
|
+
}
|
1614
|
+
},
|
1615
|
+
|
1616
|
+
/**
|
1617
|
+
* Zoom (unless we should keep the zoom level) and an to the current view.
|
1618
|
+
*/
|
1619
|
+
setView() {
|
1620
|
+
this._drawMarker();
|
1621
|
+
if (this._isOutsideMapBounds()) {
|
1622
|
+
this._event = undefined; // clear the current location so we can get back into the bounds
|
1623
|
+
this.options.onLocationOutsideMapBounds(this);
|
1624
|
+
} else {
|
1625
|
+
if (this._justClicked && this.options.initialZoomLevel !== false) {
|
1626
|
+
var f = this.options.flyTo ? this._map.flyTo : this._map.setView;
|
1627
|
+
f.bind(this._map)([this._event.latitude, this._event.longitude], this.options.initialZoomLevel);
|
1628
|
+
} else if (this.options.keepCurrentZoomLevel) {
|
1629
|
+
var f = this.options.flyTo ? this._map.flyTo : this._map.panTo;
|
1630
|
+
f.bind(this._map)([this._event.latitude, this._event.longitude]);
|
1631
|
+
} else {
|
1632
|
+
var f = this.options.flyTo ? this._map.flyToBounds : this._map.fitBounds;
|
1633
|
+
// Ignore zoom events while setting the viewport as these would stop following
|
1634
|
+
this._ignoreEvent = true;
|
1635
|
+
f.bind(this._map)(this.options.getLocationBounds(this._event), {
|
1636
|
+
padding: this.options.circlePadding,
|
1637
|
+
maxZoom: this.options.initialZoomLevel || this.options.locateOptions.maxZoom
|
1638
|
+
});
|
1639
|
+
L.Util.requestAnimFrame(function () {
|
1640
|
+
// Wait until after the next animFrame because the flyTo can be async
|
1641
|
+
this._ignoreEvent = false;
|
1642
|
+
}, this);
|
1643
|
+
}
|
1644
|
+
}
|
1645
|
+
},
|
1646
|
+
|
1647
|
+
/**
|
1648
|
+
*
|
1649
|
+
*/
|
1650
|
+
_drawCompass() {
|
1651
|
+
if (!this._event) {
|
1652
|
+
return;
|
1653
|
+
}
|
1654
|
+
|
1655
|
+
const latlng = this._event.latlng;
|
1656
|
+
|
1657
|
+
if (this.options.showCompass && latlng && this._compassHeading !== null) {
|
1658
|
+
const cStyle = this._isFollowing() ? this.options.followCompassStyle : this.options.compassStyle;
|
1659
|
+
if (!this._compass) {
|
1660
|
+
this._compass = new this.options.compassClass(latlng, this._compassHeading, cStyle).addTo(this._layer);
|
1661
|
+
} else {
|
1662
|
+
this._compass.setLatLng(latlng);
|
1663
|
+
this._compass.setHeading(this._compassHeading);
|
1664
|
+
// If the compassClass can be updated with setStyle, update it.
|
1665
|
+
if (this._compass.setStyle) {
|
1666
|
+
this._compass.setStyle(cStyle);
|
1667
|
+
}
|
1668
|
+
}
|
1669
|
+
//
|
1670
|
+
}
|
1671
|
+
if (this._compass && (!this.options.showCompass || this._compassHeading === null)) {
|
1672
|
+
this._compass.removeFrom(this._layer);
|
1673
|
+
this._compass = null;
|
1674
|
+
}
|
1675
|
+
},
|
1676
|
+
|
1677
|
+
/**
|
1678
|
+
* Draw the marker and accuracy circle on the map.
|
1679
|
+
*
|
1680
|
+
* Uses the event retrieved from onLocationFound from the map.
|
1681
|
+
*/
|
1682
|
+
_drawMarker() {
|
1683
|
+
if (this._event.accuracy === undefined) {
|
1684
|
+
this._event.accuracy = 0;
|
1685
|
+
}
|
1686
|
+
|
1687
|
+
const radius = this._event.accuracy;
|
1688
|
+
const latlng = this._event.latlng;
|
1689
|
+
|
1690
|
+
// circle with the radius of the location's accuracy
|
1691
|
+
if (this.options.drawCircle) {
|
1692
|
+
const style = this._isFollowing() ? this.options.followCircleStyle : this.options.circleStyle;
|
1693
|
+
|
1694
|
+
if (!this._circle) {
|
1695
|
+
this._circle = L.circle(latlng, radius, style).addTo(this._layer);
|
1696
|
+
} else {
|
1697
|
+
this._circle.setLatLng(latlng).setRadius(radius).setStyle(style);
|
1698
|
+
}
|
1699
|
+
}
|
1700
|
+
|
1701
|
+
let distance;
|
1702
|
+
let unit;
|
1703
|
+
if (this.options.metric) {
|
1704
|
+
distance = radius.toFixed(0);
|
1705
|
+
unit = this.options.strings.metersUnit;
|
1706
|
+
} else {
|
1707
|
+
distance = (radius * 3.2808399).toFixed(0);
|
1708
|
+
unit = this.options.strings.feetUnit;
|
1709
|
+
}
|
1710
|
+
|
1711
|
+
// small inner marker
|
1712
|
+
if (this.options.drawMarker) {
|
1713
|
+
const mStyle = this._isFollowing() ? this.options.followMarkerStyle : this.options.markerStyle;
|
1714
|
+
if (!this._marker) {
|
1715
|
+
this._marker = new this.options.markerClass(latlng, mStyle).addTo(this._layer);
|
1716
|
+
} else {
|
1717
|
+
this._marker.setLatLng(latlng);
|
1718
|
+
// If the markerClass can be updated with setStyle, update it.
|
1719
|
+
if (this._marker.setStyle) {
|
1720
|
+
this._marker.setStyle(mStyle);
|
1721
|
+
}
|
1722
|
+
}
|
1723
|
+
}
|
1724
|
+
|
1725
|
+
this._drawCompass();
|
1726
|
+
|
1727
|
+
const t = this.options.strings.popup;
|
1728
|
+
function getPopupText() {
|
1729
|
+
if (typeof t === "string") {
|
1730
|
+
return L.Util.template(t, { distance, unit });
|
1731
|
+
} else if (typeof t === "function") {
|
1732
|
+
return t({ distance, unit });
|
1733
|
+
} else {
|
1734
|
+
return t;
|
1735
|
+
}
|
1736
|
+
}
|
1737
|
+
if (this.options.showPopup && t && this._marker) {
|
1738
|
+
this._marker.bindPopup(getPopupText())._popup.setLatLng(latlng);
|
1739
|
+
}
|
1740
|
+
if (this.options.showPopup && t && this._compass) {
|
1741
|
+
this._compass.bindPopup(getPopupText())._popup.setLatLng(latlng);
|
1742
|
+
}
|
1743
|
+
},
|
1744
|
+
|
1745
|
+
/**
|
1746
|
+
* Remove the marker from map.
|
1747
|
+
*/
|
1748
|
+
_removeMarker() {
|
1749
|
+
this._layer.clearLayers();
|
1750
|
+
this._marker = undefined;
|
1751
|
+
this._circle = undefined;
|
1752
|
+
},
|
1753
|
+
|
1754
|
+
/**
|
1755
|
+
* Unload the plugin and all event listeners.
|
1756
|
+
* Kind of the opposite of onAdd.
|
1757
|
+
*/
|
1758
|
+
_unload() {
|
1759
|
+
this.stop();
|
1760
|
+
this._map.off("unload", this._unload, this);
|
1761
|
+
},
|
1762
|
+
|
1763
|
+
/**
|
1764
|
+
* Sets the compass heading
|
1765
|
+
*/
|
1766
|
+
_setCompassHeading(angle) {
|
1767
|
+
if (!isNaN(parseFloat(angle)) && isFinite(angle)) {
|
1768
|
+
angle = Math.round(angle);
|
1769
|
+
|
1770
|
+
this._compassHeading = angle;
|
1771
|
+
L.Util.requestAnimFrame(this._drawCompass, this);
|
1772
|
+
} else {
|
1773
|
+
this._compassHeading = null;
|
1774
|
+
}
|
1775
|
+
},
|
1776
|
+
|
1777
|
+
/**
|
1778
|
+
* If the compass fails calibration just fail safely and remove the compass
|
1779
|
+
*/
|
1780
|
+
_onCompassNeedsCalibration() {
|
1781
|
+
this._setCompassHeading();
|
1782
|
+
},
|
1783
|
+
|
1784
|
+
/**
|
1785
|
+
* Process and normalise compass events
|
1786
|
+
*/
|
1787
|
+
_onDeviceOrientation(e) {
|
1788
|
+
if (!this._active) {
|
1789
|
+
return;
|
1790
|
+
}
|
1791
|
+
|
1792
|
+
if (e.webkitCompassHeading) {
|
1793
|
+
// iOS
|
1794
|
+
this._setCompassHeading(e.webkitCompassHeading);
|
1795
|
+
} else if (e.absolute && e.alpha) {
|
1796
|
+
// Android
|
1797
|
+
this._setCompassHeading(360 - e.alpha);
|
1798
|
+
}
|
1799
|
+
},
|
1800
|
+
|
1801
|
+
/**
|
1802
|
+
* Calls deactivate and dispatches an error.
|
1803
|
+
*/
|
1804
|
+
_onLocationError(err) {
|
1805
|
+
// ignore time out error if the location is watched
|
1806
|
+
if (err.code == 3 && this.options.locateOptions.watch) {
|
1807
|
+
return;
|
1808
|
+
}
|
1809
|
+
|
1810
|
+
this.stop();
|
1811
|
+
this.options.onLocationError(err, this);
|
1812
|
+
},
|
1813
|
+
|
1814
|
+
/**
|
1815
|
+
* Stores the received event and updates the marker.
|
1816
|
+
*/
|
1817
|
+
_onLocationFound(e) {
|
1818
|
+
// no need to do anything if the location has not changed
|
1819
|
+
if (this._event && this._event.latlng.lat === e.latlng.lat && this._event.latlng.lng === e.latlng.lng && this._event.accuracy === e.accuracy) {
|
1820
|
+
return;
|
1821
|
+
}
|
1822
|
+
|
1823
|
+
if (!this._active) {
|
1824
|
+
// we may have a stray event
|
1825
|
+
return;
|
1826
|
+
}
|
1827
|
+
|
1828
|
+
this._event = e;
|
1829
|
+
|
1830
|
+
this._drawMarker();
|
1831
|
+
this._updateContainerStyle();
|
1832
|
+
|
1833
|
+
switch (this.options.setView) {
|
1834
|
+
case "once":
|
1835
|
+
if (this._justClicked) {
|
1836
|
+
this.setView();
|
1837
|
+
}
|
1838
|
+
break;
|
1839
|
+
case "untilPan":
|
1840
|
+
if (!this._userPanned) {
|
1841
|
+
this.setView();
|
1842
|
+
}
|
1843
|
+
break;
|
1844
|
+
case "untilPanOrZoom":
|
1845
|
+
if (!this._userPanned && !this._userZoomed) {
|
1846
|
+
this.setView();
|
1847
|
+
}
|
1848
|
+
break;
|
1849
|
+
case "always":
|
1850
|
+
this.setView();
|
1851
|
+
break;
|
1852
|
+
}
|
1853
|
+
|
1854
|
+
this._justClicked = false;
|
1855
|
+
},
|
1856
|
+
|
1857
|
+
/**
|
1858
|
+
* When the user drags. Need a separate event so we can bind and unbind event listeners.
|
1859
|
+
*/
|
1860
|
+
_onDrag() {
|
1861
|
+
// only react to drags once we have a location
|
1862
|
+
if (this._event && !this._ignoreEvent) {
|
1863
|
+
this._userPanned = true;
|
1864
|
+
this._updateContainerStyle();
|
1865
|
+
this._drawMarker();
|
1866
|
+
}
|
1867
|
+
},
|
1868
|
+
|
1869
|
+
/**
|
1870
|
+
* When the user zooms. Need a separate event so we can bind and unbind event listeners.
|
1871
|
+
*/
|
1872
|
+
_onZoom() {
|
1873
|
+
// only react to drags once we have a location
|
1874
|
+
if (this._event && !this._ignoreEvent) {
|
1875
|
+
this._userZoomed = true;
|
1876
|
+
this._updateContainerStyle();
|
1877
|
+
this._drawMarker();
|
1878
|
+
}
|
1879
|
+
},
|
1880
|
+
|
1881
|
+
/**
|
1882
|
+
* After a zoom ends update the compass and handle sideways zooms
|
1883
|
+
*/
|
1884
|
+
_onZoomEnd() {
|
1885
|
+
if (this._event) {
|
1886
|
+
this._drawCompass();
|
1887
|
+
}
|
1888
|
+
|
1889
|
+
if (this._event && !this._ignoreEvent) {
|
1890
|
+
// If we have zoomed in and out and ended up sideways treat it as a pan
|
1891
|
+
if (this._marker && !this._map.getBounds().pad(-0.3).contains(this._marker.getLatLng())) {
|
1892
|
+
this._userPanned = true;
|
1893
|
+
this._updateContainerStyle();
|
1894
|
+
this._drawMarker();
|
1895
|
+
}
|
1896
|
+
}
|
1897
|
+
},
|
1898
|
+
|
1899
|
+
/**
|
1900
|
+
* Compute whether the map is following the user location with pan and zoom.
|
1901
|
+
*/
|
1902
|
+
_isFollowing() {
|
1903
|
+
if (!this._active) {
|
1904
|
+
return false;
|
1905
|
+
}
|
1906
|
+
|
1907
|
+
if (this.options.setView === "always") {
|
1908
|
+
return true;
|
1909
|
+
} else if (this.options.setView === "untilPan") {
|
1910
|
+
return !this._userPanned;
|
1911
|
+
} else if (this.options.setView === "untilPanOrZoom") {
|
1912
|
+
return !this._userPanned && !this._userZoomed;
|
1913
|
+
}
|
1914
|
+
},
|
1915
|
+
|
1916
|
+
/**
|
1917
|
+
* Check if location is in map bounds
|
1918
|
+
*/
|
1919
|
+
_isOutsideMapBounds() {
|
1920
|
+
if (this._event === undefined) {
|
1921
|
+
return false;
|
1922
|
+
}
|
1923
|
+
return this._map.options.maxBounds && !this._map.options.maxBounds.contains(this._event.latlng);
|
1924
|
+
},
|
1925
|
+
|
1926
|
+
/**
|
1927
|
+
* Toggles button class between following and active.
|
1928
|
+
*/
|
1929
|
+
_updateContainerStyle() {
|
1930
|
+
if (!this._container) {
|
1931
|
+
return;
|
1932
|
+
}
|
1933
|
+
|
1934
|
+
if (this._active && !this._event) {
|
1935
|
+
// active but don't have a location yet
|
1936
|
+
this._setClasses("requesting");
|
1937
|
+
} else if (this._isFollowing()) {
|
1938
|
+
this._setClasses("following");
|
1939
|
+
} else if (this._active) {
|
1940
|
+
this._setClasses("active");
|
1941
|
+
} else {
|
1942
|
+
this._cleanClasses();
|
1943
|
+
}
|
1944
|
+
},
|
1945
|
+
|
1946
|
+
/**
|
1947
|
+
* Sets the CSS classes for the state.
|
1948
|
+
*/
|
1949
|
+
_setClasses(state) {
|
1950
|
+
if (state == "requesting") {
|
1951
|
+
removeClasses(this._container, "active following");
|
1952
|
+
addClasses(this._container, "requesting");
|
1953
|
+
|
1954
|
+
removeClasses(this._icon, this.options.icon);
|
1955
|
+
addClasses(this._icon, this.options.iconLoading);
|
1956
|
+
} else if (state == "active") {
|
1957
|
+
removeClasses(this._container, "requesting following");
|
1958
|
+
addClasses(this._container, "active");
|
1959
|
+
|
1960
|
+
removeClasses(this._icon, this.options.iconLoading);
|
1961
|
+
addClasses(this._icon, this.options.icon);
|
1962
|
+
} else if (state == "following") {
|
1963
|
+
removeClasses(this._container, "requesting");
|
1964
|
+
addClasses(this._container, "active following");
|
1965
|
+
|
1966
|
+
removeClasses(this._icon, this.options.iconLoading);
|
1967
|
+
addClasses(this._icon, this.options.icon);
|
1968
|
+
}
|
1969
|
+
},
|
1970
|
+
|
1971
|
+
/**
|
1972
|
+
* Removes all classes from button.
|
1973
|
+
*/
|
1974
|
+
_cleanClasses() {
|
1975
|
+
L.DomUtil.removeClass(this._container, "requesting");
|
1976
|
+
L.DomUtil.removeClass(this._container, "active");
|
1977
|
+
L.DomUtil.removeClass(this._container, "following");
|
1978
|
+
|
1979
|
+
removeClasses(this._icon, this.options.iconLoading);
|
1980
|
+
addClasses(this._icon, this.options.icon);
|
1981
|
+
},
|
1982
|
+
|
1983
|
+
/**
|
1984
|
+
* Reinitializes state variables.
|
1985
|
+
*/
|
1986
|
+
_resetVariables() {
|
1987
|
+
// whether locate is active or not
|
1988
|
+
this._active = false;
|
1989
|
+
|
1990
|
+
// true if the control was clicked for the first time
|
1991
|
+
// we need this so we can pan and zoom once we have the location
|
1992
|
+
this._justClicked = false;
|
1993
|
+
|
1994
|
+
// true if the user has panned the map after clicking the control
|
1995
|
+
this._userPanned = false;
|
1996
|
+
|
1997
|
+
// true if the user has zoomed the map after clicking the control
|
1998
|
+
this._userZoomed = false;
|
1999
|
+
}
|
2000
|
+
});
|
2001
|
+
|
2002
|
+
L.control.locate = (options) => new L.Control.Locate(options);
|
2003
|
+
|
2004
|
+
return LocateControl;
|
2005
|
+
}, window);
|
2006
|
+
} (L_Control_Locate));
|
2007
|
+
return L_Control_Locate.exports;
|
2008
|
+
}
|
2009
|
+
|
2010
|
+
requireL_Control_Locate();
|
2011
|
+
|
2012
|
+
const urlRegex =
|
2013
|
+
// eslint-disable-next-line no-useless-escape, security/detect-unsafe-regex
|
2014
|
+
/(^| )(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,10}(:[0-9]{1,10})?(\/.*)?$/gm;
|
2015
|
+
const mailRegex = /(?<![[(])([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})(?![\])])/gi;
|
2016
|
+
function fixUrls(message) {
|
2017
|
+
message = message.replace(urlRegex, function (url) {
|
2018
|
+
let hyperlink = url.replace(' ', '');
|
2019
|
+
if (!hyperlink.match('^https?://')) {
|
2020
|
+
hyperlink = 'https://' + hyperlink;
|
2021
|
+
}
|
2022
|
+
return hyperlink;
|
2023
|
+
});
|
2024
|
+
return message;
|
2025
|
+
}
|
2026
|
+
|
2027
|
+
/**
|
2028
|
+
* @category Map
|
2029
|
+
*/
|
2030
|
+
const TextView = ({ item, itemId, text, truncate = false, rawText, itemTextField, }) => {
|
2031
|
+
if (item) {
|
2032
|
+
text = item.text;
|
2033
|
+
itemId = item.id;
|
2034
|
+
}
|
2035
|
+
const tags = useTags();
|
2036
|
+
const addFilterTag = useAddFilterTag();
|
2037
|
+
let innerText = '';
|
2038
|
+
let replacedText = '';
|
2039
|
+
if (rawText) {
|
2040
|
+
innerText = replacedText = rawText;
|
2041
|
+
}
|
2042
|
+
else if (text) {
|
2043
|
+
innerText = text;
|
2044
|
+
}
|
2045
|
+
if (innerText && truncate)
|
2046
|
+
innerText = truncateText(removeMarkdownKeepLinksAndParagraphs(innerText), 100);
|
2047
|
+
if (innerText)
|
2048
|
+
replacedText = fixUrls(innerText);
|
2049
|
+
if (replacedText) {
|
2050
|
+
replacedText = replacedText.replace(/(?<!\]?\()https?:\/\/[^\s)]+(?!\))/g, (url) => {
|
2051
|
+
let shortUrl = url;
|
2052
|
+
if (url.match('^https://')) {
|
2053
|
+
shortUrl = url.split('https://')[1];
|
2054
|
+
}
|
2055
|
+
if (url.match('^http://')) {
|
2056
|
+
shortUrl = url.split('http://')[1];
|
2057
|
+
}
|
2058
|
+
return `[${shortUrl}](${url})`;
|
2059
|
+
});
|
2060
|
+
}
|
2061
|
+
if (replacedText) {
|
2062
|
+
replacedText = replacedText.replace(mailRegex, (url) => {
|
2063
|
+
return `[${url}](mailto:${url})`;
|
2064
|
+
});
|
2065
|
+
}
|
2066
|
+
if (replacedText) {
|
2067
|
+
replacedText = replacedText.replace(hashTagRegex, (match) => {
|
2068
|
+
return `[${match}](${match})`;
|
2069
|
+
});
|
2070
|
+
}
|
2071
|
+
const CustomH1 = ({ children }) => jsxRuntime.jsx("h1", { className: 'tw:text-xl tw:font-bold', children: children });
|
2072
|
+
const CustomH2 = ({ children }) => jsxRuntime.jsx("h2", { className: 'tw:text-lg tw:font-bold', children: children });
|
2073
|
+
const CustomH3 = ({ children }) => jsxRuntime.jsx("h3", { className: 'tw:text-base tw:font-bold', children: children });
|
2074
|
+
const CustomH4 = ({ children }) => jsxRuntime.jsx("h4", { className: 'tw:text-base tw:font-bold', children: children });
|
2075
|
+
const CustomH5 = ({ children }) => jsxRuntime.jsx("h5", { className: 'tw:text-sm tw:font-bold', children: children });
|
2076
|
+
const CustomH6 = ({ children }) => jsxRuntime.jsx("h6", { className: 'tw:text-sm tw:font-bold', children: children });
|
2077
|
+
const CustomParagraph = ({ children }) => jsxRuntime.jsx("p", { className: 'tw:my-2!', children: children });
|
2078
|
+
const CustomUnorderdList = ({ children }) => (jsxRuntime.jsx("ul", { className: 'tw:list-disc tw:list-inside', children: children }));
|
2079
|
+
const CustomOrderdList = ({ children }) => (jsxRuntime.jsx("ol", { className: 'tw:list-decimal tw:list-inside', children: children }));
|
2080
|
+
const CustomHorizontalRow = ({ children }) => jsxRuntime.jsx("hr", { className: 'tw:border-current', children: children });
|
2081
|
+
// eslint-disable-next-line react/prop-types
|
2082
|
+
const CustomImage = ({ alt, src, title }) => (jsxRuntime.jsx("img", { className: 'tw:max-w-full tw:rounded tw:shadow', src: src, alt: alt, title: title }));
|
2083
|
+
const CustomExternalLink = ({ href, children }) => (jsxRuntime.jsxs("a", { className: 'tw:font-bold tw:underline', href: href, target: '_blank', rel: 'noreferrer', children: [' ', children] }));
|
2084
|
+
const CustomHashTagLink = ({ children, tag, itemId, }) => {
|
2085
|
+
return (jsxRuntime.jsx("a", { style: { color: tag ? tag.color : '#faa', fontWeight: 'bold', cursor: 'pointer' }, onClick: (e) => {
|
2086
|
+
e.stopPropagation();
|
2087
|
+
addFilterTag(tag);
|
2088
|
+
}, children: decodeTag(children) }, tag ? tag.name + itemId : itemId));
|
2089
|
+
};
|
2090
|
+
// eslint-disable-next-line react/display-name
|
2091
|
+
const MemoizedVideoEmbed = React.memo(({ url }) => (jsxRuntime.jsx("iframe", { className: 'tw:w-full', src: url, allow: 'fullscreen; picture-in-picture', allowFullScreen: true })));
|
2092
|
+
return (jsxRuntime.jsx(Markdown, { className: 'tw:text-map tw:leading-map tw:text-sm', remarkPlugins: [remarkBreaks], components: {
|
2093
|
+
p: CustomParagraph,
|
2094
|
+
a: ({ href, children }) => {
|
2095
|
+
const isYouTubeVideo = href?.startsWith('https://www.youtube.com/watch?v=');
|
2096
|
+
const isRumbleVideo = href?.startsWith('https://rumble.com/embed/');
|
2097
|
+
if (isYouTubeVideo) {
|
2098
|
+
const videoId = href?.split('v=')[1].split('&')[0];
|
2099
|
+
const youtubeEmbedUrl = `https://www.youtube-nocookie.com/embed/${videoId}`;
|
2100
|
+
return jsxRuntime.jsx(MemoizedVideoEmbed, { url: youtubeEmbedUrl });
|
2101
|
+
}
|
2102
|
+
if (isRumbleVideo) {
|
2103
|
+
return jsxRuntime.jsx(MemoizedVideoEmbed, { url: href });
|
2104
|
+
}
|
2105
|
+
if (href?.startsWith('#')) {
|
2106
|
+
const tag = tags.find((t) => t.name.toLowerCase() === decodeURI(href).slice(1).toLowerCase());
|
2107
|
+
if (tag)
|
2108
|
+
return (jsxRuntime.jsx(CustomHashTagLink, { tag: tag, itemId: itemId, children: children }));
|
2109
|
+
else
|
2110
|
+
return children;
|
2111
|
+
}
|
2112
|
+
else {
|
2113
|
+
return jsxRuntime.jsx(CustomExternalLink, { href: href, children: children });
|
2114
|
+
}
|
2115
|
+
},
|
2116
|
+
ul: CustomUnorderdList,
|
2117
|
+
ol: CustomOrderdList,
|
2118
|
+
img: CustomImage,
|
2119
|
+
hr: CustomHorizontalRow,
|
2120
|
+
h1: CustomH1,
|
2121
|
+
h2: CustomH2,
|
2122
|
+
h3: CustomH3,
|
2123
|
+
h4: CustomH4,
|
2124
|
+
h5: CustomH5,
|
2125
|
+
h6: CustomH6,
|
2126
|
+
}, children: replacedText }));
|
2127
|
+
};
|
2128
|
+
function removeMarkdownKeepLinksAndParagraphs(text) {
|
2129
|
+
// Remove Markdown syntax using regular expressions but keep links and paragraphs
|
2130
|
+
return text
|
2131
|
+
.replace(/!\[.*?\]\(.*?\)/g, '') // Remove images
|
2132
|
+
.replace(/(`{1,3})(.*?)\1/g, '$2') // Remove inline code
|
2133
|
+
.replace(/(\*{1,2}|_{1,2})(.*?)\1/g, '$2') // Remove bold and italic
|
2134
|
+
.replace(/(#+)\s+(.*)/g, '$2') // Remove headers
|
2135
|
+
.replace(/>\s+(.*)/g, '$1') // Remove blockquotes
|
2136
|
+
.replace(/^\s*\n/gm, '\n') // Preserve empty lines
|
2137
|
+
.replace(/(\r\n|\n|\r)/gm, '\n'); // Preserve line breaks
|
2138
|
+
}
|
2139
|
+
function truncateText(text, limit) {
|
2140
|
+
if (text.length <= limit) {
|
2141
|
+
return text;
|
2142
|
+
}
|
2143
|
+
let truncated = '';
|
2144
|
+
let length = 0;
|
2145
|
+
// Split the text by paragraphs
|
2146
|
+
const paragraphs = text.split('\n');
|
2147
|
+
for (const paragraph of paragraphs) {
|
2148
|
+
if (length + paragraph.length > limit) {
|
2149
|
+
truncated += paragraph.slice(0, limit - length) + '...';
|
2150
|
+
break;
|
2151
|
+
}
|
2152
|
+
else {
|
2153
|
+
truncated += paragraph + '\n';
|
2154
|
+
length += paragraph.length;
|
2155
|
+
}
|
2156
|
+
}
|
2157
|
+
return truncated.trim();
|
2158
|
+
}
|
2159
|
+
|
2160
|
+
function EllipsisVerticalIcon({
|
2161
|
+
title,
|
2162
|
+
titleId,
|
2163
|
+
...props
|
2164
|
+
}, svgRef) {
|
2165
|
+
return /*#__PURE__*/React__namespace.createElement("svg", Object.assign({
|
2166
|
+
xmlns: "http://www.w3.org/2000/svg",
|
2167
|
+
viewBox: "0 0 16 16",
|
2168
|
+
fill: "currentColor",
|
2169
|
+
"aria-hidden": "true",
|
2170
|
+
"data-slot": "icon",
|
2171
|
+
ref: svgRef,
|
2172
|
+
"aria-labelledby": titleId
|
2173
|
+
}, props), title ? /*#__PURE__*/React__namespace.createElement("title", {
|
2174
|
+
id: titleId
|
2175
|
+
}, title) : null, /*#__PURE__*/React__namespace.createElement("path", {
|
2176
|
+
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"
|
2177
|
+
}));
|
2178
|
+
}
|
2179
|
+
const ForwardRef$4 = /*#__PURE__*/ React__namespace.forwardRef(EllipsisVerticalIcon);
|
2180
|
+
|
2181
|
+
/**
|
2182
|
+
* @category Templates
|
2183
|
+
*/
|
2184
|
+
function MapOverlayPage({ children, className, backdrop, card = true, }) {
|
2185
|
+
const closeScreen = () => {
|
2186
|
+
navigate(`/${window.location.search ? window.location.search : ''}`);
|
2187
|
+
};
|
2188
|
+
const navigate = reactRouterDom.useNavigate();
|
2189
|
+
const overlayRef = React.createRef();
|
2190
|
+
const backdropRef = React.createRef();
|
2191
|
+
React.useEffect(() => {
|
2192
|
+
if (overlayRef.current !== null) {
|
2193
|
+
require$$0.DomEvent.disableClickPropagation(overlayRef.current);
|
2194
|
+
require$$0.DomEvent.disableScrollPropagation(overlayRef.current);
|
2195
|
+
}
|
2196
|
+
if (backdropRef.current !== null && backdrop) {
|
2197
|
+
require$$0.DomEvent.disableClickPropagation(backdropRef.current);
|
2198
|
+
require$$0.DomEvent.disableScrollPropagation(backdropRef.current);
|
2199
|
+
}
|
2200
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2201
|
+
}, [overlayRef, backdropRef]);
|
2202
|
+
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" })] }) }) }));
|
2203
|
+
}
|
2204
|
+
|
2205
|
+
/**
|
2206
|
+
* @category Input
|
2207
|
+
*/
|
2208
|
+
function TextAreaInput({ labelTitle, dataField, labelStyle, containerStyle, inputStyle, defaultValue, placeholder, required = true, updateFormValue, }) {
|
2209
|
+
const ref = React.useRef(null);
|
2210
|
+
const [inputValue, setInputValue] = React.useState(defaultValue);
|
2211
|
+
React.useEffect(() => {
|
2212
|
+
setInputValue(defaultValue);
|
2213
|
+
}, [defaultValue]);
|
2214
|
+
const handleChange = (e) => {
|
2215
|
+
const newValue = e.target.value;
|
2216
|
+
setInputValue(newValue);
|
2217
|
+
if (updateFormValue) {
|
2218
|
+
updateFormValue(newValue);
|
2219
|
+
}
|
2220
|
+
};
|
2221
|
+
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 })] }));
|
2222
|
+
}
|
2223
|
+
|
2224
|
+
/**
|
2225
|
+
* @category Input
|
2226
|
+
*/
|
2227
|
+
function TextInput({ labelTitle, labelStyle, type, dataField, containerStyle, inputStyle, defaultValue, placeholder, autocomplete, pattern, required = true, updateFormValue, }) {
|
2228
|
+
const [inputValue, setInputValue] = React.useState(defaultValue ?? '');
|
2229
|
+
React.useEffect(() => {
|
2230
|
+
setInputValue(defaultValue ?? '');
|
2231
|
+
}, [defaultValue]);
|
2232
|
+
const handleChange = (e) => {
|
2233
|
+
const newValue = e.target.value;
|
2234
|
+
setInputValue(newValue);
|
2235
|
+
if (updateFormValue) {
|
2236
|
+
updateFormValue(newValue);
|
2237
|
+
}
|
2238
|
+
};
|
2239
|
+
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 ?? ''}` })] }));
|
2240
|
+
}
|
2241
|
+
|
2242
|
+
/**
|
2243
|
+
* @category Map
|
2244
|
+
*/
|
2245
|
+
const PopupStartEndInput = ({ item, showLabels = true, updateStartValue, updateEndValue, }) => {
|
2246
|
+
return (jsxRuntime.jsxs("div", { className: 'tw:grid tw:grid-cols-2 tw:gap-2', children: [jsxRuntime.jsx(TextInput, { type: 'date', placeholder: 'start', dataField: 'start', inputStyle: 'tw:text-sm tw:px-2', labelTitle: showLabels ? 'start' : '', 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' : '', defaultValue: item && item.end ? item.end.substring(0, 10) : '', autocomplete: 'one-time-code', updateFormValue: updateEndValue })] }));
|
2247
|
+
};
|
2248
|
+
|
2249
|
+
function CalendarDaysIcon({
|
2250
|
+
title,
|
2251
|
+
titleId,
|
2252
|
+
...props
|
2253
|
+
}, svgRef) {
|
2254
|
+
return /*#__PURE__*/React__namespace.createElement("svg", Object.assign({
|
2255
|
+
xmlns: "http://www.w3.org/2000/svg",
|
2256
|
+
viewBox: "0 0 24 24",
|
2257
|
+
fill: "currentColor",
|
2258
|
+
"aria-hidden": "true",
|
2259
|
+
"data-slot": "icon",
|
2260
|
+
ref: svgRef,
|
2261
|
+
"aria-labelledby": titleId
|
2262
|
+
}, props), title ? /*#__PURE__*/React__namespace.createElement("title", {
|
2263
|
+
id: titleId
|
2264
|
+
}, title) : null, /*#__PURE__*/React__namespace.createElement("path", {
|
2265
|
+
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"
|
2266
|
+
}), /*#__PURE__*/React__namespace.createElement("path", {
|
2267
|
+
fillRule: "evenodd",
|
2268
|
+
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",
|
2269
|
+
clipRule: "evenodd"
|
2270
|
+
}));
|
2271
|
+
}
|
2272
|
+
const ForwardRef$3 = /*#__PURE__*/ React__namespace.forwardRef(CalendarDaysIcon);
|
2273
|
+
|
2274
|
+
/**
|
2275
|
+
* @category Map
|
2276
|
+
*/
|
2277
|
+
const StartEndView = ({ item }) => {
|
2278
|
+
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() : '' })] })] }));
|
2279
|
+
};
|
2280
|
+
|
2281
|
+
function PlusIcon({
|
2282
|
+
title,
|
2283
|
+
titleId,
|
2284
|
+
...props
|
2285
|
+
}, svgRef) {
|
2286
|
+
return /*#__PURE__*/React__namespace.createElement("svg", Object.assign({
|
2287
|
+
xmlns: "http://www.w3.org/2000/svg",
|
2288
|
+
fill: "none",
|
2289
|
+
viewBox: "0 0 24 24",
|
2290
|
+
strokeWidth: 1.5,
|
2291
|
+
stroke: "currentColor",
|
2292
|
+
"aria-hidden": "true",
|
2293
|
+
"data-slot": "icon",
|
2294
|
+
ref: svgRef,
|
2295
|
+
"aria-labelledby": titleId
|
2296
|
+
}, props), title ? /*#__PURE__*/React__namespace.createElement("title", {
|
2297
|
+
id: titleId
|
2298
|
+
}, title) : null, /*#__PURE__*/React__namespace.createElement("path", {
|
2299
|
+
strokeLinecap: "round",
|
2300
|
+
strokeLinejoin: "round",
|
2301
|
+
d: "M12 4.5v15m7.5-7.5h-15"
|
2302
|
+
}));
|
2303
|
+
}
|
2304
|
+
const ForwardRef$2 = /*#__PURE__*/ React__namespace.forwardRef(PlusIcon);
|
2305
|
+
|
2306
|
+
const goldenRatioConjugate = 0.618033988749895;
|
2307
|
+
const randomColor = () => {
|
2308
|
+
return hsvToHex((Math.random() + goldenRatioConjugate) % 1, 0.8, 0.7);
|
2309
|
+
};
|
2310
|
+
function hsvToHex(h, s, v) {
|
2311
|
+
let r, g, b;
|
2312
|
+
const i = Math.floor(h * 6);
|
2313
|
+
const f = h * 6 - i;
|
2314
|
+
const p = v * (1 - s);
|
2315
|
+
const q = v * (1 - f * s);
|
2316
|
+
const t = v * (1 - (1 - f) * s);
|
2317
|
+
switch (i % 6) {
|
2318
|
+
case 0:
|
2319
|
+
r = v;
|
2320
|
+
g = t;
|
2321
|
+
b = p;
|
2322
|
+
break;
|
2323
|
+
case 1:
|
2324
|
+
r = q;
|
2325
|
+
g = v;
|
2326
|
+
b = p;
|
2327
|
+
break;
|
2328
|
+
case 2:
|
2329
|
+
r = p;
|
2330
|
+
g = v;
|
2331
|
+
b = t;
|
2332
|
+
break;
|
2333
|
+
case 3:
|
2334
|
+
r = p;
|
2335
|
+
g = q;
|
2336
|
+
b = v;
|
2337
|
+
break;
|
2338
|
+
case 4:
|
2339
|
+
r = t;
|
2340
|
+
g = p;
|
2341
|
+
b = v;
|
2342
|
+
break;
|
2343
|
+
case 5:
|
2344
|
+
r = v;
|
2345
|
+
g = p;
|
2346
|
+
b = q;
|
2347
|
+
break;
|
2348
|
+
}
|
2349
|
+
return rgbToHex(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255));
|
2350
|
+
}
|
2351
|
+
const rgbToHex = (r, g, b) => '#' +
|
2352
|
+
[r, g, b]
|
2353
|
+
.map((x) => {
|
2354
|
+
const hex = x.toString(16);
|
2355
|
+
return hex.length === 1 ? `0${hex}` : hex;
|
2356
|
+
})
|
2357
|
+
.join('');
|
2358
|
+
|
2359
|
+
function PencilIcon({
|
2360
|
+
title,
|
2361
|
+
titleId,
|
2362
|
+
...props
|
2363
|
+
}, svgRef) {
|
2364
|
+
return /*#__PURE__*/React__namespace.createElement("svg", Object.assign({
|
2365
|
+
xmlns: "http://www.w3.org/2000/svg",
|
2366
|
+
viewBox: "0 0 24 24",
|
2367
|
+
fill: "currentColor",
|
2368
|
+
"aria-hidden": "true",
|
2369
|
+
"data-slot": "icon",
|
2370
|
+
ref: svgRef,
|
2371
|
+
"aria-labelledby": titleId
|
2372
|
+
}, props), title ? /*#__PURE__*/React__namespace.createElement("title", {
|
2373
|
+
id: titleId
|
2374
|
+
}, title) : null, /*#__PURE__*/React__namespace.createElement("path", {
|
2375
|
+
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"
|
2376
|
+
}));
|
2377
|
+
}
|
2378
|
+
const ForwardRef$1 = /*#__PURE__*/ React__namespace.forwardRef(PencilIcon);
|
2379
|
+
|
2380
|
+
function TrashIcon({
|
2381
|
+
title,
|
2382
|
+
titleId,
|
2383
|
+
...props
|
2384
|
+
}, svgRef) {
|
2385
|
+
return /*#__PURE__*/React__namespace.createElement("svg", Object.assign({
|
2386
|
+
xmlns: "http://www.w3.org/2000/svg",
|
2387
|
+
viewBox: "0 0 24 24",
|
2388
|
+
fill: "currentColor",
|
2389
|
+
"aria-hidden": "true",
|
2390
|
+
"data-slot": "icon",
|
2391
|
+
ref: svgRef,
|
2392
|
+
"aria-labelledby": titleId
|
2393
|
+
}, props), title ? /*#__PURE__*/React__namespace.createElement("title", {
|
2394
|
+
id: titleId
|
2395
|
+
}, title) : null, /*#__PURE__*/React__namespace.createElement("path", {
|
2396
|
+
fillRule: "evenodd",
|
2397
|
+
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",
|
2398
|
+
clipRule: "evenodd"
|
2399
|
+
}));
|
2400
|
+
}
|
2401
|
+
const ForwardRef = /*#__PURE__*/ React__namespace.forwardRef(TrashIcon);
|
2402
|
+
|
2403
|
+
var TargetDotSVG = 'data:image/svg+xml;base64,PHN2ZwogICAgICAgICAgICAgICAgICAgICAgICAgICAgc3Ryb2tlPSdjdXJyZW50Q29sb3InCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmaWxsPSdjdXJyZW50Q29sb3InCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJva2VXaWR0aD0nMCcKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHZpZXdCb3g9JzAgMCA1MTIgNTEyJwogICAgICAgICAgICAgICAgICAgICAgICAgICAgY2xhc3NOYW1lPSd3LTUgaC01JwogICAgICAgICAgICAgICAgICAgICAgICAgICAgeG1sbnM9J2h0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnJwogICAgICAgICAgICAgICAgICAgICAgICAgID4KICAgICAgICAgICAgICAgICAgICAgICAgICAgIDxwYXRoIGQ9J00yNTYgMGMxNy43IDAgMzIgMTQuMyAzMiAzMlY0Mi40YzkzLjcgMTMuOSAxNjcuNyA4OCAxODEuNiAxODEuNkg0ODBjMTcuNyAwIDMyIDE0LjMgMzIgMzJzLTE0LjMgMzItMzIgMzJINDY5LjZjLTEzLjkgOTMuNy04OCAxNjcuNy0xODEuNiAxODEuNlY0ODBjMCAxNy43LTE0LjMgMzItMzIgMzJzLTMyLTE0LjMtMzItMzJWNDY5LjZDMTMwLjMgNDU1LjcgNTYuMyAzODEuNyA0Mi40IDI4OEgzMmMtMTcuNyAwLTMyLTE0LjMtMzItMzJzMTQuMy0zMiAzMi0zMkg0Mi40QzU2LjMgMTMwLjMgMTMwLjMgNTYuMyAyMjQgNDIuNFYzMmMwLTE3LjcgMTQuMy0zMiAzMi0zMnpNMTA3LjQgMjg4YzEyLjUgNTguMyA1OC40IDEwNC4xIDExNi42IDExNi42VjM4NGMwLTE3LjcgMTQuMy0zMiAzMi0zMnMzMiAxNC4zIDMyIDMydjIwLjZjNTguMy0xMi41IDEwNC4xLTU4LjQgMTE2LjYtMTE2LjZIMzg0Yy0xNy43IDAtMzItMTQuMy0zMi0zMnMxNC4zLTMyIDMyLTMyaDIwLjZDMzkyLjEgMTY1LjcgMzQ2LjMgMTE5LjkgMjg4IDEwNy40VjEyOGMwIDE3LjctMTQuMyAzMi0zMiAzMnMtMzItMTQuMy0zMi0zMlYxMDcuNEMxNjUuNyAxMTkuOSAxMTkuOSAxNjUuNyAxMDcuNCAyMjRIMTI4YzE3LjcgMCAzMiAxNC4zIDMyIDMycy0xNC4zIDMyLTMyIDMySDEwNy40ek0yNTYgMjI0YTMyIDMyIDAgMSAxIDAgNjQgMzIgMzIgMCAxIDEgMC02NHonPjwvcGF0aD4KICAgICAgICAgICAgICAgICAgICAgICAgICA8L3N2Zz4=';
|
2404
|
+
|
2405
|
+
const isClickInsideRectangle = (e, element) => {
|
2406
|
+
const r = element.getBoundingClientRect();
|
2407
|
+
return e.clientX > r.left && e.clientX < r.right && e.clientY > r.top && e.clientY < r.bottom;
|
2408
|
+
};
|
2409
|
+
const DialogModal = ({ title, isOpened, onClose, children, showCloseButton = true, closeOnClickOutside = true, className, }) => {
|
2410
|
+
const ref = React.useRef(null);
|
2411
|
+
React.useEffect(() => {
|
2412
|
+
if (isOpened) {
|
2413
|
+
ref.current?.showModal();
|
2414
|
+
ref.current?.classList.remove('tw:hidden');
|
2415
|
+
document.body.classList.add('modal-open'); // prevent bg scroll
|
2416
|
+
}
|
2417
|
+
else {
|
2418
|
+
ref.current?.close();
|
2419
|
+
ref.current?.classList.add('tw:hidden');
|
2420
|
+
document.body.classList.remove('modal-open');
|
2421
|
+
}
|
2422
|
+
}, [isOpened]);
|
2423
|
+
if (isOpened) {
|
2424
|
+
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" }))] }) }));
|
2425
|
+
}
|
2426
|
+
else
|
2427
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
2428
|
+
};
|
2429
|
+
|
2430
|
+
function HeaderView({ item, api, editCallback, deleteCallback, setPositionCallback, loading, hideMenu = false, big = false, truncateSubname = true, hideSubname = false, showAddress = false, }) {
|
2431
|
+
const [modalOpen, setModalOpen] = React.useState(false);
|
2432
|
+
const hasUserPermission = useHasUserPermission();
|
2433
|
+
const navigate = reactRouterDom.useNavigate();
|
2434
|
+
const appState = useAppState();
|
2435
|
+
const [imageLoaded, setImageLoaded] = React.useState(false);
|
2436
|
+
const avatar = item.image && appState.assetsApi.url + item.image + '?width=160&heigth=160';
|
2437
|
+
const title = item.name;
|
2438
|
+
const subtitle = item.subname;
|
2439
|
+
const [address] = React.useState('');
|
2440
|
+
const params = new URLSearchParams(window.location.search);
|
2441
|
+
const openDeleteModal = async (event) => {
|
2442
|
+
setModalOpen(true);
|
2443
|
+
event.stopPropagation();
|
2444
|
+
};
|
2445
|
+
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) &&
|
2446
|
+
(hasUserPermission(api?.collectionName, 'delete', item) ||
|
2447
|
+
hasUserPermission(api?.collectionName, 'update', item)) &&
|
2448
|
+
!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 &&
|
2449
|
+
hasUserPermission(api.collectionName, 'update', item) &&
|
2450
|
+
editCallback && (jsxRuntime.jsx("li", { children: jsxRuntime.jsx("a", { className: 'tw:text-base-content! tw:cursor-pointer', onClick: (e) => item.layer?.customEditLink
|
2451
|
+
? navigate(`${item.layer.customEditLink}${item.layer.customEditParameter ? `/${item.id}${params && '?' + params}` : ''} `)
|
2452
|
+
: editCallback(e), children: jsxRuntime.jsx(ForwardRef$1, { className: 'tw:h-5 tw:w-5' }) }) })), api?.updateItem &&
|
2453
|
+
hasUserPermission(api.collectionName, 'update', item) &&
|
2454
|
+
setPositionCallback && (jsxRuntime.jsx("li", { children: jsxRuntime.jsx("a", { className: 'tw:text-base-content! tw:cursor-pointer', onClick: setPositionCallback, children: jsxRuntime.jsx(SVG, { src: TargetDotSVG, className: 'tw:w-5 tw:h-5' }) }) })), api?.deleteItem &&
|
2455
|
+
hasUserPermission(api.collectionName, 'delete', item) &&
|
2456
|
+
deleteCallback && (jsxRuntime.jsx("li", { children: jsxRuntime.jsx("a", { className: 'tw:cursor-pointer tw:text-error!', 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) => {
|
2457
|
+
deleteCallback(e);
|
2458
|
+
setModalOpen(false);
|
2459
|
+
}, children: "Yes" }), jsxRuntime.jsx("label", { className: 'tw:btn tw:mt-4', onClick: () => setModalOpen(false), children: "No" })] }) })] }) })] }));
|
2460
|
+
}
|
2461
|
+
|
2462
|
+
// in miliseconds
|
2463
|
+
const units = [
|
2464
|
+
{ label: 'year', seconds: 31536000 },
|
2465
|
+
{ label: 'month', seconds: 2592000 },
|
2466
|
+
{ label: 'week', seconds: 604800 },
|
2467
|
+
{ label: 'day', seconds: 86400 },
|
2468
|
+
{ label: 'hour', seconds: 3600 },
|
2469
|
+
{ label: 'minute', seconds: 60 },
|
2470
|
+
{ label: 'second', seconds: 1 },
|
2471
|
+
];
|
2472
|
+
const timeAgo = (date) => {
|
2473
|
+
const time = Math.floor((new Date().valueOf() - new Date(date).valueOf()) / 1000);
|
2474
|
+
const { interval, unit } = calculateTimeDifference(time);
|
2475
|
+
const suffix = interval === 1 ? '' : 's';
|
2476
|
+
return `${interval} ${unit}${suffix} ago`;
|
2477
|
+
};
|
2478
|
+
const calculateTimeDifference = (time) => {
|
2479
|
+
for (const { label, seconds } of units) {
|
2480
|
+
const interval = Math.floor(time / seconds);
|
2481
|
+
if (interval >= 1) {
|
2482
|
+
return {
|
2483
|
+
interval,
|
2484
|
+
unit: label,
|
2485
|
+
};
|
2486
|
+
}
|
2487
|
+
}
|
2488
|
+
return {
|
2489
|
+
interval: 0,
|
2490
|
+
unit: '',
|
2491
|
+
};
|
2492
|
+
};
|
2493
|
+
|
2494
|
+
const TagView = ({ tag, heighlight, onClick, count, }) => {
|
2495
|
+
return (
|
2496
|
+
// Use your imagination to render suggestions.
|
2497
|
+
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));
|
2498
|
+
};
|
2499
|
+
|
2500
|
+
exports.AppStateProvider = AppStateProvider;
|
2501
|
+
exports.AuthProvider = AuthProvider;
|
2502
|
+
exports.ClusterRefProvider = ClusterRefProvider;
|
2503
|
+
exports.DialogModal = DialogModal;
|
2504
|
+
exports.FilterProvider = FilterProvider;
|
2505
|
+
exports.ForwardRef = ForwardRef$4;
|
2506
|
+
exports.ForwardRef$1 = ForwardRef$2;
|
2507
|
+
exports.HeaderView = HeaderView;
|
2508
|
+
exports.ItemsProvider = ItemsProvider;
|
2509
|
+
exports.LayersProvider = LayersProvider;
|
2510
|
+
exports.LeafletRefsProvider = LeafletRefsProvider;
|
2511
|
+
exports.MapOverlayPage = MapOverlayPage;
|
2512
|
+
exports.PermissionsProvider = PermissionsProvider;
|
2513
|
+
exports.PopupStartEndInput = PopupStartEndInput;
|
2514
|
+
exports.SelectPositionProvider = SelectPositionProvider;
|
2515
|
+
exports.StartEndView = StartEndView;
|
2516
|
+
exports.TagView = TagView;
|
2517
|
+
exports.TagsProvider = TagsProvider;
|
2518
|
+
exports.TextAreaInput = TextAreaInput;
|
2519
|
+
exports.TextInput = TextInput;
|
2520
|
+
exports.TextView = TextView;
|
2521
|
+
exports.decodeTag = decodeTag;
|
2522
|
+
exports.encodeTag = encodeTag;
|
2523
|
+
exports.hashTagRegex = hashTagRegex;
|
2524
|
+
exports.randomColor = randomColor;
|
2525
|
+
exports.timeAgo = timeAgo;
|
2526
|
+
exports.useAddFilterTag = useAddFilterTag;
|
2527
|
+
exports.useAddItem = useAddItem;
|
2528
|
+
exports.useAddMarker = useAddMarker;
|
2529
|
+
exports.useAddPopup = useAddPopup;
|
2530
|
+
exports.useAddTag = useAddTag;
|
2531
|
+
exports.useAddVisibleGroupType = useAddVisibleGroupType;
|
2532
|
+
exports.useAddVisibleLayer = useAddVisibleLayer;
|
2533
|
+
exports.useAllItemsLoaded = useAllItemsLoaded;
|
2534
|
+
exports.useAllTagsLoaded = useAllTagsLoaded;
|
2535
|
+
exports.useAppState = useAppState;
|
2536
|
+
exports.useAuth = useAuth;
|
2537
|
+
exports.useClusterRef = useClusterRef;
|
2538
|
+
exports.useFilterTags = useFilterTags;
|
2539
|
+
exports.useGetItemTags = useGetItemTags;
|
2540
|
+
exports.useHasUserPermission = useHasUserPermission;
|
2541
|
+
exports.useIsGroupTypeVisible = useIsGroupTypeVisible;
|
2542
|
+
exports.useIsLayerVisible = useIsLayerVisible;
|
2543
|
+
exports.useItems = useItems;
|
2544
|
+
exports.useLayers = useLayers;
|
2545
|
+
exports.useLeafletRefs = useLeafletRefs;
|
2546
|
+
exports.useRemoveFilterTag = useRemoveFilterTag;
|
2547
|
+
exports.useRemoveItem = useRemoveItem;
|
2548
|
+
exports.useResetFilterTags = useResetFilterTags;
|
2549
|
+
exports.useSelectPosition = useSelectPosition;
|
2550
|
+
exports.useSetAdminRole = useSetAdminRole;
|
2551
|
+
exports.useSetAppState = useSetAppState;
|
2552
|
+
exports.useSetClusterRef = useSetClusterRef;
|
2553
|
+
exports.useSetItemsApi = useSetItemsApi;
|
2554
|
+
exports.useSetItemsData = useSetItemsData;
|
2555
|
+
exports.useSetMapClicked = useSetMapClicked;
|
2556
|
+
exports.useSetMarkerClicked = useSetMarkerClicked;
|
2557
|
+
exports.useSetPermissionApi = useSetPermissionApi;
|
2558
|
+
exports.useSetPermissionData = useSetPermissionData;
|
2559
|
+
exports.useSetSelectPosition = useSetSelectPosition;
|
2560
|
+
exports.useSetTagApi = useSetTagApi;
|
2561
|
+
exports.useSetTagData = useSetTagData;
|
2562
|
+
exports.useTags = useTags;
|
2563
|
+
exports.useToggleVisibleGroupType = useToggleVisibleGroupType;
|
2564
|
+
exports.useToggleVisibleLayer = useToggleVisibleLayer;
|
2565
|
+
exports.useUpdateItem = useUpdateItem;
|
2566
|
+
exports.useVisibleGroupType = useVisibleGroupType;
|
2567
|
+
exports.useWindowDimensions = useWindowDimensions;
|
2568
|
+
//# sourceMappingURL=TagView-nJhkFKCX.js.map
|