@agnos-ui/svelte-bootstrap 0.8.1 → 0.9.0-next.0

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.
@@ -9,11 +9,8 @@ import {BROWSER as __AgnosUISveltePreprocess__BROWSER} from 'esm-env';
9
9
 
10
10
  let {children, ...props}: Partial<AccordionProps> & {children: Snippet} = $props();
11
11
 
12
- const {directives, api: accordionApi} = callWidgetFactory({
13
- factory: createAccordion,
14
- widgetName: 'accordion',
12
+ const {directives, api: accordionApi} = callWidgetFactory(createAccordion, {
15
13
  props,
16
- enablePatchChanged: true,
17
14
  });
18
15
  export const api: AccordionApi = accordionApi;
19
16
 
@@ -2,8 +2,7 @@
2
2
  import {ssrAttributes as __AgnosUISveltePreprocess__ssrAttributes, classDirective as __AgnosUISveltePreprocess__classDirective} from '@agnos-ui/svelte-headless/utils/directive';
3
3
  import {BROWSER as __AgnosUISveltePreprocess__BROWSER} from 'esm-env';
4
4
 
5
- import type {AccordionItemApi, AccordionItemContext, AccordionItemProps, AccordionItemWidget} from './accordion';
6
- import type {WidgetFactory} from '@agnos-ui/svelte-headless/types';
5
+ import type {AccordionItemApi, AccordionItemContext, AccordionItemProps} from './accordion';
7
6
  import {Slot} from '@agnos-ui/svelte-headless/slot';
8
7
  import {callWidgetFactory} from '../../config';
9
8
  import {onMount} from 'svelte';
@@ -15,12 +14,10 @@ import {BROWSER as __AgnosUISveltePreprocess__BROWSER} from 'esm-env';
15
14
 
16
15
  const id = $props.id();
17
16
  let {visible = $bindable(), ...props}: Partial<AccordionItemProps> = $props();
18
- const widget = callWidgetFactory({
19
- factory: registerItem as WidgetFactory<AccordionItemWidget>,
17
+ const widget = callWidgetFactory(registerItem, {
20
18
  get props() {
21
19
  return {...props, visible};
22
20
  },
23
- enablePatchChanged: true,
24
21
  defaultConfig: {structure, id},
25
22
  events: {
26
23
  onVisibleChange: (event) => {
@@ -9,13 +9,10 @@ import {BROWSER as __AgnosUISveltePreprocess__BROWSER} from 'esm-env';
9
9
 
10
10
  let {visible = $bindable(), ...props}: Partial<AlertProps> = $props();
11
11
 
12
- const widget = callWidgetFactory({
13
- factory: createAlert,
14
- widgetName: 'alert',
12
+ const widget = callWidgetFactory(createAlert, {
15
13
  get props() {
16
14
  return {...props, visible};
17
15
  },
18
- enablePatchChanged: true,
19
16
  defaultConfig: {structure},
20
17
  events: {
21
18
  onVisibleChange: (event) => {
@@ -38,8 +35,8 @@ import {BROWSER as __AgnosUISveltePreprocess__BROWSER} from 'esm-env';
38
35
  {#if !state.hidden}
39
36
  <div
40
37
  role="alert"
41
- use:__AgnosUISveltePreprocess__classDirective={"au-alert alert alert-"+(state.type)+" "+(state.className)+" "+(state.dismissible ? 'alert-dismissible' : '')}
42
- use:transitionDirective {...__AgnosUISveltePreprocess__BROWSER ? {} : __AgnosUISveltePreprocess__ssrAttributes(transitionDirective, [__AgnosUISveltePreprocess__classDirective, "au-alert alert alert-"+(state.type)+" "+(state.className)+" "+(state.dismissible ? 'alert-dismissible' : '')])}
38
+ use:__AgnosUISveltePreprocess__classDirective={(['au-alert', 'alert', `alert-${state.type}`, state.className, state.dismissible && 'alert-dismissible'])}
39
+ use:transitionDirective {...__AgnosUISveltePreprocess__BROWSER ? {} : __AgnosUISveltePreprocess__ssrAttributes(transitionDirective, [__AgnosUISveltePreprocess__classDirective, (['au-alert', 'alert', `alert-${state.type}`, state.className, state.dismissible && 'alert-dismissible'])])}
43
40
  >
44
41
  <Slot content={state.structure} props={widget} />
45
42
  </div>
@@ -11,11 +11,8 @@ import {BROWSER as __AgnosUISveltePreprocess__BROWSER} from 'esm-env';
11
11
 
12
12
  let props: Partial<CarouselProps<SlideData>> = $props();
13
13
 
14
- const widget = callWidgetFactory({
15
- factory: createCarousel<SlideData>,
16
- widgetName: 'collapse',
14
+ const widget = callWidgetFactory(createCarousel<SlideData>, {
17
15
  props,
18
- enablePatchChanged: true,
19
16
  defaultConfig: {
20
17
  structure,
21
18
  navigation,
@@ -1,4 +1,4 @@
1
- import type { PropsConfig, WidgetSlotContext, SlotContent, Directive, Widget } from '@agnos-ui/svelte-headless/types';
1
+ import type { WidgetSlotContext, SlotContent, Directive, Widget, WidgetFactory, PropsConfig } from '@agnos-ui/svelte-headless/types';
2
2
  import type { EmblaPluginType, EmblaPluginsType, EmblaCarouselType } from 'embla-carousel';
3
3
  /**
4
4
  * Retrieve a shallow copy of the default Carousel config
@@ -6,17 +6,6 @@ import type { EmblaPluginType, EmblaPluginsType, EmblaCarouselType } from 'embla
6
6
  */
7
7
  declare const export_getCarouselDefaultConfig: () => CarouselProps<any>;
8
8
  export { export_getCarouselDefaultConfig as getCarouselDefaultConfig };
9
- /**
10
- * Create a Carousel with given config props
11
- *
12
- * @template SlideData - The type of the data for each slide.
13
- * @param config - an optional carousel config
14
- * @returns a CarouselWidget
15
- */
16
- declare const export_createCarousel: <SlideData extends {
17
- id: string;
18
- }>(config?: PropsConfig<CarouselProps<SlideData>>) => CarouselWidget<SlideData>;
19
- export { export_createCarousel as createCarousel };
20
9
  /**
21
10
  * Represents the context for a carousel.
22
11
  *
@@ -327,6 +316,19 @@ export interface CarouselDirectives {
327
316
  export type CarouselWidget<SlideData extends {
328
317
  id: string;
329
318
  }> = Widget<CarouselProps<SlideData>, CarouselState<SlideData>, CarouselApi, CarouselDirectives>;
319
+ /**
320
+ * Create a Carousel with given config props
321
+ *
322
+ * @template SlideData - The type of the data for each slide.
323
+ * @param config - an optional carousel config
324
+ * @returns a CarouselWidget
325
+ */
326
+ declare const export_createCarousel: WidgetFactory<CarouselWidget<{
327
+ id: string;
328
+ }>, <SlideData extends {
329
+ id: string;
330
+ }>(config?: PropsConfig<CarouselProps<SlideData>>) => CarouselWidget<SlideData>>;
331
+ export { export_createCarousel as createCarousel };
330
332
  /**
331
333
  * Represents the API for a carousel component.
332
334
  */
@@ -13,9 +13,7 @@ import {BROWSER as __AgnosUISveltePreprocess__BROWSER} from 'esm-env';
13
13
  const {
14
14
  directives: {collapseDirective},
15
15
  api: collapseApi,
16
- } = callWidgetFactory({
17
- factory: createCollapse,
18
- widgetName: 'collapse',
16
+ } = callWidgetFactory(createCollapse, {
19
17
  get props() {
20
18
  return {...props, visible};
21
19
  },
@@ -27,7 +25,6 @@ import {BROWSER as __AgnosUISveltePreprocess__BROWSER} from 'esm-env';
27
25
  visible = event;
28
26
  },
29
27
  },
30
- enablePatchChanged: true,
31
28
  });
32
29
  export const api: CollapseApi = collapseApi;
33
30
  </script>
@@ -1,17 +1,10 @@
1
- import type { PropsConfig, Directive, Widget } from '@agnos-ui/svelte-headless/types';
1
+ import type { Directive, Widget, WidgetFactory } from '@agnos-ui/svelte-headless/types';
2
2
  /**
3
3
  * Retrieve a shallow copy of the default collapse config
4
4
  * @returns the default collapse config
5
5
  */
6
6
  declare const export_getCollapseDefaultConfig: () => CollapseProps;
7
7
  export { export_getCollapseDefaultConfig as getCollapseDefaultConfig };
8
- /**
9
- * Create an CollapseWidget with given config props
10
- * @param config - an optional collapse config
11
- * @returns an CollapseWidget
12
- */
13
- declare const export_createCollapse: (config?: PropsConfig<CollapseProps>) => CollapseWidget;
14
- export { export_createCollapse as createCollapse };
15
8
  /**
16
9
  * Represents the state of a collapse component.
17
10
  * Extends the properties and state from `CollapseCommonPropsAndState`.
@@ -148,3 +141,10 @@ export interface CollapseDirectives {
148
141
  * @type {Widget<CollapseProps, CollapseState, CollapseApi, CollapseDirectives>}
149
142
  */
150
143
  export type CollapseWidget = Widget<CollapseProps, CollapseState, CollapseApi, CollapseDirectives>;
144
+ /**
145
+ * Create an CollapseWidget with given config props
146
+ * @param config - an optional collapse config
147
+ * @returns an CollapseWidget
148
+ */
149
+ declare const export_createCollapse: WidgetFactory<CollapseWidget>;
150
+ export { export_createCollapse as createCollapse };
@@ -11,13 +11,10 @@ import {BROWSER as __AgnosUISveltePreprocess__BROWSER} from 'esm-env';
11
11
 
12
12
  let {visible = $bindable(), ...props}: Partial<ModalProps<Data>> = $props();
13
13
 
14
- const widget = callWidgetFactory<ModalWidget<Data>>({
15
- factory: createModal,
16
- widgetName: 'modal',
14
+ const widget = callWidgetFactory<ModalWidget<Data>>(createModal, {
17
15
  get props() {
18
16
  return {...props, visible};
19
17
  },
20
- enablePatchChanged: true,
21
18
  defaultConfig: {
22
19
  header,
23
20
  structure,
@@ -8,13 +8,10 @@
8
8
 
9
9
  let {page = $bindable(), ...props}: Partial<PaginationProps> = $props();
10
10
 
11
- const widget = callWidgetFactory({
12
- factory: createPagination,
13
- widgetName: 'pagination',
11
+ const widget = callWidgetFactory(createPagination, {
14
12
  get props() {
15
13
  return {...props, page};
16
14
  },
17
- enablePatchChanged: true,
18
15
  defaultConfig: {
19
16
  structure,
20
17
  pagesDisplay,
@@ -9,11 +9,8 @@ import {BROWSER as __AgnosUISveltePreprocess__BROWSER} from 'esm-env';
9
9
 
10
10
  let props: Partial<ProgressbarProps> = $props();
11
11
 
12
- const widget = callWidgetFactory({
13
- factory: createProgressbar,
14
- widgetName: 'progressbar',
12
+ const widget = callWidgetFactory(createProgressbar, {
15
13
  props,
16
- enablePatchChanged: true,
17
14
  defaultConfig: {
18
15
  structure,
19
16
  },
@@ -13,13 +13,10 @@ import {BROWSER as __AgnosUISveltePreprocess__BROWSER} from 'esm-env';
13
13
  state,
14
14
  directives: {containerDirective, starDirective},
15
15
  api: ratingApi,
16
- } = callWidgetFactory({
17
- factory: createRating,
18
- widgetName: 'rating',
16
+ } = callWidgetFactory(createRating, {
19
17
  get props() {
20
18
  return {...props, rating};
21
19
  },
22
- enablePatchChanged: true,
23
20
  defaultConfig: {star},
24
21
  events: {
25
22
  onRatingChange: (value: number) => {
@@ -9,13 +9,10 @@ import {BROWSER as __AgnosUISveltePreprocess__BROWSER} from 'esm-env';
9
9
 
10
10
  let {open = $bindable(false), filterText = $bindable(), selected = $bindable(), ...props}: Partial<SelectProps<Item>> = $props();
11
11
 
12
- const widget = callWidgetFactory<SelectWidget<Item>>({
13
- factory: createSelect,
14
- widgetName: 'select',
12
+ const widget = callWidgetFactory<SelectWidget<Item>>(createSelect, {
15
13
  get props() {
16
14
  return {...props, open, filterText, selected};
17
15
  },
18
- enablePatchChanged: true,
19
16
  defaultConfig: {badgeLabel, itemLabel},
20
17
  events: {
21
18
  onOpenChange: function (isOpen: boolean): void {
@@ -12,13 +12,10 @@ import {BROWSER as __AgnosUISveltePreprocess__BROWSER} from 'esm-env';
12
12
 
13
13
  let {values = $bindable(), ...props}: Partial<SliderProps> = $props();
14
14
 
15
- const widget = callWidgetFactory({
16
- factory: createSlider,
17
- widgetName: 'slider',
15
+ const widget = callWidgetFactory(createSlider, {
18
16
  get props() {
19
17
  return {...props, values};
20
18
  },
21
- enablePatchChanged: true,
22
19
  defaultConfig: {structure, handle, tick, label},
23
20
  events: {
24
21
  onValuesChange: function (newValues: number[]): void {
@@ -10,13 +10,10 @@ import {BROWSER as __AgnosUISveltePreprocess__BROWSER} from 'esm-env';
10
10
 
11
11
  let {visible = $bindable(), ...props}: Partial<ToastProps> = $props();
12
12
 
13
- const widget = callWidgetFactory({
14
- factory: createToast,
15
- widgetName: 'toast',
13
+ const widget = callWidgetFactory(createToast, {
16
14
  get props() {
17
15
  return {...props, visible};
18
16
  },
19
- enablePatchChanged: true,
20
17
  defaultConfig: {structure},
21
18
  events: {
22
19
  onVisibleChange: (event) => {
@@ -10,11 +10,8 @@
10
10
 
11
11
  let props: Partial<TreeProps> = $props();
12
12
 
13
- const widget = callWidgetFactory({
14
- factory: createTree,
15
- widgetName: 'tree',
13
+ const widget = callWidgetFactory(createTree, {
16
14
  props,
17
- enablePatchChanged: true,
18
15
  defaultConfig: {structure, item, itemContent, itemToggle},
19
16
  });
20
17
  const {state} = widget;
package/config.d.ts CHANGED
@@ -2,7 +2,72 @@ import type { Partial2Levels, WidgetsConfigStore } from '@agnos-ui/svelte-headle
2
2
  import type { ReadableSignal } from '@amadeus-it-group/tansu';
3
3
  export * from '@agnos-ui/svelte-headless/config';
4
4
  import type { WidgetsConfig } from './config.gen';
5
+ import type { Widget, WidgetFactory, WidgetProps, WidgetSlotContext } from '@agnos-ui/svelte-headless/types';
5
6
  export type { WidgetsConfig };
6
7
  type AdaptParentConfig = (config: Partial2Levels<WidgetsConfig>) => Partial2Levels<WidgetsConfig>;
7
8
  type CreateWidgetsDefaultConfig = (adaptParentConfig?: AdaptParentConfig) => WidgetsConfigStore<WidgetsConfig>;
8
- export declare const widgetsDefaultConfigKey: symbol, createWidgetsDefaultConfig: CreateWidgetsDefaultConfig, getContextWidgetConfig: <N extends keyof WidgetsConfig>(widgetName: N) => ReadableSignal<Partial<WidgetsConfig[N]> | undefined>, callWidgetFactory: any;
9
+ /**
10
+ * Key used in the Svelte context to get or set the widgets default configuration store.
11
+ */
12
+ export declare const widgetsDefaultConfigKey: symbol;
13
+ /**
14
+ * Creates in the Svelte context hierarchy a new widgets default configuration store that inherits from any widgets default configuration
15
+ * store already defined at an upper level in the Svelte context hierarchy.
16
+ * It contains its own set of widgets configuration properties that override the same properties form the parent configuration.
17
+ *
18
+ * @remarks
19
+ * The configuration is computed from the parent configuration in two steps:
20
+ * - first step: the parent configuration is transformed by the adaptParentConfig function (if specified).
21
+ * If adaptParentConfig is not specified, this step is skipped.
22
+ * - second step: the configuration from step 1 is merged (2-levels deep) with the own$ store. The own$ store initially contains
23
+ * an empty object (i.e. no property from the parent is overridden). It can be changed by calling set on the store returned by this function.
24
+ *
25
+ * @param adaptParentConfig - optional function that receives a 2-levels copy of the widgets default configuration
26
+ * defined at an upper level in the Svelte context hierarchy (or an empty object if there is none) and returns the widgets
27
+ * default configuration to be used.
28
+ * It is called only if the configuration is needed, and was not yet computed for the current value of the parent configuration.
29
+ * It is called in a tansu reactive context, so it can use any tansu store and will be called again if those stores change.
30
+ *
31
+ * @returns the resulting widgets default configuration store, which contains 3 additional properties that are stores:
32
+ * parent$, adaptedParent$ (containing the value computed after the first step), and own$ (that contains only overridding properties).
33
+ * The resulting store is writable, its set function is actually the set function of the own$ store.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const widgetsConfig = createWidgetsDefaultConfig((parentConfig) => {
38
+ * // first step configuration: transforms the parent configuration
39
+ * parentConfig.rating = parentConfig.rating ?? {};
40
+ * parentConfig.rating.className = `${parentConfig.rating.className ?? ''} my-rating-extra-class`
41
+ * return parentConfig;
42
+ * });
43
+ * widgetsConfig.set({
44
+ * // second step configuration: overrides the parent configuration
45
+ * rating: {
46
+ * slotStar: MyCustomSlotStar
47
+ * }
48
+ * });
49
+ * ```
50
+ */
51
+ export declare const createWidgetsDefaultConfig: CreateWidgetsDefaultConfig;
52
+ /**
53
+ * Retrieves a widgets configuration store from the Svelte context hierarchy.
54
+ *
55
+ * @param widgetName - the name of the widget
56
+ * @returns the widgets configuration store
57
+ */
58
+ export declare const getContextWidgetConfig: <N extends keyof WidgetsConfig>(widgetName: N) => ReadableSignal<Partial<WidgetsConfig[N]> | undefined>;
59
+ /**
60
+ * Creates and initializes a widget using the provided factory and configuration options.
61
+ *
62
+ * @param factory - the widget factory
63
+ * @param options - the optional options
64
+ * @param options.defaultConfig - the default configuration for the widget
65
+ * @param options.events - the events to be passed to the widget
66
+ * @param options.props - the props to be passed to the widget
67
+ * @returns the state, api and directives to track and interact with the widget
68
+ */
69
+ export declare const callWidgetFactory: <W extends Widget>(factory: WidgetFactory<W>, options?: {
70
+ defaultConfig?: Partial<WidgetProps<W>> | ReadableSignal<Partial<WidgetProps<W>> | undefined>;
71
+ events?: Partial<Pick<WidgetProps<W>, keyof WidgetProps<W> & `on${string}Change`>>;
72
+ props?: Partial<WidgetProps<W>>;
73
+ }) => WidgetSlotContext<W>;
package/config.js CHANGED
@@ -1,4 +1,64 @@
1
1
  import { widgetsConfigFactory } from '@agnos-ui/svelte-headless/config';
2
2
  export * from '@agnos-ui/svelte-headless/config';
3
3
  const configFactories = widgetsConfigFactory(Symbol('bootstrapWidgetsConfig'));
4
- export const { widgetsDefaultConfigKey, createWidgetsDefaultConfig, getContextWidgetConfig, callWidgetFactory } = configFactories;
4
+ /**
5
+ * Key used in the Svelte context to get or set the widgets default configuration store.
6
+ */
7
+ export const widgetsDefaultConfigKey = configFactories.widgetsDefaultConfigKey;
8
+ /**
9
+ * Creates in the Svelte context hierarchy a new widgets default configuration store that inherits from any widgets default configuration
10
+ * store already defined at an upper level in the Svelte context hierarchy.
11
+ * It contains its own set of widgets configuration properties that override the same properties form the parent configuration.
12
+ *
13
+ * @remarks
14
+ * The configuration is computed from the parent configuration in two steps:
15
+ * - first step: the parent configuration is transformed by the adaptParentConfig function (if specified).
16
+ * If adaptParentConfig is not specified, this step is skipped.
17
+ * - second step: the configuration from step 1 is merged (2-levels deep) with the own$ store. The own$ store initially contains
18
+ * an empty object (i.e. no property from the parent is overridden). It can be changed by calling set on the store returned by this function.
19
+ *
20
+ * @param adaptParentConfig - optional function that receives a 2-levels copy of the widgets default configuration
21
+ * defined at an upper level in the Svelte context hierarchy (or an empty object if there is none) and returns the widgets
22
+ * default configuration to be used.
23
+ * It is called only if the configuration is needed, and was not yet computed for the current value of the parent configuration.
24
+ * It is called in a tansu reactive context, so it can use any tansu store and will be called again if those stores change.
25
+ *
26
+ * @returns the resulting widgets default configuration store, which contains 3 additional properties that are stores:
27
+ * parent$, adaptedParent$ (containing the value computed after the first step), and own$ (that contains only overridding properties).
28
+ * The resulting store is writable, its set function is actually the set function of the own$ store.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const widgetsConfig = createWidgetsDefaultConfig((parentConfig) => {
33
+ * // first step configuration: transforms the parent configuration
34
+ * parentConfig.rating = parentConfig.rating ?? {};
35
+ * parentConfig.rating.className = `${parentConfig.rating.className ?? ''} my-rating-extra-class`
36
+ * return parentConfig;
37
+ * });
38
+ * widgetsConfig.set({
39
+ * // second step configuration: overrides the parent configuration
40
+ * rating: {
41
+ * slotStar: MyCustomSlotStar
42
+ * }
43
+ * });
44
+ * ```
45
+ */
46
+ export const createWidgetsDefaultConfig = configFactories.createWidgetsDefaultConfig;
47
+ /**
48
+ * Retrieves a widgets configuration store from the Svelte context hierarchy.
49
+ *
50
+ * @param widgetName - the name of the widget
51
+ * @returns the widgets configuration store
52
+ */
53
+ export const getContextWidgetConfig = configFactories.getContextWidgetConfig;
54
+ /**
55
+ * Creates and initializes a widget using the provided factory and configuration options.
56
+ *
57
+ * @param factory - the widget factory
58
+ * @param options - the optional options
59
+ * @param options.defaultConfig - the default configuration for the widget
60
+ * @param options.events - the events to be passed to the widget
61
+ * @param options.props - the props to be passed to the widget
62
+ * @returns the state, api and directives to track and interact with the widget
63
+ */
64
+ export const callWidgetFactory = configFactories.callWidgetFactory;
@@ -4,6 +4,7 @@ export * from './index';
4
4
  export * from './config';
5
5
  export * from './utils/widget.svelte';
6
6
  export * from './utils/writables';
7
+ export * from './utils/widget';
7
8
  export * from './utils/stores';
8
9
  export * from './utils/func';
9
10
  export * from './utils/directive';
@@ -4,6 +4,7 @@ export * from './index';
4
4
  export * from './config';
5
5
  export * from './utils/widget.svelte';
6
6
  export * from './utils/writables';
7
+ export * from './utils/widget';
7
8
  export * from './utils/stores';
8
9
  export * from './utils/func';
9
10
  export * from './utils/directive';
@@ -0,0 +1 @@
1
+ export * from '@agnos-ui/svelte-headless/utils/widget';
@@ -0,0 +1 @@
1
+ export * from '@agnos-ui/svelte-headless/utils/widget';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agnos-ui/svelte-bootstrap",
3
3
  "description": "Bootstrap-based component library for Svelte.",
4
- "version": "0.8.1",
4
+ "version": "0.9.0-next.0",
5
5
  "type": "module",
6
6
  "main": "./index.js",
7
7
  "module": "./index.js",
@@ -49,8 +49,8 @@
49
49
  }
50
50
  },
51
51
  "dependencies": {
52
- "@agnos-ui/core-bootstrap": "0.8.1",
53
- "@agnos-ui/svelte-headless": "0.8.1"
52
+ "@agnos-ui/core-bootstrap": "0.9.0-next.0",
53
+ "@agnos-ui/svelte-headless": "0.9.0-next.0"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@amadeus-it-group/tansu": "^2.0.0",