File tree Expand file tree Collapse file tree 3 files changed +26
-7
lines changed
vue-components/src/components Expand file tree Collapse file tree 3 files changed +26
-7
lines changed Original file line number Diff line number Diff line change 88# Trame setup
99# -----------------------------------------------------------------------------
1010
11- server = get_server ()
11+ server = get_server (client_type = "vue2" )
1212state , ctrl = server .state , server .controller
1313
1414
Original file line number Diff line number Diff line change 11"""Module compatible with vue2 and vue3. To use it, you need to install **trame-code**"""
2+
23from trame_client .widgets .core import AbstractElement
4+
35from .. import module
46
57__all__ = [
@@ -23,6 +25,7 @@ class Editor(HtmlElement):
2325
2426 :param options:
2527 :param value:
28+ :param model_value:
2629 :param theme:
2730 :param language:
2831 :param textmate:
@@ -41,6 +44,7 @@ def __init__(self, **kwargs):
4144 self ._attr_names += [
4245 "options" ,
4346 "value" ,
47+ ("model_value" , "modelValue" ),
4448 "theme" ,
4549 "language" ,
4650 "textmate" ,
Original file line number Diff line number Diff line change @@ -9,9 +9,11 @@ import * as monaco from "monaco-editor";
99export default {
1010 name : "VSEditor" ,
1111 props : {
12+ modelValue : {
13+ type : String ,
14+ } ,
1215 value : {
1316 type : String ,
14- default : "" ,
1517 } ,
1618 options : {
1719 type : Object ,
@@ -34,8 +36,13 @@ export default {
3436 } ,
3537 } ,
3638 watch : {
39+ modelValue ( v ) {
40+ if ( this . editor && v !== undefined && this . editor . getValue ( ) !== v ) {
41+ this . editor . setValue ( v ) ;
42+ }
43+ } ,
3744 value ( v ) {
38- if ( this . editor ) {
45+ if ( this . editor && v !== undefined && this . editor . getValue ( ) !== v ) {
3946 this . editor . setValue ( v ) ;
4047 }
4148 } ,
@@ -102,7 +109,7 @@ export default {
102109 }
103110
104111 this . editor = monaco . editor . create ( this . $el , {
105- value : this . value ,
112+ value : this . modelValue || this . value ,
106113 language : this . language ,
107114 theme : this . theme ,
108115 ...this . options ,
@@ -112,9 +119,17 @@ export default {
112119 provider . injectCSS ( ) ;
113120 }
114121
115- this . editor . onDidChangeModelContent ( ( ) =>
116- this . $emit ( "input" , this . editor . getValue ( ) )
117- ) ;
122+ this . lastValue = this . editor . getValue ( ) ;
123+
124+ this . editor . onDidChangeModelContent ( ( ) => {
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 ) ;
132+ } ) ;
118133 } ,
119134 beforeUnmount ( ) {
120135 this . editor . dispose ( ) ;
You can’t perform that action at this time.
0 commit comments