@shellui/core 0.7.0-alpha.10 → 0.7.0-alpha.12

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.
Files changed (46) hide show
  1. package/package.json +2 -2
  2. package/src/components/ui/drawer.tsx +47 -30
  3. package/src/components/ui/sheet.tsx +18 -12
  4. package/src/components/ui/shell-divider.spec.tsx +63 -0
  5. package/src/components/ui/shell-divider.tsx +20 -0
  6. package/src/components/ui/sidebar.tsx +15 -7
  7. package/src/components/ui/tooltip.tsx +4 -2
  8. package/src/features/auth/components/LoginButton.spec.tsx +203 -0
  9. package/src/features/auth/components/LoginButton.tsx +77 -28
  10. package/src/features/auth/components/LoginButtonIcons.tsx +4 -8
  11. package/src/features/chromeActions/ChromeActionsHost.tsx +5 -1
  12. package/src/features/layouts/OverlayShell.tsx +58 -40
  13. package/src/features/layouts/appbar/AppBarItemIcon.spec.tsx +45 -0
  14. package/src/features/layouts/appbar/AppBarItemIcon.tsx +19 -0
  15. package/src/features/layouts/appbar/AppBarLayout.tsx +53 -81
  16. package/src/features/layouts/appbar/appBarOverflow.spec.ts +27 -0
  17. package/src/features/layouts/appbar/appBarOverflow.ts +42 -0
  18. package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +1 -1
  19. package/src/features/layouts/chrome/constants.ts +3 -0
  20. package/src/features/layouts/chrome/viewport.ts +11 -4
  21. package/src/features/layouts/floating/FloatingBottomDock.tsx +67 -26
  22. package/src/features/layouts/floating/FloatingLayout.tsx +1 -0
  23. package/src/features/layouts/floating/FloatingSidebar.tsx +43 -20
  24. package/src/features/layouts/floating/moreSections.spec.ts +28 -0
  25. package/src/features/layouts/floating/moreSections.ts +31 -0
  26. package/src/features/layouts/fullscreen/FullscreenLayout.spec.tsx +68 -0
  27. package/src/features/layouts/fullscreen/FullscreenLayout.tsx +10 -1
  28. package/src/features/layouts/sidebar/NavigationContent.tsx +4 -4
  29. package/src/features/layouts/sidebar/SidebarIcons.tsx +67 -0
  30. package/src/features/layouts/sidebar/SidebarInner.spec.tsx +149 -0
  31. package/src/features/layouts/sidebar/SidebarInner.tsx +60 -11
  32. package/src/features/layouts/sidebar/SidebarLayout.tsx +23 -13
  33. package/src/features/layouts/windows/WindowsLayout.tsx +93 -47
  34. package/src/features/layouts/windows/deskDots.spec.ts +6 -4
  35. package/src/features/layouts/windows/deskDots.ts +8 -8
  36. package/src/features/overlays/ResponsiveModal.tsx +5 -3
  37. package/src/features/overlays/overlaySize.spec.ts +56 -16
  38. package/src/features/overlays/overlaySize.ts +114 -31
  39. package/src/features/overlays/phoneDrawerAnchoring.spec.ts +187 -0
  40. package/src/features/overlays/useOverlayReportedSize.ts +8 -3
  41. package/src/i18n/translations/en/common.json +1 -0
  42. package/src/i18n/translations/fr/common.json +1 -0
  43. package/src/index.css +232 -42
  44. package/src/service-worker/devCaches.spec.ts +32 -0
  45. package/src/service-worker/devCaches.ts +27 -0
  46. package/src/service-worker/sw-dev.ts +23 -23
@@ -0,0 +1,32 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { devCacheNames, isStaleDevCache } from './devCaches';
3
+
4
+ describe('dev service worker caches', () => {
5
+ it('names image, font and html caches after the core version', () => {
6
+ expect(devCacheNames('1.2.3')).toEqual({
7
+ images: 'shellui-dev-images-1.2.3',
8
+ fonts: 'shellui-dev-fonts-1.2.3',
9
+ html: 'shellui-dev-html-1.2.3',
10
+ });
11
+ });
12
+
13
+ it('has no cache for scripts or styles', () => {
14
+ expect(Object.keys(devCacheNames('1.2.3'))).not.toContain('static-resources');
15
+ });
16
+
17
+ it('drops unversioned caches and caches from another version', () => {
18
+ for (const name of ['images', 'html-cache', 'static-resources', 'fonts']) {
19
+ expect(isStaleDevCache(name, '1.2.3')).toBe(true);
20
+ }
21
+ expect(isStaleDevCache('shellui-dev-images-1.2.2', '1.2.3')).toBe(true);
22
+ expect(isStaleDevCache('shellui-dev-static-1.2.3', '1.2.3')).toBe(true);
23
+ });
24
+
25
+ it('keeps current caches and caches it does not own', () => {
26
+ for (const name of Object.values(devCacheNames('1.2.3'))) {
27
+ expect(isStaleDevCache(name, '1.2.3')).toBe(false);
28
+ }
29
+ expect(isStaleDevCache('workbox-precache-v2-http://localhost/', '1.2.3')).toBe(false);
30
+ expect(isStaleDevCache('api-cache', '1.2.3')).toBe(false);
31
+ });
32
+ });
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Cache names for the dev service worker (`shellui start`).
3
+ *
4
+ * Vite serves the shell at the same URLs in every version (`/index.css`,
5
+ * `/main.tsx`, `/features/...`), so the dev worker never caches scripts or
6
+ * styles. Images, fonts and the offline HTML fallback use caches named after
7
+ * the core version, so an upgrade drops the previous ones.
8
+ */
9
+ const DEV_CACHE_PREFIX = 'shellui-dev-';
10
+
11
+ /** Unversioned names written by older dev workers. */
12
+ const LEGACY_DEV_CACHES = ['images', 'html-cache', 'static-resources', 'fonts'];
13
+
14
+ export function devCacheNames(version: string) {
15
+ return {
16
+ images: `${DEV_CACHE_PREFIX}images-${version}`,
17
+ fonts: `${DEV_CACHE_PREFIX}fonts-${version}`,
18
+ html: `${DEV_CACHE_PREFIX}html-${version}`,
19
+ };
20
+ }
21
+
22
+ /** True for a cache an older dev worker left behind. */
23
+ export function isStaleDevCache(name: string, version: string): boolean {
24
+ if (LEGACY_DEV_CACHES.includes(name)) return true;
25
+ if (!name.startsWith(DEV_CACHE_PREFIX)) return false;
26
+ return !Object.values(devCacheNames(version)).includes(name);
27
+ }
@@ -2,26 +2,31 @@
2
2
 
3
3
  import { cleanupOutdatedCaches } from 'workbox-precaching';
4
4
  import { registerRoute } from 'workbox-routing';
5
- import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies';
5
+ import { CacheFirst, NetworkFirst } from 'workbox-strategies';
6
6
  import { CacheableResponsePlugin } from 'workbox-cacheable-response';
7
7
  import { ExpirationPlugin } from 'workbox-expiration';
8
8
  import { getLogger } from '@shellui/sdk';
9
+ import { version as coreVersion } from '../../package.json';
10
+ import { devCacheNames, isStaleDevCache } from './devCaches';
9
11
 
10
12
  const _logger = getLogger('shellcore');
11
13
 
12
14
  declare const self: ServiceWorkerGlobalScope;
13
15
 
16
+ const CACHE = devCacheNames(coreVersion);
17
+
14
18
  // Clean up old caches
15
19
  cleanupOutdatedCaches();
16
20
 
17
- // In dev mode, we don't precache (no manifest available)
18
- // But we can still cache resources on-demand
21
+ // In dev mode, we don't precache (no manifest available).
22
+ // Scripts, styles and workers always come from the dev server: Vite serves them at
23
+ // the same URLs in every version, so a cached copy would show an older shell.
19
24
 
20
25
  // Cache images with CacheFirst strategy
21
26
  registerRoute(
22
27
  ({ request }) => request.destination === 'image',
23
28
  new CacheFirst({
24
- cacheName: 'images',
29
+ cacheName: CACHE.images,
25
30
  plugins: [
26
31
  new CacheableResponsePlugin({
27
32
  statuses: [0, 200],
@@ -38,23 +43,7 @@ registerRoute(
38
43
  registerRoute(
39
44
  ({ request }) => request.destination === 'document',
40
45
  new NetworkFirst({
41
- cacheName: 'html-cache',
42
- plugins: [
43
- new CacheableResponsePlugin({
44
- statuses: [0, 200],
45
- }),
46
- ],
47
- }),
48
- );
49
-
50
- // Cache CSS and JS files with StaleWhileRevalidate
51
- registerRoute(
52
- ({ request }) =>
53
- request.destination === 'style' ||
54
- request.destination === 'script' ||
55
- request.destination === 'worker',
56
- new StaleWhileRevalidate({
57
- cacheName: 'static-resources',
46
+ cacheName: CACHE.html,
58
47
  plugins: [
59
48
  new CacheableResponsePlugin({
60
49
  statuses: [0, 200],
@@ -67,7 +56,7 @@ registerRoute(
67
56
  registerRoute(
68
57
  ({ request }) => request.destination === 'font',
69
58
  new CacheFirst({
70
- cacheName: 'fonts',
59
+ cacheName: CACHE.fonts,
71
60
  plugins: [
72
61
  new CacheableResponsePlugin({
73
62
  statuses: [0, 200],
@@ -87,5 +76,16 @@ self.addEventListener('message', (event) => {
87
76
  });
88
77
 
89
78
  self.addEventListener('activate', (event) => {
90
- event.waitUntil(self.clients.claim());
79
+ event.waitUntil(
80
+ (async () => {
81
+ // Drop caches from older dev workers (unversioned names or another core version).
82
+ const names = await caches.keys();
83
+ await Promise.all(
84
+ names
85
+ .filter((name) => isStaleDevCache(name, coreVersion))
86
+ .map((name) => caches.delete(name)),
87
+ );
88
+ await self.clients.claim();
89
+ })(),
90
+ );
91
91
  });