sunrize 1.11.0 → 1.11.1

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.
@@ -10,6 +10,7 @@ const
10
10
  Editor = require ("../Undo/Editor"),
11
11
  UndoManager = require ("../Undo/UndoManager"),
12
12
  _ = require ("../Application/GetText");
13
+ const { height } = require("../Bits/X3DUOM");
13
14
 
14
15
  require ("../Fields");
15
16
 
@@ -36,7 +37,7 @@ module .exports = new class SceneProperties extends Dialog
36
37
 
37
38
  this .tabs .addTextTab ("profile-and-components", _("Profile & Components"));
38
39
  this .tabs .addTextTab ("units", _("Units"));
39
- this .tabs .addTextTab ("meta-data", _("Meta Data"));
40
+ this .tabs .addTextTab ("meta-data", _("Meta Statements"));
40
41
  this .tabs .addTextTab ("world-info", _("World Info"));
41
42
 
42
43
  this .tabs .setup ();
@@ -51,7 +52,7 @@ module .exports = new class SceneProperties extends Dialog
51
52
 
52
53
  // Profile And Components
53
54
 
54
- this .profileAndComponents .table = $("<table></table>") .appendTo (this .profileAndComponents);
55
+ this .profileAndComponents .table = $("<table></table>") .appendTo (this .profileAndComponents) .height ("100%");
55
56
  this .profileAndComponents .table .body = $("<tbody></tbody>") .appendTo (this .profileAndComponents .table);
56
57
  this .profileAndComponents .inputs = { };
57
58
 
@@ -63,7 +64,7 @@ module .exports = new class SceneProperties extends Dialog
63
64
  this .profileAndComponents .inputs .profile = $("<select></select>")
64
65
  .on ("change", () => this .changeProfile ());
65
66
 
66
- this .profileAndComponents .components = $("<div></div>") .css ({ "overflow-y": "auto", "height": "20em" });
67
+ this .profileAndComponents .components = $("<div></div>") .css ({ "overflow-y": "auto" });
67
68
  this .profileAndComponents .components .table = $("<table></table>") .appendTo (this .profileAndComponents .components);
68
69
  this .profileAndComponents .components .body = $("<tbody></tbody>") .appendTo (this .profileAndComponents .components .table);
69
70
 
@@ -79,16 +80,19 @@ module .exports = new class SceneProperties extends Dialog
79
80
  {
80
81
  $("<tr></tr>")
81
82
  .append ($("<td></td>")
83
+ .width ("15px")
82
84
  .append ($("<input></input>")
83
85
  .attr ("type", "checkbox")
84
86
  .attr ("component", component .name)
85
87
  .on ("change", () => this .changeComponents ())))
86
88
  .append ($("<td></td>") .text (component .title))
87
- .append ($("<td></td>") .append ($("<input></input>")
88
- .attr ("component", component .name)
89
- .attr ("level", component .level)
90
- .val (component .level)
91
- .on ("change", () => this .changeComponents ())))
89
+ .append ($("<td></td>")
90
+ .width ("15px")
91
+ .append ($("<input></input>")
92
+ .attr ("component", component .name)
93
+ .attr ("level", component .level)
94
+ .val (component .level)
95
+ .on ("change", () => this .changeComponents ())))
92
96
  .appendTo (this .profileAndComponents .components .body);
93
97
  }
94
98
 
@@ -96,7 +100,9 @@ module .exports = new class SceneProperties extends Dialog
96
100
  .append ($("<th></th>"))
97
101
  .append ($("<td></td>")
98
102
  .append (this .profileAndComponents .inputs .checkbox)
99
- .append ($("<label></label>") .attr ("for", "infer-profile-and-components-checkbox") .text ("Infer Profile and Components from Source")))
103
+ .append ($("<label></label>")
104
+ .attr ("for", "infer-profile-and-components-checkbox")
105
+ .text (_("Infer Profile and Components from Source when Saving"))))
100
106
  .appendTo (this .profileAndComponents .table .body);
101
107
 
102
108
  $("<tr></tr>")
@@ -114,6 +120,7 @@ module .exports = new class SceneProperties extends Dialog
114
120
  this .units .table = $("<table></table>") .appendTo (this .units);
115
121
  this .units .table .head = $("<thead></thead>") .appendTo (this .units .table);
116
122
  this .units .table .body = $("<tbody></tbody>") .appendTo (this .units .table);
123
+ this .units .table .foot = $("<tfoot></tfoot>") .appendTo (this .units .table);
117
124
 
118
125
  this .units .inputs = new Map (Units .map (unit => [unit .category,
119
126
  {
@@ -163,20 +170,60 @@ module .exports = new class SceneProperties extends Dialog
163
170
 
164
171
  this .units .find ("input[category]") .on ("change", event => this .changeUnitValue (event));
165
172
 
173
+ $("<tr></tr>")
174
+ .append ($("<th></th>"))
175
+ .append ($("<th></th>"))
176
+ .append ($("<th></th>"))
177
+ .appendTo (this .units .table .foot);
178
+
166
179
  // Meta Data
167
180
 
168
181
  this .metaData .table = $("<table></table>") .addClass ("sticky-headers") .appendTo (this .metaData);
169
182
  this .metaData .table .head = $("<thead></thead>") .appendTo (this .metaData .table);
170
- this .metaData .table .body = $("<tbody></tbody>") .appendTo (this .metaData .table);
183
+ this .metaData .table .body = $("<tbody></tbody>") .appendTo (this .metaData .table) .sortable ({
184
+ helper (event, tr)
185
+ {
186
+ const
187
+ originals = tr .children (),
188
+ helper = tr .clone ();
189
+
190
+ helper .children () .each (function (index)
191
+ {
192
+ // Set helper cell sizes to match the original sizes.
193
+ $(this)
194
+ .width (originals .eq (index) .width ())
195
+ .css ("padding-top", "2px");
196
+ });
197
+
198
+ return helper;
199
+ },
200
+ update: (event, ui) =>
201
+ {
202
+ this .changeMetaData ();
203
+ },
204
+ });
205
+ this .metaData .table .foot = $("<tfoot></tfoot>") .appendTo (this .metaData .table);
171
206
 
172
207
  $("<tr></tr>")
173
- .append ($("<th></th>") .css ("width", "30%") .text (_("Key")))
174
- .append ($("<th></th>") .css ("width", "70%") .text (_("Value")))
208
+ .append ($("<th></th>") .css ("width", "15px"))
209
+ .append ($("<th></th>")
210
+ .addClass ("button")
211
+ .css ("width", "25%")
212
+ .append ($("<span></span>") .text (_("Key")))
213
+ .append ($("<span></span>")
214
+ .attr ("title", "Sort column alphabetically.")
215
+ .addClass (["material-icons", "sort-key"])
216
+ .addClass (this .config .file .sortMetaData ? ["active"] : [ ])
217
+ .css ("font-size", "inherit")
218
+ .text ("sort_by_alpha"))
219
+ .on ("click", (event) => this .sortMetaData (event)))
220
+ .append ($("<th></th>") .css ("width", "auto") .text (_("Value")))
221
+ .append ($("<th></th>") .css ("width", "15px"))
175
222
  .appendTo (this .metaData .table .head);
176
223
 
177
224
  // World Info
178
225
 
179
- this .worldInfo .table = $("<table></table>") .appendTo (this .worldInfo);
226
+ this .worldInfo .table = $("<table></table>") .height ("100%") .appendTo (this .worldInfo);
180
227
  this .worldInfo .table .body = $("<tbody></tbody>") .appendTo (this .worldInfo .table);
181
228
  this .worldInfo .inputs = { };
182
229
 
@@ -186,16 +233,18 @@ module .exports = new class SceneProperties extends Dialog
186
233
  .on ("click", () => this .toggleWorldInfo ());
187
234
 
188
235
  this .worldInfo .inputs .title = $("<input></input>");
189
- this .worldInfo .inputs .info = $("<textarea></textarea>");
236
+ this .worldInfo .inputs .info = $("<textarea></textarea>") .height ("100%") .css ("resize", "none");
190
237
 
191
238
  this .worldInfo .checkboxRow = $("<tr></tr>")
192
- .append ($("<th></th>"))
239
+ .height ("19.5px")
240
+ .append ($("<th></th>") .css ("width", "20%"))
193
241
  .append ($("<td></td>")
194
242
  .append (this .worldInfo .inputs .checkbox)
195
- .append ($("<label></label>") .attr ("for", "world-info-checkbox") .text ("World Info")))
243
+ .append ($("<label></label>") .attr ("for", "world-info-checkbox") .text (_("World Info"))))
196
244
  .appendTo (this .worldInfo .table .body);
197
245
 
198
246
  $("<tr></tr>")
247
+ .height ("19.5px")
199
248
  .append ($("<th></th>") .text (_("Title")))
200
249
  .append ($("<td></td>") .append (this .worldInfo .inputs .title))
201
250
  .appendTo (this .worldInfo .table .body);
@@ -210,6 +259,12 @@ module .exports = new class SceneProperties extends Dialog
210
259
  {
211
260
  super .configure ({ size: [600, 400] });
212
261
 
262
+ this .config .file .setDefaultValues ({
263
+ sortMetaData: false,
264
+ });
265
+
266
+ this .updateMetaDataSort ()
267
+
213
268
  if (this .executionContext)
214
269
  this .onclose ();
215
270
 
@@ -363,48 +418,111 @@ module .exports = new class SceneProperties extends Dialog
363
418
  Editor .updateUnit (this .executionContext, category, name .val (), conversionFactor .val ());
364
419
  }
365
420
 
421
+ sortMetaData (event)
422
+ {
423
+ event .preventDefault ();
424
+ event .stopPropagation ();
425
+
426
+ this .config .file .sortMetaData = !this .config .file .sortMetaData;
427
+
428
+ this .updateMetaDataSort ();
429
+ this .updateMetaData ();
430
+ }
431
+
432
+ updateMetaDataSort ()
433
+ {
434
+ this .metaData .table .head .find (".sort-key")
435
+ .removeClass ("active")
436
+ .addClass (this .config .file .sortMetaData ? ["active"] : [ ])
437
+
438
+ if (this .config .file .sortMetaData)
439
+ this .metaData .table .body .sortable ("disable");
440
+ else
441
+ this .metaData .table .body .sortable ("enable");
442
+ }
443
+
366
444
  updateMetaData ()
367
445
  {
368
446
  const
369
447
  scrollTop = this .metaData .table .scrollTop (),
370
- scrollLeft = this .metaData .table .scrollLeft ();
448
+ scrollLeft = this .metaData .table .scrollLeft (),
449
+ focusInput = this .metaData .table .body .find ("input:focus"),
450
+ focusRow = focusInput .closest ("tr");
371
451
 
372
452
  this .metaData .table .body .empty ();
373
453
 
374
- const metaData = Array .from (this .executionContext .getMetaDatas ())
375
- .sort ((a, b) => Algorithm .cmp (a [0], b [0]));
454
+ const
455
+ metaData = Array .from (this .executionContext .getMetaDatas ()),
456
+ rows = [ ];
376
457
 
377
- for (const [key, values] of metaData)
458
+ for (const [index, [key, value]] of metaData .entries ())
378
459
  {
379
- for (const value of values)
380
- {
381
- $("<tr></tr>")
382
- .append ($("<td></td>")
383
- .css ("width", "unset")
384
- .append ($("<input></input>")
460
+ const row = $("<tr></tr>")
461
+ .attr ("index", index)
462
+ .append ($("<td></td>")
463
+ .append ($("<span></span>")
464
+ .attr ("title", _("Drag to move key/value pair."))
465
+ .css ("font-size", "120%")
466
+ .addClass (["material-icons", "button", "drag"])
467
+ .addClass (this .config .file .sortMetaData ? ["disabled"] : [ ])
468
+ .text ("drag_handle")))
469
+ .append ($("<td></td>")
470
+ .append ($("<input></input>")
471
+ .attr ("index", 0)
385
472
  .attr ("placeholder", _("Insert meta key here."))
386
473
  .val (key) .on ("change", (event) => this .changeMetaData (event, key))))
387
- .append ($("<td></td>")
388
- .css ("width", "unset")
389
- .append ($("<input></input>")
474
+ .append ($("<td></td>")
475
+ .append ($("<input></input>")
476
+ .attr ("index", 1)
390
477
  .attr ("placeholder", _("Insert meta value here."))
391
- .val (value) .on ("change", (event) => this .changeMetaData (event, key))))
392
- .appendTo (this .metaData .table);
393
- }
478
+ .val (value)
479
+ .on ("change", (event) => this .changeMetaData (event, key))))
480
+ .append ($("<td></td>")
481
+ .append ($("<span></span>")
482
+ .attr ("title", _("Delete key/value pair."))
483
+ .css ("font-size", "120%")
484
+ .addClass (["material-icons", "button"])
485
+ .text ("delete_forever")
486
+ .on ("click", (event) => this .removeMetaData (event, key))));
487
+
488
+ rows .push (row);
489
+ }
490
+
491
+ if (this .config .file .sortMetaData)
492
+ {
493
+ rows .sort ((a, b) =>
494
+ {
495
+ const
496
+ keyA = $($(a) .find ("input") .get (0)) .val () ?? "",
497
+ keyB = $($(b) .find ("input") .get (0)) .val () ?? "";
498
+
499
+ return keyA .localeCompare (keyB);
500
+ });
501
+ }
502
+
503
+ this .metaData .table .body .append (rows);
504
+
505
+ if (focusInput .length)
506
+ {
507
+ const input = $(this .metaData .table .body
508
+ .find (`tr[index=${focusRow .attr ("index")}] input`)
509
+ .get (focusInput .attr ("index")));
510
+
511
+ input .focus ();
394
512
  }
395
513
 
396
514
  $("<tr></tr>")
515
+ .append ($("<td></td>"))
397
516
  .append ($("<td></td>")
398
- .css ("width", "unset")
399
517
  .append ($("<input></input>")
400
- .attr ("placeholder", _("Add new meta key."))
401
- .on ("change", event => this .changeMetaData (event, ""))))
518
+ .attr ("placeholder", _("Add new meta key."))
519
+ .on ("change", event => this .changeMetaData (event, ""))))
402
520
  .append ($("<td></td>")
403
- .css ("width", "unset")
404
521
  .append ($("<input></input>")
405
- .prop ("readonly", true)
406
- .on ("change", event => this .changeMetaData (event, ""))))
407
- .appendTo (this .metaData .table);
522
+ .prop ("readonly", true)
523
+ .on ("change", event => this .changeMetaData (event, ""))))
524
+ .append ($("<td></td>"))
525
+ .appendTo (this .metaData .table .foot .empty ());
408
526
 
409
527
  this .metaData .table .scrollTop (scrollTop);
410
528
  this .metaData .table .scrollLeft (scrollLeft);
@@ -412,32 +530,53 @@ module .exports = new class SceneProperties extends Dialog
412
530
 
413
531
  changeMetaData (event, oldKey)
414
532
  {
415
- const
416
- inputs = $(event .target) .closest ("tr") .find ("input"),
417
- key = $(inputs .get (0));
533
+ let metaData = Array .from (this .metaData .table .find ("tr"));
418
534
 
419
- if (key .val ())
420
- UndoManager .shared .beginUndo (_("Change Meta Data »%s«"), key .val ());
535
+ if (arguments .length === 2)
536
+ {
537
+ const
538
+ inputs = $(event .target) .closest ("tr") .find ("input"),
539
+ key = $(inputs .get (0)) .val () ?.trim ();
540
+
541
+ if (key)
542
+ UndoManager .shared .beginUndo (_("Change Meta Data »%s«"), key);
543
+ else
544
+ UndoManager .shared .beginUndo (_("Remove Meta Data »%s«"), oldKey);
545
+
546
+ metaData .sort ((a, b) => $(a) .attr ("index") - $(b) .attr ("index"));
547
+ }
421
548
  else
422
- UndoManager .shared .beginUndo (_("Remove Meta Data »%s«"), oldKey);
549
+ {
550
+ UndoManager .shared .beginUndo (_("Reorder Meta Data"));
551
+ }
423
552
 
424
- const metaData = Array .from (this .metaData .table .find ("tr")) .map (element =>
553
+ metaData = metaData .map (element =>
425
554
  {
426
555
  const
427
556
  inputs = $(element) .find ("input"),
428
557
  key = $(inputs .get (0)),
429
558
  value = $(inputs .get (1));
430
559
 
431
- return [key .val (), value .val ()];
560
+ return [key .val () ?.trim (), value .val () ?.trim ()];
432
561
  })
433
- .filter (([key]) => key)
434
- .sort ((a, b) => Algorithm .cmp (a [0], b [0]));
562
+ .filter (([key]) => key);
435
563
 
436
564
  Editor .setMetaData (this .executionContext, metaData);
437
565
 
438
566
  UndoManager .shared .endUndo ();
439
567
  }
440
568
 
569
+ removeMetaData (event, oldKey)
570
+ {
571
+ const
572
+ inputs = $(event .target) .closest ("tr") .find ("input"),
573
+ key = $(inputs .get (0));
574
+
575
+ key .val ("");
576
+
577
+ this .changeMetaData (event, oldKey);
578
+ }
579
+
441
580
  updateWorldInfo ()
442
581
  {
443
582
  if (this .worldInfoNode)
@@ -815,17 +815,11 @@ ${scene .toXMLString ({ html: true, indent: " " .repeat (6) }) .trimEnd () }
815
815
  */
816
816
  static setMetaData (scene, entries, undoManager = UndoManager .shared)
817
817
  {
818
- const oldEntries = [ ];
819
-
820
- for (const [key, values] of scene .getMetaDatas ())
821
- {
822
- for (const value of values)
823
- oldEntries .push ([key, value]);
824
- }
818
+ const oldEntries = scene .getMetaDatas ();
825
819
 
826
820
  undoManager .beginUndo (_("Change Meta Data"));
827
821
 
828
- for (const key of Array .from (scene .getMetaDatas () .keys ()))
822
+ for (const [key] of scene .getMetaDatas ())
829
823
  scene .removeMetaData (key);
830
824
 
831
825
  for (const [key, value] of entries)