1/* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit ArkUI 19 */ 20 21import { AsyncCallback } from './@ohos.base'; 22import Want from './@ohos.app.ability.Want'; 23 24/** 25 * Plugin component template property. 26 * 27 * @interface PluginComponentTemplate 28 * @syscap SystemCapability.ArkUI.ArkUI.Full 29 * @since 8 30 */ 31interface PluginComponentTemplate { 32 /** 33 * Defines the source 34 * 35 * @type { string } 36 * @syscap SystemCapability.ArkUI.ArkUI.Full 37 * @since 8 38 */ 39 source: string; 40 41 /** 42 * Defines the ability 43 * 44 * @type { string } 45 * @syscap SystemCapability.ArkUI.ArkUI.Full 46 * @since 8 47 */ 48 ability: string; 49} 50 51/** 52 * Plugin component manager interface. 53 * 54 * @namespace pluginComponentManager 55 * @syscap SystemCapability.ArkUI.ArkUI.Full 56 * @since 8 57 */ 58declare namespace pluginComponentManager { 59 /** 60 * Defines KVObject 61 * 62 * @syscap SystemCapability.ArkUI.ArkUI.Full 63 * @since 8 64 */ 65 type KVObject = { [key: string]: number | string | boolean | [] | KVObject } 66 67 /** 68 * Plugin component push parameters. 69 * 70 * @interface PushParameters 71 * @syscap SystemCapability.ArkUI.ArkUI.Full 72 * @since 8 73 */ 74 interface PushParameters { 75 /** 76 * Defines want. 77 * 78 * @type { Want } 79 * @syscap SystemCapability.ArkUI.ArkUI.Full 80 * @since 8 81 */ 82 want: Want; 83 84 /** 85 * Defines name. 86 * 87 * @type { string } 88 * @syscap SystemCapability.ArkUI.ArkUI.Full 89 * @since 8 90 */ 91 name: string; 92 93 /** 94 * Defines data. 95 * 96 * @type { KVObject } 97 * @syscap SystemCapability.ArkUI.ArkUI.Full 98 * @since 8 99 */ 100 data: KVObject; 101 102 /** 103 * Defines extraData. 104 * 105 * @type { KVObject } 106 * @syscap SystemCapability.ArkUI.ArkUI.Full 107 * @since 8 108 */ 109 extraData: KVObject; 110 111 /** 112 * Defines jsonPath. 113 * 114 * @type { ?string } 115 * @syscap SystemCapability.ArkUI.ArkUI.Full 116 * @since 8 117 */ 118 jsonPath?: string; 119 } 120 121 /** 122 * Plugin component push parameters which is used in push function. 123 * 124 * @interface PushParameterForStage 125 * @syscap SystemCapability.ArkUI.ArkUI.Full 126 * @systemapi 127 * @since 9 128 */ 129 interface PushParameterForStage { 130 /** 131 * Defines owner. 132 * 133 * @type { Want } 134 * @syscap SystemCapability.ArkUI.ArkUI.Full 135 * @systemapi 136 * @since 9 137 */ 138 owner: Want; 139 140 /** 141 * Defines target. 142 * 143 * @type { Want } 144 * @syscap SystemCapability.ArkUI.ArkUI.Full 145 * @systemapi 146 * @since 9 147 */ 148 target: Want; 149 150 /** 151 * Defines name. 152 * 153 * @type { string } 154 * @syscap SystemCapability.ArkUI.ArkUI.Full 155 * @systemapi 156 * @since 9 157 */ 158 name: string; 159 160 /** 161 * Defines data. 162 * 163 * @type { KVObject } 164 * @syscap SystemCapability.ArkUI.ArkUI.Full 165 * @systemapi 166 * @since 9 167 */ 168 data: KVObject; 169 170 /** 171 * Defines extraData. 172 * 173 * @type { KVObject } 174 * @syscap SystemCapability.ArkUI.ArkUI.Full 175 * @systemapi 176 * @since 9 177 */ 178 extraData: KVObject; 179 180 /** 181 * Defines jsonPath. 182 * 183 * @type { ?string } 184 * @syscap SystemCapability.ArkUI.ArkUI.Full 185 * @systemapi 186 * @since 9 187 */ 188 jsonPath?: string; 189 } 190 191 /** 192 * Plugin component request parameters. 193 * 194 * @interface RequestParameters 195 * @syscap SystemCapability.ArkUI.ArkUI.Full 196 * @since 8 197 */ 198 interface RequestParameters { 199 /** 200 * Defines want. 201 * 202 * @type { Want } 203 * @syscap SystemCapability.ArkUI.ArkUI.Full 204 * @since 8 205 */ 206 want: Want; 207 208 /** 209 * Defines name. 210 * 211 * @type { string } 212 * @syscap SystemCapability.ArkUI.ArkUI.Full 213 * @since 8 214 */ 215 name: string; 216 217 /** 218 * Defines data. 219 * 220 * @type { KVObject } 221 * @syscap SystemCapability.ArkUI.ArkUI.Full 222 * @since 8 223 */ 224 data: KVObject; 225 226 /** 227 * Defines jsonPath. 228 * 229 * @type { ?string } 230 * @syscap SystemCapability.ArkUI.ArkUI.Full 231 * @since 8 232 */ 233 jsonPath?: string; 234 } 235 236 /** 237 * Plugin component request parameters which is used in request function. 238 * 239 * @interface RequestParameterForStage 240 * @syscap SystemCapability.ArkUI.ArkUI.Full 241 * @systemapi 242 * @since 9 243 */ 244 interface RequestParameterForStage { 245 /** 246 * Defines owner. 247 * 248 * @type { Want } 249 * @syscap SystemCapability.ArkUI.ArkUI.Full 250 * @systemapi 251 * @since 9 252 */ 253 owner: Want; 254 255 /** 256 * Defines target. 257 * 258 * @type { Want } 259 * @syscap SystemCapability.ArkUI.ArkUI.Full 260 * @systemapi 261 * @since 9 262 */ 263 target: Want; 264 /** 265 * Defines name. 266 * 267 * @type { string } 268 * @syscap SystemCapability.ArkUI.ArkUI.Full 269 * @systemapi 270 * @since 9 271 */ 272 name: string; 273 274 /** 275 * Defines data. 276 * 277 * @type { KVObject } 278 * @syscap SystemCapability.ArkUI.ArkUI.Full 279 * @systemapi 280 * @since 9 281 */ 282 data: KVObject; 283 284 /** 285 * Defines jsonPath. 286 * 287 * @type { ?string } 288 * @syscap SystemCapability.ArkUI.ArkUI.Full 289 * @systemapi 290 * @since 9 291 */ 292 jsonPath?: string; 293 } 294 295 /** 296 * Plugin component request callback parameters. 297 * 298 * @interface RequestCallbackParameters 299 * @syscap SystemCapability.ArkUI.ArkUI.Full 300 * @since 8 301 */ 302 interface RequestCallbackParameters { 303 304 /** 305 * Defines componentTemplate. 306 * 307 * @type { PluginComponentTemplate } 308 * @syscap SystemCapability.ArkUI.ArkUI.Full 309 * @since 8 310 */ 311 componentTemplate: PluginComponentTemplate; 312 313 /** 314 * Defines data. 315 * 316 * @type { KVObject } 317 * @syscap SystemCapability.ArkUI.ArkUI.Full 318 * @since 8 319 */ 320 data: KVObject; 321 322 /** 323 * Defines extraData. 324 * 325 * @type { KVObject } 326 * @syscap SystemCapability.ArkUI.ArkUI.Full 327 * @since 8 328 */ 329 extraData: KVObject; 330 } 331 332 /** 333 * Plugin component request event result value. 334 * 335 * @interface RequestEventResult 336 * @syscap SystemCapability.ArkUI.ArkUI.Full 337 * @since 8 338 */ 339 interface RequestEventResult { 340 /** 341 * Defines template. 342 * 343 * @type { ?string } 344 * @syscap SystemCapability.ArkUI.ArkUI.Full 345 * @since 8 346 */ 347 template?: string; 348 349 /** 350 * Defines data. 351 * 352 * @type { ?KVObject } 353 * @syscap SystemCapability.ArkUI.ArkUI.Full 354 * @since 8 355 */ 356 data?: KVObject; 357 358 /** 359 * Defines extraData. 360 * 361 * @type { ?KVObject } 362 * @syscap SystemCapability.ArkUI.ArkUI.Full 363 * @since 8 364 */ 365 extraData?: KVObject; 366 } 367 368 /** 369 * Plugin component push event callback. 370 * 371 * @syscap SystemCapability.ArkUI.ArkUI.Full 372 * @since 8 373 */ 374 type OnPushEventCallback = (source: Want, template: PluginComponentTemplate, data: KVObject, 375 extraData: KVObject) => void; 376 377 /** 378 * Plugin component request event callback. 379 * 380 * @syscap SystemCapability.ArkUI.ArkUI.Full 381 * @since 8 382 */ 383 384 type OnRequestEventCallback = (source: Want, name: string, data: KVObject) => RequestEventResult; 385 386 /** 387 * Plugin component push method. 388 * 389 * @param { PushParameters } param 390 * @param { AsyncCallback<void> } callback 391 * @syscap SystemCapability.ArkUI.ArkUI.Full 392 * @since 8 393 */ 394 function push(param: PushParameters, callback: AsyncCallback<void>): void; 395 396 /** 397 * Plugin component request method. 398 * 399 * @param { RequestParameters } param 400 * @param { AsyncCallback<RequestCallbackParameters> } callback 401 * @syscap SystemCapability.ArkUI.ArkUI.Full 402 * @since 8 403 */ 404 function request(param: RequestParameters, callback: AsyncCallback<RequestCallbackParameters>): void; 405 406 /** 407 * Plugin component push method used to send the information of the template it provides. 408 * 409 * @param { PushParameterForStage } param - Plugin component push parameters for stage. 410 * @param { AsyncCallback<void> } callback - Plugin component push event callback. 411 * @syscap SystemCapability.ArkUI.ArkUI.Full 412 * @systemapi 413 * @StageModelOnly 414 * @since 9 415 */ 416 function push(param: PushParameterForStage, callback: AsyncCallback<void>): void; 417 418 /** 419 * Plugin component request method used to send a request for the information of the template it wants. 420 * 421 * @param { RequestParameterForStage } param - Plugin component request parameters for stage. 422 * @param { AsyncCallback<RequestCallbackParameters> } callback - Plugin component request event callback. 423 * @syscap SystemCapability.ArkUI.ArkUI.Full 424 * @systemapi 425 * @StageModelOnly 426 * @since 9 427 */ 428 function request(param: RequestParameterForStage, callback: AsyncCallback<RequestCallbackParameters>): void; 429 430 /** 431 * Plugin component event listener. 432 * 433 * @param { string } eventType 434 * @param { OnPushEventCallback | OnRequestEventCallback } callback 435 * @syscap SystemCapability.ArkUI.ArkUI.Full 436 * @since 8 437 */ 438 function on(eventType: string, callback: OnPushEventCallback | OnRequestEventCallback): void; 439} 440 441export default pluginComponentManager; 442export type { PluginComponentTemplate };