@dynamix-layout/core 0.0.2-beta.0 → 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/CHANGELOG.md +12 -0
- package/README.md +155 -61
- package/{LICENSE → dist/LICENSE} +1 -1
- package/dist/core.cjs.js +57 -0
- package/dist/core.cjs.js.br +0 -0
- package/dist/core.cjs.js.gz +0 -0
- package/dist/core.cjs.js.map +1 -0
- package/dist/core.es.js +1025 -0
- package/dist/core.es.js.br +0 -0
- package/dist/core.es.js.gz +0 -0
- package/dist/core.es.js.map +1 -0
- package/dist/core.iife.js +57 -1
- package/dist/core.iife.js.br +0 -0
- package/dist/core.iife.js.gz +0 -0
- package/dist/core.iife.js.map +1 -0
- package/dist/core.umd.js +57 -1
- package/dist/core.umd.js.br +0 -0
- package/dist/core.umd.js.gz +0 -0
- package/dist/core.umd.js.map +1 -0
- package/dist/types/app/comparator.d.ts +3 -0
- package/dist/types/app/dynamix.d.ts +97 -0
- package/dist/types/app/index.d.ts +4 -64
- package/dist/types/app/queue.d.ts +217 -0
- package/dist/types/app/reactive-state.d.ts +3 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/type/index.d.ts +54 -0
- package/package.json +58 -29
- package/dist/core.js +0 -1
- package/dist/core.mjs +0 -244
- package/dist/types/lib/Constant.d.ts +0 -14
- package/dist/types/lib/Element.d.ts +0 -22
- package/dist/types/lib/Helper.d.ts +0 -21
- package/dist/types/lib/Method.d.ts +0 -1
- package/dist/types/lib/index.d.ts +0 -4
- package/dist/types/types/Element.d.ts +0 -103
- package/dist/types/types/Method.d.ts +0 -5
- package/dist/types/types/index.d.ts +0 -2
- package/src/app/index.ts +0 -291
- package/src/index.ts +0 -3
- package/src/lib/Constant.ts +0 -17
- package/src/lib/Element.ts +0 -66
- package/src/lib/Helper.ts +0 -259
- package/src/lib/Method.ts +0 -12
- package/src/lib/index.ts +0 -4
- package/src/types/Element.ts +0 -116
- package/src/types/Method.ts +0 -4
- package/src/types/index.ts +0 -2
package/src/app/index.ts
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { ILayout, Type, LayoutTree, AreaValue } from "../types";
|
|
2
|
-
import { Node, Bond, Helper } from "../lib";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type LayoutOptions = {
|
|
6
|
-
layout?: LayoutTree,
|
|
7
|
-
range?: number,
|
|
8
|
-
dimension?: [number, number],
|
|
9
|
-
tabs?: string[],
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type Settings = {
|
|
13
|
-
layout: LayoutTree,
|
|
14
|
-
range: number,
|
|
15
|
-
dimension: [number, number],
|
|
16
|
-
coordinate: [number, number],
|
|
17
|
-
tabs: string[],
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default class Layout implements ILayout<Node, Bond> {
|
|
21
|
-
_root: Node;
|
|
22
|
-
_tabs: Node[];
|
|
23
|
-
_bond: Bond[];
|
|
24
|
-
_settings: Settings;
|
|
25
|
-
constructor(
|
|
26
|
-
options: LayoutOptions = {}
|
|
27
|
-
) {
|
|
28
|
-
|
|
29
|
-
let setting = Object.assign({
|
|
30
|
-
layout: null,
|
|
31
|
-
range: 1,
|
|
32
|
-
dimension: [0, 0],
|
|
33
|
-
coordinate: [0, 0],
|
|
34
|
-
tabs: Array.from({ length: options.range ?? 1 }, (_, i) => `tab-${i + 1}`),
|
|
35
|
-
}, options);
|
|
36
|
-
|
|
37
|
-
this._tabs = [];
|
|
38
|
-
this._bond = [];
|
|
39
|
-
this._settings = setting;
|
|
40
|
-
this._root = new Node(Type.Row, 100, null);
|
|
41
|
-
|
|
42
|
-
this._root.coordinate = this._settings.coordinate;
|
|
43
|
-
this._root.dimension = this._settings.dimension;
|
|
44
|
-
this.createTree();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public shiftTree = (srcId: string, desId: string, area: AreaValue) => {
|
|
48
|
-
|
|
49
|
-
let des: any;
|
|
50
|
-
let src: any;
|
|
51
|
-
|
|
52
|
-
this._tabs.forEach((tab: Node) => {
|
|
53
|
-
if (tab.name == desId) des = tab;
|
|
54
|
-
if (tab.name == srcId) src = tab;
|
|
55
|
-
tab.children.forEach((child: Node) => {
|
|
56
|
-
if (child.name == desId) des = child;
|
|
57
|
-
if (child.name == srcId) src = child;
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (src === undefined || src === null) return;
|
|
62
|
-
if (des === undefined || des === null) return;
|
|
63
|
-
|
|
64
|
-
if (src.parent === null) return;
|
|
65
|
-
|
|
66
|
-
const length = src.parent.children.length;
|
|
67
|
-
|
|
68
|
-
if (des.type == Type.Tabset && src.type == Type.Tab) {
|
|
69
|
-
Helper.detach(src, length > 1);
|
|
70
|
-
Helper.attach(des, src, area);
|
|
71
|
-
|
|
72
|
-
} else if (des.type == Type.Tabset && src.type == Type.Tabset) {
|
|
73
|
-
Helper.detach(src, length > 2);
|
|
74
|
-
Helper.attach(des, src, area);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return this.calculate(this._root, 0);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private createTree = () => {
|
|
81
|
-
const { layout } = this._settings;
|
|
82
|
-
|
|
83
|
-
if (!layout) {
|
|
84
|
-
Helper.createBinaryTree(this._root, this._settings);
|
|
85
|
-
console.log("create tree",JSON.stringify(this.jsonify()));
|
|
86
|
-
|
|
87
|
-
return this.updateTree();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const queue: LayoutTree[] = [layout];
|
|
91
|
-
const _queue: Node[] = [this._root];
|
|
92
|
-
|
|
93
|
-
const levels: LayoutTree[][] = [];
|
|
94
|
-
let toggle = 1;
|
|
95
|
-
|
|
96
|
-
while (queue.length) {
|
|
97
|
-
const level: LayoutTree[] = [];
|
|
98
|
-
const range = queue.length;
|
|
99
|
-
|
|
100
|
-
for (let i = 0; i < range; i++) {
|
|
101
|
-
|
|
102
|
-
const parent = queue.shift();
|
|
103
|
-
const _parent = _queue.shift();
|
|
104
|
-
|
|
105
|
-
if (parent) {
|
|
106
|
-
level.push(parent);
|
|
107
|
-
parent.children.forEach((child: LayoutTree, index: number) => {
|
|
108
|
-
queue.push(child);
|
|
109
|
-
_queue.push(
|
|
110
|
-
new Node(child.type, child.weight, _parent ?? null)
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
_parent?.children.push(_queue[_queue.length - 1]);
|
|
114
|
-
|
|
115
|
-
if (index == 0) return;
|
|
116
|
-
|
|
117
|
-
new Bond(
|
|
118
|
-
child.type,
|
|
119
|
-
_queue[_queue.length - 2],
|
|
120
|
-
_queue[_queue.length - 1],
|
|
121
|
-
);
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
levels.push(level);
|
|
127
|
-
toggle = 1 - toggle;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
this.updateTree();
|
|
131
|
-
return this;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
public updateTree = (width?: number, height?: number, hook?: Function) => {
|
|
135
|
-
|
|
136
|
-
if (width && height) {
|
|
137
|
-
this._root.dimension = [width, height];
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const queue: Node[] = [this._root];
|
|
141
|
-
|
|
142
|
-
const levels: any[][] = [];
|
|
143
|
-
let toggle = 1;
|
|
144
|
-
|
|
145
|
-
this._bond = [];
|
|
146
|
-
this._tabs = [];
|
|
147
|
-
|
|
148
|
-
while (queue.length) {
|
|
149
|
-
const level: any[] = [];
|
|
150
|
-
const range = queue.length;
|
|
151
|
-
|
|
152
|
-
for (let i = 0; i < range; i++) {
|
|
153
|
-
|
|
154
|
-
const parent = queue.shift() as Node;
|
|
155
|
-
|
|
156
|
-
const size = Helper.getSize(parent);
|
|
157
|
-
const weight = Helper.getTotalWeight(parent);
|
|
158
|
-
|
|
159
|
-
let percent = 0;
|
|
160
|
-
let sum = 0;
|
|
161
|
-
let prev = parent.children[0];
|
|
162
|
-
const dimension = parent.dimension
|
|
163
|
-
const coordinate = parent.coordinate
|
|
164
|
-
|
|
165
|
-
if (parent) {
|
|
166
|
-
level.push(parent.coordinate);
|
|
167
|
-
if (parent.type == Type.Tabset) {
|
|
168
|
-
this._tabs.push(parent);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
parent.children.forEach((child: Node, index: number) => {
|
|
172
|
-
queue.push(child);
|
|
173
|
-
child.dimension = [...dimension];
|
|
174
|
-
child.coordinate = [...coordinate];
|
|
175
|
-
|
|
176
|
-
child.weight = (child.weight / weight) * 100;
|
|
177
|
-
if (index === parent.children.length - 1) {
|
|
178
|
-
child.dimension[parent.type] = size - sum;
|
|
179
|
-
child.weight = 100 - percent;
|
|
180
|
-
} else {
|
|
181
|
-
child.weight = (child.weight / weight) * 100;
|
|
182
|
-
const dmn = size * (child.weight / 100);
|
|
183
|
-
child.dimension[parent.type] = dmn;
|
|
184
|
-
percent += child.weight;
|
|
185
|
-
sum += child.dimension[parent.type];
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
child.dimension[parent.type] = child.dimension[parent.type];
|
|
189
|
-
|
|
190
|
-
if (!child.prev) return;
|
|
191
|
-
child.coordinate[parent.type] =
|
|
192
|
-
prev.coordinate[parent.type] +
|
|
193
|
-
prev.dimension[parent.type] + 8;
|
|
194
|
-
|
|
195
|
-
child.prev.dimension = [...dimension];
|
|
196
|
-
child.prev.coordinate = [...coordinate];
|
|
197
|
-
child.prev.dimension[parent.type] = 8;
|
|
198
|
-
|
|
199
|
-
child.prev.coordinate[parent.type] =
|
|
200
|
-
prev.coordinate[parent.type] +
|
|
201
|
-
prev.dimension[parent.type];
|
|
202
|
-
|
|
203
|
-
child.prev.type = 1 - parent.type;
|
|
204
|
-
prev = child;
|
|
205
|
-
this._bond.push(child.prev);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
levels.push(level);
|
|
211
|
-
toggle = 1 - toggle;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (hook) hook();
|
|
215
|
-
|
|
216
|
-
return this.getElements();
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
calculate(node: Node, level = 0) {
|
|
221
|
-
|
|
222
|
-
if (level == 0) {
|
|
223
|
-
this._bond = [];
|
|
224
|
-
this._tabs = [];
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const reducedSize = Helper.getSize(node);
|
|
228
|
-
const totalWeight = Helper.getTotalWeight(node);
|
|
229
|
-
|
|
230
|
-
let prev = node.children[0];
|
|
231
|
-
let sum = 0;
|
|
232
|
-
let prcnt = 0;
|
|
233
|
-
|
|
234
|
-
if (node.type == Type.Tabset) {
|
|
235
|
-
this._tabs.push(node);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
node.children.forEach((child, index) => {
|
|
239
|
-
|
|
240
|
-
child.dimension = [...node.dimension];
|
|
241
|
-
child.coordinate = [...node.coordinate];
|
|
242
|
-
|
|
243
|
-
if (index === node.children.length - 1) {
|
|
244
|
-
child.dimension[node.type] = reducedSize - sum;
|
|
245
|
-
child.weight = 100 - prcnt;
|
|
246
|
-
} else {
|
|
247
|
-
child.weight = (child.weight / totalWeight) * 100;
|
|
248
|
-
child.dimension[node.type] = reducedSize * (child.weight / 100);
|
|
249
|
-
prcnt += child.weight;
|
|
250
|
-
sum += child.dimension[node.type];
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (index === 0) return;
|
|
254
|
-
|
|
255
|
-
child.coordinate[node.type] = prev.coordinate[node.type] + prev.dimension[node.type] + 8;
|
|
256
|
-
|
|
257
|
-
if (child.prev) {
|
|
258
|
-
|
|
259
|
-
child.prev.dimension = [...node.dimension];
|
|
260
|
-
child.prev.coordinate = [...node.coordinate];
|
|
261
|
-
child.prev.dimension[node.type] = 8;
|
|
262
|
-
child.prev.coordinate[node.type] = prev.coordinate[node.type] + prev.dimension[node.type];
|
|
263
|
-
|
|
264
|
-
this._bond.push(child.prev);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
prev = child;
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
if (node.type == Type.Tabset) {
|
|
271
|
-
this._tabs.push(node);
|
|
272
|
-
}
|
|
273
|
-
node.children.forEach((child) => {
|
|
274
|
-
if (child.children.length) {
|
|
275
|
-
this.calculate(child, level + 1);
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
public getElements = () => {
|
|
282
|
-
return {
|
|
283
|
-
tabs: this._tabs.map((tab: Node) => Helper.json(tab)),
|
|
284
|
-
bonds: this._bond.map((bond: Bond) => Helper.json(bond))
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
public jsonify = () => {
|
|
289
|
-
return Helper.json(this._root)
|
|
290
|
-
}
|
|
291
|
-
}
|
package/src/index.ts
DELETED
package/src/lib/Constant.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Type } from '../types';
|
|
2
|
-
|
|
3
|
-
export const AreaType = {
|
|
4
|
-
top: Type.Row,
|
|
5
|
-
left: Type.Column,
|
|
6
|
-
right: Type.Column,
|
|
7
|
-
bottom: Type.Row,
|
|
8
|
-
cover: Type.Tab
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const AreaIndex = {
|
|
12
|
-
top: 0,
|
|
13
|
-
left: 0,
|
|
14
|
-
right: 1,
|
|
15
|
-
bottom: 1,
|
|
16
|
-
cover : 0
|
|
17
|
-
}
|
package/src/lib/Element.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
INode,
|
|
3
|
-
IBond,
|
|
4
|
-
TypeValue,
|
|
5
|
-
} from '../types';
|
|
6
|
-
|
|
7
|
-
export class Node implements INode<Node,Bond> {
|
|
8
|
-
type: TypeValue;
|
|
9
|
-
name: string | null;
|
|
10
|
-
weight: number;
|
|
11
|
-
|
|
12
|
-
parent: Node | null;
|
|
13
|
-
children: Node[];
|
|
14
|
-
|
|
15
|
-
dimension: [number,number];
|
|
16
|
-
coordinate: [number,number];
|
|
17
|
-
|
|
18
|
-
prev: Bond | null;
|
|
19
|
-
next: Bond | null;
|
|
20
|
-
constructor(
|
|
21
|
-
type: TypeValue,
|
|
22
|
-
|
|
23
|
-
weight: number,
|
|
24
|
-
parent: Node | null
|
|
25
|
-
) {
|
|
26
|
-
this.type = type;
|
|
27
|
-
this.name = null;
|
|
28
|
-
this.parent = parent;
|
|
29
|
-
this.weight = weight;
|
|
30
|
-
|
|
31
|
-
this.children = [];
|
|
32
|
-
this.dimension = [0,0];
|
|
33
|
-
this.coordinate = [0,0];
|
|
34
|
-
this.prev = null;
|
|
35
|
-
this.next = null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export class Bond implements IBond<Node> {
|
|
40
|
-
type: TypeValue;
|
|
41
|
-
name: string | null;
|
|
42
|
-
|
|
43
|
-
prev: Node;
|
|
44
|
-
next: Node;
|
|
45
|
-
|
|
46
|
-
dimension: [number,number];
|
|
47
|
-
coordinate: [number,number];
|
|
48
|
-
|
|
49
|
-
constructor(
|
|
50
|
-
type: TypeValue,
|
|
51
|
-
|
|
52
|
-
prev: Node,
|
|
53
|
-
next: Node,
|
|
54
|
-
) {
|
|
55
|
-
this.type = type;
|
|
56
|
-
this.prev = prev;
|
|
57
|
-
this.next = next;
|
|
58
|
-
this.name = `${prev.name}-${next.name}`;
|
|
59
|
-
this.dimension = [0,0];
|
|
60
|
-
this.coordinate = [0,0];
|
|
61
|
-
|
|
62
|
-
prev.next = this;
|
|
63
|
-
next.prev = this;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
package/src/lib/Helper.ts
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import { IMethods, Type, AreaValue, TypeValue } from "../types"
|
|
2
|
-
import { Node, Bond } from "./Element";
|
|
3
|
-
import { AreaIndex, AreaType } from "./Constant";
|
|
4
|
-
import { Settings } from "../app";
|
|
5
|
-
export class Helper implements IMethods {
|
|
6
|
-
|
|
7
|
-
static createBinaryTree = (root: Node, settings: Settings) => {
|
|
8
|
-
const { range } = settings;
|
|
9
|
-
const tabs = [...settings.tabs]
|
|
10
|
-
if (range == 1) {
|
|
11
|
-
|
|
12
|
-
const col = new Node(Type.Column, 100, root)
|
|
13
|
-
root.children = [col];
|
|
14
|
-
Helper.addTab(col, tabs);
|
|
15
|
-
return;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const queue: Node[] = [root];
|
|
19
|
-
|
|
20
|
-
const levels: Node[][] = [];
|
|
21
|
-
|
|
22
|
-
let toggle = 1;
|
|
23
|
-
let count = 1;
|
|
24
|
-
|
|
25
|
-
while (count < (range as number) || queue.length) {
|
|
26
|
-
const level: Node[] = [];
|
|
27
|
-
const length = queue.length;
|
|
28
|
-
|
|
29
|
-
for (let i = 0; i < length; i++) {
|
|
30
|
-
|
|
31
|
-
const parent = queue.shift() as Node;
|
|
32
|
-
const pIndex = parent.parent?.children.indexOf(parent) ?? 0;
|
|
33
|
-
parent.name = `r${levels.length}/c${i}/tb${pIndex}`;
|
|
34
|
-
|
|
35
|
-
if (parent) {
|
|
36
|
-
level.push(parent);
|
|
37
|
-
|
|
38
|
-
if (count < (range as number)) {
|
|
39
|
-
parent.children[0] = new Node(toggle, 50, parent);
|
|
40
|
-
queue.push(parent.children[0]);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (count < (range as number)) {
|
|
44
|
-
parent.children[1] = new Node(toggle, 50, parent);
|
|
45
|
-
queue.push(parent.children[1]);
|
|
46
|
-
|
|
47
|
-
count++;
|
|
48
|
-
|
|
49
|
-
const bond = new Bond(
|
|
50
|
-
toggle,
|
|
51
|
-
parent.children[0],
|
|
52
|
-
parent.children[1]
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
bond.name = `r${levels.length}/c${i}/b${pIndex}-${pIndex + 1}`;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
levels.push(level);
|
|
61
|
-
toggle = 1 - toggle;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const last = [
|
|
65
|
-
...levels[levels.length - 1],
|
|
66
|
-
...levels[levels.length - 2]
|
|
67
|
-
]
|
|
68
|
-
|
|
69
|
-
last.forEach((child: Node) => {
|
|
70
|
-
Helper.addTab(child, tabs)
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
static fixSrc = (src: Node) => {
|
|
77
|
-
const parent = src.parent;
|
|
78
|
-
if (!parent) return;
|
|
79
|
-
const index = parent.children.indexOf(src);
|
|
80
|
-
const peer = parent.children[1 - index];
|
|
81
|
-
const grand = parent.parent;
|
|
82
|
-
const pIndex = grand?.children.indexOf(parent) as number;
|
|
83
|
-
|
|
84
|
-
switch (peer.type) {
|
|
85
|
-
case Type.Tabset:
|
|
86
|
-
const weight = parent.weight;
|
|
87
|
-
grand?.children.splice(pIndex, 1);
|
|
88
|
-
grand?.children.splice(pIndex, 0, peer);
|
|
89
|
-
peer.weight = weight;
|
|
90
|
-
peer.parent = grand;
|
|
91
|
-
Helper.fixBond(peer, peer.type);
|
|
92
|
-
|
|
93
|
-
break;
|
|
94
|
-
default:
|
|
95
|
-
|
|
96
|
-
if (!grand) {
|
|
97
|
-
parent.children.splice(index, 1);
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
const count = peer.children.length;
|
|
101
|
-
const affacted = (8 * (count - 1)) * 100 / grand.dimension[peer.type];
|
|
102
|
-
|
|
103
|
-
peer.children.forEach((child: Node) => {
|
|
104
|
-
child.weight = ((parent.weight - affacted) * child.weight) / 100;
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const first = peer.children[0];
|
|
108
|
-
const last = peer.children[count - 1];
|
|
109
|
-
|
|
110
|
-
grand.children = [
|
|
111
|
-
...grand.children.slice(0, pIndex),
|
|
112
|
-
...peer.children,
|
|
113
|
-
...grand.children.slice(pIndex + 1)
|
|
114
|
-
]
|
|
115
|
-
|
|
116
|
-
peer.children.forEach((child: Node) => {
|
|
117
|
-
child.parent = grand;
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
Helper.fixBond(first, peer.type);
|
|
121
|
-
Helper.fixBond(last, peer.type);
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
static detach(src: Node, flag: Boolean) {
|
|
127
|
-
const parent = src.parent;
|
|
128
|
-
if (!parent) return;
|
|
129
|
-
|
|
130
|
-
const index = src.parent?.children.indexOf(src) as number;
|
|
131
|
-
const range = parent?.children.length as number;
|
|
132
|
-
const affacted = 8 * 100 / parent.dimension[parent.type];
|
|
133
|
-
if (!flag) return Helper.fixSrc(src);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (index > 0 && index < range - 1) {
|
|
138
|
-
const weight = (src.weight + affacted) / 2;
|
|
139
|
-
const next = parent.children[index + 1];
|
|
140
|
-
const prev = parent.children[index - 1];
|
|
141
|
-
next.weight += weight;
|
|
142
|
-
prev.weight += weight;
|
|
143
|
-
new Bond(src.type, prev, next);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (index === range - 1) {
|
|
147
|
-
const prev = parent.children[index - 1];
|
|
148
|
-
prev.weight += src.weight + affacted;
|
|
149
|
-
prev.next = null;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (index === 0) {
|
|
153
|
-
const next = parent.children[index + 1];
|
|
154
|
-
next.weight += src.weight + affacted;
|
|
155
|
-
next.prev = null;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
parent.children.splice(index, 1);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
static attach(des: Node, src: Node, area: AreaValue) {
|
|
162
|
-
const parent = des.parent;
|
|
163
|
-
if (!parent) return;
|
|
164
|
-
const index = parent.children.indexOf(des) as number;
|
|
165
|
-
|
|
166
|
-
switch (AreaType[area]) {
|
|
167
|
-
case 1 - parent.type:
|
|
168
|
-
const insert = index + AreaIndex[area];
|
|
169
|
-
const affacted = 8 * 100 / parent.dimension[parent.type];
|
|
170
|
-
src.weight = des.weight = (des.weight - affacted) / 2;
|
|
171
|
-
src.parent = parent;
|
|
172
|
-
parent.children.splice(insert, 0, src);
|
|
173
|
-
Helper.fixBond(src, parent.type);
|
|
174
|
-
break;
|
|
175
|
-
|
|
176
|
-
case parent.type:
|
|
177
|
-
|
|
178
|
-
const weight = des.weight / 2;
|
|
179
|
-
const children = AreaIndex[area] == 0 ? [src, des] : [des, src];
|
|
180
|
-
const rowcol = new Node(1 - parent.type, des.weight, parent);
|
|
181
|
-
rowcol.children = children;
|
|
182
|
-
parent.children[index] = rowcol;
|
|
183
|
-
|
|
184
|
-
children.forEach((child: Node) => {
|
|
185
|
-
child.weight = weight;
|
|
186
|
-
child.parent = rowcol;
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
this.fixBond(rowcol, parent.type);
|
|
190
|
-
this.fixBond(src, parent.type);
|
|
191
|
-
this.fixBond(des, parent.type);
|
|
192
|
-
break;
|
|
193
|
-
|
|
194
|
-
case Type.Tab:
|
|
195
|
-
des.children.push(...src.children);
|
|
196
|
-
src.children.forEach((child: Node) => {
|
|
197
|
-
child.parent = des;
|
|
198
|
-
})
|
|
199
|
-
break;
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
static fixBond = (node: Node, type: TypeValue) => {
|
|
205
|
-
const parent = node.parent;
|
|
206
|
-
if (!parent) return;
|
|
207
|
-
const index = parent.children.indexOf(node) as number;
|
|
208
|
-
const range = parent.children.length;
|
|
209
|
-
|
|
210
|
-
if (index > 0 && index < range - 1) {
|
|
211
|
-
new Bond(type, parent.children[index - 1], parent.children[index]);
|
|
212
|
-
new Bond(type, parent.children[index], parent.children[index + 1]);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (index === range - 1) {
|
|
216
|
-
new Bond(type, parent.children[index - 1], parent.children[index]);
|
|
217
|
-
parent.children[index].next = null;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (index === 0) {
|
|
221
|
-
new Bond(type, parent.children[index], parent.children[index + 1]);
|
|
222
|
-
parent.children[index].prev = null;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
static getTotalWeight(node: Node): number {
|
|
227
|
-
return node.children.reduce((acc, cur) => acc + (cur.weight), 0) ?? 100;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
static getTotalNodes(node: Node): number {
|
|
231
|
-
|
|
232
|
-
return node.children.length;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
static getSize(node: Node): number {
|
|
236
|
-
return node.dimension[node.type] - ((this.getTotalNodes(node) - 1) * 8);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
static addTab = (child: Node, names: string[]) => {
|
|
240
|
-
if (child.children.length !== 0) return;
|
|
241
|
-
child.type = Type.Tabset;
|
|
242
|
-
const tab = new Node(Type.Tab, 100, child);
|
|
243
|
-
const name = names.shift() as string;
|
|
244
|
-
tab.name = name;
|
|
245
|
-
child.children = [tab];
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
static json = (node: any) => {
|
|
250
|
-
return {
|
|
251
|
-
type: node.type,
|
|
252
|
-
dimension: node.dimension,
|
|
253
|
-
coordinate: node.coordinate,
|
|
254
|
-
name: node.name,
|
|
255
|
-
children: node.children?.map((child: any) => Helper.json(child))
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
package/src/lib/Method.ts
DELETED
package/src/lib/index.ts
DELETED