Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport fixes from inspector #1041

Merged
merged 6 commits into from
Jan 26, 2025
Merged
8 changes: 8 additions & 0 deletions src/editor/components/components/PropertyRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ export default class PropertyRow extends React.Component {
return <BooleanWidget {...widgetProps} />;
}
default: {
if (
props.schema.type === 'string' &&
widgetProps.value &&
typeof widgetProps.value !== 'string'
) {
// Allow editing a custom type like event-set component schema
widgetProps.value = props.schema.stringify(widgetProps.value);
}
return <InputWidget {...widgetProps} schema={props.schema} />;
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/editor/lib/cameras.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ export function initCameras(inspector) {
const sceneEl = inspector.sceneEl;

const originalCamera = (inspector.currentCameraEl = sceneEl.camera.el);
inspector.currentCameraEl.setAttribute(
'data-aframe-inspector-original-camera',
''
);

// If the current camera is the default, we should prevent AFRAME from
// remove it once when we inject the editor's camera.
Expand Down
48 changes: 32 additions & 16 deletions src/editor/lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ function optimizeComponents(copy, source) {
var value = stringifyComponentValue(schema, optimalUpdate);
setAttribute.call(copy, name, value);
}

// Remove special components if they use the default value
if (
value === '' &&
(name === 'visible' ||
name === 'position' ||
name === 'rotation' ||
name === 'scale')
) {
removeAttribute.call(copy, name);
}
});
}

Expand Down Expand Up @@ -305,6 +316,13 @@ function getImplicitValue(component, source) {
function _multi() {
var value;

// Set isInherited to true if the component is inherited from primitive defaultComponents and is empty object
var defaults = source.defaultComponentsFromPrimitive;
isInherited =
defaults &&
/* eslint-disable-next-line no-prototype-builtins */
defaults.hasOwnProperty(component.attrName) &&
Object.keys(defaults[component.attrName]).length === 0;
Object.keys(component.schema).forEach(function (propertyName) {
var propertyValue = getFromAttribute(component, propertyName, source);
if (propertyValue === undefined) {
Expand Down Expand Up @@ -383,15 +401,15 @@ function getFromAttribute(component, propertyName, source) {
*/
function getMixedValue(component, propertyName, source) {
var value;
var reversedMixins = source.mixinEls.reverse();
var reversedMixins = source.mixinEls.toReversed();
for (var i = 0; value === undefined && i < reversedMixins.length; i++) {
var mixin = reversedMixins[i];
/* eslint-disable-next-line no-prototype-builtins */
if (mixin.attributes.hasOwnProperty(component.name)) {
if (mixin.attributes.hasOwnProperty(component.attrName)) {
if (!propertyName) {
value = mixin.getAttribute(component.name);
value = mixin.getAttribute(component.attrName);
} else {
value = mixin.getAttribute(component.name)[propertyName];
value = mixin.getAttribute(component.attrName)[propertyName];
}
}
}
Expand All @@ -400,7 +418,7 @@ function getMixedValue(component, propertyName, source) {

/**
* Gets the value for a component or component's property coming from primitive
* defaults or a-frame defaults. In this specific order.
* defaults.
*
* @param {Component} component Component to be found.
* @param {string} [propertyName] If provided, component's property to be
Expand All @@ -411,18 +429,16 @@ function getMixedValue(component, propertyName, source) {
*/
function getInjectedValue(component, propertyName, source) {
var value;
var primitiveDefaults = source.defaultComponentsFromPrimitive || {};
var aFrameDefaults = source.defaultComponents || {};
var defaultSources = [primitiveDefaults, aFrameDefaults];
for (var i = 0; value === undefined && i < defaultSources.length; i++) {
var defaults = defaultSources[i];
var primitiveDefaults = source.defaultComponentsFromPrimitive;
if (
primitiveDefaults &&
/* eslint-disable-next-line no-prototype-builtins */
if (defaults.hasOwnProperty(component.name)) {
if (!propertyName) {
value = defaults[component.name];
} else {
value = defaults[component.name][propertyName];
}
primitiveDefaults.hasOwnProperty(component.attrName)
) {
if (!propertyName) {
value = primitiveDefaults[component.attrName];
} else {
value = primitiveDefaults[component.attrName][propertyName];
}
}
return value;
Expand Down
4 changes: 4 additions & 0 deletions src/editor/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export function equal(var1, var2) {
if (type1 !== 'object' || var1 === null || var2 === null) {
return var1 === var2;
}
if (var1 instanceof HTMLElement || var2 instanceof HTMLElement) {
// If we're here, we're comparing a value of a schema property of type selector like movement-controls's camera property
return var1 === var2;
}
keys1 = Object.keys(var1);
keys2 = Object.keys(var2);
if (keys1.length !== keys2.length) {
Expand Down
Loading