-
-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathConnectorModal.vue
More file actions
199 lines (174 loc) · 5.99 KB
/
ConnectorModal.vue
File metadata and controls
199 lines (174 loc) · 5.99 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
<script setup lang="ts">
const { isConnected, isConnecting, npmUser, error, hasOperations, connect, disconnect } =
useConnector()
const { localSettings } = useUserLocalSettings()
const tokenInput = shallowRef('')
const portInput = shallowRef('31415')
const { copied, copy } = useClipboard({ copiedDuring: 2000 })
const hasAttemptedConnect = shallowRef(false)
watch(isConnected, connected => {
if (!connected) {
tokenInput.value = ''
hasAttemptedConnect.value = false
}
})
async function handleConnect() {
hasAttemptedConnect.value = true
const port = Number.parseInt(portInput.value, 10) || 31415
await connect(tokenInput.value.trim(), port)
}
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,
isBinaryOnly: true,
})
})
</script>
<template>
<Modal
:modalTitle="$t('connector.modal.title')"
:class="isConnected && hasOperations ? 'max-w-2xl' : 'max-w-md'"
id="connector-modal"
>
<!-- 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.connected_as_user', { user: npmUser }) }}
</p>
</div>
</div>
<!-- Connector preferences -->
<div class="flex flex-col gap-2">
<SettingsToggle
:label="$t('connector.modal.auto_open_url')"
v-model="localSettings.connector.autoOpenURL"
/>
</div>
<div class="border-t border-border my-3" />
<!-- Operations Queue -->
<OrgOperationsQueue />
<div v-if="!hasOperations" class="text-sm text-fg-muted">
{{ $t('connector.modal.connected_hint') }}
</div>
<ButtonBase type="button" class="w-full" @click="handleDisconnect">
{{ $t('connector.modal.disconnect') }}
</ButtonBase>
</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"
dir="ltr"
>
<span class="text-fg-subtle">$</span>
<span class="text-fg-subtle ms-2">{{ executeNpmxConnectorCommand }}</span>
<div class="ms-auto flex items-center gap-2">
<!-- Disable teleport in a modal dialog -->
<PackageManagerSelect :teleport="false" />
<ButtonBase
:aria-label="copied ? $t('connector.modal.copied') : $t('connector.modal.copy_command')"
@click="copyCommand"
class="ms-auto"
:classicon="copied ? 'i-lucide:check text-green-500' : 'i-lucide:copy'"
/>
</div>
</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>
<InputBase
id="connector-token"
v-model="tokenInput"
type="password"
name="connector-token"
:placeholder="$t('connector.modal.token_placeholder')"
no-correct
class="w-full"
/>
</div>
<details class="text-sm">
<summary class="text-fg-subtle 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>
<InputBase
id="connector-port"
v-model="portInput"
type="text"
name="connector-port"
inputmode="numeric"
autocomplete="off"
class="w-full"
/>
<div class="border-t border-border my-3" />
<div class="flex flex-col gap-2">
<SettingsToggle
:label="$t('connector.modal.auto_open_url')"
v-model="localSettings.connector.autoOpenURL"
/>
</div>
</div>
</details>
</div>
<!-- Error message (only show after user explicitly clicks Connect) -->
<div
v-if="error && hasAttemptedConnect"
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="inline-block text-xs font-bold uppercase tracking-wider text-fg rounded">
{{ $t('connector.modal.warning') }}
</p>
<p class="text-sm text-fg-muted mt-1">
{{ $t('connector.modal.warning_text') }}
</p>
</div>
<ButtonBase
type="submit"
variant="primary"
:disabled="!tokenInput.trim() || isConnecting"
class="w-full"
>
{{ isConnecting ? $t('connector.modal.connecting') : $t('connector.modal.connect') }}
</ButtonBase>
</form>
</Modal>
</template>