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 CHANGED
@@ -1,8 +1,8 @@
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 _, Fragment as V, 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({
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, 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, (a) => {
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, u) => l.value ? (d(), m("section", {
16
+ }), (a, d) => l.value ? (u(), S("section", {
17
17
  key: 0,
18
- class: y(["lkt-tab--content", e.tab.containerClass]),
18
+ class: b(["lkt-tab--content", e.tab.containerClass]),
19
19
  role: "tabpanel",
20
- id: `lkt-tabs-${B(o)}-${e.tab.key}`
20
+ id: `lkt-tabs-${A(s)}-${e.tab.key}`
21
21
  }, [
22
- (d(!0), m(V, null, A(e.tab.content, (i) => (d(), $(R(i.tag), h({
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
- _(a.$slots, "default")
29
- ], 10, Q)) : P("", !0);
28
+ $(a.$slots, "default")
29
+ ], 10, Y)) : V("", !0);
30
30
  }
31
31
  });
32
- class X {
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 X();
45
- const Z = (e, t, o) => {
46
- const r = /* @__PURE__ */ new Date(), l = r.getTime() + Y(o);
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
- }, ee = (e) => {
51
- const t = `${e}=`, o = document.cookie.split(","), r = document.cookie.split("expires="), l = C(r[1]);
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
- x(e);
54
+ P(e);
55
55
  return;
56
56
  }
57
- for (let u = 0; u < o.length; u++) {
58
- const i = C(o[u]);
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
- }, x = (e) => {
64
- Z(e, "", -1);
65
- }, te = (e) => {
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 ee(e);
69
+ return Z(e);
70
70
  }
71
71
  const t = JSON.parse(sessionStorage.getItem(e));
72
72
  if (!t)
73
73
  return;
74
- const o = typeof t.expires == "string" && t.expires.length > 0;
74
+ const s = typeof t.expires == "string" && t.expires.length > 0;
75
75
  let r;
76
- if (o && (r = new Date(t.expires)) && r < /* @__PURE__ */ new Date()) {
77
- se(e);
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
- }, se = (e) => {
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 x(e);
85
+ return P(e);
86
86
  }
87
87
  return sessionStorage.removeItem(e);
88
- }, oe = (e) => `lkt-tabs.${window.location.host}${window.location.pathname}.${e}`, ne = (e) => te(oe(e)), ae = /* @__PURE__ */ E({
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(J)),
101
+ }, q(H)),
102
102
  emits: [
103
103
  "update:modelValue"
104
104
  ],
105
105
  setup(e, { emit: t }) {
106
- const o = e, r = t, l = L(8), a = 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 n = ne(o.id);
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
- v(() => o.modelValue, (n, p) => {
112
+ y(() => s.modelValue, (n, f) => {
113
113
  typeof n == "string" && (a.value = n);
114
- }), v(a, (n, p) => {
114
+ }), y(a, (n, f) => {
115
115
  r("update:modelValue", n);
116
116
  });
117
- const u = k(() => {
117
+ const d = h(() => {
118
118
  let n = [];
119
- return o.class && n.push(o.class), n.join(" ");
120
- }), i = k(() => {
121
- var p, f;
119
+ return s.class && n.push(s.class), n.join(" ");
120
+ }), i = h(() => {
121
+ var f, k;
122
122
  let n = [];
123
- return (p = o.navStartButtons) == null || p.forEach((s) => {
123
+ return (f = s.navStartButtons) == null || f.forEach((o) => {
124
124
  n.push({
125
- type: S.Button,
126
- button: s
125
+ type: v.Button,
126
+ button: o
127
127
  });
128
- }), o.tabs.map((s) => {
129
- const b = a.value === s.key;
128
+ }), s.tabs.length > 1 && s.tabs.map((o) => {
129
+ const m = a.value === o.key;
130
130
  return {
131
- key: s.key,
132
- type: S.Button,
131
+ key: o.key,
132
+ type: v.Button,
133
133
  button: {
134
- ...s.button,
135
- type: j.Tab,
136
- text: s.button.text ?? s.key,
137
- class: b ? "is-active-tab" : "",
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: s.hash ? `#${s.hash}` : void 0
139
+ to: o.hash ? `#${o.hash}` : void 0
140
140
  },
141
141
  aria: {
142
- controls: `lkt-tabs-${l}-${s.key}`,
143
- selected: b
142
+ controls: `lkt-tabs-${l}-${o.key}`,
143
+ selected: m
144
144
  },
145
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)), a.value = s.key;
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((s) => n.push(s)), (f = o.navEndButtons) == null || f.forEach((s) => {
153
+ }).forEach((o) => n.push(o)), (k = s.navEndButtons) == null || k.forEach((o) => {
154
154
  n.push({
155
- type: S.Button,
156
- button: s
155
+ type: v.Button,
156
+ button: o
157
157
  });
158
158
  }), {
159
- menuKey: `tabs-menu-${o.id}`,
160
- type: q.TabList,
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 && o.tabs.length > 0 && (a.value = o.tabs[0].key);
166
- }), (n, p) => {
167
- const f = N("lkt-menu");
168
- return d(), m("div", {
169
- class: y(["lkt-tabs", u.value])
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
- M(f, h(i.value, { class: "lkt-tabs--list" }), null, 16),
172
- U("div", {
173
- class: y(["lkt-tabs--content", e.contentClass])
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
- (d(!0), m(V, null, A(e.tabs, (s) => F((d(), $(W, h({ ref_for: !0 }, {
176
- tab: s,
177
- isActive: a.value === s.key,
178
- identifier: B(l)
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: G(() => [
181
- _(n.$slots, "tab-" + s.key)
182
+ default: F(() => [
183
+ $(n.$slots, "tab-" + p.key)
182
184
  ]),
183
185
  _: 2
184
186
  }, 1040)), [
185
- [z, a.value === s.key]
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", ae);
195
+ e.component("lkt-tabs", ne);
194
196
  }
195
197
  };
196
198
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "lkt-tabs",
3
3
  "type": "module",
4
- "version": "2.0.2",
4
+ "version": "2.0.4",
5
5
  "description": "",
6
6
  "sideEffects": false,
7
7
  "module": "./dist/build.js",
@@ -63,35 +63,37 @@ const computedMenuConfig = computed(() => {
63
63
  })
64
64
  });
65
65
 
66
- props.tabs.map((tab: TabConfig) => {
67
- const selected = Value.value === tab.key;
68
- return <MenuEntryConfig>{
69
- key: tab.key,
70
- type: MenuEntryType.Button,
71
- button: {
72
- ...tab.button,
73
- type: ButtonType.Tab,
74
- text: tab.button.text ?? tab.key,
75
- class: selected ? 'is-active-tab' : '',
76
- anchor: {
77
- to: tab.hash ? `#${tab.hash}` : undefined
78
- },
79
- aria: {
80
- controls: `lkt-tabs-${identifier}-${tab.key}`,
81
- selected,
82
- },
83
- events: {
84
- click: (args: ClickEventArgs) => {
85
- if (typeof tab.button.events?.click === 'function') {
86
- tab.button.events?.click(args);
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
- }).forEach(entry => modelValue.push(entry));
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