@gradio/code 0.11.1 → 0.12.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @gradio/code
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Features
6
+
7
+ - [#10733](https://github.com/gradio-app/gradio/pull/10733) [`731ab92`](https://github.com/gradio-app/gradio/commit/731ab92001c88d4cf1062acf0a4f1108a4513014) - Autocompletion on code editor component. Thanks @whitphx!
8
+
9
+ ### Dependency updates
10
+
11
+ - @gradio/upload@0.15.5
12
+ - @gradio/statustracker@0.10.5
13
+ - @gradio/atoms@0.14.0
14
+
15
+ ## 0.11.2
16
+
17
+ ### Dependency updates
18
+
19
+ - @gradio/wasm@0.17.4
20
+ - @gradio/upload@0.15.4
21
+
3
22
  ## 0.11.1
4
23
 
5
24
  ### Dependency updates
package/Index.svelte CHANGED
@@ -40,6 +40,7 @@
40
40
  export let min_width: number | undefined = undefined;
41
41
  export let wrap_lines = false;
42
42
  export let show_line_numbers = true;
43
+ export let autocomplete = false;
43
44
 
44
45
  export let interactive: boolean;
45
46
 
@@ -93,6 +94,7 @@
93
94
  {dark_mode}
94
95
  {wrap_lines}
95
96
  {show_line_numbers}
97
+ {autocomplete}
96
98
  readonly={!interactive}
97
99
  on:blur={() => gradio.dispatch("blur")}
98
100
  on:focus={() => gradio.dispatch("focus")}
package/dist/Index.svelte CHANGED
@@ -27,6 +27,7 @@ export let scale = null;
27
27
  export let min_width = void 0;
28
28
  export let wrap_lines = false;
29
29
  export let show_line_numbers = true;
30
+ export let autocomplete = false;
30
31
  export let interactive;
31
32
  let dark_mode = gradio.theme === "dark";
32
33
  function handle_change() {
@@ -78,6 +79,7 @@ $:
78
79
  {dark_mode}
79
80
  {wrap_lines}
80
81
  {show_line_numbers}
82
+ {autocomplete}
81
83
  readonly={!interactive}
82
84
  on:blur={() => gradio.dispatch("blur")}
83
85
  on:focus={() => gradio.dispatch("focus")}
@@ -30,6 +30,7 @@ declare const __propDef: {
30
30
  min_width?: number | undefined;
31
31
  wrap_lines?: boolean | undefined;
32
32
  show_line_numbers?: boolean | undefined;
33
+ autocomplete?: boolean | undefined;
33
34
  interactive: boolean;
34
35
  };
35
36
  events: {
@@ -8,6 +8,7 @@ import {
8
8
  } from "@codemirror/view";
9
9
  import { StateEffect, EditorState } from "@codemirror/state";
10
10
  import { indentWithTab } from "@codemirror/commands";
11
+ import { autocompletion, acceptCompletion } from "@codemirror/autocomplete";
11
12
  import { basicDark } from "cm6-theme-basic-dark";
12
13
  import { basicLight } from "cm6-theme-basic-light";
13
14
  import { basicSetup } from "./extensions";
@@ -25,6 +26,7 @@ export let readonly = false;
25
26
  export let placeholder = void 0;
26
27
  export let wrap_lines = false;
27
28
  export let show_line_numbers = true;
29
+ export let autocomplete = false;
28
30
  const dispatch = createEventDispatcher();
29
31
  let lang_extension;
30
32
  let element;
@@ -156,6 +158,18 @@ const FontTheme = EditorView.theme({
156
158
  borderLeftColor: "var(--body-text-color)"
157
159
  }
158
160
  });
161
+ const AutocompleteTheme = EditorView.theme({
162
+ ".cm-tooltip-autocomplete": {
163
+ "& > ul": {
164
+ backgroundColor: "var(--background-fill-primary)",
165
+ color: "var(--body-text-color)"
166
+ },
167
+ "& > ul > li[aria-selected]": {
168
+ backgroundColor: "var(--color-accent-soft)",
169
+ color: "var(--body-text-color)"
170
+ }
171
+ }
172
+ });
159
173
  function create_editor_state(_value) {
160
174
  return EditorState.create({
161
175
  doc: _value ?? void 0,
@@ -172,7 +186,9 @@ function get_base_extensions(basic2, use_tab2, placeholder2, readonly2, lang, sh
172
186
  extensions2.push(basicSetup);
173
187
  }
174
188
  if (use_tab2) {
175
- extensions2.push(keymap.of([indentWithTab]));
189
+ extensions2.push(
190
+ keymap.of([{ key: "Tab", run: acceptCompletion }, indentWithTab])
191
+ );
176
192
  }
177
193
  if (placeholder2) {
178
194
  extensions2.push(placeholderExt(placeholder2));
@@ -183,6 +199,10 @@ function get_base_extensions(basic2, use_tab2, placeholder2, readonly2, lang, sh
183
199
  if (show_line_numbers2) {
184
200
  extensions2.push(lineNumbers());
185
201
  }
202
+ if (autocomplete) {
203
+ extensions2.push(autocompletion());
204
+ extensions2.push(AutocompleteTheme);
205
+ }
186
206
  extensions2.push(EditorView.updateListener.of(handle_change));
187
207
  if (wrap_lines) {
188
208
  extensions2.push(EditorView.lineWrapping);
@@ -15,6 +15,7 @@ declare const __propDef: {
15
15
  placeholder?: string | HTMLElement | null | undefined;
16
16
  wrap_lines?: boolean | undefined;
17
17
  show_line_numbers?: boolean | undefined;
18
+ autocomplete?: boolean | undefined;
18
19
  };
19
20
  events: {
20
21
  change: CustomEvent<string>;
package/package.json CHANGED
@@ -1,38 +1,38 @@
1
1
  {
2
2
  "name": "@gradio/code",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "description": "Gradio UI packages",
5
5
  "type": "module",
6
6
  "author": "",
7
7
  "license": "ISC",
8
8
  "private": false,
9
9
  "dependencies": {
10
- "@codemirror/autocomplete": "^6.3.0",
11
- "@codemirror/commands": "^6.1.2",
12
- "@codemirror/lang-css": "^6.1.0",
13
- "@codemirror/lang-html": "^6.4.2",
14
- "@codemirror/lang-javascript": "^6.1.4",
10
+ "@codemirror/autocomplete": "^6.18.6",
11
+ "@codemirror/commands": "^6.8.0",
12
+ "@codemirror/lang-css": "^6.3.1",
13
+ "@codemirror/lang-html": "^6.4.9",
14
+ "@codemirror/lang-javascript": "^6.2.3",
15
15
  "@codemirror/lang-json": "^6.0.1",
16
- "@codemirror/lang-markdown": "^6.1.0",
17
- "@codemirror/lang-python": "^6.0.4",
18
- "@codemirror/language": "^6.6.0",
19
- "@codemirror/legacy-modes": "^6.3.1",
20
- "@codemirror/lint": "^6.0.0",
21
- "@codemirror/search": "^6.2.2",
22
- "@codemirror/state": "^6.1.2",
23
- "@codemirror/view": "^6.4.1",
24
- "@lezer/common": "^1.0.2",
25
- "@lezer/highlight": "^1.1.3",
26
- "@lezer/markdown": "^1.0.2",
16
+ "@codemirror/lang-markdown": "^6.3.2",
17
+ "@codemirror/lang-python": "^6.1.7",
18
+ "@codemirror/language": "^6.10.8",
19
+ "@codemirror/legacy-modes": "^6.4.3",
20
+ "@codemirror/lint": "^6.8.4",
21
+ "@codemirror/search": "^6.5.10",
22
+ "@codemirror/state": "^6.5.2",
23
+ "@codemirror/view": "^6.36.3",
24
+ "@lezer/common": "^1.2.3",
25
+ "@lezer/highlight": "^1.2.1",
26
+ "@lezer/markdown": "^1.4.2",
27
27
  "cm6-theme-basic-dark": "^0.2.0",
28
28
  "cm6-theme-basic-light": "^0.2.0",
29
29
  "codemirror": "^6.0.1",
30
- "@gradio/atoms": "^0.13.3",
31
- "@gradio/upload": "^0.15.3",
32
- "@gradio/statustracker": "^0.10.4",
30
+ "@gradio/atoms": "^0.14.0",
31
+ "@gradio/upload": "^0.15.5",
33
32
  "@gradio/icons": "^0.10.0",
34
33
  "@gradio/utils": "^0.10.1",
35
- "@gradio/wasm": "^0.17.3"
34
+ "@gradio/wasm": "^0.17.4",
35
+ "@gradio/statustracker": "^0.10.5"
36
36
  },
37
37
  "main_changeset": true,
38
38
  "main": "./Index.svelte",
@@ -9,6 +9,7 @@
9
9
  } from "@codemirror/view";
10
10
  import { StateEffect, EditorState, type Extension } from "@codemirror/state";
11
11
  import { indentWithTab } from "@codemirror/commands";
12
+ import { autocompletion, acceptCompletion } from "@codemirror/autocomplete";
12
13
 
13
14
  import { basicDark } from "cm6-theme-basic-dark";
14
15
  import { basicLight } from "cm6-theme-basic-light";
@@ -28,6 +29,7 @@
28
29
  export let placeholder: string | HTMLElement | null | undefined = undefined;
29
30
  export let wrap_lines = false;
30
31
  export let show_line_numbers = true;
32
+ export let autocomplete = false;
31
33
 
32
34
  const dispatch = createEventDispatcher<{
33
35
  change: string;
@@ -175,6 +177,19 @@
175
177
  }
176
178
  });
177
179
 
180
+ const AutocompleteTheme = EditorView.theme({
181
+ ".cm-tooltip-autocomplete": {
182
+ "& > ul": {
183
+ backgroundColor: "var(--background-fill-primary)",
184
+ color: "var(--body-text-color)"
185
+ },
186
+ "& > ul > li[aria-selected]": {
187
+ backgroundColor: "var(--color-accent-soft)",
188
+ color: "var(--body-text-color)"
189
+ }
190
+ }
191
+ });
192
+
178
193
  function create_editor_state(_value: string | null | undefined): EditorState {
179
194
  return EditorState.create({
180
195
  doc: _value ?? undefined,
@@ -200,7 +215,9 @@
200
215
  extensions.push(basicSetup);
201
216
  }
202
217
  if (use_tab) {
203
- extensions.push(keymap.of([indentWithTab]));
218
+ extensions.push(
219
+ keymap.of([{ key: "Tab", run: acceptCompletion }, indentWithTab])
220
+ );
204
221
  }
205
222
  if (placeholder) {
206
223
  extensions.push(placeholderExt(placeholder));
@@ -208,10 +225,13 @@
208
225
  if (lang) {
209
226
  extensions.push(lang);
210
227
  }
211
-
212
228
  if (show_line_numbers) {
213
229
  extensions.push(lineNumbers());
214
230
  }
231
+ if (autocomplete) {
232
+ extensions.push(autocompletion());
233
+ extensions.push(AutocompleteTheme);
234
+ }
215
235
 
216
236
  extensions.push(EditorView.updateListener.of(handle_change));
217
237
  if (wrap_lines) {