Skip to content
Merged
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.pnp.js

# testing
/coverage
coverage/

# production
/build
Expand Down
287 changes: 284 additions & 3 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"react-router-dom": "^7.9.6"
},
"devDependencies": {
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.39.1",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.0",
Expand All @@ -40,6 +39,7 @@
"@types/react-router-dom": "^5.3.3",
"@vitejs/plugin-legacy": "^7.2.1",
"@vitejs/plugin-react": "^5.1.1",
"@vitest/coverage-v8": "^4.0.10",
"eslint": "^9.39.1",
"eslint-plugin-prettier": "^5.5.4",
"eslint-plugin-react": "^7.37.5",
Expand All @@ -54,10 +54,10 @@
"scripts": {
"dev": "vite --host",
"build": "tsc && vite build",
"test": "vitest",
"test": "vitest run --coverage",
"lint": "eslint ./src",
"lint:fix": "eslint ./src --fix",
"preview": "vite preview"
},
"version": "5.20.11"
"version": "5.21.0-0"
}
20 changes: 19 additions & 1 deletion src/components/side-panel/style-side-panel/design-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import {
setLineNum,
setPanelType,
setPlatform,
setPsdLabel,
setPsdNum,
setSpanLineNum,
setTheme,
staggerStationNames,
toggleLineNameBeforeDestination,
} from '../../../redux/param/param-slice';
import { PanelTypeGZMTR, PanelTypeShmetro, RmgStyle, ShortDirection } from '../../../constants/constants';
import { PanelTypeGZMTR, PanelTypeShmetro, PsdLabel, RmgStyle, ShortDirection } from '../../../constants/constants';
import { MdSwapVert } from 'react-icons/md';
import { RmgButtonGroup, RmgFields, RmgFieldsField } from '@railmapgen/rmg-components';
import { useTranslation } from 'react-i18next';
Expand All @@ -37,6 +38,7 @@ export default function DesignSection() {
direction,
platform_num: platformNum,
psd_num: psdNum,
psdLabel,
coachNum,
namePosMTR,
customiseMTRDest,
Expand Down Expand Up @@ -149,6 +151,22 @@ export default function DesignSection() {
onChange: value => dispatch(setPsdNum(value)),
hidden: ![RmgStyle.GZMTR].includes(style),
},
{
type: 'custom',
label: t('Platform door label'),
component: (
<RmgButtonGroup
selections={[
{ label: '屏蔽门 Screen door', value: PsdLabel.screen },
{ label: '站台门 Platform door', value: PsdLabel.platform },
]}
defaultValue={psdLabel}
onChange={label => dispatch(setPsdLabel(label))}
/>
),
hidden: ![RmgStyle.GZMTR].includes(style),
minW: 260,
},
{
type: 'input',
label: t('Coach number'),
Expand Down
6 changes: 6 additions & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export enum ShortDirection {
right = 'r',
}

export enum PsdLabel {
screen = 'screen',
platform = 'platform',
}

export enum BranchStyle {
through = 'through',
nonThrough = 'nonthrough',
Expand Down Expand Up @@ -252,6 +257,7 @@ export interface RMGParam {
line_num: string;
spanLineNum?: boolean;
psd_num: string;
psdLabel: PsdLabel;
coachNum: string;
info_panel_type: PanelTypeGZMTR | PanelTypeShmetro;
notesGZMTR?: Note[];
Expand Down
1 change: 1 addition & 0 deletions src/i18n/translations/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
"Open selected": "打开选中项目",
"Open template": "打开模板",
"Paid area": "付费区换乘",
"Platform door label": "站台门标签",
"Project": "项目",
"Project selected is invalid or corrupted.": "选中的项目无效或已损坏。",
"Project Selector": "项目选择器",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/translations/zh-Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
"Open selected": "開啟所選專案",
"Open template": "開啟範本",
"Paid area": "付費區轉車",
"Platform door label": "幕門標籤",
"Project": "專案",
"Project selected is invalid or corrupted.": "所選專案無效或者已損壞。",
"Project Selector": "專案選擇器",
Expand Down
6 changes: 6 additions & 0 deletions src/redux/param/param-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Note,
PanelTypeGZMTR,
PanelTypeShmetro,
PsdLabel,
RMGParam,
RmgStyle,
ShortDirection,
Expand Down Expand Up @@ -84,6 +85,10 @@ const paramSlice = createSlice({
state.psd_num = action.payload;
},

setPsdLabel: (state, action: PayloadAction<PsdLabel>) => {
state.psdLabel = action.payload;
},

setCoachNum: (state, action: PayloadAction<string>) => {
state.coachNum = action.payload;
},
Expand Down Expand Up @@ -190,6 +195,7 @@ export const {
setLineNum,
setSpanLineNum,
setPsdNum,
setPsdLabel,
setCoachNum,
setPanelType,
addNote,
Expand Down
2 changes: 2 additions & 0 deletions src/redux/param/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Name,
PanelTypeGZMTR,
PanelTypeShmetro,
PsdLabel,
RMGParam,
RmgStyle,
Services,
Expand Down Expand Up @@ -115,6 +116,7 @@ export const initParam = (style: RmgStyle, language: LanguageCode): RMGParam =>
line_num: '1',
spanLineNum: true,
psd_num: '1',
psdLabel: PsdLabel.platform,
coachNum: '1',
info_panel_type: style === RmgStyle.SHMetro ? PanelTypeShmetro.sh : PanelTypeGZMTR.gz1,
direction_gz_x: 40,
Expand Down
7 changes: 4 additions & 3 deletions src/svgs/gzmtr/psd-number.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { MonoColour } from '@railmapgen/rmg-palette-resources';
import { SVGProps } from 'react';
import { PsdLabel } from '../../constants/constants';

interface PsdNumberProps extends SVGProps<SVGGElement> {
num: string;
psdLabel: PsdLabel;
inStrip?: boolean;
showAsPlatformDoor?: boolean;
}

export default function PsdNumber(props: PsdNumberProps) {
const { num, inStrip, showAsPlatformDoor, ...others } = props;
const { num, psdLabel, inStrip, ...others } = props;

return (
<g textAnchor="middle" fill={inStrip ? MonoColour.black : 'var(--rmg-theme-fg)'} {...others}>
<rect height={40} width={40} rx={4} x={-20} fill={inStrip ? '#fff' : 'var(--rmg-theme-colour)'} />
<text className="rmg-name__en" fontSize={20} dy={12}>
{num}
</text>
{showAsPlatformDoor ? (
{psdLabel === PsdLabel.platform ? (
<>
<text className="rmg-name__zh" fontSize={11} dy={26}>
站台门
Expand Down
2 changes: 2 additions & 0 deletions src/svgs/gzmtr/rail-map/railmap-gzmtr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const RailMapGZMTR = () => {
svg_height: svgHeight,
direction,
psd_num: psdNumber,
psdLabel,
info_panel_type: infoPanelType,
notesGZMTR: notes,
current_stn_idx: currentStationIndex,
Expand All @@ -42,6 +43,7 @@ const RailMapGZMTR = () => {
variant={infoPanelType}
isShowLight={infoPanelType === PanelTypeGZMTR.gz2otis}
isShowPSD={infoPanelType === PanelTypeGZMTR.gz2otis && psdNumber}
psdLabel={psdLabel}
/>

{!loop &&
Expand Down
2 changes: 2 additions & 0 deletions src/svgs/gzmtr/runin/runin-gzmtr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function RunInGZMTR() {
info_panel_type: infoPanelType,
platform_num: platformNumber,
psd_num: psdNumber,
psdLabel,
coachNum,
theme,
} = useRootSelector(store => store.param);
Expand All @@ -42,6 +43,7 @@ export default function RunInGZMTR() {
variant={infoPanelType}
isShowLight={infoPanelType !== PanelTypeGZMTR.gz2otis}
isShowPSD={infoPanelType !== PanelTypeGZMTR.gz2otis && psdNumber}
psdLabel={psdLabel}
/>

<g transform={infoPanelType === PanelTypeGZMTR.gz2otis ? otisTransforms.platform : ''}>
Expand Down
10 changes: 7 additions & 3 deletions src/svgs/gzmtr/strip-gzmtr.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { PanelTypeGZMTR, PanelTypeShmetro } from '../../constants/constants';
import { PanelTypeGZMTR, PanelTypeShmetro, PsdLabel } from '../../constants/constants';
import PsdNumber from './psd-number';
import { memo, useMemo } from 'react';

interface Props {
variant: PanelTypeGZMTR | PanelTypeShmetro;
isShowLight: boolean;
isShowPSD: false | string;
psdLabel: PsdLabel;
}

const StripGZMTR = (props: Props) => {
Expand Down Expand Up @@ -132,8 +133,8 @@ const PSD = memo(
return (
<PsdNumber
num={props.isShowPSD as string}
psdLabel={props.psdLabel}
inStrip={isInStrip}
showAsPlatformDoor={props.variant === PanelTypeGZMTR.gz11}
style={{
['--psd-dy' as any]: psdDy,
transform: 'translate(var(--translate-x), var(--translate-y))scale(var(--scale))',
Expand All @@ -146,5 +147,8 @@ const PSD = memo(
/>
);
},
(prevProps, nextProps) => prevProps.variant === nextProps.variant && prevProps.isShowPSD === nextProps.isShowPSD
(prevProps, nextProps) =>
prevProps.variant === nextProps.variant &&
prevProps.isShowPSD === nextProps.isShowPSD &&
prevProps.psdLabel === nextProps.psdLabel
);
18 changes: 17 additions & 1 deletion src/util/param-updater-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { MonoColour, Theme, updateTheme } from '@railmapgen/rmg-palette-resources';
import rmgRuntime, { logger } from '@railmapgen/rmg-runtime';
import { nanoid } from 'nanoid';
import { CanvasType, InterchangeGroup, Name, Note, RMGParam, RmgStyle, StationInfo } from '../constants/constants';
import {
CanvasType,
InterchangeGroup,
Name,
Note,
PsdLabel,
RMGParam,
RmgStyle,
StationInfo,
} from '../constants/constants';

export const updateParam = (param: { [x: string]: any }) => {
// Version 0.10
Expand Down Expand Up @@ -252,6 +261,7 @@ export const updateParam = (param: { [x: string]: any }) => {
v5_10_updateInterchangeGroup(param);
v5_17_updateLocalisedName(param);
v5_18_addStationNameSpacingAndSvgWidthPlatform(param);
v5_21_addPsdLabel(param);

sanitiseParam(param);
return param;
Expand Down Expand Up @@ -312,6 +322,12 @@ export const v5_18_addStationNameSpacingAndSvgWidthPlatform = (param: Record<str
}
};

export const v5_21_addPsdLabel = (param: Record<string, any>) => {
if (!('psdLabel' in param)) {
param.psdLabel = PsdLabel.screen;
}
};

interface MatchedThemeWithPaths {
path: string;
value: Theme;
Expand Down
31 changes: 15 additions & 16 deletions vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
/// <reference types="vitest/config" />

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import legacy from '@vitejs/plugin-legacy';
import { coverageConfigDefaults } from 'vitest/config';

// https://vitejs.dev/config
export default defineConfig({
base: '/rmg/',
plugins: [
react(),
legacy({
targets: ['defaults', '>0.2%', 'not dead'],
modernPolyfills: true,
}),
],
plugins: [react()],
build: {
rollupOptions: {
output: {
manualChunks: {
react: ['react', 'react-dom', 'react-router-dom', '@reduxjs/toolkit', 'react-redux', 'react-i18next'],
react: [
'react',
'react-dom',
'react-router-dom',
'@reduxjs/toolkit',
'react-redux',
'react-i18next',
],
chakra: ['@chakra-ui/react', '@emotion/react', '@emotion/styled', 'framer-motion', 'react-icons'],
'ag-grid-community': ['ag-grid-community'],
'ag-grid-react': ['ag-grid-react'],
Expand All @@ -39,11 +38,11 @@ export default defineConfig({
globals: true,
environment: 'jsdom',
setupFiles: './src/setupTests.ts',
server: {
deps: {
fallbackCJS: false,
},
},
watch: false,
coverage: {
provider: 'v8',
exclude: coverageConfigDefaults.exclude,
skipFull: true,
},
},
});