@fiscozen/composables 0.1.16-beta.1 → 0.1.18
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/composables.js +184 -201
- package/dist/composables.umd.cjs +1 -1
- package/package.json +3 -3
- package/src/FzFloating.vue +0 -7
- package/src/__tests__/__snapshots__/FzFloating.spec.ts.snap +12 -24
- package/src/composables/index.ts +1 -0
- package/src/composables/useClickOutside.ts +9 -12
- package/src/composables/useCurrency.ts +75 -0
- package/src/composables/useFloating.ts +78 -122
- package/src/composables/useKeyDown.ts +1 -4
- package/src/composables/useKeyUp.ts +4 -6
- package/src/types.ts +1 -7
- package/src/utils/index.ts +4 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiscozen/composables",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "Design System utility composables",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"vite": "^5.0.10",
|
|
26
26
|
"vitest": "^1.2.0",
|
|
27
27
|
"vue-tsc": "^1.8.25",
|
|
28
|
+
"@fiscozen/tsconfig": "^0.1.0",
|
|
28
29
|
"@fiscozen/eslint-config": "^0.1.0",
|
|
29
|
-
"@fiscozen/prettier-config": "^0.1.0"
|
|
30
|
-
"@fiscozen/tsconfig": "^0.1.0"
|
|
30
|
+
"@fiscozen/prettier-config": "^0.1.0"
|
|
31
31
|
},
|
|
32
32
|
"license": "ISC",
|
|
33
33
|
"scripts": {
|
package/src/FzFloating.vue
CHANGED
|
@@ -9,8 +9,6 @@ const props = withDefaults(defineProps<FzFloatingProps>(), {
|
|
|
9
9
|
teleport: false
|
|
10
10
|
})
|
|
11
11
|
|
|
12
|
-
const emits = defineEmits(['fzfloating:setPosition'])
|
|
13
|
-
|
|
14
12
|
const opener = ref(null)
|
|
15
13
|
const content = ref<HTMLElement | null>(null)
|
|
16
14
|
|
|
@@ -19,15 +17,10 @@ const slots = useSlots()
|
|
|
19
17
|
const useFloatingOpts: FzUseFloatingArgs = {
|
|
20
18
|
position: computed(() => props.position),
|
|
21
19
|
element: {
|
|
22
|
-
// @ts-ignore
|
|
23
20
|
domRef: content
|
|
24
21
|
},
|
|
25
22
|
container: {
|
|
26
|
-
// @ts-ignore
|
|
27
23
|
domRef: toRef(props.container || document.body)
|
|
28
|
-
},
|
|
29
|
-
callback(...args) {
|
|
30
|
-
emits('fzfloating:setPosition', ...args)
|
|
31
24
|
}
|
|
32
25
|
}
|
|
33
26
|
if (slots.opener) {
|
|
@@ -3,119 +3,107 @@
|
|
|
3
3
|
exports[`FzFloating > should match snapshot 1`] = `
|
|
4
4
|
"<div>
|
|
5
5
|
<div class="inline-flex"><button>opener</button></div>
|
|
6
|
-
<div class="
|
|
6
|
+
<div class="bg-core-white absolute p-4 z-10">
|
|
7
7
|
<div>content</div>
|
|
8
8
|
</div>
|
|
9
|
-
<!--v-if-->
|
|
10
9
|
</div>"
|
|
11
10
|
`;
|
|
12
11
|
|
|
13
12
|
exports[`FzFloating > should match snapshot 2`] = `
|
|
14
13
|
"<div>
|
|
15
14
|
<div class="inline-flex"><button>opener</button></div>
|
|
16
|
-
<div class="
|
|
15
|
+
<div class="bg-core-white absolute p-4 z-10">
|
|
17
16
|
<div>content</div>
|
|
18
17
|
</div>
|
|
19
|
-
<!--v-if-->
|
|
20
18
|
</div>"
|
|
21
19
|
`;
|
|
22
20
|
|
|
23
21
|
exports[`FzFloating > should match snapshot 3`] = `
|
|
24
22
|
"<div>
|
|
25
23
|
<div class="inline-flex"><button>opener</button></div>
|
|
26
|
-
<div class="
|
|
24
|
+
<div class="bg-core-white absolute p-4 z-10">
|
|
27
25
|
<div>content</div>
|
|
28
26
|
</div>
|
|
29
|
-
<!--v-if-->
|
|
30
27
|
</div>"
|
|
31
28
|
`;
|
|
32
29
|
|
|
33
30
|
exports[`FzFloating > should match snapshot 4`] = `
|
|
34
31
|
"<div>
|
|
35
32
|
<div class="inline-flex"><button>opener</button></div>
|
|
36
|
-
<div class="
|
|
33
|
+
<div class="bg-core-white absolute p-4 z-10">
|
|
37
34
|
<div>content</div>
|
|
38
35
|
</div>
|
|
39
|
-
<!--v-if-->
|
|
40
36
|
</div>"
|
|
41
37
|
`;
|
|
42
38
|
|
|
43
39
|
exports[`FzFloating > should match snapshot 5`] = `
|
|
44
40
|
"<div>
|
|
45
41
|
<div class="inline-flex"><button>opener</button></div>
|
|
46
|
-
<div class="
|
|
42
|
+
<div class="bg-core-white absolute p-4 z-10">
|
|
47
43
|
<div>content</div>
|
|
48
44
|
</div>
|
|
49
|
-
<!--v-if-->
|
|
50
45
|
</div>"
|
|
51
46
|
`;
|
|
52
47
|
|
|
53
48
|
exports[`FzFloating > should match snapshot 6`] = `
|
|
54
49
|
"<div>
|
|
55
50
|
<div class="inline-flex"><button>opener</button></div>
|
|
56
|
-
<div class="
|
|
51
|
+
<div class="bg-core-white absolute p-4 z-10">
|
|
57
52
|
<div>content</div>
|
|
58
53
|
</div>
|
|
59
|
-
<!--v-if-->
|
|
60
54
|
</div>"
|
|
61
55
|
`;
|
|
62
56
|
|
|
63
57
|
exports[`FzFloating > should match snapshot 7`] = `
|
|
64
58
|
"<div>
|
|
65
59
|
<div class="inline-flex"><button>opener</button></div>
|
|
66
|
-
<div class="
|
|
60
|
+
<div class="bg-core-white absolute p-4 z-10">
|
|
67
61
|
<div>content</div>
|
|
68
62
|
</div>
|
|
69
|
-
<!--v-if-->
|
|
70
63
|
</div>"
|
|
71
64
|
`;
|
|
72
65
|
|
|
73
66
|
exports[`FzFloating > should match snapshot 8`] = `
|
|
74
67
|
"<div>
|
|
75
68
|
<div class="inline-flex"><button>opener</button></div>
|
|
76
|
-
<div class="
|
|
69
|
+
<div class="bg-core-white absolute p-4 z-10">
|
|
77
70
|
<div>content</div>
|
|
78
71
|
</div>
|
|
79
|
-
<!--v-if-->
|
|
80
72
|
</div>"
|
|
81
73
|
`;
|
|
82
74
|
|
|
83
75
|
exports[`FzFloating > should match snapshot 9`] = `
|
|
84
76
|
"<div>
|
|
85
77
|
<div class="inline-flex"><button>opener</button></div>
|
|
86
|
-
<div class="
|
|
78
|
+
<div class="bg-core-white absolute p-4 z-10">
|
|
87
79
|
<div>content</div>
|
|
88
80
|
</div>
|
|
89
|
-
<!--v-if-->
|
|
90
81
|
</div>"
|
|
91
82
|
`;
|
|
92
83
|
|
|
93
84
|
exports[`FzFloating > should match snapshot 10`] = `
|
|
94
85
|
"<div>
|
|
95
86
|
<div class="inline-flex"><button>opener</button></div>
|
|
96
|
-
<div class="
|
|
87
|
+
<div class="bg-core-white absolute p-4 z-10">
|
|
97
88
|
<div>content</div>
|
|
98
89
|
</div>
|
|
99
|
-
<!--v-if-->
|
|
100
90
|
</div>"
|
|
101
91
|
`;
|
|
102
92
|
|
|
103
93
|
exports[`FzFloating > should match snapshot 11`] = `
|
|
104
94
|
"<div>
|
|
105
95
|
<div class="inline-flex"><button>opener</button></div>
|
|
106
|
-
<div class="
|
|
96
|
+
<div class="bg-core-white absolute p-4 z-10">
|
|
107
97
|
<div>content</div>
|
|
108
98
|
</div>
|
|
109
|
-
<!--v-if-->
|
|
110
99
|
</div>"
|
|
111
100
|
`;
|
|
112
101
|
|
|
113
102
|
exports[`FzFloating > should match snapshot 12`] = `
|
|
114
103
|
"<div>
|
|
115
104
|
<div class="inline-flex"><button>opener</button></div>
|
|
116
|
-
<div class="
|
|
105
|
+
<div class="bg-core-white absolute p-4 z-10">
|
|
117
106
|
<div>content</div>
|
|
118
107
|
</div>
|
|
119
|
-
<!--v-if-->
|
|
120
108
|
</div>"
|
|
121
109
|
`;
|
package/src/composables/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { onBeforeUnmount, onMounted, Ref, watch } from 'vue'
|
|
2
2
|
|
|
3
3
|
function useClickOutside(
|
|
4
|
-
component: Ref<HTMLElement | undefined>,
|
|
4
|
+
component: Ref<HTMLElement | undefined>,
|
|
5
5
|
callback: () => void,
|
|
6
|
-
elementToListenClicksOn?: Ref<HTMLElement | undefined
|
|
6
|
+
elementToListenClicksOn?: Ref<HTMLElement | undefined>,
|
|
7
7
|
) {
|
|
8
8
|
// fail early if any of the required params is missing
|
|
9
9
|
if (!component) {
|
|
@@ -14,7 +14,7 @@ function useClickOutside(
|
|
|
14
14
|
throw new Error('A callback has to be provided.')
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const listener = (event:
|
|
17
|
+
const listener = (event: MouseEvent) => {
|
|
18
18
|
if (
|
|
19
19
|
!component.value ||
|
|
20
20
|
event.target === component.value ||
|
|
@@ -28,15 +28,12 @@ function useClickOutside(
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
if (elementToListenClicksOn) {
|
|
31
|
-
watch(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (oldVal) {
|
|
35
|
-
oldVal.removeEventListener('click', listener)
|
|
36
|
-
}
|
|
37
|
-
newVal?.addEventListener('click', listener)
|
|
31
|
+
watch(elementToListenClicksOn, (newVal: HTMLElement | undefined, oldVal: HTMLElement | undefined) => {
|
|
32
|
+
if (oldVal) {
|
|
33
|
+
oldVal.removeEventListener('click', listener)
|
|
38
34
|
}
|
|
39
|
-
|
|
35
|
+
newVal?.addEventListener('click', listener)
|
|
36
|
+
});
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
onMounted(() => {
|
|
@@ -48,7 +45,7 @@ function useClickOutside(
|
|
|
48
45
|
onBeforeUnmount(() => {
|
|
49
46
|
if (elementToListenClicksOn) {
|
|
50
47
|
elementToListenClicksOn.value!.removeEventListener('click', listener)
|
|
51
|
-
return
|
|
48
|
+
return;
|
|
52
49
|
}
|
|
53
50
|
document.removeEventListener('click', listener)
|
|
54
51
|
})
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {Ref, watch, getCurrentInstance, computed, ref} from 'vue'
|
|
2
|
+
|
|
3
|
+
export const useCurrency = () => {
|
|
4
|
+
const inputRef: Ref<HTMLInputElement|null> = ref(null)
|
|
5
|
+
const vm = getCurrentInstance()
|
|
6
|
+
|
|
7
|
+
const modelValue = computed(() => vm?.props.modelValue)
|
|
8
|
+
|
|
9
|
+
const format = (input: number) => {
|
|
10
|
+
return input.toLocaleString('it-IT', {
|
|
11
|
+
minimumFractionDigits: 2,
|
|
12
|
+
maximumFractionDigits: 2,
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const parse = (text: string) => {
|
|
17
|
+
// strip currency, handle edge cases...
|
|
18
|
+
return parseFloat(text)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const setValue = (val: number) => {
|
|
22
|
+
if (Number.isNaN(val)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
vm && vm.emit('update:modelValue', val)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const onInput = (el: HTMLInputElement) => (e: Event) => {
|
|
30
|
+
if (!inputRef.value || !e.target) {
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
let {value} = el;
|
|
34
|
+
value = value.replace(/[^0-9,.]/g, '')
|
|
35
|
+
inputRef.value.value = value;
|
|
36
|
+
const number = parse(value)
|
|
37
|
+
setValue(Number.isNaN(number) ? 0 : number)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const onBlur = (e: FocusEvent) => {
|
|
41
|
+
if (!inputRef.value || !e.target) {
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
let number = parse((e.target as HTMLInputElement).value.replace(/,/g,"."))
|
|
45
|
+
if (Number.isNaN(number)) {
|
|
46
|
+
number = 0;
|
|
47
|
+
}
|
|
48
|
+
const text = format(number)
|
|
49
|
+
|
|
50
|
+
inputRef.value.value = text;
|
|
51
|
+
setValue(number)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
watch(inputRef, (newVal, oldVal) => {
|
|
55
|
+
if(!newVal) {
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (oldVal) {
|
|
60
|
+
oldVal?.removeEventListener('input', onInput(newVal))
|
|
61
|
+
oldVal?.removeEventListener('blur', onBlur)
|
|
62
|
+
}
|
|
63
|
+
newVal.addEventListener('input', onInput(newVal))
|
|
64
|
+
newVal.addEventListener('blur', onBlur)
|
|
65
|
+
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
inputRef,
|
|
71
|
+
parse,
|
|
72
|
+
format,
|
|
73
|
+
setValue
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import { FzFloatingPosition, FzRect, FzUseFloatingArgs } from '../types'
|
|
2
|
-
import { ref, reactive, onUnmounted, Ref, nextTick } from 'vue'
|
|
2
|
+
import { ref, reactive, onUnmounted, Ref, nextTick, computed } from 'vue'
|
|
3
3
|
import { calcRealPos, getHighestAvailableSpacePos } from '../utils'
|
|
4
4
|
|
|
5
5
|
export const useFloating = (
|
|
6
6
|
args: FzUseFloatingArgs
|
|
7
7
|
): {
|
|
8
8
|
float: FzRect
|
|
9
|
-
rect: Ref<DOMRect |
|
|
9
|
+
rect: Ref<DOMRect | null>
|
|
10
|
+
floatObserver: Ref<IntersectionObserver>
|
|
10
11
|
setPosition: () => Promise<void>
|
|
11
|
-
position: Ref<FzFloatingPosition>
|
|
12
|
-
openerRect: Ref<DOMRect | undefined>
|
|
13
|
-
containerRect: Ref<DOMRect | undefined>
|
|
14
12
|
} => {
|
|
15
13
|
const safeElementDomRef = ref<HTMLElement | null>(null)
|
|
16
14
|
const safeContainerDomRef = ref<HTMLElement | null>(null)
|
|
17
15
|
const safeOpenerDomRef = ref<HTMLElement | null>(null)
|
|
18
|
-
const
|
|
19
|
-
const containerRect = ref<DOMRect | undefined>()
|
|
20
|
-
const position = ref<FzFloatingPosition>('auto')
|
|
21
|
-
const rect = ref<DOMRect | undefined>()
|
|
16
|
+
const rect = ref<DOMRect | null>(null)
|
|
22
17
|
const float = reactive<FzRect>({
|
|
23
18
|
position: { x: 0, y: 0 }
|
|
24
19
|
})
|
|
@@ -35,21 +30,20 @@ export const useFloating = (
|
|
|
35
30
|
) => {}
|
|
36
31
|
|
|
37
32
|
const floatObserver = ref(new IntersectionObserver(handleIntersect, options))
|
|
38
|
-
position.value = args.position ? args.position.value : 'auto'
|
|
39
33
|
|
|
40
34
|
const setPosition = () =>
|
|
41
35
|
nextTick(() => {
|
|
42
36
|
safeElementDomRef.value =
|
|
43
|
-
|
|
44
|
-
? document.querySelector(args.element.domRef.value)
|
|
45
|
-
: args.element.domRef.value
|
|
37
|
+
typeof args.element.domRef.value === 'string'
|
|
38
|
+
? document.querySelector(args.element.domRef.value)
|
|
39
|
+
: args.element.domRef.value
|
|
46
40
|
if (!args.container) {
|
|
47
41
|
safeContainerDomRef.value = document.body
|
|
48
42
|
} else {
|
|
49
43
|
safeContainerDomRef.value =
|
|
50
|
-
|
|
44
|
+
typeof args.container.domRef.value === 'string'
|
|
51
45
|
? document.querySelector(args.container.domRef.value)
|
|
52
|
-
: args.container.domRef.value
|
|
46
|
+
: args.container.domRef.value
|
|
53
47
|
safeContainerDomRef.value ??= document.body
|
|
54
48
|
}
|
|
55
49
|
|
|
@@ -59,102 +53,77 @@ export const useFloating = (
|
|
|
59
53
|
|
|
60
54
|
if (args.opener) {
|
|
61
55
|
safeOpenerDomRef.value =
|
|
62
|
-
|
|
56
|
+
typeof args.opener.domRef.value === 'string'
|
|
63
57
|
? document.querySelector(args.opener.domRef.value)
|
|
64
|
-
: args.opener.domRef.value
|
|
58
|
+
: args.opener.domRef.value
|
|
65
59
|
}
|
|
66
60
|
|
|
67
61
|
rect.value = safeElementDomRef.value.getBoundingClientRect()
|
|
68
|
-
openerRect
|
|
69
|
-
containerRect
|
|
62
|
+
const openerRect = safeOpenerDomRef.value?.getBoundingClientRect()
|
|
63
|
+
const containerRect = safeContainerDomRef.value.getBoundingClientRect()
|
|
70
64
|
|
|
71
|
-
const elStyle = window.getComputedStyle(safeElementDomRef.value
|
|
65
|
+
const elStyle = window.getComputedStyle(safeElementDomRef.value)
|
|
72
66
|
|
|
73
67
|
// multiple observer calls on same target do not cause multiple registrations
|
|
74
|
-
floatObserver.value.observe(safeElementDomRef.value
|
|
75
|
-
floatObserver.value.observe(safeContainerDomRef.value
|
|
68
|
+
floatObserver.value.observe(safeElementDomRef.value)
|
|
69
|
+
floatObserver.value.observe(safeContainerDomRef.value)
|
|
70
|
+
|
|
71
|
+
let position: FzFloatingPosition = args.position ? args.position.value : 'auto'
|
|
76
72
|
|
|
77
73
|
let translateY = 0
|
|
78
74
|
let translateX = 0
|
|
79
75
|
|
|
80
|
-
if (args.opener && safeOpenerDomRef.value && openerRect
|
|
76
|
+
if (args.opener && safeOpenerDomRef.value && openerRect) {
|
|
81
77
|
const leftWithoutXMargin =
|
|
82
|
-
openerRect.
|
|
83
|
-
const leftWithoutLeftMargin = openerRect.
|
|
78
|
+
openerRect.left - parseFloat(elStyle.marginLeft) - parseFloat(elStyle.marginRight)
|
|
79
|
+
const leftWithoutLeftMargin = openerRect.left - parseFloat(elStyle.marginLeft)
|
|
84
80
|
const topWithoutYMargin =
|
|
85
|
-
openerRect.
|
|
86
|
-
const topWithoutTopMargin = openerRect.
|
|
81
|
+
openerRect.top - parseFloat(elStyle.marginTop) - parseFloat(elStyle.marginBottom)
|
|
82
|
+
const topWithoutTopMargin = openerRect.top - parseFloat(elStyle.marginTop)
|
|
87
83
|
|
|
88
|
-
switch (position
|
|
84
|
+
switch (position) {
|
|
89
85
|
case 'auto':
|
|
90
|
-
position
|
|
91
|
-
safeContainerDomRef.value
|
|
92
|
-
safeElementDomRef.value
|
|
93
|
-
safeOpenerDomRef.value
|
|
94
|
-
)
|
|
95
|
-
break
|
|
96
|
-
case 'auto-vertical':
|
|
97
|
-
position.value = getHighestAvailableSpacePos(
|
|
98
|
-
safeContainerDomRef.value as HTMLElement,
|
|
99
|
-
safeElementDomRef.value as HTMLElement,
|
|
100
|
-
safeOpenerDomRef.value as HTMLElement,
|
|
101
|
-
undefined,
|
|
102
|
-
true
|
|
86
|
+
position = getHighestAvailableSpacePos(
|
|
87
|
+
safeContainerDomRef.value,
|
|
88
|
+
safeElementDomRef.value,
|
|
89
|
+
safeOpenerDomRef.value
|
|
103
90
|
)
|
|
104
91
|
break
|
|
105
92
|
case 'auto-start':
|
|
106
|
-
position
|
|
107
|
-
safeContainerDomRef.value
|
|
108
|
-
safeElementDomRef.value
|
|
109
|
-
safeOpenerDomRef.value
|
|
93
|
+
position = getHighestAvailableSpacePos(
|
|
94
|
+
safeContainerDomRef.value,
|
|
95
|
+
safeElementDomRef.value,
|
|
96
|
+
safeOpenerDomRef.value,
|
|
110
97
|
'start'
|
|
111
98
|
)
|
|
112
99
|
break
|
|
113
|
-
case 'auto-vertical-start':
|
|
114
|
-
position.value = getHighestAvailableSpacePos(
|
|
115
|
-
safeContainerDomRef.value as HTMLElement,
|
|
116
|
-
safeElementDomRef.value as HTMLElement,
|
|
117
|
-
safeOpenerDomRef.value as HTMLElement,
|
|
118
|
-
'start',
|
|
119
|
-
true
|
|
120
|
-
)
|
|
121
|
-
break
|
|
122
100
|
case 'auto-end':
|
|
123
|
-
position
|
|
124
|
-
safeContainerDomRef.value
|
|
125
|
-
safeElementDomRef.value
|
|
126
|
-
safeOpenerDomRef.value
|
|
101
|
+
position = getHighestAvailableSpacePos(
|
|
102
|
+
safeContainerDomRef.value,
|
|
103
|
+
safeElementDomRef.value,
|
|
104
|
+
safeOpenerDomRef.value,
|
|
127
105
|
'end'
|
|
128
106
|
)
|
|
129
107
|
break
|
|
130
|
-
case 'auto-vertical-end':
|
|
131
|
-
position.value = getHighestAvailableSpacePos(
|
|
132
|
-
safeContainerDomRef.value as HTMLElement,
|
|
133
|
-
safeElementDomRef.value as HTMLElement,
|
|
134
|
-
safeOpenerDomRef.value as HTMLElement,
|
|
135
|
-
'end',
|
|
136
|
-
true
|
|
137
|
-
)
|
|
138
|
-
break
|
|
139
108
|
default:
|
|
140
109
|
break
|
|
141
110
|
}
|
|
142
|
-
switch (position
|
|
111
|
+
switch (position) {
|
|
143
112
|
case 'bottom':
|
|
144
|
-
float.position.y = openerRect.
|
|
145
|
-
float.position.x = leftWithoutLeftMargin + openerRect.
|
|
113
|
+
float.position.y = openerRect.bottom
|
|
114
|
+
float.position.x = leftWithoutLeftMargin + openerRect.width / 2
|
|
146
115
|
translateX = -50
|
|
147
116
|
translateY = 0
|
|
148
117
|
break
|
|
149
118
|
case 'bottom-start':
|
|
150
|
-
float.position.y = openerRect.
|
|
119
|
+
float.position.y = openerRect.bottom
|
|
151
120
|
float.position.x = leftWithoutXMargin
|
|
152
121
|
translateX = 0
|
|
153
122
|
translateY = 0
|
|
154
123
|
break
|
|
155
124
|
case 'bottom-end':
|
|
156
|
-
float.position.y = openerRect.
|
|
157
|
-
float.position.x = openerRect.
|
|
125
|
+
float.position.y = openerRect.bottom
|
|
126
|
+
float.position.x = openerRect.right
|
|
158
127
|
translateX = -100
|
|
159
128
|
translateY = 0
|
|
160
129
|
break
|
|
@@ -165,13 +134,13 @@ export const useFloating = (
|
|
|
165
134
|
translateY = 0
|
|
166
135
|
break
|
|
167
136
|
case 'left':
|
|
168
|
-
float.position.y = topWithoutTopMargin + openerRect.
|
|
137
|
+
float.position.y = topWithoutTopMargin + openerRect.height / 2
|
|
169
138
|
float.position.x = leftWithoutXMargin
|
|
170
139
|
translateY = -50
|
|
171
140
|
translateX = -100
|
|
172
141
|
break
|
|
173
142
|
case 'left-end':
|
|
174
|
-
float.position.y = openerRect.
|
|
143
|
+
float.position.y = openerRect.bottom
|
|
175
144
|
float.position.x = leftWithoutXMargin
|
|
176
145
|
translateY = -100
|
|
177
146
|
translateX = -100
|
|
@@ -184,31 +153,31 @@ export const useFloating = (
|
|
|
184
153
|
break
|
|
185
154
|
case 'top':
|
|
186
155
|
float.position.y = topWithoutYMargin
|
|
187
|
-
float.position.x = leftWithoutLeftMargin + openerRect.
|
|
156
|
+
float.position.x = leftWithoutLeftMargin + openerRect.width / 2
|
|
188
157
|
translateX = -50
|
|
189
158
|
translateY = -100
|
|
190
159
|
break
|
|
191
160
|
case 'top-end':
|
|
192
161
|
float.position.y = topWithoutYMargin
|
|
193
|
-
float.position.x = openerRect.
|
|
162
|
+
float.position.x = openerRect.right
|
|
194
163
|
translateX = -100
|
|
195
164
|
translateY = -100
|
|
196
165
|
break
|
|
197
166
|
case 'right-start':
|
|
198
167
|
float.position.y = topWithoutYMargin
|
|
199
|
-
float.position.x = openerRect.
|
|
168
|
+
float.position.x = openerRect.right
|
|
200
169
|
translateX = 0
|
|
201
170
|
translateY = 0
|
|
202
171
|
break
|
|
203
172
|
case 'right':
|
|
204
|
-
float.position.y = topWithoutTopMargin + openerRect.
|
|
205
|
-
float.position.x = openerRect.
|
|
173
|
+
float.position.y = topWithoutTopMargin + openerRect.height / 2
|
|
174
|
+
float.position.x = openerRect.right
|
|
206
175
|
translateY = -50
|
|
207
176
|
translateX = 0
|
|
208
177
|
break
|
|
209
178
|
case 'right-end':
|
|
210
|
-
float.position.y = openerRect.
|
|
211
|
-
float.position.x = openerRect.
|
|
179
|
+
float.position.y = openerRect.bottom
|
|
180
|
+
float.position.x = openerRect.right
|
|
212
181
|
translateY = -100
|
|
213
182
|
translateX = 0
|
|
214
183
|
break
|
|
@@ -216,45 +185,42 @@ export const useFloating = (
|
|
|
216
185
|
break
|
|
217
186
|
}
|
|
218
187
|
} else {
|
|
219
|
-
switch (position
|
|
188
|
+
switch (position) {
|
|
220
189
|
case 'bottom':
|
|
221
|
-
float.position.y = containerRect.
|
|
222
|
-
float.position.x = containerRect.
|
|
190
|
+
float.position.y = containerRect.bottom - rect.value.height
|
|
191
|
+
float.position.x = containerRect.left + containerRect.width / 2
|
|
223
192
|
translateX = -50
|
|
224
193
|
break
|
|
225
194
|
case 'left-end':
|
|
226
195
|
case 'bottom-start':
|
|
227
|
-
float.position.y = containerRect.
|
|
228
|
-
float.position.x = containerRect.
|
|
196
|
+
float.position.y = containerRect.bottom - rect.value.height
|
|
197
|
+
float.position.x = containerRect.left
|
|
229
198
|
break
|
|
230
199
|
case 'right-end':
|
|
231
200
|
case 'bottom-end':
|
|
232
|
-
float.position.y = containerRect.
|
|
233
|
-
float.position.x = containerRect.
|
|
201
|
+
float.position.y = containerRect.bottom - rect.value.height
|
|
202
|
+
float.position.x = containerRect.right - rect.value.width
|
|
234
203
|
break
|
|
235
204
|
case 'left':
|
|
236
|
-
float.position.y =
|
|
237
|
-
|
|
238
|
-
float.position.x = containerRect.value.left
|
|
205
|
+
float.position.y = containerRect.top + (containerRect.height - rect.value.height) / 2
|
|
206
|
+
float.position.x = containerRect.left
|
|
239
207
|
break
|
|
240
208
|
case 'top-start':
|
|
241
209
|
case 'left-start':
|
|
242
|
-
float.position.y = containerRect.
|
|
243
|
-
float.position.x = containerRect.
|
|
210
|
+
float.position.y = containerRect.top
|
|
211
|
+
float.position.x = containerRect.left
|
|
244
212
|
break
|
|
245
213
|
case 'top':
|
|
246
|
-
float.position.y = containerRect.
|
|
247
|
-
float.position.x =
|
|
248
|
-
containerRect.value.left + (containerRect.value.width - rect.value.width) / 2
|
|
214
|
+
float.position.y = containerRect.top
|
|
215
|
+
float.position.x = containerRect.left + (containerRect.width - rect.value.width) / 2
|
|
249
216
|
break
|
|
250
217
|
case 'top-end':
|
|
251
218
|
case 'right-start':
|
|
252
|
-
float.position.y = containerRect.
|
|
253
|
-
float.position.x = containerRect.
|
|
219
|
+
float.position.y = containerRect.top
|
|
220
|
+
float.position.x = containerRect.right - rect.value.width
|
|
254
221
|
case 'right':
|
|
255
|
-
float.position.y =
|
|
256
|
-
|
|
257
|
-
float.position.x = containerRect.value.right - rect.value.width
|
|
222
|
+
float.position.y = containerRect.top + (containerRect.height - rect.value.height) / 2
|
|
223
|
+
float.position.x = containerRect.right - rect.value.width
|
|
258
224
|
break
|
|
259
225
|
default:
|
|
260
226
|
break
|
|
@@ -266,29 +232,23 @@ export const useFloating = (
|
|
|
266
232
|
float.position.x = realPos.x
|
|
267
233
|
float.position.y = realPos.y
|
|
268
234
|
|
|
269
|
-
if (realPos.x < containerRect.
|
|
270
|
-
float.position.x = containerRect.
|
|
235
|
+
if (realPos.x < containerRect.left) {
|
|
236
|
+
float.position.x = containerRect.left
|
|
271
237
|
translateX = 0
|
|
272
238
|
}
|
|
273
239
|
|
|
274
|
-
if (realPos.x + rect.value.width > containerRect.
|
|
275
|
-
|
|
276
|
-
if (fixVal > 0) {
|
|
277
|
-
float.position.x = fixVal
|
|
278
|
-
}
|
|
240
|
+
if (realPos.x + rect.value.width > containerRect.right) {
|
|
241
|
+
float.position.x = containerRect.right - rect.value.width
|
|
279
242
|
translateX = 0
|
|
280
243
|
}
|
|
281
244
|
|
|
282
|
-
if (realPos.y < containerRect.
|
|
283
|
-
float.position.y = containerRect.
|
|
245
|
+
if (realPos.y < containerRect.top) {
|
|
246
|
+
float.position.y = containerRect.top
|
|
284
247
|
translateY = 0
|
|
285
248
|
}
|
|
286
249
|
|
|
287
|
-
if (realPos.y + rect.value.height > containerRect.
|
|
288
|
-
|
|
289
|
-
if (fixVal > 0) {
|
|
290
|
-
float.position.y = fixVal
|
|
291
|
-
}
|
|
250
|
+
if (realPos.y + rect.value.height > containerRect.bottom) {
|
|
251
|
+
float.position.y = containerRect.bottom - rect.value.height
|
|
292
252
|
translateY = 0
|
|
293
253
|
}
|
|
294
254
|
|
|
@@ -298,8 +258,6 @@ export const useFloating = (
|
|
|
298
258
|
safeElementDomRef.value.style.display = 'flex'
|
|
299
259
|
|
|
300
260
|
rect.value = safeElementDomRef.value.getBoundingClientRect()
|
|
301
|
-
|
|
302
|
-
args.callback && args.callback(rect, openerRect, containerRect, position)
|
|
303
261
|
})
|
|
304
262
|
|
|
305
263
|
onUnmounted(() => {
|
|
@@ -309,9 +267,7 @@ export const useFloating = (
|
|
|
309
267
|
return {
|
|
310
268
|
float,
|
|
311
269
|
rect,
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
openerRect,
|
|
315
|
-
containerRect
|
|
270
|
+
floatObserver,
|
|
271
|
+
setPosition
|
|
316
272
|
}
|
|
317
273
|
}
|