@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.
@@ -1,9 +1,6 @@
1
1
  import { onBeforeUnmount, onMounted, Ref } from 'vue'
2
2
 
3
- function useKeyDown(
4
- component: Ref<HTMLElement | undefined>,
5
- callback: (event: KeyboardEvent) => void
6
- ) {
3
+ function useKeyDown(component: Ref<HTMLElement | undefined>, callback: (event: KeyboardEvent) => void) {
7
4
  // fail early if any of the required params is missing
8
5
  if (!component) {
9
6
  throw new Error('A target component has to be provided.')
@@ -1,9 +1,7 @@
1
1
  import { onBeforeUnmount, onMounted, Ref } from 'vue'
2
2
 
3
- function useKeyUp(
4
- callback: (event: KeyboardEvent) => void,
5
- component?: Ref<HTMLElement | undefined>
6
- ) {
3
+ function useKeyUp(callback: (event: KeyboardEvent) => void, component?: Ref<HTMLElement | undefined>) {
4
+
7
5
  if (!callback || typeof callback !== 'function') {
8
6
  throw new Error('A callback has to be provided.')
9
7
  }
@@ -15,7 +13,7 @@ function useKeyUp(
15
13
  onMounted(() => {
16
14
  if (!component) {
17
15
  document.addEventListener('keyup', listener)
18
- return
16
+ return;
19
17
  }
20
18
  component.value!.addEventListener('keyup', listener)
21
19
  })
@@ -23,7 +21,7 @@ function useKeyUp(
23
21
  onBeforeUnmount(() => {
24
22
  if (!component) {
25
23
  document.removeEventListener('keyup', listener)
26
- return
24
+ return;
27
25
  }
28
26
  component.value!.removeEventListener('keyup', listener)
29
27
  })
package/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Ref } from 'vue'
2
2
 
3
- type PositionPrimary = 'bottom' | 'left' | 'top' | 'right' | 'auto' | 'auto-vertical'
3
+ type PositionPrimary = 'bottom' | 'left' | 'top' | 'right' | 'auto'
4
4
  type PositionSecondary = 'start' | 'end'
5
5
  export type FzFloatingPosition = PositionPrimary | `${PositionPrimary}-${PositionSecondary}`
6
6
 
@@ -40,10 +40,4 @@ export interface FzUseFloatingArgs {
40
40
  container?: FzFloatElement
41
41
  opener?: FzFloatElement
42
42
  position?: Ref<FzFloatingPosition>
43
- callback?: (
44
- rect: Ref<DOMRect | undefined>,
45
- openerRect: Ref<DOMRect | undefined>,
46
- containerRect: Ref<DOMRect | undefined>,
47
- position: Ref<FzFloatingPosition>
48
- ) => void
49
43
  }
@@ -10,12 +10,11 @@ export const getHighestAvailableSpacePos = (
10
10
  container: HTMLElement,
11
11
  el: HTMLElement,
12
12
  opener: HTMLElement,
13
- justify?: 'start' | 'end',
14
- verticalOnly?: boolean
13
+ justify?: 'start' | 'end'
15
14
  ): FzFloatingPosition => {
16
- let mainPosition: MainPosition = verticalOnly ? 'bottom' : 'right'
15
+ let mainPosition: MainPosition = 'right'
17
16
 
18
- let positionRes: FzFloatingPosition = verticalOnly ? 'bottom-start' : 'right-start'
17
+ let positionRes: FzFloatingPosition = 'right-start'
19
18
 
20
19
  const containerRect = container.getBoundingClientRect()
21
20
  const elRect = el.getBoundingClientRect()
@@ -30,7 +29,7 @@ export const getHighestAvailableSpacePos = (
30
29
  const spaceBottomNormalized =
31
30
  (containerRect.bottom - openerRect.bottom - elRect.height) / containerRect.height
32
31
 
33
- let positionList = [
32
+ const positionList = [
34
33
  {
35
34
  key: 'right',
36
35
  space: spaceRightNormalized
@@ -49,10 +48,6 @@ export const getHighestAvailableSpacePos = (
49
48
  } as PositionListItem
50
49
  ].sort((a, b) => b.space - a.space)
51
50
 
52
- if (verticalOnly) {
53
- positionList = positionList.filter((pos) => pos.key === 'top' || pos.key === 'bottom')
54
- }
55
-
56
51
  mainPosition = positionList[0].key
57
52
 
58
53
  if (!justify) {