1- import { BoolCodeControl } from "comps/controls/codeControl" ;
1+ import { BoolCodeControl , StringControl } from "comps/controls/codeControl" ;
22import React , { ReactNode , useContext , useRef } from "react" ;
33import { ExternalEditorContext } from "util/context/ExternalEditorContext" ;
44import { Comp , CompParams , MultiBaseComp } from "lowcoder-core" ;
@@ -22,10 +22,14 @@ import {
2222 MethodConfigsType ,
2323 withMethodExposing ,
2424} from "./withMethodExposing" ;
25+ import { Section } from "lowcoder-design" ;
26+ import { trans } from "i18n" ;
2527
2628export type NewChildren < ChildrenCompMap extends Record < string , Comp < unknown > > > =
2729 ChildrenCompMap & {
2830 hidden : InstanceType < typeof BoolCodeControl > ;
31+ id : InstanceType < typeof StringControl > ;
32+ className : InstanceType < typeof StringControl > ;
2933 } ;
3034
3135export function HidableView ( props : {
@@ -50,12 +54,46 @@ export function HidableView(props: {
5054 }
5155}
5256
57+ export function ExtendedComponentView ( props : {
58+ children : JSX . Element | React . ReactNode ;
59+ id : string ;
60+ className : string ;
61+ } ) {
62+ if ( ! props . id && ! props . className ) {
63+ return < > { props . children } </ > ;
64+ }
65+
66+ return (
67+ < div id = { props . id } className = { props . className } >
68+ { props . children }
69+ </ div >
70+ ) ;
71+ }
72+
73+ export function ExtendedPropertyView <
74+ ChildrenCompMap extends Record < string , Comp < unknown > > ,
75+ > ( props : {
76+ children : JSX . Element | React . ReactNode ,
77+ childrenMap : NewChildren < ChildrenCompMap >
78+ }
79+ ) {
80+ return (
81+ < >
82+ { props . children }
83+ < Section name = { trans ( "prop.component" ) } >
84+ { props . childrenMap . id ?. propertyView ( { label : trans ( "prop.id" ) } ) }
85+ { props . childrenMap . className ?. propertyView ( { label : trans ( "prop.className" ) } ) }
86+ </ Section >
87+ </ >
88+ ) ;
89+ }
90+
5391export function uiChildren <
5492 ChildrenCompMap extends Record < string , Comp < unknown > > ,
5593> (
5694 childrenMap : ToConstructor < ChildrenCompMap >
5795) : ToConstructor < NewChildren < ChildrenCompMap > > {
58- return { ...childrenMap , hidden : BoolCodeControl } as any ;
96+ return { ...childrenMap , hidden : BoolCodeControl , id : StringControl , className : StringControl } as any ;
5997}
6098
6199type ViewReturn = ReactNode ;
@@ -89,10 +127,22 @@ export class UICompBuilder<
89127 setPropertyViewFn (
90128 propertyViewFn : PropertyViewFnTypeForComp < NewChildren < ChildrenCompMap > >
91129 ) {
92- this . propertyViewFn = propertyViewFn ;
130+ this . propertyViewFn = this . decoratePropertyViewFn ( propertyViewFn ) ;
93131 return this ;
94132 }
95133
134+ decoratePropertyViewFn (
135+ propertyViewFn : PropertyViewFnTypeForComp < NewChildren < ChildrenCompMap > >
136+ ) : PropertyViewFnTypeForComp < NewChildren < ChildrenCompMap > > {
137+ return ( childrenMap , dispatch ) => {
138+ return (
139+ < ExtendedPropertyView childrenMap = { childrenMap } >
140+ { propertyViewFn ( childrenMap , dispatch ) }
141+ </ ExtendedPropertyView >
142+ ) ;
143+ } ;
144+ }
145+
96146 setExposeStateConfigs (
97147 configs : ExposingConfig < ChildrenToComp < ChildrenCompMap > > [ ]
98148 ) {
@@ -113,6 +163,12 @@ export class UICompBuilder<
113163 if ( this . childrenMap . hasOwnProperty ( "hidden" ) ) {
114164 throw new Error ( "already has hidden" ) ;
115165 }
166+ if ( this . childrenMap . hasOwnProperty ( "id" ) ) {
167+ throw new Error ( "already has id" ) ;
168+ }
169+ if ( this . childrenMap . hasOwnProperty ( "className" ) ) {
170+ throw new Error ( "already has className" ) ;
171+ }
116172 const newChildrenMap = uiChildren ( this . childrenMap ) ;
117173 const builder = this ;
118174
@@ -185,8 +241,10 @@ function UIView(props: { comp: any; viewFn: any }) {
185241 //END ADD BY FRED
186242
187243 return (
188- < HidableView hidden = { childrenProps . hidden as boolean } >
189- { props . viewFn ( childrenProps , comp . dispatch ) }
190- </ HidableView >
244+ < ExtendedComponentView id = { childrenProps . id as string } className = { childrenProps . className as string } >
245+ < HidableView hidden = { childrenProps . hidden as boolean } >
246+ { props . viewFn ( childrenProps , comp . dispatch ) }
247+ </ HidableView >
248+ </ ExtendedComponentView >
191249 ) ;
192250}
0 commit comments