1
1
import React , { PureComponent } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
- import { MultiSelectBox , SelectBox } from '@neos-project/react-ui-components' ;
3
+ import { $get } from 'plow-js' ;
4
+ import { connect } from 'react-redux' ;
5
+ import MultiSelectBox from '@neos-project/react-ui-components/src/MultiSelectBox/' ;
6
+ import SelectBox from '@neos-project/react-ui-components/src/SelectBox/' ;
4
7
import { dndTypes } from '@neos-project/neos-ui-constants' ;
5
8
import { neos } from '@neos-project/neos-ui-decorators' ;
6
- import { $get } from 'plow-js' ;
9
+ import { selectors } from '@neos-project/neos-ui-redux-store' ;
10
+
7
11
import Controls from './Components/Controls/index' ;
8
12
import AssetOption from '../../Library/AssetOption' ;
9
13
import { AssetUpload } from '../../Library/index' ;
@@ -14,6 +18,10 @@ const DEFAULT_FEATURES = {
14
18
upload : true
15
19
} ;
16
20
21
+ @connect ( state => ( {
22
+ siteNodePath : state ?. cr ?. nodes ?. siteNode ,
23
+ focusedNodePath : selectors . CR . Nodes . focusedNodePathSelector ( state )
24
+ } ) , null , null , { forwardRef : true } )
17
25
@neos ( globalRegistry => ( {
18
26
assetLookupDataLoader : globalRegistry . get ( 'dataLoaders' ) . get ( 'AssetLookup' ) ,
19
27
i18nRegistry : globalRegistry . get ( 'i18n' ) ,
@@ -44,7 +52,9 @@ export default class AssetEditor extends PureComponent {
44
52
} ) . isRequired ,
45
53
secondaryEditorsRegistry : PropTypes . object . isRequired ,
46
54
renderSecondaryInspector : PropTypes . func . isRequired ,
47
- imagesOnly : PropTypes . bool
55
+ imagesOnly : PropTypes . bool ,
56
+ siteNodePath : PropTypes . string . isRequired ,
57
+ focusedNodePath : PropTypes . string . isRequired
48
58
} ;
49
59
50
60
static defaultProps = {
@@ -179,8 +189,30 @@ export default class AssetEditor extends PureComponent {
179
189
}
180
190
}
181
191
192
+ afterUpload = uploadResult => {
193
+ if ( uploadResult ?. object ) {
194
+ this . handleValueChange ( uploadResult ?. object ?. __identity ) ;
195
+ } else {
196
+ this . handleValuesChange ( uploadResult ) ;
197
+ }
198
+ }
199
+
182
200
handleChooseFile = ( ) => {
183
- this . assetUpload . chooseFromLocalFileSystem ( ) ;
201
+ const { secondaryEditorsRegistry, options} = this . props ;
202
+ if ( secondaryEditorsRegistry . get ( 'Neos.Neos/Inspector/Secondary/Editors/AssetUploadScreen' ) ) {
203
+ // set media type constraint to "image/*" if it is not explicitly specified via options.constraints.mediaTypes
204
+ const constraints = { ...options . constraints , mediaTypes : ( options . constraints && options . constraints . mediaTypes ) || [ 'image/*' ] } ;
205
+ const { component : AssetUploadScreen } = secondaryEditorsRegistry . get ( 'Neos.Neos/Inspector/Secondary/Editors/AssetUploadScreen' ) ;
206
+ const additionalData = {
207
+ propertyName : this . props . identifier ,
208
+ focusedNodePath : this . props . focusedNodePath ,
209
+ siteNodePath : this . props . siteNodePath ,
210
+ metaData : this . props . imagesOnly ? 'Image' : 'Asset'
211
+ } ;
212
+ this . props . renderSecondaryInspector ( 'ASSET_UPLOAD_MEDIA' , ( ) => < AssetUploadScreen type = { this . props . imagesOnly ? 'images' : 'all' } constraints = { constraints } onComplete = { this . afterUpload } additionalData = { additionalData } /> ) ;
213
+ } else {
214
+ this . assetUpload . chooseFromLocalFileSystem ( ) ;
215
+ }
184
216
}
185
217
186
218
renderControls ( ) {
0 commit comments