lexgui 0.1.27 → 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.27",
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
  */
@@ -3848,7 +3952,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
3848
3952
 
3849
3953
  // Add dropdown widget button
3850
3954
  let buttonName = value;
3851
- 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>";
3852
3956
 
3853
3957
  this.queue(container);
3854
3958
 
@@ -3861,7 +3965,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
3861
3965
  let rect = event.currentTarget.getBoundingClientRect();
3862
3966
  let y_pos = container.classList.contains('lexdialog') ? rect.top - 5 + rect.height : rect.y + rect.height - 5;
3863
3967
  element.querySelector(".lexoptions").style.top = y_pos + 'px';
3864
- element.querySelector(".lexoptions").style.width = (event.currentTarget.clientWidth) + 2 + 'px';
3968
+ element.querySelector(".lexoptions").style.width = (event.currentTarget.clientWidth) + 'px';
3865
3969
  element.querySelector(".lexoptions").toggleAttribute('hidden');
3866
3970
  list.focus();
3867
3971
  }, { buttonClass: 'array', skipInlineCount: true });
@@ -3877,24 +3981,24 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
3877
3981
  selectedOption.querySelector("span").innerHTML = selectedOption.querySelector("span").innerHTML.replaceAll(selectedOption.querySelector("span").innerText, v);
3878
3982
  }
3879
3983
 
3880
- //Add dropdown options container
3881
- let list = document.createElement('ul');
3984
+ // Add dropdown options container
3985
+ let list = document.createElement( 'ul' );
3882
3986
  list.tabIndex = -1;
3883
3987
  list.className = "lexoptions";
3884
3988
  list.hidden = true;
3885
3989
 
3886
- list.addEventListener('focusout', function(e) {
3990
+ list.addEventListener( 'focusout', function( e ) {
3887
3991
  e.stopPropagation();
3888
3992
  e.stopImmediatePropagation();
3889
- if(e.relatedTarget === selectedOption.querySelector("button")) {
3993
+ if(e.relatedTarget === selectedOption.querySelector( 'button' )) {
3890
3994
  this.unfocus_event = true;
3891
- setTimeout(() => delete this.unfocus_event, 200);
3892
- } else if (e.relatedTarget && e.relatedTarget.tagName == "INPUT") {
3995
+ setTimeout( () => delete this.unfocus_event, 200 );
3996
+ } else if ( e.relatedTarget && e.relatedTarget.tagName == "INPUT" ) {
3893
3997
  return;
3894
- }else if (e.target.id == 'input-filter') {
3998
+ }else if ( e.target.id == 'input-filter' ) {
3895
3999
  return;
3896
4000
  }
3897
- this.toggleAttribute('hidden', true);
4001
+ this.toggleAttribute( 'hidden', true );
3898
4002
  });
3899
4003
 
3900
4004
  // Add filter options
@@ -4191,7 +4295,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4191
4295
 
4192
4296
  // Add dropdown array button
4193
4297
 
4194
- const itemNameWidth = "3%";
4298
+ const itemNameWidth = "4%";
4195
4299
 
4196
4300
  var container = document.createElement('div');
4197
4301
  container.className = "lexarray";
@@ -4199,7 +4303,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4199
4303
 
4200
4304
  this.queue( container );
4201
4305
 
4202
- 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>`;
4203
4307
 
4204
4308
  let buttonName = "Array (size " + values.length + ")";
4205
4309
  buttonName += angle_down;
@@ -4267,7 +4371,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4267
4371
  }
4268
4372
 
4269
4373
  buttonName = "Add item";
4270
- 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>";
4271
4375
  this.addButton(null, buttonName, (v, event) => {
4272
4376
  values.push( "" );
4273
4377
  updateItems();
@@ -4786,6 +4890,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4786
4890
  doc.addEventListener("mouseup",inner_mouseup);
4787
4891
  lastY = e.pageY;
4788
4892
  document.body.classList.add('nocursor');
4893
+ document.body.classList.add('noevents');
4789
4894
  drag_icon.classList.remove('hidden');
4790
4895
  }
4791
4896
 
@@ -4810,6 +4915,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4810
4915
  doc.removeEventListener("mousemove",inner_mousemove);
4811
4916
  doc.removeEventListener("mouseup",inner_mouseup);
4812
4917
  document.body.classList.remove('nocursor');
4918
+ document.body.classList.remove('noevents');
4813
4919
  drag_icon.classList.add('hidden');
4814
4920
  }
4815
4921
 
@@ -4956,6 +5062,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4956
5062
  doc.addEventListener("mouseup",inner_mouseup);
4957
5063
  lastY = e.pageY;
4958
5064
  document.body.classList.add('nocursor');
5065
+ document.body.classList.add('noevents');
4959
5066
  drag_icon.classList.remove('hidden');
4960
5067
  }
4961
5068
 
@@ -4988,6 +5095,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
4988
5095
  doc.removeEventListener("mousemove",inner_mousemove);
4989
5096
  doc.removeEventListener("mouseup",inner_mouseup);
4990
5097
  document.body.classList.remove('nocursor');
5098
+ document.body.classList.remove('noevents');
4991
5099
  drag_icon.classList.add('hidden');
4992
5100
  }
4993
5101
 
@@ -5717,8 +5825,8 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5717
5825
  this.root = root;
5718
5826
  this.title = titleDiv;
5719
5827
 
5720
- if(draggable)
5721
- makeDraggable( root, 'lexdialogtitle' );
5828
+ if( draggable )
5829
+ makeDraggable( root, { targetClass: 'lexdialogtitle' } );
5722
5830
 
5723
5831
  // Process position and size
5724
5832
  if(size.length && typeof(size[0]) != "string")
@@ -6134,8 +6242,8 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
6134
6242
  element.style.minHeight = "50px";
6135
6243
  element.style.width = options.width || "100%";
6136
6244
 
6137
- element.bgcolor = options.bgcolor || "#15181c";
6138
- 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");
6139
6247
  element.linecolor = options.linecolor || "#555";
6140
6248
 
6141
6249
  element.value = value || [];