@octostar/map-component 0.3.1 → 0.3.2
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.cjs +83 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +84 -23
- package/dist/index.mjs.map +1 -1
- package/dist/types/components/timebar.d.ts +23 -3
- package/dist/types/components/timebar.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/timeline-store.d.ts +12 -2
- package/dist/types/lib/timeline-store.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { twMerge } from "tailwind-merge";
|
|
|
12
12
|
import { MousePointer2, Square, Hexagon, Circle, MoreVertical, ChevronDown, Filter, X, Move, Ruler, Search, Scan, Pencil, Database, MapPin, Minus, Pentagon, Type, MoveRight, Undo2, Redo2, Trash2, Navigation, Loader2, Map as Map$1, Satellite, FolderOpen, Upload, Download, MoreHorizontal, Focus, Box, Layers, Plus, ChevronRight, Eye, EyeOff, Lock, Smile, Package, Copy, FolderInput, Save, Calendar, Palette, Blend, RefreshCw, ExternalLink, Info, SkipBack, Pause, Play, Clock, AlertTriangle, TestTube, Users, GripVertical, Plane, FileJson, Check, Phone, Car, AlertCircle } from "lucide-react";
|
|
13
13
|
import { createPortal } from "react-dom";
|
|
14
14
|
import { format } from "date-fns";
|
|
15
|
-
import {
|
|
15
|
+
import { createStore, useStore } from "zustand";
|
|
16
16
|
import Flatbush from "flatbush";
|
|
17
17
|
import dayjs from "dayjs";
|
|
18
18
|
import * as toGeoJSON from "@mapbox/togeojson";
|
|
@@ -6963,6 +6963,7 @@ const timelineStoreInitializer = (set2, get) => ({
|
|
|
6963
6963
|
rangeEnd: null,
|
|
6964
6964
|
isPlaying: false,
|
|
6965
6965
|
playbackSpeed: 1,
|
|
6966
|
+
playMode: "sliding",
|
|
6966
6967
|
histogramBins: [],
|
|
6967
6968
|
setEnabled: (enabled) => {
|
|
6968
6969
|
if (enabled) {
|
|
@@ -7004,10 +7005,14 @@ const timelineStoreInitializer = (set2, get) => ({
|
|
|
7004
7005
|
});
|
|
7005
7006
|
const computedMin = minDate;
|
|
7006
7007
|
const computedMax = maxDate;
|
|
7007
|
-
const
|
|
7008
|
+
const sameFeatures = state.temporalFeatures.length === timedFeatures.length && timedFeatures.every((f, i) => {
|
|
7009
|
+
var _a2, _b2, _c, _d;
|
|
7010
|
+
const prev = state.temporalFeatures[i];
|
|
7011
|
+
return f.id === prev.id && ((_a2 = f.startDate) == null ? void 0 : _a2.getTime()) === ((_b2 = prev.startDate) == null ? void 0 : _b2.getTime()) && ((_c = f.endDate) == null ? void 0 : _c.getTime()) === ((_d = prev.endDate) == null ? void 0 : _d.getTime());
|
|
7012
|
+
});
|
|
7008
7013
|
const sameDates = ((_a = state.globalMinDate) == null ? void 0 : _a.getTime()) === (computedMin == null ? void 0 : computedMin.getTime()) && ((_b = state.globalMaxDate) == null ? void 0 : _b.getTime()) === (computedMax == null ? void 0 : computedMax.getTime());
|
|
7009
7014
|
const sameUntimed = state.untimedFeatureIds.length === untimedIds.length && untimedIds.every((id, i) => id === state.untimedFeatureIds[i]);
|
|
7010
|
-
if (
|
|
7015
|
+
if (sameFeatures && sameDates && sameUntimed && state.hasTemporalData) return;
|
|
7011
7016
|
const histogramBins = minDate && maxDate ? computeHistogramBins(timedFeatures, minDate, maxDate) : [];
|
|
7012
7017
|
set2({
|
|
7013
7018
|
hasTemporalData: true,
|
|
@@ -7023,6 +7028,7 @@ const timelineStoreInitializer = (set2, get) => ({
|
|
|
7023
7028
|
setRange: (start, end) => set2({ rangeStart: start, rangeEnd: end }),
|
|
7024
7029
|
setPlaying: (playing) => set2({ isPlaying: playing }),
|
|
7025
7030
|
setPlaybackSpeed: (speed) => set2({ playbackSpeed: speed }),
|
|
7031
|
+
setPlayMode: (mode) => set2({ playMode: mode }),
|
|
7026
7032
|
advancePlayhead: () => {
|
|
7027
7033
|
const state = get();
|
|
7028
7034
|
if (!state.globalMinDate || !state.globalMaxDate || !state.rangeStart) {
|
|
@@ -7066,7 +7072,7 @@ const TimelineStoreContext = createContext(null);
|
|
|
7066
7072
|
function useTimelineStoreApi() {
|
|
7067
7073
|
const store = useContext(TimelineStoreContext);
|
|
7068
7074
|
if (!store) {
|
|
7069
|
-
throw new Error("useTimelineStoreApi must be used within a MapEditorCanvas
|
|
7075
|
+
throw new Error("useTimelineStoreApi must be used within a MapEditorCanvas or a TimelineStoreContext.Provider");
|
|
7070
7076
|
}
|
|
7071
7077
|
return store;
|
|
7072
7078
|
}
|
|
@@ -7078,6 +7084,12 @@ function useTimelineStore(selector) {
|
|
|
7078
7084
|
}
|
|
7079
7085
|
const TIMEBAR_HEIGHT = 158;
|
|
7080
7086
|
const TIMEBAR_BOTTOM_OFFSET = 12;
|
|
7087
|
+
const DEFAULT_LABELS = {
|
|
7088
|
+
play: "Play",
|
|
7089
|
+
pause: "Pause",
|
|
7090
|
+
reset: "Reset timeline",
|
|
7091
|
+
cumulative: "Cumulative: keep what has appeared"
|
|
7092
|
+
};
|
|
7081
7093
|
const MINUTE_MS = 6e4;
|
|
7082
7094
|
const HOUR_MS = 36e5;
|
|
7083
7095
|
const DAY_MS = 864e5;
|
|
@@ -7226,7 +7238,7 @@ function Histogram({ bins, maxCount, colorGroupedBins }) {
|
|
|
7226
7238
|
const containerRef = useRef(null);
|
|
7227
7239
|
if (bins.length === 0 || maxCount === 0) return null;
|
|
7228
7240
|
const hasColorGroups = colorGroupedBins && colorGroupedBins.length > 0 && colorGroupedBins.some((group) => group.bins.some((count) => count > 0));
|
|
7229
|
-
return /* @__PURE__ */ jsxs("div", { className: "relative h-16", ref: containerRef, children: [
|
|
7241
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative h-16", ref: containerRef, "data-testid": "timebar-histogram", children: [
|
|
7230
7242
|
/* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-end gap-px", children: bins.map((bin, i) => {
|
|
7231
7243
|
const height = bin.count / maxCount * 100;
|
|
7232
7244
|
const isHovered = hoveredBin === i;
|
|
@@ -7301,7 +7313,17 @@ function TimebarToggle({ onClick, hasData }) {
|
|
|
7301
7313
|
}
|
|
7302
7314
|
);
|
|
7303
7315
|
}
|
|
7304
|
-
function Timebar({
|
|
7316
|
+
function Timebar({
|
|
7317
|
+
onFilterChange,
|
|
7318
|
+
selectedFeatureIds = [],
|
|
7319
|
+
selectedFeatureColors,
|
|
7320
|
+
selectionDisplay = "bars",
|
|
7321
|
+
className,
|
|
7322
|
+
timebarExtra,
|
|
7323
|
+
formatCount: formatCount2,
|
|
7324
|
+
labels: labelOverrides
|
|
7325
|
+
}) {
|
|
7326
|
+
const labels = { ...DEFAULT_LABELS, ...labelOverrides };
|
|
7305
7327
|
const {
|
|
7306
7328
|
isEnabled,
|
|
7307
7329
|
hasTemporalData,
|
|
@@ -7312,19 +7334,22 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
|
|
|
7312
7334
|
rangeStart,
|
|
7313
7335
|
rangeEnd,
|
|
7314
7336
|
isPlaying,
|
|
7337
|
+
playMode,
|
|
7315
7338
|
histogramBins: storeHistogramBins,
|
|
7316
7339
|
setRange,
|
|
7317
|
-
setPlaying
|
|
7340
|
+
setPlaying,
|
|
7341
|
+
setPlayMode
|
|
7318
7342
|
} = useTimelineStore();
|
|
7319
7343
|
const timelineStoreApi = useTimelineStoreApi();
|
|
7320
7344
|
const hasSelection = selectedFeatureIds.length > 0;
|
|
7345
|
+
const selectionAsLine = hasSelection && selectionDisplay === "line";
|
|
7321
7346
|
const selectedTemporalFeatures = useMemo(() => {
|
|
7322
7347
|
if (!hasSelection) return temporalFeatures;
|
|
7323
7348
|
const selectedSet = new Set(selectedFeatureIds);
|
|
7324
7349
|
return temporalFeatures.filter((f) => selectedSet.has(f.id));
|
|
7325
7350
|
}, [hasSelection, selectedFeatureIds, temporalFeatures]);
|
|
7326
7351
|
const histogramBins = useMemo(() => {
|
|
7327
|
-
if (!hasSelection || storeHistogramBins.length === 0) return storeHistogramBins;
|
|
7352
|
+
if (!hasSelection || selectionAsLine || storeHistogramBins.length === 0) return storeHistogramBins;
|
|
7328
7353
|
return storeHistogramBins.map((bin, binIndex) => {
|
|
7329
7354
|
const isLastBin = binIndex === storeHistogramBins.length - 1;
|
|
7330
7355
|
let count = 0;
|
|
@@ -7337,16 +7362,16 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
|
|
|
7337
7362
|
}
|
|
7338
7363
|
return { ...bin, count };
|
|
7339
7364
|
});
|
|
7340
|
-
}, [hasSelection, storeHistogramBins, selectedTemporalFeatures]);
|
|
7341
|
-
const colorGroupedBins = histogramBins.length > 0 && hasSelection && selectedFeatureColors && selectedFeatureColors.size > 0 && globalMinDate && globalMaxDate ? (() => {
|
|
7365
|
+
}, [hasSelection, selectionAsLine, storeHistogramBins, selectedTemporalFeatures]);
|
|
7366
|
+
const colorGroupedBins = histogramBins.length > 0 && hasSelection && (selectionAsLine || selectedFeatureColors && selectedFeatureColors.size > 0) && globalMinDate && globalMaxDate ? (() => {
|
|
7342
7367
|
if (selectedTemporalFeatures.length === 0) return [];
|
|
7343
7368
|
const colorGroups = /* @__PURE__ */ new Map();
|
|
7344
7369
|
selectedTemporalFeatures.forEach((f) => {
|
|
7345
|
-
const color = selectedFeatureColors.get(f.id) || "#3b82f6";
|
|
7370
|
+
const color = (selectedFeatureColors == null ? void 0 : selectedFeatureColors.get(f.id)) || "#3b82f6";
|
|
7346
7371
|
if (!colorGroups.has(color)) colorGroups.set(color, []);
|
|
7347
7372
|
colorGroups.get(color).push(f);
|
|
7348
7373
|
});
|
|
7349
|
-
if (colorGroups.size <= 1) return [];
|
|
7374
|
+
if (!selectionAsLine && colorGroups.size <= 1) return [];
|
|
7350
7375
|
const result = [];
|
|
7351
7376
|
colorGroups.forEach((features, color) => {
|
|
7352
7377
|
const bins = histogramBins.map((bin, binIndex) => {
|
|
@@ -7405,14 +7430,24 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
|
|
|
7405
7430
|
setPlaying(false);
|
|
7406
7431
|
return;
|
|
7407
7432
|
}
|
|
7408
|
-
|
|
7409
|
-
|
|
7410
|
-
|
|
7411
|
-
|
|
7412
|
-
|
|
7413
|
-
|
|
7433
|
+
if (state.playMode === "cumulative") {
|
|
7434
|
+
const grown = new Date((state.rangeEnd ?? state.rangeStart).getTime() + stepPerFrame);
|
|
7435
|
+
if (grown >= state.globalMaxDate) {
|
|
7436
|
+
setRange(state.rangeStart, state.globalMaxDate);
|
|
7437
|
+
setPlaying(false);
|
|
7438
|
+
return;
|
|
7439
|
+
}
|
|
7440
|
+
setRange(state.rangeStart, grown);
|
|
7441
|
+
} else {
|
|
7442
|
+
const newStart = new Date(state.rangeStart.getTime() + stepPerFrame);
|
|
7443
|
+
const newEnd = state.rangeEnd ? new Date(state.rangeEnd.getTime() + stepPerFrame) : null;
|
|
7444
|
+
if (newStart >= state.globalMaxDate) {
|
|
7445
|
+
setRange(state.globalMinDate, state.globalMaxDate);
|
|
7446
|
+
setPlaying(false);
|
|
7447
|
+
return;
|
|
7448
|
+
}
|
|
7449
|
+
setRange(newStart, newEnd && newEnd <= state.globalMaxDate ? newEnd : state.globalMaxDate);
|
|
7414
7450
|
}
|
|
7415
|
-
setRange(newStart, newEnd && newEnd <= state.globalMaxDate ? newEnd : state.globalMaxDate);
|
|
7416
7451
|
}
|
|
7417
7452
|
animationFrameRef.current = requestAnimationFrame(animate);
|
|
7418
7453
|
};
|
|
@@ -7443,11 +7478,17 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
|
|
|
7443
7478
|
setPlaying(false);
|
|
7444
7479
|
};
|
|
7445
7480
|
const handlePlayPause = () => {
|
|
7446
|
-
if (!isPlaying &&
|
|
7481
|
+
if (!isPlaying && playMode === "cumulative") {
|
|
7482
|
+
if (!rangeEnd || rangeEnd >= globalMaxDate) {
|
|
7483
|
+
const from = rangeStart && rangeStart < globalMaxDate ? rangeStart : globalMinDate;
|
|
7484
|
+
setRange(from, from);
|
|
7485
|
+
}
|
|
7486
|
+
} else if (!isPlaying && rangeStart && rangeStart >= globalMaxDate) {
|
|
7447
7487
|
setRange(globalMinDate, globalMaxDate);
|
|
7448
7488
|
}
|
|
7449
7489
|
setPlaying(!isPlaying);
|
|
7450
7490
|
};
|
|
7491
|
+
const cumulative = playMode === "cumulative";
|
|
7451
7492
|
return /* @__PURE__ */ jsxs(
|
|
7452
7493
|
"div",
|
|
7453
7494
|
{
|
|
@@ -7495,7 +7536,7 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
|
|
|
7495
7536
|
size: "small",
|
|
7496
7537
|
icon: /* @__PURE__ */ jsx(SkipBack, { className: "w-3.5 h-3.5" }),
|
|
7497
7538
|
onClick: handleReset,
|
|
7498
|
-
"aria-label":
|
|
7539
|
+
"aria-label": labels.reset,
|
|
7499
7540
|
"data-testid": "button-timeline-reset",
|
|
7500
7541
|
className: "!h-7 !w-7 !p-0 !min-w-0"
|
|
7501
7542
|
}
|
|
@@ -7507,17 +7548,34 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
|
|
|
7507
7548
|
size: "small",
|
|
7508
7549
|
icon: isPlaying ? /* @__PURE__ */ jsx(Pause, { className: "w-3.5 h-3.5" }) : /* @__PURE__ */ jsx(Play, { className: "w-3.5 h-3.5" }),
|
|
7509
7550
|
onClick: handlePlayPause,
|
|
7510
|
-
"aria-label": isPlaying ?
|
|
7551
|
+
"aria-label": isPlaying ? labels.pause : labels.play,
|
|
7511
7552
|
"data-testid": "button-timeline-play",
|
|
7512
7553
|
className: "!h-7 !w-7 !p-0 !min-w-0"
|
|
7513
7554
|
}
|
|
7514
7555
|
),
|
|
7556
|
+
/* @__PURE__ */ jsx(Tooltip, { title: labels.cumulative, children: /* @__PURE__ */ jsx(
|
|
7557
|
+
Button,
|
|
7558
|
+
{
|
|
7559
|
+
size: "small",
|
|
7560
|
+
color: cumulative ? "primary" : "default",
|
|
7561
|
+
variant: cumulative ? "filled" : "text",
|
|
7562
|
+
icon: /* @__PURE__ */ jsx(Layers, { className: "w-3.5 h-3.5" }),
|
|
7563
|
+
onClick: () => setPlayMode(cumulative ? "sliding" : "cumulative"),
|
|
7564
|
+
"aria-label": labels.cumulative,
|
|
7565
|
+
"aria-pressed": cumulative,
|
|
7566
|
+
"data-testid": "button-timeline-cumulative",
|
|
7567
|
+
className: "!h-7 !w-7 !p-0 !min-w-0"
|
|
7568
|
+
}
|
|
7569
|
+
) }),
|
|
7515
7570
|
/* @__PURE__ */ jsx(
|
|
7516
7571
|
"span",
|
|
7517
7572
|
{
|
|
7518
7573
|
className: "text-xs text-muted-foreground ml-1",
|
|
7519
7574
|
"data-testid": "text-timeline-feature-count",
|
|
7520
|
-
children:
|
|
7575
|
+
children: formatCount2 ? formatCount2({
|
|
7576
|
+
total: temporalFeatures.length,
|
|
7577
|
+
selected: hasSelection ? selectedTemporalFeatures.length : null
|
|
7578
|
+
}) : hasSelection ? `${selectedTemporalFeatures.length} of ${temporalFeatures.length} selected` : `${temporalFeatures.length} feature${temporalFeatures.length !== 1 ? "s" : ""}`
|
|
7521
7579
|
}
|
|
7522
7580
|
)
|
|
7523
7581
|
] }),
|
|
@@ -17407,8 +17465,10 @@ export {
|
|
|
17407
17465
|
TIMEBAR_HEIGHT,
|
|
17408
17466
|
Timebar,
|
|
17409
17467
|
TimebarToggle,
|
|
17468
|
+
TimelineStoreContext,
|
|
17410
17469
|
cn,
|
|
17411
17470
|
createClusterPieManager,
|
|
17471
|
+
createTimelineStore,
|
|
17412
17472
|
featureCollectionBlobPartsAsync,
|
|
17413
17473
|
getIconEmoji,
|
|
17414
17474
|
isFeatureInRange,
|
|
@@ -17418,6 +17478,7 @@ export {
|
|
|
17418
17478
|
parseKMLToGeoJSON,
|
|
17419
17479
|
useToast as toast,
|
|
17420
17480
|
useTimelineStore,
|
|
17481
|
+
useTimelineStoreApi,
|
|
17421
17482
|
useToast
|
|
17422
17483
|
};
|
|
17423
17484
|
//# sourceMappingURL=index.mjs.map
|