@agnos-ui/core 0.0.1-alpha.6 → 0.0.1-alpha.7

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.
Files changed (59) hide show
  1. package/components/accordion/index.d.ts +1 -0
  2. package/components/accordion/index.js +1 -0
  3. package/components/alert/alert.d.ts +0 -1
  4. package/components/alert/alert.js +0 -1
  5. package/components/alert/index.d.ts +2 -0
  6. package/components/alert/index.js +2 -0
  7. package/components/modal/index.d.ts +1 -0
  8. package/components/modal/index.js +1 -0
  9. package/components/pagination/index.d.ts +2 -0
  10. package/components/pagination/index.js +2 -0
  11. package/components/pagination/pagination.d.ts +0 -1
  12. package/components/pagination/pagination.js +0 -1
  13. package/components/progressbar/index.d.ts +1 -0
  14. package/components/progressbar/index.js +1 -0
  15. package/components/rating/index.d.ts +1 -0
  16. package/components/rating/index.js +1 -0
  17. package/components/select/index.d.ts +1 -0
  18. package/components/select/index.js +1 -0
  19. package/components/slider/index.d.ts +1 -0
  20. package/components/slider/index.js +1 -0
  21. package/components/slider/slider.d.ts +6 -0
  22. package/components/slider/slider.js +24 -0
  23. package/index.d.ts +8 -8
  24. package/index.js +8 -8
  25. package/package.json +2 -2
  26. package/services/floatingUI.d.ts +8 -0
  27. package/services/floatingUI.js +8 -0
  28. package/services/intersection.d.ts +8 -0
  29. package/services/intersection.js +8 -0
  30. package/services/portal.d.ts +7 -0
  31. package/services/portal.js +7 -0
  32. package/services/transitions/baseTransitions.d.ts +14 -0
  33. package/services/transitions/baseTransitions.js +14 -0
  34. package/services/transitions/collapse.d.ts +15 -1
  35. package/services/transitions/collapse.js +14 -1
  36. package/services/transitions/cssTransitions.d.ts +6 -0
  37. package/services/transitions/cssTransitions.js +6 -0
  38. package/services/transitions/simpleClassTransition.d.ts +12 -1
  39. package/services/transitions/simpleClassTransition.js +38 -24
  40. package/types.d.ts +6 -0
  41. package/types.js +6 -0
  42. package/utils/internal/checks.d.ts +9 -9
  43. package/utils/internal/checks.js +9 -9
  44. package/utils/internal/dom.d.ts +12 -0
  45. package/utils/internal/dom.js +12 -0
  46. package/utils/internal/func.d.ts +9 -0
  47. package/utils/internal/func.js +9 -0
  48. package/utils/internal/promise.d.ts +56 -0
  49. package/utils/internal/promise.js +56 -0
  50. package/utils/internal/scrollbars.d.ts +6 -0
  51. package/utils/internal/scrollbars.js +6 -0
  52. package/utils/internal/sort.d.ts +14 -0
  53. package/utils/internal/sort.js +14 -0
  54. package/utils/internal/textDirection.d.ts +6 -0
  55. package/utils/internal/textDirection.js +6 -0
  56. package/utils/stores.d.ts +21 -0
  57. package/utils/stores.js +21 -0
  58. package/utils/writables.d.ts +6 -0
  59. package/utils/writables.js +6 -0
@@ -0,0 +1 @@
1
+ export * from './accordion';
@@ -0,0 +1 @@
1
+ export * from './accordion';
@@ -1,7 +1,6 @@
1
1
  import type { CommonAlertApi, CommonAlertDirectives, CommonAlertProps, CommonAlertState } from './common';
2
2
  import type { ExtendWidgetAdaptSlotWidgetProps } from '../../services/extendWidget';
3
3
  import type { Widget, WidgetFactory, WidgetSlotContext } from '../../types';
4
- export * from './common';
5
4
  export type AlertContext = WidgetSlotContext<AlertWidget>;
6
5
  export interface AlertExtraProps {
7
6
  /**
@@ -1,7 +1,6 @@
1
1
  import { createCommonAlert, getCommonAlertDefaultConfig } from './common';
2
2
  import { extendWidgetProps } from '../../services/extendWidget';
3
3
  import { typeString } from '../../utils/writables';
4
- export * from './common';
5
4
  const alertDefaultConfig = {
6
5
  type: 'primary',
7
6
  };
@@ -0,0 +1,2 @@
1
+ export * from './common';
2
+ export * from './alert';
@@ -0,0 +1,2 @@
1
+ export * from './common';
2
+ export * from './alert';
@@ -0,0 +1 @@
1
+ export * from './modal';
@@ -0,0 +1 @@
1
+ export * from './modal';
@@ -0,0 +1,2 @@
1
+ export * from './bootstrap';
2
+ export * from './pagination';
@@ -0,0 +1,2 @@
1
+ export * from './bootstrap';
2
+ export * from './pagination';
@@ -1,6 +1,5 @@
1
1
  import type { PropsConfig, Widget, SlotContent, WidgetSlotContext } from '../../types';
2
2
  import type { WidgetsCommonPropsAndState } from '../commonProps';
3
- export * from './bootstrap';
4
3
  /**
5
4
  * A type for the slot context of the pagination widget
6
5
  */
@@ -4,7 +4,6 @@ import { bindableDerived, stateStores, writablesForProps } from '../../utils/sto
4
4
  import { clamp, isNumber } from '../../utils/internal/checks';
5
5
  import { typeBoolean, typeFunction, typeNumber, typeString } from '../../utils/writables';
6
6
  import { noop } from '../../utils/internal/func';
7
- export * from './bootstrap';
8
7
  const defaultConfig = {
9
8
  page: 1,
10
9
  collectionSize: 0,
@@ -0,0 +1 @@
1
+ export * from './progressbar';
@@ -0,0 +1 @@
1
+ export * from './progressbar';
@@ -0,0 +1 @@
1
+ export * from './rating';
@@ -0,0 +1 @@
1
+ export * from './rating';
@@ -0,0 +1 @@
1
+ export * from './select';
@@ -0,0 +1 @@
1
+ export * from './select';
@@ -0,0 +1 @@
1
+ export * from './slider';
@@ -0,0 +1 @@
1
+ export * from './slider';
@@ -169,6 +169,12 @@ export interface SliderActions {
169
169
  * @param handleId - numeric id of the handle
170
170
  */
171
171
  mouseDown(event: MouseEvent, handleId: number): void;
172
+ /**
173
+ * Method describing the behavior of the slider handle on touch start event
174
+ * @param event - touch event
175
+ * @param handleId - number id of the handle
176
+ */
177
+ touchStart(event: TouchEvent, handleId: number): void;
172
178
  }
173
179
  export type SliderWidget = Widget<SliderProps, SliderState, SliderApi, SliderActions, SliderDirectives>;
174
180
  /**
@@ -384,6 +384,30 @@ export function createSlider(config) {
384
384
  }, { once: true });
385
385
  }
386
386
  },
387
+ touchStart(event, handleId) {
388
+ event.preventDefault();
389
+ const handleDrag = (e) => {
390
+ e.preventDefault();
391
+ const newCoord = vertical$() ? e.touches[0].clientY : e.touches[0].clientX;
392
+ event.target.focus();
393
+ if (_prevCoordinate !== newCoord) {
394
+ _prevCoordinate = newCoord;
395
+ adjustCoordinate(newCoord, handleId);
396
+ }
397
+ };
398
+ if (isInteractable$()) {
399
+ event.target.focus();
400
+ document.addEventListener('touchmove', handleDrag);
401
+ document.addEventListener('touchend', () => {
402
+ document.removeEventListener('touchmove', handleDrag);
403
+ document.removeEventListener('touchcancel', handleDrag);
404
+ }, { once: true });
405
+ document.addEventListener('touchcancel', () => {
406
+ document.removeEventListener('touchmove', handleDrag);
407
+ document.removeEventListener('touchend', handleDrag);
408
+ }, { once: true });
409
+ }
410
+ },
387
411
  },
388
412
  };
389
413
  }
package/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  export * from './components/commonProps';
2
2
  export * from './types';
3
- export * from './components/accordion/accordion';
4
- export * from './components/alert/alert';
5
- export * from './components/modal/modal';
6
- export * from './components/pagination/pagination';
7
- export * from './components/progressbar/progressbar';
8
- export * from './components/rating/rating';
9
- export * from './components/select/select';
10
- export * from './components/slider/slider';
3
+ export * from './components/accordion';
4
+ export * from './components/alert';
5
+ export * from './components/modal';
6
+ export * from './components/pagination';
7
+ export * from './components/progressbar';
8
+ export * from './components/rating';
9
+ export * from './components/select';
10
+ export * from './components/slider';
11
11
  export * from './config';
12
12
  export * from './services/extendWidget';
13
13
  export * from './services/floatingUI';
package/index.js CHANGED
@@ -2,14 +2,14 @@
2
2
  export * from './components/commonProps';
3
3
  export * from './types';
4
4
  // components
5
- export * from './components/accordion/accordion';
6
- export * from './components/alert/alert';
7
- export * from './components/modal/modal';
8
- export * from './components/pagination/pagination';
9
- export * from './components/progressbar/progressbar';
10
- export * from './components/rating/rating';
11
- export * from './components/select/select';
12
- export * from './components/slider/slider';
5
+ export * from './components/accordion';
6
+ export * from './components/alert';
7
+ export * from './components/modal';
8
+ export * from './components/pagination';
9
+ export * from './components/progressbar';
10
+ export * from './components/rating';
11
+ export * from './components/select';
12
+ export * from './components/slider';
13
13
  // config
14
14
  export * from './config';
15
15
  // services
package/package.json CHANGED
@@ -48,13 +48,13 @@
48
48
  }
49
49
  },
50
50
  "dependencies": {
51
- "@amadeus-it-group/tansu": "0.0.24"
51
+ "@amadeus-it-group/tansu": "1.0.0"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@floating-ui/dom": "*"
55
55
  },
56
56
  "sideEffects": false,
57
- "version": "0.0.1-alpha.6",
57
+ "version": "0.0.1-alpha.7",
58
58
  "homepage": "https://amadeusitgroup.github.io/AgnosUI/latest/",
59
59
  "bugs": "https://github.com/AmadeusITGroup/AgnosUI/issues",
60
60
  "license": "MIT",
@@ -15,6 +15,14 @@ export interface FloatingUIProps {
15
15
  arrowOptions: Omit<ArrowOptions, 'element'> | Derivable<Omit<ArrowOptions, 'element'>>;
16
16
  }
17
17
  export type FloatingUI = ReturnType<typeof createFloatingUI>;
18
+ /**
19
+ * Create a floating UI service.
20
+ *
21
+ * The returned service includes the patch method to patch the states, the stores to track the states and directives to apply.
22
+ *
23
+ * @param propsConfig - the props config for the floating UI service
24
+ * @returns the floating UI service
25
+ */
18
26
  export declare const createFloatingUI: (propsConfig?: PropsConfig<FloatingUIProps>) => {
19
27
  directives: {
20
28
  /**
@@ -8,6 +8,14 @@ const defaultConfig = {
8
8
  autoUpdateOptions: {},
9
9
  arrowOptions: {},
10
10
  };
11
+ /**
12
+ * Create a floating UI service.
13
+ *
14
+ * The returned service includes the patch method to patch the states, the stores to track the states and directives to apply.
15
+ *
16
+ * @param propsConfig - the props config for the floating UI service
17
+ * @returns the floating UI service
18
+ */
11
19
  export const createFloatingUI = (propsConfig) => {
12
20
  const [{ autoUpdateOptions$, computePositionOptions$: computePositionInputOptions$, arrowOptions$: arrowInputOptions$ }, patch] = writablesForProps(defaultConfig, propsConfig);
13
21
  const { directive: floatingDirective, element$: floatingElement$ } = createStoreDirective();
@@ -11,6 +11,14 @@ export interface IntersectionProps {
11
11
  */
12
12
  options: Partial<IntersectionObserverInit> | undefined;
13
13
  }
14
+ /**
15
+ * Create an intersection service.
16
+ *
17
+ * The returned service includes the patch method to set the elements to observe / intersection options and the states to track the visible elements.
18
+ *
19
+ * @param config - the props config for the intersection service
20
+ * @returns the intersection service
21
+ */
14
22
  export declare const createIntersection: (config?: PropsConfig<IntersectionProps>) => {
15
23
  /**
16
24
  * Readable of observed elements
@@ -5,6 +5,14 @@ const defaultValues = {
5
5
  elements: [],
6
6
  options: undefined,
7
7
  };
8
+ /**
9
+ * Create an intersection service.
10
+ *
11
+ * The returned service includes the patch method to set the elements to observe / intersection options and the states to track the visible elements.
12
+ *
13
+ * @param config - the props config for the intersection service
14
+ * @returns the intersection service
15
+ */
8
16
  export const createIntersection = (config) => {
9
17
  const [{ elements$, options$ }, patch] = writablesForProps(defaultValues, config);
10
18
  const visibleElements$ = derived([elements$, options$], ([elements, options], set) => {
@@ -3,4 +3,11 @@ export type PortalDirectiveArg = {
3
3
  container?: HTMLElement | null | undefined;
4
4
  insertBefore?: HTMLElement | null | undefined;
5
5
  } | null | undefined;
6
+ /**
7
+ * Creates a portal directive, allowing to attach content to any element.
8
+ *
9
+ * @param content - the content of the portal
10
+ * @param newArg - {@link PortalDirectiveArg} args
11
+ * @returns the portal directive
12
+ */
6
13
  export declare const portal: Directive<PortalDirectiveArg>;
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Creates a portal directive, allowing to attach content to any element.
3
+ *
4
+ * @param content - the content of the portal
5
+ * @param newArg - {@link PortalDirectiveArg} args
6
+ * @returns the portal directive
7
+ */
1
8
  export const portal = (content, newArg) => {
2
9
  let arg;
3
10
  let replaceComment;
@@ -131,5 +131,19 @@ export interface TransitionDirectives {
131
131
  directive: Directive<void | Partial<TransitionProps>>;
132
132
  }
133
133
  export type TransitionWidget = Widget<TransitionProps, TransitionState, TransitionApi, object, TransitionDirectives>;
134
+ /**
135
+ * A transition to show / hide an element without any animation. It uses the HTML `display` attribute.
136
+ *
137
+ * @param element - the element to animate
138
+ * @param direction - the direction
139
+ */
134
140
  export declare const noAnimation: TransitionFn;
141
+ /**
142
+ * Create a transition widget.
143
+ *
144
+ * The widget will include a patch function, stores to track the animation states and a directive to apply the animation to an element.
145
+ *
146
+ * @param config - the props config of the transition
147
+ * @returns the transition widget
148
+ */
135
149
  export declare const createTransition: (config?: PropsConfig<TransitionProps>) => TransitionWidget;
@@ -5,6 +5,12 @@ import { noop } from '../../utils/internal/func';
5
5
  import { bindableDerived, stateStores, writablesForProps } from '../../utils/stores';
6
6
  import { createStoreDirective, directiveSubscribe, directiveUpdate, mergeDirectives } from '../../utils/directive';
7
7
  const neverEndingPromise = new Promise(noop);
8
+ /**
9
+ * A transition to show / hide an element without any animation. It uses the HTML `display` attribute.
10
+ *
11
+ * @param element - the element to animate
12
+ * @param direction - the direction
13
+ */
8
14
  export const noAnimation = async (element, direction) => {
9
15
  element.style.display = direction === 'show' ? '' : 'none';
10
16
  };
@@ -28,6 +34,14 @@ const configValidator = {
28
34
  onVisibleChange: typeFunction,
29
35
  initDone: typeBooleanOrNull,
30
36
  };
37
+ /**
38
+ * Create a transition widget.
39
+ *
40
+ * The widget will include a patch function, stores to track the animation states and a directive to apply the animation to an element.
41
+ *
42
+ * @param config - the props config of the transition
43
+ * @returns the transition widget
44
+ */
31
45
  export const createTransition = (config) => {
32
46
  const [{ animation$, initDone$, visible$: requestedVisible$, transition$, onShown$, onHidden$, onVisibleChange$, animationOnInit$ }, patch] = writablesForProps(defaultValues, config, configValidator);
33
47
  const { element$, directive: storeDirective } = createStoreDirective();
@@ -1,3 +1,4 @@
1
+ import type { TransitionFn } from './baseTransitions';
1
2
  export interface CollapseContext {
2
3
  /**
3
4
  * the maximum size of the collapseable content.
@@ -26,4 +27,17 @@ export interface CollapseConfig {
26
27
  */
27
28
  animationPendingClasses?: string[];
28
29
  }
29
- export declare const createCollapseTransition: ({ dimension, showClasses, hideClasses, animationPendingClasses }?: CollapseConfig) => import("./baseTransitions").TransitionFn;
30
+ /**
31
+ * Create a collapse transition.
32
+ *
33
+ * The transition attaches / removes classes during the different states of the collapse transition.
34
+ * It also updates the dimension value when reaching a non-pending state.
35
+ *
36
+ * @param config - the collapse config
37
+ * @param config.dimension - the dimension, `height` or `width`, on which the collapse applies
38
+ * @param config.showClasses - the classes to attach when the element is fully visible
39
+ * @param config.hideClasses - the classes to attach when the element is fully collapsed
40
+ * @param config.animationPendingClasses - the classes to attach when the transition is pending
41
+ * @returns the collapse transition
42
+ */
43
+ export declare const createCollapseTransition: ({ dimension, showClasses, hideClasses, animationPendingClasses, }?: CollapseConfig) => TransitionFn;
@@ -1,6 +1,19 @@
1
1
  import { createCSSTransition } from './cssTransitions';
2
2
  import { addClasses, reflow, removeClasses } from '../../utils/internal/dom';
3
- export const createCollapseTransition = ({ dimension = 'height', showClasses, hideClasses, animationPendingClasses } = {}) => createCSSTransition((element, direction, animation, context) => {
3
+ /**
4
+ * Create a collapse transition.
5
+ *
6
+ * The transition attaches / removes classes during the different states of the collapse transition.
7
+ * It also updates the dimension value when reaching a non-pending state.
8
+ *
9
+ * @param config - the collapse config
10
+ * @param config.dimension - the dimension, `height` or `width`, on which the collapse applies
11
+ * @param config.showClasses - the classes to attach when the element is fully visible
12
+ * @param config.hideClasses - the classes to attach when the element is fully collapsed
13
+ * @param config.animationPendingClasses - the classes to attach when the transition is pending
14
+ * @returns the collapse transition
15
+ */
16
+ export const createCollapseTransition = ({ dimension = 'height', showClasses, hideClasses, animationPendingClasses, } = {}) => createCSSTransition((element, direction, animation, context) => {
4
17
  if (animation) {
5
18
  let { maxSize, minSize } = context;
6
19
  if (!maxSize) {
@@ -12,4 +12,10 @@ export declare function hasTransition(element: HTMLElement): boolean;
12
12
  */
13
13
  export declare function getTransitionDurationMs(element: HTMLElement): number;
14
14
  export type CSSTransitionFn = (element: HTMLElement, direction: 'show' | 'hide', animation: boolean, context: object) => void | (() => void);
15
+ /**
16
+ * Create a simple css transition.
17
+ *
18
+ * @param start - a function that creates the css animation and returns a clean-up function
19
+ * @returns the css transition
20
+ */
15
21
  export declare const createCSSTransition: (start: CSSTransitionFn) => TransitionFn;
@@ -19,6 +19,12 @@ export function getTransitionDurationMs(element) {
19
19
  const transitionDurationSec = parseFloat(transitionDuration);
20
20
  return (transitionDelaySec + transitionDurationSec) * 1000;
21
21
  }
22
+ /**
23
+ * Create a simple css transition.
24
+ *
25
+ * @param start - a function that creates the css animation and returns a clean-up function
26
+ * @returns the css transition
27
+ */
22
28
  export const createCSSTransition = (start) => async (element, direction, animation, signal, context) => {
23
29
  const endFn = start(element, direction, animation, context) ?? noop;
24
30
  if (animation && hasTransition(element)) {
@@ -26,4 +26,15 @@ export interface SimpleClassTransitionContext {
26
26
  */
27
27
  started?: boolean;
28
28
  }
29
- export declare const createSimpleClassTransition: ({ animationPendingClasses, animationPendingShowClasses, animationPendingHideClasses, showClasses, hideClasses, }: SimpleClassTransitionConfig) => import("./baseTransitions").TransitionFn;
29
+ /**
30
+ * Create a transition based on css classes to attach.
31
+ *
32
+ * The config includes the classes that will be attached / removed depending on the transition state.
33
+ * `animationPendingClasses` are the classes attached when the transition is in a pending state
34
+ * `animationPendingShowClasses` and `animationPendingHideClasses` are attached when transitionning towards one direction
35
+ * `showClasses` and `hideClasses` are attached when the transition has reached the show or hide state respectively
36
+ *
37
+ * @param config - the transition config
38
+ * @returns the simple class transition
39
+ */
40
+ export declare const createSimpleClassTransition: (config: SimpleClassTransitionConfig) => import("./baseTransitions").TransitionFn;
@@ -1,28 +1,42 @@
1
1
  import { createCSSTransition } from './cssTransitions';
2
2
  import { addClasses, reflow, removeClasses } from '../../utils/internal/dom';
3
- export const createSimpleClassTransition = ({ animationPendingClasses, animationPendingShowClasses, animationPendingHideClasses, showClasses, hideClasses, }) => createCSSTransition((element, direction, animation, context) => {
4
- removeClasses(element, showClasses);
5
- removeClasses(element, hideClasses);
6
- if (animation) {
7
- removeClasses(element, direction === 'show' ? animationPendingHideClasses : animationPendingShowClasses);
8
- if (!context.started) {
9
- context.started = true;
10
- // if the animation is starting, explicitly sets the initial state (reverse of the direction)
11
- // so that it is not impacted by another reflow done somewhere else before we had time to put
12
- // the right classes:
13
- const classes = direction === 'show' ? hideClasses : showClasses;
14
- addClasses(element, classes);
3
+ /**
4
+ * Create a transition based on css classes to attach.
5
+ *
6
+ * The config includes the classes that will be attached / removed depending on the transition state.
7
+ * `animationPendingClasses` are the classes attached when the transition is in a pending state
8
+ * `animationPendingShowClasses` and `animationPendingHideClasses` are attached when transitionning towards one direction
9
+ * `showClasses` and `hideClasses` are attached when the transition has reached the show or hide state respectively
10
+ *
11
+ * @param config - the transition config
12
+ * @returns the simple class transition
13
+ */
14
+ export const createSimpleClassTransition = (config) => {
15
+ const { animationPendingClasses, animationPendingShowClasses, animationPendingHideClasses, showClasses, hideClasses } = config;
16
+ return createCSSTransition((element, direction, animation, context) => {
17
+ removeClasses(element, showClasses);
18
+ removeClasses(element, hideClasses);
19
+ if (animation) {
20
+ removeClasses(element, direction === 'show' ? animationPendingHideClasses : animationPendingShowClasses);
21
+ if (!context.started) {
22
+ context.started = true;
23
+ // if the animation is starting, explicitly sets the initial state (reverse of the direction)
24
+ // so that it is not impacted by another reflow done somewhere else before we had time to put
25
+ // the right classes:
26
+ const classes = direction === 'show' ? hideClasses : showClasses;
27
+ addClasses(element, classes);
28
+ reflow(element);
29
+ removeClasses(element, classes);
30
+ }
31
+ addClasses(element, animationPendingClasses);
15
32
  reflow(element);
16
- removeClasses(element, classes);
33
+ addClasses(element, direction === 'show' ? animationPendingShowClasses : animationPendingHideClasses);
17
34
  }
18
- addClasses(element, animationPendingClasses);
19
- reflow(element);
20
- addClasses(element, direction === 'show' ? animationPendingShowClasses : animationPendingHideClasses);
21
- }
22
- return () => {
23
- removeClasses(element, animationPendingClasses);
24
- removeClasses(element, animationPendingShowClasses);
25
- removeClasses(element, animationPendingHideClasses);
26
- addClasses(element, direction === 'show' ? showClasses : hideClasses);
27
- };
28
- });
35
+ return () => {
36
+ removeClasses(element, animationPendingClasses);
37
+ removeClasses(element, animationPendingShowClasses);
38
+ removeClasses(element, animationPendingHideClasses);
39
+ addClasses(element, direction === 'show' ? showClasses : hideClasses);
40
+ };
41
+ });
42
+ };
package/types.d.ts CHANGED
@@ -57,6 +57,12 @@ export interface WidgetSlotContext<W extends Widget> {
57
57
  */
58
58
  widget: ContextWidget<W>;
59
59
  }
60
+ /**
61
+ * Extract actions, api, directives, state and stores from the widget to be passed to slots as context.
62
+ *
63
+ * @param w - the widget
64
+ * @returns the slot context
65
+ */
60
66
  export declare const toSlotContextWidget: <W extends Widget<object, object, object, object, object>>(w: W) => ContextWidget<W>;
61
67
  export type WidgetState<T extends {
62
68
  state$: SubscribableStore<any>;
package/types.js CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Extract actions, api, directives, state and stores from the widget to be passed to slots as context.
3
+ *
4
+ * @param w - the widget
5
+ * @returns the slot context
6
+ */
1
7
  export const toSlotContextWidget = (w) => ({
2
8
  actions: w.actions,
3
9
  api: w.api,
@@ -1,24 +1,24 @@
1
1
  /**
2
2
  * a number type guard
3
- * @param value the value to check
3
+ * @param value - the value to check
4
4
  * @returns true if the value is a number
5
5
  */
6
6
  export declare function isNumber(value: any): value is number;
7
7
  /**
8
8
  * a boolean type guard
9
- * @param value the value to check
9
+ * @param value - the value to check
10
10
  * @returns true if the value is a boolean
11
11
  */
12
12
  export declare function isBoolean(value: any): value is boolean;
13
13
  /**
14
14
  * a function type guard
15
- * @param value the value to check
15
+ * @param value - the value to check
16
16
  * @returns true if the value is a function
17
17
  */
18
18
  export declare function isFunction(value: any): value is (...args: any[]) => any;
19
19
  /**
20
20
  * a string type guard
21
- * @param value the value to check
21
+ * @param value - the value to check
22
22
  * @returns true if the value is a string
23
23
  */
24
24
  export declare function isString(value: any): value is string;
@@ -29,21 +29,21 @@ export declare function isString(value: any): value is string;
29
29
  export declare const isArray: (arg: any) => arg is any[];
30
30
  /**
31
31
  * Clamp the value based on a maximum and optional minimum
32
- * @param value the value to check
33
- * @param max the max to clamp to
34
- * @param [min] the min to clamp to
32
+ * @param value - the value to check
33
+ * @param max - the max to clamp to
34
+ * @param [min] - the min to clamp to
35
35
  * @returns the clamped value
36
36
  */
37
37
  export declare function clamp(value: number, max: number, min?: number): number;
38
38
  /**
39
39
  * an html element type guard
40
- * @param value the value to check
40
+ * @param value - the value to check
41
41
  * @returns true if the value is an instance of HTMLElement
42
42
  */
43
43
  export declare const isHTMLElement: (value: any) => value is HTMLElement;
44
44
  /**
45
45
  * Returns a new type guard that is based on the provided type guard and also returns true for null values.
46
- * @param isType base type guard
46
+ * @param isType - base type guard
47
47
  * @returns A type guard function that returns true for null values and calls the provided type guard for other values.
48
48
  */
49
49
  export declare const allowNull: <T>(isType: (value: any) => value is T) => (value: any) => value is T | null;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * a number type guard
3
- * @param value the value to check
3
+ * @param value - the value to check
4
4
  * @returns true if the value is a number
5
5
  */
6
6
  export function isNumber(value) {
@@ -8,7 +8,7 @@ export function isNumber(value) {
8
8
  }
9
9
  /**
10
10
  * a boolean type guard
11
- * @param value the value to check
11
+ * @param value - the value to check
12
12
  * @returns true if the value is a boolean
13
13
  */
14
14
  export function isBoolean(value) {
@@ -16,7 +16,7 @@ export function isBoolean(value) {
16
16
  }
17
17
  /**
18
18
  * a function type guard
19
- * @param value the value to check
19
+ * @param value - the value to check
20
20
  * @returns true if the value is a function
21
21
  */
22
22
  export function isFunction(value) {
@@ -24,7 +24,7 @@ export function isFunction(value) {
24
24
  }
25
25
  /**
26
26
  * a string type guard
27
- * @param value the value to check
27
+ * @param value - the value to check
28
28
  * @returns true if the value is a string
29
29
  */
30
30
  export function isString(value) {
@@ -38,9 +38,9 @@ export const isArray = Array.isArray;
38
38
  // TODO should we check that max > min?
39
39
  /**
40
40
  * Clamp the value based on a maximum and optional minimum
41
- * @param value the value to check
42
- * @param max the max to clamp to
43
- * @param [min] the min to clamp to
41
+ * @param value - the value to check
42
+ * @param max - the max to clamp to
43
+ * @param [min] - the min to clamp to
44
44
  * @returns the clamped value
45
45
  */
46
46
  export function clamp(value, max, min = 0) {
@@ -48,13 +48,13 @@ export function clamp(value, max, min = 0) {
48
48
  }
49
49
  /**
50
50
  * an html element type guard
51
- * @param value the value to check
51
+ * @param value - the value to check
52
52
  * @returns true if the value is an instance of HTMLElement
53
53
  */
54
54
  export const isHTMLElement = (value) => value instanceof HTMLElement;
55
55
  /**
56
56
  * Returns a new type guard that is based on the provided type guard and also returns true for null values.
57
- * @param isType base type guard
57
+ * @param isType - base type guard
58
58
  * @returns A type guard function that returns true for null values and calls the provided type guard for other values.
59
59
  */
60
60
  export const allowNull = (isType) => (value) => value === null || isType(value);
@@ -9,5 +9,17 @@ export declare const computeCommonAncestor: (elements: HTMLElement[]) => HTMLEle
9
9
  * @param element - the html element
10
10
  */
11
11
  export declare function reflow(element?: HTMLElement): void;
12
+ /**
13
+ * Attach the given css classes to the element
14
+ *
15
+ * @param element - the HTML element
16
+ * @param classes - the css lcasses
17
+ */
12
18
  export declare const addClasses: (element: HTMLElement, classes?: string[]) => void;
19
+ /**
20
+ * Remove the given css classes to the element
21
+ *
22
+ * @param element - the HTML element
23
+ * @param classes - the css classes
24
+ */
13
25
  export declare const removeClasses: (element: HTMLElement, classes?: string[]) => void;
@@ -37,11 +37,23 @@ export const computeCommonAncestor = (elements) => {
37
37
  export function reflow(element = document.body) {
38
38
  element.getBoundingClientRect();
39
39
  }
40
+ /**
41
+ * Attach the given css classes to the element
42
+ *
43
+ * @param element - the HTML element
44
+ * @param classes - the css lcasses
45
+ */
40
46
  export const addClasses = (element, classes) => {
41
47
  if (classes && classes.length > 0) {
42
48
  element.classList.add(...classes);
43
49
  }
44
50
  };
51
+ /**
52
+ * Remove the given css classes to the element
53
+ *
54
+ * @param element - the HTML element
55
+ * @param classes - the css classes
56
+ */
45
57
  export const removeClasses = (element, classes) => {
46
58
  if (classes && classes.length > 0) {
47
59
  element.classList.remove(...classes);
@@ -1,2 +1,11 @@
1
+ /**
2
+ * A noop function
3
+ */
1
4
  export declare const noop: () => void;
5
+ /**
6
+ * The identity function
7
+ *
8
+ * @param x - the arg
9
+ * @returns the arg
10
+ */
2
11
  export declare const identity: <T>(x: T) => T;
@@ -1,2 +1,11 @@
1
+ /**
2
+ * A noop function
3
+ */
1
4
  export const noop = () => { };
5
+ /**
6
+ * The identity function
7
+ *
8
+ * @param x - the arg
9
+ * @returns the arg
10
+ */
2
11
  export const identity = (x) => x;
@@ -5,18 +5,74 @@ export interface PromisePendingResult {
5
5
  }
6
6
  export declare const promisePending: PromisePendingResult;
7
7
  export type PromiseState<T> = PromiseFulfilledResult<T> | PromiseRejectedResult | PromisePendingResult;
8
+ /**
9
+ * Create a readable promise state store from a promise.
10
+ *
11
+ * The state of the returned store tracks the state of the promise and the resolved value or rejection reason.
12
+ *
13
+ * @param value - the promise
14
+ * @returns the readable promise state store
15
+ */
8
16
  export declare const promiseStateStore: <T>(value: T) => ReadableSignal<Readonly<PromiseState<Awaited<T>>>>;
17
+ /**
18
+ * Create a readable promise state store from a promise store.
19
+ *
20
+ * @param promiseStore$ - the promise store
21
+ * @returns the readable promise state store
22
+ */
9
23
  export declare const promiseStoreToPromiseStateStore: <T>(promiseStore$: ReadableSignal<T>) => ReadableSignal<PromiseState<Awaited<T>>>;
24
+ /**
25
+ * Create a value store from a promise state store
26
+ *
27
+ * The returned value store is only updated if the promise is fulfilled.
28
+ *
29
+ * @param store$ - the promise state store
30
+ * @param initialValue - the initial value of the returned value store
31
+ * @param equal - an equal function to compare values
32
+ * @returns the value store
33
+ */
10
34
  export declare const promiseStateStoreToValueStore: <T>(store$: ReadableSignal<PromiseState<T>>, initialValue: T, equal?: ((a: T, b: T) => boolean) | undefined) => ReadableSignal<T>;
35
+ /**
36
+ * Create a value store from a promise store
37
+ *
38
+ * The returned value store is only updated if the promise is fulfilled.
39
+ *
40
+ * @param promiseStore$ - the promise store
41
+ * @param initialValue - the initial value of the returned value store
42
+ * @param equal - an equal function to compare values
43
+ * @returns the value store
44
+ */
11
45
  export declare const promiseStoreToValueStore: <T>(promiseStore$: ReadableSignal<T>, initialValue: Awaited<T>, equal?: ((a: Awaited<T>, b: Awaited<T>) => boolean) | undefined) => ReadableSignal<Awaited<T>>;
46
+ /**
47
+ * Create a promise from a readable store and a fulfilled condition function.
48
+ *
49
+ * The promise is fulfilled when the state of the store respects the provided condition function.
50
+ *
51
+ * @param store - the readable store
52
+ * @param condition - the condition function
53
+ * @returns the promise and an unsubscribe function
54
+ */
12
55
  export declare const promiseFromStore: <T>(store: ReadableSignal<T>, condition?: (value: T) => boolean) => {
13
56
  promise: Promise<T>;
14
57
  unsubscribe(): void;
15
58
  };
59
+ /**
60
+ * Create a promise from an HTML element event.
61
+ *
62
+ * @param element - the event target
63
+ * @param event - the event to listen to
64
+ * @returns the promise and an unsubscribe function
65
+ */
16
66
  export declare const promiseFromEvent: (element: EventTarget, event: string) => {
17
67
  promise: Promise<Event>;
18
68
  unsubscribe(): void;
19
69
  };
70
+ /**
71
+ * Create a promise that resolves once a timeout has been reached.
72
+ *
73
+ * @param delay - the delay in milli seconds
74
+ * @returns a promise and an unsubscribe function
75
+ */
20
76
  export declare const promiseFromTimeout: (delay: number) => {
21
77
  promise: Promise<void>;
22
78
  unsubscribe(): void;
@@ -12,6 +12,14 @@ const createPromiseStateStore = (promise) => {
12
12
  return asReadable(store);
13
13
  };
14
14
  const promiseWeakMap = new WeakMap();
15
+ /**
16
+ * Create a readable promise state store from a promise.
17
+ *
18
+ * The state of the returned store tracks the state of the promise and the resolved value or rejection reason.
19
+ *
20
+ * @param value - the promise
21
+ * @returns the readable promise state store
22
+ */
15
23
  export const promiseStateStore = (value) => {
16
24
  if (!isThenable(value)) {
17
25
  return readable({ status: 'fulfilled', value: value });
@@ -27,7 +35,23 @@ const promiseStateStoreEqual = (a, b) => Object.is(a, b) ||
27
35
  (a.status === b.status &&
28
36
  (a.status !== 'fulfilled' || equal(a.value, b.value)) &&
29
37
  (a.status !== 'rejected' || equal(a.reason, b.reason)));
38
+ /**
39
+ * Create a readable promise state store from a promise store.
40
+ *
41
+ * @param promiseStore$ - the promise store
42
+ * @returns the readable promise state store
43
+ */
30
44
  export const promiseStoreToPromiseStateStore = (promiseStore$) => computed(() => promiseStateStore(promiseStore$())(), { equal: promiseStateStoreEqual });
45
+ /**
46
+ * Create a value store from a promise state store
47
+ *
48
+ * The returned value store is only updated if the promise is fulfilled.
49
+ *
50
+ * @param store$ - the promise state store
51
+ * @param initialValue - the initial value of the returned value store
52
+ * @param equal - an equal function to compare values
53
+ * @returns the value store
54
+ */
31
55
  export const promiseStateStoreToValueStore = (store$, initialValue, equal) => derived(store$, {
32
56
  derive: (state, set) => {
33
57
  if (state.status === 'fulfilled') {
@@ -36,8 +60,27 @@ export const promiseStateStoreToValueStore = (store$, initialValue, equal) => de
36
60
  },
37
61
  equal,
38
62
  }, initialValue);
63
+ /**
64
+ * Create a value store from a promise store
65
+ *
66
+ * The returned value store is only updated if the promise is fulfilled.
67
+ *
68
+ * @param promiseStore$ - the promise store
69
+ * @param initialValue - the initial value of the returned value store
70
+ * @param equal - an equal function to compare values
71
+ * @returns the value store
72
+ */
39
73
  export const promiseStoreToValueStore = (promiseStore$, initialValue, equal) => promiseStateStoreToValueStore(promiseStoreToPromiseStateStore(promiseStore$), initialValue, equal);
40
74
  const truthyValue = (value) => !!value;
75
+ /**
76
+ * Create a promise from a readable store and a fulfilled condition function.
77
+ *
78
+ * The promise is fulfilled when the state of the store respects the provided condition function.
79
+ *
80
+ * @param store - the readable store
81
+ * @param condition - the condition function
82
+ * @returns the promise and an unsubscribe function
83
+ */
41
84
  export const promiseFromStore = (store, condition = truthyValue) => {
42
85
  let resolve;
43
86
  const promise = new Promise((r) => (resolve = r));
@@ -62,6 +105,13 @@ export const promiseFromStore = (store, condition = truthyValue) => {
62
105
  },
63
106
  };
64
107
  };
108
+ /**
109
+ * Create a promise from an HTML element event.
110
+ *
111
+ * @param element - the event target
112
+ * @param event - the event to listen to
113
+ * @returns the promise and an unsubscribe function
114
+ */
65
115
  export const promiseFromEvent = (element, event) => {
66
116
  let resolve;
67
117
  const promise = new Promise((r) => (resolve = r));
@@ -83,6 +133,12 @@ export const promiseFromEvent = (element, event) => {
83
133
  },
84
134
  };
85
135
  };
136
+ /**
137
+ * Create a promise that resolves once a timeout has been reached.
138
+ *
139
+ * @param delay - the delay in milli seconds
140
+ * @returns a promise and an unsubscribe function
141
+ */
86
142
  export const promiseFromTimeout = (delay) => {
87
143
  let timeout;
88
144
  return {
@@ -1,2 +1,8 @@
1
+ /**
2
+ * A function to remove the scrollbars on the body element. It can be reverted using the {@link revertScrollbars} function.
3
+ */
1
4
  export declare const removeScrollbars: () => void;
5
+ /**
6
+ * A function to revert the removal of scrollbars performed by the {@link removeScrollbars} function.
7
+ */
2
8
  export declare const revertScrollbars: () => void;
@@ -17,10 +17,16 @@ const internalRemoveScrollbars = () => {
17
17
  };
18
18
  };
19
19
  let internalRevert = noop;
20
+ /**
21
+ * A function to remove the scrollbars on the body element. It can be reverted using the {@link revertScrollbars} function.
22
+ */
20
23
  export const removeScrollbars = () => {
21
24
  internalRevert();
22
25
  internalRevert = internalRemoveScrollbars();
23
26
  };
27
+ /**
28
+ * A function to revert the removal of scrollbars performed by the {@link removeScrollbars} function.
29
+ */
24
30
  export const revertScrollbars = () => {
25
31
  internalRevert();
26
32
  internalRevert = noop;
@@ -1,2 +1,16 @@
1
+ /**
2
+ * The default comparision between two values, using the javascript < and > signs.
3
+ *
4
+ * @param a - the first input
5
+ * @param b - the second input
6
+ * @returns 1, 0 or -1 depending on the default compare
7
+ */
1
8
  export declare const compareDefault: (a: any, b: any) => 0 | 1 | -1;
9
+ /**
10
+ * A comparision function between DOM elements, based on [Node.compareDocumentPosition](https://developer.mozilla.org/fr/docs/Web/API/Node/compareDocumentPosition).
11
+ *
12
+ * @param element1 - the first node
13
+ * @param element2 - the second node
14
+ * @returns 1, 0 or -1
15
+ */
2
16
  export declare const compareDomOrder: (element1: Node, element2: Node) => 0 | 1 | -1;
@@ -1,4 +1,18 @@
1
+ /**
2
+ * The default comparision between two values, using the javascript < and > signs.
3
+ *
4
+ * @param a - the first input
5
+ * @param b - the second input
6
+ * @returns 1, 0 or -1 depending on the default compare
7
+ */
1
8
  export const compareDefault = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
9
+ /**
10
+ * A comparision function between DOM elements, based on [Node.compareDocumentPosition](https://developer.mozilla.org/fr/docs/Web/API/Node/compareDocumentPosition).
11
+ *
12
+ * @param element1 - the first node
13
+ * @param element2 - the second node
14
+ * @returns 1, 0 or -1
15
+ */
2
16
  export const compareDomOrder = (element1, element2) => {
3
17
  if (element1 === element2) {
4
18
  return 0;
@@ -1 +1,7 @@
1
+ /**
2
+ * Returns the text direction of an element, using a call to `getComputedStyle`.
3
+ *
4
+ * @param element - the HTML element
5
+ * @returns the text direction of the element, 'ltr' or 'rtl'
6
+ */
1
7
  export declare const getTextDirection: (element: HTMLElement) => "rtl" | "ltr";
@@ -1 +1,7 @@
1
+ /**
2
+ * Returns the text direction of an element, using a call to `getComputedStyle`.
3
+ *
4
+ * @param element - the HTML element
5
+ * @returns the text direction of the element, 'ltr' or 'rtl'
6
+ */
1
7
  export const getTextDirection = (element) => getComputedStyle(element).direction;
package/utils/stores.d.ts CHANGED
@@ -79,7 +79,22 @@ export declare const toReadableStore: <T>(x: T | ReadableSignal<T>) => ReadableS
79
79
  * @returns either x if x is already a store, or writable(x) otherwise
80
80
  */
81
81
  export declare const toWritableStore: <T>(x: T | WritableSignal<T, T>) => WritableSignal<T, T>;
82
+ /**
83
+ * Extract and normalize config stores.
84
+ *
85
+ * @param keys - the keys of the stores to extract / normalize
86
+ * @param config - the config stores
87
+ * @returns the normalized config stores
88
+ */
82
89
  export declare const normalizeConfigStores: <T extends object>(keys: (keyof T)[], config?: ReadableSignal<Partial<T>> | ValuesOrReadableSignals<T> | undefined) => ReadableSignals<T>;
90
+ /**
91
+ * Merge two stores configs into one
92
+ *
93
+ * @param keys - the keys of the stores to extract and merge from the two provided configs
94
+ * @param config1 - the first config
95
+ * @param config2 - the second config
96
+ * @returns the merged config
97
+ */
83
98
  export declare const mergeConfigStores: <T extends object>(keys: (keyof T)[], config1?: ReadableSignals<T> | undefined, config2?: ReadableSignals<T> | undefined) => ReadableSignals<T>;
84
99
  /**
85
100
  * Returns an object containing, for each property of `defConfig`, a corresponding writable with the normalization and default value logic
@@ -136,6 +151,12 @@ export declare const writablesWithDefault: <T extends object>(defConfig: T, prop
136
151
  * ```
137
152
  */
138
153
  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];
154
+ /**
155
+ * Using input stores, this function builds an object containing the stores as readable and a global state.
156
+ *
157
+ * @param inputStores - the input stores
158
+ * @returns the object containing the stores as readable and the global state
159
+ */
139
160
  export declare const stateStores: <A extends {
140
161
  [x: `${string}$`]: ReadableSignal<any>;
141
162
  }>(inputStores: A) => {
package/utils/stores.js CHANGED
@@ -117,6 +117,13 @@ export const toReadableStore = (x) => (isStore(x) ? x : readable(x));
117
117
  * @returns either x if x is already a store, or writable(x) otherwise
118
118
  */
119
119
  export const toWritableStore = (x) => (isStore(x) ? x : writable(x));
120
+ /**
121
+ * Extract and normalize config stores.
122
+ *
123
+ * @param keys - the keys of the stores to extract / normalize
124
+ * @param config - the config stores
125
+ * @returns the normalized config stores
126
+ */
120
127
  export const normalizeConfigStores = (keys, config) => {
121
128
  const res = {};
122
129
  if (config) {
@@ -129,6 +136,14 @@ export const normalizeConfigStores = (keys, config) => {
129
136
  }
130
137
  return res;
131
138
  };
139
+ /**
140
+ * Merge two stores configs into one
141
+ *
142
+ * @param keys - the keys of the stores to extract and merge from the two provided configs
143
+ * @param config1 - the first config
144
+ * @param config2 - the second config
145
+ * @returns the merged config
146
+ */
132
147
  export const mergeConfigStores = (keys, config1, config2) => {
133
148
  const res = {};
134
149
  for (const key of keys) {
@@ -206,6 +221,12 @@ export const writablesForProps = (defConfig, propsConfig, options) => {
206
221
  const stores = writablesWithDefault(defConfig, propsConfig, options);
207
222
  return [stores, createPatch(stores)];
208
223
  };
224
+ /**
225
+ * Using input stores, this function builds an object containing the stores as readable and a global state.
226
+ *
227
+ * @param inputStores - the input stores
228
+ * @returns the object containing the stores as readable and the global state
229
+ */
209
230
  export const stateStores = (inputStores) => {
210
231
  const storesNames = [];
211
232
  const storesArray = [];
@@ -1,5 +1,11 @@
1
1
  import type { WritableWithDefaultOptions } from '../types';
2
2
  import { INVALID_VALUE } from '../types';
3
+ /**
4
+ * Check if a value respects a provided type guard.
5
+ *
6
+ * @param filter - the guard function
7
+ * @returns a function that takes a value as input, checks if it respects the type guard and returns `INVALID_VALUE` otherwise
8
+ */
3
9
  export declare const testToNormalizeValue: <T>(filter: (value: any) => value is T) => (value: any) => typeof INVALID_VALUE | T;
4
10
  export declare const typeNumber: WritableWithDefaultOptions<number>;
5
11
  export interface TypeNumberInRangeOptions {
@@ -1,5 +1,11 @@
1
1
  import { allowNull, clamp, isArray, isBoolean, isFunction, isHTMLElement, isNumber, isString } from './internal/checks';
2
2
  import { INVALID_VALUE } from '../types';
3
+ /**
4
+ * Check if a value respects a provided type guard.
5
+ *
6
+ * @param filter - the guard function
7
+ * @returns a function that takes a value as input, checks if it respects the type guard and returns `INVALID_VALUE` otherwise
8
+ */
3
9
  export const testToNormalizeValue = (filter) => (value) => filter(value) ? value : INVALID_VALUE;
4
10
  const numberNormalizeFn = testToNormalizeValue(isNumber);
5
11
  export const typeNumber = {