@ims360/svelte-ivory 0.0.46 → 0.0.48
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/dist/components/table/Column.svelte +29 -26
- package/dist/components/table/Column.svelte.d.ts.map +1 -1
- package/dist/components/table/ColumnHead.svelte +3 -5
- package/dist/components/table/ColumnHead.svelte.d.ts.map +1 -1
- package/dist/components/table/Row.svelte +25 -52
- package/dist/components/table/Row.svelte.d.ts +6 -4
- package/dist/components/table/Row.svelte.d.ts.map +1 -1
- package/dist/components/table/Table.svelte +74 -32
- package/dist/components/table/Table.svelte.d.ts +18 -8
- package/dist/components/table/Table.svelte.d.ts.map +1 -1
- package/dist/components/table/VirtualList.svelte +8 -5
- package/dist/components/table/VirtualList.svelte.d.ts +13 -3
- package/dist/components/table/VirtualList.svelte.d.ts.map +1 -1
- package/dist/components/table/controller.d.ts +3 -2
- package/dist/components/table/controller.d.ts.map +1 -1
- package/dist/components/table/index.d.ts +1 -2
- package/dist/components/table/index.d.ts.map +1 -1
- package/dist/components/table/index.js +0 -1
- package/dist/components/table/search.svelte.d.ts +8 -0
- package/dist/components/table/search.svelte.d.ts.map +1 -0
- package/dist/components/table/search.svelte.js +28 -0
- package/package.json +33 -32
- package/src/lib/components/table/Column.svelte +29 -26
- package/src/lib/components/table/ColumnHead.svelte +3 -5
- package/src/lib/components/table/Row.svelte +25 -52
- package/src/lib/components/table/Table.svelte +74 -32
- package/src/lib/components/table/VirtualList.svelte +8 -5
- package/src/lib/components/table/controller.ts +4 -2
- package/src/lib/components/table/index.ts +1 -2
- package/src/lib/components/table/search.svelte.ts +34 -0
- package/dist/components/table/plugins/search.svelte.d.ts +0 -14
- package/dist/components/table/plugins/search.svelte.d.ts.map +0 -1
- package/dist/components/table/plugins/search.svelte.js +0 -55
- package/src/lib/components/table/plugins/search.svelte.ts +0 -66
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { SvelteSet } from 'svelte/reactivity';
|
|
2
|
-
export function searchPlugin(conf) {
|
|
3
|
-
let prevSearch = undefined;
|
|
4
|
-
let expandedBeforeSearch = undefined;
|
|
5
|
-
const middleware = (state) => {
|
|
6
|
-
// ensure that the state before the search is saved and restored when the user types
|
|
7
|
-
if (prevSearch && !conf.search && expandedBeforeSearch) {
|
|
8
|
-
prevSearch = conf.search;
|
|
9
|
-
return {
|
|
10
|
-
...state,
|
|
11
|
-
expanded: expandedBeforeSearch
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
if (!conf.search)
|
|
15
|
-
return state;
|
|
16
|
-
// ensure we store the state before the we started searching
|
|
17
|
-
if (conf.search && !prevSearch)
|
|
18
|
-
expandedBeforeSearch = state.expanded;
|
|
19
|
-
// figure out which nodes to expand and hide
|
|
20
|
-
const { expanded, hidden } = search(state.data, conf.search, conf.matches);
|
|
21
|
-
prevSearch = conf.search;
|
|
22
|
-
return {
|
|
23
|
-
data: state.data.filter((d) => !hidden.has(d.id)),
|
|
24
|
-
expanded: new SvelteSet(expanded)
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
return middleware;
|
|
28
|
-
}
|
|
29
|
-
/** collapses everything that doesnt match the searchString, expands direct search hit */
|
|
30
|
-
export const search = (nodes, searchString, stringsMatch) => {
|
|
31
|
-
const search = searchString.trim().toLowerCase();
|
|
32
|
-
const hidden = new SvelteSet();
|
|
33
|
-
const expanded = new SvelteSet();
|
|
34
|
-
function nodeMatches(node, childOfMatch = false) {
|
|
35
|
-
const matches = stringsMatch(node, search);
|
|
36
|
-
let intermediate = false;
|
|
37
|
-
for (const child of node.children || []) {
|
|
38
|
-
const childMatches = nodeMatches(child, matches || childOfMatch);
|
|
39
|
-
if (childMatches)
|
|
40
|
-
intermediate = true;
|
|
41
|
-
}
|
|
42
|
-
if (intermediate) {
|
|
43
|
-
expanded.add(node.id);
|
|
44
|
-
}
|
|
45
|
-
else if (!childOfMatch && !matches) {
|
|
46
|
-
hidden.add(node.id);
|
|
47
|
-
}
|
|
48
|
-
return matches || intermediate;
|
|
49
|
-
}
|
|
50
|
-
nodes.forEach((n) => nodeMatches(n));
|
|
51
|
-
return {
|
|
52
|
-
hidden,
|
|
53
|
-
expanded
|
|
54
|
-
};
|
|
55
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { SvelteSet } from 'svelte/reactivity';
|
|
2
|
-
import type { TablePlugin, TableRow } from '../';
|
|
3
|
-
|
|
4
|
-
interface SearchConfig<T extends TableRow<T>> {
|
|
5
|
-
search: string;
|
|
6
|
-
matches: (row: T) => boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function searchPlugin<T extends TableRow<T>>(conf: SearchConfig<T>): TablePlugin<T> {
|
|
10
|
-
let prevSearch: string | undefined = undefined;
|
|
11
|
-
let expandedBeforeSearch: Set<string> | undefined = undefined;
|
|
12
|
-
|
|
13
|
-
const middleware: TablePlugin<T> = (state) => {
|
|
14
|
-
// ensure that the state before the search is saved and restored when the user types
|
|
15
|
-
if (prevSearch && !conf.search && expandedBeforeSearch) {
|
|
16
|
-
prevSearch = conf.search;
|
|
17
|
-
return {
|
|
18
|
-
...state,
|
|
19
|
-
expanded: expandedBeforeSearch
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
if (!conf.search) return state;
|
|
23
|
-
// ensure we store the state before the we started searching
|
|
24
|
-
if (conf.search && !prevSearch) expandedBeforeSearch = state.expanded;
|
|
25
|
-
// figure out which nodes to expand and hide
|
|
26
|
-
const { expanded, hidden } = search(state.data, conf.search, conf.matches);
|
|
27
|
-
prevSearch = conf.search;
|
|
28
|
-
return {
|
|
29
|
-
data: state.data.filter((d) => !hidden.has(d.id)),
|
|
30
|
-
expanded: new SvelteSet(expanded)
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
return middleware;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** collapses everything that doesnt match the searchString, expands direct search hit */
|
|
37
|
-
export const search = <T extends TableRow<T>>(
|
|
38
|
-
nodes: T[],
|
|
39
|
-
searchString: string,
|
|
40
|
-
stringsMatch: (a: T, b: string) => boolean
|
|
41
|
-
) => {
|
|
42
|
-
const search = searchString.trim().toLowerCase();
|
|
43
|
-
const hidden = new SvelteSet<string>();
|
|
44
|
-
const expanded = new SvelteSet<string>();
|
|
45
|
-
|
|
46
|
-
function nodeMatches(node: T, childOfMatch = false): boolean {
|
|
47
|
-
const matches = stringsMatch(node, search);
|
|
48
|
-
let intermediate = false;
|
|
49
|
-
for (const child of node.children || []) {
|
|
50
|
-
const childMatches = nodeMatches(child, matches || childOfMatch);
|
|
51
|
-
if (childMatches) intermediate = true;
|
|
52
|
-
}
|
|
53
|
-
if (intermediate) {
|
|
54
|
-
expanded.add(node.id);
|
|
55
|
-
} else if (!childOfMatch && !matches) {
|
|
56
|
-
hidden.add(node.id);
|
|
57
|
-
}
|
|
58
|
-
return matches || intermediate;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
nodes.forEach((n) => nodeMatches(n));
|
|
62
|
-
return {
|
|
63
|
-
hidden,
|
|
64
|
-
expanded
|
|
65
|
-
};
|
|
66
|
-
};
|