lexgui 0.5.9 → 0.5.11

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.
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  var LX = {
9
- version: "0.5.9",
9
+ version: "0.5.11",
10
10
  ready: false,
11
11
  components: [], // Specific pre-build components
12
12
  signals: {}, // Events and triggers
@@ -204,6 +204,29 @@ function setTheme( colorScheme )
204
204
 
205
205
  LX.setTheme = setTheme;
206
206
 
207
+ /**
208
+ * @method getTheme
209
+ * @description Gets either "dark" or "light" theme value
210
+ */
211
+ function getTheme()
212
+ {
213
+ return document.documentElement.getAttribute( "data-theme" ) ?? "dark";
214
+ }
215
+
216
+ LX.getTheme = getTheme;
217
+
218
+ /**
219
+ * @method switchTheme
220
+ * @description Toggles between "dark" and "light" themes
221
+ */
222
+ function switchTheme()
223
+ {
224
+ const currentTheme = getTheme();
225
+ setTheme( currentTheme == "dark" ? "light" : "dark" );
226
+ }
227
+
228
+ LX.switchTheme = switchTheme;
229
+
207
230
  /**
208
231
  * @method setThemeColor
209
232
  * @description Sets a new value for one of the main theme variables
@@ -1239,7 +1262,7 @@ function _createCommandbar( root )
1239
1262
  if( LX.has('CodeEditor') )
1240
1263
  {
1241
1264
  const instances = LX.CodeEditor.getInstances();
1242
- if( !instances.length ) return;
1265
+ if( !instances.length || !instances[ 0 ].area.root.offsetHeight ) return;
1243
1266
 
1244
1267
  const languages = instances[ 0 ].languages;
1245
1268
 
@@ -1702,35 +1725,52 @@ function badge( text, className, options = {} )
1702
1725
  LX.badge = badge;
1703
1726
 
1704
1727
  /**
1705
- * @method makeContainer
1706
- * @param {Array} size
1728
+ * @method makeElement
1729
+ * @param {String} htmlType
1707
1730
  * @param {String} className
1708
1731
  * @param {String} innerHTML
1709
1732
  * @param {HTMLElement} parent
1710
1733
  * @param {Object} overrideStyle
1711
1734
  */
1712
1735
 
1713
- function makeContainer( size, className, innerHTML, parent, overrideStyle = {} )
1736
+ function makeElement( htmlType, className, innerHTML, parent, overrideStyle = {} )
1714
1737
  {
1715
- const container = document.createElement( "div" );
1716
- container.className = "lexcontainer " + ( className ?? "" );
1717
- container.innerHTML = innerHTML ?? "";
1718
- container.style.width = size && size[ 0 ] ? size[ 0 ] : "100%";
1719
- container.style.height = size && size[ 1 ] ? size[ 1 ] : "100%";
1720
- Object.assign( container.style, overrideStyle );
1738
+ const element = document.createElement( htmlType );
1739
+ element.className = className ?? ""
1740
+ element.innerHTML = innerHTML ?? "";
1741
+ Object.assign( element.style, overrideStyle );
1721
1742
 
1722
1743
  if( parent )
1723
1744
  {
1724
1745
  if( parent.attach ) // Use attach method if possible
1725
1746
  {
1726
- parent.attach( container );
1747
+ parent.attach( element );
1727
1748
  }
1728
1749
  else // its a native HTMLElement
1729
1750
  {
1730
- parent.appendChild( container );
1751
+ parent.appendChild( element );
1731
1752
  }
1732
1753
  }
1733
1754
 
1755
+ return element;
1756
+ }
1757
+
1758
+ LX.makeElement = makeElement;
1759
+
1760
+ /**
1761
+ * @method makeContainer
1762
+ * @param {Array} size
1763
+ * @param {String} className
1764
+ * @param {String} innerHTML
1765
+ * @param {HTMLElement} parent
1766
+ * @param {Object} overrideStyle
1767
+ */
1768
+
1769
+ function makeContainer( size, className, innerHTML, parent, overrideStyle = {} )
1770
+ {
1771
+ const container = LX.makeElement( "div", "lexcontainer " + ( className ?? "" ), innerHTML, parent, overrideStyle );
1772
+ container.style.width = size && size[ 0 ] ? size[ 0 ] : "100%";
1773
+ container.style.height = size && size[ 1 ] ? size[ 1 ] : "100%";
1734
1774
  return container;
1735
1775
  }
1736
1776
 
@@ -4997,14 +5037,14 @@ class SideBar {
4997
5037
  this.root.appendChild( this.footer );
4998
5038
  }
4999
5039
 
5000
- // Set width depending on header/footer
5001
- doAsync( () => {
5002
- // This account for header, footer and all inner margins
5003
- const contentOffset = ( parseInt( this.header?.getComputedSize().height ) ?? 0 ) +
5004
- ( parseInt( this.filter?.getComputedSize().height ) ?? 0 ) +
5005
- ( parseInt( this.footer?.getComputedSize().height ) ?? 0 );
5040
+ const resizeObserver = new ResizeObserver( entries => {
5041
+ const contentOffset = ( this.header?.offsetHeight ?? 0 ) +
5042
+ ( this.filter?.offsetHeight ?? 0 ) +
5043
+ ( this.footer?.offsetHeight ?? 0 );
5006
5044
  this.content.style.height = `calc(100% - ${ contentOffset }px)`;
5007
- }, 10 );
5045
+ } );
5046
+
5047
+ resizeObserver.observe( this.root );
5008
5048
 
5009
5049
  this.items = [ ];
5010
5050
  this.icons = { };
@@ -7252,12 +7292,17 @@ class Form extends Widget {
7252
7292
  if( entryData.constructor != Object )
7253
7293
  {
7254
7294
  entryData = { };
7295
+ data[ entry ] = entryData;
7255
7296
  }
7256
7297
 
7257
7298
  entryData.placeholder = entryData.placeholder ?? entry;
7258
7299
  entryData.width = "100%";
7259
7300
 
7260
- // this.addLabel( entry, { textClass: "formlabel" } );
7301
+ if( !( options.skipLabels ?? false ) )
7302
+ {
7303
+ const label = new TextInput( null, entry, null, { disabled: true, inputClass: "formlabel nobg" } );
7304
+ container.appendChild( label.root );
7305
+ }
7261
7306
 
7262
7307
  entryData.textWidget = new TextInput( null, entryData.constructor == Object ? entryData.value : entryData, ( value ) => {
7263
7308
  container.formData[ entry ] = value;
@@ -7267,9 +7312,21 @@ class Form extends Widget {
7267
7312
  container.formData[ entry ] = entryData.constructor == Object ? entryData.value : entryData;
7268
7313
  }
7269
7314
 
7270
- container.appendChild( new Blank().root );
7315
+ const buttonContainer = LX.makeContainer( ["100%", "auto"], "flex flex-row", "", container );
7316
+
7317
+ if( options.secondaryActionName || options.secondaryActionCallback )
7318
+ {
7319
+ const secondaryButton = new Button( null, options.secondaryActionName ?? "Cancel", ( value, event ) => {
7320
+ if( callback )
7321
+ {
7322
+ callback( container.formData, event );
7323
+ }
7324
+ }, { width: "100%", minWidth: "0", buttonClass: options.secondaryButtonClass ?? "primary" } );
7325
+
7326
+ buttonContainer.appendChild( secondaryButton.root );
7327
+ }
7271
7328
 
7272
- const submitButton = new Button( null, options.actionName ?? "Submit", ( value, event ) => {
7329
+ const primaryButton = new Button( null, options.primaryActionName ?? "Submit", ( value, event ) => {
7273
7330
 
7274
7331
  for( let entry in data )
7275
7332
  {
@@ -7285,9 +7342,9 @@ class Form extends Widget {
7285
7342
  {
7286
7343
  callback( container.formData, event );
7287
7344
  }
7288
- }, { buttonClass: "primary" } );
7345
+ }, { width: "100%", minWidth: "0", buttonClass: options.primaryButtonClass ?? "contrast" } );
7289
7346
 
7290
- container.appendChild( submitButton.root );
7347
+ buttonContainer.appendChild( primaryButton.root );
7291
7348
  }
7292
7349
  }
7293
7350
 
@@ -10544,9 +10601,7 @@ class DatePicker extends Widget {
10544
10601
  container.innerHTML = "";
10545
10602
  const calendarIcon = LX.makeIcon( "calendar" );
10546
10603
  const calendarButton = new Button( null, currentDate ?? "Pick a date", () => {
10547
- this._popover = new Popover( calendarButton.root, ( popoverRoot ) => {
10548
- popoverRoot.appendChild( this.calendar.root );
10549
- } );
10604
+ this._popover = new Popover( calendarButton.root, [ this.calendar ] );
10550
10605
  }, { buttonClass: `flex flex-row px-3 ${ currentDate ? "" : "fg-tertiary" } justify-between` } );
10551
10606
 
10552
10607
  calendarButton.root.querySelector( "button" ).appendChild( calendarIcon );
@@ -11219,7 +11274,12 @@ class Panel {
11219
11274
  * @param {Object} data Form data
11220
11275
  * @param {Function} callback Callback function on submit form
11221
11276
  * @param {Object} options:
11222
- * actionName: Text to be shown in the button
11277
+ * primaryActionName: Text to be shown in the primary action button ['Submit']
11278
+ * primaryButtonClass: Button class for primary action button ['contrast']
11279
+ * secondaryActionName: Text to be shown in the secondary action button ['Cancel']
11280
+ * secondaryActionCallback: Callback function on press secondary button
11281
+ * secondaryButtonClass: Button class for secondary action button ['primary']
11282
+ * skipLabels: Do not show input field labels [false]
11223
11283
  */
11224
11284
 
11225
11285
  addForm( name, data, callback, options = {} ) {
@@ -12050,7 +12110,6 @@ class Footer {
12050
12110
  parent.appendChild( root );
12051
12111
 
12052
12112
  // Set always at bottom
12053
- root.previousElementSibling.style.height = "unset";
12054
12113
  root.previousElementSibling.style.flexGrow = "1";
12055
12114
 
12056
12115
  this.root = root;
@@ -13446,8 +13505,8 @@ class AssetView {
13446
13505
  div.className = 'lexassetbrowser';
13447
13506
  this.root = div;
13448
13507
 
13449
- let area = new LX.Area({height: "100%"});
13450
- div.appendChild(area.root);
13508
+ let area = new LX.Area( { width: "100%", height: "100%" } );
13509
+ div.appendChild( area.root );
13451
13510
 
13452
13511
  let left, right, contentArea = area;
13453
13512
 
@@ -13460,6 +13519,9 @@ class AssetView {
13460
13519
  this.contextMenu = options.contextMenu ?? [];
13461
13520
  this.onRefreshContent = options.onRefreshContent;
13462
13521
 
13522
+ // Append temporarily to the dom
13523
+ document.body.appendChild( this.root );
13524
+
13463
13525
  if( !this.skipBrowser )
13464
13526
  {
13465
13527
  [left, right] = area.split({ type: "horizontal", sizes: ["15%", "85%"]});
@@ -13497,6 +13559,9 @@ class AssetView {
13497
13559
  {
13498
13560
  this.previewPanel = right.addPanel( {className: 'lexassetcontentpanel', style: { overflow: 'scroll' }} );
13499
13561
  }
13562
+
13563
+ // Clean up
13564
+ document.body.removeChild( this.root );
13500
13565
  }
13501
13566
 
13502
13567
  /**