@bevelo/dnd 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/a11y-BOpF8vx8.d.cts +30 -0
- package/dist/a11y-Bbm_a0mw.d.ts +30 -0
- package/dist/index-DDuIvuzA.d.cts +258 -0
- package/dist/index-kH3SGg1R.d.ts +258 -0
- package/dist/index.cjs +413 -0
- package/dist/index.d.cts +139 -0
- package/dist/index.d.ts +139 -0
- package/dist/index.js +357 -0
- package/dist/live/animate-settle.cjs +20 -0
- package/dist/live/animate-settle.d.cts +14 -0
- package/dist/live/animate-settle.d.ts +14 -0
- package/dist/live/animate-settle.js +19 -0
- package/dist/live/flip.cjs +39 -0
- package/dist/live/flip.d.cts +9 -0
- package/dist/live/flip.d.ts +9 -0
- package/dist/live/flip.js +38 -0
- package/dist/live/index.cjs +22 -0
- package/dist/live/index.d.cts +4 -0
- package/dist/live/index.d.ts +4 -0
- package/dist/live/index.js +4 -0
- package/dist/live-BUYwbSUp.cjs +899 -0
- package/dist/live-Clc3aswx.js +840 -0
- package/dist/pure/a11y.cjs +85 -0
- package/dist/pure/a11y.d.cts +2 -0
- package/dist/pure/a11y.d.ts +2 -0
- package/dist/pure/a11y.js +81 -0
- package/dist/pure/apply.cjs +130 -0
- package/dist/pure/apply.d.cts +29 -0
- package/dist/pure/apply.d.ts +29 -0
- package/dist/pure/apply.js +127 -0
- package/dist/pure/reorder.cjs +121 -0
- package/dist/pure/reorder.d.cts +77 -0
- package/dist/pure/reorder.d.ts +77 -0
- package/dist/pure/reorder.js +117 -0
- package/dist/pure/sensors.cjs +243 -0
- package/dist/pure/sensors.d.cts +2 -0
- package/dist/pure/sensors.d.ts +2 -0
- package/dist/pure/sensors.js +240 -0
- package/dist/pure/spatial.cjs +121 -0
- package/dist/pure/spatial.d.cts +64 -0
- package/dist/pure/spatial.d.ts +64 -0
- package/dist/pure/spatial.js +119 -0
- package/dist/pure/state.cjs +15 -0
- package/dist/pure/state.d.cts +2 -0
- package/dist/pure/state.d.ts +2 -0
- package/dist/pure/state.js +1 -0
- package/dist/pure/tree.cjs +164 -0
- package/dist/pure/tree.d.cts +36 -0
- package/dist/pure/tree.d.ts +36 -0
- package/dist/pure/tree.js +161 -0
- package/dist/rows-B2C7Yf94.cjs +56 -0
- package/dist/rows-BIT_Rkhr.js +45 -0
- package/dist/sensors-C9RnMr6P.d.cts +212 -0
- package/dist/sensors-C9RnMr6P.d.ts +212 -0
- package/dist/settle-BiwZ0ZDt.js +235 -0
- package/dist/settle-COFsW7ul.cjs +282 -0
- package/dist/settle-Dl5Y9uOw.d.ts +59 -0
- package/dist/settle-DzdqbH4S.d.cts +59 -0
- package/dist/state-BEKGNZY1.d.cts +323 -0
- package/dist/state-BEKGNZY1.d.ts +323 -0
- package/dist/state-BK9W_RZn.cjs +672 -0
- package/dist/state-CYXS6GIb.js +595 -0
- package/package.json +89 -3
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_rows = require("../rows-B2C7Yf94.cjs");
|
|
3
|
+
// src/pure/tree.ts
|
|
4
|
+
/**
|
|
5
|
+
* The drop for a gap over the visible rows minus the carried keys. The depth is `want`
|
|
6
|
+
* clamped between the row below (it must stay a child of something above) and one deeper
|
|
7
|
+
* than the row above, capped by `maxDepth` minus the carried subtree's height. From there the
|
|
8
|
+
* depth walks down until `canNest` accepts the parent. Null when no depth is allowed.
|
|
9
|
+
*/
|
|
10
|
+
function projectTree(input) {
|
|
11
|
+
const { track, rules, source } = input;
|
|
12
|
+
const rows = require_rows.rowsOf(track, source.carried);
|
|
13
|
+
const gap = Math.min(Math.max(0, input.gap), rows.count);
|
|
14
|
+
const depthAt = (row) => rules.depthOf(rows.key(row));
|
|
15
|
+
const above = gap > 0 ? depthAt(gap - 1) : -1;
|
|
16
|
+
const below = gap < rows.count ? depthAt(gap) : 0;
|
|
17
|
+
const limit = (rules.maxDepth ?? Number.POSITIVE_INFINITY) - source.height;
|
|
18
|
+
const max = Math.min(above + 1, limit);
|
|
19
|
+
const min = below;
|
|
20
|
+
if (max < min) return null;
|
|
21
|
+
const want = Number.isFinite(input.want) ? Math.round(input.want) : min;
|
|
22
|
+
for (let depth = Math.min(Math.max(want, min), max); depth >= min; depth -= 1) {
|
|
23
|
+
const parentId = parentAt(rows, depthAt, gap, depth);
|
|
24
|
+
if (rules.canNest !== void 0 && !rules.canNest(parentId, source.ids)) continue;
|
|
25
|
+
return {
|
|
26
|
+
parentId,
|
|
27
|
+
before: gap < rows.count && below === depth ? rows.key(gap) : null,
|
|
28
|
+
depth,
|
|
29
|
+
index: gap
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
/** The nearest row above `gap` one level shallower than `depth`; null at depth 0. */
|
|
35
|
+
function parentAt(rows, depthAt, gap, depth) {
|
|
36
|
+
if (depth === 0) return null;
|
|
37
|
+
for (let row = gap - 1; row >= 0; row -= 1) if (depthAt(row) === depth - 1) return rows.key(row);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
/** One past the last visible descendant of the row at `index`. */
|
|
41
|
+
function subtreeEnd(track, depthOf, index) {
|
|
42
|
+
if (index < 0 || index >= track.count) return index;
|
|
43
|
+
const depth = depthOf(track.keyAt(index));
|
|
44
|
+
let end = index + 1;
|
|
45
|
+
while (end < track.count && depthOf(track.keyAt(end)) > depth) end += 1;
|
|
46
|
+
return end;
|
|
47
|
+
}
|
|
48
|
+
/** Where the row at `index` sits by key: its parent and its next sibling that is not carried. */
|
|
49
|
+
function treePlacement(zone, index, carried) {
|
|
50
|
+
const { track, depthOf } = zone;
|
|
51
|
+
const depth = depthOf(track.keyAt(index));
|
|
52
|
+
let parentId = null;
|
|
53
|
+
for (let row = index - 1; row >= 0 && depth > 0; row -= 1) {
|
|
54
|
+
const key = track.keyAt(row);
|
|
55
|
+
if (depthOf(key) === depth - 1) {
|
|
56
|
+
parentId = key;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
let next = subtreeEnd(track, depthOf, index);
|
|
61
|
+
while (next < track.count) {
|
|
62
|
+
const key = track.keyAt(next);
|
|
63
|
+
const nextDepth = depthOf(key);
|
|
64
|
+
if (nextDepth < depth) break;
|
|
65
|
+
if (nextDepth === depth && !carried.has(key)) return {
|
|
66
|
+
parentId,
|
|
67
|
+
before: key
|
|
68
|
+
};
|
|
69
|
+
next = subtreeEnd(track, depthOf, next);
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
parentId,
|
|
73
|
+
before: null
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function treeSiblings(zone, at, depth, carried) {
|
|
77
|
+
const { track, depthOf } = zone;
|
|
78
|
+
let before = 0;
|
|
79
|
+
for (let row = at - 1; row >= 0; row -= 1) {
|
|
80
|
+
const key = track.keyAt(row);
|
|
81
|
+
if (carried.has(key)) continue;
|
|
82
|
+
const d = depthOf(key);
|
|
83
|
+
if (d < depth) break;
|
|
84
|
+
if (d === depth) before += 1;
|
|
85
|
+
}
|
|
86
|
+
let after = 0;
|
|
87
|
+
for (let row = at; row < track.count; row += 1) {
|
|
88
|
+
const key = track.keyAt(row);
|
|
89
|
+
if (carried.has(key)) continue;
|
|
90
|
+
const d = depthOf(key);
|
|
91
|
+
if (d < depth) break;
|
|
92
|
+
if (d === depth) after += 1;
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
position: before + 1,
|
|
96
|
+
total: before + after
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The tree maths a tree zone carries. A zone spec or a `TreeZone` names it, so the drag
|
|
101
|
+
* reducer reaches tree projection, depth intent and subtree carry only through a zone that
|
|
102
|
+
* is a tree.
|
|
103
|
+
*/
|
|
104
|
+
const outline = {
|
|
105
|
+
zone(base, rules) {
|
|
106
|
+
return {
|
|
107
|
+
kind: "tree",
|
|
108
|
+
...base,
|
|
109
|
+
outline,
|
|
110
|
+
get indent() {
|
|
111
|
+
return rules().indent;
|
|
112
|
+
},
|
|
113
|
+
get maxDepth() {
|
|
114
|
+
return rules().maxDepth;
|
|
115
|
+
},
|
|
116
|
+
depthOf: (key) => rules().depthOf(key),
|
|
117
|
+
canNest: (parentId, ids) => rules().canNest?.(parentId, ids) ?? true
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
subtree(zone, index) {
|
|
121
|
+
const { track, depthOf } = zone;
|
|
122
|
+
const end = subtreeEnd(track, depthOf, index);
|
|
123
|
+
let height = 0;
|
|
124
|
+
for (let at = index + 1; at < end; at += 1) height = Math.max(height, depthOf(track.keyAt(at)) - depthOf(track.keyAt(index)));
|
|
125
|
+
return {
|
|
126
|
+
end,
|
|
127
|
+
height
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
placement: treePlacement,
|
|
131
|
+
siblings: treeSiblings,
|
|
132
|
+
gap(zone, gap, want, source, carried) {
|
|
133
|
+
const projection = projectTree({
|
|
134
|
+
track: zone.track,
|
|
135
|
+
rules: zone,
|
|
136
|
+
gap,
|
|
137
|
+
want,
|
|
138
|
+
source: {
|
|
139
|
+
ids: source.ids,
|
|
140
|
+
carried,
|
|
141
|
+
height: source.height
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return projection === null ? null : {
|
|
145
|
+
kind: "gap",
|
|
146
|
+
zoneId: zone.id,
|
|
147
|
+
placement: {
|
|
148
|
+
parentId: projection.parentId,
|
|
149
|
+
before: projection.before
|
|
150
|
+
},
|
|
151
|
+
index: projection.index,
|
|
152
|
+
depth: projection.depth
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
depth(zone, pointer, source, rtl) {
|
|
156
|
+
if (!(zone.indent > 0)) return source.depth;
|
|
157
|
+
const cross = (point) => zone.axis === "x" ? point.y : point.x;
|
|
158
|
+
const levels = Math.round((cross(pointer) - cross(source.grab) - cross(zone.origin)) / zone.indent);
|
|
159
|
+
return source.depth + (rtl ? -levels : levels);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
exports.outline = outline;
|
|
163
|
+
exports.projectTree = projectTree;
|
|
164
|
+
exports.subtreeEnd = subtreeEnd;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { D as TreeRules, x as Outline } from "../state-BEKGNZY1.cjs";
|
|
2
|
+
import { ItemTrack } from "@bevelo/runtime/geometry";
|
|
3
|
+
/** A projected drop: the parent and next sibling by key, the depth, and the gap index. */
|
|
4
|
+
export interface TreeProjection {
|
|
5
|
+
readonly parentId: string | null;
|
|
6
|
+
readonly before: string | null;
|
|
7
|
+
readonly depth: number;
|
|
8
|
+
readonly index: number;
|
|
9
|
+
}
|
|
10
|
+
/** What projection needs from the drag: the result ids, every carried key, and the subtree height. */
|
|
11
|
+
export interface TreeProjectionSource {
|
|
12
|
+
readonly ids: readonly string[];
|
|
13
|
+
readonly carried: ReadonlySet<string>;
|
|
14
|
+
readonly height: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The drop for a gap over the visible rows minus the carried keys. The depth is `want`
|
|
18
|
+
* clamped between the row below (it must stay a child of something above) and one deeper
|
|
19
|
+
* than the row above, capped by `maxDepth` minus the carried subtree's height. From there the
|
|
20
|
+
* depth walks down until `canNest` accepts the parent. Null when no depth is allowed.
|
|
21
|
+
*/
|
|
22
|
+
export declare function projectTree(input: {
|
|
23
|
+
readonly track: ItemTrack;
|
|
24
|
+
readonly rules: TreeRules;
|
|
25
|
+
readonly gap: number;
|
|
26
|
+
readonly want: number;
|
|
27
|
+
readonly source: TreeProjectionSource;
|
|
28
|
+
}): TreeProjection | null;
|
|
29
|
+
/** One past the last visible descendant of the row at `index`. */
|
|
30
|
+
export declare function subtreeEnd(track: ItemTrack, depthOf: (key: string) => number, index: number): number;
|
|
31
|
+
/**
|
|
32
|
+
* The tree maths a tree zone carries. A zone spec or a `TreeZone` names it, so the drag
|
|
33
|
+
* reducer reaches tree projection, depth intent and subtree carry only through a zone that
|
|
34
|
+
* is a tree.
|
|
35
|
+
*/
|
|
36
|
+
export declare const outline: Outline;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { D as TreeRules, x as Outline } from "../state-BEKGNZY1.js";
|
|
2
|
+
import { ItemTrack } from "@bevelo/runtime/geometry";
|
|
3
|
+
/** A projected drop: the parent and next sibling by key, the depth, and the gap index. */
|
|
4
|
+
export interface TreeProjection {
|
|
5
|
+
readonly parentId: string | null;
|
|
6
|
+
readonly before: string | null;
|
|
7
|
+
readonly depth: number;
|
|
8
|
+
readonly index: number;
|
|
9
|
+
}
|
|
10
|
+
/** What projection needs from the drag: the result ids, every carried key, and the subtree height. */
|
|
11
|
+
export interface TreeProjectionSource {
|
|
12
|
+
readonly ids: readonly string[];
|
|
13
|
+
readonly carried: ReadonlySet<string>;
|
|
14
|
+
readonly height: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The drop for a gap over the visible rows minus the carried keys. The depth is `want`
|
|
18
|
+
* clamped between the row below (it must stay a child of something above) and one deeper
|
|
19
|
+
* than the row above, capped by `maxDepth` minus the carried subtree's height. From there the
|
|
20
|
+
* depth walks down until `canNest` accepts the parent. Null when no depth is allowed.
|
|
21
|
+
*/
|
|
22
|
+
export declare function projectTree(input: {
|
|
23
|
+
readonly track: ItemTrack;
|
|
24
|
+
readonly rules: TreeRules;
|
|
25
|
+
readonly gap: number;
|
|
26
|
+
readonly want: number;
|
|
27
|
+
readonly source: TreeProjectionSource;
|
|
28
|
+
}): TreeProjection | null;
|
|
29
|
+
/** One past the last visible descendant of the row at `index`. */
|
|
30
|
+
export declare function subtreeEnd(track: ItemTrack, depthOf: (key: string) => number, index: number): number;
|
|
31
|
+
/**
|
|
32
|
+
* The tree maths a tree zone carries. A zone spec or a `TreeZone` names it, so the drag
|
|
33
|
+
* reducer reaches tree projection, depth intent and subtree carry only through a zone that
|
|
34
|
+
* is a tree.
|
|
35
|
+
*/
|
|
36
|
+
export declare const outline: Outline;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { n as rowsOf } from "../rows-BIT_Rkhr.js";
|
|
2
|
+
// src/pure/tree.ts
|
|
3
|
+
/**
|
|
4
|
+
* The drop for a gap over the visible rows minus the carried keys. The depth is `want`
|
|
5
|
+
* clamped between the row below (it must stay a child of something above) and one deeper
|
|
6
|
+
* than the row above, capped by `maxDepth` minus the carried subtree's height. From there the
|
|
7
|
+
* depth walks down until `canNest` accepts the parent. Null when no depth is allowed.
|
|
8
|
+
*/
|
|
9
|
+
function projectTree(input) {
|
|
10
|
+
const { track, rules, source } = input;
|
|
11
|
+
const rows = rowsOf(track, source.carried);
|
|
12
|
+
const gap = Math.min(Math.max(0, input.gap), rows.count);
|
|
13
|
+
const depthAt = (row) => rules.depthOf(rows.key(row));
|
|
14
|
+
const above = gap > 0 ? depthAt(gap - 1) : -1;
|
|
15
|
+
const below = gap < rows.count ? depthAt(gap) : 0;
|
|
16
|
+
const limit = (rules.maxDepth ?? Number.POSITIVE_INFINITY) - source.height;
|
|
17
|
+
const max = Math.min(above + 1, limit);
|
|
18
|
+
const min = below;
|
|
19
|
+
if (max < min) return null;
|
|
20
|
+
const want = Number.isFinite(input.want) ? Math.round(input.want) : min;
|
|
21
|
+
for (let depth = Math.min(Math.max(want, min), max); depth >= min; depth -= 1) {
|
|
22
|
+
const parentId = parentAt(rows, depthAt, gap, depth);
|
|
23
|
+
if (rules.canNest !== void 0 && !rules.canNest(parentId, source.ids)) continue;
|
|
24
|
+
return {
|
|
25
|
+
parentId,
|
|
26
|
+
before: gap < rows.count && below === depth ? rows.key(gap) : null,
|
|
27
|
+
depth,
|
|
28
|
+
index: gap
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
/** The nearest row above `gap` one level shallower than `depth`; null at depth 0. */
|
|
34
|
+
function parentAt(rows, depthAt, gap, depth) {
|
|
35
|
+
if (depth === 0) return null;
|
|
36
|
+
for (let row = gap - 1; row >= 0; row -= 1) if (depthAt(row) === depth - 1) return rows.key(row);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
/** One past the last visible descendant of the row at `index`. */
|
|
40
|
+
function subtreeEnd(track, depthOf, index) {
|
|
41
|
+
if (index < 0 || index >= track.count) return index;
|
|
42
|
+
const depth = depthOf(track.keyAt(index));
|
|
43
|
+
let end = index + 1;
|
|
44
|
+
while (end < track.count && depthOf(track.keyAt(end)) > depth) end += 1;
|
|
45
|
+
return end;
|
|
46
|
+
}
|
|
47
|
+
/** Where the row at `index` sits by key: its parent and its next sibling that is not carried. */
|
|
48
|
+
function treePlacement(zone, index, carried) {
|
|
49
|
+
const { track, depthOf } = zone;
|
|
50
|
+
const depth = depthOf(track.keyAt(index));
|
|
51
|
+
let parentId = null;
|
|
52
|
+
for (let row = index - 1; row >= 0 && depth > 0; row -= 1) {
|
|
53
|
+
const key = track.keyAt(row);
|
|
54
|
+
if (depthOf(key) === depth - 1) {
|
|
55
|
+
parentId = key;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let next = subtreeEnd(track, depthOf, index);
|
|
60
|
+
while (next < track.count) {
|
|
61
|
+
const key = track.keyAt(next);
|
|
62
|
+
const nextDepth = depthOf(key);
|
|
63
|
+
if (nextDepth < depth) break;
|
|
64
|
+
if (nextDepth === depth && !carried.has(key)) return {
|
|
65
|
+
parentId,
|
|
66
|
+
before: key
|
|
67
|
+
};
|
|
68
|
+
next = subtreeEnd(track, depthOf, next);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
parentId,
|
|
72
|
+
before: null
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function treeSiblings(zone, at, depth, carried) {
|
|
76
|
+
const { track, depthOf } = zone;
|
|
77
|
+
let before = 0;
|
|
78
|
+
for (let row = at - 1; row >= 0; row -= 1) {
|
|
79
|
+
const key = track.keyAt(row);
|
|
80
|
+
if (carried.has(key)) continue;
|
|
81
|
+
const d = depthOf(key);
|
|
82
|
+
if (d < depth) break;
|
|
83
|
+
if (d === depth) before += 1;
|
|
84
|
+
}
|
|
85
|
+
let after = 0;
|
|
86
|
+
for (let row = at; row < track.count; row += 1) {
|
|
87
|
+
const key = track.keyAt(row);
|
|
88
|
+
if (carried.has(key)) continue;
|
|
89
|
+
const d = depthOf(key);
|
|
90
|
+
if (d < depth) break;
|
|
91
|
+
if (d === depth) after += 1;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
position: before + 1,
|
|
95
|
+
total: before + after
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The tree maths a tree zone carries. A zone spec or a `TreeZone` names it, so the drag
|
|
100
|
+
* reducer reaches tree projection, depth intent and subtree carry only through a zone that
|
|
101
|
+
* is a tree.
|
|
102
|
+
*/
|
|
103
|
+
const outline = {
|
|
104
|
+
zone(base, rules) {
|
|
105
|
+
return {
|
|
106
|
+
kind: "tree",
|
|
107
|
+
...base,
|
|
108
|
+
outline,
|
|
109
|
+
get indent() {
|
|
110
|
+
return rules().indent;
|
|
111
|
+
},
|
|
112
|
+
get maxDepth() {
|
|
113
|
+
return rules().maxDepth;
|
|
114
|
+
},
|
|
115
|
+
depthOf: (key) => rules().depthOf(key),
|
|
116
|
+
canNest: (parentId, ids) => rules().canNest?.(parentId, ids) ?? true
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
subtree(zone, index) {
|
|
120
|
+
const { track, depthOf } = zone;
|
|
121
|
+
const end = subtreeEnd(track, depthOf, index);
|
|
122
|
+
let height = 0;
|
|
123
|
+
for (let at = index + 1; at < end; at += 1) height = Math.max(height, depthOf(track.keyAt(at)) - depthOf(track.keyAt(index)));
|
|
124
|
+
return {
|
|
125
|
+
end,
|
|
126
|
+
height
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
placement: treePlacement,
|
|
130
|
+
siblings: treeSiblings,
|
|
131
|
+
gap(zone, gap, want, source, carried) {
|
|
132
|
+
const projection = projectTree({
|
|
133
|
+
track: zone.track,
|
|
134
|
+
rules: zone,
|
|
135
|
+
gap,
|
|
136
|
+
want,
|
|
137
|
+
source: {
|
|
138
|
+
ids: source.ids,
|
|
139
|
+
carried,
|
|
140
|
+
height: source.height
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return projection === null ? null : {
|
|
144
|
+
kind: "gap",
|
|
145
|
+
zoneId: zone.id,
|
|
146
|
+
placement: {
|
|
147
|
+
parentId: projection.parentId,
|
|
148
|
+
before: projection.before
|
|
149
|
+
},
|
|
150
|
+
index: projection.index,
|
|
151
|
+
depth: projection.depth
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
depth(zone, pointer, source, rtl) {
|
|
155
|
+
if (!(zone.indent > 0)) return source.depth;
|
|
156
|
+
const cross = (point) => zone.axis === "x" ? point.y : point.x;
|
|
157
|
+
const levels = Math.round((cross(pointer) - cross(source.grab) - cross(zone.origin)) / zone.indent);
|
|
158
|
+
return source.depth + (rtl ? -levels : levels);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
export { outline, projectTree, subtreeEnd };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/pure/rows.ts
|
|
2
|
+
function buildRows(track, slots) {
|
|
3
|
+
const only = slots.length === 1 ? slots[0] : -1;
|
|
4
|
+
const index = only >= 0 ? (r) => r >= only ? r + 1 : r : (r) => {
|
|
5
|
+
let at = r;
|
|
6
|
+
for (const s of slots) if (s <= at) at += 1;
|
|
7
|
+
else break;
|
|
8
|
+
return at;
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
count: track.count - slots.length,
|
|
12
|
+
index,
|
|
13
|
+
key: (r) => track.keyAt(index(r)),
|
|
14
|
+
rankOf: only >= 0 ? (at) => at > only ? at - 1 : at : (at) => {
|
|
15
|
+
let b = 0;
|
|
16
|
+
for (const s of slots) if (s < at) b += 1;
|
|
17
|
+
else break;
|
|
18
|
+
return at - b;
|
|
19
|
+
},
|
|
20
|
+
hasCarried: only >= 0 ? (s) => s === only : (s) => slots.includes(s),
|
|
21
|
+
carried: slots
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
let cTrack;
|
|
25
|
+
let cKey;
|
|
26
|
+
let cRows;
|
|
27
|
+
function cachedRows(track, keyObj, items) {
|
|
28
|
+
if (track === cTrack && keyObj === cKey && cRows !== void 0) return cRows;
|
|
29
|
+
const slots = [];
|
|
30
|
+
for (const key of items) {
|
|
31
|
+
const idx = track.indexOf(key);
|
|
32
|
+
if (idx >= 0) slots.push(idx);
|
|
33
|
+
}
|
|
34
|
+
if (slots.length > 1) slots.sort((a, b) => a - b);
|
|
35
|
+
cTrack = track;
|
|
36
|
+
cKey = keyObj;
|
|
37
|
+
return cRows = buildRows(track, slots);
|
|
38
|
+
}
|
|
39
|
+
function rowsOf(track, carried) {
|
|
40
|
+
return cachedRows(track, carried, carried);
|
|
41
|
+
}
|
|
42
|
+
function rowsFor(track, carriedKeys) {
|
|
43
|
+
return cachedRows(track, carriedKeys, carriedKeys);
|
|
44
|
+
}
|
|
45
|
+
Object.defineProperty(exports, "rowsFor", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function() {
|
|
48
|
+
return rowsFor;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "rowsOf", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function() {
|
|
54
|
+
return rowsOf;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/pure/rows.ts
|
|
2
|
+
function buildRows(track, slots) {
|
|
3
|
+
const only = slots.length === 1 ? slots[0] : -1;
|
|
4
|
+
const index = only >= 0 ? (r) => r >= only ? r + 1 : r : (r) => {
|
|
5
|
+
let at = r;
|
|
6
|
+
for (const s of slots) if (s <= at) at += 1;
|
|
7
|
+
else break;
|
|
8
|
+
return at;
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
count: track.count - slots.length,
|
|
12
|
+
index,
|
|
13
|
+
key: (r) => track.keyAt(index(r)),
|
|
14
|
+
rankOf: only >= 0 ? (at) => at > only ? at - 1 : at : (at) => {
|
|
15
|
+
let b = 0;
|
|
16
|
+
for (const s of slots) if (s < at) b += 1;
|
|
17
|
+
else break;
|
|
18
|
+
return at - b;
|
|
19
|
+
},
|
|
20
|
+
hasCarried: only >= 0 ? (s) => s === only : (s) => slots.includes(s),
|
|
21
|
+
carried: slots
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
let cTrack;
|
|
25
|
+
let cKey;
|
|
26
|
+
let cRows;
|
|
27
|
+
function cachedRows(track, keyObj, items) {
|
|
28
|
+
if (track === cTrack && keyObj === cKey && cRows !== void 0) return cRows;
|
|
29
|
+
const slots = [];
|
|
30
|
+
for (const key of items) {
|
|
31
|
+
const idx = track.indexOf(key);
|
|
32
|
+
if (idx >= 0) slots.push(idx);
|
|
33
|
+
}
|
|
34
|
+
if (slots.length > 1) slots.sort((a, b) => a - b);
|
|
35
|
+
cTrack = track;
|
|
36
|
+
cKey = keyObj;
|
|
37
|
+
return cRows = buildRows(track, slots);
|
|
38
|
+
}
|
|
39
|
+
function rowsOf(track, carried) {
|
|
40
|
+
return cachedRows(track, carried, carried);
|
|
41
|
+
}
|
|
42
|
+
function rowsFor(track, carriedKeys) {
|
|
43
|
+
return cachedRows(track, carriedKeys, carriedKeys);
|
|
44
|
+
}
|
|
45
|
+
export { rowsOf as n, rowsFor as t };
|