windmill-components 1.13.2 → 1.13.3

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.
@@ -6,6 +6,8 @@ import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
6
6
  import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
7
7
  import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
8
8
  import * as vscode from 'vscode';
9
+ import { createEventDispatcher } from 'svelte';
10
+ const dispatch = createEventDispatcher();
9
11
  let divEl = null;
10
12
  let editor;
11
13
  export let deno = false;
@@ -255,6 +257,7 @@ async function loadMonaco() {
255
257
  });
256
258
  editor.onDidChangeModelContent((event) => {
257
259
  code = getCode();
260
+ dispatch('change');
258
261
  });
259
262
  if (lang == 'json') {
260
263
  monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
@@ -21,6 +21,8 @@ declare const __propDef: {
21
21
  reloadWebsocket?: (() => Promise<void>) | undefined;
22
22
  };
23
23
  events: {
24
+ change: CustomEvent<any>;
25
+ } & {
24
26
  [evt: string]: CustomEvent<any>;
25
27
  };
26
28
  slots: {};
@@ -12,16 +12,11 @@ let argError = '';
12
12
  let editing = false;
13
13
  let oldArgName; // when editing argument and changing name
14
14
  let viewJsonSchema = false;
15
- let editor;
16
- $: schemaString = JSON.stringify(schema, null, '\t');
17
- export function getEditor() {
18
- return editor;
19
- }
20
15
  // Binding is not enough because monaco Editor does not support two-way binding
21
16
  export function getSchema() {
22
17
  if (viewJsonSchema) {
23
18
  try {
24
- schema = JSON.parse(editor.getCode());
19
+ schema = JSON.parse(schemaString);
25
20
  return schema;
26
21
  }
27
22
  catch (err) {
@@ -30,7 +25,7 @@ export function getSchema() {
30
25
  }
31
26
  else {
32
27
  try {
33
- editor.setCode(JSON.stringify(schema, null, '\t'));
28
+ schemaString = JSON.stringify(schema, null, '\t');
34
29
  return schema;
35
30
  }
36
31
  catch (err) {
@@ -66,6 +61,8 @@ function handleAddOrEditArgument() {
66
61
  oldArgName = undefined;
67
62
  schemaModal.closeModal();
68
63
  }
64
+ schema = schema;
65
+ schemaString = JSON.stringify(schema, null, '\t');
69
66
  }
70
67
  function startEditArgument(argName) {
71
68
  argError = '';
@@ -83,7 +80,8 @@ function handleDeleteArgument(argName) {
83
80
  try {
84
81
  if (Object.keys(schema.properties).includes(argName)) {
85
82
  delete schema.properties[argName];
86
- schema = schema; //needed for reactivity, see https://svelte.dev/tutorial/updating-arrays-and-objects
83
+ schema = schema;
84
+ schemaString = JSON.stringify(schema, null, '\t');
87
85
  }
88
86
  else {
89
87
  throw Error('Argument not found!');
@@ -96,21 +94,14 @@ function handleDeleteArgument(argName) {
96
94
  }
97
95
  function switchTab() {
98
96
  if (viewJsonSchema) {
99
- let schemaString = editor.getCode();
100
97
  if (schemaString === '') {
101
98
  schemaString = JSON.stringify(emptySchema(), null, 4);
102
99
  }
103
- try {
104
- schema = JSON.parse(schemaString);
105
- viewJsonSchema = false;
106
- }
107
- catch (err) {
108
- sendUserToast(err, true);
109
- }
100
+ viewJsonSchema = false;
110
101
  }
111
102
  else {
112
103
  try {
113
- editor.setCode(JSON.stringify(schema, null, '\t'));
104
+ schemaString = JSON.stringify(schema, null, '\t');
114
105
  viewJsonSchema = true;
115
106
  }
116
107
  catch (err) {
@@ -153,61 +144,75 @@ function switchTab() {
153
144
  </div>
154
145
  <!--json schema or table view-->
155
146
  <div class="border-t py-1 h-full overflow-y-auto">
156
- <div class="h-full {viewJsonSchema ? 'hidden' : ''}">
157
- {#if schema.properties && Object.keys(schema.properties).length > 0 && schema.required}
158
- <TableCustom class="w-full min-h-full">
159
- <tr slot="header-row" class="underline">
160
- <th>name</th>
161
- <th>type</th>
162
- <th>description</th>
163
- <th>default</th>
164
- <th>required</th>
165
- </tr>
166
- <tbody slot="body">
167
- {#each Object.entries(schema.properties) as [name, property] (name)}
168
- <tr>
169
- <td>{name}</td>
170
- <td
171
- >{#if !property.type} any {:else} {property.type} {/if}</td
172
- >
173
- <td>{property.description}</td>
174
- <td>{JSON.stringify(property.default) ?? ''}</td>
175
- <td>{schema.required.includes(name) ? 'required' : 'optional'}</td>
176
- <td class="">
177
- <button class="mr-2" on:click={() => handleDeleteArgument(name)}
178
- ><svg
179
- class="w-4 h-4"
180
- fill="none"
181
- stroke="currentColor"
182
- viewBox="0 0 24 14"
183
- xmlns="http://www.w3.org/2000/svg"
147
+ {#if !viewJsonSchema}
148
+ <div class="h-full">
149
+ {#if schema.properties && Object.keys(schema.properties).length > 0 && schema.required}
150
+ <TableCustom class="w-full min-h-full">
151
+ <tr slot="header-row" class="underline">
152
+ <th>name</th>
153
+ <th>type</th>
154
+ <th>description</th>
155
+ <th>default</th>
156
+ <th>required</th>
157
+ </tr>
158
+ <tbody slot="body">
159
+ {#each Object.entries(schema.properties) as [name, property] (name)}
160
+ <tr>
161
+ <td>{name}</td>
162
+ <td
163
+ >{#if !property.type} any {:else} {property.type} {/if}</td
164
+ >
165
+ <td>{property.description}</td>
166
+ <td>{JSON.stringify(property.default) ?? ''}</td>
167
+ <td>{schema.required.includes(name) ? 'required' : 'optional'}</td>
168
+ <td class="">
169
+ <button class="mr-2" on:click={() => handleDeleteArgument(name)}
170
+ ><svg
171
+ class="w-4 h-4"
172
+ fill="none"
173
+ stroke="currentColor"
174
+ viewBox="0 0 24 14"
175
+ xmlns="http://www.w3.org/2000/svg"
176
+ >
177
+ <path
178
+ stroke-linecap="round"
179
+ stroke-linejoin="round"
180
+ stroke-width="2"
181
+ d="M6 18L18 6M6 6l12 12"
182
+ />
183
+ </svg></button
184
184
  >
185
- <path
186
- stroke-linecap="round"
187
- stroke-linejoin="round"
188
- stroke-width="2"
189
- d="M6 18L18 6M6 6l12 12"
190
- />
191
- </svg></button
185
+ <button
186
+ class="default-button-secondary text-xs inline-flex"
187
+ on:click={() => {
188
+ startEditArgument(name)
189
+ }}>edit</button
190
+ ></td
192
191
  >
193
- <button
194
- class="default-button-secondary text-xs inline-flex"
195
- on:click={() => {
196
- startEditArgument(name)
197
- }}>edit</button
198
- ></td
199
- >
200
- </tr>
201
- {/each}
202
- </tbody>
203
- </TableCustom>
204
- {:else}
205
- <div class="text-gray-700 text-xs italic">This script has no argument</div>
206
- {/if}
207
- </div>
208
- <div class={viewJsonSchema ? '' : 'hidden'}>
209
- <Editor code={schemaString} bind:this={editor} lang={'json'} class="small-editor" />
210
- </div>
192
+ </tr>
193
+ {/each}
194
+ </tbody>
195
+ </TableCustom>
196
+ {:else}
197
+ <div class="text-gray-700 text-xs italic">This script has no argument</div>
198
+ {/if}
199
+ </div>
200
+ {:else}
201
+ <div>
202
+ <Editor
203
+ on:change={() => {
204
+ try {
205
+ schema = JSON.parse(schemaString)
206
+ } catch (err) {
207
+ sendUserToast(err.message, true)
208
+ }
209
+ }}
210
+ bind:code={schemaString}
211
+ lang={'json'}
212
+ class="small-editor"
213
+ />
214
+ </div>
215
+ {/if}
211
216
  </div>
212
217
  </div>
213
218
 
@@ -1,10 +1,8 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  import type { Schema } from '../common';
3
- import Editor from './Editor.svelte';
4
3
  declare const __propDef: {
5
4
  props: {
6
5
  schema?: Schema | undefined;
7
- getEditor?: (() => Editor) | undefined;
8
6
  getSchema?: (() => Schema) | undefined;
9
7
  };
10
8
  events: {
@@ -16,7 +14,6 @@ export declare type SchemaEditorProps = typeof __propDef.props;
16
14
  export declare type SchemaEditorEvents = typeof __propDef.events;
17
15
  export declare type SchemaEditorSlots = typeof __propDef.slots;
18
16
  export default class SchemaEditor extends SvelteComponentTyped<SchemaEditorProps, SchemaEditorEvents, SchemaEditorSlots> {
19
- get getEditor(): () => Editor;
20
17
  get getSchema(): () => Schema;
21
18
  }
22
19
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "windmill-components",
3
- "version": "1.13.2",
3
+ "version": "1.13.3",
4
4
  "devDependencies": {
5
5
  "@sveltejs/adapter-node": "^1.0.0-next.78",
6
6
  "@sveltejs/adapter-static": "^1.0.0-next.34",