datatable-tree 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +240 -2
- package/dist/DataTable.d.ts +583 -0
- package/dist/DataTable.js +620 -0
- package/dist/Draggable.d.ts +35 -0
- package/dist/Draggable.js +91 -0
- package/dist/ListBox.d.ts +132 -0
- package/dist/ListBox.js +243 -0
- package/dist/ListVirtualizer.d.ts +59 -0
- package/dist/ListVirtualizer.js +180 -0
- package/dist/TreeList.d.ts +196 -0
- package/dist/TreeList.js +300 -0
- package/dist/config.d.ts +55 -0
- package/dist/config.js +33 -0
- package/dist/datatable.css +161 -0
- package/dist/hooks.d.ts +27 -0
- package/dist/hooks.js +115 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +15 -0
- package/dist/interfaces.d.ts +269 -0
- package/dist/interfaces.js +3 -0
- package/dist/mobx-adapter.d.ts +12 -0
- package/dist/mobx-adapter.js +21 -0
- package/dist/reactivity.d.ts +112 -0
- package/dist/reactivity.js +155 -0
- package/dist/styles.d.ts +64 -0
- package/dist/styles.js +86 -0
- package/dist/theme.d.ts +160 -0
- package/dist/theme.js +239 -0
- package/dist/util.d.ts +28 -0
- package/dist/util.js +45 -0
- package/package.json +137 -4
- package/src/DataTable.tsx +1332 -0
- package/src/Draggable.tsx +133 -0
- package/src/ListBox.tsx +423 -0
- package/src/ListVirtualizer.ts +234 -0
- package/src/TreeList.tsx +590 -0
- package/src/config.tsx +96 -0
- package/src/css.d.ts +1 -0
- package/src/datatable.css +161 -0
- package/src/hooks.ts +138 -0
- package/src/index.ts +15 -0
- package/src/interfaces.ts +309 -0
- package/src/mobx-adapter.ts +24 -0
- package/src/reactivity.ts +222 -0
- package/src/styles.tsx +102 -0
- package/src/theme.ts +346 -0
- package/src/util.ts +60 -0
package/src/util.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { IMapSource, ISet } from './interfaces.js';
|
|
2
|
+
|
|
3
|
+
/** Shorthand for `null | undefined`, i.e. the states a value can have when it's absent. */
|
|
4
|
+
export type nully = null | undefined;
|
|
5
|
+
|
|
6
|
+
/** Makes the properties `K` of `T` optional, e.g. `Optionalize<Props, 'color'|'size'>`. */
|
|
7
|
+
export type Optionalize<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
8
|
+
|
|
9
|
+
/** Creates a new object whose prototype is the given object, so that properties of the
|
|
10
|
+
* original object are visible on the new object, but new properties can be added without
|
|
11
|
+
* modifying the original. */
|
|
12
|
+
export function newObjectWithPrototype<T extends object>(prototype: T): T {
|
|
13
|
+
return Object.create(prototype);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Converts each key-value pair of a map to an element of an output array, like Array.map. */
|
|
17
|
+
export function mapMap<K,V,R>(map: IMapSource<K,V>, mapper: (k: K, v: V, index: number) => R): R[] {
|
|
18
|
+
let result: R[] = [];
|
|
19
|
+
map.forEach(
|
|
20
|
+
function(this: { result: R[], index: number }, v: V, k: K) {
|
|
21
|
+
this.result.push(mapper(k, v, this.index++));
|
|
22
|
+
},
|
|
23
|
+
{ result, index: 0 });
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Adds `key` to the set if it is absent, or removes it if it is present. */
|
|
28
|
+
export function toggleSetMembership<T>(set: ISet<T>, key: T) {
|
|
29
|
+
if (set.has(key)) {
|
|
30
|
+
set.delete(key);
|
|
31
|
+
} else {
|
|
32
|
+
set.add(key);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** True on macOS/iOS, where ⌘ plays the role that Ctrl plays elsewhere (the OS treats
|
|
37
|
+
* Ctrl+click as a right-click, so Ctrl can't be used as a mouse modifier there). */
|
|
38
|
+
export const isMacLike = typeof navigator !== 'undefined' && /Mac|iP(hone|ad|od)/.test(navigator.userAgent);
|
|
39
|
+
|
|
40
|
+
/** Whether the platform's multi-select mouse modifier is held: ⌘ on Mac (where Ctrl+click
|
|
41
|
+
* means right-click), Ctrl elsewhere. Use for mouse events; keyboard shortcuts should
|
|
42
|
+
* usually accept either key since the OS reserves different combos on each platform. */
|
|
43
|
+
export function isCtrlOrCmd(e: Readonly<{ ctrlKey?: boolean, metaKey?: boolean }>) {
|
|
44
|
+
return isMacLike ? !!e.metaKey : !!e.ctrlKey;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Returns a copy of `obj` without the specified keys (replaces lodash `omit`). */
|
|
48
|
+
export function omit<T extends object, K extends keyof T>(obj: T, ...keys: K[]): Omit<T, K> {
|
|
49
|
+
let result = { ...obj };
|
|
50
|
+
for (let key of keys) {
|
|
51
|
+
delete result[key];
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Combines class names, ignoring null/undefined/false/'' (replaces the `classnames`
|
|
57
|
+
* package for the simple case of string arguments). */
|
|
58
|
+
export function cx(...classes: Array<string | false | nully>): string {
|
|
59
|
+
return classes.filter(c => c).join(' ');
|
|
60
|
+
}
|