svelte-tably 1.0.0 → 1.0.1-next.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.
@@ -8,11 +8,20 @@
8
8
 
9
9
  -->
10
10
 
11
- <script lang="ts">
11
+ <script module lang='ts'>
12
+
13
+ export function getDefaultHeader<T extends AnyRecord,V>(title: string) {
14
+ return (
15
+ (anchor: Comment) => snippetLiteral(defaultHeader)(anchor, () => title)
16
+ ) as unknown as () => any
17
+ }
18
+
19
+ </script>
20
+
21
+ <script lang='ts'>
12
22
 
13
- import { fromProps, type AnyRecord } from '../utility.svelte.js'
14
- import type { Snippet } from 'svelte'
15
- import { ColumnState, type ColumnProps, type HeaderCtx, type ColumnSnippets } from './column.svelte.js'
23
+ import { fromProps, snippetLiteral, type AnyRecord } from '../utility.svelte.js'
24
+ import { ColumnState, type ColumnProps, type HeaderCtx, type ColumnSnippets } from './column-state.svelte.js'
16
25
 
17
26
  type T = $$Generic<Record<PropertyKey, any>>
18
27
  type V = $$Generic
@@ -24,18 +33,7 @@
24
33
 
25
34
  </script>
26
35
 
27
- <script module lang='ts'>
28
-
29
- declare const defaultHeader: <T extends AnyRecord>(anchor: unknown, title: () => string, ctx: HeaderCtx<T>) => ReturnType<Snippet>
30
-
31
- export function getDefaultHeader<T extends AnyRecord,V>(title: string) {
32
- return (
33
- (anchor: unknown, ctx: HeaderCtx<T>) => defaultHeader<T>(anchor, () => title, ctx)
34
- ) as Exclude<ColumnSnippets<T, V>['header'], string>
35
- }
36
-
37
- </script>
38
36
 
39
- {#snippet defaultHeader(title: string, ctx: HeaderCtx<T>)}
37
+ {#snippet defaultHeader(title: string)}
40
38
  {title}
41
39
  {/snippet}
@@ -1,8 +1,27 @@
1
- export declare function getDefaultHeader<T extends AnyRecord, V>(title: string): Exclude<ColumnSnippets<T, V>["header"], string>;
1
+ export declare function getDefaultHeader<T extends AnyRecord, V>(title: string): () => any;
2
2
  import { type AnyRecord } from '../utility.svelte.js';
3
- import { type ColumnSnippets } from './column.svelte.js';
3
+ import { type HeaderCtx } from './column-state.svelte.js';
4
4
  declare class __sveltets_Render<T extends Record<PropertyKey, any>, V> {
5
- props(): ColumnProps<T_1, V_1>;
5
+ props(): {
6
+ id: string;
7
+ table?: import("../index.js").TableState<T> | undefined;
8
+ header?: string | import("svelte").Snippet<[ctx: HeaderCtx<T>]> | undefined;
9
+ row?: import("svelte").Snippet<[item: T, ctx: import("./column-state.svelte.js").RowColumnCtx<T, V>]> | undefined;
10
+ statusbar?: import("svelte").Snippet<[ctx: import("./column-state.svelte.js").StatusbarCtx<T>]> | undefined;
11
+ sticky?: boolean | undefined;
12
+ show?: boolean | undefined;
13
+ sortby?: boolean | undefined;
14
+ width?: number | undefined;
15
+ fixed?: boolean | undefined;
16
+ value?: ((item: T) => V) | undefined;
17
+ sort?: boolean | ((a: V, b: V) => number) | undefined;
18
+ resizeable?: boolean | undefined;
19
+ filter?: ((value: V) => boolean) | undefined;
20
+ style?: string | undefined;
21
+ class?: string | undefined;
22
+ onclick?: ((event: MouseEvent, rowColumnCtx: import("./column-state.svelte.js").RowColumnCtx<T, V>) => void) | undefined;
23
+ pad?: "row" | "header" | "both" | undefined;
24
+ };
6
25
  events(): {};
7
26
  slots(): {};
8
27
  bindings(): "";
@@ -0,0 +1,138 @@
1
+ import { type Snippet } from 'svelte';
2
+ import { TableState, type RowCtx } from '../table/table-state.svelte.js';
3
+ import { type AnyRecord } from '../utility.svelte.js';
4
+ export type ColumnProps<T extends AnyRecord, V> = ({
5
+ id: string;
6
+ table?: TableState<T>;
7
+ } & ColumnSnippets<T, V> & ColumnDefaults<T> & ColumnOptions<T, V>) extends infer K ? {
8
+ [P in keyof K]: K[P];
9
+ } : never;
10
+ export interface HeaderCtx<T> {
11
+ readonly data: T[];
12
+ /**
13
+ * Is true when displaying in the header,
14
+ * so additional content can be shown if desired,
15
+ * so the header snippet can be re-used.
16
+ */
17
+ readonly header?: boolean;
18
+ }
19
+ export interface RowColumnCtx<T extends AnyRecord, V> extends RowCtx<T> {
20
+ readonly value: V;
21
+ readonly columnHovered: boolean;
22
+ }
23
+ export type StatusbarCtx<T extends AnyRecord> = {
24
+ readonly data: T[];
25
+ };
26
+ export type ColumnSnippets<T extends AnyRecord, V> = {
27
+ header?: Snippet<[ctx: HeaderCtx<T>]> | string;
28
+ row?: Snippet<[item: T, ctx: RowColumnCtx<T, V>]>;
29
+ statusbar?: Snippet<[ctx: StatusbarCtx<T>]>;
30
+ };
31
+ type ColumnDefaults<T> = {
32
+ /**
33
+ * Is this column sticky by default?
34
+ * @default false
35
+ */
36
+ sticky?: boolean;
37
+ /**
38
+ * Is this column visible by default?
39
+ * @default true
40
+ */
41
+ show?: boolean;
42
+ /**
43
+ * Is this column sorted by default?
44
+ * @default false
45
+ */
46
+ sortby?: boolean;
47
+ /**
48
+ * The width of the column in pixels by default
49
+ * @default 150
50
+ */
51
+ width?: number;
52
+ };
53
+ type ColumnOptions<T extends AnyRecord, V> = {
54
+ /**
55
+ * Fixed is like sticky, but in its own category — meant to not be moved/hidden ex. select-boxes
56
+ * @default false
57
+ */
58
+ fixed?: boolean;
59
+ /**
60
+ * The value of the row. Required for sorting/filtering
61
+ * @example row => row.name
62
+ */
63
+ value?: (item: T) => V;
64
+ /**
65
+ * Makes the column sortable. Sorts based of a sorting function.
66
+ *
67
+ * **Important**   `value`-attribute is required adjacent to this.
68
+ *
69
+ * If `true` uses the default `.sort()` algorithm.
70
+ *
71
+ * @default false
72
+ */
73
+ sort?: boolean | ((a: V, b: V) => number);
74
+ /**
75
+ * Is this column resizeable?
76
+ * Can not be resized if Table is marked as `resizeable={false}`
77
+ * @default true
78
+ */
79
+ resizeable?: boolean;
80
+ /**
81
+ *
82
+ * @example (value) => value.includes(search)
83
+ */
84
+ filter?: (value: V) => boolean;
85
+ /** Styling for the column element (td) */
86
+ style?: string;
87
+ /** Class for the column element (td) */
88
+ class?: string;
89
+ /** Event when the row-column is clicked */
90
+ onclick?: (event: MouseEvent, rowColumnCtx: RowColumnCtx<T, V>) => void;
91
+ /**
92
+ * Pad child element of `td`/`th` instead of the column element itself.
93
+ * This ensures the child element "fills" the whole column.
94
+ * Ex. good if you want to make the column an anchor link; `<a href='...'>`
95
+ */
96
+ pad?: 'row' | 'header' | 'both';
97
+ };
98
+ export declare class ColumnState<T extends AnyRecord = any, V = any> {
99
+ #private;
100
+ id: string;
101
+ /**
102
+ * Associated table
103
+ */
104
+ table: TableState<T>;
105
+ snippets: {
106
+ header: Snippet<[ctx: HeaderCtx<T>]> | (() => any) | undefined;
107
+ /** Title is the header-snippet, with header-ctx: `{ header: false }` */
108
+ title: (...args: any[]) => any;
109
+ row: Snippet<[item: T, ctx: RowColumnCtx<T, V>]> | undefined;
110
+ statusbar: Snippet<[ctx: StatusbarCtx<T>]> | undefined;
111
+ };
112
+ /**
113
+ * Variables that can be saved (e.g. localStorage)
114
+ * and re-provided, where these are default-fallbacks
115
+ */
116
+ defaults: {
117
+ sticky: boolean;
118
+ show: boolean;
119
+ sortby: boolean;
120
+ width: number;
121
+ };
122
+ /** Static options */
123
+ options: {
124
+ fixed: boolean;
125
+ sort: boolean | ((a: V, b: V) => number);
126
+ filter: ((value: V) => boolean) | undefined;
127
+ value: ((item: T) => V) | undefined;
128
+ resizeable: boolean;
129
+ style: string | undefined;
130
+ class: string | undefined;
131
+ onclick: ((event: MouseEvent, rowColumnCtx: RowColumnCtx<T, V>) => void) | undefined;
132
+ padRow: boolean;
133
+ padHeader: boolean;
134
+ };
135
+ toggleVisiblity(): void;
136
+ constructor(props: ColumnProps<T, V>);
137
+ }
138
+ export {};
@@ -1,4 +1,4 @@
1
- import { TableState } from '../table/table.svelte.js';
1
+ import { TableState } from '../table/table-state.svelte.js';
2
2
  import { getDefaultHeader } from './Column.svelte';
3
3
  export class ColumnState {
4
4
  #props = {};
@@ -10,7 +10,7 @@
10
10
 
11
11
  <script lang='ts'>
12
12
 
13
- import { ExpandableState, type ExpandableProps } from './expandable.svelte.js'
13
+ import { ExpandableState, type ExpandableProps } from './expandable-state.svelte.js'
14
14
  import type { AnyRecord } from '../utility.svelte.js'
15
15
  import { fromProps } from '../utility.svelte.js'
16
16
 
@@ -1,6 +1,7 @@
1
+ import { type ExpandableProps } from './expandable-state.svelte.js';
1
2
  import type { AnyRecord } from '../utility.svelte.js';
2
3
  declare class __sveltets_Render<T extends AnyRecord> {
3
- props(): ExpandableProps<T_1>;
4
+ props(): ExpandableProps<T>;
4
5
  events(): {};
5
6
  slots(): {};
6
7
  bindings(): "";
@@ -0,0 +1,48 @@
1
+ import { type RowCtx } from '../table/table-state.svelte.js';
2
+ import type { AnyRecord } from '../utility.svelte.js';
3
+ import type { Snippet } from 'svelte';
4
+ import type { EasingFunction } from 'svelte/transition';
5
+ export interface ExpandableProps<T extends AnyRecord> {
6
+ content: Snippet<[item: T, ctx: RowCtx<T>]>;
7
+ /**
8
+ * How many ms to slide open?
9
+ * @default { duration: 200, easing: sineInOut }
10
+ */
11
+ slide?: {
12
+ /** In milliseconds @default 150 */
13
+ duration?: number;
14
+ /** @default sineInOut */
15
+ easing?: EasingFunction;
16
+ };
17
+ /**
18
+ * Whether you can click on a row to expand/collapse it
19
+ * @default true
20
+ */
21
+ click?: boolean;
22
+ /**
23
+ * Whether to show the chevron on the left?
24
+ * @default 'hover'
25
+ */
26
+ chevron?: 'always' | 'hover' | 'never';
27
+ /**
28
+ * Whether multiple can be open at a time?
29
+ * @default false
30
+ */
31
+ multiple?: boolean;
32
+ }
33
+ export declare class ExpandableState<T extends AnyRecord> {
34
+ #private;
35
+ snippets: {
36
+ content: Snippet<[item: T, ctx: RowCtx<T>]>;
37
+ };
38
+ options: {
39
+ slide: {
40
+ duration: number;
41
+ easing: EasingFunction;
42
+ };
43
+ click: boolean;
44
+ chevron: "hover" | "always" | "never";
45
+ multiple: boolean;
46
+ };
47
+ constructor(props: ExpandableProps<T>);
48
+ }
@@ -1,4 +1,4 @@
1
- import { TableState } from '../table/table.svelte.js';
1
+ import { TableState } from '../table/table-state.svelte.js';
2
2
  import { sineInOut } from 'svelte/easing';
3
3
  export class ExpandableState {
4
4
  #table;
package/dist/index.d.ts CHANGED
@@ -3,8 +3,8 @@ export { default as Panel } from './panel/Panel.svelte';
3
3
  export { default as Column } from './column/Column.svelte';
4
4
  export { default as Row } from './row/Row.svelte';
5
5
  export { default as Expandable } from './expandable/Expandable.svelte';
6
- export type { TableState, TableProps } from './table/table.svelte.js';
7
- export type { RowState, RowProps } from './row/row.svelte.js';
8
- export type { ColumnState, ColumnProps } from './column/column.svelte.js';
9
- export type { ExpandableState, ExpandableProps } from './expandable/expandable.svelte.js';
10
- export type { PanelState, PanelProps } from './panel/panel.svelte.js';
6
+ export type { TableState, TableProps } from './table/table-state.svelte.js';
7
+ export type { RowState, RowProps } from './row/row-state.svelte.js';
8
+ export type { ColumnState, ColumnProps } from './column/column-state.svelte.js';
9
+ export type { ExpandableState, ExpandableProps } from './expandable/expandable-state.svelte.js';
10
+ export type { PanelState, PanelProps } from './panel/panel-state.svelte.js';
@@ -10,7 +10,7 @@
10
10
 
11
11
  <script lang='ts' generics='T extends Record<PropertyKey, unknown>'>
12
12
 
13
- import { PanelState, type PanelProps } from './panel.svelte.js'
13
+ import { PanelState, type PanelProps } from './panel-state.svelte.js'
14
14
  import { fromProps } from '../utility.svelte.js'
15
15
 
16
16
  let {...props}: PanelProps<T> = $props()
@@ -1,5 +1,6 @@
1
+ import { type PanelProps } from './panel-state.svelte.js';
1
2
  declare class __sveltets_Render<T extends Record<PropertyKey, unknown>> {
2
- props(): PanelProps<T_1>;
3
+ props(): PanelProps<T>;
3
4
  events(): {};
4
5
  slots(): {};
5
6
  bindings(): "";
@@ -0,0 +1,25 @@
1
+ import { TableState } from '../table/table-state.svelte.js';
2
+ import { type AnyRecord } from '../utility.svelte.js';
3
+ import type { Snippet } from 'svelte';
4
+ export type PanelProps<T extends AnyRecord> = {
5
+ id: string;
6
+ /**
7
+ * A darkened backdrop?
8
+ * @default true
9
+ */
10
+ backdrop?: boolean;
11
+ table?: TableState<T>;
12
+ children: Snippet<[ctx: PanelCtx<T>]>;
13
+ };
14
+ export type PanelCtx<T extends AnyRecord> = {
15
+ readonly table: TableState<T>;
16
+ readonly data: T[];
17
+ };
18
+ export declare class PanelState<T extends AnyRecord> {
19
+ #private;
20
+ table: TableState<T>;
21
+ id: string;
22
+ backdrop: boolean;
23
+ children: Snippet<[ctx: PanelCtx<T>]>;
24
+ constructor(props: PanelProps<T>);
25
+ }
@@ -1,4 +1,4 @@
1
- import { TableState } from '../table/table.svelte.js';
1
+ import { TableState } from '../table/table-state.svelte.js';
2
2
  export class PanelState {
3
3
  #props = {};
4
4
  table;
@@ -10,7 +10,7 @@
10
10
 
11
11
  <script lang='ts'>
12
12
 
13
- import { RowState, type RowProps } from './row.svelte.js'
13
+ import { RowState, type RowProps } from './row-state.svelte.js'
14
14
  import type { AnyRecord } from '../utility.svelte.js'
15
15
  import { fromProps } from '../utility.svelte.js'
16
16
 
@@ -1,6 +1,7 @@
1
+ import { type RowProps } from './row-state.svelte.js';
1
2
  import type { AnyRecord } from '../utility.svelte.js';
2
3
  declare class __sveltets_Render<T extends AnyRecord> {
3
- props(): RowProps<T_1>;
4
+ props(): RowProps<T>;
4
5
  events(): {};
5
6
  slots(): {};
6
7
  bindings(): "";
@@ -0,0 +1,43 @@
1
+ import { type RowCtx } from '../table/table-state.svelte.js';
2
+ import type { AnyRecord } from '../utility.svelte.js';
3
+ import type { Snippet } from 'svelte';
4
+ type ContextOptions<T extends AnyRecord> = {
5
+ /**
6
+ * Only show when hovering the row?
7
+ * @default true
8
+ */
9
+ hover?: boolean;
10
+ /**
11
+ * @defualt 'max-content'
12
+ */
13
+ width?: string;
14
+ };
15
+ export interface RowProps<T extends AnyRecord> {
16
+ /**
17
+ * A sticky context column on the right of each table
18
+ */
19
+ context?: Snippet<[item: T, ctx: RowCtx<T>]>;
20
+ contextOptions?: ContextOptions<T>;
21
+ contextHeader?: Snippet;
22
+ onclick?: (event: MouseEvent, ctx: RowCtx<T>) => void;
23
+ oncontextmenu?: (event: MouseEvent, ctx: RowCtx<T>) => void;
24
+ }
25
+ export declare class RowState<T extends AnyRecord> {
26
+ #private;
27
+ snippets: {
28
+ context: Snippet<[item: T, ctx: RowCtx<T>]> | undefined;
29
+ contextHeader: Snippet<[]> | undefined;
30
+ };
31
+ events: {
32
+ onclick: ((event: MouseEvent, ctx: RowCtx<T>) => void) | undefined;
33
+ oncontextmenu: ((event: MouseEvent, ctx: RowCtx<T>) => void) | undefined;
34
+ };
35
+ options: {
36
+ context: {
37
+ hover: boolean;
38
+ width: string;
39
+ };
40
+ };
41
+ constructor(props: RowProps<T>);
42
+ }
43
+ export {};
@@ -1,4 +1,4 @@
1
- import { TableState } from '../table/table.svelte.js';
1
+ import { TableState } from '../table/table-state.svelte.js';
2
2
  export class RowState {
3
3
  #table;
4
4
  #props = {};
@@ -8,9 +8,6 @@
8
8
 
9
9
  -->
10
10
 
11
- <script module lang="ts">
12
- </script>
13
-
14
11
  <script lang="ts">
15
12
  import { type Snippet } from 'svelte'
16
13
  import { fly } from 'svelte/transition'
@@ -23,12 +20,12 @@
23
20
  type RowCtx,
24
21
  type RowSelectCtx,
25
22
  type TableProps
26
- } from './table.svelte.js'
23
+ } from './table-state.svelte.js'
27
24
  import Panel from '../panel/Panel.svelte'
28
25
  import Column from '../column/Column.svelte'
29
26
  import { assignDescriptors, capitalize, fromProps, mounted, segmentize } from '../utility.svelte.js'
30
27
  import { conditional } from '../conditional.svelte.js'
31
- import { ColumnState, type RowColumnCtx } from '../column/column.svelte.js'
28
+ import { ColumnState, type RowColumnCtx } from '../column/column-state.svelte.js'
32
29
  import Expandable from '../expandable/Expandable.svelte'
33
30
  import { SizeTween } from '../size-tween.svelte.js'
34
31
  import { on } from 'svelte/events'
@@ -330,7 +327,7 @@
330
327
  positioning: false
331
328
  } as ItemState<any>,
332
329
  selected: false,
333
- expanded: false,
330
+ expanded: false
334
331
  })}
335
332
  {:else}
336
333
  {column.options.value?.(row)}
@@ -345,7 +342,7 @@
345
342
  {/if}
346
343
 
347
344
  <svelte:head>
348
- {@html `<style>${style}</style>`}
345
+ {@html `<`+`style>${style}</style>`}
349
346
  </svelte:head>
350
347
 
351
348
  {#snippet chevronSnippet(rotation: number = 0)}
@@ -399,7 +396,7 @@
399
396
  >
400
397
  {@render renderable(column)?.(args[0], args[1])}
401
398
  {#if isHeader && table.dataState.sortby === column.id && sortable}
402
- <span class='sorting-icon'>
399
+ <span class="sorting-icon">
403
400
  {@render chevronSnippet(table.dataState.sortReverse ? 0 : 180)}
404
401
  </span>
405
402
  {/if}
@@ -429,7 +426,7 @@
429
426
  >
430
427
  {@render renderable(column)?.(args[0], args[1])}
431
428
  {#if isHeader && table.dataState.sortby === column.id && sortable}
432
- <span class='sorting-icon'>
429
+ <span class="sorting-icon">
433
430
  {@render chevronSnippet(table.dataState.sortReverse ? 0 : 180)}
434
431
  </span>
435
432
  {/if}
@@ -456,7 +453,7 @@
456
453
  >
457
454
  {@render renderable(column)?.(args[0], args[1])}
458
455
  {#if isHeader && table.dataState.sortby === column.id && sortable}
459
- <span class='sorting-icon'>
456
+ <span class="sorting-icon">
460
457
  {@render chevronSnippet(table.dataState.sortReverse ? 0 : 180)}
461
458
  </span>
462
459
  {/if}
@@ -1046,7 +1043,8 @@
1046
1043
  width: auto !important;
1047
1044
  border-bottom: 1px solid var(--tably-border);
1048
1045
  }
1049
- .headers > tr > .column, .headers > tr > .context-col {
1046
+ .headers > tr > .column,
1047
+ .headers > tr > .context-col {
1050
1048
  border-bottom: 1px solid var(--tably-border);
1051
1049
  border-left: 1px solid var(--tably-border-grid);
1052
1050
  }
@@ -1084,7 +1082,8 @@
1084
1082
  display: flex;
1085
1083
  overflow: hidden;
1086
1084
 
1087
- &:not(.pad), &.pad > :global(*:first-child) {
1085
+ &:not(.pad),
1086
+ &.pad > :global(*:first-child) {
1088
1087
  padding-left: var(--tably-padding-x);
1089
1088
  }
1090
1089
  }
@@ -1092,7 +1091,8 @@
1092
1091
  & > *:last-child:not(.context-col) {
1093
1092
  width: 100%;
1094
1093
 
1095
- &:not(.pad), &.pad > :global(*:first-child) {
1094
+ &:not(.pad),
1095
+ &.pad > :global(*:first-child) {
1096
1096
  padding-right: var(--tably-padding-x);
1097
1097
  }
1098
1098
  }
@@ -1100,7 +1100,8 @@
1100
1100
 
1101
1101
  .row > .column {
1102
1102
  background-color: var(--tably-bg);
1103
- &:not(.pad), &.pad > :global(*:first-child) {
1103
+ &:not(.pad),
1104
+ &.pad > :global(*:first-child) {
1104
1105
  padding-top: var(--tably-padding-y);
1105
1106
  padding-bottom: var(--tably-padding-y);
1106
1107
  }
@@ -1,8 +1,100 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import { type Snippet } from 'svelte';
3
+ import { TableState, type TableProps } from './table-state.svelte.js';
4
+ import { type RowColumnCtx } from '../column/column-state.svelte.js';
1
5
  declare class __sveltets_Render<T extends Record<PropertyKey, unknown>> {
2
- props(): any;
6
+ props(): TableProps<T> & {
7
+ content?: Snippet<[context: {
8
+ Column: {
9
+ <V>(internal: unknown, props: {
10
+ id: string;
11
+ table?: TableState<T> | undefined;
12
+ header?: string | Snippet<[ctx: import("../column/column-state.svelte.js").HeaderCtx<T>]> | undefined;
13
+ row?: Snippet<[item: T, ctx: RowColumnCtx<T, V>]> | undefined;
14
+ statusbar?: Snippet<[ctx: import("../column/column-state.svelte.js").StatusbarCtx<T>]> | undefined;
15
+ sticky?: boolean | undefined;
16
+ show?: boolean | undefined;
17
+ sortby?: boolean | undefined;
18
+ width?: number | undefined;
19
+ fixed?: boolean | undefined;
20
+ value?: ((item: T) => V) | undefined;
21
+ sort?: boolean | ((a: V, b: V) => number) | undefined;
22
+ resizeable?: boolean | undefined;
23
+ filter?: ((value: V) => boolean) | undefined;
24
+ style?: string | undefined;
25
+ class?: string | undefined;
26
+ onclick?: ((event: MouseEvent, rowColumnCtx: RowColumnCtx<T, V>) => void) | undefined;
27
+ pad?: "row" | "header" | "both" | undefined;
28
+ }): {};
29
+ new <V>(options: import("svelte").ComponentConstructorOptions<{
30
+ id: string;
31
+ table?: TableState<T> | undefined;
32
+ header?: string | Snippet<[ctx: import("../column/column-state.svelte.js").HeaderCtx<T>]> | undefined;
33
+ row?: Snippet<[item: T, ctx: RowColumnCtx<T, V>]> | undefined;
34
+ statusbar?: Snippet<[ctx: import("../column/column-state.svelte.js").StatusbarCtx<T>]> | undefined;
35
+ sticky?: boolean | undefined;
36
+ show?: boolean | undefined;
37
+ sortby?: boolean | undefined;
38
+ width?: number | undefined;
39
+ fixed?: boolean | undefined;
40
+ value?: ((item: T) => V) | undefined;
41
+ sort?: boolean | ((a: V, b: V) => number) | undefined;
42
+ resizeable?: boolean | undefined;
43
+ filter?: ((value: V) => boolean) | undefined;
44
+ style?: string | undefined;
45
+ class?: string | undefined;
46
+ onclick?: ((event: MouseEvent, rowColumnCtx: RowColumnCtx<T, V>) => void) | undefined;
47
+ pad?: "row" | "header" | "both" | undefined;
48
+ }>): SvelteComponent<{
49
+ id: string;
50
+ table?: TableState<T> | undefined;
51
+ header?: string | Snippet<[ctx: import("../column/column-state.svelte.js").HeaderCtx<T>]> | undefined;
52
+ row?: Snippet<[item: T, ctx: RowColumnCtx<T, V>]> | undefined;
53
+ statusbar?: Snippet<[ctx: import("../column/column-state.svelte.js").StatusbarCtx<T>]> | undefined;
54
+ sticky?: boolean | undefined;
55
+ show?: boolean | undefined;
56
+ sortby?: boolean | undefined;
57
+ width?: number | undefined;
58
+ fixed?: boolean | undefined;
59
+ value?: ((item: T) => V) | undefined;
60
+ sort?: boolean | ((a: V, b: V) => number) | undefined;
61
+ resizeable?: boolean | undefined;
62
+ filter?: ((value: V) => boolean) | undefined;
63
+ style?: string | undefined;
64
+ class?: string | undefined;
65
+ onclick?: ((event: MouseEvent, rowColumnCtx: RowColumnCtx<T, V>) => void) | undefined;
66
+ pad?: "row" | "header" | "both" | undefined;
67
+ }, {}, {}> & {
68
+ $$bindings?: ReturnType<() => "">;
69
+ } & {};
70
+ };
71
+ Panel: {
72
+ (internal: unknown, props: import("../index.js").PanelProps<T>): {};
73
+ new (options: import("svelte").ComponentConstructorOptions<import("../index.js").PanelProps<T>>): SvelteComponent<import("../index.js").PanelProps<T>, {}, {}> & {
74
+ $$bindings?: ReturnType<() => "">;
75
+ };
76
+ z_$$bindings?: ReturnType<() => "">;
77
+ };
78
+ Expandable: {
79
+ (internal: unknown, props: import("../index.js").ExpandableProps<T>): {};
80
+ new (options: import("svelte").ComponentConstructorOptions<import("../index.js").ExpandableProps<T>>): SvelteComponent<import("../index.js").ExpandableProps<T>, {}, {}> & {
81
+ $$bindings?: ReturnType<() => "">;
82
+ };
83
+ z_$$bindings?: ReturnType<() => "">;
84
+ };
85
+ Row: {
86
+ (internal: unknown, props: import("../index.js").RowProps<T>): {};
87
+ new (options: import("svelte").ComponentConstructorOptions<import("../index.js").RowProps<T>>): SvelteComponent<import("../index.js").RowProps<T>, {}, {}> & {
88
+ $$bindings?: ReturnType<() => "">;
89
+ };
90
+ z_$$bindings?: ReturnType<() => "">;
91
+ };
92
+ readonly table: TableState<T>;
93
+ }]> | undefined;
94
+ };
3
95
  events(): {};
4
96
  slots(): {};
5
- bindings(): "data" | "selected" | "panel";
97
+ bindings(): "selected" | "panel" | "data";
6
98
  exports(): {
7
99
  toCSV: (opts?: {
8
100
  /** Semi-colons as separator? */
@@ -1,4 +1,4 @@
1
- import type { TableProps, TableState } from './table.svelte.js';
1
+ import type { TableProps, TableState } from './table-state.svelte.js';
2
2
  export declare class Data<T extends Record<PropertyKey, unknown>> {
3
3
  #private;
4
4
  origin: T[];
@@ -0,0 +1,107 @@
1
+ import { type Snippet } from 'svelte';
2
+ import { ColumnState, type RowColumnCtx } from '../column/column-state.svelte.js';
3
+ import { PanelState } from '../panel/panel-state.svelte.js';
4
+ import { Data } from './data.svelte.js';
5
+ import { type AnyRecord } from '../utility.svelte.js';
6
+ import type { ExpandableState } from '../expandable/expandable-state.svelte.js';
7
+ import type { ItemState } from 'runic-reorder';
8
+ import type { RowState } from '../row/row-state.svelte.js';
9
+ export type HeaderSelectCtx<T extends AnyRecord = any> = {
10
+ isSelected: boolean;
11
+ /** The list of selected items */
12
+ readonly selected: T[];
13
+ /**
14
+ * See [MDN :indeterminate](https://developer.mozilla.org/en-US/docs/Web/CSS/:indeterminate)
15
+ */
16
+ readonly indeterminate: boolean;
17
+ };
18
+ export type RowSelectCtx<T extends AnyRecord = any> = {
19
+ readonly item: T;
20
+ readonly row: RowColumnCtx<T, unknown>;
21
+ data: T[];
22
+ isSelected: boolean;
23
+ };
24
+ export interface RowCtx<T extends AnyRecord> {
25
+ readonly rowHovered: boolean;
26
+ readonly index: number;
27
+ readonly itemState: ItemState<T> | undefined;
28
+ selected: boolean;
29
+ expanded: boolean;
30
+ }
31
+ type SelectOptions<T extends AnyRecord> = {
32
+ /**
33
+ * The style, in which the selection is shown
34
+ *
35
+ * NOTE: If using `edge` | 'side', "show" will always be `hover`. This is due to
36
+ * an inconsistency/limitation of matching the scroll between the selection div and the rows.
37
+ *
38
+ * @default 'column'
39
+ */
40
+ style?: 'column';
41
+ /**
42
+ * When to show the row-select, when not selected?
43
+ * @default 'hover'
44
+ */
45
+ show?: 'hover' | 'always' | 'never';
46
+ /**
47
+ * Custom snippet
48
+ */
49
+ headerSnippet?: Snippet<[context: HeaderSelectCtx]>;
50
+ rowSnippet?: Snippet<[context: RowSelectCtx<T>]>;
51
+ };
52
+ export type TableProps<T extends AnyRecord> = {
53
+ id?: string;
54
+ data: T[];
55
+ selected?: T[];
56
+ /** Current visible panel */
57
+ panel?: string;
58
+ filters?: ((item: T) => boolean)[];
59
+ /**
60
+ * **For a reorderable table, the data is mutated when reordered.**
61
+ *
62
+ * Reorderable tables cannot
63
+ * - Be filtered
64
+ * - Be sorted
65
+ * @default false
66
+ */
67
+ reorderable?: boolean;
68
+ /** Whether columns in this table can be resized */
69
+ resizeable?: boolean;
70
+ /** Whether to enable selection */
71
+ select?: boolean | SelectOptions<T>;
72
+ /** Create missing columns automatically. */
73
+ auto?: boolean;
74
+ };
75
+ export declare class TableState<T extends AnyRecord> {
76
+ #private;
77
+ id: string;
78
+ dataState: Data<T>;
79
+ data: T[];
80
+ columns: Record<string, ColumnState<T, any>>;
81
+ panels: Record<string, PanelState<T>>;
82
+ expandable: undefined | ExpandableState<T>;
83
+ row: undefined | RowState<T>;
84
+ /** Currently selected items */
85
+ get selected(): T[];
86
+ set selected(items: T[]);
87
+ /** Column positions based on column ids */
88
+ positions: {
89
+ fixed: ColumnState<T, any>[];
90
+ sticky: ColumnState<T, any>[];
91
+ scroll: ColumnState<T, any>[];
92
+ hidden: ColumnState<T, any>[];
93
+ };
94
+ /** Primarily externally managed options */
95
+ options: {
96
+ panel: string | undefined;
97
+ filters: boolean | ((item: T) => boolean)[];
98
+ resizeable: boolean;
99
+ reorderable: boolean;
100
+ select: boolean | SelectOptions<T>;
101
+ auto: boolean;
102
+ };
103
+ add(state: ColumnState<T, any> | PanelState<T>): (() => void) | undefined;
104
+ static getContext<T extends AnyRecord>(): TableState<T> | undefined;
105
+ constructor(tableProps: TableProps<T>);
106
+ }
107
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { getContext, setContext } from 'svelte';
2
- import { ColumnState } from '../column/column.svelte.js';
3
- import { PanelState } from '../panel/panel.svelte.js';
2
+ import { ColumnState } from '../column/column-state.svelte.js';
3
+ import { PanelState } from '../panel/panel-state.svelte.js';
4
4
  import { Data } from './data.svelte.js';
5
5
  export class TableState {
6
6
  #props = {};
@@ -1,4 +1,4 @@
1
- import type { TableState } from './table.svelte.js';
1
+ import type { TableState } from './table-state.svelte.js';
2
2
  export declare class Virtualization<T extends Record<PropertyKey, unknown>> {
3
3
  #private;
4
4
  scrollTop: number;
@@ -1,3 +1,4 @@
1
+ import { Snippet } from 'svelte';
1
2
  export type Simplify<T> = T extends infer V ? {
2
3
  [K in keyof V]: V[K];
3
4
  } : never;
@@ -18,4 +19,6 @@ export declare function assignDescriptors<T extends AnyRecord, B extends AnyReco
18
19
  export declare function capitalize(str: string): string;
19
20
  /** Split words when going from lower case to uppercase; `someWords-split` -> `some Word Split...` */
20
21
  export declare function segmentize(str: string): string;
22
+ type SnippetLiteralProperties<K extends unknown[], Result extends (() => unknown)[] = []> = K extends [infer First, ...infer Rest] ? SnippetLiteralProperties<Rest, [...Result, () => First]> : Result;
23
+ export declare function snippetLiteral<K extends unknown[]>(snippet: Snippet<K>): ((anchor: Comment, ...args: SnippetLiteralProperties<K>) => ReturnType<typeof snippet>);
21
24
  export {};
@@ -102,3 +102,6 @@ export function segmentize(str) {
102
102
  }
103
103
  return result.trim();
104
104
  }
105
+ export function snippetLiteral(snippet) {
106
+ return snippet;
107
+ }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "svelte-tably",
3
- "version": "1.0.0",
3
+ "description": "A high performant dynamic table for Svelte 5",
4
+ "version": "1.0.1-next.0",
4
5
  "repository": {
5
6
  "type": "git",
6
7
  "url": "git+https://github.com/Refzlund/svelte-tably.git"
@@ -10,26 +11,20 @@
10
11
  "url": "https://github.com/Refzlund/svelte-tably/issues"
11
12
  },
12
13
  "files": [
13
- "dist",
14
- "!dist/**/*.test.*",
15
- "!dist/**/*.spec.*"
14
+ "dist"
16
15
  ],
17
- "sideEffects": [
18
- "**/*.css"
19
- ],
20
- "svelte": "./dist/index.js",
21
- "types": "./dist/index.d.ts",
22
16
  "type": "module",
23
17
  "exports": {
24
18
  ".": {
25
19
  "types": "./dist/index.d.ts",
26
- "default": "./dist/index.js"
20
+ "default": "./dist/index.js",
21
+ "svelte": "./dist/index.js"
27
22
  }
28
23
  },
29
24
  "dependencies": {
30
- "runic-reorder": "^1.0.0"
25
+ "runic-reorder": "^1"
31
26
  },
32
27
  "peerDependencies": {
33
- "svelte": "^5.0.0"
28
+ "svelte": "^5"
34
29
  }
35
30
  }