feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@coze-arch/stylelint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: [],
|
||||
});
|
||||
16
frontend/packages/foundation/global-adapter/README.md
Normal file
16
frontend/packages/foundation/global-adapter/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# @flow-foundation/global
|
||||
|
||||
> Project template for react component with storybook.
|
||||
|
||||
## Features
|
||||
|
||||
- [x] eslint & ts
|
||||
- [x] esm bundle
|
||||
- [x] umd bundle
|
||||
- [x] storybook
|
||||
|
||||
## Commands
|
||||
|
||||
- init: `rush update`
|
||||
- dev: `npm run dev`
|
||||
- build: `npm run build`
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
packageRoot: __dirname,
|
||||
preset: 'web',
|
||||
rules: {},
|
||||
});
|
||||
77
frontend/packages/foundation/global-adapter/package.json
Normal file
77
frontend/packages/foundation/global-adapter/package.json
Normal file
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"name": "@coze-foundation/global-adapter",
|
||||
"version": "0.0.1",
|
||||
"description": "应用的全局初始化逻辑",
|
||||
"license": "Apache-2.0",
|
||||
"author": "sunzhiyuan.evan@bytedance.com",
|
||||
"maintainers": [],
|
||||
"exports": {
|
||||
".": "./src/index.tsx",
|
||||
"./account-settings": "./src/components/account-dropdown/account-settings/index.tsx"
|
||||
},
|
||||
"main": "src/index.tsx",
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
".": [
|
||||
"./src/index.tsx"
|
||||
],
|
||||
"account-settings": [
|
||||
"./src/components/account-dropdown/account-settings/index.tsx"
|
||||
]
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "exit 0",
|
||||
"lint": "eslint ./ --cache",
|
||||
"test": "vitest --run --passWithNoTests",
|
||||
"test:cov": "npm run test -- --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@coze-agent-ide/space-bot": "workspace:*",
|
||||
"@coze-arch/bot-error": "workspace:*",
|
||||
"@coze-arch/bot-hooks": "workspace:*",
|
||||
"@coze-arch/bot-semi": "workspace:*",
|
||||
"@coze-arch/bot-studio-store": "workspace:*",
|
||||
"@coze-arch/bot-utils": "workspace:*",
|
||||
"@coze-arch/coze-design": "0.0.6-alpha.346d77",
|
||||
"@coze-arch/foundation-sdk": "workspace:*",
|
||||
"@coze-arch/i18n": "workspace:*",
|
||||
"@coze-arch/idl": "workspace:*",
|
||||
"@coze-arch/logger": "workspace:*",
|
||||
"@coze-foundation/account-adapter": "workspace:*",
|
||||
"@coze-foundation/account-ui-adapter": "workspace:*",
|
||||
"@coze-foundation/account-ui-base": "workspace:*",
|
||||
"@coze-foundation/browser-upgrade-banner": "workspace:*",
|
||||
"@coze-foundation/global": "workspace:*",
|
||||
"@coze-foundation/global-store": "workspace:*",
|
||||
"@coze-foundation/layout": "workspace:*",
|
||||
"@coze-studio/default-slardar": "workspace:*",
|
||||
"@coze-studio/open-auth": "workspace:*",
|
||||
"@coze-studio/user-store": "workspace:*",
|
||||
"ahooks": "^3.7.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@coze-arch/bot-typings": "workspace:*",
|
||||
"@coze-arch/eslint-config": "workspace:*",
|
||||
"@coze-arch/stylelint-config": "workspace:*",
|
||||
"@coze-arch/ts-config": "workspace:*",
|
||||
"@coze-arch/vitest-config": "workspace:*",
|
||||
"@testing-library/jest-dom": "^6.1.5",
|
||||
"@testing-library/react": "^14.1.2",
|
||||
"@testing-library/react-hooks": "^8.0.1",
|
||||
"@types/react": "18.2.37",
|
||||
"@types/react-dom": "18.2.15",
|
||||
"@vitest/coverage-v8": "~3.0.5",
|
||||
"react": "~18.2.0",
|
||||
"react-dom": "~18.2.0",
|
||||
"react-router-dom": "^6.22.0",
|
||||
"stylelint": "^15.11.0",
|
||||
"vite-plugin-svgr": "~3.3.0",
|
||||
"vitest": "~3.0.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18.2.0",
|
||||
"react-dom": ">=18.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 { PatBody } from '@coze-studio/open-auth';
|
||||
import {
|
||||
useAccountSettings as useBaseAccountSettings,
|
||||
UserInfoPanel,
|
||||
} from '@coze-foundation/account-ui-base';
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
|
||||
export const useAccountSettings = () => {
|
||||
const tabs = [
|
||||
{
|
||||
id: 'account',
|
||||
tabName: I18n.t('menu_profile_account'),
|
||||
content: () => <UserInfoPanel />,
|
||||
},
|
||||
{
|
||||
id: 'api-auth',
|
||||
tabName: I18n.t('settings_api_authorization'),
|
||||
content: () => <PatBody size="small" type="primary" />,
|
||||
},
|
||||
];
|
||||
|
||||
const { node, open } = useBaseAccountSettings({
|
||||
tabs,
|
||||
});
|
||||
return {
|
||||
node,
|
||||
open,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 { useState } from 'react';
|
||||
|
||||
import { GlobalLayoutAccountDropdown } from '@coze-foundation/layout';
|
||||
import { useLogout } from '@coze-foundation/account-ui-adapter';
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
import { useUserInfo } from '@coze-arch/foundation-sdk';
|
||||
import { IconCozExit, IconCozSetting } from '@coze-arch/coze-design/icons';
|
||||
import { Dropdown } from '@coze-arch/coze-design';
|
||||
|
||||
import { UserInfoMenu } from './user-info-menu';
|
||||
import { useAccountSettings } from './account-settings';
|
||||
|
||||
export const AccountDropdown = () => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const userInfo = useUserInfo();
|
||||
const { node: logoutModal, open: openLogoutModal } = useLogout();
|
||||
|
||||
const { node: accountSettingsNode, open: openAccountSettings } =
|
||||
useAccountSettings();
|
||||
|
||||
if (!userInfo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<GlobalLayoutAccountDropdown
|
||||
menus={[
|
||||
<UserInfoMenu />,
|
||||
<Dropdown.Divider />,
|
||||
{
|
||||
prefixIcon: <IconCozExit />,
|
||||
title: I18n.t('settings_api_authorization'),
|
||||
onClick: () => {
|
||||
openAccountSettings('api-auth');
|
||||
},
|
||||
dataTestId: 'layout_avatar_api-auth',
|
||||
},
|
||||
{
|
||||
prefixIcon: <IconCozSetting />,
|
||||
title: I18n.t('navi_bar_account_settings'),
|
||||
onClick: () => {
|
||||
openAccountSettings('account');
|
||||
},
|
||||
dataTestId: 'layout_avatar_profile-settings',
|
||||
},
|
||||
<Dropdown.Divider />,
|
||||
{
|
||||
prefixIcon: <IconCozExit />,
|
||||
title: I18n.t('basic_log_out'),
|
||||
onClick: () => {
|
||||
openLogoutModal();
|
||||
},
|
||||
dataTestId: 'layout_avatar_logout-button',
|
||||
},
|
||||
]}
|
||||
visible={visible}
|
||||
onVisibleChange={setVisible}
|
||||
>
|
||||
{logoutModal}
|
||||
{accountSettingsNode}
|
||||
</GlobalLayoutAccountDropdown>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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 { useUserInfo, useUserLabel } from '@coze-arch/foundation-sdk';
|
||||
import {
|
||||
CozAvatar,
|
||||
Badge,
|
||||
Dropdown,
|
||||
Space,
|
||||
Typography,
|
||||
Tooltip,
|
||||
} from '@coze-arch/coze-design';
|
||||
|
||||
const ellipsis = {
|
||||
showTooltip: true,
|
||||
};
|
||||
|
||||
export const UserInfoMenu = () => {
|
||||
const userInfo = useUserInfo();
|
||||
const userLabel = useUserLabel();
|
||||
|
||||
if (!userInfo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const userUniqueName = userInfo?.app_user_info?.user_unique_name;
|
||||
|
||||
return (
|
||||
<Dropdown.Item className="!h-fit">
|
||||
<div className="flex justify-between items-center w-full">
|
||||
<Space spacing={8} className="shrink grow overflow-hidden">
|
||||
{
|
||||
<Badge
|
||||
position="rightBottom"
|
||||
countStyle={{
|
||||
right: 6,
|
||||
bottom: 6,
|
||||
}}
|
||||
count={
|
||||
userLabel?.icon_url ? (
|
||||
<Tooltip
|
||||
showArrow
|
||||
position="right"
|
||||
content={userLabel?.label_name}
|
||||
trigger={userLabel?.label_name ? 'hover' : 'custom'}
|
||||
>
|
||||
<div className="bg-white rounded-full w-[16px] h-[16px] flex items-center justify-center">
|
||||
<CozAvatar
|
||||
src={userLabel?.icon_url}
|
||||
className="w-[12px] h-[12px] rounded-full"
|
||||
type="person"
|
||||
onClick={event => {
|
||||
if (userLabel?.jump_link) {
|
||||
event?.preventDefault();
|
||||
event?.stopPropagation();
|
||||
window.open(userLabel?.jump_link, '_blank');
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</Tooltip>
|
||||
) : null
|
||||
}
|
||||
className="shrink-0"
|
||||
>
|
||||
<CozAvatar
|
||||
src={userInfo.avatar_url}
|
||||
className="w-[32px] h-[32px] rounded-full"
|
||||
type="person"
|
||||
/>
|
||||
</Badge>
|
||||
}
|
||||
{
|
||||
<div className="flex-1 text-[14px] leading-[20px] overflow-hidden sp">
|
||||
<Typography.Text
|
||||
className="coz-fg-primary font-[500]"
|
||||
ellipsis={ellipsis}
|
||||
>
|
||||
{userInfo.name}
|
||||
</Typography.Text>
|
||||
<Typography.Text className="coz-fg-secondary" ellipsis={ellipsis}>
|
||||
{userUniqueName ? '@' : ''}
|
||||
{userUniqueName}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
}
|
||||
</Space>
|
||||
</div>
|
||||
</Dropdown.Item>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 { useLocation } from 'react-router-dom';
|
||||
|
||||
import { useIsLogined } from '@coze-arch/foundation-sdk';
|
||||
import { useRouteConfig } from '@coze-arch/bot-hooks';
|
||||
|
||||
export const useHasSider = () => {
|
||||
const config = useRouteConfig();
|
||||
const location = useLocation();
|
||||
const isLogined = useIsLogined();
|
||||
const queryParams = new URLSearchParams(location.search);
|
||||
const pageMode = queryParams.get('page_mode');
|
||||
|
||||
// 优先使用 page_mode 参数判断是否为全屏模式
|
||||
if (config.pageModeByQuery && pageMode === 'modal') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const notCheckLoginPage =
|
||||
(config.requireAuth && config.requireAuthOptional) || !config.requireAuth;
|
||||
// 未登录时也可访问的页面
|
||||
if (config.hasSider && notCheckLoginPage && !isLogined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !!config.hasSider;
|
||||
};
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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 { useParams } from 'react-router-dom';
|
||||
import { type FC, type PropsWithChildren } from 'react';
|
||||
|
||||
import { GlobalLayout } from '@coze-foundation/layout';
|
||||
import { useCreateBotAction } from '@coze-foundation/global';
|
||||
import { RequireAuthContainer } from '@coze-foundation/account-ui-adapter';
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
import { useRouteConfig } from '@coze-arch/bot-hooks';
|
||||
import {
|
||||
IconCozPlusCircle,
|
||||
IconCozWorkspace,
|
||||
IconCozWorkspaceFill,
|
||||
IconCozCompass,
|
||||
IconCozCompassFill,
|
||||
IconCozDocument,
|
||||
} from '@coze-arch/coze-design/icons';
|
||||
|
||||
import { AccountDropdown } from '../account-dropdown';
|
||||
import { useHasSider } from './hooks/use-has-sider';
|
||||
|
||||
export const GlobalLayoutComposed: FC<PropsWithChildren> = ({ children }) => {
|
||||
const config = useRouteConfig();
|
||||
const hasSider = useHasSider();
|
||||
const { space_id } = useParams();
|
||||
|
||||
const { createBot, createBotModal } = useCreateBotAction({
|
||||
currentSpaceId: space_id,
|
||||
});
|
||||
|
||||
return (
|
||||
<RequireAuthContainer
|
||||
needLogin={!!config.requireAuth}
|
||||
loginOptional={!!config.requireAuthOptional}
|
||||
>
|
||||
<GlobalLayout
|
||||
hasSider={hasSider}
|
||||
banner={null}
|
||||
actions={[
|
||||
{
|
||||
tooltip: I18n.t('creat_tooltip_create'),
|
||||
icon: <IconCozPlusCircle />,
|
||||
onClick: createBot,
|
||||
dataTestId: 'layout_create-agent-button',
|
||||
},
|
||||
]}
|
||||
menus={[
|
||||
{
|
||||
title: I18n.t('navigation_workspace'),
|
||||
icon: <IconCozWorkspace />,
|
||||
activeIcon: <IconCozWorkspaceFill />,
|
||||
path: '/space',
|
||||
dataTestId: 'layout_workspace-button',
|
||||
},
|
||||
{
|
||||
title: I18n.t('menu_title_store'),
|
||||
icon: <IconCozCompass />,
|
||||
activeIcon: <IconCozCompassFill />,
|
||||
path: '/explore',
|
||||
dataTestId: 'layout_explore-button',
|
||||
},
|
||||
]}
|
||||
extras={[
|
||||
{
|
||||
icon: <IconCozDocument />,
|
||||
tooltip: I18n.t('menu_documents'),
|
||||
onClick: () => {
|
||||
// cp-disable-next-line
|
||||
window.open('https://www.coze.cn/open/docs/guides');
|
||||
},
|
||||
dataTestId: 'layout_document-button',
|
||||
},
|
||||
]}
|
||||
footer={<AccountDropdown />}
|
||||
>
|
||||
{children}
|
||||
{createBotModal}
|
||||
</GlobalLayout>
|
||||
</RequireAuthContainer>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 { Outlet } from 'react-router-dom';
|
||||
import { type FC, useEffect } from 'react';
|
||||
|
||||
import { useUpdate } from 'ahooks';
|
||||
import { BrowserUpgradeWrap } from '@coze-foundation/browser-upgrade-banner';
|
||||
import { I18nProvider } from '@coze-arch/i18n/i18n-provider';
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
import { useUserInfo } from '@coze-arch/foundation-sdk';
|
||||
import { zh_CN, en_US } from '@coze-arch/coze-design/locales';
|
||||
import {
|
||||
CDLocaleProvider,
|
||||
ThemeProvider,
|
||||
enUS,
|
||||
zhCN,
|
||||
} from '@coze-arch/coze-design';
|
||||
import { LocaleProvider } from '@coze-arch/bot-semi';
|
||||
|
||||
import { GlobalLayoutComposed } from '@/components/global-layout-composed';
|
||||
|
||||
export const GlobalLayout: FC = () => {
|
||||
const userInfo = useUserInfo();
|
||||
const update = useUpdate();
|
||||
const currentLocale = userInfo?.locale ?? navigator.language ?? 'en-US';
|
||||
|
||||
// 历史原因,en-US 需要被转换为 en
|
||||
const transformedCurrentLocale =
|
||||
currentLocale === 'en-US' ? 'en' : currentLocale;
|
||||
|
||||
useEffect(() => {
|
||||
if (userInfo && I18n.language !== transformedCurrentLocale) {
|
||||
localStorage.setItem('i18next', transformedCurrentLocale);
|
||||
I18n.setLang(transformedCurrentLocale);
|
||||
// 强制更新,否则切换语言不生效
|
||||
update();
|
||||
}
|
||||
}, [userInfo, transformedCurrentLocale, update]);
|
||||
|
||||
return (
|
||||
<I18nProvider i18n={I18n}>
|
||||
<CDLocaleProvider locale={currentLocale === 'en-US' ? en_US : zh_CN}>
|
||||
<LocaleProvider locale={currentLocale === 'en-US' ? enUS : zhCN}>
|
||||
<ThemeProvider
|
||||
defaultTheme="light"
|
||||
changeSemiTheme={true}
|
||||
changeBySystem={IS_BOE}
|
||||
>
|
||||
<BrowserUpgradeWrap>
|
||||
<GlobalLayoutComposed>
|
||||
<Outlet />
|
||||
</GlobalLayoutComposed>
|
||||
</BrowserUpgradeWrap>
|
||||
</ThemeProvider>
|
||||
</LocaleProvider>
|
||||
</CDLocaleProvider>
|
||||
</I18nProvider>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 { useEffect } from 'react';
|
||||
|
||||
import { reporter, logger } from '@coze-arch/logger';
|
||||
import { useRouteConfig } from '@coze-arch/bot-hooks';
|
||||
import { useErrorCatch } from '@coze-arch/bot-error';
|
||||
import slardar from '@coze-studio/default-slardar';
|
||||
import { useAlertOnLogout } from '@coze-foundation/global/use-app-init';
|
||||
import {
|
||||
useSyncLocalStorageUid,
|
||||
useCheckLogin,
|
||||
} from '@coze-foundation/account-adapter';
|
||||
|
||||
import { useSetResponsiveBodyStyle } from './use-responsive-body-style';
|
||||
import { useResetStoreOnLogout } from './use-reset-store-on-logout';
|
||||
import { useInitCommonConfig } from './use-init-common-config';
|
||||
|
||||
/**
|
||||
* 所有初始化的逻辑收敛到这里
|
||||
* 注意登录态需要自行处理
|
||||
*/
|
||||
export const useAppInit = () => {
|
||||
const { requireAuth, requireAuthOptional, loginFallbackPath } =
|
||||
useRouteConfig();
|
||||
|
||||
useCheckLogin({
|
||||
needLogin: !!(requireAuth && !requireAuthOptional),
|
||||
loginFallbackPath,
|
||||
});
|
||||
|
||||
useSyncLocalStorageUid();
|
||||
|
||||
useEffect(() => {
|
||||
reporter.info({ message: 'Ok fine' });
|
||||
reporter.init(slardar);
|
||||
logger.init(slardar);
|
||||
}, []);
|
||||
|
||||
useErrorCatch(slardar);
|
||||
|
||||
useInitCommonConfig();
|
||||
|
||||
useResetStoreOnLogout();
|
||||
|
||||
useSetResponsiveBodyStyle();
|
||||
|
||||
useAlertOnLogout();
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file 社区版暂不支持后台配置,用于未来拓展
|
||||
*/
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { useCommonConfigStore } from '@coze-foundation/global-store';
|
||||
|
||||
export const useInitCommonConfig = () => {
|
||||
const setInitialized = useCommonConfigStore(state => state.setInitialized);
|
||||
|
||||
useEffect(() => {
|
||||
setInitialized();
|
||||
}, []);
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 { useEffect } from 'react';
|
||||
|
||||
import { userStoreService } from '@coze-studio/user-store';
|
||||
import { useBotListFilterStore } from '@coze-agent-ide/space-bot/store';
|
||||
import { useSpaceStore } from '@coze-arch/bot-studio-store';
|
||||
|
||||
export const useResetStoreOnLogout = () => {
|
||||
const isSettled = userStoreService.useIsSettled();
|
||||
const isLogined = userStoreService.useIsLogined();
|
||||
useEffect(() => {
|
||||
if (isSettled && !isLogined) {
|
||||
useSpaceStore.getState().reset();
|
||||
useBotListFilterStore.getState().reset();
|
||||
}
|
||||
}, [isLogined, isSettled]);
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 { useEffect } from 'react';
|
||||
|
||||
import { setMobileBody, setPCBody } from '@coze-arch/bot-utils';
|
||||
import { useIsResponsiveByRouteConfig } from '@coze-arch/bot-hooks';
|
||||
|
||||
export const useSetResponsiveBodyStyle = () => {
|
||||
const isResponsive = useIsResponsiveByRouteConfig();
|
||||
useEffect(() => {
|
||||
if (isResponsive) {
|
||||
setMobileBody();
|
||||
} else {
|
||||
setPCBody();
|
||||
}
|
||||
}, [isResponsive]);
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 { useLocation } from 'react-router-dom';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { logger } from '@coze-arch/logger';
|
||||
|
||||
export enum CustomPerfMarkNames {
|
||||
RouteChange = 'route_change',
|
||||
}
|
||||
|
||||
export const useTrackRouteChange = () => {
|
||||
const location = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
performance.mark(CustomPerfMarkNames.RouteChange, {
|
||||
detail: {
|
||||
location,
|
||||
},
|
||||
});
|
||||
logger.info({
|
||||
message: 'location change',
|
||||
meta: { location },
|
||||
});
|
||||
}, [location.pathname]);
|
||||
};
|
||||
21
frontend/packages/foundation/global-adapter/src/index.tsx
Normal file
21
frontend/packages/foundation/global-adapter/src/index.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export { GlobalLayout } from './components/global-layout';
|
||||
export { useAppInit } from './hooks/use-app-init';
|
||||
export { useHasSider } from './components/global-layout-composed/hooks/use-has-sider';
|
||||
export { AccountDropdown } from './components/account-dropdown';
|
||||
export { useAccountSettings } from './components/account-dropdown/account-settings';
|
||||
20
frontend/packages/foundation/global-adapter/src/typings.d.ts
vendored
Normal file
20
frontend/packages/foundation/global-adapter/src/typings.d.ts
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/// <reference types='@coze-arch/bot-typings' />
|
||||
|
||||
declare const IS_OVERSEA: boolean;
|
||||
declare const IS_BOE: boolean;
|
||||
@@ -0,0 +1,96 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
},
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"module": "ESNext",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "bundler",
|
||||
"tsBuildInfoFile": "dist/tsconfig.build.tsbuildinfo"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../account-adapter/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../account-ui-adapter/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../account-ui-base/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../agent-ide/space-bot/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-error/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-hooks/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-store/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-typings/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-utils/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/default-slardar/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/foundation-sdk/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/i18n/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/idl/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/logger/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../browser-upgrade-banner/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../components/bot-semi/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/eslint-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/stylelint-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/ts-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/vitest-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../global-store/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../global/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../layout/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../studio/open-platform/open-auth/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../studio/user-store/tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
15
frontend/packages/foundation/global-adapter/tsconfig.json
Normal file
15
frontend/packages/foundation/global-adapter/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"exclude": ["**/*"],
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.misc.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"module": "ESNext",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "bundler"
|
||||
},
|
||||
"include": ["__tests__", "vitest.config.ts", "stories"],
|
||||
"exclude": ["./dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
22
frontend/packages/foundation/global-adapter/vitest.config.ts
Normal file
22
frontend/packages/foundation/global-adapter/vitest.config.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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 { defineConfig } from '@coze-arch/vitest-config';
|
||||
|
||||
export default defineConfig({
|
||||
dirname: __dirname,
|
||||
preset: 'web',
|
||||
});
|
||||
Reference in New Issue
Block a user