lexgui 0.6.6 → 0.6.7

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.
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  const LX = {
10
- version: "0.6.6",
10
+ version: "0.6.7",
11
11
  ready: false,
12
12
  components: [], // Specific pre-build components
13
13
  signals: {}, // Events and triggers
@@ -870,7 +870,7 @@ class Sheet {
870
870
  this.root.dataset["side"] = this.side;
871
871
  this.root.tabIndex = "1";
872
872
  this.root.role = "dialog";
873
- this.root.className = "lexsheet fixed z-100 bg-primary";
873
+ this.root.className = "lexsheet fixed z-1000 bg-primary";
874
874
  LX.root.appendChild( this.root );
875
875
 
876
876
  this.root.addEventListener( "keydown", (e) => {
@@ -2205,6 +2205,11 @@ class Tabs {
2205
2205
 
2206
2206
  delete( name ) {
2207
2207
 
2208
+ if( this.selected == name )
2209
+ {
2210
+ this.selected = null;
2211
+ }
2212
+
2208
2213
  const tabEl = this.tabDOMs[ name ];
2209
2214
 
2210
2215
  if( !tabEl || tabEl.fixed )
@@ -7402,11 +7407,6 @@ function ADD_CUSTOM_WIDGET( customWidgetName, options = {} )
7402
7407
 
7403
7408
  const refresh_widget = () => {
7404
7409
 
7405
- if( instance )
7406
- {
7407
- widget.instance = instance = Object.assign( LX.deepCopy(defaultInstance), instance );
7408
- }
7409
-
7410
7410
  if( container ) container.remove();
7411
7411
  if( customWidgetsDom ) customWidgetsDom.remove();
7412
7412
 
@@ -7471,13 +7471,36 @@ function ADD_CUSTOM_WIDGET( customWidgetName, options = {} )
7471
7471
  this.queue( customWidgetsDom );
7472
7472
 
7473
7473
  const on_instance_changed = ( key, value, event ) => {
7474
- instance[ key ] = value;
7474
+ const setter = options[ `_set_${ key }` ];
7475
+ if( setter )
7476
+ {
7477
+ setter.call( instance, value );
7478
+ }
7479
+ else
7480
+ {
7481
+ instance[ key ] = value;
7482
+ }
7475
7483
  widget._trigger( new LX.IEvent( name, instance, event ), callback );
7476
7484
  };
7477
7485
 
7478
7486
  for( let key in defaultInstance )
7479
7487
  {
7480
- const value = instance[ key ] ?? defaultInstance[ key ];
7488
+ let value = null;
7489
+
7490
+ const getter = options[ `_get_${ key }` ];
7491
+ if( getter )
7492
+ {
7493
+ value = instance[ key ] ? getter.call( instance ) : getter.call( defaultInstance );
7494
+ }
7495
+ else
7496
+ {
7497
+ value = instance[ key ] ?? defaultInstance[ key ];
7498
+ }
7499
+
7500
+ if( !value )
7501
+ {
7502
+ continue;
7503
+ }
7481
7504
 
7482
7505
  switch( value.constructor )
7483
7506
  {
@@ -7507,6 +7530,9 @@ function ADD_CUSTOM_WIDGET( customWidgetName, options = {} )
7507
7530
  this._addVector( value.length, key, value, on_instance_changed.bind( this, key ) );
7508
7531
  }
7509
7532
  break;
7533
+ default:
7534
+ console.warn( `Unsupported property type: ${ value.constructor.name }` );
7535
+ break;
7510
7536
  }
7511
7537
  }
7512
7538
 
@@ -8444,6 +8470,27 @@ class Button extends Widget {
8444
8470
  wValue.innerHTML = `<span>${ ( value || "" ) }</span>`;
8445
8471
  }
8446
8472
 
8473
+ if( options.fileInput )
8474
+ {
8475
+ const fileInput = document.createElement( "input" );
8476
+ fileInput.type = "file";
8477
+ fileInput.className = "file-input";
8478
+ fileInput.style.display = "none";
8479
+ wValue.appendChild( fileInput );
8480
+
8481
+ fileInput.addEventListener( 'change', function( e ) {
8482
+ const files = e.target.files;
8483
+ if( !files.length ) return;
8484
+
8485
+ const reader = new FileReader();
8486
+ if( options.fileInputType === 'text' ) reader.readAsText( files[ 0 ] );
8487
+ else if( options.fileInputType === 'buffer' ) reader.readAsArrayBuffer( files[ 0 ] );
8488
+ else if( options.fileInputType === 'bin' ) reader.readAsBinaryString( files[ 0 ] );
8489
+ else if( options.fileInputType === 'url' ) reader.readAsDataURL( files[ 0 ] );
8490
+ reader.onload = e => { callback.call( this, e.target.result, files[ 0 ] ); } ;
8491
+ });
8492
+ }
8493
+
8447
8494
  if( options.disabled )
8448
8495
  {
8449
8496
  this.disabled = true;
@@ -8496,8 +8543,15 @@ class Button extends Widget {
8496
8543
  wValue.classList.toggle('selected');
8497
8544
  }
8498
8545
 
8499
- const swapInput = wValue.querySelector( "input" );
8500
- this._trigger( new LX.IEvent( name, swapInput?.checked ?? value, e ), callback );
8546
+ if( options.fileInput )
8547
+ {
8548
+ wValue.querySelector( ".file-input" ).click();
8549
+ }
8550
+ else
8551
+ {
8552
+ const swapInput = wValue.querySelector( "input" );
8553
+ this._trigger( new LX.IEvent( name, swapInput?.checked ?? value, e ), callback );
8554
+ }
8501
8555
  });
8502
8556
 
8503
8557
  if( options.tooltip )
@@ -12833,6 +12887,8 @@ class Panel {
12833
12887
  * hideName: Don't use name as label [false]
12834
12888
  * disabled: Make the widget disabled [false]
12835
12889
  * icon: Icon class to show as button value
12890
+ * fileInput: Button click requests a file
12891
+ * fileInputType: Type of the requested file
12836
12892
  * img: Path to image to show as button value
12837
12893
  * title: Text to show in native Element title
12838
12894
  * buttonClass: Class to add to the native button element
@@ -14173,6 +14229,13 @@ class Sidebar {
14173
14229
  info.appendChild( infoSubtext );
14174
14230
  }
14175
14231
 
14232
+ // Add icon if onHeaderPressed is defined and not collapsable (it uses the toggler icon)
14233
+ if( options.onHeaderPressed && !this.collapsable )
14234
+ {
14235
+ const icon = LX.makeIcon( "MenuArrows" );
14236
+ header.appendChild( icon );
14237
+ }
14238
+
14176
14239
  return header;
14177
14240
  }
14178
14241
 
@@ -14218,8 +14281,13 @@ class Sidebar {
14218
14281
  info.appendChild( infoSubtext );
14219
14282
  }
14220
14283
 
14221
- const icon = LX.makeIcon( "MenuArrows" );
14222
- footer.appendChild( icon );
14284
+ // Add icon if onFooterPressed is defined
14285
+ // Useful to indicate that the footer is clickable
14286
+ if( options.onFooterPressed )
14287
+ {
14288
+ const icon = LX.makeIcon( "MenuArrows" );
14289
+ footer.appendChild( icon );
14290
+ }
14223
14291
 
14224
14292
  return footer;
14225
14293
  }