wunderbaum 0.5.1 → 0.5.2

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.
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * Wunderbaum - util
3
3
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
4
- * v0.5.1, Sat, 16 Sep 2023 19:08:55 GMT (https://github.com/mar10/wunderbaum)
4
+ * v0.5.2, Mon, 09 Oct 2023 18:32:56 GMT (https://github.com/mar10/wunderbaum)
5
5
  */
6
6
  /** @module util */
7
7
  /** Readable names for `MouseEvent.button` */
@@ -756,7 +756,7 @@ var util = /*#__PURE__*/Object.freeze({
756
756
  /*!
757
757
  * Wunderbaum - types
758
758
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
759
- * v0.5.1, Sat, 16 Sep 2023 19:08:55 GMT (https://github.com/mar10/wunderbaum)
759
+ * v0.5.2, Mon, 09 Oct 2023 18:32:56 GMT (https://github.com/mar10/wunderbaum)
760
760
  */
761
761
  /**
762
762
  * Possible values for {@link WunderbaumNode.update()} and {@link Wunderbaum.update()}.
@@ -820,7 +820,7 @@ var NavModeEnum;
820
820
  /*!
821
821
  * Wunderbaum - wb_extension_base
822
822
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
823
- * v0.5.1, Sat, 16 Sep 2023 19:08:55 GMT (https://github.com/mar10/wunderbaum)
823
+ * v0.5.2, Mon, 09 Oct 2023 18:32:56 GMT (https://github.com/mar10/wunderbaum)
824
824
  */
825
825
  class WunderbaumExtension {
826
826
  constructor(tree, id, defaults) {
@@ -1175,7 +1175,7 @@ function throttle(func, wait = 0, options = {}) {
1175
1175
  /*!
1176
1176
  * Wunderbaum - ext-filter
1177
1177
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
1178
- * v0.5.1, Sat, 16 Sep 2023 19:08:55 GMT (https://github.com/mar10/wunderbaum)
1178
+ * v0.5.2, Mon, 09 Oct 2023 18:32:56 GMT (https://github.com/mar10/wunderbaum)
1179
1179
  */
1180
1180
  const START_MARKER = "\uFFF7";
1181
1181
  const END_MARKER = "\uFFF8";
@@ -1342,7 +1342,6 @@ class FilterExtension extends WunderbaumExtension {
1342
1342
  p.setExpanded(true, {
1343
1343
  noAnimation: true,
1344
1344
  noEvents: true,
1345
- scrollIntoView: false,
1346
1345
  });
1347
1346
  p._filterAutoExpanded = true;
1348
1347
  }
@@ -1373,10 +1372,11 @@ class FilterExtension extends WunderbaumExtension {
1373
1372
  * [ext-filter] Re-apply current filter.
1374
1373
  */
1375
1374
  updateFilter() {
1375
+ var _a;
1376
1376
  let tree = this.tree;
1377
1377
  if (tree.filterMode &&
1378
1378
  this.lastFilterArgs &&
1379
- tree.options.filter.autoApply) {
1379
+ ((_a = tree.options.filter) === null || _a === void 0 ? void 0 : _a.autoApply)) {
1380
1380
  this._applyFilterNoUpdate.apply(this, this.lastFilterArgs);
1381
1381
  }
1382
1382
  else {
@@ -1406,15 +1406,14 @@ class FilterExtension extends WunderbaumExtension {
1406
1406
  delete node.match;
1407
1407
  delete node.subMatchCount;
1408
1408
  delete node.titleWithHighlight;
1409
- if (node.subMatchBadge) {
1410
- node.subMatchBadge.remove();
1411
- delete node.subMatchBadge;
1412
- }
1409
+ // if (node.subMatchBadge) {
1410
+ // node.subMatchBadge.remove();
1411
+ // delete node.subMatchBadge;
1412
+ // }
1413
1413
  if (node._filterAutoExpanded && node.expanded) {
1414
1414
  node.setExpanded(false, {
1415
1415
  noAnimation: true,
1416
1416
  noEvents: true,
1417
- scrollIntoView: false,
1418
1417
  });
1419
1418
  }
1420
1419
  delete node._filterAutoExpanded;
@@ -1468,7 +1467,7 @@ function _markFuzzyMatchedChars(text, matches, escapeTitles = true) {
1468
1467
  /*!
1469
1468
  * Wunderbaum - ext-keynav
1470
1469
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
1471
- * v0.5.1, Sat, 16 Sep 2023 19:08:55 GMT (https://github.com/mar10/wunderbaum)
1470
+ * v0.5.2, Mon, 09 Oct 2023 18:32:56 GMT (https://github.com/mar10/wunderbaum)
1472
1471
  */
1473
1472
  const QUICKSEARCH_DELAY = 500;
1474
1473
  class KeynavExtension extends WunderbaumExtension {
@@ -1808,7 +1807,7 @@ class KeynavExtension extends WunderbaumExtension {
1808
1807
  /*!
1809
1808
  * Wunderbaum - ext-logger
1810
1809
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
1811
- * v0.5.1, Sat, 16 Sep 2023 19:08:55 GMT (https://github.com/mar10/wunderbaum)
1810
+ * v0.5.2, Mon, 09 Oct 2023 18:32:56 GMT (https://github.com/mar10/wunderbaum)
1812
1811
  */
1813
1812
  class LoggerExtension extends WunderbaumExtension {
1814
1813
  constructor(tree) {
@@ -1849,7 +1848,7 @@ class LoggerExtension extends WunderbaumExtension {
1849
1848
  /*!
1850
1849
  * Wunderbaum - common
1851
1850
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
1852
- * v0.5.1, Sat, 16 Sep 2023 19:08:55 GMT (https://github.com/mar10/wunderbaum)
1851
+ * v0.5.2, Mon, 09 Oct 2023 18:32:56 GMT (https://github.com/mar10/wunderbaum)
1853
1852
  */
1854
1853
  const DEFAULT_DEBUGLEVEL = 3; // Replaced by rollup script
1855
1854
  /**
@@ -2115,7 +2114,7 @@ function inflateSourceData(source) {
2115
2114
  /*!
2116
2115
  * Wunderbaum - ext-dnd
2117
2116
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
2118
- * v0.5.1, Sat, 16 Sep 2023 19:08:55 GMT (https://github.com/mar10/wunderbaum)
2117
+ * v0.5.2, Mon, 09 Oct 2023 18:32:56 GMT (https://github.com/mar10/wunderbaum)
2119
2118
  */
2120
2119
  const nodeMimeType = "application/x-wunderbaum-node";
2121
2120
  class DndExtension extends WunderbaumExtension {
@@ -2136,6 +2135,7 @@ class DndExtension extends WunderbaumExtension {
2136
2135
  preventRecursion: true,
2137
2136
  preventSameParent: false,
2138
2137
  preventVoidMoves: true,
2138
+ serializeClipboardData: true,
2139
2139
  scroll: true,
2140
2140
  scrollSensitivity: 20,
2141
2141
  // scrollnterval: 50, // Generste event every 50 ms
@@ -2144,13 +2144,13 @@ class DndExtension extends WunderbaumExtension {
2144
2144
  sourceCopyHook: null,
2145
2145
  // Events (drag support)
2146
2146
  dragStart: null,
2147
- dragDrag: null,
2147
+ drag: null,
2148
2148
  dragEnd: null,
2149
2149
  // Events (drop support)
2150
2150
  dragEnter: null,
2151
2151
  dragOver: null,
2152
2152
  dragExpand: null,
2153
- dragDrop: null,
2153
+ drop: null,
2154
2154
  dragLeave: null, // Callback(targetNode, data)
2155
2155
  });
2156
2156
  // public dropMarkerElem?: HTMLElement;
@@ -2313,8 +2313,12 @@ class DndExtension extends WunderbaumExtension {
2313
2313
  delete n.key;
2314
2314
  });
2315
2315
  nodeData._treeId = srcNode.tree.id;
2316
- const json = JSON.stringify(nodeData);
2317
- e.dataTransfer.setData(nodeMimeType, json);
2316
+ if (dndOpts.serializeClipboardData) {
2317
+ if (typeof dndOpts.serializeClipboardData === "function")
2318
+ e.dataTransfer.setData(nodeMimeType, dndOpts.serializeClipboardData(nodeData));
2319
+ else
2320
+ e.dataTransfer.setData(nodeMimeType, JSON.stringify(nodeData));
2321
+ }
2318
2322
  // e.dataTransfer!.setData("text/html", $(node.span).html());
2319
2323
  e.dataTransfer.setData("text/plain", srcNode.title);
2320
2324
  this.srcNode = srcNode;
@@ -2325,13 +2329,19 @@ class DndExtension extends WunderbaumExtension {
2325
2329
  }, 0);
2326
2330
  // --- drag ---
2327
2331
  }
2328
- else if (e.type === "drag") ;
2332
+ else if (e.type === "drag") {
2333
+ if (dndOpts.drag)
2334
+ srcNode._callEvent("dnd.drag", { event: e });
2335
+ // --- dragend ---
2336
+ }
2329
2337
  else if (e.type === "dragend") {
2330
2338
  srcNode.setClass("wb-drag-source", false);
2331
2339
  this.srcNode = null;
2332
2340
  if (this.lastTargetNode) {
2333
2341
  this._leaveNode();
2334
2342
  }
2343
+ if (dndOpts.dragEnd)
2344
+ srcNode._callEvent("dnd.dragEnd", { event: e });
2335
2345
  }
2336
2346
  return true;
2337
2347
  }
@@ -2406,6 +2416,8 @@ class DndExtension extends WunderbaumExtension {
2406
2416
  else if (e.type === "dragover") {
2407
2417
  const viewportY = e.clientY - this.tree.element.offsetTop;
2408
2418
  this.autoScroll(viewportY);
2419
+ if (dndOpts.dragOver)
2420
+ targetNode._callEvent("dnd.dragOver", { event: e });
2409
2421
  const region = this._calcDropRegion(e, this.lastAllowedDropRegions);
2410
2422
  this.lastDropRegion = region;
2411
2423
  if (dndOpts.autoExpandMS > 0 &&
@@ -2427,7 +2439,13 @@ class DndExtension extends WunderbaumExtension {
2427
2439
  return false;
2428
2440
  // --- dragleave ---
2429
2441
  }
2430
- else if (e.type === "dragleave") ;
2442
+ else if (e.type === "dragleave") {
2443
+ // NOTE: we cannot trust this event, since it is always fired,
2444
+ // Instead we remove the marker on dragenter
2445
+ if (dndOpts.dragLeave)
2446
+ targetNode._callEvent("dnd.dragLeave", { event: e });
2447
+ // --- drop ---
2448
+ }
2431
2449
  else if (e.type === "drop") {
2432
2450
  e.stopPropagation(); // prevent browser from opening links?
2433
2451
  this._leaveNode();
@@ -2445,7 +2463,7 @@ class DndExtension extends WunderbaumExtension {
2445
2463
  /*!
2446
2464
  * Wunderbaum - drag_observer
2447
2465
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
2448
- * v0.5.1, Sat, 16 Sep 2023 19:08:55 GMT (https://github.com/mar10/wunderbaum)
2466
+ * v0.5.2, Mon, 09 Oct 2023 18:32:56 GMT (https://github.com/mar10/wunderbaum)
2449
2467
  */
2450
2468
  /**
2451
2469
  * Convert mouse- and touch events to 'dragstart', 'drag', and 'dragstop'.
@@ -2581,7 +2599,7 @@ class DragObserver {
2581
2599
  /*!
2582
2600
  * Wunderbaum - ext-grid
2583
2601
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
2584
- * v0.5.1, Sat, 16 Sep 2023 19:08:55 GMT (https://github.com/mar10/wunderbaum)
2602
+ * v0.5.2, Mon, 09 Oct 2023 18:32:56 GMT (https://github.com/mar10/wunderbaum)
2585
2603
  */
2586
2604
  class GridExtension extends WunderbaumExtension {
2587
2605
  constructor(tree) {
@@ -2618,7 +2636,7 @@ class GridExtension extends WunderbaumExtension {
2618
2636
  /*!
2619
2637
  * Wunderbaum - deferred
2620
2638
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
2621
- * v0.5.1, Sat, 16 Sep 2023 19:08:55 GMT (https://github.com/mar10/wunderbaum)
2639
+ * v0.5.2, Mon, 09 Oct 2023 18:32:56 GMT (https://github.com/mar10/wunderbaum)
2622
2640
  */
2623
2641
  /**
2624
2642
  * Implement a ES6 Promise, that exposes a resolve() and reject() method.
@@ -2671,7 +2689,7 @@ class Deferred {
2671
2689
  /*!
2672
2690
  * Wunderbaum - wunderbaum_node
2673
2691
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
2674
- * v0.5.1, Sat, 16 Sep 2023 19:08:55 GMT (https://github.com/mar10/wunderbaum)
2692
+ * v0.5.2, Mon, 09 Oct 2023 18:32:56 GMT (https://github.com/mar10/wunderbaum)
2675
2693
  */
2676
2694
  /** WunderbaumNode properties that can be passed with source data.
2677
2695
  * (Any other source properties will be stored as `node.data.PROP`.)
@@ -2976,7 +2994,7 @@ class WunderbaumNode {
2976
2994
  async expandAll(flag = true, options) {
2977
2995
  const tree = this.tree;
2978
2996
  const minExpandLevel = this.tree.options.minExpandLevel;
2979
- let { depth = 99, loadLazy, force } = options !== null && options !== void 0 ? options : {};
2997
+ let { depth = 99, loadLazy, force, keepActiveNodeVisible = true, } = options !== null && options !== void 0 ? options : {};
2980
2998
  const expandOpts = {
2981
2999
  scrollIntoView: false,
2982
3000
  force: force,
@@ -3037,6 +3055,9 @@ class WunderbaumNode {
3037
3055
  tree.enableUpdate(true);
3038
3056
  tree.logTimeEnd(tag);
3039
3057
  }
3058
+ if (tree.activeNode && keepActiveNodeVisible) {
3059
+ tree.activeNode.scrollIntoView();
3060
+ }
3040
3061
  }
3041
3062
  /**
3042
3063
  * Find all descendant nodes that match condition (excluding self).
@@ -3381,7 +3402,7 @@ class WunderbaumNode {
3381
3402
  }
3382
3403
  /** Return true if this node has DOM representaion, i.e. is displayed in the viewport. */
3383
3404
  isRadio() {
3384
- return this.checkbox === "radio" || !!this.parent.radiogroup;
3405
+ return !!this.parent.radiogroup || this.getOption("checkbox") === "radio";
3385
3406
  }
3386
3407
  /** Return true if this node has DOM representaion, i.e. is displayed in the viewport. */
3387
3408
  isRendered() {
@@ -3476,7 +3497,7 @@ class WunderbaumNode {
3476
3497
  for (const [key, value] of Object.entries(source)) {
3477
3498
  if (!RESERVED_TREE_SOURCE_KEYS.has(key)) {
3478
3499
  tree.data[key] = value;
3479
- tree.logDebug(`Add source.${key} to tree.data.${key}`);
3500
+ // tree.logDebug(`Add source.${key} to tree.data.${key}`);
3480
3501
  }
3481
3502
  }
3482
3503
  if (tree.options.selectMode === "hier") {
@@ -3664,7 +3685,6 @@ class WunderbaumNode {
3664
3685
  */
3665
3686
  async makeVisible(options) {
3666
3687
  let i, dfd = new Deferred(), deferreds = [], parents = this.getParentList(false, false), len = parents.length, noAnimation = getOption(options, "noAnimation", false), scroll = getOption(options, "scrollIntoView", true);
3667
- // scroll = !(options && options.scrollIntoView === false);
3668
3688
  // Expand bottom-up, so only the top node is animated
3669
3689
  for (i = len - 1; i >= 0; i--) {
3670
3690
  // self.debug("pushexpand" + parents[i]);
@@ -3937,7 +3957,7 @@ class WunderbaumNode {
3937
3957
  }
3938
3958
  else if (TEST_IMG.test(icon)) {
3939
3959
  // Image URL
3940
- iconSpan = elemFromHtml(`<img src="${icon}" class="wb-icon">`);
3960
+ iconSpan = elemFromHtml(`<i class="wb-icon" style="background-image: url('${icon}');">`);
3941
3961
  }
3942
3962
  else {
3943
3963
  // Class name
@@ -3985,7 +4005,6 @@ class WunderbaumNode {
3985
4005
  const tree = this.tree;
3986
4006
  const treeOptions = tree.options;
3987
4007
  const checkbox = this.getOption("checkbox");
3988
- // const checkbox = this.getOption("checkbox") !== false;
3989
4008
  const columns = tree.columns;
3990
4009
  const level = this.getLevel();
3991
4010
  let elem;
@@ -4200,27 +4219,31 @@ class WunderbaumNode {
4200
4219
  rowDiv.classList.add(...typeInfo.classes);
4201
4220
  }
4202
4221
  if (expanderSpan) {
4222
+ let image = null;
4203
4223
  if (this._isLoading) {
4204
- expanderSpan.className = "wb-expander " + iconMap.loading;
4224
+ image = iconMap.loading;
4205
4225
  }
4206
4226
  else if (this.isExpandable(false)) {
4207
4227
  if (this.expanded) {
4208
- expanderSpan.className = "wb-expander " + iconMap.expanderExpanded;
4228
+ image = iconMap.expanderExpanded;
4209
4229
  }
4210
4230
  else {
4211
- expanderSpan.className = "wb-expander " + iconMap.expanderCollapsed;
4231
+ image = iconMap.expanderCollapsed;
4212
4232
  }
4213
4233
  }
4214
4234
  else if (this.lazy && this.children == null) {
4215
- expanderSpan.className = "wb-expander " + iconMap.expanderLazy;
4235
+ image = iconMap.expanderLazy;
4216
4236
  }
4217
- else {
4237
+ if (image == null)
4218
4238
  expanderSpan.classList.add("wb-indent");
4219
- }
4239
+ else if (TEST_IMG.test(image))
4240
+ expanderSpan.style.backgroundImage = `url('${image}')`;
4241
+ else
4242
+ expanderSpan.className = "wb-expander " + image;
4220
4243
  }
4221
4244
  if (checkboxSpan) {
4222
4245
  let cbclass = "wb-checkbox ";
4223
- if (this.parent.radiogroup) {
4246
+ if (this.isRadio()) {
4224
4247
  cbclass += "wb-radio ";
4225
4248
  if (this.selected) {
4226
4249
  cbclass += iconMap.radioChecked;
@@ -4509,7 +4532,7 @@ class WunderbaumNode {
4509
4532
  const updateOpts = { immediate: immediate };
4510
4533
  // const updateOpts = { immediate: !!util.getOption(options, "immediate") };
4511
4534
  this.tree.update(ChangeType.structure, updateOpts);
4512
- if (flag && scrollIntoView !== false) {
4535
+ if (flag && scrollIntoView) {
4513
4536
  const lastChild = this.getLastChild();
4514
4537
  if (lastChild) {
4515
4538
  this.tree.updatePendingModifications();
@@ -4982,7 +5005,7 @@ WunderbaumNode.sequence = 0;
4982
5005
  /*!
4983
5006
  * Wunderbaum - ext-edit
4984
5007
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
4985
- * v0.5.1, Sat, 16 Sep 2023 19:08:55 GMT (https://github.com/mar10/wunderbaum)
5008
+ * v0.5.2, Mon, 09 Oct 2023 18:32:56 GMT (https://github.com/mar10/wunderbaum)
4986
5009
  */
4987
5010
  // const START_MARKER = "\uFFF7";
4988
5011
  class EditExtension extends WunderbaumExtension {
@@ -5278,8 +5301,8 @@ class EditExtension extends WunderbaumExtension {
5278
5301
  * https://github.com/mar10/wunderbaum
5279
5302
  *
5280
5303
  * Released under the MIT license.
5281
- * @version v0.5.1
5282
- * @date Sat, 16 Sep 2023 19:08:55 GMT
5304
+ * @version v0.5.2
5305
+ * @date Mon, 09 Oct 2023 18:32:56 GMT
5283
5306
  */
5284
5307
  // import "./wunderbaum.scss";
5285
5308
  class WbSystemRoot extends WunderbaumNode {
@@ -5565,7 +5588,9 @@ class Wunderbaum {
5565
5588
  node.setActive(true, { event: e });
5566
5589
  }
5567
5590
  if (info.region === NodeRegion.expander) {
5568
- node.setExpanded(!node.isExpanded());
5591
+ node.setExpanded(!node.isExpanded(), {
5592
+ scrollIntoView: options.scrollIntoViewOnExpandClick !== false,
5593
+ });
5569
5594
  }
5570
5595
  else if (info.region === NodeRegion.checkbox) {
5571
5596
  node.toggleSelected();
@@ -7027,17 +7052,15 @@ class Wunderbaum {
7027
7052
  }
7028
7053
  else {
7029
7054
  this.log("_updateViewportImmediately():", pending);
7030
- let height = this.listContainerElement.clientHeight;
7031
- // We cannot get the height for absolute positioned parent, so look at first col
7032
- // let headerHeight = this.headerElement.clientHeight
7033
- // let headerHeight = this.headerElement.children[0].children[0].clientHeight;
7034
- // const headerHeight = this.options.headerHeightPx;
7035
- const headerHeight = this.headerElement.clientHeight; // May be 0
7036
- const wantHeight = this.element.clientHeight - headerHeight - FIX_ADJUST_HEIGHT;
7037
- if (Math.abs(height - wantHeight) > 1.0) {
7038
- // this.log("resize", height, wantHeight);
7039
- this.listContainerElement.style.height = wantHeight + "px";
7040
- height = wantHeight;
7055
+ if (this.options.adjustHeight !== false) {
7056
+ let height = this.listContainerElement.clientHeight;
7057
+ const headerHeight = this.headerElement.clientHeight; // May be 0
7058
+ const wantHeight = this.element.clientHeight - headerHeight - FIX_ADJUST_HEIGHT;
7059
+ if (Math.abs(height - wantHeight) > 1.0) {
7060
+ // this.log("resize", height, wantHeight);
7061
+ this.listContainerElement.style.height = wantHeight + "px";
7062
+ height = wantHeight;
7063
+ }
7041
7064
  }
7042
7065
  // console.profile(`_updateViewportImmediately()`)
7043
7066
  if (pending.has(RF.clearMarkup)) {
@@ -7413,7 +7436,7 @@ class Wunderbaum {
7413
7436
  }
7414
7437
  Wunderbaum.sequence = 0;
7415
7438
  /** Wunderbaum release version number "MAJOR.MINOR.PATCH". */
7416
- Wunderbaum.version = "v0.5.1"; // Set to semver by 'grunt release'
7439
+ Wunderbaum.version = "v0.5.2"; // Set to semver by 'grunt release'
7417
7440
  /** Expose some useful methods of the util.ts module as `Wunderbaum.util`. */
7418
7441
  Wunderbaum.util = util;
7419
7442