agviewermap-react 0.1.32 → 0.1.35
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/LazyModalContent-3BSYEYha.js +196 -0
- package/dist/agviewermap-react.js +2 -2
- package/dist/agviewermap-react.umd.cjs +1241 -88
- package/dist/index-PKUq5TLD.js +81839 -0
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/dist/LazyModalContent-DIdquydV.js +0 -237
- package/dist/index-BQl3wtjU.js +0 -103382
package/package.json
CHANGED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { j as jsxRuntimeExports, M as MarkersContext, u as useIntl, a as MyModal, B as Button, T as Tooltip, b as BiPencil, C as Card, c as MarkerForm, d as debounce, t as transformMarker, S as Spinner, e as Search, I as Input, f as MapPin, g as MyButton, h as Trash2 } from "./index-BQl3wtjU.js";
|
|
2
|
-
import { useState, useContext, useCallback, useRef, useMemo, useEffect } from "react";
|
|
3
|
-
const ArrowUpRightIcon = (props) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
4
|
-
"svg",
|
|
5
|
-
{
|
|
6
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
7
|
-
width: 20,
|
|
8
|
-
height: 20,
|
|
9
|
-
viewBox: "0 0 20 20",
|
|
10
|
-
fill: "none",
|
|
11
|
-
...props,
|
|
12
|
-
children: [
|
|
13
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
14
|
-
"path",
|
|
15
|
-
{
|
|
16
|
-
stroke: "#373737",
|
|
17
|
-
strokeLinecap: "round",
|
|
18
|
-
strokeLinejoin: "round",
|
|
19
|
-
strokeWidth: 2,
|
|
20
|
-
d: "m5.833 14.167 8.334-8.334"
|
|
21
|
-
}
|
|
22
|
-
),
|
|
23
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
24
|
-
"path",
|
|
25
|
-
{
|
|
26
|
-
stroke: "#000",
|
|
27
|
-
strokeLinecap: "round",
|
|
28
|
-
strokeLinejoin: "round",
|
|
29
|
-
strokeWidth: 2,
|
|
30
|
-
d: "M5.833 5.833h8.334v8.334"
|
|
31
|
-
}
|
|
32
|
-
)
|
|
33
|
-
]
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
const EditMarkerModal = ({ marker, markerId, buttonClassName = "" }) => {
|
|
37
|
-
const [open, setOpen] = useState(false);
|
|
38
|
-
const { handleMarkerUpdate } = useContext(MarkersContext);
|
|
39
|
-
const intl = useIntl();
|
|
40
|
-
const _onChangeVisibility = useCallback(() => {
|
|
41
|
-
setOpen((prev) => !prev);
|
|
42
|
-
}, []);
|
|
43
|
-
const handlerEditMarker = (data) => {
|
|
44
|
-
console.log("data after editing", data);
|
|
45
|
-
console.log("data before editing", marker);
|
|
46
|
-
return handleMarkerUpdate(data);
|
|
47
|
-
};
|
|
48
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
49
|
-
MyModal,
|
|
50
|
-
{
|
|
51
|
-
trigger: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { variant: "outline", size: "icon", tabIndex: -1, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
52
|
-
Tooltip,
|
|
53
|
-
{
|
|
54
|
-
text: intl.formatMessage({
|
|
55
|
-
id: "app.agviewer_map.edit_marker",
|
|
56
|
-
defaultMessage: "Edit Marker"
|
|
57
|
-
}),
|
|
58
|
-
children: /* @__PURE__ */ jsxRuntimeExports.jsx(BiPencil, { className: "w-5 h-5 action-icon" })
|
|
59
|
-
}
|
|
60
|
-
) }),
|
|
61
|
-
title: intl.formatMessage({
|
|
62
|
-
id: "app.agviewer_map.edit_marker",
|
|
63
|
-
defaultMessage: "Edit Marker"
|
|
64
|
-
}),
|
|
65
|
-
open,
|
|
66
|
-
setOpen,
|
|
67
|
-
headerClassName: "m-4",
|
|
68
|
-
onClose: _onChangeVisibility,
|
|
69
|
-
children: /* @__PURE__ */ jsxRuntimeExports.jsx(Card, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
70
|
-
MarkerForm,
|
|
71
|
-
{
|
|
72
|
-
marker,
|
|
73
|
-
onSubmit: handlerEditMarker,
|
|
74
|
-
onCancel: _onChangeVisibility,
|
|
75
|
-
submitButtonText: intl.formatMessage({
|
|
76
|
-
id: "app.agviewer_map.save_changes",
|
|
77
|
-
defaultMessage: "Save Changes"
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
) })
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
};
|
|
84
|
-
const MarkerItem = ({ marker, onMarkerClick, onDeleteMarker, markersData, intl }) => /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "marker-item rounded-md hover:bg-gray-50 dark:hover:bg-gray-700 p-2 mb-2", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "marker-item-info", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between items-center gap-2", children: [
|
|
85
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2 flex-1 min-w-0", children: [
|
|
86
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(MapPin, { className: "h-4 w-4 text-primary flex-shrink-0" }),
|
|
87
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("h5", { className: "text-sm font-medium text-gray-800 dark:text-gray-200 break-words leading-tight", children: marker == null ? void 0 : marker.title })
|
|
88
|
-
] }),
|
|
89
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-1 flex-shrink-0", children: [
|
|
90
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { text: intl.formatMessage({ id: "app.agviewer_map.focus_marker", defaultMessage: "Focus on the marker" }), children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
91
|
-
MyButton,
|
|
92
|
-
{
|
|
93
|
-
variant: "icon",
|
|
94
|
-
className: "rounded-full p-1 hover:bg-gray-100 dark:hover:bg-gray-600",
|
|
95
|
-
onClick: (e) => onMarkerClick(e, marker),
|
|
96
|
-
"data-marker-id": marker.id,
|
|
97
|
-
children: /* @__PURE__ */ jsxRuntimeExports.jsx(ArrowUpRightIcon, { className: "w-4 h-4" })
|
|
98
|
-
}
|
|
99
|
-
) }),
|
|
100
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { text: intl.formatMessage({ id: "app.agviewer_map.delete_marker", defaultMessage: "Delete Marker" }), children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
101
|
-
MyButton,
|
|
102
|
-
{
|
|
103
|
-
variant: "icon",
|
|
104
|
-
className: "rounded-full p-1 hover:bg-gray-100 dark:hover:bg-gray-600",
|
|
105
|
-
onClick: (e) => onDeleteMarker(e, marker),
|
|
106
|
-
"data-marker-id": marker.id,
|
|
107
|
-
children: /* @__PURE__ */ jsxRuntimeExports.jsx(Trash2, { className: "w-4 h-4 text-red-500" })
|
|
108
|
-
}
|
|
109
|
-
) }),
|
|
110
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
111
|
-
EditMarkerModal,
|
|
112
|
-
{
|
|
113
|
-
marker: markersData.find((m) => m.id === marker.id)
|
|
114
|
-
}
|
|
115
|
-
)
|
|
116
|
-
] })
|
|
117
|
-
] }) }) });
|
|
118
|
-
function LazyModalContent({
|
|
119
|
-
markersData,
|
|
120
|
-
loading,
|
|
121
|
-
handleDeleteMarker,
|
|
122
|
-
onMarkerClick,
|
|
123
|
-
onClose,
|
|
124
|
-
intl
|
|
125
|
-
}) {
|
|
126
|
-
const [searchTerm, setSearchTerm] = useState("");
|
|
127
|
-
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState("");
|
|
128
|
-
const [isSearching, setIsSearching] = useState(false);
|
|
129
|
-
const [visibleItems, setVisibleItems] = useState(20);
|
|
130
|
-
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
|
131
|
-
const scrollContainerRef = useRef(null);
|
|
132
|
-
const debouncedSearch = useCallback(
|
|
133
|
-
debounce((value) => {
|
|
134
|
-
setDebouncedSearchTerm(value);
|
|
135
|
-
setIsSearching(false);
|
|
136
|
-
}, 300),
|
|
137
|
-
[]
|
|
138
|
-
);
|
|
139
|
-
const handleSearchChange = useCallback((e) => {
|
|
140
|
-
const value = e.target.value;
|
|
141
|
-
setSearchTerm(value);
|
|
142
|
-
setIsSearching(true);
|
|
143
|
-
debouncedSearch(value);
|
|
144
|
-
}, [debouncedSearch]);
|
|
145
|
-
const transformedMarkers = useMemo(() => {
|
|
146
|
-
if (!markersData || markersData.length === 0) return [];
|
|
147
|
-
return markersData.map((m) => transformMarker(m));
|
|
148
|
-
}, [markersData]);
|
|
149
|
-
const filteredMarkers = useMemo(() => {
|
|
150
|
-
if (!debouncedSearchTerm) return transformedMarkers;
|
|
151
|
-
const searchLower = debouncedSearchTerm.toLowerCase();
|
|
152
|
-
return transformedMarkers.filter(
|
|
153
|
-
(marker) => {
|
|
154
|
-
var _a, _b;
|
|
155
|
-
return (_b = (_a = marker == null ? void 0 : marker.title) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes(searchLower);
|
|
156
|
-
}
|
|
157
|
-
);
|
|
158
|
-
}, [transformedMarkers, debouncedSearchTerm]);
|
|
159
|
-
const visibleMarkers = useMemo(() => {
|
|
160
|
-
return filteredMarkers.slice(0, visibleItems);
|
|
161
|
-
}, [filteredMarkers, visibleItems]);
|
|
162
|
-
useEffect(() => {
|
|
163
|
-
setVisibleItems(20);
|
|
164
|
-
}, [debouncedSearchTerm]);
|
|
165
|
-
const loadMore = useCallback(() => {
|
|
166
|
-
if (isLoadingMore || visibleItems >= filteredMarkers.length) return;
|
|
167
|
-
setIsLoadingMore(true);
|
|
168
|
-
setTimeout(() => {
|
|
169
|
-
setVisibleItems((prev) => Math.min(prev + 20, filteredMarkers.length));
|
|
170
|
-
setIsLoadingMore(false);
|
|
171
|
-
}, 300);
|
|
172
|
-
}, [isLoadingMore, visibleItems, filteredMarkers.length]);
|
|
173
|
-
const handleScroll = useCallback((e) => {
|
|
174
|
-
const { scrollTop, scrollHeight, clientHeight } = e.target;
|
|
175
|
-
const isNearBottom = scrollTop + clientHeight >= scrollHeight - 100;
|
|
176
|
-
if (isNearBottom && !isLoadingMore && visibleItems < filteredMarkers.length) {
|
|
177
|
-
loadMore();
|
|
178
|
-
}
|
|
179
|
-
}, [loadMore, isLoadingMore, visibleItems, filteredMarkers.length]);
|
|
180
|
-
const handleMarkerClick = useCallback((e, marker) => {
|
|
181
|
-
onMarkerClick(e, marker);
|
|
182
|
-
onClose();
|
|
183
|
-
}, [onMarkerClick, onClose]);
|
|
184
|
-
const handleDelete = useCallback((e, marker) => {
|
|
185
|
-
handleDeleteMarker(e, marker);
|
|
186
|
-
}, [handleDeleteMarker]);
|
|
187
|
-
if (loading) {
|
|
188
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex justify-center items-center h-40", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Spinner, {}) });
|
|
189
|
-
}
|
|
190
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "w-full", children: [
|
|
191
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative mb-4", children: [
|
|
192
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(Search, { className: "w-4 h-4 text-gray-500 absolute left-3 top-1/2 transform -translate-y-1/2" }),
|
|
193
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
194
|
-
Input,
|
|
195
|
-
{
|
|
196
|
-
className: "pl-9 w-full text-sm h-9",
|
|
197
|
-
placeholder: intl.formatMessage({ id: "app.agviewer_map.search_station", defaultMessage: "Search Station" }),
|
|
198
|
-
value: searchTerm,
|
|
199
|
-
onChange: handleSearchChange
|
|
200
|
-
}
|
|
201
|
-
),
|
|
202
|
-
isSearching && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "absolute right-3 top-1/2 transform -translate-y-1/2", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "animate-spin rounded-full h-4 w-4 border-b-2 border-primary" }) })
|
|
203
|
-
] }),
|
|
204
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
205
|
-
"div",
|
|
206
|
-
{
|
|
207
|
-
ref: scrollContainerRef,
|
|
208
|
-
className: "overflow-y-auto h-[350px]",
|
|
209
|
-
onScroll: handleScroll,
|
|
210
|
-
children: filteredMarkers.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-20 p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("h5", { className: "text-sm text-gray-500 dark:text-gray-400", children: searchTerm ? intl.formatMessage({ id: "app.agviewer_map.no_station_found", defaultMessage: "No Station Found" }) : intl.formatMessage({ id: "app.agviewer_map.no_station_found", defaultMessage: "No Station Found" }) }) }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
211
|
-
visibleMarkers.map((marker) => /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
212
|
-
MarkerItem,
|
|
213
|
-
{
|
|
214
|
-
marker,
|
|
215
|
-
onMarkerClick: handleMarkerClick,
|
|
216
|
-
onDeleteMarker: handleDelete,
|
|
217
|
-
markersData,
|
|
218
|
-
intl
|
|
219
|
-
},
|
|
220
|
-
marker.id
|
|
221
|
-
)),
|
|
222
|
-
isLoadingMore && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex justify-center items-center py-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
223
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "animate-spin rounded-full h-4 w-4 border-b-2 border-primary" }),
|
|
224
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-500 dark:text-gray-400", children: "Loading more..." })
|
|
225
|
-
] }) }),
|
|
226
|
-
visibleItems >= filteredMarkers.length && filteredMarkers.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex justify-center items-center py-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-500 dark:text-gray-400", children: intl.formatMessage({
|
|
227
|
-
id: "app.agviewer_map.all_results_loaded",
|
|
228
|
-
defaultMessage: "All results loaded"
|
|
229
|
-
}) }) })
|
|
230
|
-
] })
|
|
231
|
-
}
|
|
232
|
-
)
|
|
233
|
-
] });
|
|
234
|
-
}
|
|
235
|
-
export {
|
|
236
|
-
LazyModalContent as default
|
|
237
|
-
};
|