wx-svelte-menu 2.3.1 → 2.4.2
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 +3 -3
- package/src/components/ActionMenu.svelte +9 -13
- package/src/components/DropDownMenu.svelte +1 -1
- package/src/components/MenuBar.svelte +7 -0
- package/src/components/MenuOption.svelte +21 -2
- package/src/helpers/index.js +3 -2
- package/types/index.d.ts +1 -0
- package/whatsnew.md +21 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wx-svelte-menu",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.2",
|
|
4
4
|
"description": "Svelte menu component for creating dropdown menus, context menus, or complex menu bars",
|
|
5
5
|
"productTag": "menu",
|
|
6
6
|
"productTrial": false,
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://svar.dev/svelte/core/",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@svar-ui/svelte-core": "2.
|
|
37
|
-
"@svar-ui/lib-dom": "0.
|
|
36
|
+
"@svar-ui/svelte-core": "2.4.1",
|
|
37
|
+
"@svar-ui/lib-dom": "0.12.0"
|
|
38
38
|
},
|
|
39
39
|
"files": [
|
|
40
40
|
"src",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import { Portal } from "@svar-ui/svelte-core";
|
|
3
|
-
import { id } from "@svar-ui/lib-dom";
|
|
4
3
|
import Menu from "./Menu.svelte";
|
|
5
4
|
import { filterMenu } from "../helpers";
|
|
5
|
+
import { locateID } from "@svar-ui/lib-dom";
|
|
6
6
|
|
|
7
7
|
let {
|
|
8
8
|
options,
|
|
@@ -15,15 +15,19 @@
|
|
|
15
15
|
onclick,
|
|
16
16
|
} = $props();
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const attrName = $derived(
|
|
19
|
+
`data-${dataKey.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase()}`
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const filteredOptions = $derived.by(() => {
|
|
19
23
|
if (item !== null && filter) {
|
|
20
24
|
return filterMenu(options, v => filter(v, item));
|
|
21
25
|
}
|
|
22
26
|
return options;
|
|
23
27
|
});
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
let item = $state(null);
|
|
30
|
+
let parent = $state(null);
|
|
27
31
|
let left = $state(0),
|
|
28
32
|
top = $state(0);
|
|
29
33
|
|
|
@@ -31,14 +35,6 @@
|
|
|
31
35
|
parent = null;
|
|
32
36
|
onclick && onclick(ev);
|
|
33
37
|
}
|
|
34
|
-
function getDataAttr(node, name) {
|
|
35
|
-
let v = null;
|
|
36
|
-
while (node && node.dataset && !v) {
|
|
37
|
-
v = node.dataset[name];
|
|
38
|
-
node = node.parentNode;
|
|
39
|
-
}
|
|
40
|
-
return v ? id(v) : null;
|
|
41
|
-
}
|
|
42
38
|
|
|
43
39
|
export function show(ev, obj) {
|
|
44
40
|
if (!ev) {
|
|
@@ -54,7 +50,7 @@
|
|
|
54
50
|
left = ev.clientX + 1;
|
|
55
51
|
top = ev.clientY + 1;
|
|
56
52
|
|
|
57
|
-
item = typeof obj !== "undefined" ? obj :
|
|
53
|
+
item = typeof obj !== "undefined" ? obj : locateID(target, attrName);
|
|
58
54
|
if (resolver) {
|
|
59
55
|
item = resolver(item, ev);
|
|
60
56
|
if (!item) return;
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
{#each finalOptions as option (option.id)}
|
|
51
51
|
<button
|
|
52
52
|
class="wx-option {active === option.id ? 'wx-active' : ''}"
|
|
53
|
+
class:wx-disabled={option.disabled}
|
|
53
54
|
onmouseenter={ev => onHover(ev, option)}
|
|
54
55
|
onclick={ev => setMenu(ev, option, true)}>{option.text}</button
|
|
55
56
|
>
|
|
@@ -92,4 +93,10 @@
|
|
|
92
93
|
background-color: var(--wx-background-alt);
|
|
93
94
|
border-radius: var(--wx-button-border-radius);
|
|
94
95
|
}
|
|
96
|
+
.wx-disabled {
|
|
97
|
+
pointer-events: none;
|
|
98
|
+
}
|
|
99
|
+
.wx-disabled {
|
|
100
|
+
color: var(--wx-color-font-disabled);
|
|
101
|
+
}
|
|
95
102
|
</style>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
+
import { setID } from "@svar-ui/lib-dom";
|
|
2
3
|
import { getItemHandler } from "../helpers";
|
|
3
4
|
|
|
4
5
|
let { option, onclick, onshow } = $props();
|
|
@@ -7,6 +8,14 @@
|
|
|
7
8
|
function onHover() {
|
|
8
9
|
onshow(option.data ? option.id : false, element);
|
|
9
10
|
}
|
|
11
|
+
function onClick(ev) {
|
|
12
|
+
if (option.data) {
|
|
13
|
+
ev.stopPropagation();
|
|
14
|
+
onshow(option.id, element);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
onclick(ev);
|
|
18
|
+
}
|
|
10
19
|
</script>
|
|
11
20
|
|
|
12
21
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
@@ -14,9 +23,10 @@
|
|
|
14
23
|
<div
|
|
15
24
|
bind:this={element}
|
|
16
25
|
class="wx-option {option.css || ''}"
|
|
17
|
-
|
|
26
|
+
class:wx-disabled={option.disabled}
|
|
27
|
+
data-id={setID(option.id)}
|
|
18
28
|
onmouseenter={onHover}
|
|
19
|
-
{
|
|
29
|
+
onclick={onClick}
|
|
20
30
|
>
|
|
21
31
|
{#if option.icon}<i class="wx-icon {option.icon}"></i>{/if}
|
|
22
32
|
{#if option.comp}
|
|
@@ -80,4 +90,13 @@
|
|
|
80
90
|
margin-left: 20px;
|
|
81
91
|
white-space: nowrap;
|
|
82
92
|
}
|
|
93
|
+
|
|
94
|
+
.wx-disabled {
|
|
95
|
+
pointer-events: none;
|
|
96
|
+
}
|
|
97
|
+
.wx-disabled .wx-value,
|
|
98
|
+
.wx-disabled .wx-icon,
|
|
99
|
+
.wx-disabled .wx-sub-icon {
|
|
100
|
+
color: var(--wx-color-font-disabled);
|
|
101
|
+
}
|
|
83
102
|
</style>
|
package/src/helpers/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { uid } from "@svar-ui/lib-dom";
|
|
2
|
+
|
|
1
3
|
export function walkData(data, cb) {
|
|
2
4
|
data.forEach(a => {
|
|
3
5
|
cb(a);
|
|
@@ -27,11 +29,10 @@ export function filterMenu(data, cb) {
|
|
|
27
29
|
return out;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
let uid = 1;
|
|
31
32
|
export function prepareMenuData(data) {
|
|
32
33
|
return mapData(data, a => {
|
|
33
34
|
// [deprecated] option.type to be deprecated in 3.0
|
|
34
|
-
const opt = { ...a, id: a.id || uid
|
|
35
|
+
const opt = { ...a, id: a.id || uid() };
|
|
35
36
|
if (opt.type) opt.comp = opt.type;
|
|
36
37
|
return opt;
|
|
37
38
|
});
|
package/types/index.d.ts
CHANGED
package/whatsnew.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## 2.4.2
|
|
2
|
+
|
|
3
|
+
### Fixes
|
|
4
|
+
|
|
5
|
+
- Submenus are not shown on mobile devices
|
|
6
|
+
|
|
7
|
+
## 2.4.1
|
|
8
|
+
|
|
9
|
+
- Using Svelte Core v2.4.1
|
|
10
|
+
|
|
11
|
+
## 2.4.0
|
|
12
|
+
|
|
13
|
+
### Updates
|
|
14
|
+
|
|
15
|
+
- More options to precisely position and align ContextMenu, DropDownMenu, ActionMenu
|
|
16
|
+
|
|
17
|
+
### Fixes
|
|
18
|
+
|
|
19
|
+
- Incorrect position of Menus in a relatively positioned continer
|
|
20
|
+
- Incorrect position of Menus close to the container edges
|
|
21
|
+
|
|
1
22
|
## 2.3.1
|
|
2
23
|
|
|
3
24
|
### Fixes
|