svelte-tably 1.0.0-next.8 → 1.0.0-next.9

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/README.md CHANGED
@@ -14,12 +14,13 @@ A high performant dynamic table
14
14
  - [x] "Virtual" data (for sorting/filtering)
15
15
  - [x] Panels
16
16
  - [x] Virtual elements
17
- - [ ] sorting
17
+ - [x] sorting
18
18
  - [x] select
19
19
  - [ ] filtering
20
20
  - [ ] orderable table
21
21
  - [ ] row context-menu
22
22
  - [ ] dropout section
23
+ - [ ] csv export
23
24
 
24
25
  ### Usage Notes
25
26
 
@@ -8,8 +8,7 @@
8
8
 
9
9
  -->
10
10
 
11
- <script module lang='ts'>
12
-
11
+ <script module lang="ts">
13
12
  export type RowCtx<V> = {
14
13
  readonly value: V
15
14
  readonly isHovered: boolean
@@ -17,20 +16,84 @@
17
16
  selected: boolean
18
17
  }
19
18
 
20
- export interface Column<T = unknown, V = unknown> {
21
- header?: Snippet<[
22
- /**
23
- * Is true when displaying in the header,
24
- * so additional content can be shown if desired,
25
- * so the header snippet can be re-used.
26
- */
27
- header?: boolean
28
- ]>
19
+ export interface ColumnProps<T, V> {
20
+ header?: Snippet<
21
+ [
22
+ /**
23
+ * Is true when displaying in the header,
24
+ * so additional content can be shown if desired,
25
+ * so the header snippet can be re-used.
26
+ */
27
+ header?: boolean
28
+ ]
29
+ >
29
30
  row: Snippet<[item: T, row: RowCtx<V>]>
30
31
  statusbar?: Snippet
31
32
 
33
+ id: string
34
+
35
+ // options
36
+ /**
37
+ * Is this column sticky by default?
38
+ * @default false
39
+ */
40
+ sticky?: boolean
41
+ /**
42
+ * Fixed is like sticky, but in its own category — meant to not be moved/hidden ex. select-boxes
43
+ * @default false
44
+ */
45
+ fixed?: boolean
46
+ /**
47
+ * Is this column sorted by default?
48
+ * @default false
49
+ */
50
+ sort?: boolean
51
+ /**
52
+ * Is this column visible by default?
53
+ * @default true
54
+ */
55
+ show?: boolean
56
+ /**
57
+ * The width of the column in pixels by default
58
+ * @default 150
59
+ */
60
+ width?: number
61
+ /**
62
+ * The value of the row. Required for sorting/filtering
63
+ * @example row => row.name
64
+ */
65
+ value?: (item: T) => V
66
+ /**
67
+ * Makes the column sortable. Sorts based of a sorting function.
68
+ *
69
+ * **Important**   `value`-attribute is required adjacent to this.
70
+ *
71
+ * If `true` uses the default `.sort()` algorithm.
72
+ *
73
+ * @default false
74
+ */
75
+ sorting?: boolean | ((a: V, b: V) => number)
76
+ /**
77
+ * Is this column resizeable?
78
+ * Can not be resized if Table is marked as `resizeable={false}`
79
+ * @default true
80
+ */
81
+ resizeable?: boolean
82
+
83
+ /**
84
+ * Optional: Provide the table it is a part of
85
+ */
86
+ table?: TableState
87
+ }
88
+
89
+ export interface ColumnState<T = unknown, V = unknown, C extends ColumnProps<T, V> = ColumnProps<T, V>> {
90
+ id: C['id']
91
+ header?: C['header']
92
+ row: C['row']
93
+ statusbar?: C['statusbar']
94
+
32
95
  fixed?: boolean
33
-
96
+
34
97
  /** Default options for initial table */
35
98
  defaults: {
36
99
  sticky?: boolean
@@ -40,58 +103,41 @@
40
103
  }
41
104
  /** More options */
42
105
  options: {
43
- value?: (item: T) => V
44
- sorting?: unknown extends V ? (a: T, b: T) => number : (a: V, b: V) => number
106
+ value?: C['value']
107
+ sorting?: boolean | ((a: any, b: any) => number)
45
108
  resizeable: boolean
46
109
  }
47
110
  }
48
-
49
111
  </script>
50
112
 
51
- <script lang='ts' generics='T extends Record<PropertyKey, any>, V = unknown'>
52
-
113
+ <script lang="ts">
53
114
  import { onDestroy, type Snippet } from 'svelte'
54
115
  import { getTableState, type TableState } from './Table.svelte'
55
116
 
56
- interface Props {
57
- header?: Column<T, V>['header']
58
- row: Column<T, V>['row']
59
- statusbar?: Column<T, V>['statusbar']
117
+ type T = $$Generic<Record<PropertyKey, any>>
118
+ type V = $$Generic
60
119
 
61
- id: string
62
-
63
- // options
64
- sticky?: boolean
65
- /** Fixed is like sticky, but in its own category — meant to not be moved/hidden ex. select-boxes */
66
- fixed?: boolean
67
- sort?: boolean
68
- show?: boolean
69
- width?: number
70
- value?: Column<T, V>['options']['value']
71
- sorting?: Column<T, V>['options']['sorting']
72
- /** @default true */
73
- resizeable?: boolean
74
-
75
- /** Optional: Provide the table it is a part of */
76
- table?: TableState
77
- }
120
+ let {
121
+ header,
122
+ row,
123
+ statusbar,
124
+ id,
78
125
 
79
- let {
80
- header, row, statusbar, id,
81
-
82
126
  sticky = false,
83
127
  fixed = false,
84
- sort = false,
128
+ sort = false,
85
129
  show = true,
86
130
  width,
87
-
131
+
88
132
  resizeable = true,
89
- value, sorting,
133
+ value,
134
+ sorting,
90
135
 
91
136
  table
92
- }: Props = $props()
137
+ }: ColumnProps<T, V> = $props()
93
138
 
94
- const column: Column<T, V> = $state({
139
+ const column: ColumnState<T, V> = $state({
140
+ id,
95
141
  header,
96
142
  row,
97
143
  statusbar,
@@ -110,10 +156,9 @@
110
156
  })
111
157
 
112
158
  table ??= getTableState()
113
- table.addColumn(id, column as Column)
159
+ table.addColumn(id, column as ColumnState)
114
160
 
115
161
  onDestroy(() => {
116
162
  table.removeColumn(id)
117
163
  })
118
-
119
- </script>
164
+ </script>
@@ -4,17 +4,74 @@ export type RowCtx<V> = {
4
4
  readonly index: number;
5
5
  selected: boolean;
6
6
  };
7
- export interface Column<T = unknown, V = unknown> {
7
+ export interface ColumnProps<T, V> {
8
8
  header?: Snippet<[
9
9
  /**
10
10
  * Is true when displaying in the header,
11
11
  * so additional content can be shown if desired,
12
12
  * so the header snippet can be re-used.
13
- */
13
+ */
14
14
  header?: boolean
15
15
  ]>;
16
16
  row: Snippet<[item: T, row: RowCtx<V>]>;
17
17
  statusbar?: Snippet;
18
+ id: string;
19
+ /**
20
+ * Is this column sticky by default?
21
+ * @default false
22
+ */
23
+ sticky?: boolean;
24
+ /**
25
+ * Fixed is like sticky, but in its own category — meant to not be moved/hidden ex. select-boxes
26
+ * @default false
27
+ */
28
+ fixed?: boolean;
29
+ /**
30
+ * Is this column sorted by default?
31
+ * @default false
32
+ */
33
+ sort?: boolean;
34
+ /**
35
+ * Is this column visible by default?
36
+ * @default true
37
+ */
38
+ show?: boolean;
39
+ /**
40
+ * The width of the column in pixels by default
41
+ * @default 150
42
+ */
43
+ width?: number;
44
+ /**
45
+ * The value of the row. Required for sorting/filtering
46
+ * @example row => row.name
47
+ */
48
+ value?: (item: T) => V;
49
+ /**
50
+ * Makes the column sortable. Sorts based of a sorting function.
51
+ *
52
+ * **Important**   `value`-attribute is required adjacent to this.
53
+ *
54
+ * If `true` uses the default `.sort()` algorithm.
55
+ *
56
+ * @default false
57
+ */
58
+ sorting?: boolean | ((a: V, b: V) => number);
59
+ /**
60
+ * Is this column resizeable?
61
+ * Can not be resized if Table is marked as `resizeable={false}`
62
+ * @default true
63
+ */
64
+ resizeable?: boolean;
65
+ /**
66
+ * Optional: Provide the table it is a part of
67
+ */
68
+ table?: TableState;
69
+ }
70
+ export interface ColumnState<T = unknown, V = unknown, C extends ColumnProps<T, V> = ColumnProps<T, V>> {
71
+ id: C['id'];
72
+ header?: C['header'];
73
+ row: C['row'];
74
+ statusbar?: C['statusbar'];
18
75
  fixed?: boolean;
19
76
  /** Default options for initial table */
20
77
  defaults: {
@@ -25,42 +82,25 @@ export interface Column<T = unknown, V = unknown> {
25
82
  };
26
83
  /** More options */
27
84
  options: {
28
- value?: (item: T) => V;
29
- sorting?: unknown extends V ? (a: T, b: T) => number : (a: V, b: V) => number;
85
+ value?: C['value'];
86
+ sorting?: boolean | ((a: any, b: any) => number);
30
87
  resizeable: boolean;
31
88
  };
32
89
  }
33
90
  import { type Snippet } from 'svelte';
34
91
  import { type TableState } from './Table.svelte';
35
- declare class __sveltets_Render<T extends Record<PropertyKey, any>, V = unknown> {
36
- props(): {
37
- header?: Column<T_1, V_1>["header"];
38
- row: Column<T_1, V_1>["row"];
39
- statusbar?: Column<T_1, V_1>["statusbar"];
40
- id: string;
41
- sticky?: boolean;
42
- /** Fixed is like sticky, but in its own category — meant to not be moved/hidden ex. select-boxes */
43
- fixed?: boolean;
44
- sort?: boolean;
45
- show?: boolean;
46
- width?: number;
47
- value?: Column<T_1, V_1>["options"]["value"];
48
- sorting?: Column<T_1, V_1>["options"]["sorting"];
49
- /** @default true */
50
- resizeable?: boolean;
51
- /** Optional: Provide the table it is a part of */
52
- table?: TableState;
53
- };
92
+ declare class __sveltets_Render<T extends Record<PropertyKey, any>, V> {
93
+ props(): ColumnProps<T, V>;
54
94
  events(): {};
55
95
  slots(): {};
56
96
  bindings(): "";
57
97
  exports(): {};
58
98
  }
59
99
  interface $$IsomorphicComponent {
60
- new <T extends Record<PropertyKey, any>, V = unknown>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T, V>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T, V>['props']>, ReturnType<__sveltets_Render<T, V>['events']>, ReturnType<__sveltets_Render<T, V>['slots']>> & {
100
+ new <T extends Record<PropertyKey, any>, V>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T, V>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T, V>['props']>, ReturnType<__sveltets_Render<T, V>['events']>, ReturnType<__sveltets_Render<T, V>['slots']>> & {
61
101
  $$bindings?: ReturnType<__sveltets_Render<T, V>['bindings']>;
62
102
  } & ReturnType<__sveltets_Render<T, V>['exports']>;
63
- <T extends Record<PropertyKey, any>, V = unknown>(internal: unknown, props: ReturnType<__sveltets_Render<T, V>['props']> & {}): ReturnType<__sveltets_Render<T, V>['exports']>;
103
+ <T extends Record<PropertyKey, any>, V>(internal: unknown, props: ReturnType<__sveltets_Render<T, V>['props']> & {}): ReturnType<__sveltets_Render<T, V>['exports']>;
64
104
  z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
65
105
  }
66
106
  /**
@@ -71,5 +111,5 @@ interface $$IsomorphicComponent {
71
111
  * <Component />
72
112
  */
73
113
  declare const Column: $$IsomorphicComponent;
74
- type Column<T extends Record<PropertyKey, any>, V = unknown> = InstanceType<typeof Column<T, V>>;
114
+ type Column<T extends Record<PropertyKey, any>, V> = InstanceType<typeof Column<T, V>>;
75
115
  export default Column;