lkt-table 1.0.13
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 +219 -0
- package/dist/lkt-table.es.js +373 -0
- package/dist/lkt-table.umd.js +1 -0
- package/dist/types/components/LktHiddenRow.vue.d.ts +209 -0
- package/dist/types/components/LktTableRow.vue.d.ts +194 -0
- package/dist/types/functions/table-functions.d.ts +52 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/instances/LktTableColumn.d.ts +16 -0
- package/dist/types/interfaces/TableColumn.d.ts +9 -0
- package/dist/types/lib-components/LktTable.vue.d.ts +214 -0
- package/lkt-table.css +114 -0
- package/package.json +71 -0
- package/src/components/LktHiddenRow.vue +59 -0
- package/src/components/LktTableRow.vue +60 -0
- package/src/index.ts +13 -0
- package/src/lib-components/LktTable.vue +260 -0
package/README.md
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# LKT Table
|
|
2
|
+

|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Vue component (Vue.js 3.0) allowing a simple yet powerful table component.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
* Custom slots per column
|
|
13
|
+
* Hide columns by config
|
|
14
|
+
* Automatically hide empty columns
|
|
15
|
+
* Full support of [Sortable.js](https://github.com/RubaXa/Sortable) features:
|
|
16
|
+
* Supports touch devices
|
|
17
|
+
* Supports drag handles and selectable text
|
|
18
|
+
* Smart auto-scrolling
|
|
19
|
+
* No jQuery dependency
|
|
20
|
+
* Keeps in sync HTML and view model list
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
### With npm
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm i -S lkt-table
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Typical use:
|
|
31
|
+
In your main.js
|
|
32
|
+
```js
|
|
33
|
+
import LktTable from 'lkt-table';
|
|
34
|
+
|
|
35
|
+
app.use(LktTable);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
In your component:
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<lkt-table v-model="myArray" v-bind:columns="columns"></lkt-table>
|
|
42
|
+
```
|
|
43
|
+
```js
|
|
44
|
+
import {createColumn} from 'lkt-table';
|
|
45
|
+
|
|
46
|
+
let isSortable = false;
|
|
47
|
+
|
|
48
|
+
export default {
|
|
49
|
+
data() {
|
|
50
|
+
return {
|
|
51
|
+
columns: [
|
|
52
|
+
createColumn('name', 'Name'),
|
|
53
|
+
createColumn('surname', 'Surname', isSortable),
|
|
54
|
+
],
|
|
55
|
+
items: [
|
|
56
|
+
{name: 'a', surname: 'n'},
|
|
57
|
+
{name: 'b', surname: 'n1'},
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### With `custom column slots`:
|
|
66
|
+
```html
|
|
67
|
+
<lkt-table v-model:value="myArray" v-bind:columns="columns">
|
|
68
|
+
<template v-slot:name="{item}">{{item.name}}</template
|
|
69
|
+
</lkt-table>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Usage of `createColumn`:
|
|
73
|
+
```js
|
|
74
|
+
const column = createColumn(elementProperty, propertyTextInHeader)
|
|
75
|
+
|
|
76
|
+
// Enables/disables column being sortable
|
|
77
|
+
// by clicking in header
|
|
78
|
+
// Default: true
|
|
79
|
+
.setIsSortable(status)
|
|
80
|
+
|
|
81
|
+
// Make this column hidden, available by clicking a button
|
|
82
|
+
// Default: false
|
|
83
|
+
.setIsHidden(status)
|
|
84
|
+
|
|
85
|
+
// Defines a text formatter for this column
|
|
86
|
+
// Useful if you don't need and slot
|
|
87
|
+
// Must be a function
|
|
88
|
+
// Default: undefined
|
|
89
|
+
.setFormatter(formatter)
|
|
90
|
+
|
|
91
|
+
// Defines a check function to test if this column
|
|
92
|
+
// is empty.
|
|
93
|
+
// If all items has this column empty, this column
|
|
94
|
+
// won't be rendered
|
|
95
|
+
// Default: undefined
|
|
96
|
+
.setEmptyChecker(checker)
|
|
97
|
+
|
|
98
|
+
// Defines a function to check which colspan should take
|
|
99
|
+
// this column
|
|
100
|
+
// Default: undefined
|
|
101
|
+
.setColSpan(checker)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Props
|
|
105
|
+
|
|
106
|
+
### value
|
|
107
|
+
Type: `Array`<br>
|
|
108
|
+
Required: `true`<br>
|
|
109
|
+
Default: `[]`
|
|
110
|
+
|
|
111
|
+
Input data array to display.
|
|
112
|
+
```html
|
|
113
|
+
<lkt-table v-model:value="myArray"></lkt-table>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### columns
|
|
117
|
+
Type: `Array`<br>
|
|
118
|
+
Required: `true`<br>
|
|
119
|
+
Default: `[]`
|
|
120
|
+
|
|
121
|
+
Columns configuration (data to be shown, order, ...)
|
|
122
|
+
```html
|
|
123
|
+
<lkt-table v-bind:columns="columns"></lkt-table>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### sorter
|
|
127
|
+
Type: `Function`<br>
|
|
128
|
+
Required: `false`<br>
|
|
129
|
+
Default: `undefined`
|
|
130
|
+
|
|
131
|
+
Sorting function which will be triggered each time a th is clicked (if column is sortable)
|
|
132
|
+
```html
|
|
133
|
+
<lkt-table v-bind:sorter="sorter"></lkt-table>
|
|
134
|
+
```
|
|
135
|
+
```js
|
|
136
|
+
export default {
|
|
137
|
+
methods: {
|
|
138
|
+
sorter(datum1, datum2, column, sortDirection) {
|
|
139
|
+
return 1;
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
...
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
### sortable
|
|
148
|
+
Type: `Boolean`<br>
|
|
149
|
+
Required: `false`<br>
|
|
150
|
+
Default: `false`
|
|
151
|
+
|
|
152
|
+
Enables drag and drop
|
|
153
|
+
```html
|
|
154
|
+
<lkt-table v-bind:sortable="true"></lkt-table>
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### hideEmptyColumns
|
|
158
|
+
Type: `Boolean`<br>
|
|
159
|
+
Required: `false`<br>
|
|
160
|
+
Default: `false`
|
|
161
|
+
|
|
162
|
+
Enables automatic hide empty columns
|
|
163
|
+
```html
|
|
164
|
+
<lkt-table v-bind:hide-empty-columns="true"></lkt-table>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### draggableChecker
|
|
168
|
+
Type: `Function`<br>
|
|
169
|
+
Required: `false`<br>
|
|
170
|
+
Default: `(evt) => true`
|
|
171
|
+
|
|
172
|
+
A function to determine if an item can be dragged
|
|
173
|
+
```html
|
|
174
|
+
<lkt-table v-bind:draggable-checker="fn"></lkt-table>
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### checkValidDrag
|
|
178
|
+
Type: `Function`<br>
|
|
179
|
+
Required: `false`<br>
|
|
180
|
+
Default: `(evt) => true`
|
|
181
|
+
|
|
182
|
+
A function to determine if an item can be dropped in a certain position
|
|
183
|
+
```html
|
|
184
|
+
<lkt-table v-bind:check-valid-drag="fn"></lkt-table>
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
### Events
|
|
189
|
+
|
|
190
|
+
* LktTable emits these events:
|
|
191
|
+
|
|
192
|
+
- `update:modelValue` (for value v-model)
|
|
193
|
+
- `sort` (same as input, but after sorting)
|
|
194
|
+
|
|
195
|
+
HTML:
|
|
196
|
+
```HTML
|
|
197
|
+
<lkt-table v-on:sort="doSomething"></lkt-table>
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Slots
|
|
201
|
+
|
|
202
|
+
#### custom column slot
|
|
203
|
+
LktTable generates one slot per column, so you can always control how a column will be shown.
|
|
204
|
+
|
|
205
|
+
The `custom column slot` will be named with the column key.
|
|
206
|
+
|
|
207
|
+
Slot props:
|
|
208
|
+
- `value` the element value for that column
|
|
209
|
+
- `item` the element itself
|
|
210
|
+
- `column` the column config
|
|
211
|
+
- `i` the row index
|
|
212
|
+
|
|
213
|
+
```html
|
|
214
|
+
<lkt-table v-model:value="myArray" v-bind:columns="columns">
|
|
215
|
+
<template v-slot:name="{item, value}">
|
|
216
|
+
<div>{{value}}, {{item.surname}}</div>
|
|
217
|
+
</template
|
|
218
|
+
</lkt-table>
|
|
219
|
+
```
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
var ae = Object.defineProperty;
|
|
2
|
+
var ne = (e, t, a) => t in e ? ae(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
|
|
3
|
+
var $ = (e, t, a) => (ne(e, typeof t != "symbol" ? t + "" : t, a), a);
|
|
4
|
+
import { defineComponent as x, openBlock as s, createElementBlock as o, createCommentVNode as C, normalizeClass as ie, Fragment as k, renderList as g, unref as v, renderSlot as B, createTextVNode as Y, toDisplayString as L, withDirectives as re, createElementVNode as p, vShow as se, useSlots as oe, ref as V, computed as I, onMounted as de, watch as Q, createBlock as N, withCtx as H, createSlots as M } from "vue";
|
|
5
|
+
import ue from "vuedraggable";
|
|
6
|
+
import { createLktEvent as U } from "lkt-events";
|
|
7
|
+
import { generateRandomString as ce } from "lkt-string-tools";
|
|
8
|
+
class Z {
|
|
9
|
+
constructor(t = "", a = "") {
|
|
10
|
+
$(this, "key");
|
|
11
|
+
$(this, "label");
|
|
12
|
+
$(this, "sortable");
|
|
13
|
+
$(this, "hidden");
|
|
14
|
+
$(this, "formatter");
|
|
15
|
+
$(this, "checkEmpty");
|
|
16
|
+
$(this, "colspan");
|
|
17
|
+
this.key = t, this.label = a, this.sortable = !0, this.hidden = !1, this.formatter = void 0, this.checkEmpty = void 0, this.colspan = void 0;
|
|
18
|
+
}
|
|
19
|
+
setIsSortable(t = !0) {
|
|
20
|
+
return this.sortable = t, this;
|
|
21
|
+
}
|
|
22
|
+
setIsHidden(t = !0) {
|
|
23
|
+
return this.hidden = t, this;
|
|
24
|
+
}
|
|
25
|
+
setFormatter(t = void 0) {
|
|
26
|
+
return this.formatter = t, this;
|
|
27
|
+
}
|
|
28
|
+
setEmptyChecker(t = void 0) {
|
|
29
|
+
return this.checkEmpty = t, this;
|
|
30
|
+
}
|
|
31
|
+
setColSpan(t = void 0) {
|
|
32
|
+
return this.colspan = void 0, this;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const qe = (e, t, a = !0) => new Z(e, t).setIsSortable(a), Me = (e, t, a = !0) => new Z(e, t).setIsSortable(a).setIsHidden(!0), W = (e, t, a, c) => {
|
|
36
|
+
if (!a)
|
|
37
|
+
return 0;
|
|
38
|
+
let f = e[a.key], n = t[a.key];
|
|
39
|
+
if (c === "asc") {
|
|
40
|
+
if (f > n)
|
|
41
|
+
return 1;
|
|
42
|
+
if (n > f)
|
|
43
|
+
return -1;
|
|
44
|
+
} else {
|
|
45
|
+
if (f > n)
|
|
46
|
+
return -1;
|
|
47
|
+
if (n > f)
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
return 0;
|
|
51
|
+
}, T = (e, t, a) => e.formatter && typeof e.formatter == "function" ? e.formatter(t[e.key], t, e, a) : t[e.key], fe = (e, t, a) => {
|
|
52
|
+
if (!e.colspan)
|
|
53
|
+
return -1;
|
|
54
|
+
let c = t;
|
|
55
|
+
return a.forEach((f) => {
|
|
56
|
+
let n = G(e, f);
|
|
57
|
+
n > 0 && n < c && (c = n);
|
|
58
|
+
}), c;
|
|
59
|
+
}, G = (e, t) => e.colspan === !1 ? !1 : typeof e.colspan == "function" ? e.colspan(t) : e.colspan, me = (e, t, a) => {
|
|
60
|
+
if (typeof e != "object" || !e.key || t.indexOf(e.key) > -1)
|
|
61
|
+
return !1;
|
|
62
|
+
let c = G(e, a);
|
|
63
|
+
return typeof e.colspan > "u" ? !0 : (typeof e.colspan < "u" && (typeof e.colspan == "function" ? c = parseInt(e.colspan()) : c = parseInt(e.colspan)), c > 0);
|
|
64
|
+
}, ye = (e = []) => {
|
|
65
|
+
if (e.length > 0) {
|
|
66
|
+
for (let t = 0; t < e.length; ++t)
|
|
67
|
+
if (e[t].sortable)
|
|
68
|
+
return e[t].key;
|
|
69
|
+
}
|
|
70
|
+
return "";
|
|
71
|
+
}, he = (e, t) => {
|
|
72
|
+
if (e.length > 0) {
|
|
73
|
+
for (let a = 0; a < e.length; ++a)
|
|
74
|
+
if (e[a].key === t)
|
|
75
|
+
return e[a];
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}, be = ["data-i", "data-handle-drag"], ve = {
|
|
79
|
+
key: 0,
|
|
80
|
+
"data-role": "drag-indicator"
|
|
81
|
+
}, ke = {
|
|
82
|
+
key: 1,
|
|
83
|
+
"data-role": "invalid-drag-indicator"
|
|
84
|
+
}, ge = ["data-column", "colspan", "title", "onClick"], Ce = { name: "LktTableRow", inheritAttrs: !1 }, X = /* @__PURE__ */ x({
|
|
85
|
+
...Ce,
|
|
86
|
+
props: {
|
|
87
|
+
isDraggable: { type: Boolean, default: !0 },
|
|
88
|
+
sortable: { type: Boolean, default: !0 },
|
|
89
|
+
i: { type: [Number], default: 0 },
|
|
90
|
+
displayHiddenColumnsIndicator: { type: Boolean, default: !1 },
|
|
91
|
+
visibleColumns: { type: Array, default: () => [] },
|
|
92
|
+
emptyColumns: { type: Array, default: () => [] },
|
|
93
|
+
hiddenIsVisible: { type: Boolean, default: !1 },
|
|
94
|
+
item: { type: Object, default: () => ({}) }
|
|
95
|
+
},
|
|
96
|
+
emits: ["click", "show"],
|
|
97
|
+
setup(e, { emit: t }) {
|
|
98
|
+
const a = t, c = (n, d, u) => {
|
|
99
|
+
a("click", n, U("", { item: d, column: u }));
|
|
100
|
+
}, f = (n, d) => {
|
|
101
|
+
a("show", n, U("", { i: d }));
|
|
102
|
+
};
|
|
103
|
+
return (n, d) => (s(), o("tr", {
|
|
104
|
+
"data-i": e.i,
|
|
105
|
+
"data-handle-drag": e.isDraggable
|
|
106
|
+
}, [
|
|
107
|
+
e.sortable && e.isDraggable ? (s(), o("td", ve)) : e.sortable ? (s(), o("td", ke)) : C("", !0),
|
|
108
|
+
e.displayHiddenColumnsIndicator ? (s(), o("td", {
|
|
109
|
+
key: 2,
|
|
110
|
+
onClick: d[0] || (d[0] = (u) => f(u, e.i)),
|
|
111
|
+
"data-role": "show-more",
|
|
112
|
+
class: ie(e.hiddenIsVisible ? "state-open" : "")
|
|
113
|
+
}, null, 2)) : C("", !0),
|
|
114
|
+
(s(!0), o(k, null, g(e.visibleColumns, (u) => (s(), o(k, null, [
|
|
115
|
+
v(me)(u, e.emptyColumns, e.item) ? (s(), o("td", {
|
|
116
|
+
key: 0,
|
|
117
|
+
"data-column": u.key,
|
|
118
|
+
colspan: v(G)(u, e.item),
|
|
119
|
+
title: v(T)(u, e.item, e.i),
|
|
120
|
+
onClick: (S) => c(S, e.item, u)
|
|
121
|
+
}, [
|
|
122
|
+
n.$slots[u.key] ? B(n.$slots, u.key, {
|
|
123
|
+
key: 0,
|
|
124
|
+
value: e.item[u.key],
|
|
125
|
+
item: e.item,
|
|
126
|
+
column: u,
|
|
127
|
+
i: e.i
|
|
128
|
+
}) : e.item ? (s(), o(k, { key: 1 }, [
|
|
129
|
+
Y(L(v(T)(u, e.item, e.i)), 1)
|
|
130
|
+
], 64)) : C("", !0)
|
|
131
|
+
], 8, ge)) : C("", !0)
|
|
132
|
+
], 64))), 256))
|
|
133
|
+
], 8, be));
|
|
134
|
+
}
|
|
135
|
+
}), pe = { "data-role": "hidden-row" }, Se = ["colspan"], $e = ["data-column"], Ie = ["data-i"], Ve = ["data-column", "title", "onClick"], Be = { name: "LktHiddenRow", inheritAttrs: !1 }, Ee = /* @__PURE__ */ x({
|
|
136
|
+
...Be,
|
|
137
|
+
props: {
|
|
138
|
+
isDraggable: { type: Boolean, default: !0 },
|
|
139
|
+
sortable: { type: Boolean, default: !0 },
|
|
140
|
+
i: { type: [Number], default: 0 },
|
|
141
|
+
hiddenColumnsColSpan: { type: Number, default: 0 },
|
|
142
|
+
visibleColumns: { type: Array, default: () => [] },
|
|
143
|
+
hiddenColumns: { type: Array, default: () => [] },
|
|
144
|
+
emptyColumns: { type: Array, default: () => [] },
|
|
145
|
+
hiddenIsVisible: { type: Boolean, default: !1 },
|
|
146
|
+
item: { type: Object, default: () => ({}) }
|
|
147
|
+
},
|
|
148
|
+
emits: ["click"],
|
|
149
|
+
setup(e, { emit: t }) {
|
|
150
|
+
const a = t, c = (f, n, d) => {
|
|
151
|
+
a("click", f, U("", { item: n, column: d }));
|
|
152
|
+
};
|
|
153
|
+
return (f, n) => re((s(), o("tr", pe, [
|
|
154
|
+
p("td", { colspan: e.hiddenColumnsColSpan }, [
|
|
155
|
+
p("table", null, [
|
|
156
|
+
p("tr", null, [
|
|
157
|
+
(s(!0), o(k, null, g(e.hiddenColumns, (d) => (s(), o("th", {
|
|
158
|
+
"data-column": d.key
|
|
159
|
+
}, [
|
|
160
|
+
p("div", null, L(d.label), 1)
|
|
161
|
+
], 8, $e))), 256))
|
|
162
|
+
]),
|
|
163
|
+
p("tr", { "data-i": e.i }, [
|
|
164
|
+
(s(!0), o(k, null, g(e.hiddenColumns, (d, u) => (s(), o("td", {
|
|
165
|
+
"data-column": d.key,
|
|
166
|
+
title: v(T)(d, e.item, u),
|
|
167
|
+
onClick: (S) => c(S, e.item, d)
|
|
168
|
+
}, [
|
|
169
|
+
f.$slots[d.key] ? B(f.$slots, d.key, {
|
|
170
|
+
key: 0,
|
|
171
|
+
value: e.item[d.key],
|
|
172
|
+
item: e.item,
|
|
173
|
+
column: d,
|
|
174
|
+
i: u
|
|
175
|
+
}) : (s(), o(k, { key: 1 }, [
|
|
176
|
+
Y(L(v(T)(d, e.item, u)), 1)
|
|
177
|
+
], 64))
|
|
178
|
+
], 8, Ve))), 256))
|
|
179
|
+
], 8, Ie)
|
|
180
|
+
])
|
|
181
|
+
], 8, Se)
|
|
182
|
+
], 512)), [
|
|
183
|
+
[se, e.hiddenIsVisible]
|
|
184
|
+
]);
|
|
185
|
+
}
|
|
186
|
+
}), De = ["data-sortable"], we = {
|
|
187
|
+
key: 0,
|
|
188
|
+
"data-role": "drag-indicator"
|
|
189
|
+
}, Ae = { key: 1 }, Ne = ["data-column", "data-sortable", "data-sort", "colspan", "title", "onClick"], He = { key: 1 }, Le = {
|
|
190
|
+
key: 1,
|
|
191
|
+
class: "lkt-empty-table"
|
|
192
|
+
}, Te = { name: "LktTable", inheritAttrs: !1 }, Ke = /* @__PURE__ */ x({
|
|
193
|
+
...Te,
|
|
194
|
+
props: {
|
|
195
|
+
modelValue: { type: Array, default: () => [] },
|
|
196
|
+
columns: { type: Array, default: () => [] },
|
|
197
|
+
sorter: { type: Function, default: W },
|
|
198
|
+
sortable: { type: Boolean, default: !1 },
|
|
199
|
+
hideEmptyColumns: { type: Boolean, default: !1 },
|
|
200
|
+
draggableChecker: { type: Function, default: (e) => !0 },
|
|
201
|
+
checkValidDrag: { type: Function, default: (e) => !0 },
|
|
202
|
+
draggableItemKey: { type: String, default: "name" }
|
|
203
|
+
},
|
|
204
|
+
emits: ["update:modelValue", "sort", "click"],
|
|
205
|
+
setup(e, { expose: t, emit: a }) {
|
|
206
|
+
const c = a, f = oe(), n = e, d = {}, u = V(typeof n.sorter == "function" ? n.sorter : W), S = V(ye(n.columns)), E = V("asc"), h = V(n.modelValue), w = V(d), J = V(!1), K = ce(12), _ = I(() => h.value.length > 0), A = I(() => {
|
|
207
|
+
if (!n.hideEmptyColumns)
|
|
208
|
+
return [];
|
|
209
|
+
let l = [];
|
|
210
|
+
return n.columns.forEach((i) => {
|
|
211
|
+
let r = i.key, m = !1;
|
|
212
|
+
h.value.forEach((y) => {
|
|
213
|
+
if (typeof y.checkEmpty == "function")
|
|
214
|
+
return y.checkEmpty(y);
|
|
215
|
+
y[r] && (m = !0);
|
|
216
|
+
}), m || l.push(r);
|
|
217
|
+
}), l;
|
|
218
|
+
}), D = I(() => n.columns.filter((l) => !l.hidden)), F = I(() => n.columns.filter((l) => l.hidden)), ee = I(() => {
|
|
219
|
+
let l = D.value.length + 1;
|
|
220
|
+
return n.sortable && ++l, l;
|
|
221
|
+
}), O = I(() => F.value.length > 0 && !n.sortable), te = I(() => n.columns.map((l) => l.key)), R = I(() => {
|
|
222
|
+
let l = [];
|
|
223
|
+
for (let i in f)
|
|
224
|
+
te.value.indexOf(i) !== -1 && l.push(i);
|
|
225
|
+
return l;
|
|
226
|
+
}), le = (l) => {
|
|
227
|
+
let i = l.target;
|
|
228
|
+
if (typeof i.dataset.column > "u")
|
|
229
|
+
do
|
|
230
|
+
i = i.parentNode;
|
|
231
|
+
while (typeof i.dataset.column > "u" && i.tagName !== "TABLE" && i.tagName !== "body");
|
|
232
|
+
if (i.tagName === "TD" && (i = i.parentNode, i = i.dataset.i, typeof i < "u"))
|
|
233
|
+
return h.value[i];
|
|
234
|
+
}, j = (l) => w.value["tr_" + l] === !0, P = (l) => {
|
|
235
|
+
!l || l.sortable && (h.value = h.value.sort((i, r) => u.value(i, r, l, E.value)), E.value = E.value === "asc" ? "desc" : "asc", S.value = l.key, c("sort", [S.value, E.value]));
|
|
236
|
+
}, z = (l, i) => {
|
|
237
|
+
c("click", l, i);
|
|
238
|
+
}, q = (l, i) => {
|
|
239
|
+
let r = "tr_" + i.value.i;
|
|
240
|
+
w.value[r] = typeof w.value[r] > "u" ? !0 : !w.value[r];
|
|
241
|
+
};
|
|
242
|
+
return de(() => {
|
|
243
|
+
P(he(n.columns, S.value));
|
|
244
|
+
}), Q(() => n.modelValue, (l) => h.value = l), Q(h, (l) => c("update:modelValue", l)), t({ getItemByEvent: le }), (l, i) => _.value ? (s(), o("div", {
|
|
245
|
+
key: 0,
|
|
246
|
+
class: "lkt-table",
|
|
247
|
+
"data-sortable": e.sortable
|
|
248
|
+
}, [
|
|
249
|
+
p("table", null, [
|
|
250
|
+
p("thead", null, [
|
|
251
|
+
p("tr", null, [
|
|
252
|
+
e.sortable ? (s(), o("th", we)) : C("", !0),
|
|
253
|
+
O.value ? (s(), o("th", Ae)) : C("", !0),
|
|
254
|
+
(s(!0), o(k, null, g(D.value, (r) => (s(), o(k, null, [
|
|
255
|
+
A.value.indexOf(r.key) === -1 ? (s(), o("th", {
|
|
256
|
+
key: 0,
|
|
257
|
+
"data-column": r.key,
|
|
258
|
+
"data-sortable": r.sortable === !0,
|
|
259
|
+
"data-sort": r.sortable === !0 && S.value === r.key ? E.value : "",
|
|
260
|
+
colspan: v(fe)(r, e.columns.length, h.value),
|
|
261
|
+
title: r.label,
|
|
262
|
+
onClick: (m) => P(r)
|
|
263
|
+
}, [
|
|
264
|
+
p("div", null, L(r.label), 1)
|
|
265
|
+
], 8, Ne)) : C("", !0)
|
|
266
|
+
], 64))), 256))
|
|
267
|
+
])
|
|
268
|
+
]),
|
|
269
|
+
e.sortable ? (s(), N(v(ue), {
|
|
270
|
+
key: 0,
|
|
271
|
+
modelValue: h.value,
|
|
272
|
+
"onUpdate:modelValue": i[0] || (i[0] = (r) => h.value = r),
|
|
273
|
+
move: e.checkValidDrag,
|
|
274
|
+
itemKey: e.draggableItemKey,
|
|
275
|
+
onStart: i[1] || (i[1] = (r) => J.value = !0),
|
|
276
|
+
onEnd: i[2] || (i[2] = (r) => J.value = !1),
|
|
277
|
+
tag: "tbody",
|
|
278
|
+
class: "lkt-sortable-table",
|
|
279
|
+
handle: "[data-handle-drag]"
|
|
280
|
+
}, {
|
|
281
|
+
item: H(({ element: r, index: m }) => [
|
|
282
|
+
(s(), N(X, {
|
|
283
|
+
key: v(K) + "-" + m,
|
|
284
|
+
i: m,
|
|
285
|
+
item: r,
|
|
286
|
+
"display-hidden-columns-indicator": O.value,
|
|
287
|
+
"is-draggable": e.draggableChecker ? e.draggableChecker(r) : !0,
|
|
288
|
+
sortable: e.sortable,
|
|
289
|
+
"visible-columns": D.value,
|
|
290
|
+
"empty-columns": A.value,
|
|
291
|
+
"hidden-is-visible": j(m),
|
|
292
|
+
onClick: z,
|
|
293
|
+
onShow: q
|
|
294
|
+
}, M({ _: 2 }, [
|
|
295
|
+
g(R.value, (y) => ({
|
|
296
|
+
name: y,
|
|
297
|
+
fn: H((b) => [
|
|
298
|
+
B(l.$slots, y, {
|
|
299
|
+
item: b.item,
|
|
300
|
+
value: b.value,
|
|
301
|
+
column: b.column
|
|
302
|
+
})
|
|
303
|
+
])
|
|
304
|
+
}))
|
|
305
|
+
]), 1032, ["i", "item", "display-hidden-columns-indicator", "is-draggable", "sortable", "visible-columns", "empty-columns", "hidden-is-visible"]))
|
|
306
|
+
]),
|
|
307
|
+
_: 3
|
|
308
|
+
}, 8, ["modelValue", "move", "itemKey"])) : (s(), o("tbody", He, [
|
|
309
|
+
(s(!0), o(k, null, g(h.value, (r, m) => (s(), N(X, {
|
|
310
|
+
key: v(K) + "-" + m,
|
|
311
|
+
i: m,
|
|
312
|
+
item: r,
|
|
313
|
+
"display-hidden-columns-indicator": O.value,
|
|
314
|
+
"is-draggable": e.draggableChecker ? e.draggableChecker(r) : !0,
|
|
315
|
+
sortable: e.sortable,
|
|
316
|
+
"visible-columns": D.value,
|
|
317
|
+
"empty-columns": A.value,
|
|
318
|
+
"hidden-is-visible": j(m),
|
|
319
|
+
onClick: z,
|
|
320
|
+
onShow: q
|
|
321
|
+
}, M({ _: 2 }, [
|
|
322
|
+
g(R.value, (y) => ({
|
|
323
|
+
name: y,
|
|
324
|
+
fn: H((b) => [
|
|
325
|
+
B(l.$slots, y, {
|
|
326
|
+
item: b.item,
|
|
327
|
+
value: b.value,
|
|
328
|
+
column: b.column
|
|
329
|
+
})
|
|
330
|
+
])
|
|
331
|
+
}))
|
|
332
|
+
]), 1032, ["i", "item", "display-hidden-columns-indicator", "is-draggable", "sortable", "visible-columns", "empty-columns", "hidden-is-visible"]))), 128)),
|
|
333
|
+
F.value.length > 0 ? (s(!0), o(k, { key: 0 }, g(h.value, (r, m) => (s(), N(Ee, {
|
|
334
|
+
key: v(K) + "-" + m,
|
|
335
|
+
i: m,
|
|
336
|
+
item: r,
|
|
337
|
+
"hidden-columns": F.value,
|
|
338
|
+
"hidden-columns-col-span": ee.value,
|
|
339
|
+
"is-draggable": e.draggableChecker ? e.draggableChecker(r) : !0,
|
|
340
|
+
sortable: e.sortable,
|
|
341
|
+
"visible-columns": D.value,
|
|
342
|
+
"empty-columns": A.value,
|
|
343
|
+
"hidden-is-visible": j(m),
|
|
344
|
+
onClick: z,
|
|
345
|
+
onShow: q
|
|
346
|
+
}, M({ _: 2 }, [
|
|
347
|
+
g(R.value, (y) => ({
|
|
348
|
+
name: y,
|
|
349
|
+
fn: H((b) => [
|
|
350
|
+
B(l.$slots, y, {
|
|
351
|
+
item: b.item,
|
|
352
|
+
value: b.value,
|
|
353
|
+
column: b.column
|
|
354
|
+
})
|
|
355
|
+
])
|
|
356
|
+
}))
|
|
357
|
+
]), 1032, ["i", "item", "hidden-columns", "hidden-columns-col-span", "is-draggable", "sortable", "visible-columns", "empty-columns", "hidden-is-visible"]))), 128)) : C("", !0)
|
|
358
|
+
]))
|
|
359
|
+
])
|
|
360
|
+
], 8, De)) : l.$slots["no-items"] ? (s(), o("div", Le, [
|
|
361
|
+
B(l.$slots, "no-items")
|
|
362
|
+
])) : C("", !0);
|
|
363
|
+
}
|
|
364
|
+
}), Ue = {
|
|
365
|
+
install: (e) => {
|
|
366
|
+
e.component("lkt-table", Ke);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
export {
|
|
370
|
+
qe as createColumn,
|
|
371
|
+
Me as createHiddenColumn,
|
|
372
|
+
Ue as default
|
|
373
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(c,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("vuedraggable"),require("lkt-events"),require("lkt-string-tools")):typeof define=="function"&&define.amd?define(["exports","vue","vuedraggable","lkt-events","lkt-string-tools"],e):(c=typeof globalThis<"u"?globalThis:c||self,e(c.LktTable={},c.Vue,c.draggable,c.LktEvents,c.LktStringTools))})(this,function(c,e,p,N,R){"use strict";var ge=Object.defineProperty;var pe=(c,e,p)=>e in c?ge(c,e,{enumerable:!0,configurable:!0,writable:!0,value:p}):c[e]=p;var g=(c,e,p)=>(pe(c,typeof e!="symbol"?e+"":e,p),p);const x=(t=>t&&typeof t=="object"&&"default"in t?t:{default:t})(p);class H{constructor(l="",i=""){g(this,"key");g(this,"label");g(this,"sortable");g(this,"hidden");g(this,"formatter");g(this,"checkEmpty");g(this,"colspan");this.key=l,this.label=i,this.sortable=!0,this.hidden=!1,this.formatter=void 0,this.checkEmpty=void 0,this.colspan=void 0}setIsSortable(l=!0){return this.sortable=l,this}setIsHidden(l=!0){return this.hidden=l,this}setFormatter(l=void 0){return this.formatter=l,this}setEmptyChecker(l=void 0){return this.checkEmpty=l,this}setColSpan(l=void 0){return this.colspan=void 0,this}}const M=(t,l,i=!0)=>new H(t,l).setIsSortable(i),z=(t,l,i=!0)=>new H(t,l).setIsSortable(i).setIsHidden(!0),j=(t,l,i,m)=>{if(!i)return 0;let f=t[i.key],a=l[i.key];if(m==="asc"){if(f>a)return 1;if(a>f)return-1}else{if(f>a)return-1;if(a>f)return 1}return 0},E=(t,l,i)=>t.formatter&&typeof t.formatter=="function"?t.formatter(l[t.key],l,t,i):l[t.key],P=(t,l,i)=>{if(!t.colspan)return-1;let m=l;return i.forEach(f=>{let a=$(t,f);a>0&&a<m&&(m=a)}),m},$=(t,l)=>t.colspan===!1?!1:typeof t.colspan=="function"?t.colspan(l):t.colspan,U=(t,l,i)=>{if(typeof t!="object"||!t.key||l.indexOf(t.key)>-1)return!1;let m=$(t,i);return typeof t.colspan>"u"?!0:(typeof t.colspan<"u"&&(typeof t.colspan=="function"?m=parseInt(t.colspan()):m=parseInt(t.colspan)),m>0)},G=(t=[])=>{if(t.length>0){for(let l=0;l<t.length;++l)if(t[l].sortable)return t[l].key}return""},J=(t,l)=>{if(t.length>0){for(let i=0;i<t.length;++i)if(t[i].key===l)return t[i]}return null},Q=["data-i","data-handle-drag"],W={key:0,"data-role":"drag-indicator"},X={key:1,"data-role":"invalid-drag-indicator"},Y=["data-column","colspan","title","onClick"],Z={name:"LktTableRow",inheritAttrs:!1},K=e.defineComponent({...Z,props:{isDraggable:{type:Boolean,default:!0},sortable:{type:Boolean,default:!0},i:{type:[Number],default:0},displayHiddenColumnsIndicator:{type:Boolean,default:!1},visibleColumns:{type:Array,default:()=>[]},emptyColumns:{type:Array,default:()=>[]},hiddenIsVisible:{type:Boolean,default:!1},item:{type:Object,default:()=>({})}},emits:["click","show"],setup(t,{emit:l}){const i=l,m=(a,s,d)=>{i("click",a,N.createLktEvent("",{item:s,column:d}))},f=(a,s)=>{i("show",a,N.createLktEvent("",{i:s}))};return(a,s)=>(e.openBlock(),e.createElementBlock("tr",{"data-i":t.i,"data-handle-drag":t.isDraggable},[t.sortable&&t.isDraggable?(e.openBlock(),e.createElementBlock("td",W)):t.sortable?(e.openBlock(),e.createElementBlock("td",X)):e.createCommentVNode("",!0),t.displayHiddenColumnsIndicator?(e.openBlock(),e.createElementBlock("td",{key:2,onClick:s[0]||(s[0]=d=>f(d,t.i)),"data-role":"show-more",class:e.normalizeClass(t.hiddenIsVisible?"state-open":"")},null,2)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.visibleColumns,d=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.unref(U)(d,t.emptyColumns,t.item)?(e.openBlock(),e.createElementBlock("td",{key:0,"data-column":d.key,colspan:e.unref($)(d,t.item),title:e.unref(E)(d,t.item,t.i),onClick:b=>m(b,t.item,d)},[a.$slots[d.key]?e.renderSlot(a.$slots,d.key,{key:0,value:t.item[d.key],item:t.item,column:d,i:t.i}):t.item?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createTextVNode(e.toDisplayString(e.unref(E)(d,t.item,t.i)),1)],64)):e.createCommentVNode("",!0)],8,Y)):e.createCommentVNode("",!0)],64))),256))],8,Q))}}),_={"data-role":"hidden-row"},v=["colspan"],ee=["data-column"],te=["data-i"],le=["data-column","title","onClick"],ne={name:"LktHiddenRow",inheritAttrs:!1},ae=e.defineComponent({...ne,props:{isDraggable:{type:Boolean,default:!0},sortable:{type:Boolean,default:!0},i:{type:[Number],default:0},hiddenColumnsColSpan:{type:Number,default:0},visibleColumns:{type:Array,default:()=>[]},hiddenColumns:{type:Array,default:()=>[]},emptyColumns:{type:Array,default:()=>[]},hiddenIsVisible:{type:Boolean,default:!1},item:{type:Object,default:()=>({})}},emits:["click"],setup(t,{emit:l}){const i=l,m=(f,a,s)=>{i("click",f,N.createLktEvent("",{item:a,column:s}))};return(f,a)=>e.withDirectives((e.openBlock(),e.createElementBlock("tr",_,[e.createElementVNode("td",{colspan:t.hiddenColumnsColSpan},[e.createElementVNode("table",null,[e.createElementVNode("tr",null,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.hiddenColumns,s=>(e.openBlock(),e.createElementBlock("th",{"data-column":s.key},[e.createElementVNode("div",null,e.toDisplayString(s.label),1)],8,ee))),256))]),e.createElementVNode("tr",{"data-i":t.i},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.hiddenColumns,(s,d)=>(e.openBlock(),e.createElementBlock("td",{"data-column":s.key,title:e.unref(E)(s,t.item,d),onClick:b=>m(b,t.item,s)},[f.$slots[s.key]?e.renderSlot(f.$slots,s.key,{key:0,value:t.item[s.key],item:t.item,column:s,i:d}):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createTextVNode(e.toDisplayString(e.unref(E)(s,t.item,d)),1)],64))],8,le))),256))],8,te)])],8,v)],512)),[[e.vShow,t.hiddenIsVisible]])}}),re=["data-sortable"],oe={key:0,"data-role":"drag-indicator"},ie={key:1},se=["data-column","data-sortable","data-sort","colspan","title","onClick"],de={key:1},ce={key:1,class:"lkt-empty-table"},me={name:"LktTable",inheritAttrs:!1},fe=e.defineComponent({...me,props:{modelValue:{type:Array,default:()=>[]},columns:{type:Array,default:()=>[]},sorter:{type:Function,default:j},sortable:{type:Boolean,default:!1},hideEmptyColumns:{type:Boolean,default:!1},draggableChecker:{type:Function,default:t=>!0},checkValidDrag:{type:Function,default:t=>!0},draggableItemKey:{type:String,default:"name"}},emits:["update:modelValue","sort","click"],setup(t,{expose:l,emit:i}){const m=i,f=e.useSlots(),a=t,s={},d=e.ref(typeof a.sorter=="function"?a.sorter:j),b=e.ref(G(a.columns)),C=e.ref("asc"),y=e.ref(a.modelValue),S=e.ref(s),O=e.ref(!1),L=R.generateRandomString(12),ke=e.computed(()=>y.value.length>0),V=e.computed(()=>{if(!a.hideEmptyColumns)return[];let n=[];return a.columns.forEach(r=>{let o=r.key,u=!1;y.value.forEach(k=>{if(typeof k.checkEmpty=="function")return k.checkEmpty(k);k[o]&&(u=!0)}),u||n.push(o)}),n}),B=e.computed(()=>a.columns.filter(n=>!n.hidden)),I=e.computed(()=>a.columns.filter(n=>n.hidden)),ye=e.computed(()=>{let n=B.value.length+1;return a.sortable&&++n,n}),D=e.computed(()=>I.value.length>0&&!a.sortable),he=e.computed(()=>a.columns.map(n=>n.key)),w=e.computed(()=>{let n=[];for(let r in f)he.value.indexOf(r)!==-1&&n.push(r);return n}),be=n=>{let r=n.target;if(typeof r.dataset.column>"u")do r=r.parentNode;while(typeof r.dataset.column>"u"&&r.tagName!=="TABLE"&&r.tagName!=="body");if(r.tagName==="TD"&&(r=r.parentNode,r=r.dataset.i,typeof r<"u"))return y.value[r]},F=n=>S.value["tr_"+n]===!0,q=n=>{!n||n.sortable&&(y.value=y.value.sort((r,o)=>d.value(r,o,n,C.value)),C.value=C.value==="asc"?"desc":"asc",b.value=n.key,m("sort",[b.value,C.value]))},T=(n,r)=>{m("click",n,r)},A=(n,r)=>{let o="tr_"+r.value.i;S.value[o]=typeof S.value[o]>"u"?!0:!S.value[o]};return e.onMounted(()=>{q(J(a.columns,b.value))}),e.watch(()=>a.modelValue,n=>y.value=n),e.watch(y,n=>m("update:modelValue",n)),l({getItemByEvent:be}),(n,r)=>ke.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"lkt-table","data-sortable":t.sortable},[e.createElementVNode("table",null,[e.createElementVNode("thead",null,[e.createElementVNode("tr",null,[t.sortable?(e.openBlock(),e.createElementBlock("th",oe)):e.createCommentVNode("",!0),D.value?(e.openBlock(),e.createElementBlock("th",ie)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(B.value,o=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[V.value.indexOf(o.key)===-1?(e.openBlock(),e.createElementBlock("th",{key:0,"data-column":o.key,"data-sortable":o.sortable===!0,"data-sort":o.sortable===!0&&b.value===o.key?C.value:"",colspan:e.unref(P)(o,t.columns.length,y.value),title:o.label,onClick:u=>q(o)},[e.createElementVNode("div",null,e.toDisplayString(o.label),1)],8,se)):e.createCommentVNode("",!0)],64))),256))])]),t.sortable?(e.openBlock(),e.createBlock(e.unref(x.default),{key:0,modelValue:y.value,"onUpdate:modelValue":r[0]||(r[0]=o=>y.value=o),move:t.checkValidDrag,itemKey:t.draggableItemKey,onStart:r[1]||(r[1]=o=>O.value=!0),onEnd:r[2]||(r[2]=o=>O.value=!1),tag:"tbody",class:"lkt-sortable-table",handle:"[data-handle-drag]"},{item:e.withCtx(({element:o,index:u})=>[(e.openBlock(),e.createBlock(K,{key:e.unref(L)+"-"+u,i:u,item:o,"display-hidden-columns-indicator":D.value,"is-draggable":t.draggableChecker?t.draggableChecker(o):!0,sortable:t.sortable,"visible-columns":B.value,"empty-columns":V.value,"hidden-is-visible":F(u),onClick:T,onShow:A},e.createSlots({_:2},[e.renderList(w.value,k=>({name:k,fn:e.withCtx(h=>[e.renderSlot(n.$slots,k,{item:h.item,value:h.value,column:h.column})])}))]),1032,["i","item","display-hidden-columns-indicator","is-draggable","sortable","visible-columns","empty-columns","hidden-is-visible"]))]),_:3},8,["modelValue","move","itemKey"])):(e.openBlock(),e.createElementBlock("tbody",de,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(y.value,(o,u)=>(e.openBlock(),e.createBlock(K,{key:e.unref(L)+"-"+u,i:u,item:o,"display-hidden-columns-indicator":D.value,"is-draggable":t.draggableChecker?t.draggableChecker(o):!0,sortable:t.sortable,"visible-columns":B.value,"empty-columns":V.value,"hidden-is-visible":F(u),onClick:T,onShow:A},e.createSlots({_:2},[e.renderList(w.value,k=>({name:k,fn:e.withCtx(h=>[e.renderSlot(n.$slots,k,{item:h.item,value:h.value,column:h.column})])}))]),1032,["i","item","display-hidden-columns-indicator","is-draggable","sortable","visible-columns","empty-columns","hidden-is-visible"]))),128)),I.value.length>0?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(y.value,(o,u)=>(e.openBlock(),e.createBlock(ae,{key:e.unref(L)+"-"+u,i:u,item:o,"hidden-columns":I.value,"hidden-columns-col-span":ye.value,"is-draggable":t.draggableChecker?t.draggableChecker(o):!0,sortable:t.sortable,"visible-columns":B.value,"empty-columns":V.value,"hidden-is-visible":F(u),onClick:T,onShow:A},e.createSlots({_:2},[e.renderList(w.value,k=>({name:k,fn:e.withCtx(h=>[e.renderSlot(n.$slots,k,{item:h.item,value:h.value,column:h.column})])}))]),1032,["i","item","hidden-columns","hidden-columns-col-span","is-draggable","sortable","visible-columns","empty-columns","hidden-is-visible"]))),128)):e.createCommentVNode("",!0)]))])],8,re)):n.$slots["no-items"]?(e.openBlock(),e.createElementBlock("div",ce,[e.renderSlot(n.$slots,"no-items")])):e.createCommentVNode("",!0)}}),ue={install:t=>{t.component("lkt-table",fe)}};c.createColumn=M,c.createHiddenColumn=z,c.default=ue,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|