feat: jsparse, jscode tooptip (#1303)

Co-authored-by: sealday <zhanglin@daoyoucloud.com>
Reviewed-on: https://git.daoyoucloud.com:8443/daoyoucloud/tachybase/pulls/1303
This commit is contained in:
bai.zixv 2024-07-11 14:28:24 +08:00
parent d3b01736a7
commit 627c88ed83
6 changed files with 89 additions and 4 deletions

View File

@ -21,6 +21,7 @@
"@formily/reactive-react": "2.3.1", "@formily/reactive-react": "2.3.1",
"@formily/shared": "2.3.1", "@formily/shared": "2.3.1",
"@formily/validator": "2.3.1", "@formily/validator": "2.3.1",
"@uiw/codemirror-theme-vscode": "^4.23.0",
"@uiw/react-codemirror": "^4.22.2", "@uiw/react-codemirror": "^4.22.2",
"antd": "5.19.1", "antd": "5.19.1",
"classnames": "^2.5.1", "classnames": "^2.5.1",

View File

@ -3,6 +3,7 @@ import { connect } from '@tachybase/schema';
import { autocompletion } from '@codemirror/autocomplete'; import { autocompletion } from '@codemirror/autocomplete';
import { javascript } from '@codemirror/lang-javascript'; import { javascript } from '@codemirror/lang-javascript';
import { vscodeDark } from '@uiw/codemirror-theme-vscode';
import CM from '@uiw/react-codemirror'; import CM from '@uiw/react-codemirror';
// 定义全局对象和子对象的补全项 // 定义全局对象和子对象的补全项
@ -83,6 +84,7 @@ export const CodeMirror = connect(({ value, onChange, ...otherProps }) => {
value={value || ''} value={value || ''}
onChange={onChange} onChange={onChange}
{...otherProps} {...otherProps}
theme={vscodeDark}
extensions={[ extensions={[
javascript({ jsx: true }), javascript({ jsx: true }),
autocompletion({ autocompletion({

View File

@ -27,6 +27,9 @@ export class JSParseInstruction extends Instruction {
type: 'string', type: 'string',
title: tval('JSCode expression'), title: tval('JSCode expression'),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-decorator-props': {
tooltip: 'ctx.data\nctx.body\n__ctx\nlib.JSON\nlib.qrcode\ncanvas\nlib.dayjs\nlib.log',
},
'x-component': 'CodeMirror', 'x-component': 'CodeMirror',
required: true, required: true,
}, },

View File

@ -27,7 +27,7 @@ export class JSONParseInstruction extends Instruction {
type: 'string', type: 'string',
title: tval('Query expression'), title: tval('Query expression'),
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Input.TextArea', 'x-component': 'CodeMirror',
}, },
model: { model: {
type: 'array', type: 'array',

View File

@ -1,3 +1,5 @@
import crypto from 'crypto';
import * as canvas from 'canvas'; import * as canvas from 'canvas';
import _ from 'lodash'; import _ from 'lodash';
import qrcode from 'qrcode'; import qrcode from 'qrcode';
@ -19,6 +21,7 @@ export class JSParseInstruction extends Instruction {
JSON, JSON,
canvas, canvas,
qrcode, qrcode,
crypto,
log: console.log, log: console.log,
}, },
}); });
@ -62,7 +65,7 @@ function mapModel(data, model) {
} }
async function evalSimulate(jsCode, { ctx, lib }) { async function evalSimulate(jsCode, { ctx, lib }) {
const AsyncFunction = async function () {}.constructor; const AsyncFunction: any = async function () {}.constructor;
return await new AsyncFunction('$root', `with($root) { ${jsCode}; }`)({ return await new AsyncFunction('$root', `with($root) { ${jsCode}; }`)({
ctx, ctx,
// 允许用户覆盖,这个时候可以使用 _ctx // 允许用户覆盖,这个时候可以使用 _ctx

View File

@ -674,19 +674,22 @@ importers:
version: 2.3.1 version: 2.3.1
'@formily/react': '@formily/react':
specifier: 2.3.1 specifier: 2.3.1
version: 2.3.1(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1)(react-is@18.3.1)(react@18.3.1)(typescript@5.4.5) version: 2.3.1(react-dom@18.3.1)(react-is@18.3.1)(react@18.3.1)(typescript@5.4.5)
'@formily/reactive': '@formily/reactive':
specifier: 2.3.1 specifier: 2.3.1
version: 2.3.1 version: 2.3.1
'@formily/reactive-react': '@formily/reactive-react':
specifier: 2.3.1 specifier: 2.3.1
version: 2.3.1(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1)(react-is@18.3.1)(react@18.3.1) version: 2.3.1(react-dom@18.3.1)(react-is@18.3.1)(react@18.3.1)
'@formily/shared': '@formily/shared':
specifier: 2.3.1 specifier: 2.3.1
version: 2.3.1 version: 2.3.1
'@formily/validator': '@formily/validator':
specifier: 2.3.1 specifier: 2.3.1
version: 2.3.1 version: 2.3.1
'@uiw/codemirror-theme-vscode':
specifier: ^4.23.0
version: 4.23.0(@codemirror/language@6.10.2)(@codemirror/state@6.4.1)(@codemirror/view@6.28.4)
'@uiw/react-codemirror': '@uiw/react-codemirror':
specifier: ^4.22.2 specifier: ^4.22.2
version: 4.22.2(@babel/runtime@7.24.7)(@codemirror/autocomplete@6.16.3)(@codemirror/language@6.10.2)(@codemirror/lint@6.8.1)(@codemirror/search@6.5.6)(@codemirror/state@6.4.1)(@codemirror/theme-one-dark@6.1.2)(@codemirror/view@6.28.4)(codemirror@6.0.1)(react-dom@18.3.1)(react@18.3.1) version: 4.22.2(@babel/runtime@7.24.7)(@codemirror/autocomplete@6.16.3)(@codemirror/language@6.10.2)(@codemirror/lint@6.8.1)(@codemirror/search@6.5.6)(@codemirror/state@6.4.1)(@codemirror/theme-one-dark@6.1.2)(@codemirror/view@6.28.4)(codemirror@6.0.1)(react-dom@18.3.1)(react@18.3.1)
@ -9744,6 +9747,35 @@ packages:
- typescript - typescript
dev: false dev: false
/@formily/react@2.3.1(react-dom@18.3.1)(react-is@18.3.1)(react@18.3.1)(typescript@5.4.5):
resolution: {integrity: sha512-8KkFJe2OnbsgiXwY/txUcUaCQIfIkfowWQinOSni02U2ssgs2bpb1ifFHlZrFGfrrW/xhce4ANUHRgoVYt7W4Q==}
engines: {npm: '>=3.0.0'}
peerDependencies:
'@types/react': '>=16.8.0'
'@types/react-dom': '>=16.8.0'
react: '>=16.8.0'
react-dom: '>=16.8.0'
react-is: '>=16.8.0'
peerDependenciesMeta:
'@types/react':
optional: true
'@types/react-dom':
optional: true
dependencies:
'@formily/core': 2.3.1
'@formily/json-schema': 2.3.1(typescript@5.4.5)
'@formily/reactive': 2.3.1
'@formily/reactive-react': 2.3.1(react-dom@18.3.1)(react-is@18.3.1)(react@18.3.1)
'@formily/shared': 2.3.1
'@formily/validator': 2.3.1
hoist-non-react-statics: 3.3.2
react: 18.3.1
react-dom: 18.3.1(react@18.3.1)
react-is: 18.3.1
transitivePeerDependencies:
- typescript
dev: false
/@formily/reactive-react@2.3.1(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1)(react-is@18.3.1)(react@18.3.1): /@formily/reactive-react@2.3.1(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1)(react-is@18.3.1)(react@18.3.1):
resolution: {integrity: sha512-r6d94JBWhwXGpsffNLnRzgksQJtmqudD1cq7ky2Oljtxg5Ynl8H0Ppcnsv0bd9NbNSAeDeFs2uwWz56exgDzjA==} resolution: {integrity: sha512-r6d94JBWhwXGpsffNLnRzgksQJtmqudD1cq7ky2Oljtxg5Ynl8H0Ppcnsv0bd9NbNSAeDeFs2uwWz56exgDzjA==}
engines: {npm: '>=3.0.0'} engines: {npm: '>=3.0.0'}
@ -9768,6 +9800,28 @@ packages:
react-is: 18.3.1 react-is: 18.3.1
dev: false dev: false
/@formily/reactive-react@2.3.1(react-dom@18.3.1)(react-is@18.3.1)(react@18.3.1):
resolution: {integrity: sha512-r6d94JBWhwXGpsffNLnRzgksQJtmqudD1cq7ky2Oljtxg5Ynl8H0Ppcnsv0bd9NbNSAeDeFs2uwWz56exgDzjA==}
engines: {npm: '>=3.0.0'}
peerDependencies:
'@types/react': '>=16.8.0'
'@types/react-dom': '>=16.8.0'
react: '>=16.8.0'
react-dom: '>=16.8.0'
react-is: '>=16.8.0'
peerDependenciesMeta:
'@types/react':
optional: true
'@types/react-dom':
optional: true
dependencies:
'@formily/reactive': 2.3.1
hoist-non-react-statics: 3.3.2
react: 18.3.1
react-dom: 18.3.1(react@18.3.1)
react-is: 18.3.1
dev: false
/@formily/reactive@2.3.1: /@formily/reactive@2.3.1:
resolution: {integrity: sha512-IVHOZW7VBc+Gq9eB/gPldi7pEC3wDonDb99KvHlS8SmzsY6+a/iAdrw2mDagXXUficsC2gT4y4EcJ2f1ALMKtQ==} resolution: {integrity: sha512-IVHOZW7VBc+Gq9eB/gPldi7pEC3wDonDb99KvHlS8SmzsY6+a/iAdrw2mDagXXUficsC2gT4y4EcJ2f1ALMKtQ==}
engines: {npm: '>=3.0.0'} engines: {npm: '>=3.0.0'}
@ -13277,6 +13331,28 @@ packages:
'@codemirror/view': 6.28.4 '@codemirror/view': 6.28.4
dev: false dev: false
/@uiw/codemirror-theme-vscode@4.23.0(@codemirror/language@6.10.2)(@codemirror/state@6.4.1)(@codemirror/view@6.28.4):
resolution: {integrity: sha512-zl1FD7U1b58tqlF216jYv2okvVkTe+FP1ztqO/DF129bcH99QjszkakshyfxQEvvF4ys3zyzqZ7vU3VYBir8tg==}
dependencies:
'@uiw/codemirror-themes': 4.23.0(@codemirror/language@6.10.2)(@codemirror/state@6.4.1)(@codemirror/view@6.28.4)
transitivePeerDependencies:
- '@codemirror/language'
- '@codemirror/state'
- '@codemirror/view'
dev: false
/@uiw/codemirror-themes@4.23.0(@codemirror/language@6.10.2)(@codemirror/state@6.4.1)(@codemirror/view@6.28.4):
resolution: {integrity: sha512-9fiji9xooZyBQozR1i6iTr56YP7j/Dr/VgsNWbqf5Szv+g+4WM1iZuiDGwNXmFMWX8gbkDzp6ASE21VCPSofWw==}
peerDependencies:
'@codemirror/language': '>=6.0.0'
'@codemirror/state': '>=6.0.0'
'@codemirror/view': '>=6.0.0'
dependencies:
'@codemirror/language': 6.10.2
'@codemirror/state': 6.4.1
'@codemirror/view': 6.28.4
dev: false
/@uiw/react-codemirror@4.22.2(@babel/runtime@7.24.7)(@codemirror/autocomplete@6.16.3)(@codemirror/language@6.10.2)(@codemirror/lint@6.8.1)(@codemirror/search@6.5.6)(@codemirror/state@6.4.1)(@codemirror/theme-one-dark@6.1.2)(@codemirror/view@6.28.4)(codemirror@6.0.1)(react-dom@18.3.1)(react@18.3.1): /@uiw/react-codemirror@4.22.2(@babel/runtime@7.24.7)(@codemirror/autocomplete@6.16.3)(@codemirror/language@6.10.2)(@codemirror/lint@6.8.1)(@codemirror/search@6.5.6)(@codemirror/state@6.4.1)(@codemirror/theme-one-dark@6.1.2)(@codemirror/view@6.28.4)(codemirror@6.0.1)(react-dom@18.3.1)(react@18.3.1):
resolution: {integrity: sha512-okCSl+WJG63gRx8Fdz7v0C6RakBQnbb3pHhuzIgDB+fwhipgFodSnu2n9oOsQesJ5YQ7mSOcKMgX0JEsu4nnfQ==} resolution: {integrity: sha512-okCSl+WJG63gRx8Fdz7v0C6RakBQnbb3pHhuzIgDB+fwhipgFodSnu2n9oOsQesJ5YQ7mSOcKMgX0JEsu4nnfQ==}
peerDependencies: peerDependencies: