diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml index 064072aec..7d4cf4426 100644 --- a/.github/workflows/pr-test.yml +++ b/.github/workflows/pr-test.yml @@ -22,12 +22,26 @@ jobs: with: node-version: ${{ matrix.node-version }} repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: test + - name: npm install + env: + NODE_OPTIONS: '--max-old-space-size=8192' run: | npm i --legacy-peer-deps cd packages/ooxml-viewer npm i --legacy-peer-deps cd ../../ - npm run build --workspaces + npm run build --workspace amis-formula + npm run build --workspace amis-core + npm run build --workspace amis-ui + npm run build --workspace amis + npm run build --workspace amis-editor-core + npm run build --workspace amis-editor + - name: typescript check + env: + NODE_OPTIONS: '--max-old-space-size=8192' + run: | + npm run typecheck + - name: test + run: | npm test --workspaces sh deploy-gh-pages.sh diff --git a/examples/components/ECharts.tsx b/examples/components/ECharts.tsx index 7b2a51c40..6ec69a64e 100644 --- a/examples/components/ECharts.tsx +++ b/examples/components/ECharts.tsx @@ -49,11 +49,11 @@ const LazyComponent = lazyData( }, { title: 'X 轴', - body: Axis('x') + body: (Axis as any)('x') }, { title: 'Y 轴', - body: Axis('y') + body: (Axis as any)('y') }, { title: '极标', diff --git a/examples/loader.ts b/examples/loader.ts index d7929f6ae..20e4929aa 100644 --- a/examples/loader.ts +++ b/examples/loader.ts @@ -33,8 +33,8 @@ }; Object.keys(mapping).forEach(key => { - amis.require.aliasMapping[key] = mapping[key]; + (window as any).amis.require.aliasMapping[key] = mapping[key]; }); - (window as any).amisRequire = amis.require; + (window as any).amisRequire = (window as any).amis.require; })(); diff --git a/examples/polyfills/index.ts b/examples/polyfills/index.ts index a715a5f3c..8e49cb9a2 100644 --- a/examples/polyfills/index.ts +++ b/examples/polyfills/index.ts @@ -14,7 +14,9 @@ import 'core-js/es/map'; import 'core-js/es/set'; import 'core-js/es/symbol'; +// @ts-ignore import './cloest'; +// @ts-ignore import './classList'; // ios 没有这个会报错 diff --git a/mock/cfc/index.js b/mock/cfc/index.js index 14965b634..50784f165 100755 --- a/mock/cfc/index.js +++ b/mock/cfc/index.js @@ -1,6 +1,7 @@ // cfc 入口。 exports.handler = (event, context, callback) => { try { + // @ts-ignore const entry = require('./mock/index'); entry(mockRequest(event, context), mockResponse(event, context, callback)); } catch (e) { diff --git a/mock/index.js b/mock/index.js index 385cc27b6..46828558c 100644 --- a/mock/index.js +++ b/mock/index.js @@ -2,6 +2,7 @@ * @file 用于模拟 cfc 接口 */ +// @ts-ignore const cfcHandler = require('./cfc/index').handler; module.exports = function (req, res) { diff --git a/package.json b/package.json index e4bfbe986..e2d6ab262 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "release": "npm run build --workspaces && lerna publish from-package --registry=https://registry.npmjs.org --ignore-scripts", "revision": "ts-node ./scripts/generate-revision.ts", "publish-to-internal": "sh ./publish-to-internal.sh", - "stylelint": "npx stylelint 'packages/**/*.scss'" + "stylelint": "npx stylelint 'packages/**/*.scss'", + "typecheck": "tsc --noEmit" }, "husky": { "hooks": { diff --git a/packages/amis-core/src/components/Overlay.tsx b/packages/amis-core/src/components/Overlay.tsx index 56b03d5fc..91d26b2bf 100644 --- a/packages/amis-core/src/components/Overlay.tsx +++ b/packages/amis-core/src/components/Overlay.tsx @@ -181,9 +181,12 @@ interface OverlayProps { shouldUpdatePosition?: boolean; rootClose?: boolean; onHide?(props: any, ...args: any[]): any; - container?: HTMLElement | (() => HTMLElement | null | undefined); + container?: + | HTMLElement + | React.ReactNode + | (() => HTMLElement | React.ReactNode | null | undefined); containerSelector?: string; - target?: React.ReactNode | Function; + target?: React.ReactNode | HTMLElement | Function; watchTargetSizeChange?: boolean; offset?: [number, number]; onEnter?(node: HTMLElement): any; diff --git a/packages/amis-core/src/types.ts b/packages/amis-core/src/types.ts index c08f8f093..bc697e04f 100644 --- a/packages/amis-core/src/types.ts +++ b/packages/amis-core/src/types.ts @@ -625,6 +625,13 @@ export interface BaseSchemaWithoutType { */ staticInputClassName?: SchemaClassName; staticSchema?: any; + + /** + * 组件样式 + */ + style?: { + [propName: string]: any; + }; } export type OperatorType = diff --git a/packages/amis-editor-core/src/builder/ApiBuilder.ts b/packages/amis-editor-core/src/builder/ApiBuilder.ts index e9d5d464a..630d5480d 100644 --- a/packages/amis-editor-core/src/builder/ApiBuilder.ts +++ b/packages/amis-editor-core/src/builder/ApiBuilder.ts @@ -12,8 +12,8 @@ import { } from './DSBuilder'; import cloneDeep from 'lodash/cloneDeep'; import {getEnv} from 'mobx-state-tree'; -import type {ButtonSchema} from 'amis/lib/renderers/Action'; -import type {FormSchema, SchemaCollection, SchemaObject} from 'amis/lib/Schema'; +import type {ButtonSchema} from 'amis'; +import type {FormSchema, SchemaCollection, SchemaObject} from 'amis'; import type {DSSourceSettingFormConfig} from './DSBuilder'; import {getSchemaTpl, tipedLabel} from '../tpl'; diff --git a/packages/amis-editor-core/src/builder/DSBuilder.ts b/packages/amis-editor-core/src/builder/DSBuilder.ts index 5c343f8cf..739997682 100644 --- a/packages/amis-editor-core/src/builder/DSBuilder.ts +++ b/packages/amis-editor-core/src/builder/DSBuilder.ts @@ -2,9 +2,9 @@ * 数据源构造器,可用于对接当前amis中的扩展数据源 */ -import type {ButtonSchema} from 'amis/lib/renderers/Action'; -import type {CRUD2Schema} from 'amis/lib/renderers/CRUD2'; -import type {FormSchema, SchemaCollection, SchemaObject} from 'amis/lib/Schema'; +import type {ButtonSchema} from 'amis'; +import type {CRUD2Schema} from 'amis'; +import type {FormSchema, SchemaCollection, SchemaObject} from 'amis'; import {EditorNodeType} from '../store/node'; /** diff --git a/packages/amis-editor-core/src/component/Editor.tsx b/packages/amis-editor-core/src/component/Editor.tsx index ba686b14a..81c8bdba7 100644 --- a/packages/amis-editor-core/src/component/Editor.tsx +++ b/packages/amis-editor-core/src/component/Editor.tsx @@ -3,7 +3,7 @@ import cx from 'classnames'; import Preview from './Preview'; import {autobind} from '../util'; import {MainStore, EditorStoreType} from '../store/editor'; -import type {SchemaObject} from 'amis/lib/Schema'; +import type {SchemaObject} from 'amis'; import {EditorManager, EditorManagerConfig, PluginClass} from '../manager'; import {reaction} from 'mobx'; import {RenderOptions, toast} from 'amis'; diff --git a/packages/amis-editor-core/src/manager.ts b/packages/amis-editor-core/src/manager.ts index 9768576c2..eb3ffe39f 100644 --- a/packages/amis-editor-core/src/manager.ts +++ b/packages/amis-editor-core/src/manager.ts @@ -66,7 +66,7 @@ import findIndex from 'lodash/findIndex'; import {EditorDNDManager} from './dnd'; import {VariableManager} from './variable'; import {IScopedContext} from 'amis'; -import type {SchemaObject, SchemaCollection} from 'amis/lib/Schema'; +import type {SchemaObject, SchemaCollection} from 'amis'; import type {RendererConfig} from 'amis-core'; import isPlainObject from 'lodash/isPlainObject'; import {omit} from 'lodash'; @@ -132,7 +132,9 @@ export function registerEditorPlugin(klass: PluginClass) { */ export function getEditorPlugins(options: any = {}) { const {scene = 'global'} = options; - return builtInPlugins.filter(item => item.scene?.includes(scene)); + return builtInPlugins.filter(item => + (Array.isArray(item) ? item[0] : item).scene?.includes(scene) + ); } /** @@ -327,9 +329,18 @@ export class EditorManager { ); } - normalizeScene(plugins?: Array) { + normalizeScene( + plugins?: Array< + | PluginClass + | [PluginClass, Record | (() => Record)] + > + ) { return ( - plugins?.map((klass: PluginClass) => { + plugins?.map(klass => { + if (Array.isArray(klass)) { + klass = klass[0]; + } + // 处理插件身上的场景信息 const scene = Array.from( new Set(['global'].concat(klass.scene || 'global')) diff --git a/packages/amis-editor-core/src/tpl.tsx b/packages/amis-editor-core/src/tpl.tsx index 53eea87d1..074ac0ef2 100644 --- a/packages/amis-editor-core/src/tpl.tsx +++ b/packages/amis-editor-core/src/tpl.tsx @@ -1,4 +1,4 @@ -import type {SchemaObject} from 'amis/lib/Schema'; +import type {SchemaObject} from 'amis'; /** * @file amis schema 配置模板,主要很多地方都要全部配置的化, diff --git a/packages/amis-editor-core/src/util.ts b/packages/amis-editor-core/src/util.ts index 01ed8896e..6013f5096 100644 --- a/packages/amis-editor-core/src/util.ts +++ b/packages/amis-editor-core/src/util.ts @@ -8,7 +8,7 @@ import DeepDiff, {Diff} from 'deep-diff'; import isPlainObject from 'lodash/isPlainObject'; import isNumber from 'lodash/isNumber'; import type {Schema} from 'amis'; -import type {SchemaObject} from 'amis/lib/Schema'; +import type {SchemaObject} from 'amis'; import {assign, cloneDeep} from 'lodash'; import {getGlobalData} from 'amis-theme-editor-helper'; diff --git a/packages/amis-editor/src/component/TableViewEditor.tsx b/packages/amis-editor/src/component/TableViewEditor.tsx index 92451f914..b491ec3f2 100644 --- a/packages/amis-editor/src/component/TableViewEditor.tsx +++ b/packages/amis-editor/src/component/TableViewEditor.tsx @@ -5,11 +5,7 @@ import React from 'react'; import isEqual from 'lodash/isEqual'; import {toast} from 'amis'; -import { - TableViewSchema, - TdObject, - TrObject -} from 'amis/lib/renderers/TableView'; +import {TableViewSchema, TrObject} from 'amis'; import {EditorManager} from 'amis-editor-core'; import {autobind, JSONGetById, EditorStoreType} from 'amis-editor-core'; diff --git a/packages/amis-editor/src/plugin/Alert.tsx b/packages/amis-editor/src/plugin/Alert.tsx index 8d2e1fe7d..fd3a86c84 100644 --- a/packages/amis-editor/src/plugin/Alert.tsx +++ b/packages/amis-editor/src/plugin/Alert.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {registerEditorPlugin} from 'amis-editor-core'; import {BaseEventContext, BasePlugin} from 'amis-editor-core'; import {getSchemaTpl} from 'amis-editor-core'; -import type {SchemaObject} from 'amis/lib/Schema'; +import type {SchemaObject} from 'amis'; export class AlertPlugin extends BasePlugin { static scene = ['layout']; diff --git a/packages/amis-editor/src/plugin/Button.tsx b/packages/amis-editor/src/plugin/Button.tsx index 4c1a98562..357bf42e5 100644 --- a/packages/amis-editor/src/plugin/Button.tsx +++ b/packages/amis-editor/src/plugin/Button.tsx @@ -11,7 +11,7 @@ import {defaultValue, getSchemaTpl} from 'amis-editor-core'; import {BUTTON_DEFAULT_ACTION} from '../component/BaseControl'; import {getEventControlConfig} from '../renderer/event-control/helper'; import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core'; -import type {SchemaObject} from 'amis/lib/Schema'; +import type {SchemaObject} from 'amis'; import {getOldActionSchema} from '../renderer/event-control/helper'; export class ButtonPlugin extends BasePlugin { diff --git a/packages/amis-editor/src/plugin/CRUD.tsx b/packages/amis-editor/src/plugin/CRUD.tsx index 177d613df..7bb1d2c4b 100644 --- a/packages/amis-editor/src/plugin/CRUD.tsx +++ b/packages/amis-editor/src/plugin/CRUD.tsx @@ -24,8 +24,8 @@ import { import {defaultValue, getSchemaTpl} from 'amis-editor-core'; import {isObject, JSONPipeIn} from 'amis-editor-core'; import {setVariable} from 'amis-core'; -import {ActionSchema} from 'amis/lib/renderers/Action'; -import {CRUDCommonSchema} from 'amis/lib/renderers/CRUD'; +import type {ActionSchema} from 'amis'; +import type {CRUDCommonSchema} from 'amis'; import {getEnv} from 'mobx-state-tree'; import {EditorNodeType, RendererPluginAction} from 'amis-editor-core'; import {normalizeApi} from 'amis-core'; diff --git a/packages/amis-editor/src/plugin/CRUD2.tsx b/packages/amis-editor/src/plugin/CRUD2.tsx index 0e7fc9470..6dca3bd6f 100644 --- a/packages/amis-editor/src/plugin/CRUD2.tsx +++ b/packages/amis-editor/src/plugin/CRUD2.tsx @@ -24,10 +24,10 @@ import { RendererPluginEvent } from 'amis-editor-core'; import {flattenDeep, fromPairs, isObject, remove} from 'lodash'; -import type {ButtonSchema} from 'amis/lib/renderers/Action'; -import type {FormSchema, SchemaObject} from 'amis/lib/Schema'; +import type {ButtonSchema} from 'amis'; +import type {FormSchema, SchemaObject} from 'amis'; import {findTree} from 'amis'; -import type {CRUD2Schema} from 'amis/lib/renderers/CRUD2'; +import type {CRUD2Schema} from 'amis'; import {FeatureOption} from '../renderer/FeatureControl'; import {getArgsWrapper} from '../renderer/event-control/helper'; diff --git a/packages/amis-editor/src/plugin/Form/CodeEditor.tsx b/packages/amis-editor/src/plugin/Form/CodeEditor.tsx index 710ee2dca..ffa4ca9d9 100644 --- a/packages/amis-editor/src/plugin/Form/CodeEditor.tsx +++ b/packages/amis-editor/src/plugin/Form/CodeEditor.tsx @@ -1,4 +1,4 @@ -import {availableLanguages} from 'amis/lib/renderers/Form/Editor'; +import {EditorAvailableLanguages as availableLanguages} from 'amis'; import {defaultValue, getSchemaTpl, undefinedPipeOut} from 'amis-editor-core'; import {registerEditorPlugin} from 'amis-editor-core'; import {BasePlugin} from 'amis-editor-core'; diff --git a/packages/amis-editor/src/plugin/Form/DiffEditor.tsx b/packages/amis-editor/src/plugin/Form/DiffEditor.tsx index 960a33844..fed3b5c1e 100644 --- a/packages/amis-editor/src/plugin/Form/DiffEditor.tsx +++ b/packages/amis-editor/src/plugin/Form/DiffEditor.tsx @@ -1,4 +1,4 @@ -import {availableLanguages} from 'amis/lib/renderers/Form/Editor'; +import {EditorAvailableLanguages as availableLanguages} from 'amis'; import { defaultValue, getSchemaTpl, diff --git a/packages/amis-editor/src/plugin/Form/InputSubForm.tsx b/packages/amis-editor/src/plugin/Form/InputSubForm.tsx index 902b0b7f8..09f580171 100644 --- a/packages/amis-editor/src/plugin/Form/InputSubForm.tsx +++ b/packages/amis-editor/src/plugin/Form/InputSubForm.tsx @@ -1,5 +1,5 @@ import {Button} from 'amis'; -import type {SchemaCollection} from 'amis/lib/Schema'; +import type {SchemaCollection} from 'amis'; import React from 'react'; import { BaseEventContext, diff --git a/packages/amis-editor/src/plugin/Form/NestedSelect.tsx b/packages/amis-editor/src/plugin/Form/NestedSelect.tsx index 26bd584dc..a9fa46e01 100644 --- a/packages/amis-editor/src/plugin/Form/NestedSelect.tsx +++ b/packages/amis-editor/src/plugin/Form/NestedSelect.tsx @@ -1,16 +1,7 @@ -import {relativeValueRe} from 'amis'; import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core'; -import {availableLanguages} from 'amis/lib/renderers/Form/Editor'; -import {defaultValue, getSchemaTpl, valuePipeOut} from 'amis-editor-core'; +import {getSchemaTpl} from 'amis-editor-core'; import {registerEditorPlugin} from 'amis-editor-core'; -import { - BasePlugin, - BasicSubRenderInfo, - RendererEventContext, - SubRendererInfo, - BaseEventContext, - tipedLabel -} from 'amis-editor-core'; +import {BasePlugin, BaseEventContext, tipedLabel} from 'amis-editor-core'; import {ValidatorTag} from '../../validator'; import {getEventControlConfig} from '../../renderer/event-control/helper'; diff --git a/packages/amis-editor/src/plugin/Others/Action.tsx b/packages/amis-editor/src/plugin/Others/Action.tsx index 8e5a8ed03..7906798ae 100644 --- a/packages/amis-editor/src/plugin/Others/Action.tsx +++ b/packages/amis-editor/src/plugin/Others/Action.tsx @@ -10,7 +10,7 @@ import { } from 'amis-editor-core'; import {defaultValue, getSchemaTpl} from 'amis-editor-core'; import {diff} from 'amis-editor-core'; -import type {SchemaCollection} from 'amis/lib/Schema'; +import type {SchemaCollection} from 'amis'; export class ActionPlugin extends BasePlugin { panelTitle = '按钮'; diff --git a/packages/amis-editor/src/plugin/Page.tsx b/packages/amis-editor/src/plugin/Page.tsx index 32730cbb7..ba563d6f5 100644 --- a/packages/amis-editor/src/plugin/Page.tsx +++ b/packages/amis-editor/src/plugin/Page.tsx @@ -8,7 +8,7 @@ import { } from 'amis-editor-core'; import {getEventControlConfig} from '../renderer/event-control/helper'; import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core'; -import type {SchemaObject} from 'amis/lib/Schema'; +import type {SchemaObject} from 'amis'; import {tipedLabel} from 'amis-editor-core'; import {jsonToJsonSchema, EditorNodeType} from 'amis-editor-core'; diff --git a/packages/amis-editor/src/plugin/SearchBox.tsx b/packages/amis-editor/src/plugin/SearchBox.tsx index a5fc28989..8e65eab3f 100644 --- a/packages/amis-editor/src/plugin/SearchBox.tsx +++ b/packages/amis-editor/src/plugin/SearchBox.tsx @@ -8,7 +8,7 @@ import { import {getSchemaTpl} from 'amis-editor-core'; import {getEventControlConfig} from '../renderer/event-control/helper'; -import type {SchemaObject} from 'amis/lib/Schema'; +import type {Schema} from 'amis-core'; export class SearchBoxPlugin extends BasePlugin { // 关联渲染器名字 @@ -25,7 +25,7 @@ export class SearchBoxPlugin extends BasePlugin { pluginIcon = 'search-box-plugin'; tags = ['表单项']; - scaffold: SchemaObject = { + scaffold: Schema = { type: 'search-box', body: { type: 'tpl', diff --git a/packages/amis-editor/src/plugin/Table.tsx b/packages/amis-editor/src/plugin/Table.tsx index 15a256832..13c6f3a09 100644 --- a/packages/amis-editor/src/plugin/Table.tsx +++ b/packages/amis-editor/src/plugin/Table.tsx @@ -22,7 +22,7 @@ import { import {defaultValue, getSchemaTpl, tipedLabel} from 'amis-editor-core'; import {mockValue} from 'amis-editor-core'; import {EditorNodeType} from 'amis-editor-core'; -import type {SchemaObject} from 'amis/lib/Schema'; +import type {SchemaObject} from 'amis'; import { getEventControlConfig, getArgsWrapper diff --git a/packages/amis-editor/src/plugin/Table2.tsx b/packages/amis-editor/src/plugin/Table2.tsx index 8e3dec258..8def5d840 100644 --- a/packages/amis-editor/src/plugin/Table2.tsx +++ b/packages/amis-editor/src/plugin/Table2.tsx @@ -25,7 +25,7 @@ import { getEventControlConfig, getArgsWrapper } from '../renderer/event-control/helper'; -import type {SchemaObject} from 'amis/lib/Schema'; +import type {SchemaObject} from 'amis'; export class Table2Plugin extends BasePlugin { // 关联渲染器名字 diff --git a/packages/amis-editor/src/plugin/TableCell2.tsx b/packages/amis-editor/src/plugin/TableCell2.tsx index f718bc1e7..4c0654709 100644 --- a/packages/amis-editor/src/plugin/TableCell2.tsx +++ b/packages/amis-editor/src/plugin/TableCell2.tsx @@ -16,8 +16,8 @@ import { } from 'amis-editor-core'; import type {DSField} from 'amis-editor-core'; import {fromPairs} from 'lodash'; -import type {TabsSchema} from 'amis/lib/renderers/Tabs'; -import type {SchemaObject} from 'amis/lib/Schema'; +import type {TabsSchema} from 'amis'; +import type {SchemaObject} from 'amis'; import {remarkTpl} from '../component/BaseControl'; export class TableCell2Plugin extends BasePlugin { diff --git a/packages/amis-editor/src/plugin/TableView.tsx b/packages/amis-editor/src/plugin/TableView.tsx index 68752335b..9db5210d4 100644 --- a/packages/amis-editor/src/plugin/TableView.tsx +++ b/packages/amis-editor/src/plugin/TableView.tsx @@ -16,7 +16,7 @@ import { } from 'amis-editor-core'; import {defaultValue, getSchemaTpl} from 'amis-editor-core'; import {VRenderer} from 'amis-editor-core'; -import type {TableViewSchema} from 'amis/lib/renderers/TableView'; +import type {TableViewSchema} from 'amis'; import {JSONGetById} from 'amis-editor-core'; import {TableViewEditor} from '../component/TableViewEditor'; diff --git a/packages/amis-editor/src/renderer/APIAdaptorControl.tsx b/packages/amis-editor/src/renderer/APIAdaptorControl.tsx index d6c11a1b6..09be6e6c7 100644 --- a/packages/amis-editor/src/renderer/APIAdaptorControl.tsx +++ b/packages/amis-editor/src/renderer/APIAdaptorControl.tsx @@ -53,7 +53,6 @@ export default class APIAdaptorControl extends React.Component< APIAdaptorControlProps, APIAdaptorControlState > { - static defaultProps: Pick = { params: [] }; @@ -89,13 +88,12 @@ export default class APIAdaptorControl extends React.Component< ...(typeof content === 'string' ? {content} : { - content: ' ', // amis缺陷,必须有这个字段,否则显示不出来 - children: () => content - } - ), - ...this.props.tooltipProps || {}, - ...othersProps || {} - } + content: ' ', // amis缺陷,必须有这个字段,否则显示不出来 + children: () => content + }), + ...(this.props.tooltipProps || {}), + ...(othersProps || {}) + }; } renderEditor() { @@ -114,8 +112,8 @@ export default class APIAdaptorControl extends React.Component< mergeParams } = this.props; - const lastParams = typeof mergeParams === 'function' - ? mergeParams(params) : params; + const lastParams = + typeof mergeParams === 'function' ? mergeParams(params) : params; return render('api-adaptor-control-editor', [ { @@ -124,20 +122,22 @@ export default class APIAdaptorControl extends React.Component< body: [ 'function ', '(', - ...lastParams.map(({label, tip}, index) => { - return [ - { - type: 'button', - level: 'link', - label, - className: 'ae-AdaptorControl-func-arg', - ...tip ? {tooltip: this.genTooltipProps(tip)} : {} - }, - ...(index === lastParams.length - 1 - ? [] : [''] - ) - ] - }).flat(), + ...lastParams + .map(({label, tip}, index) => { + return [ + { + type: 'button', + level: 'link', + label, + className: 'ae-AdaptorControl-func-arg', + ...(tip ? {tooltip: this.genTooltipProps(tip)} : {}) + }, + ...(index === lastParams.length - 1 + ? [] + : ['']) + ]; + }) + .flat(), ') {' ] }, @@ -190,20 +190,20 @@ export default class APIAdaptorControl extends React.Component< }); } }, - ...switchTip ? [ - - - - ] : [] + ...(switchTip + ? [ + + + + ] + : []) ] }); } @@ -216,7 +216,7 @@ export default class APIAdaptorControl extends React.Component< {this.renderSwitch()} {this.renderEditor()} - ) + ); } } @FormItem({ @@ -232,11 +232,14 @@ export class APIAdaptorControlRenderer extends APIAdaptorControl {} */ const genCodeSchema = (code: string, size?: string[]) => ({ type: 'container', - ...!size ? {} - : {style: { - width: size[0], - height: size[1] - }}, + ...(!size + ? {} + : { + style: { + width: size[0], + height: size[1] + } + }), body: { type: 'code', language: 'typescript', @@ -246,8 +249,7 @@ const genCodeSchema = (code: string, size?: string[]) => ({ }); // 请求适配器 示例代码 -export const requestAdaptorDefaultCode = -`api.data.count = api.data.count + 1; +export const requestAdaptorDefaultCode = `api.data.count = api.data.count + 1; return api;`; // 适配器 适配器 api 参数说明 @@ -259,9 +261,9 @@ export const adaptorApiStruct = `{ ... }`; -export const adaptorApiStructTooltip = - render(genCodeSchema(adaptorApiStruct, ['350px', '128px'])) -; +export const adaptorApiStructTooltip = render( + genCodeSchema(adaptorApiStruct, ['350px', '128px']) +); // 适配器 response 参数说明 export const adaptorResponseStruct = `{ @@ -273,13 +275,12 @@ export const adaptorResponseStruct = `{ ... }`; -export const adaptorResponseStructTooltip = - render(genCodeSchema(adaptorResponseStruct, ['345px', '144px'])) -; +export const adaptorResponseStructTooltip = render( + genCodeSchema(adaptorResponseStruct, ['345px', '144px']) +); // 接收适配器 示例代码 -export const adaptorDefaultCode = -`// API响应或自定义处理后需要符合以下格式 +export const adaptorDefaultCode = `// API响应或自定义处理后需要符合以下格式 return { status: 0, // 0 表示请求成功,否则按错误处理 msg: '请求成功', @@ -291,8 +292,7 @@ return { } }`; -export const validateApiAdaptorDefaultCode = -`// 校验成功 +export const validateApiAdaptorDefaultCode = `// 校验成功 return { status: 0 }; diff --git a/packages/amis-editor/src/renderer/APIControl.tsx b/packages/amis-editor/src/renderer/APIControl.tsx index 2be9f9b82..e4189cab0 100644 --- a/packages/amis-editor/src/renderer/APIControl.tsx +++ b/packages/amis-editor/src/renderer/APIControl.tsx @@ -17,10 +17,10 @@ import { getSchemaTpl } from 'amis-editor-core'; -import type {SchemaObject, SchemaCollection, SchemaApi} from 'amis/lib/Schema'; +import type {SchemaObject, SchemaCollection, SchemaApi} from 'amis'; import type {Api} from 'amis'; import type {FormControlProps} from 'amis-core'; -import type {ActionSchema} from 'amis/lib/renderers/Action'; +import type {ActionSchema} from 'amis'; export type ApiObject = Api & { messages?: Record< @@ -913,9 +913,7 @@ export default class APIControl extends React.Component< ] }, getSchemaTpl( - name === 'validateApi' - ? 'validateApiAdaptor' - : 'apiAdaptor' + name === 'validateApi' ? 'validateApiAdaptor' : 'apiAdaptor' ) ] }, diff --git a/packages/amis-editor/src/renderer/ActionApiControl.tsx b/packages/amis-editor/src/renderer/ActionApiControl.tsx index 11141e0f2..52976bf6d 100644 --- a/packages/amis-editor/src/renderer/ActionApiControl.tsx +++ b/packages/amis-editor/src/renderer/ActionApiControl.tsx @@ -8,13 +8,19 @@ import {PickerContainer} from 'amis-ui'; import {getEnv} from 'mobx-state-tree'; import {normalizeApi, isEffectiveApi, isApiOutdated} from 'amis-core'; -import {autobind, isObject, anyChanged, createObject, getSchemaTpl} from 'amis-editor-core'; +import { + autobind, + isObject, + anyChanged, + createObject, + getSchemaTpl +} from 'amis-editor-core'; import {tipedLabel} from 'amis-editor-core'; -import type {SchemaObject, SchemaCollection, SchemaApi} from 'amis/lib/Schema'; +import type {SchemaObject, SchemaCollection, SchemaApi} from 'amis'; import type {Api} from 'amis'; import type {FormControlProps} from 'amis-core'; -import type {ActionSchema} from 'amis/lib/renderers/Action'; +import type {ActionSchema} from 'amis'; export interface APIControlProps extends FormControlProps { name?: string; @@ -754,7 +760,7 @@ export default class APIControl extends React.Component< ] }, getSchemaTpl('apiRequestAdaptor'), - getSchemaTpl('apiAdaptor'), + getSchemaTpl('apiAdaptor') ] }, { diff --git a/packages/amis-editor/src/renderer/BadgeControl.tsx b/packages/amis-editor/src/renderer/BadgeControl.tsx index 232e14793..e469c6721 100644 --- a/packages/amis-editor/src/renderer/BadgeControl.tsx +++ b/packages/amis-editor/src/renderer/BadgeControl.tsx @@ -18,7 +18,7 @@ import { import {defaultValue, tipedLabel} from 'amis-editor-core'; import type {FormControlProps} from 'amis-core'; -import type {SchemaExpression} from 'amis/lib/Schema'; +import type {SchemaExpression} from 'amis'; export interface BadgeControlProps extends FormControlProps { /** diff --git a/packages/amis-editor/src/renderer/DataBindingControl.tsx b/packages/amis-editor/src/renderer/DataBindingControl.tsx index d05374824..1bbeef1a9 100644 --- a/packages/amis-editor/src/renderer/DataBindingControl.tsx +++ b/packages/amis-editor/src/renderer/DataBindingControl.tsx @@ -21,7 +21,7 @@ import React from 'react'; import {EditorManager, EditorNodeType, autobind} from 'amis-editor-core'; import type {DSField, DSFieldGroup} from 'amis-editor-core'; import {matchSorter} from 'match-sorter'; -import type {SchemaCollection} from 'amis/lib/Schema'; +import type {SchemaCollection} from 'amis'; import {default as cx} from 'classnames'; export interface DataBindingProps extends FormControlProps { diff --git a/packages/amis-editor/src/renderer/MapSourceControl.tsx b/packages/amis-editor/src/renderer/MapSourceControl.tsx index 46bea0221..69abfea65 100644 --- a/packages/amis-editor/src/renderer/MapSourceControl.tsx +++ b/packages/amis-editor/src/renderer/MapSourceControl.tsx @@ -7,7 +7,7 @@ import cx from 'classnames'; import {FormItem} from 'amis'; import {autobind, getSchemaTpl, tipedLabel} from 'amis-editor-core'; import {FormControlProps, isObject} from 'amis-core'; -import type {SchemaApi} from 'amis/lib/Schema'; +import type {SchemaApi} from 'amis'; import debounce from 'lodash/debounce'; enum MapType { diff --git a/packages/amis-editor/src/renderer/NavBadgeControl.tsx b/packages/amis-editor/src/renderer/NavBadgeControl.tsx index 2c448ca59..91c31e127 100644 --- a/packages/amis-editor/src/renderer/NavBadgeControl.tsx +++ b/packages/amis-editor/src/renderer/NavBadgeControl.tsx @@ -16,7 +16,7 @@ import { import {defaultValue, tipedLabel, getSchemaTpl} from 'amis-editor-core'; import type {FormControlProps} from 'amis-core'; -import type {SchemaExpression} from 'amis/lib/Schema'; +import type {SchemaExpression} from 'amis'; export interface BadgeControlProps extends FormControlProps { /** @@ -325,7 +325,7 @@ export default class BadgeControl extends React.Component< name: 'checked', mode: 'horizontal', value: checked, - onChange: checked => this.handleSwitchChange(checked) + onChange: (checked: boolean) => this.handleSwitchChange(checked) }) )} {checked ? this.renderBody() : null} diff --git a/packages/amis-editor/src/renderer/NavDefaultActive.tsx b/packages/amis-editor/src/renderer/NavDefaultActive.tsx index 4022893cd..4d7986876 100644 --- a/packages/amis-editor/src/renderer/NavDefaultActive.tsx +++ b/packages/amis-editor/src/renderer/NavDefaultActive.tsx @@ -22,7 +22,7 @@ export default class NavDefaultActiveControl extends React.Component< super(props); } - deleteActive(data) { + deleteActive(data: any) { for (let item of data) { if (item.active) { delete item.active; @@ -33,7 +33,7 @@ export default class NavDefaultActiveControl extends React.Component< } } - findActiveKey(data, index?: string) { + findActiveKey(data: any, index?: string) { for (let i = 0; i < data.length; i++) { const item = data[i]; if (item.active) { diff --git a/packages/amis-editor/src/renderer/NavSourceControl.tsx b/packages/amis-editor/src/renderer/NavSourceControl.tsx index e728f260e..4fe34be61 100644 --- a/packages/amis-editor/src/renderer/NavSourceControl.tsx +++ b/packages/amis-editor/src/renderer/NavSourceControl.tsx @@ -12,7 +12,7 @@ import {FormItem, Button, InputBox, Switch, Radios} from 'amis'; import {autobind} from 'amis-editor-core'; import {getSchemaTpl} from 'amis-editor-core'; import type {FormControlProps} from 'amis-core'; -import type {SchemaApi} from 'amis/lib/Schema'; +import type {SchemaApi} from 'amis'; export type valueType = 'text' | 'boolean' | 'number'; @@ -402,7 +402,7 @@ export default class NavSourceControl extends React.Component< {children && children.length ? ( <> - {children.map((item, id: number) => { + {children.map((item: any, id: number) => { return this.renderOption({...item, index: `${index}_${id}`}); })}