svelte-bricks 0.1.7 → 0.2.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.
- package/{Masonry.svelte → dist/Masonry.svelte} +17 -13
- package/{Masonry.svelte.d.ts → dist/Masonry.svelte.d.ts} +12 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +49 -25
- package/readme.md +87 -20
- package/index.d.ts +0 -1
- package/index.js +0 -1
|
@@ -14,27 +14,27 @@
|
|
|
14
14
|
|
|
15
15
|
<script>import { flip } from 'svelte/animate';
|
|
16
16
|
import { fade } from 'svelte/transition';
|
|
17
|
-
export let items;
|
|
18
|
-
export let minColWidth = 330;
|
|
19
|
-
export let maxColWidth = 500;
|
|
20
|
-
export let gap = 20;
|
|
21
|
-
export let masonryWidth = 0;
|
|
22
|
-
export let masonryHeight = 0;
|
|
23
17
|
export let animate = true;
|
|
24
|
-
export let style = ``;
|
|
25
|
-
export let duration = 200;
|
|
26
18
|
export { className as class };
|
|
27
19
|
export let columnClass = ``;
|
|
20
|
+
export let duration = 200;
|
|
21
|
+
export let gap = 20;
|
|
28
22
|
// On non-primitive types, we need a property to tell masonry items apart. This component
|
|
29
23
|
// hard-codes the name of this property to 'id'. See https://svelte.dev/tutorial/keyed-each-blocks.
|
|
30
|
-
export let idKey = `id`;
|
|
31
24
|
export let getId = (item) => {
|
|
32
|
-
if (typeof item === `string`)
|
|
33
|
-
return item;
|
|
34
25
|
if (typeof item === `number`)
|
|
35
26
|
return item;
|
|
27
|
+
if (typeof item === `string`)
|
|
28
|
+
return item;
|
|
36
29
|
return item[idKey];
|
|
37
30
|
};
|
|
31
|
+
export let idKey = `id`;
|
|
32
|
+
export let items;
|
|
33
|
+
export let masonryHeight = 0;
|
|
34
|
+
export let masonryWidth = 0;
|
|
35
|
+
export let maxColWidth = 500;
|
|
36
|
+
export let minColWidth = 330;
|
|
37
|
+
export let style = ``;
|
|
38
38
|
let className = ``;
|
|
39
39
|
$: nCols = Math.min(items.length, Math.floor(masonryWidth / (minColWidth + gap)) || 1);
|
|
40
40
|
$: itemsToCols = items.reduce((cols, item, idx) => {
|
|
@@ -58,12 +58,16 @@ $: itemsToCols = items.reduce((cols, item, idx) => {
|
|
|
58
58
|
out:fade|local={{ delay: 0, duration }}
|
|
59
59
|
animate:flip={{ duration }}
|
|
60
60
|
>
|
|
61
|
-
<slot {idx} {item}
|
|
61
|
+
<slot {idx} {item}>
|
|
62
|
+
<span>{item}</span>
|
|
63
|
+
</slot>
|
|
62
64
|
</div>
|
|
63
65
|
{/each}
|
|
64
66
|
{:else}
|
|
65
67
|
{#each col as [item, idx] (getId(item))}
|
|
66
|
-
<slot {idx} {item}
|
|
68
|
+
<slot {idx} {item}>
|
|
69
|
+
<span>{item}</span>
|
|
70
|
+
</slot>
|
|
67
71
|
{/each}
|
|
68
72
|
{/if}
|
|
69
73
|
</div>
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
declare class __sveltets_Render<Item> {
|
|
3
3
|
props(): {
|
|
4
|
-
items: Item[];
|
|
5
|
-
minColWidth?: number | undefined;
|
|
6
|
-
maxColWidth?: number | undefined;
|
|
7
|
-
gap?: number | undefined;
|
|
8
|
-
masonryWidth?: number | undefined;
|
|
9
|
-
masonryHeight?: number | undefined;
|
|
10
4
|
animate?: boolean | undefined;
|
|
11
|
-
style?: string | undefined;
|
|
12
|
-
duration?: number | undefined;
|
|
13
5
|
class?: string | undefined;
|
|
14
6
|
columnClass?: string | undefined;
|
|
7
|
+
duration?: number | undefined;
|
|
8
|
+
gap?: number | undefined;
|
|
9
|
+
getId?: ((item: Item) => string | number) | undefined;
|
|
15
10
|
idKey?: string | undefined;
|
|
16
|
-
|
|
11
|
+
items: Item[];
|
|
12
|
+
masonryHeight?: number | undefined;
|
|
13
|
+
masonryWidth?: number | undefined;
|
|
14
|
+
maxColWidth?: number | undefined;
|
|
15
|
+
minColWidth?: number | undefined;
|
|
16
|
+
style?: string | undefined;
|
|
17
17
|
};
|
|
18
18
|
events(): {} & {
|
|
19
19
|
[evt: string]: CustomEvent<any>;
|
|
@@ -25,9 +25,9 @@ declare class __sveltets_Render<Item> {
|
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
export
|
|
29
|
-
export
|
|
30
|
-
export
|
|
28
|
+
export type MasonryProps<Item> = ReturnType<__sveltets_Render<Item>['props']>;
|
|
29
|
+
export type MasonryEvents<Item> = ReturnType<__sveltets_Render<Item>['events']>;
|
|
30
|
+
export type MasonrySlots<Item> = ReturnType<__sveltets_Render<Item>['slots']>;
|
|
31
31
|
export default class Masonry<Item> extends SvelteComponentTyped<MasonryProps<Item>, MasonryEvents<Item>, MasonrySlots<Item>> {
|
|
32
32
|
}
|
|
33
33
|
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default, default as Masonry } from './Masonry.svelte';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default, default as Masonry } from './Masonry.svelte';
|
package/package.json
CHANGED
|
@@ -2,32 +2,46 @@
|
|
|
2
2
|
"name": "svelte-bricks",
|
|
3
3
|
"description": "Simple masonry implementation without column balancing",
|
|
4
4
|
"author": "Janosh Riebesell <janosh.riebesell@gmail.com>",
|
|
5
|
-
"homepage": "https://svelte-bricks
|
|
5
|
+
"homepage": "https://janosh.github.io/svelte-bricks",
|
|
6
6
|
"repository": "https://github.com/janosh/svelte-bricks",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.2.0",
|
|
9
9
|
"type": "module",
|
|
10
|
-
"svelte": "
|
|
10
|
+
"svelte": "./dist/index.js",
|
|
11
11
|
"bugs": "https://github.com/janosh/svelte-bricks/issues",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"dev": "vite dev",
|
|
14
|
+
"build": "vite build",
|
|
15
|
+
"preview": "vite preview",
|
|
16
|
+
"package": "svelte-package",
|
|
17
|
+
"serve": "vite build && vite preview",
|
|
18
|
+
"check": "svelte-check --ignore dist",
|
|
19
|
+
"test": "vitest test",
|
|
20
|
+
"changelog": "npx auto-changelog --package --output changelog.md --hide-credit --commit-limit false"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"svelte": "^3.57.0"
|
|
24
|
+
},
|
|
12
25
|
"devDependencies": {
|
|
13
|
-
"@sveltejs/adapter-static": "^
|
|
14
|
-
"@sveltejs/kit": "^1.
|
|
15
|
-
"@
|
|
16
|
-
"@typescript-eslint/
|
|
17
|
-
"eslint": "^
|
|
26
|
+
"@sveltejs/adapter-static": "^2.0.1",
|
|
27
|
+
"@sveltejs/kit": "^1.13.0",
|
|
28
|
+
"@sveltejs/package": "^2.0.2",
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "^5.56.0",
|
|
30
|
+
"@typescript-eslint/parser": "^5.56.0",
|
|
31
|
+
"eslint": "^8.36.0",
|
|
18
32
|
"eslint-plugin-svelte3": "^4.0.0",
|
|
19
|
-
"jsdom": "^
|
|
20
|
-
"mdsvex": "^0.10.
|
|
21
|
-
"prettier": "^2.6
|
|
22
|
-
"prettier-plugin-svelte": "^2.
|
|
23
|
-
"svelte": "^3.
|
|
24
|
-
"svelte-
|
|
25
|
-
"svelte-
|
|
26
|
-
"svelte-
|
|
27
|
-
"svelte2tsx": "^0.
|
|
28
|
-
"typescript": "^
|
|
29
|
-
"vite": "^2.
|
|
30
|
-
"vitest": "^0.
|
|
33
|
+
"jsdom": "^21.1.1",
|
|
34
|
+
"mdsvex": "^0.10.6",
|
|
35
|
+
"prettier": "^2.8.6",
|
|
36
|
+
"prettier-plugin-svelte": "^2.10.0",
|
|
37
|
+
"svelte-check": "^3.1.4",
|
|
38
|
+
"svelte-preprocess": "^5.0.3",
|
|
39
|
+
"svelte-toc": "^0.5.4",
|
|
40
|
+
"svelte-zoo": "^0.4.3",
|
|
41
|
+
"svelte2tsx": "^0.6.10",
|
|
42
|
+
"typescript": "^5.0.2",
|
|
43
|
+
"vite": "^4.2.1",
|
|
44
|
+
"vitest": "^0.29.7"
|
|
31
45
|
},
|
|
32
46
|
"keywords": [
|
|
33
47
|
"svelte",
|
|
@@ -39,8 +53,18 @@
|
|
|
39
53
|
"access": "public"
|
|
40
54
|
},
|
|
41
55
|
"exports": {
|
|
42
|
-
"./
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
56
|
+
"./Masonry.svelte": {
|
|
57
|
+
"types": "./dist/Masonry.svelte.d.ts",
|
|
58
|
+
"svelte": "./dist/Masonry.svelte",
|
|
59
|
+
"default": "./dist/Masonry.svelte"
|
|
60
|
+
},
|
|
61
|
+
".": {
|
|
62
|
+
"types": "./dist/index.d.ts",
|
|
63
|
+
"svelte": "./dist/index.js",
|
|
64
|
+
"default": "./dist/index.js"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"files": [
|
|
68
|
+
"dist"
|
|
69
|
+
]
|
|
70
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<div class="hide-in-docs">
|
|
2
2
|
|
|
3
3
|
<h1 align="center">
|
|
4
|
-
<img src="https://raw.githubusercontent.com/janosh/svelte-bricks/main/static/favicon.svg" alt="
|
|
4
|
+
<img src="https://raw.githubusercontent.com/janosh/svelte-bricks/main/static/favicon.svg" alt="Logo" height=60>
|
|
5
5
|
<br> Svelte Bricks
|
|
6
6
|
</h1>
|
|
7
7
|
|
|
@@ -9,21 +9,20 @@
|
|
|
9
9
|
|
|
10
10
|
[](https://github.com/janosh/svelte-bricks/actions/workflows/test.yml)
|
|
11
11
|
[](https://npmjs.com/package/svelte-bricks)
|
|
12
|
-
[](https://github.com/janosh/svelte-bricks/actions/workflows/gh-pages.yml)
|
|
13
13
|
[](https://results.pre-commit.ci/latest/github/janosh/svelte-bricks/main)
|
|
14
|
+
[](https://stackblitz.com/github/janosh/svelte-bricks)
|
|
14
15
|
|
|
15
16
|
</h4>
|
|
16
17
|
|
|
17
|
-
Naive implementation in Svelte without column balancing.
|
|
18
|
-
|
|
19
|
-
**[Live demo](https://svelte-bricks.netlify.app)**
|
|
18
|
+
Naive implementation in Svelte without column balancing. **[Live demo](https://janosh.github.io/svelte-bricks)**
|
|
20
19
|
|
|
21
20
|
</div>
|
|
22
21
|
|
|
23
22
|
## Installation
|
|
24
23
|
|
|
25
24
|
```sh
|
|
26
|
-
|
|
25
|
+
npm install --dev svelte-bricks
|
|
27
26
|
```
|
|
28
27
|
|
|
29
28
|
## Usage
|
|
@@ -57,7 +56,7 @@ h)
|
|
|
57
56
|
</Masonry>
|
|
58
57
|
```
|
|
59
58
|
|
|
60
|
-
**Note**:
|
|
59
|
+
**Note**: If `items` is an array of objects, this component tries to access an `id` property on each item. This value is used to tell items apart in the keyed `{#each}` block that creates the masonry layout. Without it, Svelte could not avoid duplicates when new items are added or existing ones rearranged. Read the [Svelte docs](https://svelte.dev/tutorial/keyed-each-blocks) for details. To change the name of the identifier key, pass `idKey="some-uniq-key`. Or pass a function `getId = (item: Item) => string | number` that maps items to unique IDs.
|
|
61
60
|
|
|
62
61
|
**Hint**: Balanced columns can be achieved even with this simple implementation if masonry items are allowed to stretch to the column height.
|
|
63
62
|
|
|
@@ -67,19 +66,87 @@ h)
|
|
|
67
66
|
|
|
68
67
|
Additional optional props are:
|
|
69
68
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
69
|
+
1. ```ts
|
|
70
|
+
animate: boolean = true
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Whether to [FLIP-animate](https://svelte.dev/tutorial/animate) masonry items when viewport resizing or other events cause `items` to rearrange.
|
|
74
|
+
|
|
75
|
+
1. ```ts
|
|
76
|
+
class: string = ``
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Applies to the outer `div` wrapping all masonry columns. For use with CSS frameworks like Tailwind.
|
|
80
|
+
|
|
81
|
+
1. ```ts
|
|
82
|
+
columnClass: string = ``
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Applies to each column `div`.
|
|
86
|
+
|
|
87
|
+
1. ```ts
|
|
88
|
+
duration: number = 200
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Transition duration in milli seconds when masonry items are rearranged or added/removed. Set to 0 to disable transitions.
|
|
92
|
+
|
|
93
|
+
1. ```ts
|
|
94
|
+
gap: number = 20
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Gap between columns and items within each column in `px`.
|
|
98
|
+
|
|
99
|
+
1. ```ts
|
|
100
|
+
getId = (item: Item): string | number => {
|
|
101
|
+
if (typeof item === `number`) return item
|
|
102
|
+
if (typeof item === `string`) return item
|
|
103
|
+
return item[idKey]
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Custom function that maps masonry items to unique IDs of type `string` or `number`.
|
|
108
|
+
|
|
109
|
+
1. ```ts
|
|
110
|
+
idKey: string = `id`
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Name of the attribute to use as identifier if items are objects.
|
|
114
|
+
|
|
115
|
+
1. ```ts
|
|
116
|
+
items: Item[]
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The only required prop are the list of items to render where `Item = $$Generic` is a generic type which usually will be `object` but can also be simple types `string` or `number`.
|
|
120
|
+
|
|
121
|
+
1. ```ts
|
|
122
|
+
masonryHeight: number = 0
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The masonry `div`s height in `px`.
|
|
126
|
+
|
|
127
|
+
1. ```ts
|
|
128
|
+
masonryWidth: number = 0
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
The masonry `div`s width in `px`.
|
|
132
|
+
|
|
133
|
+
1. ```ts
|
|
134
|
+
maxColWidth: number = 500
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Maximum column width in `px`.
|
|
138
|
+
|
|
139
|
+
1. ```ts
|
|
140
|
+
minColWidth: number = 330
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Minimum column width in `px`.
|
|
144
|
+
|
|
145
|
+
1. ```ts
|
|
146
|
+
style: string = ``
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Inline styles that will be applied to the top-level `div.masonry`.
|
|
83
150
|
|
|
84
151
|
## Styling
|
|
85
152
|
|
package/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './Masonry.svelte';
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './Masonry.svelte';
|