Skip to content

Commit 26c5cf2

Browse files
Add a reset property button, visualize with bold italic property explicitly set to default value, add the meaning in the tooltip with also min and max values for number and int (#846)
1 parent 8a6db7f commit 26c5cf2

5 files changed

Lines changed: 104 additions & 16 deletions

File tree

src/components/components/PropertyRow.js

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import React from 'react';
33
import PropTypes from 'prop-types';
44
import clsx from 'clsx';
5+
import { faRotateLeft } from '@fortawesome/free-solid-svg-icons';
56

7+
import { AwesomeIcon } from '../AwesomeIcon';
68
import BooleanWidget from '../widgets/BooleanWidget';
79
import ColorWidget from '../widgets/ColorWidget';
810
import InputWidget from '../widgets/InputWidget';
@@ -36,7 +38,7 @@ export default class PropertyRow extends React.Component {
3638
this.id = props.componentname + ':' + props.name;
3739
}
3840

39-
getWidget() {
41+
getType() {
4042
const props = this.props;
4143
let type = props.schema.type;
4244

@@ -57,6 +59,13 @@ export default class PropertyRow extends React.Component {
5759
type = 'boolean';
5860
}
5961

62+
return type;
63+
}
64+
65+
getWidget() {
66+
const props = this.props;
67+
const type = this.getType();
68+
6069
let value =
6170
type === 'selector'
6271
? props.entity.getDOMAttribute(props.componentname)?.[props.name]
@@ -152,18 +161,49 @@ export default class PropertyRow extends React.Component {
152161
}
153162
}
154163

164+
isPropertyExplicitlySet() {
165+
const props = this.props;
166+
if (props.isSingle) {
167+
return props.entity.getDOMAttribute(props.componentname) !== null;
168+
} else {
169+
return (
170+
(props.entity.getDOMAttribute(props.componentname) || {})[
171+
props.name
172+
] !== undefined
173+
);
174+
}
175+
}
176+
155177
render() {
156178
const props = this.props;
157-
const value =
158-
props.schema.type === 'selector'
159-
? props.entity.getDOMAttribute(props.componentname)?.[props.name]
160-
: JSON.stringify(props.data);
161-
const title =
162-
props.name + '\n - type: ' + props.schema.type + '\n - value: ' + value;
179+
const type = this.getType();
180+
const isPropertyDefined = this.isPropertyDefined();
181+
const isPropertyExplicitlySet = this.isPropertyExplicitlySet();
163182

183+
let title = props.name + '\n - type: ' + type;
184+
if (type === 'number' || type === 'int') {
185+
const schema = props.schema;
186+
if (schema.hasOwnProperty('min') && schema.min !== -Infinity) {
187+
title += '\n - min: ' + schema.min;
188+
}
189+
if (schema.hasOwnProperty('max') && schema.max !== Infinity) {
190+
title += '\n - max: ' + schema.max;
191+
}
192+
}
193+
if (!isPropertyDefined) {
194+
if (isPropertyExplicitlySet) {
195+
title += '\n\nexplicitly set to default value';
196+
} else {
197+
title += '\n\ndefault value';
198+
}
199+
} else {
200+
title += '\n\nmodified value';
201+
}
164202
const className = clsx({
165203
propertyRow: true,
166-
propertyRowDefined: this.isPropertyDefined()
204+
propertyRowDefined: isPropertyDefined,
205+
propertyRowExplicitlySetToDefault:
206+
!isPropertyDefined && isPropertyExplicitlySet
167207
});
168208

169209
return (
@@ -172,6 +212,22 @@ export default class PropertyRow extends React.Component {
172212
{props.name}
173213
</label>
174214
{this.getWidget()}
215+
{isPropertyExplicitlySet && type !== 'map' && (
216+
<button
217+
className="reset-button"
218+
title="Reset"
219+
onClick={() => {
220+
updateEntity(
221+
props.entity,
222+
props.componentname,
223+
!props.isSingle ? props.name : '',
224+
null
225+
);
226+
}}
227+
>
228+
<AwesomeIcon icon={faRotateLeft} />
229+
</button>
230+
)}
175231
</div>
176232
);
177233
}

src/lib/entity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ function stringifyComponentValue(schema, data) {
250250
function _multi() {
251251
var propertyBag = {};
252252
Object.keys(data).forEach(function (name) {
253-
if (schema[name]) {
253+
if (schema[name] && data[name] !== undefined) {
254254
propertyBag[name] = schema[name].stringify(data[name]);
255255
}
256256
});

src/lib/history.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,21 @@ Events.on('entityupdate', (payload) => {
1818
if (payload.property) {
1919
updates[entity.id][payload.component] =
2020
updates[entity.id][payload.component] || {};
21-
if (component.schema[payload.property]) {
21+
if (value === null) {
22+
delete updates[entity.id][payload.component][payload.property];
23+
} else if (component.schema[payload.property]) {
2224
value = component.schema[payload.property].stringify(payload.value);
25+
updates[entity.id][payload.component][payload.property] = value;
26+
} else {
27+
updates[entity.id][payload.component][payload.property] = value;
2328
}
24-
updates[entity.id][payload.component][payload.property] = value;
2529
} else {
26-
value = component.schema.stringify(payload.value);
27-
updates[entity.id][payload.component] = value;
30+
if (value === null) {
31+
delete updates[entity.id][payload.component];
32+
} else {
33+
value = component.schema.stringify(payload.value);
34+
updates[entity.id][payload.component] = value;
35+
}
2836
}
2937
}
3038
});

src/style/components.styl

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,16 @@
6969
display flex
7070
font-size 13px
7171
min-height 30px
72-
padding 2px 15px
72+
padding 2px 30px 2px 15px
73+
position relative
74+
75+
&:has(.vec3)
76+
padding-right 15px
7377

7478
.text
7579
cursor default
7680
display inline-block
81+
flex-shrink 0
7782
overflow hidden
7883
padding-right 10px
7984
text-overflow ellipsis
@@ -112,7 +117,7 @@
112117
input.string
113118
box-sizing border-box
114119
padding-left 8px
115-
width 165px
120+
width 150px
116121

117122
input[type="text"]:focus,
118123
input.string:focus
@@ -130,6 +135,25 @@
130135
color var(--color-property-defined)
131136
font-weight 600
132137

138+
.propertyRowExplicitlySetToDefault .text
139+
font-style italic
140+
font-weight 600
141+
142+
.propertyRow .reset-button
143+
background none
144+
border none
145+
color var(--color-base-content)
146+
cursor pointer
147+
opacity 0.6
148+
padding 2px
149+
position absolute
150+
right 8px
151+
top 50%
152+
transform translateY(-50%)
153+
154+
&:hover
155+
opacity 1
156+
133157
#addComponentContainer
134158
align-items center
135159
background var(--color-base-200)

src/style/widgets.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
.select-widget
44
display inline-block
5-
width 157px
5+
width 142px

0 commit comments

Comments
 (0)