@northgraindata/dsui 0.4.1 → 0.5.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.
- package/bin/dsui.mjs +1 -1
- package/dist/plugin-sdk.mjs +1 -1
- package/dist/runtime/plugins/code-repository.browser.mjs +60 -0
- package/dist/runtime/plugins/code-repository.mjs +2 -2
- package/dist/runtime/plugins/example-plugin.mjs +1 -1
- package/dist/runtime/plugins/health.browser.mjs +202 -68
- package/dist/runtime/plugins/health.mjs +97 -6
- package/dist/runtime/plugins/monitoring.mjs +11 -1
- package/dist/runtime/plugins/status-pages.browser.mjs +5033 -0
- package/dist/runtime/plugins/status-pages.mjs +52 -0
- package/dist/server.mjs +205 -188
- package/package.json +1 -1
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@northgraindata/dsui-ui/src/components/input.tsx +2 -5
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@northgraindata/dsui-ui/src/components/suggest-input.tsx +197 -0
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@northgraindata/dsui-ui/src/index.tsx +5 -0
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@northgraindata/dsui-ui/src/styles.css +54 -0
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/cjs/index.cjs +3 -2
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/cjs/index.cjs.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/esm/index.js +3 -2
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/esm/index.js.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/package.json +2 -2
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/src/index.tsx +11 -2
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.cjs +79 -26
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.cjs.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.d.cts +12 -1
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.cjs +14 -2
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.cjs.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.d.cts +3 -2
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.d.ts +12 -1
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.js +79 -26
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.js.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.d.ts +3 -2
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js +14 -2
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/package.json +1 -1
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/src/index.ts +135 -24
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/src/scroll-classifier.ts +31 -3
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/define.ts +22 -1
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/index.ts +1 -0
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/presentation.test.ts +73 -0
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/presentation.ts +34 -0
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/types.ts +23 -0
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/layout/gauge.tsx +14 -2
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/dataset/dataset.test.ts +134 -0
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/dataset/index.ts +141 -0
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/index.ts +23 -0
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/cjs/index.cjs +3 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/cjs/index.cjs.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/esm/index.js +3 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/dist/esm/index.js.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/package.json +2 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/react-virtual/src/index.tsx +11 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.cjs +79 -26
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.cjs.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.d.cts +12 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.cjs +14 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.cjs.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.d.cts +3 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.d.ts +12 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.js +79 -26
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.js.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.d.ts +3 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js +14 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/package.json +1 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/src/index.ts +135 -24
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/node_modules/@tanstack/virtual-core/src/scroll-classifier.ts +31 -3
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/define.ts +22 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/index.ts +1 -0
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/presentation.test.ts +73 -0
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/presentation.ts +34 -0
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/adapter/types.ts +23 -0
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/layout/gauge.tsx +14 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/dataset/dataset.test.ts +134 -0
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/dataset/index.ts +141 -0
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/index.ts +23 -0
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/react-virtual/dist/cjs/index.cjs +3 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/react-virtual/dist/cjs/index.cjs.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/react-virtual/dist/esm/index.js +3 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/react-virtual/dist/esm/index.js.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/react-virtual/package.json +2 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/react-virtual/src/index.tsx +11 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.cjs +79 -26
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.cjs.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/cjs/index.d.cts +12 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.cjs +14 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.cjs.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/cjs/scroll-classifier.d.cts +3 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.d.ts +12 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.js +79 -26
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/esm/index.js.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.d.ts +3 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js +14 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/dist/esm/scroll-classifier.js.map +1 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/package.json +1 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/src/index.ts +135 -24
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@tanstack/virtual-core/src/scroll-classifier.ts +31 -3
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/package.json +2 -1
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/src/diagnostics.ts +24 -0
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/src/events.ts +6 -0
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/src/index.ts +162 -2
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/src/modal.test.ts +76 -0
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/src/modal.ts +200 -0
- package/sdk/node_modules/@northgraindata/dsui-ui/src/components/input.tsx +2 -5
- package/sdk/node_modules/@northgraindata/dsui-ui/src/components/suggest-input.tsx +197 -0
- package/sdk/node_modules/@northgraindata/dsui-ui/src/index.tsx +5 -0
- package/sdk/node_modules/@northgraindata/dsui-ui/src/styles.css +54 -0
- package/web/assets/index-DQkPkPN7.css +1 -0
- package/web/assets/index-w07fgRf1.js +218 -0
- package/web/index.html +2 -2
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/keyed-items.test.ts +0 -23
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/query-editor/column-profile.test.ts +0 -109
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/query-editor/query-explorer.test.ts +0 -29
- package/sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/table-data.test.ts +0 -65
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/keyed-items.test.ts +0 -23
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/query-editor/column-profile.test.ts +0 -109
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/query-editor/query-explorer.test.ts +0 -29
- package/sdk/node_modules/@northgraindata/dsui-plugin-sdk/node_modules/@northgraindata/dsui-adapter-sdk/src/components/ui/table-data.test.ts +0 -65
- package/web/assets/index-BBd7EEtd.js +0 -98
- package/web/assets/index-C16grSph.css +0 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { defineAdapter } from "./define";
|
|
3
|
+
|
|
4
|
+
const base = {
|
|
5
|
+
metadata: { id: "community", name: "Community adapter", version: "1.0.0" },
|
|
6
|
+
health: async () => ({ status: "healthy" as const, score: 100, checks: [] }),
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
test("community adapters can declare catalog content without changing runtime capabilities", () => {
|
|
10
|
+
const adapter = defineAdapter({
|
|
11
|
+
...base,
|
|
12
|
+
metadata: {
|
|
13
|
+
...base.metadata,
|
|
14
|
+
presentation: {
|
|
15
|
+
category: " Databases ",
|
|
16
|
+
features: [{ title: "SQL workspace", description: "Run queries." }],
|
|
17
|
+
links: [
|
|
18
|
+
{
|
|
19
|
+
kind: "documentation",
|
|
20
|
+
label: "Documentation",
|
|
21
|
+
href: "https://example.com/docs",
|
|
22
|
+
},
|
|
23
|
+
{ label: "More info", href: "https://example.com" },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
expect(adapter.metadata.presentation?.category).toBe("Databases");
|
|
29
|
+
expect(adapter.metadata.presentation?.features?.[0]?.title).toBe(
|
|
30
|
+
"SQL workspace",
|
|
31
|
+
);
|
|
32
|
+
expect(adapter.metadata.presentation?.links?.[0]?.href).toBe(
|
|
33
|
+
"https://example.com/docs",
|
|
34
|
+
);
|
|
35
|
+
expect(adapter.metadata.presentation?.links?.[0]?.kind).toBe("documentation");
|
|
36
|
+
expect(adapter.metadata.presentation?.links?.[1]?.kind).toBeUndefined();
|
|
37
|
+
expect(adapter.resources).toEqual([]);
|
|
38
|
+
expect(defineAdapter(base).metadata).not.toHaveProperty("presentation");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
for (const href of [
|
|
42
|
+
"javascript:alert(1)",
|
|
43
|
+
"data:text/html,test",
|
|
44
|
+
"/relative/docs",
|
|
45
|
+
]) {
|
|
46
|
+
test(`rejects an unsupported catalog link: ${href}`, () => {
|
|
47
|
+
expect(() =>
|
|
48
|
+
defineAdapter({
|
|
49
|
+
...base,
|
|
50
|
+
metadata: {
|
|
51
|
+
...base.metadata,
|
|
52
|
+
presentation: {
|
|
53
|
+
links: [{ label: "Docs", href }],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
).toThrow("Invalid adapter presentation");
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
test("rejects empty feature labels rather than publishing unusable catalog content", () => {
|
|
62
|
+
expect(() =>
|
|
63
|
+
defineAdapter({
|
|
64
|
+
...base,
|
|
65
|
+
metadata: {
|
|
66
|
+
...base.metadata,
|
|
67
|
+
presentation: {
|
|
68
|
+
features: [{ title: " " }],
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
72
|
+
).toThrow("Invalid adapter presentation");
|
|
73
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/** Optional, author-maintained catalog content. Runtime capabilities remain separate. */
|
|
4
|
+
export const adapterPresentationSchema = z.object({
|
|
5
|
+
category: z.string().trim().min(1).optional(),
|
|
6
|
+
overview: z.string().trim().min(1).optional(),
|
|
7
|
+
features: z
|
|
8
|
+
.array(
|
|
9
|
+
z.object({
|
|
10
|
+
title: z.string().trim().min(1),
|
|
11
|
+
description: z.string().trim().min(1).optional(),
|
|
12
|
+
}),
|
|
13
|
+
)
|
|
14
|
+
.optional(),
|
|
15
|
+
compatibility: z.array(z.string().trim().min(1)).optional(),
|
|
16
|
+
limitations: z.array(z.string().trim().min(1)).optional(),
|
|
17
|
+
links: z
|
|
18
|
+
.array(
|
|
19
|
+
z.object({
|
|
20
|
+
kind: z.enum(["website", "documentation", "source"]).optional(),
|
|
21
|
+
label: z.string().trim().min(1),
|
|
22
|
+
href: z
|
|
23
|
+
.string()
|
|
24
|
+
.url()
|
|
25
|
+
.refine(
|
|
26
|
+
(value) => /^https?:\/\//i.test(value),
|
|
27
|
+
"Catalog links must use HTTP or HTTPS",
|
|
28
|
+
),
|
|
29
|
+
}),
|
|
30
|
+
)
|
|
31
|
+
.optional(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export type AdapterPresentation = z.infer<typeof adapterPresentationSchema>;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
2
|
import type { AnyActionDefinition } from "../action/index";
|
|
3
3
|
import type { BlobStore } from "../blob";
|
|
4
|
+
import type { DatasetsCapability } from "../dataset/index";
|
|
4
5
|
import type { AnyJobDefinition } from "../job";
|
|
5
6
|
import type { AnyPageDefinition } from "../page/index";
|
|
6
7
|
import type { AnyResourceDefinition } from "../resource/index";
|
|
7
8
|
import type { AnyRouteDefinition } from "../route";
|
|
8
9
|
import type { AnySignalDefinition } from "../signal";
|
|
9
10
|
import type { AnyStoreDefinition } from "../store/index";
|
|
11
|
+
import type { AdapterPresentation } from "./presentation";
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Host API contract version, independent of the npm package version.
|
|
@@ -51,6 +53,8 @@ export interface AdapterInfo {
|
|
|
51
53
|
* when missing or unreachable.
|
|
52
54
|
*/
|
|
53
55
|
iconUrl?: string;
|
|
56
|
+
/** Optional catalog content shared by the host and connection flow. */
|
|
57
|
+
presentation?: AdapterPresentation;
|
|
54
58
|
/** One-line description for listings. */
|
|
55
59
|
description?: string;
|
|
56
60
|
}
|
|
@@ -115,6 +119,12 @@ export interface AdapterHealthCheck {
|
|
|
115
119
|
readonly ok: boolean;
|
|
116
120
|
/** Optional measured value or explanation. */
|
|
117
121
|
readonly detail?: string;
|
|
122
|
+
/**
|
|
123
|
+
* Where to look when this signal fails, as a path inside the service's
|
|
124
|
+
* workspace such as `/dags`. A consumer may offer it as a link; it never
|
|
125
|
+
* runs anything. Must start with a single `/`.
|
|
126
|
+
*/
|
|
127
|
+
readonly href?: string;
|
|
118
128
|
}
|
|
119
129
|
|
|
120
130
|
/**
|
|
@@ -202,6 +212,13 @@ export interface AdapterDefinition<TContext = unknown, TConfig = unknown> {
|
|
|
202
212
|
readonly signals: readonly AnySignalDefinition[];
|
|
203
213
|
/** HTTP endpoints each configured service serves. */
|
|
204
214
|
readonly routes: readonly AnyRouteDefinition<TContext>[];
|
|
215
|
+
/**
|
|
216
|
+
* Describes the data this system holds, when it can do so cheaply.
|
|
217
|
+
*
|
|
218
|
+
* Optional: a plugin that needs it skips services whose adapter does not
|
|
219
|
+
* declare it, so an adapter adopts it when it is ready.
|
|
220
|
+
*/
|
|
221
|
+
readonly datasets?: DatasetsCapability<TContext>;
|
|
205
222
|
}
|
|
206
223
|
|
|
207
224
|
/**
|
|
@@ -284,4 +301,10 @@ export interface DefineAdapterOptions<TContext, TConfig> {
|
|
|
284
301
|
signals?: readonly AnySignalDefinition[];
|
|
285
302
|
/** HTTP endpoints, served per configured service. */
|
|
286
303
|
routes?: readonly AnyRouteDefinition<TContext>[];
|
|
304
|
+
/**
|
|
305
|
+
* Lists and measures the datasets (tables, files, assets) behind a service.
|
|
306
|
+
*
|
|
307
|
+
* @see {@link DatasetsCapability}
|
|
308
|
+
*/
|
|
309
|
+
datasets?: DatasetsCapability<TContext>;
|
|
287
310
|
}
|
|
@@ -68,7 +68,13 @@ export function Gauge({ node }: { node: PageNode }) {
|
|
|
68
68
|
? node.props.label
|
|
69
69
|
: undefined;
|
|
70
70
|
return (
|
|
71
|
-
<div
|
|
71
|
+
<div
|
|
72
|
+
className="ov-gauge"
|
|
73
|
+
data-tone={tone}
|
|
74
|
+
role="img"
|
|
75
|
+
aria-label={label ?? `${Math.round(value)} of ${max}`}
|
|
76
|
+
title={label}
|
|
77
|
+
>
|
|
72
78
|
<svg viewBox="0 0 64 64" aria-hidden="true">
|
|
73
79
|
<path
|
|
74
80
|
d={circlePath(radius)}
|
|
@@ -84,8 +90,14 @@ export function Gauge({ node }: { node: PageNode }) {
|
|
|
84
90
|
/>
|
|
85
91
|
</svg>
|
|
86
92
|
{showValue ? (
|
|
87
|
-
<span className="ov-gauge-number">
|
|
93
|
+
<span className="ov-gauge-number">
|
|
94
|
+
{Math.round(value)}
|
|
95
|
+
<small className="ov-gauge-max">/{max}</small>
|
|
96
|
+
</span>
|
|
88
97
|
) : null}
|
|
98
|
+
<span className="ov-gauge-bar" aria-hidden="true">
|
|
99
|
+
<span style={{ width: `${share * 100}%` }} />
|
|
100
|
+
</span>
|
|
89
101
|
</div>
|
|
90
102
|
);
|
|
91
103
|
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { defineAdapter } from "../adapter/index";
|
|
3
|
+
import { InvalidDefinitionError } from "../shared/errors";
|
|
4
|
+
import {
|
|
5
|
+
DATASET_OBSERVE_MAX_REFS,
|
|
6
|
+
type DatasetsCapability,
|
|
7
|
+
datasetListInputSchema,
|
|
8
|
+
datasetObservationSchema,
|
|
9
|
+
datasetObserveInputSchema,
|
|
10
|
+
datasetPageSchema,
|
|
11
|
+
defineDatasets,
|
|
12
|
+
} from "./index";
|
|
13
|
+
|
|
14
|
+
const health = async () => ({
|
|
15
|
+
status: "healthy" as const,
|
|
16
|
+
score: 100,
|
|
17
|
+
checks: [],
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const capability: DatasetsCapability<{ rows: number }> = {
|
|
21
|
+
list: () => ({
|
|
22
|
+
items: [{ ref: { name: "public.orders" }, kind: "table" }],
|
|
23
|
+
}),
|
|
24
|
+
observe: (refs, ctx) =>
|
|
25
|
+
refs.map((ref) => ({
|
|
26
|
+
ref,
|
|
27
|
+
at: "2026-11-19T10:00:00.000Z",
|
|
28
|
+
rowCount: ctx.rows,
|
|
29
|
+
})),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function adapter(datasets?: DatasetsCapability<{ rows: number }>) {
|
|
33
|
+
return defineAdapter({
|
|
34
|
+
metadata: { id: "demo", name: "Demo", version: "1.0.0" },
|
|
35
|
+
context: () => ({ rows: 42 }),
|
|
36
|
+
health,
|
|
37
|
+
...(datasets ? { datasets } : {}),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe("datasets capability", () => {
|
|
42
|
+
test("is absent unless the adapter declares it", () => {
|
|
43
|
+
expect(adapter().datasets).toBeUndefined();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("is carried on the definition and called with the context", async () => {
|
|
47
|
+
const definition = adapter(capability);
|
|
48
|
+
const ctx = await definition.createContext({});
|
|
49
|
+
const observed = await definition.datasets?.observe(
|
|
50
|
+
[{ name: "public.orders" }],
|
|
51
|
+
ctx,
|
|
52
|
+
);
|
|
53
|
+
expect(observed).toEqual([
|
|
54
|
+
{
|
|
55
|
+
ref: { name: "public.orders" },
|
|
56
|
+
at: "2026-11-19T10:00:00.000Z",
|
|
57
|
+
rowCount: 42,
|
|
58
|
+
},
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("rejects a capability without both reads", () => {
|
|
63
|
+
expect(() =>
|
|
64
|
+
defineDatasets({ list: capability.list } as DatasetsCapability),
|
|
65
|
+
).toThrow(InvalidDefinitionError);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("dataset schemas", () => {
|
|
70
|
+
test("list input defaults the page size and enforces the ceiling", () => {
|
|
71
|
+
expect(datasetListInputSchema.parse({}).limit).toBe(500);
|
|
72
|
+
expect(datasetListInputSchema.safeParse({ limit: 1_001 }).success).toBe(
|
|
73
|
+
false,
|
|
74
|
+
);
|
|
75
|
+
expect(datasetListInputSchema.safeParse({ limit: 0 }).success).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("kind is an open kebab-case string", () => {
|
|
79
|
+
const page = (kind: string) =>
|
|
80
|
+
datasetPageSchema.safeParse({
|
|
81
|
+
items: [{ ref: { name: "x" }, kind }],
|
|
82
|
+
}).success;
|
|
83
|
+
expect(page("table")).toBe(true);
|
|
84
|
+
expect(page("materialized-view")).toBe(true);
|
|
85
|
+
expect(page("topic")).toBe(true);
|
|
86
|
+
expect(page("Table")).toBe(false);
|
|
87
|
+
expect(page("")).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("an observation needs a time but no particular measure", () => {
|
|
91
|
+
const ref = { name: "x" };
|
|
92
|
+
expect(
|
|
93
|
+
datasetObservationSchema.safeParse({
|
|
94
|
+
ref,
|
|
95
|
+
at: "2026-11-19T10:00:00Z",
|
|
96
|
+
}).success,
|
|
97
|
+
).toBe(true);
|
|
98
|
+
expect(datasetObservationSchema.safeParse({ ref }).success).toBe(false);
|
|
99
|
+
expect(
|
|
100
|
+
datasetObservationSchema.safeParse({ ref, at: "yesterday" }).success,
|
|
101
|
+
).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("measures cannot be negative or fractional", () => {
|
|
105
|
+
const base = { ref: { name: "x" }, at: "2026-11-19T10:00:00Z" };
|
|
106
|
+
for (const bad of [
|
|
107
|
+
{ rowCount: -1 },
|
|
108
|
+
{ rowCount: 1.5 },
|
|
109
|
+
{ bytes: -5 },
|
|
110
|
+
{ changeCounter: -1 },
|
|
111
|
+
])
|
|
112
|
+
expect(
|
|
113
|
+
datasetObservationSchema.safeParse({ ...base, ...bad }).success,
|
|
114
|
+
).toBe(false);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("observe is bounded in both directions", () => {
|
|
118
|
+
const refs = (count: number) =>
|
|
119
|
+
Array.from({ length: count }, (_, index) => ({ name: `t${index}` }));
|
|
120
|
+
expect(datasetObserveInputSchema.safeParse({ refs: [] }).success).toBe(
|
|
121
|
+
false,
|
|
122
|
+
);
|
|
123
|
+
expect(
|
|
124
|
+
datasetObserveInputSchema.safeParse({
|
|
125
|
+
refs: refs(DATASET_OBSERVE_MAX_REFS),
|
|
126
|
+
}).success,
|
|
127
|
+
).toBe(true);
|
|
128
|
+
expect(
|
|
129
|
+
datasetObserveInputSchema.safeParse({
|
|
130
|
+
refs: refs(DATASET_OBSERVE_MAX_REFS + 1),
|
|
131
|
+
}).success,
|
|
132
|
+
).toBe(false);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { InvalidDefinitionError } from "../shared/errors";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Upper bounds the host enforces on both sides of the adapter process
|
|
6
|
+
* boundary, so a misbehaving adapter cannot flood a plugin and a plugin
|
|
7
|
+
* cannot ask one adapter for an unbounded amount of work.
|
|
8
|
+
*/
|
|
9
|
+
export const DATASET_LIST_MAX_LIMIT = 1_000;
|
|
10
|
+
export const DATASET_OBSERVE_MAX_REFS = 500;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Names one dataset inside one service.
|
|
14
|
+
*
|
|
15
|
+
* `name` is whatever the system itself calls the thing: `analytics.public.orders`
|
|
16
|
+
* for a table, `landing/orders/` for an object prefix, `orders_daily` for an
|
|
17
|
+
* asset. It is unique within a service, which is all a monitor needs, because a
|
|
18
|
+
* monitor always belongs to one service.
|
|
19
|
+
*
|
|
20
|
+
* `namespace` is optional and unset by default. It exists so that identity
|
|
21
|
+
* across services (a dbt model, the table it builds and an orchestrator asset
|
|
22
|
+
* being the same dataset) can be added later without changing this type.
|
|
23
|
+
*/
|
|
24
|
+
export const datasetRefSchema = z.object({
|
|
25
|
+
namespace: z.string().min(1).max(512).optional(),
|
|
26
|
+
name: z.string().min(1).max(512),
|
|
27
|
+
});
|
|
28
|
+
export type DatasetRef = z.infer<typeof datasetRefSchema>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Open string, like a health check id: the host and the plugins never branch on
|
|
32
|
+
* it. Well-known values are `table`, `view`, `materialized-view`, `file-set`,
|
|
33
|
+
* `model` and `asset`; an adapter reporting `topic` needs no change anywhere.
|
|
34
|
+
*/
|
|
35
|
+
export const datasetKindSchema = z
|
|
36
|
+
.string()
|
|
37
|
+
.regex(/^[a-z][a-z0-9-]*$/, "Dataset kind must be kebab-case")
|
|
38
|
+
.max(64);
|
|
39
|
+
|
|
40
|
+
export const datasetColumnSchema = z.object({
|
|
41
|
+
name: z.string().min(1).max(512),
|
|
42
|
+
/** The type as the system spells it, for example `timestamp with time zone`. */
|
|
43
|
+
type: z.string().max(256).optional(),
|
|
44
|
+
nullable: z.boolean().optional(),
|
|
45
|
+
});
|
|
46
|
+
export type DatasetColumn = z.infer<typeof datasetColumnSchema>;
|
|
47
|
+
|
|
48
|
+
export const datasetInfoSchema = z.object({
|
|
49
|
+
ref: datasetRefSchema,
|
|
50
|
+
kind: datasetKindSchema,
|
|
51
|
+
title: z.string().max(512).optional(),
|
|
52
|
+
columns: z.array(datasetColumnSchema).max(5_000).optional(),
|
|
53
|
+
});
|
|
54
|
+
export type DatasetInfo = z.infer<typeof datasetInfoSchema>;
|
|
55
|
+
|
|
56
|
+
export const datasetListInputSchema = z.object({
|
|
57
|
+
cursor: z.string().max(2_048).optional(),
|
|
58
|
+
limit: z.number().int().min(1).max(DATASET_LIST_MAX_LIMIT).default(500),
|
|
59
|
+
});
|
|
60
|
+
export type DatasetListInput = z.input<typeof datasetListInputSchema>;
|
|
61
|
+
|
|
62
|
+
export const datasetPageSchema = z.object({
|
|
63
|
+
items: z.array(datasetInfoSchema).max(DATASET_LIST_MAX_LIMIT),
|
|
64
|
+
nextCursor: z.string().max(2_048).optional(),
|
|
65
|
+
});
|
|
66
|
+
export type DatasetPage = z.infer<typeof datasetPageSchema>;
|
|
67
|
+
|
|
68
|
+
const isoTime = z.string().datetime({ offset: true });
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* One measurement of a dataset. Every measure is optional, because systems
|
|
72
|
+
* differ in what they can tell cheaply: a plugin must treat an absent measure
|
|
73
|
+
* as "not reported", never as zero.
|
|
74
|
+
*/
|
|
75
|
+
export const datasetObservationSchema = z.object({
|
|
76
|
+
ref: datasetRefSchema,
|
|
77
|
+
/** When the adapter took the measurement. */
|
|
78
|
+
at: isoTime,
|
|
79
|
+
rowCount: z.number().int().min(0).optional(),
|
|
80
|
+
/** False when `rowCount` is a statistic or an estimate rather than a count. */
|
|
81
|
+
rowCountExact: z.boolean().optional(),
|
|
82
|
+
bytes: z.number().int().min(0).optional(),
|
|
83
|
+
/** When the data last changed, for systems that record it. */
|
|
84
|
+
lastModifiedAt: isoTime.optional(),
|
|
85
|
+
/**
|
|
86
|
+
* A value that never decreases and grows with every write, for systems that
|
|
87
|
+
* record no modification time. A consumer derives "changed since the last
|
|
88
|
+
* look" from it; the number itself means nothing.
|
|
89
|
+
*/
|
|
90
|
+
changeCounter: z.number().int().min(0).optional(),
|
|
91
|
+
columns: z.array(datasetColumnSchema).max(5_000).optional(),
|
|
92
|
+
});
|
|
93
|
+
export type DatasetObservation = z.infer<typeof datasetObservationSchema>;
|
|
94
|
+
|
|
95
|
+
export const datasetObserveInputSchema = z.object({
|
|
96
|
+
refs: z.array(datasetRefSchema).min(1).max(DATASET_OBSERVE_MAX_REFS),
|
|
97
|
+
});
|
|
98
|
+
export type DatasetObserveInput = z.infer<typeof datasetObserveInputSchema>;
|
|
99
|
+
|
|
100
|
+
export const datasetObservationsSchema = z
|
|
101
|
+
.array(datasetObservationSchema)
|
|
102
|
+
.max(DATASET_OBSERVE_MAX_REFS);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* What an adapter offers when it can describe the data it holds.
|
|
106
|
+
*
|
|
107
|
+
* Both reads are cheap by contract: `list` and `observe` answer from the
|
|
108
|
+
* system's own catalog or statistics and must not scan the data. A system that
|
|
109
|
+
* cannot do that for a dataset reports the measures it can and omits the rest.
|
|
110
|
+
* Neither may change anything in the connected system.
|
|
111
|
+
*/
|
|
112
|
+
export interface DatasetsCapability<TContext = unknown> {
|
|
113
|
+
/** Page through every dataset the connection can see. */
|
|
114
|
+
list(
|
|
115
|
+
input: { cursor?: string; limit: number },
|
|
116
|
+
ctx: TContext,
|
|
117
|
+
): Promise<DatasetPage> | DatasetPage;
|
|
118
|
+
/**
|
|
119
|
+
* Measure the given datasets in one call. A dataset that no longer exists is
|
|
120
|
+
* left out of the result rather than failing the call.
|
|
121
|
+
*/
|
|
122
|
+
observe(
|
|
123
|
+
refs: readonly DatasetRef[],
|
|
124
|
+
ctx: TContext,
|
|
125
|
+
): Promise<readonly DatasetObservation[]> | readonly DatasetObservation[];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Declares the dataset capability; a typed identity function like `defineSignal`. */
|
|
129
|
+
export function defineDatasets<TContext = unknown>(
|
|
130
|
+
capability: DatasetsCapability<TContext>,
|
|
131
|
+
): DatasetsCapability<TContext> {
|
|
132
|
+
if (
|
|
133
|
+
!capability ||
|
|
134
|
+
typeof capability.list !== "function" ||
|
|
135
|
+
typeof capability.observe !== "function"
|
|
136
|
+
)
|
|
137
|
+
throw new InvalidDefinitionError(
|
|
138
|
+
"Datasets capability requires list and observe functions",
|
|
139
|
+
);
|
|
140
|
+
return capability;
|
|
141
|
+
}
|
|
@@ -28,6 +28,7 @@ export {
|
|
|
28
28
|
type AdapterHealthReport,
|
|
29
29
|
type AdapterHealthRuntime,
|
|
30
30
|
type AdapterInfo,
|
|
31
|
+
type AdapterPresentation,
|
|
31
32
|
type ConnectionMethodDefinition,
|
|
32
33
|
type ConnectionRequestConcurrency,
|
|
33
34
|
type DefineAdapterOptions,
|
|
@@ -200,6 +201,28 @@ export type {
|
|
|
200
201
|
export { CodeExplorer } from "./components/primitives/code-explorer";
|
|
201
202
|
export type { ComponentClient, ComponentProps } from "./components/runtime";
|
|
202
203
|
export { componentProps } from "./components/runtime";
|
|
204
|
+
export {
|
|
205
|
+
DATASET_LIST_MAX_LIMIT,
|
|
206
|
+
DATASET_OBSERVE_MAX_REFS,
|
|
207
|
+
type DatasetColumn,
|
|
208
|
+
type DatasetInfo,
|
|
209
|
+
type DatasetListInput,
|
|
210
|
+
type DatasetObservation,
|
|
211
|
+
type DatasetObserveInput,
|
|
212
|
+
type DatasetPage,
|
|
213
|
+
type DatasetRef,
|
|
214
|
+
type DatasetsCapability,
|
|
215
|
+
datasetColumnSchema,
|
|
216
|
+
datasetInfoSchema,
|
|
217
|
+
datasetKindSchema,
|
|
218
|
+
datasetListInputSchema,
|
|
219
|
+
datasetObservationSchema,
|
|
220
|
+
datasetObservationsSchema,
|
|
221
|
+
datasetObserveInputSchema,
|
|
222
|
+
datasetPageSchema,
|
|
223
|
+
datasetRefSchema,
|
|
224
|
+
defineDatasets,
|
|
225
|
+
} from "./dataset/index";
|
|
203
226
|
export {
|
|
204
227
|
type AnyJobDefinition,
|
|
205
228
|
type DefineJobOptions,
|
|
@@ -27,7 +27,8 @@ function useVirtualizerBase({
|
|
|
27
27
|
directDomUpdatesMode = "transform",
|
|
28
28
|
...options
|
|
29
29
|
}) {
|
|
30
|
-
const
|
|
30
|
+
const [, dispatch] = React__namespace.useReducer((x) => x + 1, 0);
|
|
31
|
+
const rerender = React__namespace.useRef(dispatch).current;
|
|
31
32
|
const directRef = React__namespace.useRef({
|
|
32
33
|
enabled: directDomUpdates,
|
|
33
34
|
mode: directDomUpdatesMode,
|
|
@@ -156,7 +157,7 @@ function useWindowVirtualizer(options) {
|
|
|
156
157
|
observeElementRect: virtualCore.observeWindowRect,
|
|
157
158
|
observeElementOffset: virtualCore.observeWindowOffset,
|
|
158
159
|
scrollToFn: virtualCore.windowScroll,
|
|
159
|
-
initialOffset: () => typeof document !== "undefined" ? window.scrollY : 0,
|
|
160
|
+
initialOffset: () => typeof document !== "undefined" ? options.horizontal ? window.scrollX : window.scrollY : 0,
|
|
160
161
|
...options
|
|
161
162
|
});
|
|
162
163
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nimport { flushSync } from 'react-dom'\nimport {\n Virtualizer,\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport type {\n PartialKeys,\n VirtualItem,\n VirtualizerOptions,\n} from '@tanstack/virtual-core'\n\nexport * from '@tanstack/virtual-core'\n\nconst useIsomorphicLayoutEffect =\n typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nexport type ReactVirtualizer<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n> = Virtualizer<TScrollElement, TItemElement> & {\n /**\n * Ref callback for the inner size container element. Only meaningful when\n * `directDomUpdates: true` — the virtualizer writes the container's\n * main-axis size (`height` or `width`) directly to skip React re-renders.\n */\n containerRef: (node: HTMLElement | null) => void\n}\n\nexport type ReactVirtualizerOptions<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n> = VirtualizerOptions<TScrollElement, TItemElement> & {\n useFlushSync?: boolean\n /**\n * Skip React re-renders for scroll-only updates. The virtualizer writes\n * item positions (`top`/`left`) and the container size (`height`/`width`)\n * directly to the DOM, and only re-renders when the visible index range\n * or `isScrolling` changes.\n *\n * Requirements when enabled:\n * - Item elements must be `position: absolute`; in `'transform'` mode they\n * must also be anchored with `top: 0` / `left: 0`.\n * - Item elements must NOT set the main-axis position in their style — the\n * virtualizer owns `top` / `left` in `'position'` mode and `transform` in\n * `'transform'` mode.\n * - The inner size container must receive `virtualizer.containerRef` and\n * must NOT set `height` / `width` in its style.\n * - For multi-lane layouts (grids / masonry), the cross-axis position\n * (e.g. `left: ${(item.lane * 100) / lanes}%`) is stable per item and\n * must still be set in your JSX — only the main axis is automated.\n *\n * This flag is intended to be set once at mount. Toggling it (or\n * `directDomUpdatesMode`) at runtime can leave stale inline styles on\n * items and the container.\n */\n directDomUpdates?: boolean\n /**\n * How `directDomUpdates` positions item elements.\n * - `'transform'` (default): writes `transform: translate3d(...)`.\n * Promotes items to their own compositor layer — usually smoother on long\n * lists, but creates a stacking context and can interfere with\n * `position: fixed` descendants. Item elements must still be anchored with\n * `position: absolute`, `top: 0`, and `left: 0`.\n * - `'position'`: writes `top` / `left`. Item elements must be\n * `position: absolute`.\n */\n directDomUpdatesMode?: 'position' | 'transform'\n}\n\nfunction useVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>({\n useFlushSync = true,\n directDomUpdates = false,\n directDomUpdatesMode = 'transform',\n ...options\n}: ReactVirtualizerOptions<TScrollElement, TItemElement>): ReactVirtualizer<\n TScrollElement,\n TItemElement\n> {\n const rerender = React.useReducer((x: number) => x + 1, 0)[1]\n\n // Mutable across renders so the onChange closure captured by setOptions\n // always reads the latest values without us having to re-create it.\n const directRef = React.useRef({\n enabled: directDomUpdates,\n mode: directDomUpdatesMode,\n container: null as HTMLElement | null,\n lastSize: null as number | null,\n // Keyed by the element itself so a remounted node (same key, new DOM\n // node — e.g. when `enabled` is toggled off then on) is treated as fresh\n // and gets its style written.\n lastPositions: new WeakMap<HTMLElement, number>(),\n prevRange: null as {\n startIndex: number\n endIndex: number\n isScrolling: boolean\n } | null,\n })\n directRef.current.enabled = directDomUpdates\n directRef.current.mode = directDomUpdatesMode\n\n // Set while the virtualizer measures an item through `measureElement`, which is\n // passed as a ref and therefore runs while React is committing.\n const measuringFromRef = React.useRef(false)\n\n // Writes the size container's total extent to the DOM. Idempotent — guarded\n // by lastSize. Split out from applyDirectStyles so it can run *before* the\n // scroll-position sync in the _willUpdate effect: an end-anchored prepend\n // grows the total and bumps scrollOffset in the same pass, and if scrollTop\n // is written before the container has grown the browser clamps it to the\n // stale (shorter) scrollHeight, leaving a gap at the top until the next\n // scroll (visible only in directDomUpdates mode — React-rendered sizers get\n // their height during render).\n const applyContainerSize = (\n instance: Virtualizer<TScrollElement, TItemElement>,\n ) => {\n const state = directRef.current\n if (!state.enabled || !state.container) return\n\n const totalSize = instance.getTotalSize()\n if (totalSize !== state.lastSize) {\n state.lastSize = totalSize\n const sizeAxis = instance.options.horizontal ? 'width' : 'height'\n state.container.style[sizeAxis] = `${totalSize}px`\n }\n }\n\n // Writes one item's main-axis position to its element. Idempotent — guarded\n // by lastPositions.\n const applyItemPosition = (\n instance: Virtualizer<TScrollElement, TItemElement>,\n item: VirtualItem,\n el: HTMLElement,\n ) => {\n const state = directRef.current\n const horizontal = !!instance.options.horizontal\n const next = item.start - instance.options.scrollMargin\n if (state.lastPositions.get(el) === next) return\n state.lastPositions.set(el, next)\n if (state.mode === 'transform') {\n el.style.transform = horizontal\n ? `translate3d(${next}px, 0, 0)`\n : `translate3d(0, ${next}px, 0)`\n } else {\n el.style[horizontal ? 'left' : 'top'] = `${next}px`\n }\n }\n\n // Writes container size + item positions to the DOM. Idempotent — guarded\n // by lastSize / lastPositions. Called from onChange (covers scroll-driven\n // updates) and from a layout effect (covers post-render commits when refs\n // have just registered new items in elementsCache).\n const applyDirectStyles = (\n instance: Virtualizer<TScrollElement, TItemElement>,\n ) => {\n const state = directRef.current\n if (!state.enabled || !state.container) return\n\n applyContainerSize(instance)\n\n for (const item of instance.getVirtualItems()) {\n const el = instance.elementsCache.get(item.key) as HTMLElement | undefined\n if (el) applyItemPosition(instance, item, el)\n }\n }\n\n const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = {\n ...options,\n onChange: (instance, sync) => {\n const state = directRef.current\n let shouldRerender = true\n\n if (state.enabled) {\n applyDirectStyles(instance)\n\n // Only re-render on range / isScrolling changes\n const range = instance.range\n const prev = state.prevRange\n shouldRerender =\n !prev ||\n prev.isScrolling !== instance.isScrolling ||\n prev.startIndex !== range?.startIndex ||\n prev.endIndex !== range?.endIndex\n if (shouldRerender) {\n state.prevRange = range\n ? {\n startIndex: range.startIndex,\n endIndex: range.endIndex,\n isScrolling: instance.isScrolling,\n }\n : null\n }\n }\n\n if (shouldRerender) {\n // A sync notify raised from `measureElement` reaches us while React is\n // committing, because `measureElement` is a ref callback. `flushSync`\n // cannot flush there: React still runs the callback at sync priority, but\n // it skips the flush and warns in development. The commit phase already\n // runs at discrete (sync) priority, so leaving `flushSync` out for that\n // window keeps the same lane and the same flush point — without the\n // warning. Every other sync notify (ResizeObserver re-measures, scroll\n // adjustments) still flushes synchronously.\n if (useFlushSync && sync && !measuringFromRef.current) {\n flushSync(rerender)\n } else {\n rerender()\n }\n }\n\n options.onChange?.(instance, sync)\n },\n }\n\n const [instance] = React.useState(() => {\n const v = new Virtualizer<TScrollElement, TItemElement>(resolvedOptions)\n const measureElement = v.measureElement\n v.measureElement = (node: TItemElement | null) => {\n measuringFromRef.current = true\n try {\n measureElement(node)\n } finally {\n measuringFromRef.current = false\n }\n // A row can mount in a commit that does not include this component — a\n // child re-rendering on its own state, context or a resolved Suspense\n // boundary — which the `applyDirectStyles` effect below never sees.\n // Position it as it registers; a row the effect does cover is skipped by\n // `lastPositions`.\n const state = directRef.current\n if (node !== null && state.enabled && state.container) {\n const item = v.measurementsCache[v.indexFromElement(node)]\n if (item) applyItemPosition(v, item, node as unknown as HTMLElement)\n }\n }\n return Object.assign(v, {\n containerRef: (node: HTMLElement | null) => {\n const state = directRef.current\n state.container = node\n state.lastSize = null\n // Sizes the container, and positions the rows that mounted with it:\n // React attaches children's refs before their parent's, so they have\n // already registered but found no container to be positioned in.\n if (node !== null) {\n applyDirectStyles(v)\n }\n },\n })\n })\n\n instance.setOptions(resolvedOptions)\n\n useIsomorphicLayoutEffect(() => {\n return instance._didMount()\n }, [])\n\n useIsomorphicLayoutEffect(() => {\n // Grow the size container to the new total BEFORE _willUpdate syncs the\n // scroll position. On an end-anchored prepend the scroll target lands at\n // the new bottom; if the container is still at its old (shorter) height the\n // browser clamps the scrollTop write and the list is left with a gap at the\n // top until the next scroll. Positions are written afterwards by the\n // applyDirectStyles effect below.\n applyContainerSize(instance)\n return instance._willUpdate()\n })\n\n // After every render commit, newly mounted item refs have registered in\n // elementsCache; write their positions to the DOM so the user doesn't see\n // them at (0, 0) until the next onChange.\n useIsomorphicLayoutEffect(() => {\n applyDirectStyles(instance)\n })\n\n return instance\n}\n\nexport function useVirtualizer<\n TScrollElement extends Element,\n TItemElement extends Element,\n>(\n options: PartialKeys<\n ReactVirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >,\n): ReactVirtualizer<TScrollElement, TItemElement> {\n return useVirtualizerBase<TScrollElement, TItemElement>({\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...options,\n })\n}\n\nexport function useWindowVirtualizer<TItemElement extends Element>(\n options: PartialKeys<\n ReactVirtualizerOptions<Window, TItemElement>,\n | 'getScrollElement'\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n >,\n): ReactVirtualizer<Window, TItemElement> {\n return useVirtualizerBase<Window, TItemElement>({\n getScrollElement: () => (typeof document !== 'undefined' ? window : null),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n initialOffset: () => (typeof document !== 'undefined' ? window.scrollY : 0),\n ...options,\n })\n}\n"],"names":["React","instance","flushSync","Virtualizer","observeElementRect","observeElementOffset","elementScroll","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAM,4BACJ,OAAO,aAAa,cAAcA,iBAAM,kBAAkBA,iBAAM;AAuDlE,SAAS,mBAGP;AAAA,EACA,eAAe;AAAA,EACf,mBAAmB;AAAA,EACnB,uBAAuB;AAAA,E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AC;AACzD,YAAI,KAAM,mBAAkB,GAAG,MAAM,IAA8B;AAAA,MACrE;AAAA,IACF;AACA,WAAO,OAAO,OAAO,GAAG;AAAA,MACtB,cAAc,CAAC,SAA6B;AAC1C,cAAM,QAAQ,UAAU;AACxB,cAAM,YAAY;AAClB,cAAM,WAAW;AAIjB,YAAI,SAAS,MAAM;AACjB,4BAAkB,CAAC;AAAA,QACrB;AAAA,MACF;AAAA,IAAA,CACD;AAAA,EACH,CAAC;AAED,WAAS,WAAW,eAAe;AAEnC,4BAA0B,MAAM;AAC9B,WAAO,SAAS,UAAA;AAAA,EAClB,GAAG,CAAA,CAAE;AAEL,4BAA0B,MAAM;AAO9B,uBAAmB,QAAQ;AAC3B,WAAO,SAAS,YAAA;AAAA,EAClB,CAAC;AAKD,4BAA0B,MAAM;AAC9B,sBAAkB,QAAQ;AAAA,EAC5B,CAAC;AAED,SAAO;AACT;AAEO,SAAS,eAId,SAIgD;AAChD,SAAO,mBAAiD;AAAA,IAAA,oBACtDC,YAAAA;AAAAA,IAAA,sBACAC,YAAAA;AAAAA,IACA,YAAYC,YAAAA;AAAAA,IACZ,GAAG;AAAA,EAAA,CACJ;AACH;AAEO,SAAS,qBACd,SAOwC;AACxC,SAAO,mBAAyC;AAAA,IAC9C,kBAAkB,MAAO,OAAO,aAAa,cAAc,SAAS;AAAA,IACpE,oBAAoBC,YAAAA;AAAAA,IACpB,sBAAsBC,YAAAA;AAAAA,IACtB,YAAYC,YAAAA;AAAAA,IACZ,eAAe,MAAO,OAAO,aAAa,cAAc,OAAO,UAAU;AAAA,IACzE,GAAG;AAAA,EAAA,CACJ;AACH;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nimport { flushSync } from 'react-dom'\nimport {\n Virtualizer,\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport type {\n PartialKeys,\n VirtualItem,\n VirtualizerOptions,\n} from '@tanstack/virtual-core'\n\nexport * from '@tanstack/virtual-core'\n\nconst useIsomorphicLayoutEffect =\n typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect\n\nexport type ReactVirtualizer<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n> = Virtualizer<TScrollElement, TItemElement> & {\n /**\n * Ref callback for the inner size container element. Only meaningful when\n * `directDomUpdates: true` — the virtualizer writes the container's\n * main-axis size (`height` or `width`) directly to skip React re-renders.\n */\n containerRef: (node: HTMLElement | null) => void\n}\n\nexport type ReactVirtualizerOptions<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n> = VirtualizerOptions<TScrollElement, TItemElement> & {\n useFlushSync?: boolean\n /**\n * Skip React re-renders for scroll-only updates. The virtualizer writes\n * item positions (`top`/`left`) and the container size (`height`/`width`)\n * directly to the DOM, and only re-renders when the visible index range\n * or `isScrolling` changes.\n *\n * Requirements when enabled:\n * - Item elements must be `position: absolute`; in `'transform'` mode they\n * must also be anchored with `top: 0` / `left: 0`.\n * - Item elements must NOT set the main-axis position in their style — the\n * virtualizer owns `top` / `left` in `'position'` mode and `transform` in\n * `'transform'` mode.\n * - The inner size container must receive `virtualizer.containerRef` and\n * must NOT set `height` / `width` in its style.\n * - For multi-lane layouts (grids / masonry), the cross-axis position\n * (e.g. `left: ${(item.lane * 100) / lanes}%`) is stable per item and\n * must still be set in your JSX — only the main axis is automated.\n *\n * This flag is intended to be set once at mount. Toggling it (or\n * `directDomUpdatesMode`) at runtime can leave stale inline styles on\n * items and the container.\n */\n directDomUpdates?: boolean\n /**\n * How `directDomUpdates` positions item elements.\n * - `'transform'` (default): writes `transform: translate3d(...)`.\n * Promotes items to their own compositor layer — usually smoother on long\n * lists, but creates a stacking context and can interfere with\n * `position: fixed` descendants. Item elements must still be anchored with\n * `position: absolute`, `top: 0`, and `left: 0`.\n * - `'position'`: writes `top` / `left`. Item elements must be\n * `position: absolute`.\n */\n directDomUpdatesMode?: 'position' | 'transform'\n}\n\nfunction useVirtualizerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n>({\n useFlushSync = true,\n directDomUpdates = false,\n directDomUpdatesMode = 'transform',\n ...options\n}: ReactVirtualizerOptions<TScrollElement, TItemElement>): ReactVirtualizer<\n TScrollElement,\n TItemElement\n> {\n const [, dispatch] = React.useReducer((x: number) => x + 1, 0)\n // React DevTools replays hooks with a no-op dispatch while inspecting them.\n // Keep the original dispatch so that setOptions below cannot replace the\n // virtualizer's render callback with the inspector's no-op.\n const rerender = React.useRef(dispatch).current\n\n // Mutable across renders so the onChange closure captured by setOptions\n // always reads the latest values without us having to re-create it.\n const directRef = React.useRef({\n enabled: directDomUpdates,\n mode: directDomUpdatesMode,\n container: null as HTMLElement | null,\n lastSize: null as number | null,\n // Keyed by the element itself so a remounted node (same key, new DOM\n // node — e.g. when `enabled` is toggled off then on) is treated as fresh\n // and gets its style written.\n lastPositions: new WeakMap<HTMLElement, number>(),\n prevRange: null as {\n startIndex: number\n endIndex: number\n isScrolling: boolean\n } | null,\n })\n directRef.current.enabled = directDomUpdates\n directRef.current.mode = directDomUpdatesMode\n\n // Set while the virtualizer measures an item through `measureElement`, which is\n // passed as a ref and therefore runs while React is committing.\n const measuringFromRef = React.useRef(false)\n\n // Writes the size container's total extent to the DOM. Idempotent — guarded\n // by lastSize. Split out from applyDirectStyles so it can run *before* the\n // scroll-position sync in the _willUpdate effect: an end-anchored prepend\n // grows the total and bumps scrollOffset in the same pass, and if scrollTop\n // is written before the container has grown the browser clamps it to the\n // stale (shorter) scrollHeight, leaving a gap at the top until the next\n // scroll (visible only in directDomUpdates mode — React-rendered sizers get\n // their height during render).\n const applyContainerSize = (\n instance: Virtualizer<TScrollElement, TItemElement>,\n ) => {\n const state = directRef.current\n if (!state.enabled || !state.container) return\n\n const totalSize = instance.getTotalSize()\n if (totalSize !== state.lastSize) {\n state.lastSize = totalSize\n const sizeAxis = instance.options.horizontal ? 'width' : 'height'\n state.container.style[sizeAxis] = `${totalSize}px`\n }\n }\n\n // Writes one item's main-axis position to its element. Idempotent — guarded\n // by lastPositions.\n const applyItemPosition = (\n instance: Virtualizer<TScrollElement, TItemElement>,\n item: VirtualItem,\n el: HTMLElement,\n ) => {\n const state = directRef.current\n const horizontal = !!instance.options.horizontal\n const next = item.start - instance.options.scrollMargin\n if (state.lastPositions.get(el) === next) return\n state.lastPositions.set(el, next)\n if (state.mode === 'transform') {\n el.style.transform = horizontal\n ? `translate3d(${next}px, 0, 0)`\n : `translate3d(0, ${next}px, 0)`\n } else {\n el.style[horizontal ? 'left' : 'top'] = `${next}px`\n }\n }\n\n // Writes container size + item positions to the DOM. Idempotent — guarded\n // by lastSize / lastPositions. Called from onChange (covers scroll-driven\n // updates) and from a layout effect (covers post-render commits when refs\n // have just registered new items in elementsCache).\n const applyDirectStyles = (\n instance: Virtualizer<TScrollElement, TItemElement>,\n ) => {\n const state = directRef.current\n if (!state.enabled || !state.container) return\n\n applyContainerSize(instance)\n\n for (const item of instance.getVirtualItems()) {\n const el = instance.elementsCache.get(item.key) as HTMLElement | undefined\n if (el) applyItemPosition(instance, item, el)\n }\n }\n\n const resolvedOptions: VirtualizerOptions<TScrollElement, TItemElement> = {\n ...options,\n onChange: (instance, sync) => {\n const state = directRef.current\n let shouldRerender = true\n\n if (state.enabled) {\n applyDirectStyles(instance)\n\n // Only re-render on range / isScrolling changes\n const range = instance.range\n const prev = state.prevRange\n shouldRerender =\n !prev ||\n prev.isScrolling !== instance.isScrolling ||\n prev.startIndex !== range?.startIndex ||\n prev.endIndex !== range?.endIndex\n if (shouldRerender) {\n state.prevRange = range\n ? {\n startIndex: range.startIndex,\n endIndex: range.endIndex,\n isScrolling: instance.isScrolling,\n }\n : null\n }\n }\n\n if (shouldRerender) {\n // A sync notify raised from `measureElement` reaches us while React is\n // committing, because `measureElement` is a ref callback. `flushSync`\n // cannot flush there: React still runs the callback at sync priority, but\n // it skips the flush and warns in development. The commit phase already\n // runs at discrete (sync) priority, so leaving `flushSync` out for that\n // window keeps the same lane and the same flush point — without the\n // warning. Every other sync notify (ResizeObserver re-measures, scroll\n // adjustments) still flushes synchronously.\n if (useFlushSync && sync && !measuringFromRef.current) {\n flushSync(rerender)\n } else {\n rerender()\n }\n }\n\n options.onChange?.(instance, sync)\n },\n }\n\n const [instance] = React.useState(() => {\n const v = new Virtualizer<TScrollElement, TItemElement>(resolvedOptions)\n const measureElement = v.measureElement\n v.measureElement = (node: TItemElement | null) => {\n measuringFromRef.current = true\n try {\n measureElement(node)\n } finally {\n measuringFromRef.current = false\n }\n // A row can mount in a commit that does not include this component — a\n // child re-rendering on its own state, context or a resolved Suspense\n // boundary — which the `applyDirectStyles` effect below never sees.\n // Position it as it registers; a row the effect does cover is skipped by\n // `lastPositions`.\n const state = directRef.current\n if (node !== null && state.enabled && state.container) {\n const item = v.measurementsCache[v.indexFromElement(node)]\n if (item) applyItemPosition(v, item, node as unknown as HTMLElement)\n }\n }\n return Object.assign(v, {\n containerRef: (node: HTMLElement | null) => {\n const state = directRef.current\n state.container = node\n state.lastSize = null\n // Sizes the container, and positions the rows that mounted with it:\n // React attaches children's refs before their parent's, so they have\n // already registered but found no container to be positioned in.\n if (node !== null) {\n applyDirectStyles(v)\n }\n },\n })\n })\n\n instance.setOptions(resolvedOptions)\n\n useIsomorphicLayoutEffect(() => {\n return instance._didMount()\n }, [])\n\n useIsomorphicLayoutEffect(() => {\n // Grow the size container to the new total BEFORE _willUpdate syncs the\n // scroll position. On an end-anchored prepend the scroll target lands at\n // the new bottom; if the container is still at its old (shorter) height the\n // browser clamps the scrollTop write and the list is left with a gap at the\n // top until the next scroll. Positions are written afterwards by the\n // applyDirectStyles effect below.\n applyContainerSize(instance)\n return instance._willUpdate()\n })\n\n // After every render commit, newly mounted item refs have registered in\n // elementsCache; write their positions to the DOM so the user doesn't see\n // them at (0, 0) until the next onChange.\n useIsomorphicLayoutEffect(() => {\n applyDirectStyles(instance)\n })\n\n return instance\n}\n\nexport function useVirtualizer<\n TScrollElement extends Element,\n TItemElement extends Element,\n>(\n options: PartialKeys<\n ReactVirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >,\n): ReactVirtualizer<TScrollElement, TItemElement> {\n return useVirtualizerBase<TScrollElement, TItemElement>({\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...options,\n })\n}\n\nexport function useWindowVirtualizer<TItemElement extends Element>(\n options: PartialKeys<\n ReactVirtualizerOptions<Window, TItemElement>,\n | 'getScrollElement'\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n >,\n): ReactVirtualizer<Window, TItemElement> {\n return useVirtualizerBase<Window, TItemElement>({\n getScrollElement: () => (typeof document !== 'undefined' ? window : null),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n initialOffset: () =>\n typeof document !== 'undefined'\n ? options.horizontal\n ? window.scrollX\n : window.scrollY\n : 0,\n ...options,\n })\n}\n"],"names":["React","instance","flushSync","Virtualizer","observeElementRect","observeElementOffset","elementScroll","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAM,4BACJ,OAAO,aAAa,cAAcA,iBAAM,kBAAkBA,iBAAM;AAuDlE,SAAS,mBAGP;AAAA,EACA,eAAe;AAAA,EACf,mBAAmB;AAAA,EACnB,uBAAuB;AAAA,EACvB,GAAG;AACL,GAGE;AACA,QAAM,CAAA,EAAG,QAAQ,IAAIA,iBAAM,WAAW,CAAC,MAAc,IAAI,GAAG,CAAC;AAI7D,QAAM,WAAWA,iBAAM,OAAO,QAAQ,EAAE;AAIxC,QAAM,YAAYA,iBAAM,OAAO;AAAA,IAC7B,SAAS;AAAA,IACT,MAAM;AAAA,IACN,WAAW;AAAA,IACX,UAAU;AAAA;AAAA;AAAA;AAAA,IAIV,mCAAmB,QAAA;AAAA,IACnB,WA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,MACF;AAAA,IAAA,CACD;AAAA,EACH,CAAC;AAED,WAAS,WAAW,eAAe;AAEnC,4BAA0B,MAAM;AAC9B,WAAO,SAAS,UAAA;AAAA,EAClB,GAAG,CAAA,CAAE;AAEL,4BAA0B,MAAM;AAO9B,uBAAmB,QAAQ;AAC3B,WAAO,SAAS,YAAA;AAAA,EAClB,CAAC;AAKD,4BAA0B,MAAM;AAC9B,sBAAkB,QAAQ;AAAA,EAC5B,CAAC;AAED,SAAO;AACT;AAEO,SAAS,eAId,SAIgD;AAChD,SAAO,mBAAiD;AAAA,IAAA,oBACtDC,YAAAA;AAAAA,IAAA,sBACAC,YAAAA;AAAAA,IACA,YAAYC,YAAAA;AAAAA,IACZ,GAAG;AAAA,EAAA,CACJ;AACH;AAEO,SAAS,qBACd,SAOwC;AACxC,SAAO,mBAAyC;AAAA,IAC9C,kBAAkB,MAAO,OAAO,aAAa,cAAc,SAAS;AAAA,IACpE,oBAAoBC,YAAAA;AAAAA,IACpB,sBAAsBC,YAAAA;AAAAA,IACtB,YAAYC,YAAAA;AAAAA,IACZ,eAAe,MACb,OAAO,aAAa,cAChB,QAAQ,aACN,OAAO,UACP,OAAO,UACT;AAAA,IACN,GAAG;AAAA,EAAA,CACJ;AACH;;;;;;;;;"}
|
|
@@ -9,7 +9,8 @@ function useVirtualizerBase({
|
|
|
9
9
|
directDomUpdatesMode = "transform",
|
|
10
10
|
...options
|
|
11
11
|
}) {
|
|
12
|
-
const
|
|
12
|
+
const [, dispatch] = React.useReducer((x) => x + 1, 0);
|
|
13
|
+
const rerender = React.useRef(dispatch).current;
|
|
13
14
|
const directRef = React.useRef({
|
|
14
15
|
enabled: directDomUpdates,
|
|
15
16
|
mode: directDomUpdatesMode,
|
|
@@ -138,7 +139,7 @@ function useWindowVirtualizer(options) {
|
|
|
138
139
|
observeElementRect: observeWindowRect,
|
|
139
140
|
observeElementOffset: observeWindowOffset,
|
|
140
141
|
scrollToFn: windowScroll,
|
|
141
|
-
initialOffset: () => typeof document !== "undefined" ? window.scrollY : 0,
|
|
142
|
+
initialOffset: () => typeof document !== "undefined" ? options.horizontal ? window.scrollX : window.scrollY : 0,
|
|
142
143
|
...options
|
|
143
144
|
});
|
|
144
145
|
}
|