wunderbaum 0.6.0 → 0.7.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-2023, Martin Wendt. Released under the MIT license.
10
- * v0.6.0, Wed, 08 Nov 2023 19:58:55 GMT (https://github.com/mar10/wunderbaum)
10
+ * v0.7.0, Sat, 09 Dec 2023 13:47:27 GMT (https://github.com/mar10/wunderbaum)
11
11
  */
12
12
  /** @module util */
13
13
  /** Readable names for `MouseEvent.button` */
@@ -771,7 +771,7 @@
771
771
  /*!
772
772
  * Wunderbaum - types
773
773
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
774
- * v0.6.0, Wed, 08 Nov 2023 19:58:55 GMT (https://github.com/mar10/wunderbaum)
774
+ * v0.7.0, Sat, 09 Dec 2023 13:47:27 GMT (https://github.com/mar10/wunderbaum)
775
775
  */
776
776
  /**
777
777
  * Possible values for {@link WunderbaumNode.update()} and {@link Wunderbaum.update()}.
@@ -835,7 +835,7 @@
835
835
  /*!
836
836
  * Wunderbaum - wb_extension_base
837
837
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
838
- * v0.6.0, Wed, 08 Nov 2023 19:58:55 GMT (https://github.com/mar10/wunderbaum)
838
+ * v0.7.0, Sat, 09 Dec 2023 13:47:27 GMT (https://github.com/mar10/wunderbaum)
839
839
  */
840
840
  class WunderbaumExtension {
841
841
  constructor(tree, id, defaults) {
@@ -1191,7 +1191,7 @@
1191
1191
  /*!
1192
1192
  * Wunderbaum - ext-filter
1193
1193
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
1194
- * v0.6.0, Wed, 08 Nov 2023 19:58:55 GMT (https://github.com/mar10/wunderbaum)
1194
+ * v0.7.0, Sat, 09 Dec 2023 13:47:27 GMT (https://github.com/mar10/wunderbaum)
1195
1195
  */
1196
1196
  const START_MARKER = "\uFFF7";
1197
1197
  const END_MARKER = "\uFFF8";
@@ -1491,7 +1491,7 @@
1491
1491
  /*!
1492
1492
  * Wunderbaum - ext-keynav
1493
1493
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
1494
- * v0.6.0, Wed, 08 Nov 2023 19:58:55 GMT (https://github.com/mar10/wunderbaum)
1494
+ * v0.7.0, Sat, 09 Dec 2023 13:47:27 GMT (https://github.com/mar10/wunderbaum)
1495
1495
  */
1496
1496
  const QUICKSEARCH_DELAY = 500;
1497
1497
  class KeynavExtension extends WunderbaumExtension {
@@ -1837,7 +1837,7 @@
1837
1837
  /*!
1838
1838
  * Wunderbaum - ext-logger
1839
1839
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
1840
- * v0.6.0, Wed, 08 Nov 2023 19:58:55 GMT (https://github.com/mar10/wunderbaum)
1840
+ * v0.7.0, Sat, 09 Dec 2023 13:47:27 GMT (https://github.com/mar10/wunderbaum)
1841
1841
  */
1842
1842
  class LoggerExtension extends WunderbaumExtension {
1843
1843
  constructor(tree) {
@@ -1879,7 +1879,7 @@
1879
1879
  /*!
1880
1880
  * Wunderbaum - common
1881
1881
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
1882
- * v0.6.0, Wed, 08 Nov 2023 19:58:55 GMT (https://github.com/mar10/wunderbaum)
1882
+ * v0.7.0, Sat, 09 Dec 2023 13:47:27 GMT (https://github.com/mar10/wunderbaum)
1883
1883
  */
1884
1884
  const DEFAULT_DEBUGLEVEL = 3; // Replaced by rollup script
1885
1885
  /**
@@ -1958,6 +1958,7 @@
1958
1958
  "_keyMap",
1959
1959
  "_positional",
1960
1960
  "_typeList",
1961
+ "_valueMap",
1961
1962
  "_version",
1962
1963
  "children",
1963
1964
  "columns",
@@ -2027,18 +2028,34 @@
2027
2028
  const y = b.title.toLowerCase();
2028
2029
  return x === y ? 0 : x > y ? 1 : -1;
2029
2030
  }
2031
+ /**
2032
+ * Convert 'flat' to 'nested' format.
2033
+ *
2034
+ * Flat node entry format:
2035
+ * [PARENT_ID, [POSITIONAL_ARGS]]
2036
+ * or
2037
+ * [PARENT_ID, [POSITIONAL_ARGS], {KEY_VALUE_ARGS}]
2038
+ *
2039
+ * 1. Parent-referencing list is converted to a list of nested dicts with
2040
+ * optional `children` properties.
2041
+ * 2. `[POSITIONAL_ARGS]` are added as dict attributes.
2042
+ */
2030
2043
  function unflattenSource(source) {
2031
2044
  var _a, _b, _c;
2032
- const { _format, _keyMap, _positional, children } = source;
2045
+ const { _format, _keyMap = {}, _positional = [], children } = source;
2033
2046
  if (_format !== "flat") {
2034
2047
  throw new Error(`Expected source._format: "flat", but got ${_format}`);
2035
2048
  }
2036
2049
  if (_positional && _positional.includes("children")) {
2037
2050
  throw new Error(`source._positional must not include "children": ${_positional}`);
2038
2051
  }
2039
- // Inverse keyMap:
2040
- const longToShort = {};
2041
- if (_keyMap) {
2052
+ let longToShort = _keyMap;
2053
+ if (_keyMap.t) {
2054
+ // Inverse keyMap was used (pre 0.7.0)
2055
+ // TODO: raise Error on final 1.x release
2056
+ const msg = `source._keyMap maps from long to short since v0.7.0. Flip key/value!`;
2057
+ console.warn(msg); // eslint-disable-line no-console
2058
+ longToShort = {};
2042
2059
  for (const [key, value] of Object.entries(_keyMap)) {
2043
2060
  longToShort[value] = key;
2044
2061
  }
@@ -2049,16 +2066,16 @@
2049
2066
  const indexToNodeMap = {};
2050
2067
  const keyAttrName = (_a = longToShort["key"]) !== null && _a !== void 0 ? _a : "key";
2051
2068
  const childrenAttrName = (_b = longToShort["children"]) !== null && _b !== void 0 ? _b : "children";
2052
- for (const [index, node] of children.entries()) {
2069
+ for (const [index, nodeTuple] of children.entries()) {
2053
2070
  // Node entry format:
2054
2071
  // [PARENT_ID, [POSITIONAL_ARGS]]
2055
2072
  // or
2056
2073
  // [PARENT_ID, [POSITIONAL_ARGS], {KEY_VALUE_ARGS}]
2057
- const [parentId, args, kwargs = {}] = node;
2074
+ const [parentId, args, kwargs = {}] = nodeTuple;
2058
2075
  // Free up some memory as we go
2059
- node[1] = null;
2060
- if (node[2] != null) {
2061
- node[2] = null;
2076
+ nodeTuple[1] = null;
2077
+ if (nodeTuple[2] != null) {
2078
+ nodeTuple[2] = null;
2062
2079
  }
2063
2080
  // console.log("flatten", parentId, args, kwargs)
2064
2081
  // We keep `kwargs` as our new node definition. Then we add all positional
@@ -2096,56 +2113,96 @@
2096
2113
  newChildren.push(kwargs);
2097
2114
  }
2098
2115
  }
2099
- delete source.children;
2100
2116
  source.children = newChildren;
2101
2117
  }
2102
- function inflateSourceData(source) {
2103
- const { _format, _keyMap, _typeList } = source;
2118
+ /**
2119
+ * Decompresses the source data by
2120
+ * - converting from 'flat' to 'nested' format
2121
+ * - expanding short alias names to long names (if defined in _keyMap)
2122
+ * - resolving value indexes to value strings (if defined in _valueMap)
2123
+ *
2124
+ * @param source - The source object to be decompressed.
2125
+ * @returns void
2126
+ */
2127
+ function decompressSourceData(source) {
2128
+ let { _format, _version = 1, _keyMap, _valueMap } = source;
2129
+ assert(_version === 1, `Expected file version 1 instead of ${_version}`);
2130
+ let longToShort = _keyMap;
2131
+ let shortToLong = {};
2132
+ if (longToShort) {
2133
+ for (const [key, value] of Object.entries(longToShort)) {
2134
+ shortToLong[value] = key;
2135
+ }
2136
+ }
2137
+ // Fallback for old format (pre 0.7.0, using _keyMap in reverse direction)
2138
+ // TODO: raise Error on final 1.x release
2139
+ if (longToShort && longToShort.t) {
2140
+ const msg = `source._keyMap maps from long to short since v0.7.0. Flip key/value!`;
2141
+ console.warn(msg); // eslint-disable-line no-console
2142
+ [longToShort, shortToLong] = [shortToLong, longToShort];
2143
+ }
2144
+ // Fallback for old format (pre 0.7.0, using _typeList instead of _valueMap)
2145
+ // TODO: raise Error on final 1.x release
2146
+ if (source._typeList != null) {
2147
+ const msg = `source._typeList is deprecated since v0.7.0: use source._valueMap: {"type": [...]} instead.`;
2148
+ if (_valueMap != null) {
2149
+ throw new Error(msg);
2150
+ }
2151
+ else {
2152
+ console.warn(msg); // eslint-disable-line no-console
2153
+ _valueMap = { type: source._typeList };
2154
+ delete source._typeList;
2155
+ }
2156
+ }
2104
2157
  if (_format === "flat") {
2105
2158
  unflattenSource(source);
2106
2159
  }
2107
2160
  delete source._format;
2108
2161
  delete source._version;
2109
2162
  delete source._keyMap;
2110
- delete source._typeList;
2163
+ delete source._valueMap;
2111
2164
  delete source._positional;
2112
2165
  function _iter(childList) {
2113
2166
  for (const node of childList) {
2114
- // Expand short alias names
2115
- if (_keyMap) {
2116
- // Iterate over a list of names, because we modify inside the loop:
2117
- Object.getOwnPropertyNames(node).forEach((propName) => {
2118
- var _a;
2119
- const long = (_a = _keyMap[propName]) !== null && _a !== void 0 ? _a : propName;
2120
- if (long !== propName) {
2121
- node[long] = node[propName];
2167
+ // Iterate over a list of names, because we modify inside the loop
2168
+ // (for ... of ... does not allow this)
2169
+ Object.getOwnPropertyNames(node).forEach((propName) => {
2170
+ const value = node[propName];
2171
+ // Replace short names with long names if defined in _keyMap
2172
+ let longName = propName;
2173
+ if (_keyMap && shortToLong[propName] != null) {
2174
+ longName = shortToLong[propName];
2175
+ if (longName !== propName) {
2176
+ node[longName] = value;
2122
2177
  delete node[propName];
2123
2178
  }
2124
- });
2125
- }
2126
- // `node` now has long attribute names
2127
- // Resolve node type indexes
2128
- const type = node.type;
2129
- if (_typeList && type != null && typeof type === "number") {
2130
- const newType = _typeList[type];
2131
- if (newType == null) {
2132
- throw new Error(`Expected typeList[${type}] entry in [${_typeList}]`);
2133
2179
  }
2134
- node.type = newType;
2135
- }
2180
+ // Replace type index with type name if defined in _valueMap
2181
+ if (_valueMap &&
2182
+ typeof value === "number" &&
2183
+ _valueMap[longName] != null) {
2184
+ const newValue = _valueMap[longName][value];
2185
+ if (newValue == null) {
2186
+ throw new Error(`Expected valueMap[${longName}][${value}] entry in [${_valueMap[longName]}]`);
2187
+ }
2188
+ node[longName] = newValue;
2189
+ }
2190
+ });
2136
2191
  // Recursion
2137
2192
  if (node.children) {
2138
2193
  _iter(node.children);
2139
2194
  }
2140
2195
  }
2141
2196
  }
2142
- _iter(source.children);
2197
+ if (_keyMap || _valueMap) {
2198
+ _iter(source.children);
2199
+ }
2143
2200
  }
2144
2201
 
2145
2202
  /*!
2146
2203
  * Wunderbaum - ext-dnd
2147
2204
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
2148
- * v0.6.0, Wed, 08 Nov 2023 19:58:55 GMT (https://github.com/mar10/wunderbaum)
2205
+ * v0.7.0, Sat, 09 Dec 2023 13:47:27 GMT (https://github.com/mar10/wunderbaum)
2149
2206
  */
2150
2207
  const nodeMimeType = "application/x-wunderbaum-node";
2151
2208
  class DndExtension extends WunderbaumExtension {
@@ -2548,6 +2605,7 @@
2548
2605
  }
2549
2606
  else if (e.type === "drop") {
2550
2607
  e.stopPropagation(); // prevent browser from opening links?
2608
+ e.preventDefault(); // #69 prevent iOS browser from opening links
2551
2609
  this._leaveNode();
2552
2610
  const region = this.lastDropRegion;
2553
2611
  let nodeData = (_a = e.dataTransfer) === null || _a === void 0 ? void 0 : _a.getData(nodeMimeType);
@@ -2568,13 +2626,14 @@
2568
2626
  });
2569
2627
  }, 10);
2570
2628
  }
2629
+ return false;
2571
2630
  }
2572
2631
  }
2573
2632
 
2574
2633
  /*!
2575
2634
  * Wunderbaum - drag_observer
2576
2635
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
2577
- * v0.6.0, Wed, 08 Nov 2023 19:58:55 GMT (https://github.com/mar10/wunderbaum)
2636
+ * v0.7.0, Sat, 09 Dec 2023 13:47:27 GMT (https://github.com/mar10/wunderbaum)
2578
2637
  */
2579
2638
  /**
2580
2639
  * Convert mouse- and touch events to 'dragstart', 'drag', and 'dragstop'.
@@ -2710,7 +2769,7 @@
2710
2769
  /*!
2711
2770
  * Wunderbaum - ext-grid
2712
2771
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
2713
- * v0.6.0, Wed, 08 Nov 2023 19:58:55 GMT (https://github.com/mar10/wunderbaum)
2772
+ * v0.7.0, Sat, 09 Dec 2023 13:47:27 GMT (https://github.com/mar10/wunderbaum)
2714
2773
  */
2715
2774
  class GridExtension extends WunderbaumExtension {
2716
2775
  constructor(tree) {
@@ -2747,7 +2806,7 @@
2747
2806
  /*!
2748
2807
  * Wunderbaum - deferred
2749
2808
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
2750
- * v0.6.0, Wed, 08 Nov 2023 19:58:55 GMT (https://github.com/mar10/wunderbaum)
2809
+ * v0.7.0, Sat, 09 Dec 2023 13:47:27 GMT (https://github.com/mar10/wunderbaum)
2751
2810
  */
2752
2811
  /**
2753
2812
  * Implement a ES6 Promise, that exposes a resolve() and reject() method.
@@ -2800,7 +2859,7 @@
2800
2859
  /*!
2801
2860
  * Wunderbaum - wunderbaum_node
2802
2861
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
2803
- * v0.6.0, Wed, 08 Nov 2023 19:58:55 GMT (https://github.com/mar10/wunderbaum)
2862
+ * v0.7.0, Sat, 09 Dec 2023 13:47:27 GMT (https://github.com/mar10/wunderbaum)
2804
2863
  */
2805
2864
  /** WunderbaumNode properties that can be passed with source data.
2806
2865
  * (Any other source properties will be stored as `node.data.PROP`.)
@@ -3595,7 +3654,7 @@
3595
3654
  const format = (_a = source.format) !== null && _a !== void 0 ? _a : "nested";
3596
3655
  assert(format === "nested" || format === "flat", `Expected source.format = 'nested' or 'flat': ${format}`);
3597
3656
  // Pre-rocess for 'nested' or 'flat' format
3598
- inflateSourceData(source);
3657
+ decompressSourceData(source);
3599
3658
  assert(source.children, "If `source` is an object, it must have a `children` property");
3600
3659
  if (source.types) {
3601
3660
  tree.logInfo("Redefine types", source.columns);
@@ -3753,7 +3812,8 @@
3753
3812
  return;
3754
3813
  }
3755
3814
  assert(isArray(source) || (source && source.url), "The lazyLoad event must return a node list, `{url: ...}`, or false.");
3756
- await this.load(source); // also calls setStatus('ok')
3815
+ await this.load(source);
3816
+ this.setStatus(NodeStatusType.ok);
3757
3817
  if (wasExpanded) {
3758
3818
  this.expanded = true;
3759
3819
  this.tree.update(ChangeType.structure);
@@ -5132,7 +5192,7 @@
5132
5192
  /*!
5133
5193
  * Wunderbaum - ext-edit
5134
5194
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
5135
- * v0.6.0, Wed, 08 Nov 2023 19:58:55 GMT (https://github.com/mar10/wunderbaum)
5195
+ * v0.7.0, Sat, 09 Dec 2023 13:47:27 GMT (https://github.com/mar10/wunderbaum)
5136
5196
  */
5137
5197
  // const START_MARKER = "\uFFF7";
5138
5198
  class EditExtension extends WunderbaumExtension {
@@ -5432,8 +5492,8 @@
5432
5492
  * https://github.com/mar10/wunderbaum
5433
5493
  *
5434
5494
  * Released under the MIT license.
5435
- * @version v0.6.0
5436
- * @date Wed, 08 Nov 2023 19:58:55 GMT
5495
+ * @version v0.7.0
5496
+ * @date Sat, 09 Dec 2023 13:47:27 GMT
5437
5497
  */
5438
5498
  // import "./wunderbaum.scss";
5439
5499
  class WbSystemRoot extends WunderbaumNode {
@@ -7566,7 +7626,7 @@
7566
7626
  }
7567
7627
  Wunderbaum.sequence = 0;
7568
7628
  /** Wunderbaum release version number "MAJOR.MINOR.PATCH". */
7569
- Wunderbaum.version = "v0.6.0"; // Set to semver by 'grunt release'
7629
+ Wunderbaum.version = "v0.7.0"; // Set to semver by 'grunt release'
7570
7630
  /** Expose some useful methods of the util.ts module as `Wunderbaum.util`. */
7571
7631
  Wunderbaum.util = util;
7572
7632