UNPKG

@itwin/presentation-common

Version:

Common pieces for iModel.js presentation packages

53 lines 1.87 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * 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 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Content = void 0; const Descriptor_js_1 = require("./Descriptor.js"); const Item_js_1 = require("./Item.js"); /** * A data structure that contains the [[Descriptor]] and a list of [[Item]] * objects which are based on that descriptor. * * @public */ 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_js_1.Descriptor.fromJSON(json.descriptor); if (!descriptor) { return undefined; } const contentSet = json.contentSet.map((itemJson) => Item_js_1.Item.fromJSON(itemJson)).filter((item) => item !== undefined); return new Content(descriptor, contentSet); } } exports.Content = Content; //# sourceMappingURL=Content.js.map