fix: resolve TypeScript narrowing errors and renamed lightweight-charts exports

This commit is contained in:
Marko Djordjevic 2026-02-16 16:05:54 +01:00
parent efcf5c185f
commit 23131b2c33
2 changed files with 34 additions and 25 deletions

View file

@ -763,13 +763,16 @@ const CandleChart = forwardRef<CandleChartHandle, CandleChartProps>(
const timestamp = typeof time === 'string' ? Date.parse(time) / 1000 : (time as number);
// First, check for line hit using primitives' hitTest
let deleteLineHit: { id: number; primitive: TrendLine } | null = null;
linePrimitivesRef.current.forEach((primitive, id) => {
const hit = primitive.hitTest(timeCoordinate, priceCoordinate);
if (hit) {
deleteLineHit = { id, primitive };
}
});
const deleteLineHit = (() => {
let result: { id: number; primitive: TrendLine } | null = null;
linePrimitivesRef.current.forEach((primitive, id) => {
const hit = primitive.hitTest(timeCoordinate, priceCoordinate);
if (hit) {
result = { id, primitive };
}
});
return result as { id: number; primitive: TrendLine } | null;
})();
if (deleteLineHit) {
// Delete the clicked line
@ -794,13 +797,16 @@ const CandleChart = forwardRef<CandleChartHandle, CandleChartProps>(
}
// Next, check for rectangle hit using primitives' hitTest
let rectangleHit: { id: number; primitive: RectangleDrawingPrimitive } | null = null;
rectanglePrimitivesRef.current.forEach((primitive, id) => {
const hit = primitive.hitTest(timeCoordinate, priceCoordinate);
if (hit) {
rectangleHit = { id, primitive };
}
});
const rectangleHit = (() => {
let result: { id: number; primitive: RectangleDrawingPrimitive } | null = null;
rectanglePrimitivesRef.current.forEach((primitive, id) => {
const hit = primitive.hitTest(timeCoordinate, priceCoordinate);
if (hit) {
result = { id, primitive };
}
});
return result as { id: number; primitive: RectangleDrawingPrimitive } | null;
})();
if (rectangleHit) {
// Delete the clicked rectangle
@ -853,13 +859,16 @@ const CandleChart = forwardRef<CandleChartHandle, CandleChartProps>(
// Handle line selection when no tool is active or delete tool is active
if (!activeTool || activeTool === 'delete') {
// Check if a line was clicked
let lineHit: { id: number; primitive: TrendLine } | null = null;
linePrimitivesRef.current.forEach((primitive, id) => {
const hit = primitive.hitTest(timeCoordinate, priceCoordinate);
if (hit && activeTool !== 'delete') {
lineHit = { id, primitive };
}
});
const lineHit = (() => {
let result: { id: number; primitive: TrendLine } | null = null;
linePrimitivesRef.current.forEach((primitive, id) => {
const hit = primitive.hitTest(timeCoordinate, priceCoordinate);
if (hit && activeTool !== 'delete') {
result = { id, primitive };
}
});
return result as { id: number; primitive: TrendLine } | null;
})();
if (lineHit && activeTool !== 'delete') {
// Toggle selection