File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed
vue-components/src/components Expand file tree Collapse file tree 2 files changed +24
-5
lines changed 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__ = [
@@ -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" ,
Original file line number Diff line number Diff 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 ( ) {
You can’t perform that action at this time.
0 commit comments