sanity 5.0.0-next-major.20251210134624 → 5.0.0-next-major.20251212101828

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/lib/index.js CHANGED
@@ -29,7 +29,7 @@ import memoize$1 from "lodash/memoize.js";
29
29
  import { useObservable, useObservableEvent } from "react-rx";
30
30
  import { observableCallback } from "observable-callback";
31
31
  import { fromUrl } from "@sanity/bifur-client";
32
- import debug$a from "debug";
32
+ import debug$c from "debug";
33
33
  import startCase from "lodash/startCase.js";
34
34
  import { isValidElementType } from "react-is";
35
35
  import uniqueId from "lodash/uniqueId.js";
@@ -4969,7 +4969,7 @@ function _shareReplayLatest(config) {
4969
4969
  return merge(wrapped, emitLatest);
4970
4970
  };
4971
4971
  }
4972
- const debug$9 = debug$a("sanity:document-store"), DEFAULT_TTL = 12e4, DEFAULT_MAX_ENTRIES = 1e3;
4972
+ const debug$b = debug$c("sanity:document-store"), DEFAULT_TTL = 12e4, DEFAULT_MAX_ENTRIES = 1e3;
4973
4973
  function dedupeListenerEvents({
4974
4974
  ttl = DEFAULT_TTL,
4975
4975
  max: max2 = DEFAULT_MAX_ENTRIES
@@ -4983,7 +4983,7 @@ function dedupeListenerEvents({
4983
4983
  seen
4984
4984
  };
4985
4985
  const key = `${event.transactionId}#${event.documentId}`;
4986
- return seen.has(key) ? (debug$9("Ignoring duplicate listener event: ", key), {
4986
+ return seen.has(key) ? (debug$b("Ignoring duplicate listener event: ", key), {
4987
4987
  seen,
4988
4988
  emit: []
4989
4989
  }) : (seen.set(key, null), {
@@ -5041,7 +5041,7 @@ function sequentializeListenerEvents(options) {
5041
5041
  if (event.type === "mutation") {
5042
5042
  const orderedChains = toOrderedChains(state.buffer.concat(event)).map((chain) => {
5043
5043
  const [discarded, rest] = discardChainTo(chain, state.base.revision);
5044
- return discarded.length > 0 && debug$9("Discarded %d mutations already applied to document", discarded.length), rest;
5044
+ return discarded.length > 0 && debug$b("Discarded %d mutations already applied to document", discarded.length), rest;
5045
5045
  }), [resolvedChains, _nextBuffer] = partition(orderedChains, (chain) => state.base.revision === chain[0]?.previousRev), nextBuffer = _nextBuffer.flat().toSorted((a, b) => a.messageReceivedAt.localeCompare(b.messageReceivedAt));
5046
5046
  if (resolvedChains.length > 1)
5047
5047
  throw new Error("Expected at most one resolved chain");
@@ -5051,7 +5051,7 @@ function sequentializeListenerEvents(options) {
5051
5051
  // resultRev pointing at a transaction id.
5052
5052
  lastMutation.transition === "disappear" ? void 0 : lastMutation?.resultRev
5053
5053
  );
5054
- return state.buffer.length > 0 && (debug$9("Resolved chain: %s => %s", resolvedChains[0][0].previousRev, resolvedChains[0].at(-1)?.resultRev), nextBuffer.length > 0 ? debug$9("There are still %d unchainable mutations", nextBuffer.length) : debug$9("All chains were resolved")), {
5054
+ return state.buffer.length > 0 && (debug$b("Resolved chain: %s => %s", resolvedChains[0][0].previousRev, resolvedChains[0].at(-1)?.resultRev), nextBuffer.length > 0 ? debug$b("There are still %d unchainable mutations", nextBuffer.length) : debug$b("All chains were resolved")), {
5055
5055
  base: {
5056
5056
  revision: nextBaseRevision
5057
5057
  },
@@ -5078,7 +5078,7 @@ function sequentializeListenerEvents(options) {
5078
5078
  }), switchMap$1((state) => {
5079
5079
  if (state.buffer.length > 0) {
5080
5080
  const brokenChainStartsAt = new Date(state.buffer[0].messageReceivedAt), nextDeadline = resolveChainDeadline - (Date.now() - brokenChainStartsAt.getTime());
5081
- return debug$9("There are %d listener event(s) that can't be applied in sequence. This could be due to events arriving out of order. Will throw an error if chain can't be resolved within %dms", state.buffer.length, nextDeadline), debug$9("Buffered events: %O", state.buffer), concat(of(state), timer(nextDeadline).pipe(mergeMap(() => throwError(() => new DeadlineExceededError(`Did not resolve chain within a deadline of ${resolveChainDeadline}ms`, state)))));
5081
+ return debug$b("There are %d listener event(s) that can't be applied in sequence. This could be due to events arriving out of order. Will throw an error if chain can't be resolved within %dms", state.buffer.length, nextDeadline), debug$b("Buffered events: %O", state.buffer), concat(of(state), timer(nextDeadline).pipe(mergeMap(() => throwError(() => new DeadlineExceededError(`Did not resolve chain within a deadline of ${resolveChainDeadline}ms`, state)))));
5082
5082
  }
5083
5083
  return of(state);
5084
5084
  }), mergeMap((state) => state.emitEvents));
@@ -5153,7 +5153,7 @@ function getPairListener(_client, idPair, options = {}) {
5153
5153
  disconnectedTime
5154
5154
  }, i) => {
5155
5155
  const shouldSyncDocument = event.type === "welcome" && i === 0 || disconnectedTime && disconnectedTime > REFETCH_IF_DISCONNECTED_LONGER_THAN_MS;
5156
- return (disconnectedTime || 0) > 0 && debug$9("Reconnected after being disconnected for: %dms", disconnectedTime), shouldSyncDocument ? fetchInitialDocumentSnapshots().pipe(mergeMap(({
5156
+ return (disconnectedTime || 0) > 0 && debug$b("Reconnected after being disconnected for: %dms", disconnectedTime), shouldSyncDocument ? fetchInitialDocumentSnapshots().pipe(mergeMap(({
5157
5157
  draft,
5158
5158
  published,
5159
5159
  version: version2
@@ -5192,7 +5192,7 @@ function getPairListener(_client, idPair, options = {}) {
5192
5192
  mergeMap((v) => v.next),
5193
5193
  share()
5194
5194
  ), draftEvents$ = pairEvents$.pipe(filter((event) => event.type === "mutation" || event.type === "snapshot" ? event.documentId === draftId : !0), sequentializeListenerEvents()), publishedEvents$ = pairEvents$.pipe(filter((event) => event.type === "mutation" || event.type === "snapshot" ? event.documentId === publishedId : !0), sequentializeListenerEvents()), versionEvents$ = pairEvents$.pipe(filter((event) => event.type === "mutation" || event.type === "snapshot" ? event.documentId === versionId : !0), sequentializeListenerEvents());
5195
- return merge(draftEvents$, publishedEvents$, versionEvents$).pipe(catchError((err, caught$) => err instanceof OutOfSyncError ? (debug$9("Recovering from OutOfSyncError: %s", err.name), typeof options?.onSyncErrorRecovery == "function" ? options?.onSyncErrorRecovery(err) : console.error(err), caught$) : throwError(() => err)));
5195
+ return merge(draftEvents$, publishedEvents$, versionEvents$).pipe(catchError((err, caught$) => err instanceof OutOfSyncError ? (debug$b("Recovering from OutOfSyncError: %s", err.name), typeof options?.onSyncErrorRecovery == "function" ? options?.onSyncErrorRecovery(err) : console.error(err), caught$) : throwError(() => err)));
5196
5196
  function fetchInitialDocumentSnapshots() {
5197
5197
  return client.observable.getDocuments([publishedId, draftId, versionId].filter((id2) => typeof id2 == "string"), {
5198
5198
  tag: "document.snapshots"
@@ -27455,17 +27455,17 @@ const DATE_FORMAT = {
27455
27455
  t3
27456
27456
  ] }), $[7] = t2, $[8] = t3, $[9] = t4) : t4 = $[9], t4;
27457
27457
  }, rootName$1 = "scheduled-publishing:";
27458
- debug$a(rootName$1);
27458
+ debug$c(rootName$1);
27459
27459
  function debugWithName$1(name) {
27460
27460
  const namespace = `${rootName$1}${name}`;
27461
- return debug$a && debug$a.enabled(namespace) ? debug$a(namespace) : debug$a(rootName$1);
27461
+ return debug$c && debug$c.enabled(namespace) ? debug$c(namespace) : debug$c(rootName$1);
27462
27462
  }
27463
27463
  function createTZDateFromComponents$1(date, timeZone) {
27464
27464
  return new TZDate(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds(), timeZone);
27465
27465
  }
27466
27466
  const TimeZoneEvents = {
27467
27467
  update: "timeZoneEventUpdate"
27468
- }, debug$8 = debugWithName$1("useScheduleOperation"), timeZoneLocalStorageNamespace = "studio.timezone.", timeZoneCache = /* @__PURE__ */ new Map(), offsetCache = /* @__PURE__ */ new Map(), offsetToMinutes = (offset) => {
27468
+ }, debug$a = debugWithName$1("useScheduleOperation"), timeZoneLocalStorageNamespace = "studio.timezone.", timeZoneCache = /* @__PURE__ */ new Map(), offsetCache = /* @__PURE__ */ new Map(), offsetToMinutes = (offset) => {
27469
27469
  if (!offset) return 0;
27470
27470
  const multiplier = offset.startsWith("-") ? -1 : 1;
27471
27471
  if (!offset.includes(":")) return multiplier * Number(offset.replace(/[+-]/, "")) * 60;
@@ -27616,7 +27616,7 @@ const TIME_ZONE_SCOPE_TYPE = {
27616
27616
  const getTimeZone = t15;
27617
27617
  let t16;
27618
27618
  $[44] !== keyStoreId || $[45] !== keyValueStore || $[46] !== toast ? (t16 = (tz_5) => {
27619
- debug$8("handleNewValue:", tz_5), setTimeZone((prevTz) => {
27619
+ debug$a("handleNewValue:", tz_5), setTimeZone((prevTz) => {
27620
27620
  const run_0 = () => {
27621
27621
  prevTz?.name !== tz_5.name && (keyValueStore.setKey(keyStoreId, tz_5.name), window.dispatchEvent(new Event(TimeZoneEvents.update))), toast.push({
27622
27622
  closable: !0,
@@ -38785,7 +38785,7 @@ function toStylePercentage(num) {
38785
38785
  const HotspotImageContainer = styled.div`
38786
38786
  position: relative;
38787
38787
  width: 100%;
38788
- `, debug$7 = debug$a("sanity-imagetool");
38788
+ `, debug$9 = debug$c("sanity-imagetool");
38789
38789
  function getCropAspect(crop, srcAspect) {
38790
38790
  const origHeight = 1 / srcAspect, origWidth = srcAspect * origHeight, cropWidth = origWidth - (crop.left + crop.right) * origWidth, cropHeight = origHeight - (crop.top + crop.bottom) * origHeight;
38791
38791
  return cropWidth / cropHeight;
@@ -38819,7 +38819,7 @@ const HotspotImage = memo(function(props2) {
38819
38819
  let t7, t8;
38820
38820
  $[2] !== src || $[3] !== updateContainerAspect ? (t7 = () => {
38821
38821
  const imageElement = imageElementRef.current;
38822
- return imageElement && imageElement.src && imageElement.complete && imageElement.naturalWidth !== void 0 && (debug$7("Image '%s' already loaded, refreshing (from cache) to trigger onLoad / onError", src), imageElement.src = imageElement.src), startTransition(() => updateContainerAspect()), window.addEventListener("resize", updateContainerAspect), () => {
38822
+ return imageElement && imageElement.src && imageElement.complete && imageElement.naturalWidth !== void 0 && (debug$9("Image '%s' already loaded, refreshing (from cache) to trigger onLoad / onError", src), imageElement.src = imageElement.src), startTransition(() => updateContainerAspect()), window.addEventListener("resize", updateContainerAspect), () => {
38823
38823
  window.removeEventListener("resize", updateContainerAspect);
38824
38824
  };
38825
38825
  }, t8 = [src, updateContainerAspect], $[2] = src, $[3] = updateContainerAspect, $[4] = t7, $[5] = t8) : (t7 = $[4], t8 = $[5]), useEffect(t7, t8);
@@ -45368,7 +45368,7 @@ const ReleaseTypeOption = (t0) => {
45368
45368
  publishedId
45369
45369
  }).pipe(map$1((result) => result.documentIds)).pipe(switchMap$1((versionIds) => previewStore.unstable_observeDocumentIdSet('_type == "sanity.canvas.link" && studioDocumentId in $ids', {
45370
45370
  ids: versionIds
45371
- }))), getCompanionDoc$ = (id2) => client.observable.fetch("*[_id == $id][0]{ _id, canvasDocumentId, studioDocumentId}", {
45371
+ }))), getCompanionDoc$ = (id2) => client.observable.fetch("*[_id == $id][0]{ _id, canvasDocumentId, studioDocumentId, isStudioDocumentEditable}", {
45372
45372
  id: id2
45373
45373
  }, {
45374
45374
  tag: "canvas.companion-docs"
@@ -52282,10 +52282,10 @@ function isRecentSearchTerms(terms) {
52282
52282
  return typeof terms.__recent < "u";
52283
52283
  }
52284
52284
  const rootName = "core:studio:navbar:search:";
52285
- debug$a(rootName);
52285
+ debug$c(rootName);
52286
52286
  function debugWithName(name) {
52287
52287
  const namespace = `${rootName}${name}`;
52288
- return debug$a && debug$a.enabled(namespace) ? debug$a(namespace) : debug$a(rootName);
52288
+ return debug$c && debug$c.enabled(namespace) ? debug$c(namespace) : debug$c(rootName);
52289
52289
  }
52290
52290
  function isDebugMode() {
52291
52291
  return typeof window > "u" ? !1 : window.location.hash.slice(1).split(";").includes(DEBUG_FRAGMENT);
@@ -52324,10 +52324,10 @@ function initialSearchState({
52324
52324
  strategy
52325
52325
  };
52326
52326
  }
52327
- const debug$6 = debugWithName("reducer");
52327
+ const debug$8 = debugWithName("reducer");
52328
52328
  function searchReducer(state, action) {
52329
52329
  let prefix = "\u{1F50D}";
52330
- switch (action.type.startsWith("SEARCH_REQUEST") && (prefix = "\u{1F6A8}"), action.type.startsWith("RECENT_SEARCHES") && (prefix = "\u{1F4BE}"), debug$6(prefix, action), action.type) {
52330
+ switch (action.type.startsWith("SEARCH_REQUEST") && (prefix = "\u{1F6A8}"), action.type.startsWith("RECENT_SEARCHES") && (prefix = "\u{1F4BE}"), debug$8(prefix, action), action.type) {
52331
52331
  case "FILTERS_VISIBLE_SET":
52332
52332
  return {
52333
52333
  ...state,
@@ -57799,7 +57799,7 @@ function getArrayFieldsetAndFieldGroupOperations(state, path) {
57799
57799
  return foundMember ? getFieldsetAndFieldGroupOperations(foundMember.item, rest) : [];
57800
57800
  }
57801
57801
  const useCanvasCompanionDoc = (documentId) => {
57802
- const $ = c(12), companionDocsStore = useCanvasCompanionDocsStore();
57802
+ const $ = c(13), companionDocsStore = useCanvasCompanionDocsStore();
57803
57803
  let t0;
57804
57804
  $[0] !== documentId ? (t0 = getPublishedId(documentId), $[0] = documentId, $[1] = t0) : t0 = $[1];
57805
57805
  const publishedId = t0;
@@ -57808,13 +57808,14 @@ const useCanvasCompanionDoc = (documentId) => {
57808
57808
  const companionDocs = useObservable(t1);
57809
57809
  let t2;
57810
57810
  $[5] !== companionDocs?.data || $[6] !== documentId ? (t2 = companionDocs?.data.find((companion) => companion?.studioDocumentId === documentId), $[5] = companionDocs?.data, $[6] = documentId, $[7] = t2) : t2 = $[7];
57811
- const companionDoc = t2, t3 = !!companionDoc, t4 = companionDocs?.loading;
57812
- let t5;
57813
- return $[8] !== companionDoc || $[9] !== t3 || $[10] !== t4 ? (t5 = {
57811
+ const companionDoc = t2, t3 = !!companionDoc, t4 = companionDoc ? !companionDoc.isStudioDocumentEditable : !1, t5 = companionDocs?.loading;
57812
+ let t6;
57813
+ return $[8] !== companionDoc || $[9] !== t3 || $[10] !== t4 || $[11] !== t5 ? (t6 = {
57814
57814
  isLinked: t3,
57815
+ isLockedByCanvas: t4,
57815
57816
  companionDoc,
57816
- loading: t4
57817
- }, $[8] = companionDoc, $[9] = t3, $[10] = t4, $[11] = t5) : t5 = $[11], t5;
57817
+ loading: t5
57818
+ }, $[8] = companionDoc, $[9] = t3, $[10] = t4, $[11] = t5, $[12] = t6) : t6 = $[12], t6;
57818
57819
  };
57819
57820
  function getSanityCreateLinkMetadata(doc) {
57820
57821
  return doc?._create;
@@ -58328,13 +58329,13 @@ function useDocumentForm(options) {
58328
58329
  let t22;
58329
58330
  $[56] !== selectedPerspective ? (t22 = isReleaseDocument(selectedPerspective) ? isReleaseScheduledOrScheduling(selectedPerspective) : !1, $[56] = selectedPerspective, $[57] = t22) : t22 = $[57];
58330
58331
  const isReleaseLocked = t22, {
58331
- isLinked
58332
+ isLockedByCanvas
58332
58333
  } = useCanvasCompanionDoc(value._id);
58333
58334
  let t23;
58334
- $[58] !== connectionState || $[59] !== editState2 || $[60] !== isCreateLinked || $[61] !== isLinked || $[62] !== isNonExistent || $[63] !== isPermissionsLoading || $[64] !== isReleaseLocked || $[65] !== liveEdit || $[66] !== onlyHasVersions || $[67] !== permissions?.granted || $[68] !== readOnlyProp || $[69] !== ready || $[70] !== releaseId || $[71] !== schemaType || $[72] !== selectedPerspectiveName || $[73] !== value ? (t23 = () => {
58335
+ $[58] !== connectionState || $[59] !== editState2 || $[60] !== isCreateLinked || $[61] !== isLockedByCanvas || $[62] !== isNonExistent || $[63] !== isPermissionsLoading || $[64] !== isReleaseLocked || $[65] !== liveEdit || $[66] !== onlyHasVersions || $[67] !== permissions?.granted || $[68] !== readOnlyProp || $[69] !== ready || $[70] !== releaseId || $[71] !== schemaType || $[72] !== selectedPerspectiveName || $[73] !== value ? (t23 = () => {
58335
58336
  const hasNoPermission = !isPermissionsLoading && !permissions?.granted, updateActionDisabled = !isActionEnabled(schemaType, "update"), createActionDisabled = isNonExistent && !isActionEnabled(schemaType, "create"), reconnecting = connectionState === "reconnecting", isLocked = editState2.transactionSyncLock?.enabled, willBeUnpublished = value ? isGoingToUnpublish(value) : !1;
58336
- return editState2.version && !editState2.draft && !editState2.published && onlyHasVersions && selectedPerspectiveName !== getVersionFromId(editState2.version._id) && isNewDocument(editState2) === !1 || liveEdit && editState2.draft?._id || !liveEdit && selectedPerspectiveName === "published" || releaseId && getVersionFromId(value._id) !== releaseId && isNewDocument(editState2) === !1 || !ready || isLinked || hasNoPermission || updateActionDisabled || createActionDisabled || reconnecting || isLocked || isCreateLinked || willBeUnpublished || isReleaseLocked ? !0 : typeof readOnlyProp == "function" ? readOnlyProp(editState2) : !!readOnlyProp;
58337
- }, $[58] = connectionState, $[59] = editState2, $[60] = isCreateLinked, $[61] = isLinked, $[62] = isNonExistent, $[63] = isPermissionsLoading, $[64] = isReleaseLocked, $[65] = liveEdit, $[66] = onlyHasVersions, $[67] = permissions?.granted, $[68] = readOnlyProp, $[69] = ready, $[70] = releaseId, $[71] = schemaType, $[72] = selectedPerspectiveName, $[73] = value, $[74] = t23) : t23 = $[74];
58337
+ return editState2.version && !editState2.draft && !editState2.published && onlyHasVersions && selectedPerspectiveName !== getVersionFromId(editState2.version._id) && isNewDocument(editState2) === !1 || liveEdit && editState2.draft?._id || !liveEdit && selectedPerspectiveName === "published" || releaseId && getVersionFromId(value._id) !== releaseId && isNewDocument(editState2) === !1 || !ready || isLockedByCanvas || hasNoPermission || updateActionDisabled || createActionDisabled || reconnecting || isLocked || isCreateLinked || willBeUnpublished || isReleaseLocked ? !0 : typeof readOnlyProp == "function" ? readOnlyProp(editState2) : !!readOnlyProp;
58338
+ }, $[58] = connectionState, $[59] = editState2, $[60] = isCreateLinked, $[61] = isLockedByCanvas, $[62] = isNonExistent, $[63] = isPermissionsLoading, $[64] = isReleaseLocked, $[65] = liveEdit, $[66] = onlyHasVersions, $[67] = permissions?.granted, $[68] = readOnlyProp, $[69] = ready, $[70] = releaseId, $[71] = schemaType, $[72] = selectedPerspectiveName, $[73] = value, $[74] = t23) : t23 = $[74];
58338
58339
  let t24;
58339
58340
  $[75] !== t23 ? (t24 = t23(), $[75] = t23, $[76] = t24) : t24 = $[76];
58340
58341
  const readOnly = t24, {
@@ -70956,7 +70957,7 @@ function getErrorMessage(err) {
70956
70957
  let message;
70957
70958
  return isClientError(err) ? err.response.statusCode === 403 ? message = FORBIDDEN_RESPONSE_TEXT : message = err.message : (err instanceof Error && (message = err.message), message = String(err)), message;
70958
70959
  }
70959
- const debug$5 = debugWithName$1("useScheduleOperation");
70960
+ const debug$7 = debugWithName$1("useScheduleOperation");
70960
70961
  function useScheduleApi() {
70961
70962
  const $ = c(3);
70962
70963
  let t0;
@@ -70976,7 +70977,7 @@ function createScheduleApi(client) {
70976
70977
  date,
70977
70978
  documentId
70978
70979
  }) {
70979
- debug$5("_create:", documentId);
70980
+ debug$7("_create:", documentId);
70980
70981
  const roundedDate = new Date(date);
70981
70982
  return roundedDate.setSeconds(0), roundedDate.setMilliseconds(0), client.request({
70982
70983
  body: {
@@ -70993,7 +70994,7 @@ function createScheduleApi(client) {
70993
70994
  function _delete({
70994
70995
  scheduleId
70995
70996
  }) {
70996
- return debug$5("_delete:", scheduleId), client.request({
70997
+ return debug$7("_delete:", scheduleId), client.request({
70997
70998
  method: "DELETE",
70998
70999
  uri: `/schedules/${projectId}/${dataset}/${scheduleId}`
70999
71000
  });
@@ -71001,7 +71002,7 @@ function createScheduleApi(client) {
71001
71002
  function _deleteMultiple({
71002
71003
  scheduleIds
71003
71004
  }) {
71004
- debug$5("_deleteMultiple:", scheduleIds);
71005
+ debug$7("_deleteMultiple:", scheduleIds);
71005
71006
  const requests = scheduleIds.map((scheduleId) => _delete({
71006
71007
  scheduleId
71007
71008
  }));
@@ -71010,7 +71011,7 @@ function createScheduleApi(client) {
71010
71011
  function _publish({
71011
71012
  scheduleId
71012
71013
  }) {
71013
- return debug$5("_publish:", scheduleId), client.request({
71014
+ return debug$7("_publish:", scheduleId), client.request({
71014
71015
  method: "POST",
71015
71016
  uri: `/schedules/${projectId}/${dataset}/${scheduleId}/publish`
71016
71017
  });
@@ -71019,7 +71020,7 @@ function createScheduleApi(client) {
71019
71020
  documentSchedule,
71020
71021
  scheduleId
71021
71022
  }) {
71022
- return debug$5("_update:", scheduleId, documentSchedule), client.request({
71023
+ return debug$7("_update:", scheduleId, documentSchedule), client.request({
71023
71024
  body: documentSchedule,
71024
71025
  method: "PATCH",
71025
71026
  uri: `/schedules/${projectId}/${dataset}/${scheduleId}`
@@ -73763,7 +73764,7 @@ const Schedules = (props2) => {
73763
73764
  function _temp$Q(schedule) {
73764
73765
  return /* @__PURE__ */ jsx(ScheduleItem, { schedule, type: "document" }, schedule.id);
73765
73766
  }
73766
- const debug$4 = debugWithName$1("ScheduleAction"), useScheduleAction = (props2) => {
73767
+ const debug$6 = debugWithName$1("ScheduleAction"), useScheduleAction = (props2) => {
73767
73768
  const $ = c(47), {
73768
73769
  draft,
73769
73770
  id: id2,
@@ -73799,7 +73800,7 @@ const debug$4 = debugWithName$1("ScheduleAction"), useScheduleAction = (props2)
73799
73800
  isInitialLoading,
73800
73801
  schedules: schedules2
73801
73802
  } = usePollSchedules(t1);
73802
- debug$4("schedules", schedules2);
73803
+ debug$6("schedules", schedules2);
73803
73804
  const hasExistingSchedules = schedules2 && schedules2.length > 0, documentExists = draft !== null || published !== null, insufficientPermissions = !isPermissionsLoading && !permissions?.granted;
73804
73805
  let t2;
73805
73806
  $[5] !== handleOpenDialog || $[6] !== mode ? (t2 = () => {
@@ -73864,7 +73865,7 @@ useScheduleAction.displayName = "ScheduleAction";
73864
73865
  function resolveDocumentActions(existingActions, context) {
73865
73866
  return context.versionType === "published" ? existingActions : existingActions.findIndex((a) => a.action === "publish") < 0 ? [useScheduleAction, ...existingActions] : existingActions.flatMap((action) => action.action === "publish" ? [action, useScheduleAction] : action);
73866
73867
  }
73867
- const debug$3 = debugWithName$1("ScheduledBadge"), useScheduledBadge = (props2) => {
73868
+ const debug$5 = debugWithName$1("ScheduledBadge"), useScheduledBadge = (props2) => {
73868
73869
  const $ = c(7);
73869
73870
  let t0;
73870
73871
  $[0] !== props2.id ? (t0 = {
@@ -73874,7 +73875,7 @@ const debug$3 = debugWithName$1("ScheduledBadge"), useScheduledBadge = (props2)
73874
73875
  const {
73875
73876
  schedules: schedules2
73876
73877
  } = usePollSchedules(t0);
73877
- debug$3("schedules", schedules2);
73878
+ debug$5("schedules", schedules2);
73878
73879
  const upcomingSchedule = schedules2?.[0];
73879
73880
  if (!upcomingSchedule || !upcomingSchedule.executeAt || !upcomingSchedule.action)
73880
73881
  return null;
@@ -78163,7 +78164,7 @@ class SchemaError extends Error {
78163
78164
  super("SchemaError"), this.schema = schema2, this.name = "SchemaError";
78164
78165
  }
78165
78166
  }
78166
- const debug$2 = debug$a("sanity:config"), TOGGLE$1 = "toggle.schema.upload-pause";
78167
+ const debug$4 = debug$c("sanity:config"), TOGGLE$1 = "toggle.schema.upload-pause";
78167
78168
  async function isEnabled$1(client) {
78168
78169
  if (typeof process < "u" && process?.env?.SANITY_STUDIO_SCHEMA_DESCRIPTOR)
78169
78170
  return !0;
@@ -78173,7 +78174,7 @@ async function isEnabled$1(client) {
78173
78174
  return projectId ? firstValueFrom(getFeatures({
78174
78175
  projectId,
78175
78176
  versionedClient: client
78176
- })).then((features2) => features2.includes(TOGGLE$1)).catch((err) => (debug$2("Fetching features failed. NOT sending schema to server.", {
78177
+ })).then((features2) => features2.includes(TOGGLE$1)).catch((err) => (debug$4("Fetching features failed. NOT sending schema to server.", {
78177
78178
  err
78178
78179
  }), !1)) : !1;
78179
78180
  }
@@ -78219,7 +78220,7 @@ async function uploadSchema(schema2, client) {
78219
78220
  }
78220
78221
  throw new Error(`Schema synchronization didn't succeed in ${MAX_SYNC_ITERATIONS} iterations`);
78221
78222
  }
78222
- const debug$1 = debug$a("sanity:config"), isError$1 = (p) => p.severity === "error";
78223
+ const debug$3 = debug$c("sanity:config"), isError$1 = (p) => p.severity === "error";
78223
78224
  function normalizeIcon$1(Icon2, title, subtitle = "") {
78224
78225
  return isValidElementType(Icon2) ? /* @__PURE__ */ jsx(Icon2, {}) : isValidElement(Icon2) ? Icon2 : createDefaultIcon(title, subtitle);
78225
78226
  }
@@ -78718,7 +78719,7 @@ function resolveSource$1({
78718
78719
  staticInitialValueTemplateItems,
78719
78720
  options: config,
78720
78721
  schemaDescriptorId: authenticated ? catchTap(uploadSchema(schema2, getClient2(DEFAULT_STUDIO_CLIENT_OPTIONS)), (err) => {
78721
- debug$1("Uploading schema failed", {
78722
+ debug$3("Uploading schema failed", {
78722
78723
  err
78723
78724
  });
78724
78725
  }) : Promise.resolve(void 0)
@@ -84833,7 +84834,7 @@ function GlobalPerspectiveProvider(t0) {
84833
84834
  let t4;
84834
84835
  return $[2] !== children || $[3] !== excludedPerspectives || $[4] !== selectedPerspectiveName ? (t4 = /* @__PURE__ */ jsx(PerspectiveProvider, { selectedPerspectiveName, excludedPerspectives, children }), $[2] = children, $[3] = excludedPerspectives, $[4] = selectedPerspectiveName, $[5] = t4) : t4 = $[5], t4;
84835
84836
  }
84836
- const debug = debug$a("sanity:store"), TOGGLE = "toggle.user-application.upload-live-manifest";
84837
+ const debug$2 = debug$c("sanity:store"), TOGGLE = "toggle.user-application.upload-live-manifest";
84837
84838
  async function isEnabled(client) {
84838
84839
  if (typeof process < "u" && process?.env?.SANITY_STUDIO_USER_APPLICATION_CACHE)
84839
84840
  return !0;
@@ -84843,52 +84844,47 @@ async function isEnabled(client) {
84843
84844
  return projectId ? firstValueFrom(getFeatures({
84844
84845
  projectId,
84845
84846
  versionedClient: client
84846
- })).then((features2) => features2.includes(TOGGLE)).catch((err) => (debug(`Fetching features failed. User applications cache not enabled for project ${projectId}.`, {
84847
+ })).then((features2) => features2.includes(TOGGLE)).catch((err) => (debug$2(`Fetching features failed. User applications cache not enabled for project ${projectId}.`, {
84847
84848
  err
84848
84849
  }), !1)) : !1;
84849
84850
  }
84850
- function createUserApplicationCache(client) {
84851
+ function createUserApplicationCache() {
84851
84852
  const appCache = {}, projectIndex = {};
84852
84853
  return {
84853
- get: async (projectId, apiHost) => {
84854
+ get: async (client) => {
84855
+ const {
84856
+ projectId
84857
+ } = client.config();
84858
+ if (projectId === void 0)
84859
+ return [];
84854
84860
  const existingIndex = projectIndex[projectId];
84855
84861
  if (existingIndex) {
84856
84862
  const appIds = await existingIndex;
84857
84863
  return Promise.all(appIds.map((id2) => appCache[id2]));
84858
84864
  }
84859
- const targetHost = typeof apiHost > "u" ? "https://api.sanity.io" : apiHost, projectClient = client.withConfig({
84860
- projectId,
84861
- apiHost: targetHost
84862
- });
84865
+ const projectClient = client.withConfig(DEFAULT_STUDIO_CLIENT_OPTIONS);
84863
84866
  if (!await isEnabled(projectClient))
84864
84867
  return [];
84865
84868
  const promise = projectClient.request({
84866
84869
  method: "GET",
84867
84870
  url: `/projects/${projectId}/user-applications`,
84868
84871
  tag: "user-application-cache.fetch-user-applications"
84869
- }).then((apps) => {
84870
- const appsWithApiHost = apps.map((app) => {
84871
- const appWithApiHost = {
84872
- ...app,
84873
- apiHost: targetHost
84874
- };
84875
- return appCache[app.id] = appWithApiHost, appWithApiHost;
84876
- });
84877
- return projectIndex[projectId] = appsWithApiHost.map((app) => app.id), appsWithApiHost;
84878
- }).catch(() => (delete projectIndex[projectId], []));
84872
+ }).then((apps) => (projectIndex[projectId] = apps.map((app) => (appCache[app.id] = app, app.id)), apps)).catch((err) => (debug$2("Fetching user application failed.", {
84873
+ err
84874
+ }), delete projectIndex[projectId], []));
84879
84875
  return projectIndex[projectId] = promise.then((apps) => apps.map((app) => app.id)), promise;
84880
84876
  }
84881
84877
  };
84882
84878
  }
84883
84879
  function UserApplicationCacheProvider(t0) {
84884
- const $ = c(6), {
84880
+ const $ = c(5), {
84885
84881
  children
84886
- } = t0, client = useClient(DEFAULT_STUDIO_CLIENT_OPTIONS), parentCache = useContext(UserApplicationCacheContext);
84882
+ } = t0, parentCache = useContext(UserApplicationCacheContext);
84887
84883
  let t1;
84888
- $[0] !== client || $[1] !== parentCache ? (t1 = parentCache || createUserApplicationCache(client), $[0] = client, $[1] = parentCache, $[2] = t1) : t1 = $[2];
84884
+ $[0] !== parentCache ? (t1 = parentCache || createUserApplicationCache(), $[0] = parentCache, $[1] = t1) : t1 = $[1];
84889
84885
  const cache2 = t1;
84890
84886
  let t2;
84891
- return $[3] !== cache2 || $[4] !== children ? (t2 = /* @__PURE__ */ jsx(UserApplicationCacheContext.Provider, { value: cache2, children }), $[3] = cache2, $[4] = children, $[5] = t2) : t2 = $[5], t2;
84887
+ return $[2] !== cache2 || $[3] !== children ? (t2 = /* @__PURE__ */ jsx(UserApplicationCacheContext.Provider, { value: cache2, children }), $[2] = cache2, $[3] = children, $[4] = t2) : t2 = $[4], t2;
84892
84888
  }
84893
84889
  function useUserApplicationCache() {
84894
84890
  const cache2 = useContext(UserApplicationCacheContext);
@@ -84973,9 +84969,8 @@ function sanitizePath(path) {
84973
84969
  return path.replace(/^\/+/, "/");
84974
84970
  }
84975
84971
  const ComlinkRouteHandler = () => (useComlinkRouteHandler(), null);
84976
- function getAppUrl(app) {
84977
- const internalUrlSuffix2 = app.apiHost !== void 0 && app.apiHost.includes("sanity.work") ? "studio.sanity.work" : "sanity.studio";
84978
- return app.urlType === "internal" ? `https://${app.appHost}.${internalUrlSuffix2}` : app.appHost;
84972
+ function getAppUrl(app, internalHost) {
84973
+ return app.urlType === "internal" ? `https://${app.appHost}.${internalHost}` : app.appHost;
84979
84974
  }
84980
84975
  function currentUrlMatchesApp({
84981
84976
  origin,
@@ -84987,21 +84982,18 @@ function currentUrlMatchesApp({
84987
84982
  return pathname === appPathname ? !0 : pathname.startsWith(appPathname.endsWith("/") ? appPathname : `${appPathname}/`);
84988
84983
  }
84989
84984
  async function findUserApplication(cache2, workspaces) {
84990
- if (typeof window > "u" || !window.location)
84985
+ if (typeof window > "u" || !window.location || workspaces.length === 0)
84991
84986
  return;
84992
- const entities = Array.from(new Map(workspaces.map((ws) => [ws.projectId, {
84993
- projectId: ws.projectId,
84994
- apiHost: ws.apiHost
84995
- }])).values());
84996
- return (await Promise.all(entities.map((e) => cache2.get(e.projectId, e.apiHost)))).flat().reduce((best, app) => {
84997
- const appUrl = getAppUrl(app);
84998
- if (appUrl && currentUrlMatchesApp(window.location, appUrl)) {
84999
- const bestUrl = best ? getAppUrl(best) : "";
85000
- return appUrl.length > bestUrl.length ? app : best;
85001
- }
85002
- return best;
85003
- }, void 0);
84987
+ const workspace = workspaces[0], state = await firstValueFrom(workspace.auth.state);
84988
+ if (!state.authenticated)
84989
+ return;
84990
+ let internalHost = "sanity.studio";
84991
+ return workspace.apiHost !== void 0 && workspace.apiHost.includes("sanity.work") && (internalHost = "studio.sanity.work"), (await cache2.get(state.client)).reduce((best, app) => {
84992
+ const appUrl = getAppUrl(app, internalHost);
84993
+ return appUrl && currentUrlMatchesApp(window.location, appUrl) && appUrl.length > best[1].length ? [app, appUrl] : best;
84994
+ }, [void 0, ""])[0];
85004
84995
  }
84996
+ const debug$1 = debug$c("studio:live-user-application");
85005
84997
  function LiveUserApplicationProvider(t0) {
85006
84998
  const $ = c(9), {
85007
84999
  children
@@ -85012,7 +85004,7 @@ function LiveUserApplicationProvider(t0) {
85012
85004
  return findUserApplication(userApplicationCache, workspaces).then((found) => {
85013
85005
  hasSubscriber && setUserApplication(found);
85014
85006
  }).catch((error) => {
85015
- console.error("Error when determining live user application id:", error), hasSubscriber && setUserApplication(void 0);
85007
+ debug$1("Error when determining live user application id:", error), hasSubscriber && setUserApplication(void 0);
85016
85008
  }), () => {
85017
85009
  hasSubscriber = !1;
85018
85010
  };
@@ -85360,19 +85352,21 @@ async function generateStudioManifest(workspaces, theme) {
85360
85352
  workspaces: workspaceManifests.filter((config) => config !== null)
85361
85353
  };
85362
85354
  }
85363
- async function registerStudioManifest(client, userApplication, workspaces, theme) {
85355
+ async function registerStudioManifest(userApplication, workspaces, theme) {
85356
+ const {
85357
+ id: id2,
85358
+ projectId
85359
+ } = userApplication, workspace = workspaces.find((ws) => ws.projectId === projectId);
85360
+ if (!workspace)
85361
+ return;
85364
85362
  const liveManifest = await generateStudioManifest(workspaces, theme);
85365
85363
  if (liveManifest.workspaces.length === 0)
85366
85364
  return;
85367
85365
  const {
85368
- id: id2,
85369
- projectId,
85370
- apiHost
85371
- } = userApplication;
85372
- await client.withConfig({
85373
- projectId,
85374
- apiHost
85375
- }).request({
85366
+ client,
85367
+ authenticated
85368
+ } = await firstValueFrom(workspace.auth.state);
85369
+ authenticated && await client.withConfig(DEFAULT_STUDIO_CLIENT_OPTIONS).request({
85376
85370
  method: "POST",
85377
85371
  uri: `/projects/${projectId}/user-applications/${id2}/config/live-manifest`,
85378
85372
  body: {
@@ -85381,19 +85375,20 @@ async function registerStudioManifest(client, userApplication, workspaces, theme
85381
85375
  tag: "live-manifest-register"
85382
85376
  });
85383
85377
  }
85378
+ const debug = debug$c("sanity:manifest");
85384
85379
  function LiveManifestRegisterProvider() {
85385
- const $ = c(6), client = useClient(DEFAULT_STUDIO_CLIENT_OPTIONS), workspaces = useWorkspaces(), {
85380
+ const $ = c(5), workspaces = useWorkspaces(), {
85386
85381
  userApplication
85387
85382
  } = useLiveUserApplication(), {
85388
85383
  theme
85389
85384
  } = useRootTheme();
85390
85385
  let t0, t1;
85391
- return $[0] !== client || $[1] !== theme || $[2] !== userApplication || $[3] !== workspaces ? (t0 = () => {
85392
- !userApplication || workspaces.length === 0 || registerStudioManifest(client, userApplication, workspaces, theme).catch(_temp$d);
85393
- }, t1 = [client, userApplication, workspaces, theme], $[0] = client, $[1] = theme, $[2] = userApplication, $[3] = workspaces, $[4] = t0, $[5] = t1) : (t0 = $[4], t1 = $[5]), useEffect(t0, t1), null;
85386
+ return $[0] !== theme || $[1] !== userApplication || $[2] !== workspaces ? (t0 = () => {
85387
+ !userApplication || workspaces.length === 0 || registerStudioManifest(userApplication, workspaces, theme).catch(_temp$d);
85388
+ }, t1 = [userApplication, workspaces, theme], $[0] = theme, $[1] = userApplication, $[2] = workspaces, $[3] = t0, $[4] = t1) : (t0 = $[3], t1 = $[4]), useEffect(t0, t1), null;
85394
85389
  }
85395
85390
  function _temp$d(err) {
85396
- console.error("Failed to upload studio manifest", err);
85391
+ debug("Failed to upload studio manifest", err);
85397
85392
  }
85398
85393
  const CONSENT_CLIENT_OPTIONS = {
85399
85394
  apiVersion: "2023-12-18"
@@ -87475,20 +87470,24 @@ function StudioProvider(t0) {
87475
87470
  } = t0;
87476
87471
  errorReporter.initialize();
87477
87472
  let t1;
87478
- $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = /* @__PURE__ */ jsx(MaybeEnableErrorReporting, { errorReporter }), $[0] = t1) : t1 = $[0];
87479
- let t2, t3;
87480
- $[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsx(LiveManifestRegisterProvider, {}), t3 = /* @__PURE__ */ jsx(ComlinkRouteHandler, {}), $[1] = t2, $[2] = t3) : (t2 = $[1], t3 = $[2]);
87473
+ $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = /* @__PURE__ */ jsx(LiveManifestRegisterProvider, {}), $[0] = t1) : t1 = $[0];
87474
+ let t2;
87475
+ $[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = /* @__PURE__ */ jsx(MaybeEnableErrorReporting, { errorReporter }), $[1] = t2) : t2 = $[1];
87476
+ let t3;
87477
+ $[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = /* @__PURE__ */ jsx(ComlinkRouteHandler, {}), $[2] = t3) : t3 = $[2];
87481
87478
  let t4;
87482
87479
  $[3] !== children ? (t4 = /* @__PURE__ */ jsx(LocaleProvider, { children: /* @__PURE__ */ jsxs(PackageVersionStatusProvider, { children: [
87483
- t1,
87484
- /* @__PURE__ */ jsx(ResourceCacheProvider, { children: /* @__PURE__ */ jsx(UserApplicationCacheProvider, { children: /* @__PURE__ */ jsx(AppIdCacheProvider, { children: /* @__PURE__ */ jsxs(LiveUserApplicationProvider, { children: [
87485
- t2,
87480
+ t2,
87481
+ /* @__PURE__ */ jsx(ResourceCacheProvider, { children: /* @__PURE__ */ jsxs(AppIdCacheProvider, { children: [
87486
87482
  t3,
87487
87483
  /* @__PURE__ */ jsx(StudioAnnouncementsProvider, { children: /* @__PURE__ */ jsx(GlobalPerspectiveProvider, { children: /* @__PURE__ */ jsx(DocumentLimitUpsellProvider, { children: /* @__PURE__ */ jsx(AssetLimitUpsellProvider, { children }) }) }) })
87488
- ] }) }) }) })
87484
+ ] }) })
87489
87485
  ] }) }), $[3] = children, $[4] = t4) : t4 = $[4];
87490
87486
  let t5;
87491
- $[5] !== config || $[6] !== t4 ? (t5 = /* @__PURE__ */ jsx(WorkspaceLoaderBoundary, { LoadingComponent: LoadingBlock, ConfigErrorsComponent: ConfigErrorsScreen, children: /* @__PURE__ */ jsx(StudioTelemetryProvider, { config, children: t4 }) }), $[5] = config, $[6] = t4, $[7] = t5) : t5 = $[7];
87487
+ $[5] !== config || $[6] !== t4 ? (t5 = /* @__PURE__ */ jsx(UserApplicationCacheProvider, { children: /* @__PURE__ */ jsxs(LiveUserApplicationProvider, { children: [
87488
+ t1,
87489
+ /* @__PURE__ */ jsx(WorkspaceLoaderBoundary, { LoadingComponent: LoadingBlock, ConfigErrorsComponent: ConfigErrorsScreen, children: /* @__PURE__ */ jsx(StudioTelemetryProvider, { config, children: t4 }) })
87490
+ ] }) }), $[5] = config, $[6] = t4, $[7] = t5) : t5 = $[7];
87492
87491
  const _children = t5;
87493
87492
  let t6;
87494
87493
  $[8] !== _children || $[9] !== noAuthBoundary ? (t6 = /* @__PURE__ */ jsx(StudioThemeProvider, { children: /* @__PURE__ */ jsx(UserColorManagerProvider, { children: noAuthBoundary ? _children : /* @__PURE__ */ jsx(AuthBoundary, { LoadingComponent: LoadingBlock, AuthenticateComponent: AuthenticateScreen, NotAuthenticatedComponent: NotAuthenticatedScreen, children: _children }) }) }), $[8] = _children, $[9] = noAuthBoundary, $[10] = t6) : t6 = $[10];