@wxn0brp/nya-dock 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -2
- package/dist/history.d.ts +16 -0
- package/dist/history.js +33 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/logger.js +1 -1
- package/dist/mouse/movePanel.js +38 -15
- package/dist/mouse/resize.js +85 -36
- package/dist/render.js +65 -15
- package/dist/state.d.ts +19 -5
- package/dist/state.js +111 -4
- package/dist/storage.js +4 -1
- package/dist/style.css +111 -33
- package/dist/style.css.map +1 -1
- package/dist/types.d.ts +18 -2
- package/dist/utils/convertSplit.js +35 -23
- package/dist/utils/detect.js +1 -1
- package/dist/utils/layout.d.ts +6 -0
- package/dist/utils/layout.js +46 -0
- package/dist/utils/movePanel.d.ts +3 -1
- package/dist/utils/movePanel.js +160 -48
- package/dist/utils/tabs.d.ts +8 -0
- package/dist/utils/tabs.js +71 -0
- package/package.json +9 -7
package/dist/state.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { render } from "./render.js";
|
|
2
2
|
import { defaultState, loadState } from "./storage.js";
|
|
3
|
+
import { RESIZE_MIN } from "./const.js";
|
|
3
4
|
import { convertToSplits } from "./utils/convertSplit.js";
|
|
4
5
|
import { movePanel } from "./utils/movePanel.js";
|
|
6
|
+
import { activateTab, isStructStack, toStack } from "./utils/tabs.js";
|
|
7
|
+
import { HistoryManager } from "./history.js";
|
|
5
8
|
export class NyaController {
|
|
6
9
|
_split;
|
|
7
10
|
_panels = new Map();
|
|
@@ -9,10 +12,20 @@ export class NyaController {
|
|
|
9
12
|
master;
|
|
10
13
|
settings = {
|
|
11
14
|
key: "nya.dock",
|
|
15
|
+
minSize: RESIZE_MIN,
|
|
12
16
|
};
|
|
13
17
|
_struct;
|
|
18
|
+
history;
|
|
19
|
+
constructor() {
|
|
20
|
+
this.history = new HistoryManager();
|
|
21
|
+
}
|
|
14
22
|
setDefaultState(state) {
|
|
15
|
-
|
|
23
|
+
if (Array.isArray(state))
|
|
24
|
+
this._struct = convertToSplits(state);
|
|
25
|
+
else if (isStructStack(state))
|
|
26
|
+
this._struct = toStack(state);
|
|
27
|
+
else
|
|
28
|
+
this._struct = state;
|
|
16
29
|
}
|
|
17
30
|
init() {
|
|
18
31
|
if (!this.master)
|
|
@@ -20,6 +33,7 @@ export class NyaController {
|
|
|
20
33
|
if (!this._struct)
|
|
21
34
|
throw new Error("Structure not set");
|
|
22
35
|
loadState(this);
|
|
36
|
+
this._pushHistory();
|
|
23
37
|
}
|
|
24
38
|
registerPanel(id, panel) {
|
|
25
39
|
panel.dataset.nya_id = id;
|
|
@@ -28,18 +42,111 @@ export class NyaController {
|
|
|
28
42
|
}
|
|
29
43
|
_render() {
|
|
30
44
|
this._splits.clear();
|
|
31
|
-
|
|
45
|
+
const result = render(this);
|
|
46
|
+
this._syncSeparators();
|
|
47
|
+
return result;
|
|
32
48
|
}
|
|
33
49
|
_setDefaultSize() {
|
|
34
|
-
this._splits.forEach(
|
|
50
|
+
this._splits.forEach(split => {
|
|
35
51
|
split.style.setProperty("--size", "50%");
|
|
36
52
|
});
|
|
53
|
+
this._syncSeparators();
|
|
54
|
+
}
|
|
55
|
+
_syncSeparators() {
|
|
56
|
+
const min = this.settings.minSize;
|
|
57
|
+
this._splits.forEach(split => {
|
|
58
|
+
const divider = split.querySelector(":scope > .nya-resize");
|
|
59
|
+
if (!divider)
|
|
60
|
+
return;
|
|
61
|
+
const isColumn = split.classList.contains("column");
|
|
62
|
+
const total = isColumn ? split.offsetHeight : split.offsetWidth;
|
|
63
|
+
const first = split.firstElementChild;
|
|
64
|
+
if (!total || !first)
|
|
65
|
+
return;
|
|
66
|
+
const percent = (value) => Math.round((value / total) * 100);
|
|
67
|
+
const size = isColumn ? first.offsetHeight : first.offsetWidth;
|
|
68
|
+
divider.setAttribute("aria-valuenow", String(percent(size)));
|
|
69
|
+
divider.setAttribute("aria-valuemin", String(percent(min)));
|
|
70
|
+
divider.setAttribute("aria-valuemax", String(100 - percent(min)));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
_syncStack(panelId, active) {
|
|
74
|
+
const body = this._panels.get(panelId)?.parentElement;
|
|
75
|
+
const stack = body?.parentElement;
|
|
76
|
+
if (!body || !stack)
|
|
77
|
+
return;
|
|
78
|
+
stack
|
|
79
|
+
.querySelectorAll(":scope > .nya-stack-tabs > .nya-tab")
|
|
80
|
+
.forEach((tab, index) => tab.classList.toggle("active", index === active));
|
|
81
|
+
body.querySelectorAll(":scope > .panel").forEach((panel, index) => {
|
|
82
|
+
panel.style.display = index === active ? "" : "none";
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
selectTab(panelId) {
|
|
86
|
+
const { tree, active } = activateTab(this._split, panelId);
|
|
87
|
+
if (active === -1)
|
|
88
|
+
return false;
|
|
89
|
+
this._split = tree;
|
|
90
|
+
this._syncStack(panelId, active);
|
|
91
|
+
this._pushHistory();
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
_captureState() {
|
|
95
|
+
const sizes = {};
|
|
96
|
+
this._splits.forEach((split, key) => {
|
|
97
|
+
sizes[key] = split.style.getPropertyValue("--size");
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
split: Object.assign({}, this._split),
|
|
101
|
+
sizes,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
_pushHistory() {
|
|
105
|
+
this.history.push(this._captureState());
|
|
106
|
+
}
|
|
107
|
+
_restoreState(state) {
|
|
108
|
+
this._split = state.split;
|
|
109
|
+
this._render();
|
|
110
|
+
this._splits.forEach((split, key) => {
|
|
111
|
+
split.style.setProperty("--size", state.sizes[key]);
|
|
112
|
+
});
|
|
113
|
+
this._syncSeparators();
|
|
114
|
+
}
|
|
115
|
+
undo() {
|
|
116
|
+
const previousState = this.history.undo();
|
|
117
|
+
if (previousState) {
|
|
118
|
+
this._restoreState(previousState);
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
redo() {
|
|
124
|
+
const nextState = this.history.redo();
|
|
125
|
+
if (nextState) {
|
|
126
|
+
this._restoreState(nextState);
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
canUndo() {
|
|
132
|
+
return this.history.canUndo();
|
|
133
|
+
}
|
|
134
|
+
canRedo() {
|
|
135
|
+
return this.history.canRedo();
|
|
37
136
|
}
|
|
38
137
|
movePanel(sourceId, targetId, zone) {
|
|
39
|
-
|
|
138
|
+
const previous = this._split;
|
|
139
|
+
const result = movePanel(this, sourceId, targetId, zone);
|
|
140
|
+
if (this._split === previous)
|
|
141
|
+
return result;
|
|
142
|
+
this._render();
|
|
143
|
+
this._setDefaultSize();
|
|
144
|
+
this._pushHistory();
|
|
145
|
+
return result;
|
|
40
146
|
}
|
|
41
147
|
reset() {
|
|
42
148
|
defaultState(this);
|
|
149
|
+
this._pushHistory();
|
|
43
150
|
}
|
|
44
151
|
}
|
|
45
152
|
export const controller = new NyaController();
|
package/dist/storage.js
CHANGED
|
@@ -7,7 +7,10 @@ export function saveState(controller) {
|
|
|
7
7
|
controller._splits.forEach((split, key) => {
|
|
8
8
|
sizes[key] = split.style.getPropertyValue("--size");
|
|
9
9
|
});
|
|
10
|
-
localStorage.setItem(controller.settings.key, JSON.stringify({
|
|
10
|
+
localStorage.setItem(controller.settings.key, JSON.stringify({
|
|
11
|
+
state,
|
|
12
|
+
sizes,
|
|
13
|
+
}));
|
|
11
14
|
}
|
|
12
15
|
export function defaultState(controller) {
|
|
13
16
|
controller._split = Object.assign({}, controller._struct);
|
package/dist/style.css
CHANGED
|
@@ -29,18 +29,18 @@
|
|
|
29
29
|
width: 100%;
|
|
30
30
|
}
|
|
31
31
|
.split.column > :first-child {
|
|
32
|
-
|
|
32
|
+
flex: 0 0 auto;
|
|
33
33
|
height: var(--size) !important;
|
|
34
34
|
}
|
|
35
|
-
.split.column >
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
.split.column > .nya-resize {
|
|
36
|
+
cursor: row-resize;
|
|
37
|
+
}
|
|
38
|
+
.split.column > .nya-resize::after {
|
|
38
39
|
left: 0;
|
|
39
40
|
right: 0;
|
|
40
|
-
|
|
41
|
-
height:
|
|
42
|
-
|
|
43
|
-
cursor: row-resize;
|
|
41
|
+
top: 50%;
|
|
42
|
+
height: 1px;
|
|
43
|
+
transform: translateY(-50%);
|
|
44
44
|
}
|
|
45
45
|
.split.row {
|
|
46
46
|
flex-direction: row;
|
|
@@ -49,60 +49,124 @@
|
|
|
49
49
|
height: 100%;
|
|
50
50
|
}
|
|
51
51
|
.split.row > :first-child {
|
|
52
|
-
|
|
52
|
+
flex: 0 0 auto;
|
|
53
53
|
width: var(--size) !important;
|
|
54
54
|
}
|
|
55
|
-
.split.row >
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
.split.row > .nya-resize {
|
|
56
|
+
cursor: col-resize;
|
|
57
|
+
}
|
|
58
|
+
.split.row > .nya-resize::after {
|
|
58
59
|
top: 0;
|
|
59
60
|
bottom: 0;
|
|
60
|
-
|
|
61
|
-
width:
|
|
62
|
-
|
|
63
|
-
cursor: col-resize;
|
|
61
|
+
left: 50%;
|
|
62
|
+
width: 1px;
|
|
63
|
+
transform: translateX(-50%);
|
|
64
64
|
}
|
|
65
|
-
.split > :
|
|
65
|
+
.split > :last-child {
|
|
66
66
|
flex: 1;
|
|
67
67
|
}
|
|
68
|
+
.split > .nya-resize {
|
|
69
|
+
position: relative;
|
|
70
|
+
flex: 0 0 6px;
|
|
71
|
+
z-index: 5;
|
|
72
|
+
}
|
|
73
|
+
.split > .nya-resize::after {
|
|
74
|
+
content: "";
|
|
75
|
+
position: absolute;
|
|
76
|
+
background: var(--nya-dock-border, silver);
|
|
77
|
+
}
|
|
78
|
+
.split > .nya-resize:focus-visible {
|
|
79
|
+
outline: 2px solid var(--nya-dock-focus, blueviolet);
|
|
80
|
+
outline-offset: -2px;
|
|
81
|
+
}
|
|
68
82
|
|
|
69
|
-
.
|
|
83
|
+
.nya-stack {
|
|
70
84
|
display: flex;
|
|
71
85
|
flex-direction: column;
|
|
86
|
+
height: 100%;
|
|
87
|
+
flex: 1;
|
|
88
|
+
min-width: 0;
|
|
72
89
|
}
|
|
73
|
-
|
|
90
|
+
|
|
91
|
+
.nya-stack-tabs {
|
|
92
|
+
display: flex;
|
|
93
|
+
background-color: var(--nya-dock-header, #2c2c2c);
|
|
94
|
+
border-bottom: 1px solid var(--nya-dock-header-border, #444);
|
|
95
|
+
overflow-x: auto;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.nya-tab {
|
|
99
|
+
padding: 10px;
|
|
100
|
+
border: none;
|
|
101
|
+
background: transparent;
|
|
102
|
+
color: var(--nya-dock-header-color, #ddd);
|
|
103
|
+
cursor: pointer;
|
|
104
|
+
white-space: nowrap;
|
|
105
|
+
}
|
|
106
|
+
.nya-tab.active {
|
|
107
|
+
background: var(--nya-dock-tab-active, #3a3a3a);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.nya-stack-body {
|
|
111
|
+
flex: 1;
|
|
112
|
+
display: flex;
|
|
113
|
+
position: relative;
|
|
114
|
+
min-height: 0;
|
|
115
|
+
}
|
|
116
|
+
.nya-stack-body > .panel {
|
|
117
|
+
flex: 1;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.nya-stack .panel > .panel-header {
|
|
121
|
+
display: none;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.split .panel,
|
|
125
|
+
.nya-stack-body .panel {
|
|
126
|
+
display: flex;
|
|
127
|
+
flex-direction: column;
|
|
128
|
+
}
|
|
129
|
+
.split .panel .panel-header,
|
|
130
|
+
.nya-stack-body .panel .panel-header {
|
|
74
131
|
background-color: var(--nya-dock-header, #2c2c2c);
|
|
75
132
|
padding: 10px;
|
|
76
133
|
border-bottom: 1px solid var(--nya-dock-header-border, #444);
|
|
77
134
|
font-weight: bold;
|
|
78
135
|
color: var(--nya-dock-header-color, #ddd);
|
|
79
136
|
}
|
|
80
|
-
.split .panel .panel-content
|
|
137
|
+
.split .panel .panel-content,
|
|
138
|
+
.nya-stack-body .panel .panel-content {
|
|
81
139
|
padding: 15px;
|
|
82
140
|
flex: 1;
|
|
83
141
|
overflow-y: auto;
|
|
84
142
|
position: relative;
|
|
85
143
|
}
|
|
86
|
-
.split .panel .panel-content h3
|
|
144
|
+
.split .panel .panel-content h3,
|
|
145
|
+
.nya-stack-body .panel .panel-content h3 {
|
|
87
146
|
margin-top: 0;
|
|
88
147
|
color: var(--nya-dock-content-color, #aaa);
|
|
89
148
|
border-bottom: 1px solid var(--nya-dock-content-border, #444);
|
|
90
149
|
padding-bottom: 5px;
|
|
91
150
|
}
|
|
92
|
-
.split .panel .panel-content p
|
|
151
|
+
.split .panel .panel-content p,
|
|
152
|
+
.nya-stack-body .panel .panel-content p {
|
|
93
153
|
margin: 10px 0;
|
|
94
154
|
line-height: 1.5;
|
|
95
155
|
}
|
|
96
|
-
.split .panel .panel-content ul
|
|
156
|
+
.split .panel .panel-content ul,
|
|
157
|
+
.nya-stack-body .panel .panel-content ul {
|
|
97
158
|
padding-left: 20px;
|
|
98
159
|
}
|
|
99
|
-
.split .panel .panel-content ul li
|
|
160
|
+
.split .panel .panel-content ul li,
|
|
161
|
+
.nya-stack-body .panel .panel-content ul li {
|
|
100
162
|
margin: 5px 0;
|
|
101
163
|
}
|
|
102
|
-
.split .panel .panel-content .button-group
|
|
164
|
+
.split .panel .panel-content .button-group,
|
|
165
|
+
.nya-stack-body .panel .panel-content .button-group {
|
|
103
166
|
margin-top: 15px;
|
|
104
167
|
}
|
|
105
|
-
.split .panel .panel-content .button-group button
|
|
168
|
+
.split .panel .panel-content .button-group button,
|
|
169
|
+
.nya-stack-body .panel .panel-content .button-group button {
|
|
106
170
|
background: var(--nya-dock-button-background, #444);
|
|
107
171
|
color: var(--nya-dock-button-color, white);
|
|
108
172
|
border: none;
|
|
@@ -111,44 +175,58 @@
|
|
|
111
175
|
border-radius: 4px;
|
|
112
176
|
cursor: pointer;
|
|
113
177
|
}
|
|
114
|
-
.split .panel .panel-content .button-group button:hover
|
|
178
|
+
.split .panel .panel-content .button-group button:hover,
|
|
179
|
+
.nya-stack-body .panel .panel-content .button-group button:hover {
|
|
115
180
|
background: var(--nya-dock-button-hover-background, #555);
|
|
116
181
|
}
|
|
117
|
-
.split .panel .panel-content .info-box
|
|
182
|
+
.split .panel .panel-content .info-box,
|
|
183
|
+
.nya-stack-body .panel .panel-content .info-box {
|
|
118
184
|
background: var(--nya-dock-info-box-background, #222);
|
|
119
185
|
padding: 10px;
|
|
120
186
|
border-radius: 4px;
|
|
121
187
|
border-left: 3px solid var(--nya-dock-info-box-border, #666);
|
|
122
188
|
}
|
|
123
|
-
.split .panel .panel-content::before
|
|
189
|
+
.split .panel .panel-content::before,
|
|
190
|
+
.nya-stack-body .panel .panel-content::before {
|
|
124
191
|
content: "";
|
|
125
192
|
position: absolute;
|
|
126
193
|
background-color: var(--nya-dock-dock-background, blueviolet);
|
|
127
194
|
opacity: var(--nya-dock-dock-opacity, 0.2);
|
|
128
195
|
}
|
|
129
|
-
.split .panel .panel-content.dock-left::before
|
|
196
|
+
.split .panel .panel-content.dock-left::before,
|
|
197
|
+
.nya-stack-body .panel .panel-content.dock-left::before {
|
|
130
198
|
left: 0;
|
|
131
199
|
top: 0;
|
|
132
200
|
width: 40%;
|
|
133
201
|
height: 100%;
|
|
134
202
|
}
|
|
135
|
-
.split .panel .panel-content.dock-right::before
|
|
203
|
+
.split .panel .panel-content.dock-right::before,
|
|
204
|
+
.nya-stack-body .panel .panel-content.dock-right::before {
|
|
136
205
|
right: 0;
|
|
137
206
|
top: 0;
|
|
138
207
|
width: 40%;
|
|
139
208
|
height: 100%;
|
|
140
209
|
}
|
|
141
|
-
.split .panel .panel-content.dock-top::before
|
|
210
|
+
.split .panel .panel-content.dock-top::before,
|
|
211
|
+
.nya-stack-body .panel .panel-content.dock-top::before {
|
|
142
212
|
left: 0;
|
|
143
213
|
top: 0;
|
|
144
214
|
width: 100%;
|
|
145
215
|
height: 40%;
|
|
146
216
|
}
|
|
147
|
-
.split .panel .panel-content.dock-bottom::before
|
|
217
|
+
.split .panel .panel-content.dock-bottom::before,
|
|
218
|
+
.nya-stack-body .panel .panel-content.dock-bottom::before {
|
|
148
219
|
left: 0;
|
|
149
220
|
bottom: 0;
|
|
150
221
|
width: 100%;
|
|
151
222
|
height: 40%;
|
|
152
223
|
}
|
|
224
|
+
.split .panel .panel-content.dock-center::before,
|
|
225
|
+
.nya-stack-body .panel .panel-content.dock-center::before {
|
|
226
|
+
left: 0;
|
|
227
|
+
top: 0;
|
|
228
|
+
width: 100%;
|
|
229
|
+
height: 100%;
|
|
230
|
+
}
|
|
153
231
|
|
|
154
232
|
/*# sourceMappingURL=style.css.map */
|
package/dist/style.css.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sourceRoot":"","sources":["../src/style.scss"],"names":[],"mappings":"AAAA;EACI;EACA;;;AAGJ;EACI;EACA;EACA;EACA;;AAEA;EACI;;AAEA;EACI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAIR;EACI;;AAEA;EACI;;AAGJ;EACI;EACA;;AAEA;EACI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAKZ;EACI;;AAEA;EACI;;AAGJ;EACI;EACA
|
|
1
|
+
{"version":3,"sourceRoot":"","sources":["../src/style.scss"],"names":[],"mappings":"AAAA;EACI;EACA;;;AAGJ;EACI;EACA;EACA;EACA;;AAEA;EACI;;AAEA;EACI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAIR;EACI;;AAEA;EACI;;AAGJ;EACI;EACA;;AAGJ;EACI;;AAEA;EACI;EACA;EACA;EACA;EACA;;AAKZ;EACI;;AAEA;EACI;;AAGJ;EACI;EACA;;AAGJ;EACI;;AAEA;EACI;EACA;EACA;EACA;EACA;;AAKZ;EACI;;AAGJ;EACI;EACA;EACA;;AAEA;EACI;EACA;EACA;;AAGJ;EACI;EACA;;;AAKZ;EACI;EACA;EACA;EACA;EACA;;;AAGJ;EACI;EACA;EACA;EACA;;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;;AAEA;EACI;;;AAIR;EACI;EACA;EACA;EACA;;AAEA;EACI;;;AAIR;EACI;;;AAGJ;AAAA;EAEI;EACA;;AAEA;AAAA;EACI;EACA;EACA;EACA;EACA;;AAGJ;AAAA;EACI;EACA;EACA;EACA;;AAEA;AAAA;EACI;EACA;EACA;EACA;;AAGJ;AAAA;EACI;EACA;;AAGJ;AAAA;EACI;;AAEA;AAAA;EACI;;AAIR;AAAA;EACI;;AAEA;AAAA;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;AAAA;EACI;;AAKZ;AAAA;EACI;EACA;EACA;EACA;;AAGJ;AAAA;EACI;EACA;EACA;EACA;;AAGJ;AAAA;EACI;EACA;EACA;EACA;;AAGJ;AAAA;EACI;EACA;EACA;EACA;;AAGJ;AAAA;EACI;EACA;EACA;EACA;;AAGJ;AAAA;EACI;EACA;EACA;EACA;;AAGJ;AAAA;EACI;EACA;EACA;EACA","file":"style.css"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
export type Direction = "left" | "right" | "top" | "bottom";
|
|
2
2
|
export type NyaNode = string;
|
|
3
3
|
export type SplitType = "row" | "column";
|
|
4
|
+
export interface NyaStack {
|
|
5
|
+
type: "stack";
|
|
6
|
+
tabs: string[];
|
|
7
|
+
active: number;
|
|
8
|
+
}
|
|
4
9
|
export interface NyaSplit {
|
|
5
|
-
nodes: [
|
|
10
|
+
nodes: [
|
|
11
|
+
NyaNode | NyaSplit | NyaStack,
|
|
12
|
+
NyaNode | NyaSplit | NyaStack
|
|
13
|
+
];
|
|
6
14
|
type: SplitType;
|
|
7
15
|
}
|
|
8
|
-
export type StructNode = [
|
|
16
|
+
export type StructNode = [
|
|
17
|
+
string | StructNode | StructStack,
|
|
18
|
+
string | StructNode | StructStack,
|
|
19
|
+
1?
|
|
20
|
+
];
|
|
21
|
+
export type StructStack = {
|
|
22
|
+
tabs: string[];
|
|
23
|
+
active?: number;
|
|
24
|
+
};
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import { isStructStack, toStack } from "./tabs.js";
|
|
2
|
+
function convertNode(node) {
|
|
3
|
+
if (Array.isArray(node))
|
|
4
|
+
return convertToSplits(node);
|
|
5
|
+
if (isStructStack(node))
|
|
6
|
+
return toStack(node);
|
|
7
|
+
return node;
|
|
8
|
+
}
|
|
1
9
|
export function convertToSplits(arr) {
|
|
2
10
|
if (arr.length === 0) {
|
|
3
11
|
throw new Error("Array structure must have at least one element");
|
|
@@ -9,46 +17,50 @@ export function convertToSplits(arr) {
|
|
|
9
17
|
actualArray = arr.slice(0, 2);
|
|
10
18
|
}
|
|
11
19
|
if (actualArray.length === 1) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
return {
|
|
22
|
-
type: isColumnLayout ? "column" : "row",
|
|
23
|
-
nodes: [element, "empty"]
|
|
24
|
-
};
|
|
25
|
-
}
|
|
20
|
+
return {
|
|
21
|
+
type: isColumnLayout ? "column" : "row",
|
|
22
|
+
nodes: [
|
|
23
|
+
convertNode(actualArray[0]),
|
|
24
|
+
"empty",
|
|
25
|
+
],
|
|
26
|
+
};
|
|
26
27
|
}
|
|
27
28
|
else if (actualArray.length === 2) {
|
|
28
29
|
const [first, second] = actualArray;
|
|
29
|
-
const firstElement = Array.isArray(first) ? convertToSplits(first) : first;
|
|
30
|
-
const secondElement = Array.isArray(second) ? convertToSplits(second) : second;
|
|
31
30
|
return {
|
|
32
31
|
type: isColumnLayout ? "column" : "row",
|
|
33
|
-
nodes: [
|
|
32
|
+
nodes: [
|
|
33
|
+
convertNode(first),
|
|
34
|
+
convertNode(second),
|
|
35
|
+
],
|
|
34
36
|
};
|
|
35
37
|
}
|
|
36
38
|
else {
|
|
37
39
|
const [first, ...rest] = actualArray;
|
|
38
|
-
let restStructure = [
|
|
40
|
+
let restStructure = [
|
|
41
|
+
rest[0],
|
|
42
|
+
];
|
|
39
43
|
for (let i = 1; i < rest.length; i++) {
|
|
40
44
|
if (isColumnLayout) {
|
|
41
|
-
restStructure = [
|
|
45
|
+
restStructure = [
|
|
46
|
+
restStructure,
|
|
47
|
+
rest[i],
|
|
48
|
+
1,
|
|
49
|
+
];
|
|
42
50
|
}
|
|
43
51
|
else {
|
|
44
|
-
restStructure = [
|
|
52
|
+
restStructure = [
|
|
53
|
+
restStructure,
|
|
54
|
+
rest[i],
|
|
55
|
+
];
|
|
45
56
|
}
|
|
46
57
|
}
|
|
47
|
-
const firstElement = Array.isArray(first) ? convertToSplits(first) : first;
|
|
48
|
-
const restElement = Array.isArray(restStructure) ? convertToSplits(restStructure) : restStructure;
|
|
49
58
|
return {
|
|
50
59
|
type: isColumnLayout ? "column" : "row",
|
|
51
|
-
nodes: [
|
|
60
|
+
nodes: [
|
|
61
|
+
convertNode(first),
|
|
62
|
+
convertNode(restStructure),
|
|
63
|
+
],
|
|
52
64
|
};
|
|
53
65
|
}
|
|
54
66
|
}
|
package/dist/utils/detect.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NyaSplit, NyaStack } from "../types.js";
|
|
2
|
+
export type LayoutChild = string | NyaSplit | NyaStack;
|
|
3
|
+
export declare function row(...nodes: LayoutChild[]): NyaSplit;
|
|
4
|
+
export declare function column(...nodes: LayoutChild[]): NyaSplit;
|
|
5
|
+
export declare function tabs(ids: string[], active?: number): NyaStack;
|
|
6
|
+
export declare function tabs(...ids: string[]): NyaStack;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
function fold(type, nodes) {
|
|
2
|
+
if (nodes.length < 2)
|
|
3
|
+
throw new Error(`nya-dock: ${type} needs at least two children`);
|
|
4
|
+
if (nodes.length === 2)
|
|
5
|
+
return {
|
|
6
|
+
type,
|
|
7
|
+
nodes: [
|
|
8
|
+
nodes[0],
|
|
9
|
+
nodes[1],
|
|
10
|
+
],
|
|
11
|
+
};
|
|
12
|
+
return {
|
|
13
|
+
type,
|
|
14
|
+
nodes: [
|
|
15
|
+
nodes[0],
|
|
16
|
+
fold(type, nodes.slice(1)),
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function row(...nodes) {
|
|
21
|
+
return fold("row", nodes);
|
|
22
|
+
}
|
|
23
|
+
export function column(...nodes) {
|
|
24
|
+
return fold("column", nodes);
|
|
25
|
+
}
|
|
26
|
+
export function tabs(...args) {
|
|
27
|
+
let ids;
|
|
28
|
+
let active;
|
|
29
|
+
if (Array.isArray(args[0])) {
|
|
30
|
+
ids = args[0];
|
|
31
|
+
active = args[1] ?? 0;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
ids = args;
|
|
35
|
+
active = 0;
|
|
36
|
+
}
|
|
37
|
+
if (ids.length === 0)
|
|
38
|
+
throw new Error("nya-dock: tabs needs at least one id");
|
|
39
|
+
return {
|
|
40
|
+
type: "stack",
|
|
41
|
+
tabs: [
|
|
42
|
+
...ids,
|
|
43
|
+
],
|
|
44
|
+
active,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { NyaController } from "../state.js";
|
|
2
2
|
import { Direction } from "../types.js";
|
|
3
|
-
|
|
3
|
+
type Zone = Direction | "center";
|
|
4
|
+
export declare function movePanel(controller: NyaController, sourceId: string, targetId: string, zone: Zone): void;
|
|
5
|
+
export {};
|