@sanity/sdk-react 3.3.0-rc.1 → 3.4.0-rc.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/dist/_exports/dashboard-internal.d.ts +2 -2
- package/dist/_exports/dashboard.d.ts +57 -1
- package/dist/_exports/dashboard.d.ts.map +1 -1
- package/dist/_exports/dashboard.js +69 -38
- package/dist/_exports/dashboard.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/{useStudioWorkspacesByProjectIdDataset-BZ_Ud887.js → useStudioWorkspacesByProjectIdDataset-B5A5kBH9.js} +85 -5
- package/dist/useStudioWorkspacesByProjectIdDataset-B5A5kBH9.js.map +1 -0
- package/package.json +8 -8
- package/src/_exports/dashboard-internal.ts +6 -1
- package/src/_exports/dashboard.test-d.ts +30 -4
- package/src/_exports/dashboard.ts +3 -0
- package/src/hooks/dashboard/useApplicationBasePath.test.tsx +77 -0
- package/src/hooks/dashboard/useApplicationBasePath.ts +23 -0
- package/src/hooks/dashboard/useApplications.test.tsx +12 -3
- package/src/hooks/dashboard/useApplications.ts +5 -24
- package/src/hooks/dashboard/useAuthToken.test.tsx +48 -0
- package/src/hooks/dashboard/useAuthToken.ts +20 -0
- package/src/hooks/dashboard/useCurrentUser.test.tsx +57 -0
- package/src/hooks/dashboard/useCurrentUser.ts +22 -0
- package/src/hooks/dashboard/useOrganizationId.test.tsx +52 -1
- package/src/hooks/dashboard/useOrganizationId.tsx +15 -2
- package/src/hooks/dashboard/useStudioWorkspacesByProjectIdDataset.test.tsx +142 -1
- package/src/hooks/dashboard/useStudioWorkspacesByProjectIdDataset.ts +58 -1
- package/src/hooks/dashboard/useWindowTitle.test.ts +23 -0
- package/src/hooks/dashboard/useWindowTitle.ts +14 -0
- package/src/hooks/installations/useInstallations.test-d.ts +10 -0
- package/dist/useStudioWorkspacesByProjectIdDataset-BZ_Ud887.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { installMessageBus, resetMessageBus } from "@sanity/sdk/_internal";
|
|
2
|
-
export { installMessageBus, resetMessageBus };
|
|
1
|
+
import { ApplicationStatus, ApplicationStatusUpdate, installMessageBus, resetMessageBus } from "@sanity/sdk/_internal";
|
|
2
|
+
export { type ApplicationStatus, type ApplicationStatusUpdate, installMessageBus, resetMessageBus };
|
|
@@ -2,6 +2,7 @@ import { Application, ApplicationBase, DocumentHandle } from "@sanity/sdk";
|
|
|
2
2
|
import React, { PropsWithChildren } from "react";
|
|
3
3
|
import { PathChangeMessage } from "@sanity/message-protocol";
|
|
4
4
|
import { ApplicationConfig, ApplicationConfig as ApplicationConfig$1, ApplicationConfigAppType, ApplicationConfigAppType as ApplicationConfigAppType$1, ConnectMessageBusOptions, DashboardTopics, EventTopic, EventTopic as EventTopic$1, EventTopicDef, MessageBus, MessageBusAbortOptions, MessageBusClient, MessageBusConnection, MessageBusEmitOptions, MessageBusEmitOptions as MessageBusEmitOptions$1, MessageBusEmitResult, MessageBusEmitResult as MessageBusEmitResult$1, MessageBusError, MessageBusErrorCode, MessageBusHost, MessageBusMessage, MessageBusMeta, MessageBusQueryOptions, MessageBusStateSource, NavigationLocation, NavigationTarget, PayloadOf, PayloadOf as PayloadOf$1, RemoteModuleRef, RemoteModuleRef as RemoteModuleRef$1, ReplyOf, ReplyOf as ReplyOf$1, StateTopic, StateTopic as StateTopic$1, StateTopicDef, TopicData, TopicData as TopicData$1, TopicError, TopicName, TopicResult, Topics, ValueOf, ValueOf as ValueOf$1, connectMessageBus } from "@sanity/sdk/dashboard";
|
|
5
|
+
import { CurrentUser as CurrentUser$1 } from "@sanity/types";
|
|
5
6
|
import { UserOptions } from "@module-federation/runtime/types";
|
|
6
7
|
/**
|
|
7
8
|
* Authenticates the SDK with the Sanity Dashboard's session when the app runs
|
|
@@ -360,7 +361,7 @@ type DashboardWebWorker = Extract<DashboardApplicationInterface, {
|
|
|
360
361
|
* The minimal Brett application fields with its loadable views and web workers.
|
|
361
362
|
* @public
|
|
362
363
|
*/
|
|
363
|
-
type DashboardApplication =
|
|
364
|
+
type DashboardApplication = DashboardTopicApplication & {
|
|
364
365
|
readonly views: DashboardView[];
|
|
365
366
|
readonly webWorkers: DashboardWebWorker[];
|
|
366
367
|
};
|
|
@@ -397,6 +398,23 @@ export declare function useApplications(): DashboardApplication[];
|
|
|
397
398
|
* @public
|
|
398
399
|
*/
|
|
399
400
|
export declare function useApplication(applicationId: DashboardApplication['id']): DashboardApplication | null;
|
|
401
|
+
/**
|
|
402
|
+
* Returns the base path for an application.
|
|
403
|
+
*
|
|
404
|
+
* Suspends until Dashboard publishes the path and throws a `TopicError` when the application is
|
|
405
|
+
* unknown.
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* ```tsx
|
|
409
|
+
* function ApplicationBasePath() {
|
|
410
|
+
* const basePath = useApplicationBasePath()
|
|
411
|
+
* return <span>{basePath}</span>
|
|
412
|
+
* }
|
|
413
|
+
* ```
|
|
414
|
+
*
|
|
415
|
+
* @public
|
|
416
|
+
*/
|
|
417
|
+
export declare function useApplicationBasePath(): TopicData$1<'applications.base-path'>;
|
|
400
418
|
/**
|
|
401
419
|
* Selects an application configuration by application id or application type.
|
|
402
420
|
* @public
|
|
@@ -461,6 +479,38 @@ export declare function useApplicationConfigs(): readonly ApplicationConfig$1[];
|
|
|
461
479
|
* @public
|
|
462
480
|
*/
|
|
463
481
|
export declare function useApplicationForegroundId(): Application['id'] | null;
|
|
482
|
+
/**
|
|
483
|
+
* Returns the session token for the reading connection, or `null` while signed out.
|
|
484
|
+
*
|
|
485
|
+
* Suspends until Dashboard publishes the token.
|
|
486
|
+
*
|
|
487
|
+
* @example
|
|
488
|
+
* ```tsx
|
|
489
|
+
* function AuthToken() {
|
|
490
|
+
* const token = useAuthToken()
|
|
491
|
+
* return <span>{token ?? 'Signed out'}</span>
|
|
492
|
+
* }
|
|
493
|
+
* ```
|
|
494
|
+
*
|
|
495
|
+
* @public
|
|
496
|
+
*/
|
|
497
|
+
export declare function useAuthToken(): string | null;
|
|
498
|
+
/**
|
|
499
|
+
* Returns the signed-in user, or `null` while signed out.
|
|
500
|
+
*
|
|
501
|
+
* Suspends until Dashboard publishes the current user.
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
* ```tsx
|
|
505
|
+
* function CurrentUser() {
|
|
506
|
+
* const user = useCurrentUser()
|
|
507
|
+
* return <span>{user?.name ?? 'Signed out'}</span>
|
|
508
|
+
* }
|
|
509
|
+
* ```
|
|
510
|
+
*
|
|
511
|
+
* @public
|
|
512
|
+
*/
|
|
513
|
+
export declare function useCurrentUser(): CurrentUser$1 | null;
|
|
464
514
|
/**
|
|
465
515
|
* Emits a dashboard event topic, typed to the topic's payload and reply.
|
|
466
516
|
* @public
|
|
@@ -617,6 +667,9 @@ export declare function useNavigateToStudioDocument(documentHandle: DocumentHand
|
|
|
617
667
|
*
|
|
618
668
|
* A React hook that retrieves the dashboard organization ID that is currently selected in the Sanity Dashboard.
|
|
619
669
|
*
|
|
670
|
+
* Works in both Dashboard runtimes: it reads the `organizations.current` message bus topic when a
|
|
671
|
+
* host has installed the bus, and falls back to the Comlink connection otherwise.
|
|
672
|
+
*
|
|
620
673
|
* @example
|
|
621
674
|
* ```tsx
|
|
622
675
|
* function DashboardComponent() {
|
|
@@ -668,6 +721,9 @@ export declare const useTopic: <K extends StateTopic$1>(topic: K) => TopicData$1
|
|
|
668
721
|
*
|
|
669
722
|
* The Sanity dashboard appends `| Sanity` to produce the final browser tab title.
|
|
670
723
|
*
|
|
724
|
+
* Works in both Dashboard runtimes: it manages the document title over the Comlink connection, and
|
|
725
|
+
* no-ops under the message bus, where the Dashboard host owns the title.
|
|
726
|
+
*
|
|
671
727
|
* @param viewTitle - An optional view-specific title to prepend to the app title.
|
|
672
728
|
*
|
|
673
729
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dashboard.d.ts","names":[],"sources":["../../src/context/DashboardTokenRefresh.tsx","../../src/dashboard/createRemoteInstance.ts","../../src/dashboard/urlFor.ts","../../src/hooks/dashboard/useAgentResourceContext.ts","../../src/hooks/dashboard/useApplications.ts","../../src/hooks/dashboard/useApplication.ts","../../src/hooks/dashboard/useApplicationConfig.ts","../../src/hooks/dashboard/useApplicationConfigs.ts","../../src/hooks/dashboard/useApplicationForegroundId.ts","../../src/hooks/dashboard/useEmit.ts","../../src/hooks/dashboard/useNavigate.ts","../../src/hooks/dashboard/useNavigateToStudioDocument.ts","../../src/hooks/dashboard/useOrganizationId.tsx","../../src/hooks/dashboard/useRemoteClient.ts","../../src/hooks/dashboard/useTopic.ts","../../src/hooks/dashboard/useWindowTitle.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"dashboard.d.ts","names":[],"sources":["../../src/context/DashboardTokenRefresh.tsx","../../src/dashboard/createRemoteInstance.ts","../../src/dashboard/urlFor.ts","../../src/hooks/dashboard/useAgentResourceContext.ts","../../src/hooks/dashboard/useApplications.ts","../../src/hooks/dashboard/useApplication.ts","../../src/hooks/dashboard/useApplicationBasePath.ts","../../src/hooks/dashboard/useApplicationConfig.ts","../../src/hooks/dashboard/useApplicationConfigs.ts","../../src/hooks/dashboard/useApplicationForegroundId.ts","../../src/hooks/dashboard/useAuthToken.ts","../../src/hooks/dashboard/useCurrentUser.ts","../../src/hooks/dashboard/useEmit.ts","../../src/hooks/dashboard/useNavigate.ts","../../src/hooks/dashboard/useNavigateToStudioDocument.ts","../../src/hooks/dashboard/useOrganizationId.tsx","../../src/hooks/dashboard/useRemoteClient.ts","../../src/hooks/dashboard/useTopic.ts","../../src/hooks/dashboard/useWindowTitle.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+Fa,+BAA+B,MAAM,GAAG;KCxFhD,aAAa,GAAG,gBAAgB,KAAK,KAAK,GAAG,KAAK,QAAQ,KAAK,GAAG;;;;KAK3D;EACV;EACA;;;;;KAcU,8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;;;;;;;wBCpCa;;;;;;qBCrBH,uBAAuB;;;;;;;;;;;;;;;;;;qBCavB,WAMN,UAAU,cAAY,OAAO,MAAM,YAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBC4CpC,eAAe"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as useWindowConnection, c as useSanityInstance, i as DashboardTokenRefreshProvider, n as useTopic, r as useOrganizationId, s as createStateSourceHook, t as useStudioWorkspacesByProjectIdDataset } from "../useStudioWorkspacesByProjectIdDataset-B5A5kBH9.js";
|
|
2
2
|
import { c } from "react-compiler-runtime";
|
|
3
3
|
import "@sanity/sdk";
|
|
4
|
-
import { createLogger,
|
|
4
|
+
import { createLogger, getApplicationOrigin, isDashboardEnvironment, requireDashboardMessageBus } from "@sanity/sdk/_internal";
|
|
5
5
|
import { useEffect, useRef, useState } from "react";
|
|
6
6
|
import { SDK_CHANNEL_NAME, SDK_NODE_NAME } from "@sanity/message-protocol";
|
|
7
7
|
import "@sanity/sdk/comlink";
|
|
8
8
|
import { of } from "rxjs";
|
|
9
9
|
import { MessageBusError, TopicError, connectMessageBus } from "@sanity/sdk/dashboard";
|
|
10
|
+
import "@sanity/types";
|
|
10
11
|
import { createInstance } from "@module-federation/runtime";
|
|
11
12
|
import "@module-federation/runtime/types";
|
|
12
13
|
const MANIFEST_FILE = "mf-manifest.json";
|
|
@@ -445,41 +446,10 @@ function useAgentResourceContext(options) {
|
|
|
445
446
|
updateContext();
|
|
446
447
|
}, t3 = [updateContext], $[6] = updateContext, $[7] = t2, $[8] = t3), useEffect(t2, t3);
|
|
447
448
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
*
|
|
451
|
-
* The hook suspends until the topic publishes its first value, using the message bus query
|
|
452
|
-
* deadline. A topic declared with `TopicResult` resolves to its successful value; a
|
|
453
|
-
* failed result throws a `TopicError` to the nearest error boundary.
|
|
454
|
-
*
|
|
455
|
-
* @example
|
|
456
|
-
* ```tsx
|
|
457
|
-
* function ForegroundApplication() {
|
|
458
|
-
* const foregroundId = useTopic('applications.foreground')
|
|
459
|
-
* return <span>{foregroundId ?? 'No application in the foreground'}</span>
|
|
460
|
-
* }
|
|
461
|
-
* ```
|
|
462
|
-
*
|
|
463
|
-
* @public
|
|
464
|
-
*/
|
|
465
|
-
const useTopic = createStateSourceHook({
|
|
466
|
-
getState: getTopicState,
|
|
467
|
-
shouldSuspend: (instance, topic) => getTopicState(instance, topic).getCurrent() === void 0,
|
|
468
|
-
suspender: resolveTopic
|
|
469
|
-
}), applicationOrigin = (application) => {
|
|
470
|
-
if (application.externalUrl !== null) return new URL(application.externalUrl).origin;
|
|
471
|
-
if (application.slug === null) return null;
|
|
472
|
-
let staging = globalThis.__SANITY_STAGING__ === !0;
|
|
473
|
-
if (application.isSingleton) {
|
|
474
|
-
let domain = staging ? "run.sanity.work" : "sanity.run";
|
|
475
|
-
return `https://${application.slug}-apps-${application.organizationId}.${domain}`;
|
|
476
|
-
}
|
|
477
|
-
let domain = staging ? "studio.sanity.work" : "sanity.studio";
|
|
478
|
-
return `https://${application.slug}.${domain}`;
|
|
479
|
-
}, loadableInterfaces = ({ activeDeployment, config }) => config?.mfManifest === void 0 ? [] : activeDeployment?.interfaces ?? [], toApplication = (application) => {
|
|
480
|
-
let { activeDeployment: _activeDeployment, config: _config, ...applicationBase } = application, interfaces = loadableInterfaces(application), entry = interfaces.length === 0 ? null : applicationOrigin(applicationBase);
|
|
449
|
+
const loadableInterfaces = ({ activeDeployment, config }) => config?.mfManifest === void 0 ? [] : activeDeployment?.interfaces ?? [], toApplication = (application) => {
|
|
450
|
+
let { activeDeployment: _activeDeployment, config: _config, ...applicationBase } = application, interfaces = loadableInterfaces(application), entry = interfaces.length === 0 ? null : getApplicationOrigin(applicationBase);
|
|
481
451
|
if (entry === null) return {
|
|
482
|
-
...
|
|
452
|
+
...application,
|
|
483
453
|
views: [],
|
|
484
454
|
webWorkers: []
|
|
485
455
|
};
|
|
@@ -507,7 +477,7 @@ const useTopic = createStateSourceHook({
|
|
|
507
477
|
});
|
|
508
478
|
}
|
|
509
479
|
return {
|
|
510
|
-
...
|
|
480
|
+
...application,
|
|
511
481
|
views,
|
|
512
482
|
webWorkers
|
|
513
483
|
};
|
|
@@ -553,6 +523,25 @@ function useApplication(applicationId) {
|
|
|
553
523
|
return id === applicationId;
|
|
554
524
|
}) ?? null;
|
|
555
525
|
}
|
|
526
|
+
/**
|
|
527
|
+
* Returns the base path for an application.
|
|
528
|
+
*
|
|
529
|
+
* Suspends until Dashboard publishes the path and throws a `TopicError` when the application is
|
|
530
|
+
* unknown.
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```tsx
|
|
534
|
+
* function ApplicationBasePath() {
|
|
535
|
+
* const basePath = useApplicationBasePath()
|
|
536
|
+
* return <span>{basePath}</span>
|
|
537
|
+
* }
|
|
538
|
+
* ```
|
|
539
|
+
*
|
|
540
|
+
* @public
|
|
541
|
+
*/
|
|
542
|
+
function useApplicationBasePath() {
|
|
543
|
+
return useTopic("applications.base-path");
|
|
544
|
+
}
|
|
556
545
|
const NO_CONFIGS = Object.freeze([]);
|
|
557
546
|
/**
|
|
558
547
|
* Returns the application configuration modules available in the dashboard.
|
|
@@ -615,6 +604,42 @@ function useApplicationForegroundId() {
|
|
|
615
604
|
return useTopic("applications.foreground");
|
|
616
605
|
}
|
|
617
606
|
/**
|
|
607
|
+
* Returns the session token for the reading connection, or `null` while signed out.
|
|
608
|
+
*
|
|
609
|
+
* Suspends until Dashboard publishes the token.
|
|
610
|
+
*
|
|
611
|
+
* @example
|
|
612
|
+
* ```tsx
|
|
613
|
+
* function AuthToken() {
|
|
614
|
+
* const token = useAuthToken()
|
|
615
|
+
* return <span>{token ?? 'Signed out'}</span>
|
|
616
|
+
* }
|
|
617
|
+
* ```
|
|
618
|
+
*
|
|
619
|
+
* @public
|
|
620
|
+
*/
|
|
621
|
+
function useAuthToken() {
|
|
622
|
+
return useTopic("auth.token");
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Returns the signed-in user, or `null` while signed out.
|
|
626
|
+
*
|
|
627
|
+
* Suspends until Dashboard publishes the current user.
|
|
628
|
+
*
|
|
629
|
+
* @example
|
|
630
|
+
* ```tsx
|
|
631
|
+
* function CurrentUser() {
|
|
632
|
+
* const user = useCurrentUser()
|
|
633
|
+
* return <span>{user?.name ?? 'Signed out'}</span>
|
|
634
|
+
* }
|
|
635
|
+
* ```
|
|
636
|
+
*
|
|
637
|
+
* @public
|
|
638
|
+
*/
|
|
639
|
+
function useCurrentUser() {
|
|
640
|
+
return useTopic("users.current");
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
618
643
|
* Returns a stable function that emits a dashboard event topic.
|
|
619
644
|
*
|
|
620
645
|
* The event is sent immediately. Ignore the lazy result for fire-and-forget delivery, await it
|
|
@@ -839,6 +864,9 @@ function resolveAppTitle(resource) {
|
|
|
839
864
|
*
|
|
840
865
|
* The Sanity dashboard appends `| Sanity` to produce the final browser tab title.
|
|
841
866
|
*
|
|
867
|
+
* Works in both Dashboard runtimes: it manages the document title over the Comlink connection, and
|
|
868
|
+
* no-ops under the message bus, where the Dashboard host owns the title.
|
|
869
|
+
*
|
|
842
870
|
* @param viewTitle - An optional view-specific title to prepend to the app title.
|
|
843
871
|
*
|
|
844
872
|
* @example
|
|
@@ -867,6 +895,9 @@ function resolveAppTitle(resource) {
|
|
|
867
895
|
* @public
|
|
868
896
|
*/
|
|
869
897
|
function useWindowTitle(viewTitle) {
|
|
898
|
+
isDashboardEnvironment() || useComlinkWindowTitle(viewTitle);
|
|
899
|
+
}
|
|
900
|
+
function useComlinkWindowTitle(viewTitle) {
|
|
870
901
|
let [appTitle, setAppTitle] = useState(null), { fetch } = useWindowConnection({
|
|
871
902
|
name: SDK_NODE_NAME,
|
|
872
903
|
connectTo: SDK_CHANNEL_NAME
|
|
@@ -894,6 +925,6 @@ function useWindowTitle(viewTitle) {
|
|
|
894
925
|
};
|
|
895
926
|
}, [viewTitle, appTitle]);
|
|
896
927
|
}
|
|
897
|
-
export { MessageBusError, DashboardTokenRefreshProvider as TokenRefreshProvider, TopicError, UrlBuilder, connectMessageBus, createRemoteInstance, urlFor, useAgentResourceContext, useApplication, useApplicationConfig, useApplicationConfigs, useApplicationForegroundId, useApplications, useEmit, useNavigate, useNavigateToStudioDocument, useOrganizationId, useRemoteClient, useTopic, useWindowTitle };
|
|
928
|
+
export { MessageBusError, DashboardTokenRefreshProvider as TokenRefreshProvider, TopicError, UrlBuilder, connectMessageBus, createRemoteInstance, urlFor, useAgentResourceContext, useApplication, useApplicationBasePath, useApplicationConfig, useApplicationConfigs, useApplicationForegroundId, useApplications, useAuthToken, useCurrentUser, useEmit, useNavigate, useNavigateToStudioDocument, useOrganizationId, useRemoteClient, useTopic, useWindowTitle };
|
|
898
929
|
|
|
899
930
|
//# sourceMappingURL=dashboard.js.map
|