@eclipse-lyra/extension-sqleditor 0.7.56 → 0.7.58
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/dist/index.js +13 -10
- package/dist/index.js.map +1 -1
- package/dist/sqleditor-extension-MEwwujrA.js +824 -0
- package/dist/sqleditor-extension-MEwwujrA.js.map +1 -0
- package/package.json +3 -3
- package/dist/sqleditor-extension-BFAaVI-7.js +0 -920
- package/dist/sqleditor-extension-BFAaVI-7.js.map +0 -1
|
@@ -0,0 +1,824 @@
|
|
|
1
|
+
import { File, LyraPart, TOPIC_CONTRIBUTEIONS_CHANGED, confirmDialog, contributionRegistry, editorRegistry, publish, rootContext, subscribe, taskService, toastError, toastInfo, unsubscribe } from "@eclipse-lyra/core";
|
|
2
|
+
import { html } from "@eclipse-lyra/core/externals/lit";
|
|
3
|
+
import { customElement, property, state } from "lit/decorators.js";
|
|
4
|
+
import { LitElement, css, html as html$1 } from "lit";
|
|
5
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
6
|
+
import _decorate from "@oxc-project/runtime/helpers/decorate";
|
|
7
|
+
import { createRef, ref } from "lit/directives/ref.js";
|
|
8
|
+
//#region src/sql-extension-manager.ts
|
|
9
|
+
var LyraSqlExtensionManager = class LyraSqlExtensionManager extends LitElement {
|
|
10
|
+
constructor(..._args) {
|
|
11
|
+
super(..._args);
|
|
12
|
+
this.open = false;
|
|
13
|
+
this.db = null;
|
|
14
|
+
this.databaseLabel = "";
|
|
15
|
+
this.extensions = [];
|
|
16
|
+
this.loading = false;
|
|
17
|
+
this.updatingId = null;
|
|
18
|
+
this.error = null;
|
|
19
|
+
this.filterText = "";
|
|
20
|
+
}
|
|
21
|
+
configure(options) {
|
|
22
|
+
this.db = options.db;
|
|
23
|
+
this.databaseLabel = options.databaseLabel;
|
|
24
|
+
this.extensions = [];
|
|
25
|
+
this.error = null;
|
|
26
|
+
this.refreshExtensions();
|
|
27
|
+
}
|
|
28
|
+
show() {
|
|
29
|
+
if (!this.db || !this.db.listDbExtensions) return;
|
|
30
|
+
this.open = true;
|
|
31
|
+
}
|
|
32
|
+
hide() {
|
|
33
|
+
this.open = false;
|
|
34
|
+
}
|
|
35
|
+
async refreshExtensions() {
|
|
36
|
+
if (!this.db || !this.db.listDbExtensions) {
|
|
37
|
+
this.extensions = [];
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.loading = true;
|
|
41
|
+
this.error = null;
|
|
42
|
+
try {
|
|
43
|
+
const result = await taskService.runAsync("Loading database extensions", async () => this.db.listDbExtensions());
|
|
44
|
+
this.extensions = Array.isArray(result) ? result : [];
|
|
45
|
+
} catch (err) {
|
|
46
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
47
|
+
this.error = msg;
|
|
48
|
+
toastError(msg);
|
|
49
|
+
} finally {
|
|
50
|
+
this.loading = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async enableExtension(ext) {
|
|
54
|
+
if (!this.db || !this.db.enableDbExtension) return;
|
|
55
|
+
this.updatingId = ext.id;
|
|
56
|
+
this.error = null;
|
|
57
|
+
try {
|
|
58
|
+
await taskService.runAsync(`Enabling extension ${ext.label || ext.id}`, async () => this.db.enableDbExtension(ext.id));
|
|
59
|
+
await this.refreshExtensions();
|
|
60
|
+
} catch (err) {
|
|
61
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
62
|
+
this.error = msg;
|
|
63
|
+
toastError(msg);
|
|
64
|
+
} finally {
|
|
65
|
+
this.updatingId = null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async disableExtension(ext) {
|
|
69
|
+
if (!this.db || !this.db.disableDbExtension) return;
|
|
70
|
+
this.updatingId = ext.id;
|
|
71
|
+
this.error = null;
|
|
72
|
+
try {
|
|
73
|
+
await taskService.runAsync(`Disabling extension ${ext.label || ext.id}`, async () => this.db.disableDbExtension(ext.id));
|
|
74
|
+
await this.refreshExtensions();
|
|
75
|
+
} catch (err) {
|
|
76
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
77
|
+
this.error = msg;
|
|
78
|
+
toastError(msg);
|
|
79
|
+
} finally {
|
|
80
|
+
this.updatingId = null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
renderExtensionRow(ext) {
|
|
84
|
+
const installed = Boolean(ext.installed);
|
|
85
|
+
const canDisable = installed && !!this.db?.disableDbExtension;
|
|
86
|
+
const isUpdating = this.updatingId === ext.id;
|
|
87
|
+
return html$1`
|
|
88
|
+
<div class="extension-item">
|
|
89
|
+
<div class="extension-main">
|
|
90
|
+
<div class="extension-name">${ext.label || ext.id}</div>
|
|
91
|
+
${ext.description ? html$1`<div class="extension-desc">${ext.description}</div>` : null}
|
|
92
|
+
</div>
|
|
93
|
+
<div class="extension-meta">
|
|
94
|
+
<span
|
|
95
|
+
class=${installed ? "badge badge-installed" : "badge badge-available"}
|
|
96
|
+
>
|
|
97
|
+
${installed ? "Installed" : "Available"}
|
|
98
|
+
</span>
|
|
99
|
+
<div class="extension-actions">
|
|
100
|
+
${installed ? html$1`
|
|
101
|
+
<wa-button
|
|
102
|
+
size="small"
|
|
103
|
+
appearance="plain"
|
|
104
|
+
?disabled=${!canDisable || isUpdating}
|
|
105
|
+
@click=${() => void this.disableExtension(ext)}
|
|
106
|
+
>
|
|
107
|
+
<wa-icon
|
|
108
|
+
name="circle-minus"
|
|
109
|
+
label="Disable"
|
|
110
|
+
></wa-icon>
|
|
111
|
+
</wa-button>
|
|
112
|
+
` : html$1`
|
|
113
|
+
<wa-button
|
|
114
|
+
size="small"
|
|
115
|
+
appearance="plain"
|
|
116
|
+
?disabled=${isUpdating}
|
|
117
|
+
@click=${() => void this.enableExtension(ext)}
|
|
118
|
+
>
|
|
119
|
+
<wa-icon
|
|
120
|
+
name="plug-circle-plus"
|
|
121
|
+
label="Enable"
|
|
122
|
+
></wa-icon>
|
|
123
|
+
</wa-button>
|
|
124
|
+
`}
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
`;
|
|
129
|
+
}
|
|
130
|
+
render() {
|
|
131
|
+
const hasDb = Boolean(this.db && this.db.listDbExtensions);
|
|
132
|
+
const filter = this.filterText.trim().toLowerCase();
|
|
133
|
+
const filteredExtensions = !filter ? this.extensions : this.extensions.filter((ext) => {
|
|
134
|
+
return `${ext.label ?? ""} ${ext.id} ${ext.description ?? ""}`.toLowerCase().includes(filter);
|
|
135
|
+
});
|
|
136
|
+
const hasItems = filteredExtensions.length > 0;
|
|
137
|
+
return html$1`
|
|
138
|
+
<wa-dialog
|
|
139
|
+
label="Database extensions"
|
|
140
|
+
?open=${this.open}
|
|
141
|
+
@wa-after-hide=${() => {
|
|
142
|
+
this.open = false;
|
|
143
|
+
this.dispatchEvent(new CustomEvent("hide", {
|
|
144
|
+
bubbles: true,
|
|
145
|
+
composed: true
|
|
146
|
+
}));
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
<div class="extension-manager">
|
|
150
|
+
<p class="extension-manager-description">
|
|
151
|
+
Database:
|
|
152
|
+
<strong>${this.databaseLabel || "Current connection"}</strong>
|
|
153
|
+
</p>
|
|
154
|
+
|
|
155
|
+
${!hasDb ? html$1`
|
|
156
|
+
<wa-alert variant="warning" open>
|
|
157
|
+
<wa-icon slot="icon" name="triangle-exclamation"></wa-icon>
|
|
158
|
+
The current SQL engine does not expose any extension information.
|
|
159
|
+
</wa-alert>
|
|
160
|
+
` : null}
|
|
161
|
+
|
|
162
|
+
${this.error ? html$1`
|
|
163
|
+
<wa-alert
|
|
164
|
+
variant="danger"
|
|
165
|
+
open
|
|
166
|
+
closable
|
|
167
|
+
@wa-after-hide=${() => {
|
|
168
|
+
this.error = null;
|
|
169
|
+
}}
|
|
170
|
+
>
|
|
171
|
+
<wa-icon slot="icon" name="circle-exclamation"></wa-icon>
|
|
172
|
+
${this.error}
|
|
173
|
+
</wa-alert>
|
|
174
|
+
` : null}
|
|
175
|
+
|
|
176
|
+
<wa-input
|
|
177
|
+
size="small"
|
|
178
|
+
placeholder="Filter extensions…"
|
|
179
|
+
.value=${this.filterText}
|
|
180
|
+
@input=${(event) => {
|
|
181
|
+
this.filterText = event.target?.value ?? "";
|
|
182
|
+
}}
|
|
183
|
+
@wa-clear=${() => {
|
|
184
|
+
this.filterText = "";
|
|
185
|
+
}}
|
|
186
|
+
with-clear
|
|
187
|
+
>
|
|
188
|
+
<wa-icon slot="prefix" name="magnifying-glass"></wa-icon>
|
|
189
|
+
</wa-input>
|
|
190
|
+
|
|
191
|
+
<div class="extension-list">
|
|
192
|
+
${this.loading ? html$1`<div class="extension-list-empty">Loading extensions…</div>` : !hasItems ? html$1`
|
|
193
|
+
<div class="extension-list-empty">
|
|
194
|
+
No extensions available for this connection.
|
|
195
|
+
</div>
|
|
196
|
+
` : repeat(filteredExtensions, (ext) => ext.id, (ext) => this.renderExtensionRow(ext))}
|
|
197
|
+
</div>
|
|
198
|
+
</div>
|
|
199
|
+
<div slot="footer" class="extension-manager-footer">
|
|
200
|
+
<wa-button variant="default" @click=${() => this.hide()}>
|
|
201
|
+
Close
|
|
202
|
+
</wa-button>
|
|
203
|
+
</div>
|
|
204
|
+
</wa-dialog>
|
|
205
|
+
`;
|
|
206
|
+
}
|
|
207
|
+
static {
|
|
208
|
+
this.styles = css`
|
|
209
|
+
:host {
|
|
210
|
+
display: contents;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.extension-manager {
|
|
214
|
+
display: flex;
|
|
215
|
+
flex-direction: column;
|
|
216
|
+
gap: 1rem;
|
|
217
|
+
padding: 1rem;
|
|
218
|
+
height: 420px;
|
|
219
|
+
box-sizing: border-box;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.extension-toolbar {
|
|
223
|
+
display: flex;
|
|
224
|
+
justify-content: flex-end;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.extension-manager-description {
|
|
228
|
+
margin: 0;
|
|
229
|
+
font-size: 0.95rem;
|
|
230
|
+
opacity: 0.9;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.extension-list {
|
|
234
|
+
display: flex;
|
|
235
|
+
flex-direction: column;
|
|
236
|
+
gap: 0.5rem;
|
|
237
|
+
flex: 1;
|
|
238
|
+
min-height: 0;
|
|
239
|
+
max-height: 100%;
|
|
240
|
+
overflow-y: auto;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.extension-list-empty {
|
|
244
|
+
font-size: 0.9rem;
|
|
245
|
+
opacity: 0.8;
|
|
246
|
+
padding: 0.5rem 0;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
.extension-item {
|
|
250
|
+
display: flex;
|
|
251
|
+
align-items: flex-start;
|
|
252
|
+
justify-content: space-between;
|
|
253
|
+
gap: 0.75rem;
|
|
254
|
+
padding: 0.5rem 0;
|
|
255
|
+
border-bottom: 1px solid var(--wa-color-neutral-200, #e5e7eb);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.extension-main {
|
|
259
|
+
display: flex;
|
|
260
|
+
flex-direction: column;
|
|
261
|
+
gap: 0.15rem;
|
|
262
|
+
min-width: 0;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
.extension-name {
|
|
266
|
+
font-weight: 500;
|
|
267
|
+
font-size: 0.95rem;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.extension-desc {
|
|
271
|
+
font-size: 0.85rem;
|
|
272
|
+
opacity: 0.8;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.extension-meta {
|
|
276
|
+
display: flex;
|
|
277
|
+
flex-direction: column;
|
|
278
|
+
align-items: flex-end;
|
|
279
|
+
gap: 0.35rem;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.extension-actions {
|
|
283
|
+
display: flex;
|
|
284
|
+
gap: 0.25rem;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
.badge {
|
|
288
|
+
display: inline-flex;
|
|
289
|
+
align-items: center;
|
|
290
|
+
padding: 0.15rem 0.4rem;
|
|
291
|
+
border-radius: 999px;
|
|
292
|
+
font-size: 0.75rem;
|
|
293
|
+
border: 1px solid var(--wa-color-neutral-200, #e5e7eb);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.badge-installed {
|
|
297
|
+
background-color: var(--wa-color-success-50, #ecfdf3);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
.badge-available {
|
|
301
|
+
background-color: var(--wa-color-neutral-50, #f9fafb);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.extension-manager-footer {
|
|
305
|
+
display: flex;
|
|
306
|
+
justify-content: flex-end;
|
|
307
|
+
padding-top: 1rem;
|
|
308
|
+
border-top: 1px solid var(--wa-color-neutral-200, #e5e7eb);
|
|
309
|
+
}
|
|
310
|
+
`;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
_decorate([property({ type: Boolean })], LyraSqlExtensionManager.prototype, "open", void 0);
|
|
314
|
+
_decorate([property({ attribute: false })], LyraSqlExtensionManager.prototype, "db", void 0);
|
|
315
|
+
_decorate([property()], LyraSqlExtensionManager.prototype, "databaseLabel", void 0);
|
|
316
|
+
_decorate([state()], LyraSqlExtensionManager.prototype, "extensions", void 0);
|
|
317
|
+
_decorate([state()], LyraSqlExtensionManager.prototype, "loading", void 0);
|
|
318
|
+
_decorate([state()], LyraSqlExtensionManager.prototype, "updatingId", void 0);
|
|
319
|
+
_decorate([state()], LyraSqlExtensionManager.prototype, "error", void 0);
|
|
320
|
+
_decorate([state()], LyraSqlExtensionManager.prototype, "filterText", void 0);
|
|
321
|
+
LyraSqlExtensionManager = _decorate([customElement("lyra-sql-extension-manager")], LyraSqlExtensionManager);
|
|
322
|
+
var SqlExtensionManagerService = class {
|
|
323
|
+
constructor() {
|
|
324
|
+
this.managerInstance = null;
|
|
325
|
+
}
|
|
326
|
+
showExtensionManager(options) {
|
|
327
|
+
if (!options.db || !options.db.listDbExtensions) {
|
|
328
|
+
toastError("The current SQL engine does not support extensions.");
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
if (!this.managerInstance) {
|
|
332
|
+
this.managerInstance = document.createElement("lyra-sql-extension-manager");
|
|
333
|
+
document.body.appendChild(this.managerInstance);
|
|
334
|
+
}
|
|
335
|
+
this.managerInstance.configure(options);
|
|
336
|
+
this.managerInstance.show();
|
|
337
|
+
return this.managerInstance;
|
|
338
|
+
}
|
|
339
|
+
getManager() {
|
|
340
|
+
return this.managerInstance;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
var sqlExtensionManagerService = new SqlExtensionManagerService();
|
|
344
|
+
rootContext.put("sqlExtensionManagerService", sqlExtensionManagerService);
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region src/sql-editor.ts
|
|
347
|
+
var MAX_TAB_LABEL = 28;
|
|
348
|
+
function truncateLabel(sql) {
|
|
349
|
+
const oneLine = sql.replace(/\s+/g, " ").trim();
|
|
350
|
+
if (oneLine.length <= MAX_TAB_LABEL) return oneLine;
|
|
351
|
+
return `${oneLine.slice(0, MAX_TAB_LABEL)}…`;
|
|
352
|
+
}
|
|
353
|
+
var LyraSqlEditor = class LyraSqlEditor extends LyraPart {
|
|
354
|
+
constructor(..._args) {
|
|
355
|
+
super(..._args);
|
|
356
|
+
this.readOnly = false;
|
|
357
|
+
this.initialContent = void 0;
|
|
358
|
+
this.initialUri = void 0;
|
|
359
|
+
this.running = false;
|
|
360
|
+
this.availableAdapters = [];
|
|
361
|
+
this.selectedEngineId = null;
|
|
362
|
+
this.availableConnections = [];
|
|
363
|
+
this.selectedConnectionId = null;
|
|
364
|
+
this.widgetRef = createRef();
|
|
365
|
+
this.databases = /* @__PURE__ */ new Map();
|
|
366
|
+
this._onContentChange = () => {
|
|
367
|
+
this.markDirty(true);
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
async doInitUI() {
|
|
371
|
+
const file = this.input.data;
|
|
372
|
+
this.initialContent = await file.getContents();
|
|
373
|
+
this.initialUri = file.getWorkspacePath();
|
|
374
|
+
this.unsubscribeContributionsToken = subscribe(TOPIC_CONTRIBUTEIONS_CHANGED, (event) => {
|
|
375
|
+
if (event?.target === "system.sqladapters") this.refreshAdapters();
|
|
376
|
+
});
|
|
377
|
+
await this.refreshAdapters();
|
|
378
|
+
this.requestUpdate();
|
|
379
|
+
}
|
|
380
|
+
async refreshAdapters() {
|
|
381
|
+
const contributions = contributionRegistry.getContributions("system.sqladapters");
|
|
382
|
+
this.availableAdapters = contributions;
|
|
383
|
+
if (!contributions.length) {
|
|
384
|
+
this.selectedEngineId = null;
|
|
385
|
+
this.availableConnections = [];
|
|
386
|
+
this.selectedConnectionId = null;
|
|
387
|
+
await this.updateComplete;
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (!this.selectedEngineId) this.selectedEngineId = (contributions.find((c) => c.id === "duckdb") ?? contributions[0]).id;
|
|
391
|
+
this.requestUpdate();
|
|
392
|
+
await this.refreshConnections();
|
|
393
|
+
await this.updateComplete;
|
|
394
|
+
}
|
|
395
|
+
async getOrLoadDatabase(engineId) {
|
|
396
|
+
const cached = this.databases.get(engineId);
|
|
397
|
+
if (cached) return cached;
|
|
398
|
+
const adapter = this.availableAdapters.find((c) => c.id === engineId);
|
|
399
|
+
if (!adapter) return null;
|
|
400
|
+
try {
|
|
401
|
+
const label = adapter.label || adapter.id;
|
|
402
|
+
const database = await taskService.runAsync(`Opening ${label} database`, async (progress) => {
|
|
403
|
+
progress.message = `Connecting to ${label}…`;
|
|
404
|
+
return adapter.loader();
|
|
405
|
+
});
|
|
406
|
+
this.databases.set(engineId, database);
|
|
407
|
+
return database;
|
|
408
|
+
} catch (err) {
|
|
409
|
+
toastError(err instanceof Error ? err.message : String(err));
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
async refreshConnections() {
|
|
414
|
+
const engineId = this.selectedEngineId;
|
|
415
|
+
if (!engineId) {
|
|
416
|
+
this.availableConnections = [];
|
|
417
|
+
this.selectedConnectionId = null;
|
|
418
|
+
await this.updateComplete;
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
const db = await this.getOrLoadDatabase(engineId);
|
|
422
|
+
if (!db) {
|
|
423
|
+
this.availableConnections = [];
|
|
424
|
+
this.selectedConnectionId = null;
|
|
425
|
+
await this.updateComplete;
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const infos = await db.listConnections();
|
|
429
|
+
this.availableConnections = infos;
|
|
430
|
+
const currentId = db.currentConnectionId;
|
|
431
|
+
if (currentId !== null) {
|
|
432
|
+
this.selectedConnectionId = currentId;
|
|
433
|
+
await this.updateComplete;
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
const preferred = infos.find((info) => info.isDefault) ?? infos[0];
|
|
437
|
+
this.selectedConnectionId = preferred ? preferred.id : null;
|
|
438
|
+
if (preferred) await db.selectConnection(preferred.id ?? null);
|
|
439
|
+
await this.updateComplete;
|
|
440
|
+
}
|
|
441
|
+
async onEngineChange(e) {
|
|
442
|
+
const value = e.target?.value ?? "";
|
|
443
|
+
if (this.selectedEngineId === value) return;
|
|
444
|
+
this.selectedEngineId = value || null;
|
|
445
|
+
await this.refreshConnections();
|
|
446
|
+
this.requestUpdate();
|
|
447
|
+
}
|
|
448
|
+
async onConnectionChange(e) {
|
|
449
|
+
const value = e.target?.value ?? "";
|
|
450
|
+
const next = value === "" ? null : value;
|
|
451
|
+
if (this.selectedConnectionId === next) return;
|
|
452
|
+
this.selectedConnectionId = next;
|
|
453
|
+
const engineId = this.selectedEngineId;
|
|
454
|
+
if (!engineId) return;
|
|
455
|
+
const db = await this.getOrLoadDatabase(engineId);
|
|
456
|
+
if (!db) return;
|
|
457
|
+
await db.selectConnection(next);
|
|
458
|
+
this.requestUpdate();
|
|
459
|
+
}
|
|
460
|
+
async onEngineDropdownSelect(e) {
|
|
461
|
+
const value = e.detail?.item?.value ?? "";
|
|
462
|
+
if (this.selectedEngineId === value) return;
|
|
463
|
+
this.selectedEngineId = value || null;
|
|
464
|
+
await this.refreshConnections();
|
|
465
|
+
this.requestUpdate();
|
|
466
|
+
}
|
|
467
|
+
async onConnectionDropdownSelect(e) {
|
|
468
|
+
const value = e.detail?.item?.value ?? "";
|
|
469
|
+
const next = value === "" ? null : value;
|
|
470
|
+
if (this.selectedConnectionId === next) return;
|
|
471
|
+
this.selectedConnectionId = next;
|
|
472
|
+
const engineId = this.selectedEngineId;
|
|
473
|
+
if (!engineId) return;
|
|
474
|
+
const db = await this.getOrLoadDatabase(engineId);
|
|
475
|
+
if (!db) return;
|
|
476
|
+
await db.selectConnection(next);
|
|
477
|
+
this.requestUpdate();
|
|
478
|
+
}
|
|
479
|
+
async deleteConnectionById(e, id) {
|
|
480
|
+
e.stopPropagation();
|
|
481
|
+
e.preventDefault();
|
|
482
|
+
const engineId = this.selectedEngineId;
|
|
483
|
+
if (!engineId) return;
|
|
484
|
+
const db = await this.getOrLoadDatabase(engineId);
|
|
485
|
+
if (!db || !db.deleteConnection) return;
|
|
486
|
+
if (!await confirmDialog(`Delete connection "${this.availableConnections.find((info) => info.id === id)?.label ?? (id === null ? "In-memory" : id ?? "Current connection")}"?`)) return;
|
|
487
|
+
if (id !== null) await db.deleteConnection(id);
|
|
488
|
+
else await db.selectConnection(null);
|
|
489
|
+
await this.refreshConnections();
|
|
490
|
+
this.requestUpdate();
|
|
491
|
+
}
|
|
492
|
+
save() {
|
|
493
|
+
const value = this.widgetRef.value?.getContent() ?? "";
|
|
494
|
+
this.input?.data.saveContents(value);
|
|
495
|
+
this.markDirty(false);
|
|
496
|
+
}
|
|
497
|
+
async doClose() {
|
|
498
|
+
if (this.unsubscribeContributionsToken) {
|
|
499
|
+
unsubscribe(this.unsubscribeContributionsToken);
|
|
500
|
+
this.unsubscribeContributionsToken = void 0;
|
|
501
|
+
}
|
|
502
|
+
this.widgetRef.value?.dispose();
|
|
503
|
+
for (const db of this.databases.values()) await db.close();
|
|
504
|
+
this.databases.clear();
|
|
505
|
+
}
|
|
506
|
+
getLanguage() {
|
|
507
|
+
return "sql";
|
|
508
|
+
}
|
|
509
|
+
isLanguage(lang) {
|
|
510
|
+
return lang.toLowerCase() === "sql";
|
|
511
|
+
}
|
|
512
|
+
getContent() {
|
|
513
|
+
return this.widgetRef.value?.getContent() ?? null;
|
|
514
|
+
}
|
|
515
|
+
getSelection() {
|
|
516
|
+
return this.widgetRef.value?.getSelection() ?? null;
|
|
517
|
+
}
|
|
518
|
+
getSnippet(lines = 5) {
|
|
519
|
+
return this.widgetRef.value?.getSnippet(lines) ?? null;
|
|
520
|
+
}
|
|
521
|
+
getFilePath() {
|
|
522
|
+
return this.input?.data?.getWorkspacePath() ?? null;
|
|
523
|
+
}
|
|
524
|
+
async runQuery(useSelectionOnly = false) {
|
|
525
|
+
const selection = this.getSelection()?.trim();
|
|
526
|
+
const content = this.getContent()?.trim();
|
|
527
|
+
const sql = useSelectionOnly ? selection : content;
|
|
528
|
+
if (!sql) {
|
|
529
|
+
toastError(useSelectionOnly ? "No selection to run" : "No SQL to run");
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
if (this.running) return;
|
|
533
|
+
const engineId = this.selectedEngineId;
|
|
534
|
+
if (!engineId) {
|
|
535
|
+
toastError("No SQL engine available");
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
const db = await this.getOrLoadDatabase(engineId);
|
|
539
|
+
if (!db) {
|
|
540
|
+
toastError("Could not initialize SQL engine");
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
if (!this.selectedConnectionId && this.availableConnections.length) {
|
|
544
|
+
const preferred = this.availableConnections.find((info) => info.isDefault) ?? this.availableConnections[0];
|
|
545
|
+
this.selectedConnectionId = preferred.id;
|
|
546
|
+
await db.selectConnection(preferred.id ?? null);
|
|
547
|
+
}
|
|
548
|
+
this.running = true;
|
|
549
|
+
const label = truncateLabel(sql);
|
|
550
|
+
this.requestUpdate();
|
|
551
|
+
const timeoutId = window.setTimeout(() => this.clearRunningState(), 6e4);
|
|
552
|
+
try {
|
|
553
|
+
const result = await db.runQuery(sql);
|
|
554
|
+
const adapter = this.availableAdapters.find((c) => c.id === engineId);
|
|
555
|
+
publish("dataview/publish", {
|
|
556
|
+
title: label,
|
|
557
|
+
data: {
|
|
558
|
+
columns: result.columns,
|
|
559
|
+
rows: result.rows
|
|
560
|
+
},
|
|
561
|
+
source: adapter?.label ?? engineId
|
|
562
|
+
});
|
|
563
|
+
} catch (err) {
|
|
564
|
+
toastError(err instanceof Error ? err.message : String(err));
|
|
565
|
+
} finally {
|
|
566
|
+
window.clearTimeout(timeoutId);
|
|
567
|
+
this.running = false;
|
|
568
|
+
this.requestUpdate();
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
clearRunningState() {
|
|
572
|
+
if (!this.running) return;
|
|
573
|
+
this.running = false;
|
|
574
|
+
this.requestUpdate();
|
|
575
|
+
}
|
|
576
|
+
async createConnection() {
|
|
577
|
+
const engineId = this.selectedEngineId;
|
|
578
|
+
if (!engineId) return;
|
|
579
|
+
const db = await this.getOrLoadDatabase(engineId);
|
|
580
|
+
if (!db || !db.createConnection) return;
|
|
581
|
+
const info = await db.createConnection();
|
|
582
|
+
if (!info) return;
|
|
583
|
+
await this.refreshConnections();
|
|
584
|
+
this.selectedConnectionId = info.id;
|
|
585
|
+
await db.selectConnection(info.id ?? null);
|
|
586
|
+
toastInfo(`Connection "${info.label}" created`);
|
|
587
|
+
this.requestUpdate();
|
|
588
|
+
}
|
|
589
|
+
async deleteConnection() {
|
|
590
|
+
const engineId = this.selectedEngineId;
|
|
591
|
+
if (!engineId) return;
|
|
592
|
+
const db = await this.getOrLoadDatabase(engineId);
|
|
593
|
+
if (!db || !db.deleteConnection) return;
|
|
594
|
+
const id = this.selectedConnectionId;
|
|
595
|
+
if (!await confirmDialog(`Delete connection "${this.availableConnections.find((info) => info.id === id)?.label ?? (id === null ? "In-memory" : id ?? "Current connection")}"?`)) return;
|
|
596
|
+
if (id !== null) await db.deleteConnection(id);
|
|
597
|
+
else await db.selectConnection(null);
|
|
598
|
+
await this.refreshConnections();
|
|
599
|
+
this.requestUpdate();
|
|
600
|
+
}
|
|
601
|
+
getCurrentConnectionLabel() {
|
|
602
|
+
const id = this.selectedConnectionId;
|
|
603
|
+
if (id === null) return "In-memory";
|
|
604
|
+
if (!id) return null;
|
|
605
|
+
return this.availableConnections.find((c) => c.id === id)?.label ?? id;
|
|
606
|
+
}
|
|
607
|
+
async openExtensionManager() {
|
|
608
|
+
const engineId = this.selectedEngineId;
|
|
609
|
+
if (!engineId) return;
|
|
610
|
+
const db = await this.getOrLoadDatabase(engineId);
|
|
611
|
+
if (!db || !db.listDbExtensions) {
|
|
612
|
+
toastInfo("Extensions are not available for the selected SQL engine.");
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
const engineLabel = (this.availableAdapters.find((c) => c.id === engineId) ?? null)?.label ?? engineId;
|
|
616
|
+
const connectionLabel = this.getCurrentConnectionLabel();
|
|
617
|
+
const databaseLabel = connectionLabel ? `${engineLabel} – ${connectionLabel}` : engineLabel;
|
|
618
|
+
sqlExtensionManagerService.showExtensionManager({
|
|
619
|
+
db,
|
|
620
|
+
databaseLabel
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
renderToolbar() {
|
|
624
|
+
const adapters = this.availableAdapters;
|
|
625
|
+
const hasEngines = adapters.length > 0;
|
|
626
|
+
const hasConnections = this.availableConnections.length > 0;
|
|
627
|
+
const engineId = this.selectedEngineId;
|
|
628
|
+
const dbForEngine = engineId ? this.databases.get(engineId) : null;
|
|
629
|
+
const supportsExtensions = Boolean(dbForEngine?.listDbExtensions);
|
|
630
|
+
return html$1`
|
|
631
|
+
<wa-dropdown
|
|
632
|
+
class="engine-select"
|
|
633
|
+
placement="bottom-start"
|
|
634
|
+
distance="4"
|
|
635
|
+
size="small"
|
|
636
|
+
@wa-select=${(e) => void this.onEngineDropdownSelect(e)}
|
|
637
|
+
>
|
|
638
|
+
<wa-button
|
|
639
|
+
slot="trigger"
|
|
640
|
+
appearance="plain"
|
|
641
|
+
size="small"
|
|
642
|
+
with-caret
|
|
643
|
+
title="SQL engine"
|
|
644
|
+
>
|
|
645
|
+
${this.selectedEngineId ? adapters.find((a) => a.id === this.selectedEngineId)?.label ?? this.selectedEngineId : "Select engine"}
|
|
646
|
+
</wa-button>
|
|
647
|
+
${adapters.map((adapter) => html$1`
|
|
648
|
+
<wa-dropdown-item
|
|
649
|
+
value=${adapter.id}
|
|
650
|
+
type="checkbox"
|
|
651
|
+
?checked=${adapter.id === this.selectedEngineId}
|
|
652
|
+
>
|
|
653
|
+
${adapter.label}
|
|
654
|
+
</wa-dropdown-item>
|
|
655
|
+
`)}
|
|
656
|
+
</wa-dropdown>
|
|
657
|
+
<wa-dropdown
|
|
658
|
+
class="connection-select"
|
|
659
|
+
placement="bottom-start"
|
|
660
|
+
distance="4"
|
|
661
|
+
size="small"
|
|
662
|
+
@wa-select=${(e) => void this.onConnectionDropdownSelect(e)}
|
|
663
|
+
>
|
|
664
|
+
<wa-button
|
|
665
|
+
slot="trigger"
|
|
666
|
+
appearance="plain"
|
|
667
|
+
size="small"
|
|
668
|
+
with-caret
|
|
669
|
+
title="Connection"
|
|
670
|
+
?disabled=${!hasEngines || !hasConnections}
|
|
671
|
+
>
|
|
672
|
+
${this.selectedConnectionId === null ? "In-memory" : this.availableConnections.find((c) => c.id === this.selectedConnectionId)?.label ?? "Select connection"}
|
|
673
|
+
</wa-button>
|
|
674
|
+
${this.availableConnections.map((info) => html$1`
|
|
675
|
+
<wa-dropdown-item
|
|
676
|
+
value=${info.id ?? ""}
|
|
677
|
+
type="checkbox"
|
|
678
|
+
?checked=${info.id === this.selectedConnectionId}
|
|
679
|
+
>
|
|
680
|
+
${info.label}
|
|
681
|
+
<wa-button
|
|
682
|
+
slot="details"
|
|
683
|
+
appearance="plain"
|
|
684
|
+
size="small"
|
|
685
|
+
title=${info.id === null ? "Reset in-memory connection" : "Delete connection"}
|
|
686
|
+
@click=${(e) => this.deleteConnectionById(e, info.id)}
|
|
687
|
+
>
|
|
688
|
+
<wa-icon
|
|
689
|
+
name=${info.id === null ? "rotate-right" : "trash"}
|
|
690
|
+
label=${info.id === null ? "Reset" : "Delete"}
|
|
691
|
+
></wa-icon>
|
|
692
|
+
</wa-button>
|
|
693
|
+
</wa-dropdown-item>
|
|
694
|
+
`)}
|
|
695
|
+
</wa-dropdown>
|
|
696
|
+
<wa-button
|
|
697
|
+
size="small"
|
|
698
|
+
appearance="plain"
|
|
699
|
+
title="New connection"
|
|
700
|
+
@click=${() => void this.createConnection()}
|
|
701
|
+
>
|
|
702
|
+
<wa-icon name="plus" label="New"></wa-icon>
|
|
703
|
+
</wa-button>
|
|
704
|
+
${supportsExtensions ? html$1`
|
|
705
|
+
<wa-button
|
|
706
|
+
size="small"
|
|
707
|
+
appearance="plain"
|
|
708
|
+
title="Manage extensions"
|
|
709
|
+
?disabled=${!hasEngines || !hasConnections}
|
|
710
|
+
@click=${() => void this.openExtensionManager()}
|
|
711
|
+
>
|
|
712
|
+
<wa-icon name="puzzle-piece" label="Extensions"></wa-icon>
|
|
713
|
+
Extensions
|
|
714
|
+
</wa-button>
|
|
715
|
+
` : null}
|
|
716
|
+
<wa-button
|
|
717
|
+
size="small"
|
|
718
|
+
appearance="plain"
|
|
719
|
+
?disabled=${this.running}
|
|
720
|
+
@click=${() => void this.runQuery(true)}
|
|
721
|
+
title="Run selection only"
|
|
722
|
+
>
|
|
723
|
+
<wa-icon name="i-cursor" label="Run selection"></wa-icon>
|
|
724
|
+
${this.running ? "Running…" : "Run selection"}
|
|
725
|
+
</wa-button>
|
|
726
|
+
<wa-button
|
|
727
|
+
size="small"
|
|
728
|
+
appearance="plain"
|
|
729
|
+
?disabled=${this.running}
|
|
730
|
+
@click=${() => void this.runQuery(false)}
|
|
731
|
+
title="Run all SQL"
|
|
732
|
+
>
|
|
733
|
+
<wa-icon name="play" label="Run"></wa-icon>
|
|
734
|
+
${this.running ? "Running…" : "Run all"}
|
|
735
|
+
</wa-button>
|
|
736
|
+
`;
|
|
737
|
+
}
|
|
738
|
+
renderContent() {
|
|
739
|
+
if (this.initialContent === void 0) return html$1`<div class="editor-placeholder"></div>`;
|
|
740
|
+
return html$1`
|
|
741
|
+
<div class="editor-area">
|
|
742
|
+
<lyra-monaco-widget
|
|
743
|
+
.value=${this.initialContent}
|
|
744
|
+
.uri=${this.initialUri}
|
|
745
|
+
.language=${"sql"}
|
|
746
|
+
.readOnly=${this.readOnly}
|
|
747
|
+
@content-change=${this._onContentChange}
|
|
748
|
+
${ref(this.widgetRef)}
|
|
749
|
+
></lyra-monaco-widget>
|
|
750
|
+
</div>
|
|
751
|
+
`;
|
|
752
|
+
}
|
|
753
|
+
static {
|
|
754
|
+
this.styles = css`
|
|
755
|
+
:host {
|
|
756
|
+
display: flex;
|
|
757
|
+
flex-direction: column;
|
|
758
|
+
position: relative;
|
|
759
|
+
width: 100%;
|
|
760
|
+
height: 100%;
|
|
761
|
+
}
|
|
762
|
+
.engine-select {
|
|
763
|
+
max-width: 10rem;
|
|
764
|
+
}
|
|
765
|
+
.connection-select {
|
|
766
|
+
max-width: 12rem;
|
|
767
|
+
}
|
|
768
|
+
.editor-area {
|
|
769
|
+
flex: 1;
|
|
770
|
+
min-height: 0;
|
|
771
|
+
height: 100%;
|
|
772
|
+
display: flex;
|
|
773
|
+
flex-direction: column;
|
|
774
|
+
overflow: hidden;
|
|
775
|
+
}
|
|
776
|
+
.editor-area lyra-monaco-widget,
|
|
777
|
+
.editor-area monaco-widget {
|
|
778
|
+
flex: 1;
|
|
779
|
+
min-height: 0;
|
|
780
|
+
}
|
|
781
|
+
.editor-placeholder {
|
|
782
|
+
flex: 1;
|
|
783
|
+
min-height: 0;
|
|
784
|
+
}
|
|
785
|
+
`;
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
_decorate([property({ attribute: false })], LyraSqlEditor.prototype, "input", void 0);
|
|
789
|
+
_decorate([property({ type: Boolean })], LyraSqlEditor.prototype, "readOnly", void 0);
|
|
790
|
+
_decorate([state()], LyraSqlEditor.prototype, "initialContent", void 0);
|
|
791
|
+
_decorate([state()], LyraSqlEditor.prototype, "initialUri", void 0);
|
|
792
|
+
_decorate([state()], LyraSqlEditor.prototype, "running", void 0);
|
|
793
|
+
_decorate([state()], LyraSqlEditor.prototype, "availableAdapters", void 0);
|
|
794
|
+
_decorate([state()], LyraSqlEditor.prototype, "selectedEngineId", void 0);
|
|
795
|
+
_decorate([state()], LyraSqlEditor.prototype, "availableConnections", void 0);
|
|
796
|
+
_decorate([state()], LyraSqlEditor.prototype, "selectedConnectionId", void 0);
|
|
797
|
+
LyraSqlEditor = _decorate([customElement("lyra-sql-editor")], LyraSqlEditor);
|
|
798
|
+
//#endregion
|
|
799
|
+
//#region src/sqleditor-extension.ts
|
|
800
|
+
function activate() {
|
|
801
|
+
editorRegistry.registerEditorInputHandler({
|
|
802
|
+
editorId: "system.sqleditor",
|
|
803
|
+
label: "SQL Editor",
|
|
804
|
+
icon: "database",
|
|
805
|
+
canHandle: (input) => input instanceof File && input.getName().toLowerCase().endsWith(".sql"),
|
|
806
|
+
ranking: 900,
|
|
807
|
+
handle: async (input) => {
|
|
808
|
+
const editorInput = {
|
|
809
|
+
title: input.getWorkspacePath(),
|
|
810
|
+
data: input,
|
|
811
|
+
key: input.getWorkspacePath(),
|
|
812
|
+
icon: "database",
|
|
813
|
+
state: {},
|
|
814
|
+
component: () => null
|
|
815
|
+
};
|
|
816
|
+
editorInput.component = (id) => html`<lyra-sql-editor id="${id}" .input=${editorInput}></lyra-sql-editor>`;
|
|
817
|
+
return editorInput;
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
//#endregion
|
|
822
|
+
export { activate as default };
|
|
823
|
+
|
|
824
|
+
//# sourceMappingURL=sqleditor-extension-MEwwujrA.js.map
|