/* * Copyright 2025 coze-dev Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import React, { useState, type ComponentProps } from 'react'; import { ImageRender } from '@coze-common/table-view'; import { I18n } from '@coze-arch/i18n'; import { ColumnType } from '@coze-arch/bot-api/memory'; import { IconCozImage } from '@coze-arch/coze-design/icons'; import { TextArea, Button, Modal } from '@coze-arch/coze-design'; import { type TableDataItem } from './hooks'; import styles from './index.module.less'; export interface TableSegmentModalProps extends ComponentProps { tableData: TableDataItem[]; canEdit: boolean; handleTextAreaChange: (index: number, value: string) => void; onCancel: (e: React.MouseEvent) => void; onSubmit: () => void; loading?: boolean; } interface RenderFooterProps { loading?: boolean; onCancel: (e: React.MouseEvent) => void; onSubmit: (e: React.MouseEvent) => void; } interface TableColumn { key: string; title: string; render?: (item: TableDataItem, index: number) => React.ReactNode; } interface TableSegmentContentProps { columns: TableColumn[]; tableData: TableDataItem[]; canEdit: boolean; handleTextAreaChange: (index: number, value: string) => void; } export const getSrcFromImg = (str: string): string[] => { if (!str) { return []; } const imgRegx = /]+src\s*=\s*['"]([^'"]+)['"][^>]*>/g; // Matching using regular expressions const matches = str.match(imgRegx); // Extract the value of the src attribute from the matching result const srcList: string[] = []; if (matches) { for (const match of matches) { const src = match.match(/src\s*=\s*['"]([^'"]+)['"]/)?.[1]; if (src) { srcList.push(src); } } } return srcList; }; const TableSegmentContent: React.FC = ({ columns, tableData, canEdit, }) => (
{columns.map(column => (
{column.title}
))}
{tableData.map((item, index) => (
{columns.map(column => (
{typeof column.render === 'function' ? column.render(item, index) : item[column.key as keyof TableDataItem]}
))}
))}
); const RenderFooter: React.FC = ({ ...modalProps }) => ( <> ); const OptimizedTextArea: React.FC<{ index: number; value?: string; disabled: boolean; error?: string; handleTextAreaChange: (index: number, value: string) => void; }> = React.memo( ({ index, disabled, error, value: initialValue, handleTextAreaChange }) => { const [value, setValue] = useState(initialValue); const onBlur = () => handleTextAreaChange(index, value || ''); return (