@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 CHANGED
@@ -6983,6 +6983,7 @@ const timelineStoreInitializer = (set2, get) => ({
6983
6983
  rangeEnd: null,
6984
6984
  isPlaying: false,
6985
6985
  playbackSpeed: 1,
6986
+ playMode: "sliding",
6986
6987
  histogramBins: [],
6987
6988
  setEnabled: (enabled) => {
6988
6989
  if (enabled) {
@@ -7024,10 +7025,14 @@ const timelineStoreInitializer = (set2, get) => ({
7024
7025
  });
7025
7026
  const computedMin = minDate;
7026
7027
  const computedMax = maxDate;
7027
- const sameFeatureIds = state.temporalFeatures.length === timedFeatures.length && timedFeatures.every((f, i) => f.id === state.temporalFeatures[i].id);
7028
+ const sameFeatures = state.temporalFeatures.length === timedFeatures.length && timedFeatures.every((f, i) => {
7029
+ var _a2, _b2, _c, _d;
7030
+ const prev = state.temporalFeatures[i];
7031
+ 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());
7032
+ });
7028
7033
  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());
7029
7034
  const sameUntimed = state.untimedFeatureIds.length === untimedIds.length && untimedIds.every((id, i) => id === state.untimedFeatureIds[i]);
7030
- if (sameFeatureIds && sameDates && sameUntimed && state.hasTemporalData) return;
7035
+ if (sameFeatures && sameDates && sameUntimed && state.hasTemporalData) return;
7031
7036
  const histogramBins = minDate && maxDate ? computeHistogramBins(timedFeatures, minDate, maxDate) : [];
7032
7037
  set2({
7033
7038
  hasTemporalData: true,
@@ -7043,6 +7048,7 @@ const timelineStoreInitializer = (set2, get) => ({
7043
7048
  setRange: (start, end) => set2({ rangeStart: start, rangeEnd: end }),
7044
7049
  setPlaying: (playing) => set2({ isPlaying: playing }),
7045
7050
  setPlaybackSpeed: (speed) => set2({ playbackSpeed: speed }),
7051
+ setPlayMode: (mode) => set2({ playMode: mode }),
7046
7052
  advancePlayhead: () => {
7047
7053
  const state = get();
7048
7054
  if (!state.globalMinDate || !state.globalMaxDate || !state.rangeStart) {
@@ -7086,7 +7092,7 @@ const TimelineStoreContext = react.createContext(null);
7086
7092
  function useTimelineStoreApi() {
7087
7093
  const store = react.useContext(TimelineStoreContext);
7088
7094
  if (!store) {
7089
- throw new Error("useTimelineStoreApi must be used within a MapEditorCanvas (TimelineStoreContext.Provider)");
7095
+ throw new Error("useTimelineStoreApi must be used within a MapEditorCanvas or a TimelineStoreContext.Provider");
7090
7096
  }
7091
7097
  return store;
7092
7098
  }
@@ -7098,6 +7104,12 @@ function useTimelineStore(selector) {
7098
7104
  }
7099
7105
  const TIMEBAR_HEIGHT = 158;
7100
7106
  const TIMEBAR_BOTTOM_OFFSET = 12;
7107
+ const DEFAULT_LABELS = {
7108
+ play: "Play",
7109
+ pause: "Pause",
7110
+ reset: "Reset timeline",
7111
+ cumulative: "Cumulative: keep what has appeared"
7112
+ };
7101
7113
  const MINUTE_MS = 6e4;
7102
7114
  const HOUR_MS = 36e5;
7103
7115
  const DAY_MS = 864e5;
@@ -7246,7 +7258,7 @@ function Histogram({ bins, maxCount, colorGroupedBins }) {
7246
7258
  const containerRef = react.useRef(null);
7247
7259
  if (bins.length === 0 || maxCount === 0) return null;
7248
7260
  const hasColorGroups = colorGroupedBins && colorGroupedBins.length > 0 && colorGroupedBins.some((group) => group.bins.some((count) => count > 0));
7249
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative h-16", ref: containerRef, children: [
7261
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative h-16", ref: containerRef, "data-testid": "timebar-histogram", children: [
7250
7262
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 flex items-end gap-px", children: bins.map((bin, i) => {
7251
7263
  const height = bin.count / maxCount * 100;
7252
7264
  const isHovered = hoveredBin === i;
@@ -7321,7 +7333,17 @@ function TimebarToggle({ onClick, hasData }) {
7321
7333
  }
7322
7334
  );
7323
7335
  }
7324
- function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColors, className, timebarExtra }) {
7336
+ function Timebar({
7337
+ onFilterChange,
7338
+ selectedFeatureIds = [],
7339
+ selectedFeatureColors,
7340
+ selectionDisplay = "bars",
7341
+ className,
7342
+ timebarExtra,
7343
+ formatCount: formatCount2,
7344
+ labels: labelOverrides
7345
+ }) {
7346
+ const labels = { ...DEFAULT_LABELS, ...labelOverrides };
7325
7347
  const {
7326
7348
  isEnabled,
7327
7349
  hasTemporalData,
@@ -7332,19 +7354,22 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
7332
7354
  rangeStart,
7333
7355
  rangeEnd,
7334
7356
  isPlaying,
7357
+ playMode,
7335
7358
  histogramBins: storeHistogramBins,
7336
7359
  setRange,
7337
- setPlaying
7360
+ setPlaying,
7361
+ setPlayMode
7338
7362
  } = useTimelineStore();
7339
7363
  const timelineStoreApi = useTimelineStoreApi();
7340
7364
  const hasSelection = selectedFeatureIds.length > 0;
7365
+ const selectionAsLine = hasSelection && selectionDisplay === "line";
7341
7366
  const selectedTemporalFeatures = react.useMemo(() => {
7342
7367
  if (!hasSelection) return temporalFeatures;
7343
7368
  const selectedSet = new Set(selectedFeatureIds);
7344
7369
  return temporalFeatures.filter((f) => selectedSet.has(f.id));
7345
7370
  }, [hasSelection, selectedFeatureIds, temporalFeatures]);
7346
7371
  const histogramBins = react.useMemo(() => {
7347
- if (!hasSelection || storeHistogramBins.length === 0) return storeHistogramBins;
7372
+ if (!hasSelection || selectionAsLine || storeHistogramBins.length === 0) return storeHistogramBins;
7348
7373
  return storeHistogramBins.map((bin, binIndex) => {
7349
7374
  const isLastBin = binIndex === storeHistogramBins.length - 1;
7350
7375
  let count = 0;
@@ -7357,16 +7382,16 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
7357
7382
  }
7358
7383
  return { ...bin, count };
7359
7384
  });
7360
- }, [hasSelection, storeHistogramBins, selectedTemporalFeatures]);
7361
- const colorGroupedBins = histogramBins.length > 0 && hasSelection && selectedFeatureColors && selectedFeatureColors.size > 0 && globalMinDate && globalMaxDate ? (() => {
7385
+ }, [hasSelection, selectionAsLine, storeHistogramBins, selectedTemporalFeatures]);
7386
+ const colorGroupedBins = histogramBins.length > 0 && hasSelection && (selectionAsLine || selectedFeatureColors && selectedFeatureColors.size > 0) && globalMinDate && globalMaxDate ? (() => {
7362
7387
  if (selectedTemporalFeatures.length === 0) return [];
7363
7388
  const colorGroups = /* @__PURE__ */ new Map();
7364
7389
  selectedTemporalFeatures.forEach((f) => {
7365
- const color = selectedFeatureColors.get(f.id) || "#3b82f6";
7390
+ const color = (selectedFeatureColors == null ? void 0 : selectedFeatureColors.get(f.id)) || "#3b82f6";
7366
7391
  if (!colorGroups.has(color)) colorGroups.set(color, []);
7367
7392
  colorGroups.get(color).push(f);
7368
7393
  });
7369
- if (colorGroups.size <= 1) return [];
7394
+ if (!selectionAsLine && colorGroups.size <= 1) return [];
7370
7395
  const result = [];
7371
7396
  colorGroups.forEach((features, color) => {
7372
7397
  const bins = histogramBins.map((bin, binIndex) => {
@@ -7425,14 +7450,24 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
7425
7450
  setPlaying(false);
7426
7451
  return;
7427
7452
  }
7428
- const newStart = new Date(state.rangeStart.getTime() + stepPerFrame);
7429
- const newEnd = state.rangeEnd ? new Date(state.rangeEnd.getTime() + stepPerFrame) : null;
7430
- if (newStart >= state.globalMaxDate) {
7431
- setRange(state.globalMinDate, state.globalMaxDate);
7432
- setPlaying(false);
7433
- return;
7453
+ if (state.playMode === "cumulative") {
7454
+ const grown = new Date((state.rangeEnd ?? state.rangeStart).getTime() + stepPerFrame);
7455
+ if (grown >= state.globalMaxDate) {
7456
+ setRange(state.rangeStart, state.globalMaxDate);
7457
+ setPlaying(false);
7458
+ return;
7459
+ }
7460
+ setRange(state.rangeStart, grown);
7461
+ } else {
7462
+ const newStart = new Date(state.rangeStart.getTime() + stepPerFrame);
7463
+ const newEnd = state.rangeEnd ? new Date(state.rangeEnd.getTime() + stepPerFrame) : null;
7464
+ if (newStart >= state.globalMaxDate) {
7465
+ setRange(state.globalMinDate, state.globalMaxDate);
7466
+ setPlaying(false);
7467
+ return;
7468
+ }
7469
+ setRange(newStart, newEnd && newEnd <= state.globalMaxDate ? newEnd : state.globalMaxDate);
7434
7470
  }
7435
- setRange(newStart, newEnd && newEnd <= state.globalMaxDate ? newEnd : state.globalMaxDate);
7436
7471
  }
7437
7472
  animationFrameRef.current = requestAnimationFrame(animate);
7438
7473
  };
@@ -7463,11 +7498,17 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
7463
7498
  setPlaying(false);
7464
7499
  };
7465
7500
  const handlePlayPause = () => {
7466
- if (!isPlaying && rangeStart && rangeStart >= globalMaxDate) {
7501
+ if (!isPlaying && playMode === "cumulative") {
7502
+ if (!rangeEnd || rangeEnd >= globalMaxDate) {
7503
+ const from = rangeStart && rangeStart < globalMaxDate ? rangeStart : globalMinDate;
7504
+ setRange(from, from);
7505
+ }
7506
+ } else if (!isPlaying && rangeStart && rangeStart >= globalMaxDate) {
7467
7507
  setRange(globalMinDate, globalMaxDate);
7468
7508
  }
7469
7509
  setPlaying(!isPlaying);
7470
7510
  };
7511
+ const cumulative = playMode === "cumulative";
7471
7512
  return /* @__PURE__ */ jsxRuntime.jsxs(
7472
7513
  "div",
7473
7514
  {
@@ -7515,7 +7556,7 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
7515
7556
  size: "small",
7516
7557
  icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.SkipBack, { className: "w-3.5 h-3.5" }),
7517
7558
  onClick: handleReset,
7518
- "aria-label": "Reset timeline",
7559
+ "aria-label": labels.reset,
7519
7560
  "data-testid": "button-timeline-reset",
7520
7561
  className: "!h-7 !w-7 !p-0 !min-w-0"
7521
7562
  }
@@ -7527,17 +7568,34 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
7527
7568
  size: "small",
7528
7569
  icon: isPlaying ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pause, { className: "w-3.5 h-3.5" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "w-3.5 h-3.5" }),
7529
7570
  onClick: handlePlayPause,
7530
- "aria-label": isPlaying ? "Pause" : "Play",
7571
+ "aria-label": isPlaying ? labels.pause : labels.play,
7531
7572
  "data-testid": "button-timeline-play",
7532
7573
  className: "!h-7 !w-7 !p-0 !min-w-0"
7533
7574
  }
7534
7575
  ),
7576
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Tooltip, { title: labels.cumulative, children: /* @__PURE__ */ jsxRuntime.jsx(
7577
+ antd.Button,
7578
+ {
7579
+ size: "small",
7580
+ color: cumulative ? "primary" : "default",
7581
+ variant: cumulative ? "filled" : "text",
7582
+ icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Layers, { className: "w-3.5 h-3.5" }),
7583
+ onClick: () => setPlayMode(cumulative ? "sliding" : "cumulative"),
7584
+ "aria-label": labels.cumulative,
7585
+ "aria-pressed": cumulative,
7586
+ "data-testid": "button-timeline-cumulative",
7587
+ className: "!h-7 !w-7 !p-0 !min-w-0"
7588
+ }
7589
+ ) }),
7535
7590
  /* @__PURE__ */ jsxRuntime.jsx(
7536
7591
  "span",
7537
7592
  {
7538
7593
  className: "text-xs text-muted-foreground ml-1",
7539
7594
  "data-testid": "text-timeline-feature-count",
7540
- children: hasSelection ? `${selectedTemporalFeatures.length} of ${temporalFeatures.length} selected` : `${temporalFeatures.length} feature${temporalFeatures.length !== 1 ? "s" : ""}`
7595
+ children: formatCount2 ? formatCount2({
7596
+ total: temporalFeatures.length,
7597
+ selected: hasSelection ? selectedTemporalFeatures.length : null
7598
+ }) : hasSelection ? `${selectedTemporalFeatures.length} of ${temporalFeatures.length} selected` : `${temporalFeatures.length} feature${temporalFeatures.length !== 1 ? "s" : ""}`
7541
7599
  }
7542
7600
  )
7543
7601
  ] }),
@@ -17426,8 +17484,10 @@ exports.TIMEBAR_BOTTOM_OFFSET = TIMEBAR_BOTTOM_OFFSET;
17426
17484
  exports.TIMEBAR_HEIGHT = TIMEBAR_HEIGHT;
17427
17485
  exports.Timebar = Timebar;
17428
17486
  exports.TimebarToggle = TimebarToggle;
17487
+ exports.TimelineStoreContext = TimelineStoreContext;
17429
17488
  exports.cn = cn;
17430
17489
  exports.createClusterPieManager = createClusterPieManager;
17490
+ exports.createTimelineStore = createTimelineStore;
17431
17491
  exports.featureCollectionBlobPartsAsync = featureCollectionBlobPartsAsync;
17432
17492
  exports.getIconEmoji = getIconEmoji;
17433
17493
  exports.isFeatureInRange = isFeatureInRange;
@@ -17437,5 +17497,6 @@ exports.normalizeTemporalProperties = normalizeTemporalProperties;
17437
17497
  exports.parseKMLToGeoJSON = parseKMLToGeoJSON;
17438
17498
  exports.toast = useToast;
17439
17499
  exports.useTimelineStore = useTimelineStore;
17500
+ exports.useTimelineStoreApi = useTimelineStoreApi;
17440
17501
  exports.useToast = useToast;
17441
17502
  //# sourceMappingURL=index.cjs.map