@itwin/presentation-common
Version:
Common pieces for iModel.js presentation packages
49 lines • 1.71 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 Content
*/
import { Descriptor } from "./Descriptor.js";
import { Item } from "./Item.js";
/**
* A data structure that contains the [[Descriptor]] and a list of [[Item]]
* objects which are based on that descriptor.
*
* @public
*/
export class Content {
/** Descriptor used to create the content */
descriptor;
/** Content items */
contentSet;
/** Create a new [[Content]] instance */
constructor(descriptor, items) {
this.descriptor = descriptor;
this.contentSet = items;
}
/** Serialize this object to JSON */
toJSON() {
return {
descriptor: this.descriptor.toJSON(),
contentSet: this.contentSet.map((item) => item.toJSON()),
};
}
/** Deserialize [[Content]] from JSON */
static fromJSON(json) {
if (!json) {
return undefined;
}
if (typeof json === "string") {
return Content.fromJSON(JSON.parse(json));
}
const descriptor = Descriptor.fromJSON(json.descriptor);
if (!descriptor) {
return undefined;
}
const contentSet = json.contentSet.map((itemJson) => Item.fromJSON(itemJson)).filter((item) => item !== undefined);
return new Content(descriptor, contentSet);
}
}
//# sourceMappingURL=Content.js.map