@mapfirst.ai/react 0.0.45 → 0.0.46
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/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +82 -71
- package/dist/index.mjs +82 -71
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -238,8 +238,8 @@ type SmartFilter = {
|
|
|
238
238
|
* ```
|
|
239
239
|
*/
|
|
240
240
|
declare function useMapFirst(options: BaseMapFirstOptions): {
|
|
241
|
-
instance: MapFirstCore
|
|
242
|
-
state: MapState
|
|
241
|
+
instance: MapFirstCore;
|
|
242
|
+
state: MapState;
|
|
243
243
|
setPrimaryType: (type: PropertyType) => void;
|
|
244
244
|
setSelectedMarker: (id: number | null) => void;
|
|
245
245
|
setUseApi: (useApi: boolean, autoLoad?: boolean) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -238,8 +238,8 @@ type SmartFilter = {
|
|
|
238
238
|
* ```
|
|
239
239
|
*/
|
|
240
240
|
declare function useMapFirst(options: BaseMapFirstOptions): {
|
|
241
|
-
instance: MapFirstCore
|
|
242
|
-
state: MapState
|
|
241
|
+
instance: MapFirstCore;
|
|
242
|
+
state: MapState;
|
|
243
243
|
setPrimaryType: (type: PropertyType) => void;
|
|
244
244
|
setSelectedMarker: (id: number | null) => void;
|
|
245
245
|
setUseApi: (useApi: boolean, autoLoad?: boolean) => void;
|
package/dist/index.js
CHANGED
|
@@ -1376,9 +1376,6 @@ var SmartFilter = ({
|
|
|
1376
1376
|
};
|
|
1377
1377
|
|
|
1378
1378
|
// src/index.tsx
|
|
1379
|
-
function updateStateField(setState, key, value) {
|
|
1380
|
-
setState((prev) => prev ? { ...prev, [key]: value } : null);
|
|
1381
|
-
}
|
|
1382
1379
|
function forwardCallback(optionsRef, key, ...args) {
|
|
1383
1380
|
var _a;
|
|
1384
1381
|
const callback = (_a = optionsRef.current.callbacks) == null ? void 0 : _a[key];
|
|
@@ -1392,82 +1389,96 @@ function attachMapOnce(instanceRef, attachedRef, map, config) {
|
|
|
1392
1389
|
attachedRef.current = true;
|
|
1393
1390
|
}
|
|
1394
1391
|
function useMapFirst(options) {
|
|
1395
|
-
const instanceRef = import_react9.default.useRef(null);
|
|
1396
|
-
const [state, setState] = import_react9.default.useState(null);
|
|
1397
1392
|
const optionsRef = import_react9.default.useRef(options);
|
|
1398
1393
|
import_react9.default.useEffect(() => {
|
|
1399
1394
|
optionsRef.current = options;
|
|
1400
1395
|
});
|
|
1401
|
-
import_react9.default.
|
|
1402
|
-
|
|
1403
|
-
|
|
1396
|
+
const callbacksRef = import_react9.default.useRef({});
|
|
1397
|
+
const instanceRef = import_react9.default.useRef(null);
|
|
1398
|
+
if (instanceRef.current === null) {
|
|
1399
|
+
instanceRef.current = new import_core.MapFirstCore({
|
|
1404
1400
|
adapter: null,
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1401
|
+
...optionsRef.current,
|
|
1402
|
+
callbacks: callbacksRef.current
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
const [state, setState] = import_react9.default.useState(
|
|
1406
|
+
() => instanceRef.current.getState()
|
|
1407
|
+
);
|
|
1408
|
+
import_react9.default.useEffect(() => {
|
|
1409
|
+
if (!instanceRef.current) {
|
|
1410
|
+
callbacksRef.current = {};
|
|
1411
|
+
instanceRef.current = new import_core.MapFirstCore({
|
|
1412
|
+
adapter: null,
|
|
1413
|
+
...optionsRef.current,
|
|
1414
|
+
callbacks: callbacksRef.current
|
|
1415
|
+
});
|
|
1416
|
+
setState(instanceRef.current.getState());
|
|
1417
|
+
mapLibreAttachedRef.current = false;
|
|
1418
|
+
googleMapsAttachedRef.current = false;
|
|
1419
|
+
mapboxAttachedRef.current = false;
|
|
1420
|
+
}
|
|
1421
|
+
const cb = callbacksRef.current;
|
|
1422
|
+
cb.onPropertiesChange = (properties) => {
|
|
1423
|
+
setState((prev) => ({ ...prev, properties }));
|
|
1424
|
+
forwardCallback(optionsRef, "onPropertiesChange", properties);
|
|
1425
|
+
};
|
|
1426
|
+
cb.onSelectedPropertyChange = (id) => {
|
|
1427
|
+
setState((prev) => ({ ...prev, selectedPropertyId: id }));
|
|
1428
|
+
forwardCallback(optionsRef, "onSelectedPropertyChange", id);
|
|
1429
|
+
};
|
|
1430
|
+
cb.onPrimaryTypeChange = (type) => {
|
|
1431
|
+
setState((prev) => ({ ...prev, primary: type }));
|
|
1432
|
+
forwardCallback(optionsRef, "onPrimaryTypeChange", type);
|
|
1433
|
+
};
|
|
1434
|
+
cb.onFiltersChange = (filters) => {
|
|
1435
|
+
setState((prev) => ({ ...prev, filters }));
|
|
1436
|
+
forwardCallback(optionsRef, "onFiltersChange", filters);
|
|
1437
|
+
};
|
|
1438
|
+
cb.onBoundsChange = (bounds) => {
|
|
1439
|
+
setState((prev) => ({ ...prev, bounds }));
|
|
1440
|
+
forwardCallback(optionsRef, "onBoundsChange", bounds);
|
|
1441
|
+
};
|
|
1442
|
+
cb.onPendingBoundsChange = (pendingBounds) => {
|
|
1443
|
+
setState((prev) => ({ ...prev, pendingBounds }));
|
|
1444
|
+
forwardCallback(optionsRef, "onPendingBoundsChange", pendingBounds);
|
|
1445
|
+
};
|
|
1446
|
+
cb.onCenterChange = (center, zoom) => {
|
|
1447
|
+
setState((prev) => ({ ...prev, center, zoom }));
|
|
1448
|
+
forwardCallback(optionsRef, "onCenterChange", center, zoom);
|
|
1449
|
+
};
|
|
1450
|
+
cb.onZoomChange = (zoom) => {
|
|
1451
|
+
setState((prev) => ({ ...prev, zoom }));
|
|
1452
|
+
forwardCallback(optionsRef, "onZoomChange", zoom);
|
|
1453
|
+
};
|
|
1454
|
+
cb.onActiveLocationChange = (location) => {
|
|
1455
|
+
setState((prev) => ({ ...prev, activeLocation: location }));
|
|
1456
|
+
forwardCallback(optionsRef, "onActiveLocationChange", location);
|
|
1457
|
+
};
|
|
1458
|
+
cb.onLoadingStateChange = (loading) => {
|
|
1459
|
+
setState((prev) => ({ ...prev, initialLoading: loading }));
|
|
1460
|
+
forwardCallback(optionsRef, "onLoadingStateChange", loading);
|
|
1461
|
+
};
|
|
1462
|
+
cb.onSearchingStateChange = (searching) => {
|
|
1463
|
+
setState((prev) => ({ ...prev, isSearching: searching }));
|
|
1464
|
+
forwardCallback(optionsRef, "onSearchingStateChange", searching);
|
|
1465
|
+
};
|
|
1466
|
+
cb.onFirstCallDoneChange = (firstCallDone) => {
|
|
1467
|
+
setState((prev) => ({ ...prev, firstCallDone }));
|
|
1468
|
+
forwardCallback(optionsRef, "onFirstCallDoneChange", firstCallDone);
|
|
1469
|
+
};
|
|
1470
|
+
cb.onIsFlyToAnimatingChange = (animating) => {
|
|
1471
|
+
setState((prev) => ({ ...prev, isFlyToAnimating: animating }));
|
|
1472
|
+
forwardCallback(optionsRef, "onIsFlyToAnimatingChange", animating);
|
|
1463
1473
|
};
|
|
1464
|
-
const instance = new import_core.MapFirstCore(coreOptions);
|
|
1465
|
-
instanceRef.current = instance;
|
|
1466
|
-
setState(instance.getState());
|
|
1467
1474
|
return () => {
|
|
1468
|
-
|
|
1475
|
+
var _a;
|
|
1476
|
+
const existingCb = callbacksRef.current;
|
|
1477
|
+
Object.keys(existingCb).forEach(
|
|
1478
|
+
(k) => delete existingCb[k]
|
|
1479
|
+
);
|
|
1480
|
+
(_a = instanceRef.current) == null ? void 0 : _a.destroy();
|
|
1469
1481
|
instanceRef.current = null;
|
|
1470
|
-
setState(null);
|
|
1471
1482
|
};
|
|
1472
1483
|
}, []);
|
|
1473
1484
|
const setPrimaryType = import_react9.default.useCallback((type) => {
|
package/dist/index.mjs
CHANGED
|
@@ -1336,9 +1336,6 @@ var SmartFilter = ({
|
|
|
1336
1336
|
};
|
|
1337
1337
|
|
|
1338
1338
|
// src/index.tsx
|
|
1339
|
-
function updateStateField(setState, key, value) {
|
|
1340
|
-
setState((prev) => prev ? { ...prev, [key]: value } : null);
|
|
1341
|
-
}
|
|
1342
1339
|
function forwardCallback(optionsRef, key, ...args) {
|
|
1343
1340
|
var _a;
|
|
1344
1341
|
const callback = (_a = optionsRef.current.callbacks) == null ? void 0 : _a[key];
|
|
@@ -1352,82 +1349,96 @@ function attachMapOnce(instanceRef, attachedRef, map, config) {
|
|
|
1352
1349
|
attachedRef.current = true;
|
|
1353
1350
|
}
|
|
1354
1351
|
function useMapFirst(options) {
|
|
1355
|
-
const instanceRef = React6.useRef(null);
|
|
1356
|
-
const [state, setState] = React6.useState(null);
|
|
1357
1352
|
const optionsRef = React6.useRef(options);
|
|
1358
1353
|
React6.useEffect(() => {
|
|
1359
1354
|
optionsRef.current = options;
|
|
1360
1355
|
});
|
|
1361
|
-
React6.
|
|
1362
|
-
|
|
1363
|
-
|
|
1356
|
+
const callbacksRef = React6.useRef({});
|
|
1357
|
+
const instanceRef = React6.useRef(null);
|
|
1358
|
+
if (instanceRef.current === null) {
|
|
1359
|
+
instanceRef.current = new MapFirstCore({
|
|
1364
1360
|
adapter: null,
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1361
|
+
...optionsRef.current,
|
|
1362
|
+
callbacks: callbacksRef.current
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
const [state, setState] = React6.useState(
|
|
1366
|
+
() => instanceRef.current.getState()
|
|
1367
|
+
);
|
|
1368
|
+
React6.useEffect(() => {
|
|
1369
|
+
if (!instanceRef.current) {
|
|
1370
|
+
callbacksRef.current = {};
|
|
1371
|
+
instanceRef.current = new MapFirstCore({
|
|
1372
|
+
adapter: null,
|
|
1373
|
+
...optionsRef.current,
|
|
1374
|
+
callbacks: callbacksRef.current
|
|
1375
|
+
});
|
|
1376
|
+
setState(instanceRef.current.getState());
|
|
1377
|
+
mapLibreAttachedRef.current = false;
|
|
1378
|
+
googleMapsAttachedRef.current = false;
|
|
1379
|
+
mapboxAttachedRef.current = false;
|
|
1380
|
+
}
|
|
1381
|
+
const cb = callbacksRef.current;
|
|
1382
|
+
cb.onPropertiesChange = (properties) => {
|
|
1383
|
+
setState((prev) => ({ ...prev, properties }));
|
|
1384
|
+
forwardCallback(optionsRef, "onPropertiesChange", properties);
|
|
1385
|
+
};
|
|
1386
|
+
cb.onSelectedPropertyChange = (id) => {
|
|
1387
|
+
setState((prev) => ({ ...prev, selectedPropertyId: id }));
|
|
1388
|
+
forwardCallback(optionsRef, "onSelectedPropertyChange", id);
|
|
1389
|
+
};
|
|
1390
|
+
cb.onPrimaryTypeChange = (type) => {
|
|
1391
|
+
setState((prev) => ({ ...prev, primary: type }));
|
|
1392
|
+
forwardCallback(optionsRef, "onPrimaryTypeChange", type);
|
|
1393
|
+
};
|
|
1394
|
+
cb.onFiltersChange = (filters) => {
|
|
1395
|
+
setState((prev) => ({ ...prev, filters }));
|
|
1396
|
+
forwardCallback(optionsRef, "onFiltersChange", filters);
|
|
1397
|
+
};
|
|
1398
|
+
cb.onBoundsChange = (bounds) => {
|
|
1399
|
+
setState((prev) => ({ ...prev, bounds }));
|
|
1400
|
+
forwardCallback(optionsRef, "onBoundsChange", bounds);
|
|
1401
|
+
};
|
|
1402
|
+
cb.onPendingBoundsChange = (pendingBounds) => {
|
|
1403
|
+
setState((prev) => ({ ...prev, pendingBounds }));
|
|
1404
|
+
forwardCallback(optionsRef, "onPendingBoundsChange", pendingBounds);
|
|
1405
|
+
};
|
|
1406
|
+
cb.onCenterChange = (center, zoom) => {
|
|
1407
|
+
setState((prev) => ({ ...prev, center, zoom }));
|
|
1408
|
+
forwardCallback(optionsRef, "onCenterChange", center, zoom);
|
|
1409
|
+
};
|
|
1410
|
+
cb.onZoomChange = (zoom) => {
|
|
1411
|
+
setState((prev) => ({ ...prev, zoom }));
|
|
1412
|
+
forwardCallback(optionsRef, "onZoomChange", zoom);
|
|
1413
|
+
};
|
|
1414
|
+
cb.onActiveLocationChange = (location) => {
|
|
1415
|
+
setState((prev) => ({ ...prev, activeLocation: location }));
|
|
1416
|
+
forwardCallback(optionsRef, "onActiveLocationChange", location);
|
|
1417
|
+
};
|
|
1418
|
+
cb.onLoadingStateChange = (loading) => {
|
|
1419
|
+
setState((prev) => ({ ...prev, initialLoading: loading }));
|
|
1420
|
+
forwardCallback(optionsRef, "onLoadingStateChange", loading);
|
|
1421
|
+
};
|
|
1422
|
+
cb.onSearchingStateChange = (searching) => {
|
|
1423
|
+
setState((prev) => ({ ...prev, isSearching: searching }));
|
|
1424
|
+
forwardCallback(optionsRef, "onSearchingStateChange", searching);
|
|
1425
|
+
};
|
|
1426
|
+
cb.onFirstCallDoneChange = (firstCallDone) => {
|
|
1427
|
+
setState((prev) => ({ ...prev, firstCallDone }));
|
|
1428
|
+
forwardCallback(optionsRef, "onFirstCallDoneChange", firstCallDone);
|
|
1429
|
+
};
|
|
1430
|
+
cb.onIsFlyToAnimatingChange = (animating) => {
|
|
1431
|
+
setState((prev) => ({ ...prev, isFlyToAnimating: animating }));
|
|
1432
|
+
forwardCallback(optionsRef, "onIsFlyToAnimatingChange", animating);
|
|
1423
1433
|
};
|
|
1424
|
-
const instance = new MapFirstCore(coreOptions);
|
|
1425
|
-
instanceRef.current = instance;
|
|
1426
|
-
setState(instance.getState());
|
|
1427
1434
|
return () => {
|
|
1428
|
-
|
|
1435
|
+
var _a;
|
|
1436
|
+
const existingCb = callbacksRef.current;
|
|
1437
|
+
Object.keys(existingCb).forEach(
|
|
1438
|
+
(k) => delete existingCb[k]
|
|
1439
|
+
);
|
|
1440
|
+
(_a = instanceRef.current) == null ? void 0 : _a.destroy();
|
|
1429
1441
|
instanceRef.current = null;
|
|
1430
|
-
setState(null);
|
|
1431
1442
|
};
|
|
1432
1443
|
}, []);
|
|
1433
1444
|
const setPrimaryType = React6.useCallback((type) => {
|