@tuturuuu/ui 0.19.1 → 0.20.1

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 (50) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/biome.json +1 -1
  3. package/package.json +56 -48
  4. package/src/components/ui/badge.tsx +2 -0
  5. package/src/components/ui/button.tsx +2 -0
  6. package/src/components/ui/custom/__tests__/settings-dialog-shell.test.tsx +48 -4
  7. package/src/components/ui/custom/__tests__/workspace-select-helpers.test.ts +22 -0
  8. package/src/components/ui/custom/animated-slot-text.tsx +20 -0
  9. package/src/components/ui/custom/common-footer.tsx +262 -237
  10. package/src/components/ui/custom/language-dropdown-item.tsx +3 -10
  11. package/src/components/ui/custom/language-toggle.test.tsx +30 -0
  12. package/src/components/ui/custom/language-toggle.tsx +11 -10
  13. package/src/components/ui/custom/locale-preference.ts +32 -0
  14. package/src/components/ui/custom/settings/appearance-settings.tsx +5 -13
  15. package/src/components/ui/custom/settings-dialog-shell.tsx +40 -9
  16. package/src/components/ui/custom/structure.tsx +12 -0
  17. package/src/components/ui/custom/system-language-dropdown-item.tsx +3 -6
  18. package/src/components/ui/custom/workspace-access/adapters.test.ts +10 -1
  19. package/src/components/ui/custom/workspace-access/adapters.ts +36 -4
  20. package/src/components/ui/custom/workspace-access/member-filter-utils.test.ts +14 -0
  21. package/src/components/ui/custom/workspace-access/member-filter-utils.ts +8 -0
  22. package/src/components/ui/custom/workspace-access/types.ts +20 -0
  23. package/src/components/ui/custom/workspace-access/workspace-access-context.test.tsx +111 -0
  24. package/src/components/ui/custom/workspace-access/workspace-access-default-role-card.tsx +15 -5
  25. package/src/components/ui/custom/workspace-access/workspace-access-invite-dialog.tsx +155 -48
  26. package/src/components/ui/custom/workspace-access/workspace-access-member-profile-dialog.tsx +92 -0
  27. package/src/components/ui/custom/workspace-access/workspace-access-member-row.tsx +171 -76
  28. package/src/components/ui/custom/workspace-access/workspace-access-members.tsx +11 -2
  29. package/src/components/ui/custom/workspace-access/workspace-access-page-header.tsx +11 -11
  30. package/src/components/ui/custom/workspace-access/workspace-access-page.tsx +180 -22
  31. package/src/components/ui/custom/workspace-access/workspace-access-people-filters.tsx +29 -15
  32. package/src/components/ui/custom/workspace-access/workspace-access-permission-checklist.tsx +56 -10
  33. package/src/components/ui/custom/workspace-access/workspace-access-permission-preview.test.ts +33 -0
  34. package/src/components/ui/custom/workspace-access/workspace-access-permission-preview.tsx +24 -1
  35. package/src/components/ui/custom/workspace-access/workspace-access-responsive.test.ts +64 -0
  36. package/src/components/ui/custom/workspace-access/workspace-access-role-editor-dialog.tsx +28 -16
  37. package/src/components/ui/custom/workspace-access/workspace-access-roles.tsx +35 -11
  38. package/src/components/ui/custom/workspace-access/workspace-access-tabs-toolbar.tsx +23 -11
  39. package/src/components/ui/custom/workspace-select-helpers.ts +5 -3
  40. package/src/components/ui/custom/workspace-select.tsx +8 -2
  41. package/src/components/ui/finance/shared/charts/monthly-total-chart-client.tsx +1 -1
  42. package/src/components/ui/finance/shared/charts/monthly-total-chart.tsx +1 -1
  43. package/src/components/ui/storefront/cart-summary.tsx +12 -2
  44. package/src/components/ui/storefront/storefront-surface.test.tsx +21 -0
  45. package/src/components/ui/storefront/storefront-surface.tsx +6 -0
  46. package/src/components/ui/text-editor/__tests__/collaboration-binding.test.tsx +161 -0
  47. package/src/components/ui/text-editor/editor.tsx +267 -235
  48. package/src/globals.css +166 -0
  49. package/src/hooks/__tests__/use-workspace-identity-mutation.test.tsx +181 -0
  50. package/src/hooks/use-workspace-identity-mutation.ts +136 -0
package/src/globals.css CHANGED
@@ -442,6 +442,172 @@
442
442
  --animate-accordion-up: accordion-up 0.2s ease-out;
443
443
  --animate-aurora: aurora 80s linear infinite;
444
444
  --animate-shake: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
445
+ --animate-bloom-drift: bloom-drift 24s ease-in-out infinite;
446
+ --animate-bloom-drift-slow: bloom-drift-slow 32s ease-in-out infinite;
447
+ --animate-sheen: sheen 6s ease-in-out infinite;
448
+ --animate-rise-in: rise-in 0.9s cubic-bezier(0.16, 1, 0.3, 1) both;
449
+ --animate-text-sheen: text-sheen 8s ease-in-out infinite;
450
+ --animate-marquee: marquee 40s linear infinite;
451
+ --animate-float-y: float-y 6s ease-in-out infinite;
452
+ --animate-scroll-cue: scroll-cue 2.2s ease-in-out infinite;
453
+ --animate-ring-pulse: ring-pulse 3s ease-out infinite;
454
+ --animate-day-scan: day-scan 9s ease-in-out infinite;
455
+
456
+ /* Marketing type scale. The variables resolve only where the marketing
457
+ layout loads the fonts; everywhere else these fall back to the app font. */
458
+ /* The inner fallbacks matter: apps that do not load the marketing faces
459
+ (nova, meet) would otherwise hit an undefined var and drop the whole
460
+ font-family declaration. */
461
+ --font-display:
462
+ var(--font-be-vietnam-pro, ui-sans-serif), ui-sans-serif, system-ui,
463
+ sans-serif;
464
+ --font-mono-ui:
465
+ var(--font-jetbrains-mono, ui-monospace), ui-monospace, SFMono-Regular,
466
+ Menlo, monospace;
467
+ }
468
+
469
+ /* Marketing atmosphere: slow, low-amplitude drift for hero light blooms. */
470
+ @keyframes bloom-drift {
471
+ 0%,
472
+ 100% {
473
+ transform: translate3d(0, 0, 0) scale(1);
474
+ }
475
+ 50% {
476
+ transform: translate3d(4%, -3%, 0) scale(1.08);
477
+ }
478
+ }
479
+
480
+ @keyframes bloom-drift-slow {
481
+ 0%,
482
+ 100% {
483
+ transform: translate3d(0, 0, 0) scale(1.05);
484
+ }
485
+ 50% {
486
+ transform: translate3d(-5%, 4%, 0) scale(1);
487
+ }
488
+ }
489
+
490
+ @keyframes sheen {
491
+ 0%,
492
+ 100% {
493
+ opacity: 0.35;
494
+ }
495
+ 50% {
496
+ opacity: 0.75;
497
+ }
498
+ }
499
+
500
+ /* Hero entrance. Paired with an inline animation-delay for stagger, so the
501
+ choreography needs no JavaScript and runs before hydration. */
502
+ @keyframes rise-in {
503
+ from {
504
+ opacity: 0;
505
+ transform: translate3d(0, 24px, 0);
506
+ filter: blur(12px);
507
+ }
508
+ to {
509
+ opacity: 1;
510
+ transform: translate3d(0, 0, 0);
511
+ filter: blur(0);
512
+ }
513
+ }
514
+
515
+ /* Slow light travelling through gradient headline text. */
516
+ @keyframes text-sheen {
517
+ 0%,
518
+ 100% {
519
+ background-position: 0% 50%;
520
+ }
521
+ 50% {
522
+ background-position: 100% 50%;
523
+ }
524
+ }
525
+
526
+ /* Product marquee: the track holds two identical halves, so -50% loops
527
+ seamlessly. */
528
+ @keyframes marquee {
529
+ from {
530
+ transform: translate3d(0, 0, 0);
531
+ }
532
+ to {
533
+ transform: translate3d(-50%, 0, 0);
534
+ }
535
+ }
536
+
537
+ @keyframes float-y {
538
+ 0%,
539
+ 100% {
540
+ transform: translate3d(0, 0, 0);
541
+ }
542
+ 50% {
543
+ transform: translate3d(0, -10px, 0);
544
+ }
545
+ }
546
+
547
+ @keyframes scroll-cue {
548
+ 0% {
549
+ opacity: 0;
550
+ transform: translate3d(0, -6px, 0);
551
+ }
552
+ 40% {
553
+ opacity: 1;
554
+ }
555
+ 100% {
556
+ opacity: 0;
557
+ transform: translate3d(0, 10px, 0);
558
+ }
559
+ }
560
+
561
+ /* Restless light crossing the fragmented day on the landing page. Driving
562
+ background-position (rather than a transform) keeps the highlight clipped to
563
+ the strip, so it never has to be masked. Symmetric endpoints let it sweep
564
+ out and back on one eased loop with no seam. */
565
+ @keyframes day-scan {
566
+ 0%,
567
+ 100% {
568
+ background-position: 130% 0;
569
+ }
570
+ 50% {
571
+ background-position: -30% 0;
572
+ }
573
+ }
574
+
575
+ @keyframes ring-pulse {
576
+ 0% {
577
+ opacity: 0.6;
578
+ transform: scale(0.85);
579
+ }
580
+ 100% {
581
+ opacity: 0;
582
+ transform: scale(1.6);
583
+ }
584
+ }
585
+
586
+ /* Global guard: the marketing atmosphere and entrance choreography are
587
+ decorative, so drop them entirely when the user asks for less motion. */
588
+ @media (prefers-reduced-motion: reduce) {
589
+ .animate-rise-in,
590
+ .animate-text-sheen,
591
+ .animate-marquee,
592
+ .animate-float-y,
593
+ .animate-scroll-cue,
594
+ .animate-ring-pulse,
595
+ .animate-day-scan,
596
+ .animate-bloom-drift,
597
+ .animate-bloom-drift-slow,
598
+ .animate-sheen,
599
+ .animate-aurora {
600
+ /*
601
+ * Cancelling the animation is enough, and is all we should do. These
602
+ * elements carry layout transforms (`-translate-x-1/2` centres the hero
603
+ * blooms) and deliberate opacities (blooms sit at 40-60%), so forcing
604
+ * `transform: none` / `opacity: 1` here would shift them off-centre and
605
+ * blow out their brightness. Entrance keyframes use `both`, so removing
606
+ * the animation simply leaves the element in its natural, final state.
607
+ */
608
+ /* biome-ignore lint/complexity/noImportantStyles: must beat utility-class animations for accessibility */
609
+ animation: none !important;
610
+ }
445
611
  }
446
612
 
447
613
  /* Aurora animation - must be outside @theme block */
@@ -0,0 +1,181 @@
1
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
2
+ import { act, renderHook, waitFor } from '@testing-library/react';
3
+ import type { ReactNode } from 'react';
4
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
5
+ import {
6
+ patchWorkspaceCacheValue,
7
+ useUpdateWorkspaceIdentity,
8
+ } from '../use-workspace-identity-mutation';
9
+
10
+ const WS_ID = 'ws-1';
11
+
12
+ const mocks = vi.hoisted(() => ({
13
+ refresh: vi.fn(),
14
+ updateWorkspace: vi.fn(),
15
+ }));
16
+
17
+ vi.mock('next/navigation', () => ({
18
+ useRouter: () => ({ refresh: mocks.refresh }),
19
+ }));
20
+
21
+ vi.mock('@tuturuuu/internal-api/workspaces', () => ({
22
+ updateWorkspace: (...args: unknown[]) => mocks.updateWorkspace(...args),
23
+ }));
24
+
25
+ function createHarness() {
26
+ const queryClient = new QueryClient({
27
+ defaultOptions: { queries: { retry: false } },
28
+ });
29
+
30
+ // The surfaces that show a workspace name, as each one caches it.
31
+ queryClient.setQueryData(
32
+ ['workspaces'],
33
+ [
34
+ { id: WS_ID, name: 'Old name' },
35
+ { id: 'ws-2', name: 'Other workspace' },
36
+ ]
37
+ );
38
+ queryClient.setQueryData(['workspace', WS_ID], {
39
+ workspace: { handle: 'old-handle', id: WS_ID, name: 'Old name' },
40
+ });
41
+ queryClient.setQueryData(['workspace-select-current-workspace', WS_ID], {
42
+ id: WS_ID,
43
+ name: 'Old name',
44
+ });
45
+ queryClient.setQueryData(['unrelated'], { id: WS_ID, name: 'Old name' });
46
+
47
+ const wrapper = ({ children }: { children: ReactNode }) => (
48
+ <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
49
+ );
50
+
51
+ return { queryClient, wrapper };
52
+ }
53
+
54
+ describe('patchWorkspaceCacheValue', () => {
55
+ it('patches the record, arrays of records, and wrapped shapes', () => {
56
+ const patch = { name: 'New name' };
57
+
58
+ expect(
59
+ patchWorkspaceCacheValue({ id: WS_ID, name: 'Old' }, WS_ID, patch)
60
+ ).toEqual({ id: WS_ID, name: 'New name' });
61
+
62
+ expect(
63
+ patchWorkspaceCacheValue([{ id: WS_ID, name: 'Old' }], WS_ID, patch)
64
+ ).toEqual([{ id: WS_ID, name: 'New name' }]);
65
+
66
+ expect(
67
+ patchWorkspaceCacheValue(
68
+ { workspace: { id: WS_ID, name: 'Old' } },
69
+ WS_ID,
70
+ patch
71
+ )
72
+ ).toEqual({ workspace: { id: WS_ID, name: 'New name' } });
73
+ });
74
+
75
+ it('leaves other workspaces and unknown shapes alone', () => {
76
+ const other = { id: 'ws-2', name: 'Other' };
77
+ expect(patchWorkspaceCacheValue(other, WS_ID, { name: 'New' })).toBe(other);
78
+ expect(patchWorkspaceCacheValue(null, WS_ID, { name: 'New' })).toBeNull();
79
+ expect(patchWorkspaceCacheValue('text', WS_ID, { name: 'New' })).toBe(
80
+ 'text'
81
+ );
82
+ });
83
+ });
84
+
85
+ describe('useUpdateWorkspaceIdentity', () => {
86
+ beforeEach(() => {
87
+ vi.clearAllMocks();
88
+ mocks.updateWorkspace.mockResolvedValue({ id: WS_ID });
89
+ });
90
+
91
+ // Regression: renaming a workspace used to only call `router.refresh()`, which
92
+ // re-renders server markup but leaves client caches untouched — so the
93
+ // workspace selector kept the old name until the user reloaded the page.
94
+ it('renames the workspace everywhere it is cached', async () => {
95
+ const { queryClient, wrapper } = createHarness();
96
+ const { result } = renderHook(
97
+ () => useUpdateWorkspaceIdentity({ workspaceId: WS_ID }),
98
+ { wrapper }
99
+ );
100
+
101
+ await act(async () => {
102
+ await result.current.mutateAsync({ name: 'New name' });
103
+ });
104
+
105
+ expect(queryClient.getQueryData(['workspaces'])).toEqual([
106
+ { id: WS_ID, name: 'New name' },
107
+ { id: 'ws-2', name: 'Other workspace' },
108
+ ]);
109
+ expect(queryClient.getQueryData(['workspace', WS_ID])).toEqual({
110
+ workspace: { handle: 'old-handle', id: WS_ID, name: 'New name' },
111
+ });
112
+ expect(
113
+ queryClient.getQueryData(['workspace-select-current-workspace', WS_ID])
114
+ ).toEqual({ id: WS_ID, name: 'New name' });
115
+ });
116
+
117
+ it('refreshes server-rendered surfaces too', async () => {
118
+ const { wrapper } = createHarness();
119
+ const { result } = renderHook(
120
+ () => useUpdateWorkspaceIdentity({ workspaceId: WS_ID }),
121
+ { wrapper }
122
+ );
123
+
124
+ await act(async () => {
125
+ await result.current.mutateAsync({ name: 'New name' });
126
+ });
127
+
128
+ await waitFor(() => expect(mocks.refresh).toHaveBeenCalledTimes(1));
129
+ });
130
+
131
+ it('updates the cache before the request resolves', async () => {
132
+ const { queryClient, wrapper } = createHarness();
133
+ let resolveUpdate: (value: unknown) => void = () => {};
134
+ mocks.updateWorkspace.mockReturnValue(
135
+ new Promise((resolve) => {
136
+ resolveUpdate = resolve;
137
+ })
138
+ );
139
+
140
+ const { result } = renderHook(
141
+ () => useUpdateWorkspaceIdentity({ workspaceId: WS_ID }),
142
+ { wrapper }
143
+ );
144
+
145
+ await act(async () => {
146
+ void result.current.mutateAsync({ name: 'Optimistic name' });
147
+ await Promise.resolve();
148
+ });
149
+
150
+ expect(queryClient.getQueryData(['workspaces'])).toEqual([
151
+ { id: WS_ID, name: 'Optimistic name' },
152
+ { id: 'ws-2', name: 'Other workspace' },
153
+ ]);
154
+
155
+ await act(async () => {
156
+ resolveUpdate({ id: WS_ID });
157
+ });
158
+ });
159
+
160
+ it('rolls the caches back when the rename fails', async () => {
161
+ const { queryClient, wrapper } = createHarness();
162
+ const onError = vi.fn();
163
+ mocks.updateWorkspace.mockRejectedValue(new Error('nope'));
164
+
165
+ const { result } = renderHook(
166
+ () => useUpdateWorkspaceIdentity({ onError, workspaceId: WS_ID }),
167
+ { wrapper }
168
+ );
169
+
170
+ await act(async () => {
171
+ await result.current.mutateAsync({ name: 'New name' }).catch(() => {});
172
+ });
173
+
174
+ expect(queryClient.getQueryData(['workspaces'])).toEqual([
175
+ { id: WS_ID, name: 'Old name' },
176
+ { id: 'ws-2', name: 'Other workspace' },
177
+ ]);
178
+ expect(onError).toHaveBeenCalledTimes(1);
179
+ expect(mocks.refresh).not.toHaveBeenCalled();
180
+ });
181
+ });
@@ -0,0 +1,136 @@
1
+ 'use client';
2
+
3
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
4
+ import { updateWorkspace } from '@tuturuuu/internal-api/workspaces';
5
+ import { useRouter } from 'next/navigation';
6
+
7
+ export interface WorkspaceIdentityPatch {
8
+ handle?: string;
9
+ name?: string;
10
+ }
11
+
12
+ interface QueryKeyFilter {
13
+ queryKey: readonly unknown[];
14
+ }
15
+
16
+ /**
17
+ * Matches every cached query that can carry this workspace's name or handle.
18
+ *
19
+ * The workspace selector reads `['workspaces']`, satellite panels read
20
+ * `['workspace', wsId]`, and the selector's fallback reads
21
+ * `['workspace-select-current-workspace', wsId]` — so match by the well-known
22
+ * roots plus any key mentioning the workspace id.
23
+ */
24
+ export function createWorkspaceQueryFilter(workspaceId: string) {
25
+ return {
26
+ predicate: ({ queryKey }: QueryKeyFilter) =>
27
+ queryKey[0] === 'workspaces' ||
28
+ queryKey[0] === 'user-workspaces' ||
29
+ queryKey.includes(workspaceId),
30
+ };
31
+ }
32
+
33
+ /**
34
+ * Apply a patch to any shape a workspace can take inside a cached value: the
35
+ * record itself, an array of records, or a wrapper such as `{ data }`,
36
+ * `{ workspace }` or `{ workspaces }`.
37
+ */
38
+ export function patchWorkspaceCacheValue(
39
+ value: unknown,
40
+ workspaceId: string,
41
+ patch: WorkspaceIdentityPatch
42
+ ): unknown {
43
+ if (Array.isArray(value)) {
44
+ let changed = false;
45
+ const nextArray = value.map((entry) => {
46
+ const nextEntry = patchWorkspaceCacheValue(entry, workspaceId, patch);
47
+ if (nextEntry !== entry) changed = true;
48
+ return nextEntry;
49
+ });
50
+
51
+ return changed ? nextArray : value;
52
+ }
53
+
54
+ if (!value || typeof value !== 'object') {
55
+ return value;
56
+ }
57
+
58
+ const record = value as Record<string, unknown>;
59
+ if (record.id === workspaceId) {
60
+ return { ...record, ...patch };
61
+ }
62
+
63
+ let changed = false;
64
+ const nextRecord = { ...record };
65
+ for (const key of ['data', 'workspace', 'workspaces'] as const) {
66
+ if (!(key in record)) continue;
67
+ const nextValue = patchWorkspaceCacheValue(record[key], workspaceId, patch);
68
+ if (nextValue !== record[key]) {
69
+ nextRecord[key] = nextValue;
70
+ changed = true;
71
+ }
72
+ }
73
+
74
+ return changed ? nextRecord : value;
75
+ }
76
+
77
+ /**
78
+ * Rename a workspace and make every surface agree, without a page reload.
79
+ *
80
+ * A workspace name is read from two independent places: client caches (the
81
+ * workspace selector, settings panels) and server-rendered markup (sidebars,
82
+ * headers). `router.refresh()` only refreshes the second, so a form that just
83
+ * calls it leaves the selector showing the old name until the user reloads —
84
+ * which is exactly what shipped in `apps/web`. This does all three steps:
85
+ * patch the caches optimistically, revalidate them, and refresh the server tree.
86
+ *
87
+ * Every app's settings dialog should mutate the workspace through this hook, so
88
+ * the propagation rules live in one place rather than being re-derived per app.
89
+ */
90
+ export function useUpdateWorkspaceIdentity({
91
+ onError,
92
+ onSuccess,
93
+ workspaceId,
94
+ }: {
95
+ onError?: (error: unknown) => void;
96
+ onSuccess?: (patch: WorkspaceIdentityPatch) => void;
97
+ workspaceId: string;
98
+ }) {
99
+ const queryClient = useQueryClient();
100
+ const router = useRouter();
101
+ const workspaceQueryFilter = createWorkspaceQueryFilter(workspaceId);
102
+
103
+ return useMutation({
104
+ mutationFn: (values: WorkspaceIdentityPatch) =>
105
+ updateWorkspace(workspaceId, values as { handle?: string; name: string }),
106
+ onError: (error, _values, context) => {
107
+ for (const [queryKey, previous] of context?.previousQueries ?? []) {
108
+ queryClient.setQueryData(queryKey, previous);
109
+ }
110
+
111
+ onError?.(error);
112
+ },
113
+ onMutate: async (values: WorkspaceIdentityPatch) => {
114
+ await queryClient.cancelQueries(workspaceQueryFilter);
115
+ const previousQueries = queryClient.getQueriesData(workspaceQueryFilter);
116
+
117
+ queryClient.setQueriesData(workspaceQueryFilter, (previous) =>
118
+ patchWorkspaceCacheValue(previous, workspaceId, values)
119
+ );
120
+
121
+ return { previousQueries };
122
+ },
123
+ onSuccess: async (_response, values: WorkspaceIdentityPatch) => {
124
+ queryClient.setQueriesData(workspaceQueryFilter, (previous) =>
125
+ patchWorkspaceCacheValue(previous, workspaceId, values)
126
+ );
127
+
128
+ await queryClient.invalidateQueries(workspaceQueryFilter);
129
+ // Server-rendered surfaces (sidebar header, page titles) need this; the
130
+ // cache work above is what keeps the client-side selector honest.
131
+ router.refresh();
132
+
133
+ onSuccess?.(values);
134
+ },
135
+ });
136
+ }