svelte-tably 1.0.0-next.9 → 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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +299 -93
  3. package/dist/column/Column.svelte +39 -0
  4. package/dist/column/Column.svelte.d.ts +46 -0
  5. package/dist/column/column-state.svelte.d.ts +138 -0
  6. package/dist/column/column-state.svelte.js +64 -0
  7. package/dist/conditional.svelte.d.ts +10 -0
  8. package/dist/conditional.svelte.js +26 -0
  9. package/dist/expandable/Expandable.svelte +24 -0
  10. package/dist/expandable/Expandable.svelte.d.ts +26 -0
  11. package/dist/expandable/expandable-state.svelte.d.ts +48 -0
  12. package/dist/expandable/expandable-state.svelte.js +27 -0
  13. package/dist/index.d.ts +10 -3
  14. package/dist/index.js +5 -3
  15. package/dist/panel/Panel.svelte +21 -0
  16. package/dist/{Panel.svelte.d.ts → panel/Panel.svelte.d.ts} +2 -28
  17. package/dist/panel/panel-state.svelte.d.ts +25 -0
  18. package/dist/panel/panel-state.svelte.js +18 -0
  19. package/dist/row/Row.svelte +24 -0
  20. package/dist/row/Row.svelte.d.ts +26 -0
  21. package/dist/row/row-state.svelte.d.ts +43 -0
  22. package/dist/row/row-state.svelte.js +28 -0
  23. package/dist/size-tween.svelte.d.ts +16 -0
  24. package/dist/size-tween.svelte.js +33 -0
  25. package/dist/table/Table.svelte +1140 -0
  26. package/dist/table/Table.svelte.d.ts +123 -0
  27. package/dist/table/data.svelte.d.ts +14 -0
  28. package/dist/table/data.svelte.js +81 -0
  29. package/dist/table/table-state.svelte.d.ts +107 -0
  30. package/dist/table/table-state.svelte.js +76 -0
  31. package/dist/table/virtualization.svelte.d.ts +14 -0
  32. package/dist/table/virtualization.svelte.js +86 -0
  33. package/dist/utility.svelte.d.ts +24 -0
  34. package/dist/utility.svelte.js +107 -0
  35. package/package.json +29 -53
  36. package/dist/Column.svelte +0 -164
  37. package/dist/Column.svelte.d.ts +0 -115
  38. package/dist/Panel.svelte +0 -74
  39. package/dist/Table.svelte +0 -906
  40. package/dist/Table.svelte.d.ts +0 -112
@@ -0,0 +1,64 @@
1
+ import { TableState } from '../table/table-state.svelte.js';
2
+ import { getDefaultHeader } from './Column.svelte';
3
+ export class ColumnState {
4
+ #props = {};
5
+ id = $derived(this.#props.id);
6
+ /**
7
+ * Associated table
8
+ */
9
+ table;
10
+ snippets = $derived({
11
+ header: typeof this.#props.header === 'string' ? getDefaultHeader(this.#props.header) : this.#props.header,
12
+ /** Title is the header-snippet, with header-ctx: `{ header: false }` */
13
+ title: (...args) => {
14
+ const getData = () => this.table.dataState.current;
15
+ return this.snippets.header?.(...[args[0], () => ({
16
+ get header() { return false; },
17
+ get data() {
18
+ return getData();
19
+ }
20
+ })]);
21
+ },
22
+ row: this.#props.row,
23
+ statusbar: this.#props.statusbar
24
+ });
25
+ /**
26
+ * Variables that can be saved (e.g. localStorage)
27
+ * and re-provided, where these are default-fallbacks
28
+ */
29
+ defaults = $derived({
30
+ sticky: this.#props.sticky ?? false,
31
+ show: this.#props.show ?? true,
32
+ sortby: this.#props.sortby ?? false,
33
+ width: this.#props.width ?? 150
34
+ });
35
+ /** Static options */
36
+ options = $derived({
37
+ fixed: this.#props.fixed ?? false,
38
+ sort: this.#props.sort ?? false,
39
+ filter: this.#props.filter,
40
+ value: this.#props.value,
41
+ resizeable: this.#props.resizeable ?? true,
42
+ style: this.#props.style,
43
+ class: this.#props.class,
44
+ onclick: this.#props.onclick,
45
+ padRow: this.#props.pad === 'row' || this.#props.pad === 'both',
46
+ padHeader: this.#props.pad === 'header' || this.#props.pad === 'both'
47
+ });
48
+ toggleVisiblity() {
49
+ const index = this.table.positions.hidden.indexOf(this);
50
+ if (index > -1)
51
+ this.table.positions.hidden.splice(index, 1);
52
+ else
53
+ this.table.positions.hidden.push(this);
54
+ }
55
+ constructor(props) {
56
+ this.#props = props;
57
+ this.table = props.table ?? TableState.getContext();
58
+ if (!this.table) {
59
+ throw new Error('svelte-tably: Column must be associated with a Table');
60
+ }
61
+ const remove = this.table.add(this);
62
+ $effect(() => remove);
63
+ }
64
+ }
@@ -0,0 +1,10 @@
1
+ type Actionable<A extends unknown | unknown[]> = {
2
+ destroy?: () => void;
3
+ update?: (args: A) => void;
4
+ };
5
+ export declare function conditional<A extends unknown | unknown[]>(node: HTMLElement, arg: [
6
+ condition: (() => boolean) | boolean,
7
+ action: ((node: HTMLElement, args?: A) => void | Actionable<A>),
8
+ args?: A
9
+ ]): void;
10
+ export {};
@@ -0,0 +1,26 @@
1
+ import { untrack } from 'svelte';
2
+ /*
3
+ use:conditional={[condition, action, arg]}
4
+ use:conditional={[condition, (node) => action(node, arg), updatedArg]}
5
+ */
6
+ export function conditional(node, arg) {
7
+ let prev;
8
+ let clean;
9
+ $effect(() => {
10
+ prev?.destroy?.();
11
+ clean?.();
12
+ if (typeof arg[0] === 'function' ? arg[0]() : arg[0]) {
13
+ untrack(() => {
14
+ prev = arg[1](node, arg[2]);
15
+ if (prev?.update) {
16
+ clean = $effect.root(() => {
17
+ $effect(() => {
18
+ prev.update(arg[2]);
19
+ });
20
+ });
21
+ }
22
+ });
23
+ return clean;
24
+ }
25
+ });
26
+ }
@@ -0,0 +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-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>
@@ -0,0 +1,26 @@
1
+ import { type ExpandableProps } from './expandable-state.svelte.js';
2
+ import type { AnyRecord } from '../utility.svelte.js';
3
+ declare class __sveltets_Render<T extends AnyRecord> {
4
+ props(): ExpandableProps<T>;
5
+ events(): {};
6
+ slots(): {};
7
+ bindings(): "";
8
+ exports(): {};
9
+ }
10
+ interface $$IsomorphicComponent {
11
+ new <T extends AnyRecord>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
12
+ $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
13
+ } & ReturnType<__sveltets_Render<T>['exports']>;
14
+ <T extends AnyRecord>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
15
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
16
+ }
17
+ /**
18
+ * This is a description, \
19
+ * on how to use this.
20
+ *
21
+ * @example
22
+ * <Component />
23
+ */
24
+ declare const Expandable: $$IsomorphicComponent;
25
+ type Expandable<T extends AnyRecord> = InstanceType<typeof Expandable<T>>;
26
+ export default Expandable;
@@ -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
+ }
@@ -0,0 +1,27 @@
1
+ import { TableState } from '../table/table-state.svelte.js';
2
+ import { sineInOut } from 'svelte/easing';
3
+ export class ExpandableState {
4
+ #table;
5
+ #props = {};
6
+ snippets = $derived({
7
+ content: this.#props.content
8
+ });
9
+ options = $derived({
10
+ slide: {
11
+ duration: this.#props.slide?.duration ?? 150,
12
+ easing: this.#props.slide?.easing ?? sineInOut
13
+ },
14
+ click: this.#props.click ?? true,
15
+ chevron: this.#props.chevron ?? 'hover',
16
+ multiple: this.#props.multiple ?? false
17
+ });
18
+ constructor(props) {
19
+ this.#props = props;
20
+ this.#table = TableState.getContext();
21
+ if (!this.#table) {
22
+ throw new Error('svelte-tably: Expandable must be associated with a Table');
23
+ }
24
+ this.#table.expandable = this;
25
+ $effect(() => () => this.#table.expandable === this && (this.#table.expandable = undefined));
26
+ }
27
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,10 @@
1
- export { default as default } from './Table.svelte';
2
- export { default as Panel } from './Panel.svelte';
3
- export { default as Column } from './Column.svelte';
1
+ export { default as default } from './table/Table.svelte';
2
+ export { default as Panel } from './panel/Panel.svelte';
3
+ export { default as Column } from './column/Column.svelte';
4
+ export { default as Row } from './row/Row.svelte';
5
+ export { default as Expandable } from './expandable/Expandable.svelte';
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';
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
- export { default as default } from './Table.svelte';
2
- export { default as Panel } from './Panel.svelte';
3
- export { default as Column } from './Column.svelte';
1
+ export { default as default } from './table/Table.svelte';
2
+ export { default as Panel } from './panel/Panel.svelte';
3
+ export { default as Column } from './column/Column.svelte';
4
+ export { default as Row } from './row/Row.svelte';
5
+ export { default as Expandable } from './expandable/Expandable.svelte';
@@ -0,0 +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-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
+ </script>
@@ -1,32 +1,6 @@
1
- export interface Panel<T extends Record<PropertyKey, unknown> = Record<PropertyKey, unknown>> {
2
- /** A darkened backdrop? */
3
- backdrop: boolean;
4
- content: Snippet<[context: {
5
- readonly table: TableState<T>;
6
- readonly data: T[];
7
- }]>;
8
- }
9
- export declare class PanelTween {
10
- #private;
11
- current: number;
12
- transitioning: boolean;
13
- /** bind:clientWidth */
14
- width: number;
15
- set target(value: number);
16
- constructor(cb: () => string | undefined, added?: number);
17
- }
18
- import { type Snippet } from 'svelte';
19
- import { type TableState } from './Table.svelte';
1
+ import { type PanelProps } from './panel-state.svelte.js';
20
2
  declare class __sveltets_Render<T extends Record<PropertyKey, unknown>> {
21
- props(): {
22
- id: string;
23
- /** A darkened backdrop? */
24
- backdrop?: boolean;
25
- children: Snippet<[context: {
26
- readonly table: TableState<T>;
27
- readonly data: T[];
28
- }]>;
29
- };
3
+ props(): PanelProps<T>;
30
4
  events(): {};
31
5
  slots(): {};
32
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
+ }
@@ -0,0 +1,18 @@
1
+ import { TableState } from '../table/table-state.svelte.js';
2
+ export class PanelState {
3
+ #props = {};
4
+ table;
5
+ id = $derived(this.#props.id);
6
+ backdrop = $derived(this.#props.backdrop ?? true);
7
+ children = $derived(this.#props.children);
8
+ constructor(props) {
9
+ this.#props = props;
10
+ const table = props.table ?? TableState.getContext();
11
+ if (!table) {
12
+ throw new Error('svelte-tably: Panel must be associated with a Table');
13
+ }
14
+ this.table = table;
15
+ const remove = table.add(this);
16
+ $effect(() => remove);
17
+ }
18
+ }
@@ -0,0 +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-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>
@@ -0,0 +1,26 @@
1
+ import { type RowProps } from './row-state.svelte.js';
2
+ import type { AnyRecord } from '../utility.svelte.js';
3
+ declare class __sveltets_Render<T extends AnyRecord> {
4
+ props(): RowProps<T>;
5
+ events(): {};
6
+ slots(): {};
7
+ bindings(): "";
8
+ exports(): {};
9
+ }
10
+ interface $$IsomorphicComponent {
11
+ new <T extends AnyRecord>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
12
+ $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
13
+ } & ReturnType<__sveltets_Render<T>['exports']>;
14
+ <T extends AnyRecord>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
15
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
16
+ }
17
+ /**
18
+ * This is a description, \
19
+ * on how to use this.
20
+ *
21
+ * @example
22
+ * <Component />
23
+ */
24
+ declare const Row: $$IsomorphicComponent;
25
+ type Row<T extends AnyRecord> = InstanceType<typeof Row<T>>;
26
+ export default Row;
@@ -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 {};
@@ -0,0 +1,28 @@
1
+ import { TableState } from '../table/table-state.svelte.js';
2
+ export class RowState {
3
+ #table;
4
+ #props = {};
5
+ snippets = $derived({
6
+ context: this.#props.context,
7
+ contextHeader: this.#props.contextHeader
8
+ });
9
+ events = $derived({
10
+ onclick: this.#props.onclick,
11
+ oncontextmenu: this.#props.oncontextmenu
12
+ });
13
+ options = $derived({
14
+ context: {
15
+ hover: this.#props.contextOptions?.hover ?? true,
16
+ width: this.#props.contextOptions?.width ?? 'max-content'
17
+ }
18
+ });
19
+ constructor(props) {
20
+ this.#props = props;
21
+ this.#table = TableState.getContext();
22
+ if (!this.#table) {
23
+ throw new Error('svelte-tably: Expandable must be associated with a Table');
24
+ }
25
+ this.#table.row = this;
26
+ $effect(() => () => this.#table.row === this && (this.#table.row = undefined));
27
+ }
28
+ }
@@ -0,0 +1,16 @@
1
+ import type { EasingFunction } from 'svelte/transition';
2
+ interface SizeOptions {
3
+ min?: number;
4
+ duration?: number;
5
+ easing?: EasingFunction;
6
+ }
7
+ export declare class SizeTween {
8
+ #private;
9
+ current: number;
10
+ transitioning: boolean;
11
+ /** bind:offsetWidth bind:offsetHeight */
12
+ size: number;
13
+ set target(value: number);
14
+ constructor(cb: () => boolean | undefined, opts?: SizeOptions);
15
+ }
16
+ export {};
@@ -0,0 +1,33 @@
1
+ import { untrack } from 'svelte';
2
+ import { sineInOut } from 'svelte/easing';
3
+ import { Tween } from 'svelte/motion';
4
+ export class SizeTween {
5
+ #tweenOptions = { duration: 300, easing: sineInOut };
6
+ #tween = new Tween(0, this.#tweenOptions);
7
+ current = $derived(this.#tween.current);
8
+ transitioning = $state(false);
9
+ /** bind:offsetWidth bind:offsetHeight */
10
+ size = $state(0);
11
+ set target(value) {
12
+ this.transitioning = true;
13
+ this.#tween.set(value, this.#tweenOptions).then(() => this.transitioning = false);
14
+ }
15
+ constructor(cb, opts = {}) {
16
+ if ('duration' in opts) {
17
+ this.#tweenOptions.duration = opts.duration;
18
+ }
19
+ if ('easing' in opts) {
20
+ this.#tweenOptions.easing = opts.easing;
21
+ }
22
+ untrack(() => {
23
+ if (cb()) {
24
+ requestAnimationFrame(() => {
25
+ this.#tween.set(Math.max(this.size, opts.min ?? 0), { duration: 0 });
26
+ });
27
+ }
28
+ });
29
+ $effect.pre(() => {
30
+ this.target = cb() ? Math.max(this.size, opts.min ?? 0) : 0;
31
+ });
32
+ }
33
+ }