vue-slim-tables 0.3.1 → 0.3.4
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/README.md +20 -19
- package/dist/style.css +1 -1
- package/dist/types/main.d.ts +4 -0
- package/dist/types/ts/components/loading_row.vue.d.ts +12 -0
- package/dist/types/ts/components/slim_table.vue.d.ts +127 -0
- package/dist/types/ts/types.d.ts +53 -0
- package/dist/types/ts/use/filterable.d.ts +28 -0
- package/dist/vst.es.js +176 -239
- package/dist/vst.es.js.map +1 -1
- package/dist/vst.umd.js +1 -1
- package/dist/vst.umd.js.map +1 -1
- package/package.json +22 -21
- package/dist/types/components/loading_row.vue.d.ts +0 -14
- package/dist/types/components/table.vue.d.ts +0 -83
- package/dist/types/helpers/to_query_string.d.ts +0 -2
- package/dist/types/index.d.ts +0 -2
- package/dist/types/use/filterable.d.ts +0 -23
package/README.md
CHANGED
|
@@ -9,19 +9,19 @@ npm install vue-slim-tables
|
|
|
9
9
|
|
|
10
10
|
```html
|
|
11
11
|
<template>
|
|
12
|
-
|
|
12
|
+
<VueSlimTables :columns="columns" :source="asyncSource" />
|
|
13
13
|
</template>
|
|
14
14
|
|
|
15
|
-
<script>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
<script setup>
|
|
16
|
+
const columns = [
|
|
17
|
+
{ key: 'id', title: 'ID' },
|
|
18
|
+
{ key: 'name', title: 'Name' },
|
|
19
|
+
{ key: 'phone', title: 'Phone' }
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
const asyncSource = (params) => {
|
|
23
|
+
return fetch('...', params).then((res) => res.json())
|
|
24
|
+
}
|
|
25
25
|
</script>
|
|
26
26
|
```
|
|
27
27
|
|
|
@@ -29,24 +29,25 @@ npm install vue-slim-tables
|
|
|
29
29
|
| Prop | Type | Required | Description |
|
|
30
30
|
| - | - | - | - |
|
|
31
31
|
| columns | Array | true | Array of column objects described below |
|
|
32
|
-
| source |
|
|
33
|
-
| perPage | Number | false | Number or rows to display |
|
|
32
|
+
| source | Function | true | async load |
|
|
33
|
+
| perPage | Number | false | Number or rows to display. By default 25 will be used |
|
|
34
34
|
|
|
35
35
|
#### Column object
|
|
36
36
|
| Key | Type | Required | Description |
|
|
37
37
|
| - | - | - | - |
|
|
38
38
|
| key | String | true | `Uniq` key that used for ordering and slots |
|
|
39
|
-
| title | String | true | Displayed in thead |
|
|
39
|
+
| title | String | true | Displayed in thead cell |
|
|
40
40
|
| orderable | Boolean | false | Ordering by column `key` |
|
|
41
41
|
|
|
42
42
|
### Slots
|
|
43
43
|
| Slot | Props | Description |
|
|
44
44
|
| - | - | - |
|
|
45
|
-
| #
|
|
46
|
-
| #
|
|
45
|
+
| #thead:before | - | Add a row before main |
|
|
46
|
+
| #thead | { columns, orders } | Rewrite the entire thead row |
|
|
47
|
+
| #thead:after | - | Add a row after main |
|
|
48
|
+
| #thead:${column.key} | { column } | Rewrite thead cell with custom html |
|
|
49
|
+
| #row | { row, index, columns } | Rewrite the entire tbody row |
|
|
47
50
|
| #row:empty | - | Rewrite empty table row markup |
|
|
48
51
|
| #row:loading | - | Rewrite loading table rows markup |
|
|
49
|
-
| #cell:${column.key} | { row, index, column, value } | Rewrite cell with custom html |
|
|
52
|
+
| #cell:${column.key} | { row, index, column, value } | Rewrite tbody cell with custom html |
|
|
50
53
|
| #pagination | { page, rows } | Rewrite pagination with your own implementation |
|
|
51
|
-
| #thead:before | { columns } | Render row before base header |
|
|
52
|
-
| #thead:after | { columns } | Render row after base header |
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@charset "UTF-8";@keyframes moving-gradient{0%{background-position:-250px 0}to{background-position:250px 0}}.vst-th{
|
|
1
|
+
@charset "UTF-8";@keyframes moving-gradient{0%{background-position:-250px 0}to{background-position:250px 0}}.vst{--color-white: hsl(0, 0%, 100%);--color-light-grey: hsl(0, 0%, 90%);--color-grey: hsl(0, 0%, 75%);--color-dark-grey: hsl(0, 0%, 50%);--color-blue: hsl(211, 100%, 35%);--color-light-blue: hsl(211, 100%, 50%);width:100%;max-width:100%;margin-bottom:1rem;background-color:transparent;border-collapse:separate;border-spacing:0}.vst th,.vst td{border-top:1px solid var(--color-light-grey);padding:1rem;vertical-align:top}.vst thead th{vertical-align:bottom}.vst-orderable div{display:flex;justify-content:space-between;align-items:center}.vst-orderable div:hover{cursor:pointer}.vst-orderable div:hover .vst-orderable-toggle{color:var(--color-dark-grey)}.vst-orderable div .vst-orderable-toggle{font-size:1.25rem;font-style:normal;color:var(--color-grey)}.vst-orderable div .vst-orderable-toggle:after{content:" ↔";display:inline-block;transform:rotate(-90deg)}.vst-orderable div .vst-orderable-toggle.desc:after{color:var(--color-dark-grey);content:" ↑";transform:rotate(0)}.vst-orderable div .vst-orderable-toggle.asc:after{color:var(--color-dark-grey);content:" ↓";transform:rotate(0)}.vst-loading-row div{height:1.125rem;background:linear-gradient(to right,var(--color-light-grey) 20%,var(--color-white) 50%,var(--color-light-grey) 80%);background-size:500px 1.125rem;animation-name:moving-gradient;animation-duration:1s;animation-iteration-count:infinite;animation-timing-function:ease;animation-fill-mode:forwards}.vst tr td.vst-loading-row-1 div{animation-delay:-1s}.vst tr td.vst-loading-row-2 div{animation-delay:-.9s}.vst tr td.vst-loading-row-3 div{animation-delay:-.8s}.vst tr td.vst-loading-row-4 div{animation-delay:-.7s}.vst tr td.vst-loading-row-5 div{animation-delay:-.6s}.vst tr td.vst-loading-row-6 div{animation-delay:-.5s}.vst tr td.vst-loading-row-7 div{animation-delay:-.4s}.vst tr td.vst-loading-row-8 div{animation-delay:-.3s}.vst tr td.vst-loading-row-9 div{animation-delay:-.2s}.vst tr td.vst-loading-row-10 div{animation-delay:-.1s}.vst-pagination{display:flex;padding-left:0;list-style:none;border-radius:.25rem}.vst-pagination a{font-size:1.25rem;position:relative;display:block;padding:.5rem .75rem;margin-right:-1px;line-height:1.25;color:var(--color-light-blue);background-color:var(--color-white);border:1px solid var(--color-light-grey)}.vst-pagination a:hover{z-index:2;text-decoration:none;color:var(--color-blue);background-color:var(--color-light-grey);border-color:var(--color-light-grey)}.vst-page-item.disabled .vst-page-link{pointer-events:none;color:var(--color-dark-grey);cursor:auto;background-color:var(--color-white)}.vst-page-item .vst-page-link{cursor:pointer}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { TableColumn, TableOrders, TableFetchParams, TableRow, TableFilters, TableProps } from './ts/types';
|
|
2
|
+
import VueSlimTable from './ts/components/slim_table.vue';
|
|
3
|
+
export default VueSlimTable;
|
|
4
|
+
export { TableColumn, TableOrders, TableFetchParams, TableRow, TableFilters, TableProps };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{
|
|
2
|
+
columnsLength: {
|
|
3
|
+
type: NumberConstructor;
|
|
4
|
+
required: true;
|
|
5
|
+
};
|
|
6
|
+
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
7
|
+
columnsLength: {
|
|
8
|
+
type: NumberConstructor;
|
|
9
|
+
required: true;
|
|
10
|
+
};
|
|
11
|
+
}>>, {}, {}>;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { TableOrders, TableRow, TableProps } from '../../ts/types';
|
|
2
|
+
declare const _default: <TRow extends TableRow>(__VLS_props: TableProps<TRow> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, __VLS_ctx?: Pick<{
|
|
3
|
+
props: TableProps<TRow>;
|
|
4
|
+
expose(exposed: {
|
|
5
|
+
refetch: () => void;
|
|
6
|
+
reload: () => void;
|
|
7
|
+
rows: {
|
|
8
|
+
value: TRow[];
|
|
9
|
+
};
|
|
10
|
+
}): void;
|
|
11
|
+
attrs: any;
|
|
12
|
+
slots: Partial<{
|
|
13
|
+
[key: `thead:${string}`]: (_props: {
|
|
14
|
+
column: import('../../ts/types').TableColumn;
|
|
15
|
+
orders: TableOrders;
|
|
16
|
+
}) => any;
|
|
17
|
+
[key: `cell:${string}`]: (_props: {
|
|
18
|
+
row: TRow;
|
|
19
|
+
index: number;
|
|
20
|
+
column: import('../../ts/types').TableColumn;
|
|
21
|
+
value: unknown;
|
|
22
|
+
}) => any;
|
|
23
|
+
'thead:before': () => any;
|
|
24
|
+
thead: (_props: {
|
|
25
|
+
columns: import('../../ts/types').TableColumn[];
|
|
26
|
+
orders: TableOrders;
|
|
27
|
+
}) => any;
|
|
28
|
+
'thead:after': () => any;
|
|
29
|
+
'row:loading': () => any;
|
|
30
|
+
'row:empty': () => any;
|
|
31
|
+
row: (_props: {
|
|
32
|
+
row: TRow;
|
|
33
|
+
index: number;
|
|
34
|
+
columns: import('../../ts/types').TableColumn[];
|
|
35
|
+
}) => any;
|
|
36
|
+
pagination: (_props: {
|
|
37
|
+
page: number;
|
|
38
|
+
rows: TRow[];
|
|
39
|
+
}) => any;
|
|
40
|
+
}>;
|
|
41
|
+
emit: any;
|
|
42
|
+
}, "attrs" | "emit" | "slots"> | undefined, __VLS_setup?: Promise<{
|
|
43
|
+
props: TableProps<TRow>;
|
|
44
|
+
expose(exposed: {
|
|
45
|
+
refetch: () => void;
|
|
46
|
+
reload: () => void;
|
|
47
|
+
rows: {
|
|
48
|
+
value: TRow[];
|
|
49
|
+
};
|
|
50
|
+
}): void;
|
|
51
|
+
attrs: any;
|
|
52
|
+
slots: Partial<{
|
|
53
|
+
[key: `thead:${string}`]: (_props: {
|
|
54
|
+
column: import('../../ts/types').TableColumn;
|
|
55
|
+
orders: TableOrders;
|
|
56
|
+
}) => any;
|
|
57
|
+
[key: `cell:${string}`]: (_props: {
|
|
58
|
+
row: TRow;
|
|
59
|
+
index: number;
|
|
60
|
+
column: import('../../ts/types').TableColumn;
|
|
61
|
+
value: unknown;
|
|
62
|
+
}) => any;
|
|
63
|
+
'thead:before': () => any;
|
|
64
|
+
thead: (_props: {
|
|
65
|
+
columns: import('../../ts/types').TableColumn[];
|
|
66
|
+
orders: TableOrders;
|
|
67
|
+
}) => any;
|
|
68
|
+
'thead:after': () => any;
|
|
69
|
+
'row:loading': () => any;
|
|
70
|
+
'row:empty': () => any;
|
|
71
|
+
row: (_props: {
|
|
72
|
+
row: TRow;
|
|
73
|
+
index: number;
|
|
74
|
+
columns: import('../../ts/types').TableColumn[];
|
|
75
|
+
}) => any;
|
|
76
|
+
pagination: (_props: {
|
|
77
|
+
page: number;
|
|
78
|
+
rows: TRow[];
|
|
79
|
+
}) => any;
|
|
80
|
+
}>;
|
|
81
|
+
emit: any;
|
|
82
|
+
}>) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
83
|
+
[key: string]: any;
|
|
84
|
+
}> & {
|
|
85
|
+
__ctx?: {
|
|
86
|
+
props: TableProps<TRow>;
|
|
87
|
+
expose(exposed: {
|
|
88
|
+
refetch: () => void;
|
|
89
|
+
reload: () => void;
|
|
90
|
+
rows: {
|
|
91
|
+
value: TRow[];
|
|
92
|
+
};
|
|
93
|
+
}): void;
|
|
94
|
+
attrs: any;
|
|
95
|
+
slots: Partial<{
|
|
96
|
+
[key: `thead:${string}`]: (_props: {
|
|
97
|
+
column: import('../../ts/types').TableColumn;
|
|
98
|
+
orders: TableOrders;
|
|
99
|
+
}) => any;
|
|
100
|
+
[key: `cell:${string}`]: (_props: {
|
|
101
|
+
row: TRow;
|
|
102
|
+
index: number;
|
|
103
|
+
column: import('../../ts/types').TableColumn;
|
|
104
|
+
value: unknown;
|
|
105
|
+
}) => any;
|
|
106
|
+
'thead:before': () => any;
|
|
107
|
+
thead: (_props: {
|
|
108
|
+
columns: import('../../ts/types').TableColumn[];
|
|
109
|
+
orders: TableOrders;
|
|
110
|
+
}) => any;
|
|
111
|
+
'thead:after': () => any;
|
|
112
|
+
'row:loading': () => any;
|
|
113
|
+
'row:empty': () => any;
|
|
114
|
+
row: (_props: {
|
|
115
|
+
row: TRow;
|
|
116
|
+
index: number;
|
|
117
|
+
columns: import('../../ts/types').TableColumn[];
|
|
118
|
+
}) => any;
|
|
119
|
+
pagination: (_props: {
|
|
120
|
+
page: number;
|
|
121
|
+
rows: TRow[];
|
|
122
|
+
}) => any;
|
|
123
|
+
}>;
|
|
124
|
+
emit: any;
|
|
125
|
+
} | undefined;
|
|
126
|
+
};
|
|
127
|
+
export default _default;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ShallowRef } from 'vue';
|
|
2
|
+
export type TableColumn = {
|
|
3
|
+
key: string;
|
|
4
|
+
title: string;
|
|
5
|
+
orderable?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type TableOrders = {
|
|
8
|
+
[key: string]: 'asc' | 'desc';
|
|
9
|
+
};
|
|
10
|
+
export type TableFilters = {
|
|
11
|
+
per_page: number;
|
|
12
|
+
orders: ShallowRef<TableOrders>;
|
|
13
|
+
};
|
|
14
|
+
export type TableFetchParams = {
|
|
15
|
+
page: number;
|
|
16
|
+
} & TableFilters;
|
|
17
|
+
export type TableRow = {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
};
|
|
20
|
+
export type TableProps<T> = {
|
|
21
|
+
columns: Array<TableColumn>;
|
|
22
|
+
perPage: number;
|
|
23
|
+
source: ((_: TableFetchParams) => Promise<T[]> | T[]);
|
|
24
|
+
};
|
|
25
|
+
export type TableSlots<T> = Partial<{
|
|
26
|
+
'thead:before': () => any;
|
|
27
|
+
thead: (_props: {
|
|
28
|
+
columns: TableColumn[];
|
|
29
|
+
orders: TableOrders;
|
|
30
|
+
}) => any;
|
|
31
|
+
'thead:after': () => any;
|
|
32
|
+
[key: `thead:${string}`]: (_props: {
|
|
33
|
+
column: TableColumn;
|
|
34
|
+
orders: TableOrders;
|
|
35
|
+
}) => any;
|
|
36
|
+
'row:loading': () => any;
|
|
37
|
+
'row:empty': () => any;
|
|
38
|
+
row: (_props: {
|
|
39
|
+
row: T;
|
|
40
|
+
index: number;
|
|
41
|
+
columns: TableColumn[];
|
|
42
|
+
}) => any;
|
|
43
|
+
[key: `cell:${string}`]: (_props: {
|
|
44
|
+
row: T;
|
|
45
|
+
index: number;
|
|
46
|
+
column: TableColumn;
|
|
47
|
+
value: unknown;
|
|
48
|
+
}) => any;
|
|
49
|
+
pagination: (_props: {
|
|
50
|
+
page: number;
|
|
51
|
+
rows: T[];
|
|
52
|
+
}) => any;
|
|
53
|
+
}>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type UseFiltetableArgs<T, S> = {
|
|
2
|
+
initialFilters: T;
|
|
3
|
+
loadItems: (_params: T & {
|
|
4
|
+
page: number;
|
|
5
|
+
}) => Promise<S[]>;
|
|
6
|
+
};
|
|
7
|
+
declare const SYNC_STATES: {
|
|
8
|
+
readonly INITIAL: "initial";
|
|
9
|
+
readonly SYNCING: "syncing";
|
|
10
|
+
readonly SYNCED: "synced";
|
|
11
|
+
readonly FAILED: "failed";
|
|
12
|
+
};
|
|
13
|
+
type SynsState = (typeof SYNC_STATES)[keyof typeof SYNC_STATES];
|
|
14
|
+
declare const useFilterable: <TFilters, TItem>({ initialFilters, loadItems }: UseFiltetableArgs<TFilters, TItem>) => {
|
|
15
|
+
page: import("vue").Ref<number>;
|
|
16
|
+
items: {
|
|
17
|
+
value: TItem[];
|
|
18
|
+
};
|
|
19
|
+
syncState: import("vue").Ref<SynsState>;
|
|
20
|
+
nextPage: () => void;
|
|
21
|
+
prevPage: () => void;
|
|
22
|
+
isSyncing: import("vue").ComputedRef<boolean>;
|
|
23
|
+
isSynced: import("vue").ComputedRef<boolean>;
|
|
24
|
+
isFailed: import("vue").ComputedRef<boolean>;
|
|
25
|
+
reload: () => void;
|
|
26
|
+
refetch: () => void;
|
|
27
|
+
};
|
|
28
|
+
export default useFilterable;
|
package/dist/vst.es.js
CHANGED
|
@@ -1,271 +1,208 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
import { defineComponent, openBlock, createElementBlock, createElementVNode, normalizeClass, computed, ref, reactive, isReactive, watch, shallowRef, renderSlot, Fragment, renderList, createTextVNode, toDisplayString, unref, createCommentVNode, createBlock, withModifiers } from "vue";
|
|
18
|
-
var index = "";
|
|
19
|
-
const _hoisted_1$1 = ["colspan"];
|
|
20
|
-
const _hoisted_2$1 = /* @__PURE__ */ createElementVNode("div", null, null, -1);
|
|
21
|
-
const _hoisted_3$1 = [
|
|
22
|
-
_hoisted_2$1
|
|
23
|
-
];
|
|
24
|
-
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
1
|
+
import { defineComponent as Y, openBlock as n, createElementBlock as r, createElementVNode as a, normalizeClass as S, ref as _, reactive as D, computed as f, watch as B, shallowRef as G, renderSlot as u, Fragment as $, renderList as N, mergeProps as M, toHandlers as V, createTextVNode as C, toDisplayString as I, createCommentVNode as w, unref as s, createBlock as R, withModifiers as L } from "vue";
|
|
2
|
+
const q = ["colspan"], z = /* @__PURE__ */ a("div", null, null, -1), H = [
|
|
3
|
+
z
|
|
4
|
+
], O = /* @__PURE__ */ Y({
|
|
5
|
+
__name: "loading_row",
|
|
25
6
|
props: {
|
|
26
|
-
columnsLength: { type: Number, required:
|
|
7
|
+
columnsLength: { type: Number, required: !0 }
|
|
27
8
|
},
|
|
28
|
-
setup(
|
|
29
|
-
const
|
|
30
|
-
return (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
]);
|
|
37
|
-
};
|
|
9
|
+
setup(h) {
|
|
10
|
+
const y = Math.floor(Math.random() * 10) + 1;
|
|
11
|
+
return (i, l) => (n(), r("tr", null, [
|
|
12
|
+
a("td", {
|
|
13
|
+
colspan: h.columnsLength,
|
|
14
|
+
class: S(["vst-loading-row", `vst-loading-row-${y}`])
|
|
15
|
+
}, H, 10, q)
|
|
16
|
+
]));
|
|
38
17
|
}
|
|
39
|
-
})
|
|
40
|
-
const SYNC_STATES = {
|
|
18
|
+
}), p = {
|
|
41
19
|
INITIAL: "initial",
|
|
42
20
|
SYNCING: "syncing",
|
|
43
21
|
SYNCED: "synced",
|
|
44
22
|
FAILED: "failed"
|
|
45
|
-
}
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return loadItems(filters.value).then((res) => {
|
|
57
|
-
items.value = res;
|
|
58
|
-
syncState.value = SYNC_STATES.SYNCED;
|
|
59
|
-
}).catch(() => {
|
|
60
|
-
items.value = [];
|
|
61
|
-
syncState.value = SYNC_STATES.FAILED;
|
|
62
|
-
});
|
|
23
|
+
}, j = ({ initialFilters: h, loadItems: y }) => {
|
|
24
|
+
const i = _(1), l = D({ value: [] }), d = _(p.INITIAL), b = D({ value: h }), g = f(() => ({
|
|
25
|
+
page: i.value,
|
|
26
|
+
...b.value
|
|
27
|
+
})), c = async () => {
|
|
28
|
+
d.value = p.SYNCING;
|
|
29
|
+
try {
|
|
30
|
+
l.value = await y(g.value), d.value = p.SYNCED;
|
|
31
|
+
} catch {
|
|
32
|
+
l.value = [], d.value = p.FAILED;
|
|
33
|
+
}
|
|
63
34
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
items,
|
|
69
|
-
syncState,
|
|
35
|
+
return c(), B(g, c), {
|
|
36
|
+
page: i,
|
|
37
|
+
items: l,
|
|
38
|
+
syncState: d,
|
|
70
39
|
nextPage: () => {
|
|
71
|
-
|
|
40
|
+
i.value += 1;
|
|
72
41
|
},
|
|
73
42
|
prevPage: () => {
|
|
74
|
-
|
|
43
|
+
i.value -= 1;
|
|
75
44
|
},
|
|
76
|
-
isSyncing:
|
|
77
|
-
isSynced:
|
|
78
|
-
isFailed:
|
|
45
|
+
isSyncing: f(() => d.value === p.SYNCING),
|
|
46
|
+
isSynced: f(() => d.value === p.SYNCED),
|
|
47
|
+
isFailed: f(() => d.value === p.FAILED),
|
|
79
48
|
reload: () => {
|
|
80
|
-
|
|
49
|
+
c();
|
|
81
50
|
},
|
|
82
51
|
refetch: () => {
|
|
83
|
-
|
|
84
|
-
load();
|
|
85
|
-
} else {
|
|
86
|
-
page.value = 1;
|
|
87
|
-
}
|
|
52
|
+
i.value === 1 ? c() : i.value = 1;
|
|
88
53
|
}
|
|
89
54
|
};
|
|
90
|
-
}
|
|
91
|
-
const stringify = (obj, parentPrefix) => (outputArray, [key, val]) => {
|
|
92
|
-
if (val === null || val === void 0) {
|
|
93
|
-
return outputArray;
|
|
94
|
-
}
|
|
95
|
-
const encodedKey = encodeURIComponent(key);
|
|
96
|
-
const prefix = parentPrefix ? `${parentPrefix}[${encodedKey}]` : encodedKey;
|
|
97
|
-
if (["number", "string"].includes(typeof val)) {
|
|
98
|
-
outputArray.push(`${prefix}=${encodeURIComponent(val)}`);
|
|
99
|
-
return outputArray;
|
|
100
|
-
}
|
|
101
|
-
outputArray.push(Object.entries(val).reduce(stringify(val, prefix), []).join("&"));
|
|
102
|
-
return outputArray;
|
|
103
|
-
};
|
|
104
|
-
var toQueryString = (obj) => Object.entries(obj).reduce(stringify(), []).join("&");
|
|
105
|
-
const _hoisted_1 = { class: "vst" };
|
|
106
|
-
const _hoisted_2 = { key: 0 };
|
|
107
|
-
const _hoisted_3 = ["onClick"];
|
|
108
|
-
const _hoisted_4 = { key: 0 };
|
|
109
|
-
const _hoisted_5 = ["colspan"];
|
|
110
|
-
const _hoisted_6 = ["colspan"];
|
|
111
|
-
const _hoisted_7 = {
|
|
55
|
+
}, J = { class: "vst" }, K = { key: 0 }, Q = { key: 0 }, U = ["colspan"], W = ["colspan"], X = {
|
|
112
56
|
key: 0,
|
|
113
57
|
class: "vst-pagination mt-3"
|
|
114
|
-
}
|
|
115
|
-
|
|
58
|
+
}, x = /* @__PURE__ */ Y({
|
|
59
|
+
__name: "slim_table",
|
|
116
60
|
props: {
|
|
117
|
-
columns:
|
|
118
|
-
|
|
119
|
-
|
|
61
|
+
columns: {},
|
|
62
|
+
perPage: {},
|
|
63
|
+
source: { type: Function }
|
|
120
64
|
},
|
|
121
|
-
setup(
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const response = await fetch(`${props.source}?${toQueryString(params)}`);
|
|
128
|
-
data = await response.json();
|
|
129
|
-
} else {
|
|
130
|
-
data = await props.source(params);
|
|
65
|
+
setup(h, { expose: y }) {
|
|
66
|
+
const i = h, l = G({}), d = async (e) => {
|
|
67
|
+
let o = [];
|
|
68
|
+
try {
|
|
69
|
+
o = await i.source(e);
|
|
70
|
+
} catch {
|
|
131
71
|
}
|
|
132
|
-
return
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
prevPage,
|
|
148
|
-
nextPage,
|
|
149
|
-
reload,
|
|
150
|
-
refetch,
|
|
151
|
-
items: rows
|
|
152
|
-
} = useFilterable({
|
|
153
|
-
initialFilters: { per_page: props.perPage, orders },
|
|
154
|
-
loadItems: fetchData
|
|
155
|
-
});
|
|
156
|
-
expose({
|
|
157
|
-
refetch,
|
|
158
|
-
reload,
|
|
159
|
-
rows
|
|
72
|
+
return o;
|
|
73
|
+
}, b = (e, o) => {
|
|
74
|
+
e.preventDefault(), l.value[o] === "asc" ? l.value = { [o]: "desc" } : l.value[o] === "desc" ? l.value = {} : l.value = { [o]: "asc" };
|
|
75
|
+
}, {
|
|
76
|
+
page: g,
|
|
77
|
+
isSyncing: c,
|
|
78
|
+
isSynced: P,
|
|
79
|
+
prevPage: E,
|
|
80
|
+
nextPage: F,
|
|
81
|
+
reload: A,
|
|
82
|
+
refetch: T,
|
|
83
|
+
items: v
|
|
84
|
+
} = j({
|
|
85
|
+
initialFilters: { per_page: i.perPage, orders: l },
|
|
86
|
+
loadItems: d
|
|
160
87
|
});
|
|
161
|
-
return (
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
])) : renderSlot(_ctx.$slots, `head:${column.key}`, {
|
|
182
|
-
key: 1,
|
|
183
|
-
column
|
|
88
|
+
return y({
|
|
89
|
+
refetch: T,
|
|
90
|
+
reload: A,
|
|
91
|
+
rows: v
|
|
92
|
+
}), (e, o) => (n(), r("table", J, [
|
|
93
|
+
e.columns.length ? (n(), r("thead", K, [
|
|
94
|
+
u(e.$slots, "thead:before"),
|
|
95
|
+
u(e.$slots, "thead", {
|
|
96
|
+
columns: e.columns,
|
|
97
|
+
orders: l.value
|
|
98
|
+
}, () => [
|
|
99
|
+
a("tr", null, [
|
|
100
|
+
(n(!0), r($, null, N(e.columns, (t) => (n(), r("th", M({
|
|
101
|
+
key: t.key,
|
|
102
|
+
class: ["vst-th", { "vst-orderable": t.orderable }]
|
|
103
|
+
}, V(t.orderable ? { click: (m) => b(m, t.key) } : {}, !0)), [
|
|
104
|
+
t.orderable ? (n(), r("div", Q, [
|
|
105
|
+
u(e.$slots, `thead:${t.key}`, {
|
|
106
|
+
column: t,
|
|
107
|
+
orders: l.value
|
|
184
108
|
}, () => [
|
|
185
|
-
|
|
186
|
-
])
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}), 128))
|
|
200
|
-
]) : unref(isSynced) && unref(rows).value.length === 0 ? renderSlot(_ctx.$slots, "row:empty", { key: 1 }, () => [
|
|
201
|
-
createElementVNode("tr", null, [
|
|
202
|
-
createElementVNode("td", {
|
|
203
|
-
colspan: __props.columns.length
|
|
204
|
-
}, " No records found ", 8, _hoisted_5)
|
|
205
|
-
])
|
|
206
|
-
]) : unref(isSynced) && unref(rows).value.length ? (openBlock(true), createElementBlock(Fragment, { key: 2 }, renderList(unref(rows).value, (row, i) => {
|
|
207
|
-
return renderSlot(_ctx.$slots, "row", {
|
|
208
|
-
row,
|
|
209
|
-
index: i,
|
|
210
|
-
columns: __props.columns
|
|
211
|
-
}, () => [
|
|
212
|
-
(openBlock(), createElementBlock("tr", {
|
|
213
|
-
key: row["id"] || i
|
|
214
|
-
}, [
|
|
215
|
-
(openBlock(true), createElementBlock(Fragment, null, renderList(__props.columns, (column) => {
|
|
216
|
-
return openBlock(), createElementBlock("td", {
|
|
217
|
-
key: column.key
|
|
218
|
-
}, [
|
|
219
|
-
renderSlot(_ctx.$slots, `cell:${column.key}`, {
|
|
220
|
-
row,
|
|
221
|
-
value: row[column.key],
|
|
222
|
-
column,
|
|
223
|
-
index: i
|
|
224
|
-
}, () => [
|
|
225
|
-
createTextVNode(toDisplayString(row[column.key]), 1)
|
|
226
|
-
])
|
|
227
|
-
]);
|
|
228
|
-
}), 128))
|
|
229
|
-
]))
|
|
230
|
-
]);
|
|
231
|
-
}), 256)) : createCommentVNode("", true)
|
|
109
|
+
C(I(t.title), 1)
|
|
110
|
+
]),
|
|
111
|
+
a("i", {
|
|
112
|
+
class: S(["vst-orderable-toggle", l.value[t.key]])
|
|
113
|
+
}, null, 2)
|
|
114
|
+
])) : u(e.$slots, `thead:${t.key}`, {
|
|
115
|
+
key: 1,
|
|
116
|
+
column: t,
|
|
117
|
+
orders: l.value
|
|
118
|
+
}, () => [
|
|
119
|
+
C(I(t.title), 1)
|
|
120
|
+
])
|
|
121
|
+
], 16))), 128))
|
|
122
|
+
])
|
|
232
123
|
]),
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
124
|
+
u(e.$slots, "thead:after")
|
|
125
|
+
])) : w("", !0),
|
|
126
|
+
a("tbody", null, [
|
|
127
|
+
s(c) ? u(e.$slots, "row:loading", { key: 0 }, () => [
|
|
128
|
+
(n(!0), r($, null, N(e.perPage, (t) => (n(), R(O, {
|
|
129
|
+
key: `loadingRow${t}`,
|
|
130
|
+
"columns-length": e.columns.length
|
|
131
|
+
}, null, 8, ["columns-length"]))), 128))
|
|
132
|
+
]) : s(P) && s(v).value.length === 0 ? u(e.$slots, "row:empty", { key: 1 }, () => [
|
|
133
|
+
a("tr", null, [
|
|
134
|
+
a("td", {
|
|
135
|
+
colspan: e.columns.length
|
|
136
|
+
}, " No records found ", 8, U)
|
|
137
|
+
])
|
|
138
|
+
]) : s(P) && s(v).value.length ? (n(!0), r($, { key: 2 }, N(s(v).value, (t, m) => u(e.$slots, "row", {
|
|
139
|
+
row: t,
|
|
140
|
+
index: m,
|
|
141
|
+
columns: e.columns
|
|
142
|
+
}, () => [
|
|
143
|
+
(n(), r("tr", {
|
|
144
|
+
key: t.id || m
|
|
145
|
+
}, [
|
|
146
|
+
(n(!0), r($, null, N(e.columns, (k) => (n(), r("td", {
|
|
147
|
+
key: k.key
|
|
237
148
|
}, [
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
149
|
+
u(e.$slots, `cell:${k.key}`, {
|
|
150
|
+
row: t,
|
|
151
|
+
value: t[k.key],
|
|
152
|
+
column: k,
|
|
153
|
+
index: m
|
|
241
154
|
}, () => [
|
|
242
|
-
|
|
243
|
-
createElementVNode("li", {
|
|
244
|
-
class: normalizeClass(["vst-page-item", { disabled: unref(page) === 1 || unref(isSyncing) }])
|
|
245
|
-
}, [
|
|
246
|
-
createElementVNode("a", {
|
|
247
|
-
class: "vst-page-link",
|
|
248
|
-
onClick: _cache[0] || (_cache[0] = withModifiers((...args) => unref(prevPage) && unref(prevPage)(...args), ["prevent"]))
|
|
249
|
-
}, "\u2190")
|
|
250
|
-
], 2),
|
|
251
|
-
createElementVNode("li", {
|
|
252
|
-
class: normalizeClass(["vst-page-item", {
|
|
253
|
-
disabled: unref(rows).value.length < __props.perPage || unref(isSyncing)
|
|
254
|
-
}])
|
|
255
|
-
}, [
|
|
256
|
-
createElementVNode("a", {
|
|
257
|
-
class: "vst-page-link",
|
|
258
|
-
onClick: _cache[1] || (_cache[1] = withModifiers((...args) => unref(nextPage) && unref(nextPage)(...args), ["prevent"]))
|
|
259
|
-
}, "\u2192")
|
|
260
|
-
], 2)
|
|
261
|
-
])) : createCommentVNode("", true)
|
|
155
|
+
C(I(t[k.key]), 1)
|
|
262
156
|
])
|
|
263
|
-
],
|
|
264
|
-
])
|
|
157
|
+
]))), 128))
|
|
158
|
+
]))
|
|
159
|
+
])), 256)) : w("", !0)
|
|
160
|
+
]),
|
|
161
|
+
a("tfoot", null, [
|
|
162
|
+
a("tr", null, [
|
|
163
|
+
a("td", {
|
|
164
|
+
colspan: e.columns.length
|
|
165
|
+
}, [
|
|
166
|
+
u(e.$slots, "pagination", {
|
|
167
|
+
page: s(g),
|
|
168
|
+
rows: s(v).value
|
|
169
|
+
}, () => [
|
|
170
|
+
s(g) > 1 || s(v).value.length === e.perPage || s(c) ? (n(), r("ul", X, [
|
|
171
|
+
a("li", {
|
|
172
|
+
class: S(["vst-page-item", { disabled: s(g) === 1 || s(c) }])
|
|
173
|
+
}, [
|
|
174
|
+
a("a", {
|
|
175
|
+
class: "vst-page-link",
|
|
176
|
+
onClick: o[0] || (o[0] = L(
|
|
177
|
+
//@ts-ignore
|
|
178
|
+
(...t) => s(E) && s(E)(...t),
|
|
179
|
+
["prevent"]
|
|
180
|
+
))
|
|
181
|
+
}, "←")
|
|
182
|
+
], 2),
|
|
183
|
+
a("li", {
|
|
184
|
+
class: S(["vst-page-item", {
|
|
185
|
+
disabled: s(v).value.length < e.perPage || s(c)
|
|
186
|
+
}])
|
|
187
|
+
}, [
|
|
188
|
+
a("a", {
|
|
189
|
+
class: "vst-page-link",
|
|
190
|
+
onClick: o[1] || (o[1] = L(
|
|
191
|
+
//@ts-ignore
|
|
192
|
+
(...t) => s(F) && s(F)(...t),
|
|
193
|
+
["prevent"]
|
|
194
|
+
))
|
|
195
|
+
}, "→")
|
|
196
|
+
], 2)
|
|
197
|
+
])) : w("", !0)
|
|
198
|
+
])
|
|
199
|
+
], 8, W)
|
|
265
200
|
])
|
|
266
|
-
])
|
|
267
|
-
|
|
201
|
+
])
|
|
202
|
+
]));
|
|
268
203
|
}
|
|
269
204
|
});
|
|
270
|
-
export {
|
|
205
|
+
export {
|
|
206
|
+
x as default
|
|
207
|
+
};
|
|
271
208
|
//# sourceMappingURL=vst.es.js.map
|
package/dist/vst.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vst.es.js","sources":["../src/ts/components/loading_row.vue","../src/ts/use/filterable.ts","../src/ts/
|
|
1
|
+
{"version":3,"file":"vst.es.js","sources":["../src/ts/components/loading_row.vue","../src/ts/use/filterable.ts","../src/ts/components/slim_table.vue"],"sourcesContent":["<template>\n <tr>\n <td\n :colspan=\"columnsLength\"\n :class=\"['vst-loading-row', `vst-loading-row-${randNum}`]\">\n <div />\n </td>\n </tr>\n</template>\n\n<script lang=\"ts\" setup>\ndefineProps({\n columnsLength: { type: Number, required: true },\n})\n\nconst randNum = Math.floor(Math.random() * 10) + 1\n</script>\n","import {\n ref, computed, reactive, watch,\n} from 'vue'\n\ntype CombinedFilters<T> = T & {\n page: number\n}\n\ntype UseFiltetableArgs<T, S> = {\n initialFilters: T,\n loadItems: (_params: T & { page: number }) => Promise<S[]>\n}\n\nconst SYNC_STATES = {\n INITIAL: 'initial',\n SYNCING: 'syncing',\n SYNCED: 'synced',\n FAILED: 'failed',\n} as const\n\ntype SynsState = (typeof SYNC_STATES)[keyof typeof SYNC_STATES]\n\nconst useFilterable = <TFilters, TItem>({ initialFilters, loadItems }: UseFiltetableArgs<TFilters, TItem>) => {\n const page = ref(1)\n const items: { value: TItem[] } = reactive({ value: [] })\n const syncState = ref<SynsState>(SYNC_STATES.INITIAL)\n const filters = reactive({ value: initialFilters })\n\n const combinedFilters = computed<CombinedFilters<TFilters>>(() => ({\n page: page.value,\n ...filters.value as TFilters,\n }))\n\n const load = async () => {\n syncState.value = SYNC_STATES.SYNCING\n\n try {\n items.value = await loadItems(combinedFilters.value)\n syncState.value = SYNC_STATES.SYNCED\n } catch {\n items.value = []\n syncState.value = SYNC_STATES.FAILED\n }\n }\n load()\n\n watch(combinedFilters, load)\n\n return {\n page,\n items,\n syncState,\n nextPage: () => {\n page.value += 1\n },\n prevPage: () => {\n page.value -= 1\n },\n isSyncing: computed(() => syncState.value === SYNC_STATES.SYNCING),\n isSynced: computed(() => syncState.value === SYNC_STATES.SYNCED),\n isFailed: computed(() => syncState.value === SYNC_STATES.FAILED),\n reload: () => {\n load()\n },\n refetch: () => {\n if (page.value === 1) {\n load()\n } else {\n page.value = 1\n }\n },\n }\n}\n\nexport default useFilterable\n","<template>\n <table class=\"vst\">\n <thead v-if=\"columns.length\">\n <slot name=\"thead:before\" />\n <slot name=\"thead\" :columns=\"columns\" :orders=\"orders\">\n <tr>\n <th\n v-for=\"column in columns\"\n :key=\"column.key\"\n :class=\"['vst-th', { 'vst-orderable': column.orderable }]\"\n v-on=\"column.orderable ? { click: (event: Event) => onOrderClick(event, column.key) } : {}\">\n <div v-if=\"column.orderable\">\n <slot\n :name=\"`thead:${column.key}`\"\n :column=\"column\"\n :orders=\"orders\">\n {{ column.title }}\n </slot>\n\n <i :class=\"['vst-orderable-toggle', orders[column.key]]\" />\n </div>\n\n <slot\n v-else\n :name=\"`thead:${column.key}`\"\n :column=\"column\"\n :orders=\"orders\">\n {{ column.title }}\n </slot>\n </th>\n </tr>\n </slot>\n <slot name=\"thead:after\" />\n </thead>\n <tbody>\n <slot v-if=\"isSyncing\" name=\"row:loading\">\n <LoadingRow\n v-for=\"i in perPage\"\n :key=\"`loadingRow${i}`\"\n :columns-length=\"columns.length\" />\n </slot>\n\n <slot v-else-if=\"isSynced && rows.value.length === 0\" name=\"row:empty\">\n <tr>\n <td :colspan=\"columns.length\">\n No records found\n </td>\n </tr>\n </slot>\n\n <template v-else-if=\"isSynced && rows.value.length\">\n <slot\n v-for=\"(row, i) in rows.value\"\n name=\"row\"\n :row=\"row\"\n :index=\"i\"\n :columns=\"columns\">\n <tr :key=\"row['id'] || i\">\n <td\n v-for=\"column in columns\"\n :key=\"column.key\">\n <slot\n :name=\"`cell:${column.key}`\"\n :row=\"row\"\n :value=\"row[column.key]\"\n :column=\"column\"\n :index=\"i\">\n {{ row[column.key] }}\n </slot>\n </td>\n </tr>\n </slot>\n </template>\n </tbody>\n <tfoot>\n <tr>\n <td :colspan=\"columns.length\">\n <slot name=\"pagination\" :page=\"page\" :rows=\"rows.value\">\n <ul\n v-if=\"page > 1 || rows.value.length === perPage || isSyncing\"\n class=\"vst-pagination mt-3\">\n <li :class=\"['vst-page-item', { disabled: page === 1 || isSyncing }]\">\n <a class=\"vst-page-link\" @click.prevent=\"prevPage\">←</a>\n </li>\n\n <li\n :class=\"['vst-page-item', {\n disabled: rows.value.length < perPage || isSyncing\n }]\">\n <a class=\"vst-page-link\" @click.prevent=\"nextPage\">→</a>\n </li>\n </ul>\n </slot>\n </td>\n </tr>\n </tfoot>\n </table>\n</template>\n\n<script setup lang=\"ts\" generic=\"TRow extends TableRow\">\nimport { shallowRef } from 'vue'\nimport LoadingRow from './loading_row.vue'\n\nimport useFilterable from '../use/filterable'\n\nimport type {\n TableOrders, TableFetchParams, TableRow, TableFilters, TableProps, TableSlots,\n} from '@/ts/types'\n\nconst orders = shallowRef<TableOrders>({})\nconst props = defineProps<TableProps<TRow>>()\n\nconst loadItems = async (params: TableFetchParams) => {\n let data: TRow[] = []\n\n try {\n data = await props.source(params)\n } catch {\n // TODO: show errors\n }\n\n return data\n}\n\nconst onOrderClick = (event: Event, key: string) => {\n event.preventDefault()\n\n if (orders.value[key] === 'asc') {\n orders.value = { [key]: 'desc' }\n } else if (orders.value[key] === 'desc') {\n orders.value = {}\n } else {\n orders.value = { [key]: 'asc' }\n }\n}\n\nconst {\n page, isSyncing, isSynced, prevPage, nextPage, reload, refetch, items: rows,\n} = useFilterable<TableFilters, TRow>({\n initialFilters: { per_page: props.perPage, orders },\n loadItems,\n})\n\ndefineSlots<TableSlots<TRow>>()\n\ndefineExpose({\n refetch,\n reload,\n rows,\n})\n</script>\n"],"names":["randNum","SYNC_STATES","useFilterable","initialFilters","loadItems","page","ref","items","reactive","syncState","filters","combinedFilters","computed","load","watch","orders","shallowRef","params","data","props","onOrderClick","event","key","isSyncing","isSynced","prevPage","nextPage","reload","refetch","rows","__expose"],"mappings":";;;;;;;;;AAeA,UAAMA,IAAU,KAAK,MAAM,KAAK,WAAW,EAAE,IAAI;;;;;;;;ICF3CC,IAAc;AAAA,EAClB,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AACV,GAIMC,IAAgB,CAAkB,EAAE,gBAAAC,GAAgB,WAAAC,QAAoD;AACtG,QAAAC,IAAOC,EAAI,CAAC,GACZC,IAA4BC,EAAS,EAAE,OAAO,CAAA,EAAI,CAAA,GAClDC,IAAYH,EAAeL,EAAY,OAAO,GAC9CS,IAAUF,EAAS,EAAE,OAAOL,EAAgB,CAAA,GAE5CQ,IAAkBC,EAAoC,OAAO;AAAA,IACjE,MAAMP,EAAK;AAAA,IACX,GAAGK,EAAQ;AAAA,EACX,EAAA,GAEIG,IAAO,YAAY;AACvB,IAAAJ,EAAU,QAAQR,EAAY;AAE1B,QAAA;AACF,MAAAM,EAAM,QAAQ,MAAMH,EAAUO,EAAgB,KAAK,GACnDF,EAAU,QAAQR,EAAY;AAAA,IAAA,QACxB;AACN,MAAAM,EAAM,QAAQ,IACdE,EAAU,QAAQR,EAAY;AAAA,IAChC;AAAA,EAAA;AAEG,SAAAY,KAELC,EAAMH,GAAiBE,CAAI,GAEpB;AAAA,IACL,MAAAR;AAAA,IACA,OAAAE;AAAA,IACA,WAAAE;AAAA,IACA,UAAU,MAAM;AACd,MAAAJ,EAAK,SAAS;AAAA,IAChB;AAAA,IACA,UAAU,MAAM;AACd,MAAAA,EAAK,SAAS;AAAA,IAChB;AAAA,IACA,WAAWO,EAAS,MAAMH,EAAU,UAAUR,EAAY,OAAO;AAAA,IACjE,UAAUW,EAAS,MAAMH,EAAU,UAAUR,EAAY,MAAM;AAAA,IAC/D,UAAUW,EAAS,MAAMH,EAAU,UAAUR,EAAY,MAAM;AAAA,IAC/D,QAAQ,MAAM;AACP,MAAAY;IACP;AAAA,IACA,SAAS,MAAM;AACT,MAAAR,EAAK,UAAU,IACZQ,MAELR,EAAK,QAAQ;AAAA,IAEjB;AAAA,EAAA;AAEJ;;;;;;;;;;;iBCqCMU,IAASC,EAAwB,CAAA,CAAE,GAGnCZ,IAAY,OAAOa,MAA6B;AACpD,UAAIC,IAAe,CAAA;AAEf,UAAA;AACK,QAAAA,IAAA,MAAMC,EAAM,OAAOF,CAAM;AAAA,MAAA,QAC1B;AAAA,MAER;AAEO,aAAAC;AAAA,IAAA,GAGHE,IAAe,CAACC,GAAcC,MAAgB;AAClD,MAAAD,EAAM,eAAe,GAEjBN,EAAO,MAAMO,CAAG,MAAM,QACxBP,EAAO,QAAQ,EAAE,CAACO,CAAG,GAAG,OAAO,IACtBP,EAAO,MAAMO,CAAG,MAAM,SAC/BP,EAAO,QAAQ,KAEfA,EAAO,QAAQ,EAAE,CAACO,CAAG,GAAG,MAAM;AAAA,IAChC,GAGI;AAAA,MACJ,MAAAjB;AAAA,MAAM,WAAAkB;AAAA,MAAW,UAAAC;AAAA,MAAU,UAAAC;AAAA,MAAU,UAAAC;AAAA,MAAU,QAAAC;AAAA,MAAQ,SAAAC;AAAA,MAAS,OAAOC;AAAA,QACrE3B,EAAkC;AAAA,MACpC,gBAAgB,EAAE,UAAUiB,EAAM,SAAS,QAAAJ,EAAO;AAAA,MAClD,WAAAX;AAAA,IAAA,CACD;AAIY,WAAA0B,EAAA;AAAA,MACX,SAAAF;AAAA,MACA,QAAAD;AAAA,MACA,MAAAE;AAAA,IAAA,CACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/vst.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
(function(e,k){typeof exports=="object"&&typeof module<"u"?module.exports=k(require("vue")):typeof define=="function"&&define.amd?define(["vue"],k):(e=typeof globalThis<"u"?globalThis:e||self,e.VueSlimTable=k(e.Vue))})(this,function(e){"use strict";const k="",S=["colspan"],B=[e.createElementVNode("div",null,null,-1)],V=e.defineComponent({__name:"loading_row",props:{columnsLength:{type:Number,required:!0}},setup(p){const m=Math.floor(Math.random()*10)+1;return(r,n)=>(e.openBlock(),e.createElementBlock("tr",null,[e.createElementVNode("td",{colspan:p.columnsLength,class:e.normalizeClass(["vst-loading-row",`vst-loading-row-${m}`])},B,10,S)]))}}),c={INITIAL:"initial",SYNCING:"syncing",SYNCED:"synced",FAILED:"failed"},$=({initialFilters:p,loadItems:m})=>{const r=e.ref(1),n=e.reactive({value:[]}),s=e.ref(c.INITIAL),h=e.reactive({value:p}),i=e.computed(()=>({page:r.value,...h.value})),a=async()=>{s.value=c.SYNCING;try{n.value=await m(i.value),s.value=c.SYNCED}catch{n.value=[],s.value=c.FAILED}};return a(),e.watch(i,a),{page:r,items:n,syncState:s,nextPage:()=>{r.value+=1},prevPage:()=>{r.value-=1},isSyncing:e.computed(()=>s.value===c.SYNCING),isSynced:e.computed(()=>s.value===c.SYNCED),isFailed:e.computed(()=>s.value===c.FAILED),reload:()=>{a()},refetch:()=>{r.value===1?a():r.value=1}}},C={class:"vst"},b={key:0},I={key:0},_=["colspan"],F=["colspan"],w={key:0,class:"vst-pagination mt-3"};return e.defineComponent({__name:"slim_table",props:{columns:{},perPage:{},source:{type:Function}},setup(p,{expose:m}){const r=p,n=e.shallowRef({}),s=async t=>{let o=[];try{o=await r.source(t)}catch{}return o},h=(t,o)=>{t.preventDefault(),n.value[o]==="asc"?n.value={[o]:"desc"}:n.value[o]==="desc"?n.value={}:n.value={[o]:"asc"}},{page:i,isSyncing:a,isSynced:y,prevPage:N,nextPage:E,reload:L,refetch:D,items:d}=$({initialFilters:{per_page:r.perPage,orders:n},loadItems:s});return m({refetch:D,reload:L,rows:d}),(t,o)=>(e.openBlock(),e.createElementBlock("table",C,[t.columns.length?(e.openBlock(),e.createElementBlock("thead",b,[e.renderSlot(t.$slots,"thead:before"),e.renderSlot(t.$slots,"thead",{columns:t.columns,orders:n.value},()=>[e.createElementVNode("tr",null,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.columns,l=>(e.openBlock(),e.createElementBlock("th",e.mergeProps({key:l.key,class:["vst-th",{"vst-orderable":l.orderable}]},e.toHandlers(l.orderable?{click:f=>h(f,l.key)}:{},!0)),[l.orderable?(e.openBlock(),e.createElementBlock("div",I,[e.renderSlot(t.$slots,`thead:${l.key}`,{column:l,orders:n.value},()=>[e.createTextVNode(e.toDisplayString(l.title),1)]),e.createElementVNode("i",{class:e.normalizeClass(["vst-orderable-toggle",n.value[l.key]])},null,2)])):e.renderSlot(t.$slots,`thead:${l.key}`,{key:1,column:l,orders:n.value},()=>[e.createTextVNode(e.toDisplayString(l.title),1)])],16))),128))])]),e.renderSlot(t.$slots,"thead:after")])):e.createCommentVNode("",!0),e.createElementVNode("tbody",null,[e.unref(a)?e.renderSlot(t.$slots,"row:loading",{key:0},()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.perPage,l=>(e.openBlock(),e.createBlock(V,{key:`loadingRow${l}`,"columns-length":t.columns.length},null,8,["columns-length"]))),128))]):e.unref(y)&&e.unref(d).value.length===0?e.renderSlot(t.$slots,"row:empty",{key:1},()=>[e.createElementVNode("tr",null,[e.createElementVNode("td",{colspan:t.columns.length}," No records found ",8,_)])]):e.unref(y)&&e.unref(d).value.length?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:2},e.renderList(e.unref(d).value,(l,f)=>e.renderSlot(t.$slots,"row",{row:l,index:f,columns:t.columns},()=>[(e.openBlock(),e.createElementBlock("tr",{key:l.id||f},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.columns,g=>(e.openBlock(),e.createElementBlock("td",{key:g.key},[e.renderSlot(t.$slots,`cell:${g.key}`,{row:l,value:l[g.key],column:g,index:f},()=>[e.createTextVNode(e.toDisplayString(l[g.key]),1)])]))),128))]))])),256)):e.createCommentVNode("",!0)]),e.createElementVNode("tfoot",null,[e.createElementVNode("tr",null,[e.createElementVNode("td",{colspan:t.columns.length},[e.renderSlot(t.$slots,"pagination",{page:e.unref(i),rows:e.unref(d).value},()=>[e.unref(i)>1||e.unref(d).value.length===t.perPage||e.unref(a)?(e.openBlock(),e.createElementBlock("ul",w,[e.createElementVNode("li",{class:e.normalizeClass(["vst-page-item",{disabled:e.unref(i)===1||e.unref(a)}])},[e.createElementVNode("a",{class:"vst-page-link",onClick:o[0]||(o[0]=e.withModifiers((...l)=>e.unref(N)&&e.unref(N)(...l),["prevent"]))},"←")],2),e.createElementVNode("li",{class:e.normalizeClass(["vst-page-item",{disabled:e.unref(d).value.length<t.perPage||e.unref(a)}])},[e.createElementVNode("a",{class:"vst-page-link",onClick:o[1]||(o[1]=e.withModifiers((...l)=>e.unref(E)&&e.unref(E)(...l),["prevent"]))},"→")],2)])):e.createCommentVNode("",!0)])],8,F)])])]))}})});
|
|
2
2
|
//# sourceMappingURL=vst.umd.js.map
|
package/dist/vst.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vst.umd.js","sources":["../src/ts/components/loading_row.vue","../src/ts/use/filterable.ts","../src/ts/
|
|
1
|
+
{"version":3,"file":"vst.umd.js","sources":["../src/ts/components/loading_row.vue","../src/ts/use/filterable.ts","../src/ts/components/slim_table.vue"],"sourcesContent":["<template>\n <tr>\n <td\n :colspan=\"columnsLength\"\n :class=\"['vst-loading-row', `vst-loading-row-${randNum}`]\">\n <div />\n </td>\n </tr>\n</template>\n\n<script lang=\"ts\" setup>\ndefineProps({\n columnsLength: { type: Number, required: true },\n})\n\nconst randNum = Math.floor(Math.random() * 10) + 1\n</script>\n","import {\n ref, computed, reactive, watch,\n} from 'vue'\n\ntype CombinedFilters<T> = T & {\n page: number\n}\n\ntype UseFiltetableArgs<T, S> = {\n initialFilters: T,\n loadItems: (_params: T & { page: number }) => Promise<S[]>\n}\n\nconst SYNC_STATES = {\n INITIAL: 'initial',\n SYNCING: 'syncing',\n SYNCED: 'synced',\n FAILED: 'failed',\n} as const\n\ntype SynsState = (typeof SYNC_STATES)[keyof typeof SYNC_STATES]\n\nconst useFilterable = <TFilters, TItem>({ initialFilters, loadItems }: UseFiltetableArgs<TFilters, TItem>) => {\n const page = ref(1)\n const items: { value: TItem[] } = reactive({ value: [] })\n const syncState = ref<SynsState>(SYNC_STATES.INITIAL)\n const filters = reactive({ value: initialFilters })\n\n const combinedFilters = computed<CombinedFilters<TFilters>>(() => ({\n page: page.value,\n ...filters.value as TFilters,\n }))\n\n const load = async () => {\n syncState.value = SYNC_STATES.SYNCING\n\n try {\n items.value = await loadItems(combinedFilters.value)\n syncState.value = SYNC_STATES.SYNCED\n } catch {\n items.value = []\n syncState.value = SYNC_STATES.FAILED\n }\n }\n load()\n\n watch(combinedFilters, load)\n\n return {\n page,\n items,\n syncState,\n nextPage: () => {\n page.value += 1\n },\n prevPage: () => {\n page.value -= 1\n },\n isSyncing: computed(() => syncState.value === SYNC_STATES.SYNCING),\n isSynced: computed(() => syncState.value === SYNC_STATES.SYNCED),\n isFailed: computed(() => syncState.value === SYNC_STATES.FAILED),\n reload: () => {\n load()\n },\n refetch: () => {\n if (page.value === 1) {\n load()\n } else {\n page.value = 1\n }\n },\n }\n}\n\nexport default useFilterable\n","<template>\n <table class=\"vst\">\n <thead v-if=\"columns.length\">\n <slot name=\"thead:before\" />\n <slot name=\"thead\" :columns=\"columns\" :orders=\"orders\">\n <tr>\n <th\n v-for=\"column in columns\"\n :key=\"column.key\"\n :class=\"['vst-th', { 'vst-orderable': column.orderable }]\"\n v-on=\"column.orderable ? { click: (event: Event) => onOrderClick(event, column.key) } : {}\">\n <div v-if=\"column.orderable\">\n <slot\n :name=\"`thead:${column.key}`\"\n :column=\"column\"\n :orders=\"orders\">\n {{ column.title }}\n </slot>\n\n <i :class=\"['vst-orderable-toggle', orders[column.key]]\" />\n </div>\n\n <slot\n v-else\n :name=\"`thead:${column.key}`\"\n :column=\"column\"\n :orders=\"orders\">\n {{ column.title }}\n </slot>\n </th>\n </tr>\n </slot>\n <slot name=\"thead:after\" />\n </thead>\n <tbody>\n <slot v-if=\"isSyncing\" name=\"row:loading\">\n <LoadingRow\n v-for=\"i in perPage\"\n :key=\"`loadingRow${i}`\"\n :columns-length=\"columns.length\" />\n </slot>\n\n <slot v-else-if=\"isSynced && rows.value.length === 0\" name=\"row:empty\">\n <tr>\n <td :colspan=\"columns.length\">\n No records found\n </td>\n </tr>\n </slot>\n\n <template v-else-if=\"isSynced && rows.value.length\">\n <slot\n v-for=\"(row, i) in rows.value\"\n name=\"row\"\n :row=\"row\"\n :index=\"i\"\n :columns=\"columns\">\n <tr :key=\"row['id'] || i\">\n <td\n v-for=\"column in columns\"\n :key=\"column.key\">\n <slot\n :name=\"`cell:${column.key}`\"\n :row=\"row\"\n :value=\"row[column.key]\"\n :column=\"column\"\n :index=\"i\">\n {{ row[column.key] }}\n </slot>\n </td>\n </tr>\n </slot>\n </template>\n </tbody>\n <tfoot>\n <tr>\n <td :colspan=\"columns.length\">\n <slot name=\"pagination\" :page=\"page\" :rows=\"rows.value\">\n <ul\n v-if=\"page > 1 || rows.value.length === perPage || isSyncing\"\n class=\"vst-pagination mt-3\">\n <li :class=\"['vst-page-item', { disabled: page === 1 || isSyncing }]\">\n <a class=\"vst-page-link\" @click.prevent=\"prevPage\">←</a>\n </li>\n\n <li\n :class=\"['vst-page-item', {\n disabled: rows.value.length < perPage || isSyncing\n }]\">\n <a class=\"vst-page-link\" @click.prevent=\"nextPage\">→</a>\n </li>\n </ul>\n </slot>\n </td>\n </tr>\n </tfoot>\n </table>\n</template>\n\n<script setup lang=\"ts\" generic=\"TRow extends TableRow\">\nimport { shallowRef } from 'vue'\nimport LoadingRow from './loading_row.vue'\n\nimport useFilterable from '../use/filterable'\n\nimport type {\n TableOrders, TableFetchParams, TableRow, TableFilters, TableProps, TableSlots,\n} from '@/ts/types'\n\nconst orders = shallowRef<TableOrders>({})\nconst props = defineProps<TableProps<TRow>>()\n\nconst loadItems = async (params: TableFetchParams) => {\n let data: TRow[] = []\n\n try {\n data = await props.source(params)\n } catch {\n // TODO: show errors\n }\n\n return data\n}\n\nconst onOrderClick = (event: Event, key: string) => {\n event.preventDefault()\n\n if (orders.value[key] === 'asc') {\n orders.value = { [key]: 'desc' }\n } else if (orders.value[key] === 'desc') {\n orders.value = {}\n } else {\n orders.value = { [key]: 'asc' }\n }\n}\n\nconst {\n page, isSyncing, isSynced, prevPage, nextPage, reload, refetch, items: rows,\n} = useFilterable<TableFilters, TRow>({\n initialFilters: { per_page: props.perPage, orders },\n loadItems,\n})\n\ndefineSlots<TableSlots<TRow>>()\n\ndefineExpose({\n refetch,\n reload,\n rows,\n})\n</script>\n"],"names":["randNum","SYNC_STATES","useFilterable","initialFilters","loadItems","page","ref","items","reactive","syncState","filters","combinedFilters","computed","load","watch","orders","shallowRef","params","data","props","onOrderClick","event","key","isSyncing","isSynced","prevPage","nextPage","reload","refetch","rows","__expose"],"mappings":"kaAeA,MAAMA,EAAU,KAAK,MAAM,KAAK,SAAW,EAAE,EAAI,mMCF3CC,EAAc,CAClB,QAAS,UACT,QAAS,UACT,OAAQ,SACR,OAAQ,QACV,EAIMC,EAAgB,CAAkB,CAAE,eAAAC,EAAgB,UAAAC,KAAoD,CACtG,MAAAC,EAAOC,MAAI,CAAC,EACZC,EAA4BC,EAAS,SAAA,CAAE,MAAO,CAAA,CAAI,CAAA,EAClDC,EAAYH,EAAAA,IAAeL,EAAY,OAAO,EAC9CS,EAAUF,EAAA,SAAS,CAAE,MAAOL,CAAgB,CAAA,EAE5CQ,EAAkBC,EAAAA,SAAoC,KAAO,CACjE,KAAMP,EAAK,MACX,GAAGK,EAAQ,KACX,EAAA,EAEIG,EAAO,SAAY,CACvBJ,EAAU,MAAQR,EAAY,QAE1B,GAAA,CACFM,EAAM,MAAQ,MAAMH,EAAUO,EAAgB,KAAK,EACnDF,EAAU,MAAQR,EAAY,MAAA,MACxB,CACNM,EAAM,MAAQ,GACdE,EAAU,MAAQR,EAAY,MAChC,CAAA,EAEG,OAAAY,IAELC,QAAMH,EAAiBE,CAAI,EAEpB,CACL,KAAAR,EACA,MAAAE,EACA,UAAAE,EACA,SAAU,IAAM,CACdJ,EAAK,OAAS,CAChB,EACA,SAAU,IAAM,CACdA,EAAK,OAAS,CAChB,EACA,UAAWO,EAAS,SAAA,IAAMH,EAAU,QAAUR,EAAY,OAAO,EACjE,SAAUW,EAAS,SAAA,IAAMH,EAAU,QAAUR,EAAY,MAAM,EAC/D,SAAUW,EAAS,SAAA,IAAMH,EAAU,QAAUR,EAAY,MAAM,EAC/D,OAAQ,IAAM,CACPY,GACP,EACA,QAAS,IAAM,CACTR,EAAK,QAAU,EACZQ,IAELR,EAAK,MAAQ,CAEjB,CAAA,CAEJ,yOCqCMU,EAASC,aAAwB,CAAA,CAAE,EAGnCZ,EAAY,MAAOa,GAA6B,CACpD,IAAIC,EAAe,CAAA,EAEf,GAAA,CACKA,EAAA,MAAMC,EAAM,OAAOF,CAAM,CAAA,MAC1B,CAER,CAEO,OAAAC,CAAA,EAGHE,EAAe,CAACC,EAAcC,IAAgB,CAClDD,EAAM,eAAe,EAEjBN,EAAO,MAAMO,CAAG,IAAM,MACxBP,EAAO,MAAQ,CAAE,CAACO,CAAG,EAAG,MAAO,EACtBP,EAAO,MAAMO,CAAG,IAAM,OAC/BP,EAAO,MAAQ,GAEfA,EAAO,MAAQ,CAAE,CAACO,CAAG,EAAG,KAAM,CAChC,EAGI,CACJ,KAAAjB,EAAM,UAAAkB,EAAW,SAAAC,EAAU,SAAAC,EAAU,SAAAC,EAAU,OAAAC,EAAQ,QAAAC,EAAS,MAAOC,GACrE3B,EAAkC,CACpC,eAAgB,CAAE,SAAUiB,EAAM,QAAS,OAAAJ,CAAO,EAClD,UAAAX,CAAA,CACD,EAIY,OAAA0B,EAAA,CACX,QAAAF,EACA,OAAAD,EACA,KAAAE,CAAA,CACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-slim-tables",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist"
|
|
6
6
|
],
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"require": "./dist/vst.umd.js"
|
|
13
13
|
},
|
|
14
14
|
"./stylesheets": "dist/style.css",
|
|
15
|
-
"./src/
|
|
15
|
+
"./src/main": "./src/main.ts",
|
|
16
16
|
"./filterable": "./src/ts/use/filterable"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "vite build",
|
|
20
|
-
"lint": "eslint ./src/ts/ --ext 'ts,vue'",
|
|
20
|
+
"lint": "eslint ./src/ts/ --ext 'ts,vue' --fix",
|
|
21
21
|
"test": "vitest",
|
|
22
22
|
"coverage": "vitest run --coverage"
|
|
23
23
|
},
|
|
@@ -32,27 +32,28 @@
|
|
|
32
32
|
},
|
|
33
33
|
"author": "fLa <flatra66@gmail.com>",
|
|
34
34
|
"license": "MIT",
|
|
35
|
-
"private": false,
|
|
36
35
|
"devDependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"@typescript-eslint/
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"
|
|
42
|
-
"
|
|
36
|
+
"@babel/types": "^7.20.7",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
|
38
|
+
"@typescript-eslint/parser": "^6.2.1",
|
|
39
|
+
"@vitejs/plugin-vue": "^4.2.3",
|
|
40
|
+
"@vitest/coverage-v8": "^0.34.1",
|
|
41
|
+
"@vue/test-utils": "^2.4.1",
|
|
42
|
+
"eslint": "^8.46.0",
|
|
43
43
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
44
|
-
"eslint-plugin-import": "^2.
|
|
45
|
-
"eslint-plugin-vue": "^
|
|
46
|
-
"happy-dom": "^
|
|
47
|
-
"sass": "^1.
|
|
48
|
-
"typescript": "
|
|
49
|
-
"vite": "^
|
|
50
|
-
"vite-plugin-dts": "^
|
|
51
|
-
"vitest": "^0.
|
|
52
|
-
"vue-eslint-parser": "^
|
|
44
|
+
"eslint-plugin-import": "^2.28.0",
|
|
45
|
+
"eslint-plugin-vue": "^9.16.1",
|
|
46
|
+
"happy-dom": "^10.8.0",
|
|
47
|
+
"sass": "^1.64.2",
|
|
48
|
+
"typescript": "^5.1.6",
|
|
49
|
+
"vite": "^4.4.8",
|
|
50
|
+
"vite-plugin-dts": "^3.5.1",
|
|
51
|
+
"vitest": "^0.34.1",
|
|
52
|
+
"vue-eslint-parser": "^9.1.1"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"vue": "^3.
|
|
55
|
+
"vue": "^3.3.0"
|
|
56
56
|
},
|
|
57
|
-
"types": "dist/types/
|
|
57
|
+
"types": "dist/types/main.d.ts",
|
|
58
|
+
"packageManager": "yarn@3.4.1"
|
|
58
59
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
declare const _sfc_main: import("vue").DefineComponent<{
|
|
2
|
-
columnsLength: {
|
|
3
|
-
type: NumberConstructor;
|
|
4
|
-
required: true;
|
|
5
|
-
};
|
|
6
|
-
}, {
|
|
7
|
-
randNum: number;
|
|
8
|
-
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
9
|
-
columnsLength: {
|
|
10
|
-
type: NumberConstructor;
|
|
11
|
-
required: true;
|
|
12
|
-
};
|
|
13
|
-
}>>, {}>;
|
|
14
|
-
export default _sfc_main;
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { ShallowRef } from 'vue';
|
|
2
|
-
interface TableColumn {
|
|
3
|
-
key: string;
|
|
4
|
-
title: string;
|
|
5
|
-
orderable?: boolean;
|
|
6
|
-
}
|
|
7
|
-
interface TableOrders {
|
|
8
|
-
[key: string]: 'asc' | 'desc';
|
|
9
|
-
}
|
|
10
|
-
interface TableFetchParams {
|
|
11
|
-
per_page: number;
|
|
12
|
-
page: number;
|
|
13
|
-
order?: Array<{
|
|
14
|
-
field: string;
|
|
15
|
-
direction: 'asc' | 'desc';
|
|
16
|
-
}>;
|
|
17
|
-
}
|
|
18
|
-
declare const _sfc_main: import("vue").DefineComponent<{
|
|
19
|
-
columns: {
|
|
20
|
-
type: ArrayConstructor;
|
|
21
|
-
required: true;
|
|
22
|
-
};
|
|
23
|
-
source: {
|
|
24
|
-
type: (StringConstructor | FunctionConstructor)[];
|
|
25
|
-
required: true;
|
|
26
|
-
};
|
|
27
|
-
perPage: {
|
|
28
|
-
type: NumberConstructor;
|
|
29
|
-
required: false;
|
|
30
|
-
default: number;
|
|
31
|
-
};
|
|
32
|
-
}, {
|
|
33
|
-
props: {
|
|
34
|
-
columns: Array<TableColumn>;
|
|
35
|
-
source: string | ((_: TableFetchParams) => Promise<Array<unknown>> | Array<unknown>);
|
|
36
|
-
perPage: number;
|
|
37
|
-
};
|
|
38
|
-
orders: ShallowRef<TableOrders>;
|
|
39
|
-
fetchData: (params: TableFetchParams) => Promise<any>;
|
|
40
|
-
onOrderClick: (key: string) => void;
|
|
41
|
-
page: import("vue").Ref<number>;
|
|
42
|
-
isSyncing: import("vue").ComputedRef<boolean>;
|
|
43
|
-
isSynced: import("vue").ComputedRef<boolean>;
|
|
44
|
-
prevPage: () => void;
|
|
45
|
-
nextPage: () => void;
|
|
46
|
-
reload: () => void;
|
|
47
|
-
refetch: () => void;
|
|
48
|
-
rows: {
|
|
49
|
-
value: {
|
|
50
|
-
[x: string]: any;
|
|
51
|
-
}[];
|
|
52
|
-
};
|
|
53
|
-
LoadingRow: import("vue").DefineComponent<{
|
|
54
|
-
columnsLength: {
|
|
55
|
-
type: NumberConstructor;
|
|
56
|
-
required: true;
|
|
57
|
-
};
|
|
58
|
-
}, {
|
|
59
|
-
randNum: number;
|
|
60
|
-
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
61
|
-
columnsLength: {
|
|
62
|
-
type: NumberConstructor;
|
|
63
|
-
required: true;
|
|
64
|
-
};
|
|
65
|
-
}>>, {}>;
|
|
66
|
-
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
67
|
-
columns: {
|
|
68
|
-
type: ArrayConstructor;
|
|
69
|
-
required: true;
|
|
70
|
-
};
|
|
71
|
-
source: {
|
|
72
|
-
type: (StringConstructor | FunctionConstructor)[];
|
|
73
|
-
required: true;
|
|
74
|
-
};
|
|
75
|
-
perPage: {
|
|
76
|
-
type: NumberConstructor;
|
|
77
|
-
required: false;
|
|
78
|
-
default: number;
|
|
79
|
-
};
|
|
80
|
-
}>>, {
|
|
81
|
-
perPage: number;
|
|
82
|
-
}>;
|
|
83
|
-
export default _sfc_main;
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
interface UseFiltetableArgs {
|
|
2
|
-
initialFilters: {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
};
|
|
5
|
-
loadItems: any;
|
|
6
|
-
}
|
|
7
|
-
declare const useFilterable: ({ initialFilters, loadItems }: UseFiltetableArgs) => {
|
|
8
|
-
page: import("vue").Ref<number>;
|
|
9
|
-
items: {
|
|
10
|
-
value: {
|
|
11
|
-
[x: string]: any;
|
|
12
|
-
}[];
|
|
13
|
-
};
|
|
14
|
-
syncState: import("vue").Ref<string>;
|
|
15
|
-
nextPage: () => void;
|
|
16
|
-
prevPage: () => void;
|
|
17
|
-
isSyncing: import("vue").ComputedRef<boolean>;
|
|
18
|
-
isSynced: import("vue").ComputedRef<boolean>;
|
|
19
|
-
isFailed: import("vue").ComputedRef<boolean>;
|
|
20
|
-
reload: () => void;
|
|
21
|
-
refetch: () => void;
|
|
22
|
-
};
|
|
23
|
-
export default useFilterable;
|