From 8489c5b4a6d413c912743b7ea9392203969a5832 Mon Sep 17 00:00:00 2001 From: Col0ring <1561999073@qq.com> Date: Fri, 17 Jan 2025 18:13:10 +0800 Subject: [PATCH] fix: foceClone --- .../antd/list/demos/vertical_item.py | 34 ++++++------ docs/components/antd/table/demos/basic.py | 13 +++-- .../antd/table/demos/custom_columns.py | 33 +++++------ .../antd/table/demos/expandable_row.py | 24 ++++---- .../antd/table/demos/order_specific_column.py | 32 ++++++----- .../components/antd/table/demos/pagination.py | 17 +++--- docs/components/antd/table/demos/selection.py | 55 ++++++++++--------- docs/components/base/each/demos/basic.py | 7 ++- .../components/base/each/demos/use_as_item.py | 11 ++-- .../base/each/demos/use_context_value.py | 14 +++-- docs/components/base/filter/demos/basic.py | 17 +++--- .../base/filter/demos/use_as_item.py | 11 ++-- .../base/filter/demos/use_params_mapping.py | 17 +++--- frontend/antd/list/list.tsx | 7 ++- frontend/base/filter/filter.tsx | 3 +- .../internal/BridgeContext.tsx | 2 +- .../svelte-preprocess-react/react-slot.tsx | 2 +- 17 files changed, 161 insertions(+), 138 deletions(-) diff --git a/docs/components/antd/list/demos/vertical_item.py b/docs/components/antd/list/demos/vertical_item.py index 6a9f8f51..7ec8066a 100644 --- a/docs/components/antd/list/demos/vertical_item.py +++ b/docs/components/antd/list/demos/vertical_item.py @@ -3,12 +3,17 @@ import modelscope_studio.components.base as ms data = [{ - 'avatar': - f'https://api.dicebear.com/7.x/miniavs/svg?seed={i}', + 'avatar': { + "src": f'https://api.dicebear.com/7.x/miniavs/svg?seed={i}' + }, "link": { "href": "https://ant.design", "value": f"ant design part {i}" }, + "img": { + "src": + "https://gw.alipayobjects.com/zos/rmsportal/mqaQswcyDLcXyDKnZfES.png" + }, "meta": { 'description': 'Ant Design, a design language for background applications, is refined by Ant UED Team.', @@ -26,41 +31,36 @@ def IconText(icon: str, text: str): ms.Text(text) -def on_pagination_change(e: gr.EventData): - current = e._data["payload"][0] - return gr.update(value=data[(current - 1) * 3:current * 3]) - - with gr.Blocks() as demo: with ms.Application(): with antd.ConfigProvider(): with antd.List(item_layout="vertical", size="large", + data_source=data, pagination=dict(total=len(data), pageSize=page_size)) as list: with ms.Slot("footer"): with ms.Div(): antd.Typography.Text('ant design', strong=True) ms.Text("footer part") - with ms.Each(value=data[0:3]) as list_items: + with ms.Slot("renderItem", + params_mapping="""(item) => item"""): with antd.List.Item(): with ms.Slot("actions"): IconText('StarOutlined', 156) IconText('LikeOutlined', 156) - IconText('MessageOutlined', 2) + IconText('MessageOutlined', 3) with ms.Slot("extra"): - antd.Image( - "https://gw.alipayobjects.com/zos/rmsportal/mqaQswcyDLcXyDKnZfES.png", - preview=False, - alt="logo", - width=272) + antd.Image(preview=False, + alt="logo", + width=272, + as_item="img") with antd.List.Item.Meta(as_item="meta"): with ms.Slot("avatar"): antd.Avatar(as_item="avatar") with ms.Slot("title"): antd.Typography.Link(as_item="link") - ms.Text(as_item="content") - list.pagination_change(fn=on_pagination_change, - outputs=[list_items]) + ms.Span(as_item="content") + if __name__ == "__main__": demo.queue().launch() diff --git a/docs/components/antd/table/demos/basic.py b/docs/components/antd/table/demos/basic.py index 05ce0368..c98060fc 100644 --- a/docs/components/antd/table/demos/basic.py +++ b/docs/components/antd/table/demos/basic.py @@ -19,11 +19,12 @@ with gr.Blocks() as demo: with ms.Application(): - with antd.Table(data_source=data): - antd.Table.Column(title="Name", data_index="name", key="name") - antd.Table.Column(title="Age", data_index="age", key="age") - antd.Table.Column(title="Address", - data_index="address", - key="address") + with antd.ConfigProvider(): + with antd.Table(data_source=data): + antd.Table.Column(title="Name", data_index="name", key="name") + antd.Table.Column(title="Age", data_index="age", key="age") + antd.Table.Column(title="Address", + data_index="address", + key="address") if __name__ == "__main__": demo.queue().launch() diff --git a/docs/components/antd/table/demos/custom_columns.py b/docs/components/antd/table/demos/custom_columns.py index b6cdd72c..a115813e 100644 --- a/docs/components/antd/table/demos/custom_columns.py +++ b/docs/components/antd/table/demos/custom_columns.py @@ -29,22 +29,23 @@ def on_custom(e: gr.EventData): with gr.Blocks() as demo: with ms.Application() as app: - with antd.Table(data_source=data): - antd.Table.Column(title="Name", - data_index="name", - key="name", - column_render="""(text) => { + with antd.ConfigProvider(): + with antd.Table(data_source=data): + antd.Table.Column(title="Name", + data_index="name", + key="name", + column_render="""(text) => { const React = window.ms_globals.React; return React.createElement('a', null, text); }""") - antd.Table.Column(title="Age", data_index="age", key="age") - antd.Table.Column(title="Address", - data_index="address", - key="address") - antd.Table.Column(title="Tags", - data_index="tags", - key="tags", - column_render="""(_, { tags }) => { + antd.Table.Column(title="Age", data_index="age", key="age") + antd.Table.Column(title="Address", + data_index="address", + key="address") + antd.Table.Column(title="Tags", + data_index="tags", + key="tags", + column_render="""(_, { tags }) => { const React = window.ms_globals.React; const antd = window.ms_globals.antd; return tags.map((tag) => { @@ -55,9 +56,9 @@ def on_custom(e: gr.EventData): return React.createElement(antd.Tag, { color, key: tag }, tag.toUpperCase()); }); }""") - antd.Table.Column(title="Action", - key="action", - column_render="""(_, record) => { + antd.Table.Column(title="Action", + key="action", + column_render="""(_, record) => { const React = window.ms_globals.React; const antd = window.ms_globals.antd; const dispatch = window.ms_globals.dispatch; diff --git a/docs/components/antd/table/demos/expandable_row.py b/docs/components/antd/table/demos/expandable_row.py index 30278cf0..7b1682db 100644 --- a/docs/components/antd/table/demos/expandable_row.py +++ b/docs/components/antd/table/demos/expandable_row.py @@ -45,16 +45,18 @@ with gr.Blocks() as demo: with ms.Application(): - with antd.Table(data_source=data): - with ms.Slot("expandable"): - antd.Table.Expandable( - expanded_row_render="""(record) => record.description""", - row_expandable= - """(record) => record.name !== 'Not Expandable'""") - antd.Table.Column(title="Name", data_index="name", key="name") - antd.Table.Column(title="Age", data_index="age", key="age") - antd.Table.Column(title="Address", - data_index="address", - key="address") + with antd.ConfigProvider(): + with antd.Table(data_source=data): + with ms.Slot("expandable"): + antd.Table.Expandable( + expanded_row_render= + """(record) => record.description""", + row_expandable= + """(record) => record.name !== 'Not Expandable'""") + antd.Table.Column(title="Name", data_index="name", key="name") + antd.Table.Column(title="Age", data_index="age", key="age") + antd.Table.Column(title="Address", + data_index="address", + key="address") if __name__ == "__main__": demo.queue().launch() diff --git a/docs/components/antd/table/demos/order_specific_column.py b/docs/components/antd/table/demos/order_specific_column.py index 8d86de44..9e69ed45 100644 --- a/docs/components/antd/table/demos/order_specific_column.py +++ b/docs/components/antd/table/demos/order_specific_column.py @@ -45,20 +45,22 @@ with gr.Blocks() as demo: with ms.Application(): - with antd.Table(data_source=data): - with ms.Slot("rowSelection"): - selection = antd.Table.RowSelection() - with ms.Slot("expandable"): - antd.Table.Expandable( - expanded_row_render="""(record) => record.description""", - row_expandable= - """(record) => record.name !== 'Not Expandable'""") - antd.Table.Column(title="Name", data_index="name", key="name") - antd.Table.Column(built_in_column="EXPAND_COLUMN") - antd.Table.Column(title="Age", data_index="age", key="age") - antd.Table.Column(built_in_column="SELECTION_COLUMN") - antd.Table.Column(title="Address", - data_index="address", - key="address") + with antd.ConfigProvider(): + with antd.Table(data_source=data): + with ms.Slot("rowSelection"): + selection = antd.Table.RowSelection() + with ms.Slot("expandable"): + antd.Table.Expandable( + expanded_row_render= + """(record) => record.description""", + row_expandable= + """(record) => record.name !== 'Not Expandable'""") + antd.Table.Column(title="Name", data_index="name", key="name") + antd.Table.Column(built_in_column="EXPAND_COLUMN") + antd.Table.Column(title="Age", data_index="age", key="age") + antd.Table.Column(built_in_column="SELECTION_COLUMN") + antd.Table.Column(title="Address", + data_index="address", + key="address") if __name__ == "__main__": demo.queue().launch() diff --git a/docs/components/antd/table/demos/pagination.py b/docs/components/antd/table/demos/pagination.py index 98c669c6..2e6b5eef 100644 --- a/docs/components/antd/table/demos/pagination.py +++ b/docs/components/antd/table/demos/pagination.py @@ -16,13 +16,14 @@ def on_change(e: gr.EventData): with gr.Blocks() as demo: with ms.Application(): - with antd.Table(data_source=data, - pagination=dict(pageSize=4)) as table: - antd.Table.Column(title="Name", data_index="name", key="name") - antd.Table.Column(title="Age", data_index="age", key="age") - antd.Table.Column(title="Address", - data_index="address", - key="address") - table.change(fn=on_change) + with antd.ConfigProvider(): + with antd.Table(data_source=data, + pagination=dict(pageSize=4)) as table: + antd.Table.Column(title="Name", data_index="name", key="name") + antd.Table.Column(title="Age", data_index="age", key="age") + antd.Table.Column(title="Address", + data_index="address", + key="address") + table.change(fn=on_change) if __name__ == "__main__": demo.queue().launch() diff --git a/docs/components/antd/table/demos/selection.py b/docs/components/antd/table/demos/selection.py index 195df5d5..173a9891 100644 --- a/docs/components/antd/table/demos/selection.py +++ b/docs/components/antd/table/demos/selection.py @@ -24,32 +24,33 @@ def on_selection_change(e: gr.EventData): with gr.Blocks() as demo: with ms.Application(): - with antd.Table(data_source=data): - # add selection config - with ms.Slot("rowSelection"): - selection = antd.Table.RowSelection() - antd.Table.Column(title="Name", data_index="name", key="name") - antd.Table.Column(title="Age", data_index="age", key="age") - antd.Table.Column(title="Address", - data_index="address", - key="address") - selection.change(on_selection_change) - antd.Divider("Custom selection") - with antd.Table(data_source=data): - # add selection config - with ms.Slot("rowSelection"): - with antd.Table.RowSelection(): - with ms.Slot("selections"): - antd.Table.RowSelection.Selection( - built_in_selection='SELECT_ALL') - antd.Table.RowSelection.Selection( - built_in_selection='SELECT_INVERT') - antd.Table.RowSelection.Selection( - built_in_selection='SELECT_NONE') - antd.Table.Column(title="Name", data_index="name", key="name") - antd.Table.Column(title="Age", data_index="age", key="age") - antd.Table.Column(title="Address", - data_index="address", - key="address") + with antd.ConfigProvider(): + with antd.Table(data_source=data): + # add selection config + with ms.Slot("rowSelection"): + selection = antd.Table.RowSelection() + antd.Table.Column(title="Name", data_index="name", key="name") + antd.Table.Column(title="Age", data_index="age", key="age") + antd.Table.Column(title="Address", + data_index="address", + key="address") + selection.change(on_selection_change) + antd.Divider("Custom selection") + with antd.Table(data_source=data): + # add selection config + with ms.Slot("rowSelection"): + with antd.Table.RowSelection(): + with ms.Slot("selections"): + antd.Table.RowSelection.Selection( + built_in_selection='SELECT_ALL') + antd.Table.RowSelection.Selection( + built_in_selection='SELECT_INVERT') + antd.Table.RowSelection.Selection( + built_in_selection='SELECT_NONE') + antd.Table.Column(title="Name", data_index="name", key="name") + antd.Table.Column(title="Age", data_index="age", key="age") + antd.Table.Column(title="Address", + data_index="address", + key="address") if __name__ == "__main__": demo.queue().launch() diff --git a/docs/components/base/each/demos/basic.py b/docs/components/base/each/demos/basic.py index d0f608f5..da9d8c0d 100644 --- a/docs/components/base/each/demos/basic.py +++ b/docs/components/base/each/demos/basic.py @@ -26,9 +26,10 @@ with gr.Blocks() as demo: with ms.Application(): - with antd.Space(direction="vertical"): - with ms.Each(value=data): - antd.Alert() + with antd.ConfigProvider(): + with antd.Space(direction="vertical"): + with ms.Each(value=data): + antd.Alert() if __name__ == "__main__": demo.queue().launch() diff --git a/docs/components/base/each/demos/use_as_item.py b/docs/components/base/each/demos/use_as_item.py index 4a94d7a3..e808ad4e 100644 --- a/docs/components/base/each/demos/use_as_item.py +++ b/docs/components/base/each/demos/use_as_item.py @@ -58,11 +58,12 @@ with gr.Blocks() as demo: with ms.Application(): - with ms.Each(value=data): - with antd.Card(as_item="card"): - # Inner loop - with ms.Each(as_item="each"): - antd.Typography.Paragraph() + with antd.ConfigProvider(): + with ms.Each(value=data): + with antd.Card(as_item="card"): + # Inner loop + with ms.Each(as_item="each"): + antd.Typography.Paragraph() if __name__ == "__main__": demo.queue().launch() diff --git a/docs/components/base/each/demos/use_context_value.py b/docs/components/base/each/demos/use_context_value.py index 3024392f..ccd87c7f 100644 --- a/docs/components/base/each/demos/use_context_value.py +++ b/docs/components/base/each/demos/use_context_value.py @@ -58,11 +58,15 @@ with gr.Blocks() as demo: with ms.Application(): - with ms.Each(value=data, context_value={"card": {"hoverable": True}}): - with antd.Card(as_item="card"): - # Inner loop - with ms.Each(as_item="each"): - antd.Typography.Paragraph() + with antd.ConfigProvider(): + with ms.Each(value=data, + context_value={"card": { + "hoverable": True + }}): + with antd.Card(as_item="card"): + # Inner loop + with ms.Each(as_item="each"): + antd.Typography.Paragraph() if __name__ == "__main__": demo.queue().launch() diff --git a/docs/components/base/filter/demos/basic.py b/docs/components/base/filter/demos/basic.py index ce807d45..9e460843 100644 --- a/docs/components/base/filter/demos/basic.py +++ b/docs/components/base/filter/demos/basic.py @@ -6,14 +6,15 @@ with gr.Blocks() as demo: with ms.Application(): - with antd.Space(direction="vertical"): - antd.Divider("Without Filter") - with ms.Each(value=data): - antd.Button() - antd.Divider("With Filter") - with ms.Each(value=data): - with ms.Filter(): - antd.Button("Run") + with antd.ConfigProvider(): + with antd.Space(direction="vertical"): + antd.Divider("Without Filter") + with ms.Each(value=data): + antd.Button() + antd.Divider("With Filter") + with ms.Each(value=data): + with ms.Filter(): + antd.Button("Run") if __name__ == "__main__": demo.queue().launch() diff --git a/docs/components/base/filter/demos/use_as_item.py b/docs/components/base/filter/demos/use_as_item.py index 5e87ac02..6257d708 100644 --- a/docs/components/base/filter/demos/use_as_item.py +++ b/docs/components/base/filter/demos/use_as_item.py @@ -16,11 +16,12 @@ with gr.Blocks() as demo: with ms.Application(): - with antd.Space(direction="vertical"): - with ms.Each(value=data): - with antd.Card(): - with ms.Filter(as_item="btn"): - antd.Button() + with antd.ConfigProvider(): + with antd.Space(direction="vertical"): + with ms.Each(value=data): + with antd.Card(): + with ms.Filter(as_item="btn"): + antd.Button() if __name__ == "__main__": demo.queue().launch() diff --git a/docs/components/base/filter/demos/use_params_mapping.py b/docs/components/base/filter/demos/use_params_mapping.py index 1a4300b2..9f87e9ec 100644 --- a/docs/components/base/filter/demos/use_params_mapping.py +++ b/docs/components/base/filter/demos/use_params_mapping.py @@ -12,14 +12,15 @@ with gr.Blocks() as demo: with ms.Application(): - with antd.Space(direction="vertical"): - with ms.Each(value=data): - with antd.Card(): - with ms.Filter( - params_mapping= - """(props) => ({ value: props.desc, type: props.desc === 'World' ? 'primary' : 'default' })""" - ): - antd.Button() + with antd.ConfigProvider(): + with antd.Space(direction="vertical"): + with ms.Each(value=data): + with antd.Card(): + with ms.Filter( + params_mapping= + """(props) => ({ value: props.desc, type: props.desc === 'World' ? 'primary' : 'default' })""" + ): + antd.Button() if __name__ == "__main__": demo.queue().launch() diff --git a/frontend/antd/list/list.tsx b/frontend/antd/list/list.tsx index 1b8e79bd..920635c7 100644 --- a/frontend/antd/list/list.tsx +++ b/frontend/antd/list/list.tsx @@ -23,7 +23,12 @@ export const List = sveltify< } renderItem={ slots.renderItem - ? renderParamsSlot({ slots, setSlotParams, key: 'renderItem' }) + ? renderParamsSlot( + { slots, setSlotParams, key: 'renderItem' }, + { + forceClone: true, + } + ) : renderItemFunction } /> diff --git a/frontend/base/filter/filter.tsx b/frontend/base/filter/filter.tsx index 5fd05464..38077bb8 100644 --- a/frontend/base/filter/filter.tsx +++ b/frontend/base/filter/filter.tsx @@ -21,8 +21,9 @@ export const Filter = sveltify( if (paramsMappingFn) { setFilteredContext(paramsMappingFn(ctx)); } else if (asItem) { - setFilteredContext(ctx); + setFilteredContext(ctx?.[asItem]); } + // else undefined }, [asItem, ctx, paramsMappingFn]); return ( diff --git a/frontend/svelte-preprocess-react/internal/BridgeContext.tsx b/frontend/svelte-preprocess-react/internal/BridgeContext.tsx index 5ed7ee81..5194703e 100644 --- a/frontend/svelte-preprocess-react/internal/BridgeContext.tsx +++ b/frontend/svelte-preprocess-react/internal/BridgeContext.tsx @@ -36,7 +36,7 @@ export const BridgeContext: React.FC = ({ let ctxValue = ctx; const merged_as_item = ctx?.as_item ?? as_item; - + // The first element in the context will be computed once for slotParamsMapping. const originalRestProps = { ...ensureObjectCtxValue(ctxValue), ...ensureObjectCtxValue(value), diff --git a/frontend/svelte-preprocess-react/react-slot.tsx b/frontend/svelte-preprocess-react/react-slot.tsx index 1332c373..9a313078 100644 --- a/frontend/svelte-preprocess-react/react-slot.tsx +++ b/frontend/svelte-preprocess-react/react-slot.tsx @@ -153,7 +153,7 @@ export const ReactSlot = forwardRef( return portals.length > 0; } const hasPortal = render(); - if (!hasPortal) { + if (!hasPortal || forceClone) { observer = new window.MutationObserver(() => { const _hasPortal = render(); if (_hasPortal) {