svelte-tably 1.0.0 → 1.0.1

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.
@@ -1,41 +1,39 @@
1
- <!-- @component
2
-
3
- This is a description, \
4
- on how to use this.
5
-
6
- @example
7
- <Component />
8
-
9
- -->
10
-
11
- <script lang="ts">
12
-
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'
16
-
17
- type T = $$Generic<Record<PropertyKey, any>>
18
- type V = $$Generic
19
-
20
- let {...props}: ColumnProps<T, V> = $props()
21
- const properties = fromProps(props)
22
-
23
- new ColumnState<T, V>(properties)
24
-
25
- </script>
26
-
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
-
39
- {#snippet defaultHeader(title: string, ctx: HeaderCtx<T>)}
40
- {title}
1
+ <!-- @component
2
+
3
+ This is a description, \
4
+ on how to use this.
5
+
6
+ @example
7
+ <Component />
8
+
9
+ -->
10
+
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'>
22
+
23
+ import { fromProps, snippetLiteral, type AnyRecord } from '../utility.svelte.js'
24
+ import { ColumnState, type ColumnProps, type HeaderCtx, type ColumnSnippets } from './column-state.svelte.js'
25
+
26
+ type T = $$Generic<Record<PropertyKey, any>>
27
+ type V = $$Generic
28
+
29
+ let {...props}: ColumnProps<T, V> = $props()
30
+ const properties = fromProps(props)
31
+
32
+ new ColumnState<T, V>(properties)
33
+
34
+ </script>
35
+
36
+
37
+ {#snippet defaultHeader(title: string)}
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 = {};
@@ -1,24 +1,24 @@
1
- <!-- @component
2
-
3
- This is a description, \
4
- on how to use this.
5
-
6
- @example
7
- <Component />
8
-
9
- -->
10
-
11
- <script lang='ts'>
12
-
13
- import { ExpandableState, type ExpandableProps } from './expandable.svelte.js'
14
- import type { AnyRecord } from '../utility.svelte.js'
15
- import { fromProps } from '../utility.svelte.js'
16
-
17
- type T = $$Generic<AnyRecord>
18
-
19
- let { ...restProps }: ExpandableProps<T> = $props()
20
-
21
- const properties = fromProps(restProps)
22
- new ExpandableState<T>(properties)
23
-
24
- </script>
1
+ <!-- @component
2
+
3
+ This is a description, \
4
+ on how to use this.
5
+
6
+ @example
7
+ <Component />
8
+
9
+ -->
10
+
11
+ <script lang='ts'>
12
+
13
+ import { ExpandableState, type ExpandableProps } from './expandable-state.svelte.js'
14
+ import type { AnyRecord } from '../utility.svelte.js'
15
+ import { fromProps } from '../utility.svelte.js'
16
+
17
+ type T = $$Generic<AnyRecord>
18
+
19
+ let { ...restProps }: ExpandableProps<T> = $props()
20
+
21
+ const properties = fromProps(restProps)
22
+ new ExpandableState<T>(properties)
23
+
24
+ </script>
@@ -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';
@@ -1,21 +1,21 @@
1
- <!-- @component
2
-
3
- This is a description, \
4
- on how to use this.
5
-
6
- @example
7
- <Component />
8
-
9
- -->
10
-
11
- <script lang='ts' generics='T extends Record<PropertyKey, unknown>'>
12
-
13
- import { PanelState, type PanelProps } from './panel.svelte.js'
14
- import { fromProps } from '../utility.svelte.js'
15
-
16
- let {...props}: PanelProps<T> = $props()
17
- const properties = fromProps(props)
18
-
19
- new PanelState<T>(properties)
20
-
1
+ <!-- @component
2
+
3
+ This is a description, \
4
+ on how to use this.
5
+
6
+ @example
7
+ <Component />
8
+
9
+ -->
10
+
11
+ <script lang='ts' generics='T extends Record<PropertyKey, unknown>'>
12
+
13
+ import { PanelState, type PanelProps } from './panel-state.svelte.js'
14
+ import { fromProps } from '../utility.svelte.js'
15
+
16
+ let {...props}: PanelProps<T> = $props()
17
+ const properties = fromProps(props)
18
+
19
+ new PanelState<T>(properties)
20
+
21
21
  </script>
@@ -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;
@@ -1,24 +1,24 @@
1
- <!-- @component
2
-
3
- This is a description, \
4
- on how to use this.
5
-
6
- @example
7
- <Component />
8
-
9
- -->
10
-
11
- <script lang='ts'>
12
-
13
- import { RowState, type RowProps } from './row.svelte.js'
14
- import type { AnyRecord } from '../utility.svelte.js'
15
- import { fromProps } from '../utility.svelte.js'
16
-
17
- type T = $$Generic<AnyRecord>
18
-
19
- let { ...restProps }: RowProps<T> = $props()
20
-
21
- const properties = fromProps(restProps)
22
- new RowState<T>(properties)
23
-
24
- </script>
1
+ <!-- @component
2
+
3
+ This is a description, \
4
+ on how to use this.
5
+
6
+ @example
7
+ <Component />
8
+
9
+ -->
10
+
11
+ <script lang='ts'>
12
+
13
+ import { RowState, type RowProps } from './row-state.svelte.js'
14
+ import type { AnyRecord } from '../utility.svelte.js'
15
+ import { fromProps } from '../utility.svelte.js'
16
+
17
+ type T = $$Generic<AnyRecord>
18
+
19
+ let { ...restProps }: RowProps<T> = $props()
20
+
21
+ const properties = fromProps(restProps)
22
+ new RowState<T>(properties)
23
+
24
+ </script>
@@ -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 = {};