jazz-tools 0.20.0 → 0.20.2
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/.turbo/turbo-build.log +56 -56
- package/CHANGELOG.md +21 -0
- package/dist/{chunk-3CAPPS2F.js → chunk-Q5RNSSUM.js} +269 -95
- package/dist/chunk-Q5RNSSUM.js.map +1 -0
- package/dist/chunk-ZQWSQH6L.js +20 -0
- package/dist/index.js +2 -2
- package/dist/inspector/{chunk-MCTB5ZJC.js → chunk-6JPVMI3V.js} +302 -182
- package/dist/inspector/chunk-6JPVMI3V.js.map +1 -0
- package/dist/inspector/{custom-element-5YWVZBWA.js → custom-element-PWRX4VCA.js} +1337 -206
- package/dist/inspector/custom-element-PWRX4VCA.js.map +1 -0
- package/dist/inspector/in-app.d.ts +1 -0
- package/dist/inspector/in-app.d.ts.map +1 -1
- package/dist/inspector/index.d.ts +1 -0
- package/dist/inspector/index.d.ts.map +1 -1
- package/dist/inspector/index.js +1044 -17
- package/dist/inspector/index.js.map +1 -1
- package/dist/inspector/pages/home.d.ts +4 -1
- package/dist/inspector/pages/home.d.ts.map +1 -1
- package/dist/inspector/pages/performance/PerformancePage.d.ts +7 -0
- package/dist/inspector/pages/performance/PerformancePage.d.ts.map +1 -0
- package/dist/inspector/pages/performance/SubscriptionDetailPanel.d.ts +8 -0
- package/dist/inspector/pages/performance/SubscriptionDetailPanel.d.ts.map +1 -0
- package/dist/inspector/pages/performance/SubscriptionRow.d.ts +11 -0
- package/dist/inspector/pages/performance/SubscriptionRow.d.ts.map +1 -0
- package/dist/inspector/pages/performance/Timeline.d.ts +12 -0
- package/dist/inspector/pages/performance/Timeline.d.ts.map +1 -0
- package/dist/inspector/pages/performance/helpers.d.ts +5 -0
- package/dist/inspector/pages/performance/helpers.d.ts.map +1 -0
- package/dist/inspector/pages/performance/index.d.ts +3 -0
- package/dist/inspector/pages/performance/index.d.ts.map +1 -0
- package/dist/inspector/pages/performance/types.d.ts +13 -0
- package/dist/inspector/pages/performance/types.d.ts.map +1 -0
- package/dist/inspector/pages/performance/usePerformanceEntries.d.ts +3 -0
- package/dist/inspector/pages/performance/usePerformanceEntries.d.ts.map +1 -0
- package/dist/inspector/register-custom-element.js +3 -1
- package/dist/inspector/register-custom-element.js.map +1 -1
- package/dist/inspector/standalone.js +1 -1
- package/dist/inspector/tests/pages/performance/PerformancePage.test.d.ts +2 -0
- package/dist/inspector/tests/pages/performance/PerformancePage.test.d.ts.map +1 -0
- package/dist/inspector/tests/pages/performance/SubscriptionDetailPanel.test.d.ts +2 -0
- package/dist/inspector/tests/pages/performance/SubscriptionDetailPanel.test.d.ts.map +1 -0
- package/dist/inspector/tests/pages/performance/SubscriptionRow.test.d.ts +2 -0
- package/dist/inspector/tests/pages/performance/SubscriptionRow.test.d.ts.map +1 -0
- package/dist/inspector/tests/pages/performance/Timeline.test.d.ts +2 -0
- package/dist/inspector/tests/pages/performance/Timeline.test.d.ts.map +1 -0
- package/dist/inspector/tests/pages/performance/helpers.test.d.ts +2 -0
- package/dist/inspector/tests/pages/performance/helpers.test.d.ts.map +1 -0
- package/dist/inspector/viewer/delete-local-data.d.ts.map +1 -1
- package/dist/inspector/viewer/header.d.ts +4 -2
- package/dist/inspector/viewer/header.d.ts.map +1 -1
- package/dist/inspector/viewer/page-stack.d.ts +3 -1
- package/dist/inspector/viewer/page-stack.d.ts.map +1 -1
- package/dist/react-core/hooks.d.ts +2 -2
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +50 -18
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/subscription-provider.d.ts.map +1 -1
- package/dist/react-native-core/media/image.d.ts +1 -1
- package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
- package/dist/svelte/jazz.class.svelte.js +27 -22
- package/dist/testing.js +2 -2
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +1 -1
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts +3 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +3 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +6 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/tools/ssr.js +1 -1
- package/dist/tools/subscribe/SubscriptionCache.d.ts +2 -2
- package/dist/tools/subscribe/SubscriptionCache.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionScope.d.ts +19 -12
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/tools/subscribe/errorReporting.d.ts +6 -0
- package/dist/tools/subscribe/errorReporting.d.ts.map +1 -1
- package/dist/tools/subscribe/index.d.ts +4 -4
- package/dist/tools/subscribe/index.d.ts.map +1 -1
- package/dist/tools/subscribe/types.d.ts +48 -3
- package/dist/tools/subscribe/types.d.ts.map +1 -1
- package/dist/tools/subscribe/utils.d.ts +1 -1
- package/dist/tools/subscribe/utils.d.ts.map +1 -1
- package/dist/tools/tests/SubscriptionScope.performance.test.d.ts +2 -0
- package/dist/tools/tests/SubscriptionScope.performance.test.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/inspector/in-app.tsx +41 -3
- package/src/inspector/index.tsx +5 -1
- package/src/inspector/pages/home.tsx +26 -3
- package/src/inspector/pages/performance/PerformancePage.tsx +215 -0
- package/src/inspector/pages/performance/SubscriptionDetailPanel.tsx +182 -0
- package/src/inspector/pages/performance/SubscriptionRow.tsx +242 -0
- package/src/inspector/pages/performance/Timeline.tsx +513 -0
- package/src/inspector/pages/performance/helpers.ts +70 -0
- package/src/inspector/pages/performance/index.ts +2 -0
- package/src/inspector/pages/performance/types.ts +12 -0
- package/src/inspector/pages/performance/usePerformanceEntries.ts +53 -0
- package/src/inspector/register-custom-element.ts +3 -0
- package/src/inspector/tests/pages/performance/PerformancePage.test.tsx +83 -0
- package/src/inspector/tests/pages/performance/SubscriptionDetailPanel.test.tsx +68 -0
- package/src/inspector/tests/pages/performance/SubscriptionRow.test.tsx +93 -0
- package/src/inspector/tests/pages/performance/Timeline.test.tsx +57 -0
- package/src/inspector/tests/pages/performance/helpers.test.ts +91 -0
- package/src/inspector/viewer/delete-local-data.tsx +24 -5
- package/src/inspector/viewer/header.tsx +96 -17
- package/src/inspector/viewer/page-stack.tsx +22 -18
- package/src/react-core/hooks.ts +34 -4
- package/src/react-core/subscription-provider.tsx +17 -8
- package/src/svelte/jazz.class.svelte.ts +51 -33
- package/src/tools/coValues/coList.ts +73 -37
- package/src/tools/coValues/interfaces.ts +3 -0
- package/src/tools/exports.ts +1 -0
- package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +13 -0
- package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +0 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +5 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +5 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +5 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts +6 -2
- package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +6 -2
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +5 -2
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +9 -2
- package/src/tools/subscribe/SubscriptionCache.ts +6 -4
- package/src/tools/subscribe/SubscriptionScope.ts +141 -23
- package/src/tools/subscribe/errorReporting.ts +1 -1
- package/src/tools/subscribe/index.ts +1 -1
- package/src/tools/subscribe/types.ts +62 -9
- package/src/tools/subscribe/utils.ts +2 -2
- package/src/tools/tests/SubscriptionScope.performance.test.ts +149 -0
- package/src/tools/tests/coList.test.ts +262 -0
- package/src/tools/tests/schema.withPermissions.test.ts +27 -4
- package/dist/chunk-3CAPPS2F.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -10
- package/dist/inspector/chunk-MCTB5ZJC.js.map +0 -1
- package/dist/inspector/custom-element-5YWVZBWA.js.map +0 -1
- /package/dist/{chunk-PZ5AY32C.js.map → chunk-ZQWSQH6L.js.map} +0 -0
|
@@ -2,7 +2,7 @@ import { RawCoValue, Role } from "cojson";
|
|
|
2
2
|
import { CoValue, RefEncoded, RefsToResolve } from "../internal.js";
|
|
3
3
|
import { SubscriptionScope } from "./SubscriptionScope.js";
|
|
4
4
|
export declare function myRoleForRawValue(raw: RawCoValue): Role | undefined;
|
|
5
|
-
export declare function createCoValue<D extends CoValue>(ref: RefEncoded<
|
|
5
|
+
export declare function createCoValue<D extends CoValue>(ref: RefEncoded<CoValue>, raw: RawCoValue, subscriptionScope: SubscriptionScope<D>): {
|
|
6
6
|
type: "loaded";
|
|
7
7
|
value: D;
|
|
8
8
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/tools/subscribe/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtD,OAAO,EACL,OAAO,EACP,UAAU,EACV,aAAa,EAGd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,CAUnE;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,EAC7C,GAAG,EAAE,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/tools/subscribe/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtD,OAAO,EACL,OAAO,EACP,UAAU,EACV,aAAa,EAGd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,CAUnE;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,EAC7C,GAAG,EAAE,UAAU,CAAC,OAAO,CAAC,EACxB,GAAG,EAAE,UAAU,EACf,iBAAiB,EAAE,iBAAiB,CAAC,CAAC,CAAC;;WAaG,CAAC;;EAG5C;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG;IAClD,MAAM,CAAC,EAAE,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;IAC9C,KAAK,CAAC,EAAE,CAAC,CAAC;IACV,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAKjE;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAKxE;AAED,wBAAgB,oBAAoB,CAClC,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,EACrB,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,WAoDtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubscriptionScope.performance.test.d.ts","sourceRoot":"","sources":["../../../src/tools/tests/SubscriptionScope.performance.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -196,7 +196,7 @@
|
|
|
196
196
|
},
|
|
197
197
|
"type": "module",
|
|
198
198
|
"license": "MIT",
|
|
199
|
-
"version": "0.20.
|
|
199
|
+
"version": "0.20.2",
|
|
200
200
|
"dependencies": {
|
|
201
201
|
"@manuscripts/prosemirror-recreate-steps": "^0.1.4",
|
|
202
202
|
"@scure/base": "1.2.1",
|
|
@@ -213,9 +213,9 @@
|
|
|
213
213
|
"prosemirror-transform": "^1.9.0",
|
|
214
214
|
"use-sync-external-store": "^1.5.0",
|
|
215
215
|
"zod": "4.1.11",
|
|
216
|
-
"cojson": "0.20.
|
|
217
|
-
"cojson-storage-indexeddb": "0.20.
|
|
218
|
-
"cojson-transport-ws": "0.20.
|
|
216
|
+
"cojson": "0.20.2",
|
|
217
|
+
"cojson-storage-indexeddb": "0.20.2",
|
|
218
|
+
"cojson-transport-ws": "0.20.2"
|
|
219
219
|
},
|
|
220
220
|
"devDependencies": {
|
|
221
221
|
"@scure/bip39": "^1.3.0",
|
package/src/inspector/in-app.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CoID, LocalNode, RawAccount } from "cojson";
|
|
2
2
|
import { styled } from "goober";
|
|
3
|
+
import { useCallback, useState } from "react";
|
|
3
4
|
import { PageStack } from "./viewer/page-stack.js";
|
|
4
5
|
import { GlobalStyles } from "./ui/global-styles.js";
|
|
5
6
|
import { InspectorButton, type Position } from "./viewer/inspector-button.js";
|
|
@@ -7,6 +8,25 @@ import { useOpenInspector } from "./viewer/use-open-inspector.js";
|
|
|
7
8
|
import { NodeProvider } from "./contexts/node.js";
|
|
8
9
|
import { InMemoryRouterProvider } from "./router/in-memory-router.js";
|
|
9
10
|
import { Header } from "./viewer/header.js";
|
|
11
|
+
import { PerformancePage } from "./pages/performance/index.js";
|
|
12
|
+
import { HomePage } from "./pages/home.js";
|
|
13
|
+
import { SubscriptionScope } from "jazz-tools";
|
|
14
|
+
|
|
15
|
+
export type InspectorTab = "inspector" | "performance";
|
|
16
|
+
|
|
17
|
+
const STORAGE_KEY = "jazz-inspector-tab";
|
|
18
|
+
|
|
19
|
+
function getStoredTab(): InspectorTab {
|
|
20
|
+
try {
|
|
21
|
+
const stored = localStorage.getItem(STORAGE_KEY);
|
|
22
|
+
if (stored === "inspector" || stored === "performance") {
|
|
23
|
+
return stored;
|
|
24
|
+
}
|
|
25
|
+
} catch {
|
|
26
|
+
// localStorage not available
|
|
27
|
+
}
|
|
28
|
+
return "inspector";
|
|
29
|
+
}
|
|
10
30
|
|
|
11
31
|
export function InspectorInApp({
|
|
12
32
|
position = "right",
|
|
@@ -18,6 +38,16 @@ export function InspectorInApp({
|
|
|
18
38
|
accountId?: CoID<RawAccount>;
|
|
19
39
|
}) {
|
|
20
40
|
const [open, setOpen] = useOpenInspector();
|
|
41
|
+
const [activeTab, setActiveTabState] = useState<InspectorTab>(getStoredTab);
|
|
42
|
+
|
|
43
|
+
const setActiveTab = useCallback((tab: InspectorTab) => {
|
|
44
|
+
setActiveTabState(tab);
|
|
45
|
+
try {
|
|
46
|
+
localStorage.setItem(STORAGE_KEY, tab);
|
|
47
|
+
} catch {
|
|
48
|
+
// localStorage not available
|
|
49
|
+
}
|
|
50
|
+
}, []);
|
|
21
51
|
|
|
22
52
|
if (!open) {
|
|
23
53
|
return (
|
|
@@ -30,12 +60,20 @@ export function InspectorInApp({
|
|
|
30
60
|
<InMemoryRouterProvider>
|
|
31
61
|
<InspectorContainer as={GlobalStyles} style={{ zIndex: 999 }}>
|
|
32
62
|
<Header
|
|
33
|
-
showDeleteLocalData={true}
|
|
34
63
|
showClose={true}
|
|
35
64
|
onClose={() => setOpen(false)}
|
|
65
|
+
activeTab={activeTab}
|
|
66
|
+
onTabChange={setActiveTab}
|
|
67
|
+
/>
|
|
68
|
+
{/* Both components stay mounted, visibility controlled by CSS */}
|
|
69
|
+
<PageStack
|
|
70
|
+
style={{ display: activeTab === "inspector" ? "flex" : "none" }}
|
|
71
|
+
homePage={<HomePage showDeleteLocalData />}
|
|
72
|
+
/>
|
|
73
|
+
<PerformancePage
|
|
74
|
+
style={{ display: activeTab === "performance" ? "flex" : "none" }}
|
|
75
|
+
onNavigate={() => setActiveTab("inspector")}
|
|
36
76
|
/>
|
|
37
|
-
|
|
38
|
-
<PageStack />
|
|
39
77
|
</InspectorContainer>
|
|
40
78
|
</InMemoryRouterProvider>
|
|
41
79
|
</NodeProvider>
|
package/src/inspector/index.tsx
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react";
|
|
2
2
|
import { setup } from "goober";
|
|
3
3
|
import { useJazzContextValue } from "jazz-tools/react-core";
|
|
4
|
-
import { Account } from "jazz-tools";
|
|
4
|
+
import { Account, SubscriptionScope } from "jazz-tools";
|
|
5
5
|
import { InspectorInApp } from "./in-app.js";
|
|
6
6
|
import { Position } from "./viewer/inspector-button.js";
|
|
7
7
|
|
|
8
|
+
export function enableProfiling() {
|
|
9
|
+
SubscriptionScope.enableProfiling();
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
export function JazzInspector({ position = "right" }: { position?: Position }) {
|
|
9
13
|
const context = useJazzContextValue<Account>();
|
|
10
14
|
const localNode = context.node;
|
|
@@ -5,8 +5,13 @@ import { Button, Input } from "../ui";
|
|
|
5
5
|
import { useState } from "react";
|
|
6
6
|
import { CoID, RawCoValue } from "cojson";
|
|
7
7
|
import { useRouter } from "../router";
|
|
8
|
+
import { DeleteLocalData } from "../viewer/delete-local-data.js";
|
|
8
9
|
|
|
9
|
-
export
|
|
10
|
+
export interface HomePageProps {
|
|
11
|
+
showDeleteLocalData?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function HomePage({ showDeleteLocalData }: HomePageProps) {
|
|
10
15
|
const { localNode, accountID } = useNode();
|
|
11
16
|
const { path, setPage } = useRouter();
|
|
12
17
|
const [coValueId, setCoValueId] = useState<CoID<RawCoValue> | "">("");
|
|
@@ -24,7 +29,7 @@ export function HomePage() {
|
|
|
24
29
|
};
|
|
25
30
|
|
|
26
31
|
return (
|
|
27
|
-
|
|
32
|
+
<PageContainer>
|
|
28
33
|
<CenteredForm
|
|
29
34
|
onSubmit={handleCoValueIdSubmit}
|
|
30
35
|
aria-hidden={path.length !== 0}
|
|
@@ -55,10 +60,22 @@ export function HomePage() {
|
|
|
55
60
|
Inspect my account
|
|
56
61
|
</Button>
|
|
57
62
|
</CenteredForm>
|
|
58
|
-
|
|
63
|
+
|
|
64
|
+
{showDeleteLocalData && (
|
|
65
|
+
<BottomRight>
|
|
66
|
+
<DeleteLocalData />
|
|
67
|
+
</BottomRight>
|
|
68
|
+
)}
|
|
69
|
+
</PageContainer>
|
|
59
70
|
);
|
|
60
71
|
}
|
|
61
72
|
|
|
73
|
+
const PageContainer = styled("div")`
|
|
74
|
+
position: relative;
|
|
75
|
+
height: 100%;
|
|
76
|
+
width: 100%;
|
|
77
|
+
`;
|
|
78
|
+
|
|
62
79
|
const CenteredForm = styled("form")`
|
|
63
80
|
display: flex;
|
|
64
81
|
flex-direction: column;
|
|
@@ -75,3 +92,9 @@ const CenteredForm = styled("form")`
|
|
|
75
92
|
const OrText = styled("p")`
|
|
76
93
|
text-align: center;
|
|
77
94
|
`;
|
|
95
|
+
|
|
96
|
+
const BottomRight = styled("div")`
|
|
97
|
+
position: absolute;
|
|
98
|
+
bottom: 0.75rem;
|
|
99
|
+
right: 0;
|
|
100
|
+
`;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { styled } from "goober";
|
|
2
|
+
import { type CSSProperties, useMemo, useState, useDeferredValue } from "react";
|
|
3
|
+
import { CoID, RawCoValue } from "cojson";
|
|
4
|
+
import { useRouter } from "../../router/context.js";
|
|
5
|
+
import { Timeline } from "./Timeline.js";
|
|
6
|
+
import { SubscriptionRow } from "./SubscriptionRow.js";
|
|
7
|
+
import { SubscriptionDetailPanel } from "./SubscriptionDetailPanel.js";
|
|
8
|
+
import { usePerformanceEntries } from "./usePerformanceEntries.js";
|
|
9
|
+
import type { SubscriptionEntry } from "./types.js";
|
|
10
|
+
import { SubscriptionScope } from "jazz-tools";
|
|
11
|
+
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Styled Components
|
|
14
|
+
// ============================================================================
|
|
15
|
+
|
|
16
|
+
const Container = styled("div")`
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
gap: 0.5rem;
|
|
20
|
+
padding: 1rem;
|
|
21
|
+
height: 100%;
|
|
22
|
+
min-height: 0;
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
const MainLayout = styled("div")`
|
|
26
|
+
display: flex;
|
|
27
|
+
flex: 1;
|
|
28
|
+
min-height: 0;
|
|
29
|
+
gap: 1rem;
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
const ListPanel = styled("div")`
|
|
33
|
+
flex: 1;
|
|
34
|
+
min-width: 0;
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
const Grid = styled("div")`
|
|
40
|
+
display: grid;
|
|
41
|
+
grid-template-columns:
|
|
42
|
+
minmax(100px, 150px)
|
|
43
|
+
minmax(150px, 1fr)
|
|
44
|
+
minmax(100px, 200px)
|
|
45
|
+
80px;
|
|
46
|
+
grid-template-rows: min-content;
|
|
47
|
+
overflow-y: auto;
|
|
48
|
+
overflow-x: hidden;
|
|
49
|
+
flex: 1;
|
|
50
|
+
min-height: 0;
|
|
51
|
+
position: relative;
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
const HeaderCell = styled("div")`
|
|
55
|
+
padding: 0.5rem;
|
|
56
|
+
font-size: 0.625rem;
|
|
57
|
+
font-weight: 600;
|
|
58
|
+
color: var(--j-neutral-500);
|
|
59
|
+
border-bottom: 1px solid var(--j-border-color);
|
|
60
|
+
text-transform: uppercase;
|
|
61
|
+
letter-spacing: 0.05em;
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
const EmptyState = styled("div")`
|
|
65
|
+
text-align: center;
|
|
66
|
+
padding: 2rem;
|
|
67
|
+
color: var(--j-neutral-500);
|
|
68
|
+
font-size: 0.875rem;
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
// ============================================================================
|
|
72
|
+
// Component
|
|
73
|
+
// ============================================================================
|
|
74
|
+
|
|
75
|
+
export interface PerformancePageProps {
|
|
76
|
+
onNavigate: () => void;
|
|
77
|
+
style?: CSSProperties;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function PerformancePage({ onNavigate, style }: PerformancePageProps) {
|
|
81
|
+
const entries = usePerformanceEntries();
|
|
82
|
+
const [selectedRow, setSelectedRow] = useState<string | null>(null);
|
|
83
|
+
const [timeSelection, setTimeSelection] = useState<[number, number] | null>(
|
|
84
|
+
null,
|
|
85
|
+
);
|
|
86
|
+
const deferredSelection = useDeferredValue(timeSelection);
|
|
87
|
+
const { setPage } = useRouter();
|
|
88
|
+
|
|
89
|
+
const selectRow = (uuid: string) => {
|
|
90
|
+
setSelectedRow((prev) => (prev === uuid ? null : uuid));
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const sortedEntries = useMemo(() => {
|
|
94
|
+
return [...entries].sort((a, b) => a.startTime - b.startTime);
|
|
95
|
+
}, [entries]);
|
|
96
|
+
|
|
97
|
+
const overallTimeRange = useMemo(() => {
|
|
98
|
+
if (entries.length === 0) return null;
|
|
99
|
+
const now = performance.now();
|
|
100
|
+
return {
|
|
101
|
+
min: Math.min(...entries.map((e) => e.startTime)),
|
|
102
|
+
max: Math.max(...entries.map((e) => e.endTime ?? now)),
|
|
103
|
+
};
|
|
104
|
+
}, [entries]);
|
|
105
|
+
|
|
106
|
+
const filteredEntries = useMemo(() => {
|
|
107
|
+
if (!deferredSelection) return sortedEntries;
|
|
108
|
+
const [startTime, endTime] = deferredSelection;
|
|
109
|
+
const now = performance.now();
|
|
110
|
+
return sortedEntries.filter((entry) => {
|
|
111
|
+
const entryEnd = entry.endTime ?? now;
|
|
112
|
+
// Entry overlaps with selection if it starts before selection ends and ends after selection starts
|
|
113
|
+
return entry.startTime <= endTime && entryEnd >= startTime;
|
|
114
|
+
});
|
|
115
|
+
}, [sortedEntries, deferredSelection]);
|
|
116
|
+
|
|
117
|
+
const displayRange = deferredSelection
|
|
118
|
+
? { min: deferredSelection[0], max: deferredSelection[1] }
|
|
119
|
+
: overallTimeRange;
|
|
120
|
+
|
|
121
|
+
// Calculate bar position for each entry
|
|
122
|
+
const getBarProps = (entry: SubscriptionEntry) => {
|
|
123
|
+
const range = (displayRange?.max ?? 1) - (displayRange?.min ?? 0) || 1;
|
|
124
|
+
const now = performance.now();
|
|
125
|
+
|
|
126
|
+
const clampedStart = Math.max(entry.startTime, displayRange?.min ?? 0);
|
|
127
|
+
const clampedEnd = Math.min(entry.endTime ?? now, displayRange?.max ?? now);
|
|
128
|
+
|
|
129
|
+
const left = Math.max(
|
|
130
|
+
0,
|
|
131
|
+
((clampedStart - (displayRange?.min ?? 0)) / range) * 100,
|
|
132
|
+
);
|
|
133
|
+
const width = Math.max(0.5, ((clampedEnd - clampedStart) / range) * 100);
|
|
134
|
+
|
|
135
|
+
const color =
|
|
136
|
+
entry.status === "pending"
|
|
137
|
+
? "var(--j-warning-color)"
|
|
138
|
+
: entry.status === "error"
|
|
139
|
+
? "var(--j-error-color)"
|
|
140
|
+
: "var(--j-success-color)";
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
barLeft: `${left}%`,
|
|
144
|
+
barWidth: `${width}%`,
|
|
145
|
+
barColor: color,
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const handleNavigateToCoValue = (id: string) => {
|
|
150
|
+
setPage(id as CoID<RawCoValue>);
|
|
151
|
+
onNavigate();
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
if (!SubscriptionScope.isProfilingEnabled) {
|
|
155
|
+
return (
|
|
156
|
+
<Container style={style}>
|
|
157
|
+
<EmptyState>Profiling is not enabled in production builds.</EmptyState>
|
|
158
|
+
</Container>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (entries.length === 0) {
|
|
163
|
+
return (
|
|
164
|
+
<Container style={style}>
|
|
165
|
+
<EmptyState>
|
|
166
|
+
No subscriptions recorded yet. Interact with your app to see
|
|
167
|
+
subscription performance data.
|
|
168
|
+
</EmptyState>
|
|
169
|
+
</Container>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const selectedEntry = selectedRow
|
|
174
|
+
? filteredEntries.find((e) => e.uuid === selectedRow)
|
|
175
|
+
: null;
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<Container style={style}>
|
|
179
|
+
{overallTimeRange && (
|
|
180
|
+
<Timeline
|
|
181
|
+
entries={sortedEntries}
|
|
182
|
+
timeRange={overallTimeRange}
|
|
183
|
+
selection={timeSelection}
|
|
184
|
+
onSelectionChange={setTimeSelection}
|
|
185
|
+
/>
|
|
186
|
+
)}
|
|
187
|
+
<MainLayout>
|
|
188
|
+
<ListPanel>
|
|
189
|
+
<Grid>
|
|
190
|
+
<HeaderCell>Source</HeaderCell>
|
|
191
|
+
<HeaderCell>CoValue</HeaderCell>
|
|
192
|
+
<HeaderCell>Caller</HeaderCell>
|
|
193
|
+
<HeaderCell>Duration</HeaderCell>
|
|
194
|
+
{filteredEntries.map((entry) => (
|
|
195
|
+
<SubscriptionRow
|
|
196
|
+
key={entry.uuid}
|
|
197
|
+
entry={entry}
|
|
198
|
+
isSelected={selectedRow === entry.uuid}
|
|
199
|
+
onSelect={() => selectRow(entry.uuid)}
|
|
200
|
+
{...getBarProps(entry)}
|
|
201
|
+
/>
|
|
202
|
+
))}
|
|
203
|
+
</Grid>
|
|
204
|
+
</ListPanel>
|
|
205
|
+
{selectedEntry && (
|
|
206
|
+
<SubscriptionDetailPanel
|
|
207
|
+
entry={selectedEntry}
|
|
208
|
+
onNavigate={handleNavigateToCoValue}
|
|
209
|
+
onClose={() => setSelectedRow(null)}
|
|
210
|
+
/>
|
|
211
|
+
)}
|
|
212
|
+
</MainLayout>
|
|
213
|
+
</Container>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { styled } from "goober";
|
|
2
|
+
import type { SubscriptionEntry } from "./types.js";
|
|
3
|
+
import { formatTime, formatDuration, getCallerStack } from "./helpers.js";
|
|
4
|
+
|
|
5
|
+
// ============================================================================
|
|
6
|
+
// Styled Components
|
|
7
|
+
// ============================================================================
|
|
8
|
+
|
|
9
|
+
const DetailPanel = styled("div")`
|
|
10
|
+
width: 320px;
|
|
11
|
+
flex-shrink: 0;
|
|
12
|
+
padding: 0.75rem 1rem;
|
|
13
|
+
background-color: var(--j-foreground);
|
|
14
|
+
border: 1px solid var(--j-border-color);
|
|
15
|
+
border-radius: var(--j-radius-sm);
|
|
16
|
+
overflow-y: auto;
|
|
17
|
+
position: relative;
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
const CloseButton = styled("button")`
|
|
21
|
+
position: absolute;
|
|
22
|
+
top: 0.5rem;
|
|
23
|
+
right: 0.5rem;
|
|
24
|
+
display: flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
justify-content: center;
|
|
27
|
+
width: 18px;
|
|
28
|
+
height: 18px;
|
|
29
|
+
padding: 0;
|
|
30
|
+
background: none;
|
|
31
|
+
border: none;
|
|
32
|
+
border-radius: var(--j-radius-sm);
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
color: var(--j-neutral-500);
|
|
35
|
+
|
|
36
|
+
&:hover {
|
|
37
|
+
background-color: var(--j-background);
|
|
38
|
+
color: var(--j-text-color);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&:focus-visible {
|
|
42
|
+
outline: 2px solid var(--j-primary-color);
|
|
43
|
+
outline-offset: -2px;
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
const DetailsGrid = styled("div")`
|
|
48
|
+
display: grid;
|
|
49
|
+
grid-template-columns: auto 1fr;
|
|
50
|
+
gap: 0.5rem 1rem;
|
|
51
|
+
font-size: 0.625rem;
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
const DetailLabel = styled("span")`
|
|
55
|
+
color: var(--j-neutral-500);
|
|
56
|
+
font-weight: 500;
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
const DetailValue = styled("span")`
|
|
60
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
61
|
+
color: var(--j-text-color);
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
const Pre = styled("pre")`
|
|
65
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
66
|
+
font-size: 0.625rem;
|
|
67
|
+
color: var(--j-text-color);
|
|
68
|
+
margin: 0;
|
|
69
|
+
white-space: pre-wrap;
|
|
70
|
+
word-break: break-all;
|
|
71
|
+
max-height: 200px;
|
|
72
|
+
overflow-y: auto;
|
|
73
|
+
background-color: var(--j-background);
|
|
74
|
+
padding: 0.5rem;
|
|
75
|
+
border-radius: var(--j-radius-sm);
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
const StatusBadge = styled("span")`
|
|
79
|
+
display: inline-flex;
|
|
80
|
+
align-items: center;
|
|
81
|
+
gap: 0.25rem;
|
|
82
|
+
padding: 0.125rem 0.375rem;
|
|
83
|
+
border-radius: 0.25rem;
|
|
84
|
+
font-size: 0.625rem;
|
|
85
|
+
|
|
86
|
+
&[data-status="pending"] {
|
|
87
|
+
background-color: var(--j-warning-bg);
|
|
88
|
+
color: var(--j-warning-color);
|
|
89
|
+
}
|
|
90
|
+
&[data-status="loaded"] {
|
|
91
|
+
background-color: var(--j-success-bg);
|
|
92
|
+
color: var(--j-success-color);
|
|
93
|
+
}
|
|
94
|
+
&[data-status="error"] {
|
|
95
|
+
background-color: var(--j-error-bg);
|
|
96
|
+
color: var(--j-error-color);
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
// ============================================================================
|
|
101
|
+
// Component
|
|
102
|
+
// ============================================================================
|
|
103
|
+
|
|
104
|
+
export interface SubscriptionDetailPanelProps {
|
|
105
|
+
entry: SubscriptionEntry;
|
|
106
|
+
onNavigate: (id: string) => void;
|
|
107
|
+
onClose: () => void;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function SubscriptionDetailPanel({
|
|
111
|
+
entry,
|
|
112
|
+
onNavigate,
|
|
113
|
+
onClose,
|
|
114
|
+
}: SubscriptionDetailPanelProps) {
|
|
115
|
+
return (
|
|
116
|
+
<DetailPanel>
|
|
117
|
+
<CloseButton onClick={onClose} aria-label="Close detail panel">
|
|
118
|
+
<svg
|
|
119
|
+
width="10"
|
|
120
|
+
height="10"
|
|
121
|
+
viewBox="0 0 14 14"
|
|
122
|
+
fill="none"
|
|
123
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
124
|
+
>
|
|
125
|
+
<path
|
|
126
|
+
d="M1 1L13 13M1 13L13 1"
|
|
127
|
+
stroke="currentColor"
|
|
128
|
+
strokeWidth="2"
|
|
129
|
+
strokeLinecap="round"
|
|
130
|
+
/>
|
|
131
|
+
</svg>
|
|
132
|
+
</CloseButton>
|
|
133
|
+
<DetailsGrid>
|
|
134
|
+
<DetailLabel>Source</DetailLabel>
|
|
135
|
+
<DetailValue>
|
|
136
|
+
<StatusBadge data-status={entry.status}>{entry.source}</StatusBadge>
|
|
137
|
+
</DetailValue>
|
|
138
|
+
|
|
139
|
+
<DetailLabel>CoValue</DetailLabel>
|
|
140
|
+
<DetailValue>
|
|
141
|
+
<button
|
|
142
|
+
title="Click to navigate to CoValue"
|
|
143
|
+
onClick={() => onNavigate(entry.id)}
|
|
144
|
+
style={{
|
|
145
|
+
color: "var(--j-link-color)",
|
|
146
|
+
cursor: "pointer",
|
|
147
|
+
background: "none",
|
|
148
|
+
border: "none",
|
|
149
|
+
padding: 0,
|
|
150
|
+
font: "inherit",
|
|
151
|
+
}}
|
|
152
|
+
>
|
|
153
|
+
{entry.id}
|
|
154
|
+
</button>
|
|
155
|
+
</DetailValue>
|
|
156
|
+
|
|
157
|
+
<DetailLabel>Time</DetailLabel>
|
|
158
|
+
<DetailValue>
|
|
159
|
+
{formatTime(entry.startTime)} -{" "}
|
|
160
|
+
{entry.duration !== undefined
|
|
161
|
+
? formatTime(entry.startTime + entry.duration)
|
|
162
|
+
: "Pending..."}
|
|
163
|
+
</DetailValue>
|
|
164
|
+
|
|
165
|
+
<DetailLabel>Duration</DetailLabel>
|
|
166
|
+
<DetailValue>
|
|
167
|
+
{entry.duration !== undefined
|
|
168
|
+
? formatDuration(entry.duration)
|
|
169
|
+
: "Pending..."}
|
|
170
|
+
</DetailValue>
|
|
171
|
+
|
|
172
|
+
<DetailLabel>Resolve Query</DetailLabel>
|
|
173
|
+
<Pre>{JSON.stringify(JSON.parse(entry.resolve), null, 2)}</Pre>
|
|
174
|
+
|
|
175
|
+
<DetailLabel>Stack Trace</DetailLabel>
|
|
176
|
+
<Pre>
|
|
177
|
+
{getCallerStack(entry.callerStack) ?? "No stack trace available"}
|
|
178
|
+
</Pre>
|
|
179
|
+
</DetailsGrid>
|
|
180
|
+
</DetailPanel>
|
|
181
|
+
);
|
|
182
|
+
}
|