11import { Widget } from '@lumino/widgets' ;
22
3- import { Signal , ISignal } from '@lumino/signaling' ;
4-
53import { PromiseDelegate } from '@lumino/coreutils' ;
64
75/*
@@ -15,6 +13,8 @@ import './drawio/css/common.css';
1513
1614import './drawio/styles/grapheditor.css' ;
1715
16+ import { DrawIODocumentModel } from './model' ;
17+
1818import { grapheditorTxt , defaultXml } from './pack' ;
1919
2020const w = window as any ;
@@ -42,17 +42,19 @@ export class DrawIOWidget extends Widget {
4242 *
4343 * @param info - The `DashboardView` metadata.
4444 */
45- constructor ( ) {
45+ constructor ( model : DrawIODocumentModel ) {
4646 super ( ) ;
47- void Private . ensureMx ( ) . then ( mx => this . _loadDrawIO ( mx ) ) ;
48- //this._loadDrawIO(MX);
47+ this . _model = model ;
48+ Private . ensureMx ( ) . then ( mx => {
49+ this . _loadDrawIO ( mx ) ;
50+ this . _model . sharedModel . changed . connect ( this . _onContentChanged , this ) ;
51+ } ) ;
4952 }
5053
5154 /**
5255 * Dispose of the resources held by the widget.
5356 */
5457 dispose ( ) : void {
55- Signal . clearData ( this ) ;
5658 this . _editor . destroy ( ) ;
5759 super . dispose ( ) ;
5860 }
@@ -64,10 +66,6 @@ export class DrawIOWidget extends Widget {
6466 return this . _ready ;
6567 }
6668
67- get graphChanged ( ) : ISignal < this, string > {
68- return this . _graphChanged ;
69- }
70-
7169 get mx ( ) : any {
7270 return this . _mx ;
7371 }
@@ -88,21 +86,6 @@ export class DrawIOWidget extends Widget {
8886 return this . _editor . actions . actions ;
8987 }
9088
91- setContent ( newValue : string ) : void {
92- if ( this . _editor === undefined ) {
93- return ;
94- }
95-
96- const oldValue = this . _mx . mxUtils . getXml ( this . _editor . editor . getGraphXml ( ) ) ;
97-
98- if ( oldValue !== newValue && ! this . _editor . editor . graph . isEditing ( ) ) {
99- if ( newValue . length ) {
100- const xml = this . _mx . mxUtils . parseXml ( newValue ) ;
101- this . _editor . editor . setGraphXml ( xml . documentElement ) ;
102- }
103- }
104- }
105-
10689 //Direction
10790 public toggleCellStyles ( flip : string ) : void {
10891 let styleFlip = this . _editor . mx . mxConstants . STYLE_FLIPH ;
@@ -369,6 +352,22 @@ export class DrawIOWidget extends Widget {
369352 } , true ) ;
370353 }
371354
355+ private _onContentChanged ( ) : void {
356+ const newValue = this . _model . sharedModel . getSource ( ) ;
357+ if ( this . _editor === undefined ) {
358+ return ;
359+ }
360+
361+ const oldValue = this . _mx . mxUtils . getXml ( this . _editor . editor . getGraphXml ( ) ) ;
362+
363+ if ( oldValue !== newValue && ! this . _editor . editor . graph . isEditing ( ) ) {
364+ if ( newValue . length ) {
365+ const xml = this . _mx . mxUtils . parseXml ( newValue ) ;
366+ this . _editor . editor . setGraphXml ( xml . documentElement ) ;
367+ }
368+ }
369+ }
370+
372371 private _loadDrawIO ( mx : Private . MX ) : void {
373372 this . _mx = mx ;
374373
@@ -389,9 +388,12 @@ export class DrawIOWidget extends Widget {
389388 this . _editor = new this . _mx . EditorUi ( new Editor ( false , themes ) , this . node ) ;
390389 this . _editor . refresh ( ) ;
391390
391+ //console.debug(this._mx.Editor);
392+ //console.debug(this._editor.editor.graph.model);
392393 this . _editor . editor . graph . model . addListener (
393394 this . _mx . mxEvent . NOTIFY ,
394395 ( sender : any , evt : any ) => {
396+ //console.debug("Event:", evt);
395397 const changes : any [ ] = evt . properties . changes ;
396398 for ( let i = 0 ; i < changes . length ; i ++ ) {
397399 if ( changes [ i ] . root ) {
@@ -405,10 +407,29 @@ export class DrawIOWidget extends Widget {
405407
406408 const graph = this . _editor . editor . getGraphXml ( ) ;
407409 const xml = this . _mx . mxUtils . getXml ( graph ) ;
408- this . _graphChanged . emit ( xml ) ;
410+ this . _model . sharedModel . setSource ( xml ) ;
409411 }
410412 ) ;
411413
414+ /* this._editor.editor.graph.model.addListener(
415+ this._mx.mxEvent.NOTIFY,
416+ (sender: any, evt: any) => {
417+ var changes = evt.getProperty('edit').changes;
418+
419+ for (var i = 0; i < changes.length; i++)
420+ {
421+ var change = changes[i];
422+
423+ if (
424+ change instanceof this._mx.mxChildChange &&
425+ change.change.previous == null
426+ ) {
427+ this._editor.editor.graph.startEditingAtCell(change.child);
428+ break;
429+ }
430+ }
431+ }); */
432+
412433 this . _promptSpacing = this . _mx . mxUtils . bind (
413434 this ,
414435 ( defaultValue : any , fn : any ) => {
@@ -426,15 +447,18 @@ export class DrawIOWidget extends Widget {
426447 dlg . init ( ) ;
427448 }
428449 ) ;
429-
450+
451+ const data = this . _model . sharedModel . getSource ( ) ;
452+ const xml = this . _mx . mxUtils . parseXml ( data ) ;
453+ this . _editor . editor . setGraphXml ( xml . documentElement ) ;
430454 this . _ready . resolve ( void 0 ) ;
431455 }
432456
433457 private _editor : any ;
434458 private _mx : Private . MX ;
435459 private _promptSpacing : any ;
460+ private _model : DrawIODocumentModel ;
436461 private _ready = new PromiseDelegate < void > ( ) ;
437- private _graphChanged = new Signal < this, string > ( this ) ;
438462}
439463
440464/**
0 commit comments