@ims360/svelte-ivory 0.0.30 → 0.0.31
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.
|
@@ -4,7 +4,7 @@ interface SearchConfig<T extends TableRow<T>> {
|
|
|
4
4
|
matches: (row: T) => boolean;
|
|
5
5
|
}
|
|
6
6
|
export declare function searchPlugin<T extends TableRow<T>>(conf: SearchConfig<T>): TablePlugin<T>;
|
|
7
|
-
/** collapses everything that doesnt match the searchString expands direct search hit */
|
|
7
|
+
/** collapses everything that doesnt match the searchString, expands direct search hit */
|
|
8
8
|
export declare const search: <T extends TableRow<T>>(nodes: T[], searchString: string, stringsMatch: (a: T, b: string) => boolean) => {
|
|
9
9
|
hidden: Set<string>;
|
|
10
10
|
expanded: Set<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/table/plugins/search.svelte.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAEjD,UAAU,YAAY,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC;CAChC;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"search.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/table/plugins/search.svelte.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAEjD,UAAU,YAAY,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC;CAChC;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CA6BzF;AAED,yFAAyF;AACzF,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,EACxC,OAAO,CAAC,EAAE,EACV,cAAc,MAAM,EACpB,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO;;;CA8B7C,CAAC"}
|
|
@@ -14,9 +14,8 @@ export function searchPlugin(conf) {
|
|
|
14
14
|
if (!conf.search)
|
|
15
15
|
return state;
|
|
16
16
|
// ensure we store the state before the we started searching
|
|
17
|
-
if (conf.search && !prevSearch)
|
|
17
|
+
if (conf.search && !prevSearch)
|
|
18
18
|
expandedBeforeSearch = state.expanded;
|
|
19
|
-
}
|
|
20
19
|
// figure out which nodes to expand and hide
|
|
21
20
|
const { expanded, hidden } = search(state.data, conf.search, conf.matches);
|
|
22
21
|
prevSearch = conf.search;
|
|
@@ -27,16 +26,16 @@ export function searchPlugin(conf) {
|
|
|
27
26
|
};
|
|
28
27
|
return middleware;
|
|
29
28
|
}
|
|
30
|
-
/** collapses everything that doesnt match the searchString expands direct search hit */
|
|
29
|
+
/** collapses everything that doesnt match the searchString, expands direct search hit */
|
|
31
30
|
export const search = (nodes, searchString, stringsMatch) => {
|
|
32
31
|
const search = searchString.trim().toLowerCase();
|
|
33
32
|
const hidden = new Set();
|
|
34
33
|
const expanded = new Set();
|
|
35
|
-
|
|
34
|
+
function nodeMatches(node, childOfMatch = false) {
|
|
36
35
|
const matches = stringsMatch(node, search);
|
|
37
36
|
let intermediate = false;
|
|
38
37
|
for (const child of node.children || []) {
|
|
39
|
-
const childMatches =
|
|
38
|
+
const childMatches = nodeMatches(child, matches || childOfMatch);
|
|
40
39
|
if (childMatches && !intermediate)
|
|
41
40
|
intermediate = true;
|
|
42
41
|
}
|
|
@@ -47,8 +46,8 @@ export const search = (nodes, searchString, stringsMatch) => {
|
|
|
47
46
|
hidden.add(node.id);
|
|
48
47
|
}
|
|
49
48
|
return matches || intermediate;
|
|
50
|
-
}
|
|
51
|
-
nodes.forEach((n) =>
|
|
49
|
+
}
|
|
50
|
+
nodes.forEach((n) => nodeMatches(n));
|
|
52
51
|
return {
|
|
53
52
|
hidden,
|
|
54
53
|
expanded
|
package/package.json
CHANGED
|
@@ -23,14 +23,12 @@ export function searchPlugin<T extends TableRow<T>>(conf: SearchConfig<T>): Tabl
|
|
|
23
23
|
if (!conf.search) return state;
|
|
24
24
|
|
|
25
25
|
// ensure we store the state before the we started searching
|
|
26
|
-
if (conf.search && !prevSearch)
|
|
27
|
-
expandedBeforeSearch = state.expanded;
|
|
28
|
-
}
|
|
26
|
+
if (conf.search && !prevSearch) expandedBeforeSearch = state.expanded;
|
|
29
27
|
|
|
30
28
|
// figure out which nodes to expand and hide
|
|
31
29
|
const { expanded, hidden } = search(state.data, conf.search, conf.matches);
|
|
32
|
-
|
|
33
30
|
prevSearch = conf.search;
|
|
31
|
+
|
|
34
32
|
return {
|
|
35
33
|
data: state.data.filter((d) => !hidden.has(d.id)),
|
|
36
34
|
expanded: new SvelteSet(expanded)
|
|
@@ -39,7 +37,7 @@ export function searchPlugin<T extends TableRow<T>>(conf: SearchConfig<T>): Tabl
|
|
|
39
37
|
return middleware;
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
/** collapses everything that doesnt match the searchString expands direct search hit */
|
|
40
|
+
/** collapses everything that doesnt match the searchString, expands direct search hit */
|
|
43
41
|
export const search = <T extends TableRow<T>>(
|
|
44
42
|
nodes: T[],
|
|
45
43
|
searchString: string,
|
|
@@ -49,12 +47,12 @@ export const search = <T extends TableRow<T>>(
|
|
|
49
47
|
const hidden = new Set<string>();
|
|
50
48
|
const expanded = new Set<string>();
|
|
51
49
|
|
|
52
|
-
|
|
50
|
+
function nodeMatches(node: T, childOfMatch = false): boolean {
|
|
53
51
|
const matches = stringsMatch(node, search);
|
|
54
52
|
|
|
55
53
|
let intermediate = false;
|
|
56
54
|
for (const child of node.children || []) {
|
|
57
|
-
const childMatches =
|
|
55
|
+
const childMatches = nodeMatches(child, matches || childOfMatch);
|
|
58
56
|
if (childMatches && !intermediate) intermediate = true;
|
|
59
57
|
}
|
|
60
58
|
|
|
@@ -65,9 +63,9 @@ export const search = <T extends TableRow<T>>(
|
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
return matches || intermediate;
|
|
68
|
-
}
|
|
66
|
+
}
|
|
69
67
|
|
|
70
|
-
nodes.forEach((n) =>
|
|
68
|
+
nodes.forEach((n) => nodeMatches(n));
|
|
71
69
|
|
|
72
70
|
return {
|
|
73
71
|
hidden,
|