@axel669/zephyr 0.1.16 → 0.2.0-beta.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/LICENSE +21 -21
- package/package.json +34 -30
- package/readme.md +55 -44
- package/src/composed/data-table/th.svelte +60 -0
- package/src/composed/data-table.md +71 -0
- package/src/composed/data-table.svelte +136 -150
- package/src/composed/entry-button.md +34 -0
- package/src/composed/entry-button.svelte +29 -68
- package/src/composed/table-functions.js +13 -0
- package/src/composed/toast/message.svelte +44 -44
- package/src/composed/toast.md +36 -0
- package/src/composed/toast.svelte +68 -108
- package/src/control/button.md +37 -0
- package/src/control/button.svelte +25 -0
- package/src/control/input.svelte +107 -0
- package/src/control/label.md +0 -0
- package/src/control/label.svelte +36 -0
- package/src/control/link.md +37 -0
- package/src/control/link.svelte +28 -0
- package/src/control/radio.md +49 -0
- package/src/control/radio.svelte +28 -0
- package/src/control/select.md +55 -0
- package/src/control/select.svelte +62 -0
- package/src/control/tabs.md +35 -0
- package/src/control/tabs.svelte +39 -0
- package/src/control/toggle.md +38 -0
- package/src/control/toggle.svelte +47 -0
- package/src/data-display/avatar.md +26 -0
- package/src/data-display/avatar.svelte +23 -0
- package/src/data-display/badge.md +24 -0
- package/src/data-display/badge.svelte +12 -0
- package/src/data-display/chip.md +28 -0
- package/src/data-display/chip.svelte +26 -0
- package/src/data-display/details.md +0 -0
- package/src/{details.svelte → data-display/details.svelte} +3 -3
- package/src/data-display/popover.md +32 -0
- package/src/data-display/popover.svelte +23 -0
- package/src/data-display/progress.md +30 -0
- package/src/data-display/progress.svelte +25 -0
- package/src/data-display/table.md +29 -0
- package/src/data-display/table.svelte +36 -0
- package/src/data-display/tooltip.md +25 -0
- package/src/data-display/tooltip.svelte +15 -0
- package/src/dialogs/alert.md +0 -0
- package/src/dialogs/alert.svelte +4 -4
- package/src/dialogs/confirm.md +0 -0
- package/src/dialogs/confirm.svelte +5 -5
- package/src/functions.md +77 -0
- package/src/handler$.mjs +20 -68
- package/src/index.mjs +55 -92
- package/src/info/icon.md +20 -0
- package/src/info/icon.svelte +9 -0
- package/src/info/notification.md +37 -0
- package/src/info/notification.svelte +16 -0
- package/src/info/titlebar.md +46 -0
- package/src/info/titlebar.svelte +18 -0
- package/src/info/toaster.md +23 -0
- package/src/info/toaster.svelte +14 -0
- package/src/inline-dialog.svelte +23 -23
- package/src/layout/dialog.md +33 -0
- package/src/layout/dialog.svelte +24 -0
- package/src/layout/drawer.md +47 -0
- package/src/layout/drawer.svelte +47 -0
- package/src/layout/flex.md +30 -0
- package/src/layout/flex.svelte +22 -0
- package/src/layout/grid.md +36 -0
- package/src/layout/grid.svelte +26 -0
- package/src/layout/modal.md +35 -0
- package/src/layout/modal.svelte +58 -0
- package/src/layout/paper.md +77 -0
- package/src/layout/paper.svelte +45 -0
- package/src/layout/screen.md +31 -0
- package/src/layout/screen.svelte +32 -0
- package/src/{circle-spinner.svelte → spinner/circle-spinner.svelte} +2 -2
- package/src/{hexagon-spinner.svelte → spinner/hexagon-spinner.svelte} +2 -2
- package/src/spinner/spinners.md +0 -0
- package/src/text.md +22 -0
- package/src/text.svelte +20 -49
- package/src/variant.mjs +12 -12
- package/src/wsx.mjs +24 -45
- package/src/avatar.svelte +0 -54
- package/src/badge.svelte +0 -40
- package/src/button.svelte +0 -86
- package/src/chip.svelte +0 -56
- package/src/dialog.svelte +0 -54
- package/src/drawer.svelte +0 -121
- package/src/flex.svelte +0 -57
- package/src/grid.svelte +0 -66
- package/src/icon.svelte +0 -34
- package/src/input/area.svelte +0 -98
- package/src/input/elems.mjs +0 -7
- package/src/input/email.svelte +0 -104
- package/src/input/file.svelte +0 -82
- package/src/input/number.svelte +0 -104
- package/src/input/password.svelte +0 -101
- package/src/input/search.svelte +0 -104
- package/src/input/text.svelte +0 -104
- package/src/link.svelte +0 -67
- package/src/modal.svelte +0 -73
- package/src/notification.svelte +0 -57
- package/src/paper.svelte +0 -127
- package/src/popover.svelte +0 -60
- package/src/progress.svelte +0 -60
- package/src/radio.svelte +0 -82
- package/src/screen.svelte +0 -69
- package/src/select.svelte +0 -122
- package/src/table.svelte +0 -69
- package/src/tabs.svelte +0 -78
- package/src/titlebar.svelte +0 -69
- package/src/toaster.svelte +0 -42
- package/src/toggle.svelte +0 -94
- package/src/tooltip.svelte +0 -45
- package/src/vars.mjs +0 -61
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Chris Morgan
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Chris Morgan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@axel669/zephyr",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "src/index.mjs",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
-
"demo": "rollup -c test/rollup.config.mjs"
|
|
10
|
-
},
|
|
11
|
-
"keywords": [],
|
|
12
|
-
"author": "",
|
|
13
|
-
"license": "MIT",
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"@axel669/windstorm": "0.
|
|
16
|
-
"@labyrinthos/asuid": "^0.2.0"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"@axel669/
|
|
21
|
-
"@
|
|
22
|
-
"@rollup/plugin-
|
|
23
|
-
"
|
|
24
|
-
"rollup": "^3.20.2",
|
|
25
|
-
"rollup-plugin-svelte": "^7.1.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@axel669/zephyr",
|
|
3
|
+
"version": "0.2.0-beta.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "src/index.mjs",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"demo": "rollup -c test/rollup.config.mjs"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [],
|
|
12
|
+
"author": "",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@axel669/windstorm": "0.2.3",
|
|
16
|
+
"@labyrinthos/asuid": "^0.2.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@axel669/ipsen": "0.4.0-beta.3",
|
|
20
|
+
"@axel669/rollup-html-input": "^0.1.2",
|
|
21
|
+
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
22
|
+
"@rollup/plugin-terser": "^0.4.0",
|
|
23
|
+
"prism-svelte": "^0.5.0",
|
|
24
|
+
"rollup": "^3.20.2",
|
|
25
|
+
"rollup-plugin-svelte": "^7.1.6",
|
|
26
|
+
"svelte": "^4.2.7"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"src/"
|
|
30
|
+
],
|
|
31
|
+
"imports": {
|
|
32
|
+
"#lib": "./src/index.mjs"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,44 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
1
|
+
NOTE: add docs for dumbass svelte browser resolve bullshit
|
|
2
|
+
https://svelte.dev/docs/v4-migration-guide#browser-conditions-for-bundlers
|
|
3
|
+
- form controls?
|
|
4
|
+
|
|
5
|
+
# Zephyr
|
|
6
|
+
Zephyr is a svelte binding for the [Windstorm](https://windstorm.axel669.net)
|
|
7
|
+
library, with some additional parts to make it look nice in the markup.
|
|
8
|
+
|
|
9
|
+
[Docs Here](https://zephyr.axel669.net)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
Zephyr can be installed through npm (or the variants like yarn, pnpm, etc).
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @axel669/zephyr
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
Components can be imported individually from the library for tree-shaking, or
|
|
20
|
+
the entire lib can imported at once, but I dunno how big that bundle will be.
|
|
21
|
+
Components can also take any windstorm function as a prop, using the same rules
|
|
22
|
+
as the `wsx` action.
|
|
23
|
+
|
|
24
|
+
> Windstorm expects a theme to be defined on an ancestor of the html elements
|
|
25
|
+
> that use it, and Zephyr does not automatically set the theme because it can
|
|
26
|
+
> used anywhere in the page. This means the wsx action (or setting the ws-x
|
|
27
|
+
> attribute directly) will be needed for components to look right.
|
|
28
|
+
|
|
29
|
+
```svelte
|
|
30
|
+
<script>
|
|
31
|
+
// individual import for tree shaking
|
|
32
|
+
import { Button } from "@axel669/zephyr"
|
|
33
|
+
|
|
34
|
+
// bring the whole thing to keep it simple
|
|
35
|
+
import * as Wind from "@axel669/zephyr"
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<!-- the wsx action can be used to setup the ws-x needed for the body -->
|
|
39
|
+
<svelte:body use:wsx={{"$theme": theme, "$app": true}} />
|
|
40
|
+
|
|
41
|
+
<Button on:click={stuff}>
|
|
42
|
+
I'm a button!
|
|
43
|
+
</Button>
|
|
44
|
+
|
|
45
|
+
<Wind.Button on:click={stuff}>
|
|
46
|
+
I'm also button!
|
|
47
|
+
</Wind.Button>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Svelte Config
|
|
51
|
+
Zephyr does not output any css of its own, so no configuration is required to
|
|
52
|
+
make it styled as expected. For people using Svelte 4+ you will need to make
|
|
53
|
+
sure your bundler has the browser conditions set as some components do use
|
|
54
|
+
lifecycle functions that will not be bundled without the setting.
|
|
55
|
+
[Details](https://svelte.dev/docs/v4-migration-guide#browser-conditions-for-bundlers)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script context="module">
|
|
2
|
+
const sortIcons = {
|
|
3
|
+
"asc": "arrow-narrow-up",
|
|
4
|
+
"desc": "arrow-narrow-down",
|
|
5
|
+
}
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<script>
|
|
9
|
+
import { getContext } from "svelte"
|
|
10
|
+
|
|
11
|
+
import Button from "../../control/button.svelte"
|
|
12
|
+
import Grid from "../../layout/grid.svelte"
|
|
13
|
+
import Icon from "../../info/icon.svelte"
|
|
14
|
+
|
|
15
|
+
import wsx from "../../wsx.mjs"
|
|
16
|
+
import { dtContext } from "../data-table.svelte"
|
|
17
|
+
|
|
18
|
+
export let sort = null
|
|
19
|
+
export let filter = null
|
|
20
|
+
|
|
21
|
+
const context = getContext(dtContext)
|
|
22
|
+
|
|
23
|
+
const setSort = () => $context.updateSort(sort)
|
|
24
|
+
|
|
25
|
+
let value = ""
|
|
26
|
+
$: $context.updateFilter(filter, value)
|
|
27
|
+
|
|
28
|
+
$: wind = {
|
|
29
|
+
...$$restProps,
|
|
30
|
+
p: "0px",
|
|
31
|
+
sel: "none"
|
|
32
|
+
}
|
|
33
|
+
$: console.log($context.sorting)
|
|
34
|
+
$: sortIcon =
|
|
35
|
+
($context.sorting.base === sort)
|
|
36
|
+
? sortIcons[$context.sorting.direction]
|
|
37
|
+
: "arrows-up-down"
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<th use:wsx={wind} style="vertical-align: top;">
|
|
41
|
+
<Grid rows="40px min-content" p="0px" gap="0px">
|
|
42
|
+
{#if sort === null}
|
|
43
|
+
<div ws-x="flex fl.cross[center] fl.main[center]">
|
|
44
|
+
<slot />
|
|
45
|
+
</div>
|
|
46
|
+
{:else}
|
|
47
|
+
<Button compact r="0px" color="primary" fill={$context.fillHeader}
|
|
48
|
+
t.wt="inherit" on:click={setSort}>
|
|
49
|
+
<slot />
|
|
50
|
+
<Icon name={sortIcon} m.l="4px" t.sz="16px" />
|
|
51
|
+
</Button>
|
|
52
|
+
{/if}
|
|
53
|
+
{#if filter !== null}
|
|
54
|
+
<Grid gap="0px" p="0px" cols="min-content 1fr">
|
|
55
|
+
<Icon name="filter" />
|
|
56
|
+
<input type="text" ws-x="w.min[20px] outline:focus[none]" bind:value />
|
|
57
|
+
</Grid>
|
|
58
|
+
{/if}
|
|
59
|
+
</Grid>
|
|
60
|
+
</th>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# DataTable
|
|
2
|
+
|
|
3
|
+
The DataTable is a more advanced way to show data on screen. Underneath is
|
|
4
|
+
a table element like the Table component, but the DataTable supports
|
|
5
|
+
more fine-grained control over how data is passed, how rows are displayed,
|
|
6
|
+
and pagination.
|
|
7
|
+
|
|
8
|
+
> If pagination is not needed, the DataTable may not be necessary as it will
|
|
9
|
+
> only be shortcutting data formatting at that point.
|
|
10
|
+
|
|
11
|
+
## Props
|
|
12
|
+
All [windstorm functions](https://axel669.github.io/lib.windstorm/#css-shorthands)
|
|
13
|
+
are supported.
|
|
14
|
+
|
|
15
|
+
- ### color
|
|
16
|
+
Sets `$color`
|
|
17
|
+
- ### cols `Array`
|
|
18
|
+
The columns that should be displayed. Should be in the format of
|
|
19
|
+
`{ label, width?, format?, prop? }`. If a format function is provided,
|
|
20
|
+
it is called on each cell to determine a cells value as
|
|
21
|
+
`format(rowItem)`, otherwise the property defined in prop will be used
|
|
22
|
+
as the cell value.
|
|
23
|
+
- ### data `Array`
|
|
24
|
+
The data to display. Each item in the array can be in either the same
|
|
25
|
+
format as the Table, or any kind of object if column format functions
|
|
26
|
+
are used.
|
|
27
|
+
- ### cellWSX `function`
|
|
28
|
+
If given, this function will be called for each cell, and should return
|
|
29
|
+
an object that will be passed to the `wsx` action for each <td>
|
|
30
|
+
generated. The function is passed `(rowvalue, rowNum, col)`.
|
|
31
|
+
- ### rowWSX `function`
|
|
32
|
+
If given, this function will be called for each row, and should return
|
|
33
|
+
an object that will be passed to the `wsx` action for each <tr>
|
|
34
|
+
generated. The function is passed `(rowValue, rowNum)`.
|
|
35
|
+
- ### page
|
|
36
|
+
The current page of data being viewed. Can be bound, or set to control
|
|
37
|
+
which page is displayed
|
|
38
|
+
- ### pageSize
|
|
39
|
+
The number of items to show on each page. Default is 10
|
|
40
|
+
- ### rowHeight
|
|
41
|
+
The height of each row. Can be set individually through rowWSX, but
|
|
42
|
+
that may lead to a degraded user experience if the rows change size
|
|
43
|
+
while paging through the data
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
```js
|
|
47
|
+
let page
|
|
48
|
+
const cols = [
|
|
49
|
+
{ label: "N", prop: "a" },
|
|
50
|
+
{ label: "Squared", prop: "b" },
|
|
51
|
+
{ label: "Cubed", format: row => `^3 = ${row.c}` },
|
|
52
|
+
]
|
|
53
|
+
const data = [
|
|
54
|
+
{ a: 1, b: 1 ** 2, c: 1 ** 3 },
|
|
55
|
+
{ a: 2, b: 2 ** 2, c: 2 ** 3 },
|
|
56
|
+
{ a: 3, b: 3 ** 2, c: 3 ** 3 },
|
|
57
|
+
{ a: 4, b: 4 ** 2, c: 4 ** 3 },
|
|
58
|
+
{ a: 5, b: 5 ** 2, c: 5 ** 3 },
|
|
59
|
+
{ a: 6, b: 6 ** 2, c: 6 ** 3 },
|
|
60
|
+
{ a: 7, b: 7 ** 2, c: 7 ** 3 },
|
|
61
|
+
{ a: 8, b: 8 ** 2, c: 8 ** 3 },
|
|
62
|
+
{ a: 9, b: 9 ** 2, c: 9 ** 3 },
|
|
63
|
+
{ a: 10, b: 10 ** 2, c: 10 ** 3 },
|
|
64
|
+
{ a: 11, b: 11 ** 2, c: 11 ** 3 },
|
|
65
|
+
{ a: 12, b: 12 ** 2, c: 12 ** 3 },
|
|
66
|
+
{ a: 13, b: 13 ** 2, c: 13 ** 3 },
|
|
67
|
+
]
|
|
68
|
+
```
|
|
69
|
+
```svelte
|
|
70
|
+
<DataTable {cols} {data} color="warning" pageSize={3} bind:page />
|
|
71
|
+
```
|
|
@@ -1,150 +1,136 @@
|
|
|
1
|
-
<
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
]
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
<
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
</tbody>
|
|
138
|
-
</table>
|
|
139
|
-
<Grid slot="footer" gr-col="min-content min-content min-content 1fr">
|
|
140
|
-
<Button on:click={prev}>
|
|
141
|
-
<Icon name="arrow-big-left" />
|
|
142
|
-
</Button>
|
|
143
|
-
<Button on:click={next}>
|
|
144
|
-
<Icon name="arrow-big-right" />
|
|
145
|
-
</Button>
|
|
146
|
-
<Text adorn t-ws="nowrap">
|
|
147
|
-
Page {page + 1} / {pageCount}
|
|
148
|
-
</Text>
|
|
149
|
-
</Grid>
|
|
150
|
-
</Paper>
|
|
1
|
+
<svelte:options immutable />
|
|
2
|
+
|
|
3
|
+
<script context="module">
|
|
4
|
+
// find the first filter in the list that returns false
|
|
5
|
+
const applyFilters = (data, filters) => data.filter(
|
|
6
|
+
(row) => {
|
|
7
|
+
for (const [filter, value] of filters) {
|
|
8
|
+
if (filter(row, value) === false) {
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return true
|
|
13
|
+
}
|
|
14
|
+
)
|
|
15
|
+
const noSort = {
|
|
16
|
+
direction: null,
|
|
17
|
+
func: (a, b) => 0,
|
|
18
|
+
base: null,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const dtContext = Symbol("table key")
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<script>
|
|
25
|
+
import { createEventDispatcher, setContext } from "svelte"
|
|
26
|
+
import { writable } from "svelte/store"
|
|
27
|
+
|
|
28
|
+
import Button from "../control/button.svelte"
|
|
29
|
+
import Icon from "../info/icon.svelte"
|
|
30
|
+
import Paper from "../layout/paper.svelte"
|
|
31
|
+
import Table from "../data-display/table.svelte"
|
|
32
|
+
import Text from "../text.svelte"
|
|
33
|
+
|
|
34
|
+
import Grid from "../layout/grid.svelte"
|
|
35
|
+
|
|
36
|
+
import wsx from "../wsx.mjs"
|
|
37
|
+
import { handler$, eventHandler$ } from "../handler$.mjs"
|
|
38
|
+
|
|
39
|
+
export let color = false
|
|
40
|
+
export let fillHeader = true
|
|
41
|
+
export let data = []
|
|
42
|
+
export let pageSize = 10
|
|
43
|
+
export let page = 0
|
|
44
|
+
export let rowHeight = "40px"
|
|
45
|
+
|
|
46
|
+
$: rows = Array.from(
|
|
47
|
+
{ length: pageSize },
|
|
48
|
+
(_, i) => filteredData[page * pageSize + i]
|
|
49
|
+
)
|
|
50
|
+
$: rowCount = filteredData.length
|
|
51
|
+
$: pageCount = Math.ceil(rowCount / pageSize)
|
|
52
|
+
$: maxPage = Math.max(pageCount - 1, 0)
|
|
53
|
+
|
|
54
|
+
let sorting = noSort
|
|
55
|
+
let filters = new Map()
|
|
56
|
+
let filterFunctions = []
|
|
57
|
+
|
|
58
|
+
$: filteredData =
|
|
59
|
+
applyFilters(data, filterFunctions)
|
|
60
|
+
.sort(sorting.func)
|
|
61
|
+
|
|
62
|
+
const prev = () => page = Math.max(0, page - 1)
|
|
63
|
+
const next = () => page = Math.min(maxPage, page + 1)
|
|
64
|
+
|
|
65
|
+
const updateSort = (func) => {
|
|
66
|
+
if (sorting.base === func) {
|
|
67
|
+
if (sorting.direction === "desc") {
|
|
68
|
+
sorting = noSort
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
sorting = {
|
|
72
|
+
func: (a, b) => -func(a, b),
|
|
73
|
+
base: func,
|
|
74
|
+
direction: "desc"
|
|
75
|
+
}
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
sorting = {
|
|
79
|
+
func,
|
|
80
|
+
base: func,
|
|
81
|
+
direction: "asc",
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const updateFilter = (func, value) => {
|
|
85
|
+
if (func === null) {
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
filters.set(func, value)
|
|
89
|
+
filterFunctions = [
|
|
90
|
+
...filters.entries()
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const context = writable({})
|
|
95
|
+
$: $context = {
|
|
96
|
+
updateSort,
|
|
97
|
+
fillHeader,
|
|
98
|
+
sorting,
|
|
99
|
+
updateFilter,
|
|
100
|
+
}
|
|
101
|
+
setContext(dtContext, context)
|
|
102
|
+
|
|
103
|
+
const fire = createEventDispatcher()
|
|
104
|
+
const pass = handler$(
|
|
105
|
+
(row) => fire("row-click", row)
|
|
106
|
+
)
|
|
107
|
+
</script>
|
|
108
|
+
|
|
109
|
+
<Paper card {color} l-fl.cross="stretch" l-p="0px">
|
|
110
|
+
<Table data={rows} {color} {fillHeader} {...$$restProps}>
|
|
111
|
+
<tr ws-x="h.min[{rowHeight}]" slot="header">
|
|
112
|
+
<slot name="header">
|
|
113
|
+
<th>No Header Defined</th>
|
|
114
|
+
</slot>
|
|
115
|
+
</tr>
|
|
116
|
+
<tr ws-x="h[{rowHeight}]" slot="row" let:row>
|
|
117
|
+
<slot name="row" {row}>
|
|
118
|
+
<th>No Row Defined</th>
|
|
119
|
+
</slot>
|
|
120
|
+
</tr>
|
|
121
|
+
<tr ws-x="h[{rowHeight}]" slot="empty-row" />
|
|
122
|
+
</Table>
|
|
123
|
+
<Grid slot="footer" gr.cols="min-content min-content min-content 1fr">
|
|
124
|
+
{#if pageCount > 0}
|
|
125
|
+
<Button on:click={prev} disabled={page === 0}>
|
|
126
|
+
<Icon name="arrow-big-left" />
|
|
127
|
+
</Button>
|
|
128
|
+
<Button on:click={next} disabled={page === maxPage}>
|
|
129
|
+
<Icon name="arrow-big-right" />
|
|
130
|
+
</Button>
|
|
131
|
+
<Text adorn t.ws="nowrap">
|
|
132
|
+
Page {page + 1} / {pageCount}
|
|
133
|
+
</Text>
|
|
134
|
+
{/if}
|
|
135
|
+
</Grid>
|
|
136
|
+
</Paper>
|