From 585fea650e1945f22139270ecf3636addda57b17 Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 12 Jun 2024 09:40:14 +0800 Subject: [PATCH] feat: workbench block (#4555) * feat: workbench block * feat: mobilePage * fix: update WorkbenchAction * feat: improve code * fix: iconColor * fix: Improve code * feat: Improve code * fix: version --- lerna.json | 4 +- packages/core/client/src/index.ts | 1 + .../antd/action/Action.Designer.tsx | 14 +- .../plugin-block-workbench/.npmignore | 2 + .../plugin-block-workbench/README.md | 1 + .../plugin-block-workbench/client.d.ts | 2 + .../plugin-block-workbench/client.js | 1 + .../plugin-block-workbench/package.json | 11 + .../plugin-block-workbench/server.d.ts | 2 + .../plugin-block-workbench/server.js | 1 + .../ModalActionSchemaInitializerItem.tsx | 99 +++++++ .../src/client/WorkbenchAction.tsx | 47 ++++ .../src/client/WorkbenchBlock.tsx | 66 +++++ ...rkbenchLinkActionSchemaInitializerItem.tsx | 97 +++++++ ...rkbenchScanActionSchemaInitializerItem.tsx | 84 ++++++ .../src/client/blockSchema.ts | 24 ++ .../src/client/client.d.ts | 249 ++++++++++++++++++ .../src/client/index.tsx | 57 ++++ .../client/workbenchBlockInitializerItem.ts | 28 ++ .../src/client/workbenchBlockSettings.ts | 20 ++ .../src/client/workbenchConfigureActions.ts | 25 ++ .../plugin-block-workbench/src/index.ts | 11 + .../src/locale/zh-CN.json | 3 + .../src/server/collections/.gitkeep | 0 .../src/server/index.ts | 10 + .../src/server/plugin.ts | 28 ++ packages/presets/nocobase/package.json | 1 + packages/presets/nocobase/src/server/index.ts | 1 + 28 files changed, 884 insertions(+), 5 deletions(-) create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/.npmignore create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/README.md create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/client.d.ts create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/client.js create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/package.json create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/server.d.ts create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/server.js create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/client/ModalActionSchemaInitializerItem.tsx create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchAction.tsx create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchBlock.tsx create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchLinkActionSchemaInitializerItem.tsx create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchScanActionSchemaInitializerItem.tsx create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/client/blockSchema.ts create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/client/client.d.ts create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/client/index.tsx create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/client/workbenchBlockInitializerItem.ts create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/client/workbenchBlockSettings.ts create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/client/workbenchConfigureActions.ts create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/index.ts create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/locale/zh-CN.json create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/server/collections/.gitkeep create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/server/index.ts create mode 100644 packages/plugins/@nocobase/plugin-block-workbench/src/server/plugin.ts diff --git a/lerna.json b/lerna.json index d679a07eca..4339bd9f1b 100644 --- a/lerna.json +++ b/lerna.json @@ -2,9 +2,7 @@ "version": "1.0.1-alpha.3", "npmClient": "yarn", "useWorkspaces": true, - "npmClientArgs": [ - "--ignore-engines" - ], + "npmClientArgs": ["--ignore-engines"], "command": { "version": { "forcePublish": true, diff --git a/packages/core/client/src/index.ts b/packages/core/client/src/index.ts index 84e299b89f..73f90a6698 100644 --- a/packages/core/client/src/index.ts +++ b/packages/core/client/src/index.ts @@ -62,6 +62,7 @@ export * from './variables'; export { withDynamicSchemaProps } from './hoc/withDynamicSchemaProps'; +export { SchemaSettingsActionLinkItem } from './modules/actions/link/customizeLinkActionSettings'; export * from './modules/blocks/BlockSchemaToolbar'; export * from './modules/blocks/data-blocks/form'; export * from './modules/blocks/data-blocks/table'; diff --git a/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx b/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx index 860ff3ea3e..31e3ea9b9f 100644 --- a/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx +++ b/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx @@ -79,6 +79,14 @@ export function ButtonEditor(props) { 'x-visible': !isLink, // description: `原字段标题:${collectionField?.uiSchema?.title}`, }, + iconColor: { + title: t('Color'), + required: true, + default: fieldSchema?.['x-component-props']?.iconColor || '#1677FF', + 'x-hidden': !props.hasIconColor, + 'x-component': 'ColorPicker', + 'x-decorator': 'FormItem', + }, type: { 'x-decorator': 'FormItem', 'x-component': 'Radio.Group', @@ -93,18 +101,20 @@ export function ButtonEditor(props) { { value: 'primary', label: '{{t("Highlight")}}' }, { value: 'danger', label: '{{t("Danger red")}}' }, ], - 'x-visible': !isLink, + 'x-visible': !props.hasIconColor && !isLink, }, }, } as ISchema } - onSubmit={({ title, icon, type }) => { + onSubmit={({ title, icon, type, iconColor }) => { fieldSchema.title = title; field.title = title; + field.componentProps.iconColor = iconColor; field.componentProps.icon = icon; field.componentProps.danger = type === 'danger'; field.componentProps.type = type || field.componentProps.type; fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {}; + fieldSchema['x-component-props'].iconColor = iconColor; fieldSchema['x-component-props'].icon = icon; fieldSchema['x-component-props'].danger = type === 'danger'; fieldSchema['x-component-props'].type = type || field.componentProps.type; diff --git a/packages/plugins/@nocobase/plugin-block-workbench/.npmignore b/packages/plugins/@nocobase/plugin-block-workbench/.npmignore new file mode 100644 index 0000000000..65f5e8779f --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/.npmignore @@ -0,0 +1,2 @@ +/node_modules +/src diff --git a/packages/plugins/@nocobase/plugin-block-workbench/README.md b/packages/plugins/@nocobase/plugin-block-workbench/README.md new file mode 100644 index 0000000000..4c6f516d1e --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/README.md @@ -0,0 +1 @@ +# @nocobase/plugin-block-workbench diff --git a/packages/plugins/@nocobase/plugin-block-workbench/client.d.ts b/packages/plugins/@nocobase/plugin-block-workbench/client.d.ts new file mode 100644 index 0000000000..6c459cbac4 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/client.d.ts @@ -0,0 +1,2 @@ +export * from './dist/client'; +export { default } from './dist/client'; diff --git a/packages/plugins/@nocobase/plugin-block-workbench/client.js b/packages/plugins/@nocobase/plugin-block-workbench/client.js new file mode 100644 index 0000000000..b6e3be70e6 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/client.js @@ -0,0 +1 @@ +module.exports = require('./dist/client/index.js'); diff --git a/packages/plugins/@nocobase/plugin-block-workbench/package.json b/packages/plugins/@nocobase/plugin-block-workbench/package.json new file mode 100644 index 0000000000..f57a7b81aa --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/package.json @@ -0,0 +1,11 @@ +{ + "name": "@nocobase/plugin-block-workbench", + "version": "1.0.1-alpha.3", + "main": "dist/server/index.js", + "dependencies": {}, + "peerDependencies": { + "@nocobase/client": "1.x", + "@nocobase/server": "1.x", + "@nocobase/test": "1.x" + } +} diff --git a/packages/plugins/@nocobase/plugin-block-workbench/server.d.ts b/packages/plugins/@nocobase/plugin-block-workbench/server.d.ts new file mode 100644 index 0000000000..c41081ddc6 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/server.d.ts @@ -0,0 +1,2 @@ +export * from './dist/server'; +export { default } from './dist/server'; diff --git a/packages/plugins/@nocobase/plugin-block-workbench/server.js b/packages/plugins/@nocobase/plugin-block-workbench/server.js new file mode 100644 index 0000000000..972842039a --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/server.js @@ -0,0 +1 @@ +module.exports = require('./dist/server/index.js'); diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/client/ModalActionSchemaInitializerItem.tsx b/packages/plugins/@nocobase/plugin-block-workbench/src/client/ModalActionSchemaInitializerItem.tsx new file mode 100644 index 0000000000..5ed71eb2bd --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/client/ModalActionSchemaInitializerItem.tsx @@ -0,0 +1,99 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { useForm } from '@formily/react'; +import { + Action, + ActionContextProvider, + ISchema, + SchemaComponent, + SchemaInitializerItem, + useSchemaInitializer, +} from '@nocobase/client'; +import { uid } from '@nocobase/utils/client'; +import React, { useMemo, useState } from 'react'; + +export function ModalActionSchemaInitializerItem(props) { + const { modalSchema = {}, ...otherProps } = props; + const { properties, ...others } = modalSchema; + const [visible, setVisible] = useState(false); + const { setVisible: setSchemaInitializerVisible } = useSchemaInitializer(); + + const schema: ISchema = useMemo(() => { + return { + name: uid(), + 'x-component': 'Action.Modal', + 'x-component-props': { + width: '520px', + }, + type: 'void', + 'x-decorator': 'FormV2', + 'x-decorator-props': {}, + ...others, + properties: { + ...properties, + footer1: { + 'x-component': 'Action.Modal.Footer', + type: 'void', + properties: { + close: { + title: 'Cancel', + 'x-component': 'Action', + 'x-component-props': { + type: 'default', + }, + 'x-use-component-props': () => { + return { + onClick() { + setVisible(false); + props?.onCancel?.(); + }, + }; + }, + }, + submit: { + title: 'OK', + 'x-component': 'Action', + 'x-component-props': { + type: 'primary', + }, + 'x-use-component-props': () => { + // eslint-disable-next-line react-hooks/rules-of-hooks + const form = useForm(); + return { + async onClick() { + await form.submit(); + setVisible(false); + props?.onSubmit?.(form.values); + }, + }; + }, + }, + }, + }, + }, + }; + }, []); + + return ( + <> + { + setSchemaInitializerVisible(false); + setVisible(true); + props?.onClick?.(e); + }} + /> + + + + + ); +} diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchAction.tsx b/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchAction.tsx new file mode 100644 index 0000000000..cd9caec9aa --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchAction.tsx @@ -0,0 +1,47 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { useFieldSchema } from '@formily/react'; +import { Action, Icon, withDynamicSchemaProps } from '@nocobase/client'; +import { Avatar } from 'antd'; +import { createStyles } from 'antd-style'; +import React from 'react'; + +const useStyles = createStyles(({ token, css }) => ({ + // 支持 css object 的写法 + action: css` + background-color: transparent; + border: 0; + height: auto; + box-shadow: none; + `, + title: css` + margin-top: ${token.marginSM}px; + `, +})); + +function Button() { + const fieldSchema = useFieldSchema(); + const icon = fieldSchema['x-component-props']?.['icon']; + const backgroundColor = fieldSchema['x-component-props']?.['iconColor']; + const { styles, cx } = useStyles(); + + return ( +
+ } /> +
{fieldSchema.title}
+
+ ); +} + +export const WorkbenchAction = withDynamicSchemaProps((props) => { + const { className, ...others } = props; + const { styles, cx } = useStyles(); + return } />; +}); diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchBlock.tsx b/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchBlock.tsx new file mode 100644 index 0000000000..1291b2ce86 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchBlock.tsx @@ -0,0 +1,66 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { RecursionField, observer, useFieldSchema } from '@formily/react'; +import { + DndContext, + SchemaComponentOptions, + useDesignable, + useSchemaInitializerRender, + withDynamicSchemaProps, +} from '@nocobase/client'; +import { Space } from 'antd'; +import React from 'react'; +import { WorkbenchAction } from './WorkbenchAction'; + +const ConfigureActionsButton = observer( + () => { + const fieldSchema = useFieldSchema(); + const { render } = useSchemaInitializerRender(fieldSchema['x-initializer']); + return render(); + }, + { displayName: 'WorkbenchConfigureActionsButton' }, +); + +const InternalIcons = () => { + const fieldSchema = useFieldSchema(); + const { designable } = useDesignable(); + + return ( +
+ + + {fieldSchema.mapProperties((s, key) => ( + + ))} + + +
+ ); +}; + +export const WorkbenchBlock: any = withDynamicSchemaProps( + (props) => { + return ( +
+ {props.children} +
+ ); + }, + { displayName: 'WorkbenchBlock' }, +); + +WorkbenchBlock.ActionBar = () => { + return ( + <> + + + + ); +}; diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchLinkActionSchemaInitializerItem.tsx b/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchLinkActionSchemaInitializerItem.tsx new file mode 100644 index 0000000000..d8fded62e8 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchLinkActionSchemaInitializerItem.tsx @@ -0,0 +1,97 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { + ButtonEditor, + SchemaSettings, + SchemaSettingsActionLinkItem, + useSchemaInitializer, + useSchemaInitializerItem, +} from '@nocobase/client'; +import React from 'react'; +import { useTranslation } from 'react-i18next'; +import { ModalActionSchemaInitializerItem } from './ModalActionSchemaInitializerItem'; + +export const workbenchActionSettingsLink = new SchemaSettings({ + name: 'workbench:actionSettings:link', + items: [ + { + name: 'editButton', + Component: ButtonEditor, + useComponentProps() { + return { hasIconColor: true }; + }, + }, + { + name: 'editLink', + Component: SchemaSettingsActionLinkItem, + }, + { + sort: 800, + name: 'd1', + type: 'divider', + }, + { + sort: 900, + type: 'remove', + name: 'remove', + }, + ], +}); + +export function WorkbenchLinkActionSchemaInitializerItem(props) { + const itemConfig = useSchemaInitializerItem(); + // 调用插入功能 + const { insert } = useSchemaInitializer(); + const { t } = useTranslation(); + return ( + { + insert({ + type: 'void', + title: values.title, + 'x-action': 'customize:link', + 'x-toolbar': 'ActionSchemaToolbar', + 'x-settings': 'workbench:actionSettings:link', + 'x-component': 'WorkbenchAction', + 'x-use-component-props': 'useLinkActionProps', + 'x-component-props': { + icon: values.icon, + iconColor: values.iconColor, + }, + }); + }} + /> + ); +} diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchScanActionSchemaInitializerItem.tsx b/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchScanActionSchemaInitializerItem.tsx new file mode 100644 index 0000000000..1d1261ac71 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchScanActionSchemaInitializerItem.tsx @@ -0,0 +1,84 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { ButtonEditor, SchemaSettings, useSchemaInitializer, useSchemaInitializerItem } from '@nocobase/client'; +import React from 'react'; +import { useTranslation } from 'react-i18next'; +import { ModalActionSchemaInitializerItem } from './ModalActionSchemaInitializerItem'; + +export const workbenchActionSettingsScanQrCode = new SchemaSettings({ + name: 'workbench:actionSettings:scanQrCode', + items: [ + { + name: 'editButton', + Component: ButtonEditor, + useComponentProps() { + return { hasIconColor: true }; + }, + }, + { + name: 'd1', + type: 'divider', + }, + { + type: 'remove', + name: 'remove', + }, + ], +}); + +export function WorkbenchScanActionSchemaInitializerItem(props) { + const itemConfig = useSchemaInitializerItem(); + // 调用插入功能 + const { insert } = useSchemaInitializer(); + const { t } = useTranslation(); + return ( + { + console.log('values', values); + insert({ + type: 'void', + title: values.title, + 'x-component': 'WorkbenchAction', + 'x-toolbar': 'ActionSchemaToolbar', + 'x-settings': 'workbench:actionSettings:scanQrCode', + 'x-component-props': { + icon: values.icon, + iconColor: values.iconColor, + }, + }); + }} + /> + ); +} diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/client/blockSchema.ts b/packages/plugins/@nocobase/plugin-block-workbench/src/client/blockSchema.ts new file mode 100644 index 0000000000..3dd401ce60 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/client/blockSchema.ts @@ -0,0 +1,24 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { ISchema } from '@nocobase/client'; + +export const blockSchema: ISchema = { + type: 'void', + 'x-decorator': 'CardItem', + 'x-settings': 'blockSettings:workbench', + 'x-schema-toolbar': 'BlockSchemaToolbar', + 'x-component': 'WorkbenchBlock', + properties: { + actions: { + 'x-component': 'WorkbenchBlock.ActionBar', + 'x-initializer': 'workbench:configureActions', + }, + }, +}; diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/client/client.d.ts b/packages/plugins/@nocobase/plugin-block-workbench/src/client/client.d.ts new file mode 100644 index 0000000000..4e96f83fa1 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/client/client.d.ts @@ -0,0 +1,249 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +// CSS modules +type CSSModuleClasses = { readonly [key: string]: string }; + +declare module '*.module.css' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.scss' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.sass' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.less' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.styl' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.stylus' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.pcss' { + const classes: CSSModuleClasses; + export default classes; +} +declare module '*.module.sss' { + const classes: CSSModuleClasses; + export default classes; +} + +// CSS +declare module '*.css' { } +declare module '*.scss' { } +declare module '*.sass' { } +declare module '*.less' { } +declare module '*.styl' { } +declare module '*.stylus' { } +declare module '*.pcss' { } +declare module '*.sss' { } + +// Built-in asset types +// see `src/node/constants.ts` + +// images +declare module '*.apng' { + const src: string; + export default src; +} +declare module '*.png' { + const src: string; + export default src; +} +declare module '*.jpg' { + const src: string; + export default src; +} +declare module '*.jpeg' { + const src: string; + export default src; +} +declare module '*.jfif' { + const src: string; + export default src; +} +declare module '*.pjpeg' { + const src: string; + export default src; +} +declare module '*.pjp' { + const src: string; + export default src; +} +declare module '*.gif' { + const src: string; + export default src; +} +declare module '*.svg' { + const src: string; + export default src; +} +declare module '*.ico' { + const src: string; + export default src; +} +declare module '*.webp' { + const src: string; + export default src; +} +declare module '*.avif' { + const src: string; + export default src; +} + +// media +declare module '*.mp4' { + const src: string; + export default src; +} +declare module '*.webm' { + const src: string; + export default src; +} +declare module '*.ogg' { + const src: string; + export default src; +} +declare module '*.mp3' { + const src: string; + export default src; +} +declare module '*.wav' { + const src: string; + export default src; +} +declare module '*.flac' { + const src: string; + export default src; +} +declare module '*.aac' { + const src: string; + export default src; +} +declare module '*.opus' { + const src: string; + export default src; +} +declare module '*.mov' { + const src: string; + export default src; +} +declare module '*.m4a' { + const src: string; + export default src; +} +declare module '*.vtt' { + const src: string; + export default src; +} + +// fonts +declare module '*.woff' { + const src: string; + export default src; +} +declare module '*.woff2' { + const src: string; + export default src; +} +declare module '*.eot' { + const src: string; + export default src; +} +declare module '*.ttf' { + const src: string; + export default src; +} +declare module '*.otf' { + const src: string; + export default src; +} + +// other +declare module '*.webmanifest' { + const src: string; + export default src; +} +declare module '*.pdf' { + const src: string; + export default src; +} +declare module '*.txt' { + const src: string; + export default src; +} + +// wasm?init +declare module '*.wasm?init' { + const initWasm: (options?: WebAssembly.Imports) => Promise; + export default initWasm; +} + +// web worker +declare module '*?worker' { + const workerConstructor: { + new(options?: { name?: string }): Worker; + }; + export default workerConstructor; +} + +declare module '*?worker&inline' { + const workerConstructor: { + new(options?: { name?: string }): Worker; + }; + export default workerConstructor; +} + +declare module '*?worker&url' { + const src: string; + export default src; +} + +declare module '*?sharedworker' { + const sharedWorkerConstructor: { + new(options?: { name?: string }): SharedWorker; + }; + export default sharedWorkerConstructor; +} + +declare module '*?sharedworker&inline' { + const sharedWorkerConstructor: { + new(options?: { name?: string }): SharedWorker; + }; + export default sharedWorkerConstructor; +} + +declare module '*?sharedworker&url' { + const src: string; + export default src; +} + +declare module '*?raw' { + const src: string; + export default src; +} + +declare module '*?url' { + const src: string; + export default src; +} + +declare module '*?inline' { + const src: string; + export default src; +} diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/client/index.tsx b/packages/plugins/@nocobase/plugin-block-workbench/src/client/index.tsx new file mode 100644 index 0000000000..d688085625 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/client/index.tsx @@ -0,0 +1,57 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { Plugin } from '@nocobase/client'; +import { WorkbenchBlock } from './WorkbenchBlock'; +import { workbenchActionSettingsLink } from './WorkbenchLinkActionSchemaInitializerItem'; +// import { +// WorkbenchScanActionSchemaInitializerItem, +// workbenchActionSettingsScanQrCode, +// } from './WorkbenchScanActionSchemaInitializerItem'; +import { workbenchBlockInitializerItem } from './workbenchBlockInitializerItem'; +import { workbenchBlockSettings } from './workbenchBlockSettings'; +import { workbenchConfigureActions } from './workbenchConfigureActions'; + +export class PluginBlockWorkbenchClient extends Plugin { + async load() { + this.app.addComponents({ WorkbenchBlock }); + + // 新增工作台区块的设置器 + this.app.schemaSettingsManager.add(workbenchBlockSettings); + + // 工作台的配置操作埋点 + this.app.schemaInitializerManager.add(workbenchConfigureActions); + + // 添加到页面的 Add block 里 + this.app.schemaInitializerManager.addItem( + 'page:addBlock', + `otherBlocks.${workbenchBlockInitializerItem.name}`, + workbenchBlockInitializerItem, + ); + + // 添加到移动端的 Add block 里 + this.app.schemaInitializerManager.addItem( + 'mobilePage:addBlock', + `otherBlocks.${workbenchBlockInitializerItem.name}`, + workbenchBlockInitializerItem, + ); + + // link 操作 + this.app.schemaSettingsManager.add(workbenchActionSettingsLink); + + // 扫码操作 + // this.app.schemaSettingsManager.add(workbenchActionSettingsScanQrCode); + // this.app.schemaInitializerManager.addItem('workbench:configureActions', `qrcode`, { + // title: 'Scan Qr code', + // Component: WorkbenchScanActionSchemaInitializerItem, + // }); + } +} + +export default PluginBlockWorkbenchClient; diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/client/workbenchBlockInitializerItem.ts b/packages/plugins/@nocobase/plugin-block-workbench/src/client/workbenchBlockInitializerItem.ts new file mode 100644 index 0000000000..e48d9c5b17 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/client/workbenchBlockInitializerItem.ts @@ -0,0 +1,28 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { SchemaInitializerItemType, useSchemaInitializer } from '@nocobase/client'; +import { useTranslation } from 'react-i18next'; +import { blockSchema } from './blockSchema'; + +export const workbenchBlockInitializerItem: SchemaInitializerItemType = { + type: 'item', + name: 'workbenchBlock', + icon: 'FileImageOutlined', + useComponentProps() { + const { t } = useTranslation('@nocobase/plugin-block-workbench'); + const { insert } = useSchemaInitializer(); + return { + title: t('Workbench'), + onClick: () => { + insert(blockSchema); + }, + }; + }, +}; diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/client/workbenchBlockSettings.ts b/packages/plugins/@nocobase/plugin-block-workbench/src/client/workbenchBlockSettings.ts new file mode 100644 index 0000000000..0b14c91f49 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/client/workbenchBlockSettings.ts @@ -0,0 +1,20 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { SchemaSettings } from '@nocobase/client'; + +export const workbenchBlockSettings = new SchemaSettings({ + name: 'blockSettings:workbench', + items: [ + { + type: 'remove', + name: 'remove', + }, + ], +}); diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/client/workbenchConfigureActions.ts b/packages/plugins/@nocobase/plugin-block-workbench/src/client/workbenchConfigureActions.ts new file mode 100644 index 0000000000..6fe7c881d9 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/client/workbenchConfigureActions.ts @@ -0,0 +1,25 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { SchemaInitializer } from '@nocobase/client'; +import { WorkbenchLinkActionSchemaInitializerItem } from './WorkbenchLinkActionSchemaInitializerItem'; + +export const workbenchConfigureActions = new SchemaInitializer({ + name: 'workbench:configureActions', + title: '{{t("Configure actions")}}', + // 插入位置 + insertPosition: 'beforeEnd', + items: [ + { + name: 'link', + title: '{{t("Link")}}', + Component: WorkbenchLinkActionSchemaInitializerItem, + }, + ], +}); diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/index.ts b/packages/plugins/@nocobase/plugin-block-workbench/src/index.ts new file mode 100644 index 0000000000..be99a2ff1a --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/index.ts @@ -0,0 +1,11 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +export * from './server'; +export { default } from './server'; diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/locale/zh-CN.json b/packages/plugins/@nocobase/plugin-block-workbench/src/locale/zh-CN.json new file mode 100644 index 0000000000..29738d1738 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/locale/zh-CN.json @@ -0,0 +1,3 @@ +{ + "Workbench": "工作台" +} \ No newline at end of file diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/server/collections/.gitkeep b/packages/plugins/@nocobase/plugin-block-workbench/src/server/collections/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/server/index.ts b/packages/plugins/@nocobase/plugin-block-workbench/src/server/index.ts new file mode 100644 index 0000000000..be989de7c3 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/server/index.ts @@ -0,0 +1,10 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +export { default } from './plugin'; diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/server/plugin.ts b/packages/plugins/@nocobase/plugin-block-workbench/src/server/plugin.ts new file mode 100644 index 0000000000..4ca14f706f --- /dev/null +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/server/plugin.ts @@ -0,0 +1,28 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { Plugin } from '@nocobase/server'; + +export class PluginBlockWorkbenchServer extends Plugin { + async afterAdd() {} + + async beforeLoad() {} + + async load() {} + + async install() {} + + async afterEnable() {} + + async afterDisable() {} + + async remove() {} +} + +export default PluginBlockWorkbenchServer; diff --git a/packages/presets/nocobase/package.json b/packages/presets/nocobase/package.json index 6a55994946..7232005ff4 100644 --- a/packages/presets/nocobase/package.json +++ b/packages/presets/nocobase/package.json @@ -20,6 +20,7 @@ "@nocobase/plugin-auth-sms": "1.0.1-alpha.3", "@nocobase/plugin-backup-restore": "1.0.1-alpha.3", "@nocobase/plugin-block-iframe": "1.0.1-alpha.3", + "@nocobase/plugin-block-workbench": "1.0.1-alpha.3", "@nocobase/plugin-calendar": "1.0.1-alpha.3", "@nocobase/plugin-charts": "1.0.1-alpha.3", "@nocobase/plugin-client": "1.0.1-alpha.3", diff --git a/packages/presets/nocobase/src/server/index.ts b/packages/presets/nocobase/src/server/index.ts index f739fa6b45..ee1dfd1fc5 100644 --- a/packages/presets/nocobase/src/server/index.ts +++ b/packages/presets/nocobase/src/server/index.ts @@ -39,6 +39,7 @@ export class PresetNocoBase extends Plugin { 'action-export', 'backup-restore', 'block-iframe', + 'block-workbench', 'field-formula', 'data-visualization', 'auth',