Skip to content

Commit

Permalink
Fixed ESLint config linkage to TSConfig file
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn committed Aug 27, 2023
1 parent 4904c7a commit 9b4246d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 38 deletions.
28 changes: 28 additions & 0 deletions packages/react-resizable-panels/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { join } = require("path");

/* eslint-env node */
module.exports = {
ignorePatterns: [".parcel-cache", "dist", "node_modules"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "../../tsconfig.json",
tsconfigRootDir: __dirname,
},
plugins: ["@typescript-eslint", "no-restricted-imports", "react-hooks"],
root: true,
rules: {
"no-restricted-imports": [
"error",
{
paths: ["react"],
},
],
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": [
"warn",
{
additionalHooks: "(useIsomorphicLayoutEffect)",
},
],
},
};
22 changes: 0 additions & 22 deletions packages/react-resizable-panels/.eslintrc.json

This file was deleted.

11 changes: 6 additions & 5 deletions packages/react-resizable-panels/src/new/PanelGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import useIsomorphicLayoutEffect from "../hooks/useIsomorphicEffect";
import useUniqueId from "../hooks/useUniqueId";
import { resetGlobalCursorStyle, setGlobalCursorStyle } from "../utils/cursor";
import debounce from "../utils/debounce";
import { getAvailableGroupSizePixels, getResizeHandle } from "../utils/group";
import {
CSSProperties,
ElementType,
Expand All @@ -26,6 +25,8 @@ import { computePanelFlexBoxStyle } from "./utils/computePanelFlexBoxStyle";
import { computePercentagePanelConstraints } from "./utils/computePercentagePanelConstraints";
import { convertPercentageToPixels } from "./utils/convertPercentageToPixels";
import { determinePivotIndices } from "./utils/determinePivotIndices";
import { calculateAvailablePanelSizeInPixels } from "./utils/dom/calculateAvailablePanelSizeInPixels";
import { getResizeHandleElement } from "./utils/dom/getResizeHandleElement";
import { isMouseEvent, isTouchEvent } from "./utils/events";
import { getResizeEventCursorPosition } from "./utils/getResizeEventCursorPosition";
import { initializeDefaultStorage } from "./utils/initializeDefaultStorage";
Expand Down Expand Up @@ -147,7 +148,7 @@ export function PanelGroup({
unsafeLayout = loadPanelLayout(autoSaveId, panelDataArray, storage);
}

const groupSizePixels = getAvailableGroupSizePixels(groupId);
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);

if (unsafeLayout == null) {
unsafeLayout = calculateDefaultLayout({
Expand Down Expand Up @@ -363,7 +364,7 @@ export function PanelGroup({
delta = -delta;
}

const groupSizePixels = getAvailableGroupSizePixels(groupId);
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
const panelConstraints = panelDataArray.map(
(panelData) => panelData.constraints
);
Expand Down Expand Up @@ -448,7 +449,7 @@ export function PanelGroup({
(dragHandleId: string, event: ResizeEvent) => {
const { direction, layout } = committedValuesRef.current;

const handleElement = getResizeHandle(dragHandleId)!;
const handleElement = getResizeHandleElement(dragHandleId)!;

const initialCursorPosition = getResizeEventCursorPosition(
direction,
Expand Down Expand Up @@ -561,7 +562,7 @@ function panelDataHelper(
const panelIndex = panelDataArray.indexOf(panelData);
const panelConstraints = panelConstraintsArray[panelIndex];

const groupSizePixels = getAvailableGroupSizePixels(groupId);
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);

const percentagePanelConstraints = computePercentagePanelConstraints(
panelConstraintsArray,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getPanelGroup } from "../../utils/group";
import { DragState, ResizeEvent } from "../PanelGroupContext";
import { Direction } from "../types";
import { isKeyDown } from "./events";
import { calculateDragOffsetPercentage } from "./calculateDragOffsetPercentage";
import { getPanelGroupElement } from "./dom/getPanelGroupElement";
import { isKeyDown } from "./events";

// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
export function calculateDeltaPercentage(
Expand All @@ -15,7 +15,7 @@ export function calculateDeltaPercentage(
if (isKeyDown(event)) {
const isHorizontal = direction === "horizontal";

const groupElement = getPanelGroup(groupId)!;
const groupElement = getPanelGroupElement(groupId)!;
const rect = groupElement.getBoundingClientRect();
const groupSizeInPixels = isHorizontal ? rect.width : rect.height;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getPanelGroup, getResizeHandle } from "../../utils/group";
import { DragState, ResizeEvent } from "../PanelGroupContext";
import { Direction } from "../types";
import { getPanelGroupElement } from "./dom/getPanelGroupElement";
import { getResizeHandleElement } from "./dom/getResizeHandleElement";
import { getResizeEventCursorPosition } from "./getResizeEventCursorPosition";

export function calculateDragOffsetPercentage(
Expand All @@ -11,14 +12,14 @@ export function calculateDragOffsetPercentage(
): number {
const isHorizontal = direction === "horizontal";

const handleElement = getResizeHandle(dragHandleId)!;
const handleElement = getResizeHandleElement(dragHandleId)!;
const groupId = handleElement.getAttribute("data-panel-group-id")!;

let { initialCursorPosition } = initialDragState;

const cursorPosition = getResizeEventCursorPosition(direction, event);

const groupElement = getPanelGroup(groupId)!;
const groupElement = getPanelGroupElement(groupId)!;
const groupRect = groupElement.getBoundingClientRect();
const groupSizeInPixels = isHorizontal ? groupRect.width : groupRect.height;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { getResizeHandle, getResizeHandlesForGroup } from "../../utils/group";
import { getResizeHandleElementIndex } from "./dom/getResizeHandleElementIndex";

export function determinePivotIndices(
groupId: string,
dragHandleId: string
): [indexBefore: number, indexAfter: number] {
const handle = getResizeHandle(dragHandleId);
const handles = getResizeHandlesForGroup(groupId);
const index = handle ? handles.indexOf(handle) : -1;
const index = getResizeHandleElementIndex(groupId, dragHandleId);

return [index, index + 1];
return index != null ? [index, index + 1] : [-1, -1];
}

0 comments on commit 9b4246d

Please sign in to comment.