@gradio/code 0.3.8 → 0.5.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 +17 -1
- package/Example.svelte +2 -2
- package/README.md +2 -5
- package/package.json +6 -6
- package/shared/Code.svelte +33 -36
- package/shared/language.ts +33 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# @gradio/code
|
2
2
|
|
3
|
+
## 0.5.0
|
4
|
+
|
5
|
+
### Features
|
6
|
+
|
7
|
+
- [#7328](https://github.com/gradio-app/gradio/pull/7328) [`c1a7ea7`](https://github.com/gradio-app/gradio/commit/c1a7ea7c0c294aa970624f02225717c12bcf9b58) - Add SQL Support for gr.Code. Thanks [@aersam](https://github.com/aersam)!
|
8
|
+
|
9
|
+
## 0.4.0
|
10
|
+
|
11
|
+
### Features
|
12
|
+
|
13
|
+
- [#7240](https://github.com/gradio-app/gradio/pull/7240) [`1893756`](https://github.com/gradio-app/gradio/commit/18937564ab8906710549d5bccc48f7188c836f38) - Small cleanups of `Code` component. Thanks [@abidlabs](https://github.com/abidlabs)!
|
14
|
+
|
15
|
+
### Fixes
|
16
|
+
|
17
|
+
- [#7192](https://github.com/gradio-app/gradio/pull/7192) [`8dd6f4b`](https://github.com/gradio-app/gradio/commit/8dd6f4bc1901792f05cd59e86df7b1dbab692739) - Handle the case where examples is `null` for all components. Thanks [@abidlabs](https://github.com/abidlabs)!
|
18
|
+
|
3
19
|
## 0.3.8
|
4
20
|
|
5
21
|
### Patch Changes
|
@@ -265,4 +281,4 @@ Thanks [@pngwn](https://github.com/pngwn)!
|
|
265
281
|
|
266
282
|
- Updated dependencies []:
|
267
283
|
- @gradio/atoms@0.0.2
|
268
|
-
- @gradio/upload@0.0.2
|
284
|
+
- @gradio/upload@0.0.2
|
package/Example.svelte
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
<script lang="ts">
|
2
|
-
export let value: string;
|
2
|
+
export let value: string | null;
|
3
3
|
export let type: "gallery" | "table";
|
4
4
|
export let selected = false;
|
5
5
|
</script>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<pre
|
8
8
|
class:table={type === "table"}
|
9
9
|
class:gallery={type === "gallery"}
|
10
|
-
class:selected>{value}</pre>
|
10
|
+
class:selected>{value ? value : ""}</pre>
|
11
11
|
|
12
12
|
<style>
|
13
13
|
pre {
|
package/README.md
CHANGED
@@ -8,17 +8,14 @@
|
|
8
8
|
|
9
9
|
BaseCode
|
10
10
|
```javascript
|
11
|
-
export let
|
11
|
+
export let class_names = "";
|
12
12
|
export let value = "";
|
13
13
|
export let dark_mode: boolean;
|
14
|
-
|
15
14
|
export let basic = true;
|
16
15
|
export let language: string;
|
17
16
|
export let lines = 5;
|
18
17
|
export let extensions: Extension[] = [];
|
19
|
-
|
20
|
-
export let useTab = true;
|
21
|
-
|
18
|
+
export let use_tab = true;
|
22
19
|
export let readonly = false;
|
23
20
|
export let placeholder: string | HTMLElement | null | undefined = undefined;
|
24
21
|
```
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gradio/code",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.5.0",
|
4
4
|
"description": "Gradio UI packages",
|
5
5
|
"type": "module",
|
6
6
|
"author": "",
|
@@ -28,11 +28,11 @@
|
|
28
28
|
"cm6-theme-basic-light": "^0.2.0",
|
29
29
|
"codemirror": "^6.0.1",
|
30
30
|
"@gradio/icons": "^0.3.2",
|
31
|
-
"@gradio/upload": "^0.7.
|
32
|
-
"@gradio/
|
33
|
-
"@gradio/
|
34
|
-
"@gradio/
|
35
|
-
"@gradio/
|
31
|
+
"@gradio/upload": "^0.7.2",
|
32
|
+
"@gradio/statustracker": "^0.4.5",
|
33
|
+
"@gradio/wasm": "^0.6.0",
|
34
|
+
"@gradio/atoms": "^0.5.1",
|
35
|
+
"@gradio/utils": "^0.2.2"
|
36
36
|
},
|
37
37
|
"main_changeset": true,
|
38
38
|
"main": "./Index.svelte",
|
package/shared/Code.svelte
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
<script lang="ts">
|
2
|
-
import type { ViewUpdate } from "@codemirror/view";
|
3
2
|
import { createEventDispatcher, onMount } from "svelte";
|
4
3
|
import {
|
5
4
|
EditorView,
|
5
|
+
ViewUpdate,
|
6
6
|
keymap,
|
7
7
|
placeholder as placeholderExt
|
8
8
|
} from "@codemirror/view";
|
@@ -14,17 +14,14 @@
|
|
14
14
|
import { basicSetup } from "./extensions";
|
15
15
|
import { getLanguageExtension } from "./language";
|
16
16
|
|
17
|
-
export let
|
17
|
+
export let class_names = "";
|
18
18
|
export let value = "";
|
19
19
|
export let dark_mode: boolean;
|
20
|
-
|
21
20
|
export let basic = true;
|
22
21
|
export let language: string;
|
23
22
|
export let lines = 5;
|
24
23
|
export let extensions: Extension[] = [];
|
25
|
-
|
26
|
-
export let useTab = true;
|
27
|
-
|
24
|
+
export let use_tab = true;
|
28
25
|
export let readonly = false;
|
29
26
|
export let placeholder: string | HTMLElement | null | undefined = undefined;
|
30
27
|
|
@@ -45,42 +42,42 @@
|
|
45
42
|
}
|
46
43
|
|
47
44
|
$: reconfigure(), lang_extension;
|
48
|
-
$:
|
49
|
-
$:
|
45
|
+
$: set_doc(value);
|
46
|
+
$: update_lines();
|
50
47
|
|
51
|
-
function
|
52
|
-
if (view &&
|
48
|
+
function set_doc(new_doc: string): void {
|
49
|
+
if (view && new_doc !== view.state.doc.toString()) {
|
53
50
|
view.dispatch({
|
54
51
|
changes: {
|
55
52
|
from: 0,
|
56
53
|
to: view.state.doc.length,
|
57
|
-
insert:
|
54
|
+
insert: new_doc
|
58
55
|
}
|
59
56
|
});
|
60
57
|
}
|
61
58
|
}
|
62
59
|
|
63
|
-
function
|
60
|
+
function update_lines(): void {
|
64
61
|
if (view) {
|
65
|
-
view.requestMeasure({ read:
|
62
|
+
view.requestMeasure({ read: update_gutters });
|
66
63
|
}
|
67
64
|
}
|
68
65
|
|
69
|
-
function
|
66
|
+
function create_editor_view(): EditorView {
|
70
67
|
const editorView = new EditorView({
|
71
68
|
parent: element,
|
72
|
-
state:
|
69
|
+
state: create_editor_state(value)
|
73
70
|
});
|
74
|
-
editorView.dom.addEventListener("focus",
|
75
|
-
editorView.dom.addEventListener("blur",
|
71
|
+
editorView.dom.addEventListener("focus", handle_focus, true);
|
72
|
+
editorView.dom.addEventListener("blur", handle_blur, true);
|
76
73
|
return editorView;
|
77
74
|
}
|
78
75
|
|
79
|
-
function
|
76
|
+
function handle_focus(): void {
|
80
77
|
dispatch("focus");
|
81
78
|
}
|
82
79
|
|
83
|
-
function
|
80
|
+
function handle_blur(): void {
|
84
81
|
dispatch("blur");
|
85
82
|
}
|
86
83
|
|
@@ -99,7 +96,7 @@
|
|
99
96
|
return null;
|
100
97
|
}
|
101
98
|
|
102
|
-
function
|
99
|
+
function update_gutters(_view: EditorView): any {
|
103
100
|
let gutters = _view.dom.querySelectorAll<HTMLElement>(".cm-gutter");
|
104
101
|
let _lines = lines + 1;
|
105
102
|
let lineHeight = getGutterLineHeight(_view);
|
@@ -113,27 +110,27 @@
|
|
113
110
|
return null;
|
114
111
|
}
|
115
112
|
|
116
|
-
function
|
113
|
+
function handle_change(vu: ViewUpdate): void {
|
117
114
|
if (vu.docChanged) {
|
118
115
|
const doc = vu.state.doc;
|
119
116
|
const text = doc.toString();
|
120
117
|
value = text;
|
121
118
|
dispatch("change", text);
|
122
119
|
}
|
123
|
-
view.requestMeasure({ read:
|
120
|
+
view.requestMeasure({ read: update_gutters });
|
124
121
|
}
|
125
122
|
|
126
|
-
function
|
123
|
+
function get_extensions(): Extension[] {
|
127
124
|
const stateExtensions = [
|
128
|
-
...
|
125
|
+
...get_base_extensions(
|
129
126
|
basic,
|
130
|
-
|
127
|
+
use_tab,
|
131
128
|
placeholder,
|
132
129
|
readonly,
|
133
130
|
lang_extension
|
134
131
|
),
|
135
132
|
FontTheme,
|
136
|
-
...
|
133
|
+
...get_theme(),
|
137
134
|
...extensions
|
138
135
|
];
|
139
136
|
return stateExtensions;
|
@@ -168,16 +165,16 @@
|
|
168
165
|
}
|
169
166
|
});
|
170
167
|
|
171
|
-
function
|
168
|
+
function create_editor_state(_value: string | null | undefined): EditorState {
|
172
169
|
return EditorState.create({
|
173
170
|
doc: _value ?? undefined,
|
174
|
-
extensions:
|
171
|
+
extensions: get_extensions()
|
175
172
|
});
|
176
173
|
}
|
177
174
|
|
178
|
-
function
|
175
|
+
function get_base_extensions(
|
179
176
|
basic: boolean,
|
180
|
-
|
177
|
+
use_tab: boolean,
|
181
178
|
placeholder: string | HTMLElement | null | undefined,
|
182
179
|
readonly: boolean,
|
183
180
|
lang: Extension | null | undefined
|
@@ -191,7 +188,7 @@
|
|
191
188
|
if (basic) {
|
192
189
|
extensions.push(basicSetup);
|
193
190
|
}
|
194
|
-
if (
|
191
|
+
if (use_tab) {
|
195
192
|
extensions.push(keymap.of([indentWithTab]));
|
196
193
|
}
|
197
194
|
if (placeholder) {
|
@@ -201,11 +198,11 @@
|
|
201
198
|
extensions.push(lang);
|
202
199
|
}
|
203
200
|
|
204
|
-
extensions.push(EditorView.updateListener.of(
|
201
|
+
extensions.push(EditorView.updateListener.of(handle_change));
|
205
202
|
return extensions;
|
206
203
|
}
|
207
204
|
|
208
|
-
function
|
205
|
+
function get_theme(): Extension[] {
|
209
206
|
const extensions: Extension[] = [];
|
210
207
|
|
211
208
|
if (dark_mode) {
|
@@ -218,18 +215,18 @@
|
|
218
215
|
|
219
216
|
function reconfigure(): void {
|
220
217
|
view?.dispatch({
|
221
|
-
effects: StateEffect.reconfigure.of(
|
218
|
+
effects: StateEffect.reconfigure.of(get_extensions())
|
222
219
|
});
|
223
220
|
}
|
224
221
|
|
225
222
|
onMount(() => {
|
226
|
-
view =
|
223
|
+
view = create_editor_view();
|
227
224
|
return () => view?.destroy();
|
228
225
|
});
|
229
226
|
</script>
|
230
227
|
|
231
228
|
<div class="wrap">
|
232
|
-
<div class="codemirror-wrapper {
|
229
|
+
<div class="codemirror-wrapper {class_names}" bind:this={element} />
|
233
230
|
</div>
|
234
231
|
|
235
232
|
<style>
|
package/shared/language.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { Extension } from "@codemirror/state";
|
2
2
|
import { StreamLanguage } from "@codemirror/language";
|
3
|
+
import { sql } from "@codemirror/legacy-modes/mode/sql";
|
3
4
|
|
4
5
|
const possible_langs = [
|
5
6
|
"python",
|
@@ -12,9 +13,26 @@ const possible_langs = [
|
|
12
13
|
"yaml",
|
13
14
|
"dockerfile",
|
14
15
|
"shell",
|
15
|
-
"r"
|
16
|
+
"r",
|
17
|
+
"sql"
|
16
18
|
];
|
17
19
|
|
20
|
+
const sql_dialects = [
|
21
|
+
"standardSQL",
|
22
|
+
"msSQL",
|
23
|
+
"mySQL",
|
24
|
+
"mariaDB",
|
25
|
+
"sqlite",
|
26
|
+
"cassandra",
|
27
|
+
"plSQL",
|
28
|
+
"hive",
|
29
|
+
"pgSQL",
|
30
|
+
"gql",
|
31
|
+
"gpSQL",
|
32
|
+
"sparkSQL",
|
33
|
+
"esper"
|
34
|
+
] as const;
|
35
|
+
|
18
36
|
const lang_map: Record<string, (() => Promise<Extension>) | undefined> = {
|
19
37
|
python: () => import("@codemirror/lang-python").then((m) => m.python()),
|
20
38
|
markdown: async () => {
|
@@ -48,7 +66,20 @@ const lang_map: Record<string, (() => Promise<Extension>) | undefined> = {
|
|
48
66
|
r: () =>
|
49
67
|
import("@codemirror/legacy-modes/mode/r").then((m) =>
|
50
68
|
StreamLanguage.define(m.r)
|
51
|
-
)
|
69
|
+
),
|
70
|
+
sql: () =>
|
71
|
+
import("@codemirror/legacy-modes/mode/sql").then((m) =>
|
72
|
+
StreamLanguage.define(m.standardSQL)
|
73
|
+
),
|
74
|
+
...Object.fromEntries(
|
75
|
+
sql_dialects.map((dialect) => [
|
76
|
+
"sql-" + dialect,
|
77
|
+
() =>
|
78
|
+
import("@codemirror/legacy-modes/mode/sql").then((m) =>
|
79
|
+
StreamLanguage.define(m[dialect])
|
80
|
+
)
|
81
|
+
])
|
82
|
+
)
|
52
83
|
} as const;
|
53
84
|
|
54
85
|
const alias_map: Record<string, string> = {
|