gloomberb 0.19.4 → 0.19.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/package.json +3 -1
- package/src/cli/commands/command-utils.ts +4 -0
- package/src/cli/commands/market.ts +119 -27
- package/src/cli/commands/search.ts +1 -1
- package/src/cli/commands/ticker.ts +10 -6
- package/src/cli/currency-name-hint.ts +60 -0
- package/src/cli/history-rows.ts +18 -1
- package/src/cli/known-gaps.ts +17 -2
- package/src/cli/not-a-ticker.ts +5 -3
- package/src/cli/pane-functions/catalog.ts +9 -1
- package/src/cli/pane-functions/headless.ts +7 -3
- package/src/cli/pane-functions/market-session.ts +6 -7
- package/src/cli/series-search.ts +4 -5
- package/src/components/chart/composite/panel-bitmap.ts +28 -2
- package/src/components/chart/composite/time-axis.ts +17 -2
- package/src/components/layout/shell/active-drag.ts +38 -7
- package/src/components/layout/shell/drag/magnets.ts +106 -0
- package/src/components/layout/window-controls.tsx +96 -35
- package/src/components/layout/window-fullscreen.ts +20 -0
- package/src/components/quote-flash.ts +36 -32
- package/src/market-data/coordinator/events.ts +17 -1
- package/src/market-data/frame-scheduler.ts +47 -10
- package/src/market-data/frame-wake.ts +74 -0
- package/src/market-data/futures-board.ts +7 -6
- package/src/market-data/hooks.tsx +12 -3
- package/src/market-data/performance.ts +78 -9
- package/src/market-data/request-types.ts +6 -3
- package/src/plugins/builtin/alerts/cli.ts +2 -1
- package/src/plugins/builtin/analytics/risk-evidence.ts +1 -0
- package/src/plugins/builtin/attention/evidence.ts +1 -1
- package/src/plugins/builtin/awards/client.ts +1 -1
- package/src/plugins/builtin/awards/evidence.ts +1 -1
- package/src/plugins/builtin/awards/pane.tsx +2 -1
- package/src/plugins/builtin/bond-calculator/math.ts +1 -1
- package/src/plugins/builtin/broker-manager/footer.ts +3 -2
- package/src/plugins/builtin/broker-manager/index.tsx +2 -1
- package/src/plugins/builtin/broker-manager/keyboard.ts +2 -1
- package/src/plugins/builtin/catalysts/evidence.ts +1 -1
- package/src/plugins/builtin/catalysts/pane.tsx +2 -1
- package/src/plugins/builtin/chart-composer/headless.ts +40 -1
- package/src/plugins/builtin/cloud-tweets/table.tsx +3 -2
- package/src/plugins/builtin/comment-letters/client.ts +2 -1
- package/src/plugins/builtin/company-kpis/client.ts +1 -1
- package/src/plugins/builtin/company-kpis/pane.tsx +2 -1
- package/src/plugins/builtin/company-kpis/screenshot-evidence.ts +3 -2
- package/src/plugins/builtin/cot/headless.ts +9 -3
- package/src/plugins/builtin/cot/model.ts +44 -3
- package/src/plugins/builtin/credit-documents/client.ts +1 -1
- package/src/plugins/builtin/credit-documents/evidence.ts +1 -1
- package/src/plugins/builtin/credit-documents/pane.tsx +2 -1
- package/src/plugins/builtin/earnings-calls/pane.tsx +1 -1
- package/src/plugins/builtin/earnings-ripple/index.tsx +6 -1
- package/src/plugins/builtin/econ/calendar-model.ts +2 -0
- package/src/plugins/builtin/econ/fred-catalog.ts +5 -5
- package/src/plugins/builtin/econ/print-watch.ts +3 -1
- package/src/plugins/builtin/futures/series.ts +16 -1
- package/src/plugins/builtin/fx-matrix/headless.ts +4 -2
- package/src/plugins/builtin/fx-matrix/index.tsx +37 -3
- package/src/plugins/builtin/fx-matrix/pairs.ts +15 -0
- package/src/plugins/builtin/gpu/headless.ts +2 -1
- package/src/plugins/builtin/help/function-card.tsx +2 -1
- package/src/plugins/builtin/help/index.tsx +2 -1
- package/src/plugins/builtin/insider/display.ts +45 -6
- package/src/plugins/builtin/ipo-calendar/model.ts +2 -0
- package/src/plugins/builtin/iv-history/client.ts +2 -1
- package/src/plugins/builtin/iv-history/headless.ts +2 -1
- package/src/plugins/builtin/jobs/pages.ts +4 -4
- package/src/plugins/builtin/kelly-sizer/headless.ts +2 -1
- package/src/plugins/builtin/market-heatmap/index.tsx +2 -1
- package/src/plugins/builtin/members/client.ts +1 -1
- package/src/plugins/builtin/mna/distress/client.ts +1 -0
- package/src/plugins/builtin/mna/pane.tsx +4 -1
- package/src/plugins/builtin/options/market-reference.ts +1 -1
- package/src/plugins/builtin/options/open-interest-as-of.ts +3 -1
- package/src/plugins/builtin/options/view.tsx +2 -1
- package/src/plugins/builtin/options-calculator/evidence.ts +1 -1
- package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +1 -1
- package/src/plugins/builtin/options-scenario/csp-screen.ts +8 -4
- package/src/plugins/builtin/options-scenario/csp.ts +28 -9
- package/src/plugins/builtin/options-scenario/evidence.ts +5 -4
- package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
- package/src/plugins/builtin/perps/client.ts +1 -1
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -1
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +7 -3
- package/src/plugins/builtin/portfolio-list/use-throttled-memo.ts +10 -19
- package/src/plugins/builtin/research/analyst-model.ts +1 -0
- package/src/plugins/builtin/research/equity-diagnostic-pane.tsx +2 -1
- package/src/plugins/builtin/research/index.tsx +1 -0
- package/src/plugins/builtin/research/relative-valuation-currency.ts +1 -1
- package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -1
- package/src/plugins/builtin/research-search/command-bar-search.ts +3 -1
- package/src/plugins/builtin/research-search/snippet.ts +1 -0
- package/src/plugins/builtin/revenue-breakdown/client.ts +3 -2
- package/src/plugins/builtin/seasonality/headless.ts +2 -1
- package/src/plugins/builtin/sec/command-bar-search.ts +3 -2
- package/src/plugins/builtin/sec/index.tsx +7 -4
- package/src/plugins/builtin/sec/row-summaries.ts +28 -12
- package/src/plugins/builtin/short-interest/watch-client.ts +2 -1
- package/src/plugins/builtin/social-mentions/client.ts +2 -1
- package/src/plugins/builtin/supply-chain/client.ts +1 -1
- package/src/plugins/builtin/supply-chain/evidence.ts +1 -1
- package/src/plugins/builtin/supply-chain/graph-pane.tsx +2 -1
- package/src/plugins/builtin/supply-chain/pane.tsx +2 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +1 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +24 -4
- package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +1 -1
- package/src/plugins/builtin/time-sales/client.ts +1 -0
- package/src/plugins/builtin/vol-surface/client.ts +2 -1
- package/src/plugins/builtin/yield-curve/headless.ts +3 -1
- package/src/portfolio/column-values.ts +76 -10
- package/src/renderers/dom/host/box.tsx +204 -176
- package/src/renderers/dom/host/style.ts +49 -20
- package/src/renderers/dom/host/text.tsx +3 -2
- package/src/renderers/electrobun/bun/desktop/backend.ts +2 -0
- package/src/renderers/electrobun/bun/desktop/host-requests.ts +25 -1
- package/src/renderers/electrobun/bun/desktop/relaunch.ts +9 -1
- package/src/renderers/electrobun/bun/desktop/windows-script.ts +9 -6
- package/src/renderers/electrobun/bun/window/windows-native.ts +26 -1
- package/src/renderers/electrobun/shared/protocol.ts +6 -0
- package/src/renderers/electrobun/view/ui-host.tsx +7 -0
- package/src/renderers/electrobun/view/window-fullscreen.ts +10 -3
- package/src/sources/provider-router/index.ts +7 -1
- package/src/time-series/price-units.ts +11 -0
- package/src/ui/host.tsx +2 -0
- package/src/utils/currency-names.ts +20 -0
- package/src/utils/currency-pair.ts +6 -0
- package/src/utils/exchange-rate-snapshot.ts +20 -2
- package/src/utils/fx-market-hours.ts +43 -0
|
@@ -26,7 +26,7 @@ import { hideDragShield, showDragShield } from "./drag-shield";
|
|
|
26
26
|
import { applyLiveFrame } from "./live-frame";
|
|
27
27
|
import { observeCellSize } from "./size-observer";
|
|
28
28
|
import { fitSurface, surfaceFollows, trackSurface } from "./surface-fit";
|
|
29
|
-
import { cleanDomProps, commonStyle } from "./style";
|
|
29
|
+
import { cleanDomProps, commonStyle, useStableStyle } from "./style";
|
|
30
30
|
|
|
31
31
|
/** Farther than this from the pointer, in px, a predicted point is noise. */
|
|
32
32
|
const MAX_PREDICTION_PX = 48;
|
|
@@ -74,6 +74,17 @@ function releasePointer(captured: { element: HTMLElement; pointerId: number } |
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
interface BoxHandlers {
|
|
78
|
+
cancelPendingFrame(): void;
|
|
79
|
+
handleMouseDown(event: MouseEvent): void;
|
|
80
|
+
handlePointerDown(event: PointerEvent): void;
|
|
81
|
+
handleMouseDownCapture(event: MouseEvent): void;
|
|
82
|
+
handleMouseOver(event: MouseEvent): void;
|
|
83
|
+
handleMouseOut(event: MouseEvent): void;
|
|
84
|
+
handleMouseMove(event: MouseEvent): void;
|
|
85
|
+
handleMouseUp(event: MouseEvent): void;
|
|
86
|
+
}
|
|
87
|
+
|
|
77
88
|
export const WebBox = forwardRef<HTMLDivElement, Record<string, unknown> & { children?: ReactNode }>(
|
|
78
89
|
function WebBox({ children, ...props }, ref: Ref<HTMLDivElement>) {
|
|
79
90
|
const elementRef = useRef<HTMLDivElement | null>(null);
|
|
@@ -101,62 +112,6 @@ export const WebBox = forwardRef<HTMLDivElement, Record<string, unknown> & { chi
|
|
|
101
112
|
return handle as unknown as HTMLDivElement;
|
|
102
113
|
}, []);
|
|
103
114
|
|
|
104
|
-
const cancelPendingFrame = () => {
|
|
105
|
-
if (frameRef.current !== null) {
|
|
106
|
-
cancelWebFrame(frameRef.current);
|
|
107
|
-
frameRef.current = null;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const flushPendingFrameMouseHandlers = () => {
|
|
112
|
-
const moveEvent = pendingMoveRef.current;
|
|
113
|
-
const dragEvent = pendingDragRef.current;
|
|
114
|
-
pendingMoveRef.current = null;
|
|
115
|
-
pendingDragRef.current = null;
|
|
116
|
-
|
|
117
|
-
if (moveEvent) {
|
|
118
|
-
callCellMouseHandler(propsRef.current.onMouseMove, moveEvent);
|
|
119
|
-
}
|
|
120
|
-
if (dragEvent) {
|
|
121
|
-
callCellMouseHandler(propsRef.current.onMouse, dragEvent);
|
|
122
|
-
callCellMouseHandler(propsRef.current.onMouseDrag, dragEvent);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const flushPendingFrameNow = () => {
|
|
127
|
-
cancelPendingFrame();
|
|
128
|
-
flushPendingFrameMouseHandlers();
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const scheduleFrameMouseHandler = (
|
|
132
|
-
event: MouseLikeEvent,
|
|
133
|
-
type: "move" | "drag",
|
|
134
|
-
ahead: { clientX: number; clientY: number } | null = null,
|
|
135
|
-
) => {
|
|
136
|
-
// The DOM keeps firing mousemove while a button is held. A move means no
|
|
137
|
-
// button anywhere else in the app, so drags must not surface as moves.
|
|
138
|
-
if (type === "move" && draggingRef.current) return;
|
|
139
|
-
if (type === "move" && typeof propsRef.current.onMouseMove !== "function") return;
|
|
140
|
-
if (type === "drag"
|
|
141
|
-
&& typeof propsRef.current.onMouse !== "function"
|
|
142
|
-
&& typeof propsRef.current.onMouseDrag !== "function") {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const nextEvent = cellMouseEvent(event, type, ahead);
|
|
147
|
-
if (type === "move") {
|
|
148
|
-
pendingMoveRef.current = nextEvent;
|
|
149
|
-
} else {
|
|
150
|
-
pendingDragRef.current = nextEvent;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (frameRef.current !== null) return;
|
|
154
|
-
frameRef.current = requestWebFrame(() => {
|
|
155
|
-
frameRef.current = null;
|
|
156
|
-
flushPendingFrameMouseHandlers();
|
|
157
|
-
});
|
|
158
|
-
};
|
|
159
|
-
|
|
160
115
|
const lastPointRef = useRef({ x: 0, y: 0 });
|
|
161
116
|
// The pointer that pressed this box, so a drag can capture it.
|
|
162
117
|
const pressedPointerRef = useRef<number | null>(null);
|
|
@@ -176,38 +131,186 @@ export const WebBox = forwardRef<HTMLDivElement, Record<string, unknown> & { chi
|
|
|
176
131
|
* took the pointer), so a move can put things back.
|
|
177
132
|
*/
|
|
178
133
|
const endDocumentDragRef = useRef<(event: globalThis.MouseEvent | null, outcome: "end" | "cancel") => void>(() => {});
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
134
|
+
const handlersRef = useRef<BoxHandlers | null>(null);
|
|
135
|
+
// Created once: they read the latest props through propsRef, so a re-render
|
|
136
|
+
// hands React the same listeners instead of a dozen new closures.
|
|
137
|
+
const handlers = handlersRef.current ??= (() => {
|
|
138
|
+
const cancelPendingFrame = () => {
|
|
139
|
+
if (frameRef.current !== null) {
|
|
140
|
+
cancelWebFrame(frameRef.current);
|
|
141
|
+
frameRef.current = null;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const flushPendingFrameMouseHandlers = () => {
|
|
146
|
+
const moveEvent = pendingMoveRef.current;
|
|
147
|
+
const dragEvent = pendingDragRef.current;
|
|
148
|
+
pendingMoveRef.current = null;
|
|
149
|
+
pendingDragRef.current = null;
|
|
150
|
+
|
|
151
|
+
if (moveEvent) {
|
|
152
|
+
callCellMouseHandler(propsRef.current.onMouseMove, moveEvent);
|
|
153
|
+
}
|
|
154
|
+
if (dragEvent) {
|
|
155
|
+
callCellMouseHandler(propsRef.current.onMouse, dragEvent);
|
|
156
|
+
callCellMouseHandler(propsRef.current.onMouseDrag, dragEvent);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const flushPendingFrameNow = () => {
|
|
161
|
+
cancelPendingFrame();
|
|
162
|
+
flushPendingFrameMouseHandlers();
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const scheduleFrameMouseHandler = (
|
|
166
|
+
event: MouseLikeEvent,
|
|
167
|
+
type: "move" | "drag",
|
|
168
|
+
ahead: { clientX: number; clientY: number } | null = null,
|
|
169
|
+
) => {
|
|
170
|
+
// The DOM keeps firing mousemove while a button is held. A move means no
|
|
171
|
+
// button anywhere else in the app, so drags must not surface as moves.
|
|
172
|
+
if (type === "move" && draggingRef.current) return;
|
|
173
|
+
if (type === "move" && typeof propsRef.current.onMouseMove !== "function") return;
|
|
174
|
+
if (type === "drag"
|
|
175
|
+
&& typeof propsRef.current.onMouse !== "function"
|
|
176
|
+
&& typeof propsRef.current.onMouseDrag !== "function") {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const nextEvent = cellMouseEvent(event, type, ahead);
|
|
181
|
+
if (type === "move") {
|
|
182
|
+
pendingMoveRef.current = nextEvent;
|
|
183
|
+
} else {
|
|
184
|
+
pendingDragRef.current = nextEvent;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (frameRef.current !== null) return;
|
|
188
|
+
frameRef.current = requestWebFrame(() => {
|
|
189
|
+
frameRef.current = null;
|
|
190
|
+
flushPendingFrameMouseHandlers();
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
endDocumentDragRef.current = (event, outcome) => {
|
|
195
|
+
const session = dragSessionRef.current;
|
|
196
|
+
const wasDragging = draggingRef.current;
|
|
197
|
+
if (!session && !wasDragging) return;
|
|
198
|
+
draggingRef.current = false;
|
|
199
|
+
const shielded = session?.shielded === true;
|
|
200
|
+
dragSessionRef.current = null;
|
|
201
|
+
if (shielded) hideDragShield();
|
|
202
|
+
if (session) {
|
|
203
|
+
document.removeEventListener("pointermove", session.move);
|
|
204
|
+
document.removeEventListener("mousemove", session.move);
|
|
205
|
+
document.removeEventListener("mouseup", session.up);
|
|
206
|
+
document.removeEventListener("pointerup", session.up);
|
|
207
|
+
document.removeEventListener("pointercancel", session.cancel);
|
|
208
|
+
window.removeEventListener("blur", session.cancel);
|
|
209
|
+
releasePointer(session.captured);
|
|
210
|
+
}
|
|
211
|
+
if (!wasDragging) return;
|
|
212
|
+
const point = event ?? new MouseEvent("mouseup", {
|
|
213
|
+
clientX: lastPointRef.current.x,
|
|
214
|
+
clientY: lastPointRef.current.y,
|
|
215
|
+
button: 0,
|
|
216
|
+
bubbles: true,
|
|
217
|
+
});
|
|
218
|
+
flushPendingFrameNow();
|
|
219
|
+
callMouseHandler(propsRef.current.onMouse, point, "up");
|
|
220
|
+
callMouseHandler(propsRef.current.onMouseUp, point, "up");
|
|
221
|
+
callMouseHandler(propsRef.current.onMouseDragEnd, point, outcome === "cancel" ? "drag-cancel" : "drag-end");
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const handleMouseDown = (event: MouseEvent) => {
|
|
225
|
+
const hasSyntheticDrag = typeof propsRef.current.onMouse === "function";
|
|
226
|
+
const hasDirectDrag = typeof propsRef.current.onMouseDrag === "function" || typeof propsRef.current.onMouseDragEnd === "function";
|
|
227
|
+
pendingMoveRef.current = null;
|
|
228
|
+
// A press that never saw mouseup (the window move took the pointer) is still tracked.
|
|
229
|
+
// Finish it before the new press, so its drag-end cannot clear the drag this press starts.
|
|
230
|
+
endDocumentDragRef.current(null, "end");
|
|
231
|
+
callMouseHandler(propsRef.current.onMouseDown, event, "down");
|
|
232
|
+
if (event.button !== 0 || (event.isPropagationStopped() && !hasDirectDrag)) return;
|
|
233
|
+
if (!hasSyntheticDrag && !hasDirectDrag) return;
|
|
234
|
+
callMouseHandler(propsRef.current.onMouse, event, "down");
|
|
235
|
+
draggingRef.current = true;
|
|
236
|
+
lastPointRef.current = { x: event.clientX, y: event.clientY };
|
|
237
|
+
const originX = event.clientX;
|
|
238
|
+
const originY = event.clientY;
|
|
239
|
+
const move = (moveEvent: globalThis.MouseEvent) => {
|
|
240
|
+
if (!draggingRef.current) return;
|
|
241
|
+
const current = dragSessionRef.current;
|
|
242
|
+
if (isPointerMove(moveEvent)) {
|
|
243
|
+
if (current) current.pointerMoves = true;
|
|
244
|
+
} else if (current?.pointerMoves) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
lastPointRef.current = { x: moveEvent.clientX, y: moveEvent.clientY };
|
|
248
|
+
// The button is up and mouseup never arrived. End the drag instead of following the cursor.
|
|
249
|
+
if (moveEvent.buttons === 0) {
|
|
250
|
+
endDocumentDragRef.current(moveEvent, "end");
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const dx = moveEvent.clientX - originX;
|
|
254
|
+
const dy = moveEvent.clientY - originY;
|
|
255
|
+
if (current && !current.shielded) {
|
|
256
|
+
if (dx * dx + dy * dy < 9) return;
|
|
257
|
+
current.shielded = true;
|
|
258
|
+
showDragShield(elementRef.current);
|
|
259
|
+
// Captured once it is a drag (a click keeps its usual target), the
|
|
260
|
+
// moves skip hit testing and leave every other element's hover state
|
|
261
|
+
// alone: nothing under the pointer restyles or repaints while a pane,
|
|
262
|
+
// divider or chart is dragged across it. The document listeners still
|
|
263
|
+
// see every move.
|
|
264
|
+
if (!current.captured) current.captured = capturePointer(elementRef.current, pressedPointerRef.current);
|
|
265
|
+
}
|
|
266
|
+
scheduleFrameMouseHandler(moveEvent, "drag", predictedPoint(moveEvent));
|
|
267
|
+
};
|
|
268
|
+
const up = (upEvent: globalThis.MouseEvent) => {
|
|
269
|
+
endDocumentDragRef.current(upEvent, "end");
|
|
270
|
+
};
|
|
271
|
+
const cancel = () => {
|
|
272
|
+
endDocumentDragRef.current(null, "cancel");
|
|
273
|
+
};
|
|
274
|
+
dragSessionRef.current = { move, up, cancel, captured: null, pointerMoves: false, shielded: false };
|
|
275
|
+
document.addEventListener("pointermove", move);
|
|
276
|
+
document.addEventListener("mousemove", move);
|
|
277
|
+
document.addEventListener("mouseup", up);
|
|
278
|
+
document.addEventListener("pointerup", up);
|
|
279
|
+
document.addEventListener("pointercancel", cancel);
|
|
280
|
+
window.addEventListener("blur", cancel);
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const handlePointerDown = (event: PointerEvent) => {
|
|
284
|
+
pressedPointerRef.current = event.pointerId;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const handleMouseDownCapture = (event: MouseEvent) => {
|
|
288
|
+
callMouseHandler(propsRef.current.onMouseDownCapture, event, "down");
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const handleMouseOver = (event: MouseEvent) => {
|
|
292
|
+
callMouseHandler(propsRef.current.onMouseOver, event, "over");
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const handleMouseOut = (event: MouseEvent) => {
|
|
296
|
+
pendingMoveRef.current = null;
|
|
297
|
+
callMouseHandler(propsRef.current.onMouseOut, event, "out");
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
return {
|
|
301
|
+
cancelPendingFrame,
|
|
302
|
+
handleMouseDown,
|
|
303
|
+
handlePointerDown,
|
|
304
|
+
handleMouseDownCapture,
|
|
305
|
+
handleMouseOver,
|
|
306
|
+
handleMouseOut,
|
|
307
|
+
handleMouseMove: (event: MouseEvent) => scheduleFrameMouseHandler(event, "move"),
|
|
308
|
+
handleMouseUp: (event: MouseEvent) => callMouseHandler(propsRef.current.onMouseUp, event, "up"),
|
|
309
|
+
};
|
|
310
|
+
})();
|
|
208
311
|
|
|
209
312
|
useEffect(() => () => {
|
|
210
|
-
cancelPendingFrame();
|
|
313
|
+
handlers.cancelPendingFrame();
|
|
211
314
|
pendingMoveRef.current = null;
|
|
212
315
|
pendingDragRef.current = null;
|
|
213
316
|
endDocumentDragRef.current(null, "end");
|
|
@@ -263,103 +366,28 @@ export const WebBox = forwardRef<HTMLDivElement, Record<string, unknown> & { chi
|
|
|
263
366
|
};
|
|
264
367
|
}, [handlesWheel, pinchAsWheel]);
|
|
265
368
|
|
|
266
|
-
const handleMouseDown = (event: MouseEvent) => {
|
|
267
|
-
const hasSyntheticDrag = typeof propsRef.current.onMouse === "function";
|
|
268
|
-
const hasDirectDrag = typeof propsRef.current.onMouseDrag === "function" || typeof propsRef.current.onMouseDragEnd === "function";
|
|
269
|
-
pendingMoveRef.current = null;
|
|
270
|
-
// A press that never saw mouseup (the window move took the pointer) is still tracked.
|
|
271
|
-
// Finish it before the new press, so its drag-end cannot clear the drag this press starts.
|
|
272
|
-
endDocumentDragRef.current(null, "end");
|
|
273
|
-
callMouseHandler(propsRef.current.onMouseDown, event, "down");
|
|
274
|
-
if (event.button !== 0 || (event.isPropagationStopped() && !hasDirectDrag)) return;
|
|
275
|
-
if (!hasSyntheticDrag && !hasDirectDrag) return;
|
|
276
|
-
callMouseHandler(propsRef.current.onMouse, event, "down");
|
|
277
|
-
draggingRef.current = true;
|
|
278
|
-
lastPointRef.current = { x: event.clientX, y: event.clientY };
|
|
279
|
-
const originX = event.clientX;
|
|
280
|
-
const originY = event.clientY;
|
|
281
|
-
const move = (moveEvent: globalThis.MouseEvent) => {
|
|
282
|
-
if (!draggingRef.current) return;
|
|
283
|
-
const current = dragSessionRef.current;
|
|
284
|
-
if (isPointerMove(moveEvent)) {
|
|
285
|
-
if (current) current.pointerMoves = true;
|
|
286
|
-
} else if (current?.pointerMoves) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
lastPointRef.current = { x: moveEvent.clientX, y: moveEvent.clientY };
|
|
290
|
-
// The button is up and mouseup never arrived. End the drag instead of following the cursor.
|
|
291
|
-
if (moveEvent.buttons === 0) {
|
|
292
|
-
endDocumentDragRef.current(moveEvent, "end");
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
const dx = moveEvent.clientX - originX;
|
|
296
|
-
const dy = moveEvent.clientY - originY;
|
|
297
|
-
if (current && !current.shielded) {
|
|
298
|
-
if (dx * dx + dy * dy < 9) return;
|
|
299
|
-
current.shielded = true;
|
|
300
|
-
showDragShield(elementRef.current);
|
|
301
|
-
// Captured once it is a drag (a click keeps its usual target), the
|
|
302
|
-
// moves skip hit testing and leave every other element's hover state
|
|
303
|
-
// alone: nothing under the pointer restyles or repaints while a pane,
|
|
304
|
-
// divider or chart is dragged across it. The document listeners still
|
|
305
|
-
// see every move.
|
|
306
|
-
if (!current.captured) current.captured = capturePointer(elementRef.current, pressedPointerRef.current);
|
|
307
|
-
}
|
|
308
|
-
scheduleFrameMouseHandler(moveEvent, "drag", predictedPoint(moveEvent));
|
|
309
|
-
};
|
|
310
|
-
const up = (upEvent: globalThis.MouseEvent) => {
|
|
311
|
-
endDocumentDragRef.current(upEvent, "end");
|
|
312
|
-
};
|
|
313
|
-
const cancel = () => {
|
|
314
|
-
endDocumentDragRef.current(null, "cancel");
|
|
315
|
-
};
|
|
316
|
-
dragSessionRef.current = { move, up, cancel, captured: null, pointerMoves: false, shielded: false };
|
|
317
|
-
document.addEventListener("pointermove", move);
|
|
318
|
-
document.addEventListener("mousemove", move);
|
|
319
|
-
document.addEventListener("mouseup", up);
|
|
320
|
-
document.addEventListener("pointerup", up);
|
|
321
|
-
document.addEventListener("pointercancel", cancel);
|
|
322
|
-
window.addEventListener("blur", cancel);
|
|
323
|
-
};
|
|
324
|
-
|
|
325
369
|
const handlesDrag = typeof props.onMouse === "function"
|
|
326
370
|
|| typeof props.onMouseDrag === "function"
|
|
327
371
|
|| typeof props.onMouseDragEnd === "function";
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
const handleMouseOver = (event: MouseEvent) => {
|
|
337
|
-
callMouseHandler(propsRef.current.onMouseOver, event, "over");
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
const handleMouseOut = (event: MouseEvent) => {
|
|
341
|
-
pendingMoveRef.current = null;
|
|
342
|
-
callMouseHandler(propsRef.current.onMouseOut, event, "out");
|
|
343
|
-
};
|
|
344
|
-
|
|
372
|
+
const style = useStableStyle({
|
|
373
|
+
...commonStyle(props),
|
|
374
|
+
"--gloom-box-hover-bg": hoverBackgroundColor,
|
|
375
|
+
...(props.style as CSSProperties | undefined),
|
|
376
|
+
...(props.visible === false ? { display: "none" } : undefined),
|
|
377
|
+
} as CSSProperties);
|
|
345
378
|
return (
|
|
346
379
|
<div
|
|
347
380
|
{...cleanDomProps(props)}
|
|
348
381
|
data-gloom-hover-bg={hoverBackgroundColor ? "true" : undefined}
|
|
349
382
|
ref={elementRef}
|
|
350
|
-
onMouseDownCapture={typeof props.onMouseDownCapture === "function" ? handleMouseDownCapture : undefined}
|
|
351
|
-
onPointerDown={handlesDrag ? handlePointerDown : undefined}
|
|
352
|
-
onMouseDown={handleMouseDown}
|
|
353
|
-
onMouseOver={handleMouseOver}
|
|
354
|
-
onMouseMove={
|
|
355
|
-
onMouseUp={
|
|
356
|
-
onMouseOut={handleMouseOut}
|
|
357
|
-
style={
|
|
358
|
-
...commonStyle(props),
|
|
359
|
-
"--gloom-box-hover-bg": hoverBackgroundColor,
|
|
360
|
-
...(props.style as CSSProperties | undefined),
|
|
361
|
-
...(props.visible === false ? { display: "none" } : undefined),
|
|
362
|
-
} as CSSProperties}
|
|
383
|
+
onMouseDownCapture={typeof props.onMouseDownCapture === "function" ? handlers.handleMouseDownCapture : undefined}
|
|
384
|
+
onPointerDown={handlesDrag ? handlers.handlePointerDown : undefined}
|
|
385
|
+
onMouseDown={handlers.handleMouseDown}
|
|
386
|
+
onMouseOver={handlers.handleMouseOver}
|
|
387
|
+
onMouseMove={handlers.handleMouseMove}
|
|
388
|
+
onMouseUp={handlers.handleMouseUp}
|
|
389
|
+
onMouseOut={handlers.handleMouseOut}
|
|
390
|
+
style={style}
|
|
363
391
|
>
|
|
364
392
|
{children as ReactNode}
|
|
365
393
|
</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { useRef, type CSSProperties } from "react";
|
|
2
2
|
import { TextAttributes, type TextProps } from "../../../ui/host";
|
|
3
3
|
import { WEB_CELL_HEIGHT, WEB_CELL_WIDTH } from "../../../theme/font-scale";
|
|
4
4
|
|
|
@@ -113,30 +113,59 @@ export function textStyle(props: TextProps): CSSProperties {
|
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
/** Kit props a host element takes that are not DOM attributes (`onMouse*` handlers are left out too). */
|
|
117
|
+
const NON_DOM_PROPS: ReadonlySet<string> = new Set([
|
|
118
|
+
"fg", "bg", "backgroundColor", "flexDirection", "flexGrow", "flexShrink", "flexBasis", "flexWrap",
|
|
119
|
+
"alignItems", "justifyContent",
|
|
120
|
+
"padding", "paddingX", "paddingY", "paddingLeft", "paddingRight", "paddingTop", "paddingBottom",
|
|
121
|
+
"margin", "marginX", "marginY", "marginLeft", "marginRight", "marginTop", "marginBottom",
|
|
122
|
+
"bold", "underline", "inverse", "dim", "italic", "strikethrough", "attributes", "content", "position", "left", "right", "top", "bottom",
|
|
123
|
+
"zIndex", "width", "height", "minWidth", "minHeight", "maxWidth", "maxHeight", "gap", "columnGap", "rowGap",
|
|
124
|
+
"border", "borderStyle", "borderColor", "overflow", "selectable", "visible", "name", "color",
|
|
125
|
+
"focused", "focusedBackgroundColor", "textColor", "focusedTextColor", "placeholderColor",
|
|
126
|
+
"cursorColor", "selectionBg", "selectionFg", "showCursor", "keyBindings", "wrapText", "wrapMode",
|
|
127
|
+
"initialValue", "value", "onInput", "onChange", "onSubmit", "onEscape", "onCursorChange", "onMouse",
|
|
128
|
+
"scrollX", "scrollY", "focusable", "bitmap", "bitmaps", "crosshair", "vectors", "text", "font",
|
|
129
|
+
"hoverBackgroundColor", "joinPastedLines", "stickyScroll", "stickyStart", "onStickyPinChange", "pinchAsWheel",
|
|
130
|
+
]);
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The props a host element passes on to its DOM node, in their order. Built in
|
|
134
|
+
* one pass: every box and text run calls this on every render.
|
|
135
|
+
*/
|
|
116
136
|
export function cleanDomProps(props: Record<string, unknown>): Record<string, unknown> {
|
|
117
|
-
const next = {
|
|
118
|
-
for (const key of
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
"padding", "paddingX", "paddingY", "paddingLeft", "paddingRight", "paddingTop", "paddingBottom",
|
|
122
|
-
"margin", "marginX", "marginY", "marginLeft", "marginRight", "marginTop", "marginBottom",
|
|
123
|
-
"bold", "underline", "inverse", "dim", "italic", "strikethrough", "attributes", "content", "position", "left", "right", "top", "bottom",
|
|
124
|
-
"zIndex", "width", "height", "minWidth", "minHeight", "maxWidth", "maxHeight", "gap", "columnGap", "rowGap",
|
|
125
|
-
"border", "borderStyle", "borderColor", "overflow", "selectable", "visible", "name", "color",
|
|
126
|
-
"focused", "focusedBackgroundColor", "textColor", "focusedTextColor", "placeholderColor",
|
|
127
|
-
"cursorColor", "selectionBg", "selectionFg", "showCursor", "keyBindings", "wrapText", "wrapMode",
|
|
128
|
-
"initialValue", "value", "onInput", "onChange", "onSubmit", "onEscape", "onCursorChange", "onMouse",
|
|
129
|
-
"scrollX", "scrollY", "focusable", "bitmap", "bitmaps", "crosshair", "vectors", "text", "font",
|
|
130
|
-
"hoverBackgroundColor", "joinPastedLines", "stickyScroll", "stickyStart", "onStickyPinChange", "pinchAsWheel",
|
|
131
|
-
]) {
|
|
132
|
-
delete next[key];
|
|
133
|
-
}
|
|
134
|
-
for (const key of Object.keys(next)) {
|
|
135
|
-
if (key.startsWith("onMouse")) delete next[key];
|
|
137
|
+
const next: Record<string, unknown> = {};
|
|
138
|
+
for (const key of Object.keys(props)) {
|
|
139
|
+
if (NON_DOM_PROPS.has(key) || key.startsWith("onMouse")) continue;
|
|
140
|
+
next[key] = props[key];
|
|
136
141
|
}
|
|
137
142
|
return next;
|
|
138
143
|
}
|
|
139
144
|
|
|
145
|
+
/**
|
|
146
|
+
* `style` as it was last rendered while nothing in it changed, so React skips
|
|
147
|
+
* the element's inline style on a re-render instead of comparing every
|
|
148
|
+
* property again (and reading `element.style`). A host box re-renders with
|
|
149
|
+
* each render of its parent, and most leave its style as it was.
|
|
150
|
+
*/
|
|
151
|
+
export function useStableStyle<T extends object>(style: T): T {
|
|
152
|
+
const previousRef = useRef<{ style: T; keys: string[] } | null>(null);
|
|
153
|
+
const previous = previousRef.current;
|
|
154
|
+
if (previous && sameStyle(previous.style as Record<string, unknown>, previous.keys, style as Record<string, unknown>)) return previous.style;
|
|
155
|
+
previousRef.current = { style, keys: Object.keys(style) };
|
|
156
|
+
return style;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** The same keys with the same values, so React would write nothing. Read in order, which a rebuilt style keeps. */
|
|
160
|
+
function sameStyle(left: Record<string, unknown>, leftKeys: readonly string[], right: Record<string, unknown>): boolean {
|
|
161
|
+
let index = 0;
|
|
162
|
+
for (const key in right) {
|
|
163
|
+
if (leftKeys[index] !== key || left[key] !== right[key]) return false;
|
|
164
|
+
index += 1;
|
|
165
|
+
}
|
|
166
|
+
return index === leftKeys.length;
|
|
167
|
+
}
|
|
168
|
+
|
|
140
169
|
function allowsZeroMinSize(props: Record<string, unknown>, axis: "inline" | "block"): boolean {
|
|
141
170
|
if (props.overflow === "hidden" || props.overflow === "clip") return true;
|
|
142
171
|
if (typeof props.flexShrink === "number" && props.flexShrink > 0) return true;
|
|
@@ -11,7 +11,7 @@ import { renderAsciiText } from "../../../ui/ascii-font";
|
|
|
11
11
|
import { webAsciiTextLines, webAsciiTextWordmarkVariant } from "./ascii-text";
|
|
12
12
|
import { BlockGlyphCanvas } from "./block-glyph-canvas";
|
|
13
13
|
import { mouseHandlers } from "./mouse";
|
|
14
|
-
import { cleanDomProps, commonStyle, selectionStyle, textStyle } from "./style";
|
|
14
|
+
import { cleanDomProps, commonStyle, selectionStyle, textStyle, useStableStyle } from "./style";
|
|
15
15
|
|
|
16
16
|
// Read per render: the cell width tracks the configured font size.
|
|
17
17
|
function wordmarkCharWidthPx(): number {
|
|
@@ -60,11 +60,12 @@ function renderTextContent(children: ReactNode, content: TextProps["content"], b
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export function WebText({ children, ...props }: TextProps) {
|
|
63
|
+
const style = useStableStyle({ ...textStyle(props), ...(props.style as CSSProperties | undefined) });
|
|
63
64
|
return (
|
|
64
65
|
<span
|
|
65
66
|
{...cleanDomProps(props)}
|
|
66
67
|
{...mouseHandlers(props)}
|
|
67
|
-
style={
|
|
68
|
+
style={style}
|
|
68
69
|
>
|
|
69
70
|
{renderTextContent(children, props.content, props)}
|
|
70
71
|
</span>
|
|
@@ -570,7 +570,9 @@ export class DesktopBackend {
|
|
|
570
570
|
case "host.exit":
|
|
571
571
|
case "host.windowControl":
|
|
572
572
|
case "host.windowFullscreen":
|
|
573
|
+
case "host.windowMaximized":
|
|
573
574
|
case "host.startWindowDrag":
|
|
575
|
+
case "host.startWindowResize":
|
|
574
576
|
case "host.openExternal":
|
|
575
577
|
case "host.copyText":
|
|
576
578
|
case "host.focusWindow":
|
|
@@ -5,12 +5,13 @@ import type {
|
|
|
5
5
|
DesktopBackendRequestResponse,
|
|
6
6
|
DesktopHostRequest,
|
|
7
7
|
DesktopWindowControlAction,
|
|
8
|
+
DesktopWindowResizeEdge,
|
|
8
9
|
} from "../../shared/protocol";
|
|
9
10
|
import { safeExternalUrl } from "../../../../utils/external-url";
|
|
10
11
|
import { getContextMenuRequestId, normalizeContextMenuItems } from "../context-menu/normalize";
|
|
11
12
|
import { MAIN_WINDOW_RPC_KEY } from "../window/focus";
|
|
12
13
|
import { applyDesktopWindowControl } from "../window/controls";
|
|
13
|
-
import { startSystemWindowMove } from "../window/windows-native";
|
|
14
|
+
import { startSystemWindowMove, startSystemWindowResize } from "../window/windows-native";
|
|
14
15
|
import { saveTextFileToDownloads } from "../../../../utils/save-text-file";
|
|
15
16
|
import { setAppBadge } from "./app-badge";
|
|
16
17
|
import { desktopBootFramePath, saveDesktopBootFrame } from "../window/boot-frame";
|
|
@@ -55,6 +56,14 @@ function isWindowFullscreen(backend: DesktopBackend, windowKey: string | undefin
|
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
function isWindowMaximized(backend: DesktopBackend, windowKey: string | undefined): boolean {
|
|
60
|
+
try {
|
|
61
|
+
return windowForRpcKey(backend, windowKey)?.isMaximized?.() === true;
|
|
62
|
+
} catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
58
67
|
function controlWindow(
|
|
59
68
|
backend: DesktopBackend,
|
|
60
69
|
windowKey: string | undefined,
|
|
@@ -82,6 +91,11 @@ function exitDesktopApp(backend: DesktopBackend): void {
|
|
|
82
91
|
Utils.quit();
|
|
83
92
|
}
|
|
84
93
|
|
|
94
|
+
function normalizeWindowResizeEdge(edge: unknown): DesktopWindowResizeEdge {
|
|
95
|
+
if (edge === "top" || edge === "top-left" || edge === "top-right") return edge;
|
|
96
|
+
throw new Error("host.startWindowResize requires a top edge or corner.");
|
|
97
|
+
}
|
|
98
|
+
|
|
85
99
|
function normalizeWindowControlAction(action: unknown): DesktopWindowControlAction {
|
|
86
100
|
if (action === "minimize" || action === "toggle-maximize" || action === "close") {
|
|
87
101
|
return action;
|
|
@@ -112,6 +126,8 @@ export async function handleDesktopHostRequest(
|
|
|
112
126
|
}
|
|
113
127
|
case "host.windowFullscreen":
|
|
114
128
|
return isWindowFullscreen(backend, backend.rpcs.getRpcWindowKey(rpc));
|
|
129
|
+
case "host.windowMaximized":
|
|
130
|
+
return isWindowMaximized(backend, backend.rpcs.getRpcWindowKey(rpc));
|
|
115
131
|
case "host.startWindowDrag": {
|
|
116
132
|
const targetWindow = windowForRpcKey(backend, backend.rpcs.getRpcWindowKey(rpc));
|
|
117
133
|
if (!targetWindow?.ptr || !startSystemWindowMove(targetWindow.ptr)) {
|
|
@@ -119,6 +135,14 @@ export async function handleDesktopHostRequest(
|
|
|
119
135
|
}
|
|
120
136
|
return null;
|
|
121
137
|
}
|
|
138
|
+
case "host.startWindowResize": {
|
|
139
|
+
const edge = normalizeWindowResizeEdge(request.payload.edge);
|
|
140
|
+
const targetWindow = windowForRpcKey(backend, backend.rpcs.getRpcWindowKey(rpc));
|
|
141
|
+
if (!targetWindow?.ptr || !startSystemWindowResize(targetWindow.ptr, edge)) {
|
|
142
|
+
throw new Error("This window cannot be resized by the system.");
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
122
146
|
case "host.openExternal": {
|
|
123
147
|
if (typeof request.payload.url !== "string") {
|
|
124
148
|
throw new Error("host.openExternal requires a URL.");
|
|
@@ -144,6 +144,14 @@ try {
|
|
|
144
144
|
].join("\n");
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
/**
|
|
148
|
+
* How long a restart waits for its script, with the error screen saying the
|
|
149
|
+
* restart was asked. Windows PowerShell started by the Task Scheduler can take
|
|
150
|
+
* over 20 s to run its first line: 23 s on an idle Windows on Arm machine,
|
|
151
|
+
* over a minute on a busy one, where a task runs below normal priority.
|
|
152
|
+
*/
|
|
153
|
+
const RESTART_SCRIPT_START_TIMEOUT_MS = 120_000;
|
|
154
|
+
|
|
147
155
|
/**
|
|
148
156
|
* Electrobun puts the Windows app in a job that ends every process it starts
|
|
149
157
|
* when it exits, so the script runs from a scheduled task, which outlives it.
|
|
@@ -164,7 +172,7 @@ async function scheduleWindowsRelaunch(context: RelaunchContext): Promise<void>
|
|
|
164
172
|
taskName: `GloomRestart-${context.pid}`,
|
|
165
173
|
home: context.home,
|
|
166
174
|
}));
|
|
167
|
-
const answer = await runScriptAfterExit(script, log, cancel, `GloomRestart-${context.pid}
|
|
175
|
+
const answer = await runScriptAfterExit(script, log, cancel, `GloomRestart-${context.pid}`, RESTART_SCRIPT_START_TIMEOUT_MS);
|
|
168
176
|
if (answer.kind !== "started") throw new Error(`the restart script did not start: ${answer.reason}`);
|
|
169
177
|
}
|
|
170
178
|
|