@effect-tui/react 0.2.1 → 0.2.2
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/dist/src/components/TextInput.js +1 -1
- package/dist/src/components/TextInput.js.map +1 -1
- package/dist/src/console/ConsolePopover.d.ts.map +1 -1
- package/dist/src/console/ConsolePopover.js +6 -6
- package/dist/src/console/ConsolePopover.js.map +1 -1
- package/dist/src/exit.d.ts +7 -0
- package/dist/src/exit.d.ts.map +1 -0
- package/dist/src/exit.js +9 -0
- package/dist/src/exit.js.map +1 -0
- package/dist/src/hooks/use-quit.d.ts.map +1 -1
- package/dist/src/hooks/use-quit.js +2 -1
- package/dist/src/hooks/use-quit.js.map +1 -1
- package/dist/src/hosts/canvas.d.ts +3 -0
- package/dist/src/hosts/canvas.d.ts.map +1 -1
- package/dist/src/hosts/canvas.js +9 -1
- package/dist/src/hosts/canvas.js.map +1 -1
- package/dist/src/renderer-types.d.ts +6 -0
- package/dist/src/renderer-types.d.ts.map +1 -1
- package/dist/src/renderer.d.ts.map +1 -1
- package/dist/src/renderer.js +35 -10
- package/dist/src/renderer.js.map +1 -1
- package/dist/src/utils/flex-layout.d.ts +14 -0
- package/dist/src/utils/flex-layout.d.ts.map +1 -1
- package/dist/src/utils/flex-layout.js +78 -23
- package/dist/src/utils/flex-layout.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/TextInput.tsx +1 -1
- package/src/console/ConsolePopover.tsx +85 -93
- package/src/exit.ts +8 -0
- package/src/hooks/use-quit.ts +2 -1
- package/src/hosts/canvas.ts +11 -0
- package/src/renderer-types.ts +6 -0
- package/src/renderer.ts +35 -9
- package/src/utils/flex-layout.ts +81 -22
|
@@ -5,24 +5,61 @@ import { crossDim, crossPos, crossSize, mainDim, mainPos, mainSize, makeRect } f
|
|
|
5
5
|
/**
|
|
6
6
|
* Measure children along a flex axis.
|
|
7
7
|
* Returns cached sizes and total size.
|
|
8
|
+
*
|
|
9
|
+
* SwiftUI-style measure:
|
|
10
|
+
* 1. First measure all non-greedy children with full available space
|
|
11
|
+
* 2. Then measure greedy children with remaining space
|
|
12
|
+
*
|
|
13
|
+
* This ensures non-greedy elements always get their natural size,
|
|
14
|
+
* even when sibling greedy elements have large content.
|
|
8
15
|
*/
|
|
9
16
|
export function measureFlex(axis, children, spacing, maxMain, maxCross) {
|
|
10
|
-
const sizes =
|
|
11
|
-
let totalMain = 0;
|
|
17
|
+
const sizes = new Array(children.length);
|
|
12
18
|
let maxChildCross = 0;
|
|
19
|
+
const totalSpacing = Math.max(0, (children.length - 1) * spacing);
|
|
20
|
+
// Pass 1: Measure non-greedy children first with full available space
|
|
21
|
+
let nonGreedyTotal = 0;
|
|
13
22
|
for (let i = 0; i < children.length; i++) {
|
|
14
23
|
const child = children[i];
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
const greedyWeight = getGreedyWeight(child);
|
|
25
|
+
if (greedyWeight === 0) {
|
|
26
|
+
// Non-greedy: measure with full available space
|
|
27
|
+
const childMaxW = axis === "vertical" ? maxCross : maxMain;
|
|
28
|
+
const childMaxH = axis === "vertical" ? maxMain : maxCross;
|
|
29
|
+
const size = child.measure(childMaxW, childMaxH);
|
|
30
|
+
sizes[i] = size;
|
|
31
|
+
nonGreedyTotal += mainSize(axis, size);
|
|
32
|
+
maxChildCross = Math.max(maxChildCross, crossSize(axis, size));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Pass 2: Measure greedy children with remaining space
|
|
36
|
+
const remainingForGreedy = Math.max(0, maxMain - nonGreedyTotal - totalSpacing);
|
|
37
|
+
let totalGreedyWeight = 0;
|
|
38
|
+
for (let i = 0; i < children.length; i++) {
|
|
39
|
+
const greedyWeight = getGreedyWeight(children[i]);
|
|
40
|
+
if (greedyWeight > 0)
|
|
41
|
+
totalGreedyWeight += greedyWeight;
|
|
25
42
|
}
|
|
43
|
+
let greedyMeasuredTotal = 0;
|
|
44
|
+
for (let i = 0; i < children.length; i++) {
|
|
45
|
+
const child = children[i];
|
|
46
|
+
const greedyWeight = getGreedyWeight(child);
|
|
47
|
+
if (greedyWeight > 0) {
|
|
48
|
+
// Greedy: measure with proportional share of remaining space
|
|
49
|
+
const greedyMain = totalGreedyWeight > 0
|
|
50
|
+
? (remainingForGreedy * greedyWeight) / totalGreedyWeight
|
|
51
|
+
: remainingForGreedy;
|
|
52
|
+
const childMaxW = axis === "vertical" ? maxCross : greedyMain;
|
|
53
|
+
const childMaxH = axis === "vertical" ? greedyMain : maxCross;
|
|
54
|
+
const size = child.measure(childMaxW, childMaxH);
|
|
55
|
+
sizes[i] = size;
|
|
56
|
+
greedyMeasuredTotal += mainSize(axis, size);
|
|
57
|
+
maxChildCross = Math.max(maxChildCross, crossSize(axis, size));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Calculate total main dimension
|
|
61
|
+
// Use actual measured sizes, not the constraint
|
|
62
|
+
let totalMain = nonGreedyTotal + greedyMeasuredTotal + totalSpacing;
|
|
26
63
|
// Build total size from main/cross dimensions
|
|
27
64
|
const totalW = axis === "vertical" ? maxChildCross : totalMain;
|
|
28
65
|
const totalH = axis === "vertical" ? totalMain : maxChildCross;
|
|
@@ -45,22 +82,33 @@ function getGreedyWeight(child) {
|
|
|
45
82
|
}
|
|
46
83
|
/**
|
|
47
84
|
* Layout children along a flex axis using cached sizes.
|
|
85
|
+
*
|
|
86
|
+
* SwiftUI-style layout:
|
|
87
|
+
* 1. Non-greedy children get their natural (measured) size
|
|
88
|
+
* 2. Greedy children share the REMAINING space proportionally
|
|
89
|
+
*
|
|
90
|
+
* This ensures non-greedy elements (like footers) are always visible,
|
|
91
|
+
* even when greedy elements (like scroll views) have overflowing content.
|
|
48
92
|
*/
|
|
49
93
|
export function layoutFlex(axis, children, cachedSizes, rect, spacing, alignment, stretchCross) {
|
|
50
|
-
// Calculate totals
|
|
51
|
-
let totalNaturalMain = 0;
|
|
52
|
-
let totalGreedyWeight = 0;
|
|
53
94
|
const totalSpacing = Math.max(0, (children.length - 1) * spacing);
|
|
95
|
+
const availableMain = mainDim(axis, rect);
|
|
96
|
+
// Pass 1: Calculate space needed by non-greedy children
|
|
97
|
+
let nonGreedyTotal = 0;
|
|
98
|
+
let totalGreedyWeight = 0;
|
|
54
99
|
for (let i = 0; i < children.length; i++) {
|
|
55
100
|
const child = children[i];
|
|
56
101
|
const size = cachedSizes[i] ?? child.measure(rect.w, rect.h);
|
|
57
|
-
|
|
58
|
-
|
|
102
|
+
const greedyWeight = getGreedyWeight(child);
|
|
103
|
+
if (greedyWeight === 0) {
|
|
104
|
+
// Non-greedy: use natural size
|
|
105
|
+
nonGreedyTotal += mainSize(axis, size);
|
|
106
|
+
}
|
|
107
|
+
totalGreedyWeight += greedyWeight;
|
|
59
108
|
}
|
|
60
|
-
//
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
// Layout children
|
|
109
|
+
// Remaining space for greedy children (after non-greedy + spacing)
|
|
110
|
+
const remainingForGreedy = Math.max(0, availableMain - nonGreedyTotal - totalSpacing);
|
|
111
|
+
// Pass 2: Layout all children
|
|
64
112
|
let curMainPos = mainPos(axis, rect);
|
|
65
113
|
const crossStartPos = crossPos(axis, rect);
|
|
66
114
|
const crossDimVal = crossDim(axis, rect);
|
|
@@ -68,8 +116,15 @@ export function layoutFlex(axis, children, cachedSizes, rect, spacing, alignment
|
|
|
68
116
|
const child = children[i];
|
|
69
117
|
const size = cachedSizes[i] ?? { w: 0, h: 0 };
|
|
70
118
|
const greedyWeight = getGreedyWeight(child);
|
|
71
|
-
|
|
72
|
-
|
|
119
|
+
let childMainDim;
|
|
120
|
+
if (greedyWeight > 0 && totalGreedyWeight > 0) {
|
|
121
|
+
// Greedy: gets proportional share of remaining space
|
|
122
|
+
childMainDim = (remainingForGreedy * greedyWeight) / totalGreedyWeight;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// Non-greedy: gets natural size
|
|
126
|
+
childMainDim = mainSize(axis, size);
|
|
127
|
+
}
|
|
73
128
|
const childCrossDim = crossSize(axis, size);
|
|
74
129
|
// Calculate cross position based on alignment
|
|
75
130
|
let curCrossPos = crossStartPos;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flex-layout.js","sourceRoot":"","sources":["../../../src/utils/flex-layout.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAa,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAYjH
|
|
1
|
+
{"version":3,"file":"flex-layout.js","sourceRoot":"","sources":["../../../src/utils/flex-layout.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAa,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAYjH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAC1B,IAAc,EACd,QAAwB,EACxB,OAAe,EACf,OAAe,EACf,QAAgB;IAEhB,MAAM,KAAK,GAAW,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAChD,IAAI,aAAa,GAAG,CAAC,CAAA;IACrB,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAA;IAEjE,sEAAsE;IACtE,IAAI,cAAc,GAAG,CAAC,CAAA;IACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,MAAM,KAAK,GAAG,QAAQ,CAAC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