Skip to content

Commit

Permalink
Merge branch 'master' into style/dark-code
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed Feb 29, 2024
2 parents 9e93ea3 + 134ce72 commit 26f143c
Show file tree
Hide file tree
Showing 86 changed files with 1,695 additions and 646 deletions.
23 changes: 23 additions & 0 deletions .swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true,
"dynamicImport": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true,
"react": {
"runtime": "classic"
}
},
"keepClassNames": true,
"externalHelpers": true,
"loose": false
},
"sourceMaps": true,
"minify": false
}
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[文档(国外)](https://baidu.github.io/amis/) |
[可视化编辑器](https://aisuda.github.io/amis-editor-demo/) |
[amis-admin](https://github.com/aisuda/amis-admin) |
[爱速搭](https://aisuda.bce.baidu.com/aisuda-docs/)
[爱速搭](https://aisuda.baidu.com/)

</div>

Expand Down Expand Up @@ -63,7 +63,13 @@ npm test --workspaces

# 测试某个用例
# <spec-name>为用例名称,比如inputImage
npm test --workspace amis <spec-name>
npm test --workspace amis -- -t <spec-name>

# 运行某个单测文件
./node_modules/.bin/jest packages/amis/__tests__/renderers/Form/buttonToolBar.test.tsx

# 运行某个单测文件里的某个例子
./node_modules/.bin/jest packages/amis/__tests__/renderers/Form/buttonToolBar.test.tsx -t 'Renderer:button-toolbar'

# 查看测试用例覆盖率
npm run coverage
Expand All @@ -73,7 +79,7 @@ npm run update-snapshot

# 更新单个 snapshot
# <spec-name>为用例名称,比如inputImage
npm run update-snapshot --workspace amis <spec-name>
npm run update-snapshot --workspace amis -- -t <spec-name>
```

### 发布版本
Expand Down Expand Up @@ -106,4 +112,4 @@ npm run release

## 低代码平台

amis 只能实现前端低代码,如果需要完整的低代码平台推荐使用[爱速搭](https://aisuda.bce.baidu.com/aisuda-docs/)
amis 只能实现前端低代码,如果需要完整的低代码平台推荐使用[爱速搭](https://aisuda.baidu.com/)
69 changes: 69 additions & 0 deletions docs/zh-CN/concepts/event-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,75 @@ run action ajax
| copyFormat | `string` | `text/html` | 复制格式 |
| content | [模板](../../docs/concepts/template) | - | 指定复制的内容。可用 `${xxx}` 取值 |

### 打印

> 6.2.0 及以后版本
打印页面中的某个组件,对应的组件需要配置 `testid`,如果要打印多个,可以使用 `"testids": ["x", "y"]` 来打印多个组件

```schema
{
type: 'page',
body: [
{
type: 'button',
label: '打印',
level: 'primary',
className: 'mr-2',
onEvent: {
click: {
actions: [
{
actionType: 'print',
args: {
testid: 'mycrud'
}
}
]
}
}
},
{
"type": "crud",
"api": "/api/mock2/sample",
"testid": "mycrud",
"syncLocation": false,
"columns": [
{
"name": "id",
"label": "ID"
},
{
"name": "engine",
"label": "Rendering engine"
},
{
"name": "browser",
"label": "Browser"
},
{
"name": "platform",
"label": "Platform(s)"
},
{
"name": "version",
"label": "Engine version"
},
{
"name": "grade",
"label": "CSS grade"
}
]
}
]
}
```

| 属性名 | 类型 | 默认值 | 说明 |
| ------- | ---------- | ------ | ----------------- |
| testid | `string` | | 组件的 testid |
| testids | `string[]` | - | 多个组件的 testid |

### 发送邮件

通过配置`actionType: 'email'`和邮件属性实现发送邮件操作。
Expand Down
11 changes: 10 additions & 1 deletion examples/components/CRUD/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,16 @@ export default {
body: {
type: 'form',
name: 'sample-edit-form',
api: '/api/sample/$id',
data:{
env: 'test'
},
api: {
method:'post',
url:'/api/sample/$id',
messages:{
success: '成功了-${env}'
}
},
body: [
{
type: 'input-text',
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
"@babel/types": "^7.22.5",
"@fortawesome/fontawesome-free": "^6.1.1",
"@rollup/plugin-replace": "^5.0.1",
"@swc/core": "^1.3.107",
"@swc/helpers": "^0.5.3",
"@swc/jest": "^0.2.34",
"@types/express": "^4.17.14",
"@types/jest": "^28.1.0",
"@types/js-yaml": "^4.0.5",
Expand Down Expand Up @@ -117,7 +120,9 @@
"tsx",
"js"
],
"preset": "ts-jest",
"transform": {
"^.+\\.(t|j)sx?$": "@swc/jest"
},
"setupFiles": [
"jest-canvas-mock"
],
Expand All @@ -144,4 +149,4 @@
"printBasicPrototype": false
}
}
}
}
22 changes: 22 additions & 0 deletions packages/amis-core/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true,
"dynamicImport": true
},
"transform": {
"decoratorMetadata": true,
"legacyDecorator": true,
"react": {
"runtime": "classic"
}
},
"keepClassNames": true,
"externalHelpers": true,
"loose": false
},
"minify": false
}
1 change: 1 addition & 0 deletions packages/amis-core/__tests__/scoped.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {makeEnv} from './helper';
test('Scoped splitTarget', async () => {
expect(splitTarget('abc')).toEqual(['abc']);
expect(splitTarget('a,b,c')).toEqual(['a', 'b', 'c']);
expect(splitTarget('a, b, c ')).toEqual(['a', 'b', 'c']);
expect(splitTarget('a?x=1&y=2,b,c')).toEqual(['a?x=1&y=2', 'b', 'c']);
expect(splitTarget('a?x=${[a, b]},b,c')).toEqual(['a?x=${[a, b]}', 'b', 'c']);
expect(splitTarget('a?x=${[a, b]}')).toEqual(['a?x=${[a, b]}']);
Expand Down
9 changes: 2 additions & 7 deletions packages/amis-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@
"js"
],
"transform": {
"\\.(ts|tsx)$": [
"ts-jest",
{
"diagnostics": false
}
]
"^.+\\.(t|j)sx?$": "@swc/jest"
},
"setupFiles": [
"jest-canvas-mock"
Expand All @@ -109,4 +104,4 @@
]
},
"gitHead": "37d23b4a8eb1c663bc38e8dd9040889ea1526ec4"
}
}
2 changes: 1 addition & 1 deletion packages/amis-core/src/Scoped.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function splitTarget(target: string): Array<string> {
let parts: Array<string> = [];

pos.reduceRight((arr: Array<string>, index) => {
arr.unshift(target.slice(index + 1));
arr.unshift(target.slice(index + 1)?.trim());
target = target.slice(0, index);
return arr;
}, parts);
Expand Down
2 changes: 1 addition & 1 deletion packages/amis-core/src/WithStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export function HocStoreFactory(renderer: {
props.store?.storeType === 'ComboStore'
? undefined
: syncDataFromSuper(
store.data,
{...store.data, ...props.data},
(props.data as any).__super,
(prevProps.data as any).__super,
store,
Expand Down
51 changes: 51 additions & 0 deletions packages/amis-core/src/actions/PrintAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {printElements} from '../utils/printElement';
import {RendererEvent} from '../utils/renderer-event';
import {
RendererAction,
ListenerAction,
ListenerContext,
registerAction
} from './Action';

export interface IPrintAction extends ListenerAction {
actionType: 'copy';
args: {
testid?: string;
testids?: string[];
};
}

/**
* 打印动作
*
* @export
* @class PrintAction
* @implements {Action}
*/
export class PrintAction implements RendererAction {
async run(
action: IPrintAction,
renderer: ListenerContext,
event: RendererEvent<any>
) {
if (action.args?.testid) {
const element = document.querySelector(
`[data-testid='${action.args.testid}']`
);
if (element) {
printElements([element]);
}
} else if (action.args?.testids) {
const elements: Element[] = [];
action.args.testids.forEach(testid => {
const element = document.querySelector(`[data-testid='${testid}']`);
if (element) {
elements.push(element);
}
});
printElements(elements);
}
}
}

registerAction('print', new PrintAction());
1 change: 1 addition & 0 deletions packages/amis-core/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ import './EmailAction';
import './LinkAction';
import './ToastAction';
import './PageAction';
import './PrintAction';

export * from './Action';
3 changes: 2 additions & 1 deletion packages/amis-core/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ export {
splitTarget,
CustomStyle,
enableDebug,
disableDebug
disableDebug,
envOverwrite
};

export function render(
Expand Down
6 changes: 4 additions & 2 deletions packages/amis-core/src/renderers/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import LazyComponent from '../components/LazyComponent';
import {isAlive} from 'mobx-state-tree';

import type {LabelAlign} from './Item';
import {injectObjectChain} from '../utils';
import {buildTestId, injectObjectChain} from '../utils';
import {reaction} from 'mobx';

export interface FormHorizontal {
Expand Down Expand Up @@ -1808,7 +1808,8 @@ export default class Form extends React.Component<FormProps, object> {
render,
staticClassName,
static: isStatic = false,
loadingConfig
loadingConfig,
testid
} = this.props;

const {restError} = store;
Expand Down Expand Up @@ -1840,6 +1841,7 @@ export default class Form extends React.Component<FormProps, object> {
)}
onSubmit={this.handleFormSubmit}
noValidate
{...buildTestId(testid)}
>
{/* 实现回车自动提交 */}
<input type="submit" style={{display: 'none'}} />
Expand Down
20 changes: 16 additions & 4 deletions packages/amis-core/src/renderers/wrapControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ export function wrapControl<

setInitialValue(value: any) {
const model = this.model!;
const {formStore: form, data} = this.props;
const {formStore: form, data, canAccessSuperData} = this.props;
const isExp = isExpression(value);

if (isExp) {
Expand All @@ -479,10 +479,22 @@ export function wrapControl<
} else {
let initialValue = model.extraName
? [
getVariable(data, model.name, form?.canAccessSuperData),
getVariable(data, model.extraName, form?.canAccessSuperData)
getVariable(
data,
model.name,
canAccessSuperData ?? form?.canAccessSuperData
),
getVariable(
data,
model.extraName,
canAccessSuperData ?? form?.canAccessSuperData
)
]
: getVariable(data, model.name, form?.canAccessSuperData);
: getVariable(
data,
model.name,
canAccessSuperData ?? form?.canAccessSuperData
);

if (
model.extraName &&
Expand Down

0 comments on commit 26f143c

Please sign in to comment.