wunderbaum 0.11.0 → 0.12.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.
- package/README.md +4 -5
- package/dist/wunderbaum.css +10 -10
- package/dist/wunderbaum.css.map +1 -1
- package/dist/wunderbaum.d.ts +52 -12
- package/dist/wunderbaum.esm.js +712 -626
- package/dist/wunderbaum.esm.min.js +24 -24
- package/dist/wunderbaum.esm.min.js.map +1 -1
- package/dist/wunderbaum.umd.js +712 -626
- package/dist/wunderbaum.umd.min.js +30 -30
- package/dist/wunderbaum.umd.min.js.map +1 -1
- package/package.json +7 -5
- package/src/common.ts +1 -1
- package/src/types.ts +32 -8
- package/src/util.ts +12 -0
- package/src/wb_ext_dnd.ts +9 -4
- package/src/wb_ext_edit.ts +4 -0
- package/src/wb_node.ts +108 -40
- package/src/wunderbaum.scss +18 -16
- package/src/wunderbaum.ts +38 -19
package/src/wunderbaum.ts
CHANGED
|
@@ -61,7 +61,7 @@ import {
|
|
|
61
61
|
makeNodeTitleStartMatcher,
|
|
62
62
|
nodeTitleSorter,
|
|
63
63
|
RENDER_MAX_PREFETCH,
|
|
64
|
-
|
|
64
|
+
DEFAULT_ROW_HEIGHT,
|
|
65
65
|
} from "./common";
|
|
66
66
|
import { WunderbaumNode } from "./wb_node";
|
|
67
67
|
import { Deferred } from "./deferred";
|
|
@@ -197,7 +197,7 @@ export class Wunderbaum {
|
|
|
197
197
|
debugLevel: DEFAULT_DEBUGLEVEL, // 0:quiet, 1:errors, 2:warnings, 3:info, 4:verbose
|
|
198
198
|
header: null, // Show/hide header (pass bool or string)
|
|
199
199
|
// headerHeightPx: ROW_HEIGHT,
|
|
200
|
-
rowHeightPx:
|
|
200
|
+
rowHeightPx: DEFAULT_ROW_HEIGHT,
|
|
201
201
|
iconMap: "bootstrap",
|
|
202
202
|
columns: null,
|
|
203
203
|
types: null,
|
|
@@ -294,6 +294,16 @@ export class Wunderbaum {
|
|
|
294
294
|
this.element.tabIndex = 0;
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
+
if (opts.rowHeightPx !== DEFAULT_ROW_HEIGHT) {
|
|
298
|
+
this.element.style.setProperty(
|
|
299
|
+
"--wb-row-outer-height",
|
|
300
|
+
opts.rowHeightPx + "px"
|
|
301
|
+
);
|
|
302
|
+
this.element.style.setProperty(
|
|
303
|
+
"--wb-row-inner-height",
|
|
304
|
+
opts.rowHeightPx - 2 + "px"
|
|
305
|
+
);
|
|
306
|
+
}
|
|
297
307
|
// Attach tree instance to <div>
|
|
298
308
|
(<any>this.element)._wb_tree = this;
|
|
299
309
|
|
|
@@ -488,7 +498,12 @@ export class Wunderbaum {
|
|
|
488
498
|
) {
|
|
489
499
|
return false;
|
|
490
500
|
}
|
|
491
|
-
if (
|
|
501
|
+
if (
|
|
502
|
+
node &&
|
|
503
|
+
info.colIdx === 0 &&
|
|
504
|
+
node.isExpandable() &&
|
|
505
|
+
info.region !== NodeRegion.expander
|
|
506
|
+
) {
|
|
492
507
|
this._callMethod("edit._stopEditTitle");
|
|
493
508
|
node.setExpanded(!node.isExpanded());
|
|
494
509
|
}
|
|
@@ -759,6 +774,7 @@ export class Wunderbaum {
|
|
|
759
774
|
|
|
760
775
|
/** Return the topmost visible node in the viewport. */
|
|
761
776
|
getTopmostVpNode(complete = true) {
|
|
777
|
+
const rowHeight = this.options.rowHeightPx!;
|
|
762
778
|
const gracePx = 1; // ignore subpixel scrolling
|
|
763
779
|
const scrollParent = this.element;
|
|
764
780
|
// const headerHeight = this.headerElement.clientHeight; // May be 0
|
|
@@ -766,15 +782,16 @@ export class Wunderbaum {
|
|
|
766
782
|
let topIdx: number;
|
|
767
783
|
|
|
768
784
|
if (complete) {
|
|
769
|
-
topIdx = Math.ceil((scrollTop - gracePx) /
|
|
785
|
+
topIdx = Math.ceil((scrollTop - gracePx) / rowHeight);
|
|
770
786
|
} else {
|
|
771
|
-
topIdx = Math.floor(scrollTop /
|
|
787
|
+
topIdx = Math.floor(scrollTop / rowHeight);
|
|
772
788
|
}
|
|
773
789
|
return this._getNodeByRowIdx(topIdx)!;
|
|
774
790
|
}
|
|
775
791
|
|
|
776
792
|
/** Return the lowest visible node in the viewport. */
|
|
777
793
|
getLowestVpNode(complete = true) {
|
|
794
|
+
const rowHeight = this.options.rowHeightPx!;
|
|
778
795
|
const scrollParent = this.element;
|
|
779
796
|
const headerHeight = this.headerElement.clientHeight; // May be 0
|
|
780
797
|
const scrollTop = scrollParent.scrollTop;
|
|
@@ -782,9 +799,9 @@ export class Wunderbaum {
|
|
|
782
799
|
let bottomIdx: number;
|
|
783
800
|
|
|
784
801
|
if (complete) {
|
|
785
|
-
bottomIdx = Math.floor((scrollTop + clientHeight) /
|
|
802
|
+
bottomIdx = Math.floor((scrollTop + clientHeight) / rowHeight) - 1;
|
|
786
803
|
} else {
|
|
787
|
-
bottomIdx = Math.ceil((scrollTop + clientHeight) /
|
|
804
|
+
bottomIdx = Math.ceil((scrollTop + clientHeight) / rowHeight) - 1;
|
|
788
805
|
}
|
|
789
806
|
bottomIdx = Math.min(bottomIdx, this.count(true) - 1);
|
|
790
807
|
return this._getNodeByRowIdx(bottomIdx)!;
|
|
@@ -1282,9 +1299,10 @@ export class Wunderbaum {
|
|
|
1282
1299
|
* @param includeHidden Not yet implemented
|
|
1283
1300
|
*/
|
|
1284
1301
|
findRelatedNode(node: WunderbaumNode, where: string, includeHidden = false) {
|
|
1302
|
+
const rowHeight = this.options.rowHeightPx!;
|
|
1285
1303
|
let res = null;
|
|
1286
1304
|
const pageSize = Math.floor(
|
|
1287
|
-
this.listContainerElement.clientHeight /
|
|
1305
|
+
this.listContainerElement.clientHeight / rowHeight
|
|
1288
1306
|
);
|
|
1289
1307
|
|
|
1290
1308
|
switch (where) {
|
|
@@ -1633,7 +1651,7 @@ export class Wunderbaum {
|
|
|
1633
1651
|
const PADDING = 2; // leave some pixels between viewport bounds
|
|
1634
1652
|
|
|
1635
1653
|
let node;
|
|
1636
|
-
WunderbaumNode;
|
|
1654
|
+
// WunderbaumNode;
|
|
1637
1655
|
let options: ScrollToOptions | undefined;
|
|
1638
1656
|
|
|
1639
1657
|
if (nodeOrOpts instanceof WunderbaumNode) {
|
|
@@ -1644,14 +1662,15 @@ export class Wunderbaum {
|
|
|
1644
1662
|
}
|
|
1645
1663
|
util.assert(node && node._rowIdx != null, `Invalid node: ${node}`);
|
|
1646
1664
|
|
|
1665
|
+
const rowHeight = this.options.rowHeightPx!;
|
|
1647
1666
|
const scrollParent = this.element;
|
|
1648
1667
|
const headerHeight = this.headerElement.clientHeight; // May be 0
|
|
1649
1668
|
const scrollTop = scrollParent.scrollTop;
|
|
1650
1669
|
const vpHeight = scrollParent.clientHeight;
|
|
1651
|
-
const rowTop = node._rowIdx! *
|
|
1670
|
+
const rowTop = node._rowIdx! * rowHeight + headerHeight;
|
|
1652
1671
|
const vpTop = headerHeight;
|
|
1653
1672
|
const vpRowTop = rowTop - scrollTop;
|
|
1654
|
-
const vpRowBottom = vpRowTop +
|
|
1673
|
+
const vpRowBottom = vpRowTop + rowHeight;
|
|
1655
1674
|
const topNode = options?.topNode;
|
|
1656
1675
|
|
|
1657
1676
|
// this.log( `scrollTo(${node.title}), vpTop:${vpTop}px, scrollTop:${scrollTop}, vpHeight:${vpHeight}, rowTop:${rowTop}, vpRowTop:${vpRowTop}`, nodeOrOpts , options);
|
|
@@ -1664,7 +1683,7 @@ export class Wunderbaum {
|
|
|
1664
1683
|
} else {
|
|
1665
1684
|
// Node is below viewport
|
|
1666
1685
|
// this.log("Below viewport");
|
|
1667
|
-
newScrollTop = rowTop +
|
|
1686
|
+
newScrollTop = rowTop + rowHeight - vpHeight + PADDING; // leave some pixels between viewport bounds
|
|
1668
1687
|
}
|
|
1669
1688
|
} else {
|
|
1670
1689
|
// Node is above viewport
|
|
@@ -2362,20 +2381,20 @@ export class Wunderbaum {
|
|
|
2362
2381
|
options = Object.assign({ newNodesOnly: false }, options);
|
|
2363
2382
|
const newNodesOnly = !!options.newNodesOnly;
|
|
2364
2383
|
|
|
2365
|
-
const
|
|
2366
|
-
const
|
|
2384
|
+
const rowHeight = this.options.rowHeightPx!;
|
|
2385
|
+
const vpHeight = this.element.clientHeight;
|
|
2367
2386
|
const prefetch = RENDER_MAX_PREFETCH;
|
|
2368
2387
|
// const grace_prefetch = RENDER_MAX_PREFETCH - RENDER_MIN_PREFETCH;
|
|
2369
2388
|
const ofs = this.element.scrollTop;
|
|
2370
2389
|
|
|
2371
|
-
let startIdx = Math.max(0, ofs /
|
|
2390
|
+
let startIdx = Math.max(0, ofs / rowHeight - prefetch);
|
|
2372
2391
|
startIdx = Math.floor(startIdx);
|
|
2373
2392
|
// Make sure start is always even, so the alternating row colors don't
|
|
2374
2393
|
// change when scrolling:
|
|
2375
2394
|
if (startIdx % 2) {
|
|
2376
2395
|
startIdx--;
|
|
2377
2396
|
}
|
|
2378
|
-
let endIdx = Math.max(0, (ofs +
|
|
2397
|
+
let endIdx = Math.max(0, (ofs + vpHeight) / rowHeight + prefetch);
|
|
2379
2398
|
endIdx = Math.ceil(endIdx);
|
|
2380
2399
|
|
|
2381
2400
|
// this.debug("render", opts);
|
|
@@ -2408,20 +2427,20 @@ export class Wunderbaum {
|
|
|
2408
2427
|
} else if (rowDiv && newNodesOnly) {
|
|
2409
2428
|
obsoleteNodes.delete(node);
|
|
2410
2429
|
// no need to update existing node markup
|
|
2411
|
-
rowDiv.style.top = idx *
|
|
2430
|
+
rowDiv.style.top = idx * rowHeight + "px";
|
|
2412
2431
|
prevElem = rowDiv;
|
|
2413
2432
|
} else {
|
|
2414
2433
|
obsoleteNodes.delete(node);
|
|
2415
2434
|
// Create new markup
|
|
2416
2435
|
if (rowDiv) {
|
|
2417
|
-
rowDiv.style.top = idx *
|
|
2436
|
+
rowDiv.style.top = idx * rowHeight + "px";
|
|
2418
2437
|
}
|
|
2419
2438
|
node._render({ top: top, after: prevElem });
|
|
2420
2439
|
// node.log("render", top, prevElem, "=>", node._rowElem);
|
|
2421
2440
|
prevElem = node._rowElem!;
|
|
2422
2441
|
}
|
|
2423
2442
|
idx++;
|
|
2424
|
-
top +=
|
|
2443
|
+
top += rowHeight;
|
|
2425
2444
|
});
|
|
2426
2445
|
this.treeRowCount = idx;
|
|
2427
2446
|
for (const n of obsoleteNodes) {
|