1/* 2 * Copyright (c) 2021 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 * Provides an interface for attribute subscribers. 18 * @since 7 19 * @systemapi 20 */ 21interface IPropertySubscriber { 22 /** 23 * Called when the ID of the property subscriber is queried. 24 * @since 7 25 * @systemapi 26 */ 27 id(): number; 28 29 /** 30 * Provides a single attribute change user interface. 31 * @since 7 32 * @systemapi 33 */ 34 aboutToBeDeleted(owningView?: IPropertySubscriber): void; 35} 36 37/** 38 * Defines the subscriber. 39 * @since 7 40 * @systemapi 41 */ 42interface ISinglePropertyChangeSubscriber<T> extends IPropertySubscriber { 43 /** 44 * Provides a single attribute change user interface. 45 * @since 7 46 * @systemapi 47 */ 48 hasChanged(newValue: T): void; 49} 50 51/** 52 * Defines the subscribed abstract property. 53 * @since 7 54 * @systemapi 55 */ 56declare abstract class SubscribedAbstractProperty<T> { 57 /** 58 * Setting Subscribers. 59 * @since 7 60 * @systemapi 61 */ 62 protected subscribers_: Set<number>; 63 64 /** 65 * Private user ID. 66 * @since 7 67 * @systemapi 68 */ 69 private id_; 70 71 /** 72 * Private user information. 73 * @since 7 74 * @systemapi 75 */ 76 private info_?; 77 78 /** 79 * @since 7 80 * @systemapi 81 */ 82 constructor( 83 /** 84 * Subscriber IPropertySubscriber. 85 * @since 7 86 * @systemapi 87 */ 88 subscribeMe?: IPropertySubscriber, 89 /** 90 * Subscriber info. 91 * @since 7 92 * @systemapi 93 */ 94 info?: string, 95 ); 96 97 /** 98 * Called when the subscriber ID is entered. 99 * @since 7 100 * @systemapi 101 */ 102 id(): number; 103 104 /** 105 * Called when a subscriber information description is entered. 106 * @since 7 107 * @systemapi 108 */ 109 info(): string; 110 111 /** 112 * Called when data is obtained. 113 * @since 7 114 * @systemapi 115 */ 116 abstract get(): T; 117 118 /** 119 * Called when data is created. 120 * @since 7 121 * @systemapi 122 */ 123 abstract set(newValue: T): void; 124 125 /** 126 * Called when a two-way synchronization is created. 127 * @since 7 128 * @systemapi 129 */ 130 createTwoWaySync(subscribeMe?: IPropertySubscriber, info?: string): SyncedPropertyTwoWay<T>; 131 132 /** 133 * Called when a one-way synchronization is created. 134 * @since 7 135 * @systemapi 136 */ 137 createOneWaySync(subscribeMe?: IPropertySubscriber, info?: string): SyncedPropertyOneWay<T>; 138 139 /** 140 * Called when the subscriber is unlinked. 141 * @since 7 142 * @systemapi 143 */ 144 unlinkSuscriber(subscriberId: number): void; 145 146 /** 147 * Called when the notification has changed. 148 * @since 7 149 * @systemapi 150 */ 151 protected notifyHasChanged(newValue: T): void; 152 153 /** 154 * Called when the notification property is read. 155 * @since 7 156 * @systemapi 157 */ 158 protected notifyPropertyRead(): void; 159 160 /** 161 * Called when the number of users is queried. 162 * @since 7 163 * @systemapi 164 */ 165 numberOfSubscrbers(): number; 166} 167 168/** 169 * Defines the state value. 170 * @since 7 171 * @systemapi 172 */ 173declare class SyncedPropertyTwoWay<T> 174 extends SubscribedAbstractProperty<T> 175 implements ISinglePropertyChangeSubscriber<T> 176{ 177 /** 178 * Sources of synchronization attributes bidirectionally. 179 * @since 7 180 * @systemapi 181 */ 182 private source_; 183 184 /** 185 * constructor parameters. 186 * @since 7 187 * @systemapi 188 */ 189 constructor(source: SubscribedAbstractProperty<T>, subscribeMe?: IPropertySubscriber, info?: string); 190 191 /** 192 * Called when processing information about to be deleted. 193 * @since 7 194 * @systemapi 195 */ 196 aboutToBeDeleted(unsubscribeMe?: IPropertySubscriber): void; 197 198 /** 199 * Information Changed. 200 * @since 7 201 * @systemapi 202 */ 203 hasChanged(newValue: T): void; 204 205 /** 206 * Called when data is obtained. 207 * @since 7 208 * @systemapi 209 */ 210 get(): T; 211 212 /** 213 * Called when data is created. 214 * @since 7 215 * @systemapi 216 */ 217 set(newValue: T): void; 218} 219 220/** 221 * Defines the prop state value. 222 * @since 7 223 * @systemapi 224 */ 225declare class SyncedPropertyOneWay<T> 226 extends SubscribedAbstractProperty<T> 227 implements ISinglePropertyChangeSubscriber<T> 228{ 229 /** 230 * Pack value for single-item binding. 231 * @since 7 232 * @systemapi 233 */ 234 private wrappedValue_; 235 236 /** 237 * Sources of synchronization attributes bidirectionally. 238 * @since 7 239 * @systemapi 240 */ 241 private source_; 242 243 /** 244 * Constructor parameters. 245 * @since 7 246 * @systemapi 247 */ 248 constructor(source: SubscribedAbstractProperty<T>, subscribeMe?: IPropertySubscriber, info?: string); 249 250 /** 251 * Called when processing information about to be deleted. 252 * @since 7 253 * @systemapi 254 */ 255 aboutToBeDeleted(unsubscribeMe?: IPropertySubscriber): void; 256 257 /** 258 * Information Changed. 259 * @since 7 260 * @systemapi 261 */ 262 hasChanged(newValue: T): void; 263 264 /** 265 * Called when data is obtained. 266 * @since 7 267 * @systemapi 268 */ 269 get(): T; 270 271 /** 272 * Called when data is created. 273 * @since 7 274 * @systemapi 275 */ 276 set(newValue: T): void; 277} 278 279/** 280 * Defines the AppStorage interface. 281 * @since 7 282 */ 283declare class AppStorage { 284 /** 285 * Called when a link is set. 286 * @since 7 287 */ 288 static Link(propName: string): any; 289 290 /** 291 * Called when a hyperlink is set. 292 * @since 7 293 */ 294 static SetAndLink<T>(propName: string, defaultValue: T): SubscribedAbstractProperty<T>; 295 296 /** 297 * Called when a property is set. 298 * @since 7 299 */ 300 static Prop(propName: string): any; 301 302 /** 303 * Called when dynamic properties are set. 304 * @since 7 305 */ 306 static SetAndProp<S>(propName: string, defaultValue: S): SubscribedAbstractProperty<S>; 307 308 /** 309 * Called when owning or not. 310 * @since 7 311 */ 312 static Has(propName: string): boolean; 313 314 /** 315 * Called when data is obtained. 316 * @since 7 317 */ 318 static Get<T>(propName: string): T | undefined; 319 320 /** 321 * Called when setting. 322 * @since 7 323 */ 324 static Set<T>(propName: string, newValue: T): boolean; 325 326 /** 327 * Called when setting or creating. 328 * @since 7 329 */ 330 static SetOrCreate<T>(propName: string, newValue: T): void; 331 332 /** 333 * Called when a deletion is made. 334 * @since 7 335 */ 336 static Delete(propName: string): boolean; 337 338 /** 339 * Called when a dictionary is sorted. 340 * @since 7 341 */ 342 static Keys(): IterableIterator<string>; 343 344 /** 345 * Called when a cleanup occurs. 346 * @since 7 347 */ 348 static staticClear(): boolean; 349 350 /** 351 * Called when the data can be changed. 352 * @since 7 353 */ 354 static IsMutable(propName: string): boolean; 355 356 /** 357 * Called when you check how much data is stored. 358 * @since 7 359 */ 360 static Size(): number; 361} 362 363/** 364 * Defines the Environment interface. 365 * @since 7 366 */ 367declare class Environment { 368 /** 369 * Constructor. 370 * @since 7 371 * @systemapi 372 * @hide 373 */ 374 constructor(); 375 376 /** 377 * Called when a property value is checked. 378 * @since 7 379 */ 380 static EnvProp<S>(key: string, value: S): boolean; 381 382 /** 383 * Called when multiple property values are checked. 384 * @since 7 385 */ 386 static EnvProps( 387 props: { 388 key: string; 389 defaultValue: any; 390 }[], 391 ): void; 392 393 /** 394 * Set the key value. 395 * @since 7 396 */ 397 static Keys(): Array<string>; 398} 399 400/** 401 * Defines the ColorMode of device. 402 * @since 7 403 */ 404declare enum ColorMode { 405 /** 406 * Light mode. 407 * @since 7 408 */ 409 LIGHT = 0, 410 411 /** 412 * Dark mode. 413 * @since 7 414 */ 415 DARK, 416} 417 418/** 419 * Defines the LayoutDirection of device. 420 * @since 7 421 */ 422declare enum LayoutDirection { 423 /** 424 * Elements are laid out from left to right. 425 * @since 7 426 */ 427 LTR, 428 429 /** 430 * Elements are laid out from right to left. 431 * @since 7 432 */ 433 RTL, 434 435 /** 436 * Elements are laid out from auto. 437 * @since 8 438 */ 439 Auto, 440} 441 442/** 443 * Defines the PersistentStorage interface. 444 * @since 7 445 */ 446declare class PersistentStorage { 447 /** 448 * Constructor parameters. 449 * @since 7 450 * @systemapi 451 * @hide 452 */ 453 constructor(appStorage: AppStorage, storage: Storage); 454 455 /** 456 * Called when a persistence property is stored. 457 * @since 7 458 */ 459 static PersistProp<T>(key: string, defaultValue: T): void; 460 461 /** 462 * Called when a property is deleted. 463 * @since 7 464 */ 465 static DeleteProp(key: string): void; 466 467 /** 468 * Called when multiple persistence properties are stored. 469 * @since 7 470 */ 471 static PersistProps( 472 properties: { 473 key: string; 474 defaultValue: any; 475 }[], 476 ): void; 477 478 /** 479 * Set the key value. 480 * @since 7 481 */ 482 static Keys(): Array<string>; 483} 484 485/** 486 * Defines the base class of storage. 487 * @since 7 488 * @systemapi 489 */ 490declare class Storage { 491 /** 492 * Constructor parameters. 493 * @since 7 494 * @systemapi 495 * @hide 496 */ 497 constructor(needCrossThread?: boolean, file?: string); 498 499 /** 500 * Called when data is obtained. 501 * @since 7 502 * @systemapi 503 * @hide 504 */ 505 get(key: string): string | undefined; 506 507 /** 508 * Called when setting. 509 * @since 7 510 * @systemapi 511 * @hide 512 */ 513 set(key: string, val: any): void; 514 515 /** 516 * Called when data is cleared. 517 * @since 7 518 * @systemapi 519 * @hide 520 */ 521 clear(): void; 522 523 /** 524 * Called when data is deleted. 525 * @since 7 526 * @systemapi 527 * @hide 528 */ 529 delete(key: string): void; 530} 531 532/** 533 * Defines the Subscribale base class. 534 * @since 7 535 * @systemapi 536 * @hide 537 */ 538declare abstract class SubscribaleAbstract { 539 /** 540 * Returns the ownership attribute set by the. 541 * @since 7 542 * @systemapi 543 * @hide 544 */ 545 private owningProperties_: Set<number>; 546 547 /** 548 * Constructor. 549 * @since 7 550 * @systemapi 551 * @hide 552 */ 553 constructor(); 554 555 /** 556 * Called when the notification property has changed. 557 * @since 7 558 * @systemapi 559 * @hide 560 */ 561 protected notifyPropertyHasChanged(propName: string, newValue: any): void; 562 563 /** 564 * Called when adding an already owned property. 565 * @since 7 566 * @systemapi 567 * @hide 568 */ 569 public addOwningProperty(subscriber: IPropertySubscriber): void; 570 571 /** 572 * Called when an already owned property is deleted. 573 * @since 7 574 * @systemapi 575 * @hide 576 */ 577 public removeOwningProperty(property: IPropertySubscriber): void; 578 579 /** 580 * Called when an already owned property is deleted by ID 581 * @since 7 582 * @systemapi 583 * @hide 584 */ 585 public removeOwningPropertyById(subscriberId: number): void; 586} 587 588/** 589 * Used for ide. 590 * @since 7 591 * @systemapi 592 * @hide 593 */ 594declare const appStorage: AppStorage; 595