@oaiz/app-kit 0.0.0-stage → 0.1.4128

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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -2
  3. package/THIRD_PARTY_NOTICES.md +76 -0
  4. package/package.json +139 -4
  5. package/registry.json +1847 -0
  6. package/src/components/activity-timeline.tsx +227 -0
  7. package/src/components/app-shell.tsx +622 -0
  8. package/src/components/bar-list.tsx +47 -0
  9. package/src/components/board.tsx +700 -0
  10. package/src/components/calendar-view.tsx +1388 -0
  11. package/src/components/card-grid.tsx +462 -0
  12. package/src/components/charts.tsx +701 -0
  13. package/src/components/chat-markdown.tsx +230 -0
  14. package/src/components/chat-panel.tsx +760 -0
  15. package/src/components/code-editor.tsx +276 -0
  16. package/src/components/collection-controls.tsx +226 -0
  17. package/src/components/command-palette.tsx +403 -0
  18. package/src/components/confirm-action.tsx +123 -0
  19. package/src/components/data-table.tsx +821 -0
  20. package/src/components/date-input.tsx +429 -0
  21. package/src/components/empty-state.tsx +31 -0
  22. package/src/components/error-state.tsx +37 -0
  23. package/src/components/file-upload.tsx +595 -0
  24. package/src/components/filter-bar.tsx +415 -0
  25. package/src/components/grouped-picker.tsx +250 -0
  26. package/src/components/line-items.tsx +601 -0
  27. package/src/components/list-view.tsx +491 -0
  28. package/src/components/metrics.tsx +53 -0
  29. package/src/components/page-header.tsx +33 -0
  30. package/src/components/property-picker.tsx +546 -0
  31. package/src/components/record-detail.tsx +416 -0
  32. package/src/components/record-form.tsx +295 -0
  33. package/src/components/record-name.tsx +85 -0
  34. package/src/components/save-bar.tsx +142 -0
  35. package/src/components/sign-in.tsx +179 -0
  36. package/src/components/split-view.tsx +128 -0
  37. package/src/components/status-dot.tsx +56 -0
  38. package/src/components/stepper.tsx +153 -0
  39. package/src/components/text-diff-model.ts +111 -0
  40. package/src/components/text-diff.tsx +98 -0
  41. package/src/components/time-zone-picker.tsx +69 -0
  42. package/src/components/ui/accordion.tsx +138 -0
  43. package/src/components/ui/alert-dialog.tsx +67 -0
  44. package/src/components/ui/alert.tsx +65 -0
  45. package/src/components/ui/avatar-group.tsx +119 -0
  46. package/src/components/ui/avatar.tsx +55 -0
  47. package/src/components/ui/badge.tsx +59 -0
  48. package/src/components/ui/bottom-navigation.tsx +102 -0
  49. package/src/components/ui/breadcrumb.tsx +117 -0
  50. package/src/components/ui/button.tsx +71 -0
  51. package/src/components/ui/card.tsx +95 -0
  52. package/src/components/ui/checkbox.tsx +31 -0
  53. package/src/components/ui/collapsible.tsx +27 -0
  54. package/src/components/ui/context-menu.tsx +270 -0
  55. package/src/components/ui/count-up.tsx +136 -0
  56. package/src/components/ui/detail-disclosure-section.tsx +109 -0
  57. package/src/components/ui/dialog.tsx +157 -0
  58. package/src/components/ui/dropdown-menu.tsx +273 -0
  59. package/src/components/ui/form-field.tsx +155 -0
  60. package/src/components/ui/heading.tsx +126 -0
  61. package/src/components/ui/hover-card.tsx +45 -0
  62. package/src/components/ui/input.tsx +50 -0
  63. package/src/components/ui/label.tsx +30 -0
  64. package/src/components/ui/orb-spinner.tsx +238 -0
  65. package/src/components/ui/popover.tsx +59 -0
  66. package/src/components/ui/progress-ring.tsx +125 -0
  67. package/src/components/ui/progress.tsx +38 -0
  68. package/src/components/ui/radio-group.tsx +124 -0
  69. package/src/components/ui/resizable.tsx +48 -0
  70. package/src/components/ui/scroll-fade.tsx +98 -0
  71. package/src/components/ui/segmented-control.tsx +70 -0
  72. package/src/components/ui/select.tsx +230 -0
  73. package/src/components/ui/separator.tsx +29 -0
  74. package/src/components/ui/sheet.tsx +170 -0
  75. package/src/components/ui/shimmer-text.tsx +87 -0
  76. package/src/components/ui/shortcut.tsx +39 -0
  77. package/src/components/ui/skeleton.tsx +15 -0
  78. package/src/components/ui/slider.tsx +48 -0
  79. package/src/components/ui/switch.tsx +44 -0
  80. package/src/components/ui/table.tsx +119 -0
  81. package/src/components/ui/tabs.tsx +80 -0
  82. package/src/components/ui/text.tsx +93 -0
  83. package/src/components/ui/textarea.tsx +51 -0
  84. package/src/components/ui/toast.tsx +141 -0
  85. package/src/components/ui/toaster.tsx +40 -0
  86. package/src/components/ui/tooltip.tsx +38 -0
  87. package/src/components/ui/top-banner.tsx +108 -0
  88. package/src/components/ui/tree-view.tsx +215 -0
  89. package/src/components/ui/use-toast.tsx +184 -0
  90. package/src/components/ui/voice-orb.tsx +252 -0
  91. package/src/hooks/oaiz-chat.tsx +530 -0
  92. package/src/hooks/oaiz-data.tsx +617 -0
  93. package/src/hooks/oaiz-session.tsx +63 -0
  94. package/src/hooks/use-arrivals.ts +19 -0
  95. package/src/hooks/use-breakpoint.ts +100 -0
  96. package/src/hooks/use-media-query.ts +36 -0
  97. package/src/hooks/use-theme.ts +67 -0
  98. package/src/hooks/use-url-state.ts +77 -0
  99. package/src/lib/breakpoints.ts +81 -0
  100. package/src/lib/csp-nonce.ts +15 -0
  101. package/src/lib/format.ts +291 -0
  102. package/src/lib/speech-level.ts +118 -0
  103. package/src/lib/utils.ts +109 -0
  104. package/src/styles/oaiz/app.css +21 -0
  105. package/src/styles/oaiz/scrollbars.css +20 -0
  106. package/src/styles/oaiz/tokens.css +952 -0
  107. package/src/styles/oaiz/voice-orb.css +39 -0
@@ -0,0 +1,276 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import {
3
+ Annotation,
4
+ Compartment,
5
+ EditorState,
6
+ Transaction,
7
+ } from '@codemirror/state';
8
+ import { defaultKeymap, history, historyKeymap } from '@codemirror/commands';
9
+ import { autocompletion } from '@codemirror/autocomplete';
10
+ import { python } from '@codemirror/lang-python';
11
+ import { PostgreSQL, sql, type SQLNamespace } from '@codemirror/lang-sql';
12
+ import { HighlightStyle, syntaxHighlighting } from '@codemirror/language';
13
+ import { tags } from '@lezer/highlight';
14
+ import {
15
+ Decoration,
16
+ drawSelection,
17
+ EditorView,
18
+ keymap,
19
+ lineNumbers,
20
+ placeholder as editorPlaceholder,
21
+ } from '@codemirror/view';
22
+ import { cspNonce } from '../lib/csp-nonce';
23
+ import { cn } from '../lib/utils';
24
+
25
+ export type CodeEditorProps = {
26
+ value: string;
27
+ onChange: (value: string) => void;
28
+ label: string;
29
+ language?: 'python' | 'sql';
30
+ readOnly?: boolean;
31
+ placeholder?: string;
32
+ height?: string;
33
+ describedBy?: string;
34
+ invalid?: boolean;
35
+ onBlur?: () => void;
36
+ /** Mod+Enter submits; Tab always moves to the next control. */
37
+ onSubmit?: () => void;
38
+ sqlSchema?: SQLNamespace;
39
+ sqlDefaultSchema?: string;
40
+ /** A one-based source location. */
41
+ errorLocation?: { line: number; column: number } | null;
42
+ className?: string;
43
+ };
44
+
45
+ const externalChange = Annotation.define<boolean>();
46
+ const errorMark = Decoration.mark({ class: 'cm-error-location' });
47
+ const highlight = HighlightStyle.define([
48
+ { tag: tags.keyword, color: 'var(--color-code-key-text)' },
49
+ {
50
+ tag: [tags.string, tags.special(tags.string)],
51
+ color: 'var(--color-code-string-text)',
52
+ },
53
+ { tag: [tags.number, tags.bool], color: 'var(--color-code-number-text)' },
54
+ { tag: tags.null, color: 'var(--color-code-null-text)' },
55
+ {
56
+ tag: [tags.punctuation, tags.operator],
57
+ color: 'var(--color-code-punctuation-text)',
58
+ },
59
+ { tag: tags.comment, color: 'var(--color-muted-foreground)' },
60
+ ]);
61
+ const theme = EditorView.theme({
62
+ '&': {
63
+ height: '100%',
64
+ maxWidth: '100%',
65
+ color: 'var(--color-code-foreground)',
66
+ backgroundColor: 'var(--color-code-background)',
67
+ },
68
+ '&.cm-focused': {
69
+ outline: '2px solid var(--color-ring)',
70
+ outlineOffset: '2px',
71
+ },
72
+ '.cm-scroller': {
73
+ overflow: 'auto',
74
+ fontFamily: 'var(--font-mono)',
75
+ minWidth: '0',
76
+ },
77
+ '.cm-content': { caretColor: 'var(--color-foreground)', minHeight: '100%' },
78
+ '.cm-cursor, .cm-dropCursor': { borderLeftColor: 'var(--color-foreground)' },
79
+ '.cm-gutters': {
80
+ color: 'var(--color-muted-foreground)',
81
+ backgroundColor: 'var(--color-muted)',
82
+ borderColor: 'var(--color-border)',
83
+ },
84
+ '&.cm-focused .cm-selectionBackground, .cm-selectionBackground': {
85
+ backgroundColor: 'var(--color-accent)',
86
+ },
87
+ '.cm-placeholder': { color: 'var(--color-muted-foreground)' },
88
+ '.cm-error-location': {
89
+ textDecoration: 'underline wavy var(--color-destructive-text)',
90
+ textUnderlineOffset: '3px',
91
+ },
92
+ '.cm-tooltip': {
93
+ backgroundColor: 'var(--color-popover)',
94
+ color: 'var(--color-popover-foreground)',
95
+ border: '1px solid var(--color-border)',
96
+ },
97
+ '.cm-tooltip-autocomplete ul li[aria-selected]': {
98
+ backgroundColor: 'var(--color-primary)',
99
+ color: 'var(--color-primary-foreground)',
100
+ },
101
+ });
102
+
103
+ function errorDecoration(
104
+ state: EditorState,
105
+ location: CodeEditorProps['errorLocation'],
106
+ ) {
107
+ if (
108
+ !location ||
109
+ !Number.isInteger(location.line) ||
110
+ !Number.isInteger(location.column) ||
111
+ location.line < 1 ||
112
+ location.line > state.doc.lines ||
113
+ location.column < 1
114
+ )
115
+ return [];
116
+ const line = state.doc.line(location.line);
117
+ const from = Math.min(line.from + location.column - 1, line.to);
118
+ const word = /^[\w$."]+/.exec(state.doc.sliceString(from, line.to));
119
+ const to = word ? from + word[0].length : Math.min(from + 1, line.to);
120
+ const mark =
121
+ to > from
122
+ ? errorMark.range(from, to)
123
+ : from > line.from
124
+ ? errorMark.range(from - 1, from)
125
+ : null;
126
+ return mark ? EditorView.decorations.of(Decoration.set([mark])) : [];
127
+ }
128
+
129
+ /** A controlled code field. Completion uses Ctrl+Space and Enter; Tab leaves the editor. */
130
+ export function CodeEditor({
131
+ value,
132
+ onChange,
133
+ label,
134
+ language = 'python',
135
+ readOnly = false,
136
+ placeholder,
137
+ height = '20rem',
138
+ describedBy,
139
+ invalid = false,
140
+ onBlur,
141
+ onSubmit,
142
+ sqlSchema,
143
+ sqlDefaultSchema,
144
+ errorLocation,
145
+ className,
146
+ }: CodeEditorProps) {
147
+ const root = useRef<HTMLDivElement>(null);
148
+ const viewRef = useRef<EditorView | null>(null);
149
+ const callbacks = useRef({ onChange, onBlur, onSubmit });
150
+ const initialValue = useRef(value);
151
+ const configuration = useRef(new Compartment());
152
+ const errors = useRef(new Compartment());
153
+
154
+ useEffect(() => {
155
+ callbacks.current = { onChange, onBlur, onSubmit };
156
+ }, [onChange, onBlur, onSubmit]);
157
+
158
+ useEffect(() => {
159
+ if (!root.current) return;
160
+ const view = new EditorView({
161
+ parent: root.current,
162
+ state: EditorState.create({
163
+ doc: initialValue.current,
164
+ extensions: [
165
+ EditorView.cspNonce.of(cspNonce() ?? ''),
166
+ lineNumbers(),
167
+ drawSelection(),
168
+ history(),
169
+ autocompletion(),
170
+ syntaxHighlighting(highlight),
171
+ theme,
172
+ keymap.of([
173
+ {
174
+ key: 'Mod-Enter',
175
+ run: (editor) => {
176
+ if (editor.state.readOnly || !callbacks.current.onSubmit)
177
+ return false;
178
+ callbacks.current.onSubmit();
179
+ return true;
180
+ },
181
+ },
182
+ ...defaultKeymap,
183
+ ...historyKeymap,
184
+ ]),
185
+ configuration.current.of([]),
186
+ errors.current.of([]),
187
+ EditorView.updateListener.of((update) => {
188
+ if (
189
+ update.docChanged &&
190
+ !update.transactions.some((transaction) =>
191
+ transaction.annotation(externalChange),
192
+ )
193
+ )
194
+ callbacks.current.onChange(update.state.doc.toString());
195
+ }),
196
+ EditorView.domEventHandlers({
197
+ blur: () => {
198
+ callbacks.current.onBlur?.();
199
+ },
200
+ }),
201
+ ],
202
+ }),
203
+ });
204
+ viewRef.current = view;
205
+ return () => {
206
+ viewRef.current = null;
207
+ view.destroy();
208
+ };
209
+ }, []);
210
+
211
+ useEffect(() => {
212
+ const view = viewRef.current;
213
+ if (!view) return;
214
+ view.dispatch({
215
+ effects: configuration.current.reconfigure([
216
+ language === 'python'
217
+ ? python()
218
+ : sql({
219
+ dialect: PostgreSQL,
220
+ schema: sqlSchema,
221
+ defaultSchema: sqlDefaultSchema,
222
+ upperCaseKeywords: true,
223
+ }),
224
+ EditorState.readOnly.of(readOnly),
225
+ EditorView.editable.of(!readOnly),
226
+ EditorView.contentAttributes.of({
227
+ 'aria-label': label,
228
+ 'aria-multiline': 'true',
229
+ 'aria-readonly': String(readOnly),
230
+ 'aria-invalid': String(invalid),
231
+ ...(describedBy ? { 'aria-describedby': describedBy } : {}),
232
+ tabindex: '0',
233
+ }),
234
+ ...(placeholder ? [editorPlaceholder(placeholder)] : []),
235
+ ]),
236
+ });
237
+ }, [
238
+ language,
239
+ readOnly,
240
+ label,
241
+ describedBy,
242
+ invalid,
243
+ placeholder,
244
+ sqlSchema,
245
+ sqlDefaultSchema,
246
+ ]);
247
+
248
+ useEffect(() => {
249
+ const view = viewRef.current;
250
+ if (!view) return;
251
+ if (view.state.doc.toString() !== value)
252
+ view.dispatch({
253
+ changes: { from: 0, to: view.state.doc.length, insert: value },
254
+ annotations: [
255
+ externalChange.of(true),
256
+ Transaction.addToHistory.of(false),
257
+ ],
258
+ });
259
+ view.dispatch({
260
+ effects: errors.current.reconfigure(
261
+ errorDecoration(view.state, errorLocation),
262
+ ),
263
+ });
264
+ }, [value, errorLocation]);
265
+
266
+ return (
267
+ <div
268
+ ref={root}
269
+ className={cn(
270
+ 'min-w-0 max-w-full rounded-md border border-input font-mono text-sm',
271
+ className,
272
+ )}
273
+ style={{ height }}
274
+ />
275
+ );
276
+ }
@@ -0,0 +1,226 @@
1
+ import { useEffect, useId, type ReactNode } from 'react';
2
+ import { Button } from './ui/button';
3
+ import { Text } from './ui/text';
4
+ import { Label } from './ui/label';
5
+ import { Switch } from './ui/switch';
6
+ import {
7
+ Select,
8
+ SelectTrigger,
9
+ SelectValue,
10
+ SelectContent,
11
+ SelectItem,
12
+ } from './ui/select';
13
+
14
+ export type CollectionPage = {
15
+ index: number;
16
+ size: number;
17
+ count: number;
18
+ onChange: (index: number) => void;
19
+ };
20
+
21
+ export type PagerLabels = {
22
+ pages: string;
23
+ previous: string;
24
+ next: string;
25
+ range: (first: number, last: number, count: number) => string;
26
+ };
27
+
28
+ export function Pager({
29
+ page,
30
+ loading = false,
31
+ labels,
32
+ }: {
33
+ page: CollectionPage;
34
+ loading?: boolean;
35
+ labels?: Partial<PagerLabels>;
36
+ }) {
37
+ const lastPage = Math.max(0, Math.ceil(page.count / page.size) - 1);
38
+ const pastTheEnd = !loading && page.index > lastPage;
39
+ useEffect(() => {
40
+ if (pastTheEnd) page.onChange(lastPage);
41
+ }, [pastTheEnd, lastPage, page.onChange]);
42
+ if (page.index === 0 && page.count <= page.size) return null;
43
+ const first =
44
+ page.count === 0 ? 0 : Math.min(page.count, page.index * page.size + 1);
45
+ const last = Math.min(page.count, (page.index + 1) * page.size);
46
+ return (
47
+ <nav
48
+ aria-label={labels?.pages ?? 'Pages'}
49
+ className="flex flex-wrap items-center justify-between gap-inline px-inset"
50
+ >
51
+ <Text size="sm" variant="muted" aria-live="polite">
52
+ {labels?.range?.(first, last, page.count) ??
53
+ `${first}–${last} of ${page.count}`}
54
+ </Text>
55
+ <div className="flex gap-inline">
56
+ <Button
57
+ type="button"
58
+ size="sm"
59
+ variant="outline"
60
+ disabled={loading || page.index <= 0}
61
+ onClick={() => page.onChange(page.index - 1)}
62
+ >
63
+ {labels?.previous ?? 'Previous'}
64
+ </Button>
65
+ <Button
66
+ type="button"
67
+ size="sm"
68
+ variant="outline"
69
+ disabled={loading || last >= page.count}
70
+ onClick={() => page.onChange(page.index + 1)}
71
+ >
72
+ {labels?.next ?? 'Next'}
73
+ </Button>
74
+ </div>
75
+ </nav>
76
+ );
77
+ }
78
+
79
+ export type CollectionSort = { column: string; ascending: boolean };
80
+
81
+ export function SortControl({
82
+ options,
83
+ value,
84
+ onChange,
85
+ labels,
86
+ }: {
87
+ options: { value: string; label: string }[];
88
+ value?: CollectionSort | null;
89
+ onChange: (sort: CollectionSort) => void;
90
+ labels?: {
91
+ sort?: string;
92
+ choose?: string;
93
+ ascending?: string;
94
+ descending?: string;
95
+ };
96
+ }) {
97
+ const id = useId();
98
+ return (
99
+ <div className="flex flex-wrap items-center gap-inline">
100
+ <Label htmlFor={id}>{labels?.sort ?? 'Sort by'}</Label>
101
+ <Select
102
+ value={value?.column ?? ''}
103
+ onValueChange={(column) =>
104
+ onChange({ column, ascending: value?.ascending ?? true })
105
+ }
106
+ >
107
+ <SelectTrigger id={id} size="sm" className="w-auto min-w-0 max-w-full">
108
+ <SelectValue placeholder={labels?.choose ?? 'Choose column'} />
109
+ </SelectTrigger>
110
+ <SelectContent>
111
+ {options.map((option) => (
112
+ <SelectItem key={option.value} value={option.value}>
113
+ {option.label}
114
+ </SelectItem>
115
+ ))}
116
+ </SelectContent>
117
+ </Select>
118
+ <Button
119
+ type="button"
120
+ size="sm"
121
+ variant="outline"
122
+ disabled={!value}
123
+ onClick={() =>
124
+ value && onChange({ ...value, ascending: !value.ascending })
125
+ }
126
+ >
127
+ {value?.ascending === false
128
+ ? (labels?.descending ?? 'Descending')
129
+ : (labels?.ascending ?? 'Ascending')}
130
+ </Button>
131
+ </div>
132
+ );
133
+ }
134
+
135
+ export type BulkActionBarLabels = {
136
+ selection: string;
137
+ selected: (count: number, scope: 'page' | 'all') => string;
138
+ clear: string;
139
+ selectAll: (count: number) => string;
140
+ };
141
+
142
+ /** The caller owns selection across pages and whether all matching records are selected. */
143
+ export function BulkActionBar({
144
+ count,
145
+ scope = 'page',
146
+ totalCount,
147
+ onClear,
148
+ onSelectAll,
149
+ children,
150
+ labels,
151
+ }: {
152
+ count: number;
153
+ scope?: 'page' | 'all';
154
+ totalCount?: number;
155
+ onClear: () => void;
156
+ onSelectAll?: () => void;
157
+ children?: ReactNode;
158
+ labels?: Partial<BulkActionBarLabels>;
159
+ }) {
160
+ if (count === 0) return null;
161
+ return (
162
+ <section
163
+ aria-label={labels?.selection ?? 'Selected records'}
164
+ className="flex flex-wrap items-center gap-inline rounded-md border bg-muted p-inline"
165
+ >
166
+ <span role="status" className="text-sm">
167
+ {labels?.selected?.(count, scope) ??
168
+ `${count} selected ${scope === 'all' ? 'across all results' : 'on loaded pages'}`}
169
+ </span>
170
+ <Button type="button" variant="ghost" size="sm" onClick={onClear}>
171
+ {labels?.clear ?? 'Clear selection'}
172
+ </Button>
173
+ {scope !== 'all' &&
174
+ onSelectAll &&
175
+ totalCount !== undefined &&
176
+ totalCount > count && (
177
+ <Button
178
+ type="button"
179
+ variant="outline"
180
+ size="sm"
181
+ onClick={onSelectAll}
182
+ >
183
+ {labels?.selectAll?.(totalCount) ??
184
+ `Select all ${totalCount} matching records`}
185
+ </Button>
186
+ )}
187
+ {children}
188
+ </section>
189
+ );
190
+ }
191
+
192
+ /** The caller owns live updates and refresh requests. */
193
+ export function CollectionLiveControl({
194
+ enabled,
195
+ onEnabledChange,
196
+ onRefresh,
197
+ refreshing = false,
198
+ labels,
199
+ }: {
200
+ enabled: boolean;
201
+ onEnabledChange: (enabled: boolean) => void;
202
+ onRefresh: () => void;
203
+ refreshing?: boolean;
204
+ labels?: { live?: string; refresh?: string; refreshing?: string };
205
+ }) {
206
+ const id = useId();
207
+ return (
208
+ <div className="flex flex-wrap items-center gap-inline">
209
+ <Switch id={id} checked={enabled} onCheckedChange={onEnabledChange} />
210
+ <Label htmlFor={id}>{labels?.live ?? 'Live updates'}</Label>
211
+ {!enabled && (
212
+ <Button
213
+ type="button"
214
+ variant="outline"
215
+ size="sm"
216
+ disabled={refreshing}
217
+ onClick={onRefresh}
218
+ >
219
+ {refreshing
220
+ ? (labels?.refreshing ?? 'Refreshing…')
221
+ : (labels?.refresh ?? 'Refresh')}
222
+ </Button>
223
+ )}
224
+ </div>
225
+ );
226
+ }