1
- import { withTheme } from '@rjsf/core' ;
2
- import type {
3
- RJSFValidationError ,
4
- ErrorListProps ,
5
- UISchemaSubmitButtonOptions ,
6
- } from '@rjsf/utils' ;
7
- import validator from '@rjsf/validator-ajv8' ;
1
+ import { withTheme } from '@rjsf/core' ;
2
+ import type { RJSFValidationError , ErrorListProps , UISchemaSubmitButtonOptions } from "@rjsf/utils" ;
3
+ import validator from "@rjsf/validator-ajv8" ;
8
4
// import Ajv from "@rjsf/validator-ajv8";
9
- import { default as Button } from 'antd/es/button' ;
10
- import { BoolControl } from 'comps/controls/boolControl' ;
11
- import { jsonObjectExposingStateControl } from 'comps/controls/codeStateControl' ;
12
- import { styleControl } from 'comps/controls/styleControl' ;
13
- import {
14
- AnimationStyle ,
15
- AnimationStyleType ,
16
- JsonSchemaFormStyle ,
17
- type JsonSchemaFormStyleType ,
18
- } from 'comps/controls/styleControlConstants' ;
19
- import {
20
- depsConfig ,
21
- NameConfigHidden ,
22
- withExposingConfigs ,
23
- } from 'comps/generators/withExposing' ;
24
- import { withMethodExposing } from 'comps/generators/withMethodExposing' ;
25
- import type { ValueFromOption } from 'lowcoder-design' ;
26
- import { i18nObjs , trans } from 'i18n' ;
27
- import type { JSONSchema7 } from 'json-schema' ;
28
- import styled from 'styled-components' ;
29
- import { toBoolean , toNumber , toString } from 'util/convertUtils' ;
30
- import { Section , sectionNames } from 'lowcoder-design' ;
31
- import { jsonObjectControl } from '../../controls/codeControl' ;
32
- import {
33
- eventHandlerControl ,
34
- submitEvent ,
35
- } from '../../controls/eventHandlerControl' ;
36
- import { UICompBuilder } from '../../generators' ;
37
- import DateWidget from './dateWidget' ;
38
- import ErrorBoundary from './errorBoundary' ;
39
- import { Theme } from '@rjsf/antd' ;
40
- import { hiddenPropertyView } from 'comps/utils/propertyUtils' ;
5
+ import { default as Button } from "antd/es/button" ;
6
+ import { BoolControl } from "comps/controls/boolControl" ;
7
+ import { jsonObjectExposingStateControl } from "comps/controls/codeStateControl" ;
8
+ import { styleControl } from "comps/controls/styleControl" ;
9
+ import { AnimationStyle , AnimationStyleType , JsonSchemaFormStyle , type JsonSchemaFormStyleType } from "comps/controls/styleControlConstants" ;
10
+ import { depsConfig , NameConfigHidden , withExposingConfigs } from "comps/generators/withExposing" ;
11
+ import { withMethodExposing } from "comps/generators/withMethodExposing" ;
12
+ import type { ValueFromOption } from "lowcoder-design" ;
13
+ import { i18nObjs , trans } from "i18n" ;
14
+ import type { JSONSchema7 } from "json-schema" ;
15
+ import styled from "styled-components" ;
16
+ import { toBoolean , toNumber , toString } from "util/convertUtils" ;
17
+ import { Section , sectionNames } from "lowcoder-design" ;
18
+ import { jsonObjectControl } from "../../controls/codeControl" ;
19
+ import { eventHandlerControl , submitEvent } from "../../controls/eventHandlerControl" ;
20
+ import { UICompBuilder } from "../../generators" ;
21
+ import DateWidget from "./dateWidget" ;
22
+ import ErrorBoundary from "./errorBoundary" ;
23
+ import { Theme } from "@rjsf/antd" ;
24
+ import { hiddenPropertyView } from "comps/utils/propertyUtils" ;
41
25
42
- import { useContext } from ' react' ;
43
- import { EditorContext } from ' comps/editorState' ;
26
+ import { useContext } from " react" ;
27
+ import { EditorContext } from " comps/editorState" ;
44
28
45
29
Theme . widgets . DateWidget = DateWidget ( false ) ;
46
30
Theme . widgets . DateTimeWidget = DateWidget ( true ) ;
@@ -97,35 +81,29 @@ function convertData(schema?: JSONSchema7, data?: any) {
97
81
return data ;
98
82
}
99
83
// fix required invalidation problem
100
- if (
101
- schema . type !== 'object' &&
102
- ( data === undefined || data === null || data === '' )
103
- ) {
84
+ if ( schema . type !== "object" && ( data === undefined || data === null || data === "" ) ) {
104
85
return undefined ;
105
86
}
106
87
switch ( schema . type ) {
107
- case ' string' :
88
+ case " string" :
108
89
return toString ( data ) ;
109
- case ' number' :
90
+ case " number" :
110
91
return toNumber ( data ) ;
111
- case ' integer' :
92
+ case " integer" :
112
93
return Math . trunc ( toNumber ( data ) ) ;
113
- case ' boolean' :
94
+ case " boolean" :
114
95
return toBoolean ( data ) ;
115
- case ' null' :
96
+ case " null" :
116
97
return null ;
117
- case ' object' : {
98
+ case " object" : {
118
99
const properties = schema . properties ;
119
100
if ( ! properties ) {
120
101
return data ;
121
102
}
122
103
let newData : Record < string , unknown > = { } ;
123
104
Object . entries ( properties ) . forEach ( ( [ key , definition ] ) => {
124
105
const value = data ? data [ key ] : undefined ;
125
- newData [ key ] =
126
- typeof definition === 'object'
127
- ? convertData ( definition , value )
128
- : value ;
106
+ newData [ key ] = typeof definition === "object" ? convertData ( definition , value ) : value ;
129
107
} ) ;
130
108
return newData ;
131
109
}
@@ -140,34 +118,28 @@ function convertData(schema?: JSONSchema7, data?: any) {
140
118
// JSON schema refer to https://json-schema.org/understanding-json-schema/reference/
141
119
function getErrorMessage ( error : RJSFValidationError ) : string {
142
120
switch ( error . name ) {
143
- case 'required' :
144
- return trans ( 'jsonSchemaForm.required' ) ;
145
- case 'maximum' :
146
- return trans ( 'jsonSchemaForm.maximum' , { value : error . params . limit } ) ;
147
- case 'minimum' :
148
- return trans ( 'jsonSchemaForm.minimum' , { value : error . params . limit } ) ;
149
- case 'exclusiveMaximum' :
150
- return trans ( 'jsonSchemaForm.exclusiveMaximum' , {
151
- value : error . params . limit ,
152
- } ) ;
153
- case 'exclusiveMinimum' :
154
- return trans ( 'jsonSchemaForm.exclusiveMinimum' , {
155
- value : error . params . limit ,
156
- } ) ;
157
- case 'multipleOf' :
158
- return trans ( 'jsonSchemaForm.multipleOf' , {
159
- value : error . params . multipleOf ,
160
- } ) ;
161
- case 'minLength' :
162
- return trans ( 'jsonSchemaForm.minLength' , { value : error . params . limit } ) ;
163
- case 'maxLength' :
164
- return trans ( 'jsonSchemaForm.maxLength' , { value : error . params . limit } ) ;
165
- case 'pattern' :
166
- return trans ( 'jsonSchemaForm.pattern' , { value : error . params . pattern } ) ;
167
- case 'format' :
168
- return trans ( 'jsonSchemaForm.format' , { value : error . params . format } ) ;
121
+ case "required" :
122
+ return trans ( "jsonSchemaForm.required" ) ;
123
+ case "maximum" :
124
+ return trans ( "jsonSchemaForm.maximum" , { value : error . params . limit } ) ;
125
+ case "minimum" :
126
+ return trans ( "jsonSchemaForm.minimum" , { value : error . params . limit } ) ;
127
+ case "exclusiveMaximum" :
128
+ return trans ( "jsonSchemaForm.exclusiveMaximum" , { value : error . params . limit } ) ;
129
+ case "exclusiveMinimum" :
130
+ return trans ( "jsonSchemaForm.exclusiveMinimum" , { value : error . params . limit } ) ;
131
+ case "multipleOf" :
132
+ return trans ( "jsonSchemaForm.multipleOf" , { value : error . params . multipleOf } ) ;
133
+ case "minLength" :
134
+ return trans ( "jsonSchemaForm.minLength" , { value : error . params . limit } ) ;
135
+ case "maxLength" :
136
+ return trans ( "jsonSchemaForm.maxLength" , { value : error . params . limit } ) ;
137
+ case "pattern" :
138
+ return trans ( "jsonSchemaForm.pattern" , { value : error . params . pattern } ) ;
139
+ case "format" :
140
+ return trans ( "jsonSchemaForm.format" , { value : error . params . format } ) ;
169
141
}
170
- return '' ;
142
+ return "" ;
171
143
}
172
144
173
145
function transformErrors ( errors : RJSFValidationError [ ] ) : RJSFValidationError [ ] {
@@ -177,7 +149,7 @@ function transformErrors(errors: RJSFValidationError[]): RJSFValidationError[] {
177
149
// Error message displayed below the comp (will not be displayed when "ui:help" is set in the UI schema)
178
150
error . message = message ;
179
151
// Errors displayed in the error list, not displayed when empty
180
- error . stack = '' ;
152
+ error . stack = "" ;
181
153
}
182
154
return error ;
183
155
} ) ;
@@ -190,7 +162,7 @@ function ErrorList(props: ErrorListProps) {
190
162
return < > </ > ;
191
163
}
192
164
return (
193
- < div style = { { color : ' red' } } >
165
+ < div style = { { color : " red" } } >
194
166
< ul >
195
167
{ errors . map ( ( error ) => (
196
168
< li key = { error . stack } > { error . stack } </ li >
@@ -202,12 +174,10 @@ function ErrorList(props: ErrorListProps) {
202
174
203
175
function onSubmit ( props : {
204
176
resetAfterSubmit : boolean ;
205
- data : { reset : ( ) => void } ;
206
- onEvent : (
207
- eventName : ValueFromOption < typeof EventOptions >
208
- ) => Promise < unknown > ;
177
+ data : { reset : ( ) => void } ;
178
+ onEvent : ( eventName : ValueFromOption < typeof EventOptions > ) => Promise < unknown > ;
209
179
} ) : Promise < void > {
210
- return props . onEvent ( ' submit' ) . then ( ( ) => {
180
+ return props . onEvent ( " submit" ) . then ( ( ) => {
211
181
if ( props . resetAfterSubmit ) {
212
182
props . data . reset ( ) ;
213
183
}
@@ -230,7 +200,7 @@ let FormBasicComp = (function () {
230
200
return new UICompBuilder ( childrenMap , ( props ) => {
231
201
// rjsf 4.20 supports ui:submitButtonOptions, but if the button is customized, it will not take effect. Here we implement it ourselves
232
202
const buttonOptions = props ?. uiSchema ?. [
233
- ' ui:submitButtonOptions'
203
+ " ui:submitButtonOptions"
234
204
] as UISchemaSubmitButtonOptions ;
235
205
236
206
return (
@@ -265,41 +235,37 @@ let FormBasicComp = (function () {
265
235
. setPropertyViewFn ( ( children ) => {
266
236
return (
267
237
< >
268
- { ( useContext ( EditorContext ) . editorModeStatus === 'logic' ||
269
- useContext ( EditorContext ) . editorModeStatus === 'both' ) && (
238
+ { ( useContext ( EditorContext ) . editorModeStatus === "logic" || useContext ( EditorContext ) . editorModeStatus === "both" ) && (
270
239
< Section name = { sectionNames . basic } >
240
+
271
241
{ children . schema . propertyView ( {
272
242
label : (
273
243
< >
274
- { trans ( ' jsonSchemaForm.jsonSchema' ) + ' (' }
244
+ { trans ( " jsonSchemaForm.jsonSchema" ) + " (" }
275
245
< a
276
- href = {
277
- 'http://json-schema.org/learn/getting-started-step-by-step'
278
- }
279
- target = { '_blank' }
246
+ href = { "http://json-schema.org/learn/getting-started-step-by-step" }
247
+ target = { "_blank" }
280
248
rel = "noreferrer"
281
249
>
282
250
Docs 1
283
251
</ a >
284
- { ', ' }
252
+ { ", " }
285
253
< a
286
- href = { ' https://jsonforms.io/examples/basic' }
287
- target = { ' _blank' }
254
+ href = { " https://jsonforms.io/examples/basic" }
255
+ target = { " _blank" }
288
256
rel = "noreferrer"
289
257
>
290
258
Docs 2
291
259
</ a >
292
- { ')' }
260
+ { ")" }
293
261
</ >
294
262
) ,
295
263
tooltip : (
296
264
< >
297
- { trans ( ' jsonSchemaForm.schemaTooltip' ) + ' ' }
265
+ { trans ( " jsonSchemaForm.schemaTooltip" ) + " " }
298
266
< a
299
- href = {
300
- 'http://json-schema.org/learn/getting-started-step-by-step'
301
- }
302
- target = { '_blank' }
267
+ href = { "http://json-schema.org/learn/getting-started-step-by-step" }
268
+ target = { "_blank" }
303
269
rel = "noreferrer"
304
270
>
305
271
JSON schema
@@ -310,33 +276,33 @@ let FormBasicComp = (function () {
310
276
{ children . uiSchema . propertyView ( {
311
277
label : (
312
278
< >
313
- { trans ( ' jsonSchemaForm.uiSchema' ) + ' (' }
279
+ { trans ( " jsonSchemaForm.uiSchema" ) + " (" }
314
280
< a
315
- href = { ' https://jsonforms.io/docs/uischema' }
316
- target = { ' _blank' }
281
+ href = { " https://jsonforms.io/docs/uischema" }
282
+ target = { " _blank" }
317
283
rel = "noreferrer"
318
284
>
319
285
Docs 1
320
286
</ a >
321
- { ', ' }
287
+ { ", " }
322
288
< a
323
- href = {
324
- 'https://rjsf-team.github.io/react-jsonschema-form/docs/api-reference/uiSchema'
325
- }
326
- target = { '_blank' }
289
+ href = { "https://rjsf-team.github.io/react-jsonschema-form/docs/api-reference/uiSchema" }
290
+ target = { "_blank" }
327
291
rel = "noreferrer"
328
292
>
329
293
Docs 2
330
294
</ a >
331
- { ')' }
332
- </ >
295
+ { ")" }
296
+ </ >
333
297
) ,
334
298
tooltip : (
335
299
< >
336
- { trans ( ' jsonSchemaForm.schemaTooltip' ) + ' ' }
300
+ { trans ( " jsonSchemaForm.schemaTooltip" ) + " " }
337
301
< a
338
- href = { 'https://jsonforms.io/docs/uischema' }
339
- target = { '_blank' }
302
+ href = {
303
+ "https://jsonforms.io/docs/uischema"
304
+ }
305
+ target = { "_blank" }
340
306
rel = "noreferrer"
341
307
>
342
308
UI schema
@@ -345,33 +311,32 @@ let FormBasicComp = (function () {
345
311
) ,
346
312
} ) }
347
313
{ children . data . propertyView ( {
348
- label : trans ( ' jsonSchemaForm.defaultData' ) ,
314
+ label : trans ( " jsonSchemaForm.defaultData" ) ,
349
315
} ) }
350
316
</ Section >
351
317
) }
352
318
353
- { ( useContext ( EditorContext ) . editorModeStatus === 'logic' ||
354
- useContext ( EditorContext ) . editorModeStatus === 'both' ) && (
319
+ { ( useContext ( EditorContext ) . editorModeStatus === "logic" || useContext ( EditorContext ) . editorModeStatus === "both" ) && (
355
320
< Section name = { sectionNames . interaction } >
356
321
{ children . onEvent . getPropertyView ( ) }
357
322
{ hiddenPropertyView ( children ) }
358
323
{ children . resetAfterSubmit . propertyView ( {
359
- label : trans ( ' jsonSchemaForm.resetAfterSubmit' ) ,
324
+ label : trans ( " jsonSchemaForm.resetAfterSubmit" ) ,
360
325
} ) }
361
326
</ Section >
362
327
) }
363
328
364
- { ( useContext ( EditorContext ) . editorModeStatus === 'layout' ||
365
- useContext ( EditorContext ) . editorModeStatus === 'both' ) && (
329
+ { ( useContext ( EditorContext ) . editorModeStatus === "layout" || useContext ( EditorContext ) . editorModeStatus === "both" ) && (
366
330
< >
367
- < Section name = { sectionNames . style } >
368
- { children . style . getPropertyView ( ) }
369
- </ Section >
370
- < Section name = { sectionNames . animationStyle } >
371
- { children . animationStyle . getPropertyView ( ) }
331
+ < Section name = { sectionNames . style } >
332
+ { children . style . getPropertyView ( ) }
333
+ </ Section >
334
+ < Section name = { sectionNames . animationStyle } >
335
+ { children . animationStyle . getPropertyView ( ) }
372
336
</ Section >
373
- </ >
337
+ </ >
374
338
) }
339
+
375
340
</ >
376
341
) ;
377
342
} )
@@ -380,9 +345,9 @@ let FormBasicComp = (function () {
380
345
381
346
let FormTmpComp = withExposingConfigs ( FormBasicComp , [
382
347
depsConfig ( {
383
- name : ' data' ,
384
- desc : trans ( ' jsonSchemaForm.dataDesc' ) ,
385
- depKeys : [ ' schema' , ' data' ] ,
348
+ name : " data" ,
349
+ desc : trans ( " jsonSchemaForm.dataDesc" ) ,
350
+ depKeys : [ " schema" , " data" ] ,
386
351
func : ( input ) => {
387
352
return convertData ( input . schema , input . data ) ;
388
353
} ,
@@ -393,8 +358,8 @@ let FormTmpComp = withExposingConfigs(FormBasicComp, [
393
358
FormTmpComp = withMethodExposing ( FormTmpComp , [
394
359
{
395
360
method : {
396
- name : ' submit' ,
397
- description : trans ( ' export.submitDesc' ) ,
361
+ name : " submit" ,
362
+ description : trans ( " export.submitDesc" ) ,
398
363
params : [ ] ,
399
364
} ,
400
365
// FIXME: currently, it cannot be verified when submitted through the method, fix it later
0 commit comments