wunderbaum 0.1.0 → 0.2.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.
@@ -7,7 +7,7 @@
7
7
  /*!
8
8
  * Wunderbaum - util
9
9
  * Copyright (c) 2021-2022, Martin Wendt. Released under the MIT license.
10
- * v0.1.0, Thu, 10 Nov 2022 13:27:25 GMT (https://github.com/mar10/wunderbaum)
10
+ * v0.2.0, Tue, 17 Jan 2023 19:26:18 GMT (https://github.com/mar10/wunderbaum)
11
11
  */
12
12
  /** @module util */
13
13
  /** Readable names for `MouseEvent.button` */
@@ -713,7 +713,7 @@
713
713
  /*!
714
714
  * Wunderbaum - types
715
715
  * Copyright (c) 2021-2022, Martin Wendt. Released under the MIT license.
716
- * v0.1.0, Thu, 10 Nov 2022 13:27:25 GMT (https://github.com/mar10/wunderbaum)
716
+ * v0.2.0, Tue, 17 Jan 2023 19:26:18 GMT (https://github.com/mar10/wunderbaum)
717
717
  */
718
718
  /** Possible values for `setModified()`. */
719
719
  var ChangeType;
@@ -765,7 +765,7 @@
765
765
  /*!
766
766
  * Wunderbaum - wb_extension_base
767
767
  * Copyright (c) 2021-2022, Martin Wendt. Released under the MIT license.
768
- * v0.1.0, Thu, 10 Nov 2022 13:27:25 GMT (https://github.com/mar10/wunderbaum)
768
+ * v0.2.0, Tue, 17 Jan 2023 19:26:18 GMT (https://github.com/mar10/wunderbaum)
769
769
  */
770
770
  class WunderbaumExtension {
771
771
  constructor(tree, id, defaults) {
@@ -1056,7 +1056,7 @@
1056
1056
  /*!
1057
1057
  * Wunderbaum - ext-filter
1058
1058
  * Copyright (c) 2021-2022, Martin Wendt. Released under the MIT license.
1059
- * v0.1.0, Thu, 10 Nov 2022 13:27:25 GMT (https://github.com/mar10/wunderbaum)
1059
+ * v0.2.0, Tue, 17 Jan 2023 19:26:18 GMT (https://github.com/mar10/wunderbaum)
1060
1060
  */
1061
1061
  const START_MARKER = "\uFFF7";
1062
1062
  const END_MARKER = "\uFFF8";
@@ -1240,16 +1240,12 @@
1240
1240
  }
1241
1241
  /**
1242
1242
  * [ext-filter] Dim or hide nodes.
1243
- *
1244
- * @param {boolean} [options={autoExpand: false, leavesOnly: false}]
1245
1243
  */
1246
1244
  filterNodes(filter, options) {
1247
1245
  return this._applyFilterNoUpdate(filter, false, options);
1248
1246
  }
1249
1247
  /**
1250
1248
  * [ext-filter] Dim or hide whole branches.
1251
- *
1252
- * @param {boolean} [options={autoExpand: false}]
1253
1249
  */
1254
1250
  filterBranches(filter, options) {
1255
1251
  return this._applyFilterNoUpdate(filter, true, options);
@@ -1361,7 +1357,7 @@
1361
1357
  /*!
1362
1358
  * Wunderbaum - ext-keynav
1363
1359
  * Copyright (c) 2021-2022, Martin Wendt. Released under the MIT license.
1364
- * v0.1.0, Thu, 10 Nov 2022 13:27:25 GMT (https://github.com/mar10/wunderbaum)
1360
+ * v0.2.0, Tue, 17 Jan 2023 19:26:18 GMT (https://github.com/mar10/wunderbaum)
1365
1361
  */
1366
1362
  const QUICKSEARCH_DELAY = 500;
1367
1363
  class KeynavExtension extends WunderbaumExtension {
@@ -1388,11 +1384,10 @@
1388
1384
  var _a;
1389
1385
  const ace = (_a = this.tree
1390
1386
  .getActiveColElem()) === null || _a === void 0 ? void 0 : _a.querySelector("input:focus,select:focus");
1391
- console.log(`_isCurInputFocused`, ace);
1392
1387
  return !!ace;
1393
1388
  }
1394
1389
  onKeyEvent(data) {
1395
- const event = data.event, tree = this.tree, opts = data.options, activate = !event.ctrlKey || opts.autoActivate, curInput = this._getEmbeddedInputElem(event.target), navModeOption = opts.navigationModeOption;
1390
+ const event = data.event, tree = this.tree, opts = data.options, activate = !event.ctrlKey || opts.autoActivate, curInput = this._getEmbeddedInputElem(event.target), inputHasFocus = curInput && this._isCurInputFocused(), navModeOption = opts.navigationModeOption;
1396
1391
  // isCellEditMode = tree.navMode === NavigationMode.cellEdit;
1397
1392
  let focusNode, eventName = eventToString(event), node = data.node, handled = true;
1398
1393
  // tree.log(`onKeyEvent: ${eventName}, curInput`, curInput);
@@ -1429,6 +1424,22 @@
1429
1424
  // -----------------------------------------------------------------------
1430
1425
  // --- Row Mode ---
1431
1426
  // -----------------------------------------------------------------------
1427
+ if (inputHasFocus) {
1428
+ // If editing an embedded input control, let the control handle all
1429
+ // keys. Only Enter and Escape should apply / discard, but keep the
1430
+ // keyboard focus.
1431
+ switch (eventName) {
1432
+ case "Enter":
1433
+ curInput.blur();
1434
+ tree.setFocus();
1435
+ break;
1436
+ case "Escape":
1437
+ node.render();
1438
+ tree.setFocus();
1439
+ break;
1440
+ }
1441
+ return;
1442
+ }
1432
1443
  // --- Quick-Search
1433
1444
  if (opts.quicksearch &&
1434
1445
  eventName.length === 1 &&
@@ -1530,6 +1541,11 @@
1530
1541
  if (eventName === "Escape") {
1531
1542
  // Discard changes
1532
1543
  node.render();
1544
+ // Keep cell-nav mode
1545
+ node.logDebug(`Reset focused input`);
1546
+ tree.setFocus();
1547
+ tree.setColumn(tree.activeColIdx);
1548
+ return;
1533
1549
  // } else if (!INPUT_BREAKOUT_KEYS.has(eventName)) {
1534
1550
  }
1535
1551
  else if (eventName !== "Enter") {
@@ -1604,8 +1620,11 @@
1604
1620
  break;
1605
1621
  case "Escape":
1606
1622
  tree.setFocus(); // Blur prev. input if any
1623
+ node.log(`keynav: focus tree...`);
1607
1624
  if (tree.isCellNav() && navModeOption !== NavModeEnum.cell) {
1625
+ node.log(`keynav: setCellNav(false)`);
1608
1626
  tree.setCellNav(false); // row-nav mode
1627
+ tree.setFocus(); //
1609
1628
  handled = true;
1610
1629
  }
1611
1630
  break;
@@ -1678,7 +1697,7 @@
1678
1697
  /*!
1679
1698
  * Wunderbaum - ext-logger
1680
1699
  * Copyright (c) 2021-2022, Martin Wendt. Released under the MIT license.
1681
- * v0.1.0, Thu, 10 Nov 2022 13:27:25 GMT (https://github.com/mar10/wunderbaum)
1700
+ * v0.2.0, Tue, 17 Jan 2023 19:26:18 GMT (https://github.com/mar10/wunderbaum)
1682
1701
  */
1683
1702
  class LoggerExtension extends WunderbaumExtension {
1684
1703
  constructor(tree) {
@@ -1718,7 +1737,7 @@
1718
1737
  /*!
1719
1738
  * Wunderbaum - common
1720
1739
  * Copyright (c) 2021-2022, Martin Wendt. Released under the MIT license.
1721
- * v0.1.0, Thu, 10 Nov 2022 13:27:25 GMT (https://github.com/mar10/wunderbaum)
1740
+ * v0.2.0, Tue, 17 Jan 2023 19:26:18 GMT (https://github.com/mar10/wunderbaum)
1722
1741
  */
1723
1742
  const DEFAULT_DEBUGLEVEL = 4; // Replaced by rollup script
1724
1743
  /**
@@ -1958,7 +1977,7 @@
1958
1977
  /*!
1959
1978
  * Wunderbaum - ext-dnd
1960
1979
  * Copyright (c) 2021-2022, Martin Wendt. Released under the MIT license.
1961
- * v0.1.0, Thu, 10 Nov 2022 13:27:25 GMT (https://github.com/mar10/wunderbaum)
1980
+ * v0.2.0, Tue, 17 Jan 2023 19:26:18 GMT (https://github.com/mar10/wunderbaum)
1962
1981
  */
1963
1982
  const nodeMimeType = "application/x-wunderbaum-node";
1964
1983
  class DndExtension extends WunderbaumExtension {
@@ -2231,7 +2250,7 @@
2231
2250
  /*!
2232
2251
  * Wunderbaum - drag_observer
2233
2252
  * Copyright (c) 2021-2022, Martin Wendt. Released under the MIT license.
2234
- * v0.1.0, Thu, 10 Nov 2022 13:27:25 GMT (https://github.com/mar10/wunderbaum)
2253
+ * v0.2.0, Tue, 17 Jan 2023 19:26:18 GMT (https://github.com/mar10/wunderbaum)
2235
2254
  */
2236
2255
  /**
2237
2256
  * Convert mouse- and touch events to 'dragstart', 'drag', and 'dragstop'.
@@ -2367,7 +2386,7 @@
2367
2386
  /*!
2368
2387
  * Wunderbaum - ext-grid
2369
2388
  * Copyright (c) 2021-2022, Martin Wendt. Released under the MIT license.
2370
- * v0.1.0, Thu, 10 Nov 2022 13:27:25 GMT (https://github.com/mar10/wunderbaum)
2389
+ * v0.2.0, Tue, 17 Jan 2023 19:26:18 GMT (https://github.com/mar10/wunderbaum)
2371
2390
  */
2372
2391
  class GridExtension extends WunderbaumExtension {
2373
2392
  constructor(tree) {
@@ -2404,7 +2423,7 @@
2404
2423
  /*!
2405
2424
  * Wunderbaum - deferred
2406
2425
  * Copyright (c) 2021-2022, Martin Wendt. Released under the MIT license.
2407
- * v0.1.0, Thu, 10 Nov 2022 13:27:25 GMT (https://github.com/mar10/wunderbaum)
2426
+ * v0.2.0, Tue, 17 Jan 2023 19:26:18 GMT (https://github.com/mar10/wunderbaum)
2408
2427
  */
2409
2428
  /**
2410
2429
  * Implement a ES6 Promise, that exposes a resolve() and reject() method.
@@ -2457,7 +2476,7 @@
2457
2476
  /*!
2458
2477
  * Wunderbaum - wunderbaum_node
2459
2478
  * Copyright (c) 2021-2022, Martin Wendt. Released under the MIT license.
2460
- * v0.1.0, Thu, 10 Nov 2022 13:27:25 GMT (https://github.com/mar10/wunderbaum)
2479
+ * v0.2.0, Tue, 17 Jan 2023 19:26:18 GMT (https://github.com/mar10/wunderbaum)
2461
2480
  */
2462
2481
  /** Top-level properties that can be passed with `data`. */
2463
2482
  const NODE_PROPS = new Set([
@@ -3925,6 +3944,19 @@
3925
3944
  this._createIcon(nodeElem, iconSpan, !expanderSpan);
3926
3945
  }
3927
3946
  }
3947
+ // Adjust column width
3948
+ if (opts.resizeCols !== false && !this.isColspan()) {
3949
+ const colElems = rowDiv.querySelectorAll("span.wb-col");
3950
+ let idx = 0;
3951
+ let ofs = 0;
3952
+ for (let colDef of this.tree.columns) {
3953
+ const colElem = colElems[idx];
3954
+ colElem.style.left = `${ofs}px`;
3955
+ colElem.style.width = `${colDef._widthPx}px`;
3956
+ idx++;
3957
+ ofs += colDef._widthPx;
3958
+ }
3959
+ }
3928
3960
  }
3929
3961
  /**
3930
3962
  * Create or update node's markup.
@@ -4396,7 +4428,7 @@
4396
4428
  /*!
4397
4429
  * Wunderbaum - ext-edit
4398
4430
  * Copyright (c) 2021-2022, Martin Wendt. Released under the MIT license.
4399
- * v0.1.0, Thu, 10 Nov 2022 13:27:25 GMT (https://github.com/mar10/wunderbaum)
4431
+ * v0.2.0, Tue, 17 Jan 2023 19:26:18 GMT (https://github.com/mar10/wunderbaum)
4400
4432
  */
4401
4433
  // const START_MARKER = "\uFFF7";
4402
4434
  class EditExtension extends WunderbaumExtension {
@@ -4487,7 +4519,7 @@
4487
4519
  const trigger = this.getPluginOption("trigger");
4488
4520
  // const inputElem =
4489
4521
  // event.target && event.target.closest("input,[contenteditable]");
4490
- // tree.logDebug(`_preprocessKeyEvent: ${eventName}`);
4522
+ // tree.logDebug(`_preprocessKeyEvent: ${eventName}, editing:${this.isEditingTitle()}`);
4491
4523
  // --- Title editing: apply/discard ---
4492
4524
  // if (inputElem) {
4493
4525
  if (this.isEditingTitle()) {
@@ -4691,8 +4723,8 @@
4691
4723
  * https://github.com/mar10/wunderbaum
4692
4724
  *
4693
4725
  * Released under the MIT license.
4694
- * @version v0.1.0
4695
- * @date Thu, 10 Nov 2022 13:27:25 GMT
4726
+ * @version v0.2.0
4727
+ * @date Tue, 17 Jan 2023 19:26:18 GMT
4696
4728
  */
4697
4729
  class WbSystemRoot extends WunderbaumNode {
4698
4730
  constructor(tree) {
@@ -4979,6 +5011,7 @@
4979
5011
  return false;
4980
5012
  }
4981
5013
  if (node && info.colIdx === 0 && node.isExpandable()) {
5014
+ this._callMethod("edit._stopEditTitle");
4982
5015
  node.setExpanded(!node.isExpanded());
4983
5016
  }
4984
5017
  });
@@ -4995,7 +5028,16 @@
4995
5028
  });
4996
5029
  onEvent(this.element, "focusin focusout", (e) => {
4997
5030
  const flag = e.type === "focusin";
5031
+ const targetNode = Wunderbaum.getNode(e);
4998
5032
  this._callEvent("focus", { flag: flag, event: e });
5033
+ if (flag && this.isRowNav() && !this.isEditing()) {
5034
+ if (opts.navigationModeOption === NavModeEnum.row) {
5035
+ targetNode === null || targetNode === void 0 ? void 0 : targetNode.setActive();
5036
+ }
5037
+ else {
5038
+ this.setCellNav();
5039
+ }
5040
+ }
4999
5041
  if (!flag) {
5000
5042
  this._callMethod("edit._stopEditTitle", true, {
5001
5043
  event: e,
@@ -6127,7 +6169,9 @@
6127
6169
  }
6128
6170
  }
6129
6171
  }
6130
- /** Update column headers and width. */
6172
+ /** Update column headers and width.
6173
+ * Return true if at least one column width changed.
6174
+ */
6131
6175
  updateColumns(options) {
6132
6176
  options = Object.assign({ calculateCols: true, updateRows: true }, options);
6133
6177
  const defaultMinWidth = 4;
@@ -6135,6 +6179,8 @@
6135
6179
  const isGrid = this.isGrid();
6136
6180
  // Shorten last column width to avoid h-scrollbar
6137
6181
  const FIX_ADJUST_LAST_COL = 2;
6182
+ const columns = this.columns;
6183
+ const col0 = columns[0];
6138
6184
  let totalWidth = 0;
6139
6185
  let totalWeight = 0;
6140
6186
  let fixedWidth = 0;
@@ -6144,11 +6190,17 @@
6144
6190
  this.setCellNav(false);
6145
6191
  }
6146
6192
  if (options.calculateCols) {
6193
+ if (col0.id !== "*") {
6194
+ throw new Error(`First column must have id '*': got '${col0.id}'`);
6195
+ }
6147
6196
  // Gather width definitions
6148
6197
  this._columnsById = {};
6149
- for (let col of this.columns) {
6198
+ for (let col of columns) {
6150
6199
  this._columnsById[col.id] = col;
6151
6200
  let cw = col.width;
6201
+ if (col.id === "*" && col !== col0) {
6202
+ throw new Error(`Column id '*' must be defined only once: '${col.title}'`);
6203
+ }
6152
6204
  if (!cw || cw === "*") {
6153
6205
  col._weight = 1.0;
6154
6206
  totalWeight += 1.0;
@@ -6167,13 +6219,13 @@
6167
6219
  fixedWidth += px;
6168
6220
  }
6169
6221
  else {
6170
- error(`Invalid column width: ${cw}`);
6222
+ error(`Invalid column width: ${cw} (expected string ending with 'px' or number, e.g. "<num>px" or <int>)`);
6171
6223
  }
6172
6224
  }
6173
6225
  // Share remaining space between non-fixed columns
6174
6226
  const restPx = Math.max(0, vpWidth - fixedWidth);
6175
6227
  let ofsPx = 0;
6176
- for (let col of this.columns) {
6228
+ for (let col of columns) {
6177
6229
  let minWidth;
6178
6230
  if (col._weight) {
6179
6231
  const cmw = col.minWidth;
@@ -6195,7 +6247,7 @@
6195
6247
  col._ofsPx = ofsPx;
6196
6248
  ofsPx += col._widthPx;
6197
6249
  }
6198
- this.columns[this.columns.length - 1]._widthPx -= FIX_ADJUST_LAST_COL;
6250
+ columns[columns.length - 1]._widthPx -= FIX_ADJUST_LAST_COL;
6199
6251
  totalWidth = ofsPx - FIX_ADJUST_LAST_COL;
6200
6252
  }
6201
6253
  // if (this.options.fixedCol) {
@@ -6214,6 +6266,7 @@
6214
6266
  this._updateRows();
6215
6267
  }
6216
6268
  }
6269
+ return modified;
6217
6270
  }
6218
6271
  /** Create/update header markup from `this.columns` definition.
6219
6272
  * @internal
@@ -6298,8 +6351,8 @@
6298
6351
  height = wantHeight;
6299
6352
  }
6300
6353
  // console.profile(`_updateViewportImmediately()`)
6301
- this.updateColumns({ updateRows: false });
6302
- this._updateRows({ newNodesOnly: newNodesOnly });
6354
+ const modified = this.updateColumns({ updateRows: false });
6355
+ this._updateRows({ newNodesOnly: newNodesOnly && !modified });
6303
6356
  // console.profileEnd(`_updateViewportImmediately()`)
6304
6357
  if (this.options.connectTopBreadcrumb) {
6305
6358
  let path = (_a = this.getTopmostVpNode(true)) === null || _a === void 0 ? void 0 : _a.getPath(false, "title", " > ");
@@ -6626,6 +6679,18 @@
6626
6679
  /* ---------------------------------------------------------------------------
6627
6680
  * FILTER
6628
6681
  * -------------------------------------------------------------------------*/
6682
+ /**
6683
+ * [ext-filter] Dim or hide nodes.
6684
+ */
6685
+ filterNodes(filter, options) {
6686
+ return this.extensions.filter.filterNodes(filter, options);
6687
+ }
6688
+ /**
6689
+ * [ext-filter] Dim or hide whole branches.
6690
+ */
6691
+ filterBranches(filter, options) {
6692
+ return this.extensions.filter.filterBranches(filter, options);
6693
+ }
6629
6694
  /**
6630
6695
  * [ext-filter] Reset the filter.
6631
6696
  *
@@ -6653,7 +6718,7 @@
6653
6718
  }
6654
6719
  Wunderbaum.sequence = 0;
6655
6720
  /** Wunderbaum release version number "MAJOR.MINOR.PATCH". */
6656
- Wunderbaum.version = "v0.1.0"; // Set to semver by 'grunt release'
6721
+ Wunderbaum.version = "v0.2.0"; // Set to semver by 'grunt release'
6657
6722
  /** Expose some useful methods of the util.ts module as `Wunderbaum.util`. */
6658
6723
  Wunderbaum.util = util;
6659
6724