@casinogate/ui 1.5.6 → 1.6.1
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 +52 -0
- package/dist/assets/css/theme.css +2 -0
- package/dist/components/breadcrumb/breadcrumb.stories.svelte +0 -2
- package/dist/components/data-table/utils/render-helper.d.ts +0 -77
- package/dist/components/data-table/utils/render-helper.js +0 -77
- package/dist/components/dialog/_ui/basic-dialog/basic-dialog.svelte +89 -0
- package/dist/components/dialog/_ui/basic-dialog/basic-dialog.svelte.d.ts +6 -0
- package/dist/components/dialog/_ui/basic-dialog/index.d.ts +1 -0
- package/dist/components/dialog/_ui/basic-dialog/index.js +1 -0
- package/dist/components/dialog/_ui/nested-dialog/index.d.ts +1 -0
- package/dist/components/dialog/_ui/nested-dialog/index.js +1 -0
- package/dist/components/dialog/_ui/nested-dialog/nested-dialog.svelte +26 -0
- package/dist/components/dialog/_ui/nested-dialog/nested-dialog.svelte.d.ts +18 -0
- package/dist/components/dialog/components/dialog.close.svelte +17 -0
- package/dist/components/dialog/components/dialog.close.svelte.d.ts +4 -0
- package/dist/components/dialog/components/dialog.content.svelte +36 -0
- package/dist/components/dialog/components/dialog.content.svelte.d.ts +4 -0
- package/dist/components/dialog/components/dialog.overlay.svelte +32 -0
- package/dist/components/dialog/components/dialog.overlay.svelte.d.ts +4 -0
- package/dist/components/dialog/components/dialog.portal.svelte +10 -0
- package/dist/components/dialog/components/dialog.portal.svelte.d.ts +3 -0
- package/dist/components/dialog/components/dialog.positioner.svelte +34 -0
- package/dist/components/dialog/components/dialog.positioner.svelte.d.ts +4 -0
- package/dist/components/dialog/components/dialog.root.svelte +21 -0
- package/dist/components/dialog/components/dialog.root.svelte.d.ts +3 -0
- package/dist/components/dialog/components/dialog.svelte.d.ts +46 -0
- package/dist/components/dialog/components/dialog.svelte.js +72 -0
- package/dist/components/dialog/dialog-host-item.svelte +61 -0
- package/dist/components/dialog/dialog-host-item.svelte.d.ts +5 -0
- package/dist/components/dialog/dialog-host.svelte +38 -0
- package/dist/components/dialog/dialog-host.svelte.d.ts +5 -0
- package/dist/components/dialog/dialog.stories.svelte +102 -0
- package/dist/components/dialog/dialog.stories.svelte.d.ts +3 -0
- package/dist/components/dialog/exports-primitive.d.ts +6 -0
- package/dist/components/dialog/exports-primitive.js +6 -0
- package/dist/components/dialog/exports.d.ts +1 -0
- package/dist/components/dialog/exports.js +1 -0
- package/dist/components/dialog/index.d.ts +5 -0
- package/dist/components/dialog/index.js +4 -0
- package/dist/components/dialog/model/dialog-manager.svelte.d.ts +28 -0
- package/dist/components/dialog/model/dialog-manager.svelte.js +156 -0
- package/dist/components/dialog/model/index.d.ts +1 -0
- package/dist/components/dialog/model/index.js +1 -0
- package/dist/components/dialog/styles.d.ts +60 -0
- package/dist/components/dialog/styles.js +54 -0
- package/dist/components/dialog/types.d.ts +76 -0
- package/dist/components/dialog/types.js +1 -0
- package/dist/components/icons/cross.svelte +12 -0
- package/dist/components/icons/cross.svelte.d.ts +3 -0
- package/dist/components/icons/exports.d.ts +1 -0
- package/dist/components/icons/exports.js +1 -0
- package/dist/components/icons/sort.svelte +1 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/components/input-group/components/input-group.root.svelte +0 -0
- package/dist/components/input-group/components/input-group.root.svelte.d.ts +26 -0
- package/dist/components/input-group/exports-primitive.d.ts +1 -0
- package/dist/components/input-group/exports-primitive.js +1 -0
- package/dist/components/input-group/index.d.ts +1 -0
- package/dist/components/input-group/index.js +1 -0
- package/dist/components/input-group/styles.d.ts +1 -0
- package/dist/components/input-group/styles.js +1 -0
- package/dist/components/input-group/types.d.ts +1 -0
- package/dist/components/input-group/types.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +1 -0
- package/dist/internal/types/common.d.ts +1 -1
- package/dist/internal/utils/attrs.d.ts +1 -0
- package/dist/internal/utils/attrs.js +3 -0
- package/dist/internal/utils/event-dispatcher.d.ts +12 -0
- package/dist/internal/utils/event-dispatcher.js +50 -0
- package/dist/internal/utils/index.d.ts +2 -0
- package/dist/internal/utils/index.js +2 -0
- package/dist/internal/utils/render.d.ts +13 -0
- package/dist/internal/utils/render.js +22 -0
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Dialog as DialogPrimitive } from 'bits-ui';
|
|
3
|
+
import { boxWith } from 'svelte-toolbelt';
|
|
4
|
+
import type { DialogRootProps } from '../types.js';
|
|
5
|
+
import { DialogRootState } from './dialog.svelte.js';
|
|
6
|
+
|
|
7
|
+
let { open = $bindable(false), children, ...restProps }: DialogRootProps = $props();
|
|
8
|
+
|
|
9
|
+
const rootState = DialogRootState.create({
|
|
10
|
+
open: boxWith(
|
|
11
|
+
() => open,
|
|
12
|
+
(v) => {
|
|
13
|
+
open = v;
|
|
14
|
+
}
|
|
15
|
+
),
|
|
16
|
+
});
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<DialogPrimitive.Root bind:open={rootState.opts.open.current} {...restProps}>
|
|
20
|
+
{@render children?.()}
|
|
21
|
+
</DialogPrimitive.Root>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { RefAttachment } from '../../../internal/types/common.js';
|
|
2
|
+
import { type WithRefProps, type WritableBoxedValues } from 'svelte-toolbelt';
|
|
3
|
+
type DialogRootStateOpts = WritableBoxedValues<{
|
|
4
|
+
open: boolean;
|
|
5
|
+
}>;
|
|
6
|
+
export declare class DialogRootState {
|
|
7
|
+
static create(opts: DialogRootStateOpts): DialogRootState;
|
|
8
|
+
readonly opts: DialogRootStateOpts;
|
|
9
|
+
constructor(opts: DialogRootStateOpts);
|
|
10
|
+
}
|
|
11
|
+
type DialogContentStateOpts = WithRefProps<{}>;
|
|
12
|
+
export declare class DialogContentState {
|
|
13
|
+
static create(opts: DialogContentStateOpts): DialogContentState;
|
|
14
|
+
readonly opts: DialogContentStateOpts;
|
|
15
|
+
readonly attachment: RefAttachment;
|
|
16
|
+
constructor(opts: DialogContentStateOpts);
|
|
17
|
+
readonly props: {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly "data-slot": "content";
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
type DialogOverlayStateOpts = WithRefProps<{}>;
|
|
23
|
+
export declare class DialogOverlayState {
|
|
24
|
+
static create(opts: DialogOverlayStateOpts): DialogOverlayState;
|
|
25
|
+
readonly opts: DialogOverlayStateOpts;
|
|
26
|
+
readonly attachment: RefAttachment;
|
|
27
|
+
constructor(opts: DialogOverlayStateOpts);
|
|
28
|
+
readonly props: {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly "data-slot": "overlay";
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
type DialogPositionerStateOpts = WithRefProps<{}>;
|
|
34
|
+
export declare class DialogPositionerState {
|
|
35
|
+
static create(opts: DialogPositionerStateOpts): DialogPositionerState;
|
|
36
|
+
readonly opts: DialogPositionerStateOpts;
|
|
37
|
+
readonly attachment: RefAttachment;
|
|
38
|
+
readonly root: DialogRootState;
|
|
39
|
+
constructor(opts: DialogPositionerStateOpts, root: DialogRootState);
|
|
40
|
+
readonly props: {
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly "data-slot": "positioner";
|
|
43
|
+
readonly 'data-state': string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { SLOT_ATTR_NAME } from '../../../internal/constants/attrs.js';
|
|
2
|
+
import { getDataOpenState } from '../../../internal/utils/attrs.js';
|
|
3
|
+
import { keyWithPrefix } from '../../../internal/utils/common.js';
|
|
4
|
+
import { Context } from 'runed';
|
|
5
|
+
import { attachRef } from 'svelte-toolbelt';
|
|
6
|
+
const DialogRootContext = new Context(keyWithPrefix('dialog-root'));
|
|
7
|
+
const SLOT_ATTR_VALUES = {
|
|
8
|
+
content: 'content',
|
|
9
|
+
overlay: 'overlay',
|
|
10
|
+
positioner: 'positioner',
|
|
11
|
+
close: 'close',
|
|
12
|
+
};
|
|
13
|
+
export class DialogRootState {
|
|
14
|
+
static create(opts) {
|
|
15
|
+
return DialogRootContext.set(new DialogRootState(opts));
|
|
16
|
+
}
|
|
17
|
+
opts;
|
|
18
|
+
constructor(opts) {
|
|
19
|
+
this.opts = opts;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class DialogContentState {
|
|
23
|
+
static create(opts) {
|
|
24
|
+
return new DialogContentState(opts);
|
|
25
|
+
}
|
|
26
|
+
opts;
|
|
27
|
+
attachment;
|
|
28
|
+
constructor(opts) {
|
|
29
|
+
this.opts = opts;
|
|
30
|
+
this.attachment = attachRef(opts.ref);
|
|
31
|
+
}
|
|
32
|
+
props = $derived.by(() => ({
|
|
33
|
+
id: this.opts.id.current,
|
|
34
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.content,
|
|
35
|
+
...this.attachment,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
export class DialogOverlayState {
|
|
39
|
+
static create(opts) {
|
|
40
|
+
return new DialogOverlayState(opts);
|
|
41
|
+
}
|
|
42
|
+
opts;
|
|
43
|
+
attachment;
|
|
44
|
+
constructor(opts) {
|
|
45
|
+
this.opts = opts;
|
|
46
|
+
this.attachment = attachRef(opts.ref);
|
|
47
|
+
}
|
|
48
|
+
props = $derived.by(() => ({
|
|
49
|
+
id: this.opts.id.current,
|
|
50
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.overlay,
|
|
51
|
+
...this.attachment,
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
export class DialogPositionerState {
|
|
55
|
+
static create(opts) {
|
|
56
|
+
return new DialogPositionerState(opts, DialogRootContext.get());
|
|
57
|
+
}
|
|
58
|
+
opts;
|
|
59
|
+
attachment;
|
|
60
|
+
root;
|
|
61
|
+
constructor(opts, root) {
|
|
62
|
+
this.opts = opts;
|
|
63
|
+
this.attachment = attachRef(opts.ref);
|
|
64
|
+
this.root = root;
|
|
65
|
+
}
|
|
66
|
+
props = $derived.by(() => ({
|
|
67
|
+
id: this.opts.id.current,
|
|
68
|
+
[SLOT_ATTR_NAME]: SLOT_ATTR_VALUES.positioner,
|
|
69
|
+
'data-state': getDataOpenState(this.root.opts.open.current),
|
|
70
|
+
...this.attachment,
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { Context, watch } from 'runed';
|
|
3
|
+
|
|
4
|
+
const DialogItemContext = new Context<Omit<DialogItemState, 'component'>>('dialog-item');
|
|
5
|
+
|
|
6
|
+
export const useDialogItemContext = () => DialogItemContext.get();
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import Content from './components/dialog.content.svelte';
|
|
11
|
+
import Overlay from './components/dialog.overlay.svelte';
|
|
12
|
+
import Portal from './components/dialog.portal.svelte';
|
|
13
|
+
import Positioner from './components/dialog.positioner.svelte';
|
|
14
|
+
import Root from './components/dialog.root.svelte';
|
|
15
|
+
import type { DialogItemState } from './types.js';
|
|
16
|
+
|
|
17
|
+
let { component, props: dialogProps, options, open, id, close, update }: DialogItemState = $props();
|
|
18
|
+
|
|
19
|
+
const { interactOutsideBehavior = 'close', escapeKeydownBehavior = 'close', onOpenChange, ...restOptions } = options;
|
|
20
|
+
const Component = $derived(component);
|
|
21
|
+
const contentProps = $derived({
|
|
22
|
+
interactOutsideBehavior,
|
|
23
|
+
escapeKeydownBehavior,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
DialogItemContext.set({
|
|
27
|
+
props: dialogProps,
|
|
28
|
+
options,
|
|
29
|
+
open,
|
|
30
|
+
id,
|
|
31
|
+
update,
|
|
32
|
+
close,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
watch(
|
|
36
|
+
() => open,
|
|
37
|
+
() => {
|
|
38
|
+
onOpenChange?.(open);
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<Root
|
|
44
|
+
{...restOptions}
|
|
45
|
+
bind:open={
|
|
46
|
+
() => open,
|
|
47
|
+
(v) => {
|
|
48
|
+
open = v;
|
|
49
|
+
close();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
>
|
|
53
|
+
<Portal>
|
|
54
|
+
<Overlay />
|
|
55
|
+
<Positioner>
|
|
56
|
+
<Content {...contentProps}>
|
|
57
|
+
<Component {...dialogProps} />
|
|
58
|
+
</Content>
|
|
59
|
+
</Positioner>
|
|
60
|
+
</Portal>
|
|
61
|
+
</Root>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const useDialogItemContext: () => Omit<DialogItemState, "component">;
|
|
2
|
+
import type { DialogItemState } from './types.js';
|
|
3
|
+
declare const DialogHostItem: import("svelte").Component<DialogItemState, {}, "">;
|
|
4
|
+
type DialogHostItem = ReturnType<typeof DialogHostItem>;
|
|
5
|
+
export default DialogHostItem;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
export const createRegister = <TKey extends string, TComponent extends DialogComponent>(
|
|
3
|
+
key: TKey,
|
|
4
|
+
component: TComponent,
|
|
5
|
+
options?: Partial<DialogRegistrationOptions>
|
|
6
|
+
): { [key in TKey]: DialogRegistrationValue<TKey, TComponent> } => {
|
|
7
|
+
return {
|
|
8
|
+
[key]: {
|
|
9
|
+
key: key,
|
|
10
|
+
component,
|
|
11
|
+
options,
|
|
12
|
+
},
|
|
13
|
+
} as { [key in TKey]: DialogRegistrationValue<TKey, TComponent> };
|
|
14
|
+
};
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
import HostItem from './dialog-host-item.svelte';
|
|
19
|
+
import type {
|
|
20
|
+
DialogComponent,
|
|
21
|
+
DialogHostProps,
|
|
22
|
+
DialogRegistrationOptions,
|
|
23
|
+
DialogRegistrationValue,
|
|
24
|
+
} from './types.js';
|
|
25
|
+
|
|
26
|
+
import { boxWith } from 'svelte-toolbelt';
|
|
27
|
+
import { DialogManagerState } from './model/dialog-manager.svelte.js';
|
|
28
|
+
|
|
29
|
+
let { register = {} }: DialogHostProps = $props();
|
|
30
|
+
|
|
31
|
+
const managerState = DialogManagerState.create({
|
|
32
|
+
register: boxWith(() => register),
|
|
33
|
+
});
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
{#each managerState.dialogs as dialog (dialog.id)}
|
|
37
|
+
<HostItem {...dialog} />
|
|
38
|
+
{/each}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const createRegister: <TKey extends string, TComponent extends DialogComponent>(key: TKey, component: TComponent, options?: Partial<DialogRegistrationOptions>) => { [key in TKey]: DialogRegistrationValue<TKey, TComponent>; };
|
|
2
|
+
import type { DialogComponent, DialogHostProps, DialogRegistrationOptions, DialogRegistrationValue } from './types.js';
|
|
3
|
+
declare const DialogHost: import("svelte").Component<DialogHostProps, {}, "">;
|
|
4
|
+
type DialogHost = ReturnType<typeof DialogHost>;
|
|
5
|
+
export default DialogHost;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { Button } from '../button/index.js';
|
|
3
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
4
|
+
import type { Parameters } from '@storybook/sveltekit';
|
|
5
|
+
import type { ComponentProps } from 'svelte';
|
|
6
|
+
import { BasicDialog } from './_ui/basic-dialog/index.js';
|
|
7
|
+
import { NestedDialog } from './_ui/nested-dialog/index.js';
|
|
8
|
+
import DialogRoot from './components/dialog.root.svelte';
|
|
9
|
+
import DialogHost, { createRegister } from './dialog-host.svelte';
|
|
10
|
+
import { DialogPrimitive } from './index.js';
|
|
11
|
+
import { dialogs } from './model/dialog-manager.svelte.js';
|
|
12
|
+
|
|
13
|
+
const register = {
|
|
14
|
+
...createRegister('basic', BasicDialog),
|
|
15
|
+
...createRegister('nested', NestedDialog),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const parameters: Parameters = {
|
|
19
|
+
controls: {
|
|
20
|
+
include: ['open'],
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
docs: {
|
|
24
|
+
story: {
|
|
25
|
+
inline: false,
|
|
26
|
+
iframeHeight: 500,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const { Story } = defineMeta({
|
|
32
|
+
title: 'UI Kit/Dialog',
|
|
33
|
+
component: DialogRoot,
|
|
34
|
+
// subcomponents: {
|
|
35
|
+
// 'dialog-host': DialogHost,
|
|
36
|
+
// },
|
|
37
|
+
tags: ['autodocs'],
|
|
38
|
+
parameters,
|
|
39
|
+
// argTypes: {
|
|
40
|
+
// open: {
|
|
41
|
+
// table: {
|
|
42
|
+
// defaultValue: { summary: 'false', detail: '$bindable(false)' },
|
|
43
|
+
// },
|
|
44
|
+
// },
|
|
45
|
+
// },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
type Args = ComponentProps<typeof DialogRoot>;
|
|
49
|
+
|
|
50
|
+
const args: Args = {
|
|
51
|
+
open: true,
|
|
52
|
+
};
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<script lang="ts">
|
|
56
|
+
let basicOpen = $state(false);
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<DialogHost {register} />
|
|
60
|
+
|
|
61
|
+
<Story name="Basic" {args} {parameters}>
|
|
62
|
+
{#snippet template(args: Args)}
|
|
63
|
+
<div class="cgui:bg-bg-primary cgui:h-full cgui:w-full">
|
|
64
|
+
<Button onclick={() => (basicOpen = !basicOpen)}>Toggle</Button>
|
|
65
|
+
|
|
66
|
+
<DialogRoot {...args} bind:open={basicOpen}>
|
|
67
|
+
<DialogPrimitive.Portal>
|
|
68
|
+
<DialogPrimitive.Overlay />
|
|
69
|
+
|
|
70
|
+
<DialogPrimitive.Positioner>
|
|
71
|
+
<DialogPrimitive.Content class="cgui:bg-surface-white cgui:size-40">
|
|
72
|
+
<DialogPrimitive.Close />
|
|
73
|
+
|
|
74
|
+
Content
|
|
75
|
+
</DialogPrimitive.Content>
|
|
76
|
+
</DialogPrimitive.Positioner>
|
|
77
|
+
</DialogPrimitive.Portal>
|
|
78
|
+
</DialogRoot>
|
|
79
|
+
</div>
|
|
80
|
+
{/snippet}
|
|
81
|
+
</Story>
|
|
82
|
+
|
|
83
|
+
<Story name="Registered">
|
|
84
|
+
{#snippet template()}
|
|
85
|
+
<div class="cgui:bg-bg-primary cgui:h-full cgui:w-full cgui:flex cgui:items-center cgui:justify-center cgui:gap-4">
|
|
86
|
+
<Button
|
|
87
|
+
onclick={() =>
|
|
88
|
+
dialogs.openRegistered({
|
|
89
|
+
key: 'basic',
|
|
90
|
+
props: {
|
|
91
|
+
name: 'John Doe',
|
|
92
|
+
},
|
|
93
|
+
options: {
|
|
94
|
+
onOpenChange: (open) => {
|
|
95
|
+
console.log('OPEN CHANGE', open);
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
})}>Open</Button
|
|
99
|
+
>
|
|
100
|
+
</div>
|
|
101
|
+
{/snippet}
|
|
102
|
+
</Story>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as Close } from './components/dialog.close.svelte';
|
|
2
|
+
export { default as Content } from './components/dialog.content.svelte';
|
|
3
|
+
export { default as Overlay } from './components/dialog.overlay.svelte';
|
|
4
|
+
export { default as Portal } from './components/dialog.portal.svelte';
|
|
5
|
+
export { default as Positioner } from './components/dialog.positioner.svelte';
|
|
6
|
+
export { default as Root } from './components/dialog.root.svelte';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as Close } from './components/dialog.close.svelte';
|
|
2
|
+
export { default as Content } from './components/dialog.content.svelte';
|
|
3
|
+
export { default as Overlay } from './components/dialog.overlay.svelte';
|
|
4
|
+
export { default as Portal } from './components/dialog.portal.svelte';
|
|
5
|
+
export { default as Positioner } from './components/dialog.positioner.svelte';
|
|
6
|
+
export { default as Root } from './components/dialog.root.svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createRegister, default as Host } from './dialog-host.svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createRegister, default as Host } from './dialog-host.svelte';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * as DialogPrimitive from './exports-primitive.js';
|
|
2
|
+
export * as Dialog from './exports.js';
|
|
3
|
+
export { useDialogItemContext } from './dialog-host-item.svelte';
|
|
4
|
+
export { dialogs } from './model/index.js';
|
|
5
|
+
export type { DialogCloseProps, DialogContentProps, DialogOptions, DialogOverlayProps, DialogPortalProps, DialogPositionerProps, DialogRootProps, ExtractRegisterdDialogs, RegisteredDialogCollection, RegisteredDialogKeys, RegisteredDialogsOverride, RegistereDialogProps, } from './types.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Context } from 'runed';
|
|
2
|
+
import { type ComponentProps } from 'svelte';
|
|
3
|
+
import { type ReadableBoxedValues } from 'svelte-toolbelt';
|
|
4
|
+
import type { CloseDialogCommandPayload, DialogComponent, DialogItemState, DialogRegistrationValue, OpenDialogCommandPayload, OpenRegisteredDialogCommandPayload, RegisteredDialogCollection, RegisteredDialogKeys } from '../types.js';
|
|
5
|
+
export declare const DialogManagerContext: Context<DialogManagerState>;
|
|
6
|
+
type DialogManagerOpts = ReadableBoxedValues<{
|
|
7
|
+
register: Record<string, DialogRegistrationValue>;
|
|
8
|
+
}>;
|
|
9
|
+
export declare class DialogManagerState {
|
|
10
|
+
#private;
|
|
11
|
+
static create(opts: DialogManagerOpts): DialogManagerState;
|
|
12
|
+
readonly opts: DialogManagerOpts;
|
|
13
|
+
constructor(opts: DialogManagerOpts);
|
|
14
|
+
innerClose(payload: CloseDialogCommandPayload): void;
|
|
15
|
+
get dialogs(): DialogItemState[];
|
|
16
|
+
set dialogs(value: DialogItemState[]);
|
|
17
|
+
}
|
|
18
|
+
declare function openRegistered<TKey extends RegisteredDialogKeys = RegisteredDialogKeys, TProps extends ComponentProps<RegisteredDialogCollection[TKey]> = ComponentProps<RegisteredDialogCollection[TKey]>>(payload: OpenRegisteredDialogCommandPayload<TKey, TProps>): string;
|
|
19
|
+
declare function open<TComponent extends DialogComponent>(payload: OpenDialogCommandPayload<TComponent>): string;
|
|
20
|
+
declare function close(payload: CloseDialogCommandPayload): void;
|
|
21
|
+
declare function closeAll(): void;
|
|
22
|
+
export declare const dialogs: {
|
|
23
|
+
openRegistered: typeof openRegistered;
|
|
24
|
+
open: typeof open;
|
|
25
|
+
close: typeof close;
|
|
26
|
+
closeAll: typeof closeAll;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { EventDispatcher } from '../../../internal/index.js';
|
|
2
|
+
import { keyWithPrefix, useId } from '../../../internal/utils/common.js';
|
|
3
|
+
import { Context } from 'runed';
|
|
4
|
+
import {} from 'svelte';
|
|
5
|
+
import { mergeProps } from 'svelte-toolbelt';
|
|
6
|
+
const Dispatcher = new EventDispatcher();
|
|
7
|
+
export const DialogManagerContext = new Context(keyWithPrefix('dialog-manager'));
|
|
8
|
+
export class DialogManagerState {
|
|
9
|
+
static create(opts) {
|
|
10
|
+
return DialogManagerContext.set(new DialogManagerState(opts));
|
|
11
|
+
}
|
|
12
|
+
#dialogs = $state([]);
|
|
13
|
+
opts;
|
|
14
|
+
constructor(opts) {
|
|
15
|
+
this.opts = opts;
|
|
16
|
+
$effect(() => {
|
|
17
|
+
this.#subscribeToEvents();
|
|
18
|
+
return () => {
|
|
19
|
+
this.#unsubscribe?.();
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
#unsubscribe;
|
|
24
|
+
#subscribeToEvents() {
|
|
25
|
+
this.#unsubscribe = Dispatcher.subscribe({
|
|
26
|
+
'dialog:openRegistered': (event) => this.#handleOpenRegistered(event.detail),
|
|
27
|
+
'dialog:open': (event) => this.#handleOpen(event.detail),
|
|
28
|
+
'dialog:close': (event) => this.#handleClose(event.detail),
|
|
29
|
+
'dialog:closeAll': () => this.#handleCloseAll(),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
#handleOpenRegistered(payload) {
|
|
33
|
+
const { key, props, options = {}, id } = payload;
|
|
34
|
+
const registeredValue = this.opts.register.current?.[key];
|
|
35
|
+
if (!registeredValue) {
|
|
36
|
+
throw new Error(`Dialog with key "${key}" is not registered`);
|
|
37
|
+
}
|
|
38
|
+
const { component, options: registeredOptions } = registeredValue;
|
|
39
|
+
const componentProps = {
|
|
40
|
+
id,
|
|
41
|
+
...props,
|
|
42
|
+
};
|
|
43
|
+
const mergedOptions = mergeProps(registeredOptions, options);
|
|
44
|
+
const state = {
|
|
45
|
+
component: component,
|
|
46
|
+
props: componentProps,
|
|
47
|
+
id,
|
|
48
|
+
close: () => close({ id }),
|
|
49
|
+
update: (fn) => {
|
|
50
|
+
this.#updateDialog(id, fn);
|
|
51
|
+
},
|
|
52
|
+
options: mergedOptions,
|
|
53
|
+
open: true,
|
|
54
|
+
};
|
|
55
|
+
const newDialogs = [...this.#dialogs.map((d) => ({ ...d, open: false })), state];
|
|
56
|
+
this.dialogs = newDialogs;
|
|
57
|
+
}
|
|
58
|
+
#updateDialog(id, fn) {
|
|
59
|
+
const dialogIndex = this.#dialogs.findIndex((d) => d.id === id);
|
|
60
|
+
if (dialogIndex === -1)
|
|
61
|
+
return;
|
|
62
|
+
const currentDialog = this.#dialogs[dialogIndex];
|
|
63
|
+
if (!currentDialog)
|
|
64
|
+
return;
|
|
65
|
+
const { props: newProps, options: newOptions } = fn(currentDialog.props, currentDialog.options);
|
|
66
|
+
currentDialog.props = { id, ...newProps };
|
|
67
|
+
currentDialog.options = newOptions;
|
|
68
|
+
}
|
|
69
|
+
#handleOpen(payload) {
|
|
70
|
+
const { component, props, options = {}, id } = payload;
|
|
71
|
+
const componentProps = {
|
|
72
|
+
id,
|
|
73
|
+
...props,
|
|
74
|
+
};
|
|
75
|
+
const state = {
|
|
76
|
+
component: component,
|
|
77
|
+
props: componentProps,
|
|
78
|
+
id,
|
|
79
|
+
close: () => close({ id }),
|
|
80
|
+
update: (fn) => {
|
|
81
|
+
this.#updateDialog(id, fn);
|
|
82
|
+
},
|
|
83
|
+
options,
|
|
84
|
+
open: true,
|
|
85
|
+
};
|
|
86
|
+
this.dialogs = [...this.dialogs.map((d) => ({ ...d, open: false })), state];
|
|
87
|
+
}
|
|
88
|
+
#handleClose(payload) {
|
|
89
|
+
const { id } = payload;
|
|
90
|
+
for (let i = this.#dialogs.length - 1; i >= 0; i--) {
|
|
91
|
+
const dialog = this.#dialogs[i];
|
|
92
|
+
console.log('dialog IDX', i);
|
|
93
|
+
if (!dialog)
|
|
94
|
+
continue;
|
|
95
|
+
if (dialog.id === id) {
|
|
96
|
+
dialog.open = false;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (!dialog.open) {
|
|
100
|
+
dialog.open = true;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
setTimeout(() => {
|
|
105
|
+
console.log('afterTick');
|
|
106
|
+
this.dialogs = this.dialogs.filter((d) => d.id !== id);
|
|
107
|
+
}, 150);
|
|
108
|
+
}
|
|
109
|
+
#handleCloseAll() {
|
|
110
|
+
this.dialogs = [];
|
|
111
|
+
}
|
|
112
|
+
innerClose(payload) {
|
|
113
|
+
this.#handleClose(payload);
|
|
114
|
+
}
|
|
115
|
+
get dialogs() {
|
|
116
|
+
return this.#dialogs;
|
|
117
|
+
}
|
|
118
|
+
set dialogs(value) {
|
|
119
|
+
this.#dialogs = value;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function openRegistered(payload) {
|
|
123
|
+
const { key, props, options } = payload;
|
|
124
|
+
const id = useId();
|
|
125
|
+
Dispatcher.dispatch('dialog:openRegistered', {
|
|
126
|
+
key,
|
|
127
|
+
props,
|
|
128
|
+
id,
|
|
129
|
+
options,
|
|
130
|
+
});
|
|
131
|
+
return id;
|
|
132
|
+
}
|
|
133
|
+
function open(payload) {
|
|
134
|
+
const { component, props, options } = payload;
|
|
135
|
+
const id = useId();
|
|
136
|
+
Dispatcher.dispatch('dialog:open', {
|
|
137
|
+
component,
|
|
138
|
+
props,
|
|
139
|
+
options,
|
|
140
|
+
id,
|
|
141
|
+
});
|
|
142
|
+
return id;
|
|
143
|
+
}
|
|
144
|
+
function close(payload) {
|
|
145
|
+
const { id } = payload;
|
|
146
|
+
Dispatcher.dispatch('dialog:close', { id });
|
|
147
|
+
}
|
|
148
|
+
function closeAll() {
|
|
149
|
+
Dispatcher.dispatch('dialog:closeAll');
|
|
150
|
+
}
|
|
151
|
+
export const dialogs = {
|
|
152
|
+
openRegistered,
|
|
153
|
+
open,
|
|
154
|
+
close,
|
|
155
|
+
closeAll,
|
|
156
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DialogManagerContext, DialogManagerState, dialogs } from './dialog-manager.svelte.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DialogManagerContext, DialogManagerState, dialogs } from './dialog-manager.svelte.js';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { VariantProps } from 'tailwind-variants';
|
|
2
|
+
export declare const dialogPositionerStyles: import("tailwind-variants").TVReturnType<{
|
|
3
|
+
align: {
|
|
4
|
+
center: string[];
|
|
5
|
+
};
|
|
6
|
+
}, undefined, string[], {
|
|
7
|
+
align: {
|
|
8
|
+
center: string[];
|
|
9
|
+
};
|
|
10
|
+
}, undefined, import("tailwind-variants").TVReturnType<{
|
|
11
|
+
align: {
|
|
12
|
+
center: string[];
|
|
13
|
+
};
|
|
14
|
+
}, undefined, string[], unknown, unknown, undefined>>;
|
|
15
|
+
export declare const dialogOverlayStyles: import("tailwind-variants").TVReturnType<{} | {} | {}, undefined, string[], {} | {}, undefined, import("tailwind-variants").TVReturnType<unknown, undefined, string[], unknown, unknown, undefined>>;
|
|
16
|
+
export declare const dialogContentStyles: import("tailwind-variants").TVReturnType<{
|
|
17
|
+
variant: {
|
|
18
|
+
default: string[];
|
|
19
|
+
clean: never[];
|
|
20
|
+
};
|
|
21
|
+
rounded: {
|
|
22
|
+
default: string[];
|
|
23
|
+
sm: string[];
|
|
24
|
+
lg: string[];
|
|
25
|
+
xl: string[];
|
|
26
|
+
full: string[];
|
|
27
|
+
clean: never[];
|
|
28
|
+
};
|
|
29
|
+
}, undefined, string[], {
|
|
30
|
+
variant: {
|
|
31
|
+
default: string[];
|
|
32
|
+
clean: never[];
|
|
33
|
+
};
|
|
34
|
+
rounded: {
|
|
35
|
+
default: string[];
|
|
36
|
+
sm: string[];
|
|
37
|
+
lg: string[];
|
|
38
|
+
xl: string[];
|
|
39
|
+
full: string[];
|
|
40
|
+
clean: never[];
|
|
41
|
+
};
|
|
42
|
+
}, undefined, import("tailwind-variants").TVReturnType<{
|
|
43
|
+
variant: {
|
|
44
|
+
default: string[];
|
|
45
|
+
clean: never[];
|
|
46
|
+
};
|
|
47
|
+
rounded: {
|
|
48
|
+
default: string[];
|
|
49
|
+
sm: string[];
|
|
50
|
+
lg: string[];
|
|
51
|
+
xl: string[];
|
|
52
|
+
full: string[];
|
|
53
|
+
clean: never[];
|
|
54
|
+
};
|
|
55
|
+
}, undefined, string[], unknown, unknown, undefined>>;
|
|
56
|
+
export declare const dialogCloseStyles: import("tailwind-variants").TVReturnType<{} | {} | {}, undefined, string[], {} | {}, undefined, import("tailwind-variants").TVReturnType<unknown, undefined, string[], unknown, unknown, undefined>>;
|
|
57
|
+
export type DialogPositionerVariants = VariantProps<typeof dialogPositionerStyles>;
|
|
58
|
+
export type DialogOverlayVariants = VariantProps<typeof dialogOverlayStyles>;
|
|
59
|
+
export type DialogContentVariants = VariantProps<typeof dialogContentStyles>;
|
|
60
|
+
export type DialogCloseVariants = VariantProps<typeof dialogCloseStyles>;
|