@ims360/svelte-ivory 0.3.2 → 0.3.3
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/basic/Element.svelte +2 -2
- package/dist/components/table/Column.svelte +19 -19
- package/dist/components/table/Column.svelte.d.ts +1 -0
- package/dist/components/table/Column.svelte.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/lib/components/basic/Element.svelte +2 -2
- package/src/lib/components/table/Column.svelte +19 -19
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
}: ElementProps & { div?: HTMLElement } = $props();
|
|
43
43
|
|
|
44
44
|
function isAnchor(props: ElementProps): props is AnchorAttributes {
|
|
45
|
-
return 'href' in props;
|
|
45
|
+
return 'href' in props && typeof props.href !== 'undefined';
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
function isButton(props: ElementProps): props is ButtonAttributes {
|
|
49
|
-
return 'onclick' in props || 'type' in props;
|
|
49
|
+
return ('onclick' in props && typeof props.onclick !== 'undefined') || 'type' in props;
|
|
50
50
|
}
|
|
51
51
|
</script>
|
|
52
52
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { merge } from '../../utils/functions';
|
|
4
4
|
import { type Snippet } from 'svelte';
|
|
5
5
|
import type { ClassValue } from 'svelte/elements';
|
|
6
|
+
import Element from '../basic/Element.svelte';
|
|
6
7
|
import type { ColumnConfig } from './columnController.svelte';
|
|
7
8
|
import { getRowContext } from './Row.svelte';
|
|
8
9
|
import { getTableContext } from './Table.svelte';
|
|
@@ -12,6 +13,7 @@
|
|
|
12
13
|
/** If the type is incorrect pass the "row" property with the right type */
|
|
13
14
|
children: Snippet;
|
|
14
15
|
onclick?: (e: Event) => void | Promise<void>;
|
|
16
|
+
href?: string;
|
|
15
17
|
/** Cannot be used with resizable columns*/
|
|
16
18
|
ignoreWidth?: boolean;
|
|
17
19
|
offsetNestingLevel?: number;
|
|
@@ -21,37 +23,38 @@
|
|
|
21
23
|
<script lang="ts">
|
|
22
24
|
let {
|
|
23
25
|
class: clazz,
|
|
24
|
-
children,
|
|
25
26
|
onclick,
|
|
27
|
+
href,
|
|
26
28
|
ignoreWidth = false,
|
|
29
|
+
offsetNestingLevel = 0,
|
|
27
30
|
// ColumnConfig
|
|
31
|
+
id,
|
|
32
|
+
width,
|
|
33
|
+
minWidth,
|
|
28
34
|
resizable = true,
|
|
29
|
-
|
|
35
|
+
header,
|
|
30
36
|
...props
|
|
31
37
|
}: ColumnProps = $props();
|
|
32
38
|
|
|
33
39
|
// Register the new column if this is the first table row that was rendered
|
|
34
40
|
const tableContext = getTableContext();
|
|
35
|
-
const column = tableContext.registerColumn({ resizable,
|
|
41
|
+
const column = tableContext.registerColumn({ id, width, minWidth, resizable, header });
|
|
36
42
|
const rowContext = getRowContext();
|
|
37
43
|
|
|
38
44
|
const finalOnClick = $derived(onclick || rowContext.onclick);
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (finalOnClick) return 'button';
|
|
43
|
-
if (rowContext.href) return 'a';
|
|
44
|
-
return 'div';
|
|
45
|
+
const finalHref = $derived.by(() => {
|
|
46
|
+
if (finalOnClick) return undefined;
|
|
47
|
+
return href || rowContext.href;
|
|
45
48
|
});
|
|
46
49
|
|
|
47
50
|
// passes updated props to the column
|
|
48
51
|
$effect(() => {
|
|
49
|
-
column.updateConfig({ resizable,
|
|
52
|
+
column.updateConfig({ resizable, minWidth, id, header });
|
|
50
53
|
});
|
|
51
54
|
|
|
52
55
|
// this must be separate to the above effect, since otherwise the width would be reset on every scroll
|
|
53
56
|
$effect(() => {
|
|
54
|
-
if (!resizable && typeof
|
|
57
|
+
if (!resizable && typeof width !== 'undefined') column.width = width;
|
|
55
58
|
});
|
|
56
59
|
|
|
57
60
|
const widthStyle = $derived(
|
|
@@ -60,11 +63,10 @@
|
|
|
60
63
|
</script>
|
|
61
64
|
|
|
62
65
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
onclick={
|
|
66
|
-
href={
|
|
67
|
-
type={allowClicking ? 'button' : undefined}
|
|
66
|
+
<Element
|
|
67
|
+
{...props}
|
|
68
|
+
onclick={finalOnClick}
|
|
69
|
+
href={finalHref}
|
|
68
70
|
style={ignoreWidth ? '' : `width: ${widthStyle}`}
|
|
69
71
|
class={merge([
|
|
70
72
|
'box-border flex h-full shrink-0 flex-row items-center justify-start gap-1 truncate',
|
|
@@ -72,6 +74,4 @@
|
|
|
72
74
|
theme.current.table?.column?.class,
|
|
73
75
|
clazz
|
|
74
76
|
])}
|
|
75
|
-
|
|
76
|
-
{@render children()}
|
|
77
|
-
</svelte:element>
|
|
77
|
+
/>
|
|
@@ -6,6 +6,7 @@ export interface ColumnProps extends ColumnConfig {
|
|
|
6
6
|
/** If the type is incorrect pass the "row" property with the right type */
|
|
7
7
|
children: Snippet;
|
|
8
8
|
onclick?: (e: Event) => void | Promise<void>;
|
|
9
|
+
href?: string;
|
|
9
10
|
/** Cannot be used with resizable columns*/
|
|
10
11
|
ignoreWidth?: boolean;
|
|
11
12
|
offsetNestingLevel?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Column.svelte.d.ts","sourceRoot":"","sources":["../../../src/lib/components/table/Column.svelte.ts"],"names":[],"mappings":"AAKI,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"Column.svelte.d.ts","sourceRoot":"","sources":["../../../src/lib/components/table/Column.svelte.ts"],"names":[],"mappings":"AAKI,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAI9D,MAAM,WAAW,WAAY,SAAQ,YAAY;IAC7C,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,2EAA2E;IAC3E,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAwDL,QAAA,MAAM,MAAM,iDAAwC,CAAC;AACrD,KAAK,MAAM,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC;AACxC,eAAe,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
}: ElementProps & { div?: HTMLElement } = $props();
|
|
43
43
|
|
|
44
44
|
function isAnchor(props: ElementProps): props is AnchorAttributes {
|
|
45
|
-
return 'href' in props;
|
|
45
|
+
return 'href' in props && typeof props.href !== 'undefined';
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
function isButton(props: ElementProps): props is ButtonAttributes {
|
|
49
|
-
return 'onclick' in props || 'type' in props;
|
|
49
|
+
return ('onclick' in props && typeof props.onclick !== 'undefined') || 'type' in props;
|
|
50
50
|
}
|
|
51
51
|
</script>
|
|
52
52
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { merge } from '$lib/utils/functions';
|
|
4
4
|
import { type Snippet } from 'svelte';
|
|
5
5
|
import type { ClassValue } from 'svelte/elements';
|
|
6
|
+
import Element from '../basic/Element.svelte';
|
|
6
7
|
import type { ColumnConfig } from './columnController.svelte';
|
|
7
8
|
import { getRowContext } from './Row.svelte';
|
|
8
9
|
import { getTableContext } from './Table.svelte';
|
|
@@ -12,6 +13,7 @@
|
|
|
12
13
|
/** If the type is incorrect pass the "row" property with the right type */
|
|
13
14
|
children: Snippet;
|
|
14
15
|
onclick?: (e: Event) => void | Promise<void>;
|
|
16
|
+
href?: string;
|
|
15
17
|
/** Cannot be used with resizable columns*/
|
|
16
18
|
ignoreWidth?: boolean;
|
|
17
19
|
offsetNestingLevel?: number;
|
|
@@ -21,37 +23,38 @@
|
|
|
21
23
|
<script lang="ts">
|
|
22
24
|
let {
|
|
23
25
|
class: clazz,
|
|
24
|
-
children,
|
|
25
26
|
onclick,
|
|
27
|
+
href,
|
|
26
28
|
ignoreWidth = false,
|
|
29
|
+
offsetNestingLevel = 0,
|
|
27
30
|
// ColumnConfig
|
|
31
|
+
id,
|
|
32
|
+
width,
|
|
33
|
+
minWidth,
|
|
28
34
|
resizable = true,
|
|
29
|
-
|
|
35
|
+
header,
|
|
30
36
|
...props
|
|
31
37
|
}: ColumnProps = $props();
|
|
32
38
|
|
|
33
39
|
// Register the new column if this is the first table row that was rendered
|
|
34
40
|
const tableContext = getTableContext();
|
|
35
|
-
const column = tableContext.registerColumn({ resizable,
|
|
41
|
+
const column = tableContext.registerColumn({ id, width, minWidth, resizable, header });
|
|
36
42
|
const rowContext = getRowContext();
|
|
37
43
|
|
|
38
44
|
const finalOnClick = $derived(onclick || rowContext.onclick);
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (finalOnClick) return 'button';
|
|
43
|
-
if (rowContext.href) return 'a';
|
|
44
|
-
return 'div';
|
|
45
|
+
const finalHref = $derived.by(() => {
|
|
46
|
+
if (finalOnClick) return undefined;
|
|
47
|
+
return href || rowContext.href;
|
|
45
48
|
});
|
|
46
49
|
|
|
47
50
|
// passes updated props to the column
|
|
48
51
|
$effect(() => {
|
|
49
|
-
column.updateConfig({ resizable,
|
|
52
|
+
column.updateConfig({ resizable, minWidth, id, header });
|
|
50
53
|
});
|
|
51
54
|
|
|
52
55
|
// this must be separate to the above effect, since otherwise the width would be reset on every scroll
|
|
53
56
|
$effect(() => {
|
|
54
|
-
if (!resizable && typeof
|
|
57
|
+
if (!resizable && typeof width !== 'undefined') column.width = width;
|
|
55
58
|
});
|
|
56
59
|
|
|
57
60
|
const widthStyle = $derived(
|
|
@@ -60,11 +63,10 @@
|
|
|
60
63
|
</script>
|
|
61
64
|
|
|
62
65
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
onclick={
|
|
66
|
-
href={
|
|
67
|
-
type={allowClicking ? 'button' : undefined}
|
|
66
|
+
<Element
|
|
67
|
+
{...props}
|
|
68
|
+
onclick={finalOnClick}
|
|
69
|
+
href={finalHref}
|
|
68
70
|
style={ignoreWidth ? '' : `width: ${widthStyle}`}
|
|
69
71
|
class={merge([
|
|
70
72
|
'box-border flex h-full shrink-0 flex-row items-center justify-start gap-1 truncate',
|
|
@@ -72,6 +74,4 @@
|
|
|
72
74
|
theme.current.table?.column?.class,
|
|
73
75
|
clazz
|
|
74
76
|
])}
|
|
75
|
-
|
|
76
|
-
{@render children()}
|
|
77
|
-
</svelte:element>
|
|
77
|
+
/>
|