diff --git a/src/editor/components/components/PropertyRow.js b/src/editor/components/components/PropertyRow.js index 4c000ccd3..fda4b898a 100644 --- a/src/editor/components/components/PropertyRow.js +++ b/src/editor/components/components/PropertyRow.js @@ -109,6 +109,14 @@ export default class PropertyRow extends React.Component { return ; } 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 ; } } diff --git a/src/editor/lib/cameras.js b/src/editor/lib/cameras.js index 329a20f22..ee760a7a0 100644 --- a/src/editor/lib/cameras.js +++ b/src/editor/lib/cameras.js @@ -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. diff --git a/src/editor/lib/entity.js b/src/editor/lib/entity.js index 75b2dc690..6452d064d 100644 --- a/src/editor/lib/entity.js +++ b/src/editor/lib/entity.js @@ -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); + } }); } @@ -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) { @@ -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]; } } } @@ -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 @@ -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; diff --git a/src/editor/lib/utils.js b/src/editor/lib/utils.js index 074c13a47..3ff409f68 100644 --- a/src/editor/lib/utils.js +++ b/src/editor/lib/utils.js @@ -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) {