@blackbelt-technology/pi-dashboard-client-utils 0.8.0 → 0.10.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/package.json +35 -3
- package/src/ActionList.tsx +54 -30
- package/src/ActionListMenuContext.ts +19 -0
- package/src/Dialog.tsx +38 -16
- package/src/LayerPortal.tsx +40 -6
- package/src/Popover.tsx +25 -23
- package/src/SearchableSelectDialog.tsx +94 -31
- package/src/StatusPill.tsx +28 -58
- package/src/ZoomControls.tsx +28 -15
- package/src/identity/dpop.ts +91 -0
- package/src/identity/login-flow.ts +197 -0
- package/src/identity/oidc-flow.ts +96 -0
- package/src/identity/pkce.ts +129 -0
- package/src/identity/token-store.ts +66 -0
- package/src/mdi-by-key.ts +90 -0
- package/src/minimal-chat/MinimalChatView.tsx +107 -14
- package/src/minimal-chat/index.ts +2 -0
- package/src/minimal-chat/live-tail-text.ts +27 -0
- package/src/minimal-chat/types.ts +26 -0
- package/src/tone.ts +28 -0
- package/src/useZoomPan.ts +33 -13
package/src/useZoomPan.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
|
2
3
|
|
|
3
4
|
export interface ZoomPanState {
|
|
4
5
|
scale: number;
|
|
@@ -10,6 +11,13 @@ export interface UseZoomPanOptions {
|
|
|
10
11
|
minScale?: number;
|
|
11
12
|
maxScale?: number;
|
|
12
13
|
zoomStep?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Scale the surface starts at and that reset / double-click return to.
|
|
16
|
+
* Clamped into [minScale, maxScale]; defaults to 1. While the user has not
|
|
17
|
+
* interacted, a changed value re-seeds the view (fit may resolve async).
|
|
18
|
+
* See change: fix-markdown-remount-storm (D4).
|
|
19
|
+
*/
|
|
20
|
+
initialScale?: number;
|
|
13
21
|
}
|
|
14
22
|
|
|
15
23
|
const DEFAULT_MIN = 0.5;
|
|
@@ -26,7 +34,23 @@ export function useZoomPan(options?: UseZoomPanOptions) {
|
|
|
26
34
|
const maxScale = options?.maxScale ?? DEFAULT_MAX;
|
|
27
35
|
const zoomStep = options?.zoomStep ?? DEFAULT_STEP;
|
|
28
36
|
|
|
29
|
-
const
|
|
37
|
+
const initialScale = Math.min(maxScale, Math.max(minScale, options?.initialScale ?? 1));
|
|
38
|
+
|
|
39
|
+
const [state, rawSetState] = useState<ZoomPanState>({ scale: initialScale, translateX: 0, translateY: 0 });
|
|
40
|
+
// True once the user zoomed/panned; a late initialScale change must not override that.
|
|
41
|
+
const touched = useRef(false);
|
|
42
|
+
const setState = useCallback((u: React.SetStateAction<ZoomPanState>) => {
|
|
43
|
+
touched.current = true;
|
|
44
|
+
rawSetState(u);
|
|
45
|
+
}, []);
|
|
46
|
+
const resetToInitial = useCallback(() => {
|
|
47
|
+
touched.current = false;
|
|
48
|
+
rawSetState({ scale: initialScale, translateX: 0, translateY: 0 });
|
|
49
|
+
}, [initialScale]);
|
|
50
|
+
|
|
51
|
+
useLayoutEffect(() => {
|
|
52
|
+
if (!touched.current) rawSetState({ scale: initialScale, translateX: 0, translateY: 0 });
|
|
53
|
+
}, [initialScale]);
|
|
30
54
|
|
|
31
55
|
// Refs for drag tracking (avoid re-renders during drag)
|
|
32
56
|
const dragging = useRef(false);
|
|
@@ -59,7 +83,7 @@ export function useZoomPan(options?: UseZoomPanOptions) {
|
|
|
59
83
|
};
|
|
60
84
|
});
|
|
61
85
|
},
|
|
62
|
-
[clampScale],
|
|
86
|
+
[clampScale, setState],
|
|
63
87
|
);
|
|
64
88
|
|
|
65
89
|
// ── Wheel handler ──────────────────────────────────────────────────
|
|
@@ -108,7 +132,7 @@ export function useZoomPan(options?: UseZoomPanOptions) {
|
|
|
108
132
|
translateX: prev.translateX + dx,
|
|
109
133
|
translateY: prev.translateY + dy,
|
|
110
134
|
}));
|
|
111
|
-
}, []);
|
|
135
|
+
}, [setState]);
|
|
112
136
|
|
|
113
137
|
const onPointerUp = useCallback(() => {
|
|
114
138
|
dragging.current = false;
|
|
@@ -142,9 +166,7 @@ export function useZoomPan(options?: UseZoomPanOptions) {
|
|
|
142
166
|
}, []);
|
|
143
167
|
|
|
144
168
|
// ── Double-click reset ─────────────────────────────────────────────
|
|
145
|
-
const onDoubleClick =
|
|
146
|
-
setState({ scale: 1, translateX: 0, translateY: 0 });
|
|
147
|
-
}, []);
|
|
169
|
+
const onDoubleClick = resetToInitial;
|
|
148
170
|
|
|
149
171
|
// ── Button controls ────────────────────────────────────────────────
|
|
150
172
|
const zoomIn = useCallback(() => {
|
|
@@ -152,18 +174,16 @@ export function useZoomPan(options?: UseZoomPanOptions) {
|
|
|
152
174
|
const newScale = clampScale(prev.scale * zoomStep);
|
|
153
175
|
return { ...prev, scale: newScale };
|
|
154
176
|
});
|
|
155
|
-
}, [clampScale, zoomStep]);
|
|
177
|
+
}, [clampScale, zoomStep, setState]);
|
|
156
178
|
|
|
157
179
|
const zoomOut = useCallback(() => {
|
|
158
180
|
setState((prev) => {
|
|
159
181
|
const newScale = clampScale(prev.scale / zoomStep);
|
|
160
182
|
return { ...prev, scale: newScale };
|
|
161
183
|
});
|
|
162
|
-
}, [clampScale, zoomStep]);
|
|
184
|
+
}, [clampScale, zoomStep, setState]);
|
|
163
185
|
|
|
164
|
-
const reset =
|
|
165
|
-
setState({ scale: 1, translateX: 0, translateY: 0 });
|
|
166
|
-
}, []);
|
|
186
|
+
const reset = resetToInitial;
|
|
167
187
|
|
|
168
188
|
const handlers = {
|
|
169
189
|
onWheel,
|
|
@@ -175,5 +195,5 @@ export function useZoomPan(options?: UseZoomPanOptions) {
|
|
|
175
195
|
onDoubleClick,
|
|
176
196
|
};
|
|
177
197
|
|
|
178
|
-
return { state, handlers, zoomIn, zoomOut, reset };
|
|
198
|
+
return { state, handlers, zoomIn, zoomOut, reset, initialScale };
|
|
179
199
|
}
|