wunderbaum 0.0.1 → 0.0.4

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.
@@ -9,7 +9,6 @@ import {
9
9
  escapeHtml,
10
10
  escapeRegex,
11
11
  extend,
12
- extractHtmlText,
13
12
  onEvent,
14
13
  } from "./util";
15
14
  import { NodeFilterCallback, NodeStatusType } from "./common";
@@ -79,7 +78,7 @@ export class FilterExtension extends WunderbaumExtension {
79
78
  count = 0,
80
79
  tree = this.tree,
81
80
  treeOpts = tree.options,
82
- escapeTitles = treeOpts.escapeTitles,
81
+ // escapeTitles = treeOpts.escapeTitles,
83
82
  prevAutoCollapse = treeOpts.autoCollapse,
84
83
  opts = extend({}, treeOpts.filter, _opts),
85
84
  hideMode = opts.mode === "hide",
@@ -118,35 +117,36 @@ export class FilterExtension extends WunderbaumExtension {
118
117
  if (!node.title) {
119
118
  return false;
120
119
  }
121
- let text = escapeTitles ? node.title : extractHtmlText(node.title);
120
+ // let text = escapeTitles ? node.title : extractHtmlText(node.title);
121
+ let text = node.title;
122
122
  // `.match` instead of `.test` to get the capture groups
123
123
  let res = text.match(re);
124
124
 
125
125
  if (res && opts.highlight) {
126
- if (escapeTitles) {
127
- if (opts.fuzzy) {
128
- temp = _markFuzzyMatchedChars(text, res, escapeTitles);
129
- } else {
130
- // #740: we must not apply the marks to escaped entity names, e.g. `"`
131
- // Use some exotic characters to mark matches:
132
- temp = text.replace(reHighlight, function (s) {
133
- return START_MARKER + s + END_MARKER;
134
- });
135
- }
136
- // now we can escape the title...
137
- node.titleWithHighlight = escapeHtml(temp)
138
- // ... and finally insert the desired `<mark>` tags
139
- .replace(RE_START_MARKER, "<mark>")
140
- .replace(RE_END_MARTKER, "</mark>");
126
+ // if (escapeTitles) {
127
+ if (opts.fuzzy) {
128
+ temp = _markFuzzyMatchedChars(text, res, true);
141
129
  } else {
142
- if (opts.fuzzy) {
143
- node.titleWithHighlight = _markFuzzyMatchedChars(text, res);
144
- } else {
145
- node.titleWithHighlight = text.replace(reHighlight, function (s) {
146
- return "<mark>" + s + "</mark>";
147
- });
148
- }
130
+ // #740: we must not apply the marks to escaped entity names, e.g. `&quot;`
131
+ // Use some exotic characters to mark matches:
132
+ temp = text.replace(reHighlight, function (s) {
133
+ return START_MARKER + s + END_MARKER;
134
+ });
149
135
  }
136
+ // now we can escape the title...
137
+ node.titleWithHighlight = escapeHtml(temp)
138
+ // ... and finally insert the desired `<mark>` tags
139
+ .replace(RE_START_MARKER, "<mark>")
140
+ .replace(RE_END_MARTKER, "</mark>");
141
+ // } else {
142
+ // if (opts.fuzzy) {
143
+ // node.titleWithHighlight = _markFuzzyMatchedChars(text, res);
144
+ // } else {
145
+ // node.titleWithHighlight = text.replace(reHighlight, function (s) {
146
+ // return "<mark>" + s + "</mark>";
147
+ // });
148
+ // }
149
+ // }
150
150
  // node.debug("filter", escapeTitles, text, node.titleWithHighlight);
151
151
  }
152
152
  return !!res;
@@ -266,9 +266,9 @@ export class FilterExtension extends WunderbaumExtension {
266
266
  * [ext-filter] Reset the filter.
267
267
  */
268
268
  clearFilter() {
269
- let tree = this.tree,
270
- // statusNode = tree.root.findDirectChild(KEY_NODATA),
271
- escapeTitles = tree.options.escapeTitles;
269
+ let tree = this.tree;
270
+ // statusNode = tree.root.findDirectChild(KEY_NODATA),
271
+ // escapeTitles = tree.options.escapeTitles;
272
272
  // enhanceTitle = tree.options.enhanceTitle,
273
273
  tree.enableUpdate(false);
274
274
 
@@ -284,11 +284,11 @@ export class FilterExtension extends WunderbaumExtension {
284
284
  if (node.match && node._rowElem) {
285
285
  // #491, #601
286
286
  let titleElem = node._rowElem.querySelector("span.wb-title")!;
287
- if (escapeTitles) {
288
- titleElem.textContent = node.title;
289
- } else {
290
- titleElem.innerHTML = node.title;
291
- }
287
+ // if (escapeTitles) {
288
+ titleElem.textContent = node.title;
289
+ // } else {
290
+ // titleElem.innerHTML = node.title;
291
+ // }
292
292
  node._callEvent("enhanceTitle", { titleElem: titleElem });
293
293
  }
294
294
  delete node.match;
@@ -330,7 +330,7 @@ export class FilterExtension extends WunderbaumExtension {
330
330
  function _markFuzzyMatchedChars(
331
331
  text: string,
332
332
  matches: RegExpMatchArray,
333
- escapeTitles = false
333
+ escapeTitles = true
334
334
  ) {
335
335
  let matchingIndices = [];
336
336
  // get the indices of matched characters (Iterate through `RegExpMatchArray`)
@@ -350,7 +350,7 @@ function _markFuzzyMatchedChars(
350
350
  // Map each `text` char to its position and store in `textPoses`.
351
351
  let textPoses = text.split("");
352
352
  if (escapeTitles) {
353
- // If escaping the title, then wrap the matchng char within exotic chars
353
+ // If escaping the title, then wrap the matching char within exotic chars
354
354
  matchingIndices.forEach(function (v) {
355
355
  textPoses[v] = START_MARKER + textPoses[v] + END_MARKER;
356
356
  });
@@ -0,0 +1,45 @@
1
+ /*!
2
+ * Wunderbaum - ext-grid
3
+ * Copyright (c) 2021-2022, Martin Wendt. Released under the MIT license.
4
+ * @VERSION, @DATE (https://github.com/mar10/wunderbaum)
5
+ */
6
+ import { Wunderbaum } from "./wunderbaum";
7
+ import { WunderbaumExtension } from "./wb_extension_base";
8
+ import { DragCallbackArgType, DragObserver } from "./drag_observer";
9
+
10
+ export class GridExtension extends WunderbaumExtension {
11
+ protected observer: DragObserver;
12
+
13
+ constructor(tree: Wunderbaum) {
14
+ super(tree, "grid", {
15
+ // throttle: 200,
16
+ });
17
+
18
+ this.observer = new DragObserver({
19
+ root: window.document,
20
+ selector: "span.wb-col-resizer",
21
+ thresh: 4,
22
+ // throttle: 400,
23
+ dragstart: (e) => {
24
+ return this.tree.element.contains(e.dragElem);
25
+ },
26
+ drag: (e) => {
27
+ // TODO: throttle
28
+ return this.handleDrag(e);
29
+ },
30
+ dragstop: (e) => {
31
+ return this.handleDrag(e);
32
+ },
33
+ });
34
+ }
35
+
36
+ init() {
37
+ super.init();
38
+ }
39
+
40
+ protected handleDrag(e: DragCallbackArgType): void {
41
+ const info = Wunderbaum.getEventInfo(e.event);
42
+ // this.tree.options.
43
+ this.tree.log(`${e.type}(${e.dx})`, e, info);
44
+ }
45
+ }
@@ -94,7 +94,7 @@ export class KeynavExtension extends WunderbaumExtension {
94
94
  if (!node.expanded && (node.children || node.lazy)) {
95
95
  eventName = "Add"; // expand
96
96
  } else if (navModeOption === NavigationModeOption.startRow) {
97
- tree.setCellMode(NavigationMode.cellNav);
97
+ tree.setNavigationMode(NavigationMode.cellNav);
98
98
  return;
99
99
  }
100
100
  break;
@@ -133,6 +133,8 @@ export class KeynavExtension extends WunderbaumExtension {
133
133
  case "Home":
134
134
  case "Control+End":
135
135
  case "Control+Home":
136
+ case "Meta+ArrowDown":
137
+ case "Meta+ArrowUp":
136
138
  case "PageDown":
137
139
  case "PageUp":
138
140
  node.navigate(eventName, { activate: activate, event: event });
@@ -164,10 +166,10 @@ export class KeynavExtension extends WunderbaumExtension {
164
166
  break;
165
167
  case "Escape":
166
168
  if (tree.navMode === NavigationMode.cellEdit) {
167
- tree.setCellMode(NavigationMode.cellNav);
169
+ tree.setNavigationMode(NavigationMode.cellNav);
168
170
  handled = true;
169
171
  } else if (tree.navMode === NavigationMode.cellNav) {
170
- tree.setCellMode(NavigationMode.row);
172
+ tree.setNavigationMode(NavigationMode.row);
171
173
  handled = true;
172
174
  }
173
175
  break;
@@ -176,7 +178,7 @@ export class KeynavExtension extends WunderbaumExtension {
176
178
  tree.setColumn(tree.activeColIdx - 1);
177
179
  handled = true;
178
180
  } else if (navModeOption !== NavigationModeOption.cell) {
179
- tree.setCellMode(NavigationMode.row);
181
+ tree.setNavigationMode(NavigationMode.row);
180
182
  handled = true;
181
183
  }
182
184
  break;
@@ -193,6 +195,8 @@ export class KeynavExtension extends WunderbaumExtension {
193
195
  case "Home":
194
196
  case "Control+End":
195
197
  case "Control+Home":
198
+ case "Meta+ArrowDown":
199
+ case "Meta+ArrowUp":
196
200
  case "PageDown":
197
201
  case "PageUp":
198
202
  node.navigate(eventName, { activate: activate, event: event });
@@ -38,14 +38,14 @@ export abstract class WunderbaumExtension {
38
38
  this.tree.element.classList.add("wb-ext-" + this.id);
39
39
  }
40
40
 
41
- // protected callEvent(name: string, extra?: any): any {
42
- // let func = this.extensionOpts[name];
41
+ // protected callEvent(type: string, extra?: any): any {
42
+ // let func = this.extensionOpts[type];
43
43
  // if (func) {
44
44
  // return func.call(
45
45
  // this.tree,
46
46
  // util.extend(
47
47
  // {
48
- // event: this.id + "." + name,
48
+ // event: this.id + "." + type,
49
49
  // },
50
50
  // extra
51
51
  // )