Skip to content

Commit 4ef60f0

Browse files
committed
Merge branch 'preact'
2 parents a42ff50 + dda2ba2 commit 4ef60f0

23 files changed

+103
-134
lines changed

build.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ const ctx = await esbuild.context({
5252
loader: { '.woff2': 'file' },
5353
metafile: !dev,
5454
jsxDev: dev,
55+
alias: {
56+
react: 'preact/compat',
57+
'react-dom/test-utils': 'preact/test-utils',
58+
'react-dom': 'preact/compat',
59+
'react/jsx-runtime': 'preact/jsx-runtime',
60+
},
5561
});
5662

5763
if (dev) {

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
"@types/geojson": "7946.0.16",
2626
"@types/node": "22.16.0",
2727
"@types/papaparse": "5.3.16",
28-
"@types/react": "19.1.8",
29-
"@types/react-dom": "19.1.6",
3028
"autoprefixer": "10.4.21",
3129
"aws-cdk-lib": "2.204.0",
3230
"browserslist": "4.25.1",
@@ -52,8 +50,7 @@
5250
"geographiclib-dms": "2.1.1",
5351
"geographiclib-geodesic": "patch:geographiclib-geodesic@npm%3A2.1.1#~/.yarn/patches/geographiclib-geodesic-npm-2.1.1-2da4df7f31.patch",
5452
"papaparse": "5.5.3",
55-
"react": "19.1.0",
56-
"react-dom": "19.1.0",
53+
"preact": "10.26.9",
5754
"react-redux": "9.2.0",
5855
"redux": "5.0.1",
5956
"redux-persist": "6.0.0",

src/About.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type React from 'react';
1+
import type { FunctionComponent } from 'preact';
22

3-
const About: React.FC = () => (
3+
const About: FunctionComponent = () => (
44
<>
55
<h2>About</h2>
66
<p className="hint">

src/Data.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { useCallback } from 'react';
1+
import type { FunctionComponent } from 'preact';
2+
import { useCallback } from 'preact/compat';
23
import type { FeatureCollection, Point } from 'geojson';
34
import FileInput from './FileInput';
45
import MaybeError from './MaybeError';
@@ -7,7 +8,7 @@ import { parseData } from './parseData';
78
import { useAppDispatch, useAppSelector } from './store';
89
import { stringifyError } from './util';
910

10-
const Data: React.FC = () => {
11+
const Data: FunctionComponent = () => {
1112
const dispatch = useAppDispatch();
1213
const count = useAppSelector((state) => state.data.photos.features.length);
1314
const error = useAppSelector((state) => state.data.error);

src/FileInput.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { useCallback, useRef } from 'react';
1+
import type { FunctionComponent } from 'preact';
2+
import { ChangeEventHandler, useCallback, useRef } from 'preact/compat';
23

34
type Kind = 'csv' | 'kml' | 'json';
45

@@ -20,23 +21,22 @@ const exts: Record<Kind, string> = {
2021
kml: '.kml',
2122
};
2223

23-
const FileInput: React.FC<Props> = ({ kind, onFile, children }) => {
24+
const FileInput: FunctionComponent<Props> = ({ kind, onFile, children }) => {
2425
const inputRef = useRef<HTMLInputElement>(null);
2526

2627
const onLoadClick = useCallback(() => {
2728
inputRef.current?.click();
2829
}, []);
2930

30-
const onFileChange: React.ChangeEventHandler<HTMLInputElement> =
31-
React.useCallback(
32-
(evt) => {
33-
const files = evt.target.files;
34-
if (files?.length === 1 && onFile) {
35-
onFile(files[0]);
36-
}
37-
},
38-
[onFile]
39-
);
31+
const onFileChange: ChangeEventHandler<HTMLInputElement> = useCallback(
32+
(evt) => {
33+
const files = evt.currentTarget.files;
34+
if (files?.length === 1 && onFile) {
35+
onFile(files[0]);
36+
}
37+
},
38+
[onFile]
39+
);
4040

4141
const accept = [mimes, exts]
4242
.flatMap((map) => kind.map((k) => map[k]))

src/Game/BasicInput.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React, { useCallback } from 'react';
1+
import { ChangeEventHandler, useCallback } from 'preact/compat';
22
import { setBasic } from '../gameSlice';
33
import { useAppDispatch, useAppSelector } from '../store';
44

55
const BasicInput = () => {
66
const dispatch = useAppDispatch();
77
const text = useAppSelector((state) => state.game.basicText);
8-
const onChange: React.ChangeEventHandler<HTMLInputElement> = useCallback(
9-
(evt) => dispatch(setBasic(evt.target.value)),
8+
const onChange: ChangeEventHandler<HTMLInputElement> = useCallback(
9+
(evt) => dispatch(setBasic(evt.currentTarget.value)),
1010
[dispatch]
1111
);
1212

src/Game/LineInput.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback } from 'react';
1+
import { ChangeEventHandler, useCallback } from 'preact/compat';
22
import FileInput from '../FileInput';
33
import {
44
setLine0,
@@ -18,19 +18,18 @@ const LineInput = () => {
1818
(state) => state.game.lineTarget.geometry.coordinates.length === 2
1919
);
2020
const wraparound = useAppSelector((state) => state.game.lineWraparound);
21-
const onChange0: React.ChangeEventHandler<HTMLInputElement> = useCallback(
22-
(evt) => dispatch(setLine0(evt.target.value)),
21+
const onChange0: ChangeEventHandler<HTMLInputElement> = useCallback(
22+
(evt) => dispatch(setLine0(evt.currentTarget.value)),
2323
[dispatch]
2424
);
25-
const onChange1: React.ChangeEventHandler<HTMLInputElement> = useCallback(
26-
(evt) => dispatch(setLine1(evt.target.value)),
25+
const onChange1: ChangeEventHandler<HTMLInputElement> = useCallback(
26+
(evt) => dispatch(setLine1(evt.currentTarget.value)),
27+
[dispatch]
28+
);
29+
const onChangeWraparound: ChangeEventHandler<HTMLInputElement> = useCallback(
30+
(evt) => dispatch(setLineWraparound(evt.currentTarget.checked)),
2731
[dispatch]
2832
);
29-
const onChangeWraparound: React.ChangeEventHandler<HTMLInputElement> =
30-
useCallback(
31-
(evt) => dispatch(setLineWraparound(evt.target.checked)),
32-
[dispatch]
33-
);
3433
const onFile = useCallback(
3534
async (file: File) => {
3635
try {

src/Game/MultiInput.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import React, { useCallback } from 'react';
1+
import {
2+
ChangeEventHandler,
3+
ClipboardEventHandler,
4+
useCallback,
5+
} from 'preact/compat';
26
import { setMulti } from '../gameSlice';
37
import { useAppDispatch, useAppSelector } from '../store';
48

@@ -7,15 +11,15 @@ const COORDS_RE = /[+-]?[0-9]+(?:\.?[0-9]+)?[,\s]+[+-]?[0-9]+(?:\.?[0-9]+)?/g;
711
const MultiInput = () => {
812
const dispatch = useAppDispatch();
913
const text = useAppSelector((state) => state.game.multiText);
10-
const onChange: React.ChangeEventHandler<HTMLTextAreaElement> = useCallback(
14+
const onChange: ChangeEventHandler<HTMLTextAreaElement> = useCallback(
1115
(evt) => {
12-
dispatch(setMulti(evt.target.value));
16+
dispatch(setMulti(evt.currentTarget.value));
1317
},
1418
[dispatch]
1519
);
16-
const onPaste: React.ClipboardEventHandler<HTMLTextAreaElement> = useCallback(
20+
const onPaste: ClipboardEventHandler<HTMLTextAreaElement> = useCallback(
1721
(evt) => {
18-
const data = evt.clipboardData.getData('text/plain');
22+
const data = evt.clipboardData?.getData('text/plain') ?? '';
1923
let results: string[] = [];
2024
for (const result of data.matchAll(COORDS_RE)) {
2125
results.push(result[0]);

src/Game/Params.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type React from 'react';
1+
import { FunctionComponent } from 'preact';
22
import MaybeError from '../MaybeError';
33
import { GameMode } from '../game-modes';
44
import { useAppSelector } from '../store';
55
import BasicInput from './BasicInput';
66
import LineInput from './LineInput';
77
import MultiInput from './MultiInput';
88

9-
const GameInput: React.FC = () => {
9+
const GameInput: FunctionComponent = () => {
1010
const mode = useAppSelector((state) => state.game.mode);
1111

1212
switch (mode) {
@@ -19,12 +19,12 @@ const GameInput: React.FC = () => {
1919
}
2020
};
2121

22-
const GameError: React.FC = () => {
22+
const GameError: FunctionComponent = () => {
2323
const error = useAppSelector((state) => state.game.error);
2424
return <MaybeError error={error} />;
2525
};
2626

27-
const GameParams: React.FC = () => (
27+
const GameParams: FunctionComponent = () => (
2828
<div id="game-params">
2929
<GameInput />
3030
<GameError />

src/Game/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type React from 'react';
1+
import { FunctionComponent } from 'preact';
22
import { Selector } from '../Radio';
33
import { GameMode, Geoid } from '../game-modes';
44
import { setGeoid, setMode } from '../gameSlice';
55
import { useAppSelector } from '../store';
66
import GameParams from './Params';
77

8-
const Game: React.FC = () => {
8+
const Game: FunctionComponent = () => {
99
const mode = useAppSelector((state) => state.game.mode);
1010
const geoid = useAppSelector((state) => state.game.geoid);
1111

0 commit comments

Comments
 (0)