|
1 | | -<svelte:options accessors={true} /> |
2 | | - |
3 | 1 | <script lang="ts"> |
4 | 2 | import { |
5 | | - importComponent, |
6 | 3 | getProps, |
| 4 | + importComponent, |
7 | 5 | processProps, |
8 | 6 | } from '@svelte-preprocess-react/component'; |
9 | | - import { getSlotKey } from '@svelte-preprocess-react/svelte-contexts/slot.svelte'; |
10 | 7 | import { getSubIndex } from '@svelte-preprocess-react/svelte-contexts/each.svelte'; |
| 8 | + import { getSlotKey } from '@svelte-preprocess-react/svelte-contexts/slot.svelte'; |
11 | 9 |
|
12 | 10 | import EachItem from './EachItem.svelte'; |
13 | 11 |
|
14 | 12 | const AwaitedEach = importComponent(() => import('./each')); |
15 | 13 | const AwaitedEachPlaceholder = importComponent( |
16 | 14 | () => import('./each.placeholder') |
17 | 15 | ); |
18 | | - export let context_value: Record<PropertyKey, any>; |
19 | | - export let value: Record<PropertyKey, any>[] = []; |
20 | | - export let as_item: string | undefined; |
21 | | - // gradio properties |
22 | | - export let visible = true; |
23 | | - export let _internal: { |
24 | | - index?: number; |
25 | | - } = {}; |
| 16 | + const props = $props(); |
| 17 | + const { getComponentProps, children } = getProps<{ |
| 18 | + context_value: Record<PropertyKey, any> | undefined; |
| 19 | + value: Record<PropertyKey, any>[] | undefined; |
| 20 | + _internal: { |
| 21 | + index?: number; |
| 22 | + }; |
| 23 | + }>(() => props); |
| 24 | +
|
26 | 25 | // if ms.Each inside ms.Each |
27 | 26 | const subIndex = getSubIndex(); |
28 | 27 | const slotKey = getSlotKey(); |
29 | | - const [mergedProps, update] = getSlotContext( |
30 | | - { |
31 | | - _internal, |
32 | | - value, |
33 | | - as_item, |
34 | | - visible, |
35 | | - restProps: $$restProps, |
36 | | - context_value, |
| 28 | +
|
| 29 | + const getProceedProps = processProps( |
| 30 | + () => { |
| 31 | + const { |
| 32 | + visible, |
| 33 | + _internal, |
| 34 | + value, |
| 35 | + as_item, |
| 36 | + elem_classes, |
| 37 | + elem_id, |
| 38 | + elem_style, |
| 39 | + context_value, |
| 40 | + ...restProps |
| 41 | + } = getComponentProps(); |
| 42 | + return { |
| 43 | + _internal, |
| 44 | + as_item, |
| 45 | + value, |
| 46 | + visible, |
| 47 | + elem_id, |
| 48 | + elem_classes, |
| 49 | + elem_style, |
| 50 | + context_value, |
| 51 | + restProps, |
| 52 | + }; |
37 | 53 | }, |
38 | 54 | undefined, |
39 | | - { |
40 | | - shouldResetSlotKey: false, |
41 | | - } |
| 55 | + { shouldResetSlotKey: false } |
42 | 56 | ); |
43 | | - $: update({ |
44 | | - _internal, |
45 | | - value, |
46 | | - as_item, |
47 | | - visible, |
48 | | - restProps: $$restProps, |
49 | | - context_value, |
50 | | - }); |
51 | | - let merged_value: typeof value = []; |
52 | | - let merged_context_value: typeof context_value; |
53 | | - let force_clone = false; |
| 57 | +
|
| 58 | + const proceedProps = $derived(getProceedProps()); |
| 59 | +
|
| 60 | + let merged_value: typeof proceedProps.value = $state([]); |
| 61 | + let merged_context_value: typeof proceedProps.context_value = $state({}); |
| 62 | + let force_clone = $state(false); |
54 | 63 | </script> |
55 | 64 |
|
56 | | -{#if $mergedProps.visible} |
| 65 | +{#if proceedProps.visible} |
57 | 66 | {#await AwaitedEachPlaceholder then EachPlaceholder} |
58 | 67 | <EachPlaceholder |
59 | | - value={$mergedProps.value} |
60 | | - contextValue={$mergedProps.context_value} |
| 68 | + value={proceedProps.value} |
| 69 | + contextValue={proceedProps.context_value} |
61 | 70 | slots={{}} |
62 | | - {...$mergedProps.restProps} |
| 71 | + {...proceedProps.restProps} |
63 | 72 | onChange={(props) => { |
64 | 73 | merged_value = props.value || []; |
65 | 74 | merged_context_value = props.contextValue || {}; |
|
69 | 78 | {#if force_clone} |
70 | 79 | {#await AwaitedEach then Each} |
71 | 80 | <Each |
72 | | - {...$mergedProps.restProps} |
73 | | - contextValue={$mergedProps.context_value} |
74 | | - value={$mergedProps.value} |
75 | | - __internal_slot_key={$slotKey} |
| 81 | + {...proceedProps.restProps} |
| 82 | + contextValue={proceedProps.context_value} |
| 83 | + value={proceedProps.value} |
| 84 | + __internal_slot_key={slotKey?.value} |
76 | 85 | slots={{}} |
77 | 86 | > |
78 | | - <slot /> |
| 87 | + {@render children()} |
79 | 88 | </Each> |
80 | 89 | {/await} |
81 | 90 | {:else} |
82 | 91 | {#each merged_value as item, i (i)} |
83 | 92 | <EachItem |
84 | | - context_value={merged_context_value} |
| 93 | + context_value={merged_context_value || {}} |
85 | 94 | value={item} |
86 | | - index={($mergedProps._internal.index || 0) + (subIndex || 0)} |
87 | | - subIndex={(subIndex || 0) + i} |
| 95 | + index={(proceedProps._internal.index || 0) + (subIndex || 0)} |
| 96 | + subIndex={(subIndex?.value || 0) + i} |
88 | 97 | > |
89 | | - <slot /> |
| 98 | + {@render children()} |
90 | 99 | </EachItem> |
91 | 100 | {/each} |
92 | 101 | {/if} |
|
0 commit comments