@fiscozen/composables 0.1.35 → 0.1.36-beta.1

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": "@fiscozen/composables",
3
- "version": "0.1.35",
3
+ "version": "0.1.36-beta.1",
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": {
@@ -1,5 +1,5 @@
1
1
  <script lang="ts" setup>
2
- import { ref, useSlots, watch, toRef, computed, onBeforeUnmount, toRefs } from 'vue'
2
+ import { ref, useSlots, watch, toRef, computed, onBeforeUnmount, toRefs, defineExpose } from 'vue'
3
3
  import { useFloating } from './composables'
4
4
  import { FzFloatingProps, FzUseFloatingArgs } from './types'
5
5
 
@@ -11,8 +11,8 @@ const props = withDefaults(defineProps<FzFloatingProps>(), {
11
11
 
12
12
  const emits = defineEmits(['fzfloating:setPosition'])
13
13
 
14
- const content = ref<HTMLElement | null>(null)
15
- const opener = ref<HTMLElement | null>(null)
14
+ const content = ref<HTMLElement>()
15
+ const opener = ref<HTMLElement>()
16
16
 
17
17
  const slots = useSlots()
18
18
 
@@ -101,6 +101,10 @@ const contentClass = computed(() => {
101
101
 
102
102
  return ['bg-core-white fixed p-4', props.contentClass]
103
103
  })
104
+
105
+ defineExpose({
106
+ setPosition: floating.setPosition
107
+ })
104
108
  </script>
105
109
 
106
110
  <template>
@@ -123,7 +127,7 @@ const contentClass = computed(() => {
123
127
  <div
124
128
  ref="content"
125
129
  v-show="$slots.default && (!$slots.opener || ($slots.opener && isOpen))"
126
- class="fz__floating__content"
130
+ class="fz__floating__content bg-core-black"
127
131
  :class="contentClass"
128
132
  >
129
133
  <slot :isOpen :floating></slot>
@@ -38,7 +38,7 @@ export const useFloating = (
38
38
  const floatObserver = ref(new IntersectionObserver(handleIntersect, options))
39
39
  const actualPosition = ref<FzFloatingPosition>()
40
40
 
41
- const setPosition = () =>
41
+ const setPosition = (ignoreCallback: boolean = false) =>
42
42
  nextTick(() => {
43
43
  actualPosition.value = args.position ? args.position.value : 'auto'
44
44
  safeElementDomRef.value = (
@@ -297,9 +297,6 @@ export const useFloating = (
297
297
  translateY = 0
298
298
  }
299
299
 
300
- if(float.position.y < 0) float.position.y = 0
301
- if(float.position.x < 0) float.position.x = 0
302
-
303
300
  safeElementDomRef.value.style.top = `${float.position.y}px`
304
301
  safeElementDomRef.value.style.left = `${float.position.x}px`
305
302
  safeElementDomRef.value.style.position = 'fixed'
@@ -307,7 +304,7 @@ export const useFloating = (
307
304
 
308
305
  rect.value = safeElementDomRef.value.getBoundingClientRect()
309
306
 
310
- if (args.callback?.value) {
307
+ if (args.callback?.value && !ignoreCallback) {
311
308
  args.callback.value(rect, openerRect, containerRect, position, actualPosition)
312
309
  }
313
310
  })
@@ -1,212 +0,0 @@
1
- import { ref as d, reactive as w, onUnmounted as O, nextTick as B, defineComponent as $, useSlots as C, computed as P, toRef as S, watch as y, openBlock as z, createElementBlock as F, createElementVNode as k, renderSlot as R, unref as x, withDirectives as N, vShow as E } from "vue";
2
- const g = (s, n, l, p) => {
3
- let i = "right", e = "right-start";
4
- const r = s.getBoundingClientRect(), c = n.getBoundingClientRect(), h = l.getBoundingClientRect(), m = (h.left - r.left - c.width) / r.width, t = (r.right - h.right - c.width) / r.width, o = (h.top - r.top - c.height) / r.height, f = (r.bottom - h.bottom - c.height) / r.height;
5
- if (i = [
6
- {
7
- key: "right",
8
- space: t
9
- },
10
- {
11
- key: "top",
12
- space: o
13
- },
14
- {
15
- key: "bottom",
16
- space: f
17
- },
18
- {
19
- key: "left",
20
- space: m
21
- }
22
- ].sort((a, v) => v.space - a.space)[0].key, !p)
23
- switch (i) {
24
- case "right":
25
- case "left":
26
- const a = (c.height - h.height) / 2;
27
- r.top > h.top - a && (p = "end"), r.bottom < h.top - a && (p = "start");
28
- break;
29
- }
30
- return e = p ? `${i}-${p}` : i, e;
31
- }, q = (s, n, l, p) => ({
32
- x: n.x + s.width * l / 100,
33
- y: n.y + s.height * p / 100
34
- }), D = (s) => {
35
- const n = d(null), l = d(null), p = d(null), i = d(null), e = w({
36
- position: { x: 0, y: 0 }
37
- }), r = {
38
- root: null,
39
- rootMargin: "0px",
40
- threshold: 1,
41
- ...s.element.intersectionOptions
42
- }, c = (t, o) => {
43
- }, h = d(new IntersectionObserver(c, r)), m = () => B(() => {
44
- var b;
45
- if (n.value = typeof s.element.domRef.value == "string" ? document.querySelector(s.element.domRef.value) : s.element.domRef.value, s.container ? (l.value = typeof s.container.domRef.value == "string" ? document.querySelector(s.container.domRef.value) : s.container.domRef.value, l.value ?? (l.value = document.body)) : l.value = document.body, !n.value)
46
- throw new Error("missing reference element for floating behavior");
47
- s.opener && (p.value = typeof s.opener.domRef.value == "string" ? document.querySelector(s.opener.domRef.value) : s.opener.domRef.value), i.value = n.value.getBoundingClientRect();
48
- const t = (b = p.value) == null ? void 0 : b.getBoundingClientRect(), o = l.value.getBoundingClientRect();
49
- h.value.observe(n.value), h.value.observe(l.value);
50
- let f = s.position ? s.position.value : "auto", u = 0, a = 0;
51
- if (s.opener && p.value && t) {
52
- switch (f) {
53
- case "auto":
54
- f = g(
55
- l.value,
56
- n.value,
57
- p.value
58
- );
59
- break;
60
- case "auto-start":
61
- f = g(
62
- l.value,
63
- n.value,
64
- p.value,
65
- "start"
66
- );
67
- break;
68
- case "auto-end":
69
- f = g(
70
- l.value,
71
- n.value,
72
- p.value,
73
- "end"
74
- );
75
- break;
76
- }
77
- switch (f) {
78
- case "bottom":
79
- e.position.y = t.bottom, e.position.x = t.left + t.width / 2, a = -50, u = 0;
80
- break;
81
- case "bottom-start":
82
- e.position.y = t.bottom, e.position.x = t.left, a = 0, u = 0;
83
- break;
84
- case "bottom-end":
85
- e.position.y = t.bottom, e.position.x = t.right, a = -100, u = 0;
86
- break;
87
- case "left-start":
88
- e.position.y = t.top, e.position.x = t.left, a = -100, u = 0;
89
- break;
90
- case "left":
91
- e.position.y = t.top + t.height / 2, e.position.x = t.left, u = -50, a = -100;
92
- break;
93
- case "left-end":
94
- e.position.y = t.bottom, e.position.x = t.left, u = -100, a = -100;
95
- break;
96
- case "top-start":
97
- e.position.y = t.top, e.position.x = t.left, u = -100, a = 0;
98
- break;
99
- case "top":
100
- e.position.y = t.top, e.position.x = t.left + t.width / 2, a = -50, u = -100;
101
- break;
102
- case "top-end":
103
- e.position.y = t.top, e.position.x = t.right, a = -100, u = -100;
104
- break;
105
- case "right-start":
106
- e.position.y = t.top, e.position.x = t.right, a = 0, u = 0;
107
- break;
108
- case "right":
109
- e.position.y = t.top + t.height / 2, e.position.x = t.right, u = -50, a = 0;
110
- break;
111
- case "right-end":
112
- e.position.y = t.bottom, e.position.x = t.right, u = -100, a = 0;
113
- break;
114
- }
115
- } else
116
- switch (f) {
117
- case "bottom":
118
- e.position.y = o.bottom - i.value.height, e.position.x = o.left + o.width / 2, a = -50;
119
- break;
120
- case "left-end":
121
- case "bottom-start":
122
- e.position.y = o.bottom - i.value.height, e.position.x = o.left;
123
- break;
124
- case "right-end":
125
- case "bottom-end":
126
- e.position.y = o.bottom - i.value.height, e.position.x = o.right - i.value.width;
127
- break;
128
- case "left":
129
- e.position.y = o.top + (o.height - i.value.height) / 2, e.position.x = o.left;
130
- break;
131
- case "top-start":
132
- case "left-start":
133
- e.position.y = o.top, e.position.x = o.left;
134
- break;
135
- case "top":
136
- e.position.y = o.top, e.position.x = o.left + (o.width - i.value.width) / 2;
137
- break;
138
- case "top-end":
139
- case "right-start":
140
- e.position.y = o.top, e.position.x = o.right - i.value.width;
141
- case "right":
142
- e.position.y = o.top + (o.height - i.value.height) / 2, e.position.x = o.right - i.value.width;
143
- break;
144
- }
145
- const v = q(i.value, e.position, a, u);
146
- v.x < o.left && (e.position.x = o.left, a = 0), v.x + i.value.width > o.right && (e.position.x = o.right - i.value.width, a = 0), v.y < o.top && (e.position.y = o.top, u = 0), v.y + i.value.height > o.bottom && (e.position.y = o.bottom - i.value.height, u = 0), n.value.style.top = `${e.position.y}px`, n.value.style.left = `${e.position.x}px`, n.value.style.transform = `translateY(${u}%) translateX(${a}%)`, n.value.style.position = "absolute", i.value = n.value.getBoundingClientRect();
147
- });
148
- return O(() => {
149
- h.value.disconnect();
150
- }), {
151
- float: e,
152
- rect: i,
153
- floatObserver: h,
154
- setPosition: m
155
- };
156
- }, I = /* @__PURE__ */ $({
157
- __name: "FzFloating",
158
- props: {
159
- isOpen: { type: Boolean, default: !1 },
160
- position: { default: "auto" },
161
- container: {}
162
- },
163
- setup(s) {
164
- const n = s, l = d(null), p = d(null), i = C(), e = {
165
- position: P(() => n.position),
166
- element: {
167
- domRef: p
168
- },
169
- container: {
170
- domRef: S(n.container || document.body)
171
- }
172
- };
173
- i.opener && (e.opener = {
174
- domRef: l
175
- });
176
- const r = D(e);
177
- return y(
178
- () => n.position,
179
- () => n.isOpen && r.setPosition()
180
- ), y(
181
- () => n.isOpen,
182
- (c) => c && r.setPosition()
183
- ), (c, h) => (z(), F("div", null, [
184
- k("div", {
185
- ref_key: "opener",
186
- ref: l,
187
- class: "inline-flex"
188
- }, [
189
- R(c.$slots, "opener", {
190
- isOpen: c.isOpen,
191
- floating: x(r)
192
- })
193
- ], 512),
194
- N(k("div", {
195
- ref_key: "content",
196
- ref: p,
197
- class: "bg-core-white absolute p-4"
198
- }, [
199
- R(c.$slots, "default", {
200
- isOpen: c.isOpen,
201
- floating: x(r)
202
- })
203
- ], 512), [
204
- [E, !c.$slots.opener || c.$slots.opener && c.isOpen]
205
- ])
206
- ]));
207
- }
208
- });
209
- export {
210
- I as FzFloating,
211
- D as useFloating
212
- };
@@ -1 +0,0 @@
1
- (function(d,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],i):(d=typeof globalThis<"u"?globalThis:d||self,i(d.FzComposables={},d.Vue))})(this,function(d,i){"use strict";const g=(a,s,r,p)=>{let n="right",e="right-start";const c=a.getBoundingClientRect(),f=s.getBoundingClientRect(),u=r.getBoundingClientRect(),y=(u.left-c.left-f.width)/c.width,t=(c.right-u.right-f.width)/c.width,o=(u.top-c.top-f.height)/c.height,m=(c.bottom-u.bottom-f.height)/c.height;if(n=[{key:"right",space:t},{key:"top",space:o},{key:"bottom",space:m},{key:"left",space:y}].sort((l,b)=>b.space-l.space)[0].key,!p)switch(n){case"right":case"left":const l=(f.height-u.height)/2;c.top>u.top-l&&(p="end"),c.bottom<u.top-l&&(p="start");break}return e=p?`${n}-${p}`:n,e},R=(a,s,r,p)=>({x:s.x+a.width*r/100,y:s.y+a.height*p/100}),v=a=>{const s=i.ref(null),r=i.ref(null),p=i.ref(null),n=i.ref(null),e=i.reactive({position:{x:0,y:0}}),c={root:null,rootMargin:"0px",threshold:1,...a.element.intersectionOptions},f=(t,o)=>{},u=i.ref(new IntersectionObserver(f,c)),y=()=>i.nextTick(()=>{var k;if(s.value=typeof a.element.domRef.value=="string"?document.querySelector(a.element.domRef.value):a.element.domRef.value,a.container?(r.value=typeof a.container.domRef.value=="string"?document.querySelector(a.container.domRef.value):a.container.domRef.value,r.value??(r.value=document.body)):r.value=document.body,!s.value)throw new Error("missing reference element for floating behavior");a.opener&&(p.value=typeof a.opener.domRef.value=="string"?document.querySelector(a.opener.domRef.value):a.opener.domRef.value),n.value=s.value.getBoundingClientRect();const t=(k=p.value)==null?void 0:k.getBoundingClientRect(),o=r.value.getBoundingClientRect();u.value.observe(s.value),u.value.observe(r.value);let m=a.position?a.position.value:"auto",h=0,l=0;if(a.opener&&p.value&&t){switch(m){case"auto":m=g(r.value,s.value,p.value);break;case"auto-start":m=g(r.value,s.value,p.value,"start");break;case"auto-end":m=g(r.value,s.value,p.value,"end");break}switch(m){case"bottom":e.position.y=t.bottom,e.position.x=t.left+t.width/2,l=-50,h=0;break;case"bottom-start":e.position.y=t.bottom,e.position.x=t.left,l=0,h=0;break;case"bottom-end":e.position.y=t.bottom,e.position.x=t.right,l=-100,h=0;break;case"left-start":e.position.y=t.top,e.position.x=t.left,l=-100,h=0;break;case"left":e.position.y=t.top+t.height/2,e.position.x=t.left,h=-50,l=-100;break;case"left-end":e.position.y=t.bottom,e.position.x=t.left,h=-100,l=-100;break;case"top-start":e.position.y=t.top,e.position.x=t.left,h=-100,l=0;break;case"top":e.position.y=t.top,e.position.x=t.left+t.width/2,l=-50,h=-100;break;case"top-end":e.position.y=t.top,e.position.x=t.right,l=-100,h=-100;break;case"right-start":e.position.y=t.top,e.position.x=t.right,l=0,h=0;break;case"right":e.position.y=t.top+t.height/2,e.position.x=t.right,h=-50,l=0;break;case"right-end":e.position.y=t.bottom,e.position.x=t.right,h=-100,l=0;break}}else switch(m){case"bottom":e.position.y=o.bottom-n.value.height,e.position.x=o.left+o.width/2,l=-50;break;case"left-end":case"bottom-start":e.position.y=o.bottom-n.value.height,e.position.x=o.left;break;case"right-end":case"bottom-end":e.position.y=o.bottom-n.value.height,e.position.x=o.right-n.value.width;break;case"left":e.position.y=o.top+(o.height-n.value.height)/2,e.position.x=o.left;break;case"top-start":case"left-start":e.position.y=o.top,e.position.x=o.left;break;case"top":e.position.y=o.top,e.position.x=o.left+(o.width-n.value.width)/2;break;case"top-end":case"right-start":e.position.y=o.top,e.position.x=o.right-n.value.width;case"right":e.position.y=o.top+(o.height-n.value.height)/2,e.position.x=o.right-n.value.width;break}const b=R(n.value,e.position,l,h);b.x<o.left&&(e.position.x=o.left,l=0),b.x+n.value.width>o.right&&(e.position.x=o.right-n.value.width,l=0),b.y<o.top&&(e.position.y=o.top,h=0),b.y+n.value.height>o.bottom&&(e.position.y=o.bottom-n.value.height,h=0),s.value.style.top=`${e.position.y}px`,s.value.style.left=`${e.position.x}px`,s.value.style.transform=`translateY(${h}%) translateX(${l}%)`,s.value.style.position="absolute",n.value=s.value.getBoundingClientRect()});return i.onUnmounted(()=>{u.value.disconnect()}),{float:e,rect:n,floatObserver:u,setPosition:y}},x=i.defineComponent({__name:"FzFloating",props:{isOpen:{type:Boolean,default:!1},position:{default:"auto"},container:{}},setup(a){const s=a,r=i.ref(null),p=i.ref(null),n=i.useSlots(),e={position:i.computed(()=>s.position),element:{domRef:p},container:{domRef:i.toRef(s.container||document.body)}};n.opener&&(e.opener={domRef:r});const c=v(e);return i.watch(()=>s.position,()=>s.isOpen&&c.setPosition()),i.watch(()=>s.isOpen,f=>f&&c.setPosition()),(f,u)=>(i.openBlock(),i.createElementBlock("div",null,[i.createElementVNode("div",{ref_key:"opener",ref:r,class:"inline-flex"},[i.renderSlot(f.$slots,"opener",{isOpen:f.isOpen,floating:i.unref(c)})],512),i.withDirectives(i.createElementVNode("div",{ref_key:"content",ref:p,class:"bg-core-white absolute p-4"},[i.renderSlot(f.$slots,"default",{isOpen:f.isOpen,floating:i.unref(c)})],512),[[i.vShow,!f.$slots.opener||f.$slots.opener&&f.isOpen]])]))}});d.FzFloating=x,d.useFloating=v,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});