@tuidom/elements 0.2.3 → 0.3.0

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.
@@ -69,7 +69,7 @@ export class EditorPartElement extends TUIElement {
69
69
  */
70
70
  setViews(views, weights) {
71
71
  this.views = [...views];
72
- const raw = weights !== undefined && weights.length === views.length ? [...weights] : [];
72
+ const raw = weights?.length === views.length ? [...weights] : [];
73
73
  this.weightsValue = this.normalizeWeights(raw);
74
74
  this.maximizedIndexValue = null;
75
75
  this.rebuildSashes();
@@ -519,8 +519,9 @@ export class ListViewElement extends ScrollableElement {
519
519
  this.hasCollapsibleRows = hasCollapsible;
520
520
  // Курсор возвращается на прежнюю строку по id; если она пропала (скрыта,
521
521
  // свёрнута под родителя) — на ближайший оставшийся индекс, не прыгая наверх.
522
- if (this.pendingCursorId !== null && this.visibleIndexById.has(this.pendingCursorId)) {
523
- this.cursorIndex = this.visibleIndexById.get(this.pendingCursorId);
522
+ const pendingIndex = this.pendingCursorId !== null ? this.visibleIndexById.get(this.pendingCursorId) : undefined;
523
+ if (pendingIndex !== undefined) {
524
+ this.cursorIndex = pendingIndex;
524
525
  }
525
526
  else if (out.length === 0) {
526
527
  this.cursorIndex = 0;
@@ -584,8 +585,10 @@ export class ListViewElement extends ScrollableElement {
584
585
  * тогда новый последний ребёнок строки встаёт в самый хвост проекции.
585
586
  */
586
587
  isProjectionTail(id) {
587
- // Вызывается при видимом родителе — проекция материализована и непуста.
588
- let cursor = this.visibleRows[this.visibleRows.length - 1];
588
+ // Вызывается при видимом родителе — проекция материализована и непуста,
589
+ // так что ensureProjection здесь просто отдаёт готовый массив.
590
+ const rows = this.ensureProjection();
591
+ let cursor = rows[rows.length - 1];
589
592
  while (cursor) {
590
593
  if (cursor.id === id)
591
594
  return true;
@@ -794,7 +797,7 @@ export class ListViewElement extends ScrollableElement {
794
797
  for (let i = 0; i < count; i++) {
795
798
  const idx = (start + i) % count;
796
799
  const label = rows[idx].label;
797
- if (label !== undefined && label.toLowerCase().startsWith(prefix)) {
800
+ if (label?.toLowerCase().startsWith(prefix) === true) {
798
801
  this.setSelectedIndex(idx);
799
802
  return;
800
803
  }
@@ -802,7 +805,7 @@ export class ListViewElement extends ScrollableElement {
802
805
  }
803
806
  handleExpandOrMoveToChild() {
804
807
  const rows = this.ensureProjection();
805
- const row = rows[this.cursorIndex];
808
+ const row = rows.at(this.cursorIndex);
806
809
  if (!row || !this.rowHasChildren(row.id))
807
810
  return;
808
811
  if (this.collapsedIds.has(row.id)) {
@@ -815,7 +818,7 @@ export class ListViewElement extends ScrollableElement {
815
818
  }
816
819
  handleCollapseOrMoveToParent() {
817
820
  const rows = this.ensureProjection();
818
- const row = rows[this.cursorIndex];
821
+ const row = rows.at(this.cursorIndex);
819
822
  if (!row)
820
823
  return;
821
824
  if (this.rowHasChildren(row.id) && !this.collapsedIds.has(row.id)) {
@@ -832,14 +835,14 @@ export class ListViewElement extends ScrollableElement {
832
835
  }
833
836
  activateCursorRow() {
834
837
  const rows = this.ensureProjection();
835
- const row = rows[this.cursorIndex];
838
+ const row = rows.at(this.cursorIndex);
836
839
  if (!row)
837
840
  return;
838
841
  this.onActivate?.(row.element);
839
842
  }
840
843
  toggleCursorRow() {
841
844
  const rows = this.ensureProjection();
842
- const row = rows[this.cursorIndex];
845
+ const row = rows.at(this.cursorIndex);
843
846
  if (!row || !this.rowHasChildren(row.id))
844
847
  return;
845
848
  this.toggleCollapsed(row.id);
@@ -189,7 +189,7 @@ export class PopupMenuElement extends TUIElement {
189
189
  return true;
190
190
  current = current.getParent();
191
191
  }
192
- return this.child !== null && this.child.menu.ownsElement(target);
192
+ return this.child?.menu.ownsElement(target) === true;
193
193
  }
194
194
  /** Каскадно закрывает всю цепочку открытых подменю. */
195
195
  closeSubmenus() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuidom/elements",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "Experimental terminal UI DOM — widgets: lists, trees, menus, inputs, quick pick. API is unstable.",
6
6
  "license": "MIT",
@@ -28,6 +28,6 @@
28
28
  "./*": "./dist/*.js"
29
29
  },
30
30
  "dependencies": {
31
- "@tuidom/core": "0.2.3"
31
+ "@tuidom/core": "0.3.0"
32
32
  }
33
33
  }