lkt-menu 1.0.3 → 1.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.d.ts +12 -11
- package/dist/build.js +110 -90
- package/dist/index.d.ts +2 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/MenuItem.vue +30 -3
package/dist/build.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare function
|
|
1
|
+
declare function he(n: any, t: any, s: any): {
|
|
2
2
|
key: any;
|
|
3
3
|
href: any;
|
|
4
4
|
label: any;
|
|
@@ -6,21 +6,22 @@ declare function se(n: any, t: any, l: any): {
|
|
|
6
6
|
isOpened: boolean;
|
|
7
7
|
isActive: boolean;
|
|
8
8
|
children: any[];
|
|
9
|
-
setChildren: (t: any) =>
|
|
10
|
-
setOnClick: (t: any) =>
|
|
9
|
+
setChildren: (t: any) => T;
|
|
10
|
+
setOnClick: (t: any) => T;
|
|
11
11
|
onClick: any;
|
|
12
|
-
setIsActiveChecker: (t: any) =>
|
|
12
|
+
setIsActiveChecker: (t: any) => T;
|
|
13
13
|
isActiveChecker: any;
|
|
14
|
-
setIsActive: (t?: boolean) =>
|
|
15
|
-
setLabel: (t: any) =>
|
|
16
|
-
setIcon: (t: any) =>
|
|
14
|
+
setIsActive: (t?: boolean) => T;
|
|
15
|
+
setLabel: (t: any) => T;
|
|
16
|
+
setIcon: (t: any) => T;
|
|
17
17
|
doClose: () => void;
|
|
18
18
|
};
|
|
19
|
-
declare namespace
|
|
19
|
+
declare namespace ve {
|
|
20
20
|
function install(n: any): void;
|
|
21
21
|
}
|
|
22
|
-
declare
|
|
23
|
-
|
|
22
|
+
declare function me(n: any): boolean;
|
|
23
|
+
declare class T {
|
|
24
|
+
constructor(t: any, s: any, v: any);
|
|
24
25
|
key: any;
|
|
25
26
|
href: any;
|
|
26
27
|
label: any;
|
|
@@ -38,4 +39,4 @@ declare class K {
|
|
|
38
39
|
setIcon(t: any): this;
|
|
39
40
|
doClose(): void;
|
|
40
41
|
}
|
|
41
|
-
export {
|
|
42
|
+
export { he as createMenuEntry, ve as default, me as setMenuToggleSlot };
|
package/dist/build.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { __ as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { defineComponent as R, ref as U, useSlots as B, computed as i, watch as g, onMounted as q, resolveComponent as w, openBlock as u, createElementBlock as a, normalizeClass as _, createElementVNode as C, createVNode as G, withCtx as E, unref as H, renderSlot as I, createCommentVNode as m, toDisplayString as J, createBlock as M, resolveDynamicComponent as P, Fragment as K, renderList as V, createSlots as N, reactive as Q } from "vue";
|
|
2
|
+
import { __ as X } from "lkt-i18n";
|
|
3
|
+
import { useRouter as Y } from "vue-router";
|
|
4
|
+
class T {
|
|
5
|
+
constructor(t, s, v) {
|
|
6
|
+
this.key = "", this.href = "", this.label = "", this.icon = "", this.onClick = void 0, this.isActiveChecker = void 0, this.isOpened = !1, this.isActive = !1, this.parent = void 0, this.children = [], this.key = t, this.href = s, this.label = v;
|
|
6
7
|
}
|
|
7
8
|
setChildren(t) {
|
|
8
|
-
return t.forEach((
|
|
9
|
+
return t.forEach((s) => s.parent = this), this.children = t, this;
|
|
9
10
|
}
|
|
10
11
|
setOnClick(t) {
|
|
11
12
|
return this.onClick = t, this;
|
|
@@ -26,138 +27,157 @@ class K {
|
|
|
26
27
|
this.isOpened = !1;
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
const
|
|
30
|
-
n.includes(
|
|
31
|
-
}), n),
|
|
30
|
+
const $ = (n, t) => (t.forEach((s) => {
|
|
31
|
+
n.includes(s.key) || n.push(s.key), s.children.length > 0 && $(n, s.children);
|
|
32
|
+
}), n), b = class b {
|
|
33
|
+
};
|
|
34
|
+
b.toggleSlot = "", b.debugEnabled = !1;
|
|
35
|
+
let k = b;
|
|
36
|
+
const Z = { class: "lkt-menu-entry-main" }, ee = { class: "lkt-entry-content" }, te = {
|
|
32
37
|
key: 0,
|
|
33
38
|
class: "lkt-menu-entry-icon"
|
|
34
|
-
},
|
|
39
|
+
}, le = {
|
|
35
40
|
key: 1,
|
|
36
41
|
class: "lkt-menu-entry-text"
|
|
37
|
-
},
|
|
42
|
+
}, ne = {
|
|
38
43
|
key: 0,
|
|
39
44
|
class: "lkt-menu-entry-children"
|
|
40
|
-
},
|
|
45
|
+
}, se = /* @__PURE__ */ R({
|
|
41
46
|
__name: "MenuItem",
|
|
42
47
|
props: {
|
|
43
|
-
modelValue: { default: () => new
|
|
48
|
+
modelValue: { default: () => new T("", "", "") }
|
|
44
49
|
},
|
|
45
50
|
emits: ["update:modelValue"],
|
|
46
51
|
setup(n, { emit: t }) {
|
|
47
|
-
const
|
|
52
|
+
const s = t, v = n, e = U(v.modelValue), r = B(), A = Y(), p = () => {
|
|
48
53
|
e.value.isOpened = !e.value.isOpened;
|
|
49
|
-
},
|
|
54
|
+
}, o = () => (e.value.children.length > 0 && p(), typeof e.value.onClick == "function" && e.value.onClick({
|
|
50
55
|
entry: e.value
|
|
51
|
-
}), 1),
|
|
52
|
-
let
|
|
53
|
-
return
|
|
54
|
-
}),
|
|
55
|
-
let
|
|
56
|
-
for (let
|
|
57
|
-
|
|
58
|
-
return
|
|
59
|
-
}),
|
|
56
|
+
}), 1), c = i(() => r["icon-" + e.value.key] || e.value.icon !== ""), O = i(() => {
|
|
57
|
+
let l = [];
|
|
58
|
+
return c.value && l.push("has-icon"), l.join(" ");
|
|
59
|
+
}), f = i(() => $([], e.value.children)), h = i(() => {
|
|
60
|
+
let l = [];
|
|
61
|
+
for (let d in r)
|
|
62
|
+
d.startsWith("icon-") && f.value.includes(d.substring(5)) && l.push(d);
|
|
63
|
+
return l;
|
|
64
|
+
}), W = i(() => e.value.label.startsWith("__:") ? X(e.value.label.substring(3)) : e.value.label), x = i(() => e.value.isActive ? !0 : typeof e.value.isActiveChecker == "function" ? !!e.value.isActiveChecker({
|
|
60
65
|
entry: e.value
|
|
61
|
-
}) : !1);
|
|
62
|
-
return
|
|
63
|
-
e.value =
|
|
64
|
-
}, { deep: !0 }),
|
|
65
|
-
|
|
66
|
-
}, { deep: !0 }), (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
}) : !1), D = i(() => !!k.toggleSlot), j = i(() => k.toggleSlot);
|
|
67
|
+
return g(() => v.modelValue, (l) => {
|
|
68
|
+
e.value = l;
|
|
69
|
+
}, { deep: !0 }), g(e, (l) => {
|
|
70
|
+
s("update:modelValue", l);
|
|
71
|
+
}, { deep: !0 }), q(() => {
|
|
72
|
+
let l = A.currentRoute;
|
|
73
|
+
if (l.value.path === e.value.href)
|
|
74
|
+
e.value.isOpened = !0;
|
|
75
|
+
else if (e.value.children.length > 0) {
|
|
76
|
+
let d = !1;
|
|
77
|
+
e.value.children.forEach((S) => {
|
|
78
|
+
l.value.path === S.href && (d = !0);
|
|
79
|
+
}), d && (e.value.isOpened = !0);
|
|
80
|
+
}
|
|
81
|
+
}), (l, d) => {
|
|
82
|
+
const S = w("lkt-anchor"), z = w("menu-item", !0);
|
|
83
|
+
return u(), a("div", {
|
|
84
|
+
class: _(["lkt-menu-entry", O.value])
|
|
70
85
|
}, [
|
|
71
|
-
|
|
72
|
-
|
|
86
|
+
C("div", Z, [
|
|
87
|
+
G(S, {
|
|
73
88
|
to: e.value.href,
|
|
74
|
-
"on-click":
|
|
75
|
-
"is-active":
|
|
89
|
+
"on-click": o,
|
|
90
|
+
"is-active": x.value
|
|
76
91
|
}, {
|
|
77
|
-
default:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
92
|
+
default: E(() => [
|
|
93
|
+
C("div", ee, [
|
|
94
|
+
c.value ? (u(), a("div", te, [
|
|
95
|
+
H(r)["icon-" + e.value.key] ? I(l.$slots, "icon-" + e.value.key, {
|
|
81
96
|
key: e.value.key,
|
|
82
97
|
entry: e.value
|
|
83
|
-
}) : e.value.icon !== "" ? (u(),
|
|
98
|
+
}) : e.value.icon !== "" ? (u(), a("i", {
|
|
84
99
|
key: 1,
|
|
85
|
-
class:
|
|
86
|
-
}, null, 2)) :
|
|
87
|
-
])) :
|
|
88
|
-
e.value.label !== "" ? (u(),
|
|
100
|
+
class: _(e.value.icon)
|
|
101
|
+
}, null, 2)) : m("", !0)
|
|
102
|
+
])) : m("", !0),
|
|
103
|
+
e.value.label !== "" ? (u(), a("div", le, J(W.value), 1)) : m("", !0)
|
|
89
104
|
])
|
|
90
105
|
]),
|
|
91
106
|
_: 3
|
|
92
107
|
}, 8, ["to", "is-active"]),
|
|
93
|
-
e.value.children.length > 0 ? (u(),
|
|
108
|
+
e.value.children.length > 0 ? (u(), a("div", {
|
|
94
109
|
key: 0,
|
|
95
110
|
class: "lkt-menu-entry-toggle",
|
|
96
|
-
onClick:
|
|
111
|
+
onClick: p
|
|
97
112
|
}, [
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
113
|
+
D.value ? (u(), M(P(j.value), {
|
|
114
|
+
key: 0,
|
|
115
|
+
class: _(["lkt-menu-entry-toggle-inner", e.value.isOpened ? "is-opened" : ""])
|
|
116
|
+
}, null, 8, ["class"])) : (u(), a("div", {
|
|
117
|
+
key: 1,
|
|
118
|
+
class: _(["lkt-menu-entry-toggle-inner lkt-menu-entry-toggle-triangle", e.value.isOpened ? "is-opened" : ""])
|
|
119
|
+
}, null, 2))
|
|
120
|
+
])) : m("", !0)
|
|
102
121
|
]),
|
|
103
|
-
e.value.isOpened ? (u(),
|
|
104
|
-
(u(!0),
|
|
105
|
-
modelValue: e.value.children[
|
|
106
|
-
"onUpdate:modelValue": (
|
|
107
|
-
key:
|
|
108
|
-
},
|
|
109
|
-
V(
|
|
110
|
-
name:
|
|
111
|
-
fn:
|
|
112
|
-
I(
|
|
122
|
+
e.value.isOpened ? (u(), a("div", ne, [
|
|
123
|
+
(u(!0), a(K, null, V(e.value.children, (F, L) => (u(), M(z, {
|
|
124
|
+
modelValue: e.value.children[L],
|
|
125
|
+
"onUpdate:modelValue": (y) => e.value.children[L] = y,
|
|
126
|
+
key: F.key
|
|
127
|
+
}, N({ _: 2 }, [
|
|
128
|
+
V(h.value, (y) => ({
|
|
129
|
+
name: y,
|
|
130
|
+
fn: E(() => [
|
|
131
|
+
I(l.$slots, y)
|
|
113
132
|
])
|
|
114
133
|
}))
|
|
115
134
|
]), 1032, ["modelValue", "onUpdate:modelValue"]))), 128))
|
|
116
|
-
])) :
|
|
135
|
+
])) : m("", !0)
|
|
117
136
|
], 2);
|
|
118
137
|
};
|
|
119
138
|
}
|
|
120
|
-
}),
|
|
139
|
+
}), ue = { class: "lkt-menu-container" }, oe = { class: "lkt-menu" }, re = /* @__PURE__ */ C("div", { class: "lkt-menu-outside" }, null, -1), ie = /* @__PURE__ */ R({
|
|
121
140
|
__name: "LktMenu",
|
|
122
141
|
props: {
|
|
123
142
|
modelValue: { default: () => [] }
|
|
124
143
|
},
|
|
125
144
|
emits: ["update:modelValue"],
|
|
126
145
|
setup(n, { emit: t }) {
|
|
127
|
-
const
|
|
128
|
-
let
|
|
129
|
-
for (let
|
|
130
|
-
|
|
131
|
-
return
|
|
146
|
+
const s = n, v = t, e = B(), r = U(s.modelValue), A = i(() => $([], r.value)), p = i(() => {
|
|
147
|
+
let o = [];
|
|
148
|
+
for (let c in e)
|
|
149
|
+
c.startsWith("icon-") && A.value.includes(c.substring(5)) && o.push(c);
|
|
150
|
+
return o;
|
|
132
151
|
});
|
|
133
|
-
return
|
|
134
|
-
r.value =
|
|
135
|
-
}, { deep: !0 }),
|
|
136
|
-
|
|
137
|
-
}, { deep: !0 }), (
|
|
138
|
-
|
|
139
|
-
(u(!0),
|
|
140
|
-
modelValue: r.value[
|
|
141
|
-
"onUpdate:modelValue": (
|
|
142
|
-
key:
|
|
143
|
-
},
|
|
144
|
-
V(
|
|
145
|
-
name:
|
|
146
|
-
fn:
|
|
147
|
-
I(
|
|
152
|
+
return g(() => s.modelValue, (o) => {
|
|
153
|
+
r.value = o;
|
|
154
|
+
}, { deep: !0 }), g(r, (o) => {
|
|
155
|
+
v("update:modelValue", o);
|
|
156
|
+
}, { deep: !0 }), (o, c) => (u(), a("div", ue, [
|
|
157
|
+
C("div", oe, [
|
|
158
|
+
(u(!0), a(K, null, V(r.value, (O, f) => (u(), M(se, {
|
|
159
|
+
modelValue: r.value[f],
|
|
160
|
+
"onUpdate:modelValue": (h) => r.value[f] = h,
|
|
161
|
+
key: O.key
|
|
162
|
+
}, N({ _: 2 }, [
|
|
163
|
+
V(p.value, (h) => ({
|
|
164
|
+
name: h,
|
|
165
|
+
fn: E(() => [
|
|
166
|
+
I(o.$slots, h)
|
|
148
167
|
])
|
|
149
168
|
}))
|
|
150
169
|
]), 1032, ["modelValue", "onUpdate:modelValue"]))), 128))
|
|
151
170
|
]),
|
|
152
|
-
|
|
171
|
+
re
|
|
153
172
|
]));
|
|
154
173
|
}
|
|
155
|
-
}),
|
|
174
|
+
}), ve = {
|
|
156
175
|
install: (n) => {
|
|
157
|
-
n.component("lkt-menu") === void 0 && n.component("lkt-menu",
|
|
176
|
+
n.component("lkt-menu") === void 0 && n.component("lkt-menu", ie);
|
|
158
177
|
}
|
|
159
|
-
},
|
|
178
|
+
}, he = (n, t, s) => Q(new T(n, t, s)), me = (n) => (k.toggleSlot = n, !0);
|
|
160
179
|
export {
|
|
161
|
-
|
|
162
|
-
|
|
180
|
+
he as createMenuEntry,
|
|
181
|
+
ve as default,
|
|
182
|
+
me as setMenuToggleSlot
|
|
163
183
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Plugin } from 'vue';
|
|
1
|
+
import { Component, Plugin } from 'vue';
|
|
2
2
|
import "../style.css";
|
|
3
3
|
import { MenuEntry } from "./classes/MenuEntry";
|
|
4
4
|
declare const LktMenu: Plugin;
|
|
5
5
|
export default LktMenu;
|
|
6
6
|
export declare const createMenuEntry: (key: string, href: string, label: string) => MenuEntry;
|
|
7
|
+
export declare const setMenuToggleSlot: (component: string | Component) => boolean;
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.lkt-menu{background:var(--lkt-menu-bg);padding:var(--lkt-menu-padding);max-width:var(--lkt-menu-max-width);width:var(--lkt-menu-width);height:100%}.lkt-menu-entry-toggle-triangle{width:0;height:0;border-style:solid;border-width:10px 10px 0 10px;border-color:var(--lkt-menu-color-toggle) transparent transparent transparent;transform:rotate(0);transition:all linear .2s}.lkt-
|
|
1
|
+
.lkt-menu{background:var(--lkt-menu-bg);padding:var(--lkt-menu-padding);max-width:var(--lkt-menu-max-width);width:var(--lkt-menu-width);height:100%}.lkt-menu-entry-toggle-inner{transition:all linear .2s}.lkt-menu-entry-toggle-inner.is-opened{transform:rotate(180deg)}.lkt-menu-entry-toggle-triangle{width:0;height:0;border-style:solid;border-width:10px 10px 0 10px;border-color:var(--lkt-menu-color-toggle) transparent transparent transparent;transform:rotate(0);transition:all linear .2s}.lkt-entry-content{display:inline-flex;flex-direction:row;gap:var(--lkt-menu-gap)}.lkt-menu-entry-toggle{display:inline-flex;flex-direction:row;align-items:center;justify-content:center}.lkt-menu-entry{padding:var(--lkt-menu-padding-entry)}.lkt-menu-entry .lkt-anchor{width:100%}.lkt-menu-entry-main{display:flex;justify-content:space-between}.lkt-entry-content{font-size:var(--lkt-menu-font-size);width:100%}.lkt-menu-outside{position:fixed;top:64px;right:0;left:0;bottom:0;background:var(--lkt-menu-bg-outside);z-index:-1}.lkt-menu-entry-children{padding:var(--lkt-menu-padding-children)}.lkt-menu-entry-text{padding:var(--lkt-menu-padding-text-without-icon)}.lkt-menu.has-icon .lkt-menu-entry-text{padding:var(--lkt-menu-padding-text)}.lkt-menu.has-icon .lkt-menu-entry-icon+.lkt-menu-entry-text{padding:var(--lkt-menu-padding-text-with-icon)}
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import {MenuEntry} from "../classes/MenuEntry";
|
|
3
|
-
import {computed, ref, useSlots, watch} from "vue";
|
|
3
|
+
import {computed, onMounted, ref, useSlots, watch} from "vue";
|
|
4
4
|
import {LktObject} from "lkt-ts-interfaces";
|
|
5
5
|
import {fetchKeys} from "../functions/helpers";
|
|
6
6
|
import {__} from "lkt-i18n";
|
|
7
|
+
import {useRouter} from "vue-router";
|
|
8
|
+
import {Settings} from "../settings/Settings";
|
|
7
9
|
|
|
8
10
|
const emit = defineEmits(['update:modelValue']);
|
|
9
11
|
|
|
@@ -17,6 +19,8 @@ const entry = ref(props.modelValue);
|
|
|
17
19
|
|
|
18
20
|
const slots = useSlots();
|
|
19
21
|
|
|
22
|
+
const router = useRouter();
|
|
23
|
+
|
|
20
24
|
const onClickToggle = () => {
|
|
21
25
|
entry.value.isOpened = !entry.value.isOpened;
|
|
22
26
|
},
|
|
@@ -72,6 +76,12 @@ const availableKeys = computed(() => {
|
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
return false;
|
|
79
|
+
}),
|
|
80
|
+
hasToggleSlot = computed(() => {
|
|
81
|
+
return !!Settings.toggleSlot;
|
|
82
|
+
}),
|
|
83
|
+
toggleSlot = computed(() => {
|
|
84
|
+
return Settings.toggleSlot;
|
|
75
85
|
});
|
|
76
86
|
|
|
77
87
|
watch(() => props.modelValue, (v) => {
|
|
@@ -79,7 +89,21 @@ watch(() => props.modelValue, (v) => {
|
|
|
79
89
|
}, {deep: true});
|
|
80
90
|
watch(entry, (v) => {
|
|
81
91
|
emit('update:modelValue', v)
|
|
82
|
-
}, {deep: true})
|
|
92
|
+
}, {deep: true});
|
|
93
|
+
|
|
94
|
+
onMounted(() => {
|
|
95
|
+
let currentRoute = router.currentRoute;
|
|
96
|
+
if (currentRoute.value.path === entry.value.href) {
|
|
97
|
+
entry.value.isOpened = true;
|
|
98
|
+
} else if (entry.value.children.length > 0) {
|
|
99
|
+
let opened = false;
|
|
100
|
+
entry.value.children.forEach((child) => {
|
|
101
|
+
if (currentRoute.value.path === child.href) opened = true;
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
if (opened) entry.value.isOpened = true;
|
|
105
|
+
}
|
|
106
|
+
})
|
|
83
107
|
</script>
|
|
84
108
|
|
|
85
109
|
<template>
|
|
@@ -108,7 +132,10 @@ watch(entry, (v) => {
|
|
|
108
132
|
</lkt-anchor>
|
|
109
133
|
|
|
110
134
|
<div class="lkt-menu-entry-toggle" v-if="entry.children.length > 0" @click="onClickToggle">
|
|
111
|
-
<
|
|
135
|
+
<template v-if="hasToggleSlot">
|
|
136
|
+
<component :is="toggleSlot" class="lkt-menu-entry-toggle-inner" :class="entry.isOpened ? 'is-opened' : '' "/>
|
|
137
|
+
</template>
|
|
138
|
+
<div v-else class="lkt-menu-entry-toggle-inner lkt-menu-entry-toggle-triangle" :class="entry.isOpened ? 'is-opened' : '' "/>
|
|
112
139
|
</div>
|
|
113
140
|
</div>
|
|
114
141
|
<div class="lkt-menu-entry-children" v-if="entry.isOpened">
|