wx-svelte-menu 2.4.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wx-svelte-menu",
3
- "version": "2.4.0",
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.4.0",
37
- "@svar-ui/lib-dom": "0.11.1"
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
- var filteredOptions = $derived.by(() => {
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
- var item = $state(null);
26
- var parent = $state(null);
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 : getDataAttr(target, dataKey);
53
+ item = typeof obj !== "undefined" ? obj : locateID(target, attrName);
58
54
  if (resolver) {
59
55
  item = resolver(item, ev);
60
56
  if (!item) return;
@@ -9,7 +9,7 @@
9
9
  ev.preventDefault();
10
10
  }
11
11
 
12
- var parent = $state(null);
12
+ let parent = $state(null);
13
13
  function onClick(ev) {
14
14
  parent = null;
15
15
  onclick && onclick(ev);
@@ -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 -->
@@ -15,9 +24,9 @@
15
24
  bind:this={element}
16
25
  class="wx-option {option.css || ''}"
17
26
  class:wx-disabled={option.disabled}
18
- data-id={option.id}
27
+ data-id={setID(option.id)}
19
28
  onmouseenter={onHover}
20
- {onclick}
29
+ onclick={onClick}
21
30
  >
22
31
  {#if option.icon}<i class="wx-icon {option.icon}"></i>{/if}
23
32
  {#if option.comp}
@@ -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/whatsnew.md CHANGED
@@ -1,3 +1,13 @@
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
+
1
11
  ## 2.4.0
2
12
 
3
13
  ### Updates