lexgui 0.6.7 → 0.6.8

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.
@@ -756,31 +756,43 @@ class CodeEditor {
756
756
  let idx = firstNonspaceIndex( this.code.lines[ ln ] );
757
757
 
758
758
  // We already are in the first non space index...
759
- if(idx == cursor.position) idx = 0;
759
+ if( idx == cursor.position ) idx = 0;
760
760
 
761
761
  const prestring = this.code.lines[ ln ].substring( 0, idx );
762
762
  let lastX = cursor.position;
763
763
 
764
764
  this.resetCursorPos( CodeEditor.CURSOR_LEFT, cursor );
765
- if(idx > 0)
765
+ if( idx > 0 )
766
+ {
766
767
  this.cursorToString( cursor, prestring );
767
- this.setScrollLeft( 0 );
768
+ }
769
+ else
770
+ {
771
+ // No spaces, start from char 0
772
+ idx = 0;
773
+ }
768
774
 
769
- // Merge cursors
775
+ this.setScrollLeft( 0 );
770
776
  this.mergeCursors( ln );
771
777
 
772
778
  if( e.shiftKey && !e.cancelShift )
773
779
  {
774
780
  // Get last selection range
775
781
  if( cursor.selection )
782
+ {
776
783
  lastX += cursor.selection.chars;
784
+ }
777
785
 
778
786
  if( !cursor.selection )
787
+ {
779
788
  this.startSelection( cursor );
789
+ }
780
790
 
781
791
  var string = this.code.lines[ ln ].substring( idx, lastX );
782
792
  if( cursor.selection.sameLine() )
793
+ {
783
794
  cursor.selection.selectInline( cursor, idx, cursor.line, this.measureString( string ) );
795
+ }
784
796
  else
785
797
  {
786
798
  this._processSelection( cursor, e );
@@ -1666,14 +1678,16 @@ class CodeEditor {
1666
1678
  }
1667
1679
 
1668
1680
  this._removeSecondaryCursors();
1669
- var cursor = this._getCurrentCursor( true );
1670
1681
 
1682
+ var cursor = this._getCurrentCursor( true );
1671
1683
  this.saveCursor( cursor, this.code.cursorState );
1672
-
1673
1684
  this.code = this.loadedTabs[ name ];
1674
1685
  this.restoreCursor( cursor, this.code.cursorState );
1675
1686
 
1676
1687
  this.endSelection();
1688
+
1689
+ this.hideAutoCompleteBox();
1690
+
1677
1691
  this._updateDataInfoPanel( "@tab-name", name );
1678
1692
 
1679
1693
  if( this.code.languageOverride )
@@ -2220,6 +2234,14 @@ class CodeEditor {
2220
2234
  return;
2221
2235
 
2222
2236
  const key = e.key ?? e.detail.key;
2237
+
2238
+ // Do not propagate "space to scroll" event
2239
+ if( key == ' ' )
2240
+ {
2241
+ e.preventDefault();
2242
+ e.stopPropagation();
2243
+ }
2244
+
2223
2245
  const target = e.detail.targetCursor;
2224
2246
 
2225
2247
  // Global keys
@@ -2359,7 +2381,9 @@ class CodeEditor {
2359
2381
 
2360
2382
  // keys with length > 1 are probably special keys
2361
2383
  if( key.length > 1 && this.specialKeys.indexOf( key ) == -1 )
2384
+ {
2362
2385
  return;
2386
+ }
2363
2387
 
2364
2388
  let lidx = cursor.line;
2365
2389
  this.code.lines[ lidx ] = this.code.lines[ lidx ] ?? "";
@@ -2545,11 +2569,11 @@ class CodeEditor {
2545
2569
 
2546
2570
  async _copyContent( cursor ) {
2547
2571
 
2548
- let text_to_copy = "";
2572
+ let textToCopy = "";
2549
2573
 
2550
2574
  if( !cursor.selection )
2551
2575
  {
2552
- text_to_copy = "\n" + this.code.lines[ cursor.line ];
2576
+ textToCopy = "\n" + this.code.lines[ cursor.line ];
2553
2577
  }
2554
2578
  else
2555
2579
  {
@@ -2569,27 +2593,30 @@ class CodeEditor {
2569
2593
  const num_chars = cursor.selection.chars + ( cursor.selection.toY - cursor.selection.fromY ) * separator.length;
2570
2594
  const text = code.substr( index, num_chars );
2571
2595
  const lines = text.split( separator );
2572
- text_to_copy = lines.join('\n');
2596
+ textToCopy = lines.join('\n');
2573
2597
  }
2574
2598
 
2575
- navigator.clipboard.writeText( text_to_copy ).then(() => console.log("Successfully copied"), (err) => console.error("Error"));
2599
+ navigator.clipboard.writeText( textToCopy );
2600
+ // .then(() => console.log("Successfully copied"), (err) => console.error("Error"));
2576
2601
  }
2577
2602
 
2578
2603
  async _cutContent( cursor ) {
2579
2604
 
2580
2605
  let lidx = cursor.line;
2581
- let text_to_cut = "";
2606
+ let textToCut = "";
2582
2607
 
2583
2608
  this._addUndoStep( cursor, true );
2584
2609
 
2585
2610
  if( !cursor.selection )
2586
2611
  {
2587
- text_to_cut = "\n" + this.code.lines[ cursor.line ];
2612
+ textToCut = "\n" + this.code.lines[ cursor.line ];
2588
2613
  this.code.lines.splice( lidx, 1 );
2589
2614
  this.processLines();
2590
2615
  this.resetCursorPos( CodeEditor.CURSOR_LEFT, cursor );
2591
2616
  if( this.code.lines[ lidx ] == undefined )
2617
+ {
2592
2618
  this.lineUp( cursor );
2619
+ }
2593
2620
  }
2594
2621
  else
2595
2622
  {
@@ -2597,24 +2624,27 @@ class CodeEditor {
2597
2624
  if( cursor.selection ) cursor.selection.invertIfNecessary();
2598
2625
 
2599
2626
  const separator = "_NEWLINE_";
2600
- let code = this.code.lines.join(separator);
2627
+ let code = this.code.lines.join( separator );
2601
2628
 
2602
2629
  // Get linear start index
2603
2630
  let index = 0;
2604
2631
 
2605
- for(let i = 0; i <= cursor.selection.fromY; i++)
2632
+ for( let i = 0; i <= cursor.selection.fromY; i++ )
2633
+ {
2606
2634
  index += (i == cursor.selection.fromY ? cursor.selection.fromX : this.code.lines[ i ].length);
2635
+ }
2607
2636
 
2608
2637
  index += cursor.selection.fromY * separator.length;
2609
- const num_chars = cursor.selection.chars + (cursor.selection.toY - cursor.selection.fromY) * separator.length;
2610
- const text = code.substr(index, num_chars);
2611
- const lines = text.split(separator);
2612
- text_to_cut = lines.join('\n');
2638
+ const numChars = cursor.selection.chars + (cursor.selection.toY - cursor.selection.fromY) * separator.length;
2639
+ const text = code.substr( index, numChars );
2640
+ const lines = text.split( separator );
2641
+ textToCut = lines.join('\n');
2613
2642
 
2614
2643
  this.deleteSelection( cursor );
2615
2644
  }
2616
2645
 
2617
- navigator.clipboard.writeText( text_to_cut ).then(() => console.log("Successfully cut"), (err) => console.error("Error"));
2646
+ navigator.clipboard.writeText( textToCut );
2647
+ // .then(() => console.log("Successfully cut"), (err) => console.error("Error"));
2618
2648
  }
2619
2649
 
2620
2650
  _duplicateLine( lidx, cursor ) {
package/build/lexgui.css CHANGED
@@ -3835,10 +3835,9 @@ meter:-moz-meter-sub-sub-optimum::-moz-meter-bar {
3835
3835
  .lexwidget:has(.lextogglesubmenu),
3836
3836
  .lexwidget:has(.lexcustomcontainer) {
3837
3837
  border-radius: 6px;
3838
- display: grid;
3839
- grid-template-columns: repeat(2, 1fr);
3840
- grid-template-rows: auto auto;
3841
3838
  transition: background-color 0.2s ease-out;
3839
+ display: flex;
3840
+ flex-wrap: wrap;
3842
3841
  }
3843
3842
 
3844
3843
  .lexwidget:has(.lexarrayitems)[data-opened=true],
package/build/lexgui.js CHANGED
@@ -14,7 +14,7 @@ console.warn( 'Script _build/lexgui.js_ is depracated and will be removed soon.
14
14
  */
15
15
 
16
16
  const LX = {
17
- version: "0.6.7",
17
+ version: "0.6.8",
18
18
  ready: false,
19
19
  components: [], // Specific pre-build components
20
20
  signals: {}, // Events and triggers
@@ -6432,16 +6432,15 @@ class Area {
6432
6432
  if( auto && type == "vertical" )
6433
6433
  {
6434
6434
  // Listen resize event on first area
6435
- const resizeObserver = new ResizeObserver( entries => {
6435
+ this._autoVerticalResizeObserver = new ResizeObserver( entries => {
6436
6436
  for ( const entry of entries )
6437
6437
  {
6438
6438
  const size = entry.target.getComputedSize();
6439
6439
  area2.root.style.height = "calc(100% - " + ( size.height ) + "px )";
6440
6440
  }
6441
- resizeObserver.disconnect();
6442
6441
  });
6443
6442
 
6444
- resizeObserver.observe( area1.root );
6443
+ this._autoVerticalResizeObserver.observe( area1.root );
6445
6444
  }
6446
6445
 
6447
6446
  // Being minimizable means it's also resizeable!
@@ -6963,6 +6962,12 @@ class Area {
6963
6962
  return;
6964
6963
  }
6965
6964
 
6965
+ // When manual resizing, we don't need the observer anymore
6966
+ if( this._autoVerticalResizeObserver )
6967
+ {
6968
+ this._autoVerticalResizeObserver.disconnect();
6969
+ }
6970
+
6966
6971
  const a1 = this.sections[ 0 ];
6967
6972
  var a1Root = a1.root;
6968
6973
 
@@ -7383,7 +7388,7 @@ function ADD_CUSTOM_WIDGET( customWidgetName, options = {} )
7383
7388
 
7384
7389
  LX.Panel.prototype[ 'add' + customWidgetName ] = function( name, instance, callback ) {
7385
7390
 
7386
- options.nameWidth = "100%";
7391
+ const userParams = Array.from( arguments ).slice( 3 );
7387
7392
 
7388
7393
  let widget = new Widget( Widget.CUSTOM, name, null, options );
7389
7394
  this._attachWidget( widget );
@@ -7405,6 +7410,11 @@ function ADD_CUSTOM_WIDGET( customWidgetName, options = {} )
7405
7410
  }
7406
7411
  };
7407
7412
 
7413
+ widget.onResize = ( rect ) => {
7414
+ const realNameWidth = ( widget.root.domName?.style.width ?? "0px" );
7415
+ container.style.width = `calc( 100% - ${ realNameWidth })`;
7416
+ };
7417
+
7408
7418
  const element = widget.root;
7409
7419
 
7410
7420
  let container, customWidgetsDom;
@@ -7543,6 +7553,11 @@ function ADD_CUSTOM_WIDGET( customWidgetName, options = {} )
7543
7553
  }
7544
7554
  }
7545
7555
 
7556
+ if( options.onCreate )
7557
+ {
7558
+ options.onCreate.call( this, this, ...userParams );
7559
+ }
7560
+
7546
7561
  this.clearQueue();
7547
7562
  }
7548
7563
  };
@@ -11574,16 +11589,16 @@ class Table extends Widget {
11574
11589
  container.className = "lextable";
11575
11590
  this.root.appendChild( container );
11576
11591
 
11577
- this.centered = options.centered ?? false;
11578
- if( this.centered === true )
11592
+ this._centered = options.centered ?? false;
11593
+ if( this._centered === true )
11579
11594
  {
11580
11595
  container.classList.add( "centered" );
11581
11596
  }
11582
11597
 
11598
+ this.activeCustomFilters = {};
11583
11599
  this.filter = options.filter ?? false;
11584
- this.toggleColumns = options.toggleColumns ?? false;
11585
11600
  this.customFilters = options.customFilters ?? false;
11586
- this.activeCustomFilters = {};
11601
+ this._toggleColumns = options.toggleColumns ?? false;
11587
11602
  this._currentFilter = options.filterValue;
11588
11603
 
11589
11604
  data.head = data.head ?? [];
@@ -11591,6 +11606,7 @@ class Table extends Widget {
11591
11606
  data.checkMap = { };
11592
11607
  data.colVisibilityMap = { };
11593
11608
  data.head.forEach( (col, index) => { data.colVisibilityMap[ index ] = true; });
11609
+ this.data = data;
11594
11610
 
11595
11611
  const compareFn = ( idx, order, a, b) => {
11596
11612
  if (a[idx] < b[idx]) return -order;
@@ -11604,7 +11620,7 @@ class Table extends Widget {
11604
11620
  };
11605
11621
 
11606
11622
  // Append header
11607
- if( this.filter || this.customFilters || this.toggleColumns )
11623
+ if( this.filter || this.customFilters || this._toggleColumns )
11608
11624
  {
11609
11625
  const headerContainer = LX.makeContainer( [ "100%", "auto" ], "flex flex-row" );
11610
11626
 
@@ -11716,7 +11732,7 @@ class Table extends Widget {
11716
11732
  this._resetCustomFiltersBtn.root.classList.add( "hidden" );
11717
11733
  }
11718
11734
 
11719
- if( this.toggleColumns )
11735
+ if( this._toggleColumns )
11720
11736
  {
11721
11737
  const icon = LX.makeIcon( "Settings2" );
11722
11738
  const toggleColumnsBtn = new LX.Button( "toggleColumnsBtn", icon.innerHTML + "View", (value, e) => {
@@ -11804,7 +11820,7 @@ class Table extends Widget {
11804
11820
  th.querySelector( "span" ).appendChild( LX.makeIcon( "MenuArrows", { svgClass: "sm" } ) );
11805
11821
 
11806
11822
  const idx = data.head.indexOf( headData );
11807
- if( this.centered && this.centered.indexOf( idx ) > -1 )
11823
+ if( this._centered?.indexOf && this._centered.indexOf( idx ) > -1 )
11808
11824
  {
11809
11825
  th.classList.add( "centered" );
11810
11826
  }
@@ -11814,7 +11830,7 @@ class Table extends Widget {
11814
11830
  { name: "Desc", icon: "ArrowDownAZ", callback: sortFn.bind( this, idx, -1 ) }
11815
11831
  ];
11816
11832
 
11817
- if( this.toggleColumns )
11833
+ if( this._toggleColumns )
11818
11834
  {
11819
11835
  menuOptions.push(
11820
11836
  null,
@@ -11876,6 +11892,9 @@ class Table extends Widget {
11876
11892
  // Origin row should go to the target row, and the rest should be moved up/down
11877
11893
  const fromIdx = rIdx - 1;
11878
11894
  const targetIdx = movePending[ 1 ] - 1;
11895
+
11896
+ LX.emit( "@on_table_sort", { instance: this, fromIdx, targetIdx } );
11897
+
11879
11898
  const b = data.body[ fromIdx ];
11880
11899
  let targetOffset = 0;
11881
11900
 
@@ -12081,7 +12100,7 @@ class Table extends Widget {
12081
12100
  td.innerHTML = `${ rowData }`;
12082
12101
 
12083
12102
  const idx = bodyData.indexOf( rowData );
12084
- if( this.centered && this.centered.indexOf( idx ) > -1 )
12103
+ if( this._centered?.indexOf && this._centered.indexOf( idx ) > -1 )
12085
12104
  {
12086
12105
  td.classList.add( "centered" );
12087
12106
  }
@@ -12171,8 +12190,50 @@ class Table extends Widget {
12171
12190
 
12172
12191
  LX.doAsync( this.onResize.bind( this ) );
12173
12192
  }
12193
+
12194
+ getSelectedRows() {
12195
+
12196
+ const selectedRows = [];
12197
+
12198
+ for( const row of this.data.body )
12199
+ {
12200
+ const rowId = LX.getSupportedDOMName( row.join( '-' ) ).substr( 0, 32 );
12201
+ if( this.data.checkMap[ rowId ] === true )
12202
+ {
12203
+ selectedRows.push( row );
12204
+ }
12205
+ }
12206
+
12207
+ return selectedRows;
12208
+ }
12209
+
12210
+ _setCentered( v ) {
12211
+
12212
+ if( v.constructor == Boolean )
12213
+ {
12214
+ const container = this.root.querySelector( ".lextable" );
12215
+ container.classList.toggle( "centered", v );
12216
+ }
12217
+ else
12218
+ {
12219
+ // Make sure this is an array containing which columns have
12220
+ // to be centered
12221
+ v = [].concat( v );
12222
+ }
12223
+
12224
+ this._centered = v;
12225
+
12226
+ this.refresh();
12227
+ }
12174
12228
  }
12175
12229
 
12230
+ Object.defineProperty( Table.prototype, "centered", {
12231
+ get: function() { return this._centered; },
12232
+ set: function( v ) { this._setCentered( v ); },
12233
+ enumerable: true,
12234
+ configurable: true
12235
+ });
12236
+
12176
12237
  LX.Table = Table;
12177
12238
 
12178
12239
  /**