regular-layout 0.0.2 → 0.1.0
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 +17 -3
- package/dist/common/{calculate_split.d.ts → calculate_edge.d.ts} +2 -2
- package/dist/common/constants.d.ts +29 -0
- package/dist/common/generate_grid.d.ts +1 -1
- package/dist/common/generate_overlay.d.ts +1 -1
- package/dist/common/layout_config.d.ts +3 -21
- package/dist/common/redistribute_panel_sizes.d.ts +1 -1
- package/dist/extensions.d.ts +6 -8
- package/dist/index.js +9 -9
- package/dist/index.js.map +4 -4
- package/dist/regular-layout-frame.d.ts +4 -1
- package/dist/regular-layout.d.ts +47 -18
- package/package.json +2 -1
- package/src/common/calculate_edge.ts +104 -0
- package/src/common/calculate_intersect.ts +3 -0
- package/src/common/constants.ts +46 -0
- package/src/common/flatten.ts +1 -0
- package/src/common/generate_grid.ts +2 -1
- package/src/common/generate_overlay.ts +8 -5
- package/src/common/insert_child.ts +1 -0
- package/src/common/layout_config.ts +4 -26
- package/src/common/redistribute_panel_sizes.ts +2 -4
- package/src/common/remove_child.ts +1 -0
- package/src/extensions.ts +16 -12
- package/src/regular-layout-frame.ts +111 -59
- package/src/regular-layout.ts +122 -89
- package/src/common/calculate_split.ts +0 -185
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
2
|
-
// ░░░░░░░░▄▀░█▀▄░█▀▀░█▀▀░█░█░█░░░█▀█░█▀▄░░░░░█░░░█▀█░█░█░█▀█░█░█░▀█▀░▀▄░░░░░░░░
|
|
3
|
-
// ░░░░░░░▀▄░░█▀▄░█▀▀░█░█░█░█░█░░░█▀█░█▀▄░▀▀▀░█░░░█▀█░░█░░█░█░█░█░░█░░░▄▀░░░░░░░
|
|
4
|
-
// ░░░░░░░░░▀░▀░▀░▀▀▀░▀▀▀░▀▀▀░▀▀▀░▀░▀░▀░▀░░░░░▀▀▀░▀░▀░░▀░░▀▀▀░▀▀▀░░▀░░▀░░░░░░░░░
|
|
5
|
-
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
6
|
-
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
|
7
|
-
// ┃ * Copyright (c) 2026, the Regular Layout Authors. This file is part * ┃
|
|
8
|
-
// ┃ * of the Regular Layout library, distributed under the terms of the * ┃
|
|
9
|
-
// ┃ * [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). * ┃
|
|
10
|
-
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
11
|
-
|
|
12
|
-
import { calculate_intersection } from "./calculate_intersect";
|
|
13
|
-
import { insert_child } from "./insert_child";
|
|
14
|
-
import {
|
|
15
|
-
SPLIT_EDGE_TOLERANCE,
|
|
16
|
-
type Layout,
|
|
17
|
-
type LayoutPath,
|
|
18
|
-
} from "./layout_config";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Calculates an insertion point (which may involve splitting a single
|
|
22
|
-
* `"child-panel"` into a new `"split-panel"`), based on the cursor position.
|
|
23
|
-
* *
|
|
24
|
-
* @param col - The cursor column.
|
|
25
|
-
* @param row - The cursor row.
|
|
26
|
-
* @param panel - The `Layout` to insert into.
|
|
27
|
-
* @param slot - The slot identifier where the insert should occur
|
|
28
|
-
* @param drop_target - The `LayoutPath` (from `calculateIntersect`) of the
|
|
29
|
-
* panel to either insert next to, or split by.
|
|
30
|
-
* @returns A new `LayoutPath` reflecting the updated (maybe) `"split-panel"`,
|
|
31
|
-
* which is enough to draw the overlay.
|
|
32
|
-
*/
|
|
33
|
-
export function calculate_split(
|
|
34
|
-
col: number,
|
|
35
|
-
row: number,
|
|
36
|
-
panel: Layout,
|
|
37
|
-
slot: string,
|
|
38
|
-
drop_target: LayoutPath,
|
|
39
|
-
): LayoutPath {
|
|
40
|
-
if (
|
|
41
|
-
drop_target.column_offset < SPLIT_EDGE_TOLERANCE ||
|
|
42
|
-
drop_target.column_offset > 1 - SPLIT_EDGE_TOLERANCE
|
|
43
|
-
) {
|
|
44
|
-
if (drop_target.orientation === "horizontal") {
|
|
45
|
-
const is_before = drop_target.column_offset < SPLIT_EDGE_TOLERANCE;
|
|
46
|
-
if (drop_target.path.length === 0) {
|
|
47
|
-
const insert_index = is_before ? 0 : 1;
|
|
48
|
-
const new_panel = insert_child(panel, slot, [insert_index]);
|
|
49
|
-
// When inserting before, point to new panel; when after, keep original
|
|
50
|
-
if (is_before) {
|
|
51
|
-
drop_target = calculate_intersection(col, row, new_panel, false);
|
|
52
|
-
} else {
|
|
53
|
-
const new_drop_target = calculate_intersection(
|
|
54
|
-
col,
|
|
55
|
-
row,
|
|
56
|
-
new_panel,
|
|
57
|
-
false,
|
|
58
|
-
);
|
|
59
|
-
drop_target = {
|
|
60
|
-
...new_drop_target,
|
|
61
|
-
path: [0],
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
const path_without_last = drop_target.path.slice(0, -1);
|
|
66
|
-
const last_index = drop_target.path[drop_target.path.length - 1];
|
|
67
|
-
const insert_index = is_before ? last_index : last_index + 1;
|
|
68
|
-
const new_panel = insert_child(panel, slot, [
|
|
69
|
-
...path_without_last,
|
|
70
|
-
insert_index,
|
|
71
|
-
]);
|
|
72
|
-
// When inserting before, point to new panel; when after, keep original
|
|
73
|
-
if (is_before) {
|
|
74
|
-
drop_target = calculate_intersection(col, row, new_panel, false);
|
|
75
|
-
} else {
|
|
76
|
-
// Keep the original panel but update view_window from new layout
|
|
77
|
-
const new_drop_target = calculate_intersection(
|
|
78
|
-
col,
|
|
79
|
-
row,
|
|
80
|
-
new_panel,
|
|
81
|
-
false,
|
|
82
|
-
);
|
|
83
|
-
drop_target = {
|
|
84
|
-
...new_drop_target,
|
|
85
|
-
path: [...path_without_last, last_index],
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
const insert_index =
|
|
91
|
-
drop_target.column_offset < SPLIT_EDGE_TOLERANCE ? 0 : 1;
|
|
92
|
-
const original_path = drop_target.path;
|
|
93
|
-
const new_panel = insert_child(
|
|
94
|
-
panel,
|
|
95
|
-
slot,
|
|
96
|
-
[...original_path, insert_index],
|
|
97
|
-
"horizontal",
|
|
98
|
-
);
|
|
99
|
-
drop_target = calculate_intersection(col, row, new_panel, false);
|
|
100
|
-
// Override to point to the newly inserted panel
|
|
101
|
-
drop_target = {
|
|
102
|
-
...drop_target,
|
|
103
|
-
slot,
|
|
104
|
-
path: [...original_path, insert_index],
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (drop_target) {
|
|
109
|
-
drop_target.is_edge = true;
|
|
110
|
-
}
|
|
111
|
-
} else if (
|
|
112
|
-
drop_target.row_offset < SPLIT_EDGE_TOLERANCE ||
|
|
113
|
-
drop_target.row_offset > 1 - SPLIT_EDGE_TOLERANCE
|
|
114
|
-
) {
|
|
115
|
-
if (drop_target.orientation === "vertical") {
|
|
116
|
-
const is_before = drop_target.row_offset < SPLIT_EDGE_TOLERANCE;
|
|
117
|
-
if (drop_target.path.length === 0) {
|
|
118
|
-
const insert_index = is_before ? 0 : 1;
|
|
119
|
-
const new_panel = insert_child(panel, slot, [insert_index]);
|
|
120
|
-
// When inserting before, point to new panel; when after, keep original
|
|
121
|
-
if (is_before) {
|
|
122
|
-
drop_target = calculate_intersection(col, row, new_panel, false);
|
|
123
|
-
} else {
|
|
124
|
-
const new_drop_target = calculate_intersection(
|
|
125
|
-
col,
|
|
126
|
-
row,
|
|
127
|
-
new_panel,
|
|
128
|
-
false,
|
|
129
|
-
);
|
|
130
|
-
drop_target = {
|
|
131
|
-
...new_drop_target,
|
|
132
|
-
path: [0],
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
} else {
|
|
136
|
-
const path_without_last = drop_target.path.slice(0, -1);
|
|
137
|
-
const last_index = drop_target.path[drop_target.path.length - 1];
|
|
138
|
-
const insert_index = is_before ? last_index : last_index + 1;
|
|
139
|
-
const new_panel = insert_child(panel, slot, [
|
|
140
|
-
...path_without_last,
|
|
141
|
-
insert_index,
|
|
142
|
-
]);
|
|
143
|
-
// When inserting before, point to new panel; when after, keep original
|
|
144
|
-
if (is_before) {
|
|
145
|
-
drop_target = calculate_intersection(col, row, new_panel, false);
|
|
146
|
-
} else {
|
|
147
|
-
// Keep the original panel but update view_window from new layout
|
|
148
|
-
const new_drop_target = calculate_intersection(
|
|
149
|
-
col,
|
|
150
|
-
row,
|
|
151
|
-
new_panel,
|
|
152
|
-
false,
|
|
153
|
-
);
|
|
154
|
-
drop_target = {
|
|
155
|
-
...new_drop_target,
|
|
156
|
-
path: [...path_without_last, last_index],
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
} else {
|
|
161
|
-
const insert_index =
|
|
162
|
-
drop_target.row_offset < SPLIT_EDGE_TOLERANCE ? 0 : 1;
|
|
163
|
-
const original_path = drop_target.path;
|
|
164
|
-
const new_panel = insert_child(
|
|
165
|
-
panel,
|
|
166
|
-
slot,
|
|
167
|
-
[...original_path, insert_index],
|
|
168
|
-
"vertical",
|
|
169
|
-
);
|
|
170
|
-
drop_target = calculate_intersection(col, row, new_panel, false);
|
|
171
|
-
// Override to point to the newly inserted panel
|
|
172
|
-
drop_target = {
|
|
173
|
-
...drop_target,
|
|
174
|
-
slot,
|
|
175
|
-
path: [...original_path, insert_index],
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (drop_target) {
|
|
180
|
-
drop_target.is_edge = true;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return drop_target;
|
|
185
|
-
}
|