@agnos-ui/core
Advanced tools
Comparing version 0.0.1-alpha.6 to 0.0.1-alpha.7
import type { CommonAlertApi, CommonAlertDirectives, CommonAlertProps, CommonAlertState } from './common'; | ||
import type { ExtendWidgetAdaptSlotWidgetProps } from '../../services/extendWidget'; | ||
import type { Widget, WidgetFactory, WidgetSlotContext } from '../../types'; | ||
export * from './common'; | ||
export type AlertContext = WidgetSlotContext<AlertWidget>; | ||
@@ -6,0 +5,0 @@ export interface AlertExtraProps { |
import { createCommonAlert, getCommonAlertDefaultConfig } from './common'; | ||
import { extendWidgetProps } from '../../services/extendWidget'; | ||
import { typeString } from '../../utils/writables'; | ||
export * from './common'; | ||
const alertDefaultConfig = { | ||
@@ -6,0 +5,0 @@ type: 'primary', |
import type { PropsConfig, Widget, SlotContent, WidgetSlotContext } from '../../types'; | ||
import type { WidgetsCommonPropsAndState } from '../commonProps'; | ||
export * from './bootstrap'; | ||
/** | ||
@@ -5,0 +4,0 @@ * A type for the slot context of the pagination widget |
@@ -7,3 +7,2 @@ import { computed } from '@amadeus-it-group/tansu'; | ||
import { noop } from '../../utils/internal/func'; | ||
export * from './bootstrap'; | ||
const defaultConfig = { | ||
@@ -10,0 +9,0 @@ page: 1, |
@@ -172,2 +172,8 @@ import type { WidgetsCommonPropsAndState } from '../commonProps'; | ||
mouseDown(event: MouseEvent, handleId: number): void; | ||
/** | ||
* Method describing the behavior of the slider handle on touch start event | ||
* @param event - touch event | ||
* @param handleId - number id of the handle | ||
*/ | ||
touchStart(event: TouchEvent, handleId: number): void; | ||
} | ||
@@ -174,0 +180,0 @@ export type SliderWidget = Widget<SliderProps, SliderState, SliderApi, SliderActions, SliderDirectives>; |
@@ -387,4 +387,28 @@ import { computed, derived, writable } from '@amadeus-it-group/tansu'; | ||
}, | ||
touchStart(event, handleId) { | ||
event.preventDefault(); | ||
const handleDrag = (e) => { | ||
e.preventDefault(); | ||
const newCoord = vertical$() ? e.touches[0].clientY : e.touches[0].clientX; | ||
event.target.focus(); | ||
if (_prevCoordinate !== newCoord) { | ||
_prevCoordinate = newCoord; | ||
adjustCoordinate(newCoord, handleId); | ||
} | ||
}; | ||
if (isInteractable$()) { | ||
event.target.focus(); | ||
document.addEventListener('touchmove', handleDrag); | ||
document.addEventListener('touchend', () => { | ||
document.removeEventListener('touchmove', handleDrag); | ||
document.removeEventListener('touchcancel', handleDrag); | ||
}, { once: true }); | ||
document.addEventListener('touchcancel', () => { | ||
document.removeEventListener('touchmove', handleDrag); | ||
document.removeEventListener('touchend', handleDrag); | ||
}, { once: true }); | ||
} | ||
}, | ||
}, | ||
}; | ||
} |
export * from './components/commonProps'; | ||
export * from './types'; | ||
export * from './components/accordion/accordion'; | ||
export * from './components/alert/alert'; | ||
export * from './components/modal/modal'; | ||
export * from './components/pagination/pagination'; | ||
export * from './components/progressbar/progressbar'; | ||
export * from './components/rating/rating'; | ||
export * from './components/select/select'; | ||
export * from './components/slider/slider'; | ||
export * from './components/accordion'; | ||
export * from './components/alert'; | ||
export * from './components/modal'; | ||
export * from './components/pagination'; | ||
export * from './components/progressbar'; | ||
export * from './components/rating'; | ||
export * from './components/select'; | ||
export * from './components/slider'; | ||
export * from './config'; | ||
@@ -12,0 +12,0 @@ export * from './services/extendWidget'; |
16
index.js
@@ -5,10 +5,10 @@ // types | ||
// components | ||
export * from './components/accordion/accordion'; | ||
export * from './components/alert/alert'; | ||
export * from './components/modal/modal'; | ||
export * from './components/pagination/pagination'; | ||
export * from './components/progressbar/progressbar'; | ||
export * from './components/rating/rating'; | ||
export * from './components/select/select'; | ||
export * from './components/slider/slider'; | ||
export * from './components/accordion'; | ||
export * from './components/alert'; | ||
export * from './components/modal'; | ||
export * from './components/pagination'; | ||
export * from './components/progressbar'; | ||
export * from './components/rating'; | ||
export * from './components/select'; | ||
export * from './components/slider'; | ||
// config | ||
@@ -15,0 +15,0 @@ export * from './config'; |
@@ -51,3 +51,3 @@ { | ||
"dependencies": { | ||
"@amadeus-it-group/tansu": "0.0.24" | ||
"@amadeus-it-group/tansu": "1.0.0" | ||
}, | ||
@@ -58,3 +58,3 @@ "peerDependencies": { | ||
"sideEffects": false, | ||
"version": "0.0.1-alpha.6", | ||
"version": "0.0.1-alpha.7", | ||
"homepage": "https://amadeusitgroup.github.io/AgnosUI/latest/", | ||
@@ -61,0 +61,0 @@ "bugs": "https://github.com/AmadeusITGroup/AgnosUI/issues", |
@@ -18,2 +18,10 @@ import type { ArrowOptions, AutoUpdateOptions, ComputePositionConfig, Derivable } from '@floating-ui/dom'; | ||
export type FloatingUI = ReturnType<typeof createFloatingUI>; | ||
/** | ||
* Create a floating UI service. | ||
* | ||
* The returned service includes the patch method to patch the states, the stores to track the states and directives to apply. | ||
* | ||
* @param propsConfig - the props config for the floating UI service | ||
* @returns the floating UI service | ||
*/ | ||
export declare const createFloatingUI: (propsConfig?: PropsConfig<FloatingUIProps>) => { | ||
@@ -20,0 +28,0 @@ directives: { |
@@ -11,2 +11,10 @@ import { computed, derived } from '@amadeus-it-group/tansu'; | ||
}; | ||
/** | ||
* Create a floating UI service. | ||
* | ||
* The returned service includes the patch method to patch the states, the stores to track the states and directives to apply. | ||
* | ||
* @param propsConfig - the props config for the floating UI service | ||
* @returns the floating UI service | ||
*/ | ||
export const createFloatingUI = (propsConfig) => { | ||
@@ -13,0 +21,0 @@ const [{ autoUpdateOptions$, computePositionOptions$: computePositionInputOptions$, arrowOptions$: arrowInputOptions$ }, patch] = writablesForProps(defaultConfig, propsConfig); |
@@ -14,2 +14,10 @@ import type { PropsConfig } from '../types'; | ||
} | ||
/** | ||
* Create an intersection service. | ||
* | ||
* The returned service includes the patch method to set the elements to observe / intersection options and the states to track the visible elements. | ||
* | ||
* @param config - the props config for the intersection service | ||
* @returns the intersection service | ||
*/ | ||
export declare const createIntersection: (config?: PropsConfig<IntersectionProps>) => { | ||
@@ -16,0 +24,0 @@ /** |
@@ -8,2 +8,10 @@ import { asReadable, derived } from '@amadeus-it-group/tansu'; | ||
}; | ||
/** | ||
* Create an intersection service. | ||
* | ||
* The returned service includes the patch method to set the elements to observe / intersection options and the states to track the visible elements. | ||
* | ||
* @param config - the props config for the intersection service | ||
* @returns the intersection service | ||
*/ | ||
export const createIntersection = (config) => { | ||
@@ -10,0 +18,0 @@ const [{ elements$, options$ }, patch] = writablesForProps(defaultValues, config); |
@@ -6,2 +6,9 @@ import type { Directive } from '../types'; | ||
} | null | undefined; | ||
/** | ||
* Creates a portal directive, allowing to attach content to any element. | ||
* | ||
* @param content - the content of the portal | ||
* @param newArg - {@link PortalDirectiveArg} args | ||
* @returns the portal directive | ||
*/ | ||
export declare const portal: Directive<PortalDirectiveArg>; |
@@ -0,1 +1,8 @@ | ||
/** | ||
* Creates a portal directive, allowing to attach content to any element. | ||
* | ||
* @param content - the content of the portal | ||
* @param newArg - {@link PortalDirectiveArg} args | ||
* @returns the portal directive | ||
*/ | ||
export const portal = (content, newArg) => { | ||
@@ -2,0 +9,0 @@ let arg; |
@@ -134,3 +134,17 @@ import type { Directive, PropsConfig, Widget } from '../../types'; | ||
export type TransitionWidget = Widget<TransitionProps, TransitionState, TransitionApi, object, TransitionDirectives>; | ||
/** | ||
* A transition to show / hide an element without any animation. It uses the HTML `display` attribute. | ||
* | ||
* @param element - the element to animate | ||
* @param direction - the direction | ||
*/ | ||
export declare const noAnimation: TransitionFn; | ||
/** | ||
* Create a transition widget. | ||
* | ||
* The widget will include a patch function, stores to track the animation states and a directive to apply the animation to an element. | ||
* | ||
* @param config - the props config of the transition | ||
* @returns the transition widget | ||
*/ | ||
export declare const createTransition: (config?: PropsConfig<TransitionProps>) => TransitionWidget; |
@@ -8,2 +8,8 @@ import { batch, computed, derived, writable } from '@amadeus-it-group/tansu'; | ||
const neverEndingPromise = new Promise(noop); | ||
/** | ||
* A transition to show / hide an element without any animation. It uses the HTML `display` attribute. | ||
* | ||
* @param element - the element to animate | ||
* @param direction - the direction | ||
*/ | ||
export const noAnimation = async (element, direction) => { | ||
@@ -32,2 +38,10 @@ element.style.display = direction === 'show' ? '' : 'none'; | ||
}; | ||
/** | ||
* Create a transition widget. | ||
* | ||
* The widget will include a patch function, stores to track the animation states and a directive to apply the animation to an element. | ||
* | ||
* @param config - the props config of the transition | ||
* @returns the transition widget | ||
*/ | ||
export const createTransition = (config) => { | ||
@@ -34,0 +48,0 @@ const [{ animation$, initDone$, visible$: requestedVisible$, transition$, onShown$, onHidden$, onVisibleChange$, animationOnInit$ }, patch] = writablesForProps(defaultValues, config, configValidator); |
@@ -0,1 +1,2 @@ | ||
import type { TransitionFn } from './baseTransitions'; | ||
export interface CollapseContext { | ||
@@ -29,2 +30,15 @@ /** | ||
} | ||
export declare const createCollapseTransition: ({ dimension, showClasses, hideClasses, animationPendingClasses }?: CollapseConfig) => import("./baseTransitions").TransitionFn; | ||
/** | ||
* Create a collapse transition. | ||
* | ||
* The transition attaches / removes classes during the different states of the collapse transition. | ||
* It also updates the dimension value when reaching a non-pending state. | ||
* | ||
* @param config - the collapse config | ||
* @param config.dimension - the dimension, `height` or `width`, on which the collapse applies | ||
* @param config.showClasses - the classes to attach when the element is fully visible | ||
* @param config.hideClasses - the classes to attach when the element is fully collapsed | ||
* @param config.animationPendingClasses - the classes to attach when the transition is pending | ||
* @returns the collapse transition | ||
*/ | ||
export declare const createCollapseTransition: ({ dimension, showClasses, hideClasses, animationPendingClasses, }?: CollapseConfig) => TransitionFn; |
import { createCSSTransition } from './cssTransitions'; | ||
import { addClasses, reflow, removeClasses } from '../../utils/internal/dom'; | ||
export const createCollapseTransition = ({ dimension = 'height', showClasses, hideClasses, animationPendingClasses } = {}) => createCSSTransition((element, direction, animation, context) => { | ||
/** | ||
* Create a collapse transition. | ||
* | ||
* The transition attaches / removes classes during the different states of the collapse transition. | ||
* It also updates the dimension value when reaching a non-pending state. | ||
* | ||
* @param config - the collapse config | ||
* @param config.dimension - the dimension, `height` or `width`, on which the collapse applies | ||
* @param config.showClasses - the classes to attach when the element is fully visible | ||
* @param config.hideClasses - the classes to attach when the element is fully collapsed | ||
* @param config.animationPendingClasses - the classes to attach when the transition is pending | ||
* @returns the collapse transition | ||
*/ | ||
export const createCollapseTransition = ({ dimension = 'height', showClasses, hideClasses, animationPendingClasses, } = {}) => createCSSTransition((element, direction, animation, context) => { | ||
if (animation) { | ||
@@ -5,0 +18,0 @@ let { maxSize, minSize } = context; |
@@ -15,2 +15,8 @@ import type { TransitionFn } from './baseTransitions'; | ||
export type CSSTransitionFn = (element: HTMLElement, direction: 'show' | 'hide', animation: boolean, context: object) => void | (() => void); | ||
/** | ||
* Create a simple css transition. | ||
* | ||
* @param start - a function that creates the css animation and returns a clean-up function | ||
* @returns the css transition | ||
*/ | ||
export declare const createCSSTransition: (start: CSSTransitionFn) => TransitionFn; |
@@ -22,2 +22,8 @@ import { noop } from '../../utils/internal/func'; | ||
} | ||
/** | ||
* Create a simple css transition. | ||
* | ||
* @param start - a function that creates the css animation and returns a clean-up function | ||
* @returns the css transition | ||
*/ | ||
export const createCSSTransition = (start) => async (element, direction, animation, signal, context) => { | ||
@@ -24,0 +30,0 @@ const endFn = start(element, direction, animation, context) ?? noop; |
@@ -29,2 +29,13 @@ export interface SimpleClassTransitionConfig { | ||
} | ||
export declare const createSimpleClassTransition: ({ animationPendingClasses, animationPendingShowClasses, animationPendingHideClasses, showClasses, hideClasses, }: SimpleClassTransitionConfig) => import("./baseTransitions").TransitionFn; | ||
/** | ||
* Create a transition based on css classes to attach. | ||
* | ||
* The config includes the classes that will be attached / removed depending on the transition state. | ||
* `animationPendingClasses` are the classes attached when the transition is in a pending state | ||
* `animationPendingShowClasses` and `animationPendingHideClasses` are attached when transitionning towards one direction | ||
* `showClasses` and `hideClasses` are attached when the transition has reached the show or hide state respectively | ||
* | ||
* @param config - the transition config | ||
* @returns the simple class transition | ||
*/ | ||
export declare const createSimpleClassTransition: (config: SimpleClassTransitionConfig) => import("./baseTransitions").TransitionFn; |
import { createCSSTransition } from './cssTransitions'; | ||
import { addClasses, reflow, removeClasses } from '../../utils/internal/dom'; | ||
export const createSimpleClassTransition = ({ animationPendingClasses, animationPendingShowClasses, animationPendingHideClasses, showClasses, hideClasses, }) => createCSSTransition((element, direction, animation, context) => { | ||
removeClasses(element, showClasses); | ||
removeClasses(element, hideClasses); | ||
if (animation) { | ||
removeClasses(element, direction === 'show' ? animationPendingHideClasses : animationPendingShowClasses); | ||
if (!context.started) { | ||
context.started = true; | ||
// if the animation is starting, explicitly sets the initial state (reverse of the direction) | ||
// so that it is not impacted by another reflow done somewhere else before we had time to put | ||
// the right classes: | ||
const classes = direction === 'show' ? hideClasses : showClasses; | ||
addClasses(element, classes); | ||
/** | ||
* Create a transition based on css classes to attach. | ||
* | ||
* The config includes the classes that will be attached / removed depending on the transition state. | ||
* `animationPendingClasses` are the classes attached when the transition is in a pending state | ||
* `animationPendingShowClasses` and `animationPendingHideClasses` are attached when transitionning towards one direction | ||
* `showClasses` and `hideClasses` are attached when the transition has reached the show or hide state respectively | ||
* | ||
* @param config - the transition config | ||
* @returns the simple class transition | ||
*/ | ||
export const createSimpleClassTransition = (config) => { | ||
const { animationPendingClasses, animationPendingShowClasses, animationPendingHideClasses, showClasses, hideClasses } = config; | ||
return createCSSTransition((element, direction, animation, context) => { | ||
removeClasses(element, showClasses); | ||
removeClasses(element, hideClasses); | ||
if (animation) { | ||
removeClasses(element, direction === 'show' ? animationPendingHideClasses : animationPendingShowClasses); | ||
if (!context.started) { | ||
context.started = true; | ||
// if the animation is starting, explicitly sets the initial state (reverse of the direction) | ||
// so that it is not impacted by another reflow done somewhere else before we had time to put | ||
// the right classes: | ||
const classes = direction === 'show' ? hideClasses : showClasses; | ||
addClasses(element, classes); | ||
reflow(element); | ||
removeClasses(element, classes); | ||
} | ||
addClasses(element, animationPendingClasses); | ||
reflow(element); | ||
removeClasses(element, classes); | ||
addClasses(element, direction === 'show' ? animationPendingShowClasses : animationPendingHideClasses); | ||
} | ||
addClasses(element, animationPendingClasses); | ||
reflow(element); | ||
addClasses(element, direction === 'show' ? animationPendingShowClasses : animationPendingHideClasses); | ||
} | ||
return () => { | ||
removeClasses(element, animationPendingClasses); | ||
removeClasses(element, animationPendingShowClasses); | ||
removeClasses(element, animationPendingHideClasses); | ||
addClasses(element, direction === 'show' ? showClasses : hideClasses); | ||
}; | ||
}); | ||
return () => { | ||
removeClasses(element, animationPendingClasses); | ||
removeClasses(element, animationPendingShowClasses); | ||
removeClasses(element, animationPendingHideClasses); | ||
addClasses(element, direction === 'show' ? showClasses : hideClasses); | ||
}; | ||
}); | ||
}; |
@@ -60,2 +60,8 @@ import type { ReadableSignal, StoreOptions, SubscribableStore, WritableSignal } from '@amadeus-it-group/tansu'; | ||
} | ||
/** | ||
* Extract actions, api, directives, state and stores from the widget to be passed to slots as context. | ||
* | ||
* @param w - the widget | ||
* @returns the slot context | ||
*/ | ||
export declare const toSlotContextWidget: <W extends Widget<object, object, object, object, object>>(w: W) => ContextWidget<W>; | ||
@@ -62,0 +68,0 @@ export type WidgetState<T extends { |
@@ -0,1 +1,7 @@ | ||
/** | ||
* Extract actions, api, directives, state and stores from the widget to be passed to slots as context. | ||
* | ||
* @param w - the widget | ||
* @returns the slot context | ||
*/ | ||
export const toSlotContextWidget = (w) => ({ | ||
@@ -2,0 +8,0 @@ actions: w.actions, |
/** | ||
* a number type guard | ||
* @param value the value to check | ||
* @param value - the value to check | ||
* @returns true if the value is a number | ||
@@ -9,3 +9,3 @@ */ | ||
* a boolean type guard | ||
* @param value the value to check | ||
* @param value - the value to check | ||
* @returns true if the value is a boolean | ||
@@ -16,3 +16,3 @@ */ | ||
* a function type guard | ||
* @param value the value to check | ||
* @param value - the value to check | ||
* @returns true if the value is a function | ||
@@ -23,3 +23,3 @@ */ | ||
* a string type guard | ||
* @param value the value to check | ||
* @param value - the value to check | ||
* @returns true if the value is a string | ||
@@ -35,5 +35,5 @@ */ | ||
* Clamp the value based on a maximum and optional minimum | ||
* @param value the value to check | ||
* @param max the max to clamp to | ||
* @param [min] the min to clamp to | ||
* @param value - the value to check | ||
* @param max - the max to clamp to | ||
* @param [min] - the min to clamp to | ||
* @returns the clamped value | ||
@@ -44,3 +44,3 @@ */ | ||
* an html element type guard | ||
* @param value the value to check | ||
* @param value - the value to check | ||
* @returns true if the value is an instance of HTMLElement | ||
@@ -51,5 +51,5 @@ */ | ||
* Returns a new type guard that is based on the provided type guard and also returns true for null values. | ||
* @param isType base type guard | ||
* @param isType - base type guard | ||
* @returns A type guard function that returns true for null values and calls the provided type guard for other values. | ||
*/ | ||
export declare const allowNull: <T>(isType: (value: any) => value is T) => (value: any) => value is T | null; |
/** | ||
* a number type guard | ||
* @param value the value to check | ||
* @param value - the value to check | ||
* @returns true if the value is a number | ||
@@ -11,3 +11,3 @@ */ | ||
* a boolean type guard | ||
* @param value the value to check | ||
* @param value - the value to check | ||
* @returns true if the value is a boolean | ||
@@ -20,3 +20,3 @@ */ | ||
* a function type guard | ||
* @param value the value to check | ||
* @param value - the value to check | ||
* @returns true if the value is a function | ||
@@ -29,3 +29,3 @@ */ | ||
* a string type guard | ||
* @param value the value to check | ||
* @param value - the value to check | ||
* @returns true if the value is a string | ||
@@ -44,5 +44,5 @@ */ | ||
* Clamp the value based on a maximum and optional minimum | ||
* @param value the value to check | ||
* @param max the max to clamp to | ||
* @param [min] the min to clamp to | ||
* @param value - the value to check | ||
* @param max - the max to clamp to | ||
* @param [min] - the min to clamp to | ||
* @returns the clamped value | ||
@@ -55,3 +55,3 @@ */ | ||
* an html element type guard | ||
* @param value the value to check | ||
* @param value - the value to check | ||
* @returns true if the value is an instance of HTMLElement | ||
@@ -62,5 +62,5 @@ */ | ||
* Returns a new type guard that is based on the provided type guard and also returns true for null values. | ||
* @param isType base type guard | ||
* @param isType - base type guard | ||
* @returns A type guard function that returns true for null values and calls the provided type guard for other values. | ||
*/ | ||
export const allowNull = (isType) => (value) => value === null || isType(value); |
@@ -12,3 +12,15 @@ /** | ||
export declare function reflow(element?: HTMLElement): void; | ||
/** | ||
* Attach the given css classes to the element | ||
* | ||
* @param element - the HTML element | ||
* @param classes - the css lcasses | ||
*/ | ||
export declare const addClasses: (element: HTMLElement, classes?: string[]) => void; | ||
/** | ||
* Remove the given css classes to the element | ||
* | ||
* @param element - the HTML element | ||
* @param classes - the css classes | ||
*/ | ||
export declare const removeClasses: (element: HTMLElement, classes?: string[]) => void; |
@@ -40,2 +40,8 @@ /** | ||
} | ||
/** | ||
* Attach the given css classes to the element | ||
* | ||
* @param element - the HTML element | ||
* @param classes - the css lcasses | ||
*/ | ||
export const addClasses = (element, classes) => { | ||
@@ -46,2 +52,8 @@ if (classes && classes.length > 0) { | ||
}; | ||
/** | ||
* Remove the given css classes to the element | ||
* | ||
* @param element - the HTML element | ||
* @param classes - the css classes | ||
*/ | ||
export const removeClasses = (element, classes) => { | ||
@@ -48,0 +60,0 @@ if (classes && classes.length > 0) { |
@@ -0,2 +1,11 @@ | ||
/** | ||
* A noop function | ||
*/ | ||
export declare const noop: () => void; | ||
/** | ||
* The identity function | ||
* | ||
* @param x - the arg | ||
* @returns the arg | ||
*/ | ||
export declare const identity: <T>(x: T) => T; |
@@ -0,2 +1,11 @@ | ||
/** | ||
* A noop function | ||
*/ | ||
export const noop = () => { }; | ||
/** | ||
* The identity function | ||
* | ||
* @param x - the arg | ||
* @returns the arg | ||
*/ | ||
export const identity = (x) => x; |
@@ -8,6 +8,49 @@ import type { ReadableSignal } from '@amadeus-it-group/tansu'; | ||
export type PromiseState<T> = PromiseFulfilledResult<T> | PromiseRejectedResult | PromisePendingResult; | ||
/** | ||
* Create a readable promise state store from a promise. | ||
* | ||
* The state of the returned store tracks the state of the promise and the resolved value or rejection reason. | ||
* | ||
* @param value - the promise | ||
* @returns the readable promise state store | ||
*/ | ||
export declare const promiseStateStore: <T>(value: T) => ReadableSignal<Readonly<PromiseState<Awaited<T>>>>; | ||
/** | ||
* Create a readable promise state store from a promise store. | ||
* | ||
* @param promiseStore$ - the promise store | ||
* @returns the readable promise state store | ||
*/ | ||
export declare const promiseStoreToPromiseStateStore: <T>(promiseStore$: ReadableSignal<T>) => ReadableSignal<PromiseState<Awaited<T>>>; | ||
/** | ||
* Create a value store from a promise state store | ||
* | ||
* The returned value store is only updated if the promise is fulfilled. | ||
* | ||
* @param store$ - the promise state store | ||
* @param initialValue - the initial value of the returned value store | ||
* @param equal - an equal function to compare values | ||
* @returns the value store | ||
*/ | ||
export declare const promiseStateStoreToValueStore: <T>(store$: ReadableSignal<PromiseState<T>>, initialValue: T, equal?: ((a: T, b: T) => boolean) | undefined) => ReadableSignal<T>; | ||
/** | ||
* Create a value store from a promise store | ||
* | ||
* The returned value store is only updated if the promise is fulfilled. | ||
* | ||
* @param promiseStore$ - the promise store | ||
* @param initialValue - the initial value of the returned value store | ||
* @param equal - an equal function to compare values | ||
* @returns the value store | ||
*/ | ||
export declare const promiseStoreToValueStore: <T>(promiseStore$: ReadableSignal<T>, initialValue: Awaited<T>, equal?: ((a: Awaited<T>, b: Awaited<T>) => boolean) | undefined) => ReadableSignal<Awaited<T>>; | ||
/** | ||
* Create a promise from a readable store and a fulfilled condition function. | ||
* | ||
* The promise is fulfilled when the state of the store respects the provided condition function. | ||
* | ||
* @param store - the readable store | ||
* @param condition - the condition function | ||
* @returns the promise and an unsubscribe function | ||
*/ | ||
export declare const promiseFromStore: <T>(store: ReadableSignal<T>, condition?: (value: T) => boolean) => { | ||
@@ -17,2 +60,9 @@ promise: Promise<T>; | ||
}; | ||
/** | ||
* Create a promise from an HTML element event. | ||
* | ||
* @param element - the event target | ||
* @param event - the event to listen to | ||
* @returns the promise and an unsubscribe function | ||
*/ | ||
export declare const promiseFromEvent: (element: EventTarget, event: string) => { | ||
@@ -22,2 +72,8 @@ promise: Promise<Event>; | ||
}; | ||
/** | ||
* Create a promise that resolves once a timeout has been reached. | ||
* | ||
* @param delay - the delay in milli seconds | ||
* @returns a promise and an unsubscribe function | ||
*/ | ||
export declare const promiseFromTimeout: (delay: number) => { | ||
@@ -24,0 +80,0 @@ promise: Promise<void>; |
@@ -15,2 +15,10 @@ import { asReadable, computed, derived, equal, readable, writable } from '@amadeus-it-group/tansu'; | ||
const promiseWeakMap = new WeakMap(); | ||
/** | ||
* Create a readable promise state store from a promise. | ||
* | ||
* The state of the returned store tracks the state of the promise and the resolved value or rejection reason. | ||
* | ||
* @param value - the promise | ||
* @returns the readable promise state store | ||
*/ | ||
export const promiseStateStore = (value) => { | ||
@@ -31,3 +39,19 @@ if (!isThenable(value)) { | ||
(a.status !== 'rejected' || equal(a.reason, b.reason))); | ||
/** | ||
* Create a readable promise state store from a promise store. | ||
* | ||
* @param promiseStore$ - the promise store | ||
* @returns the readable promise state store | ||
*/ | ||
export const promiseStoreToPromiseStateStore = (promiseStore$) => computed(() => promiseStateStore(promiseStore$())(), { equal: promiseStateStoreEqual }); | ||
/** | ||
* Create a value store from a promise state store | ||
* | ||
* The returned value store is only updated if the promise is fulfilled. | ||
* | ||
* @param store$ - the promise state store | ||
* @param initialValue - the initial value of the returned value store | ||
* @param equal - an equal function to compare values | ||
* @returns the value store | ||
*/ | ||
export const promiseStateStoreToValueStore = (store$, initialValue, equal) => derived(store$, { | ||
@@ -41,4 +65,23 @@ derive: (state, set) => { | ||
}, initialValue); | ||
/** | ||
* Create a value store from a promise store | ||
* | ||
* The returned value store is only updated if the promise is fulfilled. | ||
* | ||
* @param promiseStore$ - the promise store | ||
* @param initialValue - the initial value of the returned value store | ||
* @param equal - an equal function to compare values | ||
* @returns the value store | ||
*/ | ||
export const promiseStoreToValueStore = (promiseStore$, initialValue, equal) => promiseStateStoreToValueStore(promiseStoreToPromiseStateStore(promiseStore$), initialValue, equal); | ||
const truthyValue = (value) => !!value; | ||
/** | ||
* Create a promise from a readable store and a fulfilled condition function. | ||
* | ||
* The promise is fulfilled when the state of the store respects the provided condition function. | ||
* | ||
* @param store - the readable store | ||
* @param condition - the condition function | ||
* @returns the promise and an unsubscribe function | ||
*/ | ||
export const promiseFromStore = (store, condition = truthyValue) => { | ||
@@ -68,2 +111,9 @@ let resolve; | ||
}; | ||
/** | ||
* Create a promise from an HTML element event. | ||
* | ||
* @param element - the event target | ||
* @param event - the event to listen to | ||
* @returns the promise and an unsubscribe function | ||
*/ | ||
export const promiseFromEvent = (element, event) => { | ||
@@ -90,2 +140,8 @@ let resolve; | ||
}; | ||
/** | ||
* Create a promise that resolves once a timeout has been reached. | ||
* | ||
* @param delay - the delay in milli seconds | ||
* @returns a promise and an unsubscribe function | ||
*/ | ||
export const promiseFromTimeout = (delay) => { | ||
@@ -92,0 +148,0 @@ let timeout; |
@@ -0,2 +1,8 @@ | ||
/** | ||
* A function to remove the scrollbars on the body element. It can be reverted using the {@link revertScrollbars} function. | ||
*/ | ||
export declare const removeScrollbars: () => void; | ||
/** | ||
* A function to revert the removal of scrollbars performed by the {@link removeScrollbars} function. | ||
*/ | ||
export declare const revertScrollbars: () => void; |
@@ -20,2 +20,5 @@ import { noop } from './func'; | ||
let internalRevert = noop; | ||
/** | ||
* A function to remove the scrollbars on the body element. It can be reverted using the {@link revertScrollbars} function. | ||
*/ | ||
export const removeScrollbars = () => { | ||
@@ -25,2 +28,5 @@ internalRevert(); | ||
}; | ||
/** | ||
* A function to revert the removal of scrollbars performed by the {@link removeScrollbars} function. | ||
*/ | ||
export const revertScrollbars = () => { | ||
@@ -27,0 +33,0 @@ internalRevert(); |
@@ -0,2 +1,16 @@ | ||
/** | ||
* The default comparision between two values, using the javascript < and > signs. | ||
* | ||
* @param a - the first input | ||
* @param b - the second input | ||
* @returns 1, 0 or -1 depending on the default compare | ||
*/ | ||
export declare const compareDefault: (a: any, b: any) => 0 | 1 | -1; | ||
/** | ||
* A comparision function between DOM elements, based on [Node.compareDocumentPosition](https://developer.mozilla.org/fr/docs/Web/API/Node/compareDocumentPosition). | ||
* | ||
* @param element1 - the first node | ||
* @param element2 - the second node | ||
* @returns 1, 0 or -1 | ||
*/ | ||
export declare const compareDomOrder: (element1: Node, element2: Node) => 0 | 1 | -1; |
@@ -0,2 +1,16 @@ | ||
/** | ||
* The default comparision between two values, using the javascript < and > signs. | ||
* | ||
* @param a - the first input | ||
* @param b - the second input | ||
* @returns 1, 0 or -1 depending on the default compare | ||
*/ | ||
export const compareDefault = (a, b) => (a < b ? -1 : a > b ? 1 : 0); | ||
/** | ||
* A comparision function between DOM elements, based on [Node.compareDocumentPosition](https://developer.mozilla.org/fr/docs/Web/API/Node/compareDocumentPosition). | ||
* | ||
* @param element1 - the first node | ||
* @param element2 - the second node | ||
* @returns 1, 0 or -1 | ||
*/ | ||
export const compareDomOrder = (element1, element2) => { | ||
@@ -3,0 +17,0 @@ if (element1 === element2) { |
@@ -0,1 +1,7 @@ | ||
/** | ||
* Returns the text direction of an element, using a call to `getComputedStyle`. | ||
* | ||
* @param element - the HTML element | ||
* @returns the text direction of the element, 'ltr' or 'rtl' | ||
*/ | ||
export declare const getTextDirection: (element: HTMLElement) => "rtl" | "ltr"; |
@@ -0,1 +1,7 @@ | ||
/** | ||
* Returns the text direction of an element, using a call to `getComputedStyle`. | ||
* | ||
* @param element - the HTML element | ||
* @returns the text direction of the element, 'ltr' or 'rtl' | ||
*/ | ||
export const getTextDirection = (element) => getComputedStyle(element).direction; |
@@ -82,3 +82,18 @@ import type { ReadableSignal, StoreInput, StoresInputValues, WritableSignal } from '@amadeus-it-group/tansu'; | ||
export declare const toWritableStore: <T>(x: T | WritableSignal<T, T>) => WritableSignal<T, T>; | ||
/** | ||
* Extract and normalize config stores. | ||
* | ||
* @param keys - the keys of the stores to extract / normalize | ||
* @param config - the config stores | ||
* @returns the normalized config stores | ||
*/ | ||
export declare const normalizeConfigStores: <T extends object>(keys: (keyof T)[], config?: ReadableSignal<Partial<T>> | ValuesOrReadableSignals<T> | undefined) => ReadableSignals<T>; | ||
/** | ||
* Merge two stores configs into one | ||
* | ||
* @param keys - the keys of the stores to extract and merge from the two provided configs | ||
* @param config1 - the first config | ||
* @param config2 - the second config | ||
* @returns the merged config | ||
*/ | ||
export declare const mergeConfigStores: <T extends object>(keys: (keyof T)[], config1?: ReadableSignals<T> | undefined, config2?: ReadableSignals<T> | undefined) => ReadableSignals<T>; | ||
@@ -140,2 +155,8 @@ /** | ||
export declare const writablesForProps: <T extends object>(defConfig: T, propsConfig?: PropsConfig<T> | undefined, options?: { [K in keyof T]?: WritableWithDefaultOptions<T[K]> | undefined; } | undefined) => [ToWritableSignal<T>, <U extends Partial<T>>(storesValues?: void | U | undefined) => void]; | ||
/** | ||
* Using input stores, this function builds an object containing the stores as readable and a global state. | ||
* | ||
* @param inputStores - the input stores | ||
* @returns the object containing the stores as readable and the global state | ||
*/ | ||
export declare const stateStores: <A extends { | ||
@@ -142,0 +163,0 @@ [x: `${string}$`]: ReadableSignal<any>; |
@@ -120,2 +120,9 @@ import { asReadable, asWritable, batch, computed, derived, get, readable, writable } from '@amadeus-it-group/tansu'; | ||
export const toWritableStore = (x) => (isStore(x) ? x : writable(x)); | ||
/** | ||
* Extract and normalize config stores. | ||
* | ||
* @param keys - the keys of the stores to extract / normalize | ||
* @param config - the config stores | ||
* @returns the normalized config stores | ||
*/ | ||
export const normalizeConfigStores = (keys, config) => { | ||
@@ -133,2 +140,10 @@ const res = {}; | ||
}; | ||
/** | ||
* Merge two stores configs into one | ||
* | ||
* @param keys - the keys of the stores to extract and merge from the two provided configs | ||
* @param config1 - the first config | ||
* @param config2 - the second config | ||
* @returns the merged config | ||
*/ | ||
export const mergeConfigStores = (keys, config1, config2) => { | ||
@@ -211,2 +226,8 @@ const res = {}; | ||
}; | ||
/** | ||
* Using input stores, this function builds an object containing the stores as readable and a global state. | ||
* | ||
* @param inputStores - the input stores | ||
* @returns the object containing the stores as readable and the global state | ||
*/ | ||
export const stateStores = (inputStores) => { | ||
@@ -213,0 +234,0 @@ const storesNames = []; |
import type { WritableWithDefaultOptions } from '../types'; | ||
import { INVALID_VALUE } from '../types'; | ||
/** | ||
* Check if a value respects a provided type guard. | ||
* | ||
* @param filter - the guard function | ||
* @returns a function that takes a value as input, checks if it respects the type guard and returns `INVALID_VALUE` otherwise | ||
*/ | ||
export declare const testToNormalizeValue: <T>(filter: (value: any) => value is T) => (value: any) => typeof INVALID_VALUE | T; | ||
@@ -4,0 +10,0 @@ export declare const typeNumber: WritableWithDefaultOptions<number>; |
import { allowNull, clamp, isArray, isBoolean, isFunction, isHTMLElement, isNumber, isString } from './internal/checks'; | ||
import { INVALID_VALUE } from '../types'; | ||
/** | ||
* Check if a value respects a provided type guard. | ||
* | ||
* @param filter - the guard function | ||
* @returns a function that takes a value as input, checks if it respects the type guard and returns `INVALID_VALUE` otherwise | ||
*/ | ||
export const testToNormalizeValue = (filter) => (value) => filter(value) ? value : INVALID_VALUE; | ||
@@ -4,0 +10,0 @@ const numberNormalizeFn = testToNormalizeValue(isNumber); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
271039
100
7102
+ Added@amadeus-it-group/tansu@1.0.0(transitive)
- Removed@amadeus-it-group/tansu@0.0.24(transitive)