wunderbaum 0.5.1 → 0.5.3

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/src/common.ts CHANGED
@@ -193,7 +193,7 @@ function unflattenSource(source: any): void {
193
193
  );
194
194
  }
195
195
  // Inverse keyMap:
196
- let longToShort: any = {};
196
+ const longToShort: any = {};
197
197
  if (_keyMap) {
198
198
  for (const [key, value] of Object.entries(_keyMap)) {
199
199
  longToShort[<string>value] = key;
@@ -277,7 +277,7 @@ export function inflateSourceData(source: any): void {
277
277
  delete source._positional;
278
278
 
279
279
  function _iter(childList: any[]) {
280
- for (let node of childList) {
280
+ for (const node of childList) {
281
281
  // Expand short alias names
282
282
  if (_keyMap) {
283
283
  // Iterate over a list of names, because we modify inside the loop:
package/src/debounce.ts CHANGED
@@ -270,6 +270,7 @@ export function debounce<F extends Procedure>(
270
270
  const isInvoking = shouldInvoke(time);
271
271
 
272
272
  lastArgs = args;
273
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
273
274
  lastThis = this;
274
275
  lastCallTime = time;
275
276
 
package/src/types.ts CHANGED
@@ -187,7 +187,7 @@ export interface WbIconBadgeEventResultType {
187
187
  badge: string | number | HTMLSpanElement | null | false;
188
188
  /** Additional class name(s), separate with space. */
189
189
  badgeClass?: string;
190
- /** Additional class name(s), separate with space. */
190
+ /** Tooltip for the badge. */
191
191
  badgeTooltip?: string;
192
192
  }
193
193
 
@@ -471,6 +471,8 @@ export interface ExpandAllOptions {
471
471
  loadLazy?: boolean;
472
472
  /** Ignore `minExpandLevel` option @default false */
473
473
  force?: boolean;
474
+ /** Keep active node visible @default true */
475
+ keepActiveNodeVisible?: boolean;
474
476
  }
475
477
 
476
478
  /** Possible values for {@link Wunderbaum.filterNodes()} and {@link Wunderbaum.filterBranches()}. */
@@ -613,6 +615,124 @@ export interface VisitRowsOptions {
613
615
  wrap?: boolean;
614
616
  }
615
617
 
618
+ export type FilterOptionsType = {
619
+ /**
620
+ * Element or selector of an input control for filter query strings
621
+ * @default null
622
+ */
623
+ connectInput?: null | string | Element;
624
+ /**
625
+ * Re-apply last filter if lazy data is loaded
626
+ * @default true
627
+ */
628
+ autoApply?: boolean;
629
+ /**
630
+ * Expand all branches that contain matches while filtered
631
+ * @default false
632
+ */
633
+ autoExpand?: boolean;
634
+ /**
635
+ * Show a badge with number of matching child nodes near parent icons
636
+ * @default true
637
+ */
638
+ counter?: boolean;
639
+ /**
640
+ * Match single characters in order, e.g. 'fb' will match 'FooBar'
641
+ * @default false
642
+ */
643
+ fuzzy?: boolean;
644
+ /**
645
+ * Hide counter badge if parent is expanded
646
+ * @default true
647
+ */
648
+ hideExpandedCounter?: boolean;
649
+ /**
650
+ * Hide expanders if all child nodes are hidden by filter
651
+ * @default false;
652
+ */
653
+ hideExpanders?: boolean;
654
+ /**
655
+ * Highlight matches by wrapping inside <mark> tags
656
+ * @default true
657
+ */
658
+ highlight?: boolean;
659
+ /**
660
+ * Match end nodes only
661
+ * @default false
662
+ */
663
+ leavesOnly?: boolean;
664
+ /**
665
+ * Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
666
+ * @default 'dim'
667
+ */
668
+ mode?: "dim" | "hide";
669
+ /**
670
+ * Display a 'no data' status node if result is empty
671
+ * @default true
672
+ */
673
+ noData?: boolean;
674
+ };
675
+
676
+ export type EditOptionsType = {
677
+ /**
678
+ * @default 100
679
+ */
680
+ debounce?: number;
681
+ /**
682
+ * @default 1
683
+ */
684
+ minlength?: number;
685
+ /**
686
+ * @default null;
687
+ */
688
+ maxlength?: null | number;
689
+ /**
690
+ * ["clickActive", "F2", "macEnter"],
691
+ * @default []
692
+ */
693
+ trigger?: string[];
694
+ /**
695
+ * @default true
696
+ */
697
+ trim?: boolean;
698
+ /**
699
+ * @default true
700
+ */
701
+ select?: boolean;
702
+ /**
703
+ * Handle 'clickActive' only if last click is less than this old (0: always)
704
+ * @default 1000
705
+ */
706
+ slowClickDelay?: number;
707
+ /**
708
+ * Please enter a title",
709
+ * @default true
710
+ */
711
+ validity?: boolean;
712
+
713
+ // --- Events ---
714
+ // (note: there is also the `tree.change` event.)
715
+ /**
716
+ * `beforeEdit(e)` may return an input HTML string. Otherwise use a default.
717
+ */
718
+ beforeEdit?: null | ((e: WbNodeEventType) => boolean) | string;
719
+ /**
720
+ *
721
+ */
722
+ edit?:
723
+ | null
724
+ | ((e: WbNodeEventType & { inputElem: HTMLInputElement }) => void);
725
+ /**
726
+ *
727
+ */
728
+ apply?:
729
+ | null
730
+ | ((e: WbNodeEventType & { inputElem: HTMLInputElement }) => any)
731
+ | Promise<any>;
732
+ };
733
+
734
+ export type GridOptionsType = object;
735
+
616
736
  /* -----------------------------------------------------------------------------
617
737
  * wb_ext_dnd
618
738
  * ---------------------------------------------------------------------------*/
@@ -641,7 +761,7 @@ export type DndOptionsType = {
641
761
  * Expand nodes after n milliseconds of hovering
642
762
  * @default 1500
643
763
  */
644
- autoExpandMS: 1500;
764
+ autoExpandMS?: 1500;
645
765
  // /**
646
766
  // * Additional offset for drop-marker with hitMode = "before"/"after"
647
767
  // * @default
@@ -662,62 +782,67 @@ export type DndOptionsType = {
662
782
  * true: Drag multiple (i.e. selected) nodes. Also a callback() is allowed
663
783
  * @default false
664
784
  */
665
- multiSource: false;
785
+ multiSource?: false;
666
786
  /**
667
787
  * Restrict the possible cursor shapes and modifier operations (can also be set in the dragStart event)
668
788
  * @default "all"
669
789
  */
670
- effectAllowed: "all";
790
+ effectAllowed?: "all";
671
791
  // /**
672
792
  // * 'copy'|'link'|'move'|'auto'(calculate from `effectAllowed`+modifier keys) or callback(node, data) that returns such string.
673
793
  // * @default
674
794
  // */
675
795
  // dropEffect: "auto";
676
796
  /**
677
- * Default dropEffect ('copy', 'link', or 'move') when no modifier is pressed (overide in dragDrag, dragOver).
797
+ * Default dropEffect ('copy', 'link', or 'move') when no modifier is pressed (overide in drag, dragOver).
678
798
  * @default "move"
679
799
  */
680
- dropEffectDefault: string;
800
+ dropEffectDefault?: string;
681
801
  /**
682
802
  * Prevent dropping nodes from different Wunderbaum trees
683
803
  * @default false
684
804
  */
685
- preventForeignNodes: boolean;
805
+ preventForeignNodes?: boolean;
686
806
  /**
687
807
  * Prevent dropping items on unloaded lazy Wunderbaum tree nodes
688
808
  * @default true
689
809
  */
690
- preventLazyParents: boolean;
810
+ preventLazyParents?: boolean;
691
811
  /**
692
812
  * Prevent dropping items other than Wunderbaum tree nodes
693
813
  * @default false
694
814
  */
695
- preventNonNodes: boolean;
815
+ preventNonNodes?: boolean;
696
816
  /**
697
817
  * Prevent dropping nodes on own descendants
698
818
  * @default true
699
819
  */
700
- preventRecursion: boolean;
820
+ preventRecursion?: boolean;
701
821
  /**
702
822
  * Prevent dropping nodes under same direct parent
703
823
  * @default false
704
824
  */
705
- preventSameParent: false;
825
+ preventSameParent?: false;
706
826
  /**
707
827
  * Prevent dropping nodes 'before self', etc. (move only)
708
828
  * @default true
709
829
  */
710
- preventVoidMoves: boolean;
830
+ preventVoidMoves?: boolean;
831
+ /**
832
+ * Serialize Node Data to datatransfer object
833
+ * @default true
834
+ */
835
+ serializeClipboardData?: boolean | ((nodeData: WbNodeData) => string);
711
836
  /**
712
837
  * Enable auto-scrolling while dragging
713
838
  * @default true
714
839
  */
715
- scroll: boolean;
840
+ scroll?: boolean;
716
841
  /**
717
842
  * Active top/bottom margin in pixel
718
843
  * @default 20
719
844
  */
720
- scrollSensitivity: 20;
845
+ scrollSensitivity?: 20;
721
846
  // /**
722
847
  // * Scroll events every N microseconds
723
848
  // * @default 50
@@ -727,7 +852,7 @@ export type DndOptionsType = {
727
852
  * Pixel per event
728
853
  * @default 5
729
854
  */
730
- scrollSpeed: 5;
855
+ scrollSpeed?: 5;
731
856
  // /**
732
857
  // * Allow dragging of nodes to different IE windows
733
858
  // * @default false
@@ -737,47 +862,56 @@ export type DndOptionsType = {
737
862
  * Optional callback passed to `toDict` on dragStart @since 2.38
738
863
  * @default null
739
864
  */
740
- sourceCopyHook: null;
865
+ sourceCopyHook?: null;
741
866
  // Events (drag support)
742
867
  /**
743
868
  * Callback(sourceNode, data), return true, to enable dnd drag
744
869
  * @default null
745
870
  */
746
- dragStart?: WbNodeEventType;
871
+ dragStart?: null | ((e: WbNodeEventType & { event: DragEvent }) => boolean);
747
872
  /**
748
873
  * Callback(sourceNode, data)
749
874
  * @default null
750
875
  */
751
- dragDrag: null;
876
+ drag?: null | ((e: WbNodeEventType & { event: DragEvent }) => void);
752
877
  /**
753
878
  * Callback(sourceNode, data)
754
879
  * @default null
755
880
  */
756
- dragEnd: null;
881
+ dragEnd?: null | ((e: WbNodeEventType & { event: DragEvent }) => void);
757
882
  // Events (drop support)
758
883
  /**
759
884
  * Callback(targetNode, data), return true, to enable dnd drop
760
885
  * @default null
761
886
  */
762
- dragEnter: null;
887
+ dragEnter?: null | ((e: WbNodeEventType & { event: DragEvent }) => boolean);
763
888
  /**
764
889
  * Callback(targetNode, data)
765
890
  * @default null
766
891
  */
767
- dragOver: null;
892
+ dragOver?: null | ((e: WbNodeEventType & { event: DragEvent }) => void);
768
893
  /**
769
894
  * Callback(targetNode, data), return false to prevent autoExpand
770
895
  * @default null
771
896
  */
772
- dragExpand: null;
897
+ dragExpand?: null | ((e: WbNodeEventType & { event: DragEvent }) => boolean);
773
898
  /**
774
899
  * Callback(targetNode, data)
775
900
  * @default null
776
901
  */
777
- dragDrop: null;
902
+ drop?:
903
+ | null
904
+ | ((
905
+ e: WbNodeEventType & {
906
+ event: DragEvent;
907
+ region: DropRegionType;
908
+ defaultDropMode: string;
909
+ sourceNode: WunderbaumNode;
910
+ }
911
+ ) => void);
778
912
  /**
779
913
  * Callback(targetNode, data)
780
914
  * @default null
781
915
  */
782
- dragLeave: null;
916
+ dragLeave?: null;
783
917
  };
package/src/util.ts CHANGED
@@ -137,8 +137,8 @@ export function each(
137
137
  // accept `null` or `undefined`
138
138
  return obj;
139
139
  }
140
- let length = obj.length,
141
- i = 0;
140
+ const length = obj.length;
141
+ let i = 0;
142
142
 
143
143
  if (typeof length === "number") {
144
144
  for (; i < length; i++) {
@@ -147,7 +147,7 @@ export function each(
147
147
  }
148
148
  }
149
149
  } else {
150
- for (let k in obj) {
150
+ for (const k in obj) {
151
151
  if (callback.call(obj[i], k, obj[k]) === false) {
152
152
  break;
153
153
  }
@@ -256,11 +256,13 @@ export function getValueFromElem(elem: HTMLElement, coerce = false): any {
256
256
  value = input.valueAsNumber;
257
257
  break;
258
258
  case "radio":
259
- const name = input.name;
260
- const checked = input.parentElement!.querySelector(
261
- `input[name="${name}"]:checked`
262
- );
263
- value = checked ? (<HTMLInputElement>checked).value : undefined;
259
+ {
260
+ const name = input.name;
261
+ const checked = input.parentElement!.querySelector(
262
+ `input[name="${name}"]:checked`
263
+ );
264
+ value = checked ? (<HTMLInputElement>checked).value : undefined;
265
+ }
264
266
  break;
265
267
  case "text":
266
268
  default:
@@ -438,9 +440,9 @@ export function eventTargetFromSelector(
438
440
  * ```
439
441
  */
440
442
  export function eventToString(event: Event): string {
441
- let key = (<KeyboardEvent>event).key,
442
- et = event.type,
443
- s = [];
443
+ const key = (<KeyboardEvent>event).key;
444
+ const et = event.type;
445
+ const s = [];
444
446
 
445
447
  if ((<KeyboardEvent>event).altKey) {
446
448
  s.push("Alt");
@@ -479,11 +481,11 @@ export function eventToString(event: Event): string {
479
481
  // TODO: support deep merge --> https://stackoverflow.com/a/42740894
480
482
  export function extend(...args: any[]) {
481
483
  for (let i = 1; i < args.length; i++) {
482
- let arg = args[i];
484
+ const arg = args[i];
483
485
  if (arg == null) {
484
486
  continue;
485
487
  }
486
- for (let key in arg) {
488
+ for (const key in arg) {
487
489
  if (Object.prototype.hasOwnProperty.call(arg, key)) {
488
490
  args[0][key] = arg[key];
489
491
  }
@@ -604,18 +606,17 @@ export function overrideMethod(
604
606
  handler: FunctionType,
605
607
  ctx?: any
606
608
  ) {
607
- let prevSuper: FunctionType,
608
- prevSuperApply: FunctionType,
609
- self = ctx || instance,
610
- prevFunc = instance[methodName],
611
- _super = (...args: any[]) => {
612
- return prevFunc.apply(self, args);
613
- },
614
- _superApply = (argsArray: any[]) => {
615
- return prevFunc.apply(self, argsArray);
616
- };
609
+ let prevSuper: FunctionType, prevSuperApply: FunctionType;
610
+ const self = ctx || instance;
611
+ const prevFunc = instance[methodName];
612
+ const _super = (...args: any[]) => {
613
+ return prevFunc.apply(self, args);
614
+ };
615
+ const _superApply = (argsArray: any[]) => {
616
+ return prevFunc.apply(self, argsArray);
617
+ };
617
618
 
618
- let wrapper = (...args: any[]) => {
619
+ const wrapper = (...args: any[]) => {
619
620
  try {
620
621
  prevSuper = self._super;
621
622
  prevSuperApply = self._superApply;
@@ -717,7 +718,7 @@ export function getOption(
717
718
  [ext, name] = name.split(".");
718
719
  opts = opts[ext];
719
720
  }
720
- let value = opts ? opts[name] : null;
721
+ const value = opts ? opts[name] : null;
721
722
  // Use value from value options dict, fallback do default
722
723
  return value ?? defaultValue;
723
724
  }
@@ -728,7 +729,7 @@ export function toSet(val: any): Set<string> {
728
729
  return val;
729
730
  }
730
731
  if (typeof val === "string") {
731
- let set = new Set<string>();
732
+ const set = new Set<string>();
732
733
  for (const c of val.split(" ")) {
733
734
  set.add(c.trim());
734
735
  }
@@ -812,7 +813,7 @@ export function adaptiveThrottle(
812
813
  try {
813
814
  callback.apply(this, useArgs);
814
815
  } catch (error) {
815
- console.error(error);
816
+ console.error(error); // eslint-disable-line no-console
816
817
  }
817
818
  const elap = Date.now() - start;
818
819