ui-ingredients 0.0.67 → 0.0.68

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,16 @@
1
1
  <script lang="ts" module>
2
2
  import type {HtmlIngredientProps} from '../types.js';
3
+ import type {Action} from 'svelte/action';
3
4
 
4
5
  export interface TreeViewBranchContentProps
5
- extends HtmlIngredientProps<'div', HTMLDivElement> {}
6
+ extends HtmlIngredientProps<'div', HTMLDivElement, never, Action> {}
6
7
  </script>
7
8
 
8
9
  <script lang="ts">
9
10
  import {mergeProps} from '../merge-props.js';
11
+ import {createPresence} from '../presence/create-presence.svelte.js';
12
+ import {getPresenceStrategyPropsContext} from '../presence/presence-context.svelte.js';
13
+ import {reflect} from '@zag-js/svelte';
10
14
  import {
11
15
  getTreeViewBranchPropsContext,
12
16
  getTreeViewContext,
@@ -22,16 +26,31 @@
22
26
  let treeView = getTreeViewContext();
23
27
 
24
28
  let branchProps = getTreeViewBranchPropsContext();
29
+ let branchState = $derived(treeView.getBranchState(branchProps));
30
+
31
+ let presenceStrategyProps = getPresenceStrategyPropsContext();
32
+ let presence = createPresence(
33
+ reflect(() => ({
34
+ present: branchState.expanded,
35
+ ...presenceStrategyProps,
36
+ })),
37
+ );
25
38
 
26
39
  let mergedProps = $derived(
27
- mergeProps(treeView.getBranchContentProps(branchProps), props),
40
+ mergeProps(
41
+ treeView.getBranchContentProps(branchProps),
42
+ presence.getPresenceProps(),
43
+ props,
44
+ ),
28
45
  );
29
46
  </script>
30
47
 
31
- {#if asChild}
32
- {@render asChild(mergedProps)}
33
- {:else}
34
- <div bind:this={ref} {...mergedProps}>
35
- {@render children?.()}
36
- </div>
48
+ {#if presence.mounted}
49
+ {#if asChild}
50
+ {@render asChild(presence.setReference, mergedProps)}
51
+ {:else}
52
+ <div bind:this={ref} {...mergedProps}>
53
+ {@render children?.()}
54
+ </div>
55
+ {/if}
37
56
  {/if}
@@ -1,5 +1,6 @@
1
1
  import type { HtmlIngredientProps } from '../types.js';
2
- export interface TreeViewBranchContentProps extends HtmlIngredientProps<'div', HTMLDivElement> {
2
+ import type { Action } from 'svelte/action';
3
+ export interface TreeViewBranchContentProps extends HtmlIngredientProps<'div', HTMLDivElement, never, Action> {
3
4
  }
4
5
  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> {
5
6
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
@@ -1,4 +1,5 @@
1
1
  <script lang="ts" module>
2
+ import type {PresenceStrategyProps} from '../presence/create-presence.svelte.js';
2
3
  import type {Assign, HtmlIngredientProps} from '../types.js';
3
4
  import type {
4
5
  CreateTreeViewProps,
@@ -7,13 +8,15 @@
7
8
 
8
9
  export interface TreeViewProps
9
10
  extends Assign<
10
- HtmlIngredientProps<'div', HTMLDivElement, CreateTreeViewReturn>,
11
- CreateTreeViewProps
12
- > {}
11
+ HtmlIngredientProps<'div', HTMLDivElement, CreateTreeViewReturn>,
12
+ CreateTreeViewProps
13
+ >,
14
+ PresenceStrategyProps {}
13
15
  </script>
14
16
 
15
17
  <script lang="ts">
16
18
  import {mergeProps} from '../merge-props.js';
19
+ import {setPresenceStrategyPropsContext} from '../presence/presence-context.svelte.js';
17
20
  import {reflect} from '@zag-js/svelte';
18
21
  import {createSplitProps} from '@zag-js/utils';
19
22
  import {createTreeView} from './create-tree-view.svelte.js';
@@ -26,6 +29,12 @@
26
29
  ...props
27
30
  }: TreeViewProps = $props();
28
31
 
32
+ let [presenceStrategyProps, rest] = $derived(
33
+ createSplitProps<PresenceStrategyProps>(['lazyMount', 'keepMounted'])(
34
+ props,
35
+ ),
36
+ );
37
+
29
38
  let [createTreeViewProps, localProps] = $derived(
30
39
  createSplitProps<CreateTreeViewProps>([
31
40
  'id',
@@ -39,14 +48,14 @@
39
48
  'onFocusChange',
40
49
  'onExpandedChange',
41
50
  'onSelectionChange',
42
- ])(props),
51
+ ])(rest),
43
52
  );
44
53
 
45
54
  let treeView = createTreeView(reflect(() => createTreeViewProps));
46
-
47
55
  let mergedProps = $derived(mergeProps(treeView.getRootProps(), localProps));
48
56
 
49
57
  setTreeViewContext(treeView);
58
+ setPresenceStrategyPropsContext(() => presenceStrategyProps);
50
59
  </script>
51
60
 
52
61
  {#if asChild}
@@ -1,6 +1,7 @@
1
+ import type { PresenceStrategyProps } from '../presence/create-presence.svelte.js';
1
2
  import type { Assign, HtmlIngredientProps } from '../types.js';
2
3
  import type { CreateTreeViewProps, CreateTreeViewReturn } from './create-tree-view.svelte.js';
3
- export interface TreeViewProps extends Assign<HtmlIngredientProps<'div', HTMLDivElement, CreateTreeViewReturn>, CreateTreeViewProps> {
4
+ export interface TreeViewProps extends Assign<HtmlIngredientProps<'div', HTMLDivElement, CreateTreeViewReturn>, CreateTreeViewProps>, PresenceStrategyProps {
4
5
  }
5
6
  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> {
6
7
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ui-ingredients",
3
3
  "type": "module",
4
- "version": "0.0.67",
4
+ "version": "0.0.68",
5
5
  "packageManager": "pnpm@9.7.0",
6
6
  "svelte": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",