1- import { IPublicTypeComponentAction , IPublicTypeMetadataTransducer } from '@alilc/lowcode-types' ;
1+ import { IPublicModelNode , IPublicTypeComponentAction , IPublicTypeMetadataTransducer } from '@alilc/lowcode-types' ;
22import { engineConfig } from '@alilc/lowcode-editor-core' ;
33import { intlNode } from './locale' ;
44import {
@@ -8,18 +8,19 @@ import {
88 IconClone ,
99 IconHidden ,
1010} from './icons' ;
11- import { Node } from './document' ;
1211import { componentDefaults , legacyIssues } from './transducers' ;
1312
1413export class ComponentActions {
14+ private metadataTransducers : IPublicTypeMetadataTransducer [ ] = [ ] ;
15+
1516 actions : IPublicTypeComponentAction [ ] = [
1617 {
1718 name : 'remove' ,
1819 content : {
1920 icon : IconRemove ,
2021 title : intlNode ( 'remove' ) ,
2122 /* istanbul ignore next */
22- action ( node : Node ) {
23+ action ( node : IPublicModelNode ) {
2324 node . remove ( ) ;
2425 } ,
2526 } ,
@@ -31,13 +32,13 @@ export class ComponentActions {
3132 icon : IconHidden ,
3233 title : intlNode ( 'hide' ) ,
3334 /* istanbul ignore next */
34- action ( node : Node ) {
35- node . setVisible ( false ) ;
35+ action ( node : IPublicModelNode ) {
36+ node . visible = false ;
3637 } ,
3738 } ,
3839 /* istanbul ignore next */
39- condition : ( node : Node ) => {
40- return node . componentMeta . isModal ;
40+ condition : ( node : IPublicModelNode ) => {
41+ return node . componentMeta ? .isModal ;
4142 } ,
4243 important : true ,
4344 } ,
@@ -47,25 +48,25 @@ export class ComponentActions {
4748 icon : IconClone ,
4849 title : intlNode ( 'copy' ) ,
4950 /* istanbul ignore next */
50- action ( node : Node ) {
51+ action ( node : IPublicModelNode ) {
5152 // node.remove();
5253 const { document : doc , parent, index } = node ;
5354 if ( parent ) {
54- const newNode = doc . insertNode ( parent , node , index + 1 , true ) ;
55- newNode . select ( ) ;
56- const { isRGL, rglNode } = node . getRGL ( ) ;
55+ const newNode = doc ? .insertNode ( parent , node , ( index ?? 0 ) + 1 , true ) ;
56+ newNode ? .select ( ) ;
57+ const { isRGL, rglNode } = node ? .getRGL ( ) ;
5758 if ( isRGL ) {
5859 // 复制 layout 信息
59- const layout = rglNode . getPropValue ( 'layout' ) || [ ] ;
60- const curLayout = layout . filter ( ( item ) => item . i === node . getPropValue ( 'fieldId' ) ) ;
60+ const layout : any = rglNode ? .getPropValue ( 'layout' ) || [ ] ;
61+ const curLayout = layout . filter ( ( item : any ) => item . i === node . getPropValue ( 'fieldId' ) ) ;
6162 if ( curLayout && curLayout [ 0 ] ) {
6263 layout . push ( {
6364 ...curLayout [ 0 ] ,
64- i : newNode . getPropValue ( 'fieldId' ) ,
65+ i : newNode ? .getPropValue ( 'fieldId' ) ,
6566 } ) ;
66- rglNode . setPropValue ( 'layout' , layout ) ;
67+ rglNode ? .setPropValue ( 'layout' , layout ) ;
6768 // 如果是磁贴块复制,则需要滚动到影响位置
68- setTimeout ( ( ) => newNode . document . simulator ?. scrollToNode ( newNode ) , 10 ) ;
69+ setTimeout ( ( ) => newNode ? .document ?. project ?. simulatorHost ?. scrollToNode ( newNode ) , 10 ) ;
6970 }
7071 }
7172 }
@@ -79,13 +80,13 @@ export class ComponentActions {
7980 icon : IconLock , // 锁定 icon
8081 title : intlNode ( 'lock' ) ,
8182 /* istanbul ignore next */
82- action ( node : Node ) {
83+ action ( node : IPublicModelNode ) {
8384 node . lock ( ) ;
8485 } ,
8586 } ,
8687 /* istanbul ignore next */
87- condition : ( node : Node ) => {
88- return engineConfig . get ( 'enableCanvasLock' , false ) && node . isContainer ( ) && ! node . isLocked ;
88+ condition : ( node : IPublicModelNode ) => {
89+ return engineConfig . get ( 'enableCanvasLock' , false ) && node . isContainerNode && ! node . isLocked ;
8990 } ,
9091 important : true ,
9192 } ,
@@ -95,13 +96,13 @@ export class ComponentActions {
9596 icon : IconUnlock , // 解锁 icon
9697 title : intlNode ( 'unlock' ) ,
9798 /* istanbul ignore next */
98- action ( node : Node ) {
99+ action ( node : IPublicModelNode ) {
99100 node . lock ( false ) ;
100101 } ,
101102 } ,
102103 /* istanbul ignore next */
103- condition : ( node : Node ) => {
104- return engineConfig . get ( 'enableCanvasLock' , false ) && node . isContainer ( ) && node . isLocked ;
104+ condition : ( node : IPublicModelNode ) => {
105+ return engineConfig . get ( 'enableCanvasLock' , false ) && node . isContainerNode && node . isLocked ;
105106 } ,
106107 important : true ,
107108 } ,
@@ -132,8 +133,6 @@ export class ComponentActions {
132133 }
133134 }
134135
135- private metadataTransducers : IPublicTypeMetadataTransducer [ ] = [ ] ;
136-
137136 registerMetadataTransducer (
138137 transducer : IPublicTypeMetadataTransducer ,
139138 level = 100 ,
0 commit comments