sanity 6.3.0-next.35 → 6.3.0-next.37
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.
|
@@ -1141,6 +1141,7 @@ interface DocumentPreviewStore {
|
|
|
1141
1141
|
* transitions on the received listener events.
|
|
1142
1142
|
* This provides a lightweight way of subscribing to a list of ids for simple cases where you just want to subscribe to a set of documents ids
|
|
1143
1143
|
* that matches a particular filter.
|
|
1144
|
+
*
|
|
1144
1145
|
* @hidden
|
|
1145
1146
|
* @beta
|
|
1146
1147
|
* @param filter - A groq filter to use for the document set
|
|
@@ -1155,14 +1156,30 @@ interface DocumentPreviewStore {
|
|
|
1155
1156
|
insert?: 'sorted' | 'prepend' | 'append';
|
|
1156
1157
|
apiVersion?: string;
|
|
1157
1158
|
}) => Observable<DocumentIdSetObserverState>;
|
|
1159
|
+
/**
|
|
1160
|
+
* Observes the set of version and variant document ids that exist for a given
|
|
1161
|
+
* document group id.
|
|
1162
|
+
*
|
|
1163
|
+
* Unlike `unstable_observeDocumentIdSet`, this does not open a dedicated
|
|
1164
|
+
* real-time listener for each published id. Instead, it is driven by the
|
|
1165
|
+
* shared global listener and batches the discovery queries for all observed
|
|
1166
|
+
* document group ids into a single combined query, returning the ids in
|
|
1167
|
+
* ascending order.
|
|
1168
|
+
*
|
|
1169
|
+
* @hidden
|
|
1170
|
+
* @beta
|
|
1171
|
+
*/
|
|
1172
|
+
unstable_observeVersionDocumentIds: (publishedId: string) => Observable<string[]>;
|
|
1158
1173
|
/**
|
|
1159
1174
|
* Observe a complete document with the given ID
|
|
1175
|
+
*
|
|
1160
1176
|
* @hidden
|
|
1161
1177
|
* @beta
|
|
1162
1178
|
*/
|
|
1163
1179
|
unstable_observeDocument: (id: string, clientConfig?: ObserveDocumentAPIConfig) => Observable<SanityDocument | undefined>;
|
|
1164
1180
|
/**
|
|
1165
1181
|
* Observe a list of complete documents with the given IDs
|
|
1182
|
+
*
|
|
1166
1183
|
* @hidden
|
|
1167
1184
|
* @beta
|
|
1168
1185
|
*/
|
package/lib/_chunks-es/index2.js
CHANGED
|
@@ -12,7 +12,7 @@ import { styled, css, useTheme as useTheme$1, keyframes, createGlobalStyle } fro
|
|
|
12
12
|
import { EllipsisHorizontalIcon, ErrorOutlineIcon, ArrowLeftIcon, WarningOutlineIcon, CircleIcon, CalendarIcon, UnpublishIcon, PublishIcon, EditIcon, CloseIcon, TrashIcon, AddCircleIcon, TimelineIcon, ChevronRightIcon, ArrowRightIcon, ArrowDownIcon, DocumentIcon, ImageIcon, ChevronDownIcon, RevertIcon, InfoOutlineIcon, CheckmarkIcon, AddIcon, HelpCircleIcon, AccessDeniedIcon, ToggleArrowRightIcon, SyncIcon, LaunchIcon, BulbOutlineIcon, UnknownIcon, LinkIcon, ChevronUpIcon, DownloadIcon, DocumentsIcon, UploadIcon, DragHandleIcon, InsertAboveIcon, InsertBelowIcon, CopyIcon, AddDocumentIcon, SearchIcon, ChevronLeftIcon, EarthGlobeIcon, EarthAmericasIcon, UlistIcon, OlistIcon, CodeIcon, UnderlineIcon, StrikethroughIcon, ItalicIcon, BoldIcon, BlockElementIcon, InlineElementIcon, CollapseIcon, ExpandIcon, ResetIcon, Icon, ReadOnlyIcon, BinaryDocumentIcon, LockIcon, CropIcon, EyeOpenIcon, ClockIcon, DotIcon, BoltIcon, ComposeSparklesIcon, UnlockIcon, ClipboardIcon, CheckmarkCircleIcon, StringIcon, NumberIcon, BlockContentIcon, UndoIcon, UnlinkIcon, LinkRemovedIcon, CommentIcon, TaskIcon, DesktopIcon, MoonIcon, SunIcon, SpinnerIcon, ControlsIcon, SortIcon, SparkleIcon, EyeClosedIcon, DoubleChevronRightIcon, AddUserIcon, CogIcon, LeaveIcon, UsersIcon, FaceHappyIcon, FaceIndifferentIcon, FaceSadIcon, FeedbackIcon, GithubIcon, RefreshIcon, MenuIcon, UserIcon } from "@sanity/icons";
|
|
13
13
|
import { createMemoryHistory, createBrowserHistory } from "history";
|
|
14
14
|
import { of, concat, defer, EMPTY as EMPTY$5, map as map$1, merge, defaultIfEmpty, catchError as catchError$1, switchMap as switchMap$1, take, concatMap, from, Observable, BehaviorSubject, fromEvent, skip, ReplaySubject, timer, firstValueFrom, throwError, NEVER, Subject, tap as tap$1, finalize, share as share$1, combineLatest, asyncScheduler, bufferTime, mergeMap as mergeMap$1, filter as filter$1, lastValueFrom, partition as partition$1, distinctUntilChanged as distinctUntilChanged$1, asapScheduler, using, repeat, scan as scan$1, shareReplay as shareReplay$1, pipe, iif, startWith as startWith$1, concatWith, count, toArray as toArray$2, reduce as reduce$1, switchScan, delayWhen, first as first$1, zipWith, takeWhile, debounceTime as debounceTime$1, find, zip, isObservable, retry, debounce as debounce$1, delay as delay$1, timeout as timeout$1, connect, forkJoin } from "rxjs";
|
|
15
|
-
import { catchError, tap, switchMap, map, scan, distinctUntilChanged, startWith, shareReplay, mergeMap, filter, share, mergeMapTo, takeUntil, take as take$1, publishReplay, refCount, withLatestFrom, concatMap as concatMap$1, groupBy as groupBy$1, throttleTime, last, mergeAll, toArray as toArray$1, distinct, skip as skip$1, first, debounceTime, auditTime, switchMapTo, delay, reduce as reduce$2, finalize as finalize$1, expand, mapTo, debounce as debounce$2, retry as retry$1, timeout } from "rxjs/operators";
|
|
15
|
+
import { catchError, tap, switchMap, map, scan, distinctUntilChanged, startWith, shareReplay, mergeMap, filter, share, mergeMapTo, takeUntil, take as take$1, publishReplay, refCount, withLatestFrom, concatMap as concatMap$1, groupBy as groupBy$1, throttleTime, last, mergeAll, toArray as toArray$1, distinct, skip as skip$1, first, debounceTime, auditTime, switchMapTo, delay, reduce as reduce$2, finalize as finalize$1, bufferWhen, expand, mapTo, debounce as debounce$2, retry as retry$1, timeout } from "rxjs/operators";
|
|
16
16
|
import { useObservable, useObservableEvent } from "react-rx";
|
|
17
17
|
import { getVersionId, getDraftId, getPublishedId, isPublishedId, isDraftId, getVersionFromId, isVersionId, DRAFTS_FOLDER } from "@sanity/client/csm";
|
|
18
18
|
import { tz, TZDate } from "@date-fns/tz";
|
|
@@ -26010,7 +26010,7 @@ const PER_PAGE = 200, ASSET_TYPE_IMAGE = "sanity.imageAsset", ASSET_TYPE_FILE =
|
|
|
26010
26010
|
extension in [${typesForFilter.extensions}] ||
|
|
26011
26011
|
mimeType in [${typesForFilter.mimes}]
|
|
26012
26012
|
)`;
|
|
26013
|
-
}, buildQuery = (start = 0, end = PER_PAGE, assetType = ASSET_TYPE_IMAGE, acceptParam) => {
|
|
26013
|
+
}, buildQuery$1 = (start = 0, end = PER_PAGE, assetType = ASSET_TYPE_IMAGE, acceptParam) => {
|
|
26014
26014
|
const filterCondition = acceptParam.length > 0 ? buildFilterQuery(acceptParam) : "";
|
|
26015
26015
|
return `
|
|
26016
26016
|
*[_type == "${assetType}" ${filterCondition}] | order(_updatedAt desc) [${start}...${end}] {
|
|
@@ -26050,7 +26050,7 @@ const PER_PAGE = 200, ASSET_TYPE_IMAGE = "sanity.imageAsset", ASSET_TYPE_FILE =
|
|
|
26050
26050
|
let t3;
|
|
26051
26051
|
$[3] !== accept || $[4] !== assetType || $[5] !== versionedClient2 ? (t3 = (pageNumber) => {
|
|
26052
26052
|
const start = pageNumber * PER_PAGE, end = start + PER_PAGE, isImageAssetType = assetType === "image", tag = isImageAssetType ? "asset.image-list" : "asset.file-list", assetTypeParam = isImageAssetType ? ASSET_TYPE_IMAGE : ASSET_TYPE_FILE;
|
|
26053
|
-
setIsLoading(!0), typeof accept < "u" && (fetch$.current = versionedClient2.observable.fetch(buildQuery(start, end, assetTypeParam, accept), {}, {
|
|
26053
|
+
setIsLoading(!0), typeof accept < "u" && (fetch$.current = versionedClient2.observable.fetch(buildQuery$1(start, end, assetTypeParam, accept), {}, {
|
|
26054
26054
|
tag
|
|
26055
26055
|
}).subscribe((result) => {
|
|
26056
26056
|
setIsLastPage(result.length < PER_PAGE), setAssets((prevState) => prevState.concat(result)), setIsLoading(!1);
|
|
@@ -45982,6 +45982,68 @@ function createObserveFields(options) {
|
|
|
45982
45982
|
return objects.some((object) => fieldName in object ? (value = object[fieldName], !0) : !1), value;
|
|
45983
45983
|
}
|
|
45984
45984
|
}
|
|
45985
|
+
const VERSION_OF_QUERY_OVERHEAD = 29, MAX_CONCURRENT_BATCH_FETCHES = 10;
|
|
45986
|
+
function createObserveVersionDocumentIds(options) {
|
|
45987
|
+
const {
|
|
45988
|
+
client,
|
|
45989
|
+
invalidationChannel
|
|
45990
|
+
} = options, releasesClient = versionedClient(client, RELEASES_STUDIO_CLIENT_OPTIONS.apiVersion), fetchFast = debounceCollect((collectedArgs) => fetchVersionIdSets(releasesClient, collectedArgs), 100), fetchSlow = debounceCollect((collectedArgs) => fetchVersionIdSets(releasesClient, collectedArgs), 1e3), cache2 = /* @__PURE__ */ new Map();
|
|
45991
|
+
return function(documentGroupId) {
|
|
45992
|
+
const cachedInstance = cache2.get(documentGroupId);
|
|
45993
|
+
if (cachedInstance)
|
|
45994
|
+
return cachedInstance;
|
|
45995
|
+
const instance = invalidationChannel.pipe(filter((event) => event.type === "connected" || getPublishedId(event.documentId) === documentGroupId), switchMap((event) => event.type === "connected" || event.visibility === "query" ? fetchFast(documentGroupId).pipe(mergeMap((ids) => event.type === "mutation" && event.documentId !== documentGroupId && !ids.includes(event.documentId) ? concat(of(ids), fetchSlow(documentGroupId)) : of(ids))) : fetchSlow(documentGroupId)), distinctUntilChanged(isEqual$1), finalize$1(() => cache2.delete(documentGroupId)), shareReplay({
|
|
45996
|
+
refCount: !0,
|
|
45997
|
+
bufferSize: 1
|
|
45998
|
+
}));
|
|
45999
|
+
return cache2.set(documentGroupId, instance), instance;
|
|
46000
|
+
};
|
|
46001
|
+
}
|
|
46002
|
+
function bufferByByteSize(byteSize, maxBytes) {
|
|
46003
|
+
return (source) => {
|
|
46004
|
+
const closeBuffer = new Subject();
|
|
46005
|
+
let bufferedBytes = 0;
|
|
46006
|
+
return source.pipe(tap((value) => {
|
|
46007
|
+
const size = byteSize(value);
|
|
46008
|
+
bufferedBytes > 0 && bufferedBytes + size >= maxBytes && (bufferedBytes = 0, closeBuffer.next()), bufferedBytes += size;
|
|
46009
|
+
}), bufferWhen(() => closeBuffer));
|
|
46010
|
+
};
|
|
46011
|
+
}
|
|
46012
|
+
function buildQuery(documentGroupIds) {
|
|
46013
|
+
return `[${documentGroupIds.map((id2) => `*[sanity::versionOf(${JSON.stringify(id2)})]._id`).join(",")}]`;
|
|
46014
|
+
}
|
|
46015
|
+
function fetchBatch(client, ids) {
|
|
46016
|
+
return client.observable.fetch(buildQuery(ids), {}, {
|
|
46017
|
+
tag: "preview.observe-version-ids"
|
|
46018
|
+
}).pipe(
|
|
46019
|
+
retry({
|
|
46020
|
+
delay: (_, attempt) => timer(Math.min(3e4, attempt * 1e3))
|
|
46021
|
+
}),
|
|
46022
|
+
// Sort each set ascending so consumers get a stable order.
|
|
46023
|
+
map((result) => result.map((versionIds) => [...versionIds].sort()))
|
|
46024
|
+
);
|
|
46025
|
+
}
|
|
46026
|
+
function fetchVersionIdSets(client, collectedArgs) {
|
|
46027
|
+
const documentGroupIds = collectedArgs.map(([documentGroupId]) => documentGroupId);
|
|
46028
|
+
return documentGroupIds.length === 0 ? of([]) : from(documentGroupIds).pipe(
|
|
46029
|
+
// Split into batches small enough that each combined query stays within the
|
|
46030
|
+
// max query size.
|
|
46031
|
+
bufferByByteSize((id2) => id2.length + VERSION_OF_QUERY_OVERHEAD, MAX_DOCUMENT_ID_CHUNK_SIZE),
|
|
46032
|
+
// Fetch batches in parallel, tracking each batch's position so results can
|
|
46033
|
+
// be reordered.
|
|
46034
|
+
mergeMap((batch, index) => fetchBatch(client, batch).pipe(map((result) => ({
|
|
46035
|
+
index,
|
|
46036
|
+
result
|
|
46037
|
+
}))), MAX_CONCURRENT_BATCH_FETCHES),
|
|
46038
|
+
toArray$1(),
|
|
46039
|
+
// Restore source order (parallel fetches may settle out of order), and
|
|
46040
|
+
// flatten the batch results back into a single array aligned with
|
|
46041
|
+
// `documentGroupIds`.
|
|
46042
|
+
map((settled) => settled.sort((a, b) => a.index - b.index).flatMap(({
|
|
46043
|
+
result
|
|
46044
|
+
}) => result))
|
|
46045
|
+
);
|
|
46046
|
+
}
|
|
45985
46047
|
function createDocumentPreviewStore({
|
|
45986
46048
|
client
|
|
45987
46049
|
}) {
|
|
@@ -46013,7 +46075,10 @@ function createDocumentPreviewStore({
|
|
|
46013
46075
|
_ref: id2
|
|
46014
46076
|
}, [DOCUMENT_SYSTEM_FIELD], apiConfig, perspective).pipe(map((res) => isRecord$4(res) && isRecord$4(res[DOCUMENT_SYSTEM_FIELD]) ? res[DOCUMENT_SYSTEM_FIELD] : void 0), distinctUntilChanged());
|
|
46015
46077
|
}
|
|
46016
|
-
const observeDocumentIdSet = createDocumentIdSetObserver(versionedClient2),
|
|
46078
|
+
const observeDocumentIdSet = createDocumentIdSetObserver(versionedClient2), observeVersionDocumentIds = createObserveVersionDocumentIds({
|
|
46079
|
+
client: versionedClient2,
|
|
46080
|
+
invalidationChannel
|
|
46081
|
+
}), observeForPreview = createPreviewObserver({
|
|
46017
46082
|
observeDocumentTypeFromId,
|
|
46018
46083
|
observePaths: observePaths2
|
|
46019
46084
|
}), observeDocumentStackAvailability = createDocumentStackAvailabilityObserver(versionedClient2, observePaths2), observeDocumentPairAvailability = createPreviewAvailabilityObserver(versionedClient2, observePaths2), observePathsDocumentPair = createObservePathsDocumentPair({
|
|
@@ -46026,6 +46091,7 @@ function createDocumentPreviewStore({
|
|
|
46026
46091
|
observeDocumentTypeFromId,
|
|
46027
46092
|
observeDocumentSystemFromId,
|
|
46028
46093
|
unstable_observeDocumentIdSet: observeDocumentIdSet,
|
|
46094
|
+
unstable_observeVersionDocumentIds: observeVersionDocumentIds,
|
|
46029
46095
|
unstable_observeDocument: observeDocument,
|
|
46030
46096
|
unstable_observeDocuments: (ids) => combineLatest(ids.map((id2) => observeDocument(id2))),
|
|
46031
46097
|
unstable_observeDocumentPairAvailability: observeDocumentPairAvailability,
|
|
@@ -46275,16 +46341,13 @@ function getOrCreateDocumentVersionsObservable(options) {
|
|
|
46275
46341
|
documentPreviewStore,
|
|
46276
46342
|
projectId,
|
|
46277
46343
|
dataset,
|
|
46278
|
-
publishedId
|
|
46279
|
-
params = void 0
|
|
46344
|
+
publishedId
|
|
46280
46345
|
} = options, cacheKey2 = `${projectId}-${dataset}-${publishedId}`, cachedObservable = observableCache.get(cacheKey2);
|
|
46281
46346
|
if (cachedObservable)
|
|
46282
46347
|
return cachedObservable;
|
|
46283
|
-
const newObservable = documentPreviewStore.
|
|
46284
|
-
apiVersion: RELEASES_STUDIO_CLIENT_OPTIONS.apiVersion
|
|
46285
|
-
}).pipe(swr(cacheKey2), map$1(({
|
|
46348
|
+
const newObservable = documentPreviewStore.unstable_observeVersionDocumentIds(publishedId).pipe(swr(cacheKey2), map$1(({
|
|
46286
46349
|
value
|
|
46287
|
-
}) => value
|
|
46350
|
+
}) => value), switchMap$1((documentIds) => {
|
|
46288
46351
|
if (documentIds.length === 0)
|
|
46289
46352
|
return of({
|
|
46290
46353
|
data: [],
|