1
- import { simpleMultiComp } from "../../generators" ;
1
+ import { MultiCompBuilder , simpleMultiComp } from "../../generators" ;
2
2
import { SimpleNameComp } from "@lowcoder-ee/comps/comps/simpleNameComp" ;
3
3
import { StringControl } from "@lowcoder-ee/comps/controls/codeControl" ;
4
4
import { list } from "@lowcoder-ee/comps/generators/list" ;
@@ -9,7 +9,9 @@ import { KeyValueList } from "components/keyValueList";
9
9
import { trans } from "i18n" ;
10
10
import { PopupCard } from "components/popupCard" ;
11
11
import { EditorContext , EditorState } from "@lowcoder-ee/comps/editorState" ;
12
- import { migrateOldData } from "@lowcoder-ee/comps/generators/simpleGenerators" ;
12
+ import { withExposingRaw } from "@lowcoder-ee/comps/generators/withExposing" ;
13
+ import { NameAndExposingInfo } from "@lowcoder-ee/comps/utils/exposingTypes" ;
14
+ import { fromRecord } from "lowcoder-core" ;
13
15
14
16
interface VariablesParams {
15
17
// variables: string[]; todo support parse variables
@@ -50,33 +52,44 @@ const VariableKey = ({children, dispatch}: any) => {
50
52
</ >
51
53
)
52
54
}
53
- const VariableItem = class extends simpleMultiComp ( {
55
+
56
+ const VariableItemBase = new MultiCompBuilder ( {
54
57
key : SimpleNameComp ,
55
58
value : StringControl ,
56
- } ) {
57
- propertyView ( params : VariablesParams ) : ReactNode {
58
- return (
59
- < >
60
- < div style = { { display : "flex" , gap : "8px" , flexGrow : 1 } } >
61
- < VariableKey
62
- children = { this . children }
63
- dispatch = { this . dispatch }
64
- />
65
- < div style = { { width : "232px" , flexGrow : 1 } } >
66
- { this . children . value . propertyView ( { placeholder : "value" } ) }
67
- </ div >
68
- </ div >
69
- </ >
70
- )
71
- }
72
- }
59
+ } , ( props ) => props )
60
+ . setPropertyViewFn ( ( children , dispatch ) => ( < >
61
+ < div style = { { display : "flex" , gap : "8px" , flexGrow : 1 } } >
62
+ < VariableKey
63
+ children = { children }
64
+ dispatch = { dispatch }
65
+ />
66
+ < div style = { { width : "232px" , flexGrow : 1 } } >
67
+ { children . value . propertyView ( { placeholder : "value" } ) }
68
+ </ div >
69
+ </ div >
70
+ </ > ) )
71
+ . build ( )
72
+
73
+ const VariableItem = withExposingRaw ( VariableItemBase , { } , ( comp ) =>
74
+ fromRecord ( {
75
+ value : comp . children . value . exposingNode ( ) ,
76
+ } )
77
+ ) ;
73
78
74
79
const VariableListPropertyViewWrapper = ( { children} : any ) => {
75
80
const editorState = useContext ( EditorContext ) ;
76
81
return children ( editorState ) ;
77
82
}
78
83
79
84
export const VariablesComp = class extends list ( VariableItem ) {
85
+ nameAndExposingInfo ( ) : NameAndExposingInfo {
86
+ const result : NameAndExposingInfo = { } ;
87
+ Object . values ( this . children ) . forEach ( ( comp ) => {
88
+ result [ comp . children . key . getView ( ) ] = comp . exposingInfo ( ) ;
89
+ } )
90
+ return result ;
91
+ }
92
+
80
93
genNewName ( editorState : EditorState ) {
81
94
const name = editorState . getNameGenerator ( ) . genItemName ( "variable" ) ;
82
95
return name ;
@@ -99,7 +112,7 @@ export const VariablesComp = class extends list(VariableItem) {
99
112
< ControlPropertyViewWrapper { ...params } >
100
113
< KeyValueList
101
114
allowDeletingAll
102
- list = { this . getView ( ) . map ( ( child ) => child . propertyView ( params ) ) }
115
+ list = { this . getView ( ) . map ( ( child ) => child . getPropertyView ( ) ) }
103
116
onAdd = { ( ) => this . add ( editorState ) }
104
117
onDelete = { ( item , index ) => this . dispatch ( this . deleteAction ( index ) ) }
105
118
/>
0 commit comments