@a16n/web-sim 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -2
- package/bin/cli.ts +255 -0
- package/bin/web-sim.js +39 -0
- package/overrides/@backpackapp-io/react-native-toast/overrides.ts +15 -0
- package/overrides/@react-native-firebase/app/overrides.ts +34 -0
- package/overrides/@tiktok-for-business/react-native-sdk/NativeTiktokSdk.ts +29 -0
- package/overrides/@tiktok-for-business/react-native-sdk/overrides.ts +9 -0
- package/overrides/expo-application/ExpoApplication.ts +81 -0
- package/overrides/expo-application/overrides.ts +16 -0
- package/overrides/expo-background-task/ExpoBackgroundTaskModule.ts +30 -0
- package/overrides/expo-background-task/overrides.ts +9 -0
- package/overrides/expo-constants/ExponentConstants.ts +66 -0
- package/overrides/expo-constants/overrides.ts +9 -0
- package/overrides/expo-device/ExpoDevice.ts +104 -0
- package/overrides/expo-device/overrides.ts +9 -0
- package/overrides/expo-glass-effect/GlassContainer.tsx +9 -0
- package/overrides/expo-glass-effect/GlassView.tsx +95 -0
- package/overrides/expo-glass-effect/availability.ts +14 -0
- package/overrides/expo-glass-effect/overrides.ts +14 -0
- package/overrides/expo-haptics/Haptics.ts +67 -0
- package/overrides/expo-haptics/overrides.ts +5 -0
- package/overrides/expo-mail-composer/ExpoMailComposer.ts +40 -0
- package/overrides/expo-mail-composer/overrides.ts +9 -0
- package/overrides/expo-mesh-gradient/MeshGradientView.tsx +44 -0
- package/overrides/expo-mesh-gradient/overrides.ts +9 -0
- package/overrides/expo-modules-core/overrides.ts +12 -0
- package/overrides/expo-navigation-bar/ExpoNavigationBar.ts +29 -0
- package/overrides/expo-navigation-bar/NavigationBar.ts +43 -0
- package/overrides/expo-navigation-bar/overrides.ts +12 -0
- package/overrides/expo-router/NativeStackView.tsx +74 -0
- package/overrides/expo-router/NativeTabsView.tsx +263 -0
- package/overrides/expo-router/SafeAreaProvider.ts +6 -0
- package/overrides/expo-router/overrides.ts +23 -0
- package/overrides/expo-router/statusBarRequests.ts +51 -0
- package/overrides/expo-screen-orientation/ExpoScreenOrientation.ts +173 -0
- package/overrides/expo-screen-orientation/overrides.ts +21 -0
- package/overrides/expo-sharing/SharingNativeModule.ts +21 -0
- package/overrides/expo-sharing/overrides.ts +9 -0
- package/overrides/expo-sms/ExpoSMS.ts +24 -0
- package/overrides/expo-sms/overrides.ts +9 -0
- package/overrides/expo-splash-screen/SplashScreen.ts +25 -0
- package/overrides/expo-splash-screen/overrides.ts +5 -0
- package/overrides/expo-status-bar/StatusBar.tsx +44 -0
- package/overrides/expo-status-bar/overrides.ts +5 -0
- package/overrides/expo-store-review/ExpoStoreReview.ts +18 -0
- package/overrides/expo-store-review/overrides.ts +9 -0
- package/overrides/expo-symbols/SymbolView.tsx +192 -0
- package/overrides/expo-symbols/overrides.ts +9 -0
- package/overrides/expo-system-ui/ExpoSystemUI.ts +34 -0
- package/overrides/expo-system-ui/overrides.ts +9 -0
- package/overrides/expo-task-manager/ExpoTaskManager.ts +39 -0
- package/overrides/expo-task-manager/overrides.ts +9 -0
- package/overrides/expo-tracking-transparency/ExpoTrackingTransparency.ts +30 -0
- package/overrides/expo-tracking-transparency/overrides.ts +11 -0
- package/overrides/expo-video/ExpoVideo.ts +16 -0
- package/overrides/expo-video/overrides.ts +9 -0
- package/overrides/lottie-react-native/LottieView.tsx +87 -0
- package/overrides/lottie-react-native/overrides.ts +9 -0
- package/overrides/react-native-pager-view/PagerViewNativeComponent.tsx +254 -0
- package/overrides/react-native-pager-view/overrides.ts +9 -0
- package/overrides/react-native-reanimated/overrides.ts +28 -0
- package/overrides/react-native-safe-area-context/NativeSafeAreaProvider.tsx +40 -0
- package/overrides/react-native-safe-area-context/overrides.ts +12 -0
- package/overrides/react-native-share/NativeRNShare.ts +22 -0
- package/overrides/react-native-share/overrides.ts +12 -0
- package/overrides/react-native-share/platform.ts +14 -0
- package/overrides/react-native-turbo-image/TurboImage.tsx +101 -0
- package/overrides/react-native-turbo-image/overrides.ts +9 -0
- package/overrides/react-native-web/RefreshControl.tsx +57 -0
- package/overrides/react-native-web/overrides.ts +157 -0
- package/overrides/react-native-web/useElementLayout.ts +152 -0
- package/package.json +80 -4
- package/plugins/battery/overrides/expo-battery/ExpoBattery.ts +57 -0
- package/plugins/battery/overrides/expo-battery/overrides.ts +9 -0
- package/plugins/battery/plugin.ts +8 -0
- package/plugins/battery/shell.tsx +56 -0
- package/plugins/battery/state.ts +11 -0
- package/plugins/biometrics/overrides/expo-local-authentication/ExpoLocalAuthentication.ts +90 -0
- package/plugins/biometrics/overrides/expo-local-authentication/overrides.ts +11 -0
- package/plugins/biometrics/plugin.ts +8 -0
- package/plugins/biometrics/shell.tsx +88 -0
- package/plugins/biometrics/state.ts +41 -0
- package/plugins/brightness/app.ts +5 -0
- package/plugins/brightness/overrides/expo-brightness/Brightness.ts +98 -0
- package/plugins/brightness/overrides/expo-brightness/overrides.ts +10 -0
- package/plugins/brightness/plugin.ts +9 -0
- package/plugins/brightness/shell.tsx +55 -0
- package/plugins/brightness/state.ts +19 -0
- package/plugins/calendar/calendar.ts +299 -0
- package/plugins/calendar/overrides/expo-calendar/ExpoCalendar.ts +358 -0
- package/plugins/calendar/overrides/expo-calendar/LegacyExpoCalendar.ts +163 -0
- package/plugins/calendar/overrides/expo-calendar/overrides.ts +14 -0
- package/plugins/calendar/plugin.ts +8 -0
- package/plugins/calendar/shell.tsx +123 -0
- package/plugins/camera/overrides/expo-camera/ExpoCamera.tsx +269 -0
- package/plugins/camera/overrides/expo-camera/ExpoCameraManager.ts +56 -0
- package/plugins/camera/overrides/expo-camera/overrides.ts +12 -0
- package/plugins/camera/plugin.ts +9 -0
- package/plugins/camera/shell.tsx +107 -0
- package/plugins/camera/state.ts +61 -0
- package/plugins/clipboard/overrides/expo-clipboard/ExpoClipboard.ts +138 -0
- package/plugins/clipboard/overrides/expo-clipboard/overrides.ts +9 -0
- package/plugins/clipboard/plugin.ts +8 -0
- package/plugins/clipboard/shell.tsx +122 -0
- package/plugins/clipboard/state.ts +93 -0
- package/plugins/clock/app.ts +25 -0
- package/plugins/clock/plugin.ts +8 -0
- package/plugins/clock/shell.tsx +225 -0
- package/plugins/clock/state.ts +12 -0
- package/plugins/contacts/contacts.ts +125 -0
- package/plugins/contacts/overrides/expo-contacts/ExpoContacts.ts +153 -0
- package/plugins/contacts/overrides/expo-contacts/ExpoContactsNext.ts +232 -0
- package/plugins/contacts/overrides/expo-contacts/overrides.ts +12 -0
- package/plugins/contacts/plugin.ts +8 -0
- package/plugins/contacts/shell.tsx +109 -0
- package/plugins/home-indicator/app.ts +5 -0
- package/plugins/home-indicator/plugin.ts +9 -0
- package/plugins/home-indicator/requests.ts +48 -0
- package/plugins/home-indicator/shell.tsx +68 -0
- package/plugins/home-indicator/state.ts +31 -0
- package/plugins/keep-awake/app.ts +5 -0
- package/plugins/keep-awake/overrides/expo-keep-awake/ExpoKeepAwake.ts +27 -0
- package/plugins/keep-awake/overrides/expo-keep-awake/overrides.ts +9 -0
- package/plugins/keep-awake/plugin.ts +9 -0
- package/plugins/keep-awake/shell.tsx +80 -0
- package/plugins/keep-awake/state.ts +12 -0
- package/plugins/keyboard/Keyboard.tsx +354 -0
- package/plugins/keyboard/app.ts +90 -0
- package/plugins/keyboard/controller.ts +384 -0
- package/plugins/keyboard/fields.ts +244 -0
- package/plugins/keyboard/icons.tsx +283 -0
- package/plugins/keyboard/keyboard.css +362 -0
- package/plugins/keyboard/layouts/android.ts +175 -0
- package/plugins/keyboard/layouts/index.ts +10 -0
- package/plugins/keyboard/layouts/ios.ts +219 -0
- package/plugins/keyboard/layouts/types.ts +80 -0
- package/plugins/keyboard/overrides/react-native-keyboard-controller/KeyboardController.tsx +470 -0
- package/plugins/keyboard/overrides/react-native-keyboard-controller/overrides.ts +9 -0
- package/plugins/keyboard/plugin.ts +13 -0
- package/plugins/keyboard/shell.tsx +133 -0
- package/plugins/keyboard/state.ts +92 -0
- package/plugins/keyboard/suggestions.ts +63 -0
- package/plugins/keyboard/taps.ts +77 -0
- package/plugins/keyboard/typing.ts +112 -0
- package/plugins/locale/app.ts +232 -0
- package/plugins/locale/locale.ts +143 -0
- package/plugins/locale/overrides/expo-localization/ExpoLocalization.ts +41 -0
- package/plugins/locale/overrides/expo-localization/overrides.ts +9 -0
- package/plugins/locale/plugin.ts +9 -0
- package/plugins/locale/shell.tsx +147 -0
- package/plugins/locale/state.ts +36 -0
- package/plugins/location/geo.ts +56 -0
- package/plugins/location/overrides/expo-location/ExpoLocation.ts +235 -0
- package/plugins/location/overrides/expo-location/overrides.ts +11 -0
- package/plugins/location/places.ts +38 -0
- package/plugins/location/plugin.ts +8 -0
- package/plugins/location/shell.tsx +188 -0
- package/plugins/location/state.ts +51 -0
- package/plugins/motion/overrides/expo-sensors/DeviceSensor.ts +169 -0
- package/plugins/motion/overrides/expo-sensors/ExponentPedometer.ts +54 -0
- package/plugins/motion/overrides/expo-sensors/overrides.ts +14 -0
- package/plugins/motion/plugin.ts +8 -0
- package/plugins/motion/sensors.ts +116 -0
- package/plugins/motion/shell.tsx +136 -0
- package/plugins/motion/state.ts +46 -0
- package/plugins/network/app.ts +400 -0
- package/plugins/network/overrides/expo-network/ExpoNetwork.ts +51 -0
- package/plugins/network/overrides/expo-network/overrides.ts +9 -0
- package/plugins/network/plugin.ts +8 -0
- package/plugins/network/shell.tsx +67 -0
- package/plugins/network/state.ts +29 -0
- package/plugins/notifications/center.ts +255 -0
- package/plugins/notifications/content.ts +36 -0
- package/plugins/notifications/overrides/expo-notifications/NotificationsModule.ts +175 -0
- package/plugins/notifications/overrides/expo-notifications/channels.ts +108 -0
- package/plugins/notifications/overrides/expo-notifications/getDevicePushTokenAsync.ts +19 -0
- package/plugins/notifications/overrides/expo-notifications/getExpoPushTokenAsync.ts +16 -0
- package/plugins/notifications/overrides/expo-notifications/overrides.ts +36 -0
- package/plugins/notifications/plugin.ts +8 -0
- package/plugins/notifications/shell.tsx +192 -0
- package/plugins/notifications/state.ts +56 -0
- package/plugins/notifications/tokens.ts +47 -0
- package/plugins/notifications/trigger.ts +107 -0
- package/plugins/permissions/plugin.ts +6 -0
- package/plugins/permissions/shell.tsx +50 -0
- package/plugins/permissions/state.ts +38 -0
- package/plugins/photos/appLibrary.ts +114 -0
- package/plugins/photos/library.ts +322 -0
- package/plugins/photos/overrides/expo-image-picker/ExponentImagePicker.ts +153 -0
- package/plugins/photos/overrides/expo-image-picker/overrides.ts +13 -0
- package/plugins/photos/overrides/expo-media-library/ExpoMediaLibrary.ts +235 -0
- package/plugins/photos/overrides/expo-media-library/NativeMediaLibraryModule.ts +318 -0
- package/plugins/photos/overrides/expo-media-library/overrides.ts +19 -0
- package/plugins/photos/plugin.ts +8 -0
- package/plugins/photos/samples.ts +367 -0
- package/plugins/photos/shell.tsx +164 -0
- package/plugins/photos/state.ts +88 -0
- package/plugins/storage/files.ts +351 -0
- package/plugins/storage/overrides/expo-file-system/ExpoFileSystem.ts +770 -0
- package/plugins/storage/overrides/expo-file-system/ExponentFileSystem.ts +196 -0
- package/plugins/storage/overrides/expo-file-system/overrides.ts +13 -0
- package/plugins/storage/overrides/expo-secure-store/ExpoSecureStore.ts +75 -0
- package/plugins/storage/overrides/expo-secure-store/overrides.ts +9 -0
- package/plugins/storage/plugin.ts +8 -0
- package/plugins/storage/reset.ts +136 -0
- package/plugins/storage/secure.ts +71 -0
- package/plugins/storage/shell.tsx +365 -0
- package/plugins/storage/state.ts +13 -0
- package/src/client/app/appDocument.ts +129 -0
- package/src/client/app/appFocus.ts +97 -0
- package/src/client/app/console.ts +118 -0
- package/src/client/app/fonts.ts +76 -0
- package/src/client/app/main.tsx +99 -0
- package/src/client/app/routeContext.ts +45 -0
- package/src/client/app/touch.ts +640 -0
- package/src/client/entry.ts +20 -0
- package/src/client/modules.d.ts +8 -0
- package/src/client/react-native/app.ts +57 -0
- package/src/client/react-native/deep.ts +13 -0
- package/src/client/react-native/keyboard.tsx +192 -0
- package/src/client/react-native/library.ts +256 -0
- package/src/client/shell/Cookies.tsx +95 -0
- package/src/client/shell/LogDrawer.tsx +415 -0
- package/src/client/shell/PhotoPicker.tsx +174 -0
- package/src/client/shell/PluginOverlays.tsx +42 -0
- package/src/client/shell/PluginPanels.tsx +82 -0
- package/src/client/shell/ResetApp.tsx +87 -0
- package/src/client/shell/Resizer.tsx +99 -0
- package/src/client/shell/Shell.tsx +531 -0
- package/src/client/shell/SystemBars.tsx +376 -0
- package/src/client/shell/SystemCamera.tsx +181 -0
- package/src/client/shell/SystemOverlay.tsx +422 -0
- package/src/client/shell/SystemSheets.tsx +462 -0
- package/src/client/shell/backdrop.ts +229 -0
- package/src/client/shell/control.ts +91 -0
- package/src/client/shell/events.ts +226 -0
- package/src/client/shell/geometry.ts +68 -0
- package/src/client/shell/host.ts +492 -0
- package/src/client/shell/icons.tsx +34 -0
- package/src/client/shell/logFeed.ts +102 -0
- package/src/client/shell/main.tsx +22 -0
- package/src/client/shell/permissionCopy.ts +169 -0
- package/src/client/shell/plugins.ts +266 -0
- package/src/client/shell/popout.ts +185 -0
- package/src/client/shell/popover.ts +27 -0
- package/src/client/shell/shell.css +878 -0
- package/src/client/shell/statusTime.ts +31 -0
- package/src/client/shell/tooltips.ts +104 -0
- package/src/client/virtual.d.ts +23 -0
- package/src/devices/catalog.ts +223 -0
- package/src/devices/types.ts +83 -0
- package/src/node/appInfo.ts +188 -0
- package/src/node/appSource.ts +140 -0
- package/src/node/config.ts +180 -0
- package/src/node/control.ts +144 -0
- package/src/node/doctor.ts +199 -0
- package/src/node/events/cli.ts +206 -0
- package/src/node/events/shared.ts +238 -0
- package/src/node/events/store.ts +266 -0
- package/src/node/fonts.ts +377 -0
- package/src/node/index.ts +5 -0
- package/src/node/overrides/define.ts +56 -0
- package/src/node/overrides/packages.ts +136 -0
- package/src/node/overrides/platformPatch.ts +56 -0
- package/src/node/overrides/plugin.ts +169 -0
- package/src/node/overrides/registry.ts +258 -0
- package/src/node/paths.ts +18 -0
- package/src/node/platform.ts +171 -0
- package/src/node/plugins.ts +98 -0
- package/src/node/proxy.ts +421 -0
- package/src/node/server.ts +254 -0
- package/src/node/worklets.ts +86 -0
- package/src/plugin/index.ts +33 -0
- package/src/plugin/types.ts +127 -0
- package/src/plugin/ui.tsx +562 -0
- package/src/runtime/clock.ts +112 -0
- package/src/runtime/draw.ts +196 -0
- package/src/runtime/index.ts +519 -0
- package/src/runtime/media.ts +379 -0
- package/src/runtime/records.ts +76 -0
- package/src/runtime/timezone.ts +81 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ArrowCounterClockwiseIcon, CaretRightIcon } from '@phosphor-icons/react'
|
|
2
|
+
import { useState, useSyncExternalStore } from 'react'
|
|
3
|
+
import type { ShellPlugin } from '../../plugin/types.ts'
|
|
4
|
+
import type { SimState } from '../../runtime/index.ts'
|
|
5
|
+
import { USER } from './events.ts'
|
|
6
|
+
import type { PluginStore } from './plugins.ts'
|
|
7
|
+
|
|
8
|
+
// Sections start collapsed; this keeps the ones the user opened.
|
|
9
|
+
const EXPANDED_KEY = 'web-sim:panels-expanded'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The side panel: a section per plugin that has a panel and applies to the device's platform.
|
|
13
|
+
*/
|
|
14
|
+
export function PluginPanels({ store, sim }: { store: PluginStore; sim: SimState }) {
|
|
15
|
+
const [expanded, setExpanded] = useState<string[]>(() => readExpanded())
|
|
16
|
+
const shown = store.plugins.filter(
|
|
17
|
+
(plugin) => plugin.Panel !== undefined && (plugin.platforms === undefined || plugin.platforms.includes(sim.device.platform)),
|
|
18
|
+
)
|
|
19
|
+
const toggle = (id: string) => {
|
|
20
|
+
const next = expanded.includes(id) ? expanded.filter((other) => other !== id) : [...expanded, id]
|
|
21
|
+
setExpanded(next)
|
|
22
|
+
try {
|
|
23
|
+
localStorage.setItem(EXPANDED_KEY, JSON.stringify(next))
|
|
24
|
+
} catch {
|
|
25
|
+
// Storage blocked.
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return (
|
|
29
|
+
<aside className="ws-panels" aria-label="Plugins">
|
|
30
|
+
{shown.map((plugin) => (
|
|
31
|
+
<PanelSection key={plugin.id} plugin={plugin} store={store} sim={sim} open={expanded.includes(plugin.id)} onToggle={() => toggle(plugin.id)} />
|
|
32
|
+
))}
|
|
33
|
+
</aside>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function PanelSection({
|
|
38
|
+
plugin,
|
|
39
|
+
store,
|
|
40
|
+
sim,
|
|
41
|
+
open,
|
|
42
|
+
onToggle,
|
|
43
|
+
}: {
|
|
44
|
+
plugin: ShellPlugin
|
|
45
|
+
store: PluginStore
|
|
46
|
+
sim: SimState
|
|
47
|
+
open: boolean
|
|
48
|
+
onToggle: () => void
|
|
49
|
+
}) {
|
|
50
|
+
const subscribe = (listener: () => void) => store.subscribe(plugin.id, listener)
|
|
51
|
+
const state = useSyncExternalStore(subscribe, () => store.get(plugin.id)!)
|
|
52
|
+
const { Panel, icon: Icon } = plugin
|
|
53
|
+
// What the panel changes is the user's.
|
|
54
|
+
const context = store.context(plugin, USER)
|
|
55
|
+
return (
|
|
56
|
+
<section className="ws-panel" data-plugin={plugin.id}>
|
|
57
|
+
<header className="ws-panel-head">
|
|
58
|
+
<button type="button" className="ws-panel-title" onClick={onToggle} aria-expanded={open} data-tooltip={open ? `Collapse ${plugin.title}` : `Expand ${plugin.title}`}>
|
|
59
|
+
<CaretRightIcon size={14} className={open ? 'ws-panel-chevron ws-panel-chevron-open' : 'ws-panel-chevron'} />
|
|
60
|
+
{Icon !== undefined && <Icon size={14} />}
|
|
61
|
+
<span>{plugin.title}</span>
|
|
62
|
+
</button>
|
|
63
|
+
<button type="button" className="ws-icon-button ws-panel-reset" onClick={() => store.reset(plugin.id)} data-tooltip={`Reset ${plugin.title}`} aria-label={`Reset ${plugin.title}`}>
|
|
64
|
+
<ArrowCounterClockwiseIcon size={13} />
|
|
65
|
+
</button>
|
|
66
|
+
</header>
|
|
67
|
+
{open && Panel !== undefined && (
|
|
68
|
+
<div className="ws-panel-body">
|
|
69
|
+
<Panel state={state} set={context.set} emit={context.emit} run={(action, args) => store.run(plugin.id, action, args)} sim={sim} />
|
|
70
|
+
</div>
|
|
71
|
+
)}
|
|
72
|
+
</section>
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function readExpanded(): string[] {
|
|
77
|
+
try {
|
|
78
|
+
return JSON.parse(localStorage.getItem(EXPANDED_KEY) ?? '[]') as string[]
|
|
79
|
+
} catch {
|
|
80
|
+
return []
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { BroomIcon } from '@phosphor-icons/react'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import type { HostStore } from './host.ts'
|
|
4
|
+
import { usePopover } from './popover.ts'
|
|
5
|
+
|
|
6
|
+
/** The stores the storage plugin's `reset` action clears (`plugins/storage/reset.ts`), as the popover names them. */
|
|
7
|
+
const STORES = [
|
|
8
|
+
{ id: 'secureStore', label: 'Secure store', detail: 'expo-secure-store' },
|
|
9
|
+
{ id: 'files', label: 'Files', detail: 'expo-file-system' },
|
|
10
|
+
{ id: 'localStorage', label: 'AsyncStorage', detail: 'and the rest of localStorage, MMKV on web' },
|
|
11
|
+
{ id: 'databases', label: 'Databases', detail: "the app's IndexedDB, SQLite on web" },
|
|
12
|
+
{ id: 'cookies', label: 'Cookies', detail: 'the cookie jar' },
|
|
13
|
+
{ id: 'permissions', label: 'Permissions', detail: 'back to not asked' },
|
|
14
|
+
] as const
|
|
15
|
+
|
|
16
|
+
const CHOICE_KEY = 'web-sim:reset-stores'
|
|
17
|
+
|
|
18
|
+
function readChoice(): string[] {
|
|
19
|
+
try {
|
|
20
|
+
const saved = JSON.parse(localStorage.getItem(CHOICE_KEY) ?? 'null') as unknown
|
|
21
|
+
return Array.isArray(saved) ? saved.filter((id) => STORES.some((store) => store.id === id)) : STORES.map((store) => store.id)
|
|
22
|
+
} catch {
|
|
23
|
+
return STORES.map((store) => store.id)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The toolbar's reset: ticks for what to clear, then the app is stopped, cleared and launched again, as deleting and
|
|
29
|
+
* reinstalling it does. It runs the storage plugin's `reset` action, as `web-sim run storage reset` does, so it is
|
|
30
|
+
* logged the same way. The ticks are remembered.
|
|
31
|
+
*/
|
|
32
|
+
export function ResetButton({ host }: { host: HostStore }) {
|
|
33
|
+
const { open, setOpen, root } = usePopover()
|
|
34
|
+
const [chosen, setChosen] = useState(readChoice)
|
|
35
|
+
const [busy, setBusy] = useState(false)
|
|
36
|
+
if (!host.plugins.plugins.some((plugin) => plugin.id === 'storage' && plugin.actions?.reset !== undefined)) {
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
const toggle = (id: string, on: boolean) => {
|
|
40
|
+
const next = STORES.map((store) => store.id).filter((store) => (store === id ? on : chosen.includes(store)))
|
|
41
|
+
setChosen(next)
|
|
42
|
+
try {
|
|
43
|
+
localStorage.setItem(CHOICE_KEY, JSON.stringify(next))
|
|
44
|
+
} catch {
|
|
45
|
+
// Storage blocked: kept until the tab closes.
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const reset = async () => {
|
|
49
|
+
setBusy(true)
|
|
50
|
+
try {
|
|
51
|
+
await host.plugins.run('storage', 'reset', chosen.length === STORES.length ? undefined : { only: chosen })
|
|
52
|
+
} finally {
|
|
53
|
+
setBusy(false)
|
|
54
|
+
setOpen(false)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const label = open ? 'Hide reset' : 'Reset app'
|
|
58
|
+
return (
|
|
59
|
+
<div className="ws-popover-anchor" ref={root}>
|
|
60
|
+
<button type="button" className="ws-icon-button" onClick={() => setOpen(!open)} data-tooltip={label} aria-label={label} aria-pressed={open} aria-expanded={open}>
|
|
61
|
+
<BroomIcon size={16} />
|
|
62
|
+
</button>
|
|
63
|
+
{open && (
|
|
64
|
+
<div className="ws-popover ws-reset" role="dialog" aria-label="Reset app">
|
|
65
|
+
<div className="ws-popover-head">
|
|
66
|
+
<span className="ws-popover-title">Reset app</span>
|
|
67
|
+
</div>
|
|
68
|
+
<div className="ws-reset-stores">
|
|
69
|
+
{STORES.map((store) => (
|
|
70
|
+
<label key={store.id} className="ws-reset-store">
|
|
71
|
+
<input type="checkbox" checked={chosen.includes(store.id)} onChange={(event) => toggle(store.id, event.target.checked)} />
|
|
72
|
+
<span className="ws-reset-text">
|
|
73
|
+
<span>{store.label}</span>
|
|
74
|
+
<span className="ws-reset-detail">{store.detail}</span>
|
|
75
|
+
</span>
|
|
76
|
+
</label>
|
|
77
|
+
))}
|
|
78
|
+
</div>
|
|
79
|
+
<p className="ws-reset-note">The app stops, what's ticked is cleared, and it launches again.</p>
|
|
80
|
+
<button type="button" className="ws-text-button ws-danger-button" disabled={chosen.length === 0 || busy} onClick={() => void reset()}>
|
|
81
|
+
{busy ? 'Resetting…' : 'Reset'}
|
|
82
|
+
</button>
|
|
83
|
+
</div>
|
|
84
|
+
)}
|
|
85
|
+
</div>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { type PointerEvent as ReactPointerEvent, useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
type Size = { width: number; height: number }
|
|
4
|
+
|
|
5
|
+
type Axis = 'x' | 'y' | 'xy'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Handles on a resizable device's right edge, bottom edge and corner, as Chrome's responsive mode has. The device
|
|
9
|
+
* stays centred, so an edge moves half as far as the size changes: a drag of one point grows it by two, and the edge
|
|
10
|
+
* stays under the pointer. `scale` is the device's drawn scale, held still by the caller while a drag lasts.
|
|
11
|
+
*/
|
|
12
|
+
export function ResizeHandles({
|
|
13
|
+
size,
|
|
14
|
+
scale,
|
|
15
|
+
slot,
|
|
16
|
+
onResize,
|
|
17
|
+
onDragChange,
|
|
18
|
+
}: {
|
|
19
|
+
/** The screen's size as drawn, in the current orientation. */
|
|
20
|
+
size: Size
|
|
21
|
+
scale: number
|
|
22
|
+
/** The scaled device's box. */
|
|
23
|
+
slot: Size
|
|
24
|
+
onResize: (size: Size) => void
|
|
25
|
+
onDragChange: (dragging: boolean) => void
|
|
26
|
+
}) {
|
|
27
|
+
const start = (axis: Axis) => (event: ReactPointerEvent<HTMLDivElement>) => {
|
|
28
|
+
event.preventDefault()
|
|
29
|
+
const handle = event.currentTarget
|
|
30
|
+
handle.setPointerCapture(event.pointerId)
|
|
31
|
+
const origin = { x: event.clientX, y: event.clientY, ...size }
|
|
32
|
+
onDragChange(true)
|
|
33
|
+
const move = (moved: PointerEvent) => {
|
|
34
|
+
onResize({
|
|
35
|
+
width: axis === 'y' ? origin.width : origin.width + ((moved.clientX - origin.x) * 2) / scale,
|
|
36
|
+
height: axis === 'x' ? origin.height : origin.height + ((moved.clientY - origin.y) * 2) / scale,
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
const end = () => {
|
|
40
|
+
handle.removeEventListener('pointermove', move)
|
|
41
|
+
handle.removeEventListener('pointerup', end)
|
|
42
|
+
handle.removeEventListener('pointercancel', end)
|
|
43
|
+
onDragChange(false)
|
|
44
|
+
}
|
|
45
|
+
handle.addEventListener('pointermove', move)
|
|
46
|
+
handle.addEventListener('pointerup', end)
|
|
47
|
+
handle.addEventListener('pointercancel', end)
|
|
48
|
+
}
|
|
49
|
+
return (
|
|
50
|
+
<>
|
|
51
|
+
<div className="ws-resize ws-resize-x" style={{ left: slot.width + 6, height: slot.height }} onPointerDown={start('x')} data-tooltip="Resize" data-tooltip-side="right" />
|
|
52
|
+
<div className="ws-resize ws-resize-y" style={{ top: slot.height + 6, width: slot.width }} onPointerDown={start('y')} data-tooltip="Resize" />
|
|
53
|
+
<div className="ws-resize ws-resize-xy" style={{ left: slot.width + 4, top: slot.height + 4 }} onPointerDown={start('xy')} data-tooltip="Resize" data-tooltip-side="right" />
|
|
54
|
+
</>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The screen's width and height as fields in the toolbar, applied on Enter or when a field loses focus. */
|
|
59
|
+
export function SizeFields({ size, onResize }: { size: Size; onResize: (size: Size) => void }) {
|
|
60
|
+
return (
|
|
61
|
+
<span className="ws-size-fields">
|
|
62
|
+
<SizeField label="Width" value={size.width} onCommit={(width) => onResize({ ...size, width })} />
|
|
63
|
+
<span className="ws-size-times">×</span>
|
|
64
|
+
<SizeField label="Height" value={size.height} onCommit={(height) => onResize({ ...size, height })} />
|
|
65
|
+
</span>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function SizeField({ label, value, onCommit }: { label: string; value: number; onCommit: (value: number) => void }) {
|
|
70
|
+
const [text, setText] = useState(String(value))
|
|
71
|
+
useEffect(() => setText(String(value)), [value])
|
|
72
|
+
const commit = () => {
|
|
73
|
+
const number = Number(text)
|
|
74
|
+
if (Number.isFinite(number) && number > 0) {
|
|
75
|
+
onCommit(number)
|
|
76
|
+
} else {
|
|
77
|
+
setText(String(value))
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return (
|
|
81
|
+
<input
|
|
82
|
+
className="ws-size-field"
|
|
83
|
+
inputMode="numeric"
|
|
84
|
+
aria-label={label}
|
|
85
|
+
data-tooltip={label}
|
|
86
|
+
value={text}
|
|
87
|
+
onChange={(event) => setText(event.target.value)}
|
|
88
|
+
onBlur={commit}
|
|
89
|
+
onKeyDown={(event) => {
|
|
90
|
+
if (event.key === 'Enter') {
|
|
91
|
+
commit()
|
|
92
|
+
} else if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
|
|
93
|
+
event.preventDefault()
|
|
94
|
+
onCommit(value + (event.key === 'ArrowUp' ? 1 : -1) * (event.shiftKey ? 10 : 1))
|
|
95
|
+
}
|
|
96
|
+
}}
|
|
97
|
+
/>
|
|
98
|
+
)
|
|
99
|
+
}
|