wunderbaum 0.8.0 → 0.8.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.
@@ -823,13 +823,26 @@ declare module "wb_node" {
823
823
  _fetchWithOptions(source: any): Promise<any>;
824
824
  /** Download data from the cloud, then call `.update()`. */
825
825
  load(source: SourceType): Promise<void>;
826
- /**Load content of a lazy node. */
826
+ /**
827
+ * Load content of a lazy node.
828
+ * If the node is already loaded, nothing happens.
829
+ * @param [forceReload=false] If true, reload even if already loaded.
830
+ */
827
831
  loadLazy(forceReload?: boolean): Promise<void>;
828
- /** Alias for `logDebug` */
832
+ /** Write to `console.log` with node name as prefix if opts.debugLevel >= 4.
833
+ * @see {@link WunderbaumNode.logDebug}
834
+ */
829
835
  log(...args: any[]): void;
836
+ /** Write to `console.debug` with node name as prefix if opts.debugLevel >= 4
837
+ * and browser console level includes debug/verbose messages.
838
+ * @see {@link WunderbaumNode.log}
839
+ */
830
840
  logDebug(...args: any[]): void;
841
+ /** Write to `console.error` with node name as prefix if opts.debugLevel >= 1. */
831
842
  logError(...args: any[]): void;
843
+ /** Write to `console.info` with node name as prefix if opts.debugLevel >= 3. */
832
844
  logInfo(...args: any[]): void;
845
+ /** Write to `console.warn` with node name as prefix if opts.debugLevel >= 2. */
833
846
  logWarn(...args: any[]): void;
834
847
  /** Expand all parents and optionally scroll into visible area as neccessary.
835
848
  * Promise is resolved, when lazy loading and animations are done.
@@ -1032,7 +1045,7 @@ declare module "wb_options" {
1032
1045
  * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
1033
1046
  * @VERSION, @DATE (https://github.com/mar10/wunderbaum)
1034
1047
  */
1035
- import { ColumnDefinitionList, DndOptionsType, DynamicBoolOption, DynamicBoolOrStringOption, DynamicCheckboxOption, DynamicIconOption, EditOptionsType, FilterOptionsType, NavModeEnum, NodeTypeDefinitionMap, SelectModeType, WbActivateEventType, WbChangeEventType, WbClickEventType, WbDeactivateEventType, WbErrorEventType, WbIconBadgeCallback, WbInitEventType, WbKeydownEventType, WbNodeData, WbNodeEventType, WbReceiveEventType, WbRenderEventType, WbTreeEventType } from "types";
1048
+ import { WbCancelableEventResultType, ColumnDefinitionList, DndOptionsType, DynamicBoolOption, DynamicBoolOrStringOption, DynamicCheckboxOption, DynamicIconOption, EditOptionsType, FilterOptionsType, NavModeEnum, NodeTypeDefinitionMap, SelectModeType, WbActivateEventType, WbChangeEventType, WbClickEventType, WbDeactivateEventType, WbErrorEventType, WbExpandEventType, WbIconBadgeCallback, WbInitEventType, WbKeydownEventType, WbNodeData, WbNodeEventType, WbReceiveEventType, WbRenderEventType, WbSelectEventType, WbTreeEventType, WbIconBadgeEventResultType } from "types";
1036
1049
  /**
1037
1050
  * Available options for {@link wunderbaum.Wunderbaum}.
1038
1051
  *
@@ -1220,18 +1233,30 @@ declare module "wb_options" {
1220
1233
  dnd?: DndOptionsType;
1221
1234
  edit?: EditOptionsType;
1222
1235
  filter?: FilterOptionsType;
1223
- grid?: any;
1224
1236
  /**
1225
- *
1237
+ * `e.node` was activated.
1226
1238
  * @category Callback
1227
1239
  */
1228
1240
  activate?: (e: WbActivateEventType) => void;
1241
+ /**
1242
+ * `e.node` is about to be activated.
1243
+ * Return `false` to prevent default handling, i.e. activating the node.
1244
+ * See also `deactivate` event.
1245
+ * @category Callback
1246
+ */
1247
+ beforeActivate?: (e: WbActivateEventType) => WbCancelableEventResultType;
1248
+ /**
1249
+ * `e.node` is about to be expanded/collapsed.
1250
+ * Return `false` to prevent default handling, i.e. expanding/collapsing the node.
1251
+ * @category Callback
1252
+ */
1253
+ beforeExpand?: (e: WbExpandEventType) => WbCancelableEventResultType;
1229
1254
  /**
1230
1255
  *
1231
- * Return `false` to prevent default handling, e.g. activating the node.
1256
+ * Return `false` to prevent default handling, i.e. (de)selecting the node.
1232
1257
  * @category Callback
1233
1258
  */
1234
- beforeActivate?: (e: WbActivateEventType) => void;
1259
+ beforeSelect?: (e: WbSelectEventType) => WbCancelableEventResultType;
1235
1260
  /**
1236
1261
  *
1237
1262
  * @category Callback
@@ -1239,39 +1264,46 @@ declare module "wb_options" {
1239
1264
  change?: (e: WbChangeEventType) => void;
1240
1265
  /**
1241
1266
  *
1242
- * Return `false` to prevent default handling, e.g. activating the node.
1267
+ * Return `false` to prevent default behavior, e.g. expand/collapse, (de)selection, or activation.
1243
1268
  * @category Callback
1244
1269
  */
1245
- click?: (e: WbClickEventType) => void;
1270
+ click?: (e: WbClickEventType) => WbCancelableEventResultType;
1246
1271
  /**
1247
- *
1272
+ * Return `false` to prevent default behavior, e.g. expand/collapse.
1248
1273
  * @category Callback
1249
1274
  */
1250
- dblclick?: (e: WbClickEventType) => void;
1275
+ dblclick?: (e: WbClickEventType) => WbCancelableEventResultType;
1251
1276
  /**
1277
+ * `e.node` was deactivated.
1252
1278
  *
1253
1279
  * Return `false` to prevent default handling, e.g. deactivating the node
1254
1280
  * and activating the next.
1281
+ * See also `activate` event.
1255
1282
  * @category Callback
1256
1283
  */
1257
- deactivate?: (e: WbDeactivateEventType) => void;
1284
+ deactivate?: (e: WbDeactivateEventType) => WbCancelableEventResultType;
1258
1285
  /**
1259
- *
1286
+ * `e.node` was discarded from the viewport and its HTML markup removed.
1260
1287
  * @category Callback
1261
1288
  */
1262
1289
  discard?: (e: WbNodeEventType) => void;
1263
1290
  /**
1264
- *
1291
+ * `e.node` is about to be rendered. We can add a badge to the icon cell here.
1265
1292
  * @category Callback
1266
1293
  */
1267
- iconBadge?: WbIconBadgeCallback;
1294
+ iconBadge?: (e: WbIconBadgeCallback) => WbIconBadgeEventResultType;
1268
1295
  /**
1269
- *
1296
+ * An error occurred, e.g. during initialization or lazy loading.
1270
1297
  * @category Callback
1271
1298
  */
1272
1299
  error?: (e: WbErrorEventType) => void;
1273
1300
  /**
1274
- *
1301
+ * `e.node` was expanded (`e.flag === true`) or collapsed (`e.flag === false`)
1302
+ * @category Callback
1303
+ */
1304
+ expand?: (e: WbTreeEventType) => void;
1305
+ /**
1306
+ * The tree received or lost focus.
1275
1307
  * Check `e.flag` for status.
1276
1308
  * @category Callback
1277
1309
  */
@@ -1280,15 +1312,17 @@ declare module "wb_options" {
1280
1312
  * Fires when the tree markup was created and the initial source data was loaded.
1281
1313
  * Typical use cases would be activating a node, setting focus, enabling other
1282
1314
  * controls on the page, etc.<br>
1283
- * Check `e.error` for status.
1315
+ * Also sent if an error occured during initialization (check `e.error` for status).
1284
1316
  * @category Callback
1285
1317
  */
1286
1318
  init?: (e: WbInitEventType) => void;
1287
1319
  /**
1288
- *
1320
+ * Fires when a key was pressed while the tree has focus.
1321
+ * `e.node` is set if a node is currently active.
1322
+ * Return `false` to prevent default navigation.
1289
1323
  * @category Callback
1290
1324
  */
1291
- keydown?: (e: WbKeydownEventType) => void;
1325
+ keydown?: (e: WbKeydownEventType) => WbCancelableEventResultType;
1292
1326
  /**
1293
1327
  * Fires when a node that was marked 'lazy', is expanded for the first time.
1294
1328
  * Typically we return an endpoint URL or the Promise of a fetch request that
@@ -1324,13 +1358,12 @@ declare module "wb_options" {
1324
1358
  */
1325
1359
  render?: (e: WbRenderEventType) => void;
1326
1360
  /**
1327
- *
1361
+ * Same as `render(e)`, but for the status nodes, i.e. `e.node.statusNodeType`.
1328
1362
  * @category Callback
1329
1363
  */
1330
1364
  renderStatusNode?: (e: WbRenderEventType) => void;
1331
1365
  /**
1332
- *
1333
- * Check `e.flag` for status.
1366
+ *`e.node` was selected (`e.flag === true`) or deselected (`e.flag === false`)
1334
1367
  * @category Callback
1335
1368
  */
1336
1369
  select?: (e: WbNodeEventType) => void;
@@ -1440,6 +1473,8 @@ declare module "types" {
1440
1473
  /** Other data is passed to `node.data` and can be accessed via `node.data.NAME` */
1441
1474
  [key: string]: unknown;
1442
1475
  }
1476
+ /** A callback that receives a node instance and returns a string value. */
1477
+ export type WbCancelableEventResultType = false | void;
1443
1478
  export interface WbTreeEventType {
1444
1479
  /** Name of the event. */
1445
1480
  type: string;
@@ -1538,6 +1573,11 @@ declare module "types" {
1538
1573
  /** Additional information derived from the original keyboard event. */
1539
1574
  info: WbEventInfo;
1540
1575
  }
1576
+ export interface WbModifyChildEventType extends WbNodeEventType {
1577
+ /** Type of change: 'add', 'remove', 'rename', 'move', 'data', ... */
1578
+ operation: string;
1579
+ child: WunderbaumNode;
1580
+ }
1541
1581
  export interface WbReceiveEventType extends WbNodeEventType {
1542
1582
  response: any;
1543
1583
  }
@@ -2023,27 +2063,43 @@ declare module "types" {
2023
2063
  validity?: boolean;
2024
2064
  /**
2025
2065
  * `beforeEdit(e)` may return an input HTML string. Otherwise use a default.
2066
+ * @category Callback
2026
2067
  */
2027
2068
  beforeEdit?: null | ((e: WbNodeEventType) => boolean) | string;
2028
2069
  /**
2029
2070
  *
2071
+ * @category Callback
2030
2072
  */
2031
2073
  edit?: null | ((e: WbNodeEventType & {
2032
2074
  inputElem: HTMLInputElement;
2033
2075
  }) => void);
2034
2076
  /**
2035
2077
  *
2078
+ * @category Callback
2036
2079
  */
2037
2080
  apply?: null | ((e: WbNodeEventType & {
2038
2081
  inputElem: HTMLInputElement;
2039
2082
  }) => any) | Promise<any>;
2040
2083
  };
2041
- export type GridOptionsType = object;
2042
2084
  export type InsertNodeType = "before" | "after" | "prependChild" | "appendChild";
2043
2085
  export type DropEffectType = "none" | "copy" | "link" | "move";
2044
2086
  export type DropEffectAllowedType = "none" | "copy" | "copyLink" | "copyMove" | "link" | "linkMove" | "move" | "all";
2045
2087
  export type DropRegionType = "over" | "before" | "after";
2046
2088
  export type DropRegionTypeSet = Set<DropRegionType>;
2089
+ export interface DragEventType extends WbNodeEventType {
2090
+ /** The original event. */
2091
+ event: DragEvent;
2092
+ /** The source node. */
2093
+ node: WunderbaumNode;
2094
+ }
2095
+ export interface DropEventType extends WbNodeEventType {
2096
+ /** The original event. */
2097
+ event: DragEvent;
2098
+ /** The target node. */
2099
+ node: WunderbaumNode;
2100
+ /** The source node if any. */
2101
+ sourceNode: WunderbaumNode;
2102
+ }
2047
2103
  export type DndOptionsType = {
2048
2104
  /**
2049
2105
  * Expand nodes after n milliseconds of hovering
@@ -2129,53 +2185,49 @@ declare module "types" {
2129
2185
  /**
2130
2186
  * Optional callback passed to `toDict` on dragStart @since 2.38
2131
2187
  * @default null
2188
+ * @category Callback
2132
2189
  */
2133
2190
  sourceCopyHook?: null;
2134
2191
  /**
2135
2192
  * Callback(sourceNode, data), return true, to enable dnd drag
2136
2193
  * @default null
2194
+ * @category Callback
2137
2195
  */
2138
- dragStart?: null | ((e: WbNodeEventType & {
2139
- event: DragEvent;
2140
- }) => boolean);
2196
+ dragStart?: null | ((e: DragEventType) => boolean);
2141
2197
  /**
2142
2198
  * Callback(sourceNode, data)
2143
2199
  * @default null
2200
+ * @category Callback
2144
2201
  */
2145
- drag?: null | ((e: WbNodeEventType & {
2146
- event: DragEvent;
2147
- }) => void);
2202
+ drag?: null | ((e: DragEventType) => void);
2148
2203
  /**
2149
2204
  * Callback(sourceNode, data)
2150
2205
  * @default null
2206
+ * @category Callback
2151
2207
  */
2152
- dragEnd?: null | ((e: WbNodeEventType & {
2153
- event: DragEvent;
2154
- }) => void);
2208
+ dragEnd?: null | ((e: DragEventType) => void);
2155
2209
  /**
2156
2210
  * Callback(targetNode, data), return true, to enable dnd drop
2157
2211
  * @default null
2212
+ * @category Callback
2158
2213
  */
2159
- dragEnter?: null | ((e: WbNodeEventType & {
2160
- event: DragEvent;
2161
- }) => DropRegionTypeSet | boolean);
2214
+ dragEnter?: null | ((e: DropEventType) => DropRegionType | DropRegionTypeSet | boolean);
2162
2215
  /**
2163
2216
  * Callback(targetNode, data)
2164
2217
  * @default null
2218
+ * @category Callback
2165
2219
  */
2166
- dragOver?: null | ((e: WbNodeEventType & {
2167
- event: DragEvent;
2168
- }) => void);
2220
+ dragOver?: null | ((e: DropEventType) => void);
2169
2221
  /**
2170
2222
  * Callback(targetNode, data), return false to prevent autoExpand
2171
2223
  * @default null
2224
+ * @category Callback
2172
2225
  */
2173
- dragExpand?: null | ((e: WbNodeEventType & {
2174
- event: DragEvent;
2175
- }) => boolean);
2226
+ dragExpand?: null | ((e: DropEventType) => boolean);
2176
2227
  /**
2177
2228
  * Callback(targetNode, data)
2178
2229
  * @default null
2230
+ * @category Callback
2179
2231
  */
2180
2232
  drop?: null | ((e: WbNodeEventType & {
2181
2233
  event: DragEvent;
@@ -2188,9 +2240,13 @@ declare module "types" {
2188
2240
  /**
2189
2241
  * Callback(targetNode, data)
2190
2242
  * @default null
2243
+ * @category Callback
2191
2244
  */
2192
- dragLeave?: null;
2245
+ dragLeave?: null | ((e: DropEventType) => void);
2193
2246
  };
2247
+ export type GridOptionsType = object;
2248
+ export type KeynavOptionsType = object;
2249
+ export type LoggerOptionsType = object;
2194
2250
  }
2195
2251
  declare module "wb_extension_base" {
2196
2252
  import { Wunderbaum } from "wunderbaum";
@@ -2244,9 +2300,15 @@ declare module "wb_ext_filter" {
2244
2300
  }
2245
2301
  }
2246
2302
  declare module "wb_ext_keynav" {
2303
+ /*!
2304
+ * Wunderbaum - ext-keynav
2305
+ * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
2306
+ * @VERSION, @DATE (https://github.com/mar10/wunderbaum)
2307
+ */
2308
+ import { KeynavOptionsType } from "types";
2247
2309
  import { Wunderbaum } from "wunderbaum";
2248
2310
  import { WunderbaumExtension } from "wb_extension_base";
2249
- export class KeynavExtension extends WunderbaumExtension<any> {
2311
+ export class KeynavExtension extends WunderbaumExtension<KeynavOptionsType> {
2250
2312
  constructor(tree: Wunderbaum);
2251
2313
  protected _getEmbeddedInputElem(elem: any): HTMLInputElement | null;
2252
2314
  protected _isCurInputFocused(): boolean;
@@ -2254,9 +2316,15 @@ declare module "wb_ext_keynav" {
2254
2316
  }
2255
2317
  }
2256
2318
  declare module "wb_ext_logger" {
2319
+ /*!
2320
+ * Wunderbaum - ext-logger
2321
+ * Copyright (c) 2021-2023, Martin Wendt. Released under the MIT license.
2322
+ * @VERSION, @DATE (https://github.com/mar10/wunderbaum)
2323
+ */
2324
+ import { LoggerOptionsType } from "types";
2257
2325
  import { WunderbaumExtension } from "wb_extension_base";
2258
2326
  import { Wunderbaum } from "wunderbaum";
2259
- export class LoggerExtension extends WunderbaumExtension<any> {
2327
+ export class LoggerExtension extends WunderbaumExtension<LoggerOptionsType> {
2260
2328
  readonly prefix: string;
2261
2329
  protected ignoreEvents: Set<string>;
2262
2330
  constructor(tree: Wunderbaum);
@@ -2479,10 +2547,16 @@ declare module "wunderbaum" {
2479
2547
  protected treeRowCount: number;
2480
2548
  protected _disableUpdateCount: number;
2481
2549
  protected _disableUpdateIgnoreCount: number;
2482
- /** Currently active node if any. */
2483
- activeNode: WunderbaumNode | null;
2484
- /** Current node hat has keyboard focus if any. */
2485
- focusNode: WunderbaumNode | null;
2550
+ protected _activeNode: WunderbaumNode | null;
2551
+ protected _focusNode: WunderbaumNode | null;
2552
+ /** Currently active node if any.
2553
+ * Use @link {WunderbaumNode.setActive|setActive} to modify.
2554
+ */
2555
+ get activeNode(): WunderbaumNode;
2556
+ /** Current node hat has keyboard focus if any.
2557
+ * Use @link {WunderbaumNode.setFocus|setFocus()} to modify.
2558
+ */
2559
+ get focusNode(): WunderbaumNode;
2486
2560
  /** Shared properties, referenced by `node.type`. */
2487
2561
  types: NodeTypeDefinitionMap;
2488
2562
  /** List of column definitions. */
@@ -2740,10 +2814,13 @@ declare module "wunderbaum" {
2740
2814
  */
2741
2815
  getActiveColElem(): HTMLSpanElement;
2742
2816
  /**
2743
- * Return the currently active node or null.
2817
+ * Return the currently active node or null (alias for `tree.activeNode`).
2818
+ * Alias for {@link Wunderbaum.activeNode}.
2819
+ *
2744
2820
  * @see {@link WunderbaumNode.setActive}
2745
2821
  * @see {@link WunderbaumNode.isActive}
2746
- * @see {@link WunderbaumNode.getFocusNode}
2822
+ * @see {@link Wunderbaum.activeNode}
2823
+ * @see {@link Wunderbaum.focusNode}
2747
2824
  */
2748
2825
  getActiveNode(): WunderbaumNode;
2749
2826
  /**
@@ -2752,7 +2829,11 @@ declare module "wunderbaum" {
2752
2829
  getFirstChild(): WunderbaumNode;
2753
2830
  /**
2754
2831
  * Return the node that currently has keyboard focus or null.
2755
- * @see {@link WunderbaumNode.getActiveNode}
2832
+ * Alias for {@link Wunderbaum.focusNode}.
2833
+ * @see {@link WunderbaumNode.setFocus}
2834
+ * @see {@link WunderbaumNode.hasFocus}
2835
+ * @see {@link Wunderbaum.activeNode}
2836
+ * @see {@link Wunderbaum.focusNode}
2756
2837
  */
2757
2838
  getFocusNode(): WunderbaumNode;
2758
2839
  /** Return a {node: WunderbaumNode, region: TYPE} object for a mouse event.
@@ -2781,21 +2862,24 @@ declare module "wunderbaum" {
2781
2862
  * Return true if any node is currently beeing loaded, i.e. a Ajax request is pending.
2782
2863
  */
2783
2864
  isLoading(): boolean;
2784
- /** Alias for {@link Wunderbaum.logDebug}.
2785
- * @alias Wunderbaum.logDebug
2865
+ /** Write to `console.log` with tree name as prefix if opts.debugLevel >= 4.
2866
+ * @see {@link Wunderbaum.logDebug}
2867
+ */
2868
+ log(...args: any[]): void;
2869
+ /** Write to `console.debug` with tree name as prefix if opts.debugLevel >= 4.
2870
+ * and browser console level includes debug/verbose messages.
2871
+ * @see {@link Wunderbaum.log}
2786
2872
  */
2787
- log: (...args: any[]) => void;
2788
- /** Log to console if opts.debugLevel >= 4 */
2789
2873
  logDebug(...args: any[]): void;
2790
- /** Log error to console. */
2874
+ /** Write to `console.error` with tree name as prefix. */
2791
2875
  logError(...args: any[]): void;
2792
- /** Log to console if opts.debugLevel >= 3 */
2876
+ /** Write to `console.info` with tree name as prefix if opts.debugLevel >= 3. */
2793
2877
  logInfo(...args: any[]): void;
2794
2878
  /** @internal */
2795
2879
  logTime(label: string): string;
2796
2880
  /** @internal */
2797
2881
  logTimeEnd(label: string): void;
2798
- /** Log to console if opts.debugLevel >= 2 */
2882
+ /** Write to `console.warn` with tree name as prefix with if opts.debugLevel >= 2. */
2799
2883
  logWarn(...args: any[]): void;
2800
2884
  /**
2801
2885
  * Make sure that this node is vertically scrolled into the viewport.
@@ -2820,10 +2904,12 @@ declare module "wunderbaum" {
2820
2904
  * colIdx is 0, the node title is put into edit mode.
2821
2905
  */
2822
2906
  setColumn(colIdx: number | string, options?: SetColumnOptions): void;
2907
+ _setActiveNode(node: WunderbaumNode | null): void;
2823
2908
  /** Set or remove keyboard focus to the tree container. */
2824
2909
  setActiveNode(key: string, flag?: boolean, options?: SetActiveOptions): void;
2825
2910
  /** Set or remove keyboard focus to the tree container. */
2826
2911
  setFocus(flag?: boolean): void;
2912
+ _setFocusNode(node: WunderbaumNode | null): void;
2827
2913
  /**
2828
2914
  * Schedule an update request to reflect a tree change.
2829
2915
  * The render operation is async and debounced unless the `immediate` option