diff --git a/packages/core/client/src/schema-settings/GeneralSchemaDesigner.tsx b/packages/core/client/src/schema-settings/GeneralSchemaDesigner.tsx index 92fd8b253d..68a5fddbb9 100644 --- a/packages/core/client/src/schema-settings/GeneralSchemaDesigner.tsx +++ b/packages/core/client/src/schema-settings/GeneralSchemaDesigner.tsx @@ -216,9 +216,8 @@ const InternalSchemaToolbar: FC = (props) => { ...props, ...(fieldSchema?.['x-toolbar-props'] || {}), } as SchemaToolbarProps; - const { designable } = useDesignable(); const compile = useCompile(); - const { styles } = useStyles(); + const { componentCls, hashId } = useStyles(); const { t } = useTranslation(); const { getAriaLabel } = useGetAriaLabelOfDesigner(); const dm = useDataSourceManager(); @@ -229,8 +228,9 @@ const InternalSchemaToolbar: FC = (props) => { const titleArr = useMemo(() => { if (!title) return undefined; if (typeof title === 'string') return [compile(title)]; - if (Array.isArray(title)) return title.map((item) => compile(item)); - }, [compile, title]); + if (Array.isArray(title)) return compile(title); + }, [title]); + const { render: schemaSettingsRender, exists: schemaSettingsExists } = useSchemaSettingsRender( settings || fieldSchema?.['x-settings'], fieldSchema?.['x-settings-props'], @@ -282,9 +282,7 @@ const InternalSchemaToolbar: FC = (props) => { const settingsElement = useMemo(() => { return settings !== false && schemaSettingsExists ? schemaSettingsRender() : null; }, [schemaSettingsExists, schemaSettingsRender, settings]); - const toolbarRef = useRef(null); - useEffect(() => { const toolbarElement = toolbarRef.current; let parentElement = toolbarElement?.parentElement; @@ -314,38 +312,33 @@ const InternalSchemaToolbar: FC = (props) => { parentElement.addEventListener('mouseenter', show); parentElement.addEventListener('mouseleave', hide); - return () => { parentElement.removeEventListener('mouseenter', show); parentElement.removeEventListener('mouseleave', hide); }; }, []); - if (!designable) { - return null; - } - return (
{titleArr && ( -
+
- + {dataSource ? `${compile(dataSource?.displayName)} > ${titleArr[0]}` : titleArr[0]} {titleArr[1] && ( - + {`${t('Reference template')}: ${`${titleArr[1]}` || t('Untitled')}`} )}
)} -
+
{dragElement} {initializerElement} diff --git a/packages/core/client/src/schema-settings/styles.ts b/packages/core/client/src/schema-settings/styles.ts index f052a77a69..5ba5dc451d 100644 --- a/packages/core/client/src/schema-settings/styles.ts +++ b/packages/core/client/src/schema-settings/styles.ts @@ -7,11 +7,13 @@ * For more information, please refer to: https://www.nocobase.com/agreement. */ -import { createStyles } from 'antd-style'; +import { genStyleHook } from '../schema-component/antd/__builtins__/style'; + +export const useStyles = genStyleHook('nb-schema-toolbar', (token) => { + const { componentCls } = token; -export const useStyles = createStyles(() => { return { - toolbar: { + [componentCls]: { position: 'absolute', zIndex: 999, display: 'none', @@ -26,39 +28,40 @@ export const useStyles = createStyles(() => { '.ant-space-item .anticon': { margin: 0, }, - }, - toolbarTitle: { - pointerEvents: 'none', - position: 'absolute', - fontSize: 12, - padding: 0, - lineHeight: '16px', - height: '16px', - borderBottomRightRadius: 2, - borderRadius: 2, - top: 2, - left: 2, - }, - toolbarTitleTag: { - padding: '0 3px', - borderRadius: 2, - background: 'var(--colorSettings)', - color: '#fff', - display: 'block', - }, - toolbarIcons: { - position: 'absolute', - right: '2px', - top: '2px', - lineHeight: '16px', - pointerEvents: 'all', - '.ant-space-item': { - backgroundColor: 'var(--colorSettings)', - color: '#fff', + + '.toolbar-title': { + pointerEvents: 'none', + position: 'absolute', + fontSize: 12, + padding: 0, lineHeight: '16px', - width: '16px', - paddingLeft: '1px', - alignSelf: 'stretch', + height: '16px', + borderBottomRightRadius: 2, + borderRadius: 2, + top: 2, + left: 2, + }, + '.toolbar-title-tag': { + padding: '0 3px', + borderRadius: 2, + background: 'var(--colorSettings)', + color: '#fff', + display: 'block', + }, + '.toolbar-icons': { + position: 'absolute', + right: '2px', + top: '2px', + lineHeight: '16px', + pointerEvents: 'all', + '.ant-space-item': { + backgroundColor: 'var(--colorSettings)', + color: '#fff', + lineHeight: '16px', + width: '16px', + paddingLeft: '1px', + alignSelf: 'stretch', + }, }, }, };