Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"jest-transform-css": "^6.0.1",
"npm-run-all": "^4.1.5",
"postcss": "^8.3.6",
"prettier": "^2.3.2",
"prettier": "^3.8.1",
"prop-types": "^15.8.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import pkg from "./package.json" with { type: "json" };

function createExternal(dependencies) {
return Object.keys(dependencies).flatMap(
(dependency) => new RegExp(`^${dependency}(\\/.+)?`)
(dependency) => new RegExp(`^${dependency}(\\/.+)?`),
);
}

Expand Down
18 changes: 9 additions & 9 deletions src/ActiveCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("<ActiveCell />", () => {
render(
<context.Provider value={[INITIAL_STATE, DISPATCH_MOCK]}>
<ActiveCell DataEditor={MOCK_DATA_EDITOR} />
</context.Provider>
</context.Provider>,
);
expect(document.querySelector(".Spreadsheet__active-cell")).toBeNull();
expect(MOCK_DATA_EDITOR).toBeCalledTimes(0);
Expand All @@ -48,7 +48,7 @@ describe("<ActiveCell />", () => {
render(
<context.Provider value={[STATE_WITH_ACTIVE, DISPATCH_MOCK]}>
<ActiveCell DataEditor={MOCK_DATA_EDITOR} />
</context.Provider>
</context.Provider>,
);
const activeCell = document.querySelector(".Spreadsheet__active-cell");
expect(activeCell).not.toBeNull();
Expand All @@ -61,7 +61,7 @@ describe("<ActiveCell />", () => {
value={[{ ...STATE_WITH_ACTIVE, mode: "edit" }, DISPATCH_MOCK]}
>
<ActiveCell DataEditor={MOCK_DATA_EDITOR} />
</context.Provider>
</context.Provider>,
);
const activeCell = document.querySelector(".Spreadsheet__active-cell");
expect(activeCell).not.toBeNull();
Expand All @@ -75,7 +75,7 @@ describe("<ActiveCell />", () => {
onChange: expect.any(Function),
exitEditMode: expect.any(Function),
},
{}
{},
);
});
test("calls setCellData if value changed", () => {
Expand All @@ -84,7 +84,7 @@ describe("<ActiveCell />", () => {
value={[{ ...STATE_WITH_ACTIVE, mode: "edit" }, DISPATCH_MOCK]}
>
<ActiveCell DataEditor={DataEditor} />
</context.Provider>
</context.Provider>,
);
const activeCell = document.querySelector(".Spreadsheet__active-cell");
expect(activeCell).not.toBeNull();
Expand All @@ -96,14 +96,14 @@ describe("<ActiveCell />", () => {
expect(DISPATCH_MOCK).toBeCalledWith(
Actions.setCellData(Point.ORIGIN, {
value: "test",
})
}),
);
rerender(
<context.Provider
value={[{ ...STATE_WITH_ACTIVE, mode: "view" }, DISPATCH_MOCK]}
>
<ActiveCell DataEditor={DataEditor} />
</context.Provider>
</context.Provider>,
);
expect(activeCell).not.toHaveClass("Spreadsheet__active-cell--edit");
});
Expand All @@ -113,7 +113,7 @@ describe("<ActiveCell />", () => {
value={[{ ...STATE_WITH_ACTIVE, mode: "edit" }, DISPATCH_MOCK]}
>
<ActiveCell DataEditor={MOCK_DATA_EDITOR} />
</context.Provider>
</context.Provider>,
);
const activeCell = document.querySelector(".Spreadsheet__active-cell");
expect(activeCell).not.toBeNull();
Expand All @@ -123,7 +123,7 @@ describe("<ActiveCell />", () => {
value={[{ ...STATE_WITH_ACTIVE, mode: "view" }, DISPATCH_MOCK]}
>
<ActiveCell DataEditor={MOCK_DATA_EDITOR} />
</context.Provider>
</context.Provider>,
);
expect(DISPATCH_MOCK).toBeCalledTimes(0);
expect(activeCell).not.toHaveClass("Spreadsheet__active-cell--edit");
Expand Down
14 changes: 7 additions & 7 deletions src/ActiveCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@ const ActiveCell: React.FC<Props> = (props) => {
const setCellData = React.useCallback(
(active: Point.Point, data: Types.CellBase) =>
dispatch(Actions.setCellData(active, data)),
[dispatch]
[dispatch],
);
const edit = React.useCallback(() => dispatch(Actions.edit()), [dispatch]);
const commit = React.useCallback(
(changes: Types.CommitChanges<Types.CellBase>) =>
dispatch(Actions.commit(changes)),
[dispatch]
[dispatch],
);
const view = React.useCallback(() => {
dispatch(Actions.view());
}, [dispatch]);
const active = useSelector((state) => state.active);
const mode = useSelector((state) => state.mode);
const cell = useSelector((state) =>
state.active ? Matrix.get(state.active, state.model.data) : undefined
state.active ? Matrix.get(state.active, state.model.data) : undefined,
);
const dimensions = useSelector((state) =>
active
? getCellDimensions(active, state.rowDimensions, state.columnDimensions)
: undefined
: undefined,
);
const hidden = React.useMemo(
() => !active || !dimensions,
[active, dimensions]
[active, dimensions],
);

const initialCellRef = React.useRef<Types.CellBase | undefined>(undefined);
Expand All @@ -56,7 +56,7 @@ const ActiveCell: React.FC<Props> = (props) => {
}
setCellData(active, cell);
},
[setCellData, active]
[setCellData, active],
);

React.useEffect(() => {
Expand Down Expand Up @@ -110,7 +110,7 @@ const ActiveCell: React.FC<Props> = (props) => {
ref={rootRef}
className={classnames(
"Spreadsheet__active-cell",
`Spreadsheet__active-cell--${mode}`
`Spreadsheet__active-cell--${mode}`,
)}
style={dimensions}
onClick={mode === "view" && !readOnly ? edit : undefined}
Expand Down
20 changes: 10 additions & 10 deletions src/Cell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ describe("<Cell />", () => {
wrapper,
});
const element = document.querySelector(
".Spreadsheet__cell.Spreadsheet__cell--readonly"
".Spreadsheet__cell.Spreadsheet__cell--readonly",
);
expect(element).not.toBeNull();
expect(MOCK_DATA_VIEWER).toBeCalledTimes(1);
expect(MOCK_DATA_VIEWER).toBeCalledWith(
{ ...EXAMPLE_DATA_VIEWER_PROPS, cell: EXAMPLE_READ_ONLY_DATA },
{}
{},
);
expect(MOCK_SET_CELL_DIMENSIONS).toBeCalledTimes(0);
});
Expand All @@ -103,13 +103,13 @@ describe("<Cell />", () => {
wrapper,
});
const element = document.querySelector(
`.Spreadsheet__cell.${EXAMPLE_DATA_WITH_CLASS_NAME.className}`
`.Spreadsheet__cell.${EXAMPLE_DATA_WITH_CLASS_NAME.className}`,
);
expect(element).not.toBeNull();
expect(MOCK_DATA_VIEWER).toBeCalledTimes(1);
expect(MOCK_DATA_VIEWER).toBeCalledWith(
{ ...EXAMPLE_DATA_VIEWER_PROPS, cell: EXAMPLE_DATA_WITH_CLASS_NAME },
{}
{},
);
expect(MOCK_SET_CELL_DIMENSIONS).toBeCalledTimes(0);
});
Expand All @@ -125,7 +125,7 @@ describe("<Cell />", () => {
expect(MOCK_SET_CELL_DIMENSIONS).toBeCalledTimes(1);
expect(MOCK_SET_CELL_DIMENSIONS).toBeCalledWith(
EXAMPLE_POINT,
getOffsetRect(element)
getOffsetRect(element),
);
});
test("renders active", () => {
Expand Down Expand Up @@ -154,7 +154,7 @@ describe("<Cell />", () => {
expect(MOCK_SET_CELL_DIMENSIONS).toBeCalledTimes(1);
expect(MOCK_SET_CELL_DIMENSIONS).toBeCalledWith(
EXAMPLE_POINT,
getOffsetRect(element)
getOffsetRect(element),
);
expect(MOCK_ACTIVATE).toBeCalledTimes(1);
expect(MOCK_ACTIVATE).toBeCalledWith(EXAMPLE_POINT);
Expand All @@ -174,7 +174,7 @@ describe("<Cell />", () => {
expect(MOCK_SET_CELL_DIMENSIONS).toBeCalledTimes(1);
expect(MOCK_SET_CELL_DIMENSIONS).toBeCalledWith(
EXAMPLE_POINT,
getOffsetRect(element)
getOffsetRect(element),
);
expect(MOCK_ACTIVATE).toBeCalledTimes(0);
expect(MOCK_SELECT).toBeCalledTimes(1);
Expand All @@ -194,7 +194,7 @@ describe("<Cell />", () => {
expect(MOCK_SET_CELL_DIMENSIONS).toBeCalledTimes(1);
expect(MOCK_SET_CELL_DIMENSIONS).toBeCalledWith(
EXAMPLE_POINT,
getOffsetRect(element)
getOffsetRect(element),
);
expect(MOCK_ACTIVATE).toBeCalledTimes(0);
expect(MOCK_SELECT).toBeCalledTimes(1);
Expand All @@ -205,14 +205,14 @@ describe("<Cell />", () => {
<Cell {...EXAMPLE_PROPS} data={EXAMPLE_DATA_WITH_CUSTOM_DATA_VIEWER} />,
{
wrapper,
}
},
);
const element = document.querySelector(".Spreadsheet__cell");
expect(element).not.toBeNull();
expect(MOCK_CUSTOM_DATA_VIEWER).toBeCalledTimes(1);
expect(MOCK_CUSTOM_DATA_VIEWER).toBeCalledWith(
EXAMPLE_CUSTOM_DATA_VIEWER_PROPS,
{}
{},
);
expect(MOCK_SET_CELL_DIMENSIONS).toBeCalledTimes(0);
});
Expand Down
22 changes: 11 additions & 11 deletions src/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const Cell: React.FC<Types.CellComponentProps> = ({
row,
column,
}),
[row, column]
[row, column],
);

const handleMouseDown = React.useCallback(
Expand All @@ -44,7 +44,7 @@ export const Cell: React.FC<Types.CellComponentProps> = ({
}
}
},
[mode, setCellDimensions, point, select, activate]
[mode, setCellDimensions, point, select, activate],
);

const handleMouseOver = React.useCallback(
Expand All @@ -54,7 +54,7 @@ export const Cell: React.FC<Types.CellComponentProps> = ({
select(point);
}
},
[setCellDimensions, select, dragging, point]
[setCellDimensions, select, dragging, point],
);

React.useEffect(() => {
Expand Down Expand Up @@ -94,7 +94,7 @@ export const Cell: React.FC<Types.CellComponentProps> = ({
};

export const enhance = (
CellComponent: React.ComponentType<Types.CellComponentProps>
CellComponent: React.ComponentType<Types.CellComponentProps>,
): React.FC<
Omit<
Types.CellComponentProps,
Expand All @@ -117,34 +117,34 @@ export const enhance = (
row,
column,
}),
[row, column]
[row, column],
);
const setCellData = React.useCallback(
(data: Types.CellBase) => dispatch(Actions.setCellData(point, data)),
[dispatch, point]
[dispatch, point],
);
const select = React.useCallback(
(point: Point.Point) => dispatch(Actions.select(point)),
[dispatch]
[dispatch],
);
const activate = React.useCallback(
(point: Point.Point) => dispatch(Actions.activate(point)),
[dispatch]
[dispatch],
);
const setCellDimensions = React.useCallback(
(point: Point.Point, dimensions: Types.Dimensions) =>
dispatch(Actions.setCellDimensions(point, dimensions)),
[dispatch]
[dispatch],
);
const active = useSelector((state) => isActive(state.active, point));
const mode = useSelector((state) => (active ? state.mode : "view"));
const data = useSelector((state) => Matrix.get(point, state.model.data));
const evaluatedData = useSelector((state) =>
Matrix.get(point, state.model.evaluatedData)
Matrix.get(point, state.model.evaluatedData),
);

const selected = useSelector((state) =>
state.selected.has(state.model.data, point)
state.selected.has(state.model.data, point),
);
const dragging = useSelector((state) => state.dragging);
const copied = useSelector((state) => state.copied?.has(point) || false);
Expand Down
2 changes: 1 addition & 1 deletion src/ColumnIndicator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("<ColumnIndicator />", () => {
});
expect(document.querySelectorAll("th.Spreadsheet__header").length).toBe(1);
const indicator = document.querySelector(
"th.Spreadsheet__header"
"th.Spreadsheet__header",
) as HTMLTableCellElement;
indicator.click();
expect(EXAMPLE_PROPS.onSelect).toBeCalledTimes(1);
Expand Down
8 changes: 4 additions & 4 deletions src/ColumnIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ColumnIndicator: Types.ColumnIndicatorComponent = ({
(event: React.MouseEvent) => {
onSelect(column, event.shiftKey);
},
[onSelect, column]
[onSelect, column],
);
return (
<th
Expand All @@ -33,17 +33,17 @@ const ColumnIndicator: Types.ColumnIndicatorComponent = ({
export default ColumnIndicator;

export const enhance = (
ColumnIndicatorComponent: Types.ColumnIndicatorComponent
ColumnIndicatorComponent: Types.ColumnIndicatorComponent,
): React.FC<Omit<Types.ColumnIndicatorProps, "selected" | "onSelect">> => {
return function ColumnIndicatorWrapper(props) {
const dispatch = useDispatch();
const selectEntireColumn = React.useCallback(
(column: number, extend: boolean) =>
dispatch(Actions.selectEntireColumn(column, extend)),
[dispatch]
[dispatch],
);
const selected = useSelector((state) =>
state.selected.hasEntireColumn(props.column)
state.selected.hasEntireColumn(props.column),
);
return (
<ColumnIndicatorComponent
Expand Down
6 changes: 3 additions & 3 deletions src/Copied.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ describe("<Copied />", () => {
render(
<context.Provider value={[INITIAL_STATE, jest.fn()]}>
<Copied />
</context.Provider>
</context.Provider>,
);
});
expect(
document.querySelector(
".Spreadsheet__floating-rect.Spreadsheet__floating-rect--copied"
)
".Spreadsheet__floating-rect.Spreadsheet__floating-rect--copied",
),
);
});
2 changes: 1 addition & 1 deletion src/Copied.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Copied: React.FC = () => {
const dimensions = useSelector(
(state) =>
range &&
getRangeDimensions(state.rowDimensions, state.columnDimensions, range)
getRangeDimensions(state.rowDimensions, state.columnDimensions, range),
);
const hidden = range === null;

Expand Down
2 changes: 1 addition & 1 deletion src/CornerIndicator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("<CornerIndicator />", () => {
render(<CornerIndicator {...EXAMPLE_PROPS} />, { wrapper });
expect(document.querySelectorAll("th.Spreadsheet__header").length).toBe(1);
const indicator = document.querySelector(
"th.Spreadsheet__header"
"th.Spreadsheet__header",
) as HTMLTableCellElement;
indicator.click();
expect(EXAMPLE_PROPS.onSelect).toBeCalledTimes(1);
Expand Down
Loading