feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
5
frontend/packages/community/explore/.stylelintrc.js
Normal file
5
frontend/packages/community/explore/.stylelintrc.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@coze-arch/stylelint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: [],
|
||||
});
|
||||
16
frontend/packages/community/explore/README.md
Normal file
16
frontend/packages/community/explore/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# @coze-foundation/space-ui-adapter
|
||||
|
||||
> 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`
|
||||
12
frontend/packages/community/explore/config/rush-project.json
Normal file
12
frontend/packages/community/explore/config/rush-project.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
7
frontend/packages/community/explore/eslint.config.js
Normal file
7
frontend/packages/community/explore/eslint.config.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
packageRoot: __dirname,
|
||||
preset: 'web',
|
||||
rules: {},
|
||||
});
|
||||
50
frontend/packages/community/explore/package.json
Normal file
50
frontend/packages/community/explore/package.json
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "@coze-community/explore",
|
||||
"version": "0.0.1",
|
||||
"description": "explore page",
|
||||
"license": "Apache-2.0",
|
||||
"author": "gaoding.devingao@bytedance.com",
|
||||
"maintainers": [],
|
||||
"main": "src/index.tsx",
|
||||
"scripts": {
|
||||
"build": "exit 0",
|
||||
"lint": "eslint ./ --cache",
|
||||
"test": "vitest --run --passWithNoTests",
|
||||
"test:cov": "npm run test -- --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@coze-arch/bot-api": "workspace:*",
|
||||
"@coze-arch/bot-hooks": "workspace:*",
|
||||
"@coze-arch/coze-design": "0.0.6-alpha.346d77",
|
||||
"@coze-arch/i18n": "workspace:*",
|
||||
"@coze-community/components": "workspace:*",
|
||||
"@coze-studio/api-schema": "workspace:*",
|
||||
"ahooks": "^3.7.8",
|
||||
"classnames": "^2.3.2",
|
||||
"react-router-dom": "^6.11.1",
|
||||
"zustand": "^4.4.7"
|
||||
},
|
||||
"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",
|
||||
"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,5 @@
|
||||
.explore-list-container {
|
||||
.spin {
|
||||
height: 200px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 { type FC } from 'react';
|
||||
|
||||
import { useRequest } from 'ahooks';
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
import { IconCozIllusError } from '@coze-arch/coze-design/illustrations';
|
||||
import { EmptyState } from '@coze-arch/coze-design';
|
||||
|
||||
import styles from './index.module.less';
|
||||
|
||||
export const PageList: FC<{
|
||||
title: string;
|
||||
renderCard: (cardData: unknown) => React.ReactNode;
|
||||
renderCardSkeleton: () => React.ReactNode;
|
||||
getDataList: () => Promise<unknown[]>;
|
||||
}> = ({ title, renderCard, getDataList, renderCardSkeleton }) => {
|
||||
const {
|
||||
data: cardList,
|
||||
loading,
|
||||
error,
|
||||
refresh,
|
||||
} = useRequest(async () => {
|
||||
const dataList = await getDataList();
|
||||
return dataList;
|
||||
});
|
||||
console.log('data:', { cardList, loading, error });
|
||||
return (
|
||||
<div className={styles['explore-list-container']}>
|
||||
<h2 className="leading-[72px] text-[20px] m-[0] pl-[24px] pr-[24px]">
|
||||
{title}
|
||||
</h2>
|
||||
|
||||
{error && !loading ? (
|
||||
<EmptyState
|
||||
size="full_screen"
|
||||
icon={<IconCozIllusError className="coz-fg-dim text-32px" />}
|
||||
title={I18n.t('inifinit_list_load_fail')}
|
||||
buttonText={I18n.t('inifinit_list_retry')}
|
||||
onButtonClick={() => {
|
||||
refresh();
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<div className="grid grid-cols-3 auto-rows-min gap-[20px] [@media(min-width:1600px)]:grid-cols-4 pl-[24px] pr-[24px]">
|
||||
{loading
|
||||
? new Array(20).fill(0).map((_, index) => renderCardSkeleton?.())
|
||||
: cardList?.map(item => renderCard(item))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
.explore-sub-menu {
|
||||
.text {
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 { useNavigate } from 'react-router-dom';
|
||||
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
import {
|
||||
IconCozTemplate,
|
||||
IconCozTemplateFill,
|
||||
IconCozPlugin,
|
||||
IconCozPluginFill,
|
||||
} from '@coze-arch/coze-design/icons';
|
||||
import { Space } from '@coze-arch/coze-design';
|
||||
import { SubMenuItem } from '@coze-community/components';
|
||||
|
||||
import { useExploreRoute } from '../../hooks/use-explore-route';
|
||||
|
||||
const getMenuConfig = () => [
|
||||
{
|
||||
type: 'plugin',
|
||||
icon: <IconCozPlugin />,
|
||||
activeIcon: <IconCozPluginFill />,
|
||||
title: I18n.t('Plugins'),
|
||||
isActive: true,
|
||||
path: '/explore/plugin',
|
||||
},
|
||||
{
|
||||
icon: <IconCozTemplate />,
|
||||
activeIcon: <IconCozTemplateFill />,
|
||||
title: I18n.t('template_name'),
|
||||
isActive: true,
|
||||
type: 'template',
|
||||
path: '/explore/template',
|
||||
},
|
||||
];
|
||||
|
||||
export const ExploreSubMenu = () => {
|
||||
const navigate = useNavigate();
|
||||
const { type } = useExploreRoute();
|
||||
const menuConfig = getMenuConfig();
|
||||
return (
|
||||
<Space spacing={4} vertical>
|
||||
<p className="text-[14px] w-full text-left font-medium coz-fg-secondary ">
|
||||
{I18n.t('menu_title_personal_space')}
|
||||
</p>
|
||||
{menuConfig.map(item => (
|
||||
<SubMenuItem
|
||||
{...item}
|
||||
isActive={item.type === type}
|
||||
onClick={() => {
|
||||
navigate(item.path);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</Space>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 { useRouteConfig } from '@coze-arch/bot-hooks';
|
||||
import { type TRouteConfigGlobal } from '@coze-arch/bot-hooks';
|
||||
|
||||
export interface ExploreRouteType extends TRouteConfigGlobal {
|
||||
type?: 'template' | 'plugin';
|
||||
}
|
||||
export const useExploreRoute = useRouteConfig<ExploreRouteType>;
|
||||
19
frontend/packages/community/explore/src/index.tsx
Normal file
19
frontend/packages/community/explore/src/index.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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 { ExploreSubMenu } from './components/sub-menu';
|
||||
export { TemplatePage } from './pages/template';
|
||||
export { PluginPage } from './pages/plugin';
|
||||
@@ -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 { I18n } from '@coze-arch/i18n';
|
||||
import { explore } from '@coze-studio/api-schema';
|
||||
|
||||
import {
|
||||
PluginCard,
|
||||
type PluginCardProps,
|
||||
PluginCardSkeleton,
|
||||
} from '@coze-community/components';
|
||||
|
||||
import { PageList } from '../../components/page-list';
|
||||
|
||||
export const PluginPage = () => (
|
||||
<PageList
|
||||
title={I18n.t('Plugins')}
|
||||
getDataList={getPluginData}
|
||||
renderCard={data => <PluginCard {...(data as PluginCardProps)} />}
|
||||
renderCardSkeleton={() => <PluginCardSkeleton />}
|
||||
/>
|
||||
);
|
||||
|
||||
const getPluginData = async () => {
|
||||
const result = await explore.PublicGetProductList({
|
||||
entity_type: explore.product_common.ProductEntityType.Plugin,
|
||||
sort_type: explore.product_common.SortType.Newest,
|
||||
page_num: 0,
|
||||
page_size: 1000,
|
||||
});
|
||||
return result.data?.products || [];
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 { explore } from '@coze-studio/api-schema';
|
||||
import {
|
||||
TemplateCard,
|
||||
type TemplateCardProps,
|
||||
TemplateCardSkeleton,
|
||||
} from '@coze-community/components';
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
|
||||
import { PageList } from '../../components/page-list';
|
||||
|
||||
export const TemplatePage = () => (
|
||||
<PageList
|
||||
title={I18n.t('template_name')}
|
||||
getDataList={() => getTemplateData()}
|
||||
renderCard={data => <TemplateCard {...(data as TemplateCardProps)} />}
|
||||
renderCardSkeleton={() => <TemplateCardSkeleton />}
|
||||
/>
|
||||
);
|
||||
|
||||
const getTemplateData = async () => {
|
||||
const result = await explore.PublicGetProductList({
|
||||
entity_type: explore.product_common.ProductEntityType.TemplateCommon,
|
||||
sort_type: explore.product_common.SortType.Newest,
|
||||
page_num: 0,
|
||||
page_size: 1000,
|
||||
});
|
||||
return result.data?.products || [];
|
||||
};
|
||||
17
frontend/packages/community/explore/src/typings.d.ts
vendored
Normal file
17
frontend/packages/community/explore/src/typings.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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' />
|
||||
48
frontend/packages/community/explore/tsconfig.build.json
Normal file
48
frontend/packages/community/explore/tsconfig.build.json
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"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": "../../arch/api-schema/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-api/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-hooks/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-typings/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/i18n/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../component/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"
|
||||
}
|
||||
]
|
||||
}
|
||||
15
frontend/packages/community/explore/tsconfig.json
Normal file
15
frontend/packages/community/explore/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"
|
||||
}
|
||||
]
|
||||
}
|
||||
20
frontend/packages/community/explore/tsconfig.misc.json
Normal file
20
frontend/packages/community/explore/tsconfig.misc.json
Normal file
@@ -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/community/explore/vitest.config.ts
Normal file
22
frontend/packages/community/explore/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