1/* 2 * Copyright (c) 2024 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 16var __decorate = this && this.__decorate || function (e, o, t, i) { 17 var n, r = arguments.length, l = r < 3 ? o : null === i ? i = Object.getOwnPropertyDescriptor(o, t) : i; 18 if ('object' === typeof Reflect && 'function' === typeof Reflect.decorate) { 19 l = Reflect.decorate(e, o, t, i); 20 } else { 21 for (var s = e.length - 1; s >= 0; s--) { 22 (n = e[s]) && (l = (r < 3 ? n(l) : r > 3 ? n(o, t, l) : n(o, t)) || l); 23 } 24 } 25 return r > 3 && l && Object.defineProperty(o, t, l), l; 26}; 27const photoAccessHelper = requireNapi('file.photoAccessHelper'); 28const FILTER_MEDIA_TYPE_ALL = 'FILTER_MEDIA_TYPE_ALL'; 29const FILTER_MEDIA_TYPE_IMAGE = 'FILTER_MEDIA_TYPE_IMAGE'; 30const FILTER_MEDIA_TYPE_VIDEO = 'FILTER_MEDIA_TYPE_VIDEO'; 31 32export class PhotoPickerComponent extends ViewPU { 33 constructor(e, o, t, i = -1, n = void 0) { 34 super(e, t, i); 35 'function' === typeof n && (this.paramsGenerator_ = n); 36 this.pickerOptions = void 0; 37 this.onSelect = void 0; 38 this.onDeselect = void 0; 39 this.onItemClicked = void 0; 40 this.onEnterPhotoBrowser = void 0; 41 this.onExitPhotoBrowser = void 0; 42 this.onPickerControllerReady = void 0; 43 this.onPhotoBrowserChanged = void 0; 44 this.onSelectedItemsDeleted = void 0; 45 this.onExceedMaxSelected = void 0; 46 this.onCurrentAlbumDeleted = void 0; 47 this.__pickerController = new SynchedPropertyNesedObjectPU(o.pickerController, this, 'pickerController'); 48 this.proxy = void 0; 49 this.setInitiallyProvidedValue(o); 50 this.declareWatch('pickerController', this.onChanged); 51 } 52 53 setInitiallyProvidedValue(e) { 54 void 0 !== e.pickerOptions && (this.pickerOptions = e.pickerOptions); 55 void 0 !== e.onSelect && (this.onSelect = e.onSelect); 56 void 0 !== e.onDeselect && (this.onDeselect = e.onDeselect); 57 void 0 !== e.onItemClicked && (this.onItemClicked = e.onItemClicked); 58 void 0 !== e.onEnterPhotoBrowser && (this.onEnterPhotoBrowser = e.onEnterPhotoBrowser); 59 void 0 !== e.onExitPhotoBrowser && (this.onExitPhotoBrowser = e.onExitPhotoBrowser); 60 void 0 !== e.onPhotoBrowserChanged && (this.onPhotoBrowserChanged = e.onPhotoBrowserChanged); 61 void 0 !== e.onPickerControllerReady && (this.onPickerControllerReady = e.onPickerControllerReady); 62 void 0 !== e.onSelectedItemsDeleted && (this.onSelectedItemsDeleted = e.onSelectedItemsDeleted); 63 void 0 !== e.onExceedMaxSelected && (this.onExceedMaxSelected = e.onExceedMaxSelected); 64 void 0 !== e.onCurrentAlbumDeleted && (this.onCurrentAlbumDeleted = e.onCurrentAlbumDeleted); 65 this.__pickerController.set(e.pickerController); 66 void 0 !== e.proxy && (this.proxy = e.proxy); 67 } 68 69 updateStateVars(e) { 70 this.__pickerController.set(e.pickerController); 71 } 72 73 purgeVariableDependenciesOnElmtId(e) { 74 this.__pickerController.purgeDependencyOnElmtId(e); 75 } 76 77 aboutToBeDeleted() { 78 this.__pickerController.aboutToBeDeleted(); 79 SubscriberManager.Get().delete(this.id__()); 80 this.aboutToBeDeletedInternal(); 81 } 82 83 get pickerController() { 84 return this.__pickerController.get(); 85 } 86 87 onChanged() { 88 var e; 89 if (!this.proxy) { 90 return; 91 } 92 let o = null === (e = this.pickerController) || void 0 === e ? void 0 : e.data; 93 if (null == o ? void 0 : o.has('SET_SELECTED_URIS')) { 94 this.proxy.send({ selectUris: null == o ? void 0 : o.get('SET_SELECTED_URIS') }); 95 console.info('PhotoPickerComponent onChanged: SET_SELECTED_URIS'); 96 } else if (null == o ? void 0 : o.has('SET_ALBUM_URI')) { 97 this.proxy.send({ albumUri: null == o ? void 0 : o.get('SET_ALBUM_URI') }); 98 console.info('PhotoPickerComponent onChanged: SET_ALBUM_URI'); 99 } else if (null == o ? void 0 : o.has('SET_MAX_SELECT_COUNT')) { 100 this.onSetMaxSelectCount(o); 101 } else if (null == o ? void 0 : o.has('SET_PHOTO_BROWSER_ITEM')) { 102 this.onSetPhotoBrowserItem(o); 103 } else if (null == o ? void 0 : o.has('EXIT_PHOTO_BROWSER')) { 104 this.handleExitPhotoBrowser(); 105 } else if (null == o ? void 0 : o.has('SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY')) { 106 this.onSetPhotoBrowserUIElementVisibility(o); 107 } else { 108 console.info('PhotoPickerComponent onChanged: other case'); 109 } 110 } 111 112 onSetMaxSelectCount(o) { 113 let e = null == o ? void 0 : o.get('SET_MAX_SELECT_COUNT'); 114 let t = null == e ? void 0 : e.data; 115 this.proxy.send({ 116 totalCount: null == t ? void 0 : t.get(MaxCountType.TOTAL_MAX_COUNT), 117 photoCount: null == t ? void 0 : t.get(MaxCountType.PHOTO_MAX_COUNT), 118 videoCount: null == t ? void 0 : t.get(MaxCountType.VIDEO_MAX_COUNT) 119 }); 120 console.info('PhotoPickerComponent onChanged: SET_MAX_SELECT_COUNT'); 121 } 122 123 onSetPhotoBrowserItem(o) { 124 let e = null == o ? void 0 : o.get('SET_PHOTO_BROWSER_ITEM'); 125 this.proxy.send({ 126 itemUri: null == e ? void 0 : e.uri, 127 photoBrowserRange: null == e ? void 0 : e.photoBrowserRange 128 }); 129 console.info('PhotoPickerComponent onChanged: SET_PHOTO_BROWSER_ITEM'); 130 } 131 132 handleExitPhotoBrowser() { 133 this.proxy.send({ exitPhotoBrowser: true }); 134 console.info('PhotoPickerComponent onChanged: EXIT_PHOTO_BROWSER'); 135 } 136 137 onSetPhotoBrowserUIElementVisibility(o) { 138 let e = null == o ? void 0 : o.get('SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY'); 139 this.proxy.send({ 140 elements: null == e ? void 0 : e.elements, 141 isVisible: null == e ? void 0 : e.isVisible 142 }); 143 console.info('PhotoPickerComponent onChanged: SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY'); 144 } 145 146 initialRender() { 147 this.observeComponentCreation2(((e, o) => { 148 Row.create(); 149 Row.height('100%'); 150 }), Row); 151 this.observeComponentCreation2(((e, o) => { 152 Column.create(); 153 Column.width('100%'); 154 }), Column); 155 this.observeComponentCreation2(((e, o) => { 156 var t, i, n, r, l, s, c, p, a, d, h, E, C, T, m, P, _, b, d; 157 SecurityUIExtensionComponent.create({ 158 parameters: { 159 'ability.want.params.uiExtensionTargetType': 'photoPicker', 160 uri: 'multipleselect', 161 targetPage: 'photoPage', 162 filterMediaType: this.convertMIMETypeToFilterType(null === (t = this.pickerOptions) || void 0 === t ? void 0 : t.MIMEType), 163 maxSelectNumber: null === (i = this.pickerOptions) || void 0 === i ? void 0 : i.maxSelectNumber, 164 isPhotoTakingSupported: null === (n = this.pickerOptions) || void 0 === n ? void 0 : n.isPhotoTakingSupported, 165 isEditSupported: !1, 166 recommendationOptions: null === (r = this.pickerOptions) || void 0 === r ? void 0 : r.recommendationOptions, 167 preselectedUri: null === (l = this.pickerOptions) || void 0 === l ? void 0 : l.preselectedUris, 168 isFromPickerView: !0, 169 isNeedActionBar: !1, 170 isNeedSelectBar: !1, 171 isSearchSupported: null === (s = this.pickerOptions) || void 0 === s ? void 0 : s.isSearchSupported, 172 checkBoxColor: null === (c = this.pickerOptions) || void 0 === c ? void 0 : c.checkBoxColor, 173 backgroundColor: null === (p = this.pickerOptions) || void 0 === p ? void 0 : p.backgroundColor, 174 checkboxTextColor: null === (a = this.pickerOptions) || void 0 === a ? void 0 : a.checkboxTextColor, 175 photoBrowserBackgroundColorMode: null === (d = this.pickerOptions) || void 0 === d ? void 0 : d.photoBrowserBackgroundColorMode, 176 isRepeatSelectSupported: null === (h = this.pickerOptions) || void 0 === h ? void 0 : h.isRepeatSelectSupported, 177 maxSelectedReminderMode: null === (E = this.pickerOptions) || void 0 === E ? void 0 : E.maxSelectedReminderMode, 178 orientation: null === (C = this.pickerOptions) || void 0 === C ? void 0 : C.orientation, 179 selectMode: null === (T = this.pickerOptions) || void 0 === T ? void 0 : T.selectMode, 180 maxPhotoSelectNumber: null === (m = this.pickerOptions) || void 0 === m ? void 0 : m.maxPhotoSelectNumber, 181 maxVideoSelectNumber: null === (P = this.pickerOptions) || void 0 === P ? void 0 : P.maxVideoSelectNumber, 182 isOnItemClickedSet: !!this.onItemClicked, 183 isPreviewForSingleSelectionSupported: null === (_ = this.pickerOptions) || void 0 === _ ? void 0 : _.isPreviewForSingleSelectionSupported, 184 isSlidingSelectionSupported: null === (b = this.pickerOptions) || void 0 === b ? void 0 : b.isSlidingSelectionSupported, 185 photoBrowserCheckboxPosition: null === (d = this.pickerOptions) || void 0 === d ? void 0 : d.photoBrowserCheckboxPosition 186 } 187 }); 188 SecurityUIExtensionComponent.height('100%'); 189 SecurityUIExtensionComponent.width('100%'); 190 SecurityUIExtensionComponent.onRemoteReady((e => { 191 this.proxy = e; 192 console.info('PhotoPickerComponent onRemoteReady'); 193 })); 194 SecurityUIExtensionComponent.onReceive((e => { 195 let o = e; 196 this.handleOnReceive(o); 197 })); 198 SecurityUIExtensionComponent.onError((() => { 199 console.info('PhotoPickerComponent onError'); 200 })); 201 }), SecurityUIExtensionComponent); 202 Column.pop(); 203 Row.pop(); 204 } 205 206 handleOnReceive(e) { 207 let o = e.dataType; 208 console.info('PhotoPickerComponent onReceive: dataType = ' + o); 209 if ('selectOrDeselect' === o) { 210 this.handleSelectOrDeselect(e); 211 } else if ('itemClick' === o) { 212 this.handleItemClick(e); 213 } else if ('onPhotoBrowserStateChanged' === o) { 214 this.handleEnterOrExitPhotoBrowser(e); 215 } else if ('remoteReady' === o) { 216 if (this.onPickerControllerReady) { 217 this.onPickerControllerReady(); 218 console.info('PhotoPickerComponent onReceive: onPickerControllerReady'); 219 } 220 } else if ('onPhotoBrowserChanged' === o) { 221 this.handlePhotoBrowserChange(e); 222 } else { 223 this.handleOtherOnReceive(e); 224 console.info('PhotoPickerComponent onReceive: other case'); 225 } 226 console.info('PhotoPickerComponent onReceive' + JSON.stringify(e)); 227 } 228 229 handleOtherOnReceive(e) { 230 let o = e.dataType; 231 if ('exceedMaxSelected' === o) { 232 if (this.onExceedMaxSelected) { 233 this.onExceedMaxSelected(e.maxCountType); 234 } 235 } else if ('selectedItemsDeleted' === o) { 236 if (this.onSelectedItemsDeleted) { 237 this.onSelectedItemsDeleted(e.selectedItemInfos); 238 } 239 } else if ('currentAlbumDeleted' === o) { 240 if (this.onCurrentAlbumDeleted) { 241 this.onCurrentAlbumDeleted(); 242 } 243 } else { 244 console.info('PhotoPickerComponent onReceive: other case'); 245 } 246 } 247 248 handleSelectOrDeselect(e) { 249 if (e.isSelect) { 250 if (this.onSelect) { 251 this.onSelect(e['select-item-list']); 252 console.info('PhotoPickerComponent onReceive: onSelect'); 253 } 254 } else if (this.onDeselect) { 255 this.onDeselect(e['select-item-list']); 256 console.info('PhotoPickerComponent onReceive: onDeselect'); 257 } 258 } 259 260 handleItemClick(e) { 261 if (this.onItemClicked) { 262 let o = ClickType.SELECTED; 263 let t = e.clickType; 264 'select' === t ? o = ClickType.SELECTED : 'deselect' === t ? o = ClickType.DESELECTED : console.info('PhotoPickerComponent onReceive: other clickType'); 265 let i = new ItemInfo; 266 let n = e.itemType; 267 'thumbnail' === n ? i.itemType = ItemType.THUMBNAIL : 'camera' === n ? i.itemType = ItemType.CAMERA : console.info('PhotoPickerComponent onReceive: other itemType'); 268 i.uri = e.uri; 269 i.mimeType = e.mimeType; 270 i.width = e.width; 271 i.height = e.height; 272 i.size = e.size; 273 i.duration = e.duration; 274 let r = this.onItemClicked(i, o); 275 console.info('PhotoPickerComponent onReceive: onItemClicked = ' + o); 276 if (this.proxy) { 277 if ('thumbnail' === n && o === ClickType.SELECTED) { 278 this.proxy.send({ clickConfirm: i.uri, isConfirm: r }); 279 console.info('PhotoPickerComponent onReceive: click confirm: uri = ' + i.uri + 'isConfirm = ' + r); 280 } 281 if ('camera' === n) { 282 this.proxy.send({ enterCamera: r }); 283 console.info('PhotoPickerComponent onReceive: enter camera ' + r); 284 } 285 } 286 } 287 } 288 289 handleEnterOrExitPhotoBrowser(e) { 290 let o = e.isEnter; 291 let t = new PhotoBrowserInfo; 292 t.animatorParams = new AnimatorParams; 293 t.animatorParams.duration = e.duration; 294 t.animatorParams.curve = e.curve; 295 o ? this.onEnterPhotoBrowser && this.onEnterPhotoBrowser(t) : this.onExitPhotoBrowser && this.onExitPhotoBrowser(t); 296 console.info('PhotoPickerComponent onReceive: onPhotoBrowserStateChanged = ' + o); 297 } 298 299 handlePhotoBrowserChange(e) { 300 let o = new BaseItemInfo(); 301 o.uri = e.uri; 302 if (this.onPhotoBrowserChanged) { 303 this.onPhotoBrowserChanged(o); 304 } 305 console.info('PhotoPickerComponent onReceive: onPhotoBrowserChanged = ' + o.uri); 306 } 307 308 convertMIMETypeToFilterType(e) { 309 let o; 310 o = e === photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE ? 311 FILTER_MEDIA_TYPE_IMAGE : e === photoAccessHelper.PhotoViewMIMETypes.VIDEO_TYPE ? 312 FILTER_MEDIA_TYPE_VIDEO : FILTER_MEDIA_TYPE_ALL; 313 console.info('PhotoPickerComponent convertMIMETypeToFilterType' + JSON.stringify(o)); 314 return o; 315 } 316 317 rerender() { 318 this.updateDirtyElements(); 319 } 320} 321let PickerController = class { 322 setData(e, o) { 323 if (!o) { 324 return; 325 } 326 if (e === DataType.SET_SELECTED_URIS) { 327 if (o instanceof Array) { 328 let e = o; 329 if (e) { 330 this.data = new Map([['SET_SELECTED_URIS', [...e]]]); 331 console.info('PhotoPickerComponent SET_SELECTED_URIS' + JSON.stringify(e)); 332 } 333 } 334 } else if (e === DataType.SET_ALBUM_URI) { 335 let e = o; 336 if (e !== undefined) { 337 this.data = new Map([['SET_ALBUM_URI', e]]); 338 console.info('PhotoPickerComponent SET_ALBUM_URI' + JSON.stringify(e)); 339 } 340 } else { 341 console.info('PhotoPickerComponent setData: other case'); 342 } 343 } 344 345 setMaxSelected(e) { 346 if (e) { 347 this.data = new Map([['SET_MAX_SELECT_COUNT', e]]); 348 console.info('PhotoPickerComponent SET_MAX_SELECT_COUNT' + JSON.stringify(e)); 349 } 350 } 351 352 setPhotoBrowserItem(e, o) { 353 let l = new PhotoBrowserRangeInfo; 354 l.uri = e; 355 let m = o ? o : PhotoBrowserRange.ALL; 356 l.photoBrowserRange = m; 357 this.data = new Map([['SET_PHOTO_BROWSER_ITEM', l]]); 358 console.info('PhotoPickerComponent SET_PHOTO_BROWSER_ITEM ' + JSON.stringify(l)); 359 } 360 361 exitPhotoBrowser() { 362 this.data = new Map([['EXIT_PHOTO_BROWSER', true]]); 363 console.info('PhotoPickerComponent EXIT_PHOTO_BROWSER '); 364 } 365 366 setPhotoBrowserUIElementVisibility(e, o) { 367 let m = new PhotoBrowserUIElementVisibility; 368 m.elements = e; 369 m.isVisible = o; 370 this.data = new Map([['SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY', m]]); 371 console.info('PhotoPickerComponent SET_PHOTO_BROWSER_UI_ELEMENT_VISIBILITY ' + JSON.stringify(m)); 372 } 373}; 374PickerController = __decorate([Observed], PickerController); 375 376export class PickerOptions extends photoAccessHelper.BaseSelectOptions { 377} 378 379export class BaseItemInfo { 380} 381 382export class ItemInfo extends BaseItemInfo { 383} 384 385export class PhotoBrowserInfo { 386} 387 388export class AnimatorParams { 389} 390 391export class MaxSelected { 392} 393 394class PhotoBrowserRangeInfo { 395} 396 397class PhotoBrowserUIElementVisibility { 398} 399 400export var DataType; 401!function(e) { 402 e[e.SET_SELECTED_URIS = 1] = 'SET_SELECTED_URIS'; 403 e[e.SET_ALBUM_URI = 2] = 'SET_ALBUM_URI'; 404}(DataType || (DataType = {})); 405 406export var ItemType; 407!function(e) { 408 e[e.THUMBNAIL = 0] = 'THUMBNAIL'; 409 e[e.CAMERA = 1] = 'CAMERA'; 410}(ItemType || (ItemType = {})); 411 412export var ClickType; 413!function(e) { 414 e[e.SELECTED = 0] = 'SELECTED'; 415 e[e.DESELECTED = 1] = 'DESELECTED'; 416}(ClickType || (ClickType = {})); 417 418export var PickerOrientation; 419!function(e) { 420 e[e.VERTICAL = 0] = 'VERTICAL'; 421 e[e.HORIZONTAL = 1] = 'HORIZONTAL'; 422}(PickerOrientation || (PickerOrientation = {})); 423 424export var SelectMode; 425!function(e) { 426 e[e.SINGLE_SELECT = 0] = 'SINGLE_SELECT'; 427 e[e.MULTI_SELECT = 1] = 'MULTI_SELECT'; 428}(SelectMode || (SelectMode = {})); 429 430export var PickerColorMode; 431!function(e) { 432 e[e.AUTO = 0] = 'AUTO'; 433 e[e.LIGHT = 1] = 'LIGHT'; 434 e[e.DARK = 2] = 'DARK'; 435}(PickerColorMode || (PickerColorMode = {})); 436 437export var ReminderMode; 438!function(e) { 439 e[e.NONE = 0] = 'NONE'; 440 e[e.TOAST = 1] = 'TOAST'; 441 e[e.MASK = 2] = 'MASK'; 442}(ReminderMode || (ReminderMode = {})); 443 444export var MaxCountType; 445!function(e) { 446 e[e.TOTAL_MAX_COUNT = 0] = 'TOTAL_MAX_COUNT'; 447 e[e.PHOTO_MAX_COUNT = 1] = 'PHOTO_MAX_COUNT'; 448 e[e.VIDEO_MAX_COUNT = 2] = 'VIDEO_MAX_COUNT'; 449}(MaxCountType || (MaxCountType = {})); 450 451export var PhotoBrowserRange; 452!function(e) { 453 e[e.ALL = 0] = 'ALL'; 454 e[e.SELECTED_ONLY = 1] = 'SELECTED_ONLY'; 455}(PhotoBrowserRange || (PhotoBrowserRange = {})); 456 457export var PhotoBrowserUIElement; 458!function(e) { 459 e[e.CHECKBOX = 0] = 'CHECKBOX'; 460 e[e.BACK_BUTTON = 1] = 'BACK_BUTTON'; 461}(PhotoBrowserUIElement || (PhotoBrowserUIElement = {})); 462 463export default { PhotoPickerComponent, PickerController, PickerOptions, DataType, BaseItemInfo, ItemInfo, PhotoBrowserInfo, AnimatorParams, 464 MaxSelected, ItemType, ClickType, PickerOrientation, SelectMode, PickerColorMode, ReminderMode, MaxCountType, PhotoBrowserRange, PhotoBrowserUIElement };