@@ -48,7 +48,7 @@ export type SelectSourceType = "editor" | "leftPanel" | "addComp" | "rightPanel"
4848
4949/**
5050 * *所有编辑器状态都放置在此处,并且仍然是不可变的。
51- *
51+ *
5252 * 注意:
5353 * 1.需要持久化的状态由comp维护,这里的状态不是持久化的。
5454 * 2.所有setter都不会更改当前editorState实例,而是生成新实例。
@@ -60,23 +60,23 @@ export type SelectSourceType = "editor" | "leftPanel" | "addComp" | "rightPanel"
6060export class EditorState {
6161 readonly rootComp : ESRootCompType ;
6262 readonly showPropertyPane : boolean = false ; //显示属性面板
63- readonly selectedCompNames : Set < string > = new Set ( ) ; //已选择的的组件名
63+ readonly selectedCompNames : Set < string > = new Set ( ) ; //已选择的的组件名
6464 readonly isDragging : boolean = false ; //正在拖动标识
6565 readonly draggingCompType : string = "button" ; //正在拖动的组件类型
6666 readonly forceShowGrid : boolean = false ; // 强制显示网格线
6767 readonly disableInteract : boolean = false ; // 禁用comp的交互(如点击按钮事件)
68- readonly selectedBottomResName : string = "" ; //选中的底部查询名
68+ readonly selectedBottomResName : string = "" ; //选中的底部查询名
6969 readonly selectedBottomResType ?: BottomResTypeEnum ; //选中的底部查询类型
7070 readonly showResultCompName : string = "" ;
7171 readonly selectSource ?: SelectSourceType ; // the source of select type
7272 readonly isPasting : boolean = false ; // 是否正在粘贴组件
73+ readonly isCodeEditorPanelOpen : boolean = false ; // CodeEditorPanel是否打开
7374
7475 private __nameAndExposingInfoCache__ : NameAndExposingInfo = { } ; // 组件名称和暴露信息缓存
7576 private __uiCompByNameCache__ : Record < string , any > = { } ; // 按名称缓存的UI组件
7677
7778 private readonly setEditorState : ( fn : ( editorState : EditorState ) => EditorState ) => void ;
7879
79-
8080 /**
8181 * 构造函数
8282 * @param rootComp 根组件
@@ -222,12 +222,7 @@ export class EditorState {
222222 const stateComInfoList = this . getTempStateCompInfoList ( ) ;
223223 const transformerComInfoList = this . getTransformerCompInfoList ( ) ;
224224 const dataResponderInfoList = this . getDataResponderInfoList ( ) ;
225- return [
226- ...queryComInfoList ,
227- ...stateComInfoList ,
228- ...transformerComInfoList ,
229- ...dataResponderInfoList ,
230- ] ;
225+ return [ ...queryComInfoList , ...stateComInfoList , ...transformerComInfoList , ...dataResponderInfoList ] ;
231226 }
232227
233228 /**
@@ -379,12 +374,12 @@ export class EditorState {
379374
380375 /**
381376 * 获取选定的组件
382- *
377+ *
383378 * 此方法用于从所有组件中筛选出选定的组件具体步骤如下:
384379 * 1. 获取所有组件的映射
385380 * 2. 使用lodash的pickBy方法筛选组件映射中符合选定条件的组件
386381 * 3. 筛选条件是组件的子元素名称在选定的组件名称列表中
387- *
382+ *
388383 * @returns 返回一个对象,包含所有选定的组件
389384 */
390385 selectedComps ( ) {
@@ -397,10 +392,10 @@ export class EditorState {
397392
398393 /**
399394 * 选择容器组件
400- *
395+ *
401396 * 此函数旨在确定当前选中的容器组件如果选中的组件为空,则返回当前UI组件的根组件
402397 * 如果选中的组件是容器类型,则返回该容器类型的子组件否则,返回第一个选中的组件或根组件
403- *
398+ *
404399 * @returns {UIComponent } 当前选中的容器组件或根组件
405400 */
406401 selectedContainer ( ) {
@@ -419,28 +414,25 @@ export class EditorState {
419414
420415 /**
421416 * 根据组件键查找容器
422- *
417+ *
423418 * 此方法旨在通过组件键(compKey)查找对应的容器,首先尝试在UI组件中查找,
424419 * 如果未找到,则继续在hooks组件中查找这种方式确保了查找过程的灵活性和高效性
425- *
420+ *
426421 * @param compKey 组件的唯一键,用于标识特定的组件
427422 * @returns 返回找到的容器,如果没有找到则可能返回undefined或特定的默认值
428423 */
429424 findContainer ( compKey : string ) {
430- return (
431- this . getUIComp ( ) . getComp ( ) ?. findContainer ?.( compKey ) ||
432- this . getHooksComp ( ) . findContainer ( compKey )
433- ) ;
425+ return this . getUIComp ( ) . getComp ( ) ?. findContainer ?.( compKey ) || this . getHooksComp ( ) . findContainer ( compKey ) ;
434426 }
435427
436428 /**
437429 * 查找UI父容器组件
438- *
430+ *
439431 * 此方法旨在寻找指定组件的父容器组件它首先通过`getUIComp()`方法获取UI组件实例,
440432 * 并尝试在其上执行`findParentContainer`方法如果未找到,则通过`getHooksComp()`方法
441433 * 获取Hooks组件实例,并在其上执行相同方法这种冗余检查确保了在两个可能的组件实例中
442434 * 寻找到合适的父容器组件
443- *
435+ *
444436 * @param compName 组件名称,用于标识需要查找父容器的目标组件
445437 * @param containerCompType 可选参数,指定父容器组件的类型如果不传入此参数,
446438 * 将返回任何类型的父容器组件
@@ -455,9 +447,9 @@ export class EditorState {
455447
456448 /**
457449 * 确定组件是否被选中,无论其是否处于多选状态。
458- *
450+ *
459451 * 该方法主要基于组件名称检查当前状态下组件是否被选中。它首先通过 `getAllCompMap` 获取所有组件的映射,然后遍历该映射以查找名称匹配的组件。如果找到该组件且其已被选中(即名称存在于 `selectedCompNames` 中),则返回该组件。这允许快速检查组件的选中状态,而不受其他选中组件的影响。
460- *
452+ *
461453 * @param compName 要检查的组件名称。
462454 * @returns 返回与当前组件名称对应的组件,无论其是否处于多选状态。
463455 */
@@ -516,7 +508,7 @@ export class EditorState {
516508 this . changeStateFn ( ( editorState ) => {
517509 return {
518510 rootComp : compFn ( editorState . rootComp ) ,
519- isPasting : false // 重置粘贴状态
511+ isPasting : false , // 重置粘贴状态
520512 } ;
521513 } ) ;
522514 }
@@ -547,6 +539,12 @@ export class EditorState {
547539 this . changeState ( { isPasting } ) ;
548540 }
549541
542+ setCodeEditorPanelOpen ( isOpen : boolean ) {
543+ if ( this . isCodeEditorPanelOpen !== isOpen ) {
544+ this . changeState ( { isCodeEditorPanelOpen : isOpen } ) ;
545+ }
546+ }
547+
550548 getUIComp ( ) {
551549 return this . rootComp . children . ui ;
552550 }
0 commit comments