lexgui 0.1.26 → 0.1.28

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.26",
15
+ version: "0.1.28",
16
16
  ready: false,
17
17
  components: [], // specific pre-build components
18
18
  signals: {} // events and triggers
@@ -142,24 +142,35 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
142
142
  set ( x, y ) { this.x = x; this.y = y; }
143
143
  add ( v, v0 = new vec2() ) { v0.set( this.x + v.x, this.y + v.y ); return v0; }
144
144
  sub ( v, v0 = new vec2() ) { v0.set( this.x - v.x, this.y - v.y ); return v0; }
145
- mul ( v, v0 = new vec2() ) { if( v.constructor == Number ) { v = new vec2(v) } v = v0.set( this.x * v.x, this.y * v.y ); return v0; }
146
- div ( v, v0 = new vec2() ) { v0.set( this.x / v.x, this.y / v.y ); return v0; }
145
+ mul ( v, v0 = new vec2() ) { if( v.constructor == Number ) { v = new vec2( v ) } v0.set( this.x * v.x, this.y * v.y ); return v0; }
146
+ div ( v, v0 = new vec2() ) { if( v.constructor == Number ) { v = new vec2( v ) } v0.set( this.x / v.x, this.y / v.y ); return v0; }
147
147
  };
148
148
 
149
149
  LX.vec2 = vec2;
150
150
 
151
151
  // Other utils
152
152
 
153
- function makeDraggable( domEl, targetClass ) {
153
+ function makeDraggable( domEl, options = { } ) {
154
154
 
155
155
  let offsetX;
156
156
  let offsetY;
157
157
  let currentTarget = null;
158
+ let targetClass = options.targetClass;
159
+
160
+ const moveFunc = (e) => {
161
+ if(!currentTarget) return;
162
+ let left = e.clientX - offsetX;
163
+ let top = e.clientY - offsetY;
164
+ if(left > 3 && (left + domEl.offsetWidth + 6) <= window.innerWidth)
165
+ domEl.style.left = left + 'px';
166
+ if(top > 3 && (top + domEl.offsetHeight + 6) <= window.innerHeight)
167
+ domEl.style.top = top + 'px';
168
+ };
169
+
170
+ let onMove = options.onMove ?? moveFunc;
158
171
 
159
172
  domEl.setAttribute('draggable', true);
160
173
  domEl.addEventListener("mousedown", function(e) {
161
- // e.stopPropagation();
162
- // e.stopImmediatePropagation();
163
174
  currentTarget = (e.target.classList.contains(targetClass) || !targetClass) ? e.target : null;
164
175
  });
165
176
 
@@ -176,23 +187,13 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
176
187
  const rect = e.target.getBoundingClientRect();
177
188
  offsetX = e.clientX - rect.x;
178
189
  offsetY = e.clientY - rect.y;
179
- document.addEventListener("mousemove", moveFunc );
190
+ document.addEventListener("mousemove", onMove );
180
191
  }, false);
181
192
 
182
- const moveFunc = (e) => {
183
- if(!currentTarget) return;
184
- let left = e.clientX - offsetX;
185
- let top = e.clientY - offsetY;
186
- if(left > 3 && (left + domEl.offsetWidth + 6) <= window.innerWidth)
187
- domEl.style.left = left + 'px';
188
- if(top > 3 && (top + domEl.offsetHeight + 6) <= window.innerHeight)
189
- domEl.style.top = top + 'px';
190
- };
191
-
192
193
  document.addEventListener('mouseup', () => {
193
194
  if(currentTarget) {
194
195
  currentTarget = null;
195
- document.removeEventListener("mousemove", moveFunc );
196
+ document.removeEventListener("mousemove", onMove );
196
197
  }
197
198
  });
198
199
  }
@@ -333,15 +334,20 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
333
334
 
334
335
  const propagate_add = ( item, filter, path ) => {
335
336
 
336
- const key = Object.keys(item)[0];
337
- if( (path + key).toLowerCase().includes(filter) ) {
338
- if(item.callback)
339
- add_element(key, item.callback, path, item);
337
+ const key = Object.keys( item )[ 0 ];
338
+ let name = item.name ?? path + key;
339
+ if( name.toLowerCase().includes( filter ) ) {
340
+ if( item.callback )
341
+ add_element( item.name ?? key, item.callback, path, item );
340
342
  }
341
343
 
344
+ // is sidebar..
345
+ if( item.name )
346
+ return;
347
+
342
348
  path += key + " > ";
343
349
 
344
- for( let c of item[key] )
350
+ for( let c of item[ key ] )
345
351
  propagate_add( c, filter, path );
346
352
  };
347
353
 
@@ -351,7 +357,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
351
357
 
352
358
  for( let m of LX.menubars )
353
359
  for( let i of m.items ) {
354
- propagate_add( i, filter, "");
360
+ propagate_add( i, filter, "" );
355
361
  }
356
362
 
357
363
  if( LX.has('CodeEditor') )
@@ -869,7 +875,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
869
875
  }
870
876
 
871
877
  // Create areas
872
- var area1 = new Area({ no_append: true, className: "split" + (options.menubar ? "" : " origin") });
878
+ var area1 = new Area({ no_append: true, className: "split" + (options.menubar || options.sidebar ? "" : " origin") });
873
879
  var area2 = new Area({ no_append: true, className: "split"});
874
880
 
875
881
  area1.parentArea = this;
@@ -1190,16 +1196,11 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
1190
1196
  addMenubar( callback, options = {} ) {
1191
1197
 
1192
1198
  let menubar = new Menubar(options);
1193
- LX.menubars.push( menubar );
1194
1199
 
1195
1200
  if(callback) callback( menubar );
1196
1201
 
1197
- // Hack to get content height
1198
- // let d = document.createElement('div');
1199
- // d.appendChild(menubar.root);
1200
- // document.body.appendChild(d);
1201
- // const height = menubar.root.clientHeight;
1202
- // d.remove();
1202
+ LX.menubars.push( menubar );
1203
+
1203
1204
  const height = 48; // pixels
1204
1205
 
1205
1206
  const [bar, content] = this.split({type: 'vertical', sizes: [height, null], resize: false, menubar: true});
@@ -1209,6 +1210,27 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
1209
1210
  return menubar;
1210
1211
  }
1211
1212
 
1213
+ /**
1214
+ * @method addSidebar
1215
+ * @param {Function} callback Function to fill the sidebar
1216
+ */
1217
+
1218
+ addSidebar( callback, options = {} ) {
1219
+
1220
+ let sidebar = new SideBar( options );
1221
+
1222
+ if( callback ) callback( sidebar );
1223
+
1224
+ LX.menubars.push( sidebar );
1225
+
1226
+ const width = 64; // pixels
1227
+
1228
+ const [bar, content] = this.split( { type: 'horizontal', sizes: [ width, null ], resize: false, sidebar: true } );
1229
+ bar.attach( sidebar );
1230
+ bar.is_sidebar = true;
1231
+ return sidebar;
1232
+ }
1233
+
1212
1234
  /**
1213
1235
  * @method addOverlayButtons
1214
1236
  * @param {Array} buttons Buttons info
@@ -1782,7 +1804,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
1782
1804
  let entry = document.createElement('div');
1783
1805
  entry.className = "lexmenuentry";
1784
1806
  entry.id = pKey;
1785
- entry.innerText = key;
1807
+ entry.innerHTML = "<span>" + key + "</span>";
1786
1808
  if(options.position == "left") {
1787
1809
  this.root.prepend( entry );
1788
1810
  }
@@ -1806,7 +1828,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
1806
1828
  var rect = c.getBoundingClientRect();
1807
1829
  contextmenu.style.left = (isSubMenu ? rect.width : rect.left) + "px";
1808
1830
  // Entries use css to set top relative to parent
1809
- contextmenu.style.top = (isSubMenu ? 0 : rect.bottom) + "px";
1831
+ contextmenu.style.top = (isSubMenu ? 0 : rect.bottom - 4) + "px";
1810
1832
  c.appendChild( contextmenu );
1811
1833
 
1812
1834
  contextmenu.focus();
@@ -1932,11 +1954,16 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
1932
1954
  return;
1933
1955
  }
1934
1956
 
1957
+ // Manage selected
1958
+ this.root.querySelectorAll(".lexmenuentry").forEach( e => e.classList.remove( 'selected' ) );
1959
+ entry.classList.add( "selected" );
1960
+
1935
1961
  this.root.querySelectorAll(".lexcontextmenu").forEach(e => e.remove());
1936
1962
  create_submenu( item, key, entry, -1 );
1937
1963
  });
1938
1964
 
1939
1965
  entry.addEventListener("mouseleave", () => {
1966
+ this.root.querySelectorAll(".lexmenuentry").forEach( e => e.classList.remove( 'selected' ) );
1940
1967
  this.root.querySelectorAll(".lexcontextmenu").forEach(e => e.remove());
1941
1968
  });
1942
1969
  }
@@ -2124,6 +2151,83 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
2124
2151
 
2125
2152
  LX.Menubar = Menubar;
2126
2153
 
2154
+ /**
2155
+ * @class SideBar
2156
+ */
2157
+
2158
+ class SideBar {
2159
+
2160
+ constructor( options = {} ) {
2161
+
2162
+ this.root = document.createElement( 'div' );
2163
+ this.root.className = "lexsidebar";
2164
+
2165
+ this.footer = document.createElement( 'div' );
2166
+ this.footer.className = "lexsidebarfooter";
2167
+ this.root.appendChild( this.footer );
2168
+
2169
+ this.items = [ ];
2170
+ }
2171
+
2172
+ /**
2173
+ * @method add
2174
+ * @param {*} options:
2175
+ * callback: Function to call on each item
2176
+ * bottom: Bool to set item at the bottom as helper button (not selectable)
2177
+ */
2178
+
2179
+ add( key, options = {} ) {
2180
+
2181
+ if( options.constructor == Function )
2182
+ options = { callback: options };
2183
+
2184
+ let pKey = key.replace( /\s/g, '' ).replaceAll( '.', '' );
2185
+
2186
+ if( this.items.findIndex( (v, i) => v.key == pKey ) > -1 )
2187
+ {
2188
+ console.warn( `'${key}' already created in Sidebar` );
2189
+ return;
2190
+ }
2191
+
2192
+ let entry = document.createElement( 'div' );
2193
+ entry.className = "lexsidebarentry";
2194
+ entry.id = pKey;
2195
+ entry.title = key;
2196
+
2197
+ if( options.bottom )
2198
+ {
2199
+ this.footer.appendChild( entry );
2200
+ }else
2201
+ {
2202
+ this.root.appendChild( entry );
2203
+ }
2204
+
2205
+ // Reappend footer in root
2206
+ this.root.appendChild( this.footer );
2207
+
2208
+ let button = document.createElement( 'button' );
2209
+ button.innerHTML = "<i class='"+ (options.icon ?? "") + "'></i>";
2210
+ entry.appendChild( button );
2211
+
2212
+ entry.addEventListener("click", () => {
2213
+
2214
+ const f = options.callback;
2215
+ if( f ) f.call( this, key, entry );
2216
+
2217
+ // Manage selected
2218
+ if( !options.bottom )
2219
+ {
2220
+ this.root.querySelectorAll(".lexsidebarentry").forEach( e => e.classList.remove( 'selected' ) );
2221
+ entry.classList.add( "selected" );
2222
+ }
2223
+ });
2224
+
2225
+ this.items.push( { name: pKey, domEl: entry, callback: options.callback } );
2226
+ }
2227
+ };
2228
+
2229
+ LX.SideBar = SideBar;
2230
+
2127
2231
  /**
2128
2232
  * @class Widget
2129
2233
  */
@@ -3016,6 +3120,9 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
3016
3120
  if( options.width ) {
3017
3121
  element.style.width = element.style.minWidth = options.width;
3018
3122
  }
3123
+ if( options.maxWidth ) {
3124
+ element.style.maxWidth = options.maxWidth;
3125
+ }
3019
3126
  if( options.minWidth ) {
3020
3127
  element.style.minWidth = options.minWidth;
3021
3128
  }
@@ -3845,7 +3952,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
3845
3952
 
3846
3953
  // Add dropdown widget button
3847
3954
  let buttonName = value;
3848
- buttonName += "<a class='fa-solid fa-angle-down' style='float:right; margin-right: 6px;'></a>";
3955
+ buttonName += "<a class='fa-solid fa-angle-down' style='float:right; margin-right: 3px;'></a>";
3849
3956
 
3850
3957
  this.queue(container);
3851
3958
 
@@ -3858,7 +3965,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
3858
3965
  let rect = event.currentTarget.getBoundingClientRect();
3859
3966
  let y_pos = container.classList.contains('lexdialog') ? rect.top - 5 + rect.height : rect.y + rect.height - 5;
3860
3967
  element.querySelector(".lexoptions").style.top = y_pos + 'px';
3861
- element.querySelector(".lexoptions").style.width = (event.currentTarget.clientWidth) + 2 + 'px';
3968
+ element.querySelector(".lexoptions").style.width = (event.currentTarget.clientWidth) + 'px';
3862
3969
  element.querySelector(".lexoptions").toggleAttribute('hidden');
3863
3970
  list.focus();
3864
3971
  }, { buttonClass: 'array', skipInlineCount: true });
@@ -3874,24 +3981,24 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
3874
3981
  selectedOption.querySelector("span").innerHTML = selectedOption.querySelector("span").innerHTML.replaceAll(selectedOption.querySelector("span").innerText, v);
3875
3982
  }
3876
3983
 
3877
- //Add dropdown options container
3878
- let list = document.createElement('ul');
3984
+ // Add dropdown options container
3985
+ let list = document.createElement( 'ul' );
3879
3986
  list.tabIndex = -1;
3880
3987
  list.className = "lexoptions";
3881
3988
  list.hidden = true;
3882
3989
 
3883
- list.addEventListener('focusout', function(e) {
3990
+ list.addEventListener( 'focusout', function( e ) {
3884
3991
  e.stopPropagation();
3885
3992
  e.stopImmediatePropagation();
3886
- if(e.relatedTarget === selectedOption.querySelector("button")) {
3993
+ if(e.relatedTarget === selectedOption.querySelector( 'button' )) {
3887
3994
  this.unfocus_event = true;
3888
- setTimeout(() => delete this.unfocus_event, 200);
3889
- } else if (e.relatedTarget && e.relatedTarget.tagName == "INPUT") {
3995
+ setTimeout( () => delete this.unfocus_event, 200 );
3996
+ } else if ( e.relatedTarget && e.relatedTarget.tagName == "INPUT" ) {
3890
3997
  return;
3891
- }else if (e.target.id == 'input-filter') {
3998
+ }else if ( e.target.id == 'input-filter' ) {
3892
3999
  return;
3893
4000
  }
3894
- this.toggleAttribute('hidden', true);
4001
+ this.toggleAttribute( 'hidden', true );
3895
4002
  });
3896
4003
 
3897
4004
  // Add filter options
@@ -4188,7 +4295,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4188
4295
 
4189
4296
  // Add dropdown array button
4190
4297
 
4191
- const itemNameWidth = "3%";
4298
+ const itemNameWidth = "4%";
4192
4299
 
4193
4300
  var container = document.createElement('div');
4194
4301
  container.className = "lexarray";
@@ -4196,7 +4303,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4196
4303
 
4197
4304
  this.queue( container );
4198
4305
 
4199
- const angle_down = `<a class='fa-solid fa-angle-down' style='float:right; margin-right: 6px;'></a>`;
4306
+ const angle_down = `<a class='fa-solid fa-angle-down' style='float:right; margin-right: 3px;'></a>`;
4200
4307
 
4201
4308
  let buttonName = "Array (size " + values.length + ")";
4202
4309
  buttonName += angle_down;
@@ -4264,7 +4371,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4264
4371
  }
4265
4372
 
4266
4373
  buttonName = "Add item";
4267
- buttonName += "<a class='fa-solid fa-plus' style='float:right; margin-right: 6px; margin-top: 2px;'></a>";
4374
+ buttonName += "<a class='fa-solid fa-plus' style='float:right; margin-right: 3px; margin-top: 2px;'></a>";
4268
4375
  this.addButton(null, buttonName, (v, event) => {
4269
4376
  values.push( "" );
4270
4377
  updateItems();
@@ -4783,6 +4890,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4783
4890
  doc.addEventListener("mouseup",inner_mouseup);
4784
4891
  lastY = e.pageY;
4785
4892
  document.body.classList.add('nocursor');
4893
+ document.body.classList.add('noevents');
4786
4894
  drag_icon.classList.remove('hidden');
4787
4895
  }
4788
4896
 
@@ -4807,6 +4915,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4807
4915
  doc.removeEventListener("mousemove",inner_mousemove);
4808
4916
  doc.removeEventListener("mouseup",inner_mouseup);
4809
4917
  document.body.classList.remove('nocursor');
4918
+ document.body.classList.remove('noevents');
4810
4919
  drag_icon.classList.add('hidden');
4811
4920
  }
4812
4921
 
@@ -4953,6 +5062,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4953
5062
  doc.addEventListener("mouseup",inner_mouseup);
4954
5063
  lastY = e.pageY;
4955
5064
  document.body.classList.add('nocursor');
5065
+ document.body.classList.add('noevents');
4956
5066
  drag_icon.classList.remove('hidden');
4957
5067
  }
4958
5068
 
@@ -4985,6 +5095,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4985
5095
  doc.removeEventListener("mousemove",inner_mousemove);
4986
5096
  doc.removeEventListener("mouseup",inner_mouseup);
4987
5097
  document.body.classList.remove('nocursor');
5098
+ document.body.classList.remove('noevents');
4988
5099
  drag_icon.classList.add('hidden');
4989
5100
  }
4990
5101
 
@@ -5714,8 +5825,8 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5714
5825
  this.root = root;
5715
5826
  this.title = titleDiv;
5716
5827
 
5717
- if(draggable)
5718
- makeDraggable( root, 'lexdialogtitle' );
5828
+ if( draggable )
5829
+ makeDraggable( root, { targetClass: 'lexdialogtitle' } );
5719
5830
 
5720
5831
  // Process position and size
5721
5832
  if(size.length && typeof(size[0]) != "string")
@@ -6131,8 +6242,8 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
6131
6242
  element.style.minHeight = "50px";
6132
6243
  element.style.width = options.width || "100%";
6133
6244
 
6134
- element.bgcolor = options.bgcolor || "#15181c";
6135
- element.pointscolor = options.pointscolor || "#7b8ae2";
6245
+ element.bgcolor = options.bgcolor || LX.getThemeColor("global-dark-background");
6246
+ element.pointscolor = options.pointscolor || LX.getThemeColor("global-selected-light");
6136
6247
  element.linecolor = options.linecolor || "#555";
6137
6248
 
6138
6249
  element.value = value || [];