@agnos-ui/svelte-headless 0.8.0 → 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.
- package/config.d.ts +12 -14
- package/config.js +22 -7
- package/generated/index.d.ts +5 -4
- package/generated/index.js +5 -4
- package/generated/utils/widget.d.ts +1 -0
- package/generated/utils/widget.js +1 -0
- package/package.json +2 -2
- package/utils/widget.svelte.d.ts +8 -11
- package/utils/widget.svelte.js +14 -17
package/config.d.ts
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import type { Partial2Levels, WidgetsConfigStore } from '@agnos-ui/core/config';
|
|
1
|
+
import type { WidgetsConfig, Partial2Levels, WidgetsConfigStore } from '@agnos-ui/core/config';
|
|
2
2
|
import type { ReadableSignal } from '@amadeus-it-group/tansu';
|
|
3
|
-
import type { Widget,
|
|
3
|
+
import type { Widget, WidgetFactory, WidgetProps } from '@agnos-ui/core/types';
|
|
4
4
|
export * from '@agnos-ui/core/config';
|
|
5
|
-
type WidgetFactoryInput<Config extends {
|
|
6
|
-
[widgetName: string]: object;
|
|
7
|
-
}, W extends Widget> = {
|
|
8
|
-
factory: WidgetFactory<W>;
|
|
9
|
-
widgetName?: null | keyof Config;
|
|
10
|
-
defaultConfig?: Partial<WidgetProps<W>> | ReadableSignal<Partial<WidgetProps<W>> | undefined>;
|
|
11
|
-
events?: Partial<Pick<WidgetProps<W>, keyof WidgetProps<W> & `on${string}Change`>>;
|
|
12
|
-
props?: Partial<WidgetProps<W>>;
|
|
13
|
-
enablePatchChanged?: true;
|
|
14
|
-
};
|
|
15
5
|
type AdaptParentConfig<Config> = (config: Partial2Levels<Config>) => Partial2Levels<Config>;
|
|
16
6
|
type CreateWidgetsDefaultConfig<Config extends {
|
|
17
7
|
[widgetName: string]: object;
|
|
@@ -34,6 +24,14 @@ export declare const widgetsConfigFactory: <Config extends {
|
|
|
34
24
|
widgetsDefaultConfigKey: symbol;
|
|
35
25
|
createWidgetsDefaultConfig: CreateWidgetsDefaultConfig<Config>;
|
|
36
26
|
getContextWidgetConfig: <N extends keyof Config>(widgetName: N) => ReadableSignal<Partial<Config[N]> | undefined>;
|
|
37
|
-
callWidgetFactory: <W extends Widget>(
|
|
27
|
+
callWidgetFactory: <W extends Widget>(factory: WidgetFactory<W>, options?: {
|
|
28
|
+
defaultConfig?: Partial<WidgetProps<W>> | ReadableSignal<Partial<WidgetProps<W>> | undefined>;
|
|
29
|
+
events?: Partial<Pick<WidgetProps<W>, keyof WidgetProps<W> & `on${string}Change`>>;
|
|
30
|
+
props?: Partial<WidgetProps<W>>;
|
|
31
|
+
}) => WidgetSlotContext<W_1>;
|
|
38
32
|
};
|
|
39
|
-
export declare const widgetsDefaultConfigKey: symbol, createWidgetsDefaultConfig: CreateWidgetsDefaultConfig<WidgetsConfig>, getContextWidgetConfig: <N extends string | number | symbol>(widgetName: N) => ReadableSignal<any>, callWidgetFactory: <W extends Widget>(
|
|
33
|
+
export declare const widgetsDefaultConfigKey: symbol, createWidgetsDefaultConfig: CreateWidgetsDefaultConfig<WidgetsConfig>, getContextWidgetConfig: <N extends string | number | symbol>(widgetName: N) => ReadableSignal<any>, callWidgetFactory: <W extends Widget>(factory: WidgetFactory<W>, options?: {
|
|
34
|
+
defaultConfig?: Partial<WidgetProps<W>> | ReadableSignal<Partial<WidgetProps<W>> | undefined>;
|
|
35
|
+
events?: Partial<Pick<WidgetProps<W>, keyof WidgetProps<W> & `on${string}Change`>>;
|
|
36
|
+
props?: Partial<WidgetProps<W>>;
|
|
37
|
+
} | undefined) => WidgetSlotContext<W_1>;
|
package/config.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createWidgetsConfig } from '@agnos-ui/core/config';
|
|
2
|
+
import { FACTORY_WIDGET_NAME } from '@agnos-ui/core/types';
|
|
2
3
|
import { computed } from '@amadeus-it-group/tansu';
|
|
3
4
|
import { getContext, setContext } from 'svelte';
|
|
4
5
|
import { callWidgetFactoryWithConfig } from './utils/widget.svelte';
|
|
@@ -57,19 +58,33 @@ export const widgetsConfigFactory = (widgetsDefaultConfigKey = Symbol('widgetsCo
|
|
|
57
58
|
setContext(widgetsDefaultConfigKey, child$);
|
|
58
59
|
return child$;
|
|
59
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Retrieves a widgets configuration store from the Svelte context hierarchy.
|
|
63
|
+
*
|
|
64
|
+
* @param widgetName - the name of the widget
|
|
65
|
+
* @returns the widgets configuration store
|
|
66
|
+
*/
|
|
60
67
|
const getContextWidgetConfig = (widgetName) => {
|
|
61
68
|
const widgetsConfig = getContext(widgetsDefaultConfigKey);
|
|
62
69
|
return computed(() => widgetsConfig?.()[widgetName]);
|
|
63
70
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Creates and initializes a widget using the provided factory and configuration options.
|
|
73
|
+
*
|
|
74
|
+
* @param factory - the widget factory
|
|
75
|
+
* @param options - the optional options
|
|
76
|
+
* @param options.defaultConfig - the default configuration for the widget
|
|
77
|
+
* @param options.events - the events to be passed to the widget
|
|
78
|
+
* @param options.props - the props to be passed to the widget
|
|
79
|
+
* @returns the state, api and directives to track and interact with the widget
|
|
80
|
+
*/
|
|
81
|
+
const callWidgetFactory = (factory, options) => callWidgetFactoryWithConfig(factory, {
|
|
82
|
+
defaultConfig: options?.defaultConfig,
|
|
83
|
+
widgetConfig: factory[FACTORY_WIDGET_NAME] ? getContextWidgetConfig(factory[FACTORY_WIDGET_NAME]) : null,
|
|
84
|
+
events: options?.events,
|
|
69
85
|
get props() {
|
|
70
|
-
return
|
|
86
|
+
return options?.props;
|
|
71
87
|
},
|
|
72
|
-
enablePatchChanged: input.enablePatchChanged,
|
|
73
88
|
});
|
|
74
89
|
return {
|
|
75
90
|
/**
|
package/generated/index.d.ts
CHANGED
|
@@ -8,14 +8,15 @@ export * from './services/hash';
|
|
|
8
8
|
export * from './services/focustrack';
|
|
9
9
|
export * from './services/floatingUI';
|
|
10
10
|
export * from './services/extendWidget';
|
|
11
|
-
export * from './utils/writables';
|
|
12
|
-
export * from './utils/stores';
|
|
13
|
-
export * from './utils/func';
|
|
14
|
-
export * from './utils/directive';
|
|
15
11
|
export * from './services/transitions/simpleClassTransition';
|
|
16
12
|
export * from './services/transitions/cssTransitions';
|
|
17
13
|
export * from './services/transitions/collapse';
|
|
18
14
|
export * from './services/transitions/baseTransitions';
|
|
15
|
+
export * from './utils/writables';
|
|
16
|
+
export * from './utils/widget';
|
|
17
|
+
export * from './utils/stores';
|
|
18
|
+
export * from './utils/func';
|
|
19
|
+
export * from './utils/directive';
|
|
19
20
|
export * from './types';
|
|
20
21
|
export * from './config';
|
|
21
22
|
export * from './components/tree/index';
|
package/generated/index.js
CHANGED
|
@@ -8,14 +8,15 @@ export * from './services/hash';
|
|
|
8
8
|
export * from './services/focustrack';
|
|
9
9
|
export * from './services/floatingUI';
|
|
10
10
|
export * from './services/extendWidget';
|
|
11
|
-
export * from './utils/writables';
|
|
12
|
-
export * from './utils/stores';
|
|
13
|
-
export * from './utils/func';
|
|
14
|
-
export * from './utils/directive';
|
|
15
11
|
export * from './services/transitions/simpleClassTransition';
|
|
16
12
|
export * from './services/transitions/cssTransitions';
|
|
17
13
|
export * from './services/transitions/collapse';
|
|
18
14
|
export * from './services/transitions/baseTransitions';
|
|
15
|
+
export * from './utils/writables';
|
|
16
|
+
export * from './utils/widget';
|
|
17
|
+
export * from './utils/stores';
|
|
18
|
+
export * from './utils/func';
|
|
19
|
+
export * from './utils/directive';
|
|
19
20
|
export * from './types';
|
|
20
21
|
export * from './config';
|
|
21
22
|
export * from './components/tree/index';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/utils/widget';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@agnos-ui/core/utils/widget';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agnos-ui/svelte-headless",
|
|
3
3
|
"description": "Headless component library for Svelte.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.0-next.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
7
7
|
"module": "./index.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@agnos-ui/core": "0.
|
|
52
|
+
"@agnos-ui/core": "0.9.0-next.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@amadeus-it-group/tansu": "^2.0.0",
|
package/utils/widget.svelte.d.ts
CHANGED
|
@@ -3,20 +3,17 @@ import type { Widget, WidgetFactory, WidgetProps, WidgetSlotContext } from '../t
|
|
|
3
3
|
/**
|
|
4
4
|
* Call a widget factory using provided configs.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @
|
|
13
|
-
* @returns the widget
|
|
6
|
+
* @param factory - the widget factory to call
|
|
7
|
+
* @param options - the optional options
|
|
8
|
+
* @param options.defaultConfig - the default config of the widget
|
|
9
|
+
* @param options.widgetConfig - the config of the widget, overriding the defaultConfig
|
|
10
|
+
* @param options.events - the events of the widget
|
|
11
|
+
* @param options.props - the props of the widget
|
|
12
|
+
* @returns the state, api and directives to track and interact with the widget
|
|
14
13
|
*/
|
|
15
|
-
export declare const callWidgetFactoryWithConfig: <W extends Widget>(
|
|
16
|
-
factory: WidgetFactory<W>;
|
|
14
|
+
export declare const callWidgetFactoryWithConfig: <W extends Widget>(factory: WidgetFactory<W>, options?: {
|
|
17
15
|
defaultConfig?: Partial<WidgetProps<W>> | ReadableSignal<Partial<WidgetProps<W>> | undefined>;
|
|
18
16
|
widgetConfig?: null | undefined | ReadableSignal<Partial<WidgetProps<W>> | undefined>;
|
|
19
17
|
events?: Partial<Pick<WidgetProps<W>, keyof WidgetProps<W> & `on${string}Change`>>;
|
|
20
18
|
props?: Partial<WidgetProps<W>>;
|
|
21
|
-
enablePatchChanged?: true;
|
|
22
19
|
}) => WidgetSlotContext<W>;
|
package/utils/widget.svelte.js
CHANGED
|
@@ -39,18 +39,17 @@ const eventStore = (event, prop) => {
|
|
|
39
39
|
/**
|
|
40
40
|
* Call a widget factory using provided configs.
|
|
41
41
|
*
|
|
42
|
-
* @param
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
46
|
-
* @param
|
|
47
|
-
* @param
|
|
48
|
-
* @
|
|
49
|
-
* @returns the widget
|
|
42
|
+
* @param factory - the widget factory to call
|
|
43
|
+
* @param options - the optional options
|
|
44
|
+
* @param options.defaultConfig - the default config of the widget
|
|
45
|
+
* @param options.widgetConfig - the config of the widget, overriding the defaultConfig
|
|
46
|
+
* @param options.events - the events of the widget
|
|
47
|
+
* @param options.props - the props of the widget
|
|
48
|
+
* @returns the state, api and directives to track and interact with the widget
|
|
50
49
|
*/
|
|
51
|
-
export const callWidgetFactoryWithConfig = (
|
|
52
|
-
const {
|
|
53
|
-
const props =
|
|
50
|
+
export const callWidgetFactoryWithConfig = (factory, options) => {
|
|
51
|
+
const { defaultConfig, widgetConfig, events } = options ?? {};
|
|
52
|
+
const props = options?.props ?? {};
|
|
54
53
|
const defaultConfig$ = toReadableStore(defaultConfig);
|
|
55
54
|
const propsWithEvents = { ...props };
|
|
56
55
|
if (events) {
|
|
@@ -63,12 +62,10 @@ export const callWidgetFactoryWithConfig = (parameter) => {
|
|
|
63
62
|
props: propsWithEvents,
|
|
64
63
|
});
|
|
65
64
|
const runes = Object.fromEntries(Object.entries(widget.stores).map(([key, val]) => [key.slice(0, -1), fromStore(val)]));
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
71
|
-
}
|
|
65
|
+
const patch = createPatchChangedProps(props, widget.patch);
|
|
66
|
+
$effect(() => {
|
|
67
|
+
patch({ ...options?.props });
|
|
68
|
+
});
|
|
72
69
|
return {
|
|
73
70
|
api: widget.api,
|
|
74
71
|
directives: widget.directives,
|