117 const nlohmann::json& j) {
118 if (!j.is_object()) {
119 return absl::InvalidArgumentError(
"dock node must be a JSON object");
121 const std::string type = j.value(
"type",
"");
122 if (type ==
"leaf") {
123 auto node = std::make_unique<DockNode>();
126 node->active_tab_index = j.value(
"active_tab_index", 0);
127 if (j.contains(
"panels")) {
128 const auto& panels = j.at(
"panels");
129 if (!panels.is_array()) {
130 return absl::InvalidArgumentError(
"leaf 'panels' must be an array");
132 for (
const auto& p : panels) {
135 return entry.status();
136 node->panels.push_back(std::move(*entry));
141 if (type ==
"split") {
142 auto node = std::make_unique<DockNode>();
145 const std::string dir_str = j.value(
"direction",
"left");
149 node->split_direction = *dir;
150 node->split_ratio = j.value(
"ratio", 0.5f);
151 if (!j.contains(
"child_a") || !j.contains(
"child_b")) {
152 return absl::InvalidArgumentError(
"split node missing child_a/child_b");
160 node->child_a = std::move(*a);
161 node->child_b = std::move(*b);
164 return absl::InvalidArgumentError(
165 absl::StrCat(
"unknown dock node type: '", type,
"'"));