lexgui 0.1.11 → 0.1.12

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.
@@ -183,6 +183,7 @@ class CodeEditor {
183
183
 
184
184
  // Code
185
185
 
186
+ this.useAutoComplete = options.autocomplete ?? true;
186
187
  this.highlight = options.highlight ?? 'Plain Text';
187
188
  this.onsave = options.onsave ?? ((code) => { });
188
189
  this.onrun = options.onrun ?? ((code) => { this.runScript(code) });
@@ -203,7 +204,7 @@ class CodeEditor {
203
204
  'End', 'Tab', 'Escape'
204
205
  ];
205
206
  this.keywords = {
206
- 'JavaScript': ['var', 'let', 'const', 'this', 'in', 'of', 'true', 'false', 'new', 'function', 'NaN', 'static', 'class', 'constructor', 'null', 'typeof'],
207
+ 'JavaScript': ['var', 'let', 'const', 'this', 'in', 'of', 'true', 'false', 'new', 'function', 'NaN', 'static', 'class', 'constructor', 'null', 'typeof', 'debugger'],
207
208
  'GLSL': ['true', 'false', 'function', 'int', 'float', 'vec2', 'vec3', 'vec4', 'mat2x2', 'mat3x3', 'mat4x4', 'struct'],
208
209
  'CSS': ['body', 'html', 'canvas', 'div', 'input', 'span', '.'],
209
210
  'WGSL': ['var', 'let', 'true', 'false', 'fn', 'bool', 'u32', 'i32', 'f16', 'f32', 'vec2f', 'vec3f', 'vec4f', 'mat2x2f', 'mat3x3f', 'mat4x4f', 'array', 'atomic', 'struct',
@@ -212,15 +213,23 @@ class CodeEditor {
212
213
  'texture_storage_2d_array', 'texture_storage_3d'],
213
214
  'JSON': []
214
215
  };
216
+ this.utils = {
217
+ 'JavaScript': ['querySelector', 'body', 'addEventListener', 'removeEventListener', 'remove', 'sort', 'filter', 'isNaN', 'parseFloat', 'parseInt'],
218
+ 'GLSL': [],
219
+ 'CSS': [],
220
+ 'WGSL': [],
221
+ 'JSON': []
222
+ };
215
223
  this.builtin = {
216
- 'JavaScript': ['console', 'window', 'navigator'],
224
+ 'JavaScript': ['document', 'console', 'window', 'navigator', 'Object', 'Function', 'Boolean', 'Symbol', 'Error'],
217
225
  'CSS': ['*', '!important'],
218
226
  'GLSL': [],
219
227
  'WGSL': [],
220
228
  'JSON': []
221
229
  };
222
- this.literals = {
223
- 'JavaScript': ['for', 'if', 'else', 'case', 'switch', 'return', 'while', 'continue', 'break', 'do'],
230
+ this.statementsAndDeclarations = {
231
+ 'JavaScript': ['for', 'if', 'else', 'case', 'switch', 'return', 'while', 'continue', 'break', 'do', 'import',
232
+ 'from', 'throw', 'async', 'try', 'catch'],
224
233
  'GLSL': ['for', 'if', 'else', 'return', 'continue', 'break'],
225
234
  'WGSL': ['const','for', 'if', 'else', 'return', 'continue', 'break', 'storage', 'read', 'uniform'],
226
235
  'JSON': [],
@@ -1289,7 +1298,8 @@ class CodeEditor {
1289
1298
 
1290
1299
  // Manage autocomplete
1291
1300
 
1292
- this.showAutoCompleteBox( key, cursor );
1301
+ if( this.useAutoComplete )
1302
+ this.showAutoCompleteBox( key, cursor );
1293
1303
  }
1294
1304
 
1295
1305
  action( key, deleteSelection, fn ) {
@@ -1453,8 +1463,8 @@ class CodeEditor {
1453
1463
  else if( this.builtin[this.highlight] && this.builtin[this.highlight].indexOf(token) > -1 )
1454
1464
  span.classList.add("cm-bln");
1455
1465
 
1456
- else if( this.literals[this.highlight] && this.literals[this.highlight].indexOf(token) > -1 )
1457
- span.classList.add("cm-lit");
1466
+ else if( this.statementsAndDeclarations[this.highlight] && this.statementsAndDeclarations[this.highlight].indexOf(token) > -1 )
1467
+ span.classList.add("cm-std");
1458
1468
 
1459
1469
  else if( this.symbols[this.highlight] && this.symbols[this.highlight].indexOf(token) > -1 )
1460
1470
  span.classList.add("cm-sym");
@@ -1878,7 +1888,7 @@ class CodeEditor {
1878
1888
 
1879
1889
  runScript( code ) {
1880
1890
  var script = document.createElement('script');
1881
- script.type = 'text/javascript';
1891
+ script.type = 'module';
1882
1892
  script.innerHTML = code;
1883
1893
  // script.src = url[i] + ( version ? "?version=" + version : "" );
1884
1894
  script.async = false;
@@ -1921,13 +1931,11 @@ class CodeEditor {
1921
1931
 
1922
1932
  showAutoCompleteBox( key, cursor ) {
1923
1933
 
1924
- // Delimiter.. no autocomplete for this case
1925
- if( key == ' ' )
1926
- return;
1927
-
1928
1934
  const [word, start, end] = this.getWordAtPos( cursor, -1 );
1929
- if(!word.length)
1930
- return;
1935
+ if(key == ' ' || !word.length) {
1936
+ this.hideAutoCompleteBox();
1937
+ return;
1938
+ }
1931
1939
 
1932
1940
  this.autocomplete.innerHTML = ""; // Clear all suggestions
1933
1941
 
@@ -1935,8 +1943,9 @@ class CodeEditor {
1935
1943
 
1936
1944
  // Add language special keys...
1937
1945
  suggestions = suggestions.concat( this.keywords[ this.highlight ] );
1938
- suggestions = suggestions.concat( this.literals[ this.highlight ] );
1946
+ suggestions = suggestions.concat( this.statementsAndDeclarations[ this.highlight ] );
1939
1947
  suggestions = suggestions.concat( this.builtin[ this.highlight ] );
1948
+ suggestions = suggestions.concat( this.utils[ this.highlight ] );
1940
1949
  suggestions = suggestions.concat( Object.keys(this.code.tokens).filter( a => a != word ) );
1941
1950
 
1942
1951
  // Remove single chars and duplicates...
package/build/lexgui.css CHANGED
@@ -2928,7 +2928,7 @@ ul.lexassetscontent {
2928
2928
  .cm-kwd { color: #218cce; } /* keyword */
2929
2929
  .cm-com { color: #5cab5a; } /* comment */
2930
2930
  .cm-typ { color: #36c0b0; } /* type */
2931
- .cm-lit { color: #cf6dcf; } /* literal */
2931
+ .cm-std { color: #cf6dcf; } /* statements & declarations */
2932
2932
  .cm-bln { color: inherit; } /* builtin */
2933
2933
  .cm-dec { color: #b1ce9b; } /* decimal */
2934
2934
  .cm-sym { color: #e7ded2; } /* symbol */
@@ -2938,7 +2938,7 @@ ul.lexassetscontent {
2938
2938
  .cm-kwd.css { color: #e8be53; } /* keyword */
2939
2939
  .cm-com.css { color: #5cab5a; } /* comment */
2940
2940
  .cm-typ.css { color: #b7c3ec; } /* type */
2941
- .cm-lit.css { color: #cf6dcf; } /* literal */
2941
+ .cm-std.css { color: #cf6dcf; } /* statements & declarations */
2942
2942
  .cm-bln.css { color: #2194ce; } /* builtin */
2943
2943
  .cm-dec.css { color: #b1ce9b; } /* decimal */
2944
2944
  .cm-sym.css { color: #f9d620; } /* symbol */
@@ -2948,7 +2948,7 @@ ul.lexassetscontent {
2948
2948
  .cm-kwd.json { color: inherit; } /* keyword */
2949
2949
  .cm-com.json { color: inherit; } /* comment */
2950
2950
  .cm-typ.json { color: inherit; } /* type */
2951
- .cm-lit.json { color: inherit; } /* literal */
2951
+ .cm-std.json { color: inherit; } /* statements & declarations */
2952
2952
  .cm-bln.json { color: inherit; } /* builtin */
2953
2953
  .cm-dec.json { color: #b1ce9b; } /* decimal */
2954
2954
  .cm-sym.json { color: #cf6dcf; } /* symbol */
@@ -2958,7 +2958,7 @@ ul.lexassetscontent {
2958
2958
  .cm-kwd.glsl { color: #2194ce; } /* keyword */
2959
2959
  .cm-com.glsl { color: #5cab5a; } /* comment */
2960
2960
  .cm-typ.glsl { color: #36c0b0; } /* type */
2961
- .cm-lit.glsl { color: #cf6dcf; } /* literal */
2961
+ .cm-std.glsl { color: #cf6dcf; } /* statements & declarations */
2962
2962
  .cm-bln.glsl { color: #cfc159; } /* builtin */
2963
2963
  .cm-dec.glsl { color: #b1ce9b; } /* decimal */
2964
2964
  .cm-sym.glsl { color: #f9cb20; } /* symbol */
@@ -2968,14 +2968,14 @@ ul.lexassetscontent {
2968
2968
  .cm-kwd.wgsl { color: #2194ce; } /* keyword */
2969
2969
  .cm-com.wgsl { color: #5cab5a; } /* comment */
2970
2970
  .cm-typ.wgsl { color: #36c0b0; } /* type */
2971
- .cm-lit.wgsl { color: #cf6dcf; } /* literal */
2971
+ .cm-std.wgsl { color: #cf6dcf; } /* statements & declarations */
2972
2972
  .cm-bln.wgsl { color: #cfc159; } /* builtin */
2973
2973
  .cm-dec.wgsl { color: #b1ce9b; } /* decimal */
2974
2974
  .cm-sym.wgsl { color: #f9cb20; } /* symbol */
2975
2975
  .cm-mtd.wgsl { color: #e0cc68; } /* method */
2976
2976
 
2977
2977
  /* plain color */
2978
- .cm-str.plaintext, .cm-kwd.plaintext, .cm-com.plaintext, .cm-typ.plaintext, .cm-lit.plaintext,
2978
+ .cm-str.plaintext, .cm-kwd.plaintext, .cm-com.plaintext, .cm-typ.plaintext, .cm-std.plaintext,
2979
2979
  .cm-bln.plaintext, .cm-dec.plaintext, .cm-sym.plaintext, .cm-mtd.plaintext { color: inherit; }
2980
2980
 
2981
2981
 
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.11",
15
+ version: "0.1.12",
16
16
  ready: false,
17
17
  components: [], // specific pre-build components
18
18
  signals: {} // events and triggers
@@ -143,7 +143,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
143
143
 
144
144
  // Other utils
145
145
 
146
- function set_as_draggable(domEl) {
146
+ function makeDraggable( domEl, targetClass ) {
147
147
 
148
148
  let offsetX;
149
149
  let offsetY;
@@ -153,7 +153,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
153
153
  domEl.addEventListener("mousedown", function(e) {
154
154
  // e.stopPropagation();
155
155
  // e.stopImmediatePropagation();
156
- currentTarget = e.target.classList.contains('lexdialogtitle') ? e.target : null;
156
+ currentTarget = (e.target.classList.contains(targetClass) || !targetClass) ? e.target : null;
157
157
  });
158
158
 
159
159
  domEl.addEventListener("dragstart", function(e) {
@@ -169,12 +169,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
169
169
  const rect = e.target.getBoundingClientRect();
170
170
  offsetX = e.clientX - rect.x;
171
171
  offsetY = e.clientY - rect.y;
172
- e.dataTransfer.setData('branch_title', e.target.querySelector(".lexdialogtitle").innerText);
173
- e.dataTransfer.setData('dialog_id', e.target.id);
174
-
175
172
  document.addEventListener("mousemove", moveFunc );
176
- console.log("wefwef");
177
-
178
173
  }, false);
179
174
 
180
175
  const moveFunc = (e) => {
@@ -194,6 +189,8 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
194
189
  }
195
190
  });
196
191
  }
192
+
193
+ LX.makeDraggable = makeDraggable;
197
194
 
198
195
  function create_global_searchbar( root ) {
199
196
 
@@ -5626,7 +5623,7 @@ console.warn( 'Script "build/lexgui.js" is depracated and will be removed soon.
5626
5623
  this.title = titleDiv;
5627
5624
 
5628
5625
  if(draggable)
5629
- set_as_draggable(root);
5626
+ makeDraggable( root, 'lexdialogtitle' );
5630
5627
 
5631
5628
  // Process position and size
5632
5629
  if(size.length && typeof(size[0]) != "string")
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  var LX = {
11
- version: "0.1.11",
11
+ version: "0.1.12",
12
12
  ready: false,
13
13
  components: [], // specific pre-build components
14
14
  signals: {} // events and triggers
@@ -139,7 +139,7 @@ LX.vec2 = vec2;
139
139
 
140
140
  // Other utils
141
141
 
142
- function set_as_draggable(domEl) {
142
+ function makeDraggable( domEl, targetClass ) {
143
143
 
144
144
  let offsetX;
145
145
  let offsetY;
@@ -149,7 +149,7 @@ function set_as_draggable(domEl) {
149
149
  domEl.addEventListener("mousedown", function(e) {
150
150
  // e.stopPropagation();
151
151
  // e.stopImmediatePropagation();
152
- currentTarget = e.target.classList.contains('lexdialogtitle') ? e.target : null;
152
+ currentTarget = (e.target.classList.contains(targetClass) || !targetClass) ? e.target : null;
153
153
  });
154
154
 
155
155
  domEl.addEventListener("dragstart", function(e) {
@@ -165,12 +165,7 @@ function set_as_draggable(domEl) {
165
165
  const rect = e.target.getBoundingClientRect();
166
166
  offsetX = e.clientX - rect.x;
167
167
  offsetY = e.clientY - rect.y;
168
- e.dataTransfer.setData('branch_title', e.target.querySelector(".lexdialogtitle").innerText);
169
- e.dataTransfer.setData('dialog_id', e.target.id);
170
-
171
168
  document.addEventListener("mousemove", moveFunc );
172
- console.log("wefwef");
173
-
174
169
  }, false);
175
170
 
176
171
  const moveFunc = (e) => {
@@ -191,6 +186,8 @@ function set_as_draggable(domEl) {
191
186
  });
192
187
  }
193
188
 
189
+ LX.makeDraggable = makeDraggable;
190
+
194
191
  function create_global_searchbar( root ) {
195
192
 
196
193
  let global_search = document.createElement("div");
@@ -5622,7 +5619,7 @@ class Dialog {
5622
5619
  this.title = titleDiv;
5623
5620
 
5624
5621
  if(draggable)
5625
- set_as_draggable(root);
5622
+ makeDraggable( root, 'lexdialogtitle' );
5626
5623
 
5627
5624
  // Process position and size
5628
5625
  if(size.length && typeof(size[0]) != "string")
@@ -42,25 +42,25 @@
42
42
  };
43
43
 
44
44
  let editor = new LX.CodeEditor(rightArea, {
45
- // allow_add_scripts: false
45
+ // allow_add_scripts: false,
46
+ // autocomplete: false
46
47
  });
47
48
 
48
49
  editor.loadFile( "../data/test.json" );
49
50
  editor.loadFile( "../data/style.css" );
50
51
  editor.loadFile( "../data/script.js" );
51
52
 
53
+ var ctx = canvas.getContext("2d");
54
+ ctx.fillStyle = "#b7a9b1";
55
+ ctx.font = "48px Monospace";
56
+ ctx.strokeStyle = "#ff1999";
57
+
52
58
  function loop(dt) {
53
59
 
54
60
  var ctx = canvas.getContext("2d");
55
61
 
56
- ctx.fillStyle = "#b7a9b1";
57
62
  ctx.fillRect(0, 0, canvas.width, canvas.height);
58
-
59
- ctx.font = "48px Monospace";
60
- ctx.fillStyle = "#ff1999";
61
-
62
- const text = "Lexgui.js @jxarco";
63
- ctx.fillText(text, 300, 300);
63
+ ctx.strokeText("Lexgui.js @jxarco", 200, 300);
64
64
 
65
65
  requestAnimationFrame(loop);
66
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lexgui",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "JS library to create web graphical user interfaces",
5
5
  "type": "module",
6
6
  "main": "./build/lexgui.js",