@krak-stack/registry 0.1.49 → 0.1.51

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/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @krak-stack/registry
2
2
 
3
+ ## 0.1.51
4
+
5
+ ### Patch Changes
6
+
7
+ - 0e67ce7: Add application events, server audit recording, and cookieless browser analytics through the OTLP/HTTP JSON logs endpoint.
8
+ - Install: `service-events`, or the `@krak-stack/registry/events`, `/events/browser`, and `/events/migrations` exports.
9
+ - Default OTLP: forward analytics to your telemetry backend; use `Otlp.event` for server telemetry.
10
+ - Optional SQL: PostgreSQL/SQLite persistence for in-app queries, visit timelines, and transactional audit records. `Events.track` requires SQL and supports verified actor context.
11
+ - Browser: `BrowserEvents` provides event/page tracking, automatic SPA views, DNT/GPC support, and path sanitization.
12
+ - Enrichment: trusted Cloudflare/custom geolocation and daily visitor IDs, without browser storage or automatic raw IP storage.
13
+ - Web Vitals: a separate `BrowserWebVitals` layer reuses the browser event exporter, respects DNT/GPC, and keeps `web-vitals` out of base browser imports.
14
+ - Dependencies: Bowser and Web Vitals are regular package dependencies, so package consumers do not need to declare them separately.
15
+ - Composition: `BrowserEvents` and `BrowserWebVitals` consume `BrowserOtlp`; server-side `Events` and `HttpApiOtlp` consume `Otlp`. Browser event export is enabled by default, batching is shared, and `Events.ingestionLayer` connects HTTP ingestion to application recording.
16
+
17
+ SQL is authoritative for persisted events; collector forwarding is best effort. Audit classification provides an application audit trail, not immutable archival storage or a compliance guarantee.
18
+
19
+ ## 0.1.50
20
+
21
+ ### Patch Changes
22
+
23
+ - Render configured empty groups and their actions in DataTable table and gallery views even when no resource rows exist. Preserve loading, error, and normal empty states when no groups are available.
24
+ - Persist Group by selections alongside column and view preferences, including explicitly cleared grouping. Keep existing saved preferences compatible and use the initial grouping when no grouping preference has been saved.
25
+
3
26
  ## 0.1.49
4
27
 
5
28
  ### Patch Changes
package/README.md CHANGED
@@ -1,449 +1,41 @@
1
1
  # @krak-stack/registry
2
2
 
3
- Tree-shakable runtime components and Effect services from the KrakStack shadcn registry.
3
+ Tree-shakable components and Effect services from the KrakStack registry.
4
+
5
+ ## Install
4
6
 
5
7
  ```bash
6
8
  bun add @krak-stack/registry
7
9
  ```
8
10
 
9
- ## Effect forms
10
-
11
- Applications using Effect forms need `@lucas-barake/effect-form@1.1.0` and
12
- `@lucas-barake/effect-form-react@1.1.0`, which support stable Effect 4 without
13
- compatibility patches:
14
-
15
- ```sh
16
- bun add @lucas-barake/effect-form@1.1.0 @lucas-barake/effect-form-react@1.1.0
17
- ```
11
+ Install the peer dependencies required by the items you use. Each item's registry documentation lists its dependencies and setup.
18
12
 
19
- When upgrading from the patched betas, remove their `patchedDependencies`
20
- entries and patch files, update any form version overrides to `1.1.0`, and run
21
- `bun install`. Preserve unrelated dependency patches.
13
+ ## Use
22
14
 
23
- ## Usage
24
-
25
- Import only the subpaths used by the application:
15
+ Import from the specific package subpaths you need:
26
16
 
27
17
  ```tsx
28
18
  import { DataTable } from "@krak-stack/registry/data-table";
29
- import { Pagination } from "@krak-stack/registry/pagination";
30
- import { AgentService } from "@krak-stack/registry/agent";
31
- import { AgentWidget, makeAgentAtoms } from "@krak-stack/registry/agent/client";
32
- import { makeAgentApiGroup } from "@krak-stack/registry/agent/schema";
33
- import { makeHttpApiToolkit } from "@krak-stack/registry/httpapi/toolkit";
34
- import { makeHttpApiCli } from "@krak-stack/registry/httpapi/cli";
35
- import { HttpApiAdapter } from "@krak-stack/registry/httpapi/adapter";
36
- import { HttpApiOtlp } from "@krak-stack/registry/opentelemetry/api";
19
+ import { Otlp } from "@krak-stack/registry/opentelemetry";
37
20
  import { BrowserOtlp } from "@krak-stack/registry/opentelemetry/browser";
38
- import { createDocsSource, makeDocs } from "@krak-stack/registry/docs";
39
- import { loadMdxDocsDirectory } from "@krak-stack/registry/docs/server";
40
- import {
41
- DocumentationToolkit,
42
- DocumentationToolkitLayer,
43
- } from "@krak-stack/registry/documentation-toolkit";
44
- import {
45
- WebFetchToolkit,
46
- WebFetchToolkitLayer,
47
- } from "@krak-stack/registry/webfetch-toolkit";
48
- import { Query } from "@krak-stack/registry/query";
49
- import { createSeo } from "@krak-stack/registry/seo";
50
- import { FileExtractionService } from "@krak-stack/registry/service-file-extraction";
51
- import { FileExtractedTextSchema } from "@krak-stack/registry/service-file-extraction/schema";
52
- import {
53
- HealthApiGroup,
54
- healthHandler,
55
- HealthService,
56
- } from "@krak-stack/registry/service-health";
57
- import { NotificationService } from "@krak-stack/registry/service-notification";
58
- ```
59
-
60
- ## OpenTelemetry
61
-
62
- | Export | Purpose |
63
- | --------------------------------------------------------- | --------------------------------------------------------------------------------------- |
64
- | `HttpApiOtlp.layer` from `opentelemetry/api` | Server exporters and same-origin browser ingestion routes. Includes `ServerOtlp.layer`. |
65
- | `ServerOtlp.layer` from `opentelemetry/server` | Exporters for workers, workflows, and CLIs without an HTTP server. |
66
- | `BrowserOtlp.layer(options)` from `opentelemetry/browser` | Browser tracing and optional events, logs, and metrics. |
67
-
68
- ### Setup
69
-
70
- Provide the HTTP layer once at the application composition root:
71
-
72
- ```ts
73
- import { Layer } from "effect";
74
- import { HttpApiOtlp } from "@krak-stack/registry/opentelemetry/api";
75
-
76
- const appLayer = appRoutes.pipe(Layer.provideMerge(HttpApiOtlp.layer));
77
- ```
78
-
79
- Configure an OTLP/HTTP collector on the server:
80
-
81
- ```dotenv
82
- OTEL_SERVICE_NAME=my-app-api
83
- OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
84
- OTEL_TRACES_EXPORTER=otlp
85
- OTEL_METRICS_EXPORTER=otlp
86
- OTEL_LOGS_EXPORTER=otlp
87
- ```
88
-
89
- Browser events require the logs signal. The proxy forwards enabled signals from
90
- `/api/otel/v1/{traces,metrics,logs}` to the collector. Keep collector credentials
91
- server-side. Server log endpoint/header overrides use
92
- `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` / `OTEL_EXPORTER_OTLP_LOGS_HEADERS`, falling
93
- back to the shared endpoint/headers; these overrides do not change proxy routing.
94
- `OTEL_SDK_DISABLED=true` disables server export, not browser collection.
95
-
96
- Install one browser layer on the Atom context passed to `AtomHttpApi.Service`:
97
-
98
- ```ts
99
- import { Atom } from "effect/reactivity";
100
- import { BrowserOtlp } from "@krak-stack/registry/opentelemetry/browser";
101
-
102
- const apiRuntime = Atom.context();
103
- if (!import.meta.env.SSR) {
104
- apiRuntime.addGlobalLayer(
105
- BrowserOtlp.layer({ serviceName: "my-app-web", events: {} }),
106
- );
107
- }
108
- ```
109
-
110
- Mount/read `ApiClient.runtime` in the root layout to start it. Browser methods
111
- target the active layer even when run from another Effect runtime. Calls before
112
- startup or after disposal are no-ops, not buffered. Dispose long-lived server and
113
- browser runtimes on shutdown to flush pending data.
114
-
115
- ### Browser API
116
-
117
- All methods return Effects. Use `yield*` inside Effect code or
118
- `Effect.runPromise(...)` / `Effect.runFork(...)` from application callbacks.
119
-
120
- | Method | Behavior |
121
- | ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
122
- | `identify({ userId?, organizationId? })` | Replace identity for future events; omitted fields clear old values. Emits no event. |
123
- | `identify(null)` | Clear identity, for example on logout. |
124
- | `track(name, properties?, options?)` | Record a named event. |
125
- | `page(options?)` | Record `browser.page_view`. Accepts `path`, `name`, `category`, `properties`, and event `options`. `pageView` is an alias. |
126
-
127
- `identify` has no typed failure: invalid input warns without including supplied
128
- values and leaves identity unchanged. `track` and `page` fail with an Effect
129
- schema error on invalid input. Identity is in memory only, applies to events
130
- rather than automatic traces/logs, and never rewrites queued events.
131
-
132
- ### Auth example
133
-
134
- Mount this once under the application's Atom registry. `ApiClient` and
135
- `authSessionAtom` are application-owned; the telemetry package has no auth
136
- dependency. The session atom in this example exposes KrakStack Auth session data.
137
-
138
- ```tsx
139
- import { useAtomSubscribe, useAtomValue } from "@effect/atom-react";
140
- import { BrowserOtlp } from "@krak-stack/registry/opentelemetry/browser";
141
- import { Effect } from "effect";
142
- import { AsyncResult } from "effect/reactivity";
143
- import { ApiClient } from "@/lib/api-client";
144
- import { authSessionAtom } from "@/services/auth/client";
145
-
146
- export const AuthTelemetry = () => {
147
- const runtime = useAtomValue(ApiClient.runtime);
148
-
149
- useAtomSubscribe(
150
- authSessionAtom,
151
- (session) => {
152
- if (!AsyncResult.isSuccess(runtime)) return;
153
-
154
- Effect.runFork(
155
- BrowserOtlp.identify(
156
- AsyncResult.isSuccess(session) && !session.waiting && session.value
157
- ? {
158
- userId: session.value.user.id,
159
- organizationId:
160
- session.value.session.activeOrganizationId ?? undefined,
161
- }
162
- : null,
163
- ),
164
- );
165
- },
166
- { immediate: true },
167
- );
168
-
169
- return null;
170
- };
171
- ```
172
-
173
- This identifies after startup and clears identity during auth loading, failure,
174
- and logout. The first page view may be anonymous. For other auth libraries, pass
175
- the same two IDs or `null` when auth state changes. Apply your own consent policy;
176
- do not send names, emails, or session tokens as identity.
177
-
178
- ### Page views and browser options
179
-
180
- `events: {}` enables custom events and one page view on startup, then on pathname
181
- changes through `pushState`, `replaceState`, and back/forward navigation.
182
- Same-path and query/hash-only changes are ignored. Tracking follows URL changes,
183
- not loader completion. Paths exclude query strings/fragments but may still
184
- contain personal IDs.
185
-
186
- For sanitized route templates or custom timing, use
187
- `events: { pageViews: false }` and call `page({ path: "/orders/:id" })` manually.
188
- Do not combine automatic and manual tracking for the same view.
189
-
190
- | Layer option | Default |
191
- | ----------------------------------------- | --------------------------------------------------------------- |
192
- | `serviceName` | Required |
193
- | `traces` | `{}`; includes global exception capture. `false` disables both. |
194
- | `events`, `logs`, `metrics` | `false`; enable each independently with `{}`. |
195
- | `baseUrl` | `/api/otel` |
196
- | `serviceVersion`, `attributes`, `headers` | Optional resource/transport metadata. |
197
-
198
- Browser events batch every 30 seconds, up to 100 records by default. Override
199
- `exportInterval`, `maxBatchSize`, and `shutdownTimeout` under `events`.
200
-
201
- ### Server events and shared options
202
-
203
- Define server events as Effects and run them inside the runtime with
204
- `ServerOtlp.layer` (or the HTTP layer):
205
-
206
- ```ts
207
- import { Effect } from "effect";
208
- import { ServerOtlp } from "@krak-stack/registry/opentelemetry/server";
209
-
210
- const orderCompleted = Effect.gen(function* () {
211
- yield* ServerOtlp.track("app.order.completed", { "order.total": 49 });
212
- });
213
- ```
214
-
215
- Authenticated handlers inherit `user.id` and `organization.id` from
216
- `AuthMiddleware` log annotations. Server identity is fiber-scoped; there is no
217
- server `identify` method. Background jobs can supply identity per event.
218
-
219
- Both `track` methods accept `options`:
220
-
221
- | Option | OTLP attribute / meaning |
222
- | ------------------------------------------------- | ------------------------------------------------------------------- |
223
- | `userId`, `anonymousId`, `sessionId`, `messageId` | `user.id`, `analytics.anonymous_id`, `session.id`, `log.record.uid` |
224
- | `context` | Additional flat attributes |
225
- | `timestamp` | Effect `DateTime.Utc` occurrence time; otherwise recorded now |
226
-
227
- Attribute precedence, lowest to highest: context, properties, explicit identity
228
- options, browser identified identity, scoped log annotations. Values support
229
- strings, finite numbers, booleans, and homogeneous arrays, not nested objects.
230
- Use stable event names and put dynamic values in attributes. Message IDs support
231
- correlation, not guaranteed deduplication.
232
-
233
- Events are OTLP log records with `eventName`, INFO severity, and active trace/span
234
- IDs when available; they do not create spans. `browser.page_view`, `url.path`,
235
- `analytics.page.name`, and `analytics.page.category` describe page events; the
236
- analytics names are project conventions, not standardized OTel semantics.
237
-
238
- Configure collector/storage separately. Browser identity is untrusted analytics
239
- metadata, not authorization or an audit trail. No visitor/session IDs or cookies
240
- are generated. Browser flushing on hidden/pagehide is best-effort. Apply payload
241
- and rate limits at ingestion, and keep sensitive data out of events and
242
- high-cardinality fields out of Loki labels.
243
-
244
- ## Other services
245
-
246
- `@krak-stack/registry/service-notification` is the source-compatible direct
247
- dispatcher. Use the separate `@krak-stack/notifications` package for a durable
248
- inbox, package-owned migrations, persisted delivery jobs, retries, workers, and
249
- one-shot reminders.
250
-
251
- Create a configured SEO helper once with site-wide defaults, then use it for each page:
252
-
253
- ```tsx
254
- const siteSeo = createSeo({
255
- origin: "https://krakstack.net",
256
- locales: ["en", "fr"],
257
- siteName: "KrakStack",
258
- sameAs: ["https://github.com/krakcons/krakstack"],
259
- });
260
-
261
- <Route
262
- head={() =>
263
- siteSeo({
264
- title: "KrakStack",
265
- description: "Production-ready building blocks for TanStack apps.",
266
- locale: "en",
267
- })
268
- }
269
- />;
270
- ```
271
-
272
- The returned object contains `meta`, `links`, and derived JSON-LD `scripts`. Website pages receive `WebSite` and `Organization` data; documentation pages can pass `type: "article"` for `Article` data. Use the lower-level `seo` function directly when a configured factory is not useful.
273
-
274
- HTTP API adapter, AI tool, and CLI utilities are available under
275
- the `@krak-stack/registry/httpapi/*` subpaths. Keep application-specific API
276
- layers, handlers, authentication, and client bindings in the application.
277
-
278
- Use `@krak-stack/registry/httpapi/toolkit` for HTTP API tools.
279
-
280
- ### HTTP API tools and MCP
281
-
282
- Static toolkits keep definitions and implementations separate:
283
- `DocumentationToolkit` / `DocumentationToolkitLayer({ docs, locale })` and
284
- `WebFetchToolkit` / `WebFetchToolkitLayer(options?)`. Merge the definitions with
285
- `Toolkit.merge`, then provide their handler layers. Web-fetch options are
286
- validated during layer acquisition through the Effect error channel.
287
-
288
- HTTP API tools are generated dynamically, so `makeHttpApiToolkit()` returns
289
- matching definitions and handlers together.
290
-
291
- CLI, toolkit, and MCP registration share `HttpApiAdapter.operations`. Each operation
292
- contains its tool name, typed `inputSchema`, derived `inputJsonSchema`, and method
293
- annotations. Inputs use `{ params, query, headers, body }`; only the CLI turns
294
- terminal arguments into that shape. The generated HTTP client handles wire
295
- encoding, and payload codecs retain their transformations.
296
-
297
- Use `makeHttpApiToolkit(config)` to construct matching tools and handlers once:
298
-
299
- ```ts
300
- import { makeHttpApiToolkit } from "@krak-stack/registry/httpapi/toolkit";
301
-
302
- const { toolkit, handlers } = yield * makeHttpApiToolkit();
303
- const tools = yield * toolkit.pipe(Effect.provide(handlers));
304
- ```
305
-
306
- Provide one `HttpApiAdapter` layer through the surrounding Effect layers:
307
-
308
- ```ts
309
- const adapterLayer = HttpApiAdapter.layer({
310
- api: AppApi,
311
- baseUrl: "https://example.com",
312
- methods: ["get"],
313
- }).pipe(Layer.provide(FetchHttpClient.layer));
314
21
  ```
315
22
 
316
- This replaces the separate `HttpApiSpec` and `ApiClient` services. The catalogue,
317
- input/success codecs, execution client, and result encoder all use the same API.
318
- Import from `@krak-stack/registry/httpapi/adapter`, or install
319
- `@krak-stack/httpapi-adapter` with shadcn. The old client/helper package subpaths
320
- and client registry item have been removed.
321
- Configuration is optional. Construct once and use the returned pair for agents
322
- or MCP; the separate `HttpApiToolkit` and `HttpApiToolkitLayer` factories have
323
- been removed.
324
-
325
- For CLI commands, `makeHttpApiCli()` returns `{ command, run }`. Provide the same
326
- `HttpApiAdapter` layer and supply the platform CLI services when
327
- running commands. `run` derives the CLI version from the API metadata:
328
-
329
- ```ts
330
- const { command, run } = yield * makeHttpApiCli();
331
- yield * run(args);
332
- ```
333
-
334
- `makeHttpApiCli` is the only public CLI export. `HttpApiCli`, its layer, and the
335
- custom runners have been removed. Process arguments, platform services, error
336
- reporting, and exit handling belong to the application's Effect runtime:
337
-
338
- ```ts
339
- import { NodeRuntime, NodeServices } from "@effect/platform-node";
340
-
341
- Effect.gen(function* () {
342
- const { run } = yield* makeHttpApiCli();
343
- yield* run(process.argv.slice(2));
344
- }).pipe(
345
- Effect.provide(adapterLayer),
346
- Effect.provide(NodeServices.layer),
347
- NodeRuntime.runMain,
348
- );
349
- ```
350
-
351
- Install `@effect/platform-node` matching your Effect version for this example;
352
- `adapterLayer` supplies the application's `HttpApiAdapter`.
353
-
354
- For an HTTP MCP server, register the toolkit directly with Effect. Keep the
355
- transport and server identity in the application:
356
-
357
- ```ts
358
- import { Effect, Layer } from "effect";
359
- import { McpProtocol, McpServer } from "effect/ai";
360
- import { FetchHttpClient } from "effect/http";
361
- import { HttpApiAdapter } from "@krak-stack/registry/httpapi/adapter";
362
- import { makeHttpApiToolkit } from "@krak-stack/registry/httpapi/toolkit";
363
- import { AppApi } from "@/api";
364
-
365
- export const mcpLayer = Layer.effectDiscard(
366
- Effect.gen(function* () {
367
- const { toolkit, handlers } = yield* makeHttpApiToolkit({});
368
- yield* McpServer.registerToolkit(toolkit).pipe(Effect.provide(handlers));
369
- }),
370
- ).pipe(
371
- Layer.provideMerge(
372
- McpServer.layerHttp({
373
- name: "app",
374
- version: "1.0.0",
375
- path: "/api/mcp",
376
- protocols: [McpProtocol.v2025_11_25],
377
- }),
378
- ),
379
- Layer.provide(
380
- HttpApiAdapter.layer({
381
- api: AppApi,
382
- baseUrl: "http://localhost:3000",
383
- methods: ["get"],
384
- }),
385
- ),
386
- Layer.provide(FetchHttpClient.layer),
387
- );
388
- ```
389
-
390
- This example explicitly selects GET operations; `HttpApiAdapter` otherwise includes
391
- all supported methods. Use `include` to narrow exposure further. Supply an
392
- authenticated `HttpClient` instead of `FetchHttpClient.layer` when the downstream
393
- API requires credentials. Inbound MCP authentication and authorization remain
394
- application-owned; tool annotations are not access controls.
395
-
396
- If intentionally exposing writes, enforce authorization or confirmation in the
397
- application before opting out of agent approval with `needsApproval: () => false`.
398
- Approval requirements are no longer silently disabled by an MCP adapter.
399
-
400
- The `HttpApiMcp` service, `@krak-stack/registry/httpapi/mcp` export, and
401
- `@krak-stack/httpapi-mcp` registry item have been removed. Replace them with the
402
- composition above. Any Effect toolkit can be registered this way; it does not
403
- need to originate from an HttpApi.
404
-
405
- Documentation consumers load and compile their application-owned MDX on the
406
- server, then pass the validated page records to `createDocsSource` and
407
- `makeDocs`:
408
-
409
- ```ts
410
- const pages = await loadMdxDocsDirectory("src/content/docs");
411
- const source = createDocsSource({ pages, locales: ["en", "fr"] });
412
- ```
413
-
414
- The `@krak-stack/registry/docs/server` export requires the Bun runtime. Keep it
415
- behind a server-only module or server function so it is not included in browser
416
- bundles.
417
-
418
- Add the package's Tailwind source to the application stylesheet:
23
+ For packaged UI components, include the Tailwind source in your application stylesheet:
419
24
 
420
25
  ```css
421
26
  @import "@krak-stack/registry/tailwind.css";
422
27
  ```
423
28
 
424
- The same canonical sources remain available through shadcn:
29
+ To install editable source instead of importing the package, use the shadcn registry:
425
30
 
426
31
  ```bash
427
- bunx shadcn@latest add @krak-stack/data-table
32
+ bunx shadcn@latest add https://krakstack.net/r/data-table.json
428
33
  ```
429
34
 
430
- Project-specific configuration and scaffolding remain available through shadcn.
431
-
432
- ## Oxlint Plugin
433
-
434
- Projects that prefer centrally versioned rules can load the compiled anti-slop
435
- plugin directly from the package:
436
-
437
- ```json
438
- {
439
- "jsPlugins": [
440
- {
441
- "name": "anti-slop",
442
- "specifier": "@krak-stack/registry/oxlint/anti-slop"
443
- }
444
- ]
445
- }
446
- ```
35
+ ## Find components and documentation
447
36
 
448
- Use `@krak-stack/lint-format` instead when the project should receive editable,
449
- vendored rule source under `tools/oxlint/anti-slop`.
37
+ - [KrakStack registry and docs](https://krakstack.net): browse items, dependencies, setup and usage.
38
+ - [Package exports](./package.json): available import subpaths.
39
+ - [Registry definitions](../../registry.json): item names, source files and documentation.
40
+ - [Source code](https://github.com/krakcons/krakstack): implementations and examples.
41
+ - [Changelog](./CHANGELOG.md): package releases.
@@ -979,6 +979,7 @@ import { jsx as jsx14, jsxs as jsxs8, Fragment } from "react/jsx-runtime";
979
979
  var DataTablePersistedUiStateSchema = Schema.Struct({
980
980
  columnVisibility: Schema.Record(Schema.String, Schema.Boolean),
981
981
  columnSizing: Schema.Record(Schema.String, Schema.Number),
982
+ grouping: Schema.optionalKey(Schema.Array(Schema.String)),
982
983
  view: Schema.Literals(["table", "gallery"])
983
984
  }).annotate({ identifier: "DataTablePersistedUiState" });
984
985
  var dataTableStorageRuntime = Atom.runtime(BrowserKeyValueStore.layerLocalStorage);
@@ -1071,11 +1072,11 @@ var DEFAULT_UI_STATE = {
1071
1072
  var persistedUiFromState = (state) => ({
1072
1073
  columnVisibility: state.columnVisibility,
1073
1074
  columnSizing: state.columnSizing,
1075
+ grouping: state.grouping,
1074
1076
  view: state.view
1075
1077
  });
1076
1078
  var transientUiFromState = (state) => ({
1077
1079
  rowSelection: state.rowSelection,
1078
- grouping: state.grouping,
1079
1080
  collapsedGroups: state.collapsedGroups
1080
1081
  });
1081
1082
  var clampWidth = (column, width) => Math.min(column.maxWidth ?? DEFAULT_MAX_WIDTH, Math.max(column.minWidth ?? DEFAULT_MIN_WIDTH, width));
@@ -2355,11 +2356,11 @@ var GroupActions = ({
2355
2356
  });
2356
2357
  };
2357
2358
  var GroupedTable = ({
2358
- tableAtom
2359
+ tableAtom,
2360
+ sections
2359
2361
  }) => {
2360
2362
  const [store, setStore] = useTableAtom(tableAtom);
2361
2363
  const model = deriveModel(store);
2362
- const sections = groupDataTableRows(model.sortedRows, getActiveGrouping(store));
2363
2364
  const extra = (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0);
2364
2365
  const renderSections = (items) => items.flatMap((section) => {
2365
2366
  const collapsed = !!store.state.collapsedGroups[section.key];
@@ -2597,12 +2598,15 @@ var DataTableBody = ({
2597
2598
  }) => {
2598
2599
  const [store] = useTableAtom(tableAtom);
2599
2600
  const model = deriveModel(store);
2600
- const grouped = getActiveGrouping(store).length > 0;
2601
+ const fields = getActiveGrouping(store);
2602
+ const grouped = fields.length > 0;
2601
2603
  const rows = grouped ? model.sortedRows : model.pageRows;
2604
+ const sections = groupDataTableRows(rows, fields);
2602
2605
  const colSpan = model.visibleColumns.length + (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0);
2603
- if (grouped && rows.length && !store.config.status.error) {
2606
+ if (sections.length && (rows.length || !store.config.status.loading) && !store.config.status.error) {
2604
2607
  return /* @__PURE__ */ jsx14(GroupedTable, {
2605
- tableAtom
2608
+ tableAtom,
2609
+ sections
2606
2610
  });
2607
2611
  }
2608
2612
  return /* @__PURE__ */ jsx14(TableBody, {
@@ -2706,6 +2710,7 @@ var DataTableGallery = ({
2706
2710
  const model = deriveModel(store);
2707
2711
  const fields = getActiveGrouping(store);
2708
2712
  const rows = fields.length ? model.sortedRows : model.pageRows;
2713
+ const sections = groupDataTableRows(rows, fields);
2709
2714
  if (store.config.status.error) {
2710
2715
  return /* @__PURE__ */ jsx14("div", {
2711
2716
  className: "text-destructive rounded-lg border border-dashed p-10 text-center",
@@ -2720,7 +2725,7 @@ var DataTableGallery = ({
2720
2725
  })
2721
2726
  });
2722
2727
  }
2723
- if (!rows.length) {
2728
+ if (!rows.length && !sections.length) {
2724
2729
  return /* @__PURE__ */ jsx14("div", {
2725
2730
  className: "text-muted-foreground rounded-lg border border-dashed p-10 text-center",
2726
2731
  children: store.config.status.empty ?? store.config.labels.empty
@@ -2799,7 +2804,7 @@ var DataTableGallery = ({
2799
2804
  });
2800
2805
  return /* @__PURE__ */ jsx14("div", {
2801
2806
  className: "space-y-4",
2802
- children: renderSections(groupDataTableRows(rows, fields))
2807
+ children: renderSections(sections)
2803
2808
  });
2804
2809
  };
2805
2810
  var DataTablePagination = ({
@@ -2845,15 +2850,17 @@ var HydratedDataTable = ({
2845
2850
  setPersistedUiState,
2846
2851
  ...props
2847
2852
  }) => {
2848
- const [transientUiAtom] = useState(() => {
2853
+ const [initialGrouping] = useState(() => {
2849
2854
  const grouping = props.features?.grouping;
2850
- return Atom.make({
2851
- ...transientUiFromState(DEFAULT_UI_STATE),
2852
- grouping: grouping && grouping.initial ? grouping.initial : []
2853
- });
2855
+ return grouping && grouping.initial ? grouping.initial : [];
2854
2856
  });
2857
+ const [transientUiAtom] = useState(() => Atom.make(transientUiFromState(DEFAULT_UI_STATE)));
2855
2858
  const [transientUiState, setTransientUiState] = useAtom(transientUiAtom);
2856
- const uiState = useMemo(() => ({ ...persistedUiState, ...transientUiState }), [persistedUiState, transientUiState]);
2859
+ const uiState = useMemo(() => ({
2860
+ ...persistedUiState,
2861
+ ...transientUiState,
2862
+ grouping: persistedUiState.grouping ?? initialGrouping
2863
+ }), [persistedUiState, transientUiState, initialGrouping]);
2857
2864
  const setUiState = useCallback((state) => {
2858
2865
  setPersistedUiState(persistedUiFromState(state));
2859
2866
  setTransientUiState(transientUiFromState(state));
@@ -2946,7 +2953,10 @@ var DataTable = (props) => {
2946
2953
  runtime: dataTableStorageRuntime,
2947
2954
  key: `data-table:${pathname}:${columnIds}:${viewCapability}:ui`,
2948
2955
  schema: DataTablePersistedUiStateSchema,
2949
- defaultValue: () => persistedUiFromState(DEFAULT_UI_STATE)
2956
+ defaultValue: () => ({
2957
+ ...persistedUiFromState(DEFAULT_UI_STATE),
2958
+ grouping: props.features?.grouping ? props.features.grouping.initial ?? [] : []
2959
+ })
2950
2960
  });
2951
2961
  });
2952
2962
  const [persistedUiResult, setPersistedUiState] = useAtom(persistedUiAtom);
package/dist/lib/docs.js CHANGED
@@ -410,7 +410,7 @@ var MarkdownContent = ({
410
410
  dangerouslySetInnerHTML: { __html: remainingHtml }
411
411
  }, "html-final"));
412
412
  return /* @__PURE__ */ jsx5("div", {
413
- className: cn("[&_a:hover]:text-primary [&_a]:decoration-border [&_blockquote]:border-primary/40 [&_blockquote]:bg-muted/40 [&_h2_a]:text-muted-foreground [&_h3_a]:text-muted-foreground [&_[data-inline-code]]:bg-muted text-[0.98rem] leading-7 [&_[data-markdown-table]]:overflow-x-auto [&_[data-inline-code]]:rounded [&_[data-inline-code]]:px-1.5 [&_[data-inline-code]]:py-0.5 [&_[data-inline-code]]:font-mono [&_[data-inline-code]]:text-[0.875em] [&_a]:font-medium [&_a]:underline [&_a]:decoration-1 [&_a]:underline-offset-4 [&_a]:transition-colors [&_blockquote]:my-5 [&_blockquote]:rounded-r-lg [&_blockquote]:border-l-4 [&_blockquote]:px-5 [&_blockquote]:py-1 [&_h2]:mt-12 [&_h2]:scroll-mt-20 [&_h2]:border-t [&_h2]:pt-8 [&_h2]:text-2xl [&_h2]:font-bold [&_h2]:tracking-tight [&_h2_a]:ml-2 [&_h2_a]:no-underline [&_h2:first-of-type]:mt-0 [&_h2:first-of-type]:border-t-0 [&_h2:first-of-type]:pt-0 [&_h3]:mt-8 [&_h3]:scroll-mt-20 [&_h3]:text-xl [&_h3]:font-semibold [&_h3]:tracking-tight [&_h3_a]:ml-2 [&_h3_a]:no-underline [&_ol]:my-5 [&_p]:my-5 [&_table]:w-full [&_table]:text-sm [&_td]:border-b [&_td]:p-2 [&_th]:border-b [&_th]:p-2 [&_th]:text-left [&_ul]:my-5", className),
413
+ className: cn("[&_a:hover]:text-primary [&_a]:decoration-border [&_blockquote]:border-primary/40 [&_blockquote]:bg-muted/40 [&_h2_a]:text-muted-foreground [&_h3_a]:text-muted-foreground [&_[data-inline-code]]:bg-muted text-[0.98rem] leading-7 [&_[data-markdown-table]]:overflow-x-auto [&_[data-inline-code]]:rounded [&_[data-inline-code]]:px-1.5 [&_[data-inline-code]]:py-0.5 [&_[data-inline-code]]:font-mono [&_[data-inline-code]]:text-[0.875em] [&_a]:font-medium [&_a]:underline [&_a]:decoration-1 [&_a]:underline-offset-4 [&_a]:transition-colors [&_blockquote]:my-5 [&_blockquote]:rounded-r-lg [&_blockquote]:border-l-4 [&_blockquote]:px-5 [&_blockquote]:py-1 [&_h2]:mt-12 [&_h2]:scroll-mt-20 [&_h2]:border-t [&_h2]:pt-8 [&_h2]:text-2xl [&_h2]:font-bold [&_h2]:tracking-tight [&_h2_a]:ml-2 [&_h2_a]:no-underline [&_h2:first-of-type]:mt-0 [&_h2:first-of-type]:border-t-0 [&_h2:first-of-type]:pt-0 [&_h3]:mt-8 [&_h3]:scroll-mt-20 [&_h3]:text-xl [&_h3]:font-semibold [&_h3]:tracking-tight [&_h3_a]:ml-2 [&_h3_a]:no-underline [&_ol]:my-5 [&_p]:my-5 [&_table]:w-full [&_table]:text-sm [&_td]:border-b [&_td]:p-2 [&_th]:border-b [&_th]:p-2 [&_th]:text-left [&_ul]:my-5", "[&_li]:my-1 [&_li>ol]:my-2 [&_li>p]:my-2 [&_li>ul]:my-2 [&_ol]:list-decimal [&_ol]:ps-6 [&_ul]:list-disc [&_ul]:ps-6", className),
414
414
  children: content
415
415
  });
416
416
  };
@@ -2011,7 +2011,7 @@ var DocsArticle = ({
2011
2011
  });
2012
2012
  };
2013
2013
  var useActiveDocsHeading = (headings) => {
2014
- const [activeHeadingId, setActiveHeadingId] = useState6(headings[0]?.id);
2014
+ const [activeHeadingId, setActiveHeadingId] = useState6();
2015
2015
  useEffect5(() => {
2016
2016
  const elements = headings.flatMap((heading) => {
2017
2017
  const element = document.getElementById(heading.id);
@@ -413,7 +413,7 @@ var MarkdownContent = ({
413
413
  dangerouslySetInnerHTML: { __html: remainingHtml }
414
414
  }, "html-final"));
415
415
  return /* @__PURE__ */ jsx4("div", {
416
- className: cn("[&_a:hover]:text-primary [&_a]:decoration-border [&_blockquote]:border-primary/40 [&_blockquote]:bg-muted/40 [&_h2_a]:text-muted-foreground [&_h3_a]:text-muted-foreground [&_[data-inline-code]]:bg-muted text-[0.98rem] leading-7 [&_[data-markdown-table]]:overflow-x-auto [&_[data-inline-code]]:rounded [&_[data-inline-code]]:px-1.5 [&_[data-inline-code]]:py-0.5 [&_[data-inline-code]]:font-mono [&_[data-inline-code]]:text-[0.875em] [&_a]:font-medium [&_a]:underline [&_a]:decoration-1 [&_a]:underline-offset-4 [&_a]:transition-colors [&_blockquote]:my-5 [&_blockquote]:rounded-r-lg [&_blockquote]:border-l-4 [&_blockquote]:px-5 [&_blockquote]:py-1 [&_h2]:mt-12 [&_h2]:scroll-mt-20 [&_h2]:border-t [&_h2]:pt-8 [&_h2]:text-2xl [&_h2]:font-bold [&_h2]:tracking-tight [&_h2_a]:ml-2 [&_h2_a]:no-underline [&_h2:first-of-type]:mt-0 [&_h2:first-of-type]:border-t-0 [&_h2:first-of-type]:pt-0 [&_h3]:mt-8 [&_h3]:scroll-mt-20 [&_h3]:text-xl [&_h3]:font-semibold [&_h3]:tracking-tight [&_h3_a]:ml-2 [&_h3_a]:no-underline [&_ol]:my-5 [&_p]:my-5 [&_table]:w-full [&_table]:text-sm [&_td]:border-b [&_td]:p-2 [&_th]:border-b [&_th]:p-2 [&_th]:text-left [&_ul]:my-5", className),
416
+ className: cn("[&_a:hover]:text-primary [&_a]:decoration-border [&_blockquote]:border-primary/40 [&_blockquote]:bg-muted/40 [&_h2_a]:text-muted-foreground [&_h3_a]:text-muted-foreground [&_[data-inline-code]]:bg-muted text-[0.98rem] leading-7 [&_[data-markdown-table]]:overflow-x-auto [&_[data-inline-code]]:rounded [&_[data-inline-code]]:px-1.5 [&_[data-inline-code]]:py-0.5 [&_[data-inline-code]]:font-mono [&_[data-inline-code]]:text-[0.875em] [&_a]:font-medium [&_a]:underline [&_a]:decoration-1 [&_a]:underline-offset-4 [&_a]:transition-colors [&_blockquote]:my-5 [&_blockquote]:rounded-r-lg [&_blockquote]:border-l-4 [&_blockquote]:px-5 [&_blockquote]:py-1 [&_h2]:mt-12 [&_h2]:scroll-mt-20 [&_h2]:border-t [&_h2]:pt-8 [&_h2]:text-2xl [&_h2]:font-bold [&_h2]:tracking-tight [&_h2_a]:ml-2 [&_h2_a]:no-underline [&_h2:first-of-type]:mt-0 [&_h2:first-of-type]:border-t-0 [&_h2:first-of-type]:pt-0 [&_h3]:mt-8 [&_h3]:scroll-mt-20 [&_h3]:text-xl [&_h3]:font-semibold [&_h3]:tracking-tight [&_h3_a]:ml-2 [&_h3_a]:no-underline [&_ol]:my-5 [&_p]:my-5 [&_table]:w-full [&_table]:text-sm [&_td]:border-b [&_td]:p-2 [&_th]:border-b [&_th]:p-2 [&_th]:text-left [&_ul]:my-5", "[&_li]:my-1 [&_li>ol]:my-2 [&_li>p]:my-2 [&_li>ul]:my-2 [&_ol]:list-decimal [&_ol]:ps-6 [&_ul]:list-disc [&_ul]:ps-6", className),
417
417
  children: content
418
418
  });
419
419
  };
@@ -0,0 +1,26 @@
1
+ import type { EventAttributes } from "../opentelemetry/schema.js";
2
+ import { OtlpEvents } from "../opentelemetry/events.js";
3
+ import { Context, Effect, Layer, Schema } from "effect";
4
+ import { BrowserEventOptions, type BrowserPageOptions } from "./schema.js";
5
+ export type { BrowserEventOptions, BrowserPageOptions } from "./schema.js";
6
+ export type { EventAttributes } from "../opentelemetry/schema.js";
7
+ export interface BrowserEventsOptions {
8
+ readonly enabled?: boolean;
9
+ readonly respectDoNotTrack?: boolean;
10
+ readonly pageViews?: boolean;
11
+ readonly locale?: () => string;
12
+ /** Replace paths containing personal identifiers with route templates. */
13
+ readonly sanitizePath?: (path: string) => string;
14
+ }
15
+ declare const BrowserEventsClient_base: Context.ServiceClass<BrowserEventsClient, "krakstack/events/BrowserEventsClient", {
16
+ readonly events: OtlpEvents["Service"];
17
+ readonly context: (name: string, properties?: EventAttributes) => EventAttributes;
18
+ }>;
19
+ declare class BrowserEventsClient extends BrowserEventsClient_base {
20
+ }
21
+ export declare class BrowserEvents {
22
+ static readonly track: (name: string, properties?: EventAttributes, options?: BrowserEventOptions) => Effect.Effect<void, Schema.SchemaError, never>;
23
+ static readonly page: (options?: BrowserPageOptions) => Effect.Effect<void, Schema.SchemaError, never>;
24
+ /** Requires BrowserOtlp; no identifiers are persisted. */
25
+ static readonly layer: ({ enabled, respectDoNotTrack, pageViews, locale, sanitizePath, }?: BrowserEventsOptions) => Layer.Layer<BrowserEventsClient, never, OtlpEvents>;
26
+ }