@stacksjs/composables 0.72.57 → 0.72.60
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/useArrayUtils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ref,watch}from"@stacksjs/stx";import{isRef,unref}from"./_shared";function watchSource(source,cb){if(isRef(source))watch(source,cb)}function getArray(source){return unref(source)}export function useArrayDifference(list,other,compareFn){const result=ref([]);function update(){const arr=getArray(list),otherArr=getArray(other);if(compareFn)result.value=arr.filter((item)=>!otherArr.some((o)=>compareFn(item,o)));else result.value=arr.filter((item)=>!otherArr.includes(item))}update();watchSource(list,update);watchSource(other,update);return result}export function useArrayEvery(list,fn){const result=ref(!1);function update(){result.value=getArray(list).every(fn)}update();watchSource(list,update);return result}export function useArrayFilter(list,fn){const result=ref([]);function update(){result.value=getArray(list).filter(fn)}update();watchSource(list,update);return result}export function useArrayFind(list,fn){const result=ref(void 0);function update(){result.value=getArray(list).find(fn)}update();watchSource(list,update);return result}export function useArrayFindIndex(list,fn){const result=ref(-1);function update(){result.value=getArray(list).findIndex(fn)}update();watchSource(list,update);return result}export function useArrayIncludes(list,value,compareFn){const result=ref(!1);function update(){const arr=getArray(list),v=unref(value);if(compareFn)result.value=arr.some((item)=>compareFn(item,v));else result.value=arr.includes(v)}update();watchSource(list,update);if(isRef(value))watch(value,update);return result}export function useArrayMap(list,fn){const result=ref([]);function update(){result.value=getArray(list).map(fn)}update();watchSource(list,update);return result}export function useArrayReduce(list,fn,initialValue){const result=ref(initialValue);function update(){result.value=getArray(list).reduce(fn,initialValue)}update();watchSource(list,update);return result}export function useArraySome(list,fn){const result=ref(!1);function update(){result.value=getArray(list).some(fn)}update();watchSource(list,update);return result}export function useArrayUnique(list,compareFn){const result=ref([]);function update(){const arr=getArray(list);if(compareFn)result.value=arr.filter((item,index)=>arr.findIndex((other)=>compareFn(item,other))===index);else result.value=[...new Set(arr)]}update();watchSource(list,update);return result}
|
package/dist/useCssVar.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ref,watch}from"@stacksjs/stx";import{unref}from"./_shared";export function useCssVar(name,target,defaultValue){const variable=ref(defaultValue??""),getEl=()=>{const t=unref(target);if(t)return t;if(typeof document<"u")return document.documentElement;return null},el=getEl();if(el){const current=getComputedStyle(el).getPropertyValue(unref(name)).trim();if(current)variable.value=current}watch(variable,(val)=>{const element=getEl();if(element)element.style.setProperty(unref(name),val)});return variable}
|
package/dist/useEventListener.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{onUnmounted,watch}from"@stacksjs/stx";import{isRef,unref,noop
|
|
1
|
+
import{onUnmounted,watch}from"@stacksjs/stx";import{isRef,unref,noop}from"./_shared";export function useEventListener(target,event,handler,options){let cleanup=noop;const register=(el)=>{if(!el)return noop;el.addEventListener(event,handler,options);return()=>{el.removeEventListener(event,handler,options)}};if(isRef(target)){watch(target,(_newTarget,_oldTarget)=>{cleanup();cleanup=register(unref(target))});cleanup=register(target.value)}else cleanup=register(target);const stop=()=>{cleanup();cleanup=noop};try{onUnmounted(stop)}catch{}return stop}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{onUnmounted,ref
|
|
1
|
+
import{onUnmounted,ref}from"@stacksjs/stx";import{unref}from"./_shared";export function useInfiniteScroll(target,onLoadMore,options={}){const{distance=100,direction="bottom"}=options,isLoading=ref(!1);let active=!0;const handler=async()=>{if(!active||isLoading.value)return;const el=unref(target);if(!el)return;let shouldLoad=!1;if(el===window||el===document.documentElement){const scrollTop=window.scrollY||document.documentElement.scrollTop,scrollHeight=document.documentElement.scrollHeight,clientHeight=window.innerHeight;if(direction==="bottom")shouldLoad=scrollHeight-scrollTop-clientHeight<=distance;else if(direction==="top")shouldLoad=scrollTop<=distance}else{const element=el;if(direction==="bottom")shouldLoad=element.scrollHeight-element.scrollTop-element.clientHeight<=distance;else if(direction==="top")shouldLoad=element.scrollTop<=distance;else if(direction==="right")shouldLoad=element.scrollWidth-element.scrollLeft-element.clientWidth<=distance;else if(direction==="left")shouldLoad=element.scrollLeft<=distance}if(shouldLoad){isLoading.value=!0;try{await onLoadMore()}finally{isLoading.value=!1}}},el=unref(target);if(el){const scrollTarget=el===document.documentElement?window:el;scrollTarget.addEventListener("scroll",handler,{passive:!0});try{onUnmounted(()=>{active=!1;scrollTarget.removeEventListener("scroll",handler)})}catch{}}return{isLoading}}
|
package/dist/useMath.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{computed
|
|
1
|
+
import{computed}from"@stacksjs/stx";function unref(val){if(val&&typeof val==="object"&&"value"in val&&"subscribe"in val)return val.value;return val}export function useAbs(value){return computed(()=>Math.abs(unref(value)))}export function useAverage(...args){return computed(()=>{const values=args.map(unref);return values.length?values.reduce((a,b)=>a+b,0)/values.length:0})}export function useCeil(value){return computed(()=>Math.ceil(unref(value)))}export function useClamp(value,min,max){return computed(()=>Math.min(unref(max),Math.max(unref(min),unref(value))))}export function useFloor(value){return computed(()=>Math.floor(unref(value)))}export function useMax(...args){return computed(()=>Math.max(...args.map(unref)))}export function useMin(...args){return computed(()=>Math.min(...args.map(unref)))}export function usePrecision(value,digits=0){return computed(()=>Number(unref(value).toFixed(Math.max(0,Math.min(100,unref(digits))))))}export function useRound(value){return computed(()=>Math.round(unref(value)))}export function useSum(...args){return computed(()=>args.map(unref).reduce((a,b)=>a+b,0))}export function useTrunc(value){return computed(()=>Math.trunc(unref(value)))}export function logicNot(value){return computed(()=>!unref(value))}export function logicOr(...args){return computed(()=>args.some((a)=>unref(a)))}export const or=logicOr;export function and(...args){return computed(()=>args.every((a)=>unref(a)))}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ref,watch}from"@stacksjs/stx";export function useOffsetPagination(options={}){const{total:totalOption,pageSize=10,page=1,onPageChange,onPageSizeChange}=options,currentPage=ref(page),currentPageSize=ref(pageSize),totalItems=typeof totalOption==="object"&&totalOption&&"value"in totalOption?totalOption:ref(typeof totalOption==="number"?totalOption:0),pageCount=ref(Math.max(1,Math.ceil(totalItems.value/currentPageSize.value))),isFirstPage=ref(currentPage.value<=1),isLastPage=ref(currentPage.value>=pageCount.value);function updateComputed(){pageCount.value=Math.max(1,Math.ceil(totalItems.value/currentPageSize.value));isFirstPage.value=currentPage.value<=1;isLastPage.value=currentPage.value>=pageCount.value}watch(currentPage,()=>{updateComputed();onPageChange?.({currentPage:currentPage.value,currentPageSize:currentPageSize.value})});watch(currentPageSize,()=>{currentPage.value=1;updateComputed();onPageSizeChange?.({currentPage:currentPage.value,currentPageSize:currentPageSize.value})});watch(totalItems,()=>{updateComputed()});function prev(){if(currentPage.value>1)currentPage.value--}function next(){if(currentPage.value<pageCount.value)currentPage.value++}updateComputed();return{currentPage,currentPageSize,pageCount,isFirstPage,isLastPage,prev,next}}
|
package/dist/useToNumber.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ref,watch}from"@stacksjs/stx";import{toValue}from"./_shared";export function useToNumber(value,options={}){const{method="parseFloat",radix=10,nanToZero=!1}=options,result=ref(0);function convert(val){if(typeof val==="number")return val;let num;if(method==="parseInt")num=Number.parseInt(val,radix);else num=Number.parseFloat(val);if(nanToZero&&Number.isNaN(num))return 0;return num}result.value=convert(toValue(value));if(typeof value==="function");else if(value&&typeof value==="object"&&"value"in value&&"subscribe"in value)watch(value,(newVal)=>{result.value=convert(newVal)});return result}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/composables",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.72.
|
|
5
|
+
"version": "0.72.60",
|
|
6
6
|
"description": "Stacks composables powered by stx reactivity.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@stacksjs/stx": "^0.2.219",
|
|
55
|
-
"@stacksjs/datetime": "0.72.
|
|
55
|
+
"@stacksjs/datetime": "0.72.60"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"better-dx": "^0.2.24"
|