1
- import { ViewDocIcon } from "assets/icons" ;
2
1
import { BoolCodeControl , StringControl } from "comps/controls/codeControl" ;
3
2
import { dropdownControl } from "comps/controls/dropdownControl" ;
4
3
import { MultiCompBuilder , withDefault } from "comps/generators" ;
@@ -15,12 +14,14 @@ import {
15
14
ConstructorToView ,
16
15
fromRecord ,
17
16
MultiBaseComp ,
17
+ SimpleAbstractComp ,
18
18
withFunction
19
19
} from "lowcoder-core" ;
20
- import { controlItem , Option } from "lowcoder-design" ;
21
- import styled from "styled-components" ;
20
+ import { controlItem , Dropdown , Option , OptionsType , ValueFromOption } from "lowcoder-design" ;
22
21
import { getNextEntityName } from "util/stringUtils" ;
23
- import { TargetCompAction } from "@lowcoder-ee/comps/comps/tourComp/componentSelectorControl" ;
22
+ import { BoolControl , ControlParams } from "lowcoder-sdk" ;
23
+ import { ReactNode , useContext , useEffect , useState } from "react" ;
24
+ import { EditorContext , EditorState } from "@lowcoder-ee/comps/editorState" ;
24
25
// import { PlacementType } from "@rc-component"
25
26
export type PlacementType = 'left' | 'leftTop' | 'leftBottom' | 'right' | 'rightTop' | 'rightBottom' | 'top' | 'topLeft' | 'topRight' | 'bottom' | 'bottomLeft' | 'bottomRight' | 'center' ;
26
27
@@ -205,35 +206,6 @@ export function manualTourStepsControl<T extends TourStepControlType>(
205
206
: ManualOptionControl ;
206
207
}
207
208
208
- const TipLabel = styled . p `
209
- display: inline;
210
- margin: 2px 0 0 0;
211
- padding: 0;
212
-
213
- font-size: 13px;
214
- color: #9195a3;
215
- line-height: 18px;
216
- cursor: pointer;
217
-
218
- :hover g g {
219
- stroke: #315efb;
220
- }
221
- ` ;
222
- const DocIcon = styled ( ViewDocIcon ) `
223
- transform: translateY(1px);
224
- margin-right: 6px;
225
- ` ;
226
-
227
- const optionListDocUrl = trans ( "docUrls.optionList" ) ;
228
- const OptionTip = optionListDocUrl ? (
229
- < TipLabel onClick = { ( ) => window . open ( optionListDocUrl ) } >
230
- < DocIcon title = { trans ( "optionsControl.viewDocs" ) } />
231
- { trans ( "optionsControl.tip" ) }
232
- </ TipLabel >
233
- ) : (
234
- < > </ >
235
- ) ;
236
-
237
209
type TourStepChildType = {
238
210
title : InstanceType < typeof StringControl > ,
239
211
} ;
@@ -308,14 +280,131 @@ const PlacementOptions: {label: string, value: PlacementType}[] = [
308
280
{ label : "Bottom Right" , value : "bottomRight" } ,
309
281
] ;
310
282
283
+
284
+ export function editorStateDropdownControl < T extends OptionsType > (
285
+ options : ( ( editorState : EditorState ) => T ) ,
286
+ defaultValue : ValueFromOption < T >
287
+ ) {
288
+ return class extends editorStateDropdownAbstractControl ( options , defaultValue ) {
289
+ override getView ( ) {
290
+ return this . value ;
291
+ }
292
+ } ;
293
+ }
294
+
295
+ interface EditorStateDropdownControlParams < T extends OptionsType > extends ControlParams {
296
+ radioButton ?: boolean ;
297
+ border ?: boolean ;
298
+ type ?: "oneline" ;
299
+ disabled ?: boolean ;
300
+ // parent comp may batch dispatch in some cases
301
+ disableDispatchValueChange ?: boolean ;
302
+ onChange ?: ( value : string ) => void ;
303
+ options ?: T ;
304
+ showSearch ?: boolean ;
305
+ dropdownStyle ?: React . CSSProperties ;
306
+ labelStyle ?: React . CSSProperties ;
307
+ IconType ?: "OnlyAntd" | "All" | "default" | undefined ;
308
+ }
309
+ type EditorStateDropdownOptions < T extends OptionsType > = ( editorState : EditorState ) => T ;
310
+
311
+ interface DropdownPropertyViewProps < T extends OptionsType >
312
+ extends Omit < EditorStateDropdownControlParams < T > , "options" > {
313
+ options : EditorStateDropdownOptions < T > ;
314
+ onChange : ( value : ValueFromOption < T > ) => void ;
315
+ value : ValueFromOption < T > ;
316
+ }
317
+
318
+ function EditorStateDropdownPropertyView < T extends OptionsType > ( props : DropdownPropertyViewProps < T > ) {
319
+ const { options, onChange, value, ...params } = props ;
320
+ const [ finalOptions , setFinalOptions ] = useState < T > (
321
+ typeof options === "function" ? ( [ ] as unknown as T ) : options
322
+ ) ;
323
+ const editorState = useContext ( EditorContext ) ;
324
+
325
+ useEffect ( ( ) => {
326
+ if ( typeof options !== "function" ) {
327
+ setFinalOptions ( options ) ;
328
+ return ;
329
+ }
330
+ if ( ! finalOptions ?. length ) {
331
+ setFinalOptions ( options ( editorState ) )
332
+ //.then((items) => setFinalOptions(items));
333
+ }
334
+ } , [ finalOptions . length , options ] ) ;
335
+
336
+ return (
337
+ < Dropdown
338
+ placement = { params . placement }
339
+ toolTip = { params . tooltip }
340
+ value = { value }
341
+ options = { finalOptions }
342
+ radioButton = { params . radioButton }
343
+ border = { params . border }
344
+ type = { params . type }
345
+ label = { params . label }
346
+ showSearch = { params . showSearch }
347
+ onChange = { onChange }
348
+ disabled = { params . disabled }
349
+ dropdownStyle = { props . dropdownStyle }
350
+ labelStyle = { props . labelStyle }
351
+ />
352
+ ) ;
353
+ }
354
+
355
+ /**
356
+ * Leave a getView method unimplemented, because the type cannot be changed by inheritance
357
+ */
358
+ export function editorStateDropdownAbstractControl < T extends OptionsType > (
359
+ options : ( ( editorState : EditorState ) => T ) ,
360
+ defaultValue : ValueFromOption < T >
361
+ ) {
362
+ abstract class DropdownControl extends SimpleAbstractComp < ValueFromOption < T > > {
363
+ override getDefaultValue ( ) : ValueFromOption < T > {
364
+ return defaultValue ;
365
+ }
366
+
367
+ propertyView ( params : EditorStateDropdownControlParams < T > ) {
368
+ return controlItem (
369
+ { filterText : params . label } ,
370
+ < EditorStateDropdownPropertyView < T >
371
+ { ...params }
372
+ value = { this . value }
373
+ options = { options }
374
+ onChange = { ( value ) => {
375
+ if ( ! params . disableDispatchValueChange ) {
376
+ this . dispatchChangeValueAction ( value ) ;
377
+ }
378
+ params . onChange ?.( value ) ;
379
+ } }
380
+ />
381
+ ) ;
382
+ }
383
+
384
+ getPropertyView ( ) : ReactNode {
385
+ throw new Error ( "Method not implemented." ) ;
386
+ }
387
+ }
388
+
389
+ return DropdownControl ;
390
+ }
391
+
311
392
let TourStep = new MultiCompBuilder (
312
393
{
313
- target : TargetCompAction ,
314
- // target: dropdownControl(editorState.getAllUICompMap(), ""),
315
- arrow : BoolCodeControl ,
394
+ // target: TargetCompAction,
395
+ target : editorStateDropdownControl ( ( editorState ) => {
396
+ console . log ( "Is editor defined? " )
397
+ console . log ( editorState )
398
+ return Object . values ( editorState . getAllUICompMap ( ) ) . map ( ( it ) => ( {
399
+ label : it . children . name . getView ( ) ,
400
+ value : it . children . name . getView ( ) ,
401
+ } ) )
402
+ } ,
403
+ "" ) ,
404
+ arrow : BoolControl ,
316
405
title : StringControl ,
317
406
description : StringControl ,
318
- placement : dropdownControl ( PlacementOptions , "center " ) ,
407
+ placement : dropdownControl ( PlacementOptions , "bottom " ) ,
319
408
hidden : BoolCodeControl ,
320
409
} ,
321
410
( props ) => props
@@ -333,11 +422,17 @@ TourStep = class extends TourStep implements TourStepCompProperty {
333
422
label : "Description" ,
334
423
placeholder : "Welcome to lowcoder, this is your first tutorial step" ,
335
424
} ) }
336
- { this . children . target . propertyView ( ) }
425
+ { this . children . target . propertyView ( {
426
+ label : "TARGET" ,
427
+ radioButton : false ,
428
+ } ) }
337
429
{ this . children . placement . propertyView ( {
338
430
label : trans ( "textShow.verticalAlignment" ) ,
339
431
radioButton : false
340
432
} ) }
433
+ { this . children . arrow . propertyView ( {
434
+ label : "Arrow"
435
+ } ) }
341
436
{ hiddenPropertyView ( this . children ) }
342
437
</ >
343
438
) ;
@@ -346,7 +441,7 @@ TourStep = class extends TourStep implements TourStepCompProperty {
346
441
347
442
export const TourStepControl = tourStepsControl ( TourStep , {
348
443
initOptions : [
349
- { title : "BLAHHH " , description : "I love tutorials " } ,
350
- { title : "second title " , description : "Because they mean I don't have to teach people " } ,
444
+ { title : "Welcome " , description : "Welcome to lowcoder " } ,
445
+ { title : "Step 2 " , description : "This is a tutorial step " } ,
351
446
] ,
352
447
} ) ;
0 commit comments