Skip to content

Commit d9dc6f8

Browse files
committed
fix: bring back vue2 support
1 parent 9172e3b commit d9dc6f8

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

trame_code/widgets/code.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Module compatible with vue2 and vue3. To use it, you need to install **trame-code**"""
2+
23
from trame_client.widgets.core import AbstractElement
4+
35
from .. import module
46

57
__all__ = [
@@ -21,8 +23,9 @@ class Editor(HtmlElement):
2123
2224
Properties:
2325
24-
:param v_model:
2526
:param options:
27+
:param value:
28+
:param model_value:
2629
:param theme:
2730
:param language:
2831
:param textmate:
@@ -40,6 +43,8 @@ def __init__(self, **kwargs):
4043
)
4144
self._attr_names += [
4245
"options",
46+
"value",
47+
("model_value", "modelValue"),
4348
"theme",
4449
"language",
4550
"textmate",

vue-components/src/components/Editor.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export default {
1111
props: {
1212
modelValue: {
1313
type: String,
14-
default: "",
14+
},
15+
value: {
16+
type: String,
1517
},
1618
options: {
1719
type: Object,
@@ -35,7 +37,12 @@ export default {
3537
},
3638
watch: {
3739
modelValue(v) {
38-
if (this.editor && this.editor.getValue() !== v) {
40+
if (this.editor && v !== undefined && this.editor.getValue() !== v) {
41+
this.editor.setValue(v);
42+
}
43+
},
44+
value(v) {
45+
if (this.editor && v !== undefined && this.editor.getValue() !== v) {
3946
this.editor.setValue(v);
4047
}
4148
},
@@ -112,9 +119,16 @@ export default {
112119
provider.injectCSS();
113120
}
114121

122+
this.lastValue = this.editor.getValue();
123+
115124
this.editor.onDidChangeModelContent(() => {
116-
this.$emit("update:modelValue", this.editor.getValue());
117-
this.$emit("input", this.editor.getValue());
125+
const newValue = this.editor.getValue();
126+
if (this.lastValue === newValue) {
127+
return;
128+
}
129+
this.lastValue = newValue;
130+
this.$emit("update:modelValue", newValue);
131+
this.$emit("input", newValue);
118132
});
119133
},
120134
beforeUnmount() {

0 commit comments

Comments
 (0)