wunderbaum 0.5.2 → 0.5.3

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/src/wunderbaum.ts CHANGED
@@ -166,7 +166,7 @@ export class Wunderbaum {
166
166
  protected lastClickTime = 0;
167
167
 
168
168
  constructor(options: WunderbaumOptions) {
169
- let opts = (this.options = util.extend(
169
+ const opts = (this.options = util.extend(
170
170
  {
171
171
  id: null,
172
172
  source: null, // URL for GET/PUT, Ajax options, or callback
@@ -220,7 +220,7 @@ export class Wunderbaum {
220
220
  } catch (error) {
221
221
  // We re-raise in the reject handler, but Chrome resets the stack
222
222
  // frame then, so we log it here:
223
- console.error("Exception inside `init(e)` event:", error);
223
+ this.logError("Exception inside `init(e)` event:", error);
224
224
  }
225
225
  })
226
226
  .catch((err) => {
@@ -524,7 +524,7 @@ export class Wunderbaum {
524
524
  el = document.querySelectorAll(".wunderbaum")[el]; // el was an integer: return nth element
525
525
  } else if (typeof el === "string") {
526
526
  // Search all trees for matching ID
527
- for (let treeElem of document.querySelectorAll(".wunderbaum")) {
527
+ for (const treeElem of document.querySelectorAll(".wunderbaum")) {
528
528
  const tree = (<any>treeElem)._wb_tree;
529
529
  if (tree && tree.id === el) {
530
530
  return tree;
@@ -606,7 +606,7 @@ export class Wunderbaum {
606
606
 
607
607
  /** Called on tree (re)init after markup is created, before loading. */
608
608
  protected _initExtensions(): void {
609
- for (let ext of this.extensionList) {
609
+ for (const ext of this.extensionList) {
610
610
  ext.init();
611
611
  }
612
612
  }
@@ -619,9 +619,9 @@ export class Wunderbaum {
619
619
  `Missing or duplicate key: '${key}'.`
620
620
  );
621
621
  this.keyMap.set(key, node);
622
- let rk = node.refKey;
622
+ const rk = node.refKey;
623
623
  if (rk) {
624
- let rks = this.refKeyMap.get(rk); // Set of nodes with this refKey
624
+ const rks = this.refKeyMap.get(rk); // Set of nodes with this refKey
625
625
  if (rks) {
626
626
  rks.add(node);
627
627
  } else {
@@ -654,13 +654,13 @@ export class Wunderbaum {
654
654
  data: any = {}
655
655
  ): any {
656
656
  let res;
657
- let d = util.extend(
657
+ const d = util.extend(
658
658
  {},
659
659
  { tree: this, options: this.options, result: undefined },
660
660
  data
661
661
  );
662
662
 
663
- for (let ext of this.extensionList) {
663
+ for (const ext of this.extensionList) {
664
664
  res = (<any>ext[hook]).call(ext, d);
665
665
  if (res === false) {
666
666
  break;
@@ -979,8 +979,9 @@ export class Wunderbaum {
979
979
  this.clear();
980
980
  this.resizeObserver.disconnect();
981
981
  this.element.innerHTML = "";
982
+
982
983
  // Remove all event handlers
983
- this.element.outerHTML = this.element.outerHTML;
984
+ this.element.outerHTML = this.element.outerHTML; // eslint-disable-line
984
985
  }
985
986
 
986
987
  /**
@@ -1191,10 +1192,10 @@ export class Wunderbaum {
1191
1192
  startNode?: WunderbaumNode | null
1192
1193
  ): WunderbaumNode | null {
1193
1194
  //, visibleOnly) {
1194
- let res: WunderbaumNode | null = null,
1195
- firstNode = this.getFirstChild()!;
1195
+ let res: WunderbaumNode | null = null;
1196
+ const firstNode = this.getFirstChild()!;
1196
1197
 
1197
- let matcher =
1198
+ const matcher =
1198
1199
  typeof match === "string" ? makeNodeTitleStartMatcher(match) : match;
1199
1200
  startNode = startNode || firstNode;
1200
1201
 
@@ -1291,13 +1292,15 @@ export class Wunderbaum {
1291
1292
  res = this._getNextNodeInView(node);
1292
1293
  break;
1293
1294
  case "pageDown":
1294
- const bottomNode = this.getLowestVpNode();
1295
- // this.logDebug(`${where}(${node}) -> ${bottomNode}`);
1295
+ {
1296
+ const bottomNode = this.getLowestVpNode();
1297
+ // this.logDebug(`${where}(${node}) -> ${bottomNode}`);
1296
1298
 
1297
- if (node._rowIdx! < bottomNode._rowIdx!) {
1298
- res = bottomNode;
1299
- } else {
1300
- res = this._getNextNodeInView(node, pageSize);
1299
+ if (node._rowIdx! < bottomNode._rowIdx!) {
1300
+ res = bottomNode;
1301
+ } else {
1302
+ res = this._getNextNodeInView(node, pageSize);
1303
+ }
1301
1304
  }
1302
1305
  break;
1303
1306
  case "pageUp":
@@ -1327,7 +1330,7 @@ export class Wunderbaum {
1327
1330
  name_cb?: NodeStringCallback,
1328
1331
  connectors?: string[]
1329
1332
  ): IterableIterator<string> {
1330
- return this.root.format_iter(name_cb, connectors);
1333
+ yield* this.root.format_iter(name_cb, connectors);
1331
1334
  }
1332
1335
 
1333
1336
  /**
@@ -1392,22 +1395,22 @@ export class Wunderbaum {
1392
1395
  * TYPE: 'title' | 'prefix' | 'expander' | 'checkbox' | 'icon' | undefined
1393
1396
  */
1394
1397
  static getEventInfo(event: Event): WbEventInfo {
1395
- let target = <Element>event.target,
1396
- cl = target.classList,
1397
- parentCol = target.closest("span.wb-col") as HTMLSpanElement,
1398
- node = Wunderbaum.getNode(target),
1399
- tree = node ? node.tree : Wunderbaum.getTree(event),
1400
- res: WbEventInfo = {
1401
- event: <MouseEvent>event,
1402
- canonicalName: util.eventToString(event),
1403
- tree: tree!,
1404
- node: node,
1405
- region: NodeRegion.unknown,
1406
- colDef: undefined,
1407
- colIdx: -1,
1408
- colId: undefined,
1409
- colElem: parentCol,
1410
- };
1398
+ const target = <Element>event.target;
1399
+ const cl = target.classList;
1400
+ const parentCol = target.closest("span.wb-col") as HTMLSpanElement;
1401
+ const node = Wunderbaum.getNode(target);
1402
+ const tree = node ? node.tree : Wunderbaum.getTree(event);
1403
+ const res: WbEventInfo = {
1404
+ event: <MouseEvent>event,
1405
+ canonicalName: util.eventToString(event),
1406
+ tree: tree!,
1407
+ node: node,
1408
+ region: NodeRegion.unknown,
1409
+ colDef: undefined,
1410
+ colIdx: -1,
1411
+ colId: undefined,
1412
+ colElem: parentCol,
1413
+ };
1411
1414
 
1412
1415
  if (cl.contains("wb-title")) {
1413
1416
  res.region = NodeRegion.title;
@@ -1435,7 +1438,7 @@ export class Wunderbaum {
1435
1438
  } else {
1436
1439
  // Somewhere near the title
1437
1440
  if (event.type !== "mousemove" && !(event instanceof KeyboardEvent)) {
1438
- console.warn("getEventInfo(): not found", event, res);
1441
+ tree?.logWarn("getEventInfo(): not found", event, res);
1439
1442
  }
1440
1443
  return res;
1441
1444
  }
@@ -1465,7 +1468,7 @@ export class Wunderbaum {
1465
1468
  * Return true if any node is currently beeing loaded, i.e. a Ajax request is pending.
1466
1469
  */
1467
1470
  isLoading(): boolean {
1468
- var res = false;
1471
+ let res = false;
1469
1472
 
1470
1473
  this.root.visit((n) => {
1471
1474
  // also visit rootNode
@@ -1485,31 +1488,28 @@ export class Wunderbaum {
1485
1488
  /** Log to console if opts.debugLevel >= 4 */
1486
1489
  logDebug(...args: any[]) {
1487
1490
  if (this.options.debugLevel! >= 4) {
1488
- Array.prototype.unshift.call(args, this.toString());
1489
- console.log.apply(console, args);
1491
+ console.log(this.toString(), ...args); // eslint-disable-line no-console
1490
1492
  }
1491
1493
  }
1492
1494
 
1493
1495
  /** Log error to console. */
1494
1496
  logError(...args: any[]) {
1495
1497
  if (this.options.debugLevel! >= 1) {
1496
- Array.prototype.unshift.call(args, this.toString());
1497
- console.error.apply(console, args);
1498
+ console.error(this.toString(), ...args); // eslint-disable-line no-console
1498
1499
  }
1499
1500
  }
1500
1501
 
1501
1502
  /** Log to console if opts.debugLevel >= 3 */
1502
1503
  logInfo(...args: any[]) {
1503
1504
  if (this.options.debugLevel! >= 3) {
1504
- Array.prototype.unshift.call(args, this.toString());
1505
- console.info.apply(console, args);
1505
+ console.info(this.toString(), ...args); // eslint-disable-line no-console
1506
1506
  }
1507
1507
  }
1508
1508
 
1509
1509
  /** @internal */
1510
1510
  logTime(label: string): string {
1511
1511
  if (this.options.debugLevel! >= 4) {
1512
- console.time(this + ": " + label);
1512
+ console.time(this + ": " + label); // eslint-disable-line no-console
1513
1513
  }
1514
1514
  return label;
1515
1515
  }
@@ -1517,15 +1517,14 @@ export class Wunderbaum {
1517
1517
  /** @internal */
1518
1518
  logTimeEnd(label: string): void {
1519
1519
  if (this.options.debugLevel! >= 4) {
1520
- console.timeEnd(this + ": " + label);
1520
+ console.timeEnd(this + ": " + label); // eslint-disable-line no-console
1521
1521
  }
1522
1522
  }
1523
1523
 
1524
1524
  /** Log to console if opts.debugLevel >= 2 */
1525
1525
  logWarn(...args: any[]) {
1526
1526
  if (this.options.debugLevel! >= 2) {
1527
- Array.prototype.unshift.call(args, this.toString());
1528
- console.warn.apply(console, args);
1527
+ console.warn(this.toString(), ...args); // eslint-disable-line no-console
1529
1528
  }
1530
1529
  }
1531
1530
 
@@ -1630,9 +1629,9 @@ export class Wunderbaum {
1630
1629
 
1631
1630
  // Update `wb-active` class for all headers
1632
1631
  if (this.hasHeader()) {
1633
- for (let rowDiv of this.headerElement.children) {
1632
+ for (const rowDiv of this.headerElement.children) {
1634
1633
  let i = 0;
1635
- for (let colDiv of rowDiv.children) {
1634
+ for (const colDiv of rowDiv.children) {
1636
1635
  (colDiv as HTMLElement).classList.toggle("wb-active", i++ === colIdx);
1637
1636
  }
1638
1637
  }
@@ -1641,9 +1640,9 @@ export class Wunderbaum {
1641
1640
  this.activeNode?.update(ChangeType.status);
1642
1641
 
1643
1642
  // Update `wb-active` class for all cell spans
1644
- for (let rowDiv of this.nodeListElement.children) {
1643
+ for (const rowDiv of this.nodeListElement.children) {
1645
1644
  let i = 0;
1646
- for (let colDiv of rowDiv.children) {
1645
+ for (const colDiv of rowDiv.children) {
1647
1646
  (colDiv as HTMLElement).classList.toggle("wb-active", i++ === colIdx);
1648
1647
  }
1649
1648
  }
@@ -1667,15 +1666,6 @@ export class Wunderbaum {
1667
1666
  }
1668
1667
  }
1669
1668
 
1670
- /**
1671
- * @deprecated since v0.3.6: use `update()` instead.
1672
- */
1673
- setModified(change: ChangeType, ...args: any[]): void {
1674
- this.logWarn("setModified() is deprecated: use update() instead.");
1675
- // @ts-ignore
1676
- // (!) TS2556: A spread argument must either have a tuple type or be passed to a rest parameter.
1677
- return this.update.call(this, change, ...args);
1678
- }
1679
1669
  /**
1680
1670
  * Schedule an update request to reflect a tree change.
1681
1671
  * The render operation is async and debounced unless the `immediate` option
@@ -1857,7 +1847,7 @@ export class Wunderbaum {
1857
1847
  util.extend(this.types, types);
1858
1848
  }
1859
1849
  // Convert `TYPE.classes` to a Set
1860
- for (let t of Object.values(this.types) as any) {
1850
+ for (const t of Object.values(this.types) as any) {
1861
1851
  if (t.classes) {
1862
1852
  t.classes = util.toSet(t.classes);
1863
1853
  }
@@ -1900,7 +1890,7 @@ export class Wunderbaum {
1900
1890
  const defaultMinWidth = 4;
1901
1891
  const vpWidth = this.element.clientWidth;
1902
1892
  // Shorten last column width to avoid h-scrollbar
1903
- const FIX_ADJUST_LAST_COL = 2;
1893
+ const FIX_ADJUST_LAST_COL = 0; // 2;
1904
1894
  const columns = this.columns;
1905
1895
  const col0 = columns[0];
1906
1896
 
@@ -1920,9 +1910,9 @@ export class Wunderbaum {
1920
1910
  }
1921
1911
  // Gather width definitions
1922
1912
  this._columnsById = {};
1923
- for (let col of columns) {
1913
+ for (const col of columns) {
1924
1914
  this._columnsById[<string>col.id] = col;
1925
- let cw = col.width;
1915
+ const cw = col.width;
1926
1916
  if (col.id === "*" && col !== col0) {
1927
1917
  throw new Error(
1928
1918
  `Column id '*' must be defined only once: '${col.title}'.`
@@ -1937,7 +1927,7 @@ export class Wunderbaum {
1937
1927
  totalWeight += cw;
1938
1928
  } else if (typeof cw === "string" && cw.endsWith("px")) {
1939
1929
  col._weight = 0;
1940
- let px = parseFloat(cw.slice(0, -2));
1930
+ const px = parseFloat(cw.slice(0, -2));
1941
1931
  if (col._widthPx != px) {
1942
1932
  modified = true;
1943
1933
  col._widthPx = px;
@@ -1953,7 +1943,7 @@ export class Wunderbaum {
1953
1943
  const restPx = Math.max(0, vpWidth - fixedWidth);
1954
1944
  let ofsPx = 0;
1955
1945
 
1956
- for (let col of columns) {
1946
+ for (const col of columns) {
1957
1947
  let minWidth: number;
1958
1948
 
1959
1949
  if (col._weight) {
@@ -2297,10 +2287,9 @@ export class Wunderbaum {
2297
2287
  stopNode: WunderbaumNode,
2298
2288
  siblingOfs = 0,
2299
2289
  skipFirstNode = options.includeSelf === false,
2300
- includeHidden = !!options.includeHidden,
2301
- checkFilter = !includeHidden && this.filterMode === "hide",
2302
2290
  node: WunderbaumNode = options.start || this.root.children![0];
2303
-
2291
+ const includeHidden = !!options.includeHidden;
2292
+ const checkFilter = !includeHidden && this.filterMode === "hide";
2304
2293
  parent = node.parent;
2305
2294
  while (parent) {
2306
2295
  // visit siblings
@@ -2381,8 +2370,8 @@ export class Wunderbaum {
2381
2370
  let children,
2382
2371
  idx,
2383
2372
  parent,
2384
- includeHidden = !!options.includeHidden,
2385
2373
  node = options.start || this.root.children![0];
2374
+ const includeHidden = !!options.includeHidden;
2386
2375
 
2387
2376
  if (options.includeSelf !== false) {
2388
2377
  if (callback(node) === false) {