@karni/ui 0.0.0-stage → 0.4.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.
Files changed (142) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +928 -2
  3. package/dist/index.cjs +9 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.js +8699 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/manifest.json +102 -0
  8. package/dist/mockServiceWorker.js +361 -0
  9. package/dist/script-BVJ9BbPm.cjs +2 -0
  10. package/dist/script-BVJ9BbPm.cjs.map +1 -0
  11. package/dist/script-D1fn4Dm4.js +6 -0
  12. package/dist/script-D1fn4Dm4.js.map +1 -0
  13. package/dist/src/auth/AuthGuard.d.ts +77 -0
  14. package/dist/src/auth/LoginForm.d.ts +63 -0
  15. package/dist/src/auth/engine.d.ts +101 -0
  16. package/dist/src/auth/provider.d.ts +43 -0
  17. package/dist/src/auth/storage.d.ts +26 -0
  18. package/dist/src/auth/types.d.ts +32 -0
  19. package/dist/src/auth/usePermission.d.ts +7 -0
  20. package/dist/src/components/brand/karni-mark.d.ts +21 -0
  21. package/dist/src/components/brand/mark-paths.d.ts +8 -0
  22. package/dist/src/components/chart/data-chart.d.ts +129 -0
  23. package/dist/src/components/empty-state/empty-state.d.ts +40 -0
  24. package/dist/src/components/file-upload/FileUpload.d.ts +108 -0
  25. package/dist/src/components/layout/layout.d.ts +150 -0
  26. package/dist/src/components/layout/route-focus.d.ts +43 -0
  27. package/dist/src/components/modal/modal.d.ts +86 -0
  28. package/dist/src/components/page/page.d.ts +60 -0
  29. package/dist/src/components/primitives/button.d.ts +45 -0
  30. package/dist/src/components/primitives/checkbox.d.ts +8 -0
  31. package/dist/src/components/primitives/dropdown-menu.d.ts +24 -0
  32. package/dist/src/components/primitives/icons.d.ts +19 -0
  33. package/dist/src/components/primitives/input.d.ts +7 -0
  34. package/dist/src/components/primitives/label.d.ts +8 -0
  35. package/dist/src/components/primitives/select.d.ts +94 -0
  36. package/dist/src/components/primitives/skeleton.d.ts +7 -0
  37. package/dist/src/components/primitives/switch.d.ts +8 -0
  38. package/dist/src/components/primitives/tabs.d.ts +10 -0
  39. package/dist/src/components/primitives/textarea.d.ts +7 -0
  40. package/dist/src/components/resource/ResourceDetail.d.ts +7 -0
  41. package/dist/src/components/resource/ResourceForm.d.ts +8 -0
  42. package/dist/src/components/resource/ResourceSelect.d.ts +9 -0
  43. package/dist/src/components/resource/ResourceTable.d.ts +17 -0
  44. package/dist/src/components/resource/audit-fields.d.ts +17 -0
  45. package/dist/src/components/resource/detail/ResourceDetail.d.ts +128 -0
  46. package/dist/src/components/resource/displayLabel.d.ts +12 -0
  47. package/dist/src/components/resource/empty-value.d.ts +17 -0
  48. package/dist/src/components/resource/form/ResourceForm.d.ts +109 -0
  49. package/dist/src/components/resource/form/field-inputs.d.ts +34 -0
  50. package/dist/src/components/resource/form/fixtures.d.ts +24 -0
  51. package/dist/src/components/resource/form/form-states.d.ts +87 -0
  52. package/dist/src/components/resource/form/prepare.d.ts +54 -0
  53. package/dist/src/components/resource/form/server-errors.d.ts +14 -0
  54. package/dist/src/components/resource/history/ChangeHistory.d.ts +60 -0
  55. package/dist/src/components/resource/import/ResourceImport.d.ts +84 -0
  56. package/dist/src/components/resource/nouns.d.ts +12 -0
  57. package/dist/src/components/resource/query-state.d.ts +20 -0
  58. package/dist/src/components/resource/resource-names.d.ts +23 -0
  59. package/dist/src/components/resource/select/ResourceSelect.d.ts +67 -0
  60. package/dist/src/components/resource/select/select-states.d.ts +68 -0
  61. package/dist/src/components/resource/select/use-debounced-value.d.ts +2 -0
  62. package/dist/src/components/resource/select/use-option-pages.d.ts +37 -0
  63. package/dist/src/components/resource/select/venue-backend.d.ts +144 -0
  64. package/dist/src/components/resource/table/BulkActionsBar.d.ts +77 -0
  65. package/dist/src/components/resource/table/CardList.d.ts +31 -0
  66. package/dist/src/components/resource/table/ConfirmDialog.d.ts +28 -0
  67. package/dist/src/components/resource/table/ExportButtons.d.ts +17 -0
  68. package/dist/src/components/resource/table/FilterBar.d.ts +29 -0
  69. package/dist/src/components/resource/table/PaginationControls.d.ts +31 -0
  70. package/dist/src/components/resource/table/ResourceTable.d.ts +137 -0
  71. package/dist/src/components/resource/table/RowCard.d.ts +31 -0
  72. package/dist/src/components/resource/table/TableView.d.ts +29 -0
  73. package/dist/src/components/resource/table/ViewOptions.d.ts +19 -0
  74. package/dist/src/components/resource/table/access.d.ts +12 -0
  75. package/dist/src/components/resource/table/demo-fixtures.d.ts +25 -0
  76. package/dist/src/components/resource/table/derive-columns.d.ts +33 -0
  77. package/dist/src/components/resource/table/grid-navigation.d.ts +23 -0
  78. package/dist/src/components/resource/table/layout.d.ts +37 -0
  79. package/dist/src/components/resource/table/preferences.d.ts +12 -0
  80. package/dist/src/components/resource/table/slots.d.ts +41 -0
  81. package/dist/src/components/resource/table/states.d.ts +91 -0
  82. package/dist/src/components/resource/table/story-fixtures.d.ts +25 -0
  83. package/dist/src/components/resource/table/structural-columns.d.ts +25 -0
  84. package/dist/src/components/resource/table/table-icons.d.ts +16 -0
  85. package/dist/src/components/resource/table/table-utils.d.ts +48 -0
  86. package/dist/src/components/resource/table/url-state.d.ts +67 -0
  87. package/dist/src/components/resource/table/use-container-width.d.ts +10 -0
  88. package/dist/src/components/resource/table/use-debounced-value.d.ts +1 -0
  89. package/dist/src/components/resource/testapp-fixtures.d.ts +78 -0
  90. package/dist/src/components/stat/stat.d.ts +54 -0
  91. package/dist/src/components/toast/toast-store.d.ts +36 -0
  92. package/dist/src/components/toast/toaster.d.ts +66 -0
  93. package/dist/src/components/toast/use-toast.d.ts +24 -0
  94. package/dist/src/hooks/keys.d.ts +24 -0
  95. package/dist/src/hooks/multipart.d.ts +44 -0
  96. package/dist/src/hooks/params.d.ts +25 -0
  97. package/dist/src/hooks/types.d.ts +41 -0
  98. package/dist/src/hooks/useChangeHistory.d.ts +30 -0
  99. package/dist/src/hooks/useResourceImport.d.ts +107 -0
  100. package/dist/src/hooks/useResourceItem.d.ts +4 -0
  101. package/dist/src/hooks/useResourceList.d.ts +4 -0
  102. package/dist/src/hooks/useResourceMutations.d.ts +13 -0
  103. package/dist/src/hooks/useUnsavedChangesGuard.d.ts +31 -0
  104. package/dist/src/index.d.ts +113 -0
  105. package/dist/src/lib/cn.d.ts +8 -0
  106. package/dist/src/lib/roles.d.ts +45 -0
  107. package/dist/src/lib/variants.d.ts +33 -0
  108. package/dist/src/primitives/registry.d.ts +81 -0
  109. package/dist/src/schema/client.d.ts +90 -0
  110. package/dist/src/schema/parse.d.ts +101 -0
  111. package/dist/src/schema/provider.d.ts +20 -0
  112. package/dist/src/schema/types.d.ts +93 -0
  113. package/dist/src/schema/useSchema.d.ts +21 -0
  114. package/dist/src/schema/zod.d.ts +4 -0
  115. package/dist/src/states/ErrorState.d.ts +43 -0
  116. package/dist/src/states/PendingButton.d.ts +16 -0
  117. package/dist/src/states/describe-error.d.ts +25 -0
  118. package/dist/src/states/hooks.d.ts +10 -0
  119. package/dist/src/theme/script.d.ts +12 -0
  120. package/dist/src/theme/theme.d.ts +45 -0
  121. package/dist/styles.css +248 -0
  122. package/dist/tailwind-preset.cjs +2 -0
  123. package/dist/tailwind-preset.cjs.map +1 -0
  124. package/dist/tailwind-preset.d.ts +140 -0
  125. package/dist/tailwind-preset.js +183 -0
  126. package/dist/tailwind-preset.js.map +1 -0
  127. package/dist/tailwind-v4.css +31 -0
  128. package/dist/vite-plugin.cjs +2 -0
  129. package/dist/vite-plugin.cjs.map +1 -0
  130. package/dist/vite-plugin.d.ts +19 -0
  131. package/dist/vite-plugin.js +16 -0
  132. package/dist/vite-plugin.js.map +1 -0
  133. package/eslint-plugin/index.js +76 -0
  134. package/eslint-plugin/lib/docs.js +11 -0
  135. package/eslint-plugin/lib/glob.js +51 -0
  136. package/eslint-plugin/rules/max-page-lines.js +65 -0
  137. package/eslint-plugin/rules/no-deep-imports.js +61 -0
  138. package/eslint-plugin/rules/no-direct-http.js +128 -0
  139. package/eslint-plugin/rules/no-raw-elements.js +65 -0
  140. package/eslint-plugin/rules/no-style-literals.js +222 -0
  141. package/eslint-plugin/rules.json +32 -0
  142. package/package.json +156 -4
@@ -0,0 +1,102 @@
1
+ {
2
+ "components": [
3
+ "AuthGuard",
4
+ "AuthProvider",
5
+ "Button",
6
+ "ChangeHistory",
7
+ "Checkbox",
8
+ "DataChart",
9
+ "DropdownMenu",
10
+ "DropdownMenuCheckboxItem",
11
+ "DropdownMenuContent",
12
+ "DropdownMenuGroup",
13
+ "DropdownMenuItem",
14
+ "DropdownMenuLabel",
15
+ "DropdownMenuPortal",
16
+ "DropdownMenuSeparator",
17
+ "DropdownMenuTrigger",
18
+ "EmptyState",
19
+ "EmptyValue",
20
+ "ErrorState",
21
+ "FileUpload",
22
+ "Input",
23
+ "KarniMark",
24
+ "KarniPrimitivesProvider",
25
+ "KarniProvider",
26
+ "Label",
27
+ "Layout",
28
+ "LoginForm",
29
+ "Modal",
30
+ "ModalClose",
31
+ "ModalDescription",
32
+ "ModalTitle",
33
+ "Page",
34
+ "PendingButton",
35
+ "PermissionDenied",
36
+ "ResourceDetail",
37
+ "ResourceForm",
38
+ "ResourceImport",
39
+ "ResourceSelect",
40
+ "ResourceTable",
41
+ "Select",
42
+ "SelectContent",
43
+ "SelectGroup",
44
+ "SelectItem",
45
+ "SelectLabel",
46
+ "SelectRoot",
47
+ "SelectSeparator",
48
+ "SelectTrigger",
49
+ "SelectValue",
50
+ "Skeleton",
51
+ "Stat",
52
+ "Switch",
53
+ "Tabs",
54
+ "TabsContent",
55
+ "TabsList",
56
+ "TabsTrigger",
57
+ "Textarea",
58
+ "ThemeProvider",
59
+ "ThemeToggle",
60
+ "Toaster"
61
+ ],
62
+ "hooks": [
63
+ "useAuth",
64
+ "useChangeHistory",
65
+ "useDelayedFlag",
66
+ "useImportActions",
67
+ "useImportDescribe",
68
+ "useImportJob",
69
+ "useKarniClient",
70
+ "useKarniPrimitives",
71
+ "useOnlineStatus",
72
+ "usePermission",
73
+ "useResourceItem",
74
+ "useResourceList",
75
+ "useResourceMutations",
76
+ "useSchema",
77
+ "useTheme",
78
+ "useToast",
79
+ "useUnsavedChangesGuard"
80
+ ],
81
+ "roles": {
82
+ "async-select": "ResourceSelect",
83
+ "auth-guard": "AuthGuard",
84
+ "change-history": "ChangeHistory",
85
+ "chart": "DataChart",
86
+ "data-table": "ResourceTable",
87
+ "detail-view": "ResourceDetail",
88
+ "empty-state": "EmptyState",
89
+ "error-state": "ErrorState",
90
+ "file-upload": "FileUpload",
91
+ "layout-shell": "Layout",
92
+ "login-form": "LoginForm",
93
+ "modal": "Modal",
94
+ "page-shell": "Page",
95
+ "permission-denied": "PermissionDenied",
96
+ "resource-form": "ResourceForm",
97
+ "resource-import": "ResourceImport",
98
+ "stat": "Stat",
99
+ "theme-toggle": "ThemeToggle",
100
+ "toast": "Toaster"
101
+ }
102
+ }
@@ -0,0 +1,361 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
3
+
4
+ /**
5
+ * Mock Service Worker.
6
+ * @see https://github.com/mswjs/msw
7
+ * - Please do NOT modify this file.
8
+ */
9
+
10
+ const PACKAGE_VERSION = '2.15.0'
11
+ const INTEGRITY_CHECKSUM = '03cb67ac84128e63d7cd722a6e5b7f1e'
12
+ const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
13
+ const activeClientIds = new Set()
14
+
15
+ addEventListener('install', function () {
16
+ self.skipWaiting()
17
+ })
18
+
19
+ addEventListener('activate', function (event) {
20
+ event.waitUntil(self.clients.claim())
21
+ })
22
+
23
+ addEventListener('message', async function (event) {
24
+ const clientId = Reflect.get(event.source || {}, 'id')
25
+
26
+ if (!clientId || !self.clients) {
27
+ return
28
+ }
29
+
30
+ const client = await self.clients.get(clientId)
31
+
32
+ if (!client) {
33
+ return
34
+ }
35
+
36
+ const allClients = await self.clients.matchAll({
37
+ type: 'window',
38
+ })
39
+
40
+ switch (event.data) {
41
+ case 'KEEPALIVE_REQUEST': {
42
+ sendToClient(client, {
43
+ type: 'KEEPALIVE_RESPONSE',
44
+ })
45
+ break
46
+ }
47
+
48
+ case 'INTEGRITY_CHECK_REQUEST': {
49
+ sendToClient(client, {
50
+ type: 'INTEGRITY_CHECK_RESPONSE',
51
+ payload: {
52
+ packageVersion: PACKAGE_VERSION,
53
+ checksum: INTEGRITY_CHECKSUM,
54
+ },
55
+ })
56
+ break
57
+ }
58
+
59
+ case 'MOCK_ACTIVATE': {
60
+ activeClientIds.add(clientId)
61
+
62
+ sendToClient(client, {
63
+ type: 'MOCKING_ENABLED',
64
+ payload: {
65
+ client: {
66
+ id: client.id,
67
+ frameType: client.frameType,
68
+ },
69
+ },
70
+ })
71
+ break
72
+ }
73
+
74
+ case 'CLIENT_CLOSED': {
75
+ activeClientIds.delete(clientId)
76
+
77
+ const remainingClients = allClients.filter((client) => {
78
+ return client.id !== clientId
79
+ })
80
+
81
+ // Unregister itself when there are no more clients
82
+ if (remainingClients.length === 0) {
83
+ self.registration.unregister()
84
+ }
85
+
86
+ break
87
+ }
88
+ }
89
+ })
90
+
91
+ addEventListener('fetch', function (event) {
92
+ const requestInterceptedAt = Date.now()
93
+
94
+ // Bypass navigation requests.
95
+ if (event.request.mode === 'navigate') {
96
+ return
97
+ }
98
+
99
+ // Opening the DevTools triggers the "only-if-cached" request
100
+ // that cannot be handled by the worker. Bypass such requests.
101
+ if (
102
+ event.request.cache === 'only-if-cached' &&
103
+ event.request.mode !== 'same-origin'
104
+ ) {
105
+ return
106
+ }
107
+
108
+ // Bypass all requests when there are no active clients.
109
+ // Prevents the self-unregistered worked from handling requests
110
+ // after it's been terminated (still remains active until the next reload).
111
+ if (activeClientIds.size === 0) {
112
+ return
113
+ }
114
+
115
+ const requestId = crypto.randomUUID()
116
+ event.respondWith(handleRequest(event, requestId, requestInterceptedAt))
117
+ })
118
+
119
+ /**
120
+ * @param {FetchEvent} event
121
+ * @param {string} requestId
122
+ * @param {number} requestInterceptedAt
123
+ */
124
+ async function handleRequest(event, requestId, requestInterceptedAt) {
125
+ const client = await resolveMainClient(event)
126
+ const requestCloneForEvents = event.request.clone()
127
+ const response = await getResponse(
128
+ event,
129
+ client,
130
+ requestId,
131
+ requestInterceptedAt,
132
+ )
133
+
134
+ // Send back the response clone for the "response:*" life-cycle events.
135
+ // Ensure MSW is active and ready to handle the message, otherwise
136
+ // this message will pend indefinitely.
137
+ if (client && activeClientIds.has(client.id)) {
138
+ const serializedRequest = await serializeRequest(requestCloneForEvents)
139
+
140
+ // Omit the body of server-sent event stream responses.
141
+ // Cloning such responses would prevent client-side stream cancelations
142
+ // from reaching the original stream (a teed stream only cancels its
143
+ // source once both of its branches cancel) and would buffer the
144
+ // entire stream into the unconsumed clone indefinitely.
145
+ const isEventStreamResponse = response.headers
146
+ .get('content-type')
147
+ ?.toLowerCase()
148
+ .startsWith('text/event-stream')
149
+
150
+ // Clone the response so both the client and the library could consume it.
151
+ const responseClone = isEventStreamResponse ? null : response.clone()
152
+
153
+ sendToClient(
154
+ client,
155
+ {
156
+ type: 'RESPONSE',
157
+ payload: {
158
+ isMockedResponse: IS_MOCKED_RESPONSE in response,
159
+ request: {
160
+ id: requestId,
161
+ ...serializedRequest,
162
+ },
163
+ response: {
164
+ type: response.type,
165
+ status: response.status,
166
+ statusText: response.statusText,
167
+ headers: Object.fromEntries(response.headers.entries()),
168
+ body: responseClone ? responseClone.body : null,
169
+ },
170
+ },
171
+ },
172
+ responseClone && responseClone.body
173
+ ? [serializedRequest.body, responseClone.body]
174
+ : [],
175
+ )
176
+ }
177
+
178
+ return response
179
+ }
180
+
181
+ /**
182
+ * Resolve the main client for the given event.
183
+ * Client that issues a request doesn't necessarily equal the client
184
+ * that registered the worker. It's with the latter the worker should
185
+ * communicate with during the response resolving phase.
186
+ * @param {FetchEvent} event
187
+ * @returns {Promise<Client | undefined>}
188
+ */
189
+ async function resolveMainClient(event) {
190
+ const client = await self.clients.get(event.clientId)
191
+
192
+ if (activeClientIds.has(event.clientId)) {
193
+ return client
194
+ }
195
+
196
+ if (client?.frameType === 'top-level') {
197
+ return client
198
+ }
199
+
200
+ const allClients = await self.clients.matchAll({
201
+ type: 'window',
202
+ })
203
+
204
+ return allClients
205
+ .filter((client) => {
206
+ // Get only those clients that are currently visible.
207
+ return client.visibilityState === 'visible'
208
+ })
209
+ .find((client) => {
210
+ // Find the client ID that's recorded in the
211
+ // set of clients that have registered the worker.
212
+ return activeClientIds.has(client.id)
213
+ })
214
+ }
215
+
216
+ /**
217
+ * @param {FetchEvent} event
218
+ * @param {Client | undefined} client
219
+ * @param {string} requestId
220
+ * @param {number} requestInterceptedAt
221
+ * @returns {Promise<Response>}
222
+ */
223
+ async function getResponse(event, client, requestId, requestInterceptedAt) {
224
+ // Clone the request because it might've been already used
225
+ // (i.e. its body has been read and sent to the client).
226
+ const requestClone = event.request.clone()
227
+
228
+ function passthrough() {
229
+ // Cast the request headers to a new Headers instance
230
+ // so the headers can be manipulated with.
231
+ const headers = new Headers(requestClone.headers)
232
+
233
+ // Remove the "accept" header value that marked this request as passthrough.
234
+ // This prevents request alteration and also keeps it compliant with the
235
+ // user-defined CORS policies.
236
+ const acceptHeader = headers.get('accept')
237
+ if (acceptHeader) {
238
+ const values = acceptHeader.split(',').map((value) => value.trim())
239
+ const filteredValues = values.filter(
240
+ (value) => value !== 'msw/passthrough',
241
+ )
242
+
243
+ if (filteredValues.length > 0) {
244
+ headers.set('accept', filteredValues.join(', '))
245
+ } else {
246
+ headers.delete('accept')
247
+ }
248
+ }
249
+
250
+ return fetch(requestClone, { headers })
251
+ }
252
+
253
+ // Bypass mocking when the client is not active.
254
+ if (!client) {
255
+ return passthrough()
256
+ }
257
+
258
+ // Bypass initial page load requests (i.e. static assets).
259
+ // The absence of the immediate/parent client in the map of the active clients
260
+ // means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet
261
+ // and is not ready to handle requests.
262
+ if (!activeClientIds.has(client.id)) {
263
+ return passthrough()
264
+ }
265
+
266
+ // Notify the client that a request has been intercepted.
267
+ const serializedRequest = await serializeRequest(event.request)
268
+ const clientMessage = await sendToClient(
269
+ client,
270
+ {
271
+ type: 'REQUEST',
272
+ payload: {
273
+ id: requestId,
274
+ interceptedAt: requestInterceptedAt,
275
+ ...serializedRequest,
276
+ },
277
+ },
278
+ [serializedRequest.body],
279
+ )
280
+
281
+ switch (clientMessage.type) {
282
+ case 'MOCK_RESPONSE': {
283
+ return respondWithMock(clientMessage.data)
284
+ }
285
+
286
+ case 'PASSTHROUGH': {
287
+ return passthrough()
288
+ }
289
+ }
290
+
291
+ return passthrough()
292
+ }
293
+
294
+ /**
295
+ * @param {Client} client
296
+ * @param {any} message
297
+ * @param {Array<Transferable>} transferrables
298
+ * @returns {Promise<any>}
299
+ */
300
+ function sendToClient(client, message, transferrables = []) {
301
+ return new Promise((resolve, reject) => {
302
+ const channel = new MessageChannel()
303
+
304
+ channel.port1.onmessage = (event) => {
305
+ if (event.data && event.data.error) {
306
+ return reject(event.data.error)
307
+ }
308
+
309
+ resolve(event.data)
310
+ }
311
+
312
+ client.postMessage(message, [
313
+ channel.port2,
314
+ ...transferrables.filter(Boolean),
315
+ ])
316
+ })
317
+ }
318
+
319
+ /**
320
+ * @param {Response} response
321
+ * @returns {Response}
322
+ */
323
+ function respondWithMock(response) {
324
+ // Setting response status code to 0 is a no-op.
325
+ // However, when responding with a "Response.error()", the produced Response
326
+ // instance will have status code set to 0. Since it's not possible to create
327
+ // a Response instance with status code 0, handle that use-case separately.
328
+ if (response.status === 0) {
329
+ return Response.error()
330
+ }
331
+
332
+ const mockedResponse = new Response(response.body, response)
333
+
334
+ Reflect.defineProperty(mockedResponse, IS_MOCKED_RESPONSE, {
335
+ value: true,
336
+ enumerable: true,
337
+ })
338
+
339
+ return mockedResponse
340
+ }
341
+
342
+ /**
343
+ * @param {Request} request
344
+ */
345
+ async function serializeRequest(request) {
346
+ return {
347
+ url: request.url,
348
+ mode: request.mode,
349
+ method: request.method,
350
+ headers: Object.fromEntries(request.headers.entries()),
351
+ cache: request.cache,
352
+ credentials: request.credentials,
353
+ destination: request.destination,
354
+ integrity: request.integrity,
355
+ redirect: request.redirect,
356
+ referrer: request.referrer,
357
+ referrerPolicy: request.referrerPolicy,
358
+ body: await request.arrayBuffer(),
359
+ keepalive: request.keepalive,
360
+ }
361
+ }
@@ -0,0 +1,2 @@
1
+ var e=`karni-theme`,t=`(function(){try{var t=localStorage.getItem("${e}");var d=t==="dark"||((t===null||t==="system")&&matchMedia("(prefers-color-scheme: dark)").matches);document.documentElement.classList.toggle("dark",d);document.documentElement.style.colorScheme=d?"dark":"light"}catch(e){}})();`;Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return t}});
2
+ //# sourceMappingURL=script-BVJ9BbPm.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-BVJ9BbPm.cjs","names":["THEME_STORAGE_KEY","KARNI_THEME_SCRIPT"],"sources":["../src/theme/script.ts"],"sourcesContent":["/**\n * The theme's pre-paint script, with no React: shared by ThemeProvider and\n * the `@karni/ui/vite` plugin, which runs in Node at build time.\n */\n\n/** The localStorage key ThemeProvider keeps the user's choice under. */\nexport const THEME_STORAGE_KEY = \"karni-theme\";\n\n/**\n * Inline script for index.html's `<head>`: applies the stored (or system) theme\n * before the first paint. Uses the default storage key. In a Vite app,\n * `karniTheme()` from `@karni/ui/vite` puts it there.\n */\nexport const KARNI_THEME_SCRIPT = `(function(){try{var t=localStorage.getItem(\"${THEME_STORAGE_KEY}\");var d=t===\"dark\"||((t===null||t===\"system\")&&matchMedia(\"(prefers-color-scheme: dark)\").matches);document.documentElement.classList.toggle(\"dark\",d);document.documentElement.style.colorScheme=d?\"dark\":\"light\"}catch(e){}})();`;\n"],"mappings":"AAMA,IAAaA,EAAoB,cAOpBC,EAAqB,+CAA+CD,EAAkB,qO"}
@@ -0,0 +1,6 @@
1
+ //#region src/theme/script.ts
2
+ var e = "karni-theme", t = `(function(){try{var t=localStorage.getItem("${e}");var d=t==="dark"||((t===null||t==="system")&&matchMedia("(prefers-color-scheme: dark)").matches);document.documentElement.classList.toggle("dark",d);document.documentElement.style.colorScheme=d?"dark":"light"}catch(e){}})();`;
3
+ //#endregion
4
+ export { e as n, t };
5
+
6
+ //# sourceMappingURL=script-D1fn4Dm4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-D1fn4Dm4.js","names":["THEME_STORAGE_KEY","KARNI_THEME_SCRIPT"],"sources":["../src/theme/script.ts"],"sourcesContent":["/**\n * The theme's pre-paint script, with no React: shared by ThemeProvider and\n * the `@karni/ui/vite` plugin, which runs in Node at build time.\n */\n\n/** The localStorage key ThemeProvider keeps the user's choice under. */\nexport const THEME_STORAGE_KEY = \"karni-theme\";\n\n/**\n * Inline script for index.html's `<head>`: applies the stored (or system) theme\n * before the first paint. Uses the default storage key. In a Vite app,\n * `karniTheme()` from `@karni/ui/vite` puts it there.\n */\nexport const KARNI_THEME_SCRIPT = `(function(){try{var t=localStorage.getItem(\"${THEME_STORAGE_KEY}\");var d=t===\"dark\"||((t===null||t===\"system\")&&matchMedia(\"(prefers-color-scheme: dark)\").matches);document.documentElement.classList.toggle(\"dark\",d);document.documentElement.style.colorScheme=d?\"dark\":\"light\"}catch(e){}})();`;\n"],"mappings":";AAMA,IAAaA,IAAoB,eAOpBC,IAAqB,+CAA+CD,EAAkB"}
@@ -0,0 +1,77 @@
1
+ import { ReactElement, ReactNode } from 'react';
2
+ import { KarniUser } from './types';
3
+ /**
4
+ * <AuthGuard> renders children only for authenticated users (optionally
5
+ * holding one of the given roles). Otherwise it renders a fallback or says
6
+ * why, in plain words (contract "Hooks + auth").
7
+ *
8
+ * Two different refusals: with `explain`, a visitor who is not signed in sees
9
+ * a sign-in prompt (the `Anonymous` slot: a LoginForm, so signing in reveals
10
+ * the content in place) and a signed-in user whose role lacks access sees
11
+ * PermissionDenied (the `Denied` slot). `anonymous` / `denied` render your own
12
+ * node for one of them, and `fallback` (one node for both) keeps working.
13
+ *
14
+ * Deprecation (0.4 → 1.0): a guard with none of `explain`, `fallback`,
15
+ * `anonymous`, `denied` or `slots` renders nothing when it refuses, as in
16
+ * 0.3, and warns once in development. 1.0 makes `explain` the default. A
17
+ * guard that hides a piece of UI passes `fallback={null}`.
18
+ *
19
+ * While the initial auth state resolves, the `loading` slot renders
20
+ * (default: nothing) so protected content never flashes a login screen
21
+ * during session restore.
22
+ */
23
+ import * as React from "react";
24
+ /** What the `Anonymous` slot receives: nobody is signed in. */
25
+ export interface AuthGuardAnonymousProps {
26
+ /** The roles the content needs, when the guard names some. */
27
+ roles: readonly string[];
28
+ className?: string;
29
+ }
30
+ /** What the `Denied` slot receives: someone is signed in, and no role of theirs is in `roles`. */
31
+ export interface AuthGuardDeniedProps {
32
+ user: KarniUser;
33
+ /** The roles the content needs. */
34
+ roles: readonly string[];
35
+ className?: string;
36
+ }
37
+ /**
38
+ * The replaceable refusals of AuthGuard. Pass any subset as `slots`.
39
+ * `defaultAuthGuardSlots` holds Karni's own, to wrap them.
40
+ */
41
+ export interface AuthGuardSlots {
42
+ /** Not signed in: a sign-in prompt. */
43
+ Anonymous: React.ComponentType<AuthGuardAnonymousProps>;
44
+ /** Signed in without the role: PermissionDenied. */
45
+ Denied: React.ComponentType<AuthGuardDeniedProps>;
46
+ }
47
+ export interface AuthGuardProps {
48
+ /** Grant access when the user holds AT LEAST ONE of these role names. */
49
+ roles?: string[];
50
+ /**
51
+ * Rendered for anonymous users and role mismatches alike. `anonymous` and
52
+ * `denied` (or `slots`) are preferred: they say which of the two it is.
53
+ * `null` renders nothing.
54
+ */
55
+ fallback?: ReactNode;
56
+ /** Rendered for a visitor who is not signed in (wins over `fallback`). */
57
+ anonymous?: ReactNode;
58
+ /** Rendered for a signed-in user whose role lacks access (wins over `fallback`). */
59
+ denied?: ReactNode;
60
+ /** Rendered while the auth status is still "loading". Default: nothing. */
61
+ loading?: ReactNode;
62
+ /** Replace the default refusals: Anonymous (sign-in prompt), Denied (PermissionDenied). */
63
+ slots?: Partial<AuthGuardSlots>;
64
+ /**
65
+ * Say why instead of rendering nothing: the sign-in prompt for a visitor,
66
+ * PermissionDenied for a role mismatch. It is the default from 1.0. Until
67
+ * then a guard with no fallback and no `explain` renders nothing (and warns).
68
+ */
69
+ explain?: boolean;
70
+ /** Merged onto the default refusal's root. */
71
+ className?: string;
72
+ children?: ReactNode;
73
+ }
74
+ /** Karni's own slots, exported so a project can wrap one instead of rewriting it. */
75
+ export declare const defaultAuthGuardSlots: AuthGuardSlots;
76
+ /** Renders its children only for a signed-in user, optionally with one of the given roles, and otherwise says why. */
77
+ export declare function AuthGuard(props: AuthGuardProps): ReactElement | null;
@@ -0,0 +1,63 @@
1
+ import { KarniErrorDescription } from '../states/describe-error';
2
+ import { ErrorSlotProps } from '../states/ErrorState';
3
+ import { KarniUser } from './types';
4
+ /**
5
+ * LoginForm is the sign-in form every app needs (contract: auth).
6
+ *
7
+ * Email + password against `useAuth().login`, with the error inline. On
8
+ * success it calls `onSuccess(user)` (navigate there). When the backend's
9
+ * 2FA gate fires, `on2FA` receives the ephemeral token so the app can render
10
+ * its code step (`POST <authBasePath>/2fa/login/`). Without a handler the
11
+ * form explains that a code is required. Render it inside `AuthProvider`,
12
+ * e.g. as `AuthGuard`'s `fallback`.
13
+ */
14
+ import * as React from "react";
15
+ /** What the `Error` slot receives: ErrorSlotProps plus the message, already worded for sign-in. */
16
+ export interface LoginFormErrorProps extends ErrorSlotProps {
17
+ /** Put this id on the message's root: the inputs' `aria-describedby` points at it. */
18
+ id: string;
19
+ /**
20
+ * The failure in plain words: wrong credentials ("That email and password
21
+ * do not match"), throttling ("Wait 42 seconds"), offline, a server error.
22
+ */
23
+ described: KarniErrorDescription;
24
+ }
25
+ /**
26
+ * The replaceable parts of LoginForm. Pass any subset as `slots`.
27
+ * `defaultLoginFormSlots` holds Karni's own, to wrap them.
28
+ */
29
+ export interface LoginFormSlots {
30
+ /** The message under the fields when signing in fails (announced as an alert). */
31
+ Error: React.ComponentType<LoginFormErrorProps>;
32
+ }
33
+ export interface LoginFormProps {
34
+ /** Called with the signed-in user. Navigate from here. */
35
+ onSuccess?: (user: KarniUser) => void;
36
+ /** Called when the account needs a second factor (the token completes it). */
37
+ on2FA?: (ephemeralToken: string) => void;
38
+ /** Heading above the fields. `null` renders none. Default "Sign in". */
39
+ title?: React.ReactNode;
40
+ /** Text under the heading (demo logins, a signup link, ...). */
41
+ description?: React.ReactNode;
42
+ /** The submit button's label. Default "Sign in". */
43
+ submitLabel?: React.ReactNode;
44
+ /** Disables the form (e.g. while the auth status is still "loading"). */
45
+ disabled?: boolean;
46
+ /** Focus the email field when the form appears. Default true: signing in is the page's purpose. */
47
+ autoFocus?: boolean;
48
+ /** Replace parts of the form: Error. */
49
+ slots?: Partial<LoginFormSlots>;
50
+ className?: string;
51
+ }
52
+ /** Karni's own slots, exported so a project can wrap one instead of rewriting it. */
53
+ export declare const defaultLoginFormSlots: LoginFormSlots;
54
+ /**
55
+ * Email and password sign-in form with inline errors and a callback for the two-factor step.
56
+ *
57
+ * Wrong credentials, throttling, a dropped connection and a server error each
58
+ * read differently. The message is announced, both fields point at it
59
+ * (`aria-describedby`) and are marked invalid when they are the problem.
60
+ * After a failure the email stays. Wrong credentials clear the password and
61
+ * focus it. Escape hatch: `slots.Error`.
62
+ */
63
+ export declare function LoginForm({ onSuccess, on2FA, title, description, submitLabel, disabled, autoFocus, slots, className, }: LoginFormProps): React.JSX.Element;