@ims360/svelte-ivory 0.0.42 → 0.0.45
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/ai/Chat.svelte +12 -12
- package/dist/components/ai/Chat.svelte.d.ts +3 -1
- package/dist/components/ai/Chat.svelte.d.ts.map +1 -1
- package/dist/components/ai/UserMessage.svelte +1 -1
- package/dist/components/basic/checkbox/Checkbox.svelte +0 -1
- package/dist/components/basic/checkbox/Checkbox.svelte.d.ts.map +1 -1
- package/dist/components/layout/drawer/Drawer.svelte +13 -9
- package/dist/components/layout/drawer/Drawer.svelte.d.ts +4 -4
- package/dist/components/layout/drawer/Drawer.svelte.d.ts.map +1 -1
- package/dist/components/layout/modal/Modal.svelte +12 -9
- package/dist/components/layout/modal/Modal.svelte.d.ts +6 -5
- package/dist/components/layout/modal/Modal.svelte.d.ts.map +1 -1
- package/dist/components/layout/popover/Popover.svelte +1 -0
- package/dist/components/layout/popover/Popover.svelte.d.ts.map +1 -1
- package/dist/components/layout/tooltip/Tooltip.svelte +5 -5
- package/dist/components/layout/tooltip/Tooltip.svelte.d.ts +5 -3
- package/dist/components/layout/tooltip/Tooltip.svelte.d.ts.map +1 -1
- package/dist/components/table/Column.svelte +2 -2
- package/dist/components/table/ColumnHead.svelte +4 -4
- package/dist/components/table/ColumnHead.svelte.d.ts +3 -3
- package/dist/components/table/ColumnHead.svelte.d.ts.map +1 -1
- package/dist/components/table/Row.svelte +0 -1
- package/dist/components/table/Row.svelte.d.ts.map +1 -1
- package/dist/components/table/Table.svelte +56 -24
- package/dist/components/table/Table.svelte.d.ts +12 -9
- package/dist/components/table/Table.svelte.d.ts.map +1 -1
- package/dist/components/table/VirtualList.svelte +3 -3
- package/dist/components/table/columnController.svelte.d.ts +1 -1
- package/dist/components/table/columnController.svelte.d.ts.map +1 -1
- package/dist/components/table/columnController.svelte.js +1 -1
- package/dist/components/table/controller.d.ts +23 -0
- package/dist/components/table/controller.d.ts.map +1 -0
- package/dist/components/table/controller.js +52 -0
- package/dist/components/table/index.d.ts +2 -2
- package/dist/components/table/index.d.ts.map +1 -1
- package/dist/components/table/index.js +2 -2
- package/dist/components/table/plugins/search.svelte.d.ts +3 -2
- package/dist/components/table/plugins/search.svelte.d.ts.map +1 -1
- package/dist/components/table/plugins/search.svelte.js +3 -4
- package/dist/components/toast/Toast.svelte +0 -2
- package/dist/components/toast/Toast.svelte.d.ts.map +1 -1
- package/dist/utils/functions/cookie.js +1 -1
- package/package.json +1 -1
- package/src/lib/components/ai/Chat.svelte +12 -12
- package/src/lib/components/ai/UserMessage.svelte +1 -1
- package/src/lib/components/basic/checkbox/Checkbox.svelte +0 -1
- package/src/lib/components/layout/drawer/Drawer.svelte +13 -9
- package/src/lib/components/layout/modal/Modal.svelte +12 -9
- package/src/lib/components/layout/popover/Popover.svelte +1 -0
- package/src/lib/components/layout/tabs/index.ts +0 -1
- package/src/lib/components/layout/tooltip/Tooltip.svelte +5 -5
- package/src/lib/components/table/Column.svelte +2 -2
- package/src/lib/components/table/ColumnHead.svelte +4 -4
- package/src/lib/components/table/Row.svelte +0 -1
- package/src/lib/components/table/Table.svelte +56 -24
- package/src/lib/components/table/VirtualList.svelte +3 -3
- package/src/lib/components/table/columnController.svelte.ts +1 -1
- package/src/lib/components/table/controller.ts +75 -0
- package/src/lib/components/table/index.ts +2 -9
- package/src/lib/components/table/plugins/search.svelte.ts +3 -12
- package/src/lib/components/toast/Toast.svelte +0 -2
- package/src/lib/utils/functions/cookie.ts +1 -1
- package/dist/components/layout/modal/ModalTest.svelte +0 -9
- package/dist/components/layout/modal/ModalTest.svelte.d.ts +0 -8
- package/dist/components/layout/modal/ModalTest.svelte.d.ts.map +0 -1
- package/dist/components/table/controller.svelte.d.ts +0 -37
- package/dist/components/table/controller.svelte.d.ts.map +0 -1
- package/dist/components/table/controller.svelte.js +0 -160
- package/dist/components/table/plugins/expandAll.svelte.d.ts +0 -7
- package/dist/components/table/plugins/expandAll.svelte.d.ts.map +0 -1
- package/dist/components/table/plugins/expandAll.svelte.js +0 -24
- package/dist/utils/functions/transitionProps.d.ts +0 -1
- package/dist/utils/functions/transitionProps.d.ts.map +0 -1
- package/dist/utils/functions/transitionProps.js +0 -1
- package/src/lib/components/layout/modal/ModalTest.svelte +0 -9
- package/src/lib/components/table/controller.svelte.ts +0 -203
- package/src/lib/components/table/plugins/expandAll.svelte.ts +0 -34
- package/src/lib/utils/functions/transitionProps.ts +0 -1
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import { getContext, setContext, type Snippet } from 'svelte';
|
|
6
6
|
import type { ClassValue } from 'svelte/elements';
|
|
7
|
+
import { SvelteSet } from 'svelte/reactivity';
|
|
7
8
|
import { twMerge } from 'tailwind-merge';
|
|
8
|
-
import { Column
|
|
9
|
+
import { Column as ColumnComponent, type TablePlugin, type TableRow } from '.';
|
|
9
10
|
import ColumnHead from './ColumnHead.svelte';
|
|
10
11
|
import Row from './Row.svelte';
|
|
11
12
|
import VirtualList from './VirtualList.svelte';
|
|
12
|
-
import {
|
|
13
|
+
import { ColumnController, type ColumnConfig } from './columnController.svelte';
|
|
14
|
+
import { treeWalker, type TableState } from './controller';
|
|
13
15
|
|
|
14
16
|
export interface TableProps<T extends TableRow<T>> {
|
|
15
17
|
class?: ClassValue;
|
|
@@ -24,7 +26,11 @@
|
|
|
24
26
|
rowClass?: ClassValue;
|
|
25
27
|
headerClass?: ClassValue;
|
|
26
28
|
plugins?: TablePlugin<T>[];
|
|
27
|
-
|
|
29
|
+
/**
|
|
30
|
+
* **Bindable**
|
|
31
|
+
*/
|
|
32
|
+
b_columns?: ColumnController[];
|
|
33
|
+
expanded?: SvelteSet<string>;
|
|
28
34
|
/**
|
|
29
35
|
* **Bindable**
|
|
30
36
|
*/
|
|
@@ -35,9 +41,11 @@
|
|
|
35
41
|
|
|
36
42
|
const TABLE_CONTEXT = {};
|
|
37
43
|
export type TableContext<T extends TableRow<T>> = {
|
|
38
|
-
|
|
44
|
+
registerColumn: (config: ColumnConfig) => ColumnController;
|
|
45
|
+
toggleExpansion: (id: string) => void;
|
|
39
46
|
nestingInset: number;
|
|
40
47
|
};
|
|
48
|
+
|
|
41
49
|
function setTableContext<T extends TableRow<T>>(context: TableContext<T>) {
|
|
42
50
|
setContext(TABLE_CONTEXT, context);
|
|
43
51
|
}
|
|
@@ -48,8 +56,6 @@
|
|
|
48
56
|
</script>
|
|
49
57
|
|
|
50
58
|
<script lang="ts" generics="T extends TableRow<T>">
|
|
51
|
-
interface Props<TI extends { id: string }> extends TableProps<TI> {}
|
|
52
|
-
|
|
53
59
|
let {
|
|
54
60
|
class: clazz,
|
|
55
61
|
data,
|
|
@@ -61,31 +67,57 @@
|
|
|
61
67
|
onclick,
|
|
62
68
|
href,
|
|
63
69
|
plugins = [],
|
|
64
|
-
|
|
65
|
-
nestingInset = 4
|
|
66
|
-
|
|
70
|
+
expanded: expanded = new SvelteSet<string>(),
|
|
71
|
+
nestingInset = 4,
|
|
72
|
+
b_columns: externalColumns = $bindable(),
|
|
73
|
+
b_scrollTop = $bindable()
|
|
74
|
+
}: TableProps<T> = $props();
|
|
67
75
|
|
|
68
|
-
$
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
let columns = $state<ColumnController[]>(externalColumns ?? []);
|
|
77
|
+
const results = $derived(computeResults(data, expanded, plugins));
|
|
78
|
+
|
|
79
|
+
function toggleExpansion(id: string) {
|
|
80
|
+
if (expanded.has(id)) expanded.delete(id);
|
|
81
|
+
else expanded.add(id);
|
|
82
|
+
}
|
|
72
83
|
|
|
73
84
|
setTableContext({
|
|
74
|
-
|
|
75
|
-
|
|
85
|
+
toggleExpansion,
|
|
86
|
+
registerColumn(config: ColumnConfig) {
|
|
87
|
+
let existingColumn: ColumnController | undefined = undefined;
|
|
88
|
+
for (const column of existingColumn || columns) {
|
|
89
|
+
if (column.id !== config.id) continue;
|
|
90
|
+
existingColumn = column;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (existingColumn) return existingColumn;
|
|
94
|
+
const col = new ColumnController(config);
|
|
95
|
+
(externalColumns || columns).push(col);
|
|
96
|
+
return col;
|
|
76
97
|
},
|
|
77
98
|
get nestingInset() {
|
|
78
99
|
return nestingInset;
|
|
79
100
|
}
|
|
80
101
|
});
|
|
81
102
|
|
|
103
|
+
function computeResults(data: T[], expanded: Set<string>, plugins: TablePlugin<T>[]) {
|
|
104
|
+
let state: TableState<T> = {
|
|
105
|
+
data,
|
|
106
|
+
expanded
|
|
107
|
+
};
|
|
108
|
+
for (const plugin of plugins) {
|
|
109
|
+
state = plugin(state);
|
|
110
|
+
}
|
|
111
|
+
return treeWalker(state);
|
|
112
|
+
}
|
|
113
|
+
|
|
82
114
|
const treeIndicatorId = pseudoRandomId('tree-indicator-');
|
|
83
115
|
</script>
|
|
84
116
|
|
|
85
117
|
<VirtualList
|
|
86
|
-
data={
|
|
118
|
+
data={results.entries}
|
|
87
119
|
class={twMerge(clsx(['flex flex-col overflow-hidden border-transparent', clazz]))}
|
|
88
|
-
bind:b_scrollTop
|
|
120
|
+
bind:b_scrollTop
|
|
89
121
|
{rowHeight}
|
|
90
122
|
>
|
|
91
123
|
{#snippet header()}
|
|
@@ -97,7 +129,7 @@
|
|
|
97
129
|
)
|
|
98
130
|
)}
|
|
99
131
|
>
|
|
100
|
-
{#each
|
|
132
|
+
{#each externalColumns || columns as column (column.id)}
|
|
101
133
|
<ColumnHead {column}>
|
|
102
134
|
{#if typeof column.header === 'function'}
|
|
103
135
|
{@render column.header()}
|
|
@@ -119,15 +151,15 @@
|
|
|
119
151
|
class={rowClass}
|
|
120
152
|
>
|
|
121
153
|
{@render firstColumn?.({ row: node })}
|
|
122
|
-
<
|
|
154
|
+
<ColumnComponent
|
|
123
155
|
id={treeIndicatorId}
|
|
124
156
|
resizable={false}
|
|
125
157
|
header=""
|
|
126
158
|
onclick={() => {
|
|
127
|
-
|
|
159
|
+
toggleExpansion(node.id);
|
|
128
160
|
}}
|
|
129
|
-
ignoreWidth={
|
|
130
|
-
width={
|
|
161
|
+
ignoreWidth={results.someHaveChildren}
|
|
162
|
+
width={results.someHaveChildren ? 24 : 0}
|
|
131
163
|
minWidth={0}
|
|
132
164
|
>
|
|
133
165
|
<div
|
|
@@ -138,12 +170,12 @@
|
|
|
138
170
|
<ChevronRight
|
|
139
171
|
class={[
|
|
140
172
|
'ml-auto aspect-square shrink-0 transition-transform duration-100',
|
|
141
|
-
|
|
173
|
+
expanded.has(id) && 'rotate-90'
|
|
142
174
|
]}
|
|
143
175
|
/>
|
|
144
176
|
{/if}
|
|
145
177
|
</div>
|
|
146
|
-
</
|
|
178
|
+
</ColumnComponent>
|
|
147
179
|
{@render passedChildren?.({ row: node, nestingLevel, index })}
|
|
148
180
|
</Row>
|
|
149
181
|
{/snippet}
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
data,
|
|
20
20
|
children,
|
|
21
21
|
header,
|
|
22
|
-
b_scrollTop = $bindable(
|
|
22
|
+
b_scrollTop = $bindable(),
|
|
23
23
|
rowHeight,
|
|
24
24
|
overscan = 2
|
|
25
25
|
}: Props<T> = $props();
|
|
26
26
|
|
|
27
|
-
let scroll_top = $state(b_scrollTop);
|
|
27
|
+
let scroll_top = $state(b_scrollTop ?? 0);
|
|
28
28
|
let scroll_left = $state(0);
|
|
29
29
|
let header_width = $state(0);
|
|
30
30
|
let viewport = $state<HTMLElement>();
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
onMount(() => {
|
|
56
|
-
if (!viewport) return;
|
|
56
|
+
if (!viewport || typeof b_scrollTop === 'undefined') return;
|
|
57
57
|
viewport.scrollTop = b_scrollTop;
|
|
58
58
|
});
|
|
59
59
|
</script>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export type TableRow<T> = { id: string; children?: T[] };
|
|
2
|
+
export type TablePlugin<T extends TableRow<T>> = (state: TableState<T>) => TableState<T>;
|
|
3
|
+
|
|
4
|
+
export interface TableState<T extends TableRow<T>> {
|
|
5
|
+
data: T[];
|
|
6
|
+
expanded: Set<string>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface TreeRow<T> {
|
|
10
|
+
node: T;
|
|
11
|
+
nestingLevel: number;
|
|
12
|
+
id: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Walks though a tree strucure and turns it into a flat list, needed since the `VirtualList` needs a list, not a tree */
|
|
16
|
+
export function treeWalker<T extends TableRow<T>>(config: TableState<T>) {
|
|
17
|
+
const { data, expanded } = config;
|
|
18
|
+
const stack: { node: T; nestingLevel: number }[] = [];
|
|
19
|
+
|
|
20
|
+
// push the root nodes of the trees onto the stack
|
|
21
|
+
for (let i = 0; i < data.length; i++) {
|
|
22
|
+
stack.push({
|
|
23
|
+
node: data[data.length - i - 1],
|
|
24
|
+
nestingLevel: 0
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const entries: TreeRow<T>[] = []; // the final result
|
|
29
|
+
|
|
30
|
+
let someHaveChildren = false; // used to determine whether to show the tree utility buttons
|
|
31
|
+
let maxNestingLevel = 0;
|
|
32
|
+
while (stack.length !== 0) {
|
|
33
|
+
const stackEntry = stack.pop();
|
|
34
|
+
if (!stackEntry) break;
|
|
35
|
+
|
|
36
|
+
const { node, nestingLevel } = stackEntry;
|
|
37
|
+
const children = node.children;
|
|
38
|
+
|
|
39
|
+
if (children && children.length > 0) {
|
|
40
|
+
someHaveChildren = true;
|
|
41
|
+
// only show the children of expanded elements
|
|
42
|
+
if (expanded.has(node.id)) {
|
|
43
|
+
maxNestingLevel = Math.max(maxNestingLevel, nestingLevel + 1);
|
|
44
|
+
stack.push(
|
|
45
|
+
...children
|
|
46
|
+
.map((c) => ({
|
|
47
|
+
node: c,
|
|
48
|
+
nestingLevel: nestingLevel + 1
|
|
49
|
+
}))
|
|
50
|
+
.reverse()
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
entries.push({
|
|
56
|
+
id: node.id,
|
|
57
|
+
node,
|
|
58
|
+
nestingLevel
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
entries,
|
|
64
|
+
someHaveChildren,
|
|
65
|
+
maxNestingLevel
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function getAllIds<T extends TableRow<T>>(...nodes: T[]): string[] {
|
|
70
|
+
const ids = nodes.map((n) => n.id);
|
|
71
|
+
for (const node of nodes) {
|
|
72
|
+
ids.push(...getAllIds(...(node.children ?? [])));
|
|
73
|
+
}
|
|
74
|
+
return ids;
|
|
75
|
+
}
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
export { default as Column, type ColumnProps } from './Column.svelte';
|
|
2
|
+
export { ColumnController, type ColumnConfig } from './columnController.svelte';
|
|
2
3
|
export { getColumnHeadContext } from './ColumnHead.svelte';
|
|
3
|
-
export {
|
|
4
|
-
createTableConfig,
|
|
5
|
-
getAllIds,
|
|
6
|
-
type TableConfig,
|
|
7
|
-
type TablePlugin,
|
|
8
|
-
type TableRow,
|
|
9
|
-
type TableState
|
|
10
|
-
} from './controller.svelte';
|
|
11
|
-
export { expandAllPlugin } from './plugins/expandAll.svelte';
|
|
4
|
+
export { getAllIds, type TablePlugin, type TableRow, type TableState } from './controller';
|
|
12
5
|
export { searchPlugin } from './plugins/search.svelte';
|
|
13
6
|
export {
|
|
14
7
|
getTableContext,
|
|
@@ -19,17 +19,12 @@ export function searchPlugin<T extends TableRow<T>>(conf: SearchConfig<T>): Tabl
|
|
|
19
19
|
expanded: expandedBeforeSearch
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
|
|
23
22
|
if (!conf.search) return state;
|
|
24
|
-
|
|
25
23
|
// ensure we store the state before the we started searching
|
|
26
24
|
if (conf.search && !prevSearch) expandedBeforeSearch = state.expanded;
|
|
27
|
-
|
|
28
25
|
// figure out which nodes to expand and hide
|
|
29
26
|
const { expanded, hidden } = search(state.data, conf.search, conf.matches);
|
|
30
27
|
prevSearch = conf.search;
|
|
31
|
-
console.log(hidden);
|
|
32
|
-
|
|
33
28
|
return {
|
|
34
29
|
data: state.data.filter((d) => !hidden.has(d.id)),
|
|
35
30
|
expanded: new SvelteSet(expanded)
|
|
@@ -45,29 +40,25 @@ export const search = <T extends TableRow<T>>(
|
|
|
45
40
|
stringsMatch: (a: T, b: string) => boolean
|
|
46
41
|
) => {
|
|
47
42
|
const search = searchString.trim().toLowerCase();
|
|
48
|
-
const hidden = new
|
|
49
|
-
const expanded = new
|
|
43
|
+
const hidden = new SvelteSet<string>();
|
|
44
|
+
const expanded = new SvelteSet<string>();
|
|
50
45
|
|
|
51
46
|
function nodeMatches(node: T, childOfMatch = false): boolean {
|
|
52
47
|
const matches = stringsMatch(node, search);
|
|
53
|
-
|
|
54
48
|
let intermediate = false;
|
|
55
49
|
for (const child of node.children || []) {
|
|
56
50
|
const childMatches = nodeMatches(child, matches || childOfMatch);
|
|
57
|
-
if (childMatches
|
|
51
|
+
if (childMatches) intermediate = true;
|
|
58
52
|
}
|
|
59
|
-
|
|
60
53
|
if (intermediate) {
|
|
61
54
|
expanded.add(node.id);
|
|
62
55
|
} else if (!childOfMatch && !matches) {
|
|
63
56
|
hidden.add(node.id);
|
|
64
57
|
}
|
|
65
|
-
|
|
66
58
|
return matches || intermediate;
|
|
67
59
|
}
|
|
68
60
|
|
|
69
61
|
nodes.forEach((n) => nodeMatches(n));
|
|
70
|
-
|
|
71
62
|
return {
|
|
72
63
|
hidden,
|
|
73
64
|
expanded
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type ModalProps } from './Modal.svelte';
|
|
2
|
-
type $$ComponentProps = ModalProps & {
|
|
3
|
-
open: boolean;
|
|
4
|
-
};
|
|
5
|
-
declare const ModalTest: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
6
|
-
type ModalTest = ReturnType<typeof ModalTest>;
|
|
7
|
-
export default ModalTest;
|
|
8
|
-
//# sourceMappingURL=ModalTest.svelte.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ModalTest.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/layout/modal/ModalTest.svelte.ts"],"names":[],"mappings":"AAGA,OAAc,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEvD,KAAK,gBAAgB,GAAI,UAAU,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAazD,QAAA,MAAM,SAAS,sDAAwC,CAAC;AACxD,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAC9C,eAAe,SAAS,CAAC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { SvelteSet } from 'svelte/reactivity';
|
|
2
|
-
import { Column, type ColumnConfig } from './columnController.svelte';
|
|
3
|
-
export type TableRow<T> = {
|
|
4
|
-
id: string;
|
|
5
|
-
children?: T[];
|
|
6
|
-
};
|
|
7
|
-
export type TablePlugin<T extends TableRow<T>> = (state: TableState<T>) => TableState<T>;
|
|
8
|
-
export interface TableConfig<T extends TableRow<T>> {
|
|
9
|
-
data: T[];
|
|
10
|
-
plugins?: TablePlugin<T>[];
|
|
11
|
-
id?: string;
|
|
12
|
-
expanded: SvelteSet<string>;
|
|
13
|
-
columns: Column[];
|
|
14
|
-
scrollTop: number;
|
|
15
|
-
readonly results: ReturnType<typeof treeWalker<T>>;
|
|
16
|
-
readonly registerColumn: (config: ColumnConfig) => Column;
|
|
17
|
-
readonly toggleExpansion: (id: string) => void;
|
|
18
|
-
}
|
|
19
|
-
export declare function createTableConfig<T extends TableRow<T>>(): TableConfig<T>;
|
|
20
|
-
export interface TableState<T extends TableRow<T>> {
|
|
21
|
-
data: T[];
|
|
22
|
-
expanded: Set<string>;
|
|
23
|
-
}
|
|
24
|
-
interface TreeRow<T> {
|
|
25
|
-
node: T;
|
|
26
|
-
nestingLevel: number;
|
|
27
|
-
id: string;
|
|
28
|
-
}
|
|
29
|
-
/** Walks though a tree strucure and turns it into a flat list, needed since the `VirtualList` needs a list, not a tree */
|
|
30
|
-
declare function treeWalker<T extends TableRow<T>>(config: TableState<T>): {
|
|
31
|
-
entries: TreeRow<T>[];
|
|
32
|
-
someHaveChildren: boolean;
|
|
33
|
-
maxNestingLevel: number;
|
|
34
|
-
};
|
|
35
|
-
export declare function getAllIds<T extends TableRow<T>>(...nodes: T[]): string[];
|
|
36
|
-
export {};
|
|
37
|
-
//# sourceMappingURL=controller.svelte.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"controller.svelte.d.ts","sourceRoot":"","sources":["../../../src/lib/components/table/controller.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEtE,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAA;CAAE,CAAC;AACzD,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC;AAEzF,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC;IAC9C,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAC5B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,MAAM,CAAC;IAC1D,QAAQ,CAAC,eAAe,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAClD;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,CA+DzE;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC;IAC7C,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACzB;AAED,UAAU,OAAO,CAAC,CAAC;IACf,IAAI,EAAE,CAAC,CAAC;IACR,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;CACd;AAkDD,0HAA0H;AAC1H,iBAAS,UAAU,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;;;;EAmD/D;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,CAMxE"}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { SvelteSet } from 'svelte/reactivity';
|
|
2
|
-
import { Column } from './columnController.svelte';
|
|
3
|
-
export function createTableConfig() {
|
|
4
|
-
let data = $state([]);
|
|
5
|
-
let plugins = $state([]);
|
|
6
|
-
let scrollTop = $state(0);
|
|
7
|
-
const expanded = new SvelteSet();
|
|
8
|
-
const columns = $state([]);
|
|
9
|
-
const results = $derived.by(() => {
|
|
10
|
-
let state = {
|
|
11
|
-
data,
|
|
12
|
-
expanded
|
|
13
|
-
};
|
|
14
|
-
for (const plugin of plugins) {
|
|
15
|
-
state = plugin(state);
|
|
16
|
-
}
|
|
17
|
-
return treeWalker(state);
|
|
18
|
-
});
|
|
19
|
-
return {
|
|
20
|
-
get data() {
|
|
21
|
-
return data;
|
|
22
|
-
},
|
|
23
|
-
set data(d) {
|
|
24
|
-
data = d;
|
|
25
|
-
},
|
|
26
|
-
get plugins() {
|
|
27
|
-
return plugins;
|
|
28
|
-
},
|
|
29
|
-
set plugins(p) {
|
|
30
|
-
plugins = p;
|
|
31
|
-
},
|
|
32
|
-
get scrollTop() {
|
|
33
|
-
return scrollTop;
|
|
34
|
-
},
|
|
35
|
-
set scrollTop(s) {
|
|
36
|
-
scrollTop = s;
|
|
37
|
-
},
|
|
38
|
-
get expanded() {
|
|
39
|
-
return expanded;
|
|
40
|
-
},
|
|
41
|
-
get columns() {
|
|
42
|
-
return columns;
|
|
43
|
-
},
|
|
44
|
-
get results() {
|
|
45
|
-
return results;
|
|
46
|
-
},
|
|
47
|
-
registerColumn(config) {
|
|
48
|
-
let existingColumn = undefined;
|
|
49
|
-
for (const column of columns) {
|
|
50
|
-
if (column.id !== config.id)
|
|
51
|
-
continue;
|
|
52
|
-
existingColumn = column;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
if (existingColumn)
|
|
56
|
-
return existingColumn;
|
|
57
|
-
const col = new Column(config);
|
|
58
|
-
columns.push(col);
|
|
59
|
-
return col;
|
|
60
|
-
},
|
|
61
|
-
toggleExpansion(id) {
|
|
62
|
-
if (expanded.has(id))
|
|
63
|
-
expanded.delete(id);
|
|
64
|
-
else
|
|
65
|
-
expanded.add(id);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
// export class TableController<T extends TableRow<T>> {
|
|
70
|
-
// id = $state();
|
|
71
|
-
// columns = $state<Column[]>([]);
|
|
72
|
-
// data = $state<T[]>([]);
|
|
73
|
-
// expanded: Set<string> = new SvelteSet<string>();
|
|
74
|
-
// scrollTop = $state(0);
|
|
75
|
-
// constructor(id?: string) {
|
|
76
|
-
// this.id = id;
|
|
77
|
-
// }
|
|
78
|
-
// readonly results = $derived(treeWalker(this.data, this.expanded));
|
|
79
|
-
// refresh(conf: TableConfig<T>) {
|
|
80
|
-
// let intitalState: TableState<T> = {
|
|
81
|
-
// data: [...(conf.data ?? [])],
|
|
82
|
-
// expanded: this.expanded
|
|
83
|
-
// };
|
|
84
|
-
// for (const plugin of conf.plugins ?? []) {
|
|
85
|
-
// intitalState = plugin(intitalState);
|
|
86
|
-
// }
|
|
87
|
-
// this.data = intitalState.data;
|
|
88
|
-
// this.expanded = new SvelteSet(intitalState.expanded);
|
|
89
|
-
// this.id = conf.id ?? this.id ?? pseudoRandomId('table-');
|
|
90
|
-
// }
|
|
91
|
-
// registerColumn(config: ColumnConfig): Column {
|
|
92
|
-
// // only register a column once
|
|
93
|
-
// let existingColumn: Column | undefined = undefined;
|
|
94
|
-
// for (const column of this.columns) {
|
|
95
|
-
// if (column.id !== config.id) continue;
|
|
96
|
-
// existingColumn = column;
|
|
97
|
-
// break;
|
|
98
|
-
// }
|
|
99
|
-
// if (existingColumn) return existingColumn;
|
|
100
|
-
// const col = new Column(config);
|
|
101
|
-
// this.columns.push(col);
|
|
102
|
-
// return col;
|
|
103
|
-
// }
|
|
104
|
-
// toggleExpansion(id: string) {
|
|
105
|
-
// if (this.expanded.has(id)) this.expanded.delete(id);
|
|
106
|
-
// else this.expanded.add(id);
|
|
107
|
-
// }
|
|
108
|
-
// }
|
|
109
|
-
/** Walks though a tree strucure and turns it into a flat list, needed since the `VirtualList` needs a list, not a tree */
|
|
110
|
-
function treeWalker(config) {
|
|
111
|
-
const { data, expanded } = config;
|
|
112
|
-
const stack = [];
|
|
113
|
-
// push the root nodes of the trees onto the stack
|
|
114
|
-
for (let i = 0; i < data.length; i++) {
|
|
115
|
-
stack.push({
|
|
116
|
-
node: data[data.length - i - 1],
|
|
117
|
-
nestingLevel: 0
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
const entries = []; // the final result
|
|
121
|
-
let someHaveChildren = false; // used to determine whether to show the tree utility buttons
|
|
122
|
-
let maxNestingLevel = 0;
|
|
123
|
-
while (stack.length !== 0) {
|
|
124
|
-
const stackEntry = stack.pop();
|
|
125
|
-
if (!stackEntry)
|
|
126
|
-
break;
|
|
127
|
-
const { node, nestingLevel } = stackEntry;
|
|
128
|
-
const children = node.children;
|
|
129
|
-
if (children && children.length > 0) {
|
|
130
|
-
someHaveChildren = true;
|
|
131
|
-
// only show the children of expanded elements
|
|
132
|
-
if (expanded.has(node.id)) {
|
|
133
|
-
maxNestingLevel = Math.max(maxNestingLevel, nestingLevel + 1);
|
|
134
|
-
stack.push(...children
|
|
135
|
-
.map((c) => ({
|
|
136
|
-
node: c,
|
|
137
|
-
nestingLevel: nestingLevel + 1
|
|
138
|
-
}))
|
|
139
|
-
.reverse());
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
entries.push({
|
|
143
|
-
id: node.id,
|
|
144
|
-
node,
|
|
145
|
-
nestingLevel
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
return {
|
|
149
|
-
entries,
|
|
150
|
-
someHaveChildren,
|
|
151
|
-
maxNestingLevel
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
export function getAllIds(...nodes) {
|
|
155
|
-
const ids = nodes.map((n) => n.id);
|
|
156
|
-
for (const node of nodes) {
|
|
157
|
-
ids.push(...getAllIds(...(node.children ?? [])));
|
|
158
|
-
}
|
|
159
|
-
return ids;
|
|
160
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type TablePlugin, type TableRow } from '../controller.svelte';
|
|
2
|
-
interface ExpandAllConfig {
|
|
3
|
-
enabled: boolean;
|
|
4
|
-
}
|
|
5
|
-
export declare function expandAllPlugin<T extends TableRow<T>>(conf: Partial<ExpandAllConfig>): TablePlugin<T>;
|
|
6
|
-
export {};
|
|
7
|
-
//# sourceMappingURL=expandAll.svelte.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"expandAll.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/table/plugins/expandAll.svelte.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAElF,UAAU,eAAe;IACrB,OAAO,EAAE,OAAO,CAAC;CACpB;AAMD,wBAAgB,eAAe,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,CAAC,EACjD,IAAI,EAAE,OAAO,CAAC,eAAe,CAAC,GAC/B,WAAW,CAAC,CAAC,CAAC,CAoBhB"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { SvelteSet } from 'svelte/reactivity';
|
|
2
|
-
import { getAllIds } from '../controller.svelte';
|
|
3
|
-
const DEFAULT_CONFIG = {
|
|
4
|
-
enabled: true
|
|
5
|
-
};
|
|
6
|
-
export function expandAllPlugin(conf) {
|
|
7
|
-
let initialized = false;
|
|
8
|
-
const config = {
|
|
9
|
-
...DEFAULT_CONFIG,
|
|
10
|
-
...conf
|
|
11
|
-
};
|
|
12
|
-
const middleware = (state) => {
|
|
13
|
-
if (initialized || !config.enabled)
|
|
14
|
-
return state;
|
|
15
|
-
initialized = true;
|
|
16
|
-
const allIds = getAllIds(...state.data);
|
|
17
|
-
const newExpanded = new SvelteSet(allIds);
|
|
18
|
-
return {
|
|
19
|
-
data: state.data,
|
|
20
|
-
expanded: newExpanded
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
return middleware;
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=transitionProps.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transitionProps.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/functions/transitionProps.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|