1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const SerializeError_1 = require("./SerializeError");
|
4 | function maybeSerializeMenuItemGroup(item, index, path) {
|
5 | return item instanceof MenuItemGroupBuilder ? item.serialize({ path, index }) : item;
|
6 | }
|
7 | exports.maybeSerializeMenuItemGroup = maybeSerializeMenuItemGroup;
|
8 | class MenuItemGroupBuilder {
|
9 | constructor(spec) {
|
10 | this._id = spec ? spec.id : '';
|
11 | this._title = spec ? spec.title : '';
|
12 | }
|
13 | id(id) {
|
14 | return new MenuItemGroupBuilder({ id, title: this._title });
|
15 | }
|
16 | getId() {
|
17 | return this._id;
|
18 | }
|
19 | title(title) {
|
20 | return new MenuItemGroupBuilder({ id: this._id, title });
|
21 | }
|
22 | getTitle() {
|
23 | return this._title;
|
24 | }
|
25 | serialize(options = { path: [] }) {
|
26 | const { _id, _title } = this;
|
27 | if (!_id) {
|
28 | throw new SerializeError_1.SerializeError('`id` is required for a menu item group', options.path, options.index, _title).withHelpUrl(SerializeError_1.HELP_URL.ID_REQUIRED);
|
29 | }
|
30 | if (!_title) {
|
31 | throw new SerializeError_1.SerializeError('`title` is required for a menu item group', options.path, _id).withHelpUrl(SerializeError_1.HELP_URL.TITLE_REQUIRED);
|
32 | }
|
33 | return {
|
34 | id: _id,
|
35 | title: _title
|
36 | };
|
37 | }
|
38 | }
|
39 | exports.MenuItemGroupBuilder = MenuItemGroupBuilder;
|
40 |
|
41 |
|