@fiscozen/composables 0.1.14 → 0.1.15

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.14",
3
+ "version": "0.1.15",
4
4
  "description": "Design System utility composables",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "vitest": "^1.2.0",
27
27
  "vue-tsc": "^1.8.25",
28
28
  "@fiscozen/eslint-config": "^0.1.0",
29
- "@fiscozen/prettier-config": "^0.1.0",
30
- "@fiscozen/tsconfig": "^0.1.0"
29
+ "@fiscozen/tsconfig": "^0.1.0",
30
+ "@fiscozen/prettier-config": "^0.1.0"
31
31
  },
32
32
  "license": "ISC",
33
33
  "scripts": {
@@ -59,6 +59,7 @@ const contentClass = computed(() => {
59
59
 
60
60
  <template>
61
61
  <div>
62
+ <slot name="opener-start"></slot>
62
63
  <div ref="opener" class="inline-flex">
63
64
  <slot name="opener" :isOpen :floating></slot>
64
65
  </div>
@@ -76,7 +77,7 @@ const contentClass = computed(() => {
76
77
  <div
77
78
  ref="content"
78
79
  v-show="$slots.default && (!$slots.opener || ($slots.opener && isOpen))"
79
- class="fz__floating__content bg-core-white fixed p-4 z-10"
80
+ class="fz__floating__content bg-core-white absolute p-4 z-10"
80
81
  :class="contentClass"
81
82
  >
82
83
  <slot :isOpen :floating></slot>
@@ -254,7 +254,7 @@ export const useFloating = (
254
254
 
255
255
  safeElementDomRef.value.style.top = `${float.position.y}px`
256
256
  safeElementDomRef.value.style.left = `${float.position.x}px`
257
- safeElementDomRef.value.style.position = 'fixed'
257
+ // safeElementDomRef.value.style.position = 'fixed'
258
258
  safeElementDomRef.value.style.display = 'flex'
259
259
 
260
260
  rect.value = safeElementDomRef.value.getBoundingClientRect()
@@ -1,299 +0,0 @@
1
- import { ref as f, reactive as M, onUnmounted as z, nextTick as P, onMounted as w, onBeforeUnmount as C, defineComponent as A, useSlots as N, computed as O, toRef as T, watch as $, openBlock as D, createElementBlock as W, createElementVNode as F, renderSlot as k, unref as S, withDirectives as q, normalizeClass as I, vShow as U } from "vue";
2
- const x = (o, t, i, n) => {
3
- let a = "right", e = "right-start";
4
- const c = o.getBoundingClientRect(), d = t.getBoundingClientRect(), r = i.getBoundingClientRect(), b = (r.left - c.left - d.width) / c.width, l = (c.right - r.right - d.width) / c.width, s = (r.top - c.top - d.height) / c.height, h = (c.bottom - r.bottom - d.height) / c.height;
5
- if (a = [
6
- {
7
- key: "right",
8
- space: l
9
- },
10
- {
11
- key: "top",
12
- space: s
13
- },
14
- {
15
- key: "bottom",
16
- space: h
17
- },
18
- {
19
- key: "left",
20
- space: b
21
- }
22
- ].sort((p, u) => u.space - p.space)[0].key, !n)
23
- switch (a) {
24
- case "right":
25
- case "left":
26
- const p = (d.height - r.height) / 2;
27
- c.top > r.top - p && (n = "end"), c.bottom < r.top - p && (n = "start");
28
- break;
29
- }
30
- return e = n ? `${a}-${n}` : a, e;
31
- }, K = (o, t, i, n) => ({
32
- x: t.x + o.width * i / 100,
33
- y: t.y + o.height * n / 100
34
- }), Q = (o) => {
35
- const t = f(null), i = f(null), n = f(null), a = f(null), e = M({
36
- position: { x: 0, y: 0 }
37
- }), c = {
38
- root: null,
39
- rootMargin: "0px",
40
- threshold: 1,
41
- ...o.element.intersectionOptions
42
- }, d = (l, s) => {
43
- }, r = f(new IntersectionObserver(d, c)), b = () => P(() => {
44
- var E;
45
- if (t.value = typeof o.element.domRef.value == "string" ? document.querySelector(o.element.domRef.value) : o.element.domRef.value, o.container ? (i.value = typeof o.container.domRef.value == "string" ? document.querySelector(o.container.domRef.value) : o.container.domRef.value, i.value ?? (i.value = document.body)) : i.value = document.body, !t.value)
46
- throw new Error("missing reference element for floating behavior");
47
- o.opener && (n.value = typeof o.opener.domRef.value == "string" ? document.querySelector(o.opener.domRef.value) : o.opener.domRef.value), a.value = t.value.getBoundingClientRect();
48
- const l = (E = n.value) == null ? void 0 : E.getBoundingClientRect(), s = i.value.getBoundingClientRect(), h = window.getComputedStyle(t.value);
49
- r.value.observe(t.value), r.value.observe(i.value);
50
- let v = o.position ? o.position.value : "auto", p = 0, u = 0;
51
- if (o.opener && n.value && l) {
52
- const g = l.left - parseFloat(h.marginLeft) - parseFloat(h.marginRight), L = l.left - parseFloat(h.marginLeft), y = l.top - parseFloat(h.marginTop) - parseFloat(h.marginBottom), B = l.top - parseFloat(h.marginTop);
53
- switch (v) {
54
- case "auto":
55
- v = x(
56
- i.value,
57
- t.value,
58
- n.value
59
- );
60
- break;
61
- case "auto-start":
62
- v = x(
63
- i.value,
64
- t.value,
65
- n.value,
66
- "start"
67
- );
68
- break;
69
- case "auto-end":
70
- v = x(
71
- i.value,
72
- t.value,
73
- n.value,
74
- "end"
75
- );
76
- break;
77
- }
78
- switch (v) {
79
- case "bottom":
80
- e.position.y = l.bottom, e.position.x = L + l.width / 2, u = -50, p = 0;
81
- break;
82
- case "bottom-start":
83
- e.position.y = l.bottom, e.position.x = g, u = 0, p = 0;
84
- break;
85
- case "bottom-end":
86
- e.position.y = l.bottom, e.position.x = l.right, u = -100, p = 0;
87
- break;
88
- case "left-start":
89
- e.position.y = y, e.position.x = g, u = -100, p = 0;
90
- break;
91
- case "left":
92
- e.position.y = B + l.height / 2, e.position.x = g, p = -50, u = -100;
93
- break;
94
- case "left-end":
95
- e.position.y = l.bottom, e.position.x = g, p = -100, u = -100;
96
- break;
97
- case "top-start":
98
- e.position.y = y, e.position.x = g, p = -100, u = 0;
99
- break;
100
- case "top":
101
- e.position.y = y, e.position.x = L + l.width / 2, u = -50, p = -100;
102
- break;
103
- case "top-end":
104
- e.position.y = y, e.position.x = l.right, u = -100, p = -100;
105
- break;
106
- case "right-start":
107
- e.position.y = y, e.position.x = l.right, u = 0, p = 0;
108
- break;
109
- case "right":
110
- e.position.y = B + l.height / 2, e.position.x = l.right, p = -50, u = 0;
111
- break;
112
- case "right-end":
113
- e.position.y = l.bottom, e.position.x = l.right, p = -100, u = 0;
114
- break;
115
- }
116
- } else
117
- switch (v) {
118
- case "bottom":
119
- e.position.y = s.bottom - a.value.height, e.position.x = s.left + s.width / 2, u = -50;
120
- break;
121
- case "left-end":
122
- case "bottom-start":
123
- e.position.y = s.bottom - a.value.height, e.position.x = s.left;
124
- break;
125
- case "right-end":
126
- case "bottom-end":
127
- e.position.y = s.bottom - a.value.height, e.position.x = s.right - a.value.width;
128
- break;
129
- case "left":
130
- e.position.y = s.top + (s.height - a.value.height) / 2, e.position.x = s.left;
131
- break;
132
- case "top-start":
133
- case "left-start":
134
- e.position.y = s.top, e.position.x = s.left;
135
- break;
136
- case "top":
137
- e.position.y = s.top, e.position.x = s.left + (s.width - a.value.width) / 2;
138
- break;
139
- case "top-end":
140
- case "right-start":
141
- e.position.y = s.top, e.position.x = s.right - a.value.width;
142
- case "right":
143
- e.position.y = s.top + (s.height - a.value.height) / 2, e.position.x = s.right - a.value.width;
144
- break;
145
- }
146
- const m = K(a.value, e.position, u, p);
147
- e.position.x = m.x, e.position.y = m.y, m.x < s.left && (e.position.x = s.left, u = 0), m.x + a.value.width > s.right && (e.position.x = s.right - a.value.width, u = 0), m.y < s.top && (e.position.y = s.top, p = 0), m.y + a.value.height > s.bottom && (e.position.y = s.bottom - a.value.height, p = 0), t.value.style.top = `${e.position.y}px`, t.value.style.left = `${e.position.x}px`, t.value.style.position = "fixed", t.value.style.display = "flex", a.value = t.value.getBoundingClientRect();
148
- });
149
- return z(() => {
150
- r.value.disconnect();
151
- }), {
152
- float: e,
153
- rect: a,
154
- floatObserver: r,
155
- setPosition: b
156
- };
157
- };
158
- function R(o) {
159
- const t = window.matchMedia(o), i = f(t.matches);
160
- function n(a) {
161
- i.value = a.matches;
162
- }
163
- return w(() => {
164
- t.addEventListener("change", n);
165
- }), z(() => {
166
- t.removeEventListener("change", n);
167
- }), i;
168
- }
169
- function Y(o) {
170
- return {
171
- isGreater(t) {
172
- return R(`(min-width: ${o[t]})`);
173
- },
174
- isSmaller(t) {
175
- return R(`(max-width: ${o[t]})`);
176
- },
177
- isInBetween(t, i) {
178
- return R(`(min-width: ${o[t]}) and (max-width: ${o[i]})`);
179
- }
180
- };
181
- }
182
- function G(o, t) {
183
- if (!o)
184
- throw new Error("A target component has to be provided.");
185
- if (!t)
186
- throw new Error("A callback has to be provided.");
187
- const i = (n) => {
188
- !o.value || n.target === o.value || n.composedPath().includes(o.value) || typeof t == "function" && t();
189
- };
190
- w(() => {
191
- window.addEventListener("click", i);
192
- }), C(() => {
193
- window.removeEventListener("click", i);
194
- });
195
- }
196
- function H(o, t) {
197
- if (!o)
198
- throw new Error("A target component has to be provided.");
199
- if (!t || typeof t != "function")
200
- throw new Error("A callback has to be provided.");
201
- const i = (n) => {
202
- t(n);
203
- };
204
- w(() => {
205
- o.value.addEventListener("keydown", i);
206
- }), C(() => {
207
- o.value.removeEventListener("keydown", i);
208
- });
209
- }
210
- function V(o, t) {
211
- if (!o || typeof o != "function")
212
- throw new Error("A callback has to be provided.");
213
- const i = (n) => {
214
- o(n);
215
- };
216
- w(() => {
217
- if (!t) {
218
- document.addEventListener("keyup", i);
219
- return;
220
- }
221
- t.value.addEventListener("keyup", i);
222
- }), C(() => {
223
- if (!t) {
224
- document.removeEventListener("keyup", i);
225
- return;
226
- }
227
- t.value.removeEventListener("keyup", i);
228
- });
229
- }
230
- const J = /* @__PURE__ */ A({
231
- __name: "FzFloating",
232
- props: {
233
- isOpen: { type: Boolean, default: !1 },
234
- position: { default: "auto" },
235
- container: {},
236
- contentClass: {},
237
- openerClass: {},
238
- overrideContentClass: { type: Boolean }
239
- },
240
- setup(o) {
241
- const t = o, i = f(null), n = f(null), a = N(), e = {
242
- position: O(() => t.position),
243
- element: {
244
- domRef: n
245
- },
246
- container: {
247
- domRef: T(t.container || document.body)
248
- }
249
- };
250
- a.opener && (e.opener = {
251
- domRef: i
252
- });
253
- const c = Q(e);
254
- $(
255
- () => t.position,
256
- () => t.isOpen && c.setPosition()
257
- ), $(
258
- () => t.isOpen,
259
- (r) => {
260
- !r || !n.value || (n.value.style.top = "0px", n.value.style.left = "0px", n.value.style.transform = "none", c.setPosition());
261
- }
262
- );
263
- const d = O(() => t.overrideContentClass ? t.contentClass : ["bg-core-white fixed p-4 z-10", t.contentClass]);
264
- return (r, b) => (D(), W("div", null, [
265
- F("div", {
266
- ref_key: "opener",
267
- ref: i,
268
- class: "inline-flex"
269
- }, [
270
- k(r.$slots, "opener", {
271
- isOpen: r.isOpen,
272
- floating: S(c)
273
- })
274
- ], 512),
275
- k(r.$slots, "opener-end"),
276
- q(F("div", {
277
- ref_key: "content",
278
- ref: n,
279
- class: I(d.value)
280
- }, [
281
- k(r.$slots, "default", {
282
- isOpen: r.isOpen,
283
- floating: S(c)
284
- })
285
- ], 2), [
286
- [U, r.$slots.default && (!r.$slots.opener || r.$slots.opener && r.isOpen)]
287
- ])
288
- ]));
289
- }
290
- });
291
- export {
292
- J as FzFloating,
293
- Y as useBreakpoints,
294
- G as useClickOutside,
295
- Q as useFloating,
296
- H as useKeyDown,
297
- V as useKeyUp,
298
- R as useMediaQuery
299
- };
@@ -1 +0,0 @@
1
- (function(f,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],o):(f=typeof globalThis<"u"?globalThis:f||self,o(f.FzComposables={},f.Vue))})(this,function(f,o){"use strict";const x=(n,t,i,s)=>{let r="right",e="right-start";const d=n.getBoundingClientRect(),h=t.getBoundingClientRect(),l=i.getBoundingClientRect(),k=(l.left-d.left-h.width)/d.width,p=(d.right-l.right-h.width)/d.width,a=(l.top-d.top-h.height)/d.height,m=(d.bottom-l.bottom-h.height)/d.height;if(r=[{key:"right",space:p},{key:"top",space:a},{key:"bottom",space:m},{key:"left",space:k}].sort((c,u)=>u.space-c.space)[0].key,!s)switch(r){case"right":case"left":const c=(h.height-l.height)/2;d.top>l.top-c&&(s="end"),d.bottom<l.top-c&&(s="start");break}return e=s?`${r}-${s}`:r,e},L=(n,t,i,s)=>({x:t.x+n.width*i/100,y:t.y+n.height*s/100}),R=n=>{const t=o.ref(null),i=o.ref(null),s=o.ref(null),r=o.ref(null),e=o.reactive({position:{x:0,y:0}}),d={root:null,rootMargin:"0px",threshold:1,...n.element.intersectionOptions},h=(p,a)=>{},l=o.ref(new IntersectionObserver(h,d)),k=()=>o.nextTick(()=>{var C;if(t.value=typeof n.element.domRef.value=="string"?document.querySelector(n.element.domRef.value):n.element.domRef.value,n.container?(i.value=typeof n.container.domRef.value=="string"?document.querySelector(n.container.domRef.value):n.container.domRef.value,i.value??(i.value=document.body)):i.value=document.body,!t.value)throw new Error("missing reference element for floating behavior");n.opener&&(s.value=typeof n.opener.domRef.value=="string"?document.querySelector(n.opener.domRef.value):n.opener.domRef.value),r.value=t.value.getBoundingClientRect();const p=(C=s.value)==null?void 0:C.getBoundingClientRect(),a=i.value.getBoundingClientRect(),m=window.getComputedStyle(t.value);l.value.observe(t.value),l.value.observe(i.value);let g=n.position?n.position.value:"auto",c=0,u=0;if(n.opener&&s.value&&p){const v=p.left-parseFloat(m.marginLeft)-parseFloat(m.marginRight),E=p.left-parseFloat(m.marginLeft),b=p.top-parseFloat(m.marginTop)-parseFloat(m.marginBottom),B=p.top-parseFloat(m.marginTop);switch(g){case"auto":g=x(i.value,t.value,s.value);break;case"auto-start":g=x(i.value,t.value,s.value,"start");break;case"auto-end":g=x(i.value,t.value,s.value,"end");break}switch(g){case"bottom":e.position.y=p.bottom,e.position.x=E+p.width/2,u=-50,c=0;break;case"bottom-start":e.position.y=p.bottom,e.position.x=v,u=0,c=0;break;case"bottom-end":e.position.y=p.bottom,e.position.x=p.right,u=-100,c=0;break;case"left-start":e.position.y=b,e.position.x=v,u=-100,c=0;break;case"left":e.position.y=B+p.height/2,e.position.x=v,c=-50,u=-100;break;case"left-end":e.position.y=p.bottom,e.position.x=v,c=-100,u=-100;break;case"top-start":e.position.y=b,e.position.x=v,c=-100,u=0;break;case"top":e.position.y=b,e.position.x=E+p.width/2,u=-50,c=-100;break;case"top-end":e.position.y=b,e.position.x=p.right,u=-100,c=-100;break;case"right-start":e.position.y=b,e.position.x=p.right,u=0,c=0;break;case"right":e.position.y=B+p.height/2,e.position.x=p.right,c=-50,u=0;break;case"right-end":e.position.y=p.bottom,e.position.x=p.right,c=-100,u=0;break}}else switch(g){case"bottom":e.position.y=a.bottom-r.value.height,e.position.x=a.left+a.width/2,u=-50;break;case"left-end":case"bottom-start":e.position.y=a.bottom-r.value.height,e.position.x=a.left;break;case"right-end":case"bottom-end":e.position.y=a.bottom-r.value.height,e.position.x=a.right-r.value.width;break;case"left":e.position.y=a.top+(a.height-r.value.height)/2,e.position.x=a.left;break;case"top-start":case"left-start":e.position.y=a.top,e.position.x=a.left;break;case"top":e.position.y=a.top,e.position.x=a.left+(a.width-r.value.width)/2;break;case"top-end":case"right-start":e.position.y=a.top,e.position.x=a.right-r.value.width;case"right":e.position.y=a.top+(a.height-r.value.height)/2,e.position.x=a.right-r.value.width;break}const y=L(r.value,e.position,u,c);e.position.x=y.x,e.position.y=y.y,y.x<a.left&&(e.position.x=a.left,u=0),y.x+r.value.width>a.right&&(e.position.x=a.right-r.value.width,u=0),y.y<a.top&&(e.position.y=a.top,c=0),y.y+r.value.height>a.bottom&&(e.position.y=a.bottom-r.value.height,c=0),t.value.style.top=`${e.position.y}px`,t.value.style.left=`${e.position.x}px`,t.value.style.position="fixed",t.value.style.display="flex",r.value=t.value.getBoundingClientRect()});return o.onUnmounted(()=>{l.value.disconnect()}),{float:e,rect:r,floatObserver:l,setPosition:k}};function w(n){const t=window.matchMedia(n),i=o.ref(t.matches);function s(r){i.value=r.matches}return o.onMounted(()=>{t.addEventListener("change",s)}),o.onUnmounted(()=>{t.removeEventListener("change",s)}),i}function O(n){return{isGreater(t){return w(`(min-width: ${n[t]})`)},isSmaller(t){return w(`(max-width: ${n[t]})`)},isInBetween(t,i){return w(`(min-width: ${n[t]}) and (max-width: ${n[i]})`)}}}function F(n,t){if(!n)throw new Error("A target component has to be provided.");if(!t)throw new Error("A callback has to be provided.");const i=s=>{!n.value||s.target===n.value||s.composedPath().includes(n.value)||typeof t=="function"&&t()};o.onMounted(()=>{window.addEventListener("click",i)}),o.onBeforeUnmount(()=>{window.removeEventListener("click",i)})}function S(n,t){if(!n)throw new Error("A target component has to be provided.");if(!t||typeof t!="function")throw new Error("A callback has to be provided.");const i=s=>{t(s)};o.onMounted(()=>{n.value.addEventListener("keydown",i)}),o.onBeforeUnmount(()=>{n.value.removeEventListener("keydown",i)})}function $(n,t){if(!n||typeof n!="function")throw new Error("A callback has to be provided.");const i=s=>{n(s)};o.onMounted(()=>{if(!t){document.addEventListener("keyup",i);return}t.value.addEventListener("keyup",i)}),o.onBeforeUnmount(()=>{if(!t){document.removeEventListener("keyup",i);return}t.value.removeEventListener("keyup",i)})}const M=o.defineComponent({__name:"FzFloating",props:{isOpen:{type:Boolean,default:!1},position:{default:"auto"},container:{},contentClass:{},openerClass:{},overrideContentClass:{type:Boolean}},setup(n){const t=n,i=o.ref(null),s=o.ref(null),r=o.useSlots(),e={position:o.computed(()=>t.position),element:{domRef:s},container:{domRef:o.toRef(t.container||document.body)}};r.opener&&(e.opener={domRef:i});const d=R(e);o.watch(()=>t.position,()=>t.isOpen&&d.setPosition()),o.watch(()=>t.isOpen,l=>{!l||!s.value||(s.value.style.top="0px",s.value.style.left="0px",s.value.style.transform="none",d.setPosition())});const h=o.computed(()=>t.overrideContentClass?t.contentClass:["bg-core-white fixed p-4 z-10",t.contentClass]);return(l,k)=>(o.openBlock(),o.createElementBlock("div",null,[o.createElementVNode("div",{ref_key:"opener",ref:i,class:"inline-flex"},[o.renderSlot(l.$slots,"opener",{isOpen:l.isOpen,floating:o.unref(d)})],512),o.renderSlot(l.$slots,"opener-end"),o.withDirectives(o.createElementVNode("div",{ref_key:"content",ref:s,class:o.normalizeClass(h.value)},[o.renderSlot(l.$slots,"default",{isOpen:l.isOpen,floating:o.unref(d)})],2),[[o.vShow,l.$slots.default&&(!l.$slots.opener||l.$slots.opener&&l.isOpen)]])]))}});f.FzFloating=M,f.useBreakpoints=O,f.useClickOutside=F,f.useFloating=R,f.useKeyDown=S,f.useKeyUp=$,f.useMediaQuery=w,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});