Skip to content

Commit ff773d1

Browse files
committed
refactor: Switch from TypeScript to JavaScript to reduce build complexity
1 parent dd18100 commit ff773d1

27 files changed

+329
-657
lines changed

dist/remark/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function remarkResistogram(options) {
119119
for (let i = nodesToProcess.length - 1; i >= 0; i--) {
120120
const { node: node2, index, parent } = nodesToProcess[i];
121121
const text = toString(node2);
122-
const regex = /%%RESIST\s*([^%]*)%%/g;
122+
const regex = /%%RESIST\s*([^%]*)%%/;
123123
const match = text.match(regex);
124124
if (!match || match.index === void 0) continue;
125125
const beforeText = text.slice(0, match.index).trim();

dist/theme/ResistanceTable/components/Legend.tsx renamed to dist/theme/ResistanceTable/components/Legend.jsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
import React from 'react';
22

33
// Mock types
4-
type FormattedCol = { id: string; name: string; short: string };
5-
type DisplayMode = 'full' | 'compact' | 'superCompact';
4+
// Helper function to remove type annotations for JS conversion
5+
const identity = (props) => props;
66

7-
interface LegendProps {
8-
cols: FormattedCol[];
9-
displayMode: DisplayMode;
10-
styles: any;
11-
}
12-
13-
export const Legend = ({ cols, displayMode, styles }: LegendProps) => {
7+
export const Legend = ({ cols, displayMode, styles }) => {
148
if (displayMode === 'full') return null;
159

1610
return (

src/theme/ResistanceTable/components/TableBody.tsx renamed to dist/theme/ResistanceTable/components/TableBody.jsx

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,5 @@
11
import React from 'react';
22
import { TableRow } from './TableRow';
3-
import { getTranslator } from '../i18n';
4-
5-
type Translator = ReturnType<typeof getTranslator>;
6-
7-
// Mock types
8-
type FormattedRow = Record<string, any> & { rowLong: string; rowShort: string };
9-
type FormattedCol = { id: string; name: string; short: string };
10-
type DisplayMode = 'full' | 'compact' | 'superCompact';
11-
12-
interface TableBodyProps {
13-
data: FormattedRow[];
14-
cols: FormattedCol[];
15-
displayMode: DisplayMode;
16-
rowsAreAbx: boolean;
17-
hoveredRow: number | null;
18-
hoveredCol: number | null;
19-
onSetHover: (row: number, col: number) => void;
20-
onClearHover: () => void;
21-
onShowTooltip: (content: React.ReactNode, element: HTMLElement) => void;
22-
onHideTooltip: () => void;
23-
styles: any;
24-
colorMode: 'dark' | 'light';
25-
sourceId2ShortName: Map<string, string>;
26-
t: Translator;
27-
}
283

294
export const TableBody = ({
305
data,
@@ -41,7 +16,7 @@ export const TableBody = ({
4116
colorMode,
4217
sourceId2ShortName,
4318
t,
44-
}: TableBodyProps) => {
19+
}) => {
4520
return (
4621
<tbody>
4722
{data.map((row, rowIndex) => (
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React from 'react';
2+
import { CellTooltipContent } from '../ui/components';
3+
import { cellStyle, hl } from '../utils';
4+
5+
export const TableCell = React.memo(
6+
({
7+
row,
8+
col,
9+
rowsAreAbx,
10+
rowIndex,
11+
colIndex,
12+
hoveredRow,
13+
hoveredCol,
14+
onSetHover,
15+
onClearHover,
16+
onShowTooltip,
17+
onHideTooltip,
18+
styles,
19+
colorMode,
20+
sourceId2ShortName,
21+
t,
22+
}) => {
23+
const cell = row[col.name];
24+
const highlight = hoveredRow === rowIndex || hoveredCol === colIndex;
25+
26+
const handleMouseEnter = (event) => {
27+
onSetHover(rowIndex, colIndex);
28+
const content = (
29+
<CellTooltipContent
30+
row={row}
31+
col={col}
32+
cell={cell}
33+
rowsAreAbx={rowsAreAbx}
34+
sourceName={cell?.source_id ? sourceId2ShortName.get(cell.source_id) : undefined}
35+
t={t}
36+
/>
37+
);
38+
onShowTooltip(content, event.currentTarget);
39+
};
40+
41+
const handleMouseLeave = () => {
42+
onClearHover();
43+
onHideTooltip();
44+
};
45+
46+
return (
47+
<td
48+
style={{
49+
...cellStyle(cell?.pct, colorMode),
50+
...(highlight ? hl : {}),
51+
}}
52+
onMouseEnter={handleMouseEnter}
53+
onMouseLeave={handleMouseLeave}
54+
onClick={handleMouseEnter}
55+
>
56+
<span className={styles.fullCellTrigger}>
57+
{cell ? `${cell.pct}%` : '—'}
58+
</span>
59+
</td>
60+
);
61+
},
62+
);

dist/theme/ResistanceTable/components/TableCell.tsx

Lines changed: 0 additions & 94 deletions
This file was deleted.

src/theme/ResistanceTable/components/TableHeader.tsx renamed to dist/theme/ResistanceTable/components/TableHeader.jsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
import React from 'react';
22
import { TableHeaderCell } from './TableHeaderCell';
33

4-
// Mock types
5-
type FormattedCol = { id: string; name: string; short: string };
6-
type DisplayMode = 'full' | 'compact' | 'superCompact';
7-
8-
interface TableHeaderProps {
9-
cols: FormattedCol[];
10-
displayMode: DisplayMode;
11-
hoveredCol: number | null;
12-
onSetHover: (row: number, col: number) => void;
13-
onClearHover: () => void;
14-
onShowTooltip: (content: React.ReactNode, element: HTMLElement) => void;
15-
onHideTooltip: () => void;
16-
styles: any;
17-
}
18-
194
export const TableHeader = ({
205
cols,
216
displayMode,
@@ -25,8 +10,8 @@ export const TableHeader = ({
2510
onShowTooltip,
2611
onHideTooltip,
2712
styles,
28-
}: TableHeaderProps) => {
29-
const abxCol = { whiteSpace: 'nowrap', width: '1%' } as const;
13+
}) => {
14+
const abxCol = { whiteSpace: 'nowrap', width: '1%' };
3015

3116
return (
3217
<thead>

dist/theme/ResistanceTable/components/TableHeaderCell.tsx renamed to dist/theme/ResistanceTable/components/TableHeaderCell.jsx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
import React from 'react';
22
import { hl } from '../utils';
33

4-
// Mock types
5-
type FormattedCol = { id: string; name: string; short: string };
6-
type DisplayMode = 'full' | 'compact' | 'superCompact';
7-
8-
interface TableHeaderCellProps {
9-
col: FormattedCol;
10-
colIndex: number;
11-
displayMode: DisplayMode;
12-
hoveredCol: number | null;
13-
onSetHover: (row: number, col: number) => void;
14-
onClearHover: () => void;
15-
onShowTooltip: (content: React.ReactNode, element: HTMLElement) => void;
16-
onHideTooltip: () => void;
17-
styles: any;
18-
}
19-
204
export const TableHeaderCell = React.memo(
215
({
226
col,
@@ -28,10 +12,10 @@ export const TableHeaderCell = React.memo(
2812
onShowTooltip,
2913
onHideTooltip,
3014
styles,
31-
}: TableHeaderCellProps) => {
15+
}) => {
3216
const highlight = hoveredCol === colIndex;
3317

34-
const handleMouseEnter = (event: React.MouseEvent<HTMLTableCellElement>) => {
18+
const handleMouseEnter = (event) => {
3519
onSetHover(-1, colIndex);
3620
if (displayMode !== 'full') {
3721
onShowTooltip(col.name, event.currentTarget);

src/theme/ResistanceTable/components/TableRow.tsx renamed to dist/theme/ResistanceTable/components/TableRow.jsx

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,6 @@
11
import React from 'react';
22
import { TableCell } from './TableCell';
33
import { hl } from '../utils';
4-
import { getTranslator } from '../i18n';
5-
6-
type Translator = ReturnType<typeof getTranslator>;
7-
8-
// Mock types
9-
type FormattedRow = Record<string, any> & { rowLong: string; rowShort: string };
10-
type FormattedCol = { id: string; name: string; short: string };
11-
type DisplayMode = 'full' | 'compact' | 'superCompact';
12-
13-
interface TableRowProps {
14-
row: FormattedRow;
15-
cols: FormattedCol[];
16-
rowIndex: number;
17-
displayMode: DisplayMode;
18-
rowsAreAbx: boolean;
19-
hoveredRow: number | null;
20-
hoveredCol: number | null;
21-
onSetHover: (row: number, col: number) => void;
22-
onClearHover: () => void;
23-
onShowTooltip: (content: React.ReactNode, element: HTMLElement) => void;
24-
onHideTooltip: () => void;
25-
styles: any;
26-
colorMode: 'dark' | 'light';
27-
sourceId2ShortName: Map<string, string>;
28-
t: Translator;
29-
}
304

315
export const TableRow = React.memo(
326
({
@@ -45,11 +19,11 @@ export const TableRow = React.memo(
4519
colorMode,
4620
sourceId2ShortName,
4721
t,
48-
}: TableRowProps) => {
22+
}) => {
4923
const highlight = hoveredRow === rowIndex;
50-
const abxCol = { whiteSpace: 'nowrap', width: '1%' } as const;
24+
const abxCol = { whiteSpace: 'nowrap', width: '1%' };
5125

52-
const handleMouseEnter = (event: React.MouseEvent<HTMLTableCellElement>) => {
26+
const handleMouseEnter = (event) => {
5327
onSetHover(rowIndex, -1); // Hover the whole row
5428
if (displayMode !== 'full') {
5529
onShowTooltip(row.rowLong, event.currentTarget);
File renamed without changes.

0 commit comments

Comments
 (0)