Skip to content

Commit 248125a

Browse files
authored
Merge pull request #120 from MaaAssistantArknights/dev
feat: multiple
2 parents a50d1db + 35afac3 commit 248125a

File tree

5 files changed

+163
-94
lines changed

5 files changed

+163
-94
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"@dnd-kit/utilities": "^3.2.0",
2828
"@iconify/icons-simple-icons": "^1.2.22",
2929
"@iconify/react": "^3.2.2",
30-
"@sentry/react": "^7.4.1",
31-
"@sentry/tracing": "^7.4.1",
30+
"@sentry/react": "^7.27.0",
31+
"@sentry/tracing": "^7.27.0",
3232
"@typescript-eslint/eslint-plugin": "^5.33.1",
3333
"ajv": "^8.11.0",
3434
"ajv-i18n": "^4.2.0",

src/components/editor/floatingMap/FloatingMap.tsx

Lines changed: 105 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import { Card, NonIdealState, Spinner } from '@blueprintjs/core'
1+
import { Button, Card, NonIdealState, Spinner } from '@blueprintjs/core'
22

3+
import clsx from 'clsx'
4+
import { clamp } from 'lodash-es'
35
import { useCallback, useEffect, useState } from 'react'
46
import { createPortal } from 'react-dom'
57
import { Rnd, RndResizeCallback } from 'react-rnd'
8+
import { useWindowSize } from 'react-use'
69

710
import { sendMessage, useMessage } from '../../../utils/messenger'
811
import { useLazyStorage } from '../../../utils/useLazyStorage'
@@ -17,6 +20,7 @@ import {
1720
} from './connection'
1821

1922
interface FloatingMapConfig {
23+
show: boolean
2024
x: number
2125
y: number
2226
width: number
@@ -26,6 +30,8 @@ interface FloatingMapConfig {
2630
const UID = 'floating-map'
2731
const STORAGE_KEY = `copilot-${UID}`
2832

33+
const HEADER_CLASS = 'floating-map-header'
34+
2935
const HEADER_HEIGHT = 16
3036
const ASPECT_RATIO = 16 / 9
3137
const MIN_HEIGHT = 150 + HEADER_HEIGHT
@@ -43,6 +49,7 @@ export function FloatingMap() {
4349
const [config, setConfig] = useLazyStorage<FloatingMapConfig>(
4450
STORAGE_KEY,
4551
{
52+
show: true,
4653
x: 0,
4754
y: window.innerHeight - DEFAULT_HEIGHT,
4855
width: DEFAULT_WIDTH,
@@ -52,6 +59,16 @@ export function FloatingMap() {
5259
(savedValue, defaultValue) => ({ ...defaultValue, ...savedValue }),
5360
)
5461

62+
const { width: windowWidth, height: windowHeight } = useWindowSize()
63+
64+
useEffect(() => {
65+
setConfig((cfg) => ({
66+
...cfg,
67+
x: clamp(cfg.x, 0, windowWidth - cfg.width),
68+
y: clamp(cfg.y, 0, windowHeight - cfg.height),
69+
}))
70+
}, [windowWidth, windowHeight])
71+
5572
const [iframeWindow, setIframeWindow] = useState<Window | null | undefined>()
5673
const [mapStatus, setMapStatus] = useState(MapStatus.Loading)
5774

@@ -137,55 +154,98 @@ export function FloatingMap() {
137154

138155
return createPortal(
139156
<div className="fixed z-30 inset-0 pointer-events-none">
140-
<Rnd
141-
className="pointer-events-auto"
142-
dragHandleClassName="drag-handle"
143-
bounds="window"
144-
minWidth={MIN_WIDTH}
145-
minHeight={MIN_HEIGHT}
146-
lockAspectRatio={ASPECT_RATIO}
147-
lockAspectRatioExtraHeight={HEADER_HEIGHT}
148-
default={config}
149-
onDragStart={onDragStartHandler}
150-
onDragStop={onDragStopHandler}
151-
onResizeStart={onResizeStartHandler}
152-
onResizeStop={onResizeStopHandler}
153-
>
154-
<Card
155-
className="h-full !p-0 flex flex-col overflow-hidden"
156-
elevation={3}
157+
{config.show ? (
158+
<Rnd
159+
className="pointer-events-auto"
160+
dragHandleClassName={HEADER_CLASS}
161+
bounds="window"
162+
minWidth={MIN_WIDTH}
163+
minHeight={MIN_HEIGHT}
164+
lockAspectRatio={ASPECT_RATIO}
165+
lockAspectRatioExtraHeight={HEADER_HEIGHT}
166+
default={config}
167+
position={config}
168+
onDragStart={onDragStartHandler}
169+
onDragStop={onDragStopHandler}
170+
onResizeStart={onResizeStartHandler}
171+
onResizeStop={onResizeStopHandler}
157172
>
158-
<div
159-
className="drag-handle cursor-move bg-gray-200"
160-
style={{ height: HEADER_HEIGHT }}
161-
/>
162-
{level ? (
163-
<div className="relative flex-grow">
164-
<iframe
165-
title={UID}
166-
className="w-full h-full"
167-
src={getMapUrl(level)}
168-
onLoad={(e) => {
169-
setIframeWindow((e.target as HTMLIFrameElement).contentWindow)
170-
}}
171-
/>
172-
{mapStatus === MapStatus.Loading && (
173-
<NonIdealState
174-
className="absolute inset-0 bg-gray-900/50 [&_*]:!text-white"
175-
icon={
176-
<Spinner className="[&_.bp4-spinner-head]:stroke-current" />
177-
}
178-
description={iframeWindow ? undefined : '等待地图连接...'}
173+
<Card
174+
className="h-full !p-0 flex flex-col overflow-hidden"
175+
elevation={3}
176+
>
177+
<FloatingMapHeader config={config} setConfig={setConfig} />
178+
{level ? (
179+
<div className="relative flex-grow">
180+
<iframe
181+
title={UID}
182+
className="w-full h-full"
183+
src={getMapUrl(level)}
184+
onLoad={(e) => {
185+
setIframeWindow(
186+
(e.target as HTMLIFrameElement).contentWindow,
187+
)
188+
}}
179189
/>
180-
)}
181-
</div>
182-
) : (
183-
<NonIdealState icon="area-of-interest" title="未选择关卡" />
184-
)}
190+
{mapStatus === MapStatus.Loading && (
191+
<NonIdealState
192+
className="absolute inset-0 bg-gray-900/50 [&_*]:!text-white"
193+
icon={
194+
<Spinner className="[&_.bp4-spinner-head]:stroke-current" />
195+
}
196+
description={iframeWindow ? undefined : '等待地图连接...'}
197+
/>
198+
)}
199+
</div>
200+
) : (
201+
<NonIdealState icon="area-of-interest" title="未选择关卡" />
202+
)}
203+
</Card>
204+
</Rnd>
205+
) : (
206+
<Card
207+
className="absolute !p-0 overflow-hidden pointer-events-auto"
208+
elevation={2}
209+
style={{ left: 0, bottom: 0 }}
210+
>
211+
<FloatingMapHeader config={config} setConfig={setConfig} />
185212
</Card>
186-
</Rnd>
213+
)}
187214
</div>,
188215

189216
document.body,
190217
)
191218
}
219+
220+
function FloatingMapHeader({
221+
className,
222+
config,
223+
setConfig,
224+
}: {
225+
className?: string
226+
config: FloatingMapConfig
227+
setConfig: (config: FloatingMapConfig) => void
228+
}) {
229+
return (
230+
<div
231+
className={clsx(
232+
className,
233+
HEADER_CLASS,
234+
'flex items-center text-xs bg-gray-200',
235+
config.show ? 'cursor-move' : 'cursor-default',
236+
)}
237+
style={{ height: HEADER_HEIGHT }}
238+
>
239+
<Button
240+
minimal
241+
small={!config.show}
242+
className="min-h-0 !py-0"
243+
title={config.show ? '隐藏地图' : '显示地图'}
244+
icon={config.show ? 'caret-down' : 'caret-up'}
245+
onClick={() => setConfig({ ...config, show: !config.show })}
246+
>
247+
{!config.show && '地图'}
248+
</Button>
249+
</div>
250+
)
251+
}

src/main.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ import './styles/index.css'
2222

2323
Sentry.init({
2424
dsn: 'https://[email protected]/6545242',
25-
integrations: [new BrowserTracing()],
25+
integrations: [new BrowserTracing(), new Sentry.Replay()],
2626
tracesSampleRate: 0.05,
27+
28+
replaysSessionSampleRate: 0.001,
29+
replaysOnErrorSampleRate: 0.1,
30+
31+
debug: import.meta.env.DEV,
32+
2733
enabled: import.meta.env.PROD,
2834
beforeSend: (event) => {
2935
if (import.meta.env.DEV) return null

vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ export default defineConfig({
1111
src: require('path').resolve(__dirname, 'src'),
1212
},
1313
},
14+
build: {
15+
sourcemap: true,
16+
},
1417
})

yarn.lock

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -892,67 +892,67 @@
892892
estree-walker "^2.0.1"
893893
picomatch "^2.2.2"
894894

895-
896-
version "7.8.0"
897-
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-7.8.0.tgz#0430d327d6a44901f42fdee11a8a983dfcebd7ab"
898-
integrity sha512-khVrQ0/cfPgm4dAYc07TbHO+dGvaq5adjbIkzpQy0t64KI1GLz++JXv1GRHh5EF9J5kOTaDZX6EyKCa/zDNfxw==
899-
dependencies:
900-
"@sentry/core" "7.8.0"
901-
"@sentry/types" "7.8.0"
902-
"@sentry/utils" "7.8.0"
895+
896+
version "7.32.1"
897+
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-7.32.1.tgz#e2b9ffbaf79ce3824a107068faea02b964c9ac21"
898+
integrity sha512-w2Ay8Y28maboyA/pgNRhNxCth0pCYsJ7co5oLVAGptjOFudeihD4Bx2wthz6sfk9DpxzqtUIGa54edcniyk14g==
899+
dependencies:
900+
"@sentry/core" "7.32.1"
901+
"@sentry/replay" "7.32.1"
902+
"@sentry/types" "7.32.1"
903+
"@sentry/utils" "7.32.1"
903904
tslib "^1.9.3"
904905

905-
"@sentry/core@7.8.0":
906-
version "7.8.0"
907-
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.8.0.tgz#3ab3a4cb4389527e3ca08031a02f010ec52287e8"
908-
integrity sha512-Xogwy96P6o3qgSLIGHxzKnRxrky8QdHpnS4A6ZWjnnFFAJmMg3MPF9SmqK5dOUpO9K69jTad9vs6ES2qTydfIw==
906+
"@sentry/core@7.32.1":
907+
version "7.32.1"
908+
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.32.1.tgz#d47d95c6a9ed90d4d6db04fb2ec0d3206ac4d2f2"
909+
integrity sha512-WHCFdlvK+YiGPjjmwLLvueH7zMYxLgNl0esCQUrqoTHhZ4asIV8k3/5OXgUi4kV2DW+NjzhmtK3qKeWZxgitfw==
909910
dependencies:
910-
"@sentry/hub" "7.8.0"
911-
"@sentry/types" "7.8.0"
912-
"@sentry/utils" "7.8.0"
911+
"@sentry/types" "7.32.1"
912+
"@sentry/utils" "7.32.1"
913913
tslib "^1.9.3"
914914

915-
"@sentry/[email protected].0":
916-
version "7.8.0"
917-
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-7.8.0.tgz#ba261fff11f389511b2a2f7ccd4466dc781d1a8d"
918-
integrity sha512-L+aZ7XQJ5cM9NFBy/4caTyBVOc5DB6LK1wxPSFxCy1zsr/XpEYqTAy6ATRUeC0UKxdd/sN/lnQ8liGwVAc0gGQ==
915+
"@sentry/react@^7.27.0":
916+
version "7.32.1"
917+
resolved "https://registry.yarnpkg.com/@sentry/react/-/react-7.32.1.tgz#3de919c8a4c828cf95ba2703916244b78306d0b0"
918+
integrity sha512-DeI5N0nTn4tc1/4+ZeiSyGoMBYsYTqoRBn8F/UBMNIMseBh4/6d85QX6HyyrZi0o/N9jzMq0mnxJNJlNaicHfQ==
919919
dependencies:
920-
"@sentry/types" "7.8.0"
921-
"@sentry/utils" "7.8.0"
920+
"@sentry/browser" "7.32.1"
921+
"@sentry/types" "7.32.1"
922+
"@sentry/utils" "7.32.1"
923+
hoist-non-react-statics "^3.3.2"
922924
tslib "^1.9.3"
923925

924-
"@sentry/react@^7.4.1":
925-
version "7.8.0"
926-
resolved "https://registry.yarnpkg.com/@sentry/react/-/react-7.8.0.tgz#6d4deea2b9b351454812945c414746d2c607b7db"
927-
integrity sha512-oQLyRAyCBbb1sGnRjpeRNt7fKYYPoCM0XYiDdmudLFoQLkBNaVRm/JmYa+Ja009zV8NPG5v9yC8Ys/mIBLRgvg==
926+
"@sentry/[email protected].1":
927+
version "7.32.1"
928+
resolved "https://registry.yarnpkg.com/@sentry/replay/-/replay-7.32.1.tgz#8a6db7c529bd2d0365798c6c77fcecfea2995df5"
929+
integrity sha512-nRy2upcZecRveMCatyeukNQQH39/9lSF/j6PhWTRyHcam5bvOb2d2mM0TiIfvYxNM1ePb+9SvX1W0qqpmvqyGA==
928930
dependencies:
929-
"@sentry/browser" "7.8.0"
930-
"@sentry/types" "7.8.0"
931-
"@sentry/utils" "7.8.0"
932-
hoist-non-react-statics "^3.3.2"
933-
tslib "^1.9.3"
931+
"@sentry/core" "7.32.1"
932+
"@sentry/types" "7.32.1"
933+
"@sentry/utils" "7.32.1"
934934

935-
"@sentry/tracing@^7.4.1":
936-
version "7.8.0"
937-
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-7.8.0.tgz#e803317f26bd54b05f95f78cdc456979f786627e"
938-
integrity sha512-qhem3wJgyd2tgRk0nHMGkWtiI3ln0ZdN8N+5hLnW+CrSz8Xm5/L5gwWQszOFG7WCYM3wRYEV093MuHg+qTg8iA==
935+
"@sentry/tracing@^7.27.0":
936+
version "7.32.1"
937+
resolved "https://registry.yarnpkg.com/@sentry/tracing/-/tracing-7.32.1.tgz#762e1690fa70d27ab2f38034b0ee6cbb250da626"
938+
integrity sha512-MG67+DzsbEM0p7+g/H5DQqsjFCXkvF50gK2+8EpfO6N2uqYpELPMIeTkERtMiqjhkDZ11bokWKE33CvA/TEF5Q==
939939
dependencies:
940-
"@sentry/hub" "7.8.0"
941-
"@sentry/types" "7.8.0"
942-
"@sentry/utils" "7.8.0"
940+
"@sentry/core" "7.32.1"
941+
"@sentry/types" "7.32.1"
942+
"@sentry/utils" "7.32.1"
943943
tslib "^1.9.3"
944944

945-
"@sentry/types@7.8.0":
946-
version "7.8.0"
947-
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.8.0.tgz#009ee9c53b474030a6b14025a8904b6260d57484"
948-
integrity sha512-X9D2jlcAzbJdCHA+eCMv2t5HI9769Qpx48e+sZiK7Oasy1jwQtqzQRaiI9fy/zZ+p7Fyerj/4WjW/E2c4dJ63w==
945+
"@sentry/types@7.32.1":
946+
version "7.32.1"
947+
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.32.1.tgz#24728cf098694d31ceb4f556164674477c6433d6"
948+
integrity sha512-yWS5no9Xxftgb6IGjj7iK6TvOk6rfy2H5gKcj4DrPqSWKmh0jfszUoX4B+olkt7H75sTSQqv3yiuMsySsMh+6Q==
949949

950-
"@sentry/utils@7.8.0":
951-
version "7.8.0"
952-
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.8.0.tgz#ed9b9a607fa51125a48140b1ea836603202d3cc2"
953-
integrity sha512-6WvXawUPs60R9MitHXFL533D/Ic9tqQZbvPnBXmAkfp90Y5rcoq2QfJjkqMk/Z+Gnplwi8/wcJCC8EtYKfWg6w==
950+
"@sentry/utils@7.32.1":
951+
version "7.32.1"
952+
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.32.1.tgz#217663cbaa9e47e96c2ac92018e4eba3c1f26ecb"
953+
integrity sha512-kZVpqRTC+UiI/PlSxEuv0G5G0lZeTZTL/pyRb8sptLhFo7QxEaGO/XCDNzWC4vQdm5PrpCVZ6w/XCYCHEhx4Tw==
954954
dependencies:
955-
"@sentry/types" "7.8.0"
955+
"@sentry/types" "7.32.1"
956956
tslib "^1.9.3"
957957

958958
"@trivago/prettier-plugin-sort-imports@^3.3.0":

0 commit comments

Comments
 (0)