vue-slottable 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/style.css +1 -1
- package/dist/vue-slottable.mjs +105 -62
- package/dist/vue-slottable.umd.js +1 -1
- package/package.json +1 -1
- package/src/App.vue +2074 -483
- package/src/components/SlotTable.vue +92 -10
- package/src/components/SlotTableColumn.vue +12 -0
- package/src/types.d.ts +6 -0
- /package/{LICENSE.txt → LICENSE} +0 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/muraliavarma/vue-slot-table/actions/workflows/ci.yml)
|
|
4
4
|
[](https://www.npmjs.com/package/vue-slottable)
|
|
5
|
-
[](./LICENSE)
|
|
6
6
|
|
|
7
7
|
A flexible, slot-based table component for Vue 3. Define columns with scoped slots, add sticky columns, column groups, sorting, and more — with zero CSS opinions.
|
|
8
8
|
|
|
@@ -297,4 +297,4 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
|
297
297
|
|
|
298
298
|
## License
|
|
299
299
|
|
|
300
|
-
[MIT](./LICENSE
|
|
300
|
+
[MIT](./LICENSE)
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.sticky-left{position:sticky;left:0;z-index:1}.sticky-right{position:sticky;right:0;z-index:1}.align-left{text-align:left}.align-center{text-align:center}.align-right{text-align:right}
|
|
1
|
+
.sticky-left{position:sticky;left:0;z-index:1}.sticky-right{position:sticky;right:0;z-index:1}.align-left{text-align:left}.align-center{text-align:center}.align-right{text-align:right}.slot-table-sticky-header th{position:sticky;top:0;z-index:2}.slot-table-sticky-header .sticky-left,.slot-table-sticky-header .sticky-right{z-index:3}
|
package/dist/vue-slottable.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
const
|
|
1
|
+
import { defineComponent as S, h as s } from "vue";
|
|
2
|
+
const q = S({
|
|
3
3
|
name: "SlotTableColumn",
|
|
4
4
|
props: {
|
|
5
5
|
sticky: {
|
|
@@ -17,12 +17,24 @@ const W = b({
|
|
|
17
17
|
minWidth: {
|
|
18
18
|
type: String,
|
|
19
19
|
default: ""
|
|
20
|
+
},
|
|
21
|
+
visible: {
|
|
22
|
+
type: Boolean,
|
|
23
|
+
default: !0
|
|
24
|
+
},
|
|
25
|
+
tdClass: {
|
|
26
|
+
type: [String, Object],
|
|
27
|
+
default: void 0
|
|
28
|
+
},
|
|
29
|
+
thClass: {
|
|
30
|
+
type: [String, Object],
|
|
31
|
+
default: void 0
|
|
20
32
|
}
|
|
21
33
|
},
|
|
22
34
|
setup() {
|
|
23
35
|
return () => null;
|
|
24
36
|
}
|
|
25
|
-
}),
|
|
37
|
+
}), A = S({
|
|
26
38
|
name: "SlotTableColumnGroup",
|
|
27
39
|
props: {
|
|
28
40
|
sticky: {
|
|
@@ -37,7 +49,7 @@ const W = b({
|
|
|
37
49
|
setup() {
|
|
38
50
|
return () => null;
|
|
39
51
|
}
|
|
40
|
-
}),
|
|
52
|
+
}), D = S({
|
|
41
53
|
name: "SlotTable",
|
|
42
54
|
props: {
|
|
43
55
|
rows: {
|
|
@@ -67,87 +79,118 @@ const W = b({
|
|
|
67
79
|
bordered: {
|
|
68
80
|
type: Boolean,
|
|
69
81
|
default: !1
|
|
82
|
+
},
|
|
83
|
+
loading: {
|
|
84
|
+
type: Boolean,
|
|
85
|
+
default: !1
|
|
86
|
+
},
|
|
87
|
+
stickyHeader: {
|
|
88
|
+
type: Boolean,
|
|
89
|
+
default: !1
|
|
90
|
+
},
|
|
91
|
+
caption: {
|
|
92
|
+
type: String,
|
|
93
|
+
default: ""
|
|
70
94
|
}
|
|
71
95
|
},
|
|
72
|
-
emits: ["row-click", "header-click"],
|
|
73
|
-
setup(
|
|
96
|
+
emits: ["row-click", "header-click", "cell-click"],
|
|
97
|
+
setup(l, { slots: y, emit: b }) {
|
|
74
98
|
function p(n) {
|
|
75
99
|
const t = {};
|
|
76
100
|
return n.width && (t.width = n.width), (n["min-width"] || n.minWidth) && (t.minWidth = n["min-width"] || n.minWidth), Object.keys(t).length > 0 ? t : void 0;
|
|
77
101
|
}
|
|
78
|
-
function
|
|
79
|
-
const t = n.sticky || "",
|
|
102
|
+
function m(n) {
|
|
103
|
+
const t = n.sticky || "", a = n.align || "";
|
|
80
104
|
return {
|
|
81
105
|
"sticky-left": t === "left",
|
|
82
106
|
"sticky-right": t === "right",
|
|
83
|
-
"align-left":
|
|
84
|
-
"align-center":
|
|
85
|
-
"align-right":
|
|
107
|
+
"align-left": a === "left",
|
|
108
|
+
"align-center": a === "center",
|
|
109
|
+
"align-right": a === "right"
|
|
86
110
|
};
|
|
87
111
|
}
|
|
88
|
-
function
|
|
89
|
-
return
|
|
112
|
+
function C(n, t) {
|
|
113
|
+
return t ? typeof t == "string" ? { ...n, [t]: !0 } : { ...n, ...t } : n;
|
|
90
114
|
}
|
|
91
115
|
function K(n, t) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
116
|
+
return l.rowKey ? typeof l.rowKey == "function" ? l.rowKey(n, t) : n[l.rowKey] : t;
|
|
117
|
+
}
|
|
118
|
+
function O(n, t) {
|
|
119
|
+
const a = {};
|
|
120
|
+
if (l.striped && t % 2 === 1 && (a["slot-table-striped"] = !0), l.hoverable && (a["slot-table-hoverable"] = !0), !l.rowClass) return a;
|
|
121
|
+
if (typeof l.rowClass == "function") {
|
|
122
|
+
const r = l.rowClass(n, t);
|
|
123
|
+
typeof r == "string" ? a[r] = !0 : typeof r == "object" && Object.assign(a, r);
|
|
124
|
+
} else typeof l.rowClass == "string" ? a[l.rowClass] = !0 : Object.assign(a, l.rowClass);
|
|
125
|
+
return a;
|
|
126
|
+
}
|
|
127
|
+
function R(n) {
|
|
128
|
+
const t = n.visible;
|
|
129
|
+
return t === void 0 || t === "" || t === !0 ? !0 : !!t;
|
|
99
130
|
}
|
|
100
131
|
return () => {
|
|
101
|
-
const n = y.default ? y.default() : [], t = [],
|
|
102
|
-
n.forEach((
|
|
103
|
-
|
|
132
|
+
const n = y.default ? y.default() : [], t = [], a = [];
|
|
133
|
+
n.forEach((e) => {
|
|
134
|
+
e.type === q ? t.push(e) : e.type === A && a.push(e);
|
|
104
135
|
});
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
return
|
|
108
|
-
class:
|
|
109
|
-
style:
|
|
110
|
-
onClick: () =>
|
|
111
|
-
},
|
|
112
|
-
}), w =
|
|
113
|
-
const
|
|
114
|
-
"sticky-left":
|
|
115
|
-
"sticky-right":
|
|
116
|
-
},
|
|
117
|
-
return
|
|
118
|
-
}),
|
|
119
|
-
w.length > 0 &&
|
|
120
|
-
const
|
|
121
|
-
let
|
|
122
|
-
if (
|
|
123
|
-
const
|
|
124
|
-
|
|
136
|
+
const r = t.filter((e) => R(e.props || {})), T = l.caption ? s("caption", { class: "slot-table-caption" }, l.caption) : null, _ = r.map((e, i) => {
|
|
137
|
+
const o = e.props || {}, f = m(o), u = C(f, o.thClass || o["th-class"]), d = p(o), c = e.children && e.children.header, h = typeof c == "function" ? c() : null;
|
|
138
|
+
return s("th", {
|
|
139
|
+
class: u,
|
|
140
|
+
style: d,
|
|
141
|
+
onClick: () => b("header-click", i)
|
|
142
|
+
}, h);
|
|
143
|
+
}), w = a.map((e) => {
|
|
144
|
+
const i = e.props || {}, o = i.sticky || "", f = i.colspan ? Number(i.colspan) : void 0, u = {
|
|
145
|
+
"sticky-left": o === "left",
|
|
146
|
+
"sticky-right": o === "right"
|
|
147
|
+
}, d = e.children && e.children.default, c = typeof d == "function" ? d() : null;
|
|
148
|
+
return s("th", { class: u, colspan: f }, c);
|
|
149
|
+
}), k = [];
|
|
150
|
+
w.length > 0 && k.push(s("tr", null, w)), k.push(s("tr", null, _));
|
|
151
|
+
const F = l.stickyHeader ? { "slot-table-sticky-header": !0 } : void 0, W = s("thead", { class: F }, k);
|
|
152
|
+
let g;
|
|
153
|
+
if (l.loading && y.loading) {
|
|
154
|
+
const e = s("tr", null, [
|
|
155
|
+
s("td", { colspan: r.length, class: "slot-table-loading" }, y.loading())
|
|
125
156
|
]);
|
|
126
|
-
|
|
157
|
+
g = s("tbody", null, [e]);
|
|
158
|
+
} else if (l.rows.length === 0 && y.empty) {
|
|
159
|
+
const e = s("tr", null, [
|
|
160
|
+
s("td", { colspan: r.length, class: "slot-table-empty" }, y.empty())
|
|
161
|
+
]);
|
|
162
|
+
g = s("tbody", null, [e]);
|
|
127
163
|
} else {
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
const
|
|
131
|
-
return
|
|
164
|
+
const e = l.rows.map((i, o) => {
|
|
165
|
+
const f = r.map((u, d) => {
|
|
166
|
+
const c = u.props || {}, h = m(c), E = C(h, c.tdClass || c["td-class"]), N = p(c), B = u.children && u.children.cell, $ = typeof B == "function" ? B({ row: i, rowIndex: o, columnIndex: d }) : null;
|
|
167
|
+
return s("td", {
|
|
168
|
+
class: E,
|
|
169
|
+
style: N,
|
|
170
|
+
onClick: () => b("cell-click", o, d, i)
|
|
171
|
+
}, $);
|
|
132
172
|
});
|
|
133
|
-
return
|
|
134
|
-
key:
|
|
135
|
-
class:
|
|
136
|
-
onClick: () =>
|
|
137
|
-
},
|
|
173
|
+
return s("tr", {
|
|
174
|
+
key: K(i, o),
|
|
175
|
+
class: O(i, o),
|
|
176
|
+
onClick: () => b("row-click", o, i)
|
|
177
|
+
}, f);
|
|
138
178
|
});
|
|
139
|
-
|
|
179
|
+
g = s("tbody", null, e);
|
|
140
180
|
}
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
"
|
|
144
|
-
}
|
|
145
|
-
|
|
181
|
+
const j = r.map((e, i) => {
|
|
182
|
+
const o = e.props || {}, f = m(o), u = C(f, o.tdClass || o["td-class"]), d = p(o), c = e.children && e.children.footer, h = typeof c == "function" ? c() : null;
|
|
183
|
+
return s("td", { class: u, style: d }, h);
|
|
184
|
+
}), v = j.some((e) => e.children !== null) ? s("tfoot", null, [s("tr", null, j)]) : null, G = {
|
|
185
|
+
[l.tableClass]: !!l.tableClass,
|
|
186
|
+
"slot-table-bordered": l.bordered
|
|
187
|
+
}, H = [T, W, g, v].filter(Boolean);
|
|
188
|
+
return s("table", { class: G }, H);
|
|
146
189
|
};
|
|
147
190
|
}
|
|
148
191
|
});
|
|
149
192
|
export {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
193
|
+
D as SlotTable,
|
|
194
|
+
q as SlotTableColumn,
|
|
195
|
+
A as SlotTableColumnGroup
|
|
153
196
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(u,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(u=typeof globalThis<"u"?globalThis:u||self,t(u.VueSlotTable={},u.Vue))})(this,function(u,t){"use strict";const w=t.defineComponent({name:"SlotTableColumn",props:{sticky:{type:String,default:""},align:{type:String,default:""},width:{type:String,default:""},minWidth:{type:String,default:""},visible:{type:Boolean,default:!0},tdClass:{type:[String,Object],default:void 0},thClass:{type:[String,Object],default:void 0}},setup(){return()=>null}}),T=t.defineComponent({name:"SlotTableColumnGroup",props:{sticky:{type:String,default:""},colspan:{type:Number,default:void 0}},setup(){return()=>null}}),K=t.defineComponent({name:"SlotTable",props:{rows:{type:Array,required:!0},tableClass:{type:String,default:""},rowKey:{type:[String,Function],default:void 0},rowClass:{type:[String,Object,Function],default:void 0},striped:{type:Boolean,default:!1},hoverable:{type:Boolean,default:!1},bordered:{type:Boolean,default:!1},loading:{type:Boolean,default:!1},stickyHeader:{type:Boolean,default:!1},caption:{type:String,default:""}},emits:["row-click","header-click","cell-click"],setup(s,{slots:y,emit:g}){function m(l){const e={};return l.width&&(e.width=l.width),(l["min-width"]||l.minWidth)&&(e.minWidth=l["min-width"]||l.minWidth),Object.keys(e).length>0?e:void 0}function C(l){const e=l.sticky||"",i=l.align||"";return{"sticky-left":e==="left","sticky-right":e==="right","align-left":i==="left","align-center":i==="center","align-right":i==="right"}}function S(l,e){return e?typeof e=="string"?{...l,[e]:!0}:{...l,...e}:l}function R(l,e){return s.rowKey?typeof s.rowKey=="function"?s.rowKey(l,e):l[s.rowKey]:e}function _(l,e){const i={};if(s.striped&&e%2===1&&(i["slot-table-striped"]=!0),s.hoverable&&(i["slot-table-hoverable"]=!0),!s.rowClass)return i;if(typeof s.rowClass=="function"){const r=s.rowClass(l,e);typeof r=="string"?i[r]=!0:typeof r=="object"&&Object.assign(i,r)}else typeof s.rowClass=="string"?i[s.rowClass]=!0:Object.assign(i,s.rowClass);return i}function F(l){const e=l.visible;return e===void 0||e===""||e===!0?!0:!!e}return()=>{const l=y.default?y.default():[],e=[],i=[];l.forEach(n=>{n.type===w?e.push(n):n.type===T&&i.push(n)});const r=e.filter(n=>F(n.props||{})),W=s.caption?t.h("caption",{class:"slot-table-caption"},s.caption):null,G=r.map((n,c)=>{const o=n.props||{},h=C(o),d=S(h,o.thClass||o["th-class"]),f=m(o),a=n.children&&n.children.header,p=typeof a=="function"?a():null;return t.h("th",{class:d,style:f,onClick:()=>g("header-click",c)},p)}),j=i.map(n=>{const c=n.props||{},o=c.sticky||"",h=c.colspan?Number(c.colspan):void 0,d={"sticky-left":o==="left","sticky-right":o==="right"},f=n.children&&n.children.default,a=typeof f=="function"?f():null;return t.h("th",{class:d,colspan:h},a)}),k=[];j.length>0&&k.push(t.h("tr",null,j)),k.push(t.h("tr",null,G));const H=s.stickyHeader?{"slot-table-sticky-header":!0}:void 0,V=t.h("thead",{class:H},k);let b;if(s.loading&&y.loading){const n=t.h("tr",null,[t.h("td",{colspan:r.length,class:"slot-table-loading"},y.loading())]);b=t.h("tbody",null,[n])}else if(s.rows.length===0&&y.empty){const n=t.h("tr",null,[t.h("td",{colspan:r.length,class:"slot-table-empty"},y.empty())]);b=t.h("tbody",null,[n])}else{const n=s.rows.map((c,o)=>{const h=r.map((d,f)=>{const a=d.props||{},p=C(a),$=S(p,a.tdClass||a["td-class"]),A=m(a),O=d.children&&d.children.cell,M=typeof O=="function"?O({row:c,rowIndex:o,columnIndex:f}):null;return t.h("td",{class:$,style:A,onClick:()=>g("cell-click",o,f,c)},M)});return t.h("tr",{key:R(c,o),class:_(c,o),onClick:()=>g("row-click",o,c)},h)});b=t.h("tbody",null,n)}const B=r.map((n,c)=>{const o=n.props||{},h=C(o),d=S(h,o.tdClass||o["td-class"]),f=m(o),a=n.children&&n.children.footer,p=typeof a=="function"?a():null;return t.h("td",{class:d,style:f},p)}),q=B.some(n=>n.children!==null)?t.h("tfoot",null,[t.h("tr",null,B)]):null,E={[s.tableClass]:!!s.tableClass,"slot-table-bordered":s.bordered},N=[W,V,b,q].filter(Boolean);return t.h("table",{class:E},N)}}});u.SlotTable=K,u.SlotTableColumn=w,u.SlotTableColumnGroup=T,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-slottable",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A flexible, slot-based Vue 3 table component with sticky columns, column groups, and scoped slots for custom cell rendering.",
|
|
5
5
|
"main": "./dist/vue-slottable.umd.js",
|
|
6
6
|
"module": "./dist/vue-slottable.mjs",
|