adt-js-components 2.0.1 → 2.1.1
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/package.json +22 -6
- package/src/Map/index.js +31 -23
- package/src/Notifications/index.js +40 -10
- package/src/SubmitForm/index.js +32 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adt-js-components",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "JavaScript components for Nette framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
"url": "git+https://github.com/AppsDevTeam/js-components.git"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
+
"nette.ajax.js": "^2.3.0"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"jquery": "^3.4.1",
|
|
14
18
|
"select2": "^4.0.13",
|
|
15
19
|
"select2-bootstrap-5-theme": "^1.1.1",
|
|
16
20
|
"autonumeric": "^4.6.0",
|
|
@@ -23,14 +27,26 @@
|
|
|
23
27
|
"scrollparent": "^2.0.1",
|
|
24
28
|
"tinymce": "^5.7.0",
|
|
25
29
|
"tinymce-i18n": "^20.12.25",
|
|
26
|
-
"nette.ajax.js": "^2.3.0",
|
|
27
30
|
"leaflet": "^1.9.4",
|
|
28
31
|
"leaflet.markercluster": "^1.5.3",
|
|
29
|
-
"firebase": "^12.10.0"
|
|
30
|
-
"@firebase/messaging": "^0.12.24"
|
|
32
|
+
"firebase": "^12.10.0"
|
|
31
33
|
},
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"select2": { "optional": true },
|
|
36
|
+
"select2-bootstrap-5-theme": { "optional": true },
|
|
37
|
+
"autonumeric": { "optional": true },
|
|
38
|
+
"@here/flexpolyline": { "optional": true },
|
|
39
|
+
"flatpickr": { "optional": true },
|
|
40
|
+
"script-loader": { "optional": true },
|
|
41
|
+
"timepicker": { "optional": true },
|
|
42
|
+
"glightbox": { "optional": true },
|
|
43
|
+
"@googlemaps/js-api-loader": { "optional": true },
|
|
44
|
+
"scrollparent": { "optional": true },
|
|
45
|
+
"tinymce": { "optional": true },
|
|
46
|
+
"tinymce-i18n": { "optional": true },
|
|
47
|
+
"leaflet": { "optional": true },
|
|
48
|
+
"leaflet.markercluster": { "optional": true },
|
|
49
|
+
"firebase": { "optional": true }
|
|
34
50
|
},
|
|
35
51
|
"author": "Apps Dev Team",
|
|
36
52
|
"license": "MIT",
|
package/src/Map/index.js
CHANGED
|
@@ -23,6 +23,7 @@ const onSelectionChangeMap = new WeakMap();
|
|
|
23
23
|
const onBeforeRouteCalculationMap = new WeakMap();
|
|
24
24
|
const onAfterRouteCalculationMap = new WeakMap();
|
|
25
25
|
const disableClickZoomMap = new WeakMap();
|
|
26
|
+
const disableClusteringMap = new WeakMap();
|
|
26
27
|
const cachedRouteLoaded = new WeakMap();
|
|
27
28
|
|
|
28
29
|
const DEPOT_TYPE = {
|
|
@@ -56,7 +57,8 @@ async function run(options) {
|
|
|
56
57
|
markerInfoCallback = null,
|
|
57
58
|
onBeforeRouteCalculation = null,
|
|
58
59
|
onAfterRouteCalculation = null,
|
|
59
|
-
disableClickZoom = false
|
|
60
|
+
disableClickZoom = false,
|
|
61
|
+
disableClustering = false
|
|
60
62
|
} = JSON.parse(el.dataset.adtMap);
|
|
61
63
|
|
|
62
64
|
/** @type {RouteSetting} */
|
|
@@ -91,6 +93,7 @@ async function run(options) {
|
|
|
91
93
|
onBeforeRouteCalculationMap.set(map, onBeforeRouteCalculation);
|
|
92
94
|
onAfterRouteCalculationMap.set(map, onAfterRouteCalculation);
|
|
93
95
|
disableClickZoomMap.set(map, disableClickZoom);
|
|
96
|
+
disableClusteringMap.set(map, disableClustering);
|
|
94
97
|
|
|
95
98
|
if (mapProvider === MAP_PROVIDER.HERE) {
|
|
96
99
|
L.tileLayer(
|
|
@@ -334,21 +337,23 @@ function enableRectangleSelection(map, onSelectionChange, showSelectionOrder) {
|
|
|
334
337
|
|
|
335
338
|
function addMarkers(map, markers, options, selectedOptions, position, selectable, onSelectionChange, showSelectionOrder, markerInfoCallback) {
|
|
336
339
|
const positionsOfMarkers = [];
|
|
337
|
-
const cluster =
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
340
|
+
const cluster = disableClusteringMap.get(map)
|
|
341
|
+
? L.layerGroup()
|
|
342
|
+
: L.markerClusterGroup({
|
|
343
|
+
disableClusteringAtZoom: 18,
|
|
344
|
+
spiderfyOnMaxZoom: true,
|
|
345
|
+
showCoverageOnHover: false,
|
|
346
|
+
zoomToBoundsOnClick: true,
|
|
347
|
+
iconCreateFunction: function (cluster) {
|
|
348
|
+
const childCount = cluster.getChildCount();
|
|
349
|
+
const c = childCount < 10 ? 'small' : childCount < 100 ? 'medium' : 'large';
|
|
350
|
+
return new L.DivIcon({
|
|
351
|
+
html: '<div><span>' + childCount + '</span></div>',
|
|
352
|
+
className: 'marker-cluster marker-cluster-' + c,
|
|
353
|
+
iconSize: new L.Point(40, 40)
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
});
|
|
352
357
|
|
|
353
358
|
markerClusters.set(map, cluster);
|
|
354
359
|
let loadedCount = 0;
|
|
@@ -411,9 +416,9 @@ async function applyPreselectedMarkersVisualOnly(map, markersData) {
|
|
|
411
416
|
for (const markerData of preselected) {
|
|
412
417
|
const markerInstance = markerMap.get(markerData.id);
|
|
413
418
|
if (markerInstance && markerInstance._selectedIcon) {
|
|
414
|
-
if (settings && settings.color) {
|
|
419
|
+
if ((settings && settings.color) || markerData.iconStyle) {
|
|
415
420
|
const iconUrl = markerInstance._selectedIcon.options.iconUrl;
|
|
416
|
-
const newIcon = await createMarkerIcon(map, iconUrl, null);
|
|
421
|
+
const newIcon = await createMarkerIcon(map, iconUrl, null, null, markerData.iconStyle);
|
|
417
422
|
markerInstance.setIcon(newIcon);
|
|
418
423
|
} else {
|
|
419
424
|
markerInstance.setIcon(markerInstance._selectedIcon);
|
|
@@ -542,7 +547,7 @@ async function selectMarker(marker, map, showSelectionOrder) {
|
|
|
542
547
|
}
|
|
543
548
|
|
|
544
549
|
if (showSelectionOrder) {
|
|
545
|
-
const newIcon = await createMarkerIcon(map, marker.options.icon.options.iconUrl, newOrder);
|
|
550
|
+
const newIcon = await createMarkerIcon(map, marker.options.icon.options.iconUrl, newOrder, null, marker._markerData?.iconStyle);
|
|
546
551
|
marker.setIcon(newIcon);
|
|
547
552
|
}
|
|
548
553
|
}
|
|
@@ -581,16 +586,19 @@ function deselectMarker(marker, map, showSelectionOrder) {
|
|
|
581
586
|
async function updateMarkerOrderDisplay(map, marker, orderNumber, isSelected, color = null) {
|
|
582
587
|
if (!marker._normalIcon || !marker._normalIcon.options) return;
|
|
583
588
|
const iconUrl = isSelected && marker._selectedIcon ? marker._selectedIcon.options.iconUrl : marker._normalIcon.options.iconUrl;
|
|
584
|
-
const newIcon = await createMarkerIcon(map, iconUrl, orderNumber, color);
|
|
589
|
+
const newIcon = await createMarkerIcon(map, iconUrl, orderNumber, color, marker._markerData?.iconStyle);
|
|
585
590
|
marker.setIcon(newIcon);
|
|
586
591
|
}
|
|
587
592
|
|
|
588
|
-
async function createMarkerIcon(map, iconUrl, orderNumber, color = null) {
|
|
589
|
-
let inlineStyle =
|
|
593
|
+
async function createMarkerIcon(map, iconUrl, orderNumber, color = null, iconStyle = null) {
|
|
594
|
+
let inlineStyle = '';
|
|
590
595
|
const settings = routeSettingsMap.get(map);
|
|
591
596
|
if ((settings && settings.color) || color) {
|
|
592
597
|
inlineStyle = `--marker-fill: ${color ?? settings.color};`;
|
|
593
598
|
}
|
|
599
|
+
if (iconStyle) {
|
|
600
|
+
inlineStyle += iconStyle;
|
|
601
|
+
}
|
|
594
602
|
|
|
595
603
|
let svg;
|
|
596
604
|
if (svgCache.has(iconUrl)) {
|
|
@@ -903,7 +911,7 @@ async function toggleMarker(mapElement, markerId, selected, recalculate = true)
|
|
|
903
911
|
}
|
|
904
912
|
|
|
905
913
|
const cluster = markerClusters.get(map);
|
|
906
|
-
if (cluster) {
|
|
914
|
+
if (cluster && typeof cluster.refreshClusters === 'function') {
|
|
907
915
|
cluster.refreshClusters(marker);
|
|
908
916
|
}
|
|
909
917
|
|
|
@@ -88,18 +88,48 @@ const run = (config) => {
|
|
|
88
88
|
updateButtons();
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
// window.messaging se inicializuje async v Messaging komponentě, která nemusí
|
|
92
|
+
// doběhnout dřív než tento init (typicky po F5). Počkáme na ni, jinak by se
|
|
93
|
+
// getToken nikdy nezavolal a window.adtNotificationsToken by zůstal nenastavený.
|
|
94
|
+
var waitForMessaging = function (timeoutMs) {
|
|
95
|
+
return new Promise(function (resolve) {
|
|
96
|
+
if (window.messaging) {
|
|
97
|
+
resolve(window.messaging);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
var elapsed = 0;
|
|
101
|
+
var step = 100;
|
|
102
|
+
var interval = setInterval(function () {
|
|
103
|
+
if (window.messaging) {
|
|
104
|
+
clearInterval(interval);
|
|
105
|
+
resolve(window.messaging);
|
|
106
|
+
} else if ((elapsed += step) >= timeoutMs) {
|
|
107
|
+
clearInterval(interval);
|
|
108
|
+
resolve(null);
|
|
97
109
|
}
|
|
110
|
+
}, step);
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Initial state: check if notifications are already enabled
|
|
115
|
+
if (Notification.permission === 'granted') {
|
|
116
|
+
waitForMessaging(5000).then(function (messaging) {
|
|
117
|
+
if (!messaging) {
|
|
98
118
|
updateButtons();
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
})
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
getToken(messaging, { vapidKey: config.vapidKey })
|
|
123
|
+
.then(function (currentToken) {
|
|
124
|
+
if (currentToken) {
|
|
125
|
+
window.adtNotificationsToken = currentToken;
|
|
126
|
+
}
|
|
127
|
+
updateButtons();
|
|
128
|
+
})
|
|
129
|
+
.catch(function () {
|
|
130
|
+
updateButtons();
|
|
131
|
+
});
|
|
132
|
+
});
|
|
103
133
|
} else {
|
|
104
134
|
updateButtons();
|
|
105
135
|
}
|
package/src/SubmitForm/index.js
CHANGED
|
@@ -8,6 +8,30 @@ function getErrorElementId(el) {
|
|
|
8
8
|
return isList(el) ? el.id.split('-').slice(0, -1).join('-') : el.id;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
function toggleInvalid(el, invalid) {
|
|
12
|
+
el.classList.toggle('is-invalid', invalid);
|
|
13
|
+
// because of radio lists and checkbox lists
|
|
14
|
+
if (isList(el)) {
|
|
15
|
+
el.parentNode.classList.toggle('is-invalid', invalid);
|
|
16
|
+
}
|
|
17
|
+
// because of https://github.com/twbs/bootstrap/issues/25110
|
|
18
|
+
if (el.parentNode.classList.contains('input-group')) {
|
|
19
|
+
el.parentNode.classList.toggle('has-validation', invalid);
|
|
20
|
+
el.parentNode.classList.toggle('is-invalid', invalid);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function hasErrors(errorElement) {
|
|
25
|
+
return Array.from(errorElement.childNodes).some(node => node.nodeName !== 'SCRIPT' && node.textContent.trim() !== '');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function markErrorsFor(errorElement) {
|
|
29
|
+
const el = document.getElementById(errorElement.getAttribute('data-adt-errors-for'));
|
|
30
|
+
if (el && el.tagName !== 'FORM') {
|
|
31
|
+
toggleInvalid(el, hasErrors(errorElement));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
11
35
|
function scrollToFirstError(form) {
|
|
12
36
|
const el = $(form).find('.alert-danger:first, .is-invalid:first')[0];
|
|
13
37
|
|
|
@@ -28,10 +52,17 @@ function run(options) {
|
|
|
28
52
|
if (isList(this)) {
|
|
29
53
|
$(this).parent().parent().find('.is-invalid').removeClass('is-invalid');
|
|
30
54
|
}
|
|
55
|
+
if (this.parentNode.classList.contains('input-group')) {
|
|
56
|
+
this.parentNode.classList.remove('is-invalid');
|
|
57
|
+
}
|
|
31
58
|
});
|
|
32
59
|
}
|
|
33
60
|
|
|
34
61
|
$.nette.ext('live').after(function($el) {
|
|
62
|
+
$el.find('[data-adt-errors-for]').addBack('[data-adt-errors-for]').each(function() {
|
|
63
|
+
markErrorsFor(this);
|
|
64
|
+
});
|
|
65
|
+
|
|
35
66
|
window.addEventListener('pageshow', (e) => {
|
|
36
67
|
if (e.persisted) {
|
|
37
68
|
$el.find('[data-adt-submit-form]').each(function(e) {
|
|
@@ -85,15 +116,7 @@ function run(options) {
|
|
|
85
116
|
errorElement.innerHTML += `<div>${error.message}</div>`;
|
|
86
117
|
}
|
|
87
118
|
|
|
88
|
-
error.element
|
|
89
|
-
// because of radio lists and checkbox lists
|
|
90
|
-
if (isList(error.element)) {
|
|
91
|
-
error.element.parentNode.classList.add('is-invalid');
|
|
92
|
-
}
|
|
93
|
-
// because of https://github.com/twbs/bootstrap/issues/25110
|
|
94
|
-
if (error.element.parentNode.classList.contains('input-group')) {
|
|
95
|
-
error.element.parentNode.classList.add('has-validation');
|
|
96
|
-
}
|
|
119
|
+
toggleInvalid(error.element, true);
|
|
97
120
|
}
|
|
98
121
|
|
|
99
122
|
if (errors.length) {
|