@v1nt1248/3nclient-lib 0.2.4 → 0.2.6

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
@@ -2,7 +2,7 @@
2
2
  "name": "@v1nt1248/3nclient-lib",
3
3
  "license": "AGPL-3.0-or-later",
4
4
  "author": "v1nt1248",
5
- "version": "0.2.4",
5
+ "version": "0.2.6",
6
6
  "description": "Library for 3NWeb clients",
7
7
  "type": "module",
8
8
  "files": [
@@ -1,7 +1,8 @@
1
- import { VNode } from 'vue';
1
+ import type { VNode } from 'vue';
2
2
 
3
3
  export interface Ui3nMenuProps {
4
4
  modelValue?: boolean;
5
+ triggerElement?: HTMLElement;
5
6
  positionStrategy?: 'absolute' | 'fixed';
6
7
  positionAutoupdate?: boolean;
7
8
  offsetX?: number;
@@ -3,6 +3,7 @@
3
3
  import { autoUpdate, flip, useFloating, offset, shift } from '@floating-ui/vue';
4
4
  import { default as vClickOutside } from '../../directives/ui3n-click-outside';
5
5
  import type { Ui3nMenuEmits, Ui3nMenuProps, Ui3nMenuSlots } from './types';
6
+ import { Nullable } from '@/components/types';
6
7
 
7
8
  const props = withDefaults(defineProps<Ui3nMenuProps>(), {
8
9
  positionStrategy: 'absolute',
@@ -22,6 +23,10 @@
22
23
  const menuContentElement = ref<HTMLDivElement | null>(null);
23
24
  const isShow = ref(false);
24
25
 
26
+ const outerTriggerElement = ref<Nullable<HTMLElement>>(props.triggerElement || null);
27
+
28
+ const usedTriggerElement = computed(() => outerTriggerElement.value || menuTriggerElement.value);
29
+
25
30
  const contentBorderRadiusCss = computed(() => {
26
31
  if (typeof props.contentBorderRadius === 'number') {
27
32
  return `${props.contentBorderRadius}px`;
@@ -32,27 +37,29 @@
32
37
  });
33
38
  const zIndexCss = computed(() => props.zIndex);
34
39
 
35
- const { floatingStyles, isPositioned } = useFloating(
36
- menuTriggerElement,
40
+ const {
41
+ floatingStyles,
42
+ isPositioned,
43
+ } = useFloating(
44
+ usedTriggerElement,
37
45
  menuContentElement,
38
46
  {
39
- placement: 'bottom-start',
40
- strategy: props.positionStrategy,
41
- middleware: [
42
- offset({
43
- mainAxis: props.offsetY,
44
- crossAxis: props.offsetX + 2,
45
- }),
46
- flip({
47
- fallbackAxisSideDirection: 'end',
48
- flipAlignment: false,
49
- fallbackPlacements: ['bottom-end'],
50
- }),
51
- shift(),
52
- ],
53
- whileElementsMounted: props.positionAutoupdate || props.positionStrategy === 'fixed' ? autoUpdate : undefined,
54
- },
55
- );
47
+ placement: 'bottom-start',
48
+ strategy: props.positionStrategy,
49
+ middleware: [
50
+ offset({
51
+ mainAxis: props.offsetY,
52
+ crossAxis: props.offsetX + 2,
53
+ }),
54
+ flip({
55
+ fallbackAxisSideDirection: 'end',
56
+ flipAlignment: false,
57
+ fallbackPlacements: ['bottom-end'],
58
+ }),
59
+ shift(),
60
+ ],
61
+ whileElementsMounted: props.positionAutoupdate || props.positionStrategy === 'fixed' ? autoUpdate : undefined,
62
+ });
56
63
 
57
64
  function toggleMenu() {
58
65
  if (props.disabled) {
@@ -79,12 +86,9 @@
79
86
  }
80
87
  }
81
88
 
82
- watch(
83
- isPositioned,
84
- val => {
85
- val ? emits('opened') : emits('closed');
86
- },
87
- );
89
+ watch(isPositioned, val => {
90
+ val ? emits('opened') : emits('closed');
91
+ });
88
92
 
89
93
  watch(
90
94
  () => props.modelValue,
@@ -92,12 +96,25 @@
92
96
  if (isShow.value !== val) {
93
97
  isShow.value = val;
94
98
  }
95
- }, { immediate: true },
99
+ },
100
+ { immediate: true },
96
101
  );
102
+
103
+ watch(
104
+ () => props.triggerElement,
105
+ val => {
106
+ if (val) {
107
+ outerTriggerElement.value = val;
108
+ }
109
+ },
110
+ )
97
111
  </script>
98
112
 
99
113
  <template>
100
- <div ref="menuElement" :class="$style.ui3nMenu">
114
+ <div
115
+ ref="menuElement"
116
+ :class="$style.ui3nMenu"
117
+ >
101
118
  <div
102
119
  ref="menuTriggerElement"
103
120
  :class="[$style.ui3nMenuTrigger, disabled && $style.ui3nMenuTriggerDisabled]"