1
1
import React from "react" ;
2
2
import path from "path" ;
3
3
import { observable , computed , makeObservable } from "mobx" ;
4
- import { zipObject , map } from "lodash" ;
5
4
6
5
import { isValid , strToColor16 } from "eez-studio-shared/color" ;
7
6
@@ -30,7 +29,8 @@ import {
30
29
propertyNotSetMessage ,
31
30
createObject ,
32
31
isEezObjectArray ,
33
- getAncestorOfType
32
+ getAncestorOfType ,
33
+ getClassInfo
34
34
} from "project-editor/store" ;
35
35
import {
36
36
isDashboardProject ,
@@ -65,42 +65,8 @@ import {
65
65
import { checkExpression } from "project-editor/flow/expression" ;
66
66
import type { IFlowContext } from "project-editor/flow/flow-interfaces" ;
67
67
68
- export type BorderRadiusSpec = {
69
- topLeftX : number ;
70
- topLeftY : number ;
71
- topRightX : number ;
72
- topRightY : number ;
73
- bottomLeftX : number ;
74
- bottomLeftY : number ;
75
- bottomRightX : number ;
76
- bottomRightY : number ;
77
- } ;
78
-
79
- ////////////////////////////////////////////////////////////////////////////////
80
-
81
- export function isWidgetParentOfStyle ( object : IEezObject ) {
82
- while ( true ) {
83
- if ( object instanceof ProjectEditor . ComponentClass ) {
84
- return true ;
85
- }
86
- if ( ! getParent ( object ) ) {
87
- return false ;
88
- }
89
- object = getParent ( object ) ;
90
- }
91
- }
92
-
93
68
////////////////////////////////////////////////////////////////////////////////
94
69
95
- function openCssHelpPage ( cssAttributeName : string ) {
96
- const { shell } = require ( "electron" ) ;
97
- shell . openExternal (
98
- `https://developer.mozilla.org/en-US/docs/Web/CSS/${
99
- cssAttributeName != "css" ? cssAttributeName : ""
100
- } `
101
- ) ;
102
- }
103
-
104
70
const propertyMenu = ( props : PropertyProps ) : Electron . MenuItem [ ] => {
105
71
let menuItems : Electron . MenuItem [ ] = [ ] ;
106
72
@@ -155,6 +121,14 @@ const backgroundColorPropertyMenu = (
155
121
156
122
////////////////////////////////////////////////////////////////////////////////
157
123
124
+ const conditionalStyleConditionProperty = makeExpressionProperty (
125
+ {
126
+ name : "condition" ,
127
+ type : PropertyType . MultilineText
128
+ } ,
129
+ "boolean"
130
+ ) ;
131
+
158
132
export class ConditionalStyle extends EezObject {
159
133
style : string ;
160
134
condition : string ;
@@ -165,7 +139,8 @@ export class ConditionalStyle extends EezObject {
165
139
name : "style" ,
166
140
type : PropertyType . ObjectReference ,
167
141
referencedObjectCollectionPath : "allStyles"
168
- }
142
+ } ,
143
+ conditionalStyleConditionProperty
169
144
] ,
170
145
check : (
171
146
conditionalStyleItem : ConditionalStyle ,
@@ -888,10 +863,11 @@ const properties = [
888
863
alwaysBuildProperty
889
864
] ;
890
865
891
- const propertiesMap : { [ propertyName : string ] : PropertyInfo } = zipObject (
892
- map ( properties , p => p . name ) ,
893
- map ( properties , p => p )
894
- ) as any ;
866
+ const propertiesMap : { [ propertyName : string ] : PropertyInfo } = { } ;
867
+ for ( const property of properties ) {
868
+ propertiesMap [ property . name ] = property ;
869
+ }
870
+ console . log ( propertiesMap ) ;
895
871
896
872
////////////////////////////////////////////////////////////////////////////////
897
873
@@ -2218,8 +2194,7 @@ export class Style extends EezObject {
2218
2194
`${ getKey ( this ) } .${
2219
2195
conditionalStylesProperty . name
2220
2196
} [${ index } ].${
2221
- ProjectEditor . conditionalStyleConditionProperty
2222
- . name
2197
+ conditionalStyleConditionProperty . name
2223
2198
} `
2224
2199
) ?? false ;
2225
2200
@@ -2299,6 +2274,27 @@ registerClass("Style", Style);
2299
2274
2300
2275
////////////////////////////////////////////////////////////////////////////////
2301
2276
2277
+ function isWidgetParentOfStyle ( object : IEezObject ) {
2278
+ while ( true ) {
2279
+ if ( object instanceof ProjectEditor . ComponentClass ) {
2280
+ return true ;
2281
+ }
2282
+ if ( ! getParent ( object ) ) {
2283
+ return false ;
2284
+ }
2285
+ object = getParent ( object ) ;
2286
+ }
2287
+ }
2288
+
2289
+ function openCssHelpPage ( cssAttributeName : string ) {
2290
+ const { shell } = require ( "electron" ) ;
2291
+ shell . openExternal (
2292
+ `https://developer.mozilla.org/en-US/docs/Web/CSS/${
2293
+ cssAttributeName != "css" ? cssAttributeName : ""
2294
+ } `
2295
+ ) ;
2296
+ }
2297
+
2302
2298
function getInheritedValue (
2303
2299
styleObject : Style ,
2304
2300
propertyName : string ,
@@ -2383,6 +2379,45 @@ export function getStyleProperty(
2383
2379
return inheritedValue ?. value ;
2384
2380
}
2385
2381
2382
+ export function getAdditionalStyleFlowProperties ( widget : Widget ) {
2383
+ const additionalProperties : PropertyInfo [ ] = [ ] ;
2384
+
2385
+ const classInfo = getClassInfo ( widget ) ;
2386
+
2387
+ for ( const propertyInfo of classInfo . properties ) {
2388
+ if (
2389
+ propertyInfo . type == PropertyType . Object &&
2390
+ propertyInfo . typeClass == Style
2391
+ ) {
2392
+ const style = ( widget as any ) [ propertyInfo . name ] as Style ;
2393
+
2394
+ if ( style . conditionalStyles ) {
2395
+ for (
2396
+ let index = 0 ;
2397
+ index < style . conditionalStyles . length ;
2398
+ index ++
2399
+ ) {
2400
+ additionalProperties . push (
2401
+ Object . assign ( { } , conditionalStyleConditionProperty , {
2402
+ name : `${ propertyInfo . name } .${ conditionalStylesProperty . name } [${ index } ].${ conditionalStyleConditionProperty . name } `
2403
+ } )
2404
+ ) ;
2405
+ }
2406
+ }
2407
+
2408
+ if ( style . dynamicCSS ) {
2409
+ additionalProperties . push (
2410
+ Object . assign ( { } , dynamicCssProperty , {
2411
+ name : `${ propertyInfo . name } .${ dynamicCssProperty . name } `
2412
+ } )
2413
+ ) ;
2414
+ }
2415
+ }
2416
+ }
2417
+
2418
+ return additionalProperties ;
2419
+ }
2420
+
2386
2421
////////////////////////////////////////////////////////////////////////////////
2387
2422
2388
2423
const feature : ProjectEditorFeature = {
0 commit comments