@shellui/core 0.7.0-alpha.1 → 0.7.0-alpha.10
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 +2 -2
- package/schemas/shellui.config.schema.json +37 -4
- package/src/components/ContentView.tsx +19 -8
- package/src/components/ui/sidebar.tsx +11 -5
- package/src/features/admin/AdminView.tsx +9 -6
- package/src/features/auth/AuthProvider.tsx +25 -4
- package/src/features/auth/appBackend/appBackendSessions.spec.ts +134 -0
- package/src/features/auth/appBackend/appBackendSessions.ts +168 -17
- package/src/features/auth/appBackend/childFrames.spec.ts +328 -0
- package/src/features/auth/appBackend/childFrames.ts +180 -0
- package/src/features/auth/appBackend/frameAuth.ts +47 -10
- package/src/features/auth/appBackend/silentSignIn.spec.ts +18 -0
- package/src/features/auth/appBackend/silentSignIn.ts +15 -1
- package/src/features/auth/appBackend/tokenExchange.spec.ts +98 -0
- package/src/features/auth/appBackend/tokenExchange.ts +76 -0
- package/src/features/auth/components/OAuthCallbackView.tsx +7 -5
- package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +42 -1
- package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +23 -0
- package/src/features/auth/utils/canRestoreStoredSession.spec.ts +29 -0
- package/src/features/auth/utils/canRestoreStoredSession.ts +12 -0
- package/src/features/auth/utils/index.ts +7 -1
- package/src/features/auth/utils/resolveSdkLoginRedirectPath.spec.ts +41 -0
- package/src/features/auth/utils/resolveSdkLoginRedirectPath.ts +31 -0
- package/src/features/auth/utils/webPkce.spec.ts +23 -0
- package/src/features/auth/utils/webPkce.ts +23 -6
- package/src/features/chromeActions/computeActionInsets.ts +7 -4
- package/src/features/config/types.ts +30 -4
- package/src/features/layouts/appbar/AppBarLayout.tsx +63 -30
- package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +12 -23
- package/src/features/layouts/chrome/ContentDragOverlay.tsx +5 -6
- package/src/features/layouts/chrome/DesktopChrome.tsx +37 -0
- package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +15 -4
- package/src/features/layouts/chrome/MacStrip.tsx +33 -0
- package/src/features/layouts/chrome/constants.ts +33 -8
- package/src/features/layouts/chrome/index.ts +8 -0
- package/src/features/layouts/chrome/stripDragMap.ts +35 -0
- package/src/features/layouts/chrome/stripNoDrag.spec.tsx +103 -0
- package/src/features/layouts/chrome/useScrollHideChrome.ts +3 -8
- package/src/features/layouts/filterNavigationForAuthState.spec.ts +5 -3
- package/src/features/layouts/floating/FloatingBottomDock.tsx +199 -20
- package/src/features/layouts/floating/FloatingLayout.tsx +13 -8
- package/src/features/layouts/floating/FloatingSidebar.tsx +144 -70
- package/src/features/layouts/floating/computeFloatingInsets.ts +22 -4
- package/src/features/layouts/floating/useFloatingChrome.ts +3 -1
- package/src/features/layouts/floating/useSoftKeyboard.spec.ts +39 -0
- package/src/features/layouts/floating/useSoftKeyboard.ts +82 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.tsx +38 -10
- package/src/features/layouts/sidebar/NavigationContent.tsx +14 -6
- package/src/features/layouts/sidebar/SidebarIcons.tsx +3 -9
- package/src/features/layouts/sidebar/SidebarInner.tsx +50 -39
- package/src/features/layouts/sidebar/SidebarLayout.tsx +8 -11
- package/src/features/layouts/utils.ts +4 -3
- package/src/features/layouts/windows/DesktopDots.tsx +76 -0
- package/src/features/layouts/windows/WindowsLayout.tsx +184 -125
- package/src/features/layouts/windows/deskDots.spec.ts +52 -0
- package/src/features/layouts/windows/deskDots.ts +314 -0
- package/src/features/settings/SettingsProvider.tsx +158 -2
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +8 -7
- package/src/features/settings/utils/buildSettingsForPropagation.ts +4 -6
- package/src/features/theme/applyTheme.ts +8 -0
- package/src/features/theme/navContrast.spec.ts +49 -0
- package/src/features/theme/navContrast.ts +108 -0
- package/src/features/transfers/transferQueue.spec.ts +6 -2
- package/src/i18n/translations/en/common.json +25 -0
- package/src/i18n/translations/fr/common.json +25 -0
- package/src/index.css +935 -46
- package/src/index.ts +1 -0
- package/src/routes/hooks/useNavigationItems.ts +14 -3
- package/src/routes/hooks/withShellSearch.spec.ts +13 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows layout desktop: calm dot field on a canvas.
|
|
3
|
+
* Ported from the layouts redesign reference (`desk-dots.js`), itself derived from
|
|
4
|
+
* the shellui.com hero dots: three to four times slower, half the travel, no pointer play.
|
|
5
|
+
* Decorative only. The caller mounts it on an `aria-hidden` host.
|
|
6
|
+
*/
|
|
7
|
+
export const DESK_DOTS = {
|
|
8
|
+
/** Grid spacing in px (same as the website). */
|
|
9
|
+
spacing: 24,
|
|
10
|
+
/** Dot radius in px. */
|
|
11
|
+
radius: 1.1,
|
|
12
|
+
/** Base alpha of `--foreground` in light mode. */
|
|
13
|
+
alphaLight: 0.15,
|
|
14
|
+
/** Base alpha of `--foreground` in dark mode. */
|
|
15
|
+
alphaDark: 0.11,
|
|
16
|
+
/** One dot in this many is tinted with `--primary`. */
|
|
17
|
+
accentEvery: 11,
|
|
18
|
+
/** Accent base alpha; rises with the gust. */
|
|
19
|
+
accentAlpha: 0.22,
|
|
20
|
+
/** Extra alpha at full displacement. */
|
|
21
|
+
gustLift: 0.16,
|
|
22
|
+
/** Max displacement in px. */
|
|
23
|
+
gustPx: 3.5,
|
|
24
|
+
/** Width of a wind front in px. */
|
|
25
|
+
frontWidth: 170,
|
|
26
|
+
/** Front slant in degrees. */
|
|
27
|
+
slantDeg: 18,
|
|
28
|
+
/** Time for one front to cross the desktop, ms range. */
|
|
29
|
+
crossMs: [30000, 40000] as const,
|
|
30
|
+
/** Gap between fronts, ms range. */
|
|
31
|
+
everyMs: [9000, 15000] as const,
|
|
32
|
+
spring: 0.035,
|
|
33
|
+
damp: 0.88,
|
|
34
|
+
/** Frame cap. */
|
|
35
|
+
fps: 30,
|
|
36
|
+
/** Device pixel ratio cap. */
|
|
37
|
+
dprMax: 2,
|
|
38
|
+
} as const;
|
|
39
|
+
|
|
40
|
+
export type DeskDotsOptions = Partial<{
|
|
41
|
+
[K in keyof typeof DESK_DOTS]: (typeof DESK_DOTS)[K] extends readonly [number, number]
|
|
42
|
+
? readonly [number, number]
|
|
43
|
+
: number;
|
|
44
|
+
}>;
|
|
45
|
+
|
|
46
|
+
export interface DeskDotsHandle {
|
|
47
|
+
/** True while the desktop is covered (maximized window) or a window is dragged or resized. */
|
|
48
|
+
pause: (paused: boolean) => void;
|
|
49
|
+
/** Draw count and total draw time, for profiling. */
|
|
50
|
+
stats: { frames: number; ms: number };
|
|
51
|
+
destroy: () => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type Rgb = [number, number, number];
|
|
55
|
+
|
|
56
|
+
const BUCKETS = 6;
|
|
57
|
+
|
|
58
|
+
/** Alpha for a bucket: base dots and accent dots rise with the gust. */
|
|
59
|
+
export function bucketAlpha(
|
|
60
|
+
accent: boolean,
|
|
61
|
+
bucket: number,
|
|
62
|
+
dark: boolean,
|
|
63
|
+
p: { alphaLight: number; alphaDark: number; accentAlpha: number; gustLift: number } = DESK_DOTS,
|
|
64
|
+
): number {
|
|
65
|
+
const m = (bucket + 0.5) / BUCKETS;
|
|
66
|
+
if (accent) return p.accentAlpha + p.gustLift * 1.6 * m;
|
|
67
|
+
return (dark ? p.alphaDark : p.alphaLight) + p.gustLift * m;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Grid size for a host box: columns and rows of dots. */
|
|
71
|
+
export function gridSize(width: number, height: number, spacing: number = DESK_DOTS.spacing) {
|
|
72
|
+
const cols = Math.max(0, Math.ceil(width / spacing));
|
|
73
|
+
const rows = Math.max(0, Math.ceil(height / spacing));
|
|
74
|
+
return { cols, rows, count: cols * rows };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Same 1 in N pattern as the reference: stable across relayouts. */
|
|
78
|
+
export function isAccentDot(col: number, row: number, every: number = DESK_DOTS.accentEvery) {
|
|
79
|
+
return (col * 7 + row * 3) % every === 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function mountDeskDots(host: HTMLElement, opts: DeskDotsOptions = {}): DeskDotsHandle {
|
|
83
|
+
const P = { ...DESK_DOTS, ...opts };
|
|
84
|
+
const stats = { frames: 0, ms: 0 };
|
|
85
|
+
const canvas = document.createElement('canvas');
|
|
86
|
+
canvas.setAttribute('aria-hidden', 'true');
|
|
87
|
+
canvas.style.position = 'absolute';
|
|
88
|
+
canvas.style.inset = '0';
|
|
89
|
+
canvas.style.width = '100%';
|
|
90
|
+
canvas.style.height = '100%';
|
|
91
|
+
canvas.style.pointerEvents = 'none';
|
|
92
|
+
const ctx = canvas.getContext('2d', { alpha: true });
|
|
93
|
+
if (!ctx) {
|
|
94
|
+
return { pause: () => {}, stats, destroy: () => {} };
|
|
95
|
+
}
|
|
96
|
+
host.appendChild(canvas);
|
|
97
|
+
host.setAttribute('data-live', 'true');
|
|
98
|
+
|
|
99
|
+
const slant = Math.tan((P.slantDeg * Math.PI) / 180);
|
|
100
|
+
const smooth = (t: number) => t * t * (3 - 2 * t);
|
|
101
|
+
const rnd = (a: number, b: number) => a + Math.random() * (b - a);
|
|
102
|
+
|
|
103
|
+
let w = 0;
|
|
104
|
+
let h = 0;
|
|
105
|
+
let n = 0;
|
|
106
|
+
let X = new Float32Array(0);
|
|
107
|
+
let Y = new Float32Array(0);
|
|
108
|
+
let OX = new Float32Array(0);
|
|
109
|
+
let OY = new Float32Array(0);
|
|
110
|
+
let VX = new Float32Array(0);
|
|
111
|
+
let VY = new Float32Array(0);
|
|
112
|
+
let S = new Float32Array(0);
|
|
113
|
+
let PH = new Float32Array(0);
|
|
114
|
+
let AC = new Uint8Array(0);
|
|
115
|
+
let fronts: { t: number; v: number; x: number }[] = [];
|
|
116
|
+
let nextAt = 0;
|
|
117
|
+
let raf = 0;
|
|
118
|
+
let last = 0;
|
|
119
|
+
let paused = false;
|
|
120
|
+
let settled = false;
|
|
121
|
+
let destroyed = false;
|
|
122
|
+
let idleTimer: ReturnType<typeof setTimeout> | undefined;
|
|
123
|
+
let layoutTimer: ReturnType<typeof setTimeout> | undefined;
|
|
124
|
+
let fg: Rgb = [17, 24, 39];
|
|
125
|
+
let pr: Rgb = [227, 165, 18];
|
|
126
|
+
let dark = false;
|
|
127
|
+
|
|
128
|
+
// Theme colours: resolve any CSS colour (oklch included) through a 1 x 1 canvas.
|
|
129
|
+
const probe = document.createElement('canvas');
|
|
130
|
+
probe.width = 1;
|
|
131
|
+
probe.height = 1;
|
|
132
|
+
const pctx = probe.getContext('2d', { willReadFrequently: true });
|
|
133
|
+
const toRgb = (css: string, fallback: Rgb): Rgb => {
|
|
134
|
+
if (!pctx || !css) return fallback;
|
|
135
|
+
pctx.clearRect(0, 0, 1, 1);
|
|
136
|
+
pctx.fillStyle = '#000';
|
|
137
|
+
pctx.fillStyle = css;
|
|
138
|
+
pctx.fillRect(0, 0, 1, 1);
|
|
139
|
+
const d = pctx.getImageData(0, 0, 1, 1).data;
|
|
140
|
+
return [d[0], d[1], d[2]];
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const paths: Path2D[] = new Array(BUCKETS * 2);
|
|
144
|
+
function draw() {
|
|
145
|
+
if (!ctx) return;
|
|
146
|
+
const t0 = performance.now();
|
|
147
|
+
ctx.clearRect(0, 0, w, h);
|
|
148
|
+
for (let k = 0; k < paths.length; k++) paths[k] = new Path2D();
|
|
149
|
+
for (let i = 0; i < n; i++) {
|
|
150
|
+
const m = Math.min(1, Math.hypot(OX[i], OY[i]) / P.gustPx);
|
|
151
|
+
const b = Math.min(BUCKETS - 1, (m * BUCKETS) | 0);
|
|
152
|
+
const p = paths[AC[i] * BUCKETS + b];
|
|
153
|
+
const x = X[i] + OX[i];
|
|
154
|
+
const y = Y[i] + OY[i];
|
|
155
|
+
p.moveTo(x + P.radius, y);
|
|
156
|
+
p.arc(x, y, P.radius, 0, Math.PI * 2);
|
|
157
|
+
}
|
|
158
|
+
for (let a = 0; a < 2; a++) {
|
|
159
|
+
const c = a ? pr : fg;
|
|
160
|
+
for (let b = 0; b < BUCKETS; b++) {
|
|
161
|
+
const al = bucketAlpha(a === 1, b, dark, P);
|
|
162
|
+
ctx.fillStyle = `rgba(${c[0]},${c[1]},${c[2]},${al.toFixed(3)})`;
|
|
163
|
+
ctx.fill(paths[a * BUCKETS + b]);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
stats.frames++;
|
|
167
|
+
stats.ms += performance.now() - t0;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function readTheme() {
|
|
171
|
+
const cs = getComputedStyle(host);
|
|
172
|
+
fg = toRgb(cs.getPropertyValue('--foreground').trim(), fg);
|
|
173
|
+
pr = toRgb(cs.getPropertyValue('--primary').trim(), pr);
|
|
174
|
+
dark = document.documentElement.classList.contains('dark');
|
|
175
|
+
settled = false;
|
|
176
|
+
draw();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function layout() {
|
|
180
|
+
if (!ctx) return;
|
|
181
|
+
const dpr = Math.min(window.devicePixelRatio || 1, P.dprMax);
|
|
182
|
+
w = host.clientWidth;
|
|
183
|
+
h = host.clientHeight;
|
|
184
|
+
canvas.width = Math.round(w * dpr);
|
|
185
|
+
canvas.height = Math.round(h * dpr);
|
|
186
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
187
|
+
const { cols, rows, count } = gridSize(w, h, P.spacing);
|
|
188
|
+
n = count;
|
|
189
|
+
X = new Float32Array(n);
|
|
190
|
+
Y = new Float32Array(n);
|
|
191
|
+
OX = new Float32Array(n);
|
|
192
|
+
OY = new Float32Array(n);
|
|
193
|
+
VX = new Float32Array(n);
|
|
194
|
+
VY = new Float32Array(n);
|
|
195
|
+
S = new Float32Array(n);
|
|
196
|
+
PH = new Float32Array(n);
|
|
197
|
+
AC = new Uint8Array(n);
|
|
198
|
+
const x0 = (w - (cols - 1) * P.spacing) / 2;
|
|
199
|
+
const y0 = P.spacing / 2;
|
|
200
|
+
let i = 0;
|
|
201
|
+
for (let r = 0; r < rows; r++) {
|
|
202
|
+
for (let c = 0; c < cols; c++, i++) {
|
|
203
|
+
X[i] = x0 + c * P.spacing;
|
|
204
|
+
Y[i] = y0 + r * P.spacing;
|
|
205
|
+
S[i] = 0.6 + Math.random() * 0.4;
|
|
206
|
+
PH[i] = Math.random() * Math.PI * 2;
|
|
207
|
+
AC[i] = isAccentDot(c, r, P.accentEvery) ? 1 : 0;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
settled = false;
|
|
211
|
+
draw();
|
|
212
|
+
kick();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function step(now: number) {
|
|
216
|
+
raf = 0;
|
|
217
|
+
if (paused || destroyed || document.hidden) return;
|
|
218
|
+
if (now - last < 1000 / P.fps - 1) {
|
|
219
|
+
raf = requestAnimationFrame(step);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
last = now;
|
|
223
|
+
if (!nextAt) nextAt = now + rnd(800, 2500);
|
|
224
|
+
if (now >= nextAt) {
|
|
225
|
+
fronts.push({
|
|
226
|
+
t: now,
|
|
227
|
+
v: (w + 2 * P.frontWidth + h * slant) / rnd(P.crossMs[0], P.crossMs[1]),
|
|
228
|
+
x: 0,
|
|
229
|
+
});
|
|
230
|
+
nextAt = now + rnd(P.everyMs[0], P.everyMs[1]);
|
|
231
|
+
}
|
|
232
|
+
for (const f of fronts) f.x = (now - f.t) * f.v - P.frontWidth - h * slant;
|
|
233
|
+
fronts = fronts.filter((f) => f.x < w + P.frontWidth);
|
|
234
|
+
let energy = 0;
|
|
235
|
+
for (let i = 0; i < n; i++) {
|
|
236
|
+
let tx = 0;
|
|
237
|
+
let ty = 0;
|
|
238
|
+
for (const f of fronts) {
|
|
239
|
+
const k = 1 - Math.abs(X[i] - f.x - (h - Y[i]) * slant) / P.frontWidth;
|
|
240
|
+
if (k > 0) {
|
|
241
|
+
const g = P.gustPx * S[i] * smooth(k);
|
|
242
|
+
tx += g;
|
|
243
|
+
ty += g * 0.25 * Math.sin(PH[i]);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
VX[i] = (VX[i] + (tx - OX[i]) * P.spring) * P.damp;
|
|
247
|
+
VY[i] = (VY[i] + (ty - OY[i]) * P.spring) * P.damp;
|
|
248
|
+
OX[i] += VX[i];
|
|
249
|
+
OY[i] += VY[i];
|
|
250
|
+
energy += Math.abs(VX[i]) + Math.abs(VY[i]) + Math.abs(OX[i]);
|
|
251
|
+
}
|
|
252
|
+
// Idle: no front on screen and every dot at rest. Stop until the next front.
|
|
253
|
+
if (!fronts.length && energy < n * 0.002) {
|
|
254
|
+
if (!settled) {
|
|
255
|
+
OX.fill(0);
|
|
256
|
+
OY.fill(0);
|
|
257
|
+
draw();
|
|
258
|
+
settled = true;
|
|
259
|
+
}
|
|
260
|
+
clearTimeout(idleTimer);
|
|
261
|
+
idleTimer = setTimeout(kick, Math.max(0, nextAt - performance.now()));
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
settled = false;
|
|
265
|
+
draw();
|
|
266
|
+
raf = requestAnimationFrame(step);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function kick() {
|
|
270
|
+
if (!raf && !paused && !destroyed && !document.hidden) raf = requestAnimationFrame(step);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function stop() {
|
|
274
|
+
cancelAnimationFrame(raf);
|
|
275
|
+
raf = 0;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const ro =
|
|
279
|
+
typeof ResizeObserver !== 'undefined'
|
|
280
|
+
? new ResizeObserver(() => {
|
|
281
|
+
clearTimeout(layoutTimer);
|
|
282
|
+
layoutTimer = setTimeout(layout, 150);
|
|
283
|
+
})
|
|
284
|
+
: null;
|
|
285
|
+
ro?.observe(host);
|
|
286
|
+
// applyTheme writes vars inline on <html>, so watch style as well as class.
|
|
287
|
+
const mo = new MutationObserver(readTheme);
|
|
288
|
+
mo.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'style'] });
|
|
289
|
+
const onVisibility = () => (document.hidden ? stop() : kick());
|
|
290
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
291
|
+
|
|
292
|
+
readTheme();
|
|
293
|
+
layout();
|
|
294
|
+
|
|
295
|
+
return {
|
|
296
|
+
pause(value: boolean) {
|
|
297
|
+
paused = value;
|
|
298
|
+
if (paused) stop();
|
|
299
|
+
else kick();
|
|
300
|
+
},
|
|
301
|
+
stats,
|
|
302
|
+
destroy() {
|
|
303
|
+
destroyed = true;
|
|
304
|
+
stop();
|
|
305
|
+
clearTimeout(idleTimer);
|
|
306
|
+
clearTimeout(layoutTimer);
|
|
307
|
+
ro?.disconnect();
|
|
308
|
+
mo.disconnect();
|
|
309
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
310
|
+
canvas.remove();
|
|
311
|
+
host.removeAttribute('data-live');
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from 'react';
|
|
10
10
|
import {
|
|
11
11
|
bindVisibleResume,
|
|
12
|
+
CHILD_FRAME_SESSION,
|
|
12
13
|
deliverSessionHandoff,
|
|
13
14
|
getLogger,
|
|
14
15
|
shellui,
|
|
@@ -19,8 +20,32 @@ import {
|
|
|
19
20
|
import { SettingsContext } from './SettingsContext';
|
|
20
21
|
import { useConfig } from '../config/useConfig';
|
|
21
22
|
import { useAuth } from '../auth/hooks/useAuth';
|
|
22
|
-
import { frameAuthPropagationOptions } from '../auth/appBackend/frameAuth';
|
|
23
23
|
import {
|
|
24
|
+
childFrameAuthPropagationOptions,
|
|
25
|
+
frameAuthPropagationOptions,
|
|
26
|
+
} from '../auth/appBackend/frameAuth';
|
|
27
|
+
import {
|
|
28
|
+
addChildFrame,
|
|
29
|
+
findChildFrame,
|
|
30
|
+
listChildFrames,
|
|
31
|
+
removeChildFrame,
|
|
32
|
+
validateChildFrameRegistration,
|
|
33
|
+
type ChildFrameEntry,
|
|
34
|
+
} from '../auth/appBackend/childFrames';
|
|
35
|
+
import { resolveFrameNavigationItem } from '../auth/appBackend/identity';
|
|
36
|
+
import { describeAppSessionFailure } from '../auth/appBackend/tokenExchange';
|
|
37
|
+
|
|
38
|
+
function safeOrigin(url: string): string {
|
|
39
|
+
try {
|
|
40
|
+
return new URL(url).origin;
|
|
41
|
+
} catch {
|
|
42
|
+
return '';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
import {
|
|
46
|
+
ensureAppBackendSession,
|
|
47
|
+
allowSilentRetry,
|
|
48
|
+
getAppBackendSessionFailure,
|
|
24
49
|
getAppBackendSession,
|
|
25
50
|
refreshAppBackendSessionIfDue,
|
|
26
51
|
subscribeAppBackendSessions,
|
|
@@ -211,10 +236,45 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
211
236
|
[config],
|
|
212
237
|
);
|
|
213
238
|
|
|
239
|
+
/** Settings for a child app hosted by an embedded app. Never carries the shell token. */
|
|
240
|
+
const pushSettingsToChildFrame = useCallback(
|
|
241
|
+
(entry: ChildFrameEntry | null, path: string[], baseSettings: Settings) => {
|
|
242
|
+
const lang = baseSettings.language?.code || 'en';
|
|
243
|
+
const settingsToPropagate = buildSettingsForPropagation(baseSettings, config, lang, {
|
|
244
|
+
...childFrameAuthPropagationOptions({
|
|
245
|
+
identity: entry?.identity ?? null,
|
|
246
|
+
getAppSession: getAppBackendSession,
|
|
247
|
+
services: entry?.services ?? null,
|
|
248
|
+
}),
|
|
249
|
+
includeLayoutChrome: false,
|
|
250
|
+
frameUuid: path[path.length - 1],
|
|
251
|
+
});
|
|
252
|
+
shellui.sendMessage({
|
|
253
|
+
type: 'SHELLUI_SETTINGS',
|
|
254
|
+
payload: { settings: settingsToPropagate },
|
|
255
|
+
to: path,
|
|
256
|
+
});
|
|
257
|
+
},
|
|
258
|
+
[config],
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
const propagateSettingsToChildFrames = useCallback(
|
|
262
|
+
(baseSettings: Settings) => {
|
|
263
|
+
const live = new Set(shellui.frameRegistry.getLiveIframes().map(([uuid]) => uuid));
|
|
264
|
+
const known = new Set(shellui.frameRegistry.getAllIframes().map(([uuid]) => uuid));
|
|
265
|
+
for (const entry of listChildFrames((uuid) => known.has(uuid))) {
|
|
266
|
+
if (!live.has(entry.hostUuid)) continue;
|
|
267
|
+
pushSettingsToChildFrame(entry, [entry.hostUuid, entry.frameId], baseSettings);
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
[pushSettingsToChildFrame],
|
|
271
|
+
);
|
|
272
|
+
|
|
214
273
|
const propagateSettingsToIframes = useCallback(
|
|
215
274
|
(baseSettings: Settings) => {
|
|
216
275
|
const iframes = shellui.frameRegistry.getLiveIframes();
|
|
217
276
|
if (iframes.length === 0) return;
|
|
277
|
+
propagateSettingsToChildFrames(baseSettings);
|
|
218
278
|
const lang = baseSettings.language?.code || 'en';
|
|
219
279
|
for (const [uuid, iframe] of iframes) {
|
|
220
280
|
const frameSrc = iframe?.src ?? '';
|
|
@@ -230,7 +290,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
230
290
|
});
|
|
231
291
|
}
|
|
232
292
|
},
|
|
233
|
-
[authOptionsForFrame, config],
|
|
293
|
+
[authOptionsForFrame, config, propagateSettingsToChildFrames],
|
|
234
294
|
);
|
|
235
295
|
|
|
236
296
|
const pushSettingsToFrame = useCallback(
|
|
@@ -502,6 +562,26 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
502
562
|
.getAllIframes()
|
|
503
563
|
.find(([uuid]) => uuid === firstHopIframeUuid)?.[1]
|
|
504
564
|
: undefined;
|
|
565
|
+
// A child app hosted by an embedded app gets its own session, never the host's.
|
|
566
|
+
const childEntry = findChildFrame(requestingPath);
|
|
567
|
+
const hostEmbedsApps = Boolean(
|
|
568
|
+
requestingFrame?.src &&
|
|
569
|
+
resolveFrameNavigationItem(requestingFrame.src, config)?.childFrames,
|
|
570
|
+
);
|
|
571
|
+
const isHostedChild = requestingPath.length > 1 && (childEntry || hostEmbedsApps);
|
|
572
|
+
if (isHostedChild) {
|
|
573
|
+
if (childEntry?.identity) {
|
|
574
|
+
await ensureAppBackendSession(childEntry.identity, { allowSilent: true });
|
|
575
|
+
}
|
|
576
|
+
deliverSessionHandoff(() =>
|
|
577
|
+
pushSettingsToChildFrame(
|
|
578
|
+
childEntry,
|
|
579
|
+
requestingPath,
|
|
580
|
+
settingsRef.current ?? defaultSettings,
|
|
581
|
+
),
|
|
582
|
+
);
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
505
585
|
if (requestingFrame?.src) {
|
|
506
586
|
await refreshAppBackendSessionIfDue(requestingFrame.src, config);
|
|
507
587
|
}
|
|
@@ -589,13 +669,89 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
589
669
|
},
|
|
590
670
|
);
|
|
591
671
|
|
|
672
|
+
const cleanupChildRegister = shellui.addMessageListener(
|
|
673
|
+
'SHELLUI_CHILD_FRAME_REGISTER',
|
|
674
|
+
(message: ShellUIMessage) => {
|
|
675
|
+
if (typeof window === 'undefined' || window.parent !== window) return;
|
|
676
|
+
const from = (message.from ?? []).filter(Boolean);
|
|
677
|
+
const hostSrc = shellui.frameRegistry
|
|
678
|
+
.getAllIframes()
|
|
679
|
+
.find(([uuid]) => uuid === from[0])?.[1]?.src;
|
|
680
|
+
const result = validateChildFrameRegistration({
|
|
681
|
+
from,
|
|
682
|
+
hostSrc,
|
|
683
|
+
payload: message.payload,
|
|
684
|
+
config,
|
|
685
|
+
});
|
|
686
|
+
if (!result.ok) {
|
|
687
|
+
logger.warn('Rejected a child app frame', { reason: result.reason });
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
addChildFrame(result.entry);
|
|
691
|
+
const { entry } = result;
|
|
692
|
+
if (entry.rejectedServices.length) {
|
|
693
|
+
// Keys only: the URLs themselves stay out of the log.
|
|
694
|
+
logger.warn('Dropped child app service URLs not in childFrames.serviceOrigins', {
|
|
695
|
+
origin: safeOrigin(entry.url),
|
|
696
|
+
services: entry.rejectedServices,
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
logger.info('Child app frame registered', {
|
|
700
|
+
origin: safeOrigin(entry.url),
|
|
701
|
+
identity: entry.identity?.url ?? null,
|
|
702
|
+
companyId: entry.identity?.companyId ?? null,
|
|
703
|
+
});
|
|
704
|
+
void (async () => {
|
|
705
|
+
let ok = true;
|
|
706
|
+
let reason: string | null = null;
|
|
707
|
+
if (entry.identity) {
|
|
708
|
+
// A (re)registration is a fresh mount or a user retry: allow one more silent try.
|
|
709
|
+
allowSilentRetry(entry.identity.key);
|
|
710
|
+
const token = await ensureAppBackendSession(entry.identity, { allowSilent: true });
|
|
711
|
+
ok = Boolean(token);
|
|
712
|
+
reason = ok ? null : (getAppBackendSessionFailure(entry.identity.key) ?? 'no_session');
|
|
713
|
+
}
|
|
714
|
+
shellui.sendMessage({
|
|
715
|
+
type: CHILD_FRAME_SESSION,
|
|
716
|
+
payload: {
|
|
717
|
+
frameId: entry.frameId,
|
|
718
|
+
ok,
|
|
719
|
+
...(reason ? { reason, hint: describeAppSessionFailure(reason) } : {}),
|
|
720
|
+
} as unknown as ShellUIMessage['payload'],
|
|
721
|
+
to: [entry.hostUuid],
|
|
722
|
+
});
|
|
723
|
+
logger.info('Child app frame session', { origin: safeOrigin(entry.url), ok, reason });
|
|
724
|
+
deliverSessionHandoff(() =>
|
|
725
|
+
pushSettingsToChildFrame(
|
|
726
|
+
entry,
|
|
727
|
+
[entry.hostUuid, entry.frameId],
|
|
728
|
+
settingsRef.current ?? defaultSettings,
|
|
729
|
+
),
|
|
730
|
+
);
|
|
731
|
+
})();
|
|
732
|
+
},
|
|
733
|
+
);
|
|
734
|
+
|
|
735
|
+
const cleanupChildUnregister = shellui.addMessageListener(
|
|
736
|
+
'SHELLUI_CHILD_FRAME_UNREGISTER',
|
|
737
|
+
(message: ShellUIMessage) => {
|
|
738
|
+
const from = (message.from ?? []).filter(Boolean);
|
|
739
|
+
const frameId = (message.payload as { frameId?: unknown } | null)?.frameId;
|
|
740
|
+
if (from.length !== 1 || typeof frameId !== 'string') return;
|
|
741
|
+
removeChildFrame(from[0], frameId);
|
|
742
|
+
},
|
|
743
|
+
);
|
|
744
|
+
|
|
592
745
|
return () => {
|
|
593
746
|
cleanup();
|
|
594
747
|
cleanupSettings();
|
|
595
748
|
cleanupSettingsRequested();
|
|
596
749
|
cleanupInitialized();
|
|
750
|
+
cleanupChildRegister();
|
|
751
|
+
cleanupChildUnregister();
|
|
597
752
|
};
|
|
598
753
|
}, [
|
|
754
|
+
pushSettingsToChildFrame,
|
|
599
755
|
authOptionsForFrame,
|
|
600
756
|
config,
|
|
601
757
|
applyHandoffToken,
|
|
@@ -287,25 +287,26 @@ describe('buildSettingsForPropagation', () => {
|
|
|
287
287
|
expect(result.email).toEqual({ url: 'http://localhost:8003' });
|
|
288
288
|
});
|
|
289
289
|
|
|
290
|
-
it('
|
|
290
|
+
it('sends no email when email is set without url (no built-in default)', () => {
|
|
291
291
|
const config = {
|
|
292
292
|
email: {},
|
|
293
293
|
} as ShellUIConfig;
|
|
294
294
|
|
|
295
295
|
const result = buildSettingsForPropagation(baseSettings, config, 'en');
|
|
296
|
-
expect(result.email).
|
|
296
|
+
expect(result.email).toBeNull();
|
|
297
297
|
});
|
|
298
298
|
|
|
299
|
-
it('propagates showInAdmin false for email
|
|
299
|
+
it('propagates showInAdmin false for email', () => {
|
|
300
300
|
const config = {
|
|
301
301
|
email: {
|
|
302
|
+
url: 'http://localhost:8003',
|
|
302
303
|
showInAdmin: false,
|
|
303
304
|
},
|
|
304
305
|
} as ShellUIConfig;
|
|
305
306
|
|
|
306
307
|
const result = buildSettingsForPropagation(baseSettings, config, 'en');
|
|
307
308
|
expect(result.email).toEqual({
|
|
308
|
-
url: '
|
|
309
|
+
url: 'http://localhost:8003',
|
|
309
310
|
showInAdmin: false,
|
|
310
311
|
});
|
|
311
312
|
});
|
|
@@ -560,7 +561,7 @@ describe('buildSettingsForPropagation', () => {
|
|
|
560
561
|
expect(json).not.toContain('https://email.shellui.com');
|
|
561
562
|
});
|
|
562
563
|
|
|
563
|
-
it('
|
|
564
|
+
it('sends no email when a foreign app sets an empty email object', () => {
|
|
564
565
|
const withEmptyEmail = {
|
|
565
566
|
...appConfig,
|
|
566
567
|
navigation: (appConfig.navigation ?? []).map((item) =>
|
|
@@ -580,7 +581,7 @@ describe('buildSettingsForPropagation', () => {
|
|
|
580
581
|
'en',
|
|
581
582
|
options,
|
|
582
583
|
);
|
|
583
|
-
expect(result.email).
|
|
584
|
+
expect(result.email).toBeNull();
|
|
584
585
|
expect(result.storage).toBeNull();
|
|
585
586
|
expect(result.hosting).toBeNull();
|
|
586
587
|
const json = JSON.stringify(result);
|
|
@@ -618,7 +619,7 @@ describe('buildSettingsForPropagation', () => {
|
|
|
618
619
|
);
|
|
619
620
|
expect(result.accessToken).toBe(shellToken);
|
|
620
621
|
expect(result.authBackendBaseUrl).toBe('https://id.example.com');
|
|
621
|
-
expect(result.email).
|
|
622
|
+
expect(result.email).toBeNull();
|
|
622
623
|
expect(result.storage).toEqual(shellServices.storage);
|
|
623
624
|
expect(result.hosting).toEqual(shellServices.hosting);
|
|
624
625
|
});
|
|
@@ -15,15 +15,13 @@ import {
|
|
|
15
15
|
getPublishedLayoutChrome,
|
|
16
16
|
} from '../../layouts/floating/layoutChromeStore';
|
|
17
17
|
|
|
18
|
-
/** Production email-service origin. No trailing slash. */
|
|
19
|
-
const DEFAULT_EMAIL_SERVICE_URL = 'https://email.shellui.com';
|
|
20
|
-
|
|
21
18
|
const propagateEmail = (email: EmailConfig | null | undefined): SettingsEmail | null => {
|
|
22
|
-
|
|
23
|
-
const url = email
|
|
19
|
+
// No built-in default: email must come from config or the host app.
|
|
20
|
+
const url = email?.url?.trim().replace(/\/+$/, '') || null;
|
|
21
|
+
if (!url) return null;
|
|
24
22
|
return {
|
|
25
23
|
url,
|
|
26
|
-
...(email
|
|
24
|
+
...(email?.showInAdmin === false ? { showInAdmin: false } : {}),
|
|
27
25
|
};
|
|
28
26
|
};
|
|
29
27
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { toCssVarValue } from './color';
|
|
2
2
|
import type { ThemeColorsMode, ThemeDefinition } from './types';
|
|
3
3
|
import { isHomeScreenPwa, isTauriRuntime } from '../layouts/chrome/runtime';
|
|
4
|
+
import { isLowNavContrast, NAV_CONTRAST_ATTR } from './navContrast';
|
|
4
5
|
|
|
5
6
|
const COLOR_VAR_MAP: Array<[keyof ThemeColorsMode, string]> = [
|
|
6
7
|
['background', '--background'],
|
|
@@ -95,6 +96,13 @@ export function applyTheme(theme: ThemeDefinition, isDark: boolean): void {
|
|
|
95
96
|
|
|
96
97
|
root.style.setProperty('--radius', colors.radius);
|
|
97
98
|
|
|
99
|
+
// Solid active pill under 4.5:1 in this mode: chrome switches to a tinted pill.
|
|
100
|
+
if (isLowNavContrast(colors.sidebarPrimary, colors.sidebarPrimaryForeground)) {
|
|
101
|
+
root.setAttribute(NAV_CONTRAST_ATTR, 'low');
|
|
102
|
+
} else {
|
|
103
|
+
root.removeAttribute(NAV_CONTRAST_ATTR);
|
|
104
|
+
}
|
|
105
|
+
|
|
98
106
|
// Browser-tab chrome only — see syncThemeColorMeta (skipped for PWA / Tauri).
|
|
99
107
|
syncThemeColorMeta(toCssVarValue(colors.background) || (isDark ? '#000000' : '#ffffff'));
|
|
100
108
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { contrastRatio, isLowNavContrast, parseThemeColor } from './navContrast';
|
|
4
|
+
import { curatedThemes } from './themes';
|
|
5
|
+
import { applyTheme } from './applyTheme';
|
|
6
|
+
|
|
7
|
+
describe('navContrast', () => {
|
|
8
|
+
it('parses oklch, hex and hsl', () => {
|
|
9
|
+
expect(parseThemeColor('oklch(1 0 0)')).toEqual([1, 1, 1]);
|
|
10
|
+
expect(parseThemeColor('#000000')).toEqual([0, 0, 0]);
|
|
11
|
+
expect(parseThemeColor('0 0% 100%')?.map((n) => Math.round(n))).toEqual([1, 1, 1]);
|
|
12
|
+
expect(parseThemeColor('hsl(0 0% 0%)')).toEqual([0, 0, 0]);
|
|
13
|
+
expect(parseThemeColor('var(--x)')).toBeNull();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('computes WCAG ratios', () => {
|
|
17
|
+
expect(contrastRatio('#000000', '#ffffff')).toBeCloseTo(21, 1);
|
|
18
|
+
expect(contrastRatio('nope', '#ffffff')).toBeNull();
|
|
19
|
+
expect(isLowNavContrast('nope', '#ffffff')).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('keeps the solid pill on shellui and flags the low curated modes (37 from the audit, plus quantum-rose light at 4.497:1)', () => {
|
|
23
|
+
const low: string[] = [];
|
|
24
|
+
for (const theme of curatedThemes) {
|
|
25
|
+
for (const mode of ['light', 'dark'] as const) {
|
|
26
|
+
const c = theme.colors[mode];
|
|
27
|
+
if (isLowNavContrast(c.sidebarPrimary, c.sidebarPrimaryForeground)) {
|
|
28
|
+
low.push(`${theme.name}:${mode}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
expect(low).not.toContain('shellui:light');
|
|
33
|
+
expect(low).not.toContain('shellui:dark');
|
|
34
|
+
expect(low).toContain('twitter:light');
|
|
35
|
+
expect(low).toContain('amber-minimal:dark');
|
|
36
|
+
expect(low).toContain('quantum-rose:light');
|
|
37
|
+
expect(low).toHaveLength(38);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('applyTheme sets and clears the attribute on <html>', () => {
|
|
41
|
+
const twitter = curatedThemes.find((t) => t.name === 'twitter');
|
|
42
|
+
const shellui = curatedThemes.find((t) => t.name === 'shellui');
|
|
43
|
+
if (!twitter || !shellui) throw new Error('curated themes twitter and shellui are required');
|
|
44
|
+
applyTheme({ ...twitter, fontFiles: [] }, false);
|
|
45
|
+
expect(document.documentElement.getAttribute('data-shellui-nav-contrast')).toBe('low');
|
|
46
|
+
applyTheme({ ...shellui, fontFiles: [] }, false);
|
|
47
|
+
expect(document.documentElement.hasAttribute('data-shellui-nav-contrast')).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
});
|