lexgui 0.1.17 → 0.1.19

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.
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  var LX = {
11
- version: "0.1.17",
11
+ version: "0.1.19",
12
12
  ready: false,
13
13
  components: [], // specific pre-build components
14
14
  signals: {} // events and triggers
@@ -20,6 +20,13 @@ LX.MOUSE_TRIPLE_CLICK = 3;
20
20
  function clamp (num, min, max) { return Math.min(Math.max(num, min), max) }
21
21
  function round(num, n) { return +num.toFixed(n); }
22
22
 
23
+ function getSupportedDOMName( string )
24
+ {
25
+ return string.replace(/\s/g, '').replaceAll('@', '_').replaceAll('+', '_plus_').replaceAll('.', '');
26
+ }
27
+
28
+ LX.getSupportedDOMName = getSupportedDOMName;
29
+
23
30
  function has( component_name )
24
31
  {
25
32
  return (LX.components.indexOf( component_name ) > -1);
@@ -254,7 +261,16 @@ function create_global_searchbar( root ) {
254
261
  e.stopPropagation();
255
262
  global_search.classList.toggle('hidden');
256
263
  global_search.querySelector('input').focus();
257
- add_elements(undefined);
264
+ add_elements( undefined );
265
+ }
266
+ else
267
+ {
268
+ for( let c of LX.components )
269
+ if( LX[c].prototype.onKeyPressed )
270
+ {
271
+ const instances = LX.CodeEditor.getInstances();
272
+ for( let i of instances ) i.onKeyPressed( e );
273
+ }
258
274
  }
259
275
  });
260
276
 
@@ -339,17 +355,23 @@ function create_global_searchbar( root ) {
339
355
  const instances = LX.CodeEditor.getInstances();
340
356
  if(!instances.length) return;
341
357
 
342
- const languages = Object.keys( instances[0].languages );
358
+ const languages = instances[ 0 ].languages;
359
+
360
+ for( let l of Object.keys( languages ) ) {
361
+
362
+ const key = "Language: " + l;
363
+ const icon = instances[ 0 ]._getFileIcon( null, languages[ l ].ext );
343
364
 
344
- for( let l of languages ) {
365
+ let value = icon.includes( 'fa-' ) ? "<i class='" + icon + "'></i>" :
366
+ "<img src='" + ( "https://raw.githubusercontent.com/jxarco/lexgui.js/master/" + icon ) + "'>";
345
367
 
346
- const key = "Set language: " + l;
347
- if( key.toLowerCase().includes(filter) ) {
348
- add_element(key, () => {
368
+ value += key + " <span class='lang-ext'>(" + languages[ l ].ext + ")</span>";
369
+ if( key.toLowerCase().includes( filter ) ) {
370
+ add_element( value, () => {
349
371
  for( let i of instances ) {
350
372
  i._changeLanguage( l );
351
373
  }
352
- }, "", {});
374
+ }, "", {} );
353
375
  }
354
376
  }
355
377
  }
@@ -1351,14 +1373,14 @@ class Area {
1351
1373
 
1352
1374
  _moveSplit( dt, force_animation = false, force_width = 0 ) {
1353
1375
 
1354
- if(!this.type)
1355
- throw("No split area");
1376
+ if( !this.type )
1377
+ throw( "No split area" );
1356
1378
 
1357
- if(dt === undefined) // splitbar didn't move!
1379
+ if( dt === undefined ) // Splitbar didn't move!
1358
1380
  return;
1359
1381
 
1360
- var a1 = this.sections[0];
1361
- var a2 = this.sections[1];
1382
+ var a1 = this.sections[ 0 ];
1383
+ var a2 = this.sections[ 1 ];
1362
1384
  var splitinfo = " - "+ LX.DEFAULT_SPLITBAR_SIZE + "px";
1363
1385
 
1364
1386
  let transition = null;
@@ -1367,29 +1389,30 @@ class Area {
1367
1389
  // Remove transitions for this change..
1368
1390
  transition = a1.root.style.transition;
1369
1391
  a1.root.style.transition = a2.root.style.transition = "none";
1370
- flushCss(a1.root);
1371
- flushCss(a2.root);
1392
+ flushCss( a1.root );
1393
+ flushCss( a2.root );
1372
1394
  }
1373
1395
 
1374
- if(this.type == "horizontal") {
1375
-
1376
- var size = Math.max(a2.root.offsetWidth + dt, parseInt(a2.minWidth));
1396
+ if( this.type == "horizontal" )
1397
+ {
1398
+ var size = Math.max( a2.root.offsetWidth + dt, parseInt( a2.minWidth ) );
1377
1399
  if( force_width ) size = force_width;
1378
1400
  a1.root.style.width = "-moz-calc( 100% - " + size + "px " + splitinfo + " )";
1379
1401
  a1.root.style.width = "-webkit-calc( 100% - " + size + "px " + splitinfo + " )";
1380
1402
  a1.root.style.width = "calc( 100% - " + size + "px " + splitinfo + " )";
1381
- a1.root.style.minWidth = a1.minWidth + "px";
1382
- a2.root.style.width = size + "px"; //other split
1403
+ a1.root.style.minWidth = parseInt( a1.minWidth ) + "px";
1404
+ a2.root.style.width = size + "px";
1405
+ if( a1.maxWidth != Infinity ) a2.root.style.minWidth = "calc( 100% - " + parseInt( a1.maxWidth ) + "px" + " )";
1383
1406
  }
1384
- else {
1385
-
1407
+ else
1408
+ {
1386
1409
  var size = Math.max((a2.root.offsetHeight + dt) + a2.offset, parseInt(a2.minHeight));
1387
1410
  if( force_width ) size = force_width;
1388
1411
  a1.root.style.height = "-moz-calc( 100% - " + size + "px " + splitinfo + " )";
1389
1412
  a1.root.style.height = "-webkit-calc( 100% - " + size + "px " + splitinfo + " )";
1390
1413
  a1.root.style.height = "calc( 100% - " + size + "px " + splitinfo + " )";
1391
1414
  a1.root.style.minHeight = a1.minHeight + "px";
1392
- a2.root.style.height = ( size - a2.offset ) + "px"; //other split
1415
+ a2.root.style.height = ( size - a2.offset ) + "px";
1393
1416
  }
1394
1417
 
1395
1418
  if( !force_animation )
@@ -1537,11 +1560,23 @@ class Tabs {
1537
1560
  contentEl.style.display = isSelected ? "block" : "none";
1538
1561
  contentEl.classList.add("lextabcontent");
1539
1562
 
1563
+ // Process icon
1564
+ if( options.icon )
1565
+ {
1566
+ if( options.icon.includes( 'fa-' ) ) // It's fontawesome icon...
1567
+ options.icon = "<i class='" + options.icon + "'></i>";
1568
+ else // an image..
1569
+ {
1570
+ const rootPath = "https://raw.githubusercontent.com/jxarco/lexgui.js/master/";
1571
+ options.icon = "<img src='" + ( rootPath + options.icon ) + "'>";
1572
+ }
1573
+ }
1574
+
1540
1575
  // Create tab
1541
1576
  let tabEl = document.createElement('span');
1542
1577
  tabEl.dataset["name"] = name;
1543
1578
  tabEl.className = "lexareatab" + (isSelected ? " selected" : "");
1544
- tabEl.innerHTML = name;
1579
+ tabEl.innerHTML = (options.icon ?? "") + name;
1545
1580
  tabEl.id = name.replace(/\s/g, '') + Tabs.TAB_ID++;
1546
1581
  tabEl.title = options.title;
1547
1582
  tabEl.selected = isSelected ?? false;
@@ -1588,9 +1623,7 @@ class Tabs {
1588
1623
  tabEl.addEventListener("mouseup", e => {
1589
1624
  e.preventDefault();
1590
1625
  e.stopPropagation();
1591
- if(e.button == 1 ) {
1592
- if(this.onclose)
1593
- this.onclose( tabEl.dataset["name"] );
1626
+ if( e.button == 1 ) {
1594
1627
  this.delete( tabEl.dataset["name"] );
1595
1628
  }
1596
1629
  });
@@ -1601,7 +1634,7 @@ class Tabs {
1601
1634
  e.preventDefault();
1602
1635
  return;
1603
1636
  }
1604
- e.dataTransfer.setData("source", e.target.id);
1637
+ e.dataTransfer.setData( "source", e.target.id );
1605
1638
  });
1606
1639
 
1607
1640
  // Attach content
@@ -1630,6 +1663,9 @@ class Tabs {
1630
1663
  if(!tabEl || tabEl.fixed)
1631
1664
  return;
1632
1665
 
1666
+ if( this.onclose )
1667
+ this.onclose( name );
1668
+
1633
1669
  // Delete tab element
1634
1670
  this.tabDOMs[ name ].remove();
1635
1671
  delete this.tabDOMs[ name ];
@@ -2372,22 +2408,33 @@ class NodeTree {
2372
2408
 
2373
2409
  let item = document.createElement('li');
2374
2410
  item.className = "lextreeitem " + "datalevel" + level + (is_parent ? " parent" : "") + (is_selected ? " selected" : "");
2375
- item.id = node.id;
2411
+ item.id = LX.getSupportedDOMName( node.id );
2376
2412
  item.tabIndex = "0";
2377
2413
 
2378
2414
  // Select hierarchy icon
2379
- let icon = "fa-solid fa-square"; // Default: no childs
2415
+ let icon = (this.options.skip_default_icon ?? true) ? "" : "fa-solid fa-square"; // Default: no childs
2380
2416
  if( is_parent ) icon = node.closed ? "fa-solid fa-caret-right" : "fa-solid fa-caret-down";
2381
2417
  item.innerHTML = "<a class='" + icon + " hierarchy'></a>";
2382
2418
 
2383
2419
  // Add display icon
2384
2420
  icon = node.icon;
2385
- if( icon ) item.innerHTML += "<a class='" + icon + "'></a>";
2421
+
2422
+ // Process icon
2423
+ if( node.icon )
2424
+ {
2425
+ if( node.icon.includes( 'fa-' ) ) // It's fontawesome icon...
2426
+ item.innerHTML += "<a class='" + node.icon + " tree-item-icon'></a>";
2427
+ else // an image..
2428
+ {
2429
+ const rootPath = "https://raw.githubusercontent.com/jxarco/lexgui.js/master/";
2430
+ item.innerHTML += "<img src='" + ( rootPath + node.icon ) + "'>";
2431
+ }
2432
+ }
2386
2433
 
2387
2434
  item.innerHTML += (node.rename ? "" : node.id);
2388
2435
 
2389
2436
  item.setAttribute('draggable', true);
2390
- item.style.paddingLeft = ((is_parent ? 0 : 3 ) + (3 + (level+1) * 25)) + "px";
2437
+ item.style.paddingLeft = ((is_parent ? 0 : 3 ) + (3 + (level+1) * 15)) + "px";
2391
2438
  list.appendChild(item);
2392
2439
 
2393
2440
  // Callbacks
@@ -2429,16 +2476,19 @@ class NodeTree {
2429
2476
  }
2430
2477
  });
2431
2478
 
2432
- if( this.options.rename ?? true )
2433
- item.addEventListener("dblclick", function() {
2479
+ item.addEventListener("dblclick", function() {
2480
+ if( that.options.rename ?? true )
2481
+ {
2434
2482
  // Trigger rename
2435
2483
  node.rename = true;
2436
2484
  that.refresh();
2437
- if(that.onevent) {
2438
- const event = new TreeEvent(TreeEvent.NODE_DBLCLICKED, node);
2439
- that.onevent( event );
2440
- }
2441
- });
2485
+ }
2486
+ if( that.onevent )
2487
+ {
2488
+ const event = new TreeEvent(TreeEvent.NODE_DBLCLICKED, node);
2489
+ that.onevent( event );
2490
+ }
2491
+ });
2442
2492
 
2443
2493
  item.addEventListener("contextmenu", e => {
2444
2494
  e.preventDefault();
@@ -2476,7 +2526,7 @@ class NodeTree {
2476
2526
  else if( e.key == "ArrowUp" || e.key == "ArrowDown" ) // Unique or zero selected
2477
2527
  {
2478
2528
  var selected = this.selected.length > 1 ? (e.key == "ArrowUp" ? this.selected.shift() : this.selected.pop()) : this.selected[0];
2479
- var el = this.domEl.querySelector("#" + selected.id);
2529
+ var el = this.domEl.querySelector("#" + LX.getSupportedDOMName( selected.id ) );
2480
2530
  var sibling = e.key == "ArrowUp" ? el.previousSibling : el.nextSibling;
2481
2531
  if( sibling ) sibling.click();
2482
2532
  }
@@ -2504,10 +2554,10 @@ class NodeTree {
2504
2554
  that.onevent( event );
2505
2555
  }
2506
2556
 
2507
- node.id = this.value;
2557
+ node.id = LX.getSupportedDOMName( this.value );
2508
2558
  delete node.rename;
2509
2559
  that.frefresh( node.id );
2510
- list.querySelector("#" + this.value).classList.add('selected');
2560
+ list.querySelector("#" + node.id).classList.add('selected');
2511
2561
  }
2512
2562
  if(e.key == 'Escape') {
2513
2563
  delete node.rename;
@@ -2655,21 +2705,21 @@ class NodeTree {
2655
2705
  }
2656
2706
  }
2657
2707
 
2658
- refresh(newData, selectedId) {
2708
+ refresh( newData, selectedId ) {
2659
2709
  this.data = newData ?? this.data;
2660
- this.domEl.querySelector("ul").innerHTML = "";
2710
+ this.domEl.querySelector( "ul" ).innerHTML = "";
2661
2711
  this._create_item( null, this.data, 0, selectedId );
2662
2712
  }
2663
2713
 
2664
2714
  /* Refreshes the tree and focuses current element */
2665
2715
  frefresh( id ) {
2666
2716
  this.refresh();
2667
- var el = this.domEl.querySelector("#" + id);
2668
- if(el) el.focus();
2717
+ var el = this.domEl.querySelector( "#" + id );
2718
+ if( el ) el.focus();
2669
2719
  }
2670
2720
 
2671
- select(id) {
2672
- this.refresh(null, id);
2721
+ select( id ) {
2722
+ this.refresh( null, id );
2673
2723
  }
2674
2724
  }
2675
2725
 
@@ -5836,7 +5886,7 @@ class ContextMenu {
5836
5886
  const hasSubmenu = o[ k ].length;
5837
5887
  let entry = document.createElement('div');
5838
5888
  entry.className = "lexcontextmenuentry" + (o[ 'className' ] ? " " + o[ 'className' ] : "" );
5839
- entry.id = o.id ?? ("eId" + this._getSupportedDOMName( k ));
5889
+ entry.id = o.id ?? ("eId" + getSupportedDOMName( k ));
5840
5890
  entry.innerHTML = "";
5841
5891
  const icon = o[ 'icon' ];
5842
5892
  if(icon) {
@@ -5983,7 +6033,7 @@ class ContextMenu {
5983
6033
  for( let item of this.items )
5984
6034
  {
5985
6035
  let key = Object.keys(item)[0];
5986
- let pKey = "eId" + this._getSupportedDOMName( key );
6036
+ let pKey = "eId" + getSupportedDOMName( key );
5987
6037
 
5988
6038
  // Item already created
5989
6039
  const id = "#" + (item.id ?? pKey);
@@ -5999,11 +6049,6 @@ class ContextMenu {
5999
6049
 
6000
6050
  this.colors[ token ] = color;
6001
6051
  }
6002
-
6003
- _getSupportedDOMName( key ) {
6004
- return key.replace(/\s/g, '').replaceAll('@', '_').replaceAll('+', '_plus_');
6005
- }
6006
-
6007
6052
  };
6008
6053
 
6009
6054
  LX.ContextMenu = ContextMenu;
package/demo.js CHANGED
@@ -487,7 +487,7 @@ function fillPanel( panel ) {
487
487
  panel.sameLine(2);
488
488
  panel.addFile("Img1", data => { console.log(data) }, {} );
489
489
  panel.addFile("Img2", data => { console.log(data) }, {} );
490
- panel.addDropdown("Best Engine", ["Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot","Godot", "Unity", "Unreal Engine"], "Unity", (value, event) => {
490
+ panel.addDropdown("Best Engine", ["Godot", "Unity", "Unreal Engine"], "Unity", (value, event) => {
491
491
  console.log(value);
492
492
  });
493
493
 
@@ -24,59 +24,53 @@
24
24
  let area = LX.init();
25
25
 
26
26
  // split main area
27
- var [leftArea, rightArea] = area.split({ sizes:["40%","60%"] });
27
+ // var [leftArea, rightArea] = area.split({ sizes:["55%","45%"] });
28
28
 
29
29
  // add canvas to leftArea
30
- var canvas = document.createElement('canvas');
31
- canvas.id = "mycanvas";
32
- canvas.width = leftArea.root.clientWidth;
33
- canvas.height = leftArea.root.clientHeight;
34
- canvas.style.width = "100%";
35
- canvas.style.height = "100%";
36
- leftArea.attach( canvas );
30
+ // var canvas = document.createElement('canvas');
31
+ // canvas.id = "mycanvas";
32
+ // canvas.width = leftArea.root.clientWidth;
33
+ // canvas.height = leftArea.root.clientHeight;
34
+ // canvas.style.width = "100%";
35
+ // canvas.style.height = "100%";
36
+ // leftArea.attach( canvas );
37
37
 
38
38
  // add on resize event to control canvas size
39
- leftArea.onresize = function( bounding ) {
40
- canvas.width = bounding.width;
41
- canvas.height = bounding.height;
42
- };
39
+ // leftArea.onresize = function( bounding ) {
40
+ // canvas.width = bounding.width;
41
+ // canvas.height = bounding.height;
42
+ // };
43
43
 
44
- let editor = new LX.CodeEditor(rightArea, {
44
+ let editor = new LX.CodeEditor(area, {
45
45
  // allow_add_scripts: false,
46
46
  // autocomplete: false,
47
- // disable_edition: true
47
+ // disable_edition: true,
48
+ file_explorer: true
48
49
  });
49
50
 
50
- // editor.loadFile( "../data/test.json" );
51
- // editor.loadFile( "../data/style.css" );
52
- // editor.loadFile( "../data/script.js" );
53
- // editor.loadFile( "../data/engine.cpp" );
54
- editor.loadFile( "../demo.js" );
51
+ editor.loadFile( "../data/test.json" );
52
+ editor.loadFile( "../data/style.css" );
53
+ editor.loadFile( "../data/engine.cpp" );
54
+ editor.loadFile( "../data/script.js" );
55
+ editor.loadFile( "../data/xml_test.xml" );
56
+ editor.loadFile( "../localhost.bat" );
55
57
 
56
- // var button = document.createElement('button');
57
- // button.value = "CLICK ME";
58
- // button.style.width = "100px";
59
- // button.style.height = "100px";
60
- // button.style.position = "absolute";
61
- // button.onclick = editor.processLines.bind(editor);
62
- // document.body.appendChild( button );
58
+ // var ctx = canvas.getContext("2d");
59
+ // ctx.fillStyle = "#b7a9b1";
60
+ // ctx.font = "48px Monospace";
61
+ // ctx.strokeStyle = "#ff1999";
63
62
 
64
- var ctx = canvas.getContext("2d");
65
- ctx.fillStyle = "#b7a9b1";
66
- ctx.font = "48px Monospace";
67
- ctx.strokeStyle = "#ff1999";
68
-
69
- function loop(dt) {
63
+ // function loop(dt) {
70
64
 
71
- var ctx = canvas.getContext("2d");
65
+ // var ctx = canvas.getContext("2d");
72
66
 
73
- ctx.fillRect(0, 0, canvas.width, canvas.height);
74
- ctx.strokeText("Lexgui.js @jxarco", 200, 300);
67
+ // ctx.fillRect(0, 0, canvas.width, canvas.height);
68
+ // ctx.strokeText("Lexgui.js @jxarco", 200, 300);
75
69
 
76
- requestAnimationFrame(loop);
77
- }
70
+ // requestAnimationFrame(loop);
71
+ // }
78
72
 
79
- requestAnimationFrame(loop);
73
+ // requestAnimationFrame(loop);
80
74
 
81
75
  </script>
82
76
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lexgui",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "JS library to create web graphical user interfaces",
5
5
  "type": "module",
6
6
  "main": "./build/lexgui.js",