@depup/sanity 5.17.1-depup.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.
Files changed (116) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +57 -0
  3. package/bin/sanity +209 -0
  4. package/changes.json +114 -0
  5. package/lib/_chunks-dts/ActiveWorkspaceMatcherContext.d.ts +16164 -0
  6. package/lib/_chunks-dts/index.d.ts +780 -0
  7. package/lib/_chunks-dts/types.d.ts +2765 -0
  8. package/lib/_chunks-dts/types2.d.ts +656 -0
  9. package/lib/_chunks-dts/types3.d.ts +303 -0
  10. package/lib/_chunks-es/BroadcastDisplayedDocument.js +20 -0
  11. package/lib/_chunks-es/BroadcastDisplayedDocument.js.map +1 -0
  12. package/lib/_chunks-es/DisplayedDocumentBroadcaster.js +32 -0
  13. package/lib/_chunks-es/DisplayedDocumentBroadcaster.js.map +1 -0
  14. package/lib/_chunks-es/LiveQueries.js +339 -0
  15. package/lib/_chunks-es/LiveQueries.js.map +1 -0
  16. package/lib/_chunks-es/MenuGroup.js +106 -0
  17. package/lib/_chunks-es/MenuGroup.js.map +1 -0
  18. package/lib/_chunks-es/PostMessageDocuments.js +72 -0
  19. package/lib/_chunks-es/PostMessageDocuments.js.map +1 -0
  20. package/lib/_chunks-es/PostMessagePerspective.js +23 -0
  21. package/lib/_chunks-es/PostMessagePerspective.js.map +1 -0
  22. package/lib/_chunks-es/PostMessagePreviewSnapshots.js +69 -0
  23. package/lib/_chunks-es/PostMessagePreviewSnapshots.js.map +1 -0
  24. package/lib/_chunks-es/PostMessageRefreshMutations.js +74 -0
  25. package/lib/_chunks-es/PostMessageRefreshMutations.js.map +1 -0
  26. package/lib/_chunks-es/PostMessageSchema.js +502 -0
  27. package/lib/_chunks-es/PostMessageSchema.js.map +1 -0
  28. package/lib/_chunks-es/PostMessageTelemetry.js +21 -0
  29. package/lib/_chunks-es/PostMessageTelemetry.js.map +1 -0
  30. package/lib/_chunks-es/PresentationToolGrantsCheck.js +3848 -0
  31. package/lib/_chunks-es/PresentationToolGrantsCheck.js.map +1 -0
  32. package/lib/_chunks-es/QRCodeSVG.js +692 -0
  33. package/lib/_chunks-es/QRCodeSVG.js.map +1 -0
  34. package/lib/_chunks-es/StructureToolProvider.js +2360 -0
  35. package/lib/_chunks-es/StructureToolProvider.js.map +1 -0
  36. package/lib/_chunks-es/VideoPlayer.js +22 -0
  37. package/lib/_chunks-es/VideoPlayer.js.map +1 -0
  38. package/lib/_chunks-es/ViteDevServerStopped.js +52 -0
  39. package/lib/_chunks-es/ViteDevServerStopped.js.map +1 -0
  40. package/lib/_chunks-es/index.js +285 -0
  41. package/lib/_chunks-es/index.js.map +1 -0
  42. package/lib/_chunks-es/index2.js +105 -0
  43. package/lib/_chunks-es/index2.js.map +1 -0
  44. package/lib/_chunks-es/index3.js +139 -0
  45. package/lib/_chunks-es/index3.js.map +1 -0
  46. package/lib/_chunks-es/index4.js +1020 -0
  47. package/lib/_chunks-es/index4.js.map +1 -0
  48. package/lib/_chunks-es/pane.js +5 -0
  49. package/lib/_chunks-es/pane.js.map +1 -0
  50. package/lib/_chunks-es/pane2.js +5 -0
  51. package/lib/_chunks-es/pane2.js.map +1 -0
  52. package/lib/_chunks-es/presentation.js +549 -0
  53. package/lib/_chunks-es/presentation.js.map +1 -0
  54. package/lib/_chunks-es/resources.js +303 -0
  55. package/lib/_chunks-es/resources.js.map +1 -0
  56. package/lib/_chunks-es/resources2.js +459 -0
  57. package/lib/_chunks-es/resources2.js.map +1 -0
  58. package/lib/_chunks-es/resources3.js +281 -0
  59. package/lib/_chunks-es/resources3.js.map +1 -0
  60. package/lib/_chunks-es/resources4.js +184 -0
  61. package/lib/_chunks-es/resources4.js.map +1 -0
  62. package/lib/_chunks-es/resources5.js +161 -0
  63. package/lib/_chunks-es/resources5.js.map +1 -0
  64. package/lib/_chunks-es/resources6.js +141 -0
  65. package/lib/_chunks-es/resources6.js.map +1 -0
  66. package/lib/_chunks-es/resources7.js +24 -0
  67. package/lib/_chunks-es/resources7.js.map +1 -0
  68. package/lib/_chunks-es/resources8.js +603 -0
  69. package/lib/_chunks-es/resources8.js.map +1 -0
  70. package/lib/_chunks-es/resources9.js +126 -0
  71. package/lib/_chunks-es/resources9.js.map +1 -0
  72. package/lib/_chunks-es/structureTool.js +13673 -0
  73. package/lib/_chunks-es/structureTool.js.map +1 -0
  74. package/lib/_chunks-es/version.js +17 -0
  75. package/lib/_chunks-es/version.js.map +1 -0
  76. package/lib/_createContext.d.ts +12 -0
  77. package/lib/_createContext.js +38 -0
  78. package/lib/_createContext.js.map +1 -0
  79. package/lib/_internal.d.ts +9 -0
  80. package/lib/_internal.js +12 -0
  81. package/lib/_internal.js.map +1 -0
  82. package/lib/_singletons.d.ts +951 -0
  83. package/lib/_singletons.js +284 -0
  84. package/lib/_singletons.js.map +1 -0
  85. package/lib/cli.d.ts +3 -0
  86. package/lib/cli.js +9 -0
  87. package/lib/cli.js.map +1 -0
  88. package/lib/desk.d.ts +910 -0
  89. package/lib/desk.js +71 -0
  90. package/lib/desk.js.map +1 -0
  91. package/lib/index.d.ts +4 -0
  92. package/lib/index.js +92934 -0
  93. package/lib/index.js.map +1 -0
  94. package/lib/media-library.d.ts +85 -0
  95. package/lib/media-library.js +11 -0
  96. package/lib/media-library.js.map +1 -0
  97. package/lib/migrate.d.ts +1 -0
  98. package/lib/migrate.js +2 -0
  99. package/lib/migrate.js.map +1 -0
  100. package/lib/presentation.d.ts +28 -0
  101. package/lib/presentation.js +10 -0
  102. package/lib/presentation.js.map +1 -0
  103. package/lib/router.d.ts +560 -0
  104. package/lib/router.js +777 -0
  105. package/lib/router.js.map +1 -0
  106. package/lib/structure.d.ts +3 -0
  107. package/lib/structure.js +639 -0
  108. package/lib/structure.js.map +1 -0
  109. package/mock-browser-env-stub-loader.mjs +27 -0
  110. package/package.json +383 -0
  111. package/static/favicons/apple-touch-icon.png +0 -0
  112. package/static/favicons/favicon-192.png +0 -0
  113. package/static/favicons/favicon-512.png +0 -0
  114. package/static/favicons/favicon-96.png +0 -0
  115. package/static/favicons/favicon.ico +0 -0
  116. package/static/favicons/favicon.svg +12 -0
@@ -0,0 +1,1020 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { c } from "react/compiler-runtime";
3
+ import { useState, useEffect, memo, useRef, Fragment } from "react";
4
+ import { isRecord, useDocumentStore, useTranslation, usePerspective, useEditState, useSchema, useValuePreview, _isCustomDocumentTypeDefinition, useWorkspace, SourceProvider } from "sanity";
5
+ import { generateHelpUrl, Button, ErrorBoundary } from "./index.js";
6
+ import { assignId, LOADING_PANE, useStructureTool, useDocumentLastRev, PaneLayout, LoadingPane, StructureToolPane, setActivePanes } from "./structureTool.js";
7
+ import { structureLocaleNamespace, SerializeError, StructureToolProvider } from "./StructureToolProvider.js";
8
+ import { useRouter, useRouterState } from "sanity/router";
9
+ import omit from "lodash-es/omit.js";
10
+ import { isObservable, from, of, firstValueFrom, NEVER, concat, ReplaySubject } from "rxjs";
11
+ import { switchMap, publishReplay, refCount, map, startWith, pairwise, scan, distinctUntilChanged } from "rxjs/operators";
12
+ import isEqual from "lodash-es/isEqual.js";
13
+ import "nanoid";
14
+ import { ResolvedPanesProvider } from "sanity/_singletons";
15
+ import { uuid } from "@sanity/uuid";
16
+ import { SyncIcon, WarningOutlineIcon } from "@sanity/icons";
17
+ import { Stack, Text, Code, Box, Card, Container, Heading, Flex, useToast, useTheme, PortalProvider } from "@sanity/ui";
18
+ import { styled } from "styled-components";
19
+ import "react-i18next";
20
+ import "lodash-es/camelCase.js";
21
+ import "speakingurl";
22
+ import "react-is";
23
+ import "lodash-es/uniqueId.js";
24
+ import "lodash-es/uniq.js";
25
+ import "lodash-es/kebabCase.js";
26
+ import "lodash-es/find.js";
27
+ import "lodash-es/startCase.js";
28
+ import { isHotkey } from "is-hotkey-esm";
29
+ class PaneResolutionError extends Error {
30
+ constructor({
31
+ message,
32
+ context,
33
+ helpId,
34
+ cause
35
+ }) {
36
+ super(message), this.name = "PaneResolutionError", this.context = context, this.helpId = helpId, this.cause = cause;
37
+ }
38
+ }
39
+ const isPromise = (thing) => !!thing && typeof thing?.then == "function", isSerializable = (thing) => isRecord(thing) ? typeof thing.serialize == "function" : !1, rethrowWithPaneResolutionErrors = (next) => (unresolvedPane, context, flatIndex) => {
40
+ try {
41
+ return next(unresolvedPane, context, flatIndex);
42
+ } catch (e) {
43
+ throw e instanceof PaneResolutionError ? e : new PaneResolutionError({
44
+ message: typeof e?.message == "string" ? e.message : "",
45
+ context,
46
+ cause: e
47
+ });
48
+ }
49
+ }, wrapWithPublishReplay = (next) => (...args) => next(...args).pipe(
50
+ // need to add publishReplay + refCount to ensure new subscribers always
51
+ // get an emission. without this, memoized observables may get stuck
52
+ // waiting for their first emissions resulting in a loading pane
53
+ publishReplay(1),
54
+ refCount()
55
+ );
56
+ function createPaneResolver(middleware) {
57
+ const resolvePane = rethrowWithPaneResolutionErrors(wrapWithPublishReplay(middleware((unresolvedPane, context, flatIndex) => {
58
+ if (!unresolvedPane)
59
+ throw new PaneResolutionError({
60
+ message: "Pane returned no child",
61
+ context,
62
+ helpId: "structure-item-returned-no-child"
63
+ });
64
+ return isPromise(unresolvedPane) || isObservable(unresolvedPane) ? from(unresolvedPane).pipe(switchMap((result) => resolvePane(result, context, flatIndex))) : isSerializable(unresolvedPane) ? resolvePane(unresolvedPane.serialize(context), context, flatIndex) : typeof unresolvedPane == "function" ? resolvePane(unresolvedPane(context.id, context), context, flatIndex) : of(unresolvedPane);
65
+ })));
66
+ return resolvePane;
67
+ }
68
+ const bindCache = /* @__PURE__ */ new WeakMap();
69
+ function memoBind(obj, methodKey) {
70
+ const boundMethods = bindCache.get(obj) || /* @__PURE__ */ new Map();
71
+ if (boundMethods) {
72
+ const bound2 = boundMethods.get(methodKey);
73
+ if (bound2) return bound2;
74
+ }
75
+ const method = obj[methodKey];
76
+ if (typeof method != "function")
77
+ throw new Error(`Expected property \`${methodKey}\` to be a function but got ${typeof method} instead.`);
78
+ const bound = method.bind(obj);
79
+ return boundMethods.set(methodKey, bound), bindCache.set(obj, boundMethods), bound;
80
+ }
81
+ async function resolveIntent(options) {
82
+ const resolvedPaneCache = /* @__PURE__ */ new Map(), resolvePane = createPaneResolver((nextFn) => (unresolvedPane, context, flatIndex) => {
83
+ const key = unresolvedPane && `${assignId(unresolvedPane)}-${context.path.join("__")}`, cachedResolvedPane = key && resolvedPaneCache.get(key);
84
+ if (cachedResolvedPane) return cachedResolvedPane;
85
+ const result = nextFn(unresolvedPane, context, flatIndex);
86
+ return key && resolvedPaneCache.set(key, result), result;
87
+ }), fallbackEditorPanes = [[{
88
+ id: `__edit__${options.params.id}`,
89
+ params: {
90
+ ...omit(options.params, ["id"]),
91
+ type: options.params.type
92
+ },
93
+ payload: options.payload
94
+ }]];
95
+ async function traverse({
96
+ currentId,
97
+ flatIndex,
98
+ intent,
99
+ params,
100
+ parent: parent2,
101
+ path,
102
+ payload,
103
+ unresolvedPane,
104
+ levelIndex,
105
+ structureContext
106
+ }) {
107
+ if (!unresolvedPane) return [];
108
+ const {
109
+ id: targetId,
110
+ type: schemaTypeName,
111
+ ...otherParams
112
+ } = params, resolvedPane = await firstValueFrom(resolvePane(unresolvedPane, {
113
+ id: currentId,
114
+ splitIndex: 0,
115
+ parent: parent2,
116
+ path,
117
+ index: flatIndex,
118
+ params: {},
119
+ payload: void 0,
120
+ structureContext
121
+ }, flatIndex));
122
+ return resolvedPane.type === "document" && resolvedPane.id === targetId ? [{
123
+ panes: [...path.slice(0, path.length - 1).map((i) => [{
124
+ id: i
125
+ }]), [{
126
+ id: targetId,
127
+ params: otherParams,
128
+ payload
129
+ }]],
130
+ depthIndex: path.length,
131
+ levelIndex
132
+ }] : (
133
+ // if the resolve pane's `canHandleIntent` returns true, then resolve
134
+ resolvedPane.canHandleIntent?.(intent, params, {
135
+ pane: resolvedPane,
136
+ index: flatIndex
137
+ }) || // if the pane's `canHandleIntent` did not return true, then match against
138
+ // this default case. we will resolve the intent if:
139
+ resolvedPane.type === "documentList" && // 1. the schema type matches (this required for the document to render)
140
+ resolvedPane.schemaTypeName === schemaTypeName && // 2. the filter is the default filter.
141
+ //
142
+ // NOTE: this case is to prevent false positive matches where the user
143
+ // has configured a more specific filter for a particular type. In that
144
+ // case, the user can implement their own `canHandleIntent` function
145
+ resolvedPane.options.filter === "_type == $type" ? [{
146
+ panes: [
147
+ // map the current path to router panes
148
+ ...path.map((id) => [{
149
+ id
150
+ }]),
151
+ // then augment with the intents IDs and params
152
+ [{
153
+ id: params.id,
154
+ params: otherParams,
155
+ payload
156
+ }]
157
+ ],
158
+ depthIndex: path.length,
159
+ levelIndex
160
+ }] : resolvedPane.type === "list" && resolvedPane.child && resolvedPane.items ? (await Promise.all(resolvedPane.items.map((item, nextLevelIndex) => item.type === "divider" ? Promise.resolve([]) : traverse({
161
+ currentId: item._id || item.id,
162
+ flatIndex: flatIndex + 1,
163
+ intent,
164
+ params,
165
+ parent: resolvedPane,
166
+ path: [...path, item.id],
167
+ payload,
168
+ unresolvedPane: typeof resolvedPane.child == "function" ? memoBind(resolvedPane, "child") : resolvedPane.child,
169
+ levelIndex: nextLevelIndex,
170
+ structureContext
171
+ })))).flat() : []
172
+ );
173
+ }
174
+ const closestPaneToRoot = (await traverse({
175
+ currentId: "root",
176
+ flatIndex: 0,
177
+ levelIndex: 0,
178
+ intent: options.intent,
179
+ params: options.params,
180
+ parent: null,
181
+ path: [],
182
+ payload: options.payload,
183
+ unresolvedPane: options.rootPaneNode,
184
+ structureContext: options.structureContext
185
+ })).sort((a, b) => a.depthIndex === b.depthIndex ? a.levelIndex - b.levelIndex : a.depthIndex - b.depthIndex)[0];
186
+ return closestPaneToRoot ? closestPaneToRoot.panes : fallbackEditorPanes;
187
+ }
188
+ function isDocumentPaneNode(pane) {
189
+ return pane !== LOADING_PANE && pane.type === "document";
190
+ }
191
+ const fallbackEditorChild = (nodeId, context) => {
192
+ const id = nodeId.replace(/^__edit__/, ""), {
193
+ params,
194
+ payload,
195
+ structureContext: {
196
+ resolveDocumentNode
197
+ }
198
+ } = context, {
199
+ type,
200
+ template
201
+ } = params;
202
+ if (!type)
203
+ throw new Error(`Document type for document with ID ${id} was not provided in the router params.`);
204
+ let defaultDocumentBuilder = resolveDocumentNode({
205
+ schemaType: type,
206
+ documentId: id
207
+ }).id("editor");
208
+ return template && (defaultDocumentBuilder = defaultDocumentBuilder.initialValueTemplate(template, payload)), defaultDocumentBuilder.serialize();
209
+ };
210
+ function hashContext(context) {
211
+ return `contextHash(${JSON.stringify({
212
+ id: context.id,
213
+ parentId: parent && assignId(parent),
214
+ path: context.path,
215
+ index: context.index,
216
+ splitIndex: context.splitIndex,
217
+ serializeOptionsIndex: context.serializeOptions?.index,
218
+ serializeOptionsPath: context.serializeOptions?.path
219
+ })})`;
220
+ }
221
+ const hashResolvedPaneMeta = (meta) => {
222
+ const normalized = {
223
+ type: meta.type,
224
+ id: meta.routerPaneSibling.id,
225
+ params: meta.routerPaneSibling.params || {},
226
+ payload: meta.routerPaneSibling.payload || null,
227
+ flatIndex: meta.flatIndex,
228
+ groupIndex: meta.groupIndex,
229
+ siblingIndex: meta.siblingIndex,
230
+ path: meta.path,
231
+ paneNode: meta.type === "resolvedMeta" ? assignId(meta.paneNode) : null
232
+ };
233
+ return `metaHash(${JSON.stringify(normalized)})`;
234
+ };
235
+ function resolvePaneTree({
236
+ unresolvedPane,
237
+ flattenedRouterPanes,
238
+ parent: parent2,
239
+ path,
240
+ resolvePane,
241
+ structureContext
242
+ }) {
243
+ const [current, ...rest] = flattenedRouterPanes, next = rest[0], context = {
244
+ id: current.routerPaneSibling.id,
245
+ splitIndex: current.siblingIndex,
246
+ parent: parent2,
247
+ path: [...path, current.routerPaneSibling.id],
248
+ index: current.flatIndex,
249
+ params: current.routerPaneSibling.params || {},
250
+ payload: current.routerPaneSibling.payload,
251
+ structureContext
252
+ };
253
+ try {
254
+ return resolvePane(unresolvedPane, context, current.flatIndex).pipe(
255
+ // this switch map receives a resolved pane
256
+ switchMap((paneNode) => {
257
+ const resolvedPaneMeta = {
258
+ type: "resolvedMeta",
259
+ ...current,
260
+ paneNode,
261
+ path: context.path
262
+ }, loadingPanes = rest.map((i, restIndex) => ({
263
+ type: "loading",
264
+ path: [...context.path, ...rest.slice(restIndex).map((_, currentIndex) => `[${i.flatIndex + currentIndex}]`)],
265
+ paneNode: null,
266
+ ...i
267
+ }));
268
+ if (!rest.length)
269
+ return of([resolvedPaneMeta]);
270
+ let nextStream;
271
+ return (
272
+ /* the fallback editor case */
273
+ next?.routerPaneSibling.id.startsWith("__edit__") ? nextStream = resolvePaneTree({
274
+ unresolvedPane: fallbackEditorChild,
275
+ flattenedRouterPanes: rest,
276
+ parent: parent2,
277
+ path: context.path,
278
+ resolvePane,
279
+ structureContext
280
+ }) : current.groupIndex === next?.groupIndex ? nextStream = resolvePaneTree({
281
+ unresolvedPane,
282
+ flattenedRouterPanes: rest,
283
+ parent: parent2,
284
+ path,
285
+ resolvePane,
286
+ structureContext
287
+ }) : nextStream = resolvePaneTree({
288
+ unresolvedPane: typeof paneNode.child == "function" ? memoBind(paneNode, "child") : paneNode.child,
289
+ flattenedRouterPanes: rest,
290
+ parent: paneNode,
291
+ path: context.path,
292
+ resolvePane,
293
+ structureContext
294
+ }), concat(
295
+ // we emit the loading panes first in a concat (this emits immediately)
296
+ of([resolvedPaneMeta, ...loadingPanes]),
297
+ // then whenever the next stream is done, the results will be combined.
298
+ nextStream.pipe(map((nextResolvedPanes) => [resolvedPaneMeta, ...nextResolvedPanes]))
299
+ )
300
+ );
301
+ })
302
+ );
303
+ } catch (e) {
304
+ if (e instanceof PaneResolutionError && (e.context && console.warn(`Pane resolution error at index ${e.context.index}${e.context.splitIndex > 0 ? ` for split pane index ${e.context.splitIndex}` : ""}: ${e.message}${e.helpId ? ` - see ${generateHelpUrl(e.helpId)}` : ""}`, e), e.helpId === "structure-item-returned-no-child"))
305
+ return of([]);
306
+ throw e;
307
+ }
308
+ }
309
+ function createResolvedPaneNodeStream({
310
+ routerPanesStream,
311
+ rootPaneNode,
312
+ initialCacheState = {
313
+ cacheKeysByFlatIndex: [],
314
+ flattenedRouterPanes: [],
315
+ resolvedPaneCache: /* @__PURE__ */ new Map(),
316
+ resolvePane: () => NEVER
317
+ },
318
+ structureContext
319
+ }) {
320
+ return routerPanesStream.pipe(
321
+ // add in implicit "root" router pane
322
+ map((rawRouterPanes) => [[{
323
+ id: "root"
324
+ }], ...rawRouterPanes]),
325
+ // create flattened router panes
326
+ map((routerPanes) => routerPanes.flatMap((routerPaneGroup, groupIndex) => routerPaneGroup.map((routerPaneSibling, siblingIndex) => ({
327
+ routerPaneSibling,
328
+ groupIndex,
329
+ siblingIndex
330
+ }))).map((i, index) => ({
331
+ ...i,
332
+ flatIndex: index
333
+ }))),
334
+ // calculate a "diffIndex" used for clearing the memo cache
335
+ startWith([]),
336
+ pairwise(),
337
+ map(([prev, curr]) => {
338
+ for (let i = 0; i < curr.length; i++) {
339
+ const prevValue = prev[i], currValue = curr[i];
340
+ if (!isEqual(prevValue, currValue))
341
+ return {
342
+ flattenedRouterPanes: curr,
343
+ diffIndex: i
344
+ };
345
+ }
346
+ return {
347
+ flattenedRouterPanes: curr,
348
+ diffIndex: curr.length
349
+ };
350
+ }),
351
+ // create the memoized `resolvePane` function and manage the memo cache
352
+ scan((acc, next) => {
353
+ const {
354
+ cacheKeysByFlatIndex,
355
+ resolvedPaneCache
356
+ } = acc, {
357
+ flattenedRouterPanes,
358
+ diffIndex
359
+ } = next, beforeDiffIndex = cacheKeysByFlatIndex.slice(0, diffIndex + 1), afterDiffIndex = cacheKeysByFlatIndex.slice(diffIndex + 1), keysToKeep = new Set(beforeDiffIndex.flatMap((keySet) => Array.from(keySet))), keysToDelete = afterDiffIndex.flatMap((keySet) => Array.from(keySet)).filter((key) => !keysToKeep.has(key));
360
+ for (const key of keysToDelete)
361
+ resolvedPaneCache.delete(key);
362
+ return {
363
+ flattenedRouterPanes,
364
+ cacheKeysByFlatIndex,
365
+ resolvedPaneCache,
366
+ resolvePane: createPaneResolver((nextFn) => (unresolvedPane, context, flatIndex) => {
367
+ const key = unresolvedPane && `${assignId(unresolvedPane)}-${hashContext(context)}`, cachedResolvedPane = key && resolvedPaneCache.get(key);
368
+ if (cachedResolvedPane) return cachedResolvedPane;
369
+ const result = nextFn(unresolvedPane, context, flatIndex);
370
+ if (!key) return result;
371
+ const cacheKeySet = cacheKeysByFlatIndex[flatIndex] || /* @__PURE__ */ new Set();
372
+ return cacheKeySet.add(key), cacheKeysByFlatIndex[flatIndex] = cacheKeySet, resolvedPaneCache.set(key, result), result;
373
+ })
374
+ };
375
+ }, initialCacheState),
376
+ // run the memoized, recursive resolving
377
+ switchMap(({
378
+ flattenedRouterPanes,
379
+ resolvePane
380
+ }) => resolvePaneTree({
381
+ unresolvedPane: rootPaneNode,
382
+ flattenedRouterPanes,
383
+ parent: null,
384
+ path: [],
385
+ resolvePane,
386
+ structureContext
387
+ }))
388
+ ).pipe(
389
+ // this diffs the previous emission with the current one. if there is a new
390
+ // loading pane at the same position where a previous pane already had a
391
+ // resolved value (looking at the IDs to compare), then return the previous
392
+ // pane instead of the loading pane
393
+ scan((prev, next) => next.map((nextPane, index) => {
394
+ const prevPane = prev[index];
395
+ return !prevPane || nextPane.type !== "loading" ? nextPane : prevPane.routerPaneSibling.id === nextPane.routerPaneSibling.id ? prevPane : nextPane;
396
+ }), []),
397
+ // this prevents duplicate emissions
398
+ distinctUntilChanged((prev, next) => {
399
+ if (prev.length !== next.length) return !1;
400
+ for (let i = 0; i < next.length; i++) {
401
+ const prevValue = prev[i], nextValue = next[i];
402
+ if (hashResolvedPaneMeta(prevValue) !== hashResolvedPaneMeta(nextValue))
403
+ return !1;
404
+ }
405
+ return !0;
406
+ })
407
+ );
408
+ }
409
+ function useRouterPanesStream() {
410
+ const $ = c(6), [routerStateSubject] = useState(_temp$5);
411
+ let t0;
412
+ $[0] !== routerStateSubject ? (t0 = routerStateSubject.asObservable().pipe(map(_temp2$3)), $[0] = routerStateSubject, $[1] = t0) : t0 = $[1];
413
+ const routerPanes$ = t0, {
414
+ state: routerState
415
+ } = useRouter();
416
+ let t1, t2;
417
+ return $[2] !== routerState || $[3] !== routerStateSubject ? (t1 = () => {
418
+ routerStateSubject.next(routerState);
419
+ }, t2 = [routerState, routerStateSubject], $[2] = routerState, $[3] = routerStateSubject, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), useEffect(t1, t2), routerPanes$;
420
+ }
421
+ function _temp2$3(_routerState) {
422
+ return _routerState?.panes || [];
423
+ }
424
+ function _temp$5() {
425
+ return new ReplaySubject(1);
426
+ }
427
+ function useResolvedPanes() {
428
+ const $ = c(19), [error, setError] = useState(), [maximizedPane, setMaximizedPane] = useState(null);
429
+ if (error)
430
+ throw error;
431
+ const {
432
+ structureContext,
433
+ rootPaneNode
434
+ } = useStructureTool(), {
435
+ navigate
436
+ } = useRouter();
437
+ let t0;
438
+ $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = {
439
+ paneDataItems: [],
440
+ resolvedPanes: [],
441
+ routerPanes: []
442
+ }, $[0] = t0) : t0 = $[0];
443
+ const [data, setData] = useState(t0), routerPanesStream = useRouterPanesStream();
444
+ let t1, t2;
445
+ $[1] !== rootPaneNode || $[2] !== routerPanesStream || $[3] !== structureContext ? (t1 = () => {
446
+ const subscription = createResolvedPaneNodeStream({
447
+ rootPaneNode,
448
+ routerPanesStream,
449
+ structureContext
450
+ }).pipe(map(_temp5$1)).subscribe({
451
+ next: (result) => setData(result),
452
+ error: (e) => setError(e)
453
+ });
454
+ return () => subscription.unsubscribe();
455
+ }, t2 = [rootPaneNode, routerPanesStream, structureContext], $[1] = rootPaneNode, $[2] = routerPanesStream, $[3] = structureContext, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), useEffect(t1, t2);
456
+ let t3, t4;
457
+ $[6] !== data || $[7] !== navigate ? (t3 = function() {
458
+ const {
459
+ paneDataItems: paneDataItems_0,
460
+ routerPanes: routerPanes_0
461
+ } = data, lastPane = paneDataItems_0[paneDataItems_0.length - 1]?.pane;
462
+ if (!lastPane || !isDocumentPaneNode(lastPane) || !lastPane.defaultPanes)
463
+ return;
464
+ const currentGroup_0 = routerPanes_0[paneDataItems_0.length - 1];
465
+ if (!currentGroup_0 || currentGroup_0.length !== 1)
466
+ return;
467
+ const currentParams = currentGroup_0[0].params;
468
+ if (currentParams?.expanded)
469
+ return;
470
+ const expandedGroup = lastPane.defaultPanes.map((viewId, index) => ({
471
+ id: currentGroup_0[0].id,
472
+ params: {
473
+ ...currentParams,
474
+ view: viewId,
475
+ ...index === 0 ? {
476
+ expanded: "true"
477
+ } : {}
478
+ },
479
+ payload: currentGroup_0[0].payload
480
+ }));
481
+ navigate({
482
+ panes: [...routerPanes_0.slice(1, -1), expandedGroup]
483
+ }, {
484
+ replace: !0
485
+ });
486
+ }, t4 = [data, navigate], $[6] = data, $[7] = navigate, $[8] = t3, $[9] = t4) : (t3 = $[8], t4 = $[9]), useEffect(t3, t4);
487
+ let t5;
488
+ if ($[10] !== data.paneDataItems || $[11] !== maximizedPane) {
489
+ let t62;
490
+ $[13] !== maximizedPane ? (t62 = (item) => ({
491
+ ...item,
492
+ maximized: maximizedPane ? item.key === maximizedPane.key : !1
493
+ }), $[13] = maximizedPane, $[14] = t62) : t62 = $[14], t5 = data.paneDataItems.map(t62), $[10] = data.paneDataItems, $[11] = maximizedPane, $[12] = t5;
494
+ } else
495
+ t5 = $[12];
496
+ const paneDataItemsWithMaximized = t5;
497
+ let t6;
498
+ return $[15] !== data || $[16] !== maximizedPane || $[17] !== paneDataItemsWithMaximized ? (t6 = {
499
+ ...data,
500
+ paneDataItems: paneDataItemsWithMaximized,
501
+ maximizedPane,
502
+ setMaximizedPane
503
+ }, $[15] = data, $[16] = maximizedPane, $[17] = paneDataItemsWithMaximized, $[18] = t6) : t6 = $[18], t6;
504
+ }
505
+ function _temp5$1(resolvedPanes) {
506
+ const routerPanes = resolvedPanes.reduce(_temp3$1, []), groupsLen = routerPanes.length, paneDataItems = resolvedPanes.map((pane) => {
507
+ const {
508
+ groupIndex,
509
+ flatIndex,
510
+ siblingIndex,
511
+ routerPaneSibling,
512
+ path
513
+ } = pane, itemId = routerPaneSibling.id, nextGroup = routerPanes[groupIndex + 1];
514
+ return {
515
+ active: groupIndex === groupsLen - 2,
516
+ childItemId: nextGroup?.[0].id ?? null,
517
+ index: flatIndex,
518
+ itemId: routerPaneSibling.id,
519
+ groupIndex,
520
+ key: `${pane.type === "loading" ? "unknown" : pane.paneNode.id}-${itemId}-${siblingIndex}`,
521
+ pane: pane.type === "loading" ? LOADING_PANE : pane.paneNode,
522
+ params: routerPaneSibling.params || {},
523
+ path: path.join(";"),
524
+ payload: routerPaneSibling.payload,
525
+ selected: flatIndex === resolvedPanes.length - 1,
526
+ siblingIndex,
527
+ maximized: !1
528
+ };
529
+ });
530
+ return {
531
+ paneDataItems,
532
+ routerPanes,
533
+ resolvedPanes: paneDataItems.map(_temp4$1)
534
+ };
535
+ }
536
+ function _temp4$1(pane_0) {
537
+ return pane_0.pane;
538
+ }
539
+ function _temp3$1(acc, next) {
540
+ const currentGroup = acc[next.groupIndex] || [];
541
+ return currentGroup[next.siblingIndex] = next.routerPaneSibling, acc[next.groupIndex] = currentGroup, acc;
542
+ }
543
+ async function ensureDocumentIdAndType(documentStore, id, type) {
544
+ if (id && type) return {
545
+ id,
546
+ type
547
+ };
548
+ if (!id && type) return {
549
+ id: uuid(),
550
+ type
551
+ };
552
+ if (id && !type) {
553
+ const resolvedType = await firstValueFrom(documentStore.resolveTypeForDocument(id));
554
+ return {
555
+ id,
556
+ type: resolvedType
557
+ };
558
+ }
559
+ throw new PaneResolutionError({
560
+ message: "Neither document `id` or `type` was provided when trying to resolve intent."
561
+ });
562
+ }
563
+ const EMPTY_RECORD = {}, IntentResolver = memo(function() {
564
+ const $ = c(7), {
565
+ navigate
566
+ } = useRouter(), maybeIntent = useRouterState(_temp$4), {
567
+ rootPaneNode,
568
+ structureContext
569
+ } = useStructureTool(), documentStore = useDocumentStore(), [error, setError] = useState(null);
570
+ if (error)
571
+ throw error;
572
+ let t0, t1;
573
+ return $[0] !== documentStore || $[1] !== maybeIntent || $[2] !== navigate || $[3] !== rootPaneNode || $[4] !== structureContext ? (t0 = () => {
574
+ if (maybeIntent) {
575
+ const {
576
+ intent,
577
+ params,
578
+ payload
579
+ } = maybeIntent;
580
+ let cancelled = !1;
581
+ return (async function() {
582
+ const {
583
+ id,
584
+ type
585
+ } = await ensureDocumentIdAndType(documentStore, typeof params.id == "string" ? params.id : void 0, typeof params.type == "string" ? params.type : void 0);
586
+ if (cancelled)
587
+ return;
588
+ const panes = await resolveIntent({
589
+ intent,
590
+ params: {
591
+ ...params,
592
+ id,
593
+ type
594
+ },
595
+ payload,
596
+ rootPaneNode,
597
+ structureContext
598
+ });
599
+ cancelled || navigate({
600
+ panes
601
+ }, {
602
+ replace: !0
603
+ });
604
+ })().catch(setError), () => {
605
+ cancelled = !0;
606
+ };
607
+ }
608
+ }, t1 = [documentStore, maybeIntent, navigate, rootPaneNode, structureContext], $[0] = documentStore, $[1] = maybeIntent, $[2] = navigate, $[3] = rootPaneNode, $[4] = structureContext, $[5] = t0, $[6] = t1) : (t0 = $[5], t1 = $[6]), useEffect(t0, t1), null;
609
+ });
610
+ function _temp$4(routerState) {
611
+ const intentName = typeof routerState.intent == "string" ? routerState.intent : void 0;
612
+ return intentName ? {
613
+ intent: intentName,
614
+ params: isRecord(routerState.params) ? routerState.params : EMPTY_RECORD,
615
+ payload: routerState.payload
616
+ } : void 0;
617
+ }
618
+ const PathSegment = styled.span.withConfig({
619
+ displayName: "PathSegment",
620
+ componentId: "sc-jnonai-0"
621
+ })`&:not(:last-child)::after{content:' ➝ ';opacity:0.5;}`;
622
+ function formatStack(stack) {
623
+ return stack.replace(/\(\.\.\.\)\./g, `(...)
624
+ .`).replace(/__WEBPACK_IMPORTED_MODULE_\d+_+/g, "").replace(/___default\./g, ".").replace(new RegExp(` \\(https?:\\/\\/${window.location.host}`, "g"), " (");
625
+ }
626
+ function StructureError(t0) {
627
+ const $ = c(74), {
628
+ error
629
+ } = t0;
630
+ if (!(error instanceof PaneResolutionError))
631
+ throw error;
632
+ const {
633
+ cause
634
+ } = error, {
635
+ t
636
+ } = useTranslation(structureLocaleNamespace), stack = cause?.stack || error.stack;
637
+ let t1;
638
+ $[0] !== cause || $[1] !== error.message || $[2] !== stack ? (t1 = stack && !(cause instanceof SerializeError) && !error.message.includes("Module build failed:"), $[0] = cause, $[1] = error.message, $[2] = stack, $[3] = t1) : t1 = $[3];
639
+ const showStack = t1;
640
+ let T0, T1, T2, handleReload, helpId, t10, t11, t12, t13, t14, t2, t3, t4, t5, t6, t7, t8, t9;
641
+ if ($[4] !== cause || $[5] !== error.helpId || $[6] !== t) {
642
+ const path = cause instanceof SerializeError ? cause.path : [];
643
+ helpId = cause instanceof SerializeError && cause.helpId || error.helpId, handleReload = _temp$3, T2 = Card, t10 = "fill", t11 = "auto", t12 = 4, t13 = "border", t14 = "critical", T1 = Container;
644
+ let t152;
645
+ $[25] !== t ? (t152 = t("structure-error.header.text"), $[25] = t, $[26] = t152) : t152 = $[26], $[27] !== t152 ? (t9 = /* @__PURE__ */ jsx(Heading, { as: "h2", children: t152 }), $[27] = t152, $[28] = t9) : t9 = $[28], T0 = Card, t2 = 4, t3 = 4, t4 = 2, t5 = "auto", t6 = 1, t7 = "inherit", t8 = path.length > 0 && /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
646
+ /* @__PURE__ */ jsx(Text, { size: 1, weight: "medium", children: t("structure-error.structure-path.label") }),
647
+ /* @__PURE__ */ jsx(Code, { children: path.slice(1).map(_temp2$2) })
648
+ ] }), $[4] = cause, $[5] = error.helpId, $[6] = t, $[7] = T0, $[8] = T1, $[9] = T2, $[10] = handleReload, $[11] = helpId, $[12] = t10, $[13] = t11, $[14] = t12, $[15] = t13, $[16] = t14, $[17] = t2, $[18] = t3, $[19] = t4, $[20] = t5, $[21] = t6, $[22] = t7, $[23] = t8, $[24] = t9;
649
+ } else
650
+ T0 = $[7], T1 = $[8], T2 = $[9], handleReload = $[10], helpId = $[11], t10 = $[12], t11 = $[13], t12 = $[14], t13 = $[15], t14 = $[16], t2 = $[17], t3 = $[18], t4 = $[19], t5 = $[20], t6 = $[21], t7 = $[22], t8 = $[23], t9 = $[24];
651
+ let t15;
652
+ $[29] !== t ? (t15 = t("structure-error.error.label"), $[29] = t, $[30] = t15) : t15 = $[30];
653
+ let t16;
654
+ $[31] !== t15 ? (t16 = /* @__PURE__ */ jsx(Text, { size: 1, weight: "medium", children: t15 }), $[31] = t15, $[32] = t16) : t16 = $[32];
655
+ let t17;
656
+ $[33] !== error.message || $[34] !== showStack || $[35] !== stack ? (t17 = showStack ? formatStack(stack) : error.message, $[33] = error.message, $[34] = showStack, $[35] = stack, $[36] = t17) : t17 = $[36];
657
+ let t18;
658
+ $[37] !== t17 ? (t18 = /* @__PURE__ */ jsx(Code, { children: t17 }), $[37] = t17, $[38] = t18) : t18 = $[38];
659
+ let t19;
660
+ $[39] !== t16 || $[40] !== t18 ? (t19 = /* @__PURE__ */ jsxs(Stack, { marginTop: 4, space: 2, children: [
661
+ t16,
662
+ t18
663
+ ] }), $[39] = t16, $[40] = t18, $[41] = t19) : t19 = $[41];
664
+ let t20;
665
+ $[42] !== helpId || $[43] !== t ? (t20 = helpId && /* @__PURE__ */ jsx(Box, { marginTop: 4, children: /* @__PURE__ */ jsx(Text, { children: /* @__PURE__ */ jsx("a", { href: generateHelpUrl(helpId), rel: "noopener noreferrer", target: "_blank", children: t("structure-error.docs-link.text") }) }) }), $[42] = helpId, $[43] = t, $[44] = t20) : t20 = $[44];
666
+ let t21;
667
+ $[45] !== t ? (t21 = t("structure-error.reload-button.text"), $[45] = t, $[46] = t21) : t21 = $[46];
668
+ let t22;
669
+ $[47] !== handleReload || $[48] !== t21 ? (t22 = /* @__PURE__ */ jsx(Box, { marginTop: 4, children: /* @__PURE__ */ jsx(Button, { text: t21, icon: SyncIcon, tone: "primary", onClick: handleReload }) }), $[47] = handleReload, $[48] = t21, $[49] = t22) : t22 = $[49];
670
+ let t23;
671
+ $[50] !== T0 || $[51] !== t19 || $[52] !== t2 || $[53] !== t20 || $[54] !== t22 || $[55] !== t3 || $[56] !== t4 || $[57] !== t5 || $[58] !== t6 || $[59] !== t7 || $[60] !== t8 ? (t23 = /* @__PURE__ */ jsxs(T0, { marginTop: t2, padding: t3, radius: t4, overflow: t5, shadow: t6, tone: t7, children: [
672
+ t8,
673
+ t19,
674
+ t20,
675
+ t22
676
+ ] }), $[50] = T0, $[51] = t19, $[52] = t2, $[53] = t20, $[54] = t22, $[55] = t3, $[56] = t4, $[57] = t5, $[58] = t6, $[59] = t7, $[60] = t8, $[61] = t23) : t23 = $[61];
677
+ let t24;
678
+ $[62] !== T1 || $[63] !== t23 || $[64] !== t9 ? (t24 = /* @__PURE__ */ jsxs(T1, { children: [
679
+ t9,
680
+ t23
681
+ ] }), $[62] = T1, $[63] = t23, $[64] = t9, $[65] = t24) : t24 = $[65];
682
+ let t25;
683
+ return $[66] !== T2 || $[67] !== t10 || $[68] !== t11 || $[69] !== t12 || $[70] !== t13 || $[71] !== t14 || $[72] !== t24 ? (t25 = /* @__PURE__ */ jsx(T2, { height: t10, overflow: t11, padding: t12, sizing: t13, tone: t14, children: t24 }), $[66] = T2, $[67] = t10, $[68] = t11, $[69] = t12, $[70] = t13, $[71] = t14, $[72] = t24, $[73] = t25) : t25 = $[73], t25;
684
+ }
685
+ function _temp2$2(segment, i) {
686
+ return /* @__PURE__ */ jsx(PathSegment, { children: segment }, `${segment}-${i}`);
687
+ }
688
+ function _temp$3() {
689
+ window.location.reload();
690
+ }
691
+ function NoDocumentTypesScreen() {
692
+ const $ = c(17), {
693
+ t
694
+ } = useTranslation(structureLocaleNamespace);
695
+ let t0;
696
+ $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, children: /* @__PURE__ */ jsx(WarningOutlineIcon, {}) }) }), $[0] = t0) : t0 = $[0];
697
+ let t1;
698
+ $[1] !== t ? (t1 = t("no-document-types-screen.title"), $[1] = t, $[2] = t1) : t1 = $[2];
699
+ let t2;
700
+ $[3] !== t1 ? (t2 = /* @__PURE__ */ jsx(Text, { as: "h1", size: 1, weight: "medium", children: t1 }), $[3] = t1, $[4] = t2) : t2 = $[4];
701
+ let t3;
702
+ $[5] !== t ? (t3 = t("no-document-types-screen.subtitle"), $[5] = t, $[6] = t3) : t3 = $[6];
703
+ let t4;
704
+ $[7] !== t3 ? (t4 = /* @__PURE__ */ jsx(Text, { as: "p", muted: !0, size: 1, children: t3 }), $[7] = t3, $[8] = t4) : t4 = $[8];
705
+ let t5;
706
+ $[9] !== t ? (t5 = t("no-document-types-screen.link-text"), $[9] = t, $[10] = t5) : t5 = $[10];
707
+ let t6;
708
+ $[11] !== t5 ? (t6 = /* @__PURE__ */ jsx(Text, { as: "p", muted: !0, size: 1, children: /* @__PURE__ */ jsx("a", { href: "https://www.sanity.io/docs/create-a-schema-and-configure-sanity-studio", target: "_blank", rel: "noreferrer", children: t5 }) }), $[11] = t5, $[12] = t6) : t6 = $[12];
709
+ let t7;
710
+ return $[13] !== t2 || $[14] !== t4 || $[15] !== t6 ? (t7 = /* @__PURE__ */ jsx(Card, { height: "fill", children: /* @__PURE__ */ jsx(Flex, { align: "center", height: "fill", justify: "center", padding: 4, sizing: "border", children: /* @__PURE__ */ jsx(Container, { width: 0, children: /* @__PURE__ */ jsx(Card, { padding: 4, radius: 2, shadow: 1, tone: "caution", children: /* @__PURE__ */ jsxs(Flex, { children: [
711
+ t0,
712
+ /* @__PURE__ */ jsxs(Stack, { flex: 1, marginLeft: 3, space: 3, children: [
713
+ t2,
714
+ t4,
715
+ t6
716
+ ] })
717
+ ] }) }) }) }) }), $[13] = t2, $[14] = t4, $[15] = t6, $[16] = t7) : t7 = $[16], t7;
718
+ }
719
+ const DocumentTitle = (props) => {
720
+ const $ = c(7), {
721
+ documentId,
722
+ documentType
723
+ } = props, {
724
+ selectedReleaseId
725
+ } = usePerspective(), editState = useEditState(documentId, documentType, "default", selectedReleaseId), schema = useSchema(), {
726
+ t
727
+ } = useTranslation(structureLocaleNamespace), isNewDocument = !editState?.published && !editState?.draft, documentValue = editState?.version || editState?.draft || editState?.published, schemaType = schema.get(documentType), {
728
+ value,
729
+ isLoading: previewValueIsLoading
730
+ } = useValuePreview({
731
+ enabled: !!documentValue,
732
+ schemaType,
733
+ value: documentValue
734
+ }), {
735
+ lastRevisionDocument
736
+ } = useDocumentLastRev(documentId, documentType), documentTitle = lastRevisionDocument && !documentValue ? "" : isNewDocument ? t("browser-document-title.new-document", {
737
+ schemaType: schemaType?.title || schemaType?.name
738
+ }) : value?.title || t("browser-document-title.untitled-document"), settled = editState.ready && !previewValueIsLoading, newTitle = useConstructDocumentTitle(documentTitle);
739
+ let t0;
740
+ $[0] !== newTitle || $[1] !== settled ? (t0 = () => {
741
+ settled && (document.title = newTitle);
742
+ }, $[0] = newTitle, $[1] = settled, $[2] = t0) : t0 = $[2];
743
+ let t1;
744
+ return $[3] !== documentTitle || $[4] !== newTitle || $[5] !== settled ? (t1 = [documentTitle, settled, newTitle], $[3] = documentTitle, $[4] = newTitle, $[5] = settled, $[6] = t1) : t1 = $[6], useEffect(t0, t1), null;
745
+ }, PassthroughTitle = (props) => {
746
+ const $ = c(5), {
747
+ title
748
+ } = props, newTitle = useConstructDocumentTitle(title);
749
+ let t0;
750
+ $[0] !== newTitle ? (t0 = () => {
751
+ document.title = newTitle;
752
+ }, $[0] = newTitle, $[1] = t0) : t0 = $[1];
753
+ let t1;
754
+ return $[2] !== newTitle || $[3] !== title ? (t1 = [newTitle, title], $[2] = newTitle, $[3] = title, $[4] = t1) : t1 = $[4], useEffect(t0, t1), null;
755
+ }, StructureTitle = (props) => {
756
+ const $ = c(8), {
757
+ resolvedPanes
758
+ } = props;
759
+ if (!resolvedPanes?.length)
760
+ return null;
761
+ const lastPane = resolvedPanes[resolvedPanes.length - 1];
762
+ if (isLoadingPane(lastPane)) {
763
+ let t02;
764
+ return $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t02 = /* @__PURE__ */ jsx(PassthroughTitle, {}), $[0] = t02) : t02 = $[0], t02;
765
+ }
766
+ if (isDocumentPane(lastPane)) {
767
+ if (lastPane?.title) {
768
+ let t03;
769
+ return $[1] !== lastPane.title ? (t03 = /* @__PURE__ */ jsx(PassthroughTitle, { title: lastPane.title }), $[1] = lastPane.title, $[2] = t03) : t03 = $[2], t03;
770
+ }
771
+ let t02;
772
+ return $[3] !== lastPane.options.id || $[4] !== lastPane.options.type ? (t02 = /* @__PURE__ */ jsx(DocumentTitle, { documentId: lastPane.options.id, documentType: lastPane.options.type }), $[3] = lastPane.options.id, $[4] = lastPane.options.type, $[5] = t02) : t02 = $[5], t02;
773
+ }
774
+ const t0 = lastPane?.title;
775
+ let t1;
776
+ return $[6] !== t0 ? (t1 = /* @__PURE__ */ jsx(PassthroughTitle, { title: t0 }), $[6] = t0, $[7] = t1) : t1 = $[7], t1;
777
+ };
778
+ function useConstructDocumentTitle(activeTitle) {
779
+ const $ = c(3), structureToolBaseTitle = useStructureTool().structureContext.title;
780
+ let t0;
781
+ return $[0] !== activeTitle || $[1] !== structureToolBaseTitle ? (t0 = [activeTitle, structureToolBaseTitle].filter(_temp$2), $[0] = activeTitle, $[1] = structureToolBaseTitle, $[2] = t0) : t0 = $[2], t0.join(" | ");
782
+ }
783
+ function _temp$2(title) {
784
+ return title;
785
+ }
786
+ function isDocumentPane(pane) {
787
+ return pane !== LOADING_PANE && pane.type === "document";
788
+ }
789
+ function isLoadingPane(pane) {
790
+ return pane === LOADING_PANE;
791
+ }
792
+ const StyledPaneLayout = styled(PaneLayout).withConfig({
793
+ displayName: "StyledPaneLayout",
794
+ componentId: "sc-1hgaa0f-0"
795
+ })`min-height:100%;min-width:320px;`, isSaveHotkey = isHotkey("mod+s"), StructureTool = memo(function(t0) {
796
+ const $ = c(58), {
797
+ onPaneChange
798
+ } = t0, {
799
+ push: pushToast
800
+ } = useToast(), schema = useSchema(), {
801
+ navigate
802
+ } = useRouter(), routerState = useRouterState(), {
803
+ layoutCollapsed,
804
+ setLayoutCollapsed
805
+ } = useStructureTool(), resolvedPanesValue = useResolvedPanes(), {
806
+ paneDataItems,
807
+ resolvedPanes,
808
+ setMaximizedPane,
809
+ maximizedPane
810
+ } = resolvedPanesValue, isResolvingIntent = useRouterState(_temp$1), {
811
+ sanity: t1
812
+ } = useTheme(), {
813
+ media
814
+ } = t1, [portalElement, setPortalElement] = useState(null);
815
+ let t2;
816
+ $[0] !== setLayoutCollapsed ? (t2 = () => setLayoutCollapsed(!0), $[0] = setLayoutCollapsed, $[1] = t2) : t2 = $[1];
817
+ const handleRootCollapse = t2;
818
+ let t3;
819
+ $[2] !== setLayoutCollapsed ? (t3 = () => setLayoutCollapsed(!1), $[2] = setLayoutCollapsed, $[3] = t3) : t3 = $[3];
820
+ const handleRootExpand = t3;
821
+ let t4;
822
+ if ($[4] !== paneDataItems) {
823
+ const maximizedLastIndex = paneDataItems.findLastIndex(_temp2$1);
824
+ t4 = maximizedLastIndex === -1 ? paneDataItems : paneDataItems.slice(maximizedLastIndex).filter((pane_0) => pane_0.groupIndex <= paneDataItems[maximizedLastIndex].groupIndex), $[4] = paneDataItems, $[5] = t4;
825
+ } else
826
+ t4 = $[5];
827
+ const paneItemsToShow = t4;
828
+ let t5, t6;
829
+ $[6] !== onPaneChange || $[7] !== resolvedPanes ? (t5 = () => {
830
+ resolvedPanes.length && onPaneChange(resolvedPanes);
831
+ }, t6 = [onPaneChange, resolvedPanes], $[6] = onPaneChange, $[7] = resolvedPanes, $[8] = t5, $[9] = t6) : (t5 = $[8], t6 = $[9]), useEffect(t5, t6);
832
+ let t7, t8;
833
+ $[10] !== pushToast ? (t7 = () => {
834
+ const handleGlobalKeyDown = (event) => {
835
+ isSaveHotkey(event) && (event.preventDefault(), pushToast({
836
+ closable: !0,
837
+ id: "auto-save-message",
838
+ status: "info",
839
+ title: "Your work is automatically saved!",
840
+ duration: 4e3
841
+ }));
842
+ };
843
+ return window.addEventListener("keydown", handleGlobalKeyDown), () => window.removeEventListener("keydown", handleGlobalKeyDown);
844
+ }, t8 = [pushToast], $[10] = pushToast, $[11] = t7, $[12] = t8) : (t7 = $[11], t8 = $[12]), useEffect(t7, t8);
845
+ const hasDefinedDocumentTypes = schema._original?.types.some(_isCustomDocumentTypeDefinition);
846
+ let t9;
847
+ $[13] !== navigate || $[14] !== routerState?.panes || $[15] !== setMaximizedPane ? (t9 = (paneData) => {
848
+ if (!paneData)
849
+ return;
850
+ const currentPanes = routerState?.panes || [];
851
+ if (paneData.maximized) {
852
+ setMaximizedPane(null), navigate({
853
+ panes: currentPanes
854
+ });
855
+ return;
856
+ }
857
+ if (paneData.pane !== LOADING_PANE && paneData.pane.type === "document") {
858
+ const slicedPanes = currentPanes.slice(0, paneData.groupIndex);
859
+ setMaximizedPane(paneData), navigate({
860
+ panes: slicedPanes
861
+ });
862
+ }
863
+ }, $[13] = navigate, $[14] = routerState?.panes, $[15] = setMaximizedPane, $[16] = t9) : t9 = $[16];
864
+ const onSetMaximizedPane = t9, previousSelectedIndexRef = useRef(-1);
865
+ let t10;
866
+ $[17] !== navigate || $[18] !== paneDataItems || $[19] !== routerState?.panes || $[20] !== setMaximizedPane ? (t10 = () => {
867
+ const focusedPaneAccordingToParams = paneDataItems.find(_temp3);
868
+ if (!focusedPaneAccordingToParams)
869
+ return;
870
+ focusedPaneAccordingToParams.pane !== LOADING_PANE && focusedPaneAccordingToParams.pane.type === "document" && setMaximizedPane(focusedPaneAccordingToParams);
871
+ const panesWithoutFocus = (routerState?.panes || []).map(_temp5);
872
+ navigate({
873
+ panes: panesWithoutFocus
874
+ }, {
875
+ replace: !0
876
+ });
877
+ }, $[17] = navigate, $[18] = paneDataItems, $[19] = routerState?.panes, $[20] = setMaximizedPane, $[21] = t10) : t10 = $[21];
878
+ const t11 = routerState?.panes;
879
+ let t12;
880
+ $[22] !== navigate || $[23] !== paneDataItems || $[24] !== setMaximizedPane || $[25] !== t11 ? (t12 = [navigate, paneDataItems, t11, setMaximizedPane], $[22] = navigate, $[23] = paneDataItems, $[24] = setMaximizedPane, $[25] = t11, $[26] = t12) : t12 = $[26], useEffect(t10, t12);
881
+ let t13, t14;
882
+ if ($[27] !== maximizedPane || $[28] !== paneDataItems || $[29] !== setMaximizedPane ? (t13 = () => {
883
+ const selectedIndex = paneDataItems.findIndex(_temp6), prevSelectedIndex = previousSelectedIndexRef.current;
884
+ if (previousSelectedIndexRef.current = selectedIndex, !!maximizedPane) {
885
+ if (maximizedPane.pane !== LOADING_PANE && maximizedPane.pane.type !== "document") {
886
+ setMaximizedPane(null);
887
+ return;
888
+ }
889
+ if (selectedIndex !== -1 && selectedIndex !== prevSelectedIndex) {
890
+ const selectedPane = paneDataItems[selectedIndex];
891
+ setMaximizedPane(selectedPane);
892
+ return;
893
+ }
894
+ if (!paneDataItems.some((pane_3) => pane_3.key === maximizedPane.key)) {
895
+ const fallbackPane = paneDataItems.find((pane_4) => pane_4.groupIndex === maximizedPane.groupIndex && pane_4.siblingIndex === maximizedPane.siblingIndex && pane_4.pane !== LOADING_PANE && pane_4.pane.type === "document");
896
+ setMaximizedPane(fallbackPane || null);
897
+ }
898
+ }
899
+ }, t14 = [maximizedPane, paneDataItems, setMaximizedPane], $[27] = maximizedPane, $[28] = paneDataItems, $[29] = setMaximizedPane, $[30] = t13, $[31] = t14) : (t13 = $[30], t14 = $[31]), useEffect(t13, t14), !hasDefinedDocumentTypes) {
900
+ let t152;
901
+ return $[32] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t152 = /* @__PURE__ */ jsx(NoDocumentTypesScreen, {}), $[32] = t152) : t152 = $[32], t152;
902
+ }
903
+ const t15 = portalElement || null, t16 = layoutCollapsed ? void 0 : "fill", t17 = media[1];
904
+ let t18;
905
+ if ($[33] !== onSetMaximizedPane || $[34] !== paneItemsToShow) {
906
+ let t192;
907
+ $[36] !== onSetMaximizedPane ? (t192 = (paneData_0) => {
908
+ const {
909
+ active,
910
+ childItemId,
911
+ groupIndex,
912
+ itemId,
913
+ key: paneKey,
914
+ pane: pane_5,
915
+ index: paneIndex,
916
+ params: paneParams,
917
+ path,
918
+ payload,
919
+ siblingIndex,
920
+ selected,
921
+ maximized
922
+ } = paneData_0;
923
+ return /* @__PURE__ */ jsx(Fragment, { children: pane_5 === LOADING_PANE ? /* @__PURE__ */ jsx(LoadingPane, { paneKey, path, selected }) : /* @__PURE__ */ jsx(StructureToolPane, { active, groupIndex, index: paneIndex, pane: pane_5, childItemId, itemId, paneKey, params: paneParams, payload, path, selected, siblingIndex, maximized, onSetMaximizedPane: () => onSetMaximizedPane(paneData_0) }) }, `${pane_5 === LOADING_PANE ? "loading" : pane_5.type}-${paneIndex}`);
924
+ }, $[36] = onSetMaximizedPane, $[37] = t192) : t192 = $[37], t18 = paneItemsToShow.map(t192), $[33] = onSetMaximizedPane, $[34] = paneItemsToShow, $[35] = t18;
925
+ } else
926
+ t18 = $[35];
927
+ let t19;
928
+ $[38] !== isResolvingIntent || $[39] !== paneDataItems.length ? (t19 = paneDataItems.length <= 1 && isResolvingIntent && /* @__PURE__ */ jsx(LoadingPane, { paneKey: "intent-resolver" }), $[38] = isResolvingIntent, $[39] = paneDataItems.length, $[40] = t19) : t19 = $[40];
929
+ let t20;
930
+ $[41] !== handleRootCollapse || $[42] !== handleRootExpand || $[43] !== media[1] || $[44] !== t16 || $[45] !== t18 || $[46] !== t19 ? (t20 = /* @__PURE__ */ jsxs(StyledPaneLayout, { flex: 1, height: t16, minWidth: t17, onCollapse: handleRootCollapse, onExpand: handleRootExpand, children: [
931
+ t18,
932
+ t19
933
+ ] }), $[41] = handleRootCollapse, $[42] = handleRootExpand, $[43] = media[1], $[44] = t16, $[45] = t18, $[46] = t19, $[47] = t20) : t20 = $[47];
934
+ let t21;
935
+ $[48] !== resolvedPanes ? (t21 = /* @__PURE__ */ jsx(StructureTitle, { resolvedPanes }), $[48] = resolvedPanes, $[49] = t21) : t21 = $[49];
936
+ let t22;
937
+ $[50] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t22 = /* @__PURE__ */ jsx("div", { "data-portal": "", ref: setPortalElement }), $[50] = t22) : t22 = $[50];
938
+ let t23;
939
+ $[51] !== t15 || $[52] !== t20 || $[53] !== t21 ? (t23 = /* @__PURE__ */ jsxs(PortalProvider, { element: t15, children: [
940
+ t20,
941
+ t21,
942
+ t22
943
+ ] }), $[51] = t15, $[52] = t20, $[53] = t21, $[54] = t23) : t23 = $[54];
944
+ let t24;
945
+ return $[55] !== resolvedPanesValue || $[56] !== t23 ? (t24 = /* @__PURE__ */ jsx(ResolvedPanesProvider, { value: resolvedPanesValue, children: t23 }), $[55] = resolvedPanesValue, $[56] = t23, $[57] = t24) : t24 = $[57], t24;
946
+ });
947
+ function _temp$1(state) {
948
+ return typeof state.intent == "string";
949
+ }
950
+ function _temp2$1(pane) {
951
+ return pane.maximized;
952
+ }
953
+ function _temp3(p) {
954
+ return p.params?.mode === "focus";
955
+ }
956
+ function _temp4(pane_1) {
957
+ const {
958
+ mode: _omitMode,
959
+ ...rest
960
+ } = pane_1.params || {}, nextParams = Object.keys(rest).length ? rest : void 0;
961
+ return {
962
+ ...pane_1,
963
+ params: nextParams
964
+ };
965
+ }
966
+ function _temp5(group) {
967
+ return group.map(_temp4);
968
+ }
969
+ function _temp6(pane_2) {
970
+ return pane_2.selected;
971
+ }
972
+ function StructureToolBoundary(t0) {
973
+ const $ = c(14), {
974
+ tool: t1
975
+ } = t0, {
976
+ options
977
+ } = t1, {
978
+ unstable_sources: sources
979
+ } = useWorkspace(), [firstSource] = sources;
980
+ let t2;
981
+ $[0] !== options ? (t2 = options || {}, $[0] = options, $[1] = t2) : t2 = $[1];
982
+ const {
983
+ source,
984
+ defaultDocumentNode,
985
+ structure
986
+ } = t2;
987
+ let t3;
988
+ $[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = [], $[2] = t3) : t3 = $[2], useEffect(_temp2, t3);
989
+ let t4;
990
+ $[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = {
991
+ error: null
992
+ }, $[3] = t4) : t4 = $[3];
993
+ const [t5, setError] = useState(t4), {
994
+ error
995
+ } = t5;
996
+ if (error) {
997
+ let t62;
998
+ return $[4] !== error ? (t62 = /* @__PURE__ */ jsx(StructureError, { error }), $[4] = error, $[5] = t62) : t62 = $[5], t62;
999
+ }
1000
+ const t6 = source || firstSource.name;
1001
+ let t7, t8;
1002
+ $[6] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t7 = /* @__PURE__ */ jsx(StructureTool, { onPaneChange: setActivePanes }), t8 = /* @__PURE__ */ jsx(IntentResolver, {}), $[6] = t7, $[7] = t8) : (t7 = $[6], t8 = $[7]);
1003
+ let t9;
1004
+ $[8] !== defaultDocumentNode || $[9] !== structure ? (t9 = /* @__PURE__ */ jsxs(StructureToolProvider, { defaultDocumentNode, structure, children: [
1005
+ t7,
1006
+ t8
1007
+ ] }), $[8] = defaultDocumentNode, $[9] = structure, $[10] = t9) : t9 = $[10];
1008
+ let t10;
1009
+ return $[11] !== t6 || $[12] !== t9 ? (t10 = /* @__PURE__ */ jsx(ErrorBoundary, { onCatch: setError, children: /* @__PURE__ */ jsx(SourceProvider, { name: t6, children: t9 }) }), $[11] = t6, $[12] = t9, $[13] = t10) : t10 = $[13], t10;
1010
+ }
1011
+ function _temp2() {
1012
+ return setActivePanes([]), _temp;
1013
+ }
1014
+ function _temp() {
1015
+ return setActivePanes([]);
1016
+ }
1017
+ export {
1018
+ StructureToolBoundary as default
1019
+ };
1020
+ //# sourceMappingURL=index4.js.map