@cocos/cocos-cli-types 0.0.1-alpha.24.1 → 0.0.1-alpha.24.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/cli.d.ts +211 -36
  2. package/index.d.ts +211 -36
  3. package/package.json +1 -1
package/cli.d.ts CHANGED
@@ -485,7 +485,7 @@ export declare interface GlTFUserData {
485
485
  * 添加/创建组件的选项
486
486
  */
487
487
  export declare interface IAddComponentOptions {
488
- nodePathOrUuid: string;
488
+ nodePath: string;
489
489
  component: string;
490
490
  }
491
491
 
@@ -689,31 +689,31 @@ export declare interface IComponentService extends IServiceEvents {
689
689
  /**
690
690
  * 添加组件到指定节点,返回添加后的组件信息
691
691
  * @param params - 添加组件选项
692
- * @param params.nodePathOrUuid - 目标节点路径或 UUID
692
+ * @param params.nodePath - 目标节点路径
693
693
  * @param params.component - 组件类名,支持精确匹配('cc.Label')和模糊匹配('label')
694
694
  * @returns 添加成功后的组件信息
695
695
  *
696
696
  * @example
697
697
  * ```ts
698
698
  * // 通过节点路径 + 精确组件名
699
- * const comp = await addComponent({ nodePathOrUuid: 'Canvas/MyNode', component: 'cc.Label' });
699
+ * const comp = await add({ nodePath: 'Canvas/MyNode', component: 'cc.Label' });
700
700
  *
701
- * // 通过节点 UUID + 模糊组件名
702
- * const comp = await addComponent({ nodePathOrUuid: 'abc-123-uuid', component: 'label' });
701
+ * // 通过节点路径 + 模糊组件名
702
+ * const comp = await add({ nodePath: 'Canvas/MyNode', component: 'label' });
703
703
  * ```
704
704
  */
705
- addComponent(params: IAddComponentOptions): Promise<IComponent>;
705
+ add(params: IAddComponentOptions): Promise<IComponent>;
706
706
  /**
707
707
  * 删除指定组件
708
708
  * @param params - 删除组件选项
709
- * @param params.path - 组件路径,支持路径、UUID 或资源 URL
709
+ * @param params.path - 组件路径
710
710
  * @returns 删除成功返回 true,失败返回 false
711
711
  */
712
- removeComponent(params: IRemoveComponentOptions): Promise<boolean>;
712
+ remove(params: IRemoveComponentOptions): Promise<boolean>;
713
713
  /**
714
714
  * 设置组件属性
715
715
  * - CLI 调用时传入 ISetPropertyOptions,通过 componentPath 定位,属性为扁平键值对
716
- * - 编辑器调用时传入 ISetPropertyOptionsForEditor,通过节点 UUID + dump 路径定位,属性为 IProperty 格式
716
+ * - 编辑器调用时传入 ISetPropertyOptionsForEditor,通过节点路径 + dump 路径定位,属性为 IProperty 格式
717
717
  *
718
718
  * @param params - 设置属性选项,根据调用方不同传入不同类型
719
719
  * @returns 设置成功返回 true,失败返回 false
@@ -726,9 +726,9 @@ export declare interface IComponentService extends IServiceEvents {
726
726
  * properties: { string: 'Hello', fontSize: 32 },
727
727
  * });
728
728
  *
729
- * // 编辑器方式:通过节点 UUID + dump 路径定位,传 IProperty 格式
729
+ * // 编辑器方式:通过节点路径 + dump 路径定位,传 IProperty 格式
730
730
  * await setProperty({
731
- * uuid: 'node-uuid',
731
+ * nodePath: 'Canvas/MyNode',
732
732
  * path: '__comps__.0.string',
733
733
  * dump: { value: 'Hello', type: 'String' },
734
734
  * });
@@ -746,33 +746,33 @@ export declare interface IComponentService extends IServiceEvents {
746
746
  * @example
747
747
  * ```ts
748
748
  * CLI 模式:返回 IComponent(扁平属性)
749
- * const comp = await queryComponent({ path: 'Canvas/cc.Label_1' }) as IComponent;
749
+ * const comp = await query({ path: 'Canvas/cc.Label_1' }) as IComponent;
750
750
  *
751
751
  * 编辑器模式:直接传 string,这里是uuid,因为与cli重复了,也支持 path 和 url
752
- * const comp = await queryComponent('uuid') as IComponentForEditor;
752
+ * const comp = await query('uuid') as IComponentForEditor;
753
753
  * ```
754
754
  */
755
- queryComponent(params: IQueryComponentOptions | string): Promise<IComponent | IComponentForEditor | null>;
755
+ query(params: IQueryComponentOptions | string): Promise<IComponent | IComponentForEditor | null>;
756
756
  /**
757
757
  * 获取所有已注册的组件类名,包含内置与自定义组件
758
758
  * @returns 组件类名数组,如 ['cc.Label', 'cc.Sprite', 'MyCustomComponent']
759
759
  */
760
- queryAllComponent(): Promise<string[]>;
760
+ queryAll(): Promise<string[]>;
761
761
  /**
762
- * 创建组件(编辑器使用),与 addComponent 不同的是仅返回是否成功
762
+ * 创建组件(编辑器使用),与 add 不同的是仅返回是否成功
763
763
  * @param params - 添加组件选项
764
- * @param params.nodePathOrUuid - 目标节点路径或 UUID
764
+ * @param params.nodePath - 目标节点路径
765
765
  * @param params.component - 组件类名
766
766
  * @returns 创建成功返回 true,失败返回 false
767
767
  */
768
- createComponent(params: IAddComponentOptions): Promise<boolean>;
768
+ create(params: IAddComponentOptions): Promise<boolean>;
769
769
  /**
770
770
  * 复位组件,将组件所有属性恢复为默认值
771
771
  * @param params - 查询组件选项,用于定位要复位的组件
772
- * @param params.path - 组件路径,支持路径、UUID 或资源 URL
772
+ * @param params.path - 组件路径
773
773
  * @returns 复位成功返回 true,失败返回 false
774
774
  */
775
- resetComponent(params: IQueryComponentOptions): Promise<boolean>;
775
+ reset(params: IQueryComponentOptions): Promise<boolean>;
776
776
  /**
777
777
  * 获取所有注册类名,支持按继承关系过滤
778
778
  * @param options - 过滤选项,不传则返回所有注册类
@@ -797,25 +797,25 @@ export declare interface IComponentService extends IServiceEvents {
797
797
  }[]>;
798
798
  /**
799
799
  * 查询指定节点上所有组件暴露的可调用函数
800
- * @param uuid - 节点 UUID
800
+ * @param path - 节点路径
801
801
  * @returns 节点上组件的函数信息,节点不存在时返回空对象
802
802
  */
803
- queryComponentFunctionOfNode(uuid: string): Promise<any>;
803
+ queryFunctionOfNode(path: string): Promise<any>;
804
804
  /**
805
805
  * 执行组件上的指定方法
806
806
  * @param options - 执行选项
807
- * @param options.uuid - 组件实例的 UUID
807
+ * @param options.path - 组件路径,如 'Canvas/cc.Label_1'
808
808
  * @param options.name - 要执行的方法名,如 'onLoad'、'start'
809
809
  * @param options.args - 方法参数列表
810
810
  * @returns 执行成功返回 true,失败返回 false
811
811
  */
812
- executeComponentMethod(options: IExecuteComponentMethodOptions): Promise<boolean>;
812
+ executeMethod(options: IExecuteComponentMethodOptions): Promise<any>;
813
813
  /**
814
814
  * 查询指定名称的组件是否已注册(是否存在对应脚本)
815
815
  * @param name - 组件类名,如 'cc.Label'
816
816
  * @returns 存在返回 true,不存在返回 false
817
817
  */
818
- queryComponentHasScript(name: string): Promise<boolean>;
818
+ hasScript(name: string): Promise<boolean>;
819
819
  init(): void;
820
820
  unregisterCompMgrEvents(): void;
821
821
  }
@@ -921,7 +921,7 @@ export declare interface IEngineService extends IServiceEvents {
921
921
  * 执行组件方法的选项
922
922
  */
923
923
  export declare interface IExecuteComponentMethodOptions {
924
- uuid: string;
924
+ path: string;
925
925
  name: string;
926
926
  args: any[];
927
927
  }
@@ -1057,6 +1057,31 @@ export declare interface INode extends INodeIdentifier {
1057
1057
  prefab: IPrefabInfo | null;
1058
1058
  }
1059
1059
 
1060
+ export declare interface INodeForEditor {
1061
+ active: IProperty;
1062
+ locked: IProperty;
1063
+ name: IProperty;
1064
+ position: IProperty;
1065
+ /**
1066
+ * 此为 dump 数据,非 node.rotation
1067
+ * 实际指向 node.eulerAngles
1068
+ * rotation 为了给用户更友好的文案
1069
+ */
1070
+ rotation: IProperty;
1071
+ mobility: IProperty;
1072
+ scale: IProperty;
1073
+ layer: IProperty;
1074
+ uuid: IProperty;
1075
+ children: IProperty[];
1076
+ parent: IProperty;
1077
+ __comps__: IProperty[];
1078
+ __type__: string;
1079
+ __prefab__?: IPrefabForEditor;
1080
+ _prefabInstance?: any;
1081
+ removedComponents?: IRemovedComponentInfo[];
1082
+ mountedRoot?: string;
1083
+ }
1084
+
1060
1085
  export declare interface INodeIdentifier {
1061
1086
  nodeId: string;
1062
1087
  path: string;
@@ -1081,30 +1106,144 @@ export declare interface INodeService extends IServiceEvents {
1081
1106
  * 创建节点
1082
1107
  * @param params
1083
1108
  */
1084
- createNodeByType(params: ICreateByNodeTypeParams): Promise<INode | null>;
1109
+ createByType(params: ICreateByNodeTypeParams): Promise<INode | null>;
1085
1110
  /**
1086
1111
  * 创建节点
1087
1112
  * @param params
1088
1113
  */
1089
- createNodeByAsset(params: ICreateByAssetParams): Promise<INode | null>;
1114
+ createByAsset(params: ICreateByAssetParams): Promise<INode | null>;
1090
1115
  /**
1091
1116
  * 删除节点
1092
1117
  * @param params
1093
1118
  */
1094
- deleteNode(params: IDeleteNodeParams): Promise<IDeleteNodeResult | null>;
1119
+ delete(params: IDeleteNodeParams): Promise<IDeleteNodeResult | null>;
1095
1120
  /**
1096
1121
  * 更新节点
1097
1122
  * @param params
1098
1123
  */
1099
- updateNode(params: IUpdateNodeParams): Promise<IUpdateNodeResult>;
1124
+ update(params: IUpdateNodeParams): Promise<IUpdateNodeResult>;
1100
1125
  /**
1101
- * 查询节点
1126
+ * 查询节点信息
1127
+ * - 不传参数时,返回当前场景的 dump 数据(ISceneForEditor)
1128
+ * - 传入 string 时,返回指定路径节点的 dump 数据(编辑器模式,返回 INodeForEditor 数据)
1129
+ * - 传入 IQueryNodeParams 时,返回 INode(CLI 模式)
1130
+ *
1131
+ * @param params - 查询选项、节点路径字符串或不传
1132
+ * @returns 如果传入 IQueryNodeParams 返回 INode,如果传入 string 或不传返回 INodeForEditor 或 ISceneForEditor,未找到返回 null
1102
1133
  */
1103
- queryNode(params: IQueryNodeParams): Promise<INode | null>;
1134
+ query(params?: IQueryNodeParams | string): Promise<INode | INodeForEditor | ISceneForEditor | null>;
1104
1135
  /**
1105
1136
  * 查询节点树(层级管理器格式)
1106
1137
  */
1107
1138
  queryNodeTree(params: IQueryNodeTreeParams): Promise<INodeTreeItem | null>;
1139
+ /**
1140
+ * 预览设置节点属性,临时应用属性变更但不记录到 undo 栈
1141
+ * 用于编辑器中拖拽滑块等实时预览场景,首次调用时会缓存原始值,
1142
+ * 可通过 cancelPreviewSetProperty 恢复
1143
+ *
1144
+ * @param options - 设置属性选项
1145
+ * @param options.nodePath - 节点路径
1146
+ * @param options.path - 属性路径,如 'position'、'scale'
1147
+ * @param options.dump - 属性的 dump 数据
1148
+ * @returns 设置成功返回 true,节点或属性路径无效返回 false
1149
+ *
1150
+ * @example
1151
+ * ```ts
1152
+ * // 预览修改节点位置
1153
+ * await previewSetProperty({
1154
+ * nodePath: 'Canvas/MyNode',
1155
+ * path: 'position',
1156
+ * dump: { value: { x: 100, y: 200, z: 0 }, type: 'cc.Vec3' },
1157
+ * });
1158
+ * ```
1159
+ */
1160
+ previewSetProperty(options: ISetPropertyOptionsForEditor): Promise<boolean>;
1161
+ /**
1162
+ * 取消预览设置,将节点属性恢复到 previewSetProperty 调用前的值
1163
+ * 仅使用 options.nodePath 和 options.path,options.dump 不会被使用
1164
+ *
1165
+ * @param options - 设置属性选项
1166
+ * @param options.nodePath - 节点路径
1167
+ * @param options.path - 属性路径
1168
+ * @returns 恢复成功返回 true,无缓存的预览数据或节点无效返回 false
1169
+ */
1170
+ cancelPreviewSetProperty(options: ISetPropertyOptionsForEditor): Promise<boolean>;
1171
+ /**
1172
+ * 设置节点属性,会记录到 undo 栈
1173
+ *
1174
+ * @param options - 设置属性选项
1175
+ * @param options.nodePath - 节点路径
1176
+ * @param options.path - 属性路径,如 'position'、'rotation'、'layer'
1177
+ * @param options.dump - 属性的 dump 数据
1178
+ * @returns 设置成功返回 true,节点不存在返回 false
1179
+ *
1180
+ * @example
1181
+ * ```ts
1182
+ * await setProperty({
1183
+ * nodePath: 'Canvas/MyNode',
1184
+ * path: 'position',
1185
+ * dump: { value: { x: 100, y: 200, z: 0 }, type: 'cc.Vec3' },
1186
+ * });
1187
+ * ```
1188
+ */
1189
+ setProperty(options: ISetPropertyOptionsForEditor): Promise<boolean>;
1190
+ /**
1191
+ * 重置节点的变换属性(position、rotation、scale、mobility)到默认值
1192
+ *
1193
+ * @param path - 节点路径
1194
+ * @returns 重置成功返回 true,节点不存在返回 false
1195
+ */
1196
+ reset(path: string): Promise<boolean>;
1197
+ /**
1198
+ * 重置节点的单个属性到 CCClass 定义的默认值
1199
+ * 仅使用 options.nodePath 和 options.path,options.dump 不会被使用
1200
+ *
1201
+ * @param options - 设置属性选项
1202
+ * @param options.nodePath - 节点路径
1203
+ * @param options.path - 属性路径,如 'position'、'scale'
1204
+ * @returns 重置成功返回 true,节点不存在返回 false
1205
+ */
1206
+ resetProperty(options: ISetPropertyOptionsForEditor): Promise<boolean>;
1207
+ /**
1208
+ * 将节点上值为 null 的属性初始化为默认实例
1209
+ * 当属性为 null 且有定义构造函数类型时,会创建该类型的新实例
1210
+ * 仅使用 options.nodePath 和 options.path,options.dump 不会被使用
1211
+ *
1212
+ * @param options - 设置属性选项
1213
+ * @param options.nodePath - 节点路径
1214
+ * @param options.path - 属性路径
1215
+ * @returns 初始化成功返回 true,节点不存在返回 false
1216
+ *
1217
+ * @example
1218
+ * ```ts
1219
+ * // 将节点上值为 null 的自定义属性初始化
1220
+ * await updatePropertyFromNull({
1221
+ * nodePath: 'Canvas/MyNode',
1222
+ * path: 'customProperty',
1223
+ * dump: {} as IProperty,
1224
+ * });
1225
+ * ```
1226
+ */
1227
+ updatePropertyFromNull(options: ISetPropertyOptionsForEditor): Promise<boolean>;
1228
+ /**
1229
+ * 设置节点及其所有子节点的 layer 属性
1230
+ * 递归将相同的 layer 值应用到整个节点子树
1231
+ * 仅使用 options.nodePath 和 options.dump,options.path 不会被使用(内部固定为 'layer')
1232
+ *
1233
+ * @param options - 设置属性选项
1234
+ * @param options.nodePath - 节点路径
1235
+ * @param options.dump - layer 属性的 dump 数据
1236
+ *
1237
+ * @example
1238
+ * ```ts
1239
+ * await setNodeAndChildrenLayer({
1240
+ * nodePath: 'Canvas/MyNode',
1241
+ * path: 'layer',
1242
+ * dump: { value: 1 << 25, type: 'Enum' },
1243
+ * });
1244
+ * ```
1245
+ */
1246
+ setNodeAndChildrenLayer(options: ISetPropertyOptionsForEditor): Promise<void>;
1108
1247
  }
1109
1248
 
1110
1249
  export declare interface INodeTreeComponent {
@@ -1155,6 +1294,16 @@ export declare interface IPrefab {
1155
1294
  persistent: boolean;
1156
1295
  }
1157
1296
 
1297
+ export declare interface IPrefabForEditor {
1298
+ uuid: string;
1299
+ fileId: string;
1300
+ rootUuid: string;
1301
+ sync: boolean;
1302
+ prefabStateInfo: IPrefabStateInfo;
1303
+ targetOverrides?: ITargetOverrideInfoForEditor[];
1304
+ instance?: IProperty;
1305
+ }
1306
+
1158
1307
  export declare interface IPrefabInfo {
1159
1308
  /** 关联的预制体资源信息 */
1160
1309
  asset?: IPrefab;
@@ -1348,6 +1497,11 @@ export declare interface IRemoveComponentOptions {
1348
1497
  path: string;
1349
1498
  }
1350
1499
 
1500
+ export declare interface IRemovedComponentInfo {
1501
+ name: string;
1502
+ fileID: string;
1503
+ }
1504
+
1351
1505
  export declare interface IRevertToPrefabParams {
1352
1506
  nodePath: string;
1353
1507
  }
@@ -1369,6 +1523,20 @@ export declare interface IScene extends IBaseIdentifier {
1369
1523
  components: IComponentIdentifier[];
1370
1524
  }
1371
1525
 
1526
+ export declare interface ISceneForEditor {
1527
+ name: IProperty;
1528
+ active: IProperty;
1529
+ locked: IProperty;
1530
+ _globals: Record<string, IProperty>;
1531
+ isScene: boolean;
1532
+ autoReleaseAssets: IProperty;
1533
+ uuid: IProperty;
1534
+ children: IProperty[];
1535
+ parent: string;
1536
+ __type__: string;
1537
+ targetOverrides?: ITargetOverrideInfoForEditor[];
1538
+ }
1539
+
1372
1540
  export declare interface ISceneMouseEvent {
1373
1541
  x: number;
1374
1542
  y: number;
@@ -1447,10 +1615,9 @@ export declare interface IServiceEvents {
1447
1615
  onSetPropertyComponent?(comp: Component): void;
1448
1616
  onComponentAdded?(comp: Component): void;
1449
1617
  onComponentRemoved?(comp: Component): void;
1618
+ onBeforeChangeComponent?(node: Node_2): void;
1619
+ onBeforeAddComponent?(name: string, node: Node_2): void;
1450
1620
  onBeforeRemoveComponent?(comp: Component): void;
1451
- onComponentBeforeChanged?(node: Node_2): void;
1452
- onBeforeComponentAdded?(name: string, node: Node_2): void;
1453
- onComponentChanged?(name: string, opts: IChangeNodeOptions): void;
1454
1621
  onAssetDeleted?(uuid: string): void;
1455
1622
  onAssetChanged?(uuid: string): void;
1456
1623
  onAssetRefreshed?(uuid: string): void;
@@ -1491,7 +1658,7 @@ export declare interface ISetPropertyOptions {
1491
1658
  * 编辑器设置组件属性的选项
1492
1659
  */
1493
1660
  export declare interface ISetPropertyOptionsForEditor {
1494
- uuid: string;
1661
+ nodePath: string;
1495
1662
  path: string;
1496
1663
  dump: IProperty;
1497
1664
  record?: boolean;
@@ -1529,6 +1696,14 @@ export declare interface ITargetOverrideInfo {
1529
1696
  targetInfo: ITargetInfo | null;
1530
1697
  }
1531
1698
 
1699
+ export declare interface ITargetOverrideInfoForEditor {
1700
+ source: string;
1701
+ sourceInfo?: string[];
1702
+ propertyPath: string[];
1703
+ target: string;
1704
+ targetInfo?: string[];
1705
+ }
1706
+
1532
1707
  export declare interface IUndoService {
1533
1708
  beginRecording(uuids: string[], options?: any): string;
1534
1709
  endRecording(commandId: string): void;
package/index.d.ts CHANGED
@@ -975,7 +975,7 @@ export declare namespace i18n {
975
975
  * 添加/创建组件的选项
976
976
  */
977
977
  export declare interface IAddComponentOptions {
978
- nodePathOrUuid: string;
978
+ nodePath: string;
979
979
  component: string;
980
980
  }
981
981
 
@@ -1274,31 +1274,31 @@ export declare interface IComponentService extends IServiceEvents {
1274
1274
  /**
1275
1275
  * 添加组件到指定节点,返回添加后的组件信息
1276
1276
  * @param params - 添加组件选项
1277
- * @param params.nodePathOrUuid - 目标节点路径或 UUID
1277
+ * @param params.nodePath - 目标节点路径
1278
1278
  * @param params.component - 组件类名,支持精确匹配('cc.Label')和模糊匹配('label')
1279
1279
  * @returns 添加成功后的组件信息
1280
1280
  *
1281
1281
  * @example
1282
1282
  * ```ts
1283
1283
  * // 通过节点路径 + 精确组件名
1284
- * const comp = await addComponent({ nodePathOrUuid: 'Canvas/MyNode', component: 'cc.Label' });
1284
+ * const comp = await add({ nodePath: 'Canvas/MyNode', component: 'cc.Label' });
1285
1285
  *
1286
- * // 通过节点 UUID + 模糊组件名
1287
- * const comp = await addComponent({ nodePathOrUuid: 'abc-123-uuid', component: 'label' });
1286
+ * // 通过节点路径 + 模糊组件名
1287
+ * const comp = await add({ nodePath: 'Canvas/MyNode', component: 'label' });
1288
1288
  * ```
1289
1289
  */
1290
- addComponent(params: IAddComponentOptions): Promise<IComponent>;
1290
+ add(params: IAddComponentOptions): Promise<IComponent>;
1291
1291
  /**
1292
1292
  * 删除指定组件
1293
1293
  * @param params - 删除组件选项
1294
- * @param params.path - 组件路径,支持路径、UUID 或资源 URL
1294
+ * @param params.path - 组件路径
1295
1295
  * @returns 删除成功返回 true,失败返回 false
1296
1296
  */
1297
- removeComponent(params: IRemoveComponentOptions): Promise<boolean>;
1297
+ remove(params: IRemoveComponentOptions): Promise<boolean>;
1298
1298
  /**
1299
1299
  * 设置组件属性
1300
1300
  * - CLI 调用时传入 ISetPropertyOptions,通过 componentPath 定位,属性为扁平键值对
1301
- * - 编辑器调用时传入 ISetPropertyOptionsForEditor,通过节点 UUID + dump 路径定位,属性为 IProperty 格式
1301
+ * - 编辑器调用时传入 ISetPropertyOptionsForEditor,通过节点路径 + dump 路径定位,属性为 IProperty 格式
1302
1302
  *
1303
1303
  * @param params - 设置属性选项,根据调用方不同传入不同类型
1304
1304
  * @returns 设置成功返回 true,失败返回 false
@@ -1311,9 +1311,9 @@ export declare interface IComponentService extends IServiceEvents {
1311
1311
  * properties: { string: 'Hello', fontSize: 32 },
1312
1312
  * });
1313
1313
  *
1314
- * // 编辑器方式:通过节点 UUID + dump 路径定位,传 IProperty 格式
1314
+ * // 编辑器方式:通过节点路径 + dump 路径定位,传 IProperty 格式
1315
1315
  * await setProperty({
1316
- * uuid: 'node-uuid',
1316
+ * nodePath: 'Canvas/MyNode',
1317
1317
  * path: '__comps__.0.string',
1318
1318
  * dump: { value: 'Hello', type: 'String' },
1319
1319
  * });
@@ -1331,33 +1331,33 @@ export declare interface IComponentService extends IServiceEvents {
1331
1331
  * @example
1332
1332
  * ```ts
1333
1333
  * CLI 模式:返回 IComponent(扁平属性)
1334
- * const comp = await queryComponent({ path: 'Canvas/cc.Label_1' }) as IComponent;
1334
+ * const comp = await query({ path: 'Canvas/cc.Label_1' }) as IComponent;
1335
1335
  *
1336
1336
  * 编辑器模式:直接传 string,这里是uuid,因为与cli重复了,也支持 path 和 url
1337
- * const comp = await queryComponent('uuid') as IComponentForEditor;
1337
+ * const comp = await query('uuid') as IComponentForEditor;
1338
1338
  * ```
1339
1339
  */
1340
- queryComponent(params: IQueryComponentOptions | string): Promise<IComponent | IComponentForEditor | null>;
1340
+ query(params: IQueryComponentOptions | string): Promise<IComponent | IComponentForEditor | null>;
1341
1341
  /**
1342
1342
  * 获取所有已注册的组件类名,包含内置与自定义组件
1343
1343
  * @returns 组件类名数组,如 ['cc.Label', 'cc.Sprite', 'MyCustomComponent']
1344
1344
  */
1345
- queryAllComponent(): Promise<string[]>;
1345
+ queryAll(): Promise<string[]>;
1346
1346
  /**
1347
- * 创建组件(编辑器使用),与 addComponent 不同的是仅返回是否成功
1347
+ * 创建组件(编辑器使用),与 add 不同的是仅返回是否成功
1348
1348
  * @param params - 添加组件选项
1349
- * @param params.nodePathOrUuid - 目标节点路径或 UUID
1349
+ * @param params.nodePath - 目标节点路径
1350
1350
  * @param params.component - 组件类名
1351
1351
  * @returns 创建成功返回 true,失败返回 false
1352
1352
  */
1353
- createComponent(params: IAddComponentOptions): Promise<boolean>;
1353
+ create(params: IAddComponentOptions): Promise<boolean>;
1354
1354
  /**
1355
1355
  * 复位组件,将组件所有属性恢复为默认值
1356
1356
  * @param params - 查询组件选项,用于定位要复位的组件
1357
- * @param params.path - 组件路径,支持路径、UUID 或资源 URL
1357
+ * @param params.path - 组件路径
1358
1358
  * @returns 复位成功返回 true,失败返回 false
1359
1359
  */
1360
- resetComponent(params: IQueryComponentOptions): Promise<boolean>;
1360
+ reset(params: IQueryComponentOptions): Promise<boolean>;
1361
1361
  /**
1362
1362
  * 获取所有注册类名,支持按继承关系过滤
1363
1363
  * @param options - 过滤选项,不传则返回所有注册类
@@ -1382,25 +1382,25 @@ export declare interface IComponentService extends IServiceEvents {
1382
1382
  }[]>;
1383
1383
  /**
1384
1384
  * 查询指定节点上所有组件暴露的可调用函数
1385
- * @param uuid - 节点 UUID
1385
+ * @param path - 节点路径
1386
1386
  * @returns 节点上组件的函数信息,节点不存在时返回空对象
1387
1387
  */
1388
- queryComponentFunctionOfNode(uuid: string): Promise<any>;
1388
+ queryFunctionOfNode(path: string): Promise<any>;
1389
1389
  /**
1390
1390
  * 执行组件上的指定方法
1391
1391
  * @param options - 执行选项
1392
- * @param options.uuid - 组件实例的 UUID
1392
+ * @param options.path - 组件路径,如 'Canvas/cc.Label_1'
1393
1393
  * @param options.name - 要执行的方法名,如 'onLoad'、'start'
1394
1394
  * @param options.args - 方法参数列表
1395
1395
  * @returns 执行成功返回 true,失败返回 false
1396
1396
  */
1397
- executeComponentMethod(options: IExecuteComponentMethodOptions): Promise<boolean>;
1397
+ executeMethod(options: IExecuteComponentMethodOptions): Promise<any>;
1398
1398
  /**
1399
1399
  * 查询指定名称的组件是否已注册(是否存在对应脚本)
1400
1400
  * @param name - 组件类名,如 'cc.Label'
1401
1401
  * @returns 存在返回 true,不存在返回 false
1402
1402
  */
1403
- queryComponentHasScript(name: string): Promise<boolean>;
1403
+ hasScript(name: string): Promise<boolean>;
1404
1404
  init(): void;
1405
1405
  unregisterCompMgrEvents(): void;
1406
1406
  }
@@ -1638,7 +1638,7 @@ export declare interface IEngineService extends IServiceEvents {
1638
1638
  * 执行组件方法的选项
1639
1639
  */
1640
1640
  export declare interface IExecuteComponentMethodOptions {
1641
- uuid: string;
1641
+ path: string;
1642
1642
  name: string;
1643
1643
  args: any[];
1644
1644
  }
@@ -1892,6 +1892,31 @@ export declare interface INode extends INodeIdentifier {
1892
1892
  prefab: IPrefabInfo | null;
1893
1893
  }
1894
1894
 
1895
+ export declare interface INodeForEditor {
1896
+ active: IProperty;
1897
+ locked: IProperty;
1898
+ name: IProperty;
1899
+ position: IProperty;
1900
+ /**
1901
+ * 此为 dump 数据,非 node.rotation
1902
+ * 实际指向 node.eulerAngles
1903
+ * rotation 为了给用户更友好的文案
1904
+ */
1905
+ rotation: IProperty;
1906
+ mobility: IProperty;
1907
+ scale: IProperty;
1908
+ layer: IProperty;
1909
+ uuid: IProperty;
1910
+ children: IProperty[];
1911
+ parent: IProperty;
1912
+ __comps__: IProperty[];
1913
+ __type__: string;
1914
+ __prefab__?: IPrefabForEditor;
1915
+ _prefabInstance?: any;
1916
+ removedComponents?: IRemovedComponentInfo[];
1917
+ mountedRoot?: string;
1918
+ }
1919
+
1895
1920
  export declare interface INodeIdentifier {
1896
1921
  nodeId: string;
1897
1922
  path: string;
@@ -1916,30 +1941,144 @@ export declare interface INodeService extends IServiceEvents {
1916
1941
  * 创建节点
1917
1942
  * @param params
1918
1943
  */
1919
- createNodeByType(params: ICreateByNodeTypeParams): Promise<INode | null>;
1944
+ createByType(params: ICreateByNodeTypeParams): Promise<INode | null>;
1920
1945
  /**
1921
1946
  * 创建节点
1922
1947
  * @param params
1923
1948
  */
1924
- createNodeByAsset(params: ICreateByAssetParams): Promise<INode | null>;
1949
+ createByAsset(params: ICreateByAssetParams): Promise<INode | null>;
1925
1950
  /**
1926
1951
  * 删除节点
1927
1952
  * @param params
1928
1953
  */
1929
- deleteNode(params: IDeleteNodeParams): Promise<IDeleteNodeResult | null>;
1954
+ delete(params: IDeleteNodeParams): Promise<IDeleteNodeResult | null>;
1930
1955
  /**
1931
1956
  * 更新节点
1932
1957
  * @param params
1933
1958
  */
1934
- updateNode(params: IUpdateNodeParams): Promise<IUpdateNodeResult>;
1959
+ update(params: IUpdateNodeParams): Promise<IUpdateNodeResult>;
1935
1960
  /**
1936
- * 查询节点
1961
+ * 查询节点信息
1962
+ * - 不传参数时,返回当前场景的 dump 数据(ISceneForEditor)
1963
+ * - 传入 string 时,返回指定路径节点的 dump 数据(编辑器模式,返回 INodeForEditor 数据)
1964
+ * - 传入 IQueryNodeParams 时,返回 INode(CLI 模式)
1965
+ *
1966
+ * @param params - 查询选项、节点路径字符串或不传
1967
+ * @returns 如果传入 IQueryNodeParams 返回 INode,如果传入 string 或不传返回 INodeForEditor 或 ISceneForEditor,未找到返回 null
1937
1968
  */
1938
- queryNode(params: IQueryNodeParams): Promise<INode | null>;
1969
+ query(params?: IQueryNodeParams | string): Promise<INode | INodeForEditor | ISceneForEditor | null>;
1939
1970
  /**
1940
1971
  * 查询节点树(层级管理器格式)
1941
1972
  */
1942
1973
  queryNodeTree(params: IQueryNodeTreeParams): Promise<INodeTreeItem | null>;
1974
+ /**
1975
+ * 预览设置节点属性,临时应用属性变更但不记录到 undo 栈
1976
+ * 用于编辑器中拖拽滑块等实时预览场景,首次调用时会缓存原始值,
1977
+ * 可通过 cancelPreviewSetProperty 恢复
1978
+ *
1979
+ * @param options - 设置属性选项
1980
+ * @param options.nodePath - 节点路径
1981
+ * @param options.path - 属性路径,如 'position'、'scale'
1982
+ * @param options.dump - 属性的 dump 数据
1983
+ * @returns 设置成功返回 true,节点或属性路径无效返回 false
1984
+ *
1985
+ * @example
1986
+ * ```ts
1987
+ * // 预览修改节点位置
1988
+ * await previewSetProperty({
1989
+ * nodePath: 'Canvas/MyNode',
1990
+ * path: 'position',
1991
+ * dump: { value: { x: 100, y: 200, z: 0 }, type: 'cc.Vec3' },
1992
+ * });
1993
+ * ```
1994
+ */
1995
+ previewSetProperty(options: ISetPropertyOptionsForEditor): Promise<boolean>;
1996
+ /**
1997
+ * 取消预览设置,将节点属性恢复到 previewSetProperty 调用前的值
1998
+ * 仅使用 options.nodePath 和 options.path,options.dump 不会被使用
1999
+ *
2000
+ * @param options - 设置属性选项
2001
+ * @param options.nodePath - 节点路径
2002
+ * @param options.path - 属性路径
2003
+ * @returns 恢复成功返回 true,无缓存的预览数据或节点无效返回 false
2004
+ */
2005
+ cancelPreviewSetProperty(options: ISetPropertyOptionsForEditor): Promise<boolean>;
2006
+ /**
2007
+ * 设置节点属性,会记录到 undo 栈
2008
+ *
2009
+ * @param options - 设置属性选项
2010
+ * @param options.nodePath - 节点路径
2011
+ * @param options.path - 属性路径,如 'position'、'rotation'、'layer'
2012
+ * @param options.dump - 属性的 dump 数据
2013
+ * @returns 设置成功返回 true,节点不存在返回 false
2014
+ *
2015
+ * @example
2016
+ * ```ts
2017
+ * await setProperty({
2018
+ * nodePath: 'Canvas/MyNode',
2019
+ * path: 'position',
2020
+ * dump: { value: { x: 100, y: 200, z: 0 }, type: 'cc.Vec3' },
2021
+ * });
2022
+ * ```
2023
+ */
2024
+ setProperty(options: ISetPropertyOptionsForEditor): Promise<boolean>;
2025
+ /**
2026
+ * 重置节点的变换属性(position、rotation、scale、mobility)到默认值
2027
+ *
2028
+ * @param path - 节点路径
2029
+ * @returns 重置成功返回 true,节点不存在返回 false
2030
+ */
2031
+ reset(path: string): Promise<boolean>;
2032
+ /**
2033
+ * 重置节点的单个属性到 CCClass 定义的默认值
2034
+ * 仅使用 options.nodePath 和 options.path,options.dump 不会被使用
2035
+ *
2036
+ * @param options - 设置属性选项
2037
+ * @param options.nodePath - 节点路径
2038
+ * @param options.path - 属性路径,如 'position'、'scale'
2039
+ * @returns 重置成功返回 true,节点不存在返回 false
2040
+ */
2041
+ resetProperty(options: ISetPropertyOptionsForEditor): Promise<boolean>;
2042
+ /**
2043
+ * 将节点上值为 null 的属性初始化为默认实例
2044
+ * 当属性为 null 且有定义构造函数类型时,会创建该类型的新实例
2045
+ * 仅使用 options.nodePath 和 options.path,options.dump 不会被使用
2046
+ *
2047
+ * @param options - 设置属性选项
2048
+ * @param options.nodePath - 节点路径
2049
+ * @param options.path - 属性路径
2050
+ * @returns 初始化成功返回 true,节点不存在返回 false
2051
+ *
2052
+ * @example
2053
+ * ```ts
2054
+ * // 将节点上值为 null 的自定义属性初始化
2055
+ * await updatePropertyFromNull({
2056
+ * nodePath: 'Canvas/MyNode',
2057
+ * path: 'customProperty',
2058
+ * dump: {} as IProperty,
2059
+ * });
2060
+ * ```
2061
+ */
2062
+ updatePropertyFromNull(options: ISetPropertyOptionsForEditor): Promise<boolean>;
2063
+ /**
2064
+ * 设置节点及其所有子节点的 layer 属性
2065
+ * 递归将相同的 layer 值应用到整个节点子树
2066
+ * 仅使用 options.nodePath 和 options.dump,options.path 不会被使用(内部固定为 'layer')
2067
+ *
2068
+ * @param options - 设置属性选项
2069
+ * @param options.nodePath - 节点路径
2070
+ * @param options.dump - layer 属性的 dump 数据
2071
+ *
2072
+ * @example
2073
+ * ```ts
2074
+ * await setNodeAndChildrenLayer({
2075
+ * nodePath: 'Canvas/MyNode',
2076
+ * path: 'layer',
2077
+ * dump: { value: 1 << 25, type: 'Enum' },
2078
+ * });
2079
+ * ```
2080
+ */
2081
+ setNodeAndChildrenLayer(options: ISetPropertyOptionsForEditor): Promise<void>;
1943
2082
  }
1944
2083
 
1945
2084
  export declare interface INodeTreeComponent {
@@ -2020,6 +2159,16 @@ export declare interface IPrefab {
2020
2159
  persistent: boolean;
2021
2160
  }
2022
2161
 
2162
+ export declare interface IPrefabForEditor {
2163
+ uuid: string;
2164
+ fileId: string;
2165
+ rootUuid: string;
2166
+ sync: boolean;
2167
+ prefabStateInfo: IPrefabStateInfo;
2168
+ targetOverrides?: ITargetOverrideInfoForEditor[];
2169
+ instance?: IProperty;
2170
+ }
2171
+
2023
2172
  export declare interface IPrefabInfo {
2024
2173
  /** 关联的预制体资源信息 */
2025
2174
  asset?: IPrefab;
@@ -2286,6 +2435,11 @@ export declare interface IRemoveComponentOptions {
2286
2435
  path: string;
2287
2436
  }
2288
2437
 
2438
+ export declare interface IRemovedComponentInfo {
2439
+ name: string;
2440
+ fileID: string;
2441
+ }
2442
+
2289
2443
  export declare interface IRevertToPrefabParams {
2290
2444
  nodePath: string;
2291
2445
  }
@@ -2307,6 +2461,20 @@ export declare interface IScene extends IBaseIdentifier {
2307
2461
  components: IComponentIdentifier[];
2308
2462
  }
2309
2463
 
2464
+ export declare interface ISceneForEditor {
2465
+ name: IProperty;
2466
+ active: IProperty;
2467
+ locked: IProperty;
2468
+ _globals: Record<string, IProperty>;
2469
+ isScene: boolean;
2470
+ autoReleaseAssets: IProperty;
2471
+ uuid: IProperty;
2472
+ children: IProperty[];
2473
+ parent: string;
2474
+ __type__: string;
2475
+ targetOverrides?: ITargetOverrideInfoForEditor[];
2476
+ }
2477
+
2310
2478
  export declare interface ISceneMouseEvent {
2311
2479
  x: number;
2312
2480
  y: number;
@@ -2385,10 +2553,9 @@ export declare interface IServiceEvents {
2385
2553
  onSetPropertyComponent?(comp: Component): void;
2386
2554
  onComponentAdded?(comp: Component): void;
2387
2555
  onComponentRemoved?(comp: Component): void;
2556
+ onBeforeChangeComponent?(node: Node_2): void;
2557
+ onBeforeAddComponent?(name: string, node: Node_2): void;
2388
2558
  onBeforeRemoveComponent?(comp: Component): void;
2389
- onComponentBeforeChanged?(node: Node_2): void;
2390
- onBeforeComponentAdded?(name: string, node: Node_2): void;
2391
- onComponentChanged?(name: string, opts: IChangeNodeOptions): void;
2392
2559
  onAssetDeleted?(uuid: string): void;
2393
2560
  onAssetChanged?(uuid: string): void;
2394
2561
  onAssetRefreshed?(uuid: string): void;
@@ -2429,7 +2596,7 @@ export declare interface ISetPropertyOptions {
2429
2596
  * 编辑器设置组件属性的选项
2430
2597
  */
2431
2598
  export declare interface ISetPropertyOptionsForEditor {
2432
- uuid: string;
2599
+ nodePath: string;
2433
2600
  path: string;
2434
2601
  dump: IProperty;
2435
2602
  record?: boolean;
@@ -2503,6 +2670,14 @@ export declare interface ITargetOverrideInfo {
2503
2670
  targetInfo: ITargetInfo | null;
2504
2671
  }
2505
2672
 
2673
+ export declare interface ITargetOverrideInfoForEditor {
2674
+ source: string;
2675
+ sourceInfo?: string[];
2676
+ propertyPath: string[];
2677
+ target: string;
2678
+ targetInfo?: string[];
2679
+ }
2680
+
2506
2681
  export declare interface IUerDataConfigItem {
2507
2682
  key?: string; // 唯一标识符
2508
2683
  // 配置显示的名字,如果需要翻译,则传入 i18n:${key}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@cocos/cocos-cli-types",
3
3
  "description": "types for cocos cli",
4
4
  "author": "cocos cli",
5
- "version": "0.0.1-alpha.24.1",
5
+ "version": "0.0.1-alpha.24.2",
6
6
  "main": "index.d.ts",
7
7
  "types": "index.d.ts",
8
8
  "exports": {