@itwin/appui-abstract
Version:
iTwin.js UI abstractions
97 lines • 3.9 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Properties
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.PropertyRecord = void 0;
const StandardTypeNames_1 = require("./StandardTypeNames");
const Value_1 = require("./Value");
/**
* PropertyRecord contains instance information about a Property, including a
* value that can be edited using a PropertyEditor and converted using a TypeConverter.
* @public
*/
class PropertyRecord {
/** Value for the property */
value;
/** The property description containing metadata for the property */
property;
/** Description for the property */
description;
/** Indicates if the property is read-only */
isReadonly;
/** Indicates if the property is disabled */
isDisabled;
/** Indicates if the property record represents merged properties */
isMerged;
/** Indicates if the property should be automatically expanded */
autoExpand;
/** Map containing any additional data */
extendedData;
/** Properties for link logic */
links;
/** Constructs a PropertyRecord instance */
constructor(value, property) {
this.value = value;
this.property = property;
}
/** Creates a copy of this PropertyRecord with a new value and optionally a new PropertyDescription */
copyWithNewValue(newValue, newDescription) {
const rec = new PropertyRecord(newValue, newDescription ? newDescription : this.property);
assignMemberIfExists(rec, this, "description");
assignMemberIfExists(rec, this, "isReadonly");
assignMemberIfExists(rec, this, "isDisabled");
assignMemberIfExists(rec, this, "isMerged");
assignMemberIfExists(rec, this, "autoExpand");
assignMemberIfExists(rec, this, "extendedData");
assignMemberIfExists(rec, this, "links");
return rec;
}
/** Gets this property record value children records */
getChildrenRecords() {
switch (this.value.valueFormat) {
case Value_1.PropertyValueFormat.Primitive:
return [];
case Value_1.PropertyValueFormat.Struct:
return Object.values(this.value.members);
case Value_1.PropertyValueFormat.Array:
return this.value.items;
}
}
/** Creates a PropertyRecord based on a value string and an optional property description or name */
static fromString(value, descriptionOrName) {
let description;
if (descriptionOrName && typeof descriptionOrName === "object") {
description = descriptionOrName;
}
else if (descriptionOrName && typeof descriptionOrName === "string") {
description = {
name: descriptionOrName,
displayLabel: descriptionOrName,
typename: StandardTypeNames_1.StandardTypeNames.String,
};
}
else {
description = {
name: "string_value",
displayLabel: "String Value",
typename: StandardTypeNames_1.StandardTypeNames.String,
};
}
return new PropertyRecord({
valueFormat: Value_1.PropertyValueFormat.Primitive,
value,
displayValue: value,
}, description);
}
}
exports.PropertyRecord = PropertyRecord;
function assignMemberIfExists(target, source, memberName) {
if (source.hasOwnProperty(memberName))
target[memberName] = source[memberName];
}
//# sourceMappingURL=Record.js.map