lkt-menu 2.0.7 → 2.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lkt-menu",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "lkt",
@@ -25,7 +25,6 @@
25
25
  "types": "./dist/build.d.ts",
26
26
  "files": [
27
27
  "dist/*",
28
- "src/**/*.vue",
29
28
  "theme/**/*.css"
30
29
  ],
31
30
  "license": "MIT",
package/theme/default.css CHANGED
@@ -32,4 +32,12 @@
32
32
 
33
33
  /** Event: Hover */
34
34
  --lkt-menu--hover--text-decoration: none;
35
+
36
+ /** Element: Container */
37
+ --lkt-menu--container--width: 100%;
38
+ --lkt-menu--container--top: 0;
39
+ --lkt-menu--container--bottom: 0;
40
+ --lkt-menu--container--background: transparent;
41
+ --lkt-menu--container--transition: all linear 100ms;
42
+ --lkt-menu--container--max-height: 100%;
35
43
  }
@@ -1,182 +0,0 @@
1
- <script setup lang="ts">
2
- import { MenuEntryConfig, MenuEntryType } from 'lkt-vue-kernel';
3
- import { computed, onMounted, ref, useSlots, watch } from 'vue';
4
- import { fetchKeys } from '../functions/helpers';
5
- import { useRouter } from 'vue-router';
6
- import { Settings } from '../settings/Settings';
7
-
8
- const emit = defineEmits([
9
- 'update:modelValue',
10
- ]);
11
-
12
- const props = withDefaults(defineProps<{
13
- modelValue?: MenuEntryConfig
14
- }>(), {
15
- modelValue: () => ({}),
16
- });
17
-
18
- const entry = ref(<MenuEntryConfig>props.modelValue),
19
- slots = useSlots(),
20
- router = useRouter(),
21
- isActive = ref(false);
22
-
23
- const onClickToggle = () => {
24
- entry.value.isOpened = !entry.value.isOpened;
25
- },
26
- onClick = () => {
27
- if (typeof entry.value.children !== 'undefined' && entry.value.children?.length > 0 && !entry.value.keepOpenOnChildClick) onClickToggle();
28
-
29
- if (typeof entry.value.events?.click === 'function') {
30
- entry.value.events.click({
31
- entry: entry.value,
32
- });
33
- return 1;
34
- }
35
- return 1;
36
- };
37
-
38
- const canRenderIcon = computed(() => {
39
- return slots['icon-' + entry.value.key]
40
- || entry.value.icon !== '';
41
- }),
42
- classes = computed(() => {
43
- let r = [];
44
- if (canRenderIcon.value) r.push('has-icon');
45
- if (isActive.value) r.push('is-active');
46
- if (entry.value.type) r.push(`is-${entry.value.type}`);
47
- return r.join(' ');
48
- });
49
-
50
- const availableKeys = computed(() => {
51
- let r: string[] = [];
52
- return fetchKeys(r, entry.value?.children ?? []);
53
- }),
54
- entryIconSlots = computed((): Array<string> => {
55
- let r = [];
56
- for (let k in slots) {
57
- if (k.startsWith('icon-')) {
58
- if (availableKeys.value.includes(k.substring(5))) {
59
- r.push(k);
60
- }
61
- }
62
- }
63
- return r;
64
- }),
65
- computedIsActive = computed(() => {
66
- if (entry.value.isActive) return true;
67
-
68
- if (typeof entry.value.isActiveChecker === 'function') {
69
- let r = entry.value.isActiveChecker({
70
- entry: entry.value,
71
- });
72
- return !!r;
73
- }
74
-
75
- return false;
76
- }),
77
- hasToggleSlot = computed(() => {
78
- return !!Settings.toggleSlot;
79
- }),
80
- toggleSlot = computed(() => {
81
- return Settings.toggleSlot;
82
- });
83
-
84
- watch(() => props.modelValue, (v) => {
85
- entry.value = v;
86
- }, { deep: true });
87
-
88
- watch(entry, (v) => {
89
- emit('update:modelValue', v);
90
- }, { deep: true });
91
-
92
- onMounted(() => {
93
- let currentRoute = router?.currentRoute;
94
- if (currentRoute) {
95
- if (currentRoute.value.path === entry.value.anchor?.to) {
96
- entry.value.isOpened = true;
97
-
98
- } else if (typeof entry.value.children !== 'undefined' && entry.value.children?.length > 0) {
99
- let opened = false;
100
- entry.value.children?.forEach((child) => {
101
- if (currentRoute.value.path === child.anchor?.to) opened = true;
102
- });
103
-
104
- if (opened) entry.value.isOpened = true;
105
- }
106
- }
107
- });
108
- </script>
109
-
110
- <template>
111
- <div class="lkt-menu-entry" :class="classes">
112
- <div class="lkt-menu-entry-main">
113
- <lkt-button
114
- v-if="entry.type === MenuEntryType.Button"
115
- v-bind="entry.button"
116
- >
117
- <template v-if="slots.tooltip" #tooltip>
118
- <slot name="tooltip" />
119
- </template>
120
- <template v-if="slots.split" #split>
121
- <slot name="split" />
122
- </template>
123
- </lkt-button>
124
-
125
- <lkt-header
126
- v-else-if="entry.type === MenuEntryType.Header"
127
- v-bind="entry.header"
128
- />
129
-
130
- <lkt-anchor
131
- v-else-if="entry.type === MenuEntryType.Anchor"
132
- v-bind="entry.anchor"
133
- />
134
- <lkt-anchor
135
- v-else
136
- v-bind="entry.anchor"
137
- :on-click="onClick"
138
- :is-active="computedIsActive"
139
- @active="($e: any) => isActive = $e"
140
- >
141
- <template #text="{text}">
142
- <div class="lkt-entry-content">
143
- <div class="lkt-menu-entry-icon" v-if="canRenderIcon">
144
- <template v-if="slots['icon-'+entry.key]">
145
- <slot :name="'icon-'+entry.key"
146
- :key="entry.key"
147
- :entry="entry" />
148
- </template>
149
- <template v-else-if="entry.icon !== ''">
150
- <i :class="entry.icon" />
151
- </template>
152
- </div>
153
- <div class="lkt-menu-entry-text" v-if="text !== ''">
154
- {{ text }}
155
- </div>
156
- </div>
157
- </template>
158
- </lkt-anchor>
159
-
160
- <div class="lkt-menu-entry-toggle"
161
- v-if="entry.type !== MenuEntryType.Button && entry.children && entry.children?.length > 0"
162
- @click="onClickToggle">
163
- <template v-if="hasToggleSlot">
164
- <component :is="toggleSlot" class="lkt-menu-entry-toggle-inner"
165
- :class="entry.isOpened ? 'is-opened' : '' " />
166
- </template>
167
- <div v-else class="lkt-menu-entry-toggle-inner" :class="entry.isOpened ? 'is-opened' : '' ">
168
- <i class="lkt-icn-angle-bottom" />
169
- </div>
170
- </div>
171
- </div>
172
- <div class="lkt-menu-entry-children" v-if="entry.isOpened">
173
- <menu-item v-for="(_, i) in entry.children"
174
- v-model="entry.children[i]"
175
- :key="entry.children[i].key">
176
- <template v-for="slot in entryIconSlots" v-slot:[slot]>
177
- <slot :name="slot" />
178
- </template>
179
- </menu-item>
180
- </div>
181
- </div>
182
- </template>
@@ -1,111 +0,0 @@
1
- <script setup lang="ts">
2
- import MenuItem from '../components/MenuItem.vue';
3
- import { computed, ref, useSlots, watch } from 'vue';
4
- import { getDefaultValues, LktObject, Menu, MenuConfig } from 'lkt-vue-kernel';
5
- import { fetchKeys } from '../functions/helpers';
6
- import { DataState } from 'lkt-data-state';
7
- import { httpCall, HTTPResponse } from 'lkt-http-client';
8
-
9
- const props = withDefaults(defineProps<MenuConfig>(), getDefaultValues(Menu));
10
-
11
- const emit = defineEmits([
12
- 'update:modelValue',
13
- 'click-outside',
14
- 'loading',
15
- 'results',
16
- 'response',
17
- 'error',
18
- ]);
19
-
20
- const slots = useSlots();
21
-
22
- const entries = ref(props.modelValue);
23
-
24
- const parseFilters = (filters: LktObject) => {
25
- let d: LktObject = {};
26
- if (typeof filters === 'object' && Object.keys(filters).length > 0) {
27
- d = JSON.parse(JSON.stringify(filters));
28
- }
29
- for (let k in d) {
30
- if (Array.isArray(d[k]) || typeof d[k] === 'object') {
31
- d[k] = JSON.stringify(d[k]);
32
- }
33
- }
34
- return d;
35
- };
36
- let resourceDataState = new DataState({});
37
- resourceDataState.increment(parseFilters(props.http?.data ?? {}));
38
-
39
- const availableKeys = computed(() => {
40
- let r: string[] = [];
41
- return fetchKeys(r, entries.value);
42
- }),
43
- entryIconSlots = computed((): LktObject => {
44
- let r = [];
45
- for (let k in slots) {
46
- if (k.startsWith('icon-')) {
47
- if (availableKeys.value.includes(k.substring(5))) {
48
- r.push(k);
49
- }
50
- }
51
- }
52
- return r;
53
- }),
54
- loadResource = () => {
55
- if (!props.http?.resource) return;
56
-
57
- let d = resourceDataState.getData();
58
- emit('loading');
59
-
60
- httpCall(props.http?.resource, d).then((r: HTTPResponse) => {
61
- resourceDataState.turnStoredIntoOriginal();
62
- //@ts-ignore
63
- entries.value = r.data;
64
- emit('results', r.data);
65
- emit('response', r);
66
-
67
- }).catch((r: any) => {
68
- emit('error', r);
69
- });
70
- };
71
-
72
- const onClickOutside = () => {
73
- emit('click-outside');
74
- };
75
-
76
- watch(() => props.modelValue, (v) => {
77
- entries.value = v;
78
- }, { deep: true });
79
-
80
- watch(entries, (v) => {
81
- emit('update:modelValue', v);
82
- }, { deep: true });
83
-
84
- loadResource();
85
- </script>
86
-
87
- <template>
88
- <div class="lkt-menu">
89
- <div class="lkt-menu-main">
90
- <template v-if="slots.before">
91
- <slot name="before"/>
92
- </template>
93
- <div class="lkt-menu-entries">
94
- <menu-item v-for="(entry, i) in entries" v-model="entries[i]" :key="entry.key" :class="entry.class">
95
- <template v-for="slot in entryIconSlots" v-slot:[slot]>
96
- <slot :name="slot" />
97
- </template>
98
-
99
- <template v-if="slots[`tooltip-${entry.key}`]" #tooltip>
100
- <slot :name="`tooltip-${entry.key}`"/>
101
- </template>
102
-
103
- <template v-if="slots[`split-${entry.key}`]" #split>
104
- <slot :name="`split-${entry.key}`"/>
105
- </template>
106
- </menu-item>
107
- </div>
108
- </div>
109
- <div class="lkt-menu-outside" v-on:click="onClickOutside" />
110
- </div>
111
- </template>