1
- import { default as Row } from 'antd/es/row' ;
2
- import { default as Col } from 'antd/es/col' ;
3
- import { JSONObject , JSONValue } from 'util/jsonTypes' ;
4
- import {
5
- CompAction ,
6
- CompActionTypes ,
7
- deleteCompAction ,
8
- wrapChildAction ,
9
- } from 'lowcoder-core' ;
10
- import {
11
- DispatchType ,
12
- RecordConstructorToView ,
13
- wrapDispatch ,
14
- } from 'lowcoder-core' ;
15
- import { AutoHeightControl } from 'comps/controls/autoHeightControl' ;
16
- import { ColumnOptionControl } from 'comps/controls/optionsControl' ;
17
- import { styleControl } from 'comps/controls/styleControl' ;
1
+ import { default as Row } from "antd/es/row" ;
2
+ import { default as Col } from "antd/es/col" ;
3
+ import { JSONObject , JSONValue } from "util/jsonTypes" ;
4
+ import { CompAction , CompActionTypes , deleteCompAction , wrapChildAction } from "lowcoder-core" ;
5
+ import { DispatchType , RecordConstructorToView , wrapDispatch } from "lowcoder-core" ;
6
+ import { AutoHeightControl } from "comps/controls/autoHeightControl" ;
7
+ import { ColumnOptionControl } from "comps/controls/optionsControl" ;
8
+ import { styleControl } from "comps/controls/styleControl" ;
18
9
import {
19
10
ResponsiveLayoutRowStyle ,
20
11
ResponsiveLayoutRowStyleType ,
21
12
ResponsiveLayoutColStyleType ,
22
13
ResponsiveLayoutColStyle ,
23
14
AnimationStyle ,
24
- AnimationStyleType ,
25
- } from 'comps/controls/styleControlConstants' ;
26
- import { sameTypeMap , UICompBuilder , withDefault } from 'comps/generators' ;
27
- import { addMapChildAction } from 'comps/generators/sameTypeMap' ;
28
- import {
29
- NameConfigHidden ,
30
- withExposingConfigs ,
31
- } from 'comps/generators/withExposing' ;
32
- import { NameGenerator } from 'comps/utils' ;
33
- import { Section , controlItem , sectionNames } from 'lowcoder-design' ;
34
- import { HintPlaceHolder } from 'lowcoder-design' ;
35
- import _ from 'lodash' ;
36
- import React from 'react' ;
37
- import styled from 'styled-components' ;
38
- import { IContainer } from '../containerBase/iContainer' ;
39
- import { SimpleContainerComp } from '../containerBase/simpleContainerComp' ;
40
- import { CompTree , mergeCompTrees } from '../containerBase/utils' ;
15
+ AnimationStyleType
16
+ } from "comps/controls/styleControlConstants" ;
17
+ import { sameTypeMap , UICompBuilder , withDefault } from "comps/generators" ;
18
+ import { addMapChildAction } from "comps/generators/sameTypeMap" ;
19
+ import { NameConfigHidden , withExposingConfigs } from "comps/generators/withExposing" ;
20
+ import { NameGenerator } from "comps/utils" ;
21
+ import { Section , controlItem , sectionNames } from "lowcoder-design" ;
22
+ import { HintPlaceHolder } from "lowcoder-design" ;
23
+ import _ from "lodash" ;
24
+ import React from "react" ;
25
+ import styled from "styled-components" ;
26
+ import { IContainer } from "../containerBase/iContainer" ;
27
+ import { SimpleContainerComp } from "../containerBase/simpleContainerComp" ;
28
+ import { CompTree , mergeCompTrees } from "../containerBase/utils" ;
41
29
import {
42
30
ContainerBaseProps ,
43
31
gridItemCompToGridItems ,
44
32
InnerGrid ,
45
- } from ' ../containerComp/containerView' ;
46
- import { BackgroundColorContext } from ' comps/utils/backgroundColorContext' ;
47
- import { trans } from ' i18n' ;
48
- import { messageInstance } from ' lowcoder-design/src/components/GlobalInstances' ;
49
- import { BoolControl } from ' comps/controls/boolControl' ;
50
- import { BoolCodeControl , NumberControl } from ' comps/controls/codeControl' ;
33
+ } from " ../containerComp/containerView" ;
34
+ import { BackgroundColorContext } from " comps/utils/backgroundColorContext" ;
35
+ import { trans } from " i18n" ;
36
+ import { messageInstance } from " lowcoder-design/src/components/GlobalInstances" ;
37
+ import { BoolControl } from " comps/controls/boolControl" ;
38
+ import { BoolCodeControl , NumberControl } from " comps/controls/codeControl" ;
51
39
52
- import { useContext } from ' react' ;
53
- import { EditorContext } from ' comps/editorState' ;
40
+ import { useContext } from " react" ;
41
+ import { EditorContext } from " comps/editorState" ;
54
42
55
- import {
56
- disabledPropertyView ,
57
- hiddenPropertyView ,
58
- } from 'comps/utils/propertyUtils' ;
59
- import { DisabledContext } from 'comps/generators/uiCompBuilder' ;
43
+ import { disabledPropertyView , hiddenPropertyView } from "comps/utils/propertyUtils" ;
44
+ import { DisabledContext } from "comps/generators/uiCompBuilder" ;
60
45
61
46
const RowWrapper = styled ( Row ) < {
62
47
$style : ResponsiveLayoutRowStyleType ;
@@ -72,33 +57,33 @@ const RowWrapper = styled(Row)<{
72
57
` ;
73
58
74
59
const ColWrapper = styled ( Col ) < {
75
- $style : ResponsiveLayoutColStyleType ;
76
- $minWidth ?: string ;
77
- $matchColumnsHeight : boolean ;
60
+ $style : ResponsiveLayoutColStyleType ,
61
+ $minWidth ?: string ,
62
+ $matchColumnsHeight : boolean ,
78
63
} > `
79
64
display: flex;
80
65
flex-direction: column;
81
66
flex-basis: ${ ( props ) => props . $minWidth } ;
82
67
max-width: ${ ( props ) => props . $minWidth } ;
83
68
84
69
> div {
85
- height: ${ ( props ) => ( props . $matchColumnsHeight ? '100%' : 'auto' ) } ;
70
+ height: ${ ( props ) => props . $matchColumnsHeight ? '100%' : 'auto' } ;
86
71
}
87
72
` ;
88
73
89
- const childrenMap = {
74
+ const childrenMap = {
90
75
disabled : BoolCodeControl ,
91
76
columns : ColumnOptionControl ,
92
77
containers : withDefault ( sameTypeMap ( SimpleContainerComp ) , {
93
- 0 : { view : { } , layout : { } } ,
94
- 1 : { view : { } , layout : { } } ,
78
+ 0 : { view : { } , layout : { } } ,
79
+ 1 : { view : { } , layout : { } } ,
95
80
} ) ,
96
81
autoHeight : AutoHeightControl ,
97
82
rowBreak : withDefault ( BoolControl , false ) ,
98
83
matchColumnsHeight : withDefault ( BoolControl , true ) ,
99
84
rowStyle : withDefault ( styleControl ( ResponsiveLayoutRowStyle ) , { } ) ,
100
85
columnStyle : withDefault ( styleControl ( ResponsiveLayoutColStyle ) , { } ) ,
101
- animationStyle : styleControl ( AnimationStyle ) ,
86
+ animationStyle :styleControl ( AnimationStyle ) ,
102
87
columnPerRowLG : withDefault ( NumberControl , 4 ) ,
103
88
columnPerRowMD : withDefault ( NumberControl , 2 ) ,
104
89
columnPerRowSM : withDefault ( NumberControl , 1 ) ,
@@ -107,10 +92,10 @@ const childrenMap = {
107
92
} ;
108
93
109
94
type ViewProps = RecordConstructorToView < typeof childrenMap > ;
110
- type ResponsiveLayoutProps = ViewProps & { dispatch : DispatchType } ;
95
+ type ResponsiveLayoutProps = ViewProps & { dispatch : DispatchType } ;
111
96
type ColumnContainerProps = Omit < ContainerBaseProps , 'style' > & {
112
- style : ResponsiveLayoutColStyleType ;
113
- } ;
97
+ style : ResponsiveLayoutColStyleType ,
98
+ }
114
99
115
100
const ColumnContainer = ( props : ColumnContainerProps ) => {
116
101
return (
@@ -124,6 +109,7 @@ const ColumnContainer = (props: ColumnContainerProps) => {
124
109
) ;
125
110
} ;
126
111
112
+
127
113
const ResponsiveLayout = ( props : ResponsiveLayoutProps ) => {
128
114
let {
129
115
columns,
@@ -138,7 +124,7 @@ const ResponsiveLayout = (props: ResponsiveLayoutProps) => {
138
124
columnPerRowSM,
139
125
verticalSpacing,
140
126
horizontalSpacing,
141
- animationStyle,
127
+ animationStyle
142
128
} = props ;
143
129
144
130
return (
@@ -236,7 +222,9 @@ const ResponsiveLayout = (props: ResponsiveLayoutProps) => {
236
222
237
223
export const ResponsiveLayoutBaseComp = ( function ( ) {
238
224
return new UICompBuilder ( childrenMap , ( props , dispatch ) => {
239
- return < ResponsiveLayout { ...props } dispatch = { dispatch } /> ;
225
+ return (
226
+ < ResponsiveLayout { ...props } dispatch = { dispatch } />
227
+ ) ;
240
228
} )
241
229
. setPropertyViewFn ( ( children ) => {
242
230
return (
@@ -317,35 +305,25 @@ export const ResponsiveLayoutBaseComp = (function () {
317
305
. build ( ) ;
318
306
} ) ( ) ;
319
307
320
- class ResponsiveLayoutImplComp
321
- extends ResponsiveLayoutBaseComp
322
- implements IContainer
323
- {
308
+ class ResponsiveLayoutImplComp extends ResponsiveLayoutBaseComp implements IContainer {
324
309
private syncContainers ( ) : this {
325
310
const columns = this . children . columns . getView ( ) ;
326
- const ids : Set < string > = new Set (
327
- columns . map ( ( column ) => String ( column . id ) )
328
- ) ;
311
+ const ids : Set < string > = new Set ( columns . map ( ( column ) => String ( column . id ) ) ) ;
329
312
let containers = this . children . containers . getView ( ) ;
330
313
// delete
331
314
const actions : CompAction [ ] = [ ] ;
332
315
Object . keys ( containers ) . forEach ( ( id ) => {
333
316
if ( ! ids . has ( id ) ) {
334
317
// log.debug("syncContainers delete. ids=", ids, " id=", id);
335
- actions . push (
336
- wrapChildAction ( 'containers' , wrapChildAction ( id , deleteCompAction ( ) ) )
337
- ) ;
318
+ actions . push ( wrapChildAction ( "containers" , wrapChildAction ( id , deleteCompAction ( ) ) ) ) ;
338
319
}
339
320
} ) ;
340
321
// new
341
322
ids . forEach ( ( id ) => {
342
323
if ( ! containers . hasOwnProperty ( id ) ) {
343
324
// log.debug("syncContainers new containers: ", containers, " id: ", id);
344
325
actions . push (
345
- wrapChildAction (
346
- 'containers' ,
347
- addMapChildAction ( id , { layout : { } , items : { } } )
348
- )
326
+ wrapChildAction ( "containers" , addMapChildAction ( id , { layout : { } , items : { } } ) )
349
327
) ;
350
328
}
351
329
} ) ;
@@ -361,26 +339,20 @@ class ResponsiveLayoutImplComp
361
339
const columns = this . children . columns . getView ( ) ;
362
340
if ( action . type === CompActionTypes . CUSTOM ) {
363
341
const value = action . value as JSONObject ;
364
- if ( value . type === ' push' ) {
342
+ if ( value . type === " push" ) {
365
343
const itemValue = value . value as JSONObject ;
366
344
if ( _ . isEmpty ( itemValue . key ) ) itemValue . key = itemValue . label ;
367
345
action = {
368
346
...action ,
369
347
value : {
370
348
...value ,
371
- value : { ...itemValue } ,
349
+ value : { ...itemValue } ,
372
350
} ,
373
351
} as CompAction ;
374
352
}
375
- const { path} = action ;
376
- if (
377
- value . type === 'delete' &&
378
- path [ 0 ] === 'columns' &&
379
- columns . length <= 1
380
- ) {
381
- messageInstance . warning (
382
- trans ( 'responsiveLayout.atLeastOneColumnError' )
383
- ) ;
353
+ const { path } = action ;
354
+ if ( value . type === "delete" && path [ 0 ] === 'columns' && columns . length <= 1 ) {
355
+ messageInstance . warning ( trans ( "responsiveLayout.atLeastOneColumnError" ) ) ;
384
356
// at least one column
385
357
return this ;
386
358
}
@@ -403,9 +375,7 @@ class ResponsiveLayoutImplComp
403
375
404
376
getCompTree ( ) : CompTree {
405
377
const containerMap = this . children . containers . getView ( ) ;
406
- const compTrees = Object . values ( containerMap ) . map ( ( container ) =>
407
- container . getCompTree ( )
408
- ) ;
378
+ const compTrees = Object . values ( containerMap ) . map ( ( container ) => container . getCompTree ( ) ) ;
409
379
return mergeCompTrees ( compTrees ) ;
410
380
}
411
381
@@ -426,7 +396,7 @@ class ResponsiveLayoutImplComp
426
396
container . getPasteValue ( nameGenerator )
427
397
) ;
428
398
429
- return { ...this . toJsonValue ( ) , containers : containerPasteValueMap } ;
399
+ return { ...this . toJsonValue ( ) , containers : containerPasteValueMap } ;
430
400
}
431
401
432
402
override autoHeight ( ) : boolean {
@@ -436,5 +406,5 @@ class ResponsiveLayoutImplComp
436
406
437
407
export const ResponsiveLayoutComp = withExposingConfigs (
438
408
ResponsiveLayoutImplComp ,
439
- [ NameConfigHidden ]
409
+ [ NameConfigHidden ]
440
410
) ;
0 commit comments