windmill-components 1.13.27 → 1.22.42
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/components/AppConnect.svelte +281 -0
- package/components/AppConnect.svelte.d.ts +22 -0
- package/components/ArgInput.svelte +32 -24
- package/components/ArgInput.svelte.d.ts +6 -1
- package/components/Button.svelte +16 -7
- package/components/CenteredModal.svelte +30 -0
- package/components/CenteredModal.svelte.d.ts +19 -0
- package/components/DisplayResult.svelte +52 -46
- package/components/Editor.svelte +69 -64
- package/components/Editor.svelte.d.ts +3 -1
- package/components/EditorBar.svelte +204 -0
- package/components/EditorBar.svelte.d.ts +23 -0
- package/components/FlowBuilder.svelte +57 -110
- package/components/FlowBuilder.svelte.d.ts +0 -2
- package/components/FlowEditor.svelte +183 -65
- package/components/FlowEditor.svelte.d.ts +4 -4
- package/components/FlowJobResult.svelte +23 -0
- package/components/FlowJobResult.svelte.d.ts +17 -0
- package/components/FlowPreview.svelte +17 -28
- package/components/FlowPreview.svelte.d.ts +7 -1
- package/components/FlowStatusViewer.svelte +55 -25
- package/components/FlowStatusViewer.svelte.d.ts +1 -1
- package/components/FlowViewer.svelte +136 -0
- package/components/FlowViewer.svelte.d.ts +24 -0
- package/components/IconedResourceType.svelte +6 -4
- package/components/JobStatus.svelte +1 -1
- package/components/Modal.svelte +5 -3
- package/components/ModuleStep.svelte +129 -56
- package/components/ModuleStep.svelte.d.ts +4 -8
- package/components/ObjectResourceInput.svelte +0 -1
- package/components/Path.svelte +55 -9
- package/components/Path.svelte.d.ts +2 -0
- package/components/RadioButton.svelte +1 -1
- package/components/RadioButtonV2.svelte +33 -0
- package/components/RadioButtonV2.svelte.d.ts +20 -0
- package/components/ResourceEditor.svelte +19 -15
- package/components/ResourcePicker.svelte +2 -2
- package/components/ResourcePicker.svelte.d.ts +2 -2
- package/components/RunForm.svelte +2 -3
- package/components/SchemaForm.svelte +119 -121
- package/components/SchemaForm.svelte.d.ts +6 -4
- package/components/SchemaModal.svelte +1 -1
- package/components/SchemaModal.svelte.d.ts +1 -1
- package/components/SchemaViewer.svelte +1 -1
- package/components/ScriptBuilder.svelte +43 -62
- package/components/ScriptEditor.svelte +12 -189
- package/components/ScriptPicker.svelte +7 -18
- package/components/ScriptPicker.svelte.d.ts +1 -0
- package/components/Switch.svelte.d.ts +2 -2
- package/components/Toggle.svelte +34 -0
- package/components/Toggle.svelte.d.ts +28 -0
- package/components/Tooltip.svelte +53 -80
- package/components/Tooltip.svelte.d.ts +1 -5
- package/components/VariableEditor.svelte +11 -2
- package/components/flows/CopyFirstStepSchema.svelte +10 -0
- package/components/flows/CopyFirstStepSchema.svelte.d.ts +14 -0
- package/components/flows/DynamicInputHelpBox.svelte +72 -0
- package/components/flows/DynamicInputHelpBox.svelte.d.ts +14 -0
- package/components/flows/FlowInputs.svelte +27 -0
- package/components/flows/FlowInputs.svelte.d.ts +19 -0
- package/components/flows/FlowModuleHeader.svelte +92 -0
- package/components/flows/FlowModuleHeader.svelte.d.ts +22 -0
- package/components/flows/flowStore.d.ts +17 -0
- package/components/flows/flowStore.js +161 -0
- package/components/flows/pickers/FlowScriptPicker.svelte +11 -0
- package/components/flows/pickers/FlowScriptPicker.svelte.d.ts +22 -0
- package/components/flows/pickers/PickHubScript.svelte +30 -0
- package/components/flows/pickers/PickHubScript.svelte.d.ts +18 -0
- package/components/flows/pickers/PickScript.svelte +38 -0
- package/components/flows/pickers/PickScript.svelte.d.ts +18 -0
- package/components/flows/utils.d.ts +17 -0
- package/components/flows/utils.js +143 -0
- package/components/propertyPicker/ObjectViewer.svelte +113 -0
- package/components/propertyPicker/ObjectViewer.svelte.d.ts +21 -0
- package/components/propertyPicker/OverlayPropertyPicker.svelte +69 -0
- package/components/propertyPicker/OverlayPropertyPicker.svelte.d.ts +21 -0
- package/components/propertyPicker/PropPicker.svelte +24 -0
- package/components/propertyPicker/PropPicker.svelte.d.ts +18 -0
- package/components/propertyPicker/WarningMessage.svelte +43 -0
- package/components/propertyPicker/WarningMessage.svelte.d.ts +16 -0
- package/components/propertyPicker/utils.d.ts +2 -0
- package/components/propertyPicker/utils.js +40 -0
- package/gen/core/ApiError.d.ts +3 -1
- package/gen/core/ApiError.js +3 -1
- package/gen/core/OpenAPI.js +1 -1
- package/gen/core/request.js +2 -2
- package/gen/index.d.ts +4 -0
- package/gen/index.js +1 -0
- package/gen/models/CompletedJob.d.ts +3 -1
- package/gen/models/CompletedJob.js +1 -0
- package/gen/models/CreateResource.d.ts +1 -0
- package/gen/models/CreateVariable.d.ts +2 -0
- package/gen/models/FlowModule.d.ts +2 -0
- package/gen/models/FlowModuleValue.d.ts +14 -2
- package/gen/models/FlowModuleValue.js +7 -0
- package/gen/models/FlowStatusModule.d.ts +6 -0
- package/gen/models/ListableVariable.d.ts +2 -0
- package/gen/models/OpenFlow.d.ts +7 -0
- package/gen/models/OpenFlow.js +4 -0
- package/gen/models/QueuedJob.d.ts +2 -1
- package/gen/models/QueuedJob.js +1 -0
- package/gen/models/Resource.d.ts +1 -0
- package/gen/models/Script.d.ts +1 -0
- package/gen/models/SlackToken.d.ts +8 -0
- package/gen/models/SlackToken.js +4 -0
- package/gen/models/TokenResponse.d.ts +6 -0
- package/gen/models/TokenResponse.js +4 -0
- package/gen/services/AdminService.d.ts +6 -2
- package/gen/services/AuditService.d.ts +24 -8
- package/gen/services/FlowService.d.ts +50 -10
- package/gen/services/FlowService.js +26 -0
- package/gen/services/GranularAclService.d.ts +6 -2
- package/gen/services/GroupService.d.ts +18 -6
- package/gen/services/JobService.d.ts +167 -46
- package/gen/services/JobService.js +26 -2
- package/gen/services/OauthService.d.ts +104 -0
- package/gen/services/OauthService.js +133 -0
- package/gen/services/ResourceService.d.ts +39 -7
- package/gen/services/ResourceService.js +30 -0
- package/gen/services/ScheduleService.d.ts +36 -6
- package/gen/services/ScheduleService.js +30 -0
- package/gen/services/ScriptService.d.ts +77 -19
- package/gen/services/ScriptService.js +31 -1
- package/gen/services/UserService.d.ts +49 -11
- package/gen/services/UserService.js +17 -0
- package/gen/services/VariableService.d.ts +19 -4
- package/gen/services/VariableService.js +15 -0
- package/gen/services/WorkerService.d.ts +6 -2
- package/gen/services/WorkspaceService.d.ts +29 -24
- package/gen/services/WorkspaceService.js +8 -23
- package/logout.js +10 -3
- package/package.json +52 -23
- package/script_helpers.d.ts +4 -0
- package/script_helpers.js +70 -0
- package/scripts.d.ts +2 -1
- package/scripts.js +5 -5
- package/stores.d.ts +7 -0
- package/stores.js +12 -0
- package/utils.d.ts +28 -1
- package/utils.js +206 -0
|
@@ -50,52 +50,58 @@ function inferResultKind(result) {
|
|
|
50
50
|
<svelte:head>
|
|
51
51
|
{@html github}
|
|
52
52
|
</svelte:head>
|
|
53
|
-
{#if
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
<div class="
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
{:else if resultKind == 'table-row'}<div
|
|
71
|
-
class="grid grid-flow-col-dense border border-gray-200 rounded-md "
|
|
72
|
-
>
|
|
73
|
-
<TableCustom>
|
|
74
|
-
<tbody slot="body">
|
|
75
|
-
{#each asListOfList(Object.values(result)[0]) as row}
|
|
76
|
-
<tr>
|
|
77
|
-
{#each row as v}
|
|
78
|
-
<td>{v ?? ''}</td>
|
|
53
|
+
{#if result}
|
|
54
|
+
{#if Object.keys(result).length > 0}<div>
|
|
55
|
+
The result keys are: <b>{Object.keys(result).join(', ')}</b>
|
|
56
|
+
</div>
|
|
57
|
+
{/if}
|
|
58
|
+
{#if resultKind == 'table-col'}
|
|
59
|
+
<div class="grid grid-flow-col-dense border border-gray-200 rounded-md ">
|
|
60
|
+
{#each Object.keys(result) as col}
|
|
61
|
+
<div class="flex flex-col min-w-full">
|
|
62
|
+
<div class="px-12 text-left uppercase border-b bg-gray-50 overflow-hidden rounded-t-md ">
|
|
63
|
+
{col}
|
|
64
|
+
</div>
|
|
65
|
+
{#if Array.isArray(result[col])}
|
|
66
|
+
{#each result[col] as item}
|
|
67
|
+
<div class="px-12 text-left">
|
|
68
|
+
{typeof item === 'string' ? item : JSON.stringify(item)}
|
|
69
|
+
</div>
|
|
79
70
|
{/each}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
</
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
<div class="h-full">
|
|
87
|
-
Result is an image: <img
|
|
88
|
-
alt="png rendered"
|
|
89
|
-
class="w-auto h-full"
|
|
90
|
-
src="data:image/png;base64,{result.png}"
|
|
91
|
-
/>
|
|
92
|
-
</div>
|
|
93
|
-
{:else if resultKind == 'file'}
|
|
94
|
-
<div>
|
|
95
|
-
Result is a file: <a
|
|
96
|
-
download="windmill.file"
|
|
97
|
-
href="data:application/octet-stream;base64,{result.file}">Download</a
|
|
71
|
+
{/if}
|
|
72
|
+
</div>
|
|
73
|
+
{/each}
|
|
74
|
+
</div>
|
|
75
|
+
{:else if resultKind == 'table-row'}<div
|
|
76
|
+
class="grid grid-flow-col-dense border border-gray-200 rounded-md "
|
|
98
77
|
>
|
|
99
|
-
|
|
100
|
-
|
|
78
|
+
<TableCustom>
|
|
79
|
+
<tbody slot="body">
|
|
80
|
+
{#each asListOfList(Object.values(result)[0]) as row}
|
|
81
|
+
<tr>
|
|
82
|
+
{#each row as v}
|
|
83
|
+
<td>{v ?? ''}</td>
|
|
84
|
+
{/each}
|
|
85
|
+
</tr>
|
|
86
|
+
{/each}
|
|
87
|
+
</tbody>
|
|
88
|
+
</TableCustom>
|
|
89
|
+
</div>
|
|
90
|
+
{:else if resultKind == 'png'}
|
|
91
|
+
<div class="h-full">
|
|
92
|
+
Result is an image: <img
|
|
93
|
+
alt="png rendered"
|
|
94
|
+
class="w-auto h-full"
|
|
95
|
+
src="data:image/png;base64,{result.png}"
|
|
96
|
+
/>
|
|
97
|
+
</div>
|
|
98
|
+
{:else if resultKind == 'file'}
|
|
99
|
+
<div>
|
|
100
|
+
Result is a file: <a
|
|
101
|
+
download="windmill.file"
|
|
102
|
+
href="data:application/octet-stream;base64,{result.file}">Download</a
|
|
103
|
+
>
|
|
104
|
+
</div>
|
|
105
|
+
{:else}<Highlight language={json} code={JSON.stringify(result, null, 4).replace(/\\n/g, '\n')} />
|
|
106
|
+
{/if}
|
|
101
107
|
{/if}
|
package/components/Editor.svelte
CHANGED
|
@@ -1,39 +1,48 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
<script>import { browser, dev } from '$app/env';
|
|
2
|
+
import { page } from '$app/stores';
|
|
3
|
+
import { buildExtraLib, sendUserToast } from '../utils';
|
|
4
4
|
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
|
|
5
5
|
import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
|
|
6
6
|
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
|
|
7
|
-
import { createEventDispatcher } from 'svelte';
|
|
8
|
-
|
|
7
|
+
import { createEventDispatcher, onDestroy, onMount } from 'svelte';
|
|
8
|
+
import { buildWorkerDefinition } from 'monaco-editor-workers';
|
|
9
9
|
let divEl = null;
|
|
10
10
|
let editor;
|
|
11
11
|
export let deno = false;
|
|
12
12
|
export let lang = deno ? 'typescript' : 'python';
|
|
13
|
-
export let code;
|
|
13
|
+
export let code = '';
|
|
14
14
|
export let hash = (Math.random() + 1).toString(36).substring(2);
|
|
15
15
|
export let cmdEnterAction = undefined;
|
|
16
16
|
export let formatAction = undefined;
|
|
17
17
|
export let automaticLayout = true;
|
|
18
18
|
export let websocketAlive = { pyright: false, black: false, deno: false };
|
|
19
|
+
export let extraLib = lang == 'typescript' && !deno ? buildExtraLib() : '';
|
|
20
|
+
export let extraLibPath = 'file:///node_modules/@types/windmill/index.d.ts';
|
|
19
21
|
let websockets = [];
|
|
22
|
+
let websocketInterval;
|
|
20
23
|
let uri = '';
|
|
21
24
|
let disposeMethod;
|
|
25
|
+
const dispatch = createEventDispatcher();
|
|
22
26
|
if (browser) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
if (dev) {
|
|
28
|
+
buildWorkerDefinition('../../../node_modules/monaco-editor-workers/dist/workers', import.meta.url, false);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
self.MonacoEnvironment = {
|
|
33
|
+
getWorker: function (_moduleId, label) {
|
|
34
|
+
if (label === 'json') {
|
|
35
|
+
return new jsonWorker();
|
|
36
|
+
}
|
|
37
|
+
else if (label === 'typescript' || label === 'javascript') {
|
|
38
|
+
return new tsWorker();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return new editorWorker();
|
|
42
|
+
}
|
|
34
43
|
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
37
46
|
}
|
|
38
47
|
export function getCode() {
|
|
39
48
|
return editor?.getValue();
|
|
@@ -73,16 +82,17 @@ export async function reloadWebsocket() {
|
|
|
73
82
|
const { MonacoLanguageClient } = await import('monaco-languageclient');
|
|
74
83
|
const { CloseAction, ErrorAction } = await import('vscode-languageclient');
|
|
75
84
|
const vscode = await import('vscode');
|
|
76
|
-
const {
|
|
85
|
+
const { toSocket, WebSocketMessageReader, WebSocketMessageWriter } = await import('vscode-ws-jsonrpc');
|
|
86
|
+
const { RequestType } = await import('vscode-jsonrpc');
|
|
77
87
|
function createLanguageClient(transports, name, initializationOptions) {
|
|
78
88
|
const client = new MonacoLanguageClient({
|
|
79
89
|
name: name,
|
|
80
90
|
clientOptions: {
|
|
81
91
|
documentSelector: deno ? ['typescript'] : ['python'],
|
|
82
92
|
errorHandler: {
|
|
83
|
-
error: () => ({ action: ErrorAction.
|
|
93
|
+
error: () => ({ action: ErrorAction.Continue }),
|
|
84
94
|
closed: () => ({
|
|
85
|
-
action: CloseAction.
|
|
95
|
+
action: CloseAction.DoNotRestart
|
|
86
96
|
})
|
|
87
97
|
},
|
|
88
98
|
markdown: {
|
|
@@ -120,15 +130,29 @@ export async function reloadWebsocket() {
|
|
|
120
130
|
const writer = new WebSocketMessageWriter(socket);
|
|
121
131
|
const languageClient = createLanguageClient({ reader, writer }, name, options);
|
|
122
132
|
languageClient.start();
|
|
133
|
+
reader.onClose(() => {
|
|
134
|
+
try {
|
|
135
|
+
languageClient.stop();
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
console.error(err);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
123
141
|
socket.onClose((_code, _reason) => {
|
|
124
142
|
websocketAlive[name] = false;
|
|
125
143
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
144
|
+
if (name == 'deno') {
|
|
145
|
+
vscode.commands.getCommands().then((v) => {
|
|
146
|
+
if (!v.includes('deno.cache')) {
|
|
147
|
+
vscode.commands.registerCommand('deno.cache', (uris = []) => {
|
|
148
|
+
languageClient.sendRequest(new RequestType('deno/cache'), {
|
|
149
|
+
referrer: { uri },
|
|
150
|
+
uris: uris.map((uri) => ({ uri }))
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
|
130
154
|
});
|
|
131
|
-
}
|
|
155
|
+
}
|
|
132
156
|
websocketAlive[name] = true;
|
|
133
157
|
};
|
|
134
158
|
}
|
|
@@ -191,6 +215,15 @@ export async function reloadWebsocket() {
|
|
|
191
215
|
}
|
|
192
216
|
});
|
|
193
217
|
}
|
|
218
|
+
websocketInterval && clearInterval(websocketInterval);
|
|
219
|
+
websocketInterval = setInterval(() => {
|
|
220
|
+
if (document.visibilityState == 'visible') {
|
|
221
|
+
if (!websocketAlive.black && !websocketAlive.deno && !websocketAlive.pyright) {
|
|
222
|
+
sendUserToast('Smart assistant got disconnected. Reconnecting to windmill language server for smart assistance');
|
|
223
|
+
reloadWebsocket();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}, 5000);
|
|
194
227
|
}
|
|
195
228
|
}
|
|
196
229
|
function closeWebsockets() {
|
|
@@ -203,6 +236,7 @@ function closeWebsockets() {
|
|
|
203
236
|
}
|
|
204
237
|
}
|
|
205
238
|
websockets = [];
|
|
239
|
+
websocketInterval && clearInterval(websocketInterval);
|
|
206
240
|
}
|
|
207
241
|
async function loadMonaco() {
|
|
208
242
|
const monaco = await import('monaco-editor');
|
|
@@ -245,6 +279,12 @@ async function loadMonaco() {
|
|
|
245
279
|
scrollBeyondLastLine: false,
|
|
246
280
|
minimap: {
|
|
247
281
|
enabled: false
|
|
282
|
+
},
|
|
283
|
+
scrollbar: {
|
|
284
|
+
alwaysConsumeMouseWheel: false
|
|
285
|
+
},
|
|
286
|
+
lightbulb: {
|
|
287
|
+
enabled: true
|
|
248
288
|
}
|
|
249
289
|
});
|
|
250
290
|
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, function () {
|
|
@@ -281,47 +321,12 @@ async function loadMonaco() {
|
|
|
281
321
|
});
|
|
282
322
|
}
|
|
283
323
|
else {
|
|
284
|
-
monaco.languages.typescript.typescriptDefaults.addExtraLib(
|
|
285
|
-
/**
|
|
286
|
-
* get variable (including secret) at path
|
|
287
|
-
* @param {string} path - path of the variable (e.g: g/all/pretty_secret)
|
|
288
|
-
*/
|
|
289
|
-
export function variable(path: string): string;
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* get resource at path
|
|
293
|
-
* @param {string} path - path of the resource (e.g: g/all/my_resource)
|
|
294
|
-
*/
|
|
295
|
-
export function resource(path: string): any;
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* get result of step n.
|
|
299
|
-
* If n is negative, for instance -1, it is the step just before this one.
|
|
300
|
-
* Step 0 is flow input.
|
|
301
|
-
* @param {number} n - step number.
|
|
302
|
-
*/
|
|
303
|
-
export function step(n: number): any;
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* flow input as an object
|
|
307
|
-
*/
|
|
308
|
-
export const flow_input: any;
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* previous result as an object
|
|
312
|
-
*/
|
|
313
|
-
export const previous_result: any;
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* static params of this same step
|
|
317
|
-
*/
|
|
318
|
-
export const params: any;
|
|
319
|
-
`, 'file:///node_modules/@types/windmill/index.d.ts');
|
|
324
|
+
monaco.languages.typescript.typescriptDefaults.addExtraLib(extraLib, extraLibPath);
|
|
320
325
|
}
|
|
321
326
|
}
|
|
322
327
|
if (lang == 'python' || deno) {
|
|
323
328
|
const { MonacoServices } = await import('monaco-languageclient');
|
|
324
|
-
MonacoServices.install(
|
|
329
|
+
MonacoServices.install();
|
|
325
330
|
}
|
|
326
331
|
reloadWebsocket();
|
|
327
332
|
return () => {
|
|
@@ -4,7 +4,7 @@ declare const __propDef: {
|
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
deno?: boolean | undefined;
|
|
6
6
|
lang?: string | undefined;
|
|
7
|
-
code
|
|
7
|
+
code?: string | undefined;
|
|
8
8
|
hash?: string | undefined;
|
|
9
9
|
cmdEnterAction?: (() => void) | undefined;
|
|
10
10
|
formatAction?: (() => void) | undefined;
|
|
@@ -14,6 +14,8 @@ declare const __propDef: {
|
|
|
14
14
|
black: boolean;
|
|
15
15
|
deno: boolean;
|
|
16
16
|
} | undefined;
|
|
17
|
+
extraLib?: string | undefined;
|
|
18
|
+
extraLibPath?: string | undefined;
|
|
17
19
|
getCode?: (() => string) | undefined;
|
|
18
20
|
insertAtCursor?: ((code: string) => void) | undefined;
|
|
19
21
|
insertAtBeginning?: ((code: string) => void) | undefined;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
<script>import { ResourceService, ScriptService, VariableService } from '../gen';
|
|
2
|
+
import { getScriptByPath, loadHubScripts, sendUserToast } from '../utils';
|
|
3
|
+
import Icon from 'svelte-awesome';
|
|
4
|
+
import { faSearch } from '@fortawesome/free-solid-svg-icons';
|
|
5
|
+
import { workspaceStore, hubScripts } from '../stores';
|
|
6
|
+
import ItemPicker from './ItemPicker.svelte';
|
|
7
|
+
import VariableEditor from './VariableEditor.svelte';
|
|
8
|
+
import ResourceEditor from './ResourceEditor.svelte';
|
|
9
|
+
import { Highlight } from 'svelte-highlight';
|
|
10
|
+
import { python, typescript } from 'svelte-highlight/languages';
|
|
11
|
+
import github from 'svelte-highlight/styles/github';
|
|
12
|
+
import Modal from './Modal.svelte';
|
|
13
|
+
export let lang;
|
|
14
|
+
export let editor;
|
|
15
|
+
export let websocketAlive;
|
|
16
|
+
let variablePicker;
|
|
17
|
+
let resourcePicker;
|
|
18
|
+
let scriptPicker;
|
|
19
|
+
let variableEditor;
|
|
20
|
+
let resourceEditor;
|
|
21
|
+
let codeViewer;
|
|
22
|
+
let codeLang = 'deno';
|
|
23
|
+
let codeContent = '';
|
|
24
|
+
async function loadVariables() {
|
|
25
|
+
let r = [];
|
|
26
|
+
const variables = (await VariableService.listVariable({ workspace: $workspaceStore ?? 'NO_W' })).map((x) => {
|
|
27
|
+
return { name: x.path, ...x };
|
|
28
|
+
});
|
|
29
|
+
const rvariables = await VariableService.listContextualVariables({
|
|
30
|
+
workspace: $workspaceStore ?? 'NO_W'
|
|
31
|
+
});
|
|
32
|
+
r = r.concat(variables).concat(rvariables);
|
|
33
|
+
return r;
|
|
34
|
+
}
|
|
35
|
+
async function loadScripts() {
|
|
36
|
+
const workspaceScripts = await ScriptService.listScripts({
|
|
37
|
+
workspace: $workspaceStore ?? 'NO_W'
|
|
38
|
+
});
|
|
39
|
+
await loadHubScripts();
|
|
40
|
+
const hubScripts_ = $hubScripts ?? [];
|
|
41
|
+
return workspaceScripts.concat(hubScripts_);
|
|
42
|
+
}
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<svelte:head>
|
|
46
|
+
{@html github}
|
|
47
|
+
</svelte:head>
|
|
48
|
+
|
|
49
|
+
<ItemPicker
|
|
50
|
+
bind:this={scriptPicker}
|
|
51
|
+
pickCallback={async (path, _) => {
|
|
52
|
+
const { language, content } = await getScriptByPath(path ?? '')
|
|
53
|
+
codeContent = content
|
|
54
|
+
codeLang = language
|
|
55
|
+
codeViewer.openModal()
|
|
56
|
+
}}
|
|
57
|
+
closeOnClick={false}
|
|
58
|
+
itemName="script"
|
|
59
|
+
extraField="summary"
|
|
60
|
+
loadItems={loadScripts}
|
|
61
|
+
/>
|
|
62
|
+
|
|
63
|
+
<Modal bind:this={codeViewer}>
|
|
64
|
+
<div slot="title">Code</div>
|
|
65
|
+
<div slot="content">
|
|
66
|
+
{#if codeLang == 'python3'}
|
|
67
|
+
<Highlight language={python} code={codeContent} />
|
|
68
|
+
{:else if codeLang == 'deno'}
|
|
69
|
+
<Highlight language={typescript} code={codeContent} />
|
|
70
|
+
{/if}
|
|
71
|
+
</div></Modal
|
|
72
|
+
>
|
|
73
|
+
|
|
74
|
+
<ItemPicker
|
|
75
|
+
bind:this={variablePicker}
|
|
76
|
+
pickCallback={(path, name) => {
|
|
77
|
+
if (!path) {
|
|
78
|
+
if (lang == 'deno') {
|
|
79
|
+
editor.insertAtCursor(`Deno.env.get('${name}')`)
|
|
80
|
+
} else {
|
|
81
|
+
if (!editor.getCode().includes('import os')) {
|
|
82
|
+
editor.insertAtBeginning('import os\n')
|
|
83
|
+
}
|
|
84
|
+
editor.insertAtCursor(`os.environ.get("${name}")`)
|
|
85
|
+
}
|
|
86
|
+
sendUserToast(`${name} inserted at cursor`)
|
|
87
|
+
} else {
|
|
88
|
+
if (lang == 'deno') {
|
|
89
|
+
if (!editor.getCode().includes('import * as wmill from')) {
|
|
90
|
+
editor.insertAtBeginning(
|
|
91
|
+
`import * as wmill from 'https://deno.land/x/windmill@v${__pkg__.version}/index.ts'\n`
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
editor.insertAtCursor(`(await wmill.getVariable('${path}'))`)
|
|
95
|
+
} else {
|
|
96
|
+
if (!editor.getCode().includes('import wmill')) {
|
|
97
|
+
editor.insertAtBeginning('import wmill\n')
|
|
98
|
+
}
|
|
99
|
+
editor.insertAtCursor(`wmill.get_variable("${path}")`)
|
|
100
|
+
}
|
|
101
|
+
sendUserToast(`${name} inserted at cursor`)
|
|
102
|
+
}
|
|
103
|
+
}}
|
|
104
|
+
itemName="Variable"
|
|
105
|
+
extraField="name"
|
|
106
|
+
loadItems={loadVariables}
|
|
107
|
+
>
|
|
108
|
+
<div slot="submission" class="flex flex-row">
|
|
109
|
+
<div class="text-xs mr-2 align-middle">
|
|
110
|
+
The variable you were looking for does not exist yet?
|
|
111
|
+
</div>
|
|
112
|
+
<button
|
|
113
|
+
class="default-button-secondary"
|
|
114
|
+
type="button"
|
|
115
|
+
on:click={() => {
|
|
116
|
+
variableEditor.initNew()
|
|
117
|
+
}}
|
|
118
|
+
>
|
|
119
|
+
Create a new variable
|
|
120
|
+
</button>
|
|
121
|
+
</div>
|
|
122
|
+
</ItemPicker>
|
|
123
|
+
|
|
124
|
+
<ItemPicker
|
|
125
|
+
bind:this={resourcePicker}
|
|
126
|
+
pickCallback={(path, _) => {
|
|
127
|
+
if (lang == 'deno') {
|
|
128
|
+
if (!editor.getCode().includes('import * as wmill from')) {
|
|
129
|
+
editor.insertAtBeginning(
|
|
130
|
+
`import * as wmill from 'https://deno.land/x/windmill@v${__pkg__.version}/index.ts'\n`
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
editor.insertAtCursor(`(await wmill.getResource('${path}'))`)
|
|
134
|
+
} else {
|
|
135
|
+
if (!editor.getCode().includes('import wmill')) {
|
|
136
|
+
editor.insertAtBeginning('import wmill\n')
|
|
137
|
+
}
|
|
138
|
+
editor.insertAtCursor(`wmill.get_resource("${path}")`)
|
|
139
|
+
}
|
|
140
|
+
sendUserToast(`${path} inserted at cursor`)
|
|
141
|
+
}}
|
|
142
|
+
itemName="Resource"
|
|
143
|
+
extraField="resource_type"
|
|
144
|
+
loadItems={async () =>
|
|
145
|
+
await ResourceService.listResource({ workspace: $workspaceStore ?? 'NO_W' })}
|
|
146
|
+
>
|
|
147
|
+
<div slot="submission" class="flex flex-row">
|
|
148
|
+
<div class="text-xs mr-2 align-middle">
|
|
149
|
+
The resource you were looking for does not exist yet?
|
|
150
|
+
</div>
|
|
151
|
+
<button
|
|
152
|
+
class="default-button-secondary"
|
|
153
|
+
type="button"
|
|
154
|
+
on:click={() => {
|
|
155
|
+
resourceEditor.initNew()
|
|
156
|
+
}}
|
|
157
|
+
>
|
|
158
|
+
Create a new resource
|
|
159
|
+
</button>
|
|
160
|
+
</div>
|
|
161
|
+
</ItemPicker>
|
|
162
|
+
|
|
163
|
+
<ResourceEditor bind:this={resourceEditor} on:refresh={resourcePicker.openModal} />
|
|
164
|
+
|
|
165
|
+
<VariableEditor bind:this={variableEditor} on:create={variablePicker.openModal} />
|
|
166
|
+
|
|
167
|
+
<div class="flex flex-row justify-around w-full">
|
|
168
|
+
<button
|
|
169
|
+
class="default-button-secondary font-semibold py-px mr-2 text-xs align-middle max-h-8"
|
|
170
|
+
on:click|stopPropagation={() => {
|
|
171
|
+
variablePicker.openModal()
|
|
172
|
+
}}
|
|
173
|
+
>Variable picker <Icon data={faSearch} scale={0.7} />
|
|
174
|
+
</button>
|
|
175
|
+
|
|
176
|
+
<button
|
|
177
|
+
class="default-button-secondary font-semibold py-px text-xs mr-2 align-middle max-h-8"
|
|
178
|
+
on:click|stopPropagation={() => {
|
|
179
|
+
resourcePicker.openModal()
|
|
180
|
+
}}
|
|
181
|
+
>Resource picker <Icon data={faSearch} scale={0.7} />
|
|
182
|
+
</button>
|
|
183
|
+
<button
|
|
184
|
+
class="default-button-secondary font-semibold py-px text-xs mr-2 align-middle max-h-8"
|
|
185
|
+
on:click|stopPropagation={() => {
|
|
186
|
+
scriptPicker.openModal()
|
|
187
|
+
}}
|
|
188
|
+
>Script explorer <Icon data={faSearch} scale={0.7} />
|
|
189
|
+
</button>
|
|
190
|
+
|
|
191
|
+
<button
|
|
192
|
+
class="default-button-secondary py-px max-h-8 text-xs"
|
|
193
|
+
on:click|stopPropagation={() => {
|
|
194
|
+
editor.reloadWebsocket()
|
|
195
|
+
}}
|
|
196
|
+
>
|
|
197
|
+
Reload assistants (status: {#if lang == 'deno'}<span
|
|
198
|
+
class={websocketAlive.deno ? 'text-green-600' : 'text-red-600'}>deno</span
|
|
199
|
+
>{:else if lang == 'python3'}<span
|
|
200
|
+
class={websocketAlive.pyright ? 'text-green-600' : 'text-red-600'}>pyright</span
|
|
201
|
+
>
|
|
202
|
+
<span class={websocketAlive.black ? 'text-green-600' : 'text-red-600'}> black</span>{/if})
|
|
203
|
+
</button>
|
|
204
|
+
</div>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type Editor from './Editor.svelte';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
lang: 'python3' | 'deno';
|
|
6
|
+
editor: Editor;
|
|
7
|
+
websocketAlive: {
|
|
8
|
+
pyright: boolean;
|
|
9
|
+
black: boolean;
|
|
10
|
+
deno: boolean;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
events: {
|
|
14
|
+
[evt: string]: CustomEvent<any>;
|
|
15
|
+
};
|
|
16
|
+
slots: {};
|
|
17
|
+
};
|
|
18
|
+
export declare type EditorBarProps = typeof __propDef.props;
|
|
19
|
+
export declare type EditorBarEvents = typeof __propDef.events;
|
|
20
|
+
export declare type EditorBarSlots = typeof __propDef.slots;
|
|
21
|
+
export default class EditorBar extends SvelteComponentTyped<EditorBarProps, EditorBarEvents, EditorBarSlots> {
|
|
22
|
+
}
|
|
23
|
+
export {};
|