lkt-tabs 2.0.2 → 2.0.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/dist/build.js +84 -82
- package/package.json +1 -1
- package/src/lib-components/LktTabs.vue +29 -26
package/dist/build.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { TabType as
|
|
3
|
-
import { generateRandomString as
|
|
4
|
-
import { secondsToMilliseconds as
|
|
5
|
-
const
|
|
1
|
+
import { defineComponent as B, ref as _, computed as h, watch as y, createElementBlock as S, createCommentVNode as V, openBlock as u, unref as A, normalizeClass as b, renderSlot as $, Fragment as L, renderList as x, createBlock as g, resolveDynamicComponent as R, mergeProps as T, mergeDefaults as K, onMounted as I, resolveComponent as M, createElementVNode as N, withDirectives as U, withCtx as F, vShow as G } from "vue";
|
|
2
|
+
import { TabType as E, MenuEntryType as v, ButtonType as z, MenuType as j, getDefaultValues as q, Tabs as H } from "lkt-vue-kernel";
|
|
3
|
+
import { generateRandomString as D, trim as O } from "lkt-string-tools";
|
|
4
|
+
import { secondsToMilliseconds as J } from "lkt-date-tools";
|
|
5
|
+
const Y = ["id"], Q = /* @__PURE__ */ B({
|
|
6
6
|
__name: "LktTab",
|
|
7
7
|
props: {
|
|
8
8
|
tab: {},
|
|
@@ -10,26 +10,26 @@ const Q = ["id"], W = /* @__PURE__ */ E({
|
|
|
10
10
|
identifier: {}
|
|
11
11
|
},
|
|
12
12
|
setup(e) {
|
|
13
|
-
const t = e,
|
|
14
|
-
return
|
|
13
|
+
const t = e, s = D(8), r = _(t.isActive), l = h(() => t.tab.type === E.Always ? !0 : t.tab.type === E.Lazy ? r.value : t.isActive);
|
|
14
|
+
return y(() => t.isActive, (a) => {
|
|
15
15
|
a && (r.value = !0);
|
|
16
|
-
}), (a,
|
|
16
|
+
}), (a, d) => l.value ? (u(), S("section", {
|
|
17
17
|
key: 0,
|
|
18
|
-
class:
|
|
18
|
+
class: b(["lkt-tab--content", e.tab.containerClass]),
|
|
19
19
|
role: "tabpanel",
|
|
20
|
-
id: `lkt-tabs-${
|
|
20
|
+
id: `lkt-tabs-${A(s)}-${e.tab.key}`
|
|
21
21
|
}, [
|
|
22
|
-
(
|
|
22
|
+
(u(!0), S(L, null, x(e.tab.content, (i) => (u(), g(R(i.tag), T({
|
|
23
23
|
class: i.class
|
|
24
24
|
}, { ref_for: !0 }, i.props, {
|
|
25
25
|
modelValue: i.vModels.modelValue,
|
|
26
26
|
"onUpdate:modelValue": (n) => i.vModels.modelValue = n
|
|
27
27
|
}), null, 16, ["class", "modelValue", "onUpdate:modelValue"]))), 256)),
|
|
28
|
-
|
|
29
|
-
], 10,
|
|
28
|
+
$(a.$slots, "default")
|
|
29
|
+
], 10, Y)) : V("", !0);
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
|
-
class
|
|
32
|
+
class W {
|
|
33
33
|
constructor(t) {
|
|
34
34
|
t || (t = !0), this.value = t;
|
|
35
35
|
}
|
|
@@ -41,51 +41,51 @@ class c {
|
|
|
41
41
|
}
|
|
42
42
|
c.SUPPORTS_LOCAL_STORAGE = !1;
|
|
43
43
|
c.SUPPORTS_SESSION_STORAGE = !1;
|
|
44
|
-
c.COOKIE_FALLBACK = new
|
|
45
|
-
const
|
|
46
|
-
const r = /* @__PURE__ */ new Date(), l = r.getTime() +
|
|
44
|
+
c.COOKIE_FALLBACK = new W();
|
|
45
|
+
const X = (e, t, s) => {
|
|
46
|
+
const r = /* @__PURE__ */ new Date(), l = r.getTime() + J(s);
|
|
47
47
|
r.setTime(l);
|
|
48
48
|
const a = `expires=${r.toUTCString()}`;
|
|
49
49
|
document.cookie = `${e}=${t}, ${a}`;
|
|
50
|
-
},
|
|
51
|
-
const t = `${e}=`,
|
|
50
|
+
}, Z = (e) => {
|
|
51
|
+
const t = `${e}=`, s = document.cookie.split(","), r = document.cookie.split("expires="), l = O(r[1]);
|
|
52
52
|
let a = new Date(l);
|
|
53
53
|
if (l && (a = new Date(l)) && a < /* @__PURE__ */ new Date()) {
|
|
54
|
-
|
|
54
|
+
P(e);
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
|
-
for (let
|
|
58
|
-
const i =
|
|
57
|
+
for (let d = 0; d < s.length; d++) {
|
|
58
|
+
const i = O(s[d]);
|
|
59
59
|
if (i.indexOf(t) == 0)
|
|
60
60
|
return i.substring(t.length, i.length);
|
|
61
61
|
}
|
|
62
62
|
return "";
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
},
|
|
63
|
+
}, P = (e) => {
|
|
64
|
+
X(e, "", -1);
|
|
65
|
+
}, ee = (e) => {
|
|
66
66
|
if (!c.SUPPORTS_SESSION_STORAGE) {
|
|
67
67
|
if (!c.COOKIE_FALLBACK.enabled())
|
|
68
68
|
throw new Error("Browser doesn't support sessionStorage and cookies fallback is disabled");
|
|
69
|
-
return
|
|
69
|
+
return Z(e);
|
|
70
70
|
}
|
|
71
71
|
const t = JSON.parse(sessionStorage.getItem(e));
|
|
72
72
|
if (!t)
|
|
73
73
|
return;
|
|
74
|
-
const
|
|
74
|
+
const s = typeof t.expires == "string" && t.expires.length > 0;
|
|
75
75
|
let r;
|
|
76
|
-
if (
|
|
77
|
-
|
|
76
|
+
if (s && (r = new Date(t.expires)) && r < /* @__PURE__ */ new Date()) {
|
|
77
|
+
te(e);
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
80
|
return t.value;
|
|
81
|
-
},
|
|
81
|
+
}, te = (e) => {
|
|
82
82
|
if (!c.SUPPORTS_SESSION_STORAGE) {
|
|
83
83
|
if (!c.COOKIE_FALLBACK.enabled())
|
|
84
84
|
throw new Error("Browser doesn't support sessionStorage and cookies fallback is disabled");
|
|
85
|
-
return
|
|
85
|
+
return P(e);
|
|
86
86
|
}
|
|
87
87
|
return sessionStorage.removeItem(e);
|
|
88
|
-
},
|
|
88
|
+
}, se = (e) => `lkt-tabs.${window.location.host}${window.location.pathname}.${e}`, oe = (e) => ee(se(e)), ne = /* @__PURE__ */ B({
|
|
89
89
|
__name: "LktTabs",
|
|
90
90
|
props: /* @__PURE__ */ K({
|
|
91
91
|
modelValue: {},
|
|
@@ -98,91 +98,93 @@ const Z = (e, t, o) => {
|
|
|
98
98
|
navStartButtons: {},
|
|
99
99
|
navEndButtons: {},
|
|
100
100
|
navPostEndButtonsElements: {}
|
|
101
|
-
}, H
|
|
101
|
+
}, q(H)),
|
|
102
102
|
emits: [
|
|
103
103
|
"update:modelValue"
|
|
104
104
|
],
|
|
105
105
|
setup(e, { emit: t }) {
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
let n =
|
|
106
|
+
const s = e, r = t, l = D(8), a = _("");
|
|
107
|
+
if (s.useSession) {
|
|
108
|
+
s.id || console.warn("[LKT Tabs] You're trying to use session provided tabs without the required id. Please, add id attr");
|
|
109
|
+
let n = oe(s.id);
|
|
110
110
|
n && (a.value = n);
|
|
111
111
|
}
|
|
112
|
-
|
|
112
|
+
y(() => s.modelValue, (n, f) => {
|
|
113
113
|
typeof n == "string" && (a.value = n);
|
|
114
|
-
}),
|
|
114
|
+
}), y(a, (n, f) => {
|
|
115
115
|
r("update:modelValue", n);
|
|
116
116
|
});
|
|
117
|
-
const
|
|
117
|
+
const d = h(() => {
|
|
118
118
|
let n = [];
|
|
119
|
-
return
|
|
120
|
-
}), i =
|
|
121
|
-
var
|
|
119
|
+
return s.class && n.push(s.class), n.join(" ");
|
|
120
|
+
}), i = h(() => {
|
|
121
|
+
var f, k;
|
|
122
122
|
let n = [];
|
|
123
|
-
return (
|
|
123
|
+
return (f = s.navStartButtons) == null || f.forEach((o) => {
|
|
124
124
|
n.push({
|
|
125
|
-
type:
|
|
126
|
-
button:
|
|
125
|
+
type: v.Button,
|
|
126
|
+
button: o
|
|
127
127
|
});
|
|
128
|
-
}),
|
|
129
|
-
const
|
|
128
|
+
}), s.tabs.length > 1 && s.tabs.map((o) => {
|
|
129
|
+
const m = a.value === o.key;
|
|
130
130
|
return {
|
|
131
|
-
key:
|
|
132
|
-
type:
|
|
131
|
+
key: o.key,
|
|
132
|
+
type: v.Button,
|
|
133
133
|
button: {
|
|
134
|
-
...
|
|
135
|
-
type:
|
|
136
|
-
text:
|
|
137
|
-
class:
|
|
134
|
+
...o.button,
|
|
135
|
+
type: z.Tab,
|
|
136
|
+
text: o.button.text ?? o.key,
|
|
137
|
+
class: m ? "is-active-tab" : "",
|
|
138
138
|
anchor: {
|
|
139
|
-
to:
|
|
139
|
+
to: o.hash ? `#${o.hash}` : void 0
|
|
140
140
|
},
|
|
141
141
|
aria: {
|
|
142
|
-
controls: `lkt-tabs-${l}-${
|
|
143
|
-
selected:
|
|
142
|
+
controls: `lkt-tabs-${l}-${o.key}`,
|
|
143
|
+
selected: m
|
|
144
144
|
},
|
|
145
145
|
events: {
|
|
146
|
-
click: (
|
|
147
|
-
var
|
|
148
|
-
typeof ((
|
|
146
|
+
click: (p) => {
|
|
147
|
+
var w, C;
|
|
148
|
+
typeof ((w = o.button.events) == null ? void 0 : w.click) == "function" && ((C = o.button.events) == null || C.click(p)), a.value = o.key;
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
};
|
|
153
|
-
}).forEach((
|
|
153
|
+
}).forEach((o) => n.push(o)), (k = s.navEndButtons) == null || k.forEach((o) => {
|
|
154
154
|
n.push({
|
|
155
|
-
type:
|
|
156
|
-
button:
|
|
155
|
+
type: v.Button,
|
|
156
|
+
button: o
|
|
157
157
|
});
|
|
158
158
|
}), {
|
|
159
|
-
menuKey: `tabs-menu-${
|
|
160
|
-
type:
|
|
161
|
-
modelValue: n
|
|
159
|
+
menuKey: `tabs-menu-${s.id}`,
|
|
160
|
+
type: j.TabList,
|
|
161
|
+
modelValue: n,
|
|
162
|
+
renderOutside: !1
|
|
162
163
|
};
|
|
163
164
|
});
|
|
164
165
|
return I(() => {
|
|
165
|
-
!a.value &&
|
|
166
|
-
}), (n,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
166
|
+
!a.value && s.tabs.length > 0 && (a.value = s.tabs[0].key);
|
|
167
|
+
}), (n, f) => {
|
|
168
|
+
var o, m;
|
|
169
|
+
const k = M("lkt-menu");
|
|
170
|
+
return u(), S("div", {
|
|
171
|
+
class: b(["lkt-tabs", d.value])
|
|
170
172
|
}, [
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
class:
|
|
173
|
+
((m = (o = i.value) == null ? void 0 : o.modelValue) == null ? void 0 : m.length) > 0 ? (u(), g(k, T({ key: 0 }, i.value, { class: "lkt-tabs--list" }), null, 16)) : V("", !0),
|
|
174
|
+
N("div", {
|
|
175
|
+
class: b(["lkt-tabs--content", e.contentClass])
|
|
174
176
|
}, [
|
|
175
|
-
(
|
|
176
|
-
tab:
|
|
177
|
-
isActive: a.value ===
|
|
178
|
-
identifier:
|
|
177
|
+
(u(!0), S(L, null, x(e.tabs, (p) => U((u(), g(Q, T({ ref_for: !0 }, {
|
|
178
|
+
tab: p,
|
|
179
|
+
isActive: a.value === p.key,
|
|
180
|
+
identifier: A(l)
|
|
179
181
|
}), {
|
|
180
|
-
default:
|
|
181
|
-
|
|
182
|
+
default: F(() => [
|
|
183
|
+
$(n.$slots, "tab-" + p.key)
|
|
182
184
|
]),
|
|
183
185
|
_: 2
|
|
184
186
|
}, 1040)), [
|
|
185
|
-
[
|
|
187
|
+
[G, a.value === p.key]
|
|
186
188
|
])), 256))
|
|
187
189
|
], 2)
|
|
188
190
|
], 2);
|
|
@@ -190,7 +192,7 @@ const Z = (e, t, o) => {
|
|
|
190
192
|
}
|
|
191
193
|
}), ue = {
|
|
192
194
|
install: (e, t) => {
|
|
193
|
-
e.component("lkt-tabs",
|
|
195
|
+
e.component("lkt-tabs", ne);
|
|
194
196
|
}
|
|
195
197
|
};
|
|
196
198
|
export {
|
package/package.json
CHANGED
|
@@ -63,35 +63,37 @@ const computedMenuConfig = computed(() => {
|
|
|
63
63
|
})
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
props.tabs.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
tab.button.events?.click
|
|
66
|
+
if (props.tabs.length > 1){
|
|
67
|
+
props.tabs.map((tab: TabConfig) => {
|
|
68
|
+
const selected = Value.value === tab.key;
|
|
69
|
+
return <MenuEntryConfig>{
|
|
70
|
+
key: tab.key,
|
|
71
|
+
type: MenuEntryType.Button,
|
|
72
|
+
button: {
|
|
73
|
+
...tab.button,
|
|
74
|
+
type: ButtonType.Tab,
|
|
75
|
+
text: tab.button.text ?? tab.key,
|
|
76
|
+
class: selected ? 'is-active-tab' : '',
|
|
77
|
+
anchor: {
|
|
78
|
+
to: tab.hash ? `#${tab.hash}` : undefined
|
|
79
|
+
},
|
|
80
|
+
aria: {
|
|
81
|
+
controls: `lkt-tabs-${identifier}-${tab.key}`,
|
|
82
|
+
selected,
|
|
83
|
+
},
|
|
84
|
+
events: {
|
|
85
|
+
click: (args: ClickEventArgs) => {
|
|
86
|
+
if (typeof tab.button.events?.click === 'function') {
|
|
87
|
+
tab.button.events?.click(args);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Value.value = tab.key;
|
|
87
91
|
}
|
|
88
|
-
|
|
89
|
-
Value.value = tab.key;
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
+
}).forEach(entry => modelValue.push(entry));
|
|
96
|
+
}
|
|
95
97
|
|
|
96
98
|
props.navEndButtons?.forEach(button => {
|
|
97
99
|
modelValue.push({
|
|
@@ -105,6 +107,7 @@ const computedMenuConfig = computed(() => {
|
|
|
105
107
|
menuKey: `tabs-menu-${props.id}`,
|
|
106
108
|
type: MenuType.TabList,
|
|
107
109
|
modelValue,
|
|
110
|
+
renderOutside: false,
|
|
108
111
|
}
|
|
109
112
|
})
|
|
110
113
|
|
|
@@ -118,7 +121,7 @@ onMounted(() => {
|
|
|
118
121
|
|
|
119
122
|
<template>
|
|
120
123
|
<div class="lkt-tabs" v-bind:class="classes">
|
|
121
|
-
<lkt-menu v-bind="computedMenuConfig" class="lkt-tabs--list"/>
|
|
124
|
+
<lkt-menu v-if="computedMenuConfig?.modelValue?.length > 0" v-bind="computedMenuConfig" class="lkt-tabs--list"/>
|
|
122
125
|
<div class="lkt-tabs--content" :class="contentClass">
|
|
123
126
|
<template v-for="tab in tabs">
|
|
124
127
|
<lkt-tab
|