@@ -3,17 +3,31 @@ import { ActivityBlock } from '../../abstract/ActivityBlock.js';
3
3
import { UploaderBlock } from '../../abstract/UploaderBlock.js' ;
4
4
import { CloudImageEditorBlock } from '../CloudImageEditor/index.js' ;
5
5
6
+ /** @typedef {{ internalId: string } } ActivityParams */
7
+
6
8
export class CloudImageEditorActivity extends UploaderBlock {
7
9
couldBeCtxOwner = true ;
8
10
activityType = ActivityBlock . activities . CLOUD_IMG_EDIT ;
9
11
10
- constructor ( ) {
11
- super ( ) ;
12
-
13
- this . init$ = {
14
- ...this . init$ ,
15
- cdnUrl : null ,
16
- } ;
12
+ /**
13
+ * @private
14
+ * @type {import('../../abstract/TypedData.js').TypedData | undefined }
15
+ */
16
+ _entry ;
17
+
18
+ /**
19
+ * @private
20
+ * @type {CloudImageEditorBlock | undefined }
21
+ */
22
+ _instance ;
23
+
24
+ /** @type {ActivityParams } */
25
+ get activityParams ( ) {
26
+ const params = super . activityParams ;
27
+ if ( 'internalId' in params ) {
28
+ return params ;
29
+ }
30
+ throw new Error ( `Cloud Image Editor activity params not found` ) ;
17
31
}
18
32
19
33
initCallback ( ) {
@@ -24,19 +38,6 @@ export class CloudImageEditorActivity extends UploaderBlock {
24
38
onDeactivate : ( ) => this . unmountEditor ( ) ,
25
39
} ) ;
26
40
27
- this . sub ( '*focusedEntry' , ( /** @type {import('../../abstract/TypedData.js').TypedData } */ entry ) => {
28
- if ( ! entry ) {
29
- return ;
30
- }
31
- this . entry = entry ;
32
-
33
- this . entry . subscribe ( 'cdnUrl' , ( cdnUrl ) => {
34
- if ( cdnUrl ) {
35
- this . $ . cdnUrl = cdnUrl ;
36
- }
37
- } ) ;
38
- } ) ;
39
-
40
41
this . subConfigValue ( 'cropPreset' , ( cropPreset ) => {
41
42
if ( this . _instance && this . _instance . getAttribute ( 'crop-preset' ) !== cropPreset ) {
42
43
this . _instance . setAttribute ( 'crop-preset' , cropPreset ) ;
@@ -52,11 +53,11 @@ export class CloudImageEditorActivity extends UploaderBlock {
52
53
53
54
/** @param {CustomEvent<import('../CloudImageEditor/src/types.js').ApplyResult> } e */
54
55
handleApply ( e ) {
55
- if ( ! this . entry ) {
56
+ if ( ! this . _entry ) {
56
57
return ;
57
58
}
58
59
let result = e . detail ;
59
- this . entry . setMultipleValues ( {
60
+ this . _entry . setMultipleValues ( {
60
61
cdnUrl : result . cdnUrl ,
61
62
cdnUrlModifiers : result . cdnUrlModifiers ,
62
63
} ) ;
@@ -68,8 +69,17 @@ export class CloudImageEditorActivity extends UploaderBlock {
68
69
}
69
70
70
71
mountEditor ( ) {
72
+ const { internalId } = this . activityParams ;
73
+ this . _entry = this . uploadCollection . read ( internalId ) ;
74
+ if ( ! this . _entry ) {
75
+ throw new Error ( `Entry with internalId "${ internalId } " not found` ) ;
76
+ }
77
+ const cdnUrl = this . _entry . getValue ( 'cdnUrl' ) ;
78
+ if ( ! cdnUrl ) {
79
+ throw new Error ( `Entry with internalId "${ internalId } " hasn't uploaded yet` ) ;
80
+ }
81
+
71
82
const instance = new CloudImageEditorBlock ( ) ;
72
- const cdnUrl = this . $ . cdnUrl ;
73
83
const cropPreset = this . cfg . cropPreset ;
74
84
const tabs = this . cfg . cloudImageEditorTabs ;
75
85
@@ -100,14 +110,13 @@ export class CloudImageEditorActivity extends UploaderBlock {
100
110
101
111
this . innerHTML = '' ;
102
112
this . appendChild ( instance ) ;
103
- this . _mounted = true ;
104
113
105
- /** @private */
106
114
this . _instance = instance ;
107
115
}
108
116
109
117
unmountEditor ( ) {
110
118
this . _instance = undefined ;
119
+ this . _entry = undefined ;
111
120
this . innerHTML = '' ;
112
121
}
113
122
}
0 commit comments