@sanity/sdk-react 0.0.1 → 0.0.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/dist/index.d.ts CHANGED
@@ -133,7 +133,6 @@ export {DatasetsResponse}
133
133
 
134
134
  declare interface DocumentInteractionHistory {
135
135
  recordEvent: (eventType: 'viewed' | 'edited' | 'created' | 'deleted') => void
136
- isConnected: boolean
137
136
  }
138
137
 
139
138
  /**
@@ -237,7 +236,6 @@ declare interface ManageFavorite extends FavoriteStatusResponse {
237
236
  favorite: () => Promise<void>
238
237
  unfavorite: () => Promise<void>
239
238
  isFavorited: boolean
240
- isConnected: boolean
241
239
  }
242
240
 
243
241
  /**
@@ -258,7 +256,6 @@ export declare type MessageHandler<TWindowMessage extends WindowMessage> = (
258
256
  */
259
257
  export declare interface NavigateToStudioResult {
260
258
  navigateToStudioDocument: () => void
261
- isConnected: boolean
262
259
  }
263
260
 
264
261
  /**
@@ -559,7 +556,6 @@ export {SortOrderingItem}
559
556
  declare interface StudioWorkspacesResult {
560
557
  workspacesByProjectIdAndDataset: WorkspacesByProjectIdDataset
561
558
  error: string | null
562
- isConnected: boolean
563
559
  }
564
560
 
565
561
  declare type Updater<TValue> = TValue | ((currentValue: TValue) => TValue)
@@ -1577,16 +1573,28 @@ declare interface UseManageFavoriteProps extends DocumentHandle {
1577
1573
  * - `isConnected` - Boolean indicating if connection to Dashboard is established
1578
1574
  *
1579
1575
  * @example
1580
- * ```ts
1576
+ * ```tsx
1581
1577
  * import {useNavigateToStudioDocument, type DocumentHandle} from '@sanity/sdk-react'
1578
+ * import {Button} from '@sanity/ui'
1579
+ * import {Suspense} from 'react'
1582
1580
  *
1583
- * function MyComponent({documentHandle}: {documentHandle: DocumentHandle}) {
1581
+ * function NavigateButton({documentHandle}: {documentHandle: DocumentHandle}) {
1584
1582
  * const {navigateToStudioDocument, isConnected} = useNavigateToStudioDocument(documentHandle)
1583
+ * return (
1584
+ * <Button
1585
+ * disabled={!isConnected}
1586
+ * onClick={navigateToStudioDocument}
1587
+ * text="Navigate to Studio Document"
1588
+ * />
1589
+ * )
1590
+ * }
1585
1591
  *
1592
+ * // Wrap the component with Suspense since the hook may suspend
1593
+ * function MyDocumentAction({documentHandle}: {documentHandle: DocumentHandle}) {
1586
1594
  * return (
1587
- * <button onClick={navigateToStudioDocument} disabled={!isConnected}>
1588
- * Navigate to Studio Document
1589
- * </button>
1595
+ * <Suspense fallback={<Button text="Loading..." disabled />}>
1596
+ * <NavigateButton documentHandle={documentHandle} />
1597
+ * </Suspense>
1590
1598
  * )
1591
1599
  * }
1592
1600
  * ```
@@ -2143,7 +2151,11 @@ export declare function useQuery<TData>(options: QueryOptions): {
2143
2151
  *
2144
2152
  * @example
2145
2153
  * ```tsx
2146
- * function MyDocumentAction(props: DocumentActionProps) {
2154
+ * import {useRecordDocumentHistoryEvent} from '@sanity/sdk-react'
2155
+ * import {Button} from '@sanity/ui'
2156
+ * import {Suspense} from 'react'
2157
+ *
2158
+ * function RecordEventButton(props: DocumentActionProps) {
2147
2159
  * const {documentId, documentType, resourceType, resourceId} = props
2148
2160
  * const {recordEvent, isConnected} = useRecordDocumentHistoryEvent({
2149
2161
  * documentId,
@@ -2151,15 +2163,23 @@ export declare function useQuery<TData>(options: QueryOptions): {
2151
2163
  * resourceType,
2152
2164
  * resourceId,
2153
2165
  * })
2154
- *
2155
2166
  * return (
2156
2167
  * <Button
2157
2168
  * disabled={!isConnected}
2158
2169
  * onClick={() => recordEvent('viewed')}
2159
- * text={'Viewed'}
2170
+ * text="Viewed"
2160
2171
  * />
2161
2172
  * )
2162
2173
  * }
2174
+ *
2175
+ * // Wrap the component with Suspense since the hook may suspend
2176
+ * function MyDocumentAction(props: DocumentActionProps) {
2177
+ * return (
2178
+ * <Suspense fallback={<Button text="Loading..." disabled />}>
2179
+ * <RecordEventButton {...props} />
2180
+ * </Suspense>
2181
+ * )
2182
+ * }
2163
2183
  * ```
2164
2184
  */
2165
2185
  export declare function useRecordDocumentHistoryEvent({
@@ -2265,6 +2285,36 @@ export declare const useSanityInstance: (config?: SanityConfig) => SanityInstanc
2265
2285
  /**
2266
2286
  * Hook that fetches studio workspaces and organizes them by projectId:dataset
2267
2287
  * @internal
2288
+ *
2289
+ * @example
2290
+ * ```tsx
2291
+ * import {useStudioWorkspacesByProjectIdDataset} from '@sanity/sdk-react'
2292
+ * import {Card, Code, Button} from '@sanity/ui'
2293
+ * import {Suspense} from 'react'
2294
+ *
2295
+ * function WorkspacesCard() {
2296
+ * const {workspacesByProjectIdAndDataset, error} = useStudioWorkspacesByProjectIdDataset()
2297
+ * if (error) {
2298
+ * return <div>Error: {error}</div>
2299
+ * }
2300
+ * return (
2301
+ * <Card padding={4} radius={2} shadow={1}>
2302
+ * <Code language="json">
2303
+ * {JSON.stringify(workspacesByProjectIdAndDataset, null, 2)}
2304
+ * </Code>
2305
+ * </Card>
2306
+ * )
2307
+ * }
2308
+ *
2309
+ * // Wrap the component with Suspense since the hook may suspend
2310
+ * function DashboardWorkspaces() {
2311
+ * return (
2312
+ * <Suspense fallback={<Button text="Loading..." disabled />}>
2313
+ * <WorkspacesCard />
2314
+ * </Suspense>
2315
+ * )
2316
+ * }
2317
+ * ```
2268
2318
  */
2269
2319
  export declare function useStudioWorkspacesByProjectIdDataset(): StudioWorkspacesResult
2270
2320
 
@@ -2343,7 +2393,6 @@ export declare function useWindowConnection<
2343
2393
  name,
2344
2394
  connectTo,
2345
2395
  onMessage,
2346
- onStatus,
2347
2396
  }: UseWindowConnectionOptions<TFrameMessage>): WindowConnection<TWindowMessage>
2348
2397
 
2349
2398
  /**
@@ -2353,7 +2402,6 @@ export declare interface UseWindowConnectionOptions<TMessage extends FrameMessag
2353
2402
  name: string
2354
2403
  connectTo: string
2355
2404
  onMessage?: Record<TMessage['type'], WindowMessageHandler<TMessage>>
2356
- onStatus?: (status: ComlinkStatus) => void
2357
2405
  }
2358
2406
 
2359
2407
  /**
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import { c } from "react-compiler-runtime";
3
- import { getAuthState, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout, AuthStateType, createSanityInstance, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, getOrCreateNode, releaseNode, getFavoritesState, resolveFavoritesState, resolveDatasets, getDatasetsState, applyDocumentActions, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, createGroqSearchFilter, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, getActiveReleasesState, getPerspectiveState, getUsersKey, parseUsersKey, getUsersState, resolveUsers, loadMoreUsers } from "@sanity/sdk";
3
+ import { getAuthState, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout, AuthStateType, createSanityInstance, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, getNodeState, getFavoritesState, resolveFavoritesState, resolveDatasets, getDatasetsState, applyDocumentActions, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, createGroqSearchFilter, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, getActiveReleasesState, getPerspectiveState, getUsersKey, parseUsersKey, getUsersState, resolveUsers, loadMoreUsers } from "@sanity/sdk";
4
4
  export * from "@sanity/sdk";
5
5
  import { createContext, useContext, useSyncExternalStore, useState, useEffect, useRef, Suspense, useMemo, useCallback, useInsertionEffect, useTransition } from "react";
6
6
  import { ErrorBoundary } from "react-error-boundary";
@@ -329,52 +329,50 @@ function useFrameConnection(options) {
329
329
  function _temp$4(unsub) {
330
330
  return unsub();
331
331
  }
332
+ const useNodeState = createStateSourceHook({
333
+ getState: getNodeState,
334
+ shouldSuspend: (instance, nodeInput) => getNodeState(instance, nodeInput).getCurrent() === void 0,
335
+ suspender: (instance, nodeInput) => firstValueFrom(getNodeState(instance, nodeInput).observable.pipe(filter(Boolean)))
336
+ });
332
337
  function useWindowConnection(t0) {
333
- const $ = c(11), {
338
+ const $ = c(19), {
334
339
  name,
335
340
  connectTo,
336
- onMessage,
337
- onStatus
338
- } = t0, nodeRef = useRef(null);
341
+ onMessage
342
+ } = t0;
339
343
  let t1;
340
- $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = [], $[0] = t1) : t1 = $[0];
341
- const messageUnsubscribers = useRef(t1), instance = useSanityInstance();
342
- let t2, t3;
343
- $[1] !== connectTo || $[2] !== instance || $[3] !== name || $[4] !== onMessage || $[5] !== onStatus ? (t2 = () => {
344
- const node = getOrCreateNode(instance, {
345
- name,
346
- connectTo
347
- });
348
- nodeRef.current = node;
349
- const statusUnsubscribe = node.onStatus((eventStatus) => {
350
- onStatus?.(eventStatus);
351
- });
352
- return onMessage && Object.entries(onMessage).forEach((t42) => {
353
- const [type, handler] = t42, messageUnsubscribe = node.on(type, handler);
354
- messageUnsubscribers.current.push(messageUnsubscribe);
355
- }), () => {
356
- statusUnsubscribe(), messageUnsubscribers.current.forEach(_temp$3), messageUnsubscribers.current = [], releaseNode(instance, name), nodeRef.current = null;
357
- };
358
- }, t3 = [instance, name, connectTo, onMessage, onStatus], $[1] = connectTo, $[2] = instance, $[3] = name, $[4] = onMessage, $[5] = onStatus, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), useEffect(t2, t3);
344
+ $[0] !== connectTo || $[1] !== name ? (t1 = {
345
+ name,
346
+ connectTo
347
+ }, $[0] = connectTo, $[1] = name, $[2] = t1) : t1 = $[2];
348
+ const {
349
+ node
350
+ } = useNodeState(t1);
351
+ let t2;
352
+ $[3] === Symbol.for("react.memo_cache_sentinel") ? (t2 = [], $[3] = t2) : t2 = $[3];
353
+ const messageUnsubscribers = useRef(t2), instance = useSanityInstance();
354
+ let t3;
355
+ $[4] !== node || $[5] !== onMessage ? (t3 = () => (onMessage && Object.entries(onMessage).forEach((t42) => {
356
+ const [type, handler] = t42, messageUnsubscribe = node.on(type, handler);
357
+ messageUnsubscribe && messageUnsubscribers.current.push(messageUnsubscribe);
358
+ }), () => {
359
+ messageUnsubscribers.current.forEach(_temp$3), messageUnsubscribers.current = [];
360
+ }), $[4] = node, $[5] = onMessage, $[6] = t3) : t3 = $[6];
359
361
  let t4;
360
- $[8] === Symbol.for("react.memo_cache_sentinel") ? (t4 = (type_0, data) => {
361
- if (!nodeRef.current)
362
- throw new Error("Cannot send message before connection is established");
363
- nodeRef.current.post(type_0, data);
364
- }, $[8] = t4) : t4 = $[8];
365
- const sendMessage = t4;
362
+ $[7] !== instance || $[8] !== name || $[9] !== node || $[10] !== onMessage ? (t4 = [instance, name, onMessage, node], $[7] = instance, $[8] = name, $[9] = node, $[10] = onMessage, $[11] = t4) : t4 = $[11], useEffect(t3, t4);
366
363
  let t5;
367
- $[9] === Symbol.for("react.memo_cache_sentinel") ? (t5 = (type_1, data_0, fetchOptions) => {
368
- if (!nodeRef.current)
369
- throw new Error("Cannot fetch before connection is established");
370
- return nodeRef.current?.fetch(type_1, data_0, fetchOptions ?? {});
371
- }, $[9] = t5) : t5 = $[9];
372
- const fetch = t5;
364
+ $[12] !== node ? (t5 = (type_0, data) => {
365
+ node.post(type_0, data);
366
+ }, $[12] = node, $[13] = t5) : t5 = $[13];
367
+ const sendMessage = t5;
373
368
  let t6;
374
- return $[10] === Symbol.for("react.memo_cache_sentinel") ? (t6 = {
369
+ $[14] !== node ? (t6 = (type_1, data_0, fetchOptions) => node.fetch(type_1, data_0, fetchOptions ?? {}), $[14] = node, $[15] = t6) : t6 = $[15];
370
+ const fetch = t6;
371
+ let t7;
372
+ return $[16] !== fetch || $[17] !== sendMessage ? (t7 = {
375
373
  sendMessage,
376
374
  fetch
377
- }, $[10] = t6) : t6 = $[10], t6;
375
+ }, $[16] = fetch, $[17] = sendMessage, $[18] = t7) : t7 = $[18], t7;
378
376
  }
379
377
  function _temp$3(unsubscribe) {
380
378
  return unsubscribe();
@@ -388,12 +386,11 @@ function useManageFavorite({
388
386
  resourceType,
389
387
  schemaName
390
388
  }) {
391
- const [status, setStatus] = useState("idle"), {
389
+ const {
392
390
  fetch
393
391
  } = useWindowConnection({
394
392
  name: SDK_NODE_NAME,
395
- connectTo: SDK_CHANNEL_NAME,
396
- onStatus: setStatus
393
+ connectTo: SDK_CHANNEL_NAME
397
394
  }), instance = useSanityInstance(), {
398
395
  config
399
396
  } = instance, instanceProjectId = config?.projectId, instanceDataset = config?.dataset, projectId = paramProjectId ?? instanceProjectId, dataset = paramDataset ?? instanceDataset;
@@ -408,8 +405,8 @@ function useManageFavorite({
408
405
  resourceId,
409
406
  resourceType,
410
407
  schemaName
411
- }), [documentId, documentType, resourceId, resourceType, schemaName]), favoriteState = getFavoritesState(instance, context), state = useSyncExternalStore(favoriteState.subscribe, favoriteState.getCurrent), isFavorited = state?.isFavorited ?? !1, handleFavoriteAction = useCallback(async (action) => {
412
- if (!(status !== "connected" || !fetch || !documentId || !documentType || !resourceType))
408
+ }), [documentId, documentType, resourceId, resourceType, schemaName]), favoriteState = getFavoritesState(instance, context), isFavorited = useSyncExternalStore(favoriteState.subscribe, favoriteState.getCurrent)?.isFavorited ?? !1, handleFavoriteAction = useCallback(async (action) => {
409
+ if (!(!fetch || !documentId || !documentType || !resourceType))
413
410
  try {
414
411
  const payload = {
415
412
  eventType: action,
@@ -429,100 +426,33 @@ function useManageFavorite({
429
426
  } catch (err) {
430
427
  throw console.error(`Failed to ${action === "added" ? "favorite" : "unfavorite"} document:`, err), err;
431
428
  }
432
- }, [fetch, documentId, documentType, resourceId, resourceType, schemaName, instance, context, status]), favorite = useCallback(() => handleFavoriteAction("added"), [handleFavoriteAction]), unfavorite = useCallback(() => handleFavoriteAction("removed"), [handleFavoriteAction]);
433
- if (!state)
434
- try {
435
- throw resolveFavoritesState(instance, context);
436
- } catch (err_0) {
437
- if (err_0 instanceof Error && err_0.message === "Favorites service connection timeout")
438
- return {
439
- favorite: async () => {
440
- },
441
- unfavorite: async () => {
442
- },
443
- isFavorited: !1,
444
- isConnected: !1
445
- };
446
- throw err_0;
447
- }
429
+ }, [fetch, documentId, documentType, resourceId, resourceType, schemaName, instance, context]), favorite = useCallback(() => handleFavoriteAction("added"), [handleFavoriteAction]), unfavorite = useCallback(() => handleFavoriteAction("removed"), [handleFavoriteAction]);
448
430
  return {
449
431
  favorite,
450
432
  unfavorite,
451
- isFavorited,
452
- isConnected: status === "connected"
433
+ isFavorited
453
434
  };
454
435
  }
455
- function useRecordDocumentHistoryEvent(t0) {
456
- const $ = c(11), {
457
- documentId,
458
- documentType,
459
- resourceType,
460
- resourceId,
461
- schemaName
462
- } = t0, [status, setStatus] = useState("idle");
463
- let t1;
464
- $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
465
- name: SDK_NODE_NAME,
466
- connectTo: SDK_CHANNEL_NAME,
467
- onStatus: setStatus
468
- }, $[0] = t1) : t1 = $[0];
469
- const {
470
- sendMessage
471
- } = useWindowConnection(t1);
472
- if (resourceType !== "studio" && !resourceId)
473
- throw new Error("resourceId is required for media-library and canvas resources");
474
- let t2;
475
- $[1] !== documentId || $[2] !== documentType || $[3] !== resourceId || $[4] !== resourceType || $[5] !== schemaName || $[6] !== sendMessage ? (t2 = (eventType) => {
476
- try {
477
- const message = {
478
- type: "dashboard/v1/events/history",
479
- data: {
480
- eventType,
481
- document: {
482
- id: documentId,
483
- type: documentType,
484
- resource: {
485
- id: resourceId,
486
- type: resourceType,
487
- schemaName
488
- }
489
- }
490
- }
491
- };
492
- sendMessage(message.type, message.data);
493
- } catch (t32) {
494
- const error = t32;
495
- throw console.error("Failed to record history event:", error), error;
496
- }
497
- }, $[1] = documentId, $[2] = documentType, $[3] = resourceId, $[4] = resourceType, $[5] = schemaName, $[6] = sendMessage, $[7] = t2) : t2 = $[7];
498
- const recordEvent = t2, t3 = status === "connected";
499
- let t4;
500
- return $[8] !== recordEvent || $[9] !== t3 ? (t4 = {
501
- recordEvent,
502
- isConnected: t3
503
- }, $[8] = recordEvent, $[9] = t3, $[10] = t4) : t4 = $[10], t4;
504
- }
505
436
  function useStudioWorkspacesByProjectIdDataset() {
506
- const $ = c(10);
437
+ const $ = c(8);
507
438
  let t0;
508
439
  $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {}, $[0] = t0) : t0 = $[0];
509
- const [workspacesByProjectIdAndDataset, setWorkspacesByProjectIdAndDataset] = useState(t0), [status, setStatus] = useState("idle"), [error, setError] = useState(null);
440
+ const [workspacesByProjectIdAndDataset, setWorkspacesByProjectIdAndDataset] = useState(t0), [error, setError] = useState(null);
510
441
  let t1;
511
442
  $[1] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
512
443
  name: SDK_NODE_NAME,
513
- connectTo: SDK_CHANNEL_NAME,
514
- onStatus: setStatus
444
+ connectTo: SDK_CHANNEL_NAME
515
445
  }, $[1] = t1) : t1 = $[1];
516
446
  const {
517
447
  fetch
518
448
  } = useWindowConnection(t1);
519
449
  let t2, t3;
520
- $[2] !== fetch || $[3] !== status ? (t2 = () => {
521
- if (!fetch || status !== "connected")
450
+ $[2] !== fetch ? (t2 = () => {
451
+ if (!fetch)
522
452
  return;
523
453
  const fetchWorkspaces = async function(signal) {
524
454
  try {
525
- const data = await fetch("dashboard/v1/bridge/context", void 0, {
455
+ const data = await fetch("dashboard/v1/context", void 0, {
526
456
  signal
527
457
  }), workspaceMap = {}, noProjectIdAndDataset = [];
528
458
  data.context.availableResources.forEach((resource) => {
@@ -547,39 +477,31 @@ function useStudioWorkspacesByProjectIdDataset() {
547
477
  return fetchWorkspaces(controller.signal), () => {
548
478
  controller.abort();
549
479
  };
550
- }, t3 = [fetch, status], $[2] = fetch, $[3] = status, $[4] = t2, $[5] = t3) : (t2 = $[4], t3 = $[5]), useEffect(t2, t3);
551
- const t4 = status === "connected";
552
- let t5;
553
- return $[6] !== error || $[7] !== t4 || $[8] !== workspacesByProjectIdAndDataset ? (t5 = {
480
+ }, t3 = [fetch], $[2] = fetch, $[3] = t2, $[4] = t3) : (t2 = $[3], t3 = $[4]), useEffect(t2, t3);
481
+ let t4;
482
+ return $[5] !== error || $[6] !== workspacesByProjectIdAndDataset ? (t4 = {
554
483
  workspacesByProjectIdAndDataset,
555
- error,
556
- isConnected: t4
557
- }, $[6] = error, $[7] = t4, $[8] = workspacesByProjectIdAndDataset, $[9] = t5) : t5 = $[9], t5;
484
+ error
485
+ }, $[5] = error, $[6] = workspacesByProjectIdAndDataset, $[7] = t4) : t4 = $[7], t4;
558
486
  }
559
487
  function useNavigateToStudioDocument(documentHandle, preferredStudioUrl) {
560
- const $ = c(11), {
561
- workspacesByProjectIdAndDataset,
562
- isConnected: workspacesConnected
563
- } = useStudioWorkspacesByProjectIdDataset(), [status, setStatus] = useState("idle");
488
+ const $ = c(8), {
489
+ workspacesByProjectIdAndDataset
490
+ } = useStudioWorkspacesByProjectIdDataset();
564
491
  let t0;
565
492
  $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {
566
493
  name: SDK_NODE_NAME,
567
- connectTo: SDK_CHANNEL_NAME,
568
- onStatus: setStatus
494
+ connectTo: SDK_CHANNEL_NAME
569
495
  }, $[0] = t0) : t0 = $[0];
570
496
  const {
571
497
  sendMessage
572
498
  } = useWindowConnection(t0);
573
499
  let t1;
574
- $[1] !== documentHandle || $[2] !== preferredStudioUrl || $[3] !== sendMessage || $[4] !== status || $[5] !== workspacesByProjectIdAndDataset || $[6] !== workspacesConnected ? (t1 = () => {
500
+ $[1] !== documentHandle || $[2] !== preferredStudioUrl || $[3] !== sendMessage || $[4] !== workspacesByProjectIdAndDataset ? (t1 = () => {
575
501
  const {
576
502
  projectId,
577
503
  dataset
578
504
  } = documentHandle;
579
- if (!workspacesConnected || status !== "connected") {
580
- console.warn("Not connected to Dashboard");
581
- return;
582
- }
583
505
  if (!projectId || !dataset) {
584
506
  console.warn("Project ID and dataset are required to navigate to a studio document");
585
507
  return;
@@ -604,13 +526,60 @@ function useNavigateToStudioDocument(documentHandle, preferredStudioUrl) {
604
526
  }
605
527
  };
606
528
  sendMessage(message.type, message.data);
607
- }, $[1] = documentHandle, $[2] = preferredStudioUrl, $[3] = sendMessage, $[4] = status, $[5] = workspacesByProjectIdAndDataset, $[6] = workspacesConnected, $[7] = t1) : t1 = $[7];
608
- const navigateToStudioDocument = t1, t2 = workspacesConnected && status === "connected";
529
+ }, $[1] = documentHandle, $[2] = preferredStudioUrl, $[3] = sendMessage, $[4] = workspacesByProjectIdAndDataset, $[5] = t1) : t1 = $[5];
530
+ const navigateToStudioDocument = t1;
531
+ let t2;
532
+ return $[6] !== navigateToStudioDocument ? (t2 = {
533
+ navigateToStudioDocument
534
+ }, $[6] = navigateToStudioDocument, $[7] = t2) : t2 = $[7], t2;
535
+ }
536
+ function useRecordDocumentHistoryEvent(t0) {
537
+ const $ = c(10), {
538
+ documentId,
539
+ documentType,
540
+ resourceType,
541
+ resourceId,
542
+ schemaName
543
+ } = t0;
544
+ let t1;
545
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = {
546
+ name: SDK_NODE_NAME,
547
+ connectTo: SDK_CHANNEL_NAME
548
+ }, $[0] = t1) : t1 = $[0];
549
+ const {
550
+ sendMessage
551
+ } = useWindowConnection(t1);
552
+ if (resourceType !== "studio" && !resourceId)
553
+ throw new Error("resourceId is required for media-library and canvas resources");
554
+ let t2;
555
+ $[1] !== documentId || $[2] !== documentType || $[3] !== resourceId || $[4] !== resourceType || $[5] !== schemaName || $[6] !== sendMessage ? (t2 = (eventType) => {
556
+ try {
557
+ const message = {
558
+ type: "dashboard/v1/events/history",
559
+ data: {
560
+ eventType,
561
+ document: {
562
+ id: documentId,
563
+ type: documentType,
564
+ resource: {
565
+ id: resourceId,
566
+ type: resourceType,
567
+ schemaName
568
+ }
569
+ }
570
+ }
571
+ };
572
+ sendMessage(message.type, message.data);
573
+ } catch (t32) {
574
+ const error = t32;
575
+ throw console.error("Failed to record history event:", error), error;
576
+ }
577
+ }, $[1] = documentId, $[2] = documentType, $[3] = resourceId, $[4] = resourceType, $[5] = schemaName, $[6] = sendMessage, $[7] = t2) : t2 = $[7];
578
+ const recordEvent = t2;
609
579
  let t3;
610
- return $[8] !== navigateToStudioDocument || $[9] !== t2 ? (t3 = {
611
- navigateToStudioDocument,
612
- isConnected: t2
613
- }, $[8] = navigateToStudioDocument, $[9] = t2, $[10] = t3) : t3 = $[10], t3;
580
+ return $[8] !== recordEvent ? (t3 = {
581
+ recordEvent
582
+ }, $[8] = recordEvent, $[9] = t3) : t3 = $[9], t3;
614
583
  }
615
584
  const useDatasets = createStateSourceHook({
616
585
  getState: getDatasetsState,
@@ -1070,7 +1039,7 @@ function useUsers(options) {
1070
1039
  loadMore
1071
1040
  };
1072
1041
  }
1073
- var version = "0.0.1";
1042
+ var version = "0.0.2";
1074
1043
  function getEnv(key) {
1075
1044
  if (typeof import.meta < "u" && import.meta.env)
1076
1045
  return import.meta.env[key];