|
|
|
@ -6,9 +6,11 @@ |
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using Jint; |
|
|
|
using Jint.Native; |
|
|
|
using Jint.Native.Object; |
|
|
|
using Jint.Runtime; |
|
|
|
using Jint.Runtime.Descriptors; |
|
|
|
using Squidex.Domain.Apps.Core.Contents; |
|
|
|
using Squidex.Infrastructure; |
|
|
|
@ -24,11 +26,11 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper |
|
|
|
private Dictionary<string, PropertyDescriptor> fieldProperties; |
|
|
|
private bool isChanged; |
|
|
|
|
|
|
|
public override bool Extensible => true; |
|
|
|
|
|
|
|
public ContentDataObject(Engine engine, NamedContentData contentData) |
|
|
|
: base(engine) |
|
|
|
{ |
|
|
|
Extensible = true; |
|
|
|
|
|
|
|
this.contentData = contentData; |
|
|
|
} |
|
|
|
|
|
|
|
@ -68,23 +70,27 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper |
|
|
|
return isChanged; |
|
|
|
} |
|
|
|
|
|
|
|
public override void RemoveOwnProperty(string propertyName) |
|
|
|
public override void RemoveOwnProperty(JsValue property) |
|
|
|
{ |
|
|
|
if (fieldsToDelete == null) |
|
|
|
{ |
|
|
|
fieldsToDelete = new HashSet<string>(); |
|
|
|
} |
|
|
|
|
|
|
|
var propertyName = property.AsString(); |
|
|
|
|
|
|
|
fieldsToDelete.Add(propertyName); |
|
|
|
fieldProperties?.Remove(propertyName); |
|
|
|
|
|
|
|
MarkChanged(); |
|
|
|
} |
|
|
|
|
|
|
|
public override bool DefineOwnProperty(string propertyName, PropertyDescriptor desc, bool throwOnError) |
|
|
|
public override bool DefineOwnProperty(JsValue property, PropertyDescriptor desc) |
|
|
|
{ |
|
|
|
EnsurePropertiesInitialized(); |
|
|
|
|
|
|
|
var propertyName = property.AsString(); |
|
|
|
|
|
|
|
if (!fieldProperties.ContainsKey(propertyName)) |
|
|
|
{ |
|
|
|
fieldProperties[propertyName] = new ContentDataProperty(this) { Value = desc.Value }; |
|
|
|
@ -93,25 +99,38 @@ namespace Squidex.Domain.Apps.Core.Scripting.ContentWrapper |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
public override void Put(string propertyName, JsValue value, bool throwOnError) |
|
|
|
public override bool Set(JsValue property, JsValue value, JsValue receiver) |
|
|
|
{ |
|
|
|
EnsurePropertiesInitialized(); |
|
|
|
|
|
|
|
var propertyName = property.AsString(); |
|
|
|
|
|
|
|
fieldProperties.GetOrAdd(propertyName, this, (k, c) => new ContentDataProperty(c)).Value = value; |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
public override PropertyDescriptor GetOwnProperty(string propertyName) |
|
|
|
public override PropertyDescriptor GetOwnProperty(JsValue property) |
|
|
|
{ |
|
|
|
EnsurePropertiesInitialized(); |
|
|
|
|
|
|
|
var propertyName = property.AsString(); |
|
|
|
|
|
|
|
return fieldProperties.GetOrAdd(propertyName, this, (k, c) => new ContentDataProperty(c, new ContentFieldObject(c, new ContentFieldData(), false))); |
|
|
|
} |
|
|
|
|
|
|
|
public override IEnumerable<KeyValuePair<string, PropertyDescriptor>> GetOwnProperties() |
|
|
|
public override IEnumerable<KeyValuePair<JsValue, PropertyDescriptor>> GetOwnProperties() |
|
|
|
{ |
|
|
|
EnsurePropertiesInitialized(); |
|
|
|
|
|
|
|
return fieldProperties.Select(x => new KeyValuePair<JsValue, PropertyDescriptor>(x.Key, x.Value)); |
|
|
|
} |
|
|
|
|
|
|
|
public override List<JsValue> GetOwnPropertyKeys(Types types = Types.String | Types.Symbol) |
|
|
|
{ |
|
|
|
EnsurePropertiesInitialized(); |
|
|
|
|
|
|
|
return fieldProperties; |
|
|
|
return fieldProperties.Keys.Select(x => (JsValue)x).ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
private void EnsurePropertiesInitialized() |
|
|
|
|