Skip to content

Commit 739fc7c

Browse files
committed
fix(core): standalone mode plugins injection
1 parent 11a4aa0 commit 739fc7c

File tree

16 files changed

+128
-136
lines changed

16 files changed

+128
-136
lines changed

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"dev:standalone": "cd src/client/standalone && vite dev",
4646
"prepack": "pnpm build",
4747
"play": "DEBUG='vite:devtools:*' pnpm -C playground run dev",
48+
"play:standlone": "DEBUG='vite:devtools:*' pnpm -C playground run dev:standalone",
4849
"cli": "DEBUG='vite:devtools:*' tsx src/node/cli.ts",
4950
"play:build": "pnpm -C playground run build"
5051
},

packages/core/playground/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"private": true,
66
"scripts": {
77
"dev": "VITE_DEVTOOLS_LOCAL_DEV=true vite",
8+
"dev:standlone": "DEBUG='vite:devtools:*' VITE_DEVTOOLS_LOCAL_DEV=true tsx ../src/node/cli.ts",
89
"build": "vite build && vite-devtools"
910
}
1011
}

packages/core/src/client/inject/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/// <reference types="vite/client" />
22
/// <reference lib="dom" />
33

4-
import type { DockPanelState } from '../webcomponents'
4+
import type { DockPanelStorage } from '../webcomponents'
55
import { getDevToolsRpcClient } from '@vitejs/devtools-kit/client'
66
import { useLocalStorage } from '@vueuse/core'
7-
import { createDockContext } from '../webcomponents'
7+
import { createDocksContext } from '../webcomponents'
88

99
export async function init(): Promise<void> {
1010
// eslint-disable-next-line no-console
@@ -19,7 +19,7 @@ export async function init(): Promise<void> {
1919
// eslint-disable-next-line no-console
2020
console.log('[VITE DEVTOOLS] RPC Functions', rpcFunctions)
2121

22-
const state = useLocalStorage<DockPanelState>(
22+
const state = useLocalStorage<DockPanelStorage>(
2323
'vite-devtools-dock-state',
2424
{
2525
width: 80,
@@ -28,12 +28,12 @@ export async function init(): Promise<void> {
2828
left: 0,
2929
position: 'left',
3030
open: false,
31-
minimizePanelInactive: 3_000,
31+
inactiveTimeout: 3_000,
3232
},
3333
{ mergeDefaults: true },
3434
)
3535

36-
const context = await createDockContext(
36+
const context = await createDocksContext(
3737
'embedded',
3838
rpc,
3939
state,

packages/core/src/client/standalone/App.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script setup lang="ts">
2-
import type { DockContext } from '../webcomponents/state/dock'
2+
import type { DocksContext } from '../webcomponents/state/dock'
33
import { getDevToolsRpcClient } from '@vitejs/devtools-kit/client'
44
import { markRaw, useTemplateRef } from 'vue'
55
import DockEntries from '../webcomponents/components/DockEntries.vue'
66
import VitePlus from '../webcomponents/components/icons/VitePlus.vue'
77
import ViewEntry from '../webcomponents/components/ViewEntry.vue'
8-
import { createDockContext } from '../webcomponents/state/dock'
8+
import { createDocksContext } from '../webcomponents/state/dock'
99
import { useStateHandlers } from '../webcomponents/state/state'
1010
import { PresistedDomViewsManager } from '../webcomponents/utils/PresistedDomViewsManager'
1111
@@ -17,7 +17,7 @@ console.log('[VITE DEVTOOLS] RPC', rpc)
1717
const viewsContainer = useTemplateRef<HTMLElement>('viewsContainer')
1818
const presistedDoms = markRaw(new PresistedDomViewsManager(viewsContainer))
1919
20-
const context: DockContext = await createDockContext(
20+
const context: DocksContext = await createDocksContext(
2121
'standalone',
2222
rpc,
2323
)

packages/core/src/client/standalone/vite.config.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,6 @@ export default defineConfig({
1414
plugins: [
1515
Vue(),
1616
UnoCSS(),
17-
{
18-
name: 'local',
19-
devtools: {
20-
setup(ctx) {
21-
ctx.docks.register({
22-
title: 'Local',
23-
icon: 'https://upload.wikimedia.org/wikipedia/commons/9/95/Vue.js_Logo_2.svg',
24-
id: 'local',
25-
type: 'iframe',
26-
url: 'https://antfu.me',
27-
})
28-
},
29-
},
30-
},
3117
{
3218
name: 'setup',
3319
async configureServer(viteDevServer) {

packages/core/src/client/webcomponents/components/Dock.vue

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import type { DockContext } from '../state/dock'
2+
import type { DocksContext } from '../state/dock'
33
import { useEventListener, useScreenSafeArea } from '@vueuse/core'
44
import { computed, onMounted, reactive, ref, useTemplateRef, watchEffect } from 'vue'
55
import { useStateHandlers } from '../state/state'
@@ -10,7 +10,7 @@ import VitePlusCore from './icons/VitePlusCore.vue'
1010
1111
// Here we directly destructure is as we don't expect context to be changed
1212
const props = defineProps<{
13-
context: DockContext
13+
context: DocksContext
1414
}>()
1515
const context = props.context
1616
@@ -76,6 +76,7 @@ onMounted(() => {
7676
if (!isDragging.value)
7777
return
7878
79+
const store = context.panel.store
7980
const centerX = window.innerWidth / 2
8081
const centerY = window.innerHeight / 2
8182
@@ -96,16 +97,16 @@ onMounted(() => {
9697
const BL = Math.atan2(window.innerHeight - HORIZONTAL_MARGIN - centerY, 0 - centerX)
9798
const BR = Math.atan2(window.innerHeight - HORIZONTAL_MARGIN - centerY, window.innerWidth - centerX)
9899
99-
context.state.position = deg >= TL && deg <= TR
100+
store.position = deg >= TL && deg <= TR
100101
? 'top'
101102
: deg >= TR && deg <= BR
102103
? 'right'
103104
: deg >= BR && deg <= BL
104105
? 'bottom'
105106
: 'left'
106107
107-
context.state.left = snapToPoints(x / window.innerWidth * 100)
108-
context.state.top = snapToPoints(y / window.innerHeight * 100)
108+
store.left = snapToPoints(x / window.innerWidth * 100)
109+
store.top = snapToPoints(y / window.innerHeight * 100)
109110
})
110111
useEventListener(window, 'pointerup', () => {
111112
isDragging.value = false
@@ -131,19 +132,20 @@ function clamp(value: number, min: number, max: number) {
131132
132133
const recalculateCounter = ref(0)
133134
const isHovering = ref(false)
134-
const isVertical = computed(() => context.state.position === 'left' || context.state.position === 'right')
135135
136136
const anchorPos = computed(() => {
137137
// eslint-disable-next-line ts/no-unused-expressions
138138
recalculateCounter.value
139139
140+
const store = context.panel.store
141+
140142
const halfWidth = (dockEl.value?.clientWidth || 0) / 2
141143
const halfHeight = (dockEl.value?.clientHeight || 0) / 2
142144
143-
const left = context.state.left * windowSize.width / 100
144-
const top = context.state.top * windowSize.height / 100
145+
const left = store.left * windowSize.width / 100
146+
const top = store.top * windowSize.height / 100
145147
146-
switch (context.state.position) {
148+
switch (store.position) {
147149
case 'top':
148150
return {
149151
left: clamp(left, halfWidth + panelMargins.left, windowSize.width - halfWidth - panelMargins.right),
@@ -171,29 +173,29 @@ const anchorPos = computed(() => {
171173
let _timer: ReturnType<typeof setTimeout> | null = null
172174
function bringUp() {
173175
isHovering.value = true
174-
if (context.state.minimizePanelInactive < 0)
176+
if (context.panel.store.inactiveTimeout < 0)
175177
return
176178
if (_timer)
177179
clearTimeout(_timer)
178180
_timer = setTimeout(() => {
179181
isHovering.value = false
180-
}, +context.state.minimizePanelInactive || 0)
182+
}, +context.panel.store.inactiveTimeout || 0)
181183
}
182184
183185
const isHidden = computed(() => false)
184186
185187
const isMinimized = computed(() => {
186-
if (context.state.minimizePanelInactive < 0)
188+
if (context.panel.store.inactiveTimeout < 0)
187189
return false
188-
if (context.state.minimizePanelInactive === 0)
190+
if (context.panel.store.inactiveTimeout === 0)
189191
return true
190192
// @ts-expect-error compatibility
191193
const isTouchDevice = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0
192194
return !isDragging.value
193-
&& !context.state.open
195+
&& !context.panel.store.open
194196
&& !isHovering.value
195197
&& !isTouchDevice
196-
&& context.state.minimizePanelInactive
198+
&& context.panel.store.inactiveTimeout
197199
})
198200
199201
const anchorStyle = computed(() => {
@@ -206,7 +208,7 @@ const anchorStyle = computed(() => {
206208
207209
const panelStyle = computed(() => {
208210
const style: any = {
209-
transform: isVertical.value
211+
transform: context.panel.isVertical
210212
? `translate(-50%, -50%) rotate(90deg)`
211213
: `translate(-50%, -50%)`,
212214
}
@@ -233,8 +235,8 @@ onMounted(() => {
233235
ref="anchorEl"
234236
:style="[anchorStyle]"
235237
:class="{
236-
'vite-devtools-horizontal': !isVertical,
237-
'vite-devtools-vertical': isVertical,
238+
'vite-devtools-horizontal': !context.panel.isVertical,
239+
'vite-devtools-vertical': context.panel.isVertical,
238240
'vite-devtools-minimized': isMinimized,
239241
}"
240242
@mousemove="bringUp"
@@ -258,7 +260,7 @@ onMounted(() => {
258260
/>
259261
<BracketRight
260262
class="vite-devtools-dock-bracket absolute right--1 top-1/2 translate-y--1/2 bottom-0 w-2.5 op75 transition-opacity duration-300"
261-
:class="isVertical ? 'scale-y--100' : ''"
263+
:class="context.panel.isVertical ? 'scale-y--100' : ''"
262264
/>
263265
<VitePlusCore
264266
class="w-3 h-3 absolute left-1/2 top-1/2 translate-x--1/2 translate-y--1/2 transition-opacity duration-300"
@@ -268,7 +270,7 @@ onMounted(() => {
268270
:entries="context.dockEntries"
269271
class="transition duration-200 flex items-center w-full h-full justify-center"
270272
:class="isMinimized ? 'opacity-0 pointer-events-none' : 'opacity-100'"
271-
:is-vertical="isVertical"
273+
:is-vertical="context.panel.isVertical"
272274
:selected="context.selected"
273275
@select="selectDockEntry"
274276
/>

packages/core/src/client/webcomponents/components/DockEmbedded.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { VueElementConstructor } from 'vue'
2-
import type { DockContext } from '../state/dock'
2+
import type { DocksContext } from '../state/dock'
33
import { defineCustomElement } from 'vue'
44
import css from '../.generated/css'
55
import Component from './DockEmbedded.vue'
@@ -11,7 +11,7 @@ export const DockEmbedded = defineCustomElement(
1111
styles: [css],
1212
},
1313
) as VueElementConstructor<{
14-
context: DockContext
14+
context: DocksContext
1515
}>
1616

1717
customElements.define('vite-devtools-dock-embedded', DockEmbedded)

packages/core/src/client/webcomponents/components/DockEmbedded.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script setup lang="ts">
2-
import type { DockContext } from '../state/dock'
2+
import type { DocksContext } from '../state/dock'
33
import Dock from './Dock.vue'
44
import DockPanel from './DockPanel.vue'
55
import FloatingTooltip from './FloatingTooltip.vue'
66
77
defineProps<{
8-
context: DockContext
8+
context: DocksContext
99
}>()
1010
</script>
1111

packages/core/src/client/webcomponents/components/DockPanel.vue

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<script setup lang="ts">
22
import type { DevToolsDockEntry } from '@vitejs/devtools-kit'
33
import type { CSSProperties } from 'vue'
4-
import type { DockContext } from '../state/dock'
4+
import type { DocksContext } from '../state/dock'
55
import { useElementBounding, useWindowSize } from '@vueuse/core'
66
import { computed, markRaw, onMounted, reactive, ref, toRefs, useTemplateRef } from 'vue'
77
import { PresistedDomViewsManager } from '../utils/PresistedDomViewsManager'
88
import DockPanelResizer from './DockPanelResizer.vue'
99
import ViewEntry from './ViewEntry.vue'
1010
1111
const props = defineProps<{
12-
context: DockContext
12+
context: DocksContext
1313
selected: DevToolsDockEntry | null
1414
dockEl?: HTMLDivElement
1515
panelMargins: { left: number, top: number, right: number, bottom: number }
@@ -34,10 +34,12 @@ const anchorPos = computed(() => {
3434
const halfWidth = (props.dockEl?.clientWidth || 0) / 2
3535
const halfHeight = (props.dockEl?.clientHeight || 0) / 2
3636
37-
const left = context.state.left * windowSize.width / 100
38-
const top = context.state.top * windowSize.height / 100
37+
const store = context.panel.store
3938
40-
switch (context.state.position) {
39+
const left = store.left * windowSize.width / 100
40+
const top = store.top * windowSize.height / 100
41+
42+
switch (store.position) {
4143
case 'top':
4244
return {
4345
left: clamp(left, halfWidth + panelMargins.value.left, windowSize.width - halfWidth - panelMargins.value.right),
@@ -65,13 +67,13 @@ const anchorPos = computed(() => {
6567
let _timer: ReturnType<typeof setTimeout> | null = null
6668
function bringUp() {
6769
isHovering.value = true
68-
if (context.state.minimizePanelInactive < 0)
70+
if (context.panel.store.inactiveTimeout < 0)
6971
return
7072
if (_timer)
7173
clearTimeout(_timer)
7274
_timer = setTimeout(() => {
7375
isHovering.value = false
74-
}, +context.state.minimizePanelInactive || 0)
76+
}, +context.panel.store.inactiveTimeout || 0)
7577
}
7678
7779
const { width: frameWidth, height: frameHeight } = useElementBounding(dockPanel)
@@ -95,22 +97,25 @@ const iframeStyle = computed(() => {
9597
const maxWidth = windowSize.width - marginHorizontal
9698
const maxHeight = windowSize.height - marginVertical
9799
100+
const panel = context.panel
101+
const store = panel.store
102+
98103
const style: CSSProperties = {
99104
position: 'fixed',
100105
zIndex: -1,
101-
pointerEvents: (context.isDragging || context.isResizing) ? 'none' : 'auto',
102-
width: `min(${context.state.width}vw, calc(100vw - ${marginHorizontal}px))`,
103-
height: `min(${context.state.height}vh, calc(100vh - ${marginVertical}px))`,
106+
pointerEvents: (panel.isDragging || panel.isResizing) ? 'none' : 'auto',
107+
width: `min(${store.width}vw, calc(100vw - ${marginHorizontal}px))`,
108+
height: `min(${store.height}vh, calc(100vh - ${marginVertical}px))`,
104109
}
105110
106111
const anchor = anchorPos.value
107-
const width = Math.min(maxWidth, context.state.width * windowSize.width / 100)
108-
const height = Math.min(maxHeight, context.state.height * windowSize.height / 100)
112+
const width = Math.min(maxWidth, store.width * windowSize.width / 100)
113+
const height = Math.min(maxHeight, store.height * windowSize.height / 100)
109114
110115
const anchorX = anchor?.left || 0
111116
const anchorY = anchor?.top || 0
112117
113-
switch (context.state.position) {
118+
switch (store.position) {
114119
case 'top':
115120
case 'bottom':
116121
style.left = `${-frameWidth.value / 2}px`
@@ -131,7 +136,7 @@ const iframeStyle = computed(() => {
131136
break
132137
}
133138
134-
switch (context.state.position) {
139+
switch (store.position) {
135140
case 'top':
136141
style.top = 0
137142
break
@@ -163,9 +168,7 @@ onMounted(() => {
163168
:style="iframeStyle"
164169
>
165170
<DockPanelResizer
166-
v-model:is-resizing="context.isResizing"
167-
:is-dragging="context.isDragging"
168-
:state="context.state"
171+
:panel="context.panel"
169172
/>
170173
<ViewEntry
171174
v-if="selected && viewsContainer"

0 commit comments

Comments
 (0)