| IMenuItem,
934 | target?: string
935 | ): void;
936 | }
937 |
938 | /**
939 | * 命令模块
940 | */
941 | export namespace command {
942 | interface ICommandHandlerArg {
943 | context: any;
944 | data: any;
945 | type: string;
946 | }
947 | interface ICommandHandler {
948 | (arg: ICommandHandlerArg): any;
949 | }
950 | /**
951 | * 注册一个命令
952 | * @param {string} commandType 命令名称
953 | * @param {handler} 命令回调函数
954 | *
955 | * 命令注册成功后会在 CS 全局可用,建议命令名以 '模块.具体操作' 格式注册,例如 'Editor.Close'
956 | */
957 | export function registerCommand(
958 | commandType: string,
959 | handler: ICommandHandler
960 | ): IDisposable;
961 |
962 | /**
963 | * 手动触发一个已注册的命令
964 | * @param {string} commandType 命令名称
965 | * @param payload 命令参数,会传入到注册的命令回调函数中
966 | *
967 | * ```javascript
968 | * registerCommand('Git.Commit', (commitMessage) => {
969 | * // ...
970 | * });
971 | *
972 | * const CommitBtn = (props) => {
973 | *
974 | *
977 | *
978 | * }
979 | * ```
980 | */
981 | export function executeCommand(commandType: string, payload?: any): void;
982 |
983 | /**
984 | * 一个组合键实例
985 | */
986 | interface IKeyMaps {
987 | /**
988 | * 按下组合键后触发的命令
989 | */
990 | command: string;
991 | /**
992 | * mac os键位
993 | */
994 | mac: string;
995 | /**
996 | * windows 键位
997 | */
998 | win: string;
999 | /**
1000 | * 名称
1001 | */
1002 | label: any;
1003 | }
1004 | interface IKeyBinding {
1005 | /**
1006 | * 组合名
1007 | */
1008 | name: string;
1009 | keymaps: Array;
1010 | }
1011 | /**
1012 | * 注册快捷键组合
1013 | *
1014 | * @param {IKeyBinding} keyBindings 快捷键组合
1015 | * @return {IDisposable} 清除快捷键
1016 | *
1017 | * **Note:** 快捷键只能用于手动触发 registerCommand 函数注册的命令
1018 | *
1019 | * 例如 'ctrl+c' 表示一个快捷键组合
1020 | * 如果组合键已被占用将无法注册,可在 CS 设置面板->快捷键查看已注册的插件快捷键和系统快捷键
1021 | *
1022 | * 目前暂不支持修改已注册的快捷键
1023 | */
1024 | export function registerKeyBindings(keyBindings: IKeyBinding): IDisposable;
1025 | }
1026 |
1027 | /**
1028 | * 窗口相关方法
1029 | */
1030 | export namespace actions {
1031 | interface INotify {
1032 | notifyType: "ERROR" | "INFO";
1033 | message: any;
1034 | }
1035 | /**
1036 | * 弹出一个通知
1037 | * @param {INotify} notify 通知
1038 | *
1039 | * 此方法需要传入通知类型,目前支持 ERROR 和 INFO
1040 | */
1041 | export function notification(notify: INotify): void;
1042 |
1043 | /**
1044 | * 弹出一个错误通知
1045 | * @param {string} message 通知消息
1046 | */
1047 | export function errorNotify(message: string | object): void;
1048 |
1049 | /**
1050 | * 弹出一个默认通知
1051 | * @param {string} message 通知消息
1052 | */
1053 | export function infoNotify(message: string | object): void;
1054 |
1055 | /**
1056 | * 在左下角状态栏显示一条消息,不传入 hideAfterTimeout 默认 3000 ms 后自动隐藏消息
1057 | *
1058 | * @param {string} text 要显示的消息
1059 | * @param {number} hideAfterTimeout 显示时间,单位 ms
1060 | * @return {IStatusBarMsgDispose} 清除函数,调用后立即隐藏消息
1061 | *
1062 | * ```javascript
1063 | * const dipose = actions.setStatusBarMessage('一条调皮的状态消息', 10000);
1064 | * setTimeout(() => {
1065 | * dipose();
1066 | * }, 2000)
1067 | * ```
1068 | */
1069 | export function setStatusBarMessage(
1070 | text: string,
1071 | hideAfterTimeout: number | Promise
1072 | ): IDisposable;
1073 |
1074 | /**
1075 | * 在左下角状态栏显示一条消息,不传入 hideWhenDone 默认 3000 ms 后自动隐藏消息
1076 | *
1077 | * @param {string} text 要显示的消息
1078 | * @param {number} hideWhenDone Promise 执行完毕自动隐藏消息
1079 | * @return {IStatusBarMsgDispose} 清除函数,调用后立即隐藏消息
1080 | *
1081 | * ```javascript
1082 | * const task = new Promise((resolve, reject) => {
1083 | * setTimeout(() => {
1084 | * resolve()
1085 | * }, 5000)
1086 | * });
1087 | *
1088 | * const dispose = actions.setStatusBarMessage('第二条调皮的消息', task);
1089 | * ```
1090 | */
1091 | export function setStatusBarMessage(
1092 | text: string,
1093 | hideWhenDone: Promise
1094 | ): IDisposable;
1095 | }
1096 |
1097 | /**
1098 | * 插件注册相关
1099 | */
1100 | interface IInjectLabel {
1101 | [propName: string]: any;
1102 | }
1103 |
1104 | interface IComponentGetter {
1105 | (extensions: any): any;
1106 | }
1107 |
1108 | interface IPluginChildren {
1109 | position: string;
1110 | key: string;
1111 | label: any;
1112 | view: any;
1113 | }
1114 |
1115 | type IAppRegisterCallBackFn = (...args: Array) => any;
1116 |
1117 | type IAppUnRegisterCallBackFn = IAppRegisterCallBackFn;
1118 |
1119 | type IPluginRegisterFn = (children: IPluginChildren, callback: IAppRegisterCallBackFn) => void;
1120 |
1121 | /**
1122 | * 组件注入方法
1123 | */
1124 | interface IInjectFn {
1125 | (
1126 | /**
1127 | * 位置
1128 | */
1129 | position: string,
1130 | /**
1131 | * 显示标签
1132 | */
1133 | label: IInjectLabel,
1134 | /**
1135 | * 返回组件的回调函数
1136 | */
1137 | getComponent: IComponentGetter,
1138 | /**
1139 | * 注入组件后的回调函数
1140 | */
1141 | callback?: IAppRegisterCallBackFn
1142 | ): IPluginRegisterFn;
1143 | }
1144 |
1145 | /**
1146 | * 卸载插件
1147 | */
1148 | type IPluginUnRegisterFn = (children: any, callback?: IAppUnRegisterCallBackFn) => void;
1149 |
1150 | /**
1151 | * 菜单栏注入点
1152 | */
1153 | interface IMENUBAR {
1154 | // 插件将在菜单栏右侧以 widget 形式显示
1155 | WIDGET: string;
1156 | }
1157 |
1158 | /**
1159 | * 侧边栏注入点
1160 | */
1161 | interface ISIDEBAR {
1162 | // 右侧边栏
1163 | RIGHT: string;
1164 | // 左侧边栏
1165 | LEFT: string;
1166 | // 下边栏
1167 | BOTTOM: string;
1168 | }
1169 |
1170 | /**
1171 | * 顶部面包屑导航
1172 | */
1173 | interface ITOPBAR {
1174 | // 右侧以 widget 形式显示
1175 | WIDGET: string;
1176 | }
1177 |
1178 | interface ICONTAINERS {
1179 | UTILITIES: string;
1180 | }
1181 |
1182 | interface ISTATUSBAR {
1183 | WIDGET: string;
1184 | }
1185 |
1186 | interface IEDITOR {
1187 | CENTER: string;
1188 | VIEW: string;
1189 | }
1190 |
1191 | interface IPluginPosition {
1192 | MENUBAR: IMENUBAR;
1193 | SIDEBAR: ISIDEBAR;
1194 | TOPBAR: ITOPBAR;
1195 | CONTAINERS: ICONTAINERS;
1196 | STATUSBAR: ISTATUSBAR;
1197 | EDITOR: IEDITOR;
1198 | }
1199 |
1200 | interface IInjectComponent {
1201 | inject: IInjectFn;
1202 | register: IPluginRegisterFn;
1203 | unregister: IPluginUnRegisterFn;
1204 | PluginArea: any;
1205 | position: IPluginPosition;
1206 | }
1207 |
1208 | interface IRequest {
1209 | (options: any): Promise;
1210 | get: (options: any) => Promise;
1211 | postJSON: (options: any) => Promise;
1212 | }
1213 |
1214 | interface ILangProp {
1215 | [propName: string]: string;
1216 | }
1217 | interface ILanguage {
1218 | [propName: string]: ILangProp;
1219 | }
1220 |
1221 | interface ILanguagePool {
1222 | zh_CN: ILanguage;
1223 | en_US: ILanguage;
1224 | }
1225 |
1226 | export interface II18nConf {
1227 | customLanguagePool: ILanguagePool;
1228 | }
1229 |
1230 | interface IStylusObject {
1231 | use: () => void;
1232 | unuse: () => void;
1233 | }
1234 | interface IStyles {
1235 | dark: IStylusObject;
1236 | light: IStylusObject;
1237 | }
1238 | interface IPluginContextConf {
1239 | i18n?: II18nConf;
1240 | styles?: IStyles;
1241 | [propName: string]: any;
1242 | }
1243 |
1244 | interface II18nScope {
1245 | get: any;
1246 | }
1247 |
1248 | interface I18n {
1249 | get: (template: string) => string;
1250 | (template: string): any;
1251 | }
1252 |
1253 | export class PluginContext {
1254 | constructor(config: IPluginContextConf);
1255 | inializeData: any;
1256 | injectComponent: IInjectComponent;
1257 | request: IRequest;
1258 | i18n: I18n;
1259 | sdk: any;
1260 | }
1261 |
1262 | interface IAppManager {
1263 | pluginWillMount?: () => void;
1264 | pluginWillUnMount?: () => void;
1265 | [propName: string]: any;
1266 | }
1267 | interface IAppRegisterConf {
1268 | key: string;
1269 | Manager: IAppManager;
1270 | app?: any;
1271 | }
1272 |
1273 | interface IPluginProperties {
1274 | [propkey: string]: IProperties;
1275 | }
1276 |
1277 | /**
1278 | * 自定义设置项
1279 | */
1280 | interface IProperties {
1281 | /**
1282 | * 标题
1283 | */
1284 | title: string;
1285 | /**
1286 | * 描述
1287 | */
1288 | description?: string;
1289 | /**
1290 | * 值类型
1291 | */
1292 | type: string;
1293 | /**
1294 | * 默认值
1295 | */
1296 | default: Array | string | boolean | null;
1297 | /**
1298 | * 枚举值,可选
1299 | */
1300 | enum?: Array;
1301 | }
1302 | interface IPluginConfiguration {
1303 | /**
1304 | * 插件唯一 key
1305 | */
1306 | key: string;
1307 | /**
1308 | * 需要显示在设置面板中的标签页标题
1309 | */
1310 | title: string;
1311 | /**
1312 | * 注册的设置项,包含设置项的唯一 key、title、默认值、类型及描述等信息
1313 | */
1314 | properties: IPluginProperties;
1315 | }
1316 |
1317 | type IPluginConfigChangeHandler = (propKey: string, oldValue: any, newValue: any) => void;
1318 |
1319 | /**
1320 | * 注册一系列插件自定义设置项,该设置会在 CS -> 设置面板中以单独的标签展示
1321 | * @param {IPluginConfiguration} configuration 设置项
1322 | *
1323 | * 相同插件 key 多次注册的设置项会被替换
1324 | *
1325 | * **Note:** 请分清 type 属性表示设置项值的属性类型,用字符串表示
1326 | *
1327 | * 设置项的书写规则非常简单,例如你的设置项负责管理启动/禁用某功能,则其中 type 值应为 boolean,default 为 true/false
1328 | * 这将会被渲染为一个 checkbox
1329 | *
1330 | * 又或者你希望设置项是一个下拉选择框,就需要包含 enum 属性,并提供所有可选项
1331 | *
1332 | * 而如果设置项 type 为 string ,default 为 null 或 空串,则会被渲染为一个普通的输入框
1333 | * ```javascript
1334 | * const mySettings = {
1335 | * key: 'my-plugin',
1336 | * title; ‘My Plugin Setting’,
1337 | * properties: {
1338 | * 'enable.autofocus': {
1339 | * type: boolean,
1340 | * title: '启用自动聚焦'
1341 | * default: false,
1342 | * description: 'enable autofocus',
1343 | * },
1344 | * 'render.mode': {
1345 | * type: string,
1346 | * enum: [
1347 | * 'canvas',
1348 | * 'dom',
1349 | * 'auto',
1350 | * ],
1351 | * default: 'auto',
1352 | * title: '选择渲染模式',
1353 | * description: 'some secription...',
1354 | * }
1355 | * }
1356 | * }
1357 | * registerPluginConfiguration(mySettings)
1358 | * ```
1359 | */
1360 | export function registerPluginConfiguration(
1361 | configuration: IPluginConfiguration
1362 | ): void;
1363 | interface IPluginKVProperties {
1364 | [propName: string]: any;
1365 | }
1366 | /**
1367 | * 获取指定插件 key 注册的所有设置项的 key/value 对象
1368 | *
1369 | * @param {string} pluginKey 插件唯一 key
1370 | * @return {IPluginKVProperties} key/value 对象
1371 | *
1372 | */
1373 | export function getPluginConfiguration(
1374 | pluginKey: string
1375 | ): IPluginKVProperties;
1376 | /**
1377 | * 注册指定插件所注册设置项被修改时的回调函数
1378 | *
1379 | * @param {string} pluginKey 插件唯一 key
1380 | * @param {IPluginConfigChangeHandler} fn 回调函数
1381 | * @return {IDisposable} dispose 清除回调函数
1382 | *
1383 | * 回调函数会在对应插件的自定义设置项发生改变时被调用
1384 | * 可以获取到包括发生改变设置项的唯一 key, 以及新/旧值
1385 | */
1386 | export function registerPluginConfigChangeHandler(
1387 | pluginKey: string,
1388 | fn: IPluginConfigChangeHandler
1389 | ): IDisposable;
1390 | export function appRegistry(
1391 | registerConf: Array,
1392 | callbackfn?: IAppRegisterCallBackFn
1393 | ): void;
1394 |
1395 | type IDisposable = () => void;
1396 |
1397 | interface IAdvanceProviderConnect {
1398 | Provider: any
1399 | connect: any
1400 | }
1401 | export function createAdvancedProviderAndConnect(storeKey: string): IAdvanceProviderConnect
1402 | /**
1403 | * 生成插件唯一 pluginKey
1404 | */
1405 | export function generatePluginKey():string;
1406 | }
1407 |
--------------------------------------------------------------------------------