diff --git a/backend/modelscope_studio/components/base/div/__init__.py b/backend/modelscope_studio/components/base/div/__init__.py index cf4d290d..27e735a9 100644 --- a/backend/modelscope_studio/components/base/div/__init__.py +++ b/backend/modelscope_studio/components/base/div/__init__.py @@ -5,10 +5,6 @@ from gradio.events import EventListener from ....utils.dev import ModelScopeLayoutComponent, resolve_frontend_dir -from ...antd.carousel import AntdCarousel -from ...antd.space import AntdSpace -from ...antd.tooltip import AntdTooltip -from ..slot import ModelScopeSlot class ModelScopeDiv(ModelScopeLayoutComponent): @@ -66,14 +62,8 @@ def __init__( as_item=as_item, elem_style=elem_style, **kwargs) - if self.parent and self._internal and (any( - isinstance(self.parent, component) for component in [ - AntdCarousel, - AntdSpace, - AntdTooltip, - ModelScopeSlot, - ])): - self._internal.update(fragment=True) + + self._internal.update(fragment=True) self.value = value self.props = props diff --git a/backend/modelscope_studio/components/base/span/__init__.py b/backend/modelscope_studio/components/base/span/__init__.py index 7793f5de..3b61c2e3 100644 --- a/backend/modelscope_studio/components/base/span/__init__.py +++ b/backend/modelscope_studio/components/base/span/__init__.py @@ -5,10 +5,6 @@ from gradio.events import EventListener from ....utils.dev import ModelScopeLayoutComponent, resolve_frontend_dir -from ...antd.carousel import AntdCarousel -from ...antd.space import AntdSpace -from ...antd.tooltip import AntdTooltip -from ..slot import ModelScopeSlot class ModelScopeSpan(ModelScopeLayoutComponent): @@ -66,14 +62,8 @@ def __init__( as_item=as_item, elem_style=elem_style, **kwargs) - if self.parent and self._internal and (any( - isinstance(self.parent, component) for component in [ - AntdCarousel, - AntdSpace, - AntdTooltip, - ModelScopeSlot, - ])): - self._internal.update(fragment=True) + + self._internal.update(fragment=True) self.value = value self.props = props diff --git a/backend/modelscope_studio/components/base/text/__init__.py b/backend/modelscope_studio/components/base/text/__init__.py index 42c50a41..1fa9a42d 100644 --- a/backend/modelscope_studio/components/base/text/__init__.py +++ b/backend/modelscope_studio/components/base/text/__init__.py @@ -3,9 +3,6 @@ from typing import Any from ....utils.dev import ModelScopeComponent, resolve_frontend_dir -from ...antd.carousel import AntdCarousel -from ...antd.space import AntdSpace -from ...antd.tooltip import AntdTooltip class ModelScopeText(ModelScopeComponent): @@ -37,10 +34,7 @@ def __init__( as_item=as_item, elem_style=elem_style, **kwargs) - if self.parent and self._internal and (any( - isinstance(self.parent, component) - for component in [AntdCarousel, AntdTooltip, AntdSpace])): - self._internal.update(fragment=True) + self._internal.update(fragment=True) self.value = value FRONTEND_DIR = resolve_frontend_dir("text", type="base") diff --git a/backend/modelscope_studio/utils/dev/app_context.py b/backend/modelscope_studio/utils/dev/app_context.py index 1301e39b..5ba9bc3e 100644 --- a/backend/modelscope_studio/utils/dev/app_context.py +++ b/backend/modelscope_studio/utils/dev/app_context.py @@ -1,3 +1,6 @@ +import warnings + + class AppContext: _app = None @@ -12,7 +15,7 @@ def has_app(cls): @classmethod def assert_app(cls): if cls._app is None: - raise ImportError( + warnings.warn( """: Cannot find the `Application` component, did you forget to import it from `modelscope_studio.components.base`?""" ) diff --git a/frontend/antd/button/Index.svelte b/frontend/antd/button/Index.svelte index 3ca3e94f..91038071 100644 --- a/frontend/antd/button/Index.svelte +++ b/frontend/antd/button/Index.svelte @@ -72,12 +72,9 @@ {...$mergedProps.props} {...bindEvents($mergedProps)} slots={$slots} + value={$mergedProps.value} > - {#if $mergedProps._internal.layout} - - {:else} - {$mergedProps.value} - {/if} + {/await} {/if} diff --git a/frontend/antd/button/button.tsx b/frontend/antd/button/button.tsx index e305597a..2b18aa34 100644 --- a/frontend/antd/button/button.tsx +++ b/frontend/antd/button/button.tsx @@ -1,15 +1,26 @@ import { sveltify } from '@svelte-preprocess-react'; import { ReactSlot } from '@svelte-preprocess-react/react-slot'; import React from 'react'; +import { useTargets } from '@utils/hooks/useTargets'; import { Button as AButton, type GetProps } from 'antd'; export const Button = sveltify, ['icon']>( - ({ slots, ...props }) => { + ({ slots, value, children, ...props }) => { + const targets = useTargets(children); return ( : props.icon} - /> + > + {targets.length > 0 ? ( + children + ) : ( + <> + {children} + {value} + + )} + ); } ); diff --git a/frontend/antd/divider/divider.tsx b/frontend/antd/divider/divider.tsx index e61d6ddc..0bef3e3f 100644 --- a/frontend/antd/divider/divider.tsx +++ b/frontend/antd/divider/divider.tsx @@ -1,10 +1,8 @@ import { sveltify } from '@svelte-preprocess-react'; import { Divider as ADivider, type GetProps } from 'antd'; -export const Divider = sveltify, ['children']>( - ({ ...props }) => { - return ; - } -); +export const Divider = sveltify>(({ ...props }) => { + return ; +}); export default Divider; diff --git a/frontend/antd/dropdown/button/Index.svelte b/frontend/antd/dropdown/button/Index.svelte index 50d808e9..0b0d202e 100644 --- a/frontend/antd/dropdown/button/Index.svelte +++ b/frontend/antd/dropdown/button/Index.svelte @@ -81,12 +81,9 @@ slots={$slots} menuItems={$items} {setSlotParams} + value={$mergedProps.value} > - {#if $mergedProps._internal.layout} - - {:else} - {$mergedProps.value} - {/if} + {/await} {/if} diff --git a/frontend/antd/dropdown/button/dropdown.button.tsx b/frontend/antd/dropdown/button/dropdown.button.tsx index a2b10f76..5abfdff8 100644 --- a/frontend/antd/dropdown/button/dropdown.button.tsx +++ b/frontend/antd/dropdown/button/dropdown.button.tsx @@ -14,6 +14,7 @@ export const DropdownButton = sveltify< GetProps & { menuItems: Item[]; setSlotParams: SetSlotParams; + value?: string; }, [ 'icon', @@ -31,12 +32,15 @@ export const DropdownButton = sveltify< dropdownRender, buttonsRender, setSlotParams, + value, ...props }) => { const getPopupContainerFunction = useFunction(getPopupContainer); const dropdownRenderFunction = useFunction(dropdownRender); const buttonsRenderFunction = useFunction(buttonsRender); const buttonsRenderTargets = useTargets(children, 'buttonsRender'); + const targets = useTargets(children); + return ( - {children} + {targets.length > 0 ? ( + children + ) : ( + <> + {children} + {value} + + )} ); } diff --git a/frontend/antd/table/table.tsx b/frontend/antd/table/table.tsx index efef003b..e6768f92 100644 --- a/frontend/antd/table/table.tsx +++ b/frontend/antd/table/table.tsx @@ -70,7 +70,7 @@ export const Table = sveltify< const paginationConfig = getConfig(pagination); const paginationShowTotalFunction = useFunction(paginationConfig.showTotal); const rowClassNameFunction = useFunction(rowClassName); - const rowKeyFunction = useFunction(rowKey); + const rowKeyFunction = useFunction(rowKey, true); const supportShowSorterTooltipConfig = slots['showSorterTooltip.title'] || typeof showSorterTooltip === 'object'; const showSorterTooltipConfig = getConfig(showSorterTooltip); diff --git a/frontend/antd/tag/Index.svelte b/frontend/antd/tag/Index.svelte index eafaed74..3a40a567 100644 --- a/frontend/antd/tag/Index.svelte +++ b/frontend/antd/tag/Index.svelte @@ -69,12 +69,9 @@ {...$mergedProps.props} {...bindEvents($mergedProps)} slots={$slots} + value={$mergedProps.value} > - {#if $mergedProps._internal.layout} - - {:else} - {$mergedProps.value} - {/if} + {/await} {/if} diff --git a/frontend/antd/tag/checkable-tag/Index.svelte b/frontend/antd/tag/checkable-tag/Index.svelte index 5a20646a..a4287a95 100644 --- a/frontend/antd/tag/checkable-tag/Index.svelte +++ b/frontend/antd/tag/checkable-tag/Index.svelte @@ -74,16 +74,13 @@ {...$mergedProps.props} {...bindEvents($mergedProps)} slots={$slots} + label={$mergedProps.label} checked={$mergedProps.props.checked ?? $mergedProps.value} onValueChange={(checked) => { value = checked; }} > - {#if $mergedProps._internal.layout} - - {:else} - {$mergedProps.label} - {/if} + {/await} {/if} diff --git a/frontend/antd/tag/checkable-tag/tag.checkable-tag.tsx b/frontend/antd/tag/checkable-tag/tag.checkable-tag.tsx index 3410949c..98606e53 100644 --- a/frontend/antd/tag/checkable-tag/tag.checkable-tag.tsx +++ b/frontend/antd/tag/checkable-tag/tag.checkable-tag.tsx @@ -1,12 +1,15 @@ import { sveltify } from '@svelte-preprocess-react'; import React from 'react'; +import { useTargets } from '@utils/hooks/useTargets'; import { type GetProps, Tag as ATag } from 'antd'; export const CheckableTag = sveltify< GetProps & { onValueChange: (checked: boolean) => void; + label?: string; } ->(({ onChange, onValueChange, ...props }) => { +>(({ onChange, onValueChange, children, label, ...props }) => { + const targets = useTargets(children); return ( + > + {targets.length > 0 ? ( + children + ) : ( + <> + {children} + {label} + + )} + ); }); diff --git a/frontend/antd/tag/tag.tsx b/frontend/antd/tag/tag.tsx index 685e4667..f05c8a37 100644 --- a/frontend/antd/tag/tag.tsx +++ b/frontend/antd/tag/tag.tsx @@ -1,24 +1,34 @@ import { sveltify } from '@svelte-preprocess-react'; import { ReactSlot } from '@svelte-preprocess-react/react-slot'; import React from 'react'; +import { useTargets } from '@utils/hooks/useTargets'; import { type GetProps, Tag as ATag } from 'antd'; -export const Tag = sveltify, ['closeIcon', 'icon']>( - ({ slots, ...props }) => { - return ( - : props.icon} - closeIcon={ - slots.closeIcon ? ( - - ) : ( - props.closeIcon - ) - } - /> - ); - } -); +export const Tag = sveltify< + GetProps & { + value?: string; + }, + ['closeIcon', 'icon'] +>(({ slots, value, children, ...props }) => { + const targets = useTargets(children); + return ( + : props.icon} + closeIcon={ + slots.closeIcon ? : props.closeIcon + } + > + {targets.length > 0 ? ( + children + ) : ( + <> + {children} + {value} + + )} + + ); +}); export default Tag; diff --git a/frontend/antd/typography/typography.base.tsx b/frontend/antd/typography/typography.base.tsx index ef60ab6e..3d20a72a 100644 --- a/frontend/antd/typography/typography.base.tsx +++ b/frontend/antd/typography/typography.base.tsx @@ -3,14 +3,13 @@ import { ReactSlot } from '@svelte-preprocess-react/react-slot'; import type { SetSlotParams } from '@svelte-preprocess-react/slot'; import React, { useMemo } from 'react'; import { useSlotsChildren } from '@utils/hooks/useSlotsChildren'; +import { useTargets } from '@utils/hooks/useTargets'; import { omitUndefinedProps } from '@utils/omitUndefinedProps'; import { renderParamsSlot } from '@utils/renderParamsSlot'; import { type GetProps, Typography } from 'antd'; import type { EllipsisConfig } from 'antd/es/typography/Base'; import cls from 'classnames'; -import { useTargets } from '../../utils/hooks/useTargets'; - function getConfig(value: T): Partial> { if (typeof value === 'object' && value !== null) { return value as any; @@ -83,6 +82,7 @@ export const TypographyBase = sveltify< } }, [component]); const [slotsChildren, restChildren] = useSlotsChildren(children); + const targets = useTargets(children); return ( <>
{slotsChildren}
@@ -103,7 +103,7 @@ export const TypographyBase = sveltify< icon: copyableIconTargets.length > 0 ? copyableIconTargets.map((slot, index) => { - return ; + return ; }) : copyableConfig.icon, }) @@ -114,7 +114,7 @@ export const TypographyBase = sveltify< ? { ...editableConfig, icon: slots['editable.icon'] ? ( - + ) : ( editableConfig.icon ), @@ -163,7 +163,7 @@ export const TypographyBase = sveltify< : undefined) as boolean } > - {restChildren} + {targets.length > 0 ? restChildren : <>{value}} );