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 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 { ie as default };
2
- declare namespace ie {
3
- function install(e: any, o: any): void;
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 T, createElementBlock as f, openBlock as l, unref as w, renderSlot as E, Fragment as S, renderList as O, createBlock as C, resolveDynamicComponent as x, mergeProps as h, mergeDefaults as A, ref as V, watch as b, computed as v, onMounted as D, resolveComponent as P, normalizeClass as K, createVNode as R, createElementVNode as I, createCommentVNode as N, withCtx as F } from "vue";
2
- import { generateRandomString as B, trim as _ } from "lkt-string-tools";
3
- import { secondsToMilliseconds as M } from "lkt-date-tools";
4
- import { MenuEntryType as k, ButtonType as U, MenuType as G, getDefaultValues as j, Tabs as q } from "lkt-vue-kernel";
5
- const z = ["id"], H = /* @__PURE__ */ T({
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 = B(8);
14
- return (s, i) => (l(), f("section", {
15
- class: "lkt-tab--content",
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-${w(o)}-${e.tab.key}`
20
+ id: `lkt-tabs-${B(o)}-${e.tab.key}`
18
21
  }, [
19
- (l(!0), f(S, null, O(e.tab.content, (a) => (l(), C(x(a.tag), h({
20
- class: a.class
21
- }, { ref_for: !0 }, a.props), null, 16, ["class"]))), 256)),
22
- E(s.$slots, "default")
23
- ], 8, z));
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 J {
27
- constructor(o) {
28
- o || (o = !0), this.value = o;
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 J();
39
- const Y = (e, o, s) => {
40
- const i = /* @__PURE__ */ new Date(), a = i.getTime() + M(s);
41
- i.setTime(a);
42
- const r = `expires=${i.toUTCString()}`;
43
- document.cookie = `${e}=${o}, ${r}`;
44
- }, Q = (e) => {
45
- const o = `${e}=`, s = document.cookie.split(","), i = document.cookie.split("expires="), a = _(i[1]);
46
- let r = new Date(a);
47
- if (a && (r = new Date(a)) && r < /* @__PURE__ */ new Date()) {
48
- $(e);
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 < s.length; u++) {
52
- const d = _(s[u]);
53
- if (d.indexOf(o) == 0)
54
- return d.substring(o.length, d.length);
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
- }, $ = (e) => {
58
- Y(e, "", -1);
59
- }, W = (e) => {
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 Q(e);
69
+ return ee(e);
64
70
  }
65
- const o = JSON.parse(sessionStorage.getItem(e));
66
- if (!o)
71
+ const t = JSON.parse(sessionStorage.getItem(e));
72
+ if (!t)
67
73
  return;
68
- const s = typeof o.expires == "string" && o.expires.length > 0;
69
- let i;
70
- if (s && (i = new Date(o.expires)) && i < /* @__PURE__ */ new Date()) {
71
- X(e);
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 o.value;
75
- }, X = (e) => {
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 $(e);
85
+ return x(e);
80
86
  }
81
87
  return sessionStorage.removeItem(e);
82
- }, Z = (e) => `lkt-tabs.${window.location.host}${window.location.pathname}.${e}`, ee = (e) => W(Z(e)), te = { class: "lkt-tabs--content" }, se = /* @__PURE__ */ T({
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__ */ A({
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
- }, j(q)),
99
+ navEndButtons: {},
100
+ navPostEndButtonsElements: {}
101
+ }, H(J)),
94
102
  emits: [
95
103
  "update:modelValue"
96
104
  ],
97
- setup(e, { emit: o }) {
98
- const s = e, i = o, a = B(8), r = V("");
99
- if (s.useSession) {
100
- s.id || console.warn("[LKT Tabs] You're trying to use session provided tabs without the required id. Please, add id attr");
101
- let n = ee(s.id);
102
- n && (r.value = n);
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
- b(() => s.modelValue, (n, p) => {
105
- typeof n == "string" && (r.value = n);
106
- }), b(r, (n, p) => {
107
- i("update:modelValue");
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 = v(() => {
110
- let n = [];
111
- return s.class && n.push(s.class), n.join(" ");
112
- }), d = v(() => {
113
- var p, m;
114
- let n = [];
115
- return (p = s.navStartButtons) == null || p.forEach((t) => {
116
- n.push({
117
- type: k.Button,
118
- button: t
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
- }), s.tabs.map((t) => ({
121
- key: t.key,
122
- type: k.Button,
123
- button: {
124
- ...t.button,
125
- type: U.Tab,
126
- text: t.button.text ?? t.key,
127
- anchor: {
128
- to: t.hash ? `#${t.hash}` : void 0
129
- },
130
- aria: {
131
- controls: `lkt-tabs-${a}-${t.key}`,
132
- selected: r.value === t.key
133
- },
134
- events: {
135
- click: (L) => {
136
- var g, y;
137
- typeof ((g = t.button.events) == null ? void 0 : g.click) == "function" && ((y = t.button.events) == null || y.click(L)), r.value = t.key;
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
- })).forEach((t) => n.push(t)), (m = s.navEndButtons) == null || m.forEach((t) => {
142
- n.push({
143
- type: k.Button,
144
- button: t
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-${s.id}`,
148
- type: G.TabList,
149
- modelValue: n
159
+ menuKey: `tabs-menu-${o.id}`,
160
+ type: q.TabList,
161
+ modelValue: a
150
162
  };
151
163
  });
152
- return D(() => {
153
- !r.value && s.tabs.length > 0 && (r.value = s.tabs[0].key);
154
- }), (n, p) => {
155
- const m = P("lkt-menu");
156
- return l(), f("div", {
157
- class: K(["lkt-tabs", u.value])
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
- R(m, h(d.value, { class: "lkt-tabs--list" }), null, 16),
160
- I("div", te, [
161
- (l(!0), f(S, null, O(e.tabs, (t) => (l(), f(S, null, [
162
- r.value === t.key ? (l(), C(H, h({
163
- key: 0,
164
- ref_for: !0
165
- }, {
166
- tab: t,
167
- isActive: r.value === t.key,
168
- identifier: w(a)
169
- }), {
170
- default: F(() => [
171
- E(n.$slots, "tab-" + t.key)
172
- ]),
173
- _: 2
174
- }, 1040)) : N("", !0)
175
- ], 64))), 256))
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
- }), ie = {
181
- install: (e, o) => {
182
- e.component("lkt-tabs", se);
191
+ }), ue = {
192
+ install: (e, t) => {
193
+ e.component("lkt-tabs", ae);
183
194
  }
184
195
  };
185
196
  export {
186
- ie as default
197
+ ue as default
187
198
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lkt-tabs",
3
3
  "type": "module",
4
- "version": "2.0.0",
4
+ "version": "2.0.1",
5
5
  "description": "",
6
6
  "sideEffects": false,
7
7
  "module": "./dist/build.js",
@@ -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
- <component
22
- v-for="element in tab.content"
23
- :is="element.tag"
24
- :class="element.class"
25
- v-bind="element.props"
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: Value.value === tab.key,
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-if="Value === tab.key"
125
+ v-show="Value === tab.key"
124
126
  v-bind="{
125
127
  tab,
126
128
  isActive: Value === tab.key,