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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![CI](https://github.com/muraliavarma/vue-slot-table/actions/workflows/ci.yml/badge.svg)](https://github.com/muraliavarma/vue-slot-table/actions/workflows/ci.yml)
4
4
  [![npm version](https://img.shields.io/npm/v/vue-slottable.svg)](https://www.npmjs.com/package/vue-slottable)
5
- [![license](https://img.shields.io/npm/l/vue-slottable.svg)](./LICENSE.txt)
5
+ [![license](https://img.shields.io/github/license/muraliavarma/vue-slot-table.svg)](./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.txt)
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}
@@ -1,5 +1,5 @@
1
- import { defineComponent as b, h as i } from "vue";
2
- const W = b({
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
- }), B = b({
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
- }), F = b({
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(e, { slots: y, emit: g }) {
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 C(n) {
79
- const t = n.sticky || "", s = n.align || "";
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": s === "left",
84
- "align-center": s === "center",
85
- "align-right": s === "right"
107
+ "align-left": a === "left",
108
+ "align-center": a === "center",
109
+ "align-right": a === "right"
86
110
  };
87
111
  }
88
- function S(n, t) {
89
- return e.rowKey ? typeof e.rowKey == "function" ? e.rowKey(n, t) : n[e.rowKey] : t;
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
- const s = {};
93
- if (e.striped && t % 2 === 1 && (s["slot-table-striped"] = !0), e.hoverable && (s["slot-table-hoverable"] = !0), !e.rowClass) return s;
94
- if (typeof e.rowClass == "function") {
95
- const u = e.rowClass(n, t);
96
- typeof u == "string" ? s[u] = !0 : typeof u == "object" && Object.assign(s, u);
97
- } else typeof e.rowClass == "string" ? s[e.rowClass] = !0 : Object.assign(s, e.rowClass);
98
- return s;
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 = [], s = [];
102
- n.forEach((l) => {
103
- l.type === W ? t.push(l) : l.type === B && s.push(l);
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 u = t.map((l, a) => {
106
- const c = l.props || {}, d = C(c), o = p(c), r = l.children && l.children.header, f = typeof r == "function" ? r() : null;
107
- return i("th", {
108
- class: d,
109
- style: o,
110
- onClick: () => g("header-click", a)
111
- }, f);
112
- }), w = s.map((l) => {
113
- const a = l.props || {}, c = a.sticky || "", d = a.colspan ? Number(a.colspan) : void 0, o = {
114
- "sticky-left": c === "left",
115
- "sticky-right": c === "right"
116
- }, r = l.children && l.children.default, f = typeof r == "function" ? r() : null;
117
- return i("th", { class: o, colspan: d }, f);
118
- }), h = [];
119
- w.length > 0 && h.push(i("tr", null, w)), h.push(i("tr", null, u));
120
- const T = i("thead", null, h);
121
- let m;
122
- if (e.rows.length === 0 && y.empty) {
123
- const l = i("tr", null, [
124
- i("td", { colspan: t.length, class: "slot-table-empty" }, y.empty())
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
- m = i("tbody", null, [l]);
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 l = e.rows.map((a, c) => {
129
- const d = t.map((o, r) => {
130
- const f = o.props || {}, j = C(f), R = p(f), k = o.children && o.children.cell, O = typeof k == "function" ? k({ row: a, rowIndex: c, columnIndex: r }) : null;
131
- return i("td", { class: j, style: R }, O);
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 i("tr", {
134
- key: S(a, c),
135
- class: K(a, c),
136
- onClick: () => g("row-click", c, a)
137
- }, d);
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
- m = i("tbody", null, l);
179
+ g = s("tbody", null, e);
140
180
  }
141
- const _ = {
142
- [e.tableClass]: !!e.tableClass,
143
- "slot-table-bordered": e.bordered
144
- };
145
- return i("table", { class: _ }, [T, m]);
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
- F as SlotTable,
151
- W as SlotTableColumn,
152
- B as SlotTableColumnGroup
193
+ D as SlotTable,
194
+ q as SlotTableColumn,
195
+ A as SlotTableColumnGroup
153
196
  };
@@ -1 +1 @@
1
- (function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.VueSlotTable={},a.Vue))})(this,function(a,t){"use strict";const p=t.defineComponent({name:"SlotTableColumn",props:{sticky:{type:String,default:""},align:{type:String,default:""},width:{type:String,default:""},minWidth:{type:String,default:""}},setup(){return()=>null}}),g=t.defineComponent({name:"SlotTableColumnGroup",props:{sticky:{type:String,default:""},colspan:{type:Number,default:void 0}},setup(){return()=>null}}),j=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}},emits:["row-click","header-click"],setup(n,{slots:y,emit:C}){function S(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 w(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 K(l,e){return n.rowKey?typeof n.rowKey=="function"?n.rowKey(l,e):l[n.rowKey]:e}function _(l,e){const i={};if(n.striped&&e%2===1&&(i["slot-table-striped"]=!0),n.hoverable&&(i["slot-table-hoverable"]=!0),!n.rowClass)return i;if(typeof n.rowClass=="function"){const f=n.rowClass(l,e);typeof f=="string"?i[f]=!0:typeof f=="object"&&Object.assign(i,f)}else typeof n.rowClass=="string"?i[n.rowClass]=!0:Object.assign(i,n.rowClass);return i}return()=>{const l=y.default?y.default():[],e=[],i=[];l.forEach(s=>{s.type===p?e.push(s):s.type===g&&i.push(s)});const f=e.map((s,o)=>{const c=s.props||{},h=w(c),r=S(c),u=s.children&&s.children.header,d=typeof u=="function"?u():null;return t.h("th",{class:h,style:r,onClick:()=>C("header-click",o)},d)}),k=i.map(s=>{const o=s.props||{},c=o.sticky||"",h=o.colspan?Number(o.colspan):void 0,r={"sticky-left":c==="left","sticky-right":c==="right"},u=s.children&&s.children.default,d=typeof u=="function"?u():null;return t.h("th",{class:r,colspan:h},d)}),m=[];k.length>0&&m.push(t.h("tr",null,k)),m.push(t.h("tr",null,f));const O=t.h("thead",null,m);let b;if(n.rows.length===0&&y.empty){const s=t.h("tr",null,[t.h("td",{colspan:e.length,class:"slot-table-empty"},y.empty())]);b=t.h("tbody",null,[s])}else{const s=n.rows.map((o,c)=>{const h=e.map((r,u)=>{const d=r.props||{},W=w(d),B=S(d),T=r.children&&r.children.cell,G=typeof T=="function"?T({row:o,rowIndex:c,columnIndex:u}):null;return t.h("td",{class:W,style:B},G)});return t.h("tr",{key:K(o,c),class:_(o,c),onClick:()=>C("row-click",c,o)},h)});b=t.h("tbody",null,s)}const R={[n.tableClass]:!!n.tableClass,"slot-table-bordered":n.bordered};return t.h("table",{class:R},[O,b])}}});a.SlotTable=j,a.SlotTableColumn=p,a.SlotTableColumnGroup=g,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
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.1.0",
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",