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