lexgui 0.1.39 → 0.1.41

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.
package/build/lexgui.js CHANGED
@@ -12,7 +12,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
12
12
  */
13
13
 
14
14
  var LX = global.LX = {
15
- version: "0.1.39",
15
+ version: "0.1.41",
16
16
  ready: false,
17
17
  components: [], // specific pre-build components
18
18
  signals: {} // events and triggers
@@ -1200,7 +1200,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
1200
1200
  // Send area resize to every widget in the area
1201
1201
  for( let widget of widgets )
1202
1202
  {
1203
- const jsInstance = widget.jsIinstance;
1203
+ const jsInstance = widget.jsInstance;
1204
1204
 
1205
1205
  if( jsInstance.onresize )
1206
1206
  {
@@ -2541,6 +2541,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
2541
2541
  static KNOB = 23;
2542
2542
  static SIZE = 24;
2543
2543
  static PAD = 25;
2544
+ static FORM = 26;
2544
2545
 
2545
2546
  static NO_CONTEXT_TYPES = [
2546
2547
  Widget.BUTTON,
@@ -2627,6 +2628,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
2627
2628
  case Widget.KNOB: return "Knob";
2628
2629
  case Widget.SIZE: return "Size";
2629
2630
  case Widget.PAD: return "Pad";
2631
+ case Widget.FORM: return "Form";
2630
2632
  case Widget.CUSTOM: return this.customName;
2631
2633
  }
2632
2634
  }
@@ -2821,7 +2823,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
2821
2823
  let isParent = node.children.length > 0;
2822
2824
  let isSelected = this.selected.indexOf( node ) > -1;
2823
2825
 
2824
- if( this.options.only_folders )
2826
+ if( this.options.onlyFolders )
2825
2827
  {
2826
2828
  let has_folders = false;
2827
2829
  node.children.forEach( c => has_folders |= (c.type == 'folder') );
@@ -3200,7 +3202,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
3200
3202
  {
3201
3203
  let child = node.children[i];
3202
3204
 
3203
- if( this.options.only_folders && child.type != 'folder')
3205
+ if( this.options.onlyFolders && child.type != 'folder')
3204
3206
  continue;
3205
3207
 
3206
3208
  this._create_item( node, child, level + 1 );
@@ -3528,7 +3530,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
3528
3530
 
3529
3531
  if( name != undefined )
3530
3532
  {
3531
- if( !(options.no_name ?? false) )
3533
+ if( !(options.hideName ?? false) )
3532
3534
  {
3533
3535
  let domName = document.createElement( 'div' );
3534
3536
  domName.className = "lexwidgetname";
@@ -3568,6 +3570,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
3568
3570
  }
3569
3571
 
3570
3572
  widget.domEl = element;
3573
+ element.jsInstance = widget;
3571
3574
 
3572
3575
  const insert_widget = el => {
3573
3576
  if(options.container)
@@ -3637,7 +3640,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
3637
3640
  element.className += " lexfilter noname";
3638
3641
 
3639
3642
  let input = document.createElement('input');
3640
- input.id = 'input-filter';
3643
+ input.className = 'lexinput-filter';
3641
3644
  input.setAttribute("placeholder", options.placeholder);
3642
3645
  input.style.width = "calc( 100% - 17px )";
3643
3646
  input.value = options.filterValue || "";
@@ -4222,7 +4225,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4222
4225
 
4223
4226
  addCard( name, options = {} ) {
4224
4227
 
4225
- options.no_name = true;
4228
+ options.hideName = true;
4226
4229
  let widget = this.create_widget(name, Widget.CARD, options);
4227
4230
  let element = widget.domEl;
4228
4231
 
@@ -4273,6 +4276,89 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4273
4276
  return widget;
4274
4277
  }
4275
4278
 
4279
+ /**
4280
+ * @method addForm
4281
+ * @param {String} name Widget name
4282
+ * @param {Object} data Form data
4283
+ * @param {Function} callback Callback function on submit form
4284
+ * @param {*} options:
4285
+ * actionName: Text to be shown in the button
4286
+ */
4287
+
4288
+ addForm( name, data, callback, options = {} ) {
4289
+
4290
+ if( data.constructor != Object )
4291
+ {
4292
+ console.error( "Form data must be an Object" );
4293
+ return;
4294
+ }
4295
+
4296
+ // Always hide name for this one
4297
+ options.hideName = true;
4298
+
4299
+ let widget = this.create_widget( name, Widget.FORM, options );
4300
+
4301
+ widget.onGetValue = () => {
4302
+ return container.formData;
4303
+ };
4304
+
4305
+ widget.onSetValue = ( newValue, skipCallback ) => {
4306
+ container.formData = newValue;
4307
+ const entries = container.querySelectorAll( ".lexwidget" );
4308
+ for( let i = 0; i < entries.length; ++i )
4309
+ {
4310
+ const entry = entries[ i ];
4311
+ if( entry.jsInstance.type != LX.Widget.TEXT )
4312
+ {
4313
+ continue;
4314
+ }
4315
+ let entryName = entries[ i ].querySelector( ".lexwidgetname" ).innerText;
4316
+ let entryInput = entries[ i ].querySelector( ".lextext input" );
4317
+ entryInput.value = newValue[ entryName ] ?? "";
4318
+ Panel._dispatch_event( entryInput, "focusout", skipCallback );
4319
+ }
4320
+ };
4321
+
4322
+ // Add widget value
4323
+
4324
+ let element = widget.domEl;
4325
+
4326
+ let container = document.createElement( 'div' );
4327
+ container.className = "lexformdata";
4328
+
4329
+ this.queue( container );
4330
+
4331
+ container.formData = {};
4332
+
4333
+ for( let entry in data )
4334
+ {
4335
+ const entryData = data[ entry ];
4336
+ this.addText( entry, entryData.constructor == Object ? entryData.value : entryData, ( value ) => {
4337
+ container.formData[ entry ] = value;
4338
+ }, entryData );
4339
+
4340
+ container.formData[ entry ] = entryData.constructor == Object ? entryData.value : entryData;
4341
+ }
4342
+
4343
+ this.addButton( null, options.actionName ?? "Submit", ( value, event ) => {
4344
+ if( callback )
4345
+ {
4346
+ callback( container.formData, event );
4347
+ }
4348
+ } );
4349
+
4350
+ this.clearQueue();
4351
+
4352
+ element.appendChild( container );
4353
+
4354
+ if( !widget.name || options.hideName ) {
4355
+ element.className += " noname";
4356
+ container.style.width = "100%";
4357
+ }
4358
+
4359
+ return widget;
4360
+ }
4361
+
4276
4362
  /**
4277
4363
  * @method addContent
4278
4364
  * @param {HTMLElement} element
@@ -4297,27 +4383,29 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4297
4383
  async addImage( url, options = {} ) {
4298
4384
 
4299
4385
  if( !url )
4300
- return;
4386
+ {
4387
+ return;
4388
+ }
4301
4389
 
4302
- options.no_name = true;
4303
- let widget = this.create_widget(null, Widget.IMAGE, options);
4390
+ options.hideName = true;
4391
+ let widget = this.create_widget( null, Widget.IMAGE, options );
4304
4392
  let element = widget.domEl;
4305
4393
 
4306
- let container = document.createElement('div');
4394
+ let container = document.createElement( 'div' );
4307
4395
  container.className = "leximage";
4308
4396
  container.style.width = "100%";
4309
4397
 
4310
- let img = document.createElement('img');
4398
+ let img = document.createElement( 'img' );
4311
4399
  img.src = url;
4312
4400
 
4313
- for(let s in options.style) {
4314
-
4315
- img.style[s] = options.style[s];
4401
+ for( let s in options.style )
4402
+ {
4403
+ img.style[ s ] = options.style[ s ];
4316
4404
  }
4317
4405
 
4318
4406
  await img.decode();
4319
- container.appendChild(img);
4320
- element.appendChild(container);
4407
+ container.appendChild( img );
4408
+ element.appendChild( container );
4321
4409
 
4322
4410
  return widget;
4323
4411
  }
@@ -4416,7 +4504,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4416
4504
  setTimeout( () => delete this.unfocus_event, 200 );
4417
4505
  } else if ( e.relatedTarget && e.relatedTarget.tagName == "INPUT" ) {
4418
4506
  return;
4419
- }else if ( e.target.id == 'input-filter' ) {
4507
+ }else if ( e.target.id == 'lexinput-filter' ) {
4420
4508
  return;
4421
4509
  }
4422
4510
  this.toggleAttribute( 'hidden', true );
@@ -5391,7 +5479,6 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5391
5479
  vecinput.addEventListener( "mousedown", inner_mousedown );
5392
5480
 
5393
5481
  var that = this;
5394
- var lastY = 0;
5395
5482
 
5396
5483
  function inner_mousedown( e )
5397
5484
  {
@@ -5403,13 +5490,16 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5403
5490
  var doc = that.root.ownerDocument;
5404
5491
  doc.addEventListener( 'mousemove', inner_mousemove );
5405
5492
  doc.addEventListener( 'mouseup', inner_mouseup );
5406
- lastY = e.pageY;
5407
- document.body.classList.add( 'nocursor' );
5408
5493
  document.body.classList.add( 'noevents' );
5409
5494
  dragIcon.classList.remove( 'hidden' );
5410
5495
  e.stopImmediatePropagation();
5411
5496
  e.stopPropagation();
5412
5497
 
5498
+ if( !document.pointerLockElement )
5499
+ {
5500
+ vecinput.requestPointerLock();
5501
+ }
5502
+
5413
5503
  if( options.onPress )
5414
5504
  {
5415
5505
  options.onPress.bind( vecinput )( e, vecinput );
@@ -5418,8 +5508,10 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5418
5508
 
5419
5509
  function inner_mousemove( e )
5420
5510
  {
5421
- if ( lastY != e.pageY ) {
5422
- let dt = lastY - e.pageY;
5511
+ let dt = -e.movementY;
5512
+
5513
+ if ( dt != 0 )
5514
+ {
5423
5515
  let mult = options.step ?? 1;
5424
5516
  if( e.shiftKey ) mult *= 10;
5425
5517
  else if( e.altKey ) mult *= 0.1;
@@ -5428,7 +5520,6 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5428
5520
  Panel._dispatch_event( vecinput, "change" );
5429
5521
  }
5430
5522
 
5431
- lastY = e.pageY;
5432
5523
  e.stopPropagation();
5433
5524
  e.preventDefault();
5434
5525
  }
@@ -5438,10 +5529,14 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5438
5529
  var doc = that.root.ownerDocument;
5439
5530
  doc.removeEventListener( 'mousemove', inner_mousemove );
5440
5531
  doc.removeEventListener( 'mouseup', inner_mouseup );
5441
- document.body.classList.remove( 'nocursor' );
5442
5532
  document.body.classList.remove( 'noevents' );
5443
5533
  dragIcon.classList.add( 'hidden' );
5444
5534
 
5535
+ if( document.pointerLockElement )
5536
+ {
5537
+ document.exitPointerLock();
5538
+ }
5539
+
5445
5540
  if( options.onRelease )
5446
5541
  {
5447
5542
  options.onRelease.bind( vecinput )( e, vecinput );
@@ -5534,7 +5629,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5534
5629
 
5535
5630
  if( value[ i ].constructor == Number )
5536
5631
  {
5537
- value[ i ] = clamp(value[ i ], +vecinput.min, +vecinput.max);
5632
+ value[ i ] = clamp( value[ i ], +vecinput.min, +vecinput.max );
5538
5633
  value[ i ] = round( value[ i ], options.precision );
5539
5634
  }
5540
5635
 
@@ -5576,7 +5671,9 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5576
5671
  vecinput.addEventListener( "change", e => {
5577
5672
 
5578
5673
  if( isNaN( e.target.value ) )
5674
+ {
5579
5675
  return;
5676
+ }
5580
5677
 
5581
5678
  const skipCallback = e.detail;
5582
5679
 
@@ -5587,7 +5684,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5587
5684
  if( !skipCallback )
5588
5685
  {
5589
5686
  let btn = element.querySelector( ".lexwidgetname .lexicon" );
5590
- if( btn ) btn.style.display = val != vecinput.iValue ? "block": "none";
5687
+ if( btn ) btn.style.display = val != vecinput.iValue ? "block" : "none";
5591
5688
  }
5592
5689
 
5593
5690
  if( locker.locked )
@@ -5596,7 +5693,8 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5596
5693
  v.value = val;
5597
5694
  value[ v.idx ] = val;
5598
5695
  }
5599
- } else
5696
+ }
5697
+ else
5600
5698
  {
5601
5699
  vecinput.value = val;
5602
5700
  value[ e.target.idx ] = val;
@@ -5610,7 +5708,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5610
5708
  vecinput.addEventListener( "mousedown", inner_mousedown );
5611
5709
 
5612
5710
  var that = this;
5613
- var lastY = 0;
5711
+
5614
5712
  function inner_mousedown( e )
5615
5713
  {
5616
5714
  if( document.activeElement == vecinput )
@@ -5621,13 +5719,17 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5621
5719
  var doc = that.root.ownerDocument;
5622
5720
  doc.addEventListener( 'mousemove', inner_mousemove );
5623
5721
  doc.addEventListener( 'mouseup', inner_mouseup );
5624
- lastY = e.pageY;
5625
5722
  document.body.classList.add( 'nocursor' );
5626
5723
  document.body.classList.add( 'noevents' );
5627
5724
  dragIcon.classList.remove( 'hidden' );
5628
5725
  e.stopImmediatePropagation();
5629
5726
  e.stopPropagation();
5630
5727
 
5728
+ if( !document.pointerLockElement )
5729
+ {
5730
+ vecinput.requestPointerLock();
5731
+ }
5732
+
5631
5733
  if( options.onPress )
5632
5734
  {
5633
5735
  options.onPress.bind( vecinput )( e, vecinput );
@@ -5636,8 +5738,10 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5636
5738
 
5637
5739
  function inner_mousemove( e )
5638
5740
  {
5639
- if ( lastY != e.pageY ) {
5640
- let dt = lastY - e.pageY;
5741
+ let dt = -e.movementY;
5742
+
5743
+ if ( dt != 0 )
5744
+ {
5641
5745
  let mult = options.step ?? 1;
5642
5746
  if( e.shiftKey ) mult = 10;
5643
5747
  else if( e.altKey ) mult = 0.1;
@@ -5656,7 +5760,6 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5656
5760
  }
5657
5761
  }
5658
5762
 
5659
- lastY = e.pageY;
5660
5763
  e.stopPropagation();
5661
5764
  e.preventDefault();
5662
5765
  }
@@ -5666,10 +5769,14 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5666
5769
  var doc = that.root.ownerDocument;
5667
5770
  doc.removeEventListener( 'mousemove', inner_mousemove );
5668
5771
  doc.removeEventListener( 'mouseup', inner_mouseup );
5669
- document.body.classList.remove( 'nocursor' );
5670
5772
  document.body.classList.remove( 'noevents' );
5671
5773
  dragIcon.classList.add('hidden');
5672
5774
 
5775
+ if( document.pointerLockElement )
5776
+ {
5777
+ document.exitPointerLock();
5778
+ }
5779
+
5673
5780
  if( options.onRelease )
5674
5781
  {
5675
5782
  options.onRelease.bind( vecinput )( e, vecinput );
@@ -5707,7 +5814,8 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5707
5814
  {
5708
5815
  this.classList.add( "fa-lock" );
5709
5816
  this.classList.remove( "fa-lock-open" );
5710
- } else {
5817
+ }
5818
+ else {
5711
5819
  this.classList.add( "fa-lock-open" );
5712
5820
  this.classList.remove( "fa-lock" );
5713
5821
  }
@@ -7506,12 +7614,12 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7506
7614
  this.layout = options.layout ?? AssetView.LAYOUT_CONTENT;
7507
7615
  this.contentPage = 1;
7508
7616
 
7509
- if(options.root_path)
7617
+ if( options.rootPath )
7510
7618
  {
7511
- if(options.root_path.constructor !== String)
7619
+ if(options.rootPath.constructor !== String)
7512
7620
  console.warn("Asset Root Path must be a String (now is " + path.constructor.name + ")");
7513
7621
  else
7514
- this.rootPath = options.root_path;
7622
+ this.rootPath = options.rootPath;
7515
7623
  }
7516
7624
 
7517
7625
  let div = document.createElement('div');
@@ -7523,13 +7631,13 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7523
7631
 
7524
7632
  let left, right, contentArea = area;
7525
7633
 
7526
- this.skip_browser = options.skip_browser ?? false;
7527
- this.skip_preview = options.skip_preview ?? false;
7528
- this.only_folders = options.only_folders ?? true;
7529
- this.preview_actions = options.preview_actions ?? [];
7530
- this.context_menu = options.context_menu ?? [];
7634
+ this.skipBrowser = options.skipBrowser ?? false;
7635
+ this.skipPreview = options.skipPreview ?? false;
7636
+ this.onlyFolders = options.onlyFolders ?? true;
7637
+ this.previewActions = options.previewActions ?? [];
7638
+ this.contextMenu = options.contextMenu ?? [];
7531
7639
 
7532
- if( !this.skip_browser )
7640
+ if( !this.skipBrowser )
7533
7641
  {
7534
7642
  [left, right] = area.split({ type: "horizontal", sizes: ["15%", "85%"]});
7535
7643
  contentArea = right;
@@ -7538,28 +7646,34 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7538
7646
  right.setLimitBox( 512, 0 );
7539
7647
  }
7540
7648
 
7541
- if( !this.skip_preview )
7542
- [contentArea, right] = contentArea.split({ type: "horizontal", sizes: ["80%", "20%"]});
7649
+ if( !this.skipPreview )
7650
+ {
7651
+ [ contentArea, right ] = contentArea.split({ type: "horizontal", sizes: ["80%", "20%"]});
7652
+ }
7543
7653
 
7544
- this.allowedTypes = options.allowed_types || ["None", "Image", "Mesh", "Script", "JSON", "Clip"];
7654
+ this.allowedTypes = options.allowedTypes || ["None", "Image", "Mesh", "Script", "JSON", "Clip"];
7545
7655
 
7546
7656
  this.prevData = [];
7547
7657
  this.nextData = [];
7548
7658
  this.data = [];
7549
7659
 
7550
- this._processData(this.data, null);
7660
+ this._processData( this.data, null );
7551
7661
 
7552
7662
  this.currentData = this.data;
7553
7663
  this.path = ['@'];
7554
7664
 
7555
- if(!this.skip_browser)
7556
- this._createTreePanel(left);
7665
+ if( !this.skipBrowser )
7666
+ {
7667
+ this._createTreePanel( left );
7668
+ }
7557
7669
 
7558
- this._createContentPanel(contentArea);
7670
+ this._createContentPanel( contentArea );
7559
7671
 
7560
7672
  // Create resource preview panel
7561
- if( !this.skip_preview )
7562
- this.previewPanel = right.addPanel({className: 'lexassetcontentpanel', style: { overflow: 'scroll' }});
7673
+ if( !this.skipPreview )
7674
+ {
7675
+ this.previewPanel = right.addPanel( {className: 'lexassetcontentpanel', style: { overflow: 'scroll' }} );
7676
+ }
7563
7677
  }
7564
7678
 
7565
7679
  /**
@@ -7573,12 +7687,15 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7573
7687
 
7574
7688
  this.data = data;
7575
7689
 
7576
- this._processData(this.data, null);
7690
+ this._processData( this.data, null );
7577
7691
  this.currentData = this.data;
7578
- this.path = ['@'];
7692
+ this.path = [ '@' ];
7693
+
7694
+ if( !this.skipBrowser )
7695
+ {
7696
+ this._createTreePanel( this.area );
7697
+ }
7579
7698
 
7580
- if(!this.skip_browser)
7581
- this._createTreePanel(this.area);
7582
7699
  this._refreshContent();
7583
7700
 
7584
7701
  this.onevent = onevent;
@@ -7588,12 +7705,18 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7588
7705
  * @method clear
7589
7706
  */
7590
7707
  clear() {
7591
- if(this.previewPanel)
7708
+ if( this.previewPanel )
7709
+ {
7592
7710
  this.previewPanel.clear();
7593
- if(this.leftPanel)
7711
+ }
7712
+ if( this.leftPanel )
7713
+ {
7594
7714
  this.leftPanel.clear();
7595
- if(this.rightPanel)
7596
- this.rightPanel.clear()
7715
+ }
7716
+ if( this.rightPanel )
7717
+ {
7718
+ this.rightPanel.clear()
7719
+ }
7597
7720
  }
7598
7721
 
7599
7722
  /**
@@ -7604,14 +7727,16 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7604
7727
 
7605
7728
  if( data.constructor !== Array )
7606
7729
  {
7607
- data['folder'] = parent;
7730
+ data[ 'folder' ] = parent;
7608
7731
  data.children = data.children ?? [];
7609
7732
  }
7610
7733
 
7611
7734
  let list = data.constructor === Array ? data : data.children;
7612
7735
 
7613
7736
  for( var i = 0; i < list.length; ++i )
7614
- this._processData( list[i], data );
7737
+ {
7738
+ this._processData( list[ i ], data );
7739
+ }
7615
7740
  }
7616
7741
 
7617
7742
  /**
@@ -7623,9 +7748,9 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7623
7748
  this.path.length = 0;
7624
7749
 
7625
7750
  const push_parents_id = i => {
7626
- if(!i) return;
7751
+ if( !i ) return;
7627
7752
  let list = i.children ? i.children : i;
7628
- let c = list[0];
7753
+ let c = list[ 0 ];
7629
7754
  if( !c ) return;
7630
7755
  if( !c.folder ) return;
7631
7756
  this.path.push( c.folder.id ?? '@' );
@@ -7634,19 +7759,22 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7634
7759
 
7635
7760
  push_parents_id( data );
7636
7761
 
7637
- LX.emit("@on_folder_change", this.path.reverse().join('/'));
7762
+ LX.emit( "@on_folder_change", this.path.reverse().join('/') );
7638
7763
  }
7639
7764
 
7640
7765
  /**
7641
7766
  * @method _createTreePanel
7642
7767
  */
7643
7768
 
7644
- _createTreePanel(area) {
7769
+ _createTreePanel( area ) {
7645
7770
 
7646
7771
  if(this.leftPanel)
7772
+ {
7647
7773
  this.leftPanel.clear();
7648
- else {
7649
- this.leftPanel = area.addPanel({className: 'lexassetbrowserpanel'});
7774
+ }
7775
+ else
7776
+ {
7777
+ this.leftPanel = area.addPanel({ className: 'lexassetbrowserpanel' });
7650
7778
  }
7651
7779
 
7652
7780
  // Process data to show in tree
@@ -7658,18 +7786,21 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7658
7786
  this.tree = this.leftPanel.addTree("Content Browser", treeData, {
7659
7787
  // icons: tree_icons,
7660
7788
  filter: false,
7661
- only_folders: this.only_folders,
7662
- onevent: (event) => {
7789
+ onlyFolders: this.onlyFolders,
7790
+ onevent: event => {
7663
7791
 
7664
7792
  let node = event.node;
7665
7793
  let value = event.value;
7666
7794
 
7667
- switch(event.type) {
7795
+ switch( event.type )
7796
+ {
7668
7797
  case LX.TreeEvent.NODE_SELECTED:
7669
- if(!event.multiple) {
7798
+ if( !event.multiple )
7799
+ {
7670
7800
  this._enterFolder( node );
7671
7801
  }
7672
- if(!node.parent) {
7802
+ if( !node.parent )
7803
+ {
7673
7804
  this.prevData.push( this.currentData );
7674
7805
  this.currentData = this.data;
7675
7806
  this._refreshContent();
@@ -7691,9 +7822,9 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7691
7822
  * @method _setContentLayout
7692
7823
  */
7693
7824
 
7694
- _setContentLayout( layout_mode ) {
7825
+ _setContentLayout( layoutMode ) {
7695
7826
 
7696
- this.layout = layout_mode;
7827
+ this.layout = layoutMode;
7697
7828
 
7698
7829
  this._refreshContent();
7699
7830
  }
@@ -7702,12 +7833,15 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7702
7833
  * @method _createContentPanel
7703
7834
  */
7704
7835
 
7705
- _createContentPanel(area) {
7836
+ _createContentPanel( area ) {
7706
7837
 
7707
- if(this.rightPanel)
7838
+ if( this.rightPanel )
7839
+ {
7708
7840
  this.rightPanel.clear();
7709
- else {
7710
- this.rightPanel = area.addPanel({className: 'lexassetcontentpanel'});
7841
+ }
7842
+ else
7843
+ {
7844
+ this.rightPanel = area.addPanel({ className: 'lexassetcontentpanel' });
7711
7845
  }
7712
7846
 
7713
7847
  const on_sort = (value, event) => {
@@ -7735,20 +7869,24 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7735
7869
  }
7736
7870
 
7737
7871
  const on_change_page = (value, event) => {
7738
- if(!this.allow_next_page)
7872
+ if( !this.allowNextPage )
7873
+ {
7739
7874
  return;
7740
- const last_page = this.contentPage;
7875
+ }
7876
+ const lastPage = this.contentPage;
7741
7877
  this.contentPage += value;
7742
7878
  this.contentPage = Math.min( this.contentPage, (((this.currentData.length - 1) / AssetView.MAX_PAGE_ELEMENTS )|0) + 1 );
7743
7879
  this.contentPage = Math.max( this.contentPage, 1 );
7744
7880
 
7745
- if( last_page != this.contentPage )
7881
+ if( lastPage != this.contentPage )
7882
+ {
7746
7883
  this._refreshContent();
7884
+ }
7747
7885
  }
7748
7886
 
7749
7887
  this.rightPanel.sameLine();
7750
7888
  this.rightPanel.addDropdown("Filter", this.allowedTypes, this.allowedTypes[0], (v) => this._refreshContent.call(this, null, v), { width: "20%", minWidth: "128px" });
7751
- this.rightPanel.addText(null, this.search_value ?? "", (v) => this._refreshContent.call(this, v, null), { placeholder: "Search assets.." });
7889
+ this.rightPanel.addText(null, this.searchValue ?? "", (v) => this._refreshContent.call(this, v, null), { placeholder: "Search assets.." });
7752
7890
  this.rightPanel.addButton(null, "<a class='fa fa-arrow-up-short-wide'></a>", on_sort.bind(this), { className: "micro", title: "Sort" });
7753
7891
  this.rightPanel.addButton(null, "<a class='fa-solid fa-grip'></a>", on_change_view.bind(this), { className: "micro", title: "View" });
7754
7892
  // Content Pages
@@ -7756,7 +7894,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7756
7894
  this.rightPanel.addButton(null, "<a class='fa-solid fa-angles-right'></a>", on_change_page.bind(this, 1), { className: "micro", title: "Next Page" });
7757
7895
  this.rightPanel.endLine();
7758
7896
 
7759
- if( !this.skip_browser )
7897
+ if( !this.skipBrowser )
7760
7898
  {
7761
7899
  this.rightPanel.sameLine();
7762
7900
  this.rightPanel.addComboButtons( null, [
@@ -7816,27 +7954,27 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7816
7954
  this._refreshContent();
7817
7955
  }
7818
7956
 
7819
- _refreshContent(search_value, filter) {
7957
+ _refreshContent( searchValue, filter ) {
7820
7958
 
7821
- const is_content_layout = (this.layout == AssetView.LAYOUT_CONTENT); // default
7959
+ const isContentLayout = (this.layout == AssetView.LAYOUT_CONTENT); // default
7822
7960
 
7823
7961
  this.filter = filter ?? (this.filter ?? "None");
7824
- this.search_value = search_value ?? (this.search_value ?? "");
7962
+ this.searchValue = searchValue ?? (this.searchValue ?? "");
7825
7963
  this.content.innerHTML = "";
7826
- this.content.className = (is_content_layout ? "lexassetscontent" : "lexassetscontent list");
7964
+ this.content.className = (isContentLayout ? "lexassetscontent" : "lexassetscontent list");
7827
7965
  let that = this;
7828
7966
 
7829
7967
  const add_item = function(item) {
7830
7968
 
7831
- const type = item.type.charAt(0).toUpperCase() + item.type.slice(1);
7969
+ const type = item.type.charAt( 0 ).toUpperCase() + item.type.slice( 1 );
7832
7970
  const extension = getExtension( item.id );
7833
- const is_folder = type === "Folder";
7971
+ const isFolder = type === "Folder";
7834
7972
 
7835
7973
  let itemEl = document.createElement('li');
7836
7974
  itemEl.className = "lexassetitem " + item.type.toLowerCase();
7837
7975
  itemEl.title = type + ": " + item.id;
7838
7976
  itemEl.tabIndex = -1;
7839
- that.content.appendChild(itemEl);
7977
+ that.content.appendChild( itemEl );
7840
7978
 
7841
7979
  if(item.selected != undefined) {
7842
7980
  let span = document.createElement('span');
@@ -7845,9 +7983,10 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7845
7983
  checkbox_input.type = "checkbox";
7846
7984
  checkbox_input.className = "checkbox";
7847
7985
  checkbox_input.checked = item.selected;
7848
- checkbox_input.addEventListener('change', (e, v) => {
7986
+ checkbox_input.addEventListener('change', ( e, v ) => {
7849
7987
  item.selected = !item.selected;
7850
- if(that.onevent) {
7988
+ if( that.onevent )
7989
+ {
7851
7990
  const event = new AssetViewEvent(AssetViewEvent.ASSET_CHECKED, e.shiftKey ? [item] : item );
7852
7991
  event.multiple = !!e.shiftKey;
7853
7992
  that.onevent( event );
@@ -7862,19 +8001,19 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7862
8001
  let title = document.createElement('span');
7863
8002
  title.className = "lexassettitle";
7864
8003
  title.innerText = item.id;
7865
- itemEl.appendChild(title);
8004
+ itemEl.appendChild( title );
7866
8005
 
7867
- if( !that.skip_preview ) {
8006
+ if( !that.skipPreview ) {
7868
8007
 
7869
8008
  let preview = null;
7870
- const has_image = item.src && (['png', 'jpg'].indexOf( getExtension( item.src ) ) > -1 || item.src.includes("data:image/") ); // Support b64 image as src
8009
+ const hasImage = item.src && (['png', 'jpg'].indexOf( getExtension( item.src ) ) > -1 || item.src.includes("data:image/") ); // Support b64 image as src
7871
8010
 
7872
- if( has_image || is_folder || !is_content_layout)
8011
+ if( hasImage || isFolder || !isContentLayout)
7873
8012
  {
7874
8013
  preview = document.createElement('img');
7875
- let real_src = item.unknown_extension ? that.rootPath + "images/file.png" : (is_folder ? that.rootPath + "images/folder.png" : item.src);
7876
- preview.src = (is_content_layout || is_folder ? real_src : that.rootPath + "images/file.png");
7877
- itemEl.appendChild(preview);
8014
+ let real_src = item.unknown_extension ? that.rootPath + "images/file.png" : (isFolder ? that.rootPath + "images/folder.png" : item.src);
8015
+ preview.src = (isContentLayout || isFolder ? real_src : that.rootPath + "images/file.png");
8016
+ itemEl.appendChild( preview );
7878
8017
  }
7879
8018
  else
7880
8019
  {
@@ -7900,7 +8039,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7900
8039
  }
7901
8040
  }
7902
8041
 
7903
- if( !is_folder )
8042
+ if( !isFolder )
7904
8043
  {
7905
8044
  let info = document.createElement('span');
7906
8045
  info.className = "lexassetinfo";
@@ -7912,30 +8051,37 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7912
8051
  e.stopImmediatePropagation();
7913
8052
  e.stopPropagation();
7914
8053
 
7915
- const is_double_click = e.detail == LX.MOUSE_DOUBLE_CLICK;
8054
+ const isDoubleClick = ( e.detail == LX.MOUSE_DOUBLE_CLICK );
7916
8055
 
7917
- if(!is_double_click)
8056
+ if( !isDoubleClick )
7918
8057
  {
7919
- if(!e.shiftKey)
8058
+ if( !e.shiftKey )
8059
+ {
7920
8060
  that.content.querySelectorAll('.lexassetitem').forEach( i => i.classList.remove('selected') );
8061
+ }
8062
+
7921
8063
  this.classList.add('selected');
7922
- if( !that.skip_preview )
8064
+
8065
+ if( !that.skipPreview )
8066
+ {
7923
8067
  that._previewAsset( item );
8068
+ }
7924
8069
  }
7925
- else if(is_folder)
8070
+ else if( isFolder )
7926
8071
  {
7927
8072
  that._enterFolder( item );
7928
8073
  return;
7929
8074
  }
7930
8075
 
7931
- if(that.onevent) {
7932
- const event = new AssetViewEvent(is_double_click ? AssetViewEvent.ASSET_DBLCLICKED : AssetViewEvent.ASSET_SELECTED, e.shiftKey ? [item] : item );
8076
+ if( that.onevent )
8077
+ {
8078
+ const event = new AssetViewEvent(isDoubleClick ? AssetViewEvent.ASSET_DBLCLICKED : AssetViewEvent.ASSET_SELECTED, e.shiftKey ? [item] : item );
7933
8079
  event.multiple = !!e.shiftKey;
7934
8080
  that.onevent( event );
7935
8081
  }
7936
8082
  });
7937
8083
 
7938
- if( that.context_menu )
8084
+ if( that.contextMenu )
7939
8085
  {
7940
8086
  itemEl.addEventListener('contextmenu', function(e) {
7941
8087
  e.preventDefault();
@@ -7943,10 +8089,10 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7943
8089
  const multiple = that.content.querySelectorAll('.selected').length;
7944
8090
 
7945
8091
  LX.addContextMenu( multiple > 1 ? (multiple + " selected") :
7946
- is_folder ? item.id : item.type, e, m => {
8092
+ isFolder ? item.id : item.type, e, m => {
7947
8093
  if(multiple <= 1)
7948
8094
  m.add("Rename");
7949
- if( !is_folder )
8095
+ if( !isFolder )
7950
8096
  m.add("Clone", that._clone_item.bind(that, item));
7951
8097
  if(multiple <= 1)
7952
8098
  m.add("Properties");
@@ -7965,21 +8111,23 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7965
8111
 
7966
8112
  const fr = new FileReader();
7967
8113
 
7968
- const filtered_data = this.currentData.filter( _i => {
8114
+ const filteredData = this.currentData.filter( _i => {
7969
8115
  return (this.filter != "None" ? _i.type.toLowerCase() == this.filter.toLowerCase() : true) &&
7970
- _i.id.toLowerCase().includes(this.search_value.toLowerCase())
8116
+ _i.id.toLowerCase().includes(this.searchValue.toLowerCase())
7971
8117
  } );
7972
8118
 
7973
- if(filter || search_value) {
8119
+ if( filter || searchValue )
8120
+ {
7974
8121
  this.contentPage = 1;
7975
8122
  }
8123
+
7976
8124
  // Show all data if using filters
7977
- const start_index = (this.contentPage - 1) * AssetView.MAX_PAGE_ELEMENTS;
7978
- const end_index = Math.min( start_index + AssetView.MAX_PAGE_ELEMENTS, filtered_data.length );
8125
+ const startIndex = (this.contentPage - 1) * AssetView.MAX_PAGE_ELEMENTS;
8126
+ const endIndex = Math.min( startIndex + AssetView.MAX_PAGE_ELEMENTS, filteredData.length );
7979
8127
 
7980
- for( let i = start_index; i < end_index; ++i )
8128
+ for( let i = startIndex; i < endIndex; ++i )
7981
8129
  {
7982
- let item = filtered_data[i];
8130
+ let item = filteredData[ i ];
7983
8131
 
7984
8132
  if( item.path )
7985
8133
  {
@@ -7990,7 +8138,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7990
8138
  item.src = e.currentTarget.result; // This is a base64 string...
7991
8139
  item._path = item.path;
7992
8140
  delete item.path;
7993
- this._refreshContent(search_value, filter);
8141
+ this._refreshContent( searchValue, filter );
7994
8142
  };
7995
8143
  } });
7996
8144
  }else
@@ -7998,15 +8146,15 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
7998
8146
  item.domEl = add_item( item );
7999
8147
  }
8000
8148
  }
8001
- this.allow_next_page = filtered_data.length - 1 > AssetView.MAX_PAGE_ELEMENTS;
8002
- LX.emit("@on_page_change", "Page " + this.contentPage + " / " + ((((filtered_data.length - 1) / AssetView.MAX_PAGE_ELEMENTS )|0) + 1));
8149
+ this.allowNextPage = filteredData.length - 1 > AssetView.MAX_PAGE_ELEMENTS;
8150
+ LX.emit("@on_page_change", "Page " + this.contentPage + " / " + ((((filteredData.length - 1) / AssetView.MAX_PAGE_ELEMENTS )|0) + 1));
8003
8151
  }
8004
8152
 
8005
8153
  /**
8006
8154
  * @method _previewAsset
8007
8155
  */
8008
8156
 
8009
- _previewAsset(file) {
8157
+ _previewAsset( file ) {
8010
8158
 
8011
8159
  const is_base_64 = file.src && file.src.includes("data:image/");
8012
8160
 
@@ -8015,34 +8163,37 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
8015
8163
 
8016
8164
  if( file.type == 'image' || file.src )
8017
8165
  {
8018
- const has_image = ['png', 'jpg'].indexOf( getExtension( file.src ) ) > -1 || is_base_64;
8019
- if( has_image )
8020
- this.previewPanel.addImage(file.src, { style: { width: "100%" } });
8166
+ const hasImage = ['png', 'jpg'].indexOf( getExtension( file.src ) ) > -1 || is_base_64;
8167
+ if( hasImage )
8168
+ {
8169
+ this.previewPanel.addImage( file.src, { style: { width: "100%" } } );
8170
+ }
8021
8171
  }
8022
8172
 
8023
8173
  const options = { disabled: true };
8024
8174
 
8025
8175
  this.previewPanel.addText("Filename", file.id, null, options);
8026
- if(file._path || file.src ) this.previewPanel.addText("URL", file._path ? file._path : file.src, null, options);
8176
+ if( file.lastModified ) this.previewPanel.addText("Last Modified", new Date( file.lastModified ).toLocaleString(), null, options);
8177
+ if( file._path || file.src ) this.previewPanel.addText("URL", file._path ? file._path : file.src, null, options);
8027
8178
  this.previewPanel.addText("Path", this.path.join('/'), null, options);
8028
8179
  this.previewPanel.addText("Type", file.type, null, options);
8029
- if(file.bytesize) this.previewPanel.addText("Size", (file.bytesize/1024).toPrecision(3) + " KBs", null, options);
8030
- if(file.type == "folder") this.previewPanel.addText("Files", file.children ? file.children.length.toString() : "0", null, options);
8180
+ if( file.bytesize ) this.previewPanel.addText("Size", (file.bytesize/1024).toPrecision(3) + " KBs", null, options);
8181
+ if( file.type == "folder" ) this.previewPanel.addText("Files", file.children ? file.children.length.toString() : "0", null, options);
8031
8182
 
8032
8183
  this.previewPanel.addSeparator();
8033
8184
 
8034
- const preview_actions = [...this.preview_actions];
8185
+ const previewActions = [...this.previewActions];
8035
8186
 
8036
- if( !preview_actions.length )
8187
+ if( !previewActions.length )
8037
8188
  {
8038
8189
  // By default
8039
- preview_actions.push({
8190
+ previewActions.push({
8040
8191
  name: 'Download',
8041
8192
  callback: () => LX.downloadURL(file.src, file.id)
8042
8193
  });
8043
8194
  }
8044
8195
 
8045
- for( let action of preview_actions )
8196
+ for( let action of previewActions )
8046
8197
  {
8047
8198
  if( action.type && action.type !== file.type || action.path && action.path !== this.path.join('/') )
8048
8199
  continue;
@@ -8052,7 +8203,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
8052
8203
  this.previewPanel.merge();
8053
8204
  }
8054
8205
 
8055
- _processDrop(e) {
8206
+ _processDrop( e ) {
8056
8207
 
8057
8208
  const fr = new FileReader();
8058
8209
  const num_files = e.dataTransfer.files.length;
@@ -8072,7 +8223,8 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
8072
8223
  let item = {
8073
8224
  "id": file.name,
8074
8225
  "src": e.currentTarget.result,
8075
- "extension": ext
8226
+ "extension": ext,
8227
+ "lastModified": file.lastModified
8076
8228
  };
8077
8229
 
8078
8230
  switch(ext)
@@ -8097,7 +8249,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
8097
8249
 
8098
8250
  if(i == (num_files - 1)) {
8099
8251
  this._refreshContent();
8100
- if( !this.skip_browser )
8252
+ if( !this.skipBrowser )
8101
8253
  this.tree.refresh();
8102
8254
  }
8103
8255
  };
@@ -8117,10 +8269,10 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
8117
8269
  this._refreshContent();
8118
8270
  }
8119
8271
 
8120
- _enterFolder( folder_item ) {
8272
+ _enterFolder( folderItem ) {
8121
8273
 
8122
8274
  this.prevData.push( this.currentData );
8123
- this.currentData = folder_item.children;
8275
+ this.currentData = folderItem.children;
8124
8276
  this.contentPage = 1;
8125
8277
  this._refreshContent();
8126
8278
 
@@ -8128,27 +8280,33 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
8128
8280
  this._updatePath(this.currentData);
8129
8281
 
8130
8282
  // Trigger event
8131
- if(this.onevent) {
8132
- const event = new AssetViewEvent(AssetViewEvent.ENTER_FOLDER, folder_item);
8283
+ if( this.onevent )
8284
+ {
8285
+ const event = new AssetViewEvent( AssetViewEvent.ENTER_FOLDER, folderItem );
8133
8286
  this.onevent( event );
8134
8287
  }
8135
8288
  }
8136
8289
 
8137
8290
  _deleteItem( item ) {
8138
8291
 
8139
- const idx = this.currentData.indexOf(item);
8140
- if(idx > -1) {
8141
- this.currentData.splice(idx, 1);
8142
- this._refreshContent(this.search_value, this.filter);
8292
+ const idx = this.currentData.indexOf( item );
8293
+ if(idx < 0)
8294
+ {
8295
+ console.error( "[AssetView Error] Cannot delete. Item not found." );
8296
+ return;
8297
+ }
8143
8298
 
8144
- if(this.onevent) {
8145
- const event = new AssetViewEvent(AssetViewEvent.ASSET_DELETED, item );
8146
- this.onevent( event );
8147
- }
8299
+ this.currentData.splice( idx, 1 );
8300
+ this._refreshContent( this.searchValue, this.filter );
8148
8301
 
8149
- this.tree.refresh();
8150
- this._processData(this.data);
8302
+ if(this.onevent)
8303
+ {
8304
+ const event = new AssetViewEvent( AssetViewEvent.ASSET_DELETED, item );
8305
+ this.onevent( event );
8151
8306
  }
8307
+
8308
+ this.tree.refresh();
8309
+ this._processData( this.data );
8152
8310
  }
8153
8311
 
8154
8312
  _cloneItem( item ) {
@@ -8159,7 +8317,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
8159
8317
  delete item.folder;
8160
8318
  const new_item = deepCopy( item );
8161
8319
  this.currentData.splice(idx, 0, new_item);
8162
- this._refreshContent(this.search_value, this.filter);
8320
+ this._refreshContent(this.searchValue, this.filter);
8163
8321
 
8164
8322
  if(this.onevent) {
8165
8323
  const event = new AssetViewEvent(AssetViewEvent.ASSET_CLONED, item );
@@ -8426,6 +8584,10 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
8426
8584
  return !!r.length;
8427
8585
  }
8428
8586
 
8587
+ Element.prototype.addClass = function( className ) {
8588
+ if( className ) this.classList.add( className );
8589
+ }
8590
+
8429
8591
  Element.prototype.getComputedSize = function() {
8430
8592
  const cs = getComputedStyle( this );
8431
8593
  return {
@@ -8438,7 +8600,6 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
8438
8600
  getTime() { return new Date().getTime() },
8439
8601
  compareThreshold( v, p, n, t ) { return Math.abs(v - p) >= t || Math.abs(v - n) >= t },
8440
8602
  compareThresholdRange( v0, v1, t0, t1 ) { return v0 >= t0 && v0 <= t1 || v1 >= t0 && v1 <= t1 || v0 <= t0 && v1 >= t1},
8441
- clamp (num, min, max) { return Math.min(Math.max(num, min), max) },
8442
8603
  uidGenerator: simple_guidGenerator,
8443
8604
  deleteElement( el ) { if( el ) el.remove(); },
8444
8605
  flushCss(element) {