lexgui 0.7.7 → 0.7.9

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.7.7",
10
+ version: "0.7.9",
11
11
  ready: false,
12
12
  extensions: [], // Store extensions used
13
13
  signals: {}, // Events and triggers
@@ -1239,7 +1239,7 @@ class DropdownMenu {
1239
1239
  }
1240
1240
 
1241
1241
  const menuItem = document.createElement('div');
1242
- menuItem.className = "lexdropdownmenuitem" + ( item.name ? "" : " label" ) + ( item.disabled ?? false ? " disabled" : "" ) + ( ` ${ item.className ?? "" }` );
1242
+ menuItem.className = "lexdropdownmenuitem" + ( ( item.name || item.options ) ? "" : " label" ) + ( item.disabled ?? false ? " disabled" : "" ) + ( ` ${ item.className ?? "" }` );
1243
1243
  menuItem.dataset["id"] = pKey;
1244
1244
  menuItem.innerHTML = `<span>${ key }</span>`;
1245
1245
  menuItem.tabIndex = "1";
@@ -1325,19 +1325,23 @@ class DropdownMenu {
1325
1325
  else
1326
1326
  {
1327
1327
  menuItem.addEventListener( "click", () => {
1328
- const f = item[ 'callback' ];
1329
- if( f )
1330
- {
1331
- f.call( this, key, menuItem );
1332
- }
1333
-
1334
1328
  const radioName = menuItem.getAttribute( "data-radioname" );
1335
1329
  if( radioName )
1336
1330
  {
1337
1331
  this._trigger[ radioName ] = key;
1338
1332
  }
1339
1333
 
1340
- this.destroy( true );
1334
+ const f = item.callback;
1335
+ if( f )
1336
+ {
1337
+ f.call( this, key, menuItem, radioName );
1338
+ }
1339
+
1340
+ // If has options, it's a radio group label, so don't close the menu
1341
+ if( !item.options && ( item.closeOnClick ?? true ) )
1342
+ {
1343
+ this.destroy( true );
1344
+ }
1341
1345
  } );
1342
1346
  }
1343
1347
 
@@ -1375,8 +1379,6 @@ class DropdownMenu {
1375
1379
 
1376
1380
  if( item.options )
1377
1381
  {
1378
- this._addSeparator();
1379
-
1380
1382
  console.assert( this._trigger[ item.name ] && "An item of the radio group must be selected!" );
1381
1383
  this._radioGroup = {
1382
1384
  name: item.name,
@@ -6610,6 +6612,22 @@ Object.assign(LX, {
6610
6612
  }
6611
6613
  });
6612
6614
 
6615
+ /**
6616
+ * @method formatBytes
6617
+ * @param {Number} bytes
6618
+ **/
6619
+ function formatBytes( bytes )
6620
+ {
6621
+ if( bytes === 0 ) return "0 B";
6622
+ const k = 1024;
6623
+ const sizes = [ "B", "KB", "MB", "GB", "TB" ];
6624
+ const i = Math.floor( Math.log( bytes ) / Math.log( k ) );
6625
+ const value = bytes / Math.pow( k, i );
6626
+ return value.toFixed( 2 ) + " " + sizes[ i ];
6627
+ }
6628
+
6629
+ LX.formatBytes = formatBytes;
6630
+
6613
6631
  /**
6614
6632
  * @method compareThreshold
6615
6633
  * @param {String} url
@@ -15144,17 +15162,26 @@ class Menubar {
15144
15162
  } });
15145
15163
  };
15146
15164
 
15147
- entry.addEventListener("click", () => {
15165
+ entry.addEventListener("mousedown", (e) => {
15166
+ e.preventDefault();
15167
+ });
15168
+
15169
+ entry.addEventListener("mouseup", (e) => {
15170
+
15171
+ e.preventDefault();
15172
+
15148
15173
  const f = item[ 'callback' ];
15149
15174
  if( f )
15150
15175
  {
15151
- f.call( this, key, entry );
15176
+ f.call( this, key, entry, e );
15152
15177
  return;
15153
15178
  }
15154
15179
 
15155
15180
  _showEntry();
15156
15181
 
15157
15182
  this.focused = true;
15183
+
15184
+ return false;
15158
15185
  });
15159
15186
 
15160
15187
  entry.addEventListener( "mouseover", (e) => {
@@ -15321,7 +15348,12 @@ class Menubar {
15321
15348
  }
15322
15349
 
15323
15350
  const _b = button.querySelector('a');
15324
- _b.addEventListener("click", (e) => {
15351
+
15352
+ _b.addEventListener( "mousedown", (e) => {
15353
+ e.preventDefault();
15354
+ });
15355
+
15356
+ _b.addEventListener( "mouseup", (e) => {
15325
15357
  if( callback && !disabled )
15326
15358
  {
15327
15359
  callback.call( this, _b, e );
@@ -16159,7 +16191,8 @@ LX.AssetViewEvent = AssetViewEvent;
16159
16191
  class AssetView {
16160
16192
 
16161
16193
  static LAYOUT_GRID = 0;
16162
- static LAYOUT_LIST = 1;
16194
+ static LAYOUT_COMPACT = 1;
16195
+ static LAYOUT_LIST = 2;
16163
16196
 
16164
16197
  static CONTENT_SORT_ASC = 0;
16165
16198
  static CONTENT_SORT_DESC = 1;
@@ -16421,7 +16454,9 @@ class AssetView {
16421
16454
  }
16422
16455
  else
16423
16456
  {
16457
+ area.root.classList.add( "flex", "flex-col" );
16424
16458
  this.toolsPanel = area.addPanel({ className: 'flex flex-col overflow-hidden', height:"auto" });
16459
+ this.toolsPanel.root.style.flex = "none";
16425
16460
  this.contentPanel = area.addPanel({ className: 'lexassetcontentpanel flex flex-col overflow-hidden' });
16426
16461
  }
16427
16462
 
@@ -16438,7 +16473,8 @@ class AssetView {
16438
16473
  const _onChangeView = ( value, event ) => {
16439
16474
  new LX.DropdownMenu( event.target, [
16440
16475
  { name: "Grid", icon: "LayoutGrid", callback: () => this._setContentLayout( AssetView.LAYOUT_GRID ) },
16441
- { name: "List", icon: "LayoutList", callback: () => this._setContentLayout( AssetView.LAYOUT_LIST ) }
16476
+ { name: "Compact", icon: "LayoutList", callback: () => this._setContentLayout( AssetView.LAYOUT_COMPACT ) },
16477
+ { name: "List", icon: "List", callback: () => this._setContentLayout( AssetView.LAYOUT_LIST ) }
16442
16478
  ], { side: "right", align: "start" });
16443
16479
  };
16444
16480
 
@@ -16548,11 +16584,13 @@ class AssetView {
16548
16584
  _refreshContent( searchValue, filter ) {
16549
16585
 
16550
16586
  const isGridLayout = ( this.layout == AssetView.LAYOUT_GRID ); // default
16587
+ const isCompactLayout = ( this.layout == AssetView.LAYOUT_COMPACT );
16588
+ const isListLayout = ( this.layout == AssetView.LAYOUT_LIST );
16551
16589
 
16552
16590
  this.filter = filter ?? ( this.filter ?? "None" );
16553
16591
  this.searchValue = searchValue ?? (this.searchValue ?? "");
16554
16592
  this.content.innerHTML = "";
16555
- this.content.className = (isGridLayout ? "lexassetscontent" : "lexassetscontent list");
16593
+ this.content.className = `lexassetscontent${ isCompactLayout ? " compact" : ( isListLayout ? " list" : "" ) }`;
16556
16594
  let that = this;
16557
16595
 
16558
16596
  const _addItem = function(item) {
@@ -16566,6 +16604,11 @@ class AssetView {
16566
16604
  itemEl.tabIndex = -1;
16567
16605
  that.content.appendChild( itemEl );
16568
16606
 
16607
+ if( item.lastModified && !item.lastModifiedDate )
16608
+ {
16609
+ item.lastModifiedDate = that._lastModifiedToStringDate( item.lastModified );
16610
+ }
16611
+
16569
16612
  if( !that.useNativeTitle )
16570
16613
  {
16571
16614
  let desc = document.createElement( 'span' );
@@ -16687,14 +16730,17 @@ class AssetView {
16687
16730
  }
16688
16731
  }
16689
16732
 
16690
- if( !isFolder )
16733
+ // Add item type info
16734
+ let itemInfoHtml = type;
16735
+
16736
+ if( isListLayout )
16691
16737
  {
16692
- let info = document.createElement('span');
16693
- info.className = "lexassetinfo";
16694
- info.innerText = type;
16695
- itemEl.appendChild(info);
16738
+ if( item.bytesize ) itemInfoHtml += ` | ${ LX.formatBytes( item.bytesize ) }`;
16739
+ if( item.lastModifiedDate ) itemInfoHtml += ` | ${ item.lastModifiedDate }`;
16696
16740
  }
16697
16741
 
16742
+ LX.makeContainer( [ "auto", "auto" ], "lexassetinfo", itemInfoHtml, itemEl );
16743
+
16698
16744
  itemEl.addEventListener('click', function( e ) {
16699
16745
  e.stopImmediatePropagation();
16700
16746
  e.stopPropagation();
@@ -16836,18 +16882,18 @@ class AssetView {
16836
16882
  const options = { disabled: true };
16837
16883
 
16838
16884
  this.previewPanel.addText("Filename", file.id, null, options);
16839
- if( file.lastModified ) this.previewPanel.addText("Last Modified", new Date( file.lastModified ).toLocaleString(), null, options);
16885
+ if( file.lastModifiedDate ) this.previewPanel.addText("Last Modified", file.lastModifiedDate, null, options);
16840
16886
  if( file._path || file.src ) this.previewPanel.addText("URL", file._path ? file._path : file.src, null, options);
16841
16887
  this.previewPanel.addText("Path", this.path.join('/'), null, options);
16842
16888
  this.previewPanel.addText("Type", file.type, null, options);
16843
- if( file.bytesize ) this.previewPanel.addText("Size", (file.bytesize/1024).toPrecision(3) + " KBs", null, options);
16889
+ if( file.bytesize ) this.previewPanel.addText("Size", LX.formatBytes( file.bytesize ), null, options);
16844
16890
  if( file.type == "folder" ) this.previewPanel.addText("Files", file.children ? file.children.length.toString() : "0", null, options);
16845
16891
 
16846
16892
  this.previewPanel.addSeparator();
16847
16893
 
16848
16894
  const previewActions = [...this.previewActions];
16849
16895
 
16850
- if( !previewActions.length )
16896
+ if( !previewActions.length && file.type !== "folder" )
16851
16897
  {
16852
16898
  // By default
16853
16899
  previewActions.push({
@@ -16887,7 +16933,8 @@ class AssetView {
16887
16933
  "id": file.name,
16888
16934
  "src": e.currentTarget.result,
16889
16935
  "extension": ext,
16890
- "lastModified": file.lastModified
16936
+ "lastModified": file.lastModified,
16937
+ "lastModifiedDate": this._lastModifiedToStringDate( file.lastModified )
16891
16938
  };
16892
16939
 
16893
16940
  switch(ext)
@@ -17000,6 +17047,11 @@ class AssetView {
17000
17047
 
17001
17048
  this._processData( this.data );
17002
17049
  }
17050
+
17051
+ _lastModifiedToStringDate( lm ) {
17052
+ const d = new Date( lm ).toLocaleString();
17053
+ return d.substring( 0, d.indexOf( ',' ) );
17054
+ }
17003
17055
  }
17004
17056
 
17005
17057
  LX.AssetView = AssetView;