@octostar/map-component 0.3.4 → 0.3.6
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 +81 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +83 -27
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -0
- package/dist/types/components/map-context-menu.d.ts +16 -0
- package/dist/types/components/map-context-menu.d.ts.map +1 -0
- package/dist/types/components/map-editor-canvas.d.ts.map +1 -1
- package/dist/types/components/timebar.d.ts.map +1 -1
- package/dist/types/lib/context-menu-placement.d.ts +33 -0
- package/dist/types/lib/context-menu-placement.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2195,6 +2195,68 @@ function frameYield(scheduler = defaultScheduler, fallbackMs = 50) {
|
|
|
2195
2195
|
}, fallbackMs);
|
|
2196
2196
|
});
|
|
2197
2197
|
}
|
|
2198
|
+
function placeContextMenu(point, parent, menu) {
|
|
2199
|
+
const scaleX = parent.offsetWidth > 0 ? parent.rect.width / parent.offsetWidth : 1;
|
|
2200
|
+
const scaleY = parent.offsetHeight > 0 ? parent.rect.height / parent.offsetHeight : 1;
|
|
2201
|
+
const left = (point.x - parent.rect.left) / scaleX - parent.clientLeft;
|
|
2202
|
+
const top = (point.y - parent.rect.top) / scaleY - parent.clientTop;
|
|
2203
|
+
return {
|
|
2204
|
+
left: fit(left, menu.width, parent.clientWidth),
|
|
2205
|
+
top: fit(top, menu.height, parent.clientHeight)
|
|
2206
|
+
};
|
|
2207
|
+
}
|
|
2208
|
+
function fit(start, size, available) {
|
|
2209
|
+
const opened = start + size > available ? start - size : start;
|
|
2210
|
+
return Math.max(0, Math.min(opened, available - size));
|
|
2211
|
+
}
|
|
2212
|
+
function MapContextMenu({ x, y, items, onClose }) {
|
|
2213
|
+
const menuRef = react.useRef(null);
|
|
2214
|
+
react.useLayoutEffect(() => {
|
|
2215
|
+
const menu = menuRef.current;
|
|
2216
|
+
const parent = menu == null ? void 0 : menu.offsetParent;
|
|
2217
|
+
if (!menu || !(parent instanceof HTMLElement)) return;
|
|
2218
|
+
const { left, top } = placeContextMenu(
|
|
2219
|
+
{ x, y },
|
|
2220
|
+
{
|
|
2221
|
+
rect: parent.getBoundingClientRect(),
|
|
2222
|
+
offsetWidth: parent.offsetWidth,
|
|
2223
|
+
offsetHeight: parent.offsetHeight,
|
|
2224
|
+
clientLeft: parent.clientLeft,
|
|
2225
|
+
clientTop: parent.clientTop,
|
|
2226
|
+
clientWidth: parent.clientWidth,
|
|
2227
|
+
clientHeight: parent.clientHeight
|
|
2228
|
+
},
|
|
2229
|
+
{ width: menu.offsetWidth, height: menu.offsetHeight }
|
|
2230
|
+
);
|
|
2231
|
+
menu.style.left = `${left}px`;
|
|
2232
|
+
menu.style.top = `${top}px`;
|
|
2233
|
+
}, [x, y, items]);
|
|
2234
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2235
|
+
"div",
|
|
2236
|
+
{
|
|
2237
|
+
ref: menuRef,
|
|
2238
|
+
className: "z-[9999] min-w-[160px] max-h-full overflow-y-auto rounded-md border bg-popover p-1 shadow-md",
|
|
2239
|
+
style: { position: "absolute", left: 0, top: 0 },
|
|
2240
|
+
"data-testid": "context-menu",
|
|
2241
|
+
children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2242
|
+
"button",
|
|
2243
|
+
{
|
|
2244
|
+
className: `flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover-elevate active-elevate-2 ${item.disabled ? "opacity-50 cursor-not-allowed" : "cursor-pointer"} ${item.destructive ? "text-destructive" : ""}`,
|
|
2245
|
+
disabled: item.disabled,
|
|
2246
|
+
onClick: () => {
|
|
2247
|
+
if (!item.disabled) {
|
|
2248
|
+
item.onSelect();
|
|
2249
|
+
onClose();
|
|
2250
|
+
}
|
|
2251
|
+
},
|
|
2252
|
+
"data-testid": `context-menu-item-${item.id}`,
|
|
2253
|
+
children: item.label
|
|
2254
|
+
},
|
|
2255
|
+
item.id
|
|
2256
|
+
))
|
|
2257
|
+
}
|
|
2258
|
+
);
|
|
2259
|
+
}
|
|
2198
2260
|
function CursorCoordinatesOverlay({ map }) {
|
|
2199
2261
|
const [coords, setCoords] = react.useState(null);
|
|
2200
2262
|
react.useEffect(() => {
|
|
@@ -7402,7 +7464,7 @@ function formatDateTime(date) {
|
|
|
7402
7464
|
minute: "2-digit"
|
|
7403
7465
|
});
|
|
7404
7466
|
}
|
|
7405
|
-
function Histogram({ bins, maxCount, colorGroupedBins }) {
|
|
7467
|
+
function Histogram({ bins, maxCount, colorGroupedBins, selectedBins }) {
|
|
7406
7468
|
const [hoveredBin, setHoveredBin] = react.useState(null);
|
|
7407
7469
|
const containerRef = react.useRef(null);
|
|
7408
7470
|
if (bins.length === 0 || maxCount === 0) return null;
|
|
@@ -7461,7 +7523,8 @@ function Histogram({ bins, maxCount, colorGroupedBins }) {
|
|
|
7461
7523
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-muted-foreground", children: [
|
|
7462
7524
|
bins[hoveredBin].count,
|
|
7463
7525
|
" event",
|
|
7464
|
-
bins[hoveredBin].count !== 1 ? "s" : ""
|
|
7526
|
+
bins[hoveredBin].count !== 1 ? "s" : "",
|
|
7527
|
+
!!(selectedBins == null ? void 0 : selectedBins[hoveredBin]) && ` (${selectedBins[hoveredBin]} selected)`
|
|
7465
7528
|
] })
|
|
7466
7529
|
]
|
|
7467
7530
|
}
|
|
@@ -7532,7 +7595,9 @@ function Timebar({
|
|
|
7532
7595
|
return { ...bin, count };
|
|
7533
7596
|
});
|
|
7534
7597
|
}, [hasSelection, selectionAsLine, storeHistogramBins, selectedTemporalFeatures]);
|
|
7535
|
-
const colorGroupedBins =
|
|
7598
|
+
const colorGroupedBins = react.useMemo(() => {
|
|
7599
|
+
if (histogramBins.length === 0 || !hasSelection || !globalMinDate || !globalMaxDate) return [];
|
|
7600
|
+
if (!selectionAsLine && !(selectedFeatureColors && selectedFeatureColors.size > 0)) return [];
|
|
7536
7601
|
if (selectedTemporalFeatures.length === 0) return [];
|
|
7537
7602
|
const colorGroups = /* @__PURE__ */ new Map();
|
|
7538
7603
|
selectedTemporalFeatures.forEach((f) => {
|
|
@@ -7556,7 +7621,11 @@ function Timebar({
|
|
|
7556
7621
|
result.push({ color, bins });
|
|
7557
7622
|
});
|
|
7558
7623
|
return result;
|
|
7559
|
-
}
|
|
7624
|
+
}, [hasSelection, selectionAsLine, histogramBins, selectedTemporalFeatures, selectedFeatureColors, globalMinDate, globalMaxDate]);
|
|
7625
|
+
const selectedBins = react.useMemo(
|
|
7626
|
+
() => selectionAsLine ? histogramBins.map((_, i) => colorGroupedBins.reduce((sum, group) => sum + group.bins[i], 0)) : void 0,
|
|
7627
|
+
[selectionAsLine, histogramBins, colorGroupedBins]
|
|
7628
|
+
);
|
|
7560
7629
|
const animationFrameRef = react.useRef(null);
|
|
7561
7630
|
const lastFrameTimeRef = react.useRef(0);
|
|
7562
7631
|
const playbackDuration = 1e4;
|
|
@@ -7674,7 +7743,8 @@ function Timebar({
|
|
|
7674
7743
|
{
|
|
7675
7744
|
bins: histogramBins,
|
|
7676
7745
|
maxCount: maxBinCount,
|
|
7677
|
-
colorGroupedBins
|
|
7746
|
+
colorGroupedBins,
|
|
7747
|
+
selectedBins
|
|
7678
7748
|
}
|
|
7679
7749
|
),
|
|
7680
7750
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -16836,31 +16906,17 @@ const MapEditorCanvas = react.forwardRef(function MapEditorCanvas2({
|
|
|
16836
16906
|
{
|
|
16837
16907
|
selectedFeatureIds,
|
|
16838
16908
|
selectedFeatureColors,
|
|
16909
|
+
selectionDisplay: "line",
|
|
16839
16910
|
timebarExtra
|
|
16840
16911
|
}
|
|
16841
16912
|
),
|
|
16842
16913
|
contextMenu && /* @__PURE__ */ jsxRuntime.jsx(
|
|
16843
|
-
|
|
16914
|
+
MapContextMenu,
|
|
16844
16915
|
{
|
|
16845
|
-
|
|
16846
|
-
|
|
16847
|
-
|
|
16848
|
-
|
|
16849
|
-
"button",
|
|
16850
|
-
{
|
|
16851
|
-
className: `flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover-elevate active-elevate-2 ${item.disabled ? "opacity-50 cursor-not-allowed" : "cursor-pointer"} ${item.destructive ? "text-destructive" : ""}`,
|
|
16852
|
-
disabled: item.disabled,
|
|
16853
|
-
onClick: () => {
|
|
16854
|
-
if (!item.disabled) {
|
|
16855
|
-
item.onSelect();
|
|
16856
|
-
setContextMenu(null);
|
|
16857
|
-
}
|
|
16858
|
-
},
|
|
16859
|
-
"data-testid": `context-menu-item-${item.id}`,
|
|
16860
|
-
children: item.label
|
|
16861
|
-
},
|
|
16862
|
-
item.id
|
|
16863
|
-
))
|
|
16916
|
+
x: contextMenu.x,
|
|
16917
|
+
y: contextMenu.y,
|
|
16918
|
+
items: contextMenu.items,
|
|
16919
|
+
onClose: () => setContextMenu(null)
|
|
16864
16920
|
}
|
|
16865
16921
|
),
|
|
16866
16922
|
/* @__PURE__ */ jsxRuntime.jsx(CursorCoordinatesOverlay, { map: isMapLoaded ? map.current : null }),
|