diff --git a/examples/demo/App.tsx b/examples/demo/App.tsx index e0815291..1d11512d 100755 --- a/examples/demo/App.tsx +++ b/examples/demo/App.tsx @@ -514,7 +514,7 @@ function TabStorage({tab, layout}: {tab: TabNode, layout: FlexLayout.Layout}) { width: listBounds.width, height: listBounds.height, callback: () => { - const json = dragging instanceof TabNode ? dragging._toJson() as IJsonTabNode : dragging + const json = dragging instanceof TabNode ? dragging.toJson() as IJsonTabNode : dragging setStoredTabs(tabs => [...tabs, json]) @@ -541,7 +541,7 @@ function TabStorage({tab, layout}: {tab: TabNode, layout: FlexLayout.Layout}) { width: itemRect.width, height: 0, callback: () => { - const json = dragging instanceof TabNode ? dragging._toJson() as IJsonTabNode : dragging + const json = dragging instanceof TabNode ? dragging.toJson() as IJsonTabNode : dragging setStoredTabs(tabs => { const newTabs = [...tabs] diff --git a/src/model/BorderNode.ts b/src/model/BorderNode.ts index fceae400..015c92ec 100755 --- a/src/model/BorderNode.ts +++ b/src/model/BorderNode.ts @@ -6,6 +6,7 @@ import Orientation from "../Orientation"; import Rect from "../Rect"; import IDraggable from "./IDraggable"; import IDropTarget from "./IDropTarget"; +import { IJsonBorderNode } from "./IJsonModel"; import Model, { ILayoutMetrics } from "./Model"; import Node from "./Node"; import SplitterNode from "./SplitterNode"; @@ -355,12 +356,11 @@ class BorderNode extends Node implements IDropTarget { this._model._tidy(); } - /** @hidden @internal */ - _toJson() { + toJson(): IJsonBorderNode { const json: any = {}; BorderNode._attributeDefinitions.toJson(json, this._attributes); json.location = this._location.getName(); - json.children = this._children.map((child) => (child as TabNode)._toJson()); + json.children = this._children.map((child) => (child as TabNode).toJson()); return json; } diff --git a/src/model/BorderSet.ts b/src/model/BorderSet.ts index ba40c8f6..9c959673 100755 --- a/src/model/BorderSet.ts +++ b/src/model/BorderSet.ts @@ -40,7 +40,7 @@ class BorderSet { /** @hidden @internal */ _toJson() { - return this._borders.map((borderNode) => borderNode._toJson()); + return this._borders.map((borderNode) => borderNode.toJson()); } /** @hidden @internal */ diff --git a/src/model/Model.ts b/src/model/Model.ts index 00c90e68..8691bb43 100755 --- a/src/model/Model.ts +++ b/src/model/Model.ts @@ -385,17 +385,15 @@ class Model { * @returns {IJsonModel} json object that represents this model */ toJson(): IJsonModel { - const json: any = { global: {}, layout: {} }; - Model._attributeDefinitions.toJson(json.global, this._attributes); + const global: any = {}; + Model._attributeDefinitions.toJson(global, this._attributes); // save state of nodes this.visitNodes((node) => { node._fireEvent("save", undefined); }); - json.borders = this._borders._toJson(); - json.layout = (this._root as RowNode)._toJson(); - return json as IJsonModel; + return { global, borders: this._borders._toJson(), layout: (this._root as RowNode).toJson() }; } getSplitterSize() { diff --git a/src/model/Node.ts b/src/model/Node.ts index 49c2283f..3feace83 100755 --- a/src/model/Node.ts +++ b/src/model/Node.ts @@ -4,6 +4,7 @@ import DropInfo from "../DropInfo"; import Orientation from "../Orientation"; import Rect from "../Rect"; import IDraggable from "./IDraggable"; +import { IJsonBorderNode, IJsonRowNode, IJsonTabNode, IJsonTabSetNode } from "./IJsonModel"; import Model, { ILayoutMetrics } from "./Model"; abstract class Node { @@ -92,6 +93,8 @@ abstract class Node { delete this._listeners[event]; } + abstract toJson(): IJsonRowNode | IJsonBorderNode | IJsonTabSetNode | IJsonTabNode | undefined; + /** @hidden @internal */ _setId(id: string) { this._attributes.id = id; @@ -283,8 +286,6 @@ abstract class Node { abstract _updateAttrs(json: any): void; /** @hidden @internal */ abstract _getAttributeDefinitions(): AttributeDefinitions; - /** @hidden @internal */ - abstract _toJson(): any; } export default Node; diff --git a/src/model/RowNode.ts b/src/model/RowNode.ts index 0e731377..0c438cbc 100755 --- a/src/model/RowNode.ts +++ b/src/model/RowNode.ts @@ -8,6 +8,7 @@ import Rect from "../Rect"; import BorderNode from "./BorderNode"; import IDraggable from "./IDraggable"; import IDropTarget from "./IDropTarget"; +import { IJsonRowNode } from "./IJsonModel"; import Model, { ILayoutMetrics } from "./Model"; import Node from "./Node"; import SplitterNode from "./SplitterNode"; @@ -506,14 +507,13 @@ class RowNode extends Node implements IDropTarget { this._model._tidy(); } - /** @hidden @internal */ - _toJson() { + toJson(): IJsonRowNode { const json: any = {}; RowNode._attributeDefinitions.toJson(json, this._attributes); json.children = []; this._children.forEach((child) => { - json.children.push(child._toJson()); + json.children.push(child.toJson()); }); return json; diff --git a/src/model/SplitterNode.ts b/src/model/SplitterNode.ts index e0ea0be9..fa897acf 100755 --- a/src/model/SplitterNode.ts +++ b/src/model/SplitterNode.ts @@ -72,8 +72,7 @@ class SplitterNode extends Node { return new AttributeDefinitions(); } - /** @hidden @internal */ - _toJson(): any { + toJson(): undefined { return undefined; } } diff --git a/src/model/TabNode.ts b/src/model/TabNode.ts index 39acbb43..a9ec8b87 100755 --- a/src/model/TabNode.ts +++ b/src/model/TabNode.ts @@ -3,6 +3,7 @@ import AttributeDefinitions from "../AttributeDefinitions"; import Rect from "../Rect"; import BorderNode from "./BorderNode"; import IDraggable from "./IDraggable"; +import { IJsonTabNode } from "./IJsonModel"; import Model, { ILayoutMetrics } from "./Model"; import Node from "./Node"; import TabSetNode from "./TabSetNode"; @@ -174,8 +175,7 @@ class TabNode extends Node implements IDraggable { this._fireEvent("close", {}); } - /** @hidden @internal */ - _toJson() { + toJson(): IJsonTabNode { const json = {}; TabNode._attributeDefinitions.toJson(json, this._attributes); return json; diff --git a/src/model/TabSetNode.ts b/src/model/TabSetNode.ts index 8ad1e5f3..cd9623d9 100755 --- a/src/model/TabSetNode.ts +++ b/src/model/TabSetNode.ts @@ -7,6 +7,7 @@ import Rect from "../Rect"; import BorderNode from "./BorderNode"; import IDraggable from "./IDraggable"; import IDropTarget from "./IDropTarget"; +import { IJsonTabSetNode } from "./IJsonModel"; import Model, { ILayoutMetrics } from "./Model"; import Node from "./Node"; import RowNode from "./RowNode"; @@ -430,11 +431,10 @@ class TabSetNode extends Node implements IDraggable, IDropTarget { this._model._tidy(); } - /** @hidden @internal */ - _toJson(): any { + toJson(): IJsonTabSetNode { const json: any = {}; TabSetNode._attributeDefinitions.toJson(json, this._attributes); - json.children = this._children.map((child) => child._toJson()); + json.children = this._children.map((child) => child.toJson()); if (this.isActive()) { json.active = true;