@svelte-atoms/core 1.0.0-alpha.28 → 1.0.0-alpha.29
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/README.md +1 -5
- package/dist/components/alert/alert-actions.svelte +43 -43
- package/dist/components/alert/alert-close-button.svelte +70 -70
- package/dist/components/alert/alert-content.svelte +43 -43
- package/dist/components/alert/alert-description.svelte +42 -42
- package/dist/components/alert/alert-icon.svelte +47 -47
- package/dist/components/alert/alert-root.svelte +103 -103
- package/dist/components/alert/alert-title.svelte +42 -42
- package/dist/components/alert/alert.stories.svelte +401 -401
- package/dist/components/atom/html-atom.svelte +6 -4
- package/dist/components/atom/html-atom.svelte.d.ts +1 -1
- package/dist/components/atom/snippet-renderer.svelte +5 -5
- package/dist/components/button/button.stories.svelte +60 -60
- package/dist/components/calendar/calendar-body.svelte +107 -107
- package/dist/components/calendar/calendar-day.svelte +0 -1
- package/dist/components/calendar/calendar-header.svelte +2 -6
- package/dist/components/calendar/calendar-header.svelte.d.ts +0 -1
- package/dist/components/calendar/calendar-root.svelte +0 -2
- package/dist/components/calendar/calendar-week-day.svelte +34 -34
- package/dist/components/calendar/calendar.css +26 -26
- package/dist/components/calendar/calendar.stories.svelte +0 -5
- package/dist/components/calendar/calendar.stories.svelte.d.ts +24 -4
- package/dist/components/datagrid/datagrid-root.svelte +59 -59
- package/dist/components/datagrid/datagrid.css +5 -47
- package/dist/components/datagrid/types.d.ts +1 -1
- package/dist/components/date-picker/atoms.d.ts +0 -4
- package/dist/components/date-picker/atoms.js +0 -4
- package/dist/components/date-picker/date-picker-calendar.svelte +34 -9
- package/dist/components/date-picker/date-picker-calendar.svelte.d.ts +2 -5
- package/dist/components/date-picker/date-picker-header.svelte +59 -64
- package/dist/components/date-picker/date-picker-header.svelte.d.ts +2 -5
- package/dist/components/date-picker/date-picker-months.svelte +36 -44
- package/dist/components/date-picker/date-picker-months.svelte.d.ts +2 -5
- package/dist/components/date-picker/date-picker-root.svelte +3 -2
- package/dist/components/date-picker/date-picker-root.svelte.d.ts +2 -15
- package/dist/components/date-picker/date-picker-years.svelte +88 -97
- package/dist/components/date-picker/date-picker-years.svelte.d.ts +2 -5
- package/dist/components/date-picker/date-picker.stories.svelte +6 -15
- package/dist/components/date-picker/types.d.ts +53 -1
- package/dist/components/dialog/dialog-content.svelte +62 -62
- package/dist/components/element/html-element.svelte +85 -85
- package/dist/components/element/types.d.ts +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/lazy/index.d.ts +1 -0
- package/dist/components/lazy/index.js +1 -0
- package/dist/components/lazy/lazy.stories.svelte +35 -0
- package/dist/components/lazy/lazy.stories.svelte.d.ts +19 -0
- package/dist/components/lazy/lazy.svelte +28 -0
- package/dist/components/lazy/lazy.svelte.d.ts +5 -0
- package/dist/components/lazy/types.d.ts +10 -0
- package/dist/components/lazy/types.js +1 -0
- package/dist/components/menu/menu-list.svelte +40 -39
- package/dist/components/menu/menu-list.svelte.d.ts +1 -0
- package/dist/components/popover/popover-content.svelte +178 -178
- package/dist/components/popover/popover-root.svelte +48 -48
- package/dist/components/popover/popover.stories.svelte +52 -52
- package/dist/components/qr-code/index.d.ts +1 -0
- package/dist/components/qr-code/index.js +1 -0
- package/dist/components/qr-code/qr-code.stories.svelte +4 -1
- package/dist/components/qr-code/qr-code.svelte +65 -15
- package/dist/components/qr-code/qr-code.svelte.d.ts +2 -4
- package/dist/components/qr-code/types.d.ts +14 -0
- package/dist/components/qr-code/types.js +1 -0
- package/dist/components/sidebar/bond.svelte.d.ts +0 -5
- package/dist/components/sidebar/bond.svelte.js +1 -12
- package/dist/components/sidebar/sidebar-content.svelte +39 -39
- package/dist/components/sidebar/sidebar-content.svelte.d.ts +2 -2
- package/dist/components/sidebar/sidebar-root.svelte +41 -68
- package/dist/components/sidebar/sidebar-root.svelte.d.ts +2 -2
- package/dist/components/sidebar/sidebar.stories.svelte +54 -52
- package/dist/components/sidebar/types.d.ts +6 -6
- package/llm/variants.md +1259 -1261
- package/package.json +2 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from '@storybook/addon-svelte-csf';
|
|
3
|
+
|
|
4
|
+
const { Story } = defineMeta({
|
|
5
|
+
title: 'Atoms/Lazy'
|
|
6
|
+
});
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import Lazy from './lazy.svelte';
|
|
11
|
+
import { Root } from '../root';
|
|
12
|
+
import { delay } from 'es-toolkit';
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<Story name="Lazy">
|
|
16
|
+
{#snippet children({ args })}
|
|
17
|
+
<Root>
|
|
18
|
+
{#snippet children({})}
|
|
19
|
+
<Lazy
|
|
20
|
+
promise={import('../button/button.svelte').then(async res=> {
|
|
21
|
+
await delay(1000 * 5);
|
|
22
|
+
|
|
23
|
+
return res.default;
|
|
24
|
+
})}
|
|
25
|
+
>
|
|
26
|
+
Hello World
|
|
27
|
+
|
|
28
|
+
{#snippet loading()}
|
|
29
|
+
<span>Loading...</span>
|
|
30
|
+
{/snippet}
|
|
31
|
+
</Lazy>
|
|
32
|
+
{/snippet}
|
|
33
|
+
</Root>
|
|
34
|
+
{/snippet}
|
|
35
|
+
</Story>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Lazy from './lazy.svelte';
|
|
2
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
+
$$bindings?: Bindings;
|
|
5
|
+
} & Exports;
|
|
6
|
+
(internal: unknown, props: {
|
|
7
|
+
$$events?: Events;
|
|
8
|
+
$$slots?: Slots;
|
|
9
|
+
}): Exports & {
|
|
10
|
+
$set?: any;
|
|
11
|
+
$on?: any;
|
|
12
|
+
};
|
|
13
|
+
z_$$bindings?: Bindings;
|
|
14
|
+
}
|
|
15
|
+
declare const Lazy: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
16
|
+
[evt: string]: CustomEvent<any>;
|
|
17
|
+
}, {}, {}, string>;
|
|
18
|
+
type Lazy = InstanceType<typeof Lazy>;
|
|
19
|
+
export default Lazy;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Component } from 'svelte';
|
|
3
|
+
import type { LazyProps } from './types';
|
|
4
|
+
|
|
5
|
+
let { promise, children, loading, error, ...restProps }: LazyProps = $props();
|
|
6
|
+
|
|
7
|
+
let Lazy: Component | null = $state(null);
|
|
8
|
+
|
|
9
|
+
let err = $state();
|
|
10
|
+
|
|
11
|
+
promise
|
|
12
|
+
.then((c) => {
|
|
13
|
+
Lazy = c;
|
|
14
|
+
})
|
|
15
|
+
.catch((r) => {
|
|
16
|
+
err = r;
|
|
17
|
+
});
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<Lazy {...restProps}>
|
|
21
|
+
{@render children?.()}
|
|
22
|
+
</Lazy>
|
|
23
|
+
|
|
24
|
+
{#if err && error}
|
|
25
|
+
{@render error?.()}
|
|
26
|
+
{:else if !Lazy}
|
|
27
|
+
{@render loading?.()}
|
|
28
|
+
{/if}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Component, Snippet } from 'svelte';
|
|
2
|
+
import type { HtmlAtomProps } from '../atom';
|
|
3
|
+
export interface LazyExtendProps {
|
|
4
|
+
}
|
|
5
|
+
export interface LazyProps extends HtmlAtomProps<'button'>, LazyExtendProps {
|
|
6
|
+
promise: Promise<Component>;
|
|
7
|
+
children?: Snippet;
|
|
8
|
+
error?: Snippet;
|
|
9
|
+
loading?: Snippet;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,39 +1,40 @@
|
|
|
1
|
-
<script lang="ts" generics="T extends keyof HTMLElementTagNameMap = 'div', B extends Base = Base">
|
|
2
|
-
import { List } from '../list';
|
|
3
|
-
import { Content } from '../popover/atoms';
|
|
4
|
-
import type { Base } from '../atom';
|
|
5
|
-
import { PopoverBond } from '../popover';
|
|
6
|
-
|
|
7
|
-
const bond = PopoverBond.get();
|
|
8
|
-
|
|
9
|
-
let {
|
|
10
|
-
class: klass = '',
|
|
11
|
-
as = 'ul' as T,
|
|
12
|
-
base = List.Root as B,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
{
|
|
27
|
-
{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
<script lang="ts" generics="T extends keyof HTMLElementTagNameMap = 'div', B extends Base = Base">
|
|
2
|
+
import { List } from '../list';
|
|
3
|
+
import { Content } from '../popover/atoms';
|
|
4
|
+
import type { Base } from '../atom';
|
|
5
|
+
import { PopoverBond } from '../popover';
|
|
6
|
+
|
|
7
|
+
const bond = PopoverBond.get();
|
|
8
|
+
|
|
9
|
+
let {
|
|
10
|
+
class: klass = '',
|
|
11
|
+
as = 'ul' as T,
|
|
12
|
+
base = List.Root as B,
|
|
13
|
+
preset = 'menu.list',
|
|
14
|
+
children = undefined,
|
|
15
|
+
onmount = undefined,
|
|
16
|
+
ondestroy = undefined,
|
|
17
|
+
animate = undefined,
|
|
18
|
+
enter = undefined,
|
|
19
|
+
exit = undefined,
|
|
20
|
+
initial = undefined,
|
|
21
|
+
...restProps
|
|
22
|
+
} = $props();
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<Content
|
|
26
|
+
{as}
|
|
27
|
+
{base}
|
|
28
|
+
{bond}
|
|
29
|
+
{preset}
|
|
30
|
+
class={['bg-background border-border overflow-hidden p-0', '$preset', klass]}
|
|
31
|
+
onmount={onmount?.bind(bond.state)}
|
|
32
|
+
ondestroy={ondestroy?.bind(bond.state)}
|
|
33
|
+
enter={enter?.bind(bond.state)}
|
|
34
|
+
exit={exit?.bind(bond.state)}
|
|
35
|
+
initial={initial?.bind(bond.state)}
|
|
36
|
+
animate={animate?.bind(bond.state)}
|
|
37
|
+
{...restProps}
|
|
38
|
+
>
|
|
39
|
+
{@render children?.()}
|
|
40
|
+
</Content>
|
|
@@ -1,178 +1,178 @@
|
|
|
1
|
-
<script lang="ts" generics="E extends HtmlElementTagName, B extends Base = Base">
|
|
2
|
-
import { animate as motion } from 'motion';
|
|
3
|
-
import { PortalBond, PortalsBond, Teleport } from '../portal';
|
|
4
|
-
import { HtmlAtom, type Base } from '../atom';
|
|
5
|
-
import type { HtmlElementTagName, HtmlElementType } from '../element';
|
|
6
|
-
import { DURATION } from '../../shared';
|
|
7
|
-
import { PopoverBond } from './bond.svelte';
|
|
8
|
-
import type { AnimateParams, PopoverContentProps } from './types';
|
|
9
|
-
|
|
10
|
-
type Element = HtmlElementType<E>;
|
|
11
|
-
|
|
12
|
-
const bond = PopoverBond.get();
|
|
13
|
-
const activePortalBond = (() => {
|
|
14
|
-
const key = bond.state.props.portal;
|
|
15
|
-
if (key instanceof PortalBond) {
|
|
16
|
-
return key;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
let portal: PortalBond | undefined | null = undefined;
|
|
20
|
-
|
|
21
|
-
if (typeof key === 'string') {
|
|
22
|
-
portal = PortalsBond.get()?.state.get(key);
|
|
23
|
-
console.error('portal was not found');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return portal ?? PortalBond.get();
|
|
27
|
-
})();
|
|
28
|
-
|
|
29
|
-
if (!bond) {
|
|
30
|
-
throw new Error('<PopoverOverlay /> must be used within a <Popover />');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let {
|
|
34
|
-
class: klass = '',
|
|
35
|
-
children = undefined,
|
|
36
|
-
onmount = undefined,
|
|
37
|
-
ondestroy = undefined,
|
|
38
|
-
animate = _animate,
|
|
39
|
-
enter = undefined,
|
|
40
|
-
exit = undefined,
|
|
41
|
-
initial = undefined,
|
|
42
|
-
...restProps
|
|
43
|
-
}: PopoverContentProps<E, B> = $props();
|
|
44
|
-
|
|
45
|
-
const isOpen = $derived(bond.state.isOpen && !!bond.elements.trigger);
|
|
46
|
-
const portalId = $derived(activePortalBond?.id);
|
|
47
|
-
|
|
48
|
-
const position = $derived(bond.position);
|
|
49
|
-
const placement = $derived(position?.placement);
|
|
50
|
-
|
|
51
|
-
const x = $derived(position?.x ?? 0);
|
|
52
|
-
const y = $derived(position?.y ?? 0);
|
|
53
|
-
|
|
54
|
-
const dy = $derived(placement?.startsWith('top') ? -1 : placement?.startsWith('bottom') ? 1 : 0);
|
|
55
|
-
const dx = $derived(placement?.startsWith('left') ? -1 : placement?.startsWith('right') ? 1 : 0);
|
|
56
|
-
|
|
57
|
-
const offset = $derived(bond.state.props.offset);
|
|
58
|
-
|
|
59
|
-
const xOffset = $derived(dx * offset);
|
|
60
|
-
const yOffset = $derived(dy * offset);
|
|
61
|
-
|
|
62
|
-
const openAsNumber = $derived(+isOpen);
|
|
63
|
-
const deltaArrow = $derived(position?.middlewareData?.arrow ? 1 : 0);
|
|
64
|
-
|
|
65
|
-
let isInitialized = false;
|
|
66
|
-
|
|
67
|
-
function _containerInitial(this: typeof bond.state, node: Element) {
|
|
68
|
-
const arrowClientWidth = bond?.elements.arrow?.clientWidth ?? 0;
|
|
69
|
-
const arrowClientHeight = bond?.elements.arrow?.clientHeight ?? 0;
|
|
70
|
-
|
|
71
|
-
const _x = x + xOffset * openAsNumber + deltaArrow * dx * arrowClientWidth;
|
|
72
|
-
const _y = y + yOffset * openAsNumber + deltaArrow * dy * arrowClientHeight;
|
|
73
|
-
|
|
74
|
-
node.style.transform = `translate3d(${_x}px, ${_y}px, 1px)`;
|
|
75
|
-
|
|
76
|
-
isInitialized = true;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function _containerAnimate(this: typeof bond.state, node: Element, _?: AnimateParams) {
|
|
80
|
-
if (!isInitialized) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const deltaArrow = position?.middlewareData?.arrow ? 1 : 0;
|
|
85
|
-
const arrowClientWidth = bond?.elements.arrow?.clientWidth ?? 0;
|
|
86
|
-
const arrowClientHeight = bond?.elements.arrow?.clientHeight ?? 0;
|
|
87
|
-
|
|
88
|
-
const _x = x + xOffset * openAsNumber + deltaArrow * dx * arrowClientWidth;
|
|
89
|
-
const _y = y + yOffset * openAsNumber + deltaArrow * dy * arrowClientHeight;
|
|
90
|
-
|
|
91
|
-
node.style.transform = `translate3d(${_x}px, ${_y}px, 1px)`;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
let isOpened = false;
|
|
95
|
-
|
|
96
|
-
function _animate(this: typeof bond.state, node: Element) {
|
|
97
|
-
const isOpen = this.isOpen;
|
|
98
|
-
|
|
99
|
-
const arrowClientWidth = bond?.elements.arrow?.clientWidth ?? 0;
|
|
100
|
-
const arrowClientHeight = bond?.elements.arrow?.clientHeight ?? 0;
|
|
101
|
-
|
|
102
|
-
const _x = openAsNumber * dx;
|
|
103
|
-
const _y = openAsNumber * dy;
|
|
104
|
-
|
|
105
|
-
const getTransformOrigin = () => {
|
|
106
|
-
switch (placement) {
|
|
107
|
-
case 'top':
|
|
108
|
-
case 'top-start':
|
|
109
|
-
case 'top-end':
|
|
110
|
-
return 'bottom';
|
|
111
|
-
case 'bottom':
|
|
112
|
-
case 'bottom-start':
|
|
113
|
-
case 'bottom-end':
|
|
114
|
-
return 'top';
|
|
115
|
-
case 'left':
|
|
116
|
-
case 'left-start':
|
|
117
|
-
case 'left-end':
|
|
118
|
-
return 'right';
|
|
119
|
-
case 'right':
|
|
120
|
-
case 'right-start':
|
|
121
|
-
case 'right-end':
|
|
122
|
-
return 'left';
|
|
123
|
-
default:
|
|
124
|
-
return 'center';
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const transformOrigin = getTransformOrigin();
|
|
129
|
-
|
|
130
|
-
const from = isOpened ? 1 : 0.95;
|
|
131
|
-
|
|
132
|
-
motion(
|
|
133
|
-
node,
|
|
134
|
-
{
|
|
135
|
-
opacity: openAsNumber,
|
|
136
|
-
y: _y + dy * (!isOpen ? -1 : 0) * (arrowClientHeight + yOffset),
|
|
137
|
-
x: _x + dx * (!isOpen ? -1 : 0) * (arrowClientWidth + xOffset),
|
|
138
|
-
scaleY: dy ? (isOpen ? [from, 1] : [1, 0.8]) : undefined,
|
|
139
|
-
scaleX: dx ? (isOpen ? [from, 1] : [1, 0.8]) : undefined,
|
|
140
|
-
transformOrigin
|
|
141
|
-
},
|
|
142
|
-
{ duration: DURATION.fast / 1000 }
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
isOpened = isOpen;
|
|
146
|
-
}
|
|
147
|
-
</script>
|
|
148
|
-
|
|
149
|
-
<Teleport
|
|
150
|
-
portal={portalId ?? 'root.l0'}
|
|
151
|
-
as="div"
|
|
152
|
-
class={[
|
|
153
|
-
'pointer-events-auto absolute top-0 left-0 h-min w-fit',
|
|
154
|
-
!isOpen && 'pointer-events-none'
|
|
155
|
-
]}
|
|
156
|
-
initial={_containerInitial?.bind(bond.state)}
|
|
157
|
-
animate={_containerAnimate?.bind(bond.state)}
|
|
158
|
-
{...bond.content({ onchange: _containerInitial })}
|
|
159
|
-
>
|
|
160
|
-
<HtmlAtom
|
|
161
|
-
{bond}
|
|
162
|
-
preset="popover.content"
|
|
163
|
-
class={[
|
|
164
|
-
'popover-content bg-popover text-popover-foreground border-border rounded-md border p-2 opacity-0 shadow-lg',
|
|
165
|
-
'$preset',
|
|
166
|
-
klass
|
|
167
|
-
]}
|
|
168
|
-
enter={enter?.bind(bond.state)}
|
|
169
|
-
exit={exit?.bind(bond.state)}
|
|
170
|
-
initial={initial?.bind(bond.state)}
|
|
171
|
-
animate={animate?.bind(bond.state)}
|
|
172
|
-
onmount={onmount?.bind(bond.state)}
|
|
173
|
-
ondestroy={ondestroy?.bind(bond.state)}
|
|
174
|
-
{...restProps}
|
|
175
|
-
>
|
|
176
|
-
{@render children?.({ popover: bond })}
|
|
177
|
-
</HtmlAtom>
|
|
178
|
-
</Teleport>
|
|
1
|
+
<script lang="ts" generics="E extends HtmlElementTagName, B extends Base = Base">
|
|
2
|
+
import { animate as motion } from 'motion';
|
|
3
|
+
import { PortalBond, PortalsBond, Teleport } from '../portal';
|
|
4
|
+
import { HtmlAtom, type Base } from '../atom';
|
|
5
|
+
import type { HtmlElementTagName, HtmlElementType } from '../element';
|
|
6
|
+
import { DURATION } from '../../shared';
|
|
7
|
+
import { PopoverBond } from './bond.svelte';
|
|
8
|
+
import type { AnimateParams, PopoverContentProps } from './types';
|
|
9
|
+
|
|
10
|
+
type Element = HtmlElementType<E>;
|
|
11
|
+
|
|
12
|
+
const bond = PopoverBond.get();
|
|
13
|
+
const activePortalBond = (() => {
|
|
14
|
+
const key = bond.state.props.portal;
|
|
15
|
+
if (key instanceof PortalBond) {
|
|
16
|
+
return key;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let portal: PortalBond | undefined | null = undefined;
|
|
20
|
+
|
|
21
|
+
if (typeof key === 'string') {
|
|
22
|
+
portal = PortalsBond.get()?.state.get(key);
|
|
23
|
+
console.error('portal was not found');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return portal ?? PortalBond.get();
|
|
27
|
+
})();
|
|
28
|
+
|
|
29
|
+
if (!bond) {
|
|
30
|
+
throw new Error('<PopoverOverlay /> must be used within a <Popover />');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let {
|
|
34
|
+
class: klass = '',
|
|
35
|
+
children = undefined,
|
|
36
|
+
onmount = undefined,
|
|
37
|
+
ondestroy = undefined,
|
|
38
|
+
animate = _animate,
|
|
39
|
+
enter = undefined,
|
|
40
|
+
exit = undefined,
|
|
41
|
+
initial = undefined,
|
|
42
|
+
...restProps
|
|
43
|
+
}: PopoverContentProps<E, B> = $props();
|
|
44
|
+
|
|
45
|
+
const isOpen = $derived(bond.state.isOpen && !!bond.elements.trigger);
|
|
46
|
+
const portalId = $derived(activePortalBond?.id);
|
|
47
|
+
|
|
48
|
+
const position = $derived(bond.position);
|
|
49
|
+
const placement = $derived(position?.placement);
|
|
50
|
+
|
|
51
|
+
const x = $derived(position?.x ?? 0);
|
|
52
|
+
const y = $derived(position?.y ?? 0);
|
|
53
|
+
|
|
54
|
+
const dy = $derived(placement?.startsWith('top') ? -1 : placement?.startsWith('bottom') ? 1 : 0);
|
|
55
|
+
const dx = $derived(placement?.startsWith('left') ? -1 : placement?.startsWith('right') ? 1 : 0);
|
|
56
|
+
|
|
57
|
+
const offset = $derived(bond.state.props.offset);
|
|
58
|
+
|
|
59
|
+
const xOffset = $derived(dx * offset);
|
|
60
|
+
const yOffset = $derived(dy * offset);
|
|
61
|
+
|
|
62
|
+
const openAsNumber = $derived(+isOpen);
|
|
63
|
+
const deltaArrow = $derived(position?.middlewareData?.arrow ? 1 : 0);
|
|
64
|
+
|
|
65
|
+
let isInitialized = false;
|
|
66
|
+
|
|
67
|
+
function _containerInitial(this: typeof bond.state, node: Element) {
|
|
68
|
+
const arrowClientWidth = bond?.elements.arrow?.clientWidth ?? 0;
|
|
69
|
+
const arrowClientHeight = bond?.elements.arrow?.clientHeight ?? 0;
|
|
70
|
+
|
|
71
|
+
const _x = x + xOffset * openAsNumber + deltaArrow * dx * arrowClientWidth;
|
|
72
|
+
const _y = y + yOffset * openAsNumber + deltaArrow * dy * arrowClientHeight;
|
|
73
|
+
|
|
74
|
+
node.style.transform = `translate3d(${_x}px, ${_y}px, 1px)`;
|
|
75
|
+
|
|
76
|
+
isInitialized = true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function _containerAnimate(this: typeof bond.state, node: Element, _?: AnimateParams) {
|
|
80
|
+
if (!isInitialized) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const deltaArrow = position?.middlewareData?.arrow ? 1 : 0;
|
|
85
|
+
const arrowClientWidth = bond?.elements.arrow?.clientWidth ?? 0;
|
|
86
|
+
const arrowClientHeight = bond?.elements.arrow?.clientHeight ?? 0;
|
|
87
|
+
|
|
88
|
+
const _x = x + xOffset * openAsNumber + deltaArrow * dx * arrowClientWidth;
|
|
89
|
+
const _y = y + yOffset * openAsNumber + deltaArrow * dy * arrowClientHeight;
|
|
90
|
+
|
|
91
|
+
node.style.transform = `translate3d(${_x}px, ${_y}px, 1px)`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let isOpened = false;
|
|
95
|
+
|
|
96
|
+
function _animate(this: typeof bond.state, node: Element) {
|
|
97
|
+
const isOpen = this.isOpen;
|
|
98
|
+
|
|
99
|
+
const arrowClientWidth = bond?.elements.arrow?.clientWidth ?? 0;
|
|
100
|
+
const arrowClientHeight = bond?.elements.arrow?.clientHeight ?? 0;
|
|
101
|
+
|
|
102
|
+
const _x = openAsNumber * dx;
|
|
103
|
+
const _y = openAsNumber * dy;
|
|
104
|
+
|
|
105
|
+
const getTransformOrigin = () => {
|
|
106
|
+
switch (placement) {
|
|
107
|
+
case 'top':
|
|
108
|
+
case 'top-start':
|
|
109
|
+
case 'top-end':
|
|
110
|
+
return 'bottom';
|
|
111
|
+
case 'bottom':
|
|
112
|
+
case 'bottom-start':
|
|
113
|
+
case 'bottom-end':
|
|
114
|
+
return 'top';
|
|
115
|
+
case 'left':
|
|
116
|
+
case 'left-start':
|
|
117
|
+
case 'left-end':
|
|
118
|
+
return 'right';
|
|
119
|
+
case 'right':
|
|
120
|
+
case 'right-start':
|
|
121
|
+
case 'right-end':
|
|
122
|
+
return 'left';
|
|
123
|
+
default:
|
|
124
|
+
return 'center';
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const transformOrigin = getTransformOrigin();
|
|
129
|
+
|
|
130
|
+
const from = isOpened ? 1 : 0.95;
|
|
131
|
+
|
|
132
|
+
motion(
|
|
133
|
+
node,
|
|
134
|
+
{
|
|
135
|
+
opacity: openAsNumber,
|
|
136
|
+
y: _y + dy * (!isOpen ? -1 : 0) * (arrowClientHeight + yOffset),
|
|
137
|
+
x: _x + dx * (!isOpen ? -1 : 0) * (arrowClientWidth + xOffset),
|
|
138
|
+
scaleY: dy ? (isOpen ? [from, 1] : [1, 0.8]) : undefined,
|
|
139
|
+
scaleX: dx ? (isOpen ? [from, 1] : [1, 0.8]) : undefined,
|
|
140
|
+
transformOrigin
|
|
141
|
+
},
|
|
142
|
+
{ duration: DURATION.fast / 1000 }
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
isOpened = isOpen;
|
|
146
|
+
}
|
|
147
|
+
</script>
|
|
148
|
+
|
|
149
|
+
<Teleport
|
|
150
|
+
portal={portalId ?? 'root.l0'}
|
|
151
|
+
as="div"
|
|
152
|
+
class={[
|
|
153
|
+
'pointer-events-auto absolute top-0 left-0 h-min w-fit',
|
|
154
|
+
!isOpen && 'pointer-events-none'
|
|
155
|
+
]}
|
|
156
|
+
initial={_containerInitial?.bind(bond.state)}
|
|
157
|
+
animate={_containerAnimate?.bind(bond.state)}
|
|
158
|
+
{...bond.content({ onchange: _containerInitial })}
|
|
159
|
+
>
|
|
160
|
+
<HtmlAtom
|
|
161
|
+
{bond}
|
|
162
|
+
preset="popover.content"
|
|
163
|
+
class={[
|
|
164
|
+
'popover-content bg-popover text-popover-foreground border-border rounded-md border p-2 opacity-0 shadow-lg',
|
|
165
|
+
'$preset',
|
|
166
|
+
klass
|
|
167
|
+
]}
|
|
168
|
+
enter={enter?.bind(bond.state)}
|
|
169
|
+
exit={exit?.bind(bond.state)}
|
|
170
|
+
initial={initial?.bind(bond.state)}
|
|
171
|
+
animate={animate?.bind(bond.state)}
|
|
172
|
+
onmount={onmount?.bind(bond.state)}
|
|
173
|
+
ondestroy={ondestroy?.bind(bond.state)}
|
|
174
|
+
{...restProps}
|
|
175
|
+
>
|
|
176
|
+
{@render children?.({ popover: bond })}
|
|
177
|
+
</HtmlAtom>
|
|
178
|
+
</Teleport>
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { PopoverState, PopoverBond, type PopoverStateProps } from './bond.svelte';
|
|
3
|
-
import { defineProperty, defineState } from '../../utils';
|
|
4
|
-
import type { PopoverRootProps } from './types';
|
|
5
|
-
|
|
6
|
-
let {
|
|
7
|
-
open = $bindable(false),
|
|
8
|
-
disabled = false,
|
|
9
|
-
placements = ['bottom-start', 'bottom-end', 'top-start', 'top-end'],
|
|
10
|
-
placement = 'bottom-start',
|
|
11
|
-
offset = 0,
|
|
12
|
-
portal = undefined,
|
|
13
|
-
extend = {},
|
|
14
|
-
factory = _factory,
|
|
15
|
-
children = undefined
|
|
16
|
-
}: PopoverRootProps = $props();
|
|
17
|
-
|
|
18
|
-
const bondProps = defineState<PopoverStateProps>([
|
|
19
|
-
defineProperty(
|
|
20
|
-
'open',
|
|
21
|
-
() => open,
|
|
22
|
-
(v) => {
|
|
23
|
-
open = v;
|
|
24
|
-
}
|
|
25
|
-
),
|
|
26
|
-
defineProperty('disabled', () => disabled),
|
|
27
|
-
defineProperty('placement', () => placement),
|
|
28
|
-
defineProperty('offset', () => offset),
|
|
29
|
-
defineProperty('placements', () => placements ?? []),
|
|
30
|
-
defineProperty('portal', () => portal),
|
|
31
|
-
defineProperty('extend', () => extend)
|
|
32
|
-
]);
|
|
33
|
-
|
|
34
|
-
const bond = factory(bondProps).share();
|
|
35
|
-
|
|
36
|
-
function _factory(props: typeof bondProps) {
|
|
37
|
-
const popoverState = new PopoverState(() => props);
|
|
38
|
-
const popoverBond = new PopoverBond(popoverState);
|
|
39
|
-
|
|
40
|
-
return popoverBond;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function getBond() {
|
|
44
|
-
return bond;
|
|
45
|
-
}
|
|
46
|
-
</script>
|
|
47
|
-
|
|
48
|
-
{@render children?.({ popover: bond })}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { PopoverState, PopoverBond, type PopoverStateProps } from './bond.svelte';
|
|
3
|
+
import { defineProperty, defineState } from '../../utils';
|
|
4
|
+
import type { PopoverRootProps } from './types';
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
open = $bindable(false),
|
|
8
|
+
disabled = false,
|
|
9
|
+
placements = ['bottom-start', 'bottom-end', 'top-start', 'top-end'],
|
|
10
|
+
placement = 'bottom-start',
|
|
11
|
+
offset = 0,
|
|
12
|
+
portal = undefined,
|
|
13
|
+
extend = {},
|
|
14
|
+
factory = _factory,
|
|
15
|
+
children = undefined
|
|
16
|
+
}: PopoverRootProps = $props();
|
|
17
|
+
|
|
18
|
+
const bondProps = defineState<PopoverStateProps>([
|
|
19
|
+
defineProperty(
|
|
20
|
+
'open',
|
|
21
|
+
() => open,
|
|
22
|
+
(v) => {
|
|
23
|
+
open = v;
|
|
24
|
+
}
|
|
25
|
+
),
|
|
26
|
+
defineProperty('disabled', () => disabled),
|
|
27
|
+
defineProperty('placement', () => placement),
|
|
28
|
+
defineProperty('offset', () => offset),
|
|
29
|
+
defineProperty('placements', () => placements ?? []),
|
|
30
|
+
defineProperty('portal', () => portal),
|
|
31
|
+
defineProperty('extend', () => extend)
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
const bond = factory(bondProps).share();
|
|
35
|
+
|
|
36
|
+
function _factory(props: typeof bondProps) {
|
|
37
|
+
const popoverState = new PopoverState(() => props);
|
|
38
|
+
const popoverBond = new PopoverBond(popoverState);
|
|
39
|
+
|
|
40
|
+
return popoverBond;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getBond() {
|
|
44
|
+
return bond;
|
|
45
|
+
}
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
{@render children?.({ popover: bond })}
|