@vidro/map-handler 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +67 -1
  2. package/dist/map-handler.js +1 -1
  3. package/map-handler.d.ts +134 -0
  4. package/package.json +11 -4
  5. package/src/types.d.ts +63 -0
  6. package/.babelrc +0 -6
  7. package/doc/animation.png +0 -0
  8. package/doc/confirmComponent.png +0 -0
  9. package/doc/giswater.png +0 -0
  10. package/doc/giswaterInfo.png +0 -0
  11. package/doc/giswaterInfoApi.png +0 -0
  12. package/doc/giswatergeojson.png +0 -0
  13. package/doc/multiTile.png +0 -0
  14. package/doc/multiTileNoGutter.png +0 -0
  15. package/doc/togglelayergiswater.png +0 -0
  16. package/doc/vidromaps-basic.png +0 -0
  17. package/examples/full/apidemo.js +0 -387
  18. package/examples/full/cachedToken.dat +0 -1
  19. package/examples/full/cachedTokenData.dat +0 -1
  20. package/examples/full/docker/Docker_compose.yml +0 -14
  21. package/examples/full/docker/Dockerfile +0 -27
  22. package/examples/full/index.php +0 -200
  23. package/examples/full/storeToken.php +0 -6
  24. package/examples/full/tester.css +0 -74
  25. package/examples/full/tester.js +0 -658
  26. package/examples/multipleIframes/index.js +0 -82
  27. package/examples/multipleIframes/index.php +0 -52
  28. package/examples/react-next/README.md +0 -282
  29. package/examples/react-next/atoms/PrintLayoutSelector.js +0 -50
  30. package/examples/react-next/atoms/PrintPaperSizeSelector.js +0 -48
  31. package/examples/react-next/atoms/ZoomToScaleButton.js +0 -57
  32. package/examples/react-next/components/AuthComponent.js +0 -88
  33. package/examples/react-next/components/MapButtons.js +0 -136
  34. package/examples/react-next/components/MapFilters.js +0 -120
  35. package/examples/react-next/components/MapIframe.js +0 -25
  36. package/examples/react-next/components/MapInfo.js +0 -36
  37. package/examples/react-next/components/MapLayers.js +0 -60
  38. package/examples/react-next/components/MapList.js +0 -51
  39. package/examples/react-next/contexts/auth.js +0 -147
  40. package/examples/react-next/contexts/maps.js +0 -185
  41. package/examples/react-next/contexts/messages.js +0 -360
  42. package/examples/react-next/contexts/print.js +0 -51
  43. package/examples/react-next/env.sample +0 -3
  44. package/examples/react-next/eslint.config.mjs +0 -14
  45. package/examples/react-next/hooks/useMapEvents.js +0 -118
  46. package/examples/react-next/jsconfig.json +0 -7
  47. package/examples/react-next/next.config.mjs +0 -6
  48. package/examples/react-next/package.json +0 -25
  49. package/examples/react-next/pages/_app.js +0 -5
  50. package/examples/react-next/pages/index.js +0 -90
  51. package/examples/react-next/postcss.config.mjs +0 -8
  52. package/examples/react-next/public/discord.svg +0 -8
  53. package/examples/react-next/public/favicon.ico +0 -0
  54. package/examples/react-next/public/file.svg +0 -1
  55. package/examples/react-next/public/logo.png +0 -0
  56. package/examples/react-next/public/next.svg +0 -1
  57. package/examples/react-next/shared/constants.js +0 -47
  58. package/examples/react-next/shared/cookies.js +0 -23
  59. package/examples/react-next/styles/globals.css +0 -24
  60. package/examples/react-next/tailwind.config.mjs +0 -17
  61. package/examples/serverLess/dist/index.23420cfa.js +0 -2973
  62. package/examples/serverLess/dist/index.23420cfa.js.map +0 -1
  63. package/examples/serverLess/dist/index.91b6cacc.js +0 -2
  64. package/examples/serverLess/dist/index.91b6cacc.js.map +0 -1
  65. package/examples/serverLess/dist/index.html +0 -1
  66. package/examples/serverLess/index.html +0 -39
  67. package/examples/serverLess/main.js +0 -113
  68. package/examples/serverLess/package.json +0 -18
  69. package/examples/serverLess/readme.md +0 -41
  70. package/examples/simple/index.html +0 -23
  71. package/examples/simple/simple.js +0 -80
  72. package/examples/taigua/index.html +0 -55
  73. package/examples/taigua/main.js +0 -490
  74. package/examples/tester.css +0 -74
  75. package/examples/vidromap/index.js +0 -20
  76. package/examples/vidromap/index.php +0 -111
  77. package/flows.md +0 -73
  78. package/helpers.md +0 -45
  79. package/src/index.js +0 -879
  80. package/src/shared/iframe-communicator.js +0 -18
  81. package/webpack.config.js +0 -22
@@ -1,185 +0,0 @@
1
- "use client";
2
- import { createContext, useContext, useState, useEffect } from "react";
3
- import { useAuth } from "./auth";
4
- import {
5
- setMapId as setMapIdCookie,
6
- getMapId as getMapIdCookie,
7
- removeMapId as removeMapIdCookie,
8
- } from "@/shared/cookies";
9
- const MapsContext = createContext({});
10
-
11
- export const MapsProvider = ({ children }) => {
12
- const { apiUrl, token } = useAuth();
13
- const [map, setMap] = useState(null);
14
- const [mapId, setMapId] = useState(null);
15
-
16
- const [mapError, setMapError] = useState(null);
17
- const [mapReady, setMapReady] = useState(false);
18
-
19
- const [sessionToken, setSessionToken] = useState(null);
20
- const [currentMapAction, setCurrentMapAction] = useState(null);
21
- const [clickedCoordinates, setClickedCoordinates] = useState(null);
22
- const [bboxCoordinates, setBboxcoordinates] = useState(null);
23
- const [zoomLevel, setZoomLevel] = useState(null);
24
- const [mapScale, setMapScale] = useState(null);
25
- const [mapResolution, setMapResolution] = useState(null);
26
- const [srid, setSrid] = useState(null);
27
-
28
- //geolocations
29
- const [geolocalizing, setGeolocalizing] = useState(false);
30
- const [geolocalizingstatus, setGeolocalizingStatus] = useState(null);
31
- const [userGeoPosition, setUserGeoPosition] = useState(null);
32
-
33
- //measure
34
- const [measureStatus, setMeasureStatus] = useState(null);
35
-
36
- //layers
37
- const [displayedLayers, setDisplayedLayers] = useState([]);
38
- const [activeLayer, setActiveLayer] = useState(null);
39
- const [mapLayers, setMapLayers] = useState(null);
40
-
41
- const [infoLayerSource, setInfoLayerSource] = useState([]); //layer from info is received
42
-
43
- //filters
44
- const [configuredFilters, setConfiguredFilters] = useState(null); //backoffice configured filters
45
- const [mapFilters, setMapfilters] = useState(null);
46
- const [filtersApplied, setFiltersApplied] = useState(false);
47
- const [activeFilters, setActiveFilters] = useState([]);
48
-
49
- //tools
50
- const [selectedTool, setSelectedTool] = useState(null);
51
-
52
- useEffect(() => {
53
- if (!token) return;
54
- (async () => {
55
- if (!getMapIdCookie()) {
56
- console.log("No map if cookie found");
57
-
58
- return;
59
- }
60
- console.log("Map id cookie found, getting map...");
61
- try {
62
- await GetMap(getMapIdCookie());
63
- } catch (error) {
64
- console.error("Error getting map from cookie", error);
65
- return;
66
- }
67
- })();
68
- }, [token]);
69
-
70
- const GetMap = async (id) => {
71
- let url = `${apiUrl}map/${id}`;
72
-
73
- try {
74
- const response = await fetch(url, {
75
- method: "GET",
76
- headers: {
77
- "Content-Type": "application/json",
78
- Authorization: `Bearer ${token}`,
79
- },
80
- });
81
- const data = await response.json();
82
- console.log("GetMap", data);
83
- setMapId(id);
84
- setMapError(false);
85
- setSessionToken(data.message.sessionToken);
86
- setMap(
87
- `${data.message.iframe}?sessionToken=${data.message.sessionToken}`
88
- );
89
- //store map id in cookie, to avoid losing it on page refresh
90
- setMapIdCookie(id);
91
-
92
- return;
93
- } catch (error) {
94
- console.error("Error fetching map:", error);
95
- setSessionToken(null);
96
- setMap(null);
97
- setMapId(null);
98
- removeMapIdCookie();
99
-
100
- throw error;
101
- }
102
- };
103
-
104
- const GetMapInfo = async (id) => {
105
- let url = `${apiUrl}map/detail/${id}`;
106
-
107
- try {
108
- const response = await fetch(url, {
109
- method: "GET",
110
- headers: {
111
- "Content-Type": "application/json",
112
- Authorization: `Bearer ${token}`,
113
- },
114
- });
115
- const data = await response.json();
116
- console.log("GetMapInfo", data);
117
- console.log("Layers", data.message.layers);
118
- setMapLayers(data.message.layers);
119
- setConfiguredFilters(data.message.layerFilters);
120
- return;
121
- } catch (error) {
122
- console.error("Error fetching map info:", error);
123
-
124
- setMapLayers(null);
125
- throw error;
126
- }
127
- };
128
- return (
129
- <MapsContext.Provider
130
- value={{
131
- mapId,
132
- setMapId,
133
- GetMap,
134
- map,
135
- sessionToken,
136
- mapError,
137
- mapReady,
138
- setMapReady,
139
- displayedLayers,
140
- setDisplayedLayers,
141
- activeLayer,
142
- setActiveLayer,
143
- currentMapAction,
144
- setCurrentMapAction,
145
- mapFilters,
146
- setMapfilters,
147
- activeFilters,
148
- setActiveFilters,
149
- configuredFilters,
150
- infoLayerSource,
151
- setInfoLayerSource,
152
- clickedCoordinates,
153
- setClickedCoordinates,
154
- bboxCoordinates,
155
- setBboxcoordinates,
156
- srid,
157
- setSrid,
158
- geolocalizing,
159
- setGeolocalizing,
160
- geolocalizingstatus,
161
- setGeolocalizingStatus,
162
- userGeoPosition,
163
- measureStatus,
164
- setMeasureStatus,
165
- selectedTool,
166
- setSelectedTool,
167
- filtersApplied,
168
- setFiltersApplied,
169
- zoomLevel,
170
- setZoomLevel,
171
- mapScale,
172
- setMapScale,
173
- setSessionToken,
174
- mapLayers,
175
- GetMapInfo,
176
- mapResolution,
177
- setMapResolution,
178
- }}
179
- >
180
- {children}
181
- </MapsContext.Provider>
182
- );
183
- };
184
-
185
- export const useMaps = () => useContext(MapsContext);
@@ -1,360 +0,0 @@
1
- import { createContext, useContext, useEffect, useState } from "react";
2
- import { MAP_EVENTS } from "@/shared/constants";
3
-
4
- const MessageContext = createContext({});
5
-
6
- export const MessageProvider = ({ children }) => {
7
- const [events, setEvents] = useState(false);
8
- const [communicator, setCommunicator] = useState(false);
9
- const [message, setMessage] = useState(null);
10
- const [messageQueue, setMessageQueue] = useState([]);
11
-
12
- useEffect(() => {
13
- if (!communicator) return;
14
- console.log("MapHandler is ready for use");
15
- }, [communicator]);
16
-
17
- const start = async (sessionToken) => {
18
- const { Communicator } = await import("@vidro/map-handler");
19
- const _communicator = new Communicator({ sessionToken });
20
- setCommunicator(_communicator);
21
- };
22
-
23
- const reloadLayers = () => {
24
- if (!communicator) return;
25
- communicator.reloadDisplayedLayers();
26
- };
27
-
28
- const ZoomIn = () => {
29
- console.log("ZoomIn");
30
- if (!communicator) return;
31
- console.log("ZoomIn 2");
32
- communicator.ZoomIn();
33
- };
34
-
35
- const zoomToExtent = () => {
36
- if (!communicator) return;
37
- communicator.zoomToExtent();
38
- };
39
-
40
- const ZoomOut = () => {
41
- if (!communicator) return;
42
- communicator.ZoomOut();
43
- };
44
-
45
- const Clear = () => {
46
- if (!communicator) return;
47
- communicator.clear();
48
- };
49
-
50
- const Info = (type = "geojson", layer, format = "json") => {
51
- const hitTolerance = 5;
52
- communicator.infoFromCoordinates(type, layer, hitTolerance, format);
53
- };
54
-
55
- const Geolocalize = (what) => {
56
- if (!communicator) return;
57
- communicator.Geolocalize(what);
58
- };
59
-
60
- const Filters = (filters) => {
61
- if (!communicator) return;
62
- console.log("messages - Filters", filters);
63
- communicator.setFilters(filters);
64
- };
65
-
66
- const RemoveElementFromMap = (id, layer) => {
67
- communicator.RemoveGeometry(id, layer);
68
- };
69
-
70
- const CancelAddGeom = () => {
71
- if (!communicator) return;
72
- console.log("CancelAddGeom");
73
- communicator.CancelAddGeom();
74
- };
75
-
76
- const Highlight = (item, center, animate, id, style, zoom = null) => {
77
- if (!communicator) return;
78
- console.log("Highlight", { item, center, animate, id, style, zoom });
79
- let options = {
80
- geom: item.geom,
81
- zoom,
82
- center,
83
- animate,
84
- data: item,
85
- style,
86
- };
87
- communicator.Highlight(options);
88
- };
89
-
90
- const RemoveGeometriesByProperty = (layer, property, value) => {
91
- if (!communicator) return;
92
- communicator.RemoveGeometriesByProperty(layer, property, value);
93
- };
94
-
95
- const UpdateGeometriesByProperty = (layer, property, value, style) => {
96
- if (!communicator) return;
97
- console.log("UpdateGeometriesByProperty", {
98
- layer,
99
- property,
100
- value,
101
- style,
102
- });
103
- communicator.UpdateGeometriesByProperty(layer, property, value, style);
104
- };
105
-
106
- const DrawGeometries = (geoms) => {
107
- if (!communicator) return;
108
- console.log("DrawGeometries", geoms);
109
- communicator.DrawGeometries(geoms);
110
- };
111
-
112
- const DrawGeometry = (geom, featureId, style) => {
113
- if (!communicator) return;
114
- console.log("DrawGeometry", { geom, featureId, style });
115
- communicator.DrawGeometries([{ geom, style, featureId, id: featureId }]);
116
- };
117
-
118
- const ToggleLayer = (layer, properties) => {
119
- if (!communicator) return;
120
- communicator.toggleLayer(layer, properties);
121
- };
122
-
123
- const removeLayer = (name) => {
124
- if (!communicator) return;
125
- console.log("removeLayer", { name });
126
- communicator.removeLayer(name);
127
- };
128
-
129
- const startDrawPolygon = () => {
130
- const options = {
131
- texts: {
132
- start: t({
133
- id: "COMMON.COMMON.CLICK_TO_START_DRAWING",
134
- }),
135
- continue: t({
136
- id: "COMMON.COMMON.CLICK_TO_CONTINUE_DRAWING_POLYGON",
137
- }),
138
- },
139
- style: {
140
- fill: "rgb(249, 34, 34,0.3)",
141
- stroke: "rgb(249, 34, 34)",
142
- },
143
- drawOnEnd: false,
144
- showConfirm: false,
145
- };
146
- communicator.AddGeom("Polygon", options);
147
- };
148
-
149
- const BBoxForClicks = (size) => {
150
- if (!communicator) return;
151
- communicator.setBboxSize(size);
152
- };
153
-
154
- const cancelMeasure = () => {
155
- if (!communicator) return;
156
- communicator.cancelMeasure();
157
- };
158
-
159
- const initMeasure = (type, startMsg, continueMsg) => {
160
- if (!communicator) return;
161
- communicator.cancelMeasure();
162
- communicator.initMeasure(type, startMsg, continueMsg);
163
- };
164
-
165
- const zoomToCoordinates = (coordinates, zoomLevel) => {
166
- if (!communicator) return;
167
- communicator.zoomToCoordinates(coordinates[0], coordinates[1], zoomLevel);
168
- };
169
-
170
- const zoomToGeometry = (geom, limits) => {
171
- if (!communicator) return;
172
- communicator.zoomToGeometry(geom, limits);
173
- };
174
-
175
- const centerMap = (coordinates) => {
176
- if (!communicator) return;
177
- communicator.CenterMap(coordinates[0], coordinates[1]);
178
- };
179
-
180
- const drawPoint = ({ drawOnEnd = false, showConfirm = false }) => {
181
- if (!communicator) return;
182
- communicator.AddGeom("Point", { drawOnEnd, showConfirm: true });
183
- };
184
-
185
- const addIcon = (icon, coordinates) => {
186
- communicator.addIcon({ icon, coordinates });
187
- };
188
-
189
- const zoomToScale = (scale) => {
190
- const allowedScales = [
191
- "1:100",
192
- "1:200",
193
- "1:400",
194
- "1:500",
195
- "1:1000",
196
- "1:2000",
197
- "1:5000",
198
- "1:10000",
199
- "1:50000",
200
- ];
201
- if (!allowedScales.includes(scale)) {
202
- console.error(
203
- `Invalid scale: ${scale}. Allowed values are: ${allowedScales.join(
204
- ", "
205
- )}`
206
- );
207
- return;
208
- }
209
- if (!communicator) return;
210
- console.log("zoomToScale", { scale });
211
- communicator.zoomToScale(scale);
212
- };
213
-
214
- //***** PRINT ******/
215
- const printPaperSize = (paperSize) => {
216
- console.log("printPaperSize", communicator, paperSize);
217
- communicator.printPaperSize(paperSize);
218
- };
219
- const printPaperLayout = (paperLayout) => {
220
- communicator.printPaperLayout(paperLayout);
221
- };
222
-
223
- const startPrint = (options) => {
224
- communicator.startPrint(options);
225
- };
226
- const cancelPrint = (options) => {
227
- communicator.cancelPrint(options);
228
- };
229
-
230
- const onMapEvent = (data) => {
231
- console.log(`onMapEvent`, { type: data.type, data });
232
- setMessageQueue((prevQueue) => [...prevQueue, data]);
233
- };
234
-
235
- useEffect(() => {
236
- if (message) return;
237
- if (messageQueue.length === 0) {
238
- return;
239
- }
240
- setMessage(messageQueue[0]);
241
- setMessageQueue((prevQueue) => {
242
- return prevQueue.slice(1);
243
- });
244
- }, [messageQueue, message]);
245
-
246
- useEffect(() => {
247
- if (!communicator) return;
248
- communicator.on(MAP_EVENTS.ZOOM_CHANGE, onMapEvent);
249
- communicator.on(MAP_EVENTS.LOADED, onMapEvent);
250
- communicator.on(MAP_EVENTS.CAPABILITIES, onMapEvent);
251
- communicator.on(MAP_EVENTS.ERROR, onMapEvent);
252
- communicator.on(MAP_EVENTS.GEOLOCATION, onMapEvent);
253
- communicator.on(MAP_EVENTS.END_MEASURE, onMapEvent);
254
- communicator.on(MAP_EVENTS.START_MEASURE, onMapEvent);
255
- communicator.on(MAP_EVENTS.UNLOADED, onMapEvent);
256
- communicator.on(MAP_EVENTS.COORDINATES, onMapEvent);
257
- communicator.on(MAP_EVENTS.CENTER_CHANGE, onMapEvent);
258
- communicator.on(MAP_EVENTS.ACTIVE_LAYER, onMapEvent);
259
- communicator.on(MAP_EVENTS.WMS_LAYERS, onMapEvent);
260
- communicator.on(MAP_EVENTS.STATUS, onMapEvent);
261
- communicator.on(MAP_EVENTS.INFO, onMapEvent);
262
- communicator.on(MAP_EVENTS.GEOM_ADDED, onMapEvent);
263
- communicator.on(MAP_EVENTS.LAYERS, onMapEvent);
264
- communicator.on(MAP_EVENTS.VERSION, onMapEvent);
265
- communicator.on(MAP_EVENTS.SCREENSHOT, onMapEvent);
266
- return () => {
267
- if (!communicator) return;
268
- communicator.off(MAP_EVENTS.ZOOM_CHANGE, onMapEvent);
269
- communicator.off(MAP_EVENTS.LOADED, onMapEvent);
270
- communicator.off(MAP_EVENTS.CAPABILITIES, onMapEvent);
271
- communicator.off(MAP_EVENTS.ERROR, onMapEvent);
272
- communicator.off(MAP_EVENTS.GEOLOCATION, onMapEvent);
273
- communicator.off(MAP_EVENTS.END_MEASURE, onMapEvent);
274
- communicator.off(MAP_EVENTS.START_MEASURE, onMapEvent);
275
- communicator.off(MAP_EVENTS.UNLOADED, onMapEvent);
276
- communicator.off(MAP_EVENTS.COORDINATES, onMapEvent);
277
- communicator.off(MAP_EVENTS.CENTER_CHANGE, onMapEvent);
278
- communicator.off(MAP_EVENTS.ACTIVE_LAYER, onMapEvent);
279
- communicator.off(MAP_EVENTS.WMS_LAYERS, onMapEvent);
280
- communicator.off(MAP_EVENTS.STATUS, onMapEvent);
281
- communicator.off(MAP_EVENTS.INFO, onMapEvent);
282
- communicator.off(MAP_EVENTS.LAYERS, onMapEvent);
283
- communicator.off(MAP_EVENTS.VERSION, onMapEvent);
284
- communicator.off(MAP_EVENTS.SCREENSHOT, onMapEvent);
285
- setCommunicator(null);
286
- };
287
- }, [communicator, events]);
288
-
289
- useEffect(() => {
290
- // Clean up
291
- return function cleanup() {
292
- if (communicator) {
293
- communicator.off(MAP_EVENTS.ZOOM_CHANGE, onMapEvent);
294
- communicator.off(MAP_EVENTS.LOADED, onMapEvent);
295
- communicator.off(MAP_EVENTS.CAPABILITIES, onMapEvent);
296
- communicator.off(MAP_EVENTS.ERROR, onMapEvent);
297
- communicator.off(MAP_EVENTS.GEOLOCATION, onMapEvent);
298
- communicator.off(MAP_EVENTS.END_MEASURE, onMapEvent);
299
- communicator.off(MAP_EVENTS.START_MEASURE, onMapEvent);
300
- communicator.off(MAP_EVENTS.UNLOADED, onMapEvent);
301
- communicator.off(MAP_EVENTS.COORDINATES, onMapEvent);
302
- communicator.off(MAP_EVENTS.CENTER_CHANGE, onMapEvent);
303
- communicator.off(MAP_EVENTS.ACTIVE_LAYER, onMapEvent);
304
- communicator.off(MAP_EVENTS.WMS_LAYERS, onMapEvent);
305
- communicator.off(MAP_EVENTS.STATUS, onMapEvent);
306
- communicator.off(MAP_EVENTS.INFO, onMapEvent);
307
- communicator.off(MAP_EVENTS.VERSION, onMapEvent);
308
- }
309
- setMessage(null);
310
- setEvents(false);
311
- };
312
- }, []);
313
-
314
- return (
315
- <MessageContext.Provider
316
- value={{
317
- communicator,
318
- start,
319
- ZoomIn,
320
- ZoomOut,
321
- zoomToExtent,
322
- DrawGeometry,
323
- DrawGeometries,
324
-
325
- startDrawPolygon,
326
- CancelAddGeom,
327
- Clear,
328
- Info,
329
- RemoveElementFromMap,
330
- Highlight,
331
- RemoveGeometriesByProperty,
332
- UpdateGeometriesByProperty,
333
- ToggleLayer,
334
- message,
335
- setMessage,
336
- Filters,
337
- reloadLayers,
338
- BBoxForClicks,
339
- cancelMeasure,
340
- initMeasure,
341
- removeLayer,
342
- Geolocalize,
343
- zoomToCoordinates,
344
- zoomToGeometry,
345
- centerMap,
346
- drawPoint,
347
- addIcon,
348
- zoomToScale,
349
- printPaperSize,
350
- printPaperLayout,
351
- startPrint,
352
- cancelPrint,
353
- }}
354
- >
355
- {children}
356
- </MessageContext.Provider>
357
- );
358
- };
359
-
360
- export const useMessages = () => useContext(MessageContext);
@@ -1,51 +0,0 @@
1
- "use client";
2
- import { createContext, useContext, useState, useEffect } from "react";
3
- import { useMessages } from "./messages";
4
-
5
- const PrintsContext = createContext({});
6
-
7
- export const PrintsProvider = ({ children }) => {
8
- const [paperSize, setPaperSize] = useState(null);
9
- const [paperLayout, setPaperLayout] = useState(null);
10
- const {
11
- printPaperSize,
12
- printPaperLayout,
13
- startPrint: startPrintMessages,
14
- } = useMessages();
15
-
16
- useEffect(() => {
17
- if (!paperLayout) return;
18
- console.log("set paperLayout", paperLayout);
19
- printPaperLayout(paperLayout);
20
- }, [paperLayout]);
21
-
22
- useEffect(() => {
23
- if (!paperSize) return;
24
- console.log("set paperSize", paperSize);
25
- printPaperSize(paperSize);
26
- }, [paperSize]);
27
-
28
- const startPrint = () => {
29
- console.log("Start print");
30
- startPrintMessages({
31
- paperLayout: paperLayout ? paperLayout : "landscape",
32
- paperSize: paperSize ? paperSize : "A4",
33
- });
34
- };
35
-
36
- return (
37
- <PrintsContext.Provider
38
- value={{
39
- paperLayout,
40
- setPaperLayout,
41
- paperSize,
42
- setPaperSize,
43
- startPrint,
44
- }}
45
- >
46
- {children}
47
- </PrintsContext.Provider>
48
- );
49
- };
50
-
51
- export const usePrint = () => useContext(PrintsContext);
@@ -1,3 +0,0 @@
1
- NEXT_PUBLIC_APIURL="https://your api url"
2
- NEXT_PUBLIC_USER="your user"
3
- NEXT_PUBLIC_PWD="your password"
@@ -1,14 +0,0 @@
1
- import { dirname } from "path";
2
- import { fileURLToPath } from "url";
3
- import { FlatCompat } from "@eslint/eslintrc";
4
-
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = dirname(__filename);
7
-
8
- const compat = new FlatCompat({
9
- baseDirectory: __dirname,
10
- });
11
-
12
- const eslintConfig = [...compat.extends("next/core-web-vitals")];
13
-
14
- export default eslintConfig;