@casinogate/ui 1.9.9 → 1.10.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/dist/assets/css/root.css +6 -0
- package/dist/assets/css/theme.css +1 -1
- package/dist/components/dialog/dialog-host-item.svelte +13 -3
- package/dist/components/dialog/dialog-host.svelte +5 -14
- package/dist/components/dialog/dialog-host.svelte.d.ts +2 -2
- package/dist/components/dialog/index.d.ts +1 -1
- package/dist/components/dialog/model/dialog-manager.svelte.d.ts +10 -4
- package/dist/components/dialog/model/dialog-manager.svelte.js +25 -9
- package/dist/components/dialog/styles.js +1 -1
- package/dist/components/dialog/types.d.ts +31 -17
- package/package.json +1 -1
package/dist/assets/css/root.css
CHANGED
|
@@ -845,6 +845,12 @@
|
|
|
845
845
|
background-color: color-mix(in oklab, var(--cg-ui-palette-neutral-40) 50%, transparent);
|
|
846
846
|
}
|
|
847
847
|
}
|
|
848
|
+
.cgui\:bg-neutral-100\/50 {
|
|
849
|
+
background-color: var(--cg-ui-palette-neutral-100);
|
|
850
|
+
@supports (color: color-mix(in lab, red, red)) {
|
|
851
|
+
background-color: color-mix(in oklab, var(--cg-ui-palette-neutral-100) 50%, transparent);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
848
854
|
.cgui\:bg-primary-80 {
|
|
849
855
|
background-color: var(--cg-ui-palette-primary-80);
|
|
850
856
|
}
|
|
@@ -12,10 +12,20 @@
|
|
|
12
12
|
import Portal from './components/dialog.portal.svelte';
|
|
13
13
|
import Positioner from './components/dialog.positioner.svelte';
|
|
14
14
|
import Root from './components/dialog.root.svelte';
|
|
15
|
-
import type { DialogItemState } from './types.js';
|
|
15
|
+
import type { DialogItemState, InjectedDialogProps } from './types.js';
|
|
16
16
|
|
|
17
17
|
let { component, props: dialogProps, options, open, id, close, update }: DialogItemState = $props();
|
|
18
18
|
|
|
19
|
+
function createCtx(): InjectedDialogProps {
|
|
20
|
+
return {
|
|
21
|
+
id,
|
|
22
|
+
close: (canceled?: boolean) => close(canceled),
|
|
23
|
+
update,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const ctx = $derived(createCtx());
|
|
28
|
+
|
|
19
29
|
const {
|
|
20
30
|
interactOutsideBehavior = 'close',
|
|
21
31
|
escapeKeydownBehavior = 'close',
|
|
@@ -72,7 +82,7 @@
|
|
|
72
82
|
() => open,
|
|
73
83
|
(v) => {
|
|
74
84
|
open = v;
|
|
75
|
-
close();
|
|
85
|
+
close(true);
|
|
76
86
|
}
|
|
77
87
|
}
|
|
78
88
|
>
|
|
@@ -82,7 +92,7 @@
|
|
|
82
92
|
{/if}
|
|
83
93
|
<Positioner {...positionerProps}>
|
|
84
94
|
<Content {...contentProps}>
|
|
85
|
-
<Component {...dialogProps} />
|
|
95
|
+
<Component {ctx} {...dialogProps} />
|
|
86
96
|
</Content>
|
|
87
97
|
</Positioner>
|
|
88
98
|
</Portal>
|
|
@@ -2,26 +2,17 @@
|
|
|
2
2
|
export const createRegister = <TKey extends string, TComponent extends DialogComponent>(
|
|
3
3
|
key: TKey,
|
|
4
4
|
component: TComponent,
|
|
5
|
-
options?: Partial<
|
|
6
|
-
): { [
|
|
5
|
+
options?: Partial<DialogOptions>
|
|
6
|
+
): { [K in TKey]: DialogRegistrationValue<TComponent> } => {
|
|
7
7
|
return {
|
|
8
|
-
[key]: {
|
|
9
|
-
|
|
10
|
-
component,
|
|
11
|
-
options,
|
|
12
|
-
},
|
|
13
|
-
} as { [key in TKey]: DialogRegistrationValue<TKey, TComponent> };
|
|
8
|
+
[key]: { component, options },
|
|
9
|
+
} as { [K in TKey]: DialogRegistrationValue<TComponent> };
|
|
14
10
|
};
|
|
15
11
|
</script>
|
|
16
12
|
|
|
17
13
|
<script lang="ts">
|
|
18
14
|
import HostItem from './dialog-host-item.svelte';
|
|
19
|
-
import type {
|
|
20
|
-
DialogComponent,
|
|
21
|
-
DialogHostProps,
|
|
22
|
-
DialogRegistrationOptions,
|
|
23
|
-
DialogRegistrationValue,
|
|
24
|
-
} from './types.js';
|
|
15
|
+
import type { DialogComponent, DialogHostProps, DialogOptions, DialogRegistrationValue } from './types.js';
|
|
25
16
|
|
|
26
17
|
import { boxWith } from 'svelte-toolbelt';
|
|
27
18
|
import { DialogManagerState } from './model/dialog-manager.svelte.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare const createRegister: <TKey extends string, TComponent extends DialogComponent>(key: TKey, component: TComponent, options?: Partial<
|
|
2
|
-
import type { DialogComponent, DialogHostProps,
|
|
1
|
+
export declare const createRegister: <TKey extends string, TComponent extends DialogComponent>(key: TKey, component: TComponent, options?: Partial<DialogOptions>) => { [K in TKey]: DialogRegistrationValue<TComponent>; };
|
|
2
|
+
import type { DialogComponent, DialogHostProps, DialogOptions, DialogRegistrationValue } from './types.js';
|
|
3
3
|
declare const DialogHost: import("svelte").Component<DialogHostProps, {}, "">;
|
|
4
4
|
type DialogHost = ReturnType<typeof DialogHost>;
|
|
5
5
|
export default DialogHost;
|
|
@@ -2,4 +2,4 @@ export * as DialogPrimitive from './exports-primitive.js';
|
|
|
2
2
|
export * as Dialog from './exports.js';
|
|
3
3
|
export { useDialogItemContext } from './dialog-host-item.svelte';
|
|
4
4
|
export { dialogs } from './model/index.js';
|
|
5
|
-
export type { DialogCloseProps, DialogContentProps, DialogOptions, DialogOverlayProps, DialogPortalProps, DialogPositionerProps, DialogRootProps, ExtractRegisterdDialogs, RegisteredDialogCollection, RegisteredDialogKeys, RegisteredDialogsOverride, WithDialogProps, } from './types.js';
|
|
5
|
+
export type { DialogCloseProps, DialogContentProps, DialogCustomProps, DialogHandle, DialogOptions, DialogOverlayProps, DialogPortalProps, DialogPositionerProps, DialogRootProps, DialogRegistrationValue, ExtractRegisterdDialogs, InjectedDialogProps, RegisteredDialogCollection, RegisteredDialogKeys, RegisteredDialogsOverride, WithDialogProps, } from './types.js';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Context } from 'runed';
|
|
2
|
-
import { type ComponentProps } from 'svelte';
|
|
3
2
|
import { type ReadableBoxedValues } from 'svelte-toolbelt';
|
|
4
|
-
import type { CloseDialogCommandPayload, DialogComponent, DialogItemState, DialogRegistrationValue, OpenDialogCommandPayload, OpenRegisteredDialogCommandPayload,
|
|
3
|
+
import type { CloseDialogCommandPayload, DialogComponent, DialogHandle, DialogItemState, DialogOptions, DialogRegistrationValue, OpenDialogCommandPayload, OpenRegisteredDialogCommandPayload, RegisteredDialogKeys } from '../types.js';
|
|
5
4
|
export declare const DialogManagerContext: Context<DialogManagerState>;
|
|
6
5
|
type DialogManagerOpts = ReadableBoxedValues<{
|
|
7
6
|
register: Record<string, DialogRegistrationValue>;
|
|
@@ -15,14 +14,21 @@ export declare class DialogManagerState {
|
|
|
15
14
|
get dialogs(): DialogItemState[];
|
|
16
15
|
set dialogs(value: DialogItemState[]);
|
|
17
16
|
}
|
|
18
|
-
declare function openRegistered<TKey extends RegisteredDialogKeys
|
|
19
|
-
declare function open<TComponent extends DialogComponent>(payload: OpenDialogCommandPayload<TComponent>):
|
|
17
|
+
declare function openRegistered<TKey extends RegisteredDialogKeys>(key: TKey, payload: OpenRegisteredDialogCommandPayload<TKey>): DialogHandle;
|
|
18
|
+
declare function open<TComponent extends DialogComponent>(payload: OpenDialogCommandPayload<TComponent>): DialogHandle;
|
|
20
19
|
declare function close(payload: CloseDialogCommandPayload): void;
|
|
21
20
|
declare function closeAll(): void;
|
|
21
|
+
declare function update(payload: {
|
|
22
|
+
id: string;
|
|
23
|
+
}, fn: (currentProps: Record<string, unknown>, currentOptions: Partial<DialogOptions>) => {
|
|
24
|
+
props: Record<string, unknown>;
|
|
25
|
+
options: Partial<DialogOptions>;
|
|
26
|
+
}): void;
|
|
22
27
|
export declare const dialogs: {
|
|
23
28
|
openRegistered: typeof openRegistered;
|
|
24
29
|
open: typeof open;
|
|
25
30
|
close: typeof close;
|
|
26
31
|
closeAll: typeof closeAll;
|
|
32
|
+
update: typeof update;
|
|
27
33
|
};
|
|
28
34
|
export {};
|
|
@@ -27,6 +27,7 @@ export class DialogManagerState {
|
|
|
27
27
|
'dialog:open': (event) => this.#handleOpen(event.detail),
|
|
28
28
|
'dialog:close': (event) => this.#handleClose(event.detail),
|
|
29
29
|
'dialog:closeAll': () => this.#handleCloseAll(),
|
|
30
|
+
'dialog:update': (event) => this.#updateDialog(event.detail.id, event.detail.fn),
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
#updateDialog(id, fn) {
|
|
@@ -56,7 +57,7 @@ export class DialogManagerState {
|
|
|
56
57
|
component: component,
|
|
57
58
|
props: componentProps,
|
|
58
59
|
id,
|
|
59
|
-
close: () => close({ id }),
|
|
60
|
+
close: (canceled) => close({ id, canceled }),
|
|
60
61
|
update: (fn) => {
|
|
61
62
|
this.#updateDialog(id, fn);
|
|
62
63
|
},
|
|
@@ -76,7 +77,7 @@ export class DialogManagerState {
|
|
|
76
77
|
component: component,
|
|
77
78
|
props: componentProps,
|
|
78
79
|
id,
|
|
79
|
-
close: () => close({ id }),
|
|
80
|
+
close: (canceled) => close({ id, canceled }),
|
|
80
81
|
update: (fn) => {
|
|
81
82
|
this.#updateDialog(id, fn);
|
|
82
83
|
},
|
|
@@ -86,7 +87,9 @@ export class DialogManagerState {
|
|
|
86
87
|
this.dialogs = [...this.dialogs.map((d) => ({ ...d, open: false })), state];
|
|
87
88
|
}
|
|
88
89
|
#handleClose(payload) {
|
|
89
|
-
const { id } = payload;
|
|
90
|
+
const { id, canceled = true } = payload;
|
|
91
|
+
// Find the dialog to get its onClose callback
|
|
92
|
+
const closingDialog = this.#dialogs.find((d) => d.id === id);
|
|
90
93
|
for (let i = this.#dialogs.length - 1; i >= 0; i--) {
|
|
91
94
|
const dialog = this.#dialogs[i];
|
|
92
95
|
if (!dialog)
|
|
@@ -100,6 +103,8 @@ export class DialogManagerState {
|
|
|
100
103
|
break;
|
|
101
104
|
}
|
|
102
105
|
}
|
|
106
|
+
// Call onClose callback with canceled flag
|
|
107
|
+
closingDialog?.options.onClose?.(canceled);
|
|
103
108
|
setTimeout(() => {
|
|
104
109
|
this.dialogs = this.dialogs.filter((d) => d.id !== id);
|
|
105
110
|
}, 150);
|
|
@@ -117,8 +122,15 @@ export class DialogManagerState {
|
|
|
117
122
|
this.#dialogs = value;
|
|
118
123
|
}
|
|
119
124
|
}
|
|
120
|
-
function
|
|
121
|
-
|
|
125
|
+
function createHandle(id) {
|
|
126
|
+
return {
|
|
127
|
+
id,
|
|
128
|
+
close: (canceled) => close({ id, canceled }),
|
|
129
|
+
update: (fn) => update({ id }, fn),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function openRegistered(key, payload) {
|
|
133
|
+
const { props, options } = payload;
|
|
122
134
|
const id = useId();
|
|
123
135
|
Dispatcher.dispatch('dialog:openRegistered', {
|
|
124
136
|
key,
|
|
@@ -126,7 +138,7 @@ function openRegistered(payload) {
|
|
|
126
138
|
id,
|
|
127
139
|
options,
|
|
128
140
|
});
|
|
129
|
-
return id;
|
|
141
|
+
return createHandle(id);
|
|
130
142
|
}
|
|
131
143
|
function open(payload) {
|
|
132
144
|
const { component, props, options } = payload;
|
|
@@ -137,18 +149,22 @@ function open(payload) {
|
|
|
137
149
|
options,
|
|
138
150
|
id,
|
|
139
151
|
});
|
|
140
|
-
return id;
|
|
152
|
+
return createHandle(id);
|
|
141
153
|
}
|
|
142
154
|
function close(payload) {
|
|
143
|
-
const { id } = payload;
|
|
144
|
-
Dispatcher.dispatch('dialog:close', { id });
|
|
155
|
+
const { id, canceled } = payload;
|
|
156
|
+
Dispatcher.dispatch('dialog:close', { id, canceled });
|
|
145
157
|
}
|
|
146
158
|
function closeAll() {
|
|
147
159
|
Dispatcher.dispatch('dialog:closeAll');
|
|
148
160
|
}
|
|
161
|
+
function update(payload, fn) {
|
|
162
|
+
Dispatcher.dispatch('dialog:update', { id: payload.id, fn });
|
|
163
|
+
}
|
|
149
164
|
export const dialogs = {
|
|
150
165
|
openRegistered,
|
|
151
166
|
open,
|
|
152
167
|
close,
|
|
153
168
|
closeAll,
|
|
169
|
+
update,
|
|
154
170
|
};
|
|
@@ -17,7 +17,7 @@ export const dialogOverlayStyles = tv({
|
|
|
17
17
|
base: [
|
|
18
18
|
'cgui:pointer-events-none cgui:fixed cgui:top-0 cgui:left-0 cgui:z-(--z-index-dialog) cgui:overflow-hidden',
|
|
19
19
|
'cgui:size-full',
|
|
20
|
-
'cgui:bg-
|
|
20
|
+
'cgui:bg-neutral-100/50',
|
|
21
21
|
'cgui:data-[state=open]:animate-in cgui:data-[state=closed]:animate-out cgui:data-[state=closed]:fade-out-0 cgui:data-[state=open]:fade-in-0',
|
|
22
22
|
],
|
|
23
23
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Fn } from '../../internal/types/common.js';
|
|
2
1
|
import type { PrimitiveDivAttributes } from '../../internal/types/html-attributes.js';
|
|
3
2
|
import type { DialogCloseProps as DialogClosePropsPrimitive, DialogContentProps as DialogContentPropsPrimitive, DialogOverlayProps as DialogOverlayPropsPrimitive, DialogPortalProps as DialogPortalPropsPrimitive, DialogRootProps as DialogRootPropsPrimitive } from 'bits-ui';
|
|
4
3
|
import type { Component, ComponentProps } from 'svelte';
|
|
@@ -18,19 +17,16 @@ export type DialogComponent = Component<any>;
|
|
|
18
17
|
export interface RegisteredDialogsOverride {
|
|
19
18
|
}
|
|
20
19
|
export type RegisteredDialogCollectionOverwritten = keyof RegisteredDialogsOverride extends never ? {
|
|
21
|
-
dialogs: Record<string,
|
|
20
|
+
dialogs: Record<string, DialogRegistrationValue>;
|
|
22
21
|
} : RegisteredDialogsOverride;
|
|
23
22
|
export type RegisteredDialogCollection = RegisteredDialogCollectionOverwritten['dialogs'];
|
|
24
23
|
export type RegisteredDialogKeys = keyof RegisteredDialogCollectionOverwritten['dialogs'];
|
|
25
|
-
export type DialogRegistrationValue<
|
|
26
|
-
key: TKey;
|
|
24
|
+
export type DialogRegistrationValue<TComponent extends DialogComponent = DialogComponent> = {
|
|
27
25
|
component: TComponent;
|
|
28
|
-
options?: Partial<
|
|
29
|
-
};
|
|
30
|
-
export type DialogRegistrationOptions = {
|
|
31
|
-
escapeKeydownBehavior?: DialogContentProps['escapeKeydownBehavior'];
|
|
32
|
-
interactOutsideBehavior?: DialogContentProps['interactOutsideBehavior'];
|
|
26
|
+
options?: Partial<DialogOptions>;
|
|
33
27
|
};
|
|
28
|
+
/** Extract custom props from a dialog component (omit injected ctx) */
|
|
29
|
+
export type DialogCustomProps<T extends Component<any>> = Omit<ComponentProps<T>, 'ctx'>;
|
|
34
30
|
export type DialogOptions = Omit<DialogRootProps, 'open' | 'onOpenChangeComplete' | 'children'> & {
|
|
35
31
|
withOverlay?: boolean;
|
|
36
32
|
escapeKeydownBehavior?: Extract<DialogContentProps['escapeKeydownBehavior'], 'close' | 'ignore'>;
|
|
@@ -41,6 +37,8 @@ export type DialogOptions = Omit<DialogRootProps, 'open' | 'onOpenChangeComplete
|
|
|
41
37
|
contentProps?: Partial<Omit<DialogContentProps, 'id' | 'class' | 'children' | 'ref' | 'child'>>;
|
|
42
38
|
positionerProps?: Partial<Omit<DialogPositionerProps, 'id' | 'class' | 'children' | 'ref' | 'child'>>;
|
|
43
39
|
overlayProps?: Partial<Omit<DialogOverlayProps, 'id' | 'class' | 'children' | 'ref' | 'child'>>;
|
|
40
|
+
/** Called when dialog closes. `canceled: true` means user dismissed (escape, click outside, cancel button) */
|
|
41
|
+
onClose?: (canceled: boolean) => void;
|
|
44
42
|
};
|
|
45
43
|
export type DialogItemState = {
|
|
46
44
|
id: string;
|
|
@@ -52,29 +50,45 @@ export type DialogItemState = {
|
|
|
52
50
|
props: Record<string, unknown>;
|
|
53
51
|
options: Partial<DialogOptions>;
|
|
54
52
|
}) => void;
|
|
55
|
-
close:
|
|
53
|
+
close: (canceled?: boolean) => void;
|
|
56
54
|
};
|
|
57
|
-
export type OpenRegisteredDialogPayload<TKey extends RegisteredDialogKeys = RegisteredDialogKeys
|
|
55
|
+
export type OpenRegisteredDialogPayload<TKey extends RegisteredDialogKeys = RegisteredDialogKeys> = {
|
|
58
56
|
key: TKey;
|
|
59
|
-
props:
|
|
57
|
+
props: DialogCustomProps<RegisteredDialogCollection[TKey]['component']>;
|
|
60
58
|
options?: Partial<DialogOptions>;
|
|
61
59
|
};
|
|
62
|
-
export type OpenRegisteredDialogCommandPayload<TKey extends RegisteredDialogKeys = RegisteredDialogKeys
|
|
63
|
-
|
|
64
|
-
props: Omit<TProps, 'id'>;
|
|
60
|
+
export type OpenRegisteredDialogCommandPayload<TKey extends RegisteredDialogKeys = RegisteredDialogKeys> = {
|
|
61
|
+
props: DialogCustomProps<RegisteredDialogCollection[TKey]['component']>;
|
|
65
62
|
options?: Partial<DialogOptions>;
|
|
66
63
|
};
|
|
67
64
|
export type OpenDialogCommandPayload<TComponent extends DialogComponent = DialogComponent> = {
|
|
68
65
|
component: TComponent;
|
|
69
|
-
props:
|
|
66
|
+
props: DialogCustomProps<TComponent>;
|
|
70
67
|
options?: Partial<DialogOptions>;
|
|
71
68
|
};
|
|
72
69
|
export type CloseDialogCommandPayload = {
|
|
73
70
|
id: string;
|
|
71
|
+
canceled?: boolean;
|
|
74
72
|
};
|
|
75
|
-
export type
|
|
73
|
+
export type InjectedDialogProps = {
|
|
76
74
|
id: string;
|
|
75
|
+
close: (canceled?: boolean) => void;
|
|
76
|
+
update: (fn: (currentProps: Record<string, unknown>, currentOptions: Partial<DialogOptions>) => {
|
|
77
|
+
props: Record<string, unknown>;
|
|
78
|
+
options: Partial<DialogOptions>;
|
|
79
|
+
}) => void;
|
|
80
|
+
};
|
|
81
|
+
export type WithDialogProps<T extends Record<string, unknown>> = {
|
|
82
|
+
ctx: InjectedDialogProps;
|
|
77
83
|
} & T;
|
|
84
|
+
export type DialogHandle = {
|
|
85
|
+
id: string;
|
|
86
|
+
close: (canceled?: boolean) => void;
|
|
87
|
+
update: (fn: (currentProps: Record<string, unknown>, currentOptions: Partial<DialogOptions>) => {
|
|
88
|
+
props: Record<string, unknown>;
|
|
89
|
+
options: Partial<DialogOptions>;
|
|
90
|
+
}) => void;
|
|
91
|
+
};
|
|
78
92
|
export type ExtractRegisterdDialogs<TData extends Record<string, DialogRegistrationValue>> = {
|
|
79
93
|
[TKey in keyof TData]: TData[TKey]['component'];
|
|
80
94
|
};
|