@octostar/map-component 0.2.1 → 0.2.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.mjs CHANGED
@@ -12,7 +12,7 @@ import { clsx } from "clsx";
12
12
  import { twMerge } from "tailwind-merge";
13
13
  import { createPortal } from "react-dom";
14
14
  import { format } from "date-fns";
15
- import { create } from "zustand";
15
+ import { useStore, createStore } from "zustand";
16
16
  import dayjs from "dayjs";
17
17
  import * as toGeoJSON from "@mapbox/togeojson";
18
18
  const ICONS = [
@@ -4526,7 +4526,7 @@ function computeHistogramBins(features, minDate, maxDate, binCount = 50) {
4526
4526
  });
4527
4527
  return bins;
4528
4528
  }
4529
- const useTimelineStore = create((set, get) => ({
4529
+ const timelineStoreInitializer = (set, get) => ({
4530
4530
  isEnabled: false,
4531
4531
  hasTemporalData: false,
4532
4532
  temporalFeatures: [],
@@ -4631,7 +4631,24 @@ const useTimelineStore = create((set, get) => ({
4631
4631
  isPlaying: false,
4632
4632
  histogramBins: []
4633
4633
  })
4634
- }));
4634
+ });
4635
+ function createTimelineStore() {
4636
+ return createStore(timelineStoreInitializer);
4637
+ }
4638
+ const TimelineStoreContext = createContext(null);
4639
+ function useTimelineStoreApi() {
4640
+ const store = useContext(TimelineStoreContext);
4641
+ if (!store) {
4642
+ throw new Error("useTimelineStoreApi must be used within a MapEditorCanvas (TimelineStoreContext.Provider)");
4643
+ }
4644
+ return store;
4645
+ }
4646
+ const identityTimelineSelector = (state) => state;
4647
+ function useTimelineStore(selector) {
4648
+ const store = useTimelineStoreApi();
4649
+ const select = selector ?? identityTimelineSelector;
4650
+ return useStore(store, select);
4651
+ }
4635
4652
  const TIMEBAR_HEIGHT = 158;
4636
4653
  const TIMEBAR_BOTTOM_OFFSET = 12;
4637
4654
  const MINUTE_MS = 6e4;
@@ -4872,6 +4889,7 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4872
4889
  setRange,
4873
4890
  setPlaying
4874
4891
  } = useTimelineStore();
4892
+ const timelineStoreApi = useTimelineStoreApi();
4875
4893
  const hasSelection = selectedFeatureIds.length > 0;
4876
4894
  const selectedTemporalFeatures = useMemo(() => {
4877
4895
  if (!hasSelection) return temporalFeatures;
@@ -4955,7 +4973,7 @@ function Timebar({ onFilterChange, selectedFeatureIds = [], selectedFeatureColor
4955
4973
  const elapsed = timestamp - lastFrameTimeRef.current;
4956
4974
  if (elapsed >= frameInterval) {
4957
4975
  lastFrameTimeRef.current = timestamp;
4958
- const state = useTimelineStore.getState();
4976
+ const state = timelineStoreApi.getState();
4959
4977
  if (!state.rangeStart || !state.globalMaxDate || !state.globalMinDate) {
4960
4978
  setPlaying(false);
4961
4979
  return;
@@ -6055,8 +6073,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6055
6073
  const [labelsSuppressed, setLabelsSuppressed] = useState(true);
6056
6074
  const [cursorCoords, setCursorCoords] = useState(null);
6057
6075
  const [contextMenu, setContextMenu] = useState(null);
6058
- const timelineStore = useTimelineStore();
6059
- useEffect(() => () => useTimelineStore.getState().reset(), []);
6076
+ const [timelineStoreApi] = useState(createTimelineStore);
6077
+ const timelineStore = useStore(timelineStoreApi);
6060
6078
  const { toast: internalToast } = useToast();
6061
6079
  const toast = toastProvider ?? internalToast;
6062
6080
  useEffect(() => {
@@ -6929,8 +6947,8 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
6929
6947
  }
6930
6948
  layerTemporalCacheRef.current.set(layerId, { featureCount: features.length, hasTemporal: layerHasTemporal });
6931
6949
  });
6932
- useTimelineStore.getState().setTemporalFeatures(temporalFeatures, untimedIds);
6933
- }, []);
6950
+ timelineStoreApi.getState().setTemporalFeatures(temporalFeatures, untimedIds);
6951
+ }, [timelineStoreApi]);
6934
6952
  const scheduleTimelineUpdate = useCallback(() => {
6935
6953
  if (timelineUpdateTimerRef.current) clearTimeout(timelineUpdateTimerRef.current);
6936
6954
  timelineUpdateTimerRef.current = setTimeout(() => {
@@ -8934,10 +8952,10 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
8934
8952
  },
8935
8953
  isEditModeEnabled: () => isEditMode,
8936
8954
  setTimelineEnabled: (enabled) => {
8937
- useTimelineStore.getState().setEnabled(enabled);
8955
+ timelineStoreApi.getState().setEnabled(enabled);
8938
8956
  },
8939
8957
  setTimelineRange: (start, end) => {
8940
- useTimelineStore.getState().setRange(start, end);
8958
+ timelineStoreApi.getState().setRange(start, end);
8941
8959
  onTimelineChange == null ? void 0 : onTimelineChange(start, end);
8942
8960
  },
8943
8961
  exportGeoJSON: (layerIds) => {
@@ -9256,7 +9274,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
9256
9274
  return features;
9257
9275
  },
9258
9276
  getTimelineRange: () => {
9259
- const ts = useTimelineStore.getState();
9277
+ const ts = timelineStoreApi.getState();
9260
9278
  return {
9261
9279
  start: ts.rangeStart,
9262
9280
  end: ts.rangeEnd
@@ -12584,7 +12602,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
12584
12602
  ] }) });
12585
12603
  }
12586
12604
  const toastContextValue = toastProvider ?? null;
12587
- return /* @__PURE__ */ jsx(ToastContext.Provider, { value: toastContextValue, children: /* @__PURE__ */ jsx(MapDropZone, { onDrop: handleDropGeoJSON, children: /* @__PURE__ */ jsxs("div", { className: `map-container w-full h-full min-w-0 relative overflow-hidden isolate ${className || ""}`, "data-testid": "map-editor-canvas", children: [
12605
+ return /* @__PURE__ */ jsx(TimelineStoreContext.Provider, { value: timelineStoreApi, children: /* @__PURE__ */ jsx(ToastContext.Provider, { value: toastContextValue, children: /* @__PURE__ */ jsx(MapDropZone, { onDrop: handleDropGeoJSON, children: /* @__PURE__ */ jsxs("div", { className: `map-container w-full h-full min-w-0 relative overflow-hidden isolate ${className || ""}`, "data-testid": "map-editor-canvas", children: [
12588
12606
  /* @__PURE__ */ jsx(
12589
12607
  "div",
12590
12608
  {
@@ -13085,7 +13103,7 @@ const MapEditorCanvas = forwardRef(function MapEditorCanvas2({
13085
13103
  "data-testid": "input-file-geojson"
13086
13104
  }
13087
13105
  )
13088
- ] }) }) });
13106
+ ] }) }) }) });
13089
13107
  });
13090
13108
  function ActionPanel({ onSave, onLoad, disabled }) {
13091
13109
  return /* @__PURE__ */ jsxs(