1
1
import { Utils as CommonUtils } from '@openeo/js-commons' ;
2
+ import { types } from 'util' ;
2
3
3
4
class Utils extends CommonUtils {
4
5
@@ -11,9 +12,15 @@ class Utils extends CommonUtils {
11
12
default : undefined
12
13
}
13
14
}
14
- if ( vue . props [ key ] . type === Function ) {
15
+ let types = Array . isArray ( vue . props [ key ] . type ) ? vue . props [ key ] . type : [ vue . props [ key ] . type ] ;
16
+ types = types . filter ( t => typeof t === 'function' ) . map ( t => t . name ) ;
17
+ if ( types . includes ( 'Function' ) ) {
15
18
continue ;
16
19
}
20
+ else if ( types . includes ( 'Boolean' ) ) {
21
+ // Functions for default are not executed for Boolean, so remove the type
22
+ delete vue . props [ key ] . type ;
23
+ }
17
24
let defaultValue = vue . props [ key ] . default ;
18
25
if ( typeof defaultValue === 'function' ) {
19
26
defaultValue = defaultValue ( ) ;
@@ -28,6 +35,7 @@ class Utils extends CommonUtils {
28
35
29
36
static readHtmlProp ( prop , component , defaultValue = undefined ) {
30
37
if ( Utils . isObject ( component ) && Utils . isObject ( component . $slots ) && Array . isArray ( component . $slots . default ) ) {
38
+ // Read script tag for specific prop
31
39
let el = component . $slots . default . find ( slot => typeof slot . tag === 'string' && slot . tag . toUpperCase ( ) === 'SCRIPT' && slot . data . attrs . prop === prop && slot . data . attrs . type === 'application/json' ) ;
32
40
if ( el ) {
33
41
try {
@@ -37,6 +45,19 @@ class Utils extends CommonUtils {
37
45
console . error ( `Data passed to prop '${ prop } ' via script tag is invalid: ${ error . message } ` ) ;
38
46
}
39
47
}
48
+ // Read script tag containing all props as JSON
49
+ let elAll = component . $slots . default . find ( slot => typeof slot . tag === 'string' && slot . tag . toUpperCase ( ) === 'SCRIPT' && slot . data . attrs . type === 'application/json' ) ;
50
+ if ( elAll ) {
51
+ try {
52
+ let data = JSON . parse ( elAll . data . domProps . innerHTML ) ;
53
+ if ( Utils . isObject ( data ) && typeof data [ prop ] !== 'undefined' ) {
54
+ return data [ prop ] ;
55
+ }
56
+ }
57
+ catch ( error ) {
58
+ console . error ( `Data passed via script tag is invalid: ${ error . message } ` ) ;
59
+ }
60
+ }
40
61
}
41
62
return defaultValue ;
42
63
}
0 commit comments