wunderbaum 0.9.0 → 0.10.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.
@@ -294,7 +294,7 @@
294
294
  /*!
295
295
  * Wunderbaum - util
296
296
  * Copyright (c) 2021-2024, Martin Wendt. Released under the MIT license.
297
- * v0.9.0, Sun, 05 May 2024 16:08:56 GMT (https://github.com/mar10/wunderbaum)
297
+ * v0.10.1, Sat, 20 Jul 2024 13:53:46 GMT (https://github.com/mar10/wunderbaum)
298
298
  */
299
299
  /** @module util */
300
300
  /** Readable names for `MouseEvent.button` */
@@ -770,7 +770,7 @@
770
770
  function isArray(obj) {
771
771
  return Array.isArray(obj);
772
772
  }
773
- /** Return true if `obj` is of type `Object` and has no propertied. */
773
+ /** Return true if `obj` is of type `Object` and has no properties. */
774
774
  function isEmptyObject(obj) {
775
775
  return Object.keys(obj).length === 0 && obj.constructor === Object;
776
776
  }
@@ -943,6 +943,54 @@
943
943
  }
944
944
  throw new Error("Cannot convert to Set<string>: " + val);
945
945
  }
946
+ /** Convert a pixel string to number.
947
+ * We accept a number or a string like '123px'. If undefined, the first default
948
+ * value that is a number or a string ending with 'px' is returned.
949
+ *
950
+ * Example:
951
+ * ```js
952
+ * let x = undefined;
953
+ * let y = "123px";
954
+ * const width = util.toPixel(x, y, 100); // returns 123
955
+ * ```
956
+ */
957
+ function toPixel(
958
+ // val: string | number | undefined | null,
959
+ ...defaults) {
960
+ // if (typeof val === "number") {
961
+ // return val;
962
+ // }
963
+ for (const d of defaults) {
964
+ if (typeof d === "number") {
965
+ return d;
966
+ }
967
+ if (typeof d === "string" && d.endsWith("px")) {
968
+ return parseInt(d, 10);
969
+ }
970
+ assert(d == null, `Expected a number or string like '123px': ${d}`);
971
+ }
972
+ throw new Error(`Expected a string like '123px': ${defaults}`);
973
+ }
974
+ /** Return the the boolean value of the first non-null element.
975
+ * Example:
976
+ * ```js
977
+ * const opts = { flag: true };
978
+ * const value = util.toBool(opts.foo, opts.flag, false); // returns true
979
+ * ```
980
+ */
981
+ function toBool(
982
+ // val: boolean | undefined | null,
983
+ ...boolDefaults) {
984
+ // if (val != null) {
985
+ // return !!val;
986
+ // }
987
+ for (const d of boolDefaults) {
988
+ if (d != null) {
989
+ return !!d;
990
+ }
991
+ }
992
+ throw new Error("No default boolean value provided");
993
+ }
946
994
  // /** Check if a string is contained in an Array or Set. */
947
995
  // export function isAnyOf(s: string, items: Array<string>|Set<string>): boolean {
948
996
  // return Array.prototype.includes.call(items, s)
@@ -1084,6 +1132,8 @@
1084
1132
  setValueToElem: setValueToElem,
1085
1133
  sleep: sleep,
1086
1134
  throttle: throttle,
1135
+ toBool: toBool,
1136
+ toPixel: toPixel,
1087
1137
  toSet: toSet,
1088
1138
  toggleCheckbox: toggleCheckbox,
1089
1139
  type: type
@@ -1092,7 +1142,7 @@
1092
1142
  /*!
1093
1143
  * Wunderbaum - types
1094
1144
  * Copyright (c) 2021-2024, Martin Wendt. Released under the MIT license.
1095
- * v0.9.0, Sun, 05 May 2024 16:08:56 GMT (https://github.com/mar10/wunderbaum)
1145
+ * v0.10.1, Sat, 20 Jul 2024 13:53:46 GMT (https://github.com/mar10/wunderbaum)
1096
1146
  */
1097
1147
  /**
1098
1148
  * Possible values for {@link WunderbaumNode.update()} and {@link Wunderbaum.update()}.
@@ -1156,7 +1206,7 @@
1156
1206
  /*!
1157
1207
  * Wunderbaum - wb_extension_base
1158
1208
  * Copyright (c) 2021-2024, Martin Wendt. Released under the MIT license.
1159
- * v0.9.0, Sun, 05 May 2024 16:08:56 GMT (https://github.com/mar10/wunderbaum)
1209
+ * v0.10.1, Sat, 20 Jul 2024 13:53:46 GMT (https://github.com/mar10/wunderbaum)
1160
1210
  */
1161
1211
  class WunderbaumExtension {
1162
1212
  constructor(tree, id, defaults) {
@@ -1215,7 +1265,7 @@
1215
1265
  /*!
1216
1266
  * Wunderbaum - ext-filter
1217
1267
  * Copyright (c) 2021-2024, Martin Wendt. Released under the MIT license.
1218
- * v0.9.0, Sun, 05 May 2024 16:08:56 GMT (https://github.com/mar10/wunderbaum)
1268
+ * v0.10.1, Sat, 20 Jul 2024 13:53:46 GMT (https://github.com/mar10/wunderbaum)
1219
1269
  */
1220
1270
  const START_MARKER = "\uFFF7";
1221
1271
  const END_MARKER = "\uFFF8";
@@ -1242,6 +1292,7 @@
1242
1292
  const connectInput = this.getPluginOption("connectInput");
1243
1293
  if (connectInput) {
1244
1294
  this.queryInput = elemFromSelector(connectInput);
1295
+ assert(this.queryInput, `Invalid 'filter.connectInput' option: ${connectInput}.`);
1245
1296
  onEvent(this.queryInput, "input", debounce((e) => {
1246
1297
  // this.tree.log("query", e);
1247
1298
  this.filterNodes(this.queryInput.value.trim(), {});
@@ -1539,7 +1590,7 @@
1539
1590
  /*!
1540
1591
  * Wunderbaum - ext-keynav
1541
1592
  * Copyright (c) 2021-2024, Martin Wendt. Released under the MIT license.
1542
- * v0.9.0, Sun, 05 May 2024 16:08:56 GMT (https://github.com/mar10/wunderbaum)
1593
+ * v0.10.1, Sat, 20 Jul 2024 13:53:46 GMT (https://github.com/mar10/wunderbaum)
1543
1594
  */
1544
1595
  const QUICKSEARCH_DELAY = 500;
1545
1596
  class KeynavExtension extends WunderbaumExtension {
@@ -1903,7 +1954,7 @@
1903
1954
  /*!
1904
1955
  * Wunderbaum - ext-logger
1905
1956
  * Copyright (c) 2021-2024, Martin Wendt. Released under the MIT license.
1906
- * v0.9.0, Sun, 05 May 2024 16:08:56 GMT (https://github.com/mar10/wunderbaum)
1957
+ * v0.10.1, Sat, 20 Jul 2024 13:53:46 GMT (https://github.com/mar10/wunderbaum)
1907
1958
  */
1908
1959
  class LoggerExtension extends WunderbaumExtension {
1909
1960
  constructor(tree) {
@@ -1945,7 +1996,7 @@
1945
1996
  /*!
1946
1997
  * Wunderbaum - common
1947
1998
  * Copyright (c) 2021-2024, Martin Wendt. Released under the MIT license.
1948
- * v0.9.0, Sun, 05 May 2024 16:08:56 GMT (https://github.com/mar10/wunderbaum)
1999
+ * v0.10.1, Sat, 20 Jul 2024 13:53:46 GMT (https://github.com/mar10/wunderbaum)
1949
2000
  */
1950
2001
  const DEFAULT_DEBUGLEVEL = 3; // Replaced by rollup script
1951
2002
  /**
@@ -1963,6 +2014,8 @@
1963
2014
  const TITLE_SPAN_PAD_Y = 7;
1964
2015
  /** Render row markup for N nodes above and below the visible viewport. */
1965
2016
  const RENDER_MAX_PREFETCH = 5;
2017
+ /** Minimum column width if not set otherwise. */
2018
+ const DEFAULT_MIN_COL_WIDTH = 4;
1966
2019
  /** Regular expression to detect if a string describes an image URL (in contrast
1967
2020
  * to a class name). Strings are considered image urls if they contain '.' or '/'.
1968
2021
  */
@@ -2268,7 +2321,7 @@
2268
2321
  /*!
2269
2322
  * Wunderbaum - ext-dnd
2270
2323
  * Copyright (c) 2021-2024, Martin Wendt. Released under the MIT license.
2271
- * v0.9.0, Sun, 05 May 2024 16:08:56 GMT (https://github.com/mar10/wunderbaum)
2324
+ * v0.10.1, Sat, 20 Jul 2024 13:53:46 GMT (https://github.com/mar10/wunderbaum)
2272
2325
  */
2273
2326
  const nodeMimeType = "application/x-wunderbaum-node";
2274
2327
  class DndExtension extends WunderbaumExtension {
@@ -2713,7 +2766,7 @@
2713
2766
  /*!
2714
2767
  * Wunderbaum - drag_observer
2715
2768
  * Copyright (c) 2021-2024, Martin Wendt. Released under the MIT license.
2716
- * v0.9.0, Sun, 05 May 2024 16:08:56 GMT (https://github.com/mar10/wunderbaum)
2769
+ * v0.10.1, Sat, 20 Jul 2024 13:53:46 GMT (https://github.com/mar10/wunderbaum)
2717
2770
  */
2718
2771
  /**
2719
2772
  * Convert mouse- and touch events to 'dragstart', 'drag', and 'dragstop'.
@@ -2721,6 +2774,7 @@
2721
2774
  class DragObserver {
2722
2775
  constructor(opts) {
2723
2776
  this.start = {
2777
+ event: null,
2724
2778
  x: 0,
2725
2779
  y: 0,
2726
2780
  altKey: false,
@@ -2730,6 +2784,7 @@
2730
2784
  };
2731
2785
  this.dragElem = null;
2732
2786
  this.dragging = false;
2787
+ this.customData = {};
2733
2788
  // TODO: touch events
2734
2789
  this.events = ["mousedown", "mouseup", "mousemove", "keydown"];
2735
2790
  if (!opts.root) {
@@ -2757,22 +2812,32 @@
2757
2812
  stopDrag(cb_event) {
2758
2813
  if (this.dragging && this.opts.dragstop && cb_event) {
2759
2814
  cb_event.type = "dragstop";
2760
- this.opts.dragstop(cb_event);
2815
+ try {
2816
+ this.opts.dragstop(cb_event);
2817
+ }
2818
+ catch (err) {
2819
+ console.error("dragstop error", err); // eslint-disable-line no-console
2820
+ }
2761
2821
  }
2762
2822
  this.dragElem = null;
2763
2823
  this.dragging = false;
2824
+ this.start.event = null;
2825
+ this.customData = {};
2764
2826
  }
2765
2827
  handleEvent(e) {
2766
2828
  const type = e.type;
2767
2829
  const opts = this.opts;
2768
2830
  const cb_event = {
2769
2831
  type: e.type,
2832
+ startEvent: type === "mousedown" ? e : this.start.event,
2770
2833
  event: e,
2834
+ customData: this.customData,
2771
2835
  dragElem: this.dragElem,
2772
2836
  dx: e.pageX - this.start.x,
2773
2837
  dy: e.pageY - this.start.y,
2774
2838
  apply: undefined,
2775
2839
  };
2840
+ // console.log("handleEvent", type, cb_event);
2776
2841
  switch (type) {
2777
2842
  case "keydown":
2778
2843
  this.stopDrag(cb_event);
@@ -2797,6 +2862,7 @@
2797
2862
  }
2798
2863
  }
2799
2864
  }
2865
+ this.start.event = e;
2800
2866
  this.start.x = e.pageX;
2801
2867
  this.start.y = e.pageY;
2802
2868
  this.start.altKey = e.altKey;
@@ -2849,7 +2915,7 @@
2849
2915
  /*!
2850
2916
  * Wunderbaum - ext-grid
2851
2917
  * Copyright (c) 2021-2024, Martin Wendt. Released under the MIT license.
2852
- * v0.9.0, Sun, 05 May 2024 16:08:56 GMT (https://github.com/mar10/wunderbaum)
2918
+ * v0.10.1, Sat, 20 Jul 2024 13:53:46 GMT (https://github.com/mar10/wunderbaum)
2853
2919
  */
2854
2920
  class GridExtension extends WunderbaumExtension {
2855
2921
  constructor(tree) {
@@ -2858,11 +2924,43 @@
2858
2924
  });
2859
2925
  this.observer = new DragObserver({
2860
2926
  root: window.document,
2861
- selector: "span.wb-col-resizer",
2927
+ selector: "span.wb-col-resizer-active",
2862
2928
  thresh: 4,
2863
2929
  // throttle: 400,
2864
2930
  dragstart: (e) => {
2865
- return this.tree.element.contains(e.dragElem);
2931
+ const info = Wunderbaum.getEventInfo(e.startEvent);
2932
+ const colDef = info.colDef;
2933
+ const allow = colDef &&
2934
+ this.tree.element.contains(e.dragElem) &&
2935
+ toBool(colDef.resizable, tree.options.resizableColumns, false);
2936
+ // this.tree.log("dragstart", colDef, e, info);
2937
+ this.tree.element.classList.toggle("wb-col-resizing", !!allow);
2938
+ info.colElem.classList.toggle("wb-col-resizing", !!allow);
2939
+ // We start dagging, so we remember the actual width in *pixels*
2940
+ // (which may be 'auto' or '100%').
2941
+ // Since we we re-create the markup on each update, we also cannot store
2942
+ // the original event or DOM element, but only the colDef object.
2943
+ if (allow) {
2944
+ // Store initial target column infos in customData
2945
+ e.customData.colDef = colDef;
2946
+ e.customData.orgCustomWidthPx = colDef.customWidthPx;
2947
+ const curWidthPx = Number.parseInt(info.colElem.style.width, 10);
2948
+ e.customData.orgWidthPx = curWidthPx;
2949
+ // Set custom width to current width, so that we can modify it
2950
+ colDef.customWidthPx = curWidthPx;
2951
+ // this.tree.log(
2952
+ // `dragstart customWidthPx=${colDef.customWidthPx}`,
2953
+ // e,
2954
+ // info
2955
+ // );
2956
+ this.tree.update(ChangeType.colStructure);
2957
+ // this.tree.log(
2958
+ // `dragstart 2 customWidthPx=${colDef.customWidthPx}`,
2959
+ // e,
2960
+ // info
2961
+ // );
2962
+ }
2963
+ return allow;
2866
2964
  },
2867
2965
  drag: (e) => {
2868
2966
  // TODO: throttle
@@ -2876,17 +2974,39 @@
2876
2974
  init() {
2877
2975
  super.init();
2878
2976
  }
2977
+ /**
2978
+ * Hanldes drag and sragstop events for column resizing.
2979
+ */
2879
2980
  handleDrag(e) {
2880
- const info = Wunderbaum.getEventInfo(e.event);
2881
- // this.tree.options.
2882
- this.tree.log(`${e.type}(${e.dx})`, e, info);
2981
+ const custom = e.customData;
2982
+ const colDef = custom.colDef;
2983
+ // this.tree.log(`${e.type} (dx=${e.dx})`, e, info);
2984
+ if (e.type === "dragstop" || e.type === "drag") {
2985
+ this.tree.element.classList.remove("wb-col-resizing");
2986
+ // info.colElem!.classList.remove("wb-col-resizing");
2987
+ if (e.apply || e.type === "drag") {
2988
+ const minWidth = toPixel(colDef.minWidth, DEFAULT_MIN_COL_WIDTH);
2989
+ const newWidth = Math.max(minWidth, custom.orgWidthPx + e.dx);
2990
+ colDef.customWidthPx = newWidth;
2991
+ // this.tree.log(
2992
+ // `${e.type} minWidth=${minWidth}, newWidth=${newWidth}`,
2993
+ // colDef
2994
+ // );
2995
+ }
2996
+ else {
2997
+ // Drag was cancelled
2998
+ this.tree.log("Column resize cancelled", e);
2999
+ colDef.customWidthPx = custom.orgCustomWidthPx; // Restore original width or undefined
3000
+ }
3001
+ this.tree.update(ChangeType.colStructure);
3002
+ }
2883
3003
  }
2884
3004
  }
2885
3005
 
2886
3006
  /*!
2887
3007
  * Wunderbaum - deferred
2888
3008
  * Copyright (c) 2021-2024, Martin Wendt. Released under the MIT license.
2889
- * v0.9.0, Sun, 05 May 2024 16:08:56 GMT (https://github.com/mar10/wunderbaum)
3009
+ * v0.10.1, Sat, 20 Jul 2024 13:53:46 GMT (https://github.com/mar10/wunderbaum)
2890
3010
  */
2891
3011
  /**
2892
3012
  * Implement a ES6 Promise, that exposes a resolve() and reject() method.
@@ -2939,7 +3059,7 @@
2939
3059
  /*!
2940
3060
  * Wunderbaum - wunderbaum_node
2941
3061
  * Copyright (c) 2021-2024, Martin Wendt. Released under the MIT license.
2942
- * v0.9.0, Sun, 05 May 2024 16:08:56 GMT (https://github.com/mar10/wunderbaum)
3062
+ * v0.10.1, Sat, 20 Jul 2024 13:53:46 GMT (https://github.com/mar10/wunderbaum)
2943
3063
  */
2944
3064
  /** WunderbaumNode properties that can be passed with source data.
2945
3065
  * (Any other source properties will be stored as `node.data.PROP`.)
@@ -5348,7 +5468,7 @@
5348
5468
  /*!
5349
5469
  * Wunderbaum - ext-edit
5350
5470
  * Copyright (c) 2021-2024, Martin Wendt. Released under the MIT license.
5351
- * v0.9.0, Sun, 05 May 2024 16:08:56 GMT (https://github.com/mar10/wunderbaum)
5471
+ * v0.10.1, Sat, 20 Jul 2024 13:53:46 GMT (https://github.com/mar10/wunderbaum)
5352
5472
  */
5353
5473
  // const START_MARKER = "\uFFF7";
5354
5474
  class EditExtension extends WunderbaumExtension {
@@ -5679,8 +5799,8 @@
5679
5799
  * https://github.com/mar10/wunderbaum
5680
5800
  *
5681
5801
  * Released under the MIT license.
5682
- * @version v0.9.0
5683
- * @date Sun, 05 May 2024 16:08:56 GMT
5802
+ * @version v0.10.1
5803
+ * @date Sat, 20 Jul 2024 13:53:46 GMT
5684
5804
  */
5685
5805
  // import "./wunderbaum.scss";
5686
5806
  class WbSystemRoot extends WunderbaumNode {
@@ -7003,6 +7123,13 @@
7003
7123
  console.warn(this.toString(), ...args); // eslint-disable-line no-console
7004
7124
  }
7005
7125
  }
7126
+ /** Reset column widths to default. */
7127
+ resetColumns() {
7128
+ this.columns.forEach((col) => {
7129
+ delete col.customWidthPx;
7130
+ });
7131
+ this.update(ChangeType.colStructure);
7132
+ }
7006
7133
  /**
7007
7134
  * Make sure that this node is vertically scrolled into the viewport.
7008
7135
  *
@@ -7360,7 +7487,7 @@
7360
7487
  this._columnsById = {};
7361
7488
  for (const col of columns) {
7362
7489
  this._columnsById[col.id] = col;
7363
- const cw = col.width;
7490
+ const cw = col.customWidthPx ? `${col.customWidthPx}px` : col.width;
7364
7491
  if (col.id === "*" && col !== col0) {
7365
7492
  throw new Error(`Column id '*' must be defined only once: '${col.title}'.`);
7366
7493
  }
@@ -7466,7 +7593,13 @@
7466
7593
  }
7467
7594
  let resizer = "";
7468
7595
  if (i < colCount - 1) {
7469
- resizer = '<span class="wb-col-resizer"></span>';
7596
+ if (toBool(col.resizable, this.options.resizableColumns, false)) {
7597
+ resizer =
7598
+ '<span class="wb-col-resizer wb-col-resizer-active"></span>';
7599
+ }
7600
+ else {
7601
+ resizer = '<span class="wb-col-resizer"></span>';
7602
+ }
7470
7603
  }
7471
7604
  colElem.innerHTML = `<span class="wb-col-title"${tooltip}>${title}</span>${resizer}`;
7472
7605
  if (this.isCellNav()) {
@@ -7547,6 +7680,7 @@
7547
7680
  // console.profileEnd(`_updateViewportImmediately()`)
7548
7681
  }
7549
7682
  if (this.options.connectTopBreadcrumb) {
7683
+ assert(this.options.connectTopBreadcrumb.textContent != null, `Invalid 'connectTopBreadcrumb' option (input element expected).`);
7550
7684
  let path = (_a = this.getTopmostVpNode(true)) === null || _a === void 0 ? void 0 : _a.getPath(false, "title", " > ");
7551
7685
  path = path ? path + " >" : "";
7552
7686
  this.options.connectTopBreadcrumb.textContent = path;
@@ -7916,7 +8050,7 @@
7916
8050
  }
7917
8051
  Wunderbaum.sequence = 0;
7918
8052
  /** Wunderbaum release version number "MAJOR.MINOR.PATCH". */
7919
- Wunderbaum.version = "v0.9.0"; // Set to semver by 'grunt release'
8053
+ Wunderbaum.version = "v0.10.1"; // Set to semver by 'grunt release'
7920
8054
  /** Expose some useful methods of the util.ts module as `Wunderbaum.util`. */
7921
8055
  Wunderbaum.util = util;
7922
8056