forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectorModal.vue
More file actions
229 lines (207 loc) · 8.85 KB
/
ConnectorModal.vue
File metadata and controls
229 lines (207 loc) · 8.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<script setup lang="ts">
const open = defineModel<boolean>('open', { default: false })
const { isConnected, isConnecting, npmUser, error, hasOperations, connect, disconnect } =
useConnector()
const tokenInput = shallowRef('')
const portInput = shallowRef('31415')
const { copied, copy } = useClipboard({ copiedDuring: 2000 })
async function handleConnect() {
const port = Number.parseInt(portInput.value, 10) || 31415
const success = await connect(tokenInput.value.trim(), port)
if (success) {
tokenInput.value = ''
open.value = false
}
}
function handleDisconnect() {
disconnect()
}
function copyCommand() {
let command = executeNpmxConnectorCommand.value
if (portInput.value !== '31415') {
command += ` --port ${portInput.value}`
}
copy(command)
}
const selectedPM = useSelectedPackageManager()
const executeNpmxConnectorCommand = computed(() => {
return getExecuteCommand({
packageName: 'npmx-connector',
packageManager: selectedPM.value,
})
})
// Reset form when modal opens
watch(open, isOpen => {
if (isOpen) {
tokenInput.value = ''
}
})
</script>
<template>
<Teleport to="body">
<Transition
enter-active-class="transition-opacity duration-200"
leave-active-class="transition-opacity duration-200"
enter-from-class="opacity-0"
leave-to-class="opacity-0"
>
<div v-if="open" class="fixed inset-0 z-50 flex items-center justify-center p-4">
<!-- Backdrop -->
<button
type="button"
class="absolute inset-0 bg-black/60 cursor-default"
:aria-label="$t('connector.modal.close_modal')"
@click="open = false"
/>
<!-- Modal -->
<div
class="relative w-full bg-bg border border-border rounded-lg shadow-xl max-h-[90vh] overflow-y-auto overscroll-contain"
:class="isConnected && hasOperations ? 'max-w-2xl' : 'max-w-md'"
role="dialog"
aria-modal="true"
aria-labelledby="connector-modal-title"
>
<div class="p-6">
<div class="flex items-center justify-between mb-6">
<h2 id="connector-modal-title" class="font-mono text-lg font-medium">
{{ $t('connector.modal.title') }}
</h2>
<button
type="button"
class="text-fg-subtle hover:text-fg transition-colors duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50 rounded"
:aria-label="$t('common.close')"
@click="open = false"
>
<span class="i-carbon:close block w-5 h-5" aria-hidden="true" />
</button>
</div>
<!-- Connected state -->
<div v-if="isConnected" class="space-y-4">
<div class="flex items-center gap-3 p-4 bg-bg-subtle border border-border rounded-lg">
<span class="w-3 h-3 rounded-full bg-green-500" aria-hidden="true" />
<div>
<p class="font-mono text-sm text-fg">{{ $t('connector.modal.connected') }}</p>
<p v-if="npmUser" class="font-mono text-xs text-fg-muted">
{{ $t('connector.modal.logged_in_as', { user: npmUser }) }}
</p>
</div>
</div>
<!-- Operations Queue -->
<OperationsQueue />
<div v-if="!hasOperations" class="text-sm text-fg-muted">
{{ $t('connector.modal.connected_hint') }}
</div>
<button
type="button"
class="w-full px-4 py-2 font-mono text-sm text-fg-muted bg-bg-subtle border border-border rounded-md transition-colors duration-200 hover:text-fg hover:border-border-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50"
@click="handleDisconnect"
>
{{ $t('connector.modal.disconnect') }}
</button>
</div>
<!-- Disconnected state -->
<form v-else class="space-y-4" @submit.prevent="handleConnect">
<p class="text-sm text-fg-muted">
{{ $t('connector.modal.run_hint') }}
</p>
<div
class="flex items-center p-3 bg-bg-muted border border-border rounded-lg font-mono text-sm"
>
<span class="text-fg-subtle">$</span>
<span class="text-fg-subtle ms-2">{{ executeNpmxConnectorCommand }}</span>
<button
type="button"
:aria-label="
copied ? $t('connector.modal.copied') : $t('connector.modal.copy_command')
"
class="ms-auto text-fg-subtle hover:text-fg transition-colors duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50 rounded"
@click="copyCommand"
>
<span v-if="!copied" class="i-carbon:copy block w-5 h-5" aria-hidden="true" />
<span
v-else
class="i-carbon:checkmark block w-5 h-5 text-green-500"
aria-hidden="true"
/>
</button>
</div>
<p class="text-sm text-fg-muted">{{ $t('connector.modal.paste_token') }}</p>
<div class="space-y-3">
<div>
<label
for="connector-token"
class="block text-xs text-fg-subtle uppercase tracking-wider mb-1.5"
>
{{ $t('connector.modal.token_label') }}
</label>
<input
id="connector-token"
v-model="tokenInput"
type="password"
name="connector-token"
:placeholder="$t('connector.modal.token_placeholder')"
v-bind="noCorrect"
class="w-full px-3 py-2 font-mono text-sm bg-bg-subtle border border-border rounded-md text-fg placeholder:text-fg-subtle transition-colors duration-200 focus:border-border-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50"
/>
</div>
<details class="text-sm">
<summary
class="text-fg-subtle cursor-pointer hover:text-fg-muted transition-colors duration-200"
>
{{ $t('connector.modal.advanced') }}
</summary>
<div class="mt-3">
<label
for="connector-port"
class="block text-xs text-fg-subtle uppercase tracking-wider mb-1.5"
>
{{ $t('connector.modal.port_label') }}
</label>
<input
id="connector-port"
v-model="portInput"
type="text"
name="connector-port"
inputmode="numeric"
autocomplete="off"
class="w-full px-3 py-2 font-mono text-sm bg-bg-subtle border border-border rounded-md text-fg transition-colors duration-200 focus:border-border-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50"
/>
</div>
</details>
</div>
<!-- Error message -->
<div
v-if="error"
role="alert"
class="p-3 text-sm text-red-400 bg-red-500/10 border border-red-500/20 rounded-md"
>
{{ error }}
</div>
<!-- Warning message -->
<div
role="alert"
class="p-3 text-sm text-red-400 bg-red-500/10 border border-red-500/20 rounded-md"
>
<p class="font-mono text-sm text-fg font-bold">
{{ $t('connector.modal.warning') }}
</p>
<p class="text-sm text-fg-muted">
{{ $t('connector.modal.warning_text') }}
</p>
</div>
<button
type="submit"
:disabled="!tokenInput.trim() || isConnecting"
class="w-full px-4 py-2 font-mono text-sm text-bg bg-fg rounded-md transition-all duration-200 hover:bg-fg/90 disabled:opacity-50 disabled:cursor-not-allowed focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50 focus-visible:ring-offset-2 focus-visible:ring-offset-bg"
>
{{
isConnecting ? $t('connector.modal.connecting') : $t('connector.modal.connect')
}}
</button>
</form>
</div>
</div>
</div>
</Transition>
</Teleport>
</template>